comfy-ts 2.10.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 (110) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-DFxzQfDc.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 +565 -62
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +210 -31
  8. package/dist/index.d.ts +210 -31
  9. package/dist/index.js +561 -63
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-_nrvJYyt.js → run-serve-BeAznay5.js} +549 -43
  12. package/dist/run-serve-BeAznay5.js.map +1 -0
  13. package/dist/{run-tui-Atvf9vb3.js → run-tui-BTGjvnKk.js} +75 -18
  14. package/dist/run-tui-BTGjvnKk.js.map +1 -0
  15. package/dist/{DefinedWorkflow-BatWaZO1.js → schemaDrift-Cg39vs53.js} +644 -60
  16. package/dist/schemaDrift-Cg39vs53.js.map +1 -0
  17. package/dist/serve-web.js +523 -133
  18. package/dist/{state-6RFDIQwJ.js → state-C7REnHan.js} +18 -3
  19. package/dist/{state-6RFDIQwJ.js.map → state-C7REnHan.js.map} +1 -1
  20. package/dist/web.d.ts +210 -31
  21. package/dist/web.js +561 -63
  22. package/dist/web.js.map +1 -1
  23. package/examples/comfy-cloud/capybara-i2v.cflow.ts +2 -0
  24. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +2 -0
  25. package/examples/comfy-cloud/wan22-i2v.cflow.ts +2 -0
  26. package/examples/comfy-cloud/wan22-t2v.cflow.ts +2 -0
  27. package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
  28. package/examples/rvion/07-local-llm-text-gen.cflow.ts +2 -2
  29. package/examples/rvion/10-anima-t2i.cflow.ts +229 -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 +17 -7
  35. package/src/cli/draftMeta.ts +39 -0
  36. package/src/cli/serve/ServeApp.ts +242 -12
  37. package/src/cli/serve/applyVarPayload.ts +50 -22
  38. package/src/cli/serve/describeVar.ts +49 -6
  39. package/src/cli/serve/favicon.ts +3 -0
  40. package/src/cli/serve/llmConfigShape.ts +51 -0
  41. package/src/cli/serve/llmConfigs.ts +52 -0
  42. package/src/cli/serve/tagList.ts +92 -0
  43. package/src/cli/serve/tagSource.ts +69 -0
  44. package/src/cli/serve/web/api.ts +60 -0
  45. package/src/cli/serve/web/components/App.tsx +336 -44
  46. package/src/cli/serve/web/components/Gallery.tsx +105 -28
  47. package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
  48. package/src/cli/serve/web/components/Icon.tsx +18 -2
  49. package/src/cli/serve/web/components/MenuButton.tsx +53 -0
  50. package/src/cli/serve/web/components/Omnibox.tsx +85 -0
  51. package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
  52. package/src/cli/serve/web/components/TooltipLayer.tsx +45 -0
  53. package/src/cli/serve/web/components/VarIcon.tsx +24 -0
  54. package/src/cli/serve/web/components/VarsForm.tsx +341 -177
  55. package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
  56. package/src/cli/serve/web/components/controls/LorasControl.tsx +708 -285
  57. package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
  58. package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
  59. package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
  60. package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
  61. package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
  62. package/src/cli/serve/web/components/modKey.ts +2 -0
  63. package/src/cli/serve/web/llm.ts +23 -12
  64. package/src/cli/serve/web/promptEditor/promptExtensions.ts +281 -0
  65. package/src/cli/serve/web/state/EnhancerSt.ts +415 -100
  66. package/src/cli/serve/web/state/FormSt.ts +193 -29
  67. package/src/cli/serve/web/state/OmniboxSt.ts +57 -0
  68. package/src/cli/serve/web/state/WebSt.ts +281 -57
  69. package/src/cli/serve/web/state/choiceButtons.ts +61 -0
  70. package/src/cli/serve/web/state/generateButton.ts +16 -0
  71. package/src/cli/serve/web/state/history.ts +54 -0
  72. package/src/cli/serve/web/state/host.ts +5 -2
  73. package/src/cli/serve/web/state/keptLines.ts +53 -0
  74. package/src/cli/serve/web/state/latentMode.ts +20 -0
  75. package/src/cli/serve/web/state/loraSort.ts +57 -0
  76. package/src/cli/serve/web/state/moduleTree.ts +2 -2
  77. package/src/cli/serve/web/state/omnibox.ts +69 -0
  78. package/src/cli/serve/web/state/payload.ts +38 -58
  79. package/src/cli/serve/web/state/shortcuts.ts +54 -0
  80. package/src/cli/serve/web/state/sizeStars.ts +31 -0
  81. package/src/cli/serve/web/state/stableSlots.ts +21 -0
  82. package/src/cli/serve/web/state/varGroups.ts +24 -0
  83. package/src/cli/serve/web/styles.ts +472 -118
  84. package/src/cli/serve/webBundle.ts +54 -10
  85. package/src/cli/tui/components/Header.tsx +2 -0
  86. package/src/cli/tui/components/PickerOverlays.tsx +9 -2
  87. package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
  88. package/src/cli/tui/state/DraftsSt.ts +18 -2
  89. package/src/cli/tui/state/EditorSt.ts +1 -1
  90. package/src/cli/tui/state/HostSt.ts +34 -0
  91. package/src/cli/tui/state/LorasSt.ts +1 -1
  92. package/src/cli/tui/state/PickerSt.ts +25 -7
  93. package/src/cli/tui/state/SettingsSt.ts +1 -1
  94. package/src/cli/tui/state/TuiSt.ts +10 -0
  95. package/src/coreExports.ts +20 -0
  96. package/src/host/ComfyHost.ts +15 -0
  97. package/src/host/loraInfoCache.ts +70 -0
  98. package/src/host/loraManagerApi.ts +27 -0
  99. package/src/host/schemaDrift.ts +87 -0
  100. package/src/state.ts +5 -0
  101. package/src/vars/ComfyVars.ts +337 -67
  102. package/src/vars/DefinedWorkflow.ts +40 -19
  103. package/src/vars/lanes.ts +238 -0
  104. package/src/vars/loraEntry.ts +101 -0
  105. package/src/vars/promptSyntax.ts +382 -0
  106. package/dist/DefinedWorkflow-BatWaZO1.js.map +0 -1
  107. package/dist/LogsSt-DFxzQfDc.js.map +0 -1
  108. package/dist/run-serve-_nrvJYyt.js.map +0 -1
  109. package/dist/run-tui-Atvf9vb3.js.map +0 -1
  110. package/src/cli/serve/web/components/Sidebar.tsx +0 -66
