comfy-ts 0.3.0 → 1.0.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.
- package/README.md +349 -255
- package/dist/DefinedWorkflow-O3ynII3Y.js +598 -0
- package/dist/DefinedWorkflow-O3ynII3Y.js.map +1 -0
- package/dist/cli.js +3969 -128
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1208 -170
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +449 -115
- package/dist/index.d.ts +449 -115
- package/dist/index.js +1200 -171
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-Io8Xea0L.js → run-tui-BFhba_oG.js} +744 -665
- package/dist/run-tui-BFhba_oG.js.map +1 -0
- package/examples/01-txt2img.cflow.ts +50 -0
- package/examples/02-img2img-upload.cflow.ts +66 -0
- package/examples/03-export-workflow-json.cflow.ts +56 -0
- package/examples/04-krea2-turbo-t2i.cflow.ts +125 -0
- package/examples/05-comfy-cloud.cflow.ts +67 -0
- package/examples/comfy-cloud/sdk.d.ts +122674 -0
- package/guide-for-agents.md +166 -0
- package/package.json +7 -3
- package/src/cli/comfy-ts-cli.ts +19 -2
- package/src/cli/gen.ts +21 -12
- package/src/cli/tui/components/Header.tsx +5 -0
- package/src/cli/tui/components/LogsPanel.tsx +23 -0
- package/src/cli/tui/components/PreviewPanel.tsx +52 -7
- package/src/cli/tui/components/StatusBar.tsx +10 -4
- package/src/cli/tui/components/TreePanel.tsx +15 -2
- package/src/cli/tui/components/TuiApp.tsx +26 -3
- package/src/cli/tui/discoverWorkflows.ts +79 -0
- package/src/cli/tui/protocolImagePainter.ts +54 -18
- package/src/cli/tui/run-tui.tsx +55 -24
- package/src/cli/tui/state/ExecSt.ts +4 -1
- package/src/cli/tui/state/HostSt.ts +123 -1
- package/src/cli/tui/state/LogsSt.ts +107 -0
- package/src/cli/tui/state/PreviewSt.ts +173 -23
- package/src/cli/tui/state/SettingsSt.ts +48 -21
- package/src/cli/tui/state/TreeSt.ts +30 -6
- package/src/cli/tui/state/TuiSt.ts +27 -3
- package/src/cli/tui/state/WorkflowsSt.ts +16 -1
- package/src/host/ComfyHost.ts +241 -71
- package/src/host/ComfyManager.ts +10 -9
- package/src/host/ComfyUploader.ts +1 -2
- package/src/host/ResilientWebsocket.ts +3 -1
- package/src/host/hostUrl.ts +59 -0
- package/src/host/loraManagerApi.ts +5 -4
- package/src/index.ts +20 -1
- package/src/litegraph/CanonicalWorkflow.ts +77 -0
- package/src/litegraph/LiteGraphGroup.ts +9 -7
- package/src/litegraph/LiteGraphJSON.ts +34 -13
- package/src/litegraph/LiteGraphLink.ts +32 -2
- package/src/litegraph/LiteGraphNode.ts +18 -33
- package/src/litegraph/LiteGraphNodeInput.ts +10 -8
- package/src/litegraph/LiteGraphNodeOutput.ts +2 -3
- package/src/litegraph/LiteGraphSubgraphDef.ts +74 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +4 -4
- package/src/litegraph/expandSubgraphs.ts +352 -0
- package/src/litegraph/normalizeWorkflow.ts +141 -0
- package/src/runner/ComfyExecution.ts +4 -5
- package/src/runner/ComfyWorkflow.ts +2 -2
- package/src/runner/ComfyWsApi.ts +12 -1
- package/src/runner/wsBinaryFrame.ts +48 -0
- package/src/sdk-generator/Primitives.ts +6 -24
- package/src/sdk-generator/comfy-api-json.ts +3 -1
- package/src/sdk-generator/inputWidgetKind.ts +179 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
- package/src/ssh-host-manager/ssh-manager.ts +0 -15
- package/src/state.ts +13 -2
- package/src/utils/ansi.ts +7 -0
- package/src/utils/mojibake.ts +60 -0
- package/dist/log-CdfgILde.js +0 -10
- package/dist/log-CdfgILde.js.map +0 -1
- package/dist/run-tui-Io8Xea0L.js.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { makeAutoObservable, runInAction } from 'mobx'
|
|
2
2
|
import sharp from 'sharp'
|
|
3
|
+
import { imageMeta } from 'image-meta'
|
|
3
4
|
import { imageBufferToAnsi } from 'src/utils/ansiImage.ts'
|
|
4
5
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
5
|
-
import type {
|
|
6
|
+
import type { PreviewDuringRun, PreviewRenderer } from 'src/cli/tui/state/SettingsSt.ts'
|
|
6
7
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
7
8
|
|
|
8
9
|
/** OSC 1337 support: the panel can show REAL images instead of half-blocks */
|
|
@@ -12,12 +13,19 @@ export function protocolCapable(): boolean {
|
|
|
12
13
|
return term === 'iTerm.app' || term === 'WezTerm' || term === 'vscode' || process.env.LC_TERMINAL === 'iTerm2'
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
type MenuRow = { key: 'panel' | 'renderer' | 'during-run'; label: string; value: string }
|
|
17
|
+
|
|
18
|
+
/** small-latent corner: fraction of the panel each dimension takes */
|
|
19
|
+
const CORNER_FRACTION = 0.38
|
|
20
|
+
/** pixel 'latent small': the sharp-composited thumb takes this fraction of the panel */
|
|
21
|
+
const PIXEL_SMALL_FRACTION = 0.4
|
|
22
|
+
|
|
15
23
|
/**
|
|
16
|
-
* right-side preview panel
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* lora while the loras overlay is open.
|
|
24
|
+
* right-side preview panel + its `p` settings menu (mode 'preview').
|
|
25
|
+
* Three independent axes live in SettingsSt: panel on/off, renderer
|
|
26
|
+
* native/pixel, and what to show while running (latent / latent small /
|
|
27
|
+
* last output). Sources: live latent while running, last output after,
|
|
28
|
+
* selected lora while the loras overlay is open.
|
|
21
29
|
*/
|
|
22
30
|
export class PreviewSt {
|
|
23
31
|
constructor(private st: TuiSt) {
|
|
@@ -31,18 +39,94 @@ export class PreviewSt {
|
|
|
31
39
|
/** native mode: pre-shrunk output bytes / raw latent jpeg for the painter */
|
|
32
40
|
outputBytes: Uint8Array | null = null
|
|
33
41
|
latentBytes: Uint8Array | null = null
|
|
34
|
-
/**
|
|
42
|
+
/** the latent's pixel dimensions (image-meta) — sizes the native corner box */
|
|
43
|
+
latentDims: { width: number; height: number } | null = null
|
|
44
|
+
/** at least one latent frame arrived this run — false + progress = server sends none */
|
|
45
|
+
latentSeenThisRun: boolean = false
|
|
46
|
+
/** last output path, so a settings change can re-render it */
|
|
35
47
|
private lastOutputPath: string | null = null
|
|
36
48
|
|
|
37
|
-
get mode(): PreviewMode {
|
|
38
|
-
return this.st.settings.previewMode
|
|
39
|
-
}
|
|
40
49
|
get show(): boolean {
|
|
41
|
-
return this.
|
|
50
|
+
return this.st.settings.previewPanel
|
|
51
|
+
}
|
|
52
|
+
get renderer(): PreviewRenderer {
|
|
53
|
+
return this.st.settings.previewRenderer
|
|
42
54
|
}
|
|
43
|
-
/** SettingsSt already downgrades native → ansi on incapable terminals */
|
|
44
55
|
get useNative(): boolean {
|
|
45
|
-
return this.
|
|
56
|
+
return this.renderer === 'native'
|
|
57
|
+
}
|
|
58
|
+
get duringRun(): PreviewDuringRun {
|
|
59
|
+
return this.st.settings.previewDuringRun
|
|
60
|
+
}
|
|
61
|
+
get menuOpen(): boolean {
|
|
62
|
+
return this.st.mode === 'preview'
|
|
63
|
+
}
|
|
64
|
+
/** running + latents wanted + sampling well underway + none arrived = server
|
|
65
|
+
* sends none. The ≥20% gate keeps healthy runs from red-flashing: the first
|
|
66
|
+
* progress tick lands a beat before the first preview frame */
|
|
67
|
+
get latentsMissing(): boolean {
|
|
68
|
+
return (
|
|
69
|
+
this.st.exec.running &&
|
|
70
|
+
this.duringRun !== 'last-output' &&
|
|
71
|
+
(this.st.exec.progress?.percent ?? 0) >= 20 &&
|
|
72
|
+
!this.latentSeenThisRun
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---- `p` settings menu (rendered by PreviewPanel while mode === 'preview') ----
|
|
77
|
+
menuIx: number = 0
|
|
78
|
+
|
|
79
|
+
get menuRows(): MenuRow[] {
|
|
80
|
+
return [
|
|
81
|
+
{ key: 'panel', label: 'panel', value: this.show ? 'on' : 'off' },
|
|
82
|
+
{
|
|
83
|
+
key: 'renderer',
|
|
84
|
+
label: 'renderer',
|
|
85
|
+
value: this.renderer + (protocolCapable() ? '' : ' (no protocol support)'),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: 'during-run',
|
|
89
|
+
label: 'while running',
|
|
90
|
+
value:
|
|
91
|
+
this.duringRun === 'latent'
|
|
92
|
+
? 'latent'
|
|
93
|
+
: this.duringRun === 'latent-small'
|
|
94
|
+
? 'latent small'
|
|
95
|
+
: 'last output',
|
|
96
|
+
},
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
beginMenu(): void {
|
|
101
|
+
this.st.mode = 'preview'
|
|
102
|
+
this.menuIx = 0
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
blurMenu(): void {
|
|
106
|
+
this.st.mode = 'nav'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
menuMove(delta: number): void {
|
|
110
|
+
const len = this.menuRows.length
|
|
111
|
+
this.menuIx = (this.menuIx + delta + len) % len
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** cycle the selected row's value (settings persist via SettingsSt reaction) */
|
|
115
|
+
menuCycle(delta: number): void {
|
|
116
|
+
const row = this.menuRows[this.menuIx]
|
|
117
|
+
if (row == null) return
|
|
118
|
+
const s = this.st.settings
|
|
119
|
+
if (row.key === 'panel') {
|
|
120
|
+
s.previewPanel = !s.previewPanel
|
|
121
|
+
} else if (row.key === 'renderer') {
|
|
122
|
+
// no protocol support → native is unreachable, pixel is the only value
|
|
123
|
+
if (protocolCapable()) s.previewRenderer = s.previewRenderer === 'native' ? 'pixel' : 'native'
|
|
124
|
+
} else {
|
|
125
|
+
const order: PreviewDuringRun[] = ['latent', 'latent-small', 'last-output']
|
|
126
|
+
const ix = (order.indexOf(s.previewDuringRun) + delta + order.length) % order.length
|
|
127
|
+
s.previewDuringRun = order[ix] ?? 'latent'
|
|
128
|
+
}
|
|
129
|
+
this.onSettingsChanged()
|
|
46
130
|
}
|
|
47
131
|
|
|
48
132
|
reset(): void {
|
|
@@ -50,6 +134,8 @@ export class PreviewSt {
|
|
|
50
134
|
this.latentAnsi = null
|
|
51
135
|
this.outputBytes = null
|
|
52
136
|
this.latentBytes = null
|
|
137
|
+
this.latentDims = null
|
|
138
|
+
this.latentSeenThisRun = false
|
|
53
139
|
this.lastOutputPath = null
|
|
54
140
|
}
|
|
55
141
|
|
|
@@ -57,23 +143,54 @@ export class PreviewSt {
|
|
|
57
143
|
clearLatent(): void {
|
|
58
144
|
this.latentAnsi = null
|
|
59
145
|
this.latentBytes = null
|
|
146
|
+
this.latentDims = null
|
|
147
|
+
this.latentSeenThisRun = false
|
|
60
148
|
}
|
|
61
149
|
|
|
62
|
-
/** re-render the last output
|
|
63
|
-
|
|
150
|
+
/** re-render the last output for the newly chosen settings */
|
|
151
|
+
onSettingsChanged(): void {
|
|
64
152
|
this.outputAnsi = null
|
|
65
153
|
this.outputBytes = null
|
|
66
|
-
if (this.
|
|
154
|
+
if (this.show && this.lastOutputPath != null) void this.renderOutput(this.lastOutputPath)
|
|
67
155
|
}
|
|
68
156
|
|
|
69
|
-
/** what the painter should show RIGHT NOW (native
|
|
157
|
+
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
70
158
|
get protocolImage(): Uint8Array | null {
|
|
71
|
-
if (!this.useNative || !this.show) return null
|
|
159
|
+
if (!this.useNative || !this.show || this.menuOpen) return null
|
|
72
160
|
if (this.st.mode === 'overlay-loras') return this.st.loras.previewBytes
|
|
73
|
-
if (this.st.exec.running
|
|
161
|
+
if (this.st.exec.running) {
|
|
162
|
+
if (this.duringRun === 'latent') return this.latentBytes ?? this.outputBytes
|
|
163
|
+
// latent-small keeps the OUTPUT big (corner carries the latent) — last-output too
|
|
164
|
+
return this.outputBytes
|
|
165
|
+
}
|
|
74
166
|
return this.outputBytes
|
|
75
167
|
}
|
|
76
168
|
|
|
169
|
+
/** small latent painted over the panel's top-right corner (native + 'latent small' only) */
|
|
170
|
+
get protocolImageCorner(): Uint8Array | null {
|
|
171
|
+
if (!this.useNative || !this.show || this.menuOpen) return null
|
|
172
|
+
if (this.st.mode === 'overlay-loras') return null
|
|
173
|
+
if (this.st.exec.running && this.duringRun === 'latent-small') return this.latentBytes
|
|
174
|
+
return null
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** corner cell box matched to the latent's REAL aspect (a mismatched box
|
|
178
|
+
* letterboxes in iTerm — his repro: "some vertical rectangle"). Cells are
|
|
179
|
+
* ~1:2 (w:h), hence the ×2 when converting image aspect to cells. */
|
|
180
|
+
get cornerBox(): { w: number; h: number } {
|
|
181
|
+
let w = Math.max(8, Math.floor(this.width * CORNER_FRACTION))
|
|
182
|
+
const maxH = Math.max(4, Math.floor(this.height * CORNER_FRACTION))
|
|
183
|
+
const dims = this.latentDims
|
|
184
|
+
if (dims == null || dims.width === 0 || dims.height === 0) return { w, h: maxH }
|
|
185
|
+
const aspect = dims.width / dims.height
|
|
186
|
+
let h = Math.max(2, Math.round(w / aspect / 2))
|
|
187
|
+
if (h > maxH) {
|
|
188
|
+
h = maxH
|
|
189
|
+
w = Math.max(4, Math.round(h * aspect * 2))
|
|
190
|
+
}
|
|
191
|
+
return { w, h }
|
|
192
|
+
}
|
|
193
|
+
|
|
77
194
|
get width(): number {
|
|
78
195
|
// leave ~64 cols to the vars panel (plus the tree), keep the image between 24 and 80 cells
|
|
79
196
|
return Math.max(24, Math.min(80, this.st.termCols - 68 - this.st.treeWidth))
|
|
@@ -86,7 +203,7 @@ export class PreviewSt {
|
|
|
86
203
|
|
|
87
204
|
async renderOutput(path: string): Promise<void> {
|
|
88
205
|
this.lastOutputPath = path
|
|
89
|
-
if (this.
|
|
206
|
+
if (!this.show) return
|
|
90
207
|
try {
|
|
91
208
|
if (this.useNative) {
|
|
92
209
|
// pre-shrink ONCE: the painter re-uploads on every repaint, so ~100KB beats ~2MB
|
|
@@ -114,16 +231,25 @@ export class PreviewSt {
|
|
|
114
231
|
/** skip-while-busy: latent frames arrive faster than sharp renders them */
|
|
115
232
|
private _busy: boolean = false
|
|
116
233
|
async renderLatent(bytes: Uint8Array): Promise<void> {
|
|
117
|
-
|
|
234
|
+
runInAction(() => {
|
|
235
|
+
this.latentSeenThisRun = true
|
|
236
|
+
})
|
|
237
|
+
if (!this.show || this.duringRun === 'last-output') return
|
|
118
238
|
if (this.useNative) {
|
|
119
|
-
// server jpegs pass through untouched — the terminal scales them
|
|
239
|
+
// server jpegs pass through untouched — the terminal scales them;
|
|
240
|
+
// dims feed cornerBox so the corner rect matches the image aspect
|
|
241
|
+
const meta = imageMeta(bytes)
|
|
120
242
|
this.latentBytes = bytes
|
|
243
|
+
this.latentDims = meta.width != null && meta.height != null ? { width: meta.width, height: meta.height } : null
|
|
121
244
|
return
|
|
122
245
|
}
|
|
123
246
|
if (this._busy) return
|
|
124
247
|
this._busy = true
|
|
125
248
|
try {
|
|
126
|
-
const ansi =
|
|
249
|
+
const ansi =
|
|
250
|
+
this.duringRun === 'latent-small'
|
|
251
|
+
? await this.renderLatentSmallPixel(bytes)
|
|
252
|
+
: await imageBufferToAnsi(bytes, { width: this.width, height: this.height })
|
|
127
253
|
runInAction(() => {
|
|
128
254
|
this.latentAnsi = ansi
|
|
129
255
|
})
|
|
@@ -135,4 +261,28 @@ export class PreviewSt {
|
|
|
135
261
|
this._busy = false
|
|
136
262
|
}
|
|
137
263
|
}
|
|
264
|
+
|
|
265
|
+
/** pixel 'latent small': sharp-composite the latent thumb onto the last
|
|
266
|
+
* output (top-right), then ONE half-block render — a string-level overlay
|
|
267
|
+
* was tried and dropped: its space padding reads as black bars */
|
|
268
|
+
private async renderLatentSmallPixel(bytes: Uint8Array): Promise<string> {
|
|
269
|
+
const pxW = this.width
|
|
270
|
+
const pxH = this.height * 2
|
|
271
|
+
const thumb = await sharp(bytes)
|
|
272
|
+
.resize(
|
|
273
|
+
Math.max(8, Math.floor(pxW * PIXEL_SMALL_FRACTION)),
|
|
274
|
+
Math.max(8, Math.floor(pxH * PIXEL_SMALL_FRACTION)),
|
|
275
|
+
{ fit: 'inside' },
|
|
276
|
+
)
|
|
277
|
+
.png()
|
|
278
|
+
.toBuffer()
|
|
279
|
+
const outPath = this.lastOutputPath
|
|
280
|
+
if (outPath == null) return imageBufferToAnsi(thumb, { width: this.width, height: this.height })
|
|
281
|
+
const base = await sharp(outPath).resize(pxW, pxH, { fit: 'inside' }).png().toBuffer()
|
|
282
|
+
const composed = await sharp(base)
|
|
283
|
+
.composite([{ input: thumb, gravity: 'northeast' }])
|
|
284
|
+
.png()
|
|
285
|
+
.toBuffer()
|
|
286
|
+
return imageBufferToAnsi(composed, { width: this.width, height: this.height })
|
|
287
|
+
}
|
|
138
288
|
}
|
|
@@ -4,41 +4,62 @@ import { dirname } from 'pathe'
|
|
|
4
4
|
import { protocolCapable } from 'src/cli/tui/state/PreviewSt.ts'
|
|
5
5
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
6
6
|
|
|
7
|
-
export type
|
|
7
|
+
export type PreviewRenderer = 'native' | 'pixel'
|
|
8
|
+
export type PreviewDuringRun = 'latent' | 'latent-small' | 'last-output'
|
|
9
|
+
|
|
10
|
+
export type PreviewSettings = {
|
|
11
|
+
previewPanel: boolean
|
|
12
|
+
previewRenderer: PreviewRenderer
|
|
13
|
+
previewDuringRun: PreviewDuringRun
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** read stored preview settings, migrating the legacy single `previewMode`
|
|
17
|
+
* (native|ansi|off) into the three independent axes */
|
|
18
|
+
export function migratePreviewSettings(raw: Record<string, unknown>, defaults: PreviewSettings): PreviewSettings {
|
|
19
|
+
const out = { ...defaults }
|
|
20
|
+
const legacy = raw.previewMode
|
|
21
|
+
if (legacy === 'native') out.previewRenderer = 'native'
|
|
22
|
+
if (legacy === 'ansi') out.previewRenderer = 'pixel'
|
|
23
|
+
if (legacy === 'off') out.previewPanel = false
|
|
24
|
+
if (typeof raw.previewPanel === 'boolean') out.previewPanel = raw.previewPanel
|
|
25
|
+
if (raw.previewRenderer === 'native' || raw.previewRenderer === 'pixel') out.previewRenderer = raw.previewRenderer
|
|
26
|
+
if (
|
|
27
|
+
raw.previewDuringRun === 'latent' ||
|
|
28
|
+
raw.previewDuringRun === 'latent-small' ||
|
|
29
|
+
raw.previewDuringRun === 'last-output'
|
|
30
|
+
)
|
|
31
|
+
out.previewDuringRun = raw.previewDuringRun
|
|
32
|
+
return out
|
|
33
|
+
}
|
|
8
34
|
|
|
9
35
|
/** persisted TUI settings at `.comfy-ts/settings.json` (LOCAL state, gitignored) */
|
|
10
36
|
export class SettingsSt {
|
|
11
37
|
constructor(private st: TuiSt) {
|
|
12
38
|
this.load()
|
|
13
|
-
// a non-protocol terminal can't do native — fall the stored setting back to
|
|
14
|
-
if (this.
|
|
39
|
+
// a non-protocol terminal can't do native — fall the stored setting back to pixel
|
|
40
|
+
if (this.previewRenderer === 'native' && !protocolCapable()) this.previewRenderer = 'pixel'
|
|
15
41
|
makeAutoObservable<SettingsSt, 'st'>(this, { st: false })
|
|
16
42
|
this.st.disposers.push(
|
|
17
43
|
reaction(
|
|
18
|
-
() =>
|
|
44
|
+
() =>
|
|
45
|
+
JSON.stringify({
|
|
46
|
+
previewPanel: this.previewPanel,
|
|
47
|
+
previewRenderer: this.previewRenderer,
|
|
48
|
+
previewDuringRun: this.previewDuringRun,
|
|
49
|
+
lastDraft: this.lastDraft,
|
|
50
|
+
}),
|
|
19
51
|
(json) => this.write(json),
|
|
20
52
|
{ delay: 300 },
|
|
21
53
|
),
|
|
22
54
|
)
|
|
23
55
|
}
|
|
24
56
|
|
|
25
|
-
|
|
57
|
+
previewPanel: boolean = true
|
|
58
|
+
previewRenderer: PreviewRenderer = protocolCapable() ? 'native' : 'pixel'
|
|
59
|
+
previewDuringRun: PreviewDuringRun = 'latent'
|
|
26
60
|
/** module basename → the draft that was active last time (reopened on load) */
|
|
27
61
|
lastDraft: Record<string, string> = {}
|
|
28
62
|
|
|
29
|
-
setPreviewMode(mode: PreviewMode): void {
|
|
30
|
-
this.previewMode = mode
|
|
31
|
-
this.st.preview.onModeChanged()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** `p` cycles native → ansi → off (native skipped when the terminal can't do it) */
|
|
35
|
-
cyclePreviewMode(): void {
|
|
36
|
-
const order: PreviewMode[] = protocolCapable() ? ['native', 'ansi', 'off'] : ['ansi', 'off']
|
|
37
|
-
const next = order[(order.indexOf(this.previewMode) + 1) % order.length] ?? 'off'
|
|
38
|
-
this.setPreviewMode(next)
|
|
39
|
-
this.st.exec.notice = `preview: ${next}`
|
|
40
|
-
}
|
|
41
|
-
|
|
42
63
|
rememberDraft(moduleKey: string, draft: string): void {
|
|
43
64
|
this.lastDraft[moduleKey] = draft
|
|
44
65
|
}
|
|
@@ -49,9 +70,15 @@ export class SettingsSt {
|
|
|
49
70
|
try {
|
|
50
71
|
const raw: unknown = JSON.parse(readFileSync(path, 'utf8'))
|
|
51
72
|
if (raw == null || typeof raw !== 'object') return
|
|
52
|
-
const o = raw as
|
|
53
|
-
|
|
54
|
-
this.
|
|
73
|
+
const o = raw as Record<string, unknown>
|
|
74
|
+
const preview = migratePreviewSettings(o, {
|
|
75
|
+
previewPanel: this.previewPanel,
|
|
76
|
+
previewRenderer: this.previewRenderer,
|
|
77
|
+
previewDuringRun: this.previewDuringRun,
|
|
78
|
+
})
|
|
79
|
+
this.previewPanel = preview.previewPanel
|
|
80
|
+
this.previewRenderer = preview.previewRenderer
|
|
81
|
+
this.previewDuringRun = preview.previewDuringRun
|
|
55
82
|
if (o.lastDraft != null && typeof o.lastDraft === 'object')
|
|
56
83
|
this.lastDraft = { ...(o.lastDraft as Record<string, string>) }
|
|
57
84
|
} catch {
|
|
@@ -3,7 +3,16 @@ import { draftKeyForFile, listDraftsForFile } from 'src/cli/tui/state/DraftsSt.t
|
|
|
3
3
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
4
4
|
|
|
5
5
|
export type TreeRow =
|
|
6
|
-
| { kind: '
|
|
6
|
+
| { kind: 'section'; label: string } // dim group header (bundled examples), never selectable
|
|
7
|
+
| {
|
|
8
|
+
kind: 'workflow'
|
|
9
|
+
file: string
|
|
10
|
+
name: string
|
|
11
|
+
expanded: boolean
|
|
12
|
+
current: boolean
|
|
13
|
+
hasDrafts: boolean
|
|
14
|
+
error: string | null
|
|
15
|
+
}
|
|
7
16
|
| { kind: 'draft'; file: string; draft: string; active: boolean }
|
|
8
17
|
|
|
9
18
|
/** the left `(t)ree`: workflows with their drafts nested under them */
|
|
@@ -19,7 +28,13 @@ export class TreeSt {
|
|
|
19
28
|
void this.st.drafts.version // fs-derived: recompute when drafts change
|
|
20
29
|
const w = this.st.workflows
|
|
21
30
|
const rows: TreeRow[] = []
|
|
31
|
+
let sectionPushed = false
|
|
22
32
|
for (const file of w.files) {
|
|
33
|
+
// bundled examples come LAST in files: one section header before the first
|
|
34
|
+
if (!sectionPushed && w.bundled.has(file)) {
|
|
35
|
+
rows.push({ kind: 'section', label: 'comfy-ts examples' })
|
|
36
|
+
sectionPushed = true
|
|
37
|
+
}
|
|
23
38
|
const current = file === w.currentPath
|
|
24
39
|
const expanded = this.expandedFiles.has(file)
|
|
25
40
|
const drafts = listDraftsForFile(file)
|
|
@@ -30,6 +45,7 @@ export class TreeSt {
|
|
|
30
45
|
expanded,
|
|
31
46
|
current,
|
|
32
47
|
hasDrafts: drafts.length > 0,
|
|
48
|
+
error: w.loadErrors.get(file) ?? null,
|
|
33
49
|
})
|
|
34
50
|
if (!expanded) continue
|
|
35
51
|
for (const draft of drafts) {
|
|
@@ -64,16 +80,23 @@ export class TreeSt {
|
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
move(delta: number): void {
|
|
67
|
-
const
|
|
83
|
+
const rows = this.rows
|
|
84
|
+
const len = rows.length
|
|
68
85
|
if (len === 0) return
|
|
69
|
-
|
|
86
|
+
let ix = this.ix
|
|
87
|
+
// hop over section headers (never selectable); bounded: wraps at most once
|
|
88
|
+
for (let step = 0; step < len; step++) {
|
|
89
|
+
ix = (ix + delta + len) % len
|
|
90
|
+
if (rows[ix]?.kind !== 'section') break
|
|
91
|
+
}
|
|
92
|
+
this.ix = ix
|
|
70
93
|
}
|
|
71
94
|
|
|
72
95
|
/** →: unfold the workflow under the cursor; on a draft row there is nothing
|
|
73
96
|
* left to unfold, so → continues rightwards into the vars panel */
|
|
74
97
|
unfold(): void {
|
|
75
98
|
const row = this.selected
|
|
76
|
-
if (row == null) return
|
|
99
|
+
if (row == null || row.kind === 'section') return
|
|
77
100
|
if (row.kind === 'workflow') this.expandedFiles.add(row.file)
|
|
78
101
|
else this.blur()
|
|
79
102
|
}
|
|
@@ -81,7 +104,7 @@ export class TreeSt {
|
|
|
81
104
|
/** ←: fold the workflow under the cursor; on a draft row, jump to (and fold) its parent */
|
|
82
105
|
fold(): void {
|
|
83
106
|
const row = this.selected
|
|
84
|
-
if (row == null) return
|
|
107
|
+
if (row == null || row.kind === 'section') return
|
|
85
108
|
this.expandedFiles.delete(row.file)
|
|
86
109
|
if (row.kind === 'draft') {
|
|
87
110
|
const ix = this.rows.findIndex((r) => r.kind === 'workflow' && r.file === row.file)
|
|
@@ -92,7 +115,7 @@ export class TreeSt {
|
|
|
92
115
|
/** ⏎: load the workflow (into 'default'), or the exact draft under the cursor */
|
|
93
116
|
async commit(): Promise<void> {
|
|
94
117
|
const row = this.selected
|
|
95
|
-
if (row == null) return
|
|
118
|
+
if (row == null || row.kind === 'section') return
|
|
96
119
|
if (row.kind === 'workflow') return this.st.workflows.commit(row.file)
|
|
97
120
|
return this.st.workflows.commit(row.file, row.draft)
|
|
98
121
|
}
|
|
@@ -100,6 +123,7 @@ export class TreeSt {
|
|
|
100
123
|
/** n: new draft — current workflow only (a draft snapshots its LIVE var values) */
|
|
101
124
|
promptNewDraft(): void {
|
|
102
125
|
const row = this.selected
|
|
126
|
+
if (row?.kind === 'section') return
|
|
103
127
|
if (row != null && row.file !== this.st.workflows.currentPath) {
|
|
104
128
|
this.st.exec.notice = 'load that workflow first (⏎) — a new draft snapshots its live vars'
|
|
105
129
|
return
|
|
@@ -4,6 +4,7 @@ import { DraftsSt } from 'src/cli/tui/state/DraftsSt.ts'
|
|
|
4
4
|
import { EditorSt } from 'src/cli/tui/state/EditorSt.ts'
|
|
5
5
|
import { ExecSt } from 'src/cli/tui/state/ExecSt.ts'
|
|
6
6
|
import { HostSt } from 'src/cli/tui/state/HostSt.ts'
|
|
7
|
+
import { LogsSt } from 'src/cli/tui/state/LogsSt.ts'
|
|
7
8
|
import { LorasSt } from 'src/cli/tui/state/LorasSt.ts'
|
|
8
9
|
import { PickerSt } from 'src/cli/tui/state/PickerSt.ts'
|
|
9
10
|
import { PreviewSt } from 'src/cli/tui/state/PreviewSt.ts'
|
|
@@ -14,11 +15,13 @@ import { WorkflowsSt } from 'src/cli/tui/state/WorkflowsSt.ts'
|
|
|
14
15
|
import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
|
|
15
16
|
|
|
16
17
|
// nav = vars list · tree = left workflow panel · host = host stats/actions ·
|
|
18
|
+
// preview = `p` settings menu in the preview panel ·
|
|
17
19
|
// edit = inline single-line (numbers + custom prompts) · overlay-* = modal popups
|
|
18
20
|
export type TuiMode =
|
|
19
21
|
| 'nav'
|
|
20
22
|
| 'tree'
|
|
21
23
|
| 'host'
|
|
24
|
+
| 'preview'
|
|
22
25
|
| 'edit'
|
|
23
26
|
| 'overlay-text'
|
|
24
27
|
| 'overlay-choice'
|
|
@@ -45,13 +48,24 @@ export class TuiSt {
|
|
|
45
48
|
preview: PreviewSt
|
|
46
49
|
host: HostSt
|
|
47
50
|
queue: QueueSt
|
|
51
|
+
logs: LogsSt
|
|
48
52
|
settings: SettingsSt
|
|
49
53
|
|
|
50
54
|
/** owned cleanups (reactions, listeners) — flushed by dispose() */
|
|
51
55
|
disposers: (() => void)[] = []
|
|
52
56
|
onExit: () => void = () => {}
|
|
53
57
|
|
|
54
|
-
constructor(
|
|
58
|
+
constructor(
|
|
59
|
+
wf: DefinedWorkflow,
|
|
60
|
+
opts: {
|
|
61
|
+
workflowFiles?: string[]
|
|
62
|
+
currentFile?: string
|
|
63
|
+
/** files that came from the PACKAGED examples (grouped apart in the tree) */
|
|
64
|
+
bundledFiles?: Set<string>
|
|
65
|
+
/** modules that failed to load before mount (red rows in the tree) */
|
|
66
|
+
loadErrors?: Map<string, string>
|
|
67
|
+
} = {},
|
|
68
|
+
) {
|
|
55
69
|
this.wf = wf
|
|
56
70
|
// wf: observable.ref so switching workflows re-renders without proxying
|
|
57
71
|
// the foreign object; children manage their own observability
|
|
@@ -68,19 +82,27 @@ export class TuiSt {
|
|
|
68
82
|
preview: false,
|
|
69
83
|
host: false,
|
|
70
84
|
queue: false,
|
|
85
|
+
logs: false,
|
|
71
86
|
settings: false,
|
|
72
87
|
})
|
|
73
88
|
this.settings = new SettingsSt(this)
|
|
74
89
|
this.editor = new EditorSt(this)
|
|
75
90
|
this.picker = new PickerSt(this)
|
|
76
91
|
this.loras = new LorasSt(this)
|
|
77
|
-
this.workflows = new WorkflowsSt(
|
|
92
|
+
this.workflows = new WorkflowsSt(
|
|
93
|
+
this,
|
|
94
|
+
opts.workflowFiles ?? [],
|
|
95
|
+
opts.currentFile ?? null,
|
|
96
|
+
opts.bundledFiles,
|
|
97
|
+
opts.loadErrors,
|
|
98
|
+
)
|
|
78
99
|
this.tree = new TreeSt(this)
|
|
79
100
|
this.drafts = new DraftsSt(this)
|
|
80
101
|
this.exec = new ExecSt(this)
|
|
81
102
|
this.preview = new PreviewSt(this)
|
|
82
103
|
this.host = new HostSt(this)
|
|
83
104
|
this.queue = new QueueSt(this)
|
|
105
|
+
this.logs = new LogsSt(this)
|
|
84
106
|
// the TUI is ALWAYS in a draft from the very first frame: the one this
|
|
85
107
|
// workflow was last in (settings), else 'default'; the current workflow
|
|
86
108
|
// starts unfolded so its drafts are visible in the tree
|
|
@@ -116,7 +138,9 @@ export class TuiSt {
|
|
|
116
138
|
get treeWidth(): number {
|
|
117
139
|
const longest = Math.max(
|
|
118
140
|
8,
|
|
119
|
-
...this.tree.rows.map((r) =>
|
|
141
|
+
...this.tree.rows.map((r) =>
|
|
142
|
+
r.kind === 'workflow' ? r.name.length : r.kind === 'draft' ? r.draft.length + 3 : r.label.length,
|
|
143
|
+
),
|
|
120
144
|
)
|
|
121
145
|
return Math.min(32, longest + 7)
|
|
122
146
|
}
|
|
@@ -12,8 +12,12 @@ export class WorkflowsSt {
|
|
|
12
12
|
private st: TuiSt,
|
|
13
13
|
public files: string[],
|
|
14
14
|
currentPath: string | null = null,
|
|
15
|
+
bundled: Set<string> = new Set(),
|
|
16
|
+
loadErrors: Map<string, string> = new Map(),
|
|
15
17
|
) {
|
|
16
18
|
this.currentPath = currentPath
|
|
19
|
+
this.bundled = bundled
|
|
20
|
+
this.loadErrors = loadErrors
|
|
17
21
|
makeAutoObservable<WorkflowsSt, 'st'>(this, { st: false })
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -21,6 +25,13 @@ export class WorkflowsSt {
|
|
|
21
25
|
currentPath: string | null
|
|
22
26
|
loading: boolean = false
|
|
23
27
|
|
|
28
|
+
/** the subset of files that came from the PACKAGED examples (grouped apart in the tree) */
|
|
29
|
+
bundled: Set<string>
|
|
30
|
+
|
|
31
|
+
/** per-file load failures (import threw / no DefinedWorkflow export) — red rows in the tree,
|
|
32
|
+
* cleared by a later successful load; ⏎ on the row retries */
|
|
33
|
+
loadErrors: Map<string, string>
|
|
34
|
+
|
|
24
35
|
/**
|
|
25
36
|
* every host seen across switches. Modules are import-cached, so a
|
|
26
37
|
* switched-away host must stay connected (switching back reuses it) — exit
|
|
@@ -65,10 +76,12 @@ export class WorkflowsSt {
|
|
|
65
76
|
const wf = findDefinedWorkflow(mod)
|
|
66
77
|
if (wf == null) throw new Error(`${path} exports no DefinedWorkflow`)
|
|
67
78
|
runInAction(() => {
|
|
79
|
+
this.loadErrors.delete(path)
|
|
68
80
|
this.loadedHosts.add(this.st.wf.host)
|
|
69
81
|
this.loadedHosts.add(wf.host)
|
|
70
82
|
this.st.wf = wf
|
|
71
83
|
this.st.queue.attach(wf.host)
|
|
84
|
+
this.st.logs.attach(wf.host)
|
|
72
85
|
this.currentPath = path
|
|
73
86
|
this.st.selIx = 0
|
|
74
87
|
this.st.mode = 'nav'
|
|
@@ -80,8 +93,10 @@ export class WorkflowsSt {
|
|
|
80
93
|
})
|
|
81
94
|
} catch (e) {
|
|
82
95
|
runInAction(() => {
|
|
96
|
+
const msg = extractErrorMessage(e)
|
|
97
|
+
this.loadErrors.set(path, msg)
|
|
83
98
|
this.st.mode = 'nav'
|
|
84
|
-
this.st.exec.error =
|
|
99
|
+
this.st.exec.error = msg
|
|
85
100
|
})
|
|
86
101
|
} finally {
|
|
87
102
|
runInAction(() => {
|