comfy-ts 2.13.0 → 2.15.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-C3UIWR-o.js} +2 -2
  3. package/dist/{LogsSt-CUeo843w.js.map → LogsSt-C3UIWR-o.js.map} +1 -1
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +213 -53
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +123 -21
  8. package/dist/index.d.ts +123 -21
  9. package/dist/index.js +207 -54
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-DlRBv_Nk.js → run-serve-B5PfIuhK.js} +310 -88
  12. package/dist/run-serve-B5PfIuhK.js.map +1 -0
  13. package/dist/{run-tui-B5uxm2_l.js → run-tui-D-N4_yyX.js} +15 -9
  14. package/dist/run-tui-D-N4_yyX.js.map +1 -0
  15. package/dist/{schemaDrift-E95iTF7E.js → schemaDrift-BkN8rLiZ.js} +163 -25
  16. package/dist/schemaDrift-BkN8rLiZ.js.map +1 -0
  17. package/dist/serve-web.js +160 -71
  18. package/dist/{state-CUp2J1Zy.js → state-CZsYJqB6.js} +45 -35
  19. package/dist/state-CZsYJqB6.js.map +1 -0
  20. package/dist/web.d.ts +120 -21
  21. package/dist/web.js +196 -51
  22. package/dist/web.js.map +1 -1
  23. package/examples/media/README.md +8 -0
  24. package/examples/media/sine_440hz_3s.flac +0 -0
  25. package/examples/media/testsrc_256x256_3s.mp4 +0 -0
  26. package/examples/rvion/14-video-soundtrack.cflow.ts +47 -0
  27. package/guide-for-agents.md +2 -1
  28. package/package.json +2 -2
  29. package/src/cli/serve/ServeApp.ts +189 -110
  30. package/src/cli/serve/applyVarPayload.ts +5 -3
  31. package/src/cli/serve/describeVar.ts +5 -3
  32. package/src/cli/serve/resultHistory.ts +141 -0
  33. package/src/cli/serve/run-serve.ts +4 -1
  34. package/src/cli/serve/runError.ts +23 -0
  35. package/src/cli/serve/serveSettings.ts +17 -1
  36. package/src/cli/serve/web/api.ts +33 -2
  37. package/src/cli/serve/web/components/App.tsx +6 -4
  38. package/src/cli/serve/web/components/Gallery.tsx +116 -11
  39. package/src/cli/serve/web/components/Icon.tsx +4 -0
  40. package/src/cli/serve/web/components/MemoryBudget.tsx +98 -0
  41. package/src/cli/serve/web/components/RunError.tsx +19 -0
  42. package/src/cli/serve/web/components/ShortcutsModal.tsx +54 -0
  43. package/src/cli/serve/web/components/SideMenu.tsx +14 -0
  44. package/src/cli/serve/web/components/VarsForm.tsx +75 -55
  45. package/src/cli/serve/web/components/controls/BasicControls.tsx +8 -1
  46. package/src/cli/serve/web/components/controls/LorasControl.tsx +6 -3
  47. package/src/cli/serve/web/components/controls/MediaControl.tsx +111 -0
  48. package/src/cli/serve/web/promptEditor/promptExtensions.ts +3 -1
  49. package/src/cli/serve/web/state/FormSt.ts +70 -2
  50. package/src/cli/serve/web/state/RunSt.ts +61 -3
  51. package/src/cli/serve/web/state/WebSt.ts +26 -2
  52. package/src/cli/serve/web/state/formRows.ts +9 -0
  53. package/src/cli/serve/web/state/host.ts +2 -0
  54. package/src/cli/serve/web/state/keptResults.ts +26 -0
  55. package/src/cli/serve/web/state/lightbox.ts +17 -0
  56. package/src/cli/serve/web/state/mediaDrop.ts +76 -0
  57. package/src/cli/serve/web/state/shortcutCatalog.ts +100 -0
  58. package/src/cli/serve/web/state/shortcuts.ts +10 -0
  59. package/src/cli/serve/web/styles.ts +112 -24
  60. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +4 -1
  61. package/src/cli/tui/imagePicker/ImagePickerSt.ts +15 -6
  62. package/src/cli/tui/state/TuiSt.ts +1 -1
  63. package/src/coreExports.ts +10 -0
  64. package/src/exampleAssets.ts +13 -3
  65. package/src/host/ComfyUploader.ts +34 -27
  66. package/src/index.ts +1 -1
  67. package/src/runner/ComfyExecution.ts +38 -20
  68. package/src/runner/ComfyWsApi.ts +3 -0
  69. package/src/runner/mediaKinds.ts +51 -0
  70. package/src/vars/ComfyVars.ts +96 -22
  71. package/dist/run-serve-DlRBv_Nk.js.map +0 -1
  72. package/dist/run-tui-B5uxm2_l.js.map +0 -1
  73. package/dist/schemaDrift-E95iTF7E.js.map +0 -1
  74. package/dist/state-CUp2J1Zy.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,10 @@ 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 type { ComfyWorkflow } from 'src/runner/ComfyWorkflow.ts'
