comfy-ts 1.4.0 → 2.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.
Files changed (89) hide show
  1. package/README.md +80 -6
  2. package/dist/{DefinedWorkflow-C_QAxKr3.js → DefinedWorkflow-CqNE_kgR.js} +4 -2
  3. package/dist/{DefinedWorkflow-C_QAxKr3.js.map → DefinedWorkflow-CqNE_kgR.js.map} +1 -1
  4. package/dist/{DraftsSt-DcOTn0QR.js → DraftsSt-Da4DZUP7.js} +2 -2
  5. package/dist/{DraftsSt-DcOTn0QR.js.map → DraftsSt-Da4DZUP7.js.map} +1 -1
  6. package/dist/cli.js +3 -3
  7. package/dist/index.cjs +212 -66
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +72 -77
  10. package/dist/index.d.ts +72 -77
  11. package/dist/index.js +212 -66
  12. package/dist/index.js.map +1 -1
  13. package/dist/{run-serve-CN0DhrsA.js → run-serve-BqeXtf8P.js} +9 -7
  14. package/dist/run-serve-BqeXtf8P.js.map +1 -0
  15. package/dist/{run-tui-bN2hSD5i.js → run-tui-CiB7TbYv.js} +12 -6
  16. package/dist/run-tui-CiB7TbYv.js.map +1 -0
  17. package/dist/{state-COlKYipO.js → state-C1g_B8zR.js} +211 -67
  18. package/dist/state-C1g_B8zR.js.map +1 -0
  19. package/dist/web.d.ts +72 -77
  20. package/dist/web.js +212 -66
  21. package/dist/web.js.map +1 -1
  22. package/examples/comfy-cloud/ace-step-t2a.cflow.ts +1 -0
  23. package/examples/comfy-cloud/anima-t2i.cflow.ts +2 -3
  24. package/examples/comfy-cloud/boogu-i2i.cflow.ts +2 -5
  25. package/examples/comfy-cloud/capybara-i2i.cflow.ts +2 -2
  26. package/examples/comfy-cloud/capybara-i2v.cflow.ts +1 -0
  27. package/examples/comfy-cloud/capybara-t2i.cflow.ts +2 -2
  28. package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +1 -0
  29. package/examples/comfy-cloud/chroma-t2i.cflow.ts +2 -5
  30. package/examples/comfy-cloud/ernie-t2i.cflow.ts +2 -3
  31. package/examples/comfy-cloud/firered-i2i.cflow.ts +2 -2
  32. package/examples/comfy-cloud/flux1-i2i.cflow.ts +2 -2
  33. package/examples/comfy-cloud/flux1-t2i.cflow.ts +2 -2
  34. package/examples/comfy-cloud/flux2-i2i.cflow.ts +2 -5
  35. package/examples/comfy-cloud/flux2-t2i.cflow.ts +2 -5
  36. package/examples/comfy-cloud/hidream-i2i.cflow.ts +2 -5
  37. package/examples/comfy-cloud/hidream-t2i.cflow.ts +2 -2
  38. package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +1 -0
  39. package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +1 -0
  40. package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +2 -3
  41. package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +1 -0
  42. package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +2 -2
  43. package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +1 -0
  44. package/examples/comfy-cloud/krea2-t2i.cflow.ts +2 -3
  45. package/examples/comfy-cloud/lens-t2i.cflow.ts +2 -3
  46. package/examples/comfy-cloud/longcat-i2i.cflow.ts +2 -2
  47. package/examples/comfy-cloud/longcat-t2i.cflow.ts +2 -5
  48. package/examples/comfy-cloud/ltxv-i2v.cflow.ts +1 -0
  49. package/examples/comfy-cloud/ltxv-t2v.cflow.ts +1 -0
  50. package/examples/comfy-cloud/newbie-t2i.cflow.ts +2 -5
  51. package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +2 -5
  52. package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +2 -5
  53. package/examples/comfy-cloud/ovis-t2i.cflow.ts +2 -5
  54. package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +2 -5
  55. package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +2 -2
  56. package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +2 -2
  57. package/examples/comfy-cloud/sd35-t2i.cflow.ts +2 -2
  58. package/examples/comfy-cloud/sdk.d.ts +13251 -11458
  59. package/examples/comfy-cloud/sdxl-t2i.cflow.ts +2 -2
  60. package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +1 -0
  61. package/examples/comfy-cloud/svd-i2v.cflow.ts +1 -0
  62. package/examples/comfy-cloud/wan21-i2v.cflow.ts +1 -0
  63. package/examples/comfy-cloud/wan21-t2v.cflow.ts +1 -0
  64. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +1 -0
  65. package/examples/comfy-cloud/wan22-i2v.cflow.ts +1 -0
  66. package/examples/comfy-cloud/wan22-t2v.cflow.ts +1 -0
  67. package/examples/comfy-cloud/z-image-t2i.cflow.ts +2 -5
  68. package/examples/rvion/01-txt2img.cflow.ts +5 -3
  69. package/examples/rvion/02-img2img-upload.cflow.ts +5 -4
  70. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +6 -7
  71. package/examples/rvion/05-comfy-cloud.cflow.ts +4 -2
  72. package/examples/rvion/06-qwen-image-edit.cflow.ts +2 -3
  73. package/examples/web/example.ts +8 -1
  74. package/package.json +1 -1
  75. package/src/cli/serve/ServeApp.ts +9 -6
  76. package/src/cli/tui/state/ExecSt.ts +14 -2
  77. package/src/host/ComfyHost.ts +33 -1
  78. package/src/runner/ComfyExecution.ts +162 -74
  79. package/src/runner/ComfyWorkflow.ts +25 -3
  80. package/src/runner/ComfyWsApi.ts +6 -0
  81. package/src/runner/MediaImage.ts +58 -11
  82. package/src/runner/ephemeral.ts +21 -0
  83. package/src/runner/outputPath.ts +2 -2
  84. package/src/sdk-generator/_pythonModuleToNamespace.ts +3 -0
  85. package/src/types/index.ts +6 -2
  86. package/src/vars/DefinedWorkflow.ts +3 -1
  87. package/dist/run-serve-CN0DhrsA.js.map +0 -1
  88. package/dist/run-tui-bN2hSD5i.js.map +0 -1
  89. package/dist/state-COlKYipO.js.map +0 -1
