comfy-ts 2.7.0 → 2.9.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 (104) hide show
  1. package/README.md +20 -13
  2. package/dist/{DefinedWorkflow-BJgt5t0x.js → DefinedWorkflow-BatWaZO1.js} +199 -16
  3. package/dist/DefinedWorkflow-BatWaZO1.js.map +1 -0
  4. package/dist/{DraftsSt-dizp3VcC.js → LogsSt-DFxzQfDc.js} +152 -4
  5. package/dist/LogsSt-DFxzQfDc.js.map +1 -0
  6. package/dist/cli.js +7 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +284 -35
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +125 -7
  11. package/dist/index.d.ts +125 -7
  12. package/dist/index.js +282 -37
  13. package/dist/index.js.map +1 -1
  14. package/dist/run-serve-_nrvJYyt.js +1948 -0
  15. package/dist/run-serve-_nrvJYyt.js.map +1 -0
  16. package/dist/{run-tui-JxlEbb_f.js → run-tui-BLEdTsOX.js} +106 -157
  17. package/dist/run-tui-BLEdTsOX.js.map +1 -0
  18. package/dist/serve-web.js +441 -72
  19. package/dist/{state-CaHeDL-0.js → state-BbgJeCe6.js} +180 -45
  20. package/dist/state-BbgJeCe6.js.map +1 -0
  21. package/dist/web.d.ts +185 -7
  22. package/dist/web.js +235 -36
  23. package/dist/web.js.map +1 -1
  24. package/examples/README.md +1 -0
  25. package/examples/comfy-cloud/sdk.d.ts +4066 -321
  26. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +18 -2
  27. package/examples/rvion/07-local-llm-text-gen.cflow.ts +220 -0
  28. package/examples/web/tsconfig.json +3 -0
  29. package/extra/README.md +32 -0
  30. package/extra/comfyui-textgen-stream/README.md +35 -0
  31. package/extra/comfyui-textgen-stream/__init__.py +166 -0
  32. package/extra/scripts/fetch_text_encoder.py +137 -0
  33. package/package.json +6 -3
  34. package/src/cli/comfy-ts-cli.ts +3 -1
  35. package/src/cli/serve/ServeApp.ts +754 -40
  36. package/src/cli/serve/applyVarPayload.ts +10 -3
  37. package/src/cli/serve/describeVar.ts +47 -7
  38. package/src/cli/serve/hostProtocol.ts +68 -0
  39. package/src/cli/serve/managerOnlyLoras.ts +27 -0
  40. package/src/cli/serve/run-serve.ts +35 -38
  41. package/src/cli/serve/serveSettings.ts +86 -0
  42. package/src/cli/serve/startupPrint.ts +111 -0
  43. package/src/cli/serve/web/api.ts +97 -1
  44. package/src/cli/serve/web/components/App.tsx +61 -22
  45. package/src/cli/serve/web/components/Gallery.tsx +306 -41
  46. package/src/cli/serve/web/components/Icon.tsx +160 -0
  47. package/src/cli/serve/web/components/PromptEnhancer.tsx +12 -9
  48. package/src/cli/serve/web/components/Sidebar.tsx +43 -19
  49. package/src/cli/serve/web/components/VarsForm.tsx +440 -91
  50. package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
  51. package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
  52. package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
  53. package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
  54. package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
  55. package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
  56. package/src/cli/serve/web/llm.ts +1 -1
  57. package/src/cli/serve/web/logWeb.ts +6 -0
  58. package/src/cli/serve/web/state/EnhancerSt.ts +8 -15
  59. package/src/cli/serve/web/state/FormSt.ts +74 -18
  60. package/src/cli/serve/web/state/RunSt.ts +22 -1
  61. package/src/cli/serve/web/state/WebSt.ts +814 -22
  62. package/src/cli/serve/web/state/host.ts +206 -0
  63. package/src/cli/serve/web/state/lightbox.ts +44 -0
  64. package/src/cli/serve/web/state/moduleTree.ts +52 -0
  65. package/src/cli/serve/web/state/payload.ts +44 -2
  66. package/src/cli/serve/web/state/urlSelection.ts +53 -0
  67. package/src/cli/serve/web/styles.ts +422 -57
  68. package/src/cli/serve/web/tsconfig.json +4 -0
  69. package/src/cli/tui/components/PickerOverlays.tsx +37 -0
  70. package/src/cli/tui/components/StatusBar.tsx +14 -1
  71. package/src/cli/tui/components/TuiApp.tsx +5 -2
  72. package/src/cli/tui/state/HostSt.ts +3 -2
  73. package/src/cli/tui/state/PickerSt.ts +48 -2
  74. package/src/cli/tui/state/TreeSt.ts +1 -1
  75. package/src/cli/tui/state/TuiSt.ts +2 -1
  76. package/src/coreExports.ts +8 -1
  77. package/src/graph/ComfyNode.ts +58 -1
  78. package/src/host/ComfyHost.ts +13 -2
  79. package/src/host/ComfyManager.ts +31 -13
  80. package/src/host/loraInfoCache.ts +35 -1
  81. package/src/host/loraManagerApi.ts +94 -0
  82. package/src/index.ts +2 -0
  83. package/src/promptEnhancers.ts +102 -0
  84. package/src/runner/ComfyExecution.ts +61 -6
  85. package/src/runner/ComfyWorkflow.ts +18 -4
  86. package/src/runner/ComfyWsApi.ts +3 -0
  87. package/src/runner/describePromptRejection.ts +34 -0
  88. package/src/sdk-generator/ComfySchema.ts +17 -4
  89. package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
  90. package/src/utils/ansi.ts +13 -0
  91. package/src/utils/matchesRegex.ts +13 -0
  92. package/src/utils/safeName.ts +29 -0
  93. package/src/utils/stringMap.ts +9 -0
  94. package/src/vars/ComfyVars.ts +61 -10
  95. package/src/vars/presets.ts +17 -0
  96. package/src/web.ts +12 -0
  97. package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
  98. package/dist/DraftsSt-dizp3VcC.js.map +0 -1
  99. package/dist/run-serve-D1Tsuru9.js +0 -1162
  100. package/dist/run-serve-D1Tsuru9.js.map +0 -1
  101. package/dist/run-tui-JxlEbb_f.js.map +0 -1
  102. package/dist/state-CaHeDL-0.js.map +0 -1
  103. package/src/cli/serve/promptEnhancers.ts +0 -69
  104. package/src/cli/serve/safeName.ts +0 -12
