From 6c2c61c7fbf3267f8b2c52dfe790bcd23a0cff30 Mon Sep 17 00:00:00 2001 From: Lightning Pixel Date: Sat, 14 Nov 2026 19:32:52 +0100 Subject: [PATCH] fix(workflows): accept object-shaped manifest inputs in preflight A manifest may declare `inputs` as slot objects ({ type, label, required }) instead of type names. The preflight compared those objects against output type strings, so every connection looked missing and the error named the type "text" whatever it was. Slot objects are now reduced to their type when the manifest is parsed, with their labels and optional flags carried as inputLabels and inputsRequired. Preflight only requires types with at least one required slot, and names unknown types as declared. Fixes #241 --- .../main/extension-install-utils.test.mjs | 44 ++++++++++++++++ electron/main/extension-install-utils.ts | 51 ++++++++++++++++++- electron/main/ipc-handlers.ts | 11 ++-- src/areas/workflows/mockExtensions.ts | 3 ++ src/areas/workflows/preflight.test.mjs | 27 ++++++++++ src/areas/workflows/preflight.ts | 15 +++--- src/shared/types/electron.d.ts | 1 + 7 files changed, 139 insertions(+), 13 deletions(-) diff --git a/electron/main/extension-install-utils.test.mjs b/electron/main/extension-install-utils.test.mjs index fd0eb1a08..f8c94df65 100644 --- a/electron/main/extension-install-utils.test.mjs +++ b/electron/main/extension-install-utils.test.mjs @@ -529,3 +529,47 @@ test('parseGitHubRepoUrl rejects URLs that do not name a GitHub repository', () assert.throws(() => mod.parseGitHubRepoUrl('https://github.com/owner/.git'), /expected format/) }) + +test('normalizeNodeInputs reduces slot objects to type names and keeps labels and optionality (#241)', () => { + const mod = loadModule() + // The manifest shape from the report (modly-Codex-image-extension, image-to-image) + assert.deepEqual(mod.normalizeNodeInputs({ + id: 'image-to-image', + input: 'image', + inputs: [ + { name: 'front', label: 'Primary image', type: 'image', required: true }, + { name: 'left', label: 'Image 2', type: 'image', required: false }, + ], + }), { + inputs: ['image', 'image'], + inputLabels: ['Primary image', 'Image 2'], + inputsRequired: [true, false], + }) + + // Plain type names are unchanged, with no derived labels or optionality + assert.deepEqual( + mod.normalizeNodeInputs({ inputs: ['image', 'text'], input_labels: ['Image', 'Prompt'] }), + { inputs: ['image', 'text'], inputLabels: ['Image', 'Prompt'], inputsRequired: undefined }, + ) + // Explicit input_labels win; a slot without a label falls back to its name, then its type + assert.deepEqual( + mod.normalizeNodeInputs({ inputs: ['mesh', { type: 'image', name: 'ref' }] }).inputLabels, + ['mesh', 'ref'], + ) + assert.deepEqual(mod.normalizeNodeInputs({ input: 'image' }), { inputLabels: undefined }) +}) + +test('normalizeNodeInputs rejects slot entries without a type', () => { + const mod = loadModule() + assert.throws(() => mod.normalizeNodeInputs({ id: 'n', inputs: [{ label: 'x' }] }), /n inputs\[0\] must be a type name/) + assert.throws(() => mod.normalizeNodeInputs({ id: 'n', inputs: ['image', null] }), /inputs\[1\]/) +}) + +test('validateInstallManifest sees object-shaped scene slots as scene inputs', () => { + const mod = loadModule() + const files = { hasEntryFile: () => true, hasGeneratorFile: () => true } + assert.throws(() => mod.validateInstallManifest({ + id: 'proc', type: 'process', entry: 'processor.js', + nodes: [{ id: 'run', inputs: [{ type: 'scene' }] }], + }, files, 'repository'), /scene input and output are supported only for model nodes/) +}) diff --git a/electron/main/extension-install-utils.ts b/electron/main/extension-install-utils.ts index c8d9a6da8..7f6d06c5c 100644 --- a/electron/main/extension-install-utils.ts +++ b/electron/main/extension-install-utils.ts @@ -21,6 +21,7 @@ export interface InstallManifest { id?: string input?: unknown inputs?: unknown + input_labels?: unknown output?: unknown hf_repo?: unknown model_sources?: unknown @@ -43,6 +44,54 @@ export interface ExtensionReloadPayload { errors: Record } +export interface NormalizedNodeInputs { + /** One type name per input slot, or undefined for a single-input node. */ + inputs?: string[] + /** Display label per slot: explicit `input_labels`, else the objects' labels. */ + inputLabels?: string[] + /** Set only when at least one slot is optional; true means required. */ + inputsRequired?: boolean[] +} + +/** + * A manifest may declare `inputs` as type names (`["image", "text"]`) or as + * slot objects (`[{ "type": "image", "label": "Front", "required": false }]`). + * Everything downstream compares slots against type names, so objects are + * reduced to their type here and their label/required carried separately. + */ +export function normalizeNodeInputs(node: { id?: unknown; inputs?: unknown; input_labels?: unknown }): NormalizedNodeInputs { + const explicitLabels = Array.isArray(node.input_labels) ? node.input_labels as string[] : undefined + if (!Array.isArray(node.inputs)) return { inputLabels: explicitLabels } + + const inputs: string[] = [] + const labels: (string | undefined)[] = [] + const required: boolean[] = [] + node.inputs.forEach((entry: unknown, i: number) => { + if (typeof entry === 'string') { + inputs.push(entry) + labels.push(undefined) + required.push(true) + return + } + const slot = entry as { type?: unknown; label?: unknown; name?: unknown; required?: unknown } | null + if (!slot || typeof slot !== 'object' || typeof slot.type !== 'string') { + throw new Error(`manifest.json: ${String(node.id ?? 'node')} inputs[${i}] must be a type name or an object with a "type"`) + } + inputs.push(slot.type) + labels.push(typeof slot.label === 'string' ? slot.label : typeof slot.name === 'string' ? slot.name : undefined) + required.push(slot.required !== false) + }) + + const derivedLabels = labels.some((label) => label !== undefined) + ? labels.map((label, i) => label ?? inputs[i]) + : undefined + return { + inputs, + inputLabels: explicitLabels ?? derivedLabels, + inputsRequired: required.every(Boolean) ? undefined : required, + } +} + export function assertSupportedSceneNodeShape( kind: 'model' | 'process', node: { id?: string; input?: unknown; inputs?: unknown; output?: unknown }, @@ -100,7 +149,7 @@ export function validateInstallManifest( validateModelNodeIds(manifest.nodes ?? []) } for (const node of Array.isArray(manifest.nodes) ? manifest.nodes : []) { - const declaredInputs = Array.isArray(node.inputs) ? node.inputs : [node.input ?? 'image'] + const declaredInputs = normalizeNodeInputs(node).inputs ?? [node.input ?? 'image'] const output = node.output ?? 'mesh' assertSupportedSceneNodeShape(isProcess ? 'process' : 'model', node, declaredInputs, output) const usesSharedWeights = weightGroups !== undefined || node.weight_groups !== undefined diff --git a/electron/main/ipc-handlers.ts b/electron/main/ipc-handlers.ts index 0632620ff..13c8c7b28 100644 --- a/electron/main/ipc-handlers.ts +++ b/electron/main/ipc-handlers.ts @@ -74,6 +74,7 @@ import { validateExistingExtensionReplacement, validateInstallManifest, assertSupportedSceneNodeShape, + normalizeNodeInputs, } from './extension-install-utils' import { beginExtensionRegistrationTransaction, @@ -1225,7 +1226,7 @@ export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGe id: string name?: string input?: string - inputs?: string[] + inputs?: unknown[] // type names, or { type, label?, required? } slot objects input_labels?: string[] output?: string params_schema?: unknown[] @@ -1263,7 +1264,8 @@ export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGe validateModelNodeIds(parsed.nodes ?? []) } const nodes = (parsed.nodes ?? []).map(n => { - const declaredInputs = Array.isArray(n.inputs) ? n.inputs : [n.input ?? 'image'] + const slots = normalizeNodeInputs(n) + const declaredInputs = slots.inputs ?? [n.input ?? 'image'] const output = n.output ?? 'mesh' assertSupportedSceneNodeShape(parsed.type === 'process' ? 'process' : 'model', n, declaredInputs, output) const usesManagedWeights = weightGroups !== undefined @@ -1295,8 +1297,9 @@ export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGe id: nodeId, name: n.name ?? n.id, input: n.input ?? 'image' as const, - inputs: n.inputs, - inputLabels: n.input_labels, + inputs: slots.inputs, + inputLabels: slots.inputLabels, + inputsRequired: slots.inputsRequired, output: n.output ?? 'mesh' as const, paramsSchema: n.params_schema ?? parsed.params_schema ?? [], paramDefaults: { ...(parsed.param_defaults ?? {}), ...(n.param_defaults ?? {}) }, diff --git a/src/areas/workflows/mockExtensions.ts b/src/areas/workflows/mockExtensions.ts index 9bdb9a0a6..46de1c99b 100644 --- a/src/areas/workflows/mockExtensions.ts +++ b/src/areas/workflows/mockExtensions.ts @@ -13,6 +13,7 @@ export interface WorkflowExtension { input: 'image' | 'text' | 'mesh' | 'audio' | 'scene' inputs?: ('image' | 'text' | 'mesh' | 'audio' | 'scene')[] // multi-input; overrides input when set inputLabels?: string[] // display labels per input slot + inputsRequired?: boolean[] // per slot; absent means all required output: 'image' | 'text' | 'mesh' | 'audio' | 'scene' params: ParamSchema[] builtin: boolean @@ -52,6 +53,7 @@ export function buildAllWorkflowExtensions( input: node.input, inputs: node.inputs, inputLabels: node.inputLabels, + inputsRequired: node.inputsRequired, output: node.output, params: applyParamDefaults(node.paramsSchema as ParamSchema[], node.paramDefaults), builtin: ext.builtin, @@ -74,6 +76,7 @@ export function buildAllWorkflowExtensions( input: node.input, inputs: node.inputs, inputLabels: node.inputLabels, + inputsRequired: node.inputsRequired, output: node.output, params: applyParamDefaults(node.paramsSchema as ParamSchema[], node.paramDefaults), builtin: ext.builtin, diff --git a/src/areas/workflows/preflight.test.mjs b/src/areas/workflows/preflight.test.mjs index 3b4df8aa8..fd6d54445 100644 --- a/src/areas/workflows/preflight.test.mjs +++ b/src/areas/workflows/preflight.test.mjs @@ -132,6 +132,33 @@ test('multi-input extension requires every declared input type', () => { assert.ok(issues.some((i) => i.key === 'proc:missing:text')) }) +test('optional input slots are not required, but their type is still accepted (#241)', () => { + const { validateWorkflowPreflight } = loadModule() + const proc = { id: 'proc', type: 'extensionNode', position: { x: 0, y: 0 }, data: { extensionId: 'pack/process-node' } } + // image-to-image: required front image, optional second image + const imageToImage = ext({ inputs: ['image', 'image'], inputsRequired: [true, false] }) + assert.deepEqual( + validateWorkflowPreflight(wf([imageNode('img'), proc], [{ id: 'e1', source: 'img', target: 'proc', targetHandle: 'input-0' }]), [imageToImage]), + [], + ) + + // an optional text prompt next to a required image + const withPrompt = ext({ inputs: ['image', 'text'], inputsRequired: [true, false] }) + assert.deepEqual(validateWorkflowPreflight(wf([imageNode('img'), proc], [{ id: 'e1', source: 'img', target: 'proc' }]), [withPrompt]), []) + const both = validateWorkflowPreflight( + wf([imageNode('img'), textNode('txt'), proc], [{ id: 'e1', source: 'img', target: 'proc' }, { id: 'e2', source: 'txt', target: 'proc' }]), + [withPrompt], + ) + assert.deepEqual(both, []) +}) + +test('missing type names the real type instead of defaulting to text', () => { + const { validateWorkflowPreflight } = loadModule() + const proc = { id: 'proc', type: 'extensionNode', position: { x: 0, y: 0 }, data: { extensionId: 'pack/process-node' } } + const issues = validateWorkflowPreflight(wf([proc]), [ext({ input: 'pointcloud' })]) + assert.match(issues[0].message, /needs an incoming pointcloud connection/) +}) + test('scene input requires a validated Load Scene source and rejects image wiring', () => { const { validateWorkflowPreflight } = loadModule() const model = { id: 'model', type: 'extensionNode', position: { x: 0, y: 0 }, data: { extensionId: 'pack/process-node' } } diff --git a/src/areas/workflows/preflight.ts b/src/areas/workflows/preflight.ts index 068a9277b..695de05e2 100644 --- a/src/areas/workflows/preflight.ts +++ b/src/areas/workflows/preflight.ts @@ -30,11 +30,7 @@ function nodeLabel(node: WFNode, allExtensions: WorkflowExtension[]): string { } function formatType(type: DataType): string { - if (type === 'scene') return 'scene' - if (type === 'mesh') return 'mesh' - if (type === 'image') return 'image' - if (type === 'audio') return 'audio' - return 'text' + return String(type) } function formatRequiredTypes(types: DataType[]): string { @@ -142,7 +138,10 @@ export function validateWorkflowPreflight( } const incomingEdges = workflow.edges.filter((edge) => edge.target === node.id) - const requiredTypes = [...new Set((ext.inputs ?? [ext.input]) as DataType[])] + const slotTypes = (ext.inputs ?? [ext.input]) as DataType[] + const acceptedTypes = [...new Set(slotTypes)] + // A type is required when at least one slot of that type is not optional. + const requiredTypes = [...new Set(slotTypes.filter((_, i) => ext.inputsRequired?.[i] !== false))] for (const requiredType of requiredTypes) { const hasMatchingInput = incomingEdges.some((edge) => outputTypes.get(edge.source) === requiredType) @@ -158,11 +157,11 @@ export function validateWorkflowPreflight( for (const edge of incomingEdges) { const sourceNode = nodeMap.get(edge.source) const sourceType = outputTypes.get(edge.source) - if (!sourceNode || !sourceType || requiredTypes.includes(sourceType)) continue + if (!sourceNode || !sourceType || acceptedTypes.includes(sourceType)) continue pushIssue(issues, { key: `${node.id}:type:${edge.id}`, nodeId: node.id, - message: `${ext.name} expects ${formatRequiredTypes(requiredTypes)}, but ${nodeLabel(sourceNode, allExtensions)} outputs ${formatType(sourceType)}.`, + message: `${ext.name} expects ${formatRequiredTypes(acceptedTypes)}, but ${nodeLabel(sourceNode, allExtensions)} outputs ${formatType(sourceType)}.`, }) } } diff --git a/src/shared/types/electron.d.ts b/src/shared/types/electron.d.ts index 57ec8f3ad..653c09bd3 100644 --- a/src/shared/types/electron.d.ts +++ b/src/shared/types/electron.d.ts @@ -21,6 +21,7 @@ export interface ExtensionNode { input: 'image' | 'text' | 'mesh' | 'audio' | 'scene' inputs?: ('image' | 'text' | 'mesh' | 'audio' | 'scene')[] // multi-input nodes; overrides input when set inputLabels?: string[] // display labels per input slot (e.g. positive/negative) + inputsRequired?: boolean[] // per input slot; absent means every slot is required output: 'image' | 'text' | 'mesh' | 'audio' | 'scene' paramsSchema: ParamSchema[] paramDefaults?: Record