comfy-ts 0.4.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +385 -255
  2. package/dist/DefinedWorkflow-BYyu5dK9.js +669 -0
  3. package/dist/DefinedWorkflow-BYyu5dK9.js.map +1 -0
  4. package/dist/cli.js +4106 -152
  5. package/dist/cli.js.map +1 -1
  6. package/dist/index.cjs +1560 -333
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +7826 -467
  9. package/dist/index.d.ts +7808 -449
  10. package/dist/index.js +1550 -333
  11. package/dist/index.js.map +1 -1
  12. package/dist/{run-tui-SDSJo1Qf.js → run-tui-DZ22HDHI.js} +631 -657
  13. package/dist/run-tui-DZ22HDHI.js.map +1 -0
  14. package/examples/01-txt2img.cflow.ts +50 -0
  15. package/examples/02-img2img-upload.cflow.ts +55 -0
  16. package/examples/03-export-workflow-json.cflow.ts +56 -0
  17. package/examples/04-krea2-turbo-t2i.cflow.ts +125 -0
  18. package/examples/05-comfy-cloud.cflow.ts +51 -0
  19. package/examples/README.md +30 -0
  20. package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
  21. package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
  22. package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
  23. package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
  24. package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
  25. package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
  26. package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
  27. package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
  28. package/examples/comfy-cloud/cloudHost.ts +41 -0
  29. package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
  30. package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
  31. package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
  32. package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
  33. package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
  34. package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
  35. package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
  36. package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
  37. package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
  38. package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
  39. package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
  40. package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
  41. package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
  42. package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
  43. package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
  44. package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
  45. package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
  46. package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
  47. package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
  48. package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
  49. package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
  50. package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
  51. package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
  52. package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
  53. package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
  54. package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
  55. package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
  56. package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
  57. package/examples/comfy-cloud/sdk.d.ts +123062 -0
  58. package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
  59. package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
  60. package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
  61. package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
  62. package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
  63. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
  64. package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
  65. package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
  66. package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
  67. package/examples/images/README.md +18 -0
  68. package/examples/images/bear_1024x1024.jpg +0 -0
  69. package/examples/images/deer_768x1344.jpg +0 -0
  70. package/examples/images/dog_512x512.jpg +0 -0
  71. package/examples/images/lioness_768x768.jpg +0 -0
  72. package/examples/images/pug_200x300.jpg +0 -0
  73. package/examples/images/walrus_1344x768.jpg +0 -0
  74. package/guide-for-agents.md +172 -0
  75. package/package.json +20 -4
  76. package/src/cli/comfy-ts-cli.ts +19 -2
  77. package/src/cli/gen.ts +21 -12
  78. package/src/cli/tui/components/PreviewPanel.tsx +9 -8
  79. package/src/cli/tui/components/StatusBar.tsx +11 -0
  80. package/src/cli/tui/components/TreePanel.tsx +15 -2
  81. package/src/cli/tui/components/TuiApp.tsx +18 -0
  82. package/src/cli/tui/discoverWorkflows.ts +45 -0
  83. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
  84. package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
  85. package/src/cli/tui/imagePicker/fsListing.ts +46 -0
  86. package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
  87. package/src/cli/tui/run-tui.tsx +52 -23
  88. package/src/cli/tui/state/HostSt.ts +2 -3
  89. package/src/cli/tui/state/LorasSt.ts +14 -36
  90. package/src/cli/tui/state/PreviewSt.ts +28 -2
  91. package/src/cli/tui/state/TreeSt.ts +30 -6
  92. package/src/cli/tui/state/TuiSt.ts +27 -3
  93. package/src/cli/tui/state/WorkflowsSt.ts +15 -1
  94. package/src/exampleAssets.ts +56 -0
  95. package/src/graph/ComfyNode.ts +4 -1
  96. package/src/host/ComfyHost.ts +203 -77
  97. package/src/host/ComfyManager.ts +10 -9
  98. package/src/host/ComfyUploader.ts +1 -2
  99. package/src/host/ResilientWebsocket.ts +3 -1
  100. package/src/host/hostUrl.ts +59 -0
  101. package/src/host/loraManagerApi.ts +5 -4
  102. package/src/index.ts +27 -1
  103. package/src/litegraph/CanonicalWorkflow.ts +77 -0
  104. package/src/litegraph/LiteGraphGroup.ts +9 -7
  105. package/src/litegraph/LiteGraphJSON.ts +34 -13
  106. package/src/litegraph/LiteGraphLink.ts +32 -2
  107. package/src/litegraph/LiteGraphNode.ts +18 -33
  108. package/src/litegraph/LiteGraphNodeInput.ts +10 -8
  109. package/src/litegraph/LiteGraphNodeOutput.ts +2 -3
  110. package/src/litegraph/LiteGraphSubgraphDef.ts +74 -0
  111. package/src/litegraph/convertFlowToLiteGraphJSON.ts +4 -4
  112. package/src/litegraph/expandSubgraphs.ts +352 -0
  113. package/src/litegraph/normalizeWorkflow.ts +141 -0
  114. package/src/manager/ComfyRegistry.ts +37 -9
  115. package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
  116. package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
  117. package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
  118. package/src/manager/generated/KnownModel_Base.ts +23 -7
  119. package/src/manager/generated/KnownModel_FileName.ts +421 -0
  120. package/src/manager/generated/KnownModel_Name.ts +421 -0
  121. package/src/manager/generated/KnownModel_SavePath.ts +34 -8
  122. package/src/manager/generated/KnownModel_Type.ts +18 -14
  123. package/src/manager/json/alter-list.json +221 -221
  124. package/src/manager/json/custom-node-list.json +61020 -21946
  125. package/src/manager/json/extension-node-map.json +81077 -31176
  126. package/src/manager/json/github-stats.json +29321 -12601
  127. package/src/manager/json/model-list.json +5935 -4997
  128. package/src/manager/loaders/parseReport.ts +55 -0
  129. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
  130. package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
  131. package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
  132. package/src/manager/loaders/step4_model-list-loader.ts +25 -36
  133. package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
  134. package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
  135. package/src/manager/script-update-manager.bun.ts +9 -1
  136. package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
  137. package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
  138. package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
  139. package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
  140. package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
  141. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
  142. package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
  143. package/src/runner/ComfyExecution.ts +4 -5
  144. package/src/runner/ComfyWorkflow.ts +2 -2
  145. package/src/runner/wsBinaryFrame.ts +48 -0
  146. package/src/sdk-generator/ComfySchema.ts +14 -1
  147. package/src/sdk-generator/Primitives.ts +6 -24
  148. package/src/sdk-generator/comfy-api-json.ts +3 -1
  149. package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
  150. package/src/sdk-generator/inputWidgetKind.ts +196 -0
  151. package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
  152. package/src/state.ts +13 -2
  153. package/src/vars/ComfyVars.ts +82 -2
  154. package/src/vars/DefinedWorkflow.ts +7 -2
  155. package/dist/log-CdfgILde.js +0 -10
  156. package/dist/log-CdfgILde.js.map +0 -1
  157. package/dist/run-tui-SDSJo1Qf.js.map +0 -1
  158. package/src/utils/tryExtracting.ts +0 -41
