comfy-ts 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +20 -13
  2. package/dist/{DefinedWorkflow-BJgt5t0x.js → DefinedWorkflow-BatWaZO1.js} +199 -16
  3. package/dist/DefinedWorkflow-BatWaZO1.js.map +1 -0
  4. package/dist/{DraftsSt-dizp3VcC.js → LogsSt-DFxzQfDc.js} +152 -4
  5. package/dist/LogsSt-DFxzQfDc.js.map +1 -0
  6. package/dist/cli.js +7 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +284 -35
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +125 -7
  11. package/dist/index.d.ts +125 -7
  12. package/dist/index.js +282 -37
  13. package/dist/index.js.map +1 -1
  14. package/dist/run-serve-_nrvJYyt.js +1948 -0
  15. package/dist/run-serve-_nrvJYyt.js.map +1 -0
  16. package/dist/{run-tui-JxlEbb_f.js → run-tui-BPw-SZYW.js} +106 -157
  17. package/dist/run-tui-BPw-SZYW.js.map +1 -0
  18. package/dist/serve-web.js +432 -72
  19. package/dist/{state-CaHeDL-0.js → state-B-boDz-Z.js} +180 -45
  20. package/dist/state-B-boDz-Z.js.map +1 -0
  21. package/dist/web.d.ts +109 -7
  22. package/dist/web.js +235 -36
  23. package/dist/web.js.map +1 -1
  24. package/examples/README.md +1 -0
  25. package/examples/comfy-cloud/sdk.d.ts +4066 -321
  26. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +18 -2
  27. package/examples/rvion/07-local-llm-text-gen.cflow.ts +220 -0
  28. package/examples/web/tsconfig.json +3 -0
  29. package/extra/README.md +32 -0
  30. package/extra/comfyui-textgen-stream/README.md +35 -0
  31. package/extra/comfyui-textgen-stream/__init__.py +166 -0
  32. package/extra/scripts/fetch_text_encoder.py +137 -0
  33. package/package.json +6 -3
  34. package/src/cli/comfy-ts-cli.ts +3 -1
  35. package/src/cli/serve/ServeApp.ts +754 -40
  36. package/src/cli/serve/applyVarPayload.ts +10 -3
  37. package/src/cli/serve/describeVar.ts +47 -7
  38. package/src/cli/serve/managerOnlyLoras.ts +27 -0
  39. package/src/cli/serve/run-serve.ts +35 -38
  40. package/src/cli/serve/serveSettings.ts +86 -0
  41. package/src/cli/serve/startupPrint.ts +111 -0
  42. package/src/cli/serve/web/api.ts +97 -1
  43. package/src/cli/serve/web/components/App.tsx +61 -22
  44. package/src/cli/serve/web/components/Gallery.tsx +243 -30
  45. package/src/cli/serve/web/components/Icon.tsx +160 -0
  46. package/src/cli/serve/web/components/PromptEnhancer.tsx +12 -9
  47. package/src/cli/serve/web/components/Sidebar.tsx +43 -19
  48. package/src/cli/serve/web/components/VarsForm.tsx +440 -91
  49. package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
  50. package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
  51. package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
  52. package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
  53. package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
  54. package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
  55. package/src/cli/serve/web/llm.ts +1 -1
  56. package/src/cli/serve/web/logWeb.ts +6 -0
  57. package/src/cli/serve/web/state/EnhancerSt.ts +8 -15
  58. package/src/cli/serve/web/state/FormSt.ts +66 -17
  59. package/src/cli/serve/web/state/RunSt.ts +22 -1
  60. package/src/cli/serve/web/state/WebSt.ts +518 -14
  61. package/src/cli/serve/web/state/lightbox.ts +44 -0
  62. package/src/cli/serve/web/state/moduleTree.ts +52 -0
  63. package/src/cli/serve/web/state/payload.ts +44 -2
  64. package/src/cli/serve/web/state/urlSelection.ts +53 -0
  65. package/src/cli/serve/web/styles.ts +413 -57
  66. package/src/cli/serve/web/tsconfig.json +4 -0
  67. package/src/cli/tui/components/PickerOverlays.tsx +37 -0
  68. package/src/cli/tui/components/StatusBar.tsx +14 -1
  69. package/src/cli/tui/components/TuiApp.tsx +5 -2
  70. package/src/cli/tui/state/HostSt.ts +3 -2
  71. package/src/cli/tui/state/PickerSt.ts +48 -2
  72. package/src/cli/tui/state/TreeSt.ts +1 -1
  73. package/src/cli/tui/state/TuiSt.ts +2 -1
  74. package/src/coreExports.ts +8 -1
  75. package/src/graph/ComfyNode.ts +58 -1
  76. package/src/host/ComfyHost.ts +13 -2
  77. package/src/host/ComfyManager.ts +31 -13
  78. package/src/host/loraInfoCache.ts +35 -1
  79. package/src/host/loraManagerApi.ts +94 -0
  80. package/src/index.ts +2 -0
  81. package/src/promptEnhancers.ts +102 -0
  82. package/src/runner/ComfyExecution.ts +61 -6
  83. package/src/runner/ComfyWorkflow.ts +18 -4
  84. package/src/runner/ComfyWsApi.ts +3 -0
  85. package/src/runner/describePromptRejection.ts +34 -0
  86. package/src/sdk-generator/ComfySchema.ts +17 -4
  87. package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
  88. package/src/utils/ansi.ts +13 -0
  89. package/src/utils/matchesRegex.ts +13 -0
  90. package/src/utils/safeName.ts +29 -0
  91. package/src/utils/stringMap.ts +9 -0
  92. package/src/vars/ComfyVars.ts +61 -10
  93. package/src/vars/presets.ts +17 -0
  94. package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
  95. package/dist/DraftsSt-dizp3VcC.js.map +0 -1
  96. package/dist/run-serve-D1Tsuru9.js +0 -1162
  97. package/dist/run-serve-D1Tsuru9.js.map +0 -1
  98. package/dist/run-tui-JxlEbb_f.js.map +0 -1
  99. package/dist/state-CaHeDL-0.js.map +0 -1
  100. package/src/cli/serve/promptEnhancers.ts +0 -69
  101. package/src/cli/serve/safeName.ts +0 -12
