comfy-ts 2.5.0 → 2.7.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 (67) hide show
  1. package/README.md +15 -2
  2. package/dist/{DefinedWorkflow-CnzmQrBh.js → DefinedWorkflow-BJgt5t0x.js} +14 -3
  3. package/dist/DefinedWorkflow-BJgt5t0x.js.map +1 -0
  4. package/dist/{DraftsSt-C1MbWnEp.js → DraftsSt-dizp3VcC.js} +2 -2
  5. package/dist/{DraftsSt-C1MbWnEp.js.map → DraftsSt-dizp3VcC.js.map} +1 -1
  6. package/dist/cli.js +5 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +7 -2
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +24 -18
  11. package/dist/index.d.ts +24 -18
  12. package/dist/index.js +7 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-serve-D47Zas-a.js → run-serve-D1Tsuru9.js} +494 -20
  15. package/dist/run-serve-D1Tsuru9.js.map +1 -0
  16. package/dist/{run-tui-t2TRBN0H.js → run-tui-JxlEbb_f.js} +511 -331
  17. package/dist/run-tui-JxlEbb_f.js.map +1 -0
  18. package/dist/serve-web.js +273 -0
  19. package/dist/{state-DY3Mp9Cl.js → state-CaHeDL-0.js} +7 -13
  20. package/dist/state-CaHeDL-0.js.map +1 -0
  21. package/dist/web.d.ts +24 -18
  22. package/dist/web.js +7 -2
  23. package/dist/web.js.map +1 -1
  24. package/examples/web/tsconfig.json +4 -1
  25. package/package.json +7 -5
  26. package/src/cli/comfy-ts-cli.ts +1 -1
  27. package/src/cli/serve/ServeApp.ts +383 -14
  28. package/src/cli/serve/describeVar.ts +6 -1
  29. package/src/cli/serve/promptEnhancers.ts +69 -0
  30. package/src/cli/serve/run-serve.ts +41 -7
  31. package/src/cli/serve/safeName.ts +12 -0
  32. package/src/cli/serve/web/api.ts +128 -0
  33. package/src/cli/serve/web/clipboard.ts +25 -0
  34. package/src/cli/serve/web/components/App.tsx +53 -0
  35. package/src/cli/serve/web/components/Gallery.tsx +186 -0
  36. package/src/cli/serve/web/components/PromptEnhancer.tsx +254 -0
  37. package/src/cli/serve/web/components/Sidebar.tsx +42 -0
  38. package/src/cli/serve/web/components/VarsForm.tsx +184 -0
  39. package/src/cli/serve/web/components/controls/BasicControls.tsx +95 -0
  40. package/src/cli/serve/web/components/controls/ImageControl.tsx +71 -0
  41. package/src/cli/serve/web/components/controls/LorasControl.tsx +340 -0
  42. package/src/cli/serve/web/components/controls/SeedControl.tsx +43 -0
  43. package/src/cli/serve/web/components/controls/SizeControl.tsx +49 -0
  44. package/src/cli/serve/web/llm.ts +254 -0
  45. package/src/cli/serve/web/main.tsx +18 -0
  46. package/src/cli/serve/web/state/EnhancerSt.ts +481 -0
  47. package/src/cli/serve/web/state/FormSt.ts +180 -0
  48. package/src/cli/serve/web/state/RunSt.ts +136 -0
  49. package/src/cli/serve/web/state/WebSt.ts +235 -0
  50. package/src/cli/serve/web/state/payload.ts +110 -0
  51. package/src/cli/serve/web/styles.ts +261 -0
  52. package/src/cli/serve/web/tsconfig.json +15 -0
  53. package/src/cli/serve/webBundle.ts +66 -0
  54. package/src/cli/tui/imageEscapes.ts +105 -0
  55. package/src/cli/tui/imagePicker/ImagePickerSt.ts +21 -8
  56. package/src/cli/tui/protocolImage.ts +39 -0
  57. package/src/cli/tui/protocolImagePainter.ts +56 -23
  58. package/src/cli/tui/run-tui.tsx +3 -2
  59. package/src/cli/tui/state/LorasSt.ts +22 -9
  60. package/src/cli/tui/state/PreviewSt.ts +31 -13
  61. package/src/cli/tui/state/SettingsSt.ts +1 -1
  62. package/src/state.ts +6 -0
  63. package/src/vars/ComfyVars.ts +4 -1
  64. package/dist/DefinedWorkflow-CnzmQrBh.js.map +0 -1
  65. package/dist/run-serve-D47Zas-a.js.map +0 -1
  66. package/dist/run-tui-t2TRBN0H.js.map +0 -1
  67. package/dist/state-DY3Mp9Cl.js.map +0 -1
