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
@@ -3,9 +3,20 @@
3
3
  // reaction is owned here). DRAFTS ARE LIVE (the TUI model): edits autosave
4
4
  // through PUT /drafts, generate posts {} — the draft is the one source of truth
5
5
  import { makeAutoObservable, observableRef, reaction, runInAction, type IReactionDisposer } from 'mobx'
6
- import { saveDraft, type ModuleDescription } from 'src/cli/serve/web/api.ts'
6
+ import { fetchPreviews, saveDraft, type ModuleDescription } from 'src/cli/serve/web/api.ts'
7
7
  import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
8
8
  import { normalizeInitial, payloadSnapshot } from 'src/cli/serve/web/state/payload.ts'
9
+ import {
10
+ flattenLoras,
11
+ isLorasInput,
12
+ loraSetting,
13
+ paletteLoras,
14
+ updateLora,
15
+ type LoraRecord,
16
+ type LorasInput,
17
+ } from 'src/vars/lanes.ts'
18
+ import { keywordParts, loraMuted, withLora } from 'src/vars/loraEntry.ts'
19
+ import { ENHANCE_KEY, readIntents } from 'src/cli/draftMeta.ts'
9
20
 
10
21
  /** one var row: value in toJSON shape, replaced whole on every edit */
11
22
  export class VarSt {
@@ -41,6 +52,21 @@ export class VarSt {
41
52
  this.uploadedUrl = url
42
53
  }
43
54
 
55
+ /** the workflow's declared default, in the shape the controls hold */
56
+ get defaultValue(): unknown {
57
+ return normalizeInitial(this.desc, this.desc.default)
58
+ }
59
+
60
+ /** by value: a size or a choice list is a fresh object every time */
61
+ get isAtDefault(): boolean {
62
+ return JSON.stringify(this.value) === JSON.stringify(this.defaultValue)
63
+ }
64
+
65
+ /** back to what the workflow declares; an edit like any other (autosaved, revertable) */
66
+ resetToDefault(): void {
67
+ this.set(this.defaultValue)
68
+ }
69
+
44
70
  revert(): void {
45
71
  this.value = this.initial
46
72
  this.dirty = false
@@ -52,6 +78,10 @@ export class VarSt {
52
78
  }
53
79
  }
54
80
 
81
+ /** the debounces a form runs on: tests set them to a few ms rather than wait them out */
82
+ export type FormTiming = { autosaveMs: number; previewMs: number }
83
+ export const FORM_TIMING: FormTiming = { autosaveMs: 500, previewMs: 250 }
84
+
55
85
  export class FormSt {
56
86
  vars: VarSt[]
57
87
  /** the module's host id — lora hover data routes are host-scoped */
@@ -61,7 +91,7 @@ export class FormSt {
61
91
  private disposers: IReactionDisposer[] = []
62
92
  /** saves are chained so two PUTs can never land out of order */
63
93
  private saveChain: Promise<boolean> = Promise.resolve(true)
64
- /** the values json the server last CONFIRMED — what is really on disk */
94
+ /** the values json the server last CONFIRMED — what is really on disk. Observable: `unsaved` reads it */
65
95
  private lastSaved: string
66
96
  /** the values json last HANDED to the chain, confirmed or still in flight. save() no-ops
67
97
  * against this one, never against lastSaved: while a PUT is open the disk does not hold
@@ -72,34 +102,46 @@ export class FormSt {
72
102
  /** called on the autosave debounce, right after the save is queued: the embedding host
73
103
  * mirrors the form from it (WebSt), one call per settled burst of edits, never per key */
74
104
  onSettled: (() => void) | null = null
105
+ /** the workflow's live previews for the values on screen, name → text */
106
+ previews: Record<string, string> = {}
107
+ previewError: string | null = null
108
+ private previewAbort: AbortController | null = null
75
109
 
76
110
  constructor(
77
111
  public readonly moduleKey: string,
78
112
  public readonly draft: string,
79
113
  mod: ModuleDescription,
80
114
  values: Record<string, unknown>,
115
+ timing: FormTiming = FORM_TIMING,
81
116
  ) {
82
117
  this.host = mod.host
83
118
  this.vars = Object.entries(mod.vars).map(
84
119
  ([name, desc]) => new VarSt(name, desc, normalizeInitial(desc, values[name])),
85
120
  )
121
+ this.intents = readIntents(values[ENHANCE_KEY])
86
122
  // seeded from the RAW reply, not the normalized values: when normalizeInitial heals
87
123
  // something (a stale lora key), the form is already out of sync with the file and the
88
124
  // next save() must actually send, otherwise the server keeps building the stale record
89
- this.lastSaved = JSON.stringify(Object.fromEntries(this.vars.map((v) => [v.name, values[v.name]])))
125
+ this.lastSaved = JSON.stringify(
126
+ withIntents(Object.fromEntries(this.vars.map((v) => [v.name, values[v.name]])), this.intents),
127
+ )
90
128
  this.lastQueued = this.lastSaved
91
- makeAutoObservable<FormSt, 'disposers' | 'saveChain' | 'lastSaved' | 'lastQueued' | 'queueSeq'>(this, {
92
- vars: false,
93
- moduleKey: false,
94
- draft: false,
95
- host: false,
96
- disposers: false,
97
- saveChain: false,
98
- lastSaved: false,
99
- lastQueued: false,
100
- queueSeq: false,
101
- onSettled: false,
102
- })
129
+ makeAutoObservable<FormSt, 'disposers' | 'saveChain' | 'lastSaved' | 'lastQueued' | 'queueSeq' | 'previewAbort'>(
130
+ this,
131
+ {
132
+ vars: false,
133
+ moduleKey: false,
134
+ draft: false,
135
+ host: false,
136
+ disposers: false,
137
+ saveChain: false,
138
+ lastSaved: true,
139
+ lastQueued: false,
140
+ queueSeq: false,
141
+ onSettled: false,
142
+ previewAbort: false,
143
+ },
144
+ )
103
145
  // the persistence idiom: the values json is change-detector AND payload
104
146
  this.disposers.push(
105
147
  reaction(
@@ -108,9 +150,38 @@ export class FormSt {
108
150
  void this.save()
109
151
  this.onSettled?.()
110
152
  },
111
- { delay: 500 },
153
+ { delay: timing.autosaveMs },
112
154
  ),
113
155
  )
156
+ // live previews: the same values json, asked sooner than the save (they are what you
157
+ // watch while typing), the older request cancelled so a slow reply never lands last
158
+ const previewNames = mod.previews ?? []
159
+ if (previewNames.length > 0)
160
+ this.disposers.push(
161
+ reaction(
162
+ () => JSON.stringify(this.varValues()),
163
+ () => void this.refreshPreviews(),
164
+ { delay: timing.previewMs, fireImmediately: true },
165
+ ),
166
+ )
167
+ }
168
+
169
+ async refreshPreviews(): Promise<void> {
170
+ this.previewAbort?.abort()
171
+ const abort = new AbortController()
172
+ this.previewAbort = abort
173
+ try {
174
+ const reply = await fetchPreviews({ module: this.moduleKey, values: this.varValues(), signal: abort.signal })
175
+ runInAction(() => {
176
+ this.previews = reply.previews
177
+ this.previewError = null
178
+ })
179
+ } catch (e) {
180
+ if (abort.signal.aborted) return
181
+ runInAction(() => {
182
+ this.previewError = e instanceof Error ? e.message : String(e)
183
+ })
184
+ }
114
185
  }
115
186
 
116
187
  /** stop the autosave. `flush: false` is the DELETE path: flushing there would write the
@@ -118,6 +189,7 @@ export class FormSt {
118
189
  dispose(p: { flush?: boolean } = {}): void {
119
190
  for (const d of this.disposers) d()
120
191
  this.disposers = []
192
+ this.previewAbort?.abort()
121
193
  if (p.flush === false) return
122
194
  // a draft switch inside the debounce window must not lose the edit. Compared against
123
195
  // lastQueued, like save() itself: lastSaved lags behind an in-flight write, so a revert
@@ -153,7 +225,30 @@ export class FormSt {
153
225
  )
154
226
  }
155
227
 
228
+ /** the draft file's `$enhance`: the enhancer's input per prompt (src/cli/draftMeta.ts) */
229
+ intents: Record<string, string> = {}
230
+
231
+ intentFor(key: string): string | undefined {
232
+ return this.intents[key]
233
+ }
234
+
235
+ /** '' clears it: the input then follows the prompt again */
236
+ setIntent(key: string, text: string): void {
237
+ const next = { ...this.intents }
238
+ if (text === '') delete next[key]
239
+ else next[key] = text
240
+ this.intents = next
241
+ }
242
+
243
+ /** what the draft FILE holds: the values, and the intents beside them. Saved together, so an
244
+ * intent is autosaved like any edit */
156
245
  valuesJSON(): Record<string, unknown> {
246
+ return withIntents(this.varValues(), this.intents)
247
+ }
248
+
249
+ /** the var values alone: what previews compute from and what an embedding page is told.
250
+ * An intent typed in the enhancer changes neither */
251
+ varValues(): Record<string, unknown> {
157
252
  return Object.fromEntries(this.vars.map((v) => [v.name, v.value]))
158
253
  }
159
254
 
@@ -167,27 +262,112 @@ export class FormSt {
167
262
  * record's insertion order: walking the record showed the keywords in drag order while the
168
263
  * prompt that ran used the enum order, so the preview and the run disagreed the moment you
169
264
  * reordered a card. Computed here rather than fetched: it must follow every toggle live */
170
- loraKeywordsFor(promptVar: VarSt): string[] {
265
+ /** a var whose `activeWhen` does not hold right now: shown, but disabled. The reason is a
266
+ * sentence the label shows, null when the var is active */
267
+ inactiveReason(v: VarSt): string | null {
268
+ const when = v.desc.ui?.activeWhen
269
+ if (when == null) return null
270
+ for (const [name, allowed] of Object.entries(when)) {
271
+ const other = this.vars.find((x) => x.name === name)
272
+ const current = other?.value
273
+ if (!allowed.some((a) => a === current)) return `only used when ${name} is ${allowed.join(' or ')}`
274
+ }
275
+ return null
276
+ }
277
+
278
+ /** the loras var a prompt takes its keywords from, and the record the build reads from it
279
+ * (the plain record, or its active lanes merged) */
280
+ private keywordSource(promptVar: VarSt): { source: VarSt; value: LorasInput; record: LoraRecord } | null {
171
281
  const sourceName = promptVar.desc.keywordsFrom
172
- if (sourceName == null) return []
282
+ if (sourceName == null) return null
173
283
  const source = this.vars.find((v) => v.name === sourceName)
174
- if (source == null) return []
175
- const keywords = source.desc.optionKeywords ?? {}
176
- const record = (source.value != null && typeof source.value === 'object' ? source.value : {}) as Record<
177
- string,
178
- unknown
179
- >
284
+ if (source == null) return null
285
+ const value = isLorasInput(source.value) ? source.value : {}
286
+ return { source, value, record: flattenLoras(value).record }
287
+ }
288
+
289
+ /** one group per lora in the palette that has a keyword: its name, then the keyword split at
290
+ * the commas, each part on or off. A lora the build does not run (paused, or in a lane that
291
+ * is off) keeps its group, marked not running, so switching a lane never shifts the form */
292
+ loraKeywordGroups(
293
+ promptVar: VarSt,
294
+ ): { lora: string; label: string; running: boolean; parts: { text: string; on: boolean }[] }[] {
295
+ const found = this.keywordSource(promptVar)
296
+ if (found == null) return []
297
+ const keywords = found.source.desc.optionKeywords ?? {}
298
+ const labels = found.source.desc.optionLabels ?? {}
299
+ const inPalette = new Map(paletteLoras(found.value).map((l) => [l.name, l]))
300
+ const out: { lora: string; label: string; running: boolean; parts: { text: string; on: boolean }[] }[] = []
301
+ for (const name of found.source.desc.options ?? []) {
302
+ const entry = inPalette.get(name)
303
+ if (entry == null) continue
304
+ const parts = keywordParts(keywords[name] ?? '')
305
+ if (parts.length === 0) continue
306
+ const muted = loraMuted(entry.setting)
307
+ out.push({
308
+ lora: name,
309
+ label: labels[name] ?? name,
310
+ running: entry.running,
311
+ parts: parts.map((text) => ({ text, on: !muted.includes(text) })),
312
+ })
313
+ }
314
+ return out
315
+ }
316
+
317
+ /** what the active loras will prepend, as sent: muted parts left out, deduped */
318
+ loraKeywordsFor(promptVar: VarSt): string[] {
180
319
  const out: string[] = []
181
- for (const name of source.desc.options ?? []) {
182
- const st = record[name]
183
- // same rule as the graph: only loras that are ON contribute
184
- if (st == null || st === false) continue
185
- const kw = keywords[name]
186
- if (kw != null && kw !== '' && !out.includes(kw)) out.push(kw)
320
+ for (const g of this.loraKeywordGroups(promptVar)) {
321
+ if (!g.running) continue
322
+ const kept = g.parts
323
+ .filter((w) => w.on)
324
+ .map((w) => w.text)
325
+ .join(', ')
326
+ if (kept !== '' && !out.includes(kept)) out.push(kept)
187
327
  }
188
328
  return out
189
329
  }
190
330
 
331
+ /** every keyword part the build will add in front, with the lora it comes from (the editor
332
+ * flags a tag you typed that a lora already adds) */
333
+ injectedTagsFor(promptVar: VarSt): { tag: string; source: string }[] {
334
+ return this.loraKeywordGroups(promptVar)
335
+ .filter((g) => g.running)
336
+ .flatMap((g) => g.parts.filter((w) => w.on).map((w) => ({ tag: w.text, source: g.label })))
337
+ }
338
+
339
+ /** the keyword parts of EVERY lora in the list, running or not: the editor completes them */
340
+ loraWordsFor(promptVar: VarSt): { word: string; source: string }[] {
341
+ const sourceName = promptVar.desc.keywordsFrom
342
+ const source = sourceName == null ? null : this.vars.find((v) => v.name === sourceName)
343
+ if (source == null) return []
344
+ const keywords = source.desc.optionKeywords ?? {}
345
+ const labels = source.desc.optionLabels ?? {}
346
+ return Object.entries(keywords).flatMap(([name, kw]) =>
347
+ keywordParts(kw).map((word) => ({ word, source: labels[name] ?? name })),
348
+ )
349
+ }
350
+
351
+ /** mute or unmute one part of a lora's keyword, stored on that lora in the draft */
352
+ toggleKeywordPart(promptVar: VarSt, lora: string, part: string): void {
353
+ const found = this.keywordSource(promptVar)
354
+ if (found == null) return
355
+ const muted = loraMuted(loraSetting(found.value, lora))
356
+ this.setKeywordMute(promptVar, lora, muted.includes(part) ? muted.filter((w) => w !== part) : [...muted, part])
357
+ }
358
+
359
+ /** the whole list of muted parts at once (the popover's all / none) */
360
+ setKeywordMute(promptVar: VarSt, lora: string, mute: readonly string[]): void {
361
+ const found = this.keywordSource(promptVar)
362
+ if (found == null) return
363
+ found.source.set(updateLora(found.value, lora, withLora(loraSetting(found.value, lora), { mute })))
364
+ }
365
+
366
+ /** the values on screen are not on disk yet: inside the autosave debounce, or a PUT still open */
367
+ get unsaved(): boolean {
368
+ return JSON.stringify(this.valuesJSON()) !== this.lastSaved
369
+ }
370
+
191
371
  get dirtyCount(): number {
192
372
  return this.vars.filter((v) => v.dirty).length
193
373
  }
@@ -234,3 +414,7 @@ export class FormSt {
234
414
  for (const v of this.vars) v.revert()
235
415
  }
236
416
  }
417
+
418
+ function withIntents(values: Record<string, unknown>, intents: Record<string, string>): Record<string, unknown> {
419
+ return Object.keys(intents).length === 0 ? values : { ...values, [ENHANCE_KEY]: intents }
420
+ }
@@ -0,0 +1,59 @@
1
+ // the ⌘K / ⌘J search over every workflow and draft. The list and the match are pure
2
+ // (omnibox.ts); this holds what is typed, which row is lit, and opens the pick
3
+ import { makeAutoObservable } from 'mobx'
4
+ import { omniboxEntries, searchOmnibox, type OmniboxEntry } from 'src/cli/serve/web/state/omnibox.ts'
5
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
6
+
7
+ export class OmniboxSt {
8
+ isOpen = false
9
+ query = ''
10
+ cursor = 0
11
+
12
+ constructor(private st: WebSt) {
13
+ makeAutoObservable<OmniboxSt, 'st'>(this, { st: false })
14
+ }
15
+
16
+ get results(): OmniboxEntry[] {
17
+ return searchOmnibox(omniboxEntries(this.st.modules), this.query)
18
+ }
19
+
20
+ open(): void {
21
+ this.isOpen = true
22
+ this.query = ''
23
+ // the open draft is lit, so Enter right away is a no-op rather than a jump elsewhere
24
+ const current = this.st.form
25
+ const ix =
26
+ current == null
27
+ ? -1
28
+ : this.results.findIndex(
29
+ (e) => e.kind === 'draft' && e.module === current.moduleKey && e.draft === current.draft,
30
+ )
31
+ this.cursor = Math.max(0, ix)
32
+ }
33
+
34
+ close(): void {
35
+ this.isOpen = false
36
+ }
37
+
38
+ toggle(): void {
39
+ if (this.isOpen) this.close()
40
+ else this.open()
41
+ }
42
+
43
+ setQuery(v: string): void {
44
+ this.query = v
45
+ this.cursor = 0
46
+ }
47
+
48
+ move(delta: number): void {
49
+ const n = this.results.length
50
+ if (n === 0) return
51
+ this.cursor = (this.cursor + delta + n) % n
52
+ }
53
+
54
+ pick(entry: OmniboxEntry | undefined = this.results[this.cursor]): void {
55
+ if (entry == null) return
56
+ this.close()
57
+ void this.st.select({ module: entry.module, draft: entry.draft })
58
+ }
59
+ }