From 3269b54aaee3dc309997d1c0aa972276e6ea43de Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Mon, 5 Aug 2024 16:42:37 -0400 Subject: [PATCH] Sync 2666 Execution Model Inversion (#312) * Sync 2666 Execution Model Inversion * Fix unittest * Fallback compatible --- src/extensions/core/groupNode.ts | 9 +++++++-- src/extensions/core/widgetInputs.ts | 2 +- src/scripts/api.ts | 4 +++- src/scripts/app.ts | 6 +++--- src/scripts/ui.ts | 6 +++++- tests-ui/tests/groupNode.test.ts | 2 ++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/extensions/core/groupNode.ts b/src/extensions/core/groupNode.ts index 59c9610b5..163e4d776 100644 --- a/src/extensions/core/groupNode.ts +++ b/src/extensions/core/groupNode.ts @@ -1108,8 +1108,13 @@ export class GroupNodeHandler { const executed = handleEvent.call( this, 'executed', - (d) => d?.node, - (d, id, node) => ({ ...d, node: id, merge: !node.resetExecution }) + (d) => d?.display_node || d?.node, + (d, id, node) => ({ + ...d, + node: id, + display_node: id, + merge: !node.resetExecution + }) ) const onRemoved = node.onRemoved diff --git a/src/extensions/core/widgetInputs.ts b/src/extensions/core/widgetInputs.ts index ddd3272b6..089d9765c 100644 --- a/src/extensions/core/widgetInputs.ts +++ b/src/extensions/core/widgetInputs.ts @@ -5,7 +5,7 @@ import { LiteGraph } from '@comfyorg/litegraph' import type { LGraphNode, INodeInputSlot, IWidget } from '@comfyorg/litegraph' const CONVERTED_TYPE = 'converted-widget' -const VALID_TYPES = ['STRING', 'combo', 'number', 'BOOLEAN'] +const VALID_TYPES = ['STRING', 'combo', 'number', 'toggle', 'BOOLEAN'] const CONFIG = Symbol() const GET_CONFIG = Symbol() const TARGET = Symbol() // Used for reroutes to specify the real target widget diff --git a/src/scripts/api.ts b/src/scripts/api.ts index f3ffa7178..bd613be7b 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -171,7 +171,9 @@ class ComfyApi extends EventTarget { break case 'executing': this.dispatchEvent( - new CustomEvent('executing', { detail: msg.data.node }) + new CustomEvent('executing', { + detail: msg.data.display_node || msg.data.node + }) ) break case 'executed': diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 7e7bbb57f..964f238c4 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -1627,7 +1627,7 @@ export class ComfyApp { this.workflowManager.activeWorkflow ) return - const output = this.nodeOutputs[detail.node] + const output = this.nodeOutputs[detail.display_node || detail.node] if (detail.merge && output) { for (const k in detail.output ?? {}) { const v = output[k] @@ -1638,9 +1638,9 @@ export class ComfyApp { } } } else { - this.nodeOutputs[detail.node] = detail.output + this.nodeOutputs[detail.display_node || detail.node] = detail.output } - const node = this.graph.getNodeById(detail.node) + const node = this.graph.getNodeById(detail.display_node || detail.node) if (node) { // @ts-expect-error if (node.onExecuted) diff --git a/src/scripts/ui.ts b/src/scripts/ui.ts index 0f8fa456d..6299d31d3 100644 --- a/src/scripts/ui.ts +++ b/src/scripts/ui.ts @@ -272,7 +272,11 @@ class ComfyList { false ) if ('outputs' in item) { - app.nodeOutputs = item.outputs + app.nodeOutputs = {} + for (const [key, value] of Object.entries(item.outputs)) { + const realKey = item['meta']?.[key]?.display_node ?? key + app.nodeOutputs[realKey] = value + } } } }), diff --git a/tests-ui/tests/groupNode.test.ts b/tests-ui/tests/groupNode.test.ts index 1f529c23d..bba8e340d 100644 --- a/tests-ui/tests/groupNode.test.ts +++ b/tests-ui/tests/groupNode.test.ts @@ -578,6 +578,7 @@ describe('group node', () => { new CustomEvent('executed', { detail: { node: `${nodes.save.id}`, + display_node: `${nodes.save.id}`, output: { images: [ { @@ -618,6 +619,7 @@ describe('group node', () => { new CustomEvent('executed', { detail: { node: `${group.id}:5`, + display_node: `${group.id}:5`, output: { images: [ {