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
@@ -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
+ // the names new and duplicate give a draft without asking: rename is one click away, a prompt on
2
+ // every copy is not. PURE, tests/serve-web-draft-names.test.ts
3
+ import { copyName } from 'src/utils/copyName.ts'
4
+
5
+ /** `new`, `new 2`, … the first name no draft of this workflow has */
6
+ export function freeDraftName(drafts: readonly string[]): string {
7
+ if (!drafts.includes('new')) return 'new'
8
+ let n = 2
9
+ while (drafts.includes(`new ${n}`)) n++
10
+ return `new ${n}`
11
+ }
12
+
13
+ /** `shot 007` → `shot 008`, `default` → `default-2`, never a name already taken */
14
+ export function duplicateDraftName(from: string, drafts: readonly string[]): string {
15
+ return copyName(from, drafts)
16
+ }
@@ -0,0 +1,75 @@
1
+ // the open drafts as tabs: pure list operations and key reads, the store (WebSt) owns when they run
2
+ export type DraftTab = { module: string; draft: string }
3
+
4
+ /** where the serve process keeps them, under .comfy-ts/: draft names are private, so this file
5
+ * must stay gitignored (tests/serve-tabs.test.ts runs git check-ignore on it) */
6
+ export const SERVE_TABS_FILE = 'serve-tabs.json'
7
+
8
+ const same = (a: DraftTab, b: DraftTab): boolean => a.module === b.module && a.draft === b.draft
9
+
10
+ /** a draft you open gets a tab at the end; one already open keeps its place */
11
+ export function openTab(tabs: readonly DraftTab[], t: DraftTab): readonly DraftTab[] {
12
+ return tabs.some((x) => same(x, t)) ? tabs : [...tabs, { module: t.module, draft: t.draft }]
13
+ }
14
+
15
+ /** `next` is where to go: the right neighbour of the closed OPEN tab, else its left one, null
16
+ * when the open tab stays. The last tab stays: a draft is always open */
17
+ export function closeTab(
18
+ tabs: readonly DraftTab[],
19
+ t: DraftTab,
20
+ active: DraftTab | null,
21
+ ): { tabs: readonly DraftTab[]; next: DraftTab | null } {
22
+ const ix = tabs.findIndex((x) => same(x, t))
23
+ if (ix < 0 || tabs.length <= 1) return { tabs, next: null }
24
+ const rest = tabs.filter((_, i) => i !== ix)
25
+ if (active == null || !same(active, t)) return { tabs: rest, next: null }
26
+ return { tabs: rest, next: rest[Math.min(ix, rest.length - 1)] ?? null }
27
+ }
28
+
29
+ /** the renamed draft keeps the tab's place, even when the switch already opened it at the end */
30
+ export function renameTab(tabs: readonly DraftTab[], from: DraftTab, to: DraftTab): readonly DraftTab[] {
31
+ const ix = tabs.findIndex((x) => same(x, from))
32
+ const rest = tabs.filter((x) => !same(x, to))
33
+ if (ix < 0) return openTab(rest, to)
34
+ return rest.map((x) => (same(x, from) ? { module: to.module, draft: to.draft } : x))
35
+ }
36
+
37
+ /** ⌘1 to ⌘8 (ctrl elsewhere) the nth tab, ⌘9 the last one, as browsers do */
38
+ export function tabForKey(
39
+ tabs: readonly DraftTab[],
40
+ e: { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean },
41
+ ): DraftTab | null {
42
+ if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
43
+ if (!/^[1-9]$/.test(e.key)) return null
44
+ const n = Number(e.key)
45
+ return (n === 9 ? tabs[tabs.length - 1] : tabs[n - 1]) ?? null
46
+ }
47
+
48
+ /** ⌘PageUp / ⌘PageDown (ctrl elsewhere): the previous or next tab, wrapping at the ends */
49
+ export function tabStepForKey(
50
+ tabs: readonly DraftTab[],
51
+ active: DraftTab | null,
52
+ e: { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean },
53
+ ): DraftTab | null {
54
+ if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
55
+ const dir = e.key === 'PageDown' ? 1 : e.key === 'PageUp' ? -1 : 0
56
+ if (dir === 0 || tabs.length < 2) return null
57
+ const ix = active == null ? -1 : tabs.findIndex((x) => same(x, active))
58
+ if (ix < 0) return (dir > 0 ? tabs[0] : tabs[tabs.length - 1]) ?? null
59
+ return tabs[(ix + dir + tabs.length) % tabs.length] ?? null
60
+ }
61
+
62
+ /** a stored list, shape-checked, keeping only drafts that still exist */
63
+ export function readTabs(raw: unknown, modules: readonly { module: string; drafts: readonly string[] }[]): DraftTab[] {
64
+ if (!Array.isArray(raw)) return []
65
+ const out: DraftTab[] = []
66
+ for (const x of raw as unknown[]) {
67
+ if (x == null || typeof x !== 'object') continue
68
+ const o = x as { module?: unknown; draft?: unknown }
69
+ if (typeof o.module !== 'string' || typeof o.draft !== 'string') continue
70
+ const t = { module: o.module, draft: o.draft }
71
+ if (!modules.some((m) => m.module === t.module && m.drafts.includes(t.draft))) continue
72
+ if (!out.some((y) => same(y, t))) out.push(t)
73
+ }
74
+ return out
75
+ }
@@ -0,0 +1,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: 'Run',
13
+ fill: p.isRunning ? Math.max(0, Math.min(100, Math.round(p.percent ?? 0))) : null,
14
+ running: p.isRunning,
15
+ }
16
+ }
@@ -0,0 +1,54 @@
1
+ // what you submitted, kept for the life of the page: every prompt a generate sent, every text an
2
+ // enhance started from. In memory only, closing the page forgets it. PURE, headless-tested
3
+
4
+ export type HistoryEntry<V> = {
5
+ /** what is searched and shown */
6
+ text: string
7
+ /** what a pick writes back (a prompt var holds a string or lanes) */
8
+ value: V
9
+ /** epoch ms of the LAST time this text was submitted */
10
+ at: number
11
+ /** where it was submitted from, shown dim: `04-krea2-turbo-t2i · prompt` */
12
+ source: string
13
+ /** how many times it was submitted */
14
+ count: number
15
+ }
16
+
17
+ /** a generous bound: a long session stays searchable without the page growing without limit */
18
+ export const HISTORY_CAP = 1000
19
+
20
+ /** newest first, one entry per distinct text: submitting a text again moves it to the top */
21
+ export function pushHistory<V>(
22
+ list: readonly HistoryEntry<V>[],
23
+ next: { text: string; value: V; at: number; source: string },
24
+ ): HistoryEntry<V>[] {
25
+ if (next.text.trim() === '') return [...list]
26
+ const seen = list.find((e) => e.text === next.text)
27
+ const rest = list.filter((e) => e.text !== next.text)
28
+ return [{ ...next, count: (seen?.count ?? 0) + 1 }, ...rest].slice(0, HISTORY_CAP)
29
+ }
30
+
31
+ /** every word of the query must appear in the text (any case, any order); newest first kept.
32
+ * A letter by letter fuzzy match would hit nearly any long prompt, words find the one you mean */
33
+ export function searchHistory<V>(list: readonly HistoryEntry<V>[], query: string): HistoryEntry<V>[] {
34
+ const words = query
35
+ .toLowerCase()
36
+ .split(/\s+/)
37
+ .filter((w) => w !== '')
38
+ if (words.length === 0) return [...list]
39
+ return list.filter((e) => {
40
+ const hay = `${e.text}\n${e.source}`.toLowerCase()
41
+ return words.every((w) => hay.includes(w))
42
+ })
43
+ }
44
+
45
+ export function timeAgo(at: number, now: number): string {
46
+ const s = Math.max(0, Math.round((now - at) / 1000))
47
+ if (s < 10) return 'just now'
48
+ if (s < 60) return `${s}s ago`
49
+ const m = Math.floor(s / 60)
50
+ if (m < 60) return `${m} min ago`
51
+ const h = Math.floor(m / 60)
52
+ if (h < 24) return `${h} h ${m % 60} min ago`
53
+ return `${Math.floor(h / 24)} d ago`
54
+ }
@@ -12,6 +12,7 @@
12
12
  // Host messages run IN ORDER, and not before the boot is done: a message that lands while the