@@ -1,4 +1,4 @@
1
- import { A as logInfo, D as resolveComfyStorage, E as getComfyStorage, M as sha1Hex, N as sha1HexOfString, O as isQuiet, T as bang, j as logSuccess, k as logError, t as DefinedWorkflow, w as extractErrorMessage } from "./DefinedWorkflow-BJgt5t0x.js";
1
+ import { G as resolveComfyStorage, H as isRecord$1, J as logInfo, K as isQuiet, Q as sha1HexOfString, R as ansi, U as bang, V as extractErrorMessage, W as getComfyStorage, X as statelessRegex, Y as logSuccess, Z as sha1Hex, q as logError, t as DefinedWorkflow } from "./DefinedWorkflow-BatWaZO1.js";
2
2
  import { basename, join } from "pathe";
3
3
  import { scope, type } from "arktype";
4
4
  import { nanoid } from "nanoid";
@@ -375,6 +375,25 @@ const defaultValueForWidget = (p) => {
375
375
  };
376
376
  //#endregion
377
377
  //#region src/sdk-generator/comfyui-sdk-codegen.ts
378
+ const isScalar = (x) => typeof x === "string" || typeof x === "number" || typeof x === "boolean";
379
+ /** a dynamic-combo branch input, typed the way its dotted prompt key is filled: inline enums
380
+ * and COMBO option lists become literal unions, everything else stays a named slot */
381
+ const branchInputType = (entry) => {
382
+ const opts = isRecord(entry.opts) ? entry.opts : null;
383
+ const scalars = (Array.isArray(entry.type) ? entry.type : Array.isArray(opts?.["options"]) ? opts["options"] : []).filter(isScalar);
384
+ if (scalars.length > 0) return scalars.map((o) => JSON.stringify(o)).join(" | ");
385
+ if (typeof entry.type === "string") return `Accepts[${JSON.stringify(entry.type)}]`;
386
+ return "string | number | boolean";
387
+ };
388
+ /** `& ({key:'a'; 'name.x'?: …} | {key:'b'})` — one member per branch, so a key from a branch
389
+ * you did not select is a type error. Branch fields are optional: ComfyNode fills them
390
+ * from the schema at serialization (agent/architecture.md, dynamic-combo fill) */
391
+ const dynamicComboUnion = (p) => {
392
+ return ` & (${p.options.map((opt) => {
393
+ const fields = opt.inputs.map((e) => `${escapeJSKey(`${p.name}.${e.name}`)}?: ${branchInputType(e)}`);
394
+ return `{ ${[`${p.nameEscaped}${p.keyOptional ? "?" : ""}: ${JSON.stringify(opt.key)}`, ...fields].join("; ")} }`;
395
+ }).join(" | ")})`;
396
+ };
378
397
  /**
379
398
  * convert a host id to the namespace name it gets inside the global `Comfy` namespace
380
399
  * e.g. 'windows-1' -> 'Windows1', 'my_cloud.instance' -> 'MyCloudInstance'
@@ -427,6 +446,7 @@ function codegenSDK(opts) {
427
446
  b.indent();
428
447
  for (const n of nodes) {
429
448
  p(`${escapeJSKey(n.nodeKey)}: {`);
449
+ const comboSuffixes = [];
430
450
  for (const i of n.inputs) {
431
451
  const kind = classifySchemaInput(i);
432
452
  if (kind.kind === "dynamic-container") {
@@ -437,6 +457,16 @@ function codegenSDK(opts) {
437
457
  });
438
458
  continue;
439
459
  }
460
+ if (kind.kind === "dynamic-combo") {
461
+ const optsDyn = typeof i.opts === "string" ? null : i.opts;
462
+ comboSuffixes.push(dynamicComboUnion({
463
+ name: i.nameInComfy,
464
+ nameEscaped: i.nameInComfyEscaped,
465
+ options: kind.options,
466
+ keyOptional: optsDyn?.default !== void 0 || !i.required
467
+ }));
468
+ continue;
469
+ }
440
470
  const opts_ = typeof i.opts === "string" ? null : i.opts;
441
471
  let type = `Accepts[${JSON.stringify(i.typeName)}]`;
442
472
  const comboOptions = i.typeName === "COMBO" && Array.isArray(opts_?.options) ? opts_.options.filter((o) => typeof o === "string" || typeof o === "number" || typeof o === "boolean") : [];
@@ -453,7 +483,7 @@ function codegenSDK(opts) {
453
483
  const canBeOmmited = opts_?.default !== void 0 || !i.required;
454
484
  p(` ${i.nameInComfyEscaped}${canBeOmmited ? "?" : ""}: ${type}`);
455
485
  }
456
- p(`},`);
486
+ p(`}${comboSuffixes.join("")},`);
457
487
  }
458
488
  b.deindent();
459
489
  p("}");
@@ -622,7 +652,8 @@ var ComfySchema = class {
622
652
  };
623
653
  this.getLoras = (filter) => {
624
654
  const all = this.stringValues("LoraLoader.lora_name");
625
- return filter == null ? all : all.filter((n) => filter.test(n));
655
+ const stateless = filter == null ? null : statelessRegex(filter);
656
+ return stateless == null ? all : all.filter((n) => stateless.test(n));
626
657
  };
627
658
  this.getImages = () => {
628
659
  return this.stringValues("LoadImage.image");
@@ -756,15 +787,19 @@ var ComfySchema = class {
756
787
  comfyUnionDef: slotType
757
788
  }).unionName);
758
789
  else throw new Error(`invalid schema (${JSON.stringify(slotType)}) for input "${ipt.name}" in node "${nodeNameInComfy}" (type: ${typeof slotType}; expected: Array | string)`);
759
- const isAutogrowContainer = typeof slotType === "string" && classifyWidgetInput({
790
+ const widgetKind = typeof slotType === "string" ? classifyWidgetInput({
760
791
  name: ipt.name,
761
792
  type: slotType,
762
793
  opts: slotOpts
763
- }).kind === "dynamic-container";
794
+ }) : null;
795
+ const isAutogrowContainer = widgetKind?.kind === "dynamic-container";
764
796
  if (isAutogrowContainer) {
765
797
  const instType = containerInstanceSlotType(slotOpts);
766
798
  if (instType != null) this.knownSlotTypes.add(asComfyNodeSlotTypeName(instType));
767
799
  }
800
+ if (widgetKind?.kind === "dynamic-combo") {
801
+ for (const opt of widgetKind.options) for (const entry of opt.inputs) if (typeof entry.type === "string") this.knownSlotTypes.add(asComfyNodeSlotTypeName(entry.type));
802
+ }
768
803
  node.inputs.push({
769
804
  slotName: inputSlotName,
770
805
  required: ipt.required && !isAutogrowContainer,
@@ -815,7 +850,7 @@ var ComfySchema = class {
815
850
  };
816
851
  //#endregion
817
852
  //#region package.json
818
- var version = "2.7.0";
853
+ var version = "2.8.0";
819
854
  //#endregion
820
855
  //#region src/litegraph/LiteGraphLinkID.ts
821
856
  const asLiteGraphLinkID = (id) => id;
@@ -1688,6 +1723,34 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1688
1723
  return prompt;
1689
1724
  };
1690
1725
  //#endregion
1726
+ //#region src/runner/describePromptRejection.ts
1727
+ function str(v) {
1728
+ return typeof v === "string" ? v.trim() : "";
1729
+ }
1730
+ function describePromptRejection(body) {
1731
+ if (!isRecord$1(body)) return "no reason given";
1732
+ const parts = [];
1733
+ const err = body["error"];
1734
+ if (isRecord$1(err)) {
1735
+ const head = str(err["message"]);
1736
+ const detail = str(err["details"]);
1737
+ if (head !== "") parts.push(detail === "" ? head : `${head} (${detail})`);
1738
+ }
1739
+ const nodes = body["node_errors"];
1740
+ if (isRecord$1(nodes)) for (const [nodeId, raw] of Object.entries(nodes)) {
1741
+ if (!isRecord$1(raw)) continue;
1742
+ const list = raw["errors"];
1743
+ if (!Array.isArray(list)) continue;
1744
+ for (const e of list) {
1745
+ if (!isRecord$1(e)) continue;
1746
+ const detail = str(e["details"]);
1747
+ const msg = str(e["message"]);
1748
+ parts.push(`node ${nodeId}: ${[msg, detail].filter((x) => x !== "").join(" — ")}`);
1749
+ }
1750
+ }
1751
+ return parts.length === 0 ? "no reason given" : parts.join(" · ");
1752
+ }
1753
+ //#endregion
1691
1754
  //#region src/errors/InvalidPromptError.ts
1692
1755
  var InvalidPromptError = class extends Error {
1693
1756
  constructor(message, snapshot, details) {
@@ -1733,6 +1796,7 @@ var ComfyNodeOutput = class {
1733
1796
  };
1734
1797
  //#endregion
1735
1798
  //#region src/graph/ComfyNode.ts
1799
+ const isScalarValue = (x) => typeof x === "string" || typeof x === "number" || typeof x === "boolean";
1736
1800
  /** ComfyNode
1737
1801
  * - correspond to a signal in the graph
1738
1802
  * - belongs to a script
@@ -1825,13 +1889,27 @@ var ComfyNode = class ComfyNode {
1825
1889
  _convertPromptExtToPrompt(promptExt) {
1826
1890
  const inputs = {};
1827
1891
  const _done = /* @__PURE__ */ new Set();
