feat: video-stage continue validator and clip picker

This commit is contained in:
Benjiyaya
2026-08-29 05:17:35 +08:00
parent 105c6ac6e3
commit 36db1f90c9
8 changed files with 186 additions and 90 deletions
-2
View File
@@ -235,7 +235,6 @@ export const workflows = {
inputs: ComfyDynamicInput[];
outputs: ComfyDynamicOutput[];
suggested_profile?: string;
motion_role?: 'first' | 'next' | null;
}>('/api/workflows/analyze', {
method: 'POST',
body: JSON.stringify({ workflow_json }),
@@ -275,7 +274,6 @@ export const jobsApi = {
scene_ids?: number[];
workflow_id?: number;
input_values?: Record<string, unknown>;
continue_motion?: boolean;
} = {},
) =>
api<{ ok: boolean; jobs: Job[] }>(`/api/jobs/projects/${projectId}/generate-videos`, {
@@ -49,11 +49,6 @@ export function classifyInput(inp: ComfyDynamicInput): ClassifiedInput {
return { input: inp, zone: 'composer', widget: 'negativeTextarea' };
}
// Timeline-owned — filled on enqueue, never a user widget.
if (role === 'clipindex') {
return { input: inp, zone: 'hidden', widget: 'numberPill' };
}
// --- Media tray ---
if (
role === 'character' ||
-1
View File
@@ -29,7 +29,6 @@ const INPUT_ROLE_ALIASES: Record<string, string[]> = {
image: ['image', 'img'],
video: ['video', 'vid'],
audio: ['audio', 'sound', 'sfx'],
clipindex: ['clipindex', 'clip_index'],
seed: ['seed'],
duration: ['duration', 'dur', 'length', 'seconds'],
};
-2
View File
@@ -35,8 +35,6 @@ export interface Workflow {
description: string | null;
prompt_profile: string;
is_enabled: boolean;
/** H3 Motion Context pair: FirstMotion vs NextMotion. */
motion_role?: 'first' | 'next' | null;
}
export interface Job {
@@ -48,6 +48,10 @@
onSubmit?: () => void;
/** Pending state for the Generate button (shows spinner-ish label). */
submitting?: boolean;
/** Disable the Generate button (e.g. workflow cannot fulfil the scene). */
disabled?: boolean;
/** Why Generate is disabled — surfaced as the button's title tooltip. */
generateDisabledHint?: string;
/** Custom label for the Generate button. */
generateLabel?: string;
}
@@ -65,6 +69,8 @@
onChange,
onSubmit,
submitting = false,
disabled = false,
generateDisabledHint = '',
generateLabel = 'Generate',
}: Props = $props();
@@ -355,8 +361,9 @@
<button
type="button"
class="generate-btn"
class:disabled={submitting}
disabled={submitting}
class:disabled={submitting || disabled}
disabled={submitting || disabled}
title={disabled ? generateDisabledHint : undefined}
onclick={() => onSubmit?.()}
aria-label="Generate"
>
@@ -13,6 +13,8 @@
type Workflow,
} from '$lib/api';
import { compactInputValues } from '$lib/comfy/promptInput';
import { normalizeInputRole } from '$lib/comfy/parser';
import type { ComfyDynamicInput } from '$lib/comfy/types';
import type { AssetOption } from '$lib/assetPicker';
import { progressFor } from '$lib/jobProgress';
import SafeMedia from './SafeMedia.svelte';
@@ -36,8 +38,10 @@
let formValues = $state<Record<string, string | number>>({});
let selectedWorkflow = $state<Record<number, number>>({});
let lastFormScene = $state<number | null>(null);
// Clip source for continue scenes, keyed per scene: 'auto' | 'upload' | scene id.
let clipSource = $state<Record<number, string>>({});
// Per-scene input cache — switching scenes no longer wipes the form.
// Per-scene input cache — switching scenes no longer wipes the form.
const formCache = new Map<number, Record<string, string | number>>();
const scenesQuery = createQuery(
@@ -73,8 +77,6 @@
queryFn: playgroundApi.listUploads,
});
let continueByScene = $state<Record<number, boolean>>({});
const scenes = $derived(($scenesQuery.data?.scenes ?? []) as Scene[]);
const totalSec = $derived(
scenes.reduce((sum, s) => sum + Math.max(s.duration_sec || 5, 1), 0),
@@ -139,10 +141,6 @@
? videoWorkflows
: (($workflowsQuery.data ?? []) as Workflow[]).filter((w) => w.is_enabled),
);
const motionPairReady = $derived(
enabledWorkflows.some((w) => w.motion_role === 'first') &&
enabledWorkflows.some((w) => w.motion_role === 'next'),
);
$effect(() => {
if (selectedId != null) return;
@@ -175,17 +173,23 @@
return seed;
}
function previousScene(scene: Scene | null): Scene | null {
if (!scene) return null;
const earlier = scenes.filter((s) => s.order_index < scene.order_index);
return earlier.length ? earlier[earlier.length - 1] : null;
function workflowHasVideoInput(wf: Workflow | undefined): boolean {
return Boolean(
wf?.input_schema?.some((inp) => normalizeInputRole(inp.role ?? null) === 'video'),
);
}
function continueMotionFor(scene: Scene): boolean {
const prev = previousScene(scene);
if (!prev) return false;
if (continueByScene[scene.id] !== undefined) return continueByScene[scene.id];
return Boolean(prev.video_path);
function videoInputNodeFor(wf: Workflow | undefined): ComfyDynamicInput | undefined {
return wf?.input_schema?.find((inp) => normalizeInputRole(inp.role ?? null) === 'video');
}
// Timeline source options for a continue scene: earlier scenes that already
// rendered a clip, ordered by timeline position.
function timelineClipOptions(current: Scene | null): Scene[] {
if (!current) return [];
return scenes
.filter((s) => s.id !== current.id && s.order_index < current.order_index && s.video_path)
.sort((a, b) => a.order_index - b.order_index);
}
const generateOne = createMutation({
@@ -196,7 +200,6 @@
scene_ids: [sceneId],
workflow_id: selectedWorkflow[sceneId] ?? wf?.id,
input_values: compactInputValues(formValues),
continue_motion: scene ? continueMotionFor(scene) : false,
});
},
onSuccess: async () => {
@@ -211,8 +214,8 @@
// One POST per scene (the H3 prompt rewrite runs synchronously inside each
// request, so a single all-scenes POST could take minutes and time out).
// The queue worker then renders them strictly in sequence (concurrency 1).
// Do not send continue_motion here: omit it so the backend can treat a
// just-queued previous scene as "ready" and pick First/Next correctly.
// No per-scene form values here: continue scenes resolve their previous
// clip at enqueue or run time on the backend.
let batching = $state(false);
let batchNote = $state('');
@@ -316,7 +319,7 @@
return `${m}:${r.toString().padStart(2, '0')}`;
}
// Same compact "3m ago" style as ProjectCard — local copy keeps this stage self-contained.
// Same compact "3m ago" style as ProjectCard — local copy keeps this stage self-contained.
function relativeTime(iso: string): string {
const then = new Date(iso).getTime();
if (Number.isNaN(then)) return '';
@@ -349,7 +352,7 @@
selectedId = id;
}
// Filmstrip click → jump back to the editor with that scene selected.
// Filmstrip click → jump back to the editor with that scene selected.
function editScene(id: number) {
selectedId = id;
view = 'edit';
@@ -386,7 +389,7 @@
? ((exportJob.output_paths ?? []).find((p) => /\.mp4$/i.test(p)) ?? null)
: null,
);
// A clip finished after the export completed → the film no longer matches the timeline.
// A clip finished after the export completed → the film no longer matches the timeline.
const exportStale = $derived.by(() => {
if (exportJob?.status !== 'done' || !exportJob.completed_at) return false;
const exportAt = Date.parse(exportJob.completed_at);
@@ -468,7 +471,7 @@
{#if scenes.length === 0}
Build a script first, then cut clips on the timeline.
{:else}
{doneCount}/{scenes.length} clips done · {formatClock(totalSec)} total
{doneCount}/{scenes.length} clips done · {formatClock(totalSec)} total
{/if}
</p>
</div>
@@ -520,7 +523,7 @@
<div class="paused-banner" role="status">
<Icon name="alert" size={16} />
<StatusChip status="paused" label="Queue paused" />
<span class="paused-text">Renders are held — workers sit idle until you resume.</span>
<span class="paused-text">Renders are held — workers sit idle until you resume.</span>
<span class="paused-action">
<Button size="sm" variant="secondary" onclick={resumeQueue}>Resume now</Button>
</span>
@@ -536,6 +539,13 @@
{@const selWf = workflowFor(selected)}
{@const selStatus = statusOf(selected)}
{@const selPreview = previewPath(selected)}
{@const selHasVideoInput = workflowHasVideoInput(selWf)}
{@const selVideoNode = videoInputNodeFor(selWf)}
{@const selClips = timelineClipOptions(selected)}
{@const selChain = Boolean(selected.chain_from_prev)}
{@const selSource = clipSource[selected.id] ?? 'auto'}
{@const selSourceValid = selSource === 'auto' || selSource === 'upload' || selClips.some((s) => String(s.id) === selSource)}
{@const selBlocked = selChain && !selHasVideoInput}
<VideoEditWorkspace
{scenes}
{selected}
@@ -554,11 +564,32 @@
{statusOf}
{thumbFor}
{formatClock}
showContinueMotion={motionPairReady && previousScene(selected) != null}
continueMotion={continueMotionFor(selected)}
chained={continueMotionFor}
onContinueChange={(on) => {
continueByScene = { ...continueByScene, [selected.id]: on };
chained={(scene) => Boolean(scene.chain_from_prev)}
generateDisabled={selBlocked}
generateDisabledReason={selBlocked
? 'This scene continues from the previous video — pick a workflow with a video input'
: ''}
clipSource={{
enabled: selChain && selHasVideoInput && Boolean(selVideoNode),
value: selSourceValid ? selSource : 'auto',
options: selClips.map((s) => ({ id: String(s.id), label: `#${s.order_index} ${s.heading || 'Scene'}` })),
}}
onClipSourceChange={(val) => {
if (val === 'auto') {
// Back to Auto: send nothing — the backend resolves the previous clip.
const next = { ...clipSource };
delete next[selected.id];
clipSource = next;
if (selVideoNode) formValues = { ...formValues, [selVideoNode.nodeId]: '' };
} else if (val === 'upload') {
clipSource = { ...clipSource, [selected.id]: 'upload' };
} else {
clipSource = { ...clipSource, [selected.id]: val };
const clip = selClips.find((s) => String(s.id) === val);
if (clip?.video_path && selVideoNode) {
formValues = { ...formValues, [selVideoNode.nodeId]: clip.video_path };
}
}
}}
onSelect={selectScene}
onStep={step}
@@ -589,13 +620,13 @@
{#if exportStale}
<div class="stale-banner" role="status">
<Icon name="alert" size={14} />
<span>Clips changed since this export — re-export to update.</span>
<span>Clips changed since this export — re-export to update.</span>
</div>
{/if}
{:else if exportState === 'active'}
<div class="program-slate">
<Spinner size="lg" />
<h3 class="slate-title">Exporting your film…</h3>
<h3 class="slate-title">Exporting your film…</h3>
<div class="slate-progress">
<ProgressBar
value={exportProg?.progress ?? 0}
@@ -603,7 +634,7 @@
label={exportProg?.message}
/>
</div>
<p class="slate-sub">You can keep editing — export runs in the background.</p>
<p class="slate-sub">You can keep editing — export runs in the background.</p>
<Button variant="ghost" size="sm" onclick={cancelExport}>Cancel</Button>
</div>
{:else if exportState === 'failed'}
@@ -630,7 +661,7 @@
</span>
<h3 class="slate-title">Your film isn't exported yet</h3>
<p class="slate-sub">
{clipsReady} clips · {formatClock(totalSec)} · 0.5s crossfades · loudness matched
{clipsReady} clips · {formatClock(totalSec)} · 0.5s crossfades · loudness matched
</p>
{#if clipsMissing > 0}
<p class="slate-warn" role="status">
@@ -657,7 +688,7 @@
{@const exportUrl = assetUrl(exportPath)}
<div class="film-meta">
<span class="film-meta-text">
{exportClipCount} clips · {formatClock(totalSec)}{#if exportedAgo} · Exported {exportedAgo}{/if}
{exportClipCount} clips · {formatClock(totalSec)}{#if exportedAgo} · Exported {exportedAgo}{/if}
</span>
<div class="film-actions">
{#if exportUrl}
@@ -686,7 +717,7 @@
<button
type="button"
class="filmstrip-item"
title={`${scene.heading || 'Scene'} — edit in timeline`}
title={`${scene.heading || 'Scene'} — edit in timeline`}
onclick={() => editScene(scene.id)}
>
{#if thumb?.kind === 'image'}
@@ -20,7 +20,6 @@
let analyzedInputs = $state<ComfyDynamicInput[]>([]);
let analyzedOutputs = $state<ComfyDynamicOutput[]>([]);
let analyzed = $state(false);
let analyzedMotion = $state<'first' | 'next' | null>(null);
let pendingJson = $state<Record<string, unknown> | null>(null);
let wfName = $state('');
@@ -40,7 +39,6 @@
analyzed = false;
analyzedInputs = [];
analyzedOutputs = [];
analyzedMotion = null;
pendingJson = null;
try {
const json = JSON.parse(text) as Record<string, unknown>;
@@ -48,10 +46,8 @@
const result = await workflows.analyze(json);
analyzedInputs = result.inputs;
analyzedOutputs = result.outputs;
analyzedMotion = result.motion_role ?? null;
analyzed = true;
wfProfile = result.suggested_profile ?? 'prose';
if (result.motion_role) wfKind = 'video';
if (!wfName.trim() && uploadedFileName) {
wfName = uploadedFileName.replace(/\.json$/i, '');
}
@@ -231,11 +227,6 @@
{/if}
{#if analyzed}
{#if analyzedMotion}
<p class="muted">
Motion chain: {analyzedMotion === 'first' ? 'First motion (clip 1)' : 'Next motion (clips 2+)'}
</p>
{/if}
<div class="io-panel">
<div class="io-col">
<h4>Detected inputs ({analyzedInputs.length})</h4>
@@ -363,11 +354,6 @@
{#if wf.prompt_profile === 'minimax_h3_ref'}
<span class="kind-badge h3">H3-ref</span>
{/if}
{#if wf.motion_role === 'first'}
<span class="kind-badge h3">First motion</span>
{:else if wf.motion_role === 'next'}
<span class="kind-badge h3">Next motion</span>
{/if}
<span class="count">{wf.input_schema?.length ?? 0} inputs</span>
<span class="count">{wf.output_schema?.length ?? 0} outputs</span>
{#if !wf.is_enabled}<StatusChip status="disabled" label="Disabled" />{/if}
@@ -7,6 +7,7 @@
import type { Scene, Workflow } from '$lib/api';
import OmniComposer from '$lib/components/OmniComposer.svelte';
import type { AssetOption } from '$lib/assetPicker';
import Icon from '$lib/components/ui/Icon.svelte';
import ClipMonitor from './ClipMonitor.svelte';
import SceneFilmstrip from './SceneFilmstrip.svelte';
import SceneScriptDrawer from './SceneScriptDrawer.svelte';
@@ -18,6 +19,19 @@
message?: string;
}
interface ClipSourceOption {
/** Scene id as string, for a native select. */
id: string;
label: string;
}
interface ClipSourceConfig {
/** Only offered when the scene continues from the previous video and the workflow can accept it. */
enabled: boolean;
value: string;
options: ClipSourceOption[];
}
interface Props {
scenes: Scene[];
selected: Scene;
@@ -32,9 +46,12 @@
formValues: Record<string, string | number>;
assetOptions: AssetOption[];
allowUpload?: boolean;
showContinueMotion?: boolean;
continueMotion?: boolean;
onContinueChange?: (on: boolean) => void;
/** Disable Generate: scene continues from the previous video but the workflow cannot accept it. */
generateDisabled?: boolean;
generateDisabledReason?: string;
/** Where this continue scene's video input comes from (auto / upload / a timeline clip). */
clipSource?: ClipSourceConfig;
onClipSourceChange?: (value: string) => void;
chained?: (scene: Scene) => boolean;
submitting?: boolean;
statusOf: (scene: Scene) => string;
@@ -61,9 +78,10 @@
formValues = $bindable(),
assetOptions,
allowUpload = true,
showContinueMotion = false,
continueMotion = false,
onContinueChange,
generateDisabled = false,
generateDisabledReason = '',
clipSource,
onClipSourceChange,
chained = () => false,
submitting = false,
statusOf,
@@ -106,35 +124,59 @@
<div class="composer-dock">
{#if workflow}
{#if generateDisabled}
<div class="continue-warning" role="alert">
<Icon name="alert" size={16} />
<div class="continue-warning-text">
<span class="continue-warning-title">Workflow has no video input</span>
<span>
This scene continues from the previous video. Switch to a workflow that has a video
input (LoadVideo node tagged (Input:video)).
</span>
</div>
</div>
{:else if clipSource?.enabled}
<div class="clip-source-row">
<label class="clip-source-label" for="clip-source-select">Video source</label>
<select
id="clip-source-select"
class="clip-source-select"
value={clipSource.value}
onchange={(e) => onClipSourceChange?.(e.currentTarget.value)}
>
<option value="auto">Auto (previous clip)</option>
<option value="upload">Upload file</option>
{#if clipSource.options.length > 0}
<optgroup label="From timeline">
{#each clipSource.options as opt (opt.id)}
<option value={opt.id}>{opt.label}</option>
{/each}
</optgroup>
{/if}
</select>
</div>
{/if}
{#if assetOptions.length === 0}
<p class="asset-hint">
No refs yet. Generate character sheets or environments in Assets, or upload a video/audio
file here.
</p>
{/if}
{#if showContinueMotion}
<label class="continue-row">
<input
type="checkbox"
checked={continueMotion}
onchange={(e) => onContinueChange?.(e.currentTarget.checked)}
/>
<span>Continue motion from previous clip</span>
</label>
{/if}
<OmniComposer
inputs={workflow.input_schema}
bind:values={formValues}
{workflow}
{workflows}
onWorkflowChange={onWorkflowChange}
{assetOptions}
{allowUpload}
generateLabel="Generate clip"
{submitting}
onChange={onFormChange}
onSubmit={onGenerate}
/>
{assetOptions}
{allowUpload}
generateLabel="Generate clip"
{submitting}
disabled={generateDisabled}
generateDisabledHint={generateDisabledReason}
onChange={onFormChange}
onSubmit={onGenerate}
/>
{:else}
<div class="no-wf">
<p class="empty-title">No video workflow enabled</p>
@@ -175,18 +217,58 @@
flex-shrink: 0;
}
.continue-row {
.continue-warning {
display: flex;
align-items: flex-start;
gap: 10px;
padding: 10px 12px;
margin: 0 0 8px;
border-radius: var(--radius-md);
border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--border));
background: color-mix(in srgb, var(--warning) 10%, var(--bg-surface));
color: var(--text-secondary);
font-size: 13px;
}
.continue-warning :global(svg) {
flex-shrink: 0;
margin-top: 2px;
color: var(--warning);
}
.continue-warning-text {
display: flex;
flex-direction: column;
gap: 2px;
}
.continue-warning-title {
font-weight: 650;
color: var(--text-primary);
}
.clip-source-row {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 8px;
font-size: 12px;
color: var(--text-secondary);
cursor: pointer;
}
.continue-row input {
accent-color: var(--accent);
.clip-source-label {
font-size: 12px;
color: var(--text-secondary);
white-space: nowrap;
}
.clip-source-select {
max-width: 320px;
padding: 6px 10px;
font-size: 13px;
color: var(--text-primary);
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
font-family: var(--font-body);
}
.asset-hint {