comfy-ts 2.18.0 → 2.18.1

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.
@@ -902,7 +902,7 @@ var ComfySchema = class {
902
902
  };
903
903
  //#endregion
904
904
  //#region package.json
905
- var version = "2.18.0";
905
+ var version = "2.18.1";
906
906
  //#endregion
907
907
  //#region src/litegraph/LiteGraphLinkID.ts
908
908
  const asLiteGraphLinkID = (id) => id;
@@ -912,8 +912,55 @@ const LiteGraphLinkID_ = type.number.atLeast(0).as();
912
912
  /** boundary sentinel ids inside definition link tables */
913
913
  const SUBGRAPH_INPUT_NODE_ID = -10;
914
914
  const SUBGRAPH_OUTPUT_NODE_ID = -20;
915
- /** 48 corpus files nest defs inside defs; a self-referencing def would loop forever */
916
- const MAX_EXPANSION_PASSES = 32;
915
+ /** expanded node count above which a file is refused before expanding: the largest official
916
+ * template expands to 575 nodes, and fan-out nesting grows geometrically without any cycle */
917
+ const MAX_EXPANDED_NODES = 1e5;
918
+ /**
919
+ * before any expansion: the definitions as a graph (def → the defs its NORMAL-mode instances name,
920
+ * the only ones expansion follows). A cycle reachable from the root is refused with the defs it
921
+ * runs through, and the expanded size is counted, not built, and refused above
922
+ * MAX_EXPANDED_NODES. One explicit stack, no recursion: the file decides the depth
923
+ */
924
+ const checkExpansion = (wf, defs) => {
925
+ const children = (nodes) => nodes.filter((n) => n.mode === "normal" && defs.has(n.type)).map((n) => n.type);
926
+ const own = (nodes) => nodes.filter((n) => !(n.mode === "normal" && defs.has(n.type))).length;
927
+ const name = (id) => JSON.stringify(defs.get(id)?.name ?? id);
928
+ const cap = (n) => Math.min(n, 100001);
929
+ const size = /* @__PURE__ */ new Map();
930
+ const onPath = /* @__PURE__ */ new Set();
931
+ for (const root of new Set(children(wf.nodes))) {
932
+ if (size.has(root)) continue;
933
+ const stack = [{
934
+ id: root,
935
+ kids: children(bang(defs.get(root)).nodes),
936
+ next: 0
937
+ }];
938
+ onPath.add(root);
939
+ while (stack.length > 0) {
940
+ const top = bang(stack[stack.length - 1]);
941
+ const kid = top.kids[top.next++];
942
+ if (kid == null) {
943
+ const total = top.kids.reduce((acc, k) => cap(acc + (size.get(k) ?? 0)), own(bang(defs.get(top.id)).nodes));
944
+ size.set(top.id, total);
945
+ onPath.delete(top.id);
946
+ stack.pop();
947
+ continue;
948
+ }
949
+ if (size.has(kid)) continue;
950
+ if (onPath.has(kid)) {
951
+ const from = stack.findIndex((frame) => frame.id === kid);
952
+ throw new WorkflowNormalizeError("subgraph-cycle", `subgraph definitions contain themselves: ${[...stack.slice(from).map((frame) => frame.id), kid].map(name).join(" → ")}`, { cycle: stack.slice(from).map((frame) => frame.id) });
953
+ }
954
+ onPath.add(kid);
955
+ stack.push({
956
+ id: kid,
957
+ kids: children(bang(defs.get(kid)).nodes),
958
+ next: 0
959
+ });
960
+ }
961
+ }
962
+ if (children(wf.nodes).reduce((acc, k) => cap(acc + (size.get(k) ?? 0)), own(wf.nodes)) > 1e5) throw new WorkflowNormalizeError("subgraph-too-large", `subgraph expansion would produce more than ${MAX_EXPANDED_NODES} nodes (the largest official template has 575)`);
963
+ };
917
964
  /**
918
965
  * widget-kind fallback when a def input slot has no boundary target carrying a
919
966
  * widget marker: these litegraph slot types carry widget values. LOCAL copy on
@@ -936,11 +983,12 @@ const PRIMITIVE_WIDGET_TYPES = /* @__PURE__ */ new Set([
936
983
  * passthrough walk, which needs no interior.
937
984
  */
938
985
  const expandSubgraphs = (wf, defs) => {
986
+ checkExpansion(wf, defs);
939
987
  let passes = 0;
940
988
  while (true) {
941
989
  const expandable = wf.nodes.filter((n) => defs.has(n.type) && n.mode !== "bypassed");
942
990
  if (expandable.length === 0) return wf;
943
- if (++passes > MAX_EXPANSION_PASSES) throw new WorkflowNormalizeError("subgraph-cycle", `subgraph expansion did not terminate after ${MAX_EXPANSION_PASSES} passes — self-referencing definitions?`);
991
+ if (++passes > defs.size + 1) throw new WorkflowNormalizeError("subgraph-cycle", `subgraph expansion still had instances after ${passes - 1} passes over ${defs.size} definitions`);
944
992
  for (const instance of expandable) if (instance.mode === "muted") dropMutedInstance(wf, instance);
945
993
  else expandOneInstance(wf, instance, bang(defs.get(instance.type)));
946
994
  }
@@ -1593,6 +1641,8 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1593
1641
  if (node.widgets.positional.length > 0) PRIMITIVE_VALUES[node.id] = node.widgets.positional[0];
1594
1642
  else if (Object.hasOwn(node.widgets.named, "value")) PRIMITIVE_VALUES[node.id] = node.widgets.named["value"];
1595
1643
  }
1644
+ const linksById = new Map(workflow.links.map((l) => [l.id, l]));
1645
+ const nodesById = new Map(workflow.nodes.map((n) => [n.id, n]));
1596
1646
  for (const node of workflow.nodes) {
1597
1647
  if (isNeverExecuted(node)) continue;
1598
1648
  if (node.mode !== "normal") continue;
@@ -1771,9 +1821,9 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1771
1821
  }
1772
1822
  }
1773
1823
  const getParentNode = (linkId) => {
1774
- const link = workflow.links.find((link) => link.id === linkId);
1824
+ const link = linksById.get(linkId);
1775
1825
  if (link == null) throw new WorkflowConvertError("dangling-link", `node ${node.id}(${node.type}) references a non-existing link (id=${linkId})`, node);
1776
- const parentNode = workflow.nodes.find((n) => n.id === link.originId);
1826
+ const parentNode = nodesById.get(link.originId);
1777
1827
  if (parentNode == null) throw new WorkflowConvertError("dangling-link", `link ${linkId} references a non-existent parent node ${link.originId}`, node);
1778
1828
  return {
1779
1829
  node: parentNode,
@@ -1899,15 +1949,20 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1899
1949
  }
1900
1950
  }
1901
1951
  if (missing.size > 0) {
1902
- const complete = (id, seen) => {
1903
- if (seen.has(id)) return true;
1904
- seen.add(id);
1905
- if (missing.has(id)) return false;
1906
- for (const value of Object.values(prompt[id]?.inputs ?? {})) if (Array.isArray(value) && typeof value[0] === "string" && !complete(value[0], seen)) return false;
1907
- return true;
1908
- };
1952
+ const consumers = /* @__PURE__ */ new Map();
1953
+ for (const [id, n] of Object.entries(prompt)) for (const value of Object.values(n.inputs)) if (Array.isArray(value) && typeof value[0] === "string") {
1954
+ const list = consumers.get(value[0]) ?? [];
1955
+ list.push(id);
1956
+ consumers.set(value[0], list);
1957
+ }
1958
+ const blocked = new Set(missing.keys());
1959
+ const queue = [...blocked];
1960
+ for (let head = 0; head < queue.length; head++) for (const next of consumers.get(queue[head] ?? "") ?? []) if (!blocked.has(next)) {
1961
+ blocked.add(next);
1962
+ queue.push(next);
1963
+ }
1909
1964
  const outputs = Object.keys(prompt).filter((id) => schema.data.spec[prompt[id]?.class_type ?? ""]?.output_node === true);
1910
- const dropped = outputs.filter((id) => !complete(id, /* @__PURE__ */ new Set()));
1965
+ const dropped = outputs.filter((id) => blocked.has(id));
1911
1966
  const first = missing.values().next().value;
1912
1967
  if (first != null && outputs.length > 0 && dropped.length === outputs.length) throw new WorkflowConvertError("missing-required-input", first.message, first.node);
1913
1968
  if (dropped.length > 0 || outputs.length === 0) console.warn(`🟡 [workflow] ComfyUI will skip output node(s) ${dropped.join(", ") || "(none in this graph)"}: ${[...missing.values()].map((m) => m.message).join("; ")}`);
@@ -4091,8 +4146,13 @@ const ComfyManagerAPIPackList_ark = type({
4091
4146
  /** 🔶 NAMING DISCLAIMER: I call a "custom node package" => "PLUGIN" */
4092
4147
  const MANAGER_TIMING = {
4093
4148
  pollMs: 1e3,
4094
- installTimeoutMs: 60 * 6e4
4149
+ installTimeoutMs: 60 * 6e4,
4150
+ pollGraceMs: 12e4
4095
4151
  };
4152
+ /** an install the host refused or reported failed: ends the wait at once */
4153
+ var InstallFailed = class extends Error {};
4154
+ /** we lost sight of the task: the outcome is not known */
4155
+ var OutcomeUnknown = class extends Error {};
4096
4156
  /** what each generation does NOT serve (history means the `?ui_id=` form) */
4097
4157
  const NOT_SERVED = {
4098
4158
  v3: [
@@ -4198,7 +4258,7 @@ var ComfyManager = class {
4198
4258
  fetchPlugins: () => this.installedPluginView(api),
4199
4259
  fetchModels: () => this.installedModelView(),
4200
4260
  enqueuePlugin: (plugin, uiId) => this.enqueuePluginTask(api, plugin, uiId),
4201
- settle: (what, uiId) => this.settleByHistory(api, what, uiId)
4261
+ settle: (what, uiId, landed, sentId) => this.settleByHistory(api, what, uiId, landed, sentId)
4202
4262
  };
4203
4263
  }
4204
4264
  };
@@ -4247,7 +4307,8 @@ var ComfyManager = class {
4247
4307
  return this.modelList?.models.some((x) => x.name === name && x.installed === "True") ?? false;
4248
4308
  };
4249
4309
  this.modelsBeeingInstalled = /* @__PURE__ */ new Set();
4250
- this.installModel = async (model) => {
4310
+ this.installModel = async (model) => await this.installModelOutcome(model) === "installed";
4311
+ this.installModelOutcome = async (model) => {
4251
4312
  this.modelsBeeingInstalled.add(model.name);
4252
4313
  try {
4253
4314
  return await this.runInstall(`model "${model.name}"`, {
@@ -4260,7 +4321,8 @@ var ComfyManager = class {
4260
4321
  await this.post(this.route(api, "/manager/queue/install_model"), body);
4261
4322
  },
4262
4323
  landed: async (s) => {
4263
- return (await s.fetchModels()).models.find((x) => x.filename === model.filename && x.save_path === model.save_path && x.base === model.base)?.installed === "True";
4324
+ const row = (await s.fetchModels()).models.find((x) => x.filename === model.filename && x.save_path === model.save_path && x.base === model.base);
4325
+ return row == null ? null : row.installed === "True";
4264
4326
  }
4265
4327
  });
4266
4328
  } finally {
@@ -4294,10 +4356,43 @@ var ComfyManager = class {
4294
4356
  return "error";
4295
4357
  })();
4296
4358
  };
4359
+ this.requirementStatus = (req) => {
4360
+ const mirror = this.mirror();
4361
+ const packs = (() => {
4362
+ if (req.type === "customNodesByNodeKey") return mirror.plugins_byNodeKey.get(req.nodeName) ?? [];
4363
+ if (req.type === "customNodesByTitle") return [mirror.plugins_byTitle.get(req.title)].filter((x) => x != null);
4364
+ if (req.type === "customNodesByURI") return [mirror.plugins_byFile.get(req.uri)].filter((x) => x != null);
4365
+ return null;
4366
+ })();
4367
+ if (packs == null) return req.type === "modelInManager" ? this.getModelStatus(req.modelName) : null;
4368
+ if (packs.length === 0) return req.type === "customNodesByNodeKey" ? "unknown" : null;
4369
+ const statuses = packs.map((x) => this.getPluginStatus(x.title));
4370
+ if (statuses.some((x) => x === "installed" || x === "update-available")) return "installed";
4371
+ return statuses.every((x) => x === "not-installed") ? "not-installed" : "unknown";
4372
+ };
4373
+ this.checkRequirements = (requirements) => {
4374
+ const out = {
4375
+ missing: [],
4376
+ undecided: []
4377
+ };
4378
+ for (const req of requirements) {
4379
+ if (req.optional) continue;
4380
+ const status = this.requirementStatus(req);
4381
+ if (status === "not-installed") out.missing.push(req);
4382
+ else if (status === "unknown" || status === "error") out.undecided.push(req);
4383
+ }
4384
+ return out;
4385
+ };
4386
+ this.matchRequirements = (requirements) => {
4387
+ const check = this.checkRequirements(requirements);
4388
+ if (check.undecided.length > 0) logError(`requirements the host lists cannot decide, read as present: ${check.undecided.map((r) => JSON.stringify(r)).join(", ")}` + (this.pluginList == null || this.modelList == null ? " (the lists are not fetched: call fetchPluginsAndModels)" : ""));
4389
+ return check.missing.length === 0;
4390
+ };
4297
4391
  this.fetchPlugins = async (mode = "cache", skipUpdate = true) => {
4298
4392
  return this.strategy(await this.api()).fetchPlugins(mode, skipUpdate);
4299
4393
  };
4300
- this.installPlugin = async (plugin) => {
4394
+ this.installPlugin = async (plugin) => await this.installPluginOutcome(plugin) === "installed";
4395
+ this.installPluginOutcome = async (plugin) => {
4301
4396
  return this.runInstall(`plugin "${plugin.title}"`, {
4302
4397
  enqueue: (api, uiId) => this.strategy(api).enqueuePlugin(plugin, uiId),
4303
4398
  landed: async (_s, api) => {
@@ -4374,8 +4469,9 @@ var ComfyManager = class {
4374
4469
  };
4375
4470
  this.enqueuePluginTask = async (api, plugin, uiId) => {
4376
4471
  const url = plugin.files[0] ?? plugin.reference;
4472
+ const id = repoPath(url).split("/").pop() ?? url;
4377
4473
  const params = {
4378
- id: repoPath(url).split("/").pop() ?? url,
4474
+ id,
4379
4475
  version: "nightly",
4380
4476
  selected_version: "nightly",
4381
4477
  repository: url,
@@ -4388,18 +4484,26 @@ var ComfyManager = class {
4388
4484
  kind: "install",
4389
4485
  params
4390
4486
  });
4487
+ return id;
4391
4488
  };
4392
- this.settleByHistory = async (api, what, uiId) => {
4489
+ this.settleByHistory = async (api, what, uiId, landed, sentId) => {
4393
4490
  const route = this.route(api, "/manager/queue/history", `?ui_id=${encodeURIComponent(uiId)}`);
4491
+ const readEntry = async () => (await this.getValid(route, TaskHistory_ark)).history.status ?? null;
4394
4492
  const entry = await this.waitFor(what, async () => {
4395
- const status = (await this.getValid(route, TaskHistory_ark)).history.status;
4396
- if (status == null) await this.restartIdleQueue(api);
4397
- return status ?? null;
4493
+ const status = await readEntry();
4494
+ if (status != null) return status;
4495
+ if (await this.restartIdleQueue(api) !== "drained") return null;
4496
+ const late = await readEntry();
4497
+ if (late != null) return late;
4498
+ throw new InstallFailed("the task left the queue with no result (a queue/reset from the Manager UI or another client removes it)");
4398
4499
  });
4399
- if (entry.status_str === "success" || entry.status_str === "skip") return;
4500
+ if (entry.status_str === "success" || entry.status_str === "skip") {
4501
+ if (await this.endState(landed) !== false) return;
4502
+ throw new InstallFailed(sentId != null ? `the Manager reported success, but this pack does not read installed: another pack holds the id "${sentId}" it installs by` : "the Manager reported success, but it does not read installed afterwards");
4503
+ }
4400
4504
  const messages = entry.messages ?? [];
4401
4505
  const gate = messages.length === 1 && messages[0] === "failed" ? ": refused by its security policy, which allows installs only with security_level normal or below AND either ComfyUI listening on localhost or network_mode personal_cloud (the ComfyUI console names the rule)" : "";
4402
- throw new Error(`the Manager reports ${entry.status_str}: ${messages.join(" | ")}${gate}`);
4506
+ throw new InstallFailed(`the Manager reports ${entry.status_str}: ${messages.join(" | ")}${gate}`);
4403
4507
  };
4404
4508
  this.restartIdleQueue = async (api) => {
4405
4509
  const status = await this.getValid(this.route(api, "/manager/queue/status"), QueueStatus_ark);
@@ -4410,29 +4514,52 @@ var ComfyManager = class {
4410
4514
  };
4411
4515
  this.settleByDrain = async (api, what, landed) => {
4412
4516
  await this.waitFor(what, async () => await this.restartIdleQueue(api) === "drained" ? true : null);
4413
- if (!await landed()) throw new Error(`the Manager queue drained but it is not installed; ComfyUI-Manager ${api.version} reports why only over its websocket (cm-queue-status) and in the ComfyUI console`);
4517
+ const state = await this.endState(landed);
4518
+ if (state === true) return;
4519
+ if (state === null) throw new OutcomeUnknown("the queue drained, but the lists cannot say whether it is installed");
4520
+ throw new InstallFailed(`the Manager queue drained but it is not installed; ComfyUI-Manager ${api.version} reports why only over its websocket (cm-queue-status) and in the ComfyUI console`);
4521
+ };
4522
+ this.endState = async (landed) => {
4523
+ try {
4524
+ return await landed();
4525
+ } catch (exception) {
4526
+ throw new OutcomeUnknown(`the task ran, but its end state could not be read: ${errorText(exception)}`);
4527
+ }
4414
4528
  };
4415
4529
  this.runInstall = async (what, p) => {
4530
+ const host = this.host.getServerHostHTTP();
4416
4531
  try {
4417
4532
  const api = await this.api();
4418
4533
  const s = this.strategy(api);
4419
4534
  const uiId = nanoid();
4420
- await p.enqueue(api, uiId);
4535
+ const sentId = await p.enqueue(api, uiId);
4421
4536
  await this.post(this.route(api, "/manager/queue/start"));
4422
- await s.settle(what, uiId, () => p.landed(s, api));
4537
+ await s.settle(what, uiId, () => p.landed(s, api), sentId);
4423
4538
  logSuccess(`${what} installed`);
4424
- return true;
4539
+ return "installed";
4425
4540
  } catch (exception) {
4426
- logError(`${what}: install failed on ${this.host.getServerHostHTTP()}: ${errorText(exception)}`);
4427
- return false;
4541
+ if (exception instanceof OutcomeUnknown) {
4542
+ logError(`${what}: OUTCOME UNKNOWN on ${host}: ${exception.message}. The Manager may still be installing it: refetch the list (fetchModels / fetchPlugins) and read its status before installing again, a blind retry queues a second download`);
4543
+ return "unknown";
4544
+ }
4545
+ logError(`${what}: install failed on ${host}: ${errorText(exception)}`);
4546
+ return "failed";
4428
4547
  }
4429
4548
  };
4430
4549
  this.waitFor = async (what, check) => {
4431
4550
  const deadline = Date.now() + this.timing.installTimeoutMs;
4551
+ let lastAnswer = Date.now();
4432
4552
  for (;;) {
4433
- const value = await check();
4434
- if (value != null) return value;
4435
- if (Date.now() >= deadline) throw new Error(`${what} still running after ${this.timing.installTimeoutMs} ms (manager.timing.installTimeoutMs)`);
4553
+ try {
4554
+ const value = await check();
4555
+ lastAnswer = Date.now();
4556
+ if (value != null) return value;
4557
+ } catch (exception) {
4558
+ if (exception instanceof InstallFailed) throw exception;
4559
+ if (Date.now() - lastAnswer >= this.timing.pollGraceMs) throw new OutcomeUnknown(`the host gave no answer for ${this.timing.pollGraceMs} ms (manager.timing.pollGraceMs), last: ${errorText(exception)}`);
4560
+ logError(`${what}: poll failed, still waiting: ${errorText(exception)}`);
4561
+ }
4562
+ if (Date.now() >= deadline) throw new OutcomeUnknown(`still running after ${this.timing.installTimeoutMs} ms (manager.timing.installTimeoutMs)`);
4436
4563
  await new Promise((resolve) => setTimeout(resolve, this.timing.pollMs));
4437
4564
  }
4438
4565
  };
@@ -4783,26 +4910,8 @@ var ComfyHost = class {
4783
4910
  constructor(data) {
4784
4911
  this.data = data;
4785
4912
  this.uploader = new ComfyUploader(this);
4786
- this.matchRequirements = (requirements) => {
4787
- const repo = comfyts.registry;
4788
- for (const req of requirements) {
4789
- if (req.optional) continue;
4790
- if (req.type === "customNodesByNodeKey") {
4791
- if (!(repo.plugins_byNodeKey.get(req.nodeName) ?? []).find((i) => this.manager.isPluginInstalled(i.title))) return false;
4792
- } else if (req.type === "customNodesByTitle") {
4793
- const plugin = repo.plugins_byTitle.get(req.title);
4794
- if (plugin == null) continue;
4795
- if (!this.manager.isPluginInstalled(plugin.title)) return false;
4796
- } else if (req.type === "customNodesByURI") {
4797
- const plugin = repo.plugins_byFile.get(req.uri);
4798
- if (plugin == null) continue;
4799
- if (!this.manager.isPluginInstalled(plugin.title)) return false;
4800
- } else if (req.type === "modelInManager") {
4801
- if (!this.manager.isModelInstalled(req.modelName)) return false;
4802
- }
4803
- }
4804
- return true;
4805
- };
4913
+ this.matchRequirements = (requirements) => this.manager.matchRequirements(requirements);
4914
+ this.checkRequirements = (requirements) => this.manager.checkRequirements(requirements);
4806
4915
  this.serverLogs = [];
4807
4916
  this.wantLog = true;
4808
4917
  this.maxLogs = 200;
@@ -6029,4 +6138,4 @@ var ComfyTS = class ComfyTS {
6029
6138
  //#endregion
6030
6139
  export { ComfySchema as a, importSharp as i, settingsPathFor as n, readableStringify as r, ComfyTS as t };
6031
6140
 
6032
- //# sourceMappingURL=state-DgwWhZWb.js.map
6141
+ //# sourceMappingURL=state-C067Kbew.js.map