"use client"; import { useCallback, useEffect, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; // FAST FEEDBACK (lib/report/takePreview.mjs; operator, 5 Nov 2026): a take's two quick renders, each a // step of the durable queue (POST /api/report/takes/fast, the fixed command `umtool take

--id // --preview | --changes [--from ]`), their state inline, each output's local path with Copy, and the // file itself played here. // // Preview render the whole take at the preview tier (1280×720, veryfast): out/.preview.mp4 // Render changes only what changed against the take it was made from, each item ± 3 s, labelled // with its time in the full cut: out/.changes.mp4 and changes.json // // Polls GET /api/report/takes/fast every 3 s only while a step is queued or a render runs. type Fast = { state: string | null; mp4: string | null; mp4Bytes?: number | null; seconds: number | null; endedAt?: string | null; error?: string | null; log?: string | null; list?: string | null; items?: number | null; from?: string | null; } | null; type View = { take: string; from: string | null; preview: Fast; changes: Fast; steps: { qid: string; state: string; kind: "preview" | "changes"; error: string | null }[] }; const LIVE = new Set(["queued", "running", "waiting"]); function stateOf(kind: "preview" | "changes", v: View | null) { const step = v?.steps.filter((s) => s.kind === kind).at(-1) ?? null; const rec = v?.[kind] ?? null; if (rec && (rec.state === "running" || rec.state === "waiting")) return { state: rec.state, step, rec }; if (step && (step.state === "queued" || step.state === "running" || step.state === "blocked")) return { state: step.state, step, rec }; return { state: rec?.state ?? null, step, rec }; } function Copy({ text }: { text: string }) { const [done, setDone] = useState(false); return ( ); } export default function FastRenders({ project, take, compact = false }: { project: string; take: string; compact?: boolean }) { const [view, setView] = useState(null); const [busy, setBusy] = useState<"preview" | "changes" | null>(null); const [said, setSaid] = useState(null); const [playing, setPlaying] = useState<"preview" | "changes" | null>(null); const [tick, setTick] = useState(0); const load = useCallback(async () => { const r = await fetch(`/api/report/takes/fast?${new URLSearchParams({ project, take })}`, { cache: "no-store" }).catch(() => null); if (r?.ok) setView((await r.json()) as View); }, [project, take]); useEffect(() => { void load(); }, [load, tick]); const live = (["preview", "changes"] as const).some((k) => LIVE.has(String(stateOf(k, view).state))); useEffect(() => { if (!live) return; const t = setInterval(() => setTick((n) => n + 1), 3000); return () => clearInterval(t); }, [live]); const start = async (kind: "preview" | "changes") => { setBusy(kind); setSaid(null); try { const r = await fetch("/api/report/takes/fast", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, take, kind, ...(kind === "changes" && view?.from ? { from: view.from } : {}) }), cache: "no-store", }); const j = (await r.json().catch(() => ({}))) as { error?: string; qid?: string }; setSaid(r.ok ? `queued as ${j.qid}` : (j.error ?? `HTTP ${r.status}`)); await load(); } finally { setBusy(null); } }; const row = (kind: "preview" | "changes", label: string, title: string) => { const s = stateOf(kind, view); const running = LIVE.has(String(s.state)); const disabled = !!busy || running || (kind === "changes" && !view?.from); return (

{s.state && ( {s.step && running && s.step.state !== "running" ? `${s.state} (${s.step.qid})` : s.state} {s.state === "failed" && s.rec?.error ? ` — ${s.rec.error}` : ""} {s.state === "blocked" && s.step?.error ? ` — ${s.step.error}` : ""} {s.state === "done" && s.rec?.seconds != null ? ` · ${Math.round(s.rec.seconds)} s` : ""} {kind === "changes" && s.state === "done" && s.rec?.items != null ? ` · ${s.rec.items} piece(s) against ${s.rec.from}` : ""} )} {s.rec?.mp4 && !running && ( <> {s.rec.mp4} )}
); }; return (
{row("preview", "Preview render", "the whole take at 1280×720, fast: its full render untouched (umtool take … --preview)")} {row("changes", "Render changes", `only what changed against ${view?.from ?? "its base"}, each item ± 3 s, labelled (umtool take … --changes)`)} {said &&

{said}

} {playing && view?.[playing]?.mp4 && (
); }