comfy-ts 1.4.0 → 2.0.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 (89) hide show
  1. package/README.md +80 -6
  2. package/dist/{DefinedWorkflow-C_QAxKr3.js → DefinedWorkflow-CqNE_kgR.js} +4 -2
  3. package/dist/{DefinedWorkflow-C_QAxKr3.js.map → DefinedWorkflow-CqNE_kgR.js.map} +1 -1
  4. package/dist/{DraftsSt-DcOTn0QR.js → DraftsSt-Da4DZUP7.js} +2 -2
  5. package/dist/{DraftsSt-DcOTn0QR.js.map → DraftsSt-Da4DZUP7.js.map} +1 -1
  6. package/dist/cli.js +3 -3
  7. package/dist/index.cjs +212 -66
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +72 -77
  10. package/dist/index.d.ts +72 -77
  11. package/dist/index.js +212 -66
  12. package/dist/index.js.map +1 -1
  13. package/dist/{run-serve-CN0DhrsA.js → run-serve-BqeXtf8P.js} +9 -7
  14. package/dist/run-serve-BqeXtf8P.js.map +1 -0
  15. package/dist/{run-tui-bN2hSD5i.js → run-tui-CiB7TbYv.js} +12 -6
  16. package/dist/run-tui-CiB7TbYv.js.map +1 -0
  17. package/dist/{state-COlKYipO.js → state-C1g_B8zR.js} +211 -67
  18. package/dist/state-C1g_B8zR.js.map +1 -0
  19. package/dist/web.d.ts +72 -77
  20. package/dist/web.js +212 -66
  21. package/dist/web.js.map +1 -1
  22. package/examples/comfy-cloud/ace-step-t2a.cflow.ts +1 -0
  23. package/examples/comfy-cloud/anima-t2i.cflow.ts +2 -3
  24. package/examples/comfy-cloud/boogu-i2i.cflow.ts +2 -5
  25. package/examples/comfy-cloud/capybara-i2i.cflow.ts +2 -2
  26. package/examples/comfy-cloud/capybara-i2v.cflow.ts +1 -0
  27. package/examples/comfy-cloud/capybara-t2i.cflow.ts +2 -2
  28. package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +1 -0
  29. package/examples/comfy-cloud/chroma-t2i.cflow.ts +2 -5
  30. package/examples/comfy-cloud/ernie-t2i.cflow.ts +2 -3
  31. package/examples/comfy-cloud/firered-i2i.cflow.ts +2 -2
  32. package/examples/comfy-cloud/flux1-i2i.cflow.ts +2 -2
  33. package/examples/comfy-cloud/flux1-t2i.cflow.ts +2 -2
  34. package/examples/comfy-cloud/flux2-i2i.cflow.ts +2 -5
  35. package/examples/comfy-cloud/flux2-t2i.cflow.ts +2 -5
  36. package/examples/comfy-cloud/hidream-i2i.cflow.ts +2 -5
  37. package/examples/comfy-cloud/hidream-t2i.cflow.ts +2 -2
  38. package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +1 -0
  39. package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +1 -0
  40. package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +2 -3
  41. package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +1 -0
  42. package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +2 -2
  43. package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +1 -0
  44. package/examples/comfy-cloud/krea2-t2i.cflow.ts +2 -3
  45. package/examples/comfy-cloud/lens-t2i.cflow.ts +2 -3
  46. package/examples/comfy-cloud/longcat-i2i.cflow.ts +2 -2
  47. package/examples/comfy-cloud/longcat-t2i.cflow.ts +2 -5
  48. package/examples/comfy-cloud/ltxv-i2v.cflow.ts +1 -0
  49. package/examples/comfy-cloud/ltxv-t2v.cflow.ts +1 -0
  50. package/examples/comfy-cloud/newbie-t2i.cflow.ts +2 -5
  51. package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +2 -5
  52. package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +2 -5
  53. package/examples/comfy-cloud/ovis-t2i.cflow.ts +2 -5
  54. package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +2 -5
  55. package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +2 -2
  56. package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +2 -2
  57. package/examples/comfy-cloud/sd35-t2i.cflow.ts +2 -2
  58. package/examples/comfy-cloud/sdk.d.ts +13251 -11458
  59. package/examples/comfy-cloud/sdxl-t2i.cflow.ts +2 -2
  60. package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +1 -0
  61. package/examples/comfy-cloud/svd-i2v.cflow.ts +1 -0
  62. package/examples/comfy-cloud/wan21-i2v.cflow.ts +1 -0
  63. package/examples/comfy-cloud/wan21-t2v.cflow.ts +1 -0
  64. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +1 -0
  65. package/examples/comfy-cloud/wan22-i2v.cflow.ts +1 -0
  66. package/examples/comfy-cloud/wan22-t2v.cflow.ts +1 -0
  67. package/examples/comfy-cloud/z-image-t2i.cflow.ts +2 -5
  68. package/examples/rvion/01-txt2img.cflow.ts +5 -3
  69. package/examples/rvion/02-img2img-upload.cflow.ts +5 -4
  70. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +6 -7
  71. package/examples/rvion/05-comfy-cloud.cflow.ts +4 -2
  72. package/examples/rvion/06-qwen-image-edit.cflow.ts +2 -3
  73. package/examples/web/example.ts +8 -1
  74. package/package.json +1 -1
  75. package/src/cli/serve/ServeApp.ts +9 -6
  76. package/src/cli/tui/state/ExecSt.ts +14 -2
  77. package/src/host/ComfyHost.ts +33 -1
  78. package/src/runner/ComfyExecution.ts +162 -74
  79. package/src/runner/ComfyWorkflow.ts +25 -3
  80. package/src/runner/ComfyWsApi.ts +6 -0
  81. package/src/runner/MediaImage.ts +58 -11
  82. package/src/runner/ephemeral.ts +21 -0
  83. package/src/runner/outputPath.ts +2 -2
  84. package/src/sdk-generator/_pythonModuleToNamespace.ts +3 -0
  85. package/src/types/index.ts +6 -2
  86. package/src/vars/DefinedWorkflow.ts +3 -1
  87. package/dist/run-serve-CN0DhrsA.js.map +0 -1
  88. package/dist/run-tui-bN2hSD5i.js.map +0 -1
  89. package/dist/state-COlKYipO.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -134,7 +134,7 @@ function createNodeStorage() {
134
134
  }
