Skip to content

Open source CapCut alternative.

TypeScript

fix(site): clear the card's model context in the picker

David Le6ba40fd48536
diff --git a/site/scripts/eval-chatgpt-widget.ts b/site/scripts/eval-chatgpt-widget.ts
index 084082b5..b771e889 100644
--- a/site/scripts/eval-chatgpt-widget.ts
+++ b/site/scripts/eval-chatgpt-widget.ts
@@ -111,7 +111,8 @@ try {
await app.locator(".skeleton").waitFor({ state: "detached" });
assert.deepEqual(await page.evaluate(() => (window as unknown as { modes: string[] }).modes), [], "an opened editor stays inline");
// A project picked in the card reaches the model, which never saw that call.
- const contexts = await page.evaluate(() => (window as unknown as { contexts: { structuredContent?: { projectId?: string } }[] }).contexts);
+ const contexts = await page.evaluate(() => (window as unknown as { contexts: { content?: unknown[]; structuredContent?: { projectId?: string } }[] }).contexts);
+ assert.deepEqual(contexts.at(-2)?.content, [], "the picker clears the card's context");
assert.equal(contexts.at(-1)?.structuredContent?.projectId, "project", "the model knows which project the card shows");
assert.equal(await app.locator("button").count(), 0, "the editor card has no controls of its own");
assert.equal(await app.locator("main.editing").evaluate((m) => getComputedStyle(m).borderTopWidth), "0px", "an inline card keeps the host's own border");
diff --git a/site/src/clients/chatgpt/ui/useProjectApp.ts b/site/src/clients/chatgpt/ui/useProjectApp.ts
index 5cb842f7..bf341634 100644
--- a/site/src/clients/chatgpt/ui/useProjectApp.ts
+++ b/site/src/clients/chatgpt/ui/useProjectApp.ts
@@ -158,10 +158,14 @@ export function useProjectApp() {
useEffect(() => {
const app = appRef.current;
if (!app || !ready || !view || !app.getHostCapabilities()?.updateModelContext) return;
- const text = projectId
- ? `The Donkey Cut card shows the project "${projectName}" (projectId ${projectId}). Requests about this project or video mean this one.`
- : "The Donkey Cut card shows the project list; no project is open.";
- void app.updateModelContext({ content: [{ type: "text", text }], structuredContent: { projectId: projectId ?? null, name: projectName ?? null } }).catch(() => {});
+ // The picker clears what the card said, so the composer carries no chip
+ // until a project opens.
+ if (!projectId) {
+ void app.updateModelContext({ content: [] }).catch(() => {});
+ return;
+ }
+ const text = `The Donkey Cut card shows the project "${projectName}" (projectId ${projectId}). Requests about this project or video mean this one.`;
+ void app.updateModelContext({ content: [{ type: "text", text }], structuredContent: { projectId, name: projectName } }).catch(() => {});
}, [ready, view, projectId, projectName]);
const playbackFailed = useCallback(() => {