comfy-ts 2.2.0 → 2.4.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 (54) hide show
  1. package/README.md +13 -0
  2. package/dist/{DefinedWorkflow-CwHInZgn.js → DefinedWorkflow-QrhT6V66.js} +441 -9
  3. package/dist/DefinedWorkflow-QrhT6V66.js.map +1 -0
  4. package/dist/{DraftsSt-omWuBSej.js → DraftsSt-D9Fhk4qR.js} +2 -2
  5. package/dist/{DraftsSt-omWuBSej.js.map → DraftsSt-D9Fhk4qR.js.map} +1 -1
  6. package/dist/cli.js +116 -8
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +292 -24
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +147 -9
  11. package/dist/index.d.ts +147 -9
  12. package/dist/index.js +280 -25
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-serve-C1oo5ilG.js → run-serve-C9E8dyLP.js} +7 -3
  15. package/dist/run-serve-C9E8dyLP.js.map +1 -0
  16. package/dist/{run-tui-CuVst-nc.js → run-tui-cawSJuuh.js} +60 -121
  17. package/dist/run-tui-cawSJuuh.js.map +1 -0
  18. package/dist/{state-CvMt0W1-.js → state-BbKuSDCV.js} +38 -77
  19. package/dist/state-BbKuSDCV.js.map +1 -0
  20. package/dist/web.d.ts +147 -9
  21. package/dist/web.js +280 -25
  22. package/dist/web.js.map +1 -1
  23. package/guide-for-agents.md +3 -0
  24. package/package.json +2 -1
  25. package/src/cli/comfy-ts-cli.ts +16 -1
  26. package/src/cli/flags.ts +14 -0
  27. package/src/cli/gen.ts +2 -4
  28. package/src/cli/loras.ts +113 -0
  29. package/src/cli/serve/ServeApp.ts +4 -0
  30. package/src/cli/serve/applyVarPayload.ts +1 -1
  31. package/src/cli/tui/components/LorasOverlay.tsx +18 -5
  32. package/src/cli/tui/components/StatusBar.tsx +1 -0
  33. package/src/cli/tui/components/TuiApp.tsx +1 -0
  34. package/src/cli/tui/imageClipboard.ts +3 -3
  35. package/src/cli/tui/protocolImagePainter.ts +1 -1
  36. package/src/cli/tui/run-tui.tsx +2 -2
  37. package/src/cli/tui/state/ExecSt.ts +2 -2
  38. package/src/cli/tui/state/HostSt.ts +1 -1
  39. package/src/cli/tui/state/LorasSt.ts +60 -15
  40. package/src/cli/tui/state/PreviewSt.ts +1 -1
  41. package/src/cli/tui/state/SettingsSt.ts +1 -1
  42. package/src/coreExports.ts +21 -1
  43. package/src/host/ComfyHost.ts +51 -3
  44. package/src/host/loraInfoCache.ts +216 -0
  45. package/src/host/loraManagerApi.ts +131 -27
  46. package/src/runner/ComfyExecution.ts +1 -1
  47. package/src/runner/outputPath.ts +3 -3
  48. package/src/utils/isRecord.ts +4 -0
  49. package/src/vars/ComfyVars.ts +13 -7
  50. package/src/vars/loraKeywords.ts +48 -5
  51. package/dist/DefinedWorkflow-CwHInZgn.js.map +0 -1
  52. package/dist/run-serve-C1oo5ilG.js.map +0 -1
  53. package/dist/run-tui-CuVst-nc.js.map +0 -1
  54. package/dist/state-CvMt0W1-.js.map +0 -1
package/dist/web.js CHANGED
@@ -101,7 +101,7 @@ function getComfyStorage() {
101
101
  }
102
102
  //#endregion
103
103
  //#region package.json
104
- var version = "2.2.0";
104
+ var version = "2.4.0";
105
105
  //#endregion
106
106
  //#region src/litegraph/LiteGraphLinkID.ts
107
107
  const asLiteGraphLinkID = (id) => id;
@@ -733,7 +733,7 @@ const ComfyDefaultNodeWhenUnknown_Schema = {
733
733
  };
734
734
  //#endregion
735
735
  //#region src/sdk-generator/inputWidgetKind.ts