1892
+ /** every dotted key of every branch: the selected ones are written here, the rest are dropped */
1893
+ const _comboBranchKeys = /* @__PURE__ */ new Set();
1828
1894
  for (const i of this.$schema.inputs) {
1829
1895
  _done.add(i.nameInComfy);
1896
+ const kind = classifySchemaInput(i);
1897
+ if (kind.kind === "dynamic-combo") {
1898
+ this._writeDynamicCombo({
1899
+ name: i.nameInComfy,
1900
+ options: kind.options,
1901
+ defaultKey: kind.defaultKey,
1902
+ provided: promptExt.inputs,
1903
+ out: inputs,
1904
+ claimed: _comboBranchKeys
1905
+ });
1906
+ continue;
1907
+ }
1830
1908
  const value = this.serializeValue(i.nameInComfy, promptExt.inputs[i.nameInComfy]);
1831
1909
  if (value !== void 0) inputs[i.nameInComfy] = value;
1832
1910
  }
1833
1911
  for (const [nameInComfy, rawVal] of Object.entries(promptExt.inputs)) {
1834
- if (_done.has(nameInComfy)) continue;
1912
+ if (_done.has(nameInComfy) || _comboBranchKeys.has(nameInComfy)) continue;
1835
1913
  inputs[nameInComfy] = this.serializeValue(nameInComfy, rawVal);
1836
1914
  }
