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,98 @@
1
+ // beside blur: how much of the server's memory budget the unsaved outputs hold, and a popover to
2
+ // change that budget. The server drops the oldest unsaved outputs first once it is full
3
+ import {
4
+ autoUpdate,
5
+ flip,
6
+ FloatingPortal,
7
+ offset,
8
+ shift,
9
+ useDismiss,
10
+ useFloating,
11
+ useInteractions,
12
+ } from '@floating-ui/react'
13
+ import { observer } from 'mobx-react-lite'
14
+ import { useState } from 'react'
15
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
16
+ import { formatMb } from 'src/cli/serve/web/state/keptResults.ts'
17
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
18
+
19
+ const BUDGET_CHOICES_MB = [25, 50, 100, 250, 500, 1000, 2000]
20
+
21
+ export const MemoryBudgetButton = observer(function MemoryBudgetButton(p: { st: WebSt }) {
22
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null)
23
+ const [open, setOpen] = useState(false)
24
+ const memory = p.st.run.memory
25
+ const budgetMb = p.st.settings.memoryBudgetMb
26
+ return (
27
+ <>
28
+ <button
29
+ type="button"
30
+ ref={setAnchor}
31
+ className={open ? 'sel' : ''}
32
+ data-tip="unsaved results kept in the server memory: click to change the budget"
33
+ onClick={() => {
34
+ if (!open) void p.st.run.refreshMemory()
35
+ setOpen(!open)
36
+ }}
37
+ >
38
+ <Icon name="memory" />
39
+ {memory == null ? `${budgetMb} MB` : `${formatMb(memory.usedBytes)}/${budgetMb} MB`}
40
+ </button>
41
+ {open && anchor != null ? <MemoryMenu st={p.st} anchor={anchor} onClose={() => setOpen(false)} /> : null}
42
+ </>
43
+ )
44
+ })
45
+
46
+ const MemoryMenu = observer(function MemoryMenu(p: { st: WebSt; anchor: HTMLElement; onClose: () => void }) {
47
+ const { refs, floatingStyles, context } = useFloating({
48
+ open: true,
49
+ onOpenChange: (open) => {
50
+ if (!open) p.onClose()
51
+ },
52
+ placement: 'bottom-end',
53
+ middleware: [offset(4), flip(), shift({ padding: 8 })],
54
+ whileElementsMounted: autoUpdate,
55
+ elements: { reference: p.anchor },
56
+ })
57
+ const { getFloatingProps } = useInteractions([useDismiss(context)])
58
+ const memory = p.st.run.memory
59
+ const budgetMb = p.st.settings.memoryBudgetMb
60
+ // a hand-written budget off the list still shows as the selected value
61
+ const choices = BUDGET_CHOICES_MB.includes(budgetMb)
62
+ ? BUDGET_CHOICES_MB
63
+ : [...BUDGET_CHOICES_MB, budgetMb].sort((a, b) => a - b)
64
+ return (
65
+ <FloatingPortal>
66
+ <div ref={refs.setFloating} style={floatingStyles} className="tab-menu memory-menu" {...getFloatingProps()}>
67
+ <div className="menu-row">
68
+ <Icon name="memory" />
69
+ <span className="menu-value">server memory</span>
70
+ </div>
71
+ <p className="hint memory-note">
72
+ Unsaved results live in the serve process only: a page reload shows them again, a server restart loses
73
+ them. Past the budget, the oldest go first.
74
+ </p>
75
+ <label className="menu-row">
76
+ <span>budget</span>
77
+ <select
78
+ className="menu-select"
79
+ value={budgetMb}
80
+ onChange={(e) => void p.st.setMemoryBudget(Number(e.target.value))}
81
+ >
82
+ {choices.map((mb) => (
83
+ <option key={mb} value={mb}>
84
+ {mb >= 1000 ? `${mb / 1000} GB` : `${mb} MB`}
85
+ </option>
86
+ ))}
87
+ </select>
88
+ </label>
89
+ <div className="hint memory-note">
90
+ {memory == null
91
+ ? 'usage not read yet'
92
+ : `${formatMb(memory.usedBytes)} MB used by ${memory.outputs} unsaved output${memory.outputs === 1 ? '' : 's'}, ${memory.runs} run${memory.runs === 1 ? '' : 's'} kept`}
93
+ </div>
94
+ {p.st.savingError != null ? <div className="error memory-note">{p.st.savingError}</div> : null}
95
+ </div>
96
+ </FloatingPortal>
97
+ )
98
+ })
@@ -0,0 +1,19 @@
1
+ // the last failed run, in full: ComfyUI's message names the node and often a file path, so it
2
+ // wraps instead of being cut to one line. Under the prompt preview, where the eye is after a run
3
+ import { observer } from 'mobx-react-lite'
4
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
5
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
6
+
7
+ export const RunError = observer(function RunError(p: { st: WebSt }) {
8
+ const error = p.st.run.error
9
+ if (error == null) return null
10
+ return (
11
+ <div className="run-error-block" role="alert">
12
+ <Icon name="warn" />
13
+ <pre className="run-error-text">{error}</pre>
14
+ <button type="button" className="link danger" data-tip="dismiss" onClick={() => p.st.run.dismissError()}>
15
+ <Icon name="close" />
16
+ </button>
17
+ </div>
18
+ )
19
+ })
@@ -0,0 +1,54 @@
1
+ // every key the panel binds, one popup, opened from the menu
2
+ import { observer } from 'mobx-react-lite'
3
+ import { useEffect } from 'react'
4
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
5
+ import { shortcutCatalog } from 'src/cli/serve/web/state/shortcutCatalog.ts'
6
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
7
+
8
+ export const ShortcutsModal = observer(function ShortcutsModal(p: { st: WebSt }) {
9
+ const open = p.st.showShortcuts
10
+ useEffect(() => {
11
+ if (!open) return
12
+ const onKey = (e: KeyboardEvent): void => {
13
+ if (e.key === 'Escape') p.st.setShowShortcuts(false)
14
+ }
15
+ window.addEventListener('keydown', onKey)
16
+ return () => window.removeEventListener('keydown', onKey)
17
+ }, [open, p.st])
18
+ if (!open) return null
19
+ return (
20
+ <div className="modal-overlay top" onClick={() => p.st.setShowShortcuts(false)}>
21
+ <div className="modal shortcuts-modal" onClick={(e) => e.stopPropagation()}>
22
+ <div className="modal-head">
23
+ <Icon name="keyboard" />
24
+ <span className="shortcuts-title">shortcuts</span>
25
+ <button
26
+ type="button"
27
+ className="modal-close"
28
+ data-tip="close (esc)"
29
+ onClick={() => p.st.setShowShortcuts(false)}
30
+ >
31
+ <Icon name="close" />
32
+ </button>
33
+ </div>
34
+ <div className="shortcuts-body">
35
+ {shortcutCatalog().map((g) => (
36
+ <section key={g.title} className="shortcuts-group">
37
+ <div className="menu-title">{g.title}</div>
38
+ {g.rows.map((r) => (
39
+ <div key={r.what} className="shortcuts-row">
40
+ <span className="shortcuts-keys">
41
+ {r.keys.map((k) => (
42
+ <kbd key={k}>{k}</kbd>
43
+ ))}
44
+ </span>
45
+ <span>{r.what}</span>
46
+ </div>
47
+ ))}
48
+ </section>
49
+ ))}
50
+ </div>
51
+ </div>
52
+ </div>
53
+ )
54
+ })
@@ -368,6 +368,17 @@ export const MenuCards = observer(function MenuCards(p: { st: WebSt }) {
368
368
  ))}
