Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Fix null-optional mismatch, audio binding, routing copy, disabled reasons, composer loss

Bitti31bce25ba489
diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.ts
index 072d18b..775cbd1 100644
--- a/src/components/ProjectWorkspace.test.ts
+++ b/src/components/ProjectWorkspace.test.ts
@@ -69,7 +69,11 @@ describe("project workspace timecode", () => {
const timeline = container.querySelector(".timeline-view")!;
fireEvent.keyDown(timeline, { key: "Delete" });
expect(onChange).not.toHaveBeenCalled();
- expect((screen.getByTitle("Delete selected clip") as HTMLButtonElement).disabled).toBe(true);
+ // Still disabled — and now it says why, rather than keeping the enabled
+ // wording while being unclickable.
+ const deleteButton = screen.getByRole("button", { name: "Delete" }) as HTMLButtonElement;
+ expect(deleteButton.disabled).toBe(true);
+ expect(deleteButton.title).toBe("This clip’s track is locked");
});
it("inserts only a completed job with a real output into Story", () => {
@@ -132,6 +136,61 @@ describe("project workspace timecode", () => {
expect(split().title).toBe("Split at playhead");
});
+ it("keeps half-written composer text when you visit another tab and come back", async () => {
+ const config = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
+ const { container } = render(createElement(ProjectWorkspace, {
+ project: { folderPath: "C:\\Ceramic Lamp", config }, initialView: "generator",
+ onBack: () => undefined, onSave: async () => undefined,
+ }));
+ const composer = () => container.querySelector(".generation-composer textarea") as HTMLTextAreaElement;
+ fireEvent.change(composer(), { target: { value: "a slow push across the launch pad" } });
+ fireEvent.click(screen.getByRole("button", { name: "Timeline" }));
+ await screen.findByRole("heading", { name: "Timeline", level: 2 });
+ fireEvent.click(screen.getByRole("button", { name: "Generator" }));
+ await screen.findByRole("heading", { name: "Generator" });
+ // Switching tabs unmounts the generator. Losing the user's own half-written
+ // words is the one thing this app must never do.
+ expect(composer().value).toBe("a slow push across the launch pad");
+ });
+
+ it("does not bind an audio-tagged reference a new shot's prompt would drop", () => {
+ const fresh = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
+ const config = parseProjectConfig({ ...fresh, references: [
+ { id: "ref-audio", kind: "text", name: "Score idea", description: "Sparse piano.", content: "Sparse piano.", intendedUse: ["audio"], createdAt: fresh.createdAt },
+ ] });
+ const onChange = vi.fn();
+ const { container } = render(createElement(GeneratorView, { config, folderPath: "C:\\Ceramic Lamp", onChange, onOpenTimeline: () => undefined }));
+ fireEvent.change(container.querySelector(".generation-composer textarea")!, { target: { value: "a slow push across the pad" } });
+ fireEvent.click(screen.getByRole("button", { name: /Save as a draft|Generate/ }));
+ // It would take a binding slot and then be dropped by the compiler, so the
+ // shot would claim a reference its prompt never mentions.
+ expect(onChange.mock.calls[0][0].generationJobs[0].referenceIds).toEqual([]);
+ });
+
+ it("describes only the route the bound references actually take", () => {
+ const fresh = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
+ const config = parseProjectConfig({
+ ...fresh,
+ references: [{ id: "ref-text", kind: "text", name: "Mara", description: "Calm architect.", content: "Calm architect.", intendedUse: ["character"], createdAt: fresh.createdAt }],
+ generationJobs: [{ ...fresh.generationJobs[0], referenceIds: ["ref-text"] }],
+ });
+ render(createElement(GeneratorView, { config, folderPath: "C:\\Ceramic Lamp", onChange: () => undefined, onOpenTimeline: () => undefined, selectedJobId: fresh.generationJobs[0].id }));
+ const refs = document.querySelector(".job-refs")!.textContent ?? "";
+ expect(refs).toContain("The text definition is written into this shot’s prompt.");
+ // No image is bound, so nothing is sent to the engine as an asset.
+ expect(refs).not.toContain("Images are sent to the video engine");
+ });
+
+ it("says why Duplicate and Delete are unavailable, not just that they are", () => {
+ const config = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
+ render(createElement(TimelineView, { config, onChange: () => undefined, onOpenGenerator: () => undefined }));
+ for (const label of ["Duplicate", "Delete"]) {
+ const button = screen.getByRole("button", { name: label }) as HTMLButtonElement;
+ expect(button.disabled).toBe(true);
+ expect(button.title).toBe(`Select a clip to ${label.toLowerCase()} it`);
+ }
+ });
+
it("labels a cancelled preview as cancelled instead of queued", () => {
const fresh = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
const config = parseProjectConfig({ ...fresh, generationJobs: [{ ...fresh.generationJobs[0], status: "cancelled", stage: "failed" }] });
diff --git a/src/components/ProjectWorkspace.tsx b/src/components/ProjectWorkspace.tsx
index 0e4ce57..b5c0f2a 100644
--- a/src/components/ProjectWorkspace.tsx
+++ b/src/components/ProjectWorkspace.tsx
@@ -26,6 +26,9 @@ export function ProjectWorkspace({ project, initialView = "timeline", onBack, on
const [config, setConfig] = useState(project.config);
const [view, setView] = useState<ProjectView>(initialView);
const [selectedGenerationJobId, setSelectedGenerationJobId] = useState<string | undefined>(project.config.generationJobs[0]?.id);
+ /* Switching tabs unmounts the generator, so its composer text lives here.
+ Half a shot description used to vanish on a trip to the timeline and back. */
+ const [generatorPrompt, setGeneratorPrompt] = useState("");
const [saving, setSaving] = useState(false);
const [dirty, setDirty] = useState(false);
const [saveError, setSaveError] = useState<string | null>(null);
@@ -91,7 +94,7 @@ export function ProjectWorkspace({ project, initialView = "timeline", onBack, on
<div className={`project-content project-content--${view}`}>
{view === "timeline" && <TimelineView config={config} onChange={changeConfig} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} />}
- {view === "generator" && <GeneratorView config={config} folderPath={project.folderPath} runtime={runtime?.vidfab ?? null} onChange={changeConfig} selectedJobId={selectedGenerationJobId} onOpenTimeline={() => setView("timeline")} />}
+ {view === "generator" && <GeneratorView config={config} folderPath={project.folderPath} runtime={runtime?.vidfab ?? null} onChange={changeConfig} selectedJobId={selectedGenerationJobId} onOpenTimeline={() => setView("timeline")} draftPrompt={generatorPrompt} onDraftPromptChange={setGeneratorPrompt} />}
{view === "references" && <ReferencesView config={config} folderPath={project.folderPath} onChange={changeConfig} />}
</div>
<footer className="project-agent-row"><AgentDock
diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsx
index 426b1f5..9bc85bf 100644
--- a/src/components/workspace/GeneratorView.tsx
+++ b/src/components/workspace/GeneratorView.tsx
@@ -12,13 +12,21 @@ interface GeneratorViewProps {
onChange: (next: ProjectConfig) => void;
onOpenTimeline: () => void;
selectedJobId?: string;
+ /** Composer text, held by the parent. Switching tabs unmounts this view, and
+ * keeping the half-written shot in local state threw the user's own words
+ * away — the one thing this app is not allowed to do. Optional so the view
+ * still works standalone; it falls back to its own state. */
+ draftPrompt?: string;
+ onDraftPromptChange?: (value: string) => void;
}
type JobStatus = GenerationJob["status"];
-export function GeneratorView({ config, folderPath, runtime = null, onChange, onOpenTimeline, selectedJobId }: GeneratorViewProps) {
+export function GeneratorView({ config, folderPath, runtime = null, onChange, onOpenTimeline, selectedJobId, draftPrompt, onDraftPromptChange }: GeneratorViewProps) {
const [selectedId, setSelectedId] = useState(selectedJobId ?? config.generationJobs.find((job) => job.status === "generating")?.id ?? config.generationJobs[0]?.id);
- const [prompt, setPrompt] = useState("");
+ const [ownPrompt, setOwnPrompt] = useState("");
+ const prompt = draftPrompt ?? ownPrompt;
+ const setPrompt: (value: string) => void = onDraftPromptChange ?? setOwnPrompt;
const [planNotes, setPlanNotes] = useState<Record<string, string>>({});
const composerRef = useRef<HTMLTextAreaElement | null>(null);
const configRef = useRef(config);
@@ -35,7 +43,13 @@ export function GeneratorView({ config, folderPath, runtime = null, onChange, on
// count taken from the IDs alone told the user a definition was steering the
// shot when the compiled prompt never mentioned it.
const promptRefs = useMemo(() => boundRefs.filter((ref) => isReferenceUsable(ref) && isVisualReference(ref)), [boundRefs]);
- const usableReferences = useMemo(() => config.references.filter(isReferenceUsable), [config.references]);
+ // The references a NEW shot would bind and the compiler would then keep. Both
+ // filters, or the hint promises a reference the prompt drops and a legacy
+ // audio-only one eats a binding slot a real reference should have had.
+ const usableReferences = useMemo(
+ () => config.references.filter((ref) => isReferenceUsable(ref) && isVisualReference(ref)),
+ [config.references],
+ );
const runtimeReady = runtime?.state === "ready";
const submitLabel = runtimeReady ? "Generate this shot" : "Save as a draft";
@@ -101,7 +115,9 @@ export function GeneratorView({ config, folderPath, runtime = null, onChange, on
// actually typed, or it gets read back to them as their own request.
const cleanPrompt = prompt.trim();
if (!cleanPrompt) return;
- const bound = config.references.filter(isReferenceUsable).slice(0, 2);
+ // Same pair the compiler applies, so a bound reference is always one that
+ // actually reaches the prompt.
+ const bound = config.references.filter((ref) => isReferenceUsable(ref) && isVisualReference(ref)).slice(0, 2);
const draft = createDraftGenerationJob(cleanPrompt, { referenceIds: bound.map((ref) => ref.id), references: bound });
const job: GenerationJob = runtimeReady ? { ...draft, status: "queued" } : draft;
const next = { ...config, generationJobs: [job, ...jobs] };
@@ -264,7 +280,7 @@ export function GeneratorView({ config, folderPath, runtime = null, onChange, on
})}
{promptRefs.length === 0
? <p className="job-refs__empty">The video engine only follows the words above.</p>
- : <p className="job-refs__empty">Images are sent to the video engine as reference assets; text definitions are written into this shot’s prompt. The tags are your own notes and don’t change what is sent.</p>}
+ : <p className="job-refs__empty">{referenceRouting(promptRefs)} The tags are your own notes and don’t change what is sent.</p>}
</div>
<div className="job-actions">
@@ -389,6 +405,21 @@ function QueueGroup({ title, jobs, selectedId, onSelect }: { title: string; jobs
</section>;
}
+/* Only claim the route the bound references actually take. Saying "images are
+ sent … text definitions are written into the prompt" for a shot that has only
+ one of the two describes something that isn't happening. */
+const referenceRouting = (references: ProjectReference[]): string => {
+ const hasImage = references.some((reference) => reference.kind === "image");
+ const hasText = references.some((reference) => reference.kind !== "image");
+ if (hasImage && hasText) return "Images are sent to the video engine as reference assets; text definitions are written into this shot’s prompt.";
+ if (hasImage) return references.length === 1
+ ? "The image is sent to the video engine as a reference asset."
+ : "The images are sent to the video engine as reference assets.";
+ return references.length === 1
+ ? "The text definition is written into this shot’s prompt."
+ : "The text definitions are written into this shot’s prompt.";
+};
+
/* Why a reference that is bound to this shot never reaches its prompt, or null
when it does. The wording mirrors the References card so the two screens
describe the same state in the same words. */
diff --git a/src/components/workspace/TimelineView.tsx b/src/components/workspace/TimelineView.tsx
index 5082013..17a7c0d 100644
--- a/src/components/workspace/TimelineView.tsx
+++ b/src/components/workspace/TimelineView.tsx
@@ -92,6 +92,14 @@ export function TimelineView({ config, onChange, onOpenGenerator }: { config: Pr
: playhead <= selected.startMs || playhead >= selected.startMs + selected.durationMs
? "Move the playhead inside the selected clip to split it"
: null;
+ /* Same rule as Split: a disabled control says why it is disabled, and the
+ predicate is the handler's own guard rather than a looser approximation. */
+ const duplicateBlockedBy = !selected
+ ? "Select a clip to duplicate it"
+ : !selectedTrack || selectedTrack.locked ? "This clip’s track is locked" : null;
+ const deleteBlockedBy = !selected
+ ? "Select a clip to delete it"
+ : !selectedTrack || selectedTrack.locked ? "This clip’s track is locked" : null;
const addScene = () => {
// A new project already carries an unstarted draft made from the user's own
// words, so open that rather than stacking a near-identical second shot.
@@ -180,7 +188,7 @@ export function TimelineView({ config, onChange, onOpenGenerator }: { config: Pr
<aside className="clip-inspector">
<div className="panel-chrome"><h2>Clip details</h2></div>
{selected ? <>
- <div className="inspector-summary"><span className="clip-chip" style={{ background: selected.color }}><Film size={18} /></span><div><b>{selected.label}</b><small>{selectedTrack?.name} · {selected.status}</small></div></div>
+ <div className="inspector-summary"><span className="clip-chip" style={{ background: selected.color ?? undefined }}><Film size={18} /></span><div><b>{selected.label}</b><small>{selectedTrack?.name} · {selected.status}</small></div></div>
<section className="inspector-section">
<h3>Clip</h3>
<label><span>Name</span><input value={selected.label} onChange={(event) => updateClip(selected.id, { label: event.target.value || "Untitled clip" })} /></label>
@@ -217,8 +225,8 @@ export function TimelineView({ config, onChange, onOpenGenerator }: { config: Pr
<div className="timeline-tools">
<button onClick={addScene} title="Draft a new scene"><Plus size={16} /> Add</button>
<button onClick={splitSelected} disabled={splitBlockedBy !== null} title={splitBlockedBy ?? "Split at playhead"}><Scissors size={16} /> Split</button>
- <button onClick={duplicateSelected} disabled={!selected || selectedTrack?.locked} title="Duplicate clip"><Copy size={16} /> Duplicate</button>
- <button onClick={removeSelected} disabled={!selected || selectedTrack?.locked} title="Delete selected clip"><Trash2 size={16} /> Delete</button>
+ <button onClick={duplicateSelected} disabled={duplicateBlockedBy !== null} title={duplicateBlockedBy ?? "Duplicate clip"}><Copy size={16} /> Duplicate</button>
+ <button onClick={removeSelected} disabled={deleteBlockedBy !== null} title={deleteBlockedBy ?? "Delete selected clip"}><Trash2 size={16} /> Delete</button>
</div>
</header>
<div className="timeline-grid">
diff --git a/src/lib/project.test.ts b/src/lib/project.test.ts
index 1120d07..0d24415 100644
--- a/src/lib/project.test.ts
+++ b/src/lib/project.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import completeFixture from "../../fixtures/project-v1-complete.json";
+import createdFixture from "../../fixtures/project-v1-created.json";
import {
compileMiniMaxH3Prompt,
createProjectConfig,
@@ -244,6 +245,44 @@ describe("project schema", () => {
.toContain("The target video is in a 2D-animated style.");
});
+ it("accepts a freshly created project exactly as createProjectConfig writes it", () => {
+ // This fixture is the byte-exact output of createProjectConfig. Its first
+ // job has NO clipId key at all, which is what every real project looks like.
+ expect(parseProjectConfig(createdFixture)).toBeTruthy();
+ expect("clipId" in createdFixture.generationJobs[0]).toBe(false);
+ });
+
+ it("accepts an explicit null for every optional the backend can serialise as null", () => {
+ // Rust serialises Option::None as JSON null unless the field carries
+ // skip_serializing_if, and zod's bare .optional() REJECTS null. That
+ // mismatch made create_project, open_project and every recent-projects row
+ // fail in the desktop app while the browser preview stayed green.
+ const config = structuredClone(completeFixture) as Record<string, any>;
+ config.assets[0].durationMs = null;
+ config.assets[0].width = null;
+ config.assets[0].height = null;
+ config.timeline.tracks[0].clips[0].color = null;
+ config.generationJobs[0].clipId = null;
+ const parsed = parseProjectConfig(config);
+ expect(parsed.assets[0].durationMs ?? null).toBeNull();
+ expect(parsed.generationJobs[0].clipId ?? null).toBeNull();
+ expect(parsed.timeline.tracks[0].clips[0].color ?? null).toBeNull();
+ });
+
+ it("still rejects a wrongly typed value in those same optional fields", () => {
+ // Tolerating null must not turn into tolerating anything.
+ for (const mutate of [
+ (config: any) => { config.assets[0].width = 0; },
+ (config: any) => { config.assets[0].durationMs = -1; },
+ (config: any) => { config.generationJobs[0].clipId = ""; },
+ (config: any) => { config.timeline.tracks[0].clips[0].color = 7; },
+ ]) {
+ const config = structuredClone(completeFixture) as any;
+ mutate(config);
+ expect(() => parseProjectConfig(config)).toThrow();
+ }
+ });
+
it("resolves project-relative reference paths to absolute for the engine", () => {
// enqueue_vidfab_generation never receives the project folder and vidfab.rs
// uses the string verbatim, so the frontend must send an absolute path.
diff --git a/src/lib/project.ts b/src/lib/project.ts
index b347df2..5dbf9e0 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -39,9 +39,14 @@ export const projectAssetSchema = z.object({
name: z.string().min(1),
relativePath: projectRelativePathSchema,
mimeType: z.string().min(1),
- durationMs: z.number().int().nonnegative().optional(),
- width: z.number().int().positive().optional(),
- height: z.number().int().positive().optional(),
+ // `.nullish()`, not `.optional()`. Rust serialises a `None` as an explicit
+ // JSON `null` unless the field carries skip_serializing_if, and a bare
+ // `.optional()` REJECTS null — which made every desktop create/open fail.
+ // Both layers are fixed; this side stays tolerant so a hand-edited file or a
+ // future struct without the attribute cannot resurrect that failure.
+ durationMs: z.number().int().nonnegative().nullish(),
+ width: z.number().int().positive().nullish(),
+ height: z.number().int().positive().nullish(),
createdAt: isoDateSchema,
});
@@ -53,7 +58,8 @@ export const timelineClipSchema = z.object({
durationMs: z.number().int().positive(),
sourceStartMs: z.number().int().nonnegative().default(0),
label: z.string().min(1),
- color: z.string().optional(),
+ // See the note on projectAssetSchema.durationMs — nullish, never bare optional.
+ color: z.string().nullish(),
status: z.enum(["draft", "generated", "approved"]).default("approved"),
});
@@ -106,7 +112,10 @@ export const generationJobSchema = z.object({
// change. Never treat it as the authoritative prompt.
compiledPrompt: z.string().min(1),
referenceIds: z.array(idSchema).default([]),
- clipId: idSchema.optional(),
+ // The one that broke the desktop app outright: createDraftGenerationJob never
+ // sets clipId, so EVERY project has a job without it. See the note on
+ // projectAssetSchema.durationMs.
+ clipId: idSchema.nullish(),
outputRelativePath: projectRelativePathSchema.nullable().optional(),
error: z.string().min(1).nullable().optional(),
createdAt: isoDateSchema,