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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as resolveComfyStorage, b as logInfo, g as getComfyStorage, h as extractErrorMessage, t as DefinedWorkflow, v as isQuiet, x as logSuccess, y as logError } from "./DefinedWorkflow-
|
|
1
|
+
import { _ as resolveComfyStorage, b as logInfo, g as getComfyStorage, h as extractErrorMessage, t as DefinedWorkflow, v as isQuiet, x as logSuccess, y as logError } from "./DefinedWorkflow-CqNE_kgR.js";
|
|
2
2
|
import { basename, join } from "pathe";
|
|
3
3
|
import { scope, type } from "arktype";
|
|
4
4
|
import { nanoid } from "nanoid";
|
|
@@ -102,6 +102,7 @@ function getUnionNameBasedOnFirstFoundEnumName(enumName, hash, hashContent) {
|
|
|
102
102
|
function pythonModuleToPrefix(pythonModule) {
|
|
103
103
|
if (pythonModule === "nodes") return "";
|
|
104
104
|
if (pythonModule.startsWith("comfy_extras.")) return "";
|
|
105
|
+
if (pythonModule === "custom_nodes.websocket_image_save") return "";
|
|
105
106
|
if (pythonModule.startsWith("comfy_api_nodes.")) return pythonModule.replace("comfy_api_nodes.", "api.");
|
|
106
107
|
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, "") + ".";
|
|
107
108
|
console.warn(`[comfy-ts] unexpected pythonModule "${pythonModule}", using it as prefix as-is`);
|
|
@@ -883,7 +884,7 @@ var ComfySchema = class {
|
|
|
883
884
|
};
|
|
884
885
|
//#endregion
|
|
885
886
|
//#region package.json
|
|
886
|
-
var version = "1.
|
|
887
|
+
var version = "2.1.0";
|
|
887
888
|
//#endregion
|
|
888
889
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
889
890
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -2202,7 +2203,7 @@ var LiteGraphCtx = class {
|
|
|
2202
2203
|
* `_00001_` counter every run, so trusting it overwrote the same file — and
|
|
2203
2204
|
* a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
|
|
2204
2205
|
* prefix. Local names are ours: dir from the prompt's own filename_prefix
|
|
2205
|
-
* (or an explicit
|
|
2206
|
+
* (or an explicit save.prefix override), then
|
|
2206
2207
|
* `<stem>_<timestamp>_<counter><ext>` so every run sorts chronologically
|
|
2207
2208
|
* per stem and nothing ever collides.
|
|
2208
2209
|
*/
|
|
@@ -2437,6 +2438,21 @@ const PromptInfo_ark = type({ prompt_id: types$1.PromptID }).as();
|
|
|
2437
2438
|
const WsMsg_ark = types$1.WsMsg;
|
|
2438
2439
|
const ComfyImageInfo_ark = types$1.ComfyImageInfo;
|
|
2439
2440
|
const WsMsgLogsData_ark = types$1._WsMsgLogsData;
|
|
2441
|
+
//#endregion
|
|
2442
|
+
//#region src/runner/MediaImage.ts
|
|
2443
|
+
/** base64 image loader nodes we know how to wire, in preference order — each
|
|
2444
|
+
* verified against a real object_info dump before entering the table */
|
|
2445
|
+
const BASE64_IMAGE_LOADERS = [{
|
|
2446
|
+
nameInComfy: "ETN_LoadImageBase64",
|
|
2447
|
+
inputs: (b64) => ({ image: b64 })
|
|
2448
|
+
}, {
|
|
2449
|
+
nameInComfy: "easy loadImageBase64",
|
|
2450
|
+
inputs: (b64) => ({
|
|
2451
|
+
base64_data: b64,
|
|
2452
|
+
image_output: "Hide",
|
|
2453
|
+
save_prefix: ""
|
|
2454
|
+
})
|
|
2455
|
+
}];
|
|
2440
2456
|
type({
|
|
2441
2457
|
comfyHostHttpURL: "string",
|
|
2442
2458
|
comfyImageInfo: ComfyImageInfo_ark
|
|
@@ -2465,8 +2481,19 @@ var MediaImage = class MediaImage {
|
|
|
2465
2481
|
channel
|
|
2466
2482
|
});
|
|
2467
2483
|
};
|
|
2484
|
+
this.loadInWorkflow_viaBase64Node = (workflow) => {
|
|
2485
|
+
const schema = workflow.host.schema;
|
|
2486
|
+
const entry = BASE64_IMAGE_LOADERS.find((t) => schema.nodes.some((n) => n.nameInComfy === t.nameInComfy));
|
|
2487
|
+
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).`);
|
|
2488
|
+
return new ComfyNode(workflow, (workflow._uidNumber++).toString(), {
|
|
2489
|
+
class_type: entry.nameInComfy,
|
|
2490
|
+
inputs: entry.inputs(this.getBase64Payload())
|
|
2491
|
+
}, {});
|
|
2492
|
+
};
|
|
2468
2493
|
this._buffer = null;
|
|
2469
|
-
this.freeBuffer = () =>
|
|
2494
|
+
this.freeBuffer = () => {
|
|
2495
|
+
if (this.absPath != null) this._buffer = null;
|
|
2496
|
+
};
|
|
2470
2497
|
this.updateBuffer = (buff) => {
|
|
2471
2498
|
this._buffer = buff;
|
|
2472
2499
|
this._metadata = null;
|
|
@@ -2482,32 +2509,34 @@ var MediaImage = class MediaImage {
|
|
|
2482
2509
|
this._hash = null;
|
|
2483
2510
|
this.processWithSharp_inplace = async (fn) => {
|
|
2484
2511
|
const buff = await fn((await importSharp("processWithSharp_inplace"))(this.buffer)).toBuffer();
|
|
2485
|
-
getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
|
|
2512
|
+
if (this.absPath != null) getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
|
|
2486
2513
|
this.updateBuffer(new Uint8Array(buff));
|
|
2487
2514
|
return this;
|
|
2488
2515
|
};
|
|
2489
2516
|
this.processWithSharp = async (fn, path) => {
|
|
2490
2517
|
const sharp = await importSharp("processWithSharp");
|
|
2491
|
-
path ??= this.absPath + `.processed-${Date.now()}` + this.extension;
|
|
2518
|
+
path ??= this.absPath != null ? asAbsolutePath(this.absPath + `.processed-${Date.now()}` + this.extension) : void 0;
|
|
2492
2519
|
const buffer = new Uint8Array(await fn(sharp(this.buffer)).toBuffer());
|
|
2493
|
-
getComfyStorage().writeBytes(path, buffer);
|
|
2520
|
+
if (path != null) getComfyStorage().writeBytes(path, buffer);
|
|
2494
2521
|
return new MediaImage({
|
|
2495
2522
|
path,
|
|
2496
2523
|
buffer
|
|
2497
2524
|
});
|
|
2498
2525
|
};
|
|
2499
|
-
this.absPath = data.path;
|
|
2526
|
+
this.absPath = data.path ?? null;
|
|
2500
2527
|
this.execution = data.execution;
|
|
2501
2528
|
this.promptNodeID = data.promptNodeID;
|
|
2529
|
+
if (data.path == null && data.buffer == null) throw new Error("❌ MediaImage: an in-memory image (no path) requires a buffer");
|
|
2502
2530
|
if (data.buffer != null) this.updateBuffer(data.buffer);
|
|
2503
2531
|
}
|
|
2504
2532
|
/** the image as a Blob, e.g. to feed FormData uploads */
|
|
2505
2533
|
getAsBlob() {
|
|
2506
2534
|
return new Blob([this.buffer], { type: `image/${this.metadata.type ?? "png"}` });
|
|
2507
2535
|
}
|
|
2508
|
-
/** return the image filename */
|
|
2536
|
+
/** return the image filename (in-memory images get a stable hash-derived name) */
|
|
2509
2537
|
get filename() {
|
|
2510
|
-
return basename(this.absPath);
|
|
2538
|
+
if (this.absPath != null) return basename(this.absPath);
|
|
2539
|
+
return `image-${this.hash.slice(0, 8)}.${this.metadata.type ?? "png"}`;
|
|
2511
2540
|
}
|
|
2512
2541
|
get baseNameWithoutExtension() {
|
|
2513
2542
|
const fname = this.filename;
|
|
@@ -2573,7 +2602,7 @@ var MediaImage = class MediaImage {
|
|
|
2573
2602
|
}
|
|
2574
2603
|
get buffer() {
|
|
2575
2604
|
if (this._buffer != null) return this._buffer;
|
|
2576
|
-
this._buffer = getComfyStorage().readBytes(this.absPath);
|
|
2605
|
+
this._buffer = getComfyStorage().readBytes(bang(this.absPath, "in-memory MediaImage lost its buffer"));
|
|
2577
2606
|
return this._buffer;
|
|
2578
2607
|
}
|
|
2579
2608
|
get metadata() {
|
|
@@ -2599,7 +2628,9 @@ var ComfyExecution = class {
|
|
|
2599
2628
|
constructor(workflow, data, init = {}) {
|
|
2600
2629
|
this.workflow = workflow;
|
|
2601
2630
|
this.data = data;
|
|
2602
|
-
this.
|
|
2631
|
+
this.save = null;
|
|
2632
|
+
this.scrubHistory = false;
|
|
2633
|
+
this.ephemeral = false;
|
|
2603
2634
|
this.snapshot = null;
|
|
2604
2635
|
this.onProgress = null;
|
|
2605
2636
|
this.logProgress = false;
|
|
@@ -2610,6 +2641,13 @@ var ComfyExecution = class {
|
|
|
2610
2641
|
});
|
|
2611
2642
|
this.onPromptRelatedMessage = (msg) => {
|
|
2612
2643
|
const graph = this.workflow;
|
|
2644
|
+
if (msg.type === "binary_preview_frame") {
|
|
2645
|
+
if (this.wsOutputNodeExecuting) this.onWsImageOutput({
|
|
2646
|
+
bytes: msg.bytes,
|
|
2647
|
+
mime: msg.mime
|
|
2648
|
+
});
|
|
2649
|
+
return;
|
|
2650
|
+
}
|
|
2613
2651
|
if (msg.type === "execution_start") return;
|
|
2614
2652
|
else if (msg.type === "execution_cached") graph.onExecutionCached(msg);
|
|
2615
2653
|
else if (msg.type === "executing") this.onExecuting(msg);
|
|
@@ -2653,72 +2691,104 @@ var ComfyExecution = class {
|
|
|
2653
2691
|
this.imageErrors = [];
|
|
2654
2692
|
this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
|
|
2655
2693
|
const promptNode = this.workflow.data.apiJson?.[promptNodeID];
|
|
2656
|
-
const promptMeta = this.workflow.data.metadata?.[promptNodeID];
|
|
2657
2694
|
if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`);
|
|
2658
2695
|
const imgRoute = "/view?" + new URLSearchParams(comfyImageInfo).toString();
|
|
2659
|
-
const
|
|
2696
|
+
const response = await this.host.fetchFile(imgRoute);
|
|
2697
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2698
|
+
const comfyUIInfos = {
|
|
2699
|
+
comfyImageInfo,
|
|
2700
|
+
comfyHostHttpURL: this.host.getServerHostHTTP()
|
|
2701
|
+
};
|
|
2702
|
+
const sf = this.save;
|
|
2703
|
+
if (sf == null) return this.pushImage(new MediaImage({
|
|
2704
|
+
buffer: bytes,
|
|
2705
|
+
execution: this,
|
|
2706
|
+
promptNodeID,
|
|
2707
|
+
comfyUIInfos
|
|
2708
|
+
}), promptNodeID);
|
|
2660
2709
|
const promptPrefix = promptNode.inputs["filename_prefix"];
|
|
2661
|
-
|
|
2662
|
-
|
|
2710
|
+
const written = await this.encodeAndWrite({
|
|
2711
|
+
bytes,
|
|
2712
|
+
sf,
|
|
2663
2713
|
filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
|
|
2664
2714
|
subfolder: comfyImageInfo.subfolder,
|
|
2665
|
-
filename: comfyImageInfo.filename
|
|
2666
|
-
timestamp: runTimestamp(new Date(this.startedAt))
|
|
2667
|
-
}));
|
|
2668
|
-
if (sf?.format && sf.format !== "raw") {
|
|
2669
|
-
const extension = sf.format.split("/")[1];
|
|
2670
|
-
absPath += "." + extension;
|
|
2671
|
-
}
|
|
2672
|
-
const storage = getComfyStorage();
|
|
2673
|
-
absPath = uniquifyOutputPath({
|
|
2674
|
-
path: absPath,
|
|
2675
|
-
exists: (p) => storage.exists(p),
|
|
2676
|
-
claimed: CLAIMED_OUTPUT_PATHS
|
|
2715
|
+
filename: comfyImageInfo.filename
|
|
2677
2716
|
});
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2717
|
+
this.pushImage(new MediaImage({
|
|
2718
|
+
path: written.path,
|
|
2719
|
+
buffer: written.bytes,
|
|
2720
|
+
execution: this,
|
|
2721
|
+
promptNodeID,
|
|
2722
|
+
comfyUIInfos
|
|
2723
|
+
}), promptNodeID);
|
|
2724
|
+
};
|
|
2725
|
+
this.encodeAndWrite = async (p) => {
|
|
2726
|
+
let bytes = p.bytes;
|
|
2727
|
+
const reencode = p.sf.format != null && p.sf.format !== "raw";
|
|
2728
|
+
if (reencode) {
|
|
2681
2729
|
let textChunk = {};
|
|
2682
2730
|
try {
|
|
2683
|
-
const res = getPngMetadataFromUint8Array(
|
|
2731
|
+
const res = getPngMetadataFromUint8Array(p.bytes);
|
|
2684
2732
|
if (res.success) textChunk = res.value;
|
|
2685
2733
|
} catch {}
|
|
2686
2734
|
const format = (() => {
|
|
2687
|
-
if (sf.format === "image/jpeg") return "jpeg";
|
|
2688
|
-
if (sf.format === "image/
|
|
2689
|
-
if (sf.format === "image/webp") return "webp";
|
|
2735
|
+
if (p.sf.format === "image/jpeg") return "jpeg";
|
|
2736
|
+
if (p.sf.format === "image/webp") return "webp";
|
|
2690
2737
|
return "png";
|
|
2691
2738
|
})();
|
|
2692
|
-
const encoded = await (await importSharp(`
|
|
2693
|
-
|
|
2694
|
-
img = new MediaImage({
|
|
2695
|
-
path: asAbsolutePath(absPath),
|
|
2696
|
-
buffer: new Uint8Array(encoded),
|
|
2697
|
-
execution: this,
|
|
2698
|
-
promptNodeID,
|
|
2699
|
-
comfyUIInfos: {
|
|
2700
|
-
comfyImageInfo,
|
|
2701
|
-
comfyHostHttpURL: this.host.getServerHostHTTP()
|
|
2702
|
-
}
|
|
2703
|
-
});
|
|
2704
|
-
} else {
|
|
2705
|
-
const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
|
|
2706
|
-
const uint8arr = new Uint8Array(buff);
|
|
2707
|
-
storage.writeBytes(asAbsolutePath(absPath), uint8arr);
|
|
2708
|
-
img = new MediaImage({
|
|
2709
|
-
path: asAbsolutePath(absPath),
|
|
2710
|
-
buffer: uint8arr,
|
|
2711
|
-
execution: this,
|
|
2712
|
-
promptNodeID,
|
|
2713
|
-
comfyUIInfos: {
|
|
2714
|
-
comfyImageInfo,
|
|
2715
|
-
comfyHostHttpURL: this.host.getServerHostHTTP()
|
|
2716
|
-
}
|
|
2717
|
-
});
|
|
2739
|
+
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();
|
|
2740
|
+
bytes = new Uint8Array(encoded);
|
|
2718
2741
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2742
|
+
let absPath = comfyts.resolveFromOutput(localOutputPath({
|
|
2743
|
+
localDir: p.sf.prefix,
|
|
2744
|
+
filenamePrefix: p.filenamePrefix,
|
|
2745
|
+
subfolder: p.subfolder,
|
|
2746
|
+
filename: p.filename,
|
|
2747
|
+
timestamp: runTimestamp(new Date(this.startedAt))
|
|
2748
|
+
}));
|
|
2749
|
+
if (reencode) absPath += "." + bang(p.sf.format).split("/")[1];
|
|
2750
|
+
const storage = getComfyStorage();
|
|
2751
|
+
absPath = uniquifyOutputPath({
|
|
2752
|
+
path: absPath,
|
|
2753
|
+
exists: (x) => storage.exists(x),
|
|
2754
|
+
claimed: CLAIMED_OUTPUT_PATHS
|
|
2755
|
+
});
|
|
2756
|
+
storage.writeBytes(asAbsolutePath(absPath), bytes);
|
|
2757
|
+
return {
|
|
2758
|
+
path: asAbsolutePath(absPath),
|
|
2759
|
+
bytes
|
|
2760
|
+
};
|
|
2761
|
+
};
|
|
2762
|
+
this.onWsImageOutput = (p) => {
|
|
2763
|
+
const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null;
|
|
2764
|
+
this.pendingPromises.push(this.storeWsImage(p, promptNodeID).catch((e) => {
|
|
2765
|
+
console.error(`🔴 failed to store a SaveImageWebsocket output:`, e);
|
|
2766
|
+
this.imageErrors.push({
|
|
2767
|
+
image: null,
|
|
2768
|
+
error: e
|
|
2769
|
+
});
|
|
2770
|
+
}));
|
|
2771
|
+
};
|
|
2772
|
+
this.storeWsImage = async (p, promptNodeID) => {
|
|
2773
|
+
const sf = this.save;
|
|
2774
|
+
if (sf == null) return this.pushImage(new MediaImage({
|
|
2775
|
+
buffer: p.bytes,
|
|
2776
|
+
execution: this,
|
|
2777
|
+
promptNodeID
|
|
2778
|
+
}), promptNodeID);
|
|
2779
|
+
const ext = p.mime === "image/jpeg" ? "jpg" : p.mime.split("/")[1] ?? "png";
|
|
2780
|
+
const written = await this.encodeAndWrite({
|
|
2781
|
+
bytes: p.bytes,
|
|
2782
|
+
sf,
|
|
2783
|
+
subfolder: "",
|
|
2784
|
+
filename: `${this.workflow.id}.${ext}`
|
|
2785
|
+
});
|
|
2786
|
+
this.pushImage(new MediaImage({
|
|
2787
|
+
path: written.path,
|
|
2788
|
+
buffer: written.bytes,
|
|
2789
|
+
execution: this,
|
|
2790
|
+
promptNodeID
|
|
2791
|
+
}), promptNodeID);
|
|
2722
2792
|
};
|
|
2723
2793
|
this.images = [];
|
|
2724
2794
|
this.alreadyDone = false;
|
|
@@ -2732,11 +2802,20 @@ var ComfyExecution = class {
|
|
|
2732
2802
|
await Promise.all(this.pendingPromises);
|
|
2733
2803
|
this.host.executions.delete(this.data.id);
|
|
2734
2804
|
this.host._pendingMsgs.delete(this.data.id);
|
|
2805
|
+
if (this.ephemeral) {
|
|
2806
|
+
const classTypes = Object.values(this.snapshot?.apiJson ?? {}).map((n) => n.class_type);
|
|
2807
|
+
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.`);
|
|
2808
|
+
}
|
|
2809
|
+
if (this.scrubHistory) await this.host.deleteHistory(this.data.id).catch((e) => {
|
|
2810
|
+
console.error(`🔴 failed to scrub history entry ${this.data.id} on host ${this.host.data.id}:`, e);
|
|
2811
|
+
});
|
|
2735
2812
|
this.finishProgressLine();
|
|
2736
2813
|
this._resolve(this);
|
|
2737
2814
|
};
|
|
2738
2815
|
this.snapshot = init.snapshot ?? null;
|
|
2739
|
-
this.
|
|
2816
|
+
this.save = init.save === true ? {} : init.save === false ? null : init.save ?? null;
|
|
2817
|
+
this.scrubHistory = init.scrubHistory ?? false;
|
|
2818
|
+
this.ephemeral = init.ephemeral ?? false;
|
|
2740
2819
|
this.onProgress = init.onProgress ?? null;
|
|
2741
2820
|
this.logProgress = init.logProgress ?? false;
|
|
2742
2821
|
this.host.executions.set(data.id, this);
|
|
@@ -2794,11 +2873,47 @@ var ComfyExecution = class {
|
|
|
2794
2873
|
get status() {
|
|
2795
2874
|
return this.data.status ?? "New";
|
|
2796
2875
|
}
|
|
2876
|
+
/** accumulate an output on the prompt; tags from node metadata ride along */
|
|
2877
|
+
pushImage(img, promptNodeID) {
|
|
2878
|
+
const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null;
|
|
2879
|
+
if (promptMeta?.tag) img.tags.push(promptMeta.tag);
|
|
2880
|
+
if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
|
|
2881
|
+
this.images.push(img);
|
|
2882
|
+
}
|
|
2883
|
+
/** true while the currently executing node is a SaveImageWebsocket in the
|
|
2884
|
+
* SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
|
|
2885
|
+
* live graph may still say SaveImage) — binary frames are then OUTPUTS */
|
|
2886
|
+
get wsOutputNodeExecuting() {
|
|
2887
|
+
const uid = this.workflow.currentExecutingNode?.uid;
|
|
2888
|
+
if (uid == null) return false;
|
|
2889
|
+
return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
|
|
2890
|
+
}
|
|
2797
2891
|
update(data) {
|
|
2798
2892
|
Object.assign(this.data, data);
|
|
2799
2893
|
}
|
|
2800
2894
|
};
|
|
2801
2895
|
//#endregion
|
|
2896
|
+
//#region src/runner/ephemeral.ts
|
|
2897
|
+
/**
|
|
2898
|
+
* the `ephemeral: true` rewrite (architecture.md item 14): every SaveImage
|
|
2899
|
+
* node in the SENT snapshot becomes a SaveImageWebsocket (core node, `images`
|
|
2900
|
+
* input only), so outputs stream over the ws and never touch the server disk.
|
|
2901
|
+
* Mutates the given apiJson IN PLACE — callers pass the run's deep-copied
|
|
2902
|
+
* snapshot, never the live graph. Returns how many nodes were rewritten so
|
|
2903
|
+
* callers can warn when a graph had nothing to rewrite.
|
|
2904
|
+
*/
|
|
2905
|
+
function rewriteSaveNodesToWebsocket(apiJson) {
|
|
2906
|
+
let rewritten = 0;
|
|
2907
|
+
for (const node of Object.values(apiJson)) {
|
|
2908
|
+
if (node.class_type !== "SaveImage") continue;
|
|
2909
|
+
const images = node.inputs["images"];
|
|
2910
|
+
node.class_type = "SaveImageWebsocket";
|
|
2911
|
+
node.inputs = images == null ? {} : { images };
|
|
2912
|
+
rewritten++;
|
|
2913
|
+
}
|
|
2914
|
+
return rewritten;
|
|
2915
|
+
}
|
|
2916
|
+
//#endregion
|
|
2802
2917
|
//#region src/utils/deepCopyNaive.ts
|
|
2803
2918
|
const deepCopyNaive = (x) => JSON.parse(JSON.stringify(x));
|
|
2804
2919
|
//#endregion
|
|
@@ -3061,6 +3176,11 @@ var ComfyWorkflow = class {
|
|
|
3061
3176
|
apiJson: deepCopyNaive(this.toApiJson(p.idMode ?? "use_stringified_numbers_only")),
|
|
3062
3177
|
workflowJson: await this.toWorkflowJson()
|
|
3063
3178
|
};
|
|
3179
|
+
if (p.ephemeral) {
|
|
3180
|
+
const rewritten = rewriteSaveNodesToWebsocket(snapshot.apiJson);
|
|
3181
|
+
const hasWsSaver = Object.values(snapshot.apiJson).some((n) => n.class_type === "SaveImageWebsocket");
|
|
3182
|
+
if (rewritten === 0 && !hasWsSaver) console.warn(`🟡 ephemeral run: no SaveImage/SaveImageWebsocket node in workflow '${this.id}' — nothing streams back`);
|
|
3183
|
+
}
|
|
3064
3184
|
const out = {
|
|
3065
3185
|
client_id: this.host.comfySessionId,
|
|
3066
3186
|
prompt: snapshot.apiJson,
|
|
@@ -3083,7 +3203,9 @@ var ComfyWorkflow = class {
|
|
|
3083
3203
|
graphID: this.id
|
|
3084
3204
|
}, {
|
|
3085
3205
|
snapshot,
|
|
3086
|
-
|
|
3206
|
+
save: p.save,
|
|
3207
|
+
ephemeral: p.ephemeral ?? false,
|
|
3208
|
+
scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
|
|
3087
3209
|
onProgress: p.onProgress,
|
|
3088
3210
|
logProgress: p.log ?? false
|
|
3089
3211
|
});
|
|
@@ -3793,6 +3915,12 @@ var ComfyHost = class {
|
|
|
3793
3915
|
this.interrupt = () => {
|
|
3794
3916
|
return this.postJSON_("/interrupt", {});
|
|
3795
3917
|
};
|
|
3918
|
+
this.deleteHistory = (promptId) => {
|
|
3919
|
+
return this.postJSON_("/history", { delete: [promptId] });
|
|
3920
|
+
};
|
|
3921
|
+
this.clearHistory = () => {
|
|
3922
|
+
return this.postJSON_("/history", { clear: true });
|
|
3923
|
+
};
|
|
3796
3924
|
this.fetchRawLogs = async () => {
|
|
3797
3925
|
const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
|
|
3798
3926
|
if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
|
|
@@ -4028,6 +4156,22 @@ var ComfyHost = class {
|
|
|
4028
4156
|
if (e.data instanceof ArrayBuffer) {
|
|
4029
4157
|
const frame = parseBinaryWsFrame(e.data);
|
|
4030
4158
|
if (frame.kind === "preview") {
|
|
4159
|
+
const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null;
|
|
4160
|
+
if (activeExec?.wsOutputNodeExecuting) {
|
|
4161
|
+
activeExec.onWsImageOutput({
|
|
4162
|
+
bytes: frame.bytes,
|
|
4163
|
+
mime: frame.mime
|
|
4164
|
+
});
|
|
4165
|
+
return;
|
|
4166
|
+
}
|
|
4167
|
+
if (this.activePromptID != null) {
|
|
4168
|
+
const pending = this._pendingMsgs.get(this.activePromptID);
|
|
4169
|
+
if (pending != null) pending.push({
|
|
4170
|
+
type: "binary_preview_frame",
|
|
4171
|
+
bytes: frame.bytes,
|
|
4172
|
+
mime: frame.mime
|
|
4173
|
+
});
|
|
4174
|
+
}
|
|
4031
4175
|
const imageBlob = new Blob([frame.bytes], { type: frame.mime });
|
|
4032
4176
|
this.latentPreview = {
|
|
4033
4177
|
blob: imageBlob,
|
|
@@ -4740,4 +4884,4 @@ var ComfyTS = class ComfyTS {
|
|
|
4740
4884
|
//#endregion
|
|
4741
4885
|
export { ComfySchema as a, stripAnsi as i, settingsPathFor as n, sha1HexOfString as o, readableStringify as r, ComfyTS as t };
|
|
4742
4886
|
|
|
4743
|
-
//# sourceMappingURL=state-
|
|
4887
|
+
//# sourceMappingURL=state-DC5BcG6d.js.map
|