comfy-ts 2.14.0 → 2.16.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-CUeo843w.js → LogsSt-Ct7Le0S_.js} +2 -2
- package/dist/{LogsSt-CUeo843w.js.map → LogsSt-Ct7Le0S_.js.map} +1 -1
- package/dist/cli.js +4 -4
- package/dist/index.cjs +268 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +176 -26
- package/dist/index.d.ts +176 -26
- package/dist/index.js +262 -56
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-DUqcn0h3.js → run-serve-C78hD7t9.js} +119 -40
- package/dist/run-serve-C78hD7t9.js.map +1 -0
- package/dist/{run-tui-D-LaSqgB.js → run-tui-nPETFRmk.js} +15 -9
- package/dist/run-tui-nPETFRmk.js.map +1 -0
- package/dist/{schemaDrift-E95iTF7E.js → schemaDrift-wb5XkrHV.js} +218 -27
- package/dist/schemaDrift-wb5XkrHV.js.map +1 -0
- package/dist/serve-web.js +64 -50
- package/dist/{state-BytbdZ8s.js → state-BMW57_M0.js} +45 -35
- package/dist/state-BMW57_M0.js.map +1 -0
- package/dist/web.d.ts +173 -26
- package/dist/web.js +251 -53
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/media/README.md +9 -0
- package/examples/media/sine_440hz_3s.flac +0 -0
- package/examples/media/testsrc_256x256_3s.mp4 +0 -0
- package/examples/media/voice_en_6s.flac +0 -0
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +9 -1
- package/examples/rvion/10-anima-t2i.cflow.ts +8 -1
- package/examples/rvion/14-video-soundtrack.cflow.ts +47 -0
- package/examples/rvion/15-tts-voice-clone.cflow.ts +111 -0
- package/guide-for-agents.md +3 -1
- package/package.json +2 -2
- package/src/cli/serve/ServeApp.ts +115 -32
- package/src/cli/serve/applyVarPayload.ts +5 -3
- package/src/cli/serve/describeVar.ts +5 -3
- package/src/cli/serve/resultHistory.ts +22 -6
- package/src/cli/serve/run-serve.ts +4 -1
- package/src/cli/serve/web/api.ts +4 -0
- package/src/cli/serve/web/components/DraftTabs.tsx +2 -1
- package/src/cli/serve/web/components/Gallery.tsx +86 -5
- package/src/cli/serve/web/components/HistoryPicker.tsx +5 -3
- package/src/cli/serve/web/components/MenuButton.tsx +2 -4
- package/src/cli/serve/web/components/Omnibox.tsx +2 -1
- package/src/cli/serve/web/components/PromptEnhancer.tsx +4 -3
- package/src/cli/serve/web/components/ShortcutsModal.tsx +2 -1
- package/src/cli/serve/web/components/SideMenu.tsx +2 -1
- package/src/cli/serve/web/components/VarsForm.tsx +5 -3
- package/src/cli/serve/web/components/controls/LorasControl.tsx +4 -3
- package/src/cli/serve/web/components/controls/MediaControl.tsx +111 -0
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +2 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +2 -1
- package/src/cli/serve/web/components/controls/SizeControl.tsx +2 -1
- package/src/cli/serve/web/state/FormSt.ts +70 -2
- package/src/cli/serve/web/state/escape.ts +16 -0
- package/src/cli/serve/web/state/host.ts +2 -0
- package/src/cli/serve/web/state/mediaDrop.ts +76 -0
- package/src/cli/serve/web/styles.ts +16 -2
- package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +4 -1
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +15 -6
- package/src/cli/tui/state/TuiSt.ts +1 -1
- package/src/coreExports.ts +20 -1
- package/src/exampleAssets.ts +13 -3
- package/src/host/ComfyUploader.ts +34 -27
- package/src/index.ts +1 -1
- package/src/runner/ComfyExecution.ts +38 -20
- package/src/runner/ComfyWsApi.ts +3 -0
- package/src/runner/mediaKinds.ts +51 -0
- package/src/vars/ComfyVars.ts +178 -34
- package/src/vars/DefinedWorkflow.ts +35 -2
- package/dist/run-serve-DUqcn0h3.js.map +0 -1
- package/dist/run-tui-D-LaSqgB.js.map +0 -1
- package/dist/schemaDrift-E95iTF7E.js.map +0 -1
- package/dist/state-BytbdZ8s.js.map +0 -1
- package/src/cli/serve/web/components/controls/ImageControl.tsx +0 -72
package/dist/index.js
CHANGED
|
@@ -110,7 +110,7 @@ function createNodeStorage() {
|
|
|
110
110
|
}
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region package.json
|
|
113
|
-
var version = "2.
|
|
113
|
+
var version = "2.16.0";
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
116
116
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -2017,6 +2017,8 @@ const types$1 = scope({
|
|
|
2017
2017
|
"previews?": [{ filepath: "string" }, "[]"],
|
|
2018
2018
|
"images?": "ComfyImageInfo[]",
|
|
2019
2019
|
"audio?": "ComfyImageInfo[]",
|
|
2020
|
+
"video?": "ComfyImageInfo[]",
|
|
2021
|
+
"gifs?": "ComfyImageInfo[]",
|
|
2020
2022
|
"text?": "unknown[]"
|
|
2021
2023
|
},
|
|
2022
2024
|
prompt_id: "PromptID"
|
|
@@ -2263,24 +2265,79 @@ var MediaImage = class MediaImage {
|
|
|
2263
2265
|
}
|
|
2264
2266
|
};
|
|
2265
2267
|
//#endregion
|
|
2266
|
-
//#region src/runner/
|
|
2267
|
-
/**
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2268
|
+
//#region src/runner/mediaKinds.ts
|
|
2269
|
+
/** picker defaults per kind, lowercase without dots */
|
|
2270
|
+
const DEFAULT_MEDIA_EXTENSIONS = {
|
|
2271
|
+
image: [
|
|
2272
|
+
"png",
|
|
2273
|
+
"jpg",
|
|
2274
|
+
"jpeg",
|
|
2275
|
+
"webp",
|
|
2276
|
+
"gif"
|
|
2277
|
+
],
|
|
2278
|
+
audio: [
|
|
2279
|
+
"wav",
|
|
2280
|
+
"flac",
|
|
2281
|
+
"mp3",
|
|
2282
|
+
"ogg",
|
|
2283
|
+
"opus",
|
|
2284
|
+
"m4a"
|
|
2285
|
+
],
|
|
2286
|
+
video: [
|
|
2287
|
+
"mp4",
|
|
2288
|
+
"webm",
|
|
2289
|
+
"mov",
|
|
2290
|
+
"mkv",
|
|
2291
|
+
"m4v"
|
|
2292
|
+
]
|
|
2293
|
+
};
|
|
2294
|
+
const MIMES = {
|
|
2295
|
+
png: "image/png",
|
|
2296
|
+
jpg: "image/jpeg",
|
|
2297
|
+
jpeg: "image/jpeg",
|
|
2298
|
+
webp: "image/webp",
|
|
2299
|
+
gif: "image/gif",
|
|
2273
2300
|
flac: "audio/flac",
|
|
2274
2301
|
mp3: "audio/mpeg",
|
|
2275
2302
|
opus: "audio/ogg",
|
|
2276
2303
|
ogg: "audio/ogg",
|
|
2277
2304
|
wav: "audio/wav",
|
|
2278
|
-
m4a: "audio/mp4"
|
|
2305
|
+
m4a: "audio/mp4",
|
|
2306
|
+
aac: "audio/aac",
|
|
2307
|
+
mp4: "video/mp4",
|
|
2308
|
+
m4v: "video/mp4",
|
|
2309
|
+
webm: "video/webm",
|
|
2310
|
+
mov: "video/quicktime",
|
|
2311
|
+
mkv: "video/x-matroska",
|
|
2312
|
+
avi: "video/x-msvideo"
|
|
2279
2313
|
};
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2314
|
+
/** video containers an output node can name. An animated webp or gif is an IMAGE: the
|
|
2315
|
+
* extension decides, never the `animated` flag */
|
|
2316
|
+
const VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2317
|
+
"mp4",
|
|
2318
|
+
"m4v",
|
|
2319
|
+
"webm",
|
|
2320
|
+
"mov",
|
|
2321
|
+
"mkv",
|
|
2322
|
+
"avi"
|
|
2323
|
+
]);
|
|
2324
|
+
function extensionOf(filename) {
|
|
2325
|
+
const dot = filename.lastIndexOf(".");
|
|
2326
|
+
return dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
|
|
2283
2327
|
}
|
|
2328
|
+
function isVideoFilename(filename) {
|
|
2329
|
+
return VIDEO_EXTENSIONS.has(extensionOf(filename));
|
|
2330
|
+
}
|
|
2331
|
+
function mediaMime(filename) {
|
|
2332
|
+
return MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
2333
|
+
}
|
|
2334
|
+
//#endregion
|
|
2335
|
+
//#region src/runner/ComfyExecution.ts
|
|
2336
|
+
/** paths claimed by in-flight retrievals: two same-second runs on a
|
|
2337
|
+
* counter-resetting cloud host compute the same name before either writes.
|
|
2338
|
+
* A claim is released as soon as the write lands (the file itself then holds
|
|
2339
|
+
* the name) or fails (the name is free again) — the set never accumulates */
|
|
2340
|
+
const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
|
|
2284
2341
|
var ComfyExecution = class {
|
|
2285
2342
|
get host() {
|
|
2286
2343
|
return this.workflow.host;
|
|
@@ -2347,15 +2404,28 @@ var ComfyExecution = class {
|
|
|
2347
2404
|
text: entry
|
|
2348
2405
|
});
|
|
2349
2406
|
}
|
|
2350
|
-
const
|
|
2351
|
-
|
|
2407
|
+
const out = msg.data.output;
|
|
2408
|
+
const listed = [
|
|
2409
|
+
...out?.images ?? [],
|
|
2410
|
+
...out?.video ?? [],
|
|
2411
|
+
...out?.gifs ?? []
|
|
2412
|
+
].filter((f) => f.type !== "input");
|
|
2413
|
+
for (const video of listed.filter((f) => isVideoFilename(f.filename))) this.pendingPromises.push(this.retrieveFile("video", video, promptNodeID).catch((e) => {
|
|
2414
|
+
console.error(`🔴 failed to retrieve ${video.filename}:`, e);
|
|
2415
|
+
this.videoErrors.push({
|
|
2416
|
+
video,
|
|
2417
|
+
error: e
|
|
2418
|
+
});
|
|
2419
|
+
}));
|
|
2420
|
+
const images = listed.filter((f) => !isVideoFilename(f.filename));
|
|
2421
|
+
if (images.length > 0) for (const img of images) this.pendingPromises.push(this.retrieveImage(img, promptNodeID).catch((e) => {
|
|
2352
2422
|
console.error(`🔴 failed to retrieve ${img.filename}:`, e);
|
|
2353
2423
|
this.imageErrors.push({
|
|
2354
2424
|
image: img,
|
|
2355
2425
|
error: e
|
|
2356
2426
|
});
|
|
2357
2427
|
}));
|
|
2358
|
-
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.
|
|
2428
|
+
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveFile("audio", audio, promptNodeID).catch((e) => {
|
|
2359
2429
|
console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
|
|
2360
2430
|
this.audioErrors.push({
|
|
2361
2431
|
audio,
|
|
@@ -2366,13 +2436,16 @@ var ComfyExecution = class {
|
|
|
2366
2436
|
this.pendingPromises = [];
|
|
2367
2437
|
this.audioErrors = [];
|
|
2368
2438
|
this.audios = [];
|
|
2369
|
-
this.
|
|
2439
|
+
this.videoErrors = [];
|
|
2440
|
+
this.videos = [];
|
|
2441
|
+
this.retrieveFile = async (kind, info, promptNodeID) => {
|
|
2370
2442
|
const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
|
|
2371
2443
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2372
|
-
const mime =
|
|
2444
|
+
const mime = mediaMime(info.filename);
|
|
2445
|
+
const list = kind === "audio" ? this.audios : this.videos;
|
|
2373
2446
|
const sf = this.save;
|
|
2374
2447
|
if (sf == null) {
|
|
2375
|
-
|
|
2448
|
+
list.push({
|
|
2376
2449
|
nodeId: promptNodeID,
|
|
2377
2450
|
filename: info.filename,
|
|
2378
2451
|
mime,
|
|
@@ -2392,7 +2465,7 @@ var ComfyExecution = class {
|
|
|
2392
2465
|
subfolder: info.subfolder,
|
|
2393
2466
|
filename: info.filename
|
|
2394
2467
|
});
|
|
2395
|
-
|
|
2468
|
+
list.push({
|
|
2396
2469
|
nodeId: promptNodeID,
|
|
2397
2470
|
filename: info.filename,
|
|
2398
2471
|
mime,
|
|
@@ -2572,6 +2645,7 @@ var ComfyExecution = class {
|
|
|
2572
2645
|
const p = this.progress;
|
|
2573
2646
|
const outputs = [`${this.images.length} image(s)`];
|
|
2574
2647
|
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
|
|
2648
|
+
if (this.videos.length > 0) outputs.push(`${this.videos.length} video(s)`);
|
|
2575
2649
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
|
|
2576
2650
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
|
|
2577
2651
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
@@ -3921,15 +3995,23 @@ const ComfyUploadImageResult_ark = type({
|
|
|
3921
3995
|
var ComfyUploader = class {
|
|
3922
3996
|
constructor(host) {
|
|
3923
3997
|
this.host = host;
|
|
3998
|
+
this.uploaded = /* @__PURE__ */ new Set();
|
|
3924
3999
|
this.uploadImage = async (img, p) => {
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
4000
|
+
return await this.uploadInput({
|
|
4001
|
+
blob: img.getAsBlob(),
|
|
4002
|
+
name: img.enumName,
|
|
4003
|
+
...p,
|
|
4004
|
+
slot: "LoadImage.image"
|
|
4005
|
+
});
|
|
4006
|
+
};
|
|
4007
|
+
this.uploadInput = async (p) => {
|
|
4008
|
+
const expectedFinalName = p.subfolder ? `${p.subfolder}/${p.name}` : p.name;
|
|
4009
|
+
if (this.uploaded.has(expectedFinalName) || this.host.schema.stringValues(p.slot).includes(expectedFinalName)) {
|
|
4010
|
+
console.log(`[🌁] UPLOAD: 🩶 "${expectedFinalName}" already exists on current ComfyUI instance`);
|
|
3929
4011
|
return expectedFinalName;
|
|
3930
4012
|
}
|
|
3931
4013
|
const form = new FormData();
|
|
3932
|
-
form.set("image",
|
|
4014
|
+
form.set("image", p.blob, p.name);
|
|
3933
4015
|
if (p.type) form.set("type", p.type);
|
|
3934
4016
|
if (p.override ?? true) form.set("override", "true");
|
|
3935
4017
|
if (p.subfolder) form.set("subfolder", p.subfolder);
|
|
@@ -3939,11 +4021,11 @@ var ComfyUploader = class {
|
|
|
3939
4021
|
});
|
|
3940
4022
|
const result = softValidate(ComfyUploadImageResult_ark, await resp.json());
|
|
3941
4023
|
console.log("[🌁] UPLOAD: ✅ got", result);
|
|
3942
|
-
if (result.name == null) throw new Error(
|
|
4024
|
+
if (result.name == null) throw new Error(`upload of '${p.name}' failed: the host answered no name`);
|
|
3943
4025
|
const finalName = result.subfolder ? `${result.subfolder}/${result.name}` : result.name;
|
|
3944
4026
|
if (finalName !== expectedFinalName) console.warn(`[🌁] UPLOAD: ⚠️ expected "${expectedFinalName}" but got "${finalName}"`);
|
|
3945
|
-
|
|
3946
|
-
this.
|
|
4027
|
+
if (p.slot === "LoadImage.image") this.host.schema.unsafely_addImageInSchemaWithoutReloading(finalName);
|
|
4028
|
+
this.uploaded.add(finalName);
|
|
3947
4029
|
return finalName;
|
|
3948
4030
|
};
|
|
3949
4031
|
}
|
|
@@ -4940,12 +5022,46 @@ var ToggleVar = class extends ComfyVar {
|
|
|
4940
5022
|
return this.value ? "ON" : "OFF";
|
|
4941
5023
|
}
|
|
4942
5024
|
};
|
|
5025
|
+
/** a fixed list, or the host's list for one slot once bindHost ran */
|
|
5026
|
+
var ChoiceList = class {
|
|
5027
|
+
constructor(source) {
|
|
5028
|
+
this.source = source;
|
|
5029
|
+
this.resolved = null;
|
|
5030
|
+
}
|
|
5031
|
+
get slot() {
|
|
5032
|
+
return isChoiceList(this.source) ? null : this.source;
|
|
5033
|
+
}
|
|
5034
|
+
get choices() {
|
|
5035
|
+
if (isChoiceList(this.source)) return this.source;
|
|
5036
|
+
if (this.resolved == null) throw new Error(`v.model('${this.source.slot}') is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list to v.choice otherwise)`);
|
|
5037
|
+
return this.resolved;
|
|
5038
|
+
}
|
|
5039
|
+
/** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
|
|
5040
|
+
* the SAME object_info enum the generated slot union comes from */
|
|
5041
|
+
bind(host) {
|
|
5042
|
+
const src = this.slot;
|
|
5043
|
+
if (src == null) return;
|
|
5044
|
+
const all = host.schema.stringValues(src.slot);
|
|
5045
|
+
const filter = src.filter == null ? null : statelessRegex(src.filter);
|
|
5046
|
+
this.resolved = filter == null ? all : all.filter((n) => filter.test(n));
|
|
5047
|
+
}
|
|
5048
|
+
};
|
|
4943
5049
|
var ChoiceVar = class extends ComfyVar {
|
|
4944
5050
|
constructor(choices, defaultValue, label) {
|
|
4945
5051
|
super(defaultValue, label);
|
|
4946
|
-
this.choices = choices;
|
|
4947
5052
|
this.kind = "choice";
|
|
4948
5053
|
this.select = "one";
|
|
5054
|
+
this.list = new ChoiceList(choices);
|
|
5055
|
+
}
|
|
5056
|
+
get choices() {
|
|
5057
|
+
return this.list.choices;
|
|
5058
|
+
}
|
|
5059
|
+
/** set for `v.model`: the loader input this choice lists */
|
|
5060
|
+
get hostSlot() {
|
|
5061
|
+
return this.list.slot;
|
|
5062
|
+
}
|
|
5063
|
+
bindHost(host) {
|
|
5064
|
+
this.list.bind(host);
|
|
4949
5065
|
}
|
|
4950
5066
|
next(delta = 1) {
|
|
4951
5067
|
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
@@ -4962,9 +5078,18 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4962
5078
|
var OptionalChoiceVar = class extends ComfyVar {
|
|
4963
5079
|
constructor(choices, defaultValue, label) {
|
|
4964
5080
|
super(defaultValue, label);
|
|
4965
|
-
this.choices = choices;
|
|
4966
5081
|
this.kind = "choice";
|
|
4967
5082
|
this.select = "zero-or-one";
|
|
5083
|
+
this.list = new ChoiceList(choices);
|
|
5084
|
+
}
|
|
5085
|
+
get choices() {
|
|
5086
|
+
return this.list.choices;
|
|
5087
|
+
}
|
|
5088
|
+
get hostSlot() {
|
|
5089
|
+
return this.list.slot;
|
|
5090
|
+
}
|
|
5091
|
+
bindHost(host) {
|
|
5092
|
+
this.list.bind(host);
|
|
4968
5093
|
}
|
|
4969
5094
|
/** pick `c`, or clear it when it is already the one picked */
|
|
4970
5095
|
toggle(c) {
|
|
@@ -5042,6 +5167,14 @@ function choice(choices, defaultValue, opts) {
|
|
|
5042
5167
|
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
5043
5168
|
return new ChoiceVar(choices, defaultValue, o.label);
|
|
5044
5169
|
}
|
|
5170
|
+
function model(slot, opts) {
|
|
5171
|
+
const source = {
|
|
5172
|
+
slot,
|
|
5173
|
+
filter: opts.filter
|
|
5174
|
+
};
|
|
5175
|
+
if (opts.default == null) return new OptionalChoiceVar(source, null, opts.label);
|
|
5176
|
+
return new ChoiceVar(source, opts.default, opts.label);
|
|
5177
|
+
}
|
|
5045
5178
|
/** normalize a loras record into what a standard LoraLoader chain consumes */
|
|
5046
5179
|
function activeLoras(loras) {
|
|
5047
5180
|
const out = [];
|
|
@@ -5328,42 +5461,55 @@ var SizeVar = class extends ComfyVar {
|
|
|
5328
5461
|
return `${width}×${height}${hit ? ` (${hit.label})` : ""}`;
|
|
5329
5462
|
}
|
|
5330
5463
|
};
|
|
5331
|
-
const DEFAULT_IMAGE_EXTENSIONS =
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
"
|
|
5337
|
-
|
|
5338
|
-
/** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
|
|
5339
|
-
var ImageVarEmptyError = class extends Error {
|
|
5340
|
-
constructor(varName) {
|
|
5341
|
-
super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`);
|
|
5464
|
+
const DEFAULT_IMAGE_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.image;
|
|
5465
|
+
const DEFAULT_AUDIO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.audio;
|
|
5466
|
+
const DEFAULT_VIDEO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.video;
|
|
5467
|
+
/** empty media var consumed at build time — typed so drivers surface it apart from real crashes */
|
|
5468
|
+
var MediaVarEmptyError = class extends Error {
|
|
5469
|
+
constructor(varName, media = "image") {
|
|
5470
|
+
super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`);
|
|
5342
5471
|
this.varName = varName;
|
|
5343
|
-
this.
|
|
5472
|
+
this.media = media;
|
|
5473
|
+
this.name = "MediaVarEmptyError";
|
|
5344
5474
|
}
|
|
5345
5475
|
};
|
|
5346
|
-
/**
|
|
5476
|
+
/** the image-only name this error had first; the same class */
|
|
5477
|
+
const ImageVarEmptyError = MediaVarEmptyError;
|
|
5478
|
+
/** trim + expand a leading `~/` — every media var write funnels through this */
|
|
5347
5479
|
function expandUserPath(raw) {
|
|
5348
5480
|
const trimmed = raw.trim();
|
|
5349
5481
|
return trimmed.startsWith("~/") ? join(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed;
|
|
5350
5482
|
}
|
|
5483
|
+
/** the loader node each medium goes through, and its file input */
|
|
5484
|
+
const MEDIA_LOADERS = {
|
|
5485
|
+
image: {
|
|
5486
|
+
node: "LoadImage",
|
|
5487
|
+
input: "image"
|
|
5488
|
+
},
|
|
5489
|
+
audio: {
|
|
5490
|
+
node: "LoadAudio",
|
|
5491
|
+
input: "audio"
|
|
5492
|
+
},
|
|
5493
|
+
video: {
|
|
5494
|
+
node: "LoadVideo",
|
|
5495
|
+
input: "file"
|
|
5496
|
+
}
|
|
5497
|
+
};
|
|
5351
5498
|
/**
|
|
5352
|
-
* a local
|
|
5499
|
+
* a local media file path. The VALUE is a PLAIN PATH STRING — text-encodable,
|
|
5353
5500
|
* drafts persist it verbatim (toJSON = the string), hand-editable in the
|
|
5354
|
-
* draft json. Empty = unset: outValue()/absPath() throw
|
|
5355
|
-
* so a build never runs on a silent placeholder. The TUI opens the
|
|
5356
|
-
* picker overlay for kind
|
|
5501
|
+
* draft json. Empty = unset: outValue()/absPath() throw MediaVarEmptyError,
|
|
5502
|
+
* so a build never runs on a silent placeholder. The TUI opens the file
|
|
5503
|
+
* picker overlay for every media kind.
|
|
5357
5504
|
*/
|
|
5358
|
-
var
|
|
5505
|
+
var MediaVar = class extends ComfyVar {
|
|
5359
5506
|
constructor(defaultValue, opts = {}) {
|
|
5360
5507
|
super(expandUserPath(defaultValue), opts.label);
|
|
5361
5508
|
this.opts = opts;
|
|
5362
|
-
this.kind = "image";
|
|
5363
5509
|
}
|
|
5364
5510
|
/** what the picker lists (lowercase, no dots) */
|
|
5365
5511
|
get extensions() {
|
|
5366
|
-
return this.opts.extensions ??
|
|
5512
|
+
return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind];
|
|
5367
5513
|
}
|
|
5368
5514
|
set(value) {
|
|
5369
5515
|
return super.set(expandUserPath(value));
|
|
@@ -5376,7 +5522,7 @@ var ImageVar = class extends ComfyVar {
|
|
|
5376
5522
|
return this.value !== "";
|
|
5377
5523
|
}
|
|
5378
5524
|
emptyError() {
|
|
5379
|
-
return new
|
|
5525
|
+
return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind);
|
|
5380
5526
|
}
|
|
5381
5527
|
/** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
|
|
5382
5528
|
absPath() {
|
|
@@ -5394,8 +5540,56 @@ var ImageVar = class extends ComfyVar {
|
|
|
5394
5540
|
const home = getComfyStorage().homedir();
|
|
5395
5541
|
return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
|
|
5396
5542
|
}
|
|
5543
|
+
/** upload the file hash-named (reruns dedupe) and add this medium's loader node. A dry
|
|
5544
|
+
* build names the file by its hash and uploads nothing */
|
|
5545
|
+
async loadVia(wf) {
|
|
5546
|
+
const loader = MEDIA_LOADERS[this.kind];
|
|
5547
|
+
const factory = wf.builderBase[loader.node];
|
|
5548
|
+
if (factory == null) throw new Error(`host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? "?"}' cannot load`);
|
|
5549
|
+
const abs = this.absPath();
|
|
5550
|
+
const bytes = getComfyStorage().readBytes(abs);
|
|
5551
|
+
const ext = extensionOf(abs);
|
|
5552
|
+
const name = `${hashArrayBuffer(bytes)}${ext === "" ? "" : `.${ext}`}`;
|
|
5553
|
+
const onHost = wf.dry ? name : await wf.host.uploader.uploadInput({
|
|
5554
|
+
blob: new Blob([bytes], { type: mediaMime(abs) }),
|
|
5555
|
+
name,
|
|
5556
|
+
slot: `${loader.node}.${loader.input}`,
|
|
5557
|
+
type: "input"
|
|
5558
|
+
});
|
|
5559
|
+
return factory({ [loader.input]: onHost });
|
|
5560
|
+
}
|
|
5561
|
+
};
|
|
5562
|
+
/** a local image path, loaded through LoadImage */
|
|
5563
|
+
var ImageVar = class extends MediaVar {
|
|
5564
|
+
constructor(..._args2) {
|
|
5565
|
+
super(..._args2);
|
|
5566
|
+
this.kind = "image";
|
|
5567
|
+
}
|
|
5568
|
+
async loadInWorkflow(wf) {
|
|
5569
|
+
return await this.loadVia(wf);
|
|
5570
|
+
}
|
|
5571
|
+
};
|
|
5572
|
+
/** a local audio path, loaded through LoadAudio */
|
|
5573
|
+
var AudioVar = class extends MediaVar {
|
|
5574
|
+
constructor(..._args3) {
|
|
5575
|
+
super(..._args3);
|
|
5576
|
+
this.kind = "audio";
|
|
5577
|
+
}
|
|
5578
|
+
async loadInWorkflow(wf) {
|
|
5579
|
+
return await this.loadVia(wf);
|
|
5580
|
+
}
|
|
5397
5581
|
};
|
|
5398
|
-
/**
|
|
5582
|
+
/** a local video path, loaded through LoadVideo */
|
|
5583
|
+
var VideoVar = class extends MediaVar {
|
|
5584
|
+
constructor(..._args4) {
|
|
5585
|
+
super(..._args4);
|
|
5586
|
+
this.kind = "video";
|
|
5587
|
+
}
|
|
5588
|
+
async loadInWorkflow(wf) {
|
|
5589
|
+
return await this.loadVia(wf);
|
|
5590
|
+
}
|
|
5591
|
+
};
|
|
5592
|
+
/** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.model / v.loras / v.size / v.image / v.audio / v.video */
|
|
5399
5593
|
const v = {
|
|
5400
5594
|
text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
|
|
5401
5595
|
prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
|
|
@@ -5410,7 +5604,11 @@ const v = {
|
|
|
5410
5604
|
choice,
|
|
5411
5605
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
5412
5606
|
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
5413
|
-
|
|
5607
|
+
/** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
|
|
5608
|
+
model,
|
|
5609
|
+
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts),
|
|
5610
|
+
audio: (defaultValue, opts = {}) => new AudioVar(defaultValue, opts),
|
|
5611
|
+
video: (defaultValue, opts = {}) => new VideoVar(defaultValue, opts)
|
|
5414
5612
|
};
|
|
5415
5613
|
function varValues(vars) {
|
|
5416
5614
|
const out = {};
|
|
@@ -6862,10 +7060,18 @@ function bundledExamplesDir(moduleUrl = import.meta.url) {
|
|
|
6862
7060
|
* or the package's examples/ folder was pruned.
|
|
6863
7061
|
*/
|
|
6864
7062
|
function exampleImagePath(name) {
|
|
7063
|
+
return bundledExampleFile("images", name);
|
|
7064
|
+
}
|
|
7065
|
+
/** the same for a bundled `examples/media/` audio or video file, e.g.
|
|
7066
|
+
* `exampleMediaPath('sine_440hz_3s.flac')` — the default of audio and video example vars */
|
|
7067
|
+
function exampleMediaPath(name) {
|
|
7068
|
+
return bundledExampleFile("media", name);
|
|
7069
|
+
}
|
|
7070
|
+
function bundledExampleFile(folder, name) {
|
|
6865
7071
|
const examples = bundledExamplesDir();
|
|
6866
|
-
if (examples == null) throw new Error(`[comfy-ts] cannot resolve bundled example
|
|
6867
|
-
const abs = join(examples,
|
|
6868
|
-
if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example
|
|
7072
|
+
if (examples == null) throw new Error(`[comfy-ts] cannot resolve bundled example file '${name}': the package's examples/ folder is not on disk`);
|
|
7073
|
+
const abs = join(examples, folder, name);
|
|
7074
|
+
if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example file not found: ${abs}`);
|
|
6869
7075
|
return abs;
|
|
6870
7076
|
}
|
|
6871
7077
|
//#endregion
|
|
@@ -6928,6 +7134,6 @@ function isTuiActive() {
|
|
|
6928
7134
|
*/
|
|
6929
7135
|
setDefaultComfyStorage(createNodeStorage());
|
|
6930
7136
|
//#endregion
|
|
6931
|
-
export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, MultiChoiceVar, OptionalChoiceVar, PromptVar, ResilientWebSocketClient, SD15_SIZE_PRESETS, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, isTuiActive, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, promptEnhancerPresets, readPromptEnhancers, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
|
|
7137
|
+
export { AudioVar, ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_AUDIO_EXTENSIONS, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DEFAULT_VIDEO_EXTENSIONS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, MediaVar, MediaVarEmptyError, MultiChoiceVar, OptionalChoiceVar, PromptVar, ResilientWebSocketClient, SD15_SIZE_PRESETS, SeedVar, SizeVar, TextVar, ToggleVar, VideoVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, exampleImagePath, exampleMediaPath, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, isTuiActive, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, promptEnhancerPresets, readPromptEnhancers, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
|
|
6932
7138
|
|
|
6933
7139
|
//# sourceMappingURL=index.js.map
|