@@ -0,0 +1,254 @@
1
+ // ✨ on a prompt row → the refine modal: openrouter key + thinking model +
2
+ // a library of named master prompts. Nothing touches the var until APPLY.
3
+ import { observer } from 'mobx-react-lite'
4
+ import { useEffect } from 'react'
5
+ import type { ProviderId, ReasoningEffort } from 'src/cli/serve/web/llm.ts'
6
+ import { PROVIDERS, type EnhancerSt } from 'src/cli/serve/web/state/EnhancerSt.ts'
7
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
8
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
9
+
10
+ const EFFORTS: ReasoningEffort[] = ['off', 'low', 'medium', 'high']
11
+
12
+ const PROVIDER_LABEL: Record<ProviderId, string> = {
13
+ openrouter: 'openrouter (cloud)',
14
+ openwebui: 'open webui (local)',
15
+ }
16
+
17
+ const Settings = observer(function Settings(p: { e: EnhancerSt }) {
18
+ const models = p.e.visibleModels
19
+ const local = p.e.provider === 'openwebui'
20
+ return (
21
+ <div>
22
+ <div className="section-title">provider · keys stay in this browser</div>
23
+ <div className="enh-row">
24
+ <select value={p.e.provider} onChange={(ev) => p.e.setProvider(ev.target.value)}>
25
+ {PROVIDERS.map((id) => (
26
+ <option key={id} value={id}>
27
+ {PROVIDER_LABEL[id]}
28
+ </option>
29
+ ))}
30
+ </select>
31
+ {local ? (
32
+ <input
33
+ type="text"
34
+ placeholder="http://localhost:3000"
35
+ value={p.e.baseUrl}
36
+ onChange={(ev) => p.e.setBaseUrl(ev.target.value)}
37
+ style={{ flex: 1, minWidth: 180 }}
38
+ />
39
+ ) : null}
40
+ <input
41
+ type="password"
42
+ placeholder={local ? 'open webui api key (blank if none)' : 'sk-or-v1-… (localStorage only)'}
43
+ value={p.e.apiKey}
44
+ onChange={(ev) => p.e.setApiKey(ev.target.value)}
45
+ style={{ flex: 1, minWidth: 160 }}
46
+ />
47
+ <button type="button" onClick={() => void p.e.loadModels()} disabled={p.e.modelsState === 'loading'}>
48
+ {p.e.modelsState === 'loading' ? 'loading…' : 'load models'}
49
+ </button>
50
+ </div>
51
+ <div className="enh-row">
52
+ {models.length > 0 ? (
53
+ <select value={p.e.model} onChange={(ev) => p.e.setModel(ev.target.value)} style={{ flex: 1 }}>
54
+ {/* honest display for an id outside the loaded list (free text, or a filtered-out model) */}
55
+ {models.some((m) => m.id === p.e.model) ? null : (
56
+ <option value={p.e.model}>{p.e.model} (not in the list)</option>
57
+ )}
58
+ {models.map((m) => (
59
+ <option key={m.id} value={m.id}>
60
+ {m.id}
61
+ </option>
62
+ ))}
63
+ </select>
64
+ ) : (
65
+ <input
66
+ type="text"
67
+ placeholder={local ? 'model id, e.g. qwen3:8b' : 'model id, e.g. anthropic/claude-sonnet-5'}
68
+ value={p.e.model}
69
+ onChange={(ev) => p.e.setModel(ev.target.value)}
70
+ style={{ flex: 1 }}
71
+ />
72
+ )}
73
+ <label className="row-inline" title="hide models that report no reasoning support">
74
+ <input type="checkbox" checked={p.e.thinkingOnly} onChange={() => p.e.toggleThinkingOnly()} />
75
+ <span className="hint">thinking only</span>
76
+ </label>
77
+ {local ? null : (
78
+ <label className="row-inline" title="reasoning effort sent to the model">
79
+ <span className="hint">effort</span>
80
+ <select value={p.e.effort} onChange={(ev) => p.e.setEffort(ev.target.value)}>
81
+ {EFFORTS.map((x) => (
82
+ <option key={x} value={x}>
83
+ {x}
84
+ </option>
85
+ ))}
86
+ </select>
87
+ </label>
88
+ )}
89
+ </div>
90
+ {local ? (
91
+ <div className="hint">
92
+ a local model's &lt;think&gt; block is routed to the thinking pane, never into your prompt
93
+ </div>
94
+ ) : null}
95
+ {p.e.modelsError !== '' ? <div className="error">🔴 {p.e.modelsError}</div> : null}
96
+ </div>
97
+ )
98
+ })
99
+
100
+ const MasterPrompt = observer(function MasterPrompt(p: { e: EnhancerSt }) {
101
+ const preset = p.e.preset
102
+ if (preset == null) {
103
+ return (
104
+ <div>
105
+ <div className="section-title">master prompt</div>
106
+ <div className="hint">
107
+ {p.e.presetsState === 'loading' ? 'loading .comfy-ts/prompt-enhancers/…' : 'no master prompt yet'}
108
+ </div>
109
+ {p.e.presetsError !== '' ? <div className="error">🔴 {p.e.presetsError}</div> : null}
110
+ <button type="button" onClick={() => p.e.addPreset('refine-prompt')}>
111
+ create one
112
+ </button>
113
+ </div>
114
+ )
115
+ }
116
+ const rename = (): void => {
117
+ const name = window.prompt('rename this master prompt (renames the file)', preset.name)
118
+ if (name != null) void p.e.renamePreset(name)
119
+ }
120
+ const create = (): void => {
121
+ const name = window.prompt('name the new master prompt', 'refine-<model>-prompt')
122
+ if (name != null) p.e.addPreset(name)
123
+ }
124
+ const remove = (): void => {
125
+ if (window.confirm(`delete master prompt '${preset.name}'? the .md file is removed.`)) void p.e.deletePreset()
126
+ }
127
+ return (
128
+ <div>
129
+ <div className="section-title">
130
+ master prompt · one per image model · .comfy-ts/prompt-enhancers/{preset.name}.md
131
+ </div>
132
+ <div className="enh-row">
133
+ <select value={preset.name} onChange={(ev) => p.e.selectPreset(ev.target.value)} style={{ flex: 1 }}>
134
+ {p.e.presets.map((m) => (
135
+ <option key={m.name} value={m.name}>
136
+ {m.name}
137
+ </option>
138
+ ))}
139
+ </select>
140
+ <button type="button" onClick={create}>
141
+ new
142
+ </button>
143
+ <button type="button" onClick={() => p.e.duplicatePreset()}>
144
+ duplicate
145
+ </button>
146
+ <button type="button" onClick={rename}>
147
+ rename
148
+ </button>
149
+ <button type="button" onClick={remove} title="delete this master prompt file">
150
+ ✕
151
+ </button>
152
+ <span className="hint">
153
+ {p.e.saveState === 'saving' ? 'saving…' : null}
154
+ {p.e.saveState === 'saved' ? 'autosaved to disk' : null}
155
+ {p.e.saveState === 'error' ? `🔴 save failed: ${p.e.saveError}` : null}
156
+ </span>
157
+ </div>
158
+ <textarea rows={8} value={preset.text} onChange={(ev) => p.e.setPresetText(ev.target.value)} />
159
+ </div>
160
+ )
161
+ })
162
+
163
+ const Modal = observer(function Modal(p: { e: EnhancerSt }) {
164
+ const e = p.e
165
+ useEffect(() => {
166
+ const onKey = (ev: KeyboardEvent): void => {
167
+ if (ev.key === 'Escape') e.close()
168
+ if (ev.key === 'Enter' && (ev.metaKey || ev.ctrlKey)) {
169
+ // inside the modal ⌘⏎ refines; VarsForm's generate shortcut stands down while it is open
170
+ ev.preventDefault()
171
+ e.run()
172
+ }
173
+ }
174
+ window.addEventListener('keydown', onKey)
175
+ return () => window.removeEventListener('keydown', onKey)
176
+ }, [e])
177
+ const running = e.phase === 'running'
178
+ return (
179
+ <div className="modal-overlay" onClick={() => e.close()}>
180
+ <div className="modal" onClick={(ev) => ev.stopPropagation()}>
181
+ <div className="modal-head">
182
+ <b style={{ flex: 1 }}>✨ enhance prompt</b>
183
+ <button type="button" onClick={() => e.close()}>
184
+ ✕
185
+ </button>
186
+ </div>
187
+ <div className="modal-body">
188
+ <Settings e={e} />
189
+ <MasterPrompt e={e} />
190
+ <div className="section-title">prompt</div>
191
+ <div className="enh-cols">
192
+ <div>
193
+ <div className="hint">yours (edit before refining, the var is untouched)</div>
194
+ <textarea rows={8} value={e.original} onChange={(ev) => e.setOriginal(ev.target.value)} />
195
+ </div>
196
+ <div>
197
+ <div className="hint">{running ? 'rewriting…' : 'rewritten (editable before apply)'}</div>
198
+ <textarea
199
+ rows={8}
200
+ value={e.result}
201
+ placeholder="hit enhance"
202
+ onChange={(ev) => e.setResult(ev.target.value)}
203
+ />
204
+ </div>
205
+ </div>
206
+ {e.thinking !== '' ? (
207
+ <div>
208
+ <div className="section-title">thinking</div>
209
+ <div className="enh-think">{e.thinking}</div>
210
+ </div>
211
+ ) : null}
212
+ {e.error !== '' ? <div className="error">🔴 {e.error}</div> : null}
213
+ </div>
214
+ <div className="modal-foot">
215
+ {running ? (
216
+ <button type="button" onClick={() => e.cancel()}>
217
+ stop
218
+ </button>
219
+ ) : (
220
+ <button type="button" className="primary" onClick={() => e.run()} title="⌘⏎ / ctrl+⏎">
221
+ enhance
222
+ </button>
223
+ )}
224
+ <button type="button" onClick={() => e.apply()} disabled={e.result.trim() === ''}>
225
+ apply to prompt
226
+ </button>
227
+ <span className="hint" style={{ flex: 1 }}>
228
+ {running ? `${e.result.length} chars streamed` : 'nothing is written until you apply'}
229
+ </span>
230
+ <button type="button" className="link" onClick={() => e.close()}>
231
+ cancel
232
+ </button>
233
+ </div>
234
+ </div>
235
+ </div>
236
+ )
237
+ })
238
+
239
+ export const PromptEnhancer = observer(function PromptEnhancer(p: { v: VarSt; st: WebSt; module: string }) {
240
+ const e = p.st.enhancer
241
+ return (
242
+ <>
243
+ <button
244
+ type="button"
245
+ className="link"
246
+ title="rewrite this prompt with an llm"
247
+ onClick={() => e.openFor({ v: p.v, module: p.module })}
248
+ >
249
+ ✨ enhance
250
+ </button>
251
+ {e.target === p.v ? <Modal e={e} /> : null}
252
+ </>
253
+ )
254
+ })
@@ -0,0 +1,42 @@
1
+ // module → drafts navigation + module load errors, mirrors the TUI tree's job
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
4
+
5
+ export const Sidebar = observer(function Sidebar(p: { st: WebSt }) {
6
+ return (
7
+ <div className="sidebar">
8
+ {p.st.modules.map((mod) => (
9
+ <div key={mod.module}>
10
+ <div className="side-module">
11
+ <span className="name">{mod.module}</span>
12
+ <span className="host">{mod.host}</span>
13
+ </div>
14
+ {mod.drafts.map((draft) => {
15
+ const sel = p.st.form?.moduleKey === mod.module && p.st.form?.draft === draft
16
+ return (
17
+ <button
18
+ key={draft}
19
+ type="button"
20
+ className={sel ? 'side-draft sel' : 'side-draft'}
21
+ onClick={() => void p.st.select({ module: mod.module, draft })}
22
+ >
23
+ {draft}
24
+ </button>
25
+ )
26
+ })}
27
+ </div>
28
+ ))}
29
+ {Object.keys(p.st.loadErrors).length > 0 ? (
30
+ <div className="side-errors">
31
+ <div>failed to load:</div>
32
+ {Object.entries(p.st.loadErrors).map(([file, msg]) => (
33
+ <div key={file}>
34
+ <div className="file">{file}</div>
35
+ <div className="msg">{msg}</div>
36
+ </div>
37
+ ))}
38
+ </div>
39
+ ) : null}
40
+ </div>
41
+ )
42
+ })
@@ -0,0 +1,184 @@
1
+ // the var rows: each kind dispatches to its matching control (the point of the
2
+ // web ui — architecture item 12) + the sticky run bar
3
+ import { observer } from 'mobx-react-lite'
4
+ import { useEffect } from 'react'
5
+ import {
6
+ ChoiceControl,
7
+ NumberControl,
8
+ PromptControl,
9
+ TextControl,
10
+ ToggleControl,
11
+ } from 'src/cli/serve/web/components/controls/BasicControls.tsx'
12
+ import { ImageControl } from 'src/cli/serve/web/components/controls/ImageControl.tsx'
13
+ import { LorasControl } from 'src/cli/serve/web/components/controls/LorasControl.tsx'
14
+ import { SeedControl } from 'src/cli/serve/web/components/controls/SeedControl.tsx'
15
+ import { SizeControl } from 'src/cli/serve/web/components/controls/SizeControl.tsx'
16
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
17
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
18
+
19
+ const VarControl = observer(function VarControl(p: { v: VarSt; host: string; st: WebSt; module: string }) {
20
+ switch (p.v.desc.kind) {
21
+ case 'prompt':
22
+ return <PromptControl v={p.v} st={p.st} module={p.module} />
23
+ case 'text':
24
+ return <TextControl v={p.v} />
25
+ case 'int':
26
+ case 'float':
27
+ return <NumberControl v={p.v} />
28
+ case 'seed':
29
+ return <SeedControl v={p.v} />
30
+ case 'toggle':
31
+ return <ToggleControl v={p.v} />
32
+ case 'choice':
33
+ return <ChoiceControl v={p.v} />
34
+ case 'loras':
35
+ return <LorasControl v={p.v} host={p.host} st={p.st} />
36
+ case 'size':
37
+ return <SizeControl v={p.v} />
38
+ case 'image':
39
+ return <ImageControl v={p.v} />
40
+ default:
41
+ // a newer server may describe a kind this bundle predates: stay usable
42
+ return <div className="hint">unsupported var kind '{p.v.desc.kind}' — use the json api</div>
43
+ }
44
+ })
45
+
46
+ const VarRow = observer(function VarRow(p: { v: VarSt; host: string; st: WebSt; module: string }) {
47
+ return (
48
+ <div className="var-row">
49
+ <div className="var-label">
50
+ {p.v.desc.label ?? p.v.name}
51
+ {p.v.dirty ? (
52
+ <button
53
+ type="button"
54
+ className="dirty-dot"
55
+ title="changed this session — click to restore the loaded value (autosaves)"
56
+ onClick={() => p.v.revert()}
57
+ >
58
+ ●
59
+ </button>
60
+ ) : null}
61
+ <span className="kind">{p.v.desc.kind}</span>
62
+ </div>
63
+ <div className="var-control">
64
+ <VarControl v={p.v} host={p.host} st={p.st} module={p.module} />
65
+ </div>
66
+ </div>
67
+ )
68
+ })
69
+
70
+ /** what is waiting on the host, and the way to drop it */
71
+ const QueuePanel = observer(function QueuePanel(p: { st: WebSt }) {
72
+ const queue = p.st.run.queue
73
+ if (queue.length === 0) return null
74
+ return (
75
+ <div className="queue">
76
+ <div className="queue-head">
77
+ <span>
78
+ queue · {queue.length} prompt{queue.length === 1 ? '' : 's'}
79
+ </span>
80
+ {p.st.run.pendingCount > 0 ? (
81
+ <button type="button" className="link" onClick={() => p.st.run.clearQueue()}>
82
+ clear {p.st.run.pendingCount} pending
83
+ </button>
84
+ ) : null}
85
+ </div>
86
+ {queue.map((e, ix) => (
87
+ <div key={e.id} className="queue-row">
88
+ <span className="queue-ix">{ix + 1}</span>
89
+ <span className="queue-name">
90
+ {e.module}/{e.draft}
91
+ </span>
92
+ {e.sent ? (
93
+ <span className="hint">on the host — past cancelling</span>
94
+ ) : (
95
+ <button type="button" title="drop this queued prompt" onClick={() => p.st.run.removeQueued(e.id)}>
96
+ ✕
97
+ </button>
98
+ )}
99
+ </div>
100
+ ))}
101
+ </div>
102
+ )
103
+ })
104
+
105
+ export const VarsForm = observer(function VarsForm(p: { st: WebSt }) {
106
+ const form = p.st.form
107
+ // ⌘⏎ / ctrl+⏎ submits from anywhere, textarea included (his ask)
108
+ useEffect(() => {
109
+ const onKey = (e: KeyboardEvent): void => {
110
+ // the enhancer modal owns ⌘⏎ while it is open (refine), so a rewrite never queues a run
111
+ if (p.st.enhancer.isOpen) return
112
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
113
+ e.preventDefault()
114
+ p.st.generate()
115
+ }
116
+ }
117
+ window.addEventListener('keydown', onKey)
118
+ return () => window.removeEventListener('keydown', onKey)
119
+ }, [p.st])
120
+ if (form == null) return null
121
+ const duplicate = (): void => {
122
+ const name = window.prompt('duplicate draft as…', `${form.draft} copy`)
123
+ if (name != null) void p.st.duplicateDraft(name)
124
+ }
125
+ return (
126
+ <div>
127
+ <div className="form-head">
128
+ <h2>
129
+ <b>{form.moduleKey}</b> / {form.draft}
130
+ </h2>
131
+ <span className="hint">
132
+ {form.saveState === 'saving' ? 'saving…' : null}
133
+ {form.saveState === 'saved' ? 'autosaved' : null}
134
+ {form.saveState === 'error' ? `🔴 save failed: ${form.saveError}` : null}
135
+ </span>
136
+ <button type="button" className="link" title="save these values as a new draft" onClick={duplicate}>
137
+ duplicate…
138
+ </button>
139
+ <button
140
+ type="button"
141
+ className="link danger"
142
+ title="delete this draft's file (default resets to the workflow's own values)"
143
+ onClick={() => {
144
+ if (window.confirm(`delete draft '${form.draft}' of ${form.moduleKey}? the file is removed.`))
145
+ void p.st.deleteDraft({ module: form.moduleKey, draft: form.draft })
146
+ }}
147
+ >
148
+ delete
149
+ </button>
150
+ </div>
151
+ {form.vars.map((v) => (
152
+ // keyed by DRAFT too: a draft switch must reset per-row ui state (lora filter,
153
+ // remembered strengths), not carry the other draft's over
154
+ <VarRow key={`${form.draft}/${v.name}`} v={v} host={form.host} st={p.st} module={form.moduleKey} />
155
+ ))}
156
+ <div className="runbar">
157
+ <button
158
+ type="button"
159
+ className={p.st.run.isRunning ? 'primary pulse' : 'primary'}
160
+ title="⌘⏎ / ctrl+⏎ — click again to queue another"
161
+ onClick={() => p.st.generate()}
162
+ >
163
+ {p.st.run.isRunning
164
+ ? p.st.run.progressPercent != null
165
+ ? `generating… ${Math.round(p.st.run.progressPercent)}%`
166
+ : 'generating…'
167
+ : 'generate'}
168
+ </button>
169
+ <span className="status">
170
+ {form.dirtyCount === 0
171
+ ? 'draft values'
172
+ : `${form.dirtyCount} var${form.dirtyCount > 1 ? 's' : ''} changed this session`}
173
+ </span>
174
+ {form.dirtyCount > 0 ? (
175
+ <button type="button" className="link" onClick={() => form.revertAll()}>
176
+ revert all
177
+ </button>
178
+ ) : null}
179
+ {p.st.run.error != null ? <span className="error">🔴 {p.st.run.error}</span> : null}
180
+ </div>
181
+ <QueuePanel st={p.st} />
182
+ </div>
183
+ )
184
+ })
@@ -0,0 +1,95 @@
1
+ // the small per-kind controls: prompt, text, int/float, toggle, choice —
2
+ // bigger kinds (seed, size, loras, image) have their own files
3
+ import { observer } from 'mobx-react-lite'
4
+ import { PromptEnhancer } from 'src/cli/serve/web/components/PromptEnhancer.tsx'
5
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
6
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
7
+
8
+ export const PromptControl = observer(function PromptControl(p: { v: VarSt; st: WebSt; module: string }) {
9
+ const text = typeof p.v.value === 'string' ? p.v.value : ''
10
+ const rows = Math.min(12, Math.max(4, text.split('\n').length + 1))
11
+ return (
12
+ <div>
13
+ <textarea rows={rows} value={text} onChange={(e) => p.v.set(e.target.value)} />
14
+ <div className="row-inline">
15
+ <span className="hint">// line = comment · "- " line = negative prompt</span>
16
+ <PromptEnhancer v={p.v} st={p.st} module={p.module} />
17
+ </div>
18
+ </div>
19
+ )
20
+ })
21
+
22
+ export const TextControl = observer(function TextControl(p: { v: VarSt }) {
23
+ return (
24
+ <input
25
+ type="text"
26
+ value={typeof p.v.value === 'string' ? p.v.value : ''}
27
+ onChange={(e) => p.v.set(e.target.value)}
28
+ />
29
+ )
30
+ })
31
+
32
+ export const NumberControl = observer(function NumberControl(p: { v: VarSt }) {
33
+ const isInt = p.v.desc.kind === 'int'
34
+ const num = typeof p.v.value === 'number' ? p.v.value : 0
35
+ const min = p.v.desc.min
36
+ const max = p.v.desc.max
37
+ const apply = (raw: string): void => {
38
+ const n = isInt ? parseInt(raw, 10) : parseFloat(raw)
39
+ if (Number.isFinite(n)) p.v.set(n)
40
+ }
41
+ return (
42
+ <div className="row-inline">
43
+ <input
44
+ type="number"
45
+ value={num}
46
+ step={isInt ? 1 : 'any'}
47
+ min={min}
48
+ max={max}
49
+ onChange={(e) => apply(e.target.value)}
50
+ />
51
+ {min != null && max != null ? (
52
+ <input
53
+ type="range"
54
+ style={{ flex: 1, minWidth: 120 }}
55
+ value={num}
56
+ min={min}
57
+ max={max}
58
+ step={isInt ? 1 : (max - min) / 200}
59
+ onChange={(e) => apply(e.target.value)}
60
+ />
61
+ ) : null}
62
+ {min != null || max != null ? <span className="hint">{`${min ?? '-∞'} … ${max ?? '∞'}`}</span> : null}
63
+ </div>
64
+ )
65
+ })
66
+
67
+ export const ToggleControl = observer(function ToggleControl(p: { v: VarSt }) {
68
+ return (
69
+ <label className="row-inline" style={{ cursor: 'pointer' }}>
70
+ <input type="checkbox" checked={p.v.value === true} onChange={(e) => p.v.set(e.target.checked)} />
71
+ <span className="hint">{p.v.value === true ? 'on' : 'off'}</span>
72
+ </label>
73
+ )
74
+ })
75
+
76
+ export const ChoiceControl = observer(function ChoiceControl(p: { v: VarSt }) {
77
+ const choices = p.v.desc.choices ?? []
78
+ const value = typeof p.v.value === 'string' ? p.v.value : ''
79
+ return (
80
+ <select value={value} onChange={(e) => p.v.set(e.target.value)}>
81
+ {/* honest display for a value outside the current union (stale draft): the
82
+ browser would silently SHOW the first option while the state differs */}
83
+ {choices.includes(value) ? null : (
84
+ <option value={value} disabled>
85
+ {value === '' ? '(unset)' : `${value} (not on this host)`}
86
+ </option>
87
+ )}
88
+ {choices.map((c) => (
89
+ <option key={c} value={c}>
90
+ {c}
91
+ </option>
92
+ ))}
93
+ </select>
94
+ )
95
+ })
@@ -0,0 +1,71 @@
1
+ // image: a path/url input the api already accepts, plus a browser upload
2
+ // (POST /upload → local file under outputs/serve-inputs/) and a preview when
3
+ // the value is browser-reachable
4
+ import { observer } from 'mobx-react-lite'
5
+ import { useRef } from 'react'
6
+ import { uploadFile } from 'src/cli/serve/web/api.ts'
7
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
8
+
9
+ export const ImageControl = observer(function ImageControl(p: { v: VarSt }) {
10
+ const fileInput = useRef<HTMLInputElement>(null)
11
+ const value = typeof p.v.value === 'string' ? p.v.value : ''
12
+ const previewUrl = /^https?:\/\//.test(value) ? value : p.v.uploadedUrl
13
+ const extensions = p.v.desc.extensions ?? []
14
+ const onFile = async (file: File | undefined): Promise<void> => {
15
+ if (file == null) return
16
+ try {
17
+ const reply = await uploadFile({ file })
18
+ p.v.set(reply.path)
19
+ p.v.setUploadedUrl(reply.url)
20
+ } catch (e) {
21
+ // loud both ways: the row hint cannot show async errors, alert can
22
+ alert(`upload failed: ${e instanceof Error ? e.message : String(e)}`)
23
+ }
24
+ }
25
+ return (
26
+ <div>
27
+ <div className="row-inline">
28
+ <input
29
+ type="text"
30
+ style={{ flex: 1 }}
31
+ placeholder="local path or http(s) url"
32
+ value={value}
33
+ onChange={(e) => {
34
+ p.v.set(e.target.value)
35
+ p.v.setUploadedUrl(null)
36
+ }}
37
+ />
38
+ <button type="button" onClick={() => fileInput.current?.click()}>
39
+ upload…
40
+ </button>
41
+ {value !== '' ? (
42
+ <button
43
+ type="button"
44
+ title="clear the image"
45
+ onClick={() => {
46
+ p.v.set('')
47
+ p.v.setUploadedUrl(null)
48
+ }}
49
+ >
50
+ ✕
51
+ </button>
52
+ ) : null}
53
+ <input
54
+ ref={fileInput}
55
+ type="file"
56
+ accept={extensions.map((ext) => `.${ext}`).join(',')}
57
+ style={{ display: 'none' }}
58
+ onChange={(e) => {
59
+ void onFile(e.target.files?.[0])
60
+ e.target.value = ''
61
+ }}
62
+ />
63
+ </div>
64
+ {previewUrl != null && previewUrl !== '' ? (
65
+ <div className="img-preview">
66
+ <img src={previewUrl} alt={value} />
67
+ </div>
68
+ ) : null}
69
+ </div>
70
+ )
71
+ })