comfy-ts 2.11.0 → 2.13.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 (122) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-qtFzOKpu.js → LogsSt-CUeo843w.js} +51 -7
  3. package/dist/LogsSt-CUeo843w.js.map +1 -0
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +595 -73
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +286 -46
  8. package/dist/index.d.ts +286 -46
  9. package/dist/index.js +591 -74
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-BK7BA2dn.js → run-serve-DlRBv_Nk.js} +738 -58
  12. package/dist/run-serve-DlRBv_Nk.js.map +1 -0
  13. package/dist/{run-tui-CQyvMf0N.js → run-tui-B5uxm2_l.js} +43 -18
  14. package/dist/run-tui-B5uxm2_l.js.map +1 -0
  15. package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-E95iTF7E.js} +473 -60
  16. package/dist/schemaDrift-E95iTF7E.js.map +1 -0
  17. package/dist/serve-web.js +710 -174
  18. package/dist/{state--wrz0BQc.js → state-CUp2J1Zy.js} +126 -14
  19. package/dist/state-CUp2J1Zy.js.map +1 -0
  20. package/dist/web.d.ts +286 -46
  21. package/dist/web.js +591 -74
  22. package/dist/web.js.map +1 -1
  23. package/examples/comfy-cloud/sdk.d.ts +163 -163
  24. package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
  25. package/examples/rvion/10-anima-t2i.cflow.ts +252 -0
  26. package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
  27. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
  28. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
  29. package/examples/rvion/stableAudio3Prompts.ts +19 -0
  30. package/extra/README.md +4 -0
  31. package/extra/comfyui-fresh-model-lists/README.md +25 -0
  32. package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
  33. package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
  34. package/package.json +15 -7
  35. package/src/cli/draftMeta.ts +39 -0
  36. package/src/cli/serve/ServeApp.ts +305 -30
  37. package/src/cli/serve/applyVarPayload.ts +50 -22
  38. package/src/cli/serve/byteRange.ts +48 -0
  39. package/src/cli/serve/describeVar.ts +42 -6
  40. package/src/cli/serve/llmConfigShape.ts +51 -0
  41. package/src/cli/serve/llmConfigs.ts +52 -0
  42. package/src/cli/serve/run-serve.ts +12 -3
  43. package/src/cli/serve/tagList.ts +92 -0
  44. package/src/cli/serve/tagSource.ts +69 -0
  45. package/src/cli/serve/web/api.ts +72 -0
  46. package/src/cli/serve/web/components/App.tsx +485 -44
  47. package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
  48. package/src/cli/serve/web/components/Gallery.tsx +133 -31
  49. package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
  50. package/src/cli/serve/web/components/Icon.tsx +58 -2
  51. package/src/cli/serve/web/components/MenuButton.tsx +53 -0
  52. package/src/cli/serve/web/components/Omnibox.tsx +135 -0
  53. package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
  54. package/src/cli/serve/web/components/SideMenu.tsx +414 -0
  55. package/src/cli/serve/web/components/TooltipLayer.tsx +46 -0
  56. package/src/cli/serve/web/components/VarIcon.tsx +24 -0
  57. package/src/cli/serve/web/components/VarsForm.tsx +223 -351
  58. package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
  59. package/src/cli/serve/web/components/controls/LorasControl.tsx +646 -317
  60. package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
  61. package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
  62. package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
  63. package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
  64. package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
  65. package/src/cli/serve/web/components/modKey.ts +2 -0
  66. package/src/cli/serve/web/llm.ts +23 -12
  67. package/src/cli/serve/web/promptEditor/promptExtensions.ts +284 -0
  68. package/src/cli/serve/web/state/EnhancerSt.ts +431 -101
  69. package/src/cli/serve/web/state/FormSt.ts +214 -30
  70. package/src/cli/serve/web/state/OmniboxSt.ts +59 -0
  71. package/src/cli/serve/web/state/WebSt.ts +364 -80
  72. package/src/cli/serve/web/state/choiceButtons.ts +61 -0
  73. package/src/cli/serve/web/state/draftNames.ts +16 -0
  74. package/src/cli/serve/web/state/draftTabs.ts +75 -0
  75. package/src/cli/serve/web/state/generateButton.ts +16 -0
  76. package/src/cli/serve/web/state/history.ts +54 -0
  77. package/src/cli/serve/web/state/host.ts +5 -2
  78. package/src/cli/serve/web/state/keptLines.ts +53 -0
  79. package/src/cli/serve/web/state/latentMode.ts +20 -0
  80. package/src/cli/serve/web/state/loraSort.ts +18 -0
  81. package/src/cli/serve/web/state/moduleTree.ts +2 -2
  82. package/src/cli/serve/web/state/omnibox.ts +133 -0
  83. package/src/cli/serve/web/state/payload.ts +38 -58
  84. package/src/cli/serve/web/state/shortcuts.ts +103 -0
  85. package/src/cli/serve/web/state/sizeStars.ts +31 -0
  86. package/src/cli/serve/web/state/stableSlots.ts +21 -0
  87. package/src/cli/serve/web/state/varGroups.ts +24 -0
  88. package/src/cli/serve/web/styles.ts +653 -154
  89. package/src/cli/serve/webBundle.ts +54 -10
  90. package/src/cli/serve/workflowTags.ts +42 -0
  91. package/src/cli/serve/workspaceLabels.ts +23 -0
  92. package/src/cli/tui/components/PickerOverlays.tsx +9 -2
  93. package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
  94. package/src/cli/tui/state/DraftsSt.ts +28 -8
  95. package/src/cli/tui/state/EditorSt.ts +1 -1
  96. package/src/cli/tui/state/LorasSt.ts +1 -1
  97. package/src/cli/tui/state/PickerSt.ts +25 -7
  98. package/src/cli/tui/state/SettingsSt.ts +1 -1
  99. package/src/cli/tui/state/TuiSt.ts +10 -0
  100. package/src/coreExports.ts +21 -0
  101. package/src/host/ComfyHost.ts +17 -2
  102. package/src/host/ResilientWebsocket.ts +54 -4
  103. package/src/host/loraInfoCache.ts +6 -0
  104. package/src/runner/ComfyExecution.ts +60 -0
  105. package/src/runner/ComfyWorkflow.ts +4 -0
  106. package/src/runner/ComfyWsApi.ts +2 -0
  107. package/src/runner/MediaImage.ts +2 -2
  108. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
  109. package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
  110. package/src/state.ts +5 -0
  111. package/src/utils/copyName.ts +12 -0
  112. package/src/vars/ComfyVars.ts +337 -67
  113. package/src/vars/DefinedWorkflow.ts +47 -20
  114. package/src/vars/lanes.ts +238 -0
  115. package/src/vars/loraEntry.ts +101 -0
  116. package/src/vars/promptSyntax.ts +382 -0
  117. package/dist/LogsSt-qtFzOKpu.js.map +0 -1
  118. package/dist/run-serve-BK7BA2dn.js.map +0 -1
  119. package/dist/run-tui-CQyvMf0N.js.map +0 -1
  120. package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
  121. package/dist/state--wrz0BQc.js.map +0 -1
  122. package/src/cli/serve/web/components/Sidebar.tsx +0 -66
