Line data Source code
1 : import type { INodeInputSlot } from '@comfyorg/graph-model/slots'
2 : import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
3 : import type { IBaseWidget } from '@comfyorg/graph-model/widgets'
4 : import type { NodeExecutionId } from '@comfyorg/graph-model/nodeIdentification'
5 : import { getExecutionIdByNode } from '@/utils/graphTraversalUtil'
6 :
7 : import { inputForWidget, promotedInputSource } from './promotedInputWidget'
8 : import {
9 : buildPromotedSourceExecutionId,
10 : resolveConcretePromotedWidget
11 : } from './resolveConcretePromotedWidget'
12 :
13 : type PromotedWidgetInput = INodeInputSlot & {
14 : widgetId: NonNullable<INodeInputSlot['widgetId']>
15 : }
16 :
17 958 : function hasWidgetId(
18 : input: INodeInputSlot | undefined
19 : ): input is PromotedWidgetInput {
20 958 : return input?.widgetId !== undefined
21 : }
22 :
23 : interface ResolvedPromotedWidgetSource {
24 : input: PromotedWidgetInput
25 : sourceExecutionId?: NodeExecutionId
26 : sourceNode: LGraphNode
27 : sourceWidget: IBaseWidget
28 : sourceWidgetName: string
29 : }
30 :
31 47291 : export function resolvePromotedWidgetSource(
32 : rootGraph: LGraph | null | undefined,
33 : node: LGraphNode,
34 : widget: IBaseWidget
35 : ): ResolvedPromotedWidgetSource | undefined {
36 47291 : if (!node.isSubgraphNode()) return undefined
37 :
38 958 : const input = inputForWidget(node, widget)
39 18279 : if (!hasWidgetId(input)) return undefined
40 :
41 957 : const source = promotedInputSource(node, input)
42 8079 : if (!source) return undefined
43 :
44 957 : const resolution = resolveConcretePromotedWidget(
45 : node,
46 : source.nodeId,
47 : source.widgetName
48 : )
49 8079 : if (resolution.status !== 'resolved') return undefined
50 :
51 957 : const { node: sourceNode, widget: sourceWidget } = resolution.resolved
52 47291 : const hostExecutionId = rootGraph
53 : ? getExecutionIdByNode(rootGraph, node)
54 : : undefined
55 47291 : return {
56 : input,
57 : sourceExecutionId: hostExecutionId
58 : ? buildPromotedSourceExecutionId(
59 : hostExecutionId,
60 : resolution.resolved.nodePath
61 : )
62 : : undefined,
63 : sourceNode,
64 : sourceWidget,
65 : sourceWidgetName: sourceWidget.name
66 : }
67 : }
|