comfy-ts 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/{LogsSt-qtFzOKpu.js → LogsSt-CUeo843w.js} +51 -7
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +595 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +286 -46
- package/dist/index.d.ts +286 -46
- package/dist/index.js +591 -74
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BK7BA2dn.js → run-serve-DlRBv_Nk.js} +738 -58
- package/dist/run-serve-DlRBv_Nk.js.map +1 -0
- package/dist/{run-tui-CQyvMf0N.js → run-tui-B5uxm2_l.js} +43 -18
- package/dist/run-tui-B5uxm2_l.js.map +1 -0
- package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-E95iTF7E.js} +473 -60
- package/dist/schemaDrift-E95iTF7E.js.map +1 -0
- package/dist/serve-web.js +710 -174
- package/dist/{state--wrz0BQc.js → state-CUp2J1Zy.js} +126 -14
- package/dist/state-CUp2J1Zy.js.map +1 -0
- package/dist/web.d.ts +286 -46
- package/dist/web.js +591 -74
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/10-anima-t2i.cflow.ts +252 -0
- package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
- package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
- package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
- package/examples/rvion/stableAudio3Prompts.ts +19 -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 +15 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +305 -30
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/describeVar.ts +42 -6
- package/src/cli/serve/llmConfigShape.ts +51 -0
- package/src/cli/serve/llmConfigs.ts +52 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/tagList.ts +92 -0
- package/src/cli/serve/tagSource.ts +69 -0
- package/src/cli/serve/web/api.ts +72 -0
- package/src/cli/serve/web/components/App.tsx +485 -44
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +133 -31
- package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
- package/src/cli/serve/web/components/Icon.tsx +58 -2
- package/src/cli/serve/web/components/MenuButton.tsx +53 -0
- package/src/cli/serve/web/components/Omnibox.tsx +135 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
- package/src/cli/serve/web/components/SideMenu.tsx +414 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +46 -0
- package/src/cli/serve/web/components/VarIcon.tsx +24 -0
- package/src/cli/serve/web/components/VarsForm.tsx +223 -351
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +646 -317
- 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 +284 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +431 -101
- package/src/cli/serve/web/state/FormSt.ts +214 -30
- package/src/cli/serve/web/state/OmniboxSt.ts +59 -0
- package/src/cli/serve/web/state/WebSt.ts +364 -80
- package/src/cli/serve/web/state/choiceButtons.ts +61 -0
- package/src/cli/serve/web/state/draftNames.ts +16 -0
- package/src/cli/serve/web/state/draftTabs.ts +75 -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 +18 -0
- package/src/cli/serve/web/state/moduleTree.ts +2 -2
- package/src/cli/serve/web/state/omnibox.ts +133 -0
- package/src/cli/serve/web/state/payload.ts +38 -58
- package/src/cli/serve/web/state/shortcuts.ts +103 -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 +653 -154
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -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 +28 -8
- package/src/cli/tui/state/EditorSt.ts +1 -1
- 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 +21 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- package/src/host/loraInfoCache.ts +6 -0
- package/src/runner/ComfyExecution.ts +60 -0
- package/src/runner/ComfyWorkflow.ts +4 -0
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/MediaImage.ts +2 -2
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
- package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
- package/src/state.ts +5 -0
- package/src/utils/copyName.ts +12 -0
- package/src/vars/ComfyVars.ts +337 -67
- package/src/vars/DefinedWorkflow.ts +47 -20
- package/src/vars/lanes.ts +238 -0
- package/src/vars/loraEntry.ts +101 -0
- package/src/vars/promptSyntax.ts +382 -0
- package/dist/LogsSt-qtFzOKpu.js.map +0 -1
- package/dist/run-serve-BK7BA2dn.js.map +0 -1
- package/dist/run-tui-CQyvMf0N.js.map +0 -1
- package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
- package/dist/state--wrz0BQc.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
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.13.0";
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
116
116
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -2016,6 +2016,7 @@ const types$1 = scope({
|
|
|
2016
2016
|
output: {
|
|
2017
2017
|
"previews?": [{ filepath: "string" }, "[]"],
|
|
2018
2018
|
"images?": "ComfyImageInfo[]",
|
|
2019
|
+
"audio?": "ComfyImageInfo[]",
|
|
2019
2020
|
"text?": "unknown[]"
|
|
2020
2021
|
},
|
|
2021
2022
|
prompt_id: "PromptID"
|
|
@@ -2116,11 +2117,11 @@ var MediaImage = class MediaImage {
|
|
|
2116
2117
|
});
|
|
2117
2118
|
};
|
|
2118
2119
|
this.loadInWorkflow_viaLoadImageNode = async (workflow) => {
|
|
2119
|
-
const enumName = await this.uploadAndReturnEnumName(workflow.host);
|
|
2120
|
+
const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
|
|
2120
2121
|
return bang(workflow.builderBase.LoadImage, "host has no LoadImage node")({ image: enumName });
|
|
2121
2122
|
};
|
|
2122
2123
|
this.loadInWorkflowAsMask_viaLoadImageMask = async (channel, workflow) => {
|
|
2123
|
-
const enumName = await this.uploadAndReturnEnumName(workflow.host);
|
|
2124
|
+
const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
|
|
2124
2125
|
return bang(workflow.builderBase.LoadImageMask, "host has no LoadImageMask node")({
|
|
2125
2126
|
image: enumName,
|
|
2126
2127
|
channel
|
|
@@ -2268,6 +2269,18 @@ var MediaImage = class MediaImage {
|
|
|
2268
2269
|
* A claim is released as soon as the write lands (the file itself then holds
|
|
2269
2270
|
* the name) or fails (the name is free again) — the set never accumulates */
|
|
2270
2271
|
const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
|
|
2272
|
+
const AUDIO_MIMES = {
|
|
2273
|
+
flac: "audio/flac",
|
|
2274
|
+
mp3: "audio/mpeg",
|
|
2275
|
+
opus: "audio/ogg",
|
|
2276
|
+
ogg: "audio/ogg",
|
|
2277
|
+
wav: "audio/wav",
|
|
2278
|
+
m4a: "audio/mp4"
|
|
2279
|
+
};
|
|
2280
|
+
function audioMime(filename) {
|
|
2281
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
|
2282
|
+
return AUDIO_MIMES[ext] ?? "application/octet-stream";
|
|
2283
|
+
}
|
|
2271
2284
|
var ComfyExecution = class {
|
|
2272
2285
|
get host() {
|
|
2273
2286
|
return this.workflow.host;
|
|
@@ -2342,8 +2355,51 @@ var ComfyExecution = class {
|
|
|
2342
2355
|
error: e
|
|
2343
2356
|
});
|
|
2344
2357
|
}));
|
|
2358
|
+
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveAudio(audio, promptNodeID).catch((e) => {
|
|
2359
|
+
console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
|
|
2360
|
+
this.audioErrors.push({
|
|
2361
|
+
audio,
|
|
2362
|
+
error: e
|
|
2363
|
+
});
|
|
2364
|
+
}));
|
|
2345
2365
|
};
|
|
2346
2366
|
this.pendingPromises = [];
|
|
2367
|
+
this.audioErrors = [];
|
|
2368
|
+
this.audios = [];
|
|
2369
|
+
this.retrieveAudio = async (info, promptNodeID) => {
|
|
2370
|
+
const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
|
|
2371
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2372
|
+
const mime = audioMime(info.filename);
|
|
2373
|
+
const sf = this.save;
|
|
2374
|
+
if (sf == null) {
|
|
2375
|
+
this.audios.push({
|
|
2376
|
+
nodeId: promptNodeID,
|
|
2377
|
+
filename: info.filename,
|
|
2378
|
+
mime,
|
|
2379
|
+
bytes,
|
|
2380
|
+
absPath: null
|
|
2381
|
+
});
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2384
|
+
const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs["filename_prefix"];
|
|
2385
|
+
const written = await this.encodeAndWrite({
|
|
2386
|
+
bytes,
|
|
2387
|
+
sf: {
|
|
2388
|
+
...sf,
|
|
2389
|
+
format: "raw"
|
|
2390
|
+
},
|
|
2391
|
+
filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
|
|
2392
|
+
subfolder: info.subfolder,
|
|
2393
|
+
filename: info.filename
|
|
2394
|
+
});
|
|
2395
|
+
this.audios.push({
|
|
2396
|
+
nodeId: promptNodeID,
|
|
2397
|
+
filename: info.filename,
|
|
2398
|
+
mime,
|
|
2399
|
+
bytes,
|
|
2400
|
+
absPath: written.path
|
|
2401
|
+
});
|
|
2402
|
+
};
|
|
2347
2403
|
this.imageErrors = [];
|
|
2348
2404
|
this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
|
|
2349
2405
|
const promptNode = this.workflow.data.apiJson?.[promptNodeID];
|
|
@@ -2515,6 +2571,7 @@ var ComfyExecution = class {
|
|
|
2515
2571
|
if (!this.logProgress) return;
|
|
2516
2572
|
const p = this.progress;
|
|
2517
2573
|
const outputs = [`${this.images.length} image(s)`];
|
|
2574
|
+
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
|
|
2518
2575
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
|
|
2519
2576
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
|
|
2520
2577
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
@@ -2745,6 +2802,7 @@ var ComfyWorkflow = class {
|
|
|
2745
2802
|
constructor(host, data) {
|
|
2746
2803
|
this.host = host;
|
|
2747
2804
|
this.data = data;
|
|
2805
|
+
this.dry = false;
|
|
2748
2806
|
this.nodes = [];
|
|
2749
2807
|
this.registerNode = (node) => {
|
|
2750
2808
|
if (this.data.apiJson == null) throw new Error("graph not hydrated");
|
|
@@ -3242,7 +3300,7 @@ function codegenSDK(opts) {
|
|
|
3242
3300
|
p("}");
|
|
3243
3301
|
p(`interface Builder {`);
|
|
3244
3302
|
for (const n of nodes) {
|
|
3245
|
-
const baseDescription = `displayName="${n.raw.display_name}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
|
|
3303
|
+
const baseDescription = `displayName="${n.raw.display_name ?? n.nameInComfy}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
|
|
3246
3304
|
if (n.raw.description) {
|
|
3247
3305
|
p(` /**`);
|
|
3248
3306
|
p(n.raw.description.split("\n").map((i) => ` * ${i}`).join("\n"));
|
|
@@ -3596,16 +3654,16 @@ const types = scope({
|
|
|
3596
3654
|
"hidden?": "string[]"
|
|
3597
3655
|
},
|
|
3598
3656
|
output: "ComfyInputType[]",
|
|
3599
|
-
output_is_list: "boolean[]",
|
|
3657
|
+
output_is_list: "(boolean | null)[]",
|
|
3600
3658
|
output_name: "string[]",
|
|
3601
3659
|
name: "string",
|
|
3602
|
-
display_name: "string",
|
|
3660
|
+
display_name: "string | null",
|
|
3603
3661
|
description: "string",
|
|
3604
3662
|
/** */
|
|
3605
3663
|
python_module: "string",
|
|
3606
3664
|
category: "string",
|
|
3607
3665
|
output_node: "boolean",
|
|
3608
|
-
"output_tooltips?": "string[]",
|
|
3666
|
+
"output_tooltips?": "(string | null)[]",
|
|
3609
3667
|
"deprecated?": "boolean",
|
|
3610
3668
|
"experimental?": "boolean"
|
|
3611
3669
|
},
|
|
@@ -3621,7 +3679,7 @@ const types = scope({
|
|
|
3621
3679
|
ComfyInputOpts_advanced: {
|
|
3622
3680
|
"tooltip?": "string | null | ComfyInputOpts_advanced",
|
|
3623
3681
|
"multiline?": "boolean | null",
|
|
3624
|
-
"default?": "boolean | number | string | null | number[]",
|
|
3682
|
+
"default?": "boolean | number | string | null | number[] | object",
|
|
3625
3683
|
"forceInput?": "boolean | null",
|
|
3626
3684
|
"min?": "number | null",
|
|
3627
3685
|
"round?": "boolean | number | null",
|
|
@@ -3982,14 +4040,46 @@ var ResilientWebSocketClient = class {
|
|
|
3982
4040
|
this.isOpen = false;
|
|
3983
4041
|
this.debugMessages = [];
|
|
3984
4042
|
this.hasEverOpened = false;
|
|
4043
|
+
this.heartbeat = null;
|
|
3985
4044
|
this.permanentlyClosed = false;
|
|
3986
4045
|
this.url = options.url();
|
|
3987
4046
|
this.connect();
|
|
3988
4047
|
}
|
|
4048
|
+
stopHeartbeat() {
|
|
4049
|
+
if (this.heartbeat != null) clearInterval(this.heartbeat);
|
|
4050
|
+
this.heartbeat = null;
|
|
4051
|
+
}
|
|
4052
|
+
/** ping on a timer; no pong since the previous ping = the peer is gone, drop the socket */
|
|
4053
|
+
startHeartbeat(ws) {
|
|
4054
|
+
this.stopHeartbeat();
|
|
4055
|
+
if (typeof ws.ping !== "function" || typeof ws.on !== "function") return;
|
|
4056
|
+
let awaitingPong = false;
|
|
4057
|
+
ws.on("pong", () => {
|
|
4058
|
+
awaitingPong = false;
|
|
4059
|
+
});
|
|
4060
|
+
const ms = this.options.heartbeatMs ?? 15e3;
|
|
4061
|
+
this.heartbeat = setInterval(() => {
|
|
4062
|
+
if (ws !== this.currentWS) return this.stopHeartbeat();
|
|
4063
|
+
if (awaitingPong) {
|
|
4064
|
+
this.addError(`no pong within ${ms}ms: the host is gone, dropping the socket to reconnect`);
|
|
4065
|
+
this.stopHeartbeat();
|
|
4066
|
+
if (typeof ws.terminate === "function") ws.terminate();
|
|
4067
|
+
else ws.close();
|
|
4068
|
+
return;
|
|
4069
|
+
}
|
|
4070
|
+
awaitingPong = true;
|
|
4071
|
+
try {
|
|
4072
|
+
ws.ping?.();
|
|
4073
|
+
} catch (e) {
|
|
4074
|
+
this.addError(`ping failed: ${extractErrorMessage(e)}`);
|
|
4075
|
+
}
|
|
4076
|
+
}, ms);
|
|
4077
|
+
}
|
|
3989
4078
|
/** close and stop reconnecting (lets a script exit cleanly) */
|
|
3990
4079
|
disconnectPermanently() {
|
|
3991
4080
|
this.permanentlyClosed = true;
|
|
3992
4081
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
4082
|
+
this.stopHeartbeat();
|
|
3993
4083
|
this.currentWS?.close();
|
|
3994
4084
|
this.currentWS = null;
|
|
3995
4085
|
this.isOpen = false;
|
|
@@ -4008,6 +4098,7 @@ var ResilientWebSocketClient = class {
|
|
|
4008
4098
|
this.isOpen = false;
|
|
4009
4099
|
const prevWS = this.currentWS;
|
|
4010
4100
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
4101
|
+
this.stopHeartbeat();
|
|
4011
4102
|
this.currentWS = null;
|
|
4012
4103
|
if (prevWS) {
|
|
4013
4104
|
this.addInfo("Previous WebSocket discarded");
|
|
@@ -4015,7 +4106,7 @@ var ResilientWebSocketClient = class {
|
|
|
4015
4106
|
}
|
|
4016
4107
|
let ws;
|
|
4017
4108
|
try {
|
|
4018
|
-
const transport = await resolveWsTransport();
|
|
4109
|
+
const transport = this.options.transport ?? await resolveWsTransport();
|
|
4019
4110
|
if (this.permanentlyClosed) return;
|
|
4020
4111
|
const headers = this.options.headers?.() ?? {};
|
|
4021
4112
|
ws = transport.supportsHeaders ? new transport.ctor(this.url, { headers }) : new transport.ctor(this.headerlessUrl(headers));
|
|
@@ -4037,10 +4128,12 @@ var ResilientWebSocketClient = class {
|
|
|
4037
4128
|
this.isOpen = true;
|
|
4038
4129
|
this.options.onConnectOrReconnect();
|
|
4039
4130
|
this.flushMessageBuffer();
|
|
4131
|
+
this.startHeartbeat(ws);
|
|
4040
4132
|
};
|
|
4041
4133
|
ws.onclose = (event) => {
|
|
4042
4134
|
if (ws !== this.currentWS) return;
|
|
4043
4135
|
this.isOpen = false;
|
|
4136
|
+
this.stopHeartbeat();
|
|
4044
4137
|
this.options.onClose();
|
|
4045
4138
|
if (this.permanentlyClosed) return;
|
|
4046
4139
|
this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
|
|
@@ -4049,8 +4142,9 @@ var ResilientWebSocketClient = class {
|
|
|
4049
4142
|
this.options.onFirstConnectFailed(/* @__PURE__ */ new Error(`connection refused (code=${event.code}${event.reason === "" ? "" : `, ${event.reason}`})`));
|
|
4050
4143
|
return;
|
|
4051
4144
|
}
|
|
4052
|
-
this.
|
|
4053
|
-
this.
|
|
4145
|
+
const wait = this.options.reconnectMs ?? 2e3;
|
|
4146
|
+
this.addInfo(`⏱️ reconnecting in ${wait / 1e3} seconds...`);
|
|
4147
|
+
this.reconnectTimeout = setTimeout(() => void this.connect(), wait);
|
|
4054
4148
|
};
|
|
4055
4149
|
ws.onerror = (event) => {
|
|
4056
4150
|
if (ws !== this.currentWS) return;
|
|
@@ -4350,6 +4444,221 @@ function writeKeywords() {
|
|
|
4350
4444
|
}
|
|
4351
4445
|
}
|
|
4352
4446
|
//#endregion
|
|
4447
|
+
//#region src/vars/loraEntry.ts
|
|
4448
|
+
function isLoraEntry(s) {
|
|
4449
|
+
if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
|
|
4450
|
+
const o = s;
|
|
4451
|
+
const st = o.strength;
|
|
4452
|
+
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"));
|
|
4453
|
+
}
|
|
4454
|
+
function isLoraStrength(s) {
|
|
4455
|
+
if (typeof s === "boolean") return true;
|
|
4456
|
+
if (typeof s === "number") return Number.isFinite(s);
|
|
4457
|
+
if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
4458
|
+
return isLoraEntry(s);
|
|
4459
|
+
}
|
|
4460
|
+
/** on = it runs */
|
|
4461
|
+
function loraIsOn(s) {
|
|
4462
|
+
if (s == null || s === false) return false;
|
|
4463
|
+
if (isLoraEntry(s)) return s.off !== true;
|
|
4464
|
+
return true;
|
|
4465
|
+
}
|
|
4466
|
+
/** the strengths, whatever the spelling (1/1 when there is nothing to read) */
|
|
4467
|
+
function loraStrengths(s) {
|
|
4468
|
+
if (typeof s === "number" && Number.isFinite(s)) return [s, s];
|
|
4469
|
+
if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
|
|
4470
|
+
if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
|
|
4471
|
+
return [1, 1];
|
|
4472
|
+
}
|
|
4473
|
+
function loraMuted(s) {
|
|
4474
|
+
return isLoraEntry(s) && s.mute != null ? s.mute : [];
|
|
4475
|
+
}
|
|
4476
|
+
/** a prompt keyword's parts, split at commas: each one can be left out on its own */
|
|
4477
|
+
function keywordParts(keyword) {
|
|
4478
|
+
return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
|
|
4479
|
+
}
|
|
4480
|
+
/** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
|
|
4481
|
+
function keptKeyword(keyword, muted) {
|
|
4482
|
+
return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
|
|
4483
|
+
}
|
|
4484
|
+
/** rewrite one setting, keeping what the patch does not name. The result stays in the short
|
|
4485
|
+
* spellings while nothing needs the palette form, so a plain draft reads as it always did */
|
|
4486
|
+
function withLora(s, patch) {
|
|
4487
|
+
const strength = patch.strength ?? loraStrengths(s);
|
|
4488
|
+
const off = patch.on == null ? !loraIsOn(s) : !patch.on;
|
|
4489
|
+
const mute = [...patch.mute ?? loraMuted(s)];
|
|
4490
|
+
if (!off && mute.length === 0) return [strength[0], strength[1]];
|
|
4491
|
+
return {
|
|
4492
|
+
strength: [strength[0], strength[1]],
|
|
4493
|
+
...off ? { off: true } : {},
|
|
4494
|
+
...mute.length === 0 ? {} : { mute }
|
|
4495
|
+
};
|
|
4496
|
+
}
|
|
4497
|
+
//#endregion
|
|
4498
|
+
//#region src/vars/lanes.ts
|
|
4499
|
+
const FIRST_LANE = "main";
|
|
4500
|
+
function isObject(v) {
|
|
4501
|
+
return typeof v === "object" && v != null && !Array.isArray(v);
|
|
4502
|
+
}
|
|
4503
|
+
function isPromptLane(v) {
|
|
4504
|
+
return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
|
|
4505
|
+
}
|
|
4506
|
+
function isPromptLanes(v) {
|
|
4507
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
|
|
4508
|
+
}
|
|
4509
|
+
/** the text the build reads: the active lanes joined in order, one line break between them, so
|
|
4510
|
+
* `//` and `- ` lines keep working inside every lane */
|
|
4511
|
+
function promptText(v) {
|
|
4512
|
+
if (typeof v === "string") return v;
|
|
4513
|
+
return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
|
|
4514
|
+
}
|
|
4515
|
+
const HEADER = /^# (.+?)( \(off\))?$/;
|
|
4516
|
+
function promptLanesToText(v) {
|
|
4517
|
+
return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
|
|
4518
|
+
}
|
|
4519
|
+
/** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
|
|
4520
|
+
function promptLanesFromText(text) {
|
|
4521
|
+
const lanes = [];
|
|
4522
|
+
let current = null;
|
|
4523
|
+
const body = [];
|
|
4524
|
+
const close = () => {
|
|
4525
|
+
if (current != null) lanes.push({
|
|
4526
|
+
...current,
|
|
4527
|
+
prompt: body.join("\n")
|
|
4528
|
+
});
|
|
4529
|
+
else if (body.some((l) => l.trim() !== "")) lanes.push({
|
|
4530
|
+
name: FIRST_LANE,
|
|
4531
|
+
prompt: body.join("\n"),
|
|
4532
|
+
active: true
|
|
4533
|
+
});
|
|
4534
|
+
body.length = 0;
|
|
4535
|
+
};
|
|
4536
|
+
for (const line of text.split("\n")) {
|
|
4537
|
+
const m = HEADER.exec(line);
|
|
4538
|
+
if (m == null) {
|
|
4539
|
+
body.push(line);
|
|
4540
|
+
continue;
|
|
4541
|
+
}
|
|
4542
|
+
close();
|
|
4543
|
+
current = {
|
|
4544
|
+
name: (m[1] ?? "").trim(),
|
|
4545
|
+
prompt: "",
|
|
4546
|
+
active: m[2] == null
|
|
4547
|
+
};
|
|
4548
|
+
}
|
|
4549
|
+
close();
|
|
4550
|
+
return { lanes: lanes.length > 0 ? lanes : [{
|
|
4551
|
+
name: FIRST_LANE,
|
|
4552
|
+
prompt: "",
|
|
4553
|
+
active: true
|
|
4554
|
+
}] };
|
|
4555
|
+
}
|
|
4556
|
+
function isLoraRecord(v) {
|
|
4557
|
+
return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
|
|
4558
|
+
}
|
|
4559
|
+
function isLoraLane(v) {
|
|
4560
|
+
return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
|
|
4561
|
+
}
|
|
4562
|
+
function isLoraLanes(v) {
|
|
4563
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
|
|
4564
|
+
}
|
|
4565
|
+
function isLorasInput(v) {
|
|
4566
|
+
return isLoraRecord(v) || isLoraLanes(v);
|
|
4567
|
+
}
|
|
4568
|
+
/** one record for the build: the active lanes in order. A lora in two active lanes keeps its
|
|
4569
|
+
* FIRST setting, and `duplicates` names it so the caller can say so */
|
|
4570
|
+
function flattenLoras(v) {
|
|
4571
|
+
if (!isLoraLanes(v)) return {
|
|
4572
|
+
record: v,
|
|
4573
|
+
duplicates: []
|
|
4574
|
+
};
|
|
4575
|
+
const record = {};
|
|
4576
|
+
const duplicates = [];
|
|
4577
|
+
for (const lane of v.lanes) {
|
|
4578
|
+
if (!lane.active) continue;
|
|
4579
|
+
for (const [name, st] of Object.entries(lane.loras)) {
|
|
4580
|
+
if (st == null) continue;
|
|
4581
|
+
if (name in record) duplicates.push(name);
|
|
4582
|
+
else record[name] = st;
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
return {
|
|
4586
|
+
record,
|
|
4587
|
+
duplicates
|
|
4588
|
+
};
|
|
4589
|
+
}
|
|
4590
|
+
/** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
|
|
4591
|
+
* has it (the one the build reads), else any lane, else -1 */
|
|
4592
|
+
function laneIndexOf(v, name) {
|
|
4593
|
+
const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
|
|
4594
|
+
return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
|
|
4595
|
+
}
|
|
4596
|
+
/** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
|
|
4597
|
+
* A lora in no lane yet lands in the first lane */
|
|
4598
|
+
function updateLora(v, name, next) {
|
|
4599
|
+
const write = (rec) => {
|
|
4600
|
+
const out = { ...rec };
|
|
4601
|
+
if (next == null) delete out[name];
|
|
4602
|
+
else out[name] = next;
|
|
4603
|
+
return out;
|
|
4604
|
+
};
|
|
4605
|
+
if (!isLoraLanes(v)) return write(v);
|
|
4606
|
+
if (v.lanes.length === 0) return { lanes: [{
|
|
4607
|
+
name: FIRST_LANE,
|
|
4608
|
+
active: true,
|
|
4609
|
+
loras: write({})
|
|
4610
|
+
}] };
|
|
4611
|
+
const found = laneIndexOf(v, name);
|
|
4612
|
+
const ix = found === -1 ? 0 : found;
|
|
4613
|
+
return { lanes: v.lanes.map((l, i) => i === ix ? {
|
|
4614
|
+
...l,
|
|
4615
|
+
loras: write(l.loras)
|
|
4616
|
+
} : l) };
|
|
4617
|
+
}
|
|
4618
|
+
//#endregion
|
|
4619
|
+
//#region src/vars/promptSyntax.ts
|
|
4620
|
+
/** a whole line that is a comment (the TUI colors these) */
|
|
4621
|
+
const COMMENT_LINE_RE = /^\s*\/\//;
|
|
4622
|
+
/** a negative prompt line: `- ` then its text */
|
|
4623
|
+
const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
|
|
4624
|
+
const NEGATIVE_PREFIX_RE = /^(\s*)- /;
|
|
4625
|
+
/** where a `//` comment starts on this line, -1 when none. Only at line start or after
|
|
4626
|
+
* whitespace, so `http://host` is never cut */
|
|
4627
|
+
function commentStart(line) {
|
|
4628
|
+
const m = /(?:^|\s)\/\//.exec(line);
|
|
4629
|
+
if (m == null) return -1;
|
|
4630
|
+
return m.index + m[0].length - 2;
|
|
4631
|
+
}
|
|
4632
|
+
/** the line without its comment, trailing whitespace dropped with it */
|
|
4633
|
+
function withoutComment(line) {
|
|
4634
|
+
const c = commentStart(line);
|
|
4635
|
+
return c < 0 ? {
|
|
4636
|
+
text: line,
|
|
4637
|
+
hadComment: false
|
|
4638
|
+
} : {
|
|
4639
|
+
text: line.slice(0, c).trimEnd(),
|
|
4640
|
+
hadComment: true
|
|
4641
|
+
};
|
|
4642
|
+
}
|
|
4643
|
+
/** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
|
|
4644
|
+
function parsePromptText(text) {
|
|
4645
|
+
const pos = [];
|
|
4646
|
+
const neg = [];
|
|
4647
|
+
for (const raw of text.split("\n")) {
|
|
4648
|
+
const cut = withoutComment(raw);
|
|
4649
|
+
if (cut.hadComment && cut.text.trim() === "") continue;
|
|
4650
|
+
const m = NEGATIVE_PREFIX_RE.exec(raw);
|
|
4651
|
+
if (m != null && m[0].length <= cut.text.length + 1) {
|
|
4652
|
+
const body = cut.text.slice(m[0].length).trim();
|
|
4653
|
+
if (body !== "") neg.push(body);
|
|
4654
|
+
} else pos.push(cut.text);
|
|
4655
|
+
}
|
|
4656
|
+
return {
|
|
4657
|
+
positive: pos.join("\n").trim(),
|
|
4658
|
+
negative: neg.join(", ")
|
|
4659
|
+
};
|
|
4660
|
+
}
|
|
4661
|
+
//#endregion
|
|
4353
4662
|
//#region src/vars/presets.ts
|
|
4354
4663
|
function toPresetList(spec) {
|
|
4355
4664
|
if (spec == null) return [];
|
|
@@ -4365,16 +4674,11 @@ function activePresetLabel(presets, value) {
|
|
|
4365
4674
|
}
|
|
4366
4675
|
//#endregion
|
|
4367
4676
|
//#region src/vars/ComfyVars.ts
|
|
4368
|
-
/**
|
|
4369
|
-
* full base: T is what's STORED/edited, Out what the GRAPH consumes at build
|
|
4370
|
-
* time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
|
|
4371
|
-
* the one Out-specialized var (string in, PromptValue out); the split keeps
|
|
4372
|
-
* outValue() cast-free.
|
|
4373
|
-
*/
|
|
4374
4677
|
var ComfyVarBase = class {
|
|
4375
4678
|
constructor(defaultValue, label) {
|
|
4376
4679
|
this.defaultValue = defaultValue;
|
|
4377
4680
|
this.label = label;
|
|
4681
|
+
this.uiOpts = {};
|
|
4378
4682
|
this.value = defaultValue;
|
|
4379
4683
|
makeObservable(this, {
|
|
4380
4684
|
value: observable,
|
|
@@ -4388,6 +4692,14 @@ var ComfyVarBase = class {
|
|
|
4388
4692
|
this.value = value;
|
|
4389
4693
|
return this;
|
|
4390
4694
|
}
|
|
4695
|
+
/** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
|
|
4696
|
+
ui(p) {
|
|
4697
|
+
this.uiOpts = {
|
|
4698
|
+
...this.uiOpts,
|
|
4699
|
+
...p
|
|
4700
|
+
};
|
|
4701
|
+
return this;
|
|
4702
|
+
}
|
|
4391
4703
|
/** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
|
|
4392
4704
|
toJSON() {
|
|
4393
4705
|
return this.value;
|
|
@@ -4435,12 +4747,10 @@ var TextVar = class extends ComfyVar {
|
|
|
4435
4747
|
return true;
|
|
4436
4748
|
}
|
|
4437
4749
|
};
|
|
4438
|
-
const commentLineRe = /^\s*\/\//;
|
|
4439
|
-
const negativeLineRe = /^\s*- (.*)$/;
|
|
4440
4750
|
/**
|
|
4441
4751
|
* prompt text with editor comforts, all resolved at BUILD time (the editor and
|
|
4442
4752
|
* drafts keep the raw text):
|
|
4443
|
-
* - `//`
|
|
4753
|
+
* - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
|
|
4444
4754
|
* - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
|
|
4445
4755
|
* comma-joined into `.negative`
|
|
4446
4756
|
* - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
|
|
@@ -4454,38 +4764,48 @@ var PromptVar = class extends ComfyVarBase {
|
|
|
4454
4764
|
this.kind = "prompt";
|
|
4455
4765
|
this.presets = toPresetList(promptOpts.presets);
|
|
4456
4766
|
}
|
|
4767
|
+
/** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
|
|
4457
4768
|
parse(raw) {
|
|
4458
|
-
this.set(raw);
|
|
4769
|
+
this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
|
|
4459
4770
|
return true;
|
|
4460
4771
|
}
|
|
4772
|
+
toEditBuffer() {
|
|
4773
|
+
return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
|
|
4774
|
+
}
|
|
4775
|
+
/** a var list shows the lanes by name, the inactive ones in parentheses */
|
|
4776
|
+
display() {
|
|
4777
|
+
if (!isPromptLanes(this.value)) return super.display();
|
|
4778
|
+
return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
|
|
4779
|
+
}
|
|
4780
|
+
/** the text the build reads: the plain string, or the active lanes joined in order */
|
|
4781
|
+
get text() {
|
|
4782
|
+
return promptText(this.value);
|
|
4783
|
+
}
|
|
4784
|
+
/** the tag list options in their one object form, null when this prompt has no completion */
|
|
4785
|
+
get tags() {
|
|
4786
|
+
const t = this.promptOpts.tags;
|
|
4787
|
+
if (t == null) return null;
|
|
4788
|
+
return typeof t === "string" ? { url: t } : t;
|
|
4789
|
+
}
|
|
4461
4790
|
static isCommentLine(line) {
|
|
4462
|
-
return
|
|
4791
|
+
return COMMENT_LINE_RE.test(line);
|
|
4463
4792
|
}
|
|
4464
4793
|
static isNegativeLine(line) {
|
|
4465
|
-
return
|
|
4794
|
+
return NEGATIVE_LINE_RE.test(line);
|
|
4466
4795
|
}
|
|
4467
4796
|
/** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
|
|
4468
4797
|
injectedKeywords() {
|
|
4469
4798
|
const src = this.promptOpts.loraKeywordsFrom;
|
|
4470
4799
|
if (src == null) return [];
|
|
4471
|
-
return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
|
|
4800
|
+
return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
|
|
4472
4801
|
}
|
|
4473
4802
|
outValue() {
|
|
4474
|
-
const
|
|
4475
|
-
const
|
|
4476
|
-
for (const line of this.value.split("\n")) {
|
|
4477
|
-
if (commentLineRe.test(line)) continue;
|
|
4478
|
-
const m = negativeLineRe.exec(line);
|
|
4479
|
-
if (m != null) {
|
|
4480
|
-
const text = (m[1] ?? "").trim();
|
|
4481
|
-
if (text !== "") neg.push(text);
|
|
4482
|
-
} else pos.push(line);
|
|
4483
|
-
}
|
|
4484
|
-
const body = pos.join("\n").trim();
|
|
4803
|
+
const parsed = parsePromptText(this.text);
|
|
4804
|
+
const body = parsed.positive;
|
|
4485
4805
|
const keywords = this.injectedKeywords();
|
|
4486
4806
|
return {
|
|
4487
4807
|
positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
|
|
4488
|
-
negative:
|
|
4808
|
+
negative: parsed.negative
|
|
4489
4809
|
};
|
|
4490
4810
|
}
|
|
4491
4811
|
};
|
|
@@ -4625,6 +4945,7 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4625
4945
|
super(defaultValue, label);
|
|
4626
4946
|
this.choices = choices;
|
|
4627
4947
|
this.kind = "choice";
|
|
4948
|
+
this.select = "one";
|
|
4628
4949
|
}
|
|
4629
4950
|
next(delta = 1) {
|
|
4630
4951
|
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
@@ -4637,12 +4958,96 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4637
4958
|
return true;
|
|
4638
4959
|
}
|
|
4639
4960
|
};
|
|
4961
|
+
/** one option or none: `null` is "nothing picked", clicking the lit option clears it */
|
|
4962
|
+
var OptionalChoiceVar = class extends ComfyVar {
|
|
4963
|
+
constructor(choices, defaultValue, label) {
|
|
4964
|
+
super(defaultValue, label);
|
|
4965
|
+
this.choices = choices;
|
|
4966
|
+
this.kind = "choice";
|
|
4967
|
+
this.select = "zero-or-one";
|
|
4968
|
+
}
|
|
4969
|
+
/** pick `c`, or clear it when it is already the one picked */
|
|
4970
|
+
toggle(c) {
|
|
4971
|
+
return this.set(this.value === c ? null : c);
|
|
4972
|
+
}
|
|
4973
|
+
/** the TUI text form: a choice, or an empty line for none */
|
|
4974
|
+
parse(raw) {
|
|
4975
|
+
if (raw.trim() === "") {
|
|
4976
|
+
this.set(null);
|
|
4977
|
+
return true;
|
|
4978
|
+
}
|
|
4979
|
+
const hit = this.choices.find((c) => c === raw.trim());
|
|
4980
|
+
if (hit == null) return false;
|
|
4981
|
+
this.set(hit);
|
|
4982
|
+
return true;
|
|
4983
|
+
}
|
|
4984
|
+
toEditBuffer() {
|
|
4985
|
+
return this.value ?? "";
|
|
4986
|
+
}
|
|
4987
|
+
/** a draft from when this was a many choice holds a list: its first known option */
|
|
4988
|
+
loadJSON(value) {
|
|
4989
|
+
const one = Array.isArray(value) ? value[0] : value;
|
|
4990
|
+
return this.set(this.choices.find((c) => c === one) ?? null);
|
|
4991
|
+
}
|
|
4992
|
+
display() {
|
|
4993
|
+
return this.value ?? "none";
|
|
4994
|
+
}
|
|
4995
|
+
};
|
|
4996
|
+
/** any number of options, kept in the order the choices list them */
|
|
4997
|
+
var MultiChoiceVar = class extends ComfyVar {
|
|
4998
|
+
constructor(choices, defaultValue, label) {
|
|
4999
|
+
super([...defaultValue], label);
|
|
5000
|
+
this.choices = choices;
|
|
5001
|
+
this.kind = "choice";
|
|
5002
|
+
this.select = "many";
|
|
5003
|
+
}
|
|
5004
|
+
toggle(c) {
|
|
5005
|
+
const on = this.value.includes(c);
|
|
5006
|
+
return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
|
|
5007
|
+
}
|
|
5008
|
+
/** the TUI text form: `a, b` */
|
|
5009
|
+
parse(raw) {
|
|
5010
|
+
const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
|
|
5011
|
+
const picked = this.choices.filter((c) => wanted.includes(c));
|
|
5012
|
+
if (picked.length !== new Set(wanted).size) return false;
|
|
5013
|
+
this.set(picked);
|
|
5014
|
+
return true;
|
|
5015
|
+
}
|
|
5016
|
+
toEditBuffer() {
|
|
5017
|
+
return this.value.join(", ");
|
|
5018
|
+
}
|
|
5019
|
+
/** a draft from when this was a single choice holds one value: a list of one. Unknown
|
|
5020
|
+
* options are dropped, the list comes back in the choices order */
|
|
5021
|
+
loadJSON(value) {
|
|
5022
|
+
const listed = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
5023
|
+
return this.set(this.choices.filter((c) => listed.includes(c)));
|
|
5024
|
+
}
|
|
5025
|
+
display() {
|
|
5026
|
+
return this.value.length === 0 ? "none" : this.value.join(", ");
|
|
5027
|
+
}
|
|
5028
|
+
};
|
|
5029
|
+
/** Array.isArray does not narrow a READONLY array out of a union, this does */
|
|
5030
|
+
function isChoiceList(v) {
|
|
5031
|
+
return Array.isArray(v);
|
|
5032
|
+
}
|
|
5033
|
+
function choice(choices, defaultValue, opts) {
|
|
5034
|
+
const o = typeof opts === "string" ? { label: opts } : opts ?? {};
|
|
5035
|
+
const select = o.select ?? "one";
|
|
5036
|
+
if (select === "many") {
|
|
5037
|
+
if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
|
|
5038
|
+
return new MultiChoiceVar(choices, defaultValue, o.label);
|
|
5039
|
+
}
|
|
5040
|
+
if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
|
|
5041
|
+
if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
|
|
5042
|
+
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
5043
|
+
return new ChoiceVar(choices, defaultValue, o.label);
|
|
5044
|
+
}
|
|
4640
5045
|
/** normalize a loras record into what a standard LoraLoader chain consumes */
|
|
4641
5046
|
function activeLoras(loras) {
|
|
4642
5047
|
const out = [];
|
|
4643
|
-
for (const [lora_name, s] of Object.entries(loras)) {
|
|
4644
|
-
if (s
|
|
4645
|
-
const [strength_model, strength_clip] =
|
|
5048
|
+
for (const [lora_name, s] of Object.entries(flattenLoras(loras).record)) {
|
|
5049
|
+
if (!loraIsOn(s)) continue;
|
|
5050
|
+
const [strength_model, strength_clip] = loraStrengths(s);
|
|
4646
5051
|
out.push({
|
|
4647
5052
|
lora_name,
|
|
4648
5053
|
strength_model,
|
|
@@ -4657,7 +5062,12 @@ function activeLoras(loras) {
|
|
|
4657
5062
|
* or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
|
|
4658
5063
|
* a hardcoded inventory. Selection is empty by default.
|
|
4659
5064
|
*/
|
|
4660
|
-
|
|
5065
|
+
/**
|
|
5066
|
+
* the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
|
|
5067
|
+
* build merges in listed order, skipping inactive ones. Every method reads the merged record and
|
|
5068
|
+
* writes into the lane that holds the lora, so the TUI never needs to know lanes exist
|
|
5069
|
+
*/
|
|
5070
|
+
var LorasVar = class LorasVar extends ComfyVarBase {
|
|
4661
5071
|
constructor(optionsSource, initial = {}, label) {
|
|
4662
5072
|
super(initial, label);
|
|
4663
5073
|
this.optionsSource = optionsSource;
|
|
@@ -4688,49 +5098,57 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4688
5098
|
get names() {
|
|
4689
5099
|
return [...this.options];
|
|
4690
5100
|
}
|
|
5101
|
+
/** the loras the build reads: the plain record, or the active lanes merged in order */
|
|
5102
|
+
get record() {
|
|
5103
|
+
return flattenLoras(this.value).record;
|
|
5104
|
+
}
|
|
5105
|
+
/** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
|
|
5106
|
+
outValue() {
|
|
5107
|
+
const flat = flattenLoras(this.value);
|
|
5108
|
+
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`);
|
|
5109
|
+
return flat.record;
|
|
5110
|
+
}
|
|
5111
|
+
/** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
|
|
5112
|
+
write(name, next) {
|
|
5113
|
+
return this.set(updateLora(this.value, name, next));
|
|
5114
|
+
}
|
|
5115
|
+
/** the parts of this lora's prompt keyword left out of the prompt */
|
|
5116
|
+
mutedWords(name) {
|
|
5117
|
+
return loraMuted(this.record[name]);
|
|
5118
|
+
}
|
|
4691
5119
|
/** loras currently ON (PromptVar keyword prefixing consumes this) */
|
|
4692
5120
|
activeNames() {
|
|
4693
5121
|
return this.names.filter((n) => this.isOn(n));
|
|
4694
5122
|
}
|
|
4695
5123
|
isOn(name) {
|
|
4696
|
-
|
|
4697
|
-
return s != null && s !== false;
|
|
5124
|
+
return loraIsOn(this.record[name]);
|
|
4698
5125
|
}
|
|
4699
5126
|
toggleItem(name) {
|
|
4700
|
-
const cur = this.
|
|
4701
|
-
if (cur == null || cur === false) return this.
|
|
4702
|
-
|
|
4703
|
-
[name]: this.prev[name] ?? true
|
|
4704
|
-
});
|
|
5127
|
+
const cur = this.record[name];
|
|
5128
|
+
if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
|
|
5129
|
+
if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
|
|
4705
5130
|
this.prev[name] = cur;
|
|
4706
|
-
return this.
|
|
4707
|
-
...this.value,
|
|
4708
|
-
[name]: false
|
|
4709
|
-
});
|
|
5131
|
+
return this.write(name, false);
|
|
4710
5132
|
}
|
|
4711
5133
|
/** step both strengths by delta (true becomes 1 first); no-op when off */
|
|
4712
5134
|
adjustItem(name, delta) {
|
|
4713
|
-
const cur = this.
|
|
4714
|
-
if (cur
|
|
5135
|
+
const cur = this.record[name];
|
|
5136
|
+
if (!loraIsOn(cur)) return this;
|
|
4715
5137
|
const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
|
|
4716
|
-
const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] :
|
|
4717
|
-
return this.
|
|
4718
|
-
...this.value,
|
|
4719
|
-
[name]: next
|
|
4720
|
-
});
|
|
5138
|
+
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])] });
|
|
5139
|
+
return this.write(name, next);
|
|
4721
5140
|
}
|
|
4722
5141
|
/** compact per-item strength label for lists */
|
|
4723
5142
|
strengthLabel(name) {
|
|
4724
|
-
const s = this.
|
|
4725
|
-
if (s
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
return s.toFixed(2);
|
|
5143
|
+
const s = this.record[name];
|
|
5144
|
+
if (!loraIsOn(s)) return "";
|
|
5145
|
+
const [m, c] = loraStrengths(s);
|
|
5146
|
+
return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
|
|
4729
5147
|
}
|
|
4730
5148
|
parse(raw) {
|
|
4731
5149
|
try {
|
|
4732
5150
|
const parsed = JSON.parse(raw);
|
|
4733
|
-
if (
|
|
5151
|
+
if (!isLorasInput(parsed)) return false;
|
|
4734
5152
|
this.set(parsed);
|
|
4735
5153
|
return true;
|
|
4736
5154
|
} catch {
|
|
@@ -4743,14 +5161,16 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4743
5161
|
}
|
|
4744
5162
|
/** tick (true) or untick (false) every lora in `names` (default: all options) */
|
|
4745
5163
|
setAll(on, names = this.options) {
|
|
4746
|
-
const
|
|
5164
|
+
const record = this.record;
|
|
5165
|
+
let next = this.value;
|
|
4747
5166
|
for (const name of names) {
|
|
4748
|
-
const cur =
|
|
5167
|
+
const cur = record[name];
|
|
4749
5168
|
if (on) {
|
|
4750
|
-
if (cur == null || cur === false) next
|
|
5169
|
+
if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
|
|
5170
|
+
else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
|
|
4751
5171
|
} else {
|
|
4752
|
-
if (cur
|
|
4753
|
-
next
|
|
5172
|
+
if (loraIsOn(cur)) this.prev[name] = cur;
|
|
5173
|
+
next = updateLora(next, name, false);
|
|
4754
5174
|
}
|
|
4755
5175
|
}
|
|
4756
5176
|
return this.set(next);
|
|
@@ -4799,6 +5219,56 @@ const DEFAULT_SIZE_PRESETS = [
|
|
|
4799
5219
|
height: 1344
|
|
4800
5220
|
}
|
|
4801
5221
|
];
|
|
5222
|
+
/** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
|
|
5223
|
+
const SD15_SIZE_PRESETS = [
|
|
5224
|
+
{
|
|
5225
|
+
label: "1:1 square",
|
|
5226
|
+
width: 512,
|
|
5227
|
+
height: 512
|
|
5228
|
+
},
|
|
5229
|
+
{
|
|
5230
|
+
label: "4:3 landscape",
|
|
5231
|
+
width: 576,
|
|
5232
|
+
height: 448
|
|
5233
|
+
},
|
|
5234
|
+
{
|
|
5235
|
+
label: "3:4 portrait",
|
|
5236
|
+
width: 448,
|
|
5237
|
+
height: 576
|
|
5238
|
+
},
|
|
5239
|
+
{
|
|
5240
|
+
label: "3:2 landscape",
|
|
5241
|
+
width: 576,
|
|
5242
|
+
height: 384
|
|
5243
|
+
},
|
|
5244
|
+
{
|
|
5245
|
+
label: "2:3 portrait",
|
|
5246
|
+
width: 384,
|
|
5247
|
+
height: 576
|
|
5248
|
+
},
|
|
5249
|
+
{
|
|
5250
|
+
label: "16:9 widescreen",
|
|
5251
|
+
width: 704,
|
|
5252
|
+
height: 384
|
|
5253
|
+
},
|
|
5254
|
+
{
|
|
5255
|
+
label: "9:16 tall",
|
|
5256
|
+
width: 384,
|
|
5257
|
+
height: 704
|
|
5258
|
+
}
|
|
5259
|
+
];
|
|
5260
|
+
/** starred presets are one click away in the panel, before the full list */
|
|
5261
|
+
const DEFAULT_STARRED_SIZES = [
|
|
5262
|
+
"1:1 square",
|
|
5263
|
+
"3:4 portrait",
|
|
5264
|
+
"4:3 landscape"
|
|
5265
|
+
];
|
|
5266
|
+
/** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
|
|
5267
|
+
* and offering it 1024 buckets would be offering sizes it was never trained at */
|
|
5268
|
+
function sizePresetsFor(defaultValue) {
|
|
5269
|
+
if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
|
|
5270
|
+
return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
|
|
5271
|
+
}
|
|
4802
5272
|
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
4803
5273
|
* size of a linked image var (the widget shows
|
|
4804
5274
|
* `WxH size of image '<name>'` as a pickable row) */
|
|
@@ -4806,10 +5276,11 @@ var SizeVar = class extends ComfyVar {
|
|
|
4806
5276
|
constructor(defaultValue = {
|
|
4807
5277
|
width: 1024,
|
|
4808
5278
|
height: 1024
|
|
4809
|
-
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
|
|
5279
|
+
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
|
|
4810
5280
|
super(defaultValue, label);
|
|
4811
5281
|
this.presets = presets;
|
|
4812
5282
|
this.imageVar = imageVar;
|
|
5283
|
+
this.starred = starred;
|
|
4813
5284
|
this.kind = "size";
|
|
4814
5285
|
}
|
|
4815
5286
|
/** current dimensions of the linked image var — null when no link, unset
|
|
@@ -4934,9 +5405,11 @@ const v = {
|
|
|
4934
5405
|
* which is what a tuning session wants, and reset()/revert come back to it */
|
|
4935
5406
|
seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
|
|
4936
5407
|
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
4937
|
-
|
|
5408
|
+
/** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
|
|
5409
|
+
* `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
|
|
5410
|
+
choice,
|
|
4938
5411
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
4939
|
-
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
|
|
5412
|
+
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
4940
5413
|
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
|
|
4941
5414
|
};
|
|
4942
5415
|
function varValues(vars) {
|
|
@@ -4965,6 +5438,29 @@ var DefinedWorkflow = class {
|
|
|
4965
5438
|
varDef.name = key;
|
|
4966
5439
|
varDef.bindHost?.(this.host);
|
|
4967
5440
|
}
|
|
5441
|
+
const names = this.entries().map(([key]) => key);
|
|
5442
|
+
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(", ")})`);
|
|
5443
|
+
}
|
|
5444
|
+
/** every preview for the current var values. A preview that throws, or vars that cannot be
|
|
5445
|
+
* read yet (an image var still empty), give a line saying so instead of failing the others */
|
|
5446
|
+
computePreviews() {
|
|
5447
|
+
const previews = this.spec.previews ?? {};
|
|
5448
|
+
const names = Object.keys(previews);
|
|
5449
|
+
if (names.length === 0) return {};
|
|
5450
|
+
let values;
|
|
5451
|
+
try {
|
|
5452
|
+
values = varValues(this.vars);
|
|
5453
|
+
} catch (e) {
|
|
5454
|
+
const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
|
|
5455
|
+
return Object.fromEntries(names.map((n) => [n, why]));
|
|
5456
|
+
}
|
|
5457
|
+
const out = {};
|
|
5458
|
+
for (const [name, fn] of Object.entries(previews)) try {
|
|
5459
|
+
out[name] = fn(values);
|
|
5460
|
+
} catch (e) {
|
|
5461
|
+
out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
5462
|
+
}
|
|
5463
|
+
return out;
|
|
4968
5464
|
}
|
|
4969
5465
|
/** [name, var] pairs, for drivers that enumerate the knobs */
|
|
4970
5466
|
entries() {
|
|
@@ -4978,12 +5474,15 @@ var DefinedWorkflow = class {
|
|
|
4978
5474
|
* build() for copy/export never advances). `p.host` substitutes the host
|
|
4979
5475
|
* the graph is built against (TUI host override): node/model availability
|
|
4980
5476
|
* there surfaces as workflow.problems / server validation, by design.
|
|
5477
|
+
* `p.dry` builds a graph only to read it: nothing is uploaded, lastWorkflow is left alone.
|
|
4981
5478
|
*/
|
|
4982
5479
|
async build(p = {}) {
|
|
4983
5480
|
const wf = (p.host ?? this.host).workflow({ id: this.spec.id });
|
|
5481
|
+
wf.dry = p.dry === true;
|
|
4984
5482
|
const values = varValues(this.vars);
|
|
4985
5483
|
if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
|
|
4986
5484
|
await this.spec.build(wf.builder, values, wf);
|
|
5485
|
+
if (wf.dry) return wf;
|
|
4987
5486
|
this.lastWorkflow = wf;
|
|
4988
5487
|
return wf;
|
|
4989
5488
|
}
|
|
@@ -5284,8 +5783,22 @@ var ComfyHost = class {
|
|
|
5284
5783
|
this.clearQueue = () => {
|
|
5285
5784
|
return this.postJSON_("/queue", { clear: true });
|
|
5286
5785
|
};
|
|
5786
|
+
this.interruptCoalesceMs = 3e3;
|
|
5787
|
+
this._lastInterrupt = null;
|
|
5287
5788
|
this.interrupt = () => {
|
|
5288
|
-
|
|
5789
|
+
const now = Date.now();
|
|
5790
|
+
const last = this._lastInterrupt;
|
|
5791
|
+
if (last != null && last.promptID === this.activePromptID && now - last.at < this.interruptCoalesceMs) return last.req;
|
|
5792
|
+
const req = this.postJSON_("/interrupt", {});
|
|
5793
|
+
this._lastInterrupt = {
|
|
5794
|
+
promptID: this.activePromptID,
|
|
5795
|
+
at: now,
|
|
5796
|
+
req
|
|
5797
|
+
};
|
|
5798
|
+
req.catch(() => {
|
|
5799
|
+
if (this._lastInterrupt?.req === req) this._lastInterrupt = null;
|
|
5800
|
+
});
|
|
5801
|
+
return req;
|
|
5289
5802
|
};
|
|
5290
5803
|
this.deleteHistory = (promptId) => {
|
|
5291
5804
|
return this.postJSON_("/history", { delete: [promptId] });
|
|
@@ -6270,6 +6783,10 @@ var ComfyTS = class ComfyTS {
|
|
|
6270
6783
|
resolveFromPromptEnhancers(relativePath) {
|
|
6271
6784
|
return asAbsolutePath(join(this.baseFolder, "prompt-enhancers", relativePath));
|
|
6272
6785
|
}
|
|
6786
|
+
/** the serve web ui's LLM configs (prompt enhancer), one json per config */
|
|
6787
|
+
resolveFromLlmConfigs(relativePath) {
|
|
6788
|
+
return asAbsolutePath(join(this.baseFolder, "llm-configs", relativePath));
|
|
6789
|
+
}
|
|
6273
6790
|
resolveFromCache(relativePath) {
|
|
6274
6791
|
return asAbsolutePath(join(this.baseFolder, "cache", relativePath));
|
|
6275
6792
|
}
|
|
@@ -6411,6 +6928,6 @@ function isTuiActive() {
|
|
|
6411
6928
|
*/
|
|
6412
6929
|
setDefaultComfyStorage(createNodeStorage());
|
|
6413
6930
|
//#endregion
|
|
6414
|
-
export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, PromptVar, ResilientWebSocketClient, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, isTuiActive, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, promptEnhancerPresets, readPromptEnhancers, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, toPresetList, v };
|
|
6931
|
+
export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, MultiChoiceVar, OptionalChoiceVar, PromptVar, ResilientWebSocketClient, SD15_SIZE_PRESETS, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, isTuiActive, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, promptEnhancerPresets, readPromptEnhancers, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
|
|
6415
6932
|
|
|
6416
6933
|
//# sourceMappingURL=index.js.map
|