@@ -52,7 +52,7 @@ export const sdxlT2i = host.defineWorkflow({
52
52
  end_at_step: 10000,
53
53
  return_with_leftover_noise: 'disable',
54
54
  })
55
- b.SaveImage({ images: b.VAEDecode({ samples, vae: refiner }), filename_prefix: 'comfy-ts-zoo/sdxl-t2i' })
55
+ b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae: refiner }) })
56
56
  },
57
57
  })
58
58
 
@@ -63,7 +63,7 @@ if (import.meta.main) {
63
63
  requireCloudKey()
64
64
  if (process.argv[2]) sdxlT2i.vars.prompt.set(process.argv[2])
65
65
  if (process.argv[3]) sdxlT2i.vars.seed.set(Number(process.argv[3]))
66
- const execution = await sdxlT2i.run({ log: true })
66
+ const execution = await sdxlT2i.run({ log: true, save: { prefix: 'comfy-ts-zoo/sdxl-t2i' } })
67
67
  for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
68
68
  host.disconnect()
69
69
  }
@@ -1,6 +1,7 @@
1
1
  // stable-audio t2a on Comfy Cloud — Stable Audio Open 1.0 text to audio, up to ~47s, mp3 out
2
2
  // source template: audio_stable_audio_example.json (official workflow-templates)
3
3
  // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // note: audio outputs PERSIST on the host (upstream ships no websocket saver for audio — image examples stream ephemerally)
4
5
  // run directly: bun examples/comfy-cloud/stable-audio-t2a.cflow.ts ["prompt"] [seed]
