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
@@ -1,8 +1,8 @@
1
1
  // web ui bundle resolution (architecture item 12, web ui): prebuilt
2
2
  // dist/serve-web.js next to the running module, else an in-memory Bun.build
3
- // from source (src/ ships in the npm tarball), else null — the api must serve
4
- // without a UI, never crash
5
- import { existsSync, readFileSync } from 'node:fs'
3
+ // from source (src/ ships in the npm tarball), rebuilt when a source file changes,
4
+ // else null — the api must serve without a UI, never crash
5
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
6
6
  import { fileURLToPath } from 'node:url'
7
7
  import { dirname, join } from 'pathe'
8
8
 
@@ -43,11 +43,42 @@ export async function buildWebJsText(pkgRoot: string): Promise<string> {
43
43
  return await result.outputs[0].text()
44
44
  }
45
45
 
46
- /** the runtime resolution chain; every miss logs loud and degrades to api-only */
46
+ /** changes whenever a file under `dir` is added, removed or rewritten. The web bundle reaches
47
+ * outside web/ (vars, protocol types), so the whole src/ tree is the input: ~300 stats, a few ms */
48
+ export function sourceSignature(dir: string): string {
49
+ let count = 0
50
+ let newest = 0
51
+ let bytes = 0
52
+ const walk = (d: string): void => {
53
+ for (const entry of readdirSync(d, { withFileTypes: true })) {
54
+ const abs = join(d, entry.name)
55
+ if (entry.isDirectory()) walk(abs)
56
+ else if (entry.isFile()) {
57
+ const st = statSync(abs)
58
+ count += 1
59
+ bytes += st.size
60
+ newest = Math.max(newest, st.mtimeMs)
61
+ }
62
+ }
63
+ }
64
+ walk(dir)
65
+ return `${count}:${bytes}:${newest}`
66
+ }
67
+
68
+ let prebuiltJs: string | null = null
69
+ let fromSource: { signature: string; js: Promise<string | null> } | null = null
70
+
71
+ /** the runtime resolution chain; every miss logs loud and degrades to api-only. Called on every
72
+ * page load: a prebuilt file is read once, a source build is redone only when src/ changed, so
73
+ * an edited panel shows on refresh under `bun --watch`, which never sees the bundled files */
47
74
  export async function loadOrBuildWebJs(): Promise<string | null> {
48
75
  const here = dirname(fileURLToPath(import.meta.url))
49
76
  const prebuilt = join(here, 'serve-web.js')
50
- if (existsSync(prebuilt)) return readFileSync(prebuilt, 'utf8')
77
+ if (prebuiltJs != null) return prebuiltJs
78
+ if (existsSync(prebuilt)) {
79
+ prebuiltJs = readFileSync(prebuilt, 'utf8')
80
+ return prebuiltJs
81
+ }
51
82
  if (typeof Bun === 'undefined') {
52
83
  console.error('[serve] 🔴 no serve-web.js next to the cli and not running under bun — api only, no web ui')
53
84
  return null
@@ -57,10 +88,23 @@ export async function loadOrBuildWebJs(): Promise<string | null> {
57
88
  console.error(`[serve] 🔴 web ui source not found (looked for ${WEB_ENTRY} above ${here}) — api only, no web ui`)
58
89
  return null
59
90
  }
60
- try {
61
- return await buildWebJsText(pkgRoot)
62
- } catch (e) {
63
- console.error('[serve] 🔴 web ui bundle failed — api only:', e)
64
- return null
91
+ const signature = sourceSignature(join(pkgRoot, 'src'))
92
+ if (fromSource?.signature !== signature) {
93
+ const rebuilt = fromSource != null
94
+ // a failed build stays failed for this signature: logged once, retried on the next edit
95
+ fromSource = {
96
+ signature,
97
+ js: buildWebJsText(pkgRoot).then(
98
+ (js) => {
99
+ if (rebuilt) console.log('[serve] web ui rebuilt from source')
100
+ return js
101
+ },
102
+ (e: unknown) => {
103
+ console.error('[serve] 🔴 web ui bundle failed — api only until the next edit:', e)
104
+ return null
105
+ },
106
+ ),
107
+ }
65
108
  }
109
+ return await fromSource.js
66
110
  }
@@ -50,6 +50,8 @@ export const Header = observer((p: { st: TuiSt }) => {
50
50
  {s.hostOverride != null && s.hostOverride !== s.wf.host && (
51
51
  <Text color="yellow"> ⇄ overrides {s.wf.host.data.id}</Text>
52
52
  )}
53
+ {/* the host changed under the loaded schema: say what, and where the fix is */}
54
+ {s.host.drift !== '' && <Text color="yellow"> ⚠ changed: {s.host.drift} · a → re-codegen</Text>}
53
55
  {/* while down, show the probe loop living: spinner in flight, countdown between tries */}
54
56
  {s.host.status === 'down' && (
55
57
  <Text color="red"> {s.host.probing ? s.host.spinner : `↻ ${s.host.retryInS}s`}</Text>
@@ -26,11 +26,18 @@ export const ChoiceOverlay = observer((p: { st: TuiSt }) => {
26
26
  node: (
27
27
  <Text key={opt} inverse={ix === pk.ix}>
28
28
  {ix === pk.ix ? '▸ ' : ' '}
29
+ {pk.isPicked(opt) ? '● ' : '○ '}
29
30
  {opt}
30
31
  </Text>
31
32
  ),
32
33
  }))}
33
- footer={options.length === 0 ? <Text color="red">no match</Text> : undefined}
34
+ footer={
35
+ options.length === 0 ? (
36
+ <Text color="red">no match</Text>
37
+ ) : pk.choiceIsMany ? (
38
+ <Text color="gray">⏎ toggles · esc done</Text>
39
+ ) : undefined
40
+ }
34
41
  />
35
42
  )
36
43
  })
@@ -41,7 +48,7 @@ export const PresetOverlay = observer((p: { st: TuiSt }) => {
41
48
  const s = p.st
42
49
  const pk = s.picker
43
50
  const options = pk.presetOptions
44
- const current = pk.presetVar?.value.trim() ?? ''
51
+ const current = pk.presetVar?.toEditBuffer().trim() ?? ''
45
52
  return (
46
53
  <OverlayList
47
54
  title={
@@ -38,7 +38,7 @@ export class ImagePickerSt {
38
38
  reaction(
39
39
  () => (this.st.mode === 'overlay-image' ? this.highlightedImage : null),
40
40
  () => void this.refreshPreview(),
41
- { delay: 120 },
41
+ { delay: this.st.timing.previewMs },
42
42
  ),
43
43
  )
44
44
  }
@@ -13,6 +13,7 @@ import { dirname, join } from 'pathe'
13
13
  import { moduleName } from 'src/cli/tui/treeRows.ts'
14
14
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
15
15
  import type { TuiMode, TuiSt } from 'src/cli/tui/state/TuiSt.ts'
16
+ import { isDraftRecord, preserveDraftMeta } from 'src/cli/draftMeta.ts'
16
17
 
17
18
  /** module basename (`01-txt2img`) keys the draft folder — knowable for EVERY tree file without importing it */
18
19
  export function draftKeyForFile(file: string): string {
@@ -51,7 +52,7 @@ export class DraftsSt {
51
52
  (json) => {
52
53
  if (json != null && this.active != null) this.write(this.active, json)
53
54
  },
54
- { delay: 300 },
55
+ { delay: this.st.timing.autosaveMs },
55
56
  ),
56
57
  )
57
58
  }
@@ -73,10 +74,11 @@ export class DraftsSt {
73
74
  return Object.fromEntries(this.st.entries.map(([k, varDef]) => [k, varDef.toJSON()]))
74
75
  }
75
76
 
77
+ // the TUI knows only the var values: what the panel stored beside them ($enhance) stays
76
78
  private write(name: string, json: string): void {
77
79
  const path = join(this.dir, `${name}.json`)
78
80
  mkdirSync(dirname(path), { recursive: true })
79
- writeFileSync(path, json)
81
+ writeFileSync(path, keepDraftMeta(path, json))
80
82
  this.version++
81
83
  }
82
84
 
@@ -271,3 +273,17 @@ export class DraftsSt {
271
273
  this.st.mode = 'nav'
272
274
  }
273
275
  }
276
+
277
+ /** the new json, plus the `$` keys the file on disk already carried (src/cli/draftMeta.ts) */
278
+ function keepDraftMeta(path: string, json: string): string {
279
+ if (!existsSync(path)) return json
280
+ let previous: unknown
281
+ try {
282
+ previous = JSON.parse(readFileSync(path, 'utf8'))
283
+ } catch {
284
+ return json
285
+ }
286
+ const next: unknown = JSON.parse(json)
287
+ if (!isDraftRecord(previous) || !isDraftRecord(next)) return json
288
+ return JSON.stringify(preserveDraftMeta(previous, next), null, 2)
289
+ }
@@ -63,7 +63,7 @@ export class EditorSt {
63
63
  const sel = this.st.selected?.[1]
64
64
  if (sel == null) return
65
65
  this.st.mode = 'overlay-text'
66
- this.buffer = String(sel.value)
66
+ this.buffer = sel.toEditBuffer()
67
67
  this.cursor = [...this.buffer].length
68
68
  this.invalid = false
69
69
  }
@@ -2,12 +2,15 @@ import { makeAutoObservable, reaction, runInAction } from 'mobx'
2
2
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
3
3
  import type { ComfyHost } from 'src/host/ComfyHost.ts'
4
4
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
5
+ import { summarizeDrift } from 'src/host/schemaDrift.ts'
5
6
 
6
7
  type HostAction = { key: 'refresh' | 'restart' | 'clear-queue' | 'interrupt'; label: string }
7
8
 
8
9
  export type HostStatus = 'unknown' | 'up' | 'down'
9
10
 
10
11
  const PROBE_EVERY_MS = 5000
12
+ /** a light drift check (the loaders only) at most this often while the host is up */
13
+ const DRIFT_EVERY_MS = 60_000
11
14
  const PROBE_TIMEOUT_MS = 3000
12
15
  /** ws message younger than this = the host is alive, whatever http says */
13
16
  export const WS_ALIVE_MS = 10_000
@@ -55,6 +58,7 @@ export class HostSt {
55
58
  this.status = 'unknown'
56
59
  this.statusVia = null
57
60
  this.lastProbeError = null // the previous host's failure must not show under the new one
61
+ this.drift = ''
58
62
  })
59
63
  this.probeGen++
60
64
  if (this.loopTimer != null) clearTimeout(this.loopTimer)
@@ -148,6 +152,7 @@ export class HostSt {
148
152
  }
149
153
  }
