feat: prompt review gate, ComfyUI error surfacing, saved scene setups (1.3.0)
Issues #27/#33/#28. Generate now resolves the prompt first (saved draft or H3 rewrite) and opens an editable review modal before enqueueing; job history drawer shows each render's exact payload with copy-to-form. ComfyUI 400s surface error.type + per-node messages; audio uploads go flat and VHS audio: widgets are patched. Per-scene video settings persist via scenes.video_settings_json (additive migration) and batch generate honors them. Version bumped to 1.3.0.
This commit is contained in:
@@ -104,8 +104,15 @@ export interface Settings {
|
||||
dry_run: boolean;
|
||||
}
|
||||
|
||||
import type { Job, Scene, Workflow, ComfyDynamicInput, ComfyDynamicOutput } from './comfy/types';
|
||||
export type { Job, Scene, Workflow, ComfyDynamicInput, ComfyDynamicOutput };
|
||||
import type {
|
||||
Job,
|
||||
Scene,
|
||||
SceneVideoSettings,
|
||||
Workflow,
|
||||
ComfyDynamicInput,
|
||||
ComfyDynamicOutput,
|
||||
} from './comfy/types';
|
||||
export type { Job, Scene, SceneVideoSettings, Workflow, ComfyDynamicInput, ComfyDynamicOutput };
|
||||
|
||||
async function api<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
@@ -274,12 +281,26 @@ export const jobsApi = {
|
||||
scene_ids?: number[];
|
||||
workflow_id?: number;
|
||||
input_values?: Record<string, unknown>;
|
||||
prompts?: Record<string, string>;
|
||||
} = {},
|
||||
) =>
|
||||
api<{ ok: boolean; jobs: Job[] }>(`/api/jobs/projects/${projectId}/generate-videos`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
previewPrompt: (
|
||||
projectId: number,
|
||||
payload: { scene_id: number; workflow_id?: number },
|
||||
) =>
|
||||
api<{
|
||||
prompt: string;
|
||||
profile: string;
|
||||
from_draft: boolean;
|
||||
based_on: string;
|
||||
}>(`/api/jobs/projects/${projectId}/preview-prompt`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
exportFilm: (projectId: number) =>
|
||||
api<{ ok: boolean; job: Job }>(`/api/jobs/projects/${projectId}/export`, { method: 'POST' }),
|
||||
};
|
||||
|
||||
@@ -53,6 +53,16 @@ export interface Job {
|
||||
retry_count: number;
|
||||
}
|
||||
|
||||
export interface SceneVideoSettings {
|
||||
input_values?: Record<string, string | number>;
|
||||
/** 'auto' | 'upload' | target scene id as string. */
|
||||
clip_source?: string;
|
||||
form_workflow_id?: number;
|
||||
prompt_draft?: string;
|
||||
prompt_draft_meta?: { based_on?: string; saved_at?: string };
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface Scene {
|
||||
id: number;
|
||||
project_id: number;
|
||||
@@ -66,6 +76,7 @@ export interface Scene {
|
||||
location_id: number | null;
|
||||
video_path: string | null;
|
||||
chain_from_prev?: number | boolean | null;
|
||||
video_settings?: SceneVideoSettings | null;
|
||||
character_ids: number[];
|
||||
characters: Array<{
|
||||
id: number;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import type { AssetOption } from '$lib/assetPicker';
|
||||
import { progressFor } from '$lib/jobProgress';
|
||||
import SafeMedia from './SafeMedia.svelte';
|
||||
import PromptPreviewModal from './video/PromptPreviewModal.svelte';
|
||||
import VideoEditWorkspace from './video/VideoEditWorkspace.svelte';
|
||||
import Button from './ui/Button.svelte';
|
||||
import Icon from './ui/Icon.svelte';
|
||||
@@ -170,9 +171,78 @@
|
||||
if (id === lastFormScene) return;
|
||||
if (lastFormScene != null) formCache.set(lastFormScene, formValues);
|
||||
lastFormScene = id;
|
||||
formValues = id != null ? { ...(formCache.get(id) ?? seedSceneDefaults(selected)) } : {};
|
||||
if (id != null) {
|
||||
const stored = formCache.get(id);
|
||||
if (stored) {
|
||||
formValues = { ...stored };
|
||||
} else if (selected?.video_settings?.input_values) {
|
||||
// First open of a persisted setup: hydrate from the scene row.
|
||||
formValues = {
|
||||
...seedSceneDefaults(selected),
|
||||
...selected.video_settings.input_values,
|
||||
};
|
||||
} else {
|
||||
formValues = { ...seedSceneDefaults(selected) };
|
||||
}
|
||||
} else {
|
||||
formValues = {};
|
||||
}
|
||||
});
|
||||
|
||||
// --- Auto-save scene setup (issue #28) ---
|
||||
// Debounced write-through: in-memory formCache stays source of truth for
|
||||
// the session; the scene row makes it survive restarts. Hash-compare so
|
||||
// polling refetches never trigger PATCH churn.
|
||||
let saveTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let lastSavedHash = $state('');
|
||||
|
||||
function currentVideoSettings(): Record<string, unknown> {
|
||||
if (!selected) return {};
|
||||
const out: Record<string, unknown> = {
|
||||
input_values: compactInputValues(formValues),
|
||||
};
|
||||
const wfId = selectedWorkflow[selected.id];
|
||||
if (wfId) out.form_workflow_id = wfId;
|
||||
const src = clipSource[selected.id];
|
||||
if (src) out.clip_source = src;
|
||||
const draft = selected.video_settings?.prompt_draft;
|
||||
const meta = selected.video_settings?.prompt_draft_meta;
|
||||
if (draft) {
|
||||
out.prompt_draft = draft;
|
||||
if (meta) out.prompt_draft_meta = meta;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function settingsHash(obj: Record<string, unknown>): string {
|
||||
return JSON.stringify(obj);
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
// Track the pieces that make up the persisted settings.
|
||||
const _unused = [formValues, selectedWorkflow, clipSource, selected?.id];
|
||||
void _unused;
|
||||
if (!selected || saveTimer) return;
|
||||
saveTimer = setTimeout(() => {
|
||||
saveTimer = null;
|
||||
if (!selected) return;
|
||||
const next = currentVideoSettings();
|
||||
const hash = settingsHash(next);
|
||||
if (hash === lastSavedHash) return;
|
||||
lastSavedHash = hash;
|
||||
projects
|
||||
.updateScene(projectId, selected.id, { video_settings: next })
|
||||
.catch(() => {
|
||||
/* transient — next change retries */
|
||||
});
|
||||
}, 800);
|
||||
});
|
||||
|
||||
async function onFormChangePersist() {
|
||||
// formCache write-through happens in the switch effect; autosave effect
|
||||
// handles persistence. Kept as an explicit hook for future callers.
|
||||
}
|
||||
|
||||
// Context-aware defaults for a freshly opened scene form (user edits and the
|
||||
// workflow's static defaults must not override these). Duration-role inputs
|
||||
// seed from the scene's estimated duration; ComfyDynamicForm's own prefill
|
||||
@@ -209,13 +279,15 @@
|
||||
}
|
||||
|
||||
const generateOne = createMutation({
|
||||
mutationFn: (sceneId: number) => {
|
||||
mutationFn: (vars: { sceneId: number; prompt?: string }) => {
|
||||
const { sceneId } = vars;
|
||||
const scene = scenes.find((s) => s.id === sceneId);
|
||||
const wf = scene ? workflowFor(scene) : undefined;
|
||||
return jobsApi.generateVideos(projectId, {
|
||||
scene_ids: [sceneId],
|
||||
workflow_id: selectedWorkflow[sceneId] ?? wf?.id,
|
||||
input_values: compactInputValues(formValues),
|
||||
prompts: vars.prompt ? { [String(sceneId)]: vars.prompt } : undefined,
|
||||
});
|
||||
},
|
||||
onSuccess: async () => {
|
||||
@@ -226,6 +298,19 @@
|
||||
onError: (err) => toast.error(err instanceof Error ? err.message : String(err)),
|
||||
});
|
||||
|
||||
// --- HITL review gate (issue #27) ---
|
||||
let previewOpen = $state(false);
|
||||
|
||||
function beginGenerate() {
|
||||
if (!selected) return;
|
||||
previewOpen = true;
|
||||
}
|
||||
|
||||
function onGenerateConfirmed(prompt: string) {
|
||||
if (!selected) return;
|
||||
$generateOne.mutate({ sceneId: selected.id, prompt });
|
||||
}
|
||||
|
||||
// --- 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).
|
||||
@@ -255,6 +340,7 @@
|
||||
if (batching || batchTargets.length === 0) return;
|
||||
batching = true;
|
||||
let queued = 0;
|
||||
let drafted = 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];
|
||||
@@ -263,11 +349,20 @@
|
||||
// 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".
|
||||
// Saved prompt drafts ride along; un-drafted scenes get the backend's
|
||||
// auto-rewrite (deterministic template on LLM failure).
|
||||
const draft = scene.video_settings?.prompt_draft;
|
||||
const draftFresh =
|
||||
draft && scene.video_settings?.prompt_draft_meta?.based_on
|
||||
? scene.video_settings.prompt_draft_meta.based_on
|
||||
: null;
|
||||
await jobsApi.generateVideos(projectId, {
|
||||
scene_ids: [scene.id],
|
||||
workflow_id: workflowFor(scene)?.id,
|
||||
prompts: draft ? { [String(scene.id)]: draft } : undefined,
|
||||
});
|
||||
queued++;
|
||||
if (draft) drafted++;
|
||||
client.invalidateQueries({ queryKey: ['jobs'] });
|
||||
client.invalidateQueries({ queryKey: ['scenes'] });
|
||||
} catch (err) {
|
||||
@@ -278,7 +373,12 @@
|
||||
}
|
||||
batching = false;
|
||||
batchNote = '';
|
||||
if (queued > 0) toast.success(`${queued} clip${queued === 1 ? '' : 's'} queued — rendering in sequence`);
|
||||
if (queued > 0) {
|
||||
const draftNote = drafted > 0 ? ` · ${drafted} saved draft${drafted === 1 ? '' : 's'}` : '';
|
||||
toast.success(
|
||||
`${queued} clip${queued === 1 ? '' : 's'} queued — rendering in sequence${draftNote}`,
|
||||
);
|
||||
}
|
||||
await client.invalidateQueries({ queryKey: ['jobs'] });
|
||||
await client.invalidateQueries({ queryKey: ['scenes'] });
|
||||
}
|
||||
@@ -578,6 +678,10 @@
|
||||
progress={selProg}
|
||||
error={selError}
|
||||
errorLong={selErrorLong}
|
||||
job={selJob}
|
||||
sceneJobs={($jobsQuery.data ?? []).filter(
|
||||
(j) => j.scene_id === selected.id && j.kind === 'video',
|
||||
)}
|
||||
workflow={selWf}
|
||||
workflows={enabledWorkflows}
|
||||
bind:formValues
|
||||
@@ -624,8 +728,18 @@
|
||||
onWorkflowChange={(id) => {
|
||||
selectedWorkflow = { ...selectedWorkflow, [selected.id]: Number(id) };
|
||||
}}
|
||||
onGenerate={() => $generateOne.mutate(selected.id)}
|
||||
/>
|
||||
onGenerate={() => $generateOne.mutate({ sceneId: selected.id })}
|
||||
onPreviewPrompt={beginGenerate}
|
||||
/>
|
||||
|
||||
<PromptPreviewModal
|
||||
bind:open={previewOpen}
|
||||
{projectId}
|
||||
scene={selected}
|
||||
workflow={selWf}
|
||||
inputValues={formValues}
|
||||
onConfirm={onGenerateConfirmed}
|
||||
/>
|
||||
{/if}
|
||||
{:else}
|
||||
<section class="film-view" aria-label="Film screening room">
|
||||
|
||||
@@ -0,0 +1,399 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* JobInputsDrawer — per-scene job history + read-only view of what a job
|
||||
* sent to ComfyUI. Reads job.payload (persisted in jobs.payload_json,
|
||||
* served via _job_public): the resolved prompt plus per-node input values.
|
||||
* Ref assignments are labeled by matching node ids against the workflow's
|
||||
* input_schema roles. "Copy settings to form" loads payload.input_values
|
||||
* back into the live form via the caller-provided callback.
|
||||
*/
|
||||
import type { Job, Workflow } from '$lib/api';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
import Modal from '$lib/components/ui/Modal.svelte';
|
||||
|
||||
interface Props {
|
||||
open?: boolean;
|
||||
/** Latest job for the scene — shown by default. */
|
||||
job?: Job | null;
|
||||
/** Full job list for the scene, newest first (drives history). */
|
||||
jobs?: Job[];
|
||||
workflow?: Workflow | null;
|
||||
/** Load a job's input_values back into the video form. */
|
||||
onCopySettings?: (values: Record<string, string | number>) => void;
|
||||
onclose?: () => void;
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
job = null,
|
||||
jobs = [],
|
||||
workflow = null,
|
||||
onCopySettings,
|
||||
onclose,
|
||||
}: Props = $props();
|
||||
|
||||
let selectedJobId = $state<number | null>(null);
|
||||
let copied = $state(false);
|
||||
|
||||
const historyJobs = $derived.by(() => {
|
||||
const list = (jobs ?? []).filter((j) => j.kind === 'video' && j.payload != null);
|
||||
return [...list].sort((a, b) => b.id - a.id).slice(0, 20);
|
||||
});
|
||||
|
||||
const activeJob = $derived(
|
||||
historyJobs.find((j) => j.id === selectedJobId) ?? job ?? historyJobs[0] ?? null,
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
if (open && selectedJobId == null && activeJob) {
|
||||
selectedJobId = activeJob.id;
|
||||
}
|
||||
});
|
||||
|
||||
const prompt = $derived(
|
||||
typeof activeJob?.payload?.prompt === 'string' && activeJob.payload.prompt.trim()
|
||||
? (activeJob.payload.prompt as string)
|
||||
: null,
|
||||
);
|
||||
|
||||
interface ValueRow {
|
||||
nodeId: string;
|
||||
label: string;
|
||||
role: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
const valueRows = $derived.by((): ValueRow[] => {
|
||||
const raw = activeJob?.payload?.input_values;
|
||||
if (!raw || typeof raw !== 'object') return [];
|
||||
const schema = workflow?.input_schema ?? [];
|
||||
return Object.entries(raw as Record<string, unknown>)
|
||||
.filter(([, v]) => v !== null && v !== undefined && String(v) !== '')
|
||||
.map(([nodeId, v]) => {
|
||||
const inp = schema.find((i) => i.nodeId === nodeId);
|
||||
return {
|
||||
nodeId,
|
||||
label: inp?.label ?? nodeId,
|
||||
role: inp?.role ?? '',
|
||||
value: String(v),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const refRows = $derived(valueRows.filter((r) => ['character', 'location', 'image', 'video', 'audio'].includes(r.role)));
|
||||
const otherRows = $derived(valueRows.filter((r) => !['character', 'location', 'image', 'video', 'audio'].includes(r.role)));
|
||||
|
||||
function roleLabel(role: string): string {
|
||||
switch (role) {
|
||||
case 'character':
|
||||
return 'Character ref';
|
||||
case 'location':
|
||||
return 'Location ref';
|
||||
case 'image':
|
||||
return 'Ref image';
|
||||
case 'video':
|
||||
return 'Video input';
|
||||
case 'audio':
|
||||
return 'Audio input';
|
||||
default:
|
||||
return role;
|
||||
}
|
||||
}
|
||||
|
||||
function baseName(path: string): string {
|
||||
const parts = path.replace(/\\/g, '/').split('/');
|
||||
return parts[parts.length - 1] || path;
|
||||
}
|
||||
|
||||
function copySettings() {
|
||||
if (!onCopySettings || !activeJob) return;
|
||||
const raw = activeJob.payload?.input_values;
|
||||
if (!raw || typeof raw !== 'object') return;
|
||||
const values: Record<string, string | number> = {};
|
||||
for (const [k, v] of Object.entries(raw as Record<string, unknown>)) {
|
||||
if (typeof v === 'string' || typeof v === 'number') values[k] = v;
|
||||
}
|
||||
onCopySettings(values);
|
||||
open = false;
|
||||
}
|
||||
|
||||
function statusChipClass(status: string): string {
|
||||
if (status === 'done') return 'chip-done';
|
||||
if (status === 'failed') return 'chip-failed';
|
||||
if (status === 'running') return 'chip-running';
|
||||
return 'chip-pending';
|
||||
}
|
||||
|
||||
function shortTime(iso: string): string {
|
||||
const d = new Date(iso);
|
||||
if (Number.isNaN(d.getTime())) return '';
|
||||
return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
|
||||
}
|
||||
|
||||
async function copyPrompt() {
|
||||
if (!prompt) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(prompt);
|
||||
copied = true;
|
||||
setTimeout(() => (copied = false), 1600);
|
||||
} catch {
|
||||
/* clipboard unavailable — no-op */
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:open {onclose} title="Scene render history" size="lg">
|
||||
{#if !activeJob}
|
||||
<p class="muted">No render jobs recorded for this scene yet.</p>
|
||||
{:else}
|
||||
{#if historyJobs.length > 1}
|
||||
<div class="history-strip" role="tablist" aria-label="Render history">
|
||||
{#each historyJobs as j (j.id)}
|
||||
<button
|
||||
type="button"
|
||||
class="history-chip {j.id === activeJob.id ? 'active' : ''}"
|
||||
role="tab"
|
||||
aria-selected={j.id === activeJob.id}
|
||||
onclick={() => (selectedJobId = j.id)}
|
||||
>
|
||||
<span class="chip-dot {statusChipClass(j.status)}"></span>
|
||||
<span>#{j.id}</span>
|
||||
<span class="chip-time">{j.completed_at ? shortTime(j.completed_at) : j.status}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="job-head">
|
||||
<span class="job-meta">Job #{activeJob.id}</span>
|
||||
<span class="job-meta">·</span>
|
||||
<span class="job-meta">{activeJob.status}</span>
|
||||
{#if activeJob.completed_at}
|
||||
<span class="job-meta">·</span>
|
||||
<span class="job-meta">{new Date(activeJob.completed_at).toLocaleString()}</span>
|
||||
{/if}
|
||||
<span class="job-head-actions">
|
||||
{#if onCopySettings && activeJob.payload?.input_values}
|
||||
<Button size="sm" variant="secondary" onclick={copySettings}>
|
||||
<Icon name="upload" size={14} /> Copy settings to form
|
||||
</Button>
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{#if prompt}
|
||||
<section class="block">
|
||||
<div class="block-head">
|
||||
<h3 class="block-title">Prompt</h3>
|
||||
<Button size="sm" variant="ghost" onclick={copyPrompt}>
|
||||
<Icon name={copied ? 'check' : 'link'} size={14} />
|
||||
{copied ? 'Copied' : 'Copy'}
|
||||
</Button>
|
||||
</div>
|
||||
{#if workflow?.prompt_profile === 'minimax_h3_ref'}
|
||||
<p class="block-hint">MiniMax H3 six-section rewrite — this is the exact text queued on the (Input:prompt) node.</p>
|
||||
{/if}
|
||||
<pre class="prompt-pre">{prompt}</pre>
|
||||
</section>
|
||||
{:else}
|
||||
<p class="muted">No prompt recorded on this job.</p>
|
||||
{/if}
|
||||
|
||||
{#if refRows.length > 0}
|
||||
<section class="block">
|
||||
<h3 class="block-title">References</h3>
|
||||
<ul class="ref-list">
|
||||
{#each refRows as row (row.nodeId)}
|
||||
<li class="ref-item">
|
||||
<span class="ref-role">{roleLabel(row.role)}</span>
|
||||
<span class="ref-name" title={row.value}>{baseName(row.value)}</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
{#if otherRows.length > 0}
|
||||
<section class="block">
|
||||
<h3 class="block-title">Other inputs</h3>
|
||||
<ul class="ref-list">
|
||||
{#each otherRows as row (row.nodeId)}
|
||||
<li class="ref-item">
|
||||
<span class="ref-role">{row.label}</span>
|
||||
<span class="ref-name" title={row.value}>{row.value}</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</section>
|
||||
{/if}
|
||||
{/if}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.muted {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.job-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin: 0 0 14px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.job-head-actions {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.history-strip {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
overflow-x: auto;
|
||||
padding-bottom: 6px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.history-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-shrink: 0;
|
||||
padding: 4px 10px;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
font-family: var(--font-mono);
|
||||
color: var(--text-secondary);
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 9999px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.history-chip:hover {
|
||||
color: var(--text-primary);
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.history-chip.active {
|
||||
color: var(--text-primary);
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 1px var(--accent);
|
||||
}
|
||||
|
||||
.chip-dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
.chip-done {
|
||||
background: var(--success);
|
||||
}
|
||||
|
||||
.chip-failed {
|
||||
background: var(--error);
|
||||
}
|
||||
|
||||
.chip-running {
|
||||
background: var(--warning);
|
||||
}
|
||||
|
||||
.chip-pending {
|
||||
background: var(--text-muted);
|
||||
}
|
||||
|
||||
.chip-time {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.job-meta {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.block {
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.block-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.block-title {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
color: var(--text-primary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.block-hint {
|
||||
margin: 0 0 6px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.prompt-pre {
|
||||
margin: 0;
|
||||
padding: 12px;
|
||||
max-height: 320px;
|
||||
overflow-y: auto;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.ref-list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.ref-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.ref-role {
|
||||
flex-shrink: 0;
|
||||
min-width: 110px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.ref-name {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,235 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* PromptPreviewModal — HITL review gate before Generate (issue #27).
|
||||
* Resolves the exact prompt (saved fresh draft → LLM rewrite → fallback),
|
||||
* lets the user edit/regenerate/save it, and only enqueues on confirm.
|
||||
*/
|
||||
import { createMutation } from '@tanstack/svelte-query';
|
||||
import { toast } from '$lib/toast';
|
||||
import { jobsApi, projects, type Scene, type Workflow } from '$lib/api';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
import Modal from '$lib/components/ui/Modal.svelte';
|
||||
import Spinner from '$lib/components/ui/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
open?: boolean;
|
||||
projectId: number;
|
||||
scene: Scene | null;
|
||||
workflow?: Workflow | null;
|
||||
/** Extra form values to pass through on confirm. */
|
||||
inputValues?: Record<string, string | number>;
|
||||
/** Fallback enqueue path when the modal confirms. */
|
||||
onConfirm: (prompt: string) => void;
|
||||
onclose?: () => void;
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
projectId,
|
||||
scene,
|
||||
workflow = null,
|
||||
inputValues = {},
|
||||
onConfirm,
|
||||
onclose,
|
||||
}: Props = $props();
|
||||
|
||||
let text = $state('');
|
||||
let basedOn = $state('');
|
||||
let fromDraft = $state(false);
|
||||
let stale = $state(false);
|
||||
let loadedScene = $state<number | null>(null);
|
||||
|
||||
const preview = createMutation({
|
||||
mutationFn: async () => {
|
||||
if (!scene) throw new Error('No scene selected');
|
||||
return jobsApi.previewPrompt(projectId, {
|
||||
scene_id: scene.id,
|
||||
workflow_id: workflow?.id,
|
||||
});
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
text = data.prompt;
|
||||
basedOn = data.based_on;
|
||||
fromDraft = data.from_draft;
|
||||
stale = false;
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
},
|
||||
});
|
||||
|
||||
// Resolve whenever the modal opens for a (new) scene.
|
||||
$effect(() => {
|
||||
if (!open || !scene) return;
|
||||
if (loadedScene === scene.id && text) return;
|
||||
loadedScene = scene.id;
|
||||
$preview.mutate();
|
||||
});
|
||||
|
||||
// Stale check: a draft saved against different scene content should warn.
|
||||
$effect(() => {
|
||||
if (!scene || !basedOn) return;
|
||||
const meta = scene.video_settings?.prompt_draft_meta?.based_on;
|
||||
stale = fromDraft && meta != null && meta !== basedOn;
|
||||
});
|
||||
|
||||
const draftMeta = $derived(scene?.video_settings?.prompt_draft_meta);
|
||||
|
||||
async function saveDraft() {
|
||||
if (!scene || !text.trim()) return;
|
||||
const existing = scene.video_settings ?? {};
|
||||
const next = {
|
||||
...existing,
|
||||
prompt_draft: text,
|
||||
prompt_draft_meta: { based_on: basedOn, saved_at: new Date().toISOString() },
|
||||
};
|
||||
try {
|
||||
await projects.updateScene(projectId, scene.id, { video_settings: next });
|
||||
toast.success('Draft saved — Generate will use it');
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}
|
||||
|
||||
function regenerate() {
|
||||
$preview.mutate();
|
||||
}
|
||||
|
||||
function confirmGenerate() {
|
||||
const prompt = text.trim();
|
||||
if (!prompt) {
|
||||
toast.error('Prompt is empty — edit or regenerate before generating');
|
||||
return;
|
||||
}
|
||||
open = false;
|
||||
onConfirm(prompt);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:open {onclose} title="Review prompt before generating" size="lg">
|
||||
{#if !scene}
|
||||
<p class="muted">No scene selected.</p>
|
||||
{:else if $preview.isPending}
|
||||
<div class="loading">
|
||||
<Spinner size="md" />
|
||||
<span>Resolving prompt{workflow?.prompt_profile === 'minimax_h3_ref' ? ' (H3 rewrite)' : ''}…</span>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="head-row">
|
||||
<span class="meta">Scene #{scene.order_index} · {scene.heading || 'Untitled'}</span>
|
||||
<span class="meta">{workflow?.name ?? 'Default workflow'}</span>
|
||||
</div>
|
||||
|
||||
{#if stale}
|
||||
<div class="stale-hint" role="status">
|
||||
<Icon name="alert" size={14} />
|
||||
<span>Saved draft is based on older scene content — regenerate to refresh it.</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<textarea
|
||||
class="prompt-editor"
|
||||
bind:value={text}
|
||||
rows={16}
|
||||
spellcheck="false"
|
||||
aria-label="Prompt text sent to the workflow"
|
||||
></textarea>
|
||||
|
||||
{#if fromDraft}
|
||||
<p class="hint">Loaded from your saved draft. Regenerate re-runs the rewrite.</p>
|
||||
{:else if workflow?.prompt_profile === 'minimax_h3_ref'}
|
||||
<p class="hint">MiniMax H3 six-section rewrite. Edit freely — this exact text goes to the (Input:prompt) node.</p>
|
||||
{:else}
|
||||
<p class="hint">Scene prompt (prose profile). Edit freely before generating.</p>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#snippet footer()}
|
||||
<Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
|
||||
<Button variant="secondary" disabled={$preview.isPending || !text} onclick={saveDraft}>
|
||||
Save draft
|
||||
</Button>
|
||||
<Button variant="secondary" disabled={$preview.isPending} onclick={regenerate}>
|
||||
<Icon name="retry" size={14} /> Regenerate
|
||||
</Button>
|
||||
<Button variant="primary" disabled={$preview.isPending || !text} onclick={confirmGenerate}>
|
||||
<Icon name="play" size={14} /> Generate
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.muted {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 24px 0;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.head-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.meta {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.stale-hint {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0 0 10px;
|
||||
padding: 8px 10px;
|
||||
font-size: 13px;
|
||||
color: var(--warning);
|
||||
border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--border));
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--warning) 10%, var(--bg-surface));
|
||||
}
|
||||
|
||||
.stale-hint :global(svg) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.prompt-editor {
|
||||
width: 100%;
|
||||
min-height: 260px;
|
||||
padding: 12px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
color: var(--text-primary);
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.prompt-editor:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 8px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
</style>
|
||||
@@ -4,12 +4,14 @@
|
||||
* Hero monitor + filmstrip + meta strip + docked Omni composer.
|
||||
* Does not reuse the old top two-card clip-stage layout.
|
||||
*/
|
||||
import type { Scene, Workflow } from '$lib/api';
|
||||
import type { Job, 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 ClipSourceModal from './ClipSourceModal.svelte';
|
||||
import JobInputsDrawer from './JobInputsDrawer.svelte';
|
||||
import PromptPreviewModal from './PromptPreviewModal.svelte';
|
||||
import SceneFilmstrip from './SceneFilmstrip.svelte';
|
||||
import SceneScriptDrawer from './SceneScriptDrawer.svelte';
|
||||
|
||||
@@ -44,6 +46,10 @@
|
||||
progress?: Progress | null;
|
||||
error?: string;
|
||||
errorLong?: boolean;
|
||||
/** Latest video job for the scene — drives the "what was sent" drawer. */
|
||||
job?: Job | null;
|
||||
/** All video jobs for the scene (history strip in the drawer). */
|
||||
sceneJobs?: Job[];
|
||||
workflow: Workflow | undefined;
|
||||
workflows: Workflow[];
|
||||
formValues: Record<string, string | number>;
|
||||
@@ -52,11 +58,14 @@
|
||||
/** 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;
|
||||
/** Upload file picked in the source modal — caller opens the file dialog. */
|
||||
onClipSourceUpload?: () => void;
|
||||
/** Where this continue scene's video input comes from (auto / upload / a timeline clip). */
|
||||
clipSource?: ClipSourceConfig;
|
||||
onClipSourceChange?: (value: string) => void;
|
||||
/** Upload file picked in the source modal — caller opens the file dialog. */
|
||||
onClipSourceUpload?: () => void;
|
||||
/** HITL prompt review before Generate: caller resolves + shows the modal. */
|
||||
onPreviewPrompt?: () => void;
|
||||
generateLabel?: string;
|
||||
chained?: (scene: Scene) => boolean;
|
||||
submitting?: boolean;
|
||||
statusOf: (scene: Scene) => string;
|
||||
@@ -78,6 +87,8 @@
|
||||
progress = null,
|
||||
error = '',
|
||||
errorLong = false,
|
||||
job = null,
|
||||
sceneJobs = [],
|
||||
workflow,
|
||||
workflows,
|
||||
formValues = $bindable(),
|
||||
@@ -88,6 +99,8 @@
|
||||
clipSource,
|
||||
onClipSourceChange,
|
||||
onClipSourceUpload,
|
||||
onPreviewPrompt,
|
||||
generateLabel = 'Generate clip',
|
||||
chained = () => false,
|
||||
submitting = false,
|
||||
statusOf,
|
||||
@@ -101,6 +114,15 @@
|
||||
}: Props = $props();
|
||||
|
||||
let clipSourceOpen = $state(false);
|
||||
let inputsOpen = $state(false);
|
||||
|
||||
const hasJobPayload = $derived(
|
||||
Boolean(
|
||||
job &&
|
||||
((typeof job.payload?.prompt === 'string' && job.payload.prompt) ||
|
||||
job.payload?.input_values),
|
||||
),
|
||||
);
|
||||
|
||||
/** The label shown on the Video source trigger. */
|
||||
const clipSourceLabel = $derived.by(() => {
|
||||
@@ -176,12 +198,36 @@
|
||||
onupload={() => onClipSourceUpload?.()}
|
||||
/>
|
||||
{/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 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 hasJobPayload}
|
||||
<div class="job-inputs-row">
|
||||
<button
|
||||
type="button"
|
||||
class="job-inputs-trigger"
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={inputsOpen}
|
||||
onclick={() => (inputsOpen = true)}
|
||||
>
|
||||
<Icon name="info" size={14} />
|
||||
<span>View prompt & inputs</span>
|
||||
</button>
|
||||
</div>
|
||||
<JobInputsDrawer
|
||||
bind:open={inputsOpen}
|
||||
{job}
|
||||
jobs={sceneJobs}
|
||||
{workflow}
|
||||
onCopySettings={(values) => {
|
||||
formValues = { ...formValues, ...values };
|
||||
onFormChange?.({ ...formValues });
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
<OmniComposer
|
||||
inputs={workflow.input_schema}
|
||||
bind:values={formValues}
|
||||
@@ -190,12 +236,12 @@
|
||||
onWorkflowChange={onWorkflowChange}
|
||||
{assetOptions}
|
||||
{allowUpload}
|
||||
generateLabel="Generate clip"
|
||||
{generateLabel}
|
||||
{submitting}
|
||||
disabled={generateDisabled}
|
||||
generateDisabledHint={generateDisabledReason}
|
||||
onChange={onFormChange}
|
||||
onSubmit={onGenerate}
|
||||
onSubmit={onPreviewPrompt ?? onGenerate}
|
||||
/>
|
||||
{:else}
|
||||
<div class="no-wf">
|
||||
@@ -321,6 +367,40 @@
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.job-inputs-row {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.job-inputs-trigger {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px 10px;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
background: transparent;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
transition:
|
||||
color 150ms ease,
|
||||
border-color 150ms ease;
|
||||
}
|
||||
|
||||
.job-inputs-trigger:hover {
|
||||
color: var(--text-primary);
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.job-inputs-trigger:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.no-wf {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
|
||||
Reference in New Issue
Block a user