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.
- package/README.md +1 -0
- package/dist/{LogsSt-qtFzOKpu.js → LogsSt-CUeo843w.js} +51 -7
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +595 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +286 -46
- package/dist/index.d.ts +286 -46
- package/dist/index.js +591 -74
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BK7BA2dn.js → run-serve-DlRBv_Nk.js} +738 -58
- package/dist/run-serve-DlRBv_Nk.js.map +1 -0
- package/dist/{run-tui-CQyvMf0N.js → run-tui-B5uxm2_l.js} +43 -18
- package/dist/run-tui-B5uxm2_l.js.map +1 -0
- package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-E95iTF7E.js} +473 -60
- package/dist/schemaDrift-E95iTF7E.js.map +1 -0
- package/dist/serve-web.js +710 -174
- package/dist/{state--wrz0BQc.js → state-CUp2J1Zy.js} +126 -14
- package/dist/state-CUp2J1Zy.js.map +1 -0
- package/dist/web.d.ts +286 -46
- package/dist/web.js +591 -74
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/10-anima-t2i.cflow.ts +252 -0
- package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
- package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
- package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
- package/examples/rvion/stableAudio3Prompts.ts +19 -0
- package/extra/README.md +4 -0
- package/extra/comfyui-fresh-model-lists/README.md +25 -0
- package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
- package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
- package/package.json +15 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +305 -30
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/describeVar.ts +42 -6
- package/src/cli/serve/llmConfigShape.ts +51 -0
- package/src/cli/serve/llmConfigs.ts +52 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/tagList.ts +92 -0
- package/src/cli/serve/tagSource.ts +69 -0
- package/src/cli/serve/web/api.ts +72 -0
- package/src/cli/serve/web/components/App.tsx +485 -44
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +133 -31
- package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
- package/src/cli/serve/web/components/Icon.tsx +58 -2
- package/src/cli/serve/web/components/MenuButton.tsx +53 -0
- package/src/cli/serve/web/components/Omnibox.tsx +135 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
- package/src/cli/serve/web/components/SideMenu.tsx +414 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +46 -0
- package/src/cli/serve/web/components/VarIcon.tsx +24 -0
- package/src/cli/serve/web/components/VarsForm.tsx +223 -351
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +646 -317
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
- package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
- package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
- package/src/cli/serve/web/components/modKey.ts +2 -0
- package/src/cli/serve/web/llm.ts +23 -12
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +284 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +431 -101
- package/src/cli/serve/web/state/FormSt.ts +214 -30
- package/src/cli/serve/web/state/OmniboxSt.ts +59 -0
- package/src/cli/serve/web/state/WebSt.ts +364 -80
- package/src/cli/serve/web/state/choiceButtons.ts +61 -0
- package/src/cli/serve/web/state/draftNames.ts +16 -0
- package/src/cli/serve/web/state/draftTabs.ts +75 -0
- package/src/cli/serve/web/state/generateButton.ts +16 -0
- package/src/cli/serve/web/state/history.ts +54 -0
- package/src/cli/serve/web/state/host.ts +5 -2
- package/src/cli/serve/web/state/keptLines.ts +53 -0
- package/src/cli/serve/web/state/latentMode.ts +20 -0
- package/src/cli/serve/web/state/loraSort.ts +18 -0
- package/src/cli/serve/web/state/moduleTree.ts +2 -2
- package/src/cli/serve/web/state/omnibox.ts +133 -0
- package/src/cli/serve/web/state/payload.ts +38 -58
- package/src/cli/serve/web/state/shortcuts.ts +103 -0
- package/src/cli/serve/web/state/sizeStars.ts +31 -0
- package/src/cli/serve/web/state/stableSlots.ts +21 -0
- package/src/cli/serve/web/state/varGroups.ts +24 -0
- package/src/cli/serve/web/styles.ts +653 -154
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -0
- package/src/cli/tui/components/PickerOverlays.tsx +9 -2
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
- package/src/cli/tui/state/DraftsSt.ts +28 -8
- package/src/cli/tui/state/EditorSt.ts +1 -1
- package/src/cli/tui/state/LorasSt.ts +1 -1
- package/src/cli/tui/state/PickerSt.ts +25 -7
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +10 -0
- package/src/coreExports.ts +21 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- package/src/host/loraInfoCache.ts +6 -0
- package/src/runner/ComfyExecution.ts +60 -0
- package/src/runner/ComfyWorkflow.ts +4 -0
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/MediaImage.ts +2 -2
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
- package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
- package/src/state.ts +5 -0
- package/src/utils/copyName.ts +12 -0
- package/src/vars/ComfyVars.ts +337 -67
- package/src/vars/DefinedWorkflow.ts +47 -20
- package/src/vars/lanes.ts +238 -0
- package/src/vars/loraEntry.ts +101 -0
- package/src/vars/promptSyntax.ts +382 -0
- package/dist/LogsSt-qtFzOKpu.js.map +0 -1
- package/dist/run-serve-BK7BA2dn.js.map +0 -1
- package/dist/run-tui-CQyvMf0N.js.map +0 -1
- package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
- package/dist/state--wrz0BQc.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
|
@@ -22,7 +22,7 @@ export const PresetPicker = observer(function PresetPicker(p: { v: VarSt }) {
|
|
|
22
22
|
<div className="preset-box" onKeyDown={(e) => (e.key === 'Escape' ? setOpen(false) : undefined)}>
|
|
23
23
|
<button
|
|
24
24
|
type="button"
|
|
25
|
-
className="preset-btn"
|
|
25
|
+
className="preset-btn mini"
|
|
26
26
|
aria-expanded={open}
|
|
27
27
|
data-tip="named starting texts — picking one replaces the field"
|
|
28
28
|
onClick={() => setOpen(!open)}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// prompt: one box, or `{ lanes }` (src/vars/lanes.ts), one box per named lane merged in listed
|
|
2
|
+
// order. Above it, what the active loras add: one line per lora, a popover to leave words out
|
|
3
|
+
import { observer } from 'mobx-react-lite'
|
|
4
|
+
import { useState } from 'react'
|
|
5
|
+
import { MenuButton, MenuItem } from 'src/cli/serve/web/components/MenuButton.tsx'
|
|
6
|
+
import { PresetPicker } from 'src/cli/serve/web/components/controls/PresetPicker.tsx'
|
|
7
|
+
import { PromptEditor } from 'src/cli/serve/web/components/controls/PromptEditor.tsx'
|
|
8
|
+
import { PromptEnhancer } from 'src/cli/serve/web/components/PromptEnhancer.tsx'
|
|
9
|
+
import { HistoryButton } from 'src/cli/serve/web/components/HistoryPicker.tsx'
|
|
10
|
+
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
11
|
+
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
12
|
+
import {
|
|
13
|
+
isPromptLanes,
|
|
14
|
+
moveLane,
|
|
15
|
+
newLaneName,
|
|
16
|
+
patchLane,
|
|
17
|
+
promptFromLanes,
|
|
18
|
+
removeLane,
|
|
19
|
+
toPromptLanes,
|
|
20
|
+
type PromptLane,
|
|
21
|
+
} from 'src/vars/lanes.ts'
|
|
22
|
+
|
|
23
|
+
/** the words each active lora adds in front of the prompt. One line per lora, cut with an
|
|
24
|
+
* ellipsis; clicking opens the full list with a checkbox per word and all / none */
|
|
25
|
+
const KeywordGroups = observer(function KeywordGroups(p: { v: VarSt; st: WebSt }) {
|
|
26
|
+
const [open, setOpen] = useState<string | null>(null)
|
|
27
|
+
const form = p.st.form
|
|
28
|
+
const groups = form?.loraKeywordGroups(p.v) ?? []
|
|
29
|
+
if (form == null || groups.length === 0) return null
|
|
30
|
+
return (
|
|
31
|
+
<div className="kw-prefix">
|
|
32
|
+
{groups.map((g) => {
|
|
33
|
+
const kept = g.parts.filter((w) => w.on).length
|
|
34
|
+
return (
|
|
35
|
+
<div key={g.lora} className="preset-box kw-box">
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
className={g.running ? 'kw-line' : 'kw-line stopped'}
|
|
39
|
+
aria-expanded={open === g.lora}
|
|
40
|
+
data-tip={`${g.lora}\n${g.running ? 'added in front of your prompt at run time' : 'not running: paused, or its lane is off'}\nclick to choose the words`}
|
|
41
|
+
onClick={() => setOpen(open === g.lora ? null : g.lora)}
|
|
42
|
+
>
|
|
43
|
+
<span className="kw-lora">{g.label}</span>
|
|
44
|
+
<span className="kw-words">
|
|
45
|
+
{g.parts
|
|
46
|
+
.filter((w) => w.on)
|
|
47
|
+
.map((w) => w.text)
|
|
48
|
+
.join(', ') || 'no words'}
|
|
49
|
+
</span>
|
|
50
|
+
{g.parts.length - kept > 0 ? (
|
|
51
|
+
<span className="kw-off">+{g.parts.length - kept} disabled</span>
|
|
52
|
+
) : null}
|
|
53
|
+
</button>
|
|
54
|
+
{open === g.lora ? (
|
|
55
|
+
<>
|
|
56
|
+
<div className="preset-backdrop" onClick={() => setOpen(null)} />
|
|
57
|
+
<div className="preset-menu kw-menu">
|
|
58
|
+
<div className="row-inline kw-menu-head">
|
|
59
|
+
<span className="kw-lora">{g.label}</span>
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
className="link"
|
|
63
|
+
onClick={() => form.setKeywordMute(p.v, g.lora, [])}
|
|
64
|
+
>
|
|
65
|
+
all
|
|
66
|
+
</button>
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
className="link"
|
|
70
|
+
onClick={() =>
|
|
71
|
+
form.setKeywordMute(
|
|
72
|
+
p.v,
|
|
73
|
+
g.lora,
|
|
74
|
+
g.parts.map((w) => w.text),
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
>
|
|
78
|
+
none
|
|
79
|
+
</button>
|
|
80
|
+
</div>
|
|
81
|
+
{g.parts.map((w) => (
|
|
82
|
+
<label key={w.text} className="kw-item">
|
|
83
|
+
<input
|
|
84
|
+
type="checkbox"
|
|
85
|
+
checked={w.on}
|
|
86
|
+
onChange={() => form.toggleKeywordPart(p.v, g.lora, w.text)}
|
|
87
|
+
/>
|
|
88
|
+
<span>{w.text}</span>
|
|
89
|
+
</label>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
</>
|
|
93
|
+
) : null}
|
|
94
|
+
</div>
|
|
95
|
+
)
|
|
96
|
+
})}
|
|
97
|
+
</div>
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const LANE_DRAG = 'application/x-comfy-lane'
|
|
102
|
+
|
|
103
|
+
/** one prompt lane: a name pill and its box. Click the pill to use or leave out the lane, drag
|
|
104
|
+
* it onto another lane to reorder, ⋯ to rename or remove. Nothing else on the bar */
|
|
105
|
+
const LaneBox = observer(function LaneBox(p: {
|
|
106
|
+
v: VarSt
|
|
107
|
+
st: WebSt
|
|
108
|
+
module: string
|
|
109
|
+
lanes: PromptLane[]
|
|
110
|
+
ix: number
|
|
111
|
+
/** ⌘E opens this lane's enhancer (lane 0 of the first prompt) */
|
|
112
|
+
shortcut: boolean
|
|
113
|
+
}) {
|
|
114
|
+
const [renaming, setRenaming] = useState(false)
|
|
115
|
+
const lane = p.lanes[p.ix]
|
|
116
|
+
if (lane == null) return null
|
|
117
|
+
const write = (lanes: PromptLane[]): void => {
|
|
118
|
+
p.v.set({ lanes })
|
|
119
|
+
}
|
|
120
|
+
return (
|
|
121
|
+
<div
|
|
122
|
+
className={lane.active ? 'lane-box' : 'lane-box off'}
|
|
123
|
+
onDragOver={(e) => {
|
|
124
|
+
if (e.dataTransfer.types.includes(LANE_DRAG)) e.preventDefault()
|
|
125
|
+
}}
|
|
126
|
+
onDrop={(e) => {
|
|
127
|
+
const from = Number(e.dataTransfer.getData(LANE_DRAG))
|
|
128
|
+
if (e.dataTransfer.getData(LANE_DRAG) === '' || !Number.isInteger(from) || from === p.ix) return
|
|
129
|
+
e.preventDefault()
|
|
130
|
+
write(moveLane(p.lanes, from, p.ix - from))
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<div className="lane-bar">
|
|
134
|
+
{renaming ? (
|
|
135
|
+
<input
|
|
136
|
+
type="text"
|
|
137
|
+
className="lane-name"
|
|
138
|
+
autoFocus
|
|
139
|
+
defaultValue={lane.name}
|
|
140
|
+
onFocus={(e) => e.currentTarget.select()}
|
|
141
|
+
onKeyDown={(e) => {
|
|
142
|
+
if (e.key === 'Enter') {
|
|
143
|
+
write(patchLane(p.lanes, p.ix, { name: e.currentTarget.value.trim() || lane.name }))
|
|
144
|
+
setRenaming(false)
|
|
145
|
+
}
|
|
146
|
+
if (e.key === 'Escape') setRenaming(false)
|
|
147
|
+
}}
|
|
148
|
+
onBlur={() => setRenaming(false)}
|
|
149
|
+
/>
|
|
150
|
+
) : (
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
className={lane.active ? 'lane-pill' : 'lane-pill off'}
|
|
154
|
+
draggable
|
|
155
|
+
data-tip={`${lane.active ? 'in the prompt' : 'left out'}: click to switch, drag to reorder, double-click to rename`}
|
|
156
|
+
onDragStart={(e) => {
|
|
157
|
+
e.dataTransfer.effectAllowed = 'move'
|
|
158
|
+
e.dataTransfer.setData(LANE_DRAG, String(p.ix))
|
|
159
|
+
}}
|
|
160
|
+
onClick={() => write(patchLane(p.lanes, p.ix, { active: !lane.active }))}
|
|
161
|
+
onDoubleClick={() => setRenaming(true)}
|
|
162
|
+
>
|
|
163
|
+
{lane.name}
|
|
164
|
+
</button>
|
|
165
|
+
)}
|
|
166
|
+
<span className="lane-tools">
|
|
167
|
+
<PromptEnhancer v={p.v} st={p.st} module={p.module} lane={p.ix} compact shortcut={p.shortcut} />
|
|
168
|
+
<MenuButton tip="lane actions">
|
|
169
|
+
{(close) => (
|
|
170
|
+
<>
|
|
171
|
+
<MenuItem
|
|
172
|
+
label="rename"
|
|
173
|
+
onClick={() => {
|
|
174
|
+
close()
|
|
175
|
+
setRenaming(true)
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
<MenuItem
|
|
179
|
+
label="remove"
|
|
180
|
+
disabled={p.lanes.length === 1}
|
|
181
|
+
onClick={() => {
|
|
182
|
+
close()
|
|
183
|
+
write(removeLane(p.lanes, p.ix))
|
|
184
|
+
}}
|
|
185
|
+
/>
|
|
186
|
+
</>
|
|
187
|
+
)}
|
|
188
|
+
</MenuButton>
|
|
189
|
+
</span>
|
|
190
|
+
</div>
|
|
191
|
+
<PromptEditor
|
|
192
|
+
v={p.v}
|
|
193
|
+
st={p.st}
|
|
194
|
+
module={p.module}
|
|
195
|
+
value={lane.prompt}
|
|
196
|
+
onChange={(text) => write(patchLane(p.lanes, p.ix, { prompt: text }))}
|
|
197
|
+
minLines={2}
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
export const PromptControl = observer(function PromptControl(p: {
|
|
204
|
+
v: VarSt
|
|
205
|
+
st: WebSt
|
|
206
|
+
module: string
|
|
207
|
+
/** the first prompt: ⌘P lands here and ⌘E opens its enhancer */
|
|
208
|
+
jumpTarget?: boolean
|
|
209
|
+
}) {
|
|
210
|
+
const value = p.v.value
|
|
211
|
+
if (isPromptLanes(value)) {
|
|
212
|
+
const single = promptFromLanes(value)
|
|
213
|
+
return (
|
|
214
|
+
<div>
|
|
215
|
+
<KeywordGroups v={p.v} st={p.st} />
|
|
216
|
+
<div className="lanes">
|
|
217
|
+
{value.lanes.map((lane, ix) => (
|
|
218
|
+
// index keys on purpose: a lane's name is editable and may repeat
|
|
219
|
+
<LaneBox
|
|
220
|
+
key={ix}
|
|
221
|
+
v={p.v}
|
|
222
|
+
st={p.st}
|
|
223
|
+
module={p.module}
|
|
224
|
+
lanes={value.lanes}
|
|
225
|
+
ix={ix}
|
|
226
|
+
shortcut={p.jumpTarget === true && ix === 0}
|
|
227
|
+
/>
|
|
228
|
+
))}
|
|
229
|
+
</div>
|
|
230
|
+
<div className="row-inline lane-foot">
|
|
231
|
+
<button
|
|
232
|
+
type="button"
|
|
233
|
+
className="link"
|
|
234
|
+
onClick={() =>
|
|
235
|
+
p.v.set({
|
|
236
|
+
lanes: [...value.lanes, { name: newLaneName(value.lanes), prompt: '', active: true }],
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
>
|
|
240
|
+
+ lane
|
|
241
|
+
</button>
|
|
242
|
+
{single == null ? null : (
|
|
243
|
+
<button
|
|
244
|
+
type="button"
|
|
245
|
+
className="link"
|
|
246
|
+
data-tip="back to a single prompt box"
|
|
247
|
+
onClick={() => p.v.set(single)}
|
|
248
|
+
>
|
|
249
|
+
single box
|
|
250
|
+
</button>
|
|
251
|
+
)}
|
|
252
|
+
<HistoryButton entries={p.st.promptHistory} what="prompt" onPick={(e) => p.v.set(e.value)} />
|
|
253
|
+
<span className="hint">lanes merge top to bottom</span>
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
const text = typeof value === 'string' ? value : ''
|
|
259
|
+
return (
|
|
260
|
+
<div>
|
|
261
|
+
<KeywordGroups v={p.v} st={p.st} />
|
|
262
|
+
<PromptEditor v={p.v} st={p.st} module={p.module} value={text} onChange={(t) => p.v.set(t)} minLines={4} />
|
|
263
|
+
{/* three small separate actions under the box, the same size, none dressed as a link */}
|
|
264
|
+
<div className="row-inline prompt-actions">
|
|
265
|
+
<PresetPicker v={p.v} />
|
|
266
|
+
<PromptEnhancer v={p.v} st={p.st} module={p.module} shortcut={p.jumpTarget} />
|
|
267
|
+
<HistoryButton entries={p.st.promptHistory} what="prompt" onPick={(e) => p.v.set(e.value)} />
|
|
268
|
+
<button
|
|
269
|
+
type="button"
|
|
270
|
+
className="mini"
|
|
271
|
+
data-tip="split this prompt into named lanes, merged in the order they are listed"
|
|
272
|
+
onClick={() => p.v.set(toPromptLanes(text))}
|
|
273
|
+
>
|
|
274
|
+
lanes
|
|
275
|
+
</button>
|
|
276
|
+
</div>
|
|
277
|
+
</div>
|
|
278
|
+
)
|
|
279
|
+
})
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// one prompt box: a CodeMirror editor over a plain string. The value stays controlled (a preset
|
|
2
|
+
// pick or a draft switch replaces the text), and the footer says what the editor cannot color
|
|
3
|
+
import { EditorState } from '@codemirror/state'
|
|
4
|
+
import { EditorView } from '@codemirror/view'
|
|
5
|
+
import { observer } from 'mobx-react-lite'
|
|
6
|
+
import { useEffect, useRef, useState } from 'react'
|
|
7
|
+
import { fetchTags } from 'src/cli/serve/web/api.ts'
|
|
8
|
+
import {
|
|
9
|
+
promptExtensions,
|
|
10
|
+
refreshMarks,
|
|
11
|
+
WEIGHT_STEP,
|
|
12
|
+
type PromptEditorCtx,
|
|
13
|
+
} from 'src/cli/serve/web/promptEditor/promptExtensions.ts'
|
|
14
|
+
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
15
|
+
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
16
|
+
import { estimateTokens } from 'src/vars/promptSyntax.ts'
|
|
17
|
+
|
|
18
|
+
const KEYS_TIP = [
|
|
19
|
+
`⌘↑ / ⌘↓ (or ⌃↑ / ⌃↓): weight of the selection or the tag under the cursor, ±${WEIGHT_STEP}`,
|
|
20
|
+
'⌘/ comment lines · ⌘⇧- negative lines · ⌥↑ / ⌥↓ move lines',
|
|
21
|
+
'"//" starts a comment · "- " line = negative prompt · ⌘⏎ generate',
|
|
22
|
+
].join('\n')
|
|
23
|
+
|
|
24
|
+
export const PromptEditor = observer(function PromptEditor(p: {
|
|
25
|
+
v: VarSt
|
|
26
|
+
st: WebSt
|
|
27
|
+
module: string
|
|
28
|
+
value: string
|
|
29
|
+
onChange: (text: string) => void
|
|
30
|
+
minLines: number
|
|
31
|
+
}) {
|
|
32
|
+
const host = useRef<HTMLDivElement>(null)
|
|
33
|
+
const view = useRef<EditorView | null>(null)
|
|
34
|
+
const [tagError, setTagError] = useState<string | null>(null)
|
|
35
|
+
// the editor reads these through a getter, so it sees the latest without being rebuilt
|
|
36
|
+
const latest = useRef({ p, setTagError })
|
|
37
|
+
latest.current = { p, setTagError }
|
|
38
|
+
const form = p.st.form
|
|
39
|
+
const injectedKey = JSON.stringify(form?.injectedTagsFor(p.v) ?? [])
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const ctx = (): PromptEditorCtx => {
|
|
43
|
+
const cur = latest.current.p
|
|
44
|
+
const f = cur.st.form
|
|
45
|
+
return {
|
|
46
|
+
weights: cur.v.desc.weights !== false,
|
|
47
|
+
tags: cur.v.desc.tags ?? null,
|
|
48
|
+
searchTags: async (q, signal) =>
|
|
49
|
+
(await fetchTags({ module: cur.module, varName: cur.v.name, q, signal })).hits,
|
|
50
|
+
injected: () => f?.injectedTagsFor(cur.v) ?? [],
|
|
51
|
+
loraWords: () => f?.loraWordsFor(cur.v) ?? [],
|
|
52
|
+
onTagError: (m) => latest.current.setTagError(m),
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (host.current == null) return
|
|
56
|
+
const v = new EditorView({
|
|
57
|
+
parent: host.current,
|
|
58
|
+
state: EditorState.create({
|
|
59
|
+
doc: latest.current.p.value,
|
|
60
|
+
extensions: promptExtensions({
|
|
61
|
+
ctx,
|
|
62
|
+
onChange: (text) => latest.current.p.onChange(text),
|
|
63
|
+
minLines: latest.current.p.minLines,
|
|
64
|
+
}),
|
|
65
|
+
}),
|
|
66
|
+
})
|
|
67
|
+
view.current = v
|
|
68
|
+
return () => {
|
|
69
|
+
v.destroy()
|
|
70
|
+
view.current = null
|
|
71
|
+
}
|
|
72
|
+
}, [])
|
|
73
|
+
|
|
74
|
+
// controlled: a value that changed from outside (preset, draft, revert) replaces the text
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const v = view.current
|
|
77
|
+
if (v == null) return
|
|
78
|
+
const doc = v.state.doc.toString()
|
|
79
|
+
if (doc === p.value) return
|
|
80
|
+
const head = Math.min(v.state.selection.main.head, p.value.length)
|
|
81
|
+
v.dispatch({ changes: { from: 0, to: doc.length, insert: p.value }, selection: { anchor: head } })
|
|
82
|
+
}, [p.value])
|
|
83
|
+
|
|
84
|
+
// a lora switched on or off moves which tags count as already added
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
view.current?.dispatch({ effects: refreshMarks.of(null) })
|
|
87
|
+
}, [injectedKey])
|
|
88
|
+
|
|
89
|
+
const tokens = estimateTokens(p.value)
|
|
90
|
+
return (
|
|
91
|
+
<div className="prompt-editor">
|
|
92
|
+
<div ref={host} />
|
|
93
|
+
{/* keys and the token count are reference, not something to watch: they float in the
|
|
94
|
+
corner and show only while the editor has focus. A tag error always shows */}
|
|
95
|
+
<div className={tagError == null ? 'pe-foot' : 'pe-foot has-error'}>
|
|
96
|
+
{tagError == null ? null : (
|
|
97
|
+
<span className="pe-error" data-tip={tagError}>
|
|
98
|
+
tags: {tagError}
|
|
99
|
+
</span>
|
|
100
|
+
)}
|
|
101
|
+
<span className="pe-keys" data-tip={KEYS_TIP}>
|
|
102
|
+
keys
|
|
103
|
+
</span>
|
|
104
|
+
<span
|
|
105
|
+
className="pe-tokens"
|
|
106
|
+
data-tip={'an estimate of the CLIP tokens the positive prompt uses\nCLIP models read it in chunks of 75'}
|
|
107
|
+
>
|
|
108
|
+
≈ {tokens} tokens
|
|
109
|
+
</span>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
)
|
|
113
|
+
})
|
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
// seed: mode buttons + value + 🎲. Drafts are live, so the mode configures the
|
|
2
2
|
// SERVER's per-draft seed policy (generate posts no seed key; step 4 applies
|
|
3
|
-
// the draft's {mode, value}). The buttons are
|
|
4
|
-
//
|
|
5
|
-
// row of prose wider than the input
|
|
3
|
+
// the draft's {mode, value}). The buttons are ONE short word each (fixed, inc,
|
|
4
|
+
// random), the sentence in the tooltip: the bare symbols `= + ?` were unclear,
|
|
5
|
+
// and full sentences a row of prose wider than the input
|
|
6
6
|
import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
|
|
7
7
|
import { observer } from 'mobx-react-lite'
|
|
8
8
|
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
9
9
|
import { asSeedForm, randomSeed } from 'src/cli/serve/web/state/payload.ts'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{ mode: '
|
|
11
|
+
/** the stored mode stays the symbol (drafts, the TUI, the api all speak it); the button says
|
|
12
|
+
* the word, a row of `=` `+` `?` read like punctuation */
|
|
13
|
+
const MODES: { mode: string; label: string; hint: string }[] = [
|
|
14
|
+
{ mode: '=', label: 'fixed', hint: 'this exact seed, every run' },
|
|
15
|
+
{ mode: '+', label: 'inc', hint: 'one more after each run' },
|
|
16
|
+
{ mode: '?', label: 'random', hint: 'a fresh random seed each run' },
|
|
15
17
|
]
|
|
16
18
|
|
|
17
19
|
/** `-` is a real mode a draft can hold (the TUI offers it), it is just not worth a permanent
|
|
18
20
|
* button here. It appears only while it IS the mode, so the row never misreports the draft,
|
|
19
21
|
* and it disappears once you pick another one */
|
|
20
|
-
function visibleModes(current: string): { mode: string; hint: string }[] {
|
|
22
|
+
function visibleModes(current: string): { mode: string; label: string; hint: string }[] {
|
|
21
23
|
if (MODES.some((m) => m.mode === current)) return MODES
|
|
22
|
-
return [
|
|
24
|
+
return [
|
|
25
|
+
...MODES,
|
|
26
|
+
current === '-'
|
|
27
|
+
? { mode: '-', label: 'dec', hint: 'one less after each run' }
|
|
28
|
+
: { mode: current, label: current, hint: `mode '${current}'` },
|
|
29
|
+
]
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
export const SeedControl = observer(function SeedControl(p: { v: VarSt }) {
|
|
@@ -42,7 +49,7 @@ export const SeedControl = observer(function SeedControl(p: { v: VarSt }) {
|
|
|
42
49
|
data-tip={m.hint}
|
|
43
50
|
onClick={() => p.v.set({ mode: m.mode, value: seed.value })}
|
|
44
51
|
>
|
|
45
|
-
{m.
|
|
52
|
+
{m.label}
|
|
46
53
|
</button>
|
|
47
54
|
))}
|
|
48
55
|
</span>
|
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
// size:
|
|
1
|
+
// size: starred presets as one-click aspect icons, then the full list (each row starrable),
|
|
2
|
+
// then W × H fields that fit their numbers, then ⇄ swap
|
|
2
3
|
import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
|
|
3
4
|
import { observer } from 'mobx-react-lite'
|
|
5
|
+
import { useState, type ReactNode } from 'react'
|
|
4
6
|
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
5
7
|
import { asSizeForm } from 'src/cli/serve/web/state/payload.ts'
|
|
8
|
+
import { aspectBox, starredPresets, toggleStar } from 'src/cli/serve/web/state/sizeStars.ts'
|
|
9
|
+
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
/** a tiny rectangle in the preset's own ratio, centred in a fixed square so a row lines up */
|
|
12
|
+
function AspectIcon(p: { width: number; height: number; box?: number }): ReactNode {
|
|
13
|
+
const box = p.box ?? 14
|
|
14
|
+
const r = aspectBox(p.width, p.height, box - 2)
|
|
15
|
+
return (
|
|
16
|
+
<svg className="aspect-icon" width={box} height={box} viewBox={`0 0 ${box} ${box}`} aria-hidden="true">
|
|
17
|
+
<rect
|
|
18
|
+
x={(box - r.w) / 2}
|
|
19
|
+
y={(box - r.h) / 2}
|
|
20
|
+
width={r.w}
|
|
21
|
+
height={r.h}
|
|
22
|
+
rx={1.5}
|
|
23
|
+
fill="none"
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
strokeWidth={1.4}
|
|
26
|
+
/>
|
|
27
|
+
</svg>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** a number field as wide as its number, so 512 and 1344 both read without dead space */
|
|
32
|
+
function fitWidth(n: number): string {
|
|
33
|
+
return `${String(n).length + 2.6}ch`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const SizeControl = observer(function SizeControl(p: { v: VarSt; st: WebSt; module: string }) {
|
|
37
|
+
const [open, setOpen] = useState(false)
|
|
8
38
|
const size = asSizeForm(p.v.value)
|
|
9
39
|
const presets = p.v.desc.presets ?? []
|
|
40
|
+
const starKey = `${p.module}/${p.v.name}`
|
|
41
|
+
const defaults = p.v.desc.starredPresets ?? []
|
|
42
|
+
const mine = p.st.sizeStars[starKey]
|
|
43
|
+
const stars = starredPresets({ presets, defaults, mine })
|
|
10
44
|
const current = presets.find((pr) => pr.width === size.width && pr.height === size.height)
|
|
45
|
+
const pick = (pr: { width: number; height: number }): void => p.v.set({ width: pr.width, height: pr.height })
|
|
11
46
|
const setDim = (patch: { width?: number; height?: number }): void => {
|
|
12
47
|
const width = patch.width ?? size.width
|
|
13
48
|
const height = patch.height ?? size.height
|
|
@@ -15,26 +50,84 @@ export const SizeControl = observer(function SizeControl(p: { v: VarSt }) {
|
|
|
15
50
|
p.v.set({ width: Math.floor(width), height: Math.floor(height) })
|
|
16
51
|
}
|
|
17
52
|
return (
|
|
18
|
-
<div className="row-inline">
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
<div className="row-inline size-row">
|
|
54
|
+
{stars.length > 0 ? (
|
|
55
|
+
<span className="btn-group">
|
|
56
|
+
{stars.map((pr) => (
|
|
57
|
+
<button
|
|
58
|
+
key={pr.label}
|
|
59
|
+
type="button"
|
|
60
|
+
className={pr === current ? 'sel' : ''}
|
|
61
|
+
data-tip={`${pr.label} · ${pr.width}×${pr.height}`}
|
|
62
|
+
onClick={() => pick(pr)}
|
|
63
|
+
>
|
|
64
|
+
<AspectIcon width={pr.width} height={pr.height} />
|
|
65
|
+
</button>
|
|
66
|
+
))}
|
|
67
|
+
</span>
|
|
68
|
+
) : null}
|
|
69
|
+
<div className="preset-box" onKeyDown={(e) => (e.key === 'Escape' ? setOpen(false) : undefined)}>
|
|
70
|
+
<button type="button" className="preset-btn size-pick" aria-expanded={open} onClick={() => setOpen(!open)}>
|
|
71
|
+
<AspectIcon width={size.width} height={size.height} /> {current?.label ?? 'custom'} ▾
|
|
72
|
+
</button>
|
|
73
|
+
{open ? (
|
|
74
|
+
<>
|
|
75
|
+
<div className="preset-backdrop" onClick={() => setOpen(false)} />
|
|
76
|
+
<div className="preset-menu size-menu">
|
|
77
|
+
{presets.map((pr) => {
|
|
78
|
+
const starred = stars.includes(pr)
|
|
79
|
+
return (
|
|
80
|
+
<div key={pr.label} className={pr === current ? 'size-item on' : 'size-item'}>
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
className="size-item-pick"
|
|
84
|
+
onClick={() => {
|
|
85
|
+
pick(pr)
|
|
86
|
+
setOpen(false)
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<AspectIcon width={pr.width} height={pr.height} />
|
|
90
|
+
<span className="size-item-label">{pr.label}</span>
|
|
91
|
+
<span className="hint">
|
|
92
|
+
{pr.width}×{pr.height}
|
|
93
|
+
</span>
|
|
94
|
+
</button>
|
|
95
|
+
{/* the star is its own button: starring never changes the size */}
|
|
96
|
+
<button
|
|
97
|
+
type="button"
|
|
98
|
+
className={starred ? 'size-star on' : 'size-star'}
|
|
99
|
+
// a NATIVE tooltip: the page's own tooltip is drawn inside this scrolling list, sticks
|
|
100
|
+
// out past its edge and scrolls it sideways over the last row
|
|
101
|
+
title={
|
|
102
|
+
starred ? 'unstar: remove from the quick buttons' : 'star: add to the quick buttons'
|
|
103
|
+
}
|
|
104
|
+
onClick={() =>
|
|
105
|
+
p.st.setSizeStars(starKey, toggleStar({ defaults, mine, label: pr.label }))
|
|
106
|
+
}
|
|
107
|
+
>
|
|
108
|
+
{starred ? '★' : '☆'}
|
|
109
|
+
</button>
|
|
110
|
+
</div>
|
|
111
|
+
)
|
|
112
|
+
})}
|
|
113
|
+
</div>
|
|
114
|
+
</>
|
|
115
|
+
) : null}
|
|
116
|
+
</div>
|
|
117
|
+
<input
|
|
118
|
+
type="number"
|
|
119
|
+
min={1}
|
|
120
|
+
className="size-num"
|
|
121
|
+
style={{ width: fitWidth(size.width) }}
|
|
122
|
+
value={size.width}
|
|
123
|
+
onChange={(e) => setDim({ width: Number(e.target.value) })}
|
|
124
|
+
/>
|
|
34
125
|
×
|
|
35
126
|
<input
|
|
36
127
|
type="number"
|
|
37
128
|
min={1}
|
|
129
|
+
className="size-num"
|
|
130
|
+
style={{ width: fitWidth(size.height) }}
|
|
38
131
|
value={size.height}
|
|
39
132
|
onChange={(e) => setDim({ height: Number(e.target.value) })}
|
|
40
133
|
/>
|