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
@@ -8,20 +8,29 @@ 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
- import { FormSt, type VarSt } from 'src/cli/serve/web/state/FormSt.ts'
27
+ import { OmniboxSt } from 'src/cli/serve/web/state/OmniboxSt.ts'
28
+ import { duplicateDraftName, freeDraftName } from 'src/cli/serve/web/state/draftNames.ts'
29
+ import { asLatentMode, type LatentMode } from 'src/cli/serve/web/state/latentMode.ts'
30
+ import { pushHistory, type HistoryEntry } from 'src/cli/serve/web/state/history.ts'
31
+ import { isPromptInput, promptLanesToText, type PromptInput } from 'src/vars/lanes.ts'
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'
25
34
  import { logWebError } from 'src/cli/serve/web/logWeb.ts'
26
35
  import { asSeedForm } from 'src/cli/serve/web/state/payload.ts'
27
36
  import { readUrlSelection, resolveSelection, writeUrlSelection } from 'src/cli/serve/web/state/urlSelection.ts'
@@ -55,13 +64,20 @@ export const DEFAULT_LAYOUT: ResultsLayout = 'side'
55
64
  export const LAYOUTS: {
56
65
  id: ResultsLayout
57
66
  icon: 'panel-off' | 'panel-bottom' | 'panel-left' | 'panel-side' | 'panel-corner'
67
+ /** the word under the icon, where the results go */
68
+ label: string
58
69
  title: string
59
70
  }[] = [
60
- { id: 'off', icon: 'panel-off', title: 'no preview: the form only' },
61
- { id: 'bottom', icon: 'panel-bottom', title: 'results below the form' },
62
- { id: 'left', icon: 'panel-left', title: 'results left of the form' },
63
- { id: 'side', icon: 'panel-side', title: 'results right of the form' },
64
- { id: 'pinned', icon: 'panel-corner', title: 'newest image in the bottom right corner, form scrolls under it' },
71
+ { id: 'off', icon: 'panel-off', label: 'none', title: 'no preview: the form only' },
72
+ { id: 'bottom', icon: 'panel-bottom', label: 'below', title: 'results below the form' },
73
+ { id: 'left', icon: 'panel-left', label: 'left', title: 'results left of the form' },
74
+ { id: 'side', icon: 'panel-side', label: 'right', title: 'results right of the form' },
75
+ {
76
+ id: 'pinned',
77
+ icon: 'panel-corner',
78
+ label: 'corner',
79
+ title: 'newest image in the bottom right corner, form scrolls under it',
80
+ },
65
81
  ]
66
82
 
