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/README.md CHANGED
@@ -290,6 +290,7 @@ bunx comfy-ts gen --id my-gpu --host http://127.0.0.1:8188
290
290
  # → .comfy-ts/hosts/my-gpu/{object_info.json, embeddings.json, sdk.d.ts}
291
291
 
292
292
  bunx comfy-ts outline # what's inside that 2MB sdk.d.ts?
293
+ bunx comfy-ts loras # mirror your loras' names + trigger words (below)
293
294
  bunx comfy-ts tui # your *.cflow.ts + bundled examples
294
295
  bunx comfy-ts tui [dir | module] # scan just that
295
296
  bunx comfy-ts serve [dir | module] # drafts as a local HTTP API (below)
@@ -297,6 +298,18 @@ bunx comfy-ts serve [dir | module] # drafts as a local HTTP API (below)
297
298
 
298
299
  Any reachable host: the box under your desk or a GPU machine across the network, same command, same output.
299
300
 
301
+ ### Loras with names, not file names
302
+
303
+ ComfyUI only tells you a lora's file name. If your host runs the [ComfyUI-Lora-Manager](https://github.com/willmiao/ComfyUI-Lora-Manager) extension, one command mirrors what it knows into your project:
304
+
305
+ ```bash
306
+ bunx comfy-ts loras --id my-gpu --host http://127.0.0.1:8188
307
+ # → .comfy-ts/hosts/my-gpu/loras.json (model names, civitai trigger words, tags, base models, previews)
308
+ bunx comfy-ts loras # refresh later: id and url are remembered
309
+ ```
310
+
311
+ After that, in the TUI's loras overlay you can type `aurora ink` to find `styles\aurora-ink-v3.safetensors`, and a lora's civitai trigger words are prefixed onto your `v.prompt` automatically when it is active (⌃K still overrides any lora's keyword by hand). No extension, or no sync yet? Everything behaves as before — file names and hand-typed keywords.
312
+
300
313
  ## 🌐 Serve: drafts as an HTTP API
301
314
 
302
315
  Hand-tune a draft in the TUI, then make it callable by anything that speaks HTTP — a web frontend, curl, n8n, another service:
@@ -1,6 +1,76 @@
1
1
  import { basename, isAbsolute, join, resolve } from "pathe";
2
+ import { type } from "arktype";
2
3
  import { imageMeta } from "image-meta";
3
4
  import { action, makeObservable, observable, runInAction } from "mobx";
5
+ //#region src/utils/sha1.ts
6
+ function sha1Hex(data) {
7
+ const ml = data.length;
8
+ const total = Math.ceil((ml + 1 + 8) / 64) * 64;
9
+ const bytes = new Uint8Array(total);
10
+ bytes.set(data);
11
+ bytes[ml] = 128;
12
+ const dv = new DataView(bytes.buffer);
13
+ const bitLen = ml * 8;
14
+ dv.setUint32(total - 8, Math.floor(bitLen / 2 ** 32));
15
+ dv.setUint32(total - 4, bitLen >>> 0);
16
+ let h0 = 1732584193;
17
+ let h1 = 4023233417;
18
+ let h2 = 2562383102;
19
+ let h3 = 271733878;
20
+ let h4 = 3285377520;
21
+ const w = /* @__PURE__ */ new Uint32Array(80);
22
+ for (let i = 0; i < total; i += 64) {
23
+ for (let j = 0; j < 16; j++) w[j] = dv.getUint32(i + j * 4);
24
+ for (let j = 16; j < 80; j++) {
25
+ const n = (w[j - 3] ?? 0) ^ (w[j - 8] ?? 0) ^ (w[j - 14] ?? 0) ^ (w[j - 16] ?? 0);
26
+ w[j] = n << 1 | n >>> 31;
27
+ }
28
+ let a = h0;
29
+ let b = h1;
30
+ let c = h2;
31
+ let d = h3;
32
+ let e = h4;
33
+ for (let j = 0; j < 80; j++) {
34
+ let f;
35
+ let k;
36
+ if (j < 20) {
37
+ f = b & c | ~b & d;
38
+ k = 1518500249;
39
+ } else if (j < 40) {
40
+ f = b ^ c ^ d;
41
+ k = 1859775393;
42
+ } else if (j < 60) {
43
+ f = b & c | b & d | c & d;
44
+ k = 2400959708;
45
+ } else {
46
+ f = b ^ c ^ d;
47
+ k = 3395469782;
48
+ }
49
+ const temp = (a << 5 | a >>> 27) + f + e + k + (w[j] ?? 0) >>> 0;
50
+ e = d;
51
+ d = c;
52
+ c = b << 30 | b >>> 2;
53
+ b = a;
54
+ a = temp;
55
+ }
56
+ h0 = h0 + a >>> 0;
57
+ h1 = h1 + b >>> 0;
58
+ h2 = h2 + c >>> 0;
59
+ h3 = h3 + d >>> 0;
60
+ h4 = h4 + e >>> 0;
61
+ }
62
+ return [
63
+ h0,
64
+ h1,
65
+ h2,
66
+ h3,
67
+ h4
68
+ ].map((x) => x.toString(16).padStart(8, "0")).join("");
69
+ }
70
+ function sha1HexOfString(s) {
71
+ return sha1Hex(new TextEncoder().encode(s));
72
+ }
73
+ //#endregion
4
74
  //#region src/utils/log.ts
5
75
  const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
6
76
  const logInfo = (msg) => {
@@ -75,6 +145,328 @@ const extractErrorMessage = (error) => {
75
145
  return String(error);
76
146
  };
77
147
  //#endregion
148
+ //#region src/utils/isRecord.ts
149
+ /** narrows unknown wire json to an indexable object (arrays and null excluded) */
150
+ function isRecord(v) {
151
+ return typeof v === "object" && v !== null && !Array.isArray(v);
152
+ }
153
+ //#endregion
154
+ //#region src/host/loraManagerApi.ts
155
+ /** only the ENVELOPE is schema'd — items stay unknown so nothing can strip their fields */
156
+ const lmLoraPage = type({
157
+ items: "unknown[]",
158
+ "total?": "number"
159
+ });
160
+ function readString(item, key) {
161
+ const v = item[key];
162
+ return typeof v === "string" && v !== "" ? v : null;
163
+ }
164
+ function readStringArray(item, key) {
165
+ const v = item[key];
166
+ if (!Array.isArray(v)) return [];
167
+ return v.filter((x) => typeof x === "string" && x !== "");
168
+ }
169
+ function lmFileName(item) {
170
+ return readString(item, "file_name");
171
+ }
172
+ function lmFolder(item) {
173
+ return readString(item, "folder") ?? "";
174
+ }
175
+ function lmModelName(item) {
176
+ return readString(item, "model_name");
177
+ }
178
+ function lmBaseModel(item) {
179
+ return readString(item, "base_model");
180
+ }
181
+ function lmPreviewUrl(item) {
182
+ return readString(item, "preview_url");
183
+ }
184
+ function lmTags(item) {
185
+ return readStringArray(item, "tags");
186
+ }
187
+ /** the trigger words: civitai's `trainedWords`, absent for a lora nobody published */
188
+ function lmTrainedWords(item) {
189
+ const civitai = item["civitai"];
190
+ if (!isRecord(civitai)) return [];
191
+ return readStringArray(civitai, "trainedWords");
192
+ }
193
+ /**
194
+ * the ONE key space where a host's object_info spelling of a lora meets
195
+ * lora-manager's: lowercase, forward slashes, no model extension.
196
+ * `styles\Aurora.safetensors` and lm's folder `styles` + file_name `aurora`
197
+ * both become `styles/aurora`.
198
+ */
199
+ function loraKey(name) {
200
+ return name.replaceAll("\\", "/").replace(/\.(safetensors|st|pt|ckpt)$/i, "").toLowerCase();
201
+ }
202
+ /** the file's own name, windows separators included (`styles\x.safetensors` → `x.safetensors`) */
203
+ function loraBasename(name) {
204
+ return basename(name.replaceAll("\\", "/"));
205
+ }
206
+ /** the mirror key for an lm item: its folder/file_name pair, normalized */
207
+ function lmItemKey(item) {
208
+ const file = lmFileName(item);
209
+ if (file == null) return null;
210
+ const folder = lmFolder(item);
211
+ return loraKey(folder === "" ? file : `${folder}/${file}`);
212
+ }
213
+ /** runaway stop: 20 pages × the server's 100-per-page cap = 2000 loras */
214
+ const MAX_PAGES = 20;
215
+ /**
216
+ * every lora lora-manager knows, RAW, in one paged sweep.
217
+ * page_size asks for 500; the server caps it at 100, so the loop follows `total`.
218
+ */
219
+ async function fetchLoraList(host) {
220
+ const items = [];
221
+ for (let page = 1; page <= MAX_PAGES; page++) {
222
+ let res;
223
+ try {
224
+ res = await host.fetch(`/api/lm/loras/list?page=${page}&page_size=500`, {}, { apiPrefix: false });
225
+ } catch (e) {
226
+ const reason = `host unreachable at page ${page}: ${extractErrorMessage(e)}`;
227
+ return page === 1 ? {
228
+ status: "unreachable",
229
+ reason
230
+ } : partial(items, reason);
231
+ }
232
+ if (!res.ok) {
233
+ if (page === 1) return { status: "absent" };
234
+ return partial(items, `page ${page} answered ${res.status}`);
235
+ }
236
+ const json = await res.json();
237
+ const parsed = lmLoraPage(json);
238
+ if (parsed instanceof type.errors) return partial(items, `page ${page} shape mismatch: ${parsed.summary}`);
239
+ const pageItems = parsed.items.filter(isRecord);
240
+ items.push(...pageItems);
241
+ const total = parsed.total;
242
+ if (pageItems.length === 0 || total != null && items.length >= total) return {
243
+ status: "ok",
244
+ items
245
+ };
246
+ }
247
+ return partial(items, `stopped at the ${MAX_PAGES}-page runaway limit`);
248
+ }
249
+ /** a truncated sweep is LOUD at the source, whatever the caller then decides to do */
250
+ function partial(items, reason) {
251
+ logError(`[loraManagerApi] lora sweep INCOMPLETE after ${items.length} loras — ${reason}`);
252
+ return {
253
+ status: "partial",
254
+ items,
255
+ reason
256
+ };
257
+ }
258
+ /** `loraKey` → server-relative preview_url */
259
+ function loraPreviewMapFrom(items) {
260
+ const map = /* @__PURE__ */ new Map();
261
+ for (const item of items) {
262
+ const key = lmItemKey(item);
263
+ const url = lmPreviewUrl(item);
264
+ if (key != null && url != null) map.set(key, url);
265
+ }
266
+ return map;
267
+ }
268
+ /** the bytes look like an image (magic numbers) — guards against ComfyUI's SPA index.html fallback */
269
+ function looksLikeImage(bytes) {
270
+ if (bytes.length < 3) return false;
271
+ const b = bytes;
272
+ const is = (sig, off = 0) => sig.every((v, i) => b[off + i] === v);
273
+ return is([
274
+ 137,
275
+ 80,
276
+ 78,
277
+ 71
278
+ ]) || is([
279
+ 255,
280
+ 216,
281
+ 255
282
+ ]) || is([
283
+ 71,
284
+ 73,
285
+ 70
286
+ ]) || is([
287
+ 82,
288
+ 73,
289
+ 70,
290
+ 70
291
+ ]) && is([
292
+ 87,
293
+ 69,
294
+ 66,
295
+ 80
296
+ ], 8);
297
+ }
298
+ /**
299
+ * fetch a preview image's bytes from its server-relative preview_url.
300
+ * cached on success at `.comfy-ts/cache/lora-previews/<sha1(url)>`. Returns null
301
+ * when the file is missing: lora-manager SPA-fallbacks to index.html (HTML), so
302
+ * a non-image content-type OR non-image magic bytes => no preview, not a crash.
303
+ */
304
+ async function fetchLoraPreviewBytes(host, previewUrl) {
305
+ const storage = getComfyStorage();
306
+ const cachePath = comfyts.resolveFromCache(`lora-previews/${sha1HexOfString(previewUrl)}`);
307
+ if (storage.exists(cachePath)) return storage.readBytes(cachePath);
308
+ try {
309
+ const res = await host.fetch(previewUrl, {}, { apiPrefix: false });
310
+ if (!res.ok) return null;
311
+ const ct = res.headers.get("content-type") ?? "";
312
+ if (ct !== "" && !ct.startsWith("image/")) return null;
313
+ const bytes = new Uint8Array(await res.arrayBuffer());
314
+ if (!looksLikeImage(bytes)) return null;
315
+ storage.writeBytes(cachePath, bytes);
316
+ return bytes;
317
+ } catch {
318
+ return null;
319
+ }
320
+ }
321
+ //#endregion
322
+ //#region src/host/loraInfoCache.ts
323
+ function loraMirrorPath(hostId) {
324
+ return comfyts.resolveFromHosts(join(hostId, "loras.json"));
325
+ }
326
+ /** pure: the on-disk shape for a sweep. Items without a file_name are dropped (nothing to key them by). */
327
+ function buildLoraMirror(p) {
328
+ const loras = {};
329
+ for (const item of p.items) {
330
+ const key = lmItemKey(item);
331
+ if (key == null) continue;
332
+ if (loras[key] != null) logError(`[loraInfoCache] two loras share the key '${key}' — one of them is shadowed`);
333
+ loras[key] = item;
334
+ }
335
+ return {
336
+ hostId: p.hostId,
337
+ hostUrl: p.hostUrl,
338
+ fetchedAt: p.fetchedAt,
339
+ count: Object.keys(loras).length,
340
+ loras
341
+ };
342
+ }
343
+ function writeLoraMirror(mirror) {
344
+ const path = loraMirrorPath(mirror.hostId);
345
+ getComfyStorage().writeText(path, JSON.stringify(mirror, null, 2));
346
+ return path;
347
+ }
348
+ /** null = never synced (or unreadable, which is LOGGED) */
349
+ function readLoraMirror(hostId) {
350
+ const path = loraMirrorPath(hostId);
351
+ const text = getComfyStorage().readTextIfExists(path);
352
+ if (text == null) return null;
353
+ try {
354
+ const raw = JSON.parse(text);
355
+ if (!isRecord(raw)) return null;
356
+ const rawLoras = raw["loras"];
357
+ if (!isRecord(rawLoras)) return null;
358
+ const loras = {};
359
+ for (const [key, item] of Object.entries(rawLoras)) if (isRecord(item)) loras[key] = item;
360
+ const str = (key, fallback) => {
361
+ const v = raw[key];
362
+ return typeof v === "string" ? v : fallback;
363
+ };
364
+ return {
365
+ hostId: str("hostId", hostId),
366
+ hostUrl: str("hostUrl", ""),
367
+ fetchedAt: str("fetchedAt", ""),
368
+ count: Object.keys(loras).length,
369
+ loras
370
+ };
371
+ } catch (e) {
372
+ logError(`[loraInfoCache] unreadable ${path}: ${String(e)}`);
373
+ return null;
374
+ }
375
+ }
376
+ /**
377
+ * the read model: each registered host's mirror, kept PER HOST.
378
+ *
379
+ * Per host, not merged into one map, because the same file name on two hosts is
380
+ * routinely a different model. A merged map served whichever host loaded first,
381
+ * so on the other host the overlay showed the wrong model name and the prompt
382
+ * silently received the wrong trigger words — a bad generation with no error
383
+ * anywhere. Callers that know their host say so; the rest fall back to any host
384
+ * that has the lora, which is still better than nothing for a display name.
385
+ *
386
+ * Plain (non-observable) on purpose: the loras overlay reads this from inside a
387
+ * mobx render. The storage seam has no readdir, so the host set comes from
388
+ * `comfyts.hosts` — exactly the hosts this process can be asked about.
389
+ */
390
+ const byHost = /* @__PURE__ */ new Map();
391
+ /** hosts already looked for, INCLUDING the ones with no mirror (see reloadLoraInfoCache) */
392
+ const loadedHostIds = /* @__PURE__ */ new Set();
393
+ function ensureLoaded() {
394
+ for (const hostId of comfyts.hosts.keys()) {
395
+ if (loadedHostIds.has(hostId)) continue;
396
+ loadedHostIds.add(hostId);
397
+ const mirror = readLoraMirror(hostId);
398
+ if (mirror == null) continue;
399
+ byHost.set(hostId, new Map(Object.entries(mirror.loras)));
400
+ }
401
+ }
402
+ /**
403
+ * the lm item for a raw lora name (`styles\x.safetensors`).
404
+ * `hostId` picks the mirror that actually describes this host's file; without
405
+ * it, any host that knows the name answers. null when unsynced/unknown.
406
+ */
407
+ function getLoraInfo(name, hostId) {
408
+ ensureLoaded();
409
+ const key = loraKey(name);
410
+ if (hostId != null) {
411
+ const own = byHost.get(hostId);
412
+ if (own != null) return own.get(key) ?? null;
413
+ }
414
+ for (const mirror of byHost.values()) {
415
+ const hit = mirror.get(key);
416
+ if (hit != null) return hit;
417
+ }
418
+ return null;
419
+ }
420
+ /** civitai trigger words for this lora, in civitai's order */
421
+ function getLoraTriggerWords(name, hostId) {
422
+ const info = getLoraInfo(name, hostId);
423
+ return info == null ? [] : lmTrainedWords(info);
424
+ }
425
+ /** the human name (`Aurora Ink Wash`), falling back to the file's own name */
426
+ function getLoraDisplayName(name, hostId) {
427
+ const info = getLoraInfo(name, hostId);
428
+ return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
429
+ }
430
+ /** server-relative preview url from the mirror, null when unsynced/unknown */
431
+ function getLoraPreviewUrl(name, hostId) {
432
+ const info = getLoraInfo(name, hostId);
433
+ return info == null ? null : lmPreviewUrl(info);
434
+ }
435
+ /** the lora's NAMES: the file, and the model name a human would call it by */
436
+ function loraSearchNames(name, hostId) {
437
+ const names = [loraBasename(name), name.replaceAll("\\", "/")];
438
+ const info = getLoraInfo(name, hostId);
439
+ const modelName = info == null ? null : lmModelName(info);
440
+ if (modelName != null) names.push(modelName);
441
+ return names;
442
+ }
443
+ /** the lora's FREE TEXT: tags, base model, trigger words */
444
+ function loraSearchText(name, hostId) {
445
+ const info = getLoraInfo(name, hostId);
446
+ if (info == null) return [];
447
+ const text = [...lmTags(info), ...lmTrainedWords(info)];
448
+ const baseModel = lmBaseModel(info);
449
+ if (baseModel != null) text.push(baseModel);
450
+ return text;
451
+ }
452
+ /**
453
+ * the loras overlay filter: find a lora by its human name, not only by the file
454
+ * name. EVERY whitespace-separated token must be a SUBSTRING of some field — order
455
+ * free, so `aurora ink`, `ink aurora` and `styles wash` all land on the same
456
+ * lora. NOT fuzzyMatch: a subsequence match over phrases this long matches
457
+ * nearly everything. Measured on a real collection, filtering by each lora's
458
+ * own file name: this rule peaks at 8 hits where fuzzyMatch matched a third of
459
+ * every lora present.
460
+ * Fields are matched one by one, never as a concatenated haystack, for the same
461
+ * reason. `tests/lora-corpus.private.test.ts` keeps that measurement runnable.
462
+ */
463
+ function loraMatchesFilter(name, filter, hostId) {
464
+ const tokens = filter.toLowerCase().split(/\s+/).filter((t) => t !== "");
465
+ if (tokens.length === 0) return true;
466
+ const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
467
+ return tokens.every((token) => fields.some((field) => field.includes(token)));
468
+ }
469
+ //#endregion
78
470
  //#region src/vars/loraKeywords.ts
79
471
  /**
80
472
  * hand-assigned trigger keyword(s) per lora name — set via ⌃K in the TUI loras
@@ -82,6 +474,12 @@ const extractErrorMessage = (error) => {
82
474
  * `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data
83
475
  * and must survive a cache wipe). Observable map: overlay rows re-render on
84
476
  * assignment. Keys are the RAW lora names (folder/file.safetensors).
477
+ *
478
+ * This file is the OVERRIDE layer. Below it sits the lora-manager mirror's
479
+ * civitai trigger words (src/host/loraInfoCache.ts, refreshed by
480
+ * `comfy-ts loras`), so most loras carry a keyword without anyone typing one.
481
+ * The overlay renders a mirror-sourced keyword dim and a hand-typed one yellow,
482
+ * and ⌃D drops the override to fall back to the mirror again.
85
483
  */
86
484
  const keywords = observable.map();
87
485
  let loaded = false;
@@ -104,18 +502,50 @@ function loadOnce() {
104
502
  logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
105
503
  }
106
504
  }
107
- function getLoraKeyword(name) {
505
+ /** the hand keyword when this lora HAS an entry (`''` included), else the mirror's trigger words */
506
+ function getLoraKeyword(name, hostId) {
108
507
  loadOnce();
109
- return keywords.get(name) ?? "";
508
+ const hand = keywords.get(name);
509
+ if (hand != null) return hand;
510
+ return getLoraTriggerWords(name, hostId).join(", ");
110
511
  }
111
- /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
112
- function setLoraKeyword(name, keyword) {
512
+ /** true when the keyword shown comes from the lora-manager mirror, not from ⌃K */
513
+ function isLoraKeywordFromMirror(name, hostId) {
514
+ loadOnce();
515
+ return !keywords.has(name) && getLoraTriggerWords(name, hostId).length > 0;
516
+ }
517
+ /** what `clearLoraKeywordOverride` would restore this lora to, `''` when nothing */
518
+ function loraKeywordFromMirror(name, hostId) {
519
+ return getLoraTriggerWords(name, hostId).join(", ");
520
+ }
521
+ /**
522
+ * drop the hand entry entirely, so the mirror's trigger words apply again.
523
+ * The way BACK from an empty-string tombstone: without it, clearing a keyword on
524
+ * a lora that has trigger words was a one-way door only a text editor could undo.
525
+ */
526
+ function clearLoraKeywordOverride(name) {
527
+ loadOnce();
528
+ if (!keywords.has(name)) return;
529
+ runInAction(() => void keywords.delete(name));
530
+ writeKeywords();
531
+ }
532
+ /**
533
+ * empty keyword deletes the entry — EXCEPT when the mirror has trigger words for
534
+ * this lora: there `''` is stored as an explicit tombstone, the only way to say
535
+ * "inject nothing" about a lora civitai gave words to. Every set writes the file
536
+ * (tiny, rare).
537
+ */
538
+ function setLoraKeyword(name, keyword, hostId) {
113
539
  loadOnce();
114
540
  const trimmed = keyword.trim();
115
541
  runInAction(() => {
116
- if (trimmed === "") keywords.delete(name);
542
+ if (trimmed === "" && getLoraTriggerWords(name, hostId).length === 0) keywords.delete(name);
117
543
  else keywords.set(name, trimmed);
118
544
  });
545
+ writeKeywords();
546
+ }
547
+ /** every set writes the file: it is tiny and hand-edited rarely */
548
+ function writeKeywords() {
119
549
  const path = filePath();
120
550
  try {
121
551
  getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
@@ -222,7 +652,7 @@ var PromptVar = class extends ComfyVarBase {
222
652
  injectedKeywords() {
223
653
  const src = this.promptOpts.loraKeywordsFrom;
224
654
  if (src == null) return [];
225
- return [...new Set(src.activeNames().map(getLoraKeyword).filter((k) => k !== ""))];
655
+ return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
226
656
  }
227
657
  outValue() {
228
658
  const pos = [];
@@ -400,6 +830,7 @@ var LorasVar = class LorasVar extends ComfyVar {
400
830
  this.kind = "loras";
401
831
  this.prev = {};
402
832
  this.resolvedOptions = null;
833
+ this.hostId = void 0;
403
834
  }
404
835
  get options() {
405
836
  if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
@@ -410,6 +841,7 @@ var LorasVar = class LorasVar extends ComfyVar {
410
841
  * cast: whitelist family 1 (agent/coding.md) — getLoras() returns the runtime
411
842
  * values of the SAME object_info enum the generated E_LoraName union comes from */
412
843
  bindHost(host) {
844
+ this.hostId = host.data?.id;
413
845
  if (!(this.optionsSource instanceof RegExp)) return;
414
846
  this.resolvedOptions = host.schema.getLoras(this.optionsSource);
415
847
  }
@@ -528,7 +960,7 @@ const DEFAULT_SIZE_PRESETS = [
528
960
  }
529
961
  ];
530
962
  /** width/height picker: presets + free `WxH` entry + optionally the LIVE
531
- * size of a linked image var (his ask 2026-07-30: the widget shows
963
+ * size of a linked image var (the widget shows
532
964
  * `WxH size of image '<name>'` as a pickable row) */
533
965
  var SizeVar = class extends ComfyVar {
534
966
  constructor(defaultValue = {
@@ -735,6 +1167,6 @@ var DefinedWorkflow = class {
735
1167
  }
736
1168
  };
737
1169
  //#endregion
738
- export { setLoraKeyword as a, resolveComfyStorage as c, logInfo as d, logSuccess as f, getLoraKeyword as i, isQuiet as l, LorasVar as n, extractErrorMessage as o, PromptVar as r, getComfyStorage as s, DefinedWorkflow as t, logError as u };
1170
+ export { sha1HexOfString as A, getComfyStorage as C, logInfo as D, logError as E, logSuccess as O, extractErrorMessage as S, isQuiet as T, lmModelName as _, getLoraKeyword as a, loraKey as b, setLoraKeyword as c, getLoraPreviewUrl as d, loraMatchesFilter as f, fetchLoraPreviewBytes as g, fetchLoraList as h, clearLoraKeywordOverride as i, sha1Hex as k, buildLoraMirror as l, writeLoraMirror as m, LorasVar as n, isLoraKeywordFromMirror as o, readLoraMirror as p, PromptVar as r, loraKeywordFromMirror as s, DefinedWorkflow as t, getLoraDisplayName as u, lmTrainedWords as v, resolveComfyStorage as w, loraPreviewMapFrom as x, loraBasename as y };
739
1171
 
740
- //# sourceMappingURL=DefinedWorkflow-CwHInZgn.js.map
1172
+ //# sourceMappingURL=DefinedWorkflow-QrhT6V66.js.map