comfy-ts 2.7.0 → 2.8.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 (101) 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-BPw-SZYW.js} +106 -157
  17. package/dist/run-tui-BPw-SZYW.js.map +1 -0
  18. package/dist/serve-web.js +432 -72
  19. package/dist/{state-CaHeDL-0.js → state-B-boDz-Z.js} +180 -45
  20. package/dist/state-B-boDz-Z.js.map +1 -0
  21. package/dist/web.d.ts +109 -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/managerOnlyLoras.ts +27 -0
  39. package/src/cli/serve/run-serve.ts +35 -38
  40. package/src/cli/serve/serveSettings.ts +86 -0
  41. package/src/cli/serve/startupPrint.ts +111 -0
  42. package/src/cli/serve/web/api.ts +97 -1
  43. package/src/cli/serve/web/components/App.tsx +61 -22
  44. package/src/cli/serve/web/components/Gallery.tsx +243 -30
  45. package/src/cli/serve/web/components/Icon.tsx +160 -0
  46. package/src/cli/serve/web/components/PromptEnhancer.tsx +12 -9
  47. package/src/cli/serve/web/components/Sidebar.tsx +43 -19
  48. package/src/cli/serve/web/components/VarsForm.tsx +440 -91
  49. package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
  50. package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
  51. package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
  52. package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
  53. package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
  54. package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
  55. package/src/cli/serve/web/llm.ts +1 -1
  56. package/src/cli/serve/web/logWeb.ts +6 -0
  57. package/src/cli/serve/web/state/EnhancerSt.ts +8 -15
  58. package/src/cli/serve/web/state/FormSt.ts +66 -17
  59. package/src/cli/serve/web/state/RunSt.ts +22 -1
  60. package/src/cli/serve/web/state/WebSt.ts +518 -14
  61. package/src/cli/serve/web/state/lightbox.ts +44 -0
  62. package/src/cli/serve/web/state/moduleTree.ts +52 -0
  63. package/src/cli/serve/web/state/payload.ts +44 -2
  64. package/src/cli/serve/web/state/urlSelection.ts +53 -0
  65. package/src/cli/serve/web/styles.ts +413 -57
  66. package/src/cli/serve/web/tsconfig.json +4 -0
  67. package/src/cli/tui/components/PickerOverlays.tsx +37 -0
  68. package/src/cli/tui/components/StatusBar.tsx +14 -1
  69. package/src/cli/tui/components/TuiApp.tsx +5 -2
  70. package/src/cli/tui/state/HostSt.ts +3 -2
  71. package/src/cli/tui/state/PickerSt.ts +48 -2
  72. package/src/cli/tui/state/TreeSt.ts +1 -1
  73. package/src/cli/tui/state/TuiSt.ts +2 -1
  74. package/src/coreExports.ts +8 -1
  75. package/src/graph/ComfyNode.ts +58 -1
  76. package/src/host/ComfyHost.ts +13 -2
  77. package/src/host/ComfyManager.ts +31 -13
  78. package/src/host/loraInfoCache.ts +35 -1
  79. package/src/host/loraManagerApi.ts +94 -0
  80. package/src/index.ts +2 -0
  81. package/src/promptEnhancers.ts +102 -0
  82. package/src/runner/ComfyExecution.ts +61 -6
  83. package/src/runner/ComfyWorkflow.ts +18 -4
  84. package/src/runner/ComfyWsApi.ts +3 -0
  85. package/src/runner/describePromptRejection.ts +34 -0
  86. package/src/sdk-generator/ComfySchema.ts +17 -4
  87. package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
  88. package/src/utils/ansi.ts +13 -0
  89. package/src/utils/matchesRegex.ts +13 -0
  90. package/src/utils/safeName.ts +29 -0
  91. package/src/utils/stringMap.ts +9 -0
  92. package/src/vars/ComfyVars.ts +61 -10
  93. package/src/vars/presets.ts +17 -0
  94. package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
  95. package/dist/DraftsSt-dizp3VcC.js.map +0 -1
  96. package/dist/run-serve-D1Tsuru9.js +0 -1162
  97. package/dist/run-serve-D1Tsuru9.js.map +0 -1
  98. package/dist/run-tui-JxlEbb_f.js.map +0 -1
  99. package/dist/state-CaHeDL-0.js.map +0 -1
  100. package/src/cli/serve/promptEnhancers.ts +0 -69
  101. package/src/cli/serve/safeName.ts +0 -12
