Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Separate scenes from media

Bitti703010674631
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 15a76e7..1d87bd1 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -684,11 +684,19 @@ fn validate_and_normalize_config(mut config: ProjectConfig) -> Result<ProjectCon
.as_deref()
.map(normalize_external_path)
.transpose()?;
- check_one_location(
- &format!("Asset '{}'", asset.id),
- asset.relative_path.as_ref(),
- asset.source_path.as_ref(),
- )?;
+ // A Generator scene can be cut before it is rendered. Its generated
+ // asset deliberately has no file until the render completes, while
+ // every imported asset still has exactly one stored location.
+ if asset.kind != "generated"
+ || asset.relative_path.is_some()
+ || asset.source_path.is_some()
+ {
+ check_one_location(
+ &format!("Asset '{}'", asset.id),
+ asset.relative_path.as_ref(),
+ asset.source_path.as_ref(),
+ )?;
+ }
}
for reference in &mut config.references {
if reference.id.trim().is_empty() || reference.name.trim().is_empty() {
@@ -3330,6 +3338,14 @@ mod tests {
.unwrap_err()
.contains("must have either"));
+ // A Generator scene can be arranged before its render exists. It still
+ // has an asset id for timeline integrity, and gains its path when the
+ // generated file is saved.
+ let mut waiting_scene = external_fixture();
+ waiting_scene.assets[0].kind = "generated".into();
+ waiting_scene.assets[0].source_path = None;
+ assert!(validate_and_normalize_config(waiting_scene).is_ok());
+
// A "source path" that is not absolute resolves against nothing.
for path in [
"Footage\\clip.mp4",
diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.ts
index c897966..12da464 100644
--- a/src/components/ProjectWorkspace.test.ts
+++ b/src/components/ProjectWorkspace.test.ts
@@ -13,6 +13,7 @@ import { ReferencesView } from "./workspace/ReferencesView";
import { TimelineView } from "./workspace/TimelineView";
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
+vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));
afterEach(cleanup);
@@ -258,6 +259,43 @@ describe("project workspace timecode", () => {
expect(second.container.querySelector(".media-grid--list")).not.toBeNull();
});
+ it("keeps imported media in Media and lists Generator scenes even before generation", () => {
+ const base = projectWithMedia();
+ const config = parseProjectConfig({ ...base, timeline: { tracks: base.timeline.tracks.map((track) => track.id === STORY_TRACK_ID ? { ...track, clips: [{
+ id: "clip-macro", assetId: "asset-macro", trackId: track.id, startMs: 0, durationMs: 5000, sourceStartMs: 0, label: "Macro footage", color: null, status: "approved",
+ }] } : track) } });
+ const { container } = render(createElement(TimelineView, { config, folderPath: "C:\\Ceramic Lamp", onChange: () => undefined, onOpenGenerator: () => undefined }));
+
+ expect(container.querySelector(".scene-list")!.textContent).toContain("First scene");
+ expect(container.querySelector(".scene-list")!.textContent).not.toContain("Macro footage");
+ fireEvent.click(screen.getByRole("button", { name: "Media" }));
+ const media = container.querySelector(".media-grid")! as HTMLElement;
+ expect(within(media).getByText("Macro footage")).not.toBeNull();
+ expect(within(media).getByText("Room tone")).not.toBeNull();
+ });
+
+ it("drops an ungenerated Generator scene onto a video track as a valid draft clip", () => {
+ const config = projectWithMedia();
+ const onChange = vi.fn();
+ const { container } = render(createElement(TimelineView, { config, folderPath: "C:\\Ceramic Lamp", onChange, onOpenGenerator: () => undefined }));
+ const scene = screen.getByTitle(/^First scene — drag onto a video track/);
+ const dataTransfer = fakeDataTransfer();
+
+ fireEvent.dragStart(scene, { dataTransfer });
+ fireEvent.drop(laneFor(container, config, "audio"), { dataTransfer });
+ expect(onChange).not.toHaveBeenCalled();
+
+ fireEvent.drop(laneFor(container, config, "video"), { dataTransfer });
+ const next = wrote(onChange.mock.calls[0][0], config);
+ const generatedAsset = next.assets.find((asset) => asset.id === "asset-job-initial-brief")!;
+ const clip = next.timeline.tracks.flatMap((track) => track.clips).find((item) => item.assetId === generatedAsset.id)!;
+ expect(generatedAsset.kind).toBe("generated");
+ expect(generatedAsset.relativePath ?? null).toBeNull();
+ expect(clip.status).toBe("draft");
+ expect(clip.label).toBe("First scene");
+ expect(parseProjectConfig(next)).toBeTruthy();
+ });
+
it("drops a video from the media panel onto a video track, and refuses the audio track", () => {
const config = projectWithMedia();
const video = config.assets[0];
@@ -902,8 +940,9 @@ describe("project workspace timecode", () => {
// returns early — so the button must not look live.
expect(split().disabled).toBe(true);
expect(split().title).toBe("Move the playhead inside the selected clip to split it");
- // Choosing a scene puts the playhead inside it, which is a real split.
- fireEvent.click(container.querySelector(".scene-card")!);
+ // Scrubbing inside the selected timeline clip makes it a real split. Scene
+ // cards now open Generator scenes and are no longer aliases for clips.
+ fireEvent.wheel(container.querySelector(".timeline-grid")!, { deltaY: 100, deltaMode: 0 });
expect(split().disabled).toBe(false);
expect(split().title).toBe("Split at playhead");
});
diff --git a/src/components/workspace/ProgramMonitor.tsx b/src/components/workspace/ProgramMonitor.tsx
index e52c870..5b849c9 100644
--- a/src/components/workspace/ProgramMonitor.tsx
+++ b/src/components/workspace/ProgramMonitor.tsx
@@ -141,9 +141,10 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, onSeek
// The picture's file. Nothing is read for a clip the playhead is not inside.
useEffect(() => {
- if (!asset) {
+ if (!asset || (!asset.relativePath && !asset.sourcePath)) {
setUrl(null);
setReady(false);
+ setError(null);
return;
}
let live = true;
@@ -293,6 +294,9 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, onSeek
export writes there, and a panel over it only hid the answer. */
let overlay: React.ReactNode = null;
if (!hasClips || !clip) overlay = null;
+ else if (asset?.kind === "generated" && !asset.relativePath && !asset.sourcePath) {
+ overlay = <div className="program-note"><Film size={22} /><span>Generate {clip.label} to preview it. Its place on the timeline is already saved.</span></div>;
+ }
else if (!isTauri()) {
overlay = <div className="program-note"><Film size={22} /><span>Playback needs the desktop app — the browser preview has no project folder to read the footage from.</span></div>;
} else if (error) {
diff --git a/src/components/workspace/TimelineView.tsx b/src/components/workspace/TimelineView.tsx
index 8b08b02..8c444bb 100644
--- a/src/components/workspace/TimelineView.tsx
+++ b/src/components/workspace/TimelineView.tsx
@@ -7,13 +7,22 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { resolutionLabel } from "../../lib/export";
import { importMediaFiles, isTauri } from "../../lib/persistence";
import { loadMediaLayout, saveMediaLayout, type MediaLayout } from "../../lib/settings";
-import type { ProjectAsset, ProjectConfig, TimelineClip, TimelineTrack } from "../../lib/project";
+import {
+ generationAssetId,
+ sceneDurationSeconds,
+ type GenerationJob,
+ type ProjectAsset,
+ type ProjectConfig,
+ type TimelineClip,
+ type TimelineTrack,
+} from "../../lib/project";
import {
clipEndMs, findClip, insertClip, moveClip, removeClip, snapTargets, sourceRoom, trimClip,
type SnapOptions, type SourceRoom,
} from "../../lib/timeline";
import { MediaThumbnail, type MeasuredMedia } from "./MediaThumbnail";
import { ProgramMonitor } from "./ProgramMonitor";
+import { sceneShape, STATUS_WORD } from "./sceneStatus";
const MIN_DURATION = 10_000;
const NOT_YET = "Not available yet. This control doesn’t change your project.";
@@ -28,6 +37,7 @@ const DROPPED_CLIP_MS = 5_000;
/* The drag payload is the asset id. A custom type keeps files dragged in from
the desktop, and text dragged from anywhere else, out of the drop handler. */
const ASSET_DRAG_TYPE = "application/x-polstudio-asset";
+const SCENE_DRAG_TYPE = "application/x-polstudio-generator-scene";
/* How close two edges have to be ON SCREEN before they snap together. In
pixels, not milliseconds, because that is how close they LOOK — the same
@@ -157,6 +167,7 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
is being offered — it can only see the TYPE. Remembering what dragstart
put there is the only way to know whether this lane can take it. */
const [draggedAsset, setDraggedAsset] = useState<ProjectAsset | undefined>(undefined);
+ const [draggedScene, setDraggedScene] = useState<GenerationJob | undefined>(undefined);
/* What the user is typing into Lasts, while they are typing it. The field
otherwise shows the clip's own length, and "00:0" on the way to "00:08"
must not be snapped back to a formatted timecode mid-keystroke. Null means
@@ -182,8 +193,8 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
* where the ruler stops (the canvas is at least as long as the film the user
* asked for, however little of it is cut yet). */
const contentEndMs = tracks.reduce((end, track) => track.clips.reduce((furthest, clip) => Math.max(furthest, clipEndMs(clip)), end), 0);
- const sceneClips = tracks.filter((track) => track.kind === "video").flatMap((track) => track.clips);
const duration = useMemo(() => canvasDuration(config), [config]);
+ const mediaAssets = useMemo(() => config.assets.filter((asset) => asset.kind !== "generated"), [config.assets]);
const ticks = useMemo(() => rulerTicks(duration), [duration]);
/* The lanes are ruled at the SAME interval as the ruler above them, so a line
under a clip is a line under a number. They used to be a fixed 14.7% of the
@@ -353,6 +364,9 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
return track.kind === "audio" ? asset.kind === "audio" : asset.kind !== "audio";
};
+ const acceptsScene = (track: ProjectConfig["timeline"]["tracks"][number] | undefined, scene: GenerationJob | undefined) =>
+ Boolean(scene && track && !track.locked && track.kind === "video");
+
const assetById = (id: string) => config.assets.find((asset) => asset.id === id);
/* The media panel decodes each file to draw its thumbnail, and hands back
@@ -485,6 +499,64 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
setSelectedId(clip.id);
};
+ /** Put a Generator scene in the cut whether or not it has a file yet. The
+ * generated asset is intentionally locationless while the scene is a draft;
+ * the generation event fills in its canonical MP4 path when it finishes. */
+ const dropScene = (trackId: string, jobId: string, ratio: number, laneWidthPx: number) => {
+ const job = config.generationJobs.find((candidate) => candidate.id === jobId);
+ const track = tracks.find((candidate) => candidate.id === trackId);
+ if (!job || !acceptsScene(track, job)) return;
+
+ const clipId = `clip-${crypto.randomUUID()}`;
+ onChange((current) => {
+ const currentJob = current.generationJobs.find((candidate) => candidate.id === jobId);
+ const currentTrack = current.timeline.tracks.find((candidate) => candidate.id === trackId);
+ if (!currentJob || !currentTrack || !acceptsScene(currentTrack, currentJob)) return current;
+
+ const plannedAssetId = generationAssetId(currentJob.id);
+ const existing = current.assets.find((asset) => asset.id === plannedAssetId)
+ ?? (currentJob.outputRelativePath
+ ? current.assets.find((asset) => asset.kind === "generated" && asset.relativePath === currentJob.outputRelativePath)
+ : undefined);
+ const sceneLengthMs = Math.max(minClipMs, Math.round(sceneDurationSeconds(currentJob) * 1000));
+ const asset: ProjectAsset = existing ?? {
+ id: plannedAssetId,
+ kind: "generated",
+ name: currentJob.title,
+ relativePath: currentJob.outputRelativePath ?? null,
+ sourcePath: null,
+ mimeType: "video/mp4",
+ durationMs: sceneLengthMs,
+ width: null,
+ height: null,
+ createdAt: currentJob.createdAt,
+ };
+ const currentDuration = canvasDuration(current);
+ const position = Number.isFinite(ratio) ? ratio * currentDuration : 0;
+ const startMs = Math.round(Math.max(0, Math.min(currentDuration - sceneLengthMs, position)));
+ const clip: TimelineClip = {
+ id: clipId,
+ assetId: asset.id,
+ trackId,
+ startMs,
+ durationMs: sceneLengthMs,
+ sourceStartMs: 0,
+ label: currentJob.title,
+ color: null,
+ status: currentJob.status === "completed" && currentJob.outputRelativePath ? "generated" : "draft",
+ };
+ const snap = {
+ targets: snapTargets(current.timeline.tracks, { playheadMs: playhead }),
+ toleranceMs: laneWidthPx > 0 ? (SNAP_PX * currentDuration) / laneWidthPx : 0,
+ };
+ const nextTracks = insertClip(current.timeline.tracks, trackId, clip, startMs, snap);
+ if (!nextTracks) return current;
+ const assets = existing ? current.assets : [...current.assets, asset];
+ return { ...current, assets, timeline: { tracks: nextTracks } };
+ });
+ setSelectedId(clipId);
+ };
+
/* --- Dragging a clip -----------------------------------------------------
Three gestures, one mechanism: take hold of a clip's body to move it along
@@ -617,7 +689,7 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
<button className={panelTab === "media" ? "active" : ""} onClick={() => setPanelTab("media")}><Film size={16} /> Media</button>
</div>
<div className="scene-panel__head">
- <h2>{panelTab === "scenes" ? "Story sequence" : "Project media"}</h2>
+ <h2>{panelTab === "scenes" ? "Generator scenes" : "Project media"}</h2>
{panelTab === "media" && (
<div className="layout-toggle" role="group" aria-label="Media layout">
<button
@@ -637,12 +709,30 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
</div>
{panelTab === "scenes" ? (
<div className="scene-list">
- {sceneClips.map((clip, index) => (
- <button key={clip.id} className={`scene-card ${selectedId === clip.id ? "selected" : ""}`} onClick={() => { setSelectedId(clip.id); setPlayhead(clip.startMs + 600); }}>
- <span className="scene-card__thumb"><i>{String(index + 1).padStart(2, "0")}</i><em>{(clip.durationMs / 1000).toFixed(1)}s</em></span>
- <span><b>{clip.label.replace(/^\d+ · /, "")}</b><small>{clip.status === "generated" ? "Needs review" : "In timeline"}</small></span>
- </button>
- ))}
+ {config.generationJobs.map((job, index) => {
+ const assetIds = new Set([
+ generationAssetId(job.id),
+ ...config.assets.filter((asset) => job.outputRelativePath && asset.relativePath === job.outputRelativePath).map((asset) => asset.id),
+ ]);
+ const placements = tracks.flatMap((track) => track.clips).filter((clip) => clip.id === job.clipId || assetIds.has(clip.assetId)).length;
+ return <button
+ key={job.id}
+ className="scene-card"
+ draggable
+ onClick={() => onOpenGenerator(job.id)}
+ onDragStart={(event) => {
+ event.dataTransfer.setData(SCENE_DRAG_TYPE, job.id);
+ event.dataTransfer.effectAllowed = "copy";
+ setDraggedScene(job);
+ setDraggedAsset(undefined);
+ }}
+ onDragEnd={() => { setDraggedScene(undefined); setDropTrackId(null); }}
+ title={`${job.title} — drag onto a video track below`}
+ >
+ <span className="scene-card__thumb"><i>{String(index + 1).padStart(2, "0")}</i><em>{sceneDurationSeconds(job).toFixed(1)}s</em></span>
+ <span><b>{job.title}</b><small>{STATUS_WORD[job.status]}{placements > 0 ? ` · ${placements} on timeline` : ""}</small><small>{sceneShape(job)}</small></span>
+ </button>;
+ })}
<button className="scene-add" onClick={addScene}><Plus size={18} /> Add or generate a scene</button>
</div>
) : (
@@ -650,13 +740,14 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
{/* Draggable onto the timeline. `draggable` on a <button> is the
whole mechanism — the button still clicks and still takes
focus, so keyboard users are not shut out of selecting it. */}
- {config.assets.map((asset) => <button
+ {mediaAssets.map((asset) => <button
key={asset.id}
draggable
onDragStart={(event) => {
event.dataTransfer.setData(ASSET_DRAG_TYPE, asset.id);
event.dataTransfer.effectAllowed = "copy";
setDraggedAsset(asset);
+ setDraggedScene(undefined);
}}
onDragEnd={() => { setDraggedAsset(undefined); setDropTrackId(null); }}
title={`${asset.name} — drag onto a ${asset.kind === "audio" ? "sound" : "video"} track below`}
@@ -827,13 +918,15 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
pointer simply is not over, so a sound held above a video track
looked like it had not been picked up rather than like it was
being refused. Marked for the whole drag, not just on hover. */
- dropBlocked={draggedAsset !== undefined && !acceptsAsset(track, draggedAsset)}
+ dropBlocked={(draggedAsset !== undefined && !acceptsAsset(track, draggedAsset))
+ || (draggedScene !== undefined && !acceptsScene(track, draggedScene))}
onSelect={setSelectedId}
onToggle={toggleTrack}
onRename={renameTrack}
onDragOverLane={(event) => {
- if (!event.dataTransfer.types.includes(ASSET_DRAG_TYPE)) return;
- if (!acceptsAsset(track, draggedAsset)) return;
+ const hasAsset = event.dataTransfer.types.includes(ASSET_DRAG_TYPE);
+ const hasScene = event.dataTransfer.types.includes(SCENE_DRAG_TYPE);
+ if ((!hasAsset || !acceptsAsset(track, draggedAsset)) && (!hasScene || !acceptsScene(track, draggedScene))) return;
event.preventDefault();
event.dataTransfer.dropEffect = "copy";
setDropTrackId(track.id);
@@ -842,12 +935,18 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
onDropLane={(event) => {
event.preventDefault();
setDropTrackId(null);
+ const jobId = event.dataTransfer.getData(SCENE_DRAG_TYPE);
+ const rect = event.currentTarget.getBoundingClientRect();
+ const ratio = rect.width > 0 ? (event.clientX - rect.left) / rect.width : 0;
+ if (jobId) {
+ dropScene(track.id, jobId, ratio, rect.width);
+ return;
+ }
const assetId = event.dataTransfer.getData(ASSET_DRAG_TYPE);
if (!assetId) return;
- const rect = event.currentTarget.getBoundingClientRect();
// A zero-width lane would make the ratio NaN and the clip's start
// time with it, which zod then refuses to save.
- dropAsset(track.id, assetId, rect.width > 0 ? (event.clientX - rect.left) / rect.width : 0, rect.width);
+ dropAsset(track.id, assetId, ratio, rect.width);
}}
/>)}
<div className="timeline-playhead" style={{ left: `calc(var(--track-column) + (100% - var(--track-column)) * ${playhead / duration})` }}><span /><i /></div>
diff --git a/src/components/workspace/useGenerationEvents.test.tsx b/src/components/workspace/useGenerationEvents.test.tsx
index 0d6b8e7..cb7d124 100644
--- a/src/components/workspace/useGenerationEvents.test.tsx
+++ b/src/components/workspace/useGenerationEvents.test.tsx
@@ -78,6 +78,28 @@ describe("what the app does with the engine's events", () => {
expect(job().error).toMatch(/without sound/);
});
+ it("turns a scene placed before generation into playable generated media", async () => {
+ vi.mocked(saveGeneratedScene).mockResolvedValue({ relativePath: "media/generated/job-initial-brief.mp4", bytes: 10, note: null });
+ const fresh = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
+ const jobId = fresh.generationJobs[0].id;
+ const assetId = `asset-${jobId}`;
+ const state = { config: parseProjectConfig({
+ ...fresh,
+ assets: [{ id: assetId, kind: "generated", name: "First scene", relativePath: null, sourcePath: null, mimeType: "video/mp4", durationMs: 6000, width: null, height: null, createdAt: fresh.createdAt }],
+ timeline: { tracks: fresh.timeline.tracks.map((track, index) => index === 0 ? { ...track, clips: [{ id: "clip-scene", assetId, trackId: track.id, startMs: 0, durationMs: 6000, sourceStartMs: 0, label: "First scene", color: null, status: "draft" }] } : track) },
+ }) };
+ function Harness() {
+ useGenerationEvents({ folderPath: "C:\\Ceramic Lamp", onChange: (update) => { state.config = update(state.config); } });
+ return null;
+ }
+ render(<Harness />);
+ await emit("vidfab-job", { jobId, state: "framesReady", detail: "" });
+
+ expect(state.config.assets[0].relativePath).toBe("media/generated/job-initial-brief.mp4");
+ expect(state.config.timeline.tracks[0].clips[0].status).toBe("generated");
+ expect(parseProjectConfig(state.config)).toBeTruthy();
+ });
+
it("calls a render that could not be written a failure, not a finished scene", async () => {
vi.mocked(saveGeneratedScene).mockRejectedValue(new Error("This computer's encoder refused every H.264 configuration."));
const { jobId, job } = harness();
diff --git a/src/components/workspace/useGenerationEvents.ts b/src/components/workspace/useGenerationEvents.ts
index f3975a5..a5d74e3 100644
--- a/src/components/workspace/useGenerationEvents.ts
+++ b/src/components/workspace/useGenerationEvents.ts
@@ -2,7 +2,7 @@ import { listen } from "@tauri-apps/api/event";
import { useEffect, useRef } from "react";
import { saveGeneratedScene } from "../../lib/generatedVideo";
import { isTauri } from "../../lib/persistence";
-import type { GenerationJob, ProjectConfig } from "../../lib/project";
+import { generationAssetId, type GenerationJob, type ProjectConfig } from "../../lib/project";
/* Everything the video engine says about a scene, and what to do about it.
*
@@ -85,16 +85,36 @@ export function useGenerationEvents({ folderPath, onChange }: {
if (total > 0) updateJob(jobId, { progress: Math.min(0.99, ENCODE_FLOOR + (encoded / total) * (1 - ENCODE_FLOOR)) });
},
});
- updateJob(jobId, {
- status: "completed",
- stage: "completed",
- progress: 1,
- outputRelativePath: saved.relativePath,
- // A note means something was left out of the file — the file exists
- // and the scene is finished, so this is not a failure, but it is not
- // silence either.
- error: saved.note,
- });
+ const completedAt = new Date().toISOString();
+ const assetId = generationAssetId(jobId);
+ write.current((current) => ({
+ ...current,
+ generationJobs: current.generationJobs.map((job) => job.id === jobId ? {
+ ...job,
+ status: "completed",
+ stage: "completed",
+ progress: 1,
+ outputRelativePath: saved.relativePath,
+ // A note means something was left out of the file — the file exists
+ // and the scene is finished, so this is not a failure, but it is not
+ // silence either.
+ error: saved.note,
+ updatedAt: completedAt,
+ } : job),
+ assets: current.assets.map((asset) => asset.id === assetId ? {
+ ...asset,
+ kind: "generated",
+ relativePath: saved.relativePath,
+ sourcePath: null,
+ mimeType: "video/mp4",
+ } : asset),
+ timeline: {
+ tracks: current.timeline.tracks.map((track) => ({
+ ...track,
+ clips: track.clips.map((clip) => clip.assetId === assetId ? { ...clip, status: "generated" } : clip),
+ })),
+ },
+ }));
} catch (reason) {
/* The render happened and the file did not. Failed is the honest state:
there is nothing to insert into the timeline, and the only way to get
diff --git a/src/lib/project.test.ts b/src/lib/project.test.ts
index 65049c7..7873fb2 100644
--- a/src/lib/project.test.ts
+++ b/src/lib/project.test.ts
@@ -389,6 +389,26 @@ describe("project schema", () => {
}
});
+ it("allows a generated scene asset to wait for its render without relaxing imported media", () => {
+ const waiting = structuredClone(createdFixture) as any;
+ waiting.assets = [{
+ id: "asset-job-initial-brief",
+ kind: "generated",
+ name: "First scene",
+ relativePath: null,
+ sourcePath: null,
+ mimeType: "video/mp4",
+ durationMs: 6000,
+ width: null,
+ height: null,
+ createdAt: waiting.createdAt,
+ }];
+ expect(parseProjectConfig(waiting).assets[0].relativePath ?? null).toBeNull();
+
+ waiting.assets[0].kind = "video";
+ expect(() => parseProjectConfig(waiting)).toThrow(/must have either/);
+ });
+
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 f587bc3..f9bbc97 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -130,7 +130,10 @@ export const projectAssetSchema = z.object({
createdAt: isoDateSchema,
}).superRefine((asset, context) => {
checkOneLocation(asset, context, `Asset '${asset.id}'`);
- if (!asset.relativePath && !asset.sourcePath) {
+ /* A scene may be arranged on the timeline before it has been rendered. Its
+ * generated asset is the stable thing the clip points at while the file is
+ * still absent; useGenerationEvents fills the path in when rendering ends. */
+ if (asset.kind !== "generated" && !asset.relativePath && !asset.sourcePath) {
context.addIssue({
code: z.ZodIssueCode.custom, path: ["relativePath"],
message: `Asset '${asset.id}' must have either a project-relative path or an external source path.`,
@@ -418,6 +421,9 @@ export type TimelineTrack = z.infer<typeof timelineTrackSchema>;
export type GenerationBrief = z.infer<typeof generationBriefSchema>;
export type ProjectReference = z.infer<typeof projectReferenceSchema>;
export type GenerationJob = z.infer<typeof generationJobSchema>;
+
+/** Stable backing asset for a Generator scene placed on the timeline. */
+export const generationAssetId = (jobId: string): string => `asset-${jobId}`;
export type AgentMessage = z.infer<typeof agentMessageSchema>;
export type AgentConversation = z.infer<typeof agentConversationSchema>;
export type ProviderSetting = z.infer<typeof providerSettingSchema>;