comfy-ts 2.3.0 → 2.4.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 +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 +260 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +132 -9
- package/dist/index.d.ts +132 -9
- package/dist/index.js +249 -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-cawSJuuh.js} +60 -121
- package/dist/run-tui-cawSJuuh.js.map +1 -0
- package/dist/{state-C-OOEcp3.js → state-BbKuSDCV.js} +7 -76
- package/dist/state-BbKuSDCV.js.map +1 -0
- package/dist/web.d.ts +132 -9
- package/dist/web.js +249 -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 +1 -1
- 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.0";
|
|
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) => {
|
|
@@ -3893,6 +3893,191 @@ var ResilientWebSocketClient = class {
|
|
|
3893
3893
|
}
|
|
3894
3894
|
};
|
|
3895
3895
|
//#endregion
|
|
3896
|
+
//#region src/utils/isRecord.ts
|
|
3897
|
+
/** narrows unknown wire json to an indexable object (arrays and null excluded) */
|
|
3898
|
+
function isRecord(v) {
|
|
3899
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3900
|
+
}
|
|
3901
|
+
type({
|
|
3902
|
+
items: "unknown[]",
|
|
3903
|
+
"total?": "number"
|
|
3904
|
+
});
|
|
3905
|
+
function readString(item, key) {
|
|
3906
|
+
const v = item[key];
|
|
3907
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
3908
|
+
}
|
|
3909
|
+
function readStringArray(item, key) {
|
|
3910
|
+
const v = item[key];
|
|
3911
|
+
if (!Array.isArray(v)) return [];
|
|
3912
|
+
return v.filter((x) => typeof x === "string" && x !== "");
|
|
3913
|
+
}
|
|
3914
|
+
function lmModelName(item) {
|
|
3915
|
+
return readString(item, "model_name");
|
|
3916
|
+
}
|
|
3917
|
+
function lmBaseModel(item) {
|
|
3918
|
+
return readString(item, "base_model");
|
|
3919
|
+
}
|
|
3920
|
+
function lmPreviewUrl(item) {
|
|
3921
|
+
return readString(item, "preview_url");
|
|
3922
|
+
}
|
|
3923
|
+
function lmTags(item) {
|
|
3924
|
+
return readStringArray(item, "tags");
|
|
3925
|
+
}
|
|
3926
|
+
/** the trigger words: civitai's `trainedWords`, absent for a lora nobody published */
|
|
3927
|
+
function lmTrainedWords(item) {
|
|
3928
|
+
const civitai = item["civitai"];
|
|
3929
|
+
if (!isRecord(civitai)) return [];
|
|
3930
|
+
return readStringArray(civitai, "trainedWords");
|
|
3931
|
+
}
|
|
3932
|
+
/**
|
|
3933
|
+
* the ONE key space where a host's object_info spelling of a lora meets
|
|
3934
|
+
* lora-manager's: lowercase, forward slashes, no model extension.
|
|
3935
|
+
* `styles\Aurora.safetensors` and lm's folder `styles` + file_name `aurora`
|
|
3936
|
+
* both become `styles/aurora`.
|
|
3937
|
+
*/
|
|
3938
|
+
function loraKey(name) {
|
|
3939
|
+
return name.replaceAll("\\", "/").replace(/\.(safetensors|st|pt|ckpt)$/i, "").toLowerCase();
|
|
3940
|
+
}
|
|
3941
|
+
/** the file's own name, windows separators included (`styles\x.safetensors` → `x.safetensors`) */
|
|
3942
|
+
function loraBasename(name) {
|
|
3943
|
+
return basename(name.replaceAll("\\", "/"));
|
|
3944
|
+
}
|
|
3945
|
+
//#endregion
|
|
3946
|
+
//#region src/host/loraInfoCache.ts
|
|
3947
|
+
function loraMirrorPath(hostId) {
|
|
3948
|
+
return comfyts.resolveFromHosts(join(hostId, "loras.json"));
|
|
3949
|
+
}
|
|
3950
|
+
/** null = never synced (or unreadable, which is LOGGED) */
|
|
3951
|
+
function readLoraMirror(hostId) {
|
|
3952
|
+
const path = loraMirrorPath(hostId);
|
|
3953
|
+
const text = getComfyStorage().readTextIfExists(path);
|
|
3954
|
+
if (text == null) return null;
|
|
3955
|
+
try {
|
|
3956
|
+
const raw = JSON.parse(text);
|
|
3957
|
+
if (!isRecord(raw)) return null;
|
|
3958
|
+
const rawLoras = raw["loras"];
|
|
3959
|
+
if (!isRecord(rawLoras)) return null;
|
|
3960
|
+
const loras = {};
|
|
3961
|
+
for (const [key, item] of Object.entries(rawLoras)) if (isRecord(item)) loras[key] = item;
|
|
3962
|
+
const str = (key, fallback) => {
|
|
3963
|
+
const v = raw[key];
|
|
3964
|
+
return typeof v === "string" ? v : fallback;
|
|
3965
|
+
};
|
|
3966
|
+
return {
|
|
3967
|
+
hostId: str("hostId", hostId),
|
|
3968
|
+
hostUrl: str("hostUrl", ""),
|
|
3969
|
+
fetchedAt: str("fetchedAt", ""),
|
|
3970
|
+
count: Object.keys(loras).length,
|
|
3971
|
+
loras
|
|
3972
|
+
};
|
|
3973
|
+
} catch (e) {
|
|
3974
|
+
logError(`[loraInfoCache] unreadable ${path}: ${String(e)}`);
|
|
3975
|
+
return null;
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
/**
|
|
3979
|
+
* the read model: each registered host's mirror, kept PER HOST.
|
|
3980
|
+
*
|
|
3981
|
+
* Per host, not merged into one map, because the same file name on two hosts is
|
|
3982
|
+
* routinely a different model. A merged map served whichever host loaded first,
|
|
3983
|
+
* so on the other host the overlay showed the wrong model name and the prompt
|
|
3984
|
+
* silently received the wrong trigger words — a bad generation with no error
|
|
3985
|
+
* anywhere. Callers that know their host say so; the rest fall back to any host
|
|
3986
|
+
* that has the lora, which is still better than nothing for a display name.
|
|
3987
|
+
*
|
|
3988
|
+
* Plain (non-observable) on purpose: the loras overlay reads this from inside a
|
|
3989
|
+
* mobx render. The storage seam has no readdir, so the host set comes from
|
|
3990
|
+
* `comfyts.hosts` — exactly the hosts this process can be asked about.
|
|
3991
|
+
*/
|
|
3992
|
+
const byHost = /* @__PURE__ */ new Map();
|
|
3993
|
+
/** hosts already looked for, INCLUDING the ones with no mirror (see reloadLoraInfoCache) */
|
|
3994
|
+
const loadedHostIds = /* @__PURE__ */ new Set();
|
|
3995
|
+
function ensureLoaded() {
|
|
3996
|
+
for (const hostId of comfyts.hosts.keys()) {
|
|
3997
|
+
if (loadedHostIds.has(hostId)) continue;
|
|
3998
|
+
loadedHostIds.add(hostId);
|
|
3999
|
+
const mirror = readLoraMirror(hostId);
|
|
4000
|
+
if (mirror == null) continue;
|
|
4001
|
+
byHost.set(hostId, new Map(Object.entries(mirror.loras)));
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
/**
|
|
4005
|
+
* forget everything loaded, so the next read picks up a fresh `comfy-ts loras`.
|
|
4006
|
+
* A long-lived process (the TUI, `comfy-ts serve`) has no other way to see a
|
|
4007
|
+
* re-sync that happened in another terminal.
|
|
4008
|
+
*/
|
|
4009
|
+
function reloadLoraInfoCache() {
|
|
4010
|
+
byHost.clear();
|
|
4011
|
+
loadedHostIds.clear();
|
|
4012
|
+
}
|
|
4013
|
+
/**
|
|
4014
|
+
* the lm item for a raw lora name (`styles\x.safetensors`).
|
|
4015
|
+
* `hostId` picks the mirror that actually describes this host's file; without
|
|
4016
|
+
* it, any host that knows the name answers. null when unsynced/unknown.
|
|
4017
|
+
*/
|
|
4018
|
+
function getLoraInfo(name, hostId) {
|
|
4019
|
+
ensureLoaded();
|
|
4020
|
+
const key = loraKey(name);
|
|
4021
|
+
if (hostId != null) {
|
|
4022
|
+
const own = byHost.get(hostId);
|
|
4023
|
+
if (own != null) return own.get(key) ?? null;
|
|
4024
|
+
}
|
|
4025
|
+
for (const mirror of byHost.values()) {
|
|
4026
|
+
const hit = mirror.get(key);
|
|
4027
|
+
if (hit != null) return hit;
|
|
4028
|
+
}
|
|
4029
|
+
return null;
|
|
4030
|
+
}
|
|
4031
|
+
/** civitai trigger words for this lora, in civitai's order */
|
|
4032
|
+
function getLoraTriggerWords(name, hostId) {
|
|
4033
|
+
const info = getLoraInfo(name, hostId);
|
|
4034
|
+
return info == null ? [] : lmTrainedWords(info);
|
|
4035
|
+
}
|
|
4036
|
+
/** the human name (`Aurora Ink Wash`), falling back to the file's own name */
|
|
4037
|
+
function getLoraDisplayName(name, hostId) {
|
|
4038
|
+
const info = getLoraInfo(name, hostId);
|
|
4039
|
+
return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
|
|
4040
|
+
}
|
|
4041
|
+
/** server-relative preview url from the mirror, null when unsynced/unknown */
|
|
4042
|
+
function getLoraPreviewUrl(name, hostId) {
|
|
4043
|
+
const info = getLoraInfo(name, hostId);
|
|
4044
|
+
return info == null ? null : lmPreviewUrl(info);
|
|
4045
|
+
}
|
|
4046
|
+
/** the lora's NAMES: the file, and the model name a human would call it by */
|
|
4047
|
+
function loraSearchNames(name, hostId) {
|
|
4048
|
+
const names = [loraBasename(name), name.replaceAll("\\", "/")];
|
|
4049
|
+
const info = getLoraInfo(name, hostId);
|
|
4050
|
+
const modelName = info == null ? null : lmModelName(info);
|
|
4051
|
+
if (modelName != null) names.push(modelName);
|
|
4052
|
+
return names;
|
|
4053
|
+
}
|
|
4054
|
+
/** the lora's FREE TEXT: tags, base model, trigger words */
|
|
4055
|
+
function loraSearchText(name, hostId) {
|
|
4056
|
+
const info = getLoraInfo(name, hostId);
|
|
4057
|
+
if (info == null) return [];
|
|
4058
|
+
const text = [...lmTags(info), ...lmTrainedWords(info)];
|
|
4059
|
+
const baseModel = lmBaseModel(info);
|
|
4060
|
+
if (baseModel != null) text.push(baseModel);
|
|
4061
|
+
return text;
|
|
4062
|
+
}
|
|
4063
|
+
/**
|
|
4064
|
+
* the loras overlay filter: find a lora by its human name, not only by the file
|
|
4065
|
+
* name. EVERY whitespace-separated token must be a SUBSTRING of some field — order
|
|
4066
|
+
* free, so `aurora ink`, `ink aurora` and `styles wash` all land on the same
|
|
4067
|
+
* lora. NOT fuzzyMatch: a subsequence match over phrases this long matches
|
|
4068
|
+
* nearly everything. Measured on a real collection, filtering by each lora's
|
|
4069
|
+
* own file name: this rule peaks at 8 hits where fuzzyMatch matched a third of
|
|
4070
|
+
* every lora present.
|
|
4071
|
+
* Fields are matched one by one, never as a concatenated haystack, for the same
|
|
4072
|
+
* reason. `tests/lora-corpus.private.test.ts` keeps that measurement runnable.
|
|
4073
|
+
*/
|
|
4074
|
+
function loraMatchesFilter(name, filter, hostId) {
|
|
4075
|
+
const tokens = filter.toLowerCase().split(/\s+/).filter((t) => t !== "");
|
|
4076
|
+
if (tokens.length === 0) return true;
|
|
4077
|
+
const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
|
|
4078
|
+
return tokens.every((token) => fields.some((field) => field.includes(token)));
|
|
4079
|
+
}
|
|
4080
|
+
//#endregion
|
|
3896
4081
|
//#region src/vars/loraKeywords.ts
|
|
3897
4082
|
/**
|
|
3898
4083
|
* hand-assigned trigger keyword(s) per lora name — set via ⌃K in the TUI loras
|
|
@@ -3900,6 +4085,12 @@ var ResilientWebSocketClient = class {
|
|
|
3900
4085
|
* `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data
|
|
3901
4086
|
* and must survive a cache wipe). Observable map: overlay rows re-render on
|
|
3902
4087
|
* assignment. Keys are the RAW lora names (folder/file.safetensors).
|
|
4088
|
+
*
|
|
4089
|
+
* This file is the OVERRIDE layer. Below it sits the lora-manager mirror's
|
|
4090
|
+
* civitai trigger words (src/host/loraInfoCache.ts, refreshed by
|
|
4091
|
+
* `comfy-ts loras`), so most loras carry a keyword without anyone typing one.
|
|
4092
|
+
* The overlay renders a mirror-sourced keyword dim and a hand-typed one yellow,
|
|
4093
|
+
* and ⌃D drops the override to fall back to the mirror again.
|
|
3903
4094
|
*/
|
|
3904
4095
|
const keywords = observable.map();
|
|
3905
4096
|
let loaded = false;
|
|
@@ -3922,18 +4113,50 @@ function loadOnce() {
|
|
|
3922
4113
|
logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
|
|
3923
4114
|
}
|
|
3924
4115
|
}
|
|
3925
|
-
|
|
4116
|
+
/** the hand keyword when this lora HAS an entry (`''` included), else the mirror's trigger words */
|
|
4117
|
+
function getLoraKeyword(name, hostId) {
|
|
3926
4118
|
loadOnce();
|
|
3927
|
-
|
|
4119
|
+
const hand = keywords.get(name);
|
|
4120
|
+
if (hand != null) return hand;
|
|
4121
|
+
return getLoraTriggerWords(name, hostId).join(", ");
|
|
3928
4122
|
}
|
|
3929
|
-
/**
|
|
3930
|
-
function
|
|
4123
|
+
/** true when the keyword shown comes from the lora-manager mirror, not from ⌃K */
|
|
4124
|
+
function isLoraKeywordFromMirror(name, hostId) {
|
|
4125
|
+
loadOnce();
|
|
4126
|
+
return !keywords.has(name) && getLoraTriggerWords(name, hostId).length > 0;
|
|
4127
|
+
}
|
|
4128
|
+
/** what `clearLoraKeywordOverride` would restore this lora to, `''` when nothing */
|
|
4129
|
+
function loraKeywordFromMirror(name, hostId) {
|
|
4130
|
+
return getLoraTriggerWords(name, hostId).join(", ");
|
|
4131
|
+
}
|
|
4132
|
+
/**
|
|
4133
|
+
* drop the hand entry entirely, so the mirror's trigger words apply again.
|
|
4134
|
+
* The way BACK from an empty-string tombstone: without it, clearing a keyword on
|
|
4135
|
+
* a lora that has trigger words was a one-way door only a text editor could undo.
|
|
4136
|
+
*/
|
|
4137
|
+
function clearLoraKeywordOverride(name) {
|
|
4138
|
+
loadOnce();
|
|
4139
|
+
if (!keywords.has(name)) return;
|
|
4140
|
+
runInAction(() => void keywords.delete(name));
|
|
4141
|
+
writeKeywords();
|
|
4142
|
+
}
|
|
4143
|
+
/**
|
|
4144
|
+
* empty keyword deletes the entry — EXCEPT when the mirror has trigger words for
|
|
4145
|
+
* this lora: there `''` is stored as an explicit tombstone, the only way to say
|
|
4146
|
+
* "inject nothing" about a lora civitai gave words to. Every set writes the file
|
|
4147
|
+
* (tiny, rare).
|
|
4148
|
+
*/
|
|
4149
|
+
function setLoraKeyword(name, keyword, hostId) {
|
|
3931
4150
|
loadOnce();
|
|
3932
4151
|
const trimmed = keyword.trim();
|
|
3933
4152
|
runInAction(() => {
|
|
3934
|
-
if (trimmed === "") keywords.delete(name);
|
|
4153
|
+
if (trimmed === "" && getLoraTriggerWords(name, hostId).length === 0) keywords.delete(name);
|
|
3935
4154
|
else keywords.set(name, trimmed);
|
|
3936
4155
|
});
|
|
4156
|
+
writeKeywords();
|
|
4157
|
+
}
|
|
4158
|
+
/** every set writes the file: it is tiny and hand-edited rarely */
|
|
4159
|
+
function writeKeywords() {
|
|
3937
4160
|
const path = filePath();
|
|
3938
4161
|
try {
|
|
3939
4162
|
getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
|
|
@@ -4040,7 +4263,7 @@ var PromptVar = class extends ComfyVarBase {
|
|
|
4040
4263
|
injectedKeywords() {
|
|
4041
4264
|
const src = this.promptOpts.loraKeywordsFrom;
|
|
4042
4265
|
if (src == null) return [];
|
|
4043
|
-
return [...new Set(src.activeNames().map(getLoraKeyword).filter((k) => k !== ""))];
|
|
4266
|
+
return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
|
|
4044
4267
|
}
|
|
4045
4268
|
outValue() {
|
|
4046
4269
|
const pos = [];
|
|
@@ -4232,6 +4455,7 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4232
4455
|
this.kind = "loras";
|
|
4233
4456
|
this.prev = {};
|
|
4234
4457
|
this.resolvedOptions = null;
|
|
4458
|
+
this.hostId = void 0;
|
|
4235
4459
|
}
|
|
4236
4460
|
get options() {
|
|
4237
4461
|
if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
|
|
@@ -4242,6 +4466,7 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4242
4466
|
* cast: whitelist family 1 (agent/coding.md) — getLoras() returns the runtime
|
|
4243
4467
|
* values of the SAME object_info enum the generated E_LoraName union comes from */
|
|
4244
4468
|
bindHost(host) {
|
|
4469
|
+
this.hostId = host.data?.id;
|
|
4245
4470
|
if (!(this.optionsSource instanceof RegExp)) return;
|
|
4246
4471
|
this.resolvedOptions = host.schema.getLoras(this.optionsSource);
|
|
4247
4472
|
}
|
|
@@ -4360,7 +4585,7 @@ const DEFAULT_SIZE_PRESETS = [
|
|
|
4360
4585
|
}
|
|
4361
4586
|
];
|
|
4362
4587
|
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
4363
|
-
* size of a linked image var (
|
|
4588
|
+
* size of a linked image var (the widget shows
|
|
4364
4589
|
* `WxH size of image '<name>'` as a pickable row) */
|
|
4365
4590
|
var SizeVar = class extends ComfyVar {
|
|
4366
4591
|
constructor(defaultValue = {
|
|
@@ -5814,6 +6039,6 @@ function isTuiActive() {
|
|
|
5814
6039
|
*/
|
|
5815
6040
|
setDefaultComfyStorage(createNodeStorage());
|
|
5816
6041
|
//#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 };
|
|
6042
|
+
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
6043
|
|
|
5819
6044
|
//# sourceMappingURL=index.js.map
|