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.
- package/README.md +385 -255
- package/dist/DefinedWorkflow-BYyu5dK9.js +669 -0
- package/dist/DefinedWorkflow-BYyu5dK9.js.map +1 -0
- package/dist/cli.js +4106 -152
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1560 -333
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7826 -467
- package/dist/index.d.ts +7808 -449
- package/dist/index.js +1550 -333
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-SDSJo1Qf.js → run-tui-DZ22HDHI.js} +631 -657
- package/dist/run-tui-DZ22HDHI.js.map +1 -0
- package/examples/01-txt2img.cflow.ts +50 -0
- package/examples/02-img2img-upload.cflow.ts +55 -0
- package/examples/03-export-workflow-json.cflow.ts +56 -0
- package/examples/04-krea2-turbo-t2i.cflow.ts +125 -0
- package/examples/05-comfy-cloud.cflow.ts +51 -0
- package/examples/README.md +30 -0
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/cloudHost.ts +41 -0
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
- package/examples/comfy-cloud/sdk.d.ts +123062 -0
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
- package/examples/images/README.md +18 -0
- package/examples/images/bear_1024x1024.jpg +0 -0
- package/examples/images/deer_768x1344.jpg +0 -0
- package/examples/images/dog_512x512.jpg +0 -0
- package/examples/images/lioness_768x768.jpg +0 -0
- package/examples/images/pug_200x300.jpg +0 -0
- package/examples/images/walrus_1344x768.jpg +0 -0
- package/guide-for-agents.md +172 -0
- package/package.json +20 -4
- package/src/cli/comfy-ts-cli.ts +19 -2
- package/src/cli/gen.ts +21 -12
- package/src/cli/tui/components/PreviewPanel.tsx +9 -8
- package/src/cli/tui/components/StatusBar.tsx +11 -0
- package/src/cli/tui/components/TreePanel.tsx +15 -2
- package/src/cli/tui/components/TuiApp.tsx +18 -0
- package/src/cli/tui/discoverWorkflows.ts +45 -0
- package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
- package/src/cli/tui/imagePicker/fsListing.ts +46 -0
- package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
- package/src/cli/tui/run-tui.tsx +52 -23
- package/src/cli/tui/state/HostSt.ts +2 -3
- package/src/cli/tui/state/LorasSt.ts +14 -36
- package/src/cli/tui/state/PreviewSt.ts +28 -2
- package/src/cli/tui/state/TreeSt.ts +30 -6
- package/src/cli/tui/state/TuiSt.ts +27 -3
- package/src/cli/tui/state/WorkflowsSt.ts +15 -1
- package/src/exampleAssets.ts +56 -0
- package/src/graph/ComfyNode.ts +4 -1
- package/src/host/ComfyHost.ts +203 -77
- package/src/host/ComfyManager.ts +10 -9
- package/src/host/ComfyUploader.ts +1 -2
- package/src/host/ResilientWebsocket.ts +3 -1
- package/src/host/hostUrl.ts +59 -0
- package/src/host/loraManagerApi.ts +5 -4
- package/src/index.ts +27 -1
- package/src/litegraph/CanonicalWorkflow.ts +77 -0
- package/src/litegraph/LiteGraphGroup.ts +9 -7
- package/src/litegraph/LiteGraphJSON.ts +34 -13
- package/src/litegraph/LiteGraphLink.ts +32 -2
- package/src/litegraph/LiteGraphNode.ts +18 -33
- package/src/litegraph/LiteGraphNodeInput.ts +10 -8
- package/src/litegraph/LiteGraphNodeOutput.ts +2 -3
- package/src/litegraph/LiteGraphSubgraphDef.ts +74 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +4 -4
- package/src/litegraph/expandSubgraphs.ts +352 -0
- package/src/litegraph/normalizeWorkflow.ts +141 -0
- package/src/manager/ComfyRegistry.ts +37 -9
- package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
- package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
- package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
- package/src/manager/generated/KnownModel_Base.ts +23 -7
- package/src/manager/generated/KnownModel_FileName.ts +421 -0
- package/src/manager/generated/KnownModel_Name.ts +421 -0
- package/src/manager/generated/KnownModel_SavePath.ts +34 -8
- package/src/manager/generated/KnownModel_Type.ts +18 -14
- package/src/manager/json/alter-list.json +221 -221
- package/src/manager/json/custom-node-list.json +61020 -21946
- package/src/manager/json/extension-node-map.json +81077 -31176
- package/src/manager/json/github-stats.json +29321 -12601
- package/src/manager/json/model-list.json +5935 -4997
- package/src/manager/loaders/parseReport.ts +55 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
- package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
- package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
- package/src/manager/loaders/step4_model-list-loader.ts +25 -36
- package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
- package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
- package/src/manager/script-update-manager.bun.ts +9 -1
- package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
- package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
- package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
- package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
- package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
- package/src/runner/ComfyExecution.ts +4 -5
- package/src/runner/ComfyWorkflow.ts +2 -2
- package/src/runner/wsBinaryFrame.ts +48 -0
- package/src/sdk-generator/ComfySchema.ts +14 -1
- package/src/sdk-generator/Primitives.ts +6 -24
- package/src/sdk-generator/comfy-api-json.ts +3 -1
- package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
- package/src/sdk-generator/inputWidgetKind.ts +196 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
- package/src/state.ts +13 -2
- package/src/vars/ComfyVars.ts +82 -2
- package/src/vars/DefinedWorkflow.ts +7 -2
- package/dist/log-CdfgILde.js +0 -10
- package/dist/log-CdfgILde.js.map +0 -1
- package/dist/run-tui-SDSJo1Qf.js.map +0 -1
- package/src/utils/tryExtracting.ts +0 -41
package/dist/index.js
CHANGED
|
@@ -1,17 +1,608 @@
|
|
|
1
1
|
import fs, { existsSync, mkdirSync, readFileSync, statSync, writeFile, writeFileSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, join } from "pathe";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, resolve } from "pathe";
|
|
3
3
|
import { scope, type } from "arktype";
|
|
4
4
|
import { nanoid } from "nanoid";
|
|
5
5
|
import sharp from "sharp";
|
|
6
6
|
import { imageMeta } from "image-meta";
|
|
7
7
|
import crypto from "node:crypto";
|
|
8
8
|
import WebSocket from "ws";
|
|
9
|
+
import { homedir } from "node:os";
|
|
9
10
|
import { action, makeObservable, observable, runInAction } from "mobx";
|
|
10
11
|
import https from "node:https";
|
|
11
12
|
import { stdout } from "node:process";
|
|
12
|
-
import {
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
13
14
|
//#region package.json
|
|
14
|
-
var version = "
|
|
15
|
+
var version = "1.1.0";
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/litegraph/LiteGraphLinkID.ts
|
|
18
|
+
const asLiteGraphLinkID = (id) => id;
|
|
19
|
+
const LiteGraphLinkID_ = type.number.atLeast(0).as();
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/utils/bang.ts
|
|
22
|
+
/** assertNotNull */
|
|
23
|
+
const bang = (x, msg = "") => {
|
|
24
|
+
if (x == null) {
|
|
25
|
+
console.error(`[🔴] BANG FAILED`, msg);
|
|
26
|
+
throw new Error("bang: " + (msg ?? "no message"));
|
|
27
|
+
}
|
|
28
|
+
return x;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/litegraph/expandSubgraphs.ts
|
|
32
|
+
/** boundary sentinel ids inside definition link tables */
|
|
33
|
+
const SUBGRAPH_INPUT_NODE_ID = -10;
|
|
34
|
+
const SUBGRAPH_OUTPUT_NODE_ID = -20;
|
|
35
|
+
/** 48 corpus files nest defs inside defs; a self-referencing def would loop forever */
|
|
36
|
+
const MAX_EXPANSION_PASSES = 32;
|
|
37
|
+
/**
|
|
38
|
+
* widget-kind fallback when a def input slot has no boundary target carrying a
|
|
39
|
+
* widget marker: these litegraph slot types carry widget values. LOCAL copy on
|
|
40
|
+
* purpose — the sdk-generator's seed-consumes-2 arithmetic does not apply here
|
|
41
|
+
* (the io-widget era serializes exactly one value per exposed widget slot).
|
|
42
|
+
*/
|
|
43
|
+
const PRIMITIVE_WIDGET_TYPES = /* @__PURE__ */ new Set([
|
|
44
|
+
"INT",
|
|
45
|
+
"FLOAT",
|
|
46
|
+
"STRING",
|
|
47
|
+
"BOOLEAN",
|
|
48
|
+
"COMBO"
|
|
49
|
+
]);
|
|
50
|
+
/**
|
|
51
|
+
* inline every subgraph instance (node whose `type` is a definition uuid) into
|
|
52
|
+
* the root graph: fresh numeric ids, boundary links rewired, instance widget
|
|
53
|
+
* values promoted into the inner nodes' `named` overrides. Iterative so nested
|
|
54
|
+
* definitions expand on the next pass. Muted instances are dropped (their
|
|
55
|
+
* consumers resolve unconnected); bypassed instances stay for the converter's
|
|
56
|
+
* passthrough walk, which needs no interior.
|
|
57
|
+
*/
|
|
58
|
+
const expandSubgraphs = (wf, defs) => {
|
|
59
|
+
let passes = 0;
|
|
60
|
+
while (true) {
|
|
61
|
+
const expandable = wf.nodes.filter((n) => defs.has(n.type) && n.mode !== "bypassed");
|
|
62
|
+
if (expandable.length === 0) return wf;
|
|
63
|
+
if (++passes > MAX_EXPANSION_PASSES) throw new WorkflowNormalizeError("subgraph-cycle", `subgraph expansion did not terminate after ${MAX_EXPANSION_PASSES} passes — self-referencing definitions?`);
|
|
64
|
+
for (const instance of expandable) if (instance.mode === "muted") dropMutedInstance(wf, instance);
|
|
65
|
+
else expandOneInstance(wf, instance, bang(defs.get(instance.type)));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/** converter mute semantics applied early: after expansion there is no single node left to skip */
|
|
69
|
+
const dropMutedInstance = (wf, instance) => {
|
|
70
|
+
const dead = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const link of wf.links) if (link.originId === instance.id || link.targetId === instance.id) dead.add(link.id);
|
|
72
|
+
wf.links = wf.links.filter((l) => !dead.has(l.id));
|
|
73
|
+
wf.nodes = wf.nodes.filter((n) => n.id !== instance.id);
|
|
74
|
+
pruneDeadLinkRefs(wf, dead);
|
|
75
|
+
};
|
|
76
|
+
const pruneDeadLinkRefs = (wf, dead) => {
|
|
77
|
+
if (dead.size === 0) return;
|
|
78
|
+
for (const node of wf.nodes) {
|
|
79
|
+
for (const input of node.inputs) if (input.link != null && dead.has(input.link)) input.link = null;
|
|
80
|
+
for (const output of node.outputs) output.links = output.links.filter((id) => !dead.has(id));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const expandOneInstance = (wf, instance, def) => {
|
|
84
|
+
let nextNodeId = Math.max(0, ...wf.nodes.map((n) => n.id));
|
|
85
|
+
let nextLinkId = Math.max(0, ...wf.links.map((l) => l.id));
|
|
86
|
+
const newNodeIds = /* @__PURE__ */ new Map();
|
|
87
|
+
for (const inner of def.nodes) newNodeIds.set(inner.id, ++nextNodeId);
|
|
88
|
+
const remapNodeId = (id) => newNodeIds.get(id) ?? null;
|
|
89
|
+
const defSlotOfInstanceSlot = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const [k, input] of instance.inputs.entries()) {
|
|
91
|
+
const defSlot = def.inputs.findIndex((d) => d.name === input.name);
|
|
92
|
+
if (defSlot < 0) throw new WorkflowNormalizeError("subgraph-io-mismatch", `subgraph instance ${instance.id}(${def.name}): input "${input.name}" (slot ${k}) matches no definition input (defined: ${def.inputs.map((d) => d.name).join(", ")})`);
|
|
93
|
+
defSlotOfInstanceSlot.set(k, defSlot);
|
|
94
|
+
}
|
|
95
|
+
const outerLinkIntoDefSlot = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const link of wf.links) {
|
|
97
|
+
if (link.targetId !== instance.id) continue;
|
|
98
|
+
const defSlot = defSlotOfInstanceSlot.get(link.targetSlot);
|
|
99
|
+
if (defSlot == null) throw new WorkflowNormalizeError("subgraph-io-mismatch", `subgraph instance ${instance.id}(${def.name}): link ${link.id} targets undeclared instance slot ${link.targetSlot}`);
|
|
100
|
+
outerLinkIntoDefSlot.set(defSlot, link);
|
|
101
|
+
}
|
|
102
|
+
const newLinkIds = /* @__PURE__ */ new Map();
|
|
103
|
+
const splicedLinks = [];
|
|
104
|
+
const producerByOutSlot = /* @__PURE__ */ new Map();
|
|
105
|
+
const passthroughOutSlot = /* @__PURE__ */ new Map();
|
|
106
|
+
const boundaryTargetsByInSlot = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const link of def.links) {
|
|
108
|
+
const fromInputBoundary = link.originId === SUBGRAPH_INPUT_NODE_ID;
|
|
109
|
+
const toOutputBoundary = link.targetId === SUBGRAPH_OUTPUT_NODE_ID;
|
|
110
|
+
if (fromInputBoundary && toOutputBoundary) {
|
|
111
|
+
passthroughOutSlot.set(link.targetSlot, link.originSlot);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (toOutputBoundary) {
|
|
115
|
+
const producerId = remapNodeId(link.originId);
|
|
116
|
+
if (producerId != null && !producerByOutSlot.has(link.targetSlot)) producerByOutSlot.set(link.targetSlot, {
|
|
117
|
+
nodeId: producerId,
|
|
118
|
+
slot: link.originSlot
|
|
119
|
+
});
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (fromInputBoundary) {
|
|
123
|
+
const targetId = remapNodeId(link.targetId);
|
|
124
|
+
if (targetId == null) continue;
|
|
125
|
+
const target = {
|
|
126
|
+
nodeId: targetId,
|
|
127
|
+
slot: link.targetSlot
|
|
128
|
+
};
|
|
129
|
+
const targets = boundaryTargetsByInSlot.get(link.originSlot) ?? [];
|
|
130
|
+
targets.push(target);
|
|
131
|
+
boundaryTargetsByInSlot.set(link.originSlot, targets);
|
|
132
|
+
const outer = outerLinkIntoDefSlot.get(link.originSlot);
|
|
133
|
+
if (outer == null) continue;
|
|
134
|
+
const fresh = asLiteGraphLinkID(++nextLinkId);
|
|
135
|
+
newLinkIds.set(link.id, fresh);
|
|
136
|
+
splicedLinks.push({
|
|
137
|
+
id: fresh,
|
|
138
|
+
originId: outer.originId,
|
|
139
|
+
originSlot: outer.originSlot,
|
|
140
|
+
targetId: target.nodeId,
|
|
141
|
+
targetSlot: target.slot,
|
|
142
|
+
type: link.type
|
|
143
|
+
});
|
|
144
|
+
wf.nodes.find((n) => n.id === outer.originId)?.outputs[outer.originSlot]?.links.push(fresh);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const interiorOrigin = remapNodeId(link.originId);
|
|
148
|
+
const interiorTarget = remapNodeId(link.targetId);
|
|
149
|
+
if (interiorOrigin == null || interiorTarget == null) continue;
|
|
150
|
+
const fresh = asLiteGraphLinkID(++nextLinkId);
|
|
151
|
+
newLinkIds.set(link.id, fresh);
|
|
152
|
+
splicedLinks.push({
|
|
153
|
+
id: fresh,
|
|
154
|
+
originId: interiorOrigin,
|
|
155
|
+
originSlot: link.originSlot,
|
|
156
|
+
targetId: interiorTarget,
|
|
157
|
+
targetSlot: link.targetSlot,
|
|
158
|
+
type: link.type
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const splicedNodes = def.nodes.map((inner) => ({
|
|
162
|
+
id: bang(newNodeIds.get(inner.id)),
|
|
163
|
+
type: inner.type,
|
|
164
|
+
title: inner.title,
|
|
165
|
+
mode: inner.mode,
|
|
166
|
+
isVirtualNode: inner.isVirtualNode,
|
|
167
|
+
inputs: inner.inputs.map((i) => ({
|
|
168
|
+
name: i.name,
|
|
169
|
+
type: i.type,
|
|
170
|
+
link: i.link != null ? newLinkIds.get(i.link) ?? null : null,
|
|
171
|
+
widgetName: i.widgetName
|
|
172
|
+
})),
|
|
173
|
+
outputs: inner.outputs.map((o) => ({
|
|
174
|
+
name: o.name,
|
|
175
|
+
type: o.type,
|
|
176
|
+
links: o.links.map((id) => newLinkIds.get(id)).filter((id) => id != null)
|
|
177
|
+
})),
|
|
178
|
+
widgets: {
|
|
179
|
+
positional: [...inner.widgets.positional],
|
|
180
|
+
named: { ...inner.widgets.named }
|
|
181
|
+
},
|
|
182
|
+
pos: [inner.pos[0], inner.pos[1]],
|
|
183
|
+
size: [inner.size[0], inner.size[1]],
|
|
184
|
+
properties: { ...inner.properties }
|
|
185
|
+
}));
|
|
186
|
+
const dead = /* @__PURE__ */ new Set();
|
|
187
|
+
for (const link of wf.links) {
|
|
188
|
+
if (link.targetId === instance.id) {
|
|
189
|
+
dead.add(link.id);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (link.originId !== instance.id) continue;
|
|
193
|
+
const producer = producerByOutSlot.get(link.originSlot);
|
|
194
|
+
if (producer != null) {
|
|
195
|
+
link.originId = producer.nodeId;
|
|
196
|
+
link.originSlot = producer.slot;
|
|
197
|
+
splicedNodes.find((n) => n.id === producer.nodeId)?.outputs[producer.slot]?.links.push(link.id);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const passthroughInSlot = passthroughOutSlot.get(link.originSlot);
|
|
201
|
+
const outer = passthroughInSlot != null ? outerLinkIntoDefSlot.get(passthroughInSlot) : null;
|
|
202
|
+
if (outer != null) {
|
|
203
|
+
link.originId = outer.originId;
|
|
204
|
+
link.originSlot = outer.originSlot;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
dead.add(link.id);
|
|
208
|
+
}
|
|
209
|
+
wf.links = wf.links.filter((l) => !dead.has(l.id));
|
|
210
|
+
pruneDeadLinkRefs(wf, dead);
|
|
211
|
+
promoteInstanceWidgets(instance, def, splicedNodes, newNodeIds, boundaryTargetsByInSlot);
|
|
212
|
+
wf.nodes = wf.nodes.filter((n) => n.id !== instance.id);
|
|
213
|
+
wf.nodes.push(...splicedNodes);
|
|
214
|
+
wf.links.push(...splicedLinks);
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* instance widget values land in inner nodes' `named` overrides. TWO eras for
|
|
218
|
+
* the POSITIONAL values:
|
|
219
|
+
* - proxyWidgets era: `properties.proxyWidgets` pairs [innerNodeId, widgetName]
|
|
220
|
+
* zip against the instance's positional values (incl. `control_after_generate`
|
|
221
|
+
* phantom pairs — written to `named` and simply never read, no schema input
|
|
222
|
+
* has that name).
|
|
223
|
+
* - io-widget era (no proxyWidgets): positional values zip against the def's
|
|
224
|
+
* widget-kind input slots in def order, one value per slot (no phantom —
|
|
225
|
+
* corpus-verified). An outer link into the same slot wins in the converter;
|
|
226
|
+
* the named override is still written, matching ComfyUI.
|
|
227
|
+
* PLUS, in both eras, NAMED overrides on the instance keyed by def-input name:
|
|
228
|
+
* that is how a NESTED instance receives its outer values (the previous pass
|
|
229
|
+
* wrote them to `named`), so they must forward through THIS expansion too —
|
|
230
|
+
* named wins over positional, same precedence as the converter.
|
|
231
|
+
*/
|
|
232
|
+
const promoteInstanceWidgets = (instance, def, splicedNodes, newNodeIds, boundaryTargetsByInSlot) => {
|
|
233
|
+
const promoteToSlotTargets = (slot, value) => {
|
|
234
|
+
for (const t of boundaryTargetsByInSlot.get(slot) ?? []) {
|
|
235
|
+
const target = splicedNodes.find((n) => n.id === t.nodeId);
|
|
236
|
+
const input = innerInputAt(splicedNodes, t);
|
|
237
|
+
if (target == null || input == null) continue;
|
|
238
|
+
target.widgets.named[input.name] = value;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
promotePositionalWidgets(instance, def, splicedNodes, newNodeIds, boundaryTargetsByInSlot, promoteToSlotTargets);
|
|
242
|
+
for (const [slot, io] of def.inputs.entries()) {
|
|
243
|
+
if (!Object.hasOwn(instance.widgets.named, io.name)) continue;
|
|
244
|
+
promoteToSlotTargets(slot, instance.widgets.named[io.name]);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const promotePositionalWidgets = (instance, def, splicedNodes, newNodeIds, boundaryTargetsByInSlot, promoteToSlotTargets) => {
|
|
248
|
+
const values = instance.widgets.positional;
|
|
249
|
+
if (values.length === 0) return;
|
|
250
|
+
const proxy = instance.properties["proxyWidgets"];
|
|
251
|
+
if (Array.isArray(proxy) && proxy.length > 0) {
|
|
252
|
+
const count = Math.min(values.length, proxy.length);
|
|
253
|
+
for (let k = 0; k < count; k++) {
|
|
254
|
+
const pair = proxy[k];
|
|
255
|
+
if (!Array.isArray(pair) || pair.length !== 2) throw new WorkflowNormalizeError("subgraph-io-mismatch", `subgraph instance ${instance.id}(${def.name}): malformed proxyWidgets entry ${JSON.stringify(pair)}`);
|
|
256
|
+
const innerId = Number(pair[0]);
|
|
257
|
+
const widgetName = String(pair[1]);
|
|
258
|
+
if (innerId < 0) {
|
|
259
|
+
const slot = def.inputs.findIndex((d) => d.name === widgetName);
|
|
260
|
+
if (slot < 0) throw new WorkflowNormalizeError("subgraph-io-mismatch", `subgraph instance ${instance.id}(${def.name}): proxyWidgets pair ${k} names io widget "${widgetName}" but no definition input matches`);
|
|
261
|
+
promoteToSlotTargets(slot, values[k]);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const target = splicedNodes.find((n) => n.id === newNodeIds.get(innerId));
|
|
265
|
+
if (target == null) throw new WorkflowNormalizeError("subgraph-io-mismatch", `subgraph instance ${instance.id}(${def.name}): proxyWidgets pair ${k} names unknown inner node ${String(pair[0])}`);
|
|
266
|
+
target.widgets.named[widgetName] = values[k];
|
|
267
|
+
}
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
let valueIndex = 0;
|
|
271
|
+
for (const [slot, io] of def.inputs.entries()) {
|
|
272
|
+
const targets = boundaryTargetsByInSlot.get(slot) ?? [];
|
|
273
|
+
if (!(targets.length > 0 ? targets.some((t) => innerInputAt(splicedNodes, t)?.widgetName != null) : PRIMITIVE_WIDGET_TYPES.has(io.type))) continue;
|
|
274
|
+
if (valueIndex >= values.length) break;
|
|
275
|
+
promoteToSlotTargets(slot, values[valueIndex++]);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const innerInputAt = (splicedNodes, t) => {
|
|
279
|
+
return splicedNodes.find((n) => n.id === t.nodeId)?.inputs[t.slot] ?? null;
|
|
280
|
+
};
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/litegraph/LiteGraphGroup.ts
|
|
283
|
+
const LiteGraphGroup_ark = type({
|
|
284
|
+
"id?": "number",
|
|
285
|
+
title: "string",
|
|
286
|
+
bounding: type([
|
|
287
|
+
"number",
|
|
288
|
+
"number",
|
|
289
|
+
"number",
|
|
290
|
+
"number"
|
|
291
|
+
]),
|
|
292
|
+
"color?": "string",
|
|
293
|
+
"font_size?": "number",
|
|
294
|
+
"flags?": type.Record("string", "unknown").as()
|
|
295
|
+
});
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/litegraph/LiteGraphLink.ts
|
|
298
|
+
const LiteGraphLinkTuple_ark = type([
|
|
299
|
+
LiteGraphLinkID_,
|
|
300
|
+
"number",
|
|
301
|
+
"number",
|
|
302
|
+
"number",
|
|
303
|
+
"number",
|
|
304
|
+
"string"
|
|
305
|
+
]);
|
|
306
|
+
const LiteGraphLinkObject_ark = type({
|
|
307
|
+
id: LiteGraphLinkID_,
|
|
308
|
+
origin_id: "number",
|
|
309
|
+
origin_slot: "number",
|
|
310
|
+
target_id: "number",
|
|
311
|
+
target_slot: "number",
|
|
312
|
+
type: "string",
|
|
313
|
+
"parentId?": "number"
|
|
314
|
+
});
|
|
315
|
+
const LiteGraphLink_ark = LiteGraphLinkTuple_ark.or(LiteGraphLinkObject_ark);
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/litegraph/LiteGraphNodeInput.ts
|
|
318
|
+
const LiteGraphNodeInput_ark = type({
|
|
319
|
+
name: "string",
|
|
320
|
+
type: "string",
|
|
321
|
+
"link?": LiteGraphLinkID_.or(type.null),
|
|
322
|
+
"shape?": "number",
|
|
323
|
+
"label?": "string",
|
|
324
|
+
"widget?": type({
|
|
325
|
+
name: "string",
|
|
326
|
+
"config?": "unknown"
|
|
327
|
+
})
|
|
328
|
+
});
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/litegraph/LiteGraphSlotIndex.ts
|
|
331
|
+
const asLiteGraphSlotIndex = (id) => id;
|
|
332
|
+
const LiteGraphSlotIndex_ = type.number.atLeast(0).as();
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/litegraph/LiteGraphNodeOutput.ts
|
|
335
|
+
const LiteGraphNodeOutput_ark = type({
|
|
336
|
+
name: "string",
|
|
337
|
+
type: "string",
|
|
338
|
+
"links?": LiteGraphLinkID_.array().or(type.null),
|
|
339
|
+
"shape?": "number",
|
|
340
|
+
"slot_index?": LiteGraphSlotIndex_
|
|
341
|
+
});
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/litegraph/LiteGraphNode.ts
|
|
344
|
+
const LiteGraphNode_ark = type({
|
|
345
|
+
id: "number",
|
|
346
|
+
type: "string",
|
|
347
|
+
"title?": "string",
|
|
348
|
+
"color?": "string",
|
|
349
|
+
"bgcolor?": "string",
|
|
350
|
+
pos: {
|
|
351
|
+
"0": "number",
|
|
352
|
+
"1": "number"
|
|
353
|
+
},
|
|
354
|
+
size: {
|
|
355
|
+
"0": "number",
|
|
356
|
+
"1": "number"
|
|
357
|
+
},
|
|
358
|
+
"flags?": type.Record("string", "unknown"),
|
|
359
|
+
"order?": "number",
|
|
360
|
+
"mode?": "number",
|
|
361
|
+
"inputs?": LiteGraphNodeInput_ark.array(),
|
|
362
|
+
"outputs?": LiteGraphNodeOutput_ark.array(),
|
|
363
|
+
"isVirtualNode?": "boolean",
|
|
364
|
+
"properties?": type.Record("string", "unknown"),
|
|
365
|
+
"widgets_values?": type("unknown[]").or(type.Record("string", "unknown"))
|
|
366
|
+
});
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/litegraph/LiteGraphSubgraphDef.ts
|
|
369
|
+
const LiteGraphSubgraphIO_ark = type({
|
|
370
|
+
id: "string",
|
|
371
|
+
name: "string",
|
|
372
|
+
type: "string",
|
|
373
|
+
"linkIds?": LiteGraphLinkID_.array(),
|
|
374
|
+
"label?": "string",
|
|
375
|
+
"localized_name?": "string",
|
|
376
|
+
"pos?": {
|
|
377
|
+
"0": "number",
|
|
378
|
+
"1": "number"
|
|
379
|
+
},
|
|
380
|
+
"shape?": "number"
|
|
381
|
+
});
|
|
382
|
+
const LiteGraphSubgraphDef_ark = type({
|
|
383
|
+
id: "string",
|
|
384
|
+
name: "string",
|
|
385
|
+
version: "number",
|
|
386
|
+
"state?": type.Record("string", "unknown"),
|
|
387
|
+
"revision?": "number",
|
|
388
|
+
"config?": type.Record("string", "unknown").as(),
|
|
389
|
+
"extra?": "unknown",
|
|
390
|
+
nodes: LiteGraphNode_ark.array(),
|
|
391
|
+
links: LiteGraphLinkObject_ark.array(),
|
|
392
|
+
"groups?": LiteGraphGroup_ark.array(),
|
|
393
|
+
inputNode: {
|
|
394
|
+
id: "number",
|
|
395
|
+
bounding: "number[]"
|
|
396
|
+
},
|
|
397
|
+
outputNode: {
|
|
398
|
+
id: "number",
|
|
399
|
+
bounding: "number[]"
|
|
400
|
+
},
|
|
401
|
+
inputs: LiteGraphSubgraphIO_ark.array(),
|
|
402
|
+
outputs: LiteGraphSubgraphIO_ark.array(),
|
|
403
|
+
widgets: "unknown[]"
|
|
404
|
+
});
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/litegraph/LiteGraphJSON.ts
|
|
407
|
+
const LiteGraphJSON_ark = type({
|
|
408
|
+
"id?": "string",
|
|
409
|
+
"revision?": "number",
|
|
410
|
+
"last_node_id?": "number",
|
|
411
|
+
"last_link_id?": "number",
|
|
412
|
+
"state?": type.Record("string", "unknown"),
|
|
413
|
+
nodes: LiteGraphNode_ark.array(),
|
|
414
|
+
links: LiteGraphLink_ark.array(),
|
|
415
|
+
"groups?": LiteGraphGroup_ark.array(),
|
|
416
|
+
"config?": type.Record("never", "never"),
|
|
417
|
+
"extra?": { "ds?": {
|
|
418
|
+
scale: "number",
|
|
419
|
+
offset: {
|
|
420
|
+
"0": "number",
|
|
421
|
+
"1": "number"
|
|
422
|
+
}
|
|
423
|
+
} },
|
|
424
|
+
"models?": "unknown[]",
|
|
425
|
+
"definitions?": { subgraphs: LiteGraphSubgraphDef_ark.array() },
|
|
426
|
+
"reroutes?": "unknown[]",
|
|
427
|
+
"floatingLinks?": "unknown[]",
|
|
428
|
+
version: "0.4 | 1"
|
|
429
|
+
});
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/litegraph/normalizeWorkflow.ts
|
|
432
|
+
/** a workflow JSON we cannot turn into a CanonicalWorkflow — loud, typed, never a cast */
|
|
433
|
+
var WorkflowNormalizeError = class extends Error {
|
|
434
|
+
constructor(code, message, detail) {
|
|
435
|
+
super(`[workflow ${code}] ${message}`);
|
|
436
|
+
this.code = code;
|
|
437
|
+
this.detail = detail;
|
|
438
|
+
this.name = "WorkflowNormalizeError";
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* THE one entry for foreign workflow JSON (files, clipboard, imports):
|
|
443
|
+
* tolerant ark validation, then normalization to the strict canonical shape.
|
|
444
|
+
*/
|
|
445
|
+
const parseWorkflowJson = (json) => {
|
|
446
|
+
const out = LiteGraphJSON_ark(json);
|
|
447
|
+
if (out instanceof type.errors) throw new WorkflowNormalizeError("schema-reject", out.summary, out);
|
|
448
|
+
return normalizeWorkflow(out);
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* loose wire document → strict canonical document. Defaults filled, both link
|
|
452
|
+
* eras unified, cosmetic fields dropped, subgraph definitions expanded away
|
|
453
|
+
* (see expandSubgraphs.ts — def interiors go through the SAME per-shape
|
|
454
|
+
* normalizers, they are v1 bodies).
|
|
455
|
+
*/
|
|
456
|
+
const normalizeWorkflow = (raw) => {
|
|
457
|
+
const wf = {
|
|
458
|
+
nodes: raw.nodes.map(normalizeNode),
|
|
459
|
+
links: raw.links.map(normalizeLink),
|
|
460
|
+
groups: (raw.groups ?? []).map(normalizeGroup)
|
|
461
|
+
};
|
|
462
|
+
const rawDefs = raw.definitions?.subgraphs ?? [];
|
|
463
|
+
if (rawDefs.length === 0) return wf;
|
|
464
|
+
const defs = /* @__PURE__ */ new Map();
|
|
465
|
+
for (const d of rawDefs) defs.set(d.id, normalizeSubgraphDef(d));
|
|
466
|
+
return expandSubgraphs(wf, defs);
|
|
467
|
+
};
|
|
468
|
+
const normalizeSubgraphDef = (d) => {
|
|
469
|
+
return {
|
|
470
|
+
id: d.id,
|
|
471
|
+
name: d.name,
|
|
472
|
+
inputs: d.inputs.map((io) => ({
|
|
473
|
+
name: io.name,
|
|
474
|
+
type: io.type
|
|
475
|
+
})),
|
|
476
|
+
outputs: d.outputs.map((io) => ({
|
|
477
|
+
name: io.name,
|
|
478
|
+
type: io.type
|
|
479
|
+
})),
|
|
480
|
+
nodes: d.nodes.map(normalizeNode),
|
|
481
|
+
links: d.links.map(normalizeLink)
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
const normalizeMode = (mode) => {
|
|
485
|
+
if (mode === 2) return "muted";
|
|
486
|
+
if (mode === 4) return "bypassed";
|
|
487
|
+
return "normal";
|
|
488
|
+
};
|
|
489
|
+
const normalizeNode = (n) => {
|
|
490
|
+
return {
|
|
491
|
+
id: n.id,
|
|
492
|
+
type: n.type,
|
|
493
|
+
title: n.title ?? null,
|
|
494
|
+
mode: normalizeMode(n.mode),
|
|
495
|
+
isVirtualNode: n.isVirtualNode ?? false,
|
|
496
|
+
inputs: (n.inputs ?? []).map(normalizeInput),
|
|
497
|
+
outputs: (n.outputs ?? []).map(normalizeOutput),
|
|
498
|
+
widgets: normalizeWidgetValues(n.widgets_values),
|
|
499
|
+
pos: [n.pos[0], n.pos[1]],
|
|
500
|
+
size: [n.size[0], n.size[1]],
|
|
501
|
+
properties: { ...n.properties }
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
const normalizeInput = (i) => {
|
|
505
|
+
return {
|
|
506
|
+
name: i.name,
|
|
507
|
+
type: i.type,
|
|
508
|
+
link: i.link ?? null,
|
|
509
|
+
widgetName: i.widget?.name ?? null
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
const normalizeOutput = (o) => {
|
|
513
|
+
return {
|
|
514
|
+
name: o.name,
|
|
515
|
+
type: o.type,
|
|
516
|
+
links: [...o.links ?? []]
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
const normalizeWidgetValues = (wv) => {
|
|
520
|
+
if (wv == null) return {
|
|
521
|
+
positional: [],
|
|
522
|
+
named: {}
|
|
523
|
+
};
|
|
524
|
+
if (Array.isArray(wv)) return {
|
|
525
|
+
positional: [...wv],
|
|
526
|
+
named: {}
|
|
527
|
+
};
|
|
528
|
+
return {
|
|
529
|
+
positional: [],
|
|
530
|
+
named: { ...wv }
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
const normalizeLink = (l) => {
|
|
534
|
+
if (Array.isArray(l)) return {
|
|
535
|
+
id: l[0],
|
|
536
|
+
originId: l[1],
|
|
537
|
+
originSlot: l[2],
|
|
538
|
+
targetId: l[3],
|
|
539
|
+
targetSlot: l[4],
|
|
540
|
+
type: l[5]
|
|
541
|
+
};
|
|
542
|
+
return {
|
|
543
|
+
id: l.id,
|
|
544
|
+
originId: l.origin_id,
|
|
545
|
+
originSlot: l.origin_slot,
|
|
546
|
+
targetId: l.target_id,
|
|
547
|
+
targetSlot: l.target_slot,
|
|
548
|
+
type: l.type
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
const normalizeGroup = (g) => {
|
|
552
|
+
return {
|
|
553
|
+
title: g.title,
|
|
554
|
+
bounding: [
|
|
555
|
+
g.bounding[0],
|
|
556
|
+
g.bounding[1],
|
|
557
|
+
g.bounding[2],
|
|
558
|
+
g.bounding[3]
|
|
559
|
+
],
|
|
560
|
+
color: g.color ?? "#3f789e",
|
|
561
|
+
fontSize: g.font_size ?? 24
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/runner/wsBinaryFrame.ts
|
|
566
|
+
function parseBinaryWsFrame(data) {
|
|
567
|
+
const view = new DataView(data);
|
|
568
|
+
const eventType = view.getUint32(0);
|
|
569
|
+
if (eventType === 1) {
|
|
570
|
+
const imageType = view.getUint32(4);
|
|
571
|
+
return {
|
|
572
|
+
kind: "preview",
|
|
573
|
+
bytes: new Uint8Array(data.slice(8)),
|
|
574
|
+
mime: imageType === 2 ? "image/png" : "image/jpeg",
|
|
575
|
+
metadata: null
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
if (eventType === 3) {
|
|
579
|
+
const nodeIdLen = view.getUint32(4);
|
|
580
|
+
const decoder = new TextDecoder();
|
|
581
|
+
return {
|
|
582
|
+
kind: "text",
|
|
583
|
+
nodeId: decoder.decode(data.slice(8, 8 + nodeIdLen)),
|
|
584
|
+
text: decoder.decode(data.slice(8 + nodeIdLen))
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
if (eventType === 4) {
|
|
588
|
+
const metadataLen = view.getUint32(4);
|
|
589
|
+
let metadata = null;
|
|
590
|
+
try {
|
|
591
|
+
metadata = JSON.parse(new TextDecoder().decode(data.slice(8, 8 + metadataLen)));
|
|
592
|
+
} catch {}
|
|
593
|
+
const bytes = new Uint8Array(data.slice(8 + metadataLen));
|
|
594
|
+
return {
|
|
595
|
+
kind: "preview",
|
|
596
|
+
bytes,
|
|
597
|
+
mime: bytes[0] === 137 && bytes[1] === 80 ? "image/png" : "image/jpeg",
|
|
598
|
+
metadata
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
return {
|
|
602
|
+
kind: "unknown",
|
|
603
|
+
eventType
|
|
604
|
+
};
|
|
605
|
+
}
|
|
15
606
|
//#endregion
|
|
16
607
|
//#region src/sdk-generator/Primitives.ts
|
|
17
608
|
const ComfyPrimitiveMapping = {
|
|
@@ -22,20 +613,8 @@ const ComfyPrimitiveMapping = {
|
|
|
22
613
|
};
|
|
23
614
|
const ComfyPrimitives = Object.keys(ComfyPrimitiveMapping);
|
|
24
615
|
/**
|
|
25
|
-
* when a litegraph node has
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
const howManyWidgetValuesForThisSchemaType = (input) => {
|
|
29
|
-
if (input.typeName === "INT") {
|
|
30
|
-
if (input.nameInComfy === "seed" || input.nameInComfy === "noise_seed") return 2;
|
|
31
|
-
}
|
|
32
|
-
if (input.isPrimitive) return 1;
|
|
33
|
-
if (input.typeName.startsWith("E_")) return 1;
|
|
34
|
-
return 0;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* then a litegraph node has an input entry, some convoluted logic seems to be necessary
|
|
38
|
-
* to determine how many Field_values need to be consumed for this input
|
|
616
|
+
* when a litegraph node has an input entry with a widget marker, the
|
|
617
|
+
* serialized TYPE string decides how many widgets_values it consumed in that era
|
|
39
618
|
*/
|
|
40
619
|
const howManyWidgetValuesForThisInputType = (type, nameInComfy) => {
|
|
41
620
|
if (type === "INT") {
|
|
@@ -63,94 +642,448 @@ const ComfyDefaultNodeWhenUnknown_Schema = {
|
|
|
63
642
|
output_node: false,
|
|
64
643
|
python_module: "nodes"
|
|
65
644
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
645
|
+
//#endregion
|
|
646
|
+
//#region src/sdk-generator/inputWidgetKind.ts
|
|
647
|
+
const isRecord = (x) => typeof x === "object" && x != null && !Array.isArray(x);
|
|
648
|
+
/**
|
|
649
|
+
* seed phantom: a TRUTHY `control_after_generate` adds one consumed value.
|
|
650
|
+
* The frontend creates the control widget on truthiness, and real 2026 hosts
|
|
651
|
+
* spell it as `true` OR as a string mode like `'fixed'` (PrimitiveInt.value,
|
|
652
|
+
* SeedNode.seed). When the KEY is absent (2024 era) the INT-named-seed
|
|
653
|
+
* heuristic applies.
|
|
654
|
+
*/
|
|
655
|
+
const controlConsumes = (o, typeName, name) => {
|
|
656
|
+
if (o != null && "control_after_generate" in o) return o["control_after_generate"] ? 2 : 1;
|
|
657
|
+
if (typeName === "INT" && (name === "seed" || name === "noise_seed")) return 2;
|
|
658
|
+
return 1;
|
|
659
|
+
};
|
|
660
|
+
const flattenInputSections = (inputs) => {
|
|
661
|
+
const out = [];
|
|
662
|
+
for (const section of ["required", "optional"]) {
|
|
663
|
+
const sec = inputs[section];
|
|
664
|
+
if (!isRecord(sec)) continue;
|
|
665
|
+
for (const [name, spec] of Object.entries(sec)) {
|
|
666
|
+
if (!Array.isArray(spec) || spec.length === 0) continue;
|
|
667
|
+
const t = spec[0];
|
|
668
|
+
if (typeof t !== "string" && !Array.isArray(t)) continue;
|
|
669
|
+
out.push({
|
|
670
|
+
name,
|
|
671
|
+
type: t,
|
|
672
|
+
opts: spec[1],
|
|
673
|
+
required: section === "required"
|
|
674
|
+
});
|
|
675
|
+
}
|
|
70
676
|
}
|
|
677
|
+
return out;
|
|
678
|
+
};
|
|
679
|
+
/** null when the options array is NOT the dynamic `{key, inputs}` family (then it is a plain combo) */
|
|
680
|
+
const parseDynamicOptions = (options) => {
|
|
681
|
+
if (options.length === 0) return null;
|
|
682
|
+
const out = [];
|
|
683
|
+
for (const entry of options) {
|
|
684
|
+
if (!isRecord(entry)) return null;
|
|
685
|
+
const key = entry["key"];
|
|
686
|
+
const inputs = entry["inputs"];
|
|
687
|
+
if (typeof key !== "string" || !isRecord(inputs)) return null;
|
|
688
|
+
out.push({
|
|
689
|
+
key,
|
|
690
|
+
inputs: flattenInputSections(inputs)
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
return out;
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* autogrow (`template` WITH a nested `input` section): instances are always
|
|
697
|
+
* link slots named `decl.<name_i>` (the backend force-inputs widget
|
|
698
|
+
* templates), the first `min` of them required WHEN the template input
|
|
699
|
+
* section is `required` — mirrors `_io.py Autogrow._expand_schema_for_dynamic`.
|
|
700
|
+
*/
|
|
701
|
+
const parseContainer = (template) => {
|
|
702
|
+
const input = template["input"];
|
|
703
|
+
const min = typeof template["min"] === "number" ? template["min"] : 1;
|
|
704
|
+
const prefix = typeof template["prefix"] === "string" ? template["prefix"] : "";
|
|
705
|
+
const max = typeof template["max"] === "number" ? template["max"] : 100;
|
|
706
|
+
const rawNames = template["names"];
|
|
707
|
+
const names = Array.isArray(rawNames) ? rawNames.filter((n) => typeof n === "string") : Array.from({ length: max }, (_, i) => `${prefix}${i}`);
|
|
708
|
+
return {
|
|
709
|
+
kind: "dynamic-container",
|
|
710
|
+
instanceNames: names,
|
|
711
|
+
requiredCount: isRecord(input) && isRecord(input["required"]) && Object.keys(input["required"]).length > 0 ? Math.min(min, names.length) : 0
|
|
712
|
+
};
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* the single template sub-input's slot type of an autogrow container
|
|
716
|
+
* (`'IMAGE'` for TextEncodeBooguEdit.images). null when opts are not an
|
|
717
|
+
* autogrow template or the template has several sub-inputs (corpus-absent
|
|
718
|
+
* 2026-07-30, 27/27 single on the cloud catalog) — then codegen emits no
|
|
719
|
+
* typed instance keys and the container stays builderBase territory.
|
|
720
|
+
*/
|
|
721
|
+
const containerInstanceSlotType = (opts) => {
|
|
722
|
+
const template = (isRecord(opts) ? opts : null)?.["template"];
|
|
723
|
+
if (!isRecord(template) || !isRecord(template["input"])) return null;
|
|
724
|
+
const subs = flattenInputSections(template["input"]);
|
|
725
|
+
const first = subs[0];
|
|
726
|
+
if (subs.length !== 1 || first == null || typeof first.type !== "string") return null;
|
|
727
|
+
return first.type;
|
|
728
|
+
};
|
|
729
|
+
const classifyWidgetInput = (p) => {
|
|
730
|
+
const o = isRecord(p.opts) ? p.opts : null;
|
|
731
|
+
if (o?.["forceInput"] === true) return { kind: "slot" };
|
|
732
|
+
if (Array.isArray(p.type) || p.isEnumUnion === true) {
|
|
733
|
+
const tn = typeof p.type === "string" ? p.type : "COMBO";
|
|
734
|
+
return {
|
|
735
|
+
kind: "widget",
|
|
736
|
+
consumes: controlConsumes(o, tn, p.name),
|
|
737
|
+
strictValues: true
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
if (typeof p.type !== "string") return { kind: "slot" };
|
|
741
|
+
const widgetTypeName = typeof o?.["widgetType"] === "string" ? o["widgetType"] : p.type;
|
|
742
|
+
if (ComfyPrimitiveMapping[widgetTypeName] != null) return {
|
|
743
|
+
kind: "widget",
|
|
744
|
+
consumes: controlConsumes(o, widgetTypeName, p.name),
|
|
745
|
+
strictValues: true
|
|
746
|
+
};
|
|
747
|
+
const options = o?.["options"];
|
|
748
|
+
if (Array.isArray(options)) {
|
|
749
|
+
const dynOptions = parseDynamicOptions(options);
|
|
750
|
+
if (dynOptions != null) {
|
|
751
|
+
const first = dynOptions[0];
|
|
752
|
+
if (first == null) return { kind: "slot" };
|
|
753
|
+
return {
|
|
754
|
+
kind: "dynamic-combo",
|
|
755
|
+
options: dynOptions,
|
|
756
|
+
defaultKey: typeof o?.["default"] === "string" ? o["default"] : first.key
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
return {
|
|
760
|
+
kind: "widget",
|
|
761
|
+
consumes: controlConsumes(o, p.type, p.name),
|
|
762
|
+
strictValues: true
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
const template = o?.["template"];
|
|
766
|
+
if (isRecord(template)) {
|
|
767
|
+
if (isRecord(template["input"])) return parseContainer(template);
|
|
768
|
+
return { kind: "slot" };
|
|
769
|
+
}
|
|
770
|
+
if (o?.["socketless"] === true) return {
|
|
771
|
+
kind: "widget",
|
|
772
|
+
consumes: 1,
|
|
773
|
+
strictValues: false
|
|
774
|
+
};
|
|
775
|
+
return { kind: "slot" };
|
|
776
|
+
};
|
|
777
|
+
const classifySchemaInput = (input) => classifyWidgetInput({
|
|
778
|
+
name: input.nameInComfy,
|
|
779
|
+
type: input.typeName,
|
|
780
|
+
opts: input.opts,
|
|
781
|
+
isEnumUnion: input.isEnum
|
|
782
|
+
});
|
|
783
|
+
/** how many widgets_values entries this schema input consumes (export path + positional walks) */
|
|
784
|
+
const howManyWidgetValuesForThisSchemaType = (input) => {
|
|
785
|
+
const kind = classifySchemaInput(input);
|
|
786
|
+
return kind.kind === "widget" ? kind.consumes : 0;
|
|
787
|
+
};
|
|
788
|
+
/**
|
|
789
|
+
* what ComfyUI's frontend gives a widget created with no serialized value
|
|
790
|
+
* (`getWidgetDefaultValue` semantics), used when a positional array is
|
|
791
|
+
* shorter than the schema's widget list. `null` for custom widgets — the
|
|
792
|
+
* backend accepts an explicit null but errors on an ABSENT required key.
|
|
793
|
+
*/
|
|
794
|
+
const defaultValueForWidget = (p) => {
|
|
795
|
+
const o = isRecord(p.opts) ? p.opts : null;
|
|
796
|
+
if (o != null && o["default"] !== void 0) return o["default"];
|
|
797
|
+
const widgetTypeName = typeof o?.["widgetType"] === "string" ? o["widgetType"] : p.type;
|
|
798
|
+
if (widgetTypeName === "INT" || widgetTypeName === "FLOAT") return 0;
|
|
799
|
+
if (widgetTypeName === "BOOLEAN") return false;
|
|
800
|
+
if (widgetTypeName === "STRING") return "";
|
|
801
|
+
const options = o?.["options"];
|
|
802
|
+
if (Array.isArray(options) && options.length > 0) {
|
|
803
|
+
const first = options[0];
|
|
804
|
+
if (typeof first === "string" || typeof first === "number" || typeof first === "boolean") return first;
|
|
805
|
+
}
|
|
806
|
+
if (p.enumValues != null && p.enumValues.length > 0) return p.enumValues[0];
|
|
807
|
+
return null;
|
|
71
808
|
};
|
|
72
809
|
//#endregion
|
|
73
810
|
//#region src/sdk-generator/litegraphToApiRequestPayload.ts
|
|
811
|
+
/** a canonical workflow the converter cannot turn into a prompt — the code NAMES the feature that failed */
|
|
812
|
+
var WorkflowConvertError = class extends Error {
|
|
813
|
+
constructor(code, message, node) {
|
|
814
|
+
super(`[workflow ${code}] ${message}`);
|
|
815
|
+
this.code = code;
|
|
816
|
+
this.node = node;
|
|
817
|
+
this.name = "WorkflowConvertError";
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
/**
|
|
821
|
+
* closed set: frontend-only node types that NEVER execute. PrimitiveString /
|
|
822
|
+
* PrimitiveInt / PrimitiveBoolean etc are REAL backend nodes — do not add them.
|
|
823
|
+
*/
|
|
824
|
+
const VIRTUAL_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
825
|
+
"Note",
|
|
826
|
+
"MarkdownNote",
|
|
827
|
+
"Reroute",
|
|
828
|
+
"PrimitiveNode"
|
|
829
|
+
]);
|
|
830
|
+
const isNeverExecuted = (node) => node.isVirtualNode || VIRTUAL_NODE_TYPES.has(node.type);
|
|
831
|
+
/** exact match, or `*` wildcard on either side (Reroute-style slots) */
|
|
832
|
+
/** frontend isValidConnection parity: exact, `*` wildcard, or any member of a comma-separated multi-type */
|
|
833
|
+
const linkTypeMatches = (a, b) => {
|
|
834
|
+
if (a === b || a === "*" || b === "*") return true;
|
|
835
|
+
if (!a.includes(",") && !b.includes(",")) return false;
|
|
836
|
+
const as = a.split(",");
|
|
837
|
+
const bs = b.split(",");
|
|
838
|
+
return as.some((x) => bs.includes(x));
|
|
839
|
+
};
|
|
840
|
+
/** what an inlined PrimitiveNode may contribute: scalar widget values only */
|
|
841
|
+
const isPromptScalar = (v) => v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
74
842
|
/**
|
|
75
|
-
* convert a
|
|
76
|
-
* (prompt format) ComfyUI's POST /prompt takes.
|
|
77
|
-
* Handles: muted nodes,
|
|
78
|
-
*
|
|
79
|
-
*
|
|
843
|
+
* convert a normalized workflow (CanonicalWorkflow — see parseWorkflowJson)
|
|
844
|
+
* into the api.json (prompt format) ComfyUI's POST /prompt takes.
|
|
845
|
+
* Handles: muted nodes (skipped, consumers resolve unconnected), bypassed
|
|
846
|
+
* nodes (mode 4: link resolution walks through to the first type-matching
|
|
847
|
+
* input), Note/MarkdownNote/Reroute/PrimitiveNode virtual nodes (reroutes
|
|
848
|
+
* unwrapped, primitives inlined into their consumers), widget values both
|
|
849
|
+
* positional (with the phantom `control_after_generate` offset after seeds)
|
|
850
|
+
* and named (object-form widgets_values + subgraph promotion overrides —
|
|
851
|
+
* named wins, but a live link wins over both). Widget-ness is decided from
|
|
852
|
+
* the input CONFIG (inputWidgetKind.ts): V3 string-spelled widget types
|
|
853
|
+
* (COMBO options, dynamic combos, autogrow containers, socketless customs)
|
|
854
|
+
* and 2024-era enums go through ONE classifier; a positional array shorter
|
|
855
|
+
* than the schema's widget list fills schema defaults, never throws
|
|
856
|
+
* (agent/architecture.md owns both decisions).
|
|
80
857
|
*/
|
|
81
858
|
const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
82
859
|
const prompt = {};
|
|
83
860
|
const LOG = opts.verbose ? (...args) => console.log("[🔥] converter:", ...args) : () => {};
|
|
84
861
|
const PRIMITIVE_VALUES = {};
|
|
85
|
-
for (const node of workflow.nodes)
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
PRIMITIVE_VALUES[node.id] =
|
|
862
|
+
for (const node of workflow.nodes) {
|
|
863
|
+
if (node.type !== "PrimitiveNode") continue;
|
|
864
|
+
if (node.widgets.positional.length > 0) PRIMITIVE_VALUES[node.id] = node.widgets.positional[0];
|
|
865
|
+
else if (Object.hasOwn(node.widgets.named, "value")) PRIMITIVE_VALUES[node.id] = node.widgets.named["value"];
|
|
89
866
|
}
|
|
90
867
|
for (const node of workflow.nodes) {
|
|
91
|
-
if (node
|
|
92
|
-
if (node.mode
|
|
93
|
-
if (node.type === "Reroute") continue;
|
|
94
|
-
if (node.type === "Note") continue;
|
|
95
|
-
if (node.type === "PrimitiveNode") continue;
|
|
868
|
+
if (isNeverExecuted(node)) continue;
|
|
869
|
+
if (node.mode !== "normal") continue;
|
|
96
870
|
const inputs = {};
|
|
97
|
-
const
|
|
871
|
+
const fieldNamesPresent = new Set(node.inputs.map((i) => i.name));
|
|
98
872
|
const nodeSchema_ = schema.nodesByNameInComfy[node.type];
|
|
99
|
-
if (nodeSchema_ == null) throw new
|
|
873
|
+
if (nodeSchema_ == null) throw new WorkflowConvertError("unknown-node", `node ${node.id}(${node.type}) has no schema on this host; a custom node is missing`, node);
|
|
100
874
|
const nodeSchema = nodeSchema_;
|
|
101
875
|
let offset = 0;
|
|
102
|
-
const
|
|
876
|
+
const positional = node.widgets.positional;
|
|
877
|
+
const named = node.widgets.named;
|
|
878
|
+
const widgetFallback = /* @__PURE__ */ new Map();
|
|
879
|
+
const inputsInNodeJSON = node.inputs;
|
|
103
880
|
const inputsInNodeSchema = nodeSchema.inputs;
|
|
881
|
+
/** arrays ride wrapped (a bare 2-list is a link server-side); objects pass only in lax (custom-widget) domains */
|
|
882
|
+
const toPromptValue = (value, p) => {
|
|
883
|
+
if (value == null) return null;
|
|
884
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
|
|
885
|
+
if (Array.isArray(value)) return { __value__: value };
|
|
886
|
+
if (!p.strict && isRecord(value)) return value;
|
|
887
|
+
throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}) has an invalid widget value for "${p.promptName}": ${JSON.stringify(value)}`, node);
|
|
888
|
+
};
|
|
889
|
+
/** named wins, then positional cursor; filled=true when both miss (caller falls back to the schema default) */
|
|
890
|
+
const resolveWidgetValue = (p) => {
|
|
891
|
+
let value;
|
|
892
|
+
let has = false;
|
|
893
|
+
if (Object.hasOwn(named, p.promptName)) {
|
|
894
|
+
value = named[p.promptName];
|
|
895
|
+
has = true;
|
|
896
|
+
} else if (offset < positional.length) {
|
|
897
|
+
value = positional[offset];
|
|
898
|
+
has = true;
|
|
899
|
+
}
|
|
900
|
+
if (positional.length > 0) offset += p.consumes;
|
|
901
|
+
return {
|
|
902
|
+
value,
|
|
903
|
+
filled: !has
|
|
904
|
+
};
|
|
905
|
+
};
|
|
906
|
+
const consumePlainWidget = (p) => {
|
|
907
|
+
const r = resolveWidgetValue({
|
|
908
|
+
promptName: p.promptName,
|
|
909
|
+
consumes: p.consumes
|
|
910
|
+
});
|
|
911
|
+
const raw = r.filled ? defaultValueForWidget({
|
|
912
|
+
type: p.typeName,
|
|
913
|
+
opts: p.opts,
|
|
914
|
+
enumValues: p.enumValues ?? schema.knownUnionByName.get(p.typeName)?.values
|
|
915
|
+
}) : r.value;
|
|
916
|
+
const value = toPromptValue(raw, {
|
|
917
|
+
promptName: p.promptName,
|
|
918
|
+
strict: p.strict
|
|
919
|
+
});
|
|
920
|
+
if (r.filled) LOG(`${node.type}#${node.id}.${p.promptName} = ${JSON.stringify(value)} (schema-default fill)`);
|
|
921
|
+
if (p.linkedInput?.link != null) widgetFallback.set(p.promptName, value);
|
|
922
|
+
else inputs[p.promptName] = value;
|
|
923
|
+
};
|
|
924
|
+
/** key consumed first, then the SELECTED branch inline, recursively (backend get_finalized_class_inputs) */
|
|
925
|
+
const consumeDynamicCombo = (p) => {
|
|
926
|
+
const r = resolveWidgetValue({
|
|
927
|
+
promptName: p.path,
|
|
928
|
+
consumes: 1
|
|
929
|
+
});
|
|
930
|
+
const key = r.filled ? p.defaultKey : r.value;
|
|
931
|
+
if (typeof key !== "string") throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}): dynamic combo "${p.path}" key is not a string: ${JSON.stringify(key)}`, node);
|
|
932
|
+
const opt = p.options.find((o) => o.key === key);
|
|
933
|
+
if (opt == null) throw new WorkflowConvertError("unknown-dynamic-combo-option", `node ${node.id}(${node.type}): "${key}" is not an option of dynamic combo "${p.path}" (options: ${p.options.map((o) => o.key).join(", ")})`, node);
|
|
934
|
+
if (r.filled) LOG(`${node.type}#${node.id}.${p.path} = ${key} (schema-default fill)`);
|
|
935
|
+
inputs[p.path] = key;
|
|
936
|
+
for (const sub of opt.inputs) consumeBranchInput(`${p.path}.${sub.name}`, sub);
|
|
937
|
+
};
|
|
938
|
+
const consumeBranchInput = (subPath, sub) => {
|
|
939
|
+
const kind = classifyWidgetInput({
|
|
940
|
+
name: sub.name,
|
|
941
|
+
type: sub.type,
|
|
942
|
+
opts: sub.opts
|
|
943
|
+
});
|
|
944
|
+
if (kind.kind === "slot" || kind.kind === "dynamic-container") return;
|
|
945
|
+
if (kind.kind === "dynamic-combo") return consumeDynamicCombo({
|
|
946
|
+
path: subPath,
|
|
947
|
+
options: kind.options,
|
|
948
|
+
defaultKey: kind.defaultKey
|
|
949
|
+
});
|
|
950
|
+
const inlineEnum = Array.isArray(sub.type) ? sub.type.filter((v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean") : void 0;
|
|
951
|
+
consumePlainWidget({
|
|
952
|
+
promptName: subPath,
|
|
953
|
+
typeName: typeof sub.type === "string" ? sub.type : "COMBO",
|
|
954
|
+
opts: sub.opts,
|
|
955
|
+
consumes: kind.consumes,
|
|
956
|
+
strict: kind.strictValues,
|
|
957
|
+
enumValues: inlineEnum,
|
|
958
|
+
linkedInput: inputsInNodeJSON.find((i) => i.name === subPath)
|
|
959
|
+
});
|
|
960
|
+
};
|
|
104
961
|
for (const field of inputsInNodeSchema) {
|
|
105
962
|
const input = inputsInNodeJSON.find((i) => i.name === field.nameInComfy);
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
963
|
+
let kind = classifySchemaInput(field);
|
|
964
|
+
if (kind.kind === "slot" && input?.widgetName != null) kind = {
|
|
965
|
+
kind: "widget",
|
|
966
|
+
consumes: howManyWidgetValuesForThisInputType(input.type, field.nameInComfy) === 2 ? 2 : 1,
|
|
967
|
+
strictValues: true
|
|
968
|
+
};
|
|
969
|
+
if (kind.kind === "widget") consumePlainWidget({
|
|
970
|
+
promptName: field.nameInComfy,
|
|
971
|
+
typeName: field.typeName,
|
|
972
|
+
opts: field.opts,
|
|
973
|
+
consumes: kind.consumes,
|
|
974
|
+
strict: kind.strictValues,
|
|
975
|
+
linkedInput: input
|
|
976
|
+
});
|
|
977
|
+
else if (kind.kind === "dynamic-combo") consumeDynamicCombo({
|
|
978
|
+
path: field.nameInComfy,
|
|
979
|
+
options: kind.options,
|
|
980
|
+
defaultKey: kind.defaultKey
|
|
981
|
+
});
|
|
982
|
+
else if (kind.kind === "dynamic-container") for (const instName of kind.instanceNames.slice(0, kind.requiredCount)) {
|
|
983
|
+
const iname = `${field.nameInComfy}.${instName}`;
|
|
984
|
+
if (inputsInNodeJSON.find((i) => i.name === iname)?.link == null) throw new WorkflowConvertError("missing-required-input", `node ${node.id}(${node.type}): autogrow "${field.nameInComfy}" requires instance "${iname}" connected (template.min = ${kind.requiredCount})`, node);
|
|
985
|
+
}
|
|
986
|
+
else if (!fieldNamesPresent.has(field.nameInComfy)) {
|
|
987
|
+
if (field.required) throw new WorkflowConvertError("missing-required-input", `node ${node.id}(${node.type}): required input "${field.nameInComfy}" (${field.typeName}) has neither widget value nor link`, node);
|
|
117
988
|
}
|
|
118
989
|
}
|
|
119
990
|
const getParentNode = (linkId) => {
|
|
120
|
-
const link = workflow.links.find((link) => link
|
|
121
|
-
if (link == null) throw new
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
if (parentNode == null) throw new Error(`link ${linkId} references a non-existent parent node ${parentId}`);
|
|
991
|
+
const link = workflow.links.find((link) => link.id === linkId);
|
|
992
|
+
if (link == null) throw new WorkflowConvertError("dangling-link", `node ${node.id}(${node.type}) references a non-existing link (id=${linkId})`, node);
|
|
993
|
+
const parentNode = workflow.nodes.find((n) => n.id === link.originId);
|
|
994
|
+
if (parentNode == null) throw new WorkflowConvertError("dangling-link", `link ${linkId} references a non-existent parent node ${link.originId}`, node);
|
|
125
995
|
return {
|
|
126
996
|
node: parentNode,
|
|
127
997
|
link
|
|
128
998
|
};
|
|
129
999
|
};
|
|
130
|
-
|
|
131
|
-
|
|
1000
|
+
const pickBypassInput = (p) => {
|
|
1001
|
+
const sameSlot = p.inputs[p.outSlot];
|
|
1002
|
+
if (p.consumerType === "*" || p.consumerType === "") return sameSlot ?? p.inputs[0] ?? null;
|
|
1003
|
+
if (sameSlot != null && linkTypeMatches(sameSlot.type, p.outputType) && linkTypeMatches(sameSlot.type, p.consumerType)) return sameSlot;
|
|
1004
|
+
const exact = p.inputs.find((i) => i.type === p.consumerType);
|
|
1005
|
+
if (exact != null) return exact;
|
|
1006
|
+
return p.inputs.find((i) => linkTypeMatches(i.type, p.outputType) && linkTypeMatches(i.type, p.consumerType)) ?? null;
|
|
1007
|
+
};
|
|
1008
|
+
const resolveThroughParents = (startLink, consumerType) => {
|
|
1009
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1010
|
+
let linkId = startLink;
|
|
1011
|
+
let effectiveType = consumerType;
|
|
1012
|
+
while (true) {
|
|
1013
|
+
const parent = getParentNode(linkId);
|
|
1014
|
+
if (visited.has(parent.node.id)) throw new WorkflowConvertError("dangling-link", `node ${node.id}(${node.type}): link resolution loops through node ${parent.node.id}`, node);
|
|
1015
|
+
visited.add(parent.node.id);
|
|
1016
|
+
if (parent.node.type === "Reroute") {
|
|
1017
|
+
const rerouteIn = parent.node.inputs[0]?.link;
|
|
1018
|
+
if (rerouteIn == null) return {
|
|
1019
|
+
kind: "unconnected",
|
|
1020
|
+
reason: "reroute chain ends on an empty slot"
|
|
1021
|
+
};
|
|
1022
|
+
linkId = rerouteIn;
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
if (parent.node.mode === "muted") return {
|
|
1026
|
+
kind: "unconnected",
|
|
1027
|
+
reason: `parent ${parent.node.id}(${parent.node.type}) is muted`
|
|
1028
|
+
};
|
|
1029
|
+
if (parent.node.mode === "bypassed") {
|
|
1030
|
+
const outputType = parent.node.outputs[parent.link.originSlot]?.type ?? parent.link.type;
|
|
1031
|
+
const through = pickBypassInput({
|
|
1032
|
+
inputs: parent.node.inputs,
|
|
1033
|
+
outSlot: parent.link.originSlot,
|
|
1034
|
+
outputType,
|
|
1035
|
+
consumerType: effectiveType
|
|
1036
|
+
});
|
|
1037
|
+
if (through?.link == null) return {
|
|
1038
|
+
kind: "unconnected",
|
|
1039
|
+
reason: `bypassed parent ${parent.node.id}(${parent.node.type}) has no connected ${effectiveType} input to pass through`
|
|
1040
|
+
};
|
|
1041
|
+
linkId = through.link;
|
|
1042
|
+
effectiveType = through.type;
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
1045
|
+
if (parent.node.type === "PrimitiveNode") {
|
|
1046
|
+
if (!(parent.node.id in PRIMITIVE_VALUES)) return {
|
|
1047
|
+
kind: "unconnected",
|
|
1048
|
+
reason: `PrimitiveNode#${parent.node.id} has no widget value`
|
|
1049
|
+
};
|
|
1050
|
+
return {
|
|
1051
|
+
kind: "primitive",
|
|
1052
|
+
nodeId: parent.node.id
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
return {
|
|
1056
|
+
kind: "link",
|
|
1057
|
+
nodeId: parent.node.id,
|
|
1058
|
+
slot: parent.link.originSlot
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
for (const ipt of node.inputs) {
|
|
132
1063
|
if (ipt.link == null) {
|
|
133
|
-
LOG(`${node.type}#${node.id}.${ipt.name}: empty input slot (
|
|
1064
|
+
LOG(`${node.type}#${node.id}.${ipt.name}: empty input slot (widget-backed or optional)`);
|
|
134
1065
|
continue;
|
|
135
1066
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
parent = getParentNode(firstParentInput.link);
|
|
1067
|
+
const resolved = resolveThroughParents(ipt.link, ipt.type);
|
|
1068
|
+
if (resolved.kind === "primitive") {
|
|
1069
|
+
const pv = PRIMITIVE_VALUES[resolved.nodeId];
|
|
1070
|
+
if (!isPromptScalar(pv)) throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}): PrimitiveNode#${resolved.nodeId} value is not a scalar: ${JSON.stringify(pv)}`, node);
|
|
1071
|
+
inputs[ipt.name] = pv;
|
|
1072
|
+
LOG(`${node.type}#${node.id}.${ipt.name} = ${pv} (inlined primitive)`);
|
|
1073
|
+
continue;
|
|
145
1074
|
}
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
inputs[ipt.name] =
|
|
149
|
-
LOG(`${node.type}#${node.id}.${ipt.name} = ${inputs[ipt.name]} (inlined primitive)`);
|
|
1075
|
+
if (resolved.kind === "link") {
|
|
1076
|
+
LOG(`${node.type}#${node.id}.${ipt.name} = [${resolved.nodeId}, ${resolved.slot}] (link)`);
|
|
1077
|
+
inputs[ipt.name] = [String(resolved.nodeId), resolved.slot];
|
|
150
1078
|
continue;
|
|
151
1079
|
}
|
|
152
|
-
|
|
153
|
-
|
|
1080
|
+
if (widgetFallback.has(ipt.name)) {
|
|
1081
|
+
inputs[ipt.name] = widgetFallback.get(ipt.name) ?? null;
|
|
1082
|
+
LOG(`${node.type}#${node.id}.${ipt.name} = ${inputs[ipt.name]} (widget fallback, ${resolved.reason})`);
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
if (inputsInNodeSchema.find((f) => f.nameInComfy === ipt.name)?.required) throw new WorkflowConvertError("missing-required-input", `node ${node.id}(${node.type}): required input "${ipt.name}" resolves unconnected (${resolved.reason}) and no widget value covers it`, node);
|
|
1086
|
+
LOG(`${node.type}#${node.id}.${ipt.name}: resolves unconnected (${resolved.reason})`);
|
|
154
1087
|
}
|
|
155
1088
|
prompt[String(node.id)] = {
|
|
156
1089
|
inputs,
|
|
@@ -159,14 +1092,6 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
159
1092
|
}
|
|
160
1093
|
return prompt;
|
|
161
1094
|
};
|
|
162
|
-
function isValidValue(value) {
|
|
163
|
-
if (value == null) return true;
|
|
164
|
-
if (typeof value === "string") return true;
|
|
165
|
-
if (typeof value === "number") return true;
|
|
166
|
-
if (typeof value === "boolean") return true;
|
|
167
|
-
if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number") return true;
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
1095
|
//#endregion
|
|
171
1096
|
//#region src/errors/InvalidPromptError.ts
|
|
172
1097
|
var InvalidPromptError = class extends Error {
|
|
@@ -313,7 +1238,7 @@ var ComfyNode = class ComfyNode {
|
|
|
313
1238
|
for (const i of this.$schema.inputs) {
|
|
314
1239
|
_done.add(i.nameInComfy);
|
|
315
1240
|
const value = this.serializeValue(i.nameInComfy, promptExt.inputs[i.nameInComfy]);
|
|
316
|
-
inputs[i.nameInComfy] = value;
|
|
1241
|
+
if (value !== void 0) inputs[i.nameInComfy] = value;
|
|
317
1242
|
}
|
|
318
1243
|
for (const [nameInComfy, rawVal] of Object.entries(promptExt.inputs)) {
|
|
319
1244
|
if (_done.has(nameInComfy)) continue;
|
|
@@ -515,24 +1440,6 @@ var ComfyWorkflowBuilder = class {
|
|
|
515
1440
|
}
|
|
516
1441
|
};
|
|
517
1442
|
//#endregion
|
|
518
|
-
//#region src/utils/bang.ts
|
|
519
|
-
/** assertNotNull */
|
|
520
|
-
const bang = (x, msg = "") => {
|
|
521
|
-
if (x == null) {
|
|
522
|
-
console.error(`[🔴] BANG FAILED`, msg);
|
|
523
|
-
throw new Error("bang: " + (msg ?? "no message"));
|
|
524
|
-
}
|
|
525
|
-
return x;
|
|
526
|
-
};
|
|
527
|
-
//#endregion
|
|
528
|
-
//#region src/litegraph/LiteGraphLinkID.ts
|
|
529
|
-
const asLiteGraphLinkID = (id) => id;
|
|
530
|
-
type.number.atLeast(0).as();
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region src/litegraph/LiteGraphSlotIndex.ts
|
|
533
|
-
const asLiteGraphSlotIndex = (id) => id;
|
|
534
|
-
type.number.atLeast(0).as();
|
|
535
|
-
//#endregion
|
|
536
1443
|
//#region src/litegraph/convertFlowToLiteGraphJSON.ts
|
|
537
1444
|
const convertFlowToLiteGraphJSON = (graph) => {
|
|
538
1445
|
const ctx = new LiteGraphCtx(graph);
|
|
@@ -545,7 +1452,7 @@ const convertFlowToLiteGraphJSON = (graph) => {
|
|
|
545
1452
|
const n = xx.liteGraphNode;
|
|
546
1453
|
n.pos[0] = bang(xx.comfyNode.x);
|
|
547
1454
|
n.pos[1] = bang(xx.comfyNode.y);
|
|
548
|
-
for (const o of n.outputs) o.links = ctx.links.filter((l) => l[3] === n.id && l[4] === o.slot_index).map((l) => l[0]);
|
|
1455
|
+
for (const o of n.outputs ?? []) o.links = ctx.links.filter((l) => l[3] === n.id && l[4] === o.slot_index).map((l) => l[0]);
|
|
549
1456
|
}
|
|
550
1457
|
return {
|
|
551
1458
|
last_node_id,
|
|
@@ -1027,7 +1934,7 @@ var ComfyExecution = class {
|
|
|
1027
1934
|
const promptNode = this.workflow.data.apiJson?.[promptNodeID];
|
|
1028
1935
|
const promptMeta = this.workflow.data.metadata?.[promptNodeID];
|
|
1029
1936
|
if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`);
|
|
1030
|
-
const
|
|
1937
|
+
const imgRoute = "/view?" + new URLSearchParams(comfyImageInfo).toString();
|
|
1031
1938
|
const sf = this.saveFormat;
|
|
1032
1939
|
let absPath = comfyts.resolveFromOutput(join(sf?.prefix ?? comfyImageInfo.subfolder, comfyImageInfo.filename));
|
|
1033
1940
|
if (sf?.format && sf.format !== "raw") {
|
|
@@ -1037,10 +1944,7 @@ var ComfyExecution = class {
|
|
|
1037
1944
|
mkdirSync(dirname(absPath), { recursive: true });
|
|
1038
1945
|
let img;
|
|
1039
1946
|
if (sf && sf.format !== "raw") {
|
|
1040
|
-
const buff = await (await
|
|
1041
|
-
headers: { "Content-Type": "image/png" },
|
|
1042
|
-
method: "GET"
|
|
1043
|
-
})).arrayBuffer();
|
|
1947
|
+
const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
|
|
1044
1948
|
let textChunk = {};
|
|
1045
1949
|
try {
|
|
1046
1950
|
const res = getPngMetadataFromUint8Array(new Uint8Array(buff));
|
|
@@ -1063,10 +1967,7 @@ var ComfyExecution = class {
|
|
|
1063
1967
|
}
|
|
1064
1968
|
});
|
|
1065
1969
|
} else {
|
|
1066
|
-
const buff = await (await
|
|
1067
|
-
headers: { "Content-Type": "image/png" },
|
|
1068
|
-
method: "GET"
|
|
1069
|
-
})).arrayBuffer();
|
|
1970
|
+
const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
|
|
1070
1971
|
const uint8arr = new Uint8Array(buff);
|
|
1071
1972
|
writeFileSync(absPath, uint8arr);
|
|
1072
1973
|
img = new MediaImage({
|
|
@@ -1438,9 +2339,9 @@ var ComfyWorkflow = class {
|
|
|
1438
2339
|
comfy_ts_version: comfyts.version
|
|
1439
2340
|
} }
|
|
1440
2341
|
};
|
|
1441
|
-
const
|
|
1442
|
-
const res = await fetch(promptEndpoint, {
|
|
2342
|
+
const res = await this.host.fetch("/prompt", {
|
|
1443
2343
|
method: "POST",
|
|
2344
|
+
headers: { "Content-Type": "application/json" },
|
|
1444
2345
|
body: JSON.stringify(out)
|
|
1445
2346
|
});
|
|
1446
2347
|
const promptInfo = softValidate(PromptInfo_ark, await res.json());
|
|
@@ -1711,6 +2612,15 @@ function codegenSDK(opts) {
|
|
|
1711
2612
|
for (const n of nodes) {
|
|
1712
2613
|
p(`${escapeJSKey(n.nodeKey)}: {`);
|
|
1713
2614
|
for (const i of n.inputs) {
|
|
2615
|
+
const kind = classifySchemaInput(i);
|
|
2616
|
+
if (kind.kind === "dynamic-container") {
|
|
2617
|
+
const instType = containerInstanceSlotType(i.opts);
|
|
2618
|
+
if (instType != null) kind.instanceNames.forEach((instName, ix) => {
|
|
2619
|
+
const opt = ix >= kind.requiredCount ? "?" : "";
|
|
2620
|
+
p(` ${escapeJSKey(`${i.nameInComfy}.${instName}`)}${opt}: Accepts[${JSON.stringify(instType)}]`);
|
|
2621
|
+
});
|
|
2622
|
+
continue;
|
|
2623
|
+
}
|
|
1714
2624
|
const opts_ = typeof i.opts === "string" ? null : i.opts;
|
|
1715
2625
|
let type = `Accepts[${JSON.stringify(i.typeName)}]`;
|
|
1716
2626
|
const comboOptions = i.typeName === "COMBO" && Array.isArray(opts_?.options) ? opts_.options.filter((o) => typeof o === "string" || typeof o === "number" || typeof o === "boolean") : [];
|
|
@@ -2030,9 +2940,18 @@ var ComfySchema = class {
|
|
|
2030
2940
|
comfyUnionDef: slotType
|
|
2031
2941
|
}).unionName);
|
|
2032
2942
|
else throw new Error(`invalid schema (${JSON.stringify(slotType)}) for input "${ipt.name}" in node "${nodeNameInComfy}" (type: ${typeof slotType}; expected: Array | string)`);
|
|
2943
|
+
const isAutogrowContainer = typeof slotType === "string" && classifyWidgetInput({
|
|
2944
|
+
name: ipt.name,
|
|
2945
|
+
type: slotType,
|
|
2946
|
+
opts: slotOpts
|
|
2947
|
+
}).kind === "dynamic-container";
|
|
2948
|
+
if (isAutogrowContainer) {
|
|
2949
|
+
const instType = containerInstanceSlotType(slotOpts);
|
|
2950
|
+
if (instType != null) this.knownSlotTypes.add(asComfyNodeSlotTypeName(instType));
|
|
2951
|
+
}
|
|
2033
2952
|
node.inputs.push({
|
|
2034
2953
|
slotName: inputSlotName,
|
|
2035
|
-
required: ipt.required,
|
|
2954
|
+
required: ipt.required && !isAutogrowContainer,
|
|
2036
2955
|
nameInComfy: inputNameInComfy,
|
|
2037
2956
|
nameInComfyEscaped: escapeJSKey(inputNameInComfy),
|
|
2038
2957
|
typeName: inputTypeName,
|
|
@@ -2306,8 +3225,7 @@ var ComfyManager = class {
|
|
|
2306
3225
|
}
|
|
2307
3226
|
};
|
|
2308
3227
|
this.fetchPost = async (endpoint, body, validator) => {
|
|
2309
|
-
const
|
|
2310
|
-
const response = await fetch(url, {
|
|
3228
|
+
const response = await this.host.fetch(endpoint, {
|
|
2311
3229
|
method: "POST",
|
|
2312
3230
|
headers: { "Content-Type": "application/json" },
|
|
2313
3231
|
body: JSON.stringify(body)
|
|
@@ -2318,16 +3236,14 @@ var ComfyManager = class {
|
|
|
2318
3236
|
return status;
|
|
2319
3237
|
};
|
|
2320
3238
|
this.fetchGetJSON = async (endpoint, validator) => {
|
|
2321
|
-
const
|
|
2322
|
-
const response = await fetch(url);
|
|
3239
|
+
const response = await this.host.fetch(endpoint);
|
|
2323
3240
|
if (!response.ok) throw new Error(`GET ${endpoint} failed: ${response.status} ${response.statusText}`);
|
|
2324
3241
|
const jsonResult = await response.json();
|
|
2325
3242
|
if (validator) return softValidate(validator, jsonResult);
|
|
2326
3243
|
return jsonResult;
|
|
2327
3244
|
};
|
|
2328
3245
|
this.fetchGetText = async (endopint) => {
|
|
2329
|
-
|
|
2330
|
-
return await (await fetch(url)).text();
|
|
3246
|
+
return await (await this.host.fetch(endopint)).text();
|
|
2331
3247
|
};
|
|
2332
3248
|
}
|
|
2333
3249
|
get registry() {
|
|
@@ -2345,11 +3261,10 @@ var ComfyManager = class {
|
|
|
2345
3261
|
no();
|
|
2346
3262
|
}
|
|
2347
3263
|
if (abortCtrl) abortCtrl.abort();
|
|
2348
|
-
const url = this.host.getServerHostHTTP();
|
|
2349
3264
|
abortCtrl = new AbortController();
|
|
2350
3265
|
try {
|
|
2351
3266
|
console.log(` - trying...`);
|
|
2352
|
-
await fetch(
|
|
3267
|
+
await this.host.fetch("/", { signal: abortCtrl.signal }, { apiPrefix: false });
|
|
2353
3268
|
clearInterval(interval);
|
|
2354
3269
|
yes(true);
|
|
2355
3270
|
} catch {}
|
|
@@ -2387,8 +3302,7 @@ var ComfyUploader = class {
|
|
|
2387
3302
|
if (p.type) form.set("type", p.type);
|
|
2388
3303
|
if (p.override ?? true) form.set("override", "true");
|
|
2389
3304
|
if (p.subfolder) form.set("subfolder", p.subfolder);
|
|
2390
|
-
const
|
|
2391
|
-
const resp = await fetch(uploadURL, {
|
|
3305
|
+
const resp = await this.host.fetch("/upload/image", {
|
|
2392
3306
|
method: "POST",
|
|
2393
3307
|
body: form
|
|
2394
3308
|
});
|
|
@@ -2404,6 +3318,51 @@ var ComfyUploader = class {
|
|
|
2404
3318
|
}
|
|
2405
3319
|
};
|
|
2406
3320
|
//#endregion
|
|
3321
|
+
//#region src/host/hostUrl.ts
|
|
3322
|
+
/** exactly ONE of `url` or the legacy `host`+`port` (+`https?`) spelling */
|
|
3323
|
+
function parseHostBase(p) {
|
|
3324
|
+
const hasLegacy = p.host != null || p.port != null || p.https != null;
|
|
3325
|
+
if (p.url != null && hasLegacy) throw new Error(`host '${p.id}': give either url OR host/port/https, not both spellings at once`);
|
|
3326
|
+
if (p.url == null) {
|
|
3327
|
+
if (p.host == null || p.port == null) throw new Error(`host '${p.id}': needs either url, or host AND port (got host=${p.host}, port=${p.port})`);
|
|
3328
|
+
return {
|
|
3329
|
+
scheme: p.https ? "https" : "http",
|
|
3330
|
+
host: p.host,
|
|
3331
|
+
port: p.port,
|
|
3332
|
+
basePath: ""
|
|
3333
|
+
};
|
|
3334
|
+
}
|
|
3335
|
+
let parsed;
|
|
3336
|
+
try {
|
|
3337
|
+
parsed = new URL(p.url);
|
|
3338
|
+
} catch {
|
|
3339
|
+
throw new Error(`host '${p.id}': unparseable url '${p.url}'`);
|
|
3340
|
+
}
|
|
3341
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error(`host '${p.id}': url scheme must be http or https, got '${parsed.protocol}' in '${p.url}'`);
|
|
3342
|
+
if (parsed.search !== "" || parsed.hash !== "") throw new Error(`host '${p.id}': url must be a plain base (no ?query or #hash), got '${p.url}'`);
|
|
3343
|
+
const scheme = parsed.protocol === "https:" ? "https" : "http";
|
|
3344
|
+
const port = parsed.port !== "" ? Number(parsed.port) : scheme === "https" ? 443 : 80;
|
|
3345
|
+
const basePath = parsed.pathname.replace(/\/+$/, "");
|
|
3346
|
+
return {
|
|
3347
|
+
scheme,
|
|
3348
|
+
host: parsed.hostname,
|
|
3349
|
+
port,
|
|
3350
|
+
basePath
|
|
3351
|
+
};
|
|
3352
|
+
}
|
|
3353
|
+
/** http(s) base, port omitted when it is the scheme default */
|
|
3354
|
+
function renderHttpBase(p) {
|
|
3355
|
+
return `${p.scheme}://${p.host}${renderPort(p)}${p.basePath}`;
|
|
3356
|
+
}
|
|
3357
|
+
/** ws(s) endpoint; auth NEVER rides the query string (headers own it) */
|
|
3358
|
+
function renderWsUrl(p) {
|
|
3359
|
+
return `${p.scheme === "https" ? "wss" : "ws"}://${p.host}${renderPort(p)}${p.basePath}/ws`;
|
|
3360
|
+
}
|
|
3361
|
+
function renderPort(p) {
|
|
3362
|
+
const schemeDefault = p.scheme === "https" ? 443 : 80;
|
|
3363
|
+
return p.port === schemeDefault ? "" : `:${p.port}`;
|
|
3364
|
+
}
|
|
3365
|
+
//#endregion
|
|
2407
3366
|
//#region src/host/ResilientWebsocket.ts
|
|
2408
3367
|
var ResilientWebSocketClient = class {
|
|
2409
3368
|
addInfo(msg) {
|
|
@@ -2448,7 +3407,7 @@ var ResilientWebSocketClient = class {
|
|
|
2448
3407
|
this.addInfo("Previous WebSocket discarded");
|
|
2449
3408
|
prevWS.close();
|
|
2450
3409
|
}
|
|
2451
|
-
const ws = new WebSocket(this.url);
|
|
3410
|
+
const ws = new WebSocket(this.url, { headers: this.options.headers?.() });
|
|
2452
3411
|
ws.binaryType = "arraybuffer";
|
|
2453
3412
|
this.currentWS = ws;
|
|
2454
3413
|
if (this.options.onMessage) ws.onmessage = (event) => {
|
|
@@ -2992,7 +3951,73 @@ var SizeVar = class extends ComfyVar {
|
|
|
2992
3951
|
return `${width}×${height}${hit ? ` (${hit.label})` : ""}`;
|
|
2993
3952
|
}
|
|
2994
3953
|
};
|
|
2995
|
-
|
|
3954
|
+
const DEFAULT_IMAGE_EXTENSIONS = [
|
|
3955
|
+
"png",
|
|
3956
|
+
"jpg",
|
|
3957
|
+
"jpeg",
|
|
3958
|
+
"webp",
|
|
3959
|
+
"gif"
|
|
3960
|
+
];
|
|
3961
|
+
/** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
|
|
3962
|
+
var ImageVarEmptyError = class extends Error {
|
|
3963
|
+
constructor(varName) {
|
|
3964
|
+
super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`);
|
|
3965
|
+
this.varName = varName;
|
|
3966
|
+
}
|
|
3967
|
+
};
|
|
3968
|
+
/** trim + expand a leading `~/` — every ImageVar write funnels through this */
|
|
3969
|
+
function expandUserPath(raw) {
|
|
3970
|
+
const trimmed = raw.trim();
|
|
3971
|
+
return trimmed.startsWith("~/") ? join(homedir(), trimmed.slice(2)) : trimmed;
|
|
3972
|
+
}
|
|
3973
|
+
/**
|
|
3974
|
+
* a local image path. The VALUE is a PLAIN PATH STRING — text-encodable,
|
|
3975
|
+
* drafts persist it verbatim (toJSON = the string), hand-editable in the
|
|
3976
|
+
* draft json. Empty = unset: outValue()/absPath() throw ImageVarEmptyError,
|
|
3977
|
+
* so a build never runs on a silent placeholder. The TUI opens the image
|
|
3978
|
+
* picker overlay for kind 'image'.
|
|
3979
|
+
*/
|
|
3980
|
+
var ImageVar = class extends ComfyVar {
|
|
3981
|
+
constructor(defaultValue, opts = {}) {
|
|
3982
|
+
super(expandUserPath(defaultValue), opts.label);
|
|
3983
|
+
this.opts = opts;
|
|
3984
|
+
this.kind = "image";
|
|
3985
|
+
}
|
|
3986
|
+
/** what the picker lists (lowercase, no dots) */
|
|
3987
|
+
get extensions() {
|
|
3988
|
+
return this.opts.extensions ?? DEFAULT_IMAGE_EXTENSIONS;
|
|
3989
|
+
}
|
|
3990
|
+
set(value) {
|
|
3991
|
+
return super.set(expandUserPath(value));
|
|
3992
|
+
}
|
|
3993
|
+
parse(raw) {
|
|
3994
|
+
this.set(raw);
|
|
3995
|
+
return true;
|
|
3996
|
+
}
|
|
3997
|
+
isSet() {
|
|
3998
|
+
return this.value !== "";
|
|
3999
|
+
}
|
|
4000
|
+
emptyError() {
|
|
4001
|
+
return new ImageVarEmptyError(this.name ?? this.label ?? "image");
|
|
4002
|
+
}
|
|
4003
|
+
/** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
|
|
4004
|
+
absPath() {
|
|
4005
|
+
if (!this.isSet()) throw this.emptyError();
|
|
4006
|
+
if (isAbsolute(this.value)) return this.value;
|
|
4007
|
+
return resolve(this.opts.folder ?? process.cwd(), this.value);
|
|
4008
|
+
}
|
|
4009
|
+
/** empty = unset: the build fails LOUD here (varValues calls outValue) */
|
|
4010
|
+
outValue() {
|
|
4011
|
+
if (!this.isSet()) throw this.emptyError();
|
|
4012
|
+
return this.value;
|
|
4013
|
+
}
|
|
4014
|
+
display() {
|
|
4015
|
+
if (!this.isSet()) return "(unset) pick a file";
|
|
4016
|
+
const home = homedir();
|
|
4017
|
+
return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
|
|
4018
|
+
}
|
|
4019
|
+
};
|
|
4020
|
+
/** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
|
|
2996
4021
|
const v = {
|
|
2997
4022
|
text: (defaultValue, label) => new TextVar(defaultValue, label),
|
|
2998
4023
|
prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
|
|
@@ -3002,7 +4027,8 @@ const v = {
|
|
|
3002
4027
|
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
3003
4028
|
choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
|
|
3004
4029
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
3005
|
-
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label)
|
|
4030
|
+
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label),
|
|
4031
|
+
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
|
|
3006
4032
|
};
|
|
3007
4033
|
function varValues(vars) {
|
|
3008
4034
|
const out = {};
|
|
@@ -3026,7 +4052,10 @@ var DefinedWorkflow = class {
|
|
|
3026
4052
|
this.lastWorkflow = null;
|
|
3027
4053
|
this.lastExecution = null;
|
|
3028
4054
|
this.vars = isVarsThunk(spec.vars) ? spec.vars(v) : spec.vars;
|
|
3029
|
-
for (const [, varDef] of this.entries())
|
|
4055
|
+
for (const [key, varDef] of this.entries()) {
|
|
4056
|
+
varDef.name = key;
|
|
4057
|
+
varDef.bindHost?.(this.host);
|
|
4058
|
+
}
|
|
3030
4059
|
}
|
|
3031
4060
|
/** [name, var] pairs, for drivers that enumerate the knobs */
|
|
3032
4061
|
entries() {
|
|
@@ -3058,6 +4087,17 @@ var DefinedWorkflow = class {
|
|
|
3058
4087
|
};
|
|
3059
4088
|
//#endregion
|
|
3060
4089
|
//#region src/host/ComfyHost.ts
|
|
4090
|
+
/** auth failure with a SPECIFIC meaning (per the Comfy Cloud error table):
|
|
4091
|
+
* 401 invalid/missing key · 402 insufficient credits · 429 subscription inactive
|
|
4092
|
+
* (or plain rate limiting on non-cloud hosts). The key value never appears here. */
|
|
4093
|
+
var ComfyHostAuthError = class extends Error {
|
|
4094
|
+
constructor(code, hostId, message) {
|
|
4095
|
+
super(message);
|
|
4096
|
+
this.code = code;
|
|
4097
|
+
this.hostId = hostId;
|
|
4098
|
+
this.name = "ComfyHostAuthError";
|
|
4099
|
+
}
|
|
4100
|
+
};
|
|
3061
4101
|
var ComfyHost = class {
|
|
3062
4102
|
constructor(data) {
|
|
3063
4103
|
this.data = data;
|
|
@@ -3113,7 +4153,48 @@ var ComfyHost = class {
|
|
|
3113
4153
|
return this.manager.installPlugin(customNode);
|
|
3114
4154
|
};
|
|
3115
4155
|
this.getWSUrl = () => {
|
|
3116
|
-
return
|
|
4156
|
+
return renderWsUrl(this.base);
|
|
4157
|
+
};
|
|
4158
|
+
this._apiPrefix = null;
|
|
4159
|
+
this.fetch = async (route, init = {}, p = {}) => {
|
|
4160
|
+
const base = this.getServerHostHTTP();
|
|
4161
|
+
const headers = new Headers(init.headers);
|
|
4162
|
+
for (const [k, v] of Object.entries(this.authHeaders())) headers.set(k, v);
|
|
4163
|
+
const send = (prefixed) => fetch(`${base}${prefixed ? "/api" : ""}${route}`, {
|
|
4164
|
+
...init,
|
|
4165
|
+
headers
|
|
4166
|
+
});
|
|
4167
|
+
const missed = (res) => res.status === 404 || res.status === 405;
|
|
4168
|
+
let res;
|
|
4169
|
+
if (p.apiPrefix === false) res = await send(false);
|
|
4170
|
+
else if (this._apiPrefix != null) {
|
|
4171
|
+
res = await send(this._apiPrefix);
|
|
4172
|
+
if (missed(res)) {
|
|
4173
|
+
const alt = await send(!this._apiPrefix);
|
|
4174
|
+
if (!missed(alt)) res = alt;
|
|
4175
|
+
}
|
|
4176
|
+
} else {
|
|
4177
|
+
res = await send(true);
|
|
4178
|
+
if (missed(res)) {
|
|
4179
|
+
const bare = await send(false);
|
|
4180
|
+
if (!missed(bare)) {
|
|
4181
|
+
this._apiPrefix = false;
|
|
4182
|
+
res = bare;
|
|
4183
|
+
}
|
|
4184
|
+
} else this._apiPrefix = true;
|
|
4185
|
+
}
|
|
4186
|
+
this.throwOnAuthError(res, route);
|
|
4187
|
+
return res;
|
|
4188
|
+
};
|
|
4189
|
+
this.fetchFile = async (route) => {
|
|
4190
|
+
const res = await this.fetch(route, { redirect: "manual" });
|
|
4191
|
+
if (res.status >= 300 && res.status < 400) {
|
|
4192
|
+
const location = res.headers.get("location");
|
|
4193
|
+
if (location == null) throw new Error(`GET ${route} on host '${this.data.id}' redirected (${res.status}) without a Location`);
|
|
4194
|
+
res.body?.cancel();
|
|
4195
|
+
return fetch(new URL(location, this.getServerHostHTTP()));
|
|
4196
|
+
}
|
|
4197
|
+
return res;
|
|
3117
4198
|
};
|
|
3118
4199
|
this.schemaRetrievalLogs = [];
|
|
3119
4200
|
this.resetLog = () => {
|
|
@@ -3129,7 +4210,8 @@ var ComfyHost = class {
|
|
|
3129
4210
|
return new DefinedWorkflow(this, spec);
|
|
3130
4211
|
};
|
|
3131
4212
|
this.importWorkflowJson = (json, p = {}) => {
|
|
3132
|
-
const
|
|
4213
|
+
const canonical = parseWorkflowJson(json);
|
|
4214
|
+
const apiJson = convertLiteGraphToPrompt(this.schema, canonical);
|
|
3133
4215
|
return this.importApiJson(apiJson, p);
|
|
3134
4216
|
};
|
|
3135
4217
|
this.importApiJson = (json, p = {}) => {
|
|
@@ -3169,13 +4251,12 @@ var ComfyHost = class {
|
|
|
3169
4251
|
this.schemaUpdateResult = null;
|
|
3170
4252
|
this._schemaFromCache = null;
|
|
3171
4253
|
this.postJSON_ = async (route, body) => {
|
|
3172
|
-
const
|
|
3173
|
-
for (const url of [`${base}/api${route}`, `${base}${route}`]) if ((await fetch(url, {
|
|
4254
|
+
const res = await this.fetch(route, {
|
|
3174
4255
|
method: "POST",
|
|
3175
4256
|
headers: { "Content-Type": "application/json" },
|
|
3176
4257
|
body: JSON.stringify(body)
|
|
3177
|
-
})
|
|
3178
|
-
throw new Error(`POST ${route} failed on ${
|
|
4258
|
+
});
|
|
4259
|
+
if (!res.ok) throw new Error(`POST ${route} failed on ${this.getServerHostHTTP()}: ${res.status}`);
|
|
3179
4260
|
};
|
|
3180
4261
|
this.clearQueue = () => {
|
|
3181
4262
|
return this.postJSON_("/queue", { clear: true });
|
|
@@ -3184,7 +4265,7 @@ var ComfyHost = class {
|
|
|
3184
4265
|
return this.postJSON_("/interrupt", {});
|
|
3185
4266
|
};
|
|
3186
4267
|
this.fetchRawLogs = async () => {
|
|
3187
|
-
const res = await
|
|
4268
|
+
const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
|
|
3188
4269
|
if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
|
|
3189
4270
|
const json = await res.json();
|
|
3190
4271
|
const checked = WsMsgLogsData_ark(json);
|
|
@@ -3195,25 +4276,23 @@ var ComfyHost = class {
|
|
|
3195
4276
|
return json;
|
|
3196
4277
|
};
|
|
3197
4278
|
this.subscribeLogs = async (p) => {
|
|
3198
|
-
const res = await
|
|
4279
|
+
const res = await this.fetch("/internal/logs/subscribe", {
|
|
3199
4280
|
method: "PATCH",
|
|
3200
4281
|
headers: { "Content-Type": "application/json" },
|
|
3201
4282
|
body: JSON.stringify({
|
|
3202
4283
|
enabled: p.enabled,
|
|
3203
4284
|
clientId: p.clientId
|
|
3204
4285
|
})
|
|
3205
|
-
});
|
|
4286
|
+
}, { apiPrefix: false });
|
|
3206
4287
|
if (!res.ok) throw new Error(`PATCH /internal/logs/subscribe failed: ${res.status}`);
|
|
3207
4288
|
};
|
|
3208
4289
|
this.fetchJSON_ = async (route) => {
|
|
3209
4290
|
const base = this.getServerHostHTTP();
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
}
|
|
3216
|
-
throw new Error(`GET ${route} failed on ${base} (tried /api${route} and ${route})`);
|
|
4291
|
+
const res = await this.fetch(route);
|
|
4292
|
+
if (!res.ok) throw new Error(`GET ${route} failed on ${base}: ${res.status}`);
|
|
4293
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
4294
|
+
if (!contentType.includes("json")) throw new Error(`GET ${route} on ${base} answered '${contentType || "no content-type"}' instead of json`);
|
|
4295
|
+
return await res.json();
|
|
3217
4296
|
};
|
|
3218
4297
|
this.fetchAndUpdateSchema = async () => {
|
|
3219
4298
|
try {
|
|
@@ -3256,7 +4335,9 @@ var ComfyHost = class {
|
|
|
3256
4335
|
this.onSession = null;
|
|
3257
4336
|
this.onLogs = null;
|
|
3258
4337
|
this.comfySessionId = "temp";
|
|
4338
|
+
this._unknownBinaryFrameTypes = /* @__PURE__ */ new Set();
|
|
3259
4339
|
this.status = null;
|
|
4340
|
+
this.base = parseHostBase(this.data);
|
|
3260
4341
|
/** folder where file related to the host config will be cached */
|
|
3261
4342
|
this.cacheFolder = comfyts.resolveFromHosts(this.data.id);
|
|
3262
4343
|
if (!existsSync(this.cacheFolder)) {
|
|
@@ -3282,7 +4363,19 @@ var ComfyHost = class {
|
|
|
3282
4363
|
return value;
|
|
3283
4364
|
}
|
|
3284
4365
|
getServerHostHTTP() {
|
|
3285
|
-
return
|
|
4366
|
+
return renderHttpBase(this.base);
|
|
4367
|
+
}
|
|
4368
|
+
/** extra headers + X-API-Key, for every http request AND the ws upgrade */
|
|
4369
|
+
authHeaders() {
|
|
4370
|
+
const out = {};
|
|
4371
|
+
if (this.data.headers != null) Object.assign(out, this.data.headers);
|
|
4372
|
+
if (this.data.apiKey != null) out["X-API-Key"] = this.data.apiKey;
|
|
4373
|
+
return out;
|
|
4374
|
+
}
|
|
4375
|
+
throwOnAuthError(res, route) {
|
|
4376
|
+
if (res.status === 401) throw new ComfyHostAuthError(401, this.data.id, this.data.apiKey != null ? `host '${this.data.id}': 401 on ${route} — API key invalid or expired` : `host '${this.data.id}': 401 on ${route} — host requires authentication, no apiKey configured`);
|
|
4377
|
+
if (res.status === 402) throw new ComfyHostAuthError(402, this.data.id, `host '${this.data.id}': 402 on ${route} — insufficient credits`);
|
|
4378
|
+
if (res.status === 429) throw new ComfyHostAuthError(429, this.data.id, `host '${this.data.id}': 429 on ${route} — subscription inactive or rate limited`);
|
|
3286
4379
|
}
|
|
3287
4380
|
get isConnected() {
|
|
3288
4381
|
return this.ws?.isOpen ?? false;
|
|
@@ -3298,6 +4391,7 @@ var ComfyHost = class {
|
|
|
3298
4391
|
this._readyReject = null;
|
|
3299
4392
|
}
|
|
3300
4393
|
async writeSDKToDisk() {
|
|
4394
|
+
if (this.data.sdkAutoWrite === false) return;
|
|
3301
4395
|
const comfySchemaTs = this.schema.codegenDTS({ hostId: this.data.id });
|
|
3302
4396
|
if (existsSync(this.sdkDTSPath) && readFileSync(this.sdkDTSPath, "utf-8") === comfySchemaTs) return;
|
|
3303
4397
|
await writeFileAsync(this.sdkDTSPath, comfySchemaTs, "utf-8");
|
|
@@ -3344,6 +4438,7 @@ var ComfyHost = class {
|
|
|
3344
4438
|
},
|
|
3345
4439
|
onMessage: (e) => this.onMessage(e),
|
|
3346
4440
|
url: () => this.getWSUrl(),
|
|
4441
|
+
headers: () => this.authHeaders(),
|
|
3347
4442
|
onClose: () => {
|
|
3348
4443
|
logInfo(`[👢] WEBSOCKET: closed connection to ComfyUI host ${this.data.id}`);
|
|
3349
4444
|
}
|
|
@@ -3357,8 +4452,16 @@ var ComfyHost = class {
|
|
|
3357
4452
|
this._isUpdatingSchema = v;
|
|
3358
4453
|
}
|
|
3359
4454
|
/** load the schema from .comfy-ts/hosts/<id>/ without connecting (offline workflows, fast starts).
|
|
3360
|
-
* idempotent like connect(): N co-imported modules parse the ~4MB cache once
|
|
4455
|
+
* idempotent like connect(): N co-imported modules parse the ~4MB cache once.
|
|
4456
|
+
* A MISSING cache degrades LOUDLY to the base types instead of failing the
|
|
4457
|
+
* module import (a fresh consumer project has no cache yet — the bundled
|
|
4458
|
+
* examples must still open in the TUI; run() fetches the real schema through
|
|
4459
|
+
* connect() anyway). Not memoized in that case, so a later gen/connect retries. */
|
|
3361
4460
|
loadSchemaFromCache() {
|
|
4461
|
+
if (this._schemaFromCache == null && !existsSync(this.comfyJSONPath)) {
|
|
4462
|
+
logError(`no schema cache for host '${this.data.id}' at ${this.comfyJSONPath} — continuing with base types (no node/model unions); run \`comfy-ts gen --id ${this.data.id} --host <url>\` or connect() once to create it`);
|
|
4463
|
+
return Promise.resolve();
|
|
4464
|
+
}
|
|
3362
4465
|
this._schemaFromCache ??= (async () => {
|
|
3363
4466
|
const object_info_json = comfyts.readJSON_(this.comfyJSONPath);
|
|
3364
4467
|
const embeddings_json = comfyts.readJSON_(this.embeddingsPath, []);
|
|
@@ -3389,40 +4492,23 @@ var ComfyHost = class {
|
|
|
3389
4492
|
onMessage(e) {
|
|
3390
4493
|
if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
|
|
3391
4494
|
if (e.data instanceof ArrayBuffer) {
|
|
3392
|
-
const
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
const imageBytes = buffer.slice(4);
|
|
3410
|
-
const imageBlob = new Blob([imageBytes], { type: imageMime });
|
|
3411
|
-
const imagePreview = URL.createObjectURL(imageBlob);
|
|
3412
|
-
this.latentPreview = {
|
|
3413
|
-
blob: imageBlob,
|
|
3414
|
-
url: imagePreview,
|
|
3415
|
-
receivedAt: Date.now(),
|
|
3416
|
-
promptID: this.activePromptID
|
|
3417
|
-
};
|
|
3418
|
-
this.onLatentPreview?.({
|
|
3419
|
-
bytes: new Uint8Array(imageBytes),
|
|
3420
|
-
mime: imageMime,
|
|
3421
|
-
promptID: this.activePromptID
|
|
3422
|
-
});
|
|
3423
|
-
break;
|
|
3424
|
-
}
|
|
3425
|
-
default: throw new Error(`Unknown binary websocket message of type ${eventType}`);
|
|
4495
|
+
const frame = parseBinaryWsFrame(e.data);
|
|
4496
|
+
if (frame.kind === "preview") {
|
|
4497
|
+
const imageBlob = new Blob([frame.bytes], { type: frame.mime });
|
|
4498
|
+
this.latentPreview = {
|
|
4499
|
+
blob: imageBlob,
|
|
4500
|
+
url: URL.createObjectURL(imageBlob),
|
|
4501
|
+
receivedAt: Date.now(),
|
|
4502
|
+
promptID: this.activePromptID
|
|
4503
|
+
};
|
|
4504
|
+
this.onLatentPreview?.({
|
|
4505
|
+
bytes: frame.bytes,
|
|
4506
|
+
mime: frame.mime,
|
|
4507
|
+
promptID: this.activePromptID
|
|
4508
|
+
});
|
|
4509
|
+
} else if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
|
|
4510
|
+
this._unknownBinaryFrameTypes.add(frame.eventType);
|
|
4511
|
+
console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`);
|
|
3426
4512
|
}
|
|
3427
4513
|
return;
|
|
3428
4514
|
}
|
|
@@ -3527,31 +4613,19 @@ function downloadFile(url, outputPath, logPrefix = " - ") {
|
|
|
3527
4613
|
}
|
|
3528
4614
|
//#endregion
|
|
3529
4615
|
//#region src/manager/loaders/step1_downloadComfyManagerJSONs.ts
|
|
4616
|
+
const MANAGER_RAW_BASE = "https://raw.githubusercontent.com/Comfy-Org/ComfyUI-Manager/main";
|
|
4617
|
+
const MANAGER_MIRROR_FILES = [
|
|
4618
|
+
"custom-node-list.json",
|
|
4619
|
+
"model-list.json",
|
|
4620
|
+
"extension-node-map.json",
|
|
4621
|
+
"alter-list.json",
|
|
4622
|
+
"github-stats.json"
|
|
4623
|
+
];
|
|
3530
4624
|
async function DownloadComfyManagerJSONs() {
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
await SYNC_githubStats();
|
|
3536
|
-
async function SYNC_modelList() {
|
|
3537
|
-
await downloadFile("https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json", "src/manager/json/model-list.json", `- downloading ynchronizing model-list.json...`);
|
|
3538
|
-
console.log(` saved at ${ansi.blue("src/manager/json/model-list.json")}`);
|
|
3539
|
-
}
|
|
3540
|
-
async function SYNC_customNodeList() {
|
|
3541
|
-
await downloadFile("https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json", "src/manager/json/custom-node-list.json", `- downloading synchronizing custom-node-list.json...`);
|
|
3542
|
-
console.log(` saved at ${ansi.blue("src/manager/json/custom-node-list.json")}`);
|
|
3543
|
-
}
|
|
3544
|
-
async function SYNC_extensionNodeMap() {
|
|
3545
|
-
await downloadFile("https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/extension-node-map.json", "src/manager/json/extension-node-map.json", `- downloading synchronizing extension-node-map.json...`);
|
|
3546
|
-
console.log(` saved at ${ansi.blue("src/manager/json/extension-node-map.json")}`);
|
|
3547
|
-
}
|
|
3548
|
-
async function SYNC_alterList() {
|
|
3549
|
-
await downloadFile("https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/alter-list.json", "src/manager/json/alter-list.json", `- downloading synchronizing alter-list.json...`);
|
|
3550
|
-
console.log(` saved at ${ansi.blue("src/manager/json/alter-list.json")}`);
|
|
3551
|
-
}
|
|
3552
|
-
async function SYNC_githubStats() {
|
|
3553
|
-
await downloadFile("https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/refs/heads/main/github-stats.json", "src/manager/json/github-stats.json", `- downloading ynchronizing githubStats.json...`);
|
|
3554
|
-
console.log(` saved at ${ansi.blue("src/manager/json/github-stats.json")}`);
|
|
4625
|
+
for (const file of MANAGER_MIRROR_FILES) {
|
|
4626
|
+
const dest = `src/manager/json/${file}`;
|
|
4627
|
+
await downloadFile(`${MANAGER_RAW_BASE}/${file}`, dest, `- downloading ${file}...`);
|
|
4628
|
+
console.log(` saved at ${ansi.blue(dest)}`);
|
|
3555
4629
|
}
|
|
3556
4630
|
}
|
|
3557
4631
|
//#endregion
|
|
@@ -3559,24 +4633,6 @@ async function DownloadComfyManagerJSONs() {
|
|
|
3559
4633
|
const githubRegexpV1 = /https:\/\/github.com\/(.+?)\/(.+?)\/?/;
|
|
3560
4634
|
const githubRegexpV2 = /https:\/\/github.com\/(.+?)\/([a-zA-Z0-9-_]+)?/;
|
|
3561
4635
|
//#endregion
|
|
3562
|
-
//#region src/utils/tryExtracting.ts
|
|
3563
|
-
function tryRecovering({ verbose = 0, property, hacks, onFail, onSuccess }) {
|
|
3564
|
-
if (verbose >= 2) console.log(`[🔶] trying to find a suitable value for ${property}...`);
|
|
3565
|
-
for (const hack of hacks) {
|
|
3566
|
-
if (verbose >= 2) console.log(` > trying to use ${hack.attempt}...`);
|
|
3567
|
-
const value = hack.fn();
|
|
3568
|
-
if (value != null) {
|
|
3569
|
-
if (verbose >= (hack.level ?? 1)) {
|
|
3570
|
-
if (verbose) console.log(` 🔶 recovered ${property} using ${hack.attempt}.`);
|
|
3571
|
-
}
|
|
3572
|
-
onSuccess?.(property, value);
|
|
3573
|
-
return value;
|
|
3574
|
-
}
|
|
3575
|
-
}
|
|
3576
|
-
onFail?.(property);
|
|
3577
|
-
throw new Error(`[🔶] ${property} could not be recovered`);
|
|
3578
|
-
}
|
|
3579
|
-
//#endregion
|
|
3580
4636
|
//#region src/manager/json/custom-node-list.extra.ts
|
|
3581
4637
|
const ComfyPluginExtra = [{
|
|
3582
4638
|
id: "TEMP_ComfyUI-BRIA_AI-RMBG",
|
|
@@ -3588,43 +4644,111 @@ const ComfyPluginExtra = [{
|
|
|
3588
4644
|
description: "better rembg ?"
|
|
3589
4645
|
}];
|
|
3590
4646
|
//#endregion
|
|
4647
|
+
//#region src/manager/loaders/parseReport.ts
|
|
4648
|
+
/** root shape of a manager mirror file is broken: nothing to salvage, fail loud */
|
|
4649
|
+
var ManagerParseError = class extends Error {
|
|
4650
|
+
constructor(file, detail) {
|
|
4651
|
+
super(`🔴 [manager] ${file} root shape invalid: ${detail}`);
|
|
4652
|
+
this.file = file;
|
|
4653
|
+
this.detail = detail;
|
|
4654
|
+
this.name = "ManagerParseError";
|
|
4655
|
+
}
|
|
4656
|
+
};
|
|
4657
|
+
var FileParseCounter = class {
|
|
4658
|
+
constructor(file) {
|
|
4659
|
+
this.file = file;
|
|
4660
|
+
this.total = 0;
|
|
4661
|
+
this.accepted = 0;
|
|
4662
|
+
this.skipped = /* @__PURE__ */ new Map();
|
|
4663
|
+
}
|
|
4664
|
+
ok() {
|
|
4665
|
+
this.total++;
|
|
4666
|
+
this.accepted++;
|
|
4667
|
+
}
|
|
4668
|
+
skip(reason, firstError) {
|
|
4669
|
+
this.total++;
|
|
4670
|
+
const prev = this.skipped.get(reason);
|
|
4671
|
+
if (prev == null) this.skipped.set(reason, {
|
|
4672
|
+
count: 1,
|
|
4673
|
+
firstError
|
|
4674
|
+
});
|
|
4675
|
+
else prev.count++;
|
|
4676
|
+
}
|
|
4677
|
+
};
|
|
4678
|
+
/** per-file row accounting for the manager mirror parse; printed on every registry build so upstream drift stays visible */
|
|
4679
|
+
var ManagerParseReport = class {
|
|
4680
|
+
constructor() {
|
|
4681
|
+
this.counters = [];
|
|
4682
|
+
}
|
|
4683
|
+
file(name) {
|
|
4684
|
+
const counter = new FileParseCounter(name);
|
|
4685
|
+
this.counters.push(counter);
|
|
4686
|
+
return counter;
|
|
4687
|
+
}
|
|
4688
|
+
print() {
|
|
4689
|
+
console.log(ansi.bold(`[📘 registry] parse report:`));
|
|
4690
|
+
for (const c of this.counters) {
|
|
4691
|
+
const skippedTotal = [...c.skipped.values()].reduce((acc, cur) => acc + cur.count, 0);
|
|
4692
|
+
const headline = ` ${c.file}: ${c.total} rows, ${c.accepted} accepted, ${skippedTotal} skipped`;
|
|
4693
|
+
console.log(skippedTotal === 0 ? headline : ansi.red(headline));
|
|
4694
|
+
for (const [reason, info] of c.skipped) console.log(ansi.red(` - ${reason} x${info.count}, first: ${info.firstError}`));
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
};
|
|
4698
|
+
//#endregion
|
|
3591
4699
|
//#region src/manager/types/ComfyManagerFilePluginList.ts
|
|
3592
|
-
const
|
|
4700
|
+
const ComfyManagerFilePluginListRoot_ark = type({ custom_nodes: "unknown[]" });
|
|
4701
|
+
//#endregion
|
|
4702
|
+
//#region src/manager/types/ComfyManagerPluginInfo.ts
|
|
4703
|
+
const ComfyManagerRawPluginInfo_ark = type({
|
|
3593
4704
|
author: "string",
|
|
3594
4705
|
title: type.string.as(),
|
|
3595
4706
|
reference: "string",
|
|
3596
4707
|
files: type.string.as().array(),
|
|
3597
4708
|
install_type: "string",
|
|
3598
4709
|
description: "string",
|
|
3599
|
-
id: type.string.as(),
|
|
4710
|
+
"id?": type.string.as(),
|
|
3600
4711
|
"preemptions?": "string[]",
|
|
3601
4712
|
"pip?": "string[]",
|
|
3602
4713
|
"nodename_pattern?": "string",
|
|
3603
4714
|
"apt_dependency?": "string[]",
|
|
3604
4715
|
"js_path?": "string",
|
|
3605
4716
|
"version?": "string",
|
|
3606
|
-
"tags?": "string[]"
|
|
3607
|
-
|
|
4717
|
+
"tags?": "string[]",
|
|
4718
|
+
"reference2?": "string",
|
|
4719
|
+
"category?": "string",
|
|
4720
|
+
"name?": "string",
|
|
4721
|
+
"license?": "string",
|
|
4722
|
+
"nickname?": "string",
|
|
4723
|
+
"stars?": "number",
|
|
4724
|
+
"last_update?": "string",
|
|
4725
|
+
"badges?": "string[]",
|
|
4726
|
+
"dependencies?": "string[]"
|
|
4727
|
+
});
|
|
3608
4728
|
//#endregion
|
|
3609
4729
|
//#region src/manager/loaders/step2_custom-node-list-loader.ts
|
|
3610
4730
|
const _getKnownPlugins = (DB) => {
|
|
4731
|
+
const counter = DB.report.file("custom-node-list.json");
|
|
3611
4732
|
let totalFileSeen = 0;
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
const
|
|
3615
|
-
for (const
|
|
3616
|
-
|
|
3617
|
-
plugin.title ??= tryRecoveringPluginTitle(plugin, 1);
|
|
3618
|
-
}
|
|
3619
|
-
const res = ComfyManagerFilePluginList_ark(knownPluginFile);
|
|
3620
|
-
if (DB.opts.check) {
|
|
4733
|
+
const root = ComfyManagerFilePluginListRoot_ark(JSON.parse(readFileSync("src/manager/json/custom-node-list.json", "utf8")));
|
|
4734
|
+
if (root instanceof type.errors) throw new ManagerParseError("custom-node-list.json", root.summary);
|
|
4735
|
+
const canonical = [];
|
|
4736
|
+
for (const row of root.custom_nodes) {
|
|
4737
|
+
const res = ComfyManagerRawPluginInfo_ark(row);
|
|
3621
4738
|
if (res instanceof type.errors) {
|
|
3622
|
-
|
|
3623
|
-
|
|
4739
|
+
counter.skip("schema", res.summary);
|
|
4740
|
+
continue;
|
|
4741
|
+
}
|
|
4742
|
+
const plugin = normalizePluginInfo(res);
|
|
4743
|
+
if (plugin == null) {
|
|
4744
|
+
counter.skip("id-unrecoverable", res.reference);
|
|
4745
|
+
continue;
|
|
3624
4746
|
}
|
|
4747
|
+
canonical.push(plugin);
|
|
4748
|
+
counter.ok();
|
|
3625
4749
|
}
|
|
4750
|
+
const knownPluginList = canonical.concat(ComfyPluginExtra);
|
|
3626
4751
|
for (const plugin of knownPluginList) {
|
|
3627
|
-
totalPluginSeen++;
|
|
3628
4752
|
if (DB.opts.check && DB.plugins_byTitle.has(plugin.title)) console.log(` ❌ plugin.title: "${plugin.title}" is duplicated`);
|
|
3629
4753
|
DB.plugins_byTitle.set(plugin.title, plugin);
|
|
3630
4754
|
for (const pluginURI of plugin.files) {
|
|
@@ -3635,7 +4759,7 @@ const _getKnownPlugins = (DB) => {
|
|
|
3635
4759
|
}
|
|
3636
4760
|
if (DB.opts.genTypes) {
|
|
3637
4761
|
let out1 = "";
|
|
3638
|
-
const allPluginsSortedByTitles = [...DB.plugins_byTitle.values()].sort((a, b) =>
|
|
4762
|
+
const allPluginsSortedByTitles = [...DB.plugins_byTitle.values()].sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase()));
|
|
3639
4763
|
out1 += "// prettier-ignore\n";
|
|
3640
4764
|
out1 += "export type KnownComfyPluginTitle =\n";
|
|
3641
4765
|
for (const plugin of allPluginsSortedByTitles) {
|
|
@@ -3644,7 +4768,7 @@ const _getKnownPlugins = (DB) => {
|
|
|
3644
4768
|
}
|
|
3645
4769
|
out1 += "\n";
|
|
3646
4770
|
const out1Path = "src/manager/generated/KnownComfyPluginTitle.ts";
|
|
3647
|
-
writeFileSync
|
|
4771
|
+
writeFileSync(out1Path, out1 + "\n", "utf-8");
|
|
3648
4772
|
console.log(` > generated: ${ansi.blue.underline(out1Path)}`);
|
|
3649
4773
|
let out2 = "";
|
|
3650
4774
|
const sortedFileNames = [...DB.plugins_byFile.keys()].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
|
|
@@ -3652,47 +4776,33 @@ const _getKnownPlugins = (DB) => {
|
|
|
3652
4776
|
out2 += "export type KnownComfyPluginURL =\n";
|
|
3653
4777
|
for (const fileName of sortedFileNames) out2 += ` | ${JSON.stringify(fileName)}\n`;
|
|
3654
4778
|
const out2Path = "src/manager/generated/KnownComfyPluginURL.ts";
|
|
3655
|
-
writeFileSync
|
|
4779
|
+
writeFileSync(out2Path, out2, "utf-8");
|
|
3656
4780
|
console.log(` > generated: ${ansi.blue.underline(out2Path)}`);
|
|
3657
4781
|
}
|
|
3658
4782
|
if (DB.opts.check) {
|
|
3659
|
-
console.log(` - ${
|
|
4783
|
+
console.log(` - ${knownPluginList.length} CustomNodes in file`);
|
|
3660
4784
|
console.log(` - ${DB.plugins_byTitle.size} CustomNodes registered in map`);
|
|
3661
4785
|
console.log(` - ${totalFileSeen} CustomNodes-File Seen`);
|
|
3662
4786
|
console.log(` - ${DB.plugins_byFile.size} CustomNodes-File registered in map`);
|
|
3663
4787
|
}
|
|
3664
4788
|
};
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
function tryRecoveringPluginId(plugin, verbose = 0) {
|
|
3679
|
-
return tryRecovering({
|
|
3680
|
-
property: "plugin.id",
|
|
3681
|
-
verbose,
|
|
3682
|
-
hacks: [{
|
|
3683
|
-
level: 2,
|
|
3684
|
-
attempt: "title",
|
|
3685
|
-
fn: () => plugin.title
|
|
3686
|
-
}, {
|
|
3687
|
-
attempt: "github repo name",
|
|
3688
|
-
fn: () => plugin.reference.match(githubRegexpV1)?.[2]
|
|
3689
|
-
}]
|
|
3690
|
-
});
|
|
4789
|
+
/**
|
|
4790
|
+
* raw → canonical: recover the missing `id` (absent on ~76% of upstream rows)
|
|
4791
|
+
* from the title, else the github repo name. null = unrecoverable, caller
|
|
4792
|
+
* reports and skips the row.
|
|
4793
|
+
*/
|
|
4794
|
+
function normalizePluginInfo(p) {
|
|
4795
|
+
const id = p.id ?? p.title ?? p.reference.match(githubRegexpV1)?.[2];
|
|
4796
|
+
if (id == null) return null;
|
|
4797
|
+
return {
|
|
4798
|
+
...p,
|
|
4799
|
+
id
|
|
4800
|
+
};
|
|
3691
4801
|
}
|
|
3692
4802
|
//#endregion
|
|
3693
4803
|
//#region src/manager/types/ComfyManagerPluginContentMetadata.ts
|
|
3694
4804
|
const ComfyManagerPluginContentMetadata_ark = type({
|
|
3695
|
-
title_aux: type.string.or(type.null),
|
|
4805
|
+
"title_aux?": type.string.or(type.null),
|
|
3696
4806
|
"author?": "string",
|
|
3697
4807
|
"nickname?": "string",
|
|
3698
4808
|
"description?": "string",
|
|
@@ -3706,42 +4816,37 @@ const ComfyManagerPluginContentNodeName_ark = type.string.as();
|
|
|
3706
4816
|
type("string");
|
|
3707
4817
|
//#endregion
|
|
3708
4818
|
//#region src/manager/types/ComfyManagerFilePluginContent.ts
|
|
3709
|
-
const
|
|
4819
|
+
const ComfyManagerExtensionNodeMapEntry_ark = type([ComfyManagerPluginContentNodeName_ark.array(), ComfyManagerPluginContentMetadata_ark]);
|
|
3710
4820
|
//#endregion
|
|
3711
4821
|
//#region src/manager/loaders/step3_extension-node-map-loader.ts
|
|
3712
4822
|
const _getCustomNodeRegistry = (DB) => {
|
|
4823
|
+
const counter = DB.report.file("extension-node-map.json");
|
|
3713
4824
|
let totalCustomNodeSeen = 0;
|
|
3714
|
-
const
|
|
3715
|
-
const
|
|
3716
|
-
if (
|
|
4825
|
+
const raw = JSON.parse(readFileSync("src/manager/json/extension-node-map.json", "utf8"));
|
|
4826
|
+
const root = type("Record<string, unknown>")(raw);
|
|
4827
|
+
if (root instanceof type.errors) throw new ManagerParseError("extension-node-map.json", root.summary);
|
|
4828
|
+
for (const [url, value] of Object.entries(root)) {
|
|
4829
|
+
const res = ComfyManagerExtensionNodeMapEntry_ark(value);
|
|
3717
4830
|
if (res instanceof type.errors) {
|
|
3718
|
-
|
|
3719
|
-
|
|
4831
|
+
counter.skip("schema", `${url}: ${res.summary}`);
|
|
4832
|
+
continue;
|
|
3720
4833
|
}
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
meta,
|
|
3731
|
-
plugin: confyPlugin,
|
|
3732
|
-
pythonModule: reverseEngineerWhatComfyWillSendAsPythonModuleValueOnceInstalled(confyPlugin, url, meta)
|
|
3733
|
-
};
|
|
3734
|
-
});
|
|
3735
|
-
for (const enmEntry of enmEntries) {
|
|
3736
|
-
totalCustomNodeSeen += enmEntry.comfyNodeNames.length;
|
|
3737
|
-
const plugin = enmEntry.plugin;
|
|
4834
|
+
const plugin = DB.plugins_byFile.get(url);
|
|
4835
|
+
if (plugin == null) {
|
|
4836
|
+
counter.skip("unknown-plugin-url", url);
|
|
4837
|
+
continue;
|
|
4838
|
+
}
|
|
4839
|
+
counter.ok();
|
|
4840
|
+
const comfyNodeNames = res[0];
|
|
4841
|
+
totalCustomNodeSeen += comfyNodeNames.length;
|
|
4842
|
+
const pythonModule = reverseEngineerWhatComfyWillSendAsPythonModuleValueOnceInstalled(plugin);
|
|
3738
4843
|
const nodesInPlugin = DB.customNodes_byPluginName.get(plugin.title) ?? [];
|
|
3739
4844
|
DB.customNodes_byPluginName.set(plugin.title, nodesInPlugin);
|
|
3740
|
-
for (const nodeNameInComfy of
|
|
3741
|
-
const nodeKey = toQualifiedNodeKey(
|
|
3742
|
-
const
|
|
3743
|
-
if (
|
|
3744
|
-
else
|
|
4845
|
+
for (const nodeNameInComfy of comfyNodeNames) {
|
|
4846
|
+
const nodeKey = toQualifiedNodeKey(pythonModule, nodeNameInComfy);
|
|
4847
|
+
const prevEntry = DB.plugins_byNodeKey.get(nodeKey);
|
|
4848
|
+
if (prevEntry == null) DB.plugins_byNodeKey.set(nodeKey, [plugin]);
|
|
4849
|
+
else prevEntry.push(plugin);
|
|
3745
4850
|
nodesInPlugin.push(nodeKey);
|
|
3746
4851
|
}
|
|
3747
4852
|
}
|
|
@@ -3750,23 +4855,22 @@ const _getCustomNodeRegistry = (DB) => {
|
|
|
3750
4855
|
const sortedNodeKeys = [...DB.plugins_byNodeKey.keys()].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
|
|
3751
4856
|
out += "// prettier-ignore\n";
|
|
3752
4857
|
out += "export type KnownComfyCustomNodeName =\n";
|
|
3753
|
-
for (const nodeName of sortedNodeKeys) {
|
|
3754
|
-
if (nodeName === "sd_perturbed_attention.PerturbedAttention") console.log(`[🤠] 🔴`, DB.plugins_byNodeKey.get(nodeName));
|
|
3755
|
-
out += ` | ${JSON.stringify(nodeName)}\n`;
|
|
3756
|
-
}
|
|
4858
|
+
for (const nodeName of sortedNodeKeys) out += ` | ${JSON.stringify(nodeName)}\n`;
|
|
3757
4859
|
out += "\n";
|
|
3758
4860
|
const outPath = "src/manager/generated/KnownComfyCustomNodeName.ts";
|
|
3759
4861
|
writeFileSync(outPath, out + "\n", "utf-8");
|
|
3760
4862
|
console.log(` > generated: ${ansi.blue.underline(outPath)}`);
|
|
3761
4863
|
}
|
|
3762
|
-
if (DB.opts.check)
|
|
4864
|
+
if (DB.opts.check) {
|
|
4865
|
+
console.log(` - ${totalCustomNodeSeen} CustomNodes names processed`);
|
|
4866
|
+
console.log(` - ${DB.plugins_byNodeKey.size} unique node keys registered in map`);
|
|
4867
|
+
}
|
|
3763
4868
|
};
|
|
3764
|
-
function reverseEngineerWhatComfyWillSendAsPythonModuleValueOnceInstalled(plugin
|
|
4869
|
+
function reverseEngineerWhatComfyWillSendAsPythonModuleValueOnceInstalled(plugin) {
|
|
3765
4870
|
if (plugin.id === "nodes" && plugin.reference === "https://github.com/comfyanonymous/ComfyUI") return "nodes";
|
|
3766
4871
|
const repoName = plugin.reference.match(githubRegexpV2)?.[2];
|
|
3767
4872
|
if (repoName) return `custom_nodes.${repoName}`;
|
|
3768
|
-
|
|
3769
|
-
return "🔴";
|
|
4873
|
+
return `custom_nodes.${plugin.id}`;
|
|
3770
4874
|
}
|
|
3771
4875
|
//#endregion
|
|
3772
4876
|
//#region src/manager/json/model-list.extra.ts
|
|
@@ -3790,6 +4894,9 @@ const extraModels = { models: [{
|
|
|
3790
4894
|
url: "https://huggingface.co/gemasai/4x_NMKD-Siax_200k/resolve/main/4xRealWebPhoto_v4_dat2.pth"
|
|
3791
4895
|
}] };
|
|
3792
4896
|
//#endregion
|
|
4897
|
+
//#region src/manager/types/ComfyManagerFileModelInfo.ts
|
|
4898
|
+
const ComfyManagerFileModelInfoRoot_ark = type({ models: "unknown[]" });
|
|
4899
|
+
//#endregion
|
|
3793
4900
|
//#region src/manager/types/ComfyManagerModelInfo.ts
|
|
3794
4901
|
const ComfyManagerModelInfo_ark = type({
|
|
3795
4902
|
name: type.string.as(),
|
|
@@ -3805,20 +4912,21 @@ const ComfyManagerModelInfo_ark = type({
|
|
|
3805
4912
|
//#endregion
|
|
3806
4913
|
//#region src/manager/loaders/step4_model-list-loader.ts
|
|
3807
4914
|
const _getKnownModels = (DB) => {
|
|
3808
|
-
const
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
printArkResultInConsole(errors);
|
|
3818
|
-
hasErrors = true;
|
|
3819
|
-
}
|
|
4915
|
+
const counter = DB.report.file("model-list.json");
|
|
4916
|
+
const root = ComfyManagerFileModelInfoRoot_ark(JSON.parse(readFileSync("src/manager/json/model-list.json", "utf8")));
|
|
4917
|
+
if (root instanceof type.errors) throw new ManagerParseError("model-list.json", root.summary);
|
|
4918
|
+
const canonical = [];
|
|
4919
|
+
for (const row of root.models) {
|
|
4920
|
+
const res = ComfyManagerModelInfo_ark(row);
|
|
4921
|
+
if (res instanceof type.errors) {
|
|
4922
|
+
counter.skip("schema", res.summary);
|
|
4923
|
+
continue;
|
|
3820
4924
|
}
|
|
4925
|
+
canonical.push(res);
|
|
4926
|
+
counter.ok();
|
|
3821
4927
|
}
|
|
4928
|
+
const knownModelList = canonical.concat(extraModels.models);
|
|
4929
|
+
for (const modelInfo of knownModelList) DB.knownModels.set(modelInfo.name, modelInfo);
|
|
3822
4930
|
if (DB.opts.genTypes) {
|
|
3823
4931
|
let out1 = "";
|
|
3824
4932
|
const uniqCategories = knownModelList.reduce((acc, cur) => {
|
|
@@ -3834,7 +4942,7 @@ const _getKnownModels = (DB) => {
|
|
|
3834
4942
|
for (const [cat, count] of Object.entries(uniqCategories)) out1 += ` ${JSON.stringify(cat).padEnd(20)}, // x ${count.toString().padStart(3)}\n`;
|
|
3835
4943
|
out1 += "]\n";
|
|
3836
4944
|
const out1Path = "src/manager/generated/KnownModel_Type.ts";
|
|
3837
|
-
writeFileSync
|
|
4945
|
+
writeFileSync(out1Path, out1 + "\n", "utf-8");
|
|
3838
4946
|
console.log(` > generated: ${ansi.blue.underline(out1Path)}`);
|
|
3839
4947
|
let out4 = "";
|
|
3840
4948
|
const uniqSavePath = knownModelList.reduce((acc, cur) => {
|
|
@@ -3850,7 +4958,7 @@ const _getKnownModels = (DB) => {
|
|
|
3850
4958
|
for (const [cat, count] of Object.entries(uniqSavePath)) out4 += ` ${JSON.stringify(cat).padEnd(50)}, // x ${count.toString().padStart(3)}\n`;
|
|
3851
4959
|
out4 += "]\n";
|
|
3852
4960
|
const out4Path = "src/manager/generated/KnownModel_SavePath.ts";
|
|
3853
|
-
writeFileSync
|
|
4961
|
+
writeFileSync(out4Path, out4 + "\n", "utf-8");
|
|
3854
4962
|
console.log(` > generated: ${ansi.blue.underline(out4Path)}`);
|
|
3855
4963
|
let out2 = "";
|
|
3856
4964
|
const uniqBases = knownModelList.reduce((acc, cur) => {
|
|
@@ -3867,7 +4975,7 @@ const _getKnownModels = (DB) => {
|
|
|
3867
4975
|
for (const [cat, count] of Object.entries(uniqBases)) out2 += ` ${JSON.stringify(cat).padEnd(20)}, // x ${count.toString().padStart(3)}\n`;
|
|
3868
4976
|
out2 += "]\n";
|
|
3869
4977
|
const out2Path = "src/manager/generated/KnownModel_Base.ts";
|
|
3870
|
-
writeFileSync
|
|
4978
|
+
writeFileSync(out2Path, out2 + "\n", "utf-8");
|
|
3871
4979
|
console.log(` > generated: ${ansi.blue.underline(out2Path)}`);
|
|
3872
4980
|
let out3 = "";
|
|
3873
4981
|
const sortedModels = knownModelList.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
@@ -3882,7 +4990,7 @@ const _getKnownModels = (DB) => {
|
|
|
3882
4990
|
}
|
|
3883
4991
|
out3 += "\n";
|
|
3884
4992
|
const out3Path = "src/manager/generated/KnownModel_Name.ts";
|
|
3885
|
-
writeFileSync
|
|
4993
|
+
writeFileSync(out3Path, out3 + "\n", "utf-8");
|
|
3886
4994
|
console.log(` > generated: ${ansi.blue.underline(out3Path)}`);
|
|
3887
4995
|
let out99 = "";
|
|
3888
4996
|
out99 += `// prettier-ignore\n`;
|
|
@@ -3896,20 +5004,78 @@ const _getKnownModels = (DB) => {
|
|
|
3896
5004
|
}
|
|
3897
5005
|
out99 += "\n";
|
|
3898
5006
|
const out99Path = "src/manager/generated/KnownModel_FileName.ts";
|
|
3899
|
-
writeFileSync
|
|
5007
|
+
writeFileSync(out99Path, out99 + "\n", "utf-8");
|
|
3900
5008
|
console.log(` > generated: ${ansi.blue.underline(out99Path)}`);
|
|
3901
5009
|
}
|
|
3902
5010
|
if (DB.opts.check) {
|
|
3903
5011
|
console.log(`${knownModelList.length} models found`);
|
|
3904
5012
|
console.log(`${DB.knownModels.size} models registered map`);
|
|
3905
5013
|
if (knownModelList.length !== DB.knownModels.size) console.log(`❌ some models are either duplicated or have overlapping indexing keys`);
|
|
3906
|
-
|
|
3907
|
-
|
|
5014
|
+
}
|
|
5015
|
+
};
|
|
5016
|
+
//#endregion
|
|
5017
|
+
//#region src/manager/types/ComfyManagerAlterInfo.ts
|
|
5018
|
+
const ComfyManagerAlterInfo_ark = type({
|
|
5019
|
+
id: "string",
|
|
5020
|
+
tags: "string",
|
|
5021
|
+
description: "string"
|
|
5022
|
+
});
|
|
5023
|
+
const ComfyManagerFileAlterListRoot_ark = type({ items: "unknown[]" });
|
|
5024
|
+
//#endregion
|
|
5025
|
+
//#region src/manager/loaders/step5_alter-list-loader.ts
|
|
5026
|
+
const _getAlterList = (DB) => {
|
|
5027
|
+
const counter = DB.report.file("alter-list.json");
|
|
5028
|
+
const root = ComfyManagerFileAlterListRoot_ark(JSON.parse(readFileSync("src/manager/json/alter-list.json", "utf8")));
|
|
5029
|
+
if (root instanceof type.errors) throw new ManagerParseError("alter-list.json", root.summary);
|
|
5030
|
+
const canonical = [];
|
|
5031
|
+
for (const row of root.items) {
|
|
5032
|
+
const res = ComfyManagerAlterInfo_ark(row);
|
|
5033
|
+
if (res instanceof type.errors) {
|
|
5034
|
+
counter.skip("schema", res.summary);
|
|
5035
|
+
continue;
|
|
5036
|
+
}
|
|
5037
|
+
canonical.push(res);
|
|
5038
|
+
counter.ok();
|
|
5039
|
+
}
|
|
5040
|
+
DB.alterations = canonical;
|
|
5041
|
+
};
|
|
5042
|
+
//#endregion
|
|
5043
|
+
//#region src/manager/types/ComfyManagerGithubStats.ts
|
|
5044
|
+
const ComfyManagerGithubStatEntry_ark = type({
|
|
5045
|
+
stars: "number",
|
|
5046
|
+
last_update: "string",
|
|
5047
|
+
author_account_age_days: "number"
|
|
5048
|
+
});
|
|
5049
|
+
//#endregion
|
|
5050
|
+
//#region src/manager/loaders/step6_github-stats-loader.ts
|
|
5051
|
+
const _getGithubStats = (DB) => {
|
|
5052
|
+
const counter = DB.report.file("github-stats.json");
|
|
5053
|
+
const raw = JSON.parse(readFileSync("src/manager/json/github-stats.json", "utf8"));
|
|
5054
|
+
const root = type("Record<string, unknown>")(raw);
|
|
5055
|
+
if (root instanceof type.errors) throw new ManagerParseError("github-stats.json", root.summary);
|
|
5056
|
+
for (const [url, value] of Object.entries(root)) {
|
|
5057
|
+
const res = ComfyManagerGithubStatEntry_ark(value);
|
|
5058
|
+
if (res instanceof type.errors) {
|
|
5059
|
+
counter.skip("schema", `${url}: ${res.summary}`);
|
|
5060
|
+
continue;
|
|
5061
|
+
}
|
|
5062
|
+
DB.githubStats.set(url, res);
|
|
5063
|
+
counter.ok();
|
|
3908
5064
|
}
|
|
3909
5065
|
};
|
|
3910
5066
|
//#endregion
|
|
3911
5067
|
//#region src/manager/ComfyRegistry.ts
|
|
3912
5068
|
const log = (...args) => console.log(`[📘 registry]`, ...args);
|
|
5069
|
+
const BUILTIN_URL = "https://github.com/comfyanonymous/ComfyUI";
|
|
5070
|
+
const BUILTIN_PLUGIN = {
|
|
5071
|
+
id: "nodes",
|
|
5072
|
+
author: "comfyanonymous",
|
|
5073
|
+
description: "built-in",
|
|
5074
|
+
title: "built-in",
|
|
5075
|
+
files: [BUILTIN_URL],
|
|
5076
|
+
reference: "https://github.com/comfyanonymous/ComfyUI",
|
|
5077
|
+
install_type: ""
|
|
5078
|
+
};
|
|
3913
5079
|
var ComfyRegistry = class ComfyRegistry {
|
|
3914
5080
|
static async DownloadAndUpdate(download) {
|
|
3915
5081
|
if (download) {
|
|
@@ -3929,6 +5095,9 @@ var ComfyRegistry = class ComfyRegistry {
|
|
|
3929
5095
|
this.plugins_byNodeKey = /* @__PURE__ */ new Map();
|
|
3930
5096
|
this.customNodes_byPluginName = /* @__PURE__ */ new Map();
|
|
3931
5097
|
this.knownModels = /* @__PURE__ */ new Map();
|
|
5098
|
+
this.alterations = [];
|
|
5099
|
+
this.githubStats = /* @__PURE__ */ new Map();
|
|
5100
|
+
this.report = new ManagerParseReport();
|
|
3932
5101
|
this.getKnownCheckpoints = () => {
|
|
3933
5102
|
return [...this.knownModels.values()].filter((i) => i.type === "checkpoint");
|
|
3934
5103
|
};
|
|
@@ -3968,21 +5137,19 @@ var ComfyRegistry = class ComfyRegistry {
|
|
|
3968
5137
|
nix: isUnderPrefix ? nixPath.slice(nixPrefix.length) : mi.filename
|
|
3969
5138
|
};
|
|
3970
5139
|
};
|
|
3971
|
-
this.
|
|
3972
|
-
|
|
3973
|
-
author: "comfyanonymous",
|
|
3974
|
-
description: "built-in",
|
|
3975
|
-
title: "built-in",
|
|
3976
|
-
files: [],
|
|
3977
|
-
reference: "https://github.com/comfyanonymous/ComfyUI",
|
|
3978
|
-
install_type: ""
|
|
3979
|
-
});
|
|
5140
|
+
this.plugins_byTitle.set(BUILTIN_PLUGIN.title, BUILTIN_PLUGIN);
|
|
5141
|
+
this.plugins_byFile.set(BUILTIN_URL, BUILTIN_PLUGIN);
|
|
3980
5142
|
log(`loading src/manager/json/${ansi.yellow("custom-node-list.json")}...`);
|
|
3981
5143
|
_getKnownPlugins(this);
|
|
3982
5144
|
log(`loading src/manager/json/${ansi.yellow("extension-node-map.json")}...`);
|
|
3983
5145
|
_getCustomNodeRegistry(this);
|
|
3984
5146
|
log(`loading src/manager/json/${ansi.yellow("model-list.json")}...`);
|
|
3985
5147
|
_getKnownModels(this);
|
|
5148
|
+
log(`loading src/manager/json/${ansi.yellow("alter-list.json")}...`);
|
|
5149
|
+
_getAlterList(this);
|
|
5150
|
+
log(`loading src/manager/json/${ansi.yellow("github-stats.json")}...`);
|
|
5151
|
+
_getGithubStats(this);
|
|
5152
|
+
this.report.print();
|
|
3986
5153
|
}
|
|
3987
5154
|
};
|
|
3988
5155
|
//#endregion
|
|
@@ -4029,7 +5196,11 @@ var ComfyTS = class ComfyTS {
|
|
|
4029
5196
|
host(data) {
|
|
4030
5197
|
const existing = this.hosts.get(data.id);
|
|
4031
5198
|
if (existing != null) {
|
|
4032
|
-
|
|
5199
|
+
const incoming = parseHostBase(data);
|
|
5200
|
+
const cur = existing.base;
|
|
5201
|
+
const sameBase = cur.scheme === incoming.scheme && cur.host === incoming.host && cur.port === incoming.port && cur.basePath === incoming.basePath;
|
|
5202
|
+
const sameAuth = existing.data.apiKey == null === (data.apiKey == null);
|
|
5203
|
+
if (!sameBase || !sameAuth) throw new Error(`host id '${data.id}' already registered at ${renderHttpBase(cur)}${existing.data.apiKey != null ? " (authed)" : ""} — refusing ${renderHttpBase(incoming)}${data.apiKey != null ? " (authed)" : ""}`);
|
|
4033
5204
|
return existing;
|
|
4034
5205
|
}
|
|
4035
5206
|
const created = new ComfyHost(data);
|
|
@@ -4070,6 +5241,52 @@ var ComfyTS = class ComfyTS {
|
|
|
4070
5241
|
}
|
|
4071
5242
|
};
|
|
4072
5243
|
//#endregion
|
|
5244
|
+
//#region src/exampleAssets.ts
|
|
5245
|
+
/**
|
|
5246
|
+
* the examples/ folder shipped in the npm tarball, resolved from THIS module's
|
|
5247
|
+
* own location (NEVER cwd): walking up to the nearest NAMED package.json finds
|
|
5248
|
+
* <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from
|
|
5249
|
+
* this repo's src/. Returns null when the examples are absent (a consumer may
|
|
5250
|
+
* prune the folder) or when the nearest named package is not comfy-ts (the lib
|
|
5251
|
+
* was inlined into someone else's bundle — its examples are not on disk); no
|
|
5252
|
+
* package.json all the way up is a broken install and throws.
|
|
5253
|
+
*/
|
|
5254
|
+
function bundledExamplesDir(moduleUrl = import.meta.url) {
|
|
5255
|
+
let dir = dirname(fileURLToPath(moduleUrl));
|
|
5256
|
+
let prev = "";
|
|
5257
|
+
while (dir !== prev) {
|
|
5258
|
+
const pkgPath = join(dir, "package.json");
|
|
5259
|
+
if (existsSync(pkgPath)) {
|
|
5260
|
+
let pkg = {};
|
|
5261
|
+
try {
|
|
5262
|
+
pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
5263
|
+
} catch {}
|
|
5264
|
+
if (pkg.name === "comfy-ts") {
|
|
5265
|
+
const examples = join(dir, "examples");
|
|
5266
|
+
return existsSync(examples) ? examples : null;
|
|
5267
|
+
}
|
|
5268
|
+
if (pkg.name != null) return null;
|
|
5269
|
+
}
|
|
5270
|
+
prev = dir;
|
|
5271
|
+
dir = dirname(dir);
|
|
5272
|
+
}
|
|
5273
|
+
throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`);
|
|
5274
|
+
}
|
|
5275
|
+
/**
|
|
5276
|
+
* absolute path of a bundled `examples/images/` input image, e.g.
|
|
5277
|
+
* `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
|
|
5278
|
+
* i2i/i2v example image vars, valid from this repo AND from a consumer's
|
|
5279
|
+
* node_modules/comfy-ts/. Loud throw naming the path when the file is missing
|
|
5280
|
+
* or the package's examples/ folder was pruned.
|
|
5281
|
+
*/
|
|
5282
|
+
function exampleImagePath(name) {
|
|
5283
|
+
const examples = bundledExamplesDir();
|
|
5284
|
+
if (examples == null) throw new Error(`[comfy-ts] cannot resolve bundled example image '${name}': the package's examples/ folder is not on disk`);
|
|
5285
|
+
const abs = join(examples, "images", name);
|
|
5286
|
+
if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example image not found: ${abs}`);
|
|
5287
|
+
return abs;
|
|
5288
|
+
}
|
|
5289
|
+
//#endregion
|
|
4073
5290
|
//#region src/cli/tui-env.ts
|
|
4074
5291
|
const COMFY_TS_TUI_ENV = "COMFY_TS_TUI";
|
|
4075
5292
|
function isTuiActive() {
|
|
@@ -4088,6 +5305,6 @@ function loraTag(name, strength = 1, clipStrength) {
|
|
|
4088
5305
|
return clipStrength == null ? `<lora:${name}:${strength}>` : `<lora:${name}:${strength}:${clipStrength}>`;
|
|
4089
5306
|
}
|
|
4090
5307
|
//#endregion
|
|
4091
|
-
export { ChoiceVar, ComfyExecution, ComfyHost, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_SIZE_PRESETS, DefinedWorkflow, FloatVar, IntVar, InvalidPromptError, LorasVar, MediaImage, PromptVar, ResilientWebSocketClient, SeedVar, SizeVar, TextVar, ToggleVar, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, resultFailure, resultSuccess, setLoraKeyword, v };
|
|
5308
|
+
export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, PromptVar, ResilientWebSocketClient, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, exampleImagePath, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setLoraKeyword, v };
|
|
4092
5309
|
|
|
4093
5310
|
//# sourceMappingURL=index.js.map
|