comfy-ts 2.3.0 → 2.4.1
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 +13 -0
- package/dist/{DefinedWorkflow-CwHInZgn.js → DefinedWorkflow-QrhT6V66.js} +441 -9
- package/dist/DefinedWorkflow-QrhT6V66.js.map +1 -0
- package/dist/{DraftsSt-omWuBSej.js → DraftsSt-D9Fhk4qR.js} +2 -2
- package/dist/{DraftsSt-omWuBSej.js.map → DraftsSt-D9Fhk4qR.js.map} +1 -1
- package/dist/cli.js +116 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +268 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +150 -9
- package/dist/index.d.ts +150 -9
- package/dist/index.js +257 -24
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-CfzOH-AR.js → run-serve-C9E8dyLP.js} +3 -3
- package/dist/run-serve-C9E8dyLP.js.map +1 -0
- package/dist/{run-tui-_LD0DoGe.js → run-tui-8si-rVW0.js} +60 -121
- package/dist/run-tui-8si-rVW0.js.map +1 -0
- package/dist/{state-C-OOEcp3.js → state-C0ARiFFM.js} +15 -76
- package/dist/state-C0ARiFFM.js.map +1 -0
- package/dist/web.d.ts +150 -9
- package/dist/web.js +257 -24
- package/dist/web.js.map +1 -1
- package/guide-for-agents.md +3 -0
- package/package.json +2 -1
- package/src/cli/comfy-ts-cli.ts +16 -1
- package/src/cli/flags.ts +14 -0
- package/src/cli/gen.ts +2 -4
- package/src/cli/loras.ts +113 -0
- package/src/cli/serve/applyVarPayload.ts +1 -1
- package/src/cli/tui/components/LorasOverlay.tsx +18 -5
- package/src/cli/tui/components/StatusBar.tsx +1 -0
- package/src/cli/tui/components/TuiApp.tsx +1 -0
- package/src/cli/tui/imageClipboard.ts +3 -3
- package/src/cli/tui/protocolImagePainter.ts +1 -1
- package/src/cli/tui/run-tui.tsx +2 -2
- package/src/cli/tui/state/ExecSt.ts +2 -2
- package/src/cli/tui/state/HostSt.ts +1 -1
- package/src/cli/tui/state/LorasSt.ts +60 -15
- package/src/cli/tui/state/PreviewSt.ts +1 -1
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/coreExports.ts +20 -1
- package/src/host/ComfyHost.ts +10 -1
- package/src/host/ResilientWebsocket.ts +20 -0
- package/src/host/loraInfoCache.ts +216 -0
- package/src/host/loraManagerApi.ts +131 -27
- package/src/runner/ComfyExecution.ts +1 -1
- package/src/runner/outputPath.ts +3 -3
- package/src/utils/isRecord.ts +4 -0
- package/src/vars/ComfyVars.ts +13 -7
- package/src/vars/loraKeywords.ts +48 -5
- package/dist/DefinedWorkflow-CwHInZgn.js.map +0 -1
- package/dist/run-serve-CfzOH-AR.js.map +0 -1
- package/dist/run-tui-_LD0DoGe.js.map +0 -1
- package/dist/state-C-OOEcp3.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -110,7 +110,7 @@ function createNodeStorage() {
|
|
|
110
110
|
}
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region package.json
|
|
113
|
-
var version = "2.
|
|
113
|
+
var version = "2.4.1";
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
116
116
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -742,7 +742,7 @@ const ComfyDefaultNodeWhenUnknown_Schema = {
|
|
|
742
742
|
};
|
|
743
743
|
//#endregion
|
|
744
744
|
//#region src/sdk-generator/inputWidgetKind.ts
|
|
745
|
-
const isRecord = (x) => typeof x === "object" && x != null && !Array.isArray(x);
|
|
745
|
+
const isRecord$1 = (x) => typeof x === "object" && x != null && !Array.isArray(x);
|
|
746
746
|
/**
|
|
747
747
|
* seed phantom: a TRUTHY `control_after_generate` adds one consumed value.
|
|
748
748
|
* The frontend creates the control widget on truthiness, and real 2026 hosts
|
|
@@ -759,7 +759,7 @@ const flattenInputSections = (inputs) => {
|
|
|
759
759
|
const out = [];
|
|
760
760
|
for (const section of ["required", "optional"]) {
|
|
761
761
|
const sec = inputs[section];
|
|
762
|
-
if (!isRecord(sec)) continue;
|
|
762
|
+
if (!isRecord$1(sec)) continue;
|
|
763
763
|
for (const [name, spec] of Object.entries(sec)) {
|
|
764
764
|
if (!Array.isArray(spec) || spec.length === 0) continue;
|
|
765
765
|
const t = spec[0];
|
|
@@ -779,10 +779,10 @@ const parseDynamicOptions = (options) => {
|
|
|
779
779
|
if (options.length === 0) return null;
|
|
780
780
|
const out = [];
|
|
781
781
|
for (const entry of options) {
|
|
782
|
-
if (!isRecord(entry)) return null;
|
|
782
|
+
if (!isRecord$1(entry)) return null;
|
|
783
783
|
const key = entry["key"];
|
|
784
784
|
const inputs = entry["inputs"];
|
|
785
|
-
if (typeof key !== "string" || !isRecord(inputs)) return null;
|
|
785
|
+
if (typeof key !== "string" || !isRecord$1(inputs)) return null;
|
|
786
786
|
out.push({
|
|
787
787
|
key,
|
|
788
788
|
inputs: flattenInputSections(inputs)
|
|
@@ -806,7 +806,7 @@ const parseContainer = (template) => {
|
|
|
806
806
|
return {
|
|
807
807
|
kind: "dynamic-container",
|
|
808
808
|
instanceNames: names,
|
|
809
|
-
requiredCount: isRecord(input) && isRecord(input["required"]) && Object.keys(input["required"]).length > 0 ? Math.min(min, names.length) : 0
|
|
809
|
+
requiredCount: isRecord$1(input) && isRecord$1(input["required"]) && Object.keys(input["required"]).length > 0 ? Math.min(min, names.length) : 0
|
|
810
810
|
};
|
|
811
811
|
};
|
|
812
812
|
/**
|
|
@@ -817,8 +817,8 @@ const parseContainer = (template) => {
|
|
|
817
817
|
* typed instance keys and the container stays builderBase territory.
|
|
818
818
|
*/
|
|
819
819
|
const containerInstanceSlotType = (opts) => {
|
|
820
|
-
const template = (isRecord(opts) ? opts : null)?.["template"];
|
|
821
|
-
if (!isRecord(template) || !isRecord(template["input"])) return null;
|
|
820
|
+
const template = (isRecord$1(opts) ? opts : null)?.["template"];
|
|
821
|
+
if (!isRecord$1(template) || !isRecord$1(template["input"])) return null;
|
|
822
822
|
const subs = flattenInputSections(template["input"]);
|
|
823
823
|
const first = subs[0];
|
|
824
824
|
if (subs.length !== 1 || first == null || typeof first.type !== "string") return null;
|
|
@@ -844,7 +844,7 @@ const EMPTY_CONFIG_FRONTEND_WIDGETS = { LOAD_3D: { prefixValues: [
|
|
|
844
844
|
"clear"
|
|
845
845
|
] } };
|
|
846
846
|
const classifyWidgetInput = (p) => {
|
|
847
|
-
const o = isRecord(p.opts) ? p.opts : null;
|
|
847
|
+
const o = isRecord$1(p.opts) ? p.opts : null;
|
|
848
848
|
if (o?.["forceInput"] === true) return { kind: "slot" };
|
|
849
849
|
if (Array.isArray(p.type) || p.isEnumUnion === true) {
|
|
850
850
|
const tn = typeof p.type === "string" ? p.type : "COMBO";
|
|
@@ -883,8 +883,8 @@ const classifyWidgetInput = (p) => {
|
|
|
883
883
|
};
|
|
884
884
|
}
|
|
885
885
|
const template = o?.["template"];
|
|
886
|
-
if (isRecord(template)) {
|
|
887
|
-
if (isRecord(template["input"])) return parseContainer(template);
|
|
886
|
+
if (isRecord$1(template)) {
|
|
887
|
+
if (isRecord$1(template["input"])) return parseContainer(template);
|
|
888
888
|
return { kind: "slot" };
|
|
889
889
|
}
|
|
890
890
|
if (o?.["socketless"] === true) return {
|
|
@@ -915,7 +915,7 @@ const classifySchemaInput = (input) => classifyWidgetInput({
|
|
|
915
915
|
* backend accepts an explicit null but errors on an ABSENT required key.
|
|
916
916
|
*/
|
|
917
917
|
const defaultValueForWidget = (p) => {
|
|
918
|
-
const o = isRecord(p.opts) ? p.opts : null;
|
|
918
|
+
const o = isRecord$1(p.opts) ? p.opts : null;
|
|
919
919
|
if (o != null && o["default"] !== void 0) return o["default"];
|
|
920
920
|
const widgetTypeName = typeof o?.["widgetType"] === "string" ? o["widgetType"] : p.type;
|
|
921
921
|
if (widgetTypeName === "INT" || widgetTypeName === "FLOAT") return 0;
|
|
@@ -1006,7 +1006,7 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
1006
1006
|
if (value == null) return null;
|
|
1007
1007
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
|
|
1008
1008
|
if (Array.isArray(value)) return { __value__: value };
|
|
1009
|
-
if (!p.strict && isRecord(value)) return value;
|
|
1009
|
+
if (!p.strict && isRecord$1(value)) return value;
|
|
1010
1010
|
throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}) has an invalid widget value for "${p.promptName}": ${JSON.stringify(value)}`, node);
|
|
1011
1011
|
};
|
|
1012
1012
|
/** named wins, then positional cursor (+prefixLen skips leading button values, LOAD_3D); filled=true when both miss (caller falls back to the schema default) */
|
|
@@ -1657,8 +1657,8 @@ var LiteGraphCtx = class {
|
|
|
1657
1657
|
//#endregion
|
|
1658
1658
|
//#region src/runner/outputPath.ts
|
|
1659
1659
|
/**
|
|
1660
|
-
* local output naming, relative to `.comfy-ts/outputs
|
|
1661
|
-
*
|
|
1660
|
+
* local output naming, relative to `.comfy-ts/outputs/`:
|
|
1661
|
+
* the server filename is NOT unique — cloud hosts reset the
|
|
1662
1662
|
* `_00001_` counter every run, so trusting it overwrote the same file — and
|
|
1663
1663
|
* a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
|
|
1664
1664
|
* prefix. Local names are ours: dir from the prompt's own filename_prefix
|
|
@@ -1703,7 +1703,7 @@ const withExtension = (path, ext) => {
|
|
|
1703
1703
|
/**
|
|
1704
1704
|
* never-overwrite guard: bump `-2`, `-3`, … while the path exists on disk OR
|
|
1705
1705
|
* was already CLAIMED by a still-downloading retrieval (two same-second runs
|
|
1706
|
-
* on a counter-resetting cloud host compute the same name
|
|
1706
|
+
* on a counter-resetting cloud host compute the same name).
|
|
1707
1707
|
* The chosen path is claimed before returning.
|
|
1708
1708
|
*/
|
|
1709
1709
|
const uniquifyOutputPath = (p) => {
|
|
@@ -3811,6 +3811,7 @@ var ResilientWebSocketClient = class {
|
|
|
3811
3811
|
this.messageBuffer = [];
|
|
3812
3812
|
this.isOpen = false;
|
|
3813
3813
|
this.debugMessages = [];
|
|
3814
|
+
this.hasEverOpened = false;
|
|
3814
3815
|
this.permanentlyClosed = false;
|
|
3815
3816
|
this.url = options.url();
|
|
3816
3817
|
this.connect();
|
|
@@ -3862,6 +3863,7 @@ var ResilientWebSocketClient = class {
|
|
|
3862
3863
|
ws.onopen = () => {
|
|
3863
3864
|
if (ws !== this.currentWS) return;
|
|
3864
3865
|
this.addInfo("✅ WebSocket connected to " + this.url);
|
|
3866
|
+
this.hasEverOpened = true;
|
|
3865
3867
|
this.isOpen = true;
|
|
3866
3868
|
this.options.onConnectOrReconnect();
|
|
3867
3869
|
this.flushMessageBuffer();
|
|
@@ -3872,6 +3874,11 @@ var ResilientWebSocketClient = class {
|
|
|
3872
3874
|
this.options.onClose();
|
|
3873
3875
|
if (this.permanentlyClosed) return;
|
|
3874
3876
|
this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
|
|
3877
|
+
if (!this.hasEverOpened && this.options.onFirstConnectFailed != null) {
|
|
3878
|
+
this.permanentlyClosed = true;
|
|
3879
|
+
this.options.onFirstConnectFailed(/* @__PURE__ */ new Error(`connection refused (code=${event.code}${event.reason === "" ? "" : `, ${event.reason}`})`));
|
|
3880
|
+
return;
|
|
3881
|
+
}
|
|
3875
3882
|
this.addInfo("⏱️ reconnecting in 2 seconds...");
|
|
3876
3883
|
this.reconnectTimeout = setTimeout(() => void this.connect(), 2e3);
|
|
3877
3884
|
};
|
|
@@ -3893,6 +3900,191 @@ var ResilientWebSocketClient = class {
|
|
|
3893
3900
|
}
|
|
3894
3901
|
};
|
|
3895
3902
|
//#endregion
|
|
3903
|
+
//#region src/utils/isRecord.ts
|
|
3904
|
+
/** narrows unknown wire json to an indexable object (arrays and null excluded) */
|
|
3905
|
+
function isRecord(v) {
|
|
3906
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3907
|
+
}
|
|
3908
|
+
type({
|
|
3909
|
+
items: "unknown[]",
|
|
3910
|
+
"total?": "number"
|
|
3911
|
+
});
|
|
3912
|
+
function readString(item, key) {
|
|
3913
|
+
const v = item[key];
|
|
3914
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
3915
|
+
}
|
|
3916
|
+
function readStringArray(item, key) {
|
|
3917
|
+
const v = item[key];
|
|
3918
|
+
if (!Array.isArray(v)) return [];
|
|
3919
|
+
return v.filter((x) => typeof x === "string" && x !== "");
|
|
3920
|
+
}
|
|
3921
|
+
function lmModelName(item) {
|
|
3922
|
+
return readString(item, "model_name");
|
|
3923
|
+
}
|
|
3924
|
+
function lmBaseModel(item) {
|
|
3925
|
+
return readString(item, "base_model");
|
|
3926
|
+
}
|
|
3927
|
+
function lmPreviewUrl(item) {
|
|
3928
|
+
return readString(item, "preview_url");
|
|
3929
|
+
}
|
|
3930
|
+
function lmTags(item) {
|
|
3931
|
+
return readStringArray(item, "tags");
|
|
3932
|
+
}
|
|
3933
|
+
/** the trigger words: civitai's `trainedWords`, absent for a lora nobody published */
|
|
3934
|
+
function lmTrainedWords(item) {
|
|
3935
|
+
const civitai = item["civitai"];
|
|
3936
|
+
if (!isRecord(civitai)) return [];
|
|
3937
|
+
return readStringArray(civitai, "trainedWords");
|
|
3938
|
+
}
|
|
3939
|
+
/**
|
|
3940
|
+
* the ONE key space where a host's object_info spelling of a lora meets
|
|
3941
|
+
* lora-manager's: lowercase, forward slashes, no model extension.
|
|
3942
|
+
* `styles\Aurora.safetensors` and lm's folder `styles` + file_name `aurora`
|
|
3943
|
+
* both become `styles/aurora`.
|
|
3944
|
+
*/
|
|
3945
|
+
function loraKey(name) {
|
|
3946
|
+
return name.replaceAll("\\", "/").replace(/\.(safetensors|st|pt|ckpt)$/i, "").toLowerCase();
|
|
3947
|
+
}
|
|
3948
|
+
/** the file's own name, windows separators included (`styles\x.safetensors` → `x.safetensors`) */
|
|
3949
|
+
function loraBasename(name) {
|
|
3950
|
+
return basename(name.replaceAll("\\", "/"));
|
|
3951
|
+
}
|
|
3952
|
+
//#endregion
|
|
3953
|
+
//#region src/host/loraInfoCache.ts
|
|
3954
|
+
function loraMirrorPath(hostId) {
|
|
3955
|
+
return comfyts.resolveFromHosts(join(hostId, "loras.json"));
|
|
3956
|
+
}
|
|
3957
|
+
/** null = never synced (or unreadable, which is LOGGED) */
|
|
3958
|
+
function readLoraMirror(hostId) {
|
|
3959
|
+
const path = loraMirrorPath(hostId);
|
|
3960
|
+
const text = getComfyStorage().readTextIfExists(path);
|
|
3961
|
+
if (text == null) return null;
|
|
3962
|
+
try {
|
|
3963
|
+
const raw = JSON.parse(text);
|
|
3964
|
+
if (!isRecord(raw)) return null;
|
|
3965
|
+
const rawLoras = raw["loras"];
|
|
3966
|
+
if (!isRecord(rawLoras)) return null;
|
|
3967
|
+
const loras = {};
|
|
3968
|
+
for (const [key, item] of Object.entries(rawLoras)) if (isRecord(item)) loras[key] = item;
|
|
3969
|
+
const str = (key, fallback) => {
|
|
3970
|
+
const v = raw[key];
|
|
3971
|
+
return typeof v === "string" ? v : fallback;
|
|
3972
|
+
};
|
|
3973
|
+
return {
|
|
3974
|
+
hostId: str("hostId", hostId),
|
|
3975
|
+
hostUrl: str("hostUrl", ""),
|
|
3976
|
+
fetchedAt: str("fetchedAt", ""),
|
|
3977
|
+
count: Object.keys(loras).length,
|
|
3978
|
+
loras
|
|
3979
|
+
};
|
|
3980
|
+
} catch (e) {
|
|
3981
|
+
logError(`[loraInfoCache] unreadable ${path}: ${String(e)}`);
|
|
3982
|
+
return null;
|
|
3983
|
+
}
|
|
3984
|
+
}
|
|
3985
|
+
/**
|
|
3986
|
+
* the read model: each registered host's mirror, kept PER HOST.
|
|
3987
|
+
*
|
|
3988
|
+
* Per host, not merged into one map, because the same file name on two hosts is
|
|
3989
|
+
* routinely a different model. A merged map served whichever host loaded first,
|
|
3990
|
+
* so on the other host the overlay showed the wrong model name and the prompt
|
|
3991
|
+
* silently received the wrong trigger words — a bad generation with no error
|
|
3992
|
+
* anywhere. Callers that know their host say so; the rest fall back to any host
|
|
3993
|
+
* that has the lora, which is still better than nothing for a display name.
|
|
3994
|
+
*
|
|
3995
|
+
* Plain (non-observable) on purpose: the loras overlay reads this from inside a
|
|
3996
|
+
* mobx render. The storage seam has no readdir, so the host set comes from
|
|
3997
|
+
* `comfyts.hosts` — exactly the hosts this process can be asked about.
|
|
3998
|
+
*/
|
|
3999
|
+
const byHost = /* @__PURE__ */ new Map();
|
|
4000
|
+
/** hosts already looked for, INCLUDING the ones with no mirror (see reloadLoraInfoCache) */
|
|
4001
|
+
const loadedHostIds = /* @__PURE__ */ new Set();
|
|
4002
|
+
function ensureLoaded() {
|
|
4003
|
+
for (const hostId of comfyts.hosts.keys()) {
|
|
4004
|
+
if (loadedHostIds.has(hostId)) continue;
|
|
4005
|
+
loadedHostIds.add(hostId);
|
|
4006
|
+
const mirror = readLoraMirror(hostId);
|
|
4007
|
+
if (mirror == null) continue;
|
|
4008
|
+
byHost.set(hostId, new Map(Object.entries(mirror.loras)));
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
/**
|
|
4012
|
+
* forget everything loaded, so the next read picks up a fresh `comfy-ts loras`.
|
|
4013
|
+
* A long-lived process (the TUI, `comfy-ts serve`) has no other way to see a
|
|
4014
|
+
* re-sync that happened in another terminal.
|
|
4015
|
+
*/
|
|
4016
|
+
function reloadLoraInfoCache() {
|
|
4017
|
+
byHost.clear();
|
|
4018
|
+
loadedHostIds.clear();
|
|
4019
|
+
}
|
|
4020
|
+
/**
|
|
4021
|
+
* the lm item for a raw lora name (`styles\x.safetensors`).
|
|
4022
|
+
* `hostId` picks the mirror that actually describes this host's file; without
|
|
4023
|
+
* it, any host that knows the name answers. null when unsynced/unknown.
|
|
4024
|
+
*/
|
|
4025
|
+
function getLoraInfo(name, hostId) {
|
|
4026
|
+
ensureLoaded();
|
|
4027
|
+
const key = loraKey(name);
|
|
4028
|
+
if (hostId != null) {
|
|
4029
|
+
const own = byHost.get(hostId);
|
|
4030
|
+
if (own != null) return own.get(key) ?? null;
|
|
4031
|
+
}
|
|
4032
|
+
for (const mirror of byHost.values()) {
|
|
4033
|
+
const hit = mirror.get(key);
|
|
4034
|
+
if (hit != null) return hit;
|
|
4035
|
+
}
|
|
4036
|
+
return null;
|
|
4037
|
+
}
|
|
4038
|
+
/** civitai trigger words for this lora, in civitai's order */
|
|
4039
|
+
function getLoraTriggerWords(name, hostId) {
|
|
4040
|
+
const info = getLoraInfo(name, hostId);
|
|
4041
|
+
return info == null ? [] : lmTrainedWords(info);
|
|
4042
|
+
}
|
|
4043
|
+
/** the human name (`Aurora Ink Wash`), falling back to the file's own name */
|
|
4044
|
+
function getLoraDisplayName(name, hostId) {
|
|
4045
|
+
const info = getLoraInfo(name, hostId);
|
|
4046
|
+
return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
|
|
4047
|
+
}
|
|
4048
|
+
/** server-relative preview url from the mirror, null when unsynced/unknown */
|
|
4049
|
+
function getLoraPreviewUrl(name, hostId) {
|
|
4050
|
+
const info = getLoraInfo(name, hostId);
|
|
4051
|
+
return info == null ? null : lmPreviewUrl(info);
|
|
4052
|
+
}
|
|
4053
|
+
/** the lora's NAMES: the file, and the model name a human would call it by */
|
|
4054
|
+
function loraSearchNames(name, hostId) {
|
|
4055
|
+
const names = [loraBasename(name), name.replaceAll("\\", "/")];
|
|
4056
|
+
const info = getLoraInfo(name, hostId);
|
|
4057
|
+
const modelName = info == null ? null : lmModelName(info);
|
|
4058
|
+
if (modelName != null) names.push(modelName);
|
|
4059
|
+
return names;
|
|
4060
|
+
}
|
|
4061
|
+
/** the lora's FREE TEXT: tags, base model, trigger words */
|
|
4062
|
+
function loraSearchText(name, hostId) {
|
|
4063
|
+
const info = getLoraInfo(name, hostId);
|
|
4064
|
+
if (info == null) return [];
|
|
4065
|
+
const text = [...lmTags(info), ...lmTrainedWords(info)];
|
|
4066
|
+
const baseModel = lmBaseModel(info);
|
|
4067
|
+
if (baseModel != null) text.push(baseModel);
|
|
4068
|
+
return text;
|
|
4069
|
+
}
|
|
4070
|
+
/**
|
|
4071
|
+
* the loras overlay filter: find a lora by its human name, not only by the file
|
|
4072
|
+
* name. EVERY whitespace-separated token must be a SUBSTRING of some field — order
|
|
4073
|
+
* free, so `aurora ink`, `ink aurora` and `styles wash` all land on the same
|
|
4074
|
+
* lora. NOT fuzzyMatch: a subsequence match over phrases this long matches
|
|
4075
|
+
* nearly everything. Measured on a real collection, filtering by each lora's
|
|
4076
|
+
* own file name: this rule peaks at 8 hits where fuzzyMatch matched a third of
|
|
4077
|
+
* every lora present.
|
|
4078
|
+
* Fields are matched one by one, never as a concatenated haystack, for the same
|
|
4079
|
+
* reason. `tests/lora-corpus.private.test.ts` keeps that measurement runnable.
|
|
4080
|
+
*/
|
|
4081
|
+
function loraMatchesFilter(name, filter, hostId) {
|
|
4082
|
+
const tokens = filter.toLowerCase().split(/\s+/).filter((t) => t !== "");
|
|
4083
|
+
if (tokens.length === 0) return true;
|
|
4084
|
+
const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
|
|
4085
|
+
return tokens.every((token) => fields.some((field) => field.includes(token)));
|
|
4086
|
+
}
|
|
4087
|
+
//#endregion
|
|
3896
4088
|
//#region src/vars/loraKeywords.ts
|
|
3897
4089
|
/**
|
|
3898
4090
|
* hand-assigned trigger keyword(s) per lora name — set via ⌃K in the TUI loras
|
|
@@ -3900,6 +4092,12 @@ var ResilientWebSocketClient = class {
|
|
|
3900
4092
|
* `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data
|
|
3901
4093
|
* and must survive a cache wipe). Observable map: overlay rows re-render on
|
|
3902
4094
|
* assignment. Keys are the RAW lora names (folder/file.safetensors).
|
|
4095
|
+
*
|
|
4096
|
+
* This file is the OVERRIDE layer. Below it sits the lora-manager mirror's
|
|
4097
|
+
* civitai trigger words (src/host/loraInfoCache.ts, refreshed by
|
|
4098
|
+
* `comfy-ts loras`), so most loras carry a keyword without anyone typing one.
|
|
4099
|
+
* The overlay renders a mirror-sourced keyword dim and a hand-typed one yellow,
|
|
4100
|
+
* and ⌃D drops the override to fall back to the mirror again.
|
|
3903
4101
|
*/
|
|
3904
4102
|
const keywords = observable.map();
|
|
3905
4103
|
let loaded = false;
|
|
@@ -3922,18 +4120,50 @@ function loadOnce() {
|
|
|
3922
4120
|
logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
|
|
3923
4121
|
}
|
|
3924
4122
|
}
|
|
3925
|
-
|
|
4123
|
+
/** the hand keyword when this lora HAS an entry (`''` included), else the mirror's trigger words */
|
|
4124
|
+
function getLoraKeyword(name, hostId) {
|
|
3926
4125
|
loadOnce();
|
|
3927
|
-
|
|
4126
|
+
const hand = keywords.get(name);
|
|
4127
|
+
if (hand != null) return hand;
|
|
4128
|
+
return getLoraTriggerWords(name, hostId).join(", ");
|
|
3928
4129
|
}
|
|
3929
|
-
/**
|
|
3930
|
-
function
|
|
4130
|
+
/** true when the keyword shown comes from the lora-manager mirror, not from ⌃K */
|
|
4131
|
+
function isLoraKeywordFromMirror(name, hostId) {
|
|
4132
|
+
loadOnce();
|
|
4133
|
+
return !keywords.has(name) && getLoraTriggerWords(name, hostId).length > 0;
|
|
4134
|
+
}
|
|
4135
|
+
/** what `clearLoraKeywordOverride` would restore this lora to, `''` when nothing */
|
|
4136
|
+
function loraKeywordFromMirror(name, hostId) {
|
|
4137
|
+
return getLoraTriggerWords(name, hostId).join(", ");
|
|
4138
|
+
}
|
|
4139
|
+
/**
|
|
4140
|
+
* drop the hand entry entirely, so the mirror's trigger words apply again.
|
|
4141
|
+
* The way BACK from an empty-string tombstone: without it, clearing a keyword on
|
|
4142
|
+
* a lora that has trigger words was a one-way door only a text editor could undo.
|
|
4143
|
+
*/
|
|
4144
|
+
function clearLoraKeywordOverride(name) {
|
|
4145
|
+
loadOnce();
|
|
4146
|
+
if (!keywords.has(name)) return;
|
|
4147
|
+
runInAction(() => void keywords.delete(name));
|
|
4148
|
+
writeKeywords();
|
|
4149
|
+
}
|
|
4150
|
+
/**
|
|
4151
|
+
* empty keyword deletes the entry — EXCEPT when the mirror has trigger words for
|
|
4152
|
+
* this lora: there `''` is stored as an explicit tombstone, the only way to say
|
|
4153
|
+
* "inject nothing" about a lora civitai gave words to. Every set writes the file
|
|
4154
|
+
* (tiny, rare).
|
|
4155
|
+
*/
|
|
4156
|
+
function setLoraKeyword(name, keyword, hostId) {
|
|
3931
4157
|
loadOnce();
|
|
3932
4158
|
const trimmed = keyword.trim();
|
|
3933
4159
|
runInAction(() => {
|
|
3934
|
-
if (trimmed === "") keywords.delete(name);
|
|
4160
|
+
if (trimmed === "" && getLoraTriggerWords(name, hostId).length === 0) keywords.delete(name);
|
|
3935
4161
|
else keywords.set(name, trimmed);
|
|
3936
4162
|
});
|
|
4163
|
+
writeKeywords();
|
|
4164
|
+
}
|
|
4165
|
+
/** every set writes the file: it is tiny and hand-edited rarely */
|
|
4166
|
+
function writeKeywords() {
|
|
3937
4167
|
const path = filePath();
|
|
3938
4168
|
try {
|
|
3939
4169
|
getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
|
|
@@ -4040,7 +4270,7 @@ var PromptVar = class extends ComfyVarBase {
|
|
|
4040
4270
|
injectedKeywords() {
|
|
4041
4271
|
const src = this.promptOpts.loraKeywordsFrom;
|
|
4042
4272
|
if (src == null) return [];
|
|
4043
|
-
return [...new Set(src.activeNames().map(getLoraKeyword).filter((k) => k !== ""))];
|
|
4273
|
+
return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
|
|
4044
4274
|
}
|
|
4045
4275
|
outValue() {
|
|
4046
4276
|
const pos = [];
|
|
@@ -4232,6 +4462,7 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4232
4462
|
this.kind = "loras";
|
|
4233
4463
|
this.prev = {};
|
|
4234
4464
|
this.resolvedOptions = null;
|
|
4465
|
+
this.hostId = void 0;
|
|
4235
4466
|
}
|
|
4236
4467
|
get options() {
|
|
4237
4468
|
if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
|
|
@@ -4242,6 +4473,7 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4242
4473
|
* cast: whitelist family 1 (agent/coding.md) — getLoras() returns the runtime
|
|
4243
4474
|
* values of the SAME object_info enum the generated E_LoraName union comes from */
|
|
4244
4475
|
bindHost(host) {
|
|
4476
|
+
this.hostId = host.data?.id;
|
|
4245
4477
|
if (!(this.optionsSource instanceof RegExp)) return;
|
|
4246
4478
|
this.resolvedOptions = host.schema.getLoras(this.optionsSource);
|
|
4247
4479
|
}
|
|
@@ -4360,7 +4592,7 @@ const DEFAULT_SIZE_PRESETS = [
|
|
|
4360
4592
|
}
|
|
4361
4593
|
];
|
|
4362
4594
|
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
4363
|
-
* size of a linked image var (
|
|
4595
|
+
* size of a linked image var (the widget shows
|
|
4364
4596
|
* `WxH size of image '<name>'` as a pickable row) */
|
|
4365
4597
|
var SizeVar = class extends ComfyVar {
|
|
4366
4598
|
constructor(defaultValue = {
|
|
@@ -4960,6 +5192,7 @@ var ComfyHost = class {
|
|
|
4960
5192
|
url: () => this.getWSUrl(),
|
|
4961
5193
|
headers: () => this.authHeaders(),
|
|
4962
5194
|
onTransportDead: (e) => this.markFailed(e),
|
|
5195
|
+
onFirstConnectFailed: (e) => this.markFailed(new ComfyHostUnreachableError(`host '${this.data.id}' is not reachable at ${this.getWSUrl()} — ${extractErrorMessage(e)}. Is ComfyUI running there ?`)),
|
|
4963
5196
|
onClose: () => {
|
|
4964
5197
|
logInfo(`[👢] WEBSOCKET: closed connection to ComfyUI host ${this.data.id}`);
|
|
4965
5198
|
}
|
|
@@ -5814,6 +6047,6 @@ function isTuiActive() {
|
|
|
5814
6047
|
*/
|
|
5815
6048
|
setDefaultComfyStorage(createNodeStorage());
|
|
5816
6049
|
//#endregion
|
|
5817
|
-
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, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, getComfyStorage, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
|
|
6050
|
+
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, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, isTuiActive, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
|
|
5818
6051
|
|
|
5819
6052
|
//# sourceMappingURL=index.js.map
|