736
- const isRecord = (x) => typeof x === "object" && x != null && !Array.isArray(x);
736
+ const isRecord$1 = (x) => typeof x === "object" && x != null && !Array.isArray(x);
737
737
  /**
738
738
  * seed phantom: a TRUTHY `control_after_generate` adds one consumed value.
739
739
  * The frontend creates the control widget on truthiness, and real 2026 hosts
@@ -750,7 +750,7 @@ const flattenInputSections = (inputs) => {
750
750
  const out = [];
751
751
  for (const section of ["required", "optional"]) {
752
752
  const sec = inputs[section];
753
- if (!isRecord(sec)) continue;
753
+ if (!isRecord$1(sec)) continue;
754
754
  for (const [name, spec] of Object.entries(sec)) {
755
755
  if (!Array.isArray(spec) || spec.length === 0) continue;
756
756
  const t = spec[0];
@@ -770,10 +770,10 @@ const parseDynamicOptions = (options) => {
770
770
  if (options.length === 0) return null;
771
771
  const out = [];
772
772
  for (const entry of options) {
773
- if (!isRecord(entry)) return null;
773
+ if (!isRecord$1(entry)) return null;
774
774
  const key = entry["key"];
775
775
  const inputs = entry["inputs"];
776
- if (typeof key !== "string" || !isRecord(inputs)) return null;
776
+ if (typeof key !== "string" || !isRecord$1(inputs)) return null;
777
777
  out.push({
778
778
  key,
779
779
  inputs: flattenInputSections(inputs)
@@ -797,7 +797,7 @@ const parseContainer = (template) => {
797
797
  return {
798
798
  kind: "dynamic-container",
799
799
  instanceNames: names,
800
- requiredCount: isRecord(input) && isRecord(input["required"]) && Object.keys(input["required"]).length > 0 ? Math.min(min, names.length) : 0
800
+ requiredCount: isRecord$1(input) && isRecord$1(input["required"]) && Object.keys(input["required"]).length > 0 ? Math.min(min, names.length) : 0
801
801
  };
802
802
  };
803
803
  /**
@@ -808,8 +808,8 @@ const parseContainer = (template) => {
808
808
  * typed instance keys and the container stays builderBase territory.
809
809
  */
