comfy-ts 2.12.0 → 2.14.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 (81) hide show
  1. package/dist/{LogsSt-U1H0mP1m.js → LogsSt-CUeo843w.js} +18 -4
  2. package/dist/LogsSt-CUeo843w.js.map +1 -0
  3. package/dist/cli.js +4 -4
  4. package/dist/index.cjs +123 -12
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +96 -16
  7. package/dist/index.d.ts +96 -16
  8. package/dist/index.js +123 -12
  9. package/dist/index.js.map +1 -1
  10. package/dist/{run-serve-BeAznay5.js → run-serve-DUqcn0h3.js} +477 -63
  11. package/dist/run-serve-DUqcn0h3.js.map +1 -0
  12. package/dist/{run-tui-BTGjvnKk.js → run-tui-D-LaSqgB.js} +4 -4
  13. package/dist/{run-tui-BTGjvnKk.js.map → run-tui-D-LaSqgB.js.map} +1 -1
  14. package/dist/{schemaDrift-Cg39vs53.js → schemaDrift-E95iTF7E.js} +4 -1
  15. package/dist/{schemaDrift-Cg39vs53.js.map → schemaDrift-E95iTF7E.js.map} +1 -1
  16. package/dist/serve-web.js +378 -141
  17. package/dist/{state-C7REnHan.js → state-BytbdZ8s.js} +122 -14
  18. package/dist/state-BytbdZ8s.js.map +1 -0
  19. package/dist/web.d.ts +96 -16
  20. package/dist/web.js +123 -12
  21. package/dist/web.js.map +1 -1
  22. package/examples/comfy-cloud/sdk.d.ts +163 -163
  23. package/examples/rvion/10-anima-t2i.cflow.ts +48 -25
  24. package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
  25. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
  26. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
  27. package/examples/rvion/stableAudio3Prompts.ts +19 -0
  28. package/package.json +2 -2
  29. package/src/cli/serve/ServeApp.ts +224 -77
  30. package/src/cli/serve/byteRange.ts +48 -0
  31. package/src/cli/serve/resultHistory.ts +125 -0
  32. package/src/cli/serve/run-serve.ts +12 -3
  33. package/src/cli/serve/runError.ts +23 -0
  34. package/src/cli/serve/serveSettings.ts +17 -1
  35. package/src/cli/serve/web/api.ts +53 -2
  36. package/src/cli/serve/web/components/App.tsx +311 -160
  37. package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
  38. package/src/cli/serve/web/components/Gallery.tsx +75 -25
  39. package/src/cli/serve/web/components/Icon.tsx +44 -0
  40. package/src/cli/serve/web/components/MemoryBudget.tsx +98 -0
  41. package/src/cli/serve/web/components/Omnibox.tsx +70 -20
  42. package/src/cli/serve/web/components/RunError.tsx +19 -0
  43. package/src/cli/serve/web/components/ShortcutsModal.tsx +54 -0
  44. package/src/cli/serve/web/components/SideMenu.tsx +428 -0
  45. package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
  46. package/src/cli/serve/web/components/VarsForm.tsx +141 -404
  47. package/src/cli/serve/web/components/controls/BasicControls.tsx +8 -1
  48. package/src/cli/serve/web/components/controls/LorasControl.tsx +30 -25
  49. package/src/cli/serve/web/promptEditor/promptExtensions.ts +9 -4
  50. package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
  51. package/src/cli/serve/web/state/FormSt.ts +22 -2
  52. package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
  53. package/src/cli/serve/web/state/RunSt.ts +61 -3
  54. package/src/cli/serve/web/state/WebSt.ts +198 -35
  55. package/src/cli/serve/web/state/draftNames.ts +16 -0
  56. package/src/cli/serve/web/state/draftTabs.ts +75 -0
  57. package/src/cli/serve/web/state/formRows.ts +9 -0
  58. package/src/cli/serve/web/state/generateButton.ts +1 -1
  59. package/src/cli/serve/web/state/keptResults.ts +26 -0
  60. package/src/cli/serve/web/state/lightbox.ts +17 -0
  61. package/src/cli/serve/web/state/omnibox.ts +82 -18
  62. package/src/cli/serve/web/state/shortcutCatalog.ts +100 -0
  63. package/src/cli/serve/web/state/shortcuts.ts +66 -7
  64. package/src/cli/serve/web/styles.ts +327 -93
  65. package/src/cli/serve/workflowTags.ts +42 -0
  66. package/src/cli/serve/workspaceLabels.ts +23 -0
  67. package/src/cli/tui/state/DraftsSt.ts +10 -6
  68. package/src/coreExports.ts +1 -0
  69. package/src/host/ComfyHost.ts +17 -2
  70. package/src/host/ResilientWebsocket.ts +54 -4
  71. package/src/runner/ComfyExecution.ts +60 -0
  72. package/src/runner/ComfyWorkflow.ts +4 -0
  73. package/src/runner/ComfyWsApi.ts +2 -0
  74. package/src/runner/MediaImage.ts +2 -2
  75. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
  76. package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
  77. package/src/utils/copyName.ts +12 -0
  78. package/src/vars/DefinedWorkflow.ts +7 -1
  79. package/dist/LogsSt-U1H0mP1m.js.map +0 -1
  80. package/dist/run-serve-BeAznay5.js.map +0 -1
  81. package/dist/state-C7REnHan.js.map +0 -1
