Skip to content

Open source CapCut alternative.

TypeScript

refactor(site): keep a scene run's record in the chat

David Le3ce157ceb3e1
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index 909e6682..9bc157bc 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -28,7 +28,7 @@ import {
import Markdown, { type Components } from "react-markdown";
import { baseMarkdownComponents } from "./markdownComponents";
import { LiveElapsed } from "./Elapsed";
-import { SceneActivity, SceneCard } from "./SceneCard";
+import { SceneCard } from "./SceneCard";
import { useElapsed } from "@/cut/hooks/useElapsed";
import { Button } from "@/components/ui/button";
import {
@@ -833,20 +833,10 @@ function ChatSession({
{messages.map((m) => (
<Fragment key={m.id}>
<MessageView message={m} />
- {m.id === sceneAnchorId && (
- <>
- <SceneCard threadId={threadId} />
- <SceneActivity threadId={threadId} />
- </>
- )}
+ {m.id === sceneAnchorId && <SceneCard threadId={threadId} />}
</Fragment>
))}
- {sceneAnchorId === undefined && (
- <>
- <SceneCard threadId={threadId} />
- <SceneActivity threadId={threadId} />
- </>
- )}
+ {sceneAnchorId === undefined && <SceneCard threadId={threadId} />}
<ThreadRenders threadId={threadId} />
{busy && (
<div className="ai-busy mt-1 flex items-center gap-1.5 text-[11.5px] text-muted-foreground">
diff --git a/site/src/cut/components/SceneCard.tsx b/site/src/cut/components/SceneCard.tsx
index a88b4e64..2d5614ab 100644
--- a/site/src/cut/components/SceneCard.tsx
+++ b/site/src/cut/components/SceneCard.tsx
@@ -9,7 +9,6 @@ import {
Maximize2,
RotateCw,
TriangleAlert,
- X,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { useHoverPlay } from "../hooks/useHoverPlay";
@@ -28,10 +27,12 @@ import { scrimIconButton } from "./iconButton";
import { RefThumb } from "./AssetRefs";
import { MEDIA_CORS } from "@/cut/lib/mediaCors";
-// The brief-to-video progress card, pinned into the chat while a "generate a
-// video" run is planning, waiting for approval, or rendering. The timeline fills
-// on its own via the editor bridge; this is the control surface — approve the
-// plan, watch shots land, redo one by clicking its chip.
+// The brief-to-video run, streamed into the chat while a "generate a video" run
+// is planning, waiting for approval, or rendering. It reads top to bottom the
+// way the work happens — what's being made, then the activity as it happens,
+// then the shots, then the approval. The timeline fills on its own via the
+// editor bridge; this is the control surface — approve the plan, watch shots
+// land, redo one by clicking its chip.
const STATUS_LABEL: Record<SceneRun["status"], string> = {
planning: "Planning",
@@ -85,7 +86,9 @@ export function SceneCard({ threadId }: { threadId: string }) {
if (run.chatId && run.chatId !== threadId) return null;
const inFlight = run.status === "planning" || run.status === "generating";
- const canDismiss =
+ // The run has stopped and is waiting on the user — the footer carries
+ // whatever it's waiting for (approve, retry, or the ready line).
+ const settled =
run.status === "awaiting_approval" || run.status === "done" || run.status === "failed";
const pct = run.total ? Math.round((run.placed / run.total) * 100) : 0;
const showProgress = run.status === "generating" || run.status === "done";
@@ -110,7 +113,7 @@ export function SceneCard({ threadId }: { threadId: string }) {
const elapsed = run.status === "awaiting_approval" ? null : formatDuration(clockEnd - clockAnchor);
return (
- <div className="ai-scene-card mt-2 rounded-xl border border-border bg-card/60 p-3 text-[11.5px]">
+ <div className="ai-scene-card mt-2 mb-3 text-[11.5px]">
<div className="flex items-center gap-1.5">
<Clapperboard className="size-3.5 text-[#0a84ff]" />
<span className="font-semibold">Generate video</span>
@@ -123,6 +126,8 @@ export function SceneCard({ threadId }: { threadId: string }) {
<p className="mt-1 line-clamp-2 text-muted-foreground">{run.title}</p>
+ <RunActivity run={run} inFlight={inFlight} />
+
{run.shots.length > 0 &&
(hasFrames ? (
<div className="mt-2">
@@ -183,7 +188,7 @@ export function SceneCard({ threadId }: { threadId: string }) {
</p>
)}
- {canDismiss && (
+ {settled && (
<div className="mt-2.5 flex flex-col gap-1.5">
{/* The stills notice reads as a paragraph, so it takes its own line
above the buttons rather than sharing a row with them. */}
@@ -236,17 +241,6 @@ export function SceneCard({ threadId }: { threadId: string }) {
Retry {stillCount} shot{stillCount === 1 ? "" : "s"}
</Button>
)}
- {canDismiss && (
- <Button
- size="sm"
- variant="ghost"
- className="h-7 text-muted-foreground"
- title="Dismiss"
- onClick={() => useGenScene.getState().dismiss()}
- >
- <X className="size-3.5" />
- </Button>
- )}
</div>
</div>
)}
@@ -399,13 +393,11 @@ function ShotTile({
);
}
-/** The run's chronological record, streamed into the chat as its own item
- * right under the scene card — every narrated step and every asset it made,
- * thumbnails included. Nothing the run does is internal: this is the same
- * story the agent would tell in chat. */
-export function SceneActivity({ threadId }: { threadId: string }) {
- const run = useGenScene((s) => s.run);
- const projectId = useEditor((s) => s.projectId);
+/** The run's chronological record — every narrated step and every asset it
+ * made, thumbnails included — streamed above the shots as the work happens.
+ * Nothing the run does is internal: this is the same story the agent would
+ * tell in chat. */
+function RunActivity({ run, inFlight }: { run: SceneRun; inFlight: boolean }) {
// Feed thumbnails resolve against the open project's media (the run's
// assets are project assets, chat-owned).
const assets = useEditor((s) => s.assets);
@@ -413,7 +405,7 @@ export function SceneActivity({ threadId }: { threadId: string }) {
// Follow new entries only when the chat is already reading the tail —
// never yank the user back down while they scroll through old images.
const bottomRef = useRef<HTMLDivElement>(null);
- const feedLen = run?.feed.length ?? 0;
+ const feedLen = run.feed.length;
useEffect(() => {
const scroller = bottomRef.current?.closest(".ai-messages");
if (!scroller) return;
@@ -421,13 +413,10 @@ export function SceneActivity({ threadId }: { threadId: string }) {
if (gap < 160) scroller.scrollTop = scroller.scrollHeight;
}, [feedLen]);
- if (!run || run.projectId !== projectId) return null;
- if (run.chatId && run.chatId !== threadId) return null;
- if (run.feed.length === 0) return null;
- const inFlight = run.status === "planning" || run.status === "generating";
+ if (feedLen === 0) return null;
return (
- <div className="ai-scene-activity mt-2 mb-3 flex flex-col gap-1.5">
+ <div className="ai-scene-activity mt-2 flex flex-col gap-1.5">
<div className="text-[10.5px] font-medium text-muted-foreground">Activity</div>
{run.feed.map((f, i) => {
const asset = f.mediaId ? assets.find((a) => a.id === f.mediaId) : undefined;
diff --git a/site/src/cut/lib/genScene.ts b/site/src/cut/lib/genScene.ts
index c4a3443b..964cdb44 100644
--- a/site/src/cut/lib/genScene.ts
+++ b/site/src/cut/lib/genScene.ts
@@ -585,14 +585,10 @@ function resumeDoneRun(): boolean {
const ed = useEditor.getState();
const stored = ed.genvideo;
if (!ed.projectId || !stored || stored.phase !== "done") return false;
- // Reviving the run re-opens its card; a stale dismissal must not hide the
- // record of the work about to happen on the next load.
- const project = { ...stored, cardDismissed: undefined };
- if (stored.cardDismissed) ed.setGenvideo(project);
orchestrators.get(ed.projectId)?.abort();
- const orch = buildOrchestrator(ed.projectId, project);
+ const orch = buildOrchestrator(ed.projectId, stored);
orchestrators.set(ed.projectId, orch);
- mirrorRun(ed.projectId, project);
+ mirrorRun(ed.projectId, stored);
return true;
}
@@ -656,7 +652,6 @@ interface GenSceneState {
/** A project was deleted — abort any live run so it stops spending and can't
* write back to a doc that no longer exists. */
killProject: (projectId: string) => void;
- dismiss: () => void;
}
export const useGenScene = create<GenSceneState>((set, get) => ({
@@ -827,10 +822,7 @@ export const useGenScene = create<GenSceneState>((set, get) => ({
if (!openId || !stored || stored.phase !== "failed") {
return { ok: false, message: "No failed video run to retry here." };
}
- // The retry re-opens the card; clear a stale dismissal so the revived
- // run's record survives the next load too.
- const plan = { ...stored, cardDismissed: undefined };
- if (stored.cardDismissed) useEditor.getState().setGenvideo(plan);
+ const plan = stored;
orchestrators.get(openId)?.abort();
const orch = buildOrchestrator(openId, plan);
orchestrators.set(openId, orch);
@@ -879,12 +871,12 @@ export const useGenScene = create<GenSceneState>((set, get) => ({
// even a finished run's leftovers never sit in the generate panels.
claimRunMedia(projectId, project);
// A finished or failed run has nothing to resume — its clips are already
- // on the timeline — but its card is the run's durable record, so it
- // mirrors back on every load (no orchestrator, nothing spends) until the
- // user dismisses it; the X stamps the plan so the dismissal sticks.
- // Revision tools rebuild the live run on demand (resumeDoneRun).
+ // on the timeline — but the plan and its shots are the run's permanent
+ // record in the chat, so they mirror back on every load (no orchestrator,
+ // nothing spends). Revision tools rebuild the live run on demand
+ // (resumeDoneRun).
if (project.phase === "done" || project.phase === "failed") {
- if (!project.cardDismissed) mirrorRun(projectId, project);
+ mirrorRun(projectId, project);
return;
}
// Rebuild the orchestrator around the persisted plan so approve/regenerate
@@ -969,25 +961,4 @@ export const useGenScene = create<GenSceneState>((set, get) => ({
if (run?.projectId === projectId) set({ run: null });
},
- dismiss: () => {
- const run = get().run;
- // Dismissing an unrendered plan abandons it: the orchestrator stops and
- // the persisted plan is cleared, so it can't resurrect on the next load.
- // A finished (or failed) run keeps its record — its media re-tags from it
- // on load — but the dismissal is stamped on the plan so the card stays
- // closed across loads (until a retry or revision revives the run).
- if (run && !isTerminal(run.status)) {
- killRun(run.projectId);
- } else if (run) {
- const ed = useEditor.getState();
- if (ed.projectId === run.projectId && ed.genvideo) {
- ed.setGenvideo({ ...ed.genvideo, cardDismissed: true });
- } else {
- void withProjectDoc(run.projectId, (doc) => {
- if (doc.genvideo) doc.genvideo = { ...doc.genvideo, cardDismissed: true };
- }).catch(() => {});
- }
- }
- set({ run: null });
- },
}));
diff --git a/site/src/cut/lib/genvideo/types.ts b/site/src/cut/lib/genvideo/types.ts
index dd0c949e..ab63c91c 100644
--- a/site/src/cut/lib/genvideo/types.ts
+++ b/site/src/cut/lib/genvideo/types.ts
@@ -175,10 +175,6 @@ export interface VideoProject {
/** Epoch ms when the run reached done/failed — freezes the finished card's
* elapsed clock across reloads. */
endedAt?: number;
- /** The user closed the finished run's chat card. A terminal run's card is
- * its durable record — it re-surfaces on every load until this is stamped;
- * reviving the run (retry, revision) clears it. */
- cardDismissed?: boolean;
updatedAt: number;
}