@@ -35,6 +35,43 @@ export const ChoiceOverlay = observer((p: { st: TuiSt }) => {
35
35
  )
36
36
  })
37
37
 
38
+ /** modal preset picker (`P` on a text/prompt var): the label, then a dim peek at the text it
39
+ * writes — two presets whose names are close are told apart by their first line, not by memory */
40
+ export const PresetOverlay = observer((p: { st: TuiSt }) => {
41
+ const s = p.st
42
+ const pk = s.picker
43
+ const options = pk.presetOptions
44
+ const current = pk.presetVar?.value.trim() ?? ''
45
+ return (
46
+ <OverlayList
47
+ title={
48
+ <>
49
+ presets {s.selected ? (s.selected[1].label ?? s.selected[0]) : ''}{' '}
50
+ <Text color="gray">· ⏎ replaces the text</Text>
51
+ </>
52
+ }
53
+ extraHeader={<Text color="yellow">filter: {pk.filter}▌</Text>}
54
+ selectedIx={pk.ix}
55
+ lines={s.overlayLines}
56
+ rows={options.map((opt, ix) => ({
57
+ key: opt.label,
58
+ node: (
59
+ <Text key={opt.label} inverse={ix === pk.ix} wrap="truncate">
60
+ {ix === pk.ix ? '▸ ' : ' '}
61
+ {opt.text.trim() === current ? '• ' : ' '}
62
+ {opt.label} <Text color="gray">{firstLine(opt.text)}</Text>
63
+ </Text>
64
+ ),
65
+ }))}
66
+ footer={options.length === 0 ? <Text color="red">no match</Text> : undefined}
67
+ />
68
+ )
69
+ })
70
+
71
+ function firstLine(text: string): string {
72
+ return text.split('\n').find((l) => l.trim() !== '') ?? ''
73
+ }
74
+
38
75
  /** modal size picker: presets, or type `WxH` and ⏎ for a custom size */
