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/web.js CHANGED
@@ -101,7 +101,7 @@ function getComfyStorage() {
101
101
  }
102
102
  //#endregion
103
103
  //#region package.json
104
- var version = "1.4.0";
104
+ var version = "2.0.0";
105
105
  //#endregion
106
106
  //#region src/litegraph/LiteGraphLinkID.ts
107
107
  const asLiteGraphLinkID = (id) => id;
@@ -1653,7 +1653,7 @@ var LiteGraphCtx = class {
1653
1653
  * `_00001_` counter every run, so trusting it overwrote the same file — and
1654
1654
  * a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
1655
1655
  * prefix. Local names are ours: dir from the prompt's own filename_prefix
1656
- * (or an explicit saveFormat.prefix override), then
1656
+ * (or an explicit save.prefix override), then
1657
1657
  * `<stem>_<timestamp>_<counter><ext>` so every run sorts chronologically
1658
1658
  * per stem and nothing ever collides.
1659
1659
  */
@@ -1983,6 +1983,21 @@ const PromptInfo_ark = type({ prompt_id: types$1.PromptID }).as();
1983
1983
  const WsMsg_ark = types$1.WsMsg;
1984
1984
  const ComfyImageInfo_ark = types$1.ComfyImageInfo;
1985
1985
  const WsMsgLogsData_ark = types$1._WsMsgLogsData;
1986
+ //#endregion
1987
+ //#region src/runner/MediaImage.ts
1988
+ /** base64 image loader nodes we know how to wire, in preference order — each
1989
+ * verified against a real object_info dump before entering the table */
1990
+ const BASE64_IMAGE_LOADERS = [{
1991
+ nameInComfy: "ETN_LoadImageBase64",
1992
+ inputs: (b64) => ({ image: b64 })
1993
+ }, {
1994
+ nameInComfy: "easy loadImageBase64",
1995
+ inputs: (b64) => ({
1996
+ base64_data: b64,
1997
+ image_output: "Hide",
1998
+ save_prefix: ""
1999
+ })
2000
+ }];
1986
2001
  type({
1987
2002
  comfyHostHttpURL: "string",
1988
2003
  comfyImageInfo: ComfyImageInfo_ark
@@ -2011,8 +2026,19 @@ var MediaImage = class MediaImage {
2011
2026
  channel
2012
2027
  });
2013
2028
  };
2029
+ this.loadInWorkflow_viaBase64Node = (workflow) => {
2030
+ const schema = workflow.host.schema;
2031
+ const entry = BASE64_IMAGE_LOADERS.find((t) => schema.nodes.some((n) => n.nameInComfy === t.nameInComfy));
2032
+ 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).`);
2033
+ return new ComfyNode(workflow, (workflow._uidNumber++).toString(), {
2034
+ class_type: entry.nameInComfy,
2035
+ inputs: entry.inputs(this.getBase64Payload())
2036
+ }, {});
2037
+ };
2014
2038
  this._buffer = null;
2015
- this.freeBuffer = () => void (this._buffer = null);
2039
+ this.freeBuffer = () => {
2040
+ if (this.absPath != null) this._buffer = null;
2041
+ };
2016
2042
  this.updateBuffer = (buff) => {
2017
2043
  this._buffer = buff;
2018
2044
  this._metadata = null;
@@ -2028,32 +2054,34 @@ var MediaImage = class MediaImage {
2028
2054
  this._hash = null;
2029
2055
  this.processWithSharp_inplace = async (fn) => {
2030
2056
  const buff = await fn((await importSharp("processWithSharp_inplace"))(this.buffer)).toBuffer();
2031
- getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
2057
+ if (this.absPath != null) getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
2032
2058
  this.updateBuffer(new Uint8Array(buff));
2033
2059
  return this;
2034
2060
  };
2035
2061
  this.processWithSharp = async (fn, path) => {
2036
2062
  const sharp = await importSharp("processWithSharp");
2037
- path ??= this.absPath + `.processed-${Date.now()}` + this.extension;
2063
+ path ??= this.absPath != null ? asAbsolutePath(this.absPath + `.processed-${Date.now()}` + this.extension) : void 0;
2038
2064
  const buffer = new Uint8Array(await fn(sharp(this.buffer)).toBuffer());
2039
- getComfyStorage().writeBytes(path, buffer);
2065
+ if (path != null) getComfyStorage().writeBytes(path, buffer);
2040
2066
  return new MediaImage({
2041
2067
  path,
2042
2068
  buffer
2043
2069
  });
2044
2070
  };
2045
- this.absPath = data.path;
2071
+ this.absPath = data.path ?? null;
2046
2072
  this.execution = data.execution;
2047
2073
  this.promptNodeID = data.promptNodeID;
2074
+ if (data.path == null && data.buffer == null) throw new Error("❌ MediaImage: an in-memory image (no path) requires a buffer");
2048
2075
  if (data.buffer != null) this.updateBuffer(data.buffer);
2049
2076
  }
2050
2077
  /** the image as a Blob, e.g. to feed FormData uploads */
2051
2078
  getAsBlob() {
2052
2079
  return new Blob([this.buffer], { type: `image/${this.metadata.type ?? "png"}` });
2053
2080
  }
2054
- /** return the image filename */
2081
+ /** return the image filename (in-memory images get a stable hash-derived name) */
2055
2082
  get filename() {
2056
- return basename(this.absPath);
2083
+ if (this.absPath != null) return basename(this.absPath);
2084
+ return `image-${this.hash.slice(0, 8)}.${this.metadata.type ?? "png"}`;
2057
2085
  }
2058
2086
  get baseNameWithoutExtension() {
2059
2087
  const fname = this.filename;
@@ -2119,7 +2147,7 @@ var MediaImage = class MediaImage {
2119
2147
  }
2120
2148
  get buffer() {
2121
2149
  if (this._buffer != null) return this._buffer;
2122
- this._buffer = getComfyStorage().readBytes(this.absPath);
2150
+ this._buffer = getComfyStorage().readBytes(bang(this.absPath, "in-memory MediaImage lost its buffer"));
2123
2151
  return this._buffer;
2124
2152
  }
2125
2153
  get metadata() {
@@ -2145,7 +2173,9 @@ var ComfyExecution = class {
2145
2173
  constructor(workflow, data, init = {}) {
2146
2174
  this.workflow = workflow;
2147
2175
  this.data = data;
2148
- this.saveFormat = null;
2176
+ this.save = null;
2177
+ this.scrubHistory = false;
2178
+ this.ephemeral = false;
2149
2179
  this.snapshot = null;
2150
2180
  this.onProgress = null;
2151
2181
  this.logProgress = false;
@@ -2156,6 +2186,13 @@ var ComfyExecution = class {
2156
2186
  });
2157
2187
  this.onPromptRelatedMessage = (msg) => {
2158
2188
  const graph = this.workflow;
2189
+ if (msg.type === "binary_preview_frame") {
2190
+ if (this.wsOutputNodeExecuting) this.onWsImageOutput({
2191
+ bytes: msg.bytes,
2192
+ mime: msg.mime
2193
+ });
2194
+ return;
2195
+ }
2159
2196
  if (msg.type === "execution_start") return;
2160
2197
  else if (msg.type === "execution_cached") graph.onExecutionCached(msg);
2161
2198
  else if (msg.type === "executing") this.onExecuting(msg);
@@ -2199,72 +2236,104 @@ var ComfyExecution = class {
2199
2236
  this.imageErrors = [];
2200
2237
  this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
2201
2238
  const promptNode = this.workflow.data.apiJson?.[promptNodeID];
2202
- const promptMeta = this.workflow.data.metadata?.[promptNodeID];
2203
2239
  if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`);
