merge: HEL-643 import preflight, real test runs and media groups

This commit is contained in:
总工
2026-09-29 19:12:18 +08:00
32 changed files with 3220 additions and 198 deletions
@@ -7,7 +7,7 @@
import ImageLightbox from '$lib/components/ImageLightbox.svelte';
import MediaSlot from '$lib/components/studio/MediaSlot.svelte';
import RefImageGrid from '$lib/components/studio/RefImageGrid.svelte';
import { imageFileProblem } from '$lib/comfy/imageFile';
import { mediaFileProblem } from '$lib/comfy/imageFile';
import { toStore } from 'svelte/store';
import { tick } from 'svelte';
import AppShell from '$lib/components/shell/AppShell.svelte';
@@ -145,6 +145,7 @@
let fileSizes = $state<Record<string, number>>({});
/** Reference index being replaced while its upload runs. */
let replacingIndex = $state(-1);
let replacingKey = $state('');
let showErrors = $state(false);
let submitting = $state(false);
let lightboxOpen = $state(false);
@@ -212,7 +213,9 @@
inp.kind === 'image_url' ||
inp.kind === 'video' ||
inp.kind === 'audio' ||
inp.kind === 'image_list';
inp.kind === 'image_list' ||
inp.kind === 'video_list' ||
inp.kind === 'audio_list';
// Auto-detected slots carry their role from the wiring; tagged (Input:…)
// workflows still name frames only in the title.
const isFirstFrame = (inp: ComfyDynamicInput) =>
@@ -220,14 +223,44 @@
const isLastFrame = (inp: ComfyDynamicInput) =>
role(inp) === 'last_frame' || (!inp.auto && kind === 'video' && /last|end|尾帧/.test(hay(inp)));
/** Autogrow media lists actually wired in this workflow (HEL-643: image /
* video / audio). No wiring → no entry, whatever the model could do. */
const listGroups = $derived(
schema.filter(
(i) => i.kind === 'image_list' || i.kind === 'video_list' || i.kind === 'audio_list',
),
);
function listKind(entry: ComfyDynamicInput): 'image' | 'video' | 'audio' {
if (entry.kind === 'video_list') return 'video';
if (entry.kind === 'audio_list') return 'audio';
return 'image';
}
// ComfyUI Autogrow reference images (H3 ref_images): one ordered 1…max list.
const refGroup = $derived(schema.find((i) => i.kind === 'image_list') ?? null);
const refGroup = $derived(listGroups.find((i) => i.kind === 'image_list') ?? null);
const refMax = $derived(refGroup?.max ?? 9);
const refPaths = $derived.by(() => {
const v = refGroup ? values[refGroup.nodeId] : undefined;
if (Array.isArray(v)) return v;
return typeof v === 'string' && v ? [v] : [];
});
function groupPaths(entry: ComfyDynamicInput): string[] {
const v = values[entry.nodeId];
if (Array.isArray(v)) return v;
return typeof v === 'string' && v ? [v] : [];
}
// H3 Ref2VA official limits (soft hint, keyed off the node class only).
const hasH3Hint = $derived(listGroups.some((e) => e.media_hint === 'minimax_h3_ref2va'));
const h3SoftWarnings = $derived.by(() => {
if (!hasH3Hint) return [];
const warns: string[] = [];
const counts = { image: 0, video: 0, audio: 0 };
for (const g of listGroups) counts[listKind(g)] += groupPaths(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;
});
const brokenReasons = $derived(
(currentWorkflow?.warnings ?? []).filter((w) => w.level === 'error').map((w) => w.message),
);
@@ -271,7 +304,10 @@
}
const mediaSlots = $derived.by(() => {
const media = schema.filter((i) => isMedia(i) && i.kind !== 'image_list');
const media = schema.filter(
(i) =>
isMedia(i) && i.kind !== 'image_list' && i.kind !== 'video_list' && i.kind !== 'audio_list',
);
const plainImages = media.filter(
(i) => i.kind === 'image' && role(i) !== 'mask' && !/mask|遮罩/.test(hay(i)) && !isFirstFrame(i) && !isLastFrame(i),
);
@@ -424,10 +460,17 @@
errs[s.inp.nodeId] = s.missing || t('studio.errUpload', { label: s.label });
}
}
if (refGroup) {
if (refPaths.length < (refGroup.min ?? 1)) errs[refGroup.nodeId] = t('studio.errNeedRef');
else if (refPaths.length > refMax)
errs[refGroup.nodeId] = t('studio.errRefMax', { max: refMax, n: refPaths.length, k: refPaths.length - refMax });
for (const g of listGroups) {
const n = groupPaths(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 restInputs) {
if (inp.required && !String(values[inp.nodeId] ?? '').trim()) {
@@ -486,12 +529,10 @@
}
async function slotFile(nodeId: string, file: File, mediaKind: 'image' | 'video' | 'audio' = 'image') {
if (mediaKind === 'image') {
const problem = imageFileProblem(file);
if (problem) {
setRejects(nodeId, [{ name: file.name, message: problem }]);
return;
}
const problem = mediaFileProblem(mediaKind, file);
if (problem) {
setRejects(nodeId, [{ name: file.name, message: problem }]);
return;
}
setRejects(nodeId, []);
const path = await uploadImage(nodeId, file);
@@ -499,46 +540,48 @@
}
/** Add picked/dropped files in order; a batch that would pass `max` is refused whole. */
async function refAdd(files: File[]) {
if (!refGroup) return;
const key = refGroup.nodeId;
const ok = files.filter((f) => !imageFileProblem(f));
async function groupAdd(entry: ComfyDynamicInput, files: File[]) {
const key = entry.nodeId;
const mk = listKind(entry);
const max = entry.max ?? 9;
const paths = groupPaths(entry);
const ok = files.filter((f) => !mediaFileProblem(mk, f));
const rejected = files
.filter((f) => imageFileProblem(f))
.map((f) => ({ name: f.name, message: imageFileProblem(f)! }));
.filter((f) => mediaFileProblem(mk, f))
.map((f) => ({ name: f.name, message: mediaFileProblem(mk, f)! }));
setRejects(key, rejected);
if (refPaths.length + ok.length > refMax) {
toast.error(t('studio.errRefMax', { max: refMax, n: refPaths.length, k: ok.length }));
if (paths.length + ok.length > max) {
toast.error(t('studio.errRefMax', { max, n: paths.length, k: ok.length }));
return;
}
for (const f of ok) {
const path = await uploadImage(key, f);
if (!path) break;
setVal(key, [...refPaths, path]);
setVal(key, [...paths, path]);
}
}
async function refReplace(index: number, file: File) {
if (!refGroup) return;
const key = refGroup.nodeId;
const problem = imageFileProblem(file);
async function groupReplace(entry: ComfyDynamicInput, index: number, file: File) {
const key = entry.nodeId;
const problem = mediaFileProblem(listKind(entry), file);
if (problem) {
setRejects(key, [{ name: file.name, message: problem }]);
return;
}
setRejects(key, []);
replacingKey = key;
replacingIndex = index;
try {
const path = await uploadImage(key, file);
if (path) setVal(key, refPaths.map((p, i) => (i === index ? path : p)));
if (path) setVal(key, groupPaths(entry).map((p, i) => (i === index ? path : p)));
} finally {
replacingKey = '';
replacingIndex = -1;
}
}
function refRemove(index: number) {
if (!refGroup) return;
setVal(refGroup.nodeId, refPaths.filter((_, i) => i !== index));
function groupRemove(entry: ComfyDynamicInput, index: number) {
setVal(entry.nodeId, groupPaths(entry).filter((_, i) => i !== index));
}
const imageResults = $derived(
@@ -1134,25 +1177,36 @@
{/if}
{/if}
{#if refGroup}
<div class="f-field">
<RefImageGrid
label={refGroup.label}
paths={refPaths}
max={refMax}
sizes={fileSizes}
uploadingName={uploads.uploading[refGroup.nodeId]}
uploadingIndex={replacingIndex}
rejects={slotRejects[refGroup.nodeId] ?? []}
error={showErrors ? errors[refGroup.nodeId] : undefined}
allowFromResults
onAdd={refAdd}
onReplace={refReplace}
onRemove={refRemove}
onDismissReject={(i) =>
setRejects(refGroup.nodeId, (slotRejects[refGroup.nodeId] ?? []).filter((_, j) => j !== i))}
onFromResults={() => openPicker(refGroup.nodeId)}
/>
{#if listGroups.length}
<div class="f-field ref-groups">
{#each listGroups as entry (entry.nodeId)}
<RefImageGrid
label={entry.label}
mediaKind={listKind(entry)}
paths={groupPaths(entry)}
max={entry.max ?? 9}
sizes={fileSizes}
uploadingName={uploads.uploading[entry.nodeId]}
uploadingIndex={replacingKey === entry.nodeId ? replacingIndex : -1}
rejects={slotRejects[entry.nodeId] ?? []}
error={showErrors ? errors[entry.nodeId] : undefined}
allowFromResults={entry.kind === 'image_list'}
onAdd={(files) => groupAdd(entry, files)}
onReplace={(i, file) => groupReplace(entry, i, file)}
onRemove={(i) => groupRemove(entry, i)}
onDismissReject={(i) =>
setRejects(entry.nodeId, (slotRejects[entry.nodeId] ?? []).filter((_, j) => j !== i))}
onFromResults={entry.kind === 'image_list' ? () => openPicker(entry.nodeId) : undefined}
/>
{/each}
{#if hasH3Hint}
<div class="h3-hint" role="note">
<p>{t('wfMedia.h3Limits')}</p>
{#each h3SoftWarnings as w (w)}
<p class="warn">{w}</p>
{/each}
</div>
{/if}
</div>
{/if}
@@ -1825,6 +1879,26 @@
/>
<style>
.ref-groups {
display: flex;
flex-direction: column;
gap: 14px;
}
.h3-hint {
padding: 8px 10px;
border: 1px solid var(--border-strong);
border-radius: 8px;
background: var(--surface-2);
}
.h3-hint p {
margin: 0;
font-size: 11px;
line-height: 1.6;
color: var(--text-3);
}
.h3-hint p.warn {
color: var(--accent);
}
.studio-page {
display: grid;
grid-template-columns: 352px minmax(0, 1fr) 296px;