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/web.js
CHANGED
|
@@ -101,7 +101,7 @@ function getComfyStorage() {
|
|
|
101
101
|
}
|
|
102
102
|
//#endregion
|
|
103
103
|
//#region package.json
|
|
104
|
-
var version = "2.
|
|
104
|
+
var version = "2.13.0";
|
|
105
105
|
//#endregion
|
|
106
106
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
107
107
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -2007,6 +2007,7 @@ const types$1 = scope({
|
|
|
2007
2007
|
output: {
|
|
2008
2008
|
"previews?": [{ filepath: "string" }, "[]"],
|
|
2009
2009
|
"images?": "ComfyImageInfo[]",
|
|
2010
|
+
"audio?": "ComfyImageInfo[]",
|
|
2010
2011
|
"text?": "unknown[]"
|
|
2011
2012
|
},
|
|
2012
2013
|
prompt_id: "PromptID"
|
|
@@ -2107,11 +2108,11 @@ var MediaImage = class MediaImage {
|
|
|
2107
2108
|
});
|
|
2108
2109
|
};
|
|
2109
2110
|
this.loadInWorkflow_viaLoadImageNode = async (workflow) => {
|
|
2110
|
-
const enumName = await this.uploadAndReturnEnumName(workflow.host);
|
|
2111
|
+
const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
|
|
2111
2112
|
return bang(workflow.builderBase.LoadImage, "host has no LoadImage node")({ image: enumName });
|
|
2112
2113
|
};
|
|
2113
2114
|
this.loadInWorkflowAsMask_viaLoadImageMask = async (channel, workflow) => {
|
|
2114
|
-
const enumName = await this.uploadAndReturnEnumName(workflow.host);
|
|
2115
|
+
const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
|
|
2115
2116
|
return bang(workflow.builderBase.LoadImageMask, "host has no LoadImageMask node")({
|
|
2116
2117
|
image: enumName,
|
|
2117
2118
|
channel
|
|
@@ -2259,6 +2260,18 @@ var MediaImage = class MediaImage {
|
|
|
2259
2260
|
* A claim is released as soon as the write lands (the file itself then holds
|
|
2260
2261
|
* the name) or fails (the name is free again) — the set never accumulates */
|
|
2261
2262
|
const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
|
|
2263
|
+
const AUDIO_MIMES = {
|
|
2264
|
+
flac: "audio/flac",
|
|
2265
|
+
mp3: "audio/mpeg",
|
|
2266
|
+
opus: "audio/ogg",
|
|
2267
|
+
ogg: "audio/ogg",
|
|
2268
|
+
wav: "audio/wav",
|
|
2269
|
+
m4a: "audio/mp4"
|
|
2270
|
+
};
|
|
2271
|
+
function audioMime(filename) {
|
|
2272
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
|
2273
|
+
return AUDIO_MIMES[ext] ?? "application/octet-stream";
|
|
2274
|
+
}
|
|
2262
2275
|
var ComfyExecution = class {
|
|
2263
2276
|
get host() {
|
|
2264
2277
|
return this.workflow.host;
|
|
@@ -2333,8 +2346,51 @@ var ComfyExecution = class {
|
|
|
2333
2346
|
error: e
|
|
2334
2347
|
});
|
|
2335
2348
|
}));
|
|
2349
|
+
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveAudio(audio, promptNodeID).catch((e) => {
|
|
2350
|
+
console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
|
|
2351
|
+
this.audioErrors.push({
|
|
2352
|
+
audio,
|
|
2353
|
+
error: e
|
|
2354
|
+
});
|
|
2355
|
+
}));
|
|
2336
2356
|
};
|
|
2337
2357
|
this.pendingPromises = [];
|
|
2358
|
+
this.audioErrors = [];
|
|
2359
|
+
this.audios = [];
|
|
2360
|
+
this.retrieveAudio = async (info, promptNodeID) => {
|
|
2361
|
+
const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
|
|
2362
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2363
|
+
const mime = audioMime(info.filename);
|
|
2364
|
+
const sf = this.save;
|
|
2365
|
+
if (sf == null) {
|
|
2366
|
+
this.audios.push({
|
|
2367
|
+
nodeId: promptNodeID,
|
|
2368
|
+
filename: info.filename,
|
|
2369
|
+
mime,
|
|
2370
|
+
bytes,
|
|
2371
|
+
absPath: null
|
|
2372
|
+
});
|
|
2373
|
+
return;
|
|
2374
|
+
}
|
|
2375
|
+
const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs["filename_prefix"];
|
|
2376
|
+
const written = await this.encodeAndWrite({
|
|
2377
|
+
bytes,
|
|
2378
|
+
sf: {
|
|
2379
|
+
...sf,
|
|
2380
|
+
format: "raw"
|
|
2381
|
+
},
|
|
2382
|
+
filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
|
|
2383
|
+
subfolder: info.subfolder,
|
|
2384
|
+
filename: info.filename
|
|
2385
|
+
});
|
|
2386
|
+
this.audios.push({
|
|
2387
|
+
nodeId: promptNodeID,
|
|
2388
|
+
filename: info.filename,
|
|
2389
|
+
mime,
|
|
2390
|
+
bytes,
|
|
2391
|
+
absPath: written.path
|
|
2392
|
+
});
|
|
2393
|
+
};
|
|
2338
2394
|
this.imageErrors = [];
|
|
2339
2395
|
this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
|
|
2340
2396
|
const promptNode = this.workflow.data.apiJson?.[promptNodeID];
|
|
@@ -2506,6 +2562,7 @@ var ComfyExecution = class {
|
|
|
2506
2562
|
if (!this.logProgress) return;
|
|
2507
2563
|
const p = this.progress;
|
|
2508
2564
|
const outputs = [`${this.images.length} image(s)`];
|
|
2565
|
+
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
|
|
2509
2566
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
|
|
2510
2567
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
|
|
2511
2568
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
@@ -2736,6 +2793,7 @@ var ComfyWorkflow = class {
|
|
|
2736
2793
|
constructor(host, data) {
|
|
2737
2794
|
this.host = host;
|
|
2738
2795
|
this.data = data;
|
|
2796
|
+
this.dry = false;
|
|
2739
2797
|
this.nodes = [];
|
|
2740
2798
|
this.registerNode = (node) => {
|
|
2741
2799
|
if (this.data.apiJson == null) throw new Error("graph not hydrated");
|
|
@@ -3233,7 +3291,7 @@ function codegenSDK(opts) {
|
|
|
3233
3291
|
p("}");
|
|
3234
3292
|
p(`interface Builder {`);
|
|
3235
3293
|
for (const n of nodes) {
|
|
3236
|
-
const baseDescription = `displayName="${n.raw.display_name}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
|
|
3294
|
+
const baseDescription = `displayName="${n.raw.display_name ?? n.nameInComfy}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
|
|
3237
3295
|
if (n.raw.description) {
|
|
3238
3296
|
p(` /**`);
|
|
3239
3297
|
p(n.raw.description.split("\n").map((i) => ` * ${i}`).join("\n"));
|
|
@@ -3587,16 +3645,16 @@ const types = scope({
|
|
|
3587
3645
|
"hidden?": "string[]"
|
|
3588
3646
|
},
|
|
3589
3647
|
output: "ComfyInputType[]",
|
|
3590
|
-
output_is_list: "boolean[]",
|
|
3648
|
+
output_is_list: "(boolean | null)[]",
|
|
3591
3649
|
output_name: "string[]",
|
|
3592
3650
|
name: "string",
|
|
3593
|
-
display_name: "string",
|
|
3651
|
+
display_name: "string | null",
|
|
3594
3652
|
description: "string",
|
|
3595
3653
|
/** */
|
|
3596
3654
|
python_module: "string",
|
|
3597
3655
|
category: "string",
|
|
3598
3656
|
output_node: "boolean",
|
|
3599
|
-
"output_tooltips?": "string[]",
|
|
3657
|
+
"output_tooltips?": "(string | null)[]",
|
|
3600
3658
|
"deprecated?": "boolean",
|
|
3601
3659
|
"experimental?": "boolean"
|
|
3602
3660
|
},
|
|
@@ -3612,7 +3670,7 @@ const types = scope({
|
|
|
3612
3670
|
ComfyInputOpts_advanced: {
|
|
3613
3671
|
"tooltip?": "string | null | ComfyInputOpts_advanced",
|
|
3614
3672
|
"multiline?": "boolean | null",
|
|
3615
|
-
"default?": "boolean | number | string | null | number[]",
|
|
3673
|
+
"default?": "boolean | number | string | null | number[] | object",
|
|
3616
3674
|
"forceInput?": "boolean | null",
|
|
3617
3675
|
"min?": "number | null",
|
|
3618
3676
|
"round?": "boolean | number | null",
|
|
@@ -3973,14 +4031,46 @@ var ResilientWebSocketClient = class {
|
|
|
3973
4031
|
this.isOpen = false;
|
|
3974
4032
|
this.debugMessages = [];
|
|
3975
4033
|
this.hasEverOpened = false;
|
|
4034
|
+
this.heartbeat = null;
|
|
3976
4035
|
this.permanentlyClosed = false;
|
|
3977
4036
|
this.url = options.url();
|
|
3978
4037
|
this.connect();
|
|
3979
4038
|
}
|
|
4039
|
+
stopHeartbeat() {
|
|
4040
|
+
if (this.heartbeat != null) clearInterval(this.heartbeat);
|
|
4041
|
+
this.heartbeat = null;
|
|
4042
|
+
}
|
|
4043
|
+
/** ping on a timer; no pong since the previous ping = the peer is gone, drop the socket */
|
|
4044
|
+
startHeartbeat(ws) {
|
|
4045
|
+
this.stopHeartbeat();
|
|
4046
|
+
if (typeof ws.ping !== "function" || typeof ws.on !== "function") return;
|
|
4047
|
+
let awaitingPong = false;
|
|
4048
|
+
ws.on("pong", () => {
|
|
4049
|
+
awaitingPong = false;
|
|
4050
|
+
});
|
|
4051
|
+
const ms = this.options.heartbeatMs ?? 15e3;
|
|
4052
|
+
this.heartbeat = setInterval(() => {
|
|
4053
|
+
if (ws !== this.currentWS) return this.stopHeartbeat();
|
|
4054
|
+
if (awaitingPong) {
|
|
4055
|
+
this.addError(`no pong within ${ms}ms: the host is gone, dropping the socket to reconnect`);
|
|
4056
|
+
this.stopHeartbeat();
|
|
4057
|
+
if (typeof ws.terminate === "function") ws.terminate();
|
|
4058
|
+
else ws.close();
|
|
4059
|
+
return;
|
|
4060
|
+
}
|
|
4061
|
+
awaitingPong = true;
|
|
4062
|
+
try {
|
|
4063
|
+
ws.ping?.();
|
|
4064
|
+
} catch (e) {
|
|
4065
|
+
this.addError(`ping failed: ${extractErrorMessage(e)}`);
|
|
4066
|
+
}
|
|
4067
|
+
}, ms);
|
|
4068
|
+
}
|
|
3980
4069
|
/** close and stop reconnecting (lets a script exit cleanly) */
|
|
3981
4070
|
disconnectPermanently() {
|
|
3982
4071
|
this.permanentlyClosed = true;
|
|
3983
4072
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
4073
|
+
this.stopHeartbeat();
|
|
3984
4074
|
this.currentWS?.close();
|
|
3985
4075
|
this.currentWS = null;
|
|
3986
4076
|
this.isOpen = false;
|
|
@@ -3999,6 +4089,7 @@ var ResilientWebSocketClient = class {
|
|
|
3999
4089
|
this.isOpen = false;
|
|
4000
4090
|
const prevWS = this.currentWS;
|
|
4001
4091
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
4092
|
+
this.stopHeartbeat();
|
|
4002
4093
|
this.currentWS = null;
|
|
4003
4094
|
if (prevWS) {
|
|
4004
4095
|
this.addInfo("Previous WebSocket discarded");
|
|
@@ -4006,7 +4097,7 @@ var ResilientWebSocketClient = class {
|
|
|
4006
4097
|
}
|
|
4007
4098
|
let ws;
|
|
4008
4099
|
try {
|
|
4009
|
-
const transport = await resolveWsTransport();
|
|
4100
|
+
const transport = this.options.transport ?? await resolveWsTransport();
|
|
4010
4101
|
if (this.permanentlyClosed) return;
|
|
4011
4102
|
const headers = this.options.headers?.() ?? {};
|
|
4012
4103
|
ws = transport.supportsHeaders ? new transport.ctor(this.url, { headers }) : new transport.ctor(this.headerlessUrl(headers));
|
|
@@ -4028,10 +4119,12 @@ var ResilientWebSocketClient = class {
|
|
|
4028
4119
|
this.isOpen = true;
|
|
4029
4120
|
this.options.onConnectOrReconnect();
|
|
4030
4121
|
this.flushMessageBuffer();
|
|
4122
|
+
this.startHeartbeat(ws);
|
|
4031
4123
|
};
|
|
4032
4124
|
ws.onclose = (event) => {
|
|
4033
4125
|
if (ws !== this.currentWS) return;
|
|
4034
4126
|
this.isOpen = false;
|
|
4127
|
+
this.stopHeartbeat();
|
|
4035
4128
|
this.options.onClose();
|
|
4036
4129
|
if (this.permanentlyClosed) return;
|
|
4037
4130
|
this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
|
|
@@ -4040,8 +4133,9 @@ var ResilientWebSocketClient = class {
|
|
|
4040
4133
|
this.options.onFirstConnectFailed(/* @__PURE__ */ new Error(`connection refused (code=${event.code}${event.reason === "" ? "" : `, ${event.reason}`})`));
|
|
4041
4134
|
return;
|
|
4042
4135
|
}
|
|
4043
|
-
this.
|
|
4044
|
-
this.
|
|
4136
|
+
const wait = this.options.reconnectMs ?? 2e3;
|
|
4137
|
+
this.addInfo(`⏱️ reconnecting in ${wait / 1e3} seconds...`);
|
|
4138
|
+
this.reconnectTimeout = setTimeout(() => void this.connect(), wait);
|
|
4045
4139
|
};
|
|
4046
4140
|
ws.onerror = (event) => {
|
|
4047
4141
|
if (ws !== this.currentWS) return;
|
|
@@ -4341,6 +4435,221 @@ function writeKeywords() {
|
|
|
4341
4435
|
}
|
|
4342
4436
|
}
|
|
4343
4437
|
//#endregion
|
|
4438
|
+
//#region src/vars/loraEntry.ts
|
|
4439
|
+
function isLoraEntry(s) {
|
|
4440
|
+
if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
|
|
4441
|
+
const o = s;
|
|
4442
|
+
const st = o.strength;
|
|
4443
|
+
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"));
|
|
4444
|
+
}
|
|
4445
|
+
function isLoraStrength(s) {
|
|
4446
|
+
if (typeof s === "boolean") return true;
|
|
4447
|
+
if (typeof s === "number") return Number.isFinite(s);
|
|
4448
|
+
if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
4449
|
+
return isLoraEntry(s);
|
|
4450
|
+
}
|
|
4451
|
+
/** on = it runs */
|
|
4452
|
+
function loraIsOn(s) {
|
|
4453
|
+
if (s == null || s === false) return false;
|
|
4454
|
+
if (isLoraEntry(s)) return s.off !== true;
|
|
4455
|
+
return true;
|
|
4456
|
+
}
|
|
4457
|
+
/** the strengths, whatever the spelling (1/1 when there is nothing to read) */
|
|
4458
|
+
function loraStrengths(s) {
|
|
4459
|
+
if (typeof s === "number" && Number.isFinite(s)) return [s, s];
|
|
4460
|
+
if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
|
|
4461
|
+
if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
|
|
4462
|
+
return [1, 1];
|
|
4463
|
+
}
|
|
4464
|
+
function loraMuted(s) {
|
|
4465
|
+
return isLoraEntry(s) && s.mute != null ? s.mute : [];
|
|
4466
|
+
}
|
|
4467
|
+
/** a prompt keyword's parts, split at commas: each one can be left out on its own */
|
|
4468
|
+
function keywordParts(keyword) {
|
|
4469
|
+
return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
|
|
4470
|
+
}
|
|
4471
|
+
/** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
|
|
4472
|
+
function keptKeyword(keyword, muted) {
|
|
4473
|
+
return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
|
|
4474
|
+
}
|
|
4475
|
+
/** rewrite one setting, keeping what the patch does not name. The result stays in the short
|
|
4476
|
+
* spellings while nothing needs the palette form, so a plain draft reads as it always did */
|
|
4477
|
+
function withLora(s, patch) {
|
|
4478
|
+
const strength = patch.strength ?? loraStrengths(s);
|
|
4479
|
+
const off = patch.on == null ? !loraIsOn(s) : !patch.on;
|
|
4480
|
+
const mute = [...patch.mute ?? loraMuted(s)];
|
|
4481
|
+
if (!off && mute.length === 0) return [strength[0], strength[1]];
|
|
4482
|
+
return {
|
|
4483
|
+
strength: [strength[0], strength[1]],
|
|
4484
|
+
...off ? { off: true } : {},
|
|
4485
|
+
...mute.length === 0 ? {} : { mute }
|
|
4486
|
+
};
|
|
4487
|
+
}
|
|
4488
|
+
//#endregion
|
|
4489
|
+
//#region src/vars/lanes.ts
|
|
4490
|
+
const FIRST_LANE = "main";
|
|
4491
|
+
function isObject(v) {
|
|
4492
|
+
return typeof v === "object" && v != null && !Array.isArray(v);
|
|
4493
|
+
}
|
|
4494
|
+
function isPromptLane(v) {
|
|
4495
|
+
return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
|
|
4496
|
+
}
|
|
4497
|
+
function isPromptLanes(v) {
|
|
4498
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
|
|
4499
|
+
}
|
|
4500
|
+
/** the text the build reads: the active lanes joined in order, one line break between them, so
|
|
4501
|
+
* `//` and `- ` lines keep working inside every lane */
|
|
4502
|
+
function promptText(v) {
|
|
4503
|
+
if (typeof v === "string") return v;
|
|
4504
|
+
return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
|
|
4505
|
+
}
|
|
4506
|
+
const HEADER = /^# (.+?)( \(off\))?$/;
|
|
4507
|
+
function promptLanesToText(v) {
|
|
4508
|
+
return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
|
|
4509
|
+
}
|
|
4510
|
+
/** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
|
|
4511
|
+
function promptLanesFromText(text) {
|
|
4512
|
+
const lanes = [];
|
|
4513
|
+
let current = null;
|
|
4514
|
+
const body = [];
|
|
4515
|
+
const close = () => {
|
|
4516
|
+
if (current != null) lanes.push({
|
|
4517
|
+
...current,
|
|
4518
|
+
prompt: body.join("\n")
|
|
4519
|
+
});
|
|
4520
|
+
else if (body.some((l) => l.trim() !== "")) lanes.push({
|
|
4521
|
+
name: FIRST_LANE,
|
|
4522
|
+
prompt: body.join("\n"),
|
|
4523
|
+
active: true
|
|
4524
|
+
});
|
|
4525
|
+
body.length = 0;
|
|
4526
|
+
};
|
|
4527
|
+
for (const line of text.split("\n")) {
|
|
4528
|
+
const m = HEADER.exec(line);
|
|
4529
|
+
if (m == null) {
|
|
4530
|
+
body.push(line);
|
|
4531
|
+
continue;
|
|
4532
|
+
}
|
|
4533
|
+
close();
|
|
4534
|
+
current = {
|
|
4535
|
+
name: (m[1] ?? "").trim(),
|
|
4536
|
+
prompt: "",
|
|
4537
|
+
active: m[2] == null
|
|
4538
|
+
};
|
|
4539
|
+
}
|
|
4540
|
+
close();
|
|
4541
|
+
return { lanes: lanes.length > 0 ? lanes : [{
|
|
4542
|
+
name: FIRST_LANE,
|
|
4543
|
+
prompt: "",
|
|
4544
|
+
active: true
|
|
4545
|
+
}] };
|
|
4546
|
+
}
|
|
4547
|
+
function isLoraRecord(v) {
|
|
4548
|
+
return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
|
|
4549
|
+
}
|
|
4550
|
+
function isLoraLane(v) {
|
|
4551
|
+
return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
|
|
4552
|
+
}
|
|
4553
|
+
function isLoraLanes(v) {
|
|
4554
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
|
|
4555
|
+
}
|
|
4556
|
+
function isLorasInput(v) {
|
|
4557
|
+
return isLoraRecord(v) || isLoraLanes(v);
|
|
4558
|
+
}
|
|
4559
|
+
/** one record for the build: the active lanes in order. A lora in two active lanes keeps its
|
|
4560
|
+
* FIRST setting, and `duplicates` names it so the caller can say so */
|
|
4561
|
+
function flattenLoras(v) {
|
|
4562
|
+
if (!isLoraLanes(v)) return {
|
|
4563
|
+
record: v,
|
|
4564
|
+
duplicates: []
|
|
4565
|
+
};
|
|
4566
|
+
const record = {};
|
|
4567
|
+
const duplicates = [];
|
|
4568
|
+
for (const lane of v.lanes) {
|
|
4569
|
+
if (!lane.active) continue;
|
|
4570
|
+
for (const [name, st] of Object.entries(lane.loras)) {
|
|
4571
|
+
if (st == null) continue;
|
|
4572
|
+
if (name in record) duplicates.push(name);
|
|
4573
|
+
else record[name] = st;
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
return {
|
|
4577
|
+
record,
|
|
4578
|
+
duplicates
|
|
4579
|
+
};
|
|
4580
|
+
}
|
|
4581
|
+
/** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
|
|
4582
|
+
* has it (the one the build reads), else any lane, else -1 */
|
|
4583
|
+
function laneIndexOf(v, name) {
|
|
4584
|
+
const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
|
|
4585
|
+
return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
|
|
4586
|
+
}
|
|
4587
|
+
/** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
|
|
4588
|
+
* A lora in no lane yet lands in the first lane */
|
|
4589
|
+
function updateLora(v, name, next) {
|
|
4590
|
+
const write = (rec) => {
|
|
4591
|
+
const out = { ...rec };
|
|
4592
|
+
if (next == null) delete out[name];
|
|
4593
|
+
else out[name] = next;
|
|
4594
|
+
return out;
|
|
4595
|
+
};
|
|
4596
|
+
if (!isLoraLanes(v)) return write(v);
|
|
4597
|
+
if (v.lanes.length === 0) return { lanes: [{
|
|
4598
|
+
name: FIRST_LANE,
|
|
4599
|
+
active: true,
|
|
4600
|
+
loras: write({})
|
|
4601
|
+
}] };
|
|
4602
|
+
const found = laneIndexOf(v, name);
|
|
4603
|
+
const ix = found === -1 ? 0 : found;
|
|
4604
|
+
return { lanes: v.lanes.map((l, i) => i === ix ? {
|
|
4605
|
+
...l,
|
|
4606
|
+
loras: write(l.loras)
|
|
4607
|
+
} : l) };
|
|
4608
|
+
}
|
|
4609
|
+
//#endregion
|
|
4610
|
+
//#region src/vars/promptSyntax.ts
|
|
4611
|
+
/** a whole line that is a comment (the TUI colors these) */
|
|
4612
|
+
const COMMENT_LINE_RE = /^\s*\/\//;
|
|
4613
|
+
/** a negative prompt line: `- ` then its text */
|
|
4614
|
+
const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
|
|
4615
|
+
const NEGATIVE_PREFIX_RE = /^(\s*)- /;
|
|
4616
|
+
/** where a `//` comment starts on this line, -1 when none. Only at line start or after
|
|
4617
|
+
* whitespace, so `http://host` is never cut */
|
|
4618
|
+
function commentStart(line) {
|
|
4619
|
+
const m = /(?:^|\s)\/\//.exec(line);
|
|
4620
|
+
if (m == null) return -1;
|
|
4621
|
+
return m.index + m[0].length - 2;
|
|
4622
|
+
}
|
|
4623
|
+
/** the line without its comment, trailing whitespace dropped with it */
|
|
4624
|
+
function withoutComment(line) {
|
|
4625
|
+
const c = commentStart(line);
|
|
4626
|
+
return c < 0 ? {
|
|
4627
|
+
text: line,
|
|
4628
|
+
hadComment: false
|
|
4629
|
+
} : {
|
|
4630
|
+
text: line.slice(0, c).trimEnd(),
|
|
4631
|
+
hadComment: true
|
|
4632
|
+
};
|
|
4633
|
+
}
|
|
4634
|
+
/** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
|
|
4635
|
+
function parsePromptText(text) {
|
|
4636
|
+
const pos = [];
|
|
4637
|
+
const neg = [];
|
|
4638
|
+
for (const raw of text.split("\n")) {
|
|
4639
|
+
const cut = withoutComment(raw);
|
|
4640
|
+
if (cut.hadComment && cut.text.trim() === "") continue;
|
|
4641
|
+
const m = NEGATIVE_PREFIX_RE.exec(raw);
|
|
4642
|
+
if (m != null && m[0].length <= cut.text.length + 1) {
|
|
4643
|
+
const body = cut.text.slice(m[0].length).trim();
|
|
4644
|
+
if (body !== "") neg.push(body);
|
|
4645
|
+
} else pos.push(cut.text);
|
|
4646
|
+
}
|
|
4647
|
+
return {
|
|
4648
|
+
positive: pos.join("\n").trim(),
|
|
4649
|
+
negative: neg.join(", ")
|
|
4650
|
+
};
|
|
4651
|
+
}
|
|
4652
|
+
//#endregion
|
|
4344
4653
|
//#region src/vars/presets.ts
|
|
4345
4654
|
function toPresetList(spec) {
|
|
4346
4655
|
if (spec == null) return [];
|
|
@@ -4356,16 +4665,11 @@ function activePresetLabel(presets, value) {
|
|
|
4356
4665
|
}
|
|
4357
4666
|
//#endregion
|
|
4358
4667
|
//#region src/vars/ComfyVars.ts
|
|
4359
|
-
/**
|
|
4360
|
-
* full base: T is what's STORED/edited, Out what the GRAPH consumes at build
|
|
4361
|
-
* time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
|
|
4362
|
-
* the one Out-specialized var (string in, PromptValue out); the split keeps
|
|
4363
|
-
* outValue() cast-free.
|
|
4364
|
-
*/
|
|
4365
4668
|
var ComfyVarBase = class {
|
|
4366
4669
|
constructor(defaultValue, label) {
|
|
4367
4670
|
this.defaultValue = defaultValue;
|
|
4368
4671
|
this.label = label;
|
|
4672
|
+
this.uiOpts = {};
|
|
4369
4673
|
this.value = defaultValue;
|
|
4370
4674
|
makeObservable(this, {
|
|
4371
4675
|
value: observable,
|
|
@@ -4379,6 +4683,14 @@ var ComfyVarBase = class {
|
|
|
4379
4683
|
this.value = value;
|
|
4380
4684
|
return this;
|
|
4381
4685
|
}
|
|
4686
|
+
/** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
|
|
4687
|
+
ui(p) {
|
|
4688
|
+
this.uiOpts = {
|
|
4689
|
+
...this.uiOpts,
|
|
4690
|
+
...p
|
|
4691
|
+
};
|
|
4692
|
+
return this;
|
|
4693
|
+
}
|
|
4382
4694
|
/** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
|
|
4383
4695
|
toJSON() {
|
|
4384
4696
|
return this.value;
|
|
@@ -4426,12 +4738,10 @@ var TextVar = class extends ComfyVar {
|
|
|
4426
4738
|
return true;
|
|
4427
4739
|
}
|
|
4428
4740
|
};
|
|
4429
|
-
const commentLineRe = /^\s*\/\//;
|
|
4430
|
-
const negativeLineRe = /^\s*- (.*)$/;
|
|
4431
4741
|
/**
|
|
4432
4742
|
* prompt text with editor comforts, all resolved at BUILD time (the editor and
|
|
4433
4743
|
* drafts keep the raw text):
|
|
4434
|
-
* - `//`
|
|
4744
|
+
* - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
|
|
4435
4745
|
* - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
|
|
4436
4746
|
* comma-joined into `.negative`
|
|
4437
4747
|
* - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
|
|
@@ -4445,38 +4755,48 @@ var PromptVar = class extends ComfyVarBase {
|
|
|
4445
4755
|
this.kind = "prompt";
|
|
4446
4756
|
this.presets = toPresetList(promptOpts.presets);
|
|
4447
4757
|
}
|
|
4758
|
+
/** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
|
|
4448
4759
|
parse(raw) {
|
|
4449
|
-
this.set(raw);
|
|
4760
|
+
this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
|
|
4450
4761
|
return true;
|
|
4451
4762
|
}
|
|
4763
|
+
toEditBuffer() {
|
|
4764
|
+
return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
|
|
4765
|
+
}
|
|
4766
|
+
/** a var list shows the lanes by name, the inactive ones in parentheses */
|
|
4767
|
+
display() {
|
|
4768
|
+
if (!isPromptLanes(this.value)) return super.display();
|
|
4769
|
+
return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
|
|
4770
|
+
}
|
|
4771
|
+
/** the text the build reads: the plain string, or the active lanes joined in order */
|
|
4772
|
+
get text() {
|
|
4773
|
+
return promptText(this.value);
|
|
4774
|
+
}
|
|
4775
|
+
/** the tag list options in their one object form, null when this prompt has no completion */
|
|
4776
|
+
get tags() {
|
|
4777
|
+
const t = this.promptOpts.tags;
|
|
4778
|
+
if (t == null) return null;
|
|
4779
|
+
return typeof t === "string" ? { url: t } : t;
|
|
4780
|
+
}
|
|
4452
4781
|
static isCommentLine(line) {
|
|
4453
|
-
return
|
|
4782
|
+
return COMMENT_LINE_RE.test(line);
|
|
4454
4783
|
}
|
|
4455
4784
|
static isNegativeLine(line) {
|
|
4456
|
-
return
|
|
4785
|
+
return NEGATIVE_LINE_RE.test(line);
|
|
4457
4786
|
}
|
|
4458
4787
|
/** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
|
|
4459
4788
|
injectedKeywords() {
|
|
4460
4789
|
const src = this.promptOpts.loraKeywordsFrom;
|
|
4461
4790
|
if (src == null) return [];
|
|
4462
|
-
return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
|
|
4791
|
+
return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
|
|
4463
4792
|
}
|
|
4464
4793
|
outValue() {
|
|
4465
|
-
const
|
|
4466
|
-
const
|
|
4467
|
-
for (const line of this.value.split("\n")) {
|
|
4468
|
-
if (commentLineRe.test(line)) continue;
|
|
4469
|
-
const m = negativeLineRe.exec(line);
|
|
4470
|
-
if (m != null) {
|
|
4471
|
-
const text = (m[1] ?? "").trim();
|
|
4472
|
-
if (text !== "") neg.push(text);
|
|
4473
|
-
} else pos.push(line);
|
|
4474
|
-
}
|
|
4475
|
-
const body = pos.join("\n").trim();
|
|
4794
|
+
const parsed = parsePromptText(this.text);
|
|
4795
|
+
const body = parsed.positive;
|
|
4476
4796
|
const keywords = this.injectedKeywords();
|
|
4477
4797
|
return {
|
|
4478
4798
|
positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
|
|
4479
|
-
negative:
|
|
4799
|
+
negative: parsed.negative
|
|
4480
4800
|
};
|
|
4481
4801
|
}
|
|
4482
4802
|
};
|
|
@@ -4616,6 +4936,7 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4616
4936
|
super(defaultValue, label);
|
|
4617
4937
|
this.choices = choices;
|
|
4618
4938
|
this.kind = "choice";
|
|
4939
|
+
this.select = "one";
|
|
4619
4940
|
}
|
|
4620
4941
|
next(delta = 1) {
|
|
4621
4942
|
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
@@ -4628,12 +4949,96 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4628
4949
|
return true;
|
|
4629
4950
|
}
|
|
4630
4951
|
};
|
|
4952
|
+
/** one option or none: `null` is "nothing picked", clicking the lit option clears it */
|
|
4953
|
+
var OptionalChoiceVar = class extends ComfyVar {
|
|
4954
|
+
constructor(choices, defaultValue, label) {
|
|
4955
|
+
super(defaultValue, label);
|
|
4956
|
+
this.choices = choices;
|
|
4957
|
+
this.kind = "choice";
|
|
4958
|
+
this.select = "zero-or-one";
|
|
4959
|
+
}
|
|
4960
|
+
/** pick `c`, or clear it when it is already the one picked */
|
|
4961
|
+
toggle(c) {
|
|
4962
|
+
return this.set(this.value === c ? null : c);
|
|
4963
|
+
}
|
|
4964
|
+
/** the TUI text form: a choice, or an empty line for none */
|
|
4965
|
+
parse(raw) {
|
|
4966
|
+
if (raw.trim() === "") {
|
|
4967
|
+
this.set(null);
|
|
4968
|
+
return true;
|
|
4969
|
+
}
|
|
4970
|
+
const hit = this.choices.find((c) => c === raw.trim());
|
|
4971
|
+
if (hit == null) return false;
|
|
4972
|
+
this.set(hit);
|
|
4973
|
+
return true;
|
|
4974
|
+
}
|
|
4975
|
+
toEditBuffer() {
|
|
4976
|
+
return this.value ?? "";
|
|
4977
|
+
}
|
|
4978
|
+
/** a draft from when this was a many choice holds a list: its first known option */
|
|
4979
|
+
loadJSON(value) {
|
|
4980
|
+
const one = Array.isArray(value) ? value[0] : value;
|
|
4981
|
+
return this.set(this.choices.find((c) => c === one) ?? null);
|
|
4982
|
+
}
|
|
4983
|
+
display() {
|
|
4984
|
+
return this.value ?? "none";
|
|
4985
|
+
}
|
|
4986
|
+
};
|
|
4987
|
+
/** any number of options, kept in the order the choices list them */
|
|
4988
|
+
var MultiChoiceVar = class extends ComfyVar {
|
|
4989
|
+
constructor(choices, defaultValue, label) {
|
|
4990
|
+
super([...defaultValue], label);
|
|
4991
|
+
this.choices = choices;
|
|
4992
|
+
this.kind = "choice";
|
|
4993
|
+
this.select = "many";
|
|
4994
|
+
}
|
|
4995
|
+
toggle(c) {
|
|
4996
|
+
const on = this.value.includes(c);
|
|
4997
|
+
return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
|
|
4998
|
+
}
|
|
4999
|
+
/** the TUI text form: `a, b` */
|
|
5000
|
+
parse(raw) {
|
|
5001
|
+
const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
|
|
5002
|
+
const picked = this.choices.filter((c) => wanted.includes(c));
|
|
5003
|
+
if (picked.length !== new Set(wanted).size) return false;
|
|
5004
|
+
this.set(picked);
|
|
5005
|
+
return true;
|
|
5006
|
+
}
|
|
5007
|
+
toEditBuffer() {
|
|
5008
|
+
return this.value.join(", ");
|
|
5009
|
+
}
|
|
5010
|
+
/** a draft from when this was a single choice holds one value: a list of one. Unknown
|
|
5011
|
+
* options are dropped, the list comes back in the choices order */
|
|
5012
|
+
loadJSON(value) {
|
|
5013
|
+
const listed = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
5014
|
+
return this.set(this.choices.filter((c) => listed.includes(c)));
|
|
5015
|
+
}
|
|
5016
|
+
display() {
|
|
5017
|
+
return this.value.length === 0 ? "none" : this.value.join(", ");
|
|
5018
|
+
}
|
|
5019
|
+
};
|
|
5020
|
+
/** Array.isArray does not narrow a READONLY array out of a union, this does */
|
|
5021
|
+
function isChoiceList(v) {
|
|
5022
|
+
return Array.isArray(v);
|
|
5023
|
+
}
|
|
5024
|
+
function choice(choices, defaultValue, opts) {
|
|
5025
|
+
const o = typeof opts === "string" ? { label: opts } : opts ?? {};
|
|
5026
|
+
const select = o.select ?? "one";
|
|
5027
|
+
if (select === "many") {
|
|
5028
|
+
if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
|
|
5029
|
+
return new MultiChoiceVar(choices, defaultValue, o.label);
|
|
5030
|
+
}
|
|
5031
|
+
if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
|
|
5032
|
+
if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
|
|
5033
|
+
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
5034
|
+
return new ChoiceVar(choices, defaultValue, o.label);
|
|
5035
|
+
}
|
|
4631
5036
|
/** normalize a loras record into what a standard LoraLoader chain consumes */
|
|
4632
5037
|
function activeLoras(loras) {
|
|
4633
5038
|
const out = [];
|
|
4634
|
-
for (const [lora_name, s] of Object.entries(loras)) {
|
|
4635
|
-
if (s
|
|
4636
|
-
const [strength_model, strength_clip] =
|
|
5039
|
+
for (const [lora_name, s] of Object.entries(flattenLoras(loras).record)) {
|
|
5040
|
+
if (!loraIsOn(s)) continue;
|
|
5041
|
+
const [strength_model, strength_clip] = loraStrengths(s);
|
|
4637
5042
|
out.push({
|
|
4638
5043
|
lora_name,
|
|
4639
5044
|
strength_model,
|
|
@@ -4648,7 +5053,12 @@ function activeLoras(loras) {
|
|
|
4648
5053
|
* or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
|
|
4649
5054
|
* a hardcoded inventory. Selection is empty by default.
|
|
4650
5055
|
*/
|
|
4651
|
-
|
|
5056
|
+
/**
|
|
5057
|
+
* the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
|
|
5058
|
+
* build merges in listed order, skipping inactive ones. Every method reads the merged record and
|
|
5059
|
+
* writes into the lane that holds the lora, so the TUI never needs to know lanes exist
|
|
5060
|
+
*/
|
|
5061
|
+
var LorasVar = class LorasVar extends ComfyVarBase {
|
|
4652
5062
|
constructor(optionsSource, initial = {}, label) {
|
|
4653
5063
|
super(initial, label);
|
|
4654
5064
|
this.optionsSource = optionsSource;
|
|
@@ -4679,49 +5089,57 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4679
5089
|
get names() {
|
|
4680
5090
|
return [...this.options];
|
|
4681
5091
|
}
|
|
5092
|
+
/** the loras the build reads: the plain record, or the active lanes merged in order */
|
|
5093
|
+
get record() {
|
|
5094
|
+
return flattenLoras(this.value).record;
|
|
5095
|
+
}
|
|
5096
|
+
/** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
|
|
5097
|
+
outValue() {
|
|
5098
|
+
const flat = flattenLoras(this.value);
|
|
5099
|
+
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`);
|
|
5100
|
+
return flat.record;
|
|
5101
|
+
}
|
|
5102
|
+
/** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
|
|
5103
|
+
write(name, next) {
|
|
5104
|
+
return this.set(updateLora(this.value, name, next));
|
|
5105
|
+
}
|
|
5106
|
+
/** the parts of this lora's prompt keyword left out of the prompt */
|
|
5107
|
+
mutedWords(name) {
|
|
5108
|
+
return loraMuted(this.record[name]);
|
|
5109
|
+
}
|
|
4682
5110
|
/** loras currently ON (PromptVar keyword prefixing consumes this) */
|
|
4683
5111
|
activeNames() {
|
|
4684
5112
|
return this.names.filter((n) => this.isOn(n));
|
|
4685
5113
|
}
|
|
4686
5114
|
isOn(name) {
|
|
4687
|
-
|
|
4688
|
-
return s != null && s !== false;
|
|
5115
|
+
return loraIsOn(this.record[name]);
|
|
4689
5116
|
}
|
|
4690
5117
|
toggleItem(name) {
|
|
4691
|
-
const cur = this.
|
|
4692
|
-
if (cur == null || cur === false) return this.
|
|
4693
|
-
|
|
4694
|
-
[name]: this.prev[name] ?? true
|
|
4695
|
-
});
|
|
5118
|
+
const cur = this.record[name];
|
|
5119
|
+
if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
|
|
5120
|
+
if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
|
|
4696
5121
|
this.prev[name] = cur;
|
|
4697
|
-
return this.
|
|
4698
|
-
...this.value,
|
|
4699
|
-
[name]: false
|
|
4700
|
-
});
|
|
5122
|
+
return this.write(name, false);
|
|
4701
5123
|
}
|
|
4702
5124
|
/** step both strengths by delta (true becomes 1 first); no-op when off */
|
|
4703
5125
|
adjustItem(name, delta) {
|
|
4704
|
-
const cur = this.
|
|
4705
|
-
if (cur
|
|
5126
|
+
const cur = this.record[name];
|
|
5127
|
+
if (!loraIsOn(cur)) return this;
|
|
4706
5128
|
const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
|
|
4707
|
-
const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] :
|
|
4708
|
-
return this.
|
|
4709
|
-
...this.value,
|
|
4710
|
-
[name]: next
|
|
4711
|
-
});
|
|
5129
|
+
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])] });
|
|
5130
|
+
return this.write(name, next);
|
|
4712
5131
|
}
|
|
4713
5132
|
/** compact per-item strength label for lists */
|
|
4714
5133
|
strengthLabel(name) {
|
|
4715
|
-
const s = this.
|
|
4716
|
-
if (s
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
return s.toFixed(2);
|
|
5134
|
+
const s = this.record[name];
|
|
5135
|
+
if (!loraIsOn(s)) return "";
|
|
5136
|
+
const [m, c] = loraStrengths(s);
|
|
5137
|
+
return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
|
|
4720
5138
|
}
|
|
4721
5139
|
parse(raw) {
|
|
4722
5140
|
try {
|
|
4723
5141
|
const parsed = JSON.parse(raw);
|
|
4724
|
-
if (
|
|
5142
|
+
if (!isLorasInput(parsed)) return false;
|
|
4725
5143
|
this.set(parsed);
|
|
4726
5144
|
return true;
|
|
4727
5145
|
} catch {
|
|
@@ -4734,14 +5152,16 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4734
5152
|
}
|
|
4735
5153
|
/** tick (true) or untick (false) every lora in `names` (default: all options) */
|
|
4736
5154
|
setAll(on, names = this.options) {
|
|
4737
|
-
const
|
|
5155
|
+
const record = this.record;
|
|
5156
|
+
let next = this.value;
|
|
4738
5157
|
for (const name of names) {
|
|
4739
|
-
const cur =
|
|
5158
|
+
const cur = record[name];
|
|
4740
5159
|
if (on) {
|
|
4741
|
-
if (cur == null || cur === false) next
|
|
5160
|
+
if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
|
|
5161
|
+
else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
|
|
4742
5162
|
} else {
|
|
4743
|
-
if (cur
|
|
4744
|
-
next
|
|
5163
|
+
if (loraIsOn(cur)) this.prev[name] = cur;
|
|
5164
|
+
next = updateLora(next, name, false);
|
|
4745
5165
|
}
|
|
4746
5166
|
}
|
|
4747
5167
|
return this.set(next);
|
|
@@ -4790,6 +5210,56 @@ const DEFAULT_SIZE_PRESETS = [
|
|
|
4790
5210
|
height: 1344
|
|
4791
5211
|
}
|
|
4792
5212
|
];
|
|
5213
|
+
/** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
|
|
5214
|
+
const SD15_SIZE_PRESETS = [
|
|
5215
|
+
{
|
|
5216
|
+
label: "1:1 square",
|
|
5217
|
+
width: 512,
|
|
5218
|
+
height: 512
|
|
5219
|
+
},
|
|
5220
|
+
{
|
|
5221
|
+
label: "4:3 landscape",
|
|
5222
|
+
width: 576,
|
|
5223
|
+
height: 448
|
|
5224
|
+
},
|
|
5225
|
+
{
|
|
5226
|
+
label: "3:4 portrait",
|
|
5227
|
+
width: 448,
|
|
5228
|
+
height: 576
|
|
5229
|
+
},
|
|
5230
|
+
{
|
|
5231
|
+
label: "3:2 landscape",
|
|
5232
|
+
width: 576,
|
|
5233
|
+
height: 384
|
|
5234
|
+
},
|
|
5235
|
+
{
|
|
5236
|
+
label: "2:3 portrait",
|
|
5237
|
+
width: 384,
|
|
5238
|
+
height: 576
|
|
5239
|
+
},
|
|
5240
|
+
{
|
|
5241
|
+
label: "16:9 widescreen",
|
|
5242
|
+
width: 704,
|
|
5243
|
+
height: 384
|
|
5244
|
+
},
|
|
5245
|
+
{
|
|
5246
|
+
label: "9:16 tall",
|
|
5247
|
+
width: 384,
|
|
5248
|
+
height: 704
|
|
5249
|
+
}
|
|
5250
|
+
];
|
|
5251
|
+
/** starred presets are one click away in the panel, before the full list */
|
|
5252
|
+
const DEFAULT_STARRED_SIZES = [
|
|
5253
|
+
"1:1 square",
|
|
5254
|
+
"3:4 portrait",
|
|
5255
|
+
"4:3 landscape"
|
|
5256
|
+
];
|
|
5257
|
+
/** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
|
|
5258
|
+
* and offering it 1024 buckets would be offering sizes it was never trained at */
|
|
5259
|
+
function sizePresetsFor(defaultValue) {
|
|
5260
|
+
if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
|
|
5261
|
+
return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
|
|
5262
|
+
}
|
|
4793
5263
|
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
4794
5264
|
* size of a linked image var (the widget shows
|
|
4795
5265
|
* `WxH size of image '<name>'` as a pickable row) */
|
|
@@ -4797,10 +5267,11 @@ var SizeVar = class extends ComfyVar {
|
|
|
4797
5267
|
constructor(defaultValue = {
|
|
4798
5268
|
width: 1024,
|
|
4799
5269
|
height: 1024
|
|
4800
|
-
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
|
|
5270
|
+
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
|
|
4801
5271
|
super(defaultValue, label);
|
|
4802
5272
|
this.presets = presets;
|
|
4803
5273
|
this.imageVar = imageVar;
|
|
5274
|
+
this.starred = starred;
|
|
4804
5275
|
this.kind = "size";
|
|
4805
5276
|
}
|
|
4806
5277
|
/** current dimensions of the linked image var — null when no link, unset
|
|
@@ -4925,9 +5396,11 @@ const v = {
|
|
|
4925
5396
|
* which is what a tuning session wants, and reset()/revert come back to it */
|
|
4926
5397
|
seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
|
|
4927
5398
|
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
4928
|
-
|
|
5399
|
+
/** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
|
|
5400
|
+
* `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
|
|
5401
|
+
choice,
|
|
4929
5402
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
4930
|
-
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
|
|
5403
|
+
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
4931
5404
|
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
|
|
4932
5405
|
};
|
|
4933
5406
|
function varValues(vars) {
|
|
@@ -4956,6 +5429,29 @@ var DefinedWorkflow = class {
|
|
|
4956
5429
|
varDef.name = key;
|
|
4957
5430
|
varDef.bindHost?.(this.host);
|
|
4958
5431
|
}
|
|
5432
|
+
const names = this.entries().map(([key]) => key);
|
|
5433
|
+
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(", ")})`);
|
|
5434
|
+
}
|
|
5435
|
+
/** every preview for the current var values. A preview that throws, or vars that cannot be
|
|
5436
|
+
* read yet (an image var still empty), give a line saying so instead of failing the others */
|
|
5437
|
+
computePreviews() {
|
|
5438
|
+
const previews = this.spec.previews ?? {};
|
|
5439
|
+
const names = Object.keys(previews);
|
|
5440
|
+
if (names.length === 0) return {};
|
|
5441
|
+
let values;
|
|
5442
|
+
try {
|
|
5443
|
+
values = varValues(this.vars);
|
|
5444
|
+
} catch (e) {
|
|
5445
|
+
const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
|
|
5446
|
+
return Object.fromEntries(names.map((n) => [n, why]));
|
|
5447
|
+
}
|
|
5448
|
+
const out = {};
|
|
5449
|
+
for (const [name, fn] of Object.entries(previews)) try {
|
|
5450
|
+
out[name] = fn(values);
|
|
5451
|
+
} catch (e) {
|
|
5452
|
+
out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
5453
|
+
}
|
|
5454
|
+
return out;
|
|
4959
5455
|
}
|
|
4960
5456
|
/** [name, var] pairs, for drivers that enumerate the knobs */
|
|
4961
5457
|
entries() {
|
|
@@ -4969,12 +5465,15 @@ var DefinedWorkflow = class {
|
|
|
4969
5465
|
* build() for copy/export never advances). `p.host` substitutes the host
|
|
4970
5466
|
* the graph is built against (TUI host override): node/model availability
|
|
4971
5467
|
* there surfaces as workflow.problems / server validation, by design.
|
|
5468
|
+
* `p.dry` builds a graph only to read it: nothing is uploaded, lastWorkflow is left alone.
|
|
4972
5469
|
*/
|
|
4973
5470
|
async build(p = {}) {
|
|
4974
5471
|
const wf = (p.host ?? this.host).workflow({ id: this.spec.id });
|
|
5472
|
+
wf.dry = p.dry === true;
|
|
4975
5473
|
const values = varValues(this.vars);
|
|
4976
5474
|
if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
|
|
4977
5475
|
await this.spec.build(wf.builder, values, wf);
|
|
5476
|
+
if (wf.dry) return wf;
|
|
4978
5477
|
this.lastWorkflow = wf;
|
|
4979
5478
|
return wf;
|
|
4980
5479
|
}
|
|
@@ -5275,8 +5774,22 @@ var ComfyHost = class {
|
|
|
5275
5774
|
this.clearQueue = () => {
|
|
5276
5775
|
return this.postJSON_("/queue", { clear: true });
|
|
5277
5776
|
};
|
|
5777
|
+
this.interruptCoalesceMs = 3e3;
|
|
5778
|
+
this._lastInterrupt = null;
|
|
5278
5779
|
this.interrupt = () => {
|
|
5279
|
-
|
|
5780
|
+
const now = Date.now();
|
|
5781
|
+
const last = this._lastInterrupt;
|
|
5782
|
+
if (last != null && last.promptID === this.activePromptID && now - last.at < this.interruptCoalesceMs) return last.req;
|
|
5783
|
+
const req = this.postJSON_("/interrupt", {});
|
|
5784
|
+
this._lastInterrupt = {
|
|
5785
|
+
promptID: this.activePromptID,
|
|
5786
|
+
at: now,
|
|
5787
|
+
req
|
|
5788
|
+
};
|
|
5789
|
+
req.catch(() => {
|
|
5790
|
+
if (this._lastInterrupt?.req === req) this._lastInterrupt = null;
|
|
5791
|
+
});
|
|
5792
|
+
return req;
|
|
5280
5793
|
};
|
|
5281
5794
|
this.deleteHistory = (promptId) => {
|
|
5282
5795
|
return this.postJSON_("/history", { delete: [promptId] });
|
|
@@ -6261,6 +6774,10 @@ var ComfyTS = class ComfyTS {
|
|
|
6261
6774
|
resolveFromPromptEnhancers(relativePath) {
|
|
6262
6775
|
return asAbsolutePath(join(this.baseFolder, "prompt-enhancers", relativePath));
|
|
6263
6776
|
}
|
|
6777
|
+
/** the serve web ui's LLM configs (prompt enhancer), one json per config */
|
|
6778
|
+
resolveFromLlmConfigs(relativePath) {
|
|
6779
|
+
return asAbsolutePath(join(this.baseFolder, "llm-configs", relativePath));
|
|
6780
|
+
}
|
|
6264
6781
|
resolveFromCache(relativePath) {
|
|
6265
6782
|
return asAbsolutePath(join(this.baseFolder, "cache", relativePath));
|
|
6266
6783
|
}
|
|
@@ -6308,6 +6825,6 @@ function loraTag(name, strength = 1, clipStrength) {
|
|
|
6308
6825
|
*/
|
|
6309
6826
|
setDefaultComfyStorage(createMemoryStorage());
|
|
6310
6827
|
//#endregion
|
|
6311
|
-
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, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, toPresetList, v };
|
|
6828
|
+
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, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
|
|
6312
6829
|
|
|
6313
6830
|
//# sourceMappingURL=web.js.map
|