369
369
  </div>
370
370
  </Section>
371
+ <Section title="help">
372
+ <button
373
+ type="button"
374
+ className="menu-row menu-action"
375
+ data-tip="every key the panel binds"
376
+ onClick={() => p.st.setShowShortcuts(true)}
377
+ >
378
+ <Icon name="keyboard" />
379
+ <span>shortcuts</span>
380
+ </button>
381
+ </Section>
371
382
  </div>
372
383
  )
373
384
  })
@@ -409,6 +420,9 @@ export const MenuRail = observer(function MenuRail(p: { st: WebSt; onExpand: ()
409
420
  <Icon name={it.icon} />
410
421
  </button>
411
422
  ))}
423
+ <button type="button" className="head-icon" data-tip="shortcuts" onClick={() => p.st.setShowShortcuts(true)}>
424
+ <Icon name="keyboard" />
425
+ </button>
412
426
  </div>
413
427
  )
414
428
  })
@@ -1,11 +1,13 @@
1
1
  // the var rows: each kind dispatches to its matching control (the point of the
2
2
  // web ui — architecture item 12) + the sticky run bar
3
3
  import { observer } from 'mobx-react-lite'
4
- import { useEffect, useRef, type ReactNode } from 'react'
4
+ import { useEffect, useRef, type HTMLAttributes, type ReactNode } from 'react'
5
5
  import { MOD_KEY } from 'src/cli/serve/web/components/modKey.ts'
