comfy-ts 2.12.0 → 2.14.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/dist/{LogsSt-U1H0mP1m.js → LogsSt-CUeo843w.js} +18 -4
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +123 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -16
- package/dist/index.d.ts +96 -16
- package/dist/index.js +123 -12
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BeAznay5.js → run-serve-DUqcn0h3.js} +477 -63
- package/dist/run-serve-DUqcn0h3.js.map +1 -0
- package/dist/{run-tui-BTGjvnKk.js → run-tui-D-LaSqgB.js} +4 -4
- package/dist/{run-tui-BTGjvnKk.js.map → run-tui-D-LaSqgB.js.map} +1 -1
- package/dist/{schemaDrift-Cg39vs53.js → schemaDrift-E95iTF7E.js} +4 -1
- package/dist/{schemaDrift-Cg39vs53.js.map → schemaDrift-E95iTF7E.js.map} +1 -1
- package/dist/serve-web.js +378 -141
- package/dist/{state-C7REnHan.js → state-BytbdZ8s.js} +122 -14
- package/dist/state-BytbdZ8s.js.map +1 -0
- package/dist/web.d.ts +96 -16
- package/dist/web.js +123 -12
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/10-anima-t2i.cflow.ts +48 -25
- 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/package.json +2 -2
- package/src/cli/serve/ServeApp.ts +224 -77
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/resultHistory.ts +125 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/runError.ts +23 -0
- package/src/cli/serve/serveSettings.ts +17 -1
- package/src/cli/serve/web/api.ts +53 -2
- package/src/cli/serve/web/components/App.tsx +311 -160
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +75 -25
- package/src/cli/serve/web/components/Icon.tsx +44 -0
- package/src/cli/serve/web/components/MemoryBudget.tsx +98 -0
- package/src/cli/serve/web/components/Omnibox.tsx +70 -20
- package/src/cli/serve/web/components/RunError.tsx +19 -0
- package/src/cli/serve/web/components/ShortcutsModal.tsx +54 -0
- package/src/cli/serve/web/components/SideMenu.tsx +428 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
- package/src/cli/serve/web/components/VarsForm.tsx +141 -404
- package/src/cli/serve/web/components/controls/BasicControls.tsx +8 -1
- package/src/cli/serve/web/components/controls/LorasControl.tsx +30 -25
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +9 -4
- package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
- package/src/cli/serve/web/state/FormSt.ts +22 -2
- package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
- package/src/cli/serve/web/state/RunSt.ts +61 -3
- package/src/cli/serve/web/state/WebSt.ts +198 -35
- 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/formRows.ts +9 -0
- package/src/cli/serve/web/state/generateButton.ts +1 -1
- package/src/cli/serve/web/state/keptResults.ts +26 -0
- package/src/cli/serve/web/state/lightbox.ts +17 -0
- package/src/cli/serve/web/state/omnibox.ts +82 -18
- package/src/cli/serve/web/state/shortcutCatalog.ts +100 -0
- package/src/cli/serve/web/state/shortcuts.ts +66 -7
- package/src/cli/serve/web/styles.ts +327 -93
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -0
- package/src/cli/tui/state/DraftsSt.ts +10 -6
- package/src/coreExports.ts +1 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- 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/utils/copyName.ts +12 -0
- package/src/vars/DefinedWorkflow.ts +7 -1
- package/dist/LogsSt-U1H0mP1m.js.map +0 -1
- package/dist/run-serve-BeAznay5.js.map +0 -1
- package/dist/state-C7REnHan.js.map +0 -1
|
@@ -8,28 +8,34 @@ import {
|
|
|
8
8
|
fetchHosts,
|
|
9
9
|
fetchIndex,
|
|
10
10
|
fetchSettings,
|
|
11
|
+
fetchTabs,
|
|
11
12
|
pingHost,
|
|
12
13
|
postHostAction,
|
|
13
14
|
postLoraCivitai,
|
|
14
15
|
fetchHostDrift,
|
|
15
16
|
saveDraft,
|
|
16
17
|
saveSettings,
|
|
18
|
+
saveTabs,
|
|
17
19
|
setModuleHost,
|
|
18
20
|
type HostAction,
|
|
19
21
|
type HostsPayload,
|
|
20
22
|
type ModuleDescription,
|
|
23
|
+
type PathLabel,
|
|
21
24
|
type ServeSettings,
|
|
22
25
|
} from 'src/cli/serve/web/api.ts'
|
|
23
26
|
import { EnhancerSt } from 'src/cli/serve/web/state/EnhancerSt.ts'
|
|
24
27
|
import { OmniboxSt } from 'src/cli/serve/web/state/OmniboxSt.ts'
|
|
28
|
+
import { duplicateDraftName, freeDraftName } from 'src/cli/serve/web/state/draftNames.ts'
|
|
25
29
|
import { asLatentMode, type LatentMode } from 'src/cli/serve/web/state/latentMode.ts'
|
|
26
30
|
import { pushHistory, type HistoryEntry } from 'src/cli/serve/web/state/history.ts'
|
|
27
31
|
import { isPromptInput, promptLanesToText, type PromptInput } from 'src/vars/lanes.ts'
|
|
28
32
|
import { FORM_TIMING, FormSt, type FormTiming, type VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
33
|
+
import { closeTab, openTab, readTabs, renameTab, type DraftTab } from 'src/cli/serve/web/state/draftTabs.ts'
|
|
29
34
|
import { logWebError } from 'src/cli/serve/web/logWeb.ts'
|
|
30
35
|
import { asSeedForm } from 'src/cli/serve/web/state/payload.ts'
|
|
31
36
|
import { readUrlSelection, resolveSelection, writeUrlSelection } from 'src/cli/serve/web/state/urlSelection.ts'
|
|
32
37
|
import { RunSt } from 'src/cli/serve/web/state/RunSt.ts'
|
|
38
|
+
import { DEFAULT_MEMORY_BUDGET_MB } from 'src/cli/serve/resultHistory.ts'
|
|
33
39
|
import { asLoraSort, type LoraSort } from 'src/cli/serve/web/state/loraSort.ts'
|
|
34
40
|
import {
|
|
35
41
|
coerceHostValue,
|
|
@@ -59,13 +65,20 @@ export const DEFAULT_LAYOUT: ResultsLayout = 'side'
|
|
|
59
65
|
export const LAYOUTS: {
|
|
60
66
|
id: ResultsLayout
|
|
61
67
|
icon: 'panel-off' | 'panel-bottom' | 'panel-left' | 'panel-side' | 'panel-corner'
|
|
68
|
+
/** the word under the icon, where the results go */
|
|
69
|
+
label: string
|
|
62
70
|
title: string
|
|
63
71
|
}[] = [
|
|
64
|
-
{ id: 'off', icon: 'panel-off', title: 'no preview: the form only' },
|
|
65
|
-
{ id: 'bottom', icon: 'panel-bottom', title: 'results below the form' },
|
|
66
|
-
{ id: 'left', icon: 'panel-left', title: 'results left of the form' },
|
|
67
|
-
{ id: 'side', icon: 'panel-side', title: 'results right of the form' },
|
|
68
|
-
{
|
|
72
|
+
{ id: 'off', icon: 'panel-off', label: 'none', title: 'no preview: the form only' },
|
|
73
|
+
{ id: 'bottom', icon: 'panel-bottom', label: 'below', title: 'results below the form' },
|
|
74
|
+
{ id: 'left', icon: 'panel-left', label: 'left', title: 'results left of the form' },
|
|
75
|
+
{ id: 'side', icon: 'panel-side', label: 'right', title: 'results right of the form' },
|
|
76
|
+
{
|
|
77
|
+
id: 'pinned',
|
|
78
|
+
icon: 'panel-corner',
|
|
79
|
+
label: 'corner',
|
|
80
|
+
title: 'newest image in the bottom right corner, form scrolls under it',
|
|
81
|
+
},
|
|
69
82
|
]
|
|
70
83
|
|
|
71
84
|
function isLayout(raw: unknown): raw is ResultsLayout {
|
|
@@ -81,8 +94,12 @@ type StoredSelection = {
|
|
|
81
94
|
loraFill?: boolean
|
|
82
95
|
/** trigger words under the lora cards */
|
|
83
96
|
loraTriggers?: boolean
|
|
84
|
-
/** lora image size
|
|
97
|
+
/** the single lora image size, before the form and the popup got one each: seeds both */
|
|
85
98
|
loraScale?: number
|
|
99
|
+
/** lora image size factor in the form's lora rows */
|
|
100
|
+
loraFormScale?: number
|
|
101
|
+
/** lora image size factor in the lora popup */
|
|
102
|
+
loraPopupScale?: number
|
|
86
103
|
/** the label column width, px */
|
|
87
104
|
labelWidth?: number
|
|
88
105
|
loraSort?: string
|
|
@@ -96,8 +113,11 @@ type StoredSelection = {
|
|
|
96
113
|
/** results blurred until hovered */
|
|
97
114
|
blur?: boolean
|
|
98
115
|
/** fit = one per row at the panel's width, grid = the slider's size, wrapping */
|
|
116
|
+
/** the fit/grid pair before columns: read once to seed resultsColumns */
|
|
99
117
|
resultsView?: string
|
|
100
118
|
resultsSize?: number
|
|
119
|
+
/** how many results side by side in the preview, 1 = each as wide as the panel */
|
|
120
|
+
resultsColumns?: number
|
|
101
121
|
/** live previews opened to their full text, as `module/name` */
|
|
102
122
|
expandedPreviews?: string[]
|
|
103
123
|
logs?: boolean
|
|
@@ -123,12 +143,25 @@ export function clampLoraScale(raw: unknown): number {
|
|
|
123
143
|
return Math.min(2, Math.max(0.6, Math.round(n * 20) / 20))
|
|
124
144
|
}
|
|
125
145
|
|
|
126
|
-
|
|
146
|
+
/** the form and the popup each keep their own size: the popup is for browsing, so it is
|
|
147
|
+
* usually drawn bigger than the rows under a var */
|
|
148
|
+
export function readLoraScales(stored: StoredSelection): { form: number; popup: number } {
|
|
149
|
+
return {
|
|
150
|
+
form: clampLoraScale(stored.loraFormScale ?? stored.loraScale),
|
|
151
|
+
popup: clampLoraScale(stored.loraPopupScale ?? stored.loraScale),
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** results side by side: one full width image at 1, a thumbnail wall at the top */
|
|
156
|
+
export function clampResultsColumns(raw: unknown): number {
|
|
157
|
+
const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.round(raw) : 1
|
|
158
|
+
return Math.min(8, Math.max(1, n))
|
|
159
|
+
}
|
|
127
160
|
|
|
128
|
-
/** a
|
|
129
|
-
export function
|
|
130
|
-
|
|
131
|
-
return
|
|
161
|
+
/** a blob written before columns keeps its look: fit was one per row, grid about three */
|
|
162
|
+
export function readResultsColumns(stored: StoredSelection): number {
|
|
163
|
+
if (stored.resultsColumns != null) return clampResultsColumns(stored.resultsColumns)
|
|
164
|
+
return stored.resultsView === 'grid' ? 3 : 1
|
|
132
165
|
}
|
|
133
166
|
|
|
134
167
|
export const DEFAULT_LABEL_WIDTH = 120
|
|
@@ -165,6 +198,11 @@ export class WebSt {
|
|
|
165
198
|
bootError = ''
|
|
166
199
|
modules: ModuleDescription[] = []
|
|
167
200
|
loadErrors: Record<string, string> = {}
|
|
201
|
+
/** the menu's read-only cards: where `.comfy-ts/` lives, and the folder serve scanned */
|
|
202
|
+
workspace: PathLabel | null = null
|
|
203
|
+
root: PathLabel | null = null
|
|
204
|
+
/** the phone drawer (the menu column at 760px and below) */
|
|
205
|
+
menuOpen = false
|
|
168
206
|
form: FormSt | null = null
|
|
169
207
|
formLoading = false
|
|
170
208
|
formError: string | null = null
|
|
@@ -175,8 +213,10 @@ export class WebSt {
|
|
|
175
213
|
loraFill: boolean
|
|
176
214
|
/** trigger words under each lora card: off by default, the words are reference, not a control */
|
|
177
215
|
showLoraTriggers: boolean
|
|
178
|
-
/** how big
|
|
179
|
-
|
|
216
|
+
/** how big lora images are drawn in the form's rows, 1 = the base card size */
|
|
217
|
+
loraFormScale: number
|
|
218
|
+
/** how big lora images are drawn in the lora popup, 1 = the base card size */
|
|
219
|
+
loraPopupScale: number
|
|
180
220
|
loraSort: LoraSort
|
|
181
221
|
/** how many lora cards the popup draws. A cap exists because each card is an image
|
|
182
222
|
* request; how many is a MACHINE question (your box, your collection), so it is yours */
|
|
@@ -188,7 +228,13 @@ export class WebSt {
|
|
|
188
228
|
omnibox: OmniboxSt
|
|
189
229
|
/** SERVER settings, not browser ones: they decide whether a generation writes files at all
|
|
190
230
|
* and where, so they are shared by every client and read back from GET /settings */
|
|
191
|
-
settings: ServeSettings = {
|
|
231
|
+
settings: ServeSettings = {
|
|
232
|
+
saveToDisk: true,
|
|
233
|
+
hostOverride: {},
|
|
234
|
+
savePrefix: {},
|
|
235
|
+
memoryBudgetMb: DEFAULT_MEMORY_BUDGET_MB,
|
|
236
|
+
effectivePrefix: {},
|
|
237
|
+
}
|
|
192
238
|
savingError: string | null = null
|
|
193
239
|
/** what you are typing in a prefix field, before the debounced write lands */
|
|
194
240
|
private prefixEdits: Record<string, string> = {}
|
|
@@ -261,7 +307,9 @@ export class WebSt {
|
|
|
261
307
|
this.showLoraTitles = stored.loraTitles ?? true
|
|
262
308
|
this.loraFill = stored.loraFill ?? true
|
|
263
309
|
this.showLoraTriggers = stored.loraTriggers ?? false
|
|
264
|
-
|
|
310
|
+
const loraScales = readLoraScales(stored)
|
|
311
|
+
this.loraFormScale = loraScales.form
|
|
312
|
+
this.loraPopupScale = loraScales.popup
|
|
265
313
|
this.loraSort = asLoraSort(stored.loraSort)
|
|
266
314
|
// marked in the blob, so the bump happens once and a deliberate 60 sticks after it
|
|
267
315
|
this.loraCap = clampLoraCap(
|
|
@@ -269,8 +317,7 @@ export class WebSt {
|
|
|
269
317
|
)
|
|
270
318
|
this.latentMode = asLatentMode(stored.latent)
|
|
271
319
|
this.blurResults = stored.blur ?? false
|
|
272
|
-
this.
|
|
273
|
-
this.resultsSize = clampResultsSize(stored.resultsSize)
|
|
320
|
+
this.resultsColumns = readResultsColumns(stored)
|
|
274
321
|
this.expandedPreviews = Array.isArray(stored.expandedPreviews)
|
|
275
322
|
? stored.expandedPreviews.filter((x): x is string => typeof x === 'string')
|
|
276
323
|
: []
|
|
@@ -314,8 +361,13 @@ export class WebSt {
|
|
|
314
361
|
this.persist()
|
|
315
362
|
}
|
|
316
363
|
|
|
317
|
-
|
|
318
|
-
this.
|
|
364
|
+
setLoraFormScale(v: number): void {
|
|
365
|
+
this.loraFormScale = clampLoraScale(v)
|
|
366
|
+
this.persist()
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
setLoraPopupScale(v: number): void {
|
|
370
|
+
this.loraPopupScale = clampLoraScale(v)
|
|
319
371
|
this.persist()
|
|
320
372
|
}
|
|
321
373
|
|
|
@@ -403,15 +455,15 @@ export class WebSt {
|
|
|
403
455
|
loraTitles: this.showLoraTitles,
|
|
404
456
|
loraFill: this.loraFill,
|
|
405
457
|
loraTriggers: this.showLoraTriggers,
|
|
406
|
-
|
|
458
|
+
loraFormScale: this.loraFormScale,
|
|
459
|
+
loraPopupScale: this.loraPopupScale,
|
|
407
460
|
loraSort: this.loraSort,
|
|
408
461
|
loraCap: this.loraCap,
|
|
409
462
|
loraCapMigrated: true,
|
|
410
463
|
layout: this.layout,
|
|
411
464
|
latent: this.latentMode,
|
|
412
465
|
blur: this.blurResults,
|
|
413
|
-
|
|
414
|
-
resultsSize: this.resultsSize,
|
|
466
|
+
resultsColumns: this.resultsColumns,
|
|
415
467
|
expandedPreviews: this.expandedPreviews,
|
|
416
468
|
logs: this.showLogs,
|
|
417
469
|
varOrder: this.varOrder,
|
|
@@ -424,6 +476,42 @@ export class WebSt {
|
|
|
424
476
|
}
|
|
425
477
|
}
|
|
426
478
|
|
|
479
|
+
/** the open drafts, left to right. The serve process keeps them (GET/PUT /tabs), never
|
|
480
|
+
* this browser: every window shows the same tabs */
|
|
481
|
+
tabs: readonly DraftTab[] = []
|
|
482
|
+
|
|
483
|
+
private async loadTabs(): Promise<void> {
|
|
484
|
+
try {
|
|
485
|
+
const reply = await fetchTabs()
|
|
486
|
+
const tabs = readTabs(
|
|
487
|
+
reply.tabs,
|
|
488
|
+
this.modules.map((m) => ({ module: m.module, drafts: m.drafts })),
|
|
489
|
+
)
|
|
490
|
+
runInAction(() => {
|
|
491
|
+
this.tabs = tabs
|
|
492
|
+
})
|
|
493
|
+
} catch (e) {
|
|
494
|
+
logWebError('the open tabs could not be read, starting with none', e)
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
private setTabs(next: readonly DraftTab[]): void {
|
|
499
|
+
if (next === this.tabs) return
|
|
500
|
+
this.tabs = next
|
|
501
|
+
saveTabs(next).catch((e: unknown) => logWebError('the open tabs could not be saved', e))
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
get activeTab(): DraftTab | null {
|
|
505
|
+
return this.form == null ? null : { module: this.form.moduleKey, draft: this.form.draft }
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** × on a tab: closing the open one moves to its neighbour, the last tab stays */
|
|
509
|
+
closeTab(t: DraftTab): void {
|
|
510
|
+
const r = closeTab(this.tabs, t, this.activeTab)
|
|
511
|
+
this.setTabs(r.tabs)
|
|
512
|
+
if (r.next != null) void this.select(r.next)
|
|
513
|
+
}
|
|
514
|
+
|
|
427
515
|
moduleByKey(key: string): ModuleDescription | null {
|
|
428
516
|
return this.modules.find((m) => m.module === key) ?? null
|
|
429
517
|
}
|
|
@@ -434,10 +522,13 @@ export class WebSt {
|
|
|
434
522
|
runInAction(() => {
|
|
435
523
|
this.modules = index.workflows
|
|
436
524
|
this.loadErrors = index.loadErrors ?? {}
|
|
525
|
+
this.workspace = index.workspace ?? null
|
|
526
|
+
this.root = index.root ?? null
|
|
437
527
|
this.phase = 'ready'
|
|
438
528
|
})
|
|
439
529
|
void this.loadSettings()
|
|
440
530
|
void this.loadHosts()
|
|
531
|
+
void this.run.loadKept()
|
|
441
532
|
const stored = readStoredSelection()
|
|
442
533
|
// the URL wins over the stored selection: a link someone sent is an instruction, the
|
|
443
534
|
// stored one is only a memory of this browser's last visit
|
|
@@ -452,6 +543,8 @@ export class WebSt {
|
|
|
452
543
|
this.postHost({ comfyTs: 'error', code: 'boot', message: 'no workflows are served' })
|
|
453
544
|
return
|
|
454
545
|
}
|
|
546
|
+
// before the first select, which adds its own tab to the list it read
|
|
547
|
+
await this.loadTabs()
|
|
455
548
|
await this.select(opening)
|
|
456
549
|
if (this.form == null) {
|
|
457
550
|
this.postHost({
|
|
@@ -482,6 +575,9 @@ export class WebSt {
|
|
|
482
575
|
|
|
483
576
|
/** `mirror: false` when a host request will answer with its own `state` right after */
|
|
484
577
|
select(p: { module: string; draft: string }, o: { mirror?: boolean } = {}): Promise<void> {
|
|
578
|
+
// the phone drawer is a way to a draft: arriving there closes it
|
|
579
|
+
this.menuOpen = false
|
|
580
|
+
this.renamingDraft = null
|
|
485
581
|
return this.trackSwitch(this.selectNow(p, o.mirror ?? true))
|
|
486
582
|
}
|
|
487
583
|
|
|
@@ -537,6 +633,7 @@ export class WebSt {
|
|
|
537
633
|
form.onSettled = (): void => this.mirrorState()
|
|
538
634
|
runInAction(() => {
|
|
539
635
|
this.form = form
|
|
636
|
+
this.setTabs(openTab(this.tabs, p))
|
|
540
637
|
this.persist()
|
|
541
638
|
this.syncUrl()
|
|
542
639
|
})
|
|
@@ -813,16 +910,21 @@ export class WebSt {
|
|
|
813
910
|
/** results blurred until the pointer is on them: a screen someone else may see */
|
|
814
911
|
blurResults = false
|
|
815
912
|
|
|
913
|
+
/** the popup listing every key the panel binds */
|
|
914
|
+
showShortcuts = false
|
|
915
|
+
|
|
916
|
+
setShowShortcuts(b: boolean): void {
|
|
917
|
+
this.showShortcuts = b
|
|
918
|
+
}
|
|
919
|
+
|
|
816
920
|
/** the last ⌘P / ⌘O jump: the var it targets reacts to a NEW seq, so pressing it twice works */
|
|
817
921
|
jump: { kind: 'prompt' | 'loras'; seq: number } | null = null
|
|
818
922
|
|
|
819
923
|
requestJump(kind: 'prompt' | 'loras'): void {
|
|
820
924
|
this.jump = { kind, seq: (this.jump?.seq ?? 0) + 1 }
|
|
821
925
|
}
|
|
822
|
-
/**
|
|
823
|
-
|
|
824
|
-
resultsView: 'fit' | 'grid' = 'fit'
|
|
825
|
-
resultsSize = DEFAULT_RESULTS_SIZE
|
|
926
|
+
/** results side by side in the preview, each column an equal share of its width */
|
|
927
|
+
resultsColumns = 1
|
|
826
928
|
/** live previews opened to their full text, as `module/name`; the rest show one line each */
|
|
827
929
|
expandedPreviews: string[] = []
|
|
828
930
|
private logsTimer: ReturnType<typeof setInterval> | null = null
|
|
@@ -839,13 +941,8 @@ export class WebSt {
|
|
|
839
941
|
this.persist()
|
|
840
942
|
}
|
|
841
943
|
|
|
842
|
-
|
|
843
|
-
this.
|
|
844
|
-
this.persist()
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
setResultsSize(px: number): void {
|
|
848
|
-
this.resultsSize = clampResultsSize(px)
|
|
944
|
+
setResultsColumns(n: number): void {
|
|
945
|
+
this.resultsColumns = clampResultsColumns(n)
|
|
849
946
|
this.persist()
|
|
850
947
|
}
|
|
851
948
|
|
|
@@ -854,6 +951,37 @@ export class WebSt {
|
|
|
854
951
|
this.persist()
|
|
855
952
|
}
|
|
856
953
|
|
|
954
|
+
setMenuOpen(open: boolean): void {
|
|
955
|
+
this.menuOpen = open
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
/** the name being typed for the open draft, null when no rename is in progress. Here, not in
|
|
959
|
+
* the menu, because F2 starts it from any focus */
|
|
960
|
+
renamingDraft: string | null = null
|
|
961
|
+
|
|
962
|
+
/** F2 and the rename row. The phone drawer opens so the input is on screen; a folded desktop
|
|
963
|
+
* menu unfolds (App reacts to renamingDraft) */
|
|
964
|
+
startRename(): void {
|
|
965
|
+
if (this.form == null) return
|
|
966
|
+
this.renamingDraft = this.form.draft
|
|
967
|
+
this.menuOpen = true
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
setRenaming(v: string): void {
|
|
971
|
+
this.renamingDraft = v
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
stopRename(): void {
|
|
975
|
+
this.renamingDraft = null
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/** bumped by ⌘B and the ☰: the desktop menu Panel folds or unfolds on each bump */
|
|
979
|
+
menuFoldTick = 0
|
|
980
|
+
|
|
981
|
+
requestMenuFold(): void {
|
|
982
|
+
this.menuFoldTick++
|
|
983
|
+
}
|
|
984
|
+
|
|
857
985
|
toggleLogs(): void {
|
|
858
986
|
this.showLogs = !this.showLogs
|
|
859
987
|
this.persist()
|
|
@@ -1085,7 +1213,16 @@ export class WebSt {
|
|
|
1085
1213
|
)
|
|
1086
1214
|
}
|
|
1087
1215
|
|
|
1088
|
-
|
|
1216
|
+
/** the server evicts at once on a smaller budget, so the usage is re-read after */
|
|
1217
|
+
async setMemoryBudget(mb: number): Promise<void> {
|
|
1218
|
+
if (await this.pushSettings({ memoryBudgetMb: mb })) await this.run.refreshMemory()
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
private async pushSettings(patch: {
|
|
1222
|
+
saveToDisk?: boolean
|
|
1223
|
+
savePrefix?: Record<string, string>
|
|
1224
|
+
memoryBudgetMb?: number
|
|
1225
|
+
}): Promise<boolean> {
|
|
1089
1226
|
try {
|
|
1090
1227
|
const next = await saveSettings(patch)
|
|
1091
1228
|
runInAction(() => {
|
|
@@ -1174,6 +1311,13 @@ export class WebSt {
|
|
|
1174
1311
|
this.modules = this.modules.map((m) =>
|
|
1175
1312
|
m.module === form.moduleKey ? { ...m, drafts: reply.drafts } : m,
|
|
1176
1313
|
)
|
|
1314
|
+
this.setTabs(
|
|
1315
|
+
renameTab(
|
|
1316
|
+
this.tabs,
|
|
1317
|
+
{ module: form.moduleKey, draft: from },
|
|
1318
|
+
{ module: form.moduleKey, draft: name },
|
|
1319
|
+
),
|
|
1320
|
+
)
|
|
1177
1321
|
}),
|
|
1178
1322
|
(e: unknown) =>
|
|
1179
1323
|
runInAction(() => {
|
|
@@ -1192,6 +1336,7 @@ export class WebSt {
|
|
|
1192
1336
|
}
|
|
1193
1337
|
|
|
1194
1338
|
private async deleteDraftNow(p: { module: string; draft: string }): Promise<void> {
|
|
1339
|
+
const neighbour = closeTab(this.tabs, p, this.activeTab).next
|
|
1195
1340
|
const form = this.form
|
|
1196
1341
|
if (form != null && form.moduleKey === p.module && form.draft === p.draft) {
|
|
1197
1342
|
form.dispose({ flush: false })
|
|
@@ -1203,9 +1348,12 @@ export class WebSt {
|
|
|
1203
1348
|
const reply = await deleteDraft(p)
|
|
1204
1349
|
runInAction(() => {
|
|
1205
1350
|
this.modules = this.modules.map((m) => (m.module === p.module ? { ...m, drafts: reply.drafts } : m))
|
|
1351
|
+
this.setTabs(this.tabs.filter((t) => t.module !== p.module || t.draft !== p.draft))
|
|
1206
1352
|
})
|
|
1353
|
+
// only when the open draft was the one deleted: its neighbour tab first, else the rule
|
|
1354
|
+
if (this.form != null) return
|
|
1207
1355
|
const fallback = reply.drafts.includes('default') ? 'default' : (reply.drafts[0] ?? 'default')
|
|
1208
|
-
await this.select({ module: p.module, draft: fallback })
|
|
1356
|
+
await this.select(neighbour ?? { module: p.module, draft: fallback })
|
|
1209
1357
|
} catch (e) {
|
|
1210
1358
|
runInAction(() => {
|
|
1211
1359
|
this.formError = e instanceof Error ? e.message : String(e)
|
|
@@ -1220,6 +1368,21 @@ export class WebSt {
|
|
|
1220
1368
|
await this.createDraft(rawName, form.valuesJSON())
|
|
1221
1369
|
}
|
|
1222
1370
|
|
|
1371
|
+
/** ⌘D and the duplicate row: a copy of what is on screen, auto-named, opened */
|
|
1372
|
+
duplicateCurrentDraft(): Promise<void> {
|
|
1373
|
+
const form = this.form
|
|
1374
|
+
if (form == null) return Promise.resolve()
|
|
1375
|
+
const drafts = this.moduleByKey(form.moduleKey)?.drafts ?? [form.draft]
|
|
1376
|
+
return this.duplicateDraft(duplicateDraftName(form.draft, drafts))
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/** the new draft row: the workflow's own values, auto-named, opened */
|
|
1380
|
+
newDraftFromDefaults(): Promise<void> {
|
|
1381
|
+
const form = this.form
|
|
1382
|
+
if (form == null) return Promise.resolve()
|
|
1383
|
+
return this.newDraft(freeDraftName(this.moduleByKey(form.moduleKey)?.drafts ?? []))
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1223
1386
|
/** a new draft from the workflow's OWN values (the ones in its code), not the open draft's */
|
|
1224
1387
|
async newDraft(rawName: string): Promise<void> {
|
|
1225
1388
|
const form = this.form
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// the names new and duplicate give a draft without asking: rename is one click away, a prompt on
|
|
2
|
+
// every copy is not. PURE, tests/serve-web-draft-names.test.ts
|
|
3
|
+
import { copyName } from 'src/utils/copyName.ts'
|
|
4
|
+
|
|
5
|
+
/** `new`, `new 2`, … the first name no draft of this workflow has */
|
|
6
|
+
export function freeDraftName(drafts: readonly string[]): string {
|
|
7
|
+
if (!drafts.includes('new')) return 'new'
|
|
8
|
+
let n = 2
|
|
9
|
+
while (drafts.includes(`new ${n}`)) n++
|
|
10
|
+
return `new ${n}`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** `shot 007` → `shot 008`, `default` → `default-2`, never a name already taken */
|
|
14
|
+
export function duplicateDraftName(from: string, drafts: readonly string[]): string {
|
|
15
|
+
return copyName(from, drafts)
|
|
16
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// the open drafts as tabs: pure list operations and key reads, the store (WebSt) owns when they run
|
|
2
|
+
export type DraftTab = { module: string; draft: string }
|
|
3
|
+
|
|
4
|
+
/** where the serve process keeps them, under .comfy-ts/: draft names are private, so this file
|
|
5
|
+
* must stay gitignored (tests/serve-tabs.test.ts runs git check-ignore on it) */
|
|
6
|
+
export const SERVE_TABS_FILE = 'serve-tabs.json'
|
|
7
|
+
|
|
8
|
+
const same = (a: DraftTab, b: DraftTab): boolean => a.module === b.module && a.draft === b.draft
|
|
9
|
+
|
|
10
|
+
/** a draft you open gets a tab at the end; one already open keeps its place */
|
|
11
|
+
export function openTab(tabs: readonly DraftTab[], t: DraftTab): readonly DraftTab[] {
|
|
12
|
+
return tabs.some((x) => same(x, t)) ? tabs : [...tabs, { module: t.module, draft: t.draft }]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** `next` is where to go: the right neighbour of the closed OPEN tab, else its left one, null
|
|
16
|
+
* when the open tab stays. The last tab stays: a draft is always open */
|
|
17
|
+
export function closeTab(
|
|
18
|
+
tabs: readonly DraftTab[],
|
|
19
|
+
t: DraftTab,
|
|
20
|
+
active: DraftTab | null,
|
|
21
|
+
): { tabs: readonly DraftTab[]; next: DraftTab | null } {
|
|
22
|
+
const ix = tabs.findIndex((x) => same(x, t))
|
|
23
|
+
if (ix < 0 || tabs.length <= 1) return { tabs, next: null }
|
|
24
|
+
const rest = tabs.filter((_, i) => i !== ix)
|
|
25
|
+
if (active == null || !same(active, t)) return { tabs: rest, next: null }
|
|
26
|
+
return { tabs: rest, next: rest[Math.min(ix, rest.length - 1)] ?? null }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** the renamed draft keeps the tab's place, even when the switch already opened it at the end */
|
|
30
|
+
export function renameTab(tabs: readonly DraftTab[], from: DraftTab, to: DraftTab): readonly DraftTab[] {
|
|
31
|
+
const ix = tabs.findIndex((x) => same(x, from))
|
|
32
|
+
const rest = tabs.filter((x) => !same(x, to))
|
|
33
|
+
if (ix < 0) return openTab(rest, to)
|
|
34
|
+
return rest.map((x) => (same(x, from) ? { module: to.module, draft: to.draft } : x))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** ⌘1 to ⌘8 (ctrl elsewhere) the nth tab, ⌘9 the last one, as browsers do */
|
|
38
|
+
export function tabForKey(
|
|
39
|
+
tabs: readonly DraftTab[],
|
|
40
|
+
e: { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean },
|
|
41
|
+
): DraftTab | null {
|
|
42
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
|
|
43
|
+
if (!/^[1-9]$/.test(e.key)) return null
|
|
44
|
+
const n = Number(e.key)
|
|
45
|
+
return (n === 9 ? tabs[tabs.length - 1] : tabs[n - 1]) ?? null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** ⌘PageUp / ⌘PageDown (ctrl elsewhere): the previous or next tab, wrapping at the ends */
|
|
49
|
+
export function tabStepForKey(
|
|
50
|
+
tabs: readonly DraftTab[],
|
|
51
|
+
active: DraftTab | null,
|
|
52
|
+
e: { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean },
|
|
53
|
+
): DraftTab | null {
|
|
54
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
|
|
55
|
+
const dir = e.key === 'PageDown' ? 1 : e.key === 'PageUp' ? -1 : 0
|
|
56
|
+
if (dir === 0 || tabs.length < 2) return null
|
|
57
|
+
const ix = active == null ? -1 : tabs.findIndex((x) => same(x, active))
|
|
58
|
+
if (ix < 0) return (dir > 0 ? tabs[0] : tabs[tabs.length - 1]) ?? null
|
|
59
|
+
return tabs[(ix + dir + tabs.length) % tabs.length] ?? null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** a stored list, shape-checked, keeping only drafts that still exist */
|
|
63
|
+
export function readTabs(raw: unknown, modules: readonly { module: string; drafts: readonly string[] }[]): DraftTab[] {
|
|
64
|
+
if (!Array.isArray(raw)) return []
|
|
65
|
+
const out: DraftTab[] = []
|
|
66
|
+
for (const x of raw as unknown[]) {
|
|
67
|
+
if (x == null || typeof x !== 'object') continue
|
|
68
|
+
const o = x as { module?: unknown; draft?: unknown }
|
|
69
|
+
if (typeof o.module !== 'string' || typeof o.draft !== 'string') continue
|
|
70
|
+
const t = { module: o.module, draft: o.draft }
|
|
71
|
+
if (!modules.some((m) => m.module === t.module && m.drafts.includes(t.draft))) continue
|
|
72
|
+
if (!out.some((y) => same(y, t))) out.push(t)
|
|
73
|
+
}
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** the output row's slot in the stored field order. A var name is a js identifier, so it can
|
|
2
|
+
* never collide with this */
|
|
3
|
+
export const OUTPUT_ROW = ':output'
|
|
4
|
+
|
|
5
|
+
/** every row the form draws, in the workflow's order: its vars, then the output. A stored order
|
|
6
|
+
* that predates the output slot keeps the output last (orderedVars appends unknown names) */
|
|
7
|
+
export function formRowNames(varNames: readonly string[]): string[] {
|
|
8
|
+
return [...varNames, OUTPUT_ROW]
|
|
9
|
+
}
|
|
@@ -9,7 +9,7 @@ export function generateButtonLook(p: { isRunning: boolean; percent: number | nu
|
|
|
9
9
|
running: boolean
|
|
10
10
|
} {
|
|
11
11
|
return {
|
|
12
|
-
label: '
|
|
12
|
+
label: 'Run',
|
|
13
13
|
fill: p.isRunning ? Math.max(0, Math.min(100, Math.round(p.percent ?? 0))) : null,
|
|
14
14
|
running: p.isRunning,
|
|
15
15
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// the page's results after a reload: what the serve process kept, merged with what this page
|
|
2
|
+
// already holds (a run can finish while the list is in flight). PURE, headless-tested
|
|
3
|
+
import { KEPT_RUNS } from 'src/cli/serve/resultHistory.ts'
|
|
4
|
+
|
|
5
|
+
type Run = { promptId: string; finishedAt?: number }
|
|
6
|
+
|
|
7
|
+
/** one entry per promptId, the page's own copy first, newest first, capped like the server */
|
|
8
|
+
export function mergeKept<R extends Run>(current: readonly R[], kept: readonly R[]): R[] {
|
|
9
|
+
const seen = new Set(current.map((r) => r.promptId))
|
|
10
|
+
const merged = [...current, ...kept.filter((r) => !seen.has(r.promptId))]
|
|
11
|
+
return merged
|
|
12
|
+
.map((r, ix) => ({ r, ix }))
|
|
13
|
+
.sort((a, b) => (b.r.finishedAt ?? 0) - (a.r.finishedAt ?? 0) || a.ix - b.ix)
|
|
14
|
+
.map((x) => x.r)
|
|
15
|
+
.slice(0, KEPT_RUNS)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** an output that only the serve process holds: gone on a restart, or past the memory budget */
|
|
19
|
+
export function isEphemeral(out: { url: string | null; absPath: string | null }): boolean {
|
|
20
|
+
return out.absPath == null && out.url != null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function formatMb(bytes: number): string {
|
|
24
|
+
const mb = bytes / (1024 * 1024)
|
|
25
|
+
return mb < 10 ? mb.toFixed(1) : String(Math.round(mb))
|
|
26
|
+
}
|
|
@@ -42,3 +42,20 @@ export function lightboxView(p: {
|
|
|
42
42
|
return { url: image.url, title: image.filename, promptId: finished?.promptId ?? null }
|
|
43
43
|
return { url: runPreviewSrc({ module, tick: p.previewTick }), title: 'latent preview', promptId: null }
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
/** ↑ / ↓ in the lightbox: the image before or after the open one, in the gallery's order
|
|
47
|
+
* (newest first, then each run's own image order). Stops at both ends. Null = no move */
|
|
48
|
+
export function lightboxStep(p: {
|
|
49
|
+
/** newest first */
|
|
50
|
+
results: readonly LightboxRun[]
|
|
51
|
+
url: string
|
|
52
|
+
dir: 1 | -1
|
|
53
|
+
}): Extract<LightboxTarget, { kind: 'image' }> | null {
|
|
54
|
+
const all = p.results.flatMap((r) =>
|
|
55
|
+
r.images.flatMap((i) => (i.url == null ? [] : [{ url: i.url, title: i.filename, promptId: r.promptId }])),
|
|
56
|
+
)
|
|
57
|
+
const ix = all.findIndex((x) => x.url === p.url)
|
|
58
|
+
if (ix < 0) return null
|
|
59
|
+
const next = all[ix + p.dir]
|
|
60
|
+
return next == null ? null : { kind: 'image', ...next }
|
|
61
|
+
}
|