comfy-ts 1.4.0 → 2.1.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 +80 -6
- package/dist/{DefinedWorkflow-C_QAxKr3.js → DefinedWorkflow-CqNE_kgR.js} +4 -2
- package/dist/{DefinedWorkflow-C_QAxKr3.js.map → DefinedWorkflow-CqNE_kgR.js.map} +1 -1
- package/dist/{DraftsSt-DcOTn0QR.js → DraftsSt-C-gBk9v7.js} +3 -4
- package/dist/DraftsSt-C-gBk9v7.js.map +1 -0
- package/dist/cli.js +3 -3
- package/dist/index.cjs +212 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -77
- package/dist/index.d.ts +72 -77
- package/dist/index.js +212 -66
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-CN0DhrsA.js → run-serve-CnlN_RFH.js} +9 -7
- package/dist/run-serve-CnlN_RFH.js.map +1 -0
- package/dist/{run-tui-bN2hSD5i.js → run-tui-DXI_Jufu.js} +258 -56
- package/dist/run-tui-DXI_Jufu.js.map +1 -0
- package/dist/{state-COlKYipO.js → state-DC5BcG6d.js} +211 -67
- package/dist/state-DC5BcG6d.js.map +1 -0
- package/dist/web.d.ts +72 -77
- package/dist/web.js +212 -66
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/firered-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/lens-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sdk.d.ts +13251 -11458
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +2 -5
- package/examples/rvion/01-txt2img.cflow.ts +5 -3
- package/examples/rvion/02-img2img-upload.cflow.ts +5 -4
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +6 -7
- package/examples/rvion/05-comfy-cloud.cflow.ts +4 -2
- package/examples/rvion/06-qwen-image-edit.cflow.ts +2 -3
- package/examples/web/example.ts +8 -1
- package/package.json +1 -1
- package/src/cli/serve/ServeApp.ts +9 -6
- package/src/cli/tui/components/TuiApp.tsx +4 -5
- package/src/cli/tui/components/VarsPanel.tsx +40 -2
- package/src/cli/tui/imageClipboard.ts +40 -0
- package/src/cli/tui/state/DraftsSt.ts +1 -2
- package/src/cli/tui/state/ExecSt.ts +105 -40
- package/src/cli/tui/state/PreviewSt.ts +12 -11
- package/src/cli/tui/state/SettingsSt.ts +13 -0
- package/src/cli/tui/state/TuiSt.ts +54 -5
- package/src/host/ComfyHost.ts +33 -1
- package/src/runner/ComfyExecution.ts +162 -74
- package/src/runner/ComfyWorkflow.ts +25 -3
- package/src/runner/ComfyWsApi.ts +6 -0
- package/src/runner/MediaImage.ts +58 -11
- package/src/runner/ephemeral.ts +21 -0
- package/src/runner/outputPath.ts +2 -2
- package/src/sdk-generator/_pythonModuleToNamespace.ts +3 -0
- package/src/types/index.ts +6 -2
- package/src/vars/DefinedWorkflow.ts +3 -1
- package/dist/DraftsSt-DcOTn0QR.js.map +0 -1
- package/dist/run-serve-CN0DhrsA.js.map +0 -1
- package/dist/run-tui-bN2hSD5i.js.map +0 -1
- package/dist/state-COlKYipO.js.map +0 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
|
+
import { existsSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
2
4
|
import { makeAutoObservable, runInAction } from 'mobx'
|
|
3
|
-
import { basename } from 'pathe'
|
|
5
|
+
import { basename, join } from 'pathe'
|
|
4
6
|
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
5
7
|
import type { ExecutionProgress } from 'src/runner/ComfyExecution.ts'
|
|
6
|
-
import { imageClipboardCommand } from 'src/cli/tui/imageClipboard.ts'
|
|
8
|
+
import { imageClipboardCommand, imageClipboardStdinCommand } from 'src/cli/tui/imageClipboard.ts'
|
|
7
9
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
8
10
|
import type { SeedVar } from 'src/vars/ComfyVars.ts'
|
|
9
11
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
12
|
+
import type { MediaImage } from 'src/runner/MediaImage.ts'
|
|
10
13
|
|
|
11
14
|
/** popup body: summary + the head of the copied json (proof of WHAT is in the clipboard) */
|
|
12
15
|
export function jsonHead(text: string, maxLines: number): string[] {
|
|
@@ -25,7 +28,8 @@ export class ExecSt {
|
|
|
25
28
|
/** runs we launched that have not finished (the server executes them FIFO) */
|
|
26
29
|
inFlight: number = 0
|
|
27
30
|
progress: ExecutionProgress | null = null
|
|
28
|
-
outputs
|
|
31
|
+
/** last run's outputs — MediaImages, so memory-only runs (save toggle off) stay first-class */
|
|
32
|
+
outputImages: MediaImage[] = []
|
|
29
33
|
runCount: number = 0
|
|
30
34
|
lastStatus: string | null = null
|
|
31
35
|
error: string | null = null
|
|
@@ -45,13 +49,33 @@ export class ExecSt {
|
|
|
45
49
|
|
|
46
50
|
/** workflow switch: wipe run artifacts, keep a hello notice */
|
|
47
51
|
resetForWorkflow(notice: string): void {
|
|
48
|
-
this.
|
|
52
|
+
this.outputImages = []
|
|
49
53
|
this.error = null
|
|
50
54
|
this.notice = notice
|
|
51
55
|
this.runCount = 0
|
|
52
56
|
this.lastStatus = null
|
|
53
57
|
}
|
|
54
58
|
|
|
59
|
+
/** outputs box rows: path when saved, honest memory label otherwise */
|
|
60
|
+
get outputLabels(): { name: string; detail: string; memory: boolean }[] {
|
|
61
|
+
return this.outputImages.map((img) => {
|
|
62
|
+
if (img.absPath != null) return { name: basename(img.absPath), detail: img.absPath, memory: false }
|
|
63
|
+
const dims = img.width != null && img.height != null ? `${img.width}x${img.height}, ` : ''
|
|
64
|
+
return { name: img.filename, detail: `(${dims}in memory — i copies, o opens)`, memory: true }
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** a file path for viewer/clipboard: the saved file, or the bytes
|
|
69
|
+
* materialized into os tmpdir (deliberate user action, never a silent
|
|
70
|
+
* save — architecture item 14). The path derives from the content hash,
|
|
71
|
+
* so re-materializing is a cheap existsSync, no retention needed. */
|
|
72
|
+
private materialize(img: MediaImage): string {
|
|
73
|
+
if (img.absPath != null) return img.absPath
|
|
74
|
+
const path = join(tmpdir(), `comfy-ts-mem-${img.hash.slice(0, 8)}${img.extension}`)
|
|
75
|
+
if (!existsSync(path)) writeFileSync(path, img.buffer)
|
|
76
|
+
return path
|
|
77
|
+
}
|
|
78
|
+
|
|
55
79
|
/** every run takes THIS path, queued ones included: same progress, outputs, previews */
|
|
56
80
|
async run(): Promise<void> {
|
|
57
81
|
const queued = this.running
|
|
@@ -79,15 +103,18 @@ export class ExecSt {
|
|
|
79
103
|
try {
|
|
80
104
|
const execution = await this.st.wf.run({
|
|
81
105
|
host: this.st.hostOverride ?? undefined,
|
|
106
|
+
// the save rows (vars panel, item 14): on = files under
|
|
107
|
+
// .comfy-ts/outputs/<savePrefix>/, off = outputs stay in memory
|
|
108
|
+
save: this.st.settings.saveToDisk ? { prefix: this.st.savePrefix } : false,
|
|
82
109
|
onProgress: (p) => runInAction(() => this.onProgress(p)),
|
|
83
110
|
})
|
|
84
111
|
runInAction(() => {
|
|
85
|
-
this.
|
|
112
|
+
this.outputImages = execution.images.slice()
|
|
86
113
|
this.lastStatus = execution.status
|
|
87
114
|
this.runCount++
|
|
88
115
|
})
|
|
89
116
|
const lastImage = execution.images[execution.images.length - 1]
|
|
90
|
-
if (lastImage) void this.st.preview.renderOutput(lastImage.absPath)
|
|
117
|
+
if (lastImage != null) void this.st.preview.renderOutput(lastImage.absPath ?? lastImage.buffer)
|
|
91
118
|
} catch (e) {
|
|
92
119
|
runInAction(() => {
|
|
93
120
|
this.error = extractErrorMessage(e)
|
|
@@ -128,11 +155,18 @@ export class ExecSt {
|
|
|
128
155
|
|
|
129
156
|
/** 'o': real pixels in the OS viewer — the in-terminal ceiling is half-blocks */
|
|
130
157
|
openLastOutput(): void {
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
158
|
+
const lastImg = this.outputImages[this.outputImages.length - 1]
|
|
159
|
+
if (lastImg == null) {
|
|
133
160
|
this.notice = 'no output image yet'
|
|
134
161
|
return
|
|
135
162
|
}
|
|
163
|
+
let last: string
|
|
164
|
+
try {
|
|
165
|
+
last = this.materialize(lastImg)
|
|
166
|
+
} catch (e) {
|
|
167
|
+
this.notice = `open failed: ${extractErrorMessage(e)}`
|
|
168
|
+
return
|
|
169
|
+
}
|
|
136
170
|
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open'
|
|
137
171
|
const proc = spawn(cmd, [last], { stdio: 'ignore', detached: true })
|
|
138
172
|
proc.on('error', () => {
|
|
@@ -141,7 +175,7 @@ export class ExecSt {
|
|
|
141
175
|
})
|
|
142
176
|
})
|
|
143
177
|
proc.unref()
|
|
144
|
-
this.notice = `opened ${basename(last)}`
|
|
178
|
+
this.notice = `opened ${basename(last)}${lastImg.absPath == null ? ` (memory image via ${last})` : ''}`
|
|
145
179
|
}
|
|
146
180
|
|
|
147
181
|
// ---- clipboard ----
|
|
@@ -169,53 +203,84 @@ export class ExecSt {
|
|
|
169
203
|
this.copyPopup = { title, ok, lines }
|
|
170
204
|
this.st.mode = 'overlay-copy'
|
|
171
205
|
}
|
|
172
|
-
/** 'i': the LAST generated image's pixels → clipboard (paste anywhere)
|
|
206
|
+
/** 'i': the LAST generated image's pixels → clipboard (paste anywhere).
|
|
207
|
+
* The primary route pipes png bytes over stdin — no disk write at all
|
|
208
|
+
* (his ask 2026-07-31); only when that tool fails does it fall back to
|
|
209
|
+
* the materialized-file command, and the popup says which route ran. */
|
|
173
210
|
async copyLastImage(): Promise<void> {
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
211
|
+
const lastImg = this.outputImages[this.outputImages.length - 1]
|
|
212
|
+
if (lastImg == null) {
|
|
176
213
|
this.showCopyPopup('image → clipboard', false, ['no output image yet — r runs the workflow first'])
|
|
177
214
|
return
|
|
178
215
|
}
|
|
179
|
-
|
|
180
|
-
let
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
command = imageClipboardCommand(process.platform, file)
|
|
190
|
-
} catch (e) {
|
|
191
|
-
this.showCopyPopup('image → clipboard', false, [
|
|
192
|
-
`COPY FAILED for ${basename(last)}`,
|
|
193
|
-
`png transcode failed: ${extractErrorMessage(e)}`,
|
|
194
|
-
])
|
|
195
|
-
return
|
|
196
|
-
}
|
|
216
|
+
// normalize to png IN MEMORY: osascript/PS tag bytes, they never transcode
|
|
217
|
+
let pngBytes: Uint8Array
|
|
218
|
+
try {
|
|
219
|
+
pngBytes = lastImg.metadata.type === 'png' ? lastImg.buffer : await this.toPngBytes(lastImg.buffer)
|
|
220
|
+
} catch (e) {
|
|
221
|
+
this.showCopyPopup('image → clipboard', false, [
|
|
222
|
+
`COPY FAILED for ${lastImg.filename}`,
|
|
223
|
+
`png transcode failed: ${extractErrorMessage(e)}`,
|
|
224
|
+
])
|
|
225
|
+
return
|
|
197
226
|
}
|
|
198
|
-
|
|
199
|
-
|
|
227
|
+
const piped = imageClipboardStdinCommand(process.platform, pngBytes)
|
|
228
|
+
const pipedOk = await this.runWithStdin(piped)
|
|
229
|
+
if (pipedOk) {
|
|
230
|
+
this.showCopyPopup('image → clipboard', true, [
|
|
231
|
+
`${lastImg.filename} — paste the pixels anywhere`,
|
|
232
|
+
'',
|
|
233
|
+
'nothing written to disk',
|
|
234
|
+
])
|
|
200
235
|
return
|
|
201
236
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
237
|
+
// fallback: the piped tool failed (missing/blocked) — try the file route
|
|
238
|
+
let file: string
|
|
239
|
+
try {
|
|
240
|
+
file = this.materialize(lastImg)
|
|
241
|
+
} catch (e) {
|
|
242
|
+
this.showCopyPopup('image → clipboard', false, [
|
|
243
|
+
`COPY FAILED for ${lastImg.filename}`,
|
|
244
|
+
`piped ${piped.cmd} failed, and the tmp-file fallback could not write: ${extractErrorMessage(e)}`,
|
|
245
|
+
])
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
const command = imageClipboardCommand(process.platform, file)
|
|
249
|
+
const ok =
|
|
250
|
+
command != null &&
|
|
251
|
+
(await new Promise<boolean>((resolve) => {
|
|
252
|
+
const proc = spawn(command.cmd, command.args, { stdio: 'ignore' })
|
|
253
|
+
proc.on('error', () => resolve(false))
|
|
254
|
+
proc.on('close', (code) => resolve(code === 0))
|
|
255
|
+
}))
|
|
208
256
|
runInAction(() => {
|
|
209
257
|
this.showCopyPopup(
|
|
210
258
|
'image → clipboard',
|
|
211
259
|
ok,
|
|
212
260
|
ok
|
|
213
|
-
? [`${basename(
|
|
214
|
-
: [`COPY FAILED for ${
|
|
261
|
+
? [`${basename(file)} — paste the pixels anywhere`, '', `via fallback file ${file}`]
|
|
262
|
+
: [`COPY FAILED for ${lastImg.filename}`, `could not run ${piped.cmd} — is it installed and allowed ?`],
|
|
215
263
|
)
|
|
216
264
|
})
|
|
217
265
|
}
|
|
218
266
|
|
|
267
|
+
private async toPngBytes(bytes: Uint8Array): Promise<Uint8Array> {
|
|
268
|
+
const { default: sharp } = await import('sharp')
|
|
269
|
+
return new Uint8Array(await sharp(bytes).png().toBuffer())
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private runWithStdin(p: { cmd: string; args: string[]; stdin: Uint8Array }): Promise<boolean> {
|
|
273
|
+
return new Promise((resolve) => {
|
|
274
|
+
const proc = spawn(p.cmd, p.args, { stdio: ['pipe', 'ignore', 'ignore'] })
|
|
275
|
+
proc.on('error', () => resolve(false))
|
|
276
|
+
proc.on('close', (code) => resolve(code === 0))
|
|
277
|
+
// EPIPE when the tool is missing/dies early: the close handler decides
|
|
278
|
+
proc.stdin.on('error', () => {})
|
|
279
|
+
proc.stdin.write(p.stdin)
|
|
280
|
+
proc.stdin.end()
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
219
284
|
private toClipboard(text: string): Promise<boolean> {
|
|
220
285
|
const [cmd, ...args] =
|
|
221
286
|
process.platform === 'darwin'
|
|
@@ -52,8 +52,9 @@ export class PreviewSt {
|
|
|
52
52
|
latentDims: { width: number; height: number } | null = null
|
|
53
53
|
/** at least one latent frame arrived this run — false + progress = server sends none */
|
|
54
54
|
latentSeenThisRun: boolean = false
|
|
55
|
-
/** last output
|
|
56
|
-
|
|
55
|
+
/** last output, kept so a settings change can re-render it: a path when
|
|
56
|
+
* the run saved, raw bytes for memory-only runs (item 14) */
|
|
57
|
+
private lastOutput: string | Uint8Array | null = null
|
|
57
58
|
|
|
58
59
|
get show(): boolean {
|
|
59
60
|
return this.st.settings.previewPanel
|
|
@@ -162,7 +163,7 @@ export class PreviewSt {
|
|
|
162
163
|
this.latentBytes = null
|
|
163
164
|
this.latentDims = null
|
|
164
165
|
this.latentSeenThisRun = false
|
|
165
|
-
this.
|
|
166
|
+
this.lastOutput = null
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
/** run boundary: drop the latents so the next run never shows the previous one's */
|
|
@@ -177,7 +178,7 @@ export class PreviewSt {
|
|
|
177
178
|
onSettingsChanged(): void {
|
|
178
179
|
this.outputAnsi = null
|
|
179
180
|
this.outputBytes = null
|
|
180
|
-
if (this.show && this.
|
|
181
|
+
if (this.show && this.lastOutput != null) void this.renderOutput(this.lastOutput)
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
@@ -227,13 +228,13 @@ export class PreviewSt {
|
|
|
227
228
|
return Math.max(10, this.st.termRows - 12)
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
async renderOutput(
|
|
231
|
-
this.
|
|
231
|
+
async renderOutput(src: string | Uint8Array): Promise<void> {
|
|
232
|
+
this.lastOutput = src
|
|
232
233
|
if (!this.show) return
|
|
233
234
|
try {
|
|
234
235
|
if (this.useNative) {
|
|
235
236
|
// pre-shrink ONCE: the painter re-uploads on every repaint, so ~100KB beats ~2MB
|
|
236
|
-
const shrunk = await sharp(
|
|
237
|
+
const shrunk = await sharp(src)
|
|
237
238
|
.resize(896, 896, { fit: 'inside', withoutEnlargement: true })
|
|
238
239
|
.png()
|
|
239
240
|
.toBuffer()
|
|
@@ -242,7 +243,7 @@ export class PreviewSt {
|
|
|
242
243
|
})
|
|
243
244
|
return
|
|
244
245
|
}
|
|
245
|
-
const rendered = await imageBufferToAnsi(
|
|
246
|
+
const rendered = await imageBufferToAnsi(src, { width: this.width, height: this.height })
|
|
246
247
|
runInAction(() => {
|
|
247
248
|
this.outputAnsi = rendered
|
|
248
249
|
})
|
|
@@ -302,9 +303,9 @@ export class PreviewSt {
|
|
|
302
303
|
)
|
|
303
304
|
.png()
|
|
304
305
|
.toBuffer()
|
|
305
|
-
const
|
|
306
|
-
if (
|
|
307
|
-
const base = await sharp(
|
|
306
|
+
const out = this.lastOutput
|
|
307
|
+
if (out == null) return imageBufferToAnsi(thumb, { width: this.width, height: this.height })
|
|
308
|
+
const base = await sharp(out).resize(pxW, pxH, { fit: 'inside' }).png().toBuffer()
|
|
308
309
|
const composed = await sharp(base)
|
|
309
310
|
.composite([{ input: thumb, gravity: 'northeast' }])
|
|
310
311
|
.png()
|
|
@@ -60,6 +60,8 @@ export class SettingsSt {
|
|
|
60
60
|
lastWorkflow: this.lastWorkflow,
|
|
61
61
|
hostOverrideId: this.hostOverrideId,
|
|
62
62
|
collapsedDirs: this.collapsedDirs,
|
|
63
|
+
saveToDisk: this.saveToDisk,
|
|
64
|
+
savePrefix: this.savePrefix,
|
|
63
65
|
})
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -74,6 +76,10 @@ export class SettingsSt {
|
|
|
74
76
|
hostOverrideId: string | null = null
|
|
75
77
|
/** folded tree dirs (hand-tuned state persists, like every other surface) */
|
|
76
78
|
collapsedDirs: string[] = []
|
|
79
|
+
/** the vars-panel save toggle (architecture item 14): off = outputs stay in memory */
|
|
80
|
+
saveToDisk: boolean = true
|
|
81
|
+
/** per-module override of the local save dir under .comfy-ts/outputs/ (item 14) */
|
|
82
|
+
savePrefix: Record<string, string> = {}
|
|
77
83
|
|
|
78
84
|
rememberDraft(moduleKey: string, draft: string): void {
|
|
79
85
|
this.lastDraft[moduleKey] = draft
|
|
@@ -99,6 +105,13 @@ export class SettingsSt {
|
|
|
99
105
|
if (typeof o.lastWorkflow === 'string') this.lastWorkflow = o.lastWorkflow
|
|
100
106
|
if (typeof o.hostOverrideId === 'string') this.hostOverrideId = o.hostOverrideId
|
|
101
107
|
if (Array.isArray(o.collapsedDirs)) this.collapsedDirs = o.collapsedDirs.filter((d) => typeof d === 'string')
|
|
108
|
+
if (typeof o.saveToDisk === 'boolean') this.saveToDisk = o.saveToDisk
|
|
109
|
+
if (o.savePrefix != null && typeof o.savePrefix === 'object')
|
|
110
|
+
this.savePrefix = Object.fromEntries(
|
|
111
|
+
Object.entries(o.savePrefix as Record<string, unknown>).filter(
|
|
112
|
+
(kv): kv is [string, string] => typeof kv[1] === 'string',
|
|
113
|
+
),
|
|
114
|
+
)
|
|
102
115
|
} catch {
|
|
103
116
|
// corrupt settings must never block the TUI — start from defaults
|
|
104
117
|
}
|
|
@@ -2,7 +2,7 @@ import { makeAutoObservable, observable, runInAction } from 'mobx'
|
|
|
2
2
|
import { listWindow, type ListWindow } from 'src/cli/tui/listWindow.ts'
|
|
3
3
|
import type { SeedVar, ToggleVar, AnyVar } from 'src/vars/ComfyVars.ts'
|
|
4
4
|
import { ImagePickerSt } from 'src/cli/tui/imagePicker/ImagePickerSt.ts'
|
|
5
|
-
import { DraftsSt } from 'src/cli/tui/state/DraftsSt.ts'
|
|
5
|
+
import { DraftsSt, draftKeyForFile } from 'src/cli/tui/state/DraftsSt.ts'
|
|
6
6
|
import { EditorSt } from 'src/cli/tui/state/EditorSt.ts'
|
|
7
7
|
import { ExecSt } from 'src/cli/tui/state/ExecSt.ts'
|
|
8
8
|
import { HostSt } from 'src/cli/tui/state/HostSt.ts'
|
|
@@ -201,9 +201,43 @@ export class TuiSt {
|
|
|
201
201
|
return this.entries[this.selIx]
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
/** module key of the loaded workflow (drafts + savePrefix are keyed by it) */
|
|
205
|
+
get moduleKey(): string {
|
|
206
|
+
const cur = this.workflows.currentPath
|
|
207
|
+
return cur != null ? draftKeyForFile(cur) : (this.wf.spec.id ?? 'workflow')
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** the local save dir under .comfy-ts/outputs/ — per-module override, else the module key */
|
|
211
|
+
get savePrefix(): string {
|
|
212
|
+
return this.settings.savePrefix[this.moduleKey] ?? this.moduleKey
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** empty input resets to the module-key default */
|
|
216
|
+
setSavePrefix(raw: string): void {
|
|
217
|
+
const trimmed = raw.trim().replace(/^\/+|\/+$/g, '')
|
|
218
|
+
if (trimmed === '' || trimmed === this.moduleKey) delete this.settings.savePrefix[this.moduleKey]
|
|
219
|
+
else this.settings.savePrefix[this.moduleKey] = trimmed
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** the vars list carries the TUI-owned rows after the workflow vars: the
|
|
223
|
+
* save-to-disk toggle, plus the save-prefix row while saving is on
|
|
224
|
+
* (architecture item 14) */
|
|
225
|
+
get varRowCount(): number {
|
|
226
|
+
return this.entries.length + (this.settings.saveToDisk ? 2 : 1)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** true while the selection sits on the save-to-disk pseudo-row */
|
|
230
|
+
get onSaveRow(): boolean {
|
|
231
|
+
return this.selIx === this.entries.length
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** true while the selection sits on the save-prefix pseudo-row */
|
|
235
|
+
get onPrefixRow(): boolean {
|
|
236
|
+
return this.settings.saveToDisk && this.selIx === this.entries.length + 1
|
|
237
|
+
}
|
|
238
|
+
|
|
204
239
|
moveSel(delta: number): void {
|
|
205
|
-
const len = this.
|
|
206
|
-
if (len === 0) return
|
|
240
|
+
const len = this.varRowCount
|
|
207
241
|
this.selIx = (this.selIx + delta + len) % len
|
|
208
242
|
}
|
|
209
243
|
|
|
@@ -224,7 +258,7 @@ export class TuiSt {
|
|
|
224
258
|
}
|
|
225
259
|
|
|
226
260
|
get varsWindow(): ListWindow {
|
|
227
|
-
return listWindow({ count: this.
|
|
261
|
+
return listWindow({ count: this.varRowCount, selected: this.selIx, budget: this.varsBudget })
|
|
228
262
|
}
|
|
229
263
|
|
|
230
264
|
/**
|
|
@@ -237,7 +271,7 @@ export class TuiSt {
|
|
|
237
271
|
const w = this.varsWindow
|
|
238
272
|
if (w.moreAbove || w.moreBelow) return true
|
|
239
273
|
const h = this.varsViewH > 0 ? this.varsViewH : Math.max(5, this.termRows - 5)
|
|
240
|
-
return this.
|
|
274
|
+
return this.varRowCount + 2 > h
|
|
241
275
|
}
|
|
242
276
|
|
|
243
277
|
// kind-discriminated narrowing casts below are sanctioned (agent/coding.md):
|
|
@@ -245,6 +279,21 @@ export class TuiSt {
|
|
|
245
279
|
|
|
246
280
|
/** enter/space on a var: toggle, open an overlay, or inline-edit */
|
|
247
281
|
activate(): void {
|
|
282
|
+
if (this.onSaveRow) {
|
|
283
|
+
this.settings.saveToDisk = !this.settings.saveToDisk
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
if (this.onPrefixRow) {
|
|
287
|
+
this.editor.beginCustom({
|
|
288
|
+
title: `save prefix — dir under .comfy-ts/outputs/ (empty = ${this.moduleKey})`,
|
|
289
|
+
initial: this.savePrefix,
|
|
290
|
+
onCommit: (raw) => {
|
|
291
|
+
this.setSavePrefix(raw)
|
|
292
|
+
return true
|
|
293
|
+
},
|
|
294
|
+
})
|
|
295
|
+
return
|
|
296
|
+
}
|
|
248
297
|
const sel = this.selected?.[1]
|
|
249
298
|
if (sel == null) return
|
|
250
299
|
if (sel.kind === 'toggle') (sel as ToggleVar).toggle()
|
package/src/host/ComfyHost.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type ComfyStatusData,
|
|
14
14
|
type LogEntry,
|
|
15
15
|
type PromptID,
|
|
16
|
+
type PendingWsItem,
|
|
16
17
|
type PromptRelated_WsMsg,
|
|
17
18
|
type WsMsg,
|
|
18
19
|
WsMsg_ark,
|
|
@@ -574,6 +575,20 @@ export class ComfyHost<ID extends string = string> {
|
|
|
574
575
|
return this.postJSON_('/interrupt', {})
|
|
575
576
|
}
|
|
576
577
|
|
|
578
|
+
// HISTORY SCRUB (architecture.md item 14) -------------------------------------------
|
|
579
|
+
// deletes the server-side history ENTRY (workflow JSON, prompts, output
|
|
580
|
+
// filenames) — never files: the ephemeral tier creates none to begin with
|
|
581
|
+
|
|
582
|
+
/** delete ONE prompt's server history entry */
|
|
583
|
+
deleteHistory = (promptId: string): Promise<void> => {
|
|
584
|
+
return this.postJSON_('/history', { delete: [promptId] })
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/** wipe the server's WHOLE prompt history (every user of that server) */
|
|
588
|
+
clearHistory = (): Promise<void> => {
|
|
589
|
+
return this.postJSON_('/history', { clear: true })
|
|
590
|
+
}
|
|
591
|
+
|
|
577
592
|
// SERVER LOGS ----------------------------------------------------------------------
|
|
578
593
|
// /internal routes are served bare (no /api prefix, no custom-node hijacks)
|
|
579
594
|
|
|
@@ -669,7 +684,7 @@ export class ComfyHost<ID extends string = string> {
|
|
|
669
684
|
executions: Map<PromptID, ComfyExecution> = new Map()
|
|
670
685
|
|
|
671
686
|
/** buffer in case we receive packets out of order */
|
|
672
|
-
_pendingMsgs = new Map<PromptID,
|
|
687
|
+
_pendingMsgs = new Map<PromptID, PendingWsItem[]>()
|
|
673
688
|
|
|
674
689
|
/** the active prompt currently running on this host */
|
|
675
690
|
private activePromptID: PromptID | null = null
|
|
@@ -732,6 +747,23 @@ export class ComfyHost<ID extends string = string> {
|
|
|
732
747
|
if (e.data instanceof ArrayBuffer) {
|
|
733
748
|
const frame = parseBinaryWsFrame(e.data)
|
|
734
749
|
if (frame.kind === 'preview') {
|
|
750
|
+
// OUTPUT, not preview: while a SaveImageWebsocket node executes,
|
|
751
|
+
// each preview-kind frame IS one output image (frames follow their
|
|
752
|
+
// 'executing' message on the same socket — architecture.md item 14)
|
|
753
|
+
const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null
|
|
754
|
+
if (activeExec?.wsOutputNodeExecuting) {
|
|
755
|
+
activeExec.onWsImageOutput({ bytes: frame.bytes, mime: frame.mime })
|
|
756
|
+
return
|
|
757
|
+
}
|
|
758
|
+
// pre-registration window (reviewer catch 2026-07-31): ws messages
|
|
759
|
+
// can beat the POST /prompt response, and an ephemeral output frame
|
|
760
|
+
// in that window would be the ONLY copy of the image — buffer it IN
|
|
761
|
+
// ORDER with the json messages; ComfyExecution.onCreate replays the
|
|
762
|
+
// queue and decides output-vs-latent from the state at replay time
|
|
763
|
+
if (this.activePromptID != null) {
|
|
764
|
+
const pending = this._pendingMsgs.get(this.activePromptID)
|
|
765
|
+
if (pending != null) pending.push({ type: 'binary_preview_frame', bytes: frame.bytes, mime: frame.mime })
|
|
766
|
+
}
|
|
735
767
|
// type 1 AND the cloud's type 4 (preview + metadata) feed the same hook
|
|
736
768
|
const imageBlob = new Blob([frame.bytes], { type: frame.mime })
|
|
737
769
|
this.latentPreview = {
|