Open source CapCut alternative.
TypeScript
fix(cut): format chat file sizes in readable units [rebuild]
David Le44f460ee64dc
diff --git a/site/src/cut/components/AiPanel.tools.ts b/site/src/cut/components/AiPanel.tools.tsindex 01d60736..24180495 100644--- a/site/src/cut/components/AiPanel.tools.ts+++ b/site/src/cut/components/AiPanel.tools.ts@@ -20,7 +20,7 @@ export const AI_PANEL_TOOLS = [{name: "get_asset_info",description:- "Read a project asset's file name, kind, exact file size in bytes, duration in seconds, and pixel dimensions. Use this for file-size questions when sizeBytes is absent from the media snapshot. Reads file metadata across browser, Mac, and cloud storage.",+ "Read a project asset's file name, kind, readable fileSize (KB, MB, GB), exact sizeBytes, duration in seconds, and pixel dimensions. Present fileSize in replies; include exact bytes only when asked. Use this for file-size questions when sizeBytes is absent from the media snapshot. Reads file metadata across browser, Mac, and cloud storage.",inputSchema: obj({ asset_id: str("Project asset id from media or an import result") }, ["asset_id"]),},{diff --git a/site/src/cut/lib/aiContext.test.ts b/site/src/cut/lib/aiContext.test.tsindex 25affa81..f3b86c40 100644--- a/site/src/cut/lib/aiContext.test.ts+++ b/site/src/cut/lib/aiContext.test.ts@@ -45,7 +45,7 @@ describe("describeDoc", () => {const assets = doc.assets.map((a) => ({ ...a, url: "" }));doc.assets = storedAssets(assets);await useEditor.getState().openProjectDoc("file-info", doc, assets);- const expected = { fileName: doc.assets[0].fileName, sizeBytes: 21_000_001, width: 320, height: 240 };+ const expected = { fileName: doc.assets[0].fileName, sizeBytes: 21_000_001, fileSize: "20 MB", width: 320, height: 240 };expect(buildAiContext({ chatId: null }).media[0]).toMatchObject(expected);expect(describeDoc(doc).media[0]).toMatchObject(expected);expect(describeDoc(doc).media[0].duration).toBe(doc.assets[0].duration);diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.tsindex 0f4b0f7d..977118ba 100644--- a/site/src/cut/lib/aiContext.ts+++ b/site/src/cut/lib/aiContext.ts@@ -1,5 +1,6 @@"use client";+import { formatBytes } from "@/lib/bytes";import { GUIDE_PRESETS, guideFits, guideGeometry, safeAreaOf, sanitizeGuideLines, sanitizeGuides, type GuideId, type GuideLines } from "./guides";import { hasOverlayAnim, retimeOf, speedCurveOf, type ClipSound, type SpeedNode } from "@donkeycut/effects-kit";import { chatOwner } from "./chatAssets";@@ -419,7 +420,7 @@ function describeState(name: a.name,type: a.type,fileName: a.fileName,- ...(a.sizeBytes !== undefined ? { sizeBytes: a.sizeBytes } : {}),+ ...(a.sizeBytes !== undefined ? { sizeBytes: a.sizeBytes, fileSize: formatBytes(a.sizeBytes) } : {}),...(a.width !== undefined ? { width: a.width } : {}),...(a.height !== undefined ? { height: a.height } : {}),duration: r(a.duration),diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 4f38819c..e9dc3718 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -1,5 +1,6 @@"use client";+import { formatBytes } from "@/lib/bytes";import { projectRevision } from "@/cut/lib/projectRevision";import { assertProjectCommand } from "./projectCommands";import { projectOperation, type ProjectOperation } from "./projectOperation";@@ -855,7 +856,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {const sizeBytes = asset.sizeBytes ?? await readMediaFileSize(asset.url);return {assetId: asset.id, name: asset.name, fileName: asset.fileName, kind: asset.type,- sizeBytes, duration: round2(asset.duration), width: asset.width, height: asset.height,+ sizeBytes, fileSize: formatBytes(sizeBytes), duration: round2(asset.duration), width: asset.width, height: asset.height,};},diff --git a/site/src/cut/lib/assetInfo.test.ts b/site/src/cut/lib/assetInfo.test.tsindex 82300311..0c2b5212 100644--- a/site/src/cut/lib/assetInfo.test.ts+++ b/site/src/cut/lib/assetInfo.test.ts@@ -21,13 +21,13 @@ test("existing browser assets can report file size without saved metadata", asynconst url = registerBlobFile(path, new File([new Uint8Array(4321)], "test.png"));useEditor.setState({ assets: [{ ...asset, url }] });expect(await runAiTool("get_asset_info", { asset_id: asset.id })).toMatchObject({- sizeBytes: 4321, duration: 0, width: 320, height: 240, fileName: "test.png",+ sizeBytes: 4321, fileSize: "4 KB", duration: 0, width: 320, height: 240, fileName: "test.png",});});test("saved file size needs no media request", async () => {- useEditor.setState({ assets: [{ ...asset, sizeBytes: 21_000_000 }] });- expect(await runAiTool("get_asset_info", { asset_id: asset.id })).toMatchObject({ sizeBytes: 21_000_000 });+ useEditor.setState({ assets: [{ ...asset, sizeBytes: 21_988_779 }] });+ expect(await runAiTool("get_asset_info", { asset_id: asset.id })).toMatchObject({ sizeBytes: 21_988_779, fileSize: "21 MB" });});test("a generated placeholder has no source file", async () => {diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex 01c2ceef..6e04a9fe 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -572,6 +572,7 @@ export function systemPrompt(): string {return `You are the AI editor built into a video editor. Your voice is plain, warm, and brief. Describe your own output factually; superlatives about your own work — "masterpiece", "stunning", "incredibly", "professional-grade" and their kin — are banned. 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:+- Present file sizes using the readable fileSize value (KB, MB, GB), such as \"The original file is about 21 MB.\" Include exact byte counts only when asked.- 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, name what you could do as a statement ("I can clear the unused overlays — say the word"), 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.- Do what the newest message asks, then stop. The turns above are finished work: what an earlier reply already ran is recorded with it, and the snapshot shows where the project landed — start from there and leave settled work alone.- A further message from the user can arrive while you work. It is part of the current job: take it in — a refinement changes what you are doing, an addition gets done alongside, a correction is followed — and when it depends on the work in flight, finish that first. One you cannot do in this turn — it needs this turn's finished result, or a fresh look at the timeline after your cuts land — goes to queue_message in the user's words and runs as its own turn after this one. Your reply covers both asks.