1837
1915
  return {
@@ -1839,6 +1917,31 @@ var ComfyNode = class ComfyNode {
1839
1917
  inputs
1840
1918
  };
1841
1919
  }
1920
+ /** dynamic combo → the key plus ONLY the selected branch's dotted inputs, absent ones
1921
+ * filled from the schema (agent/architecture.md, dynamic-combo fill). The host declares
1922
+ * those branch inputs required and default-fills none of them */
1923
+ _writeDynamicCombo(p) {
1924
+ for (const opt of p.options) for (const e of opt.inputs) p.claimed.add(`${p.name}.${e.name}`);
1925
+ const raw = p.provided[p.name];
1926
+ const key = typeof raw === "string" ? raw : p.defaultKey;
1927
+ const branch = p.options.find((o) => o.key === key);
1928
+ if (branch == null) {
1929
+ const known = p.options.map((o) => o.key).join(", ");
1930
+ console.error(`🔴 unknown "${p.name}" option ${JSON.stringify(key)} (known: ${known})`);
1931
+ this.graph.recordProblem(`🔴 unknown "${p.name}" option ${JSON.stringify(key)} on ${this.$schema.nodeKey}#${this.uid} (known: ${known})`);
1932
+ return;
1933
+ }
1934
+ p.out[p.name] = key;
1935
+ for (const e of branch.inputs) {
1936
+ const dotted = `${p.name}.${e.name}`;
1937
+ const given = p.provided[dotted];
1938
+ p.out[dotted] = given === void 0 ? defaultValueForWidget({
1939
+ type: typeof e.type === "string" ? e.type : "COMBO",
1940
+ opts: e.opts,
1941
+ enumValues: Array.isArray(e.type) ? e.type.filter(isScalarValue) : void 0
1942
+ }) : this.serializeValue(dotted, given);
1943
+ }
1944
+ }
1842
1945
  /** return the list of nodes piped into this node */
