comfy-ts 2.11.0 → 2.12.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 (99) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-qtFzOKpu.js → LogsSt-U1H0mP1m.js} +35 -5
  3. package/dist/LogsSt-U1H0mP1m.js.map +1 -0
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +473 -62
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +191 -31
  8. package/dist/index.d.ts +191 -31
  9. package/dist/index.js +469 -63
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-BK7BA2dn.js → run-serve-BeAznay5.js} +461 -43
  12. package/dist/run-serve-BeAznay5.js.map +1 -0
  13. package/dist/{run-tui-CQyvMf0N.js → run-tui-BTGjvnKk.js} +43 -18
  14. package/dist/run-tui-BTGjvnKk.js.map +1 -0
  15. package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-Cg39vs53.js} +470 -60
  16. package/dist/schemaDrift-Cg39vs53.js.map +1 -0
  17. package/dist/serve-web.js +508 -134
  18. package/dist/{state--wrz0BQc.js → state-C7REnHan.js} +7 -3
  19. package/dist/{state--wrz0BQc.js.map → state-C7REnHan.js.map} +1 -1
  20. package/dist/web.d.ts +191 -31
  21. package/dist/web.js +469 -63
  22. package/dist/web.js.map +1 -1
  23. package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
  24. package/examples/rvion/10-anima-t2i.cflow.ts +229 -0
  25. package/extra/README.md +4 -0
  26. package/extra/comfyui-fresh-model-lists/README.md +25 -0
  27. package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
  28. package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
  29. package/package.json +15 -7
  30. package/src/cli/draftMeta.ts +39 -0
  31. package/src/cli/serve/ServeApp.ts +148 -12
  32. package/src/cli/serve/applyVarPayload.ts +50 -22
  33. package/src/cli/serve/describeVar.ts +42 -6
  34. package/src/cli/serve/llmConfigShape.ts +51 -0
  35. package/src/cli/serve/llmConfigs.ts +52 -0
  36. package/src/cli/serve/tagList.ts +92 -0
  37. package/src/cli/serve/tagSource.ts +69 -0
  38. package/src/cli/serve/web/api.ts +48 -0
  39. package/src/cli/serve/web/components/App.tsx +336 -44
  40. package/src/cli/serve/web/components/Gallery.tsx +105 -28
  41. package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
  42. package/src/cli/serve/web/components/Icon.tsx +18 -2
  43. package/src/cli/serve/web/components/MenuButton.tsx +53 -0
  44. package/src/cli/serve/web/components/Omnibox.tsx +85 -0
  45. package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
  46. package/src/cli/serve/web/components/TooltipLayer.tsx +45 -0
  47. package/src/cli/serve/web/components/VarIcon.tsx +24 -0
  48. package/src/cli/serve/web/components/VarsForm.tsx +341 -188
  49. package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
  50. package/src/cli/serve/web/components/controls/LorasControl.tsx +644 -317
  51. package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
  52. package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
  53. package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
  54. package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
  55. package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
  56. package/src/cli/serve/web/components/modKey.ts +2 -0
  57. package/src/cli/serve/web/llm.ts +23 -12
  58. package/src/cli/serve/web/promptEditor/promptExtensions.ts +281 -0
  59. package/src/cli/serve/web/state/EnhancerSt.ts +415 -100
  60. package/src/cli/serve/web/state/FormSt.ts +193 -29
  61. package/src/cli/serve/web/state/OmniboxSt.ts +57 -0
  62. package/src/cli/serve/web/state/WebSt.ts +219 -74
  63. package/src/cli/serve/web/state/choiceButtons.ts +61 -0
  64. package/src/cli/serve/web/state/generateButton.ts +16 -0
  65. package/src/cli/serve/web/state/history.ts +54 -0
  66. package/src/cli/serve/web/state/host.ts +5 -2
  67. package/src/cli/serve/web/state/keptLines.ts +53 -0
  68. package/src/cli/serve/web/state/latentMode.ts +20 -0
  69. package/src/cli/serve/web/state/loraSort.ts +18 -0
  70. package/src/cli/serve/web/state/moduleTree.ts +2 -2
  71. package/src/cli/serve/web/state/omnibox.ts +69 -0
  72. package/src/cli/serve/web/state/payload.ts +38 -58
  73. package/src/cli/serve/web/state/shortcuts.ts +54 -0
  74. package/src/cli/serve/web/state/sizeStars.ts +31 -0
  75. package/src/cli/serve/web/state/stableSlots.ts +21 -0
  76. package/src/cli/serve/web/state/varGroups.ts +24 -0
  77. package/src/cli/serve/web/styles.ts +457 -118
  78. package/src/cli/serve/webBundle.ts +54 -10
  79. package/src/cli/tui/components/PickerOverlays.tsx +9 -2
  80. package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
  81. package/src/cli/tui/state/DraftsSt.ts +18 -2
  82. package/src/cli/tui/state/EditorSt.ts +1 -1
  83. package/src/cli/tui/state/LorasSt.ts +1 -1
  84. package/src/cli/tui/state/PickerSt.ts +25 -7
  85. package/src/cli/tui/state/SettingsSt.ts +1 -1
  86. package/src/cli/tui/state/TuiSt.ts +10 -0
  87. package/src/coreExports.ts +20 -0
  88. package/src/host/loraInfoCache.ts +6 -0
  89. package/src/state.ts +5 -0
  90. package/src/vars/ComfyVars.ts +337 -67
  91. package/src/vars/DefinedWorkflow.ts +40 -19
  92. package/src/vars/lanes.ts +238 -0
  93. package/src/vars/loraEntry.ts +101 -0
  94. package/src/vars/promptSyntax.ts +382 -0
  95. package/dist/LogsSt-qtFzOKpu.js.map +0 -1
  96. package/dist/run-serve-BK7BA2dn.js.map +0 -1
  97. package/dist/run-tui-CQyvMf0N.js.map +0 -1
  98. package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
  99. package/src/cli/serve/web/components/Sidebar.tsx +0 -66