6
+ import { RunError } from 'src/cli/serve/web/components/RunError.tsx'
6
7
  import { runChipText } from 'src/cli/serve/web/state/stableSlots.ts'
7
- import { jumpTargets, SHORTCUT_KEYS, shortcutOf } from 'src/cli/serve/web/state/shortcuts.ts'
8
+ import { isNewJump, jumpTargets, SHORTCUT_KEYS, shortcutOf } from 'src/cli/serve/web/state/shortcuts.ts'
8
9
  import { isPromptLanes } from 'src/vars/lanes.ts'
10
+ import { formRowNames, OUTPUT_ROW } from 'src/cli/serve/web/state/formRows.ts'
9
11
  import {
10
12
  ChoiceControl,
11
13
  NumberControl,
@@ -17,7 +19,7 @@ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
17
19
  import { VarIcon } from 'src/cli/serve/web/components/VarIcon.tsx'
18
20
  import { generateButtonLook } from 'src/cli/serve/web/state/generateButton.ts'
19
21
  import { groupPlaces, type GroupPlace } from 'src/cli/serve/web/state/varGroups.ts'
20
- import { ImageControl } from 'src/cli/serve/web/components/controls/ImageControl.tsx'
22
+ import { MediaControl } from 'src/cli/serve/web/components/controls/MediaControl.tsx'
21
23
  import { LorasControl } from 'src/cli/serve/web/components/controls/LorasControl.tsx'
22
24
  import { SeedControl } from 'src/cli/serve/web/components/controls/SeedControl.tsx'
23
25
  import { SizeControl } from 'src/cli/serve/web/components/controls/SizeControl.tsx'
@@ -61,13 +63,45 @@ const VarControl = observer(function VarControl(p: {
61
63
  case 'size':
62
64
  return <SizeControl v={p.v} st={p.st} module={p.module} />
63
65
  case 'image':
64
- return <ImageControl v={p.v} />
66
+ case 'audio':
67
+ case 'video':
68
+ return <MediaControl v={p.v} kind={p.v.desc.kind} />
65
69
  default:
66
70
  // a newer server may describe a kind this bundle predates: stay usable
67
71
  return <div className="hint">unsupported var kind '{p.v.desc.kind}' — use the json api</div>
68
72
  }
69
73
  })
70
74
 
75
+ /** a form row's reorder wiring: the row takes the drop, its label is the handle */
76
+ function rowDrag(p: { st: WebSt; module: string; names: readonly string[]; index: number }): {
77
+ row: Pick<HTMLAttributes<HTMLDivElement>, 'onDragOver' | 'onDrop'>
78
+ handle: Pick<HTMLAttributes<HTMLDivElement>, 'draggable' | 'onDragStart'>
79
+ } {
80
+ return {
81
+ row: {
82
+ onDragOver: (e) => {
83
+ // only a row drag: a file or an output dropped on a media var reaches its own handler
84
+ if (e.dataTransfer.types.includes('application/x-comfy-var')) e.preventDefault()
85
+ },
86
+ onDrop: (e) => {
87
+ const raw = e.dataTransfer.getData('application/x-comfy-var')
88
+ if (raw === '') return
89
+ e.preventDefault()
90
+ const from = Number(raw)
91
+ if (Number.isInteger(from) && from !== p.index)
92
+ p.st.moveVar({ module: p.module, names: p.names, from, to: p.index })
93
+ },
94
+ },
95
+ handle: {
96
+ draggable: true,
97
+ onDragStart: (e) => {
98
+ e.dataTransfer.effectAllowed = 'move'
99
+ e.dataTransfer.setData('application/x-comfy-var', String(p.index))
100
+ },
101
+ },
102
+ }
103
+ }
104
+
71
105
  const VarRow = observer(function VarRow(p: {
72
106
  v: VarSt
73
107
  host: string
@@ -83,8 +117,10 @@ const VarRow = observer(function VarRow(p: {
83
117
  const rowRef = useRef<HTMLDivElement>(null)
84
118
  const jump = p.st.jump
85
119
  const jumpKind = p.jumpKey == null ? null : p.v.desc.kind
120
+ const seenJump = useRef(jump?.seq ?? 0)
86
121
  useEffect(() => {
87
- if (jump == null || jumpKind !== 'prompt' || jump.kind !== 'prompt') return
122
+ if (jumpKind !== 'prompt' || !isNewJump(jump, 'prompt', seenJump.current)) return
123
+ seenJump.current = jump?.seq ?? 0
88
124
  const editor = rowRef.current?.querySelector<HTMLElement>('.cm-content')
89
125
  editor?.focus()
90
126
  editor?.scrollIntoView({ block: 'nearest' })
@@ -94,6 +130,7 @@ const VarRow = observer(function VarRow(p: {
94
130
  const ui = p.v.desc.ui
95
131
  const inactive = p.st.form?.inactiveReason(p.v) ?? null
96
132
  const wide = p.v.desc.kind === 'loras' || p.v.desc.kind === 'prompt'
133
+ const drag = rowDrag(p)
97
134
  return (
98
135
  <div
99
136
  ref={rowRef}
@@ -105,18 +142,7 @@ const VarRow = observer(function VarRow(p: {
105
142
  outline: ui?.border == null ? undefined : `1px solid ${ui.border}`,
106
143
  outlineOffset: ui?.border == null ? undefined : '-1px',
107
144
  }}
108
- onDragOver={(e) => {
109
- // only a row drag: a file dropped on an image var must still reach its own handler
110
- if (e.dataTransfer.types.includes('application/x-comfy-var')) e.preventDefault()
111
- }}
112
- onDrop={(e) => {
113
- const raw = e.dataTransfer.getData('application/x-comfy-var')
114
- if (raw === '') return
115
- e.preventDefault()
116
- const from = Number(raw)
117
- if (Number.isInteger(from) && from !== p.index)
118
- p.st.moveVar({ module: p.module, names: p.names, from, to: p.index })
119
- }}
145
+ {...drag.row}
120
146
  >
121
147
  {/* in the form's left gutter: back to the workflow's default. Always there (disabled at
122
148
  the default), so no row moves when a value changes */}
@@ -132,14 +158,7 @@ const VarRow = observer(function VarRow(p: {
132
158
  </button>
133
159
  {/* the LABEL is the handle: a separate grip was one more piece of permanent chrome
134
160
  for something the label itself can carry */}
135
- <div
136
- className={p.jumpKey == null ? 'var-label' : 'var-label has-kbd'}
137
- draggable
138
- onDragStart={(e) => {
139
- e.dataTransfer.effectAllowed = 'move'
140
- e.dataTransfer.setData('application/x-comfy-var', String(p.index))
141
- }}
142
- >
161
+ <div className={p.jumpKey == null ? 'var-label' : 'var-label has-kbd'} {...drag.handle}>
143
162
  {/* the kind is a TOOLTIP, not a second line: printed under every label it was a
144
163
  column of noise you read past, and it only ever answers a question you ask once */}
145
164
  {/* the (?) LEADS: labels are right-aligned against their control, so what trails a
@@ -280,12 +299,13 @@ export const GenerateButton = observer(function GenerateButton(p: { st: WebSt })
280
299
 
281
300
  /** where the generated images go: the same row shape as a var, because it is one more knob
282
301
  * of the run. The toggle and the folder are SERVER settings, so curl sees the same choice */
283
- const SaveRow = observer(function SaveRow(p: { st: WebSt; module: string }) {
302
+ const SaveRow = observer(function SaveRow(p: { st: WebSt; module: string; index: number; names: readonly string[] }) {
284
303
  const on = p.st.saveToDisk
304
+ const drag = rowDrag(p)
285
305
  return (
286
- <div className="var-row">
287
- <div className="var-label">
288
- <span data-tip="save — where this workflow's images go">output</span>
306
+ <div className="var-row" {...drag.row}>
307
+ <div className="var-label" {...drag.handle}>
308
+ <span data-tip={"save — where this workflow's images go\ndrag the label to reorder"}>output</span>
289
309
  </div>
290
310
  <div className="var-control">
291
311
  <div className="row-inline">
@@ -355,12 +375,10 @@ export const VarsForm = observer(function VarsForm(p: { st: WebSt }) {
355
375
  }, [p.st])
356
376
  if (form == null) return null
357
377
  // YOUR order (drag), falling back to the workflow's own declaration order
358
- const orderedNames = p.st.orderedVars(
359
- form.moduleKey,
360
- form.vars.map((v) => v.name),
361
- )
378
+ const orderedNames = p.st.orderedVars(form.moduleKey, formRowNames(form.vars.map((v) => v.name)))
362
379
  const orderedVars = orderedNames.map((n) => form.vars.find((v) => v.name === n)).filter((v) => v != null)
363
- const places = groupPlaces(orderedVars.map((v) => v.desc.ui ?? {}))
380
+ // over every ROW, the output slot included, so an index here is a row index
381
+ const places = groupPlaces(orderedNames.map((n) => form.vars.find((v) => v.name === n)?.desc.ui ?? {}))
364
382
  const targets = jumpTargets(
365
383
  orderedVars.map((v) => ({ name: v.name, kind: v.desc.kind, inactive: form.inactiveReason(v) != null })),
366
384
  )
@@ -380,37 +398,39 @@ export const VarsForm = observer(function VarsForm(p: { st: WebSt }) {
380
398
  drag it (kept in this browser): labels never wrap, a cut one shows whole on hover */}
381
399
  <div className="vars" style={{ gridTemplateColumns: `${p.st.labelWidth}px minmax(0, 1fr)` }}>
382
400
  <LabelResizer st={p.st} />
383
- {orderedVars.map((v, ix) => (
401
+ {orderedNames.map((name, ix) => {
402
+ // the OUTPUT is a knob like the others: a row, not a lone button in the header
403
+ if (name === OUTPUT_ROW)
404
+ return <SaveRow key={OUTPUT_ROW} st={p.st} module={form.moduleKey} index={ix} names={orderedNames} />
405
+ const v = form.vars.find((x) => x.name === name)
406
+ if (v == null) return null
384
407
  // keyed by MODULE and DRAFT: a switch must reset per-row ui state (lora filter,
385
408
  // remembered strengths, paused set), not carry the other selection's over.
386
409
  // module matters because every workflow has a `default` draft and a `prompt`
387
410
  // var, so draft+name alone matches across workflows and react reuses the row
388
- <VarRow
389
- key={`${form.moduleKey}/${form.draft}/${v.name}`}
390
- v={v}
391
- host={form.host}
392
- st={p.st}
393
- module={form.moduleKey}
394
- index={ix}
395
- names={orderedNames}
396
- place={places[ix] ?? null}
397
- jumpKey={jumpKeyOf(v.name)}
398
- />
399
- ))}
400
- {/* the OUTPUT is a knob like the others: a row, not a lone button in the header */}
401
- <SaveRow st={p.st} module={form.moduleKey} />
411
+ return (
412
+ <VarRow
413
+ key={`${form.moduleKey}/${form.draft}/${v.name}`}
414
+ v={v}
415
+ host={form.host}
416
+ st={p.st}
417
+ module={form.moduleKey}
418
+ index={ix}
419
+ names={orderedNames}
420
+ place={places[ix] ?? null}
421
+ jumpKey={jumpKeyOf(v.name)}
422
+ />
423
+ )
424
+ })}
402
425
  </div>
403
- {/* side and pinned put generate INSIDE the results panel, with its error slot; the
404
- form keeps both otherwise. The error is one reserved line either way, so a failed
405
- run never adds a bar or pushes anything down */}
426
+ {/* side and pinned put generate INSIDE the results panel; the form keeps it otherwise.
427
+ The error shows under the prompt preview, in the results panel, unless that is off */}
406
428
  {p.st.generateInResults ? null : (
407
429
  <div className="runbar">
408
430
  <GenerateButton st={p.st} />
409
- <span className="run-error" data-tip={p.st.run.error ?? undefined}>
410
- {p.st.run.error == null ? '' : `🔴 ${p.st.run.error}`}
411
- </span>
412
431
  </div>
413
432
  )}
433
+ {p.st.layout === 'off' ? <RunError st={p.st} /> : null}
414
434
  </div>
415
435
  )
416
436
  })
@@ -57,7 +57,8 @@ export const NumberControl = observer(function NumberControl(p: { v: VarSt }) {
57
57
  {min != null && max != null ? (
58
58
  <input
59
59
  type="range"
60
- style={{ flex: 1, minWidth: 120 }}
60
+ className="num-range"
61
+ style={{ flex: 1, minWidth: 120, backgroundImage: rangeFill(num, min, max) }}
61
62
  value={num}
62
63
  min={min}
63
64
  max={max}
@@ -70,6 +71,12 @@ export const NumberControl = observer(function NumberControl(p: { v: VarSt }) {
70
71
  )
71
72
  })
72
73
 
74
+ // the accent up to the value, drawn on the input: the track itself is transparent
75
+ function rangeFill(num: number, min: number, max: number): string {
76
+ const pct = max > min ? ((Math.min(max, Math.max(min, num)) - min) / (max - min)) * 100 : 0
77
+ return `linear-gradient(90deg, var(--accent) ${pct}%, var(--border) ${pct}%)`
78
+ }
79
+
73
80
  export const ToggleControl = observer(function ToggleControl(p: { v: VarSt }) {
74
81
  return (
75
82
  <label className="row-inline" style={{ cursor: 'pointer' }}>
@@ -16,6 +16,7 @@ import { MenuButton, MenuItem } from 'src/cli/serve/web/components/MenuButton.ts
16
16
  import { logWebError } from 'src/cli/serve/web/logWeb.ts'
17
17
  import { observer, useLocalObservable } from 'mobx-react-lite'
18
18
  import { useEffect, useRef, useState, type DragEvent, type ReactNode } from 'react'
19
+ import { isNewJump } from 'src/cli/serve/web/state/shortcuts.ts'
19
20
  import { fetchLoraAbout, fetchLoraInfo, loraPreviewSrc, type LoraAbout, type LoraInfo } from 'src/cli/serve/web/api.ts'
20
21
  import type { LoraStrength } from 'src/vars/loraEntry.ts'
21
22
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
@@ -356,8 +357,8 @@ export const LorasControl = observer(function LorasControl(p: {
356
357
  </button>
357
358
  <input
358
359
  type="range"
359
- min={-1}
360
- max={2}
360
+ min={0}
361
+ max={1}
361
362
  step={0.05}
362
363
  value={value}
363
364
  onChange={(e) => write(which, parseFloat(e.target.value))}
@@ -392,8 +393,10 @@ export const LorasControl = observer(function LorasControl(p: {
392
393
  // ⌘O: a NEW jump opens the picker on the first section, as its own `add` would
393
394
  const jump = p.st.jump
394
395
  const firstIx = sections[0]?.ix ?? -1
396
+ const seenJump = useRef(jump?.seq ?? 0)
395
397
  useEffect(() => {
396
- if (!p.jumpTarget || jump == null || jump.kind !== 'loras') return
398
+ if (!p.jumpTarget || !isNewJump(jump, 'loras', seenJump.current)) return
399
+ seenJump.current = jump?.seq ?? 0
397
400
  local.openFor(firstIx)
398
401
  }, [jump, p.jumpTarget, firstIx, local])
399
402
 
@@ -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
+ })
@@ -224,8 +224,10 @@ const theme = EditorView.theme(
224
224
  '.cm-content': { padding: '6px 0', caretColor: 'var(--text)' },
225
225
  '.cm-line': { padding: '0 8px' },
226
226
  '.cm-cursor': { borderLeftColor: 'var(--text)' },
227
+ // opaque on purpose: webkit blends a translucent selection down to near the background
227
228
  '&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection': {
228
- background: 'var(--accent-dim) !important',
229
+ background: '#c3d1f4 !important',
230
+ color: '#000 !important',
229
231
  },
230
232
  '.cm-placeholder': { color: 'var(--dim)' },
231
233
  '.pe-comment': { color: 'var(--dim)', fontStyle: 'italic' },