Skip to content

Open source CapCut alternative.

TypeScript

feat(site): chat video refs stage a designed opening frame [rebuild]

David Le1b9363df8f74
diff --git a/site/src/cut/components/ChatAssets.tsx b/site/src/cut/components/ChatAssets.tsx
index 7e0f2813..7876ca57 100644
--- a/site/src/cut/components/ChatAssets.tsx
+++ b/site/src/cut/components/ChatAssets.tsx
@@ -66,13 +66,21 @@ export function ChatProjectAsset({ assetId }: { assetId: string }) {
}
/** The assets a finished tool call produced, from its typed output fields:
- * `assetId` for landed media, `jobId` for a video render still in flight. */
+ * `assetId` for landed media, `jobId` for a video render still in flight,
+ * `stillAssetId` for a staged render's opening frame (shown above its job). */
export function ToolOutputAssets({ output }: { output: unknown }) {
if (!output || typeof output !== "object") return null;
- const o = output as { assetId?: unknown; jobId?: unknown };
- if (typeof o.assetId === "string") return <ChatProjectAsset assetId={o.assetId} />;
- if (typeof o.jobId === "string") return <ChatVideoJobCard jobId={o.jobId} />;
- return null;
+ const o = output as { assetId?: unknown; jobId?: unknown; stillAssetId?: unknown };
+ return (
+ <>
+ {typeof o.stillAssetId === "string" && <ChatProjectAsset assetId={o.stillAssetId} />}
+ {typeof o.assetId === "string" ? (
+ <ChatProjectAsset assetId={o.assetId} />
+ ) : typeof o.jobId === "string" ? (
+ <ChatVideoJobCard jobId={o.jobId} />
+ ) : null}
+ </>
+ );
}
/** A video render the tool started but couldn't wait out: a live card that
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index 12a4e2e2..a9e47d1d 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -614,7 +614,7 @@ export async function runAiTool(
input.reference_asset_id === undefined
? []
: resolveRefAssets([input.reference_asset_id]);
- return launchVeoJob(projectId, prompt, input, {
+ const veoOpts: Omit<VideoGenOptions, "onDone"> = {
tier: input.tier === "high" ? "high" : "fast",
durationSeconds: isNum(input.duration_seconds)
? clamp(Math.round(input.duration_seconds), 4, 8)
@@ -623,6 +623,44 @@ export async function runAiTool(
...(input.resolution === "720p" || input.resolution === "1080p"
? { resolution: input.resolution }
: {}),
+ };
+ // Staged, like the scene pipeline: reference work happens in the image
+ // model first — it holds identity far better than any video model — and
+ // the video model then animates the approved frame. The still lands as
+ // a chat asset (its card previews above the render's), and the render
+ // seeds from it with the prompt as written. Text-only asks skip
+ // straight to video; a failed still degrades to the composed-seed hop.
+ if (refs.length > 0) {
+ const still = await gen.generateImage(projectId, prompt, {
+ refs,
+ aspect:
+ input.aspect === "16:9" || input.aspect === "9:16"
+ ? input.aspect
+ : useEditor.getState().aspect,
+ chatId: chatOwner() ?? undefined,
+ });
+ const stillAsset =
+ still.status === "done" && still.assetId
+ ? useEditor.getState().assets.find((a) => a.id === still.assetId)
+ : undefined;
+ if (stillAsset) {
+ return {
+ ...launchVeoJob(projectId, prompt, input, {
+ ...veoOpts,
+ refs: [refFromAsset(stillAsset)],
+ composeRefs: false,
+ // The most Veo permits with an image input; the seed carries
+ // the subject, so a person-safety downgrade beats losing it.
+ personGeneration: "ALLOW_ADULT",
+ }),
+ stillAssetId: stillAsset.id,
+ note:
+ "Designed the opening frame from the reference first (the image card above the render), then started the video from that exact frame — it previews in this chat when it lands, in a minute or two.",
+ };
+ }
+ }
+ return launchVeoJob(projectId, prompt, input, {
+ ...veoOpts,
...(refs.length > 0 ? { refs } : {}),
});
}
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index 4a173460..13f30231 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -287,14 +287,14 @@ export const AI_TOOLS: AiToolDef[] = [
{
name: "generate_video",
description:
- "Generate an AI video clip from a text prompt (Donkey's hosted Veo model). Use for B-roll or shots the user doesn't have footage for; when the user asks you to write or improve the prompt itself, put it in chat and wait for them to ask for the video. reference_asset_id seeds the render with one project image or video frame (it becomes the opening frame when the subject is used as-is). This renders remotely and takes a minute or two, so the tool RETURNS IMMEDIATELY — the clip previews as a live card in this chat (and in the Video panel's renders) when it finishes. Tell the user it's rendering. Pass add_to_timeline:true (or an index) only when they asked for it in the cut; otherwise the user drags it in from the card. Needs the user signed in to Donkey (spends their credits).",
+ "Generate an AI video clip from a text prompt (Donkey's hosted Veo model) — the default for any video ask: \"generate/make a video of/about X\" means ONE clip from this tool, even though it sounds whole. Reach for generate_scene only when they name a narrated multi-shot production (a story, episode, or narrated short). When the user asks you to write or improve the prompt itself, put it in chat and wait for them to ask for the video. reference_asset_id anchors the render on one project image or video: the tool first designs the opening frame from it with the image model (that still previews in this chat), then animates that exact frame — so tell the user it designs the frame, then renders. The render takes a minute or two and the tool RETURNS as soon as it's started — the clip previews as a live card in this chat (and in the Video panel's renders) when it finishes. Pass add_to_timeline:true (or an index) only when they asked for it in the cut; otherwise the user drags it in from the card. Needs the user signed in to Donkey (spends their credits).",
inputSchema: obj({
prompt: str("The shot to generate — describe motion, subject, and mood"),
tier: { type: "string", enum: ["fast", "high"], description: "fast = quicker/cheaper (default), high = best quality" },
duration_seconds: num("Clip length 4–8 seconds (default 8)"),
aspect: { type: "string", enum: ["16:9", "9:16"], description: "Clip shape (default: the project aspect)" },
resolution: { type: "string", enum: ["720p", "1080p"], description: "Output detail (default 720p)" },
- reference_asset_id: str("One project asset id (image or video) to seed the render"),
+ reference_asset_id: str("One project asset id (image or video) the clip's opening frame is designed from"),
add_to_timeline: bool("Insert the clip on the video track when it lands (default false — it stays on its chat card until the user asks)"),
index: num("Insert position on the video track (passing it implies add_to_timeline)"),
}, ["prompt"]),
@@ -315,7 +315,7 @@ export const AI_TOOLS: AiToolDef[] = [
{
name: "generate_scene",
description:
- "Generate a WHOLE short video — a narrated, multi-shot cut assembled on the timeline — from a brief, or animate audio already in the project. Use this when the user wants a complete video/scene/story (\"make me a video about…\", \"turn this into a 20-second short\"), not a single clip (that's generate_video). It writes a script, voices it, breaks it into shots, then RETURNS the shot plan and STOPS: get the user's go-ahead and call approve_scene before the shots render, because each shot spends credits. Pass from_audio_asset_id to animate an audio spine the project already has (a voiceover, recording, or song → shots tiled over it) instead of writing a new script. The look is derived from the brief and any references and can be anything — cinematic live-action, anime, documentary, product ad, cartoon; never assume a genre, let the brief decide, and describe the look by its visual traits rather than naming a real franchise, show, or artist (even one a reference resembles) — the user may not want it and the generator rejects trademarked names. Needs the user signed in to Donkey (spends credits).",
+ "Generate a narrated, multi-shot cut assembled on the timeline — script, voiceover, and several shots — from a brief, or animate audio already in the project. Use this only when the user names that kind of production (\"tell a story about…\", \"turn this into a narrated 20-second short\", \"an episode\"); a plain \"generate/make a video of/about X\" is a single clip — generate_video, not this. It writes a script, voices it, breaks it into shots, then RETURNS the shot plan and STOPS: get the user's go-ahead and call approve_scene before the shots render, because each shot spends credits. Pass from_audio_asset_id to animate an audio spine the project already has (a voiceover, recording, or song → shots tiled over it) instead of writing a new script. The look is derived from the brief and any references and can be anything — cinematic live-action, anime, documentary, product ad, cartoon; never assume a genre, let the brief decide, and describe the look by its visual traits rather than naming a real franchise, show, or artist (even one a reference resembles) — the user may not want it and the generator rejects trademarked names. Needs the user signed in to Donkey (spends credits).",
inputSchema: obj({
brief: str("What the video is about — the story or subject. Omit only when animating existing audio."),
from_audio_asset_id: str("Animate this project audio asset (id from media) — shots tile over it instead of a new script"),
@@ -712,9 +712,9 @@ Two ways to get footage the user doesn't have: bundled stock (local, free) and h
Stock: stock_search browses the bundled catalogs — footage clips and images in 8 categories plus ~20 UGC talking characters — matching prompts, categories, and tags. stock_add imports an item into the project as a chat card; add_to_timeline:true (or a start) also drops it on the timeline when the user asked. In the UI these live in the Video and Image tabs beside the generators; clicking a stock tile seeds the generate panel with its prompt.
Generation:
- generate_image(prompt, aspect?, resolution?, reference_asset_ids?, add_to_timeline?, index?): the hosted image model renders the prompt at 16:9, 9:16, or 1:1 (default: project aspect) and 1K/2K/4K. The still previews in the chat; placed (add_to_timeline:true or an index) it rides video track 0 as a still clip (8s default, stretchable). Great for a cover/hook frame (index 0), a background, or a b-roll still.
-- generate_video(prompt, tier?, duration_seconds?, aspect?, resolution?, reference_asset_id?, add_to_timeline?, index?): a hosted Veo model renders a 4–8s clip with audio. tier "fast" (default) is quicker/cheaper, "high" is best quality. This takes a minute or two, so the tool returns right away and the clip previews in the chat and the Video panel's renders when it finishes (on the timeline only when asked) — tell the user it's rendering. Don't call it again for the same shot while one is in flight.
+- generate_video(prompt, tier?, duration_seconds?, aspect?, resolution?, reference_asset_id?, add_to_timeline?, index?): a hosted Veo model renders a 4–8s clip with audio. tier "fast" (default) is quicker/cheaper, "high" is best quality. With reference_asset_id it stages: the image model designs the opening frame from the reference first (that still previews in the chat), then Veo animates that exact frame. The render takes a minute or two, so the tool returns once it's started and the clip previews in the chat and the Video panel's renders when it finishes (on the timeline only when asked) — tell the user it's rendering. Don't call it again for the same shot while one is in flight.
- generate_character_video(character_id, line, …): a stock talking character delivers a line to camera, same async render as generate_video. Characters come from stock_search kind:"character" — each has a persona; you write the line (chat deliverable rules apply: asked for "a script", write it in chat first).
-References: users attach images/clips to their message or the generate panels; project asset ids (see \`media\` in editor_state, including attachments — OS drops become project assets) pass through reference_asset_ids / reference_asset_id. A model recomposes the prompt around them: for video at most one image survives as the literal opening frame; for images any number can be drawn from. When the user says "use this clip/image", pass the reference — don't just describe it in the prompt.
+References: users attach images/clips to their message or the generate panels; project asset ids (see \`media\` in editor_state, including attachments — OS drops become project assets) pass through reference_asset_ids / reference_asset_id. Images draw from any number of references; video stages one reference into a designed opening frame and animates it. When the user says "use this clip/image", pass the reference — don't just describe it in the prompt.
If generation fails with a sign-in or credits message, relay that plainly — it needs the user signed in to Donkey with credits; it is not a local fallback. Write vivid, specific prompts (subject, style, lighting, motion); the user's request is usually shorthand, so flesh it out.`,
"media-and-library": `# Media, Library & organizing
@@ -737,16 +737,16 @@ export function systemPrompt(): string {
return `You are the AI editor built into a video editor. Your voice is kind with a light sense of humor — warm first, one small joke at most, and always clear about what you did. You see the user's project through the <editor_state> snapshot attached to each message and through your tools, and you edit it by calling tools — the user watches changes land live.
Rules:
-- First decide what the user wants handed back: an edit to the project, or words in chat. "Give me / write me a prompt, script, caption, ideas, a translation" asks for the text itself — write it in chat and leave the project untouched, even though a tool could act on it; they'll say "do it" or "add it" when they want it applied (and a follow-up like "in Korean" or "shorter" revises the text, keeping the same deliverable). When they do ask for a change to the project, act directly with tools; don't describe steps they should click through unless they ask how.
+- First decide what the user wants handed back: an edit to the project, or words in chat. "Give me / write me a prompt, script, caption, ideas, a translation" asks for the text itself — write it in chat and leave the project untouched, even though a tool could act on it; they'll say "do it" or "add it" when they want it applied (and a follow-up like "in Korean" or "shorter" revises the text, keeping the same deliverable). A complaint or observation ("ugh, this is cluttered") is words too: sympathize, offer what you could do, and touch nothing until they say go. When they do ask for a change to the project, act directly with tools; don't describe steps they should click through unless they ask how.
- Use ids exactly as given in the state, and act on what your tools return — each reports what it changed, so batch independent edits into one step and call get_state only when the snapshot is stale or a result surprised you.
- When the user says "this" (this clip, this text), they mean the current selection.
- Keep replies short and concrete — one or two sentences about what you did, in that warm, lightly funny voice. You have no name and never name the app; greet with a short "How can I help?" / "What would you like to do?". No headings, no fluff.
-- Edits are undoable (unlimited undo), so prefer doing over asking; only ask when the request is genuinely ambiguous. Generation is different: undo removes the clip but the credits stay spent, so be certain the user asked for the media before calling a generation tool. Removing media is different too — delete_asset and library_organize deletes don't come back with undo, so they take an explicit ask naming the media.
+- Edits are undoable (unlimited undo), so prefer doing over asking; only ask when the request is genuinely ambiguous. The existing cut is the user's work: adding media adds — never delete, trim, or reorder clips already on the timeline unless that's what they asked for. Generation is different: undo removes the clip but the credits stay spent, so be certain the user asked for the media before calling a generation tool. Removing media is different too — delete_asset and library_organize deletes don't come back with undo, so they take an explicit ask naming the media.
- Times are seconds. The frame is the project's aspect: 1080×1920 (9:16) or 1920×1080 (16:9) — see project.aspect in editor_state.
- Read list_skills / read_skill before working in an area you're unsure about — they document every setting.
- Don't transcribe a video with no speech. If the user wants captions on silent footage, use subtitles_from_visuals (it narrates what's on screen). Never invent a spoken transcript.
- Voiceovers duck other audio by default so they stay audible. Steer a voiceover's delivery with \`direction\` and inline tags like [whispers] rather than rewriting the script.
-- generate_image / generate_video / generate_character_video / voiceover_generate / read_subtitles_aloud make media through hosted models (spends the user's Donkey credits, needs sign-in); call them when the user asked for the media itself — a request for the prompt or script gets text in chat. Bundled stock media (stock_search / stock_add) is free — use it when it fits. Media the user attached is in \`media\`; pass those asset ids as generation references when they say "use this", and place project assets in the cut with add_clip when they ask for them there ("make a movie from these photos"). Generated media previews on a chat card the user can expand, drag in, or file away; add it to the timeline (add_to_timeline:true or an index) only when they asked for it in the cut. Write a rich, specific prompt from their shorthand. Video renders take a minute or two. For a whole video — a full scene or story, not one clip — generate_scene plans a narrated multi-shot cut and stops at the shot list; confirm with the user, then call approve_scene, since it renders many paid shots (regenerate_shot / restyle_scene revise it after).
+- generate_image / generate_video / generate_character_video / voiceover_generate / read_subtitles_aloud make media through hosted models (spends the user's Donkey credits, needs sign-in); call them when the user asked for the media itself — a request for the prompt or script gets text in chat. Bundled stock media (stock_search / stock_add) is free — use it when it fits. Media the user attached is in \`media\`; pass those asset ids as generation references when they say "use this", and place project assets in the cut with add_clip when they ask for them there ("make a movie from these photos"). Generated media previews on a chat card the user can expand, drag in, or file away; add it to the timeline (add_to_timeline:true or an index) only when they asked for it in the cut. Write a rich, specific prompt from their shorthand. Video renders take a minute or two. "Generate a video of/about X" means one generate_video clip; only when they name a narrated multi-shot production (a story, episode, narrated short) does generate_scene plan it and stop at the shot list — confirm with the user, then call approve_scene, since it renders many paid shots (regenerate_shot / restyle_scene revise it after).
- You can see and hear: audio the user attaches to their message plays right in it — answer "what does this say" from what you hear, no tool call. For project footage, watch_video samples a source's frames into timestamped contact sheets (scene changes included) — watch before cutting footage you haven't seen; listen_audio plays a project audio asset; detect_silence finds dead air; capture_frame shows the one rendered frame at the playhead. The watching-and-cutting skill has the flow.`;
}