@@ -21,7 +21,11 @@ import {
21
21
  type ServeSettings,
22
22
  } from 'src/cli/serve/web/api.ts'
23
23
  import { EnhancerSt } from 'src/cli/serve/web/state/EnhancerSt.ts'
24
- import { FormSt, type VarSt } from 'src/cli/serve/web/state/FormSt.ts'
24
+ import { OmniboxSt } from 'src/cli/serve/web/state/OmniboxSt.ts'
25
+ import { asLatentMode, type LatentMode } from 'src/cli/serve/web/state/latentMode.ts'
26
+ import { pushHistory, type HistoryEntry } from 'src/cli/serve/web/state/history.ts'
27
+ import { isPromptInput, promptLanesToText, type PromptInput } from 'src/vars/lanes.ts'
28
+ import { FORM_TIMING, FormSt, type FormTiming, type VarSt } from 'src/cli/serve/web/state/FormSt.ts'
25
29
  import { logWebError } from 'src/cli/serve/web/logWeb.ts'
26
30
  import { asSeedForm } from 'src/cli/serve/web/state/payload.ts'
27
31
  import { readUrlSelection, resolveSelection, writeUrlSelection } from 'src/cli/serve/web/state/urlSelection.ts'
@@ -71,21 +75,36 @@ function isLayout(raw: unknown): raw is ResultsLayout {
71
75
  type StoredSelection = {
72
76
  module?: string
73
77
  draft?: string
74
- sidebar?: boolean
75
78
  loraImages?: boolean
76
79
  loraTitles?: boolean
77
80
  /** lora previews fill their card (cover) instead of fitting inside it (contain) */
78
81
  loraFill?: boolean
82
+ /** trigger words under the lora cards */
83
+ loraTriggers?: boolean
84
+ /** lora image size factor */
85
+ loraScale?: number
86
+ /** the label column width, px */
87
+ labelWidth?: number
79
88
  loraSort?: string
80
89
  /** how many lora cards the popup draws before it stops */
81
90
  loraCap?: number
82
91
  /** the one-shot 60 → 200 default bump already happened for this browser */
83
92
  loraCapMigrated?: boolean
84
93
  layout?: string
85
- latent?: boolean
94
+ /** a LatentMode; a boolean in blobs written before the corner mode */
95
+ latent?: boolean | string
96
+ /** results blurred until hovered */
97
+ blur?: boolean
98
+ /** fit = one per row at the panel's width, grid = the slider's size, wrapping */
99
+ resultsView?: string
100
+ resultsSize?: number
101
+ /** live previews opened to their full text, as `module/name` */
102
+ expandedPreviews?: string[]
86
103
  logs?: boolean
87
104
  /** module key → the var names in the order you dragged them into */
88
105
  varOrder?: Record<string, string[]>
106
+ /** starred size presets per `module/var`, once you star or unstar one yourself */
107
+ sizeStars?: Record<string, string[]>
89
108
  }
90
109
 
91
110
  /** varOrder is the one stored field a reader INDEXES rather than merely reads, so a blob of
@@ -97,6 +116,28 @@ export const DEFAULT_LORA_CAP = 200
97
116
  const LEGACY_LORA_CAP = 60
98
117
  /** an upper bound, not a policy: 2000 cards is 2000 image requests, and a number typed by
99
118
  * hand (or restored from an older blob) must not be able to hang the page */
119
+ /** lora images from a little smaller to twice the base size: the right size depends on the
120
+ * collection (art crops well small, a character sheet needs room) and on the screen */
121
+ export function clampLoraScale(raw: unknown): number {
122
+ const n = typeof raw === 'number' && Number.isFinite(raw) ? raw : 1
123
+ return Math.min(2, Math.max(0.6, Math.round(n * 20) / 20))
124
+ }
125
+
126
+ export const DEFAULT_RESULTS_SIZE = 320
127
+
128
+ /** a result's side in grid view: a thumbnail wall at the small end, one big image at the other */
129
+ export function clampResultsSize(raw: unknown): number {
130
+ const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.round(raw) : DEFAULT_RESULTS_SIZE
131
+ return Math.min(640, Math.max(120, n))
132
+ }
133
+
134
+ export const DEFAULT_LABEL_WIDTH = 120
135
+
136
+ export function clampLabelWidth(raw: unknown): number {
137
+ const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.round(raw) : DEFAULT_LABEL_WIDTH
138
+ return Math.min(360, Math.max(60, n))
139
+ }
140
+
100
141
  export function clampLoraCap(raw: unknown): number {
101
142
  const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.floor(raw) : DEFAULT_LORA_CAP
102
143
  return Math.min(2000, Math.max(1, n))
@@ -113,16 +154,12 @@ function readVarOrder(raw: unknown): Record<string, string[]> {
113
154
  function readStoredSelection(): StoredSelection {
114
155
  try {
115
156
  const raw = (JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}') ?? {}) as StoredSelection
116
- return { ...raw, varOrder: readVarOrder(raw.varOrder) }
157
+ return { ...raw, varOrder: readVarOrder(raw.varOrder), sizeStars: readVarOrder(raw.sizeStars) }
117
158
  } catch {
118
159
  return {}
119
160
  }
120
161
  }
121
162
 
122
- function isNarrowScreen(): boolean {
123
- return window.matchMedia('(max-width: 800px)').matches
124
- }
125
-
126
163
  export class WebSt {
127
164
  phase: 'loading' | 'error' | 'ready' = 'loading'
128
165
  bootError = ''
@@ -131,13 +168,15 @@ export class WebSt {
131
168
  form: FormSt | null = null
132
169
  formLoading = false
133
170
  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
171
  /** lora image/title visibility, EVERY lora surface (row cards + popup) — the hide toggles are NSFW screens */
137
172
  showLoraImages: boolean
138
173
  showLoraTitles: boolean
139
174
  /** cover vs contain for every lora preview: art crops well, a character sheet does not */
140
175
  loraFill: boolean
176
+ /** trigger words under each lora card: off by default, the words are reference, not a control */
177
+ showLoraTriggers: boolean
178
+ /** how big every lora image is drawn, 1 = the base card size */
179
+ loraScale: number
141
180
  loraSort: LoraSort
142
181
  /** how many lora cards the popup draws. A cap exists because each card is an image
143
182
  * request; how many is a MACHINE question (your box, your collection), so it is yours */
@@ -145,6 +184,8 @@ export class WebSt {
145
184
  run: RunSt
146
185
  /** prompt refiner: own store, own localStorage blob (the openrouter key never leaves the browser) */
147
186
  enhancer: EnhancerSt
187
+ /** ⌘K / ⌘J: every workflow and draft, fuzzy matched */
188
+ omnibox: OmniboxSt
148
189
  /** SERVER settings, not browser ones: they decide whether a generation writes files at all
149
190
  * and where, so they are shared by every client and read back from GET /settings */
150
191
  settings: ServeSettings = { saveToDisk: true, hostOverride: {}, savePrefix: {}, effectivePrefix: {} }
@@ -158,10 +199,16 @@ export class WebSt {
158
199
  }
159
200
  /** where the results go — hand-tuned, so it persists and restores */
160
201
  layout: ResultsLayout
202
+ /** where `show preview` brings the panel back to, after `off` hid it with its own buttons */
203
+ lastShownLayout: ResultsLayout = DEFAULT_LAYOUT
161
204
  /** var row order per module. A UI preference, so it lives in the browser blob: the draft
162
205
  * file is the var VALUES contract shared with the TUI, and a layout key there would have to
163
206
  * be filtered out by every reader of it */
164
207
  varOrder: Record<string, string[]> = {}
208
+ /** your own starred size presets per `module/var`; absent = the var's defaults */
209
+ sizeStars: Record<string, string[]> = {}
210
+ /** the label column width, dragged by its edge */
211
+ labelWidth = DEFAULT_LABEL_WIDTH
165
212
 
166
213
  /** the form's vars in YOUR order, with anything unknown (a new var) kept at the end */
167
214
  orderedVars(moduleKey: string, names: readonly string[]): string[] {
@@ -199,39 +246,49 @@ export class WebSt {
199
246
  * index is still loading needs a form, and dropping it was the silent failure */
200
247
  private hostChain: Promise<void> = Promise.resolve()
201
248
 
202
- constructor() {
249
+ constructor(private formTiming: FormTiming = FORM_TIMING) {
203
250
  this.run = new RunSt()
204
251
  // a finished run reports the seed it used; the form shows it, and the autosave carries it
205
252
  // into the draft, which is also what the server continues from, so `+` keeps stepping
206
253
  this.run.onSeeds = (p): void => this.applyRunSeeds(p)
207
- this.enhancer = new EnhancerSt()
254
+ this.enhancer = new EnhancerSt(() => this.form)
255
+ this.omnibox = new OmniboxSt(this)
208
256
  const stored = readStoredSelection()
209
257
  // a stored 'auto' from before the mode was removed resolves to what it MEANT on a
210
258
  // wide screen, which is where it spent most of its life
211
259
  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
260
  this.showLoraImages = stored.loraImages ?? true
216
261
  this.showLoraTitles = stored.loraTitles ?? true
217
262
  this.loraFill = stored.loraFill ?? true
263
+ this.showLoraTriggers = stored.loraTriggers ?? false
264
+ this.loraScale = clampLoraScale(stored.loraScale)
218
265
  this.loraSort = asLoraSort(stored.loraSort)
219
266
  // marked in the blob, so the bump happens once and a deliberate 60 sticks after it
220
267
  this.loraCap = clampLoraCap(
221
268
  stored.loraCapMigrated !== true && stored.loraCap === LEGACY_LORA_CAP ? DEFAULT_LORA_CAP : stored.loraCap,
222
269
  )
223
- this.showLatent = stored.latent ?? true
270
+ this.latentMode = asLatentMode(stored.latent)
271
+ this.blurResults = stored.blur ?? false
272
+ this.resultsView = stored.resultsView === 'grid' ? 'grid' : 'fit'
273
+ this.resultsSize = clampResultsSize(stored.resultsSize)
274
+ this.expandedPreviews = Array.isArray(stored.expandedPreviews)
275
+ ? stored.expandedPreviews.filter((x): x is string => typeof x === 'string')
276
+ : []
224
277
  this.varOrder = stored.varOrder ?? {}
278
+ this.sizeStars = stored.sizeStars ?? {}
279
+ this.labelWidth = clampLabelWidth(stored.labelWidth)
225
280
  this.showLogs = stored.logs ?? false
226
- makeAutoObservable<WebSt, 'hostOrigin' | 'hostChain' | 'lastPostedState' | 'switches'>(this, {
281
+ makeAutoObservable<WebSt, 'hostOrigin' | 'hostChain' | 'lastPostedState' | 'switches' | 'formTiming'>(this, {
227
282
  run: false,
228
283
  enhancer: false,
284
+ omnibox: false,
229
285
  form: observableRef,
230
286
  modules: observableShallow,
231
287
  hostOrigin: false,
232
288
  hostChain: false,
233
289
  lastPostedState: false,
234
290
  switches: false,
291
+ formTiming: false,
235
292
  })
236
293
  // inside a host page → listen for what it asks; a plain tab never sees a message
237
294
  if (isEmbedded()) window.addEventListener('message', (e) => this.onHostMessage(e))
@@ -246,8 +303,24 @@ export class WebSt {
246
303
  this.hostChain = this.boot().catch((e: unknown) => logWebError('panel boot failed', e))
247
304
  }
248
305
 
249
- toggleSidebar(): void {
250
- this.sidebarOpen = !this.sidebarOpen
306
+ /** live while dragging, persisted once on release: a write per pointer move is wasted work */
307
+ setLabelWidth(px: number, persist: boolean): void {
308
+ this.labelWidth = clampLabelWidth(px)
309
+ if (persist) this.persist()
310
+ }
311
+
312
+ setSizeStars(key: string, stars: string[]): void {
313
+ this.sizeStars[key] = stars
314
+ this.persist()
315
+ }
316
+
317
+ setLoraScale(v: number): void {
318
+ this.loraScale = clampLoraScale(v)
319
+ this.persist()
320
+ }
321
+
322
+ toggleLoraTriggers(): void {
323
+ this.showLoraTriggers = !this.showLoraTriggers
251
324
  this.persist()
252
325
  }
253
326
 
@@ -318,7 +391,7 @@ export class WebSt {
318
391
 
319
392
  private persist(): void {
320
393
  try {
321
- // merge, never rebuild: toggling the sidebar before a draft loads must not
394
+ // merge, never rebuild: toggling a setting before a draft loads must not
322
395
  // erase the stored selection (this.form is null then)
323
396
  const stored = readStoredSelection()
324
397
  localStorage.setItem(
@@ -326,17 +399,24 @@ export class WebSt {
326
399
  JSON.stringify({
327
400
  ...stored,
328
401
  ...(this.form != null ? { module: this.form.moduleKey, draft: this.form.draft } : {}),
329
- sidebar: this.sidebarOpen,
330
402
  loraImages: this.showLoraImages,
331
403
  loraTitles: this.showLoraTitles,
332
404
  loraFill: this.loraFill,
405
+ loraTriggers: this.showLoraTriggers,
406
+ loraScale: this.loraScale,
333
407
  loraSort: this.loraSort,
334
408
  loraCap: this.loraCap,
335
409
  loraCapMigrated: true,
336
410
  layout: this.layout,
337
- latent: this.showLatent,
411
+ latent: this.latentMode,
412
+ blur: this.blurResults,
413
+ resultsView: this.resultsView,
414
+ resultsSize: this.resultsSize,
415
+ expandedPreviews: this.expandedPreviews,
338
416
  logs: this.showLogs,
339
417
  varOrder: this.varOrder,
418
+ sizeStars: this.sizeStars,
419
+ labelWidth: this.labelWidth,
340
420
  }),
341
421
  )
342
422
  } catch (e) {
@@ -423,9 +503,6 @@ export class WebSt {
423
503
  // re-picking the draft you are IN is a no-op, not a reload: a pending autosave would
424
504
  // lose the race against the fetch and the typed edit would vanish from the form
425
505
  if (this.form?.moduleKey === p.module && this.form.draft === p.draft) {
426
- runInAction(() => {
427
- if (isNarrowScreen()) this.sidebarOpen = false
428
- })
429
506
  return
430
507
  }
431
508
  const token = ++this.selectToken
@@ -435,8 +512,6 @@ export class WebSt {
435
512
  this.enhancer.close()
436
513
  this.formLoading = true
437
514
  this.formError = null
438
- // picking a draft is the drawer's exit on a phone
439
- if (isNarrowScreen()) this.sidebarOpen = false
440
515
  })
441
516
  // flush the outgoing form BEFORE reading the next one, so a switch never races its own save
442
517
  const outgoing = this.form
@@ -457,7 +532,7 @@ export class WebSt {
457
532
  const reply = await fetchDraftValues(p)
458
533
  // a newer select owns the screen now: telling the host about this one would be a lie
459
534
  if (token !== this.selectToken) return
460
- const form = new FormSt(p.module, p.draft, mod, reply.values ?? {})
535
+ const form = new FormSt(p.module, p.draft, mod, reply.values ?? {}, this.formTiming)
461
536
  // the host mirrors user edits on the autosave's own debounce (pinned only)
462
537
  form.onSettled = (): void => this.mirrorState()
463
538
  runInAction(() => {
@@ -538,7 +613,7 @@ export class WebSt {
538
613
  }
539
614
 
540
615
  private stateOf(form: FormSt): { key: string; values: Record<string, unknown> } {
541
- const values = form.valuesJSON()
616
+ const values = form.varValues()
542
617
  return { key: safeStringify([form.moduleKey, form.draft, values]), values }
543
618
  }
544
619
 
@@ -690,10 +765,15 @@ export class WebSt {
690
765
 
691
766
  setLayout(next: ResultsLayout): void {
692
767
  // a click SETS the mode. cycling back to a width rule lands where no button is showing
768
+ if (this.layout !== 'off') this.lastShownLayout = this.layout
693
769
  this.layout = next
694
770
  this.persist()
695
771
  }
696
772
 
773
+ showPreview(): void {
774
+ this.setLayout(this.lastShownLayout === 'off' ? DEFAULT_LAYOUT : this.lastShownLayout)
775
+ }
776
+
697
777
  /** the host a module's runs go to right now (override if any, else the module's own) */
698
778
  hostFor(moduleKey: string): string {
699
779
  return this.hosts.overrides[moduleKey] ?? this.hosts.defaults[moduleKey] ?? ''
@@ -728,13 +808,49 @@ export class WebSt {
728
808
  showLogs = false
729
809
  logLines: string[] = []
730
810
  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
811
+ /** the latent frames during a run: full in the running card, small in a corner, or none */
812
+ latentMode: LatentMode = 'corner'
813
+ /** results blurred until the pointer is on them: a screen someone else may see */
814
+ blurResults = false
815
+
816
+ /** the last ⌘P / ⌘O jump: the var it targets reacts to a NEW seq, so pressing it twice works */
817
+ jump: { kind: 'prompt' | 'loras'; seq: number } | null = null
818
+
819
+ requestJump(kind: 'prompt' | 'loras'): void {
820
+ this.jump = { kind, seq: (this.jump?.seq ?? 0) + 1 }
821
+ }
822
+ /** fit: one image per row, as wide as the preview panel. grid: images at resultsSize px, as
823
+ * many per row as fit */
824
+ resultsView: 'fit' | 'grid' = 'fit'
825
+ resultsSize = DEFAULT_RESULTS_SIZE
826
+ /** live previews opened to their full text, as `module/name`; the rest show one line each */
827
+ expandedPreviews: string[] = []
734
828
  private logsTimer: ReturnType<typeof setInterval> | null = null
735
829
 
736
- toggleLatent(): void {
737
- this.showLatent = !this.showLatent
830
+ setLatentMode(v: LatentMode): void {
831
+ this.latentMode = v
832
+ this.persist()
833
+ }
834
+
835
+ togglePreviewExpanded(key: string): void {
836
+ this.expandedPreviews = this.expandedPreviews.includes(key)
837
+ ? this.expandedPreviews.filter((k) => k !== key)
838
+ : [...this.expandedPreviews, key]
839
+ this.persist()
840
+ }
841
+
842
+ setResultsView(v: 'fit' | 'grid'): void {
843
+ this.resultsView = v
844
+ this.persist()
845
+ }
846
+
847
+ setResultsSize(px: number): void {
848
+ this.resultsSize = clampResultsSize(px)
849
+ this.persist()
850
+ }
851
+
852
+ toggleBlur(): void {
853
+ this.blurResults = !this.blurResults
738
854
  this.persist()
739
855
  }
740
856
 
@@ -765,46 +881,50 @@ export class WebSt {
765
881
  }
766
882
  }
767
883
 
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
884
+ /** ONE refresh for everything a host knows: serve refetches its schema and re-reads its lora
885
+ * manager list, then the panel re-reads its workflow descriptions, so the open form offers
886
+ * what the host has now (a new lora, a new model) without a tab reload. The drift check calls
887
+ * it by itself; the host card's ↻ is the same call, pulsing while it runs */
888
+ refreshing = false
771
889
 
772
- async refreshLoras(): Promise<void> {
773
- if (this.loraSyncing) return
890
+ async refreshHost(): Promise<void> {
891
+ if (this.refreshing) return
774
892
  runInAction(() => {
775
- this.loraSyncing = true
893
+ this.refreshing = true
776
894
  })
777
- await this.hostAction('refresh-loras')
778
- await this.trackSwitch(this.reloadIndexAndForm())
895
+ try {
896
+ await this.hostAction('refresh-schema')
897
+ await this.trackSwitch(this.reloadIndexAndForm())
898
+ } finally {
899
+ runInAction(() => {
900
+ this.refreshing = false
901
+ })
902
+ }
779
903
  }
780
904
 
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
905
+ /** the host changed since serve loaded its schema: a light check (the loaders, a few KB) every
906
+ * 15s while the tab is visible, a full one (node types too) at boot and when a host that
907
+ * stopped answering answers again. A change is not SHOWN, it is applied: refreshHost */
786
908
  driftDown = false
787
909
 
788
910
  private startDriftWatch(): void {
789
911
  void this.checkDrift(true)
790
912
  setInterval(() => {
791
913
  if (document.visibilityState === 'visible') void this.checkDrift(false)
792
- }, 60_000)
914
+ }, 15_000)
793
915
  }
794
916
 
795
917
  async checkDrift(full: boolean): Promise<void> {
796
918
  const host = this.form == null ? null : this.hostFor(this.form.moduleKey)
797
- if (host == null || host === '') return
919
+ if (host == null || host === '' || this.refreshing) return
798
920
  try {
799
921
  const r = await fetchHostDrift({ host, full })
800
922
  const cameBack = this.driftDown
801
923
  runInAction(() => {
802
924
  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
925
  })
807
- if (cameBack && !full) await this.checkDrift(true)
926
+ if (r.changed) await this.refreshHost()
927
+ else if (cameBack && !full) await this.checkDrift(true)
808
928
  } catch {
809
929
  runInAction(() => {
810
930
  this.driftDown = true
@@ -823,13 +943,9 @@ export class WebSt {
823
943
  runInAction(() => {
824
944
  this.loraFetching.add(lora)
825
945
  this.hostError = null
826
- this.hostNote = null
827
946
  })
828
947
  try {
829
- const reply = await postLoraCivitai({ host, lora })
830
- runInAction(() => {
831
- this.hostNote = reply.note
832
- })
948
+ await postLoraCivitai({ host, lora })
833
949
  await this.trackSwitch(this.reloadIndexAndForm())
834
950
  } catch (e) {
835
951
  runInAction(() => {
@@ -865,10 +981,6 @@ export class WebSt {
865
981
  runInAction(() => {
866
982
  this.hostError = e instanceof Error ? e.message : String(e)
867
983
  })
868
- } finally {
869
- runInAction(() => {
870
- this.loraSyncing = false
871
- })
872
984
  }
873
985
  }
874
986
 
@@ -898,7 +1010,6 @@ export class WebSt {
898
1010
  if (!up) continue
899
1011
  runInAction(() => {
900
1012
  this.hostWatch = 'back'
901
- this.hostNote = `${host} is back up`
902
1013
  })
903
1014
  void this.checkDrift(true)
904
1015
  setTimeout(() => runInAction(() => (this.hostWatch = 'idle')), 4000)
@@ -912,16 +1023,11 @@ export class WebSt {
912
1023
  if (host == null || host === '') return
913
1024
  runInAction(() => {
914
1025
  this.hostError = null
915
- this.hostNote = null
916
1026
  })
917
1027
  try {
918
- const reply = await postHostAction({ host, action })
919
- runInAction(() => {
920
- this.hostNote = reply.note
921
- })
1028
+ await postHostAction({ host, action })
922
1029
  // a reboot is the one action whose result arrives LATER: watch for it
923
1030
  if (action === 'restart') void this.watchHostComeBack()
924
- if (action === 'refresh-schema') await this.checkDrift(true)
925
1031
  } catch (e) {
926
1032
  runInAction(() => {
927
1033
  this.hostError = e instanceof Error ? e.message : String(e)
@@ -1011,21 +1117,44 @@ export class WebSt {
1011
1117
  })
1012
1118
  }
1013
1119
 
1014
- generate(): void {
1015
- void this.generateNow()
1120
+ /** `override` replaces var values in THIS run only (the enhancer's try): the form and the
1121
+ * draft keep their own */
1122
+ generate(override?: Record<string, unknown>): void {
1123
+ void this.generateNow(override)
1016
1124
  }
1017
1125
 
1018
1126
  /** flush the autosave first: the server reads the draft it just wrote — one source of truth.
1019
1127
  * every click ENQUEUES, so hitting generate n times runs n prompts; the queued payload
1020
1128
  * freezes the values you saw, and seeds stay on the draft's server-side policy */
1021
- private async generateNow(): Promise<void> {
1129
+ private async generateNow(override?: Record<string, unknown>): Promise<void> {
1022
1130
  const form = this.form
1023
1131
  if (form == null) return
1024
- const payload = form.queuePayload()
1132
+ const payload = { ...form.queuePayload(), ...override }
1025
1133
  const saved = await form.save()
1026
1134
  // the header already shows the loud save error; running the stale draft would lie
1027
1135
  if (!saved) return
1028
1136
  this.run.enqueue({ module: form.moduleKey, draft: form.draft, payload })
1137
+ this.recordPrompts(form, payload)
1138
+ }
1139
+
1140
+ /** every prompt var of what was just queued, for the history picker (this page only) */
1141
+ promptHistory: HistoryEntry<PromptInput>[] = []
1142
+
1143
+ /** from the payload that was SENT, so a tried candidate is history like any prompt */
1144
+ private recordPrompts(form: FormSt, payload: Record<string, unknown>): void {
1145
+ const at = Date.now()
1146
+ for (const v of form.vars) {
1147
+ const value = payload[v.name]
1148
+ if (v.desc.kind !== 'prompt' || !isPromptInput(value)) continue
1149
+ // lanes keep their headers in the text, so a search finds a lane by its name too
1150
+ const text = typeof value === 'string' ? value : promptLanesToText(value)
1151
+ this.promptHistory = pushHistory(this.promptHistory, {
1152
+ text,
1153
+ value,
1154
+ at,
1155
+ source: `${form.moduleKey} · ${v.desc.label ?? v.name}`,
1156
+ })
1157
+ }
1029
1158
  }
1030
1159
 
1031
1160
  /** rename = write the values under the new name, switch to it, then drop the old FILE.
@@ -1086,13 +1215,29 @@ export class WebSt {
1086
1215
 
1087
1216
  /** duplicate = save the current values under a new name, then switch to it */
1088
1217
  async duplicateDraft(rawName: string): Promise<void> {
1218
+ const form = this.form
1219
+ if (form == null) return
1220
+ await this.createDraft(rawName, form.valuesJSON())
1221
+ }
1222
+
1223
+ /** a new draft from the workflow's OWN values (the ones in its code), not the open draft's */
1224
+ async newDraft(rawName: string): Promise<void> {
1225
+ const form = this.form
1226
+ const mod = form == null ? null : this.moduleByKey(form.moduleKey)
1227
+ if (mod == null) return
1228
+ const values: Record<string, unknown> = {}
1229
+ for (const [name, desc] of Object.entries(mod.vars)) values[name] = desc.default
1230
+ await this.createDraft(rawName, values)
1231
+ }
1232
+
1233
+ private async createDraft(rawName: string, values: Record<string, unknown>): Promise<void> {
1089
1234
  const form = this.form
1090
1235
  const name = rawName.trim()
1091
1236
  if (form == null || name === '') return
1092
1237
  const existing = this.moduleByKey(form.moduleKey)?.drafts.includes(name) === true
1093
1238
  if (existing && !window.confirm(`draft '${name}' already exists — overwrite it?`)) return
1094
1239
  try {
1095
- const reply = await saveDraft({ module: form.moduleKey, draft: name, values: form.valuesJSON() })
1240
+ const reply = await saveDraft({ module: form.moduleKey, draft: name, values })
1096
1241
  runInAction(() => {
1097
1242
  this.modules = this.modules.map((m) => (m.module === form.moduleKey ? { ...m, drafts: reply.drafts } : m))
1098
1243
  })
@@ -0,0 +1,61 @@
1
+ // a choice var with a few short options renders as a row of buttons, every option visible and
2
+ // one click away; anything longer stays a select. PURE, tests/serve-web-choice-buttons.test.ts
3
+ export const MAX_BUTTONS = 5
4
+ export const MAX_BUTTON_LABEL = 16
5
+
6
+ export function choiceAsButtons(choices: readonly string[]): boolean {
7
+ return choices.length > 0 && choices.length <= MAX_BUTTONS && choices.every((c) => c.length <= MAX_BUTTON_LABEL)
8
+ }
9
+
10
+ export type ChoiceSelectMode = 'one' | 'zero-or-one' | 'many'
11
+
12
+ /** the options picked right now, whatever the shape: one value, one or null, or a list */
13
+ export function pickedChoices(value: unknown): string[] {
14
+ if (typeof value === 'string') return [value]
15
+ if (Array.isArray(value)) return value.filter((x): x is string => typeof x === 'string')
16
+ return []
17
+ }
18
+
19
+ /** the value after clicking option `c`: `one` picks it, `zero-or-one` picks it or clears it,
20
+ * `many` toggles it, the list kept in the order of the choices */
21
+ export function clickChoice(p: {
22
+ select: ChoiceSelectMode
23
+ choices: readonly string[]
24
+ value: unknown
25
+ c: string
26
+ }): string | string[] | null {
27
+ if (p.select === 'one') return p.c
28
+ const picked = pickedChoices(p.value)
29
+ if (p.select === 'zero-or-one') return picked.includes(p.c) ? null : p.c
30
+ const on = picked.includes(p.c)
31
+ return p.choices.filter((x) => (x === p.c ? !on : picked.includes(x)))
32
+ }
33
+
34
+ /** a value from OUTSIDE (the embedding page) held to what this choice can hold */
35
+ export function acceptChoice(p: {
36
+ select: ChoiceSelectMode
37
+ choices: readonly string[]
38
+ raw: unknown
39
+ }): { ok: true; value: string | string[] | null } | { ok: false } {
40
+ const known = (x: unknown): x is string => typeof x === 'string' && p.choices.includes(x)
41
+ if (p.select === 'many')
42
+ return Array.isArray(p.raw) && p.raw.every(known)
43
+ ? { ok: true, value: p.choices.filter((c) => Array.isArray(p.raw) && p.raw.includes(c)) }
44
+ : { ok: false }
45
+ if (p.select === 'zero-or-one') return p.raw === null || known(p.raw) ? { ok: true, value: p.raw } : { ok: false }
46
+ return known(p.raw) ? { ok: true, value: p.raw } : { ok: false }
47
+ }
48
+
49
+ /** a stored value read in the var's CURRENT shape: a choice that changed from single to many
50
+ * (or back) keeps what it held, one value becoming a list of one, a list its first option */
51
+ export function normalizeChoice(p: {
52
+ select: ChoiceSelectMode
53
+ choices: readonly string[]
54
+ raw: unknown
55
+ }): string | string[] | null {
56
+ const picked = pickedChoices(p.raw).filter((x) => p.choices.includes(x))
57
+ if (p.select === 'many') return p.choices.filter((c) => picked.includes(c))
58
+ if (p.select === 'zero-or-one') return picked[0] ?? null
59
+ // one: a string as it stands, even one this host lacks (the control says so); a list its first
60
+ return typeof p.raw === 'string' ? p.raw : (picked[0] ?? null)
61
+ }
@@ -0,0 +1,16 @@
1
+ // what the generate button shows. PURE, tests/serve-web-generate-button.test.ts. The text NEVER
2
+ // changes: a label carrying the percent changed the button's width on every tick and moved the
3
+ // row. The progress is a fill across the button, the exact percent lives on the running card
4
+
5
+ export function generateButtonLook(p: { isRunning: boolean; percent: number | null }): {
6
+ label: string
7
+ /** 0..100 while running, null when idle */
8
+ fill: number | null
9
+ running: boolean
10
+ } {
11
+ return {
12
+ label: 'generate',
13
+ fill: p.isRunning ? Math.max(0, Math.min(100, Math.round(p.percent ?? 0))) : null,
14
+ running: p.isRunning,
15
+ }
16
+ }