@@ -0,0 +1,60 @@
1
+ // the presets button of a text/prompt var (`v.text(…, { presets })`). Picking one REPLACES
2
+ // the field, so the row's own revert dot is what undoes it — nothing here is a mode.
3
+ import { observer } from 'mobx-react-lite'
4
+ import { useState } from 'react'
5
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
6
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
7
+ import { activePresetLabel } from 'src/vars/presets.ts'
8
+
9
+ /** one line of a preset's text, enough to tell two of them apart in the menu */
10
+ function firstLine(text: string): string {
11
+ const line = text.split('\n').find((l) => l.trim() !== '') ?? ''
12
+ return line.length <= 90 ? line : `${line.slice(0, 89)}…`
13
+ }
14
+
15
+ export const PresetPicker = observer(function PresetPicker(p: { v: VarSt }) {
16
+ const presets = p.v.desc.textPresets ?? []
17
+ const [open, setOpen] = useState(false)
18
+ if (presets.length === 0) return null
19
+ const value = typeof p.v.value === 'string' ? p.v.value : ''
20
+ const active = activePresetLabel(presets, value)
21
+ return (
22
+ <div className="preset-box" onKeyDown={(e) => (e.key === 'Escape' ? setOpen(false) : undefined)}>
23
+ <button
24
+ type="button"
25
+ className="preset-btn"
26
+ aria-expanded={open}
27
+ data-tip="named starting texts — picking one replaces the field"
28
+ onClick={() => setOpen(!open)}
29
+ >
30
+ <Icon name="tag" /> presets ▾
31
+ </button>
32
+ {open ? (
33
+ <>
34
+ {/* a backdrop closes the menu on any outside click: no document listener, and
35
+ nothing to leak when the form is swapped under it */}
36
+ <div className="preset-backdrop" onClick={() => setOpen(false)} />
37
+ <div className="preset-menu">
38
+ {presets.map((preset) => (
39
+ <button
40
+ key={preset.label}
41
+ type="button"
42
+ className={preset.label === active ? 'preset-item on' : 'preset-item'}
43
+ onClick={() => {
44
+ p.v.set(preset.text)
45
+ setOpen(false)
46
+ }}
47
+ >
48
+ <span className="preset-name">
49
+ {preset.label === active ? '• ' : '  '}
50
+ {preset.label}
51
+ </span>
52
+ <span className="preset-peek">{firstLine(preset.text)}</span>
53
+ </button>
54
+ ))}
55
+ </div>
56
+ </>
57
+ ) : null}
58
+ </div>
59
+ )
60
+ })
@@ -1,17 +1,27 @@
1
1
  // seed: mode buttons + value + 🎲. Drafts are live, so the mode configures the
2
2
  // SERVER's per-draft seed policy (generate posts no seed key; step 4 applies
3
- // the draft's {mode, value})
3
+ // the draft's {mode, value}). The buttons are the SYMBOLS the mode actually is,
4
+ // with the sentence in the tooltip: `fixed / +1 / -1 / random` spelled out was a
5
+ // row of prose wider than the input it belongs to
6
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
4
7
  import { observer } from 'mobx-react-lite'
5
8
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
6
9
  import { asSeedForm, randomSeed } from 'src/cli/serve/web/state/payload.ts'
7
10
 
