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.cjs CHANGED
@@ -134,7 +134,7 @@ function createNodeStorage() {
134
134
  }
135
135
  //#endregion
136
136
  //#region package.json
137
- var version = "2.11.0";
137
+ var version = "2.12.0";
138
138
  //#endregion
139
139
  //#region src/litegraph/LiteGraphLinkID.ts
140
140
  const asLiteGraphLinkID = (id) => id;
@@ -4377,6 +4377,221 @@ function writeKeywords() {
4377
4377
  }
4378
4378
  }
4379
4379
  //#endregion
4380
+ //#region src/vars/loraEntry.ts
4381
+ function isLoraEntry(s) {
4382
+ if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
4383
+ const o = s;
4384
+ const st = o.strength;
4385
+ 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"));
4386
+ }
4387
+ function isLoraStrength(s) {
4388
+ if (typeof s === "boolean") return true;
4389
+ if (typeof s === "number") return Number.isFinite(s);
4390
+ if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
4391
+ return isLoraEntry(s);
4392
+ }
4393
+ /** on = it runs */
4394
+ function loraIsOn(s) {
4395
+ if (s == null || s === false) return false;
4396
+ if (isLoraEntry(s)) return s.off !== true;
4397
+ return true;
4398
+ }
4399
+ /** the strengths, whatever the spelling (1/1 when there is nothing to read) */
4400
+ function loraStrengths(s) {
4401
+ if (typeof s === "number" && Number.isFinite(s)) return [s, s];
4402
+ if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
4403
+ if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
4404
+ return [1, 1];
4405
+ }
4406
+ function loraMuted(s) {
4407
+ return isLoraEntry(s) && s.mute != null ? s.mute : [];
4408
+ }
4409
+ /** a prompt keyword's parts, split at commas: each one can be left out on its own */
4410
+ function keywordParts(keyword) {
4411
+ return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
4412
+ }
4413
+ /** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
4414
+ function keptKeyword(keyword, muted) {
4415
+ return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
4416
+ }
4417
+ /** rewrite one setting, keeping what the patch does not name. The result stays in the short
4418
+ * spellings while nothing needs the palette form, so a plain draft reads as it always did */
4419
+ function withLora(s, patch) {
4420
+ const strength = patch.strength ?? loraStrengths(s);
4421
+ const off = patch.on == null ? !loraIsOn(s) : !patch.on;
4422
+ const mute = [...patch.mute ?? loraMuted(s)];
4423
+ if (!off && mute.length === 0) return [strength[0], strength[1]];
4424
+ return {
4425
+ strength: [strength[0], strength[1]],
4426
+ ...off ? { off: true } : {},
4427
+ ...mute.length === 0 ? {} : { mute }
4428
+ };
4429
+ }
4430
+ //#endregion
4431
+ //#region src/vars/lanes.ts
4432
+ const FIRST_LANE = "main";
4433
+ function isObject(v) {
4434
+ return typeof v === "object" && v != null && !Array.isArray(v);
4435
+ }
4436
+ function isPromptLane(v) {
4437
+ return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
4438
+ }
4439
+ function isPromptLanes(v) {
4440
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
4441
+ }
4442
+ /** the text the build reads: the active lanes joined in order, one line break between them, so
4443
+ * `//` and `- ` lines keep working inside every lane */
4444
+ function promptText(v) {
4445
+ if (typeof v === "string") return v;
4446
+ return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
4447
+ }
4448
+ const HEADER = /^# (.+?)( \(off\))?$/;
4449
+ function promptLanesToText(v) {
4450
+ return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
4451
+ }
4452
+ /** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
4453
+ function promptLanesFromText(text) {
4454
+ const lanes = [];
4455
+ let current = null;
4456
+ const body = [];
4457
+ const close = () => {
4458
+ if (current != null) lanes.push({
4459
+ ...current,
4460
+ prompt: body.join("\n")
4461
+ });
4462
+ else if (body.some((l) => l.trim() !== "")) lanes.push({
4463
+ name: FIRST_LANE,
4464
+ prompt: body.join("\n"),
4465
+ active: true
4466
+ });
4467
+ body.length = 0;
4468
+ };
4469
+ for (const line of text.split("\n")) {
4470
+ const m = HEADER.exec(line);
4471
+ if (m == null) {
4472
+ body.push(line);
4473
+ continue;
4474
+ }
4475
+ close();
4476
+ current = {
4477
+ name: (m[1] ?? "").trim(),
4478
+ prompt: "",
4479
+ active: m[2] == null
4480
+ };
4481
+ }
4482
+ close();
4483
+ return { lanes: lanes.length > 0 ? lanes : [{
4484
+ name: FIRST_LANE,
4485
+ prompt: "",
4486
+ active: true
4487
+ }] };
4488
+ }
4489
+ function isLoraRecord(v) {
4490
+ return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
4491
+ }
4492
+ function isLoraLane(v) {
4493
+ return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
4494
+ }
4495
+ function isLoraLanes(v) {
4496
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
4497
+ }
4498
+ function isLorasInput(v) {
4499
+ return isLoraRecord(v) || isLoraLanes(v);
4500
+ }
4501
+ /** one record for the build: the active lanes in order. A lora in two active lanes keeps its
4502
+ * FIRST setting, and `duplicates` names it so the caller can say so */
4503
+ function flattenLoras(v) {
4504
+ if (!isLoraLanes(v)) return {
4505
+ record: v,
4506
+ duplicates: []
4507
+ };
4508
+ const record = {};
4509
+ const duplicates = [];
4510
+ for (const lane of v.lanes) {
4511
+ if (!lane.active) continue;
4512
+ for (const [name, st] of Object.entries(lane.loras)) {
4513
+ if (st == null) continue;
4514
+ if (name in record) duplicates.push(name);
4515
+ else record[name] = st;
4516
+ }
4517
+ }
4518
+ return {
4519
+ record,
4520
+ duplicates
4521
+ };
4522
+ }
4523
+ /** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
4524
+ * has it (the one the build reads), else any lane, else -1 */
4525
+ function laneIndexOf(v, name) {
4526
+ const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
4527
+ return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
4528
+ }
4529
+ /** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
4530
+ * A lora in no lane yet lands in the first lane */
4531
+ function updateLora(v, name, next) {
4532
+ const write = (rec) => {
4533
+ const out = { ...rec };
4534
+ if (next == null) delete out[name];
4535
+ else out[name] = next;
4536
+ return out;
4537
+ };
4538
+ if (!isLoraLanes(v)) return write(v);
4539
+ if (v.lanes.length === 0) return { lanes: [{
4540
+ name: FIRST_LANE,
4541
+ active: true,
4542
+ loras: write({})
4543
+ }] };
4544
+ const found = laneIndexOf(v, name);
4545
+ const ix = found === -1 ? 0 : found;
4546
+ return { lanes: v.lanes.map((l, i) => i === ix ? {
4547
+ ...l,
4548
+ loras: write(l.loras)
4549
+ } : l) };
4550
+ }
4551
+ //#endregion
4552
+ //#region src/vars/promptSyntax.ts
4553
+ /** a whole line that is a comment (the TUI colors these) */
4554
+ const COMMENT_LINE_RE = /^\s*\/\//;
4555
+ /** a negative prompt line: `- ` then its text */
4556
+ const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
4557
+ const NEGATIVE_PREFIX_RE = /^(\s*)- /;
4558
+ /** where a `//` comment starts on this line, -1 when none. Only at line start or after
4559
+ * whitespace, so `http://host` is never cut */
4560
+ function commentStart(line) {
4561
+ const m = /(?:^|\s)\/\//.exec(line);
4562
+ if (m == null) return -1;
4563
+ return m.index + m[0].length - 2;
4564
+ }
4565
+ /** the line without its comment, trailing whitespace dropped with it */
4566
+ function withoutComment(line) {
4567
+ const c = commentStart(line);
4568
+ return c < 0 ? {
4569
+ text: line,
4570
+ hadComment: false
4571
+ } : {
4572
+ text: line.slice(0, c).trimEnd(),
4573
+ hadComment: true
4574
+ };
4575
+ }
4576
+ /** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
4577
+ function parsePromptText(text) {
4578
+ const pos = [];
4579
+ const neg = [];
4580
+ for (const raw of text.split("\n")) {
4581
+ const cut = withoutComment(raw);
4582
+ if (cut.hadComment && cut.text.trim() === "") continue;
4583
+ const m = NEGATIVE_PREFIX_RE.exec(raw);
4584
+ if (m != null && m[0].length <= cut.text.length + 1) {
4585
+ const body = cut.text.slice(m[0].length).trim();
4586
+ if (body !== "") neg.push(body);
4587
+ } else pos.push(cut.text);
4588
+ }
4589
+ return {
4590
+ positive: pos.join("\n").trim(),
4591
+ negative: neg.join(", ")
4592
+ };
4593
+ }
4594
+ //#endregion
4380
4595
  //#region src/vars/presets.ts
4381
4596
  function toPresetList(spec) {
4382
4597
  if (spec == null) return [];
@@ -4392,16 +4607,11 @@ function activePresetLabel(presets, value) {
4392
4607
  }
4393
4608
  //#endregion
4394
4609
  //#region src/vars/ComfyVars.ts
4395
- /**
4396
- * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
4397
- * time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
4398
- * the one Out-specialized var (string in, PromptValue out); the split keeps
4399
- * outValue() cast-free.
4400
- */
4401
4610
  var ComfyVarBase = class {
4402
4611
  constructor(defaultValue, label) {
4403
4612
  this.defaultValue = defaultValue;
4404
4613
  this.label = label;
4614
+ this.uiOpts = {};
4405
4615
  this.value = defaultValue;
4406
4616
  (0, mobx.makeObservable)(this, {
4407
4617
  value: mobx.observable,
@@ -4415,6 +4625,14 @@ var ComfyVarBase = class {
4415
4625
  this.value = value;
4416
4626
  return this;
4417
4627
  }
4628
+ /** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
4629
+ ui(p) {
4630
+ this.uiOpts = {
4631
+ ...this.uiOpts,
4632
+ ...p
4633
+ };
4634
+ return this;
4635
+ }
4418
4636
  /** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
4419
4637
  toJSON() {
4420
4638
  return this.value;
@@ -4462,12 +4680,10 @@ var TextVar = class extends ComfyVar {
4462
4680
  return true;
4463
4681
  }
4464
4682
  };
4465
- const commentLineRe = /^\s*\/\//;
4466
- const negativeLineRe = /^\s*- (.*)$/;
4467
4683
  /**
4468
4684
  * prompt text with editor comforts, all resolved at BUILD time (the editor and
4469
4685
  * drafts keep the raw text):
4470
- * - `//` lines are COMMENTS — stripped
4686
+ * - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
4471
4687
  * - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
4472
4688
  * comma-joined into `.negative`
4473
4689
  * - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
@@ -4481,38 +4697,48 @@ var PromptVar = class extends ComfyVarBase {
4481
4697
  this.kind = "prompt";
4482
4698
  this.presets = toPresetList(promptOpts.presets);
4483
4699
  }
4700
+ /** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
4484
4701
  parse(raw) {
4485
- this.set(raw);
4702
+ this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
4486
4703
  return true;
4487
4704
  }
4705
+ toEditBuffer() {
4706
+ return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
4707
+ }
4708
+ /** a var list shows the lanes by name, the inactive ones in parentheses */
4709
+ display() {
4710
+ if (!isPromptLanes(this.value)) return super.display();
4711
+ return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
4712
+ }
4713
+ /** the text the build reads: the plain string, or the active lanes joined in order */
4714
+ get text() {
4715
+ return promptText(this.value);
4716
+ }
4717
+ /** the tag list options in their one object form, null when this prompt has no completion */
4718
+ get tags() {
4719
+ const t = this.promptOpts.tags;
4720
+ if (t == null) return null;
4721
+ return typeof t === "string" ? { url: t } : t;
4722
+ }
4488
4723
  static isCommentLine(line) {
4489
- return commentLineRe.test(line);
4724
+ return COMMENT_LINE_RE.test(line);
4490
4725
  }
4491
4726
  static isNegativeLine(line) {
4492
- return negativeLineRe.test(line);
4727
+ return NEGATIVE_LINE_RE.test(line);
4493
4728
  }
4494
4729
  /** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
4495
4730
  injectedKeywords() {
4496
4731
  const src = this.promptOpts.loraKeywordsFrom;
4497
4732
  if (src == null) return [];
4498
- return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
4733
+ return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
4499
4734
  }
4500
4735
  outValue() {
4501
- const pos = [];
4502
- const neg = [];
4503
- for (const line of this.value.split("\n")) {
4504
- if (commentLineRe.test(line)) continue;
4505
- const m = negativeLineRe.exec(line);
4506
- if (m != null) {
4507
- const text = (m[1] ?? "").trim();
4508
- if (text !== "") neg.push(text);
4509
- } else pos.push(line);
4510
- }
4511
- const body = pos.join("\n").trim();
4736
+ const parsed = parsePromptText(this.text);
4737
+ const body = parsed.positive;
4512
4738
  const keywords = this.injectedKeywords();
4513
4739
  return {
4514
4740
  positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
4515
- negative: neg.join(", ")
4741
+ negative: parsed.negative
4516
4742
  };
4517
4743
  }
4518
4744
  };
@@ -4652,6 +4878,7 @@ var ChoiceVar = class extends ComfyVar {
4652
4878
  super(defaultValue, label);
4653
4879
  this.choices = choices;
4654
4880
  this.kind = "choice";
4881
+ this.select = "one";
4655
4882
  }
4656
4883
  next(delta = 1) {
4657
4884
  const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
@@ -4664,12 +4891,96 @@ var ChoiceVar = class extends ComfyVar {
4664
4891
  return true;
4665
4892
  }
4666
4893
  };
4894
+ /** one option or none: `null` is "nothing picked", clicking the lit option clears it */
4895
+ var OptionalChoiceVar = class extends ComfyVar {
4896
+ constructor(choices, defaultValue, label) {
4897
+ super(defaultValue, label);
4898
+ this.choices = choices;
4899
+ this.kind = "choice";
4900
+ this.select = "zero-or-one";
4901
+ }
4902
+ /** pick `c`, or clear it when it is already the one picked */
4903
+ toggle(c) {
4904
+ return this.set(this.value === c ? null : c);
4905
+ }
4906
+ /** the TUI text form: a choice, or an empty line for none */
4907
+ parse(raw) {
4908
+ if (raw.trim() === "") {
4909
+ this.set(null);
4910
+ return true;
4911
+ }
4912
+ const hit = this.choices.find((c) => c === raw.trim());
4913
+ if (hit == null) return false;
4914
+ this.set(hit);
4915
+ return true;
4916
+ }
4917
+ toEditBuffer() {
4918
+ return this.value ?? "";
4919
+ }
4920
+ /** a draft from when this was a many choice holds a list: its first known option */
4921
+ loadJSON(value) {
4922
+ const one = Array.isArray(value) ? value[0] : value;
4923
+ return this.set(this.choices.find((c) => c === one) ?? null);
4924
+ }
4925
+ display() {
4926
+ return this.value ?? "none";
4927
+ }
4928
+ };
4929
+ /** any number of options, kept in the order the choices list them */
4930
+ var MultiChoiceVar = class extends ComfyVar {
4931
+ constructor(choices, defaultValue, label) {
4932
+ super([...defaultValue], label);
4933
+ this.choices = choices;
4934
+ this.kind = "choice";
4935
+ this.select = "many";
4936
+ }
4937
+ toggle(c) {
4938
+ const on = this.value.includes(c);
4939
+ return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
4940
+ }
4941
+ /** the TUI text form: `a, b` */
4942
+ parse(raw) {
4943
+ const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
4944
+ const picked = this.choices.filter((c) => wanted.includes(c));
4945
+ if (picked.length !== new Set(wanted).size) return false;
4946
+ this.set(picked);
4947
+ return true;
4948
+ }
4949
+ toEditBuffer() {
4950
+ return this.value.join(", ");
4951
+ }
4952
+ /** a draft from when this was a single choice holds one value: a list of one. Unknown
4953
+ * options are dropped, the list comes back in the choices order */
4954
+ loadJSON(value) {
4955
+ const listed = Array.isArray(value) ? value : value == null ? [] : [value];
4956
+ return this.set(this.choices.filter((c) => listed.includes(c)));
4957
+ }
4958
+ display() {
4959
+ return this.value.length === 0 ? "none" : this.value.join(", ");
4960
+ }
4961
+ };
4962
+ /** Array.isArray does not narrow a READONLY array out of a union, this does */
4963
+ function isChoiceList(v) {
4964
+ return Array.isArray(v);
4965
+ }
4966
+ function choice(choices, defaultValue, opts) {
4967
+ const o = typeof opts === "string" ? { label: opts } : opts ?? {};
4968
+ const select = o.select ?? "one";
4969
+ if (select === "many") {
4970
+ if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
4971
+ return new MultiChoiceVar(choices, defaultValue, o.label);
4972
+ }
4973
+ if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
4974
+ if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
4975
+ if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
4976
+ return new ChoiceVar(choices, defaultValue, o.label);
4977
+ }
4667
4978
  /** normalize a loras record into what a standard LoraLoader chain consumes */
4668
4979
  function activeLoras(loras) {
4669
4980
  const out = [];
4670
- for (const [lora_name, s] of Object.entries(loras)) {
4671
- if (s == null || s === false) continue;
4672
- const [strength_model, strength_clip] = Array.isArray(s) ? s : s === true ? [1, 1] : [s, s];
4981
+ for (const [lora_name, s] of Object.entries(flattenLoras(loras).record)) {
4982
+ if (!loraIsOn(s)) continue;
4983
+ const [strength_model, strength_clip] = loraStrengths(s);
4673
4984
  out.push({
4674
4985
  lora_name,
4675
4986
  strength_model,
@@ -4684,7 +4995,12 @@ function activeLoras(loras) {
4684
4995
  * or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
4685
4996
  * a hardcoded inventory. Selection is empty by default.
4686
4997
  */
4687
- var LorasVar = class LorasVar extends ComfyVar {
4998
+ /**
4999
+ * the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
5000
+ * build merges in listed order, skipping inactive ones. Every method reads the merged record and
5001
+ * writes into the lane that holds the lora, so the TUI never needs to know lanes exist
5002
+ */
5003
+ var LorasVar = class LorasVar extends ComfyVarBase {
4688
5004
  constructor(optionsSource, initial = {}, label) {
4689
5005
  super(initial, label);
4690
5006
  this.optionsSource = optionsSource;
@@ -4715,49 +5031,57 @@ var LorasVar = class LorasVar extends ComfyVar {
4715
5031
  get names() {
4716
5032
  return [...this.options];
4717
5033
  }
5034
+ /** the loras the build reads: the plain record, or the active lanes merged in order */
5035
+ get record() {
5036
+ return flattenLoras(this.value).record;
5037
+ }
5038
+ /** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
5039
+ outValue() {
5040
+ const flat = flattenLoras(this.value);
5041
+ 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`);
5042
+ return flat.record;
5043
+ }
5044
+ /** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
5045
+ write(name, next) {
5046
+ return this.set(updateLora(this.value, name, next));
5047
+ }
5048
+ /** the parts of this lora's prompt keyword left out of the prompt */
5049
+ mutedWords(name) {
5050
+ return loraMuted(this.record[name]);
5051
+ }
4718
5052
  /** loras currently ON (PromptVar keyword prefixing consumes this) */
4719
5053
  activeNames() {
4720
5054
  return this.names.filter((n) => this.isOn(n));
4721
5055
  }
4722
5056
  isOn(name) {
4723
- const s = this.value[name];
4724
- return s != null && s !== false;
5057
+ return loraIsOn(this.record[name]);
4725
5058
  }
4726
5059
  toggleItem(name) {
4727
- const cur = this.value[name];
4728
- if (cur == null || cur === false) return this.set({
4729
- ...this.value,
4730
- [name]: this.prev[name] ?? true
4731
- });
5060
+ const cur = this.record[name];
5061
+ if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
5062
+ if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
4732
5063
  this.prev[name] = cur;
4733
- return this.set({
4734
- ...this.value,
4735
- [name]: false
4736
- });
5064
+ return this.write(name, false);
4737
5065
  }
4738
5066
  /** step both strengths by delta (true becomes 1 first); no-op when off */
4739
5067
  adjustItem(name, delta) {
4740
- const cur = this.value[name];
4741
- if (cur == null || cur === false) return this;
5068
+ const cur = this.record[name];
5069
+ if (!loraIsOn(cur)) return this;
4742
5070
  const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
4743
- const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : step(cur === true ? 1 : cur);
4744
- return this.set({
4745
- ...this.value,
4746
- [name]: next
4747
- });
5071
+ 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])] });
5072
+ return this.write(name, next);
4748
5073
  }
4749
5074
  /** compact per-item strength label for lists */
4750
5075
  strengthLabel(name) {
4751
- const s = this.value[name];
4752
- if (s == null || s === false) return "";
4753
- if (s === true) return "1.00";
4754
- if (Array.isArray(s)) return `m:${s[0].toFixed(2)} c:${s[1].toFixed(2)}`;
4755
- return s.toFixed(2);
5076
+ const s = this.record[name];
5077
+ if (!loraIsOn(s)) return "";
5078
+ const [m, c] = loraStrengths(s);
5079
+ return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
4756
5080
  }
4757
5081
  parse(raw) {
4758
5082
  try {
4759
5083
  const parsed = JSON.parse(raw);
4760
- if (typeof parsed !== "object" || parsed == null || Array.isArray(parsed)) return false;
5084
+ if (!isLorasInput(parsed)) return false;
4761
5085
  this.set(parsed);
4762
5086
  return true;
4763
5087
  } catch {
@@ -4770,14 +5094,16 @@ var LorasVar = class LorasVar extends ComfyVar {
4770
5094
  }
4771
5095
  /** tick (true) or untick (false) every lora in `names` (default: all options) */
4772
5096
  setAll(on, names = this.options) {
4773
- const next = { ...this.value };
5097
+ const record = this.record;
5098
+ let next = this.value;
4774
5099
  for (const name of names) {
4775
- const cur = next[name];
5100
+ const cur = record[name];
4776
5101
  if (on) {
4777
- if (cur == null || cur === false) next[name] = this.prev[name] ?? true;
5102
+ if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
5103
+ else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
4778
5104
  } else {
4779
- if (cur != null && cur !== false) this.prev[name] = cur;
4780
- next[name] = false;
5105
+ if (loraIsOn(cur)) this.prev[name] = cur;
5106
+ next = updateLora(next, name, false);
4781
5107
  }
4782
5108
  }
4783
5109
  return this.set(next);
@@ -4826,6 +5152,56 @@ const DEFAULT_SIZE_PRESETS = [
4826
5152
  height: 1344
4827
5153
  }
4828
5154
  ];
5155
+ /** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
5156
+ const SD15_SIZE_PRESETS = [
5157
+ {
5158
+ label: "1:1 square",
5159
+ width: 512,
5160
+ height: 512
5161
+ },
5162
+ {
5163
+ label: "4:3 landscape",
5164
+ width: 576,
5165
+ height: 448
5166
+ },
5167
+ {
5168
+ label: "3:4 portrait",
5169
+ width: 448,
5170
+ height: 576
5171
+ },
5172
+ {
5173
+ label: "3:2 landscape",
5174
+ width: 576,
5175
+ height: 384
5176
+ },
5177
+ {
5178
+ label: "2:3 portrait",
5179
+ width: 384,
5180
+ height: 576
5181
+ },
5182
+ {
5183
+ label: "16:9 widescreen",
5184
+ width: 704,
5185
+ height: 384
5186
+ },
5187
+ {
5188
+ label: "9:16 tall",
5189
+ width: 384,
5190
+ height: 704
5191
+ }
5192
+ ];
5193
+ /** starred presets are one click away in the panel, before the full list */
5194
+ const DEFAULT_STARRED_SIZES = [
5195
+ "1:1 square",
5196
+ "3:4 portrait",
5197
+ "4:3 landscape"
5198
+ ];
5199
+ /** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
5200
+ * and offering it 1024 buckets would be offering sizes it was never trained at */
5201
+ function sizePresetsFor(defaultValue) {
5202
+ if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
5203
+ return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
5204
+ }
4829
5205
  /** width/height picker: presets + free `WxH` entry + optionally the LIVE
4830
5206
  * size of a linked image var (the widget shows
4831
5207
  * `WxH size of image '<name>'` as a pickable row) */
@@ -4833,10 +5209,11 @@ var SizeVar = class extends ComfyVar {
4833
5209
  constructor(defaultValue = {
4834
5210
  width: 1024,
4835
5211
  height: 1024
4836
- }, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
5212
+ }, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
4837
5213
  super(defaultValue, label);
4838
5214
  this.presets = presets;
4839
5215
  this.imageVar = imageVar;
5216
+ this.starred = starred;
4840
5217
  this.kind = "size";
4841
5218
  }
4842
5219
  /** current dimensions of the linked image var — null when no link, unset
@@ -4961,9 +5338,11 @@ const v = {
4961
5338
  * which is what a tuning session wants, and reset()/revert come back to it */
4962
5339
  seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
4963
5340
  toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
4964
- choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
5341
+ /** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
5342
+ * `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
5343
+ choice,
4965
5344
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
4966
- size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
5345
+ size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
4967
5346
  image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
4968
5347
  };
4969
5348
  function varValues(vars) {
@@ -4992,6 +5371,29 @@ var DefinedWorkflow = class {
4992
5371
  varDef.name = key;
4993
5372
  varDef.bindHost?.(this.host);
4994
5373
  }
5374
+ const names = this.entries().map(([key]) => key);
5375
+ 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(", ")})`);
5376
+ }
5377
+ /** every preview for the current var values. A preview that throws, or vars that cannot be
5378
+ * read yet (an image var still empty), give a line saying so instead of failing the others */
5379
+ computePreviews() {
5380
+ const previews = this.spec.previews ?? {};
5381
+ const names = Object.keys(previews);
5382
+ if (names.length === 0) return {};
5383
+ let values;
5384
+ try {
5385
+ values = varValues(this.vars);
5386
+ } catch (e) {
5387
+ const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
5388
+ return Object.fromEntries(names.map((n) => [n, why]));
5389
+ }
5390
+ const out = {};
5391
+ for (const [name, fn] of Object.entries(previews)) try {
5392
+ out[name] = fn(values);
5393
+ } catch (e) {
5394
+ out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
5395
+ }
5396
+ return out;
4995
5397
  }
4996
5398
  /** [name, var] pairs, for drivers that enumerate the knobs */
4997
5399
  entries() {
@@ -6297,6 +6699,10 @@ var ComfyTS = class ComfyTS {
6297
6699
  resolveFromPromptEnhancers(relativePath) {
6298
6700
  return asAbsolutePath((0, pathe.join)(this.baseFolder, "prompt-enhancers", relativePath));
6299
6701
  }
6702
+ /** the serve web ui's LLM configs (prompt enhancer), one json per config */
6703
+ resolveFromLlmConfigs(relativePath) {
6704
+ return asAbsolutePath((0, pathe.join)(this.baseFolder, "llm-configs", relativePath));
6705
+ }
6300
6706
  resolveFromCache(relativePath) {
6301
6707
  return asAbsolutePath((0, pathe.join)(this.baseFolder, "cache", relativePath));
6302
6708
  }
@@ -6455,6 +6861,7 @@ exports.ComfyWorkflow = ComfyWorkflow;
6455
6861
  exports.ComfyWorkflowBuilder = ComfyWorkflowBuilder;
6456
6862
  exports.DEFAULT_IMAGE_EXTENSIONS = DEFAULT_IMAGE_EXTENSIONS;
6457
6863
  exports.DEFAULT_SIZE_PRESETS = DEFAULT_SIZE_PRESETS;
6864
+ exports.DEFAULT_STARRED_SIZES = DEFAULT_STARRED_SIZES;
6458
6865
  exports.DefinedWorkflow = DefinedWorkflow;
6459
6866
  exports.FloatVar = FloatVar;
6460
6867
  exports.ImageVar = ImageVar;
@@ -6463,8 +6870,11 @@ exports.IntVar = IntVar;
6463
6870
  exports.InvalidPromptError = InvalidPromptError;
6464
6871
  exports.LorasVar = LorasVar;
6465
6872
  exports.MediaImage = MediaImage;
6873
+ exports.MultiChoiceVar = MultiChoiceVar;
6874
+ exports.OptionalChoiceVar = OptionalChoiceVar;
6466
6875
  exports.PromptVar = PromptVar;
6467
6876
  exports.ResilientWebSocketClient = ResilientWebSocketClient;
6877
+ exports.SD15_SIZE_PRESETS = SD15_SIZE_PRESETS;
6468
6878
  exports.SeedVar = SeedVar;
6469
6879
  exports.SizeVar = SizeVar;
6470
6880
  exports.TextVar = TextVar;
@@ -6515,6 +6925,7 @@ exports.resultFailure = resultFailure;
6515
6925
  exports.resultSuccess = resultSuccess;
6516
6926
  exports.setDefaultComfyStorage = setDefaultComfyStorage;
6517
6927
  exports.setLoraKeyword = setLoraKeyword;
6928
+ exports.sizePresetsFor = sizePresetsFor;
6518
6929
  exports.toPresetList = toPresetList;
6519
6930
  exports.v = v;
6520
6931