2204
2240
  const imgRoute = "/view?" + new URLSearchParams(comfyImageInfo).toString();
2205
- const sf = this.saveFormat;
2241
+ const response = await this.host.fetchFile(imgRoute);
2242
+ const bytes = new Uint8Array(await response.arrayBuffer());
2243
+ const comfyUIInfos = {
2244
+ comfyImageInfo,
2245
+ comfyHostHttpURL: this.host.getServerHostHTTP()
2246
+ };
2247
+ const sf = this.save;
2248
+ if (sf == null) return this.pushImage(new MediaImage({
2249
+ buffer: bytes,
2250
+ execution: this,
2251
+ promptNodeID,
2252
+ comfyUIInfos
2253
+ }), promptNodeID);
2206
2254
  const promptPrefix = promptNode.inputs["filename_prefix"];
2207
- let absPath = comfyts.resolveFromOutput(localOutputPath({
2208
- localDir: sf?.prefix,
2255
+ const written = await this.encodeAndWrite({
2256
+ bytes,
2257
+ sf,
2209
2258
  filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
2210
2259
  subfolder: comfyImageInfo.subfolder,
2211
- filename: comfyImageInfo.filename,
2212
- timestamp: runTimestamp(new Date(this.startedAt))
2213
- }));
2214
- if (sf?.format && sf.format !== "raw") {
2215
- const extension = sf.format.split("/")[1];
2216
- absPath += "." + extension;
2217
- }
2218
- const storage = getComfyStorage();
2219
- absPath = uniquifyOutputPath({
2220
- path: absPath,
2221
- exists: (p) => storage.exists(p),
2222
- claimed: CLAIMED_OUTPUT_PATHS
2260
+ filename: comfyImageInfo.filename
2223
2261
  });
2224
- let img;
2225
- if (sf && sf.format !== "raw") {
2226
- const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
2262
+ this.pushImage(new MediaImage({
2263
+ path: written.path,
2264
+ buffer: written.bytes,
2265
+ execution: this,
2266
+ promptNodeID,
2267
+ comfyUIInfos
2268
+ }), promptNodeID);
2269
+ };
2270
+ this.encodeAndWrite = async (p) => {
2271
+ let bytes = p.bytes;
2272
+ const reencode = p.sf.format != null && p.sf.format !== "raw";
2273
+ if (reencode) {
2227
2274
  let textChunk = {};
2228
2275
  try {
2229
- const res = getPngMetadataFromUint8Array(new Uint8Array(buff));
2276
+ const res = getPngMetadataFromUint8Array(p.bytes);
2230
2277
  if (res.success) textChunk = res.value;
2231
2278
  } catch {}
2232
2279
  const format = (() => {
2233
- if (sf.format === "image/jpeg") return "jpeg";
2234
- if (sf.format === "image/png") return "png";
2235
- if (sf.format === "image/webp") return "webp";
2280
+ if (p.sf.format === "image/jpeg") return "jpeg";
2281
+ if (p.sf.format === "image/webp") return "webp";
2236
2282
  return "png";
2237
2283
  })();
2238
- 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();
2239
- storage.writeBytes(asAbsolutePath(absPath), new Uint8Array(encoded));
2240
- img = new MediaImage({
2241
- path: asAbsolutePath(absPath),
2242
- buffer: new Uint8Array(encoded),
2243
- execution: this,
2244
- promptNodeID,
2245
- comfyUIInfos: {
2246
- comfyImageInfo,
2247
- comfyHostHttpURL: this.host.getServerHostHTTP()
2248
- }
2249
- });
2250
- } else {
2251
- const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
2252
- const uint8arr = new Uint8Array(buff);
2253
- storage.writeBytes(asAbsolutePath(absPath), uint8arr);
2254
- img = new MediaImage({
2255
- path: asAbsolutePath(absPath),
2256
- buffer: uint8arr,
2257
- execution: this,
2258
- promptNodeID,
2259
- comfyUIInfos: {
2260
- comfyImageInfo,
2261
- comfyHostHttpURL: this.host.getServerHostHTTP()
2262
- }
2263
- });
2284
+ 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();
2285
+ bytes = new Uint8Array(encoded);
2264
2286
  }
2265
- if (promptMeta?.tag) img.tags.push(promptMeta.tag);
2266
- if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
2267
- this.images.push(img);
2287
+ let absPath = comfyts.resolveFromOutput(localOutputPath({
2288
+ localDir: p.sf.prefix,
2289
+ filenamePrefix: p.filenamePrefix,
2290
+ subfolder: p.subfolder,
2291
+ filename: p.filename,
2292
+ timestamp: runTimestamp(new Date(this.startedAt))
2293
+ }));
2294
+ if (reencode) absPath += "." + bang(p.sf.format).split("/")[1];
2295
+ const storage = getComfyStorage();
2296
+ absPath = uniquifyOutputPath({
2297
+ path: absPath,
2298
+ exists: (x) => storage.exists(x),
2299
+ claimed: CLAIMED_OUTPUT_PATHS
2300
+ });
2301
+ storage.writeBytes(asAbsolutePath(absPath), bytes);
2302
+ return {
2303
+ path: asAbsolutePath(absPath),
2304
+ bytes
2305
+ };
2306
+ };
2307
+ this.onWsImageOutput = (p) => {
2308
+ const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null;
2309
+ this.pendingPromises.push(this.storeWsImage(p, promptNodeID).catch((e) => {
2310
+ console.error(`🔴 failed to store a SaveImageWebsocket output:`, e);
2311
+ this.imageErrors.push({
2312
+ image: null,
2313
+ error: e
2314
+ });
2315
+ }));
2316
+ };
2317
+ this.storeWsImage = async (p, promptNodeID) => {
2318
+ const sf = this.save;
2319
+ if (sf == null) return this.pushImage(new MediaImage({
2320
+ buffer: p.bytes,
2321
+ execution: this,
2322
+ promptNodeID
2323
+ }), promptNodeID);
2324
+ const ext = p.mime === "image/jpeg" ? "jpg" : p.mime.split("/")[1] ?? "png";
2325
+ const written = await this.encodeAndWrite({
2326
+ bytes: p.bytes,
2327
+ sf,
2328
+ subfolder: "",
2329
+ filename: `${this.workflow.id}.${ext}`
2330
+ });
2331
+ this.pushImage(new MediaImage({
2332
+ path: written.path,
2333
+ buffer: written.bytes,
2334
+ execution: this,
2335
+ promptNodeID
2336
+ }), promptNodeID);
2268
2337
  };
2269
2338
  this.images = [];
2270
2339
  this.alreadyDone = false;
@@ -2278,11 +2347,20 @@ var ComfyExecution = class {
2278
2347
  await Promise.all(this.pendingPromises);
2279
2348
  this.host.executions.delete(this.data.id);
2280
2349
  this.host._pendingMsgs.delete(this.data.id);
2350
+ if (this.ephemeral) {
2351
+ const classTypes = Object.values(this.snapshot?.apiJson ?? {}).map((n) => n.class_type);
2352
+ 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.`);
2353
+ }
2354
+ if (this.scrubHistory) await this.host.deleteHistory(this.data.id).catch((e) => {
2355
+ console.error(`🔴 failed to scrub history entry ${this.data.id} on host ${this.host.data.id}:`, e);
2356
+ });
2281
2357
  this.finishProgressLine();
2282
2358
  this._resolve(this);
2283
2359
  };
2284
2360
  this.snapshot = init.snapshot ?? null;
2285
- this.saveFormat = init.saveFormat ?? null;
2361
+ this.save = init.save === true ? {} : init.save === false ? null : init.save ?? null;
2362
+ this.scrubHistory = init.scrubHistory ?? false;
2363
+ this.ephemeral = init.ephemeral ?? false;
2286
2364
  this.onProgress = init.onProgress ?? null;
2287
2365
  this.logProgress = init.logProgress ?? false;
2288
2366
  this.host.executions.set(data.id, this);
@@ -2340,11 +2418,47 @@ var ComfyExecution = class {
2340
2418
  get status() {
2341
2419
  return this.data.status ?? "New";
2342
2420
  }
2421
+ /** accumulate an output on the prompt; tags from node metadata ride along */
2422
+ pushImage(img, promptNodeID) {
2423
+ const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null;
2424
+ if (promptMeta?.tag) img.tags.push(promptMeta.tag);
2425
+ if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
2426
+ this.images.push(img);
2427
+ }
2428
+ /** true while the currently executing node is a SaveImageWebsocket in the
2429
+ * SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
2430
+ * live graph may still say SaveImage) — binary frames are then OUTPUTS */
2431
+ get wsOutputNodeExecuting() {
2432
+ const uid = this.workflow.currentExecutingNode?.uid;
2433
+ if (uid == null) return false;
2434
+ return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
2435
+ }
2343
2436
  update(data) {
2344
2437
  Object.assign(this.data, data);
2345
2438
  }
2346
2439
  };
2347
2440
  //#endregion
2441
+ //#region src/runner/ephemeral.ts
2442
+ /**
2443
+ * the `ephemeral: true` rewrite (architecture.md item 14): every SaveImage
2444
+ * node in the SENT snapshot becomes a SaveImageWebsocket (core node, `images`
2445
+ * input only), so outputs stream over the ws and never touch the server disk.
2446
+ * Mutates the given apiJson IN PLACE — callers pass the run's deep-copied
2447
+ * snapshot, never the live graph. Returns how many nodes were rewritten so
2448
+ * callers can warn when a graph had nothing to rewrite.
2449
+ */
2450
+ function rewriteSaveNodesToWebsocket(apiJson) {
2451
+ let rewritten = 0;
2452
+ for (const node of Object.values(apiJson)) {
2453
+ if (node.class_type !== "SaveImage") continue;
2454
+ const images = node.inputs["images"];
2455
+ node.class_type = "SaveImageWebsocket";
2456
+ node.inputs = images == null ? {} : { images };
2457
+ rewritten++;
2458
+ }
2459
+ return rewritten;
2460
+ }
2461
+ //#endregion
2348
2462
  //#region src/utils/deepCopyNaive.ts
2349
2463
  const deepCopyNaive = (x) => JSON.parse(JSON.stringify(x));
2350
2464
  //#endregion
@@ -2611,6 +2725,11 @@ var ComfyWorkflow = class {
2611
2725
  apiJson: deepCopyNaive(this.toApiJson(p.idMode ?? "use_stringified_numbers_only")),
2612
2726
  workflowJson: await this.toWorkflowJson()
2613
2727
  };
2728
+ if (p.ephemeral) {
2729
+ const rewritten = rewriteSaveNodesToWebsocket(snapshot.apiJson);
2730
+ const hasWsSaver = Object.values(snapshot.apiJson).some((n) => n.class_type === "SaveImageWebsocket");
2731
+ if (rewritten === 0 && !hasWsSaver) console.warn(`🟡 ephemeral run: no SaveImage/SaveImageWebsocket node in workflow '${this.id}' — nothing streams back`);
2732
+ }
2614
2733
  const out = {
2615
2734
  client_id: this.host.comfySessionId,
2616
2735
  prompt: snapshot.apiJson,
@@ -2633,7 +2752,9 @@ var ComfyWorkflow = class {
2633
2752
  graphID: this.id
2634
2753
  }, {
2635
2754
  snapshot,
2636
- saveFormat: p.saveFormat,
2755
+ save: p.save,
2756
+ ephemeral: p.ephemeral ?? false,
2757
+ scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
2637
2758
  onProgress: p.onProgress,
2638
2759
  logProgress: p.log ?? false
2639
2760
  });
@@ -2727,6 +2848,7 @@ function getUnionNameBasedOnFirstFoundEnumName(enumName, hash, hashContent) {
2727
2848
  function pythonModuleToPrefix(pythonModule) {
2728
2849
  if (pythonModule === "nodes") return "";
2729
2850
  if (pythonModule.startsWith("comfy_extras.")) return "";
2851
+ if (pythonModule === "custom_nodes.websocket_image_save") return "";
2730
2852
  if (pythonModule.startsWith("comfy_api_nodes.")) return pythonModule.replace("comfy_api_nodes.", "api.");
2731
2853
  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, "") + ".";
2732
2854
  console.warn(`[comfy-ts] unexpected pythonModule "${pythonModule}", using it as prefix as-is`);
@@ -4408,7 +4530,9 @@ var DefinedWorkflow = class {
4408
4530
  advance: true,
4409
4531
  host
4410
4532
  })).run({
4411
- saveFormat: settings.saveFormat,
4533
+ save: settings.save,
4534
+ ephemeral: settings.ephemeral,
4535
+ scrubHistory: settings.scrubHistory,
4412
4536
  idMode: settings.idMode,
4413
4537
  log: settings.log,
4414
4538
  onProgress: settings.onProgress
@@ -4596,6 +4720,12 @@ var ComfyHost = class {
4596
4720
  this.interrupt = () => {
4597
4721
  return this.postJSON_("/interrupt", {});
4598
4722
  };
4723
+ this.deleteHistory = (promptId) => {
4724
+ return this.postJSON_("/history", { delete: [promptId] });
4725
+ };
4726
+ this.clearHistory = () => {
4727
+ return this.postJSON_("/history", { clear: true });
4728
+ };
4599
4729
  this.fetchRawLogs = async () => {
4600
4730
  const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
4601
4731
  if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
@@ -4831,6 +4961,22 @@ var ComfyHost = class {
4831
4961
  if (e.data instanceof ArrayBuffer) {
4832
4962
  const frame = parseBinaryWsFrame(e.data);
4833
4963
  if (frame.kind === "preview") {
4964
+ const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null;
4965
+ if (activeExec?.wsOutputNodeExecuting) {
4966
+ activeExec.onWsImageOutput({
4967
+ bytes: frame.bytes,
4968
+ mime: frame.mime
4969
+ });
4970
+ return;
4971
+ }
4972
+ if (this.activePromptID != null) {
4973
+ const pending = this._pendingMsgs.get(this.activePromptID);
4974
+ if (pending != null) pending.push({
4975
+ type: "binary_preview_frame",
4976
+ bytes: frame.bytes,
4977
+ mime: frame.mime
4978
+ });
4979
+ }
4834
4980
  const imageBlob = new Blob([frame.bytes], { type: frame.mime });
4835
4981
  this.latentPreview = {
4836
4982
  blob: imageBlob,