comfy-ts 1.3.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.
- package/README.md +106 -6
- package/dist/{DefinedWorkflow-gpknV-5f.js → DefinedWorkflow-CqNE_kgR.js} +67 -14
- package/dist/DefinedWorkflow-CqNE_kgR.js.map +1 -0
- package/dist/{DraftsSt-DmA0jWGl.js → DraftsSt-Da4DZUP7.js} +2 -2
- package/dist/{DraftsSt-DmA0jWGl.js.map → DraftsSt-Da4DZUP7.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.cjs +548 -239
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +164 -116
- package/dist/index.d.ts +165 -117
- package/dist/index.js +540 -230
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-Bn6yIJB0.js → run-serve-BqeXtf8P.js} +9 -7
- package/dist/run-serve-BqeXtf8P.js.map +1 -0
- package/dist/{run-tui-BtjaOXRh.js → run-tui-CiB7TbYv.js} +18 -13
- package/dist/run-tui-CiB7TbYv.js.map +1 -0
- package/dist/{state-DKCPy105.js → state-C1g_B8zR.js} +398 -201
- package/dist/state-C1g_B8zR.js.map +1 -0
- package/dist/web.d.ts +17335 -0
- package/dist/web.js +5715 -0
- package/dist/web.js.map +1 -0
- 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 +78 -0
- package/examples/web/index.html +77 -0
- package/examples/web/serve.ts +42 -0
- package/examples/web/tsconfig.json +15 -0
- package/package.json +8 -2
- package/src/cli/serve/ServeApp.ts +9 -6
- package/src/cli/tui/state/ExecSt.ts +14 -2
- package/src/coreExports.ts +118 -0
- package/src/host/ComfyHost.ts +56 -24
- package/src/host/ResilientWebsocket.ts +93 -47
- package/src/host/hostUrl.ts +2 -1
- package/src/host/loraManagerApi.ts +6 -7
- package/src/index.ts +8 -107
- package/src/manager/loaders/step2_custom-node-list-loader.ts +4 -4
- package/src/manager/loaders/step3_extension-node-map-loader.ts +3 -3
- package/src/manager/loaders/step4_model-list-loader.ts +7 -7
- package/src/manager/loaders/step5_alter-list-loader.ts +2 -2
- package/src/manager/loaders/step6_github-stats-loader.ts +2 -2
- package/src/runner/ComfyExecution.ts +168 -77
- package/src/runner/ComfyWorkflow.ts +25 -3
- package/src/runner/ComfyWsApi.ts +6 -0
- package/src/runner/MediaImage.ts +73 -38
- package/src/runner/ephemeral.ts +21 -0
- package/src/runner/outputPath.ts +2 -2
- package/src/sdk-generator/ComfySchema.ts +2 -2
- package/src/sdk-generator/_pythonModuleToNamespace.ts +3 -0
- package/src/state.ts +13 -9
- package/src/storage/ComfyStorage.ts +144 -0
- package/src/storage/nodeStorage.ts +9 -0
- package/src/types/index.ts +6 -2
- package/src/utils/downloadFile.ts +11 -69
- package/src/utils/hashArrayBuffer.ts +3 -4
- package/src/utils/lazySharp.ts +25 -0
- package/src/utils/sha1.ts +69 -0
- package/src/vars/ComfyVars.ts +5 -6
- package/src/vars/DefinedWorkflow.ts +3 -1
- package/src/vars/loraKeywords.ts +6 -6
- package/src/web.ts +13 -0
- package/dist/DefinedWorkflow-gpknV-5f.js.map +0 -1
- package/dist/run-serve-Bn6yIJB0.js.map +0 -1
- package/dist/run-tui-BtjaOXRh.js.map +0 -1
- package/dist/state-DKCPy105.js.map +0 -1
- package/src/utils/writeFile.ts +0 -16
|
@@ -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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
91
|
-
// alpha, so rejoin the MASK via core JoinImageWithAlpha
|
|
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.
|
|
107
|
+
b.SaveImageWebsocket({ images: rgba })
|
|
109
108
|
} else {
|
|
110
|
-
b.
|
|
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
|
-
|
|
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.
|
|
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
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// comfy-ts/web in a real browser page: connect to a ComfyUI host, build a
|
|
2
|
+
// txt2img graph, run it, show the image — no server between the page and
|
|
3
|
+
// Comfy. The host must allow browser origins:
|
|
4
|
+
// python main.py --enable-cors-header '*'
|
|
5
|
+
// (Comfy Cloud sends no CORS headers today — cloud rides `comfy-ts serve`.)
|
|
6
|
+
import { ComfyTS } from 'comfy-ts/web'
|
|
7
|
+
|
|
8
|
+
const comfy = ComfyTS.create()
|
|
9
|
+
|
|
10
|
+
function el<T extends HTMLElement>(id: string): T {
|
|
11
|
+
const hit = document.getElementById(id)
|
|
12
|
+
if (hit == null) throw new Error(`missing #${id}`)
|
|
13
|
+
return hit as T
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** a LIVE host has whatever nodes it has — resolve or fail loud by name */
|
|
17
|
+
function node<T>(factory: T | undefined, name: string): T {
|
|
18
|
+
if (factory == null) throw new Error(`this host has no ${name} node`)
|
|
19
|
+
return factory
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const status = el<HTMLDivElement>('status')
|
|
23
|
+
const output = el<HTMLImageElement>('output')
|
|
24
|
+
|
|
25
|
+
async function generate(): Promise<void> {
|
|
26
|
+
const url = el<HTMLInputElement>('host').value.trim()
|
|
27
|
+
const prompt = el<HTMLTextAreaElement>('prompt').value
|
|
28
|
+
const ckptName = el<HTMLInputElement>('ckpt').value.trim()
|
|
29
|
+
status.textContent = 'connecting…'
|
|
30
|
+
try {
|
|
31
|
+
// one host per url; re-clicking with the same url reuses the connection
|
|
32
|
+
const host = comfy.host({ id: `web-${url}`, url })
|
|
33
|
+
await host.connect()
|
|
34
|
+
|
|
35
|
+
const wf = host.workflow()
|
|
36
|
+
const b = wf.builderBase
|
|
37
|
+
const ckpt = node(b.CheckpointLoaderSimple, 'CheckpointLoaderSimple')({ ckpt_name: ckptName })
|
|
38
|
+
const latent = node(b.EmptyLatentImage, 'EmptyLatentImage')({ width: 512, height: 512, batch_size: 1 })
|
|
39
|
+
const sampled = node(
|
|
40
|
+
b.KSampler,
|
|
41
|
+
'KSampler',
|
|
42
|
+
)({
|
|
43
|
+
model: ckpt,
|
|
44
|
+
positive: node(b.CLIPTextEncode, 'CLIPTextEncode')({ clip: ckpt, text: prompt }),
|
|
45
|
+
negative: node(b.CLIPTextEncode, 'CLIPTextEncode')({ clip: ckpt, text: 'blurry, low quality' }),
|
|
46
|
+
latent_image: latent,
|
|
47
|
+
sampler_name: 'euler',
|
|
48
|
+
scheduler: 'normal',
|
|
49
|
+
seed: Math.floor(Math.random() * 2 ** 32),
|
|
50
|
+
steps: 20,
|
|
51
|
+
cfg: 7,
|
|
52
|
+
denoise: 1,
|
|
53
|
+
})
|
|
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
|
+
})
|
|
62
|
+
|
|
63
|
+
const execution = await wf.run({
|
|
64
|
+
onProgress: (p) => {
|
|
65
|
+
status.textContent = `${p.percent.toFixed(0)}%${p.nodeName ? ` · ${p.nodeName}` : ''}`
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
const img = execution.images[0]
|
|
69
|
+
if (img == null) throw new Error(`no image came back (status: ${execution.status})`)
|
|
70
|
+
output.src = URL.createObjectURL(img.getAsBlob())
|
|
71
|
+
status.textContent = `done · ${img.filename}`
|
|
72
|
+
} catch (e) {
|
|
73
|
+
status.textContent = String(e)
|
|
74
|
+
throw e // loud in the console too
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
el<HTMLButtonElement>('generate').onclick = (): void => void generate()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>comfy-ts/web — txt2img in the browser</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: dark;
|
|
10
|
+
}
|
|
11
|
+
body {
|
|
12
|
+
font-family: ui-monospace, monospace;
|
|
13
|
+
max-width: 640px;
|
|
14
|
+
margin: 2rem auto;
|
|
15
|
+
padding: 0 1rem;
|
|
16
|
+
background: #111;
|
|
17
|
+
color: #ddd;
|
|
18
|
+
}
|
|
19
|
+
label {
|
|
20
|
+
display: block;
|
|
21
|
+
margin-top: 0.8rem;
|
|
22
|
+
font-size: 0.8rem;
|
|
23
|
+
opacity: 0.7;
|
|
24
|
+
}
|
|
25
|
+
input,
|
|
26
|
+
textarea {
|
|
27
|
+
width: 100%;
|
|
28
|
+
box-sizing: border-box;
|
|
29
|
+
background: #1a1a1a;
|
|
30
|
+
color: #ddd;
|
|
31
|
+
border: 1px solid #333;
|
|
32
|
+
padding: 0.5rem;
|
|
33
|
+
font: inherit;
|
|
34
|
+
}
|
|
35
|
+
button {
|
|
36
|
+
margin-top: 1rem;
|
|
37
|
+
padding: 0.5rem 1.5rem;
|
|
38
|
+
background: #2a6;
|
|
39
|
+
color: #fff;
|
|
40
|
+
border: 0;
|
|
41
|
+
font: inherit;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
}
|
|
44
|
+
#status {
|
|
45
|
+
margin-top: 0.8rem;
|
|
46
|
+
min-height: 1.2em;
|
|
47
|
+
opacity: 0.8;
|
|
48
|
+
}
|
|
49
|
+
#output {
|
|
50
|
+
margin-top: 1rem;
|
|
51
|
+
max-width: 100%;
|
|
52
|
+
}
|
|
53
|
+
.note {
|
|
54
|
+
font-size: 0.75rem;
|
|
55
|
+
opacity: 0.5;
|
|
56
|
+
margin-top: 1.5rem;
|
|
57
|
+
}
|
|
58
|
+
</style>
|
|
59
|
+
</head>
|
|
60
|
+
<body>
|
|
61
|
+
<h1>comfy-ts/web</h1>
|
|
62
|
+
<label for="host">ComfyUI host (started with <code>--enable-cors-header '*'</code>)</label>
|
|
63
|
+
<input id="host" value="http://127.0.0.1:8188" />
|
|
64
|
+
<label for="ckpt">checkpoint name (as the host knows it)</label>
|
|
65
|
+
<input id="ckpt" value="v1-5-pruned-emaonly.ckpt" />
|
|
66
|
+
<label for="prompt">prompt</label>
|
|
67
|
+
<textarea id="prompt" rows="3">a lighthouse on a cliff, dramatic sky</textarea>
|
|
68
|
+
<button id="generate">generate</button>
|
|
69
|
+
<div id="status"></div>
|
|
70
|
+
<img id="output" alt="" />
|
|
71
|
+
<p class="note">
|
|
72
|
+
Everything runs in this page: comfy-ts/web talks to the host directly (schema fetch, websocket progress, image
|
|
73
|
+
download). Nothing touches disk — the library writes to an in-memory store.
|
|
74
|
+
</p>
|
|
75
|
+
<script type="module" src="./example.js"></script>
|
|
76
|
+
</body>
|
|
77
|
+
</html>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// dev server for the browser example: bundles example.ts with the SAME
|
|
2
|
+
// browser target the guard test enforces, serves it with index.html.
|
|
3
|
+
// bun examples/web/serve.ts → http://127.0.0.1:8290
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { dirname, join } from 'pathe'
|
|
6
|
+
|
|
7
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
const repoRoot = join(here, '../..')
|
|
9
|
+
|
|
10
|
+
const result = await Bun.build({
|
|
11
|
+
entrypoints: [join(here, 'example.ts')],
|
|
12
|
+
target: 'browser',
|
|
13
|
+
minify: false,
|
|
14
|
+
plugins: [
|
|
15
|
+
{
|
|
16
|
+
name: 'repo-paths',
|
|
17
|
+
setup(build) {
|
|
18
|
+
build.onResolve({ filter: /^comfy-ts\/web$/ }, () => ({ path: join(repoRoot, 'src/web.ts') }))
|
|
19
|
+
build.onResolve({ filter: /^src\// }, (args) => ({ path: join(repoRoot, args.path) }))
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
})
|
|
24
|
+
if (!result.success) {
|
|
25
|
+
console.error(result.logs.join('\n'))
|
|
26
|
+
throw new Error('example bundle failed')
|
|
27
|
+
}
|
|
28
|
+
const first = result.outputs[0]
|
|
29
|
+
if (first == null) throw new Error('no bundle output')
|
|
30
|
+
const bundle = await first.text()
|
|
31
|
+
|
|
32
|
+
const server = Bun.serve({
|
|
33
|
+
port: 8290,
|
|
34
|
+
hostname: '127.0.0.1',
|
|
35
|
+
fetch: (req) => {
|
|
36
|
+
const path = new URL(req.url).pathname
|
|
37
|
+
if (path === '/example.js') return new Response(bundle, { headers: { 'content-type': 'text/javascript' } })
|
|
38
|
+
return new Response(Bun.file(join(here, 'index.html')))
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
console.log(`comfy-ts/web example → http://127.0.0.1:${server.port}/`)
|
|
42
|
+
console.log(`point it at a ComfyUI started with: --enable-cors-header '*'`)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
// the ONE dom-typed corner of the repo: the browser example needs document/
|
|
3
|
+
// URL.createObjectURL. src/ stays dom-free by machine (root + lib configs
|
|
4
|
+
// have no dom lib), so a dom global leaking into the library fails there.
|
|
5
|
+
"extends": "../../tsconfig.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
8
|
+
"paths": {
|
|
9
|
+
"src/*": ["../../src/*"],
|
|
10
|
+
"comfy-ts": ["../../src/index.ts"],
|
|
11
|
+
"comfy-ts/web": ["../../src/web.ts"]
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"include": [".", "../../src"]
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comfy-ts",
|
|
3
|
-
"version": "
|
|
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",
|
|
@@ -48,6 +48,12 @@
|
|
|
48
48
|
"default": "./dist/index.cjs"
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
+
"./web": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/web.d.ts",
|
|
54
|
+
"default": "./dist/web.js"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
51
57
|
"./src/*": "./src/*"
|
|
52
58
|
},
|
|
53
59
|
"files": [
|
|
@@ -63,7 +69,7 @@
|
|
|
63
69
|
"build:watch": "tsdown --watch",
|
|
64
70
|
"test": "bun test",
|
|
65
71
|
"test:watch": "bun test --watch",
|
|
66
|
-
"typecheck": "tsc --noEmit",
|
|
72
|
+
"typecheck": "tsc --noEmit && tsc -p examples/web/tsconfig.json",
|
|
67
73
|
"typecheck:lib": "tsc -p tsconfig.lib.json",
|
|
68
74
|
"lint": "oxlint src examples scripts tests",
|
|
69
75
|
"format": "oxfmt src examples scripts tests",
|
|
@@ -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)
|