Skip to content

Open source CapCut alternative.

TypeScript

feat(chatgpt): the card plays the editor's proxy the moment a project opens

David Leff65ea473ee3
diff --git a/docs/guides/chatgpt-app.md b/docs/guides/chatgpt-app.md
index 2d356205..211c3644 100644
--- a/docs/guides/chatgpt-app.md
+++ b/docs/guides/chatgpt-app.md
@@ -60,8 +60,11 @@ Donkey Cut link. ChatGPT's sandbox drops null-valued keys from a tool result
before the widget sees it, so the widget contract treats a missing key and null
alike.
-Cloud previews use the existing headless renderer and a captured document.
-Repeated requests for the same saved revision reuse a queued, running, or
+Opening a project plays the proxy the editor already rendered for it, the
+same file the share page serves, so nobody waits on a render to watch. A
+render is for a revision with no current proxy, such as one edited from
+ChatGPT; it uses the existing headless renderer and a captured document, and
+repeated requests for the same saved revision reuse a queued, running, or
available completed preview. A collected preview can be rendered again.
Browser and Mac projects retain their existing render paths; they become
accessible to ChatGPT after the user saves them to the cloud in Donkey Cut.
diff --git a/site/src/clients/chatgpt/server/mcp.ts b/site/src/clients/chatgpt/server/mcp.ts
index 25c1356b..042f9e46 100644
--- a/site/src/clients/chatgpt/server/mcp.ts
+++ b/site/src/clients/chatgpt/server/mcp.ts
@@ -53,6 +53,7 @@ export const SERVER_INSTRUCTIONS = [
`Donkey Cut is an open-source video editor (Apache 2.0, ${REPOSITORY_URL}). Edit the connected account's cloud projects: import footage, inspect it, cut it, caption it, preview, undo, export.`,
"Editing, previews and exports are free. Hosted AI (voiceover, music, images, caption rewriting, transcription past the monthly allowance) spends the account's credits. Imports and exports use the account's cloud storage.",
"Workflow: list_projects or create_project → import_media → inspect_project → list_commands once, describe_commands for the ones you need → edit_project (batches, one undo step each) → render_preview → undo/redo → export_video.",
+ "open_project plays the project's current preview at once; call render_preview only after an edit or when the card reports no current preview.",
"Times are seconds; ids come from inspect_project. A batch stops at its first failed command. A tool that answers with a job still running is finished by get_job_status.",
].join("\n");
@@ -174,7 +175,7 @@ export function createChatgptServer(
{
title: "Open a Donkey Cut preview",
description:
- "Show a selected cloud project and its latest available preview. The preview can be from an earlier edit; render_preview renders the current saved revision. With no projectId, show the project picker.",
+ "Show a selected cloud project with its preview playing in the card. A preview whose revision matches the project is current; one from an earlier revision, or none, needs render_preview. With no projectId, show the project picker.",
inputSchema: z.object({ projectId: idSchema.optional() }),
outputSchema: viewSchema,
annotations: readOnlyAnnotations,
@@ -189,7 +190,7 @@ export function createChatgptServer(
{
title: "Render a Donkey Cut preview",
description:
- "Render the current saved cloud project into a playable preview. Returns a job immediately; use get_preview_status to check it. Reuses a render of the same saved revision. Consumes no AI credits. Does not edit the project.",
+ "Render the current saved cloud project into a playable preview. Needed only after an edit or when open_project reports no current preview; a current one is returned as is. Returns a job immediately; use get_preview_status to check it. Consumes no AI credits. Does not edit the project.",
inputSchema: z.object({ projectId: idSchema }),
outputSchema: viewSchema,
annotations: { ...readOnlyAnnotations, readOnlyHint: false },
@@ -526,7 +527,15 @@ function describeProjectView(view: ProjectView): string {
);
}
if (view.preview || !lines.length) {
- lines.push(`${project.name} (${project.revision}): ${view.preview ? `preview ${view.preview.status}` : "no preview yet"}.`);
+ const preview = view.preview;
+ lines.push(
+ `${project.name} (${project.revision}): ${
+ !preview ? "no preview yet"
+ : preview.status === "done" && preview.revision === project.revision ? "current preview playing in the card"
+ : preview.status === "done" ? `preview from earlier revision ${preview.revision ?? "unknown"}`
+ : `preview ${preview.status}`
+ }.`,
+ );
}
if (view.history?.undo) lines.push(`Undo would revert: ${view.history.undo}.`);
if (view.history?.redo) lines.push(`Redo would re-apply: ${view.history.redo}.`);
diff --git a/site/src/clients/chatgpt/server/projects.test.ts b/site/src/clients/chatgpt/server/projects.test.ts
index fc0586a8..e72858a4 100644
--- a/site/src/clients/chatgpt/server/projects.test.ts
+++ b/site/src/clients/chatgpt/server/projects.test.ts
@@ -5,7 +5,7 @@ import { projectTools } from "@/clients/chatgpt/server/projects";
const config = SETTINGS.chatgptApp.schema.parse(SETTINGS.chatgptApp.default);
function createTestContext(scopes: string[] = ["projects:read"]) {
- const project = { id: "mine", userId: "owner", name: "My video", version: 4 };
+ const project = { id: "mine", userId: "owner", name: "My video", version: 4, previewKey: "proxy" };
const jobs = mock(async (args: unknown) => {
void args;
return null as unknown;
@@ -27,7 +27,7 @@ function createTestContext(scopes: string[] = ["projects:read"]) {
cutMediaObject: {
findFirst: mock(async (args: unknown) => {
void args;
- return null;
+ return null as unknown;
}),
},
};
@@ -92,6 +92,17 @@ describe("ChatGPT cloud projects", () => {
expect(result.playback).toBeNull();
expect(result.view.project?.revision).toBe("cloud:4");
});
+ test("the editor's proxy is the current preview, so render plays it without queueing", async () => {
+ const { tools, db } = createTestContext(["projects:read", "previews:render"]);
+ db.cutRenderJob.findFirst.mockResolvedValue({ id: "job", state: "done", progress: 1, outputKey: "proxy", spec: { spec: {} }, updatedAt: new Date() });
+ db.cutMediaObject.findFirst.mockResolvedValue({ r2Key: "proxy" });
+ const opened = await tools.status("mine");
+ expect(opened.view.preview?.revision).toBe("cloud:4");
+ expect(opened.playback?.url).toContain("proxy");
+ const rendered = await tools.render("mine");
+ expect(rendered.view.preview?.id).toBe("job");
+ expect(rendered.playback?.url).toContain("proxy");
+ });
test("list returns only public project metadata and paging state", async () => {
const { tools, db } = createTestContext();
const result = await tools.list();
diff --git a/site/src/clients/chatgpt/server/projects.ts b/site/src/clients/chatgpt/server/projects.ts
index 096b8da1..8dfc95be 100644
--- a/site/src/clients/chatgpt/server/projects.ts
+++ b/site/src/clients/chatgpt/server/projects.ts
@@ -72,17 +72,21 @@ export function projectTools(
account: null,
});
- async function getOwnedProject(projectId: string) {
+ async function getOwnedRow(projectId: string) {
const row = await db.cutProject.findFirst({
where: { id: projectId, userId: identity.userId },
- select: { id: true, name: true, version: true },
+ select: { id: true, name: true, version: true, previewKey: true },
});
if (!row) {
throw new ProjectToolError(
"Project not found. Choose one of your cloud projects.",
);
}
- return projectSummary(row);
+ return row;
+ }
+
+ async function getOwnedProject(projectId: string) {
+ return projectSummary(await getOwnedRow(projectId));
}
/** The project view with its undo state, as every edit tool answers. */
@@ -105,7 +109,8 @@ export function projectTools(
projectId: string,
jobId?: string,
): Promise<ProjectResult> {
- const selectedProject = await getOwnedProject(projectId);
+ const row = await getOwnedRow(projectId);
+ const selectedProject = projectSummary(row);
const job = await db.cutRenderJob.findFirst({
where: {
userId: identity.userId,
@@ -142,7 +147,12 @@ export function projectTools(
id: job.id,
status,
progress: Math.max(0, Math.min(1, job.progress)),
- revision: (job.spec as { revision?: string } | null)?.revision ?? null,
+ // The editor keeps previewKey on the proxy it rendered for the saved
+ // document, and the share page serves that pointer as current; so does
+ // this card, so a project plays the moment it opens.
+ revision:
+ (job.spec as { revision?: string } | null)?.revision ??
+ (job.outputKey && job.outputKey === row.previewKey ? selectedProject.revision : null),
};
if (status === "error") {
view.preview.error = "Preview could not finish. Render a new preview.";
@@ -278,6 +288,8 @@ export function projectTools(
"Reconnect Donkey Cut with preview rendering permission.",
);
}
+ const current = await getPreviewStatus(projectId);
+ if (current.playback && current.view.preview?.revision === current.view.project?.revision) return current;
const job = await previewFromDoc(identity.userId, projectId);
if (!job) {
throw new ProjectToolError(