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.
package/dist/web.d.ts CHANGED
@@ -12274,14 +12274,14 @@ declare const types$1: import("arktype").Module<{
12274
12274
  node?: ComfyNodeId | null | undefined;
12275
12275
  };
12276
12276
  } | {
12277
- type: "execution_start";
12277
+ type: "execution_cached";
12278
12278
  data: {
12279
+ nodes: ComfyNodeId[];
12279
12280
  prompt_id: PromptID;
12280
12281
  };
12281
12282
  } | {
12282
- type: "execution_cached";
12283
+ type: "execution_start";
12283
12284
  data: {
12284
- nodes: ComfyNodeId[];
12285
12285
  prompt_id: PromptID;
12286
12286
  };
12287
12287
  } | {
@@ -12373,14 +12373,14 @@ declare const types$1: import("arktype").Module<{
12373
12373
  node?: ComfyNodeId | null | undefined;
12374
12374
  };
12375
12375
  } | {
12376
- type: "execution_start";
12376
+ type: "execution_cached";
12377
12377
  data: {
12378
+ nodes: ComfyNodeId[];
12378
12379
  prompt_id: PromptID;
12379
12380
  };
12380
12381
  } | {
12381
- type: "execution_cached";
12382
+ type: "execution_start";
12382
12383
  data: {
12383
- nodes: ComfyNodeId[];
12384
12384
  prompt_id: PromptID;
12385
12385
  };
12386
12386
  } | {
@@ -16519,6 +16519,8 @@ declare const ComfyManagerAPIPluginList_ark: import("arktype/internal/variants/o
16519
16519
  /** the part of the registry the views read */
16520
16520
  type ManagerMirror = {
16521
16521
  plugins_byTitle: ReadonlyMap<KnownComfyPluginTitle, ComfyManagerPluginInfo>;
16522
+ plugins_byFile: ReadonlyMap<string, ComfyManagerPluginInfo>;
16523
+ plugins_byNodeKey: ReadonlyMap<string, readonly ComfyManagerPluginInfo[]>;
16522
16524
  /** every model row: upstream ships a few names twice, with different files */
16523
16525
  modelRows: readonly ComfyManagerModelInfo[];
16524
16526
  };
@@ -16584,11 +16586,14 @@ type ManagerApi = {
16584
16586
  generation: ManagerGeneration;
16585
16587
  version: string;
16586
16588
  };
16587
- /** install waits poll the queue; tests pass milliseconds */
16589
+ /** install waits poll the queue; `pollGraceMs`: how long the poll survives a host that does not answer */
16588
16590
  type ManagerTiming = {
16589
16591
  pollMs: number;
16590
16592
  installTimeoutMs: number;
16593
+ pollGraceMs: number;
16591
16594
  };
16595
+ /** `unknown`: we lost sight of the task, the Manager may still be installing (agent/architecture.md) */
16596
+ type InstallOutcome = 'installed' | 'failed' | 'unknown';
16592
16597
  declare class ComfyManager {
16593
16598
  host: {
16594
16599
  getServerHostHTTP: () => string;
@@ -16638,26 +16643,39 @@ declare class ComfyManager {
16638
16643
  /** what the host has of our model mirror; a model absent from the list reads `unknown` */
16639
16644
  fetchModels: () => Promise<ComfyManagerAPIModelList>;
16640
16645
  fetchLogs: () => Promise<any>;
16646
+ /** true only for a KNOWN install: false is "not known to be installed" (missing OR undecided), see `getModelStatus` */
16641
16647
  isModelInstalled: (name: KnownModel_Name) => boolean;
16642
16648
  modelsBeeingInstalled: Set<KnownModel_Name>;
16643
- /** queue the install, wait until the Manager ran it; true only once the model is verified installed */
16649
+ /** queue the install, wait until the Manager ran it; true only once the model is verified installed (`installModelOutcome` tells failed from unknown) */
16644
16650
  installModel: (model: ComfyManagerModelInfo) => Promise<boolean>;
16651
+ installModelOutcome: (model: ComfyManagerModelInfo) => Promise<InstallOutcome>;
16645
16652
  getModelStatus: (modelName: KnownModel_Name) => PluginInstallStatus;
16646
16653
  /**
16647
16654
  * you need to call `fetchPluginList()` to populate this field
16648
16655
  */
16649
16656
  pluginList: Maybe<ComfyManagerAPIPluginList>;
16650
16657
  get titlesOfAllInstalledPlugins(): KnownComfyPluginTitle[];
16658
+ /** true only for a KNOWN install: false is "not known to be installed" (missing OR undecided), see `getPluginStatus` */
16651
16659
  isPluginInstalled: (title: KnownComfyPluginTitle) => boolean;
16652
16660
  getPluginStatus: (title: KnownComfyPluginTitle) => PluginInstallStatus;
16661
+ /** one requirement against the fetched lists; `unknown` when they cannot say, null when the mirror does not know it */
16662
+ requirementStatus: (req: Requirements) => PluginInstallStatus | null;
16663
+ /** `missing`: known not installed, the only requirements an install flow may queue; `undecided`: the lists cannot say */
16664
+ checkRequirements: (requirements: Requirements[]) => {
16665
+ missing: Requirements[];
16666
+ undecided: Requirements[];
16667
+ };
16668
+ /** false only when a requirement is known missing; an undecided one passes with a warning */
16669
+ matchRequirements: (requirements: Requirements[]) => boolean;
16653
16670
  /** the host's plugin list in the public `custom_nodes` shape, titled like our mirror; absent = `unknown` */
16654
16671
  fetchPlugins: (
16655
16672
  /** @default: 'cache' */
16656
16673
  mode?: ComfyManagerAPIFetchPolicy,
16657
16674
  /** @default: true */
16658
16675
  skipUpdate?: boolean) => Promise<ComfyManagerAPIPluginList>;
16659
- /** queue the install, wait until the Manager ran it; true only once the pack is verified installed */
16676
+ /** queue the install, wait until the Manager ran it; true only once the pack is verified installed (`installPluginOutcome` tells failed from unknown) */
16660
16677
  installPlugin: (plugin: ComfyManagerPluginInfo) => Promise<boolean>;
16678
+ installPluginOutcome: (plugin: ComfyManagerPluginInfo) => Promise<InstallOutcome>;
16661
16679
  /** the Manager's own getlist (v3, v4 legacy ui), normalized */
16662
16680
  private listedPlugins;
16663
16681
  private fetchPluginWire;
@@ -16670,9 +16688,9 @@ declare class ComfyManager {
16670
16688
  private installedModelView;
16671
16689
  /** v3 and v4 legacy ui: the Manager's own list row for the pack, sent like its own ui does */
16672
16690
  private enqueueListedPlugin;
16673
- /** v4: no list to take a row from, so the pack goes by repo name at nightly */
16691
+ /** v4: no list to take a row from, so the pack goes by repo name at nightly; resolves with that id */
16674
16692
  private enqueuePluginTask;
16675
- /** v4: the task's own history entry says how it ended */
16693
+ /** v4: the task's own history entry says how it ended; the end state confirms a success */
16676
16694
  private settleByHistory;
16677
16695
  /**
16678
16696
  * a worker lingers a few seconds after a drain, then exits; a start in that window answers 201
@@ -16682,8 +16700,14 @@ declare class ComfyManager {
16682
16700
  private restartIdleQueue;
16683
16701
  /** v3, v4 legacy ui: no per item result over http, so wait for the drain and look at the end state */
16684
16702
  private settleByDrain;
16703
+ /** the end state after the task ran: a host that does not answer here leaves the outcome unknown */
16704
+ private endState;
16685
16705
  private runInstall;
16686
- /** poll until `check` gives a value, never past `timing.installTimeoutMs` */
16706
+ /**
16707
+ * poll until `check` gives a value. A failed request is a blip: logged, and the poll goes on until
16708
+ * `timing.pollGraceMs` passes without one good answer. Giving up, or the deadline, is an UNKNOWN
16709
+ * outcome (the task may still run); only an `InstallFailed` from `check` ends the wait as a failure.
16710
+ */
16687
16711
  private waitFor;
16688
16712
  /** json POST (the Manager's csrf guard refuses simple form types); the reply json, or null when empty */
16689
16713
  private post;
@@ -17679,8 +17703,13 @@ declare class ComfyHost<ID extends string = string> {
17679
17703
  constructor(data: ComfyHostData & {
17680
17704
  id: ID;
17681
17705
  });
17682
- /** helper to check if your host have whatever it needs to run your workflow */
17706
+ /** false only when a requirement is known missing; an undecided one passes with a warning (manager.matchRequirements) */
17683
17707
  matchRequirements: (requirements: Requirements[]) => boolean;
17708
+ /** `missing` (known not installed, the only ones to queue for install) and `undecided` (the lists cannot say) */
17709
+ checkRequirements: (requirements: Requirements[]) => {
17710
+ missing: Requirements[];
17711
+ undecided: Requirements[];
17712
+ };
17684
17713
  /** server sent by the comfy-manager plugin */
17685
17714
  readonly serverLogs: ServerLog[];
17686
17715
  /** if true, request ComfyUI to forward logs */
@@ -18624,7 +18653,7 @@ type CanonicalGroup = {
18624
18653
  };
18625
18654
  //#endregion
18626
18655
  //#region src/litegraph/normalizeWorkflow.d.ts
18627
- type WorkflowNormalizeErrorCode = 'schema-reject' | 'subgraph-cycle' | 'subgraph-io-mismatch' | 'bad-document';
18656
+ type WorkflowNormalizeErrorCode = 'schema-reject' | 'subgraph-cycle' | 'subgraph-too-large' | 'subgraph-io-mismatch' | 'bad-document';
18628
18657
  /** a workflow JSON we cannot turn into a CanonicalWorkflow — loud, typed, never a cast */
18629
18658
  declare class WorkflowNormalizeError extends Error {
18630
18659
  code: WorkflowNormalizeErrorCode;
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.18.0";
104
+ var version = "2.18.1";
105
105
  //#endregion
106
106
  //#region src/litegraph/LiteGraphLinkID.ts
107
107
  const asLiteGraphLinkID = (id) => id;
@@ -121,8 +121,55 @@ const bang = (x, msg = "") => {
121
121
  /** boundary sentinel ids inside definition link tables */
122
122
  const SUBGRAPH_INPUT_NODE_ID = -10;
123
123
  const SUBGRAPH_OUTPUT_NODE_ID = -20;
124
- /** 48 corpus files nest defs inside defs; a self-referencing def would loop forever */
125
- const MAX_EXPANSION_PASSES = 32;
124
+ /** expanded node count above which a file is refused before expanding: the largest official
125
+ * template expands to 575 nodes, and fan-out nesting grows geometrically without any cycle */
126
+ const MAX_EXPANDED_NODES = 1e5;
127
+ /**
128
+ * before any expansion: the definitions as a graph (def → the defs its NORMAL-mode instances name,
129
+ * the only ones expansion follows). A cycle reachable from the root is refused with the defs it
130
+ * runs through, and the expanded size is counted, not built, and refused above
131
+ * MAX_EXPANDED_NODES. One explicit stack, no recursion: the file decides the depth
132
+ */
133
+ const checkExpansion = (wf, defs) => {
134
+ const children = (nodes) => nodes.filter((n) => n.mode === "normal" && defs.has(n.type)).map((n) => n.type);
135
+ const own = (nodes) => nodes.filter((n) => !(n.mode === "normal" && defs.has(n.type))).length;
136
+ const name = (id) => JSON.stringify(defs.get(id)?.name ?? id);
137
+ const cap = (n) => Math.min(n, 100001);
138
+ const size = /* @__PURE__ */ new Map();
139
+ const onPath = /* @__PURE__ */ new Set();
140
+ for (const root of new Set(children(wf.nodes))) {
141
+ if (size.has(root)) continue;
142
+ const stack = [{
143
+ id: root,
144
+ kids: children(bang(defs.get(root)).nodes),
145
+ next: 0
146
+ }];
147
+ onPath.add(root);
148
+ while (stack.length > 0) {
149
+ const top = bang(stack[stack.length - 1]);
150
+ const kid = top.kids[top.next++];
151
+ if (kid == null) {
152
+ const total = top.kids.reduce((acc, k) => cap(acc + (size.get(k) ?? 0)), own(bang(defs.get(top.id)).nodes));
153
+ size.set(top.id, total);
154
+ onPath.delete(top.id);
155
+ stack.pop();
156
+ continue;
157
+ }
158
+ if (size.has(kid)) continue;
159
+ if (onPath.has(kid)) {
160
+ const from = stack.findIndex((frame) => frame.id === kid);
161
+ 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) });
162
+ }
163
+ onPath.add(kid);
164
+ stack.push({
165
+ id: kid,
166
+ kids: children(bang(defs.get(kid)).nodes),
167
+ next: 0
168
+ });
169
+ }
170
+ }
171
+ 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)`);
172
+ };
126
173
  /**
127
174
  * widget-kind fallback when a def input slot has no boundary target carrying a
128
175
  * widget marker: these litegraph slot types carry widget values. LOCAL copy on
@@ -145,11 +192,12 @@ const PRIMITIVE_WIDGET_TYPES = /* @__PURE__ */ new Set([
145
192
  * passthrough walk, which needs no interior.
146
193
  */
147
194
  const expandSubgraphs = (wf, defs) => {
195
+ checkExpansion(wf, defs);
148
196
  let passes = 0;
149
197
  while (true) {
150
198
  const expandable = wf.nodes.filter((n) => defs.has(n.type) && n.mode !== "bypassed");
151
199
  if (expandable.length === 0) return wf;
152
- if (++passes > MAX_EXPANSION_PASSES) throw new WorkflowNormalizeError("subgraph-cycle", `subgraph expansion did not terminate after ${MAX_EXPANSION_PASSES} passes — self-referencing definitions?`);
200
+ if (++passes > defs.size + 1) throw new WorkflowNormalizeError("subgraph-cycle", `subgraph expansion still had instances after ${passes - 1} passes over ${defs.size} definitions`);
153
201
  for (const instance of expandable) if (instance.mode === "muted") dropMutedInstance(wf, instance);
154
202
  else expandOneInstance(wf, instance, bang(defs.get(instance.type)));
155
203
  }
@@ -1044,6 +1092,8 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1044
1092
  if (node.widgets.positional.length > 0) PRIMITIVE_VALUES[node.id] = node.widgets.positional[0];
1045
1093
  else if (Object.hasOwn(node.widgets.named, "value")) PRIMITIVE_VALUES[node.id] = node.widgets.named["value"];
1046
1094
  }
1095
+ const linksById = new Map(workflow.links.map((l) => [l.id, l]));
1096
+ const nodesById = new Map(workflow.nodes.map((n) => [n.id, n]));
1047
1097
  for (const node of workflow.nodes) {
1048
1098
  if (isNeverExecuted(node)) continue;
1049
1099
  if (node.mode !== "normal") continue;
@@ -1222,9 +1272,9 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1222
1272
  }
1223
1273
  }
1224
1274
  const getParentNode = (linkId) => {
1225
- const link = workflow.links.find((link) => link.id === linkId);
1275
+ const link = linksById.get(linkId);
1226
1276
  if (link == null) throw new WorkflowConvertError("dangling-link", `node ${node.id}(${node.type}) references a non-existing link (id=${linkId})`, node);
1227
- const parentNode = workflow.nodes.find((n) => n.id === link.originId);
1277
+ const parentNode = nodesById.get(link.originId);
1228
1278
  if (parentNode == null) throw new WorkflowConvertError("dangling-link", `link ${linkId} references a non-existent parent node ${link.originId}`, node);
1229
1279
  return {
1230
1280
  node: parentNode,
@@ -1350,15 +1400,20 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
1350
1400
  }
1351
1401
  }
1352
1402
  if (missing.size > 0) {
1353
- const complete = (id, seen) => {
1354
- if (seen.has(id)) return true;
1355
- seen.add(id);
1356
- if (missing.has(id)) return false;
1357
- for (const value of Object.values(prompt[id]?.inputs ?? {})) if (Array.isArray(value) && typeof value[0] === "string" && !complete(value[0], seen)) return false;
1358
- return true;
1359
- };
1403
+ const consumers = /* @__PURE__ */ new Map();
1404
+ for (const [id, n] of Object.entries(prompt)) for (const value of Object.values(n.inputs)) if (Array.isArray(value) && typeof value[0] === "string") {
1405
+ const list = consumers.get(value[0]) ?? [];
1406
+ list.push(id);
1407
+ consumers.set(value[0], list);
1408
+ }
1409
+ const blocked = new Set(missing.keys());
1410
+ const queue = [...blocked];
1411
+ for (let head = 0; head < queue.length; head++) for (const next of consumers.get(queue[head] ?? "") ?? []) if (!blocked.has(next)) {
1412
+ blocked.add(next);
1413
+ queue.push(next);
1414
+ }
1360
1415
  const outputs = Object.keys(prompt).filter((id) => schema.data.spec[prompt[id]?.class_type ?? ""]?.output_node === true);
1361
- const dropped = outputs.filter((id) => !complete(id, /* @__PURE__ */ new Set()));
1416
+ const dropped = outputs.filter((id) => blocked.has(id));
1362
1417
  const first = missing.values().next().value;
1363
1418
  if (first != null && outputs.length > 0 && dropped.length === outputs.length) throw new WorkflowConvertError("missing-required-input", first.message, first.node);
1364
1419
  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("; ")}`);
@@ -4414,8 +4469,13 @@ const ComfyManagerAPIPackList_ark = type({
4414
4469
  /** 🔶 NAMING DISCLAIMER: I call a "custom node package" => "PLUGIN" */
4415
4470
  const MANAGER_TIMING = {
4416
4471
  pollMs: 1e3,
4417
- installTimeoutMs: 60 * 6e4
4472
+ installTimeoutMs: 60 * 6e4,
4473
+ pollGraceMs: 12e4
4418
4474
  };
4475
+ /** an install the host refused or reported failed: ends the wait at once */
4476
+ var InstallFailed = class extends Error {};
4477
+ /** we lost sight of the task: the outcome is not known */
4478
+ var OutcomeUnknown = class extends Error {};
4419
4479
  /** what each generation does NOT serve (history means the `?ui_id=` form) */
4420
4480
  const NOT_SERVED = {
4421
4481
  v3: [
@@ -4521,7 +4581,7 @@ var ComfyManager = class {
4521
4581
  fetchPlugins: () => this.installedPluginView(api),
4522
4582
  fetchModels: () => this.installedModelView(),
4523
4583
  enqueuePlugin: (plugin, uiId) => this.enqueuePluginTask(api, plugin, uiId),
4524
- settle: (what, uiId) => this.settleByHistory(api, what, uiId)
4584
+ settle: (what, uiId, landed, sentId) => this.settleByHistory(api, what, uiId, landed, sentId)
4525
4585
  };
4526
4586
  }
4527
4587
  };
@@ -4570,7 +4630,8 @@ var ComfyManager = class {
4570
4630
  return this.modelList?.models.some((x) => x.name === name && x.installed === "True") ?? false;
4571
4631
  };
4572
4632
  this.modelsBeeingInstalled = /* @__PURE__ */ new Set();
4573
- this.installModel = async (model) => {
4633
+ this.installModel = async (model) => await this.installModelOutcome(model) === "installed";
4634
+ this.installModelOutcome = async (model) => {
4574
4635
  this.modelsBeeingInstalled.add(model.name);
4575
4636
  try {
4576
4637
  return await this.runInstall(`model "${model.name}"`, {
@@ -4583,7 +4644,8 @@ var ComfyManager = class {
4583
4644
  await this.post(this.route(api, "/manager/queue/install_model"), body);
4584
4645
  },
4585
4646
  landed: async (s) => {
4586
- return (await s.fetchModels()).models.find((x) => x.filename === model.filename && x.save_path === model.save_path && x.base === model.base)?.installed === "True";
4647
+ const row = (await s.fetchModels()).models.find((x) => x.filename === model.filename && x.save_path === model.save_path && x.base === model.base);
4648
+ return row == null ? null : row.installed === "True";
4587
4649
  }
4588
4650
  });
4589
4651
  } finally {
@@ -4617,10 +4679,43 @@ var ComfyManager = class {
4617
4679
  return "error";
4618
4680
  })();
4619
4681
  };
4682
+ this.requirementStatus = (req) => {
4683
+ const mirror = this.mirror();
4684
+ const packs = (() => {
4685
+ if (req.type === "customNodesByNodeKey") return mirror.plugins_byNodeKey.get(req.nodeName) ?? [];
4686
+ if (req.type === "customNodesByTitle") return [mirror.plugins_byTitle.get(req.title)].filter((x) => x != null);
4687
+ if (req.type === "customNodesByURI") return [mirror.plugins_byFile.get(req.uri)].filter((x) => x != null);
4688
+ return null;
4689
+ })();
4690
+ if (packs == null) return req.type === "modelInManager" ? this.getModelStatus(req.modelName) : null;
4691
+ if (packs.length === 0) return req.type === "customNodesByNodeKey" ? "unknown" : null;
4692
+ const statuses = packs.map((x) => this.getPluginStatus(x.title));
4693
+ if (statuses.some((x) => x === "installed" || x === "update-available")) return "installed";
4694
+ return statuses.every((x) => x === "not-installed") ? "not-installed" : "unknown";
4695
+ };
4696
+ this.checkRequirements = (requirements) => {
4697
+ const out = {
4698
+ missing: [],
4699
+ undecided: []
4700
+ };
4701
+ for (const req of requirements) {
4702
+ if (req.optional) continue;
4703
+ const status = this.requirementStatus(req);
4704
+ if (status === "not-installed") out.missing.push(req);
4705
+ else if (status === "unknown" || status === "error") out.undecided.push(req);
4706
+ }
4707
+ return out;
4708
+ };
4709
+ this.matchRequirements = (requirements) => {
4710
+ const check = this.checkRequirements(requirements);
4711
+ 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)" : ""));
4712
+ return check.missing.length === 0;
4713
+ };
4620
4714
  this.fetchPlugins = async (mode = "cache", skipUpdate = true) => {
4621
4715
  return this.strategy(await this.api()).fetchPlugins(mode, skipUpdate);
4622
4716
  };
4623
- this.installPlugin = async (plugin) => {
4717
+ this.installPlugin = async (plugin) => await this.installPluginOutcome(plugin) === "installed";
4718
+ this.installPluginOutcome = async (plugin) => {
4624
4719
  return this.runInstall(`plugin "${plugin.title}"`, {
4625
4720
  enqueue: (api, uiId) => this.strategy(api).enqueuePlugin(plugin, uiId),
4626
4721
  landed: async (_s, api) => {
@@ -4697,8 +4792,9 @@ var ComfyManager = class {
4697
4792
  };
4698
4793
  this.enqueuePluginTask = async (api, plugin, uiId) => {
4699
4794
  const url = plugin.files[0] ?? plugin.reference;
4795
+ const id = repoPath(url).split("/").pop() ?? url;
4700
4796
  const params = {
4701
- id: repoPath(url).split("/").pop() ?? url,
4797
+ id,
4702
4798
  version: "nightly",
4703
4799
  selected_version: "nightly",
4704
4800
  repository: url,
@@ -4711,18 +4807,26 @@ var ComfyManager = class {
4711
4807
  kind: "install",
4712
4808
  params
4713
4809
  });
4810
+ return id;
4714
4811
  };
4715
- this.settleByHistory = async (api, what, uiId) => {
4812
+ this.settleByHistory = async (api, what, uiId, landed, sentId) => {
4716
4813
  const route = this.route(api, "/manager/queue/history", `?ui_id=${encodeURIComponent(uiId)}`);
4814
+ const readEntry = async () => (await this.getValid(route, TaskHistory_ark)).history.status ?? null;
4717
4815
  const entry = await this.waitFor(what, async () => {
4718
- const status = (await this.getValid(route, TaskHistory_ark)).history.status;
4719
- if (status == null) await this.restartIdleQueue(api);
4720
- return status ?? null;
4816
+ const status = await readEntry();
4817
+ if (status != null) return status;
4818
+ if (await this.restartIdleQueue(api) !== "drained") return null;
4819
+ const late = await readEntry();
4820
+ if (late != null) return late;
4821
+ throw new InstallFailed("the task left the queue with no result (a queue/reset from the Manager UI or another client removes it)");
4721
4822
  });
4722
- if (entry.status_str === "success" || entry.status_str === "skip") return;
4823
+ if (entry.status_str === "success" || entry.status_str === "skip") {
4824
+ if (await this.endState(landed) !== false) return;
4825
+ 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");
4826
+ }
4723
4827
  const messages = entry.messages ?? [];
4724
4828
  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)" : "";
4725
- throw new Error(`the Manager reports ${entry.status_str}: ${messages.join(" | ")}${gate}`);
4829
+ throw new InstallFailed(`the Manager reports ${entry.status_str}: ${messages.join(" | ")}${gate}`);
4726
4830
  };
4727
4831
  this.restartIdleQueue = async (api) => {
4728
4832
  const status = await this.getValid(this.route(api, "/manager/queue/status"), QueueStatus_ark);
@@ -4733,29 +4837,52 @@ var ComfyManager = class {
4733
4837
  };
4734
4838
  this.settleByDrain = async (api, what, landed) => {
4735
4839
  await this.waitFor(what, async () => await this.restartIdleQueue(api) === "drained" ? true : null);
4736
- 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`);
4840
+ const state = await this.endState(landed);
4841
+ if (state === true) return;
4842
+ if (state === null) throw new OutcomeUnknown("the queue drained, but the lists cannot say whether it is installed");
4843
+ 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`);
4844
+ };
4845
+ this.endState = async (landed) => {
4846
+ try {
4847
+ return await landed();
4848
+ } catch (exception) {
4849
+ throw new OutcomeUnknown(`the task ran, but its end state could not be read: ${errorText(exception)}`);
4850
+ }
4737
4851
  };
4738
4852
  this.runInstall = async (what, p) => {
4853
+ const host = this.host.getServerHostHTTP();
4739
4854
  try {
4740
4855
  const api = await this.api();
4741
4856
  const s = this.strategy(api);
4742
4857
  const uiId = nanoid();
4743
- await p.enqueue(api, uiId);
4858
+ const sentId = await p.enqueue(api, uiId);
4744
4859
  await this.post(this.route(api, "/manager/queue/start"));
4745
- await s.settle(what, uiId, () => p.landed(s, api));
4860
+ await s.settle(what, uiId, () => p.landed(s, api), sentId);
4746
4861
  logSuccess(`${what} installed`);
4747
- return true;
4862
+ return "installed";
4748
4863
  } catch (exception) {
4749
- logError(`${what}: install failed on ${this.host.getServerHostHTTP()}: ${errorText(exception)}`);
4750
- return false;
4864
+ if (exception instanceof OutcomeUnknown) {
4865
+ 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`);
4866
+ return "unknown";
4867
+ }
4868
+ logError(`${what}: install failed on ${host}: ${errorText(exception)}`);
4869
+ return "failed";
4751
4870
  }
4752
4871
  };
4753
4872
  this.waitFor = async (what, check) => {
4754
4873
  const deadline = Date.now() + this.timing.installTimeoutMs;
4874
+ let lastAnswer = Date.now();
4755
4875
  for (;;) {
4756
- const value = await check();
4757
- if (value != null) return value;
4758
- if (Date.now() >= deadline) throw new Error(`${what} still running after ${this.timing.installTimeoutMs} ms (manager.timing.installTimeoutMs)`);
4876
+ try {
4877
+ const value = await check();
4878
+ lastAnswer = Date.now();
4879
+ if (value != null) return value;
4880
+ } catch (exception) {
4881
+ if (exception instanceof InstallFailed) throw exception;
4882
+ 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)}`);
4883
+ logError(`${what}: poll failed, still waiting: ${errorText(exception)}`);
4884
+ }
4885
+ if (Date.now() >= deadline) throw new OutcomeUnknown(`still running after ${this.timing.installTimeoutMs} ms (manager.timing.installTimeoutMs)`);
4759
4886
  await new Promise((resolve) => setTimeout(resolve, this.timing.pollMs));
4760
4887
  }
4761
4888
  };
@@ -6648,26 +6775,8 @@ var ComfyHost = class {
6648
6775
  constructor(data) {
6649
6776
  this.data = data;
6650
6777
  this.uploader = new ComfyUploader(this);
6651
- this.matchRequirements = (requirements) => {
6652
- const repo = comfyts.registry;
6653
- for (const req of requirements) {
6654
- if (req.optional) continue;
6655
- if (req.type === "customNodesByNodeKey") {
6656
- if (!(repo.plugins_byNodeKey.get(req.nodeName) ?? []).find((i) => this.manager.isPluginInstalled(i.title))) return false;
6657
- } else if (req.type === "customNodesByTitle") {
6658
- const plugin = repo.plugins_byTitle.get(req.title);
6659
- if (plugin == null) continue;
6660
- if (!this.manager.isPluginInstalled(plugin.title)) return false;
6661
- } else if (req.type === "customNodesByURI") {
6662
- const plugin = repo.plugins_byFile.get(req.uri);
6663
- if (plugin == null) continue;
6664
- if (!this.manager.isPluginInstalled(plugin.title)) return false;
6665
- } else if (req.type === "modelInManager") {
6666
- if (!this.manager.isModelInstalled(req.modelName)) return false;
6667
- }
6668
- }
6669
- return true;
6670
- };
6778
+ this.matchRequirements = (requirements) => this.manager.matchRequirements(requirements);
6779
+ this.checkRequirements = (requirements) => this.manager.checkRequirements(requirements);
6671
6780
  this.serverLogs = [];
6672
6781
  this.wantLog = true;
6673
6782
  this.maxLogs = 200;