comfy-ts 2.3.0 → 2.4.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.
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 +268 -23
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +150 -9
  11. package/dist/index.d.ts +150 -9
  12. package/dist/index.js +257 -24
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-serve-CfzOH-AR.js → run-serve-C9E8dyLP.js} +3 -3
  15. package/dist/run-serve-C9E8dyLP.js.map +1 -0
  16. package/dist/{run-tui-_LD0DoGe.js → run-tui-8si-rVW0.js} +60 -121
  17. package/dist/run-tui-8si-rVW0.js.map +1 -0
  18. package/dist/{state-C-OOEcp3.js → state-C0ARiFFM.js} +15 -76
  19. package/dist/state-C0ARiFFM.js.map +1 -0
  20. package/dist/web.d.ts +150 -9
  21. package/dist/web.js +257 -24
  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/applyVarPayload.ts +1 -1
  30. package/src/cli/tui/components/LorasOverlay.tsx +18 -5
  31. package/src/cli/tui/components/StatusBar.tsx +1 -0
  32. package/src/cli/tui/components/TuiApp.tsx +1 -0
  33. package/src/cli/tui/imageClipboard.ts +3 -3
  34. package/src/cli/tui/protocolImagePainter.ts +1 -1
  35. package/src/cli/tui/run-tui.tsx +2 -2
  36. package/src/cli/tui/state/ExecSt.ts +2 -2
  37. package/src/cli/tui/state/HostSt.ts +1 -1
  38. package/src/cli/tui/state/LorasSt.ts +60 -15
  39. package/src/cli/tui/state/PreviewSt.ts +1 -1
  40. package/src/cli/tui/state/SettingsSt.ts +1 -1
  41. package/src/coreExports.ts +20 -1
  42. package/src/host/ComfyHost.ts +10 -1
  43. package/src/host/ResilientWebsocket.ts +20 -0
  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-CfzOH-AR.js.map +0 -1
  53. package/dist/run-tui-_LD0DoGe.js.map +0 -1
  54. package/dist/state-C-OOEcp3.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.3.0";
