From d243e0a1aba0cd86b70a5c6ac94bf0032a6067c9 Mon Sep 17 00:00:00 2001 From: Justo Stoll Date: Sun, 23 Aug 2026 00:39:37 +0200 Subject: [PATCH] Video tab: Generate-all button to queue every scene's clip in sequence Queues clips one POST at a time in timeline order rather than a single all-scenes request: the H3 prompt rewrite runs synchronously inside each generate-videos request (~1-3 min per scene on local models), so one bulk request for a long timeline would sit for many minutes and risk a client timeout. The label is state-aware - 'Generate all (n)' targets only scenes without a clip (skipping done and in-flight scenes), flipping to 'Regenerate all' when the timeline is complete. A scene that fails to queue toasts and the loop continues. Rendering itself stays serialized by the queue worker. Workflow resolution matches the per-scene Generate button (session pick -> scene's stored workflow -> first enabled video workflow), which also heals scenes whose stored workflow was deleted - without it they enqueue a job doomed to 'No workflow found for job'. Co-Authored-By: Claude Fable 5 --- .../src/lib/components/QueueStage.svelte | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/calliope-web/src/lib/components/QueueStage.svelte b/calliope-web/src/lib/components/QueueStage.svelte index 623a60d1..7c16eeae 100644 --- a/calliope-web/src/lib/components/QueueStage.svelte +++ b/calliope-web/src/lib/components/QueueStage.svelte @@ -136,6 +136,61 @@ onError: (err) => toast.error(err instanceof Error ? err.message : String(err)), }); + // --- Batch generate: queue clips one by one, in timeline order. --- + // 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). + let batching = $state(false); + let batchNote = $state(''); + + const scenesNeedingClip = $derived( + scenes.filter((s) => !['done', 'pending', 'running'].includes(statusOf(s))), + ); + const batchTargets = $derived( + scenesNeedingClip.length > 0 + ? scenesNeedingClip + : scenes.filter((s) => !['pending', 'running'].includes(statusOf(s))), + ); + const batchLabel = $derived( + batching + ? batchNote + : scenesNeedingClip.length > 0 + ? `Generate all (${scenesNeedingClip.length})` + : 'Regenerate all', + ); + + async function generateAll() { + if (batching || batchTargets.length === 0) return; + batching = true; + let queued = 0; + const targets = [...batchTargets].sort((a, b) => a.order_index - b.order_index); + for (let i = 0; i < targets.length; i++) { + const scene = targets[i]; + batchNote = `Queueing ${i + 1}/${targets.length}…`; + try { + // Resolve like the per-scene button does: session pick → scene's stored + // workflow → first enabled video workflow. A scene whose stored workflow + // was deleted would otherwise enqueue a job doomed to "No workflow found". + await jobsApi.generateVideos(projectId, { + scene_ids: [scene.id], + workflow_id: workflowFor(scene)?.id, + }); + queued++; + client.invalidateQueries({ queryKey: ['jobs'] }); + client.invalidateQueries({ queryKey: ['scenes'] }); + } catch (err) { + toast.error( + `Scene #${scene.order_index}: ${err instanceof Error ? err.message : String(err)}`, + ); + } + } + batching = false; + batchNote = ''; + if (queued > 0) toast.success(`${queued} clip${queued === 1 ? '' : 's'} queued — rendering in sequence`); + await client.invalidateQueries({ queryKey: ['jobs'] }); + await client.invalidateQueries({ queryKey: ['scenes'] }); + } + function workflowFor(scene: Scene): Workflow | undefined { const id = selectedWorkflow[scene.id] ?? scene.workflow_id ?? undefined; return enabledWorkflows.find((w) => w.id === id) ?? enabledWorkflows[0] ?? undefined; @@ -345,6 +400,17 @@

+ {#if scenes.length > 0} + + {/if}