5
6
  import { v } from 'comfy-ts'
6
7
  import { cloudHost, requireCloudKey } from './cloudHost.ts'
@@ -1,6 +1,7 @@
1
1
  // svd i2v on Comfy Cloud — Stable Video Diffusion (svd_xt), 25 frames from a still image, no text prompt
2
2
  // source template: txt_to_image_to_video.json (official workflow-templates), SDXL t2i half replaced by LoadImage
3
3
  // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // note: video outputs PERSIST on the host (upstream ships no websocket saver for video — image examples stream ephemerally)
4
5
  // run directly: bun examples/comfy-cloud/svd-i2v.cflow.ts [path/to/image.png] [seed]
5
6
  import { asAbsolutePath, exampleImagePath, MediaImage, v } from 'comfy-ts'
6
7
  import { cloudHost, requireCloudKey } from './cloudHost.ts'
@@ -1,6 +1,7 @@
1
1
  // wan21 i2v on Comfy Cloud — Wan 2.1 14B 480p image to video: start image + CLIP vision steer the motion
2
2
  // source template: image_to_video_wan.json (official workflow-templates)
3
3
  // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // note: video outputs PERSIST on the host (upstream ships no websocket saver for video — image examples stream ephemerally)
4
5
  // run directly: bun examples/comfy-cloud/wan21-i2v.cflow.ts [path/to/image.png] ["prompt"]
5
6
  import { asAbsolutePath, exampleImagePath, MediaImage, v } from 'comfy-ts'
6
7
  import { cloudHost, requireCloudKey } from './cloudHost.ts'
@@ -1,6 +1,7 @@
1
1
  // wan21 t2v on Comfy Cloud — Wan 2.1 1.3B text to video, 480p, 33 frames at 16 fps
2
2
  // source template: text_to_video_wan.json (official workflow-templates)
3
3
  // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // note: video outputs PERSIST on the host (upstream ships no websocket saver for video — image examples stream ephemerally)
4
5
  // run directly: bun examples/comfy-cloud/wan21-t2v.cflow.ts ["prompt"] [seed]
5
6
  import { v } from 'comfy-ts'
6
7
  import { cloudHost, requireCloudKey } from './cloudHost.ts'
@@ -1,6 +1,7 @@
1
1
  // wan22-5b t2v on Comfy Cloud — Wan 2.2 5B ti2v, one compact model, 5s @ 24fps 1280x704
2
2
  // source template: video_wan2_2_5B_ti2v.json (official workflow-templates)
3
3
  // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // note: video outputs PERSIST on the host (upstream ships no websocket saver for video — image examples stream ephemerally)
4
5
  // run directly: bun examples/comfy-cloud/wan22-5b-t2v.cflow.ts ["prompt"] [seed]
5
6
  import { v } from 'comfy-ts'
6
7
  import { cloudHost, requireCloudKey } from './cloudHost.ts'
@@ -1,6 +1,7 @@
1
1
  // wan22 i2v on Comfy Cloud — Wan 2.2 14B image to video, two experts: high noise then low noise, 5s @ 16fps
2
2
  // source template: video_wan2_2_14B_i2v.json (official workflow-templates)
3
3
  // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // note: video outputs PERSIST on the host (upstream ships no websocket saver for video — image examples stream ephemerally)
4
5
  // run directly: bun examples/comfy-cloud/wan22-i2v.cflow.ts [path/to/image.png] ["prompt"]
5
6
  import { asAbsolutePath, exampleImagePath, MediaImage, v } from 'comfy-ts'
6
7
  import { cloudHost, requireCloudKey } from './cloudHost.ts'
@@ -1,6 +1,7 @@
1
1
  // wan22 t2v on Comfy Cloud — Wan 2.2 14B text to video, two experts: high noise then low noise, 5s @ 16fps
2
2
  // source template: video_wan2_2_14B_t2v.json (official workflow-templates)
3
3
  // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // note: video outputs PERSIST on the host (upstream ships no websocket saver for video — image examples stream ephemerally)