67
83
  function isLayout(raw: unknown): raw is ResultsLayout {
@@ -71,21 +87,43 @@ function isLayout(raw: unknown): raw is ResultsLayout {
71
87
  type StoredSelection = {
72
88
  module?: string
73
89
  draft?: string
74
- sidebar?: boolean
75
90
  loraImages?: boolean
76
91
  loraTitles?: boolean
77
92
  /** lora previews fill their card (cover) instead of fitting inside it (contain) */
78
93
  loraFill?: boolean
94
+ /** trigger words under the lora cards */
95
+ loraTriggers?: boolean
96
+ /** the single lora image size, before the form and the popup got one each: seeds both */
97
+ loraScale?: number
98
+ /** lora image size factor in the form's lora rows */
99
+ loraFormScale?: number
100
+ /** lora image size factor in the lora popup */
101
+ loraPopupScale?: number
102
+ /** the label column width, px */
103
+ labelWidth?: number
79
104
  loraSort?: string
80
105
  /** how many lora cards the popup draws before it stops */
81
106
  loraCap?: number
82
107
  /** the one-shot 60 → 200 default bump already happened for this browser */
83
108
  loraCapMigrated?: boolean
84
109
  layout?: string
85
- latent?: boolean
110
+ /** a LatentMode; a boolean in blobs written before the corner mode */
111
+ latent?: boolean | string
112
+ /** results blurred until hovered */
113
+ blur?: boolean
114
+ /** fit = one per row at the panel's width, grid = the slider's size, wrapping */
115
+ /** the fit/grid pair before columns: read once to seed resultsColumns */
116
+ resultsView?: string
117
+ resultsSize?: number
118
+ /** how many results side by side in the preview, 1 = each as wide as the panel */
119
+ resultsColumns?: number
120
+ /** live previews opened to their full text, as `module/name` */
121
+ expandedPreviews?: string[]
86
122
  logs?: boolean
87
123
  /** module key → the var names in the order you dragged them into */
88
124
  varOrder?: Record<string, string[]>
125
+ /** starred size presets per `module/var`, once you star or unstar one yourself */
126
+ sizeStars?: Record<string, string[]>
89
127
  }
90
128
 
91
129
  /** varOrder is the one stored field a reader INDEXES rather than merely reads, so a blob of
@@ -97,6 +135,41 @@ export const DEFAULT_LORA_CAP = 200
97
135
  const LEGACY_LORA_CAP = 60
98
136
  /** an upper bound, not a policy: 2000 cards is 2000 image requests, and a number typed by
99
137
  * hand (or restored from an older blob) must not be able to hang the page */
138
+ /** lora images from a little smaller to twice the base size: the right size depends on the
139
+ * collection (art crops well small, a character sheet needs room) and on the screen */
140
+ export function clampLoraScale(raw: unknown): number {
141
+ const n = typeof raw === 'number' && Number.isFinite(raw) ? raw : 1
142
+ return Math.min(2, Math.max(0.6, Math.round(n * 20) / 20))
143
+ }
144
+
145
+ /** the form and the popup each keep their own size: the popup is for browsing, so it is
146
+ * usually drawn bigger than the rows under a var */
147
+ export function readLoraScales(stored: StoredSelection): { form: number; popup: number } {
148
+ return {
149
+ form: clampLoraScale(stored.loraFormScale ?? stored.loraScale),
150
+ popup: clampLoraScale(stored.loraPopupScale ?? stored.loraScale),
151
+ }
152
+ }
153
+
154
+ /** results side by side: one full width image at 1, a thumbnail wall at the top */
155
+ export function clampResultsColumns(raw: unknown): number {
156
+ const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.round(raw) : 1
157
+ return Math.min(8, Math.max(1, n))
158
+ }
159
+
160
+ /** a blob written before columns keeps its look: fit was one per row, grid about three */
161
+ export function readResultsColumns(stored: StoredSelection): number {
162
+ if (stored.resultsColumns != null) return clampResultsColumns(stored.resultsColumns)
163
+ return stored.resultsView === 'grid' ? 3 : 1
164
+ }
165
+
166
+ export const DEFAULT_LABEL_WIDTH = 120
167
+
168
+ export function clampLabelWidth(raw: unknown): number {
169
+ const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.round(raw) : DEFAULT_LABEL_WIDTH
170
+ return Math.min(360, Math.max(60, n))
171
+ }
172
+
100
173
  export function clampLoraCap(raw: unknown): number {
101
174
  const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.floor(raw) : DEFAULT_LORA_CAP
102
175
  return Math.min(2000, Math.max(1, n))
@@ -113,31 +186,36 @@ function readVarOrder(raw: unknown): Record<string, string[]> {
113
186
  function readStoredSelection(): StoredSelection {
114
187
  try {
115
188
  const raw = (JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}') ?? {}) as StoredSelection
116
- return { ...raw, varOrder: readVarOrder(raw.varOrder) }
189
+ return { ...raw, varOrder: readVarOrder(raw.varOrder), sizeStars: readVarOrder(raw.sizeStars) }
117
190
  } catch {
118
191
  return {}
119
192
  }
120
193
  }
121
194
 
122
- function isNarrowScreen(): boolean {
123
- return window.matchMedia('(max-width: 800px)').matches
124
- }
125
-
126
195
  export class WebSt {
127
196
  phase: 'loading' | 'error' | 'ready' = 'loading'
128
197
  bootError = ''
129
198
  modules: ModuleDescription[] = []
130
199
  loadErrors: Record<string, string> = {}
200
+ /** the menu's read-only cards: where `.comfy-ts/` lives, and the folder serve scanned */
201
+ workspace: PathLabel | null = null
202
+ root: PathLabel | null = null
203
+ /** the phone drawer (the menu column at 760px and below) */
204
+ menuOpen = false
131
205
  form: FormSt | null = null
132
206
  formLoading = false
133
207
  formError: string | null = null
134
- /** drawer on narrow screens, collapsible column on wide ones — stored toggle wins over the width default */
135
- sidebarOpen: boolean
136
208
  /** lora image/title visibility, EVERY lora surface (row cards + popup) — the hide toggles are NSFW screens */
137
209
  showLoraImages: boolean
138
210
  showLoraTitles: boolean
139
211
  /** cover vs contain for every lora preview: art crops well, a character sheet does not */
140
212
  loraFill: boolean
213
+ /** trigger words under each lora card: off by default, the words are reference, not a control */
214
+ showLoraTriggers: boolean
215
+ /** how big lora images are drawn in the form's rows, 1 = the base card size */
216
+ loraFormScale: number
217
+ /** how big lora images are drawn in the lora popup, 1 = the base card size */
218
+ loraPopupScale: number
141
219
  loraSort: LoraSort
142
220
  /** how many lora cards the popup draws. A cap exists because each card is an image
143
221
  * request; how many is a MACHINE question (your box, your collection), so it is yours */
@@ -145,6 +223,8 @@ export class WebSt {
145
223
  run: RunSt
146
224
  /** prompt refiner: own store, own localStorage blob (the openrouter key never leaves the browser) */
147
225
  enhancer: EnhancerSt
226
+ /** ⌘K / ⌘J: every workflow and draft, fuzzy matched */
227
+ omnibox: OmniboxSt
148
228
  /** SERVER settings, not browser ones: they decide whether a generation writes files at all
149
229
  * and where, so they are shared by every client and read back from GET /settings */
150
230
  settings: ServeSettings = { saveToDisk: true, hostOverride: {}, savePrefix: {}, effectivePrefix: {} }
@@ -158,10 +238,16 @@ export class WebSt {
158
238
  }
159
239
  /** where the results go — hand-tuned, so it persists and restores */
160
240
  layout: ResultsLayout
241
+ /** where `show preview` brings the panel back to, after `off` hid it with its own buttons */
242
+ lastShownLayout: ResultsLayout = DEFAULT_LAYOUT
161
243
  /** var row order per module. A UI preference, so it lives in the browser blob: the draft
162
244
  * file is the var VALUES contract shared with the TUI, and a layout key there would have to
163
245
  * be filtered out by every reader of it */
164
246
  varOrder: Record<string, string[]> = {}
247
+ /** your own starred size presets per `module/var`; absent = the var's defaults */
248
+ sizeStars: Record<string, string[]> = {}
249
+ /** the label column width, dragged by its edge */
250
+ labelWidth = DEFAULT_LABEL_WIDTH
165
251
 
166
252
  /** the form's vars in YOUR order, with anything unknown (a new var) kept at the end */
167
253
  orderedVars(moduleKey: string, names: readonly string[]): string[] {
@@ -199,39 +285,50 @@ export class WebSt {
199
285
  * index is still loading needs a form, and dropping it was the silent failure */
200
286
  private hostChain: Promise<void> = Promise.resolve()
201
287
 
202
- constructor() {
288
+ constructor(private formTiming: FormTiming = FORM_TIMING) {
203
289
  this.run = new RunSt()
204
290
  // a finished run reports the seed it used; the form shows it, and the autosave carries it
205
291
  // into the draft, which is also what the server continues from, so `+` keeps stepping
206
292
  this.run.onSeeds = (p): void => this.applyRunSeeds(p)
207
- this.enhancer = new EnhancerSt()
293
+ this.enhancer = new EnhancerSt(() => this.form)
294
+ this.omnibox = new OmniboxSt(this)
208
295
  const stored = readStoredSelection()
209
296
  // a stored 'auto' from before the mode was removed resolves to what it MEANT on a
210
297
  // wide screen, which is where it spent most of its life
211
298
  this.layout = isLayout(stored.layout) ? stored.layout : DEFAULT_LAYOUT
212
- // CLOSED by default, on every width: the panel is a form, and a workflow tree taking a
213
- // column of it before you have asked for one is chrome. It reopens from the workflow box
214
- this.sidebarOpen = stored.sidebar ?? false
215
299
  this.showLoraImages = stored.loraImages ?? true
216
300
  this.showLoraTitles = stored.loraTitles ?? true
217
301
  this.loraFill = stored.loraFill ?? true
302
+ this.showLoraTriggers = stored.loraTriggers ?? false
303
+ const loraScales = readLoraScales(stored)
304
+ this.loraFormScale = loraScales.form
305
+ this.loraPopupScale = loraScales.popup
218
306
  this.loraSort = asLoraSort(stored.loraSort)
219
307
  // marked in the blob, so the bump happens once and a deliberate 60 sticks after it
220
308
  this.loraCap = clampLoraCap(
221
309
  stored.loraCapMigrated !== true && stored.loraCap === LEGACY_LORA_CAP ? DEFAULT_LORA_CAP : stored.loraCap,
222
310
  )
223
- this.showLatent = stored.latent ?? true
311
+ this.latentMode = asLatentMode(stored.latent)
312
+ this.blurResults = stored.blur ?? false
313
+ this.resultsColumns = readResultsColumns(stored)
314
+ this.expandedPreviews = Array.isArray(stored.expandedPreviews)
315
+ ? stored.expandedPreviews.filter((x): x is string => typeof x === 'string')
316
+ : []
224
317
  this.varOrder = stored.varOrder ?? {}
318
+ this.sizeStars = stored.sizeStars ?? {}
319
+ this.labelWidth = clampLabelWidth(stored.labelWidth)
225
320
  this.showLogs = stored.logs ?? false
226
- makeAutoObservable<WebSt, 'hostOrigin' | 'hostChain' | 'lastPostedState' | 'switches'>(this, {
321
+ makeAutoObservable<WebSt, 'hostOrigin' | 'hostChain' | 'lastPostedState' | 'switches' | 'formTiming'>(this, {
227
322
  run: false,
228
323
  enhancer: false,
324
+ omnibox: false,
229
325
  form: observableRef,
230
326
  modules: observableShallow,
231
327
  hostOrigin: false,
232
328
  hostChain: false,
233
329
  lastPostedState: false,
234
330
  switches: false,
331
+ formTiming: false,
235
332
  })
236
333
  // inside a host page → listen for what it asks; a plain tab never sees a message
237
334
  if (isEmbedded()) window.addEventListener('message', (e) => this.onHostMessage(e))
@@ -246,8 +343,29 @@ export class WebSt {
246
343
  this.hostChain = this.boot().catch((e: unknown) => logWebError('panel boot failed', e))
247
344
  }
248
345
 
249
- toggleSidebar(): void {
250
- this.sidebarOpen = !this.sidebarOpen
346
+ /** live while dragging, persisted once on release: a write per pointer move is wasted work */
347
+ setLabelWidth(px: number, persist: boolean): void {
348
+ this.labelWidth = clampLabelWidth(px)
349
+ if (persist) this.persist()
350
+ }
351
+
352
+ setSizeStars(key: string, stars: string[]): void {
353
+ this.sizeStars[key] = stars
354
+ this.persist()
355
+ }
356
+
357
+ setLoraFormScale(v: number): void {
358
+ this.loraFormScale = clampLoraScale(v)
359
+ this.persist()
360
+ }
361
+
362
+ setLoraPopupScale(v: number): void {
363
+ this.loraPopupScale = clampLoraScale(v)
364
+ this.persist()
365
+ }
366
+
367
+ toggleLoraTriggers(): void {
368
+ this.showLoraTriggers = !this.showLoraTriggers
251
369
  this.persist()
252
370
  }
253
371
 
@@ -318,7 +436,7 @@ export class WebSt {
318
436
 
319
437
  private persist(): void {
320
438
  try {
321
- // merge, never rebuild: toggling the sidebar before a draft loads must not
439
+ // merge, never rebuild: toggling a setting before a draft loads must not
322
440
  // erase the stored selection (this.form is null then)
323
441
  const stored = readStoredSelection()
324
442
  localStorage.setItem(
@@ -326,17 +444,24 @@ export class WebSt {
326
444
  JSON.stringify({
327
445
  ...stored,
328
446
  ...(this.form != null ? { module: this.form.moduleKey, draft: this.form.draft } : {}),
329
- sidebar: this.sidebarOpen,
330
447
  loraImages: this.showLoraImages,
331
448
  loraTitles: this.showLoraTitles,
332
449
  loraFill: this.loraFill,
450
+ loraTriggers: this.showLoraTriggers,
451
+ loraFormScale: this.loraFormScale,
452
+ loraPopupScale: this.loraPopupScale,
333
453
  loraSort: this.loraSort,
334
454
  loraCap: this.loraCap,
335
455
  loraCapMigrated: true,
336
456
  layout: this.layout,
337
- latent: this.showLatent,
457
+ latent: this.latentMode,
458
+ blur: this.blurResults,
459
+ resultsColumns: this.resultsColumns,
460
+ expandedPreviews: this.expandedPreviews,
338
461
  logs: this.showLogs,
339
462
  varOrder: this.varOrder,
463
+ sizeStars: this.sizeStars,
464
+ labelWidth: this.labelWidth,
340
465
  }),
341
466
  )
342
467
  } catch (e) {
@@ -344,6 +469,42 @@ export class WebSt {
344
469
  }
345
470
  }
346
471
 
472
+ /** the open drafts, left to right. The serve process keeps them (GET/PUT /tabs), never
473
+ * this browser: every window shows the same tabs */
474
+ tabs: readonly DraftTab[] = []
475
+
476
+ private async loadTabs(): Promise<void> {
477
+ try {
478
+ const reply = await fetchTabs()
479
+ const tabs = readTabs(
480
+ reply.tabs,
481
+ this.modules.map((m) => ({ module: m.module, drafts: m.drafts })),
482
+ )
483
+ runInAction(() => {
484
+ this.tabs = tabs
485
+ })
486
+ } catch (e) {
487
+ logWebError('the open tabs could not be read, starting with none', e)
488
+ }
489
+ }
490
+
491
+ private setTabs(next: readonly DraftTab[]): void {
492
+ if (next === this.tabs) return
493
+ this.tabs = next
494
+ saveTabs(next).catch((e: unknown) => logWebError('the open tabs could not be saved', e))
495
+ }
496
+
497
+ get activeTab(): DraftTab | null {
498
+ return this.form == null ? null : { module: this.form.moduleKey, draft: this.form.draft }
499
+ }
500
+
501
+ /** × on a tab: closing the open one moves to its neighbour, the last tab stays */
502
+ closeTab(t: DraftTab): void {
503
+ const r = closeTab(this.tabs, t, this.activeTab)
504
+ this.setTabs(r.tabs)
505
+ if (r.next != null) void this.select(r.next)
506
+ }
507
+
347
508
  moduleByKey(key: string): ModuleDescription | null {
348
509
  return this.modules.find((m) => m.module === key) ?? null
349
510
  }
@@ -354,6 +515,8 @@ export class WebSt {
354
515
  runInAction(() => {
355
516
  this.modules = index.workflows
356
517
  this.loadErrors = index.loadErrors ?? {}
518
+ this.workspace = index.workspace ?? null
519
+ this.root = index.root ?? null
357
520
  this.phase = 'ready'
358
521
  })
359
522
  void this.loadSettings()
@@ -372,6 +535,8 @@ export class WebSt {
372
535
  this.postHost({ comfyTs: 'error', code: 'boot', message: 'no workflows are served' })
373
536
  return
374
537
  }
538
+ // before the first select, which adds its own tab to the list it read
539
+ await this.loadTabs()
375
540
  await this.select(opening)
376
541
  if (this.form == null) {
377
542
  this.postHost({
@@ -402,6 +567,9 @@ export class WebSt {
402
567
 
403
568
  /** `mirror: false` when a host request will answer with its own `state` right after */
404
569
  select(p: { module: string; draft: string }, o: { mirror?: boolean } = {}): Promise<void> {
570
+ // the phone drawer is a way to a draft: arriving there closes it
571
+ this.menuOpen = false
572
+ this.renamingDraft = null
405
573
  return this.trackSwitch(this.selectNow(p, o.mirror ?? true))
406
574
  }
407
575
 
@@ -423,9 +591,6 @@ export class WebSt {
423
591
  // re-picking the draft you are IN is a no-op, not a reload: a pending autosave would
424
592
  // lose the race against the fetch and the typed edit would vanish from the form
425
593
  if (this.form?.moduleKey === p.module && this.form.draft === p.draft) {
426
- runInAction(() => {
427
- if (isNarrowScreen()) this.sidebarOpen = false
428
- })
429
594
  return
430
595
  }
431
596
  const token = ++this.selectToken
@@ -435,8 +600,6 @@ export class WebSt {
435
600
  this.enhancer.close()
436
601
  this.formLoading = true
437
602
  this.formError = null
438
- // picking a draft is the drawer's exit on a phone
439
- if (isNarrowScreen()) this.sidebarOpen = false
440
603
  })
441
604
  // flush the outgoing form BEFORE reading the next one, so a switch never races its own save
442
605
  const outgoing = this.form
@@ -457,11 +620,12 @@ export class WebSt {
457
620
  const reply = await fetchDraftValues(p)
458
621
  // a newer select owns the screen now: telling the host about this one would be a lie
459
622
  if (token !== this.selectToken) return
460
- const form = new FormSt(p.module, p.draft, mod, reply.values ?? {})
623
+ const form = new FormSt(p.module, p.draft, mod, reply.values ?? {}, this.formTiming)
461
624
  // the host mirrors user edits on the autosave's own debounce (pinned only)
462
625
  form.onSettled = (): void => this.mirrorState()
463
626
  runInAction(() => {
464
627
  this.form = form
628
+ this.setTabs(openTab(this.tabs, p))
465
629
  this.persist()
466
630
  this.syncUrl()
467
631
  })
@@ -538,7 +702,7 @@ export class WebSt {
538
702
  }
539
703
 
540
704
  private stateOf(form: FormSt): { key: string; values: Record<string, unknown> } {
541
- const values = form.valuesJSON()
705
+ const values = form.varValues()
542
706
  return { key: safeStringify([form.moduleKey, form.draft, values]), values }
543
707
  }
544
708
 
@@ -690,10 +854,15 @@ export class WebSt {
690
854
 
691
855
  setLayout(next: ResultsLayout): void {
692
856
  // a click SETS the mode. cycling back to a width rule lands where no button is showing
857
+ if (this.layout !== 'off') this.lastShownLayout = this.layout
693
858
  this.layout = next
694
859
  this.persist()
695
860
  }
696
861
 
862
+ showPreview(): void {
863
+ this.setLayout(this.lastShownLayout === 'off' ? DEFAULT_LAYOUT : this.lastShownLayout)
864
+ }
865
+
697
866
  /** the host a module's runs go to right now (override if any, else the module's own) */
698
867
  hostFor(moduleKey: string): string {
699
868
  return this.hosts.overrides[moduleKey] ?? this.hosts.defaults[moduleKey] ?? ''
@@ -728,16 +897,76 @@ export class WebSt {
728
897
  showLogs = false
729
898
  logLines: string[] = []
730
899
  logsError: string | null = null
731
- hostNote: string | null = null
732
- /** the latent frames during a run: on by default, off when you only want the final image */
733
- showLatent = true
900
+ /** the latent frames during a run: full in the running card, small in a corner, or none */
901
+ latentMode: LatentMode = 'corner'
902
+ /** results blurred until the pointer is on them: a screen someone else may see */
903
+ blurResults = false
904
+
905
+ /** the last ⌘P / ⌘O jump: the var it targets reacts to a NEW seq, so pressing it twice works */
906
+ jump: { kind: 'prompt' | 'loras'; seq: number } | null = null
907
+
908
+ requestJump(kind: 'prompt' | 'loras'): void {
909
+ this.jump = { kind, seq: (this.jump?.seq ?? 0) + 1 }
910
+ }
911
+ /** results side by side in the preview, each column an equal share of its width */
912
+ resultsColumns = 1
913
+ /** live previews opened to their full text, as `module/name`; the rest show one line each */
914
+ expandedPreviews: string[] = []
734
915
  private logsTimer: ReturnType<typeof setInterval> | null = null
735
916
 
736
- toggleLatent(): void {
737
- this.showLatent = !this.showLatent
917
+ setLatentMode(v: LatentMode): void {
918
+ this.latentMode = v
919
+ this.persist()
920
+ }
921
+
922
+ togglePreviewExpanded(key: string): void {
923
+ this.expandedPreviews = this.expandedPreviews.includes(key)
924
+ ? this.expandedPreviews.filter((k) => k !== key)
925
+ : [...this.expandedPreviews, key]
738
926
  this.persist()
739
927
  }
740
928
 
929
+ setResultsColumns(n: number): void {
930
+ this.resultsColumns = clampResultsColumns(n)
931
+ this.persist()
932
+ }
933
+
934
+ toggleBlur(): void {
935
+ this.blurResults = !this.blurResults
936
+ this.persist()
937
+ }
938
+
939
+ setMenuOpen(open: boolean): void {
940
+ this.menuOpen = open
941
+ }
942
+
943
+ /** the name being typed for the open draft, null when no rename is in progress. Here, not in
944
+ * the menu, because F2 starts it from any focus */
945
+ renamingDraft: string | null = null
946
+
947
+ /** F2 and the rename row. The phone drawer opens so the input is on screen; a folded desktop
948
+ * menu unfolds (App reacts to renamingDraft) */
949
+ startRename(): void {
950
+ if (this.form == null) return
951
+ this.renamingDraft = this.form.draft
952
+ this.menuOpen = true
953
+ }
954
+
955
+ setRenaming(v: string): void {
956
+ this.renamingDraft = v
957
+ }
958
+
959
+ stopRename(): void {
960
+ this.renamingDraft = null
961
+ }
962
+
963
+ /** bumped by ⌘B and the ☰: the desktop menu Panel folds or unfolds on each bump */
964
+ menuFoldTick = 0
965
+
966
+ requestMenuFold(): void {
967
+ this.menuFoldTick++
968
+ }
969
+
741
970
  toggleLogs(): void {
742
971
  this.showLogs = !this.showLogs
743
972
  this.persist()
@@ -765,46 +994,50 @@ export class WebSt {
765
994
  }
766
995
  }
767
996
 
768
- /** the lora mirror sweep, from the panel: the metadata (names, trigger words, previews) is
769
- * re-downloaded and every surface re-reads it, which needs the descriptors reloaded too */
770
- loraSyncing = false
997
+ /** ONE refresh for everything a host knows: serve refetches its schema and re-reads its lora
998
+ * manager list, then the panel re-reads its workflow descriptions, so the open form offers
999
+ * what the host has now (a new lora, a new model) without a tab reload. The drift check calls
1000
+ * it by itself; the host card's ↻ is the same call, pulsing while it runs */
1001
+ refreshing = false
771
1002
 
772
- async refreshLoras(): Promise<void> {
773
- if (this.loraSyncing) return
1003
+ async refreshHost(): Promise<void> {
1004
+ if (this.refreshing) return
774
1005
  runInAction(() => {
775
- this.loraSyncing = true
1006
+ this.refreshing = true
776
1007
  })
777
- await this.hostAction('refresh-loras')
778
- await this.trackSwitch(this.reloadIndexAndForm())
1008
+ try {
1009
+ await this.hostAction('refresh-schema')
1010
+ await this.trackSwitch(this.reloadIndexAndForm())
1011
+ } finally {
1012
+ runInAction(() => {
1013
+ this.refreshing = false
1014
+ })
1015
+ }
779
1016
  }
780
1017
 
781
- /** what changed on a host since the server loaded its schema, shown on the refetch button of
782
- * that host only. A light check (the loaders, a few KB) runs every minute while the tab is
783
- * visible; a full one (node types too) at boot, after a refetch or a restart, and when a host
784
- * that stopped answering answers again, which is how a restart nobody announced is noticed */
785
- drift: { host: string; summary: string } | null = null
1018
+ /** the host changed since serve loaded its schema: a light check (the loaders, a few KB) every
1019
+ * 15s while the tab is visible, a full one (node types too) at boot and when a host that
1020
+ * stopped answering answers again. A change is not SHOWN, it is applied: refreshHost */
786
1021
  driftDown = false
787
1022
 
788
1023
  private startDriftWatch(): void {
789
1024
  void this.checkDrift(true)
790
1025
  setInterval(() => {
791
1026
  if (document.visibilityState === 'visible') void this.checkDrift(false)
792
- }, 60_000)
1027
+ }, 15_000)
793
1028
  }
794
1029
 
795
1030
  async checkDrift(full: boolean): Promise<void> {
796
1031
  const host = this.form == null ? null : this.hostFor(this.form.moduleKey)
797
- if (host == null || host === '') return
1032
+ if (host == null || host === '' || this.refreshing) return
798
1033
  try {
799
1034
  const r = await fetchHostDrift({ host, full })
800
1035
  const cameBack = this.driftDown
801
1036
  runInAction(() => {
802
1037
  this.driftDown = false
803
- // a clean LIGHT check cannot clear what a full one found (node types it does not see)
804
- if (r.changed) this.drift = { host, summary: r.summary }
805
- else if (full || this.drift?.host !== host) this.drift = null
806
1038
  })
807
- if (cameBack && !full) await this.checkDrift(true)
1039
+ if (r.changed) await this.refreshHost()
1040
+ else if (cameBack && !full) await this.checkDrift(true)
808
1041
  } catch {
809
1042
  runInAction(() => {
810
1043
  this.driftDown = true
@@ -823,13 +1056,9 @@ export class WebSt {
823
1056
  runInAction(() => {
824
1057
  this.loraFetching.add(lora)
825
1058
  this.hostError = null
826
- this.hostNote = null
827
1059
  })
828
1060
  try {
829
- const reply = await postLoraCivitai({ host, lora })
830
- runInAction(() => {
831
- this.hostNote = reply.note
832
- })
1061
+ await postLoraCivitai({ host, lora })
833
1062
  await this.trackSwitch(this.reloadIndexAndForm())
834
1063
  } catch (e) {
835
1064
  runInAction(() => {
@@ -865,10 +1094,6 @@ export class WebSt {
865
1094
  runInAction(() => {
866
1095
  this.hostError = e instanceof Error ? e.message : String(e)
867
1096
  })
868
- } finally {
869
- runInAction(() => {
870
- this.loraSyncing = false
871
- })
872
1097
  }
873
1098
  }
874
1099
 
@@ -898,7 +1123,6 @@ export class WebSt {
898
1123
  if (!up) continue
899
1124
  runInAction(() => {
900
1125
  this.hostWatch = 'back'
901
- this.hostNote = `${host} is back up`
902
1126
  })
903
1127
  void this.checkDrift(true)
904
1128
  setTimeout(() => runInAction(() => (this.hostWatch = 'idle')), 4000)
@@ -912,16 +1136,11 @@ export class WebSt {
912
1136
  if (host == null || host === '') return
913
1137
  runInAction(() => {
914
1138
  this.hostError = null
915
- this.hostNote = null
916
1139
  })
917
1140
  try {
918
- const reply = await postHostAction({ host, action })
919
- runInAction(() => {
920
- this.hostNote = reply.note
921
- })
1141
+ await postHostAction({ host, action })
922
1142
  // a reboot is the one action whose result arrives LATER: watch for it
923
1143
  if (action === 'restart') void this.watchHostComeBack()
924
- if (action === 'refresh-schema') await this.checkDrift(true)
925
1144
  } catch (e) {
926
1145
  runInAction(() => {
927
1146
  this.hostError = e instanceof Error ? e.message : String(e)
@@ -1011,21 +1230,44 @@ export class WebSt {
1011
1230
  })
1012
1231
  }
1013
1232
 
1014
- generate(): void {
1015
- void this.generateNow()
1233
+ /** `override` replaces var values in THIS run only (the enhancer's try): the form and the
1234
+ * draft keep their own */
1235
+ generate(override?: Record<string, unknown>): void {
1236
+ void this.generateNow(override)
1016
1237
  }
1017
1238
 
1018
1239
  /** flush the autosave first: the server reads the draft it just wrote — one source of truth.
1019
1240
  * every click ENQUEUES, so hitting generate n times runs n prompts; the queued payload
1020
1241
  * freezes the values you saw, and seeds stay on the draft's server-side policy */
1021
- private async generateNow(): Promise<void> {
1242
+ private async generateNow(override?: Record<string, unknown>): Promise<void> {
1022
1243
  const form = this.form
1023
1244
  if (form == null) return
1024
- const payload = form.queuePayload()
1245
+ const payload = { ...form.queuePayload(), ...override }
1025
1246
  const saved = await form.save()
1026
1247
  // the header already shows the loud save error; running the stale draft would lie
1027
1248
  if (!saved) return
1028
1249
  this.run.enqueue({ module: form.moduleKey, draft: form.draft, payload })
1250
+ this.recordPrompts(form, payload)
1251
+ }
1252
+
1253
+ /** every prompt var of what was just queued, for the history picker (this page only) */
1254
+ promptHistory: HistoryEntry<PromptInput>[] = []
1255
+
1256
+ /** from the payload that was SENT, so a tried candidate is history like any prompt */
1257
+ private recordPrompts(form: FormSt, payload: Record<string, unknown>): void {
1258
+ const at = Date.now()
1259
+ for (const v of form.vars) {
1260
+ const value = payload[v.name]
1261
+ if (v.desc.kind !== 'prompt' || !isPromptInput(value)) continue
1262
+ // lanes keep their headers in the text, so a search finds a lane by its name too
1263
+ const text = typeof value === 'string' ? value : promptLanesToText(value)
1264
+ this.promptHistory = pushHistory(this.promptHistory, {
1265
+ text,
1266
+ value,
1267
+ at,
1268
+ source: `${form.moduleKey} · ${v.desc.label ?? v.name}`,
1269
+ })
1270
+ }
1029
1271
  }
1030
1272
 
1031
1273
  /** rename = write the values under the new name, switch to it, then drop the old FILE.
@@ -1045,6 +1287,13 @@ export class WebSt {
1045
1287
  this.modules = this.modules.map((m) =>
1046
1288
  m.module === form.moduleKey ? { ...m, drafts: reply.drafts } : m,
1047
1289
  )
1290
+ this.setTabs(
1291
+ renameTab(
1292
+ this.tabs,
1293
+ { module: form.moduleKey, draft: from },
1294
+ { module: form.moduleKey, draft: name },
1295
+ ),
1296
+ )
1048
1297
  }),
1049
1298
  (e: unknown) =>
1050
1299
  runInAction(() => {
@@ -1063,6 +1312,7 @@ export class WebSt {
1063
1312
  }
1064
1313
 
1065
1314
  private async deleteDraftNow(p: { module: string; draft: string }): Promise<void> {
1315
+ const neighbour = closeTab(this.tabs, p, this.activeTab).next
1066
1316
  const form = this.form
1067
1317
  if (form != null && form.moduleKey === p.module && form.draft === p.draft) {
1068
1318
  form.dispose({ flush: false })
@@ -1074,9 +1324,12 @@ export class WebSt {
1074
1324
  const reply = await deleteDraft(p)
1075
1325
  runInAction(() => {
1076
1326
  this.modules = this.modules.map((m) => (m.module === p.module ? { ...m, drafts: reply.drafts } : m))
1327
+ this.setTabs(this.tabs.filter((t) => t.module !== p.module || t.draft !== p.draft))
1077
1328
  })
1329
+ // only when the open draft was the one deleted: its neighbour tab first, else the rule
1330
+ if (this.form != null) return
1078
1331
  const fallback = reply.drafts.includes('default') ? 'default' : (reply.drafts[0] ?? 'default')
1079
- await this.select({ module: p.module, draft: fallback })
1332
+ await this.select(neighbour ?? { module: p.module, draft: fallback })
1080
1333
  } catch (e) {
1081
1334
  runInAction(() => {
1082
1335
  this.formError = e instanceof Error ? e.message : String(e)
@@ -1086,13 +1339,44 @@ export class WebSt {
1086
1339
 
1087
1340
  /** duplicate = save the current values under a new name, then switch to it */
1088
1341
  async duplicateDraft(rawName: string): Promise<void> {
1342
+ const form = this.form
1343
+ if (form == null) return
1344
+ await this.createDraft(rawName, form.valuesJSON())
1345
+ }
1346
+
1347
+ /** ⌘D and the duplicate row: a copy of what is on screen, auto-named, opened */
1348
+ duplicateCurrentDraft(): Promise<void> {
1349
+ const form = this.form
1350
+ if (form == null) return Promise.resolve()
1351
+ const drafts = this.moduleByKey(form.moduleKey)?.drafts ?? [form.draft]
1352
+ return this.duplicateDraft(duplicateDraftName(form.draft, drafts))
1353
+ }
1354
+
1355
+ /** the new draft row: the workflow's own values, auto-named, opened */
1356
+ newDraftFromDefaults(): Promise<void> {
1357
+ const form = this.form
1358
+ if (form == null) return Promise.resolve()
1359
+ return this.newDraft(freeDraftName(this.moduleByKey(form.moduleKey)?.drafts ?? []))
1360
+ }
1361
+
1362
+ /** a new draft from the workflow's OWN values (the ones in its code), not the open draft's */
1363
+ async newDraft(rawName: string): Promise<void> {
1364
+ const form = this.form
1365
+ const mod = form == null ? null : this.moduleByKey(form.moduleKey)
1366
+ if (mod == null) return
1367
+ const values: Record<string, unknown> = {}
1368
+ for (const [name, desc] of Object.entries(mod.vars)) values[name] = desc.default
1369
+ await this.createDraft(rawName, values)
1370
+ }
1371
+
1372
+ private async createDraft(rawName: string, values: Record<string, unknown>): Promise<void> {
1089
1373
  const form = this.form
1090
1374
  const name = rawName.trim()
1091
1375
  if (form == null || name === '') return
1092
1376
  const existing = this.moduleByKey(form.moduleKey)?.drafts.includes(name) === true
1093
1377
  if (existing && !window.confirm(`draft '${name}' already exists — overwrite it?`)) return
1094
1378
  try {
1095
- const reply = await saveDraft({ module: form.moduleKey, draft: name, values: form.valuesJSON() })
1379
+ const reply = await saveDraft({ module: form.moduleKey, draft: name, values })
1096
1380
  runInAction(() => {
1097
1381
  this.modules = this.modules.map((m) => (m.module === form.moduleKey ? { ...m, drafts: reply.drafts } : m))
1098
1382
  })