Open source CapCut alternative.
TypeScript
feat(cut): quote a fetched post's own text in the chat beside its media [rebuild]
David Lef8beb1697d30
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsxindex 50ea22b9..e7b7d45b 100644--- a/site/src/cut/components/AiPanel.tsx+++ b/site/src/cut/components/AiPanel.tsx@@ -1210,6 +1210,12 @@ const MessageView = memo(function MessageView({.map((part) => part as unknown as { state: string; output?: unknown }).filter((p) => p.state === "output-available").map((p) => p.output);+ // The source's own words for anything the turn pulled off the web (a tweet's+ // body, a video's title/description). It renders as a quote beside the media+ // — straight from the tool output, so the model never has to retype it.+ const sourceTexts = toolOutputs+ .map((o) => (o && typeof o === "object" ? (o as { sourceText?: unknown }).sourceText : undefined))+ .filter((t): t is string => typeof t === "string" && t.trim().length > 0);return (<div className="ai-msg-assistant group mb-3 flex min-w-0 flex-col gap-1.5">{message.parts.map((part, i) => {@@ -1292,6 +1298,16 @@ const MessageView = memo(function MessageView({}return null;})}+ {/* The imported post's own text, quoted above its media so the two read+ as one thing — the tweet body, or the video's title and description. */}+ {sourceTexts.map((t, i) => (+ <blockquote+ key={`src-${i}`}+ className="border-l-2 border-border pl-3 text-[12.5px] leading-relaxed break-words whitespace-pre-wrap text-muted-foreground"+ >+ {t}+ </blockquote>+ ))}{/* Everything the turn generated, in one left-to-right row (images andclips flow and wrap; audio and documents take their own line). Itstays in the chat until the user drags it out or files it away. */}diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex cbd92b2a..dc6695b3 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -980,7 +980,7 @@ export async function runAiTool(kind: asset.type,duration: round2(asset.type === "image" ? IMAGE_CLIP_SECONDS : asset.duration),})),- ...(text ? { postText: text } : {}),+ ...(text ? { sourceText: text } : {}),};}diff --git a/site/src/cut/lib/media.ts b/site/src/cut/lib/media.tsindex 3e48d431..7d717b3f 100644--- a/site/src/cut/lib/media.ts+++ b/site/src/cut/lib/media.ts@@ -243,7 +243,7 @@ export async function importStockMusic(* through the engine's bundled downloader and register what came back — one* asset for a video, one per photo for a photo tweet — without placing* anything on the timeline. Callers choose where assets land. `text` is the- * post text when the URL was a tweet. */+ * source's own words — a tweet's body, or a video's title and description. */export async function importUrlMedia(projectId: string,url: stringdiff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex 3994c47c..5cadcc20 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -393,7 +393,7 @@ export const AI_TOOLS: AiToolDef[] = [{name: "import_url",description:- "Download a media URL — TikTok, YouTube, Instagram Reels, an X/Twitter post, or a direct video/audio/image link — with the bundled downloader and import it into the project. An X post yields its video, or every photo plus the post text (postText). Free and local. Each asset lands on a card in this chat, and the user drags it from there to the timeline, Media, or the Library; place it yourself (add_clip) only when they asked for it in the cut. A short clip downloads in seconds; a long video can take a couple of minutes.",+ "Download a media URL — TikTok, YouTube, Instagram Reels, an X/Twitter post, or a direct video/audio/image link — with the bundled downloader and import it into the project. Free and local. Each asset lands on a card in this chat, and the source's own text (a tweet's body, a video's title and description; returned as sourceText) is quoted for the user beside the media automatically — don't retype it in your reply. The user drags a card to the timeline, Media, or the Library; place it yourself (add_clip) only when they asked for it in the cut. A short clip downloads in seconds; a long video can take a couple of minutes.",inputSchema: obj({ url: str("The page or media URL to download") }, ["url"]),},{@@ -783,7 +783,7 @@ Project media (\`media\` in editor_state) is every file in the open project. TheThe Library is shared across every project: folders, reusable assets, and templates — a template is a saved arrangement (clips, overlays, titles, captions, by reference) that comes back editable.- library_list browses it; library_add copies an asset into the project (the import step "library"-scope attachments need); template_add re-materializes a template; save_template saves timeline items as one.- library_organize handles folders (create/rename/delete), filing (move_asset), and deletes (permanent — explicit ask only).-- import_url downloads a media URL (TikTok, YouTube, Instagram, direct links) into the project as a card in the chat; the user drags it to the timeline, Media, or the Library. Place it with add_clip only when they asked for it in the cut.+- import_url downloads a media URL (TikTok, YouTube, Instagram, direct links) into the project as a card in the chat, with the source's own text quoted beside it; the user drags it to the timeline, Media, or the Library. Place it with add_clip only when they asked for it in the cut.Attachments: media files dropped on the chat import into project media by themselves; library attachments wait for library_add.`,"publish-and-export": `# Publish & exportdiff --git a/site/src/cut/server/urlImport.ts b/site/src/cut/server/urlImport.tsindex 4974f63f..5de78d79 100644--- a/site/src/cut/server/urlImport.ts+++ b/site/src/cut/server/urlImport.ts@@ -20,6 +20,7 @@ let active = 0;interface YtMeta {title?: string;+ description?: string;uploader?: string;upload_date?: string;webpage_url?: string;@@ -28,13 +29,33 @@ interface YtMeta {/** What a finished download hands its consumer: the media files (inside a* temp dir the wrapper deletes afterwards — one for yt-dlp's merged output,* one per photo for a photo tweet) plus what the extractor knew about them.- * `text` is the full post text when the URL was a tweet. */+ * `text` is the source's own words — a tweet's body, or a video's title and+ * description — shown in the chat beside the media it came with. */interface Downloaded {files: { file: string; title: string }[];source: LibrarySource;text?: string;}+// A video's own words for the chat: its title and description joined, capped so+// a long YouTube description (link dumps, chapter lists) can't flood the chat.+// TikTok/Instagram often repeat the caption as both fields, so drop a+// description that just restates the title.+const MAX_SOURCE_TEXT = 2000;+function sourceTextFromMeta(meta: YtMeta): string | undefined {+ const title = (meta.title || "").trim();+ const desc = (meta.description || "").trim();+ const body =+ desc && desc !== title && !desc.startsWith(title)+ ? title+ ? `${title}\n\n${desc}`+ : desc+ : title || desc;+ const text = body.trim();+ if (!text) return undefined;+ return text.length > MAX_SOURCE_TEXT ? `${text.slice(0, MAX_SOURCE_TEXT).trimEnd()}…` : text;+}+/** Run one guarded download and hand the files to `consume` before the temp* dir is deleted. The active slot spans the whole operation; mkdtemp runs* inside the try so a failure there still releases the slot (else a rejection@@ -125,6 +146,7 @@ async function downloadMedia(url: string, tmp: string): Promise<Downloaded> {uploader: meta.uploader,uploadDate: meta.upload_date,},+ text: sourceTextFromMeta(meta),};}