135
135
  //#endregion
136
136
  //#region package.json
137
- var version = "1.4.0";
137
+ var version = "2.0.0";
138
138
  //#endregion
139
139
  //#region src/litegraph/LiteGraphLinkID.ts
140
140
  const asLiteGraphLinkID = (id) => id;
@@ -1686,7 +1686,7 @@ var LiteGraphCtx = class {
1686
1686
  * `_00001_` counter every run, so trusting it overwrote the same file — and
1687
1687
  * a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
1688
1688
  * prefix. Local names are ours: dir from the prompt's own filename_prefix
1689
- * (or an explicit saveFormat.prefix override), then
1689
+ * (or an explicit save.prefix override), then
1690
1690
  * `<stem>_<timestamp>_<counter><ext>` so every run sorts chronologically
1691
1691
  * per stem and nothing ever collides.
1692
1692
  */
@@ -2019,6 +2019,21 @@ const PromptInfo_ark = (0, arktype.type)({ prompt_id: types$1.PromptID }).as();
2019
2019
  const WsMsg_ark = types$1.WsMsg;
2020
2020
  const ComfyImageInfo_ark = types$1.ComfyImageInfo;
2021
2021
  const WsMsgLogsData_ark = types$1._WsMsgLogsData;
2022
+ //#endregion
2023
+ //#region src/runner/MediaImage.ts
2024
+ /** base64 image loader nodes we know how to wire, in preference order — each
2025
+ * verified against a real object_info dump before entering the table */
2026
+ const BASE64_IMAGE_LOADERS = [{
2027
+ nameInComfy: "ETN_LoadImageBase64",
2028
+ inputs: (b64) => ({ image: b64 })
2029
+ }, {
2030
+ nameInComfy: "easy loadImageBase64",
2031
+ inputs: (b64) => ({
2032
+ base64_data: b64,
2033
+ image_output: "Hide",
2034
+ save_prefix: ""
2035
+ })
2036
+ }];
2022
2037
  (0, arktype.type)({
2023
2038
  comfyHostHttpURL: "string",
2024
2039
  comfyImageInfo: ComfyImageInfo_ark
@@ -2047,8 +2062,19 @@ var MediaImage = class MediaImage {
2047
2062
  channel
2048
2063
  });
2049
2064
  };
2065
+ this.loadInWorkflow_viaBase64Node = (workflow) => {
2066
+ const schema = workflow.host.schema;
2067
+ const entry = BASE64_IMAGE_LOADERS.find((t) => schema.nodes.some((n) => n.nameInComfy === t.nameInComfy));
2068
+ if (entry == null) throw new Error(`❌ host '${workflow.host.data.id}' has no base64 image loader node (looked for: ${BASE64_IMAGE_LOADERS.map((t) => `'${t.nameInComfy}'`).join(", ")}). Install one (e.g. comfyui-tooling-nodes) or fall back to loadInWorkflow_viaLoadImageNode (uploads persist server-side).`);
2069
+ return new ComfyNode(workflow, (workflow._uidNumber++).toString(), {
2070
+ class_type: entry.nameInComfy,
2071
+ inputs: entry.inputs(this.getBase64Payload())
2072
+ }, {});
2073
+ };
2050
2074
  this._buffer = null;
2051
- this.freeBuffer = () => void (this._buffer = null);
2075
+ this.freeBuffer = () => {
2076
+ if (this.absPath != null) this._buffer = null;
2077
+ };
2052
2078
  this.updateBuffer = (buff) => {
2053
2079
  this._buffer = buff;
2054
2080
  this._metadata = null;
@@ -2064,32 +2090,34 @@ var MediaImage = class MediaImage {
2064
2090
  this._hash = null;
2065
2091
  this.processWithSharp_inplace = async (fn) => {
2066
2092
  const buff = await fn((await importSharp("processWithSharp_inplace"))(this.buffer)).toBuffer();
2067
- getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
2093
+ if (this.absPath != null) getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
2068
2094
  this.updateBuffer(new Uint8Array(buff));
2069
2095
  return this;
2070
2096
  };
2071
2097
  this.processWithSharp = async (fn, path) => {
2072
2098
  const sharp = await importSharp("processWithSharp");
2073
- path ??= this.absPath + `.processed-${Date.now()}` + this.extension;
2099
+ path ??= this.absPath != null ? asAbsolutePath(this.absPath + `.processed-${Date.now()}` + this.extension) : void 0;
2074
2100
  const buffer = new Uint8Array(await fn(sharp(this.buffer)).toBuffer());
2075
- getComfyStorage().writeBytes(path, buffer);
2101
+ if (path != null) getComfyStorage().writeBytes(path, buffer);
2076
2102
  return new MediaImage({
2077
2103
  path,
2078
2104
  buffer
2079
2105
  });
2080
2106
  };
2081
- this.absPath = data.path;
2107
+ this.absPath = data.path ?? null;
2082
2108
  this.execution = data.execution;
2083
2109
  this.promptNodeID = data.promptNodeID;
2110
+ if (data.path == null && data.buffer == null) throw new Error("❌ MediaImage: an in-memory image (no path) requires a buffer");
2084
2111
  if (data.buffer != null) this.updateBuffer(data.buffer);
2085
2112
  }
2086
2113
  /** the image as a Blob, e.g. to feed FormData uploads */
2087
2114
  getAsBlob() {
2088
2115
  return new Blob([this.buffer], { type: `image/${this.metadata.type ?? "png"}` });
2089
2116
  }
2090
- /** return the image filename */
2117
+ /** return the image filename (in-memory images get a stable hash-derived name) */
2091
2118
  get filename() {
2092
- return (0, pathe.basename)(this.absPath);
2119
+ if (this.absPath != null) return (0, pathe.basename)(this.absPath);
2120
+ return `image-${this.hash.slice(0, 8)}.${this.metadata.type ?? "png"}`;
2093
2121
  }
2094
2122
  get baseNameWithoutExtension() {
2095
2123
  const fname = this.filename;
@@ -2155,7 +2183,7 @@ var MediaImage = class MediaImage {
2155
2183
  }
2156
2184
  get buffer() {
2157
2185
  if (this._buffer != null) return this._buffer;
2158
- this._buffer = getComfyStorage().readBytes(this.absPath);
2186
+ this._buffer = getComfyStorage().readBytes(bang(this.absPath, "in-memory MediaImage lost its buffer"));
2159
2187
  return this._buffer;
2160
2188
  }
2161
2189
  get metadata() {
@@ -2181,7 +2209,9 @@ var ComfyExecution = class {
2181
2209
  constructor(workflow, data, init = {}) {
2182
2210
  this.workflow = workflow;
2183
2211
  this.data = data;
2184
- this.saveFormat = null;
2212
+ this.save = null;
2213
+ this.scrubHistory = false;
2214
+ this.ephemeral = false;
2185
2215
  this.snapshot = null;
2186
2216
  this.onProgress = null;
2187
2217
  this.logProgress = false;
@@ -2192,6 +2222,13 @@ var ComfyExecution = class {
2192
2222
  });
2193
2223
  this.onPromptRelatedMessage = (msg) => {
2194
2224
  const graph = this.workflow;
2225
+ if (msg.type === "binary_preview_frame") {
2226
+ if (this.wsOutputNodeExecuting) this.onWsImageOutput({
2227
+ bytes: msg.bytes,
2228
+ mime: msg.mime
2229
+ });
2230
+ return;
2231
+ }
2195
2232
  if (msg.type === "execution_start") return;
2196
2233
  else if (msg.type === "execution_cached") graph.onExecutionCached(msg);
2197
2234
  else if (msg.type === "executing") this.onExecuting(msg);
@@ -2235,72 +2272,104 @@ var ComfyExecution = class {
2235
2272
  this.imageErrors = [];
2236
2273
  this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
2237
2274
  const promptNode = this.workflow.data.apiJson?.[promptNodeID];
2238
- const promptMeta = this.workflow.data.metadata?.[promptNodeID];
2239
2275
  if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`);
2240
2276
  const imgRoute = "/view?" + new URLSearchParams(comfyImageInfo).toString();
2241
- const sf = this.saveFormat;
2277
+ const response = await this.host.fetchFile(imgRoute);
2278
+ const bytes = new Uint8Array(await response.arrayBuffer());
2279
+ const comfyUIInfos = {
2280
+ comfyImageInfo,
2281
+ comfyHostHttpURL: this.host.getServerHostHTTP()
2282
+ };
2283
+ const sf = this.save;
2284
+ if (sf == null) return this.pushImage(new MediaImage({
2285
+ buffer: bytes,
2286
+ execution: this,
2287
+ promptNodeID,
2288
+ comfyUIInfos
2289
+ }), promptNodeID);
2242
2290
  const promptPrefix = promptNode.inputs["filename_prefix"];
2243
- let absPath = comfyts.resolveFromOutput(localOutputPath({
2244
- localDir: sf?.prefix,
2291
+ const written = await this.encodeAndWrite({
2292
+ bytes,
2293
+ sf,
2245
2294
  filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
2246
2295
  subfolder: comfyImageInfo.subfolder,
2247
- filename: comfyImageInfo.filename,
2248
- timestamp: runTimestamp(new Date(this.startedAt))
2249
- }));
2250
- if (sf?.format && sf.format !== "raw") {
2251
- const extension = sf.format.split("/")[1];
2252
- absPath += "." + extension;
2253
- }
2254
- const storage = getComfyStorage();
2255
- absPath = uniquifyOutputPath({
2256
- path: absPath,
2257
- exists: (p) => storage.exists(p),
2258
- claimed: CLAIMED_OUTPUT_PATHS
2296
+ filename: comfyImageInfo.filename
2259
2297
  });
2260
- let img;
2261
- if (sf && sf.format !== "raw") {
2262
- const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
2298
+ this.pushImage(new MediaImage({
2299
+ path: written.path,
2300
+ buffer: written.bytes,
2301
+ execution: this,
2302
+ promptNodeID,
2303
+ comfyUIInfos
2304
+ }), promptNodeID);
2305
+ };
2306
+ this.encodeAndWrite = async (p) => {
2307
+ let bytes = p.bytes;
2308
+ const reencode = p.sf.format != null && p.sf.format !== "raw";
2309
+ if (reencode) {
2263
2310
  let textChunk = {};
2264
2311
  try {
2265
- const res = getPngMetadataFromUint8Array(new Uint8Array(buff));
2312
+ const res = getPngMetadataFromUint8Array(p.bytes);
2266
2313
  if (res.success) textChunk = res.value;
2267
2314
  } catch {}
2268
2315
  const format = (() => {
2269
- if (sf.format === "image/jpeg") return "jpeg";
2270
- if (sf.format === "image/png") return "png";
2271
- if (sf.format === "image/webp") return "webp";
2316
+ if (p.sf.format === "image/jpeg") return "jpeg";
2317
+ if (p.sf.format === "image/webp") return "webp";
2272
2318
  return "png";
2273
2319
  })();
2274
- const encoded = await (await importSharp(`saveFormat '${sf.format}' re-encoding`))(buff).withMetadata().withExif({ IFD0: textChunk }).toFormat(format, sf.quality ? { quality: Math.round(sf.quality * 100) } : void 0).toBuffer();
2275
- storage.writeBytes(asAbsolutePath(absPath), new Uint8Array(encoded));
2276
- img = new MediaImage({
2277
- path: asAbsolutePath(absPath),
2278
- buffer: new Uint8Array(encoded),
2279
- execution: this,
2280
- promptNodeID,
2281
- comfyUIInfos: {
2282
- comfyImageInfo,
2283
- comfyHostHttpURL: this.host.getServerHostHTTP()
2284
- }
2285
- });
2286
- } else {
2287
- const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
2288
- const uint8arr = new Uint8Array(buff);
2289
- storage.writeBytes(asAbsolutePath(absPath), uint8arr);
2290
- img = new MediaImage({
2291
- path: asAbsolutePath(absPath),
2292
- buffer: uint8arr,
2293
- execution: this,
2294
- promptNodeID,
2295
- comfyUIInfos: {
2296
- comfyImageInfo,
2297
- comfyHostHttpURL: this.host.getServerHostHTTP()
2298
- }
2299
- });
2320
+ const encoded = await (await importSharp(`save format '${p.sf.format}' re-encoding`))(p.bytes).withMetadata().withExif({ IFD0: textChunk }).toFormat(format, p.sf.quality ? { quality: Math.round(p.sf.quality * 100) } : void 0).toBuffer();
2321
+ bytes = new Uint8Array(encoded);
2300
2322
  }
2301
- if (promptMeta?.tag) img.tags.push(promptMeta.tag);
2302
- if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
2303
- this.images.push(img);
2323
+ let absPath = comfyts.resolveFromOutput(localOutputPath({
2324
+ localDir: p.sf.prefix,
2325
+ filenamePrefix: p.filenamePrefix,
2326
+ subfolder: p.subfolder,
2327
+ filename: p.filename,
2328
+ timestamp: runTimestamp(new Date(this.startedAt))
2329
+ }));
2330
+ if (reencode) absPath += "." + bang(p.sf.format).split("/")[1];
2331
+ const storage = getComfyStorage();
2332
+ absPath = uniquifyOutputPath({
2333
+ path: absPath,
2334
+ exists: (x) => storage.exists(x),
2335
+ claimed: CLAIMED_OUTPUT_PATHS
2336
+ });
2337
+ storage.writeBytes(asAbsolutePath(absPath), bytes);
2338
+ return {
2339
+ path: asAbsolutePath(absPath),
2340
+ bytes
2341
+ };
2342
+ };
2343
+ this.onWsImageOutput = (p) => {
2344
+ const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null;
2345
+ this.pendingPromises.push(this.storeWsImage(p, promptNodeID).catch((e) => {
2346
+ console.error(`🔴 failed to store a SaveImageWebsocket output:`, e);
2347
+ this.imageErrors.push({
2348
+ image: null,
2349
+ error: e
2350
+ });
2351
+ }));
2352
+ };
2353
+ this.storeWsImage = async (p, promptNodeID) => {
2354
+ const sf = this.save;
2355
+ if (sf == null) return this.pushImage(new MediaImage({
2356
+ buffer: p.bytes,
2357
+ execution: this,
2358
+ promptNodeID
2359
+ }), promptNodeID);
2360
+ const ext = p.mime === "image/jpeg" ? "jpg" : p.mime.split("/")[1] ?? "png";
2361
+ const written = await this.encodeAndWrite({
2362
+ bytes: p.bytes,
2363
+ sf,
2364
+ subfolder: "",
2365
+ filename: `${this.workflow.id}.${ext}`
2366
+ });
2367
+ this.pushImage(new MediaImage({
2368
+ path: written.path,
2369
+ buffer: written.bytes,
2370
+ execution: this,
2371
+ promptNodeID
2372
+ }), promptNodeID);
2304
2373
  };
2305
2374
  this.images = [];
2306
2375
  this.alreadyDone = false;
@@ -2314,11 +2383,20 @@ var ComfyExecution = class {
2314
2383
  await Promise.all(this.pendingPromises);
2315
2384
  this.host.executions.delete(this.data.id);
2316
2385
  this.host._pendingMsgs.delete(this.data.id);
2386
+ if (this.ephemeral) {
2387
+ const classTypes = Object.values(this.snapshot?.apiJson ?? {}).map((n) => n.class_type);
2388
+ if (classTypes.includes("LoadImage") || classTypes.includes("LoadImageMask")) console.warn(`🟡 ephemeral run ${this.data.id}: outputs never touched the server disk, but the graph's LoadImage nodes reference files in the host's input/ folder (uploads persist — ComfyUI has no delete API). Use MediaImage.loadInWorkflow_viaBase64Node to keep inputs off the server too.`);
2389
+ }
2390
+ if (this.scrubHistory) await this.host.deleteHistory(this.data.id).catch((e) => {
2391
+ console.error(`🔴 failed to scrub history entry ${this.data.id} on host ${this.host.data.id}:`, e);
2392
+ });
2317
2393
  this.finishProgressLine();
2318
2394
  this._resolve(this);
2319
2395
  };
2320
2396
  this.snapshot = init.snapshot ?? null;
2321
- this.saveFormat = init.saveFormat ?? null;
2397
+ this.save = init.save === true ? {} : init.save === false ? null : init.save ?? null;
2398
+ this.scrubHistory = init.scrubHistory ?? false;
2399
+ this.ephemeral = init.ephemeral ?? false;
2322
2400
  this.onProgress = init.onProgress ?? null;
2323
2401
  this.logProgress = init.logProgress ?? false;
2324
2402
  this.host.executions.set(data.id, this);
@@ -2376,11 +2454,47 @@ var ComfyExecution = class {
2376
2454
  get status() {
2377
2455
  return this.data.status ?? "New";
2378
2456
  }
2457
+ /** accumulate an output on the prompt; tags from node metadata ride along */
2458
+ pushImage(img, promptNodeID) {
2459
+ const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null;
2460
+ if (promptMeta?.tag) img.tags.push(promptMeta.tag);
2461
+ if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
2462
+ this.images.push(img);
2463
+ }
2464
+ /** true while the currently executing node is a SaveImageWebsocket in the
2465
+ * SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
2466
+ * live graph may still say SaveImage) — binary frames are then OUTPUTS */
2467
+ get wsOutputNodeExecuting() {
2468
+ const uid = this.workflow.currentExecutingNode?.uid;
2469
+ if (uid == null) return false;
2470
+ return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
2471
+ }
2379
2472
  update(data) {
2380
2473
  Object.assign(this.data, data);
2381
2474
  }
2382
2475
  };
2383
2476
  //#endregion
2477
+ //#region src/runner/ephemeral.ts
2478
+ /**
2479
+ * the `ephemeral: true` rewrite (architecture.md item 14): every SaveImage
2480
+ * node in the SENT snapshot becomes a SaveImageWebsocket (core node, `images`
2481
+ * input only), so outputs stream over the ws and never touch the server disk.
2482
+ * Mutates the given apiJson IN PLACE — callers pass the run's deep-copied
2483
+ * snapshot, never the live graph. Returns how many nodes were rewritten so
2484
+ * callers can warn when a graph had nothing to rewrite.
2485
+ */
2486
+ function rewriteSaveNodesToWebsocket(apiJson) {
2487
+ let rewritten = 0;
2488
+ for (const node of Object.values(apiJson)) {
2489
+ if (node.class_type !== "SaveImage") continue;
2490
+ const images = node.inputs["images"];
2491
+ node.class_type = "SaveImageWebsocket";
2492
+ node.inputs = images == null ? {} : { images };
2493
+ rewritten++;
2494
+ }
2495
+ return rewritten;
2496
+ }
2497
+ //#endregion
2384
2498
  //#region src/utils/deepCopyNaive.ts
2385
2499
  const deepCopyNaive = (x) => JSON.parse(JSON.stringify(x));
2386
2500
  //#endregion
@@ -2647,6 +2761,11 @@ var ComfyWorkflow = class {
2647
2761
  apiJson: deepCopyNaive(this.toApiJson(p.idMode ?? "use_stringified_numbers_only")),
2648
2762
  workflowJson: await this.toWorkflowJson()
2649
2763
  };
2764
+ if (p.ephemeral) {
2765
+ const rewritten = rewriteSaveNodesToWebsocket(snapshot.apiJson);
2766
+ const hasWsSaver = Object.values(snapshot.apiJson).some((n) => n.class_type === "SaveImageWebsocket");
2767
+ if (rewritten === 0 && !hasWsSaver) console.warn(`🟡 ephemeral run: no SaveImage/SaveImageWebsocket node in workflow '${this.id}' — nothing streams back`);
2768
+ }
2650
2769
  const out = {
2651
2770
  client_id: this.host.comfySessionId,
2652
2771
  prompt: snapshot.apiJson,
@@ -2669,7 +2788,9 @@ var ComfyWorkflow = class {
2669
2788
  graphID: this.id
2670
2789
  }, {
2671
2790
  snapshot,
2672
- saveFormat: p.saveFormat,
2791
+ save: p.save,
2792
+ ephemeral: p.ephemeral ?? false,
2793
+ scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
2673
2794
  onProgress: p.onProgress,
2674
2795
  logProgress: p.log ?? false
2675
2796
  });
@@ -2763,6 +2884,7 @@ function getUnionNameBasedOnFirstFoundEnumName(enumName, hash, hashContent) {
2763
2884
  function pythonModuleToPrefix(pythonModule) {
2764
2885
  if (pythonModule === "nodes") return "";
2765
2886
  if (pythonModule.startsWith("comfy_extras.")) return "";
2887
+ if (pythonModule === "custom_nodes.websocket_image_save") return "";
2766
2888
  if (pythonModule.startsWith("comfy_api_nodes.")) return pythonModule.replace("comfy_api_nodes.", "api.");
2767
2889
  if (pythonModule.startsWith("custom_nodes.")) return pythonModule.replace(/^custom_nodes\./i, "").replace(/^comfyui[-_]/i, "").replace(/[-_]comfyui$/i, "").replace(/^comfy[-_]/i, "").replace(/[-_]comfy$/i, "").replace(/^nodes[-_]/i, "").replace(/[-_]node[-_]suite$/i, "") + ".";
2768
2890
  console.warn(`[comfy-ts] unexpected pythonModule "${pythonModule}", using it as prefix as-is`);
@@ -4444,7 +4566,9 @@ var DefinedWorkflow = class {
4444
4566
  advance: true,
4445
4567
  host
4446
4568
  })).run({
4447
- saveFormat: settings.saveFormat,
4569
+ save: settings.save,
4570
+ ephemeral: settings.ephemeral,
4571
+ scrubHistory: settings.scrubHistory,
4448
4572
  idMode: settings.idMode,
4449
4573
  log: settings.log,
4450
4574
  onProgress: settings.onProgress
@@ -4632,6 +4756,12 @@ var ComfyHost = class {
4632
4756
  this.interrupt = () => {
4633
4757
  return this.postJSON_("/interrupt", {});
4634
4758
  };
4759
+ this.deleteHistory = (promptId) => {
4760
+ return this.postJSON_("/history", { delete: [promptId] });
4761
+ };
4762
+ this.clearHistory = () => {
4763
+ return this.postJSON_("/history", { clear: true });
4764
+ };
4635
4765
  this.fetchRawLogs = async () => {
4636
4766
  const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
4637
4767
  if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
@@ -4867,6 +4997,22 @@ var ComfyHost = class {
4867
4997
  if (e.data instanceof ArrayBuffer) {
4868
4998
  const frame = parseBinaryWsFrame(e.data);
4869
4999
  if (frame.kind === "preview") {
5000
+ const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null;
5001
+ if (activeExec?.wsOutputNodeExecuting) {
5002
+ activeExec.onWsImageOutput({
5003
+ bytes: frame.bytes,
5004
+ mime: frame.mime
5005
+ });
5006
+ return;
5007
+ }
5008
+ if (this.activePromptID != null) {
5009
+ const pending = this._pendingMsgs.get(this.activePromptID);
5010
+ if (pending != null) pending.push({
5011
+ type: "binary_preview_frame",
5012
+ bytes: frame.bytes,
5013
+ mime: frame.mime
5014
+ });
5015
+ }
4870
5016
  const imageBlob = new Blob([frame.bytes], { type: frame.mime });
4871
5017
  this.latentPreview = {
4872
5018
  blob: imageBlob,