13
13
  // panel is still loading waits for the form instead of being dropped (WebSt.hostChain).
14
14
  // PURE and DOM-free below `isEmbedded`: the parsers are headless-tested.
15
+ import { acceptChoice } from 'src/cli/serve/web/state/choiceButtons.ts'
15
16
  import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
16
17
  import type { HostToPanel, PanelHostAction, PanelToHost } from 'src/cli/serve/hostProtocol.ts'
17
18
  import { asSeedForm, pruneLorasRecord } from 'src/cli/serve/web/state/payload.ts'
@@ -101,8 +102,10 @@ export function coerceHostValue(desc: VarDescriptor, raw: unknown, current: unkn
101
102
  return isFiniteNumber(raw) ? { ok: true, value: raw } : REJECT
102
103
  case 'toggle':
103
104
  return typeof raw === 'boolean' ? { ok: true, value: raw } : REJECT
104
- case 'choice':
105
- return typeof raw === 'string' && (desc.choices ?? []).includes(raw) ? { ok: true, value: raw } : REJECT
105
+ case 'choice': {
106
+ const accepted = acceptChoice({ select: desc.select ?? 'one', choices: desc.choices ?? [], raw })
107
+ return accepted.ok ? { ok: true, value: accepted.value } : REJECT
108
+ }
106
109
  case 'seed': {
107
110
  const cur = asSeedForm(current)
108
111
  if (isFiniteNumber(raw)) return { ok: true, value: { mode: cur.mode, value: Math.max(0, Math.floor(raw)) } }
@@ -0,0 +1,53 @@
1
+ // the lines a prompt keeps VERBATIM through an enhance: negatives (`- `) and comments (`// `).
2
+ // The enhancer sends only the body to the model and writes these back itself, each on its own
3
+ // line, because a model asked to copy them glues a negative onto its last sentence often enough
4
+ // that the workflow then reads it as positive text. PURE, headless-tested
5
+
6
+ const isKept = (line: string): boolean => {
7
+ const t = line.trimStart()
8
+ return t.startsWith('- ') || t.startsWith('// ')
9
+ }
10
+
11
+ export function splitKeptLines(text: string): { body: string; kept: string[] } {
12
+ const lines = text.split('\n')
13
+ return {
14
+ body: lines
15
+ .filter((l) => !isKept(l))
16
+ .join('\n')
17
+ .trim(),
18
+ kept: lines.filter(isKept).map((l) => l.trim()),
19
+ }
20
+ }
21
+
22
+ /** the negative items a kept line names, lowercased: `- blurry, jpeg` → blurry, jpeg */
23
+ function negativeItems(kept: readonly string[]): Set<string> {
24
+ const out = new Set<string>()
25
+ for (const line of kept) {
26
+ if (!line.startsWith('- ')) continue
27
+ for (const item of line.slice(2).split(',')) if (item.trim() !== '') out.add(item.trim().toLowerCase())
28
+ }
29
+ return out
30
+ }
31
+
32
+ /** the model's rewrite with the kept lines put back: whatever negative or comment lines the
33
+ * model wrote are dropped (the kept ones replace them), and a negative it glued onto a line
34
+ * (`… rain. - blurry, jpeg`) is cut off when its first item is one of the kept negatives */
35
+ export function finishRewrite(model: string, kept: readonly string[]): string {
36
+ const items = negativeItems(kept)
37
+ const body = model
38
+ .split('\n')
39
+ .filter((l) => kept.length === 0 || !isKept(l))
40
+ .map((l) => {
41
+ if (items.size === 0) return l
42
+ let at = l.indexOf(' - ')
43
+ while (at !== -1) {
44
+ const first = (l.slice(at + 3).split(',')[0] ?? '').trim().toLowerCase()
45
+ if (items.has(first)) return l.slice(0, at).trimEnd()
46
+ at = l.indexOf(' - ', at + 3)
47
+ }
48
+ return l
49
+ })
50
+ .join('\n')
51
+ .trim()
52
+ return [body, ...kept].filter((x) => x !== '').join('\n')
53
+ }
@@ -0,0 +1,20 @@
1
+ /** how a run's latent frames show: `full` in the running card at the top of the gallery, `corner`
2
+ * in a small floating card so the last image stays in view until the next one lands, `off` none */
3
+ export type LatentMode = 'full' | 'corner' | 'off'
4
+
5
+ export const LATENT_MODES: readonly { mode: LatentMode; tip: string }[] = [
6
+ {
7
+ mode: 'corner',
8
+ tip: 'latent small, in a corner: the last image stays where it is, the new one lands at once when done',
9
+ },
10
+ { mode: 'full', tip: 'latent full size, in the running card at the top of the results' },
11
+ { mode: 'off', tip: 'no latent: a progress bar, then the image' },
12
+ ]
13
+
14
+ /** a stored value → a mode. The blob held a boolean before the corner mode existed: `true` was
15
+ * the old default, never a choice between full and corner, so it takes the new default */
16
+ export function asLatentMode(raw: unknown): LatentMode {
17
+ if (raw === 'full' || raw === 'corner' || raw === 'off') return raw
18
+ if (raw === false) return 'off'
19
+ return 'corner'
20
+ }
@@ -37,3 +37,21 @@ export function sortLoraMatches(p: {
37
37
  })
38
38
  return out
39
39
  }
40
+
41
+ /** what the popup gallery draws: EVERY match, picked ones included, so picking a lora never
42
+ * moves the cards around it. `enterPick` is the first card not picked yet, what enter adds */
43
+ export function popupCards(p: { matches: readonly string[]; picked: readonly string[]; cap: number }): {
44
+ cards: string[]
45
+ enterPick: string | null
46
+ } {
47
+ const cards = p.matches.slice(0, p.cap)
48
+ const picked = new Set(p.picked)
49
+ return { cards, enterPick: cards.find((name) => !picked.has(name)) ?? null }
50
+ }
51
+
52
+ /** a popup card click: the first one adds, every later one pauses or resumes, the same switch as
53
+ * the form card. Only the ✕ removes */
54
+ export function popupCardClick(p: { picked: boolean; on: boolean }): 'add' | 'pause' | 'resume' {
55
+ if (!p.picked) return 'add'
56
+ return p.on ? 'pause' : 'resume'
57
+ }
@@ -1,7 +1,7 @@
1
- // the sidebar is a TREE, not a list: modules keep the folder they came from.
1
+ // modules keep the folder they came from: the omnibox labels read folder/workflow/draft.
2
2
  // PURE and DOM-free (browser side, so no node:path), tests/serve-web-tree.test.ts.
3
3
  // the module KEY stays the basename (it is the api identity); this only decides
4
- // what the sidebar shows above it.
4
+ // the folder part of the label.
5
5
 
6
6
  export type TreeItem = { module: string; file: string }
7
7
 
@@ -0,0 +1,133 @@
1
+ // the omnibox list and its match. PURE and DOM-free, tests/serve-web-omnibox.test.ts.
2
+ // grouped: one workflow row, then its drafts. A query word that IS a tag keeps only the
3
+ // workflows carrying it, the other words fuzzy match names and tags
4
+ import { groupModulesByFolder, type TreeItem } from 'src/cli/serve/web/state/moduleTree.ts'
5
+
6
+ export type OmniModule = TreeItem & { host: string; drafts: string[]; tags?: string[] }
7
+
8
+ /** a workflow row opens `draft`, its first draft */
9
+ export type OmniboxEntry = {
10
+ kind: 'workflow' | 'draft'
11
+ module: string
12
+ draft: string
13
+ host: string
14
+ folder: string
15
+ tags: string[]
16
+ }
17
+
18
+ export function entryKey(e: OmniboxEntry): string {
19
+ return `${e.kind}:${e.module}/${e.draft}`
20
+ }
21
+
22
+ export function omniboxEntries(modules: readonly OmniModule[]): OmniboxEntry[] {
23
+ const out: OmniboxEntry[] = []
24
+ for (const group of groupModulesByFolder(modules)) {
25
+ for (const mod of group.modules) {
26
+ // no saved draft still opens: the server serves the spec values as `default`
27
+ const drafts = mod.drafts.length > 0 ? mod.drafts : ['default']
28
+ const base = { module: mod.module, host: mod.host, folder: group.folder, tags: mod.tags ?? [] }
29
+ out.push({ kind: 'workflow', draft: drafts[0] ?? 'default', ...base })
30
+ for (const draft of drafts) out.push({ kind: 'draft', draft, ...base })
31
+ }
32
+ }
33
+ return out
34
+ }
35
+
36
+ function isBoundary(ch: string | undefined): boolean {
37
+ return ch == null || ch === '/' || ch === '-' || ch === '_' || ch === ' ' || ch === '.'
38
+ }
39
+
40
+ function scoreFrom(q: string, t: string, start: number): number | null {
41
+ let score = 0
42
+ let at = start - 1
43
+ for (const ch of q) {
44
+ const found = t.indexOf(ch, at + 1)
45
+ if (found < 0) return null
46
+ score += 1
47
+ if (found === at + 1) score += 3
48
+ if (isBoundary(t[found - 1])) score += 5
49
+ // late hits cost a little, so the same letters earlier in the label win ties
50
+ score -= (found - at - 1) * 0.05
51
+ at = found
52
+ }
53
+ return score
54
+ }
55
+
56
+ /** subsequence match, higher is better, null when the letters are not all there in order.
57
+ * a letter after a separator or right after the previous hit counts extra. Every place the
58
+ * first letter occurs is tried, since the first `a` of `examples/…/anima` is the wrong one */
59
+ export function fuzzyScore(query: string, text: string): number | null {
60
+ const q = query.toLowerCase().replace(/\s+/g, '')
61
+ if (q === '') return 0
62
+ const t = text.toLowerCase()
63
+ let best: number | null = null
64
+ for (let start = t.indexOf(q[0] ?? ''); start >= 0; start = t.indexOf(q[0] ?? '', start + 1)) {
65
+ const score = scoreFrom(q, t, start)
66
+ if (score != null && (best == null || score > best)) best = score
67
+ }
68
+ return best
69
+ }
70
+
71
+ type Group = { head: OmniboxEntry; drafts: OmniboxEntry[]; ix: number }
72
+
73
+ function groupsOf(entries: readonly OmniboxEntry[]): Group[] {
74
+ const groups: Group[] = []
75
+ for (const e of entries) {
76
+ if (e.kind === 'workflow') groups.push({ head: e, drafts: [], ix: groups.length })
77
+ else groups.at(-1)?.drafts.push(e)
78
+ }
79
+ return groups
80
+ }
81
+
82
+ const max = (a: number | null, b: number | null): number | null => (a == null ? b : b == null ? a : Math.max(a, b))
83
+
84
+ /** a letter scattered across the label scores ~1, one at a word start or in a run ~4 to 6.
85
+ * Below this average the hit is noise, and in a grouped list noise costs a whole workflow */
86
+ const MIN_SCORE_PER_LETTER = 2.5
87
+
88
+ export function searchOmnibox(entries: readonly OmniboxEntry[], query: string): OmniboxEntry[] {
89
+ const words = query
90
+ .trim()
91
+ .toLowerCase()
92
+ .split(/\s+/)
93
+ .filter((w) => w !== '')
94
+ if (words.length === 0) return [...entries]
95
+ const known = new Set(entries.flatMap((e) => e.tags))
96
+ const tagWords = words.filter((w) => known.has(w))
97
+ const text = words.filter((w) => !known.has(w)).join('')
98
+ const scored: { group: Group; score: number; rows: OmniboxEntry[] }[] = []
99
+ for (const group of groupsOf(entries)) {
100
+ if (!tagWords.every((t) => group.head.tags.includes(t))) continue
101
+ if (text === '') {
102
+ scored.push({ group, score: 0, rows: [group.head, ...group.drafts] })
103
+ continue
104
+ }
105
+ const headText = `${group.head.folder}/${group.head.module} ${group.head.tags.join(' ')}`
106
+ const good = (score: number | null): number | null =>
107
+ score != null && score >= text.length * MIN_SCORE_PER_LETTER ? score : null
108
+ const headScore = good(fuzzyScore(text, headText))
109
+ // the draft name alone first: typing a draft name should not lose to a folder that shares letters
110
+ const drafts = group.drafts
111
+ .map((d) => {
112
+ const own = good(fuzzyScore(text, d.draft))
113
+ return {
114
+ d,
115
+ own,
116
+ score: max(own == null ? null : own + 2, good(fuzzyScore(text, `${headText}/${d.draft}`))),
117
+ }
118
+ })
119
+ .filter((x): x is { d: OmniboxEntry; own: number | null; score: number } => x.score != null)
120
+ const draftHits = drafts.filter((x) => x.own != null)
121
+ const best = max(
122
+ headScore,
123
+ drafts.reduce<number | null>((m, x) => max(m, x.score), null),
124
+ )
125
+ if (best == null) continue
126
+ // drafts matched by their own name are what was searched; otherwise the whole workflow
127
+ const shown =
128
+ draftHits.length > 0 ? [...draftHits].sort((a, b) => b.score - a.score).map((x) => x.d) : group.drafts
129
+ scored.push({ group, score: best, rows: [group.head, ...shown] })
130
+ }
131
+ scored.sort((a, b) => b.score - a.score || a.group.ix - b.group.ix)
132
+ return scored.flatMap((s) => s.rows)
133
+ }
@@ -3,6 +3,9 @@
3
3
  // override payloads any more: drafts are live (autosave through PUT, generate
4
4
  // posts {}) — architecture item 12, web ui
5
5
  import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
6
+ import { normalizeChoice } from 'src/cli/serve/web/state/choiceButtons.ts'
7
+ import { isLoraLanes, type LoraRecord, type LorasInput } from 'src/vars/lanes.ts'
8
+ import { isLoraStrength, loraInPalette, loraIsOn as entryIsOn, loraStrengths, withLora } from 'src/vars/loraEntry.ts'
6
9
 
7
10
  export type SeedFormValue = { mode: string; value: number }
8
11
  export type SizeFormValue = { width: number; height: number }
@@ -38,25 +41,33 @@ export function asSizeForm(raw: unknown): SizeFormValue {
38
41
  return { width: 1024, height: 1024 }
39
42
  }
40
43
 
41
- /** the record the web keeps holds ON loras ONLY, so it always reads as "what is in the
42
- * palette". Two things are dropped: keys the host no longer offers (dead weight the ui
43
- * cannot display, and a server-side build failure), and `false` entries, LorasVar writes
44
- * one for every lora ever unticked, so treating them as palette members put the WHOLE
45
- * catalog in the row. Off is off: `activeLoras` skips both spellings, so nothing changes
46
- * in the graph, and with live drafts the next autosave heals the file */
47
- export function pruneLorasRecord(raw: unknown, options: readonly string[]): Record<string, unknown> {
44
+ /** the record the web keeps holds PALETTE loras only: on, or paused in the palette form. Two
45
+ * things are dropped: keys the host no longer offers (dead weight the ui cannot display, and a
46
+ * server-side build failure), and `false` entries, which LorasVar writes for every lora ever
47
+ * unticked in the TUI, so treating them as palette members put the WHOLE catalog in the row.
48
+ * A pause is `{ strength, off: true }` (src/vars/loraEntry.ts), never `false`, so it survives */
49
+ export function pruneLorasRecord(raw: unknown, options: readonly string[]): LoraRecord {
48
50
  if (raw == null || typeof raw !== 'object' || Array.isArray(raw)) return {}
49
51
  const known = new Set(options)
50
- const out: Record<string, unknown> = {}
51
- for (const [k, st] of Object.entries(raw as Record<string, unknown>)) if (known.has(k) && loraIsOn(st)) out[k] = st
52
+ const out: LoraRecord = {}
53
+ for (const [k, st] of Object.entries(raw as Record<string, unknown>))
54
+ if (known.has(k) && isLoraStrength(st) && loraInPalette(st)) out[k] = st
52
55
  return out
53
56
  }
54
57
 
58
+ /** either shape, pruned the same way: a plain record, or every lane's record */
59
+ export function normalizeLorasInput(raw: unknown, options: readonly string[]): LorasInput {
60
+ if (isLoraLanes(raw)) return { lanes: raw.lanes.map((l) => ({ ...l, loras: pruneLorasRecord(l.loras, options) })) }
61
+ return pruneLorasRecord(raw, options)
62
+ }
63
+
55
64
  /** what a fresh VarSt starts from: the draft value when present, else the descriptor default — seed/size/loras normalized so controls never branch on shape */
56
65
  export function normalizeInitial(desc: VarDescriptor, raw: unknown): unknown {
57
66
  if (desc.kind === 'seed') return asSeedForm(raw ?? desc.default)
58
67
  if (desc.kind === 'size') return asSizeForm(raw ?? desc.default)
59
- if (desc.kind === 'loras') return pruneLorasRecord(raw ?? desc.default, desc.options ?? [])
68
+ if (desc.kind === 'loras') return normalizeLorasInput(raw ?? desc.default, desc.options ?? [])
69
+ if (desc.kind === 'choice')
70
+ return normalizeChoice({ select: desc.select ?? 'one', choices: desc.choices ?? [], raw: raw ?? desc.default })
60
71
  return raw ?? desc.default
61
72
  }
62
73
 
@@ -64,65 +75,35 @@ export function randomSeed(): number {
64
75
  return Math.floor(Math.random() * 2 ** 32)
65
76
  }
66
77
 
67
- // ---- loras record transitions (LorasVar's semantics, mirrored for the web) ----
68
- // key absent = not selected · false = SELECTED but off (stays in the ui) ·
69
- // number | [model, clip] | true = on. LorasVar keeps the same `prev` memory so
70
- // off → on restores the strength instead of snapping to 1
78
+ // ---- loras record transitions: the stored spellings live in src/vars/loraEntry.ts, shared
79
+ // with LorasVar and serve, so the web and the library can never read a lora differently
71
80
 
72
81
  export type LoraStrengthPair = { model: number; clip: number }
73
82
 
74
83
  export function loraIsOn(st: unknown): boolean {
75
- return st != null && st !== false
84
+ return entryIsOn(st)
76
85
  }
77
86
 
78
87
  /** any stored strength shape → the {model, clip} pair the inputs edit */
79
88
  export function loraStrengthPair(st: unknown): LoraStrengthPair {
80
- if (typeof st === 'number' && Number.isFinite(st)) return { model: st, clip: st }
81
- if (Array.isArray(st) && typeof st[0] === 'number' && typeof st[1] === 'number') return { model: st[0], clip: st[1] }
82
- return { model: 1, clip: 1 }
89
+ const [model, clip] = loraStrengths(st)
90
+ return { model, clip }
83
91
  }
84
92
 
85
- /** pause/resume. A PAUSE removes the lora from the record entirely — the palette membership
86
- * of a paused lora lives in the ui, not in the draft, so a draft never accumulates the
87
- * off-entries that flooded the palette. Resuming writes the remembered strength back */
88
- export function setLoraEnabled(
89
- record: Record<string, unknown>,
90
- name: string,
91
- on: boolean,
92
- prev?: LoraStrengthPair,
93
- ): Record<string, unknown> {
94
- const next = { ...record }
95
- // PAUSE KEEPS THE KEY (as `false`): deleting it dropped the lora out of the record's
96
- // insertion order, so pausing a card sent it to the end of the row. `false` is the same
97
- // "selected but off" spelling LorasVar uses, every reader ignores it, and normalizeInitial
98
- // prunes it on load, so nothing accumulates in the draft file
99
- if (!on) next[name] = false
100
- else {
101
- const pair = prev ?? loraStrengthPair(record[name])
102
- next[name] = [pair.model, pair.clip]
103
- }
104
- return next
93
+ /** pause/resume in place: the key, its position and its strengths all stay */
94
+ export function setLoraEnabled(record: Record<string, unknown>, name: string, on: boolean): Record<string, unknown> {
95
+ return { ...record, [name]: withLora(record[name], { on }) }
105
96
  }
106
97
 
107
- /**
108
- * the palette, IN ORDER: the record's own key order (newest last on disk, shown newest FIRST),
109
- * plus loras paused in this session that already left the record. Pure, because the order is
110
- * the thing a drag rewrites and a pause must not touch.
111
- */
112
- export function paletteOrder(p: {
113
- record: Record<string, unknown>
114
- options: readonly string[]
115
- /** paused in this session — kept in the palette even when the record no longer lists them */
116
- paused: ReadonlySet<string>
117
- }): string[] {
98
+ /** the palette, IN ORDER: the record's own key order, so a lora you add lands at the end and
99
+ * nothing already on screen moves. Pure, because the order is what a drag rewrites */
100
+ export function paletteOrder(p: { record: Record<string, unknown>; options: readonly string[] }): string[] {
118
101
  const known = new Set(p.options)
119
- const inRecord = Object.keys(p.record).filter((n) => known.has(n) && (loraIsOn(p.record[n]) || p.paused.has(n)))
120
- const pausedOnly = [...p.paused].filter((n) => known.has(n) && !inRecord.includes(n))
121
- return [...inRecord, ...pausedOnly].reverse()
102
+ return Object.keys(p.record).filter((n) => known.has(n) && loraInPalette(p.record[n]))
122
103
  }
123
104
 
124
- /** move a lora to a new slot in the PALETTE (what the row shows, newest first) and give back the
125
- * record rewritten in that order, the record's key order IS the stored order */
105
+ /** move a lora to a new slot in the palette and give back the record rewritten in that order,
106
+ * the record's key order IS the stored order */
126
107
  export function reorderLoras(p: {
127
108
  record: Record<string, unknown>
128
109
  /** palette order, as displayed */
@@ -135,18 +116,17 @@ export function reorderLoras(p: {
135
116
  if (moved == null) return p.record
136
117
  next.splice(p.to, 0, moved)
137
118
  const out: Record<string, unknown> = {}
138
- // displayed is newest-first; the record stores the opposite, so it is written back reversed
139
- for (const name of [...next].reverse()) if (name in p.record) out[name] = p.record[name]
119
+ for (const name of next) if (name in p.record) out[name] = p.record[name]
140
120
  // anything the palette does not show (a key pruned from view) keeps its entry
141
121
  for (const [k, v] of Object.entries(p.record)) if (!(k in out)) out[k] = v
142
122
  return out
143
123
  }
144
124
 
145
- /** set both strengths; an OFF lora stays off (its strength is edited on re-enable) */
125
+ /** set both strengths; a paused lora stays paused */
146
126
  export function setLoraStrength(
147
127
  record: Record<string, unknown>,
148
128
  name: string,
149
129
  pair: LoraStrengthPair,
150
130
  ): Record<string, unknown> {
151
- return { ...record, [name]: [pair.model, pair.clip] }
131
+ return { ...record, [name]: withLora(record[name], { strength: [pair.model, pair.clip] }) }
152
132
  }