comfy-ts 2.6.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 +22 -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 +8 -6
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +288 -35
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +128 -7
  11. package/dist/index.d.ts +128 -7
  12. package/dist/index.js +286 -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-idFhdO4f.js → run-tui-BPw-SZYW.js} +107 -158
  17. package/dist/run-tui-BPw-SZYW.js.map +1 -0
  18. package/dist/serve-web.js +434 -81
  19. package/dist/{state-C90kdjtB.js → state-B-boDz-Z.js} +184 -45
  20. package/dist/state-B-boDz-Z.js.map +1 -0
  21. package/dist/web.d.ts +112 -7
  22. package/dist/web.js +239 -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 +7 -1
  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 +4 -2
  35. package/src/cli/serve/ServeApp.ts +825 -43
  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 +58 -29
  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 +120 -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 +85 -38
  47. package/src/cli/serve/web/components/Sidebar.tsx +43 -19
  48. package/src/cli/serve/web/components/VarsForm.tsx +440 -80
  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 +254 -0
  56. package/src/cli/serve/web/logWeb.ts +6 -0
  57. package/src/cli/serve/web/state/EnhancerSt.ts +261 -157
  58. package/src/cli/serve/web/state/FormSt.ts +70 -18
  59. package/src/cli/serve/web/state/RunSt.ts +22 -1
  60. package/src/cli/serve/web/state/WebSt.ts +542 -13
  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 +415 -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/state.ts +6 -0
  89. package/src/utils/ansi.ts +13 -0
  90. package/src/utils/matchesRegex.ts +13 -0
  91. package/src/utils/safeName.ts +29 -0
  92. package/src/utils/stringMap.ts +9 -0
  93. package/src/vars/ComfyVars.ts +61 -10
  94. package/src/vars/presets.ts +17 -0
  95. package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
  96. package/dist/DraftsSt-dizp3VcC.js.map +0 -1
  97. package/dist/run-serve-CVu39RNd.js +0 -1002
  98. package/dist/run-serve-CVu39RNd.js.map +0 -1
  99. package/dist/run-tui-idFhdO4f.js.map +0 -1
  100. package/dist/state-C90kdjtB.js.map +0 -1
  101. package/src/cli/serve/web/openrouter.ts +0 -142
package/dist/index.cjs CHANGED
@@ -134,7 +134,7 @@ function createNodeStorage() {
134
134
  }
135
135
  //#endregion
136
136
  //#region package.json
137
- var version = "2.6.0";
137
+ var version = "2.8.0";
138
138
  //#endregion
139
139
  //#region src/litegraph/LiteGraphLinkID.ts
140
140
  const asLiteGraphLinkID = (id) => id;
@@ -1245,6 +1245,40 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1245
1245
  return prompt;
1246
1246
  };
1247
1247
  //#endregion
1248
+ //#region src/utils/isRecord.ts
1249
+ /** narrows unknown wire json to an indexable object (arrays and null excluded) */
1250
+ function isRecord(v) {
1251
+ return typeof v === "object" && v !== null && !Array.isArray(v);
1252
+ }
1253
+ //#endregion
1254
+ //#region src/runner/describePromptRejection.ts
1255
+ function str(v) {
1256
+ return typeof v === "string" ? v.trim() : "";
1257
+ }
1258
+ function describePromptRejection(body) {
1259
+ if (!isRecord(body)) return "no reason given";
1260
+ const parts = [];
1261
+ const err = body["error"];
1262
+ if (isRecord(err)) {
1263
+ const head = str(err["message"]);
1264
+ const detail = str(err["details"]);
1265
+ if (head !== "") parts.push(detail === "" ? head : `${head} (${detail})`);
1266
+ }
1267
+ const nodes = body["node_errors"];
1268
+ if (isRecord(nodes)) for (const [nodeId, raw] of Object.entries(nodes)) {
1269
+ if (!isRecord(raw)) continue;
1270
+ const list = raw["errors"];
1271
+ if (!Array.isArray(list)) continue;
1272
+ for (const e of list) {
1273
+ if (!isRecord(e)) continue;
1274
+ const detail = str(e["details"]);
1275
+ const msg = str(e["message"]);
1276
+ parts.push(`node ${nodeId}: ${[msg, detail].filter((x) => x !== "").join(" — ")}`);
1277
+ }
1278
+ }
1279
+ return parts.length === 0 ? "no reason given" : parts.join(" · ");
1280
+ }
1281
+ //#endregion
1248
1282
  //#region src/errors/InvalidPromptError.ts