150
154
  if (this.host !== host) return // workflow switched mid-flight: stale verdict
155
+ const before = this.status
151
156
  const verdict = probeVerdict({
152
157
  httpOk: ok,
153
158
  wsOpen: host.isConnected,
@@ -159,6 +164,34 @@ export class HostSt {
159
164
  this.statusVia = verdict.via
160
165
  this.lastProbeError = probeError
161
166
  })
167
+ // first seen up, or back from down (a restart nobody announced): a full check. Otherwise a
168
+ // light one now and then, so a lora added under a running TUI still shows
169
+ if (verdict.status === 'up') {
170
+ if (before !== 'up') void this.checkDrift(true)
171
+ else if (Date.now() - this.driftAt > DRIFT_EVERY_MS) void this.checkDrift(false)
172
+ }
173
+ }
174
+
175
+ /** what changed on the host since its schema was loaded (`+5 loras`), '' when nothing is known
176
+ * to have changed. A committed catalog (sdkAutoWrite: false, the cloud) is never compared */
177
+ drift = ''
178
+ driftAt = 0
179
+
180
+ private async checkDrift(full: boolean): Promise<void> {
181
+ const host = this.host
182
+ if (host.data.sdkAutoWrite === false) return
183
+ this.driftAt = Date.now()
184
+ try {
185
+ const summary = summarizeDrift(await host.checkSchemaDrift({ full }))
186
+ if (this.host !== host) return
187
+ runInAction(() => {
188
+ // a clean LIGHT check cannot clear what a full one found (node types it does not see)
189
+ if (summary !== '') this.drift = summary
190
+ else if (full) this.drift = ''
191
+ })
192
+ } catch {
193
+ // reachability is the probe loop's job, and it already says so: a failed check just waits
194
+ }
162
195
  }
