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/index.cjs
CHANGED
|
@@ -134,7 +134,7 @@ function createNodeStorage() {
|
|
|
134
134
|
}
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region package.json
|
|
137
|
-
var version = "2.
|
|
137
|
+
var version = "2.24.0";
|
|
138
138
|
//#endregion
|
|
139
139
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
140
140
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -1889,13 +1889,14 @@ var ComfyNode = class ComfyNode {
|
|
|
1889
1889
|
throw new Error(`🔴 no input "${name}" on ${this.$schema.nodeKey}: cannot tell which output of the linked node to use`);
|
|
1890
1890
|
}
|
|
1891
1891
|
_getOutputForTypeOrCrash(type) {
|
|
1892
|
-
const i = this.$schema.outputs.find((i) => i.typeName
|
|
1892
|
+
const i = this.$schema.outputs.find((i) => slotTypeAccepts(type, i.typeName));
|
|
1893
|
+
if (i == null) throw new Error(`🔴 ${this.$schema.nodeKey} has no output of type ${type}: link one of its outputs by name instead`);
|
|
1893
1894
|
const val = this.outputs[i.outKey];
|
|
1894
1895
|
if (val instanceof ComfyNodeOutput) return val;
|
|
1895
1896
|
throw new Error(`Expected ${i.outKey} to be a ComfyNodeOutput`);
|
|
1896
1897
|
}
|
|
1897
1898
|
_getOutputForTypeOrNull(type) {
|
|
1898
|
-
const i = this.$schema.outputs.find((i) => i.typeName
|
|
1899
|
+
const i = this.$schema.outputs.find((i) => slotTypeAccepts(type, i.typeName));
|
|
1899
1900
|
if (i == null) return null;
|
|
1900
1901
|
const val = this.outputs[i.outKey];
|
|
1901
1902
|
if (val == null) return null;
|
|
@@ -1903,6 +1904,11 @@ var ComfyNode = class ComfyNode {
|
|
|
1903
1904
|
throw new Error(`Expected ${i.outKey} to be a ComfyNodeOutput`);
|
|
1904
1905
|
}
|
|
1905
1906
|
};
|
|
1907
|
+
/** an input typed `MESH,FILE_3D_GLB` takes an output of ANY listed type (ComfyUI's SaveGLB) */
|
|
1908
|
+
function slotTypeAccepts(inputType, outputType) {
|
|
1909
|
+
if (inputType === outputType) return true;
|
|
1910
|
+
return inputType.includes(",") && inputType.split(",").some((part) => part.trim() === outputType);
|
|
1911
|
+
}
|
|
1906
1912
|
//#endregion
|
|
1907
1913
|
//#region src/host/ComfyWorkflowBuilder.ts
|
|
1908
1914
|
var ComfyWorkflowBuilder = class {
|
|
@@ -2353,7 +2359,10 @@ const types$1 = (0, arktype.scope)({
|
|
|
2353
2359
|
Timestamp: "number",
|
|
2354
2360
|
ApiPromptInput: {
|
|
2355
2361
|
client_id: "string",
|
|
2356
|
-
extra_data: {
|
|
2362
|
+
extra_data: {
|
|
2363
|
+
extra_pnginfo: "unknown",
|
|
2364
|
+
"api_key_comfy_org?": "string"
|
|
2365
|
+
},
|
|
2357
2366
|
prompt: "unknown"
|
|
2358
2367
|
},
|
|
2359
2368
|
NodeProgress: {
|
|
@@ -2408,6 +2417,7 @@ const types$1 = (0, arktype.scope)({
|
|
|
2408
2417
|
"audio?": "ComfyImageInfo[]",
|
|
2409
2418
|
"video?": "ComfyImageInfo[]",
|
|
2410
2419
|
"gifs?": "ComfyImageInfo[]",
|
|
2420
|
+
"3d?": "ComfyImageInfo[]",
|
|
2411
2421
|
"text?": "unknown[]"
|
|
2412
2422
|
},
|
|
2413
2423
|
WsMsgExecuted: {
|
|
@@ -2769,6 +2779,88 @@ function mediaMime(filename) {
|
|
|
2769
2779
|
return MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
2770
2780
|
}
|
|
2771
2781
|
//#endregion
|
|
2782
|
+
//#region src/runner/outputs3d.ts
|
|
2783
|
+
/** ply and spz have no registered mime: the `x-` forms are what three.js and the splat viewers accept */
|
|
2784
|
+
const MODEL_3D_MIMES = {
|
|
2785
|
+
glb: "model/gltf-binary",
|
|
2786
|
+
gltf: "model/gltf+json",
|
|
2787
|
+
ply: "model/x-ply",
|
|
2788
|
+
spz: "model/x-spz",
|
|
2789
|
+
obj: "model/obj",
|
|
2790
|
+
stl: "model/stl"
|
|
2791
|
+
};
|
|
2792
|
+
function model3dMime(filename) {
|
|
2793
|
+
return MODEL_3D_MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
2794
|
+
}
|
|
2795
|
+
//#endregion
|
|
2796
|
+
//#region src/runner/historyReplay.ts
|
|
2797
|
+
const END_TYPES = /* @__PURE__ */ new Set([
|
|
2798
|
+
"execution_success",
|
|
2799
|
+
"execution_error",
|
|
2800
|
+
"execution_interrupted"
|
|
2801
|
+
]);
|
|
2802
|
+
/** a prompt's `GET /history/<id>` reply as the ws messages a client missed. Null while the host has no
|
|
2803
|
+
* entry for it: queued, running, or lost */
|
|
2804
|
+
function historyReplay(json, promptId) {
|
|
2805
|
+
const entry = field(json, promptId);
|
|
2806
|
+
if (entry == null) return null;
|
|
2807
|
+
const problems = [];
|
|
2808
|
+
const valid = (raw) => {
|
|
2809
|
+
const res = types$1.PromptRelated_WsMsg(raw);
|
|
2810
|
+
if (!(res instanceof arktype.type.errors)) return res;
|
|
2811
|
+
problems.push(`${JSON.stringify(raw).slice(0, 200)}: ${res.summary}`);
|
|
2812
|
+
return null;
|
|
2813
|
+
};
|
|
2814
|
+
const executed = [];
|
|
2815
|
+
const outputs = field(entry, "outputs");
|
|
2816
|
+
if (typeof outputs === "object" && outputs != null) for (const [node, output] of Object.entries(outputs)) {
|
|
2817
|
+
const msg = valid({
|
|
2818
|
+
type: "executed",
|
|
2819
|
+
data: {
|
|
2820
|
+
node,
|
|
2821
|
+
output,
|
|
2822
|
+
prompt_id: promptId
|
|
2823
|
+
}
|
|
2824
|
+
});
|
|
2825
|
+
if (msg != null) executed.push(msg);
|
|
2826
|
+
}
|
|
2827
|
+
const status = field(entry, "status");
|
|
2828
|
+
const list = field(status, "messages");
|
|
2829
|
+
let end = null;
|
|
2830
|
+
for (const m of Array.isArray(list) ? list : []) {
|
|
2831
|
+
if (!Array.isArray(m) || typeof m[0] !== "string" || !END_TYPES.has(m[0])) continue;
|
|
2832
|
+
end = valid({
|
|
2833
|
+
type: m[0],
|
|
2834
|
+
data: m[1]
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
const statusStr = field(status, "status_str");
|
|
2838
|
+
if (end == null && (status == null || statusStr === "success")) end = valid({
|
|
2839
|
+
type: "execution_success",
|
|
2840
|
+
data: {
|
|
2841
|
+
prompt_id: promptId,
|
|
2842
|
+
timestamp: Date.now()
|
|
2843
|
+
}
|
|
2844
|
+
});
|
|
2845
|
+
return {
|
|
2846
|
+
executed,
|
|
2847
|
+
end,
|
|
2848
|
+
problems
|
|
2849
|
+
};
|
|
2850
|
+
}
|
|
2851
|
+
function field(x, key) {
|
|
2852
|
+
if (typeof x !== "object" || x == null) return null;
|
|
2853
|
+
return Reflect.get(x, key) ?? null;
|
|
2854
|
+
}
|
|
2855
|
+
//#endregion
|
|
2856
|
+
//#region src/utils/log.ts
|
|
2857
|
+
const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
|
|
2858
|
+
const logInfo = (msg) => {
|
|
2859
|
+
if (!isQuiet()) console.log(msg);
|
|
2860
|
+
};
|
|
2861
|
+
const logError = (msg) => console.error(`[comfy-ts] 🔴 ${msg}`);
|
|
2862
|
+
const logSuccess = (msg) => console.log(`[comfy-ts] 🟢 ${msg}`);
|
|
2863
|
+
//#endregion
|
|
2772
2864
|
//#region src/runner/ComfyExecution.ts
|
|
2773
2865
|
/** paths claimed by in-flight retrievals: two same-second runs on a
|
|
2774
2866
|
* counter-resetting cloud host compute the same name before either writes.
|
|
@@ -2795,6 +2887,9 @@ var ComfyExecution = class {
|
|
|
2795
2887
|
this._resolve = resolve;
|
|
2796
2888
|
});
|
|
2797
2889
|
this.onPromptRelatedMessage = (msg) => {
|
|
2890
|
+
if (this.ended) return;
|
|
2891
|
+
this.heard();
|
|
2892
|
+
if (msg.type === "execution_success" || msg.type === "execution_error" || msg.type === "execution_interrupted") this.ended = true;
|
|
2798
2893
|
const graph = this.workflow;
|
|
2799
2894
|
if (msg.type === "binary_preview_frame") {
|
|
2800
2895
|
if (this.wsOutputNodeExecuting) this.onWsImageOutput({
|
|
@@ -2825,6 +2920,7 @@ var ComfyExecution = class {
|
|
|
2825
2920
|
this.workflow.onExecuting(msg);
|
|
2826
2921
|
};
|
|
2827
2922
|
this.onExecutionSuccess = async (_msg) => {
|
|
2923
|
+
if (this.mayHaveMissedEvents) await this.retrieveMissedOutputs();
|
|
2828
2924
|
await Promise.all(this.pendingPromises);
|
|
2829
2925
|
return this._finish({ status: "Success" });
|
|
2830
2926
|
};
|
|
@@ -2838,6 +2934,7 @@ var ComfyExecution = class {
|
|
|
2838
2934
|
};
|
|
2839
2935
|
this.onExecuted = (msg) => {
|
|
2840
2936
|
const promptNodeID = msg.data.node;
|
|
2937
|
+
this.heardExecuted.add(promptNodeID);
|
|
2841
2938
|
for (const entry of msg.data.output?.text ?? []) {
|
|
2842
2939
|
if (typeof entry !== "string") continue;
|
|
2843
2940
|
const nodeKey = this.workflow.data.apiJson?.[promptNodeID]?.class_type ?? null;
|
|
@@ -2853,7 +2950,7 @@ var ComfyExecution = class {
|
|
|
2853
2950
|
...out?.video ?? [],
|
|
2854
2951
|
...out?.gifs ?? []
|
|
2855
2952
|
].filter((f) => f.type !== "input");
|
|
2856
|
-
for (const video of listed.filter((f) => isVideoFilename(f.filename))) this.pendingPromises.push(this.retrieveFile(
|
|
2953
|
+
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) => {
|
|
2857
2954
|
console.error(`🔴 failed to retrieve ${video.filename}:`, e);
|
|
2858
2955
|
this.videoErrors.push({
|
|
2859
2956
|
video,
|
|
@@ -2868,35 +2965,118 @@ var ComfyExecution = class {
|
|
|
2868
2965
|
error: e
|
|
2869
2966
|
});
|
|
2870
2967
|
}));
|
|
2871
|
-
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveFile(
|
|
2968
|
+
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) => {
|
|
2872
2969
|
console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
|
|
2873
2970
|
this.audioErrors.push({
|
|
2874
2971
|
audio,
|
|
2875
2972
|
error: e
|
|
2876
2973
|
});
|
|
2877
2974
|
}));
|
|
2975
|
+
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({
|
|
2976
|
+
...o,
|
|
2977
|
+
format: extensionOf(o.filename)
|
|
2978
|
+
}), (e) => {
|
|
2979
|
+
console.error(`🔴 failed to retrieve ${model3d.filename}:`, e);
|
|
2980
|
+
this.models3dErrors.push({
|
|
2981
|
+
model3d,
|
|
2982
|
+
error: e
|
|
2983
|
+
});
|
|
2984
|
+
}));
|
|
2878
2985
|
};
|
|
2879
2986
|
this.pendingPromises = [];
|
|
2987
|
+
this.ended = false;
|
|
2988
|
+
this.heardExecuted = /* @__PURE__ */ new Set();
|
|
2989
|
+
this.mayHaveMissedEvents = false;
|
|
2990
|
+
this.historyRetry = {
|
|
2991
|
+
tries: 5,
|
|
2992
|
+
ms: 400
|
|
2993
|
+
};
|
|
2994
|
+
this.retrieveMissedOutputs = async () => {
|
|
2995
|
+
const id = this.data.id;
|
|
2996
|
+
for (let i = 0; i < this.historyRetry.tries; i++) {
|
|
2997
|
+
if (this.host.reconcileOff != null) return;
|
|
2998
|
+
if (i > 0) await new Promise((r) => setTimeout(r, this.historyRetry.ms));
|
|
2999
|
+
try {
|
|
3000
|
+
const replay = historyReplay(await this.host.fetchHistory(id), id);
|
|
3001
|
+
if (replay == null) continue;
|
|
3002
|
+
return this.replayUnheardOutputs(replay);
|
|
3003
|
+
} catch (e) {
|
|
3004
|
+
if (this.host.noteReconcileFailure(e)) return;
|
|
3005
|
+
return logError(`run ${id}: its history did not answer (${extractErrorMessage(e)}); an output sent while the socket was down may be missing`);
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
logError(`run ${id}: no history entry after its end; an output sent while the socket was down may be missing`);
|
|
3009
|
+
};
|
|
3010
|
+
this.lastHeardAt = Date.now();
|
|
3011
|
+
this.reconciling = false;
|
|
3012
|
+
this.loggedReconcileProblems = /* @__PURE__ */ new Set();
|
|
3013
|
+
this.reconcile = async (queued) => {
|
|
3014
|
+
const id = this.data.id;
|
|
3015
|
+
const hostId = this.host.data.id;
|
|
3016
|
+
try {
|
|
3017
|
+
if (this.ended || queued?.has(id) === true) return "waiting";
|
|
3018
|
+
let replay;
|
|
3019
|
+
try {
|
|
3020
|
+
replay = historyReplay(await this.host.fetchHistory(id), id);
|
|
3021
|
+
} catch (e) {
|
|
3022
|
+
if (!this.host.noteReconcileFailure(e)) this.logReconcileOnce(`the history of host '${hostId}' did not answer (${extractErrorMessage(e)}); waiting for its events`);
|
|
3023
|
+
return "waiting";
|
|
3024
|
+
}
|
|
3025
|
+
if (this.ended) return "waiting";
|
|
3026
|
+
if (replay == null) {
|
|
3027
|
+
if (queued == null) return "waiting";
|
|
3028
|
+
const reason = `host '${hostId}' has it neither in its queue nor in its history (cancelled, or the host restarted)`;
|
|
3029
|
+
logError(`run ${id}: ${reason}; the run fails`);
|
|
3030
|
+
this.ended = true;
|
|
3031
|
+
await this._finish({
|
|
3032
|
+
status: "Failure",
|
|
3033
|
+
error: null,
|
|
3034
|
+
reason
|
|
3035
|
+
});
|
|
3036
|
+
return "lost";
|
|
3037
|
+
}
|
|
3038
|
+
const sinceHeard = Date.now() - this.lastHeardAt;
|
|
3039
|
+
if (!this.mayHaveMissedEvents && this.sendsWsFrames && sinceHeard < this.host.runSilenceMaxMs) return "waiting";
|
|
3040
|
+
logInfo(`run ${id}: ended on host '${hostId}' without its end reaching the socket, finishing from its history`);
|
|
3041
|
+
for (const p of replay.problems) logError(`run ${id}: a history entry does not match the ws schemas, skipped: ${p}`);
|
|
3042
|
+
this.replayUnheardOutputs(replay);
|
|
3043
|
+
if (this.ephemeral) logError(`run ${id}: SaveImageWebsocket frames sent while the socket did not hear are lost (they never reach the server disk)`);
|
|
3044
|
+
if (replay.end != null) {
|
|
3045
|
+
this.onPromptRelatedMessage(replay.end);
|
|
3046
|
+
return "history";
|
|
3047
|
+
}
|
|
3048
|
+
const reason = `its history entry on host '${hostId}' carries no end message`;
|
|
3049
|
+
logError(`run ${id}: ${reason}; the run fails`);
|
|
3050
|
+
this.ended = true;
|
|
3051
|
+
await this._finish({
|
|
3052
|
+
status: "Failure",
|
|
3053
|
+
error: null,
|
|
3054
|
+
reason
|
|
3055
|
+
});
|
|
3056
|
+
return "history";
|
|
3057
|
+
} finally {
|
|
3058
|
+
this.reconciling = false;
|
|
3059
|
+
}
|
|
3060
|
+
};
|
|
2880
3061
|
this.audioErrors = [];
|
|
2881
3062
|
this.audios = [];
|
|
2882
3063
|
this.videoErrors = [];
|
|
2883
3064
|
this.videos = [];
|
|
2884
|
-
this.
|
|
3065
|
+
this.models3dErrors = [];
|
|
3066
|
+
this.models3d = [];
|
|
3067
|
+
this.retrieveFile = async (info, promptNodeID, mime) => {
|
|
2885
3068
|
const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
|
|
2886
3069
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2887
|
-
const
|
|
2888
|
-
const list = kind === "audio" ? this.audios : this.videos;
|
|
3070
|
+
const tags = this.tagsOf(promptNodeID);
|
|
2889
3071
|
const sf = this.save;
|
|
2890
|
-
if (sf == null) {
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
return;
|
|
2899
|
-
}
|
|
3072
|
+
if (sf == null) return {
|
|
3073
|
+
nodeId: promptNodeID,
|
|
3074
|
+
filename: info.filename,
|
|
3075
|
+
mime,
|
|
3076
|
+
bytes,
|
|
3077
|
+
absPath: null,
|
|
3078
|
+
tags
|
|
3079
|
+
};
|
|
2900
3080
|
const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs["filename_prefix"];
|
|
2901
3081
|
const written = await this.encodeAndWrite({
|
|
2902
3082
|
bytes,
|
|
@@ -2908,13 +3088,14 @@ var ComfyExecution = class {
|
|
|
2908
3088
|
subfolder: info.subfolder,
|
|
2909
3089
|
filename: info.filename
|
|
2910
3090
|
});
|
|
2911
|
-
|
|
3091
|
+
return {
|
|
2912
3092
|
nodeId: promptNodeID,
|
|
2913
3093
|
filename: info.filename,
|
|
2914
3094
|
mime,
|
|
2915
3095
|
bytes,
|
|
2916
|
-
absPath: written.path
|
|
2917
|
-
|
|
3096
|
+
absPath: written.path,
|
|
3097
|
+
tags
|
|
3098
|
+
};
|
|
2918
3099
|
};
|
|
2919
3100
|
this.imageErrors = [];
|
|
2920
3101
|
this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
|
|
@@ -2992,6 +3173,7 @@ var ComfyExecution = class {
|
|
|
2992
3173
|
};
|
|
2993
3174
|
};
|
|
2994
3175
|
this.onWsImageOutput = (p) => {
|
|
3176
|
+
this.heard();
|
|
2995
3177
|
const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null;
|
|
2996
3178
|
this.pendingPromises.push(this.storeWsImage(p, promptNodeID).catch((e) => {
|
|
2997
3179
|
console.error(`🔴 failed to store a SaveImageWebsocket output:`, e);
|
|
@@ -3054,7 +3236,7 @@ var ComfyExecution = class {
|
|
|
3054
3236
|
this.onProgress = init.onProgress ?? null;
|
|
3055
3237
|
this.onPreview = init.onPreview ?? null;
|
|
3056
3238
|
this.logProgress = init.logProgress ?? false;
|
|
3057
|
-
this.host.
|
|
3239
|
+
this.host.trackExecution(this);
|
|
3058
3240
|
this.onCreate();
|
|
3059
3241
|
}
|
|
3060
3242
|
get progress() {
|
|
@@ -3090,6 +3272,7 @@ var ComfyExecution = class {
|
|
|
3090
3272
|
const outputs = [`${this.images.length} image(s)`];
|
|
3091
3273
|
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
|
|
3092
3274
|
if (this.videos.length > 0) outputs.push(`${this.videos.length} video(s)`);
|
|
3275
|
+
if (this.models3d.length > 0) outputs.push(`${this.models3d.length} 3d model(s)`);
|
|
3093
3276
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
|
|
3094
3277
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
|
|
3095
3278
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
@@ -3118,13 +3301,39 @@ var ComfyExecution = class {
|
|
|
3118
3301
|
get status() {
|
|
3119
3302
|
return this.data.status ?? "New";
|
|
3120
3303
|
}
|
|
3304
|
+
replayUnheardOutputs(replay) {
|
|
3305
|
+
for (const msg of replay.executed) if (msg.type === "executed" && !this.heardExecuted.has(msg.data.node)) this.onExecuted(msg);
|
|
3306
|
+
}
|
|
3307
|
+
heard() {
|
|
3308
|
+
this.lastHeardAt = Date.now();
|
|
3309
|
+
}
|
|
3310
|
+
logReconcileOnce(msg) {
|
|
3311
|
+
if (this.loggedReconcileProblems.has(msg)) return;
|
|
3312
|
+
this.loggedReconcileProblems.add(msg);
|
|
3313
|
+
logError(`run ${this.data.id}: ${msg}`);
|
|
3314
|
+
}
|
|
3315
|
+
/** @internal called before the host reads its queue. After a reconnect the run may have lost events,
|
|
3316
|
+
* so its end reads /history for them; the flag is set before any await, so a live end that lands
|
|
3317
|
+
* during the reads still looks. A check for silence alone does not set it: a quiet run lost nothing */
|
|
3318
|
+
beginReconcile(why) {
|
|
3319
|
+
this.reconciling = true;
|
|
3320
|
+
if (why === "reconnect") this.mayHaveMissedEvents = true;
|
|
3321
|
+
}
|
|
3121
3322
|
/** accumulate an output on the prompt; tags from node metadata ride along */
|
|
3122
3323
|
pushImage(img, promptNodeID) {
|
|
3123
|
-
|
|
3124
|
-
if (promptMeta?.tag) img.tags.push(promptMeta.tag);
|
|
3125
|
-
if (promptMeta?.tags) img.tags.push(...promptMeta.tags);
|
|
3324
|
+
img.tags.push(...this.tagsOf(promptNodeID));
|
|
3126
3325
|
this.images.push(img);
|
|
3127
3326
|
}
|
|
3327
|
+
/** the tags an output node was built with (`{ tag }` / `{ tags }` metadata) */
|
|
3328
|
+
tagsOf(promptNodeID) {
|
|
3329
|
+
const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null;
|
|
3330
|
+
return [...promptMeta?.tag ? [promptMeta.tag] : [], ...promptMeta?.tags ?? []];
|
|
3331
|
+
}
|
|
3332
|
+
/** the sent graph saves through SaveImageWebsocket: those outputs exist only as ws frames */
|
|
3333
|
+
get sendsWsFrames() {
|
|
3334
|
+
const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson;
|
|
3335
|
+
return Object.values(apiJson).some((n) => n?.class_type === "SaveImageWebsocket");
|
|
3336
|
+
}
|
|
3128
3337
|
/** true while the currently executing node is a SaveImageWebsocket in the
|
|
3129
3338
|
* SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
|
|
3130
3339
|
* live graph may still say SaveImage) — binary frames are then OUTPUTS */
|
|
@@ -3136,6 +3345,7 @@ var ComfyExecution = class {
|
|
|
3136
3345
|
/** @internal a live preview frame of this run; never an output (the host routes ws saver frames
|
|
3137
3346
|
* to onWsImageOutput before they get here) */
|
|
3138
3347
|
onPreviewFrame(p) {
|
|
3348
|
+
this.heard();
|
|
3139
3349
|
const listener = this.onPreview;
|
|
3140
3350
|
if (listener == null) return;
|
|
3141
3351
|
const current = this.workflow.currentExecutingNode;
|
|
@@ -3157,6 +3367,7 @@ var ComfyExecution = class {
|
|
|
3157
3367
|
}
|
|
3158
3368
|
/** @internal a live-text frame for one node */
|
|
3159
3369
|
onProgressText(p) {
|
|
3370
|
+
this.heard();
|
|
3160
3371
|
this.progressTexts.set(p.nodeId, p.text);
|
|
3161
3372
|
this.progressText = p.text;
|
|
3162
3373
|
this.emitProgress();
|
|
@@ -3170,6 +3381,35 @@ var ComfyExecution = class {
|
|
|
3170
3381
|
}
|
|
3171
3382
|
};
|
|
3172
3383
|
//#endregion
|
|
3384
|
+
//#region src/runner/comfyOrgApiKey.ts
|
|
3385
|
+
/** the prompt holds a paid partner node and no Comfy account key was set */
|
|
3386
|
+
var ComfyOrgApiKeyMissingError = class extends Error {
|
|
3387
|
+
constructor(hostId, nodes) {
|
|
3388
|
+
const list = nodes.map((n) => `${n.classType} #${n.id}`).join(", ");
|
|
3389
|
+
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.`);
|
|
3390
|
+
this.hostId = hostId;
|
|
3391
|
+
this.nodes = nodes;
|
|
3392
|
+
this.name = "ComfyOrgApiKeyMissingError";
|
|
3393
|
+
}
|
|
3394
|
+
};
|
|
3395
|
+
/** the nodes of a prompt whose schema says `api_node: true` */
|
|
3396
|
+
const partnerApiNodes = (apiJson, schema) => {
|
|
3397
|
+
const out = [];
|
|
3398
|
+
for (const [id, node] of Object.entries(apiJson)) if (schema.nodesByNameInComfy[node.class_type]?.raw.api_node === true) out.push({
|
|
3399
|
+
id,
|
|
3400
|
+
classType: node.class_type
|
|
3401
|
+
});
|
|
3402
|
+
return out;
|
|
3403
|
+
};
|
|
3404
|
+
/** the first source set wins; an empty string counts as unset */
|
|
3405
|
+
const resolveComfyOrgApiKey = async (sources) => {
|
|
3406
|
+
for (const src of sources) {
|
|
3407
|
+
if (src == null) continue;
|
|
3408
|
+
const key = typeof src === "string" ? src : await src();
|
|
3409
|
+
if (key != null && key !== "") return key;
|
|
3410
|
+
}
|
|
3411
|
+
};
|
|
3412
|
+
//#endregion
|
|
3173
3413
|
//#region src/runner/ephemeral.ts
|
|
3174
3414
|
/**
|
|
3175
3415
|
* the `ephemeral: true` rewrite (architecture.md item 14): every SaveImage
|
|
@@ -3217,14 +3457,6 @@ function styler(open = "", close = "") {
|
|
|
3217
3457
|
}
|
|
3218
3458
|
const ansi = styler();
|
|
3219
3459
|
//#endregion
|
|
3220
|
-
//#region src/utils/log.ts
|
|
3221
|
-
const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
|
|
3222
|
-
const logInfo = (msg) => {
|
|
3223
|
-
if (!isQuiet()) console.log(msg);
|
|
3224
|
-
};
|
|
3225
|
-
const logError = (msg) => console.error(`[comfy-ts] 🔴 ${msg}`);
|
|
3226
|
-
const logSuccess = (msg) => console.log(`[comfy-ts] 🟢 ${msg}`);
|
|
3227
|
-
//#endregion
|
|
3228
3460
|
//#region src/utils/printArkResultInConsole.ts
|
|
3229
3461
|
const MAX_PRINTED_ERRORS = 10;
|
|
3230
3462
|
function printArkResultInConsole(res) {
|
|
@@ -3337,6 +3569,8 @@ function comfyWorkflowAutoLayout(p) {
|
|
|
3337
3569
|
}
|
|
3338
3570
|
//#endregion
|
|
3339
3571
|
//#region src/runner/ComfyWorkflow.ts
|
|
3572
|
+
/** a Comfy Cloud host's X-API-Key is a platform.comfy.org key, the one partner nodes bill to */
|
|
3573
|
+
const COMFY_CLOUD_HOST = "cloud.comfy.org";
|
|
3340
3574
|
const asComfyWorkflowID = (x) => x;
|
|
3341
3575
|
var ComfyWorkflow = class {
|
|
3342
3576
|
constructor(host, data) {
|
|
@@ -3467,14 +3701,29 @@ var ComfyWorkflow = class {
|
|
|
3467
3701
|
const hasWsSaver = Object.values(snapshot.apiJson).some((n) => n.class_type === "SaveImageWebsocket");
|
|
3468
3702
|
if (rewritten === 0 && !hasWsSaver) console.warn(`🟡 ephemeral run: no SaveImage/SaveImageWebsocket node in workflow '${this.id}' — nothing streams back`);
|
|
3469
3703
|
}
|
|
3704
|
+
const partners = partnerApiNodes(snapshot.apiJson, this.schema);
|
|
3705
|
+
let comfyOrgApiKey;
|
|
3706
|
+
if (partners.length > 0) {
|
|
3707
|
+
const data = this.host.data;
|
|
3708
|
+
const cloudKey = data.apiKey != null && this.host.base.host === COMFY_CLOUD_HOST ? data.apiKey : void 0;
|
|
3709
|
+
comfyOrgApiKey = await resolveComfyOrgApiKey([
|
|
3710
|
+
p.comfyOrgApiKey,
|
|
3711
|
+
data.comfyOrgApiKey,
|
|
3712
|
+
cloudKey
|
|
3713
|
+
]);
|
|
3714
|
+
if (comfyOrgApiKey == null) throw new ComfyOrgApiKeyMissingError(data.id, partners);
|
|
3715
|
+
}
|
|
3470
3716
|
const out = {
|
|
3471
3717
|
client_id: this.host.comfySessionId,
|
|
3472
3718
|
prompt: snapshot.apiJson,
|
|
3473
|
-
extra_data: {
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3719
|
+
extra_data: {
|
|
3720
|
+
extra_pnginfo: {
|
|
3721
|
+
workflow: snapshot.workflowJson,
|
|
3722
|
+
comfy_ts_workflow_id: this.id,
|
|
3723
|
+
comfy_ts_version: comfyts.version
|
|
3724
|
+
},
|
|
3725
|
+
...comfyOrgApiKey != null ? { api_key_comfy_org: comfyOrgApiKey } : {}
|
|
3726
|
+
}
|
|
3478
3727
|
};
|
|
3479
3728
|
const res = await this.host.fetch("/prompt", {
|
|
3480
3729
|
method: "POST",
|
|
@@ -3913,7 +4162,12 @@ function codegenSDK(opts) {
|
|
|
3913
4162
|
p(`INVALID_null: any`);
|
|
3914
4163
|
p("");
|
|
3915
4164
|
p("// named slot types: everything an input of that type accepts");
|
|
3916
|
-
|
|
4165
|
+
const slotTypeNames = new Set(slotTypes.map((t) => t.comfyType));
|
|
4166
|
+
for (const t of slotTypes) {
|
|
4167
|
+
const own = `${t.tsType} | HasSingle['${t.comfyType}'] | ((x: Producer['${t.comfyType}']) => Accepts['${t.comfyType}'])`;
|
|
4168
|
+
const anyOf = (t.comfyType.includes(",") ? t.comfyType.split(",").map((s) => s.trim()) : []).map((part) => slotTypeNames.has(part) ? `Accepts['${part}']` : `ComfyNodeOutput<'${part}'>`);
|
|
4169
|
+
p(`${escapeJSKey(t.comfyType)}: ${[own, ...anyOf].join(" | ")}`);
|
|
4170
|
+
}
|
|
3917
4171
|
p("");
|
|
3918
4172
|
p("// enum unions: literal values or an output carrying one");
|
|
3919
4173
|
for (const t of this.knownUnionByHash.values()) p(`${escapeJSKey(t.unionName)}: Union['${t.unionName}'] | ComfyNodeOutput<'${t.unionName}'>`);
|
|
@@ -4244,7 +4498,8 @@ const types = (0, arktype.scope)({
|
|
|
4244
4498
|
output_node: "boolean",
|
|
4245
4499
|
"output_tooltips?": "(string | null)[]",
|
|
4246
4500
|
"deprecated?": "boolean",
|
|
4247
|
-
"experimental?": "boolean"
|
|
4501
|
+
"experimental?": "boolean",
|
|
4502
|
+
"api_node?": "boolean"
|
|
4248
4503
|
},
|
|
4249
4504
|
ComfyInputSpecAlt1: ["ComfyInputType", "ComfyInputOpts"],
|
|
4250
4505
|
ComfyInputSpecAlt2: ["ComfyInputType"],
|
|
@@ -5204,6 +5459,12 @@ var ResilientWebSocketClient = class {
|
|
|
5204
5459
|
}
|
|
5205
5460
|
}, ms);
|
|
5206
5461
|
}
|
|
5462
|
+
/** close the socket cleanly, then reconnect as after any close: the server ends its handler first */
|
|
5463
|
+
reconnect() {
|
|
5464
|
+
if (this.permanentlyClosed || this.currentWS == null) return;
|
|
5465
|
+
this.addInfo("closing the socket to reconnect");
|
|
5466
|
+
this.currentWS.close();
|
|
5467
|
+
}
|
|
5207
5468
|
/** close and stop reconnecting (lets a script exit cleanly) */
|
|
5208
5469
|
disconnectPermanently() {
|
|
5209
5470
|
this.permanentlyClosed = true;
|
|
@@ -5225,6 +5486,7 @@ var ResilientWebSocketClient = class {
|
|
|
5225
5486
|
}
|
|
5226
5487
|
async connect() {
|
|
5227
5488
|
this.isOpen = false;
|
|
5489
|
+
this.url = this.options.url();
|
|
5228
5490
|
const prevWS = this.currentWS;
|
|
5229
5491
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
5230
5492
|
this.stopHeartbeat();
|
|
@@ -6764,7 +7026,8 @@ var DefinedWorkflow = class {
|
|
|
6764
7026
|
idMode: settings.idMode,
|
|
6765
7027
|
log: settings.log,
|
|
6766
7028
|
onProgress: settings.onProgress,
|
|
6767
|
-
onPreview: settings.onPreview
|
|
7029
|
+
onPreview: settings.onPreview,
|
|
7030
|
+
comfyOrgApiKey: settings.comfyOrgApiKey
|
|
6768
7031
|
});
|
|
6769
7032
|
this.lastExecution = execution;
|
|
6770
7033
|
return execution;
|
|
@@ -6856,10 +7119,17 @@ function diffSchemas(p) {
|
|
|
6856
7119
|
}
|
|
6857
7120
|
//#endregion
|
|
6858
7121
|
//#region src/host/ComfyHost.ts
|
|
6859
|
-
/** the host
|
|
6860
|
-
var
|
|
7122
|
+
/** the host answered a run check route, but not as ComfyUI does (no such route, another shape) */
|
|
7123
|
+
var HostRouteUnusableError = class extends Error {
|
|
6861
7124
|
constructor(..._args) {
|
|
6862
7125
|
super(..._args);
|
|
7126
|
+
this.name = "HostRouteUnusableError";
|
|
7127
|
+
}
|
|
7128
|
+
};
|
|
7129
|
+
/** the host never came up within ConnectOptions.timeoutMs */
|
|
7130
|
+
var ComfyHostUnreachableError = class extends Error {
|
|
7131
|
+
constructor(..._args2) {
|
|
7132
|
+
super(..._args2);
|
|
6863
7133
|
this.name = "ComfyHostUnreachableError";
|
|
6864
7134
|
}
|
|
6865
7135
|
};
|
|
@@ -7032,6 +7302,7 @@ var ComfyHost = class {
|
|
|
7032
7302
|
this._connectTimer = null;
|
|
7033
7303
|
this.disconnect = () => {
|
|
7034
7304
|
this.clearConnectTimer();
|
|
7305
|
+
this.stopWatchdog();
|
|
7035
7306
|
this.ws?.disconnectPermanently();
|
|
7036
7307
|
this.ws = null;
|
|
7037
7308
|
this._ready = null;
|
|
@@ -7051,6 +7322,50 @@ var ComfyHost = class {
|
|
|
7051
7322
|
});
|
|
7052
7323
|
if (!res.ok) throw new Error(`POST ${route} failed on ${this.getServerHostHTTP()}: ${res.status}`);
|
|
7053
7324
|
};
|
|
7325
|
+
this.fetchReconcileJSON_ = async (route) => {
|
|
7326
|
+
const res = await this.fetch(route);
|
|
7327
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
7328
|
+
if (res.ok && contentType.includes("json")) return res.json();
|
|
7329
|
+
res.body?.cancel();
|
|
7330
|
+
throw new HostRouteUnusableError(`GET ${route} answered ${res.status} ${contentType || "no content-type"}`);
|
|
7331
|
+
};
|
|
7332
|
+
this.fetchHistory = (promptId) => {
|
|
7333
|
+
return this.fetchReconcileJSON_(`/history/${encodeURIComponent(promptId)}`);
|
|
7334
|
+
};
|
|
7335
|
+
this.fetchQueuedPromptIds = async () => {
|
|
7336
|
+
const json = await this.fetchReconcileJSON_("/queue");
|
|
7337
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7338
|
+
for (const key of ["queue_running", "queue_pending"]) {
|
|
7339
|
+
const list = typeof json === "object" && json != null ? Reflect.get(json, key) : null;
|
|
7340
|
+
if (!Array.isArray(list)) throw new HostRouteUnusableError(`GET /queue has no ${key} list`);
|
|
7341
|
+
for (const item of list) {
|
|
7342
|
+
if (!Array.isArray(item) || typeof item[1] !== "string") throw new HostRouteUnusableError(`GET /queue: an item of ${key} is not [number, prompt_id, …]`);
|
|
7343
|
+
ids.add(item[1]);
|
|
7344
|
+
}
|
|
7345
|
+
}
|
|
7346
|
+
return ids;
|
|
7347
|
+
};
|
|
7348
|
+
this.reconcileOff = null;
|
|
7349
|
+
this.fetchQueuedPromptIdsOrNull = async () => {
|
|
7350
|
+
try {
|
|
7351
|
+
return await this.fetchQueuedPromptIds();
|
|
7352
|
+
} catch (e) {
|
|
7353
|
+
if (this.noteReconcileFailure(e)) return null;
|
|
7354
|
+
const msg = extractErrorMessage(e);
|
|
7355
|
+
if (!this._loggedQueueProblems.has(msg)) {
|
|
7356
|
+
this._loggedQueueProblems.add(msg);
|
|
7357
|
+
logError(`host '${this.data.id}': its queue did not answer (${msg}); no run is failed as lost until it does`);
|
|
7358
|
+
}
|
|
7359
|
+
return null;
|
|
7360
|
+
}
|
|
7361
|
+
};
|
|
7362
|
+
this._loggedQueueProblems = /* @__PURE__ */ new Set();
|
|
7363
|
+
this.runSilenceMs = 1e3;
|
|
7364
|
+
this.runSilenceMaxMs = 3e4;
|
|
7365
|
+
this._silenceWaitMs = null;
|
|
7366
|
+
this._lastCheckAt = 0;
|
|
7367
|
+
this._checking = false;
|
|
7368
|
+
this._watchdog = null;
|
|
7054
7369
|
this.clearQueue = () => {
|
|
7055
7370
|
return this.postJSON_("/queue", { clear: true });
|
|
7056
7371
|
};
|
|
@@ -7180,6 +7495,7 @@ var ComfyHost = class {
|
|
|
7180
7495
|
this.comfySessionId = "temp";
|
|
7181
7496
|
this._unknownBinaryFrameTypes = /* @__PURE__ */ new Set();
|
|
7182
7497
|
this._unknownWsEventTypes = /* @__PURE__ */ new Set();
|
|
7498
|
+
this._socketIsNew = false;
|
|
7183
7499
|
this.status = null;
|
|
7184
7500
|
this.lastWsMessageAt = null;
|
|
7185
7501
|
/** folder where file related to the host config will be cached */
|
|
@@ -7285,6 +7601,8 @@ var ComfyHost = class {
|
|
|
7285
7601
|
this.ws = new ResilientWebSocketClient({
|
|
7286
7602
|
onConnectOrReconnect: async () => {
|
|
7287
7603
|
logInfo(`[👢] WEBSOCKET: connected to ComfyUI host ${this.data.id}`);
|
|
7604
|
+
this._socketIsNew = true;
|
|
7605
|
+
this.reconcileRuns([...this.executions.values()], "reconnect");
|
|
7288
7606
|
if (this.shouldUseSchemaCache()) try {
|
|
7289
7607
|
await this.loadSchemaFromCache();
|
|
7290
7608
|
await this.waitForSession();
|
|
@@ -7298,7 +7616,7 @@ var ComfyHost = class {
|
|
|
7298
7616
|
this.markReady();
|
|
7299
7617
|
},
|
|
7300
7618
|
onMessage: (e) => this.onMessage(e),
|
|
7301
|
-
url: () => this.getWSUrl()
|
|
7619
|
+
url: () => this.comfySessionId === "temp" ? this.getWSUrl() : `${this.getWSUrl()}?clientId=${encodeURIComponent(this.comfySessionId)}`,
|
|
7302
7620
|
headers: () => this.authHeaders(),
|
|
7303
7621
|
onTransportDead: (e) => this.markFailed(e),
|
|
7304
7622
|
onFirstConnectFailed: (e) => this.markFailed(new ComfyHostUnreachableError(`host '${this.data.id}' is not reachable at ${this.getWSUrl()} — ${extractErrorMessage(e)}. Is ComfyUI running there ?`)),
|
|
@@ -7340,6 +7658,65 @@ var ComfyHost = class {
|
|
|
7340
7658
|
});
|
|
7341
7659
|
return this._schemaFromCache;
|
|
7342
7660
|
}
|
|
7661
|
+
/** @internal a failed run check: true when it proved the host has no usable route (the checks then
|
|
7662
|
+
* stop for good, said once), false for a passing failure the caller reports */
|
|
7663
|
+
noteReconcileFailure(e) {
|
|
7664
|
+
if (!(e instanceof Error) || e.name !== "HostRouteUnusableError") return false;
|
|
7665
|
+
if (this.reconcileOff == null) {
|
|
7666
|
+
this.reconcileOff = e.message;
|
|
7667
|
+
this.stopWatchdog();
|
|
7668
|
+
logInfo(`host '${this.data.id}': ${e.message}, not the ComfyUI shape: runs here are not checked over http, they wait for their events`);
|
|
7669
|
+
}
|
|
7670
|
+
return true;
|
|
7671
|
+
}
|
|
7672
|
+
/** @internal a new run routes its ws messages here, and the watchdog watches it */
|
|
7673
|
+
trackExecution(execution) {
|
|
7674
|
+
this.executions.set(execution.data.id, execution);
|
|
7675
|
+
if (this.ws == null || this._watchdog != null || this.reconcileOff != null) return;
|
|
7676
|
+
this._watchdog = setInterval(() => this.watchdogTick(), Math.min(250, this.runSilenceMs));
|
|
7677
|
+
this._watchdog.unref?.();
|
|
7678
|
+
}
|
|
7679
|
+
stopWatchdog() {
|
|
7680
|
+
if (this._watchdog != null) clearInterval(this._watchdog);
|
|
7681
|
+
this._watchdog = null;
|
|
7682
|
+
}
|
|
7683
|
+
/** a socket that hears no broadcast and no event for a while is deaf, or the host runs one long
|
|
7684
|
+
* quiet node: ask. A run queued behind a talking host is never asked about */
|
|
7685
|
+
watchdogTick() {
|
|
7686
|
+
if (this.executions.size === 0 || this.ws == null) return this.stopWatchdog();
|
|
7687
|
+
if (this._checking) return;
|
|
7688
|
+
const now = Date.now();
|
|
7689
|
+
const wait = this._silenceWaitMs ?? this.runSilenceMs;
|
|
7690
|
+
if (now - Math.max(this.lastWsMessageAt ?? 0, this._lastCheckAt) < wait) return;
|
|
7691
|
+
const due = [...this.executions.values()].filter((e) => !e.reconciling && now - e.lastHeardAt >= this.runSilenceMs);
|
|
7692
|
+
if (due.length === 0) return;
|
|
7693
|
+
this._checking = true;
|
|
7694
|
+
this.reconcileRuns(due, "silence").finally(() => {
|
|
7695
|
+
this._checking = false;
|
|
7696
|
+
this._lastCheckAt = Date.now();
|
|
7697
|
+
this._silenceWaitMs = Math.min(wait * 2, this.runSilenceMaxMs);
|
|
7698
|
+
});
|
|
7699
|
+
}
|
|
7700
|
+
/** @internal one queue read for all the runs, then the history of each run not in it. A run that
|
|
7701
|
+
* ends from its history while the socket looked fine means the socket hears nothing: ComfyUI removes
|
|
7702
|
+
* a session BY KEY when a socket's handler ends, so an old handler that ends after a reconnect evicts
|
|
7703
|
+
* the new socket of the same session. A clean close lets the server end that handler first */
|
|
7704
|
+
async reconcileRuns(runs, why) {
|
|
7705
|
+
if (this.reconcileOff != null) return;
|
|
7706
|
+
const todo = runs.filter((r) => !r.reconciling);
|
|
7707
|
+
if (todo.length === 0) return;
|
|
7708
|
+
for (const r of todo) r.beginReconcile(why);
|
|
7709
|
+
const queued = await this.fetchQueuedPromptIdsOrNull();
|
|
7710
|
+
if (this.reconcileOff != null) {
|
|
7711
|
+
for (const r of todo) r.reconciling = false;
|
|
7712
|
+
return;
|
|
7713
|
+
}
|
|
7714
|
+
const verdicts = await Promise.all(todo.map((r) => r.reconcile(queued)));
|
|
7715
|
+
if (why === "silence" && verdicts.includes("history") && this.ws?.isOpen === true) {
|
|
7716
|
+
logError(`host '${this.data.id}': a run ended without its end reaching the socket, which hears nothing; reconnecting`);
|
|
7717
|
+
this.ws.reconnect();
|
|
7718
|
+
}
|
|
7719
|
+
}
|
|
7343
7720
|
/** method to either execute or buffer the incoming message */
|
|
7344
7721
|
routeOrBuffer(prompt_id, msg) {
|
|
7345
7722
|
this.activePromptID = prompt_id;
|
|
@@ -7401,6 +7778,7 @@ var ComfyHost = class {
|
|
|
7401
7778
|
}
|
|
7402
7779
|
onMessage(e) {
|
|
7403
7780
|
this.lastWsMessageAt = Date.now();
|
|
7781
|
+
this._silenceWaitMs = null;
|
|
7404
7782
|
if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
|
|
7405
7783
|
if (e.data instanceof ArrayBuffer) {
|
|
7406
7784
|
if (isPreviewFrameType(binaryFrameType(e.data))) return this.onPreviewFrame(e.data);
|
|
@@ -7452,10 +7830,12 @@ var ComfyHost = class {
|
|
|
7452
7830
|
if (msg.type === "status") {
|
|
7453
7831
|
if (msg.data.sid) {
|
|
7454
7832
|
const sidChanged = msg.data.sid !== this.comfySessionId;
|
|
7833
|
+
const socketIsNew = this._socketIsNew;
|
|
7834
|
+
this._socketIsNew = false;
|
|
7455
7835
|
this.comfySessionId = msg.data.sid;
|
|
7456
7836
|
this._sessionResolve?.();
|
|
7457
7837
|
this._sessionResolve = null;
|
|
7458
|
-
if (sidChanged) {
|
|
7838
|
+
if (sidChanged || socketIsNew) {
|
|
7459
7839
|
this._unknownWsEventTypes.clear();
|
|
7460
7840
|
this._unknownBinaryFrameTypes.clear();
|
|
7461
7841
|
this.onSession?.(msg.data.sid);
|
|
@@ -8141,6 +8521,7 @@ var ComfyTS = class ComfyTS {
|
|
|
8141
8521
|
const authed = (p) => p.apiKey != null ? " (authed)" : "";
|
|
8142
8522
|
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)}`);
|
|
8143
8523
|
}
|
|
8524
|
+
if (data.comfyOrgApiKey != null) existing.data.comfyOrgApiKey = data.comfyOrgApiKey;
|
|
8144
8525
|
return existing;
|
|
8145
8526
|
}
|
|
8146
8527
|
const created = new ComfyHost(data);
|
|
@@ -8354,6 +8735,7 @@ exports.ComfyHostUnreachableError = ComfyHostUnreachableError;
|
|
|
8354
8735
|
exports.ComfyManager = ComfyManager;
|
|
8355
8736
|
exports.ComfyNode = ComfyNode;
|
|
8356
8737
|
exports.ComfyNodeOutput = ComfyNodeOutput;
|
|
8738
|
+
exports.ComfyOrgApiKeyMissingError = ComfyOrgApiKeyMissingError;
|
|
8357
8739
|
exports.ComfySchema = ComfySchema;
|
|
8358
8740
|
exports.ComfyTS = ComfyTS;
|
|
8359
8741
|
exports.ComfyUploader = ComfyUploader;
|