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.
Files changed (75) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-CUeo843w.js → LogsSt-Ct7Le0S_.js} +2 -2
  3. package/dist/{LogsSt-CUeo843w.js.map → LogsSt-Ct7Le0S_.js.map} +1 -1
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +268 -55
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +176 -26
  8. package/dist/index.d.ts +176 -26
  9. package/dist/index.js +262 -56
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-DUqcn0h3.js → run-serve-C78hD7t9.js} +119 -40
  12. package/dist/run-serve-C78hD7t9.js.map +1 -0
  13. package/dist/{run-tui-D-LaSqgB.js → run-tui-nPETFRmk.js} +15 -9
  14. package/dist/run-tui-nPETFRmk.js.map +1 -0
  15. package/dist/{schemaDrift-E95iTF7E.js → schemaDrift-wb5XkrHV.js} +218 -27
  16. package/dist/schemaDrift-wb5XkrHV.js.map +1 -0
  17. package/dist/serve-web.js +64 -50
  18. package/dist/{state-BytbdZ8s.js → state-BMW57_M0.js} +45 -35
  19. package/dist/state-BMW57_M0.js.map +1 -0
  20. package/dist/web.d.ts +173 -26
  21. package/dist/web.js +251 -53
  22. package/dist/web.js.map +1 -1
  23. package/examples/README.md +1 -0
  24. package/examples/media/README.md +9 -0
  25. package/examples/media/sine_440hz_3s.flac +0 -0
  26. package/examples/media/testsrc_256x256_3s.mp4 +0 -0
  27. package/examples/media/voice_en_6s.flac +0 -0
  28. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +9 -1
  29. package/examples/rvion/10-anima-t2i.cflow.ts +8 -1
  30. package/examples/rvion/14-video-soundtrack.cflow.ts +47 -0
  31. package/examples/rvion/15-tts-voice-clone.cflow.ts +111 -0
  32. package/guide-for-agents.md +3 -1
  33. package/package.json +2 -2
  34. package/src/cli/serve/ServeApp.ts +115 -32
  35. package/src/cli/serve/applyVarPayload.ts +5 -3
  36. package/src/cli/serve/describeVar.ts +5 -3
  37. package/src/cli/serve/resultHistory.ts +22 -6
  38. package/src/cli/serve/run-serve.ts +4 -1
  39. package/src/cli/serve/web/api.ts +4 -0
  40. package/src/cli/serve/web/components/DraftTabs.tsx +2 -1
  41. package/src/cli/serve/web/components/Gallery.tsx +86 -5
  42. package/src/cli/serve/web/components/HistoryPicker.tsx +5 -3
  43. package/src/cli/serve/web/components/MenuButton.tsx +2 -4
  44. package/src/cli/serve/web/components/Omnibox.tsx +2 -1
  45. package/src/cli/serve/web/components/PromptEnhancer.tsx +4 -3
  46. package/src/cli/serve/web/components/ShortcutsModal.tsx +2 -1
  47. package/src/cli/serve/web/components/SideMenu.tsx +2 -1
  48. package/src/cli/serve/web/components/VarsForm.tsx +5 -3
  49. package/src/cli/serve/web/components/controls/LorasControl.tsx +4 -3
  50. package/src/cli/serve/web/components/controls/MediaControl.tsx +111 -0
  51. package/src/cli/serve/web/components/controls/PresetPicker.tsx +2 -1
  52. package/src/cli/serve/web/components/controls/PromptControl.tsx +2 -1
  53. package/src/cli/serve/web/components/controls/SizeControl.tsx +2 -1
  54. package/src/cli/serve/web/state/FormSt.ts +70 -2
  55. package/src/cli/serve/web/state/escape.ts +16 -0
  56. package/src/cli/serve/web/state/host.ts +2 -0
  57. package/src/cli/serve/web/state/mediaDrop.ts +76 -0
  58. package/src/cli/serve/web/styles.ts +16 -2
  59. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +4 -1
  60. package/src/cli/tui/imagePicker/ImagePickerSt.ts +15 -6
  61. package/src/cli/tui/state/TuiSt.ts +1 -1
  62. package/src/coreExports.ts +20 -1
  63. package/src/exampleAssets.ts +13 -3
  64. package/src/host/ComfyUploader.ts +34 -27
  65. package/src/index.ts +1 -1
  66. package/src/runner/ComfyExecution.ts +38 -20
  67. package/src/runner/ComfyWsApi.ts +3 -0
  68. package/src/runner/mediaKinds.ts +51 -0
  69. package/src/vars/ComfyVars.ts +178 -34
  70. package/src/vars/DefinedWorkflow.ts +35 -2
  71. package/dist/run-serve-DUqcn0h3.js.map +0 -1
  72. package/dist/run-tui-D-LaSqgB.js.map +0 -1
  73. package/dist/schemaDrift-E95iTF7E.js.map +0 -1
  74. package/dist/state-BytbdZ8s.js.map +0 -1
  75. package/src/cli/serve/web/components/controls/ImageControl.tsx +0 -72
