comfy-ts 2.11.0 → 2.12.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 (99) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-qtFzOKpu.js → LogsSt-U1H0mP1m.js} +35 -5
  3. package/dist/LogsSt-U1H0mP1m.js.map +1 -0
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +473 -62
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +191 -31
  8. package/dist/index.d.ts +191 -31
  9. package/dist/index.js +469 -63
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-BK7BA2dn.js → run-serve-BeAznay5.js} +461 -43
  12. package/dist/run-serve-BeAznay5.js.map +1 -0
  13. package/dist/{run-tui-CQyvMf0N.js → run-tui-BTGjvnKk.js} +43 -18
  14. package/dist/run-tui-BTGjvnKk.js.map +1 -0
  15. package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-Cg39vs53.js} +470 -60
  16. package/dist/schemaDrift-Cg39vs53.js.map +1 -0
  17. package/dist/serve-web.js +508 -134
  18. package/dist/{state--wrz0BQc.js → state-C7REnHan.js} +7 -3
  19. package/dist/{state--wrz0BQc.js.map → state-C7REnHan.js.map} +1 -1
  20. package/dist/web.d.ts +191 -31
  21. package/dist/web.js +469 -63
  22. package/dist/web.js.map +1 -1
  23. package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
  24. package/examples/rvion/10-anima-t2i.cflow.ts +229 -0
  25. package/extra/README.md +4 -0
  26. package/extra/comfyui-fresh-model-lists/README.md +25 -0
  27. package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
  28. package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
  29. package/package.json +15 -7
  30. package/src/cli/draftMeta.ts +39 -0
  31. package/src/cli/serve/ServeApp.ts +148 -12
  32. package/src/cli/serve/applyVarPayload.ts +50 -22
  33. package/src/cli/serve/describeVar.ts +42 -6
  34. package/src/cli/serve/llmConfigShape.ts +51 -0
  35. package/src/cli/serve/llmConfigs.ts +52 -0
  36. package/src/cli/serve/tagList.ts +92 -0
  37. package/src/cli/serve/tagSource.ts +69 -0
  38. package/src/cli/serve/web/api.ts +48 -0
  39. package/src/cli/serve/web/components/App.tsx +336 -44
  40. package/src/cli/serve/web/components/Gallery.tsx +105 -28
  41. package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
  42. package/src/cli/serve/web/components/Icon.tsx +18 -2
  43. package/src/cli/serve/web/components/MenuButton.tsx +53 -0
  44. package/src/cli/serve/web/components/Omnibox.tsx +85 -0
  45. package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
  46. package/src/cli/serve/web/components/TooltipLayer.tsx +45 -0
  47. package/src/cli/serve/web/components/VarIcon.tsx +24 -0
  48. package/src/cli/serve/web/components/VarsForm.tsx +341 -188
  49. package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
  50. package/src/cli/serve/web/components/controls/LorasControl.tsx +644 -317
  51. package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
  52. package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
  53. package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
  54. package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
  55. package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
  56. package/src/cli/serve/web/components/modKey.ts +2 -0
  57. package/src/cli/serve/web/llm.ts +23 -12
  58. package/src/cli/serve/web/promptEditor/promptExtensions.ts +281 -0
  59. package/src/cli/serve/web/state/EnhancerSt.ts +415 -100
  60. package/src/cli/serve/web/state/FormSt.ts +193 -29
  61. package/src/cli/serve/web/state/OmniboxSt.ts +57 -0
  62. package/src/cli/serve/web/state/WebSt.ts +219 -74
  63. package/src/cli/serve/web/state/choiceButtons.ts +61 -0
  64. package/src/cli/serve/web/state/generateButton.ts +16 -0
  65. package/src/cli/serve/web/state/history.ts +54 -0
  66. package/src/cli/serve/web/state/host.ts +5 -2
  67. package/src/cli/serve/web/state/keptLines.ts +53 -0
  68. package/src/cli/serve/web/state/latentMode.ts +20 -0
  69. package/src/cli/serve/web/state/loraSort.ts +18 -0
  70. package/src/cli/serve/web/state/moduleTree.ts +2 -2
  71. package/src/cli/serve/web/state/omnibox.ts +69 -0
  72. package/src/cli/serve/web/state/payload.ts +38 -58
  73. package/src/cli/serve/web/state/shortcuts.ts +54 -0
  74. package/src/cli/serve/web/state/sizeStars.ts +31 -0
  75. package/src/cli/serve/web/state/stableSlots.ts +21 -0
  76. package/src/cli/serve/web/state/varGroups.ts +24 -0
  77. package/src/cli/serve/web/styles.ts +457 -118
  78. package/src/cli/serve/webBundle.ts +54 -10
  79. package/src/cli/tui/components/PickerOverlays.tsx +9 -2
  80. package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
  81. package/src/cli/tui/state/DraftsSt.ts +18 -2
  82. package/src/cli/tui/state/EditorSt.ts +1 -1
  83. package/src/cli/tui/state/LorasSt.ts +1 -1
  84. package/src/cli/tui/state/PickerSt.ts +25 -7
  85. package/src/cli/tui/state/SettingsSt.ts +1 -1
  86. package/src/cli/tui/state/TuiSt.ts +10 -0
  87. package/src/coreExports.ts +20 -0
  88. package/src/host/loraInfoCache.ts +6 -0
  89. package/src/state.ts +5 -0
  90. package/src/vars/ComfyVars.ts +337 -67
  91. package/src/vars/DefinedWorkflow.ts +40 -19
  92. package/src/vars/lanes.ts +238 -0
  93. package/src/vars/loraEntry.ts +101 -0
  94. package/src/vars/promptSyntax.ts +382 -0
  95. package/dist/LogsSt-qtFzOKpu.js.map +0 -1
  96. package/dist/run-serve-BK7BA2dn.js.map +0 -1
  97. package/dist/run-tui-CQyvMf0N.js.map +0 -1
  98. package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
  99. package/src/cli/serve/web/components/Sidebar.tsx +0 -66
