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/web.js CHANGED
@@ -101,7 +101,7 @@ function getComfyStorage() {
101
101
  }
102
102
  //#endregion
103
103
  //#region package.json
104
- var version = "2.11.0";
104
+ var version = "2.12.0";
105
105
  //#endregion
106
106
  //#region src/litegraph/LiteGraphLinkID.ts
107
107
  const asLiteGraphLinkID = (id) => id;
@@ -4341,6 +4341,221 @@ function writeKeywords() {
4341
4341
  }
4342
4342
  }
4343
4343
  //#endregion
4344
+ //#region src/vars/loraEntry.ts
4345
+ function isLoraEntry(s) {
4346
+ if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
4347
+ const o = s;
4348
+ const st = o.strength;
4349
+ 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"));
4350
+ }
4351
+ function isLoraStrength(s) {
4352
+ if (typeof s === "boolean") return true;
4353
+ if (typeof s === "number") return Number.isFinite(s);
4354
+ if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
4355
+ return isLoraEntry(s);
4356
+ }
4357
+ /** on = it runs */
4358
+ function loraIsOn(s) {
4359
+ if (s == null || s === false) return false;
4360
+ if (isLoraEntry(s)) return s.off !== true;
4361
+ return true;
4362
+ }
4363
+ /** the strengths, whatever the spelling (1/1 when there is nothing to read) */
4364
+ function loraStrengths(s) {
4365
+ if (typeof s === "number" && Number.isFinite(s)) return [s, s];
4366
+ if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
4367
+ if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
4368
+ return [1, 1];
4369
+ }
4370
+ function loraMuted(s) {
4371
+ return isLoraEntry(s) && s.mute != null ? s.mute : [];
4372
+ }
4373
+ /** a prompt keyword's parts, split at commas: each one can be left out on its own */
4374
+ function keywordParts(keyword) {
4375
+ return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
4376
+ }
4377
+ /** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
4378
+ function keptKeyword(keyword, muted) {
4379
+ return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
4380
+ }
4381
+ /** rewrite one setting, keeping what the patch does not name. The result stays in the short
4382
+ * spellings while nothing needs the palette form, so a plain draft reads as it always did */
4383
+ function withLora(s, patch) {
4384
+ const strength = patch.strength ?? loraStrengths(s);
4385
+ const off = patch.on == null ? !loraIsOn(s) : !patch.on;
4386
+ const mute = [...patch.mute ?? loraMuted(s)];
4387
+ if (!off && mute.length === 0) return [strength[0], strength[1]];
4388
+ return {
4389
+ strength: [strength[0], strength[1]],
4390
+ ...off ? { off: true } : {},
4391
+ ...mute.length === 0 ? {} : { mute }
4392
+ };
4393
+ }
4394
+ //#endregion
4395
+ //#region src/vars/lanes.ts
4396
+ const FIRST_LANE = "main";
4397
+ function isObject(v) {
4398
+ return typeof v === "object" && v != null && !Array.isArray(v);
4399
+ }
4400
+ function isPromptLane(v) {
4401
+ return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
4402
+ }
4403
+ function isPromptLanes(v) {
4404
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
4405
+ }
4406
+ /** the text the build reads: the active lanes joined in order, one line break between them, so
4407
+ * `//` and `- ` lines keep working inside every lane */
4408
+ function promptText(v) {
4409
+ if (typeof v === "string") return v;
4410
+ return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
4411
+ }
4412
+ const HEADER = /^# (.+?)( \(off\))?$/;
4413
+ function promptLanesToText(v) {
4414
+ return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
4415
+ }
4416
+ /** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
4417
+ function promptLanesFromText(text) {
4418
+ const lanes = [];
4419
+ let current = null;
4420
+ const body = [];
4421
+ const close = () => {
4422
+ if (current != null) lanes.push({
4423
+ ...current,
4424
+ prompt: body.join("\n")
4425
+ });
4426
+ else if (body.some((l) => l.trim() !== "")) lanes.push({
4427
+ name: FIRST_LANE,
4428
+ prompt: body.join("\n"),
4429
+ active: true
4430
+ });
4431
+ body.length = 0;
4432
+ };
4433
+ for (const line of text.split("\n")) {
4434
+ const m = HEADER.exec(line);
4435
+ if (m == null) {
4436
+ body.push(line);
4437
+ continue;
4438
+ }
4439
+ close();
4440
+ current = {
4441
+ name: (m[1] ?? "").trim(),
4442
+ prompt: "",
4443
+ active: m[2] == null
4444
+ };
4445
+ }
4446
+ close();
4447
+ return { lanes: lanes.length > 0 ? lanes : [{
4448
+ name: FIRST_LANE,
4449
+ prompt: "",
4450
+ active: true
4451
+ }] };
4452
+ }
4453
+ function isLoraRecord(v) {
4454
+ return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
4455
+ }
4456
+ function isLoraLane(v) {
4457
+ return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
4458
+ }
4459
+ function isLoraLanes(v) {
4460
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
4461
+ }
4462
+ function isLorasInput(v) {
4463
+ return isLoraRecord(v) || isLoraLanes(v);
4464
+ }
4465
+ /** one record for the build: the active lanes in order. A lora in two active lanes keeps its
4466
+ * FIRST setting, and `duplicates` names it so the caller can say so */
4467
+ function flattenLoras(v) {
4468
+ if (!isLoraLanes(v)) return {
4469
+ record: v,
4470
+ duplicates: []
4471
+ };
4472
+ const record = {};
4473
+ const duplicates = [];
4474
+ for (const lane of v.lanes) {
4475
+ if (!lane.active) continue;
4476
+ for (const [name, st] of Object.entries(lane.loras)) {
4477
+ if (st == null) continue;
4478
+ if (name in record) duplicates.push(name);
4479
+ else record[name] = st;
4480
+ }
4481
+ }
4482
+ return {
4483
+ record,
4484
+ duplicates
4485
+ };
4486
+ }
4487
+ /** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
4488
+ * has it (the one the build reads), else any lane, else -1 */
4489
+ function laneIndexOf(v, name) {
4490
+ const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
4491
+ return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
4492
+ }
4493
+ /** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
4494
+ * A lora in no lane yet lands in the first lane */
4495
+ function updateLora(v, name, next) {
4496
+ const write = (rec) => {
4497
+ const out = { ...rec };
4498
+ if (next == null) delete out[name];
4499
+ else out[name] = next;
4500
+ return out;
4501
+ };
4502
+ if (!isLoraLanes(v)) return write(v);
4503
+ if (v.lanes.length === 0) return { lanes: [{
4504
+ name: FIRST_LANE,
4505
+ active: true,
4506
+ loras: write({})
4507
+ }] };
4508
+ const found = laneIndexOf(v, name);
4509
+ const ix = found === -1 ? 0 : found;
4510
+ return { lanes: v.lanes.map((l, i) => i === ix ? {
4511
+ ...l,
4512
+ loras: write(l.loras)
4513
+ } : l) };
4514
+ }
4515
+ //#endregion
4516
+ //#region src/vars/promptSyntax.ts
4517
+ /** a whole line that is a comment (the TUI colors these) */
4518
+ const COMMENT_LINE_RE = /^\s*\/\//;
4519
+ /** a negative prompt line: `- ` then its text */
4520
+ const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
4521
+ const NEGATIVE_PREFIX_RE = /^(\s*)- /;
4522
+ /** where a `//` comment starts on this line, -1 when none. Only at line start or after
4523
+ * whitespace, so `http://host` is never cut */
4524
+ function commentStart(line) {
4525
+ const m = /(?:^|\s)\/\//.exec(line);
4526
+ if (m == null) return -1;
4527
+ return m.index + m[0].length - 2;
4528
+ }
4529
+ /** the line without its comment, trailing whitespace dropped with it */
4530
+ function withoutComment(line) {
4531
+ const c = commentStart(line);
4532
+ return c < 0 ? {
4533
+ text: line,
4534
+ hadComment: false
4535
+ } : {
4536
+ text: line.slice(0, c).trimEnd(),
4537
+ hadComment: true
4538
+ };
4539
+ }
4540
+ /** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
4541
+ function parsePromptText(text) {
4542
+ const pos = [];
4543
+ const neg = [];
4544
+ for (const raw of text.split("\n")) {
4545
+ const cut = withoutComment(raw);
4546
+ if (cut.hadComment && cut.text.trim() === "") continue;
4547
+ const m = NEGATIVE_PREFIX_RE.exec(raw);
4548
+ if (m != null && m[0].length <= cut.text.length + 1) {
4549
+ const body = cut.text.slice(m[0].length).trim();
4550
+ if (body !== "") neg.push(body);
4551
+ } else pos.push(cut.text);
4552
+ }
4553
+ return {
4554
+ positive: pos.join("\n").trim(),
4555
+ negative: neg.join(", ")
4556
+ };
4557
+ }
4558
+ //#endregion
4344
4559
  //#region src/vars/presets.ts
4345
4560
  function toPresetList(spec) {
4346
4561
  if (spec == null) return [];
@@ -4356,16 +4571,11 @@ function activePresetLabel(presets, value) {
4356
4571
  }
4357
4572
  //#endregion
4358
4573
  //#region src/vars/ComfyVars.ts
4359
- /**
4360
- * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
4361
- * time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
4362
- * the one Out-specialized var (string in, PromptValue out); the split keeps
4363
- * outValue() cast-free.
4364
- */
4365
4574
  var ComfyVarBase = class {
4366
4575
  constructor(defaultValue, label) {
4367
4576
  this.defaultValue = defaultValue;
4368
4577
  this.label = label;
4578
+ this.uiOpts = {};
4369
4579
  this.value = defaultValue;
4370
4580
  makeObservable(this, {
4371
4581
  value: observable,
@@ -4379,6 +4589,14 @@ var ComfyVarBase = class {
4379
4589
  this.value = value;
4380
4590
  return this;
4381
4591
  }
4592
+ /** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
4593
+ ui(p) {
4594
+ this.uiOpts = {
4595
+ ...this.uiOpts,
4596
+ ...p
4597
+ };
4598
+ return this;
4599
+ }
4382
4600
  /** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
4383
4601
  toJSON() {
4384
4602
  return this.value;
@@ -4426,12 +4644,10 @@ var TextVar = class extends ComfyVar {
4426
4644
  return true;
4427
4645
  }
4428
4646
  };
4429
- const commentLineRe = /^\s*\/\//;
4430
- const negativeLineRe = /^\s*- (.*)$/;
4431
4647
  /**
4432
4648
  * prompt text with editor comforts, all resolved at BUILD time (the editor and
4433
4649
  * drafts keep the raw text):
4434
- * - `//` lines are COMMENTS — stripped
4650
+ * - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
4435
4651
  * - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
4436
4652
  * comma-joined into `.negative`
4437
4653
  * - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
@@ -4445,38 +4661,48 @@ var PromptVar = class extends ComfyVarBase {
4445
4661
  this.kind = "prompt";
4446
4662
  this.presets = toPresetList(promptOpts.presets);
4447
4663
  }
4664
+ /** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
4448
4665
  parse(raw) {
4449
- this.set(raw);
4666
+ this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
4450
4667
  return true;
4451
4668
  }
4669
+ toEditBuffer() {
4670
+ return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
4671
+ }
4672
+ /** a var list shows the lanes by name, the inactive ones in parentheses */
4673
+ display() {
4674
+ if (!isPromptLanes(this.value)) return super.display();
4675
+ return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
4676
+ }
4677
+ /** the text the build reads: the plain string, or the active lanes joined in order */
4678
+ get text() {
4679
+ return promptText(this.value);
4680
+ }
4681
+ /** the tag list options in their one object form, null when this prompt has no completion */
4682
+ get tags() {
4683
+ const t = this.promptOpts.tags;
4684
+ if (t == null) return null;
4685
+ return typeof t === "string" ? { url: t } : t;
4686
+ }
4452
4687
  static isCommentLine(line) {
4453
- return commentLineRe.test(line);
4688
+ return COMMENT_LINE_RE.test(line);
4454
4689
  }
4455
4690
  static isNegativeLine(line) {
4456
- return negativeLineRe.test(line);
4691
+ return NEGATIVE_LINE_RE.test(line);
4457
4692
  }
4458
4693
  /** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
4459
4694
  injectedKeywords() {
4460
4695
  const src = this.promptOpts.loraKeywordsFrom;
4461
4696
  if (src == null) return [];
4462
- return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
4697
+ return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
4463
4698
  }
4464
4699
  outValue() {
4465
- const pos = [];
4466
- const neg = [];
4467
- for (const line of this.value.split("\n")) {
4468
- if (commentLineRe.test(line)) continue;
4469
- const m = negativeLineRe.exec(line);
4470
- if (m != null) {
4471
- const text = (m[1] ?? "").trim();
4472
- if (text !== "") neg.push(text);
4473
- } else pos.push(line);
4474
- }
4475
- const body = pos.join("\n").trim();
4700
+ const parsed = parsePromptText(this.text);
4701
+ const body = parsed.positive;
4476
4702
  const keywords = this.injectedKeywords();
4477
4703
  return {
4478
4704
  positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
4479
- negative: neg.join(", ")
4705
+ negative: parsed.negative
4480
4706
  };
4481
4707
  }
4482
4708
  };
@@ -4616,6 +4842,7 @@ var ChoiceVar = class extends ComfyVar {
4616
4842
  super(defaultValue, label);
4617
4843
  this.choices = choices;
4618
4844
  this.kind = "choice";
4845
+ this.select = "one";
4619
4846
  }
4620
4847
  next(delta = 1) {
4621
4848
  const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
@@ -4628,12 +4855,96 @@ var ChoiceVar = class extends ComfyVar {
4628
4855
  return true;
4629
4856
  }
4630
4857
  };
4858
+ /** one option or none: `null` is "nothing picked", clicking the lit option clears it */
4859
+ var OptionalChoiceVar = class extends ComfyVar {
4860
+ constructor(choices, defaultValue, label) {
4861
+ super(defaultValue, label);
4862
+ this.choices = choices;
4863
+ this.kind = "choice";
4864
+ this.select = "zero-or-one";
4865
+ }
4866
+ /** pick `c`, or clear it when it is already the one picked */
4867
+ toggle(c) {
4868
+ return this.set(this.value === c ? null : c);
4869
+ }
4870
+ /** the TUI text form: a choice, or an empty line for none */
4871
+ parse(raw) {
4872
+ if (raw.trim() === "") {
4873
+ this.set(null);
4874
+ return true;
4875
+ }
4876
+ const hit = this.choices.find((c) => c === raw.trim());
4877
+ if (hit == null) return false;
4878
+ this.set(hit);
4879
+ return true;
4880
+ }
4881
+ toEditBuffer() {
4882
+ return this.value ?? "";
4883
+ }
4884
+ /** a draft from when this was a many choice holds a list: its first known option */
4885
+ loadJSON(value) {
4886
+ const one = Array.isArray(value) ? value[0] : value;
4887
+ return this.set(this.choices.find((c) => c === one) ?? null);
4888
+ }
4889
+ display() {
4890
+ return this.value ?? "none";
4891
+ }
4892
+ };
4893
+ /** any number of options, kept in the order the choices list them */
4894
+ var MultiChoiceVar = class extends ComfyVar {
4895
+ constructor(choices, defaultValue, label) {
4896
+ super([...defaultValue], label);
4897
+ this.choices = choices;
4898
+ this.kind = "choice";
4899
+ this.select = "many";
4900
+ }
4901
+ toggle(c) {
4902
+ const on = this.value.includes(c);
4903
+ return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
4904
+ }
4905
+ /** the TUI text form: `a, b` */
4906
+ parse(raw) {
4907
+ const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
4908
+ const picked = this.choices.filter((c) => wanted.includes(c));
4909
+ if (picked.length !== new Set(wanted).size) return false;
4910
+ this.set(picked);
4911
+ return true;
4912
+ }
4913
+ toEditBuffer() {
4914
+ return this.value.join(", ");
4915
+ }
4916
+ /** a draft from when this was a single choice holds one value: a list of one. Unknown
4917
+ * options are dropped, the list comes back in the choices order */
4918
+ loadJSON(value) {
4919
+ const listed = Array.isArray(value) ? value : value == null ? [] : [value];
4920
+ return this.set(this.choices.filter((c) => listed.includes(c)));
4921
+ }
4922
+ display() {
4923
+ return this.value.length === 0 ? "none" : this.value.join(", ");
4924
+ }
4925
+ };
4926
+ /** Array.isArray does not narrow a READONLY array out of a union, this does */
4927
+ function isChoiceList(v) {
4928
+ return Array.isArray(v);
4929
+ }
4930
+ function choice(choices, defaultValue, opts) {
4931
+ const o = typeof opts === "string" ? { label: opts } : opts ?? {};
4932
+ const select = o.select ?? "one";
4933
+ if (select === "many") {
4934
+ if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
4935
+ return new MultiChoiceVar(choices, defaultValue, o.label);
4936
+ }
4937
+ if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
4938
+ if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
4939
+ if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
4940
+ return new ChoiceVar(choices, defaultValue, o.label);
4941
+ }
4631
4942
  /** normalize a loras record into what a standard LoraLoader chain consumes */
4632
4943
  function activeLoras(loras) {
4633
4944
  const out = [];
4634
- for (const [lora_name, s] of Object.entries(loras)) {
4635
- if (s == null || s === false) continue;
4636
- const [strength_model, strength_clip] = Array.isArray(s) ? s : s === true ? [1, 1] : [s, s];
4945
+ for (const [lora_name, s] of Object.entries(flattenLoras(loras).record)) {
4946
+ if (!loraIsOn(s)) continue;
4947
+ const [strength_model, strength_clip] = loraStrengths(s);
4637
4948
  out.push({
4638
4949
  lora_name,
4639
4950
  strength_model,
@@ -4648,7 +4959,12 @@ function activeLoras(loras) {
4648
4959
  * or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
4649
4960
  * a hardcoded inventory. Selection is empty by default.
4650
4961
  */
4651
- var LorasVar = class LorasVar extends ComfyVar {
4962
+ /**
4963
+ * the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
4964
+ * build merges in listed order, skipping inactive ones. Every method reads the merged record and
4965
+ * writes into the lane that holds the lora, so the TUI never needs to know lanes exist
4966
+ */
4967
+ var LorasVar = class LorasVar extends ComfyVarBase {
4652
4968
  constructor(optionsSource, initial = {}, label) {
4653
4969
  super(initial, label);
4654
4970
  this.optionsSource = optionsSource;
@@ -4679,49 +4995,57 @@ var LorasVar = class LorasVar extends ComfyVar {
4679
4995
  get names() {
4680
4996
  return [...this.options];
4681
4997
  }
4998
+ /** the loras the build reads: the plain record, or the active lanes merged in order */
4999
+ get record() {
5000
+ return flattenLoras(this.value).record;
5001
+ }
5002
+ /** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
5003
+ outValue() {
5004
+ const flat = flattenLoras(this.value);
5005
+ 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`);
5006
+ return flat.record;
5007
+ }
5008
+ /** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
5009
+ write(name, next) {
5010
+ return this.set(updateLora(this.value, name, next));
5011
+ }
5012
+ /** the parts of this lora's prompt keyword left out of the prompt */
5013
+ mutedWords(name) {
5014
+ return loraMuted(this.record[name]);
5015
+ }
4682
5016
  /** loras currently ON (PromptVar keyword prefixing consumes this) */
4683
5017
  activeNames() {
4684
5018
  return this.names.filter((n) => this.isOn(n));
4685
5019
  }
4686
5020
  isOn(name) {
4687
- const s = this.value[name];
4688
- return s != null && s !== false;
5021
+ return loraIsOn(this.record[name]);
4689
5022
  }
4690
5023
  toggleItem(name) {
4691
- const cur = this.value[name];
4692
- if (cur == null || cur === false) return this.set({
4693
- ...this.value,
4694
- [name]: this.prev[name] ?? true
4695
- });
5024
+ const cur = this.record[name];
5025
+ if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
5026
+ if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
4696
5027
  this.prev[name] = cur;
4697
- return this.set({
4698
- ...this.value,
4699
- [name]: false
4700
- });
5028
+ return this.write(name, false);
4701
5029
  }
4702
5030
  /** step both strengths by delta (true becomes 1 first); no-op when off */
4703
5031
  adjustItem(name, delta) {
4704
- const cur = this.value[name];
4705
- if (cur == null || cur === false) return this;
5032
+ const cur = this.record[name];
5033
+ if (!loraIsOn(cur)) return this;
4706
5034
  const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
4707
- const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : step(cur === true ? 1 : cur);
4708
- return this.set({
4709
- ...this.value,
4710
- [name]: next
4711
- });
5035
+ 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])] });
5036
+ return this.write(name, next);
4712
5037
  }
4713
5038
  /** compact per-item strength label for lists */
4714
5039
  strengthLabel(name) {
4715
- const s = this.value[name];
4716
- if (s == null || s === false) return "";
4717
- if (s === true) return "1.00";
4718
- if (Array.isArray(s)) return `m:${s[0].toFixed(2)} c:${s[1].toFixed(2)}`;
4719
- return s.toFixed(2);
5040
+ const s = this.record[name];
5041
+ if (!loraIsOn(s)) return "";
5042
+ const [m, c] = loraStrengths(s);
5043
+ return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
4720
5044
  }
4721
5045
  parse(raw) {
4722
5046
  try {
4723
5047
  const parsed = JSON.parse(raw);
4724
- if (typeof parsed !== "object" || parsed == null || Array.isArray(parsed)) return false;
5048
+ if (!isLorasInput(parsed)) return false;
4725
5049
  this.set(parsed);
4726
5050
  return true;
4727
5051
  } catch {
@@ -4734,14 +5058,16 @@ var LorasVar = class LorasVar extends ComfyVar {
4734
5058
  }
4735
5059
  /** tick (true) or untick (false) every lora in `names` (default: all options) */
4736
5060
  setAll(on, names = this.options) {
4737
- const next = { ...this.value };
5061
+ const record = this.record;
5062
+ let next = this.value;
4738
5063
  for (const name of names) {
4739
- const cur = next[name];
5064
+ const cur = record[name];
4740
5065
  if (on) {
4741
- if (cur == null || cur === false) next[name] = this.prev[name] ?? true;
5066
+ if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
5067
+ else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
4742
5068
  } else {
4743
- if (cur != null && cur !== false) this.prev[name] = cur;
4744
- next[name] = false;
5069
+ if (loraIsOn(cur)) this.prev[name] = cur;
5070
+ next = updateLora(next, name, false);
4745
5071
  }
4746
5072
  }
4747
5073
  return this.set(next);
@@ -4790,6 +5116,56 @@ const DEFAULT_SIZE_PRESETS = [
4790
5116
  height: 1344
4791
5117
  }
4792
5118
  ];
5119
+ /** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
5120
+ const SD15_SIZE_PRESETS = [
5121
+ {
5122
+ label: "1:1 square",
5123
+ width: 512,
5124
+ height: 512
5125
+ },
5126
+ {
5127
+ label: "4:3 landscape",
5128
+ width: 576,
5129
+ height: 448
5130
+ },
5131
+ {
5132
+ label: "3:4 portrait",
5133
+ width: 448,
5134
+ height: 576
5135
+ },
5136
+ {
5137
+ label: "3:2 landscape",
5138
+ width: 576,
5139
+ height: 384
5140
+ },
5141
+ {
5142
+ label: "2:3 portrait",
5143
+ width: 384,
5144
+ height: 576
5145
+ },
5146
+ {
5147
+ label: "16:9 widescreen",
5148
+ width: 704,
5149
+ height: 384
5150
+ },
5151
+ {
5152
+ label: "9:16 tall",
5153
+ width: 384,
5154
+ height: 704
5155
+ }
5156
+ ];
5157
+ /** starred presets are one click away in the panel, before the full list */
5158
+ const DEFAULT_STARRED_SIZES = [
5159
+ "1:1 square",
5160
+ "3:4 portrait",
5161
+ "4:3 landscape"
5162
+ ];
5163
+ /** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
5164
+ * and offering it 1024 buckets would be offering sizes it was never trained at */
5165
+ function sizePresetsFor(defaultValue) {
5166
+ if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
5167
+ return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
5168
+ }
4793
5169
  /** width/height picker: presets + free `WxH` entry + optionally the LIVE
4794
5170
  * size of a linked image var (the widget shows
4795
5171
  * `WxH size of image '<name>'` as a pickable row) */
@@ -4797,10 +5173,11 @@ var SizeVar = class extends ComfyVar {
4797
5173
  constructor(defaultValue = {
4798
5174
  width: 1024,
4799
5175
  height: 1024
4800
- }, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
5176
+ }, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
4801
5177
  super(defaultValue, label);
4802
5178
  this.presets = presets;
4803
5179
  this.imageVar = imageVar;
5180
+ this.starred = starred;
4804
5181
  this.kind = "size";
4805
5182
  }
4806
5183
  /** current dimensions of the linked image var — null when no link, unset
@@ -4925,9 +5302,11 @@ const v = {
4925
5302
  * which is what a tuning session wants, and reset()/revert come back to it */
4926
5303
  seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
4927
5304
  toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
4928
- choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
5305
+ /** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
5306
+ * `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
5307
+ choice,
4929
5308
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
4930
- size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
5309
+ size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
4931
5310
  image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
4932
5311
  };
4933
5312
  function varValues(vars) {
@@ -4956,6 +5335,29 @@ var DefinedWorkflow = class {
4956
5335
  varDef.name = key;
4957
5336
  varDef.bindHost?.(this.host);
4958
5337
  }
5338
+ const names = this.entries().map(([key]) => key);
5339
+ 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(", ")})`);
5340
+ }
5341
+ /** every preview for the current var values. A preview that throws, or vars that cannot be
5342
+ * read yet (an image var still empty), give a line saying so instead of failing the others */
5343
+ computePreviews() {
5344
+ const previews = this.spec.previews ?? {};
5345
+ const names = Object.keys(previews);
5346
+ if (names.length === 0) return {};
5347
+ let values;
5348
+ try {
5349
+ values = varValues(this.vars);
5350
+ } catch (e) {
5351
+ const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
5352
+ return Object.fromEntries(names.map((n) => [n, why]));
5353
+ }
5354
+ const out = {};
5355
+ for (const [name, fn] of Object.entries(previews)) try {
5356
+ out[name] = fn(values);
5357
+ } catch (e) {
5358
+ out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
5359
+ }
5360
+ return out;
4959
5361
  }
4960
5362
  /** [name, var] pairs, for drivers that enumerate the knobs */
4961
5363
  entries() {
@@ -6261,6 +6663,10 @@ var ComfyTS = class ComfyTS {
6261
6663
  resolveFromPromptEnhancers(relativePath) {
6262
6664
  return asAbsolutePath(join(this.baseFolder, "prompt-enhancers", relativePath));
6263
6665
  }
6666
+ /** the serve web ui's LLM configs (prompt enhancer), one json per config */
6667
+ resolveFromLlmConfigs(relativePath) {
6668
+ return asAbsolutePath(join(this.baseFolder, "llm-configs", relativePath));
6669
+ }
6264
6670
  resolveFromCache(relativePath) {
6265
6671
  return asAbsolutePath(join(this.baseFolder, "cache", relativePath));
6266
6672
  }
@@ -6308,6 +6714,6 @@ function loraTag(name, strength = 1, clipStrength) {
6308
6714
  */
6309
6715
  setDefaultComfyStorage(createMemoryStorage());
6310
6716
  //#endregion
6311
- 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, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, toPresetList, v };
6717
+ 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, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
6312
6718
 
6313
6719
  //# sourceMappingURL=web.js.map