810
810
  const containerInstanceSlotType = (opts) => {
811
- const template = (isRecord(opts) ? opts : null)?.["template"];
812
- if (!isRecord(template) || !isRecord(template["input"])) return null;
811
+ const template = (isRecord$1(opts) ? opts : null)?.["template"];
812
+ if (!isRecord$1(template) || !isRecord$1(template["input"])) return null;
813
813
  const subs = flattenInputSections(template["input"]);
814
814
  const first = subs[0];
815
815
  if (subs.length !== 1 || first == null || typeof first.type !== "string") return null;
@@ -835,7 +835,7 @@ const EMPTY_CONFIG_FRONTEND_WIDGETS = { LOAD_3D: { prefixValues: [
835
835
  "clear"
836
836
  ] } };
837
837
  const classifyWidgetInput = (p) => {
838
- const o = isRecord(p.opts) ? p.opts : null;
838
+ const o = isRecord$1(p.opts) ? p.opts : null;
839
839
  if (o?.["forceInput"] === true) return { kind: "slot" };
840
840
  if (Array.isArray(p.type) || p.isEnumUnion === true) {
841
841
  const tn = typeof p.type === "string" ? p.type : "COMBO";
@@ -874,8 +874,8 @@ const classifyWidgetInput = (p) => {
874
874
  };
875
875
  }
876
876
  const template = o?.["template"];
877
- if (isRecord(template)) {
878
- if (isRecord(template["input"])) return parseContainer(template);
877
+ if (isRecord$1(template)) {
878
+ if (isRecord$1(template["input"])) return parseContainer(template);
879
879
  return { kind: "slot" };
880
880
  }
881
881
  if (o?.["socketless"] === true) return {
@@ -906,7 +906,7 @@ const classifySchemaInput = (input) => classifyWidgetInput({
906
906
  * backend accepts an explicit null but errors on an ABSENT required key.
907
907
  */
908
908
  const defaultValueForWidget = (p) => {
909
- const o = isRecord(p.opts) ? p.opts : null;
909
+ const o = isRecord$1(p.opts) ? p.opts : null;
910
910
  if (o != null && o["default"] !== void 0) return o["default"];
911
911
  const widgetTypeName = typeof o?.["widgetType"] === "string" ? o["widgetType"] : p.type;
912
912
  if (widgetTypeName === "INT" || widgetTypeName === "FLOAT") return 0;
@@ -997,7 +997,7 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
997
997
  if (value == null) return null;
998
998
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
999
999
  if (Array.isArray(value)) return { __value__: value };
1000
- if (!p.strict && isRecord(value)) return value;
1000
+ if (!p.strict && isRecord$1(value)) return value;
1001
1001
  throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}) has an invalid widget value for "${p.promptName}": ${JSON.stringify(value)}`, node);
1002
1002
  };
1003
1003
  /** named wins, then positional cursor (+prefixLen skips leading button values, LOAD_3D); filled=true when both miss (caller falls back to the schema default) */
@@ -1648,8 +1648,8 @@ var LiteGraphCtx = class {
1648
1648
  //#endregion
1649
1649
  //#region src/runner/outputPath.ts
1650
1650
  /**
1651
- * local output naming, relative to `.comfy-ts/outputs/` (his repro
1652
- * 2026-07-31): the server filename is NOT unique — cloud hosts reset the
1651
+ * local output naming, relative to `.comfy-ts/outputs/`:
1652
+ * the server filename is NOT unique — cloud hosts reset the
1653
1653
  * `_00001_` counter every run, so trusting it overwrote the same file — and
1654
1654
  * a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
1655
1655
  * prefix. Local names are ours: dir from the prompt's own filename_prefix
@@ -1694,7 +1694,7 @@ const withExtension = (path, ext) => {
1694
1694
  /**
1695
1695
  * never-overwrite guard: bump `-2`, `-3`, … while the path exists on disk OR
1696
1696
  * was already CLAIMED by a still-downloading retrieval (two same-second runs
1697
- * on a counter-resetting cloud host compute the same name — reviewer catch).
1697
+ * on a counter-resetting cloud host compute the same name).
1698
1698
  * The chosen path is claimed before returning.
1699
1699
  */
1700
1700
  const uniquifyOutputPath = (p) => {
@@ -3884,6 +3884,191 @@ var ResilientWebSocketClient = class {
3884
3884
  }
3885
3885
  };
3886
3886
  //#endregion
3887
+ //#region src/utils/isRecord.ts
3888
+ /** narrows unknown wire json to an indexable object (arrays and null excluded) */
3889
+ function isRecord(v) {
3890
+ return typeof v === "object" && v !== null && !Array.isArray(v);
3891
+ }
3892
+ type({
3893
+ items: "unknown[]",
3894
+ "total?": "number"
3895
+ });
3896
+ function readString(item, key) {
3897
+ const v = item[key];
3898
+ return typeof v === "string" && v !== "" ? v : null;
3899
+ }
3900
+ function readStringArray(item, key) {
3901
+ const v = item[key];
3902
+ if (!Array.isArray(v)) return [];
3903
+ return v.filter((x) => typeof x === "string" && x !== "");
3904
+ }
3905
+ function lmModelName(item) {
3906
+ return readString(item, "model_name");
3907
+ }
3908
+ function lmBaseModel(item) {
3909
+ return readString(item, "base_model");
3910
+ }
3911
+ function lmPreviewUrl(item) {
3912
+ return readString(item, "preview_url");
3913
+ }
3914
+ function lmTags(item) {
3915
+ return readStringArray(item, "tags");
3916
+ }
3917
+ /** the trigger words: civitai's `trainedWords`, absent for a lora nobody published */
3918
+ function lmTrainedWords(item) {
3919
+ const civitai = item["civitai"];
3920
+ if (!isRecord(civitai)) return [];
3921
+ return readStringArray(civitai, "trainedWords");
3922
+ }
3923
+ /**
3924
+ * the ONE key space where a host's object_info spelling of a lora meets
3925
+ * lora-manager's: lowercase, forward slashes, no model extension.
3926
+ * `styles\Aurora.safetensors` and lm's folder `styles` + file_name `aurora`
3927
+ * both become `styles/aurora`.
3928
+ */
3929
+ function loraKey(name) {
3930
+ return name.replaceAll("\\", "/").replace(/\.(safetensors|st|pt|ckpt)$/i, "").toLowerCase();
3931
+ }
3932
+ /** the file's own name, windows separators included (`styles\x.safetensors` → `x.safetensors`) */
3933
+ function loraBasename(name) {
3934
+ return basename(name.replaceAll("\\", "/"));
3935
+ }
3936
+ //#endregion
3937
+ //#region src/host/loraInfoCache.ts
3938
+ function loraMirrorPath(hostId) {
3939
+ return comfyts.resolveFromHosts(join(hostId, "loras.json"));
3940
+ }
3941
+ /** null = never synced (or unreadable, which is LOGGED) */
3942
+ function readLoraMirror(hostId) {
3943
+ const path = loraMirrorPath(hostId);
3944
+ const text = getComfyStorage().readTextIfExists(path);
3945
+ if (text == null) return null;
3946
+ try {
3947
+ const raw = JSON.parse(text);
3948
+ if (!isRecord(raw)) return null;
3949
+ const rawLoras = raw["loras"];
3950
+ if (!isRecord(rawLoras)) return null;
3951
+ const loras = {};
3952
+ for (const [key, item] of Object.entries(rawLoras)) if (isRecord(item)) loras[key] = item;
3953
+ const str = (key, fallback) => {
3954
+ const v = raw[key];
3955
+ return typeof v === "string" ? v : fallback;
3956
+ };
3957
+ return {
3958
+ hostId: str("hostId", hostId),
3959
+ hostUrl: str("hostUrl", ""),
3960
+ fetchedAt: str("fetchedAt", ""),
3961
+ count: Object.keys(loras).length,
3962
+ loras
3963
+ };
3964
+ } catch (e) {
3965
+ logError(`[loraInfoCache] unreadable ${path}: ${String(e)}`);
3966
+ return null;
3967
+ }
3968
+ }
3969
+ /**
3970
+ * the read model: each registered host's mirror, kept PER HOST.
3971
+ *
3972
+ * Per host, not merged into one map, because the same file name on two hosts is
3973
+ * routinely a different model. A merged map served whichever host loaded first,
3974
+ * so on the other host the overlay showed the wrong model name and the prompt
3975
+ * silently received the wrong trigger words — a bad generation with no error
3976
+ * anywhere. Callers that know their host say so; the rest fall back to any host
3977
+ * that has the lora, which is still better than nothing for a display name.
3978
+ *
3979
+ * Plain (non-observable) on purpose: the loras overlay reads this from inside a
3980
+ * mobx render. The storage seam has no readdir, so the host set comes from
3981
+ * `comfyts.hosts` — exactly the hosts this process can be asked about.
3982
+ */
3983
+ const byHost = /* @__PURE__ */ new Map();
3984
+ /** hosts already looked for, INCLUDING the ones with no mirror (see reloadLoraInfoCache) */
3985
+ const loadedHostIds = /* @__PURE__ */ new Set();
3986
+ function ensureLoaded() {
3987
+ for (const hostId of comfyts.hosts.keys()) {
3988
+ if (loadedHostIds.has(hostId)) continue;
3989
+ loadedHostIds.add(hostId);
3990
+ const mirror = readLoraMirror(hostId);
3991
+ if (mirror == null) continue;
3992
+ byHost.set(hostId, new Map(Object.entries(mirror.loras)));
3993
+ }
3994
+ }
3995
+ /**
3996
+ * forget everything loaded, so the next read picks up a fresh `comfy-ts loras`.
3997
+ * A long-lived process (the TUI, `comfy-ts serve`) has no other way to see a
3998
+ * re-sync that happened in another terminal.
3999
+ */
4000
+ function reloadLoraInfoCache() {
4001
+ byHost.clear();
4002
+ loadedHostIds.clear();
4003
+ }
4004
+ /**
4005
+ * the lm item for a raw lora name (`styles\x.safetensors`).
4006
+ * `hostId` picks the mirror that actually describes this host's file; without
4007
+ * it, any host that knows the name answers. null when unsynced/unknown.
4008
+ */
4009
+ function getLoraInfo(name, hostId) {
4010
+ ensureLoaded();
4011
+ const key = loraKey(name);
4012
+ if (hostId != null) {
4013
+ const own = byHost.get(hostId);
4014
+ if (own != null) return own.get(key) ?? null;
4015
+ }
4016
+ for (const mirror of byHost.values()) {
4017
+ const hit = mirror.get(key);
4018
+ if (hit != null) return hit;
4019
+ }
4020
+ return null;
4021
+ }
4022
+ /** civitai trigger words for this lora, in civitai's order */
4023
+ function getLoraTriggerWords(name, hostId) {
4024
+ const info = getLoraInfo(name, hostId);
4025
+ return info == null ? [] : lmTrainedWords(info);
4026
+ }
4027
+ /** the human name (`Aurora Ink Wash`), falling back to the file's own name */
4028
+ function getLoraDisplayName(name, hostId) {
4029
+ const info = getLoraInfo(name, hostId);
4030
+ return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
4031
+ }
4032
+ /** server-relative preview url from the mirror, null when unsynced/unknown */
4033
+ function getLoraPreviewUrl(name, hostId) {
4034
+ const info = getLoraInfo(name, hostId);
4035
+ return info == null ? null : lmPreviewUrl(info);
4036
+ }
4037
+ /** the lora's NAMES: the file, and the model name a human would call it by */
4038
+ function loraSearchNames(name, hostId) {
4039
+ const names = [loraBasename(name), name.replaceAll("\\", "/")];
4040
+ const info = getLoraInfo(name, hostId);
4041
+ const modelName = info == null ? null : lmModelName(info);
4042
+ if (modelName != null) names.push(modelName);
4043
+ return names;
4044
+ }
4045
+ /** the lora's FREE TEXT: tags, base model, trigger words */
4046
+ function loraSearchText(name, hostId) {
4047
+ const info = getLoraInfo(name, hostId);
4048
+ if (info == null) return [];
4049
+ const text = [...lmTags(info), ...lmTrainedWords(info)];
4050
+ const baseModel = lmBaseModel(info);
4051
+ if (baseModel != null) text.push(baseModel);
4052
+ return text;
4053
+ }
4054
+ /**
4055
+ * the loras overlay filter: find a lora by its human name, not only by the file
4056
+ * name. EVERY whitespace-separated token must be a SUBSTRING of some field — order
4057
+ * free, so `aurora ink`, `ink aurora` and `styles wash` all land on the same
4058
+ * lora. NOT fuzzyMatch: a subsequence match over phrases this long matches
4059
+ * nearly everything. Measured on a real collection, filtering by each lora's
4060
+ * own file name: this rule peaks at 8 hits where fuzzyMatch matched a third of
4061
+ * every lora present.
4062
+ * Fields are matched one by one, never as a concatenated haystack, for the same
4063
+ * reason. `tests/lora-corpus.private.test.ts` keeps that measurement runnable.
4064
+ */
4065
+ function loraMatchesFilter(name, filter, hostId) {
4066
+ const tokens = filter.toLowerCase().split(/\s+/).filter((t) => t !== "");
4067
+ if (tokens.length === 0) return true;
4068
+ const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
4069
+ return tokens.every((token) => fields.some((field) => field.includes(token)));
4070
+ }
4071
+ //#endregion
3887
4072
  //#region src/vars/loraKeywords.ts
3888
4073
  /**
3889
4074
  * hand-assigned trigger keyword(s) per lora name — set via ⌃K in the TUI loras
@@ -3891,6 +4076,12 @@ var ResilientWebSocketClient = class {
3891
4076
  * `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data
3892
4077
  * and must survive a cache wipe). Observable map: overlay rows re-render on
3893
4078
  * assignment. Keys are the RAW lora names (folder/file.safetensors).
4079
+ *
4080
+ * This file is the OVERRIDE layer. Below it sits the lora-manager mirror's
4081
+ * civitai trigger words (src/host/loraInfoCache.ts, refreshed by
4082
+ * `comfy-ts loras`), so most loras carry a keyword without anyone typing one.
4083
+ * The overlay renders a mirror-sourced keyword dim and a hand-typed one yellow,
4084
+ * and ⌃D drops the override to fall back to the mirror again.
3894
4085
  */
3895
4086
  const keywords = observable.map();
3896
4087
  let loaded = false;
@@ -3913,18 +4104,50 @@ function loadOnce() {
3913
4104
  logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
3914
4105
  }
3915
4106
  }
3916
- function getLoraKeyword(name) {
4107
+ /** the hand keyword when this lora HAS an entry (`''` included), else the mirror's trigger words */
4108
+ function getLoraKeyword(name, hostId) {
4109
+ loadOnce();
4110
+ const hand = keywords.get(name);
4111
+ if (hand != null) return hand;
4112
+ return getLoraTriggerWords(name, hostId).join(", ");
4113
+ }
4114
+ /** true when the keyword shown comes from the lora-manager mirror, not from ⌃K */
4115
+ function isLoraKeywordFromMirror(name, hostId) {
3917
4116
  loadOnce();
3918
- return keywords.get(name) ?? "";
4117
+ return !keywords.has(name) && getLoraTriggerWords(name, hostId).length > 0;
4118
+ }
4119
+ /** what `clearLoraKeywordOverride` would restore this lora to, `''` when nothing */
4120
+ function loraKeywordFromMirror(name, hostId) {
4121
+ return getLoraTriggerWords(name, hostId).join(", ");
3919
4122
  }
3920
- /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
3921
- function setLoraKeyword(name, keyword) {
4123
+ /**
4124
+ * drop the hand entry entirely, so the mirror's trigger words apply again.
4125
+ * The way BACK from an empty-string tombstone: without it, clearing a keyword on
4126
+ * a lora that has trigger words was a one-way door only a text editor could undo.
4127
+ */
4128
+ function clearLoraKeywordOverride(name) {
4129
+ loadOnce();
4130
+ if (!keywords.has(name)) return;
4131
+ runInAction(() => void keywords.delete(name));
4132
+ writeKeywords();
4133
+ }
4134
+ /**
4135
+ * empty keyword deletes the entry — EXCEPT when the mirror has trigger words for
4136
+ * this lora: there `''` is stored as an explicit tombstone, the only way to say
4137
+ * "inject nothing" about a lora civitai gave words to. Every set writes the file
4138
+ * (tiny, rare).
4139
+ */
4140
+ function setLoraKeyword(name, keyword, hostId) {
3922
4141
  loadOnce();
3923
4142
  const trimmed = keyword.trim();
3924
4143
  runInAction(() => {
3925
- if (trimmed === "") keywords.delete(name);
4144
+ if (trimmed === "" && getLoraTriggerWords(name, hostId).length === 0) keywords.delete(name);
3926
4145
  else keywords.set(name, trimmed);
3927
4146
  });
4147
+ writeKeywords();
4148
+ }
4149
+ /** every set writes the file: it is tiny and hand-edited rarely */
4150
+ function writeKeywords() {
3928
4151
  const path = filePath();
3929
4152
  try {
3930
4153
  getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
@@ -4031,7 +4254,7 @@ var PromptVar = class extends ComfyVarBase {
4031
4254
  injectedKeywords() {
4032
4255
  const src = this.promptOpts.loraKeywordsFrom;
4033
4256
  if (src == null) return [];
4034
- return [...new Set(src.activeNames().map(getLoraKeyword).filter((k) => k !== ""))];
4257
+ return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
4035
4258
  }
4036
4259
  outValue() {
4037
4260
  const pos = [];
@@ -4223,6 +4446,7 @@ var LorasVar = class LorasVar extends ComfyVar {
4223
4446
  this.kind = "loras";
4224
4447
  this.prev = {};
4225
4448
  this.resolvedOptions = null;
4449
+ this.hostId = void 0;
4226
4450
  }
4227
4451
  get options() {
4228
4452
  if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
@@ -4233,6 +4457,7 @@ var LorasVar = class LorasVar extends ComfyVar {
4233
4457
  * cast: whitelist family 1 (agent/coding.md) — getLoras() returns the runtime
4234
4458
  * values of the SAME object_info enum the generated E_LoraName union comes from */
4235
4459
  bindHost(host) {
4460
+ this.hostId = host.data?.id;
4236
4461
  if (!(this.optionsSource instanceof RegExp)) return;
4237
4462
  this.resolvedOptions = host.schema.getLoras(this.optionsSource);
4238
4463
  }
@@ -4351,7 +4576,7 @@ const DEFAULT_SIZE_PRESETS = [
4351
4576
  }
4352
4577
  ];
4353
4578
  /** width/height picker: presets + free `WxH` entry + optionally the LIVE
4354
- * size of a linked image var (his ask 2026-07-30: the widget shows
4579
+ * size of a linked image var (the widget shows
4355
4580
  * `WxH size of image '<name>'` as a pickable row) */
4356
4581
  var SizeVar = class extends ComfyVar {
4357
4582
  constructor(defaultValue = {
@@ -4559,6 +4784,14 @@ var DefinedWorkflow = class {
4559
4784
  };
4560
4785
  //#endregion
4561
4786
  //#region src/host/ComfyHost.ts
4787
+ /** the host never came up within ConnectOptions.timeoutMs */
4788
+ var ComfyHostUnreachableError = class extends Error {
4789
+ constructor(..._args) {
4790
+ super(..._args);
4791
+ this.name = "ComfyHostUnreachableError";
4792
+ }
4793
+ };
4794
+ const DEFAULT_CONNECT_TIMEOUT_MS = 3e4;
4562
4795
  /** auth failure with a SPECIFIC meaning (per the Comfy Cloud error table):
4563
4796
  * 401 invalid/missing key · 402 insufficient credits · 429 subscription inactive
4564
4797
  * (or plain rate limiting on non-cloud hosts). The key value never appears here. */
@@ -4708,14 +4941,25 @@ var ComfyHost = class {
4708
4941
  this._readyResolve = res;
4709
4942
  this._readyReject = rej;
4710
4943
  });
4944
+ const timeoutMs = p.timeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
4945
+ if (timeoutMs > 0 && Number.isFinite(timeoutMs)) {
4946
+ this._connectTimer = setTimeout(() => {
4947
+ this.markFailed(new ComfyHostUnreachableError(`host '${this.data.id}' did not come up within ${timeoutMs}ms at ${this.getWSUrl()} — is ComfyUI running there ?`));
4948
+ }, timeoutMs);
4949
+ this._connectTimer.unref?.();
4950
+ }
4711
4951
  this.initWebsocket();
4712
4952
  }
4713
4953
  return this._ready;
4714
4954
  };
4955
+ this._connectTimer = null;
4715
4956
  this.disconnect = () => {
4957
+ this.clearConnectTimer();
4716
4958
  this.ws?.disconnectPermanently();
4717
4959
  this.ws = null;
4718
4960
  this._ready = null;
4961
+ this._readyResolve = null;
4962
+ this._readyReject = null;
4719
4963
  };
4720
4964
  this.ws = null;
4721
4965
  this._sessionResolve = null;
@@ -4860,15 +5104,26 @@ var ComfyHost = class {
4860
5104
  get isConnected() {
4861
5105
  return this.ws?.isOpen ?? false;
4862
5106
  }
5107
+ clearConnectTimer() {
5108
+ if (this._connectTimer != null) clearTimeout(this._connectTimer);
5109
+ this._connectTimer = null;
5110
+ }
4863
5111
  markReady() {
5112
+ this.clearConnectTimer();
4864
5113
  this._readyResolve?.();
4865
5114
  this._readyResolve = null;
4866
5115
  this._readyReject = null;
4867
5116
  }
4868
5117
  markFailed(error) {
4869
- this._readyReject?.(error);
5118
+ this.clearConnectTimer();
5119
+ const reject = this._readyReject;
5120
+ if (reject == null) return;
4870
5121
  this._readyResolve = null;
4871
5122
  this._readyReject = null;
5123
+ this._ready = null;
5124
+ this.ws?.disconnectPermanently();
5125
+ this.ws = null;
5126
+ reject(error);
4872
5127
  }
4873
5128
  async writeSDKToDisk() {
4874
5129
  if (this.data.sdkAutoWrite === false) return;
@@ -5727,6 +5982,6 @@ function loraTag(name, strength = 1, clipStrength) {
5727
5982
  */
5728
5983
  setDefaultComfyStorage(createMemoryStorage());
5729
5984
  //#endregion
5730
- export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, PromptVar, ResilientWebSocketClient, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraKeyword, hostIdToNamespace, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
5985
+ export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, PromptVar, ResilientWebSocketClient, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
5731
5986
 
5732
5987
  //# sourceMappingURL=web.js.map