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.cjs
CHANGED
|
@@ -134,7 +134,7 @@ function createNodeStorage() {
|
|
|
134
134
|
}
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region package.json
|
|
137
|
-
var version = "2.
|
|
137
|
+
var version = "2.13.0";
|
|
138
138
|
//#endregion
|
|
139
139
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
140
140
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -2043,6 +2043,7 @@ const types$1 = (0, arktype.scope)({
|
|
|
2043
2043
|
output: {
|
|
2044
2044
|
"previews?": [{ filepath: "string" }, "[]"],
|
|
2045
2045
|
"images?": "ComfyImageInfo[]",
|
|
2046
|
+
"audio?": "ComfyImageInfo[]",
|
|
2046
2047
|
"text?": "unknown[]"
|
|
2047
2048
|
},
|
|
2048
2049
|
prompt_id: "PromptID"
|
|
@@ -2143,11 +2144,11 @@ var MediaImage = class MediaImage {
|
|
|
2143
2144
|
});
|
|
2144
2145
|
};
|
|
2145
2146
|
this.loadInWorkflow_viaLoadImageNode = async (workflow) => {
|
|
2146
|
-
const enumName = await this.uploadAndReturnEnumName(workflow.host);
|
|
2147
|
+
const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
|
|
2147
2148
|
return bang(workflow.builderBase.LoadImage, "host has no LoadImage node")({ image: enumName });
|
|
2148
2149
|
};
|
|
2149
2150
|
this.loadInWorkflowAsMask_viaLoadImageMask = async (channel, workflow) => {
|
|
2150
|
-
const enumName = await this.uploadAndReturnEnumName(workflow.host);
|
|
2151
|
+
const enumName = workflow.dry ? this.enumName : await this.uploadAndReturnEnumName(workflow.host);
|
|
2151
2152
|
return bang(workflow.builderBase.LoadImageMask, "host has no LoadImageMask node")({
|
|
2152
2153
|
image: enumName,
|
|
2153
2154
|
channel
|
|
@@ -2295,6 +2296,18 @@ var MediaImage = class MediaImage {
|
|
|
2295
2296
|
* A claim is released as soon as the write lands (the file itself then holds
|
|
2296
2297
|
* the name) or fails (the name is free again) — the set never accumulates */
|
|
2297
2298
|
const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
|
|
2299
|
+
const AUDIO_MIMES = {
|
|
2300
|
+
flac: "audio/flac",
|
|
2301
|
+
mp3: "audio/mpeg",
|
|
2302
|
+
opus: "audio/ogg",
|
|
2303
|
+
ogg: "audio/ogg",
|
|
2304
|
+
wav: "audio/wav",
|
|
2305
|
+
m4a: "audio/mp4"
|
|
2306
|
+
};
|
|
2307
|
+
function audioMime(filename) {
|
|
2308
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
|
2309
|
+
return AUDIO_MIMES[ext] ?? "application/octet-stream";
|
|
2310
|
+
}
|
|
2298
2311
|
var ComfyExecution = class {
|
|
2299
2312
|
get host() {
|
|
2300
2313
|
return this.workflow.host;
|
|
@@ -2369,8 +2382,51 @@ var ComfyExecution = class {
|
|
|
2369
2382
|
error: e
|
|
2370
2383
|
});
|
|
2371
2384
|
}));
|
|
2385
|
+
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveAudio(audio, promptNodeID).catch((e) => {
|
|
2386
|
+
console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
|
|
2387
|
+
this.audioErrors.push({
|
|
2388
|
+
audio,
|
|
2389
|
+
error: e
|
|
2390
|
+
});
|
|
2391
|
+
}));
|
|
2372
2392
|
};
|
|
2373
2393
|
this.pendingPromises = [];
|
|
2394
|
+
this.audioErrors = [];
|
|
2395
|
+
this.audios = [];
|
|
2396
|
+
this.retrieveAudio = async (info, promptNodeID) => {
|
|
2397
|
+
const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
|
|
2398
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2399
|
+
const mime = audioMime(info.filename);
|
|
2400
|
+
const sf = this.save;
|
|
2401
|
+
if (sf == null) {
|
|
2402
|
+
this.audios.push({
|
|
2403
|
+
nodeId: promptNodeID,
|
|
2404
|
+
filename: info.filename,
|
|
2405
|
+
mime,
|
|
2406
|
+
bytes,
|
|
2407
|
+
absPath: null
|
|
2408
|
+
});
|
|
2409
|
+
return;
|
|
2410
|
+
}
|
|
2411
|
+
const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs["filename_prefix"];
|
|
2412
|
+
const written = await this.encodeAndWrite({
|
|
2413
|
+
bytes,
|
|
2414
|
+
sf: {
|
|
2415
|
+
...sf,
|
|
2416
|
+
format: "raw"
|
|
2417
|
+
},
|
|
2418
|
+
filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
|
|
2419
|
+
subfolder: info.subfolder,
|
|
2420
|
+
filename: info.filename
|
|
2421
|
+
});
|
|
2422
|
+
this.audios.push({
|
|
2423
|
+
nodeId: promptNodeID,
|
|
2424
|
+
filename: info.filename,
|
|
2425
|
+
mime,
|
|
2426
|
+
bytes,
|
|
2427
|
+
absPath: written.path
|
|
2428
|
+
});
|
|
2429
|
+
};
|
|
2374
2430
|
this.imageErrors = [];
|
|
2375
2431
|
this.retrieveImage = async (comfyImageInfo, promptNodeID) => {
|
|
2376
2432
|
const promptNode = this.workflow.data.apiJson?.[promptNodeID];
|
|
@@ -2542,6 +2598,7 @@ var ComfyExecution = class {
|
|
|
2542
2598
|
if (!this.logProgress) return;
|
|
2543
2599
|
const p = this.progress;
|
|
2544
2600
|
const outputs = [`${this.images.length} image(s)`];
|
|
2601
|
+
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
|
|
2545
2602
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
|
|
2546
2603
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
|
|
2547
2604
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
@@ -2772,6 +2829,7 @@ var ComfyWorkflow = class {
|
|
|
2772
2829
|
constructor(host, data) {
|
|
2773
2830
|
this.host = host;
|
|
2774
2831
|
this.data = data;
|
|
2832
|
+
this.dry = false;
|
|
2775
2833
|
this.nodes = [];
|
|
2776
2834
|
this.registerNode = (node) => {
|
|
2777
2835
|
if (this.data.apiJson == null) throw new Error("graph not hydrated");
|
|
@@ -3269,7 +3327,7 @@ function codegenSDK(opts) {
|
|
|
3269
3327
|
p("}");
|
|
3270
3328
|
p(`interface Builder {`);
|
|
3271
3329
|
for (const n of nodes) {
|
|
3272
|
-
const baseDescription = `displayName="${n.raw.display_name}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
|
|
3330
|
+
const baseDescription = `displayName="${n.raw.display_name ?? n.nameInComfy}" category="${n.category}" name="${n.nameInComfy}" output=[${n.outputs.map((o) => o.outKey).join(", ")}]`;
|
|
3273
3331
|
if (n.raw.description) {
|
|
3274
3332
|
p(` /**`);
|
|
3275
3333
|
p(n.raw.description.split("\n").map((i) => ` * ${i}`).join("\n"));
|
|
@@ -3623,16 +3681,16 @@ const types = (0, arktype.scope)({
|
|
|
3623
3681
|
"hidden?": "string[]"
|
|
3624
3682
|
},
|
|
3625
3683
|
output: "ComfyInputType[]",
|
|
3626
|
-
output_is_list: "boolean[]",
|
|
3684
|
+
output_is_list: "(boolean | null)[]",
|
|
3627
3685
|
output_name: "string[]",
|
|
3628
3686
|
name: "string",
|
|
3629
|
-
display_name: "string",
|
|
3687
|
+
display_name: "string | null",
|
|
3630
3688
|
description: "string",
|
|
3631
3689
|
/** */
|
|
3632
3690
|
python_module: "string",
|
|
3633
3691
|
category: "string",
|
|
3634
3692
|
output_node: "boolean",
|
|
3635
|
-
"output_tooltips?": "string[]",
|
|
3693
|
+
"output_tooltips?": "(string | null)[]",
|
|
3636
3694
|
"deprecated?": "boolean",
|
|
3637
3695
|
"experimental?": "boolean"
|
|
3638
3696
|
},
|
|
@@ -3648,7 +3706,7 @@ const types = (0, arktype.scope)({
|
|
|
3648
3706
|
ComfyInputOpts_advanced: {
|
|
3649
3707
|
"tooltip?": "string | null | ComfyInputOpts_advanced",
|
|
3650
3708
|
"multiline?": "boolean | null",
|
|
3651
|
-
"default?": "boolean | number | string | null | number[]",
|
|
3709
|
+
"default?": "boolean | number | string | null | number[] | object",
|
|
3652
3710
|
"forceInput?": "boolean | null",
|
|
3653
3711
|
"min?": "number | null",
|
|
3654
3712
|
"round?": "boolean | number | null",
|
|
@@ -4009,14 +4067,46 @@ var ResilientWebSocketClient = class {
|
|
|
4009
4067
|
this.isOpen = false;
|
|
4010
4068
|
this.debugMessages = [];
|
|
4011
4069
|
this.hasEverOpened = false;
|
|
4070
|
+
this.heartbeat = null;
|
|
4012
4071
|
this.permanentlyClosed = false;
|
|
4013
4072
|
this.url = options.url();
|
|
4014
4073
|
this.connect();
|
|
4015
4074
|
}
|
|
4075
|
+
stopHeartbeat() {
|
|
4076
|
+
if (this.heartbeat != null) clearInterval(this.heartbeat);
|
|
4077
|
+
this.heartbeat = null;
|
|
4078
|
+
}
|
|
4079
|
+
/** ping on a timer; no pong since the previous ping = the peer is gone, drop the socket */
|
|
4080
|
+
startHeartbeat(ws) {
|
|
4081
|
+
this.stopHeartbeat();
|
|
4082
|
+
if (typeof ws.ping !== "function" || typeof ws.on !== "function") return;
|
|
4083
|
+
let awaitingPong = false;
|
|
4084
|
+
ws.on("pong", () => {
|
|
4085
|
+
awaitingPong = false;
|
|
4086
|
+
});
|
|
4087
|
+
const ms = this.options.heartbeatMs ?? 15e3;
|
|
4088
|
+
this.heartbeat = setInterval(() => {
|
|
4089
|
+
if (ws !== this.currentWS) return this.stopHeartbeat();
|
|
4090
|
+
if (awaitingPong) {
|
|
4091
|
+
this.addError(`no pong within ${ms}ms: the host is gone, dropping the socket to reconnect`);
|
|
4092
|
+
this.stopHeartbeat();
|
|
4093
|
+
if (typeof ws.terminate === "function") ws.terminate();
|
|
4094
|
+
else ws.close();
|
|
4095
|
+
return;
|
|
4096
|
+
}
|
|
4097
|
+
awaitingPong = true;
|
|
4098
|
+
try {
|
|
4099
|
+
ws.ping?.();
|
|
4100
|
+
} catch (e) {
|
|
4101
|
+
this.addError(`ping failed: ${extractErrorMessage(e)}`);
|
|
4102
|
+
}
|
|
4103
|
+
}, ms);
|
|
4104
|
+
}
|
|
4016
4105
|
/** close and stop reconnecting (lets a script exit cleanly) */
|
|
4017
4106
|
disconnectPermanently() {
|
|
4018
4107
|
this.permanentlyClosed = true;
|
|
4019
4108
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
4109
|
+
this.stopHeartbeat();
|
|
4020
4110
|
this.currentWS?.close();
|
|
4021
4111
|
this.currentWS = null;
|
|
4022
4112
|
this.isOpen = false;
|
|
@@ -4035,6 +4125,7 @@ var ResilientWebSocketClient = class {
|
|
|
4035
4125
|
this.isOpen = false;
|
|
4036
4126
|
const prevWS = this.currentWS;
|
|
4037
4127
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
4128
|
+
this.stopHeartbeat();
|
|
4038
4129
|
this.currentWS = null;
|
|
4039
4130
|
if (prevWS) {
|
|
4040
4131
|
this.addInfo("Previous WebSocket discarded");
|
|
@@ -4042,7 +4133,7 @@ var ResilientWebSocketClient = class {
|
|
|
4042
4133
|
}
|
|
4043
4134
|
let ws;
|
|
4044
4135
|
try {
|
|
4045
|
-
const transport = await resolveWsTransport();
|
|
4136
|
+
const transport = this.options.transport ?? await resolveWsTransport();
|
|
4046
4137
|
if (this.permanentlyClosed) return;
|
|
4047
4138
|
const headers = this.options.headers?.() ?? {};
|
|
4048
4139
|
ws = transport.supportsHeaders ? new transport.ctor(this.url, { headers }) : new transport.ctor(this.headerlessUrl(headers));
|
|
@@ -4064,10 +4155,12 @@ var ResilientWebSocketClient = class {
|
|
|
4064
4155
|
this.isOpen = true;
|
|
4065
4156
|
this.options.onConnectOrReconnect();
|
|
4066
4157
|
this.flushMessageBuffer();
|
|
4158
|
+
this.startHeartbeat(ws);
|
|
4067
4159
|
};
|
|
4068
4160
|
ws.onclose = (event) => {
|
|
4069
4161
|
if (ws !== this.currentWS) return;
|
|
4070
4162
|
this.isOpen = false;
|
|
4163
|
+
this.stopHeartbeat();
|
|
4071
4164
|
this.options.onClose();
|
|
4072
4165
|
if (this.permanentlyClosed) return;
|
|
4073
4166
|
this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
|
|
@@ -4076,8 +4169,9 @@ var ResilientWebSocketClient = class {
|
|
|
4076
4169
|
this.options.onFirstConnectFailed(/* @__PURE__ */ new Error(`connection refused (code=${event.code}${event.reason === "" ? "" : `, ${event.reason}`})`));
|
|
4077
4170
|
return;
|
|
4078
4171
|
}
|
|
4079
|
-
this.
|
|
4080
|
-
this.
|
|
4172
|
+
const wait = this.options.reconnectMs ?? 2e3;
|
|
4173
|
+
this.addInfo(`⏱️ reconnecting in ${wait / 1e3} seconds...`);
|
|
4174
|
+
this.reconnectTimeout = setTimeout(() => void this.connect(), wait);
|
|
4081
4175
|
};
|
|
4082
4176
|
ws.onerror = (event) => {
|
|
4083
4177
|
if (ws !== this.currentWS) return;
|
|
@@ -4377,6 +4471,221 @@ function writeKeywords() {
|
|
|
4377
4471
|
}
|
|
4378
4472
|
}
|
|
4379
4473
|
//#endregion
|
|
4474
|
+
//#region src/vars/loraEntry.ts
|
|
4475
|
+
function isLoraEntry(s) {
|
|
4476
|
+
if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
|
|
4477
|
+
const o = s;
|
|
4478
|
+
const st = o.strength;
|
|
4479
|
+
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"));
|
|
4480
|
+
}
|
|
4481
|
+
function isLoraStrength(s) {
|
|
4482
|
+
if (typeof s === "boolean") return true;
|
|
4483
|
+
if (typeof s === "number") return Number.isFinite(s);
|
|
4484
|
+
if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
4485
|
+
return isLoraEntry(s);
|
|
4486
|
+
}
|
|
4487
|
+
/** on = it runs */
|
|
4488
|
+
function loraIsOn(s) {
|
|
4489
|
+
if (s == null || s === false) return false;
|
|
4490
|
+
if (isLoraEntry(s)) return s.off !== true;
|
|
4491
|
+
return true;
|
|
4492
|
+
}
|
|
4493
|
+
/** the strengths, whatever the spelling (1/1 when there is nothing to read) */
|
|
4494
|
+
function loraStrengths(s) {
|
|
4495
|
+
if (typeof s === "number" && Number.isFinite(s)) return [s, s];
|
|
4496
|
+
if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
|
|
4497
|
+
if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
|
|
4498
|
+
return [1, 1];
|
|
4499
|
+
}
|
|
4500
|
+
function loraMuted(s) {
|
|
4501
|
+
return isLoraEntry(s) && s.mute != null ? s.mute : [];
|
|
4502
|
+
}
|
|
4503
|
+
/** a prompt keyword's parts, split at commas: each one can be left out on its own */
|
|
4504
|
+
function keywordParts(keyword) {
|
|
4505
|
+
return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
|
|
4506
|
+
}
|
|
4507
|
+
/** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
|
|
4508
|
+
function keptKeyword(keyword, muted) {
|
|
4509
|
+
return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
|
|
4510
|
+
}
|
|
4511
|
+
/** rewrite one setting, keeping what the patch does not name. The result stays in the short
|
|
4512
|
+
* spellings while nothing needs the palette form, so a plain draft reads as it always did */
|
|
4513
|
+
function withLora(s, patch) {
|
|
4514
|
+
const strength = patch.strength ?? loraStrengths(s);
|
|
4515
|
+
const off = patch.on == null ? !loraIsOn(s) : !patch.on;
|
|
4516
|
+
const mute = [...patch.mute ?? loraMuted(s)];
|
|
4517
|
+
if (!off && mute.length === 0) return [strength[0], strength[1]];
|
|
4518
|
+
return {
|
|
4519
|
+
strength: [strength[0], strength[1]],
|
|
4520
|
+
...off ? { off: true } : {},
|
|
4521
|
+
...mute.length === 0 ? {} : { mute }
|
|
4522
|
+
};
|
|
4523
|
+
}
|
|
4524
|
+
//#endregion
|
|
4525
|
+
//#region src/vars/lanes.ts
|
|
4526
|
+
const FIRST_LANE = "main";
|
|
4527
|
+
function isObject(v) {
|
|
4528
|
+
return typeof v === "object" && v != null && !Array.isArray(v);
|
|
4529
|
+
}
|
|
4530
|
+
function isPromptLane(v) {
|
|
4531
|
+
return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
|
|
4532
|
+
}
|
|
4533
|
+
function isPromptLanes(v) {
|
|
4534
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
|
|
4535
|
+
}
|
|
4536
|
+
/** the text the build reads: the active lanes joined in order, one line break between them, so
|
|
4537
|
+
* `//` and `- ` lines keep working inside every lane */
|
|
4538
|
+
function promptText(v) {
|
|
4539
|
+
if (typeof v === "string") return v;
|
|
4540
|
+
return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
|
|
4541
|
+
}
|
|
4542
|
+
const HEADER = /^# (.+?)( \(off\))?$/;
|
|
4543
|
+
function promptLanesToText(v) {
|
|
4544
|
+
return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
|
|
4545
|
+
}
|
|
4546
|
+
/** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
|
|
4547
|
+
function promptLanesFromText(text) {
|
|
4548
|
+
const lanes = [];
|
|
4549
|
+
let current = null;
|
|
4550
|
+
const body = [];
|
|
4551
|
+
const close = () => {
|
|
4552
|
+
if (current != null) lanes.push({
|
|
4553
|
+
...current,
|
|
4554
|
+
prompt: body.join("\n")
|
|
4555
|
+
});
|
|
4556
|
+
else if (body.some((l) => l.trim() !== "")) lanes.push({
|
|
4557
|
+
name: FIRST_LANE,
|
|
4558
|
+
prompt: body.join("\n"),
|
|
4559
|
+
active: true
|
|
4560
|
+
});
|
|
4561
|
+
body.length = 0;
|
|
4562
|
+
};
|
|
4563
|
+
for (const line of text.split("\n")) {
|
|
4564
|
+
const m = HEADER.exec(line);
|
|
4565
|
+
if (m == null) {
|
|
4566
|
+
body.push(line);
|
|
4567
|
+
continue;
|
|
4568
|
+
}
|
|
4569
|
+
close();
|
|
4570
|
+
current = {
|
|
4571
|
+
name: (m[1] ?? "").trim(),
|
|
4572
|
+
prompt: "",
|
|
4573
|
+
active: m[2] == null
|
|
4574
|
+
};
|
|
4575
|
+
}
|
|
4576
|
+
close();
|
|
4577
|
+
return { lanes: lanes.length > 0 ? lanes : [{
|
|
4578
|
+
name: FIRST_LANE,
|
|
4579
|
+
prompt: "",
|
|
4580
|
+
active: true
|
|
4581
|
+
}] };
|
|
4582
|
+
}
|
|
4583
|
+
function isLoraRecord(v) {
|
|
4584
|
+
return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
|
|
4585
|
+
}
|
|
4586
|
+
function isLoraLane(v) {
|
|
4587
|
+
return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
|
|
4588
|
+
}
|
|
4589
|
+
function isLoraLanes(v) {
|
|
4590
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
|
|
4591
|
+
}
|
|
4592
|
+
function isLorasInput(v) {
|
|
4593
|
+
return isLoraRecord(v) || isLoraLanes(v);
|
|
4594
|
+
}
|
|
4595
|
+
/** one record for the build: the active lanes in order. A lora in two active lanes keeps its
|
|
4596
|
+
* FIRST setting, and `duplicates` names it so the caller can say so */
|
|
4597
|
+
function flattenLoras(v) {
|
|
4598
|
+
if (!isLoraLanes(v)) return {
|
|
4599
|
+
record: v,
|
|
4600
|
+
duplicates: []
|
|
4601
|
+
};
|
|
4602
|
+
const record = {};
|
|
4603
|
+
const duplicates = [];
|
|
4604
|
+
for (const lane of v.lanes) {
|
|
4605
|
+
if (!lane.active) continue;
|
|
4606
|
+
for (const [name, st] of Object.entries(lane.loras)) {
|
|
4607
|
+
if (st == null) continue;
|
|
4608
|
+
if (name in record) duplicates.push(name);
|
|
4609
|
+
else record[name] = st;
|
|
4610
|
+
}
|
|
4611
|
+
}
|
|
4612
|
+
return {
|
|
4613
|
+
record,
|
|
4614
|
+
duplicates
|
|
4615
|
+
};
|
|
4616
|
+
}
|
|
4617
|
+
/** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
|
|
4618
|
+
* has it (the one the build reads), else any lane, else -1 */
|
|
4619
|
+
function laneIndexOf(v, name) {
|
|
4620
|
+
const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
|
|
4621
|
+
return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
|
|
4622
|
+
}
|
|
4623
|
+
/** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
|
|
4624
|
+
* A lora in no lane yet lands in the first lane */
|
|
4625
|
+
function updateLora(v, name, next) {
|
|
4626
|
+
const write = (rec) => {
|
|
4627
|
+
const out = { ...rec };
|
|
4628
|
+
if (next == null) delete out[name];
|
|
4629
|
+
else out[name] = next;
|
|
4630
|
+
return out;
|
|
4631
|
+
};
|
|
4632
|
+
if (!isLoraLanes(v)) return write(v);
|
|
4633
|
+
if (v.lanes.length === 0) return { lanes: [{
|
|
4634
|
+
name: FIRST_LANE,
|
|
4635
|
+
active: true,
|
|
4636
|
+
loras: write({})
|
|
4637
|
+
}] };
|
|
4638
|
+
const found = laneIndexOf(v, name);
|
|
4639
|
+
const ix = found === -1 ? 0 : found;
|
|
4640
|
+
return { lanes: v.lanes.map((l, i) => i === ix ? {
|
|
4641
|
+
...l,
|
|
4642
|
+
loras: write(l.loras)
|
|
4643
|
+
} : l) };
|
|
4644
|
+
}
|
|
4645
|
+
//#endregion
|
|
4646
|
+
//#region src/vars/promptSyntax.ts
|
|
4647
|
+
/** a whole line that is a comment (the TUI colors these) */
|
|
4648
|
+
const COMMENT_LINE_RE = /^\s*\/\//;
|
|
4649
|
+
/** a negative prompt line: `- ` then its text */
|
|
4650
|
+
const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
|
|
4651
|
+
const NEGATIVE_PREFIX_RE = /^(\s*)- /;
|
|
4652
|
+
/** where a `//` comment starts on this line, -1 when none. Only at line start or after
|
|
4653
|
+
* whitespace, so `http://host` is never cut */
|
|
4654
|
+
function commentStart(line) {
|
|
4655
|
+
const m = /(?:^|\s)\/\//.exec(line);
|
|
4656
|
+
if (m == null) return -1;
|
|
4657
|
+
return m.index + m[0].length - 2;
|
|
4658
|
+
}
|
|
4659
|
+
/** the line without its comment, trailing whitespace dropped with it */
|
|
4660
|
+
function withoutComment(line) {
|
|
4661
|
+
const c = commentStart(line);
|
|
4662
|
+
return c < 0 ? {
|
|
4663
|
+
text: line,
|
|
4664
|
+
hadComment: false
|
|
4665
|
+
} : {
|
|
4666
|
+
text: line.slice(0, c).trimEnd(),
|
|
4667
|
+
hadComment: true
|
|
4668
|
+
};
|
|
4669
|
+
}
|
|
4670
|
+
/** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
|
|
4671
|
+
function parsePromptText(text) {
|
|
4672
|
+
const pos = [];
|
|
4673
|
+
const neg = [];
|
|
4674
|
+
for (const raw of text.split("\n")) {
|
|
4675
|
+
const cut = withoutComment(raw);
|
|
4676
|
+
if (cut.hadComment && cut.text.trim() === "") continue;
|
|
4677
|
+
const m = NEGATIVE_PREFIX_RE.exec(raw);
|
|
4678
|
+
if (m != null && m[0].length <= cut.text.length + 1) {
|
|
4679
|
+
const body = cut.text.slice(m[0].length).trim();
|
|
4680
|
+
if (body !== "") neg.push(body);
|
|
4681
|
+
} else pos.push(cut.text);
|
|
4682
|
+
}
|
|
4683
|
+
return {
|
|
4684
|
+
positive: pos.join("\n").trim(),
|
|
4685
|
+
negative: neg.join(", ")
|
|
4686
|
+
};
|
|
4687
|
+
}
|
|
4688
|
+
//#endregion
|
|
4380
4689
|
//#region src/vars/presets.ts
|
|
4381
4690
|
function toPresetList(spec) {
|
|
4382
4691
|
if (spec == null) return [];
|
|
@@ -4392,16 +4701,11 @@ function activePresetLabel(presets, value) {
|
|
|
4392
4701
|
}
|
|
4393
4702
|
//#endregion
|
|
4394
4703
|
//#region src/vars/ComfyVars.ts
|
|
4395
|
-
/**
|
|
4396
|
-
* full base: T is what's STORED/edited, Out what the GRAPH consumes at build
|
|
4397
|
-
* time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
|
|
4398
|
-
* the one Out-specialized var (string in, PromptValue out); the split keeps
|
|
4399
|
-
* outValue() cast-free.
|
|
4400
|
-
*/
|
|
4401
4704
|
var ComfyVarBase = class {
|
|
4402
4705
|
constructor(defaultValue, label) {
|
|
4403
4706
|
this.defaultValue = defaultValue;
|
|
4404
4707
|
this.label = label;
|
|
4708
|
+
this.uiOpts = {};
|
|
4405
4709
|
this.value = defaultValue;
|
|
4406
4710
|
(0, mobx.makeObservable)(this, {
|
|
4407
4711
|
value: mobx.observable,
|
|
@@ -4415,6 +4719,14 @@ var ComfyVarBase = class {
|
|
|
4415
4719
|
this.value = value;
|
|
4416
4720
|
return this;
|
|
4417
4721
|
}
|
|
4722
|
+
/** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
|
|
4723
|
+
ui(p) {
|
|
4724
|
+
this.uiOpts = {
|
|
4725
|
+
...this.uiOpts,
|
|
4726
|
+
...p
|
|
4727
|
+
};
|
|
4728
|
+
return this;
|
|
4729
|
+
}
|
|
4418
4730
|
/** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
|
|
4419
4731
|
toJSON() {
|
|
4420
4732
|
return this.value;
|
|
@@ -4462,12 +4774,10 @@ var TextVar = class extends ComfyVar {
|
|
|
4462
4774
|
return true;
|
|
4463
4775
|
}
|
|
4464
4776
|
};
|
|
4465
|
-
const commentLineRe = /^\s*\/\//;
|
|
4466
|
-
const negativeLineRe = /^\s*- (.*)$/;
|
|
4467
4777
|
/**
|
|
4468
4778
|
* prompt text with editor comforts, all resolved at BUILD time (the editor and
|
|
4469
4779
|
* drafts keep the raw text):
|
|
4470
|
-
* - `//`
|
|
4780
|
+
* - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
|
|
4471
4781
|
* - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
|
|
4472
4782
|
* comma-joined into `.negative`
|
|
4473
4783
|
* - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
|
|
@@ -4481,38 +4791,48 @@ var PromptVar = class extends ComfyVarBase {
|
|
|
4481
4791
|
this.kind = "prompt";
|
|
4482
4792
|
this.presets = toPresetList(promptOpts.presets);
|
|
4483
4793
|
}
|
|
4794
|
+
/** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
|
|
4484
4795
|
parse(raw) {
|
|
4485
|
-
this.set(raw);
|
|
4796
|
+
this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
|
|
4486
4797
|
return true;
|
|
4487
4798
|
}
|
|
4799
|
+
toEditBuffer() {
|
|
4800
|
+
return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
|
|
4801
|
+
}
|
|
4802
|
+
/** a var list shows the lanes by name, the inactive ones in parentheses */
|
|
4803
|
+
display() {
|
|
4804
|
+
if (!isPromptLanes(this.value)) return super.display();
|
|
4805
|
+
return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
|
|
4806
|
+
}
|
|
4807
|
+
/** the text the build reads: the plain string, or the active lanes joined in order */
|
|
4808
|
+
get text() {
|
|
4809
|
+
return promptText(this.value);
|
|
4810
|
+
}
|
|
4811
|
+
/** the tag list options in their one object form, null when this prompt has no completion */
|
|
4812
|
+
get tags() {
|
|
4813
|
+
const t = this.promptOpts.tags;
|
|
4814
|
+
if (t == null) return null;
|
|
4815
|
+
return typeof t === "string" ? { url: t } : t;
|
|
4816
|
+
}
|
|
4488
4817
|
static isCommentLine(line) {
|
|
4489
|
-
return
|
|
4818
|
+
return COMMENT_LINE_RE.test(line);
|
|
4490
4819
|
}
|
|
4491
4820
|
static isNegativeLine(line) {
|
|
4492
|
-
return
|
|
4821
|
+
return NEGATIVE_LINE_RE.test(line);
|
|
4493
4822
|
}
|
|
4494
4823
|
/** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
|
|
4495
4824
|
injectedKeywords() {
|
|
4496
4825
|
const src = this.promptOpts.loraKeywordsFrom;
|
|
4497
4826
|
if (src == null) return [];
|
|
4498
|
-
return [...new Set(src.activeNames().map((name) => getLoraKeyword(name, src.hostId)).filter((k) => k !== ""))];
|
|
4827
|
+
return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
|
|
4499
4828
|
}
|
|
4500
4829
|
outValue() {
|
|
4501
|
-
const
|
|
4502
|
-
const
|
|
4503
|
-
for (const line of this.value.split("\n")) {
|
|
4504
|
-
if (commentLineRe.test(line)) continue;
|
|
4505
|
-
const m = negativeLineRe.exec(line);
|
|
4506
|
-
if (m != null) {
|
|
4507
|
-
const text = (m[1] ?? "").trim();
|
|
4508
|
-
if (text !== "") neg.push(text);
|
|
4509
|
-
} else pos.push(line);
|
|
4510
|
-
}
|
|
4511
|
-
const body = pos.join("\n").trim();
|
|
4830
|
+
const parsed = parsePromptText(this.text);
|
|
4831
|
+
const body = parsed.positive;
|
|
4512
4832
|
const keywords = this.injectedKeywords();
|
|
4513
4833
|
return {
|
|
4514
4834
|
positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
|
|
4515
|
-
negative:
|
|
4835
|
+
negative: parsed.negative
|
|
4516
4836
|
};
|
|
4517
4837
|
}
|
|
4518
4838
|
};
|
|
@@ -4652,6 +4972,7 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4652
4972
|
super(defaultValue, label);
|
|
4653
4973
|
this.choices = choices;
|
|
4654
4974
|
this.kind = "choice";
|
|
4975
|
+
this.select = "one";
|
|
4655
4976
|
}
|
|
4656
4977
|
next(delta = 1) {
|
|
4657
4978
|
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
@@ -4664,12 +4985,96 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4664
4985
|
return true;
|
|
4665
4986
|
}
|
|
4666
4987
|
};
|
|
4988
|
+
/** one option or none: `null` is "nothing picked", clicking the lit option clears it */
|
|
4989
|
+
var OptionalChoiceVar = class extends ComfyVar {
|
|
4990
|
+
constructor(choices, defaultValue, label) {
|
|
4991
|
+
super(defaultValue, label);
|
|
4992
|
+
this.choices = choices;
|
|
4993
|
+
this.kind = "choice";
|
|
4994
|
+
this.select = "zero-or-one";
|
|
4995
|
+
}
|
|
4996
|
+
/** pick `c`, or clear it when it is already the one picked */
|
|
4997
|
+
toggle(c) {
|
|
4998
|
+
return this.set(this.value === c ? null : c);
|
|
4999
|
+
}
|
|
5000
|
+
/** the TUI text form: a choice, or an empty line for none */
|
|
5001
|
+
parse(raw) {
|
|
5002
|
+
if (raw.trim() === "") {
|
|
5003
|
+
this.set(null);
|
|
5004
|
+
return true;
|
|
5005
|
+
}
|
|
5006
|
+
const hit = this.choices.find((c) => c === raw.trim());
|
|
5007
|
+
if (hit == null) return false;
|
|
5008
|
+
this.set(hit);
|
|
5009
|
+
return true;
|
|
5010
|
+
}
|
|
5011
|
+
toEditBuffer() {
|
|
5012
|
+
return this.value ?? "";
|
|
5013
|
+
}
|
|
5014
|
+
/** a draft from when this was a many choice holds a list: its first known option */
|
|
5015
|
+
loadJSON(value) {
|
|
5016
|
+
const one = Array.isArray(value) ? value[0] : value;
|
|
5017
|
+
return this.set(this.choices.find((c) => c === one) ?? null);
|
|
5018
|
+
}
|
|
5019
|
+
display() {
|
|
5020
|
+
return this.value ?? "none";
|
|
5021
|
+
}
|
|
5022
|
+
};
|
|
5023
|
+
/** any number of options, kept in the order the choices list them */
|
|
5024
|
+
var MultiChoiceVar = class extends ComfyVar {
|
|
5025
|
+
constructor(choices, defaultValue, label) {
|
|
5026
|
+
super([...defaultValue], label);
|
|
5027
|
+
this.choices = choices;
|
|
5028
|
+
this.kind = "choice";
|
|
5029
|
+
this.select = "many";
|
|
5030
|
+
}
|
|
5031
|
+
toggle(c) {
|
|
5032
|
+
const on = this.value.includes(c);
|
|
5033
|
+
return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
|
|
5034
|
+
}
|
|
5035
|
+
/** the TUI text form: `a, b` */
|
|
5036
|
+
parse(raw) {
|
|
5037
|
+
const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
|
|
5038
|
+
const picked = this.choices.filter((c) => wanted.includes(c));
|
|
5039
|
+
if (picked.length !== new Set(wanted).size) return false;
|
|
5040
|
+
this.set(picked);
|
|
5041
|
+
return true;
|
|
5042
|
+
}
|
|
5043
|
+
toEditBuffer() {
|
|
5044
|
+
return this.value.join(", ");
|
|
5045
|
+
}
|
|
5046
|
+
/** a draft from when this was a single choice holds one value: a list of one. Unknown
|
|
5047
|
+
* options are dropped, the list comes back in the choices order */
|
|
5048
|
+
loadJSON(value) {
|
|
5049
|
+
const listed = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
5050
|
+
return this.set(this.choices.filter((c) => listed.includes(c)));
|
|
5051
|
+
}
|
|
5052
|
+
display() {
|
|
5053
|
+
return this.value.length === 0 ? "none" : this.value.join(", ");
|
|
5054
|
+
}
|
|
5055
|
+
};
|
|
5056
|
+
/** Array.isArray does not narrow a READONLY array out of a union, this does */
|
|
5057
|
+
function isChoiceList(v) {
|
|
5058
|
+
return Array.isArray(v);
|
|
5059
|
+
}
|
|
5060
|
+
function choice(choices, defaultValue, opts) {
|
|
5061
|
+
const o = typeof opts === "string" ? { label: opts } : opts ?? {};
|
|
5062
|
+
const select = o.select ?? "one";
|
|
5063
|
+
if (select === "many") {
|
|
5064
|
+
if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
|
|
5065
|
+
return new MultiChoiceVar(choices, defaultValue, o.label);
|
|
5066
|
+
}
|
|
5067
|
+
if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
|
|
5068
|
+
if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
|
|
5069
|
+
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
5070
|
+
return new ChoiceVar(choices, defaultValue, o.label);
|
|
5071
|
+
}
|
|
4667
5072
|
/** normalize a loras record into what a standard LoraLoader chain consumes */
|
|
4668
5073
|
function activeLoras(loras) {
|
|
4669
5074
|
const out = [];
|
|
4670
|
-
for (const [lora_name, s] of Object.entries(loras)) {
|
|
4671
|
-
if (s
|
|
4672
|
-
const [strength_model, strength_clip] =
|
|
5075
|
+
for (const [lora_name, s] of Object.entries(flattenLoras(loras).record)) {
|
|
5076
|
+
if (!loraIsOn(s)) continue;
|
|
5077
|
+
const [strength_model, strength_clip] = loraStrengths(s);
|
|
4673
5078
|
out.push({
|
|
4674
5079
|
lora_name,
|
|
4675
5080
|
strength_model,
|
|
@@ -4684,7 +5089,12 @@ function activeLoras(loras) {
|
|
|
4684
5089
|
* or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
|
|
4685
5090
|
* a hardcoded inventory. Selection is empty by default.
|
|
4686
5091
|
*/
|
|
4687
|
-
|
|
5092
|
+
/**
|
|
5093
|
+
* the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
|
|
5094
|
+
* build merges in listed order, skipping inactive ones. Every method reads the merged record and
|
|
5095
|
+
* writes into the lane that holds the lora, so the TUI never needs to know lanes exist
|
|
5096
|
+
*/
|
|
5097
|
+
var LorasVar = class LorasVar extends ComfyVarBase {
|
|
4688
5098
|
constructor(optionsSource, initial = {}, label) {
|
|
4689
5099
|
super(initial, label);
|
|
4690
5100
|
this.optionsSource = optionsSource;
|
|
@@ -4715,49 +5125,57 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4715
5125
|
get names() {
|
|
4716
5126
|
return [...this.options];
|
|
4717
5127
|
}
|
|
5128
|
+
/** the loras the build reads: the plain record, or the active lanes merged in order */
|
|
5129
|
+
get record() {
|
|
5130
|
+
return flattenLoras(this.value).record;
|
|
5131
|
+
}
|
|
5132
|
+
/** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
|
|
5133
|
+
outValue() {
|
|
5134
|
+
const flat = flattenLoras(this.value);
|
|
5135
|
+
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`);
|
|
5136
|
+
return flat.record;
|
|
5137
|
+
}
|
|
5138
|
+
/** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
|
|
5139
|
+
write(name, next) {
|
|
5140
|
+
return this.set(updateLora(this.value, name, next));
|
|
5141
|
+
}
|
|
5142
|
+
/** the parts of this lora's prompt keyword left out of the prompt */
|
|
5143
|
+
mutedWords(name) {
|
|
5144
|
+
return loraMuted(this.record[name]);
|
|
5145
|
+
}
|
|
4718
5146
|
/** loras currently ON (PromptVar keyword prefixing consumes this) */
|
|
4719
5147
|
activeNames() {
|
|
4720
5148
|
return this.names.filter((n) => this.isOn(n));
|
|
4721
5149
|
}
|
|
4722
5150
|
isOn(name) {
|
|
4723
|
-
|
|
4724
|
-
return s != null && s !== false;
|
|
5151
|
+
return loraIsOn(this.record[name]);
|
|
4725
5152
|
}
|
|
4726
5153
|
toggleItem(name) {
|
|
4727
|
-
const cur = this.
|
|
4728
|
-
if (cur == null || cur === false) return this.
|
|
4729
|
-
|
|
4730
|
-
[name]: this.prev[name] ?? true
|
|
4731
|
-
});
|
|
5154
|
+
const cur = this.record[name];
|
|
5155
|
+
if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
|
|
5156
|
+
if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
|
|
4732
5157
|
this.prev[name] = cur;
|
|
4733
|
-
return this.
|
|
4734
|
-
...this.value,
|
|
4735
|
-
[name]: false
|
|
4736
|
-
});
|
|
5158
|
+
return this.write(name, false);
|
|
4737
5159
|
}
|
|
4738
5160
|
/** step both strengths by delta (true becomes 1 first); no-op when off */
|
|
4739
5161
|
adjustItem(name, delta) {
|
|
4740
|
-
const cur = this.
|
|
4741
|
-
if (cur
|
|
5162
|
+
const cur = this.record[name];
|
|
5163
|
+
if (!loraIsOn(cur)) return this;
|
|
4742
5164
|
const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
|
|
4743
|
-
const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] :
|
|
4744
|
-
return this.
|
|
4745
|
-
...this.value,
|
|
4746
|
-
[name]: next
|
|
4747
|
-
});
|
|
5165
|
+
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])] });
|
|
5166
|
+
return this.write(name, next);
|
|
4748
5167
|
}
|
|
4749
5168
|
/** compact per-item strength label for lists */
|
|
4750
5169
|
strengthLabel(name) {
|
|
4751
|
-
const s = this.
|
|
4752
|
-
if (s
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
return s.toFixed(2);
|
|
5170
|
+
const s = this.record[name];
|
|
5171
|
+
if (!loraIsOn(s)) return "";
|
|
5172
|
+
const [m, c] = loraStrengths(s);
|
|
5173
|
+
return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
|
|
4756
5174
|
}
|
|
4757
5175
|
parse(raw) {
|
|
4758
5176
|
try {
|
|
4759
5177
|
const parsed = JSON.parse(raw);
|
|
4760
|
-
if (
|
|
5178
|
+
if (!isLorasInput(parsed)) return false;
|
|
4761
5179
|
this.set(parsed);
|
|
4762
5180
|
return true;
|
|
4763
5181
|
} catch {
|
|
@@ -4770,14 +5188,16 @@ var LorasVar = class LorasVar extends ComfyVar {
|
|
|
4770
5188
|
}
|
|
4771
5189
|
/** tick (true) or untick (false) every lora in `names` (default: all options) */
|
|
4772
5190
|
setAll(on, names = this.options) {
|
|
4773
|
-
const
|
|
5191
|
+
const record = this.record;
|
|
5192
|
+
let next = this.value;
|
|
4774
5193
|
for (const name of names) {
|
|
4775
|
-
const cur =
|
|
5194
|
+
const cur = record[name];
|
|
4776
5195
|
if (on) {
|
|
4777
|
-
if (cur == null || cur === false) next
|
|
5196
|
+
if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
|
|
5197
|
+
else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
|
|
4778
5198
|
} else {
|
|
4779
|
-
if (cur
|
|
4780
|
-
next
|
|
5199
|
+
if (loraIsOn(cur)) this.prev[name] = cur;
|
|
5200
|
+
next = updateLora(next, name, false);
|
|
4781
5201
|
}
|
|
4782
5202
|
}
|
|
4783
5203
|
return this.set(next);
|
|
@@ -4826,6 +5246,56 @@ const DEFAULT_SIZE_PRESETS = [
|
|
|
4826
5246
|
height: 1344
|
|
4827
5247
|
}
|
|
4828
5248
|
];
|
|
5249
|
+
/** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
|
|
5250
|
+
const SD15_SIZE_PRESETS = [
|
|
5251
|
+
{
|
|
5252
|
+
label: "1:1 square",
|
|
5253
|
+
width: 512,
|
|
5254
|
+
height: 512
|
|
5255
|
+
},
|
|
5256
|
+
{
|
|
5257
|
+
label: "4:3 landscape",
|
|
5258
|
+
width: 576,
|
|
5259
|
+
height: 448
|
|
5260
|
+
},
|
|
5261
|
+
{
|
|
5262
|
+
label: "3:4 portrait",
|
|
5263
|
+
width: 448,
|
|
5264
|
+
height: 576
|
|
5265
|
+
},
|
|
5266
|
+
{
|
|
5267
|
+
label: "3:2 landscape",
|
|
5268
|
+
width: 576,
|
|
5269
|
+
height: 384
|
|
5270
|
+
},
|
|
5271
|
+
{
|
|
5272
|
+
label: "2:3 portrait",
|
|
5273
|
+
width: 384,
|
|
5274
|
+
height: 576
|
|
5275
|
+
},
|
|
5276
|
+
{
|
|
5277
|
+
label: "16:9 widescreen",
|
|
5278
|
+
width: 704,
|
|
5279
|
+
height: 384
|
|
5280
|
+
},
|
|
5281
|
+
{
|
|
5282
|
+
label: "9:16 tall",
|
|
5283
|
+
width: 384,
|
|
5284
|
+
height: 704
|
|
5285
|
+
}
|
|
5286
|
+
];
|
|
5287
|
+
/** starred presets are one click away in the panel, before the full list */
|
|
5288
|
+
const DEFAULT_STARRED_SIZES = [
|
|
5289
|
+
"1:1 square",
|
|
5290
|
+
"3:4 portrait",
|
|
5291
|
+
"4:3 landscape"
|
|
5292
|
+
];
|
|
5293
|
+
/** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
|
|
5294
|
+
* and offering it 1024 buckets would be offering sizes it was never trained at */
|
|
5295
|
+
function sizePresetsFor(defaultValue) {
|
|
5296
|
+
if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
|
|
5297
|
+
return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
|
|
5298
|
+
}
|
|
4829
5299
|
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
4830
5300
|
* size of a linked image var (the widget shows
|
|
4831
5301
|
* `WxH size of image '<name>'` as a pickable row) */
|
|
@@ -4833,10 +5303,11 @@ var SizeVar = class extends ComfyVar {
|
|
|
4833
5303
|
constructor(defaultValue = {
|
|
4834
5304
|
width: 1024,
|
|
4835
5305
|
height: 1024
|
|
4836
|
-
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
|
|
5306
|
+
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
|
|
4837
5307
|
super(defaultValue, label);
|
|
4838
5308
|
this.presets = presets;
|
|
4839
5309
|
this.imageVar = imageVar;
|
|
5310
|
+
this.starred = starred;
|
|
4840
5311
|
this.kind = "size";
|
|
4841
5312
|
}
|
|
4842
5313
|
/** current dimensions of the linked image var — null when no link, unset
|
|
@@ -4961,9 +5432,11 @@ const v = {
|
|
|
4961
5432
|
* which is what a tuning session wants, and reset()/revert come back to it */
|
|
4962
5433
|
seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
|
|
4963
5434
|
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
4964
|
-
|
|
5435
|
+
/** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
|
|
5436
|
+
* `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
|
|
5437
|
+
choice,
|
|
4965
5438
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
4966
|
-
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
|
|
5439
|
+
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
4967
5440
|
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
|
|
4968
5441
|
};
|
|
4969
5442
|
function varValues(vars) {
|
|
@@ -4992,6 +5465,29 @@ var DefinedWorkflow = class {
|
|
|
4992
5465
|
varDef.name = key;
|
|
4993
5466
|
varDef.bindHost?.(this.host);
|
|
4994
5467
|
}
|
|
5468
|
+
const names = this.entries().map(([key]) => key);
|
|
5469
|
+
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(", ")})`);
|
|
5470
|
+
}
|
|
5471
|
+
/** every preview for the current var values. A preview that throws, or vars that cannot be
|
|
5472
|
+
* read yet (an image var still empty), give a line saying so instead of failing the others */
|
|
5473
|
+
computePreviews() {
|
|
5474
|
+
const previews = this.spec.previews ?? {};
|
|
5475
|
+
const names = Object.keys(previews);
|
|
5476
|
+
if (names.length === 0) return {};
|
|
5477
|
+
let values;
|
|
5478
|
+
try {
|
|
5479
|
+
values = varValues(this.vars);
|
|
5480
|
+
} catch (e) {
|
|
5481
|
+
const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
|
|
5482
|
+
return Object.fromEntries(names.map((n) => [n, why]));
|
|
5483
|
+
}
|
|
5484
|
+
const out = {};
|
|
5485
|
+
for (const [name, fn] of Object.entries(previews)) try {
|
|
5486
|
+
out[name] = fn(values);
|
|
5487
|
+
} catch (e) {
|
|
5488
|
+
out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
5489
|
+
}
|
|
5490
|
+
return out;
|
|
4995
5491
|
}
|
|
4996
5492
|
/** [name, var] pairs, for drivers that enumerate the knobs */
|
|
4997
5493
|
entries() {
|
|
@@ -5005,12 +5501,15 @@ var DefinedWorkflow = class {
|
|
|
5005
5501
|
* build() for copy/export never advances). `p.host` substitutes the host
|
|
5006
5502
|
* the graph is built against (TUI host override): node/model availability
|
|
5007
5503
|
* there surfaces as workflow.problems / server validation, by design.
|
|
5504
|
+
* `p.dry` builds a graph only to read it: nothing is uploaded, lastWorkflow is left alone.
|
|
5008
5505
|
*/
|
|
5009
5506
|
async build(p = {}) {
|
|
5010
5507
|
const wf = (p.host ?? this.host).workflow({ id: this.spec.id });
|
|
5508
|
+
wf.dry = p.dry === true;
|
|
5011
5509
|
const values = varValues(this.vars);
|
|
5012
5510
|
if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
|
|
5013
5511
|
await this.spec.build(wf.builder, values, wf);
|
|
5512
|
+
if (wf.dry) return wf;
|
|
5014
5513
|
this.lastWorkflow = wf;
|
|
5015
5514
|
return wf;
|
|
5016
5515
|
}
|
|
@@ -5311,8 +5810,22 @@ var ComfyHost = class {
|
|
|
5311
5810
|
this.clearQueue = () => {
|
|
5312
5811
|
return this.postJSON_("/queue", { clear: true });
|
|
5313
5812
|
};
|
|
5813
|
+
this.interruptCoalesceMs = 3e3;
|
|
5814
|
+
this._lastInterrupt = null;
|
|
5314
5815
|
this.interrupt = () => {
|
|
5315
|
-
|
|
5816
|
+
const now = Date.now();
|
|
5817
|
+
const last = this._lastInterrupt;
|
|
5818
|
+
if (last != null && last.promptID === this.activePromptID && now - last.at < this.interruptCoalesceMs) return last.req;
|
|
5819
|
+
const req = this.postJSON_("/interrupt", {});
|
|
5820
|
+
this._lastInterrupt = {
|
|
5821
|
+
promptID: this.activePromptID,
|
|
5822
|
+
at: now,
|
|
5823
|
+
req
|
|
5824
|
+
};
|
|
5825
|
+
req.catch(() => {
|
|
5826
|
+
if (this._lastInterrupt?.req === req) this._lastInterrupt = null;
|
|
5827
|
+
});
|
|
5828
|
+
return req;
|
|
5316
5829
|
};
|
|
5317
5830
|
this.deleteHistory = (promptId) => {
|
|
5318
5831
|
return this.postJSON_("/history", { delete: [promptId] });
|
|
@@ -6297,6 +6810,10 @@ var ComfyTS = class ComfyTS {
|
|
|
6297
6810
|
resolveFromPromptEnhancers(relativePath) {
|
|
6298
6811
|
return asAbsolutePath((0, pathe.join)(this.baseFolder, "prompt-enhancers", relativePath));
|
|
6299
6812
|
}
|
|
6813
|
+
/** the serve web ui's LLM configs (prompt enhancer), one json per config */
|
|
6814
|
+
resolveFromLlmConfigs(relativePath) {
|
|
6815
|
+
return asAbsolutePath((0, pathe.join)(this.baseFolder, "llm-configs", relativePath));
|
|
6816
|
+
}
|
|
6300
6817
|
resolveFromCache(relativePath) {
|
|
6301
6818
|
return asAbsolutePath((0, pathe.join)(this.baseFolder, "cache", relativePath));
|
|
6302
6819
|
}
|
|
@@ -6455,6 +6972,7 @@ exports.ComfyWorkflow = ComfyWorkflow;
|
|
|
6455
6972
|
exports.ComfyWorkflowBuilder = ComfyWorkflowBuilder;
|
|
6456
6973
|
exports.DEFAULT_IMAGE_EXTENSIONS = DEFAULT_IMAGE_EXTENSIONS;
|
|
6457
6974
|
exports.DEFAULT_SIZE_PRESETS = DEFAULT_SIZE_PRESETS;
|
|
6975
|
+
exports.DEFAULT_STARRED_SIZES = DEFAULT_STARRED_SIZES;
|
|
6458
6976
|
exports.DefinedWorkflow = DefinedWorkflow;
|
|
6459
6977
|
exports.FloatVar = FloatVar;
|
|
6460
6978
|
exports.ImageVar = ImageVar;
|
|
@@ -6463,8 +6981,11 @@ exports.IntVar = IntVar;
|
|
|
6463
6981
|
exports.InvalidPromptError = InvalidPromptError;
|
|
6464
6982
|
exports.LorasVar = LorasVar;
|
|
6465
6983
|
exports.MediaImage = MediaImage;
|
|
6984
|
+
exports.MultiChoiceVar = MultiChoiceVar;
|
|
6985
|
+
exports.OptionalChoiceVar = OptionalChoiceVar;
|
|
6466
6986
|
exports.PromptVar = PromptVar;
|
|
6467
6987
|
exports.ResilientWebSocketClient = ResilientWebSocketClient;
|
|
6988
|
+
exports.SD15_SIZE_PRESETS = SD15_SIZE_PRESETS;
|
|
6468
6989
|
exports.SeedVar = SeedVar;
|
|
6469
6990
|
exports.SizeVar = SizeVar;
|
|
6470
6991
|
exports.TextVar = TextVar;
|
|
@@ -6515,6 +7036,7 @@ exports.resultFailure = resultFailure;
|
|
|
6515
7036
|
exports.resultSuccess = resultSuccess;
|
|
6516
7037
|
exports.setDefaultComfyStorage = setDefaultComfyStorage;
|
|
6517
7038
|
exports.setLoraKeyword = setLoraKeyword;
|
|
7039
|
+
exports.sizePresetsFor = sizePresetsFor;
|
|
6518
7040
|
exports.toPresetList = toPresetList;
|
|
6519
7041
|
exports.v = v;
|
|
6520
7042
|
|