4
5
  // run directly: bun examples/comfy-cloud/wan22-t2v.cflow.ts ["prompt"] [seed]
5
6
  import { v } from 'comfy-ts'
6
7
  import { cloudHost, requireCloudKey } from './cloudHost.ts'
@@ -42,10 +42,7 @@ export const zImageT2i = host.defineWorkflow({
42
42
  scheduler: 'simple',
43
43
  denoise: 1,
44
44
  })
45
- b.SaveImage({
46
- images: b.VAEDecode({ samples, vae: b.VAELoader({ vae_name: 'ae.safetensors' }) }),
47
- filename_prefix: 'comfy-ts-zoo/z-image-t2i',
48
- })
45
+ b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae: b.VAELoader({ vae_name: 'ae.safetensors' }) }) })
49
46
  },
50
47
  })
51
48
 
@@ -56,7 +53,7 @@ if (import.meta.main) {
56
53
  requireCloudKey()
57
54
  if (process.argv[2]) zImageT2i.vars.prompt.set(process.argv[2])
58
55
  if (process.argv[3]) zImageT2i.vars.seed.set(Number(process.argv[3]))
59
- const execution = await zImageT2i.run({ log: true })
56
+ const execution = await zImageT2i.run({ log: true, save: { prefix: 'comfy-ts-zoo/z-image-t2i' } })
60
57
  for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
61
58
  host.disconnect()
62
59
  }
@@ -16,7 +16,6 @@ export const txt2img = host.defineWorkflow({
16
16
  steps: v.int(20, { min: 1, max: 60 }),
17
17
  cfg: v.float(7, { min: 0, max: 30 }),
18
18
  size: v.size({ width: 512, height: 512 }),
19
- prefix: v.text('comfy-ts-example'),
20
19
  },
21
20
  build: (b, vars) => {
22
21
  const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'SD1.5\\v1-5-pruned-emaonly.ckpt' })
@@ -32,7 +31,9 @@ export const txt2img = host.defineWorkflow({
32
31
  scheduler: 'normal',
33
32
  denoise: 1,
34
33
  })
35
- b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: vars.prefix })
34
+ // SaveImageWebsocket: the image streams back over the ws and never
35
+ // touches the server disk (README "Ephemeral outputs")
36
+ b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae: ckpt }) })
36
37
  },
37
38
  })
38
39
 
@@ -43,7 +44,8 @@ if (import.meta.main) {
43
44
  if (process.argv[2]) txt2img.vars.prompt.set(process.argv[2])
44
45
  if (process.argv[3]) txt2img.vars.seed.set(Number(process.argv[3]))
45
46
 
46
- const execution = await txt2img.run({ log: true })
47
+ // local saving is opt-in: without `save` the outputs stay in memory only
48
+ const execution = await txt2img.run({ log: true, save: { prefix: 'comfy-ts-example/txt2img' } })
47
49
  console.log(`🟢 done — ${execution.images.length} image(s):`)
48
50
  for (const img of execution.images) console.log(` ${img.absPath} (${img.width}x${img.height})`)
49
51
  host.disconnect()
@@ -19,9 +19,10 @@ export const img2img = host.defineWorkflow({
19
19
  seed: v.seed(7),
20
20
  steps: v.int(20, { min: 1, max: 60 }),
21
21
  denoise: v.float(0.65, { min: 0, max: 1 }),
22
- prefix: v.text('comfy-ts-img2img'),
23
22
  },
24
- // async build: the input image is uploaded (hash-named, deduped) per run
23
+ // async build: the input image is uploaded (hash-named, deduped) per run.
24
+ // NOTE: uploads PERSIST in the server's input/ folder — for inputs that
25
+ // must not touch the server either, see MediaImage.loadInWorkflow_viaBase64Node
25
26
  build: async (b, vars, wf) => {
26
27
  const img = new MediaImage({ path: asAbsolutePath(image.absPath()) })
27
28
  const loaded = await img.loadInWorkflow_viaLoadImageNode(wf)
@@ -39,7 +40,7 @@ export const img2img = host.defineWorkflow({
39
40
  scheduler: 'normal',
40
41
  denoise: vars.denoise, // 0.65 keeps 35% of the input image
41
42
  })
42
- b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: vars.prefix })
43
+ b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae: ckpt }) })
43
44
  },