package/dist/index.js CHANGED
@@ -110,7 +110,7 @@ function createNodeStorage() {
110
110
  }
111
111
  //#endregion
112
112
  //#region package.json
113
- var version = "2.12.0";
113
+ var version = "2.14.0";
114
114
  //#endregion
115
115
  //#region src/litegraph/LiteGraphLinkID.ts
116
116
  const asLiteGraphLinkID = (id) => id;
@@ -2016,6 +2016,7 @@ const types$1 = scope({
2016
2016
  output: {
2017
2017
  "previews?": [{ filepath: "string" }, "[]"],
2018
2018
  "images?": "ComfyImageInfo[]",
2019
+ "audio?": "ComfyImageInfo[]",
2019
2020
  "text?": "unknown[]"
2020
2021
  },
2021
2022
  prompt_id: "PromptID"
@@ -2116,11 +2117,11 @@ var MediaImage = class MediaImage {
2116
2117
  });
2117
2118
  };
2118
2119
  this.loadInWorkflow_viaLoadImageNode = async (workflow) => {
2119
- const enumName = await this.uploadAndReturnEnumName(workflow.host);
2120
+ const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
2120
2121
  return bang(workflow.builderBase.LoadImage, "host has no LoadImage node")({ image: enumName });
2121
2122
  };
2122
2123
  this.loadInWorkflowAsMask_viaLoadImageMask = async (channel, workflow) => {
2123
- const enumName = await this.uploadAndReturnEnumName(workflow.host);
2124
+ const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
2124
2125
  return bang(workflow.builderBase.LoadImageMask, "host has no LoadImageMask node")({
2125
2126
  image: enumName,
2126
2127
  channel
@@ -2268,6 +2269,18 @@ var MediaImage = class MediaImage {
2268
2269
  * A claim is released as soon as the write lands (the file itself then holds
2269
2270
  * the name) or fails (the name is free again) — the set never accumulates */
2270
2271
  const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
2272
+ const AUDIO_MIMES = {
2273
+ flac: "audio/flac",
2274
+ mp3: "audio/mpeg",
2275
+ opus: "audio/ogg",
2276
+ ogg: "audio/ogg",
2277
+ wav: "audio/wav",
2278
+ m4a: "audio/mp4"
2279
+ };
2280
+ function audioMime(filename) {
2281
+ const ext = filename.split(".").pop()?.toLowerCase() ?? "";
2282
+ return AUDIO_MIMES[ext] ?? "application/octet-stream";
2283
+ }
2271
2284
  var ComfyExecution = class {
2272
2285
  get host() {
2273
2286
  return this.workflow.host;
@@ -2342,8 +2355,51 @@ var ComfyExecution = class {
2342
2355
  error: e
2343
2356
  });
2344
2357
  }));
2358
+ for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveAudio(audio, promptNodeID).catch((e) => {
2359
+ console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
2360
+ this.audioErrors.push({
2361
+ audio,
2362
+ error: e
2363
+ });
2364
+ }));
2345
2365
  };
2346
2366
  this.pendingPromises = [];
2367
+ this.audioErrors = [];
2368
+ this.audios = [];
2369
+ this.retrieveAudio = async (info, promptNodeID) => {
2370
+ const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
2371
+ const bytes = new Uint8Array(await response.arrayBuffer());
2372
+ const mime = audioMime(info.filename);
2373
+ const sf = this.save;
2374
+ if (sf == null) {
2375
+ this.audios.push({
2376
+ nodeId: promptNodeID,
2377
+ filename: info.filename,
2378
+ mime,
2379
+ bytes,
2380
+ absPath: null
2381
+ });
2382
+ return;
2383
+ }
2384
+ const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs["filename_prefix"];
2385
+ const written = await this.encodeAndWrite({
2386
+ bytes,
2387
+ sf: {
2388
+ ...sf,
2389
+ format: "raw"
2390
+ },
2391
+ filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
2392
+ subfolder: info.subfolder,
2393
+ filename: info.filename
2394
+ });
2395
+ this.audios.push({
2396
+ nodeId: promptNodeID,
2397
+ filename: info.filename,
2398
+ mime,
2399
+ bytes,
2400
+ absPath: written.path
2401
+ });
2402
+ };
2347
2403
  this.imageErrors = [];