28
+ import type { NodeOf } from 'src/types/comfy-sdk.ts'
25
29
 
26
30
  /**
27
31
  * the var's CLASS, and the only safe way to discriminate one: `instanceof` compares class
@@ -31,7 +35,7 @@ import { toPresetList, type VarPreset, type VarPresetSpec } from 'src/vars/prese
31
35
  * in a consumer app: "var 'prompt' has unsupported kind 'text'", for EVERY kind). A string tag
32
36
  * crosses bundles; a class identity does not.
33
37
  */
34
- export type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image'
38
+ export type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | MediaKind
35
39
 
36
40
  /**
37
41
  * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
@@ -825,52 +829,70 @@ export class SizeVar extends ComfyVar<SizeValue> {
825
829
  }
826
830
  }
827
831
 
828
- export type ImageVarOpts = {
832
+ export type MediaVarOpts = {
829
833
  /** where the TUI picker starts browsing AND what relative values resolve against (absPath) */
830
834
  folder?: string
831
835
  /** 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
836
+ * boundary: `comfy-ts serve` keeps its own floor of media types it will read off the disk
833
837
  * and upload, which this list may NARROW but never widen (emptying it changes the picker,
834
838
  * not what the api accepts) */
835
839
  extensions?: readonly string[]
836
840
  label?: string
837
841
  }
842
+ export type ImageVarOpts = MediaVarOpts
843
+ export type AudioVarOpts = MediaVarOpts
844
+ export type VideoVarOpts = MediaVarOpts
838
845
 
839
- export const DEFAULT_IMAGE_EXTENSIONS: readonly string[] = ['png', 'jpg', 'jpeg', 'webp', 'gif']
846
+ export const DEFAULT_IMAGE_EXTENSIONS: readonly string[] = DEFAULT_MEDIA_EXTENSIONS.image
847
+ export const DEFAULT_AUDIO_EXTENSIONS: readonly string[] = DEFAULT_MEDIA_EXTENSIONS.audio
848
+ export const DEFAULT_VIDEO_EXTENSIONS: readonly string[] = DEFAULT_MEDIA_EXTENSIONS.video
840
849
 
