comfy-ts 2.10.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.
- package/README.md +1 -0
- package/dist/{LogsSt-DFxzQfDc.js → LogsSt-U1H0mP1m.js} +35 -5
- package/dist/LogsSt-U1H0mP1m.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +565 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +210 -31
- package/dist/index.d.ts +210 -31
- package/dist/index.js +561 -63
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-_nrvJYyt.js → run-serve-BeAznay5.js} +549 -43
- package/dist/run-serve-BeAznay5.js.map +1 -0
- package/dist/{run-tui-Atvf9vb3.js → run-tui-BTGjvnKk.js} +75 -18
- package/dist/run-tui-BTGjvnKk.js.map +1 -0
- package/dist/{DefinedWorkflow-BatWaZO1.js → schemaDrift-Cg39vs53.js} +644 -60
- package/dist/schemaDrift-Cg39vs53.js.map +1 -0
- package/dist/serve-web.js +523 -133
- package/dist/{state-6RFDIQwJ.js → state-C7REnHan.js} +18 -3
- package/dist/{state-6RFDIQwJ.js.map → state-C7REnHan.js.map} +1 -1
- package/dist/web.d.ts +210 -31
- package/dist/web.js +561 -63
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +2 -0
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/07-local-llm-text-gen.cflow.ts +2 -2
- package/examples/rvion/10-anima-t2i.cflow.ts +229 -0
- package/extra/README.md +4 -0
- package/extra/comfyui-fresh-model-lists/README.md +25 -0
- package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
- package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
- package/package.json +17 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +242 -12
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/describeVar.ts +49 -6
- package/src/cli/serve/favicon.ts +3 -0
- package/src/cli/serve/llmConfigShape.ts +51 -0
- package/src/cli/serve/llmConfigs.ts +52 -0
- package/src/cli/serve/tagList.ts +92 -0
- package/src/cli/serve/tagSource.ts +69 -0
- package/src/cli/serve/web/api.ts +60 -0
- package/src/cli/serve/web/components/App.tsx +336 -44
- package/src/cli/serve/web/components/Gallery.tsx +105 -28
- package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
- package/src/cli/serve/web/components/Icon.tsx +18 -2
- package/src/cli/serve/web/components/MenuButton.tsx +53 -0
- package/src/cli/serve/web/components/Omnibox.tsx +85 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
- package/src/cli/serve/web/components/TooltipLayer.tsx +45 -0
- package/src/cli/serve/web/components/VarIcon.tsx +24 -0
- package/src/cli/serve/web/components/VarsForm.tsx +341 -177
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +708 -285
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
- package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
- package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
- package/src/cli/serve/web/components/modKey.ts +2 -0
- package/src/cli/serve/web/llm.ts +23 -12
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +281 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +415 -100
- package/src/cli/serve/web/state/FormSt.ts +193 -29
- package/src/cli/serve/web/state/OmniboxSt.ts +57 -0
- package/src/cli/serve/web/state/WebSt.ts +281 -57
- package/src/cli/serve/web/state/choiceButtons.ts +61 -0
- package/src/cli/serve/web/state/generateButton.ts +16 -0
- package/src/cli/serve/web/state/history.ts +54 -0
- package/src/cli/serve/web/state/host.ts +5 -2
- package/src/cli/serve/web/state/keptLines.ts +53 -0
- package/src/cli/serve/web/state/latentMode.ts +20 -0
- package/src/cli/serve/web/state/loraSort.ts +57 -0
- package/src/cli/serve/web/state/moduleTree.ts +2 -2
- package/src/cli/serve/web/state/omnibox.ts +69 -0
- package/src/cli/serve/web/state/payload.ts +38 -58
- package/src/cli/serve/web/state/shortcuts.ts +54 -0
- package/src/cli/serve/web/state/sizeStars.ts +31 -0
- package/src/cli/serve/web/state/stableSlots.ts +21 -0
- package/src/cli/serve/web/state/varGroups.ts +24 -0
- package/src/cli/serve/web/styles.ts +472 -118
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/tui/components/Header.tsx +2 -0
- package/src/cli/tui/components/PickerOverlays.tsx +9 -2
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
- package/src/cli/tui/state/DraftsSt.ts +18 -2
- package/src/cli/tui/state/EditorSt.ts +1 -1
- package/src/cli/tui/state/HostSt.ts +34 -0
- package/src/cli/tui/state/LorasSt.ts +1 -1
- package/src/cli/tui/state/PickerSt.ts +25 -7
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +10 -0
- package/src/coreExports.ts +20 -0
- package/src/host/ComfyHost.ts +15 -0
- package/src/host/loraInfoCache.ts +70 -0
- package/src/host/loraManagerApi.ts +27 -0
- package/src/host/schemaDrift.ts +87 -0
- package/src/state.ts +5 -0
- package/src/vars/ComfyVars.ts +337 -67
- package/src/vars/DefinedWorkflow.ts +40 -19
- package/src/vars/lanes.ts +238 -0
- package/src/vars/loraEntry.ts +101 -0
- package/src/vars/promptSyntax.ts +382 -0
- package/dist/DefinedWorkflow-BatWaZO1.js.map +0 -1
- package/dist/LogsSt-DFxzQfDc.js.map +0 -1
- package/dist/run-serve-_nrvJYyt.js.map +0 -1
- package/dist/run-tui-Atvf9vb3.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
|
@@ -239,6 +239,11 @@ function lmPreviewUrl(item) {
|
|
|
239
239
|
function lmSha256(item) {
|
|
240
240
|
return readString(item, "sha256");
|
|
241
241
|
}
|
|
242
|
+
/** when the file landed on the host (epoch seconds): the lora manager's own "date added" sort reads it */
|
|
243
|
+
function lmModified(item) {
|
|
244
|
+
const raw = item["modified"];
|
|
245
|
+
return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
246
|
+
}
|
|
242
247
|
function lmFileSize(item) {
|
|
243
248
|
const raw = item["file_size"];
|
|
244
249
|
return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
@@ -292,6 +297,29 @@ function lmItemKey(item) {
|
|
|
292
297
|
}
|
|
293
298
|
/** runaway stop: 20 pages × the server's 100-per-page cap = 2000 loras */
|
|
294
299
|
const MAX_PAGES = 20;
|
|
300
|
+
/** asks the extension to (re)fetch civitai metadata for ONE lora file, trigger words included.
|
|
301
|
+
* The reply says why when civitai has nothing for it (a private or deleted model) */
|
|
302
|
+
async function fetchLoraCivitai(host, filePath) {
|
|
303
|
+
try {
|
|
304
|
+
const res = await host.fetch("/lm/loras/fetch-civitai", {
|
|
305
|
+
method: "POST",
|
|
306
|
+
headers: { "content-type": "application/json" },
|
|
307
|
+
body: JSON.stringify({ file_path: filePath })
|
|
308
|
+
});
|
|
309
|
+
const raw = await res.json().catch(() => null);
|
|
310
|
+
const error = isRecord(raw) && typeof raw["error"] === "string" ? raw["error"] : null;
|
|
311
|
+
if (res.ok && isRecord(raw) && raw["success"] !== false) return { ok: true };
|
|
312
|
+
return {
|
|
313
|
+
ok: false,
|
|
314
|
+
reason: error ?? `the lora manager answered ${res.status}`
|
|
315
|
+
};
|
|
316
|
+
} catch (e) {
|
|
317
|
+
return {
|
|
318
|
+
ok: false,
|
|
319
|
+
reason: extractErrorMessage(e)
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
295
323
|
/** civitai's model description for ONE lora, as PLAIN TEXT. The extension answers html, and
|
|
296
324
|
* html from a third party is never rendered: tags are stripped here, at the seam.
|
|
297
325
|
* null = the extension has no description for it (or does not expose the route) */
|
|
@@ -603,6 +631,52 @@ function getLoraDisplayName(name, hostId) {
|
|
|
603
631
|
const info = getLoraInfo(name, hostId);
|
|
604
632
|
return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
|
|
605
633
|
}
|
|
634
|
+
function loraTriggersOf(item, p = {}) {
|
|
635
|
+
const words = lmTrainedWords(item);
|
|
636
|
+
if (words.length > 0) return {
|
|
637
|
+
state: "words",
|
|
638
|
+
words
|
|
639
|
+
};
|
|
640
|
+
const civitai = item["civitai"];
|
|
641
|
+
if (isRecord(civitai) && (typeof civitai["id"] === "number" || typeof civitai["modelId"] === "number")) return { state: "none" };
|
|
642
|
+
return p.civitaiMiss === true ? { state: "not-on-civitai" } : { state: "unfetched" };
|
|
643
|
+
}
|
|
644
|
+
function getLoraTriggers(name, hostId) {
|
|
645
|
+
const info = getLoraInfo(name, hostId);
|
|
646
|
+
if (info == null) return null;
|
|
647
|
+
const sha = lmSha256(info);
|
|
648
|
+
return loraTriggersOf(info, { civitaiMiss: hostId != null && sha != null && readCivitaiMisses(hostId)[sha] != null });
|
|
649
|
+
}
|
|
650
|
+
function civitaiMissesPath(hostId) {
|
|
651
|
+
return comfyts.resolveFromHosts(join(hostId, "lora-civitai-misses.json"));
|
|
652
|
+
}
|
|
653
|
+
/** sha256 → when civitai said it has no version for that file */
|
|
654
|
+
function readCivitaiMisses(hostId) {
|
|
655
|
+
const text = getComfyStorage().readTextIfExists(civitaiMissesPath(hostId));
|
|
656
|
+
if (text == null) return {};
|
|
657
|
+
try {
|
|
658
|
+
const raw = JSON.parse(text);
|
|
659
|
+
const out = {};
|
|
660
|
+
if (isRecord(raw)) {
|
|
661
|
+
for (const [sha, at] of Object.entries(raw)) if (typeof at === "string") out[sha] = at;
|
|
662
|
+
}
|
|
663
|
+
return out;
|
|
664
|
+
} catch (e) {
|
|
665
|
+
logError(`[loraInfoCache] unreadable ${civitaiMissesPath(hostId)}: ${String(e)}`);
|
|
666
|
+
return {};
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
function recordCivitaiMiss(p) {
|
|
670
|
+
const misses = readCivitaiMisses(p.hostId);
|
|
671
|
+
if (p.miss) misses[p.sha256] = (/* @__PURE__ */ new Date()).toISOString();
|
|
672
|
+
else delete misses[p.sha256];
|
|
673
|
+
getComfyStorage().writeText(civitaiMissesPath(p.hostId), JSON.stringify(misses, null, 2));
|
|
674
|
+
}
|
|
675
|
+
/** when the lora file landed on the host (epoch seconds), null when unsynced/unknown */
|
|
676
|
+
function getLoraAddedAt(name, hostId) {
|
|
677
|
+
const info = getLoraInfo(name, hostId);
|
|
678
|
+
return info == null ? null : lmModified(info);
|
|
679
|
+
}
|
|
606
680
|
/** server-relative preview url from the mirror, null when unsynced/unknown */
|
|
607
681
|
function getLoraPreviewUrl(name, hostId) {
|
|
608
682
|
const info = getLoraInfo(name, hostId);
|
|
@@ -665,6 +739,11 @@ function loraMatchesFilter(name, filter, hostId) {
|
|
|
665
739
|
const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
|
|
666
740
|
return tokens.every((token) => fields.some((field) => field.includes(token)));
|
|
667
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
|
+
}
|
|
668
747
|
//#endregion
|
|
669
748
|
//#region src/vars/loraKeywords.ts
|
|
670
749
|
/**
|
|
@@ -753,6 +832,224 @@ function writeKeywords() {
|
|
|
753
832
|
}
|
|
754
833
|
}
|
|
755
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
|
|
756
1053
|
//#region src/vars/presets.ts
|
|
757
1054
|
function toPresetList(spec) {
|
|
758
1055
|
if (spec == null) return [];
|
|
@@ -763,16 +1060,11 @@ function toPresetList(spec) {
|
|
|
763
1060
|
}
|
|
764
1061
|
//#endregion
|
|
765
1062
|
//#region src/vars/ComfyVars.ts
|
|
766
|
-
/**
|
|
767
|
-
* full base: T is what's STORED/edited, Out what the GRAPH consumes at build
|
|
768
|
-
* time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
|
|
769
|
-
* the one Out-specialized var (string in, PromptValue out); the split keeps
|
|
770
|
-
* outValue() cast-free.
|
|
771
|
-
*/
|
|
772
1063
|
var ComfyVarBase = class {
|
|
773
1064
|
constructor(defaultValue, label) {
|
|
774
1065
|
this.defaultValue = defaultValue;
|
|
775
1066
|
this.label = label;
|
|
1067
|
+
this.uiOpts = {};
|
|
776
1068
|
this.value = defaultValue;
|
|
777
1069
|
makeObservable(this, {
|
|
778
1070
|
value: observable,
|
|
@@ -786,6 +1078,14 @@ var ComfyVarBase = class {
|
|
|
786
1078
|
this.value = value;
|
|
787
1079
|
return this;
|
|
788
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
|
+
}
|
|
789
1089
|
/** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
|
|
790
1090
|
toJSON() {
|
|
791
1091
|
return this.value;
|
|
@@ -833,12 +1133,10 @@ var TextVar = class extends ComfyVar {
|
|
|
833
1133
|
return true;
|
|
834
1134
|
}
|
|
835
1135
|
};
|
|
836
|
-
const commentLineRe = /^\s*\/\//;
|
|
837
|
-
const negativeLineRe = /^\s*- (.*)$/;
|
|
838
1136
|
/**
|
|
839
1137
|
* prompt text with editor comforts, all resolved at BUILD time (the editor and
|
|
840
1138
|
* drafts keep the raw text):
|
|
841
|
-
* - `//`
|
|
1139
|
+
* - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
|
|
842
1140
|
* - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
|
|
843
1141
|
* comma-joined into `.negative`
|
|
844
1142
|
* - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
|
|
@@ -852,38 +1150,48 @@ var PromptVar = class extends ComfyVarBase {
|
|
|
852
1150
|
this.kind = "prompt";
|
|
853
1151
|
this.presets = toPresetList(promptOpts.presets);
|
|
854
1152
|
}
|
|
1153
|
+
/** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
|
|
855
1154
|
parse(raw) {
|
|
856
|
-
this.set(raw);
|
|
1155
|
+
this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
|
|
857
1156
|
return true;
|
|
858
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
|
+
}
|
|
859
1176
|
static isCommentLine(line) {
|
|
860
|
-
return
|
|
1177
|
+
return COMMENT_LINE_RE.test(line);
|
|
861
1178
|
}
|
|
862
1179
|
static isNegativeLine(line) {
|
|
863
|
-
return
|
|
1180
|
+
return NEGATIVE_LINE_RE.test(line);
|
|
864
1181
|
}
|
|
865
1182
|
/** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
|
|
866
1183
|
injectedKeywords() {
|
|
867
1184
|
const src = this.promptOpts.loraKeywordsFrom;
|
|
868
1185
|
if (src == null) return [];
|
|
869
|
-
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 !== ""))];
|
|
870
1187
|
}
|
|
871
1188
|
outValue() {
|
|
872
|
-
const
|
|
873
|
-
const
|
|
874
|
-
for (const line of this.value.split("\n")) {
|
|
875
|
-
if (commentLineRe.test(line)) continue;
|
|
876
|
-
const m = negativeLineRe.exec(line);
|
|
877
|
-
if (m != null) {
|
|
878
|
-
const text = (m[1] ?? "").trim();
|
|
879
|
-
if (text !== "") neg.push(text);
|
|
880
|
-
} else pos.push(line);
|
|
881
|
-
}
|
|
882
|
-
const body = pos.join("\n").trim();
|
|
1189
|
+
const parsed = parsePromptText(this.text);
|
|
1190
|
+
const body = parsed.positive;
|
|
883
1191
|
const keywords = this.injectedKeywords();
|
|
884
1192
|
return {
|
|
885
1193
|
positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
|
|
886
|
-
negative:
|
|
1194
|
+
negative: parsed.negative
|
|
887
1195
|
};
|
|
888
1196
|
}
|
|
889
1197
|
};
|
|
@@ -1023,6 +1331,7 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
1023
1331
|
super(defaultValue, label);
|
|
1024
1332
|
this.choices = choices;
|
|
1025
1333
|
this.kind = "choice";
|
|
1334
|
+
this.select = "one";
|
|
1026
1335
|
}
|
|
1027
1336
|
next(delta = 1) {
|
|
1028
1337
|
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
@@ -1035,13 +1344,102 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
1035
1344
|
return true;
|
|
1036
1345
|
}
|
|
1037
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
|
+
}
|
|
1038
1431
|
/**
|
|
1039
1432
|
* multi-select lora stack over a DYNAMIC options list — a RegExp resolves
|
|
1040
1433
|
* against the host's loras at define time (DefinedWorkflow calls bindHost),
|
|
1041
1434
|
* or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
|
|
1042
1435
|
* a hardcoded inventory. Selection is empty by default.
|
|
1043
1436
|
*/
|
|
1044
|
-
|
|
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 {
|
|
1045
1443
|
constructor(optionsSource, initial = {}, label) {
|
|
1046
1444
|
super(initial, label);
|
|
1047
1445
|
this.optionsSource = optionsSource;
|
|
@@ -1072,49 +1470,57 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
1072
1470
|
get names() {
|
|
1073
1471
|
return [...this.options];
|
|
1074
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
|
+
}
|
|
1075
1491
|
/** loras currently ON (PromptVar keyword prefixing consumes this) */
|
|
1076
1492
|
activeNames() {
|
|
1077
1493
|
return this.names.filter((n) => this.isOn(n));
|
|
1078
1494
|
}
|
|
1079
1495
|
isOn(name) {
|
|
1080
|
-
|
|
1081
|
-
return s != null && s !== false;
|
|
1496
|
+
return loraIsOn(this.record[name]);
|
|
1082
1497
|
}
|
|
1083
1498
|
toggleItem(name) {
|
|
1084
|
-
const cur = this.
|
|
1085
|
-
if (cur == null || cur === false) return this.
|
|
1086
|
-
|
|
1087
|
-
[name]: this.prev[name] ?? true
|
|
1088
|
-
});
|
|
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 }));
|
|
1089
1502
|
this.prev[name] = cur;
|
|
1090
|
-
return this.
|
|
1091
|
-
...this.value,
|
|
1092
|
-
[name]: false
|
|
1093
|
-
});
|
|
1503
|
+
return this.write(name, false);
|
|
1094
1504
|
}
|
|
1095
1505
|
/** step both strengths by delta (true becomes 1 first); no-op when off */
|
|
1096
1506
|
adjustItem(name, delta) {
|
|
1097
|
-
const cur = this.
|
|
1098
|
-
if (cur
|
|
1507
|
+
const cur = this.record[name];
|
|
1508
|
+
if (!loraIsOn(cur)) return this;
|
|
1099
1509
|
const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
|
|
1100
|
-
const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] :
|
|
1101
|
-
return this.
|
|
1102
|
-
...this.value,
|
|
1103
|
-
[name]: next
|
|
1104
|
-
});
|
|
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);
|
|
1105
1512
|
}
|
|
1106
1513
|
/** compact per-item strength label for lists */
|
|
1107
1514
|
strengthLabel(name) {
|
|
1108
|
-
const s = this.
|
|
1109
|
-
if (s
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
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)}`;
|
|
1113
1519
|
}
|
|
1114
1520
|
parse(raw) {
|
|
1115
1521
|
try {
|
|
1116
1522
|
const parsed = JSON.parse(raw);
|
|
1117
|
-
if (
|
|
1523
|
+
if (!isLorasInput(parsed)) return false;
|
|
1118
1524
|
this.set(parsed);
|
|
1119
1525
|
return true;
|
|
1120
1526
|
} catch {
|
|
@@ -1127,14 +1533,16 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
1127
1533
|
}
|
|
1128
1534
|
/** tick (true) or untick (false) every lora in `names` (default: all options) */
|
|
1129
1535
|
setAll(on, names = this.options) {
|
|
1130
|
-
const
|
|
1536
|
+
const record = this.record;
|
|
1537
|
+
let next = this.value;
|
|
1131
1538
|
for (const name of names) {
|
|
1132
|
-
const cur =
|
|
1539
|
+
const cur = record[name];
|
|
1133
1540
|
if (on) {
|
|
1134
|
-
if (cur == null || cur === false) next
|
|
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 }));
|
|
1135
1543
|
} else {
|
|
1136
|
-
if (cur
|
|
1137
|
-
next
|
|
1544
|
+
if (loraIsOn(cur)) this.prev[name] = cur;
|
|
1545
|
+
next = updateLora(next, name, false);
|
|
1138
1546
|
}
|
|
1139
1547
|
}
|
|
1140
1548
|
return this.set(next);
|
|
@@ -1183,6 +1591,56 @@ const DEFAULT_SIZE_PRESETS = [
|
|
|
1183
1591
|
height: 1344
|
|
1184
1592
|
}
|
|
1185
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
|
+
}
|
|
1186
1644
|
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
1187
1645
|
* size of a linked image var (the widget shows
|
|
1188
1646
|
* `WxH size of image '<name>'` as a pickable row) */
|
|
@@ -1190,10 +1648,11 @@ var SizeVar = class extends ComfyVar {
|
|
|
1190
1648
|
constructor(defaultValue = {
|
|
1191
1649
|
width: 1024,
|
|
1192
1650
|
height: 1024
|
|
1193
|
-
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
|
|
1651
|
+
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
|
|
1194
1652
|
super(defaultValue, label);
|
|
1195
1653
|
this.presets = presets;
|
|
1196
1654
|
this.imageVar = imageVar;
|
|
1655
|
+
this.starred = starred;
|
|
1197
1656
|
this.kind = "size";
|
|
1198
1657
|
}
|
|
1199
1658
|
/** current dimensions of the linked image var — null when no link, unset
|
|
@@ -1318,9 +1777,11 @@ const v = {
|
|
|
1318
1777
|
* which is what a tuning session wants, and reset()/revert come back to it */
|
|
1319
1778
|
seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
|
|
1320
1779
|
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
1321
|
-
|
|
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,
|
|
1322
1783
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
1323
|
-
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),
|
|
1324
1785
|
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
|
|
1325
1786
|
};
|
|
1326
1787
|
function varValues(vars) {
|
|
@@ -1349,6 +1810,29 @@ var DefinedWorkflow = class {
|
|
|
1349
1810
|
varDef.name = key;
|
|
1350
1811
|
varDef.bindHost?.(this.host);
|
|
1351
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;
|
|
1352
1836
|
}
|
|
1353
1837
|
/** [name, var] pairs, for drivers that enumerate the knobs */
|
|
1354
1838
|
entries() {
|
|
@@ -1393,6 +1877,106 @@ var DefinedWorkflow = class {
|
|
|
1393
1877
|
}
|
|
1394
1878
|
};
|
|
1395
1879
|
//#endregion
|
|
1396
|
-
|
|
1880
|
+
//#region src/host/schemaDrift.ts
|
|
1881
|
+
/**
|
|
1882
|
+
* what changed on a host since a schema was loaded: node types, and the model files each loader
|
|
1883
|
+
* lists. ComfyUI exposes no boot time, so staleness is decided by CONTENT: a restart that changed
|
|
1884
|
+
* nothing stays quiet, a new lora shows even when nobody knows when the box rebooted.
|
|
1885
|
+
* A light check asks only the loaders (`/object_info/<node>`, a few KB); a full one compares every
|
|
1886
|
+
* node type (`/object_info`, megabytes).
|
|
1887
|
+
*/
|
|
1888
|
+
/** the loader inputs whose combo IS a model folder listing */
|
|
1889
|
+
const MODEL_LISTS = [
|
|
1890
|
+
{
|
|
1891
|
+
noun: "lora",
|
|
1892
|
+
node: "LoraLoader",
|
|
1893
|
+
input: "lora_name"
|
|
1894
|
+
},
|
|
1895
|
+
{
|
|
1896
|
+
noun: "checkpoint",
|
|
1897
|
+
node: "CheckpointLoaderSimple",
|
|
1898
|
+
input: "ckpt_name"
|
|
1899
|
+
},
|
|
1900
|
+
{
|
|
1901
|
+
noun: "unet",
|
|
1902
|
+
node: "UNETLoader",
|
|
1903
|
+
input: "unet_name"
|
|
1904
|
+
},
|
|
1905
|
+
{
|
|
1906
|
+
noun: "text encoder",
|
|
1907
|
+
node: "CLIPLoader",
|
|
1908
|
+
input: "clip_name"
|
|
1909
|
+
},
|
|
1910
|
+
{
|
|
1911
|
+
noun: "vae",
|
|
1912
|
+
node: "VAELoader",
|
|
1913
|
+
input: "vae_name"
|
|
1914
|
+
}
|
|
1915
|
+
];
|
|
1916
|
+
/** a combo's options in both object_info spellings: `[[...options]]` and `['COMBO', { options }]` */
|
|
1917
|
+
function comboOptions(spec, node, input) {
|
|
1918
|
+
const def = spec[node];
|
|
1919
|
+
if (!isRecord(def) || !isRecord(def["input"])) return null;
|
|
1920
|
+
const sections = def["input"];
|
|
1921
|
+
for (const section of ["required", "optional"]) {
|
|
1922
|
+
const sec = sections[section];
|
|
1923
|
+
if (!isRecord(sec)) continue;
|
|
1924
|
+
const slot = sec[input];
|
|
1925
|
+
if (!Array.isArray(slot)) continue;
|
|
1926
|
+
const first = slot[0];
|
|
1927
|
+
if (Array.isArray(first)) return first.filter((x) => typeof x === "string");
|
|
1928
|
+
const opts = slot[1];
|
|
1929
|
+
if (first === "COMBO" && isRecord(opts) && Array.isArray(opts["options"])) return opts["options"].filter((x) => typeof x === "string");
|
|
1930
|
+
}
|
|
1931
|
+
return null;
|
|
1932
|
+
}
|
|
1933
|
+
function delta(before, after) {
|
|
1934
|
+
const was = new Set(before);
|
|
1935
|
+
const now = new Set(after);
|
|
1936
|
+
return {
|
|
1937
|
+
added: after.filter((x) => !was.has(x)),
|
|
1938
|
+
removed: before.filter((x) => !now.has(x))
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
/** `live` may be PARTIAL (a light check holds only the loaders): a list is compared only where both
|
|
1942
|
+
* sides have the loader, and node types only when `full` */
|
|
1943
|
+
function diffSchemas(p) {
|
|
1944
|
+
const models = [];
|
|
1945
|
+
for (const m of MODEL_LISTS) {
|
|
1946
|
+
const before = comboOptions(p.loaded, m.node, m.input);
|
|
1947
|
+
const after = comboOptions(p.live, m.node, m.input);
|
|
1948
|
+
if (before == null || after == null) continue;
|
|
1949
|
+
const d = delta(before, after);
|
|
1950
|
+
if (d.added.length > 0 || d.removed.length > 0) models.push({
|
|
1951
|
+
noun: m.noun,
|
|
1952
|
+
...d
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
return {
|
|
1956
|
+
nodes: p.full ? delta(Object.keys(p.loaded), Object.keys(p.live)) : null,
|
|
1957
|
+
models
|
|
1958
|
+
};
|
|
1959
|
+
}
|
|
1960
|
+
function driftChanged(d) {
|
|
1961
|
+
return d.models.length > 0 || d.nodes != null && (d.nodes.added.length > 0 || d.nodes.removed.length > 0);
|
|
1962
|
+
}
|
|
1963
|
+
/** `+5 loras, -1 unet, +4 node types`, '' when nothing changed */
|
|
1964
|
+
function summarizeDrift(d) {
|
|
1965
|
+
const parts = [];
|
|
1966
|
+
const say = (n, sign, noun) => {
|
|
1967
|
+
if (n > 0) parts.push(`${sign}${n} ${noun}${n === 1 ? "" : "s"}`);
|
|
1968
|
+
};
|
|
1969
|
+
for (const m of d.models) {
|
|
1970
|
+
say(m.added.length, "+", m.noun);
|
|
1971
|
+
say(m.removed.length, "-", m.noun);
|
|
1972
|
+
}
|
|
1973
|
+
if (d.nodes != null) {
|
|
1974
|
+
say(d.nodes.added.length, "+", "node type");
|
|
1975
|
+
say(d.nodes.removed.length, "-", "node type");
|
|
1976
|
+
}
|
|
1977
|
+
return parts.join(", ");
|
|
1978
|
+
}
|
|
1979
|
+
//#endregion
|
|
1980
|
+
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 };
|
|
1397
1981
|
|
|
1398
|
-
//# sourceMappingURL=
|
|
1982
|
+
//# sourceMappingURL=schemaDrift-Cg39vs53.js.map
|