comfy-ts 2.14.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 (57) 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-DUqcn0h3.js → run-serve-B5PfIuhK.js} +108 -38
  12. package/dist/run-serve-B5PfIuhK.js.map +1 -0
  13. package/dist/{run-tui-D-LaSqgB.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 +62 -48
  18. package/dist/{state-BytbdZ8s.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 +101 -30
  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 +22 -6
  33. package/src/cli/serve/run-serve.ts +4 -1
  34. package/src/cli/serve/web/api.ts +4 -0
  35. package/src/cli/serve/web/components/Gallery.tsx +84 -4
  36. package/src/cli/serve/web/components/VarsForm.tsx +5 -3
  37. package/src/cli/serve/web/components/controls/MediaControl.tsx +111 -0
  38. package/src/cli/serve/web/state/FormSt.ts +70 -2
  39. package/src/cli/serve/web/state/host.ts +2 -0
  40. package/src/cli/serve/web/state/mediaDrop.ts +76 -0
  41. package/src/cli/serve/web/styles.ts +16 -2
  42. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +4 -1
  43. package/src/cli/tui/imagePicker/ImagePickerSt.ts +15 -6
  44. package/src/cli/tui/state/TuiSt.ts +1 -1
  45. package/src/coreExports.ts +10 -0
  46. package/src/exampleAssets.ts +13 -3
  47. package/src/host/ComfyUploader.ts +34 -27
  48. package/src/index.ts +1 -1
  49. package/src/runner/ComfyExecution.ts +38 -20
  50. package/src/runner/ComfyWsApi.ts +3 -0
  51. package/src/runner/mediaKinds.ts +51 -0
  52. package/src/vars/ComfyVars.ts +96 -22
  53. package/dist/run-serve-DUqcn0h3.js.map +0 -1
  54. package/dist/run-tui-D-LaSqgB.js.map +0 -1
  55. package/dist/schemaDrift-E95iTF7E.js.map +0 -1
  56. package/dist/state-BytbdZ8s.js.map +0 -1
  57. package/src/cli/serve/web/components/controls/ImageControl.tsx +0 -72
@@ -4,7 +4,8 @@
4
4
  // the button hides where the clipboard api is absent
5
5
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
6
6
  import { observer, useLocalObservable } from 'mobx-react-lite'
7
- import { useEffect, useRef, type ReactNode } from 'react'
7
+ import { useEffect, useRef, type DragEvent, type ReactNode } from 'react'
8
+ import { encodeDraggedOutput, OUTPUT_DRAG_MIME, type DraggedOutput } from 'src/cli/serve/web/state/mediaDrop.ts'
8
9
  import { isEphemeral } from 'src/cli/serve/web/state/keptResults.ts'
9
10
  import { runPreviewSrc } from 'src/cli/serve/web/api.ts'
10
11
  import { asSizeForm } from 'src/cli/serve/web/state/payload.ts'
@@ -38,6 +39,38 @@ const BlurHint = observer(function BlurHint(p: { st: WebSt }) {
38
39
  )
39
40
  })
40
41
 
42
+ /** one output's drag + its `→ var` buttons: every media var of the SAME kind in the open form */
43
+ function outputDrag(o: DraggedOutput): { draggable: true; onDragStart: (e: DragEvent) => void } {
44
+ return {
45
+ draggable: true,
46
+ onDragStart: (e) => {
47
+ e.dataTransfer.effectAllowed = 'copy'
48
+ e.dataTransfer.setData(OUTPUT_DRAG_MIME, encodeDraggedOutput(o))
49
+ },
50
+ }
51
+ }
52
+
53
+ const UseAs = observer(function UseAs(p: { st: WebSt; out: DraggedOutput }) {
54
+ const targets = (p.st.form?.vars ?? []).filter((v) => v.mediaKind === p.out.kind)
55
+ if (targets.length === 0 || (p.out.url == null && p.out.absPath == null)) return null
56
+ return (
57
+ <div className="use-as">
58
+ {targets.map((v) => (
59
+ <button
60
+ key={v.name}
61
+ type="button"
62
+ className="host-action"
63
+ disabled={v.mediaBusy}
64
+ data-tip={`use this ${p.out.kind} as the '${v.name}' input of the open workflow`}
65
+ onClick={() => void v.takeOutput(p.out)}
66
+ >
67
+ → {v.name}
68
+ </button>
69
+ ))}
70
+ </div>
71
+ )
72
+ })
73
+
41
74
  const canCopy = typeof navigator !== 'undefined' && navigator.clipboard != null
42
75
 
43
76
  type GalleryLocal = {
@@ -489,7 +522,16 @@ export const Gallery = observer(function Gallery(p: { st: WebSt; compact?: boole
489
522
  <div className="imgs">
490
523
  {r.images.map((img, ix) =>
491
524
  img.url != null ? (
492
- <div key={img.filename} className="img-cell">
525
+ <div
526
+ key={img.filename}
527
+ className="img-cell"
528
+ {...outputDrag({
529
+ kind: 'image',
530
+ url: img.url,
531
+ absPath: img.absPath,
532
+ filename: img.filename,
533
+ })}
534
+ >
493
535
  <button
494
536
  type="button"
495
537
  className="img-button"
@@ -508,6 +550,10 @@ export const Gallery = observer(function Gallery(p: { st: WebSt; compact?: boole
508
550
  <BlurHint st={p.st} />
509
551
  <EphemeralPill out={img} />
510
552
  </button>
553
+ <UseAs
554
+ st={p.st}
555
+ out={{ kind: 'image', url: img.url, absPath: img.absPath, filename: img.filename }}
556
+ />
511
557
  {/* the EMBEDDING page's buttons (host protocol): what it does with the
512
558
  image is its business — send it somewhere, keep it as something */}
513
559
  {p.st.hostActions.length > 0 ? (
@@ -550,12 +596,20 @@ export const Gallery = observer(function Gallery(p: { st: WebSt; compact?: boole
550
596
  )}
551
597
  {(r.audios ?? []).map((a, ix) =>
552
598
  a.url != null ? (
553
- <div key={`${r.promptId}-audio-${ix}`} className="audio-cell">
599
+ <div
600
+ key={`${r.promptId}-audio-${ix}`}
601
+ className="audio-cell"
602
+ {...outputDrag({ kind: 'audio', url: a.url, absPath: a.absPath, filename: a.filename })}
603
+ >
554
604
  <audio controls preload="metadata" src={a.url} />
555
605
  <a className="hint" href={a.url} download={a.filename}>
556
606
  {a.filename}
557
607
  </a>
558
608
  <EphemeralPill out={a} />
609
+ <UseAs
610
+ st={p.st}
611
+ out={{ kind: 'audio', url: a.url, absPath: a.absPath, filename: a.filename }}
612
+ />
559
613
  </div>
560
614
  ) : (
561
615
  <div key={`${r.promptId}-audio-${ix}`} className="noimg">
@@ -563,7 +617,33 @@ export const Gallery = observer(function Gallery(p: { st: WebSt; compact?: boole
563
617
  </div>
564
618
  ),
565
619
  )}
566
- {r.images.length === 0 && (r.texts ?? []).length === 0 && (r.audios ?? []).length === 0 ? (
620
+ {(r.videos ?? []).map((a, ix) =>
621
+ a.url != null ? (
622
+ <div
623
+ key={`${r.promptId}-video-${ix}`}
624
+ className="video-cell"
625
+ {...outputDrag({ kind: 'video', url: a.url, absPath: a.absPath, filename: a.filename })}
626
+ >
627
+ <video controls muted loop preload="metadata" src={a.url} />
628
+ <a className="hint" href={a.url} download={a.filename}>
629
+ {a.filename}
630
+ </a>
631
+ <EphemeralPill out={a} />
632
+ <UseAs
633
+ st={p.st}
634
+ out={{ kind: 'video', url: a.url, absPath: a.absPath, filename: a.filename }}
635
+ />
636
+ </div>
637
+ ) : (
638
+ <div key={`${r.promptId}-video-${ix}`} className="noimg">
639
+ {a.filename} (not saved, and no longer in memory)
640
+ </div>
641
+ ),
642
+ )}
643
+ {r.images.length === 0 &&
644
+ (r.texts ?? []).length === 0 &&
645
+ (r.audios ?? []).length === 0 &&
646
+ (r.videos ?? []).length === 0 ? (
567
647
  <div className="noimg">no outputs</div>
568
648
  ) : null}
569
649
  </div>
@@ -19,7 +19,7 @@ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
19
19
  import { VarIcon } from 'src/cli/serve/web/components/VarIcon.tsx'
20
20
  import { generateButtonLook } from 'src/cli/serve/web/state/generateButton.ts'
21
21
  import { groupPlaces, type GroupPlace } from 'src/cli/serve/web/state/varGroups.ts'
22
- import { ImageControl } from 'src/cli/serve/web/components/controls/ImageControl.tsx'
22
+ import { MediaControl } from 'src/cli/serve/web/components/controls/MediaControl.tsx'
23
23
  import { LorasControl } from 'src/cli/serve/web/components/controls/LorasControl.tsx'
24
24
  import { SeedControl } from 'src/cli/serve/web/components/controls/SeedControl.tsx'
25
25
  import { SizeControl } from 'src/cli/serve/web/components/controls/SizeControl.tsx'
@@ -63,7 +63,9 @@ const VarControl = observer(function VarControl(p: {
63
63
  case 'size':
64
64
  return <SizeControl v={p.v} st={p.st} module={p.module} />
65
65
  case 'image':
66
- return <ImageControl v={p.v} />
66
+ case 'audio':
67
+ case 'video':
68
+ return <MediaControl v={p.v} kind={p.v.desc.kind} />
67
69
  default:
68
70
  // a newer server may describe a kind this bundle predates: stay usable
69
71
  return <div className="hint">unsupported var kind '{p.v.desc.kind}' — use the json api</div>
@@ -78,7 +80,7 @@ function rowDrag(p: { st: WebSt; module: string; names: readonly string[]; index
78
80
  return {
79
81
  row: {
80
82
  onDragOver: (e) => {
81
- // only a row drag: a file dropped on an image var must still reach its own handler
83
+ // only a row drag: a file or an output dropped on a media var reaches its own handler
82
84
  if (e.dataTransfer.types.includes('application/x-comfy-var')) e.preventDefault()
83
85
  },
84
86
  onDrop: (e) => {
@@ -0,0 +1,111 @@
1
+ // image, audio, video: a path/url input the api already accepts, a browser upload (POST /upload
2
+ // → local file under outputs/serve-inputs/), and a DROP ZONE for desktop files and gallery
3
+ // outputs. The preview plays the var's own medium when the value has a browser url
4
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
5
+ import { observer } from 'mobx-react-lite'
6
+ import { useRef, useState, type DragEvent, type ReactNode } from 'react'
7
+ import { decodeDraggedOutput, OUTPUT_DRAG_MIME } from 'src/cli/serve/web/state/mediaDrop.ts'
8
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
9
+ import type { MediaKind } from 'src/runner/mediaKinds.ts'
10
+
11
+ /** a drag we can take: one of our outputs, or files from the desktop. A row reorder is not one */
12
+ function isMediaDrag(e: DragEvent): boolean {
13
+ const types = e.dataTransfer.types
14
+ return types.includes(OUTPUT_DRAG_MIME) || types.includes('Files')
15
+ }
16
+
17
+ function Preview(p: { kind: MediaKind; url: string; alt: string }): ReactNode {
18
+ if (p.kind === 'audio') return <audio controls preload="metadata" src={p.url} />
19
+ if (p.kind === 'video') return <video controls muted preload="metadata" src={p.url} />
20
+ return <img src={p.url} alt={p.alt} />
21
+ }
22
+
23
+ export const MediaControl = observer(function MediaControl(p: { v: VarSt; kind: MediaKind }) {
24
+ const fileInput = useRef<HTMLInputElement>(null)
25
+ const [over, setOver] = useState(false)
26
+ const value = typeof p.v.value === 'string' ? p.v.value : ''
27
+ const previewUrl = /^https?:\/\//.test(value) ? value : p.v.uploadedUrl
28
+ const extensions = p.v.desc.extensions ?? []
29
+ const onDrop = (e: DragEvent): void => {
30
+ if (!isMediaDrag(e)) return
31
+ e.preventDefault()
32
+ e.stopPropagation()
33
+ setOver(false)
34
+ const raw = e.dataTransfer.getData(OUTPUT_DRAG_MIME)
35
+ if (raw !== '') {
36
+ const out = decodeDraggedOutput(raw)
37
+ if (out == null) return p.v.setMediaError('that drop is not a gallery output this panel knows')
38
+ void p.v.takeOutput(out)
39
+ return
40
+ }
41
+ const file = e.dataTransfer.files[0]
42
+ if (file != null) void p.v.takeFile(file)
43
+ }
44
+ return (
45
+ <div
46
+ className={`media-drop${over ? ' over' : ''}`}
47
+ onDragOver={(e) => {
48
+ if (!isMediaDrag(e)) return
49
+ e.preventDefault()
50
+ e.dataTransfer.dropEffect = 'copy'
51
+ setOver(true)
52
+ }}
53
+ onDragLeave={(e) => {
54
+ // leaving for a child is not leaving the zone
55
+ if (e.currentTarget.contains(e.relatedTarget as Node | null)) return
56
+ setOver(false)
57
+ }}
58
+ onDrop={onDrop}
59
+ >
60
+ <div className="row-inline">
61
+ <input
62
+ type="text"
63
+ style={{ flex: 1 }}
64
+ placeholder={`local ${p.kind} path or http(s) url`}
65
+ value={value}
66
+ onChange={(e) => {
67
+ p.v.set(e.target.value)
68
+ p.v.setUploadedUrl(null)
69
+ p.v.setMediaError(null)
70
+ }}
71
+ />
72
+ <button type="button" disabled={p.v.mediaBusy} onClick={() => fileInput.current?.click()}>
73
+ {p.v.mediaBusy ? 'uploading…' : 'upload…'}
74
+ </button>
75
+ {value !== '' ? (
76
+ <button
77
+ type="button"
78
+ data-tip={`clear the ${p.kind}`}
79
+ onClick={() => {
80
+ p.v.set('')
81
+ p.v.setUploadedUrl(null)
82
+ p.v.setMediaError(null)
83
+ }}
84
+ >
85
+ <Icon name="close" />
86
+ </button>
87
+ ) : null}
88
+ <input
89
+ ref={fileInput}
90
+ type="file"
91
+ accept={extensions.map((ext) => `.${ext}`).join(',')}
92
+ style={{ display: 'none' }}
93
+ onChange={(e) => {
94
+ const file = e.target.files?.[0]
95
+ if (file != null) void p.v.takeFile(file)
96
+ e.target.value = ''
97
+ }}
98
+ />
99
+ </div>
100
+ <div className="hint media-drop-hint">
101
+ drop a {p.kind} file here, or drag one from the results (or use its <b>→ {p.v.name}</b> button)
102
+ </div>
103
+ {p.v.mediaError != null ? <div className="error">{p.v.mediaError}</div> : null}
104
+ {previewUrl != null && previewUrl !== '' ? (
105
+ <div className={`img-preview media-preview-${p.kind}`}>
106
+ <Preview kind={p.kind} url={previewUrl} alt={value} />
107
+ </div>
108
+ ) : null}
109
+ </div>
110
+ )
111
+ })
@@ -3,7 +3,16 @@
3
3
  // reaction is owned here). DRAFTS ARE LIVE (the TUI model): edits autosave
4
4
  // through PUT /drafts, generate posts {} — the draft is the one source of truth
5
5
  import { makeAutoObservable, observableRef, reaction, runInAction, type IReactionDisposer } from 'mobx'
6
- import { fetchPreviews, saveDraft, type ModuleDescription } from 'src/cli/serve/web/api.ts'
6
+ import { fetchPreviews, saveDraft, uploadFile, type ModuleDescription } from 'src/cli/serve/web/api.ts'
7
+ import {
8
+ isMediaKind,
9
+ mediaKindOfFile,
10
+ refuseDrop,
11
+ valueForOutput,
12
+ type DraggedOutput,
13
+ } from 'src/cli/serve/web/state/mediaDrop.ts'
14
+ import type { MediaKind } from 'src/runner/mediaKinds.ts'
15
+ import { logWebError } from 'src/cli/serve/web/logWeb.ts'
7
16
  import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
8
17
  import { normalizeInitial, payloadSnapshot } from 'src/cli/serve/web/state/payload.ts'
9
18
  import {
@@ -23,8 +32,12 @@ export class VarSt {
23
32
  value: unknown
24
33
  /** changed since the draft loaded — drives the revert affordance, not the payload */
25
34
  dirty = false
26
- /** image vars only: a browser-visible url for the current value (upload response or http value) */
35
+ /** media vars only: a browser-visible url for the current value (upload response or http value) */
27
36
  uploadedUrl: string | null = null
37
+ /** media vars only: why the last drop or upload did not land, shown on the row */
38
+ mediaError: string | null = null
39
+ /** media vars only: an upload is on its way */
40
+ mediaBusy = false
28
41
 
29
42
  constructor(
30
43
  public readonly name: string,
@@ -52,6 +65,60 @@ export class VarSt {
52
65
  this.uploadedUrl = url
53
66
  }
54
67
 
68
+ /** the medium this row takes, null for a non-media var */
69
+ get mediaKind(): MediaKind | null {
70
+ return isMediaKind(this.desc.kind) ? this.desc.kind : null
71
+ }
72
+
73
+ setMediaError(message: string | null): void {
74
+ this.mediaError = message
75
+ }
76
+
77
+ /** a desktop file (picked or dropped): uploaded, the var points at the local copy */
78
+ async takeFile(file: File): Promise<void> {
79
+ const kind = this.mediaKind
80
+ if (kind == null) return
81
+ const refused = refuseDrop(kind, mediaKindOfFile(file), file.name)
82
+ if (refused != null) return this.setMediaError(refused)
83
+ await this.landMedia(file.name, () => uploadFile({ file }))
84
+ }
85
+
86
+ /** a gallery output (dragged, or its `→ var` button) */
87
+ async takeOutput(o: DraggedOutput): Promise<void> {
88
+ const kind = this.mediaKind
89
+ if (kind == null) return
90
+ const refused = refuseDrop(kind, o.kind, o.filename)
91
+ if (refused != null) return this.setMediaError(refused)
92
+ await this.landMedia(o.filename, () =>
93
+ valueForOutput(o, {
94
+ fetchBlob: async (url) => {
95
+ const res = await fetch(url)
96
+ if (!res.ok) throw new Error(`http ${res.status} on ${url}`)
97
+ return res.blob()
98
+ },
99
+ upload: (file) => uploadFile({ file }),
100
+ }),
101
+ )
102
+ }
103
+
104
+ private async landMedia(what: string, get: () => Promise<{ path: string; url: string | null }>): Promise<void> {
105
+ this.mediaBusy = true
106
+ this.mediaError = null
107
+ try {
108
+ const value = await get()
109
+ runInAction(() => {
110
+ this.set(value.path)
111
+ this.uploadedUrl = value.url
112
+ })
113
+ } catch (e) {
114
+ const message = `${what}: ${e instanceof Error ? e.message : String(e)}`
115
+ logWebError('media input did not land', e)
116
+ runInAction(() => (this.mediaError = message))
117
+ } finally {
118
+ runInAction(() => (this.mediaBusy = false))
119
+ }
120
+ }
121
+
55
122
  /** the workflow's declared default, in the shape the controls hold */
56
123
  get defaultValue(): unknown {
57
124
  return normalizeInitial(this.desc, this.desc.default)
@@ -71,6 +138,7 @@ export class VarSt {
71
138
  this.value = this.initial
72
139
  this.dirty = false
73
140
  this.uploadedUrl = null
141
+ this.mediaError = null
74
142
  }
75
143
 
76
144
  snapshot(): { name: string; value: unknown } {
@@ -95,6 +95,8 @@ export function coerceHostValue(desc: VarDescriptor, raw: unknown, current: unkn
95
95
  case 'prompt':
96
96
  case 'text':
97
97
  case 'image':
98
+ case 'audio':
99
+ case 'video':
98
100
  return typeof raw === 'string' ? { ok: true, value: raw } : REJECT
99
101
  case 'int':
100
102
  return isFiniteNumber(raw) ? { ok: true, value: Math.trunc(raw) } : REJECT
@@ -0,0 +1,76 @@
1
+ // what lands on a media var: a desktop file or a gallery output. PURE (the fetch and the upload
2
+ // are injected), tests/serve-web-media-drop.test.ts. The var must end on a LOCAL PATH, because
3
+ // that is the only value /generate accepts without a download
4
+ import { DEFAULT_MEDIA_EXTENSIONS, extensionOf, MEDIA_KINDS, type MediaKind } from 'src/runner/mediaKinds.ts'
5
+
6
+ /** the dataTransfer type a gallery output drags under */
7
+ export const OUTPUT_DRAG_MIME = 'application/x-comfy-output'
8
+
9
+ export type DraggedOutput = { kind: MediaKind; url: string | null; absPath: string | null; filename: string }
10
+
11
+ export function encodeDraggedOutput(o: DraggedOutput): string {
12
+ return JSON.stringify(o)
13
+ }
14
+
15
+ /** null on anything that is not one of ours: a drop can come from any page */
16
+ export function decodeDraggedOutput(raw: string): DraggedOutput | null {
17
+ let parsed: unknown
18
+ try {
19
+ parsed = JSON.parse(raw)
20
+ } catch {
21
+ return null
22
+ }
23
+ if (parsed == null || typeof parsed !== 'object') return null
24
+ // family 10: every field is checked right below before the object is claimed
25
+ const o = parsed as Record<string, unknown>
26
+ const kind = o.kind
27
+ if (typeof kind !== 'string' || !isMediaKind(kind)) return null
28
+ if (typeof o.filename !== 'string') return null
29
+ // any page can put this type on a drag: only a same-origin url and an absolute path are ours
30
+ const url = typeof o.url === 'string' && /^\/(?!\/)/.test(o.url) ? o.url : null
31
+ const absPath = typeof o.absPath === 'string' && /^(\/|[A-Za-z]:[\\/])/.test(o.absPath) ? o.absPath : null
32
+ if (o.url != null && url == null) return null
33
+ if (o.absPath != null && absPath == null) return null
34
+ if (url == null && absPath == null) return null
35
+ return { kind, url, absPath, filename: o.filename }
36
+ }
37
+
38
+ export function isMediaKind(kind: string): kind is MediaKind {
39
+ return (MEDIA_KINDS as readonly string[]).includes(kind)
40
+ }
41
+
42
+ /** a desktop file's medium: its mime first, its extension when the browser gave no mime */
43
+ export function mediaKindOfFile(file: { name: string; type: string }): MediaKind | null {
44
+ const top = file.type.split('/')[0] ?? ''
45
+ if (isMediaKind(top)) return top
46
+ const ext = extensionOf(file.name)
47
+ return MEDIA_KINDS.find((k) => DEFAULT_MEDIA_EXTENSIONS[k].includes(ext)) ?? null
48
+ }
49
+
50
+ /** null when the var takes it, else the reason it does not, said to the user */
51
+ export function refuseDrop(varKind: MediaKind, dropped: MediaKind | null, what: string): string | null {
52
+ if (dropped === varKind) return null
53
+ return `this is ${article(varKind)} input: ${what} is ${dropped == null ? 'not a known media file' : article(dropped)}`
54
+ }
55
+
56
+ function article(kind: MediaKind): string {
57
+ return kind === 'video' ? `a ${kind}` : `an ${kind}`
58
+ }
59
+
60
+ export type MediaValue = { path: string; url: string | null }
61
+
62
+ /** a saved output is already a local path. An unsaved one lives in the server memory only, so
63
+ * its bytes are fetched and uploaded, and the var points at the uploaded copy */
64
+ export async function valueForOutput(
65
+ o: DraggedOutput,
66
+ deps: {
67
+ fetchBlob: (url: string) => Promise<Blob>
68
+ upload: (file: File) => Promise<{ path: string; url: string | null }>
69
+ },
70
+ ): Promise<MediaValue> {
71
+ if (o.absPath != null) return { path: o.absPath, url: o.url }
72
+ if (o.url == null) throw new Error(`${o.filename} is no longer in memory: nothing to use`)
73
+ const blob = await deps.fetchBlob(o.url)
74
+ const reply = await deps.upload(new File([blob], o.filename, { type: blob.type }))
75
+ return { path: reply.path, url: reply.url }
76
+ }
@@ -528,6 +528,17 @@ input[type='range'].setting-range:disabled { opacity: 0.3; }
528
528
  .run-card .noimg { color: var(--dim); font-style: italic; }
529
529
  .audio-cell { display: flex; flex-direction: column; gap: 4px; width: min(100%, 480px); }
530
530
  .audio-cell audio { width: 100%; }
531
+ .video-cell { display: flex; flex-direction: column; gap: 4px; width: min(100%, 480px); }
532
+ .gallery.by-cols .video-cell { width: 100%; }
533
+ .video-cell video { width: 100%; max-height: 480px; border-radius: 6px; background: #000; }
534
+ .img-cell[draggable='true'], .audio-cell[draggable='true'], .video-cell[draggable='true'] { cursor: grab; }
535
+ .use-as { display: flex; flex-wrap: wrap; gap: 4px; }
536
+ /* a media var takes desktop files and gallery outputs: the zone lights while one hovers it */
537
+ .media-drop { border: 1px dashed var(--border); border-radius: 6px; padding: 6px; }
538
+ .media-drop.over { border-color: var(--accent); background: var(--accent-dim); }
539
+ .media-drop .error { color: var(--red); font-size: 12px; margin-top: 4px; white-space: pre-wrap; }
540
+ .media-preview-audio audio { width: min(100%, 360px); }
541
+ .media-preview-video video { max-width: 320px; max-height: 220px; border-radius: 6px; border: 1px solid var(--border); background: #000; }
531
542
  .run-card.running { border-color: var(--accent-dim); }
532
543
  /* what the host is on, in the node's own unit — the live signal of a text run, which has
533
544
  neither a latent frame nor an image to show */
@@ -907,6 +918,9 @@ button.enh-big { font-size: 14px; padding: 8px 18px; }
907
918
  /* blur mode: every result, the latent frame included, stays blurred until the pointer is on it */
908
919
  .gallery.blur img { filter: blur(22px); transition: filter 0.12s, transform 0.12s; }
909
920
  .gallery.blur img:hover, .gallery.blur .img-cell:hover img, .gallery.blur button:hover img { filter: none; }
921
+ /* a video is a picture too: the same privacy blur, lifted while you hover it */
922
+ .gallery.blur .video-cell video { filter: blur(22px); transition: filter 0.12s; }
923
+ .gallery.blur .video-cell:hover video { filter: none; }
910
924
  /* the blur stays inside the image: clipped by its button, and the image scaled up a little while
911
925
  blurred, else the clip shows the blur fading to transparent along every edge */
912
926
  .gallery.blur .img-button { position: relative; overflow: hidden; border-radius: 6px; }
@@ -918,13 +932,13 @@ button.enh-big { font-size: 14px; padding: 8px 18px; }
918
932
  }
919
933
  .img-button:hover .blur-hint { display: none; }
920
934
  /* an unsaved output: only the serve process holds it, so it says so where the eye lands */
921
- .gallery .img-button, .audio-cell { position: relative; }
935
+ .gallery .img-button, .audio-cell, .video-cell { position: relative; }
922
936
  .ephemeral-pill {
923
937
  position: absolute; left: 6px; bottom: 6px; pointer-events: auto; display: inline-flex; align-items: center; gap: 4px;
924
938
  font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
925
939
  color: #1a1400; background: var(--amber); opacity: 0.92;
926
940
  }
927
- .audio-cell .ephemeral-pill { position: static; align-self: flex-start; }
941
+ .audio-cell .ephemeral-pill, .video-cell .ephemeral-pill { position: static; align-self: flex-start; }
928
942
  .memory-menu { max-width: 300px; }
929
943
  .memory-note { margin: 0; padding: 2px 4px; font-size: 12px; line-height: 1.4; }
930
944
  .memory-note.error { color: var(--red); }
@@ -64,7 +64,10 @@ export const ImagePickerOverlay = observer((p: { st: TuiSt }) => {
64
64
  })}
65
65
  footer={
66
66
  rows.length === 0 ? (
67
- <Text color="red">{ip.listingError ?? (ip.filter !== '' ? 'no match' : 'no images here')}</Text>
67
+ <Text color="red">
68
+ {ip.listingError ??
69
+ (ip.filter !== '' ? 'no match' : `no ${ip.selectedVar?.kind ?? 'image'} files here`)}
70
+ </Text>
68
71
  ) : undefined
69
72
  }
70
73
  />
@@ -8,7 +8,8 @@ import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
8
8
  import { fuzzyMatch } from 'src/utils/fuzzyMatch.ts'
9
9
  import { imageBufferToAnsi } from 'src/utils/ansiImage.ts'
10
10
  import { protocolReadyBytes } from 'src/cli/tui/protocolImage.ts'
11
- import type { ImageVar } from 'src/vars/ComfyVars.ts'
11
+ import type { MediaVar } from 'src/vars/ComfyVars.ts'
12
+ import { extensionOf } from 'src/runner/mediaKinds.ts'
12
13
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
13
14
 
14
15
  export type PickerPane = 'browse' | 'favorites' | 'recents'
@@ -50,9 +51,9 @@ export class ImagePickerSt {
50
51
  filter: string = ''
51
52
 
52
53
  /** kind-narrowing cast sanctioned (agent/coding.md), `kind` is the tag */
53
- get selectedVar(): ImageVar | null {
54
+ get selectedVar(): MediaVar | null {
54
55
  const sel = this.st.selected?.[1]
55
- return sel?.kind === 'image' ? (sel as ImageVar) : null
56
+ return sel?.kind === 'image' || sel?.kind === 'audio' || sel?.kind === 'video' ? (sel as MediaVar) : null
56
57
  }
57
58
 
58
59
  get folderDisplay(): string {
@@ -60,7 +61,7 @@ export class ImagePickerSt {
60
61
  }
61
62
 
62
63
  /** begin() open order: dirname(value) → persisted lastFolder → opts.folder → cwd */
63
- private initialFolder(iv: ImageVar): string {
64
+ private initialFolder(iv: MediaVar): string {
64
65
  const candidates: (string | null)[] = [
65
66
  iv.isSet() ? dirname(iv.absPath()) : null,
66
67
  pickerPrefs().lastFolder,
@@ -104,7 +105,8 @@ export class ImagePickerSt {
104
105
  }
105
106
  if (this.pane === 'recents')
106
107
  return {
107
- rows: pickerPrefs().recents.map((img) => ({
108
+ // one recents list for every medium: an audio var lists only what it could take
109
+ rows: this.recentsForVar().map((img) => ({
108
110
  kind: 'image',
109
111
  name: contractHome(img),
110
112
  path: img,
@@ -130,6 +132,11 @@ export class ImagePickerSt {
130
132
  }
131
133
  }
132
134
 
135
+ private recentsForVar(): string[] {
136
+ const exts = this.selectedVar?.extensions ?? []
137
+ return pickerPrefs().recents.filter((f) => exts.includes(extensionOf(f)))
138
+ }
139
+
133
140
  get listingError(): string | null {
134
141
  return this.paneListing.error
135
142
  }
@@ -145,8 +152,10 @@ export class ImagePickerSt {
145
152
  return this.rows[this.ix] ?? null
146
153
  }
147
154
 
148
- /** feeds the preview reaction: only a real, present image highlights */
155
+ /** feeds the preview reaction: only a real, present image highlights (an audio or video
156
+ * row has nothing to paint) */
149
157
  get highlightedImage(): string | null {
158
+ if (this.selectedVar?.kind !== 'image') return null
150
159
  const row = this.current
151
160
  return row?.kind === 'image' && !row.missing ? row.path : null
152
161
  }
@@ -317,7 +317,7 @@ export class TuiSt {
317
317
  else if (sel.kind === 'choice') this.picker.beginChoice()
318
318
  else if (sel.kind === 'size') this.picker.beginSize()
319
319
  else if (sel.kind === 'loras') this.loras.begin()
320
- else if (sel.kind === 'image') this.imagePicker.begin()
320
+ else if (sel.kind === 'image' || sel.kind === 'audio' || sel.kind === 'video') this.imagePicker.begin()
321
321
  else this.editor.beginInline() // int / float / seed: type the number
322
322
  }
323
323
 
@@ -36,6 +36,7 @@ export {
36
36
  export {
37
37
  ComfyExecution,
38
38
  type ComfyAudioOutput,
39
+ type ComfyVideoOutput,
39
40
  type ComfyExecutionData,
40
41
  type ComfyTextOutput,
41
42
  type ExecutionProgress,
@@ -90,13 +91,19 @@ export {
90
91
  MultiChoiceVar,
91
92
  LorasVar,
92
93
  SizeVar,
94
+ MediaVar,
93
95
  ImageVar,
96
+ AudioVar,
97
+ VideoVar,
98
+ MediaVarEmptyError,
94
99
  ImageVarEmptyError,
95
100
  DEFAULT_SIZE_PRESETS,
96
101
  SD15_SIZE_PRESETS,
97
102
  DEFAULT_STARRED_SIZES,
98
103
  sizePresetsFor,
99
104
  DEFAULT_IMAGE_EXTENSIONS,
105
+ DEFAULT_AUDIO_EXTENSIONS,
106
+ DEFAULT_VIDEO_EXTENSIONS,
100
107
  activeLoras,
101
108
  } from 'src/vars/ComfyVars.ts'
102
109
  export type {
@@ -114,7 +121,10 @@ export type {
114
121
  ActiveLora,
115
122
  SizeValue,
116
123
  SizePreset,
124
+ MediaVarOpts,
117
125
  ImageVarOpts,
126
+ AudioVarOpts,
127
+ VideoVarOpts,
118
128
  TextVarOpts,
119
129
  PromptVarOpts,
120
130
  PromptTagsOpts,
@@ -44,13 +44,23 @@ export function bundledExamplesDir(moduleUrl: string = import.meta.url): string
44
44
  * or the package's examples/ folder was pruned.
45
45
  */
46
46
  export function exampleImagePath(name: string): string {
47
+ return bundledExampleFile('images', name)
48
+ }
49
+
50
+ /** the same for a bundled `examples/media/` audio or video file, e.g.
51
+ * `exampleMediaPath('sine_440hz_3s.flac')` — the default of audio and video example vars */
52
+ export function exampleMediaPath(name: string): string {
53
+ return bundledExampleFile('media', name)
54
+ }
55
+
56
+ function bundledExampleFile(folder: 'images' | 'media', name: string): string {
47
57
  const examples = bundledExamplesDir()
48
58
  if (examples == null) {
49
59
  throw new Error(
50
- `[comfy-ts] cannot resolve bundled example image '${name}': the package's examples/ folder is not on disk`,
60
+ `[comfy-ts] cannot resolve bundled example file '${name}': the package's examples/ folder is not on disk`,
51
61
  )
52
62
  }
53
- const abs = join(examples, 'images', name)
54
- if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example image not found: ${abs}`)
63
+ const abs = join(examples, folder, name)
64
+ if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example file not found: ${abs}`)
55
65
  return abs
56
66
  }