package/dist/index.js CHANGED
@@ -110,7 +110,7 @@ function createNodeStorage() {
110
110
  }
111
111
  //#endregion
112
112
  //#region package.json
113
- var version = "2.11.0";
113
+ var version = "2.12.0";
114
114
  //#endregion
115
115
  //#region src/litegraph/LiteGraphLinkID.ts
116
116
  const asLiteGraphLinkID = (id) => id;
@@ -4350,6 +4350,221 @@ function writeKeywords() {
4350
4350
  }
4351
4351
  }
4352
4352
  //#endregion
4353
+ //#region src/vars/loraEntry.ts
4354
+ function isLoraEntry(s) {
4355
+ if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
4356
+ const o = s;
4357
+ const st = o.strength;
4358
+ return Array.isArray(st) && st.length === 2 && typeof st[0] === "number" && Number.isFinite(st[0]) && typeof st[1] === "number" && Number.isFinite(st[1]) && (o.off == null || typeof o.off === "boolean") && (o.mute == null || Array.isArray(o.mute) && o.mute.every((w) => typeof w === "string"));
4359
+ }
4360
+ function isLoraStrength(s) {
4361
+ if (typeof s === "boolean") return true;
4362
+ if (typeof s === "number") return Number.isFinite(s);
4363
+ if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
4364
+ return isLoraEntry(s);
4365
+ }
4366
+ /** on = it runs */
4367
+ function loraIsOn(s) {
4368
+ if (s == null || s === false) return false;
4369
+ if (isLoraEntry(s)) return s.off !== true;
4370
+ return true;
4371
+ }
4372
+ /** the strengths, whatever the spelling (1/1 when there is nothing to read) */
4373
+ function loraStrengths(s) {
4374
+ if (typeof s === "number" && Number.isFinite(s)) return [s, s];
4375
+ if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
4376
+ if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
4377
+ return [1, 1];
4378
+ }
4379
+ function loraMuted(s) {
4380
+ return isLoraEntry(s) && s.mute != null ? s.mute : [];
4381
+ }
4382
+ /** a prompt keyword's parts, split at commas: each one can be left out on its own */
4383
+ function keywordParts(keyword) {
4384
+ return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
4385
+ }
4386
+ /** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
4387
+ function keptKeyword(keyword, muted) {
4388
+ return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
4389
+ }
4390
+ /** rewrite one setting, keeping what the patch does not name. The result stays in the short
4391
+ * spellings while nothing needs the palette form, so a plain draft reads as it always did */
4392
+ function withLora(s, patch) {
4393
+ const strength = patch.strength ?? loraStrengths(s);
4394
+ const off = patch.on == null ? !loraIsOn(s) : !patch.on;
4395
+ const mute = [...patch.mute ?? loraMuted(s)];
4396
+ if (!off && mute.length === 0) return [strength[0], strength[1]];
4397
+ return {
4398
+ strength: [strength[0], strength[1]],
4399
+ ...off ? { off: true } : {},
4400
+ ...mute.length === 0 ? {} : { mute }
4401
+ };
4402
+ }
4403
+ //#endregion
4404
+ //#region src/vars/lanes.ts
4405
+ const FIRST_LANE = "main";
4406
+ function isObject(v) {
4407
+ return typeof v === "object" && v != null && !Array.isArray(v);
4408
+ }
4409
+ function isPromptLane(v) {
4410
+ return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
4411
+ }
4412
+ function isPromptLanes(v) {
4413
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
4414
+ }
4415
+ /** the text the build reads: the active lanes joined in order, one line break between them, so
4416
+ * `//` and `- ` lines keep working inside every lane */
4417
+ function promptText(v) {
4418
+ if (typeof v === "string") return v;
4419
+ return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
4420
+ }
4421
+ const HEADER = /^# (.+?)( \(off\))?$/;
4422
+ function promptLanesToText(v) {
4423
+ return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
4424
+ }
4425
+ /** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
4426
+ function promptLanesFromText(text) {
4427
+ const lanes = [];
4428
+ let current = null;
4429
+ const body = [];
4430
+ const close = () => {
4431
+ if (current != null) lanes.push({
4432
+ ...current,
4433
+ prompt: body.join("\n")
4434
+ });
4435
+ else if (body.some((l) => l.trim() !== "")) lanes.push({
4436
+ name: FIRST_LANE,
4437
+ prompt: body.join("\n"),
4438
+ active: true
4439
+ });
4440
+ body.length = 0;
4441
+ };
4442
+ for (const line of text.split("\n")) {
4443
+ const m = HEADER.exec(line);
4444
+ if (m == null) {
4445
+ body.push(line);
4446
+ continue;
4447
+ }
4448
+ close();
4449
+ current = {
4450
+ name: (m[1] ?? "").trim(),
4451
+ prompt: "",
4452
+ active: m[2] == null
4453
+ };
4454
+ }
4455
+ close();
4456
+ return { lanes: lanes.length > 0 ? lanes : [{
4457
+ name: FIRST_LANE,
4458
+ prompt: "",
4459
+ active: true
4460
+ }] };
4461
+ }
4462
+ function isLoraRecord(v) {
4463
+ return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
4464
+ }
4465
+ function isLoraLane(v) {
4466
+ return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
4467
+ }
4468
+ function isLoraLanes(v) {
4469
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
4470
+ }
4471
+ function isLorasInput(v) {
4472
+ return isLoraRecord(v) || isLoraLanes(v);
4473
+ }
4474
+ /** one record for the build: the active lanes in order. A lora in two active lanes keeps its
4475
+ * FIRST setting, and `duplicates` names it so the caller can say so */
4476
+ function flattenLoras(v) {
4477
+ if (!isLoraLanes(v)) return {
4478
+ record: v,
4479
+ duplicates: []
4480
+ };
4481
+ const record = {};
4482
+ const duplicates = [];
4483
+ for (const lane of v.lanes) {
4484
+ if (!lane.active) continue;
4485
+ for (const [name, st] of Object.entries(lane.loras)) {
4486
+ if (st == null) continue;
4487
+ if (name in record) duplicates.push(name);
4488
+ else record[name] = st;
4489
+ }
4490
+ }
4491
+ return {
4492
+ record,
4493
+ duplicates
4494
+ };
4495
+ }
4496
+ /** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
4497
+ * has it (the one the build reads), else any lane, else -1 */
4498
+ function laneIndexOf(v, name) {
4499
+ const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
4500
+ return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
4501
+ }
4502
+ /** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
4503
+ * A lora in no lane yet lands in the first lane */
4504
+ function updateLora(v, name, next) {
4505
+ const write = (rec) => {
4506
+ const out = { ...rec };
4507
+ if (next == null) delete out[name];
4508
+ else out[name] = next;
4509
+ return out;
4510
+ };
4511
+ if (!isLoraLanes(v)) return write(v);
4512
+ if (v.lanes.length === 0) return { lanes: [{
4513
+ name: FIRST_LANE,
4514
+ active: true,
4515
+ loras: write({})
4516
+ }] };
4517
+ const found = laneIndexOf(v, name);
4518
+ const ix = found === -1 ? 0 : found;
4519
+ return { lanes: v.lanes.map((l, i) => i === ix ? {
4520
+ ...l,
4521
+ loras: write(l.loras)
4522
+ } : l) };
4523
+ }
4524
+ //#endregion
4525
+ //#region src/vars/promptSyntax.ts
4526
+ /** a whole line that is a comment (the TUI colors these) */
4527
+ const COMMENT_LINE_RE = /^\s*\/\//;
4528
+ /** a negative prompt line: `- ` then its text */
4529
+ const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
4530
+ const NEGATIVE_PREFIX_RE = /^(\s*)- /;
4531
+ /** where a `//` comment starts on this line, -1 when none. Only at line start or after
4532
+ * whitespace, so `http://host` is never cut */
4533
+ function commentStart(line) {
4534
+ const m = /(?:^|\s)\/\//.exec(line);
4535
+ if (m == null) return -1;
4536
+ return m.index + m[0].length - 2;
4537
+ }
4538
+ /** the line without its comment, trailing whitespace dropped with it */
4539
+ function withoutComment(line) {
4540
+ const c = commentStart(line);
4541
+ return c < 0 ? {
4542
+ text: line,
4543
+ hadComment: false
4544
+ } : {
4545
+ text: line.slice(0, c).trimEnd(),
4546
+ hadComment: true
4547
+ };
4548
+ }
4549
+ /** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
4550
+ function parsePromptText(text) {
4551
+ const pos = [];
4552
+ const neg = [];
4553
+ for (const raw of text.split("\n")) {
4554
+ const cut = withoutComment(raw);
4555
+ if (cut.hadComment && cut.text.trim() === "") continue;
4556
+ const m = NEGATIVE_PREFIX_RE.exec(raw);
4557
+ if (m != null && m[0].length <= cut.text.length + 1) {
4558
+ const body = cut.text.slice(m[0].length).trim();
4559
+ if (body !== "") neg.push(body);
4560
+ } else pos.push(cut.text);
4561
+ }
4562
+ return {
4563
+ positive: pos.join("\n").trim(),
4564
+ negative: neg.join(", ")
4565
+ };
4566
+ }
4567
+ //#endregion
4353
4568
  //#region src/vars/presets.ts
4354
4569
  function toPresetList(spec) {
4355
4570
  if (spec == null) return [];
@@ -4365,16 +4580,11 @@ function activePresetLabel(presets, value) {
4365
4580
  }
4366
4581
  //#endregion
4367
4582
  //#region src/vars/ComfyVars.ts
4368
- /**
4369
- * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
4370
- * time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
4371
- * the one Out-specialized var (string in, PromptValue out); the split keeps
4372
- * outValue() cast-free.
4373
- */
4374
4583
  var ComfyVarBase = class {
4375
4584
  constructor(defaultValue, label) {
4376
4585
  this.defaultValue = defaultValue;
4377
4586
  this.label = label;
4587
+ this.uiOpts = {};
4378
4588
  this.value = defaultValue;
4379
4589
  makeObservable(this, {
4380
4590
  value: observable,
@@ -4388,6 +4598,14 @@ var ComfyVarBase = class {
4388
4598
  this.value = value;
4389
4599
  return this;
4390
4600
  }
4601
+ /** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
4602
+ ui(p) {
4603
+ this.uiOpts = {
4604
+ ...this.uiOpts,
4605
+ ...p
4606
+ };
4607
+ return this;
4608
+ }
4391
4609
  /** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
4392
4610
  toJSON() {
4393
4611
  return this.value;
@@ -4435,12 +4653,10 @@ var TextVar = class extends ComfyVar {
4435
4653
  return true;
4436
4654
  }
4437
4655
  };
4438
- const commentLineRe = /^\s*\/\//;
4439
- const negativeLineRe = /^\s*- (.*)$/;
4440
4656
  /**
4441
4657
  * prompt text with editor comforts, all resolved at BUILD time (the editor and
4442
4658
  * drafts keep the raw text):
4443
- * - `//` lines are COMMENTS — stripped
4659
+ * - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
4444
4660
  * - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
4445
4661
  * comma-joined into `.negative`
4446
4662
  * - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
@@ -4454,38 +4670,48 @@ var PromptVar = class extends ComfyVarBase {
4454
4670
  this.kind = "prompt";
4455
4671
  this.presets = toPresetList(promptOpts.presets);
4456
4672
  }
4673
+ /** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
4457
4674
  parse(raw) {
4458
- this.set(raw);
4675
+ this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
4459
4676
  return true;
4460
4677
  }
4678
+ toEditBuffer() {
4679
+ return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
4680
+ }
4681
+ /** a var list shows the lanes by name, the inactive ones in parentheses */
4682
+ display() {
4683
+ if (!isPromptLanes(this.value)) return super.display();
4684
+ return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
4685
+ }
4686
+ /** the text the build reads: the plain string, or the active lanes joined in order */
4687
+ get text() {
4688
+ return promptText(this.value);
4689
+ }
4690
+ /** the tag list options in their one object form, null when this prompt has no completion */
4691
+ get tags() {
4692
+ const t = this.promptOpts.tags;
4693
+ if (t == null) return null;
4694
+ return typeof t === "string" ? { url: t } : t;
4695
+ }
4461
4696
  static isCommentLine(line) {
4462
- return commentLineRe.test(line);
4697
+ return COMMENT_LINE_RE.test(line);
4463
4698
  }
4464
4699
  static isNegativeLine(line) {
4465
- return negativeLineRe.test(line);
4700
+ return NEGATIVE_LINE_RE.test(line);
4466
4701
  }
4467
4702
  /** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
4468
4703
  injectedKeywords() {
4469
4704
  const src = this.promptOpts.loraKeywordsFrom;
4470
4705
  if (src == null) return [];
4471
- return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
4706
+ return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
4472
4707
  }
4473
4708
  outValue() {
4474
- const pos = [];
4475
- const neg = [];
4476
- for (const line of this.value.split("\n")) {
4477
- if (commentLineRe.test(line)) continue;
4478
- const m = negativeLineRe.exec(line);
4479
- if (m != null) {
4480
- const text = (m[1] ?? "").trim();
4481
- if (text !== "") neg.push(text);
4482
- } else pos.push(line);
4483
- }
4484
- const body = pos.join("\n").trim();
4709
+ const parsed = parsePromptText(this.text);
4710
+ const body = parsed.positive;
4485
4711
  const keywords = this.injectedKeywords();
4486
4712
  return {
4487
4713
  positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
4488
- negative: neg.join(", ")
4714
+ negative: parsed.negative
4489
4715
  };
4490
4716
  }
4491
4717
  };
@@ -4625,6 +4851,7 @@ var ChoiceVar = class extends ComfyVar {
4625
4851
  super(defaultValue, label);
4626
4852
  this.choices = choices;
4627
4853
  this.kind = "choice";
4854
+ this.select = "one";
4628
4855
  }
4629
4856
  next(delta = 1) {
4630
4857
  const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
@@ -4637,12 +4864,96 @@ var ChoiceVar = class extends ComfyVar {
4637
4864
  return true;
4638
4865
  }
4639
4866
  };
4867
+ /** one option or none: `null` is "nothing picked", clicking the lit option clears it */
4868
+ var OptionalChoiceVar = class extends ComfyVar {
4869
+ constructor(choices, defaultValue, label) {
4870
+ super(defaultValue, label);
4871
+ this.choices = choices;
4872
+ this.kind = "choice";
4873
+ this.select = "zero-or-one";
4874
+ }
4875
+ /** pick `c`, or clear it when it is already the one picked */
4876
+ toggle(c) {
4877
+ return this.set(this.value === c ? null : c);
4878
+ }
4879
+ /** the TUI text form: a choice, or an empty line for none */
4880
+ parse(raw) {
4881
+ if (raw.trim() === "") {
4882
+ this.set(null);
4883
+ return true;
4884
+ }
4885
+ const hit = this.choices.find((c) => c === raw.trim());
4886
+ if (hit == null) return false;
4887
+ this.set(hit);
4888
+ return true;
4889
+ }
4890
+ toEditBuffer() {
4891
+ return this.value ?? "";
4892
+ }
4893
+ /** a draft from when this was a many choice holds a list: its first known option */
4894
+ loadJSON(value) {
4895
+ const one = Array.isArray(value) ? value[0] : value;
4896
+ return this.set(this.choices.find((c) => c === one) ?? null);
4897
+ }
4898
+ display() {
4899
+ return this.value ?? "none";
4900
+ }
4901
+ };
4902
+ /** any number of options, kept in the order the choices list them */
4903
+ var MultiChoiceVar = class extends ComfyVar {
4904
+ constructor(choices, defaultValue, label) {
4905
+ super([...defaultValue], label);
4906
+ this.choices = choices;
4907
+ this.kind = "choice";
4908
+ this.select = "many";
4909
+ }
4910
+ toggle(c) {
4911
+ const on = this.value.includes(c);
4912
+ return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
4913
+ }
4914
+ /** the TUI text form: `a, b` */
4915
+ parse(raw) {
4916
+ const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
4917
+ const picked = this.choices.filter((c) => wanted.includes(c));
4918
+ if (picked.length !== new Set(wanted).size) return false;
4919
+ this.set(picked);
4920
+ return true;
4921
+ }
4922
+ toEditBuffer() {
4923
+ return this.value.join(", ");
4924
+ }
4925
+ /** a draft from when this was a single choice holds one value: a list of one. Unknown
4926
+ * options are dropped, the list comes back in the choices order */
4927
+ loadJSON(value) {
4928
+ const listed = Array.isArray(value) ? value : value == null ? [] : [value];
4929
+ return this.set(this.choices.filter((c) => listed.includes(c)));
4930
+ }
4931
+ display() {
4932
+ return this.value.length === 0 ? "none" : this.value.join(", ");
4933
+ }
4934
+ };
4935
+ /** Array.isArray does not narrow a READONLY array out of a union, this does */
4936
+ function isChoiceList(v) {
4937
+ return Array.isArray(v);
4938
+ }
4939
+ function choice(choices, defaultValue, opts) {
4940
+ const o = typeof opts === "string" ? { label: opts } : opts ?? {};
4941
+ const select = o.select ?? "one";
4942
+ if (select === "many") {
4943
+ if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
4944
+ return new MultiChoiceVar(choices, defaultValue, o.label);
4945
+ }
4946
+ if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
4947
+ if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
4948
+ if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
4949
+ return new ChoiceVar(choices, defaultValue, o.label);
4950
+ }
4640
4951
  /** normalize a loras record into what a standard LoraLoader chain consumes */
4641
4952
  function activeLoras(loras) {
4642
4953
  const out = [];
4643
- for (const [lora_name, s] of Object.entries(loras)) {
4644
- if (s == null || s === false) continue;
4645
- const [strength_model, strength_clip] = Array.isArray(s) ? s : s === true ? [1, 1] : [s, s];
4954
+ for (const [lora_name, s] of Object.entries(flattenLoras(loras).record)) {
4955
+ if (!loraIsOn(s)) continue;
4956
+ const [strength_model, strength_clip] = loraStrengths(s);
4646
4957
  out.push({
4647
4958
  lora_name,
4648
4959
  strength_model,
@@ -4657,7 +4968,12 @@ function activeLoras(loras) {
4657
4968
  * or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
4658
4969
  * a hardcoded inventory. Selection is empty by default.
4659
4970
  */
4660
- var LorasVar = class LorasVar extends ComfyVar {
4971
+ /**
4972
+ * the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
4973
+ * build merges in listed order, skipping inactive ones. Every method reads the merged record and
4974
+ * writes into the lane that holds the lora, so the TUI never needs to know lanes exist
4975
+ */
4976
+ var LorasVar = class LorasVar extends ComfyVarBase {
4661
4977
  constructor(optionsSource, initial = {}, label) {
4662
4978
  super(initial, label);
4663
4979
  this.optionsSource = optionsSource;
@@ -4688,49 +5004,57 @@ var LorasVar = class LorasVar extends ComfyVar {
4688
5004
  get names() {
4689
5005
  return [...this.options];
4690
5006
  }
5007
+ /** the loras the build reads: the plain record, or the active lanes merged in order */
5008
+ get record() {
5009
+ return flattenLoras(this.value).record;
5010
+ }
5011
+ /** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
5012
+ outValue() {
5013
+ const flat = flattenLoras(this.value);
5014
+ if (flat.duplicates.length > 0) logError(`loras var '${this.name ?? this.label ?? "?"}': ${flat.duplicates.join(", ")} sit in two active lanes, the first lane's setting is used`);
5015
+ return flat.record;
5016
+ }
5017
+ /** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
5018
+ write(name, next) {
5019
+ return this.set(updateLora(this.value, name, next));
5020
+ }
5021
+ /** the parts of this lora's prompt keyword left out of the prompt */
5022
+ mutedWords(name) {
5023
+ return loraMuted(this.record[name]);
5024
+ }
4691
5025
  /** loras currently ON (PromptVar keyword prefixing consumes this) */
4692
5026
  activeNames() {
4693
5027
  return this.names.filter((n) => this.isOn(n));
4694
5028
  }
4695
5029
  isOn(name) {
4696
- const s = this.value[name];
4697
- return s != null && s !== false;
5030
+ return loraIsOn(this.record[name]);
4698
5031
  }
4699
5032
  toggleItem(name) {
4700
- const cur = this.value[name];
4701
- if (cur == null || cur === false) return this.set({
4702
- ...this.value,
4703
- [name]: this.prev[name] ?? true
4704
- });
5033
+ const cur = this.record[name];
5034
+ if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
5035
+ if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
4705
5036
  this.prev[name] = cur;
4706
- return this.set({
4707
- ...this.value,
4708
- [name]: false
4709
- });
5037
+ return this.write(name, false);
4710
5038
  }
4711
5039
  /** step both strengths by delta (true becomes 1 first); no-op when off */
4712
5040
  adjustItem(name, delta) {
4713
- const cur = this.value[name];
4714
- if (cur == null || cur === false) return this;
5041
+ const cur = this.record[name];
5042
+ if (!loraIsOn(cur)) return this;
4715
5043
  const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
4716
- const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : step(cur === true ? 1 : cur);
4717
- return this.set({
4718
- ...this.value,
4719
- [name]: next
4720
- });
5044
+ const next = typeof cur === "number" || cur === true ? step(cur === true ? 1 : cur) : Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : withLora(cur, { strength: [step(loraStrengths(cur)[0]), step(loraStrengths(cur)[1])] });
5045
+ return this.write(name, next);
4721
5046
  }
4722
5047
  /** compact per-item strength label for lists */
4723
5048
  strengthLabel(name) {
4724
- const s = this.value[name];
4725
- if (s == null || s === false) return "";
4726
- if (s === true) return "1.00";
4727
- if (Array.isArray(s)) return `m:${s[0].toFixed(2)} c:${s[1].toFixed(2)}`;
4728
- return s.toFixed(2);
5049
+ const s = this.record[name];
5050
+ if (!loraIsOn(s)) return "";
5051
+ const [m, c] = loraStrengths(s);
5052
+ return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
4729
5053
  }
4730
5054
  parse(raw) {
4731
5055
  try {
4732
5056
  const parsed = JSON.parse(raw);
4733
- if (typeof parsed !== "object" || parsed == null || Array.isArray(parsed)) return false;
5057
+ if (!isLorasInput(parsed)) return false;
4734
5058
  this.set(parsed);
4735
5059
  return true;
4736
5060
  } catch {
@@ -4743,14 +5067,16 @@ var LorasVar = class LorasVar extends ComfyVar {
4743
5067
  }
4744
5068
  /** tick (true) or untick (false) every lora in `names` (default: all options) */
4745
5069
  setAll(on, names = this.options) {
4746
- const next = { ...this.value };
5070
+ const record = this.record;
5071
+ let next = this.value;
4747
5072
  for (const name of names) {
4748
- const cur = next[name];
5073
+ const cur = record[name];
4749
5074
  if (on) {
4750
- if (cur == null || cur === false) next[name] = this.prev[name] ?? true;
5075
+ if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
5076
+ else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
4751
5077
  } else {
4752
- if (cur != null && cur !== false) this.prev[name] = cur;
4753
- next[name] = false;
5078
+ if (loraIsOn(cur)) this.prev[name] = cur;
5079
+ next = updateLora(next, name, false);
4754
5080
  }
4755
5081
  }
4756
5082
  return this.set(next);
@@ -4799,6 +5125,56 @@ const DEFAULT_SIZE_PRESETS = [
4799
5125
  height: 1344
4800
5126
  }
4801
5127
  ];
5128
+ /** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
5129
+ const SD15_SIZE_PRESETS = [
5130
+ {
5131
+ label: "1:1 square",
5132
+ width: 512,
5133
+ height: 512
5134
+ },
5135
+ {
5136
+ label: "4:3 landscape",
5137
+ width: 576,
5138
+ height: 448
5139
+ },
5140
+ {
5141
+ label: "3:4 portrait",
5142
+ width: 448,
5143
+ height: 576
5144
+ },
5145
+ {
5146
+ label: "3:2 landscape",
5147
+ width: 576,
5148
+ height: 384
5149
+ },
5150
+ {
5151
+ label: "2:3 portrait",
5152
+ width: 384,
5153
+ height: 576
5154
+ },
5155
+ {
5156
+ label: "16:9 widescreen",
5157
+ width: 704,
5158
+ height: 384
5159
+ },
5160
+ {
5161
+ label: "9:16 tall",
5162
+ width: 384,
5163
+ height: 704
5164
+ }
5165
+ ];
5166
+ /** starred presets are one click away in the panel, before the full list */
5167
+ const DEFAULT_STARRED_SIZES = [
5168
+ "1:1 square",
5169
+ "3:4 portrait",
5170
+ "4:3 landscape"
5171
+ ];
5172
+ /** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
5173
+ * and offering it 1024 buckets would be offering sizes it was never trained at */
5174
+ function sizePresetsFor(defaultValue) {
5175
+ if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
5176
+ return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
5177
+ }
4802
5178
  /** width/height picker: presets + free `WxH` entry + optionally the LIVE
4803
5179
  * size of a linked image var (the widget shows
4804
5180
  * `WxH size of image '<name>'` as a pickable row) */
@@ -4806,10 +5182,11 @@ var SizeVar = class extends ComfyVar {
4806
5182
  constructor(defaultValue = {
4807
5183
  width: 1024,
4808
5184
  height: 1024
4809
- }, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
5185
+ }, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
4810
5186
  super(defaultValue, label);
4811
5187
  this.presets = presets;
4812
5188
  this.imageVar = imageVar;
5189
+ this.starred = starred;
4813
5190
  this.kind = "size";
4814
5191
  }
4815
5192
  /** current dimensions of the linked image var — null when no link, unset
@@ -4934,9 +5311,11 @@ const v = {
4934
5311
  * which is what a tuning session wants, and reset()/revert come back to it */
4935
5312
  seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
4936
5313
  toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
4937
- choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
5314
+ /** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
5315
+ * `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
5316
+ choice,
4938
5317
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
4939
- size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
5318
+ size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
4940
5319
  image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
4941
5320
  };
4942
5321
  function varValues(vars) {
@@ -4965,6 +5344,29 @@ var DefinedWorkflow = class {
4965
5344
  varDef.name = key;
4966
5345
  varDef.bindHost?.(this.host);
4967
5346
  }
5347
+ const names = this.entries().map(([key]) => key);
5348
+ for (const [key, varDef] of this.entries()) for (const other of Object.keys(varDef.uiOpts.activeWhen ?? {})) if (!names.includes(other)) throw new Error(`workflow '${spec.id ?? "?"}': var '${key}' is activeWhen '${other}', which is not one of its vars (${names.join(", ")})`);
5349
+ }
5350
+ /** every preview for the current var values. A preview that throws, or vars that cannot be
5351
+ * read yet (an image var still empty), give a line saying so instead of failing the others */
5352
+ computePreviews() {
5353
+ const previews = this.spec.previews ?? {};
5354
+ const names = Object.keys(previews);
5355
+ if (names.length === 0) return {};
5356
+ let values;
5357
+ try {
5358
+ values = varValues(this.vars);
5359
+ } catch (e) {
5360
+ const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
5361
+ return Object.fromEntries(names.map((n) => [n, why]));
5362
+ }
5363
+ const out = {};
5364
+ for (const [name, fn] of Object.entries(previews)) try {
5365
+ out[name] = fn(values);
5366
+ } catch (e) {
5367
+ out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
5368
+ }
5369
+ return out;
4968
5370
  }
4969
5371
  /** [name, var] pairs, for drivers that enumerate the knobs */
4970
5372
  entries() {
@@ -6270,6 +6672,10 @@ var ComfyTS = class ComfyTS {
6270
6672
  resolveFromPromptEnhancers(relativePath) {
6271
6673
  return asAbsolutePath(join(this.baseFolder, "prompt-enhancers", relativePath));
6272
6674
  }
6675
+ /** the serve web ui's LLM configs (prompt enhancer), one json per config */
6676
+ resolveFromLlmConfigs(relativePath) {
6677
+ return asAbsolutePath(join(this.baseFolder, "llm-configs", relativePath));
6678
+ }
6273
6679
  resolveFromCache(relativePath) {
6274
6680
  return asAbsolutePath(join(this.baseFolder, "cache", relativePath));
6275
6681
  }
@@ -6411,6 +6817,6 @@ function isTuiActive() {
6411
6817
  */
6412
6818
  setDefaultComfyStorage(createNodeStorage());
6413
6819
  //#endregion
6414
- 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, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, isTuiActive, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, promptEnhancerPresets, readPromptEnhancers, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, toPresetList, v };
6820
+ export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, MultiChoiceVar, OptionalChoiceVar, PromptVar, ResilientWebSocketClient, SD15_SIZE_PRESETS, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, isTuiActive, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, promptEnhancerPresets, readPromptEnhancers, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
6415
6821
 
6416
6822
  //# sourceMappingURL=index.js.map