Deep link: add prompt (#1669)

Example:
open
"dyad://add-prompt?data=eyJ0aXRsZSI6IlRlc3QgUHJvbXB0IiwiZGVzY3JpcHRpb24iOiJBIHRlc3QgcHJvbXB0IGZyb20gZGVlcCBsaW5rIiwiY29udGVudCI6IlRoaXMgaXMgdGhlIGNvbnRlbnQgb2YgdGhlIHByb21wdC4ifQ%3D%3D"

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds dyad://add-prompt deep link that navigates to Library and opens a
prefilled Create Prompt dialog from base64 JSON.
> 
> - **Deep Link Handling**
> - Parse `dyad://add-prompt?data=<base64-json>` in `src/main.ts`;
validate with `AddPromptDataSchema` and send `deep-link-received` with
payload.
> - Extend `DeepLinkContext` to navigate to `/library` on `add-prompt`.
> - **Library/Dialogs**
> - Add controlled open state and `prefillData` support to
`CreateOrEditPromptDialog` and `CreatePromptDialog`
(`src/components/CreatePromptDialog.tsx`).
> - In `src/pages/library.tsx`, listen for `add-prompt` deep link,
prefill form, open dialog, and clear deep-link state.
> - **Schemas**
> - Define `AddPromptDataSchema`, `AddPromptPayload`, and
`AddPromptDeepLinkData` in `src/ipc/deep_link_data.ts` and include in
`DeepLinkData` union.
> - **E2E Tests**
> - Add Playwright test `e2e-tests/add_prompt_deep_link.spec.ts` and
ARIA snapshot to verify deep link opens prefilled dialog and saves
prompt.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1ddb12306cfca195682c8a1b719f60093b858d54. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
This commit is contained in:
Will Chen
2025-10-29 21:26:01 -07:00
committed by GitHub
parent beb777bd54
commit 04b1a36f4a
7 changed files with 199 additions and 7 deletions

View File

@@ -0,0 +1,52 @@
import { test } from "./helpers/test_helper";
import { expect } from "@playwright/test";
test("add prompt via deep link with base64-encoded data", async ({
po,
electronApp,
}) => {
await po.setUp();
await po.goToLibraryTab();
// Verify library is empty initially
await expect(po.page.getByTestId("prompt-card")).not.toBeVisible();
// Create the prompt data to be encoded
const promptData = {
title: "Deep Link Test Prompt",
description: "A prompt created via deep link",
content: "You are a helpful assistant. Please help with:\n\n[task here]",
};
// Encode the data as base64 (matching the pattern in main.ts)
const base64Data = Buffer.from(JSON.stringify(promptData)).toString("base64");
const deepLinkUrl = `dyad://add-prompt?data=${encodeURIComponent(base64Data)}`;
console.log("Triggering deep link:", deepLinkUrl);
// Trigger the deep link by emitting the 'open-url' event in the main process
await electronApp.evaluate(({ app }, url) => {
app.emit("open-url", { preventDefault: () => {} }, url);
}, deepLinkUrl);
// Wait for the dialog to open and verify prefilled data
await expect(
po.page.getByRole("dialog").getByText("Create New Prompt"),
).toBeVisible();
// Verify the form is prefilled with the correct data
await expect(po.page.getByRole("textbox", { name: "Title" })).toHaveValue(
promptData.title,
);
await expect(
po.page.getByRole("textbox", { name: "Description (optional)" }),
).toHaveValue(promptData.description);
await expect(po.page.getByRole("textbox", { name: "Content" })).toHaveValue(
promptData.content,
);
// Save the prompt
await po.page.getByRole("button", { name: "Save" }).click();
await expect(po.page.getByTestId("prompt-card")).toMatchAriaSnapshot();
});