1843
1946
  _incomingNodes() {
1844
1947
  const incomingNodes = [];
@@ -2301,7 +2404,8 @@ const types$1 = scope({
2301
2404
  node: "ComfyNodeID",
2302
2405
  output: {
2303
2406
  "previews?": [{ filepath: "string" }, "[]"],
2304
- "images?": "ComfyImageInfo[]"
2407
+ "images?": "ComfyImageInfo[]",
2408
+ "text?": "unknown[]"
2305
2409
  },
2306
2410
  prompt_id: "PromptID"
2307
2411
  },
@@ -2610,6 +2714,15 @@ var ComfyExecution = class {
2610
2714
  };
2611
2715
  this.onExecuted = (msg) => {
2612
2716
  const promptNodeID = msg.data.node;
2717
+ for (const entry of msg.data.output?.text ?? []) {
2718
+ if (typeof entry !== "string") continue;
2719
+ const nodeKey = this.workflow.data.apiJson?.[promptNodeID]?.class_type ?? null;
2720
+ this.texts.push({
2721
+ nodeId: promptNodeID,
2722
+ nodeKey,
2723
+ text: entry
2724
+ });
2725
+ }
2613
2726
  const images = msg.data.output?.images;
2614
2727
  if (images) for (const img of images) this.pendingPromises.push(this.retrieveImage(img, promptNodeID).catch((e) => {
2615
2728
  console.error(`🔴 failed to retrieve ${img.filename}:`, e);
@@ -2727,6 +2840,9 @@ var ComfyExecution = class {
2727
2840
  }), promptNodeID);
2728
2841
  };
2729
2842
  this.images = [];
2843
+ this.texts = [];
2844
+ this.progressTexts = /* @__PURE__ */ new Map();
2845
+ this.progressText = null;
2730
2846
  this.alreadyDone = false;
2731
2847
  this._finish = async (p) => {
2732
2848
  if (this.alreadyDone) throw new Error(`❌ invariant violation: already finished`);
@@ -2762,7 +2878,9 @@ var ComfyExecution = class {
2762
2878
  ...this.progressGlobal,
2763
2879
  promptId: this.data.id,
2764
2880
  nodeName: this.workflow.currentExecutingNode?.$schema.nameInComfy ?? null,
2765
- elapsedMs: Date.now() - this.startedAt
2881
+ elapsedMs: Date.now() - this.startedAt,
2882
+ nodeProgress: this.workflow.currentExecutingNode?.progress ?? null,
2883
+ progressText: this.progressText
2766
2884
  };
2767
2885
  }
2768
2886
  emitProgress() {
@@ -2773,16 +2891,21 @@ var ComfyExecution = class {
2773
2891
  const filled = Math.round(p.percent / 100 * width);
2774
2892
  const bar = "█".repeat(filled) + "░".repeat(width - filled);
2775
2893
  const node = p.nodeName ? ` · ${p.nodeName}` : "";
2776
- const line = `▶ [${bar}] ${p.percent.toFixed(0).padStart(3)}%${node} · ${(p.elapsedMs / 1e3).toFixed(0)}s`;
2777
- if (line === this._lastLoggedLine) return;
2778
- this._lastLoggedLine = line;
2779
- if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}`);
2780
- else console.log(line);
2894
+ const count = p.nodeProgress ? ` ${p.nodeProgress.value}/${p.nodeProgress.max}` : "";
2895
+ const line = `▶ [${bar}] ${p.percent.toFixed(0).padStart(3)}%${node}${count} · ${(p.elapsedMs / 1e3).toFixed(0)}s`;
2896
+ const tail = p.progressText?.replaceAll("\n", " ").trimEnd().slice(-60);
2897
+ const full = tail == null || tail === "" ? line : `${line} · …${tail}`;
2898
+ if (full === this._lastLoggedLine) return;
2899
+ this._lastLoggedLine = full;
2900
+ if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${full}`);
2901
+ else console.log(full);
2781
2902
  }
2782
2903
  finishProgressLine() {
2783
2904
  if (!this.logProgress) return;
2784
2905
  const p = this.progress;
2785
- const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${this.images.length} image(s)`;
2906
+ const outputs = [`${this.images.length} image(s)`];
2907
+ if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
2908
+ const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
2786
2909
  if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
2787
2910
  else console.log(line);
2788
2911
  }
@@ -2824,6 +2947,16 @@ var ComfyExecution = class {
2824
2947
  if (uid == null) return false;
2825
2948
  return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
2826
2949
  }
2950
+ /** @internal a live-text frame for one node */
2951
+ onProgressText(p) {
2952
+ this.progressTexts.set(p.nodeId, p.text);
2953
+ this.progressText = p.text;
2954
+ this.emitProgress();
2955
+ }
2956
+ /** the last text output, the one a single-generator workflow means by "the result" */
2957
+ get text() {
2958
+ return this.texts.at(-1)?.text ?? null;
2959
+ }
2827
2960
  update(data) {
2828
2961
  Object.assign(this.data, data);
2829
2962
  }
@@ -2853,30 +2986,6 @@ function rewriteSaveNodesToWebsocket(apiJson) {
2853
2986
  //#region src/utils/deepCopyNaive.ts
2854
2987
  const deepCopyNaive = (x) => JSON.parse(JSON.stringify(x));
2855
2988
  //#endregion
2856
- //#region src/utils/ansi.ts
2857
- const codes = {
2858
- bold: [1, 22],
2859
- underline: [4, 24],
2860
- red: [31, 39],
2861
- green: [32, 39],
2862
- yellow: [33, 39],
2863
- blue: [34, 39],
2864
- greenBright: [92, 39]
2865
- };
2866
- function styler(open = "", close = "") {
2867
- const fn = (s) => open + s + close;
2868
- return new Proxy(fn, { get(_target, prop) {
2869
- const c = codes[prop];
2870
- if (c == null) throw new Error(`unknown ansi style: ${prop}`);
2871
- return styler(`${open}\x1b[${c[0]}m`, `\x1b[${c[1]}m${close}`);
2872
- } });
2873
- }
2874
- const ansi = styler();
2875
- const ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]|\x1b[A-Za-z]/g;
2876
- function stripAnsi(s) {
2877
- return s.replace(ANSI_RE, "");
2878
- }
2879
- //#endregion
2880
2989
  //#region src/utils/printArkResultInConsole.ts
2881
2990
  const MAX_PRINTED_ERRORS = 10;
2882
2991
  function printArkResultInConsole(res) {
@@ -3107,6 +3216,7 @@ var ComfyWorkflow = class {
3107
3216
  return execution;
3108
3217
  };
3109
3218
  this.start = async (p = {}) => {
3219
+ if (this.host.ws == null) throw new Error(`🔴 host '${this.host.data.id}' was never connected — call \`await host.connect()\` before running a workflow`);
3110
3220
  this.resetRunState();
3111
3221
  const snapshot = {
3112
3222
  apiJson: deepCopyNaive(this.toApiJson(p.idMode ?? "use_stringified_numbers_only")),
@@ -3131,8 +3241,9 @@ var ComfyWorkflow = class {
3131
3241
  headers: { "Content-Type": "application/json" },
3132
3242
  body: JSON.stringify(out)
3133
3243
  });
3134
- const promptInfo = softValidate(PromptInfo_ark, await res.json());
3135
- if (res.status !== 200) throw new InvalidPromptError("ComfyUI /prompt request failed", snapshot, promptInfo);
3244
+ const promptInfoJson = await res.json();
3245
+ if (res.status !== 200) throw new InvalidPromptError(`ComfyUI refused the prompt: ${describePromptRejection(promptInfoJson)}`, snapshot, promptInfoJson);
3246
+ const promptInfo = softValidate(PromptInfo_ark, promptInfoJson);
3136
3247
  return new ComfyExecution(this, {
3137
3248
  id: promptInfo.prompt_id,
3138
3249
  executed: false,
@@ -3331,7 +3442,19 @@ var ComfyManager = class {
3331
3442
  return comfyts.registry.getModelInfoFinalFilePath(mi);
3332
3443
  };
3333
3444
  this.restartComfyUI = async () => {
3334
- return this.fetchGetJSON("/manager/reboot");
3445
+ const refusals = [];
3446
+ for (const method of ["POST", "GET"]) {
3447
+ let response;
3448
+ try {
3449
+ response = await this.host.fetch("/manager/reboot", { method });
3450
+ } catch {
3451
+ return;
3452
+ }
3453
+ if (response.ok) return;
3454
+ refusals.push(`${method} → ${response.status}`);
3455
+ if (response.status !== 404) break;
3456
+ }
3457
+ throw new Error(`🔴 ${this.host.getServerHostHTTP()} refused to reboot (${refusals.join(", ")}) — ComfyUI-Manager is not installed there, or its reboot route moved again`);
3335
3458
  };
3336
3459
  this.modelList = null;
3337
3460
  this.fetchModels = () => {
@@ -3456,7 +3579,7 @@ var ComfyManager = class {
3456
3579
  }
3457
3580
  rebootComfyUIAndUpdateHostPluginsAndModelsAfter10Seconds() {
3458
3581
  setTimeout(() => void this.fetchPluginsAndModels(), 1e4);
3459
- return this.fetchGetJSON("/manager/reboot");
3582
+ return this.restartComfyUI();
3460
3583
  }
3461
3584
  get titlesOfAllInstalledPlugins() {
3462
3585
  return this.pluginList?.custom_nodes.filter((x) => x.installed === "True").map((x) => x.title) ?? [];
@@ -3950,6 +4073,7 @@ var ComfyHost = class {
3950
4073
  this.activePromptID = null;
3951
4074
  this.latentPreview = null;
3952
4075
  this.onLatentPreview = null;
4076
+ this.onProgressText = null;
3953
4077
  this.onStatus = null;
3954
4078
  this.onSession = null;
3955
4079
  this.onLogs = null;
@@ -4163,6 +4287,17 @@ var ComfyHost = class {
4163
4287
  this._unknownBinaryFrameTypes.add(frame.eventType);
4164
4288
  console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`);
4165
4289
  }
4290
+ if (frame.kind === "text") {
4291
+ (this.activePromptID != null ? this.executions.get(this.activePromptID) : null)?.onProgressText({
4292
+ nodeId: frame.nodeId,
4293
+ text: frame.text
4294
+ });
4295
+ this.onProgressText?.({
4296
+ nodeId: frame.nodeId,
4297
+ text: frame.text,
4298
+ promptID: this.activePromptID
4299
+ });
4300
+ }
4166
4301
  return;
4167
4302
  }
4168
4303
  const msg_ = JSON.parse(String(e.data));
@@ -4861,6 +4996,6 @@ var ComfyTS = class ComfyTS {
4861
4996
  }
4862
4997
  };
4863
4998
  //#endregion
4864
- export { importSharp as a, stripAnsi as i, settingsPathFor as n, ComfySchema as o, readableStringify as r, ComfyTS as t };
4999
+ export { ComfySchema as a, importSharp as i, settingsPathFor as n, readableStringify as r, ComfyTS as t };
4865
5000
 
4866
- //# sourceMappingURL=state-CaHeDL-0.js.map
5001
+ //# sourceMappingURL=state-B-boDz-Z.js.map