From 43cc96255b7f987eff65b532f81d89bf7dc17a30 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 13 Jul 2023 20:05:45 +1000 Subject: [PATCH] fix(ui): check for metadata accumulator before connecting to it --- .../addControlNetToLinearGraph.ts | 22 ++++++++++--------- .../graphBuilders/addDynamicPromptsToGraph.ts | 14 +++++++----- .../util/graphBuilders/addLoRAsToGraph.ts | 10 +++++---- .../nodes/util/graphBuilders/addVAEToGraph.ts | 8 +++---- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addControlNetToLinearGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addControlNetToLinearGraph.ts index 3291ce389d..2b7ccccda2 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addControlNetToLinearGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addControlNetToLinearGraph.ts @@ -19,9 +19,9 @@ export const addControlNetToLinearGraph = ( const validControlNets = getValidControlNets(controlNets); - const metadataAccumulator = graph.nodes[ - METADATA_ACCUMULATOR - ] as MetadataAccumulatorInvocation; + const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as + | MetadataAccumulatorInvocation + | undefined; if (isControlNetEnabled && Boolean(validControlNets.length)) { if (validControlNets.length) { @@ -79,13 +79,15 @@ export const addControlNetToLinearGraph = ( graph.nodes[controlNetNode.id] = controlNetNode; - // metadata accumulator only needs a control field - not the whole node - // extract what we need and add to the accumulator - const controlField = omit(controlNetNode, [ - 'id', - 'type', - ]) as ControlField; - metadataAccumulator.controlnets.push(controlField); + if (metadataAccumulator) { + // metadata accumulator only needs a control field - not the whole node + // extract what we need and add to the accumulator + const controlField = omit(controlNetNode, [ + 'id', + 'type', + ]) as ControlField; + metadataAccumulator.controlnets.push(controlField); + } graph.edges.push({ source: { node_id: controlNetNode.id, field: 'control' }, diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addDynamicPromptsToGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addDynamicPromptsToGraph.ts index 2694cdc812..d4289433eb 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addDynamicPromptsToGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addDynamicPromptsToGraph.ts @@ -32,9 +32,9 @@ export const addDynamicPromptsToGraph = ( maxPrompts, } = state.dynamicPrompts; - const metadataAccumulator = graph.nodes[ - METADATA_ACCUMULATOR - ] as MetadataAccumulatorInvocation; + const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as + | MetadataAccumulatorInvocation + | undefined; if (isDynamicPromptsEnabled) { // iteration is handled via dynamic prompts @@ -116,11 +116,15 @@ export const addDynamicPromptsToGraph = ( (graph.nodes[NOISE] as NoiseInvocation).seed = seed; // hook up seed to metadata - metadataAccumulator.seed = seed; + if (metadataAccumulator) { + metadataAccumulator.seed = seed; + } } } else { // no dynamic prompt - hook up positive prompt - metadataAccumulator.positive_prompt = positivePrompt; + if (metadataAccumulator) { + metadataAccumulator.positive_prompt = positivePrompt; + } const rangeOfSizeNode: RangeOfSizeInvocation = { id: RANGE_OF_SIZE, diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts index 9b8bff2c34..3614c26976 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts @@ -30,9 +30,9 @@ export const addLoRAsToGraph = ( const { loras } = state.lora; const loraCount = size(loras); - const metadataAccumulator = graph.nodes[ - METADATA_ACCUMULATOR - ] as MetadataAccumulatorInvocation; + const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as + | MetadataAccumulatorInvocation + | undefined; if (loraCount > 0) { // Remove MAIN_MODEL_LOADER unet connection to feed it to LoRAs @@ -70,7 +70,9 @@ export const addLoRAsToGraph = ( }; // add the lora to the metadata accumulator - metadataAccumulator.loras.push({ lora: loraField, weight }); + if (metadataAccumulator) { + metadataAccumulator.loras.push({ lora: loraField, weight }); + } // add to graph graph.nodes[currentLoraNodeId] = loraLoaderNode; diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts index b3d4416b69..d76fec093c 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addVAEToGraph.ts @@ -22,9 +22,9 @@ export const addVAEToGraph = ( const vae_model = modelIdToVAEModelField(vae?.id || ''); const isAutoVae = !vae; - const metadataAccumulator = graph.nodes[ - METADATA_ACCUMULATOR - ] as MetadataAccumulatorInvocation; + const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as + | MetadataAccumulatorInvocation + | undefined; if (!isAutoVae) { graph.nodes[VAE_LOADER] = { @@ -73,7 +73,7 @@ export const addVAEToGraph = ( }); } - if (vae) { + if (vae && metadataAccumulator) { metadataAccumulator.vae = vae_model; } };