comfy-ts 1.4.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -6
- package/dist/{DefinedWorkflow-C_QAxKr3.js → DefinedWorkflow-CqNE_kgR.js} +4 -2
- package/dist/{DefinedWorkflow-C_QAxKr3.js.map → DefinedWorkflow-CqNE_kgR.js.map} +1 -1
- package/dist/{DraftsSt-DcOTn0QR.js → DraftsSt-C-gBk9v7.js} +3 -4
- package/dist/DraftsSt-C-gBk9v7.js.map +1 -0
- package/dist/cli.js +3 -3
- package/dist/index.cjs +212 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -77
- package/dist/index.d.ts +72 -77
- package/dist/index.js +212 -66
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-CN0DhrsA.js → run-serve-CnlN_RFH.js} +9 -7
- package/dist/run-serve-CnlN_RFH.js.map +1 -0
- package/dist/{run-tui-bN2hSD5i.js → run-tui-DXI_Jufu.js} +258 -56
- package/dist/run-tui-DXI_Jufu.js.map +1 -0
- package/dist/{state-COlKYipO.js → state-DC5BcG6d.js} +211 -67
- package/dist/state-DC5BcG6d.js.map +1 -0
- package/dist/web.d.ts +72 -77
- package/dist/web.js +212 -66
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/firered-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/lens-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sdk.d.ts +13251 -11458
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +2 -5
- package/examples/rvion/01-txt2img.cflow.ts +5 -3
- package/examples/rvion/02-img2img-upload.cflow.ts +5 -4
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +6 -7
- package/examples/rvion/05-comfy-cloud.cflow.ts +4 -2
- package/examples/rvion/06-qwen-image-edit.cflow.ts +2 -3
- package/examples/web/example.ts +8 -1
- package/package.json +1 -1
- package/src/cli/serve/ServeApp.ts +9 -6
- package/src/cli/tui/components/TuiApp.tsx +4 -5
- package/src/cli/tui/components/VarsPanel.tsx +40 -2
- package/src/cli/tui/imageClipboard.ts +40 -0
- package/src/cli/tui/state/DraftsSt.ts +1 -2
- package/src/cli/tui/state/ExecSt.ts +105 -40
- package/src/cli/tui/state/PreviewSt.ts +12 -11
- package/src/cli/tui/state/SettingsSt.ts +13 -0
- package/src/cli/tui/state/TuiSt.ts +54 -5
- package/src/host/ComfyHost.ts +33 -1
- package/src/runner/ComfyExecution.ts +162 -74
- package/src/runner/ComfyWorkflow.ts +25 -3
- package/src/runner/ComfyWsApi.ts +6 -0
- package/src/runner/MediaImage.ts +58 -11
- package/src/runner/ephemeral.ts +21 -0
- package/src/runner/outputPath.ts +2 -2
- package/src/sdk-generator/_pythonModuleToNamespace.ts +3 -0
- package/src/types/index.ts +6 -2
- package/src/vars/DefinedWorkflow.ts +3 -1
- package/dist/DraftsSt-DcOTn0QR.js.map +0 -1
- package/dist/run-serve-CN0DhrsA.js.map +0 -1
- package/dist/run-tui-bN2hSD5i.js.map +0 -1
- package/dist/state-COlKYipO.js.map +0 -1
|
@@ -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
|
}
|
package/examples/web/example.ts
CHANGED
|
@@ -51,7 +51,14 @@ async function generate(): Promise<void> {
|
|
|
51
51
|
cfg: 7,
|
|
52
52
|
denoise: 1,
|
|
53
53
|
})
|
|
54
|
-
|
|
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.
|
|
3
|
+
"version": "2.1.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
|
})
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Box, Text, useApp, useInput, useStdin } from 'ink'
|
|
2
2
|
import { observer } from 'mobx-react-lite'
|
|
3
|
-
import { basename } from 'pathe'
|
|
4
3
|
import { CopyOverlay } from 'src/cli/tui/components/CopyOverlay.tsx'
|
|
5
4
|
import { DraftsOverlay } from 'src/cli/tui/components/DraftsOverlay.tsx'
|
|
6
5
|
import { Header } from 'src/cli/tui/components/Header.tsx'
|
|
@@ -291,11 +290,11 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
|
|
|
291
290
|
<Box paddingX={1}>
|
|
292
291
|
<ProgressLine st={s} />
|
|
293
292
|
</Box>
|
|
294
|
-
{s.exec.
|
|
293
|
+
{s.exec.outputLabels.length > 0 && (
|
|
295
294
|
<Box borderStyle="round" paddingX={1} flexDirection="column">
|
|
296
|
-
{s.exec.
|
|
297
|
-
<Text key={o} color=
|
|
298
|
-
{
|
|
295
|
+
{s.exec.outputLabels.map((o, ix) => (
|
|
296
|
+
<Text key={`${ix}-${o.name}`} color={o.memory ? 'yellow' : 'green'} wrap="truncate">
|
|
297
|
+
{o.name} <Text color="gray">{o.detail}</Text>
|
|
299
298
|
</Text>
|
|
300
299
|
))}
|
|
301
300
|
</Box>
|
|
@@ -79,7 +79,8 @@ const VarRow = observer(
|
|
|
79
79
|
export const VarsPanel = observer((p: { st: TuiSt }) => {
|
|
80
80
|
const s = p.st
|
|
81
81
|
// label column = longest label + marker, so [kind] and values line up
|
|
82
|
-
|
|
82
|
+
// ('save to disk'.length covers the TUI-owned last row)
|
|
83
|
+
const labelW = Math.max(12, ...s.entries.map(([name, v]) => (v.label ?? name).length)) + 3
|
|
83
84
|
const focused = s.mode === 'nav' || s.mode === 'edit'
|
|
84
85
|
const boxRef = useRef<DOMElement>(null)
|
|
85
86
|
useEffect(() => {
|
|
@@ -102,7 +103,7 @@ export const VarsPanel = observer((p: { st: TuiSt }) => {
|
|
|
102
103
|
</Text>
|
|
103
104
|
</Box>
|
|
104
105
|
{w.moreAbove && <Text color="gray">…</Text>}
|
|
105
|
-
{s.entries.slice(w.start, w.end).map(([name, varDef], sliceIx) => (
|
|
106
|
+
{s.entries.slice(w.start, Math.min(w.end, s.entries.length)).map(([name, varDef], sliceIx) => (
|
|
106
107
|
<VarRow
|
|
107
108
|
key={name}
|
|
108
109
|
name={name}
|
|
@@ -113,6 +114,43 @@ export const VarsPanel = observer((p: { st: TuiSt }) => {
|
|
|
113
114
|
compact={s.varsCompact}
|
|
114
115
|
/>
|
|
115
116
|
))}
|
|
117
|
+
{/* the TUI-owned save rows ride the vars list as its last rows (item 14) */}
|
|
118
|
+
{w.end > s.entries.length && (
|
|
119
|
+
<Box flexDirection="row">
|
|
120
|
+
<Box width={labelW} flexShrink={0}>
|
|
121
|
+
<Text inverse={s.onSaveRow}>
|
|
122
|
+
{s.onSaveRow ? '▸ ' : ' '}
|
|
123
|
+
save to disk
|
|
124
|
+
</Text>
|
|
125
|
+
</Box>
|
|
126
|
+
<Box width={9} flexShrink={0}>
|
|
127
|
+
<Text color="gray">[tui]</Text>
|
|
128
|
+
</Box>
|
|
129
|
+
<Box flexGrow={1}>
|
|
130
|
+
<Text color={s.settings.saveToDisk ? 'cyan' : 'yellow'} wrap="truncate">
|
|
131
|
+
{s.settings.saveToDisk ? 'on' : 'off — outputs stay in memory'}
|
|
132
|
+
</Text>
|
|
133
|
+
</Box>
|
|
134
|
+
</Box>
|
|
135
|
+
)}
|
|
136
|
+
{s.settings.saveToDisk && w.end > s.entries.length + 1 && (
|
|
137
|
+
<Box flexDirection="row">
|
|
138
|
+
<Box width={labelW} flexShrink={0}>
|
|
139
|
+
<Text inverse={s.onPrefixRow}>
|
|
140
|
+
{s.onPrefixRow ? '▸ ' : ' '}
|
|
141
|
+
save prefix
|
|
142
|
+
</Text>
|
|
143
|
+
</Box>
|
|
144
|
+
<Box width={9} flexShrink={0}>
|
|
145
|
+
<Text color="gray">[tui]</Text>
|
|
146
|
+
</Box>
|
|
147
|
+
<Box flexGrow={1}>
|
|
148
|
+
<Text color="cyan" wrap="truncate">
|
|
149
|
+
.comfy-ts/outputs/{s.savePrefix}/
|
|
150
|
+
</Text>
|
|
151
|
+
</Box>
|
|
152
|
+
</Box>
|
|
153
|
+
)}
|
|
116
154
|
{w.moreBelow && <Text color="gray">…</Text>}
|
|
117
155
|
</Box>
|
|
118
156
|
)
|
|
@@ -7,6 +7,46 @@ const extOf = (path: string): string => {
|
|
|
7
7
|
return dot === -1 ? '' : path.slice(dot + 1).toLowerCase()
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/** platform command that puts PNG bytes on the clipboard from STDIN — no
|
|
11
|
+
* file ever touches disk (his ask 2026-07-31). The caller pipes `stdin`
|
|
12
|
+
* into the spawned process and closes it. */
|
|
13
|
+
export type ImageClipboardStdinCommand = { cmd: string; args: string[]; stdin: Uint8Array }
|
|
14
|
+
|
|
15
|
+
export const imageClipboardStdinCommand = (
|
|
16
|
+
platform: NodeJS.Platform,
|
|
17
|
+
pngBytes: Uint8Array,
|
|
18
|
+
): ImageClipboardStdinCommand => {
|
|
19
|
+
if (platform === 'darwin') {
|
|
20
|
+
// osascript reads the SCRIPT itself from stdin (`-`): a «data PNGf<hex>»
|
|
21
|
+
// literal carries the pixels inside the script — hex doubles the size,
|
|
22
|
+
// so multi-MB images take a beat; the caller falls back to the file
|
|
23
|
+
// command when this exits non-zero
|
|
24
|
+
const hex = Buffer.from(pngBytes).toString('hex').toUpperCase()
|
|
25
|
+
return {
|
|
26
|
+
cmd: 'osascript',
|
|
27
|
+
args: ['-'],
|
|
28
|
+
stdin: new TextEncoder().encode(`set the clipboard to «data PNGf${hex}»`),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (platform === 'win32') {
|
|
32
|
+
// base64 rides stdin; PS rebuilds the image from a MemoryStream — no
|
|
33
|
+
// user-controlled string ever lands in the script (quoting stays trivial)
|
|
34
|
+
const script =
|
|
35
|
+
'$b=[Convert]::FromBase64String([Console]::In.ReadToEnd()); ' +
|
|
36
|
+
'$ms=New-Object System.IO.MemoryStream(,$b); ' +
|
|
37
|
+
'Add-Type -AssemblyName System.Windows.Forms,System.Drawing; ' +
|
|
38
|
+
'$img=[System.Drawing.Image]::FromStream($ms); ' +
|
|
39
|
+
'[System.Windows.Forms.Clipboard]::SetImage($img); $img.Dispose()'
|
|
40
|
+
return {
|
|
41
|
+
cmd: 'powershell',
|
|
42
|
+
args: ['-NoProfile', '-Sta', '-Command', script],
|
|
43
|
+
stdin: new TextEncoder().encode(Buffer.from(pngBytes).toString('base64')),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// xclip reads the image bytes from stdin natively
|
|
47
|
+
return { cmd: 'xclip', args: ['-selection', 'clipboard', '-t', 'image/png'], stdin: pngBytes }
|
|
48
|
+
}
|
|
49
|
+
|
|
10
50
|
export const imageClipboardCommand = (platform: NodeJS.Platform, path: string): ImageClipboardCommand | null => {
|
|
11
51
|
const ext = extOf(path)
|
|
12
52
|
if (platform === 'darwin') {
|
|
@@ -82,8 +82,7 @@ export class DraftsSt {
|
|
|
82
82
|
|
|
83
83
|
/** module key of the currently loaded workflow (settings.lastDraft is keyed by it) */
|
|
84
84
|
private get moduleKey(): string {
|
|
85
|
-
|
|
86
|
-
return cur != null ? draftKeyForFile(cur) : (this.st.wf.spec.id ?? 'workflow')
|
|
85
|
+
return this.st.moduleKey
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
/** switch to a draft: load its stored values when the file exists, else it starts from current values */
|