diff --git a/src/extensions/core/previewAny.ts b/src/extensions/core/previewAny.ts index 5fc2ac98dc..cc05a694c2 100644 --- a/src/extensions/core/previewAny.ts +++ b/src/extensions/core/previewAny.ts @@ -9,6 +9,15 @@ import { app } from '@/scripts/app' import { type DOMWidget } from '@/scripts/domWidget' import { ComfyWidgets } from '@/scripts/widgets' import { useExtensionService } from '@/services/extensionService' +import { getNodeByLocatorId } from '@/utils/graphTraversalUtil' + +const applyValue = (node: LGraphNode, text: string | string[]) => { + const previewWidgets = + node.widgets?.filter((w) => w.name.startsWith('preview_')) ?? [] + + const value = Array.isArray(text) ? (text?.join('\n\n') ?? '') : text + for (const previewWidget of previewWidgets) previewWidget.value = value +} useExtensionService().registerExtension({ name: 'Comfy.PreviewAny', @@ -82,16 +91,14 @@ useExtensionService().registerExtension({ ? void 0 : onExecuted.apply(this, [message]) - const previewWidgets = - this.widgets?.filter((w) => w.name.startsWith('preview_')) ?? [] - - for (const previewWidget of previewWidgets) { - const text = message.text ?? '' - previewWidget.value = Array.isArray(text) - ? (text?.join('\n\n') ?? '') - : text - } + applyValue(this, message.text ?? '') } } + }, + onNodeOutputsUpdated(nodeOutputs) { + for (const [nodeLocatorId, output] of Object.entries(nodeOutputs)) { + const node = getNodeByLocatorId(app.rootGraph, nodeLocatorId) + if (node?.type === 'PreviewAny') applyValue(node, output.text ?? '') + } } }) diff --git a/src/types/comfy.ts b/src/types/comfy.ts index 7249f64718..91436877bd 100644 --- a/src/types/comfy.ts +++ b/src/types/comfy.ts @@ -7,10 +7,12 @@ import type { NodeReplacement } from '@/platform/nodeReplacement/types' import type { SettingParams } from '@/platform/settings/types' import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema' import type { Keybinding } from '@/platform/keybindings/types' +import type { NodeExecutionOutput } from '@/schemas/apiSchema' import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' import type { ComfyApp } from '@/scripts/app' import type { ComfyWidgetConstructor } from '@/scripts/widgets' import type { ComfyCommand } from '@/stores/commandStore' +import type { NodeLocatorId } from '@/types/nodeIdentification' import type { AuthUserInfo } from '@/types/authTypes' import type { BottomPanelExtension } from '@/types/extensionTypes' @@ -265,5 +267,9 @@ export interface ComfyExtension { */ onAuthUserLogout?(): Promise | void + onNodeOutputsUpdated?( + nodeOutputs: Record + ): void + [key: string]: unknown }