comfy-ts 2.21.0 → 2.23.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/dist/{ServeApp-ByMobrWW.js → ServeApp-DolRCMHj.js} +183 -14
- package/dist/ServeApp-DolRCMHj.js.map +1 -0
- package/dist/cli.js +5 -5
- package/dist/{exampleAssets-B5sMqNia.js → exampleAssets-Duneoq6r.js} +331 -42
- package/dist/exampleAssets-Duneoq6r.js.map +1 -0
- package/dist/{findDefinedWorkflow-BNZgYIww.js → findDefinedWorkflow-DjoJA8y7.js} +2 -2
- package/dist/{findDefinedWorkflow-BNZgYIww.js.map → findDefinedWorkflow-DjoJA8y7.js.map} +1 -1
- package/dist/index.cjs +381 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +201 -24
- package/dist/index.d.ts +201 -24
- package/dist/index.js +380 -35
- package/dist/index.js.map +1 -1
- package/dist/{run-run-CuBSygku.js → run-run-Cr0L9lCK.js} +5 -5
- package/dist/{run-run-CuBSygku.js.map → run-run-Cr0L9lCK.js.map} +1 -1
- package/dist/{run-serve-COk_G0Qz.js → run-serve---qA7o_m.js} +4 -4
- package/dist/{run-serve-COk_G0Qz.js.map → run-serve---qA7o_m.js.map} +1 -1
- package/dist/{run-tui-CB6i_x2y.js → run-tui-DxXiWo5J.js} +4 -4
- package/dist/{run-tui-CB6i_x2y.js.map → run-tui-DxXiWo5J.js.map} +1 -1
- package/dist/{schemaDrift-CHDVYlaj.js → schemaDrift-BTxdABHi.js} +36 -2
- package/dist/schemaDrift-BTxdABHi.js.map +1 -0
- package/dist/serve-web.js +207 -47
- package/dist/web.d.ts +201 -24
- package/dist/web.js +380 -35
- package/dist/web.js.map +1 -1
- package/examples/README.md +2 -0
- package/examples/comfy-cloud/sdk.d.ts +102 -1
- package/examples/depth-explorer/models.ts +722 -0
- package/examples/depth-explorer/serve.ts +140 -0
- package/examples/depth-explorer/thumbs/bae.webp +0 -0
- package/examples/depth-explorer/thumbs/da3-mono-large.webp +0 -0
- package/examples/depth-explorer/thumbs/dav1-vitl.webp +0 -0
- package/examples/depth-explorer/thumbs/dav2-vitl.webp +0 -0
- package/examples/depth-explorer/thumbs/dsine.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-albedo.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-metalness.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-roughness.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-shading.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-specular.webp +0 -0
- package/examples/depth-explorer/thumbs/leres.webp +0 -0
- package/examples/depth-explorer/thumbs/lotus-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/marigold2-albedo.webp +0 -0
- package/examples/depth-explorer/thumbs/marigold2-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/marigold2-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/metric3d-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/metric3d-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/midas-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/midas.webp +0 -0
- package/examples/depth-explorer/thumbs/moge2-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/moge2-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/zoe-da.webp +0 -0
- package/examples/depth-explorer/thumbs/zoe.webp +0 -0
- package/examples/depth-explorer/web/App.tsx +457 -0
- package/examples/depth-explorer/web/gl.ts +202 -0
- package/examples/depth-explorer/web/index.html +14 -0
- package/examples/depth-explorer/web/main.tsx +19 -0
- package/examples/depth-explorer/web/pixels.ts +86 -0
- package/examples/depth-explorer/web/state.ts +329 -0
- package/examples/depth-explorer/web/styles.css +366 -0
- package/examples/depth-explorer/web/tsconfig.json +16 -0
- package/examples/rvion/17-relight.cflow.ts +110 -0
- package/examples/rvion/18-world.cflow.ts +101 -0
- package/examples/world-explorer/serve.ts +171 -0
- package/examples/world-explorer/web/index.html +14 -0
- package/examples/world-explorer/web/main.tsx +200 -0
- package/examples/world-explorer/web/state.ts +212 -0
- package/examples/world-explorer/web/styles.css +131 -0
- package/examples/world-explorer/web/thumb.ts +21 -0
- package/examples/world-explorer/web/tsconfig.json +11 -0
- package/examples/world-explorer/world-state.ts +40 -0
- package/package.json +6 -7
- package/src/cli/serve/ServeApp.ts +106 -6
- package/src/cli/serve/describeVar.ts +12 -1
- package/src/cli/serve/resultHistory.ts +28 -5
- package/src/cli/serve/thumbs.ts +77 -0
- package/src/cli/serve/web/api.ts +9 -1
- package/src/cli/serve/web/components/Gallery.tsx +26 -1
- package/src/cli/serve/web/components/controls/BasicControls.tsx +14 -17
- package/src/cli/serve/web/components/controls/MediaControl.tsx +62 -9
- package/src/cli/serve/web/components/controls/RichSelect.tsx +262 -0
- package/src/cli/serve/web/state/RunSt.poll.test.ts +4 -1
- package/src/cli/serve/web/state/choiceButtons.ts +26 -2
- package/src/cli/serve/web/styles.ts +42 -0
- package/src/cli/serve/web/widgets/OutputWidgets.tsx +19 -0
- package/src/cli/serve/web/widgets/RelightSt.ts +113 -0
- package/src/cli/serve/web/widgets/RelightWidget.tsx +305 -0
- package/src/cli/serve/web/widgets/relightGl.ts +305 -0
- package/src/cli/serve/web/widgets/widgetStyles.ts +19 -0
- package/src/coreExports.ts +10 -0
- package/src/graph/ComfyNode.ts +12 -2
- package/src/host/ComfyHost.ts +153 -2
- package/src/host/ResilientWebsocket.ts +10 -0
- package/src/manager/script-update-manager.bun.ts +0 -7
- package/src/runner/ComfyExecution.ts +165 -20
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/historyReplay.ts +53 -0
- package/src/runner/outputs3d.ts +18 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
- package/src/vars/ComfyVars.ts +32 -2
- package/src/vars/DefinedWorkflow.ts +4 -0
- package/src/vars/outputWidgets.ts +47 -0
- package/dist/ServeApp-ByMobrWW.js.map +0 -1
- package/dist/exampleAssets-B5sMqNia.js.map +0 -1
- package/dist/schemaDrift-CHDVYlaj.js.map +0 -1
|
@@ -22,7 +22,11 @@ import type {
|
|
|
22
22
|
WsMsgExecutionSuccess,
|
|
23
23
|
} from 'src/runner/ComfyWsApi.ts'
|
|
24
24
|
import { MediaImage } from 'src/runner/MediaImage.ts'
|
|
25
|
-
import { isVideoFilename, mediaMime } from 'src/runner/mediaKinds.ts'
|
|
25
|
+
import { extensionOf, isVideoFilename, mediaMime } from 'src/runner/mediaKinds.ts'
|
|
26
|
+
import { model3dMime } from 'src/runner/outputs3d.ts'
|
|
27
|
+
import { type HistoryReplay, historyReplay } from 'src/runner/historyReplay.ts'
|
|
28
|
+
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
29
|
+
import { logError, logInfo } from 'src/utils/log.ts'
|
|
26
30
|
import { previewMetadataNodeId } from 'src/runner/wsBinaryFrame.ts'
|
|
27
31
|
|
|
28
32
|
/** paths claimed by in-flight retrievals: two same-second runs on a
|
|
@@ -36,6 +40,8 @@ export type ComfyExecutionData = {
|
|
|
36
40
|
graphID: ComfyWorkflowID
|
|
37
41
|
executed: boolean
|
|
38
42
|
error?: WsMsgExecutionError | WsMsgExecutionInterrupted | null
|
|
43
|
+
/** why comfy-ts failed the run itself, when no ComfyUI message says it (the host lost the prompt) */
|
|
44
|
+
reason?: string | null
|
|
39
45
|
status?: ComfyExecutionStatus | null
|
|
40
46
|
}
|
|
41
47
|
|
|
@@ -53,6 +59,10 @@ export type ComfyAudioOutput = {
|
|
|
53
59
|
* shape and same retrieval as an audio file */
|
|
54
60
|
export type ComfyVideoOutput = ComfyAudioOutput
|
|
55
61
|
|
|
62
|
+
/** one 3D file an output node published (SaveGLB, SaveGaussianSplat, SavePointCloud): a mesh, a point
|
|
63
|
+
* cloud or a splat, same retrieval as an audio file. `format` is the lowercase extension (glb, ply, spz…) */
|
|
64
|
+
export type Comfy3DOutput = ComfyAudioOutput & { format: string }
|
|
65
|
+
|
|
56
66
|
/** one text output as an output node published it (`nodeKey` is null when the node left the snapshot) */
|
|
57
67
|
export type ComfyTextOutput = {
|
|
58
68
|
nodeId: ComfyNodeId
|
|
@@ -118,7 +128,7 @@ export class ComfyExecution {
|
|
|
118
128
|
this.logProgress = init.logProgress ?? false
|
|
119
129
|
// register with the host so websocket messages route here,
|
|
120
130
|
// then flush messages that arrived before we existed
|
|
121
|
-
this.host.
|
|
131
|
+
this.host.trackExecution(this)
|
|
122
132
|
this.onCreate()
|
|
123
133
|
}
|
|
124
134
|
|
|
@@ -182,6 +192,7 @@ export class ComfyExecution {
|
|
|
182
192
|
const outputs = [`${this.images.length} image(s)`]
|
|
183
193
|
if (this.audios.length > 0) outputs.push(`${this.audios.length} audio(s)`)
|
|
184
194
|
if (this.videos.length > 0) outputs.push(`${this.videos.length} video(s)`)
|
|
195
|
+
if (this.models3d.length > 0) outputs.push(`${this.models3d.length} 3d model(s)`)
|
|
185
196
|
if (this.texts.length > 0) outputs.push(`${this.texts.length} text(s)`)
|
|
186
197
|
const line = `${this.status === 'Failure' ? '🔴' : '🟢'} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1000).toFixed(1)}s · ${outputs.join(' · ')}`
|
|
187
198
|
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`)
|
|
@@ -218,6 +229,11 @@ export class ComfyExecution {
|
|
|
218
229
|
}
|
|
219
230
|
|
|
220
231
|
onPromptRelatedMessage = (msg: PendingWsItem): void => {
|
|
232
|
+
// a run reconciled from /history can still hear its own end late: one end only
|
|
233
|
+
if (this.ended) return
|
|
234
|
+
this.heard()
|
|
235
|
+
if (msg.type === 'execution_success' || msg.type === 'execution_error' || msg.type === 'execution_interrupted')
|
|
236
|
+
this.ended = true
|
|
221
237
|
const graph = this.workflow
|
|
222
238
|
// replayed pre-registration binary frame: an OUTPUT only when the ws
|
|
223
239
|
// saver was executing at this point of the stream, else a preview
|
|
@@ -250,6 +266,7 @@ export class ComfyExecution {
|
|
|
250
266
|
}
|
|
251
267
|
|
|
252
268
|
private onExecutionSuccess = async (_msg: WsMsgExecutionSuccess): Promise<void> => {
|
|
269
|
+
if (this.mayHaveMissedEvents) await this.retrieveMissedOutputs()
|
|
253
270
|
await Promise.all(this.pendingPromises)
|
|
254
271
|
return this._finish({ status: 'Success' })
|
|
255
272
|
}
|
|
@@ -263,6 +280,7 @@ export class ComfyExecution {
|
|
|
263
280
|
/** update execution list */
|
|
264
281
|
private onExecuted = (msg: WsMsgExecuted): void => {
|
|
265
282
|
const promptNodeID = msg.data.node
|
|
283
|
+
this.heardExecuted.add(promptNodeID)
|
|
266
284
|
// a STRING output reaches the client ONLY through an output node's ui
|
|
267
285
|
// payload (PreviewAny), never through the prompt result
|
|
268
286
|
for (const entry of msg.data.output?.text ?? []) {
|
|
@@ -279,10 +297,13 @@ export class ComfyExecution {
|
|
|
279
297
|
)
|
|
280
298
|
for (const video of listed.filter((f) => isVideoFilename(f.filename))) {
|
|
281
299
|
this.pendingPromises.push(
|
|
282
|
-
this.retrieveFile(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
300
|
+
this.retrieveFile(video, promptNodeID, mediaMime(video.filename)).then(
|
|
301
|
+
(o) => void this.videos.push(o),
|
|
302
|
+
(e: unknown) => {
|
|
303
|
+
console.error(`🔴 failed to retrieve ${video.filename}:`, e)
|
|
304
|
+
this.videoErrors.push({ video, error: e })
|
|
305
|
+
},
|
|
306
|
+
),
|
|
286
307
|
)
|
|
287
308
|
}
|
|
288
309
|
const images = listed.filter((f) => !isVideoFilename(f.filename))
|
|
@@ -299,15 +320,134 @@ export class ComfyExecution {
|
|
|
299
320
|
}
|
|
300
321
|
for (const audio of msg.data.output?.audio ?? []) {
|
|
301
322
|
this.pendingPromises.push(
|
|
302
|
-
this.retrieveFile(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
323
|
+
this.retrieveFile(audio, promptNodeID, mediaMime(audio.filename)).then(
|
|
324
|
+
(o) => void this.audios.push(o),
|
|
325
|
+
(e: unknown) => {
|
|
326
|
+
console.error(`🔴 failed to retrieve ${audio.filename}:`, e)
|
|
327
|
+
this.audioErrors.push({ audio, error: e })
|
|
328
|
+
},
|
|
329
|
+
),
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
// a 3D loader echoes the file it READ, typed 'input', like LoadVideo
|
|
333
|
+
for (const model3d of (out?.['3d'] ?? []).filter((f) => f.type !== 'input')) {
|
|
334
|
+
this.pendingPromises.push(
|
|
335
|
+
this.retrieveFile(model3d, promptNodeID, model3dMime(model3d.filename)).then(
|
|
336
|
+
(o) => void this.models3d.push({ ...o, format: extensionOf(o.filename) }),
|
|
337
|
+
(e: unknown) => {
|
|
338
|
+
console.error(`🔴 failed to retrieve ${model3d.filename}:`, e)
|
|
339
|
+
this.models3dErrors.push({ model3d, error: e })
|
|
340
|
+
},
|
|
341
|
+
),
|
|
306
342
|
)
|
|
307
343
|
}
|
|
308
344
|
}
|
|
309
345
|
private pendingPromises: Promise<void>[] = []
|
|
310
346
|
|
|
347
|
+
/** an end message arrived (or was replayed): every later message is ignored */
|
|
348
|
+
private ended: boolean = false
|
|
349
|
+
/** the output nodes whose `executed` reached us, so a /history replay never retrieves one twice */
|
|
350
|
+
private heardExecuted: Set<string> = new Set()
|
|
351
|
+
|
|
352
|
+
/** the run lived through a reconnect and may have lost events: its end reads /history for them */
|
|
353
|
+
private mayHaveMissedEvents: boolean = false
|
|
354
|
+
|
|
355
|
+
private replayUnheardOutputs(replay: HistoryReplay): void {
|
|
356
|
+
for (const msg of replay.executed)
|
|
357
|
+
if (msg.type === 'executed' && !this.heardExecuted.has(msg.data.node)) this.onExecuted(msg)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** the history entry is written right after the end message is queued, so it may lag by a moment */
|
|
361
|
+
historyRetry: { tries: number; ms: number } = { tries: 5, ms: 400 }
|
|
362
|
+
|
|
363
|
+
/** a run that lived through a reconnect: an output node that ended in the gap is only in /history */
|
|
364
|
+
private retrieveMissedOutputs = async (): Promise<void> => {
|
|
365
|
+
const id = this.data.id
|
|
366
|
+
for (let i = 0; i < this.historyRetry.tries; i++) {
|
|
367
|
+
if (this.host.reconcileOff != null) return
|
|
368
|
+
if (i > 0) await new Promise((r) => setTimeout(r, this.historyRetry.ms))
|
|
369
|
+
try {
|
|
370
|
+
const replay = historyReplay(await this.host.fetchHistory(id), id)
|
|
371
|
+
if (replay == null) continue
|
|
372
|
+
return this.replayUnheardOutputs(replay)
|
|
373
|
+
} catch (e) {
|
|
374
|
+
if (this.host.noteReconcileFailure(e)) return
|
|
375
|
+
return logError(`run ${id}: its history did not answer (${extractErrorMessage(e)}); an output sent while the socket was down may be missing`)
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
logError(`run ${id}: no history entry after its end; an output sent while the socket was down may be missing`)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ---- reconcile over http (architecture.md, ResilientWebsocket.ts) ------------------------
|
|
382
|
+
/** @internal the last event of this run: the watchdog checks only runs quiet for host.runSilenceMs */
|
|
383
|
+
lastHeardAt: number = Date.now()
|
|
384
|
+
/** @internal a check is in flight: never two at once */
|
|
385
|
+
reconciling: boolean = false
|
|
386
|
+
private loggedReconcileProblems: Set<string> = new Set()
|
|
387
|
+
|
|
388
|
+
private heard(): void {
|
|
389
|
+
this.lastHeardAt = Date.now()
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
private logReconcileOnce(msg: string): void {
|
|
393
|
+
if (this.loggedReconcileProblems.has(msg)) return
|
|
394
|
+
this.loggedReconcileProblems.add(msg)
|
|
395
|
+
logError(`run ${this.data.id}: ${msg}`)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** @internal called before the host reads its queue. After a reconnect the run may have lost events,
|
|
399
|
+
* so its end reads /history for them; the flag is set before any await, so a live end that lands
|
|
400
|
+
* during the reads still looks. A check for silence alone does not set it: a quiet run lost nothing */
|
|
401
|
+
beginReconcile(why: 'reconnect' | 'silence'): void {
|
|
402
|
+
this.reconciling = true
|
|
403
|
+
if (why === 'reconnect') this.mayHaveMissedEvents = true
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** @internal ask the host where this run stands. `queued` is the host's queue read BEFORE this
|
|
407
|
+
* history read (the server moves a prompt from one to the other under one lock, so this order never
|
|
408
|
+
* misses a run that ended between the two reads); null when it did not answer, and then the run is
|
|
409
|
+
* never declared lost. A queued run needs no history read. Says how the check ended */
|
|
410
|
+
reconcile = async (queued: Set<string> | null): Promise<'history' | 'waiting' | 'lost'> => {
|
|
411
|
+
const id = this.data.id
|
|
412
|
+
const hostId = this.host.data.id
|
|
413
|
+
try {
|
|
414
|
+
if (this.ended || queued?.has(id) === true) return 'waiting'
|
|
415
|
+
let replay: HistoryReplay | null
|
|
416
|
+
try {
|
|
417
|
+
replay = historyReplay(await this.host.fetchHistory(id), id)
|
|
418
|
+
} catch (e) {
|
|
419
|
+
if (!this.host.noteReconcileFailure(e))
|
|
420
|
+
this.logReconcileOnce(`the history of host '${hostId}' did not answer (${extractErrorMessage(e)}); waiting for its events`)
|
|
421
|
+
return 'waiting'
|
|
422
|
+
}
|
|
423
|
+
if (this.ended) return 'waiting'
|
|
424
|
+
if (replay == null) {
|
|
425
|
+
if (queued == null) return 'waiting'
|
|
426
|
+
const reason = `host '${hostId}' has it neither in its queue nor in its history (cancelled, or the host restarted)`
|
|
427
|
+
logError(`run ${id}: ${reason}; the run fails`)
|
|
428
|
+
this.ended = true
|
|
429
|
+
await this._finish({ status: 'Failure', error: null, reason })
|
|
430
|
+
return 'lost'
|
|
431
|
+
}
|
|
432
|
+
logInfo(`run ${id}: ended on host '${hostId}' without its end reaching the socket, finishing from its history`)
|
|
433
|
+
for (const p of replay.problems) logError(`run ${id}: a history entry does not match the ws schemas, skipped: ${p}`)
|
|
434
|
+
this.replayUnheardOutputs(replay)
|
|
435
|
+
if (this.ephemeral)
|
|
436
|
+
logError(`run ${id}: SaveImageWebsocket frames sent while the socket did not hear are lost (they never reach the server disk)`)
|
|
437
|
+
if (replay.end != null) {
|
|
438
|
+
this.onPromptRelatedMessage(replay.end)
|
|
439
|
+
return 'history'
|
|
440
|
+
}
|
|
441
|
+
const reason = `its history entry on host '${hostId}' carries no end message`
|
|
442
|
+
logError(`run ${id}: ${reason}; the run fails`)
|
|
443
|
+
this.ended = true
|
|
444
|
+
await this._finish({ status: 'Failure', error: null, reason })
|
|
445
|
+
return 'history'
|
|
446
|
+
} finally {
|
|
447
|
+
this.reconciling = false
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
311
451
|
/** audio retrievals that failed (their files are missing from `audios`) */
|
|
312
452
|
audioErrors: { audio: ComfyImageInfo; error: unknown }[] = []
|
|
313
453
|
|
|
@@ -320,20 +460,22 @@ export class ComfyExecution {
|
|
|
320
460
|
/** video files retrieved for this execution, in arrival order (final once `done` resolves) */
|
|
321
461
|
videos: ComfyVideoOutput[] = []
|
|
322
462
|
|
|
463
|
+
/** 3D retrievals that failed (their files are missing from `models3d`) */
|
|
464
|
+
models3dErrors: { model3d: ComfyImageInfo; error: unknown }[] = []
|
|
465
|
+
|
|
466
|
+
/** 3D files retrieved for this execution, in arrival order (final once `done` resolves) */
|
|
467
|
+
models3d: Comfy3DOutput[] = []
|
|
468
|
+
|
|
469
|
+
/** one non-image file through /view, its bytes as the server wrote them; the caller files it */
|
|
323
470
|
private retrieveFile = async (
|
|
324
|
-
kind: 'audio' | 'video',
|
|
325
471
|
info: ComfyImageInfo,
|
|
326
472
|
promptNodeID: ComfyNodeId,
|
|
327
|
-
|
|
473
|
+
mime: string,
|
|
474
|
+
): Promise<ComfyAudioOutput> => {
|
|
328
475
|
const response = await this.host.fetchFile('/view?' + new URLSearchParams(info).toString())
|
|
329
476
|
const bytes = new Uint8Array(await response.arrayBuffer())
|
|
330
|
-
const mime = mediaMime(info.filename)
|
|
331
|
-
const list = kind === 'audio' ? this.audios : this.videos
|
|
332
477
|
const sf = this.save
|
|
333
|
-
if (sf == null) {
|
|
334
|
-
list.push({ nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: null })
|
|
335
|
-
return
|
|
336
|
-
}
|
|
478
|
+
if (sf == null) return { nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: null }
|
|
337
479
|
const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs['filename_prefix']
|
|
338
480
|
const written = await this.encodeAndWrite({
|
|
339
481
|
bytes,
|
|
@@ -343,7 +485,7 @@ export class ComfyExecution {
|
|
|
343
485
|
subfolder: info.subfolder,
|
|
344
486
|
filename: info.filename,
|
|
345
487
|
})
|
|
346
|
-
|
|
488
|
+
return { nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: written.path }
|
|
347
489
|
}
|
|
348
490
|
|
|
349
491
|
/** image retrievals that failed (their images are missing from `images`);
|
|
@@ -477,6 +619,7 @@ export class ComfyExecution {
|
|
|
477
619
|
/** @internal a live preview frame of this run; never an output (the host routes ws saver frames
|
|
478
620
|
* to onWsImageOutput before they get here) */
|
|
479
621
|
onPreviewFrame(p: { bytes: Uint8Array; mime: string; metadata: unknown }): void {
|
|
622
|
+
this.heard()
|
|
480
623
|
const listener = this.onPreview
|
|
481
624
|
if (listener == null) return
|
|
482
625
|
const current = this.workflow.currentExecutingNode
|
|
@@ -498,6 +641,7 @@ export class ComfyExecution {
|
|
|
498
641
|
/** one binary ws frame = one output image of the executing SaveImageWebsocket
|
|
499
642
|
* node (architecture.md item 14 — the zero-server-disk path) */
|
|
500
643
|
onWsImageOutput = (p: { bytes: Uint8Array; mime: string }): void => {
|
|
644
|
+
this.heard()
|
|
501
645
|
const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null
|
|
502
646
|
this.pendingPromises.push(
|
|
503
647
|
this.storeWsImage(p, promptNodeID).catch((e: unknown) => {
|
|
@@ -545,6 +689,7 @@ export class ComfyExecution {
|
|
|
545
689
|
|
|
546
690
|
/** @internal a live-text frame for one node */
|
|
547
691
|
onProgressText(p: { nodeId: string; text: string }): void {
|
|
692
|
+
this.heard()
|
|
548
693
|
this.progressTexts.set(p.nodeId, p.text)
|
|
549
694
|
this.progressText = p.text
|
|
550
695
|
this.emitProgress()
|
|
@@ -560,7 +705,7 @@ export class ComfyExecution {
|
|
|
560
705
|
}
|
|
561
706
|
|
|
562
707
|
private alreadyDone: boolean = false
|
|
563
|
-
private _finish = async (p: Pick<ComfyExecutionData, 'status' | 'error'>): Promise<void> => {
|
|
708
|
+
private _finish = async (p: Pick<ComfyExecutionData, 'status' | 'error' | 'reason'>): Promise<void> => {
|
|
564
709
|
if (this.alreadyDone) throw new Error(`❌ invariant violation: already finished`)
|
|
565
710
|
this.alreadyDone = true
|
|
566
711
|
this.update({ ...p, executed: true })
|
package/src/runner/ComfyWsApi.ts
CHANGED
|
@@ -73,6 +73,8 @@ const tempScope = scope({
|
|
|
73
73
|
// VideoHelperSuite's VHS_VideoCombine, and savers that name their list `video`
|
|
74
74
|
'video?': 'ComfyImageInfo[]',
|
|
75
75
|
'gifs?': 'ComfyImageInfo[]',
|
|
76
|
+
// native 3D savers (SaveGLB, SaveGaussianSplat, SavePointCloud): UI.Saved3DModels
|
|
77
|
+
'3d?': 'ComfyImageInfo[]',
|
|
76
78
|
// ui payload of a text output node (PreviewAny, and how TextGenerate
|
|
77
79
|
// results reach the client); entries are soft, non-strings are dropped
|
|
78
80
|
'text?': 'unknown[]',
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type } from 'arktype'
|
|
2
|
+
import { type PromptID, type PromptRelated_WsMsg, types } from 'src/runner/ComfyWsApi.ts'
|
|
3
|
+
|
|
4
|
+
const END_TYPES: ReadonlySet<string> = new Set(['execution_success', 'execution_error', 'execution_interrupted'])
|
|
5
|
+
|
|
6
|
+
export type HistoryReplay = {
|
|
7
|
+
/** one `executed` per output node the entry lists */
|
|
8
|
+
executed: PromptRelated_WsMsg[]
|
|
9
|
+
/** the end message: from `status.messages`, or a success when the entry says success (or, on an
|
|
10
|
+
* old server, says nothing). Null when the entry claims an end it does not carry */
|
|
11
|
+
end: PromptRelated_WsMsg | null
|
|
12
|
+
/** entries that did not pass the ws schemas, skipped */
|
|
13
|
+
problems: string[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** a prompt's `GET /history/<id>` reply as the ws messages a client missed. Null while the host has no
|
|
17
|
+
* entry for it: queued, running, or lost */
|
|
18
|
+
export function historyReplay(json: unknown, promptId: PromptID): HistoryReplay | null {
|
|
19
|
+
const entry = field(json, promptId)
|
|
20
|
+
if (entry == null) return null
|
|
21
|
+
const problems: string[] = []
|
|
22
|
+
const valid = (raw: unknown): PromptRelated_WsMsg | null => {
|
|
23
|
+
const res = types.PromptRelated_WsMsg(raw)
|
|
24
|
+
if (!(res instanceof type.errors)) return res
|
|
25
|
+
problems.push(`${JSON.stringify(raw).slice(0, 200)}: ${res.summary}`)
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const executed: PromptRelated_WsMsg[] = []
|
|
30
|
+
const outputs = field(entry, 'outputs')
|
|
31
|
+
if (typeof outputs === 'object' && outputs != null)
|
|
32
|
+
for (const [node, output] of Object.entries(outputs)) {
|
|
33
|
+
const msg = valid({ type: 'executed', data: { node, output, prompt_id: promptId } })
|
|
34
|
+
if (msg != null) executed.push(msg)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const status = field(entry, 'status')
|
|
38
|
+
const list = field(status, 'messages')
|
|
39
|
+
let end: PromptRelated_WsMsg | null = null
|
|
40
|
+
for (const m of Array.isArray(list) ? list : []) {
|
|
41
|
+
if (!Array.isArray(m) || typeof m[0] !== 'string' || !END_TYPES.has(m[0])) continue
|
|
42
|
+
end = valid({ type: m[0], data: m[1] })
|
|
43
|
+
}
|
|
44
|
+
const statusStr = field(status, 'status_str')
|
|
45
|
+
if (end == null && (status == null || statusStr === 'success'))
|
|
46
|
+
end = valid({ type: 'execution_success', data: { prompt_id: promptId, timestamp: Date.now() } })
|
|
47
|
+
return { executed, end, problems }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function field(x: unknown, key: string): unknown {
|
|
51
|
+
if (typeof x !== 'object' || x == null) return null
|
|
52
|
+
return Reflect.get(x, key) ?? null
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// the 3D files an output node can publish (ui key `3d`), and their mimes. PURE + dependency-free.
|
|
2
|
+
// a sibling of mediaKinds.ts on purpose: MediaKind drives the media VARS, and a 3D output is no var kind
|
|
3
|
+
|
|
4
|
+
import { extensionOf } from 'src/runner/mediaKinds.ts'
|
|
5
|
+
|
|
6
|
+
/** ply and spz have no registered mime: the `x-` forms are what three.js and the splat viewers accept */
|
|
7
|
+
export const MODEL_3D_MIMES: Readonly<Record<string, string>> = {
|
|
8
|
+
glb: 'model/gltf-binary',
|
|
9
|
+
gltf: 'model/gltf+json',
|
|
10
|
+
ply: 'model/x-ply',
|
|
11
|
+
spz: 'model/x-spz',
|
|
12
|
+
obj: 'model/obj',
|
|
13
|
+
stl: 'model/stl',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function model3dMime(filename: string): string {
|
|
17
|
+
return MODEL_3D_MIMES[extensionOf(filename)] ?? 'application/octet-stream'
|
|
18
|
+
}
|
|
@@ -318,10 +318,15 @@ export function codegenSDK(this: ComfySchema, opts: CodegenOptions): string {
|
|
|
318
318
|
// 2/3
|
|
319
319
|
p('')
|
|
320
320
|
p('// named slot types: everything an input of that type accepts')
|
|
321
|
+
const slotTypeNames = new Set<string>(slotTypes.map((t) => t.comfyType))
|
|
321
322
|
for (const t of slotTypes) {
|
|
322
|
-
|
|
323
|
-
|
|
323
|
+
const own = `${t.tsType} | HasSingle['${t.comfyType}'] | ((x: Producer['${t.comfyType}']) => Accepts['${t.comfyType}'])`
|
|
324
|
+
// `MESH,FILE_3D_GLB` takes an output of ANY listed type (SaveGLB's `mesh`)
|
|
325
|
+
const parts = t.comfyType.includes(',') ? t.comfyType.split(',').map((s) => s.trim()) : []
|
|
326
|
+
const anyOf = parts.map((part) =>
|
|
327
|
+
slotTypeNames.has(part) ? `Accepts['${part}']` : `ComfyNodeOutput<'${part}'>`,
|
|
324
328
|
)
|
|
329
|
+
p(`${escapeJSKey(t.comfyType)}: ${[own, ...anyOf].join(' | ')}`)
|
|
325
330
|
}
|
|
326
331
|
|
|
327
332
|
// 3/3
|
package/src/vars/ComfyVars.ts
CHANGED
|
@@ -46,6 +46,28 @@ export type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' |
|
|
|
46
46
|
*/
|
|
47
47
|
/** how a var LOOKS in the panel, set by the workflow: `v.int(8).ui({ icon, color, description })`.
|
|
48
48
|
* Every slot is optional, a color is any css color */
|
|
49
|
+
/** how one option of a choice var looks in the panel. Every field is optional: a bare option
|
|
50
|
+
* shows its value */
|
|
51
|
+
export type ChoiceOptionLook = {
|
|
52
|
+
/** a 24×24 svg path drawn in the color, or a whole `<svg …>` string */
|
|
53
|
+
icon?: string
|
|
54
|
+
color?: string
|
|
55
|
+
/** the name shown instead of the raw value (the value stays the payload) */
|
|
56
|
+
label?: string
|
|
57
|
+
description?: string
|
|
58
|
+
/** a picture: an http(s) url, or a local path relative to the workflow file */
|
|
59
|
+
thumb?: string
|
|
60
|
+
/** when it came out: `2025`, `2025-11` */
|
|
61
|
+
date?: string
|
|
62
|
+
/** what it weighs on disk: `1.3 GB` */
|
|
63
|
+
size?: string
|
|
64
|
+
/** 1 (rough) to 5 (the best of its kind) */
|
|
65
|
+
quality?: number
|
|
66
|
+
/** how long it takes: `0.9 s`, `30 s` */
|
|
67
|
+
speed?: string
|
|
68
|
+
tags?: string[]
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
export type VarUi = {
|
|
50
72
|
/** shown as a (?) after the label, the text is its tooltip */
|
|
51
73
|
description?: string
|
|
@@ -62,8 +84,8 @@ export type VarUi = {
|
|
|
62
84
|
groupColor?: string
|
|
63
85
|
border?: string
|
|
64
86
|
/** choice vars: a look per option, keyed by the option value. The lit option is filled
|
|
65
|
-
* with its own color */
|
|
66
|
-
options?: Record<string,
|
|
87
|
+
* with its own color; a dropdown row shows the rest (ChoiceOptionLook) */
|
|
88
|
+
options?: Record<string, ChoiceOptionLook>
|
|
67
89
|
/** the field is shown but disabled unless every named var holds one of the listed values:
|
|
68
90
|
* `{ model: ['aesthetic', 'base'] }`. Checked against the var names when the workflow loads.
|
|
69
91
|
* Display only: a disabled var's value still reaches the build */
|
|
@@ -909,6 +931,10 @@ export type MediaVarOpts = {
|
|
|
909
931
|
/** the text var a file's `<name>.txt` sidecar fills, when a driver sets this var from a file
|
|
910
932
|
* and leaves that one unset: a voice clip's transcript (`comfy-ts run`) */
|
|
911
933
|
sidecarText?: TextVar
|
|
934
|
+
/** one-click starting files: `{ 'a lioness': exampleImagePath(…), 'a ruin': 'https://…' }`.
|
|
935
|
+
* A local path that is not on this machine is shown disabled, a url is fetched when a run
|
|
936
|
+
* uses it. Key order is display order */
|
|
937
|
+
presets?: Record<string, string>
|
|
912
938
|
}
|
|
913
939
|
export type ImageVarOpts = MediaVarOpts
|
|
914
940
|
export type AudioVarOpts = MediaVarOpts
|
|
@@ -965,6 +991,10 @@ export abstract class MediaVar extends ComfyVar<string> {
|
|
|
965
991
|
get extensions(): readonly string[] {
|
|
966
992
|
return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind]
|
|
967
993
|
}
|
|
994
|
+
/** the one-click starting files, `~/` expanded, in their declared order */
|
|
995
|
+
get presets(): { label: string; value: string }[] {
|
|
996
|
+
return Object.entries(this.opts.presets ?? {}).map(([label, value]) => ({ label, value: expandUserPath(value) }))
|
|
997
|
+
}
|
|
968
998
|
override set(value: string): this {
|
|
969
999
|
return super.set(expandUserPath(value))
|
|
970
1000
|
}
|
|
@@ -3,6 +3,7 @@ import type { ComfyExecution } from 'src/runner/ComfyExecution.ts'
|
|
|
3
3
|
import type { ComfyWorkflow, RunSettings } from 'src/runner/ComfyWorkflow.ts'
|
|
4
4
|
import type { SdkForHost } from 'src/types/comfy-sdk.ts'
|
|
5
5
|
import type { LorasInput } from 'src/vars/lanes.ts'
|
|
6
|
+
import type { OutputWidget } from 'src/vars/outputWidgets.ts'
|
|
6
7
|
import {
|
|
7
8
|
type AnyVar,
|
|
8
9
|
type ChoiceVar,
|
|
@@ -73,6 +74,9 @@ export type DefineWorkflowSpec<ID extends string, V extends VarsSpec> = {
|
|
|
73
74
|
/** free search tags for the serve omnibox, added to the ones read from the graph
|
|
74
75
|
* (`image`, `audio`, `video`, `text`, `llm`, `edit`) */
|
|
75
76
|
tags?: string[]
|
|
77
|
+
/** built-in web panel widgets drawn over a run's outputs (`widget.relight(...)`), each role
|
|
78
|
+
* naming the `tag` of a save node. The CLI and the TUI ignore them */
|
|
79
|
+
widgets?: OutputWidget[]
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
/** type predicate (not a cast): a VarsSpec is a plain record, never callable */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// output widgets: a module names a BUILT-IN web panel widget and maps its roles to output tags
|
|
2
|
+
// (the `tag` of a save node's metadata). The panel renders it over the run's tagged images; the
|
|
3
|
+
// CLI and the TUI ignore it. Pure data: the web bundle imports this file.
|
|
4
|
+
|
|
5
|
+
/** the maps a relight widget reads, each the tag of one output image */
|
|
6
|
+
export type RelightRoles = {
|
|
7
|
+
/** the photo itself; the base colour when no albedo is given */
|
|
8
|
+
image: string
|
|
9
|
+
/** near = white; places each pixel in 3D and casts the shadows */
|
|
10
|
+
depth?: string
|
|
11
|
+
/** OpenGL convention (green up) */
|
|
12
|
+
normal?: string
|
|
13
|
+
albedo?: string
|
|
14
|
+
/** white = rough */
|
|
15
|
+
roughness?: string
|
|
16
|
+
/** white = metal */
|
|
17
|
+
metalness?: string
|
|
18
|
+
/** the non diffuse part of the light (reflections, highlights) */
|
|
19
|
+
specular?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type RelightWidget = { kind: 'relight'; title?: string; roles: RelightRoles }
|
|
23
|
+
|
|
24
|
+
export type OutputWidget = RelightWidget
|
|
25
|
+
export type OutputWidgetKind = OutputWidget['kind']
|
|
26
|
+
|
|
27
|
+
export const widget = {
|
|
28
|
+
/** a point light moved over the image in 3D: left/right, up/down, nearer/farther */
|
|
29
|
+
relight(roles: RelightRoles, opts: { title?: string } = {}): RelightWidget {
|
|
30
|
+
if (roles.depth == null && roles.normal == null)
|
|
31
|
+
throw new Error(
|
|
32
|
+
'widget.relight needs a `depth` or a `normal` role: without either there is no surface to light',
|
|
33
|
+
)
|
|
34
|
+
return { kind: 'relight', roles, ...(opts.title != null ? { title: opts.title } : {}) }
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** the roles of a widget whose tag one of the images carries, as role → index in `images` */
|
|
39
|
+
export function resolveWidgetRoles(w: OutputWidget, images: { tags?: string[] }[]): Map<string, number> {
|
|
40
|
+
const out = new Map<string, number>()
|
|
41
|
+
for (const [role, tag] of Object.entries(w.roles)) {
|
|
42
|
+
if (typeof tag !== 'string') continue
|
|
43
|
+
const ix = images.findIndex((img) => img.tags?.includes(tag) === true)
|
|
44
|
+
if (ix >= 0) out.set(role, ix)
|
|
45
|
+
}
|
|
46
|
+
return out
|
|
47
|
+
}
|