comfy-ts 2.22.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.
Files changed (54) hide show
  1. package/dist/{ServeApp-DuxYdaZZ.js → ServeApp-DolRCMHj.js} +51 -17
  2. package/dist/ServeApp-DolRCMHj.js.map +1 -0
  3. package/dist/cli.js +5 -5
  4. package/dist/{exampleAssets-1NHndnNB.js → exampleAssets-Duneoq6r.js} +330 -28
  5. package/dist/exampleAssets-Duneoq6r.js.map +1 -0
  6. package/dist/{findDefinedWorkflow-CRsBTTJK.js → findDefinedWorkflow-DjoJA8y7.js} +2 -2
  7. package/dist/{findDefinedWorkflow-CRsBTTJK.js.map → findDefinedWorkflow-DjoJA8y7.js.map} +1 -1
  8. package/dist/index.cjs +350 -34
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +131 -19
  11. package/dist/index.d.ts +131 -19
  12. package/dist/index.js +350 -34
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-run-Y5ZI48vV.js → run-run-Cr0L9lCK.js} +5 -5
  15. package/dist/{run-run-Y5ZI48vV.js.map → run-run-Cr0L9lCK.js.map} +1 -1
  16. package/dist/{run-serve-CICU_wTL.js → run-serve---qA7o_m.js} +4 -4
  17. package/dist/{run-serve-CICU_wTL.js.map → run-serve---qA7o_m.js.map} +1 -1
  18. package/dist/{run-tui-CViJXsHL.js → run-tui-DxXiWo5J.js} +4 -4
  19. package/dist/{run-tui-CViJXsHL.js.map → run-tui-DxXiWo5J.js.map} +1 -1
  20. package/dist/{schemaDrift-CzjaIwZX.js → schemaDrift-BTxdABHi.js} +16 -2
  21. package/dist/{schemaDrift-CzjaIwZX.js.map → schemaDrift-BTxdABHi.js.map} +1 -1
  22. package/dist/serve-web.js +46 -43
  23. package/dist/web.d.ts +131 -19
  24. package/dist/web.js +350 -34
  25. package/dist/web.js.map +1 -1
  26. package/examples/comfy-cloud/sdk.d.ts +102 -1
  27. package/examples/rvion/18-world.cflow.ts +101 -0
  28. package/examples/world-explorer/serve.ts +171 -0
  29. package/examples/world-explorer/web/index.html +14 -0
  30. package/examples/world-explorer/web/main.tsx +200 -0
  31. package/examples/world-explorer/web/state.ts +212 -0
  32. package/examples/world-explorer/web/styles.css +131 -0
  33. package/examples/world-explorer/web/thumb.ts +21 -0
  34. package/examples/world-explorer/web/tsconfig.json +11 -0
  35. package/examples/world-explorer/world-state.ts +40 -0
  36. package/package.json +5 -7
  37. package/src/cli/serve/ServeApp.ts +27 -2
  38. package/src/cli/serve/resultHistory.ts +22 -4
  39. package/src/cli/serve/thumbs.ts +19 -8
  40. package/src/cli/serve/web/api.ts +4 -0
  41. package/src/cli/serve/web/components/Gallery.tsx +24 -1
  42. package/src/cli/serve/web/styles.ts +3 -0
  43. package/src/coreExports.ts +1 -0
  44. package/src/graph/ComfyNode.ts +12 -2
  45. package/src/host/ComfyHost.ts +153 -2
  46. package/src/host/ResilientWebsocket.ts +10 -0
  47. package/src/manager/script-update-manager.bun.ts +0 -7
  48. package/src/runner/ComfyExecution.ts +165 -20
  49. package/src/runner/ComfyWsApi.ts +2 -0
  50. package/src/runner/historyReplay.ts +53 -0
  51. package/src/runner/outputs3d.ts +18 -0
  52. package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
  53. package/dist/ServeApp-DuxYdaZZ.js.map +0 -1
  54. package/dist/exampleAssets-1NHndnNB.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.executions.set(data.id, this)
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('video', video, promptNodeID).catch((e: unknown) => {
283
- console.error(`🔴 failed to retrieve ${video.filename}:`, e)
284
- this.videoErrors.push({ video, error: e })
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('audio', audio, promptNodeID).catch((e: unknown) => {
303
- console.error(`🔴 failed to retrieve ${audio.filename}:`, e)
304
- this.audioErrors.push({ audio, error: e })
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
- ): Promise<void> => {
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
- list.push({ nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: written.path })
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 })
@@ -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
- p(
323
- `${escapeJSKey(t.comfyType)}: ${t.tsType} | HasSingle['${t.comfyType}'] | ((x: Producer['${t.comfyType}']) => Accepts['${t.comfyType}'])`,
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