diff --git a/src/schemas/comfyWorkflowSchema.ts b/src/schemas/comfyWorkflowSchema.ts index 5006b7539..62c75d4f8 100644 --- a/src/schemas/comfyWorkflowSchema.ts +++ b/src/schemas/comfyWorkflowSchema.ts @@ -41,10 +41,10 @@ const zModelFile = z.object({ const zGraphState = z .object({ - lastGroupid: z.number().optional(), - lastNodeId: z.number().optional(), - lastLinkId: z.number().optional(), - lastRerouteId: z.number().optional() + lastGroupId: z.number(), + lastNodeId: z.number(), + lastLinkId: z.number(), + lastRerouteId: z.number() }) .passthrough() @@ -214,6 +214,15 @@ const zComfyNode = z }) .passthrough() +export const zSubgraphIO = zNodeInput.extend({ + /** Slot ID (internal; never changes once instantiated). */ + id: z.string().uuid(), + /** The data type this slot uses. Unlike nodes, this does not support legacy numeric types. */ + type: z.string(), + /** Links connected to this slot, or `undefined` if not connected. An ouptut slot should only ever have one link. */ + linkIds: z.array(z.number()).optional() +}) + const zSubgraphInstance = z .object({ id: zNodeId, @@ -223,8 +232,8 @@ const zSubgraphInstance = z flags: zFlags, order: z.number(), mode: z.number(), - inputs: z.array(zNodeInput).optional(), - outputs: z.array(zNodeOutput).optional(), + inputs: z.array(zSubgraphIO).optional(), + outputs: z.array(zSubgraphIO).optional(), widgets_values: zWidgetValues.optional(), color: z.string().optional(), bgcolor: z.string().optional() @@ -303,39 +312,41 @@ interface ComfyWorkflow1BaseType { revision?: number version: 1 models?: z.infer[] - definitions?: { - subgraphs: SubgraphInferredBaseType[] - } + state: z.infer } /** Required for recursive definition of subgraphs. */ interface ComfyWorkflow1BaseInput extends ComfyWorkflow1BaseType { - state: z.input groups?: z.input[] nodes: z.input[] links?: z.input[] floatingLinks?: z.input[] reroutes?: z.input[] + definitions?: { + subgraphs: SubgraphDefinitionBaseInput[] + } } /** Required for recursive definition of subgraphs. */ interface ComfyWorkflow1BaseOutput extends ComfyWorkflow1BaseType { - state: z.output groups?: z.output[] nodes: z.output[] links?: z.output[] floatingLinks?: z.output[] reroutes?: z.output[] + definitions?: { + subgraphs: SubgraphDefinitionBaseOutput[] + } } /** Required for recursive definition of subgraphs. */ -type ComfyWorkflow1DefinitionInput = z.input & +type SubgraphDefinitionInput = z.input & ComfyWorkflow1BaseInput & - SubgraphInferredBaseType + SubgraphDefinitionBaseInput /** Required for recursive definition of subgraphs. */ -type ComfyWorkflow1DefinitionOutput = z.output & +type SubgraphDefinitionOutput = z.output & ComfyWorkflow1BaseOutput & - SubgraphInferredBaseType + SubgraphDefinitionBaseOutput /** Schema version 1 */ export const zComfyWorkflow1 = zBaseExportableGraph @@ -356,9 +367,9 @@ export const zComfyWorkflow1 = zBaseExportableGraph subgraphs: z.lazy( (): z.ZodArray< z.ZodType< - ComfyWorkflow1DefinitionOutput, + SubgraphDefinitionOutput, z.ZodTypeDef, - ComfyWorkflow1DefinitionInput + SubgraphDefinitionInput >, 'many' > => z.array(zSubgraphDefinition) @@ -367,15 +378,6 @@ export const zComfyWorkflow1 = zBaseExportableGraph }) .passthrough() -export const zSubgraphIO = z.object({ - /** Slot ID (internal; never changes once instantiated). */ - id: z.string().uuid(), - /** The data type this slot uses. Unlike nodes, this does not support legacy numeric types. */ - type: z.string(), - /** Links connected to this slot, or `undefined` if not connected. An ouptut slot should only ever have one link. */ - linkIds: z.array(z.number()).nullable().optional() -}) - export const zExportedSubgraphIONode = z.object({ id: zNodeId, bounding: z.tuple([z.number(), z.number(), z.number(), z.number()]), @@ -387,29 +389,43 @@ export const zExposedWidget = z.object({ name: z.string() }) -interface SubgraphInferredBaseType { +interface SubgraphDefinitionBaseInput extends ComfyWorkflow1BaseInput { /** Unique graph ID. Automatically generated if not provided. */ id: string revision: number - inputNode: z.infer - outputNode: z.infer + name: string + + inputNode: z.input + outputNode: z.input /** Ordered list of inputs to the subgraph itself. Similar to a reroute, with the input side in the graph, and the output side in the subgraph. */ - inputs?: z.infer[] + inputs?: z.input[] /** Ordered list of outputs from the subgraph itself. Similar to a reroute, with the input side in the subgraph, and the output side in the graph. */ - outputs?: z.infer[] + outputs?: z.input[] /** A list of node widgets displayed in the parent graph, on the subgraph object. */ - widgets?: z.infer[] + widgets?: z.input[] definitions?: { - subgraphs: SubgraphInferredBaseType[] + subgraphs: SubgraphDefinitionBaseInput[] } } -/** Required for recursive definition of subgraphs. */ -type SubgraphDefinitionInput = z.input & - SubgraphInferredBaseType -/** Required for recursive definition of subgraphs. */ -type SubgraphDefinitionOutput = z.output & - SubgraphInferredBaseType +interface SubgraphDefinitionBaseOutput extends ComfyWorkflow1BaseOutput { + /** Unique graph ID. Automatically generated if not provided. */ + id: string + revision: number + name: string + + inputNode: z.output + outputNode: z.output + /** Ordered list of inputs to the subgraph itself. Similar to a reroute, with the input side in the graph, and the output side in the subgraph. */ + inputs?: z.output[] + /** Ordered list of outputs from the subgraph itself. Similar to a reroute, with the input side in the subgraph, and the output side in the graph. */ + outputs?: z.output[] + /** A list of node widgets displayed in the parent graph, on the subgraph object. */ + widgets?: z.output[] + definitions?: { + subgraphs: SubgraphDefinitionBaseOutput[] + } +} /** A subgraph definition `worfklow.definitions.subgraphs` */ export const zSubgraphDefinition = zComfyWorkflow1 @@ -417,7 +433,7 @@ export const zSubgraphDefinition = zComfyWorkflow1 /** Unique graph ID. Automatically generated if not provided. */ id: z.string().uuid(), revision: z.number(), - + name: z.string(), inputNode: zExportedSubgraphIONode, outputNode: zExportedSubgraphIONode,