@@ -739,6 +739,11 @@ function loraMatchesFilter(name, filter, hostId) {
739
739
  const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
740
740
  return tokens.every((token) => fields.some((field) => field.includes(token)));
741
741
  }
742
+ /** the loras a host lists that the local copy of its lora manager list does not know yet:
743
+ * downloaded after the last sync, so they have no name, preview or trigger words here */
744
+ function lorasMissingFromMirror(hostLoras, inMirror) {
745
+ return hostLoras.filter((n) => !inMirror(n));
746
+ }
742
747
  //#endregion
743
748
  //#region src/vars/loraKeywords.ts
744
749
  /**
@@ -827,6 +832,224 @@ function writeKeywords() {
827
832
  }
828
833
  }
829
834
  //#endregion
835
+ //#region src/vars/loraEntry.ts
836
+ function isLoraEntry(s) {
837
+ if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
838
+ const o = s;
839
+ const st = o.strength;
840
+ 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"));
841
+ }
842
+ function isLoraStrength(s) {
843
+ if (typeof s === "boolean") return true;
844
+ if (typeof s === "number") return Number.isFinite(s);
845
+ if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
846
+ return isLoraEntry(s);
847
+ }
848
+ /** on = it runs */
849
+ function loraIsOn(s) {
850
+ if (s == null || s === false) return false;
851
+ if (isLoraEntry(s)) return s.off !== true;
852
+ return true;
853
+ }
854
+ /** the strengths, whatever the spelling (1/1 when there is nothing to read) */
855
+ function loraStrengths(s) {
856
+ if (typeof s === "number" && Number.isFinite(s)) return [s, s];
857
+ if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
858
+ if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
859
+ return [1, 1];
860
+ }
861
+ function loraMuted(s) {
862
+ return isLoraEntry(s) && s.mute != null ? s.mute : [];
863
+ }
864
+ /** a prompt keyword's parts, split at commas: each one can be left out on its own */
865
+ function keywordParts(keyword) {
866
+ return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
867
+ }
868
+ /** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
869
+ function keptKeyword(keyword, muted) {
870
+ return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
871
+ }
872
+ /** rewrite one setting, keeping what the patch does not name. The result stays in the short
873
+ * spellings while nothing needs the palette form, so a plain draft reads as it always did */
874
+ function withLora(s, patch) {
875
+ const strength = patch.strength ?? loraStrengths(s);
876
+ const off = patch.on == null ? !loraIsOn(s) : !patch.on;
877
+ const mute = [...patch.mute ?? loraMuted(s)];
878
+ if (!off && mute.length === 0) return [strength[0], strength[1]];
879
+ return {
880
+ strength: [strength[0], strength[1]],
881
+ ...off ? { off: true } : {},
882
+ ...mute.length === 0 ? {} : { mute }
883
+ };
884
+ }
885
+ //#endregion
886
+ //#region src/vars/lanes.ts
887
+ const FIRST_LANE = "main";
888
+ function isObject(v) {
889
+ return typeof v === "object" && v != null && !Array.isArray(v);
890
+ }
891
+ function isPromptLane(v) {
892
+ return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
893
+ }
894
+ function isPromptLanes(v) {
895
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
896
+ }
897
+ function isPromptInput(v) {
898
+ return typeof v === "string" || isPromptLanes(v);
899
+ }
900
+ /** the text the build reads: the active lanes joined in order, one line break between them, so
901
+ * `//` and `- ` lines keep working inside every lane */
902
+ function promptText(v) {
903
+ if (typeof v === "string") return v;
904
+ return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
905
+ }
906
+ const HEADER = /^# (.+?)( \(off\))?$/;
907
+ function promptLanesToText(v) {
908
+ return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
909
+ }
910
+ /** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
911
+ function promptLanesFromText(text) {
912
+ const lanes = [];
913
+ let current = null;
914
+ const body = [];
915
+ const close = () => {
916
+ if (current != null) lanes.push({
917
+ ...current,
918
+ prompt: body.join("\n")
919
+ });
920
+ else if (body.some((l) => l.trim() !== "")) lanes.push({
921
+ name: FIRST_LANE,
922
+ prompt: body.join("\n"),
923
+ active: true
924
+ });
925
+ body.length = 0;
926
+ };
927
+ for (const line of text.split("\n")) {
928
+ const m = HEADER.exec(line);
929
+ if (m == null) {
930
+ body.push(line);
931
+ continue;
932
+ }
933
+ close();
934
+ current = {
935
+ name: (m[1] ?? "").trim(),
936
+ prompt: "",
937
+ active: m[2] == null
938
+ };
939
+ }
940
+ close();
941
+ return { lanes: lanes.length > 0 ? lanes : [{
942
+ name: FIRST_LANE,
943
+ prompt: "",
944
+ active: true
945
+ }] };
946
+ }
947
+ function isLoraRecord(v) {
948
+ return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
949
+ }
950
+ function isLoraLane(v) {
951
+ return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
952
+ }
953
+ function isLoraLanes(v) {
954
+ return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
955
+ }
956
+ function isLorasInput(v) {
957
+ return isLoraRecord(v) || isLoraLanes(v);
958
+ }
959
+ /** one record for the build: the active lanes in order. A lora in two active lanes keeps its
960
+ * FIRST setting, and `duplicates` names it so the caller can say so */
961
+ function flattenLoras(v) {
962
+ if (!isLoraLanes(v)) return {
963
+ record: v,
964
+ duplicates: []
965
+ };
966
+ const record = {};
967
+ const duplicates = [];
968
+ for (const lane of v.lanes) {
969
+ if (!lane.active) continue;
970
+ for (const [name, st] of Object.entries(lane.loras)) {
971
+ if (st == null) continue;
972
+ if (name in record) duplicates.push(name);
973
+ else record[name] = st;
974
+ }
975
+ }
976
+ return {
977
+ record,
978
+ duplicates
979
+ };
980
+ }
981
+ /** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
982
+ * has it (the one the build reads), else any lane, else -1 */
983
+ function laneIndexOf(v, name) {
984
+ const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
985
+ return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
986
+ }
987
+ /** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
988
+ * A lora in no lane yet lands in the first lane */
989
+ function updateLora(v, name, next) {
990
+ const write = (rec) => {
991
+ const out = { ...rec };
992
+ if (next == null) delete out[name];
993
+ else out[name] = next;
994
+ return out;
995
+ };
996
+ if (!isLoraLanes(v)) return write(v);
997
+ if (v.lanes.length === 0) return { lanes: [{
998
+ name: FIRST_LANE,
999
+ active: true,
1000
+ loras: write({})
1001
+ }] };
1002
+ const found = laneIndexOf(v, name);
1003
+ const ix = found === -1 ? 0 : found;
1004
+ return { lanes: v.lanes.map((l, i) => i === ix ? {
1005
+ ...l,
1006
+ loras: write(l.loras)
1007
+ } : l) };
1008
+ }
1009
+ //#endregion
1010
+ //#region src/vars/promptSyntax.ts
1011
+ /** a whole line that is a comment (the TUI colors these) */
1012
+ const COMMENT_LINE_RE = /^\s*\/\//;
1013
+ /** a negative prompt line: `- ` then its text */
1014
+ const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
1015
+ const NEGATIVE_PREFIX_RE = /^(\s*)- /;
1016
+ /** where a `//` comment starts on this line, -1 when none. Only at line start or after
1017
+ * whitespace, so `http://host` is never cut */
1018
+ function commentStart(line) {
1019
+ const m = /(?:^|\s)\/\//.exec(line);
1020
+ if (m == null) return -1;
1021
+ return m.index + m[0].length - 2;
1022
+ }
1023
+ /** the line without its comment, trailing whitespace dropped with it */
1024
+ function withoutComment(line) {
1025
+ const c = commentStart(line);
1026
+ return c < 0 ? {
1027
+ text: line,
1028
+ hadComment: false
1029
+ } : {
1030
+ text: line.slice(0, c).trimEnd(),
1031
+ hadComment: true
1032
+ };
1033
+ }
1034
+ /** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
1035
+ function parsePromptText(text) {
1036
+ const pos = [];
1037
+ const neg = [];
1038
+ for (const raw of text.split("\n")) {
1039
+ const cut = withoutComment(raw);
1040
+ if (cut.hadComment && cut.text.trim() === "") continue;
1041
+ const m = NEGATIVE_PREFIX_RE.exec(raw);
1042
+ if (m != null && m[0].length <= cut.text.length + 1) {
1043
+ const body = cut.text.slice(m[0].length).trim();
1044
+ if (body !== "") neg.push(body);
1045
+ } else pos.push(cut.text);
1046
+ }
1047
+ return {
1048
+ positive: pos.join("\n").trim(),
1049
+ negative: neg.join(", ")
1050
+ };
1051
+ }
1052
+ //#endregion
830
1053
  //#region src/vars/presets.ts
831
1054
  function toPresetList(spec) {
832
1055
  if (spec == null) return [];
@@ -837,16 +1060,11 @@ function toPresetList(spec) {
837
1060
  }
838
1061
  //#endregion
839
1062
  //#region src/vars/ComfyVars.ts
840
- /**
841
- * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
842
- * time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
843
- * the one Out-specialized var (string in, PromptValue out); the split keeps
844
- * outValue() cast-free.
845
- */
846
1063
  var ComfyVarBase = class {
847
1064
  constructor(defaultValue, label) {
848
1065
  this.defaultValue = defaultValue;
849
1066
  this.label = label;
1067
+ this.uiOpts = {};
850
1068
  this.value = defaultValue;
851
1069
  makeObservable(this, {
852
1070
  value: observable,
@@ -860,6 +1078,14 @@ var ComfyVarBase = class {
860
1078
  this.value = value;
861
1079
  return this;
862
1080
  }
1081
+ /** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
1082
+ ui(p) {
1083
+ this.uiOpts = {
1084
+ ...this.uiOpts,
1085
+ ...p
1086
+ };
1087
+ return this;
1088
+ }
863
1089
  /** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
864
1090
  toJSON() {
865
1091
  return this.value;
@@ -907,12 +1133,10 @@ var TextVar = class extends ComfyVar {
907
1133
  return true;
908
1134
  }
909
1135
  };
910
- const commentLineRe = /^\s*\/\//;
911
- const negativeLineRe = /^\s*- (.*)$/;
912
1136
  /**
913
1137
  * prompt text with editor comforts, all resolved at BUILD time (the editor and
914
1138
  * drafts keep the raw text):
915
- * - `//` lines are COMMENTS — stripped
1139
+ * - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
916
1140
  * - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
917
1141
  * comma-joined into `.negative`
918
1142
  * - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
@@ -926,38 +1150,48 @@ var PromptVar = class extends ComfyVarBase {
926
1150
  this.kind = "prompt";
927
1151
  this.presets = toPresetList(promptOpts.presets);
928
1152
  }
1153
+ /** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
929
1154
  parse(raw) {
930
- this.set(raw);
1155
+ this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
931
1156
  return true;
932
1157
  }
1158
+ toEditBuffer() {
1159
+ return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
1160
+ }
1161
+ /** a var list shows the lanes by name, the inactive ones in parentheses */
1162
+ display() {
1163
+ if (!isPromptLanes(this.value)) return super.display();
1164
+ return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
1165
+ }
1166
+ /** the text the build reads: the plain string, or the active lanes joined in order */
1167
+ get text() {
1168
+ return promptText(this.value);
1169
+ }
1170
+ /** the tag list options in their one object form, null when this prompt has no completion */
1171
+ get tags() {
1172
+ const t = this.promptOpts.tags;
1173
+ if (t == null) return null;
1174
+ return typeof t === "string" ? { url: t } : t;
1175
+ }
933
1176
  static isCommentLine(line) {
934
- return commentLineRe.test(line);
1177
+ return COMMENT_LINE_RE.test(line);
935
1178
  }
936
1179
  static isNegativeLine(line) {
937
- return negativeLineRe.test(line);
1180
+ return NEGATIVE_LINE_RE.test(line);
938
1181
  }
939
1182
  /** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
940
1183
  injectedKeywords() {
941
1184
  const src = this.promptOpts.loraKeywordsFrom;
942
1185
  if (src == null) return [];
943
- return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
1186
+ return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
944
1187
  }
945
1188
  outValue() {
946
- const pos = [];
947
- const neg = [];
948
- for (const line of this.value.split("\n")) {
949
- if (commentLineRe.test(line)) continue;
950
- const m = negativeLineRe.exec(line);
951
- if (m != null) {
952
- const text = (m[1] ?? "").trim();
953
- if (text !== "") neg.push(text);
954
- } else pos.push(line);
955
- }
956
- const body = pos.join("\n").trim();
1189
+ const parsed = parsePromptText(this.text);
1190
+ const body = parsed.positive;
957
1191
  const keywords = this.injectedKeywords();
958
1192
  return {
959
1193
  positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
960
- negative: neg.join(", ")
1194
+ negative: parsed.negative
961
1195
  };
962
1196
  }
963
1197
  };
@@ -1097,6 +1331,7 @@ var ChoiceVar = class extends ComfyVar {
1097
1331
  super(defaultValue, label);
1098
1332
  this.choices = choices;
1099
1333
  this.kind = "choice";
1334
+ this.select = "one";
1100
1335
  }
1101
1336
  next(delta = 1) {
1102
1337
  const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
@@ -1109,13 +1344,102 @@ var ChoiceVar = class extends ComfyVar {
1109
1344
  return true;
1110
1345
  }
1111
1346
  };
1347
+ /** one option or none: `null` is "nothing picked", clicking the lit option clears it */
1348
+ var OptionalChoiceVar = class extends ComfyVar {
1349
+ constructor(choices, defaultValue, label) {
1350
+ super(defaultValue, label);
1351
+ this.choices = choices;
1352
+ this.kind = "choice";
1353
+ this.select = "zero-or-one";
1354
+ }
1355
+ /** pick `c`, or clear it when it is already the one picked */
1356
+ toggle(c) {
1357
+ return this.set(this.value === c ? null : c);
1358
+ }
1359
+ /** the TUI text form: a choice, or an empty line for none */
1360
+ parse(raw) {
1361
+ if (raw.trim() === "") {
1362
+ this.set(null);
1363
+ return true;
1364
+ }
1365
+ const hit = this.choices.find((c) => c === raw.trim());
1366
+ if (hit == null) return false;
1367
+ this.set(hit);
1368
+ return true;
1369
+ }
1370
+ toEditBuffer() {
1371
+ return this.value ?? "";
1372
+ }
1373
+ /** a draft from when this was a many choice holds a list: its first known option */
1374
+ loadJSON(value) {
1375
+ const one = Array.isArray(value) ? value[0] : value;
1376
+ return this.set(this.choices.find((c) => c === one) ?? null);
1377
+ }
1378
+ display() {
1379
+ return this.value ?? "none";
1380
+ }
1381
+ };
1382
+ /** any number of options, kept in the order the choices list them */
1383
+ var MultiChoiceVar = class extends ComfyVar {
1384
+ constructor(choices, defaultValue, label) {
1385
+ super([...defaultValue], label);
1386
+ this.choices = choices;
1387
+ this.kind = "choice";
1388
+ this.select = "many";
1389
+ }
1390
+ toggle(c) {
1391
+ const on = this.value.includes(c);
1392
+ return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
1393
+ }
1394
+ /** the TUI text form: `a, b` */
1395
+ parse(raw) {
1396
+ const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
1397
+ const picked = this.choices.filter((c) => wanted.includes(c));
1398
+ if (picked.length !== new Set(wanted).size) return false;
1399
+ this.set(picked);
1400
+ return true;
1401
+ }
1402
+ toEditBuffer() {
1403
+ return this.value.join(", ");
1404
+ }
1405
+ /** a draft from when this was a single choice holds one value: a list of one. Unknown
1406
+ * options are dropped, the list comes back in the choices order */
1407
+ loadJSON(value) {
1408
+ const listed = Array.isArray(value) ? value : value == null ? [] : [value];
1409
+ return this.set(this.choices.filter((c) => listed.includes(c)));
1410
+ }
1411
+ display() {
1412
+ return this.value.length === 0 ? "none" : this.value.join(", ");
1413
+ }
1414
+ };
1415
+ /** Array.isArray does not narrow a READONLY array out of a union, this does */
1416
+ function isChoiceList(v) {
1417
+ return Array.isArray(v);
1418
+ }
1419
+ function choice(choices, defaultValue, opts) {
1420
+ const o = typeof opts === "string" ? { label: opts } : opts ?? {};
1421
+ const select = o.select ?? "one";
1422
+ if (select === "many") {
1423
+ if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
1424
+ return new MultiChoiceVar(choices, defaultValue, o.label);
1425
+ }
1426
+ if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
1427
+ if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
1428
+ if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
1429
+ return new ChoiceVar(choices, defaultValue, o.label);
1430
+ }
1112
1431
  /**
1113
1432
  * multi-select lora stack over a DYNAMIC options list — a RegExp resolves
1114
1433
  * against the host's loras at define time (DefinedWorkflow calls bindHost),
1115
1434
  * or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
1116
1435
  * a hardcoded inventory. Selection is empty by default.
1117
1436
  */
1118
- var LorasVar = class LorasVar extends ComfyVar {
1437
+ /**
1438
+ * the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
1439
+ * build merges in listed order, skipping inactive ones. Every method reads the merged record and
1440
+ * writes into the lane that holds the lora, so the TUI never needs to know lanes exist
1441
+ */
1442
+ var LorasVar = class LorasVar extends ComfyVarBase {
1119
1443
  constructor(optionsSource, initial = {}, label) {
1120
1444
  super(initial, label);
1121
1445
  this.optionsSource = optionsSource;
@@ -1146,49 +1470,57 @@ var LorasVar = class LorasVar extends ComfyVar {
1146
1470
  get names() {
1147
1471
  return [...this.options];
1148
1472
  }
1473
+ /** the loras the build reads: the plain record, or the active lanes merged in order */
1474
+ get record() {
1475
+ return flattenLoras(this.value).record;
1476
+ }
1477
+ /** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
1478
+ outValue() {
1479
+ const flat = flattenLoras(this.value);
1480
+ 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`);
1481
+ return flat.record;
1482
+ }
1483
+ /** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
1484
+ write(name, next) {
1485
+ return this.set(updateLora(this.value, name, next));
1486
+ }
1487
+ /** the parts of this lora's prompt keyword left out of the prompt */
1488
+ mutedWords(name) {
1489
+ return loraMuted(this.record[name]);
1490
+ }
1149
1491
  /** loras currently ON (PromptVar keyword prefixing consumes this) */
1150
1492
  activeNames() {
1151
1493
  return this.names.filter((n) => this.isOn(n));
1152
1494
  }
1153
1495
  isOn(name) {
1154
- const s = this.value[name];
1155
- return s != null && s !== false;
1496
+ return loraIsOn(this.record[name]);
1156
1497
  }
1157
1498
  toggleItem(name) {
1158
- const cur = this.value[name];
1159
- if (cur == null || cur === false) return this.set({
1160
- ...this.value,
1161
- [name]: this.prev[name] ?? true
1162
- });
1499
+ const cur = this.record[name];
1500
+ if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
1501
+ if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
1163
1502
  this.prev[name] = cur;
1164
- return this.set({
1165
- ...this.value,
1166
- [name]: false
1167
- });
1503
+ return this.write(name, false);
1168
1504
  }
1169
1505
  /** step both strengths by delta (true becomes 1 first); no-op when off */
1170
1506
  adjustItem(name, delta) {
1171
- const cur = this.value[name];
1172
- if (cur == null || cur === false) return this;
1507
+ const cur = this.record[name];
1508
+ if (!loraIsOn(cur)) return this;
1173
1509
  const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
1174
- const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : step(cur === true ? 1 : cur);
1175
- return this.set({
1176
- ...this.value,
1177
- [name]: next
1178
- });
1510
+ 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])] });
1511
+ return this.write(name, next);
1179
1512
  }
1180
1513
  /** compact per-item strength label for lists */
1181
1514
  strengthLabel(name) {
1182
- const s = this.value[name];
1183
- if (s == null || s === false) return "";
1184
- if (s === true) return "1.00";
1185
- if (Array.isArray(s)) return `m:${s[0].toFixed(2)} c:${s[1].toFixed(2)}`;
1186
- return s.toFixed(2);
1515
+ const s = this.record[name];
1516
+ if (!loraIsOn(s)) return "";
1517
+ const [m, c] = loraStrengths(s);
1518
+ return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
1187
1519
  }
1188
1520
  parse(raw) {
1189
1521
  try {
1190
1522
  const parsed = JSON.parse(raw);
1191
- if (typeof parsed !== "object" || parsed == null || Array.isArray(parsed)) return false;
1523
+ if (!isLorasInput(parsed)) return false;
1192
1524
  this.set(parsed);
1193
1525
  return true;
1194
1526
  } catch {
@@ -1201,14 +1533,16 @@ var LorasVar = class LorasVar extends ComfyVar {
1201
1533
  }
1202
1534
  /** tick (true) or untick (false) every lora in `names` (default: all options) */
1203
1535
  setAll(on, names = this.options) {
1204
- const next = { ...this.value };
1536
+ const record = this.record;
1537
+ let next = this.value;
1205
1538
  for (const name of names) {
1206
- const cur = next[name];
1539
+ const cur = record[name];
1207
1540
  if (on) {
1208
- if (cur == null || cur === false) next[name] = this.prev[name] ?? true;
1541
+ if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
1542
+ else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
1209
1543
  } else {
1210
- if (cur != null && cur !== false) this.prev[name] = cur;
1211
- next[name] = false;
1544
+ if (loraIsOn(cur)) this.prev[name] = cur;
1545
+ next = updateLora(next, name, false);
1212
1546
  }
1213
1547
  }
1214
1548
  return this.set(next);
@@ -1257,6 +1591,56 @@ const DEFAULT_SIZE_PRESETS = [
1257
1591
  height: 1344
1258
1592
  }
1259
1593
  ];
1594
+ /** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
1595
+ const SD15_SIZE_PRESETS = [
1596
+ {
1597
+ label: "1:1 square",
1598
+ width: 512,
1599
+ height: 512
1600
+ },
1601
+ {
1602
+ label: "4:3 landscape",
1603
+ width: 576,
1604
+ height: 448
1605
+ },
1606
+ {
1607
+ label: "3:4 portrait",
1608
+ width: 448,
1609
+ height: 576
1610
+ },
1611
+ {
1612
+ label: "3:2 landscape",
1613
+ width: 576,
1614
+ height: 384
1615
+ },
1616
+ {
1617
+ label: "2:3 portrait",
1618
+ width: 384,
1619
+ height: 576
1620
+ },
1621
+ {
1622
+ label: "16:9 widescreen",
1623
+ width: 704,
1624
+ height: 384
1625
+ },
1626
+ {
1627
+ label: "9:16 tall",
1628
+ width: 384,
1629
+ height: 704
1630
+ }
1631
+ ];
1632
+ /** starred presets are one click away in the panel, before the full list */
1633
+ const DEFAULT_STARRED_SIZES = [
1634
+ "1:1 square",
1635
+ "3:4 portrait",
1636
+ "4:3 landscape"
1637
+ ];
1638
+ /** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
1639
+ * and offering it 1024 buckets would be offering sizes it was never trained at */
1640
+ function sizePresetsFor(defaultValue) {
1641
+ if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
1642
+ return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
1643
+ }
1260
1644
  /** width/height picker: presets + free `WxH` entry + optionally the LIVE
1261
1645
  * size of a linked image var (the widget shows
1262
1646
  * `WxH size of image '<name>'` as a pickable row) */
@@ -1264,10 +1648,11 @@ var SizeVar = class extends ComfyVar {
1264
1648
  constructor(defaultValue = {
1265
1649
  width: 1024,
1266
1650
  height: 1024
1267
- }, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
1651
+ }, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
1268
1652
  super(defaultValue, label);
1269
1653
  this.presets = presets;
1270
1654
  this.imageVar = imageVar;
1655
+ this.starred = starred;
1271
1656
  this.kind = "size";
1272
1657
  }
1273
1658
  /** current dimensions of the linked image var — null when no link, unset
@@ -1392,9 +1777,11 @@ const v = {
1392
1777
  * which is what a tuning session wants, and reset()/revert come back to it */
1393
1778
  seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
1394
1779
  toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
1395
- choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
1780
+ /** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
1781
+ * `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
1782
+ choice,
1396
1783
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
1397
- size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
1784
+ size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
1398
1785
  image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
1399
1786
  };
1400
1787
  function varValues(vars) {
@@ -1423,6 +1810,29 @@ var DefinedWorkflow = class {
1423
1810
  varDef.name = key;
1424
1811
  varDef.bindHost?.(this.host);
1425
1812
  }
1813
+ const names = this.entries().map(([key]) => key);
1814
+ 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(", ")})`);
1815
+ }
1816
+ /** every preview for the current var values. A preview that throws, or vars that cannot be
1817
+ * read yet (an image var still empty), give a line saying so instead of failing the others */
1818
+ computePreviews() {
1819
+ const previews = this.spec.previews ?? {};
1820
+ const names = Object.keys(previews);
1821
+ if (names.length === 0) return {};
1822
+ let values;
1823
+ try {
1824
+ values = varValues(this.vars);
1825
+ } catch (e) {
1826
+ const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
1827
+ return Object.fromEntries(names.map((n) => [n, why]));
1828
+ }
1829
+ const out = {};
1830
+ for (const [name, fn] of Object.entries(previews)) try {
1831
+ out[name] = fn(values);
1832
+ } catch (e) {
1833
+ out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
1834
+ }
1835
+ return out;
1426
1836
  }
1427
1837
  /** [name, var] pairs, for drivers that enumerate the knobs */
1428
1838
  entries() {
@@ -1436,12 +1846,15 @@ var DefinedWorkflow = class {
1436
1846
  * build() for copy/export never advances). `p.host` substitutes the host
1437
1847
  * the graph is built against (TUI host override): node/model availability
1438
1848
  * there surfaces as workflow.problems / server validation, by design.
1849
+ * `p.dry` builds a graph only to read it: nothing is uploaded, lastWorkflow is left alone.
1439
1850
  */
1440
1851
  async build(p = {}) {
1441
1852
  const wf = (p.host ?? this.host).workflow({ id: this.spec.id });
1853
+ wf.dry = p.dry === true;
1442
1854
  const values = varValues(this.vars);
1443
1855
  if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
1444
1856
  await this.spec.build(wf.builder, values, wf);
1857
+ if (wf.dry) return wf;
1445
1858
  this.lastWorkflow = wf;
1446
1859
  return wf;
1447
1860
  }
@@ -1567,6 +1980,6 @@ function summarizeDrift(d) {
1567
1980
  return parts.join(", ");
1568
1981
  }
1569
1982
  //#endregion
1570
- export { resolveComfyStorage as $, fetchLoraExampleImages as A, lmSha256 as B, readLoraMirror as C, writeLoraMirror as D, reloadLoraInfoCache as E, lmFilePath as F, loraPreviewMapFrom as G, lmTrainedWords as H, lmFileSize as I, stripAnsi as J, ansi as K, lmFolder as L, fetchLoraPreviewBytes as M, lmBaseModel as N, fetchLoraCivitai as O, lmCivitai as P, getComfyStorage as Q, lmModelName as R, loraMirrorEntries as S, refreshLoraInfoCacheIfChanged as T, loraBasename as U, lmTags as V, loraKey as W, isRecord as X, extractErrorMessage as Y, bang as Z, getLoraInfo as _, DefinedWorkflow as a, sha1Hex as at, getLoraTriggers as b, PromptVar as c, isLoraKeywordFromMirror as d, isQuiet as et, loraKeywordFromMirror as f, getLoraDisplayName as g, getLoraAddedAt as h, summarizeDrift as i, statelessRegex as it, fetchLoraList as j, fetchLoraDescription as k, clearLoraKeywordOverride as l, buildLoraMirror as m, diffSchemas as n, logInfo as nt, DEFAULT_IMAGE_EXTENSIONS as o, sha1HexOfString as ot, setLoraKeyword as p, colorsAvailable as q, driftChanged as r, logSuccess as rt, LorasVar as s, MODEL_LISTS as t, logError as tt, getLoraKeyword as u, getLoraPreviewUrl as v, recordCivitaiMiss as w, loraMatchesFilter as x, getLoraTriggerWords as y, lmNotes as z };
1983
+ export { stripAnsi as $, refreshLoraInfoCacheIfChanged as A, lmFilePath as B, getLoraTriggerWords as C, lorasMissingFromMirror as D, loraMirrorEntries as E, fetchLoraExampleImages as F, lmSha256 as G, lmFolder as H, fetchLoraList as I, loraBasename as J, lmTags as K, fetchLoraPreviewBytes as L, writeLoraMirror as M, fetchLoraCivitai as N, readLoraMirror as O, fetchLoraDescription as P, colorsAvailable as Q, lmBaseModel as R, getLoraPreviewUrl as S, loraMatchesFilter as T, lmModelName as U, lmFileSize as V, lmNotes as W, loraPreviewMapFrom as X, loraKey as Y, ansi as Z, setLoraKeyword as _, DefinedWorkflow as a, isQuiet as at, getLoraDisplayName as b, PromptVar as c, logSuccess as ct, isPromptInput as d, sha1HexOfString as dt, extractErrorMessage as et, isLoraStrength as f, loraKeywordFromMirror as g, isLoraKeywordFromMirror as h, summarizeDrift as i, resolveComfyStorage as it, reloadLoraInfoCache as j, recordCivitaiMiss as k, isLoraLanes as l, statelessRegex as lt, getLoraKeyword as m, diffSchemas as n, bang as nt, DEFAULT_IMAGE_EXTENSIONS as o, logError as ot, clearLoraKeywordOverride as p, lmTrainedWords as q, driftChanged as r, getComfyStorage as rt, LorasVar as s, logInfo as st, MODEL_LISTS as t, isRecord as tt, isLorasInput as u, sha1Hex as ut, buildLoraMirror as v, getLoraTriggers as w, getLoraInfo as x, getLoraAddedAt as y, lmCivitai as z };
1571
1984
 
1572
- //# sourceMappingURL=schemaDrift-DjjEtwfx.js.map
1985
+ //# sourceMappingURL=schemaDrift-E95iTF7E.js.map