comfy-ts 2.20.1 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +21 -3
  2. package/dist/{ServeApp-B469W26E.js → ServeApp-ByMobrWW.js} +3 -3
  3. package/dist/{ServeApp-B469W26E.js.map → ServeApp-ByMobrWW.js.map} +1 -1
  4. package/dist/cli.js +5 -5
  5. package/dist/{exampleAssets-8MycEthF.js → exampleAssets-B5sMqNia.js} +58 -3
  6. package/dist/exampleAssets-B5sMqNia.js.map +1 -0
  7. package/dist/{findDefinedWorkflow-B90-xFxX.js → findDefinedWorkflow-BNZgYIww.js} +2 -2
  8. package/dist/{findDefinedWorkflow-B90-xFxX.js.map → findDefinedWorkflow-BNZgYIww.js.map} +1 -1
  9. package/dist/index.cjs +87 -19
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +19 -3
  12. package/dist/index.d.ts +19 -3
  13. package/dist/index.js +87 -19
  14. package/dist/index.js.map +1 -1
  15. package/dist/{run-run-BslhZ0Qm.js → run-run-CuBSygku.js} +5 -5
  16. package/dist/{run-run-BslhZ0Qm.js.map → run-run-CuBSygku.js.map} +1 -1
  17. package/dist/{run-serve-CsEYPGm9.js → run-serve-COk_G0Qz.js} +4 -4
  18. package/dist/{run-serve-CsEYPGm9.js.map → run-serve-COk_G0Qz.js.map} +1 -1
  19. package/dist/{run-tui-Cxa8ksav.js → run-tui-CB6i_x2y.js} +4 -4
  20. package/dist/{run-tui-Cxa8ksav.js.map → run-tui-CB6i_x2y.js.map} +1 -1
  21. package/dist/{schemaDrift-DaWsE-mt.js → schemaDrift-CHDVYlaj.js} +32 -19
  22. package/dist/{schemaDrift-DaWsE-mt.js.map → schemaDrift-CHDVYlaj.js.map} +1 -1
  23. package/dist/web.d.ts +19 -3
  24. package/dist/web.js +87 -19
  25. package/dist/web.js.map +1 -1
  26. package/package.json +2 -2
  27. package/src/host/ComfyHost.ts +21 -0
  28. package/src/host/leastBusy.ts +37 -0
  29. package/src/state.ts +6 -0
  30. package/src/vars/DefinedWorkflow.ts +38 -21
  31. package/dist/exampleAssets-8MycEthF.js.map +0 -1
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { a as readableStringify, c as writeHostFile, l as renderHttpBase, n as comfyTsPackageDir, r as ComfyTS, s as ComfySchema } from "./exampleAssets-8MycEthF.js";
3
- import { D as readLoraMirror, F as fetchLoraList, H as lmModelName, K as lmTrainedWords, _ as buildLoraMirror, j as writeLoraMirror } from "./schemaDrift-DaWsE-mt.js";
2
+ import { a as readableStringify, c as writeHostFile, l as renderHttpBase, n as comfyTsPackageDir, r as ComfyTS, s as ComfySchema } from "./exampleAssets-B5sMqNia.js";
3
+ import { D as readLoraMirror, F as fetchLoraList, H as lmModelName, K as lmTrainedWords, _ as buildLoraMirror, j as writeLoraMirror } from "./schemaDrift-CHDVYlaj.js";
4
4
  import { spawn } from "node:child_process";
5
5
  import { constants, homedir } from "node:os";
6
6
  import { fileURLToPath } from "node:url";
@@ -554,14 +554,14 @@ async function main() {
554
554
  }
555
555
  armHopChild();
556
556
  if (cmd === "run") {
557
- const { runRun } = await import("./run-run-BslhZ0Qm.js");
557
+ const { runRun } = await import("./run-run-CuBSygku.js");
558
558
  return runRun(rest);
559
559
  }
560
560
  if (cmd === "serve") {
561
- const { runServe } = await import("./run-serve-CsEYPGm9.js");
561
+ const { runServe } = await import("./run-serve-COk_G0Qz.js");
562
562
  return runServe(rest);
563
563
  }
564
- const { runTui } = await import("./run-tui-Cxa8ksav.js");
564
+ const { runTui } = await import("./run-tui-CB6i_x2y.js");
565
565
  return runTui(rest);
566
566
  }
567
567
  console.log(HELP);
@@ -1,4 +1,4 @@
1
- import { X as ansi, a as DefinedWorkflow, at as isRecord$1, ct as resolveComfyStorage, dt as logInfo, ft as logSuccess, ht as extractErrorMessage, it as hashArrayBuffer, lt as isQuiet, mt as sha1HexOfString, n as diffSchemas, nt as isVideoFilename, ot as bang, pt as statelessRegex, rt as mediaMime, st as getComfyStorage, t as MODEL_LISTS, ut as logError } from "./schemaDrift-DaWsE-mt.js";
1
+ import { X as ansi, a as DefinedWorkflow, at as isRecord$1, ct as resolveComfyStorage, dt as logInfo, ft as logSuccess, ht as extractErrorMessage, it as hashArrayBuffer, lt as isQuiet, mt as sha1HexOfString, n as diffSchemas, nt as isVideoFilename, ot as bang, pt as statelessRegex, rt as mediaMime, st as getComfyStorage, t as MODEL_LISTS, ut as logError } from "./schemaDrift-CHDVYlaj.js";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import { basename, dirname, join } from "pathe";
@@ -1003,7 +1003,7 @@ var ComfySchema = class {
1003
1003
  };
