comfy-ts 2.22.0 → 2.24.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/dist/{ServeApp-DuxYdaZZ.js → ServeApp-fsHtW5zG.js} +51 -17
- package/dist/ServeApp-fsHtW5zG.js.map +1 -0
- package/dist/cli.js +5 -5
- package/dist/{exampleAssets-1NHndnNB.js → exampleAssets-DZynSkZm.js} +405 -39
- package/dist/exampleAssets-DZynSkZm.js.map +1 -0
- package/dist/{findDefinedWorkflow-CRsBTTJK.js → findDefinedWorkflow-qyqFea7q.js} +2 -2
- package/dist/{findDefinedWorkflow-CRsBTTJK.js.map → findDefinedWorkflow-qyqFea7q.js.map} +1 -1
- package/dist/index.cjs +428 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +147 -1
- package/dist/index.d.ts +147 -1
- package/dist/index.js +428 -47
- package/dist/index.js.map +1 -1
- package/dist/{run-run-Y5ZI48vV.js → run-run-Cn2JzKlE.js} +5 -5
- package/dist/{run-run-Y5ZI48vV.js.map → run-run-Cn2JzKlE.js.map} +1 -1
- package/dist/{run-serve-CICU_wTL.js → run-serve-BhGegaCI.js} +4 -4
- package/dist/{run-serve-CICU_wTL.js.map → run-serve-BhGegaCI.js.map} +1 -1
- package/dist/{run-tui-CViJXsHL.js → run-tui-CrM4ijkH.js} +4 -4
- package/dist/{run-tui-CViJXsHL.js.map → run-tui-CrM4ijkH.js.map} +1 -1
- package/dist/{schemaDrift-CzjaIwZX.js → schemaDrift-BGYJZGMD.js} +18 -3
- package/dist/{schemaDrift-CzjaIwZX.js.map → schemaDrift-BGYJZGMD.js.map} +1 -1
- package/dist/serve-web.js +46 -43
- package/dist/web.d.ts +147 -1
- package/dist/web.js +428 -47
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/comfy-cloud/sdk.d.ts +102 -1
- package/examples/depth-explorer/models.ts +6 -56
- package/examples/depth-explorer/serve.ts +12 -133
- package/examples/depth-explorer/web/App.tsx +20 -91
- package/examples/depth-explorer/web/index.html +1 -0
- package/examples/depth-explorer/web/state.ts +26 -109
- package/examples/depth-explorer/web/styles.css +1 -286
- package/examples/explorer-kit/catalog.ts +80 -0
- package/examples/explorer-kit/server.ts +167 -0
- package/examples/explorer-kit/web/base.css +289 -0
- package/examples/explorer-kit/web/runs.ts +160 -0
- package/examples/explorer-kit/web/ui.tsx +125 -0
- package/examples/rvion/17-relight.cflow.ts +2 -1
- package/examples/rvion/18-world.cflow.ts +101 -0
- package/examples/rvion/19-flythrough.cflow.ts +312 -0
- package/examples/rvion/20-grow-splat.cflow.ts +88 -0
- package/examples/rvion/21-photo-to-model.cflow.ts +191 -0
- package/examples/rvion/flythroughChain.ts +171 -0
- package/examples/rvion/flythroughColmap.ts +157 -0
- package/examples/rvion/flythroughFuse.ts +199 -0
- package/examples/rvion/flythroughGuide.ts +300 -0
- package/examples/rvion/flythroughPalette.ts +310 -0
- package/examples/rvion/flythroughPath.ts +177 -0
- package/examples/rvion/flythroughSplat.ts +73 -0
- package/examples/rvion/grow-splat/align.ts +114 -0
- package/examples/rvion/grow-splat/grow.ts +198 -0
- package/examples/rvion/grow-splat/ply.ts +166 -0
- package/examples/rvion/grow-splat/raster.ts +207 -0
- package/examples/rvion/grow-splat/sharp.ts +45 -0
- package/examples/rvion/splatDataset.ts +80 -0
- package/examples/rvion/splatEval.ts +380 -0
- package/examples/upscale-explorer/models.ts +341 -0
- package/examples/upscale-explorer/serve.ts +19 -0
- package/examples/upscale-explorer/web/App.tsx +250 -0
- package/examples/upscale-explorer/web/compare.tsx +285 -0
- package/examples/upscale-explorer/web/index.html +15 -0
- package/examples/upscale-explorer/web/main.tsx +12 -0
- package/examples/upscale-explorer/web/state.ts +279 -0
- package/examples/upscale-explorer/web/styles.css +241 -0
- package/examples/upscale-explorer/web/tsconfig.json +16 -0
- package/examples/upscale-explorer/web/viewport.tsx +130 -0
- package/examples/world-explorer/serve.ts +171 -0
- package/examples/world-explorer/web/index.html +14 -0
- package/examples/world-explorer/web/main.tsx +200 -0
- package/examples/world-explorer/web/state.ts +212 -0
- package/examples/world-explorer/web/styles.css +131 -0
- package/examples/world-explorer/web/thumb.ts +21 -0
- package/examples/world-explorer/web/tsconfig.json +11 -0
- package/examples/world-explorer/world-state.ts +40 -0
- package/package.json +7 -8
- package/src/cli/serve/ServeApp.ts +27 -2
- package/src/cli/serve/resultHistory.ts +22 -4
- package/src/cli/serve/thumbs.ts +19 -8
- package/src/cli/serve/web/api.ts +4 -0
- package/src/cli/serve/web/components/Gallery.tsx +24 -1
- package/src/cli/serve/web/styles.ts +3 -0
- package/src/coreExports.ts +6 -0
- package/src/graph/ComfyNode.ts +12 -2
- package/src/host/ComfyHost.ts +159 -2
- package/src/host/ResilientWebsocket.ts +10 -0
- package/src/manager/script-update-manager.bun.ts +0 -7
- package/src/runner/ComfyExecution.ts +185 -23
- package/src/runner/ComfyWorkflow.ts +22 -0
- package/src/runner/ComfyWsApi.ts +3 -1
- package/src/runner/comfyOrgApiKey.ts +44 -0
- package/src/runner/historyReplay.ts +53 -0
- package/src/runner/outputs3d.ts +18 -0
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +2 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
- package/src/state.ts +2 -0
- package/src/vars/DefinedWorkflow.ts +1 -0
- package/dist/ServeApp-DuxYdaZZ.js.map +0 -1
- package/dist/exampleAssets-1NHndnNB.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 = "2.
|
|
104
|
+
var version = "2.24.0";
|
|
105
105
|
//#endregion
|
|
106
106
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
107
107
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -1856,13 +1856,14 @@ var ComfyNode = class ComfyNode {
|
|
|
1856
1856
|
throw new Error(`🔴 no input "${name}" on ${this.$schema.nodeKey}: cannot tell which output of the linked node to use`);
|
|
1857
1857
|
}
|
|
1858
1858
|
_getOutputForTypeOrCrash(type) {
|
|
1859
|
-
const i = this.$schema.outputs.find((i) => i.typeName
|
|
1859
|
+
const i = this.$schema.outputs.find((i) => slotTypeAccepts(type, i.typeName));
|
|
1860
|
+
if (i == null) throw new Error(`🔴 ${this.$schema.nodeKey} has no output of type ${type}: link one of its outputs by name instead`);
|
|
1860
1861
|
const val = this.outputs[i.outKey];
|
|
1861
1862
|
if (val instanceof ComfyNodeOutput) return val;
|
|
1862
1863
|
throw new Error(`Expected ${i.outKey} to be a ComfyNodeOutput`);
|
|
1863
1864
|
}
|
|
1864
1865
|
_getOutputForTypeOrNull(type) {
|
|
1865
|
-
const i = this.$schema.outputs.find((i) => i.typeName
|
|
1866
|
+
const i = this.$schema.outputs.find((i) => slotTypeAccepts(type, i.typeName));
|
|
1866
1867
|
if (i == null) return null;
|
|
1867
1868
|
const val = this.outputs[i.outKey];
|
|
1868
1869
|
if (val == null) return null;
|
|
@@ -1870,6 +1871,11 @@ var ComfyNode = class ComfyNode {
|
|
|
1870
1871
|
throw new Error(`Expected ${i.outKey} to be a ComfyNodeOutput`);
|
|
1871
1872
|
}
|
|
1872
1873
|
};
|
|
1874
|
+
/** an input typed `MESH,FILE_3D_GLB` takes an output of ANY listed type (ComfyUI's SaveGLB) */
|
|
1875
|
+
function slotTypeAccepts(inputType, outputType) {
|
|
1876
|
+
if (inputType === outputType) return true;
|
|
1877
|
+
return inputType.includes(",") && inputType.split(",").some((part) => part.trim() === outputType);
|
|
1878
|
+
}
|
|
1873
1879
|
//#endregion
|
|
1874
1880
|
//#region src/host/ComfyWorkflowBuilder.ts
|
|
1875
1881
|
var ComfyWorkflowBuilder = class {
|
|
@@ -2317,7 +2323,10 @@ const types$1 = scope({
|
|
|
2317
2323
|
Timestamp: "number",
|
|
2318
2324
|
ApiPromptInput: {
|
|
2319
2325
|
client_id: "string",
|
|
2320
|
-
extra_data: {
|
|
2326
|
+
extra_data: {
|
|
2327
|
+
extra_pnginfo: "unknown",
|
|
2328
|
+
"api_key_comfy_org?": "string"
|
|
2329
|
+
},
|
|
2321
2330
|
prompt: "unknown"
|
|
2322
2331
|
},
|
|
2323
2332
|
NodeProgress: {
|
|
@@ -2372,6 +2381,7 @@ const types$1 = scope({
|
|
|
2372
2381
|
"audio?": "ComfyImageInfo[]",
|
|
2373
2382
|
"video?": "ComfyImageInfo[]",
|
|
2374
2383
|
"gifs?": "ComfyImageInfo[]",
|
|
2384
|
+
"3d?": "ComfyImageInfo[]",
|
|
2375
2385
|
"text?": "unknown[]"
|
|
2376
2386
|
},
|
|
2377
2387
|
WsMsgExecuted: {
|
|
@@ -2733,6 +2743,88 @@ function mediaMime(filename) {
|
|
|
2733
2743
|
return MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
2734
2744
|
}
|
|
2735
2745
|
//#endregion
|
|
2746
|
+
//#region src/runner/outputs3d.ts
|
|
2747
|
+
/** ply and spz have no registered mime: the `x-` forms are what three.js and the splat viewers accept */
|
|
2748
|
+
const MODEL_3D_MIMES = {
|
|
2749
|
+
glb: "model/gltf-binary",
|
|
2750
|
+
gltf: "model/gltf+json",
|
|
2751
|
+
ply: "model/x-ply",
|
|
2752
|
+
spz: "model/x-spz",
|
|
2753
|
+
obj: "model/obj",
|
|
2754
|
+
stl: "model/stl"
|
|
2755
|
+
};
|
|
2756
|
+
function model3dMime(filename) {
|
|
2757
|
+
return MODEL_3D_MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
2758
|
+
}
|
|
2759
|
+
//#endregion
|
|
2760
|
+
//#region src/runner/historyReplay.ts
|
|
2761
|
+
const END_TYPES = /* @__PURE__ */ new Set([
|
|
2762
|
+
"execution_success",
|
|
2763
|
+
"execution_error",
|
|
2764
|
+
"execution_interrupted"
|
|
2765
|
+
]);
|
|
2766
|
+
/** a prompt's `GET /history/<id>` reply as the ws messages a client missed. Null while the host has no
|
|
2767
|
+
* entry for it: queued, running, or lost */
|
|
2768
|
+
function historyReplay(json, promptId) {
|
|
2769
|
+
const entry = field(json, promptId);
|
|
2770
|
+
if (entry == null) return null;
|
|
2771
|
+
const problems = [];
|
|
2772
|
+
const valid = (raw) => {
|
|
2773
|
+
const res = types$1.PromptRelated_WsMsg(raw);
|
|
2774
|
+
if (!(res instanceof type.errors)) return res;
|
|
2775
|
+
problems.push(`${JSON.stringify(raw).slice(0, 200)}: ${res.summary}`);
|
|
2776
|
+
return null;
|
|
2777
|
+
};
|
|
2778
|
+
const executed = [];
|
|
2779
|
+
const outputs = field(entry, "outputs");
|
|
2780
|
+
if (typeof outputs === "object" && outputs != null) for (const [node, output] of Object.entries(outputs)) {
|
|
2781
|
+
const msg = valid({
|
|
2782
|
+
type: "executed",
|
|
2783
|
+
data: {
|
|
2784
|
+
node,
|
|
2785
|
+
output,
|
|
2786
|
+
prompt_id: promptId
|
|
2787
|
+
}
|
|
2788
|
+
});
|
|
2789
|
+
if (msg != null) executed.push(msg);
|
|
2790
|
+
}
|
|
2791
|
+
const status = field(entry, "status");
|
|
2792
|
+
const list = field(status, "messages");
|
|
2793
|
+
let end = null;
|
|
2794
|
+
for (const m of Array.isArray(list) ? list : []) {
|
|
2795
|
+
if (!Array.isArray(m) || typeof m[0] !== "string" || !END_TYPES.has(m[0])) continue;
|
|
2796
|
+
end = valid({
|
|
2797
|
+
type: m[0],
|
|
2798
|
+
data: m[1]
|
|
2799
|
+
});
|
|
2800
|
+
}
|
|
2801
|
+
const statusStr = field(status, "status_str");
|
|
2802
|
+
if (end == null && (status == null || statusStr === "success")) end = valid({
|
|
2803
|
+
type: "execution_success",
|
|
2804
|
+
data: {
|
|
2805
|
+
prompt_id: promptId,
|
|
2806
|
+
timestamp: Date.now()
|
|
2807
|
+
}
|
|
2808
|
+
});
|
|
2809
|
+
return {
|
|
2810
|
+
executed,
|
|
2811
|
+
end,
|
|
2812
|
+
problems
|
|
2813
|
+
};
|
|
2814
|
+
}
|
|
2815
|
+
function field(x, key) {
|
|
2816
|
+
if (typeof x !== "object" || x == null) return null;
|
|
2817
|
+
return Reflect.get(x, key) ?? null;
|
|
2818
|
+
}
|
|
2819
|
+
//#endregion
|
|
2820
|
+
//#region src/utils/log.ts
|
|
2821
|
+
const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
|
|
2822
|
+
const logInfo = (msg) => {
|
|
2823
|
+
if (!isQuiet()) console.log(msg);
|
|
2824
|
+
};
|
|
2825
|
+
const logError = (msg) => console.error(`[comfy-ts] 🔴 ${msg}`);
|
|
2826
|
+
const logSuccess = (msg) => console.log(`[comfy-ts] 🟢 ${msg}`);
|
|
2827
|
+
//#endregion
|
|
2736
2828
|
//#region src/runner/ComfyExecution.ts
|
|
2737
2829
|
/** paths claimed by in-flight retrievals: two same-second runs on a
|
|
2738
2830
|
* counter-resetting cloud host compute the same name before either writes.
|
|
@@ -2759,6 +2851,9 @@ var ComfyExecution = class {
|
|
|
2759
2851
|
this._resolve = resolve;
|
|
2760
2852
|
});
|
|
2761
2853
|
this.onPromptRelatedMessage = (msg) => {
|
|
2854
|
+
if (this.ended) return;
|
|
2855
|
+
this.heard();
|
|
2856
|
+
if (msg.type === "execution_success" || msg.type === "execution_error" || msg.type === "execution_interrupted") this.ended = true;
|
|
2762
2857
|
const graph = this.workflow;
|
|
2763
2858
|
if (msg.type === "binary_preview_frame") {
|
|
2764
2859
|
if (this.wsOutputNodeExecuting) this.onWsImageOutput({
|
|
@@ -2789,6 +2884,7 @@ var ComfyExecution = class {
|
|
|
2789
2884
|
this.workflow.onExecuting(msg);
|
|
2790
2885
|
};
|
|
2791
2886
|
this.onExecutionSuccess = async (_msg) => {
|
|
2887
|
+
if (this.mayHaveMissedEvents) await this.retrieveMissedOutputs();
|
|
2792
2888
|
await Promise.all(this.pendingPromises);
|
|
2793
2889
|
return this._finish({ status: "Success" });
|
|
2794
2890
|
};
|
|
@@ -2802,6 +2898,7 @@ var ComfyExecution = class {
|
|
|
2802
2898
|
};
|
|
2803
2899
|
this.onExecuted = (msg) => {
|
|
2804
2900
|
const promptNodeID = msg.data.node;
|
|
2901
|
+
this.heardExecuted.add(promptNodeID);
|
|
2805
2902
|
for (const entry of msg.data.output?.text ?? []) {
|
|
2806
2903
|
if (typeof entry !== "string") continue;
|
|
2807
2904
|
const nodeKey = this.workflow.data.apiJson?.[promptNodeID]?.class_type ?? null;
|
|
@@ -2817,7 +2914,7 @@ var ComfyExecution = class {
|
|
|
2817
2914
|
...out?.video ?? [],
|
|
2818
2915
|
...out?.gifs ?? []
|
|
2819
2916
|
].filter((f) => f.type !== "input");
|
|
2820
|
-
for (const video of listed.filter((f) => isVideoFilename(f.filename))) this.pendingPromises.push(this.retrieveFile(
|
|
2917
|
+
for (const video of listed.filter((f) => isVideoFilename(f.filename))) this.pendingPromises.push(this.retrieveFile(video, promptNodeID, mediaMime(video.filename)).then((o) => void this.videos.push(o), (e) => {
|
|
2821
2918
|
console.error(`🔴 failed to retrieve ${video.filename}:`, e);
|
|
2822
2919
|
this.videoErrors.push({
|
|
2823
2920
|
video,
|
|
@@ -2832,35 +2929,118 @@ var ComfyExecution = class {
|
|
|
2832
2929
|
error: e
|
|
2833
2930
|
});
|
|
2834
2931
|
}));
|
|
2835
|
-
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveFile(
|
|
2932
|
+
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveFile(audio, promptNodeID, mediaMime(audio.filename)).then((o) => void this.audios.push(o), (e) => {
|
|
2836
2933
|
console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
|
|
2837
2934
|
this.audioErrors.push({
|
|
2838
2935
|
audio,
|
|
2839
2936
|
error: e
|
|
2840
2937
|
});
|
|
2841
2938
|
}));
|
|
2939
|
+
for (const model3d of (out?.["3d"] ?? []).filter((f) => f.type !== "input")) this.pendingPromises.push(this.retrieveFile(model3d, promptNodeID, model3dMime(model3d.filename)).then((o) => void this.models3d.push({
|
|
2940
|
+
...o,
|
|
2941
|
+
format: extensionOf(o.filename)
|
|
2942
|
+
}), (e) => {
|
|
2943
|
+
console.error(`🔴 failed to retrieve ${model3d.filename}:`, e);
|
|
2944
|
+
this.models3dErrors.push({
|
|
2945
|
+
model3d,
|
|
2946
|
+
error: e
|
|
2947
|
+
});
|
|
2948
|
+
}));
|
|
2842
2949
|
};
|
|
2843
2950
|
this.pendingPromises = [];
|
|
2951
|
+
this.ended = false;
|
|
2952
|
+
this.heardExecuted = /* @__PURE__ */ new Set();
|
|
2953
|
+
this.mayHaveMissedEvents = false;
|
|
2954
|
+
this.historyRetry = {
|
|
2955
|
+
tries: 5,
|
|
2956
|
+
ms: 400
|
|
2957
|
+
};
|
|
2958
|
+
this.retrieveMissedOutputs = async () => {
|
|
2959
|
+
const id = this.data.id;
|
|
2960
|
+
for (let i = 0; i < this.historyRetry.tries; i++) {
|
|
2961
|
+
if (this.host.reconcileOff != null) return;
|
|
2962
|
+
if (i > 0) await new Promise((r) => setTimeout(r, this.historyRetry.ms));
|
|
2963
|
+
try {
|
|
2964
|
+
const replay = historyReplay(await this.host.fetchHistory(id), id);
|
|
2965
|
+
if (replay == null) continue;
|
|
2966
|
+
return this.replayUnheardOutputs(replay);
|
|
2967
|
+
} catch (e) {
|
|
2968
|
+
if (this.host.noteReconcileFailure(e)) return;
|
|
2969
|
+
return logError(`run ${id}: its history did not answer (${extractErrorMessage(e)}); an output sent while the socket was down may be missing`);
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
logError(`run ${id}: no history entry after its end; an output sent while the socket was down may be missing`);
|
|
2973
|
+
};
|
|
2974
|
+
this.lastHeardAt = Date.now();
|
|
2975
|
+
this.reconciling = false;
|
|
2976
|
+
this.loggedReconcileProblems = /* @__PURE__ */ new Set();
|
|
2977
|
+
this.reconcile = async (queued) => {
|
|
2978
|
+
const id = this.data.id;
|
|
2979
|
+
const hostId = this.host.data.id;
|
|
2980
|
+
try {
|
|
2981
|
+
if (this.ended || queued?.has(id) === true) return "waiting";
|
|
2982
|
+
let replay;
|
|
2983
|
+
try {
|
|
2984
|
+
replay = historyReplay(await this.host.fetchHistory(id), id);
|
|
2985
|
+
} catch (e) {
|
|
2986
|
+
if (!this.host.noteReconcileFailure(e)) this.logReconcileOnce(`the history of host '${hostId}' did not answer (${extractErrorMessage(e)}); waiting for its events`);
|
|
2987
|
+
return "waiting";
|
|
2988
|
+
}
|
|
2989
|
+
if (this.ended) return "waiting";
|
|
2990
|
+
if (replay == null) {
|
|
2991
|
+
if (queued == null) return "waiting";
|
|
2992
|
+
const reason = `host '${hostId}' has it neither in its queue nor in its history (cancelled, or the host restarted)`;
|
|
2993
|
+
logError(`run ${id}: ${reason}; the run fails`);
|
|
2994
|
+
this.ended = true;
|
|
2995
|
+
await this._finish({
|
|
2996
|
+
status: "Failure",
|
|
2997
|
+
error: null,
|
|
2998
|
+
reason
|
|
2999
|
+
});
|
|
3000
|
+
return "lost";
|
|
3001
|
+
}
|
|
3002
|
+
const sinceHeard = Date.now() - this.lastHeardAt;
|
|
3003
|
+
if (!this.mayHaveMissedEvents && this.sendsWsFrames && sinceHeard < this.host.runSilenceMaxMs) return "waiting";
|
|
3004
|
+
logInfo(`run ${id}: ended on host '${hostId}' without its end reaching the socket, finishing from its history`);
|
|
3005
|
+
for (const p of replay.problems) logError(`run ${id}: a history entry does not match the ws schemas, skipped: ${p}`);
|
|
3006
|
+
this.replayUnheardOutputs(replay);
|
|
3007
|
+
if (this.ephemeral) logError(`run ${id}: SaveImageWebsocket frames sent while the socket did not hear are lost (they never reach the server disk)`);
|
|
3008
|
+
if (replay.end != null) {
|
|
3009
|
+
this.onPromptRelatedMessage(replay.end);
|
|
3010
|
+
return "history";
|
|
3011
|
+
}
|
|
3012
|
+
const reason = `its history entry on host '${hostId}' carries no end message`;
|
|
3013
|
+
logError(`run ${id}: ${reason}; the run fails`);
|
|
3014
|
+
this.ended = true;
|
|
3015
|
+
await this._finish({
|
|
3016
|
+
status: "Failure",
|
|
3017
|
+
error: null,
|
|
3018
|
+
reason
|
|
3019
|
+
});
|
|
3020
|
+
return "history";
|
|
3021
|
+
} finally {
|
|
3022
|
+
this.reconciling = false;
|
|
3023
|
+
}
|
|
3024
|
+
};
|
|
2844
3025
|
this.audioErrors = [];
|
|
2845
3026
|
this.audios = [];
|
|
2846
3027
|
this.videoErrors = [];
|
|
2847
3028
|
this.videos = [];
|
|
2848
|
-
this.
|
|
3029
|
+
this.models3dErrors = [];
|
|
3030
|
+
this.models3d = [];
|
|
3031
|
+
this.retrieveFile = async (info, promptNodeID, mime) => {
|
|
2849
3032
|
const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
|
|
2850
3033
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2851
|
-
const
|
|
2852
|
-
const list = kind === "audio" ? this.audios : this.videos;
|
|
3034
|
+
const tags = this.tagsOf(promptNodeID);
|
|
2853
3035
|
const sf = this.save;
|
|
2854
|
-
if (sf == null) {
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
return;
|
|
2863
|
-
}
|
|
3036
|
+
if (sf == null) return {
|
|
3037
|
+
nodeId: promptNodeID,
|
|
3038
|
+
filename: info.filename,
|
|
3039
|
+
mime,
|
|
3040
|
+
bytes,
|
|
3041
|
+
absPath: null,
|
|
3042
|
+
tags
|
|
3043
|
+
};
|
|
2864
3044
|
const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs["filename_prefix"];
|
|
2865
3045
|
const written = await this.encodeAndWrite({
|
|
2866
3046
|
bytes,
|
|
@@ -2872,13 +3052,14 @@ var ComfyExecution = class {
|
|
|
2872
3052
|
subfolder: info.subfolder,
|
|
2873
3053
|
filename: info.filename
|
|
2874
3054
|
});
|
|
2875
|
-
|
|
3055
|
+
return {
|
|
2876
3056
|
nodeId: promptNodeID,
|
|
2877
3057
|
filename: info.filename,
|
|
2878
3058
|
mime,
|
|
2879
3059
|
bytes,
|
|
2880
|
-
absPath: written.path
|
|
2881
|
-
|
|
3060
|
+
absPath: written.path,
|
|
3061
|
+
tags
|
|
3062
|
+
};
|
|
2882
3063
|
};
|
|
2883
3064
|
this.imageErrors = [];
|
|
2884
3065
|
this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
|
|
@@ -2956,6 +3137,7 @@ var ComfyExecution = class {
|
|
|
2956
3137
|
};
|
|
2957
3138
|
};
|
|
2958
3139
|
this.onWsImageOutput = (p) => {
|
|
3140
|
+
this.heard();
|
|
2959
3141
|
const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null;
|
|
2960
3142
|
this.pendingPromises.push(this.storeWsImage(p, promptNodeID).catch((e) => {
|
|
2961
3143
|
console.error(`🔴 failed to store a SaveImageWebsocket output:`, e);
|
|
@@ -3018,7 +3200,7 @@ var ComfyExecution = class {
|
|
|
3018
3200
|
this.onProgress = init.onProgress ?? null;
|
|
3019
3201
|
this.onPreview = init.onPreview ?? null;
|
|
3020
3202
|
this.logProgress = init.logProgress ?? false;
|
|
3021
|
-
this.host.
|
|
3203
|
+
this.host.trackExecution(this);
|
|
3022
3204
|
this.onCreate();
|
|
3023
3205
|
}
|
|
3024
3206
|
get progress() {
|
|
@@ -3054,6 +3236,7 @@ var ComfyExecution = class {
|
|
|
3054
3236
|
const outputs = [`${this.images.length} image(s)`];
|
|
3055
3237
|
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
|
|
3056
3238
|
if (this.videos.length > 0) outputs.push(`${this.videos.length} video(s)`);
|
|
3239
|
+
if (this.models3d.length > 0) outputs.push(`${this.models3d.length} 3d model(s)`);
|
|
3057
3240
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
|
|
3058
3241
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
|
|
3059
3242
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
@@ -3082,13 +3265,39 @@ var ComfyExecution = class {
|
|
|
3082
3265
|
get status() {
|
|
3083
3266
|
return this.data.status ?? "New";
|
|
3084
3267
|
}
|
|
3268
|
+
replayUnheardOutputs(replay) {
|
|
3269
|
+
for (const msg of replay.executed) if (msg.type === "executed" && !this.heardExecuted.has(msg.data.node)) this.onExecuted(msg);
|
|
3270
|
+
}
|
|
3271
|
+
heard() {
|
|
3272
|
+
this.lastHeardAt = Date.now();
|
|
3273
|
+
}
|
|
3274
|
+
logReconcileOnce(msg) {
|
|
3275
|
+
if (this.loggedReconcileProblems.has(msg)) return;
|
|
3276
|
+
this.loggedReconcileProblems.add(msg);
|
|
3277
|
+
logError(`run ${this.data.id}: ${msg}`);
|
|
3278
|
+
}
|
|
3279
|
+
/** @internal called before the host reads its queue. After a reconnect the run may have lost events,
|
|
3280
|
+
* so its end reads /history for them; the flag is set before any await, so a live end that lands
|
|
3281
|
+
* during the reads still looks. A check for silence alone does not set it: a quiet run lost nothing */
|
|
3282
|
+
beginReconcile(why) {
|
|
3283
|
+
this.reconciling = true;
|
|
3284
|
+
if (why === "reconnect") this.mayHaveMissedEvents = true;
|
|
3285
|
+
}
|
|
3085
3286
|
/** accumulate an output on the prompt; tags from node metadata ride along */
|
|
3086
3287
|
pushImage(img, promptNodeID) {
|
|
3087
|
-
|
|
3088
|
-
if (promptMeta?.tag) img.tags.push(promptMeta.tag);
|
|
3089
|
-
if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
|
|
3288
|
+
img.tags.push(...this.tagsOf(promptNodeID));
|
|
3090
3289
|
this.images.push(img);
|
|
3091
3290
|
}
|
|
3291
|
+
/** the tags an output node was built with (`{ tag }` / `{ tags }` metadata) */
|
|
3292
|
+
tagsOf(promptNodeID) {
|
|
3293
|
+
const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null;
|
|
3294
|
+
return [...promptMeta?.tag ? [promptMeta.tag] : [], ...promptMeta?.tags ?? []];
|
|
3295
|
+
}
|
|
3296
|
+
/** the sent graph saves through SaveImageWebsocket: those outputs exist only as ws frames */
|
|
3297
|
+
get sendsWsFrames() {
|
|
3298
|
+
const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson;
|
|
3299
|
+
return Object.values(apiJson).some((n) => n?.class_type === "SaveImageWebsocket");
|
|
3300
|
+
}
|
|
3092
3301
|
/** true while the currently executing node is a SaveImageWebsocket in the
|
|
3093
3302
|
* SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
|
|
3094
3303
|
* live graph may still say SaveImage) — binary frames are then OUTPUTS */
|
|
@@ -3100,6 +3309,7 @@ var ComfyExecution = class {
|
|
|
3100
3309
|
/** @internal a live preview frame of this run; never an output (the host routes ws saver frames
|
|
3101
3310
|
* to onWsImageOutput before they get here) */
|
|
3102
3311
|
onPreviewFrame(p) {
|
|
3312
|
+
this.heard();
|
|
3103
3313
|
const listener = this.onPreview;
|
|
3104
3314
|
if (listener == null) return;
|
|
3105
3315
|
const current = this.workflow.currentExecutingNode;
|
|
@@ -3121,6 +3331,7 @@ var ComfyExecution = class {
|
|
|
3121
3331
|
}
|
|
3122
3332
|
/** @internal a live-text frame for one node */
|
|
3123
3333
|
onProgressText(p) {
|
|
3334
|
+
this.heard();
|
|
3124
3335
|
this.progressTexts.set(p.nodeId, p.text);
|
|
3125
3336
|
this.progressText = p.text;
|
|
3126
3337
|
this.emitProgress();
|
|
@@ -3134,6 +3345,35 @@ var ComfyExecution = class {
|
|
|
3134
3345
|
}
|
|
3135
3346
|
};
|
|
3136
3347
|
//#endregion
|
|
3348
|
+
//#region src/runner/comfyOrgApiKey.ts
|
|
3349
|
+
/** the prompt holds a paid partner node and no Comfy account key was set */
|
|
3350
|
+
var ComfyOrgApiKeyMissingError = class extends Error {
|
|
3351
|
+
constructor(hostId, nodes) {
|
|
3352
|
+
const list = nodes.map((n) => `${n.classType} #${n.id}`).join(", ");
|
|
3353
|
+
super(`🔴 host '${hostId}': the prompt holds partner API node(s) ${list}, which bill a Comfy account, and no Comfy account key is set. Set it with \`comfy.host({ id: '${hostId}', comfyOrgApiKey })\` or \`run({ comfyOrgApiKey })\` (a string or a thunk; the key comes from platform.comfy.org). Nothing was sent.`);
|
|
3354
|
+
this.hostId = hostId;
|
|
3355
|
+
this.nodes = nodes;
|
|
3356
|
+
this.name = "ComfyOrgApiKeyMissingError";
|
|
3357
|
+
}
|
|
3358
|
+
};
|
|
3359
|
+
/** the nodes of a prompt whose schema says `api_node: true` */
|
|
3360
|
+
const partnerApiNodes = (apiJson, schema) => {
|
|
3361
|
+
const out = [];
|
|
3362
|
+
for (const [id, node] of Object.entries(apiJson)) if (schema.nodesByNameInComfy[node.class_type]?.raw.api_node === true) out.push({
|
|
3363
|
+
id,
|
|
3364
|
+
classType: node.class_type
|
|
3365
|
+
});
|
|
3366
|
+
return out;
|
|
3367
|
+
};
|
|
3368
|
+
/** the first source set wins; an empty string counts as unset */
|
|
3369
|
+
const resolveComfyOrgApiKey = async (sources) => {
|
|
3370
|
+
for (const src of sources) {
|
|
3371
|
+
if (src == null) continue;
|
|
3372
|
+
const key = typeof src === "string" ? src : await src();
|
|
3373
|
+
if (key != null && key !== "") return key;
|
|
3374
|
+
}
|
|
3375
|
+
};
|
|
3376
|
+
//#endregion
|
|
3137
3377
|
//#region src/runner/ephemeral.ts
|
|
3138
3378
|
/**
|
|
3139
3379
|
* the `ephemeral: true` rewrite (architecture.md item 14): every SaveImage
|
|
@@ -3181,14 +3421,6 @@ function styler(open = "", close = "") {
|
|
|
3181
3421
|
}
|
|
3182
3422
|
const ansi = styler();
|
|
3183
3423
|
//#endregion
|
|
3184
|
-
//#region src/utils/log.ts
|
|
3185
|
-
const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
|
|
3186
|
-
const logInfo = (msg) => {
|
|
3187
|
-
if (!isQuiet()) console.log(msg);
|
|
3188
|
-
};
|
|
3189
|
-
const logError = (msg) => console.error(`[comfy-ts] 🔴 ${msg}`);
|
|
3190
|
-
const logSuccess = (msg) => console.log(`[comfy-ts] 🟢 ${msg}`);
|
|
3191
|
-
//#endregion
|
|
3192
3424
|
//#region src/utils/printArkResultInConsole.ts
|
|
3193
3425
|
const MAX_PRINTED_ERRORS = 10;
|
|
3194
3426
|
function printArkResultInConsole(res) {
|
|
@@ -3301,6 +3533,8 @@ function comfyWorkflowAutoLayout(p) {
|
|
|
3301
3533
|
}
|
|
3302
3534
|
//#endregion
|
|
3303
3535
|
//#region src/runner/ComfyWorkflow.ts
|
|
3536
|
+
/** a Comfy Cloud host's X-API-Key is a platform.comfy.org key, the one partner nodes bill to */
|
|
3537
|
+
const COMFY_CLOUD_HOST = "cloud.comfy.org";
|
|
3304
3538
|
const asComfyWorkflowID = (x) => x;
|
|
3305
3539
|
var ComfyWorkflow = class {
|
|
3306
3540
|
constructor(host, data) {
|
|
@@ -3431,14 +3665,29 @@ var ComfyWorkflow = class {
|
|
|
3431
3665
|
const hasWsSaver = Object.values(snapshot.apiJson).some((n) => n.class_type === "SaveImageWebsocket");
|
|
3432
3666
|
if (rewritten === 0 && !hasWsSaver) console.warn(`🟡 ephemeral run: no SaveImage/SaveImageWebsocket node in workflow '${this.id}' — nothing streams back`);
|
|
3433
3667
|
}
|
|
3668
|
+
const partners = partnerApiNodes(snapshot.apiJson, this.schema);
|
|
3669
|
+
let comfyOrgApiKey;
|
|
3670
|
+
if (partners.length > 0) {
|
|
3671
|
+
const data = this.host.data;
|
|
3672
|
+
const cloudKey = data.apiKey != null && this.host.base.host === COMFY_CLOUD_HOST ? data.apiKey : void 0;
|
|
3673
|
+
comfyOrgApiKey = await resolveComfyOrgApiKey([
|
|
3674
|
+
p.comfyOrgApiKey,
|
|
3675
|
+
data.comfyOrgApiKey,
|
|
3676
|
+
cloudKey
|
|
3677
|
+
]);
|
|
3678
|
+
if (comfyOrgApiKey == null) throw new ComfyOrgApiKeyMissingError(data.id, partners);
|
|
3679
|
+
}
|
|
3434
3680
|
const out = {
|
|
3435
3681
|
client_id: this.host.comfySessionId,
|
|
3436
3682
|
prompt: snapshot.apiJson,
|
|
3437
|
-
extra_data: {
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3683
|
+
extra_data: {
|
|
3684
|
+
extra_pnginfo: {
|
|
3685
|
+
workflow: snapshot.workflowJson,
|
|
3686
|
+
comfy_ts_workflow_id: this.id,
|
|
3687
|
+
comfy_ts_version: comfyts.version
|
|
3688
|
+
},
|
|
3689
|
+
...comfyOrgApiKey != null ? { api_key_comfy_org: comfyOrgApiKey } : {}
|
|
3690
|
+
}
|
|
3442
3691
|
};
|
|
3443
3692
|
const res = await this.host.fetch("/prompt", {
|
|
3444
3693
|
method: "POST",
|
|
@@ -3877,7 +4126,12 @@ function codegenSDK(opts) {
|
|
|
3877
4126
|
p(`INVALID_null: any`);
|
|
3878
4127
|
p("");
|
|
3879
4128
|
p("// named slot types: everything an input of that type accepts");
|
|
3880
|
-
|
|
4129
|
+
const slotTypeNames = new Set(slotTypes.map((t) => t.comfyType));
|
|
4130
|
+
for (const t of slotTypes) {
|
|
4131
|
+
const own = `${t.tsType} | HasSingle['${t.comfyType}'] | ((x: Producer['${t.comfyType}']) => Accepts['${t.comfyType}'])`;
|
|
4132
|
+
const anyOf = (t.comfyType.includes(",") ? t.comfyType.split(",").map((s) => s.trim()) : []).map((part) => slotTypeNames.has(part) ? `Accepts['${part}']` : `ComfyNodeOutput<'${part}'>`);
|
|
4133
|
+
p(`${escapeJSKey(t.comfyType)}: ${[own, ...anyOf].join(" | ")}`);
|
|
4134
|
+
}
|
|
3881
4135
|
p("");
|
|
3882
4136
|
p("// enum unions: literal values or an output carrying one");
|
|
3883
4137
|
for (const t of this.knownUnionByHash.values()) p(`${escapeJSKey(t.unionName)}: Union['${t.unionName}'] | ComfyNodeOutput<'${t.unionName}'>`);
|
|
@@ -4208,7 +4462,8 @@ const types = scope({
|
|
|
4208
4462
|
output_node: "boolean",
|
|
4209
4463
|
"output_tooltips?": "(string | null)[]",
|
|
4210
4464
|
"deprecated?": "boolean",
|
|
4211
|
-
"experimental?": "boolean"
|
|
4465
|
+
"experimental?": "boolean",
|
|
4466
|
+
"api_node?": "boolean"
|
|
4212
4467
|
},
|
|
4213
4468
|
ComfyInputSpecAlt1: ["ComfyInputType", "ComfyInputOpts"],
|
|
4214
4469
|
ComfyInputSpecAlt2: ["ComfyInputType"],
|
|
@@ -5168,6 +5423,12 @@ var ResilientWebSocketClient = class {
|
|
|
5168
5423
|
}
|
|
5169
5424
|
}, ms);
|
|
5170
5425
|
}
|
|
5426
|
+
/** close the socket cleanly, then reconnect as after any close: the server ends its handler first */
|
|
5427
|
+
reconnect() {
|
|
5428
|
+
if (this.permanentlyClosed || this.currentWS == null) return;
|
|
5429
|
+
this.addInfo("closing the socket to reconnect");
|
|
5430
|
+
this.currentWS.close();
|
|
5431
|
+
}
|
|
5171
5432
|
/** close and stop reconnecting (lets a script exit cleanly) */
|
|
5172
5433
|
disconnectPermanently() {
|
|
5173
5434
|
this.permanentlyClosed = true;
|
|
@@ -5189,6 +5450,7 @@ var ResilientWebSocketClient = class {
|
|
|
5189
5450
|
}
|
|
5190
5451
|
async connect() {
|
|
5191
5452
|
this.isOpen = false;
|
|
5453
|
+
this.url = this.options.url();
|
|
5192
5454
|
const prevWS = this.currentWS;
|
|
5193
5455
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
5194
5456
|
this.stopHeartbeat();
|
|
@@ -6728,7 +6990,8 @@ var DefinedWorkflow = class {
|
|
|
6728
6990
|
idMode: settings.idMode,
|
|
6729
6991
|
log: settings.log,
|
|
6730
6992
|
onProgress: settings.onProgress,
|
|
6731
|
-
onPreview: settings.onPreview
|
|
6993
|
+
onPreview: settings.onPreview,
|
|
6994
|
+
comfyOrgApiKey: settings.comfyOrgApiKey
|
|
6732
6995
|
});
|
|
6733
6996
|
this.lastExecution = execution;
|
|
6734
6997
|
return execution;
|
|
@@ -6820,10 +7083,17 @@ function diffSchemas(p) {
|
|
|
6820
7083
|
}
|
|
6821
7084
|
//#endregion
|
|
6822
7085
|
//#region src/host/ComfyHost.ts
|
|
6823
|
-
/** the host
|
|
6824
|
-
var
|
|
7086
|
+
/** the host answered a run check route, but not as ComfyUI does (no such route, another shape) */
|
|
7087
|
+
var HostRouteUnusableError = class extends Error {
|
|
6825
7088
|
constructor(..._args) {
|
|
6826
7089
|
super(..._args);
|
|
7090
|
+
this.name = "HostRouteUnusableError";
|
|
7091
|
+
}
|
|
7092
|
+
};
|
|
7093
|
+
/** the host never came up within ConnectOptions.timeoutMs */
|
|
7094
|
+
var ComfyHostUnreachableError = class extends Error {
|
|
7095
|
+
constructor(..._args2) {
|
|
7096
|
+
super(..._args2);
|
|
6827
7097
|
this.name = "ComfyHostUnreachableError";
|
|
6828
7098
|
}
|
|
6829
7099
|
};
|
|
@@ -6996,6 +7266,7 @@ var ComfyHost = class {
|
|
|
6996
7266
|
this._connectTimer = null;
|
|
6997
7267
|
this.disconnect = () => {
|
|
6998
7268
|
this.clearConnectTimer();
|
|
7269
|
+
this.stopWatchdog();
|
|
6999
7270
|
this.ws?.disconnectPermanently();
|
|
7000
7271
|
this.ws = null;
|
|
7001
7272
|
this._ready = null;
|
|
@@ -7015,6 +7286,50 @@ var ComfyHost = class {
|
|
|
7015
7286
|
});
|
|
7016
7287
|
if (!res.ok) throw new Error(`POST ${route} failed on ${this.getServerHostHTTP()}: ${res.status}`);
|
|
7017
7288
|
};
|
|
7289
|
+
this.fetchReconcileJSON_ = async (route) => {
|
|
7290
|
+
const res = await this.fetch(route);
|
|
7291
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
7292
|
+
if (res.ok && contentType.includes("json")) return res.json();
|
|
7293
|
+
res.body?.cancel();
|
|
7294
|
+
throw new HostRouteUnusableError(`GET ${route} answered ${res.status} ${contentType || "no content-type"}`);
|
|
7295
|
+
};
|
|
7296
|
+
this.fetchHistory = (promptId) => {
|
|
7297
|
+
return this.fetchReconcileJSON_(`/history/${encodeURIComponent(promptId)}`);
|
|
7298
|
+
};
|
|
7299
|
+
this.fetchQueuedPromptIds = async () => {
|
|
7300
|
+
const json = await this.fetchReconcileJSON_("/queue");
|
|
7301
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7302
|
+
for (const key of ["queue_running", "queue_pending"]) {
|
|
7303
|
+
const list = typeof json === "object" && json != null ? Reflect.get(json, key) : null;
|
|
7304
|
+
if (!Array.isArray(list)) throw new HostRouteUnusableError(`GET /queue has no ${key} list`);
|
|
7305
|
+
for (const item of list) {
|
|
7306
|
+
if (!Array.isArray(item) || typeof item[1] !== "string") throw new HostRouteUnusableError(`GET /queue: an item of ${key} is not [number, prompt_id, …]`);
|
|
7307
|
+
ids.add(item[1]);
|
|
7308
|
+
}
|
|
7309
|
+
}
|
|
7310
|
+
return ids;
|
|
7311
|
+
};
|
|
7312
|
+
this.reconcileOff = null;
|
|
7313
|
+
this.fetchQueuedPromptIdsOrNull = async () => {
|
|
7314
|
+
try {
|
|
7315
|
+
return await this.fetchQueuedPromptIds();
|
|
7316
|
+
} catch (e) {
|
|
7317
|
+
if (this.noteReconcileFailure(e)) return null;
|
|
7318
|
+
const msg = extractErrorMessage(e);
|
|
7319
|
+
if (!this._loggedQueueProblems.has(msg)) {
|
|
7320
|
+
this._loggedQueueProblems.add(msg);
|
|
7321
|
+
logError(`host '${this.data.id}': its queue did not answer (${msg}); no run is failed as lost until it does`);
|
|
7322
|
+
}
|
|
7323
|
+
return null;
|
|
7324
|
+
}
|
|
7325
|
+
};
|
|
7326
|
+
this._loggedQueueProblems = /* @__PURE__ */ new Set();
|
|
7327
|
+
this.runSilenceMs = 1e3;
|
|
7328
|
+
this.runSilenceMaxMs = 3e4;
|
|
7329
|
+
this._silenceWaitMs = null;
|
|
7330
|
+
this._lastCheckAt = 0;
|
|
7331
|
+
this._checking = false;
|
|
7332
|
+
this._watchdog = null;
|
|
7018
7333
|
this.clearQueue = () => {
|
|
7019
7334
|
return this.postJSON_("/queue", { clear: true });
|
|
7020
7335
|
};
|
|
@@ -7144,6 +7459,7 @@ var ComfyHost = class {
|
|
|
7144
7459
|
this.comfySessionId = "temp";
|
|
7145
7460
|
this._unknownBinaryFrameTypes = /* @__PURE__ */ new Set();
|
|
7146
7461
|
this._unknownWsEventTypes = /* @__PURE__ */ new Set();
|
|
7462
|
+
this._socketIsNew = false;
|
|
7147
7463
|
this.status = null;
|
|
7148
7464
|
this.lastWsMessageAt = null;
|
|
7149
7465
|
/** folder where file related to the host config will be cached */
|
|
@@ -7249,6 +7565,8 @@ var ComfyHost = class {
|
|
|
7249
7565
|
this.ws = new ResilientWebSocketClient({
|
|
7250
7566
|
onConnectOrReconnect: async () => {
|
|
7251
7567
|
logInfo(`[👢] WEBSOCKET: connected to ComfyUI host ${this.data.id}`);
|
|
7568
|
+
this._socketIsNew = true;
|
|
7569
|
+
this.reconcileRuns([...this.executions.values()], "reconnect");
|
|
7252
7570
|
if (this.shouldUseSchemaCache()) try {
|
|
7253
7571
|
await this.loadSchemaFromCache();
|
|
7254
7572
|
await this.waitForSession();
|
|
@@ -7262,7 +7580,7 @@ var ComfyHost = class {
|
|
|
7262
7580
|
this.markReady();
|
|
7263
7581
|
},
|
|
7264
7582
|
onMessage: (e) => this.onMessage(e),
|
|
7265
|
-
url: () => this.getWSUrl()
|
|
7583
|
+
url: () => this.comfySessionId === "temp" ? this.getWSUrl() : `${this.getWSUrl()}?clientId=${encodeURIComponent(this.comfySessionId)}`,
|
|
7266
7584
|
headers: () => this.authHeaders(),
|
|
7267
7585
|
onTransportDead: (e) => this.markFailed(e),
|
|
7268
7586
|
onFirstConnectFailed: (e) => this.markFailed(new ComfyHostUnreachableError(`host '${this.data.id}' is not reachable at ${this.getWSUrl()} — ${extractErrorMessage(e)}. Is ComfyUI running there ?`)),
|
|
@@ -7304,6 +7622,65 @@ var ComfyHost = class {
|
|
|
7304
7622
|
});
|
|
7305
7623
|
return this._schemaFromCache;
|
|
7306
7624
|
}
|
|
7625
|
+
/** @internal a failed run check: true when it proved the host has no usable route (the checks then
|
|
7626
|
+
* stop for good, said once), false for a passing failure the caller reports */
|
|
7627
|
+
noteReconcileFailure(e) {
|
|
7628
|
+
if (!(e instanceof Error) || e.name !== "HostRouteUnusableError") return false;
|
|
7629
|
+
if (this.reconcileOff == null) {
|
|
7630
|
+
this.reconcileOff = e.message;
|
|
7631
|
+
this.stopWatchdog();
|
|
7632
|
+
logInfo(`host '${this.data.id}': ${e.message}, not the ComfyUI shape: runs here are not checked over http, they wait for their events`);
|
|
7633
|
+
}
|
|
7634
|
+
return true;
|
|
7635
|
+
}
|
|
7636
|
+
/** @internal a new run routes its ws messages here, and the watchdog watches it */
|
|
7637
|
+
trackExecution(execution) {
|
|
7638
|
+
this.executions.set(execution.data.id, execution);
|
|
7639
|
+
if (this.ws == null || this._watchdog != null || this.reconcileOff != null) return;
|
|
7640
|
+
this._watchdog = setInterval(() => this.watchdogTick(), Math.min(250, this.runSilenceMs));
|
|
7641
|
+
this._watchdog.unref?.();
|
|
7642
|
+
}
|
|
7643
|
+
stopWatchdog() {
|
|
7644
|
+
if (this._watchdog != null) clearInterval(this._watchdog);
|
|
7645
|
+
this._watchdog = null;
|
|
7646
|
+
}
|
|
7647
|
+
/** a socket that hears no broadcast and no event for a while is deaf, or the host runs one long
|
|
7648
|
+
* quiet node: ask. A run queued behind a talking host is never asked about */
|
|
7649
|
+
watchdogTick() {
|
|
7650
|
+
if (this.executions.size === 0 || this.ws == null) return this.stopWatchdog();
|
|
7651
|
+
if (this._checking) return;
|
|
7652
|
+
const now = Date.now();
|
|
7653
|
+
const wait = this._silenceWaitMs ?? this.runSilenceMs;
|
|
7654
|
+
if (now - Math.max(this.lastWsMessageAt ?? 0, this._lastCheckAt) < wait) return;
|
|
7655
|
+
const due = [...this.executions.values()].filter((e) => !e.reconciling && now - e.lastHeardAt >= this.runSilenceMs);
|
|
7656
|
+
if (due.length === 0) return;
|
|
7657
|
+
this._checking = true;
|
|
7658
|
+
this.reconcileRuns(due, "silence").finally(() => {
|
|
7659
|
+
this._checking = false;
|
|
7660
|
+
this._lastCheckAt = Date.now();
|
|
7661
|
+
this._silenceWaitMs = Math.min(wait * 2, this.runSilenceMaxMs);
|
|
7662
|
+
});
|
|
7663
|
+
}
|
|
7664
|
+
/** @internal one queue read for all the runs, then the history of each run not in it. A run that
|
|
7665
|
+
* ends from its history while the socket looked fine means the socket hears nothing: ComfyUI removes
|
|
7666
|
+
* a session BY KEY when a socket's handler ends, so an old handler that ends after a reconnect evicts
|
|
7667
|
+
* the new socket of the same session. A clean close lets the server end that handler first */
|
|
7668
|
+
async reconcileRuns(runs, why) {
|
|
7669
|
+
if (this.reconcileOff != null) return;
|
|
7670
|
+
const todo = runs.filter((r) => !r.reconciling);
|
|
7671
|
+
if (todo.length === 0) return;
|
|
7672
|
+
for (const r of todo) r.beginReconcile(why);
|
|
7673
|
+
const queued = await this.fetchQueuedPromptIdsOrNull();
|
|
7674
|
+
if (this.reconcileOff != null) {
|
|
7675
|
+
for (const r of todo) r.reconciling = false;
|
|
7676
|
+
return;
|
|
7677
|
+
}
|
|
7678
|
+
const verdicts = await Promise.all(todo.map((r) => r.reconcile(queued)));
|
|
7679
|
+
if (why === "silence" && verdicts.includes("history") && this.ws?.isOpen === true) {
|
|
7680
|
+
logError(`host '${this.data.id}': a run ended without its end reaching the socket, which hears nothing; reconnecting`);
|
|
7681
|
+
this.ws.reconnect();
|
|
7682
|
+
}
|
|
7683
|
+
}
|
|
7307
7684
|
/** method to either execute or buffer the incoming message */
|
|
7308
7685
|
routeOrBuffer(prompt_id, msg) {
|
|
7309
7686
|
this.activePromptID = prompt_id;
|
|
@@ -7365,6 +7742,7 @@ var ComfyHost = class {
|
|
|
7365
7742
|
}
|
|
7366
7743
|
onMessage(e) {
|
|
7367
7744
|
this.lastWsMessageAt = Date.now();
|
|
7745
|
+
this._silenceWaitMs = null;
|
|
7368
7746
|
if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
|
|
7369
7747
|
if (e.data instanceof ArrayBuffer) {
|
|
7370
7748
|
if (isPreviewFrameType(binaryFrameType(e.data))) return this.onPreviewFrame(e.data);
|
|
@@ -7416,10 +7794,12 @@ var ComfyHost = class {
|
|
|
7416
7794
|
if (msg.type === "status") {
|
|
7417
7795
|
if (msg.data.sid) {
|
|
7418
7796
|
const sidChanged = msg.data.sid !== this.comfySessionId;
|
|
7797
|
+
const socketIsNew = this._socketIsNew;
|
|
7798
|
+
this._socketIsNew = false;
|
|
7419
7799
|
this.comfySessionId = msg.data.sid;
|
|
7420
7800
|
this._sessionResolve?.();
|
|
7421
7801
|
this._sessionResolve = null;
|
|
7422
|
-
if (sidChanged) {
|
|
7802
|
+
if (sidChanged || socketIsNew) {
|
|
7423
7803
|
this._unknownWsEventTypes.clear();
|
|
7424
7804
|
this._unknownBinaryFrameTypes.clear();
|
|
7425
7805
|
this.onSession?.(msg.data.sid);
|
|
@@ -8105,6 +8485,7 @@ var ComfyTS = class ComfyTS {
|
|
|
8105
8485
|
const authed = (p) => p.apiKey != null ? " (authed)" : "";
|
|
8106
8486
|
throw new Error(`host id '${data.id}' already registered ${cur == null ? "with no address" : `at ${renderHttpBase(cur)}`}${authed(existing.data)} — refusing ${incoming == null ? "the id alone" : renderHttpBase(incoming)}${authed(data)}`);
|
|
8107
8487
|
}
|
|
8488
|
+
if (data.comfyOrgApiKey != null) existing.data.comfyOrgApiKey = data.comfyOrgApiKey;
|
|
8108
8489
|
return existing;
|
|
8109
8490
|
}
|
|
8110
8491
|
const created = new ComfyHost(data);
|
|
@@ -8202,6 +8583,6 @@ function loraTag(name, strength = 1, clipStrength) {
|
|
|
8202
8583
|
*/
|
|
8203
8584
|
setDefaultComfyStorage(createMemoryStorage());
|
|
8204
8585
|
//#endregion
|
|
8205
|
-
export { AudioVar, ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_AUDIO_EXTENSIONS, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DEFAULT_VIDEO_EXTENSIONS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, MediaVar, MediaVarEmptyError, MultiChoiceVar, OptionalChoiceVar, PromptVar, ResilientWebSocketClient, SD15_SIZE_PRESETS, SeedVar, SizeVar, TextVar, ToggleVar, VideoVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resolveWidgetRoles, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v, widget };
|
|
8586
|
+
export { AudioVar, ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfyOrgApiKeyMissingError, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_AUDIO_EXTENSIONS, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DEFAULT_VIDEO_EXTENSIONS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, MediaVar, MediaVarEmptyError, MultiChoiceVar, OptionalChoiceVar, PromptVar, ResilientWebSocketClient, SD15_SIZE_PRESETS, SeedVar, SizeVar, TextVar, ToggleVar, VideoVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resolveWidgetRoles, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v, widget };
|
|
8206
8587
|
|
|
8207
8588
|
//# sourceMappingURL=web.js.map
|