MCPcopy Create free account
hub / github.com/6174/comflowyspace / parseGraphVariables

Function parseGraphVariables

packages/common/types/comfy-variables.types.ts:146–218  ·  view source on GitHub ↗
(workflow: PersistedWorkflowDocument, widgets: Record<string, Widget>)

Source from the content-addressed store, hash-verified

144 * @returns
145 */
146export function parseGraphVariables(workflow: PersistedWorkflowDocument, widgets: Record<string, Widget>): ComfyGraghVariables {
147 const vars = getDefaultComfyGraphVars();
148 const nodesMap = workflow.nodes
149 const connections = workflow.connections;
150
151 connections.forEach(conn => {
152 const source_node = nodesMap[conn.source];
153 const target_node = nodesMap[conn.target];
154 const target_widget_name = target_node.value.widget;
155 const source_widget = widgets[source_node.value.widget];
156
157 if (!source_widget) {
158 return
159 }
160
161 // 如果 source 判断是本地的 widget 则不能把它的 output 作为变量,比如 reroute,const 等
162 if (Widget.isLocalWidget(source_widget)) {
163 return
164 }
165
166 // source 的输出具体信息找出来
167 const output_handle = conn.sourceHandle as any;
168 const outputs = source_widget.output;
169 const outputs_names = source_widget.output_name;
170 const output_name = outputs_names ? outputs_names[outputs.indexOf(output_handle)] : output_handle;
171
172 // target port 的信息
173 const target_handle = conn.targetHandle;
174
175 const var_info: ComfyGraphVar = {
176 name: output_name,
177 type: output_handle,
178 connection: conn,
179 source_node,
180 target_node
181 }
182
183 switch (target_widget_name) {
184 case NODE_ANYTHING_EVERYWHERE3:
185 case NODE_ANYTHING_EVERYWHERE:
186 vars.global[output_handle] = var_info
187 break;
188 case NODE_ANYTHING_EVERYWHERE_PROMPT:
189 if (target_handle == "+VE") {
190 vars.global["CONDITIONING.positive"] = {
191 ...var_info,
192 name: "CONDITIONING.positive"
193 }
194 }
195 if (target_handle == "-VE") {
196 vars.global["CONDITIONING.negative"] = {
197 ...var_info,
198 name: "CONDITIONING.negative"
199 }
200 }
201 break;
202 case NODE_ANYTHING_EVERYWHERE_REGEX:
203 vars.regex[output_handle] = {

Callers 2

createHookFunction · 0.90
createPromptFunction · 0.90

Calls 1

getDefaultComfyGraphVarsFunction · 0.85

Tested by

no test coverage detected