841
- /** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
842
- export class ImageVarEmptyError extends Error {
850
+ /** empty media var consumed at build time — typed so drivers surface it apart from real crashes */
851
+ export class MediaVarEmptyError extends Error {
843
852
  /** 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'))`)
853
+ override readonly name: string = 'MediaVarEmptyError'
854
+ constructor(
855
+ public readonly varName: string,
856
+ public readonly media: MediaKind = 'image',
857
+ ) {
858
+ super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`)
847
859
  }
848
860
  }
861
+ /** the image-only name this error had first; the same class */
862
+ export const ImageVarEmptyError = MediaVarEmptyError
863
+ export type ImageVarEmptyError = MediaVarEmptyError
849
864
 
850
- /** trim + expand a leading `~/` — every ImageVar write funnels through this */
865
+ /** trim + expand a leading `~/` — every media var write funnels through this */
851
866
  function expandUserPath(raw: string): string {
852
867
  const trimmed = raw.trim()
853
868
  return trimmed.startsWith('~/') ? join(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed
854
869
  }
855
870
 
871
+ /** the loader node each medium goes through, and its file input */
872
+ const MEDIA_LOADERS: Record<MediaKind, { node: string; input: string }> = {
873
+ image: { node: 'LoadImage', input: 'image' },
874
+ audio: { node: 'LoadAudio', input: 'audio' },
875
+ video: { node: 'LoadVideo', input: 'file' },
876
+ }
877
+
856
878
  /**
857
- * a local image path. The VALUE is a PLAIN PATH STRING — text-encodable,
879
+ * a local media file path. The VALUE is a PLAIN PATH STRING — text-encodable,
858
880
  * 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'.
881
+ * draft json. Empty = unset: outValue()/absPath() throw MediaVarEmptyError,
882
+ * so a build never runs on a silent placeholder. The TUI opens the file
883
+ * picker overlay for every media kind.
862
884
  */
863
- export class ImageVar extends ComfyVar<string> {
864
- readonly kind = 'image' as const
885
+ export abstract class MediaVar extends ComfyVar<string> {
886
+ abstract override readonly kind: MediaKind
865
887
  constructor(
866
888
  defaultValue: string,
867
- public opts: ImageVarOpts = {},
889
+ public opts: MediaVarOpts = {},
868
890
  ) {
869
891
  super(expandUserPath(defaultValue), opts.label)
870
892
  }
871
893
  /** what the picker lists (lowercase, no dots) */
872
894
  get extensions(): readonly string[] {
873
- return this.opts.extensions ?? DEFAULT_IMAGE_EXTENSIONS
895
+ return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind]
874
896
  }
875
897
  override set(value: string): this {
876
898
  return super.set(expandUserPath(value))
@@ -882,8 +904,8 @@ export class ImageVar extends ComfyVar<string> {
882
904
  isSet(): boolean {
883
905
  return this.value !== ''
884
906
  }
885
- private emptyError(): ImageVarEmptyError {
886
- return new ImageVarEmptyError(this.name ?? this.label ?? 'image')
907
+ private emptyError(): MediaVarEmptyError {
908
+ return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind)
887
909
  }
888
910
  /** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
889
911
  absPath(): string {
@@ -901,9 +923,59 @@ export class ImageVar extends ComfyVar<string> {
901
923
  const home = getComfyStorage().homedir()
902
924
  return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value
903
925
  }
926
+ /** upload the file hash-named (reruns dedupe) and add this medium's loader node. A dry
927
+ * build names the file by its hash and uploads nothing */
928
+ protected async loadVia(wf: ComfyWorkflow<string>): Promise<unknown> {
929
+ const loader = MEDIA_LOADERS[this.kind]
930
+ const factory = wf.builderBase[loader.node]
931
+ if (factory == null)
932
+ throw new Error(
933
+ `host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? '?'}' cannot load`,
934
+ )
935
+ const abs = this.absPath()
936
+ const bytes = getComfyStorage().readBytes(abs)
937
+ const ext = extensionOf(abs)
938
+ const name = `${hashArrayBuffer(bytes)}${ext === '' ? '' : `.${ext}`}`
939
+ const onHost = wf.dry
940
+ ? name
941
+ : await wf.host.uploader.uploadInput({
942
+ blob: new Blob([bytes as Uint8Array<ArrayBuffer>], { type: mediaMime(abs) }),
943
+ name,
944
+ slot: `${loader.node}.${loader.input}`,
945
+ type: 'input',
946
+ })
947
+ return factory({ [loader.input]: onHost })
948
+ }
949
+ }
950
+
951
+ /** a local image path, loaded through LoadImage */
952
+ export class ImageVar extends MediaVar {
953
+ readonly kind = 'image' as const
954
+ async loadInWorkflow<WID extends string>(wf: ComfyWorkflow<WID>): Promise<NodeOf<WID, 'LoadImage'>> {
955
+ // sanctioned cast (family 1): the node is the host's own LoadImage, built from object_info
956
+ return (await this.loadVia(wf)) as NodeOf<WID, 'LoadImage'>
957
+ }
958
+ }
959
+
960
+ /** a local audio path, loaded through LoadAudio */
961
+ export class AudioVar extends MediaVar {
962
+ readonly kind = 'audio' as const
963
+ async loadInWorkflow<WID extends string>(wf: ComfyWorkflow<WID>): Promise<NodeOf<WID, 'LoadAudio'>> {
964
+ // sanctioned cast (family 1): same as ImageVar
965
+ return (await this.loadVia(wf)) as NodeOf<WID, 'LoadAudio'>
966
+ }
967
+ }
968
+
969
+ /** a local video path, loaded through LoadVideo */
970
+ export class VideoVar extends MediaVar {
971
+ readonly kind = 'video' as const
972
+ async loadInWorkflow<WID extends string>(wf: ComfyWorkflow<WID>): Promise<NodeOf<WID, 'LoadVideo'>> {
973
+ // sanctioned cast (family 1): same as ImageVar
974
+ return (await this.loadVia(wf)) as NodeOf<WID, 'LoadVideo'>
975
+ }
904
976
  }
905
977
 
906
- /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
978
+ /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image / v.audio / v.video */
907
979
  export const v = {
908
980
  // the old `v.text(x, 'label')` form still works: a bare string IS the label
909
981
  text: (defaultValue: string, opts: TextVarOpts | string = {}): TextVar =>
@@ -936,7 +1008,9 @@ export const v = {
936
1008
  opts: { presets?: SizePreset[]; starred?: readonly string[]; label?: string; image?: ImageVar } = {},
937
1009
  ): SizeVar =>
938
1010
  new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
939
- image: (defaultValue: string, opts: ImageVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
1011
+ image: (defaultValue: string, opts: MediaVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
1012
+ audio: (defaultValue: string, opts: MediaVarOpts = {}): AudioVar => new AudioVar(defaultValue, opts),
1013
+ video: (defaultValue: string, opts: MediaVarOpts = {}): VideoVar => new VideoVar(defaultValue, opts),
940
1014
  }
941
1015
 
942
1016
  /**