package/dist/web.js CHANGED
@@ -101,7 +101,7 @@ function getComfyStorage() {
101
101
  }
102
102
  //#endregion
103
103
  //#region package.json
104
- var version = "2.14.0";
104
+ var version = "2.16.0";
105
105
  //#endregion
106
106
  //#region src/litegraph/LiteGraphLinkID.ts
107
107
  const asLiteGraphLinkID = (id) => id;
@@ -2008,6 +2008,8 @@ const types$1 = scope({
2008
2008
  "previews?": [{ filepath: "string" }, "[]"],
2009
2009
  "images?": "ComfyImageInfo[]",
2010
2010
  "audio?": "ComfyImageInfo[]",
2011
+ "video?": "ComfyImageInfo[]",
2012
+ "gifs?": "ComfyImageInfo[]",
2011
2013
  "text?": "unknown[]"
2012
2014
  },
2013
2015
  prompt_id: "PromptID"
@@ -2254,24 +2256,79 @@ var MediaImage = class MediaImage {
2254
2256
  }
2255
2257
  };
2256
2258
  //#endregion
2257
- //#region src/runner/ComfyExecution.ts
2258
- /** paths claimed by in-flight retrievals: two same-second runs on a
2259
- * counter-resetting cloud host compute the same name before either writes.
2260
- * A claim is released as soon as the write lands (the file itself then holds
2261
- * the name) or fails (the name is free again) — the set never accumulates */
2262
- const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
2263
- const AUDIO_MIMES = {
2259
+ //#region src/runner/mediaKinds.ts
2260
+ /** picker defaults per kind, lowercase without dots */
2261
+ const DEFAULT_MEDIA_EXTENSIONS = {
2262
+ image: [
2263
+ "png",
2264
+ "jpg",
2265
+ "jpeg",
2266
+ "webp",
2267
+ "gif"
2268
+ ],
2269
+ audio: [
2270
+ "wav",
2271
+ "flac",
2272
+ "mp3",
2273
+ "ogg",
2274
+ "opus",
2275
+ "m4a"
2276
+ ],
2277
+ video: [
2278
+ "mp4",
2279
+ "webm",
2280
+ "mov",
2281
+ "mkv",
2282
+ "m4v"
2283
+ ]
2284
+ };
2285
+ const MIMES = {
2286
+ png: "image/png",
2287
+ jpg: "image/jpeg",
2288
+ jpeg: "image/jpeg",
2289
+ webp: "image/webp",
2290
+ gif: "image/gif",
2264
2291
  flac: "audio/flac",
2265
2292
  mp3: "audio/mpeg",
2266
2293
  opus: "audio/ogg",
2267
2294
  ogg: "audio/ogg",
2268
2295
  wav: "audio/wav",
2269
- m4a: "audio/mp4"
2296
+ m4a: "audio/mp4",
2297
+ aac: "audio/aac",
2298
+ mp4: "video/mp4",
2299
+ m4v: "video/mp4",
2300
+ webm: "video/webm",
2301
+ mov: "video/quicktime",
2302
+ mkv: "video/x-matroska",
2303
+ avi: "video/x-msvideo"
2270
2304
  };
2271
- function audioMime(filename) {
2272
- const ext = filename.split(".").pop()?.toLowerCase() ?? "";
2273
- return AUDIO_MIMES[ext] ?? "application/octet-stream";
2305
+ /** video containers an output node can name. An animated webp or gif is an IMAGE: the
2306
+ * extension decides, never the `animated` flag */
2307
+ const VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([
2308
+ "mp4",
2309
+ "m4v",
2310
+ "webm",
2311
+ "mov",
2312
+ "mkv",
2313
+ "avi"
2314
+ ]);
2315
+ function extensionOf(filename) {
2316
+ const dot = filename.lastIndexOf(".");
2317
+ return dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
2318
+ }
2319
+ function isVideoFilename(filename) {
2320
+ return VIDEO_EXTENSIONS.has(extensionOf(filename));
2274
2321
  }
2322
+ function mediaMime(filename) {
2323
+ return MIMES[extensionOf(filename)] ?? "application/octet-stream";
2324
+ }
2325
+ //#endregion
2326
+ //#region src/runner/ComfyExecution.ts
2327
+ /** paths claimed by in-flight retrievals: two same-second runs on a
2328
+ * counter-resetting cloud host compute the same name before either writes.
2329
+ * A claim is released as soon as the write lands (the file itself then holds
2330
+ * the name) or fails (the name is free again) — the set never accumulates */
2331
+ const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
2275
2332
  var ComfyExecution = class {
2276
2333
  get host() {
2277
2334
  return this.workflow.host;
@@ -2338,15 +2395,28 @@ var ComfyExecution = class {
2338
2395
  text: entry
2339
2396
  });
2340
2397
  }
2341
- const images = msg.data.output?.images;
2342
- if (images) for (const img of images) this.pendingPromises.push(this.retrieveImage(img, promptNodeID).catch((e) => {
2398
+ const out = msg.data.output;
2399
+ const listed = [
2400
+ ...out?.images ?? [],
2401
+ ...out?.video ?? [],
2402
+ ...out?.gifs ?? []
2403
+ ].filter((f) => f.type !== "input");
2404
+ for (const video of listed.filter((f) => isVideoFilename(f.filename))) this.pendingPromises.push(this.retrieveFile("video", video, promptNodeID).catch((e) => {
2405
+ console.error(`🔴 failed to retrieve ${video.filename}:`, e);
2406
+ this.videoErrors.push({
2407
+ video,
2408
+ error: e
2409
+ });
2410
+ }));
2411
+ const images = listed.filter((f) => !isVideoFilename(f.filename));
2412
+ if (images.length > 0) for (const img of images) this.pendingPromises.push(this.retrieveImage(img, promptNodeID).catch((e) => {
2343
2413
  console.error(`🔴 failed to retrieve ${img.filename}:`, e);
2344
2414
  this.imageErrors.push({
2345
2415
  image: img,
2346
2416
  error: e
2347
2417
  });
2348
2418
  }));
2349
- for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveAudio(audio, promptNodeID).catch((e) => {
2419
+ for (const audio of msg.data.output?.audio ?? []) this.pendingPromises.push(this.retrieveFile("audio", audio, promptNodeID).catch((e) => {
2350
2420
  console.error(`🔴 failed to retrieve ${audio.filename}:`, e);
2351
2421
  this.audioErrors.push({
2352
2422
  audio,
@@ -2357,13 +2427,16 @@ var ComfyExecution = class {
2357
2427
  this.pendingPromises = [];
2358
2428
  this.audioErrors = [];
2359
2429
  this.audios = [];
2360
- this.retrieveAudio = async (info, promptNodeID) => {
2430
+ this.videoErrors = [];
2431
+ this.videos = [];
2432
+ this.retrieveFile = async (kind, info, promptNodeID) => {
2361
2433
  const response = await this.host.fetchFile("/view?" + new URLSearchParams(info).toString());
2362
2434
  const bytes = new Uint8Array(await response.arrayBuffer());
2363
- const mime = audioMime(info.filename);
2435
+ const mime = mediaMime(info.filename);
2436
+ const list = kind === "audio" ? this.audios : this.videos;
2364
2437
  const sf = this.save;
2365
2438
  if (sf == null) {
2366
- this.audios.push({
2439
+ list.push({
2367
2440
  nodeId: promptNodeID,
2368
2441
  filename: info.filename,
2369
2442
  mime,
@@ -2383,7 +2456,7 @@ var ComfyExecution = class {
2383
2456
  subfolder: info.subfolder,
2384
2457
  filename: info.filename
2385
2458
  });
2386
- this.audios.push({
2459
+ list.push({
2387
2460
  nodeId: promptNodeID,
2388
2461
  filename: info.filename,
2389
2462
  mime,
@@ -2563,6 +2636,7 @@ var ComfyExecution = class {
2563
2636
  const p = this.progress;
2564
2637
  const outputs = [`${this.images.length} image(s)`];
2565
2638
  if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`);
2639
+ if (this.videos.length > 0) outputs.push(`${this.videos.length} video(s)`);
2566
2640
  if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`);
2567
2641
  const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${outputs.join(" · ")}`;
2568
2642
  if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
@@ -3912,15 +3986,23 @@ const ComfyUploadImageResult_ark = type({
3912
3986
  var ComfyUploader = class {
3913
3987
  constructor(host) {
3914
3988
  this.host = host;
3989
+ this.uploaded = /* @__PURE__ */ new Set();
3915
3990
  this.uploadImage = async (img, p) => {
3916
- const uniqFileName = img.enumName;
3917
- const expectedFinalName = p.subfolder ? `${p.subfolder}/${uniqFileName}` : uniqFileName;
3918
- if (this.host.schema.hasImage(expectedFinalName)) {
3919
- console.log(`[🌁] UPLOAD: 🩶 "${img.absPath}" already exists on current ComfyUI instance`);
3991
+ return await this.uploadInput({
3992
+ blob: img.getAsBlob(),
3993
+ name: img.enumName,
3994
+ ...p,
3995
+ slot: "LoadImage.image"
3996
+ });
3997
+ };
3998
+ this.uploadInput = async (p) => {
3999
+ const expectedFinalName = p.subfolder ? `${p.subfolder}/${p.name}` : p.name;
4000
+ if (this.uploaded.has(expectedFinalName) || this.host.schema.stringValues(p.slot).includes(expectedFinalName)) {
4001
+ console.log(`[🌁] UPLOAD: 🩶 "${expectedFinalName}" already exists on current ComfyUI instance`);
3920
4002
  return expectedFinalName;
3921
4003
  }
3922
4004
  const form = new FormData();
3923
- form.set("image", img.getAsBlob(), uniqFileName);
4005
+ form.set("image", p.blob, p.name);
3924
4006
  if (p.type) form.set("type", p.type);
3925
4007
  if (p.override ?? true) form.set("override", "true");
3926
4008
  if (p.subfolder) form.set("subfolder", p.subfolder);
@@ -3930,11 +4012,11 @@ var ComfyUploader = class {
3930
4012
  });
3931
4013
  const result = softValidate(ComfyUploadImageResult_ark, await resp.json());
3932
4014
  console.log("[🌁] UPLOAD: ✅ got", result);
3933
- if (result.name == null) throw new Error("upload failed");
4015
+ if (result.name == null) throw new Error(`upload of '${p.name}' failed: the host answered no name`);
3934
4016
  const finalName = result.subfolder ? `${result.subfolder}/${result.name}` : result.name;
3935
4017
  if (finalName !== expectedFinalName) console.warn(`[🌁] UPLOAD: ⚠️ expected "${expectedFinalName}" but got "${finalName}"`);
3936
- else console.log(`[🌁] UPLOAD: ✅ finalName is "${finalName}"`);
3937
- this.host.schema.unsafely_addImageInSchemaWithoutReloading(finalName);
4018
+ if (p.slot === "LoadImage.image") this.host.schema.unsafely_addImageInSchemaWithoutReloading(finalName);
4019
+ this.uploaded.add(finalName);
3938
4020
  return finalName;
3939
4021
  };
3940
4022
  }
@@ -4931,12 +5013,46 @@ var ToggleVar = class extends ComfyVar {
4931
5013
  return this.value ? "ON" : "OFF";
4932
5014
  }
4933
5015
  };
5016
+ /** a fixed list, or the host's list for one slot once bindHost ran */
5017
+ var ChoiceList = class {
5018
+ constructor(source) {
5019
+ this.source = source;
5020
+ this.resolved = null;
5021
+ }
5022
+ get slot() {
5023
+ return isChoiceList(this.source) ? null : this.source;
5024
+ }
5025
+ get choices() {
5026
+ if (isChoiceList(this.source)) return this.source;
5027
+ 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)`);
5028
+ return this.resolved;
5029
+ }
5030
+ /** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
5031
+ * the SAME object_info enum the generated slot union comes from */
5032
+ bind(host) {
5033
+ const src = this.slot;
5034
+ if (src == null) return;
5035
+ const all = host.schema.stringValues(src.slot);
5036
+ const filter = src.filter == null ? null : statelessRegex(src.filter);
5037
+ this.resolved = filter == null ? all : all.filter((n) => filter.test(n));
5038
+ }
5039
+ };
4934
5040
  var ChoiceVar = class extends ComfyVar {
4935
5041
  constructor(choices, defaultValue, label) {
4936
5042
  super(defaultValue, label);
4937
- this.choices = choices;
4938
5043
  this.kind = "choice";
4939
5044
  this.select = "one";
5045
+ this.list = new ChoiceList(choices);
5046
+ }
5047
+ get choices() {
5048
+ return this.list.choices;
5049
+ }
5050
+ /** set for `v.model`: the loader input this choice lists */
5051
+ get hostSlot() {
5052
+ return this.list.slot;
5053
+ }
5054
+ bindHost(host) {
5055
+ this.list.bind(host);
4940
5056
  }
4941
5057
  next(delta = 1) {
4942
5058
  const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
@@ -4953,9 +5069,18 @@ var ChoiceVar = class extends ComfyVar {
4953
5069
  var OptionalChoiceVar = class extends ComfyVar {
4954
5070
  constructor(choices, defaultValue, label) {
4955
5071
  super(defaultValue, label);
4956
- this.choices = choices;
4957
5072
  this.kind = "choice";
4958
5073
  this.select = "zero-or-one";
5074
+ this.list = new ChoiceList(choices);
5075
+ }
5076
+ get choices() {
5077
+ return this.list.choices;
5078
+ }
5079
+ get hostSlot() {
5080
+ return this.list.slot;
5081
+ }
5082
+ bindHost(host) {
5083
+ this.list.bind(host);
4959
5084
  }
4960
5085
  /** pick `c`, or clear it when it is already the one picked */
4961
5086
  toggle(c) {
@@ -5033,6 +5158,14 @@ function choice(choices, defaultValue, opts) {
5033
5158
  if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
5034
5159
  return new ChoiceVar(choices, defaultValue, o.label);
5035
5160
  }
5161
+ function model(slot, opts) {
5162
+ const source = {
5163
+ slot,
5164
+ filter: opts.filter
5165
+ };
5166
+ if (opts.default == null) return new OptionalChoiceVar(source, null, opts.label);
5167
+ return new ChoiceVar(source, opts.default, opts.label);
5168
+ }
5036
5169
  /** normalize a loras record into what a standard LoraLoader chain consumes */
5037
5170
  function activeLoras(loras) {
5038
5171
  const out = [];
@@ -5319,42 +5452,55 @@ var SizeVar = class extends ComfyVar {
5319
5452
  return `${width}×${height}${hit ? ` (${hit.label})` : ""}`;
5320
5453
  }
5321
5454
  };
5322
- const DEFAULT_IMAGE_EXTENSIONS = [
5323
- "png",
5324
- "jpg",
5325
- "jpeg",
5326
- "webp",
5327
- "gif"
5328
- ];
5329
- /** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
5330
- var ImageVarEmptyError = class extends Error {
5331
- constructor(varName) {
5332
- super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`);
5455
+ const DEFAULT_IMAGE_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.image;
5456
+ const DEFAULT_AUDIO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.audio;
5457
+ const DEFAULT_VIDEO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.video;
5458
+ /** empty media var consumed at build time — typed so drivers surface it apart from real crashes */
5459
+ var MediaVarEmptyError = class extends Error {
5460
+ constructor(varName, media = "image") {
5461
+ super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`);
5333
5462
  this.varName = varName;
5334
- this.name = "ImageVarEmptyError";
5463
+ this.media = media;
5464
+ this.name = "MediaVarEmptyError";
5335
5465
  }
5336
5466
  };
5337
- /** trim + expand a leading `~/` — every ImageVar write funnels through this */
5467
+ /** the image-only name this error had first; the same class */
5468
+ const ImageVarEmptyError = MediaVarEmptyError;
5469
+ /** trim + expand a leading `~/` — every media var write funnels through this */
5338
5470
  function expandUserPath(raw) {
5339
5471
  const trimmed = raw.trim();
5340
5472
  return trimmed.startsWith("~/") ? join(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed;
5341
5473
  }
5474
+ /** the loader node each medium goes through, and its file input */
5475
+ const MEDIA_LOADERS = {
5476
+ image: {
5477
+ node: "LoadImage",
5478
+ input: "image"
5479
+ },
5480
+ audio: {
5481
+ node: "LoadAudio",
5482
+ input: "audio"
5483
+ },
5484
+ video: {
5485
+ node: "LoadVideo",
5486
+ input: "file"
5487
+ }
5488
+ };
5342
5489
  /**
5343
- * a local image path. The VALUE is a PLAIN PATH STRING — text-encodable,
5490
+ * a local media file path. The VALUE is a PLAIN PATH STRING — text-encodable,
5344
5491
  * drafts persist it verbatim (toJSON = the string), hand-editable in the
5345
- * draft json. Empty = unset: outValue()/absPath() throw ImageVarEmptyError,
5346
- * so a build never runs on a silent placeholder. The TUI opens the image
5347
- * picker overlay for kind 'image'.
5492
+ * draft json. Empty = unset: outValue()/absPath() throw MediaVarEmptyError,
5493
+ * so a build never runs on a silent placeholder. The TUI opens the file
5494
+ * picker overlay for every media kind.
5348
5495
  */
5349
- var ImageVar = class extends ComfyVar {
5496
+ var MediaVar = class extends ComfyVar {
5350
5497
  constructor(defaultValue, opts = {}) {
5351
5498
  super(expandUserPath(defaultValue), opts.label);
5352
5499
  this.opts = opts;
5353
- this.kind = "image";
5354
5500
  }
5355
5501
  /** what the picker lists (lowercase, no dots) */
5356
5502
  get extensions() {
5357
- return this.opts.extensions ?? DEFAULT_IMAGE_EXTENSIONS;
5503
+ return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind];
5358
5504
  }
5359
5505
  set(value) {
5360
5506
  return super.set(expandUserPath(value));
@@ -5367,7 +5513,7 @@ var ImageVar = class extends ComfyVar {
5367
5513
  return this.value !== "";
5368
5514
  }
5369
5515
  emptyError() {
5370
- return new ImageVarEmptyError(this.name ?? this.label ?? "image");
5516
+ return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind);
5371
5517
  }
5372
5518
  /** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
5373
5519
  absPath() {
@@ -5385,8 +5531,56 @@ var ImageVar = class extends ComfyVar {
5385
5531
  const home = getComfyStorage().homedir();
5386
5532
  return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
5387
5533
  }
5534
+ /** upload the file hash-named (reruns dedupe) and add this medium's loader node. A dry
5535
+ * build names the file by its hash and uploads nothing */
5536
+ async loadVia(wf) {
5537
+ const loader = MEDIA_LOADERS[this.kind];
5538
+ const factory = wf.builderBase[loader.node];
5539
+ if (factory == null) throw new Error(`host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? "?"}' cannot load`);
5540
+ const abs = this.absPath();
5541
+ const bytes = getComfyStorage().readBytes(abs);
5542
+ const ext = extensionOf(abs);
5543
+ const name = `${hashArrayBuffer(bytes)}${ext === "" ? "" : `.${ext}`}`;
5544
+ const onHost = wf.dry ? name : await wf.host.uploader.uploadInput({
5545
+ blob: new Blob([bytes], { type: mediaMime(abs) }),
5546
+ name,
5547
+ slot: `${loader.node}.${loader.input}`,
5548
+ type: "input"
5549
+ });
5550
+ return factory({ [loader.input]: onHost });
5551
+ }
5552
+ };
5553
+ /** a local image path, loaded through LoadImage */
5554
+ var ImageVar = class extends MediaVar {
5555
+ constructor(..._args2) {
5556
+ super(..._args2);
5557
+ this.kind = "image";
5558
+ }
5559
+ async loadInWorkflow(wf) {
5560
+ return await this.loadVia(wf);
5561
+ }
5562
+ };
5563
+ /** a local audio path, loaded through LoadAudio */
5564
+ var AudioVar = class extends MediaVar {
5565
+ constructor(..._args3) {
5566
+ super(..._args3);
5567
+ this.kind = "audio";
5568
+ }
5569
+ async loadInWorkflow(wf) {
5570
+ return await this.loadVia(wf);
5571
+ }
5572
+ };
5573
+ /** a local video path, loaded through LoadVideo */
5574
+ var VideoVar = class extends MediaVar {
5575
+ constructor(..._args4) {
5576
+ super(..._args4);
5577
+ this.kind = "video";
5578
+ }
5579
+ async loadInWorkflow(wf) {
5580
+ return await this.loadVia(wf);
5581
+ }
5388
5582
  };
5389
- /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
5583
+ /** 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 */
5390
5584
  const v = {
5391
5585
  text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
5392
5586
  prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
@@ -5401,7 +5595,11 @@ const v = {
5401
5595
  choice,
5402
5596
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
5403
5597
  size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
5404
- image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
5598
+ /** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
5599
+ model,
5600
+ image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts),
5601
+ audio: (defaultValue, opts = {}) => new AudioVar(defaultValue, opts),
5602
+ video: (defaultValue, opts = {}) => new VideoVar(defaultValue, opts)
5405
5603
  };
5406
5604
  function varValues(vars) {
5407
5605
  const out = {};
@@ -6825,6 +7023,6 @@ function loraTag(name, strength = 1, clipStrength) {
6825
7023
  */
6826
7024
  setDefaultComfyStorage(createMemoryStorage());
6827
7025
  //#endregion
6828
- export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, MultiChoiceVar, OptionalChoiceVar, PromptVar, ResilientWebSocketClient, SD15_SIZE_PRESETS, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
7026
+ 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, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
6829
7027
 
6830
7028
  //# sourceMappingURL=web.js.map