@@ -0,0 +1,352 @@
1
+ import type { CanonicalLink, CanonicalNode, CanonicalWorkflow } from 'src/litegraph/CanonicalWorkflow.ts'
2
+ import { asLiteGraphLinkID, type LiteGraphLinkID } from 'src/litegraph/LiteGraphLinkID.ts'
3
+ import { WorkflowNormalizeError } from 'src/litegraph/normalizeWorkflow.ts'
4
+ import { bang } from 'src/utils/bang.ts'
5
+
6
+ /** one exposed slot of a normalized subgraph definition */
7
+ export type CanonicalSubgraphIO = {
8
+ name: string
9
+ type: string
10
+ }
11
+
12
+ /** a subgraph definition normalized by the SAME per-node/per-link normalizers as the root */
13
+ export type CanonicalSubgraphDef = {
14
+ id: string // uuid, referenced by instance nodes' `type`
15
+ name: string
16
+ inputs: CanonicalSubgraphIO[]
17
+ outputs: CanonicalSubgraphIO[]
18
+ nodes: CanonicalNode[]
19
+ links: CanonicalLink[]
20
+ }
21
+
22
+ /** boundary sentinel ids inside definition link tables */
23
+ const SUBGRAPH_INPUT_NODE_ID = -10
24
+ const SUBGRAPH_OUTPUT_NODE_ID = -20
25
+
26
+ /** 48 corpus files nest defs inside defs; a self-referencing def would loop forever */
27
+ const MAX_EXPANSION_PASSES = 32
28
+
29
+ /**
30
+ * widget-kind fallback when a def input slot has no boundary target carrying a
31
+ * widget marker: these litegraph slot types carry widget values. LOCAL copy on
32
+ * purpose — the sdk-generator's seed-consumes-2 arithmetic does not apply here
33
+ * (the io-widget era serializes exactly one value per exposed widget slot).
34
+ */
35
+ const PRIMITIVE_WIDGET_TYPES: ReadonlySet<string> = new Set(['INT', 'FLOAT', 'STRING', 'BOOLEAN', 'COMBO'])
36
+
37
+ /**
38
+ * inline every subgraph instance (node whose `type` is a definition uuid) into
39
+ * the root graph: fresh numeric ids, boundary links rewired, instance widget
40
+ * values promoted into the inner nodes' `named` overrides. Iterative so nested
41
+ * definitions expand on the next pass. Muted instances are dropped (their
42
+ * consumers resolve unconnected); bypassed instances stay for the converter's
43
+ * passthrough walk, which needs no interior.
44
+ */
45
+ export const expandSubgraphs = (wf: CanonicalWorkflow, defs: Map<string, CanonicalSubgraphDef>): CanonicalWorkflow => {
46
+ let passes = 0
47
+ while (true) {
48
+ const expandable = wf.nodes.filter((n) => defs.has(n.type) && n.mode !== 'bypassed')
49
+ if (expandable.length === 0) return wf
50
+ if (++passes > MAX_EXPANSION_PASSES)
51
+ throw new WorkflowNormalizeError(
52
+ 'subgraph-cycle',
53
+ `subgraph expansion did not terminate after ${MAX_EXPANSION_PASSES} passes — self-referencing definitions?`,
54
+ )
55
+ for (const instance of expandable) {
56
+ if (instance.mode === 'muted') dropMutedInstance(wf, instance)
57
+ else expandOneInstance(wf, instance, bang(defs.get(instance.type)))
58
+ }
59
+ }
60
+ }
61
+
62
+ /** converter mute semantics applied early: after expansion there is no single node left to skip */
63
+ const dropMutedInstance = (wf: CanonicalWorkflow, instance: CanonicalNode): void => {
64
+ const dead = new Set<LiteGraphLinkID>()
65
+ for (const link of wf.links) {
66
+ if (link.originId === instance.id || link.targetId === instance.id) dead.add(link.id)
67
+ }
68
+ wf.links = wf.links.filter((l) => !dead.has(l.id))
69
+ wf.nodes = wf.nodes.filter((n) => n.id !== instance.id)
70
+ pruneDeadLinkRefs(wf, dead)
71
+ }
72
+
73
+ const pruneDeadLinkRefs = (wf: CanonicalWorkflow, dead: ReadonlySet<LiteGraphLinkID>): void => {
74
+ if (dead.size === 0) return
75
+ for (const node of wf.nodes) {
76
+ for (const input of node.inputs) {
77
+ if (input.link != null && dead.has(input.link)) input.link = null
78
+ }
79
+ for (const output of node.outputs) {
80
+ output.links = output.links.filter((id) => !dead.has(id))
81
+ }
82
+ }
83
+ }
84
+
85
+ const expandOneInstance = (wf: CanonicalWorkflow, instance: CanonicalNode, def: CanonicalSubgraphDef): void => {
86
+ // 1. fresh numeric ids, deterministic (def node order / def link order)
87
+ let nextNodeId = Math.max(0, ...wf.nodes.map((n) => n.id))
88
+ let nextLinkId = Math.max(0, ...wf.links.map((l) => l.id))
89
+ const newNodeIds = new Map<number, number>()
90
+ for (const inner of def.nodes) newNodeIds.set(inner.id, ++nextNodeId)
91
+ // null = the def link references a node the def does not contain: upstream
92
+ // editors leave STALE links behind after node deletion (corpus-verified,
93
+ // e.g. utility_video_upscale) and the frontend prunes them on load. We drop
94
+ // the link; the consumer resolves unconnected, loud at conversion when required.
95
+ const remapNodeId = (id: number): number | null => newNodeIds.get(id) ?? null
96
+
97
+ // 2. instance input slot → def input slot, BY NAME (instances may serialize
98
+ // a subset of the def's inputs). A name matching NO def input is LOUD:
99
+ // silently falling back to the positional index would wire the outer feed
100
+ // into the wrong inner slot (corpus-absent today, so a throw is safe)
101
+ const defSlotOfInstanceSlot = new Map<number, number>()
102
+ for (const [k, input] of instance.inputs.entries()) {
103
+ const defSlot = def.inputs.findIndex((d) => d.name === input.name)
104
+ if (defSlot < 0)
105
+ throw new WorkflowNormalizeError(
106
+ 'subgraph-io-mismatch',
107
+ `subgraph instance ${instance.id}(${def.name}): input "${input.name}" (slot ${k}) matches no definition input (defined: ${def.inputs.map((d) => d.name).join(', ')})`,
108
+ )
109
+ defSlotOfInstanceSlot.set(k, defSlot)
110
+ }
111
+
112
+ // 3. outer links INTO the instance, keyed by def input slot
113
+ const outerLinkIntoDefSlot = new Map<number, CanonicalLink>()
114
+ for (const link of wf.links) {
115
+ if (link.targetId !== instance.id) continue
116
+ const defSlot = defSlotOfInstanceSlot.get(link.targetSlot)
117
+ if (defSlot == null)
118
+ throw new WorkflowNormalizeError(
119
+ 'subgraph-io-mismatch',
120
+ `subgraph instance ${instance.id}(${def.name}): link ${link.id} targets undeclared instance slot ${link.targetSlot}`,
121
+ )
122
+ outerLinkIntoDefSlot.set(defSlot, link)
123
+ }
124
+
125
+ // 4. classify definition links: plain interior links clone with fresh ids;
126
+ // input-boundary links (-10 origin) become real links from the outer origin
127
+ // when one exists (else they drop and the inner target falls back to its own
128
+ // widget values); output-boundary links (-20 target) just name the inner
129
+ // producer each def output slot maps to.
130
+ const newLinkIds = new Map<LiteGraphLinkID, LiteGraphLinkID>()
131
+ const splicedLinks: CanonicalLink[] = []
132
+ const producerByOutSlot = new Map<number, { nodeId: number; slot: number }>()
133
+ const passthroughOutSlot = new Map<number, number>() // def out slot → def in slot (-10 → -20 direct)
134
+ const boundaryTargetsByInSlot = new Map<number, { nodeId: number; slot: number }[]>() // remapped inner targets
135
+ for (const link of def.links) {
136
+ const fromInputBoundary = link.originId === SUBGRAPH_INPUT_NODE_ID
137
+ const toOutputBoundary = link.targetId === SUBGRAPH_OUTPUT_NODE_ID
138
+ if (fromInputBoundary && toOutputBoundary) {
139
+ passthroughOutSlot.set(link.targetSlot, link.originSlot)
140
+ continue
141
+ }
142
+ if (toOutputBoundary) {
143
+ const producerId = remapNodeId(link.originId)
144
+ if (producerId != null && !producerByOutSlot.has(link.targetSlot))
145
+ producerByOutSlot.set(link.targetSlot, { nodeId: producerId, slot: link.originSlot })
146
+ continue
147
+ }
148
+ if (fromInputBoundary) {
149
+ const targetId = remapNodeId(link.targetId)
150
+ if (targetId == null) continue
151
+ const target = { nodeId: targetId, slot: link.targetSlot }
152
+ const targets = boundaryTargetsByInSlot.get(link.originSlot) ?? []
153
+ targets.push(target)
154
+ boundaryTargetsByInSlot.set(link.originSlot, targets)
155
+ const outer = outerLinkIntoDefSlot.get(link.originSlot)
156
+ if (outer == null) continue // no outer feed: inner target's input.link nulls at clone time
157
+ const fresh = asLiteGraphLinkID(++nextLinkId)
158
+ newLinkIds.set(link.id, fresh)
159
+ splicedLinks.push({
160
+ id: fresh,
161
+ originId: outer.originId,
162
+ originSlot: outer.originSlot,
163
+ targetId: target.nodeId,
164
+ targetSlot: target.slot,
165
+ type: link.type,
166
+ })
167
+ const originNode = wf.nodes.find((n) => n.id === outer.originId)
168
+ originNode?.outputs[outer.originSlot]?.links.push(fresh)
169
+ continue
170
+ }
171
+ const interiorOrigin = remapNodeId(link.originId)
172
+ const interiorTarget = remapNodeId(link.targetId)
173
+ if (interiorOrigin == null || interiorTarget == null) continue
174
+ const fresh = asLiteGraphLinkID(++nextLinkId)
175
+ newLinkIds.set(link.id, fresh)
176
+ splicedLinks.push({
177
+ id: fresh,
178
+ originId: interiorOrigin,
179
+ originSlot: link.originSlot,
180
+ targetId: interiorTarget,
181
+ targetSlot: link.targetSlot,
182
+ type: link.type,
183
+ })
184
+ }
185
+
186
+ // 5. clone inner nodes with remapped ids; link refs not in newLinkIds were
187
+ // dropped boundary links → null (the node falls back to its widget values)
188
+ const splicedNodes: CanonicalNode[] = def.nodes.map((inner) => ({
189
+ id: bang(newNodeIds.get(inner.id)),
190
+ type: inner.type,
191
+ title: inner.title,
192
+ mode: inner.mode,
193
+ isVirtualNode: inner.isVirtualNode,
194
+ inputs: inner.inputs.map((i) => ({
195
+ name: i.name,
196
+ type: i.type,
197
+ link: i.link != null ? (newLinkIds.get(i.link) ?? null) : null,
198
+ widgetName: i.widgetName,
199
+ })),
200
+ outputs: inner.outputs.map((o) => ({
201
+ name: o.name,
202
+ type: o.type,
203
+ links: o.links.map((id) => newLinkIds.get(id)).filter((id): id is LiteGraphLinkID => id != null),
204
+ })),
205
+ widgets: { positional: [...inner.widgets.positional], named: { ...inner.widgets.named } },
206
+ pos: [inner.pos[0], inner.pos[1]],
207
+ size: [inner.size[0], inner.size[1]],
208
+ properties: { ...inner.properties },
209
+ }))
210
+
211
+ // 6. rewire root links FROM the instance's outputs onto the inner producers;
212
+ // outer links INTO the instance were consumed by step 4
213
+ const dead = new Set<LiteGraphLinkID>()
214
+ for (const link of wf.links) {
215
+ if (link.targetId === instance.id) {
216
+ dead.add(link.id)
217
+ continue
218
+ }
219
+ if (link.originId !== instance.id) continue
220
+ const producer = producerByOutSlot.get(link.originSlot)
221
+ if (producer != null) {
222
+ link.originId = producer.nodeId
223
+ link.originSlot = producer.slot
224
+ const producerNode = splicedNodes.find((n) => n.id === producer.nodeId)
225
+ producerNode?.outputs[producer.slot]?.links.push(link.id)
226
+ continue
227
+ }
228
+ const passthroughInSlot = passthroughOutSlot.get(link.originSlot)
229
+ const outer = passthroughInSlot != null ? outerLinkIntoDefSlot.get(passthroughInSlot) : null
230
+ if (outer != null) {
231
+ link.originId = outer.originId
232
+ link.originSlot = outer.originSlot
233
+ continue
234
+ }
235
+ dead.add(link.id) // def output has no producer: consumers resolve unconnected
236
+ }
237
+ wf.links = wf.links.filter((l) => !dead.has(l.id))
238
+ pruneDeadLinkRefs(wf, dead)
239
+
240
+ // 7. widget promotion (both serialization eras), then splice
241
+ promoteInstanceWidgets(instance, def, splicedNodes, newNodeIds, boundaryTargetsByInSlot)
242
+ wf.nodes = wf.nodes.filter((n) => n.id !== instance.id)
243
+ wf.nodes.push(...splicedNodes)
244
+ wf.links.push(...splicedLinks)
245
+ }
246
+
247
+ /**
248
+ * instance widget values land in inner nodes' `named` overrides. TWO eras for
249
+ * the POSITIONAL values:
250
+ * - proxyWidgets era: `properties.proxyWidgets` pairs [innerNodeId, widgetName]
251
+ * zip against the instance's positional values (incl. `control_after_generate`
252
+ * phantom pairs — written to `named` and simply never read, no schema input
253
+ * has that name).
254
+ * - io-widget era (no proxyWidgets): positional values zip against the def's
255
+ * widget-kind input slots in def order, one value per slot (no phantom —
256
+ * corpus-verified). An outer link into the same slot wins in the converter;
257
+ * the named override is still written, matching ComfyUI.
258
+ * PLUS, in both eras, NAMED overrides on the instance keyed by def-input name:
259
+ * that is how a NESTED instance receives its outer values (the previous pass
260
+ * wrote them to `named`), so they must forward through THIS expansion too —
261
+ * named wins over positional, same precedence as the converter.
262
+ */
263
+ const promoteInstanceWidgets = (
264
+ instance: CanonicalNode,
265
+ def: CanonicalSubgraphDef,
266
+ splicedNodes: CanonicalNode[],
267
+ newNodeIds: Map<number, number>,
268
+ boundaryTargetsByInSlot: Map<number, { nodeId: number; slot: number }[]>,
269
+ ): void => {
270
+ const promoteToSlotTargets = (slot: number, value: unknown): void => {
271
+ for (const t of boundaryTargetsByInSlot.get(slot) ?? []) {
272
+ const target = splicedNodes.find((n) => n.id === t.nodeId)
273
+ const input = innerInputAt(splicedNodes, t)
274
+ if (target == null || input == null) continue
275
+ target.widgets.named[input.name] = value
276
+ }
277
+ }
278
+
279
+ promotePositionalWidgets(instance, def, splicedNodes, newNodeIds, boundaryTargetsByInSlot, promoteToSlotTargets)
280
+
281
+ for (const [slot, io] of def.inputs.entries()) {
282
+ if (!Object.hasOwn(instance.widgets.named, io.name)) continue
283
+ promoteToSlotTargets(slot, instance.widgets.named[io.name])
284
+ }
285
+ }
286
+
287
+ const promotePositionalWidgets = (
288
+ instance: CanonicalNode,
289
+ def: CanonicalSubgraphDef,
290
+ splicedNodes: CanonicalNode[],
291
+ newNodeIds: Map<number, number>,
292
+ boundaryTargetsByInSlot: Map<number, { nodeId: number; slot: number }[]>,
293
+ promoteToSlotTargets: (slot: number, value: unknown) => void,
294
+ ): void => {
295
+ const values = instance.widgets.positional
296
+ if (values.length === 0) return // inner nodes keep their serialized defaults
297
+
298
+ const proxy = instance.properties['proxyWidgets']
299
+ if (Array.isArray(proxy) && proxy.length > 0) {
300
+ const count = Math.min(values.length, proxy.length)
301
+ for (let k = 0; k < count; k++) {
302
+ const pair: unknown = proxy[k]
303
+ if (!Array.isArray(pair) || pair.length !== 2)
304
+ throw new WorkflowNormalizeError(
305
+ 'subgraph-io-mismatch',
306
+ `subgraph instance ${instance.id}(${def.name}): malformed proxyWidgets entry ${JSON.stringify(pair)}`,
307
+ )
308
+ const innerId = Number(pair[0])
309
+ const widgetName = String(pair[1])
310
+ if (innerId < 0) {
311
+ // id -1 names a widget on the subgraph node ITSELF (a promoted io
312
+ // widget): route the value through the matching def input slot
313
+ const slot = def.inputs.findIndex((d) => d.name === widgetName)
314
+ if (slot < 0)
315
+ throw new WorkflowNormalizeError(
316
+ 'subgraph-io-mismatch',
317
+ `subgraph instance ${instance.id}(${def.name}): proxyWidgets pair ${k} names io widget "${widgetName}" but no definition input matches`,
318
+ )
319
+ promoteToSlotTargets(slot, values[k])
320
+ continue
321
+ }
322
+ const target = splicedNodes.find((n) => n.id === newNodeIds.get(innerId))
323
+ if (target == null)
324
+ throw new WorkflowNormalizeError(
325
+ 'subgraph-io-mismatch',
326
+ `subgraph instance ${instance.id}(${def.name}): proxyWidgets pair ${k} names unknown inner node ${String(pair[0])}`,
327
+ )
328
+ target.widgets.named[widgetName] = values[k]
329
+ }
330
+ return
331
+ }
332
+
333
+ let valueIndex = 0
334
+ for (const [slot, io] of def.inputs.entries()) {
335
+ const targets = boundaryTargetsByInSlot.get(slot) ?? []
336
+ const isWidgetSlot =
337
+ targets.length > 0
338
+ ? targets.some((t) => innerInputAt(splicedNodes, t)?.widgetName != null)
339
+ : PRIMITIVE_WIDGET_TYPES.has(io.type)
340
+ if (!isWidgetSlot) continue
341
+ if (valueIndex >= values.length) break
342
+ promoteToSlotTargets(slot, values[valueIndex++])
343
+ }
344
+ }
345
+
346
+ const innerInputAt = (
347
+ splicedNodes: CanonicalNode[],
348
+ t: { nodeId: number; slot: number },
349
+ ): { name: string; widgetName: string | null } | null => {
350
+ const node = splicedNodes.find((n) => n.id === t.nodeId)
351
+ return node?.inputs[t.slot] ?? null
352
+ }
@@ -0,0 +1,141 @@
1
+ import { type } from 'arktype'
2
+ import type {
3
+ CanonicalGroup,
4
+ CanonicalInput,
5
+ CanonicalLink,
6
+ CanonicalNode,
7
+ CanonicalOutput,
8
+ CanonicalWidgetValues,
9
+ CanonicalWorkflow,
10
+ NodeMode,
11
+ } from 'src/litegraph/CanonicalWorkflow.ts'
12
+ import { type CanonicalSubgraphDef, expandSubgraphs } from 'src/litegraph/expandSubgraphs.ts'
13
+ import type { LiteGraphGroup } from 'src/litegraph/LiteGraphGroup.ts'
14
+ import { type LiteGraphJSON, LiteGraphJSON_ark } from 'src/litegraph/LiteGraphJSON.ts'
15
+ import type { LiteGraphLink } from 'src/litegraph/LiteGraphLink.ts'
16
+ import type { LiteGraphNode } from 'src/litegraph/LiteGraphNode.ts'
17
+ import type { LiteGraphNodeInput } from 'src/litegraph/LiteGraphNodeInput.ts'
18
+ import type { LiteGraphNodeOutput } from 'src/litegraph/LiteGraphNodeOutput.ts'
19
+ import type { LiteGraphSubgraphDef } from 'src/litegraph/LiteGraphSubgraphDef.ts'
20
+
21
+ export type WorkflowNormalizeErrorCode = 'schema-reject' | 'subgraph-cycle' | 'subgraph-io-mismatch' | 'bad-document'
22
+
23
+ /** a workflow JSON we cannot turn into a CanonicalWorkflow — loud, typed, never a cast */
24
+ export class WorkflowNormalizeError extends Error {
25
+ constructor(
26
+ public code: WorkflowNormalizeErrorCode,
27
+ message: string,
28
+ public detail?: unknown,
29
+ ) {
30
+ super(`[workflow ${code}] ${message}`)
31
+ this.name = 'WorkflowNormalizeError'
32
+ }
33
+ }
34
+
35
+ /**
36
+ * THE one entry for foreign workflow JSON (files, clipboard, imports):
37
+ * tolerant ark validation, then normalization to the strict canonical shape.
38
+ */
39
+ export const parseWorkflowJson = (json: unknown): CanonicalWorkflow => {
40
+ const out = LiteGraphJSON_ark(json)
41
+ if (out instanceof type.errors) throw new WorkflowNormalizeError('schema-reject', out.summary, out)
42
+ return normalizeWorkflow(out)
43
+ }
44
+
45
+ /**
46
+ * loose wire document → strict canonical document. Defaults filled, both link
47
+ * eras unified, cosmetic fields dropped, subgraph definitions expanded away
48
+ * (see expandSubgraphs.ts — def interiors go through the SAME per-shape
49
+ * normalizers, they are v1 bodies).
50
+ */
51
+ export const normalizeWorkflow = (raw: LiteGraphJSON): CanonicalWorkflow => {
52
+ const wf: CanonicalWorkflow = {
53
+ nodes: raw.nodes.map(normalizeNode),
54
+ links: raw.links.map(normalizeLink),
55
+ groups: (raw.groups ?? []).map(normalizeGroup),
56
+ }
57
+ const rawDefs = raw.definitions?.subgraphs ?? []
58
+ if (rawDefs.length === 0) return wf
59
+ const defs = new Map<string, CanonicalSubgraphDef>()
60
+ for (const d of rawDefs) defs.set(d.id, normalizeSubgraphDef(d))
61
+ return expandSubgraphs(wf, defs)
62
+ }
63
+
64
+ const normalizeSubgraphDef = (d: LiteGraphSubgraphDef): CanonicalSubgraphDef => {
65
+ return {
66
+ id: d.id,
67
+ name: d.name,
68
+ inputs: d.inputs.map((io) => ({ name: io.name, type: io.type })),
69
+ outputs: d.outputs.map((io) => ({ name: io.name, type: io.type })),
70
+ nodes: d.nodes.map(normalizeNode),
71
+ links: d.links.map(normalizeLink),
72
+ }
73
+ }
74
+
75
+ const normalizeMode = (mode: number | undefined): NodeMode => {
76
+ if (mode === 2) return 'muted'
77
+ if (mode === 4) return 'bypassed'
78
+ return 'normal' // 0 (always) / 1 (on-event) / 3 (on-trigger) all execute
79
+ }
80
+
81
+ const normalizeNode = (n: LiteGraphNode): CanonicalNode => {
82
+ return {
83
+ id: n.id,
84
+ type: n.type,
85
+ title: n.title ?? null,
86
+ mode: normalizeMode(n.mode),
87
+ isVirtualNode: n.isVirtualNode ?? false,
88
+ inputs: (n.inputs ?? []).map(normalizeInput),
89
+ outputs: (n.outputs ?? []).map(normalizeOutput),
90
+ widgets: normalizeWidgetValues(n.widgets_values),
91
+ pos: [n.pos[0], n.pos[1]],
92
+ size: [n.size[0], n.size[1]],
93
+ properties: { ...n.properties },
94
+ }
95
+ }
96
+
97
+ const normalizeInput = (i: LiteGraphNodeInput): CanonicalInput => {
98
+ return {
99
+ name: i.name,
100
+ type: i.type,
101
+ link: i.link ?? null,
102
+ widgetName: i.widget?.name ?? null,
103
+ }
104
+ }
105
+
106
+ const normalizeOutput = (o: LiteGraphNodeOutput): CanonicalOutput => {
107
+ return {
108
+ name: o.name,
109
+ type: o.type,
110
+ links: [...(o.links ?? [])],
111
+ }
112
+ }
113
+
114
+ const normalizeWidgetValues = (wv: unknown[] | Record<string, unknown> | undefined): CanonicalWidgetValues => {
115
+ if (wv == null) return { positional: [], named: {} }
116
+ if (Array.isArray(wv)) return { positional: [...wv], named: {} }
117
+ return { positional: [], named: { ...wv } }
118
+ }
119
+
120
+ const normalizeLink = (l: LiteGraphLink): CanonicalLink => {
121
+ if (Array.isArray(l)) {
122
+ return { id: l[0], originId: l[1], originSlot: l[2], targetId: l[3], targetSlot: l[4], type: l[5] }
123
+ }
124
+ return {
125
+ id: l.id,
126
+ originId: l.origin_id,
127
+ originSlot: l.origin_slot,
128
+ targetId: l.target_id,
129
+ targetSlot: l.target_slot,
130
+ type: l.type,
131
+ }
132
+ }
133
+
134
+ const normalizeGroup = (g: LiteGraphGroup): CanonicalGroup => {
135
+ return {
136
+ title: g.title,
137
+ bounding: [g.bounding[0], g.bounding[1], g.bounding[2], g.bounding[3]],
138
+ color: g.color ?? '#3f789e',
139
+ fontSize: g.font_size ?? 24,
140
+ }
141
+ }
@@ -8,11 +8,28 @@ import { DownloadComfyManagerJSONs } from 'src/manager/loaders/step1_downloadCom
8
8
  import { _getKnownPlugins } from 'src/manager/loaders/step2_custom-node-list-loader.ts'