1004
1004
  //#endregion
1005
1005
  //#region package.json
1006
- var version = "2.20.1";
1006
+ var version = "2.21.0";
1007
1007
  //#endregion
1008
1008
  //#region src/litegraph/LiteGraphLinkID.ts
1009
1009
  const asLiteGraphLinkID = (id) => id;
@@ -5168,6 +5168,14 @@ var ComfyHost = class {
5168
5168
  if (!res.ok) throw new Error(`GET /system_stats failed: ${res.status}`);
5169
5169
  return previewMethodFromSystemStats(await res.json());
5170
5170
  };
5171
+ this.fetchQueueSize = async (p = {}) => {
5172
+ const res = await this.fetch("/prompt", { signal: AbortSignal.timeout(p.timeoutMs ?? 3e3) });
5173
+ if (!res.ok) throw new Error(`GET /prompt failed: ${res.status}`);
5174
+ const size = queueRemainingOf(await res.json());
5175
+ if (size == null) throw new Error(`GET /prompt: no exec_info.queue_remaining in the reply`);
5176
+ return size;
5177
+ };
5178
+ this.runsInFlight = 0;
5171
5179
  this.fetchRawLogs = async () => {
5172
5180
  const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
5173
5181
  if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
@@ -5566,6 +5574,49 @@ var ComfyHost = class {
5566
5574
  }
5567
5575
  }
5568
5576
  };
5577
+ /** `exec_info.queue_remaining` of a `GET /prompt` reply, null when the shape is not there */
5578
+ function queueRemainingOf(json) {
5579
+ if (typeof json !== "object" || json == null || !("exec_info" in json)) return null;
5580
+ const info = json.exec_info;
5581
+ if (typeof info !== "object" || info == null || !("queue_remaining" in info)) return null;
5582
+ return typeof info.queue_remaining === "number" ? info.queue_remaining : null;
5583
+ }
5584
+ //#endregion
5585
+ //#region src/host/leastBusy.ts
5586
+ /**
5587
+ * the host with the shortest queue. Score = max(server queue, our runs in flight there):
5588
+ * the server counts every client, the local count sees runs not posted yet.
5589
+ * Ties go to the first host listed; a host that does not answer is skipped, all down throws.
5590
+ */
5591
+ async function leastBusy(hosts, p = {}) {
5592
+ if (hosts.length === 0) throw new Error("leastBusy: no host given");
5593
+ const probes = await Promise.all(hosts.map(async (host) => {
5594
+ try {
5595
+ const queue = await host.fetchQueueSize({ timeoutMs: p.timeoutMs });
5596
+ return {
5597
+ host,
5598
+ score: Math.max(queue, host.runsInFlight),
5599
+ error: null
5600
+ };
5601
+ } catch (err) {
5602
+ return {
5603
+ host,
5604
+ score: Infinity,
5605
+ error: extractErrorMessage(err)
5606
+ };
5607
+ }
5608
+ }));
5609
+ let best = null;
5610
+ for (const probe of probes) {
5611
+ if (probe.error != null) {
5612
+ console.warn(`🟡 leastBusy: host '${probe.host.data.id}' skipped: ${probe.error}`);
5613
+ continue;
5614
+ }
5615
+ if (best == null || probe.score < best.score) best = probe;
5616
+ }
5617
+ if (best == null) throw new Error(`🔴 leastBusy: no host answered (${probes.map((x) => `'${x.host.data.id}': ${x.error}`).join(", ")})`);
5618
+ return best.host;
5619
+ }
5569
5620
  //#endregion
5570
5621
  //#region src/utils/downloadFile.ts
5571
5622
  async function downloadFile(url, outputPath, logPrefix = " - ") {
@@ -6182,6 +6233,10 @@ var ComfyTS = class ComfyTS {
6182
6233
  this.hosts.set(data.id, created);
6183
6234
  return created;
6184
6235
  }
6236
+ /** the host with the shortest queue, for `wf.run({ host: await comfy.leastBusy([a, b]) })` */
6237
+ leastBusy(hosts, p = {}) {
6238
+ return leastBusy(hosts, p);
6239
+ }
6185
6240
  get registry() {
6186
6241
  if (this._registry == null) this._registry = new ComfyRegistry({
6187
6242
  check: false,
@@ -6263,4 +6318,4 @@ function comfyTsPackageDir(moduleUrl = import.meta.url) {
6263
6318
  //#endregion
6264
6319
  export { readableStringify as a, writeHostFile as c, settingsPathFor as i, renderHttpBase as l, comfyTsPackageDir as n, importSharp as o, ComfyTS as r, ComfySchema as s, bundledExamplesDir as t };
6265
6320
 
6266
- //# sourceMappingURL=exampleAssets-8MycEthF.js.map
6321
+ //# sourceMappingURL=exampleAssets-B5sMqNia.js.map