From 6f4d50f4f06fbb724eabfa5bc483e1b93944fc74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E5=B7=A5?= Date: Wed, 30 Sep 2026 10:59:46 +0800 Subject: [PATCH] =?UTF-8?q?HEL-653:=20C=20=E6=89=B9=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=8F=B0=E2=80=94=E2=80=94=E6=8B=86=E5=88=86=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E5=8F=B0/=E5=B7=A5=E4=BD=9C=E6=B5=81=E9=80=89=E6=8B=A9/?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A7=BD/=E8=AE=B0=E5=BD=95=E6=B5=81/?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - StudioGenerate 拆为 generate/ 下的 Composer、WorkflowPicker、SlotTray、ParamChip、 TakeFeed/TakeCard、Inspector、ParamsPanel、ContextBar,逻辑收进 schema/takes/context - 输入槽只按工作流 JSON 实际接线渲染;常用参数芯片 + 高级参数折叠,显示原值与已改标记 - 工作台素材/镜头卡新增「在生成台调参」,带项目上下文进入;结果不回填(后端无目标) - 共享样式(a-chip/a-seg/a-slot/a-tile 等)进 app.css;ShellPop 支持向上弹出 - /image、/video 仍是同一生成台,按用途预选默认工作流与筛选 Co-authored-by: Cursor Co-authored-by: multica-agent --- .../lib/components/ComfyDynamicForm.svelte | 47 +- .../lib/components/generate/Composer.svelte | 410 +++ .../lib/components/generate/ContextBar.svelte | 70 + .../lib/components/generate/Inspector.svelte | 434 +++ .../lib/components/generate/ParamChip.svelte | 179 + .../components/generate/ParamsPanel.svelte | 198 ++ .../lib/components/generate/SlotTray.svelte | 227 ++ .../lib/components/generate/TakeCard.svelte | 392 +++ .../lib/components/generate/TakeFeed.svelte | 199 ++ .../components/generate/WorkflowPicker.svelte | 223 ++ .../src/lib/components/generate/context.ts | 55 + .../src/lib/components/generate/schema.ts | 372 ++ .../src/lib/components/generate/takes.ts | 129 + .../src/lib/components/shell/ShellPop.svelte | 16 +- .../lib/components/studio/MediaSlot.svelte | 354 +- .../lib/components/studio/RefImageGrid.svelte | 416 +-- .../components/studio/StudioGenerate.svelte | 2992 +++-------------- .../workbench/AssetsStagePanel.svelte | 26 +- .../workbench/ShotStagePanel.svelte | 23 +- calliope-web/src/lib/i18n/de.ts | 89 + calliope-web/src/lib/i18n/en.ts | 89 + calliope-web/src/lib/i18n/es.ts | 89 + calliope-web/src/lib/i18n/fr.ts | 89 + calliope-web/src/lib/i18n/ja.ts | 89 + calliope-web/src/lib/i18n/ko.ts | 89 + calliope-web/src/lib/i18n/zh.ts | 89 + calliope-web/src/routes/app.css | 268 ++ .../src/routes/workbench/[id]/+page.svelte | 2 + 28 files changed, 4566 insertions(+), 3089 deletions(-) create mode 100644 calliope-web/src/lib/components/generate/Composer.svelte create mode 100644 calliope-web/src/lib/components/generate/ContextBar.svelte create mode 100644 calliope-web/src/lib/components/generate/Inspector.svelte create mode 100644 calliope-web/src/lib/components/generate/ParamChip.svelte create mode 100644 calliope-web/src/lib/components/generate/ParamsPanel.svelte create mode 100644 calliope-web/src/lib/components/generate/SlotTray.svelte create mode 100644 calliope-web/src/lib/components/generate/TakeCard.svelte create mode 100644 calliope-web/src/lib/components/generate/TakeFeed.svelte create mode 100644 calliope-web/src/lib/components/generate/WorkflowPicker.svelte create mode 100644 calliope-web/src/lib/components/generate/context.ts create mode 100644 calliope-web/src/lib/components/generate/schema.ts create mode 100644 calliope-web/src/lib/components/generate/takes.ts diff --git a/calliope-web/src/lib/components/ComfyDynamicForm.svelte b/calliope-web/src/lib/components/ComfyDynamicForm.svelte index 89a83826..3fe8606f 100644 --- a/calliope-web/src/lib/components/ComfyDynamicForm.svelte +++ b/calliope-web/src/lib/components/ComfyDynamicForm.svelte @@ -17,6 +17,10 @@ allowUpload?: boolean; /** Force required-field error rings visible (e.g. after a blocked Generate). */ showErrors?: boolean; + /** Show each field's workflow value (原值) and mark fields that differ from it. */ + showOrig?: boolean; + /** Extra per-field messages keyed by nodeId (e.g. range checks); shown with showErrors. */ + errors?: Record; /** Emits labels of required-but-empty inputs whenever the set changes. */ onValidityChange?: (missing: string[]) => void; onChange?: (values: Record) => void; @@ -30,10 +34,23 @@ assetOptions = [], allowUpload = false, showErrors = false, + showOrig = false, + errors = {}, onValidityChange, onChange, }: Props = $props(); + function hasOrig(inp: ComfyDynamicInput): boolean { + return inp.defaultValue !== undefined && inp.defaultValue !== ''; + } + + function isChanged(inp: ComfyDynamicInput): boolean { + if (!showOrig) return false; + const v = values[inp.nodeId]; + if (isBlank(v)) return hasOrig(inp); + return !hasOrig(inp) || String(v) !== String(inp.defaultValue); + } + // Unique per mounted form so label/id pairs never collide across instances. const uid = Math.random().toString(36).slice(2, 8); let touched = $state>({}); @@ -80,6 +97,11 @@ return isMissing(inp) && (showErrors || !!touched[inp.nodeId]); } + function extraError(inp: ComfyDynamicInput): string | null { + const msg = errors[inp.nodeId]?.trim(); + return msg && !isMissing(inp) && (showErrors || !!touched[inp.nodeId]) ? msg : null; + } + function thumbFor(current: string): string | null { if (!current) return null; const opt = assetOptions.find((o) => o.path === current); @@ -224,7 +246,9 @@ {#each inputs as inp (inp.nodeId)} {@const current = String(values[inp.nodeId] ?? '')} {@const id = inputId(inp.nodeId)} - {@const errored = showError(inp)} + {@const extra = extraError(inp)} + {@const errored = showError(inp) || !!extra} + {@const changed = isChanged(inp)}
{#if readonly}
{values[inp.nodeId] ?? inp.defaultValue ?? '—'}
@@ -243,6 +270,7 @@ {id} rows="3" class:invalid={errored} + class:changed aria-required={inp.required || undefined} aria-invalid={errored || undefined} value={current} @@ -254,6 +282,7 @@ {id} type="number" class:invalid={errored} + class:changed aria-required={inp.required || undefined} aria-invalid={errored || undefined} value={values[inp.nodeId] ?? ''} @@ -264,6 +293,7 @@ + {#if promptErr}{/if} + {:else if current} +

{t('desk.noPromptInput')}

+ {/if} + +
+ +
+ + +
{t('studio.connLabel')}
+ {#each endpoints as ep (ep.id)} + + {/each} + + + {t('studio.connManage')} + +
+
+ {#each chips as c (c.key)} +
+ !!errors[i.nodeId]?.trim())} + {onSet} + /> +
+ {/each} + {#if ds.common.length + ds.advanced.length > 0} + + {/if} + +
+ {#if block} + + {/if} + +
+
+
+ + + diff --git a/calliope-web/src/lib/components/generate/ContextBar.svelte b/calliope-web/src/lib/components/generate/ContextBar.svelte new file mode 100644 index 00000000..d3281f46 --- /dev/null +++ b/calliope-web/src/lib/components/generate/ContextBar.svelte @@ -0,0 +1,70 @@ + + +
+ + + {t('desk.ctxFrom', { project: projectTitle })}{#if ctx.label} · {ctx.label}{/if} + + {t('desk.ctxNoBackfill', { stage: stageName })} + {t('desk.ctxBack', { stage: stageName })} + +
+ + diff --git a/calliope-web/src/lib/components/generate/Inspector.svelte b/calliope-web/src/lib/components/generate/Inspector.svelte new file mode 100644 index 00000000..0f249192 --- /dev/null +++ b/calliope-web/src/lib/components/generate/Inspector.svelte @@ -0,0 +1,434 @@ + + + + + diff --git a/calliope-web/src/lib/components/generate/ParamChip.svelte b/calliope-web/src/lib/components/generate/ParamChip.svelte new file mode 100644 index 00000000..0ca58a69 --- /dev/null +++ b/calliope-web/src/lib/components/generate/ParamChip.svelte @@ -0,0 +1,179 @@ + + +
+ + i.label).join(' × ')} placement="top" width="260px"> + {#if single?.kind === 'select' && single.options?.length} +
{single.label}
+ {#each single.options as opt (opt)} + + {/each} + {:else} +
+ {#each inputs as inp (inp.nodeId)} + {@const id = `pc-${uid}-${inp.nodeId.replace(/[^a-zA-Z0-9_-]/g, '')}`} +
+ +
+ {#if inp.kind === 'number'} + setNumber(inp, e.currentTarget.value)} + onkeydown={(e) => e.key === 'Enter' && (open = false)} + /> + {:else} + onSet(inp.nodeId, e.currentTarget.value)} + onkeydown={(e) => e.key === 'Enter' && (open = false)} + /> + {/if} + {#if inputRole(inp) === 'seed'} + + {/if} +
+ {#if inp.min != null || inp.max != null} + {inp.min ?? '−∞'} – {inp.max ?? '∞'} + {/if} +
+ {/each} +
+ {/if} + {#if changed} +
+ +
+ {/if} +
+
+ + diff --git a/calliope-web/src/lib/components/generate/ParamsPanel.svelte b/calliope-web/src/lib/components/generate/ParamsPanel.svelte new file mode 100644 index 00000000..5be2e9cf --- /dev/null +++ b/calliope-web/src/lib/components/generate/ParamsPanel.svelte @@ -0,0 +1,198 @@ + + +
+ {#if !workflow} +

{t('desk.pickWorkflow')}

+ {:else} + {#if brokenReasons.length} + + {/if} + {#if !(workflow.input_schema ?? []).length} +

{t('studio.wfNoParamsNote')}

+ {:else if (workflow.input_schema ?? []).some((i) => i.auto)} +

{t('studio.wfAutoParamsNote', { n: workflow.input_schema.length })}

+ {/if} + + {#if ds.common.length} +
{t('desk.paramsCommon')}
+ } + quiet + showOrig + {errors} + {showErrors} + onChange={(v) => patch(ds.common, v)} + /> + {/if} + + {#if ds.advanced.length} +
+ +
+
+ } + quiet + showOrig + {errors} + {showErrors} + onChange={(v) => patch(ds.advanced, v)} + /> +
+
+
+ {/if} + + {#if changedCount > 0} +
+ +
+ {/if} + {/if} +
+ + diff --git a/calliope-web/src/lib/components/generate/SlotTray.svelte b/calliope-web/src/lib/components/generate/SlotTray.svelte new file mode 100644 index 00000000..b7d25b6e --- /dev/null +++ b/calliope-web/src/lib/components/generate/SlotTray.svelte @@ -0,0 +1,227 @@ + + +{#if ds.slots.length || ds.lists.length} +
+ {#each ds.slots as s (s.inp.nodeId)} + {@const reject = rejects[s.inp.nodeId]?.[0]} + slotFile(s, f)} + onFromResults={() => onFromResults(s.inp.nodeId)} + onClear={() => { + setRejects(s.inp.nodeId, []); + onSet(s.inp.nodeId, ''); + }} + /> + {/each} + {#each ds.lists as entry (entry.nodeId)} + groupAdd(entry, files)} + onReplace={(i, file) => groupReplace(entry, i, file)} + onRemove={(i) => onSet(entry.nodeId, listPaths(values, entry).filter((_, j) => j !== i))} + onDismissReject={(i) => setRejects(entry.nodeId, (rejects[entry.nodeId] ?? []).filter((_, j) => j !== i))} + onFromResults={entry.kind === 'image_list' ? () => onFromResults(entry.nodeId) : undefined} + /> + {/each} +
+ {#if showErrors && errors.firstLast} +

{errors.firstLast}

+ {/if} + {#if ds.hasH3Hint} +
+

{t('wfMedia.h3Limits')}

+ {#each warns as w (w)} +

{w}

+ {/each} +
+ {/if} +{/if} + + diff --git a/calliope-web/src/lib/components/generate/TakeCard.svelte b/calliope-web/src/lib/components/generate/TakeCard.svelte new file mode 100644 index 00000000..e3366218 --- /dev/null +++ b/calliope-web/src/lib/components/generate/TakeCard.svelte @@ -0,0 +1,392 @@ + + +
+ + +
+ {name} + {#if wf?.usage}{usageLabel(wf.usage)}{/if} + {fmtClock(parseDbTs(job.created_at))} +
+ + {#if prompt}

{prompt}

{/if} + + {#if inputs.length} +
+ {#each inputs.slice(0, 5) as inp (inp.path + inp.label)} + {inp.label} + {/each} + {#if inputs.length > 5}+{inputs.length - 5}{/if} +
+ {/if} + +
+ {st.label} + {#if st.tone === 'run'} + {#if progress > 0} +
+ {/if} + {fmtDur(elapsedSec(job, nowMs))} + {:else if st.tone === 'ok'} + {t('desk.took', { d: fmtDur(elapsedSec(job, nowMs)) })} + {:else if st.tone === 'fail'} + {st.detail} + {:else} + {st.detail} + {/if} +
+ + {#if st.tone === 'fail' && job.error !== 'cancelled'} + + {/if} + {#if active} + + {/if} + {#if output} + {t('desk.download')} + {/if} + {#if !active} + + {/if} +
+
+ +
+ {#if output} +
+ {#if isVideoOutput(job, output)} + + + {#if clipSec != null}{fmtDur(clipSec)}{/if} + {:else} + + {/if} + {#if job.output_paths.length > 1}×{job.output_paths.length}{/if} +
+ {:else if active} +
{st.label}
+ {:else} +
{t('desk.notGenerated')}
+ {/if} +
+
+ + diff --git a/calliope-web/src/lib/components/generate/TakeFeed.svelte b/calliope-web/src/lib/components/generate/TakeFeed.svelte new file mode 100644 index 00000000..10382850 --- /dev/null +++ b/calliope-web/src/lib/components/generate/TakeFeed.svelte @@ -0,0 +1,199 @@ + + +
+
+ {#each FILTERS as f (f.id)} + + {/each} +
+ + {t('desk.countTakes', { n: shown.length })}{#if activeCount} · {t('desk.countActive', { n: activeCount })}{/if} + + {@render inspectorToggle?.()} +
+{@render banner?.()} + +
+ {#if loading && !jobs.length} +

{t('common.loading')}

+ {:else if !shown.length} +
+ +

{filter === 'failed' ? t('desk.emptyFailed') : t('desk.emptyFeed')}

+
+ {:else} + {#each days as day (day.label)} +
{day.label}
+ {#each day.items as job (job.id)} + onSelect(job)} + onReuse={() => onReuse(job)} + onRetry={() => onRetry(job)} + onCancel={() => onCancel(job)} + onDelete={() => onDelete(job)} + /> + {/each} + {/each} + {/if} +
+ + diff --git a/calliope-web/src/lib/components/generate/WorkflowPicker.svelte b/calliope-web/src/lib/components/generate/WorkflowPicker.svelte new file mode 100644 index 00000000..451cca7c --- /dev/null +++ b/calliope-web/src/lib/components/generate/WorkflowPicker.svelte @@ -0,0 +1,223 @@ + + +
+ + (query = '')}> + +
+ {#each groups as g (g.usage)} +
{usageLabel(g.usage)} · {g.items.length}
+ {#each g.items as r (r.wf.id)} + {@const cur = r.wf.id === current?.id} + + {/each} + {:else} +

{t('desk.wfNoMatch')}

+ {/each} +
+
+ + + {t('desk.wfImport')} + + + ↑↓{t('desk.keySelect')} + Enter{t('desk.keyUse')} + Esc{t('desk.keyClose')} + +
+
+
+ + diff --git a/calliope-web/src/lib/components/generate/context.ts b/calliope-web/src/lib/components/generate/context.ts new file mode 100644 index 00000000..fcc6e528 --- /dev/null +++ b/calliope-web/src/lib/components/generate/context.ts @@ -0,0 +1,55 @@ +import type { WorkbenchStageKey } from '$lib/api'; +import type { DeskKind } from './schema'; + +/** + * 五段创作 → 生成台 handoff, carried in the URL so a reload keeps it. + * The desk only prefills from it; the playground generate API has no + * project/shot link, so results stay in the desk feed (no backfill). + */ +export interface DeskContext { + kind: DeskKind; + projectId: number; + stage: WorkbenchStageKey; + /** Human label of the source row, e.g. 镜头 S1 / 角色「林夏」. */ + label: string; + prompt?: string; + negative?: string; + durationSec?: number; +} + +const STAGES: WorkbenchStageKey[] = ['script', 'style', 'storyboard', 'assets', 'shot']; + +export function deskHref(ctx: DeskContext): string { + const q = new URLSearchParams({ + from: 'workbench', + project: String(ctx.projectId), + stage: ctx.stage, + label: ctx.label, + }); + if (ctx.prompt) q.set('prompt', ctx.prompt); + if (ctx.negative) q.set('negative', ctx.negative); + if (ctx.durationSec != null) q.set('duration', String(ctx.durationSec)); + return `/${ctx.kind}?${q.toString()}`; +} + +export function readDeskContext(url: URL, kind: DeskKind): DeskContext | null { + const q = url.searchParams; + if (q.get('from') !== 'workbench') return null; + const projectId = Number(q.get('project')); + const stage = q.get('stage') as WorkbenchStageKey | null; + if (!Number.isInteger(projectId) || projectId <= 0 || !stage || !STAGES.includes(stage)) return null; + const duration = Number(q.get('duration')); + return { + kind, + projectId, + stage, + label: q.get('label') ?? '', + prompt: q.get('prompt') ?? undefined, + negative: q.get('negative') ?? undefined, + durationSec: Number.isFinite(duration) && duration > 0 ? duration : undefined, + }; +} + +export function backHref(ctx: DeskContext): string { + return `/workbench/${ctx.projectId}?stage=${ctx.stage}`; +} diff --git a/calliope-web/src/lib/components/generate/schema.ts b/calliope-web/src/lib/components/generate/schema.ts new file mode 100644 index 00000000..e481c810 --- /dev/null +++ b/calliope-web/src/lib/components/generate/schema.ts @@ -0,0 +1,372 @@ +import type { ComfyDynamicInput, Workflow, WorkflowUsage } from '$lib/comfy/types'; +import { normalizeInputRole } from '$lib/comfy/parser'; +import { ratioShort, resolutionSelectorSize } from '$lib/comfy/resolution'; +import { t } from '$lib/i18n.svelte'; + +/** + * 生成台表单识别 (HEL-653, moved verbatim from StudioGenerate): slots and + * structured params come from what the workflow JSON actually declares — + * never from model names. No wiring → no slot. + */ + +export type DeskKind = 'image' | 'video'; +export type FormValue = string | number | string[]; +export type FormValues = Record; + +export interface SlotDef { + inp: ComfyDynamicInput; + label: string; + mediaKind: 'image' | 'video' | 'audio'; + fromResults: boolean; + /** Required-slot message when left empty (ref-upload-spec §3). */ + missing: string; + firstFrame: boolean; + lastFrame: boolean; + mask: boolean; +} + +/** Why 生成 is disabled — the line next to the button (spec-v2 §1.2). */ +export interface BlockReason { + text: string; + tone: 'warn' | 'err'; + /** Element id to focus when the reason is clicked. */ + target?: string; + /** Open the params tab instead of focusing. */ + params?: boolean; +} + +export interface DeskSchema { + prompt: ComfyDynamicInput | null; + negative: ComfyDynamicInput | null; + seed: ComfyDynamicInput | null; + width: ComfyDynamicInput | null; + height: ComfyDynamicInput | null; + resolution: ComfyDynamicInput | null; + duration: ComfyDynamicInput | null; + batch: ComfyDynamicInput | null; + /** ComfyUI ResolutionSelector: the ratio + megapixels pair decides width/height. */ + ratio: ComfyDynamicInput | null; + megapixels: ComfyDynamicInput | null; + /** Single media inputs (input image, first/last frame, mask, ref video/audio). */ + slots: SlotDef[]; + /** Autogrow media lists actually wired (image / video / audio). */ + lists: ComfyDynamicInput[]; + /** Parameters shown as composer chips (比例 / 尺寸 / 分辨率 / 时长 / 种子). */ + common: ComfyDynamicInput[]; + /** Everything else that is not media and not the prompt — folded. */ + advanced: ComfyDynamicInput[]; + hasH3Hint: boolean; +} + +export function inputRole(inp: ComfyDynamicInput): string | null { + return normalizeInputRole(inp.role ?? null); +} + +function hay(inp: ComfyDynamicInput): string { + return `${inp.role ?? ''} ${inp.label}`.toLowerCase(); +} + +export function isMedia(inp: ComfyDynamicInput): boolean { + return ( + inp.kind === 'image' || + inp.kind === 'image_url' || + inp.kind === 'video' || + inp.kind === 'audio' || + inp.kind === 'image_list' || + inp.kind === 'video_list' || + inp.kind === 'audio_list' + ); +} + +function isList(inp: ComfyDynamicInput): boolean { + return inp.kind === 'image_list' || inp.kind === 'video_list' || inp.kind === 'audio_list'; +} + +function isMask(inp: ComfyDynamicInput): boolean { + return inputRole(inp) === 'mask' || /mask|遮罩/.test(hay(inp)); +} + +// Auto-detected slots carry their role from the wiring; tagged (Input:…) +// workflows still name frames only in the title. +export function isFirstFrame(inp: ComfyDynamicInput, kind: DeskKind): boolean { + return inputRole(inp) === 'first_frame' || (!inp.auto && kind === 'video' && /first|start|首帧/.test(hay(inp))); +} +export function isLastFrame(inp: ComfyDynamicInput, kind: DeskKind): boolean { + return inputRole(inp) === 'last_frame' || (!inp.auto && kind === 'video' && /last|end|尾帧/.test(hay(inp))); +} + +export function listKind(entry: ComfyDynamicInput): 'image' | 'video' | 'audio' { + if (entry.kind === 'video_list') return 'video'; + if (entry.kind === 'audio_list') return 'audio'; + return 'image'; +} + +export function listPaths(values: FormValues, entry: ComfyDynamicInput): string[] { + const v = values[entry.nodeId]; + if (Array.isArray(v)) return v; + return typeof v === 'string' && v ? [v] : []; +} + +export function classifySchema(schema: ComfyDynamicInput[], kind: DeskKind): DeskSchema { + const plain = (pred: (i: ComfyDynamicInput) => boolean) => + schema.find((i) => !isMedia(i) && pred(i)) ?? null; + const byRole = (r: string) => plain((i) => inputRole(i) === r); + + const prompt = byRole('prompt'); + const negative = byRole('negative'); + const seed = byRole('seed'); + const width = byRole('width'); + const height = byRole('height'); + const resolution = byRole('resolution'); + const duration = byRole('duration'); + const batch = plain((i) => /批次|batch/.test(hay(i))); + const ratio = + schema.find((i) => i.kind === 'select' && inputRole(i) === 'aspect_ratio' && i.resolution) ?? null; + const megapixels = ratio ? (schema.find((i) => i.nodeId === ratio.resolution!.megapixels) ?? null) : null; + + const media = schema.filter((i) => isMedia(i) && !isList(i)); + const plainImages = media.filter( + (i) => i.kind === 'image' && !isMask(i) && !isFirstFrame(i, kind) && !isLastFrame(i, kind), + ); + const editInput = kind === 'image' && plainImages.length === 1 ? plainImages[0] : null; + const slots: SlotDef[] = []; + let refIdx = 0; + for (const inp of media) { + const base = { inp, missing: '', firstFrame: false, lastFrame: false, mask: false }; + if (inp.kind === 'video') { + slots.push({ ...base, label: t('studio.slotRefVideo'), mediaKind: 'video', fromResults: false }); + } else if (inp.kind === 'audio') { + slots.push({ ...base, label: t('studio.slotAudio'), mediaKind: 'audio', fromResults: false }); + } else if (isMask(inp)) { + slots.push({ ...base, mask: true, label: t('studio.slotMask'), mediaKind: 'image', fromResults: false }); + } else if (isFirstFrame(inp, kind)) { + slots.push({ + ...base, + firstFrame: true, + label: t('studio.slotFirst'), + mediaKind: 'image', + fromResults: true, + missing: t('studio.errNeedFirstFrame'), + }); + } else if (isLastFrame(inp, kind)) { + slots.push({ ...base, lastFrame: true, label: t('studio.slotLast'), mediaKind: 'image', fromResults: true }); + } else if (inp === editInput) { + slots.push({ + ...base, + label: t('studio.slotInput'), + mediaKind: 'image', + fromResults: true, + missing: t('studio.errNeedInputImage'), + }); + } else { + refIdx += 1; + const label = inp.auto + ? inp.label + : refIdx === 1 && media.length === 1 + ? t('studio.slotRef') + : t('studio.slotRefN', { n: refIdx }); + slots.push({ + ...base, + label, + mediaKind: 'image', + fromResults: true, + missing: t('studio.errUpload', { label }), + }); + } + } + + const lists = schema.filter(isList); + const common = [ratio, width, height, resolution, duration, seed].filter( + (i): i is ComfyDynamicInput => !!i, + ); + const commonIds = new Set(common.map((i) => i.nodeId)); + const advanced = schema.filter((i) => !isMedia(i) && i !== prompt && !commonIds.has(i.nodeId)); + + return { + prompt, + negative, + seed, + width, + height, + resolution, + duration, + batch, + ratio, + megapixels, + slots, + lists, + common, + advanced, + hasH3Hint: lists.some((e) => e.media_hint === 'minimax_h3_ref2va'), + }; +} + +/** Workflow JSON defaults — the 原值 every parameter falls back to. */ +export function schemaDefaults(schema: ComfyDynamicInput[]): FormValues { + const out: FormValues = {}; + for (const inp of schema) { + if (inp.defaultValue !== undefined && inp.defaultValue !== '') out[inp.nodeId] = inp.defaultValue; + } + return out; +} + +export function isChanged(inp: ComfyDynamicInput, values: FormValues): boolean { + const v = values[inp.nodeId]; + const orig = inp.defaultValue; + if (v === undefined || v === '') return orig !== undefined && orig !== ''; + if (orig === undefined || orig === '') return true; + return String(v) !== String(orig); +} + +export function changedParams(ds: DeskSchema, values: FormValues): ComfyDynamicInput[] { + return [...ds.common, ...ds.advanced].filter((i) => isChanged(i, values)); +} + +export function outputSize(ds: DeskSchema, values: FormValues): { width: number; height: number } | null { + if (!ds.ratio?.resolution) return null; + const mp = Number(values[ds.megapixels?.nodeId ?? ''] ?? ds.megapixels?.defaultValue); + return resolutionSelectorSize( + String(values[ds.ratio.nodeId] ?? ds.ratio.defaultValue ?? ''), + mp, + ds.ratio.resolution.multiple, + ); +} + +export function batchCount(ds: DeskSchema, values: FormValues): number { + if (!ds.batch) return 1; + const n = Number(values[ds.batch.nodeId]); + return Number.isFinite(n) && n > 0 ? Math.floor(n) : 1; +} + +/** H3 Ref2VA official limits (soft hint, keyed off the node class only). */ +export function h3Warnings(ds: DeskSchema, values: FormValues): string[] { + if (!ds.hasH3Hint) return []; + const warns: string[] = []; + const counts = { image: 0, video: 0, audio: 0 }; + for (const g of ds.lists) counts[listKind(g)] += listPaths(values, g).length; + const total = counts.image + counts.video + counts.audio; + if (total > 12) warns.push(t('wfMedia.h3TotalOver', { n: total })); + if (counts.audio > 0 && counts.image === 0 && counts.video === 0) warns.push(t('wfMedia.h3AudioAlone')); + return warns; +} + +/** Same rules the backend enforces before queueing (comfyui/validate.py). */ +export function valueError(inp: ComfyDynamicInput, raw: string | number): string | null { + const label = inp.label; + if (inp.kind === 'select') { + return inp.options?.length && !inp.options.includes(String(raw)) ? t('studio.errOption', { label }) : null; + } + if (inp.kind !== 'number') return null; + const n = Number(raw); + if (!Number.isFinite(n)) return t('studio.errNumber', { label }); + if (inp.integer && !Number.isInteger(n)) return t('studio.errInteger', { label }); + if (inp.min != null && n < inp.min) return t('studio.errMin', { label, v: inp.min }); + if (inp.max != null && n > inp.max) return t('studio.errMax', { label, v: inp.max }); + return null; +} + +/** Field errors keyed by nodeId (spec §6.2 wording); '' keys never block. */ +export function validateForm( + schema: ComfyDynamicInput[], + ds: DeskSchema, + values: FormValues, +): Record { + const errs: Record = {}; + if (ds.prompt?.required) { + const v = String(values[ds.prompt.nodeId] ?? ''); + if (!v.trim()) errs[ds.prompt.nodeId] = t('studio.errPrompt'); + else if (v.length > 2000) errs[ds.prompt.nodeId] = t('studio.errPromptLong'); + } + const first = ds.slots.find((s) => s.firstFrame); + const last = ds.slots.find((s) => s.lastFrame); + if (first && last) { + const a = String(values[first.inp.nodeId] ?? ''); + const b = String(values[last.inp.nodeId] ?? ''); + if ((!a || !b) && (a || b)) { + errs.firstLast = t('studio.errFirstLast'); + if (!a) errs[first.inp.nodeId] = ' '; + if (!b) errs[last.inp.nodeId] = ' '; + } + } + for (const s of ds.slots) { + if (!s.inp.required) continue; + if (!String(values[s.inp.nodeId] ?? '').trim()) { + errs[s.inp.nodeId] = s.missing || t('studio.errUpload', { label: s.label }); + } + } + for (const g of ds.lists) { + const n = listPaths(values, g).length; + const max = g.max ?? 9; + if (n < (g.min ?? 1)) { + errs[g.nodeId] = + g.kind === 'image_list' + ? t('studio.errNeedRef') + : t('studio.errNeedRefMedia', { n: g.min ?? 1, label: g.label }); + } else if (n > max) { + errs[g.nodeId] = t('studio.errRefMax', { max, n, k: n - max }); + } + } + for (const inp of [...ds.common, ...ds.advanced]) { + if (inp.required && !String(values[inp.nodeId] ?? '').trim()) { + errs[inp.nodeId] = t('studio.errFill', { label: inp.label }); + } + } + for (const inp of schema) { + const raw = values[inp.nodeId]; + if (raw === undefined || Array.isArray(raw) || String(raw).trim() === '' || errs[inp.nodeId]) continue; + const msg = valueError(inp, raw); + if (msg) errs[inp.nodeId] = msg; + } + return errs; +} + +/** Media a slot still waits for — the 「还缺:…」 hint next to 生成. */ +export function missingMedia(ds: DeskSchema, values: FormValues): Array<{ nodeId: string; label: string }> { + const out: Array<{ nodeId: string; label: string }> = []; + for (const s of ds.slots) { + if (s.inp.required && !String(values[s.inp.nodeId] ?? '').trim()) out.push({ nodeId: s.inp.nodeId, label: s.label }); + } + for (const g of ds.lists) { + if (listPaths(values, g).length < (g.min ?? 1)) out.push({ nodeId: g.nodeId, label: g.label }); + } + return out; +} + +export function usageLabel(u: WorkflowUsage): string { + return t(`usage.${u}`); +} + +/** Mode badge: the stored usage when we have one, else the wiring shape. */ +export function modeLabel(wf: Workflow | null, ds: DeskSchema, kind: DeskKind): string { + if (wf?.usage) return usageLabel(wf.usage); + if (ds.lists.some((g) => g.kind === 'image_list')) return t('studio.modeRefToVideo'); + if (ds.slots.some((s) => s.firstFrame)) return t('studio.modeImageToVideo'); + if (kind === 'image' && ds.slots.some((s) => s.mediaKind === 'image' && !s.mask)) + return t('studio.modeImageEdit'); + if (ds.slots.length) return ds.slots.map((s) => s.label).join(' · '); + return kind === 'image' ? t('studio.modeTextToImage') : t('studio.modeTextToVideo'); +} + +/** Picker row summary of a workflow's real media inputs, e.g. 参考图 1–9 张. */ +export function slotSummary(wf: Workflow): string { + const ds = classifySchema(wf.input_schema ?? [], wf.kind); + const parts = [ + ...ds.slots.map((s) => t('desk.slotOne', { label: s.label })), + ...ds.lists.map((g) => t('desk.slotRange', { label: g.label, min: g.min ?? 1, max: g.max ?? 9 })), + ]; + return parts.length ? parts.join(' · ') : t('desk.promptOnly'); +} + +/** Short chip text for one common parameter value. */ +export function chipValue(inp: ComfyDynamicInput, values: FormValues, ds: DeskSchema): string { + const raw = values[inp.nodeId] ?? inp.defaultValue ?? ''; + const v = Array.isArray(raw) ? raw.join(',') : String(raw); + if (inp === ds.ratio) { + const size = outputSize(ds, values); + return size ? `${ratioShort(v)} · ${size.width}×${size.height}` : ratioShort(v); + } + if (inp === ds.duration) return v ? t('desk.chipSeconds', { v }) : t('studio.durationLabel'); + if (inp === ds.seed) return t('desk.chipSeed', { v: v.length > 8 ? `${v.slice(0, 8)}…` : v || '—' }); + if (inp === ds.resolution) return t('desk.chipResolution', { v: v || '—' }); + return v || inp.label; +} diff --git a/calliope-web/src/lib/components/generate/takes.ts b/calliope-web/src/lib/components/generate/takes.ts new file mode 100644 index 00000000..57ca30ef --- /dev/null +++ b/calliope-web/src/lib/components/generate/takes.ts @@ -0,0 +1,129 @@ +import type { Job, Workflow } from '$lib/comfy/types'; +import { parseDbTs } from '$lib/dbtime'; +import { jobStatusInfo } from '$lib/jobStatus'; +import { resolutionSelectorSize } from '$lib/comfy/resolution'; +import { t } from '$lib/i18n.svelte'; +import { classifySchema, inputRole, isFirstFrame, isLastFrame, isMedia } from './schema'; + +/** Read-only views of a finished / running take (one playground job). */ + +export type FeedFilter = 'all' | 'image' | 'video' | 'failed'; + +export function jobValues(job: Job): Record { + return (job.payload?.input_values ?? {}) as Record; +} + +export function jobValueByRole(job: Job, wf: Workflow | undefined, ...roles: string[]): string | null { + if (!wf) return null; + const vals = jobValues(job); + for (const inp of wf.input_schema ?? []) { + const r = inputRole(inp); + if (r && roles.includes(r)) { + const v = vals[inp.nodeId]; + if (v !== undefined && v !== null && String(v).trim() !== '') return String(v); + } + } + return null; +} + +export function promptOf(job: Job, wf: Workflow | undefined): string { + return jobValueByRole(job, wf, 'prompt') ?? ''; +} + +export interface TakeInput { + label: string; + path: string; + kind: 'image' | 'video' | 'audio'; +} + +/** Media the take was generated from, in workflow order. */ +export function inputsOf(job: Job, wf: Workflow | undefined): TakeInput[] { + if (!wf) return []; + const kind = wf.kind; + const vals = jobValues(job); + const out: TakeInput[] = []; + let refIdx = 0; + for (const inp of wf.input_schema ?? []) { + if (!isMedia(inp)) continue; + const v = vals[inp.nodeId]; + const list = Array.isArray(v) ? v : typeof v === 'string' && v ? [v] : []; + const mk = inp.kind.startsWith('video') ? 'video' : inp.kind.startsWith('audio') ? 'audio' : 'image'; + list.forEach((p, i) => { + if (typeof p !== 'string' || !p) return; + let label = inp.label; + if (inp.kind === 'image_list') label = t('studio.slotRefN', { n: i + 1 }); + else if (isFirstFrame(inp, kind)) label = t('studio.slotFirst'); + else if (isLastFrame(inp, kind)) label = t('studio.slotLast'); + else if (inp.kind === 'image' && inputRole(inp) !== 'mask') label = t('studio.slotRefN', { n: ++refIdx }); + out.push({ label, path: p, kind: mk }); + }); + } + return out; +} + +/** 888×1184 · 种子 42 · 5 秒 — values that differ per take. */ +export function specOf(job: Job, wf: Workflow | undefined): Array<{ label: string; value: string }> { + const out: Array<{ label: string; value: string }> = []; + if (!wf) return out; + const w = jobValueByRole(job, wf, 'width'); + const h = jobValueByRole(job, wf, 'height'); + if (w && h) out.push({ label: t('desk.specSize'), value: `${w}×${h}` }); + else { + const ds = classifySchema(wf.input_schema ?? [], wf.kind); + if (ds.ratio?.resolution) { + const vals = jobValues(job); + const size = resolutionSelectorSize( + String(vals[ds.ratio.nodeId] ?? ds.ratio.defaultValue ?? ''), + Number(vals[ds.ratio.resolution.megapixels] ?? ds.megapixels?.defaultValue), + ds.ratio.resolution.multiple, + ); + if (size) out.push({ label: t('desk.specSize'), value: `${size.width}×${size.height}` }); + } + } + const seed = jobValueByRole(job, wf, 'seed'); + if (seed) out.push({ label: t('studio.seedLabel'), value: seed }); + const dur = jobValueByRole(job, wf, 'duration'); + if (dur) out.push({ label: t('studio.durationLabel'), value: t('desk.chipSeconds', { v: dur }) }); + return out; +} + +export function isVideoOutput(job: Job, path: string): boolean { + return job.kind === 'video' && !/\.(png|jpe?g|webp)$/i.test(path); +} + +export function elapsedSec(job: Job, nowMs: number): number | null { + const from = job.started_at ? parseDbTs(job.started_at) : parseDbTs(job.created_at); + if (!Number.isFinite(from)) return null; + const to = job.completed_at ? parseDbTs(job.completed_at) : nowMs; + return Math.max(0, (to - from) / 1000); +} + +export function fmtDur(sec: number | null): string { + if (sec == null) return '—'; + if (sec < 60) return t('desk.durSec', { s: Math.floor(sec) }); + const m = Math.floor(sec / 60); + const s = Math.floor(sec % 60); + return t('desk.durMin', { m, s: String(s).padStart(2, '0') }); +} + +export function fmtClock(ms: number): string { + const d = new Date(ms); + return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`; +} + +/** 今天 / 昨天 / 9月28日 heading for the feed. */ +export function dayLabel(ms: number, nowMs: number): string { + const d = new Date(ms); + const today = new Date(nowMs); + const startOf = (x: Date) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime(); + const diff = Math.round((startOf(today) - startOf(d)) / 86_400_000); + if (diff === 0) return t('desk.today'); + if (diff === 1) return t('desk.yesterday'); + return t('desk.dayDate', { m: d.getMonth() + 1, d: d.getDate() }); +} + +export function matchesFilter(job: Job, filter: FeedFilter): boolean { + if (filter === 'all') return true; + if (filter === 'failed') return jobStatusInfo(job).tone === 'fail'; + return job.kind === filter; +} diff --git a/calliope-web/src/lib/components/shell/ShellPop.svelte b/calliope-web/src/lib/components/shell/ShellPop.svelte index e016148e..d9f3e362 100644 --- a/calliope-web/src/lib/components/shell/ShellPop.svelte +++ b/calliope-web/src/lib/components/shell/ShellPop.svelte @@ -12,6 +12,8 @@ open?: boolean; label: string; align?: 'start' | 'end'; + /** `top` opens above the trigger (triggers near the bottom edge, e.g. the composer). */ + placement?: 'bottom' | 'top'; width?: string; onclose?: () => void; children: Snippet; @@ -21,6 +23,7 @@ open = $bindable(false), label, align = 'start', + placement = 'bottom', width = '300px', onclose, children, @@ -126,7 +129,7 @@