2348
2404
  this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
2349
2405
  const promptNode = this.workflow.data.apiJson?.[promptNodeID];
@@ -2515,6 +2571,7 @@ var ComfyExecution = class {
2515
2571
  if (!this.logProgress) return;
2516
2572
  const p = this.progress;
2517
2573
  const outputs = [`${this.images.length} image(s)`];
2574
+ if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
2518
2575
  if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
2519
2576
  const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
2520
2577
  if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
@@ -2745,6 +2802,7 @@ var ComfyWorkflow = class {
2745
2802
  constructor(host, data) {
2746
2803
  this.host = host;
2747
2804
  this.data = data;
2805
+ this.dry = false;
2748
2806
  this.nodes = [];
2749
2807
  this.registerNode = (node) => {
2750
2808
  if (this.data.apiJson == null) throw new Error("graph not hydrated");
@@ -3242,7 +3300,7 @@ function codegenSDK(opts) {
3242
3300
  p("}");
3243
3301
  p(`interface Builder {`);
3244
3302
  for (const n of nodes) {
3245
- const baseDescription = `displayName="${n.raw.display_name}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
3303
+ const baseDescription = `displayName="${n.raw.display_name ?? n.nameInComfy}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
3246
3304
  if (n.raw.description) {
3247
3305
  p(` /**`);
3248
3306
  p(n.raw.description.split("\n").map((i) => ` * ${i}`).join("\n"));
@@ -3596,16 +3654,16 @@ const types = scope({
3596
3654
  "hidden?": "string[]"
3597
3655
  },
3598
3656
  output: "ComfyInputType[]",
3599
- output_is_list: "boolean[]",
3657
+ output_is_list: "(boolean | null)[]",
3600
3658
  output_name: "string[]",
3601
3659
  name: "string",
3602
- display_name: "string",
3660
+ display_name: "string | null",
3603
3661
  description: "string",
3604
3662
  /** */
3605
3663
  python_module: "string",
3606
3664
  category: "string",
3607
3665
  output_node: "boolean",
3608
- "output_tooltips?": "string[]",
3666
+ "output_tooltips?": "(string | null)[]",
3609
3667
  "deprecated?": "boolean",
3610
3668
  "experimental?": "boolean"
3611
3669
  },
@@ -3621,7 +3679,7 @@ const types = scope({
3621
3679
  ComfyInputOpts_advanced: {
3622
3680
  "tooltip?": "string | null | ComfyInputOpts_advanced",
3623
3681
  "multiline?": "boolean | null",
3624
- "default?": "boolean | number | string | null | number[]",
3682
+ "default?": "boolean | number | string | null | number[] | object",
3625
3683
  "forceInput?": "boolean | null",
3626
3684
  "min?": "number | null",
3627
3685
  "round?": "boolean | number | null",
@@ -3982,14 +4040,46 @@ var ResilientWebSocketClient = class {
3982
4040
  this.isOpen = false;
3983
4041
  this.debugMessages = [];
3984
4042
  this.hasEverOpened = false;
4043
+ this.heartbeat = null;
3985
4044
  this.permanentlyClosed = false;
3986
4045
  this.url = options.url();
3987
4046
  this.connect();
3988
4047
  }
4048
+ stopHeartbeat() {
4049
+ if (this.heartbeat != null) clearInterval(this.heartbeat);
4050
+ this.heartbeat = null;
4051
+ }
4052
+ /** ping on a timer; no pong since the previous ping = the peer is gone, drop the socket */
4053
+ startHeartbeat(ws) {
4054
+ this.stopHeartbeat();
4055
+ if (typeof ws.ping !== "function" || typeof ws.on !== "function") return;
4056
+ let awaitingPong = false;
4057
+ ws.on("pong", () => {
4058
+ awaitingPong = false;
4059
+ });
4060
+ const ms = this.options.heartbeatMs ?? 15e3;
4061
+ this.heartbeat = setInterval(() => {
4062
+ if (ws !== this.currentWS) return this.stopHeartbeat();
4063
+ if (awaitingPong) {
4064
+ this.addError(`no pong within ${ms}ms: the host is gone, dropping the socket to reconnect`);
4065
+ this.stopHeartbeat();
4066
+ if (typeof ws.terminate === "function") ws.terminate();
4067
+ else ws.close();
4068
+ return;
4069
+ }
4070
+ awaitingPong = true;
4071
+ try {
4072
+ ws.ping?.();
4073
+ } catch (e) {
4074
+ this.addError(`ping failed: ${extractErrorMessage(e)}`);
4075
+ }
4076
+ }, ms);
4077
+ }
3989
4078
  /** close and stop reconnecting (lets a script exit cleanly) */
3990
4079
  disconnectPermanently() {
3991
4080
  this.permanentlyClosed = true;
3992
4081
  if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
4082
+ this.stopHeartbeat();
3993
4083
  this.currentWS?.close();
3994
4084
  this.currentWS = null;
3995
4085
  this.isOpen = false;
@@ -4008,6 +4098,7 @@ var ResilientWebSocketClient = class {
4008
4098
  this.isOpen = false;
4009
4099
  const prevWS = this.currentWS;
4010
4100
  if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
4101
+ this.stopHeartbeat();
4011
4102
  this.currentWS = null;
4012
4103
  if (prevWS) {
4013
4104
  this.addInfo("Previous WebSocket discarded");
@@ -4015,7 +4106,7 @@ var ResilientWebSocketClient = class {
4015
4106
  }
4016
4107
  let ws;
4017
4108
  try {
4018
- const transport = await resolveWsTransport();
4109
+ const transport = this.options.transport ?? await resolveWsTransport();
4019
4110
  if (this.permanentlyClosed) return;
4020
4111
  const headers = this.options.headers?.() ?? {};
4021
4112
  ws = transport.supportsHeaders ? new transport.ctor(this.url, { headers }) : new transport.ctor(this.headerlessUrl(headers));
@@ -4037,10 +4128,12 @@ var ResilientWebSocketClient = class {
4037
4128
  this.isOpen = true;
4038
4129
  this.options.onConnectOrReconnect();
4039
4130
  this.flushMessageBuffer();
4131
+ this.startHeartbeat(ws);
4040
4132
  };
4041
4133
  ws.onclose = (event) => {
4042
4134
  if (ws !== this.currentWS) return;
4043
4135
  this.isOpen = false;
4136
+ this.stopHeartbeat();
4044
4137
  this.options.onClose();
4045
4138
  if (this.permanentlyClosed) return;
4046
4139
  this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
@@ -4049,8 +4142,9 @@ var ResilientWebSocketClient = class {
4049
4142
  this.options.onFirstConnectFailed(/* @__PURE__ */ new Error(`connection refused (code=${event.code}${event.reason === "" ? "" : `, ${event.reason}`})`));
4050
4143
  return;
4051
4144
  }
4052
- this.addInfo("⏱️ reconnecting in 2 seconds...");
4053
- this.reconnectTimeout = setTimeout(() => void this.connect(), 2e3);
4145
+ const wait = this.options.reconnectMs ?? 2e3;
4146
+ this.addInfo(`⏱️ reconnecting in ${wait / 1e3} seconds...`);
4147
+ this.reconnectTimeout = setTimeout(() => void this.connect(), wait);
4054
4148
  };
4055
4149
  ws.onerror = (event) => {
4056
4150
  if (ws !== this.currentWS) return;
@@ -5380,12 +5474,15 @@ var DefinedWorkflow = class {
5380
5474
  * build() for copy/export never advances). `p.host` substitutes the host
5381
5475
  * the graph is built against (TUI host override): node/model availability
5382
5476
  * there surfaces as workflow.problems / server validation, by design.
5477
+ * `p.dry` builds a graph only to read it: nothing is uploaded, lastWorkflow is left alone.
5383
5478
  */
5384
5479
  async build(p = {}) {
5385
5480
  const wf = (p.host ?? this.host).workflow({ id: this.spec.id });
5481
+ wf.dry = p.dry === true;
5386
5482
  const values = varValues(this.vars);
5387
5483
  if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
5388
5484
  await this.spec.build(wf.builder, values, wf);
5485
+ if (wf.dry) return wf;
5389
5486
  this.lastWorkflow = wf;
5390
5487
  return wf;
5391
5488
  }
@@ -5686,8 +5783,22 @@ var ComfyHost = class {
5686
5783
  this.clearQueue = () => {
5687
5784
  return this.postJSON_("/queue", { clear: true });
5688
5785
  };
5786
+ this.interruptCoalesceMs = 3e3;
5787
+ this._lastInterrupt = null;
5689
5788
  this.interrupt = () => {
5690
- return this.postJSON_("/interrupt", {});
5789
+ const now = Date.now();
5790
+ const last = this._lastInterrupt;
5791
+ if (last != null && last.promptID === this.activePromptID && now - last.at < this.interruptCoalesceMs) return last.req;
5792
+ const req = this.postJSON_("/interrupt", {});
5793
+ this._lastInterrupt = {
5794
+ promptID: this.activePromptID,
5795
+ at: now,
5796
+ req
5797
+ };
5798
+ req.catch(() => {
5799
+ if (this._lastInterrupt?.req === req) this._lastInterrupt = null;
5800
+ });
5801
+ return req;
5691
5802
  };
5692
5803
  this.deleteHistory = (promptId) => {
5693
5804
  return this.postJSON_("/history", { delete: [promptId] });