comfy-ts 2.12.0 → 2.13.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 (69) 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-DlRBv_Nk.js} +281 -19
  11. package/dist/run-serve-DlRBv_Nk.js.map +1 -0
  12. package/dist/{run-tui-BTGjvnKk.js → run-tui-B5uxm2_l.js} +4 -4
  13. package/dist/{run-tui-BTGjvnKk.js.map → run-tui-B5uxm2_l.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 +291 -129
  17. package/dist/{state-C7REnHan.js → state-CUp2J1Zy.js} +122 -14
  18. package/dist/state-CUp2J1Zy.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 +157 -18
  30. package/src/cli/serve/byteRange.ts +48 -0
  31. package/src/cli/serve/run-serve.ts +12 -3
  32. package/src/cli/serve/web/api.ts +24 -0
  33. package/src/cli/serve/web/components/App.tsx +305 -156
  34. package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
  35. package/src/cli/serve/web/components/Gallery.tsx +44 -19
  36. package/src/cli/serve/web/components/Icon.tsx +40 -0
  37. package/src/cli/serve/web/components/Omnibox.tsx +70 -20
  38. package/src/cli/serve/web/components/SideMenu.tsx +414 -0
  39. package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
  40. package/src/cli/serve/web/components/VarsForm.tsx +70 -351
  41. package/src/cli/serve/web/components/controls/LorasControl.tsx +24 -22
  42. package/src/cli/serve/web/promptEditor/promptExtensions.ts +6 -3
  43. package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
  44. package/src/cli/serve/web/state/FormSt.ts +22 -2
  45. package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
  46. package/src/cli/serve/web/state/WebSt.ts +172 -33
  47. package/src/cli/serve/web/state/draftNames.ts +16 -0
  48. package/src/cli/serve/web/state/draftTabs.ts +75 -0
  49. package/src/cli/serve/web/state/generateButton.ts +1 -1
  50. package/src/cli/serve/web/state/omnibox.ts +82 -18
  51. package/src/cli/serve/web/state/shortcuts.ts +56 -7
  52. package/src/cli/serve/web/styles.ts +242 -82
  53. package/src/cli/serve/workflowTags.ts +42 -0
  54. package/src/cli/serve/workspaceLabels.ts +23 -0
  55. package/src/cli/tui/state/DraftsSt.ts +10 -6
  56. package/src/coreExports.ts +1 -0
  57. package/src/host/ComfyHost.ts +17 -2
  58. package/src/host/ResilientWebsocket.ts +54 -4
  59. package/src/runner/ComfyExecution.ts +60 -0
  60. package/src/runner/ComfyWorkflow.ts +4 -0
  61. package/src/runner/ComfyWsApi.ts +2 -0
  62. package/src/runner/MediaImage.ts +2 -2
  63. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
  64. package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
  65. package/src/utils/copyName.ts +12 -0
  66. package/src/vars/DefinedWorkflow.ts +7 -1
  67. package/dist/LogsSt-U1H0mP1m.js.map +0 -1
  68. package/dist/run-serve-BeAznay5.js.map +0 -1
  69. package/dist/state-C7REnHan.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { Z as ansi, a as DefinedWorkflow, at as isQuiet, ct as logSuccess, dt as sha1HexOfString, et as extractErrorMessage, it as resolveComfyStorage, lt as statelessRegex, n as diffSchemas, nt as bang, ot as logError, rt as getComfyStorage, st as logInfo, t as MODEL_LISTS, tt as isRecord$1, ut as sha1Hex } from "./schemaDrift-Cg39vs53.js";
1
+ import { Z as ansi, a as DefinedWorkflow, at as isQuiet, ct as logSuccess, dt as sha1HexOfString, et as extractErrorMessage, it as resolveComfyStorage, lt as statelessRegex, n as diffSchemas, nt as bang, ot as logError, rt as getComfyStorage, st as logInfo, t as MODEL_LISTS, tt as isRecord$1, ut as sha1Hex } from "./schemaDrift-E95iTF7E.js";
2
2
  import { basename, join } from "pathe";
3
3
  import { scope, type } from "arktype";
4
4
  import { nanoid } from "nanoid";
@@ -508,7 +508,7 @@ function codegenSDK(opts) {
508
508
  p("}");
509
509
  p(`interface Builder {`);
510
510
  for (const n of nodes) {
511
- const baseDescription = `displayName="${n.raw.display_name}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
511
+ const baseDescription = `displayName="${n.raw.display_name ?? n.nameInComfy}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
512
512
  if (n.raw.description) {
513
513
  p(` /**`);
514
514
  p(n.raw.description.split("\n").map((i) => ` * ${i}`).join("\n"));
@@ -850,7 +850,7 @@ var ComfySchema = class {
850
850
  };
851
851
  //#endregion
852
852
  //#region package.json
853
- var version = "2.12.0";
853
+ var version = "2.13.0";
854
854
  //#endregion
855
855
  //#region src/litegraph/LiteGraphLinkID.ts
856
856
  const asLiteGraphLinkID = (id) => id;
@@ -2412,6 +2412,7 @@ const types$1 = scope({
2412
2412
  output: {
2413
2413
  "previews?": [{ filepath: "string" }, "[]"],
2414
2414
  "images?": "ComfyImageInfo[]",
2415
+ "audio?": "ComfyImageInfo[]",
2415
2416
  "text?": "unknown[]"
2416
2417
  },
2417
2418
  prompt_id: "PromptID"
@@ -2512,11 +2513,11 @@ var MediaImage = class MediaImage {
2512
2513
  });
2513
2514
  };
2514
2515
  this.loadInWorkflow_viaLoadImageNode = async (workflow) => {
2515
- const enumName = await this.uploadAndReturnEnumName(workflow.host);
2516
+ const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
2516
2517
  return bang(workflow.builderBase.LoadImage, "host has no LoadImage node")({ image: enumName });
2517
2518
  };
2518
2519
  this.loadInWorkflowAsMask_viaLoadImageMask = async (channel, workflow) => {
2519
- const enumName = await this.uploadAndReturnEnumName(workflow.host);
2520
+ const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
2520
2521
  return bang(workflow.builderBase.LoadImageMask, "host has no LoadImageMask node")({
2521
2522
  image: enumName,
2522
2523
  channel
@@ -2664,6 +2665,18 @@ var MediaImage = class MediaImage {
2664
2665
  * A claim is released as soon as the write lands (the file itself then holds
2665
2666
  * the name) or fails (the name is free again) — the set never accumulates */
2666
2667
  const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
2668
+ const AUDIO_MIMES = {
2669
+ flac: "audio/flac",
2670
+ mp3: "audio/mpeg",
2671
+ opus: "audio/ogg",
2672
+ ogg: "audio/ogg",
2673
+ wav: "audio/wav",
2674
+ m4a: "audio/mp4"
2675
+ };
2676
+ function audioMime(filename) {
2677
+ const ext = filename.split(".").pop()?.toLowerCase() ?? "";
2678
+ return AUDIO_MIMES[ext] ?? "application/octet-stream";
2679
+ }
2667
2680
  var ComfyExecution = class {
2668
2681
  get host() {
2669
2682
  return this.workflow.host;
@@ -2738,8 +2751,51 @@ var ComfyExecution = class {
2738
2751
  error: e
2739
2752
  });
2740
2753
  }));
2754
+ for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveAudio(audio, promptNodeID).catch((e) => {
2755
+ console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
2756
+ this.audioErrors.push({
2757
+ audio,
2758
+ error: e
2759
+ });
2760
+ }));
2741
2761
  };
2742
2762
  this.pendingPromises = [];
2763
+ this.audioErrors = [];
2764
+ this.audios = [];
2765
+ this.retrieveAudio = async (info, promptNodeID) => {
2766
+ const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
2767
+ const bytes = new Uint8Array(await response.arrayBuffer());
2768
+ const mime = audioMime(info.filename);
2769
+ const sf = this.save;
2770
+ if (sf == null) {
2771
+ this.audios.push({
2772
+ nodeId: promptNodeID,
2773
+ filename: info.filename,
2774
+ mime,
2775
+ bytes,
2776
+ absPath: null
2777
+ });
2778
+ return;
2779
+ }
2780
+ const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs["filename_prefix"];
2781
+ const written = await this.encodeAndWrite({
2782
+ bytes,
2783
+ sf: {
2784
+ ...sf,
2785
+ format: "raw"
2786
+ },
2787
+ filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
2788
+ subfolder: info.subfolder,
2789
+ filename: info.filename
2790
+ });
2791
+ this.audios.push({
2792
+ nodeId: promptNodeID,
2793
+ filename: info.filename,
2794
+ mime,
2795
+ bytes,
2796
+ absPath: written.path
2797
+ });
2798
+ };
2743
2799
  this.imageErrors = [];
2744
2800
  this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
2745
2801
  const promptNode = this.workflow.data.apiJson?.[promptNodeID];
@@ -2911,6 +2967,7 @@ var ComfyExecution = class {
2911
2967
  if (!this.logProgress) return;
2912
2968
  const p = this.progress;
2913
2969
  const outputs = [`${this.images.length} image(s)`];
2970
+ if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
2914
2971
  if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
2915
2972
  const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
2916
2973
  if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
@@ -3110,6 +3167,7 @@ var ComfyWorkflow = class {
3110
3167
  constructor(host, data) {
3111
3168
  this.host = host;
3112
3169
  this.data = data;
3170
+ this.dry = false;
3113
3171
  this.nodes = [];
3114
3172
  this.registerNode = (node) => {
3115
3173
  if (this.data.apiJson == null) throw new Error("graph not hydrated");
@@ -3336,16 +3394,16 @@ const types = scope({
3336
3394
  "hidden?": "string[]"
3337
3395
  },
3338
3396
  output: "ComfyInputType[]",
3339
- output_is_list: "boolean[]",
3397
+ output_is_list: "(boolean | null)[]",
3340
3398
  output_name: "string[]",
3341
3399
  name: "string",
3342
- display_name: "string",
3400
+ display_name: "string | null",
3343
3401
  description: "string",
3344
3402
  /** */
3345
3403
  python_module: "string",
3346
3404
  category: "string",
3347
3405
  output_node: "boolean",
3348
- "output_tooltips?": "string[]",
3406
+ "output_tooltips?": "(string | null)[]",
3349
3407
  "deprecated?": "boolean",
3350
3408
  "experimental?": "boolean"
3351
3409
  },
@@ -3361,7 +3419,7 @@ const types = scope({
3361
3419
  ComfyInputOpts_advanced: {
3362
3420
  "tooltip?": "string | null | ComfyInputOpts_advanced",
3363
3421
  "multiline?": "boolean | null",
3364
- "default?": "boolean | number | string | null | number[]",
3422
+ "default?": "boolean | number | string | null | number[] | object",
3365
3423
  "forceInput?": "boolean | null",
3366
3424
  "min?": "number | null",
3367
3425
  "round?": "boolean | number | null",
@@ -3722,14 +3780,46 @@ var ResilientWebSocketClient = class {
3722
3780
  this.isOpen = false;
3723
3781
  this.debugMessages = [];
3724
3782
  this.hasEverOpened = false;
3783
+ this.heartbeat = null;
3725
3784
  this.permanentlyClosed = false;
3726
3785
  this.url = options.url();
3727
3786
  this.connect();
3728
3787
  }
3788
+ stopHeartbeat() {
3789
+ if (this.heartbeat != null) clearInterval(this.heartbeat);
3790
+ this.heartbeat = null;
3791
+ }
3792
+ /** ping on a timer; no pong since the previous ping = the peer is gone, drop the socket */
3793
+ startHeartbeat(ws) {
3794
+ this.stopHeartbeat();
3795
+ if (typeof ws.ping !== "function" || typeof ws.on !== "function") return;
3796
+ let awaitingPong = false;
3797
+ ws.on("pong", () => {
3798
+ awaitingPong = false;
3799
+ });
3800
+ const ms = this.options.heartbeatMs ?? 15e3;
3801
+ this.heartbeat = setInterval(() => {
3802
+ if (ws !== this.currentWS) return this.stopHeartbeat();
3803
+ if (awaitingPong) {
3804
+ this.addError(`no pong within ${ms}ms: the host is gone, dropping the socket to reconnect`);
3805
+ this.stopHeartbeat();
3806
+ if (typeof ws.terminate === "function") ws.terminate();
3807
+ else ws.close();
3808
+ return;
3809
+ }
3810
+ awaitingPong = true;
3811
+ try {
3812
+ ws.ping?.();
3813
+ } catch (e) {
3814
+ this.addError(`ping failed: ${extractErrorMessage(e)}`);
3815
+ }
3816
+ }, ms);
3817
+ }
3729
3818
  /** close and stop reconnecting (lets a script exit cleanly) */
3730
3819
  disconnectPermanently() {
3731
3820
  this.permanentlyClosed = true;
3732
3821
  if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
3822
+ this.stopHeartbeat();
3733
3823
  this.currentWS?.close();
3734
3824
  this.currentWS = null;
3735
3825
  this.isOpen = false;
@@ -3748,6 +3838,7 @@ var ResilientWebSocketClient = class {
3748
3838
  this.isOpen = false;
3749
3839
  const prevWS = this.currentWS;
3750
3840
  if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
3841
+ this.stopHeartbeat();
3751
3842
  this.currentWS = null;
3752
3843
  if (prevWS) {
3753
3844
  this.addInfo("Previous WebSocket discarded");
@@ -3755,7 +3846,7 @@ var ResilientWebSocketClient = class {
3755
3846
  }
3756
3847
  let ws;
3757
3848
  try {
3758
- const transport = await resolveWsTransport();
3849
+ const transport = this.options.transport ?? await resolveWsTransport();
3759
3850
  if (this.permanentlyClosed) return;
3760
3851
  const headers = this.options.headers?.() ?? {};
3761
3852
  ws = transport.supportsHeaders ? new transport.ctor(this.url, { headers }) : new transport.ctor(this.headerlessUrl(headers));
@@ -3777,10 +3868,12 @@ var ResilientWebSocketClient = class {
3777
3868
  this.isOpen = true;
3778
3869
  this.options.onConnectOrReconnect();
3779
3870
  this.flushMessageBuffer();
3871
+ this.startHeartbeat(ws);
3780
3872
  };
3781
3873
  ws.onclose = (event) => {
3782
3874
  if (ws !== this.currentWS) return;
3783
3875
  this.isOpen = false;
3876
+ this.stopHeartbeat();
3784
3877
  this.options.onClose();
3785
3878
  if (this.permanentlyClosed) return;
3786
3879
  this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
@@ -3789,8 +3882,9 @@ var ResilientWebSocketClient = class {
3789
3882
  this.options.onFirstConnectFailed(/* @__PURE__ */ new Error(`connection refused (code=${event.code}${event.reason === "" ? "" : `, ${event.reason}`})`));
3790
3883
  return;
3791
3884
  }
3792
- this.addInfo("⏱️ reconnecting in 2 seconds...");
3793
- this.reconnectTimeout = setTimeout(() => void this.connect(), 2e3);
3885
+ const wait = this.options.reconnectMs ?? 2e3;
3886
+ this.addInfo(`⏱️ reconnecting in ${wait / 1e3} seconds...`);
3887
+ this.reconnectTimeout = setTimeout(() => void this.connect(), wait);
3794
3888
  };
3795
3889
  ws.onerror = (event) => {
3796
3890
  if (ws !== this.currentWS) return;
@@ -4004,8 +4098,22 @@ var ComfyHost = class {
4004
4098
  this.clearQueue = () => {
4005
4099
  return this.postJSON_("/queue", { clear: true });
4006
4100
  };
4101
+ this.interruptCoalesceMs = 3e3;
4102
+ this._lastInterrupt = null;
4007
4103
  this.interrupt = () => {
4008
- return this.postJSON_("/interrupt", {});
4104
+ const now = Date.now();
4105
+ const last = this._lastInterrupt;
4106
+ if (last != null && last.promptID === this.activePromptID && now - last.at < this.interruptCoalesceMs) return last.req;
4107
+ const req = this.postJSON_("/interrupt", {});
4108
+ this._lastInterrupt = {
4109
+ promptID: this.activePromptID,
4110
+ at: now,
4111
+ req
4112
+ };
4113
+ req.catch(() => {
4114
+ if (this._lastInterrupt?.req === req) this._lastInterrupt = null;
4115
+ });
4116
+ return req;
4009
4117
  };
4010
4118
  this.deleteHistory = (promptId) => {
4011
4119
  return this.postJSON_("/history", { delete: [promptId] });
@@ -5020,4 +5128,4 @@ var ComfyTS = class ComfyTS {
5020
5128
  //#endregion
5021
5129
  export { ComfySchema as a, importSharp as i, settingsPathFor as n, readableStringify as r, ComfyTS as t };
5022
5130
 
5023
- //# sourceMappingURL=state-C7REnHan.js.map
5131
+ //# sourceMappingURL=state-CUp2J1Zy.js.map