44
45
  })
45
46
 
@@ -49,7 +50,7 @@ export default img2img
49
50
  if (import.meta.main) {
50
51
  if (process.argv[2]) img2img.vars.image.set(process.argv[2])
51
52
 
52
- const execution = await img2img.run({ log: true })
53
+ const execution = await img2img.run({ log: true, save: { prefix: 'comfy-ts-example/img2img-upload' } })
53
54
  for (const out of execution.images) console.log(`🟢 ${out.absPath}`)
54
55
  host.disconnect()
55
56
  }
@@ -32,7 +32,6 @@ export const t2i = host.defineWorkflow({
32
32
  size: v.size({ width: 1024, height: 1024 }),
33
33
  removeBg: v.toggle(true, 'remove bg'),
34
34
  loras,
35
- prefix: v.text('krea2-turbo-t2i'),
36
35
  }
37
36
  },
38
37
  build: (b, vars) => {
@@ -87,9 +86,9 @@ export const t2i = host.defineWorkflow({
87
86
  const image = b.VAEDecode({ samples, vae })
88
87
 
89
88
  if (vars.removeBg) {
90
- // background removal → transparent png. SaveImage alone drops RMBG's
91
- // alpha, so rejoin the MASK via core JoinImageWithAlpha (which inverts
92
- // the mask internally — hence the InvertMask in front).
89
+ // background removal → transparent png. The image savers drop RMBG's
90
+ // alpha unless rejoined, so rejoin the MASK via core JoinImageWithAlpha
91
+ // (which inverts the mask internally — hence the InvertMask in front).
93
92
  const cutout = b['rmbg.RMBG']({
94
93
  image,
95
94
  model: 'BEN2',
@@ -105,9 +104,9 @@ export const t2i = host.defineWorkflow({
105
104
  image: cutout.outputs.IMAGE,
106
105
  alpha: b.InvertMask({ mask: cutout.outputs.MASK }),
107
106
  })
108
- b.SaveImage({ images: rgba, filename_prefix: vars.prefix })
107
+ b.SaveImageWebsocket({ images: rgba })
109
108
  } else {
110
- b.SaveImage({ images: image, filename_prefix: vars.prefix })
109
+ b.SaveImageWebsocket({ images: image })
111
110
  }
112
111
  },
113
112
  })
@@ -119,7 +118,7 @@ if (import.meta.main) {
119
118
  if (process.argv[2]) t2i.vars.prompt.set(process.argv[2])
120
119
  if (process.argv[3]) t2i.vars.seed.set(Number(process.argv[3]))
121
120
 
122
- const execution = await t2i.run({ log: true })
121
+ const execution = await t2i.run({ log: true, save: { prefix: 'comfy-ts-example/krea2-turbo-t2i' } })
123
122
  for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
124
123
  host.disconnect()
125
124
  }
@@ -31,7 +31,9 @@ export const sd15T2i = host.defineWorkflow({
31
31
  scheduler: 'normal',
32
32
  denoise: 1,
33
33
  })
34
- b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: 'comfy-ts-zoo/sd15-t2i' })
34
+ // SaveImageWebsocket: outputs stream back over the ws, nothing lands on
35
+ // the cloud's storage (README "Ephemeral outputs")
36
+ b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae: ckpt }) })
35
37
  },
36
38
  })
37
39
 