@@ -10,6 +10,8 @@ import {
10
10
  fetchSettings,
11
11
  pingHost,
12
12
  postHostAction,
13
+ postLoraCivitai,
14
+ fetchHostDrift,
13
15
  saveDraft,
14
16
  saveSettings,
15
17
  setModuleHost,
@@ -19,11 +21,16 @@ import {
19
21
  type ServeSettings,
20
22
  } from 'src/cli/serve/web/api.ts'
21
23
  import { EnhancerSt } from 'src/cli/serve/web/state/EnhancerSt.ts'
22
- 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'
23
29
  import { logWebError } from 'src/cli/serve/web/logWeb.ts'
24
30
  import { asSeedForm } from 'src/cli/serve/web/state/payload.ts'
25
31
  import { readUrlSelection, resolveSelection, writeUrlSelection } from 'src/cli/serve/web/state/urlSelection.ts'
26
32
  import { RunSt } from 'src/cli/serve/web/state/RunSt.ts'
33
+ import { asLoraSort, type LoraSort } from 'src/cli/serve/web/state/loraSort.ts'
27
34
  import {
28
35
  coerceHostValue,
29
36
  isEmbedded,
@@ -68,20 +75,36 @@ function isLayout(raw: unknown): raw is ResultsLayout {
68
75
  type StoredSelection = {
69
76
  module?: string
70
77
  draft?: string
71
- sidebar?: boolean
72
78
  loraImages?: boolean
73
79
  loraTitles?: boolean
74
80
  /** lora previews fill their card (cover) instead of fitting inside it (contain) */
75
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
88
+ loraSort?: string
76
89
  /** how many lora cards the popup draws before it stops */
77
90
  loraCap?: number
78
91
  /** the one-shot 60 → 200 default bump already happened for this browser */
79
92
  loraCapMigrated?: boolean
80
93
  layout?: string
81
- 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[]
82
103
  logs?: boolean
83
104
  /** module key → the var names in the order you dragged them into */
84
105
  varOrder?: Record<string, string[]>
106
+ /** starred size presets per `module/var`, once you star or unstar one yourself */
107
+ sizeStars?: Record<string, string[]>
85
108
  }
86
109
 
87
110
  /** varOrder is the one stored field a reader INDEXES rather than merely reads, so a blob of
@@ -93,6 +116,28 @@ export const DEFAULT_LORA_CAP = 200
93
116
  const LEGACY_LORA_CAP = 60
94
117
  /** an upper bound, not a policy: 2000 cards is 2000 image requests, and a number typed by
95
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
+
96
141
  export function clampLoraCap(raw: unknown): number {
97
142
  const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.floor(raw) : DEFAULT_LORA_CAP
98
143
  return Math.min(2000, Math.max(1, n))
@@ -109,16 +154,12 @@ function readVarOrder(raw: unknown): Record<string, string[]> {
109
154
  function readStoredSelection(): StoredSelection {
110
155
  try {
111
156
  const raw = (JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}') ?? {}) as StoredSelection
112
- return { ...raw, varOrder: readVarOrder(raw.varOrder) }
157
+ return { ...raw, varOrder: readVarOrder(raw.varOrder), sizeStars: readVarOrder(raw.sizeStars) }
113
158
  } catch {
114
159
  return {}
115
160
  }
116
161
  }
117
162
 
118
- function isNarrowScreen(): boolean {
119
- return window.matchMedia('(max-width: 800px)').matches
120
- }
121
-
122
163
  export class WebSt {
123
164
  phase: 'loading' | 'error' | 'ready' = 'loading'
124
165
  bootError = ''
@@ -127,19 +168,24 @@ export class WebSt {
127
168
  form: FormSt | null = null
128
169
  formLoading = false
129
170
  formError: string | null = null
130
- /** drawer on narrow screens, collapsible column on wide ones — stored toggle wins over the width default */
131
- sidebarOpen: boolean
132
171
  /** lora image/title visibility, EVERY lora surface (row cards + popup) — the hide toggles are NSFW screens */
133
172
  showLoraImages: boolean
134
173
  showLoraTitles: boolean
135
174
  /** cover vs contain for every lora preview: art crops well, a character sheet does not */
136
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
180
+ loraSort: LoraSort
137
181
  /** how many lora cards the popup draws. A cap exists because each card is an image
138
182
  * request; how many is a MACHINE question (your box, your collection), so it is yours */
139
183
  loraCap: number
140
184
  run: RunSt
141
185
  /** prompt refiner: own store, own localStorage blob (the openrouter key never leaves the browser) */
142
186
  enhancer: EnhancerSt
187
+ /** ⌘K / ⌘J: every workflow and draft, fuzzy matched */
188
+ omnibox: OmniboxSt
143
189
  /** SERVER settings, not browser ones: they decide whether a generation writes files at all
144
190
  * and where, so they are shared by every client and read back from GET /settings */
145
191
  settings: ServeSettings = { saveToDisk: true, hostOverride: {}, savePrefix: {}, effectivePrefix: {} }
@@ -153,10 +199,16 @@ export class WebSt {
153
199
  }
154
200
  /** where the results go — hand-tuned, so it persists and restores */
155
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
156
204
  /** var row order per module. A UI preference, so it lives in the browser blob: the draft
157
205
  * file is the var VALUES contract shared with the TUI, and a layout key there would have to
158
206
  * be filtered out by every reader of it */
159
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
160
212
 
161
213
  /** the form's vars in YOUR order, with anything unknown (a new var) kept at the end */
162
214
  orderedVars(moduleKey: string, names: readonly string[]): string[] {
@@ -194,38 +246,49 @@ export class WebSt {
194
246
  * index is still loading needs a form, and dropping it was the silent failure */
195
247
  private hostChain: Promise<void> = Promise.resolve()
196
248
 
197
- constructor() {
249
+ constructor(private formTiming: FormTiming = FORM_TIMING) {
198
250
  this.run = new RunSt()
199
251
  // a finished run reports the seed it used; the form shows it, and the autosave carries it
200
252
  // into the draft, which is also what the server continues from, so `+` keeps stepping
201
253
  this.run.onSeeds = (p): void => this.applyRunSeeds(p)
202
- this.enhancer = new EnhancerSt()
254
+ this.enhancer = new EnhancerSt(() => this.form)
255
+ this.omnibox = new OmniboxSt(this)
203
256
  const stored = readStoredSelection()
204
257
  // a stored 'auto' from before the mode was removed resolves to what it MEANT on a
205
258
  // wide screen, which is where it spent most of its life
206
259
  this.layout = isLayout(stored.layout) ? stored.layout : DEFAULT_LAYOUT
207
- // CLOSED by default, on every width: the panel is a form, and a workflow tree taking a
208
- // column of it before you have asked for one is chrome. It reopens from the workflow box
209
- this.sidebarOpen = stored.sidebar ?? false
210
260
  this.showLoraImages = stored.loraImages ?? true
211
261
  this.showLoraTitles = stored.loraTitles ?? true
212
262
  this.loraFill = stored.loraFill ?? true
263
+ this.showLoraTriggers = stored.loraTriggers ?? false
264
+ this.loraScale = clampLoraScale(stored.loraScale)
265
+ this.loraSort = asLoraSort(stored.loraSort)
213
266
  // marked in the blob, so the bump happens once and a deliberate 60 sticks after it
214
267
  this.loraCap = clampLoraCap(
215
268
  stored.loraCapMigrated !== true && stored.loraCap === LEGACY_LORA_CAP ? DEFAULT_LORA_CAP : stored.loraCap,
216
269
  )
217
- 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
+ : []
218
277
  this.varOrder = stored.varOrder ?? {}
278
+ this.sizeStars = stored.sizeStars ?? {}
279
+ this.labelWidth = clampLabelWidth(stored.labelWidth)
219
280
  this.showLogs = stored.logs ?? false
220
- makeAutoObservable<WebSt, 'hostOrigin' | 'hostChain' | 'lastPostedState' | 'switches'>(this, {
281
+ makeAutoObservable<WebSt, 'hostOrigin' | 'hostChain' | 'lastPostedState' | 'switches' | 'formTiming'>(this, {
221
282
  run: false,
222
283
  enhancer: false,
284
+ omnibox: false,
223
285
  form: observableRef,
224
286
  modules: observableShallow,
225
287
  hostOrigin: false,
226
288
  hostChain: false,
227
289
  lastPostedState: false,
228
290
  switches: false,
291
+ formTiming: false,
229
292
  })
230
293
  // inside a host page → listen for what it asks; a plain tab never sees a message
231
294
  if (isEmbedded()) window.addEventListener('message', (e) => this.onHostMessage(e))
@@ -240,8 +303,24 @@ export class WebSt {
240
303
  this.hostChain = this.boot().catch((e: unknown) => logWebError('panel boot failed', e))
241
304
  }
242
305
 
243
- toggleSidebar(): void {
244
- 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
245
324
  this.persist()
246
325
  }
247
326
 
@@ -255,6 +334,11 @@ export class WebSt {
255
334
  this.persist()
256
335
  }
257
336
 
337
+ setLoraSort(mode: LoraSort): void {
338
+ this.loraSort = mode
339
+ this.persist()
340
+ }
341
+
258
342
  toggleLoraFill(): void {
259
343
  this.loraFill = !this.loraFill
260
344
  this.persist()
@@ -307,7 +391,7 @@ export class WebSt {
307
391
 
308
392
  private persist(): void {
309
393
  try {
310
- // 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
311
395
  // erase the stored selection (this.form is null then)
312
396
  const stored = readStoredSelection()
313
397
  localStorage.setItem(
@@ -315,16 +399,24 @@ export class WebSt {
315
399
  JSON.stringify({
316
400
  ...stored,
317
401
  ...(this.form != null ? { module: this.form.moduleKey, draft: this.form.draft } : {}),
318
- sidebar: this.sidebarOpen,
319
402
  loraImages: this.showLoraImages,
320
403
  loraTitles: this.showLoraTitles,
321
404
  loraFill: this.loraFill,
405
+ loraTriggers: this.showLoraTriggers,
406
+ loraScale: this.loraScale,
407
+ loraSort: this.loraSort,
322
408
  loraCap: this.loraCap,
323
409
  loraCapMigrated: true,
324
410
  layout: this.layout,
325
- latent: this.showLatent,
411
+ latent: this.latentMode,
412
+ blur: this.blurResults,
413
+ resultsView: this.resultsView,
414
+ resultsSize: this.resultsSize,
415
+ expandedPreviews: this.expandedPreviews,
326
416
  logs: this.showLogs,
327
417
  varOrder: this.varOrder,
418
+ sizeStars: this.sizeStars,
419
+ labelWidth: this.labelWidth,
328
420
  }),
329
421
  )
330
422
  } catch (e) {
@@ -374,6 +466,7 @@ export class WebSt {
374
466
  if (urlPrompt != null) this.setPromptText(urlPrompt)
375
467
  // last: the host replies with its buttons + its prompt, and both need a form
376
468
  this.postHost({ comfyTs: 'ready' })
469
+ this.startDriftWatch()
377
470
  } catch (e) {
378
471
  const message = e instanceof Error ? e.message : String(e)
379
472
  runInAction(() => {
@@ -410,9 +503,6 @@ export class WebSt {
410
503
  // re-picking the draft you are IN is a no-op, not a reload: a pending autosave would
411
504
  // lose the race against the fetch and the typed edit would vanish from the form
412
505
  if (this.form?.moduleKey === p.module && this.form.draft === p.draft) {
413
- runInAction(() => {
414
- if (isNarrowScreen()) this.sidebarOpen = false
415
- })
416
506
  return
417
507
  }
418
508
  const token = ++this.selectToken
@@ -422,8 +512,6 @@ export class WebSt {
422
512
  this.enhancer.close()
423
513
  this.formLoading = true
424
514
  this.formError = null
425
- // picking a draft is the drawer's exit on a phone
426
- if (isNarrowScreen()) this.sidebarOpen = false
427
515
  })
428
516
  // flush the outgoing form BEFORE reading the next one, so a switch never races its own save
429
517
  const outgoing = this.form
@@ -444,7 +532,7 @@ export class WebSt {
444
532
  const reply = await fetchDraftValues(p)
445
533
  // a newer select owns the screen now: telling the host about this one would be a lie
446
534
  if (token !== this.selectToken) return
447
- 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)
448
536
  // the host mirrors user edits on the autosave's own debounce (pinned only)
449
537
  form.onSettled = (): void => this.mirrorState()
450
538
  runInAction(() => {
@@ -525,7 +613,7 @@ export class WebSt {
525
613
  }
526
614
 
527
615
  private stateOf(form: FormSt): { key: string; values: Record<string, unknown> } {
528
- const values = form.valuesJSON()
616
+ const values = form.varValues()
529
617
  return { key: safeStringify([form.moduleKey, form.draft, values]), values }
530
618
  }
531
619
 
@@ -677,10 +765,15 @@ export class WebSt {
677
765
 
678
766
  setLayout(next: ResultsLayout): void {
679
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
680
769
  this.layout = next
681
770
  this.persist()
682
771
  }
683
772
 
773
+ showPreview(): void {
774
+ this.setLayout(this.lastShownLayout === 'off' ? DEFAULT_LAYOUT : this.lastShownLayout)
775
+ }
776
+
684
777
  /** the host a module's runs go to right now (override if any, else the module's own) */
685
778
  hostFor(moduleKey: string): string {
686
779
  return this.hosts.overrides[moduleKey] ?? this.hosts.defaults[moduleKey] ?? ''
@@ -715,13 +808,49 @@ export class WebSt {
715
808
  showLogs = false
716
809
  logLines: string[] = []
717
810
  logsError: string | null = null
718
- hostNote: string | null = null
719
- /** the latent frames during a run: on by default, off when you only want the final image */
720
- 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[] = []
721
828
  private logsTimer: ReturnType<typeof setInterval> | null = null
722
829
 
723
- toggleLatent(): void {
724
- 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
725
854
  this.persist()
726
855
  }
727
856
 
@@ -752,17 +881,81 @@ export class WebSt {
752
881
  }
753
882
  }
754
883
 
755
- /** the lora mirror sweep, from the panel: the metadata (names, trigger words, previews) is
756
- * re-downloaded and every surface re-reads it, which needs the descriptors reloaded too */
757
- 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
889
+
890
+ async refreshHost(): Promise<void> {
891
+ if (this.refreshing) return
892
+ runInAction(() => {
893
+ this.refreshing = true
894
+ })
895
+ try {
896
+ await this.hostAction('refresh-schema')
897
+ await this.trackSwitch(this.reloadIndexAndForm())
898
+ } finally {
899
+ runInAction(() => {
900
+ this.refreshing = false
901
+ })
902
+ }
903
+ }
904
+
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 */
908
+ driftDown = false
909
+
910
+ private startDriftWatch(): void {
911
+ void this.checkDrift(true)
912
+ setInterval(() => {
913
+ if (document.visibilityState === 'visible') void this.checkDrift(false)
914
+ }, 15_000)
915
+ }
758
916
 
759
- async refreshLoras(): Promise<void> {
760
- if (this.loraSyncing) return
917
+ async checkDrift(full: boolean): Promise<void> {
918
+ const host = this.form == null ? null : this.hostFor(this.form.moduleKey)
919
+ if (host == null || host === '' || this.refreshing) return
920
+ try {
921
+ const r = await fetchHostDrift({ host, full })
922
+ const cameBack = this.driftDown
923
+ runInAction(() => {
924
+ this.driftDown = false
925
+ })
926
+ if (r.changed) await this.refreshHost()
927
+ else if (cameBack && !full) await this.checkDrift(true)
928
+ } catch {
929
+ runInAction(() => {
930
+ this.driftDown = true
931
+ })
932
+ }
933
+ }
934
+
935
+ /** loras whose civitai fetch is in flight: their card says so instead of offering it twice */
936
+ loraFetching = new Set<string>()
937
+
938
+ /** one lora's trigger words, fetched from civitai by the lora manager, then the mirror and
939
+ * the descriptors re-read so the card shows what came back (words, or a definite none) */
940
+ async fetchLoraTriggers(lora: string): Promise<void> {
941
+ const host = this.form == null ? null : this.hostFor(this.form.moduleKey)
942
+ if (host == null || host === '' || this.loraFetching.has(lora)) return
761
943
  runInAction(() => {
762
- this.loraSyncing = true
944
+ this.loraFetching.add(lora)
945
+ this.hostError = null
763
946
  })
764
- await this.hostAction('refresh-loras')
765
- await this.trackSwitch(this.reloadIndexAndForm())
947
+ try {
948
+ await postLoraCivitai({ host, lora })
949
+ await this.trackSwitch(this.reloadIndexAndForm())
950
+ } catch (e) {
951
+ runInAction(() => {
952
+ this.hostError = e instanceof Error ? e.message : String(e)
953
+ })
954
+ } finally {
955
+ runInAction(() => {
956
+ this.loraFetching.delete(lora)
957
+ })
958
+ }
766
959
  }
767
960
 
768
961
  private async reloadIndexAndForm(): Promise<void> {
@@ -788,10 +981,6 @@ export class WebSt {
788
981
  runInAction(() => {
789
982
  this.hostError = e instanceof Error ? e.message : String(e)
790
983
  })
791
- } finally {
792
- runInAction(() => {
793
- this.loraSyncing = false
794
- })
795
984
  }
796
985
  }
797
986
 
@@ -821,8 +1010,8 @@ export class WebSt {
821
1010
  if (!up) continue
822
1011
  runInAction(() => {
823
1012
  this.hostWatch = 'back'
824
- this.hostNote = `${host} is back up`
825
1013
  })
1014
+ void this.checkDrift(true)
826
1015
  setTimeout(() => runInAction(() => (this.hostWatch = 'idle')), 4000)
827
1016
  return
828
1017
  }
@@ -834,13 +1023,9 @@ export class WebSt {
834
1023
  if (host == null || host === '') return
835
1024
  runInAction(() => {
836
1025
  this.hostError = null
837
- this.hostNote = null
838
1026
  })
839
1027
  try {
840
- const reply = await postHostAction({ host, action })
841
- runInAction(() => {
842
- this.hostNote = reply.note
843
- })
1028
+ await postHostAction({ host, action })
844
1029
  // a reboot is the one action whose result arrives LATER: watch for it
845
1030
  if (action === 'restart') void this.watchHostComeBack()
846
1031
  } catch (e) {
@@ -932,21 +1117,44 @@ export class WebSt {
932
1117
  })
933
1118
  }
934
1119
 
935
- generate(): void {
936
- 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)
937
1124
  }
938
1125
 
939
1126
  /** flush the autosave first: the server reads the draft it just wrote — one source of truth.
940
1127
  * every click ENQUEUES, so hitting generate n times runs n prompts; the queued payload
941
1128
  * freezes the values you saw, and seeds stay on the draft's server-side policy */
942
- private async generateNow(): Promise<void> {
1129
+ private async generateNow(override?: Record<string, unknown>): Promise<void> {
943
1130
  const form = this.form
944
1131
  if (form == null) return
945
- const payload = form.queuePayload()
1132
+ const payload = { ...form.queuePayload(), ...override }
946
1133
  const saved = await form.save()
947
1134
  // the header already shows the loud save error; running the stale draft would lie
948
1135
  if (!saved) return
949
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
+ }
950
1158
  }
951
1159
 
952
1160
  /** rename = write the values under the new name, switch to it, then drop the old FILE.
@@ -1007,13 +1215,29 @@ export class WebSt {
1007
1215
 
1008
1216
  /** duplicate = save the current values under a new name, then switch to it */
1009
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> {
1010
1234
  const form = this.form
1011
1235
  const name = rawName.trim()
1012
1236
  if (form == null || name === '') return
1013
1237
  const existing = this.moduleByKey(form.moduleKey)?.drafts.includes(name) === true
1014
1238
  if (existing && !window.confirm(`draft '${name}' already exists — overwrite it?`)) return
1015
1239
  try {
1016
- const reply = await saveDraft({ module: form.moduleKey, draft: name, values: form.valuesJSON() })
1240
+ const reply = await saveDraft({ module: form.moduleKey, draft: name, values })
1017
1241
  runInAction(() => {
1018
1242
  this.modules = this.modules.map((m) => (m.module === form.moduleKey ? { ...m, drafts: reply.drafts } : m))
1019
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
+ }