comfy-ts 2.8.0 → 2.10.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 +6 -4
- package/dist/cli.js +2 -2
- package/dist/index.cjs +10 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-BPw-SZYW.js → run-tui-Atvf9vb3.js} +2 -2
- package/dist/{run-tui-BPw-SZYW.js.map → run-tui-Atvf9vb3.js.map} +1 -1
- package/dist/serve-web.js +26 -17
- package/dist/{state-B-boDz-Z.js → state-6RFDIQwJ.js} +11 -4
- package/dist/state-6RFDIQwJ.js.map +1 -0
- package/dist/web.d.ts +77 -1
- package/dist/web.js +10 -3
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/comfy-cloud/ltx25-i2v.cflow.ts +152 -0
- package/examples/comfy-cloud/ltx25-t2v.cflow.ts +126 -0
- package/examples/comfy-cloud/minimax-music3-t2a.cflow.ts +95 -0
- package/examples/comfy-cloud/sdk.d.ts +30724 -24404
- package/examples/rvion/08-qwen-image-21-t2i.cflow.ts +64 -0
- package/examples/rvion/09-qwen-image-21-edit.cflow.ts +83 -0
- package/package.json +1 -1
- package/src/cli/serve/hostProtocol.ts +68 -0
- package/src/cli/serve/web/components/Gallery.tsx +70 -18
- package/src/cli/serve/web/state/FormSt.ts +8 -1
- package/src/cli/serve/web/state/WebSt.ts +297 -9
- package/src/cli/serve/web/state/host.ts +206 -0
- package/src/cli/serve/web/styles.ts +9 -0
- package/src/graph/ComfyNode.ts +19 -3
- package/src/web.ts +12 -0
- package/dist/state-B-boDz-Z.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// qwen image 2.1 text-to-image on windows-1 — mirrors the official image_qwen_image_2_1_t2i template
|
|
2
|
+
// int8 diffusion model + qwen3-vl 8b text encoder, 25 steps at cfg 1 (the negative only bites once cfg > 1)
|
|
3
|
+
// box inventory: qwen_image_2.1_int8_convrot, qwen3vl_8b_int8_convrot, qwen_image_2.1_vae_bf16 (Comfy-Org/Qwen-Image-2.1), ComfyUI ≥ 0.37
|
|
4
|
+
// run directly: bun examples/rvion/08-qwen-image-21-t2i.cflow.ts ["prompt"] [seed]
|
|
5
|
+
import { ComfyTS, v } from 'comfy-ts'
|
|
6
|
+
|
|
7
|
+
const comfy = ComfyTS.create()
|
|
8
|
+
const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
|
|
9
|
+
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
10
|
+
|
|
11
|
+
export const qwenImage21T2i = host.defineWorkflow({
|
|
12
|
+
id: 'qwen-image-21-t2i',
|
|
13
|
+
vars: {
|
|
14
|
+
// `- ` lines are the negative prompt, `//` lines are comments
|
|
15
|
+
prompt: v.prompt(
|
|
16
|
+
'Greyscale fashion editorial portrait of an avant-garde woman tilted upwards in profile, striking high-contrast chiaroscuro lighting, oversized thick-rimmed circular black sunglasses, a high-necked structural dress in a disrupted optical camouflage pattern of oversized polka dots and pixelated stippling. The background is a vivid mixed-media graphic collage: flat lime green planes, black and white overlapping circles, bold zebra-striped semi-circles, micro-halftone dot matrices. Sharp silhouettes, paper cut-out edges, clean graphic novel textures. No text, no letters, no logos, no watermark.',
|
|
17
|
+
),
|
|
18
|
+
seed: v.seed(42, { mode: '+' }),
|
|
19
|
+
steps: v.int(25, { min: 1, max: 60 }),
|
|
20
|
+
cfg: v.float(1, { min: 1, max: 10 }),
|
|
21
|
+
size: v.size({ width: 1024, height: 1024 }),
|
|
22
|
+
},
|
|
23
|
+
build: (b, vars) => {
|
|
24
|
+
const unet = b.UNETLoader({ unet_name: 'qwen_image_2.1_int8_convrot.safetensors', weight_dtype: 'default' })
|
|
25
|
+
const clip = b.CLIPLoader({
|
|
26
|
+
clip_name: 'qwen3vl_8b_int8_convrot.safetensors',
|
|
27
|
+
type: 'qwen_image',
|
|
28
|
+
device: 'default',
|
|
29
|
+
})
|
|
30
|
+
const vae = b.VAELoader({ vae_name: 'qwen_image_2.1_vae_bf16.safetensors' })
|
|
31
|
+
|
|
32
|
+
const cond = b.TextEncodeQwenImage21({
|
|
33
|
+
clip,
|
|
34
|
+
prompt: vars.prompt.positive,
|
|
35
|
+
negative_prompt: vars.prompt.negative,
|
|
36
|
+
resolution: 1024,
|
|
37
|
+
})
|
|
38
|
+
const samples = b.KSampler({
|
|
39
|
+
model: unet,
|
|
40
|
+
positive: cond.outputs.positive,
|
|
41
|
+
negative: cond.outputs.negative,
|
|
42
|
+
latent_image: b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
43
|
+
seed: vars.seed,
|
|
44
|
+
steps: vars.steps,
|
|
45
|
+
cfg: vars.cfg,
|
|
46
|
+
sampler_name: 'euler',
|
|
47
|
+
scheduler: 'simple',
|
|
48
|
+
denoise: 1,
|
|
49
|
+
})
|
|
50
|
+
b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae }) })
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export default qwenImage21T2i
|
|
55
|
+
|
|
56
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
57
|
+
if (import.meta.main) {
|
|
58
|
+
if (process.argv[2]) qwenImage21T2i.vars.prompt.set(process.argv[2])
|
|
59
|
+
if (process.argv[3]) qwenImage21T2i.vars.seed.set(Number(process.argv[3]))
|
|
60
|
+
|
|
61
|
+
const execution = await qwenImage21T2i.run({ log: true, save: { prefix: 'comfy-ts-example/qwen-image-21-t2i' } })
|
|
62
|
+
for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
|
|
63
|
+
host.disconnect()
|
|
64
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// qwen image 2.1 edit on windows-1 — mirrors the official image_qwen_image_2_1_image_edit template, single reference image
|
|
2
|
+
// the reference is seen by the text encoder AND spliced in as a vae latent; the output keeps the reference's own size
|
|
3
|
+
// the "remove background" preset is the official image_qwen_image_2_1_background_removal template: same graph, that instruction
|
|
4
|
+
// box inventory: qwen_image_2.1_int8_convrot, qwen3vl_8b_int8_convrot, qwen_image_2.1_vae_bf16 (Comfy-Org/Qwen-Image-2.1), ComfyUI ≥ 0.37
|
|
5
|
+
// run directly: bun examples/rvion/09-qwen-image-21-edit.cflow.ts [path/to/image.png] ["edit instruction"]
|
|
6
|
+
import { asAbsolutePath, ComfyTS, exampleImagePath, MediaImage, v } from 'comfy-ts'
|
|
7
|
+
|
|
8
|
+
const comfy = ComfyTS.create()
|
|
9
|
+
const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
|
|
10
|
+
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
11
|
+
|
|
12
|
+
// bundled default input (examples/images/, ships in the tarball) — the TUI picker or argv[2] swap it
|
|
13
|
+
const image = v.image(exampleImagePath('bear_1024x1024.jpg'))
|
|
14
|
+
|
|
15
|
+
export const qwenImage21Edit = host.defineWorkflow({
|
|
16
|
+
id: 'qwen-image-21-edit',
|
|
17
|
+
vars: {
|
|
18
|
+
image,
|
|
19
|
+
// the reference is <image1> in the instruction. `- ` lines are the negative prompt
|
|
20
|
+
prompt: v.prompt(
|
|
21
|
+
'Keep the bear and its pose in <image1> unchanged, wrap a hand-knitted red wool scarf around its neck, realistic wool texture, natural folds, keep the original background and lighting, sharp details',
|
|
22
|
+
{
|
|
23
|
+
presets: {
|
|
24
|
+
'knitted scarf':
|
|
25
|
+
'Keep the bear and its pose in <image1> unchanged, wrap a hand-knitted red wool scarf around its neck, realistic wool texture, natural folds, keep the original background and lighting, sharp details',
|
|
26
|
+
'remove background': 'Remove the background, and output a PNG image',
|
|
27
|
+
watercolor: 'Turn <image1> into a detailed watercolor painting, keep the composition unchanged',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
),
|
|
31
|
+
seed: v.seed(42, { mode: '+' }),
|
|
32
|
+
steps: v.int(25, { min: 1, max: 60 }),
|
|
33
|
+
},
|
|
34
|
+
// async build: the reference image is uploaded (hash-named, deduped) per run
|
|
35
|
+
build: async (b, vars, wf) => {
|
|
36
|
+
const img = new MediaImage({ path: asAbsolutePath(image.absPath()) })
|
|
37
|
+
const loaded = await img.loadInWorkflow_viaLoadImageNode(wf)
|
|
38
|
+
|
|
39
|
+
const unet = b.UNETLoader({ unet_name: 'qwen_image_2.1_int8_convrot.safetensors', weight_dtype: 'default' })
|
|
40
|
+
const clip = b.CLIPLoader({
|
|
41
|
+
clip_name: 'qwen3vl_8b_int8_convrot.safetensors',
|
|
42
|
+
type: 'qwen_image',
|
|
43
|
+
device: 'default',
|
|
44
|
+
})
|
|
45
|
+
const vae = b.VAELoader({ vae_name: 'qwen_image_2.1_vae_bf16.safetensors' })
|
|
46
|
+
|
|
47
|
+
// resolution 0: the reference keeps its own size (rounded to a multiple of 32)
|
|
48
|
+
const cond = b.TextEncodeQwenImage21({
|
|
49
|
+
clip,
|
|
50
|
+
prompt: vars.prompt.positive,
|
|
51
|
+
negative_prompt: vars.prompt.negative,
|
|
52
|
+
resolution: 0,
|
|
53
|
+
'images.image_1': loaded,
|
|
54
|
+
vae,
|
|
55
|
+
})
|
|
56
|
+
const samples = b.KSampler({
|
|
57
|
+
// kv cache of the reference prefix, reused across steps instead of recomputed
|
|
58
|
+
model: b.QwenImage21Cache({ model: unet, device: 'auto', dtype: 'default' }),
|
|
59
|
+
positive: cond.outputs.positive,
|
|
60
|
+
negative: cond.outputs.negative,
|
|
61
|
+
latent_image: cond.outputs.latent,
|
|
62
|
+
seed: vars.seed,
|
|
63
|
+
steps: vars.steps,
|
|
64
|
+
cfg: 1,
|
|
65
|
+
sampler_name: 'euler',
|
|
66
|
+
scheduler: 'simple',
|
|
67
|
+
denoise: 1,
|
|
68
|
+
})
|
|
69
|
+
b.SaveImageWebsocket({ images: b.VAEDecode({ samples, vae }) })
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export default qwenImage21Edit
|
|
74
|
+
|
|
75
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
76
|
+
if (import.meta.main) {
|
|
77
|
+
if (process.argv[2]) qwenImage21Edit.vars.image.set(process.argv[2])
|
|
78
|
+
if (process.argv[3]) qwenImage21Edit.vars.prompt.set(process.argv[3])
|
|
79
|
+
|
|
80
|
+
const execution = await qwenImage21Edit.run({ log: true, save: { prefix: 'comfy-ts-example/qwen-image-21-edit' } })
|
|
81
|
+
for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
|
|
82
|
+
host.disconnect()
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comfy-ts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.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",
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// the serve web panel's HOST PROTOCOL, as types only: what a page embedding the panel in an
|
|
2
|
+
// <iframe> sends and receives over postMessage. No runtime, no DOM, no imports: `comfy-ts/web`
|
|
3
|
+
// re-exports these as types, and the panel's parsers live in src/cli/serve/web/state/host.ts.
|
|
4
|
+
// The contract, message by message, is agent/architecture.md → HOST PROTOCOL.
|
|
5
|
+
|
|
6
|
+
/** a button the host asks the panel to draw on every result */
|
|
7
|
+
export type PanelHostAction = { id: string; label: string; title?: string }
|
|
8
|
+
|
|
9
|
+
/** the host requests that always get exactly one reply: `state` or `error` */
|
|
10
|
+
export type PanelRequest = 'set-selection' | 'set-values' | 'get-state'
|
|
11
|
+
|
|
12
|
+
/** the form as it is now: var name → value in the draft file's shape (seed `{mode,value}`,
|
|
13
|
+
* size `{width,height}`, loras `{name: strength}`). `request` names the host request this
|
|
14
|
+
* answers; absent when the panel volunteers it (a user edit, a user switch, run seeds).
|
|
15
|
+
* `rejected` is on a `set-values` reply only: every name that was NOT applied (no such var,
|
|
16
|
+
* or a value its control cannot produce). Never posted before the host origin is pinned */
|
|
17
|
+
export type PanelState = {
|
|
18
|
+
comfyTs: 'state'
|
|
19
|
+
module: string
|
|
20
|
+
draft: string
|
|
21
|
+
values: Record<string, unknown>
|
|
22
|
+
request?: PanelRequest
|
|
23
|
+
rejected?: string[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** `code: 'boot'` (no `request`): the panel could not boot (index failed, zero workflows, the
|
|
27
|
+
* opening draft unreadable); may go out before the pin. Every other code answers one request:
|
|
28
|
+
* `unknown-module` · `select-failed` · `superseded` · `no-form` */
|
|
29
|
+
export type PanelError =
|
|
30
|
+
| { comfyTs: 'error'; code: 'boot'; message: string }
|
|
31
|
+
| {
|
|
32
|
+
comfyTs: 'error'
|
|
33
|
+
code: 'unknown-module' | 'select-failed' | 'superseded' | 'no-form'
|
|
34
|
+
message: string
|
|
35
|
+
request: PanelRequest
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type PanelResultAction = {
|
|
39
|
+
comfyTs: 'result-action'
|
|
40
|
+
id: string
|
|
41
|
+
promptId: string
|
|
42
|
+
ix: number
|
|
43
|
+
/** the image url, relative to the panel's own origin (`/images/<promptId>/<ix>` or `/outputs/…`) */
|
|
44
|
+
url: string
|
|
45
|
+
filename: string
|
|
46
|
+
module: string
|
|
47
|
+
draft: string
|
|
48
|
+
seeds: Record<string, number>
|
|
49
|
+
/** the prompt var's text at click time, when the form has one */
|
|
50
|
+
prompt: string | null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** panel → host. `selection` is the light subset of `state` (no values), so it may go out
|
|
54
|
+
* before the pin, like `ready` and the boot error */
|
|
55
|
+
export type PanelToHost =
|
|
56
|
+
| { comfyTs: 'ready' }
|
|
57
|
+
| { comfyTs: 'selection'; module: string; draft: string }
|
|
58
|
+
| PanelState
|
|
59
|
+
| PanelError
|
|
60
|
+
| PanelResultAction
|
|
61
|
+
|
|
62
|
+
/** host → panel */
|
|
63
|
+
export type HostToPanel =
|
|
64
|
+
| { comfyTs: 'host-actions'; actions: PanelHostAction[] }
|
|
65
|
+
| { comfyTs: 'set-prompt'; text: string }
|
|
66
|
+
| { comfyTs: 'set-selection'; module: string; draft: string }
|
|
67
|
+
| { comfyTs: 'set-values'; values: Record<string, unknown> }
|
|
68
|
+
| { comfyTs: 'get-state' }
|
|
@@ -166,6 +166,24 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
166
166
|
<a href={box.url} target="_blank" rel="noreferrer">
|
|
167
167
|
open ↗
|
|
168
168
|
</a>
|
|
169
|
+
{box.promptId != null
|
|
170
|
+
? p.st.hostActions.map((a) => {
|
|
171
|
+
const run = p.st.run.results.find((r) => r.promptId === box.promptId)
|
|
172
|
+
const ix = run?.images.findIndex((i) => i.url === box.url) ?? -1
|
|
173
|
+
if (run == null || ix < 0) return null
|
|
174
|
+
return (
|
|
175
|
+
<button
|
|
176
|
+
key={a.id}
|
|
177
|
+
type="button"
|
|
178
|
+
className="host-action"
|
|
179
|
+
data-tip={a.title}
|
|
180
|
+
onClick={() => p.st.postResultAction(a.id, run, { url: box.url, filename: box.title }, ix)}
|
|
181
|
+
>
|
|
182
|
+
{a.label}
|
|
183
|
+
</button>
|
|
184
|
+
)
|
|
185
|
+
})
|
|
186
|
+
: null}
|
|
169
187
|
{box.promptId != null ? (
|
|
170
188
|
<button
|
|
171
189
|
type="button"
|
|
@@ -359,25 +377,59 @@ export const Gallery = observer(function Gallery(p: { st: WebSt; compact?: boole
|
|
|
359
377
|
</button>
|
|
360
378
|
</div>
|
|
361
379
|
<div className="imgs">
|
|
362
|
-
{r.images.map((img) =>
|
|
380
|
+
{r.images.map((img, ix) =>
|
|
363
381
|
img.url != null ? (
|
|
364
|
-
<
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
382
|
+
<div key={img.filename} className="img-cell">
|
|
383
|
+
<button
|
|
384
|
+
type="button"
|
|
385
|
+
className="img-button"
|
|
386
|
+
data-tip={img.filename}
|
|
387
|
+
onClick={() => {
|
|
388
|
+
if (img.url != null)
|
|
389
|
+
local.openLightbox({
|
|
390
|
+
kind: 'image',
|
|
391
|
+
url: img.url,
|
|
392
|
+
title: img.filename,
|
|
393
|
+
promptId: r.promptId,
|
|
394
|
+
})
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
<img src={img.url} alt={img.filename} />
|
|
398
|
+
</button>
|
|
399
|
+
{/* the EMBEDDING page's buttons (host protocol): what it does with the
|
|
400
|
+
image is its business — send it somewhere, keep it as something */}
|
|
401
|
+
{p.st.hostActions.length > 0 ? (
|
|
402
|
+
<div className="host-actions">
|
|
403
|
+
{p.st.hostActions.map((a) => (
|
|
404
|
+
<button
|
|
405
|
+
key={a.id}
|
|
406
|
+
type="button"
|
|
407
|
+
className="host-action"
|
|
408
|
+
data-tip={a.title}
|
|
409
|
+
onClick={() => {
|
|
410
|
+
if (img.url != null)
|
|
411
|
+
p.st.postResultAction(
|
|
412
|
+
a.id,
|
|
413
|
+
r,
|
|
414
|
+
{ url: img.url, filename: img.filename },
|
|
415
|
+
ix,
|
|
416
|
+
)
|
|
417
|
+
}}
|
|
418
|
+
>
|
|
419
|
+
{a.label}
|
|
420
|
+
</button>
|
|
421
|
+
))}
|
|
422
|
+
<button
|
|
423
|
+
type="button"
|
|
424
|
+
className="host-action danger"
|
|
425
|
+
data-tip="remove this result"
|
|
426
|
+
onClick={() => p.st.run.remove(r.promptId)}
|
|
427
|
+
>
|
|
428
|
+
✕
|
|
429
|
+
</button>
|
|
430
|
+
</div>
|
|
431
|
+
) : null}
|
|
432
|
+
</div>
|
|
381
433
|
) : (
|
|
382
434
|
<div key={img.filename} className="noimg">
|
|
383
435
|
{img.filename} (not saved locally — no preview)
|
|
@@ -69,6 +69,9 @@ export class FormSt {
|
|
|
69
69
|
private lastQueued: string
|
|
70
70
|
/** identity of the newest queued write, so a rollback cannot claim someone else's */
|
|
71
71
|
private queueSeq = 0
|
|
72
|
+
/** called on the autosave debounce, right after the save is queued: the embedding host
|
|
73
|
+
* mirrors the form from it (WebSt), one call per settled burst of edits, never per key */
|
|
74
|
+
onSettled: (() => void) | null = null
|
|
72
75
|
|
|
73
76
|
constructor(
|
|
74
77
|
public readonly moduleKey: string,
|
|
@@ -95,12 +98,16 @@ export class FormSt {
|
|
|
95
98
|
lastSaved: false,
|
|
96
99
|
lastQueued: false,
|
|
97
100
|
queueSeq: false,
|
|
101
|
+
onSettled: false,
|
|
98
102
|
})
|
|
99
103
|
// the persistence idiom: the values json is change-detector AND payload
|
|
100
104
|
this.disposers.push(
|
|
101
105
|
reaction(
|
|
102
106
|
() => JSON.stringify(this.valuesJSON()),
|
|
103
|
-
() =>
|
|
107
|
+
() => {
|
|
108
|
+
void this.save()
|
|
109
|
+
this.onSettled?.()
|
|
110
|
+
},
|
|
104
111
|
{ delay: 500 },
|
|
105
112
|
),
|
|
106
113
|
)
|