8
- const MODES: { mode: string; label: string; hint: string }[] = [
9
- { mode: '=', label: 'fixed', hint: 'this exact seed, every run' },
10
- { mode: '+', label: '+1', hint: 'increments after each run' },
11
- { mode: '-', label: '-1', hint: 'decrements after each run' },
12
- { mode: '?', label: 'random', hint: 'a fresh random seed each run' },
11
+ const MODES: { mode: string; hint: string }[] = [
12
+ { mode: '=', hint: 'fixed: this exact seed, every run' },
13
+ { mode: '+', hint: 'increments after each run' },
14
+ { mode: '?', hint: 'a fresh random seed each run' },
13
15
  ]
14
16
 
17
+ /** `-` is a real mode a draft can hold (the TUI offers it), it is just not worth a permanent
18
+ * button here. It appears only while it IS the mode, so the row never misreports the draft,
19
+ * and it disappears once you pick another one */
20
+ function visibleModes(current: string): { mode: string; hint: string }[] {
21
+ if (MODES.some((m) => m.mode === current)) return MODES
22
+ return [...MODES, { mode: current, hint: current === '-' ? 'decrements after each run' : `mode '${current}'` }]
23
+ }
24
+
15
25
  export const SeedControl = observer(function SeedControl(p: { v: VarSt }) {
16
26
  const seed = asSeedForm(p.v.value)
17
27
  const setValue = (n: number): void => {
@@ -20,24 +30,32 @@ export const SeedControl = observer(function SeedControl(p: { v: VarSt }) {
20
30
  }
21
31
  return (
22
32
  <div>
33
+ {/* one control: the modes are a segmented group, and every element on the row is
34
+ input-height so buttons and the number line up instead of stepping over each other */}
23
35
  <div className="row-inline">
24
- {MODES.map((m) => (
25
- <button
26
- key={m.mode}
27
- type="button"
28
- className={seed.mode === m.mode ? 'mode sel' : 'mode'}
29
- title={m.hint}
30
- onClick={() => p.v.set({ mode: m.mode, value: seed.value })}
31
- >
32
- {m.label}
33
- </button>
34
- ))}
36
+ <span className="btn-group field-height">
37
+ {visibleModes(seed.mode).map((m) => (
38
+ <button
39
+ key={m.mode}
40
+ type="button"
41
+ className={seed.mode === m.mode ? 'sel' : ''}
42
+ data-tip={m.hint}
43
+ onClick={() => p.v.set({ mode: m.mode, value: seed.value })}
44
+ >
45
+ {m.mode}
46
+ </button>
47
+ ))}
48
+ </span>
35
49
  <input type="number" min={0} value={seed.value} onChange={(e) => setValue(parseInt(e.target.value, 10))} />
36
- <button type="button" title="roll a random seed now" onClick={() => setValue(randomSeed())}>
37
- 🎲
50
+ <button
51
+ type="button"
52
+ className="field-height"
53
+ data-tip="roll a random seed now"
54
+ onClick={() => setValue(randomSeed())}
55
+ >
56
+ <Icon name="dice" />
38
57
  </button>
39
58
  </div>
40
- <div className="hint">{MODES.find((m) => m.mode === seed.mode)?.hint ?? seed.mode}</div>
41
59
  </div>
42
60
  )
43
61
  })
@@ -1,4 +1,5 @@
1
1
  // size: preset select + free WxH inputs + ⇄ swap
2
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
2
3
  import { observer } from 'mobx-react-lite'
3
4
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
4
5
  import { asSizeForm } from 'src/cli/serve/web/state/payload.ts'
@@ -39,10 +40,10 @@ export const SizeControl = observer(function SizeControl(p: { v: VarSt }) {
39
40
  />
40
41
  <button
41
42
  type="button"
42
- title="swap width and height"
43
+ data-tip="swap width and height"
43
44
  onClick={() => p.v.set({ width: size.height, height: size.width })}
44
45
  >
45
- ⇄
46
+ <Icon name="swap" />
46
47
  </button>
47
48
  </div>
48
49
  )
@@ -2,7 +2,7 @@
2
2
  // (a local box). The second http module after api.ts, and the only one that leaves
3
3
  // this origin. Keys are parameters, never module state: they live in localStorage
4
4
  // (EnhancerSt) and never reach the serve process.
5
- // Parsing is pure and DOM-free so tests/serve-web-enhancer.test.ts covers it.
5
+ // parsing is pure and DOM-free so tests/serve-web-enhancer.test.ts covers it.
6
6
 
7
7
  export type ProviderId = 'openrouter' | 'openwebui'
8
8
 
@@ -0,0 +1,6 @@
1
+ // the panel's loud channel. src/utils/log.ts is node-shaped, and a browser failure that only
2
+ // updates a state field disappears the moment something re-renders: a console line survives,
3
+ // and it is the first thing anyone reads when the ui does something inexplicable.
4
+ export function logWebError(what: string, e: unknown): void {
5
+ console.error(`🔴 [comfy-ts serve] ${what}: ${e instanceof Error ? e.message : String(e)}`)
6
+ }
@@ -2,9 +2,10 @@
2
2
  // run (architecture item 12, web ui). Hangs off the WebSt root.
3
3
  // SPLIT OF TRUTH: the master prompts are FILES on the server
4
4
  // (`.comfy-ts/prompt-enhancers/*.md`, autosaved like a draft), everything else is
5
- // browser-local in a localStorage blob — keys included, so the serve process never
5
+ // browser-local in a localStorage blob, keys included, so the serve process never
6
6
  // holds a credential. normalizeSettings/nextPresetName are PURE and headless-tested.
7
7
  import { makeAutoObservable, reaction, runInAction, type IReactionDisposer } from 'mobx'
8
+ import { stringMap } from 'src/utils/stringMap.ts'
8
9
  import {
9
10
  deletePromptEnhancer,
10
11
  fetchPromptEnhancers,
@@ -53,29 +54,21 @@ function isEffort(raw: unknown): raw is ReasoningEffort {
53
54
  return raw === 'off' || raw === 'low' || raw === 'medium' || raw === 'high'
54
55
  }
55
56
 
56
- function strMap(raw: unknown): Record<string, string> {
57
- const out: Record<string, string> = {}
58
- if (typeof raw === 'object' && raw !== null) {
59
- for (const [k, v] of Object.entries(raw)) if (typeof v === 'string') out[k] = v
60
- }
61
- return out
62
- }
63
-
64
57
  /** stored blob → usable settings. A hand-edited or half-written localStorage entry must
65
58
  * degrade to defaults, never break the modal (same wire tolerance as every stored blob) */
66
59
  export function normalizeSettings(raw: unknown): EnhancerSettings {
67
60
  const o = typeof raw === 'object' && raw !== null ? (raw as Record<string, unknown>) : {}
68
- const models = strMap(o.modelByProvider)
69
- const bases = strMap(o.baseUrlByProvider)
61
+ const models = stringMap(o.modelByProvider)
62
+ const bases = stringMap(o.baseUrlByProvider)
70
63
  return {
71
64
  provider: isProvider(o.provider) ? o.provider : 'openrouter',
72
- keyByProvider: strMap(o.keyByProvider),
65
+ keyByProvider: stringMap(o.keyByProvider),
73
66
  baseUrlByProvider: { openrouter: defaultBaseUrl('openrouter'), openwebui: defaultBaseUrl('openwebui'), ...bases },
74
67
  modelByProvider: { ...DEFAULT_MODEL, ...models },
75
68
  effort: isEffort(o.effort) ? o.effort : 'medium',
76
69
  thinkingOnly: o.thinkingOnly !== false,
77
70
  presetName: typeof o.presetName === 'string' ? o.presetName : '',
78
- presetByModule: strMap(o.presetByModule),
71
+ presetByModule: stringMap(o.presetByModule),
79
72
  }
80
73
  }
81
74
 
@@ -148,7 +141,7 @@ export class EnhancerSt {
148
141
  lastSaved: false,
149
142
  })
150
143
  // the master prompt autosaves to its file, the live-drafts model (the values json is
151
- // change-detector AND payload — the house persistence idiom)
144
+ // change-detector AND payload, the house persistence idiom)
152
145
  this.disposer = reaction(
153
146
  () => {
154
147
  const p = this.preset
@@ -397,7 +390,7 @@ export class EnhancerSt {
397
390
  }
398
391
 
399
392
  /** what gets SENT is editable too: sharpen the sketch, then refine, without closing the
400
- * modal. It stays a copy — only apply() writes the var */
393
+ * modal. It stays a copy, only apply() writes the var */
401
394
  setOriginal(v: string): void {
402
395
  this.original = v
403
396
  }
@@ -18,10 +18,10 @@ export class VarSt {
18
18
  constructor(
19
19
  public readonly name: string,
20
20
  public readonly desc: VarDescriptor,
21
- public readonly initial: unknown,
21
+ public initial: unknown,
22
22
  ) {
23
23
  this.value = initial
24
- makeAutoObservable(this, { value: observableRef, name: false, desc: false, initial: false })
24
+ makeAutoObservable(this, { value: observableRef, name: false, desc: false })
25
25
  }
26
26
 
27
27
  set(value: unknown): void {
@@ -29,6 +29,14 @@ export class VarSt {
29
29
  this.dirty = true
30
30
  }
31
31
 
32
+ /** a value the RUN reported, not one you typed: it re-baselines, so the row is not marked
33
+ * changed and revert-all does not offer to undo something nobody did */
34
+ setFromRun(value: unknown): void {
35
+ this.value = value
36
+ this.initial = value
37
+ this.dirty = false
38
+ }
39
+
32
40
  setUploadedUrl(url: string | null): void {
33
41
  this.uploadedUrl = url
34
42
  }
@@ -53,8 +61,14 @@ export class FormSt {
53
61
  private disposers: IReactionDisposer[] = []
54
62
  /** saves are chained so two PUTs can never land out of order */
55
63
  private saveChain: Promise<boolean> = Promise.resolve(true)
56
- /** the values json the server last confirmed — save() no-ops when nothing changed */
64
+ /** the values json the server last CONFIRMED — what is really on disk */
57
65
  private lastSaved: string
66
+ /** the values json last HANDED to the chain, confirmed or still in flight. save() no-ops
67
+ * against this one, never against lastSaved: while a PUT is open the disk does not hold
68
+ * lastSaved any more, so editing back to it wrote nothing and the in-flight value won */
69
+ private lastQueued: string
70
+ /** identity of the newest queued write, so a rollback cannot claim someone else's */
71
+ private queueSeq = 0
58
72
 
59
73
  constructor(
60
74
  public readonly moduleKey: string,
@@ -68,9 +82,10 @@ export class FormSt {
68
82
  )
69
83
  // seeded from the RAW reply, not the normalized values: when normalizeInitial heals
70
84
  // something (a stale lora key), the form is already out of sync with the file and the
71
- // next save() must actually send — otherwise the server keeps building the stale record
85
+ // next save() must actually send, otherwise the server keeps building the stale record
72
86
  this.lastSaved = JSON.stringify(Object.fromEntries(this.vars.map((v) => [v.name, values[v.name]])))
73
- makeAutoObservable<FormSt, 'disposers' | 'saveChain' | 'lastSaved'>(this, {
87
+ this.lastQueued = this.lastSaved
88
+ makeAutoObservable<FormSt, 'disposers' | 'saveChain' | 'lastSaved' | 'lastQueued' | 'queueSeq'>(this, {
74
89
  vars: false,
75
90
  moduleKey: false,
76
91
  draft: false,
@@ -78,6 +93,8 @@ export class FormSt {
78
93
  disposers: false,
79
94
  saveChain: false,
80
95
  lastSaved: false,
96
+ lastQueued: false,
97
+ queueSeq: false,
81
98
  })
82
99
  // the persistence idiom: the values json is change-detector AND payload
83
100
  this.disposers.push(
@@ -95,8 +112,10 @@ export class FormSt {
95
112
  for (const d of this.disposers) d()
96
113
  this.disposers = []
97
114
  if (p.flush === false) return
98
- // a draft switch inside the debounce window must not lose the edit
99
- if (JSON.stringify(this.valuesJSON()) !== this.lastSaved) void this.save()
115
+ // a draft switch inside the debounce window must not lose the edit. Compared against
116
+ // lastQueued, like save() itself: lastSaved lags behind an in-flight write, so a revert
117
+ // made while one is open looked identical to "already written" and was dropped
118
+ if (JSON.stringify(this.valuesJSON()) !== this.lastQueued) void this.save()
100
119
  }
101
120
 
102
121
  /** tab-close/hide flush. keepalive survives page teardown, so this one does NOT ride
@@ -104,7 +123,10 @@ export class FormSt {
104
123
  * server answers: a failed flush must stay dirty so the next save() retries it */
105
124
  flushKeepalive(): void {
106
125
  const encoded = JSON.stringify(this.valuesJSON())
107
- if (encoded === this.lastSaved) return
126
+ // lastQueued, not lastSaved: nothing runs after this one, so a revert made while a PUT
127
+ // was open would be lost for good rather than merely delayed
128
+ if (encoded === this.lastQueued) return
129
+ this.lastQueued = encoded
108
130
  void saveDraft(
109
131
  { module: this.moduleKey, draft: this.draft, values: JSON.parse(encoded) as Record<string, unknown> },
110
132
  { keepalive: true },
@@ -112,10 +134,12 @@ export class FormSt {
112
134
  () =>
113
135
  runInAction(() => {
114
136
  this.lastSaved = encoded
137
+ this.lastQueued = encoded
115
138
  this.saveState = 'saved'
116
139
  }),
117
140
  (e: unknown) =>
118
141
  runInAction(() => {
142
+ if (this.lastQueued === encoded) this.lastQueued = this.lastSaved
119
143
  this.saveState = 'error'
120
144
  this.saveError = e instanceof Error ? e.message : String(e)
121
145
  }),
@@ -131,6 +155,32 @@ export class FormSt {
131
155
  return payloadSnapshot(this.vars.map((v) => ({ name: v.name, kind: v.desc.kind, value: v.value })))
132
156
  }
133
157
 
158
+ /** the keywords the ACTIVE loras will prepend to this prompt, in the ORDER THE RUN USES.
159
+ * that order is the var's option list (LorasVar.activeNames filters `names`), NOT the
160
+ * record's insertion order: walking the record showed the keywords in drag order while the
161
+ * prompt that ran used the enum order, so the preview and the run disagreed the moment you
162
+ * reordered a card. Computed here rather than fetched: it must follow every toggle live */
163
+ loraKeywordsFor(promptVar: VarSt): string[] {
164
+ const sourceName = promptVar.desc.keywordsFrom
165
+ if (sourceName == null) return []
166
+ const source = this.vars.find((v) => v.name === sourceName)
167
+ if (source == null) return []
168
+ const keywords = source.desc.optionKeywords ?? {}
169
+ const record = (source.value != null && typeof source.value === 'object' ? source.value : {}) as Record<
170
+ string,
171
+ unknown
172
+ >
173
+ const out: string[] = []
174
+ for (const name of source.desc.options ?? []) {
175
+ const st = record[name]
176
+ // same rule as the graph: only loras that are ON contribute
177
+ if (st == null || st === false) continue
178
+ const kw = keywords[name]
179
+ if (kw != null && kw !== '' && !out.includes(kw)) out.push(kw)
180
+ }
181
+ return out
182
+ }
183
+
134
184
  get dirtyCount(): number {
135
185
  return this.vars.filter((v) => v.dirty).length
136
186
  }
@@ -138,15 +188,10 @@ export class FormSt {
138
188
  /** persist the draft now. Resolves FALSE on failure — generate() must not run stale inputs */
139
189
  save(): Promise<boolean> {
140
190
  const encoded = JSON.stringify(this.valuesJSON())
141
- if (encoded === this.lastSaved) {
142
- // nothing to write: the disk already holds these values, whatever an OLDER save did.
143
- // returning the previous chain here would keep a stale false alive and dead-lock generate
144
- runInAction(() => {
145
- this.saveState = 'saved'
146
- this.saveError = null
147
- })
148
- return Promise.resolve(true)
149
- }
191
+ // already on its way (or landed): ride the chain, so generate() waits for that write
192
+ if (encoded === this.lastQueued) return this.lastSaved === encoded ? Promise.resolve(true) : this.saveChain
193
+ this.lastQueued = encoded
194
+ const seq = ++this.queueSeq
150
195
  runInAction(() => {
151
196
  this.saveState = 'saving'
152
197
  })
@@ -165,6 +210,10 @@ export class FormSt {
165
210
  return true
166
211
  } catch (e) {
167
212
  runInAction(() => {
213
+ // by seq, not by value: a newer save carrying the same json must keep its marker
214
+ if (this.queueSeq === seq) this.lastQueued = this.lastSaved
215
+ // a failed chain must not be handed to the next no-op caller as a stale false
216
+ this.saveChain = Promise.resolve(true)
168
217
  this.saveState = 'error'
169
218
  this.saveError = e instanceof Error ? e.message : String(e)
170
219
  })
@@ -1,6 +1,6 @@
1
1
  // the run QUEUE + results. Clicking generate repeatedly enqueues; the drainer
2
2
  // sends ONE prompt at a time so anything still pending can be dropped before it
3
- // ever reaches the host (his ask: queued prompts must be clearable, singly or
3
+ // ever reaches the host: queued prompts must be clearable, singly or
4
4
  // all). Progress + latent preview are polled ~700ms while a prompt is in flight
5
5
  import { makeAutoObservable, observableShallow, runInAction } from 'mobx'
6
6
  import { fetchRunStatus, postGenerate, type GenerateOk } from 'src/cli/serve/web/api.ts'
@@ -25,6 +25,12 @@ export class RunSt {
25
25
  error: string | null = null
26
26
  results: RunResult[] = []
27
27
  progressPercent: number | null = null
28
+ /** what the host is doing right now, in the node's own unit — `TextGenerate 427/1024`.
29
+ * A text graph has no latent preview and no image, so this is all there is to watch */
30
+ progressNode: string | null = null
31
+ progressCount: { value: number; max: number } | null = null
32
+ /** what a streaming node has produced SO FAR — replacement semantics, newest wins */
33
+ progressText: string | null = null
28
34
  hasPreview = false
29
35
  /** the server's frame seq — the <img> cache-buster, changes only on a NEW frame */
30
36
  previewTick = 0
@@ -33,6 +39,10 @@ export class RunSt {
33
39
  /** staleness guard for the poll loop (mobx-mechanics: counters, not flags) */
34
40
  private pollGen = 0
35
41
 
42
+ /** what a finished run's seeds should do to the form. Set by WebSt: RunSt owns the queue,
43
+ * not the draft */
44
+ onSeeds: ((p: { module: string; draft: string; seeds: Record<string, number> }) => void) | null = null
45
+
36
46
  constructor() {
37
47
  makeAutoObservable(this, { queue: observableShallow, results: observableShallow })
38
48
  }
@@ -85,6 +95,9 @@ export class RunSt {
85
95
  // replace-by-copy keeps the one array idiom of this store
86
96
  this.queue = this.queue.map((e) => (e.id === next.id ? { ...e, sent: true } : e))
87
97
  this.progressPercent = null
98
+ this.progressNode = null
99
+ this.progressCount = null
100
+ this.progressText = null
88
101
  this.hasPreview = false
89
102
  })
90
103
  const gen = ++this.pollGen
@@ -95,6 +108,8 @@ export class RunSt {
95
108
  // capped: full-size <img>s per run would eat the tab
96
109
  this.results = [{ ...result, at: new Date().toLocaleTimeString() }, ...this.results].slice(0, 20)
97
110
  })
111
+ // named, because the panel may be on another draft by the time this resolves
112
+ this.onSeeds?.({ module: next.module, draft: next.draft, seeds: result.seeds })
98
113
  } catch (e) {
99
114
  runInAction(() => {
100
115
  this.error = e instanceof Error ? e.message : String(e)
@@ -107,6 +122,9 @@ export class RunSt {
107
122
  runInAction(() => {
108
123
  this.queue = this.queue.filter((e) => e.id !== next.id)
109
124
  this.progressPercent = null
125
+ this.progressNode = null
126
+ this.progressCount = null
127
+ this.progressText = null
110
128
  this.hasPreview = false
111
129
  })
112
130
  }
@@ -125,6 +143,9 @@ export class RunSt {
125
143
  runInAction(() => {
126
144
  if (gen !== this.pollGen) return
127
145
  this.progressPercent = status.percent
146
+ this.progressNode = status.node ?? null
147
+ this.progressCount = status.nodeProgress ?? null
148
+ this.progressText = status.progressText ?? null
128
149
  this.hasPreview = status.hasPreview
129
150
  this.previewTick = status.previewSeq ?? 0
130
151
  })