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.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.16.0";
|
|
138
138
|
//#endregion
|
|
139
139
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
140
140
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -2044,6 +2044,8 @@ const types$1 = (0, arktype.scope)({
|
|
|
2044
2044
|
"previews?": [{ filepath: "string" }, "[]"],
|
|
2045
2045
|
"images?": "ComfyImageInfo[]",
|
|
2046
2046
|
"audio?": "ComfyImageInfo[]",
|
|
2047
|
+
"video?": "ComfyImageInfo[]",
|
|
2048
|
+
"gifs?": "ComfyImageInfo[]",
|
|
2047
2049
|
"text?": "unknown[]"
|
|
2048
2050
|
},
|
|
2049
2051
|
prompt_id: "PromptID"
|
|
@@ -2290,24 +2292,79 @@ var MediaImage = class MediaImage {
|
|
|
2290
2292
|
}
|
|
2291
2293
|
};
|
|
2292
2294
|
//#endregion
|
|
2293
|
-
//#region src/runner/
|
|
2294
|
-
/**
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2295
|
+
//#region src/runner/mediaKinds.ts
|
|
2296
|
+
/** picker defaults per kind, lowercase without dots */
|
|
2297
|
+
const DEFAULT_MEDIA_EXTENSIONS = {
|
|
2298
|
+
image: [
|
|
2299
|
+
"png",
|
|
2300
|
+
"jpg",
|
|
2301
|
+
"jpeg",
|
|
2302
|
+
"webp",
|
|
2303
|
+
"gif"
|
|
2304
|
+
],
|
|
2305
|
+
audio: [
|
|
2306
|
+
"wav",
|
|
2307
|
+
"flac",
|
|
2308
|
+
"mp3",
|
|
2309
|
+
"ogg",
|
|
2310
|
+
"opus",
|
|
2311
|
+
"m4a"
|
|
2312
|
+
],
|
|
2313
|
+
video: [
|
|
2314
|
+
"mp4",
|
|
2315
|
+
"webm",
|
|
2316
|
+
"mov",
|
|
2317
|
+
"mkv",
|
|
2318
|
+
"m4v"
|
|
2319
|
+
]
|
|
2320
|
+
};
|
|
2321
|
+
const MIMES = {
|
|
2322
|
+
png: "image/png",
|
|
2323
|
+
jpg: "image/jpeg",
|
|
2324
|
+
jpeg: "image/jpeg",
|
|
2325
|
+
webp: "image/webp",
|
|
2326
|
+
gif: "image/gif",
|
|
2300
2327
|
flac: "audio/flac",
|
|
2301
2328
|
mp3: "audio/mpeg",
|
|
2302
2329
|
opus: "audio/ogg",
|
|
2303
2330
|
ogg: "audio/ogg",
|
|
2304
2331
|
wav: "audio/wav",
|
|
2305
|
-
m4a: "audio/mp4"
|
|
2332
|
+
m4a: "audio/mp4",
|
|
2333
|
+
aac: "audio/aac",
|
|
2334
|
+
mp4: "video/mp4",
|
|
2335
|
+
m4v: "video/mp4",
|
|
2336
|
+
webm: "video/webm",
|
|
2337
|
+
mov: "video/quicktime",
|
|
2338
|
+
mkv: "video/x-matroska",
|
|
2339
|
+
avi: "video/x-msvideo"
|
|
2306
2340
|
};
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2341
|
+
/** video containers an output node can name. An animated webp or gif is an IMAGE: the
|
|
2342
|
+
* extension decides, never the `animated` flag */
|
|
2343
|
+
const VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2344
|
+
"mp4",
|
|
2345
|
+
"m4v",
|
|
2346
|
+
"webm",
|
|
2347
|
+
"mov",
|
|
2348
|
+
"mkv",
|
|
2349
|
+
"avi"
|
|
2350
|
+
]);
|
|
2351
|
+
function extensionOf(filename) {
|
|
2352
|
+
const dot = filename.lastIndexOf(".");
|
|
2353
|
+
return dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
|
|
2310
2354
|
}
|
|
2355
|
+
function isVideoFilename(filename) {
|
|
2356
|
+
return VIDEO_EXTENSIONS.has(extensionOf(filename));
|
|
2357
|
+
}
|
|
2358
|
+
function mediaMime(filename) {
|
|
2359
|
+
return MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
2360
|
+
}
|
|
2361
|
+
//#endregion
|
|
2362
|
+
//#region src/runner/ComfyExecution.ts
|
|
2363
|
+
/** paths claimed by in-flight retrievals: two same-second runs on a
|
|
2364
|
+
* counter-resetting cloud host compute the same name before either writes.
|
|
2365
|
+
* A claim is released as soon as the write lands (the file itself then holds
|
|
2366
|
+
* the name) or fails (the name is free again) — the set never accumulates */
|
|
2367
|
+
const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
|
|
2311
2368
|
var ComfyExecution = class {
|
|
2312
2369
|
get host() {
|
|
2313
2370
|
return this.workflow.host;
|
|
@@ -2374,15 +2431,28 @@ var ComfyExecution = class {
|
|
|
2374
2431
|
text: entry
|
|
2375
2432
|
});
|
|
2376
2433
|
}
|
|
2377
|
-
const
|
|
2378
|
-
|
|
2434
|
+
const out = msg.data.output;
|
|
2435
|
+
const listed = [
|
|
2436
|
+
...out?.images ?? [],
|
|
2437
|
+
...out?.video ?? [],
|
|
2438
|
+
...out?.gifs ?? []
|
|
2439
|
+
].filter((f) => f.type !== "input");
|
|
2440
|
+
for (const video of listed.filter((f) => isVideoFilename(f.filename))) this.pendingPromises.push(this.retrieveFile("video", video, promptNodeID).catch((e) => {
|
|
2441
|
+
console.error(`🔴 failed to retrieve ${video.filename}:`, e);
|
|
2442
|
+
this.videoErrors.push({
|
|
2443
|
+
video,
|
|
2444
|
+
error: e
|
|
2445
|
+
});
|
|
2446
|
+
}));
|
|
2447
|
+
const images = listed.filter((f) => !isVideoFilename(f.filename));
|
|
2448
|
+
if (images.length > 0) for (const img of images) this.pendingPromises.push(this.retrieveImage(img, promptNodeID).catch((e) => {
|
|
2379
2449
|
console.error(`🔴 failed to retrieve ${img.filename}:`, e);
|
|
2380
2450
|
this.imageErrors.push({
|
|
2381
2451
|
image: img,
|
|
2382
2452
|
error: e
|
|
2383
2453
|
});
|
|
2384
2454
|
}));
|
|
2385
|
-
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.
|
|
2455
|
+
for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveFile("audio", audio, promptNodeID).catch((e) => {
|
|
2386
2456
|
console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
|
|
2387
2457
|
this.audioErrors.push({
|
|
2388
2458
|
audio,
|
|
@@ -2393,13 +2463,16 @@ var ComfyExecution = class {
|
|
|
2393
2463
|
this.pendingPromises = [];
|
|
2394
2464
|
this.audioErrors = [];
|
|
2395
2465
|
this.audios = [];
|
|
2396
|
-
this.
|
|
2466
|
+
this.videoErrors = [];
|
|
2467
|
+
this.videos = [];
|
|
2468
|
+
this.retrieveFile = async (kind, info, promptNodeID) => {
|
|
2397
2469
|
const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
|
|
2398
2470
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2399
|
-
const mime =
|
|
2471
|
+
const mime = mediaMime(info.filename);
|
|
2472
|
+
const list = kind === "audio" ? this.audios : this.videos;
|
|
2400
2473
|
const sf = this.save;
|
|
2401
2474
|
if (sf == null) {
|
|
2402
|
-
|
|
2475
|
+
list.push({
|
|
2403
2476
|
nodeId: promptNodeID,
|
|
2404
2477
|
filename: info.filename,
|
|
2405
2478
|
mime,
|
|
@@ -2419,7 +2492,7 @@ var ComfyExecution = class {
|
|
|
2419
2492
|
subfolder: info.subfolder,
|
|
2420
2493
|
filename: info.filename
|
|
2421
2494
|
});
|
|
2422
|
-
|
|
2495
|
+
list.push({
|
|
2423
2496
|
nodeId: promptNodeID,
|
|
2424
2497
|
filename: info.filename,
|
|
2425
2498
|
mime,
|
|
@@ -2599,6 +2672,7 @@ var ComfyExecution = class {
|
|
|
2599
2672
|
const p = this.progress;
|
|
2600
2673
|
const outputs = [`${this.images.length} image(s)`];
|
|
2601
2674
|
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
|
|
2675
|
+
if (this.videos.length > 0) outputs.push(`${this.videos.length} video(s)`);
|
|
2602
2676
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
|
|
2603
2677
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
|
|
2604
2678
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
@@ -3948,15 +4022,23 @@ const ComfyUploadImageResult_ark = (0, arktype.type)({
|
|
|
3948
4022
|
var ComfyUploader = class {
|
|
3949
4023
|
constructor(host) {
|
|
3950
4024
|
this.host = host;
|
|
4025
|
+
this.uploaded = /* @__PURE__ */ new Set();
|
|
3951
4026
|
this.uploadImage = async (img, p) => {
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
4027
|
+
return await this.uploadInput({
|
|
4028
|
+
blob: img.getAsBlob(),
|
|
4029
|
+
name: img.enumName,
|
|
4030
|
+
...p,
|
|
4031
|
+
slot: "LoadImage.image"
|
|
4032
|
+
});
|
|
4033
|
+
};
|
|
4034
|
+
this.uploadInput = async (p) => {
|
|
4035
|
+
const expectedFinalName = p.subfolder ? `${p.subfolder}/${p.name}` : p.name;
|
|
4036
|
+
if (this.uploaded.has(expectedFinalName) || this.host.schema.stringValues(p.slot).includes(expectedFinalName)) {
|
|
4037
|
+
console.log(`[🌁] UPLOAD: 🩶 "${expectedFinalName}" already exists on current ComfyUI instance`);
|
|
3956
4038
|
return expectedFinalName;
|
|
3957
4039
|
}
|
|
3958
4040
|
const form = new FormData();
|
|
3959
|
-
form.set("image",
|
|
4041
|
+
form.set("image", p.blob, p.name);
|
|
3960
4042
|
if (p.type) form.set("type", p.type);
|
|
3961
4043
|
if (p.override ?? true) form.set("override", "true");
|
|
3962
4044
|
if (p.subfolder) form.set("subfolder", p.subfolder);
|
|
@@ -3966,11 +4048,11 @@ var ComfyUploader = class {
|
|
|
3966
4048
|
});
|
|
3967
4049
|
const result = softValidate(ComfyUploadImageResult_ark, await resp.json());
|
|
3968
4050
|
console.log("[🌁] UPLOAD: ✅ got", result);
|
|
3969
|
-
if (result.name == null) throw new Error(
|
|
4051
|
+
if (result.name == null) throw new Error(`upload of '${p.name}' failed: the host answered no name`);
|
|
3970
4052
|
const finalName = result.subfolder ? `${result.subfolder}/${result.name}` : result.name;
|
|
3971
4053
|
if (finalName !== expectedFinalName) console.warn(`[🌁] UPLOAD: ⚠️ expected "${expectedFinalName}" but got "${finalName}"`);
|
|
3972
|
-
|
|
3973
|
-
this.
|
|
4054
|
+
if (p.slot === "LoadImage.image") this.host.schema.unsafely_addImageInSchemaWithoutReloading(finalName);
|
|
4055
|
+
this.uploaded.add(finalName);
|
|
3974
4056
|
return finalName;
|
|
3975
4057
|
};
|
|
3976
4058
|
}
|
|
@@ -4967,12 +5049,46 @@ var ToggleVar = class extends ComfyVar {
|
|
|
4967
5049
|
return this.value ? "ON" : "OFF";
|
|
4968
5050
|
}
|
|
4969
5051
|
};
|
|
5052
|
+
/** a fixed list, or the host's list for one slot once bindHost ran */
|
|
5053
|
+
var ChoiceList = class {
|
|
5054
|
+
constructor(source) {
|
|
5055
|
+
this.source = source;
|
|
5056
|
+
this.resolved = null;
|
|
5057
|
+
}
|
|
5058
|
+
get slot() {
|
|
5059
|
+
return isChoiceList(this.source) ? null : this.source;
|
|
5060
|
+
}
|
|
5061
|
+
get choices() {
|
|
5062
|
+
if (isChoiceList(this.source)) return this.source;
|
|
5063
|
+
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)`);
|
|
5064
|
+
return this.resolved;
|
|
5065
|
+
}
|
|
5066
|
+
/** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
|
|
5067
|
+
* the SAME object_info enum the generated slot union comes from */
|
|
5068
|
+
bind(host) {
|
|
5069
|
+
const src = this.slot;
|
|
5070
|
+
if (src == null) return;
|
|
5071
|
+
const all = host.schema.stringValues(src.slot);
|
|
5072
|
+
const filter = src.filter == null ? null : statelessRegex(src.filter);
|
|
5073
|
+
this.resolved = filter == null ? all : all.filter((n) => filter.test(n));
|
|
5074
|
+
}
|
|
5075
|
+
};
|
|
4970
5076
|
var ChoiceVar = class extends ComfyVar {
|
|
4971
5077
|
constructor(choices, defaultValue, label) {
|
|
4972
5078
|
super(defaultValue, label);
|
|
4973
|
-
this.choices = choices;
|
|
4974
5079
|
this.kind = "choice";
|
|
4975
5080
|
this.select = "one";
|
|
5081
|
+
this.list = new ChoiceList(choices);
|
|
5082
|
+
}
|
|
5083
|
+
get choices() {
|
|
5084
|
+
return this.list.choices;
|
|
5085
|
+
}
|
|
5086
|
+
/** set for `v.model`: the loader input this choice lists */
|
|
5087
|
+
get hostSlot() {
|
|
5088
|
+
return this.list.slot;
|
|
5089
|
+
}
|
|
5090
|
+
bindHost(host) {
|
|
5091
|
+
this.list.bind(host);
|
|
4976
5092
|
}
|
|
4977
5093
|
next(delta = 1) {
|
|
4978
5094
|
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
@@ -4989,9 +5105,18 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
4989
5105
|
var OptionalChoiceVar = class extends ComfyVar {
|
|
4990
5106
|
constructor(choices, defaultValue, label) {
|
|
4991
5107
|
super(defaultValue, label);
|
|
4992
|
-
this.choices = choices;
|
|
4993
5108
|
this.kind = "choice";
|
|
4994
5109
|
this.select = "zero-or-one";
|
|
5110
|
+
this.list = new ChoiceList(choices);
|
|
5111
|
+
}
|
|
5112
|
+
get choices() {
|
|
5113
|
+
return this.list.choices;
|
|
5114
|
+
}
|
|
5115
|
+
get hostSlot() {
|
|
5116
|
+
return this.list.slot;
|
|
5117
|
+
}
|
|
5118
|
+
bindHost(host) {
|
|
5119
|
+
this.list.bind(host);
|
|
4995
5120
|
}
|
|
4996
5121
|
/** pick `c`, or clear it when it is already the one picked */
|
|
4997
5122
|
toggle(c) {
|
|
@@ -5069,6 +5194,14 @@ function choice(choices, defaultValue, opts) {
|
|
|
5069
5194
|
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
5070
5195
|
return new ChoiceVar(choices, defaultValue, o.label);
|
|
5071
5196
|
}
|
|
5197
|
+
function model(slot, opts) {
|
|
5198
|
+
const source = {
|
|
5199
|
+
slot,
|
|
5200
|
+
filter: opts.filter
|
|
5201
|
+
};
|
|
5202
|
+
if (opts.default == null) return new OptionalChoiceVar(source, null, opts.label);
|
|
5203
|
+
return new ChoiceVar(source, opts.default, opts.label);
|
|
5204
|
+
}
|
|
5072
5205
|
/** normalize a loras record into what a standard LoraLoader chain consumes */
|
|
5073
5206
|
function activeLoras(loras) {
|
|
5074
5207
|
const out = [];
|
|
@@ -5355,42 +5488,55 @@ var SizeVar = class extends ComfyVar {
|
|
|
5355
5488
|
return `${width}×${height}${hit ? ` (${hit.label})` : ""}`;
|
|
5356
5489
|
}
|
|
5357
5490
|
};
|
|
5358
|
-
const DEFAULT_IMAGE_EXTENSIONS =
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
"
|
|
5364
|
-
|
|
5365
|
-
/** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
|
|
5366
|
-
var ImageVarEmptyError = class extends Error {
|
|
5367
|
-
constructor(varName) {
|
|
5368
|
-
super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`);
|
|
5491
|
+
const DEFAULT_IMAGE_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.image;
|
|
5492
|
+
const DEFAULT_AUDIO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.audio;
|
|
5493
|
+
const DEFAULT_VIDEO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.video;
|
|
5494
|
+
/** empty media var consumed at build time — typed so drivers surface it apart from real crashes */
|
|
5495
|
+
var MediaVarEmptyError = class extends Error {
|
|
5496
|
+
constructor(varName, media = "image") {
|
|
5497
|
+
super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`);
|
|
5369
5498
|
this.varName = varName;
|
|
5370
|
-
this.
|
|
5499
|
+
this.media = media;
|
|
5500
|
+
this.name = "MediaVarEmptyError";
|
|
5371
5501
|
}
|
|
5372
5502
|
};
|
|
5373
|
-
/**
|
|
5503
|
+
/** the image-only name this error had first; the same class */
|
|
5504
|
+
const ImageVarEmptyError = MediaVarEmptyError;
|
|
5505
|
+
/** trim + expand a leading `~/` — every media var write funnels through this */
|
|
5374
5506
|
function expandUserPath(raw) {
|
|
5375
5507
|
const trimmed = raw.trim();
|
|
5376
5508
|
return trimmed.startsWith("~/") ? (0, pathe.join)(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed;
|
|
5377
5509
|
}
|
|
5510
|
+
/** the loader node each medium goes through, and its file input */
|
|
5511
|
+
const MEDIA_LOADERS = {
|
|
5512
|
+
image: {
|
|
5513
|
+
node: "LoadImage",
|
|
5514
|
+
input: "image"
|
|
5515
|
+
},
|
|
5516
|
+
audio: {
|
|
5517
|
+
node: "LoadAudio",
|
|
5518
|
+
input: "audio"
|
|
5519
|
+
},
|
|
5520
|
+
video: {
|
|
5521
|
+
node: "LoadVideo",
|
|
5522
|
+
input: "file"
|
|
5523
|
+
}
|
|
5524
|
+
};
|
|
5378
5525
|
/**
|
|
5379
|
-
* a local
|
|
5526
|
+
* a local media file path. The VALUE is a PLAIN PATH STRING — text-encodable,
|
|
5380
5527
|
* drafts persist it verbatim (toJSON = the string), hand-editable in the
|
|
5381
|
-
* draft json. Empty = unset: outValue()/absPath() throw
|
|
5382
|
-
* so a build never runs on a silent placeholder. The TUI opens the
|
|
5383
|
-
* picker overlay for kind
|
|
5528
|
+
* draft json. Empty = unset: outValue()/absPath() throw MediaVarEmptyError,
|
|
5529
|
+
* so a build never runs on a silent placeholder. The TUI opens the file
|
|
5530
|
+
* picker overlay for every media kind.
|
|
5384
5531
|
*/
|
|
5385
|
-
var
|
|
5532
|
+
var MediaVar = class extends ComfyVar {
|
|
5386
5533
|
constructor(defaultValue, opts = {}) {
|
|
5387
5534
|
super(expandUserPath(defaultValue), opts.label);
|
|
5388
5535
|
this.opts = opts;
|
|
5389
|
-
this.kind = "image";
|
|
5390
5536
|
}
|
|
5391
5537
|
/** what the picker lists (lowercase, no dots) */
|
|
5392
5538
|
get extensions() {
|
|
5393
|
-
return this.opts.extensions ??
|
|
5539
|
+
return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind];
|
|
5394
5540
|
}
|
|
5395
5541
|
set(value) {
|
|
5396
5542
|
return super.set(expandUserPath(value));
|
|
@@ -5403,7 +5549,7 @@ var ImageVar = class extends ComfyVar {
|
|
|
5403
5549
|
return this.value !== "";
|
|
5404
5550
|
}
|
|
5405
5551
|
emptyError() {
|
|
5406
|
-
return new
|
|
5552
|
+
return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind);
|
|
5407
5553
|
}
|
|
5408
5554
|
/** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
|
|
5409
5555
|
absPath() {
|
|
@@ -5421,8 +5567,56 @@ var ImageVar = class extends ComfyVar {
|
|
|
5421
5567
|
const home = getComfyStorage().homedir();
|
|
5422
5568
|
return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
|
|
5423
5569
|
}
|
|
5570
|
+
/** upload the file hash-named (reruns dedupe) and add this medium's loader node. A dry
|
|
5571
|
+
* build names the file by its hash and uploads nothing */
|
|
5572
|
+
async loadVia(wf) {
|
|
5573
|
+
const loader = MEDIA_LOADERS[this.kind];
|
|
5574
|
+
const factory = wf.builderBase[loader.node];
|
|
5575
|
+
if (factory == null) throw new Error(`host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? "?"}' cannot load`);
|
|
5576
|
+
const abs = this.absPath();
|
|
5577
|
+
const bytes = getComfyStorage().readBytes(abs);
|
|
5578
|
+
const ext = extensionOf(abs);
|
|
5579
|
+
const name = `${hashArrayBuffer(bytes)}${ext === "" ? "" : `.${ext}`}`;
|
|
5580
|
+
const onHost = wf.dry ? name : await wf.host.uploader.uploadInput({
|
|
5581
|
+
blob: new Blob([bytes], { type: mediaMime(abs) }),
|
|
5582
|
+
name,
|
|
5583
|
+
slot: `${loader.node}.${loader.input}`,
|
|
5584
|
+
type: "input"
|
|
5585
|
+
});
|
|
5586
|
+
return factory({ [loader.input]: onHost });
|
|
5587
|
+
}
|
|
5588
|
+
};
|
|
5589
|
+
/** a local image path, loaded through LoadImage */
|
|
5590
|
+
var ImageVar = class extends MediaVar {
|
|
5591
|
+
constructor(..._args2) {
|
|
5592
|
+
super(..._args2);
|
|
5593
|
+
this.kind = "image";
|
|
5594
|
+
}
|
|
5595
|
+
async loadInWorkflow(wf) {
|
|
5596
|
+
return await this.loadVia(wf);
|
|
5597
|
+
}
|
|
5598
|
+
};
|
|
5599
|
+
/** a local audio path, loaded through LoadAudio */
|
|
5600
|
+
var AudioVar = class extends MediaVar {
|
|
5601
|
+
constructor(..._args3) {
|
|
5602
|
+
super(..._args3);
|
|
5603
|
+
this.kind = "audio";
|
|
5604
|
+
}
|
|
5605
|
+
async loadInWorkflow(wf) {
|
|
5606
|
+
return await this.loadVia(wf);
|
|
5607
|
+
}
|
|
5424
5608
|
};
|
|
5425
|
-
/**
|
|
5609
|
+
/** a local video path, loaded through LoadVideo */
|
|
5610
|
+
var VideoVar = class extends MediaVar {
|
|
5611
|
+
constructor(..._args4) {
|
|
5612
|
+
super(..._args4);
|
|
5613
|
+
this.kind = "video";
|
|
5614
|
+
}
|
|
5615
|
+
async loadInWorkflow(wf) {
|
|
5616
|
+
return await this.loadVia(wf);
|
|
5617
|
+
}
|
|
5618
|
+
};
|
|
5619
|
+
/** 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 */
|
|
5426
5620
|
const v = {
|
|
5427
5621
|
text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
|
|
5428
5622
|
prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
|
|
@@ -5437,7 +5631,11 @@ const v = {
|
|
|
5437
5631
|
choice,
|
|
5438
5632
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
5439
5633
|
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
5440
|
-
|
|
5634
|
+
/** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
|
|
5635
|
+
model,
|
|
5636
|
+
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts),
|
|
5637
|
+
audio: (defaultValue, opts = {}) => new AudioVar(defaultValue, opts),
|
|
5638
|
+
video: (defaultValue, opts = {}) => new VideoVar(defaultValue, opts)
|
|
5441
5639
|
};
|
|
5442
5640
|
function varValues(vars) {
|
|
5443
5641
|
const out = {};
|
|
@@ -6889,10 +7087,18 @@ function bundledExamplesDir(moduleUrl = require("url").pathToFileURL(__filename)
|
|
|
6889
7087
|
* or the package's examples/ folder was pruned.
|
|
6890
7088
|
*/
|
|
6891
7089
|
function exampleImagePath(name) {
|
|
7090
|
+
return bundledExampleFile("images", name);
|
|
7091
|
+
}
|
|
7092
|
+
/** the same for a bundled `examples/media/` audio or video file, e.g.
|
|
7093
|
+
* `exampleMediaPath('sine_440hz_3s.flac')` — the default of audio and video example vars */
|
|
7094
|
+
function exampleMediaPath(name) {
|
|
7095
|
+
return bundledExampleFile("media", name);
|
|
7096
|
+
}
|
|
7097
|
+
function bundledExampleFile(folder, name) {
|
|
6892
7098
|
const examples = bundledExamplesDir();
|
|
6893
|
-
if (examples == null) throw new Error(`[comfy-ts] cannot resolve bundled example
|
|
6894
|
-
const abs = (0, pathe.join)(examples,
|
|
6895
|
-
if (!(0, node_fs.existsSync)(abs)) throw new Error(`[comfy-ts] bundled example
|
|
7099
|
+
if (examples == null) throw new Error(`[comfy-ts] cannot resolve bundled example file '${name}': the package's examples/ folder is not on disk`);
|
|
7100
|
+
const abs = (0, pathe.join)(examples, folder, name);
|
|
7101
|
+
if (!(0, node_fs.existsSync)(abs)) throw new Error(`[comfy-ts] bundled example file not found: ${abs}`);
|
|
6896
7102
|
return abs;
|
|
6897
7103
|
}
|
|
6898
7104
|
//#endregion
|
|
@@ -6955,6 +7161,7 @@ function isTuiActive() {
|
|
|
6955
7161
|
*/
|
|
6956
7162
|
setDefaultComfyStorage(createNodeStorage());
|
|
6957
7163
|
//#endregion
|
|
7164
|
+
exports.AudioVar = AudioVar;
|
|
6958
7165
|
exports.ChoiceVar = ChoiceVar;
|
|
6959
7166
|
exports.ComfyExecution = ComfyExecution;
|
|
6960
7167
|
exports.ComfyHost = ComfyHost;
|
|
@@ -6970,9 +7177,11 @@ exports.ComfyVar = ComfyVar;
|
|
|
6970
7177
|
exports.ComfyVarBase = ComfyVarBase;
|
|
6971
7178
|
exports.ComfyWorkflow = ComfyWorkflow;
|
|
6972
7179
|
exports.ComfyWorkflowBuilder = ComfyWorkflowBuilder;
|
|
7180
|
+
exports.DEFAULT_AUDIO_EXTENSIONS = DEFAULT_AUDIO_EXTENSIONS;
|
|
6973
7181
|
exports.DEFAULT_IMAGE_EXTENSIONS = DEFAULT_IMAGE_EXTENSIONS;
|
|
6974
7182
|
exports.DEFAULT_SIZE_PRESETS = DEFAULT_SIZE_PRESETS;
|
|
6975
7183
|
exports.DEFAULT_STARRED_SIZES = DEFAULT_STARRED_SIZES;
|
|
7184
|
+
exports.DEFAULT_VIDEO_EXTENSIONS = DEFAULT_VIDEO_EXTENSIONS;
|
|
6976
7185
|
exports.DefinedWorkflow = DefinedWorkflow;
|
|
6977
7186
|
exports.FloatVar = FloatVar;
|
|
6978
7187
|
exports.ImageVar = ImageVar;
|
|
@@ -6981,6 +7190,8 @@ exports.IntVar = IntVar;
|
|
|
6981
7190
|
exports.InvalidPromptError = InvalidPromptError;
|
|
6982
7191
|
exports.LorasVar = LorasVar;
|
|
6983
7192
|
exports.MediaImage = MediaImage;
|
|
7193
|
+
exports.MediaVar = MediaVar;
|
|
7194
|
+
exports.MediaVarEmptyError = MediaVarEmptyError;
|
|
6984
7195
|
exports.MultiChoiceVar = MultiChoiceVar;
|
|
6985
7196
|
exports.OptionalChoiceVar = OptionalChoiceVar;
|
|
6986
7197
|
exports.PromptVar = PromptVar;
|
|
@@ -6990,6 +7201,7 @@ exports.SeedVar = SeedVar;
|
|
|
6990
7201
|
exports.SizeVar = SizeVar;
|
|
6991
7202
|
exports.TextVar = TextVar;
|
|
6992
7203
|
exports.ToggleVar = ToggleVar;
|
|
7204
|
+
exports.VideoVar = VideoVar;
|
|
6993
7205
|
exports.WorkflowConvertError = WorkflowConvertError;
|
|
6994
7206
|
exports.WorkflowNormalizeError = WorkflowNormalizeError;
|
|
6995
7207
|
exports.__FAIL = __FAIL;
|
|
@@ -7008,6 +7220,7 @@ exports.convertFlowToLiteGraphJSON = convertFlowToLiteGraphJSON;
|
|
|
7008
7220
|
exports.convertLiteGraphToPrompt = convertLiteGraphToPrompt;
|
|
7009
7221
|
exports.createMemoryStorage = createMemoryStorage;
|
|
7010
7222
|
exports.exampleImagePath = exampleImagePath;
|
|
7223
|
+
exports.exampleMediaPath = exampleMediaPath;
|
|
7011
7224
|
exports.getComfyStorage = getComfyStorage;
|
|
7012
7225
|
exports.getLoraDisplayName = getLoraDisplayName;
|
|
7013
7226
|
exports.getLoraInfo = getLoraInfo;
|