104
+ var version = "2.4.1";
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) => {
@@ -3802,6 +3802,7 @@ var ResilientWebSocketClient = class {
3802
3802
  this.messageBuffer = [];
3803
3803
  this.isOpen = false;
3804
3804
  this.debugMessages = [];
3805
+ this.hasEverOpened = false;
3805
3806
  this.permanentlyClosed = false;
3806
3807
  this.url = options.url();
3807
3808
  this.connect();
@@ -3853,6 +3854,7 @@ var ResilientWebSocketClient = class {
3853
3854
  ws.onopen = () => {
3854
3855
  if (ws !== this.currentWS) return;
3855
3856
  this.addInfo("✅ WebSocket connected to " + this.url);
3857
+ this.hasEverOpened = true;
3856
3858
  this.isOpen = true;
3857
3859
  this.options.onConnectOrReconnect();
3858
3860
  this.flushMessageBuffer();
@@ -3863,6 +3865,11 @@ var ResilientWebSocketClient = class {
3863
3865
  this.options.onClose();
3864
3866
  if (this.permanentlyClosed) return;
3865
3867
  this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
3868
+ if (!this.hasEverOpened && this.options.onFirstConnectFailed != null) {
3869
+ this.permanentlyClosed = true;
3870
+ this.options.onFirstConnectFailed(/* @__PURE__ */ new Error(`connection refused (code=${event.code}${event.reason === "" ? "" : `, ${event.reason}`})`));
3871
+ return;
3872
+ }
3866
3873
  this.addInfo("⏱️ reconnecting in 2 seconds...");
3867
3874
  this.reconnectTimeout = setTimeout(() => void this.connect(), 2e3);
3868
3875
  };
@@ -3884,6 +3891,191 @@ var ResilientWebSocketClient = class {
3884
3891
  }
3885
3892
  };
3886
3893
  //#endregion
3894
+ //#region src/utils/isRecord.ts
3895
+ /** narrows unknown wire json to an indexable object (arrays and null excluded) */
3896
+ function isRecord(v) {
3897
+ return typeof v === "object" && v !== null && !Array.isArray(v);
3898
+ }
3899
+ type({
3900
+ items: "unknown[]",
3901
+ "total?": "number"
3902
+ });
3903
+ function readString(item, key) {
3904
+ const v = item[key];
3905
+ return typeof v === "string" && v !== "" ? v : null;
3906
+ }
3907
+ function readStringArray(item, key) {
3908
+ const v = item[key];
3909
+ if (!Array.isArray(v)) return [];
3910
+ return v.filter((x) => typeof x === "string" && x !== "");
3911
+ }
3912
+ function lmModelName(item) {
3913
+ return readString(item, "model_name");
3914
+ }
3915
+ function lmBaseModel(item) {
3916
+ return readString(item, "base_model");
3917
+ }
3918
+ function lmPreviewUrl(item) {
3919
+ return readString(item, "preview_url");
3920
+ }
3921
+ function lmTags(item) {
3922
+ return readStringArray(item, "tags");
3923
+ }
3924
+ /** the trigger words: civitai's `trainedWords`, absent for a lora nobody published */
3925
+ function lmTrainedWords(item) {
3926
+ const civitai = item["civitai"];
3927
+ if (!isRecord(civitai)) return [];
3928
+ return readStringArray(civitai, "trainedWords");
3929
+ }
3930
+ /**
3931
+ * the ONE key space where a host's object_info spelling of a lora meets
3932
+ * lora-manager's: lowercase, forward slashes, no model extension.
3933
+ * `styles\Aurora.safetensors` and lm's folder `styles` + file_name `aurora`
3934
+ * both become `styles/aurora`.
3935
+ */
3936
+ function loraKey(name) {
3937
+ return name.replaceAll("\\", "/").replace(/\.(safetensors|st|pt|ckpt)$/i, "").toLowerCase();
3938
+ }
3939
+ /** the file's own name, windows separators included (`styles\x.safetensors` → `x.safetensors`) */
3940
+ function loraBasename(name) {
3941
+ return basename(name.replaceAll("\\", "/"));
3942
+ }
3943
+ //#endregion
3944
+ //#region src/host/loraInfoCache.ts
3945
+ function loraMirrorPath(hostId) {
3946
+ return comfyts.resolveFromHosts(join(hostId, "loras.json"));
3947
+ }
3948
+ /** null = never synced (or unreadable, which is LOGGED) */
3949
+ function readLoraMirror(hostId) {
3950
+ const path = loraMirrorPath(hostId);
3951
+ const text = getComfyStorage().readTextIfExists(path);
3952
+ if (text == null) return null;
3953
+ try {
3954
+ const raw = JSON.parse(text);
3955
+ if (!isRecord(raw)) return null;
3956
+ const rawLoras = raw["loras"];
3957
+ if (!isRecord(rawLoras)) return null;
3958
+ const loras = {};
3959
+ for (const [key, item] of Object.entries(rawLoras)) if (isRecord(item)) loras[key] = item;
3960
+ const str = (key, fallback) => {
3961
+ const v = raw[key];
3962
+ return typeof v === "string" ? v : fallback;
3963
+ };
3964
+ return {
3965
+ hostId: str("hostId", hostId),
3966
+ hostUrl: str("hostUrl", ""),
3967
+ fetchedAt: str("fetchedAt", ""),
3968
+ count: Object.keys(loras).length,
3969
+ loras
3970
+ };
3971
+ } catch (e) {
3972
+ logError(`[loraInfoCache] unreadable ${path}: ${String(e)}`);
3973
+ return null;
3974
+ }
3975
+ }
3976
+ /**
3977
+ * the read model: each registered host's mirror, kept PER HOST.
3978
+ *
3979
+ * Per host, not merged into one map, because the same file name on two hosts is
3980
+ * routinely a different model. A merged map served whichever host loaded first,
3981
+ * so on the other host the overlay showed the wrong model name and the prompt
3982
+ * silently received the wrong trigger words — a bad generation with no error
3983
+ * anywhere. Callers that know their host say so; the rest fall back to any host
3984
+ * that has the lora, which is still better than nothing for a display name.
3985
+ *
3986
+ * Plain (non-observable) on purpose: the loras overlay reads this from inside a
3987
+ * mobx render. The storage seam has no readdir, so the host set comes from
3988
+ * `comfyts.hosts` — exactly the hosts this process can be asked about.
3989
+ */
3990
+ const byHost = /* @__PURE__ */ new Map();
3991
+ /** hosts already looked for, INCLUDING the ones with no mirror (see reloadLoraInfoCache) */
3992
+ const loadedHostIds = /* @__PURE__ */ new Set();
3993
+ function ensureLoaded() {
3994
+ for (const hostId of comfyts.hosts.keys()) {
3995
+ if (loadedHostIds.has(hostId)) continue;
3996
+ loadedHostIds.add(hostId);
3997
+ const mirror = readLoraMirror(hostId);
3998
+ if (mirror == null) continue;
3999
+ byHost.set(hostId, new Map(Object.entries(mirror.loras)));
4000
+ }
4001
+ }
4002
+ /**
4003
+ * forget everything loaded, so the next read picks up a fresh `comfy-ts loras`.
4004
+ * A long-lived process (the TUI, `comfy-ts serve`) has no other way to see a
4005
+ * re-sync that happened in another terminal.
4006
+ */
4007
+ function reloadLoraInfoCache() {
4008
+ byHost.clear();
4009
+ loadedHostIds.clear();
4010
+ }
4011
+ /**
4012
+ * the lm item for a raw lora name (`styles\x.safetensors`).
4013
+ * `hostId` picks the mirror that actually describes this host's file; without
4014
+ * it, any host that knows the name answers. null when unsynced/unknown.
4015
+ */
4016
+ function getLoraInfo(name, hostId) {
4017
+ ensureLoaded();
4018
+ const key = loraKey(name);
4019
+ if (hostId != null) {
4020
+ const own = byHost.get(hostId);
4021
+ if (own != null) return own.get(key) ?? null;
4022
+ }
4023
+ for (const mirror of byHost.values()) {
4024
+ const hit = mirror.get(key);
4025
+ if (hit != null) return hit;
4026
+ }
4027
+ return null;
4028
+ }
4029
+ /** civitai trigger words for this lora, in civitai's order */
4030
+ function getLoraTriggerWords(name, hostId) {
4031
+ const info = getLoraInfo(name, hostId);
4032
+ return info == null ? [] : lmTrainedWords(info);
4033
+ }
4034
+ /** the human name (`Aurora Ink Wash`), falling back to the file's own name */
4035
+ function getLoraDisplayName(name, hostId) {
4036
+ const info = getLoraInfo(name, hostId);
4037
+ return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
4038
+ }
4039
+ /** server-relative preview url from the mirror, null when unsynced/unknown */
4040
+ function getLoraPreviewUrl(name, hostId) {
4041
+ const info = getLoraInfo(name, hostId);
4042
+ return info == null ? null : lmPreviewUrl(info);
4043
+ }
4044
+ /** the lora's NAMES: the file, and the model name a human would call it by */
4045
+ function loraSearchNames(name, hostId) {
4046
+ const names = [loraBasename(name), name.replaceAll("\\", "/")];
4047
+ const info = getLoraInfo(name, hostId);
4048
+ const modelName = info == null ? null : lmModelName(info);
4049
+ if (modelName != null) names.push(modelName);
4050
+ return names;
4051
+ }
4052
+ /** the lora's FREE TEXT: tags, base model, trigger words */
4053
+ function loraSearchText(name, hostId) {
4054
+ const info = getLoraInfo(name, hostId);
4055
+ if (info == null) return [];
4056
+ const text = [...lmTags(info), ...lmTrainedWords(info)];
4057
+ const baseModel = lmBaseModel(info);
4058
+ if (baseModel != null) text.push(baseModel);
4059
+ return text;
4060
+ }
4061
+ /**
4062
+ * the loras overlay filter: find a lora by its human name, not only by the file
4063
+ * name. EVERY whitespace-separated token must be a SUBSTRING of some field — order
4064
+ * free, so `aurora ink`, `ink aurora` and `styles wash` all land on the same
4065
+ * lora. NOT fuzzyMatch: a subsequence match over phrases this long matches
4066
+ * nearly everything. Measured on a real collection, filtering by each lora's
4067
+ * own file name: this rule peaks at 8 hits where fuzzyMatch matched a third of
4068
+ * every lora present.
4069
+ * Fields are matched one by one, never as a concatenated haystack, for the same
4070
+ * reason. `tests/lora-corpus.private.test.ts` keeps that measurement runnable.
4071
+ */
4072
+ function loraMatchesFilter(name, filter, hostId) {
4073
+ const tokens = filter.toLowerCase().split(/\s+/).filter((t) => t !== "");
4074
+ if (tokens.length === 0) return true;
4075
+ const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
4076
+ return tokens.every((token) => fields.some((field) => field.includes(token)));
4077
+ }
4078
+ //#endregion
3887
4079
  //#region src/vars/loraKeywords.ts
3888
4080
  /**
3889
4081
  * hand-assigned trigger keyword(s) per lora name — set via ⌃K in the TUI loras
@@ -3891,6 +4083,12 @@ var ResilientWebSocketClient = class {
3891
4083
  * `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data
3892
4084
  * and must survive a cache wipe). Observable map: overlay rows re-render on
3893
4085
  * assignment. Keys are the RAW lora names (folder/file.safetensors).
4086
+ *
4087
+ * This file is the OVERRIDE layer. Below it sits the lora-manager mirror's
4088
+ * civitai trigger words (src/host/loraInfoCache.ts, refreshed by
4089
+ * `comfy-ts loras`), so most loras carry a keyword without anyone typing one.
4090
+ * The overlay renders a mirror-sourced keyword dim and a hand-typed one yellow,
4091
+ * and ⌃D drops the override to fall back to the mirror again.
3894
4092
  */
3895
4093
  const keywords = observable.map();
3896
4094
  let loaded = false;
@@ -3913,18 +4111,50 @@ function loadOnce() {
3913
4111
  logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
3914
4112
  }
3915
4113
  }
3916
- function getLoraKeyword(name) {
4114
+ /** the hand keyword when this lora HAS an entry (`''` included), else the mirror's trigger words */
4115
+ function getLoraKeyword(name, hostId) {
3917
4116
  loadOnce();
3918
- return keywords.get(name) ?? "";
4117
+ const hand = keywords.get(name);
4118
+ if (hand != null) return hand;
4119
+ return getLoraTriggerWords(name, hostId).join(", ");
3919
4120
  }
3920
- /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
3921
- function setLoraKeyword(name, keyword) {
4121
+ /** true when the keyword shown comes from the lora-manager mirror, not from ⌃K */
4122
+ function isLoraKeywordFromMirror(name, hostId) {
4123
+ loadOnce();
4124
+ return !keywords.has(name) && getLoraTriggerWords(name, hostId).length > 0;
4125
+ }
4126
+ /** what `clearLoraKeywordOverride` would restore this lora to, `''` when nothing */
4127
+ function loraKeywordFromMirror(name, hostId) {
4128
+ return getLoraTriggerWords(name, hostId).join(", ");
4129
+ }
4130
+ /**
4131
+ * drop the hand entry entirely, so the mirror's trigger words apply again.
4132
+ * The way BACK from an empty-string tombstone: without it, clearing a keyword on
4133
+ * a lora that has trigger words was a one-way door only a text editor could undo.
4134
+ */
4135
+ function clearLoraKeywordOverride(name) {
4136
+ loadOnce();
4137
+ if (!keywords.has(name)) return;
4138
+ runInAction(() => void keywords.delete(name));
4139
+ writeKeywords();
4140
+ }
4141
+ /**
4142
+ * empty keyword deletes the entry — EXCEPT when the mirror has trigger words for
4143
+ * this lora: there `''` is stored as an explicit tombstone, the only way to say
4144
+ * "inject nothing" about a lora civitai gave words to. Every set writes the file
4145
+ * (tiny, rare).
4146
+ */
4147
+ function setLoraKeyword(name, keyword, hostId) {
3922
4148
  loadOnce();
3923
4149
  const trimmed = keyword.trim();
3924
4150
  runInAction(() => {
3925
- if (trimmed === "") keywords.delete(name);
4151
+ if (trimmed === "" && getLoraTriggerWords(name, hostId).length === 0) keywords.delete(name);
3926
4152
  else keywords.set(name, trimmed);
3927
4153
  });
4154
+ writeKeywords();
4155
+ }
4156
+ /** every set writes the file: it is tiny and hand-edited rarely */
4157
+ function writeKeywords() {
3928
4158
  const path = filePath();
3929
4159
  try {
3930
4160
  getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
@@ -4031,7 +4261,7 @@ var PromptVar = class extends ComfyVarBase {
4031
4261
  injectedKeywords() {
4032
4262
  const src = this.promptOpts.loraKeywordsFrom;
4033
4263
  if (src == null) return [];
4034
- return [...new Set(src.activeNames().map(getLoraKeyword).filter((k) => k !== ""))];
4264
+ return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
4035
4265
  }
4036
4266
  outValue() {
4037
4267
  const pos = [];
@@ -4223,6 +4453,7 @@ var LorasVar = class LorasVar extends ComfyVar {
4223
4453
  this.kind = "loras";
4224
4454
  this.prev = {};
4225
4455
  this.resolvedOptions = null;
4456
+ this.hostId = void 0;
4226
4457
  }
4227
4458
  get options() {
4228
4459
  if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
@@ -4233,6 +4464,7 @@ var LorasVar = class LorasVar extends ComfyVar {
4233
4464
  * cast: whitelist family 1 (agent/coding.md) — getLoras() returns the runtime
4234
4465
  * values of the SAME object_info enum the generated E_LoraName union comes from */
4235
4466
  bindHost(host) {
4467
+ this.hostId = host.data?.id;
4236
4468
  if (!(this.optionsSource instanceof RegExp)) return;
4237
4469
  this.resolvedOptions = host.schema.getLoras(this.optionsSource);
4238
4470
  }
@@ -4351,7 +4583,7 @@ const DEFAULT_SIZE_PRESETS = [
4351
4583
  }
4352
4584
  ];
4353
4585
  /** 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
4586
+ * size of a linked image var (the widget shows
4355
4587
  * `WxH size of image '<name>'` as a pickable row) */
4356
4588
  var SizeVar = class extends ComfyVar {
4357
4589
  constructor(defaultValue = {
@@ -4951,6 +5183,7 @@ var ComfyHost = class {
4951
5183
  url: () => this.getWSUrl(),
4952
5184
  headers: () => this.authHeaders(),
4953
5185
  onTransportDead: (e) => this.markFailed(e),
5186
+ onFirstConnectFailed: (e) => this.markFailed(new ComfyHostUnreachableError(`host '${this.data.id}' is not reachable at ${this.getWSUrl()} — ${extractErrorMessage(e)}. Is ComfyUI running there ?`)),
4954
5187
  onClose: () => {
4955
5188
  logInfo(`[👢] WEBSOCKET: closed connection to ComfyUI host ${this.data.id}`);
4956
5189
  }
@@ -5757,6 +5990,6 @@ function loraTag(name, strength = 1, clipStrength) {
5757
5990
  */
5758
5991
  setDefaultComfyStorage(createMemoryStorage());
5759
5992
  //#endregion
5760
- 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_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraKeyword, hostIdToNamespace, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
5993
+ 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 };
5761
5994
 
5762
5995
  //# sourceMappingURL=web.js.map