comfy-ts 2.11.0 → 2.13.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 (122) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-qtFzOKpu.js → LogsSt-CUeo843w.js} +51 -7
  3. package/dist/LogsSt-CUeo843w.js.map +1 -0
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +595 -73
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +286 -46
  8. package/dist/index.d.ts +286 -46
  9. package/dist/index.js +591 -74
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-BK7BA2dn.js → run-serve-DlRBv_Nk.js} +738 -58
  12. package/dist/run-serve-DlRBv_Nk.js.map +1 -0
  13. package/dist/{run-tui-CQyvMf0N.js → run-tui-B5uxm2_l.js} +43 -18
  14. package/dist/run-tui-B5uxm2_l.js.map +1 -0
  15. package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-E95iTF7E.js} +473 -60
  16. package/dist/schemaDrift-E95iTF7E.js.map +1 -0
  17. package/dist/serve-web.js +710 -174
  18. package/dist/{state--wrz0BQc.js → state-CUp2J1Zy.js} +126 -14
  19. package/dist/state-CUp2J1Zy.js.map +1 -0
  20. package/dist/web.d.ts +286 -46
  21. package/dist/web.js +591 -74
  22. package/dist/web.js.map +1 -1
  23. package/examples/comfy-cloud/sdk.d.ts +163 -163
  24. package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
  25. package/examples/rvion/10-anima-t2i.cflow.ts +252 -0
  26. package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
  27. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
  28. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
  29. package/examples/rvion/stableAudio3Prompts.ts +19 -0
  30. package/extra/README.md +4 -0
  31. package/extra/comfyui-fresh-model-lists/README.md +25 -0
  32. package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
  33. package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
  34. package/package.json +15 -7
  35. package/src/cli/draftMeta.ts +39 -0
  36. package/src/cli/serve/ServeApp.ts +305 -30
  37. package/src/cli/serve/applyVarPayload.ts +50 -22
  38. package/src/cli/serve/byteRange.ts +48 -0
  39. package/src/cli/serve/describeVar.ts +42 -6
  40. package/src/cli/serve/llmConfigShape.ts +51 -0
  41. package/src/cli/serve/llmConfigs.ts +52 -0
  42. package/src/cli/serve/run-serve.ts +12 -3
  43. package/src/cli/serve/tagList.ts +92 -0
  44. package/src/cli/serve/tagSource.ts +69 -0
  45. package/src/cli/serve/web/api.ts +72 -0
  46. package/src/cli/serve/web/components/App.tsx +485 -44
  47. package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
  48. package/src/cli/serve/web/components/Gallery.tsx +133 -31
  49. package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
  50. package/src/cli/serve/web/components/Icon.tsx +58 -2
  51. package/src/cli/serve/web/components/MenuButton.tsx +53 -0
  52. package/src/cli/serve/web/components/Omnibox.tsx +135 -0
  53. package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
  54. package/src/cli/serve/web/components/SideMenu.tsx +414 -0
  55. package/src/cli/serve/web/components/TooltipLayer.tsx +46 -0
  56. package/src/cli/serve/web/components/VarIcon.tsx +24 -0
  57. package/src/cli/serve/web/components/VarsForm.tsx +223 -351
  58. package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
  59. package/src/cli/serve/web/components/controls/LorasControl.tsx +646 -317
  60. package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
  61. package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
  62. package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
  63. package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
  64. package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
  65. package/src/cli/serve/web/components/modKey.ts +2 -0
  66. package/src/cli/serve/web/llm.ts +23 -12
  67. package/src/cli/serve/web/promptEditor/promptExtensions.ts +284 -0
  68. package/src/cli/serve/web/state/EnhancerSt.ts +431 -101
  69. package/src/cli/serve/web/state/FormSt.ts +214 -30
  70. package/src/cli/serve/web/state/OmniboxSt.ts +59 -0
  71. package/src/cli/serve/web/state/WebSt.ts +364 -80
  72. package/src/cli/serve/web/state/choiceButtons.ts +61 -0
  73. package/src/cli/serve/web/state/draftNames.ts +16 -0
  74. package/src/cli/serve/web/state/draftTabs.ts +75 -0
  75. package/src/cli/serve/web/state/generateButton.ts +16 -0
  76. package/src/cli/serve/web/state/history.ts +54 -0
  77. package/src/cli/serve/web/state/host.ts +5 -2
  78. package/src/cli/serve/web/state/keptLines.ts +53 -0
  79. package/src/cli/serve/web/state/latentMode.ts +20 -0
  80. package/src/cli/serve/web/state/loraSort.ts +18 -0
  81. package/src/cli/serve/web/state/moduleTree.ts +2 -2
  82. package/src/cli/serve/web/state/omnibox.ts +133 -0
  83. package/src/cli/serve/web/state/payload.ts +38 -58
  84. package/src/cli/serve/web/state/shortcuts.ts +103 -0
  85. package/src/cli/serve/web/state/sizeStars.ts +31 -0
  86. package/src/cli/serve/web/state/stableSlots.ts +21 -0
  87. package/src/cli/serve/web/state/varGroups.ts +24 -0
  88. package/src/cli/serve/web/styles.ts +653 -154
  89. package/src/cli/serve/webBundle.ts +54 -10
  90. package/src/cli/serve/workflowTags.ts +42 -0
  91. package/src/cli/serve/workspaceLabels.ts +23 -0
  92. package/src/cli/tui/components/PickerOverlays.tsx +9 -2
  93. package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
  94. package/src/cli/tui/state/DraftsSt.ts +28 -8
  95. package/src/cli/tui/state/EditorSt.ts +1 -1
  96. package/src/cli/tui/state/LorasSt.ts +1 -1
  97. package/src/cli/tui/state/PickerSt.ts +25 -7
  98. package/src/cli/tui/state/SettingsSt.ts +1 -1
  99. package/src/cli/tui/state/TuiSt.ts +10 -0
  100. package/src/coreExports.ts +21 -0
  101. package/src/host/ComfyHost.ts +17 -2
  102. package/src/host/ResilientWebsocket.ts +54 -4
  103. package/src/host/loraInfoCache.ts +6 -0
  104. package/src/runner/ComfyExecution.ts +60 -0
  105. package/src/runner/ComfyWorkflow.ts +4 -0
  106. package/src/runner/ComfyWsApi.ts +2 -0
  107. package/src/runner/MediaImage.ts +2 -2
  108. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
  109. package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
  110. package/src/state.ts +5 -0
  111. package/src/utils/copyName.ts +12 -0
  112. package/src/vars/ComfyVars.ts +337 -67
  113. package/src/vars/DefinedWorkflow.ts +47 -20
  114. package/src/vars/lanes.ts +238 -0
  115. package/src/vars/loraEntry.ts +101 -0
  116. package/src/vars/promptSyntax.ts +382 -0
  117. package/dist/LogsSt-qtFzOKpu.js.map +0 -1
  118. package/dist/run-serve-BK7BA2dn.js.map +0 -1
  119. package/dist/run-tui-CQyvMf0N.js.map +0 -1
  120. package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
  121. package/dist/state--wrz0BQc.js.map +0 -1
  122. package/src/cli/serve/web/components/Sidebar.tsx +0 -66