@@ -44,7 +46,7 @@ if (import.meta.main) {
44
46
  if (process.argv[3]) sd15T2i.vars.seed.set(Number(process.argv[3]))
45
47
 
46
48
  const t0 = Date.now()
47
- const execution = await sd15T2i.run({ log: true })
49
+ const execution = await sd15T2i.run({ log: true, save: { prefix: 'comfy-ts-zoo/sd15-t2i' } })
48
50
  console.log(`🟢 done in ${((Date.now() - t0) / 1000).toFixed(1)}s — ${execution.images.length} image(s):`)
49
51
  for (const img of execution.images) console.log(` ${img.absPath} (${img.width}x${img.height})`)
50
52
  host.disconnect()
@@ -21,7 +21,6 @@ export const qwenImageEdit = host.defineWorkflow({
21
21
  seed: v.seed(42),
22
22
  steps: v.int(4, { min: 1, max: 60 }),
23
23
  lightning: v.toggle(true, '4-step lightning lora'),
24
- prefix: v.text('qwen-image-edit'),
25
24
  },
26
25
  // async build: the reference image is uploaded (hash-named, deduped) per run
27
26
  build: async (b, vars, wf) => {
@@ -72,7 +71,7 @@ export const qwenImageEdit = host.defineWorkflow({
72
71
  scheduler: 'simple',
73
72
  denoise: 1,
74
73
  })
75
- b.SaveImage({ images: b.VAEDecode({ samples, vae }), filename_prefix: vars.prefix })
74
+ b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae }) })
76
75
  },
77
76
  })
78
77
 
@@ -83,7 +82,7 @@ if (import.meta.main) {
83
82
  if (process.argv[2]) qwenImageEdit.vars.image.set(process.argv[2])
84
83
  if (process.argv[3]) qwenImageEdit.vars.prompt.set(process.argv[3])
85
84
 
86
- const execution = await qwenImageEdit.run({ log: true })
85
+ const execution = await qwenImageEdit.run({ log: true, save: { prefix: 'comfy-ts-example/qwen-image-edit' } })
87
86
  for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
88
87
  host.disconnect()
89
88
  }
@@ -51,7 +51,14 @@ async function generate(): Promise<void> {
51
51
  cfg: 7,
52
52
  denoise: 1,
53
53
  })
54
- node(b.SaveImage, 'SaveImage')({ images: node(b.VAEDecode, 'VAEDecode')({ samples: sampled, vae: ckpt }) })
54
+ // SaveImageWebsocket: the image streams back over the ws — nothing lands
55
+ // on the server, and in the browser nothing could land on disk anyway
56
+ node(
57
+ b.SaveImageWebsocket,
58
+ 'SaveImageWebsocket',
59
+ )({
60
+ images: node(b.VAEDecode, 'VAEDecode')({ samples: sampled, vae: ckpt }),
61
+ })
55
62
 