163
196
 
164
197
  ix: number = 0
@@ -278,6 +311,7 @@ export class HostSt {
278
311
  runInAction(() => {
279
312
  const schema = this.host.schema
280
313
  this.st.exec.notice = `SDK regenerated: ${schema.nodes.length} node types, ${schema.getLoras().length} loras`
314
+ this.drift = ''
281
315
  })
282
316
  } catch (e) {
283
317
  runInAction(() => {
@@ -23,7 +23,7 @@ export class LorasSt {
23
23
  reaction(
24
24
  () => (this.st.mode === 'overlay-loras' ? this.selectedName : null),
25
25
  () => void this.refreshPreview(),
26
- { delay: 120 },
26
+ { delay: this.st.timing.previewMs },
27
27
  ),
28
28
  )
29
29
  }
@@ -1,6 +1,6 @@
1
1
  import { makeAutoObservable } from 'mobx'
2
2
  import { fuzzyMatch } from 'src/utils/fuzzyMatch.ts'
3
- import type { ChoiceVar, PromptVar, SizeVar, TextVar } from 'src/vars/ComfyVars.ts'
3
+ import type { AnyChoiceVar, PromptVar, SizeVar, TextVar } from 'src/vars/ComfyVars.ts'
4
4
  import type { VarPreset } from 'src/vars/presets.ts'
5
5
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
6
6
 
@@ -25,9 +25,21 @@ export class PickerSt {
25
25
  imageSizeRow: string | null = null
26
26
 
27
27
  // kind-narrowing casts sanctioned (agent/coding.md), `kind` is the tag
28
- private get choiceVar(): ChoiceVar<string> | null {
28
+ private get choiceVar(): AnyChoiceVar<string> | null {
29
29
  const sel = this.st.selected?.[1]
30
- return sel?.kind === 'choice' ? (sel as ChoiceVar<string>) : null
30
+ return sel?.kind === 'choice' ? (sel as AnyChoiceVar<string>) : null
31
+ }
32
+
33
+ /** is this option currently picked (one, one or none, or one of many) */
34
+ isPicked(option: string): boolean {
35
+ const cv = this.choiceVar
36
+ if (cv == null) return false
37
+ return cv.select === 'many' ? cv.value.includes(option) : cv.value === option
38
+ }
39
+
40
+ /** a many-choice stays open after ⏎: you toggle several, esc leaves */
41
+ get choiceIsMany(): boolean {
42
+ return this.choiceVar?.select === 'many'
31
43
  }
32
44
 
33
45
  private get sizeVar(): SizeVar | null {
@@ -76,7 +88,8 @@ export class PickerSt {
76
88
  this.st.mode = 'overlay-choice'
77
89
  this.filter = ''
78
90
  this.invalid = false
79
- this.ix = Math.max(0, cv.choices.indexOf(cv.value))
91
+ const first = cv.select === 'many' ? cv.value[0] : cv.value
92
+ this.ix = Math.max(0, first == null ? 0 : cv.choices.indexOf(first))
80
93
  }
81
94
 
82
95
  /** `P` on a text/prompt var that declares presets. A var without any stays on `nav`:
@@ -87,7 +100,7 @@ export class PickerSt {
87
100
  this.st.mode = 'overlay-preset'
88
101
  this.filter = ''
89
102
  this.invalid = false
90
- const value = pv.value.trim()
103
+ const value = pv.toEditBuffer().trim()
91
104
  const ix = pv.presets.findIndex((x) => x.text.trim() === value)
92
105
  this.ix = ix === -1 ? 0 : ix
93
106
  }
@@ -142,9 +155,14 @@ export class PickerSt {
142
155
  }
143
156
  const cv = this.choiceVar
144
157
  if (cv != null) {
145
- const hit = this.options[this.ix]
158
+ const hit = cv.choices.find((c) => c === this.options[this.ix])
146
159
  if (hit == null) return
147
- cv.set(hit)
160
+ if (cv.select === 'many') {
161
+ cv.toggle(hit)
162
+ return
163
+ }
164
+ if (cv.select === 'zero-or-one') cv.toggle(hit)
165
+ else cv.set(hit)
148
166
  this.st.mode = 'nav'
149
167
  return
150
168
  }
@@ -43,7 +43,7 @@ export class SettingsSt {
43
43
  reaction(
44
44
  () => this.snapshotJson(),
45
45
  (json) => this.write(json),
46
- { delay: 300 },
46
+ { delay: this.st.timing.autosaveMs },
47
47
  ),
48
48
  )
49
49
  // the delayed reaction can be cancelled by dispose with a write pending —
@@ -41,6 +41,9 @@ export type TuiMode =
41
41
  * ROOT of the TUI state tree (one instance per run). Children are service
42
42
  * classes with an `st` backref; components are stateless views over this.
43
43
  */
44
+ export type TuiTiming = { previewMs: number; autosaveMs: number }
45
+ export const TUI_TIMING: TuiTiming = { previewMs: 120, autosaveMs: 300 }
46
+
44
47
  export class TuiSt {
45
48
  wf: DefinedWorkflow
46
49
  mode: TuiMode = 'nav'
@@ -86,6 +89,9 @@ export class TuiSt {
86
89
  logs: LogsSt
87
90
  settings: SettingsSt
88
91
 
92
+ /** the debounces the sub-stores run on */
93
+ readonly timing: TuiTiming
94
+
89
95
  /** owned cleanups (reactions, listeners) — flushed by dispose() */
90
96
  disposers: (() => void)[] = []
91
97
  onExit: () => void = () => {}
@@ -99,15 +105,19 @@ export class TuiSt {
99
105
  bundledFiles?: Set<string>
100
106
  /** modules that failed to load before mount (red rows in the tree) */
101
107
  loadErrors?: Map<string, string>
108
+ /** tests set these to a few ms rather than wait them out */
109
+ timing?: TuiTiming
102
110
  } = {},
103
111
  ) {
104
112
  this.wf = wf
113
+ this.timing = opts.timing ?? TUI_TIMING
105
114
  // wf: observableRef so switching workflows re-renders without proxying
106
115
  // the foreign object; children manage their own observability
107
116
  makeAutoObservable(this, {
108
117
  wf: observableRef,
109
118
  hostOverride: observableRef,
110
119
  onExit: false,
120
+ timing: false,
111
121
  editor: false,
112
122
  picker: false,
113
123
  loras: false,
@@ -85,11 +85,16 @@ export {
85
85
  SeedVar,
86
86
  ToggleVar,
87
87
  ChoiceVar,
88
+ OptionalChoiceVar,
89
+ MultiChoiceVar,
88
90
  LorasVar,
89
91
  SizeVar,
90
92
  ImageVar,
91
93
  ImageVarEmptyError,
92
94
  DEFAULT_SIZE_PRESETS,
95
+ SD15_SIZE_PRESETS,
96
+ DEFAULT_STARRED_SIZES,
97
+ sizePresetsFor,
93
98
  DEFAULT_IMAGE_EXTENSIONS,
94
99
  activeLoras,
95
100
  } from 'src/vars/ComfyVars.ts'
@@ -97,6 +102,9 @@ export type {
97
102
  AnyVar,
98
103
  VarKind,
99
104
  VarsSpec,
105
+ VarUi,
106
+ AnyChoiceVar,
107
+ ChoiceSelect,
100
108
  VarValues,
101
109
  PromptValue,
102
110
  ActiveLoraSource,
@@ -107,8 +115,20 @@ export type {
107
115
  SizePreset,
108
116
  ImageVarOpts,
109
117
  TextVarOpts,
118
+ PromptVarOpts,
119
+ PromptTagsOpts,
110
120
  } from 'src/vars/ComfyVars.ts'
111
121
  export { toPresetList, activePresetLabel, type VarPreset, type VarPresetSpec } from 'src/vars/presets.ts'
122
+ export type {
123
+ PromptInput,
124
+ PromptLane,
125
+ PromptLanes,
126
+ LorasInput,
127
+ LoraLane,
128
+ LoraLanes,
129
+ LoraRecord,
130
+ } from 'src/vars/lanes.ts'
131
+ export type { LoraEntry } from 'src/vars/loraEntry.ts'
112
132
  export { DefinedWorkflow, type DefineWorkflowSpec, type BoundVars, type LoraNameOf } from 'src/vars/DefinedWorkflow.ts'
113
133
  export {
114
134
  clearLoraKeywordOverride,
@@ -36,6 +36,7 @@ import type { Requirements } from 'src/host/Requirements.ts'
36
36
  import { ResilientWebSocketClient, type WsMessageEvent } from 'src/host/ResilientWebsocket.ts'
37
37
  import { DefinedWorkflow, type DefineWorkflowSpec } from 'src/vars/DefinedWorkflow.ts'
38
38
  import type { VarsSpec } from 'src/vars/ComfyVars.ts'
39
+ import { diffSchemas, MODEL_LISTS, type SchemaDrift } from 'src/host/schemaDrift.ts'
39
40
 
40
41
  export type ComfyHostID = Tagged<string, { HostID: true }>
41
42
  export type ComfyHostData = {
@@ -678,6 +679,20 @@ export class ComfyHost<ID extends string = string> {
678
679
  if (!res.ok) throw new Error(`PATCH /internal/logs/subscribe failed: ${res.status}`)
679
680
  }
680
681
 
682
+ /** what changed on the host since this schema was loaded (src/host/schemaDrift.ts). `full: false`
683
+ * asks only the loaders the schema has, a few KB, so it can run on a timer. Throws when the host
684
+ * cannot be reached, which is itself the signal a caller watches for a restart */
685
+ checkSchemaDrift = async (p: { full: boolean }): Promise<SchemaDrift> => {
686
+ const loaded: Record<string, unknown> = this.schema.data.spec
687
+ const live: Record<string, unknown> = {}
688
+ if (p.full) Object.assign(live, await this.fetchJSON_<Record<string, unknown>>('/object_info'))
689
+ else
690
+ for (const m of MODEL_LISTS)
691
+ if (loaded[m.node] != null)
692
+ Object.assign(live, await this.fetchJSON_<Record<string, unknown>>(`/object_info/${m.node}`))
693
+ return diffSchemas({ loaded, live, full: p.full })
694
+ }
695
+
681
696
  /** GET a JSON route through host.fetch (/api preferred, bare fallback) */
682
697
  private fetchJSON_ = async <T>(route: string): Promise<T> => {
683
698
  const base = this.getServerHostHTTP()
@@ -8,7 +8,9 @@ import {
8
8
  lmFolder,
9
9
  lmItemKey,
10
10
  lmModelName,
11
+ lmModified,
11
12
  lmPreviewUrl,
13
+ lmSha256,
12
14
  lmTags,
13
15
  lmTrainedWords,
14
16
  loraBasename,
@@ -193,6 +195,68 @@ export function getLoraDisplayName(name: string, hostId?: string): string {
193
195
  return (info == null ? null : lmModelName(info)) ?? loraBasename(name)
194
196
  }
195
197
 
198
+ /** what the mirror knows about a lora's trigger words. The extension drops an EMPTY
199
+ * `trainedWords` when it slims the civitai block (model_scanner.py `if trained_words:`), so a
200
+ * block linked to civitai (an `id`) with no words means fetched and empty, while no block at
201
+ * all means civitai was never asked. null = the lora is not in the mirror */
202
+ export type LoraTriggers =
203
+ | { state: 'words'; words: string[] }
204
+ | { state: 'none' }
205
+ | { state: 'unfetched' }
206
+ /** civitai was asked and has no version for this file (a private or local lora) */
207
+ | { state: 'not-on-civitai' }
208
+
209
+ export function loraTriggersOf(item: LmLoraItem, p: { civitaiMiss?: boolean } = {}): LoraTriggers {
210
+ const words = lmTrainedWords(item)
211
+ if (words.length > 0) return { state: 'words', words }
212
+ const civitai = item['civitai']
213
+ if (isRecord(civitai) && (typeof civitai['id'] === 'number' || typeof civitai['modelId'] === 'number'))
214
+ return { state: 'none' }
215
+ return p.civitaiMiss === true ? { state: 'not-on-civitai' } : { state: 'unfetched' }
216
+ }
217
+
218
+ export function getLoraTriggers(name: string, hostId?: string): LoraTriggers | null {
219
+ const info = getLoraInfo(name, hostId)
220
+ if (info == null) return null
221
+ const sha = lmSha256(info)
222
+ return loraTriggersOf(info, { civitaiMiss: hostId != null && sha != null && readCivitaiMisses(hostId)[sha] != null })
223
+ }
224
+
225
+ // the lora manager records nothing when civitai has no version for a file, so the answer is kept
226
+ // here, keyed by content hash (a rename keeps it): without it such a lora would offer a fetch
227
+ // that fails the same way forever
228
+ function civitaiMissesPath(hostId: string): AbsolutePath {
229
+ return comfyts.resolveFromHosts(join(hostId, 'lora-civitai-misses.json'))
230
+ }
231
+
232
+ /** sha256 → when civitai said it has no version for that file */
233
+ export function readCivitaiMisses(hostId: string): Record<string, string> {
234
+ const text = getComfyStorage().readTextIfExists(civitaiMissesPath(hostId))
235
+ if (text == null) return {}
236
+ try {
237
+ const raw: unknown = JSON.parse(text)
238
+ const out: Record<string, string> = {}
239
+ if (isRecord(raw)) for (const [sha, at] of Object.entries(raw)) if (typeof at === 'string') out[sha] = at
240
+ return out
241
+ } catch (e) {
242
+ logError(`[loraInfoCache] unreadable ${civitaiMissesPath(hostId)}: ${String(e)}`)
243
+ return {}
244
+ }
245
+ }
246
+
247
+ export function recordCivitaiMiss(p: { hostId: string; sha256: string; miss: boolean }): void {
248
+ const misses = readCivitaiMisses(p.hostId)
249
+ if (p.miss) misses[p.sha256] = new Date().toISOString()
250
+ else delete misses[p.sha256]
251
+ getComfyStorage().writeText(civitaiMissesPath(p.hostId), JSON.stringify(misses, null, 2))
252
+ }
253
+
254
+ /** when the lora file landed on the host (epoch seconds), null when unsynced/unknown */
255
+ export function getLoraAddedAt(name: string, hostId?: string): number | null {
256
+ const info = getLoraInfo(name, hostId)
257
+ return info == null ? null : lmModified(info)
258
+ }
259
+
196
260
  /** server-relative preview url from the mirror, null when unsynced/unknown */
197
261
  export function getLoraPreviewUrl(name: string, hostId?: string): string | null {
198
262
  const info = getLoraInfo(name, hostId)
@@ -269,3 +333,9 @@ export function loraMatchesFilter(name: string, filter: string, hostId?: string)
269
333
  const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase())
270
334
  return tokens.every((token) => fields.some((field) => field.includes(token)))
271
335
  }
336
+
337
+ /** the loras a host lists that the local copy of its lora manager list does not know yet:
338
+ * downloaded after the last sync, so they have no name, preview or trigger words here */
339
+ export function lorasMissingFromMirror(hostLoras: readonly string[], inMirror: (name: string) => boolean): string[] {
340
+ return hostLoras.filter((n) => !inMirror(n))
341
+ }
@@ -58,6 +58,12 @@ export function lmSha256(item: LmLoraItem): string | null {
58
58
  return readString(item, 'sha256')
59
59
  }
60
60
 
61
+ /** when the file landed on the host (epoch seconds): the lora manager's own "date added" sort reads it */
62
+ export function lmModified(item: LmLoraItem): number | null {
63
+ const raw = item['modified']
64
+ return typeof raw === 'number' && Number.isFinite(raw) ? raw : null
65
+ }
66
+
61
67
  export function lmFileSize(item: LmLoraItem): number | null {
62
68
  const raw = item['file_size']
63
69
  return typeof raw === 'number' && Number.isFinite(raw) ? raw : null
@@ -140,6 +146,27 @@ export type LoraSweep =
140
146
  /** the host itself could not be reached (down, refused, auth) */
141
147
  | { status: 'unreachable'; reason: string }
142
148
 
149
+ /** asks the extension to (re)fetch civitai metadata for ONE lora file, trigger words included.
150
+ * The reply says why when civitai has nothing for it (a private or deleted model) */
151
+ export async function fetchLoraCivitai(
152
+ host: ComfyHost,
153
+ filePath: string,
154
+ ): Promise<{ ok: true } | { ok: false; reason: string }> {
155
+ try {
156
+ const res = await host.fetch('/lm/loras/fetch-civitai', {
157
+ method: 'POST',
158
+ headers: { 'content-type': 'application/json' },
159
+ body: JSON.stringify({ file_path: filePath }),
160
+ })
161
+ const raw: unknown = await res.json().catch(() => null)
162
+ const error = isRecord(raw) && typeof raw['error'] === 'string' ? raw['error'] : null
163
+ if (res.ok && isRecord(raw) && raw['success'] !== false) return { ok: true }
164
+ return { ok: false, reason: error ?? `the lora manager answered ${res.status}` }
165
+ } catch (e) {
166
+ return { ok: false, reason: extractErrorMessage(e) }
167
+ }
168
+ }
169
+
143
170
  /** civitai's model description for ONE lora, as PLAIN TEXT. The extension answers html, and
144
171
  * html from a third party is never rendered: tags are stripped here, at the seam.
145
172
  * null = the extension has no description for it (or does not expose the route) */