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
@@ -0,0 +1,51 @@
1
+ // the three media a var can take and an output can be. PURE + dependency-free: the web bundle
2
+ // imports it to decide which var a dropped output may land on
3
+
4
+ export type MediaKind = 'image' | 'audio' | 'video'
5
+
6
+ export const MEDIA_KINDS: readonly MediaKind[] = ['image', 'audio', 'video']
7
+
8
+ /** picker defaults per kind, lowercase without dots */
9
+ export const DEFAULT_MEDIA_EXTENSIONS: Record<MediaKind, readonly string[]> = {
10
+ image: ['png', 'jpg', 'jpeg', 'webp', 'gif'],
11
+ audio: ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a'],
12
+ video: ['mp4', 'webm', 'mov', 'mkv', 'm4v'],
13
+ }
14
+
15
+ const MIMES: Record<string, string> = {
16
+ png: 'image/png',
17
+ jpg: 'image/jpeg',
18
+ jpeg: 'image/jpeg',
19
+ webp: 'image/webp',
20
+ gif: 'image/gif',
21
+ flac: 'audio/flac',
22
+ mp3: 'audio/mpeg',
23
+ opus: 'audio/ogg',
24
+ ogg: 'audio/ogg',
25
+ wav: 'audio/wav',
26
+ m4a: 'audio/mp4',
27
+ aac: 'audio/aac',
28
+ mp4: 'video/mp4',
29
+ m4v: 'video/mp4',
30
+ webm: 'video/webm',
31
+ mov: 'video/quicktime',
32
+ mkv: 'video/x-matroska',
33
+ avi: 'video/x-msvideo',
34
+ }
35
+
36
+ /** video containers an output node can name. An animated webp or gif is an IMAGE: the
37
+ * extension decides, never the `animated` flag */
38
+ const VIDEO_EXTENSIONS = new Set(['mp4', 'm4v', 'webm', 'mov', 'mkv', 'avi'])
39
+
40
+ export function extensionOf(filename: string): string {
41
+ const dot = filename.lastIndexOf('.')
42
+ return dot < 0 ? '' : filename.slice(dot + 1).toLowerCase()
43
+ }
44
+
45
+ export function isVideoFilename(filename: string): boolean {
46
+ return VIDEO_EXTENSIONS.has(extensionOf(filename))
47
+ }
48
+
49
+ export function mediaMime(filename: string): string {
50
+ return MIMES[extensionOf(filename)] ?? 'application/octet-stream'
51
+ }
@@ -22,6 +22,11 @@ import { keptKeyword, loraIsOn, loraMuted, loraStrengths, withLora, type LoraStr
22
22
  import { logError } from 'src/utils/log.ts'
23
23
  import { COMMENT_LINE_RE, NEGATIVE_LINE_RE, parsePromptText } from 'src/vars/promptSyntax.ts'
24
24
  import { toPresetList, type VarPreset, type VarPresetSpec } from 'src/vars/presets.ts'
25
+ import { DEFAULT_MEDIA_EXTENSIONS, extensionOf, mediaMime, type MediaKind } from 'src/runner/mediaKinds.ts'
26
+ import { hashArrayBuffer } from 'src/utils/hashArrayBuffer.ts'
27
+ import { statelessRegex } from 'src/utils/matchesRegex.ts'
28
+ import type { ComfyWorkflow } from 'src/runner/ComfyWorkflow.ts'
29
+ import type { NodeOf } from 'src/types/comfy-sdk.ts'
25
30
 
26
31
  /**
27
32
  * the var's CLASS, and the only safe way to discriminate one: `instanceof` compares class
@@ -31,7 +36,7 @@ import { toPresetList, type VarPreset, type VarPresetSpec } from 'src/vars/prese
31
36
  * in a consumer app: "var 'prompt' has unsupported kind 'text'", for EVERY kind). A string tag
32
37
  * crosses bundles; a class identity does not.
33
38
  */
34
- export type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image'
39
+ export type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | MediaKind
35
40
 
36
41
  /**
37
42
  * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
@@ -406,15 +411,53 @@ export class ToggleVar extends ComfyVar<boolean> {
406
411
  /** how many options a choice holds: exactly one (the default), one or none, or any number */
407
412
  export type ChoiceSelect = 'one' | 'zero-or-one' | 'many'
408
413
 
414
+ /** where a host-bound choice reads its options: one loader input of the host's live schema,
415
+ * optionally narrowed (`v.model`) */
416
+ export type HostSlotSource = { slot: string; filter?: RegExp }
417
+
418
+ /** a fixed list, or the host's list for one slot once bindHost ran */
419
+ class ChoiceList<T extends string> {
420
+ private resolved: readonly T[] | null = null
421
+ constructor(readonly source: readonly T[] | HostSlotSource) {}
422
+ get slot(): HostSlotSource | null {
423
+ return isChoiceList(this.source) ? null : this.source
424
+ }
425
+ get choices(): readonly T[] {
426
+ if (isChoiceList(this.source)) return this.source
427
+ if (this.resolved == null)
428
+ throw new Error(
429
+ `v.model('${this.source.slot}') is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list to v.choice otherwise)`,
430
+ )
431
+ return this.resolved
432
+ }
433
+ /** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
434
+ * the SAME object_info enum the generated slot union comes from */
435
+ bind(host: LorasHost): void {
436
+ const src = this.slot
437
+ if (src == null) return
438
+ const all = host.schema.stringValues(src.slot)
439
+ const filter = src.filter == null ? null : statelessRegex(src.filter)
440
+ this.resolved = (filter == null ? all : all.filter((n) => filter.test(n))) as T[]
441
+ }
442
+ }
443
+
409
444
  export class ChoiceVar<T extends string> extends ComfyVar<T> {
410
445
  readonly kind = 'choice' as const
411
446
  readonly select = 'one' as const
412
- constructor(
413
- public readonly choices: readonly T[],
414
- defaultValue: T,
415
- label?: string,
416
- ) {
447
+ private list: ChoiceList<T>
448
+ constructor(choices: readonly T[] | HostSlotSource, defaultValue: T, label?: string) {
417
449
  super(defaultValue, label)
450
+ this.list = new ChoiceList(choices)
451
+ }
452
+ get choices(): readonly T[] {
453
+ return this.list.choices
454
+ }
455
+ /** set for `v.model`: the loader input this choice lists */
456
+ get hostSlot(): HostSlotSource | null {
457
+ return this.list.slot
458
+ }
459
+ bindHost(host: LorasHost): void {
460
+ this.list.bind(host)
418
461
  }
419
462
  next(delta: number = 1): this {
420
463
  const ix = this.choices.indexOf(this.value)
@@ -433,12 +476,19 @@ export class ChoiceVar<T extends string> extends ComfyVar<T> {
433
476
  export class OptionalChoiceVar<T extends string> extends ComfyVar<T | null> {
434
477
  readonly kind = 'choice' as const
435
478
  readonly select = 'zero-or-one' as const
436
- constructor(
437
- public readonly choices: readonly T[],
438
- defaultValue: T | null,
439
- label?: string,
440
- ) {
479
+ private list: ChoiceList<T>
480
+ constructor(choices: readonly T[] | HostSlotSource, defaultValue: T | null, label?: string) {
441
481
  super(defaultValue, label)
482
+ this.list = new ChoiceList(choices)
483
+ }
484
+ get choices(): readonly T[] {
485
+ return this.list.choices
486
+ }
487
+ get hostSlot(): HostSlotSource | null {
488
+ return this.list.slot
489
+ }
490
+ bindHost(host: LorasHost): void {
491
+ this.list.bind(host)
442
492
  }
443
493
  /** pick `c`, or clear it when it is already the one picked */
444
494
  toggle(c: T): this {
@@ -514,7 +564,7 @@ export type AnyChoiceVar<T extends string = string> = ChoiceVar<T> | OptionalCho
514
564
  type ChoiceOpts<S extends ChoiceSelect> = { label?: string; select: S }
515
565
 
516
566
  /** Array.isArray does not narrow a READONLY array out of a union, this does */
517
- function isChoiceList<T extends string>(v: T | null | readonly T[]): v is readonly T[] {
567
+ function isChoiceList<T extends string>(v: T | null | readonly T[] | HostSlotSource): v is readonly T[] {
518
568
  return Array.isArray(v)
519
569
  }
520
570
 
@@ -551,6 +601,25 @@ function choice<const T extends string>(
551
601
  return new ChoiceVar(choices, defaultValue, o.label)
552
602
  }
553
603
 
604
+ export type ModelVarOpts<T extends string> = {
605
+ /** narrows the host's list: `/krea/i` */
606
+ filter?: RegExp
607
+ label?: string
608
+ /** a file name, or null for "the workflow decides" (the build then reads null) */
609
+ default: T | null
610
+ }
611
+
612
+ /** a choice over the host's LIVE file list for one loader input (`'UNETLoader.unet_name'`),
613
+ * resolved at define time and rebound by serve's refresh-schema: a downloaded model is picked
614
+ * in the draft, never written into the workflow file */
615
+ function model<T extends string>(slot: string, opts: ModelVarOpts<T> & { default: T }): ChoiceVar<T>
616
+ function model<T extends string>(slot: string, opts: ModelVarOpts<T> & { default: null }): OptionalChoiceVar<T>
617
+ function model<T extends string>(slot: string, opts: ModelVarOpts<T>): ChoiceVar<T> | OptionalChoiceVar<T> {
618
+ const source: HostSlotSource = { slot, filter: opts.filter }
619
+ if (opts.default == null) return new OptionalChoiceVar<T>(source, null, opts.label)
620
+ return new ChoiceVar<T>(source, opts.default, opts.label)
621
+ }
622
+
554
623
  /** per-lora setting, every spelling documented in src/vars/loraEntry.ts */
555
624
  export type { LoraStrength } from 'src/vars/loraEntry.ts'
556
625
 
@@ -569,7 +638,10 @@ export function activeLoras<T extends string>(loras: LorasInput<T>): ActiveLora<
569
638
  }
570
639
 
571
640
  /** what LorasVar.bindHost needs — structural, so ComfyVars never imports ComfyHost */
572
- export type LorasHost = { data?: { id?: string }; schema: { getLoras(filter?: RegExp): string[] } }
641
+ export type LorasHost = {
642
+ data?: { id?: string }
643
+ schema: { getLoras(filter?: RegExp): string[]; stringValues(slot: string): string[] }
644
+ }
573
645
 
574
646
  /**
575
647
  * multi-select lora stack over a DYNAMIC options list — a RegExp resolves
@@ -825,52 +897,70 @@ export class SizeVar extends ComfyVar<SizeValue> {
825
897
  }
826
898
  }
827
899
 
828
- export type ImageVarOpts = {
900
+ export type MediaVarOpts = {
829
901
  /** where the TUI picker starts browsing AND what relative values resolve against (absPath) */
830
902
  folder?: string
831
903
  /** picker listing filter, lowercase without dots; never affects the value. NOT a security
832
- * boundary: `comfy-ts serve` keeps its own floor of image types it will read off the disk
904
+ * boundary: `comfy-ts serve` keeps its own floor of media types it will read off the disk
833
905
  * and upload, which this list may NARROW but never widen (emptying it changes the picker,
834
906
  * not what the api accepts) */
835
907
  extensions?: readonly string[]
836
908
  label?: string
837
909
  }
910
+ export type ImageVarOpts = MediaVarOpts
911
+ export type AudioVarOpts = MediaVarOpts
912
+ export type VideoVarOpts = MediaVarOpts
838
913
 
839
- export const DEFAULT_IMAGE_EXTENSIONS: readonly string[] = ['png', 'jpg', 'jpeg', 'webp', 'gif']
914
+ export const DEFAULT_IMAGE_EXTENSIONS: readonly string[] = DEFAULT_MEDIA_EXTENSIONS.image
915
+ export const DEFAULT_AUDIO_EXTENSIONS: readonly string[] = DEFAULT_MEDIA_EXTENSIONS.audio
916
+ export const DEFAULT_VIDEO_EXTENSIONS: readonly string[] = DEFAULT_MEDIA_EXTENSIONS.video
840
917
 
841
- /** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
842
- export class ImageVarEmptyError extends Error {
918
+ /** empty media var consumed at build time — typed so drivers surface it apart from real crashes */
919
+ export class MediaVarEmptyError extends Error {
843
920
  /** name, not instanceof: the cli bundle and dist/index.js each define this class */
844
- override readonly name = 'ImageVarEmptyError'
845
- constructor(public readonly varName: string) {
846
- super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`)
921
+ override readonly name: string = 'MediaVarEmptyError'
922
+ constructor(
923
+ public readonly varName: string,
924
+ public readonly media: MediaKind = 'image',
925
+ ) {
926
+ super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`)
847
927
  }
848
928
  }
929
+ /** the image-only name this error had first; the same class */
930
+ export const ImageVarEmptyError = MediaVarEmptyError
931
+ export type ImageVarEmptyError = MediaVarEmptyError
849
932
 
850
- /** trim + expand a leading `~/` — every ImageVar write funnels through this */
933
+ /** trim + expand a leading `~/` — every media var write funnels through this */
851
934
  function expandUserPath(raw: string): string {
852
935
  const trimmed = raw.trim()
853
936
  return trimmed.startsWith('~/') ? join(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed
854
937
  }
855
938
 
939
+ /** the loader node each medium goes through, and its file input */
940
+ const MEDIA_LOADERS: Record<MediaKind, { node: string; input: string }> = {
941
+ image: { node: 'LoadImage', input: 'image' },
942
+ audio: { node: 'LoadAudio', input: 'audio' },
943
+ video: { node: 'LoadVideo', input: 'file' },
944
+ }
945
+
856
946
  /**
857
- * a local image path. The VALUE is a PLAIN PATH STRING — text-encodable,
947
+ * a local media file path. The VALUE is a PLAIN PATH STRING — text-encodable,
858
948
  * drafts persist it verbatim (toJSON = the string), hand-editable in the
859
- * draft json. Empty = unset: outValue()/absPath() throw ImageVarEmptyError,
860
- * so a build never runs on a silent placeholder. The TUI opens the image
861
- * picker overlay for kind 'image'.
949
+ * draft json. Empty = unset: outValue()/absPath() throw MediaVarEmptyError,
950
+ * so a build never runs on a silent placeholder. The TUI opens the file
951
+ * picker overlay for every media kind.
862
952
  */
863
- export class ImageVar extends ComfyVar<string> {
864
- readonly kind = 'image' as const
953
+ export abstract class MediaVar extends ComfyVar<string> {
954
+ abstract override readonly kind: MediaKind
865
955
  constructor(
866
956
  defaultValue: string,
867
- public opts: ImageVarOpts = {},
957
+ public opts: MediaVarOpts = {},
868
958
  ) {
869
959
  super(expandUserPath(defaultValue), opts.label)
870
960
  }
871
961
  /** what the picker lists (lowercase, no dots) */
872
962
  get extensions(): readonly string[] {
873
- return this.opts.extensions ?? DEFAULT_IMAGE_EXTENSIONS
963
+ return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind]
874
964
  }
875
965
  override set(value: string): this {
876
966
  return super.set(expandUserPath(value))
@@ -882,8 +972,8 @@ export class ImageVar extends ComfyVar<string> {
882
972
  isSet(): boolean {
883
973
  return this.value !== ''
884
974
  }
885
- private emptyError(): ImageVarEmptyError {
886
- return new ImageVarEmptyError(this.name ?? this.label ?? 'image')
975
+ private emptyError(): MediaVarEmptyError {
976
+ return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind)
887
977
  }
888
978
  /** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
889
979
  absPath(): string {
@@ -901,9 +991,59 @@ export class ImageVar extends ComfyVar<string> {
901
991
  const home = getComfyStorage().homedir()
902
992
  return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value
903
993
  }
994
+ /** upload the file hash-named (reruns dedupe) and add this medium's loader node. A dry
995
+ * build names the file by its hash and uploads nothing */
996
+ protected async loadVia(wf: ComfyWorkflow<string>): Promise<unknown> {
997
+ const loader = MEDIA_LOADERS[this.kind]
998
+ const factory = wf.builderBase[loader.node]
999
+ if (factory == null)
1000
+ throw new Error(
1001
+ `host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? '?'}' cannot load`,
1002
+ )
1003
+ const abs = this.absPath()
1004
+ const bytes = getComfyStorage().readBytes(abs)
1005
+ const ext = extensionOf(abs)
1006
+ const name = `${hashArrayBuffer(bytes)}${ext === '' ? '' : `.${ext}`}`
1007
+ const onHost = wf.dry
1008
+ ? name
1009
+ : await wf.host.uploader.uploadInput({
1010
+ blob: new Blob([bytes as Uint8Array<ArrayBuffer>], { type: mediaMime(abs) }),
1011
+ name,
1012
+ slot: `${loader.node}.${loader.input}`,
1013
+ type: 'input',
1014
+ })
1015
+ return factory({ [loader.input]: onHost })
1016
+ }
1017
+ }
1018
+
1019
+ /** a local image path, loaded through LoadImage */
1020
+ export class ImageVar extends MediaVar {
1021
+ readonly kind = 'image' as const
1022
+ async loadInWorkflow<WID extends string>(wf: ComfyWorkflow<WID>): Promise<NodeOf<WID, 'LoadImage'>> {
1023
+ // sanctioned cast (family 1): the node is the host's own LoadImage, built from object_info
1024
+ return (await this.loadVia(wf)) as NodeOf<WID, 'LoadImage'>
1025
+ }
1026
+ }
1027
+
1028
+ /** a local audio path, loaded through LoadAudio */
1029
+ export class AudioVar extends MediaVar {
1030
+ readonly kind = 'audio' as const
1031
+ async loadInWorkflow<WID extends string>(wf: ComfyWorkflow<WID>): Promise<NodeOf<WID, 'LoadAudio'>> {
1032
+ // sanctioned cast (family 1): same as ImageVar
1033
+ return (await this.loadVia(wf)) as NodeOf<WID, 'LoadAudio'>
1034
+ }
1035
+ }
1036
+
1037
+ /** a local video path, loaded through LoadVideo */
1038
+ export class VideoVar extends MediaVar {
1039
+ readonly kind = 'video' as const
1040
+ async loadInWorkflow<WID extends string>(wf: ComfyWorkflow<WID>): Promise<NodeOf<WID, 'LoadVideo'>> {
1041
+ // sanctioned cast (family 1): same as ImageVar
1042
+ return (await this.loadVia(wf)) as NodeOf<WID, 'LoadVideo'>
1043
+ }
904
1044
  }
905
1045
 
906
- /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
1046
+ /** 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 */
907
1047
  export const v = {
908
1048
  // the old `v.text(x, 'label')` form still works: a bare string IS the label
909
1049
  text: (defaultValue: string, opts: TextVarOpts | string = {}): TextVar =>
@@ -936,7 +1076,11 @@ export const v = {
936
1076
  opts: { presets?: SizePreset[]; starred?: readonly string[]; label?: string; image?: ImageVar } = {},
937
1077
  ): SizeVar =>
938
1078
  new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
939
- image: (defaultValue: string, opts: ImageVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
1079
+ /** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
1080
+ model,
1081
+ image: (defaultValue: string, opts: MediaVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
1082
+ audio: (defaultValue: string, opts: MediaVarOpts = {}): AudioVar => new AudioVar(defaultValue, opts),
1083
+ video: (defaultValue: string, opts: MediaVarOpts = {}): VideoVar => new VideoVar(defaultValue, opts),
940
1084
  }
941
1085
 
942
1086
  /**
@@ -3,7 +3,17 @@ import type { ComfyExecution } from 'src/runner/ComfyExecution.ts'
3
3
  import type { ComfyWorkflow, RunSettings } from 'src/runner/ComfyWorkflow.ts'
4
4
  import type { SdkForHost } from 'src/types/comfy-sdk.ts'
5
5
  import type { LorasInput } from 'src/vars/lanes.ts'
6
- import { type AnyVar, type LorasVar, v, type VarsSpec, type VarValues, varValues } from 'src/vars/ComfyVars.ts'
6
+ import {
7
+ type AnyVar,
8
+ type ChoiceVar,
9
+ type LorasVar,
10
+ type ModelVarOpts,
11
+ type OptionalChoiceVar,
12
+ v,
13
+ type VarsSpec,
14
+ type VarValues,
15
+ varValues,
16
+ } from 'src/vars/ComfyVars.ts'
7
17
 
8
18
  /** the host's generated lora-name union (plain string when no sdk is generated) */
9
19
  export type LoraNameOf<ID extends string> = 'E_LoraName' extends keyof SdkForHost<ID>['Union']
@@ -14,11 +24,34 @@ export type LoraNameOf<ID extends string> = 'E_LoraName' extends keyof SdkForHos
14
24
  * the `v` handed to a vars LAMBDA: the global factory, host-typed —
15
25
  * `v.loras(regex)` yields the host's lora-name union (resolved via bindHost)
16
26
  */
17
- export type BoundVars<ID extends string> = Omit<typeof v, 'loras'> & {
27
+ export type BoundVars<ID extends string> = Omit<typeof v, 'loras' | 'model'> & {
18
28
  loras(options: RegExp, initial?: LorasInput<LoraNameOf<ID>>, label?: string): LorasVar<LoraNameOf<ID>>
19
29
  loras<T extends string>(options: readonly T[], initial?: LorasInput<T>, label?: string): LorasVar<T>
30
+ /** the host's file list for one loader input: the slot autocompletes, the value is its union */
31
+ model: ModelFactory<SdkForHost<ID>['Slots']>
20
32
  }
21
33
 
34
+ /** `v.model` typed by a host's slot table S (`Slots`): its own interface, so the host id's
35
+ * variance stays measurable (inlined into BoundVars, ComfyHost<ID> stopped being a ComfyHost<string>) */
36
+ export interface ModelFactory<S> {
37
+ <K extends keyof S & string>(
38
+ slot: K,
39
+ opts: ModelVarOpts<S[K] & string> & { default: S[K] & string },
40
+ ): ChoiceVar<S[K] & string>
41
+ <K extends keyof S & string>(
42
+ slot: K,
43
+ opts: ModelVarOpts<S[K] & string> & { default: null },
44
+ ): OptionalChoiceVar<S[K] & string>
45
+ }
46
+
47
+ /** every `Node.input` slot of the host's generated sdk (any string without one) */
48
+ export type SlotNameOf<ID extends string> = keyof SdkForHost<ID>['Slots'] & string
49
+
50
+ /** the value union of one slot, strings only (a loader file list) */
51
+ export type SlotValueOf<ID extends string, K extends string> = K extends keyof SdkForHost<ID>['Slots']
52
+ ? SdkForHost<ID>['Slots'][K] & string
53
+ : string
54
+
22
55
  export type DefineWorkflowSpec<ID extends string, V extends VarsSpec> = {
23
56
  /** short id; also names the workflow instances */
24
57
  id?: string