Skip to content

Open source CapCut alternative.

TypeScript

feat(site): let chat hide clips and whole tracks [rebuild]

David Le3e1cfd171544
diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.ts
index 86a86d65..a39a2f55 100644
--- a/site/src/cut/lib/aiContext.ts
+++ b/site/src/cut/lib/aiContext.ts
@@ -83,6 +83,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu
start: r(sp.start),
len: r(sp.len),
muted: sp.clip.muted,
+ ...(sp.clip.hidden ? { hidden: true } : {}),
speed: r(sp.clip.speed ?? 1),
};
}
@@ -166,6 +167,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu
// A still has no source length; report its placed length instead of 0.
sourceDuration: r(sp.asset.type === "image" ? sp.len : sp.asset.duration),
muted: sp.clip.muted,
+ ...(sp.clip.hidden ? { hidden: true } : {}),
framing: sp.clip.fit ?? "fit",
speed: r(sp.clip.speed ?? 1),
// The generated scene shot this clip came from — sceneShot is the
@@ -220,6 +222,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu
s.subtitles.tracks?.[i]?.locale ??
(i === 0 ? s.subtitles.locale ?? "en-US" : undefined),
cues: laneCues(s.subtitles, i).length,
+ ...(s.subtitles.tracks?.[i]?.hidden ? { hidden: true } : {}),
})),
status: s.subtitleStatus,
// A window of cues by default; when truncated the model calls get_state
@@ -243,7 +246,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu
}
function describeAudio(
- a: { assetId: string; start: number; in: number; out: number; volume: number; fadeIn?: number; fadeOut?: number; speed?: number; duck?: number; lane?: number },
+ a: { assetId: string; start: number; in: number; out: number; volume: number; fadeIn?: number; fadeOut?: number; speed?: number; duck?: number; lane?: number; hidden?: boolean },
assets: Map<string, { name: string }>
) {
const speed = a.speed && a.speed > 0 ? a.speed : 1;
@@ -258,6 +261,7 @@ function describeAudio(
fadeOut: r(a.fadeOut ?? 0),
...(speed !== 1 ? { speed: r(speed) } : {}),
...(a.lane ? { lane: a.lane } : {}),
+ ...(a.hidden ? { hidden: true } : {}),
// A voiceover: while it plays, other audio ducks to this gain.
...(a.duck !== undefined ? { duck: r(a.duck) } : {}),
};
@@ -288,7 +292,7 @@ function describeOverlayClip(c: VideoClip, assets: Map<string, { name: string }>
function describeOverlay(o: {
text: string; start: number; end: number; x: number; y: number;
size: number; font: string; weight: number; color: string; shadow: boolean; plate: boolean;
- plateRadius?: number; lane?: number;
+ plateRadius?: number; lane?: number; hidden?: boolean;
}) {
return {
text: o.text,
@@ -304,5 +308,6 @@ function describeOverlay(o: {
plate: o.plate,
...(o.plateRadius !== undefined && { plateRadius: r(o.plateRadius) }),
...(o.lane ? { lane: o.lane } : {}),
+ ...(o.hidden ? { hidden: true } : {}),
};
}
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index 5e7ec4c5..e4dd1e0d 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -537,6 +537,58 @@ export async function runAiTool(
return { id: next.id, volume: next.volume ?? 1 };
}
+ case "set_clip_hidden": {
+ const clip = requireItem(s.clips, input.clipId, "video clip");
+ s.updateClip(clip.id, { hidden: input.hidden ? true : undefined });
+ return { id: clip.id, hidden: Boolean(input.hidden) };
+ }
+
+ case "set_track_hidden": {
+ if (!isNum(input.track) || input.track < 0)
+ throw new ToolError("track must be 0 or higher.");
+ const track = Math.round(input.track);
+ const hidden = Boolean(input.hidden);
+ switch (input.kind) {
+ case "video": {
+ const n = s.clips.filter((c) => c.track === track).length;
+ if (!n) throw new ToolError(`No clips on video track ${track}.`);
+ s.setTrackHidden(track, hidden);
+ return { kind: "video", track, hidden, clips: n };
+ }
+ case "soundtrack": {
+ const n = s.audioClips.filter((a) => (a.lane ?? 0) === track).length;
+ if (!n) throw new ToolError(`No clips on soundtrack lane ${track}.`);
+ s.setAudioLaneHidden(track, hidden);
+ return { kind: "soundtrack", track, hidden, clips: n };
+ }
+ case "text": {
+ const n = s.overlays.filter((o) => (o.lane ?? 0) === track).length;
+ if (!n) throw new ToolError(`No titles on text track ${track}.`);
+ s.setTextLaneHidden(track, hidden);
+ return { kind: "text", track, hidden, titles: n };
+ }
+ case "subtitles": {
+ const count = subtitleLaneCount(s.subtitles);
+ if (track >= count)
+ throw new ToolError(`No subtitle track ${track} — tracks 0–${count - 1} exist.`);
+ s.setSubtitleTrackMeta(track, { hidden: hidden ? true : undefined });
+ return { kind: "subtitles", track, hidden, cues: laneCues(s.subtitles, track).length };
+ }
+ default:
+ throw new ToolError('`kind` must be "video", "soundtrack", "text", or "subtitles".');
+ }
+ }
+
+ case "set_track_muted": {
+ if (!isNum(input.track) || input.track < 0)
+ throw new ToolError("track must be 0 or higher.");
+ const track = Math.round(input.track);
+ const n = s.clips.filter((c) => c.track === track).length;
+ if (!n) throw new ToolError(`No clips on video track ${track}.`);
+ s.setTrackMuted(track, Boolean(input.muted));
+ return { track, muted: Boolean(input.muted), clips: n };
+ }
+
case "detach_audio": {
const id = input.clipId ? String(input.clipId) : s.selection?.kind === "clip" ? s.selection.id : null;
if (!id) throw new ToolError("Pass clipId or select a video clip first.");
@@ -611,6 +663,7 @@ export async function runAiTool(
Math.abs(input.speed - 1) < 1e-4 ? undefined : Math.max(SPEED_FLOOR, input.speed);
// duck >= 1 clears ducking (undefined); below 1 sets the gain.
if (isNum(input.duck)) patch.duck = input.duck >= 1 ? undefined : clamp(input.duck, 0, 1);
+ if (typeof input.hidden === "boolean") patch.hidden = input.hidden || undefined;
if (isNum(patch.in ?? NaN) || isNum(patch.out ?? NaN)) {
const nIn = patch.in ?? a.in;
const nOut = patch.out ?? a.out;
@@ -2158,5 +2211,6 @@ function titlePatch(input: Record<string, unknown>) {
if (typeof input.shadow === "boolean") patch.shadow = input.shadow;
if (typeof input.plate === "boolean") patch.plate = input.plate;
if (isNum(input.plateRadius)) patch.plateRadius = clamp(input.plateRadius, 0, 1);
+ if (typeof input.hidden === "boolean") patch.hidden = input.hidden || undefined;
return patch;
}
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index b079445a..60d7634a 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -155,6 +155,28 @@ export const AI_TOOLS: AiToolDef[] = [
description: "Set the gain on a video clip's own audio (soundtrack clips use update_audio).",
inputSchema: obj({ clipId: str("Video clip id"), volume: num("0..1.5 (1 = unchanged)") }, ["clipId", "volume"]),
},
+ {
+ name: "set_clip_hidden",
+ description:
+ "Hide or show a video clip on any track. A hidden clip stays on the timeline (grayed) but is excluded from playback and export — its span plays black and silent on track 0; an overlay layer just disappears.",
+ inputSchema: obj({ clipId: str("Video clip id"), hidden: bool("true to hide") }, ["clipId", "hidden"]),
+ },
+ {
+ name: "set_track_hidden",
+ description:
+ "Hide or show a whole timeline row at once — the track header's eye toggle. Applies to every item on that row: a hidden video track plays black and silent, a hidden soundtrack lane is silent, hidden text (title) lanes and subtitle tracks drop out of the picture. Items stay on the timeline, grayed.",
+ inputSchema: obj({
+ kind: { type: "string", enum: ["video", "soundtrack", "text", "subtitles"], description: "Which row kind" },
+ track: num("Track/lane index, 0-based"),
+ hidden: bool("true to hide"),
+ }, ["kind", "track", "hidden"]),
+ },
+ {
+ name: "set_track_muted",
+ description:
+ "Mute or unmute every clip on one video track at once — the track header's speaker toggle. The picture keeps playing.",
+ inputSchema: obj({ track: num("Video track index, 0-based"), muted: bool("true to mute") }, ["track", "muted"]),
+ },
{
name: "detach_audio",
description:
@@ -256,12 +278,13 @@ export const AI_TOOLS: AiToolDef[] = [
weight: { type: "number", enum: [400, 700], description: "Font weight" },
shadow: bool("Drop shadow"),
plate: bool("Backdrop plate"),
+ hidden: bool("Hide the title without deleting it"),
}, ["id"]),
},
{
name: "update_audio",
description:
- "Update a soundtrack clip: volume (0..1.5), fadeIn/fadeOut seconds, start position, in/out trim, speed, or duck. `duck` is voiceover ducking — while this clip plays, ALL other audio (video-clip sound and other music) drops to that gain (0..1); pass 1 to clear ducking. Use it to make a voiceover sit over quieter music.",
+ "Update a soundtrack clip: volume (0..1.5), fadeIn/fadeOut seconds, start position, in/out trim, speed, hidden, or duck. `duck` is voiceover ducking — while this clip plays, ALL other audio (video-clip sound and other music) drops to that gain (0..1); pass 1 to clear ducking. Use it to make a voiceover sit over quieter music.",
inputSchema: obj({
id: str("Soundtrack clip id"),
volume: num("0..1.5"),
@@ -272,6 +295,7 @@ export const AI_TOOLS: AiToolDef[] = [
out: num("Source out s"),
speed: num("Playback rate (1 = normal, no upper limit)"),
duck: num("Duck other audio to this gain while this clip plays, 0..1 (1 clears ducking)"),
+ hidden: bool("Silence the clip without removing it (grayed on the timeline)"),
}, ["id"]),
},
{
@@ -761,6 +785,7 @@ Times are in seconds on the shared timeline. The playhead is currentTime; a skim
- set_transition joins a clip into the next one (0–2s, 17 styles); set_animation animates one clip's own entrance/exit; set_look grades its picture with a preset filter — read the transitions-and-fades skill before styling cuts. Splitting or deleting clears the affected transition.
- split_at cuts the track-0 clip under that time into two clips at the exact frame. With a soundtrack or overlay clip selected it splits that instead.
- The user can multi-select (⌘/⇧-click) and delete several items at once; a hover chip on each video clip toggles its own audio.
+- Anything can be hidden instead of deleted: it stays on the timeline (grayed) but drops out of playback and export — a hidden video clip plays black and silent. Per item: set_clip_hidden, or the \`hidden\` field on update_overlay_video/update_title/update_audio. Whole rows: set_track_hidden (video/soundtrack/text/subtitles) and set_track_muted (video) — the eye/speaker toggles on the track headers.
- detach_audio lifts a video clip's sound to the soundtrack track (and mutes the clip) so audio can be cut independently of video.
- freeze_frame grabs one frame (default: the playhead — what the user currently sees) as a still clip and inserts it, by default at index 0 as a cover/hook frame ("make this the first frame"). The still is baked at the project's current aspect with the clip's framing applied; if the user later switches aspect they should capture a fresh one.
- set_framing: per-clip Fit (letterbox) vs Fill (crop to cover the project frame). In Fill, panX/panY position the crop window; the user can also drag the video directly in the preview. The control lives in the Inspector under "Framing" when a video clip is selected. Landscape footage usually wants fill + a pan that keeps the subject.