9
9
  import { _getCustomNodeRegistry } from 'src/manager/loaders/step3_extension-node-map-loader.ts'
10
10
  import { _getKnownModels } from 'src/manager/loaders/step4_model-list-loader.ts'
11
+ import { _getAlterList } from 'src/manager/loaders/step5_alter-list-loader.ts'
12
+ import { _getGithubStats } from 'src/manager/loaders/step6_github-stats-loader.ts'
13
+ import { ManagerParseReport } from 'src/manager/loaders/parseReport.ts'
14
+ import type { ComfyManagerAlterInfo } from 'src/manager/types/ComfyManagerAlterInfo.ts'
15
+ import type { ComfyManagerGithubStatEntry } from 'src/manager/types/ComfyManagerGithubStats.ts'
11
16
  import type { ComfyManagerModelInfo } from 'src/manager/types/ComfyManagerModelInfo.ts'
12
17
  import type { ComfyManagerPluginInfo } from 'src/manager/types/ComfyManagerPluginInfo.ts'
13
18
 
14
19
  const log = (...args: unknown[]) => console.log(`[📘 registry]`, ...args)
15
20
 
21
+ // core ComfyUI as a pseudo-plugin: extension-node-map keys the builtin nodes under this url
22
+ const BUILTIN_URL: KnownComfyPluginURL = 'https://github.com/comfyanonymous/ComfyUI'
23
+ const BUILTIN_PLUGIN: ComfyManagerPluginInfo = {
24
+ id: 'nodes',
25
+ author: 'comfyanonymous',
26
+ description: 'built-in',
27
+ title: 'built-in',
28
+ files: [BUILTIN_URL],
29
+ reference: 'https://github.com/comfyanonymous/ComfyUI',
30
+ install_type: '',
31
+ }
32
+
16
33
  export class ComfyRegistry {
17
34
  // plugins, indexed
18
35
  plugins_byTitle = new Map<KnownComfyPluginTitle, ComfyManagerPluginInfo>()
@@ -26,6 +43,15 @@ export class ComfyRegistry {
26
43
  // Models
27
44
  knownModels = new Map<KnownModel_Name, ComfyManagerModelInfo>()
28
45
 
46
+ // a1111 → comfy alternatives (alter-list.json)
47
+ alterations: ComfyManagerAlterInfo[] = []
48
+
49
+ // repo url → stars / last_update (github-stats.json)
50
+ githubStats = new Map<string, ComfyManagerGithubStatEntry>()
51
+
52
+ // per-file row accounting of the last load, printed on every build
53
+ report = new ManagerParseReport()
54
+
29
55
  static async DownloadAndUpdate(download: boolean): Promise<ComfyRegistry> {
30
56
  if (download) {
31
57
  log(chalk.bold(`1. Downloading comfy-manager JSONs...`))
@@ -46,15 +72,9 @@ export class ComfyRegistry {
46
72
  genTypes?: boolean
47
73
  } = {},
48
74
  ) {
49
- this.plugins_byFile.set('https://github.com/comfyanonymous/ComfyUI' as any, {
50
- id: 'nodes',
51
- author: 'comfyanonymous',
52
- description: 'built-in',
53
- title: 'built-in' as any,
54
- files: [],
55
- reference: 'https://github.com/comfyanonymous/ComfyUI',
56
- install_type: '',
57
- })
75
+ // seeded BEFORE codegen so 'built-in' and the core repo url are legitimate union members
76
+ this.plugins_byTitle.set(BUILTIN_PLUGIN.title, BUILTIN_PLUGIN)
77
+ this.plugins_byFile.set(BUILTIN_URL, BUILTIN_PLUGIN)
58
78
 
59
79
  log(`loading src/manager/json/${chalk.yellow('custom-node-list.json')}...`)
60
80
  _getKnownPlugins(this)
@@ -64,6 +84,14 @@ export class ComfyRegistry {
64
84
 
65
85
  log(`loading src/manager/json/${chalk.yellow('model-list.json')}...`)
66
86
  _getKnownModels(this)
87
+
88
+ log(`loading src/manager/json/${chalk.yellow('alter-list.json')}...`)
89
+ _getAlterList(this)
90
+
91
+ log(`loading src/manager/json/${chalk.yellow('github-stats.json')}...`)
92
+ _getGithubStats(this)
93
+
94
+ this.report.print()
67
95
  }
68
96
 
69
97
  getKnownCheckpoints = (): ComfyManagerModelInfo[] => {