comfy-ts 2.7.0 → 2.8.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 (101) hide show
  1. package/README.md +20 -13
  2. package/dist/{DefinedWorkflow-BJgt5t0x.js → DefinedWorkflow-BatWaZO1.js} +199 -16
  3. package/dist/DefinedWorkflow-BatWaZO1.js.map +1 -0
  4. package/dist/{DraftsSt-dizp3VcC.js → LogsSt-DFxzQfDc.js} +152 -4
  5. package/dist/LogsSt-DFxzQfDc.js.map +1 -0
  6. package/dist/cli.js +7 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +284 -35
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +125 -7
  11. package/dist/index.d.ts +125 -7
  12. package/dist/index.js +282 -37
  13. package/dist/index.js.map +1 -1
  14. package/dist/run-serve-_nrvJYyt.js +1948 -0
  15. package/dist/run-serve-_nrvJYyt.js.map +1 -0
  16. package/dist/{run-tui-JxlEbb_f.js → run-tui-BPw-SZYW.js} +106 -157
  17. package/dist/run-tui-BPw-SZYW.js.map +1 -0
  18. package/dist/serve-web.js +432 -72
  19. package/dist/{state-CaHeDL-0.js → state-B-boDz-Z.js} +180 -45
  20. package/dist/state-B-boDz-Z.js.map +1 -0
  21. package/dist/web.d.ts +109 -7
  22. package/dist/web.js +235 -36
  23. package/dist/web.js.map +1 -1
  24. package/examples/README.md +1 -0
  25. package/examples/comfy-cloud/sdk.d.ts +4066 -321
  26. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +18 -2
  27. package/examples/rvion/07-local-llm-text-gen.cflow.ts +220 -0
  28. package/examples/web/tsconfig.json +3 -0
  29. package/extra/README.md +32 -0
  30. package/extra/comfyui-textgen-stream/README.md +35 -0
  31. package/extra/comfyui-textgen-stream/__init__.py +166 -0
  32. package/extra/scripts/fetch_text_encoder.py +137 -0
  33. package/package.json +6 -3
  34. package/src/cli/comfy-ts-cli.ts +3 -1
  35. package/src/cli/serve/ServeApp.ts +754 -40
  36. package/src/cli/serve/applyVarPayload.ts +10 -3
  37. package/src/cli/serve/describeVar.ts +47 -7
  38. package/src/cli/serve/managerOnlyLoras.ts +27 -0
  39. package/src/cli/serve/run-serve.ts +35 -38
  40. package/src/cli/serve/serveSettings.ts +86 -0
  41. package/src/cli/serve/startupPrint.ts +111 -0
  42. package/src/cli/serve/web/api.ts +97 -1
  43. package/src/cli/serve/web/components/App.tsx +61 -22
  44. package/src/cli/serve/web/components/Gallery.tsx +243 -30
  45. package/src/cli/serve/web/components/Icon.tsx +160 -0
  46. package/src/cli/serve/web/components/PromptEnhancer.tsx +12 -9
  47. package/src/cli/serve/web/components/Sidebar.tsx +43 -19
  48. package/src/cli/serve/web/components/VarsForm.tsx +440 -91
  49. package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
  50. package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
  51. package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
  52. package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
  53. package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
  54. package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
  55. package/src/cli/serve/web/llm.ts +1 -1
  56. package/src/cli/serve/web/logWeb.ts +6 -0
  57. package/src/cli/serve/web/state/EnhancerSt.ts +8 -15
  58. package/src/cli/serve/web/state/FormSt.ts +66 -17
  59. package/src/cli/serve/web/state/RunSt.ts +22 -1
  60. package/src/cli/serve/web/state/WebSt.ts +518 -14
  61. package/src/cli/serve/web/state/lightbox.ts +44 -0
  62. package/src/cli/serve/web/state/moduleTree.ts +52 -0
  63. package/src/cli/serve/web/state/payload.ts +44 -2
  64. package/src/cli/serve/web/state/urlSelection.ts +53 -0
  65. package/src/cli/serve/web/styles.ts +413 -57
  66. package/src/cli/serve/web/tsconfig.json +4 -0
  67. package/src/cli/tui/components/PickerOverlays.tsx +37 -0
  68. package/src/cli/tui/components/StatusBar.tsx +14 -1
  69. package/src/cli/tui/components/TuiApp.tsx +5 -2
  70. package/src/cli/tui/state/HostSt.ts +3 -2
  71. package/src/cli/tui/state/PickerSt.ts +48 -2
  72. package/src/cli/tui/state/TreeSt.ts +1 -1
  73. package/src/cli/tui/state/TuiSt.ts +2 -1
  74. package/src/coreExports.ts +8 -1
  75. package/src/graph/ComfyNode.ts +58 -1
  76. package/src/host/ComfyHost.ts +13 -2
  77. package/src/host/ComfyManager.ts +31 -13
  78. package/src/host/loraInfoCache.ts +35 -1
  79. package/src/host/loraManagerApi.ts +94 -0
  80. package/src/index.ts +2 -0
  81. package/src/promptEnhancers.ts +102 -0
  82. package/src/runner/ComfyExecution.ts +61 -6
  83. package/src/runner/ComfyWorkflow.ts +18 -4
  84. package/src/runner/ComfyWsApi.ts +3 -0
  85. package/src/runner/describePromptRejection.ts +34 -0
  86. package/src/sdk-generator/ComfySchema.ts +17 -4
  87. package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
  88. package/src/utils/ansi.ts +13 -0
  89. package/src/utils/matchesRegex.ts +13 -0
  90. package/src/utils/safeName.ts +29 -0
  91. package/src/utils/stringMap.ts +9 -0
  92. package/src/vars/ComfyVars.ts +61 -10
  93. package/src/vars/presets.ts +17 -0
  94. package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
  95. package/dist/DraftsSt-dizp3VcC.js.map +0 -1
  96. package/dist/run-serve-D1Tsuru9.js +0 -1162
  97. package/dist/run-serve-D1Tsuru9.js.map +0 -1
  98. package/dist/run-tui-JxlEbb_f.js.map +0 -1
  99. package/dist/state-CaHeDL-0.js.map +0 -1
  100. package/src/cli/serve/promptEnhancers.ts +0 -69
  101. package/src/cli/serve/safeName.ts +0 -12
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # comfy-ts
2
2
 