@@ -1,28 +1,252 @@
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.
1
+ // ✨ on a prompt row → the refine modal: the LLM configs and the master prompts as two lists of
2
+ // vertical tabs on the left, the job (yours → rewrite) alone on the right. A tab's pen opens its
3
+ // editor over the job. Nothing touches the var until APPLY.
3
4
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
4
5
  import { observer } from 'mobx-react-lite'
5
- import { useEffect } from 'react'
6
+ import { useEffect, useRef, type ReactNode } from 'react'
7
+ import { MOD_KEY } from 'src/cli/serve/web/components/modKey.ts'
8
+ import { HistoryButton } from 'src/cli/serve/web/components/HistoryPicker.tsx'
6
9
  import type { ProviderId, ReasoningEffort } from 'src/cli/serve/web/llm.ts'
7
- import { PROVIDERS, type EnhancerSt } from 'src/cli/serve/web/state/EnhancerSt.ts'
10
+ import { PROVIDERS, type EnhancerSt, type SaveState } from 'src/cli/serve/web/state/EnhancerSt.ts'
8
11
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
9
12
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
13
+ import {
14
+ ENHANCER_KEYS,
15
+ enhancerShortcutOf,
16
+ SHORTCUT_KEYS,
17
+ type EnhancerShortcut,
18
+ } from 'src/cli/serve/web/state/shortcuts.ts'
10
19
 
11
20
  const EFFORTS: ReasoningEffort[] = ['off', 'low', 'medium', 'high']
12
21
 
13
22
  const PROVIDER_LABEL: Record<ProviderId, string> = {
14
23
  openrouter: 'openrouter (cloud)',
15
24
  openwebui: 'open webui (local)',
25
+ openai: 'llama.cpp / ollama / vllm (openai /v1)',
16
26
  }
17
27
 