1249
1283
  var InvalidPromptError = class extends Error {
1250
1284
  constructor(message, snapshot, details) {
@@ -1295,6 +1329,7 @@ var ComfyNodeOutput = class {
1295
1329
  };
1296
1330
  //#endregion
1297
1331
  //#region src/graph/ComfyNode.ts
1332
+ const isScalarValue = (x) => typeof x === "string" || typeof x === "number" || typeof x === "boolean";
1298
1333
  /** ComfyNode
1299
1334
  * - correspond to a signal in the graph
1300
1335
  * - belongs to a script
@@ -1387,13 +1422,27 @@ var ComfyNode = class ComfyNode {
1387
1422
  _convertPromptExtToPrompt(promptExt) {
1388
1423
  const inputs = {};
1389
1424
  const _done = /* @__PURE__ */ new Set();
1425
+ /** every dotted key of every branch: the selected ones are written here, the rest are dropped */
1426
+ const _comboBranchKeys = /* @__PURE__ */ new Set();
1390
1427
  for (const i of this.$schema.inputs) {
1391
1428
  _done.add(i.nameInComfy);
1429
+ const kind = classifySchemaInput(i);
1430
+ if (kind.kind === "dynamic-combo") {
1431
+ this._writeDynamicCombo({
1432
+ name: i.nameInComfy,
1433
+ options: kind.options,
1434
+ defaultKey: kind.defaultKey,
1435
+ provided: promptExt.inputs,
1436
+ out: inputs,
1437
+ claimed: _comboBranchKeys
1438
+ });
1439
+ continue;
1440
+ }
1392
1441
  const value = this.serializeValue(i.nameInComfy, promptExt.inputs[i.nameInComfy]);
1393
1442
  if (value !== void 0) inputs[i.nameInComfy] = value;
1394
1443
  }
1395
1444
  for (const [nameInComfy, rawVal] of Object.entries(promptExt.inputs)) {
1396
- if (_done.has(nameInComfy)) continue;
1445
+ if (_done.has(nameInComfy) || _comboBranchKeys.has(nameInComfy)) continue;
1397
1446
  inputs[nameInComfy] = this.serializeValue(nameInComfy, rawVal);
1398
1447
  }
1399
1448
  return {
@@ -1401,6 +1450,31 @@ var ComfyNode = class ComfyNode {
1401
1450
  inputs
1402
1451
  };
1403
1452
  }
1453
+ /** dynamic combo → the key plus ONLY the selected branch's dotted inputs, absent ones
1454
+ * filled from the schema (agent/architecture.md, dynamic-combo fill). The host declares
1455
+ * those branch inputs required and default-fills none of them */
1456
+ _writeDynamicCombo(p) {
1457
+ for (const opt of p.options) for (const e of opt.inputs) p.claimed.add(`${p.name}.${e.name}`);
1458
+ const raw = p.provided[p.name];
1459
+ const key = typeof raw === "string" ? raw : p.defaultKey;
1460
+ const branch = p.options.find((o) => o.key === key);
1461
+ if (branch == null) {
1462
+ const known = p.options.map((o) => o.key).join(", ");
1463
+ console.error(`🔴 unknown "${p.name}" option ${JSON.stringify(key)} (known: ${known})`);
1464
+ this.graph.recordProblem(`🔴 unknown "${p.name}" option ${JSON.stringify(key)} on ${this.$schema.nodeKey}#${this.uid} (known: ${known})`);
1465
+ return;
1466
+ }
1467
+ p.out[p.name] = key;
1468
+ for (const e of branch.inputs) {
1469
+ const dotted = `${p.name}.${e.name}`;
1470
+ const given = p.provided[dotted];
1471
+ p.out[dotted] = given === void 0 ? defaultValueForWidget({
1472
+ type: typeof e.type === "string" ? e.type : "COMBO",
1473
+ opts: e.opts,
1474
+ enumValues: Array.isArray(e.type) ? e.type.filter(isScalarValue) : void 0
1475
+ }) : this.serializeValue(dotted, given);
1476
+ }
1477
+ }
1404
1478
  /** return the list of nodes piped into this node */
1405
1479
  _incomingNodes() {
1406
1480
  const incomingNodes = [];
@@ -1961,7 +2035,8 @@ const types$1 = (0, arktype.scope)({
1961
2035
  node: "ComfyNodeID",
1962
2036
  output: {
1963
2037
  "previews?": [{ filepath: "string" }, "[]"],
1964
- "images?": "ComfyImageInfo[]"
2038
+ "images?": "ComfyImageInfo[]",
2039
+ "text?": "unknown[]"
1965
2040
  },
1966
2041
  prompt_id: "PromptID"
1967
2042
  },
@@ -2270,6 +2345,15 @@ var ComfyExecution = class {
2270
2345
  };
2271
2346
  this.onExecuted = (msg) => {
2272
2347
  const promptNodeID = msg.data.node;
2348
+ for (const entry of msg.data.output?.text ?? []) {
2349
+ if (typeof entry !== "string") continue;
2350
+ const nodeKey = this.workflow.data.apiJson?.[promptNodeID]?.class_type ?? null;
2351
+ this.texts.push({
2352
+ nodeId: promptNodeID,
2353
+ nodeKey,
2354
+ text: entry
2355
+ });
2356
+ }
2273
2357
  const images = msg.data.output?.images;
2274
2358
  if (images) for (const img of images) this.pendingPromises.push(this.retrieveImage(img, promptNodeID).catch((e) => {
2275
2359
  console.error(`🔴 failed to retrieve ${img.filename}:`, e);
@@ -2387,6 +2471,9 @@ var ComfyExecution = class {
2387
2471
  }), promptNodeID);
2388
2472
  };
2389
2473
  this.images = [];
2474
+ this.texts = [];
2475
+ this.progressTexts = /* @__PURE__ */ new Map();
2476
+ this.progressText = null;
2390
2477
  this.alreadyDone = false;
2391
2478
  this._finish = async (p) => {
2392
2479
  if (this.alreadyDone) throw new Error(`❌ invariant violation: already finished`);
@@ -2422,7 +2509,9 @@ var ComfyExecution = class {
2422
2509
  ...this.progressGlobal,
2423
2510
  promptId: this.data.id,
2424
2511
  nodeName: this.workflow.currentExecutingNode?.$schema.nameInComfy ?? null,
2425
- elapsedMs: Date.now() - this.startedAt
2512
+ elapsedMs: Date.now() - this.startedAt,
2513
+ nodeProgress: this.workflow.currentExecutingNode?.progress ?? null,
2514
+ progressText: this.progressText
2426
2515
  };
2427
2516
  }
2428
2517
  emitProgress() {
@@ -2433,16 +2522,21 @@ var ComfyExecution = class {
2433
2522
  const filled = Math.round(p.percent / 100 * width);
2434
2523
  const bar = "█".repeat(filled) + "░".repeat(width - filled);
2435
2524
  const node = p.nodeName ? ` · ${p.nodeName}` : "";
2436
- const line = `▶ [${bar}] ${p.percent.toFixed(0).padStart(3)}%${node} · ${(p.elapsedMs / 1e3).toFixed(0)}s`;
2437
- if (line === this._lastLoggedLine) return;
2438
- this._lastLoggedLine = line;
2439
- if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}`);
2440
- else console.log(line);
2525
+ const count = p.nodeProgress ? ` ${p.nodeProgress.value}/${p.nodeProgress.max}` : "";
2526
+ const line = `▶ [${bar}] ${p.percent.toFixed(0).padStart(3)}%${node}${count} · ${(p.elapsedMs / 1e3).toFixed(0)}s`;
2527
+ const tail = p.progressText?.replaceAll("\n", " ").trimEnd().slice(-60);
2528
+ const full = tail == null || tail === "" ? line : `${line} · …${tail}`;
2529
+ if (full === this._lastLoggedLine) return;
2530
+ this._lastLoggedLine = full;
2531
+ if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${full}`);
2532
+ else console.log(full);
2441
2533
  }
2442
2534
  finishProgressLine() {
2443
2535
  if (!this.logProgress) return;
2444
2536
  const p = this.progress;
2445
- const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${this.images.length} image(s)`;
2537
+ const outputs = [`${this.images.length} image(s)`];
2538
+ if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
2539
+ const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
2446
2540
  if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
2447
2541
  else console.log(line);
2448
2542
  }
@@ -2484,6 +2578,16 @@ var ComfyExecution = class {
2484
2578
  if (uid == null) return false;
2485
2579
  return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
2486
2580
  }
2581
+ /** @internal a live-text frame for one node */
2582
+ onProgressText(p) {
2583
+ this.progressTexts.set(p.nodeId, p.text);
2584
+ this.progressText = p.text;
2585
+ this.emitProgress();
2586
+ }
2587
+ /** the last text output, the one a single-generator workflow means by "the result" */
2588
+ get text() {
2589
+ return this.texts.at(-1)?.text ?? null;
2590
+ }
2487
2591
  update(data) {
2488
2592
  Object.assign(this.data, data);
2489
2593
  }
@@ -2516,11 +2620,14 @@ const deepCopyNaive = (x) => JSON.parse(JSON.stringify(x));
2516
2620
  //#region src/utils/ansi.ts
2517
2621
  const codes = {
2518
2622
  bold: [1, 22],
2623
+ dim: [2, 22],
2519
2624
  underline: [4, 24],
2520
2625
  red: [31, 39],
2521
2626
  green: [32, 39],
2522
2627
  yellow: [33, 39],
2523
2628
  blue: [34, 39],
2629
+ cyan: [36, 39],
2630
+ gray: [90, 39],
2524
2631
  greenBright: [92, 39]
2525
2632
  };
2526
2633
  function styler(open = "", close = "") {
@@ -2771,6 +2878,7 @@ var ComfyWorkflow = class {
2771
2878
  return execution;
2772
2879
  };
2773
2880
  this.start = async (p = {}) => {
2881
+ if (this.host.ws == null) throw new Error(`🔴 host '${this.host.data.id}' was never connected — call \`await host.connect()\` before running a workflow`);
2774
2882
  this.resetRunState();
2775
2883
  const snapshot = {
2776
2884
  apiJson: deepCopyNaive(this.toApiJson(p.idMode ?? "use_stringified_numbers_only")),
@@ -2795,8 +2903,9 @@ var ComfyWorkflow = class {
2795
2903
  headers: { "Content-Type": "application/json" },
2796
2904
  body: JSON.stringify(out)
2797
2905
  });
2798
- const promptInfo = softValidate(PromptInfo_ark, await res.json());
2799
- if (res.status !== 200) throw new InvalidPromptError("ComfyUI /prompt request failed", snapshot, promptInfo);
2906
+ const promptInfoJson = await res.json();
2907
+ if (res.status !== 200) throw new InvalidPromptError(`ComfyUI refused the prompt: ${describePromptRejection(promptInfoJson)}`, snapshot, promptInfoJson);
2908
+ const promptInfo = softValidate(PromptInfo_ark, promptInfoJson);
2800
2909
  return new ComfyExecution(this, {
2801
2910
  id: promptInfo.prompt_id,
2802
2911
  executed: false,
@@ -2869,6 +2978,13 @@ var ComfyWorkflow = class {
2869
2978
  }
2870
2979
  };
2871
2980
  //#endregion
2981
+ //#region src/utils/matchesRegex.ts
2982
+ function statelessRegex(re) {
2983
+ if (!re.global && !re.sticky) return re;
2984
+ const source = re.sticky ? `^(?:${re.source})` : re.source;
2985
+ return new RegExp(source, re.flags.replace(/[gy]/g, ""));
2986
+ }
2987
+ //#endregion
2872
2988
  //#region src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts
2873
2989
  /** having a bunch of sensible default will help slightly */
2874
2990
  function getUnionNameBasedOnFirstFoundEnumName(enumName, hash, hashContent) {
@@ -3013,6 +3129,25 @@ const wrapQuote = (s) => {
3013
3129
  };
3014
3130
  //#endregion
3015
3131
  //#region src/sdk-generator/comfyui-sdk-codegen.ts
3132
+ const isScalar = (x) => typeof x === "string" || typeof x === "number" || typeof x === "boolean";
3133
+ /** a dynamic-combo branch input, typed the way its dotted prompt key is filled: inline enums
3134
+ * and COMBO option lists become literal unions, everything else stays a named slot */
3135
+ const branchInputType = (entry) => {
3136
+ const opts = isRecord$1(entry.opts) ? entry.opts : null;
3137
+ const scalars = (Array.isArray(entry.type) ? entry.type : Array.isArray(opts?.["options"]) ? opts["options"] : []).filter(isScalar);
3138
+ if (scalars.length > 0) return scalars.map((o) => JSON.stringify(o)).join(" | ");
3139
+ if (typeof entry.type === "string") return `Accepts[${JSON.stringify(entry.type)}]`;
3140
+ return "string | number | boolean";
3141
+ };
3142
+ /** `& ({key:'a'; 'name.x'?: …} | {key:'b'})` — one member per branch, so a key from a branch
3143
+ * you did not select is a type error. Branch fields are optional: ComfyNode fills them
3144
+ * from the schema at serialization (agent/architecture.md, dynamic-combo fill) */
3145
+ const dynamicComboUnion = (p) => {
3146
+ return ` & (${p.options.map((opt) => {
3147
+ const fields = opt.inputs.map((e) => `${escapeJSKey(`${p.name}.${e.name}`)}?: ${branchInputType(e)}`);
3148
+ return `{ ${[`${p.nameEscaped}${p.keyOptional ? "?" : ""}: ${JSON.stringify(opt.key)}`, ...fields].join("; ")} }`;
3149
+ }).join(" | ")})`;
3150
+ };
3016
3151
  /**
3017
3152
  * convert a host id to the namespace name it gets inside the global `Comfy` namespace
3018
3153
  * e.g. 'windows-1' -> 'Windows1', 'my_cloud.instance' -> 'MyCloudInstance'
@@ -3065,6 +3200,7 @@ function codegenSDK(opts) {
3065
3200
  b.indent();
3066
3201
  for (const n of nodes) {
3067
3202
  p(`${escapeJSKey(n.nodeKey)}: {`);
3203
+ const comboSuffixes = [];
3068
3204
  for (const i of n.inputs) {
3069
3205
  const kind = classifySchemaInput(i);
3070
3206
  if (kind.kind === "dynamic-container") {
@@ -3075,6 +3211,16 @@ function codegenSDK(opts) {
3075
3211
  });
3076
3212
  continue;
3077
3213
  }
3214
+ if (kind.kind === "dynamic-combo") {
3215
+ const optsDyn = typeof i.opts === "string" ? null : i.opts;
3216
+ comboSuffixes.push(dynamicComboUnion({
3217
+ name: i.nameInComfy,
3218
+ nameEscaped: i.nameInComfyEscaped,
3219
+ options: kind.options,
3220
+ keyOptional: optsDyn?.default !== void 0 || !i.required
3221
+ }));
3222
+ continue;
3223
+ }
3078
3224
  const opts_ = typeof i.opts === "string" ? null : i.opts;
3079
3225
  let type = `Accepts[${JSON.stringify(i.typeName)}]`;
3080
3226
  const comboOptions = i.typeName === "COMBO" && Array.isArray(opts_?.options) ? opts_.options.filter((o) => typeof o === "string" || typeof o === "number" || typeof o === "boolean") : [];
@@ -3091,7 +3237,7 @@ function codegenSDK(opts) {
3091
3237
  const canBeOmmited = opts_?.default !== void 0 || !i.required;
3092
3238
  p(` ${i.nameInComfyEscaped}${canBeOmmited ? "?" : ""}: ${type}`);
3093
3239
  }
3094
- p(`},`);
3240
+ p(`}${comboSuffixes.join("")},`);
3095
3241
  }
3096
3242
  b.deindent();
3097
3243
  p("}");
@@ -3260,7 +3406,8 @@ var ComfySchema = class {
3260
3406
  };
3261
3407
  this.getLoras = (filter) => {
3262
3408
  const all = this.stringValues("LoraLoader.lora_name");
3263
- return filter == null ? all : all.filter((n) => filter.test(n));
3409
+ const stateless = filter == null ? null : statelessRegex(filter);
3410
+ return stateless == null ? all : all.filter((n) => stateless.test(n));
3264
3411
  };
3265
3412
  this.getImages = () => {
3266
3413
  return this.stringValues("LoadImage.image");
@@ -3394,15 +3541,19 @@ var ComfySchema = class {
3394
3541
  comfyUnionDef: slotType
3395
3542
  }).unionName);
3396
3543
  else throw new Error(`invalid schema (${JSON.stringify(slotType)}) for input "${ipt.name}" in node "${nodeNameInComfy}" (type: ${typeof slotType}; expected: Array | string)`);
3397
- const isAutogrowContainer = typeof slotType === "string" && classifyWidgetInput({
3544
+ const widgetKind = typeof slotType === "string" ? classifyWidgetInput({
3398
3545
  name: ipt.name,
3399
3546
  type: slotType,
3400
3547
  opts: slotOpts
3401
- }).kind === "dynamic-container";
3548
+ }) : null;
3549
+ const isAutogrowContainer = widgetKind?.kind === "dynamic-container";
3402
3550
  if (isAutogrowContainer) {
3403
3551
  const instType = containerInstanceSlotType(slotOpts);
3404
3552
  if (instType != null) this.knownSlotTypes.add(asComfyNodeSlotTypeName(instType));
3405
3553
  }
3554
+ if (widgetKind?.kind === "dynamic-combo") {
3555
+ for (const opt of widgetKind.options) for (const entry of opt.inputs) if (typeof entry.type === "string") this.knownSlotTypes.add(asComfyNodeSlotTypeName(entry.type));
3556
+ }
3406
3557
  node.inputs.push({
3407
3558
  slotName: inputSlotName,
3408
3559
  required: ipt.required && !isAutogrowContainer,
@@ -3578,7 +3729,19 @@ var ComfyManager = class {
3578
3729
  return comfyts.registry.getModelInfoFinalFilePath(mi);
3579
3730
  };
3580
3731
  this.restartComfyUI = async () => {
3581
- return this.fetchGetJSON("/manager/reboot");
3732
+ const refusals = [];
3733
+ for (const method of ["POST", "GET"]) {
3734
+ let response;
3735
+ try {
3736
+ response = await this.host.fetch("/manager/reboot", { method });
3737
+ } catch {
3738
+ return;
3739
+ }
3740
+ if (response.ok) return;
3741
+ refusals.push(`${method} → ${response.status}`);
3742
+ if (response.status !== 404) break;
3743
+ }
3744
+ throw new Error(`🔴 ${this.host.getServerHostHTTP()} refused to reboot (${refusals.join(", ")}) — ComfyUI-Manager is not installed there, or its reboot route moved again`);
3582
3745
  };
3583
3746
  this.modelList = null;
3584
3747
  this.fetchModels = () => {
@@ -3703,7 +3866,7 @@ var ComfyManager = class {
3703
3866
  }
3704
3867
  rebootComfyUIAndUpdateHostPluginsAndModelsAfter10Seconds() {
3705
3868
  setTimeout(() => void this.fetchPluginsAndModels(), 1e4);
3706
- return this.fetchGetJSON("/manager/reboot");
3869
+ return this.restartComfyUI();
3707
3870
  }
3708
3871
  get titlesOfAllInstalledPlugins() {
3709
3872
  return this.pluginList?.custom_nodes.filter((x) => x.installed === "True").map((x) => x.title) ?? [];
@@ -3926,12 +4089,6 @@ var ResilientWebSocketClient = class {
3926
4089
  }
3927
4090
  }
3928
4091
  };
3929
- //#endregion
3930
- //#region src/utils/isRecord.ts
3931
- /** narrows unknown wire json to an indexable object (arrays and null excluded) */
3932
- function isRecord(v) {
3933
- return typeof v === "object" && v !== null && !Array.isArray(v);
3934
- }
3935
4092
  (0, arktype.type)({
3936
4093
  items: "unknown[]",
3937
4094
  "total?": "number"
@@ -4092,7 +4249,6 @@ function getLoraPreviewUrl(name, hostId) {
4092
4249
  const info = getLoraInfo(name, hostId);
4093
4250
  return info == null ? null : lmPreviewUrl(info);
4094
4251
  }
4095
- /** the lora's NAMES: the file, and the model name a human would call it by */
4096
4252
  function loraSearchNames(name, hostId) {
4097
4253
  const names = [loraBasename(name), name.replaceAll("\\", "/")];
4098
4254
  const info = getLoraInfo(name, hostId);
@@ -4214,6 +4370,20 @@ function writeKeywords() {
4214
4370
  }
4215
4371
  }
4216
4372
  //#endregion
4373
+ //#region src/vars/presets.ts
4374
+ function toPresetList(spec) {
4375
+ if (spec == null) return [];
4376
+ return Object.entries(spec).map(([label, text]) => ({
4377
+ label,
4378
+ text
4379
+ }));
4380
+ }
4381
+ /** which preset the value still IS, or null once it was hand-edited (trailing whitespace ignored) */
4382
+ function activePresetLabel(presets, value) {
4383
+ const v = value.trim();
4384
+ return presets.find((p) => p.text.trim() === v)?.label ?? null;
4385
+ }
4386
+ //#endregion
4217
4387
  //#region src/vars/ComfyVars.ts
4218
4388
  /**
4219
4389
  * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
@@ -4271,9 +4441,14 @@ var ComfyVar = class extends ComfyVarBase {
4271
4441
  }
4272
4442
  };
4273
4443
  var TextVar = class extends ComfyVar {
4274
- constructor(..._args) {
4275
- super(..._args);
4444
+ /** a bare label string was the whole second parameter before opts existed: a published
4445
+ * consumer passing one must keep working, exactly as SeedVar does */
4446
+ constructor(defaultValue, opts = {}) {
4447
+ const o = typeof opts === "string" ? { label: opts } : opts;
4448
+ super(defaultValue, o.label);
4276
4449
  this.kind = "text";
4450
+ this.opts = o;
4451
+ this.presets = toPresetList(o.presets);
4277
4452
  }
4278
4453
  parse(raw) {
4279
4454
  this.set(raw);
@@ -4297,6 +4472,7 @@ var PromptVar = class extends ComfyVarBase {
4297
4472
  super(defaultValue, promptOpts.label);
4298
4473
  this.promptOpts = promptOpts;
4299
4474
  this.kind = "prompt";
4475
+ this.presets = toPresetList(promptOpts.presets);
4300
4476
  }
4301
4477
  parse(raw) {
4302
4478
  this.set(raw);
@@ -4373,11 +4549,14 @@ var FloatVar = class extends ComfyVar {
4373
4549
  * The number shown is always the seed the NEXT run will use.
4374
4550
  */
4375
4551
  var SeedVar = class extends ComfyVar {
4376
- constructor(defaultValue = 0, label) {
4377
- super(defaultValue, label);
4552
+ /** `opts` is the modern shape; a bare label string stays accepted, since that was the
4553
+ * signature before a workflow could declare the mode it wants to run in */
4554
+ constructor(defaultValue = 0, opts = {}) {
4555
+ const o = typeof opts === "string" ? { label: opts } : opts;
4556
+ super(defaultValue, o.label);
4378
4557
  this.kind = "seed";
4379
- this.mode = "=";
4380
- this.defaultMode = "=";
4558
+ this.mode = o.mode ?? "=";
4559
+ this.defaultMode = this.mode;
4381
4560
  (0, mobx.makeObservable)(this, {
4382
4561
  mode: mobx.observable,
4383
4562
  setMode: mobx.action,
@@ -4445,8 +4624,8 @@ var SeedVar = class extends ComfyVar {
4445
4624
  }
4446
4625
  };
4447
4626
  var ToggleVar = class extends ComfyVar {
4448
- constructor(..._args2) {
4449
- super(..._args2);
4627
+ constructor(..._args) {
4628
+ super(..._args);
4450
4629
  this.kind = "toggle";
4451
4630
  }
4452
4631
  toggle() {
@@ -4507,6 +4686,12 @@ var LorasVar = class LorasVar extends ComfyVar {
4507
4686
  this.resolvedOptions = null;
4508
4687
  this.hostId = void 0;
4509
4688
  }
4689
+ /** the filter the workflow declared, when it declared one (`v.loras(/krea-?2/i)`). Public so
4690
+ * a UI can SHOW it, and so serve applies the same narrowing to loras only its lora-manager
4691
+ * mirror knows, an unfiltered union would put the whole catalog back in a filtered picker */
4692
+ get optionsFilter() {
4693
+ return this.optionsSource instanceof RegExp ? this.optionsSource : null;
4694
+ }
4510
4695
  get options() {
4511
4696
  if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
4512
4697
  if (this.resolvedOptions == null) throw new Error(`v.loras(${String(this.optionsSource)}) is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list otherwise)`);
@@ -4761,11 +4946,13 @@ var ImageVar = class extends ComfyVar {
4761
4946
  };
4762
4947
  /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
4763
4948
  const v = {
4764
- text: (defaultValue, label) => new TextVar(defaultValue, label),
4949
+ text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
4765
4950
  prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
4766
4951
  int: (defaultValue, opts = {}) => new IntVar(defaultValue, opts),
4767
4952
  float: (defaultValue, opts = {}) => new FloatVar(defaultValue, opts),
4768
- seed: (defaultValue = 0, label) => new SeedVar(defaultValue, label),
4953
+ /** `mode` is the SPEC default the workflow runs in: `'+'` makes every run step the seed,
4954
+ * which is what a tuning session wants, and reset()/revert come back to it */
4955
+ seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
4769
4956
  toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
4770
4957
  choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
4771
4958
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
@@ -5112,6 +5299,7 @@ var ComfyHost = class {
5112
5299
  this.activePromptID = null;
5113
5300
  this.latentPreview = null;
5114
5301
  this.onLatentPreview = null;
5302
+ this.onProgressText = null;
5115
5303
  this.onStatus = null;
5116
5304
  this.onSession = null;
5117
5305
  this.onLogs = null;
@@ -5325,6 +5513,17 @@ var ComfyHost = class {
5325
5513
  this._unknownBinaryFrameTypes.add(frame.eventType);
5326
5514
  console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`);
5327
5515
  }
5516
+ if (frame.kind === "text") {
5517
+ (this.activePromptID != null ? this.executions.get(this.activePromptID) : null)?.onProgressText({
5518
+ nodeId: frame.nodeId,
5519
+ text: frame.text
5520
+ });
5521
+ this.onProgressText?.({
5522
+ nodeId: frame.nodeId,
5523
+ text: frame.text,
5524
+ promptID: this.activePromptID
5525
+ });
5526
+ }
5328
5527
  return;
5329
5528
  }
5330
5529
  const msg_ = JSON.parse(String(e.data));
@@ -5995,6 +6194,10 @@ var ComfyTS = class ComfyTS {
5995
6194
  resolveFromDrafts(relativePath) {
5996
6195
  return asAbsolutePath((0, pathe.join)(this.baseFolder, "drafts", relativePath));
5997
6196
  }
6197
+ /** master prompts of the serve web ui's prompt enhancer — hand-editable markdown */
6198
+ resolveFromPromptEnhancers(relativePath) {
6199
+ return asAbsolutePath((0, pathe.join)(this.baseFolder, "prompt-enhancers", relativePath));
6200
+ }
5998
6201
  resolveFromCache(relativePath) {
5999
6202
  return asAbsolutePath((0, pathe.join)(this.baseFolder, "cache", relativePath));
6000
6203
  }
@@ -6077,6 +6280,52 @@ function exampleImagePath(name) {
6077
6280
  return abs;
6078
6281
  }
6079
6282
  //#endregion
6283
+ //#region src/utils/safeName.ts
6284
+ /** the accepted name, or null. Rejects traversal, absolute paths, leading dots and empties */
6285
+ function validStoreName(raw) {
6286
+ const name = raw.trim();
6287
+ if (name.length > 100) return null;
6288
+ return /^[\w][\w .-]*$/.test(name) ? name : null;
6289
+ }
6290
+ //#endregion
6291
+ //#region src/promptEnhancers.ts
6292
+ const EXT = ".md";
6293
+ function promptEnhancersDir() {
6294
+ return comfyts.resolveFromPromptEnhancers("");
6295
+ }
6296
+ /** the PURE read: no seeding, no writing. What a workflow calls at define time, since importing
6297
+ * a module must never create files in someone's project */
6298
+ function readPromptEnhancers() {
6299
+ const dir = promptEnhancersDir();
6300
+ if (!(0, node_fs.existsSync)(dir)) return [];
6301
+ const out = [];
6302
+ for (const file of (0, node_fs.readdirSync)(dir).sort()) {
6303
+ if (!file.endsWith(EXT)) continue;
6304
+ const name = file.slice(0, -3);
6305
+ if (validStoreName(name) == null) continue;
6306
+ try {
6307
+ out.push({
6308
+ name,
6309
+ text: (0, node_fs.readFileSync)((0, pathe.join)(dir, file), "utf8")
6310
+ });
6311
+ } catch (e) {
6312
+ console.error(`[serve] prompt enhancer '${name}' unreadable, skipped:`, e);
6313
+ }
6314
+ }
6315
+ return out;
6316
+ }
6317
+ /**
6318
+ * the same master prompts, shaped for `v.text(x, { presets })` / `v.prompt`: file name → text.
6319
+ * The point is that ONE library of texts serves the ✨ enhancer and every var that wants them,
6320
+ * so a paragraph you tuned in the panel is offered by the workflow too, with no copy.
6321
+ * Empty when the folder is absent, so a var keeps whatever presets it declares inline.
6322
+ */
6323
+ function promptEnhancerPresets() {
6324
+ const out = {};
6325
+ for (const e of readPromptEnhancers()) out[e.name] = e.text;
6326
+ return out;
6327
+ }
6328
+ //#endregion
6080
6329
  //#region src/cli/tui-env.ts
6081
6330
  const COMFY_TS_TUI_ENV = "COMFY_TS_TUI";
6082
6331
  function isTuiActive() {
@@ -6126,6 +6375,7 @@ exports.WorkflowNormalizeError = WorkflowNormalizeError;
6126
6375
  exports.__FAIL = __FAIL;
6127
6376
  exports.__OK = __OK;
6128
6377
  exports.activeLoras = activeLoras;
6378
+ exports.activePresetLabel = activePresetLabel;
6129
6379
  exports.asAbsolutePath = asAbsolutePath;
6130
6380
  exports.asHTMLContent = asHTMLContent;
6131
6381
  exports.asMDContent = asMDContent;
@@ -6156,6 +6406,8 @@ exports.loraTag = loraTag;
6156
6406
  exports.normalizeWorkflow = normalizeWorkflow;
6157
6407
  exports.parseHostBase = parseHostBase;
6158
6408
  exports.parseWorkflowJson = parseWorkflowJson;
6409
+ exports.promptEnhancerPresets = promptEnhancerPresets;
6410
+ exports.readPromptEnhancers = readPromptEnhancers;
6159
6411
  exports.refreshLoraInfoCacheIfChanged = refreshLoraInfoCacheIfChanged;
6160
6412
  exports.reloadLoraInfoCache = reloadLoraInfoCache;
6161
6413
  exports.renderHttpBase = renderHttpBase;
@@ -6164,6 +6416,7 @@ exports.resultFailure = resultFailure;
6164
6416
  exports.resultSuccess = resultSuccess;
6165
6417
  exports.setDefaultComfyStorage = setDefaultComfyStorage;
6166
6418
  exports.setLoraKeyword = setLoraKeyword;
6419
+ exports.toPresetList = toPresetList;
6167
6420
  exports.v = v;
6168
6421
 
6169
6422
  //# sourceMappingURL=index.cjs.map