comfy-ts 2.17.1 → 2.18.1
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/dist/cli.js +3 -3
- package/dist/index.cjs +1078 -190
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1185 -410
- package/dist/index.d.ts +1185 -410
- package/dist/index.js +1078 -190
- package/dist/index.js.map +1 -1
- package/dist/{run-run-tg82jUIk.js → run-run-Zr699h2S.js} +2 -2
- package/dist/{run-run-tg82jUIk.js.map → run-run-Zr699h2S.js.map} +1 -1
- package/dist/{run-tui-Bw7BA75d.js → run-tui-CeM1GOJP.js} +2 -2
- package/dist/{run-tui-Bw7BA75d.js.map → run-tui-CeM1GOJP.js.map} +1 -1
- package/dist/serve-web.js +47 -47
- package/dist/{state-zTow5ucI.js → state-C067Kbew.js} +1079 -191
- package/dist/state-C067Kbew.js.map +1 -0
- package/dist/web.d.ts +1203 -428
- package/dist/web.js +1078 -190
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/ace-step15-t2a.cflow.ts +163 -0
- package/examples/comfy-cloud/anima-t2i-base.cflow.ts +57 -0
- package/examples/comfy-cloud/boogu-t2i.cflow.ts +55 -0
- package/examples/comfy-cloud/chronoedit-i2i.cflow.ts +95 -0
- package/examples/comfy-cloud/ernie-t2i-base.cflow.ts +81 -0
- package/examples/comfy-cloud/flux1-t2i-krea.cflow.ts +63 -0
- package/examples/comfy-cloud/flux2-i2i-dev.cflow.ts +83 -0
- package/examples/comfy-cloud/flux2-t2i-dev.cflow.ts +60 -0
- package/examples/comfy-cloud/hidream-o1-i2i.cflow.ts +71 -0
- package/examples/comfy-cloud/hidream-o1-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/krea2-i2i.cflow.ts +78 -0
- package/examples/comfy-cloud/ltx2-i2v.cflow.ts +175 -0
- package/examples/comfy-cloud/ltx2-t2v.cflow.ts +143 -0
- package/examples/comfy-cloud/ltx23-i2v.cflow.ts +189 -0
- package/examples/comfy-cloud/ltx23-t2v.cflow.ts +151 -0
- package/examples/comfy-cloud/mage-flow-i2i-turbo.cflow.ts +72 -0
- package/examples/comfy-cloud/mage-flow-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/mage-flow-t2i-turbo.cflow.ts +60 -0
- package/examples/comfy-cloud/mage-flow-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/minimax-h3-t2i.cflow.ts +64 -0
- package/examples/comfy-cloud/netayume-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/qwen-image-i2i-2509.cflow.ts +75 -0
- package/examples/comfy-cloud/qwen-image-t2i-2512.cflow.ts +63 -0
- package/examples/comfy-cloud/sdk.d.ts +21683 -13737
- package/examples/comfy-cloud/stable-audio3-t2a.cflow.ts +96 -0
- package/examples/comfy-cloud/z-image-t2i-base.cflow.ts +54 -0
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +1 -1
- package/package.json +2 -2
- package/src/graph/ComfyNode.ts +93 -12
- package/src/host/ComfyHost.ts +37 -46
- package/src/host/ComfyManager.ts +576 -64
- package/src/litegraph/CanonicalWorkflow.ts +3 -0
- package/src/litegraph/LiteGraphJSON.ts +2 -2
- package/src/litegraph/LiteGraphNodeInput.ts +2 -2
- package/src/litegraph/LiteGraphNodeOutput.ts +2 -2
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +112 -37
- package/src/litegraph/expandSubgraphs.ts +72 -4
- package/src/litegraph/normalizeWorkflow.ts +7 -1
- package/src/manager/ComfyRegistry.ts +2 -0
- package/src/manager/generated/KnownComfyCustomNodeName.ts +6354 -1680
- package/src/manager/generated/KnownComfyPluginTitle.ts +718 -356
- package/src/manager/generated/KnownComfyPluginURL.ts +357 -181
- package/src/manager/generated/KnownModel_Base.ts +9 -5
- package/src/manager/generated/KnownModel_FileName.ts +135 -0
- package/src/manager/generated/KnownModel_Name.ts +135 -0
- package/src/manager/generated/KnownModel_SavePath.ts +16 -14
- package/src/manager/generated/KnownModel_Type.ts +15 -13
- package/src/manager/installedView.ts +178 -0
- package/src/manager/json/custom-node-list.json +4018 -2248
- package/src/manager/json/extension-node-map.json +8903 -2964
- package/src/manager/json/github-stats.json +10796 -10036
- package/src/manager/json/model-list.json +298 -1
- package/src/manager/loaders/step4_model-list-loader.ts +1 -0
- package/src/manager/types/ComfyManagerAPIModelList.ts +3 -0
- package/src/manager/types/ComfyManagerAPIPluginList.ts +19 -0
- package/src/runner/ComfyExecution.ts +4 -1
- package/src/runner/ComfyWsApi.ts +82 -15
- package/src/sdk-generator/ComfySchema.ts +10 -1
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +4 -1
- package/src/sdk-generator/comfyui-sdk-codegen.ts +61 -20
- package/src/sdk-generator/inputWidgetKind.ts +19 -4
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -35
- package/dist/state-zTow5ucI.js.map +0 -1
|
@@ -185,6 +185,11 @@ const wrapQuote = (s) => {
|
|
|
185
185
|
return `'${s}'`;
|
|
186
186
|
};
|
|
187
187
|
//#endregion
|
|
188
|
+
//#region src/utils/exhaust.ts
|
|
189
|
+
function exhaust(x) {
|
|
190
|
+
return x;
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
188
193
|
//#region src/sdk-generator/inputWidgetKind.ts
|
|
189
194
|
const isRecord = (x) => typeof x === "object" && x != null && !Array.isArray(x);
|
|
190
195
|
/**
|
|
@@ -253,6 +258,14 @@ const parseContainer = (template) => {
|
|
|
253
258
|
requiredCount: isRecord(input) && isRecord(input["required"]) && Object.keys(input["required"]).length > 0 ? Math.min(min, names.length) : 0
|
|
254
259
|
};
|
|
255
260
|
};
|
|
261
|
+
/** dynamic group (`template` holding `required`/`optional` sections itself): fields in the
|
|
262
|
+
* frontend's creation order, required then optional; `_io.py _DynamicGroup` defaults min 0, max 20 */
|
|
263
|
+
const parseGroup = (o, template) => ({
|
|
264
|
+
kind: "dynamic-group",
|
|
265
|
+
fields: flattenInputSections(template),
|
|
266
|
+
min: typeof o["min"] === "number" ? o["min"] : 0,
|
|
267
|
+
max: typeof o["max"] === "number" ? o["max"] : 20
|
|
268
|
+
});
|
|
256
269
|
/**
|
|
257
270
|
* the single template sub-input's slot type of an autogrow container
|
|
258
271
|
* (`'IMAGE'` for TextEncodeBooguEdit.images). null when opts are not an
|
|
@@ -327,11 +340,12 @@ const classifyWidgetInput = (p) => {
|
|
|
327
340
|
};
|
|
328
341
|
}
|
|
329
342
|
const template = o?.["template"];
|
|
330
|
-
if (isRecord(template)) {
|
|
343
|
+
if (o != null && isRecord(template)) {
|
|
331
344
|
if (isRecord(template["input"])) return parseContainer(template);
|
|
345
|
+
if (isRecord(template["required"]) || isRecord(template["optional"])) return parseGroup(o, template);
|
|
332
346
|
return { kind: "slot" };
|
|
333
347
|
}
|
|
334
|
-
if (o?.["socketless"] ===
|
|
348
|
+
if (typeof o?.["socketless"] === "boolean") return {
|
|
335
349
|
kind: "widget",
|
|
336
350
|
consumes: 1,
|
|
337
351
|
strictValues: false,
|
|
@@ -394,6 +408,15 @@ const dynamicComboUnion = (p) => {
|
|
|
394
408
|
return `{ ${[`${p.nameEscaped}${p.keyOptional ? "?" : ""}: ${JSON.stringify(opt.key)}`, ...fields].join("; ")} }`;
|
|
395
409
|
}).join(" | ")})`;
|
|
396
410
|
};
|
|
411
|
+
/** one dynamic-group row as an object type: a field is optional when it has a default or sits in
|
|
412
|
+
* the template's optional section (ComfyNode fills it, agent/sdk-codegen.md) */
|
|
413
|
+
const dynamicGroupRow = (fields) => {
|
|
414
|
+
return `{ ${fields.map((e) => {
|
|
415
|
+
const opts = isRecord(e.opts) ? e.opts : null;
|
|
416
|
+
const optional = !e.required || opts?.["default"] !== void 0;
|
|
417
|
+
return `${escapeJSKey(e.name)}${optional ? "?" : ""}: ${branchInputType(e)}`;
|
|
418
|
+
}).join("; ")} }`;
|
|
419
|
+
};
|
|
397
420
|
/**
|
|
398
421
|
* convert a host id to the namespace name it gets inside the global `Comfy` namespace
|
|
399
422
|
* e.g. 'windows-1' -> 'Windows1', 'my_cloud.instance' -> 'MyCloudInstance'
|
|
@@ -442,6 +465,8 @@ function codegenSDK(opts) {
|
|
|
442
465
|
b.deindent();
|
|
443
466
|
p(`// #endregion`);
|
|
444
467
|
const nodes = this.nodes.toSorted((a, b) => a.nodeKey.localeCompare(b.nodeKey));
|
|
468
|
+
/** one row type per dynamic group, named once so a long COMBO union is not printed twice */
|
|
469
|
+
const groupRows = [];
|
|
445
470
|
p(`interface IN {`);
|
|
446
471
|
b.indent();
|
|
447
472
|
for (const n of nodes) {
|
|
@@ -449,23 +474,37 @@ function codegenSDK(opts) {
|
|
|
449
474
|
const comboSuffixes = [];
|
|
450
475
|
for (const i of n.inputs) {
|
|
451
476
|
const kind = classifySchemaInput(i);
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
477
|
+
switch (kind.kind) {
|
|
478
|
+
case "dynamic-container": {
|
|
479
|
+
const instType = containerInstanceSlotType(i.opts);
|
|
480
|
+
if (instType != null) kind.instanceNames.forEach((instName, ix) => {
|
|
481
|
+
const opt = ix >= kind.requiredCount ? "?" : "";
|
|
482
|
+
p(` ${escapeJSKey(`${i.nameInComfy}.${instName}`)}${opt}: Accepts[${JSON.stringify(instType)}]`);
|
|
483
|
+
});
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
case "dynamic-combo": {
|
|
487
|
+
const optsDyn = typeof i.opts === "string" ? null : i.opts;
|
|
488
|
+
comboSuffixes.push(dynamicComboUnion({
|
|
489
|
+
name: i.nameInComfy,
|
|
490
|
+
nameEscaped: i.nameInComfyEscaped,
|
|
491
|
+
options: kind.options,
|
|
492
|
+
keyOptional: optsDyn?.default !== void 0 || !i.required
|
|
493
|
+
}));
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
case "dynamic-group": {
|
|
497
|
+
const rowKey = `${n.nodeKey}.${i.nameInComfy}`;
|
|
498
|
+
groupRows.push([rowKey, dynamicGroupRow(kind.fields)]);
|
|
499
|
+
const row = `GroupRow[${JSON.stringify(rowKey)}]`;
|
|
500
|
+
p(` /** min=${kind.min} max=${kind.max} rows */`);
|
|
501
|
+
if (kind.min > 0) p(` ${i.nameInComfyEscaped}: [${row}, ...${row}[]]`);
|
|
502
|
+
else p(` ${i.nameInComfyEscaped}?: ${row}[]`);
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
case "widget":
|
|
506
|
+
case "slot": break;
|
|
507
|
+
default:
|
|
469
508
|
}
|
|
470
509
|
const opts_ = typeof i.opts === "string" ? null : i.opts;
|
|
471
510
|
let type = `Accepts[${JSON.stringify(i.typeName)}]`;
|
|
@@ -488,6 +527,15 @@ function codegenSDK(opts) {
|
|
|
488
527
|
b.deindent();
|
|
489
528
|
p("}");
|
|
490
529
|
p("");
|
|
530
|
+
if (groupRows.length > 0) {
|
|
531
|
+
p(`/** one row of each dynamic group input, keyed \`<node>.<input>\` */`);
|
|
532
|
+
p(`interface GroupRow {`);
|
|
533
|
+
b.indent();
|
|
534
|
+
for (const [key, row] of groupRows) p(`${JSON.stringify(key)}: ${row}`);
|
|
535
|
+
b.deindent();
|
|
536
|
+
p("}");
|
|
537
|
+
p("");
|
|
538
|
+
}
|
|
491
539
|
p(`interface OUT {`);
|
|
492
540
|
b.indent();
|
|
493
541
|
for (const n of nodes) {
|
|
@@ -800,9 +848,13 @@ var ComfySchema = class {
|
|
|
800
848
|
if (widgetKind?.kind === "dynamic-combo") {
|
|
801
849
|
for (const opt of widgetKind.options) for (const entry of opt.inputs) if (typeof entry.type === "string") this.knownSlotTypes.add(asComfyNodeSlotTypeName(entry.type));
|
|
802
850
|
}
|
|
851
|
+
if (widgetKind?.kind === "dynamic-group") {
|
|
852
|
+
for (const entry of widgetKind.fields) if (typeof entry.type === "string") this.knownSlotTypes.add(asComfyNodeSlotTypeName(entry.type));
|
|
853
|
+
}
|
|
854
|
+
const required = widgetKind?.kind === "dynamic-group" ? widgetKind.min > 0 : ipt.required && !isAutogrowContainer;
|
|
803
855
|
node.inputs.push({
|
|
804
856
|
slotName: inputSlotName,
|
|
805
|
-
required
|
|
857
|
+
required,
|
|
806
858
|
nameInComfy: inputNameInComfy,
|
|
807
859
|
nameInComfyEscaped: escapeJSKey(inputNameInComfy),
|
|
808
860
|
typeName: inputTypeName,
|
|
@@ -850,7 +902,7 @@ var ComfySchema = class {
|
|
|
850
902
|
};
|
|
851
903
|
//#endregion
|
|
852
904
|
//#region package.json
|
|
853
|
-
var version = "2.
|
|
905
|
+
var version = "2.18.1";
|
|
854
906
|
//#endregion
|
|
855
907
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
856
908
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -860,8 +912,55 @@ const LiteGraphLinkID_ = type.number.atLeast(0).as();
|
|
|
860
912
|
/** boundary sentinel ids inside definition link tables */
|
|
861
913
|
const SUBGRAPH_INPUT_NODE_ID = -10;
|
|
862
914
|
const SUBGRAPH_OUTPUT_NODE_ID = -20;
|
|
863
|
-
/**
|
|
864
|
-
|
|
915
|
+
/** expanded node count above which a file is refused before expanding: the largest official
|
|
916
|
+
* template expands to 575 nodes, and fan-out nesting grows geometrically without any cycle */
|
|
917
|
+
const MAX_EXPANDED_NODES = 1e5;
|
|
918
|
+
/**
|
|
919
|
+
* before any expansion: the definitions as a graph (def → the defs its NORMAL-mode instances name,
|
|
920
|
+
* the only ones expansion follows). A cycle reachable from the root is refused with the defs it
|
|
921
|
+
* runs through, and the expanded size is counted, not built, and refused above
|
|
922
|
+
* MAX_EXPANDED_NODES. One explicit stack, no recursion: the file decides the depth
|
|
923
|
+
*/
|
|
924
|
+
const checkExpansion = (wf, defs) => {
|
|
925
|
+
const children = (nodes) => nodes.filter((n) => n.mode === "normal" && defs.has(n.type)).map((n) => n.type);
|
|
926
|
+
const own = (nodes) => nodes.filter((n) => !(n.mode === "normal" && defs.has(n.type))).length;
|
|
927
|
+
const name = (id) => JSON.stringify(defs.get(id)?.name ?? id);
|
|
928
|
+
const cap = (n) => Math.min(n, 100001);
|
|
929
|
+
const size = /* @__PURE__ */ new Map();
|
|
930
|
+
const onPath = /* @__PURE__ */ new Set();
|
|
931
|
+
for (const root of new Set(children(wf.nodes))) {
|
|
932
|
+
if (size.has(root)) continue;
|
|
933
|
+
const stack = [{
|
|
934
|
+
id: root,
|
|
935
|
+
kids: children(bang(defs.get(root)).nodes),
|
|
936
|
+
next: 0
|
|
937
|
+
}];
|
|
938
|
+
onPath.add(root);
|
|
939
|
+
while (stack.length > 0) {
|
|
940
|
+
const top = bang(stack[stack.length - 1]);
|
|
941
|
+
const kid = top.kids[top.next++];
|
|
942
|
+
if (kid == null) {
|
|
943
|
+
const total = top.kids.reduce((acc, k) => cap(acc + (size.get(k) ?? 0)), own(bang(defs.get(top.id)).nodes));
|
|
944
|
+
size.set(top.id, total);
|
|
945
|
+
onPath.delete(top.id);
|
|
946
|
+
stack.pop();
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
if (size.has(kid)) continue;
|
|
950
|
+
if (onPath.has(kid)) {
|
|
951
|
+
const from = stack.findIndex((frame) => frame.id === kid);
|
|
952
|
+
throw new WorkflowNormalizeError("subgraph-cycle", `subgraph definitions contain themselves: ${[...stack.slice(from).map((frame) => frame.id), kid].map(name).join(" → ")}`, { cycle: stack.slice(from).map((frame) => frame.id) });
|
|
953
|
+
}
|
|
954
|
+
onPath.add(kid);
|
|
955
|
+
stack.push({
|
|
956
|
+
id: kid,
|
|
957
|
+
kids: children(bang(defs.get(kid)).nodes),
|
|
958
|
+
next: 0
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
if (children(wf.nodes).reduce((acc, k) => cap(acc + (size.get(k) ?? 0)), own(wf.nodes)) > 1e5) throw new WorkflowNormalizeError("subgraph-too-large", `subgraph expansion would produce more than ${MAX_EXPANDED_NODES} nodes (the largest official template has 575)`);
|
|
963
|
+
};
|
|
865
964
|
/**
|
|
866
965
|
* widget-kind fallback when a def input slot has no boundary target carrying a
|
|
867
966
|
* widget marker: these litegraph slot types carry widget values. LOCAL copy on
|
|
@@ -884,11 +983,12 @@ const PRIMITIVE_WIDGET_TYPES = /* @__PURE__ */ new Set([
|
|
|
884
983
|
* passthrough walk, which needs no interior.
|
|
885
984
|
*/
|
|
886
985
|
const expandSubgraphs = (wf, defs) => {
|
|
986
|
+
checkExpansion(wf, defs);
|
|
887
987
|
let passes = 0;
|
|
888
988
|
while (true) {
|
|
889
989
|
const expandable = wf.nodes.filter((n) => defs.has(n.type) && n.mode !== "bypassed");
|
|
890
990
|
if (expandable.length === 0) return wf;
|
|
891
|
-
if (++passes >
|
|
991
|
+
if (++passes > defs.size + 1) throw new WorkflowNormalizeError("subgraph-cycle", `subgraph expansion still had instances after ${passes - 1} passes over ${defs.size} definitions`);
|
|
892
992
|
for (const instance of expandable) if (instance.mode === "muted") dropMutedInstance(wf, instance);
|
|
893
993
|
else expandOneInstance(wf, instance, bang(defs.get(instance.type)));
|
|
894
994
|
}
|
|
@@ -996,7 +1096,8 @@ const expandOneInstance = (wf, instance, def) => {
|
|
|
996
1096
|
name: i.name,
|
|
997
1097
|
type: i.type,
|
|
998
1098
|
link: i.link != null ? newLinkIds.get(i.link) ?? null : null,
|
|
999
|
-
widgetName: i.widgetName
|
|
1099
|
+
widgetName: i.widgetName,
|
|
1100
|
+
widgetSource: i.widgetSource
|
|
1000
1101
|
})),
|
|
1001
1102
|
outputs: inner.outputs.map((o) => ({
|
|
1002
1103
|
name: o.name,
|
|
@@ -1037,6 +1138,20 @@ const expandOneInstance = (wf, instance, def) => {
|
|
|
1037
1138
|
wf.links = wf.links.filter((l) => !dead.has(l.id));
|
|
1038
1139
|
pruneDeadLinkRefs(wf, dead);
|
|
1039
1140
|
promoteInstanceWidgets(instance, def, splicedNodes, newNodeIds, boundaryTargetsByInSlot);
|
|
1141
|
+
for (const [slot, targets] of boundaryTargetsByInSlot) {
|
|
1142
|
+
if (outerLinkIntoDefSlot.has(slot)) continue;
|
|
1143
|
+
const source = targets.find((t) => innerInputAt(splicedNodes, t)?.widgetName != null);
|
|
1144
|
+
const sourceInput = source != null ? innerInputAt(splicedNodes, source) : null;
|
|
1145
|
+
if (source == null || sourceInput == null) continue;
|
|
1146
|
+
for (const t of targets) {
|
|
1147
|
+
const input = splicedNodes.find((n) => n.id === t.nodeId)?.inputs[t.slot];
|
|
1148
|
+
if (input == null || input.widgetName != null || input.link != null) continue;
|
|
1149
|
+
input.widgetSource = {
|
|
1150
|
+
nodeId: source.nodeId,
|
|
1151
|
+
inputName: sourceInput.name
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1040
1155
|
wf.nodes = wf.nodes.filter((n) => n.id !== instance.id);
|
|
1041
1156
|
wf.nodes.push(...splicedNodes);
|
|
1042
1157
|
wf.links.push(...splicedLinks);
|
|
@@ -1148,7 +1263,7 @@ const LiteGraphNodeInput_ark = type({
|
|
|
1148
1263
|
type: "string",
|
|
1149
1264
|
"link?": LiteGraphLinkID_.or(type.null),
|
|
1150
1265
|
"shape?": "number",
|
|
1151
|
-
"label?":
|
|
1266
|
+
"label?": type.string.or(type.null),
|
|
1152
1267
|
"widget?": type({
|
|
1153
1268
|
name: "string",
|
|
1154
1269
|
"config?": "unknown"
|
|
@@ -1165,7 +1280,7 @@ const LiteGraphNodeOutput_ark = type({
|
|
|
1165
1280
|
type: "string",
|
|
1166
1281
|
"links?": LiteGraphLinkID_.array().or(type.null),
|
|
1167
1282
|
"shape?": "number",
|
|
1168
|
-
"slot_index?": LiteGraphSlotIndex_
|
|
1283
|
+
"slot_index?": LiteGraphSlotIndex_.or(type.null)
|
|
1169
1284
|
});
|
|
1170
1285
|
//#endregion
|
|
1171
1286
|
//#region src/litegraph/LiteGraphNode.ts
|
|
@@ -1235,7 +1350,7 @@ const LiteGraphSubgraphDef_ark = type({
|
|
|
1235
1350
|
const LiteGraphJSON_ark = type({
|
|
1236
1351
|
"id?": "string",
|
|
1237
1352
|
"revision?": "number",
|
|
1238
|
-
"last_node_id?": "number",
|
|
1353
|
+
"last_node_id?": "number | string",
|
|
1239
1354
|
"last_link_id?": "number",
|
|
1240
1355
|
"state?": type.Record("string", "unknown"),
|
|
1241
1356
|
nodes: LiteGraphNode_ark.array(),
|
|
@@ -1334,7 +1449,8 @@ const normalizeInput = (i) => {
|
|
|
1334
1449
|
name: i.name,
|
|
1335
1450
|
type: i.type,
|
|
1336
1451
|
link: i.link ?? null,
|
|
1337
|
-
widgetName: i.widget?.name ?? null
|
|
1452
|
+
widgetName: i.widget?.name ?? null,
|
|
1453
|
+
widgetSource: null
|
|
1338
1454
|
};
|
|
1339
1455
|
};
|
|
1340
1456
|
const normalizeOutput = (o) => {
|
|
@@ -1525,6 +1641,8 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
1525
1641
|
if (node.widgets.positional.length > 0) PRIMITIVE_VALUES[node.id] = node.widgets.positional[0];
|
|
1526
1642
|
else if (Object.hasOwn(node.widgets.named, "value")) PRIMITIVE_VALUES[node.id] = node.widgets.named["value"];
|
|
1527
1643
|
}
|
|
1644
|
+
const linksById = new Map(workflow.links.map((l) => [l.id, l]));
|
|
1645
|
+
const nodesById = new Map(workflow.nodes.map((n) => [n.id, n]));
|
|
1528
1646
|
for (const node of workflow.nodes) {
|
|
1529
1647
|
if (isNeverExecuted(node)) continue;
|
|
1530
1648
|
if (node.mode !== "normal") continue;
|
|
@@ -1598,18 +1716,43 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
1598
1716
|
inputs[p.path] = key;
|
|
1599
1717
|
for (const sub of opt.inputs) consumeBranchInput(`${p.path}.${sub.name}`, sub);
|
|
1600
1718
|
};
|
|
1719
|
+
/** the row count first (named, else positional, else `min`), then every row's fields in
|
|
1720
|
+
* template order: the frontend's saved run (architecture.md, dynamic group) */
|
|
1721
|
+
const consumeDynamicGroup = (p) => {
|
|
1722
|
+
const r = resolveWidgetValue({
|
|
1723
|
+
promptName: p.path,
|
|
1724
|
+
consumes: 1,
|
|
1725
|
+
prefixLen: 0
|
|
1726
|
+
});
|
|
1727
|
+
const saved = r.filled ? p.min : r.value;
|
|
1728
|
+
if (typeof saved !== "number" || !Number.isInteger(saved) || saved < 0 || saved > p.max) throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}): dynamic group "${p.path}" row count is not an integer in [0, ${p.max}]: ${JSON.stringify(saved)}`, node);
|
|
1729
|
+
const rows = Math.max(p.min, saved);
|
|
1730
|
+
if (r.filled || rows !== saved) LOG(`${node.type}#${node.id}.${p.path} = ${rows} rows (min ${p.min})`);
|
|
1731
|
+
for (let row = 0; row < rows; row++) for (const field of p.fields) consumeBranchInput(`${p.path}.${row}.${field.name}`, field);
|
|
1732
|
+
};
|
|
1601
1733
|
const consumeBranchInput = (subPath, sub) => {
|
|
1602
1734
|
const kind = classifyWidgetInput({
|
|
1603
|
-
name:
|
|
1735
|
+
name: subPath,
|
|
1604
1736
|
type: sub.type,
|
|
1605
1737
|
opts: sub.opts
|
|
1606
1738
|
});
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1739
|
+
switch (kind.kind) {
|
|
1740
|
+
case "slot":
|
|
1741
|
+
case "dynamic-container": return;
|
|
1742
|
+
case "dynamic-combo": return consumeDynamicCombo({
|
|
1743
|
+
path: subPath,
|
|
1744
|
+
options: kind.options,
|
|
1745
|
+
defaultKey: kind.defaultKey
|
|
1746
|
+
});
|
|
1747
|
+
case "dynamic-group": return consumeDynamicGroup({
|
|
1748
|
+
path: subPath,
|
|
1749
|
+
fields: kind.fields,
|
|
1750
|
+
min: kind.min,
|
|
1751
|
+
max: kind.max
|
|
1752
|
+
});
|
|
1753
|
+
case "widget": break;
|
|
1754
|
+
default: return exhaust(kind);
|
|
1755
|
+
}
|
|
1613
1756
|
const inlineEnum = Array.isArray(sub.type) ? sub.type.filter((v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean") : void 0;
|
|
1614
1757
|
consumePlainWidget({
|
|
1615
1758
|
promptName: subPath,
|
|
@@ -1631,32 +1774,56 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
1631
1774
|
strictValues: true,
|
|
1632
1775
|
prefixValues: []
|
|
1633
1776
|
};
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1777
|
+
switch (kind.kind) {
|
|
1778
|
+
case "widget":
|
|
1779
|
+
consumePlainWidget({
|
|
1780
|
+
promptName: field.nameInComfy,
|
|
1781
|
+
typeName: field.typeName,
|
|
1782
|
+
opts: field.opts,
|
|
1783
|
+
consumes: kind.consumes,
|
|
1784
|
+
prefixLen: kind.prefixValues.length,
|
|
1785
|
+
strict: kind.strictValues,
|
|
1786
|
+
linkedInput: input
|
|
1787
|
+
});
|
|
1788
|
+
break;
|
|
1789
|
+
case "dynamic-combo":
|
|
1790
|
+
consumeDynamicCombo({
|
|
1791
|
+
path: field.nameInComfy,
|
|
1792
|
+
options: kind.options,
|
|
1793
|
+
defaultKey: kind.defaultKey
|
|
1794
|
+
});
|
|
1795
|
+
break;
|
|
1796
|
+
case "dynamic-group":
|
|
1797
|
+
consumeDynamicGroup({
|
|
1798
|
+
path: field.nameInComfy,
|
|
1799
|
+
fields: kind.fields,
|
|
1800
|
+
min: kind.min,
|
|
1801
|
+
max: kind.max
|
|
1802
|
+
});
|
|
1803
|
+
break;
|
|
1804
|
+
case "dynamic-container":
|
|
1805
|
+
for (const instName of kind.instanceNames.slice(0, kind.requiredCount)) {
|
|
1806
|
+
const iname = `${field.nameInComfy}.${instName}`;
|
|
1807
|
+
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);
|
|
1808
|
+
}
|
|
1809
|
+
break;
|
|
1810
|
+
case "slot":
|
|
1811
|
+
if (input?.link == null && Object.hasOwn(named, field.nameInComfy)) {
|
|
1812
|
+
inputs[field.nameInComfy] = toPromptValue(named[field.nameInComfy], {
|
|
1813
|
+
promptName: field.nameInComfy,
|
|
1814
|
+
strict: false
|
|
1815
|
+
});
|
|
1816
|
+
break;
|
|
1817
|
+
}
|
|
1818
|
+
if (!fieldNamesPresent.has(field.nameInComfy) && 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);
|
|
1819
|
+
break;
|
|
1820
|
+
default:
|
|
1654
1821
|
}
|
|
1655
1822
|
}
|
|
1656
1823
|
const getParentNode = (linkId) => {
|
|
1657
|
-
const link =
|
|
1824
|
+
const link = linksById.get(linkId);
|
|
1658
1825
|
if (link == null) throw new WorkflowConvertError("dangling-link", `node ${node.id}(${node.type}) references a non-existing link (id=${linkId})`, node);
|
|
1659
|
-
const parentNode =
|
|
1826
|
+
const parentNode = nodesById.get(link.originId);
|
|
1660
1827
|
if (parentNode == null) throw new WorkflowConvertError("dangling-link", `link ${linkId} references a non-existent parent node ${link.originId}`, node);
|
|
1661
1828
|
return {
|
|
1662
1829
|
node: parentNode,
|
|
@@ -1756,6 +1923,50 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
1756
1923
|
class_type: node.type
|
|
1757
1924
|
};
|
|
1758
1925
|
}
|
|
1926
|
+
for (const node of workflow.nodes) {
|
|
1927
|
+
const own = prompt[String(node.id)];
|
|
1928
|
+
if (own == null) continue;
|
|
1929
|
+
for (const ipt of node.inputs) {
|
|
1930
|
+
if (ipt.link != null || ipt.widgetSource == null || Object.hasOwn(own.inputs, ipt.name)) continue;
|
|
1931
|
+
const value = prompt[String(ipt.widgetSource.nodeId)]?.inputs[ipt.widgetSource.inputName];
|
|
1932
|
+
if (value !== void 0) own.inputs[ipt.name] = value;
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
const missing = /* @__PURE__ */ new Map();
|
|
1936
|
+
for (const node of workflow.nodes) {
|
|
1937
|
+
const own = prompt[String(node.id)];
|
|
1938
|
+
const nodeSchema = schema.nodesByNameInComfy[node.type];
|
|
1939
|
+
if (own == null || nodeSchema == null) continue;
|
|
1940
|
+
for (const field of nodeSchema.inputs) {
|
|
1941
|
+
if (!field.required || Object.hasOwn(own.inputs, field.nameInComfy)) continue;
|
|
1942
|
+
const kind = classifySchemaInput(field).kind;
|
|
1943
|
+
if (kind !== "slot" && kind !== "widget") continue;
|
|
1944
|
+
missing.set(String(node.id), {
|
|
1945
|
+
node,
|
|
1946
|
+
message: `node ${node.id}(${node.type}): required input "${field.nameInComfy}" (${field.typeName}) is unlinked and no value covers it`
|
|
1947
|
+
});
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
if (missing.size > 0) {
|
|
1952
|
+
const consumers = /* @__PURE__ */ new Map();
|
|
1953
|
+
for (const [id, n] of Object.entries(prompt)) for (const value of Object.values(n.inputs)) if (Array.isArray(value) && typeof value[0] === "string") {
|
|
1954
|
+
const list = consumers.get(value[0]) ?? [];
|
|
1955
|
+
list.push(id);
|
|
1956
|
+
consumers.set(value[0], list);
|
|
1957
|
+
}
|
|
1958
|
+
const blocked = new Set(missing.keys());
|
|
1959
|
+
const queue = [...blocked];
|
|
1960
|
+
for (let head = 0; head < queue.length; head++) for (const next of consumers.get(queue[head] ?? "") ?? []) if (!blocked.has(next)) {
|
|
1961
|
+
blocked.add(next);
|
|
1962
|
+
queue.push(next);
|
|
1963
|
+
}
|
|
1964
|
+
const outputs = Object.keys(prompt).filter((id) => schema.data.spec[prompt[id]?.class_type ?? ""]?.output_node === true);
|
|
1965
|
+
const dropped = outputs.filter((id) => blocked.has(id));
|
|
1966
|
+
const first = missing.values().next().value;
|
|
1967
|
+
if (first != null && outputs.length > 0 && dropped.length === outputs.length) throw new WorkflowConvertError("missing-required-input", first.message, first.node);
|
|
1968
|
+
if (dropped.length > 0 || outputs.length === 0) console.warn(`🟡 [workflow] ComfyUI will skip output node(s) ${dropped.join(", ") || "(none in this graph)"}: ${[...missing.values()].map((m) => m.message).join("; ")}`);
|
|
1969
|
+
}
|
|
1759
1970
|
return prompt;
|
|
1760
1971
|
};
|
|
1761
1972
|
//#endregion
|
|
@@ -1925,21 +2136,37 @@ var ComfyNode = class ComfyNode {
|
|
|
1925
2136
|
_convertPromptExtToPrompt(promptExt) {
|
|
1926
2137
|
const inputs = {};
|
|
1927
2138
|
const _done = /* @__PURE__ */ new Set();
|
|
1928
|
-
/** every dotted key
|
|
2139
|
+
/** every dotted key a dynamic input wrote or dropped on purpose: the rest loop skips them */
|
|
1929
2140
|
const _comboBranchKeys = /* @__PURE__ */ new Set();
|
|
1930
2141
|
for (const i of this.$schema.inputs) {
|
|
1931
2142
|
_done.add(i.nameInComfy);
|
|
1932
2143
|
const kind = classifySchemaInput(i);
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
2144
|
+
switch (kind.kind) {
|
|
2145
|
+
case "dynamic-combo":
|
|
2146
|
+
this._writeDynamicCombo({
|
|
2147
|
+
name: i.nameInComfy,
|
|
2148
|
+
options: kind.options,
|
|
2149
|
+
defaultKey: kind.defaultKey,
|
|
2150
|
+
provided: promptExt.inputs,
|
|
2151
|
+
out: inputs,
|
|
2152
|
+
claimed: _comboBranchKeys
|
|
2153
|
+
});
|
|
2154
|
+
continue;
|
|
2155
|
+
case "dynamic-group":
|
|
2156
|
+
this._writeDynamicGroup({
|
|
2157
|
+
name: i.nameInComfy,
|
|
2158
|
+
fields: kind.fields,
|
|
2159
|
+
min: kind.min,
|
|
2160
|
+
max: kind.max,
|
|
2161
|
+
provided: promptExt.inputs,
|
|
2162
|
+
out: inputs,
|
|
2163
|
+
claimed: _comboBranchKeys
|
|
2164
|
+
});
|
|
2165
|
+
continue;
|
|
2166
|
+
case "widget":
|
|
2167
|
+
case "slot":
|
|
2168
|
+
case "dynamic-container": break;
|
|
2169
|
+
default:
|
|
1943
2170
|
}
|
|
1944
2171
|
const value = this.serializeValue(i.nameInComfy, promptExt.inputs[i.nameInComfy]);
|
|
1945
2172
|
if (value !== void 0) inputs[i.nameInComfy] = value;
|
|
@@ -1978,6 +2205,42 @@ var ComfyNode = class ComfyNode {
|
|
|
1978
2205
|
}) : this.serializeValue(dotted, given);
|
|
1979
2206
|
}
|
|
1980
2207
|
}
|
|
2208
|
+
/** dynamic group → the row array becomes `<decl>.<row>.<field>` keys, absent fields filled
|
|
2209
|
+
* from the schema (architecture.md, dynamic group). No array = a prompt json whose dotted
|
|
2210
|
+
* keys are already the rows: they pass through the rest loop untouched */
|
|
2211
|
+
_writeDynamicGroup(p) {
|
|
2212
|
+
const where = `${this.$schema.nodeKey}#${this.uid}`;
|
|
2213
|
+
const raw = p.provided[p.name];
|
|
2214
|
+
const prefix = `${p.name}.`;
|
|
2215
|
+
if (raw == null) {
|
|
2216
|
+
if (!Object.keys(p.provided).some((k) => k.startsWith(prefix)) && p.min > 0) this.graph.recordProblem(`🔴 "${p.name}" on ${where} needs at least ${p.min} row(s)`);
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
for (const k of Object.keys(p.provided)) if (k.startsWith(prefix)) p.claimed.add(k);
|
|
2220
|
+
if (!Array.isArray(raw)) {
|
|
2221
|
+
this.graph.recordProblem(`🔴 "${p.name}" on ${where} takes an array of rows, got ${JSON.stringify(raw)}`);
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
if (raw.length < p.min || raw.length > p.max) this.graph.recordProblem(`🔴 "${p.name}" on ${where} has ${raw.length} row(s), the host takes ${p.min} to ${p.max}`);
|
|
2225
|
+
raw.forEach((row, ix) => {
|
|
2226
|
+
if (typeof row !== "object" || row == null || Array.isArray(row)) {
|
|
2227
|
+
this.graph.recordProblem(`🔴 "${p.name}" row ${ix} on ${where} is not an object: ${JSON.stringify(row)}`);
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2230
|
+
const given = new Map(Object.entries(row));
|
|
2231
|
+
for (const field of p.fields) {
|
|
2232
|
+
const dotted = `${p.name}.${ix}.${field.name}`;
|
|
2233
|
+
const value = given.get(field.name);
|
|
2234
|
+
p.out[dotted] = value == null ? defaultValueForWidget({
|
|
2235
|
+
type: typeof field.type === "string" ? field.type : "COMBO",
|
|
2236
|
+
opts: field.opts,
|
|
2237
|
+
enumValues: Array.isArray(field.type) ? field.type.filter(isScalarValue) : void 0
|
|
2238
|
+
}) : this.serializeValue(dotted, value);
|
|
2239
|
+
given.delete(field.name);
|
|
2240
|
+
}
|
|
2241
|
+
for (const extra of given.keys()) this.graph.recordProblem(`🔴 "${p.name}" row ${ix} on ${where} has no field "${extra}"`);
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
1981
2244
|
/** return the list of nodes piped into this node */
|
|
1982
2245
|
_incomingNodes() {
|
|
1983
2246
|
const incomingNodes = [];
|
|
@@ -2121,6 +2384,12 @@ var ComfyNode = class ComfyNode {
|
|
|
2121
2384
|
const kind = classifySchemaInput(decl);
|
|
2122
2385
|
const slotType = containerInstanceSlotType(decl.opts);
|
|
2123
2386
|
if (kind.kind === "dynamic-container" && kind.instanceNames.includes(name.slice(dot + 1)) && slotType != null) return slotType;
|
|
2387
|
+
if (kind.kind === "dynamic-group") {
|
|
2388
|
+
const rest = name.slice(dot + 1);
|
|
2389
|
+
const fieldName = rest.slice(rest.indexOf(".") + 1);
|
|
2390
|
+
const field = kind.fields.find((f) => f.name === fieldName);
|
|
2391
|
+
if (rest.includes(".") && typeof field?.type === "string") return field.type;
|
|
2392
|
+
}
|
|
2124
2393
|
}
|
|
2125
2394
|
throw new Error(`🔴 no input "${name}" on ${this.$schema.nodeKey}: cannot tell which output of the linked node to use`);
|
|
2126
2395
|
}
|
|
@@ -2204,44 +2473,115 @@ const convertFlowToLiteGraphJSON = (graph) => {
|
|
|
2204
2473
|
const convertNodeToLiteGraphNode = (ctx, node) => {
|
|
2205
2474
|
const inputs = [];
|
|
2206
2475
|
const widgets_values = [];
|
|
2207
|
-
const pushLinked = (name, type, link,
|
|
2476
|
+
const pushLinked = (name, type, link, extra = {}) => {
|
|
2208
2477
|
const nodeUidNumber = bang(ctx.graph.nodes.find((n) => n.uid === link[0])?.uidNumber, `link target node "${link[0]}" not found in graph`);
|
|
2209
|
-
const
|
|
2210
|
-
inputs.push(shape == null ? {
|
|
2478
|
+
const input = {
|
|
2211
2479
|
name,
|
|
2212
2480
|
type,
|
|
2213
|
-
link:
|
|
2214
|
-
}
|
|
2481
|
+
link: ctx.allocateLink(nodeUidNumber, link[1], node.uidNumber, asLiteGraphSlotIndex(inputs.length), type)
|
|
2482
|
+
};
|
|
2483
|
+
if (extra.shape != null) input.shape = extra.shape;
|
|
2484
|
+
if (extra.widget === true) input.widget = { name };
|
|
2485
|
+
inputs.push(input);
|
|
2486
|
+
};
|
|
2487
|
+
/** frontend button-widget values ride BEFORE the real value (LOAD_3D); the control_after_generate
|
|
2488
|
+
* phantom AFTER it: the classifier's consumes covers prefix + value + control, config-driven
|
|
2489
|
+
* (the 2024 INT-named-seed heuristic lives inside controlConsumes), so export and import can
|
|
2490
|
+
* never disagree on the run length */
|
|
2491
|
+
const pushWidgetRun = (kind, raw, opts) => {
|
|
2492
|
+
widgets_values.push(...kind.prefixValues, raw);
|
|
2493
|
+
const phantoms = kind.consumes - 1 - kind.prefixValues.length;
|
|
2494
|
+
for (let i = 0; i < phantoms; i++) widgets_values.push(controlMode(opts));
|
|
2495
|
+
};
|
|
2496
|
+
/** one input, the way the editor saves it: a widget writes its run (a linked one too, with
|
|
2497
|
+
* its widget socket, since the editor serializes every widget), a dynamic combo its key then
|
|
2498
|
+
* the selected branch inline, a group its row count then the rows, a slot its socket */
|
|
2499
|
+
const writeInput = (p) => {
|
|
2500
|
+
const where = `${node.$schema.nameInComfy}#${node.uid} "${p.name}"`;
|
|
2501
|
+
switch (p.kind.kind) {
|
|
2502
|
+
case "widget":
|
|
2503
|
+
if (_isLink(p.value)) {
|
|
2504
|
+
pushLinked(p.name, p.typeName, p.value, { widget: true });
|
|
2505
|
+
pushWidgetRun(p.kind, defaultValueForWidget({
|
|
2506
|
+
type: p.typeName,
|
|
2507
|
+
opts: p.opts
|
|
2508
|
+
}), p.opts);
|
|
2509
|
+
} else pushWidgetRun(p.kind, p.value, p.opts);
|
|
2510
|
+
return;
|
|
2511
|
+
case "slot":
|
|
2512
|
+
if (_isLink(p.value)) pushLinked(p.name, p.typeName, p.value);
|
|
2513
|
+
else inputs.push({
|
|
2514
|
+
name: p.name,
|
|
2515
|
+
type: p.typeName,
|
|
2516
|
+
link: null
|
|
2517
|
+
});
|
|
2518
|
+
return;
|
|
2519
|
+
case "dynamic-combo": {
|
|
2520
|
+
const kind = p.kind;
|
|
2521
|
+
const key = typeof p.value === "string" ? p.value : kind.defaultKey;
|
|
2522
|
+
const option = kind.options.find((o) => o.key === key);
|
|
2523
|
+
if (option == null) throw new Error(`🔴 [toWorkflowJson] ${where}: "${key}" is not one of its options`);
|
|
2524
|
+
widgets_values.push(key);
|
|
2525
|
+
for (const sub of option.inputs) writeSub(`${p.name}.${sub.name}`, sub);
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
case "dynamic-container": {
|
|
2529
|
+
const type = containerInstanceSlotType(p.opts) ?? "*";
|
|
2530
|
+
for (const instance of p.kind.instanceNames) {
|
|
2531
|
+
const name = `${p.name}.${instance}`;
|
|
2532
|
+
const value = node.json.inputs[name];
|
|
2533
|
+
if (value == null) continue;
|
|
2534
|
+
const raw = node.serializeValue(name, value);
|
|
2535
|
+
if (!_isLink(raw)) throw new Error(`🔴 [toWorkflowJson] ${where}.${instance} holds a literal; an autogrow instance is a link slot in the editor`);
|
|
2536
|
+
pushLinked(name, type, raw, { shape: 7 });
|
|
2537
|
+
}
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
case "dynamic-group": {
|
|
2541
|
+
const prefix = `${p.name}.`;
|
|
2542
|
+
let rows = 0;
|
|
2543
|
+
for (const key of Object.keys(node.json.inputs)) {
|
|
2544
|
+
if (!key.startsWith(prefix)) continue;
|
|
2545
|
+
const row = Number(key.slice(prefix.length).split(".")[0]);
|
|
2546
|
+
if (Number.isInteger(row) && row >= rows) rows = row + 1;
|
|
2547
|
+
}
|
|
2548
|
+
widgets_values.push(rows);
|
|
2549
|
+
for (let row = 0; row < rows; row++) for (const field of p.kind.fields) writeSub(`${prefix}${row}.${field.name}`, field);
|
|
2550
|
+
return;
|
|
2551
|
+
}
|
|
2552
|
+
default: p.kind;
|
|
2553
|
+
}
|
|
2554
|
+
};
|
|
2555
|
+
/** a dotted input (dynamic combo branch, group row field): never a schema input, so its absent
|
|
2556
|
+
* value is the widget's schema default rather than serializeValue's */
|
|
2557
|
+
const writeSub = (name, sub) => {
|
|
2558
|
+
const typeName = typeof sub.type === "string" ? sub.type : "COMBO";
|
|
2559
|
+
const raw = node.json.inputs[name];
|
|
2560
|
+
writeInput({
|
|
2215
2561
|
name,
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2562
|
+
kind: classifyWidgetInput({
|
|
2563
|
+
name,
|
|
2564
|
+
type: sub.type,
|
|
2565
|
+
opts: sub.opts
|
|
2566
|
+
}),
|
|
2567
|
+
typeName,
|
|
2568
|
+
opts: sub.opts,
|
|
2569
|
+
value: raw === void 0 ? defaultValueForWidget({
|
|
2570
|
+
type: typeName,
|
|
2571
|
+
opts: sub.opts
|
|
2572
|
+
}) : raw
|
|
2219
2573
|
});
|
|
2220
2574
|
};
|
|
2221
2575
|
for (const ipt of node.$schema.inputs) {
|
|
2222
2576
|
const kind = classifySchemaInput(ipt);
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
const name = `${ipt.nameInComfy}.${instance}`;
|
|
2227
|
-
const value = node.json.inputs[name];
|
|
2228
|
-
if (value == null) continue;
|
|
2229
|
-
const raw = node.serializeValue(name, value);
|
|
2230
|
-
if (!_isLink(raw)) throw new Error(`🔴 [toWorkflowJson] ${node.$schema.nameInComfy}#${node.uid} "${name}" holds a literal; an autogrow instance is a link slot in the editor`);
|
|
2231
|
-
pushLinked(name, type, raw, 7);
|
|
2232
|
-
}
|
|
2233
|
-
continue;
|
|
2234
|
-
}
|
|
2235
|
-
const raw = node.serializeValue(ipt.nameInComfy, node.json.inputs[ipt.nameInComfy]);
|
|
2236
|
-
if (_isLink(raw)) pushLinked(ipt.nameInComfy, ipt.typeName, raw);
|
|
2237
|
-
else if (kind.kind === "widget") {
|
|
2238
|
-
widgets_values.push(...kind.prefixValues, raw);
|
|
2239
|
-
const phantoms = kind.consumes - 1 - kind.prefixValues.length;
|
|
2240
|
-
for (let i = 0; i < phantoms; i++) widgets_values.push(controlMode(ipt.opts));
|
|
2241
|
-
} else inputs.push({
|
|
2577
|
+
const raw = node.json.inputs[ipt.nameInComfy];
|
|
2578
|
+
const value = kind.kind === "widget" || kind.kind === "slot" ? node.serializeValue(ipt.nameInComfy, raw) : raw;
|
|
2579
|
+
writeInput({
|
|
2242
2580
|
name: ipt.nameInComfy,
|
|
2243
|
-
|
|
2244
|
-
|
|
2581
|
+
kind,
|
|
2582
|
+
typeName: ipt.typeName,
|
|
2583
|
+
opts: ipt.opts,
|
|
2584
|
+
value
|
|
2245
2585
|
});
|
|
2246
2586
|
}
|
|
2247
2587
|
const outputs = node.$schema.outputs.map((i, ix) => ({
|
|
@@ -2401,11 +2741,6 @@ const getPngMetadataFromUint8Array = (pngData) => {
|
|
|
2401
2741
|
return resultSuccess(txt_chunks);
|
|
2402
2742
|
};
|
|
2403
2743
|
//#endregion
|
|
2404
|
-
//#region src/utils/exhaust.ts
|
|
2405
|
-
function exhaust(x) {
|
|
2406
|
-
return x;
|
|
2407
|
-
}
|
|
2408
|
-
//#endregion
|
|
2409
2744
|
//#region src/graph/ComfyNodeID.ts
|
|
2410
2745
|
const ComfyNodeId_ark = type.string.as();
|
|
2411
2746
|
type({
|
|
@@ -2466,16 +2801,17 @@ const types$1 = scope({
|
|
|
2466
2801
|
},
|
|
2467
2802
|
_WsMsgExecutedData: {
|
|
2468
2803
|
node: "ComfyNodeID",
|
|
2469
|
-
output:
|
|
2470
|
-
"previews?": [{ filepath: "string" }, "[]"],
|
|
2471
|
-
"images?": "ComfyImageInfo[]",
|
|
2472
|
-
"audio?": "ComfyImageInfo[]",
|
|
2473
|
-
"video?": "ComfyImageInfo[]",
|
|
2474
|
-
"gifs?": "ComfyImageInfo[]",
|
|
2475
|
-
"text?": "unknown[]"
|
|
2476
|
-
},
|
|
2804
|
+
output: "_WsMsgExecutedOutput | null",
|
|
2477
2805
|
prompt_id: "PromptID"
|
|
2478
2806
|
},
|
|
2807
|
+
_WsMsgExecutedOutput: {
|
|
2808
|
+
"previews?": [{ filepath: "string" }, "[]"],
|
|
2809
|
+
"images?": "ComfyImageInfo[]",
|
|
2810
|
+
"audio?": "ComfyImageInfo[]",
|
|
2811
|
+
"video?": "ComfyImageInfo[]",
|
|
2812
|
+
"gifs?": "ComfyImageInfo[]",
|
|
2813
|
+
"text?": "unknown[]"
|
|
2814
|
+
},
|
|
2479
2815
|
WsMsgExecuted: {
|
|
2480
2816
|
type: "'executed'",
|
|
2481
2817
|
data: "_WsMsgExecutedData"
|
|
@@ -2497,12 +2833,22 @@ const types$1 = scope({
|
|
|
2497
2833
|
exception_type: "string",
|
|
2498
2834
|
traceback: "string[]",
|
|
2499
2835
|
current_inputs: "Record<string, unknown>",
|
|
2500
|
-
current_outputs: "
|
|
2836
|
+
current_outputs: "ComfyNodeID[]"
|
|
2501
2837
|
},
|
|
2502
2838
|
WsMsgExecutionError: {
|
|
2503
2839
|
type: "'execution_error'",
|
|
2504
2840
|
data: "_WsMsgExecutionErrorData"
|
|
2505
2841
|
},
|
|
2842
|
+
_WsMsgExecutionInterruptedData: {
|
|
2843
|
+
prompt_id: "PromptID",
|
|
2844
|
+
node_id: "ComfyNodeID",
|
|
2845
|
+
node_type: "string",
|
|
2846
|
+
executed: "ComfyNodeID[]"
|
|
2847
|
+
},
|
|
2848
|
+
WsMsgExecutionInterrupted: {
|
|
2849
|
+
type: "'execution_interrupted'",
|
|
2850
|
+
data: "_WsMsgExecutionInterruptedData"
|
|
2851
|
+
},
|
|
2506
2852
|
WSMsgManagerFeedbackData: { data: "string" },
|
|
2507
2853
|
WSMsgManagerFeedback: {
|
|
2508
2854
|
type: "'manager-terminal-feedback'",
|
|
@@ -2532,11 +2878,51 @@ const types$1 = scope({
|
|
|
2532
2878
|
type: "'progress_state'",
|
|
2533
2879
|
data: "_WsMsgProgressStateData"
|
|
2534
2880
|
},
|
|
2535
|
-
PromptRelated_WsMsg: "WsMsgExecutionStart | WsMsgExecutionCached | WsMsgExecuting | WsMsgProgress | WsMsgProgressState | WsMsgExecuted | WsMsgExecutionError | WsMsgExecutionSuccess",
|
|
2881
|
+
PromptRelated_WsMsg: "WsMsgExecutionStart | WsMsgExecutionCached | WsMsgExecuting | WsMsgProgress | WsMsgProgressState | WsMsgExecuted | WsMsgExecutionError | WsMsgExecutionInterrupted | WsMsgExecutionSuccess",
|
|
2536
2882
|
WsMsg: "WsMsgStatus | WSMsgManagerFeedback | WsMsgLogs | PromptRelated_WsMsg"
|
|
2537
2883
|
}).export();
|
|
2538
2884
|
const PromptInfo_ark = type({ prompt_id: types$1.PromptID }).as();
|
|
2539
2885
|
const WsMsg_ark = types$1.WsMsg;
|
|
2886
|
+
/** every json event type ComfyHost.onMessage routes; checked against the WsMsg union below */
|
|
2887
|
+
const ROUTED_WS_EVENT_TYPES = [
|
|
2888
|
+
"status",
|
|
2889
|
+
"manager-terminal-feedback",
|
|
2890
|
+
"logs",
|
|
2891
|
+
"execution_start",
|
|
2892
|
+
"execution_cached",
|
|
2893
|
+
"executing",
|
|
2894
|
+
"progress",
|
|
2895
|
+
"progress_state",
|
|
2896
|
+
"executed",
|
|
2897
|
+
"execution_error",
|
|
2898
|
+
"execution_interrupted",
|
|
2899
|
+
"execution_success"
|
|
2900
|
+
];
|
|
2901
|
+
/** events a server or a custom node sends by design that comfy-ts has no use for: dropped
|
|
2902
|
+
* before validation, never logged (architecture.md, ws events) */
|
|
2903
|
+
const IGNORED_WS_EVENT_TYPES = [
|
|
2904
|
+
"feature_flags",
|
|
2905
|
+
"agent_status",
|
|
2906
|
+
"asset_export",
|
|
2907
|
+
"assets.seed.started",
|
|
2908
|
+
"assets.seed.progress",
|
|
2909
|
+
"assets.seed.fast_complete",
|
|
2910
|
+
"assets.seed.enrich_complete",
|
|
2911
|
+
"assets.seed.completed",
|
|
2912
|
+
"assets.seed.cancelled",
|
|
2913
|
+
"assets.seed.error",
|
|
2914
|
+
"assets.seed.paused",
|
|
2915
|
+
"assets.seed.resumed",
|
|
2916
|
+
"cm-queue-status",
|
|
2917
|
+
"cm-api-try-install-customnode",
|
|
2918
|
+
"cm-task-started",
|
|
2919
|
+
"cm-task-completed",
|
|
2920
|
+
"crystools.monitor"
|
|
2921
|
+
];
|
|
2922
|
+
const ROUTED_SET = new Set(ROUTED_WS_EVENT_TYPES);
|
|
2923
|
+
const IGNORED_SET = new Set(IGNORED_WS_EVENT_TYPES);
|
|
2924
|
+
const isRoutedWsEventType = (t) => ROUTED_SET.has(t);
|
|
2925
|
+
const isIgnoredWsEventType = (t) => IGNORED_SET.has(t);
|
|
2540
2926
|
const ComfyImageInfo_ark = types$1.ComfyImageInfo;
|
|
2541
2927
|
const WsMsgLogsData_ark = types$1._WsMsgLogsData;
|
|
2542
2928
|
//#endregion
|
|
@@ -2759,6 +3145,10 @@ var ComfyExecution = class {
|
|
|
2759
3145
|
else if (msg.type === "progress") graph.onProgress(msg);
|
|
2760
3146
|
else if (msg.type === "progress_state") {} else if (msg.type === "executed") this.onExecuted(msg);
|
|
2761
3147
|
else if (msg.type === "execution_error") return void this.onError(msg);
|
|
3148
|
+
else if (msg.type === "execution_interrupted") return void this._finish({
|
|
3149
|
+
status: "Failure",
|
|
3150
|
+
error: msg
|
|
3151
|
+
});
|
|
2762
3152
|
else if (msg.type === "execution_success") return void this.onExecutionSuccess(msg);
|
|
2763
3153
|
else {
|
|
2764
3154
|
console.log(`🔴 UNEXPECTED MESSAGE:`, msg);
|
|
@@ -3500,7 +3890,12 @@ const types = scope({
|
|
|
3500
3890
|
ComfyInputSpecAlt1: ["ComfyInputType", "ComfyInputOpts"],
|
|
3501
3891
|
ComfyInputSpecAlt2: ["ComfyInputType"],
|
|
3502
3892
|
ComfyInputSpecAlt3: type([type.null]),
|
|
3503
|
-
|
|
3893
|
+
ComfyInputSpecAlt4: [
|
|
3894
|
+
"ComfyInputType",
|
|
3895
|
+
"ComfyInputOpts",
|
|
3896
|
+
"unknown"
|
|
3897
|
+
],
|
|
3898
|
+
ComfyInputSpec: `ComfyInputSpecAlt1 | ComfyInputSpecAlt2 | ComfyInputSpecAlt3 | ComfyInputSpecAlt4`,
|
|
3504
3899
|
ComfyInputType: `string | ComfyEnumDef`,
|
|
3505
3900
|
ComfyInputHiddenEntry_broken1: "\"CHOOSE\"[][]",
|
|
3506
3901
|
ComfyInputHiddenEntry_broken2: type.Record("string", type.unknown),
|
|
@@ -3566,10 +3961,163 @@ function readableStringify(obj, maxLevel = 3, level = 0) {
|
|
|
3566
3961
|
return result;
|
|
3567
3962
|
}
|
|
3568
3963
|
//#endregion
|
|
3964
|
+
//#region src/manager/installedView.ts
|
|
3965
|
+
/**
|
|
3966
|
+
* PURE builders of the public plugin and model lists where the Manager serves none (4.x default ui),
|
|
3967
|
+
* from our mirror and what the host reports (agent/architecture.md, Manager HTTP client).
|
|
3968
|
+
* A row the data cannot decide is left OUT (reads `unknown`), never given a guessed status.
|
|
3969
|
+
*/
|
|
3970
|
+
/** `GET customnode/installed`: a disk scan, keyed by directory */
|
|
3971
|
+
const InstalledPacks_ark = type.Record("string", type({
|
|
3972
|
+
"cnr_id?": "string | null",
|
|
3973
|
+
"aux_id?": "string | null",
|
|
3974
|
+
enabled: "boolean"
|
|
3975
|
+
}));
|
|
3976
|
+
/** `GET customnode/getmappings`: the extension-node-map, registered repos rekeyed by registry id */
|
|
3977
|
+
const PackMappings_ark = type.Record("string", type(["string[]", { "title_aux?": "string" }]));
|
|
3978
|
+
/** `https://github.com/Owner/Repo.git/` → `owner/repo` */
|
|
3979
|
+
const repoPath = (url) => url.toLowerCase().replace(/\/+$/, "").replace(/\.git$/, "").split("/").slice(-2).join("/");
|
|
3980
|
+
/** git clone → its `owner/repo`; registry install → its registry id's `title_aux` (= the mirror title) */
|
|
3981
|
+
const attributePacks = (installed, mappings) => {
|
|
3982
|
+
const titleById = new Map(Object.entries(mappings).map(([k, v]) => [k.toLowerCase(), v[1].title_aux]));
|
|
3983
|
+
return Object.entries(installed).map(([dir, p]) => {
|
|
3984
|
+
const aux = p.aux_id ?? null;
|
|
3985
|
+
const cnr = p.cnr_id != null && p.cnr_id !== "" ? p.cnr_id : null;
|
|
3986
|
+
const repo = aux != null && aux.includes("/") ? repoPath(aux) : null;
|
|
3987
|
+
const title = cnr != null ? titleById.get(cnr.toLowerCase()) ?? null : null;
|
|
3988
|
+
return {
|
|
3989
|
+
enabled: p.enabled,
|
|
3990
|
+
repo,
|
|
3991
|
+
title,
|
|
3992
|
+
id: cnr ?? aux ?? dir
|
|
3993
|
+
};
|
|
3994
|
+
});
|
|
3995
|
+
};
|
|
3996
|
+
/** is this mirror row among the attributed packs, enabled? */
|
|
3997
|
+
const packIsInstalled = (packs, plugin) => {
|
|
3998
|
+
const repo = repoPath(plugin.files[0] ?? plugin.reference);
|
|
3999
|
+
return packs.some((p) => p.enabled && (p.repo === repo || p.title === plugin.title));
|
|
4000
|
+
};
|
|
4001
|
+
const buildPluginView = (p) => {
|
|
4002
|
+
const packs = attributePacks(p.installed, p.mappings);
|
|
4003
|
+
const plugins = [...p.mirror.plugins_byTitle.values()];
|
|
4004
|
+
const mirrorRepos = new Set(plugins.flatMap((x) => x.files.map(repoPath)));
|
|
4005
|
+
const mirrorTitles = new Set(plugins.map((x) => x.title));
|
|
4006
|
+
const joins = (x) => x.repo != null && mirrorRepos.has(x.repo) || x.title != null && mirrorTitles.has(x.title);
|
|
4007
|
+
const unattributed = packs.filter((x) => x.enabled && x.repo == null && !joins(x));
|
|
4008
|
+
const serverTitles = new Set(Object.values(p.mappings).flatMap((v) => v[1].title_aux != null ? [v[1].title_aux] : []));
|
|
4009
|
+
const custom_nodes = [];
|
|
4010
|
+
for (const plugin of plugins) {
|
|
4011
|
+
const repo = repoPath(plugin.files[0] ?? plugin.reference);
|
|
4012
|
+
const joined = packs.filter((x) => x.repo === repo || x.title === plugin.title);
|
|
4013
|
+
if (joined.some((x) => x.enabled)) custom_nodes.push({
|
|
4014
|
+
title: plugin.title,
|
|
4015
|
+
installed: "True"
|
|
4016
|
+
});
|
|
4017
|
+
else if (joined.length === 0 && unattributed.length > 0 && !serverTitles.has(plugin.title)) continue;
|
|
4018
|
+
else custom_nodes.push({
|
|
4019
|
+
title: plugin.title,
|
|
4020
|
+
installed: "False"
|
|
4021
|
+
});
|
|
4022
|
+
}
|
|
4023
|
+
return {
|
|
4024
|
+
list: {
|
|
4025
|
+
chanel: "default",
|
|
4026
|
+
custom_nodes
|
|
4027
|
+
},
|
|
4028
|
+
unattributed: unattributed.map((x) => x.id)
|
|
4029
|
+
};
|
|
4030
|
+
};
|
|
4031
|
+
/** the Manager's `type` → folder map for `save_path: default` (model_utils.get_model_dir, 4.4) */
|
|
4032
|
+
const DEFAULT_FOLDER_BY_TYPE = {
|
|
4033
|
+
checkpoints: "checkpoints",
|
|
4034
|
+
checkpoint: "checkpoints",
|
|
4035
|
+
unclip: "checkpoints",
|
|
4036
|
+
text_encoders: "text_encoders",
|
|
4037
|
+
clip: "text_encoders",
|
|
4038
|
+
vae: "vae",
|
|
4039
|
+
lora: "loras",
|
|
4040
|
+
"t2i-adapter": "controlnet",
|
|
4041
|
+
"t2i-style": "controlnet",
|
|
4042
|
+
controlnet: "controlnet",
|
|
4043
|
+
clip_vision: "clip_vision",
|
|
4044
|
+
gligen: "gligen",
|
|
4045
|
+
upscale: "upscale_models",
|
|
4046
|
+
embedding: "embeddings",
|
|
4047
|
+
embeddings: "embeddings",
|
|
4048
|
+
unet: "diffusion_models",
|
|
4049
|
+
diffusion_model: "diffusion_models"
|
|
4050
|
+
};
|
|
4051
|
+
/** what core `get_filename_list` lists in the standard folders */
|
|
4052
|
+
const LISTED_EXTENSIONS = [
|
|
4053
|
+
".ckpt",
|
|
4054
|
+
".pt",
|
|
4055
|
+
".pt2",
|
|
4056
|
+
".bin",
|
|
4057
|
+
".pth",
|
|
4058
|
+
".safetensors",
|
|
4059
|
+
".pkl",
|
|
4060
|
+
".sft"
|
|
4061
|
+
];
|
|
4062
|
+
/**
|
|
4063
|
+
* where this model counts as installed, in core's `/models/<folder>` terms; null when not decidable.
|
|
4064
|
+
* The Manager's own check accepts the folder root as well as the `save_path` sub folder.
|
|
4065
|
+
*/
|
|
4066
|
+
const modelLocation = (m) => {
|
|
4067
|
+
if (m.filename === "<huggingface>" || /[\\/:]/.test(m.filename)) return null;
|
|
4068
|
+
if (!LISTED_EXTENSIONS.some((ext) => m.filename.toLowerCase().endsWith(ext))) return null;
|
|
4069
|
+
if (m.save_path === "default") {
|
|
4070
|
+
const folder = DEFAULT_FOLDER_BY_TYPE[m.type.toLowerCase()];
|
|
4071
|
+
return folder == null ? null : {
|
|
4072
|
+
folder,
|
|
4073
|
+
files: [m.filename]
|
|
4074
|
+
};
|
|
4075
|
+
}
|
|
4076
|
+
const parts = m.save_path.replaceAll("\\", "/").split("/").filter((s) => s !== "");
|
|
4077
|
+
const folder = parts[0];
|
|
4078
|
+
if (folder == null || folder === "custom_nodes" || parts.includes("..")) return null;
|
|
4079
|
+
const sub = [...parts.slice(1), m.filename].join("/");
|
|
4080
|
+
return {
|
|
4081
|
+
folder,
|
|
4082
|
+
files: sub === m.filename ? [m.filename] : [m.filename, sub]
|
|
4083
|
+
};
|
|
4084
|
+
};
|
|
4085
|
+
const buildModelView = (p) => {
|
|
4086
|
+
const listed = new Map([...p.files].map(([folder, files]) => [folder, new Set(files.map((f) => f.replaceAll("\\", "/")))]));
|
|
4087
|
+
const statusOf = (m) => {
|
|
4088
|
+
const at = modelLocation(m);
|
|
4089
|
+
const files = at == null ? null : listed.get(at.folder);
|
|
4090
|
+
if (at == null || files == null) return null;
|
|
4091
|
+
return at.files.some((f) => files.has(f)) ? "True" : "False";
|
|
4092
|
+
};
|
|
4093
|
+
const byName = /* @__PURE__ */ new Map();
|
|
4094
|
+
for (const m of p.models) byName.set(m.name, [...byName.get(m.name) ?? [], m]);
|
|
4095
|
+
const models = [];
|
|
4096
|
+
for (const rows of byName.values()) {
|
|
4097
|
+
const statuses = new Set(rows.map(statusOf));
|
|
4098
|
+
const first = rows[0];
|
|
4099
|
+
const installed = statuses.size === 1 ? [...statuses][0] : null;
|
|
4100
|
+
if (first == null || installed == null) continue;
|
|
4101
|
+
models.push({
|
|
4102
|
+
name: first.name,
|
|
4103
|
+
installed,
|
|
4104
|
+
filename: first.filename,
|
|
4105
|
+
save_path: first.save_path,
|
|
4106
|
+
base: first.base
|
|
4107
|
+
});
|
|
4108
|
+
}
|
|
4109
|
+
return { models };
|
|
4110
|
+
};
|
|
4111
|
+
/** the folders the views need listed */
|
|
4112
|
+
const modelFolders = (models) => new Set([...models].flatMap((m) => modelLocation(m)?.folder ?? []));
|
|
4113
|
+
//#endregion
|
|
3569
4114
|
//#region src/manager/types/ComfyManagerAPIModelList.ts
|
|
3570
4115
|
const ComfyManagerAPIModelList_ark = type({ models: type({
|
|
3571
4116
|
name: type.string.as(),
|
|
3572
|
-
installed: `'False' | 'True' | 'Update'
|
|
4117
|
+
installed: `'False' | 'True' | 'Update'`,
|
|
4118
|
+
"filename?": "string",
|
|
4119
|
+
"save_path?": "string",
|
|
4120
|
+
"base?": "string"
|
|
3573
4121
|
}).array() });
|
|
3574
4122
|
//#endregion
|
|
3575
4123
|
//#region src/manager/types/ComfyManagerAPIPluginList.ts
|
|
@@ -3580,28 +4128,160 @@ const ComfyManagerAPIPluginList_ark = type({
|
|
|
3580
4128
|
}).array(),
|
|
3581
4129
|
chanel: "string"
|
|
3582
4130
|
});
|
|
4131
|
+
const ComfyManagerAPIPack_ark = type({
|
|
4132
|
+
title: type.string.as(),
|
|
4133
|
+
"id?": "string",
|
|
4134
|
+
"files?": "string[]",
|
|
4135
|
+
"repository?": "string",
|
|
4136
|
+
"version?": "string",
|
|
4137
|
+
"state?": "string",
|
|
4138
|
+
"update-state?": "string"
|
|
4139
|
+
});
|
|
4140
|
+
const ComfyManagerAPIPackList_ark = type({
|
|
4141
|
+
channel: "string",
|
|
4142
|
+
node_packs: type.Record("string", ComfyManagerAPIPack_ark)
|
|
4143
|
+
});
|
|
3583
4144
|
//#endregion
|
|
3584
4145
|
//#region src/host/ComfyManager.ts
|
|
4146
|
+
/** 🔶 NAMING DISCLAIMER: I call a "custom node package" => "PLUGIN" */
|
|
4147
|
+
const MANAGER_TIMING = {
|
|
4148
|
+
pollMs: 1e3,
|
|
4149
|
+
installTimeoutMs: 60 * 6e4,
|
|
4150
|
+
pollGraceMs: 12e4
|
|
4151
|
+
};
|
|
4152
|
+
/** an install the host refused or reported failed: ends the wait at once */
|
|
4153
|
+
var InstallFailed = class extends Error {};
|
|
4154
|
+
/** we lost sight of the task: the outcome is not known */
|
|
4155
|
+
var OutcomeUnknown = class extends Error {};
|
|
4156
|
+
/** what each generation does NOT serve (history means the `?ui_id=` form) */
|
|
4157
|
+
const NOT_SERVED = {
|
|
4158
|
+
v3: [
|
|
4159
|
+
"/manager/queue/batch",
|
|
4160
|
+
"/manager/queue/task",
|
|
4161
|
+
"/manager/queue/history"
|
|
4162
|
+
],
|
|
4163
|
+
"v4-legacy-ui": [
|
|
4164
|
+
"/manager/queue/install",
|
|
4165
|
+
"/manager/queue/task",
|
|
4166
|
+
"/manager/queue/history",
|
|
4167
|
+
"/manager/terminal"
|
|
4168
|
+
],
|
|
4169
|
+
v4: [
|
|
4170
|
+
"/customnode/getlist",
|
|
4171
|
+
"/externalmodel/getlist",
|
|
4172
|
+
"/manager/queue/install",
|
|
4173
|
+
"/manager/queue/batch",
|
|
4174
|
+
"/manager/terminal"
|
|
4175
|
+
]
|
|
4176
|
+
};
|
|
4177
|
+
const QueueStatus_ark = type({
|
|
4178
|
+
is_processing: "boolean",
|
|
4179
|
+
"pending_count?": "number",
|
|
4180
|
+
"total_count?": "number",
|
|
4181
|
+
"done_count?": "number"
|
|
4182
|
+
});
|
|
4183
|
+
const TaskHistory_ark = type({ history: {
|
|
4184
|
+
"status?": {
|
|
4185
|
+
status_str: "string",
|
|
4186
|
+
"messages?": "string[]"
|
|
4187
|
+
},
|
|
4188
|
+
"result?": "string"
|
|
4189
|
+
} });
|
|
4190
|
+
const ModelFolders_ark = type("string[]");
|
|
4191
|
+
const errorText = (e) => e instanceof Error ? e.message : String(e);
|
|
3585
4192
|
var ComfyManager = class {
|
|
3586
|
-
constructor(host) {
|
|
4193
|
+
constructor(host, timing = { ...MANAGER_TIMING }, mirror = () => comfyts.registry) {
|
|
3587
4194
|
this.host = host;
|
|
3588
|
-
this.
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
4195
|
+
this.timing = timing;
|
|
4196
|
+
this.mirror = mirror;
|
|
4197
|
+
this.clientId = `comfy-ts-${nanoid(8)}`;
|
|
4198
|
+
this._api = null;
|
|
4199
|
+
this.api = () => {
|
|
4200
|
+
if (this._api == null) {
|
|
4201
|
+
const probe = this.probeApi();
|
|
4202
|
+
this._api = probe;
|
|
4203
|
+
probe.catch(() => {
|
|
4204
|
+
if (this._api === probe) this._api = null;
|
|
4205
|
+
});
|
|
4206
|
+
}
|
|
4207
|
+
return this._api;
|
|
4208
|
+
};
|
|
4209
|
+
this.probeApi = async () => {
|
|
4210
|
+
const v4 = await this.host.fetch("/v2/manager/version");
|
|
4211
|
+
if (v4.ok) {
|
|
4212
|
+
const version = (await v4.text()).trim();
|
|
4213
|
+
const ui = await this.host.fetch("/v2/manager/is_legacy_manager_ui");
|
|
4214
|
+
if (!ui.ok) {
|
|
4215
|
+
logError(`ComfyUI-Manager ${version}: GET /v2/manager/is_legacy_manager_ui → ${ui.status}, assuming the default ui`);
|
|
4216
|
+
return {
|
|
4217
|
+
generation: "v4",
|
|
4218
|
+
version
|
|
4219
|
+
};
|
|
4220
|
+
}
|
|
4221
|
+
const flag = await ui.json();
|
|
4222
|
+
return {
|
|
4223
|
+
generation: typeof flag === "object" && flag != null && "is_legacy_manager_ui" in flag && flag.is_legacy_manager_ui === true ? "v4-legacy-ui" : "v4",
|
|
4224
|
+
version
|
|
4225
|
+
};
|
|
4226
|
+
}
|
|
4227
|
+
const v3 = await this.host.fetch("/manager/version");
|
|
4228
|
+
if (v3.ok) return {
|
|
4229
|
+
generation: "v3",
|
|
4230
|
+
version: (await v3.text()).trim()
|
|
4231
|
+
};
|
|
4232
|
+
throw new Error(`🔴 no ComfyUI-Manager answers at ${this.host.getServerHostHTTP()} (GET /v2/manager/version → ${v4.status}, GET /manager/version → ${v3.status})`);
|
|
4233
|
+
};
|
|
4234
|
+
this.route = (api, route, query = "") => {
|
|
4235
|
+
if (NOT_SERVED[api.generation].includes(route)) throw new Error(`🔴 ComfyUI-Manager ${api.version} (${api.generation}) does not serve ${route}`);
|
|
4236
|
+
return `${api.generation === "v3" ? "" : "/v2"}${route}${query}`;
|
|
4237
|
+
};
|
|
4238
|
+
this.strategy = (api) => {
|
|
4239
|
+
switch (api.generation) {
|
|
4240
|
+
case "v3": return {
|
|
4241
|
+
fetchPlugins: (mode, skipUpdate) => this.listedPlugins(api, mode, skipUpdate),
|
|
4242
|
+
fetchModels: () => this.listedModels(api),
|
|
4243
|
+
enqueuePlugin: (plugin, uiId) => this.enqueueListedPlugin(api, plugin, uiId, (body) => this.post(this.route(api, "/manager/queue/install"), body)),
|
|
4244
|
+
settle: (what, _uiId, landed) => this.settleByDrain(api, what, landed)
|
|
4245
|
+
};
|
|
4246
|
+
case "v4-legacy-ui": return {
|
|
4247
|
+
fetchPlugins: (mode, skipUpdate) => this.listedPlugins(api, mode, skipUpdate),
|
|
4248
|
+
fetchModels: () => this.listedModels(api),
|
|
4249
|
+
enqueuePlugin: (plugin, uiId) => this.enqueueListedPlugin(api, plugin, uiId, async (body) => {
|
|
4250
|
+
const route = this.route(api, "/manager/queue/batch");
|
|
4251
|
+
const res = await this.post(route, { install: [body] });
|
|
4252
|
+
const failed = typeof res === "object" && res != null && "failed" in res ? res.failed : null;
|
|
4253
|
+
if (Array.isArray(failed) && failed.length > 0) throw new Error(`POST ${route} refused ${JSON.stringify(failed)}: the batch reply carries ids only, the ComfyUI console says why (a 4.x security policy refusal is the usual one)`);
|
|
4254
|
+
}),
|
|
4255
|
+
settle: (what, _uiId, landed) => this.settleByDrain(api, what, landed)
|
|
4256
|
+
};
|
|
4257
|
+
case "v4": return {
|
|
4258
|
+
fetchPlugins: () => this.installedPluginView(api),
|
|
4259
|
+
fetchModels: () => this.installedModelView(),
|
|
4260
|
+
enqueuePlugin: (plugin, uiId) => this.enqueuePluginTask(api, plugin, uiId),
|
|
4261
|
+
settle: (what, uiId, landed, sentId) => this.settleByHistory(api, what, uiId, landed, sentId)
|
|
4262
|
+
};
|
|
4263
|
+
}
|
|
3592
4264
|
};
|
|
3593
|
-
this.configureLogging = (mi) => {
|
|
3594
|
-
|
|
4265
|
+
this.configureLogging = async (mi) => {
|
|
4266
|
+
const api = await this.api();
|
|
4267
|
+
const route = this.route(api, "/manager/terminal", `?mode=${mi}`);
|
|
4268
|
+
const response = await this.host.fetch(route);
|
|
4269
|
+
const text = await response.text();
|
|
4270
|
+
if (!response.ok) throw new Error(`🔴 GET ${route} → ${response.status} ${text}`);
|
|
4271
|
+
return text;
|
|
3595
4272
|
};
|
|
3596
4273
|
this.getModelInfoFinalFilePath = (mi) => {
|
|
3597
4274
|
return comfyts.registry.getModelInfoFinalFilePath(mi);
|
|
3598
4275
|
};
|
|
3599
4276
|
this.restartComfyUI = async () => {
|
|
4277
|
+
const api = await this.api();
|
|
4278
|
+
this._api = null;
|
|
4279
|
+
const route = this.route(api, "/manager/reboot");
|
|
3600
4280
|
const refusals = [];
|
|
3601
4281
|
for (const method of ["POST", "GET"]) {
|
|
3602
4282
|
let response;
|
|
3603
4283
|
try {
|
|
3604
|
-
response = await this.host.fetch(
|
|
4284
|
+
response = await this.host.fetch(route, { method });
|
|
3605
4285
|
} catch {
|
|
3606
4286
|
return;
|
|
3607
4287
|
}
|
|
@@ -3609,31 +4289,44 @@ var ComfyManager = class {
|
|
|
3609
4289
|
refusals.push(`${method} → ${response.status}`);
|
|
3610
4290
|
if (response.status !== 404) break;
|
|
3611
4291
|
}
|
|
3612
|
-
throw new Error(`🔴 ${this.host.getServerHostHTTP()} refused to reboot (${refusals.join(", ")}) — ComfyUI-Manager is not
|
|
4292
|
+
throw new Error(`🔴 ${this.host.getServerHostHTTP()} refused to reboot (${route}: ${refusals.join(", ")}) — ComfyUI-Manager ${api.version} is not there any more, or its reboot route moved again`);
|
|
4293
|
+
};
|
|
4294
|
+
this.fetchPluginsAndModels = async () => {
|
|
4295
|
+
const [_pluginList, _modelList] = await Promise.all([this.fetchPlugins(), this.fetchModels()]);
|
|
4296
|
+
this.pluginList = _pluginList;
|
|
4297
|
+
this.modelList = _modelList;
|
|
3613
4298
|
};
|
|
3614
4299
|
this.modelList = null;
|
|
3615
|
-
this.fetchModels = () => {
|
|
3616
|
-
return this.
|
|
4300
|
+
this.fetchModels = async () => {
|
|
4301
|
+
return this.strategy(await this.api()).fetchModels();
|
|
3617
4302
|
};
|
|
3618
4303
|
this.fetchLogs = () => {
|
|
3619
|
-
return this.
|
|
4304
|
+
return this.getJSON("/internal/logs");
|
|
3620
4305
|
};
|
|
3621
4306
|
this.isModelInstalled = (name) => {
|
|
3622
4307
|
return this.modelList?.models.some((x) => x.name === name && x.installed === "True") ?? false;
|
|
3623
4308
|
};
|
|
3624
4309
|
this.modelsBeeingInstalled = /* @__PURE__ */ new Set();
|
|
3625
|
-
this.installModel = async (model) =>
|
|
4310
|
+
this.installModel = async (model) => await this.installModelOutcome(model) === "installed";
|
|
4311
|
+
this.installModelOutcome = async (model) => {
|
|
4312
|
+
this.modelsBeeingInstalled.add(model.name);
|
|
3626
4313
|
try {
|
|
3627
|
-
this.
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
4314
|
+
return await this.runInstall(`model "${model.name}"`, {
|
|
4315
|
+
enqueue: async (api, uiId) => {
|
|
4316
|
+
const body = {
|
|
4317
|
+
...model,
|
|
4318
|
+
ui_id: uiId,
|
|
4319
|
+
client_id: this.clientId
|
|
4320
|
+
};
|
|
4321
|
+
await this.post(this.route(api, "/manager/queue/install_model"), body);
|
|
4322
|
+
},
|
|
4323
|
+
landed: async (s) => {
|
|
4324
|
+
const row = (await s.fetchModels()).models.find((x) => x.filename === model.filename && x.save_path === model.save_path && x.base === model.base);
|
|
4325
|
+
return row == null ? null : row.installed === "True";
|
|
4326
|
+
}
|
|
4327
|
+
});
|
|
4328
|
+
} finally {
|
|
3635
4329
|
this.modelsBeeingInstalled.delete(model.name);
|
|
3636
|
-
return false;
|
|
3637
4330
|
}
|
|
3638
4331
|
};
|
|
3639
4332
|
this.getModelStatus = (modelName) => {
|
|
@@ -3663,48 +4356,239 @@ var ComfyManager = class {
|
|
|
3663
4356
|
return "error";
|
|
3664
4357
|
})();
|
|
3665
4358
|
};
|
|
4359
|
+
this.requirementStatus = (req) => {
|
|
4360
|
+
const mirror = this.mirror();
|
|
4361
|
+
const packs = (() => {
|
|
4362
|
+
if (req.type === "customNodesByNodeKey") return mirror.plugins_byNodeKey.get(req.nodeName) ?? [];
|
|
4363
|
+
if (req.type === "customNodesByTitle") return [mirror.plugins_byTitle.get(req.title)].filter((x) => x != null);
|
|
4364
|
+
if (req.type === "customNodesByURI") return [mirror.plugins_byFile.get(req.uri)].filter((x) => x != null);
|
|
4365
|
+
return null;
|
|
4366
|
+
})();
|
|
4367
|
+
if (packs == null) return req.type === "modelInManager" ? this.getModelStatus(req.modelName) : null;
|
|
4368
|
+
if (packs.length === 0) return req.type === "customNodesByNodeKey" ? "unknown" : null;
|
|
4369
|
+
const statuses = packs.map((x) => this.getPluginStatus(x.title));
|
|
4370
|
+
if (statuses.some((x) => x === "installed" || x === "update-available")) return "installed";
|
|
4371
|
+
return statuses.every((x) => x === "not-installed") ? "not-installed" : "unknown";
|
|
4372
|
+
};
|
|
4373
|
+
this.checkRequirements = (requirements) => {
|
|
4374
|
+
const out = {
|
|
4375
|
+
missing: [],
|
|
4376
|
+
undecided: []
|
|
4377
|
+
};
|
|
4378
|
+
for (const req of requirements) {
|
|
4379
|
+
if (req.optional) continue;
|
|
4380
|
+
const status = this.requirementStatus(req);
|
|
4381
|
+
if (status === "not-installed") out.missing.push(req);
|
|
4382
|
+
else if (status === "unknown" || status === "error") out.undecided.push(req);
|
|
4383
|
+
}
|
|
4384
|
+
return out;
|
|
4385
|
+
};
|
|
4386
|
+
this.matchRequirements = (requirements) => {
|
|
4387
|
+
const check = this.checkRequirements(requirements);
|
|
4388
|
+
if (check.undecided.length > 0) logError(`requirements the host lists cannot decide, read as present: ${check.undecided.map((r) => JSON.stringify(r)).join(", ")}` + (this.pluginList == null || this.modelList == null ? " (the lists are not fetched: call fetchPluginsAndModels)" : ""));
|
|
4389
|
+
return check.missing.length === 0;
|
|
4390
|
+
};
|
|
3666
4391
|
this.fetchPlugins = async (mode = "cache", skipUpdate = true) => {
|
|
4392
|
+
return this.strategy(await this.api()).fetchPlugins(mode, skipUpdate);
|
|
4393
|
+
};
|
|
4394
|
+
this.installPlugin = async (plugin) => await this.installPluginOutcome(plugin) === "installed";
|
|
4395
|
+
this.installPluginOutcome = async (plugin) => {
|
|
4396
|
+
return this.runInstall(`plugin "${plugin.title}"`, {
|
|
4397
|
+
enqueue: (api, uiId) => this.strategy(api).enqueuePlugin(plugin, uiId),
|
|
4398
|
+
landed: async (_s, api) => {
|
|
4399
|
+
const data = await this.installedData(api);
|
|
4400
|
+
return packIsInstalled(attributePacks(data.installed, data.mappings), plugin);
|
|
4401
|
+
}
|
|
4402
|
+
});
|
|
4403
|
+
};
|
|
4404
|
+
this.listedPlugins = async (api, mode, skipUpdate) => {
|
|
4405
|
+
const raw = await this.fetchPluginWire(api, mode, skipUpdate);
|
|
4406
|
+
if (!("node_packs" in raw)) return raw;
|
|
4407
|
+
const titleByRepo = /* @__PURE__ */ new Map();
|
|
4408
|
+
for (const p of this.mirror().plugins_byTitle.values()) for (const f of p.files) titleByRepo.set(repoPath(f), p.title);
|
|
4409
|
+
return {
|
|
4410
|
+
chanel: raw.channel,
|
|
4411
|
+
custom_nodes: Object.values(raw.node_packs).map((p) => {
|
|
4412
|
+
const repo = p.files?.[0];
|
|
4413
|
+
return {
|
|
4414
|
+
title: (repo != null ? titleByRepo.get(repoPath(repo)) : void 0) ?? p.title,
|
|
4415
|
+
installed: p.state !== "enabled" ? "False" : p["update-state"] === "true" ? "Update" : "True"
|
|
4416
|
+
};
|
|
4417
|
+
})
|
|
4418
|
+
};
|
|
4419
|
+
};
|
|
4420
|
+
this.fetchPluginWire = async (api, mode, skipUpdate) => {
|
|
4421
|
+
const query = `?mode=${mode}${skipUpdate ? "&skip_update=true" : ""}`;
|
|
4422
|
+
const json = await this.getJSON(this.route(api, "/customnode/getlist", query));
|
|
4423
|
+
if (typeof json === "object" && json != null && "custom_nodes" in json) return softValidate(ComfyManagerAPIPluginList_ark, json);
|
|
4424
|
+
return softValidate(ComfyManagerAPIPackList_ark, json);
|
|
4425
|
+
};
|
|
4426
|
+
this.listedModels = async (api) => {
|
|
4427
|
+
return this.getJSON(this.route(api, "/externalmodel/getlist", "?mode=cache"), ComfyManagerAPIModelList_ark);
|
|
4428
|
+
};
|
|
4429
|
+
this.installedData = async (api) => {
|
|
4430
|
+
const [installed, mappings] = await Promise.all([this.getValid(this.route(api, "/customnode/installed"), InstalledPacks_ark), this.getValid(this.route(api, "/customnode/getmappings", "?mode=cache"), PackMappings_ark)]);
|
|
4431
|
+
return {
|
|
4432
|
+
installed,
|
|
4433
|
+
mappings
|
|
4434
|
+
};
|
|
4435
|
+
};
|
|
4436
|
+
this.installedPluginView = async (api) => {
|
|
4437
|
+
const view = buildPluginView({
|
|
4438
|
+
mirror: this.mirror(),
|
|
4439
|
+
...await this.installedData(api)
|
|
4440
|
+
});
|
|
4441
|
+
if (view.unattributed.length > 0) logError(`ComfyUI-Manager ${api.version} reports installed packs no mirror row can be tied to (${view.unattributed.join(", ")}): the mirror rows they could be read unknown`);
|
|
4442
|
+
return view.list;
|
|
4443
|
+
};
|
|
4444
|
+
this.installedModelView = async () => {
|
|
4445
|
+
const models = this.mirror().modelRows;
|
|
4446
|
+
const registered = new Set(await this.getValid("/models", ModelFolders_ark));
|
|
4447
|
+
const folders = [...modelFolders(models)].filter((f) => registered.has(f));
|
|
4448
|
+
const lists = await Promise.all(folders.map(async (f) => [f, await this.getValid(`/models/${encodeURIComponent(f)}`, ModelFolders_ark)]));
|
|
4449
|
+
return buildModelView({
|
|
4450
|
+
models,
|
|
4451
|
+
files: new Map(lists)
|
|
4452
|
+
});
|
|
4453
|
+
};
|
|
4454
|
+
this.enqueueListedPlugin = async (api, plugin, uiId, send) => {
|
|
4455
|
+
const url = plugin.files[0] ?? plugin.reference;
|
|
4456
|
+
const list = await this.fetchPluginWire(api, "cache", true);
|
|
4457
|
+
if (!("node_packs" in list)) throw new Error(`ComfyUI-Manager ${api.version} lists packs in the pre-V3 shape and has no queue install`);
|
|
4458
|
+
const found = Object.entries(list.node_packs).find(([, p]) => (p.files ?? []).some((f) => repoPath(f) === repoPath(url)));
|
|
4459
|
+
if (found == null) throw new Error(`${url} is not in the Manager's own list (channel ${list.channel}), so it refuses to install it`);
|
|
4460
|
+
const [key, row] = found;
|
|
4461
|
+
await send({
|
|
4462
|
+
...row,
|
|
4463
|
+
id: row.id ?? key,
|
|
4464
|
+
channel: list.channel,
|
|
4465
|
+
mode: "cache",
|
|
4466
|
+
ui_id: uiId,
|
|
4467
|
+
skip_post_install: false
|
|
4468
|
+
});
|
|
4469
|
+
};
|
|
4470
|
+
this.enqueuePluginTask = async (api, plugin, uiId) => {
|
|
4471
|
+
const url = plugin.files[0] ?? plugin.reference;
|
|
4472
|
+
const id = repoPath(url).split("/").pop() ?? url;
|
|
4473
|
+
const params = {
|
|
4474
|
+
id,
|
|
4475
|
+
version: "nightly",
|
|
4476
|
+
selected_version: "nightly",
|
|
4477
|
+
repository: url,
|
|
4478
|
+
mode: "cache",
|
|
4479
|
+
channel: "default"
|
|
4480
|
+
};
|
|
4481
|
+
await this.post(this.route(api, "/manager/queue/task"), {
|
|
4482
|
+
ui_id: uiId,
|
|
4483
|
+
client_id: this.clientId,
|
|
4484
|
+
kind: "install",
|
|
4485
|
+
params
|
|
4486
|
+
});
|
|
4487
|
+
return id;
|
|
4488
|
+
};
|
|
4489
|
+
this.settleByHistory = async (api, what, uiId, landed, sentId) => {
|
|
4490
|
+
const route = this.route(api, "/manager/queue/history", `?ui_id=${encodeURIComponent(uiId)}`);
|
|
4491
|
+
const readEntry = async () => (await this.getValid(route, TaskHistory_ark)).history.status ?? null;
|
|
4492
|
+
const entry = await this.waitFor(what, async () => {
|
|
4493
|
+
const status = await readEntry();
|
|
4494
|
+
if (status != null) return status;
|
|
4495
|
+
if (await this.restartIdleQueue(api) !== "drained") return null;
|
|
4496
|
+
const late = await readEntry();
|
|
4497
|
+
if (late != null) return late;
|
|
4498
|
+
throw new InstallFailed("the task left the queue with no result (a queue/reset from the Manager UI or another client removes it)");
|
|
4499
|
+
});
|
|
4500
|
+
if (entry.status_str === "success" || entry.status_str === "skip") {
|
|
4501
|
+
if (await this.endState(landed) !== false) return;
|
|
4502
|
+
throw new InstallFailed(sentId != null ? `the Manager reported success, but this pack does not read installed: another pack holds the id "${sentId}" it installs by` : "the Manager reported success, but it does not read installed afterwards");
|
|
4503
|
+
}
|
|
4504
|
+
const messages = entry.messages ?? [];
|
|
4505
|
+
const gate = messages.length === 1 && messages[0] === "failed" ? ": refused by its security policy, which allows installs only with security_level normal or below AND either ComfyUI listening on localhost or network_mode personal_cloud (the ComfyUI console names the rule)" : "";
|
|
4506
|
+
throw new InstallFailed(`the Manager reports ${entry.status_str}: ${messages.join(" | ")}${gate}`);
|
|
4507
|
+
};
|
|
4508
|
+
this.restartIdleQueue = async (api) => {
|
|
4509
|
+
const status = await this.getValid(this.route(api, "/manager/queue/status"), QueueStatus_ark);
|
|
4510
|
+
if (status.is_processing) return "running";
|
|
4511
|
+
if ((status.pending_count ?? (status.total_count ?? 0) - (status.done_count ?? 0)) <= 0) return "drained";
|
|
4512
|
+
await this.post(this.route(api, "/manager/queue/start"));
|
|
4513
|
+
return "restarted";
|
|
4514
|
+
};
|
|
4515
|
+
this.settleByDrain = async (api, what, landed) => {
|
|
4516
|
+
await this.waitFor(what, async () => await this.restartIdleQueue(api) === "drained" ? true : null);
|
|
4517
|
+
const state = await this.endState(landed);
|
|
4518
|
+
if (state === true) return;
|
|
4519
|
+
if (state === null) throw new OutcomeUnknown("the queue drained, but the lists cannot say whether it is installed");
|
|
4520
|
+
throw new InstallFailed(`the Manager queue drained but it is not installed; ComfyUI-Manager ${api.version} reports why only over its websocket (cm-queue-status) and in the ComfyUI console`);
|
|
4521
|
+
};
|
|
4522
|
+
this.endState = async (landed) => {
|
|
3667
4523
|
try {
|
|
3668
|
-
|
|
3669
|
-
return await this.fetchGetJSON(`/customnode/getlist?mode=${mode}${skip_update}`, ComfyManagerAPIPluginList_ark);
|
|
4524
|
+
return await landed();
|
|
3670
4525
|
} catch (exception) {
|
|
3671
|
-
|
|
3672
|
-
logError("node list retrieveal failed");
|
|
3673
|
-
throw exception;
|
|
4526
|
+
throw new OutcomeUnknown(`the task ran, but its end state could not be read: ${errorText(exception)}`);
|
|
3674
4527
|
}
|
|
3675
4528
|
};
|
|
3676
|
-
this.
|
|
4529
|
+
this.runInstall = async (what, p) => {
|
|
4530
|
+
const host = this.host.getServerHostHTTP();
|
|
3677
4531
|
try {
|
|
3678
|
-
await this.
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
4532
|
+
const api = await this.api();
|
|
4533
|
+
const s = this.strategy(api);
|
|
4534
|
+
const uiId = nanoid();
|
|
4535
|
+
const sentId = await p.enqueue(api, uiId);
|
|
4536
|
+
await this.post(this.route(api, "/manager/queue/start"));
|
|
4537
|
+
await s.settle(what, uiId, () => p.landed(s, api), sentId);
|
|
4538
|
+
logSuccess(`${what} installed`);
|
|
4539
|
+
return "installed";
|
|
3682
4540
|
} catch (exception) {
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
4541
|
+
if (exception instanceof OutcomeUnknown) {
|
|
4542
|
+
logError(`${what}: OUTCOME UNKNOWN on ${host}: ${exception.message}. The Manager may still be installing it: refetch the list (fetchModels / fetchPlugins) and read its status before installing again, a blind retry queues a second download`);
|
|
4543
|
+
return "unknown";
|
|
4544
|
+
}
|
|
4545
|
+
logError(`${what}: install failed on ${host}: ${errorText(exception)}`);
|
|
4546
|
+
return "failed";
|
|
4547
|
+
}
|
|
4548
|
+
};
|
|
4549
|
+
this.waitFor = async (what, check) => {
|
|
4550
|
+
const deadline = Date.now() + this.timing.installTimeoutMs;
|
|
4551
|
+
let lastAnswer = Date.now();
|
|
4552
|
+
for (;;) {
|
|
4553
|
+
try {
|
|
4554
|
+
const value = await check();
|
|
4555
|
+
lastAnswer = Date.now();
|
|
4556
|
+
if (value != null) return value;
|
|
4557
|
+
} catch (exception) {
|
|
4558
|
+
if (exception instanceof InstallFailed) throw exception;
|
|
4559
|
+
if (Date.now() - lastAnswer >= this.timing.pollGraceMs) throw new OutcomeUnknown(`the host gave no answer for ${this.timing.pollGraceMs} ms (manager.timing.pollGraceMs), last: ${errorText(exception)}`);
|
|
4560
|
+
logError(`${what}: poll failed, still waiting: ${errorText(exception)}`);
|
|
4561
|
+
}
|
|
4562
|
+
if (Date.now() >= deadline) throw new OutcomeUnknown(`still running after ${this.timing.installTimeoutMs} ms (manager.timing.installTimeoutMs)`);
|
|
4563
|
+
await new Promise((resolve) => setTimeout(resolve, this.timing.pollMs));
|
|
3686
4564
|
}
|
|
3687
4565
|
};
|
|
3688
|
-
this.
|
|
3689
|
-
const response = await this.host.fetch(
|
|
4566
|
+
this.post = async (route, body) => {
|
|
4567
|
+
const response = await this.host.fetch(route, {
|
|
3690
4568
|
method: "POST",
|
|
3691
4569
|
headers: { "Content-Type": "application/json" },
|
|
3692
|
-
body: JSON.stringify(body)
|
|
4570
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
3693
4571
|
});
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
if (
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
4572
|
+
const text = await response.text();
|
|
4573
|
+
if (!response.ok) throw new Error(`POST ${route} → ${response.status} ${text}`.trim());
|
|
4574
|
+
if (text === "") return null;
|
|
4575
|
+
try {
|
|
4576
|
+
return JSON.parse(text);
|
|
4577
|
+
} catch {
|
|
4578
|
+
return text;
|
|
4579
|
+
}
|
|
4580
|
+
};
|
|
4581
|
+
this.getJSON = async (route, validator) => {
|
|
4582
|
+
const response = await this.host.fetch(route);
|
|
4583
|
+
if (!response.ok) throw new Error(`GET ${route} → ${response.status} ${await response.text()}`.trim());
|
|
3702
4584
|
const jsonResult = await response.json();
|
|
3703
4585
|
if (validator) return softValidate(validator, jsonResult);
|
|
3704
4586
|
return jsonResult;
|
|
3705
4587
|
};
|
|
3706
|
-
this.
|
|
3707
|
-
|
|
4588
|
+
this.getValid = async (route, schema) => {
|
|
4589
|
+
const res = schema(await this.getJSON(route));
|
|
4590
|
+
if (res instanceof type.errors) throw new Error(`GET ${route}: ${res.summary}`);
|
|
4591
|
+
return res;
|
|
3708
4592
|
};
|
|
3709
4593
|
}
|
|
3710
4594
|
get registry() {
|
|
@@ -4026,26 +4910,8 @@ var ComfyHost = class {
|
|
|
4026
4910
|
constructor(data) {
|
|
4027
4911
|
this.data = data;
|
|
4028
4912
|
this.uploader = new ComfyUploader(this);
|
|
4029
|
-
this.matchRequirements = (requirements) =>
|
|
4030
|
-
|
|
4031
|
-
for (const req of requirements) {
|
|
4032
|
-
if (req.optional) continue;
|
|
4033
|
-
if (req.type === "customNodesByNodeKey") {
|
|
4034
|
-
if (!(repo.plugins_byNodeKey.get(req.nodeName) ?? []).find((i) => this.manager.isPluginInstalled(i.title))) return false;
|
|
4035
|
-
} else if (req.type === "customNodesByTitle") {
|
|
4036
|
-
const plugin = repo.plugins_byTitle.get(req.title);
|
|
4037
|
-
if (plugin == null) continue;
|
|
4038
|
-
if (!this.manager.isPluginInstalled(plugin.title)) return false;
|
|
4039
|
-
} else if (req.type === "customNodesByURI") {
|
|
4040
|
-
const plugin = repo.plugins_byFile.get(req.uri);
|
|
4041
|
-
if (plugin == null) continue;
|
|
4042
|
-
if (!this.manager.isPluginInstalled(plugin.title)) return false;
|
|
4043
|
-
} else if (req.type === "modelInManager") {
|
|
4044
|
-
if (!this.manager.isModelInstalled(req.modelName)) return false;
|
|
4045
|
-
}
|
|
4046
|
-
}
|
|
4047
|
-
return true;
|
|
4048
|
-
};
|
|
4913
|
+
this.matchRequirements = (requirements) => this.manager.matchRequirements(requirements);
|
|
4914
|
+
this.checkRequirements = (requirements) => this.manager.checkRequirements(requirements);
|
|
4049
4915
|
this.serverLogs = [];
|
|
4050
4916
|
this.wantLog = true;
|
|
4051
4917
|
this.maxLogs = 200;
|
|
@@ -4309,6 +5175,7 @@ var ComfyHost = class {
|
|
|
4309
5175
|
this.onLogs = null;
|
|
4310
5176
|
this.comfySessionId = "temp";
|
|
4311
5177
|
this._unknownBinaryFrameTypes = /* @__PURE__ */ new Set();
|
|
5178
|
+
this._unknownWsEventTypes = /* @__PURE__ */ new Set();
|
|
4312
5179
|
this.status = null;
|
|
4313
5180
|
this.lastWsMessageAt = null;
|
|
4314
5181
|
this.base = parseHostBase(this.data);
|
|
@@ -4548,9 +5415,26 @@ var ComfyHost = class {
|
|
|
4548
5415
|
}
|
|
4549
5416
|
return;
|
|
4550
5417
|
}
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
5418
|
+
let msg_ = JSON.parse(String(e.data));
|
|
5419
|
+
const rec = typeof msg_ === "object" && msg_ != null ? msg_ : null;
|
|
5420
|
+
const eventType = rec != null && "type" in rec && typeof rec.type === "string" ? rec.type : null;
|
|
5421
|
+
if (eventType != null && isIgnoredWsEventType(eventType)) return;
|
|
5422
|
+
if (eventType == null || !isRoutedWsEventType(eventType)) {
|
|
5423
|
+
const key = eventType ?? "<no type>";
|
|
5424
|
+
if (this._unknownWsEventTypes.has(key)) return;
|
|
5425
|
+
this._unknownWsEventTypes.add(key);
|
|
5426
|
+
console.error(`🔴 unknown ws event type ${JSON.stringify(key)} from host ${this.data.id}, ignored (reported once per connection)`);
|
|
5427
|
+
return;
|
|
5428
|
+
}
|
|
5429
|
+
if (eventType === "executing" && this.activePromptID != null && rec != null) {
|
|
5430
|
+
const data = Reflect.get(rec, "data");
|
|
5431
|
+
if (typeof data === "object" && data != null && !("prompt_id" in data)) msg_ = {
|
|
5432
|
+
type: eventType,
|
|
5433
|
+
data: {
|
|
5434
|
+
...data,
|
|
5435
|
+
prompt_id: this.activePromptID
|
|
5436
|
+
}
|
|
5437
|
+
};
|
|
4554
5438
|
}
|
|
4555
5439
|
const res = WsMsg_ark(msg_);
|
|
4556
5440
|
if (res instanceof type.errors) {
|
|
@@ -4564,7 +5448,11 @@ var ComfyHost = class {
|
|
|
4564
5448
|
this.comfySessionId = msg.data.sid;
|
|
4565
5449
|
this._sessionResolve?.();
|
|
4566
5450
|
this._sessionResolve = null;
|
|
4567
|
-
if (sidChanged)
|
|
5451
|
+
if (sidChanged) {
|
|
5452
|
+
this._unknownWsEventTypes.clear();
|
|
5453
|
+
this._unknownBinaryFrameTypes.clear();
|
|
5454
|
+
this.onSession?.(msg.data.sid);
|
|
5455
|
+
}
|
|
4568
5456
|
}
|
|
4569
5457
|
this.status = msg.data.status;
|
|
4570
5458
|
this.onStatus?.({ queueRemaining: msg.data.status?.exec_info?.queue_remaining ?? 0 });
|
|
@@ -4579,7 +5467,7 @@ var ComfyHost = class {
|
|
|
4579
5467
|
this.routeOrBuffer(activePromptID, msg);
|
|
4580
5468
|
return;
|
|
4581
5469
|
}
|
|
4582
|
-
if (msg.type === "execution_start" || msg.type === "execution_cached" || msg.type === "execution_error" || msg.type === "execution_success" || msg.type === "executing" || msg.type === "executed" || msg.type === "progress_state") {
|
|
5470
|
+
if (msg.type === "execution_start" || msg.type === "execution_cached" || msg.type === "execution_error" || msg.type === "execution_interrupted" || msg.type === "execution_success" || msg.type === "executing" || msg.type === "executed" || msg.type === "progress_state") {
|
|
4583
5471
|
this.routeOrBuffer(msg.data.prompt_id, msg);
|
|
4584
5472
|
return;
|
|
4585
5473
|
}
|
|
@@ -4591,8 +5479,6 @@ var ComfyHost = class {
|
|
|
4591
5479
|
this.onLogs?.(msg.data);
|
|
4592
5480
|
return;
|
|
4593
5481
|
}
|
|
4594
|
-
console.log("❌", "Unknown message:", msg);
|
|
4595
|
-
logError("Unknown message type: " + JSON.stringify(msg.type));
|
|
4596
5482
|
}
|
|
4597
5483
|
};
|
|
4598
5484
|
//#endregion
|
|
@@ -4921,6 +5807,7 @@ const _getKnownModels = (DB) => {
|
|
|
4921
5807
|
}
|
|
4922
5808
|
const knownModelList = canonical.concat(extraModels.models);
|
|
4923
5809
|
for (const modelInfo of knownModelList) DB.knownModels.set(modelInfo.name, modelInfo);
|
|
5810
|
+
DB.modelRows = knownModelList;
|
|
4924
5811
|
if (DB.opts.genTypes) {
|
|
4925
5812
|
let out1 = "";
|
|
4926
5813
|
const uniqCategories = knownModelList.reduce((acc, cur) => {
|
|
@@ -5089,6 +5976,7 @@ var ComfyRegistry = class ComfyRegistry {
|
|
|
5089
5976
|
this.plugins_byNodeKey = /* @__PURE__ */ new Map();
|
|
5090
5977
|
this.customNodes_byPluginName = /* @__PURE__ */ new Map();
|
|
5091
5978
|
this.knownModels = /* @__PURE__ */ new Map();
|
|
5979
|
+
this.modelRows = [];
|
|
5092
5980
|
this.alterations = [];
|
|
5093
5981
|
this.githubStats = /* @__PURE__ */ new Map();
|
|
5094
5982
|
this.report = new ManagerParseReport();
|
|
@@ -5250,4 +6138,4 @@ var ComfyTS = class ComfyTS {
|
|
|
5250
6138
|
//#endregion
|
|
5251
6139
|
export { ComfySchema as a, importSharp as i, settingsPathFor as n, readableStringify as r, ComfyTS as t };
|
|
5252
6140
|
|
|
5253
|
-
//# sourceMappingURL=state-
|
|
6141
|
+
//# sourceMappingURL=state-C067Kbew.js.map
|