18
- const Settings = observer(function Settings(p: { e: EnhancerSt }) {
19
- const models = p.e.visibleModels
20
- const local = p.e.provider === 'openwebui'
28
+ const BASE_PLACEHOLDER: Record<ProviderId, string> = {
29
+ openrouter: '',
30
+ openwebui: 'http://localhost:3000',
31
+ openai: 'http://localhost:8080/v1',
32
+ }
33
+
34
+ /** one library of named files (LLM configs, master prompts) as VERTICAL TABS: click a tab to
35
+ * select it, its pen opens its editor over the job, `+ new` closes the list. On a narrow
36
+ * screen the same list is a dropdown (css swaps them) */
37
+ const TabList = observer(function TabList(p: {
38
+ title: string
39
+ names: string[]
40
+ selected: string
41
+ kind: string
42
+ newName: string
43
+ save: SaveState
44
+ saveError: string
45
+ /** its editor is open over the job */
46
+ editing: boolean
47
+ onEdit(): void
48
+ /** a dot before the name (the LLM's up/down), absent = none */
49
+ status?: (name: string) => { cls: string; tip: string } | null
50
+ onSelect(name: string): void
51
+ onCreate(name: string): void
52
+ }) {
53
+ const create = (): void => {
54
+ const name = window.prompt(`name the new ${p.kind}`, p.newName)
55
+ if (name != null) p.onCreate(name)
56
+ }
57
+ const dot = (name: string): ReactNode => {
58
+ const st = p.status?.(name) ?? null
59
+ return st == null ? null : <span className={`enh-dot ${st.cls}`} data-tip={st.tip} />
60
+ }
61
+ return (
62
+ <div className="enh-tabs">
63
+ <div className="enh-tabs-title">
64
+ {p.title}
65
+ {p.save === 'saving' ? <span className="enh-save">saving…</span> : null}
66
+ {p.save === 'error' ? (
67
+ <span className="enh-save error" data-tip={p.saveError}>
68
+ 🔴 not saved
69
+ </span>
70
+ ) : null}
71
+ </div>
72
+ <select className="enh-tab-select" value={p.selected} onChange={(ev) => p.onSelect(ev.target.value)}>
73
+ {p.names.map((n) => (
74
+ <option key={n} value={n}>
75
+ {n}
76
+ </option>
77
+ ))}
78
+ </select>
79
+ <div className="enh-tab-list" role="tablist">
80
+ {p.names.map((n) => (
81
+ <div key={n} className={n === p.selected ? 'enh-tab sel' : 'enh-tab'}>
82
+ <button type="button" role="tab" aria-selected={n === p.selected} onClick={() => p.onSelect(n)}>
83
+ {dot(n)}
84
+ <span className="enh-tab-name">{n}</span>
85
+ </button>
86
+ {n === p.selected ? (
87
+ <button
88
+ type="button"
89
+ className={p.editing ? 'enh-tab-edit sel' : 'enh-tab-edit'}
90
+ data-tip={p.editing ? 'close the editor' : `edit this ${p.kind}`}
91
+ onClick={() => p.onEdit()}
92
+ >
93
+ <Icon name="pen" />
94
+ </button>
95
+ ) : null}
96
+ </div>
97
+ ))}
98
+ <button type="button" className="enh-tab-new" onClick={create}>
99
+ <Icon name="plus" /> new {p.kind}
100
+ </button>
101
+ </div>
102
+ </div>
103
+ )
104
+ })
105
+
106
+ const Side = observer(function Side(p: { e: EnhancerSt }) {
107
+ const e = p.e
108
+ const entry = e.configEntry
109
+ const preset = e.preset
110
+ return (
111
+ <nav className="enh-side">
112
+ {entry == null ? (
113
+ <div className="enh-tabs">
114
+ <div className="enh-tabs-title">llm</div>
115
+ <button type="button" className="enh-tab-new" onClick={() => e.setEditing('llm')}>
116
+ <Icon name="plus" /> set up an llm
117
+ </button>
118
+ </div>
119
+ ) : (
120
+ <TabList
121
+ title="llm"
122
+ names={e.configs.map((c) => c.name)}
123
+ selected={entry.name}
124
+ kind="llm"
125
+ newName="my-llm"
126
+ save={e.configSaveState}
127
+ saveError={e.configSaveError}
128
+ editing={e.editing === 'llm'}
129
+ onEdit={() => e.setEditing(e.editing === 'llm' ? null : 'llm')}
130
+ status={(name) => {
131
+ const st = e.configStatus.get(name)
132
+ if (st == null) return null
133
+ const err = e.configStatusError.get(name)
134
+ return {
135
+ cls: st,
136
+ tip: st === 'up' ? 'answers' : st === 'checking' ? 'checking…' : `does not answer: ${err ?? ''}`,
137
+ }
138
+ }}
139
+ onSelect={(n) => e.selectConfig(n)}
140
+ onCreate={(n) => {
141
+ e.addConfig(n)
142
+ e.setEditing('llm')
143
+ }}
144
+ />
145
+ )}
146
+ {preset == null ? (
147
+ <div className="enh-tabs">
148
+ <div className="enh-tabs-title">master prompt</div>
149
+ <button type="button" className="enh-tab-new" onClick={() => e.addPreset('refine-prompt')}>
150
+ <Icon name="plus" /> new master prompt
151
+ </button>
152
+ </div>
153
+ ) : (
154
+ <TabList
155
+ title="master prompt"
156
+ names={e.presets.map((m) => m.name)}
157
+ selected={preset.name}
158
+ kind="master prompt"
159
+ newName="refine-<model>-prompt"
160
+ save={e.saveState}
161
+ saveError={e.saveError}
162
+ editing={e.editing === 'preset'}
163
+ onEdit={() => e.setEditing(e.editing === 'preset' ? null : 'preset')}
164
+ onSelect={(n) => e.selectPreset(n)}
165
+ onCreate={(n) => {
166
+ e.addPreset(n)
167
+ e.setEditing('preset')
168
+ }}
169
+ />
170
+ )}
171
+ </nav>
172
+ )
173
+ })
174
+
175
+ /** the editor over the job: a title with the entry's name, its file actions, its fields */
176
+ function EditPanel(p: {
177
+ kind: string
178
+ name: string | null
179
+ tip?: string
180
+ onRename(name: string): void
181
+ onDuplicate(): void
182
+ onDelete(): void
183
+ onClose(): void
184
+ children: ReactNode
185
+ }): ReactNode {
186
+ const rename = (): void => {
187
+ if (p.name == null) return
188
+ const name = window.prompt(`rename this ${p.kind} (renames the file)`, p.name)
189
+ if (name != null) p.onRename(name)
190
+ }
191
+ const remove = (): void => {
192
+ if (p.name == null) return
193
+ if (window.confirm(`delete ${p.kind} '${p.name}'? its file is removed.`)) p.onDelete()
194
+ }
21
195
  return (
22
- <div>
23
- <div className="section-title">provider · keys stay in this browser</div>
24
- <div className="enh-row">
25
- <select value={p.e.provider} onChange={(ev) => p.e.setProvider(ev.target.value)}>
196
+ <section className="enh-edit">
197
+ <div className="enh-edit-head">
198
+ <h3 className="enh-h" data-tip={p.tip}>
199
+ {p.kind} <span className="enh-h-name">{p.name ?? 'new'}</span>
200
+ </h3>
201
+ {p.name == null ? null : (
202
+ <span className="btn-group">
203
+ <button type="button" onClick={() => p.onDuplicate()}>
204
+ duplicate
205
+ </button>
206
+ <button type="button" onClick={rename}>
207
+ rename
208
+ </button>
209
+ <button type="button" className="quiet-danger" onClick={remove}>
210
+ <Icon name="trash" /> delete
211
+ </button>
212
+ </span>
213
+ )}
214
+ <button
215
+ type="button"
216
+ className="enh-edit-close"
217
+ data-tip="done (esc), everything is already saved"
218
+ onClick={() => p.onClose()}
219
+ >
220
+ done
221
+ </button>
222
+ </div>
223
+ <div className="enh-edit-body">{p.children}</div>
224
+ </section>
225
+ )
226
+ }
227
+
228
+ const LlmSettings = observer(function LlmSettings(p: { e: EnhancerSt }) {
229
+ const e = p.e
230
+ const models = e.visibleModels
231
+ const local = e.provider !== 'openrouter'
232
+ const entry = e.configEntry
233
+ return (
234
+ <EditPanel
235
+ kind="llm"
236
+ name={entry?.name ?? null}
237
+ tip={
238
+ entry == null
239
+ ? 'any edit creates the config file'
240
+ : `.comfy-ts/llm-configs/${entry.name}.json, saved as you type`
241
+ }
242
+ onRename={(n) => void e.renameConfig(n)}
243
+ onDuplicate={() => e.duplicateConfig()}
244
+ onDelete={() => void e.deleteConfig()}
245
+ onClose={() => e.setEditing(null)}
246
+ >
247
+ <div className="enh-grid">
248
+ <label>provider</label>
249
+ <select value={e.provider} onChange={(ev) => e.setProvider(ev.target.value)}>
26
250
  {PROVIDERS.map((id) => (
27
251
  <option key={id} value={id}>
28
252
  {PROVIDER_LABEL[id]}
@@ -30,228 +254,300 @@ const Settings = observer(function Settings(p: { e: EnhancerSt }) {
30
254
  ))}
31
255
  </select>
32
256
  {local ? (
33
- <input
34
- type="text"
35
- placeholder="http://localhost:3000"
36
- value={p.e.baseUrl}
37
- onChange={(ev) => p.e.setBaseUrl(ev.target.value)}
38
- style={{ flex: 1, minWidth: 180 }}
39
- />
257
+ <>
258
+ <label>address</label>
259
+ <input
260
+ type="text"
261
+ placeholder={BASE_PLACEHOLDER[e.provider]}
262
+ value={e.baseUrl}
263
+ onChange={(ev) => e.setBaseUrl(ev.target.value)}
264
+ />
265
+ </>
40
266
  ) : null}
267
+ <label data-tip="kept in this browser only, never in a file">api key</label>
41
268
  <input
42
269
  type="password"
43
- placeholder={local ? 'open webui api key (blank if none)' : 'sk-or-v1-… (localStorage only)'}
44
- value={p.e.apiKey}
45
- onChange={(ev) => p.e.setApiKey(ev.target.value)}
46
- style={{ flex: 1, minWidth: 160 }}
270
+ placeholder={local ? 'blank if none' : 'sk-or-v1-…'}
271
+ value={e.apiKey}
272
+ onChange={(ev) => e.setApiKey(ev.target.value)}
47
273
  />
48
- <button type="button" onClick={() => void p.e.loadModels()} disabled={p.e.modelsState === 'loading'}>
49
- {p.e.modelsState === 'loading' ? 'loading…' : 'load models'}
50
- </button>
51
- </div>
52
- <div className="enh-row">
53
- {models.length > 0 ? (
54
- <select value={p.e.model} onChange={(ev) => p.e.setModel(ev.target.value)} style={{ flex: 1 }}>
55
- {/* honest display for an id outside the loaded list (free text, or a filtered-out model) */}
56
- {models.some((m) => m.id === p.e.model) ? null : (
57
- <option value={p.e.model}>{p.e.model} (not in the list)</option>
58
- )}
59
- {models.map((m) => (
60
- <option key={m.id} value={m.id}>
61
- {m.id}
62
- </option>
63
- ))}
64
- </select>
65
- ) : (
66
- <input
67
- type="text"
68
- placeholder={local ? 'model id, e.g. qwen3:8b' : 'model id, e.g. anthropic/claude-sonnet-5'}
69
- value={p.e.model}
70
- onChange={(ev) => p.e.setModel(ev.target.value)}
71
- style={{ flex: 1 }}
72
- />
73
- )}
74
- <label className="row-inline" data-tip="hide models that report no reasoning support">
75
- <input type="checkbox" checked={p.e.thinkingOnly} onChange={() => p.e.toggleThinkingOnly()} />
76
- <span className="hint">thinking only</span>
77
- </label>
78
- {local ? null : (
79
- <label className="row-inline" data-tip="reasoning effort sent to the model">
80
- <span className="hint">effort</span>
81
- <select value={p.e.effort} onChange={(ev) => p.e.setEffort(ev.target.value)}>
82
- {EFFORTS.map((x) => (
83
- <option key={x} value={x}>
84
- {x}
274
+ <label>model</label>
275
+ <div className="enh-inline">
276
+ {models.length > 0 ? (
277
+ <select value={e.model} onChange={(ev) => e.setModel(ev.target.value)}>
278
+ {models.some((m) => m.id === e.model) ? null : (
279
+ <option value={e.model}>{e.model} (not in the list)</option>
280
+ )}
281
+ {models.map((m) => (
282
+ <option key={m.id} value={m.id}>
283
+ {m.id}
85
284
  </option>
86
285
  ))}
87
286
  </select>
88
- </label>
287
+ ) : (
288
+ <input
289
+ type="text"
290
+ placeholder={local ? 'e.g. qwen3:8b' : 'e.g. anthropic/claude-sonnet-5'}
291
+ value={e.model}
292
+ onChange={(ev) => e.setModel(ev.target.value)}
293
+ />
294
+ )}
295
+ <button type="button" onClick={() => void e.loadModels()} disabled={e.modelsState === 'loading'}>
296
+ {e.modelsState === 'loading' ? 'asking…' : 'list models'}
297
+ </button>
298
+ </div>
299
+ {e.provider === 'openwebui' ? null : (
300
+ <>
301
+ <label
302
+ data-tip={
303
+ local
304
+ ? 'off = no thinking (chat template switch), anything else = think first'
305
+ : 'reasoning effort sent to the model'
306
+ }
307
+ >
308
+ thinking
309
+ </label>
310
+ <div className="enh-inline">
311
+ <span className="btn-group">
312
+ {EFFORTS.map((x) => (
313
+ <button
314
+ key={x}
315
+ type="button"
316
+ className={e.effort === x ? 'mode sel' : 'mode'}
317
+ onClick={() => e.setEffort(x)}
318
+ >
319
+ {x}
320
+ </button>
321
+ ))}
322
+ </span>
323
+ <label className="row-inline" data-tip="hide models that report no reasoning support">
324
+ <input type="checkbox" checked={e.thinkingOnly} onChange={() => e.toggleThinkingOnly()} />
325
+ thinking models only
326
+ </label>
327
+ </div>
328
+ </>
89
329
  )}
90
330
  </div>
91
- {local ? (
92
- <div className="hint">
93
- a local model's &lt;think&gt; block is routed to the thinking pane, never into your prompt
94
- </div>
95
- ) : null}
96
- {p.e.modelsError !== '' ? <div className="error">🔴 {p.e.modelsError}</div> : null}
97
- </div>
331
+ {e.modelsError !== '' ? <div className="error">🔴 {e.modelsError}</div> : null}
332
+ {e.configsError !== '' ? <div className="error">🔴 {e.configsError}</div> : null}
333
+ </EditPanel>
98
334
  )
99
335
  })
100
336
 
101
337
  const MasterPrompt = observer(function MasterPrompt(p: { e: EnhancerSt }) {
102
338
  const preset = p.e.preset
103
- if (preset == null) {
104
- return (
105
- <div>
106
- <div className="section-title">master prompt</div>
107
- <div className="hint">
108
- {p.e.presetsState === 'loading' ? 'loading .comfy-ts/prompt-enhancers/…' : 'no master prompt yet'}
339
+ return (
340
+ <EditPanel
341
+ kind="master prompt"
342
+ name={preset?.name ?? null}
343
+ tip={preset == null ? undefined : `.comfy-ts/prompt-enhancers/${preset.name}.md, saved as you type`}
344
+ onRename={(n) => void p.e.renamePreset(n)}
345
+ onDuplicate={() => p.e.duplicatePreset()}
346
+ onDelete={() => void p.e.deletePreset()}
347
+ onClose={() => p.e.setEditing(null)}
348
+ >
349
+ {preset == null ? (
350
+ <div className="enh-empty">
351
+ {p.e.presetsState === 'loading' ? 'loading…' : 'no master prompt yet: add one on the left'}
109
352
  </div>
110
- {p.e.presetsError !== '' ? <div className="error">🔴 {p.e.presetsError}</div> : null}
111
- <button type="button" onClick={() => p.e.addPreset('refine-prompt')}>
112
- create one
113
- </button>
114
- </div>
115
- )
116
- }
117
- const rename = (): void => {
118
- const name = window.prompt('rename this master prompt (renames the file)', preset.name)
119
- if (name != null) void p.e.renamePreset(name)
120
- }
121
- const create = (): void => {
122
- const name = window.prompt('name the new master prompt', 'refine-<model>-prompt')
123
- if (name != null) p.e.addPreset(name)
124
- }
125
- const remove = (): void => {
126
- if (window.confirm(`delete master prompt '${preset.name}'? the .md file is removed.`)) void p.e.deletePreset()
127
- }
353
+ ) : (
354
+ <textarea
355
+ className="enh-text enh-master"
356
+ rows={18}
357
+ value={preset.text}
358
+ onChange={(ev) => p.e.setPresetText(ev.target.value)}
359
+ />
360
+ )}
361
+ {p.e.presetsError !== '' ? <div className="error">🔴 {p.e.presetsError}</div> : null}
362
+ </EditPanel>
363
+ )
364
+ })
365
+
366
+ /** the job, top to bottom: the actions, then yours, then the rewrite. The two boxes share the
367
+ * height the modal has, so nothing scrolls and nothing below the buttons ever moves them */
368
+ const Job = observer(function Job(p: { e: EnhancerSt; st: WebSt }) {
369
+ const e = p.e
370
+ const running = e.phase === 'running'
371
+ // opening the enhancer puts you IN the input, the cursor after its last character: the next
372
+ // thing you do is type or press ⌘E
373
+ const inputRef = useRef<HTMLTextAreaElement>(null)
374
+ useEffect(() => {
375
+ const el = inputRef.current
376
+ if (el == null) return
377
+ el.focus()
378
+ el.setSelectionRange(el.value.length, el.value.length)
379
+ }, [])
380
+ const act = actions(e)
381
+ const kbd = (s: EnhancerShortcut): ReactNode => (
382
+ <span className="kbd-hint">
383
+ {MOD_KEY}
384
+ {ENHANCER_KEYS[s]}
385
+ </span>
386
+ )
387
+ const noResult = e.result.trim() === ''
128
388
  return (
129
- <div>
130
- <div className="section-title">
131
- master prompt · one per image model · .comfy-ts/prompt-enhancers/{preset.name}.md
132
- </div>
133
- <div className="enh-row">
134
- <select value={preset.name} onChange={(ev) => p.e.selectPreset(ev.target.value)} style={{ flex: 1 }}>
135
- {p.e.presets.map((m) => (
136
- <option key={m.name} value={m.name}>
137
- {m.name}
138
- </option>
139
- ))}
140
- </select>
141
- <button type="button" onClick={create}>
142
- new
143
- </button>
144
- <button type="button" onClick={() => p.e.duplicatePreset()}>
145
- duplicate
146
- </button>
147
- <button type="button" onClick={rename}>
148
- rename
389
+ <section className="enh-job">
390
+ <div className="enh-actions">
391
+ {/* one width for enhance and stop, so the swap never moves apply */}
392
+ {running ? (
393
+ <button type="button" className="enh-big enh-go" onClick={() => e.cancel()}>
394
+ stop
395
+ </button>
396
+ ) : (
397
+ <button type="button" className="primary enh-big enh-go" onClick={act.enhance}>
398
+ <Icon name="sparkle" /> enhance {kbd('enhance')}
399
+ </button>
400
+ )}
401
+ <button
402
+ type="button"
403
+ className="enh-big"
404
+ data-tip="generate the draft with this rewrite in place of the prompt: the prompt itself is not changed"
405
+ onClick={() => p.st.generate(e.tryOverride)}
406
+ disabled={noResult}
407
+ >
408
+ <Icon name="play" size={0.85} /> try it <span className="kbd-hint">{MOD_KEY}⏎</span>
149
409
  </button>
150
- <button type="button" onClick={remove} data-tip="delete this master prompt file">
151
- <Icon name="close" />
410
+ <button
411
+ type="button"
412
+ className="accent enh-big"
413
+ data-tip="write this rewrite into the prompt and close"
414
+ onClick={act.apply}
415
+ disabled={noResult}
416
+ >
417
+ apply to prompt {kbd('apply')}
152
418
  </button>
153
- <span className="hint">
154
- {p.e.saveState === 'saving' ? 'saving…' : null}
155
- {p.e.saveState === 'saved' ? 'autosaved to disk' : null}
156
- {p.e.saveState === 'error' ? `🔴 save failed: ${p.e.saveError}` : null}
419
+ <span className="run-error" data-tip={e.error === '' ? undefined : e.error}>
420
+ {e.error === '' ? '' : `🔴 ${e.error}`}
157
421
  </span>
158
422
  </div>
159
- <textarea rows={8} value={preset.text} onChange={(ev) => p.e.setPresetText(ev.target.value)} />
160
- </div>
423
+ <div className="enh-label enh-label-row">
424
+ <span>yours, what gets sent (the form is untouched)</span>
425
+ <span className="row-inline">
426
+ <button
427
+ type="button"
428
+ className="mini"
429
+ data-tip="replace this text with the prompt you opened the enhancer from"
430
+ onClick={() => e.usePrompt()}
431
+ >
432
+ use the prompt
433
+ </button>
434
+ <HistoryButton entries={e.inputHistory} what="enhance input" onPick={(h) => e.setOriginal(h.value)} />
435
+ </span>
436
+ </div>
437
+ <textarea
438
+ ref={inputRef}
439
+ className="enh-text enh-box"
440
+ value={e.original}
441
+ onChange={(ev) => e.setOriginal(ev.target.value)}
442
+ />
443
+ <div className="enh-label">
444
+ {running ? `rewriting… ${e.result.length} chars` : 'rewrite, editable before you apply'}
445
+ {e.thinking === '' ? null : (
446
+ <span className="enh-think-tip" data-tip={e.thinking}>
447
+ · thinking ({e.thinking.length} chars)
448
+ </span>
449
+ )}
450
+ </div>
451
+ <textarea
452
+ className="enh-text enh-box enh-result"
453
+ value={e.result}
454
+ placeholder="press enhance"
455
+ onChange={(ev) => e.setResult(ev.target.value)}
456
+ />
457
+ </section>
161
458
  )
162
459
  })
163
460
 
164
- const Modal = observer(function Modal(p: { e: EnhancerSt }) {
461
+ /** the enhancer's own actions, shared by the buttons and the keys so they cannot drift apart.
462
+ * try is the global ⌘⏎ (VarsForm), through EnhancerSt.tryOverride like its button */
463
+ function actions(e: EnhancerSt): Record<EnhancerShortcut, () => void> {
464
+ return {
465
+ enhance: () => (e.phase === 'running' ? undefined : e.run()),
466
+ apply: () => e.apply(),
467
+ }
468
+ }
469
+
470
+ const Modal = observer(function Modal(p: { e: EnhancerSt; st: WebSt }) {
165
471
  const e = p.e
472
+ const st = p.st
166
473
  useEffect(() => {
167
474
  const onKey = (ev: KeyboardEvent): void => {
168
- if (ev.key === 'Escape') e.close()
169
- if (ev.key === 'Enter' && (ev.metaKey || ev.ctrlKey)) {
170
- // inside the modal ⌘⏎ refines; VarsForm's generate shortcut stands down while it is open
171
- ev.preventDefault()
172
- e.run()
475
+ // esc closes the editor first, the modal only when nothing is open over the job
476
+ if (ev.key === 'Escape') {
477
+ if (e.editing != null) e.setEditing(null)
478
+ else e.close()
479
+ return
173
480
  }
481
+ const s = enhancerShortcutOf(ev)
482
+ if (s == null) return
483
+ ev.preventDefault()
484
+ actions(e)[s]()
174
485
  }
175
486
  window.addEventListener('keydown', onKey)
176
487
  return () => window.removeEventListener('keydown', onKey)
177
- }, [e])
178
- const running = e.phase === 'running'
488
+ }, [e, st])
179
489
  return (
180
- <div className="modal-overlay" onClick={() => e.close()}>
181
- <div className="modal" onClick={(ev) => ev.stopPropagation()}>
490
+ <div className="modal-overlay top" onClick={() => e.close()}>
491
+ <div className="modal enh-modal" onClick={(ev) => ev.stopPropagation()}>
182
492
  <div className="modal-head">
183
- <b style={{ flex: 1 }}>
493
+ <b className="enh-title">
184
494
  <Icon name="sparkle" /> enhance prompt
185
495
  </b>
186
- <button type="button" onClick={() => e.close()}>
496
+ <button
497
+ type="button"
498
+ className="modal-close"
499
+ data-tip="close (esc), nothing is applied"
500
+ onClick={() => e.close()}
501
+ >
187
502
  <Icon name="close" />
188
503
  </button>
189
504
  </div>
190
- <div className="modal-body">
191
- <Settings e={e} />
192
- <MasterPrompt e={e} />
193
- <div className="section-title">prompt</div>
194
- <div className="enh-cols">
195
- <div>
196
- <div className="hint">yours (edit before refining, the var is untouched)</div>
197
- <textarea rows={8} value={e.original} onChange={(ev) => e.setOriginal(ev.target.value)} />
198
- </div>
199
- <div>
200
- <div className="hint">{running ? 'rewriting…' : 'rewritten (editable before apply)'}</div>
201
- <textarea
202
- rows={8}
203
- value={e.result}
204
- placeholder="hit enhance"
205
- onChange={(ev) => e.setResult(ev.target.value)}
206
- />
505
+ <div className="enh-layout">
506
+ <Side e={e} />
507
+ <div className="enh-right">
508
+ <div className="modal-body enh-main">
509
+ <Job e={e} st={st} />
207
510
  </div>
511
+ {/* over the job, never beside it: the job keeps its place and size */}
512
+ {e.editing === 'llm' ? <LlmSettings e={e} /> : null}
513
+ {e.editing === 'preset' ? <MasterPrompt e={e} /> : null}
208
514
  </div>
209
- {e.thinking !== '' ? (
210
- <div>
211
- <div className="section-title">thinking</div>
212
- <div className="enh-think">{e.thinking}</div>
213
- </div>
214
- ) : null}
215
- {e.error !== '' ? <div className="error">🔴 {e.error}</div> : null}
216
- </div>
217
- <div className="modal-foot">
218
- {running ? (
219
- <button type="button" onClick={() => e.cancel()}>
220
- stop
221
- </button>
222
- ) : (
223
- <button type="button" className="primary" onClick={() => e.run()} data-tip="⌘⏎ / ctrl+⏎">
224
- enhance
225
- </button>
226
- )}
227
- <button type="button" onClick={() => e.apply()} disabled={e.result.trim() === ''}>
228
- apply to prompt
229
- </button>
230
- <span className="hint" style={{ flex: 1 }}>
231
- {running ? `${e.result.length} chars streamed` : 'nothing is written until you apply'}
232
- </span>
233
- <button type="button" className="link" onClick={() => e.close()}>
234
- cancel
235
- </button>
236
515
  </div>
237
516
  </div>
238
517
  </div>
239
518
  )
240
519
  })
241
520
 
242
- export const PromptEnhancer = observer(function PromptEnhancer(p: { v: VarSt; st: WebSt; module: string }) {
521
+ export const PromptEnhancer = observer(function PromptEnhancer(p: {
522
+ v: VarSt
523
+ st: WebSt
524
+ module: string
525
+ /** in lanes mode: refine this lane only */
526
+ lane?: number
527
+ /** the icon alone, for a lane's bar */
528
+ compact?: boolean
529
+ /** ⌘E opens THIS one (the first prompt): say so on the button */
530
+ shortcut?: boolean
531
+ }) {
243
532
  const e = p.st.enhancer
244
533
  return (
245
534
  <>
246
535
  <button
247
536
  type="button"
248
- className="link"
537
+ className={p.compact === true ? 'link' : 'mini'}
249
538
  data-tip="rewrite this prompt with an llm"
250
- onClick={() => e.openFor({ v: p.v, module: p.module })}
539
+ onClick={() => e.openFor({ v: p.v, module: p.module, lane: p.lane })}
251
540
  >
252
- <Icon name="sparkle" /> enhance
541
+ <Icon name="sparkle" />
542
+ {p.compact === true ? null : ' enhance'}
543
+ {p.shortcut === true ? (
544
+ <span className="kbd-hint">
545
+ {MOD_KEY}
546
+ {SHORTCUT_KEYS['open-enhancer']}
547
+ </span>
548
+ ) : null}
253
549
  </button>
254
- {e.target === p.v ? <Modal e={e} /> : null}
550
+ {e.target === p.v && e.targetLane === (p.lane ?? null) ? <Modal e={e} st={p.st} /> : null}
255
551
  </>
256
552
  )
257
553
  })