39
76
  export const SizeOverlay = observer((p: { st: TuiSt }) => {
40
77
  const s = p.st
@@ -105,6 +105,12 @@ const MODE_KEYS: Partial<Record<string, Hint[]>> = {
105
105
  ['type', 'filter'],
106
106
  ['esc', 'cancel'],
107
107
  ],
108
+ 'overlay-preset': [
109
+ ['⏎', 'use this text'],
110
+ ['↑↓', 'move'],
111
+ ['type', 'filter'],
112
+ ['esc', 'cancel'],
113
+ ],
108
114
  'overlay-size': [
109
115
  ['⏎', 'pick'],
110
116
  ['↑↓', 'move'],
@@ -172,7 +178,14 @@ export const KeyBar = observer((p: { st: TuiSt }) => {
172
178
  ['↑↓', 'move'],
173
179
  ['esc', 'clear'],
174
180
  ]
175
- : (MODE_KEYS[s.mode] ?? [['↑↓', 'select'], ['←', 'tree'], ...(kind ? (KIND_KEYS[kind] ?? []) : [])])
181
+ : (MODE_KEYS[s.mode] ?? [
182
+ ['↑↓', 'select'],
183
+ ['←', 'tree'],
184
+ ...(kind ? (KIND_KEYS[kind] ?? []) : []),
185
+ // advertised only on a row that HAS presets: a key offered on every text var would
186
+ // open nothing four times out of five
187
+ ...(s.picker.presetVar != null ? ([['P', 'presets']] as Hint[]) : []),
188
+ ])
176
189
  // keys already advertised by a panel title (t/v/p) or a header box (w/d/h/a)
177
190
  // are NOT repeated here — one letter, one place
178
191
  const globalHints: Hint[] =
@@ -6,7 +6,7 @@ import { Header } from 'src/cli/tui/components/Header.tsx'
6
6
  import { HostPanel } from 'src/cli/tui/components/HostPanel.tsx'
7
7
  import { HostsOverlay } from 'src/cli/tui/components/HostsOverlay.tsx'
8
8
  import { LorasOverlay } from 'src/cli/tui/components/LorasOverlay.tsx'
9
- import { ChoiceOverlay, SizeOverlay } from 'src/cli/tui/components/PickerOverlays.tsx'
9
+ import { ChoiceOverlay, PresetOverlay, SizeOverlay } from 'src/cli/tui/components/PickerOverlays.tsx'
10
10
  import { PreviewPanel } from 'src/cli/tui/components/PreviewPanel.tsx'
11
11
  import { PromptOverlay } from 'src/cli/tui/components/PromptOverlay.tsx'
12
12
  import { KeyBar, ProgressLine } from 'src/cli/tui/components/StatusBar.tsx'
@@ -72,7 +72,7 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
72
72
  if (input && !key.ctrl && !key.meta) return ed.input(input)
73
73
  return
74
74
  }
75
- if (s.mode === 'overlay-choice' || s.mode === 'overlay-size') {
75
+ if (s.mode === 'overlay-choice' || s.mode === 'overlay-size' || s.mode === 'overlay-preset') {
76
76
  const pk = s.picker
77
77
  if (key.escape) return s.editor.cancel()
78
78
  if (key.return) return pk.commit()
@@ -237,6 +237,7 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
237
237
  s.tree.focus()
238
238
  return s.tree.beginFilter()
239
239
  }
240
+ if (input === 'P') return s.picker.beginPresets()
240
241
  if (input === 'e') return s.drafts.beginRename()
241
242
  if (input === 'r') return void s.exec.run()
242
243
  if (input === 's') return s.exec.randomizeSeedAndRun()
@@ -273,6 +274,8 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
273
274
  <TextOverlay st={s} />
274
275
  ) : s.mode === 'overlay-choice' ? (
275
276
  <ChoiceOverlay st={s} />
277
+ ) : s.mode === 'overlay-preset' ? (
278
+ <PresetOverlay st={s} />
276
279
  ) : s.mode === 'overlay-size' ? (
277
280
  <SizeOverlay st={s} />
278
281
  ) : s.mode === 'overlay-loras' ? (
@@ -300,9 +300,10 @@ export class HostSt {
300
300
  this.st.exec.notice = 'reboot requested — the ws reconnects when the host is back'
301
301
  })
302
302
  } catch (e) {
303
- // the server dropping the connection mid-reboot IS the expected shape
303
+ // restartComfyUI already resolves on the mid-reboot disconnect, so an error here is a
304
+ // host that REFUSED. Reporting it as "requested" is how a dead button looks alive
304
305
  runInAction(() => {
305
- this.st.exec.notice = `reboot requested (${extractErrorMessage(e)}) — the ws reconnects when the host is back`
306
+ this.st.exec.notice = `🔴 reboot refused: ${extractErrorMessage(e)}`
306
307
  })
307
308
  } finally {
308
309
  runInAction(() => {
@@ -1,10 +1,14 @@
1
1
  import { makeAutoObservable } from 'mobx'
2
2
  import { fuzzyMatch } from 'src/utils/fuzzyMatch.ts'
3
- import type { ChoiceVar, SizeVar } from 'src/vars/ComfyVars.ts'
3
+ import type { ChoiceVar, PromptVar, SizeVar, TextVar } from 'src/vars/ComfyVars.ts'
4
+ import type { VarPreset } from 'src/vars/presets.ts'
4
5
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
5
6
 
7
+ /** the two var classes that carry presets */
8
+ type PresetVar = TextVar | PromptVar
9
+
6
10
  /**
7
- * choice + size overlays: a windowed option list with a fuzzy type-to-filter.
11
+ * choice + size + preset overlays: a windowed option list with a fuzzy type-to-filter.
8
12
  * For sizes the filter doubles as free `WxH` entry.
9
13
  */
10
14
  export class PickerSt {
@@ -31,7 +35,26 @@ export class PickerSt {
31
35
  return sel?.kind === 'size' ? (sel as SizeVar) : null
32
36
  }
33
37
 
38
+ /** null when the selected var is not text/prompt, or carries no presets */
39
+ get presetVar(): PresetVar | null {
40
+ const sel = this.st.selected?.[1]
41
+ if (sel == null || (sel.kind !== 'text' && sel.kind !== 'prompt')) return null
42
+ const withPresets = sel as PresetVar
43
+ return withPresets.presets.length === 0 ? null : withPresets
44
+ }
45
+
46
+ /** the preset rows the filter kept — the label AND the text are searched, since what you
47
+ * remember of a preset is often a phrase inside it */
48
+ get presetOptions(): VarPreset[] {
49
+ const pv = this.presetVar
50
+ if (pv == null) return []
51
+ if (this.filter === '') return pv.presets
52
+ return pv.presets.filter((x) => fuzzyMatch(this.filter, `${x.label} ${x.text}`))
53
+ }
54
+
34
55
  get options(): string[] {
56
+ const pv = this.presetVar
57
+ if (pv != null) return this.presetOptions.map((x) => x.label)
35
58
  const cv = this.choiceVar
36
59
  if (cv != null) {
37
60
  if (this.filter === '') return [...cv.choices]
@@ -56,6 +79,19 @@ export class PickerSt {
56
79
  this.ix = Math.max(0, cv.choices.indexOf(cv.value))
57
80
  }
58
81
 
82
+ /** `P` on a text/prompt var that declares presets. A var without any stays on `nav`:
83
+ * the keybar only advertises the key when the row has some */
84
+ beginPresets(): void {
85
+ const pv = this.presetVar
86
+ if (pv == null) return
87
+ this.st.mode = 'overlay-preset'
88
+ this.filter = ''
89
+ this.invalid = false
90
+ const value = pv.value.trim()
91
+ const ix = pv.presets.findIndex((x) => x.text.trim() === value)
92
+ this.ix = ix === -1 ? 0 : ix
93
+ }
94
+
59
95
  beginSize(): void {
60
96
  const sv = this.sizeVar
61
97
  if (sv == null) return
@@ -94,6 +130,16 @@ export class PickerSt {
94
130
  }
95
131
 
96
132
  commit(): void {
133
+ const pv = this.presetVar
134
+ if (pv != null) {
135
+ const hit = this.presetOptions[this.ix]
136
+ if (hit == null) return
137
+ // REPLACES the value, like the web panel's menu: a preset is a starting text, and the
138
+ // draft the row came from is what reverts it
139
+ pv.set(hit.text)
140
+ this.st.mode = 'nav'
141
+ return
142
+ }
97
143
  const cv = this.choiceVar
98
144
  if (cv != null) {
99
145
  const hit = this.options[this.ix]
@@ -120,7 +120,7 @@ export class TreeSt {
120
120
  this.ix = ix === -1 ? 0 : ix
121
121
  }
122
122
 
123
- // ---- viewport (his small-terminal overflow repro 2026-07-31) ----
123
+ // ---- viewport (a small terminal clipped the selection off-screen) ----
124
124
 
125
125
  /** measured height of the tree panel Box (TreePanel measureElement); 0 = not measured yet */
126
126
  viewH: number = 0
@@ -29,6 +29,7 @@ export type TuiMode =
29
29
  | 'edit'
30
30
  | 'overlay-text'
31
31
  | 'overlay-choice'
32
+ | 'overlay-preset'
32
33
  | 'overlay-size'
33
34
  | 'overlay-loras'
34
35
  | 'overlay-image'
@@ -246,7 +247,7 @@ export class TuiSt {
246
247
  this.selIx = (this.selIx + delta + len) % len
247
248
  }
248
249
 
249
- // ---- vars viewport (reviewer follow-up 2026-07-31: the fixed-height
250
+ // ---- vars viewport (the fixed-height
250
251
  // frame clips instead of overflowing, so the vars list must window like
251
252
  // the tree — measured height, never chrome arithmetic) ----
252
253
 
@@ -33,7 +33,12 @@ export {
33
33
  type ProgressReport,
34
34
  type RunSettings,
35
35
  } from 'src/runner/ComfyWorkflow.ts'
36
- export { ComfyExecution, type ComfyExecutionData, type ExecutionProgress } from 'src/runner/ComfyExecution.ts'
36
+ export {
37
+ ComfyExecution,
38
+ type ComfyExecutionData,
39
+ type ComfyTextOutput,
40
+ type ExecutionProgress,
41
+ } from 'src/runner/ComfyExecution.ts'
37
42
  export type { PromptID, WsMsg, PromptRelated_WsMsg } from 'src/runner/ComfyWsApi.ts'
38
43
  export { MediaImage, type MediaImageData } from 'src/runner/MediaImage.ts'
39
44
  export type { ComfyExecutionStatus } from 'src/runner/ComfyExecutionStatus.ts'
@@ -101,7 +106,9 @@ export type {
101
106
  SizeValue,
102
107
  SizePreset,
103
108
  ImageVarOpts,
109
+ TextVarOpts,
104
110
  } from 'src/vars/ComfyVars.ts'
111
+ export { toPresetList, activePresetLabel, type VarPreset, type VarPresetSpec } from 'src/vars/presets.ts'
105
112
  export { DefinedWorkflow, type DefineWorkflowSpec, type BoundVars, type LoraNameOf } from 'src/vars/DefinedWorkflow.ts'
106
113
  export {
107
114
  clearLoraKeywordOverride,
@@ -4,6 +4,8 @@ import type { ComfyNodeSchema } from 'src/sdk-generator/ComfyNodeSchema.ts'
4
4
  import type { ComfyApiNodeJson } from 'src/sdk-generator/comfy-api-json.ts'
5
5
  import type { NodeInputExt, NodeOutputExt } from 'src/sdk-generator/comfyui-types.ts'
6
6
  import { ComfyDefaultNodeWhenUnknown_Name } from 'src/sdk-generator/Primitives.ts'
7
+ import { classifySchemaInput, defaultValueForWidget } from 'src/sdk-generator/inputWidgetKind.ts'
8
+ import type { DynamicComboOption } from 'src/sdk-generator/inputWidgetKind.ts'
7
9
  import type { Maybe } from 'src/types/index.ts'
8
10
  import { comfyColors } from 'src/utils/ComfyColors.ts'
9
11
  import { auto_ } from 'src/graph/autoValue.ts'
@@ -13,6 +15,9 @@ import { NodeSlotSize, NodeTitleHeight, nodeLineHeight } from 'src/graph/NodeSlo
13
15
 
14
16
  type NodeExecutionStatus = 'executing' | 'done' | 'error' | 'waiting' | 'cached' | null
15
17
 
18
+ const isScalarValue = (x: unknown): x is string | number | boolean =>
19
+ typeof x === 'string' || typeof x === 'number' || typeof x === 'boolean'
20
+
16
21
  export type NodePort = {
17
22
  id: string
18
23
  label: string
@@ -176,8 +181,22 @@ export class ComfyNode<
176
181
  _convertPromptExtToPrompt(promptExt: ComfyApiNodeJson): ComfyApiNodeJson {
177
182
  const inputs: { [inputName: string]: any } = {}
178
183
  const _done = new Set<string>()
184
+ /** every dotted key of every branch: the selected ones are written here, the rest are dropped */
185
+ const _comboBranchKeys = new Set<string>()
179
186
  for (const i of this.$schema.inputs) {
180
187
  _done.add(i.nameInComfy)
188
+ const kind = classifySchemaInput(i)
189
+ if (kind.kind === 'dynamic-combo') {
190
+ this._writeDynamicCombo({
191
+ name: i.nameInComfy,
192
+ options: kind.options,
193
+ defaultKey: kind.defaultKey,
194
+ provided: promptExt.inputs,
195
+ out: inputs,
196
+ claimed: _comboBranchKeys,
197
+ })
198
+ continue
199
+ }
181
200
  const value = this.serializeValue(i.nameInComfy, promptExt.inputs[i.nameInComfy])
182
201
  // absent optionals (autogrow containers included) stay OUT of the
183
202
  // prompt: an `undefined` value would already be dropped by JSON
@@ -185,13 +204,51 @@ export class ComfyNode<
185
204
  if (value !== undefined) inputs[i.nameInComfy] = value
186
205
  }
187
206
  for (const [nameInComfy, rawVal] of Object.entries(promptExt.inputs)) {
188
- if (_done.has(nameInComfy)) continue
207
+ if (_done.has(nameInComfy) || _comboBranchKeys.has(nameInComfy)) continue
189
208
  const value = this.serializeValue(nameInComfy, rawVal)
190
209
  inputs[nameInComfy] = value
191
210
  }
192
211
  return { class_type: this.$schema.nameInComfy, inputs }
193
212
  }
194
213
 
214
+ /** dynamic combo → the key plus ONLY the selected branch's dotted inputs, absent ones
215
+ * filled from the schema (agent/architecture.md, dynamic-combo fill). The host declares
216
+ * those branch inputs required and default-fills none of them */
217
+ private _writeDynamicCombo(p: {
218
+ name: string
219
+ options: DynamicComboOption[]
220
+ defaultKey: string
221
+ provided: { [k: string]: unknown }
222
+ out: { [k: string]: any }
223
+ claimed: Set<string>
224
+ }): void {
225
+ for (const opt of p.options) for (const e of opt.inputs) p.claimed.add(`${p.name}.${e.name}`)
226
+ const raw = p.provided[p.name]
227
+ const key = typeof raw === 'string' ? raw : p.defaultKey
228
+ const branch = p.options.find((o) => o.key === key)
229
+ if (branch == null) {
230
+ const known = p.options.map((o) => o.key).join(', ')
231
+ console.error(`🔴 unknown "${p.name}" option ${JSON.stringify(key)} (known: ${known})`)
232
+ this.graph.recordProblem(
233
+ `🔴 unknown "${p.name}" option ${JSON.stringify(key)} on ${this.$schema.nodeKey}#${this.uid} (known: ${known})`,
234
+ )
235
+ return
236
+ }
237
+ p.out[p.name] = key
238
+ for (const e of branch.inputs) {
239
+ const dotted = `${p.name}.${e.name}`
240
+ const given = p.provided[dotted]
241
+ p.out[dotted] =
242
+ given === undefined
243
+ ? defaultValueForWidget({
244
+ type: typeof e.type === 'string' ? e.type : 'COMBO',
245
+ opts: e.opts,
246
+ enumValues: Array.isArray(e.type) ? e.type.filter(isScalarValue) : undefined,
247
+ })
248
+ : this.serializeValue(dotted, given)
249
+ }
250
+ }
251
+
195
252
  /** return the list of nodes piped into this node */
196
253
  _incomingNodes(): ComfyNodeId[] {
197
254
  const incomingNodes: ComfyNodeId[] = []
@@ -773,6 +773,9 @@ export class ComfyHost<ID extends string = string> {
773
773
  /** byte-level latent-preview hook (e.g. TUI live preview panel) */
774
774
  onLatentPreview: Maybe<(p: { bytes: Uint8Array; mime: string; promptID: Maybe<PromptID> }) => void> = null
775
775
 
776
+ /** a node's live display text, as it produces it (`PromptServer.send_progress_text`) */
777
+ onProgressText: Maybe<(p: { nodeId: string; text: string; promptID: Maybe<PromptID> }) => void> = null
778
+
776
779
  /** fires on every ws 'status' message (queue length lives there) */
777
780
  onStatus: Maybe<(p: { queueRemaining: number }) => void> = null
778
781
 
@@ -840,8 +843,16 @@ export class ComfyHost<ID extends string = string> {
840
843
  this._unknownBinaryFrameTypes.add(frame.eventType)
841
844
  console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`)
842
845
  }
843
- // frame.kind === 'text' (node progress text) is dropped: the json
844
- // 'progress' messages already carry everything we surface
846
+ if (frame.kind === 'text') {
847
+ // a node's live display text (`PromptServer.send_progress_text`), REPLACEMENT
848
+ // semantics per node: each frame is that node's current text, not a delta. This is
849
+ // the only channel on which text arrives DURING a node, so a streaming generator
850
+ // reaches us here and nowhere else. An early frame lost to the pre-registration
851
+ // window needs no buffering (unlike an output image): the next frame replaces it
852
+ const exec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null
853
+ exec?.onProgressText({ nodeId: frame.nodeId, text: frame.text })
854
+ this.onProgressText?.({ nodeId: frame.nodeId, text: frame.text, promptID: this.activePromptID })
855
+ }
845
856
  return
846
857
  }
847
858
 
@@ -80,19 +80,37 @@ export class ComfyManager {
80
80
  rebootComfyUIAndUpdateHostPluginsAndModelsAfter10Seconds(): Promise<void> {
81
81
  // 🔴 bad code
82
82
  setTimeout(() => void this.fetchPluginsAndModels(), 10_000)
83
- // curl 'http://<host>:8188/api/manager/reboot' \
84
- // -H 'Accept: */*' \
85
- // -H 'Accept-Language: en-GB' \
86
- // -H 'Cache-Control: max-age=0' \
87
- // -H 'Comfy-User: undefined' \
88
- // -H 'Connection: keep-alive' \
89
- // -H 'Referer: http://<host>:8188/' \
90
- // -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) cushystudio-shell/32.1.2 Chrome/128.0.6613.162 Electron/32.1.2 Safari/537.36'
91
- return this.fetchGetJSON('/manager/reboot')
92
- }
93
-
94
- restartComfyUI = async (): Promise<unknown> => {
95
- return this.fetchGetJSON('/manager/reboot')
83
+ return this.restartComfyUI()
84
+ }
85
+
86
+ /**
87
+ * reboot the ComfyUI process (ComfyUI-Manager).
88
+ *
89
+ * The server dies mid-request, so a DROPPED CONNECTION is the success shape and the only
90
+ * one most callers ever see. A 404 is not: the route is POST from Manager V3 on (verified
91
+ * against V3.41), and a GET there answers 404 while the process keeps running — a caller
92
+ * that treats every failure as "expected mid-reboot disconnect" then reports a reboot that
93
+ * never happened. Both verbs are tried so an old and a new Manager both work, and anything
94
+ * that is neither a disconnect nor a 404 throws with what the host actually said.
95
+ */
96
+ restartComfyUI = async (): Promise<void> => {
97
+ const refusals: string[] = []
98
+ for (const method of ['POST', 'GET'] as const) {
99
+ let response: Response
100
+ try {
101
+ response = await this.host.fetch('/manager/reboot', { method })
102
+ } catch {
103
+ return // connection gone: the process is going down, which is what we asked for
104
+ }
105
+ if (response.ok) return
106
+ refusals.push(`${method} → ${response.status}`)
107
+ // only a missing route is worth retrying with the other verb
108
+ if (response.status !== 404) break
109
+ }
110
+ throw new Error(
111
+ `🔴 ${this.host.getServerHostHTTP()} refused to reboot (${refusals.join(', ')}) — ` +
112
+ `ComfyUI-Manager is not installed there, or its reboot route moved again`,
113
+ )
96
114
  }
97
115
 
98
116
  modelList: Maybe<ComfyManagerAPIModelList> = null
@@ -3,6 +3,9 @@ import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
3
3
  import {
4
4
  type LmLoraItem,
5
5
  lmBaseModel,
6
+ lmFileName,
7
+ lmFilePath,
8
+ lmFolder,
6
9
  lmItemKey,
7
10
  lmModelName,
8
11
  lmPreviewUrl,
@@ -33,7 +36,7 @@ export type LoraMirror = {
33
36
  loras: Record<string, LmLoraItem>
34
37
  }
35
38
 
36
- export function loraMirrorPath(hostId: string): AbsolutePath {
39
+ function loraMirrorPath(hostId: string): AbsolutePath {
37
40
  return comfyts.resolveFromHosts(join(hostId, 'loras.json'))
38
41
  }
39
42
 
@@ -197,6 +200,37 @@ export function getLoraPreviewUrl(name: string, hostId?: string): string | null
197
200
  }
198
201
 
199
202
  /** the lora's NAMES: the file, and the model name a human would call it by */
203
+ /**
204
+ * every lora the mirror knows for a host: its normalized KEY (comparable with `loraKey(option)`,
205
+ * never with a raw enum value, those keep their case, extension and windows separators) and the
206
+ * NAME a ComfyUI graph would load it by, rebuilt from the manager's folder + real filename.
207
+ * `[]` when the host was never synced.
208
+ */
209
+ export function loraMirrorEntries(
210
+ hostId: string,
211
+ p: { separator?: '/' | '\\' } = {},
212
+ ): {
213
+ key: string
214
+ serverName: string
215
+ }[] {
216
+ ensureLoaded()
217
+ const sep = p.separator ?? '/'
218
+ const out: { key: string; serverName: string }[] = []
219
+ for (const [key, item] of byHost.get(hostId) ?? []) {
220
+ // file_path carries the extension the enum value needs; file_name may not
221
+ const filePath = lmFilePath(item)
222
+ const base = filePath == null ? null : (filePath.split(/[/\\]/).pop() ?? null)
223
+ const file = base ?? lmFileName(item)
224
+ if (file == null) continue
225
+ const folder = lmFolder(item)
226
+ // the manager's own `folder` can be a NESTED path with its own separators, so the whole
227
+ // name is normalized to the host's style, never just the join (8 of 119 came out mixed)
228
+ const joined = folder === '' ? file : `${folder}/${file}`
229
+ out.push({ key, serverName: joined.replaceAll(/[\\/]/g, sep) })
230
+ }
231
+ return out.sort((a, b) => a.serverName.localeCompare(b.serverName))
232
+ }
233
+
200
234
  export function loraSearchNames(name: string, hostId?: string): string[] {
201
235
  const names = [loraBasename(name), name.replaceAll('\\', '/')]
202
236
  const info = getLoraInfo(name, hostId)
@@ -52,6 +52,33 @@ export function lmBaseModel(item: LmLoraItem): string | null {
52
52
  export function lmPreviewUrl(item: LmLoraItem): string | null {
53
53
  return readString(item, 'preview_url')
54
54
  }
55
+ /** the file's size in bytes, when the extension reports it */
56
+ /** the file's content hash: what the extension keys its example images by */
57
+ export function lmSha256(item: LmLoraItem): string | null {
58
+ return readString(item, 'sha256')
59
+ }
60
+
61
+ export function lmFileSize(item: LmLoraItem): number | null {
62
+ const raw = item['file_size']
63
+ return typeof raw === 'number' && Number.isFinite(raw) ? raw : null
64
+ }
65
+
66
+ /** the note YOU wrote in the lora manager, empty when there is none */
67
+ export function lmNotes(item: LmLoraItem): string {
68
+ return readString(item, 'notes') ?? ''
69
+ }
70
+
71
+ /** the civitai block: what links a local file back to the page it came from */
72
+ export function lmCivitai(item: LmLoraItem): { modelId: number | null; name: string | null } | null {
73
+ const civitai = item['civitai']
74
+ if (!isRecord(civitai)) return null
75
+ const modelId = civitai['modelId']
76
+ return {
77
+ modelId: typeof modelId === 'number' && Number.isFinite(modelId) ? modelId : null,
78
+ name: readString(civitai, 'name'),
79
+ }
80
+ }
81
+
55
82
  export function lmTags(item: LmLoraItem): string[] {
56
83
  return readStringArray(item, 'tags')
57
84
  }
@@ -113,6 +140,73 @@ export type LoraSweep =
113
140
  /** the host itself could not be reached (down, refused, auth) */
114
141
  | { status: 'unreachable'; reason: string }
115
142
 
143
+ /** civitai's model description for ONE lora, as PLAIN TEXT. The extension answers html, and
144
+ * html from a third party is never rendered: tags are stripped here, at the seam.
145
+ * null = the extension has no description for it (or does not expose the route) */
146
+ export async function fetchLoraDescription(host: ComfyHost, filePath: string): Promise<string | null> {
147
+ try {
148
+ const res = await host.fetch(`/lm/loras/model-description?file_path=${encodeURIComponent(filePath)}`, {})
149
+ // a 404 IS "no description", any other status is the extension failing at its job: the
150
+ // two collapsed to the same silent null, which is the wrong-cause report the sibling
151
+ // fetchLoraExampleImages carries a `reason` to avoid
152
+ if (!res.ok) {
153
+ if (res.status !== 404) logError(`[lora-manager] description ${res.status} for ${filePath}`)
154
+ return null
155
+ }
156
+ const raw: unknown = await res.json()
157
+ const description = isRecord(raw) ? raw['description'] : null
158
+ if (typeof description !== 'string' || description === '') return null
159
+ return htmlToText(description)
160
+ } catch (e) {
161
+ logError(`[lora-manager] description unreachable for ${filePath}: ${extractErrorMessage(e)}`)
162
+ return null
163
+ }
164
+ }
165
+
166
+ /** `<p>a</p><br>b` → `a\n\nb`. Deliberately dumb: this text is DISPLAYED, never parsed */
167
+ function htmlToText(html: string): string {
168
+ return html
169
+ .replaceAll(/<\s*br\s*\/?>/gi, '\n')
170
+ .replaceAll(/<\/\s*(p|div|li|h[1-6])\s*>/gi, '\n\n')
171
+ .replaceAll(/<\s*li[^>]*>/gi, '· ')
172
+ .replaceAll(/<[^>]+>/g, '')
173
+ .replaceAll('&nbsp;', ' ')
174
+ .replaceAll('&amp;', '&')
175
+ .replaceAll('&lt;', '<')
176
+ .replaceAll('&gt;', '>')
177
+ .replaceAll('&quot;', '"')
178
+ .replaceAll('&#39;', "'")
179
+ .replaceAll(/\n{3,}/g, '\n\n')
180
+ .trim()
181
+ }
182
+
183
+ /** the example images lora-manager keeps for a lora. `reason` explains an empty list rather
184
+ * than pretending the lora has none, "no example images path configured" is a SETTING */
185
+ export async function fetchLoraExampleImages(
186
+ host: ComfyHost,
187
+ sha256: string,
188
+ ): Promise<{ files: string[]; reason: string | null }> {
189
+ try {
190
+ const res = await host.fetch(`/lm/example-image-files?model_hash=${encodeURIComponent(sha256)}`, {})
191
+ const raw: unknown = await res.json()
192
+ if (!isRecord(raw)) return { files: [], reason: `unexpected reply (http ${res.status})` }
193
+ if (raw['success'] !== true) {
194
+ const err = raw['error']
195
+ return { files: [], reason: typeof err === 'string' ? err : `http ${res.status}` }
196
+ }
197
+ const files = raw['files']
198
+ if (!Array.isArray(files)) return { files: [], reason: null }
199
+ const out: string[] = []
200
+ for (const f of files) {
201
+ if (typeof f === 'string') out.push(f)
202
+ else if (isRecord(f) && typeof f['path'] === 'string') out.push(f['path'])
203
+ }
204
+ return { files: out, reason: null }
205
+ } catch (e) {
206
+ return { files: [], reason: e instanceof Error ? e.message : String(e) }
207
+ }
208
+ }
209
+
116
210
  /**
117
211
  * every lora lora-manager knows, RAW, in one paged sweep.
118
212
  * page_size asks for 500; the server caps it at 100, so the loop follows `total`.
package/src/index.ts CHANGED
@@ -13,4 +13,6 @@ export * from 'src/coreExports.ts'
13
13
 
14
14
  // node-only surface: fs-backed example assets + the TUI env contract
15
15
  export { exampleImagePath } from 'src/exampleAssets.ts'
16
+ // the prompt-enhancer library on disk, offered as var presets (fs, so never in the web entry)
17
+ export { promptEnhancerPresets, readPromptEnhancers, type PromptEnhancer } from 'src/promptEnhancers.ts'
16
18
  export { isTuiActive } from 'src/cli/tui-env.ts'