Skip to content

Open source CapCut alternative.

TypeScript

feat(cut): let the chat open or collapse the side panel [rebuild]

David Le981bec13170c
diff --git a/site/src/cut/components/SidePanel.tsx b/site/src/cut/components/SidePanel.tsx
index 9f08c2a9..41017f03 100644
--- a/site/src/cut/components/SidePanel.tsx
+++ b/site/src/cut/components/SidePanel.tsx
@@ -59,6 +59,7 @@ import { useLocalPref } from "@/cut/lib/uiState";
import type { MediaAsset } from "@/cut/lib/types";
import { cn } from "@/lib/utils";
import { useRevealEffect, useRevealFlash } from "@/cut/lib/refReveal";
+import { usePanelRequestEffect, type SidePanelTab } from "@/cut/lib/panelRequest";
import { CopyNameLabel } from "./AssetRefs";
import { AudioCardFace, AudioPanel } from "./AudioPanel";
import { FolderCrumb, FolderShelf } from "./desktopFolders";
@@ -77,7 +78,7 @@ const LIBRARY_MOVE_MIME = "application/x-cut-library-move";
import { PlatformPreviewDialog, type ExportItem } from "./PlatformPreview";
import { SubtitlesPanel } from "./SubtitlesPanel";
-type Tab = "media" | "video" | "image" | "library" | "audio" | "subtitles" | "publish";
+type Tab = SidePanelTab;
const TABS: { id: Tab; label: string; icon: typeof Film }[] = [
{ id: "media", label: "Media", icon: Clapperboard },
@@ -152,6 +153,10 @@ export function SidePanel({
);
});
+ // The assistant's set_side_panel tool: open the tab it wants on screen, or
+ // collapse the panel so the canvas gets the room.
+ usePanelRequestEffect(setTab);
+
return (
<div className="flex min-h-0 border-r border-border bg-card">
{/* Icon rail — its divider drops when collapsed so the panel's outer
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index cbe7fb4b..404dac50 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -14,11 +14,12 @@ import {
deleteTemplate,
fetchLibrary,
importLibraryAsset,
- moveLibraryAsset,
+ moveLibraryItem,
renameLibraryFolder,
saveAssetToLibrary,
} from "./library";
import { enrichAsset, ensurePeaks, importImage, importStockVideo, importUrlMedia } from "./media";
+import { requestSidePanel, SIDE_PANEL_TABS, type SidePanelTab } from "./panelRequest";
import { blobToInlineAudio, refToInlineAudio, type InlineImage } from "./refMedia";
import { characterPrompt, stockTitle } from "./stock";
import { STOCK_IMAGES } from "./stockManifest";
@@ -277,6 +278,14 @@ export async function runAiTool(
return { selection: { kind: selKind, id } };
}
+ case "set_side_panel": {
+ const panel = String(input.panel);
+ if (panel !== "none" && !SIDE_PANEL_TABS.some((t) => t === panel))
+ throw new ToolError(`Unknown panel: ${panel}`);
+ requestSidePanel(panel === "none" ? null : (panel as SidePanelTab));
+ return { panel };
+ }
+
case "split_at": {
const before = s.clips.length + s.audioClips.length;
s.splitAtPlayhead(isNum(input.t) ? input.t : undefined);
@@ -1093,7 +1102,7 @@ export async function runAiTool(
case "move_asset": {
const folderId =
typeof input.folder_id === "string" && input.folder_id ? input.folder_id : null;
- await moveLibraryAsset(String(input.id ?? ""), folderId);
+ await moveLibraryItem(String(input.id ?? ""), folderId);
return { moved: true, folderId };
}
case "delete_asset": {
diff --git a/site/src/cut/lib/panelRequest.ts b/site/src/cut/lib/panelRequest.ts
new file mode 100644
index 00000000..7de54e40
--- /dev/null
+++ b/site/src/cut/lib/panelRequest.ts
@@ -0,0 +1,64 @@
+"use client";
+
+import { useEffect } from "react";
+import { create } from "zustand";
+
+// The assistant's set_side_panel tool lands here: a one-shot request the
+// SidePanel applies — open a tab, or collapse the panel to the icon rail so
+// the preview canvas takes the freed width.
+
+/** Side-panel tabs; `null` collapses the panel to the icon rail. */
+export type SidePanelTab =
+ | "media"
+ | "library"
+ | "video"
+ | "image"
+ | "audio"
+ | "subtitles"
+ | "publish";
+
+export const SIDE_PANEL_TABS: SidePanelTab[] = [
+ "media",
+ "library",
+ "video",
+ "image",
+ "audio",
+ "subtitles",
+ "publish",
+];
+
+interface PanelRequestState {
+ target: SidePanelTab | null;
+ /** Bumps per request so repeating the same target still fires the effect. */
+ seq: number;
+ /** Timestamp of the request; the effect ignores stale targets on remount. */
+ at: number;
+ request: (tab: SidePanelTab | null) => void;
+}
+
+const usePanelRequest = create<PanelRequestState>((set) => ({
+ target: null,
+ seq: 0,
+ at: 0,
+ request: (tab) => set((s) => ({ target: tab, seq: s.seq + 1, at: Date.now() })),
+}));
+
+export const requestSidePanel = (tab: SidePanelTab | null) =>
+ usePanelRequest.getState().request(tab);
+
+/** How long a request stays actionable — survives the current render pass,
+ * short enough that a later remount doesn't replay it. */
+const FRESH_MS = 3000;
+
+/** SidePanel-side handling: applies each fresh request to its tab state. */
+export function usePanelRequestEffect(apply: (tab: SidePanelTab | null) => void) {
+ const seq = usePanelRequest((s) => s.seq);
+ useEffect(() => {
+ if (!seq) return;
+ const { target, at } = usePanelRequest.getState();
+ if (Date.now() - at > FRESH_MS) return;
+ apply(target);
+ // Re-run on each request only; the callback is read fresh per firing.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [seq]);
+}
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index 820357df..754ffbe0 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -97,6 +97,18 @@ export const AI_TOOLS: AiToolDef[] = [
id: str("The item id (omit for kind=none)"),
}, ["kind"]),
},
+ {
+ name: "set_side_panel",
+ description:
+ "Open a side-panel tab, or collapse the panel to the icon rail with 'none' so the preview canvas takes the freed width — use 'none' when the user asks to clean up or maximize the workspace. 'publish' is the Details tab.",
+ inputSchema: obj({
+ panel: {
+ type: "string",
+ enum: ["media", "library", "video", "image", "audio", "subtitles", "publish", "none"],
+ description: "Tab to open, or 'none' to collapse the panel",
+ },
+ }, ["panel"]),
+ },
{
name: "split_at",
description:
@@ -435,7 +447,7 @@ export const AI_TOOLS: AiToolDef[] = [
{
name: "library_organize",
description:
- "Organize the shared Library: create_folder / rename_folder / delete_folder (a deleted folder's assets drop to the root), move_asset files an asset into a folder (omit folder_id for the root), delete_asset / delete_template remove an item. Deletes are permanent — projects keep their own copies, but delete only what the user explicitly asked to remove.",
+ "Organize the shared Library: create_folder / rename_folder / delete_folder (a deleted folder's items drop to the root), move_asset files an asset or template into a folder (omit folder_id for the root), delete_asset / delete_template remove an item. Deletes are permanent — projects keep their own copies, but delete only what the user explicitly asked to remove.",
inputSchema: obj({
action: {
type: "string",