56
63
  const execution = await wf.run({
57
64
  onProgress: (p) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 50+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -13,11 +13,12 @@ import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
13
13
 
14
14
  export type ServeModule = { key: string; file: string; dw: DefinedWorkflow }
15
15
 
16
- /** structural face of ComfyExecution — tests inject a fake starter */
16
+ /** structural face of ComfyExecution — tests inject a fake starter.
17
+ * absPath is null for in-memory images (a ws-saver run with saving off) */
17
18
  export type ServeExecution = {
18
19
  done: Promise<unknown>
19
20
  status: string
20
- images: { absPath: string; filename: string }[]
21
+ images: { absPath: string | null; filename: string }[]
21
22
  data: { id: string; error?: unknown }
22
23
  }
23
24
 
@@ -26,11 +27,13 @@ export type ServeStarter = (mod: ServeModule) => Promise<ServeExecution>
26
27
  export type ServeRequest = { method: string; url: string; accept?: string; body?: string }
27
28
  export type ServeReply = { status: number; contentType: string; body: string | Uint8Array }
28
29
 
29
- /** connect + fresh graph from current var values + send; done is awaited OUTSIDE the module mutex */
30
+ /** connect + fresh graph from current var values + send; done is awaited OUTSIDE the module mutex.
31
+ * serve OPTS INTO local saving (library default is memory-only, architecture.md
32
+ * item 14): the /outputs/ routes serve files, grouped per module */
30
33
  const realStarter: ServeStarter = async (mod) => {
31
34
  await mod.dw.host.connect()
32
35
  const wf = await mod.dw.build({ advance: true })
33
- return await wf.start({})
36
+ return await wf.start({ save: { prefix: mod.key } })
34
37
  }
35
38
 
36
39
  const CONTENT_TYPES: Record<string, string> = {
@@ -265,7 +268,7 @@ export class ServeApp {
265
268
 
266
269
  // Accept: image/* → first image's bytes directly (curl -o, <img src>)
267
270
  const first = execution.images[0]
268
- if (req.accept?.includes('image/') && first != null) {
271
+ if (req.accept?.includes('image/') && first?.absPath != null) {
269
272
  const contentType = CONTENT_TYPES[extname(first.absPath).toLowerCase()] ?? 'application/octet-stream'
270
273
  return { status: 200, contentType, body: new Uint8Array(readFileSync(first.absPath)) }
271
274
  }
@@ -279,7 +282,7 @@ export class ServeApp {
279
282
  seeds,
280
283
  images: execution.images.map((img) => ({
281
284
  filename: img.filename,
282
- url: this.outputUrl(img.absPath),
285
+ url: img.absPath != null ? this.outputUrl(img.absPath) : null,
283
286
  absPath: img.absPath,
284
287
  })),
285
288
  })
@@ -7,6 +7,8 @@ import { imageClipboardCommand } from 'src/cli/tui/imageClipboard.ts'
7
7
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
8
8
  import type { SeedVar } from 'src/vars/ComfyVars.ts'
9
9
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
10
+ import { draftKeyForFile } from 'src/cli/tui/state/DraftsSt.ts'
11
+ import type { AbsolutePath } from 'src/types/index.ts'
10
12
 
11
13
  /** popup body: summary + the head of the copied json (proof of WHAT is in the clipboard) */
12
14
  export function jsonHead(text: string, maxLines: number): string[] {
@@ -43,6 +45,12 @@ export class ExecSt {
43
45
  return this.inFlight > 0
44
46
  }
45
47
 
48
+ /** local save dir for this module's outputs (same key the drafts use) */
49
+ private get saveDirPrefix(): string {
50
+ const cur = this.st.workflows.currentPath
51
+ return cur != null ? draftKeyForFile(cur) : (this.st.wf.spec.id ?? 'workflow')
52
+ }
53
+
46
54
  /** workflow switch: wipe run artifacts, keep a hello notice */
47
55
  resetForWorkflow(notice: string): void {
48
56
  this.outputs = []
@@ -79,15 +87,19 @@ export class ExecSt {
79
87
  try {
80
88
  const execution = await this.st.wf.run({
81
89
  host: this.st.hostOverride ?? undefined,
90
+ // the TUI OPTS INTO local saving (library default is memory-only,
91
+ // item 14): the outputs list and `o` open-in-viewer need files.
92
+ // Outputs group per module under .comfy-ts/outputs/<module>/
93
+ save: { prefix: this.saveDirPrefix },
82
94
  onProgress: (p) => runInAction(() => this.onProgress(p)),
83
95
  })
84
96
  runInAction(() => {
85
- this.outputs = execution.images.map((i) => i.absPath)
97
+ this.outputs = execution.images.map((i) => i.absPath).filter((p): p is AbsolutePath => p != null)
86
98
  this.lastStatus = execution.status
87
99
  this.runCount++
88
100
  })
89
101
  const lastImage = execution.images[execution.images.length - 1]
90
- if (lastImage) void this.st.preview.renderOutput(lastImage.absPath)
102
+ if (lastImage?.absPath != null) void this.st.preview.renderOutput(lastImage.absPath)
91
103
  } catch (e) {
92
104
  runInAction(() => {
93
105
  this.error = extractErrorMessage(e)
@@ -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, PromptRelated_WsMsg[]>()
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 = {