comfy-ts 1.4.0 → 2.1.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.
- package/README.md +80 -6
- package/dist/{DefinedWorkflow-C_QAxKr3.js → DefinedWorkflow-CqNE_kgR.js} +4 -2
- package/dist/{DefinedWorkflow-C_QAxKr3.js.map → DefinedWorkflow-CqNE_kgR.js.map} +1 -1
- package/dist/{DraftsSt-DcOTn0QR.js → DraftsSt-C-gBk9v7.js} +3 -4
- package/dist/DraftsSt-C-gBk9v7.js.map +1 -0
- package/dist/cli.js +3 -3
- package/dist/index.cjs +212 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -77
- package/dist/index.d.ts +72 -77
- package/dist/index.js +212 -66
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-CN0DhrsA.js → run-serve-CnlN_RFH.js} +9 -7
- package/dist/run-serve-CnlN_RFH.js.map +1 -0
- package/dist/{run-tui-bN2hSD5i.js → run-tui-DXI_Jufu.js} +258 -56
- package/dist/run-tui-DXI_Jufu.js.map +1 -0
- package/dist/{state-COlKYipO.js → state-DC5BcG6d.js} +211 -67
- package/dist/state-DC5BcG6d.js.map +1 -0
- package/dist/web.d.ts +72 -77
- package/dist/web.js +212 -66
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/firered-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/lens-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sdk.d.ts +13251 -11458
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +2 -5
- package/examples/rvion/01-txt2img.cflow.ts +5 -3
- package/examples/rvion/02-img2img-upload.cflow.ts +5 -4
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +6 -7
- package/examples/rvion/05-comfy-cloud.cflow.ts +4 -2
- package/examples/rvion/06-qwen-image-edit.cflow.ts +2 -3
- package/examples/web/example.ts +8 -1
- package/package.json +1 -1
- package/src/cli/serve/ServeApp.ts +9 -6
- package/src/cli/tui/components/TuiApp.tsx +4 -5
- package/src/cli/tui/components/VarsPanel.tsx +40 -2
- package/src/cli/tui/imageClipboard.ts +40 -0
- package/src/cli/tui/state/DraftsSt.ts +1 -2
- package/src/cli/tui/state/ExecSt.ts +105 -40
- package/src/cli/tui/state/PreviewSt.ts +12 -11
- package/src/cli/tui/state/SettingsSt.ts +13 -0
- package/src/cli/tui/state/TuiSt.ts +54 -5
- package/src/host/ComfyHost.ts +33 -1
- package/src/runner/ComfyExecution.ts +162 -74
- package/src/runner/ComfyWorkflow.ts +25 -3
- package/src/runner/ComfyWsApi.ts +6 -0
- package/src/runner/MediaImage.ts +58 -11
- package/src/runner/ephemeral.ts +21 -0
- package/src/runner/outputPath.ts +2 -2
- package/src/sdk-generator/_pythonModuleToNamespace.ts +3 -0
- package/src/types/index.ts +6 -2
- package/src/vars/DefinedWorkflow.ts +3 -1
- package/dist/DraftsSt-DcOTn0QR.js.map +0 -1
- package/dist/run-serve-CN0DhrsA.js.map +0 -1
- package/dist/run-tui-bN2hSD5i.js.map +0 -1
- package/dist/state-COlKYipO.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 = "1.
|
|
113
|
+
var version = "2.1.0";
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
116
116
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -1662,7 +1662,7 @@ var LiteGraphCtx = class {
|
|
|
1662
1662
|
* `_00001_` counter every run, so trusting it overwrote the same file — and
|
|
1663
1663
|
* a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
|
|
1664
1664
|
* prefix. Local names are ours: dir from the prompt's own filename_prefix
|
|
1665
|
-
* (or an explicit
|
|
1665
|
+
* (or an explicit save.prefix override), then
|
|
1666
1666
|
* `<stem>_<timestamp>_<counter><ext>` so every run sorts chronologically
|
|
1667
1667
|
* per stem and nothing ever collides.
|
|
1668
1668
|
*/
|
|
@@ -1992,6 +1992,21 @@ const PromptInfo_ark = type({ prompt_id: types$1.PromptID }).as();
|
|
|
1992
1992
|
const WsMsg_ark = types$1.WsMsg;
|
|
1993
1993
|
const ComfyImageInfo_ark = types$1.ComfyImageInfo;
|
|
1994
1994
|
const WsMsgLogsData_ark = types$1._WsMsgLogsData;
|
|
1995
|
+
//#endregion
|
|
1996
|
+
//#region src/runner/MediaImage.ts
|
|
1997
|
+
/** base64 image loader nodes we know how to wire, in preference order — each
|
|
1998
|
+
* verified against a real object_info dump before entering the table */
|
|
1999
|
+
const BASE64_IMAGE_LOADERS = [{
|
|
2000
|
+
nameInComfy: "ETN_LoadImageBase64",
|
|
2001
|
+
inputs: (b64) => ({ image: b64 })
|
|
2002
|
+
}, {
|
|
2003
|
+
nameInComfy: "easy loadImageBase64",
|
|
2004
|
+
inputs: (b64) => ({
|
|
2005
|
+
base64_data: b64,
|
|
2006
|
+
image_output: "Hide",
|
|
2007
|
+
save_prefix: ""
|
|
2008
|
+
})
|
|
2009
|
+
}];
|
|
1995
2010
|
type({
|
|
1996
2011
|
comfyHostHttpURL: "string",
|
|
1997
2012
|
comfyImageInfo: ComfyImageInfo_ark
|
|
@@ -2020,8 +2035,19 @@ var MediaImage = class MediaImage {
|
|
|
2020
2035
|
channel
|
|
2021
2036
|
});
|
|
2022
2037
|
};
|
|
2038
|
+
this.loadInWorkflow_viaBase64Node = (workflow) => {
|
|
2039
|
+
const schema = workflow.host.schema;
|
|
2040
|
+
const entry = BASE64_IMAGE_LOADERS.find((t) => schema.nodes.some((n) => n.nameInComfy === t.nameInComfy));
|
|
2041
|
+
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).`);
|
|
2042
|
+
return new ComfyNode(workflow, (workflow._uidNumber++).toString(), {
|
|
2043
|
+
class_type: entry.nameInComfy,
|
|
2044
|
+
inputs: entry.inputs(this.getBase64Payload())
|
|
2045
|
+
}, {});
|
|
2046
|
+
};
|
|
2023
2047
|
this._buffer = null;
|
|
2024
|
-
this.freeBuffer = () =>
|
|
2048
|
+
this.freeBuffer = () => {
|
|
2049
|
+
if (this.absPath != null) this._buffer = null;
|
|
2050
|
+
};
|
|
2025
2051
|
this.updateBuffer = (buff) => {
|
|
2026
2052
|
this._buffer = buff;
|
|
2027
2053
|
this._metadata = null;
|
|
@@ -2037,32 +2063,34 @@ var MediaImage = class MediaImage {
|
|
|
2037
2063
|
this._hash = null;
|
|
2038
2064
|
this.processWithSharp_inplace = async (fn) => {
|
|
2039
2065
|
const buff = await fn((await importSharp("processWithSharp_inplace"))(this.buffer)).toBuffer();
|
|
2040
|
-
getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
|
|
2066
|
+
if (this.absPath != null) getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
|
|
2041
2067
|
this.updateBuffer(new Uint8Array(buff));
|
|
2042
2068
|
return this;
|
|
2043
2069
|
};
|
|
2044
2070
|
this.processWithSharp = async (fn, path) => {
|
|
2045
2071
|
const sharp = await importSharp("processWithSharp");
|
|
2046
|
-
path ??= this.absPath + `.processed-${Date.now()}` + this.extension;
|
|
2072
|
+
path ??= this.absPath != null ? asAbsolutePath(this.absPath + `.processed-${Date.now()}` + this.extension) : void 0;
|
|
2047
2073
|
const buffer = new Uint8Array(await fn(sharp(this.buffer)).toBuffer());
|
|
2048
|
-
getComfyStorage().writeBytes(path, buffer);
|
|
2074
|
+
if (path != null) getComfyStorage().writeBytes(path, buffer);
|
|
2049
2075
|
return new MediaImage({
|
|
2050
2076
|
path,
|
|
2051
2077
|
buffer
|
|
2052
2078
|
});
|
|
2053
2079
|
};
|
|
2054
|
-
this.absPath = data.path;
|
|
2080
|
+
this.absPath = data.path ?? null;
|
|
2055
2081
|
this.execution = data.execution;
|
|
2056
2082
|
this.promptNodeID = data.promptNodeID;
|
|
2083
|
+
if (data.path == null && data.buffer == null) throw new Error("❌ MediaImage: an in-memory image (no path) requires a buffer");
|
|
2057
2084
|
if (data.buffer != null) this.updateBuffer(data.buffer);
|
|
2058
2085
|
}
|
|
2059
2086
|
/** the image as a Blob, e.g. to feed FormData uploads */
|
|
2060
2087
|
getAsBlob() {
|
|
2061
2088
|
return new Blob([this.buffer], { type: `image/${this.metadata.type ?? "png"}` });
|
|
2062
2089
|
}
|
|
2063
|
-
/** return the image filename */
|
|
2090
|
+
/** return the image filename (in-memory images get a stable hash-derived name) */
|
|
2064
2091
|
get filename() {
|
|
2065
|
-
return basename(this.absPath);
|
|
2092
|
+
if (this.absPath != null) return basename(this.absPath);
|
|
2093
|
+
return `image-${this.hash.slice(0, 8)}.${this.metadata.type ?? "png"}`;
|
|
2066
2094
|
}
|
|
2067
2095
|
get baseNameWithoutExtension() {
|
|
2068
2096
|
const fname = this.filename;
|
|
@@ -2128,7 +2156,7 @@ var MediaImage = class MediaImage {
|
|
|
2128
2156
|
}
|
|
2129
2157
|
get buffer() {
|
|
2130
2158
|
if (this._buffer != null) return this._buffer;
|
|
2131
|
-
this._buffer = getComfyStorage().readBytes(this.absPath);
|
|
2159
|
+
this._buffer = getComfyStorage().readBytes(bang(this.absPath, "in-memory MediaImage lost its buffer"));
|
|
2132
2160
|
return this._buffer;
|
|
2133
2161
|
}
|
|
2134
2162
|
get metadata() {
|
|
@@ -2154,7 +2182,9 @@ var ComfyExecution = class {
|
|
|
2154
2182
|
constructor(workflow, data, init = {}) {
|
|
2155
2183
|
this.workflow = workflow;
|
|
2156
2184
|
this.data = data;
|
|
2157
|
-
this.
|
|
2185
|
+
this.save = null;
|
|
2186
|
+
this.scrubHistory = false;
|
|
2187
|
+
this.ephemeral = false;
|
|
2158
2188
|
this.snapshot = null;
|
|
2159
2189
|
this.onProgress = null;
|
|
2160
2190
|
this.logProgress = false;
|
|
@@ -2165,6 +2195,13 @@ var ComfyExecution = class {
|
|
|
2165
2195
|
});
|
|
2166
2196
|
this.onPromptRelatedMessage = (msg) => {
|
|
2167
2197
|
const graph = this.workflow;
|
|
2198
|
+
if (msg.type === "binary_preview_frame") {
|
|
2199
|
+
if (this.wsOutputNodeExecuting) this.onWsImageOutput({
|
|
2200
|
+
bytes: msg.bytes,
|
|
2201
|
+
mime: msg.mime
|
|
2202
|
+
});
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2168
2205
|
if (msg.type === "execution_start") return;
|
|
2169
2206
|
else if (msg.type === "execution_cached") graph.onExecutionCached(msg);
|
|
2170
2207
|
else if (msg.type === "executing") this.onExecuting(msg);
|
|
@@ -2208,72 +2245,104 @@ var ComfyExecution = class {
|
|
|
2208
2245
|
this.imageErrors = [];
|
|
2209
2246
|
this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
|
|
2210
2247
|
const promptNode = this.workflow.data.apiJson?.[promptNodeID];
|
|
2211
|
-
const promptMeta = this.workflow.data.metadata?.[promptNodeID];
|
|
2212
2248
|
if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`);
|
|
2213
2249
|
const imgRoute = "/view?" + new URLSearchParams(comfyImageInfo).toString();
|
|
2214
|
-
const
|
|
2250
|
+
const response = await this.host.fetchFile(imgRoute);
|
|
2251
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2252
|
+
const comfyUIInfos = {
|
|
2253
|
+
comfyImageInfo,
|
|
2254
|
+
comfyHostHttpURL: this.host.getServerHostHTTP()
|
|
2255
|
+
};
|
|
2256
|
+
const sf = this.save;
|
|
2257
|
+
if (sf == null) return this.pushImage(new MediaImage({
|
|
2258
|
+
buffer: bytes,
|
|
2259
|
+
execution: this,
|
|
2260
|
+
promptNodeID,
|
|
2261
|
+
comfyUIInfos
|
|
2262
|
+
}), promptNodeID);
|
|
2215
2263
|
const promptPrefix = promptNode.inputs["filename_prefix"];
|
|
2216
|
-
|
|
2217
|
-
|
|
2264
|
+
const written = await this.encodeAndWrite({
|
|
2265
|
+
bytes,
|
|
2266
|
+
sf,
|
|
2218
2267
|
filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
|
|
2219
2268
|
subfolder: comfyImageInfo.subfolder,
|
|
2220
|
-
filename: comfyImageInfo.filename
|
|
2221
|
-
timestamp: runTimestamp(new Date(this.startedAt))
|
|
2222
|
-
}));
|
|
2223
|
-
if (sf?.format && sf.format !== "raw") {
|
|
2224
|
-
const extension = sf.format.split("/")[1];
|
|
2225
|
-
absPath += "." + extension;
|
|
2226
|
-
}
|
|
2227
|
-
const storage = getComfyStorage();
|
|
2228
|
-
absPath = uniquifyOutputPath({
|
|
2229
|
-
path: absPath,
|
|
2230
|
-
exists: (p) => storage.exists(p),
|
|
2231
|
-
claimed: CLAIMED_OUTPUT_PATHS
|
|
2269
|
+
filename: comfyImageInfo.filename
|
|
2232
2270
|
});
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2271
|
+
this.pushImage(new MediaImage({
|
|
2272
|
+
path: written.path,
|
|
2273
|
+
buffer: written.bytes,
|
|
2274
|
+
execution: this,
|
|
2275
|
+
promptNodeID,
|
|
2276
|
+
comfyUIInfos
|
|
2277
|
+
}), promptNodeID);
|
|
2278
|
+
};
|
|
2279
|
+
this.encodeAndWrite = async (p) => {
|
|
2280
|
+
let bytes = p.bytes;
|
|
2281
|
+
const reencode = p.sf.format != null && p.sf.format !== "raw";
|
|
2282
|
+
if (reencode) {
|
|
2236
2283
|
let textChunk = {};
|
|
2237
2284
|
try {
|
|
2238
|
-
const res = getPngMetadataFromUint8Array(
|
|
2285
|
+
const res = getPngMetadataFromUint8Array(p.bytes);
|
|
2239
2286
|
if (res.success) textChunk = res.value;
|
|
2240
2287
|
} catch {}
|
|
2241
2288
|
const format = (() => {
|
|
2242
|
-
if (sf.format === "image/jpeg") return "jpeg";
|
|
2243
|
-
if (sf.format === "image/
|
|
2244
|
-
if (sf.format === "image/webp") return "webp";
|
|
2289
|
+
if (p.sf.format === "image/jpeg") return "jpeg";
|
|
2290
|
+
if (p.sf.format === "image/webp") return "webp";
|
|
2245
2291
|
return "png";
|
|
2246
2292
|
})();
|
|
2247
|
-
const encoded = await (await importSharp(`
|
|
2248
|
-
|
|
2249
|
-
img = new MediaImage({
|
|
2250
|
-
path: asAbsolutePath(absPath),
|
|
2251
|
-
buffer: new Uint8Array(encoded),
|
|
2252
|
-
execution: this,
|
|
2253
|
-
promptNodeID,
|
|
2254
|
-
comfyUIInfos: {
|
|
2255
|
-
comfyImageInfo,
|
|
2256
|
-
comfyHostHttpURL: this.host.getServerHostHTTP()
|
|
2257
|
-
}
|
|
2258
|
-
});
|
|
2259
|
-
} else {
|
|
2260
|
-
const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
|
|
2261
|
-
const uint8arr = new Uint8Array(buff);
|
|
2262
|
-
storage.writeBytes(asAbsolutePath(absPath), uint8arr);
|
|
2263
|
-
img = new MediaImage({
|
|
2264
|
-
path: asAbsolutePath(absPath),
|
|
2265
|
-
buffer: uint8arr,
|
|
2266
|
-
execution: this,
|
|
2267
|
-
promptNodeID,
|
|
2268
|
-
comfyUIInfos: {
|
|
2269
|
-
comfyImageInfo,
|
|
2270
|
-
comfyHostHttpURL: this.host.getServerHostHTTP()
|
|
2271
|
-
}
|
|
2272
|
-
});
|
|
2293
|
+
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();
|
|
2294
|
+
bytes = new Uint8Array(encoded);
|
|
2273
2295
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2296
|
+
let absPath = comfyts.resolveFromOutput(localOutputPath({
|
|
2297
|
+
localDir: p.sf.prefix,
|
|
2298
|
+
filenamePrefix: p.filenamePrefix,
|
|
2299
|
+
subfolder: p.subfolder,
|
|
2300
|
+
filename: p.filename,
|
|
2301
|
+
timestamp: runTimestamp(new Date(this.startedAt))
|
|
2302
|
+
}));
|
|
2303
|
+
if (reencode) absPath += "." + bang(p.sf.format).split("/")[1];
|
|
2304
|
+
const storage = getComfyStorage();
|
|
2305
|
+
absPath = uniquifyOutputPath({
|
|
2306
|
+
path: absPath,
|
|
2307
|
+
exists: (x) => storage.exists(x),
|
|
2308
|
+
claimed: CLAIMED_OUTPUT_PATHS
|
|
2309
|
+
});
|
|
2310
|
+
storage.writeBytes(asAbsolutePath(absPath), bytes);
|
|
2311
|
+
return {
|
|
2312
|
+
path: asAbsolutePath(absPath),
|
|
2313
|
+
bytes
|
|
2314
|
+
};
|
|
2315
|
+
};
|
|
2316
|
+
this.onWsImageOutput = (p) => {
|
|
2317
|
+
const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null;
|
|
2318
|
+
this.pendingPromises.push(this.storeWsImage(p, promptNodeID).catch((e) => {
|
|
2319
|
+
console.error(`🔴 failed to store a SaveImageWebsocket output:`, e);
|
|
2320
|
+
this.imageErrors.push({
|
|
2321
|
+
image: null,
|
|
2322
|
+
error: e
|
|
2323
|
+
});
|
|
2324
|
+
}));
|
|
2325
|
+
};
|
|
2326
|
+
this.storeWsImage = async (p, promptNodeID) => {
|
|
2327
|
+
const sf = this.save;
|
|
2328
|
+
if (sf == null) return this.pushImage(new MediaImage({
|
|
2329
|
+
buffer: p.bytes,
|
|
2330
|
+
execution: this,
|
|
2331
|
+
promptNodeID
|
|
2332
|
+
}), promptNodeID);
|
|
2333
|
+
const ext = p.mime === "image/jpeg" ? "jpg" : p.mime.split("/")[1] ?? "png";
|
|
2334
|
+
const written = await this.encodeAndWrite({
|
|
2335
|
+
bytes: p.bytes,
|
|
2336
|
+
sf,
|
|
2337
|
+
subfolder: "",
|
|
2338
|
+
filename: `${this.workflow.id}.${ext}`
|
|
2339
|
+
});
|
|
2340
|
+
this.pushImage(new MediaImage({
|
|
2341
|
+
path: written.path,
|
|
2342
|
+
buffer: written.bytes,
|
|
2343
|
+
execution: this,
|
|
2344
|
+
promptNodeID
|
|
2345
|
+
}), promptNodeID);
|
|
2277
2346
|
};
|
|
2278
2347
|
this.images = [];
|
|
2279
2348
|
this.alreadyDone = false;
|
|
@@ -2287,11 +2356,20 @@ var ComfyExecution = class {
|
|
|
2287
2356
|
await Promise.all(this.pendingPromises);
|
|
2288
2357
|
this.host.executions.delete(this.data.id);
|
|
2289
2358
|
this.host._pendingMsgs.delete(this.data.id);
|
|
2359
|
+
if (this.ephemeral) {
|
|
2360
|
+
const classTypes = Object.values(this.snapshot?.apiJson ?? {}).map((n) => n.class_type);
|
|
2361
|
+
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.`);
|
|
2362
|
+
}
|
|
2363
|
+
if (this.scrubHistory) await this.host.deleteHistory(this.data.id).catch((e) => {
|
|
2364
|
+
console.error(`🔴 failed to scrub history entry ${this.data.id} on host ${this.host.data.id}:`, e);
|
|
2365
|
+
});
|
|
2290
2366
|
this.finishProgressLine();
|
|
2291
2367
|
this._resolve(this);
|
|
2292
2368
|
};
|
|
2293
2369
|
this.snapshot = init.snapshot ?? null;
|
|
2294
|
-
this.
|
|
2370
|
+
this.save = init.save === true ? {} : init.save === false ? null : init.save ?? null;
|
|
2371
|
+
this.scrubHistory = init.scrubHistory ?? false;
|
|
2372
|
+
this.ephemeral = init.ephemeral ?? false;
|
|
2295
2373
|
this.onProgress = init.onProgress ?? null;
|
|
2296
2374
|
this.logProgress = init.logProgress ?? false;
|
|
2297
2375
|
this.host.executions.set(data.id, this);
|
|
@@ -2349,11 +2427,47 @@ var ComfyExecution = class {
|
|
|
2349
2427
|
get status() {
|
|
2350
2428
|
return this.data.status ?? "New";
|
|
2351
2429
|
}
|
|
2430
|
+
/** accumulate an output on the prompt; tags from node metadata ride along */
|
|
2431
|
+
pushImage(img, promptNodeID) {
|
|
2432
|
+
const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null;
|
|
2433
|
+
if (promptMeta?.tag) img.tags.push(promptMeta.tag);
|
|
2434
|
+
if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
|
|
2435
|
+
this.images.push(img);
|
|
2436
|
+
}
|
|
2437
|
+
/** true while the currently executing node is a SaveImageWebsocket in the
|
|
2438
|
+
* SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
|
|
2439
|
+
* live graph may still say SaveImage) — binary frames are then OUTPUTS */
|
|
2440
|
+
get wsOutputNodeExecuting() {
|
|
2441
|
+
const uid = this.workflow.currentExecutingNode?.uid;
|
|
2442
|
+
if (uid == null) return false;
|
|
2443
|
+
return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
|
|
2444
|
+
}
|
|
2352
2445
|
update(data) {
|
|
2353
2446
|
Object.assign(this.data, data);
|
|
2354
2447
|
}
|
|
2355
2448
|
};
|
|
2356
2449
|
//#endregion
|
|
2450
|
+
//#region src/runner/ephemeral.ts
|
|
2451
|
+
/**
|
|
2452
|
+
* the `ephemeral: true` rewrite (architecture.md item 14): every SaveImage
|
|
2453
|
+
* node in the SENT snapshot becomes a SaveImageWebsocket (core node, `images`
|
|
2454
|
+
* input only), so outputs stream over the ws and never touch the server disk.
|
|
2455
|
+
* Mutates the given apiJson IN PLACE — callers pass the run's deep-copied
|
|
2456
|
+
* snapshot, never the live graph. Returns how many nodes were rewritten so
|
|
2457
|
+
* callers can warn when a graph had nothing to rewrite.
|
|
2458
|
+
*/
|
|
2459
|
+
function rewriteSaveNodesToWebsocket(apiJson) {
|
|
2460
|
+
let rewritten = 0;
|
|
2461
|
+
for (const node of Object.values(apiJson)) {
|
|
2462
|
+
if (node.class_type !== "SaveImage") continue;
|
|
2463
|
+
const images = node.inputs["images"];
|
|
2464
|
+
node.class_type = "SaveImageWebsocket";
|
|
2465
|
+
node.inputs = images == null ? {} : { images };
|
|
2466
|
+
rewritten++;
|
|
2467
|
+
}
|
|
2468
|
+
return rewritten;
|
|
2469
|
+
}
|
|
2470
|
+
//#endregion
|
|
2357
2471
|
//#region src/utils/deepCopyNaive.ts
|
|
2358
2472
|
const deepCopyNaive = (x) => JSON.parse(JSON.stringify(x));
|
|
2359
2473
|
//#endregion
|
|
@@ -2620,6 +2734,11 @@ var ComfyWorkflow = class {
|
|
|
2620
2734
|
apiJson: deepCopyNaive(this.toApiJson(p.idMode ?? "use_stringified_numbers_only")),
|
|
2621
2735
|
workflowJson: await this.toWorkflowJson()
|
|
2622
2736
|
};
|
|
2737
|
+
if (p.ephemeral) {
|
|
2738
|
+
const rewritten = rewriteSaveNodesToWebsocket(snapshot.apiJson);
|
|
2739
|
+
const hasWsSaver = Object.values(snapshot.apiJson).some((n) => n.class_type === "SaveImageWebsocket");
|
|
2740
|
+
if (rewritten === 0 && !hasWsSaver) console.warn(`🟡 ephemeral run: no SaveImage/SaveImageWebsocket node in workflow '${this.id}' — nothing streams back`);
|
|
2741
|
+
}
|
|
2623
2742
|
const out = {
|
|
2624
2743
|
client_id: this.host.comfySessionId,
|
|
2625
2744
|
prompt: snapshot.apiJson,
|
|
@@ -2642,7 +2761,9 @@ var ComfyWorkflow = class {
|
|
|
2642
2761
|
graphID: this.id
|
|
2643
2762
|
}, {
|
|
2644
2763
|
snapshot,
|
|
2645
|
-
|
|
2764
|
+
save: p.save,
|
|
2765
|
+
ephemeral: p.ephemeral ?? false,
|
|
2766
|
+
scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
|
|
2646
2767
|
onProgress: p.onProgress,
|
|
2647
2768
|
logProgress: p.log ?? false
|
|
2648
2769
|
});
|
|
@@ -2736,6 +2857,7 @@ function getUnionNameBasedOnFirstFoundEnumName(enumName, hash, hashContent) {
|
|
|
2736
2857
|
function pythonModuleToPrefix(pythonModule) {
|
|
2737
2858
|
if (pythonModule === "nodes") return "";
|
|
2738
2859
|
if (pythonModule.startsWith("comfy_extras.")) return "";
|
|
2860
|
+
if (pythonModule === "custom_nodes.websocket_image_save") return "";
|
|
2739
2861
|
if (pythonModule.startsWith("comfy_api_nodes.")) return pythonModule.replace("comfy_api_nodes.", "api.");
|
|
2740
2862
|
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, "") + ".";
|
|
2741
2863
|
console.warn(`[comfy-ts] unexpected pythonModule "${pythonModule}", using it as prefix as-is`);
|
|
@@ -4417,7 +4539,9 @@ var DefinedWorkflow = class {
|
|
|
4417
4539
|
advance: true,
|
|
4418
4540
|
host
|
|
4419
4541
|
})).run({
|
|
4420
|
-
|
|
4542
|
+
save: settings.save,
|
|
4543
|
+
ephemeral: settings.ephemeral,
|
|
4544
|
+
scrubHistory: settings.scrubHistory,
|
|
4421
4545
|
idMode: settings.idMode,
|
|
4422
4546
|
log: settings.log,
|
|
4423
4547
|
onProgress: settings.onProgress
|
|
@@ -4605,6 +4729,12 @@ var ComfyHost = class {
|
|
|
4605
4729
|
this.interrupt = () => {
|
|
4606
4730
|
return this.postJSON_("/interrupt", {});
|
|
4607
4731
|
};
|
|
4732
|
+
this.deleteHistory = (promptId) => {
|
|
4733
|
+
return this.postJSON_("/history", { delete: [promptId] });
|
|
4734
|
+
};
|
|
4735
|
+
this.clearHistory = () => {
|
|
4736
|
+
return this.postJSON_("/history", { clear: true });
|
|
4737
|
+
};
|
|
4608
4738
|
this.fetchRawLogs = async () => {
|
|
4609
4739
|
const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
|
|
4610
4740
|
if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
|
|
@@ -4840,6 +4970,22 @@ var ComfyHost = class {
|
|
|
4840
4970
|
if (e.data instanceof ArrayBuffer) {
|
|
4841
4971
|
const frame = parseBinaryWsFrame(e.data);
|
|
4842
4972
|
if (frame.kind === "preview") {
|
|
4973
|
+
const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null;
|
|
4974
|
+
if (activeExec?.wsOutputNodeExecuting) {
|
|
4975
|
+
activeExec.onWsImageOutput({
|
|
4976
|
+
bytes: frame.bytes,
|
|
4977
|
+
mime: frame.mime
|
|
4978
|
+
});
|
|
4979
|
+
return;
|
|
4980
|
+
}
|
|
4981
|
+
if (this.activePromptID != null) {
|
|
4982
|
+
const pending = this._pendingMsgs.get(this.activePromptID);
|
|
4983
|
+
if (pending != null) pending.push({
|
|
4984
|
+
type: "binary_preview_frame",
|
|
4985
|
+
bytes: frame.bytes,
|
|
4986
|
+
mime: frame.mime
|
|
4987
|
+
});
|
|
4988
|
+
}
|
|
4843
4989
|
const imageBlob = new Blob([frame.bytes], { type: frame.mime });
|
|
4844
4990
|
this.latentPreview = {
|
|
4845
4991
|
blob: imageBlob,
|