3
- _the ultimate ComfyUI toolkit for TypeScript: `SDK` + `CLI` + `TUI` + agent guide_
3
+ _the ultimate ComfyUI toolkit for TypeScript: `SDK` + `CLI` + `TUI` + `web panel` + agent guide_
4
4
 
5
5
  [![CI](https://github.com/rvion/comfy-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/rvion/comfy-ts/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/comfy-ts.svg)](https://www.npmjs.com/package/comfy-ts) [![npm downloads](https://img.shields.io/npm/dm/comfy-ts.svg)](https://www.npmjs.com/package/comfy-ts) [![GitHub release](https://img.shields.io/github/v/release/rvion/comfy-ts)](https://github.com/rvion/comfy-ts/releases) [![types](https://img.shields.io/npm/types/comfy-ts)](https://www.npmjs.com/package/comfy-ts) [![license](https://img.shields.io/npm/l/comfy-ts.svg)](https://github.com/rvion/comfy-ts/blob/main/LICENSE) [![sponsor](https://img.shields.io/github/sponsors/rvion?label=sponsor&logo=githubsponsors)](https://github.com/sponsors/rvion)
6
6
 
7
- **Everything ComfyUI, from TypeScript.** Build workflows in code with autocomplete on every node and model of your exact install. Run them on any host, from the box under your desk to a cloud GPU, and get the images straight back into your code. Drive them from a terminal UI with live latent previews. Let scripts and agents discover and install whatever the ecosystem offers. Import and export both ComfyUI JSON formats. One library, the whole pipeline.
7
+ **Everything ComfyUI, from TypeScript.** Build workflows in code with autocomplete on every node and model of your exact install. Run them on any host, from the box under your desk to a cloud GPU, and get the images straight back into your code. Drive them from a terminal UI with live latent previews, or from a browser panel that turns every workflow into a form — on your desk or on your phone. Let scripts and agents discover and install whatever the ecosystem offers. Import and export both ComfyUI JSON formats. One library, the whole pipeline.
8
8
 
9
- **Jump to:** [⚡ 60 second start](#-60-second-start) · [🧩 SDK](#-the-sdk-workflows-as-code) · [🧬 Codegen](#-the-codegen-nothing-else-comes-close) · [🎛️ App mode & vars](#-app-mode--vars-knobs-on-everything) · [🖥️ TUI](#-the-tui) · [⌨️ CLI](#-the-cli) · [🌍 Comfy Cloud & hosts](#-hosts-local-lan-comfy-cloud-any-provider) · [🔌 Ecosystem](#-ecosystem-discovery-and-install) · [🤖 Agents](#-for-ai-agents) · [📚 Examples](#-examples) · [🧱 Trust](#-a-lib-you-can-trust-made-to-last)
9
+ **Jump to:** [⚡ 60 second start](#-60-second-start) · [🧩 SDK](#-the-sdk-workflows-as-code) · [🧬 Codegen](#-the-codegen-nothing-else-comes-close) · [🎛️ App mode & vars](#-app-mode--vars-knobs-on-everything) · [🖥️ TUI](#-the-tui) · [🌐 Web panel](#-the-web-panel) · [⌨️ CLI](#-the-cli) · [🌍 Comfy Cloud & hosts](#-hosts-local-lan-comfy-cloud-any-provider) · [🔌 Ecosystem](#-ecosystem-discovery-and-install) · [🤖 Agents](#-for-ai-agents) · [📚 Examples](#-examples) · [🧱 Trust](#-a-lib-you-can-trust-made-to-last)
10
10
 
11
11
  ## What's inside
12
12
 
@@ -15,6 +15,7 @@ _the ultimate ComfyUI toolkit for TypeScript: `SDK` + `CLI` + `TUI` + agent guid
15
15
  | 🧩 **the SDK** | build and run workflows in code, typed down to the model names of your exact machine |
16
16
  | ⌨️ **the CLI** | one command codegens a full typed SDK for any host, local or remote cloud |
17
17
  | 🖥️ **the TUI** | drive every workflow from the terminal: knobs, drafts, queue, live latent previews |
18
+ | 🌐 **the web panel** | the same workflows as a browser form, phone included, with an LLM prompt refiner built in |
18
19
  | 🤖 **agent tools** | typed discovery and install across the whole custom node ecosystem, built for automation |
19
20
  | 🔁 **JSON, both ways** | import and export `api.json` and `workflow.json`, drag your code onto the Comfy canvas |
20
21
 
@@ -209,11 +210,12 @@ await txt2img.run({ log: true }) // fresh graph, fresh image
209
210
 
210
211
  | var kind | superpower |
211
212
  | ----------------------- | --------------------------------------------------------------------------------- |
212
- | `v.seed` | mode + number (`+ N` `- N` `= N` `? N`), advances itself: queued runs differ |
213
+ | `v.seed` | mode + number (`+ N` `- N` `= N` `? N`), advances itself: queued runs differ. `v.seed(42, { mode: '+' })` declares the mode |
213
214
  | `v.prompt` | structured text: `//` comments stripped, `- ` lines become the negative prompt |
214
215
  | `v.loras` | RegExp resolved against the host's REAL lora list, fully typed, multi-select |
215
216
  | `v.image` | local image path, TUI picker attached; `exampleImagePath('bear_1024x1024.jpg')` defaults to a bundled sample |
216
217
  | `v.text` `v.int` `v.float` `v.toggle` `v.choice` `v.size` | the everyday knobs, ranges included |
218
+ | `presets` on `v.text` / `v.prompt` | named starting texts (`{ 'terse tags': '…' }`): a presets button in the web panel, `P` in the TUI. Picking one replaces the field. `promptEnhancerPresets()` offers your `.comfy-ts/prompt-enhancers/*.md` library as presets too |
217
219
 
218
220
  `vars` can be a lambda receiving `v` so vars reference each other: `v.prompt('a cozy house', { loraKeywordsFrom: loras })` prefixes the active loras' trigger keywords. Name the file `*.cflow.ts` and the TUI finds it.
219
221
 
@@ -321,7 +323,7 @@ bunx comfy-ts serve txt2img.cflow.ts # one workflow (routes shorten to /gener
321
323
  bunx comfy-ts serve --port 9000 --host 0.0.0.0 # pick port / reach it from your phone or tailnet
322
324
  ```
323
325
 
324
- Bound beyond localhost, the startup print lists every URL the box answers on (LAN and tailnet), so the web UI is one tap away on another device. There is no auth: only do this on a network you trust.
326
+ Bound beyond localhost, the startup print lists every URL the box answers on (LAN and tailnet), so the web UI is one tap away on another device. There is no auth: only do this on a network you trust. A browser page on any origin may call it, which is what lets `comfy-ts/web` use serve as its bridge; with no auth, that also means a page you visit can reach the API on your own machine. The launch screen says so every time.
325
327
 
326
328
  Discover what's being served — same info the startup print shows, as JSON:
327
329
 
@@ -342,16 +344,18 @@ curl -X POST http://127.0.0.1:8288/generate/txt2img/moody \
342
344
  -H 'accept: image/*' -d '{"seed": 42}' -o out.png # raw image bytes
343
345
  ```
344
346
 
345
- Draft values are the defaults, the JSON body overrides per request, and every value is validated before anything is queued (wrong choice? the 400 lists the allowed ones). `GET /drafts` self-describes every workflow, draft and var — enough for a frontend to render a form. `Accept: image/*` returns the image bytes directly (`curl … -H 'accept: image/*' -o out.png`). Drafts are re-read on every request: keep the TUI open, tweak, next call uses the new values. Binds to localhost only unless you say otherwise (`--bind`, `--port`).
347
+ Draft values are the defaults, the JSON body overrides per request, and every value is validated before anything is queued (wrong choice? the 400 lists the allowed ones). `GET /drafts` self-describes every workflow, draft and var — enough for a frontend to render a form. `Accept: image/*` returns the image bytes directly (`curl … -H 'accept: image/*' -o out.png`). Drafts are re-read on every request: keep the TUI open, tweak, next call uses the new values. Binds to localhost only unless you say otherwise (`--host`, `--port`).
346
348
 
347
- ### The web panel
349
+ ## 🌐 The web panel
348
350
 
349
- Open the same url in a **browser** and you get a full control panel — no frontend to write:
351
+ Open that same url in a **browser** and you get a full control panel — no frontend to write, nothing to build, no extra dependency:
350
352
 
351
- - every var as its real control: prompt textarea (`//` comments, `- ` negative lines), sliders, seed mode buttons (fixed / +1 / -1 / random) with 🎲, size presets, image upload with preview, and a lora picker popup — a searchable gallery of preview cards with human model names and trigger words from the [lora mirror](#loras), active loras pinned on top with per-lora model/clip strengths
352
- - edits **autosave into the selected draft**, exactly like the TUI (the two stay in sync live); duplicate a draft from the header
353
- - generate with a live progress bar and latent preview, results in a gallery — click any image for the lightbox (copy to clipboard / open / delete)
354
- - works on a phone: collapsible menu, everything touch-sized; lora images and titles can be hidden with one persistent toggle each
353
+ - every var as its real control: prompt textarea (`//` comments, `- ` negative lines), sliders, seed mode buttons (`=` `+` `?`) with 🎲, size presets, image upload with preview, and a lora palette — a switch on each card pauses or resumes that lora in place, and clicking the card opens what it is, with per-lora model/clip strengths, and browse the rest as a gallery of preview cards carrying human model names and trigger words from the [lora mirror](#loras)
354
+ - edits **autosave into the selected draft**, exactly like the TUI (the two stay in sync live); duplicate or delete a draft from the header
355
+ - every click on generate **queues** another prompt; the queue lists them and drops any pending one
356
+ - live progress bar and latent preview while it runs, results in a gallery — click any image for the lightbox (copy to clipboard / open / delete)
357
+ - **works on a phone**: collapsible menu, everything touch-sized. `--host 0.0.0.0` and the startup print hands you the LAN and tailnet urls
358
+ - ✨ **prompt refiner** on every prompt var: rewrite the prompt with a thinking model, streaming both the answer and the model's reasoning, then apply it — or not, nothing touches your prompt until you say so. Cloud through **OpenRouter**, or a local model through **Open WebUI** (a local model's `<think>` block is routed to the reasoning pane, never into your prompt). Your key stays in the browser and never reaches the serve process. The master prompts are markdown files in `.comfy-ts/prompt-enhancers/`, one per image model, editable from the panel or from your editor
355
359
 
356
360
  The JSON api above is unchanged — the panel is just another client of it.
357
361
 
@@ -443,6 +447,7 @@ Start with the didactic sequence in [`examples/rvion/`](examples/rvion/):
443
447
  | [`04-krea2-turbo-t2i`](examples/rvion/04-krea2-turbo-t2i.cflow.ts) | a real pipeline: krea2 turbo, lora stack, RMBG cutout → transparent png |
444
448
  | [`05-comfy-cloud`](examples/rvion/05-comfy-cloud.cflow.ts) | the same code on Comfy Cloud: `url` + `apiKey` host, typechecked against the committed catalog SDK |
445
449
  | [`06-qwen-image-edit`](examples/rvion/06-qwen-image-edit.cflow.ts) | Qwen Image Edit 2511, lightning 4-step lora toggle |
450
+ | [`07-local-llm-text-gen`](examples/rvion/07-local-llm-text-gen.cflow.ts) | a local LLM through core `TextGenerate`, text back in `execution.text`; `--sweep` probes every text encoder on the host |
446
451
 
447
452
  ### The model zoo: 46 cloud workflows, 32 model families
448
453
 
@@ -478,7 +483,9 @@ One folder of local state per consumer repo: `hosts/` (schema dumps + the genera
478
483
  | export api.json + autolayouted workflow.json | ✅ |
479
484
  | import api.json into a live workflow | ✅ |
480
485
  | import workflow.json (litegraph → api conversion) | ✅ |
481
- | sidekick CLI (`gen`, `outline`, `tui`) | ✅ |
486
+ | sidekick CLI (`gen`, `outline`, `tui`, `serve`) | ✅ |
487
+ | serve web panel: every var as a control, queue, gallery, phone | ✅ |
488
+ | prompt refiner in the panel (OpenRouter or local Open WebUI) | ✅ |
482
489
  | cloud hosts: `url` + `X-API-Key` auth, Comfy Cloud ran live | ✅ |
483
490
  | ComfyUI-Manager registry mirror + Known\* ecosystem unions | ✅ |
484
491
  | install custom nodes / models via ComfyUI-Manager (v2 API) | 🔶 |
@@ -71,6 +71,13 @@ function sha1HexOfString(s) {
71
71
  return sha1Hex(new TextEncoder().encode(s));
72
72
  }
73
73
  //#endregion
74
+ //#region src/utils/matchesRegex.ts
75
+ function statelessRegex(re) {
76
+ if (!re.global && !re.sticky) return re;
77
+ const source = re.sticky ? `^(?:${re.source})` : re.source;
78
+ return new RegExp(source, re.flags.replace(/[gy]/g, ""));
79
+ }
80
+ //#endregion
74
81
  //#region src/utils/log.ts
75
82
  const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
76
83
  const logInfo = (msg) => {
@@ -142,6 +149,12 @@ const bang = (x, msg = "") => {
142
149
  return x;
143
150
  };
144
151
  //#endregion
152
+ //#region src/utils/isRecord.ts
153
+ /** narrows unknown wire json to an indexable object (arrays and null excluded) */
154
+ function isRecord(v) {
155
+ return typeof v === "object" && v !== null && !Array.isArray(v);
156
+ }
157
+ //#endregion
145
158
  //#region src/utils/extractErrorMessage.ts
146
159
  /** Extracts an error message from an exception stuff. */
147
160
  const extractErrorMessage = (error) => {
@@ -155,10 +168,40 @@ const extractErrorMessage = (error) => {
155
168
  return String(error);
156
169
  };
157
170
  //#endregion
158
- //#region src/utils/isRecord.ts
159
- /** narrows unknown wire json to an indexable object (arrays and null excluded) */
160
- function isRecord(v) {
161
- return typeof v === "object" && v !== null && !Array.isArray(v);
171
+ //#region src/utils/ansi.ts
172
+ const codes = {
173
+ bold: [1, 22],
174
+ dim: [2, 22],
175
+ underline: [4, 24],
176
+ red: [31, 39],
177
+ green: [32, 39],
178
+ yellow: [33, 39],
179
+ blue: [34, 39],
180
+ cyan: [36, 39],
181
+ gray: [90, 39],
182
+ greenBright: [92, 39]
183
+ };
184
+ function styler(open = "", close = "") {
185
+ const fn = (s) => open + s + close;
186
+ return new Proxy(fn, { get(_target, prop) {
187
+ const c = codes[prop];
188
+ if (c == null) throw new Error(`unknown ansi style: ${prop}`);
189
+ return styler(`${open}\x1b[${c[0]}m`, `\x1b[${c[1]}m${close}`);
190
+ } });
191
+ }
192
+ const ansi = styler();
193
+ const ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]|\x1b[A-Za-z]/g;
194
+ function stripAnsi(s) {
195
+ return s.replace(ANSI_RE, "");
196
+ }
197
+ /** colors only where they can be seen: a real terminal, NO_COLOR unset, TERM not 'dumb'.
198
+ * A piped or redirected stdout gets plain text, so `serve > log` stays greppable */
199
+ function colorsAvailable() {
200
+ const env = globalThis.process?.env ?? {};
201
+ if (env.NO_COLOR != null && env.NO_COLOR !== "") return false;
202
+ if (env.TERM === "dumb") return false;
203
+ if (env.FORCE_COLOR != null && env.FORCE_COLOR !== "" && env.FORCE_COLOR !== "0") return true;
204
+ return globalThis.process?.stdout?.isTTY === true;
162
205
  }
163
206
  //#endregion
164
207
  //#region src/host/loraManagerApi.ts
@@ -191,6 +234,29 @@ function lmBaseModel(item) {
191
234
  function lmPreviewUrl(item) {
192
235
  return readString(item, "preview_url");
193
236
  }
237
+ /** the file's size in bytes, when the extension reports it */
238
+ /** the file's content hash: what the extension keys its example images by */
239
+ function lmSha256(item) {
240
+ return readString(item, "sha256");
241
+ }
242
+ function lmFileSize(item) {
243
+ const raw = item["file_size"];
244
+ return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
245
+ }
246
+ /** the note YOU wrote in the lora manager, empty when there is none */
247
+ function lmNotes(item) {
248
+ return readString(item, "notes") ?? "";
249
+ }
250
+ /** the civitai block: what links a local file back to the page it came from */
251
+ function lmCivitai(item) {
252
+ const civitai = item["civitai"];
253
+ if (!isRecord(civitai)) return null;
254
+ const modelId = civitai["modelId"];
255
+ return {
256
+ modelId: typeof modelId === "number" && Number.isFinite(modelId) ? modelId : null,
257
+ name: readString(civitai, "name")
258
+ };
259
+ }
194
260
  function lmTags(item) {
195
261
  return readStringArray(item, "tags");
196
262
  }
@@ -200,6 +266,10 @@ function lmTrainedWords(item) {
200
266
  if (!isRecord(civitai)) return [];
201
267
  return readStringArray(civitai, "trainedWords");
202
268
  }
269
+ /** lm's own absolute path for the file, as it exists on the HOST's disk */
270
+ function lmFilePath(item) {
271
+ return readString(item, "file_path");
272
+ }
203
273
  /**
204
274
  * the ONE key space where a host's object_info spelling of a lora meets
205
275
  * lora-manager's: lowercase, forward slashes, no model extension.
@@ -222,6 +292,65 @@ function lmItemKey(item) {
222
292
  }
223
293
  /** runaway stop: 20 pages × the server's 100-per-page cap = 2000 loras */
224
294
  const MAX_PAGES = 20;
295
+ /** civitai's model description for ONE lora, as PLAIN TEXT. The extension answers html, and
296
+ * html from a third party is never rendered: tags are stripped here, at the seam.
297
+ * null = the extension has no description for it (or does not expose the route) */
298
+ async function fetchLoraDescription(host, filePath) {
299
+ try {
300
+ const res = await host.fetch(`/lm/loras/model-description?file_path=${encodeURIComponent(filePath)}`, {});
301
+ if (!res.ok) {
302
+ if (res.status !== 404) logError(`[lora-manager] description ${res.status} for ${filePath}`);
303
+ return null;
304
+ }
305
+ const raw = await res.json();
306
+ const description = isRecord(raw) ? raw["description"] : null;
307
+ if (typeof description !== "string" || description === "") return null;
308
+ return htmlToText(description);
309
+ } catch (e) {
310
+ logError(`[lora-manager] description unreachable for ${filePath}: ${extractErrorMessage(e)}`);
311
+ return null;
312
+ }
313
+ }
314
+ /** `<p>a</p><br>b` → `a\n\nb`. Deliberately dumb: this text is DISPLAYED, never parsed */
315
+ function htmlToText(html) {
316
+ return html.replaceAll(/<\s*br\s*\/?>/gi, "\n").replaceAll(/<\/\s*(p|div|li|h[1-6])\s*>/gi, "\n\n").replaceAll(/<\s*li[^>]*>/gi, "· ").replaceAll(/<[^>]+>/g, "").replaceAll("&nbsp;", " ").replaceAll("&amp;", "&").replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&quot;", "\"").replaceAll("&#39;", "'").replaceAll(/\n{3,}/g, "\n\n").trim();
317
+ }
318
+ /** the example images lora-manager keeps for a lora. `reason` explains an empty list rather
319
+ * than pretending the lora has none, "no example images path configured" is a SETTING */
320
+ async function fetchLoraExampleImages(host, sha256) {
321
+ try {
322
+ const res = await host.fetch(`/lm/example-image-files?model_hash=${encodeURIComponent(sha256)}`, {});
323
+ const raw = await res.json();
324
+ if (!isRecord(raw)) return {
325
+ files: [],
326
+ reason: `unexpected reply (http ${res.status})`
327
+ };
328
+ if (raw["success"] !== true) {
329
+ const err = raw["error"];
330
+ return {
331
+ files: [],
332
+ reason: typeof err === "string" ? err : `http ${res.status}`
333
+ };
334
+ }
335
+ const files = raw["files"];
336
+ if (!Array.isArray(files)) return {
337
+ files: [],
338
+ reason: null
339
+ };
340
+ const out = [];
341
+ for (const f of files) if (typeof f === "string") out.push(f);
342
+ else if (isRecord(f) && typeof f["path"] === "string") out.push(f["path"]);
343
+ return {
344
+ files: out,
345
+ reason: null
346
+ };
347
+ } catch (e) {
348
+ return {
349
+ files: [],
350
+ reason: e instanceof Error ? e.message : String(e)
351
+ };
352
+ }
353
+ }
225
354
  /**
226
355
  * every lora lora-manager knows, RAW, in one paged sweep.
227
356
  * page_size asks for 500; the server caps it at 100, so the loop follows `total`.
@@ -441,6 +570,11 @@ function refreshLoraInfoCacheIfChanged() {
441
570
  if (!loadedMtimes.has(hostId) || seen !== now) loadHost(hostId);
442
571
  }
443
572
  }
573
+ /** forget everything loaded, so the next read re-reads from disk (tests, and a hard refresh) */
574
+ function reloadLoraInfoCache() {
575
+ byHost.clear();
576
+ loadedMtimes.clear();
577
+ }
444
578
  /**
445
579
  * the lm item for a raw lora name (`styles\x.safetensors`).
446
580
  * `hostId` picks the mirror that actually describes this host's file; without
@@ -475,6 +609,29 @@ function getLoraPreviewUrl(name, hostId) {
475
609
  return info == null ? null : lmPreviewUrl(info);
476
610
  }
477
611
  /** the lora's NAMES: the file, and the model name a human would call it by */
612
+ /**
613
+ * every lora the mirror knows for a host: its normalized KEY (comparable with `loraKey(option)`,
614
+ * never with a raw enum value, those keep their case, extension and windows separators) and the
615
+ * NAME a ComfyUI graph would load it by, rebuilt from the manager's folder + real filename.
616
+ * `[]` when the host was never synced.
617
+ */
618
+ function loraMirrorEntries(hostId, p = {}) {
619
+ ensureLoaded();
620
+ const sep = p.separator ?? "/";
621
+ const out = [];
622
+ for (const [key, item] of byHost.get(hostId) ?? []) {
623
+ const filePath = lmFilePath(item);
624
+ const file = (filePath == null ? null : filePath.split(/[/\\]/).pop() ?? null) ?? lmFileName(item);
625
+ if (file == null) continue;
626
+ const folder = lmFolder(item);
627
+ const joined = folder === "" ? file : `${folder}/${file}`;
628
+ out.push({
629
+ key,
630
+ serverName: joined.replaceAll(/[\\/]/g, sep)
631
+ });
632
+ }
633
+ return out.sort((a, b) => a.serverName.localeCompare(b.serverName));
634
+ }
478
635
  function loraSearchNames(name, hostId) {
479
636
  const names = [loraBasename(name), name.replaceAll("\\", "/")];
480
637
  const info = getLoraInfo(name, hostId);
@@ -596,6 +753,15 @@ function writeKeywords() {
596
753
  }
597
754
  }
598
755
  //#endregion
756
+ //#region src/vars/presets.ts
757
+ function toPresetList(spec) {
758
+ if (spec == null) return [];
759
+ return Object.entries(spec).map(([label, text]) => ({
760
+ label,
761
+ text
762
+ }));
763
+ }
764
+ //#endregion
599
765
  //#region src/vars/ComfyVars.ts
600
766
  /**
601
767
  * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
@@ -653,9 +819,14 @@ var ComfyVar = class extends ComfyVarBase {
653
819
  }
654
820
  };
655
821
  var TextVar = class extends ComfyVar {
656
- constructor(..._args) {
657
- super(..._args);
822
+ /** a bare label string was the whole second parameter before opts existed: a published
823
+ * consumer passing one must keep working, exactly as SeedVar does */
824
+ constructor(defaultValue, opts = {}) {
825
+ const o = typeof opts === "string" ? { label: opts } : opts;
826
+ super(defaultValue, o.label);
658
827
  this.kind = "text";
828
+ this.opts = o;
829
+ this.presets = toPresetList(o.presets);
659
830
  }
660
831
  parse(raw) {
661
832
  this.set(raw);
@@ -679,6 +850,7 @@ var PromptVar = class extends ComfyVarBase {
679
850
  super(defaultValue, promptOpts.label);
680
851
  this.promptOpts = promptOpts;
681
852
  this.kind = "prompt";
853
+ this.presets = toPresetList(promptOpts.presets);
682
854
  }
683
855
  parse(raw) {
684
856
  this.set(raw);
@@ -755,11 +927,14 @@ var FloatVar = class extends ComfyVar {
755
927
  * The number shown is always the seed the NEXT run will use.
756
928
  */
757
929
  var SeedVar = class extends ComfyVar {
758
- constructor(defaultValue = 0, label) {
759
- super(defaultValue, label);
930
+ /** `opts` is the modern shape; a bare label string stays accepted, since that was the
931
+ * signature before a workflow could declare the mode it wants to run in */
932
+ constructor(defaultValue = 0, opts = {}) {
933
+ const o = typeof opts === "string" ? { label: opts } : opts;
934
+ super(defaultValue, o.label);
760
935
  this.kind = "seed";
761
- this.mode = "=";
762
- this.defaultMode = "=";
936
+ this.mode = o.mode ?? "=";
937
+ this.defaultMode = this.mode;
763
938
  makeObservable(this, {
764
939
  mode: observable,
765
940
  setMode: action,
@@ -827,8 +1002,8 @@ var SeedVar = class extends ComfyVar {
827
1002
  }
828
1003
  };
829
1004
  var ToggleVar = class extends ComfyVar {
830
- constructor(..._args2) {
831
- super(..._args2);
1005
+ constructor(..._args) {
1006
+ super(..._args);
832
1007
  this.kind = "toggle";
833
1008
  }
834
1009
  toggle() {
@@ -875,6 +1050,12 @@ var LorasVar = class LorasVar extends ComfyVar {
875
1050
  this.resolvedOptions = null;
876
1051
  this.hostId = void 0;
877
1052
  }
1053
+ /** the filter the workflow declared, when it declared one (`v.loras(/krea-?2/i)`). Public so
1054
+ * a UI can SHOW it, and so serve applies the same narrowing to loras only its lora-manager
1055
+ * mirror knows, an unfiltered union would put the whole catalog back in a filtered picker */
1056
+ get optionsFilter() {
1057
+ return this.optionsSource instanceof RegExp ? this.optionsSource : null;
1058
+ }
878
1059
  get options() {
879
1060
  if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
880
1061
  if (this.resolvedOptions == null) throw new Error(`v.loras(${String(this.optionsSource)}) is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list otherwise)`);
@@ -1129,11 +1310,13 @@ var ImageVar = class extends ComfyVar {
1129
1310
  };
1130
1311
  /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
1131
1312
  const v = {
1132
- text: (defaultValue, label) => new TextVar(defaultValue, label),
1313
+ text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
1133
1314
  prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
1134
1315
  int: (defaultValue, opts = {}) => new IntVar(defaultValue, opts),
1135
1316
  float: (defaultValue, opts = {}) => new FloatVar(defaultValue, opts),
1136
- seed: (defaultValue = 0, label) => new SeedVar(defaultValue, label),
1317
+ /** `mode` is the SPEC default the workflow runs in: `'+'` makes every run step the seed,
1318
+ * which is what a tuning session wants, and reset()/revert come back to it */
1319
+ seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
1137
1320
  toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
1138
1321
  choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
1139
1322
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
@@ -1210,6 +1393,6 @@ var DefinedWorkflow = class {
1210
1393
  }
1211
1394
  };
1212
1395
  //#endregion
1213
- export { logInfo as A, loraPreviewMapFrom as C, resolveComfyStorage as D, getComfyStorage as E, sha1Hex as M, sha1HexOfString as N, isQuiet as O, loraKey as S, bang as T, fetchLoraList as _, getLoraKeyword as a, lmTrainedWords as b, setLoraKeyword as c, getLoraPreviewUrl as d, getLoraTriggerWords as f, writeLoraMirror as g, refreshLoraInfoCacheIfChanged as h, clearLoraKeywordOverride as i, logSuccess as j, logError as k, buildLoraMirror as l, readLoraMirror as m, LorasVar as n, isLoraKeywordFromMirror as o, loraMatchesFilter as p, PromptVar as r, loraKeywordFromMirror as s, DefinedWorkflow as t, getLoraDisplayName as u, fetchLoraPreviewBytes as v, extractErrorMessage as w, loraBasename as x, lmModelName as y };
1396
+ export { lmModelName as A, stripAnsi as B, fetchLoraList as C, lmFilePath as D, lmCivitai as E, loraBasename as F, resolveComfyStorage as G, isRecord as H, loraKey as I, logInfo as J, isQuiet as K, loraPreviewMapFrom as L, lmSha256 as M, lmTags as N, lmFileSize as O, lmTrainedWords as P, sha1HexOfString as Q, ansi as R, fetchLoraExampleImages as S, lmBaseModel as T, bang as U, extractErrorMessage as V, getComfyStorage as W, statelessRegex as X, logSuccess as Y, sha1Hex as Z, readLoraMirror as _, clearLoraKeywordOverride as a, writeLoraMirror as b, loraKeywordFromMirror as c, getLoraDisplayName as d, getLoraInfo as f, loraMirrorEntries as g, loraMatchesFilter as h, PromptVar as i, lmNotes as j, lmFolder as k, setLoraKeyword as l, getLoraTriggerWords as m, DEFAULT_IMAGE_EXTENSIONS as n, getLoraKeyword as o, getLoraPreviewUrl as p, logError as q, LorasVar as r, isLoraKeywordFromMirror as s, DefinedWorkflow as t, buildLoraMirror as u, refreshLoraInfoCacheIfChanged as v, fetchLoraPreviewBytes as w, fetchLoraDescription as x, reloadLoraInfoCache as y, colorsAvailable as z };
1214
1397
 
1215
- //# sourceMappingURL=DefinedWorkflow-BJgt5t0x.js.map
1398
+ //# sourceMappingURL=DefinedWorkflow-BatWaZO1.js.map