comfy-ts 0.3.0 → 1.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 +349 -255
- package/dist/DefinedWorkflow-O3ynII3Y.js +598 -0
- package/dist/DefinedWorkflow-O3ynII3Y.js.map +1 -0
- package/dist/cli.js +3969 -128
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1208 -170
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +449 -115
- package/dist/index.d.ts +449 -115
- package/dist/index.js +1200 -171
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-Io8Xea0L.js → run-tui-BFhba_oG.js} +744 -665
- package/dist/run-tui-BFhba_oG.js.map +1 -0
- package/examples/01-txt2img.cflow.ts +50 -0
- package/examples/02-img2img-upload.cflow.ts +66 -0
- package/examples/03-export-workflow-json.cflow.ts +56 -0
- package/examples/04-krea2-turbo-t2i.cflow.ts +125 -0
- package/examples/05-comfy-cloud.cflow.ts +67 -0
- package/examples/comfy-cloud/sdk.d.ts +122674 -0
- package/guide-for-agents.md +166 -0
- package/package.json +7 -3
- package/src/cli/comfy-ts-cli.ts +19 -2
- package/src/cli/gen.ts +21 -12
- package/src/cli/tui/components/Header.tsx +5 -0
- package/src/cli/tui/components/LogsPanel.tsx +23 -0
- package/src/cli/tui/components/PreviewPanel.tsx +52 -7
- package/src/cli/tui/components/StatusBar.tsx +10 -4
- package/src/cli/tui/components/TreePanel.tsx +15 -2
- package/src/cli/tui/components/TuiApp.tsx +26 -3
- package/src/cli/tui/discoverWorkflows.ts +79 -0
- package/src/cli/tui/protocolImagePainter.ts +54 -18
- package/src/cli/tui/run-tui.tsx +55 -24
- package/src/cli/tui/state/ExecSt.ts +4 -1
- package/src/cli/tui/state/HostSt.ts +123 -1
- package/src/cli/tui/state/LogsSt.ts +107 -0
- package/src/cli/tui/state/PreviewSt.ts +173 -23
- package/src/cli/tui/state/SettingsSt.ts +48 -21
- package/src/cli/tui/state/TreeSt.ts +30 -6
- package/src/cli/tui/state/TuiSt.ts +27 -3
- package/src/cli/tui/state/WorkflowsSt.ts +16 -1
- package/src/host/ComfyHost.ts +241 -71
- package/src/host/ComfyManager.ts +10 -9
- package/src/host/ComfyUploader.ts +1 -2
- package/src/host/ResilientWebsocket.ts +3 -1
- package/src/host/hostUrl.ts +59 -0
- package/src/host/loraManagerApi.ts +5 -4
- package/src/index.ts +20 -1
- package/src/litegraph/CanonicalWorkflow.ts +77 -0
- package/src/litegraph/LiteGraphGroup.ts +9 -7
- package/src/litegraph/LiteGraphJSON.ts +34 -13
- package/src/litegraph/LiteGraphLink.ts +32 -2
- package/src/litegraph/LiteGraphNode.ts +18 -33
- package/src/litegraph/LiteGraphNodeInput.ts +10 -8
- package/src/litegraph/LiteGraphNodeOutput.ts +2 -3
- package/src/litegraph/LiteGraphSubgraphDef.ts +74 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +4 -4
- package/src/litegraph/expandSubgraphs.ts +352 -0
- package/src/litegraph/normalizeWorkflow.ts +141 -0
- package/src/runner/ComfyExecution.ts +4 -5
- package/src/runner/ComfyWorkflow.ts +2 -2
- package/src/runner/ComfyWsApi.ts +12 -1
- package/src/runner/wsBinaryFrame.ts +48 -0
- package/src/sdk-generator/Primitives.ts +6 -24
- package/src/sdk-generator/comfy-api-json.ts +3 -1
- package/src/sdk-generator/inputWidgetKind.ts +179 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
- package/src/ssh-host-manager/ssh-manager.ts +0 -15
- package/src/state.ts +13 -2
- package/src/utils/ansi.ts +7 -0
- package/src/utils/mojibake.ts +60 -0
- package/dist/log-CdfgILde.js +0 -10
- package/dist/log-CdfgILde.js.map +0 -1
- package/dist/run-tui-Io8Xea0L.js.map +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// generate an image from text, fully typed against the 'windows-1' host sdk
|
|
2
|
+
// run directly: bun examples/01-txt2img.cflow.ts ["prompt"] [seed]
|
|
3
|
+
// in the TUI: bun run tui (scans **/*.cflow.ts, tweak vars, r to run)
|
|
4
|
+
import { ComfyTS, v } from 'comfy-ts'
|
|
5
|
+
|
|
6
|
+
const comfy = ComfyTS.create()
|
|
7
|
+
const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
|
|
8
|
+
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
9
|
+
|
|
10
|
+
export const txt2img = host.defineWorkflow({
|
|
11
|
+
id: 'txt2img',
|
|
12
|
+
vars: {
|
|
13
|
+
prompt: v.text('a cozy house in a snowy forest, warm windows'),
|
|
14
|
+
negative: v.text('blurry, low quality'),
|
|
15
|
+
seed: v.seed(42),
|
|
16
|
+
steps: v.int(20, { min: 1, max: 60 }),
|
|
17
|
+
cfg: v.float(7, { min: 0, max: 30 }),
|
|
18
|
+
size: v.size({ width: 512, height: 512 }),
|
|
19
|
+
prefix: v.text('comfy-ts-example'),
|
|
20
|
+
},
|
|
21
|
+
build: (b, vars) => {
|
|
22
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'SD1.5\\v1-5-pruned-emaonly.ckpt' })
|
|
23
|
+
const samples = b.KSampler({
|
|
24
|
+
model: ckpt,
|
|
25
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt }),
|
|
26
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: vars.negative }),
|
|
27
|
+
latent_image: b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
28
|
+
seed: vars.seed,
|
|
29
|
+
steps: vars.steps,
|
|
30
|
+
cfg: vars.cfg,
|
|
31
|
+
sampler_name: 'euler',
|
|
32
|
+
scheduler: 'normal',
|
|
33
|
+
denoise: 1,
|
|
34
|
+
})
|
|
35
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: vars.prefix })
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export default txt2img
|
|
40
|
+
|
|
41
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
42
|
+
if (import.meta.main) {
|
|
43
|
+
if (process.argv[2]) txt2img.vars.prompt.set(process.argv[2])
|
|
44
|
+
if (process.argv[3]) txt2img.vars.seed.set(Number(process.argv[3]))
|
|
45
|
+
|
|
46
|
+
const execution = await txt2img.run({ log: true })
|
|
47
|
+
console.log(`🟢 done — ${execution.images.length} image(s):`)
|
|
48
|
+
for (const img of execution.images) console.log(` ${img.absPath} (${img.width}x${img.height})`)
|
|
49
|
+
host.disconnect()
|
|
50
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// upload a local image (hash-named, deduped) and run img2img on it
|
|
2
|
+
// run directly: bun examples/02-img2img-upload.cflow.ts [path/to/image.png]
|
|
3
|
+
// in the TUI: bun run tui — the `image` var is a path; empty = generated placeholder
|
|
4
|
+
import { mkdirSync } from 'node:fs'
|
|
5
|
+
import { asAbsolutePath, ComfyTS, MediaImage, v } from 'comfy-ts'
|
|
6
|
+
import { dirname, resolve } from 'pathe'
|
|
7
|
+
import sharp from 'sharp'
|
|
8
|
+
|
|
9
|
+
const comfy = ComfyTS.create()
|
|
10
|
+
const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
|
|
11
|
+
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
12
|
+
|
|
13
|
+
/** empty path → a generated flat-color placeholder (keeps the example self-contained) */
|
|
14
|
+
async function resolveInputImage(path: string): Promise<string> {
|
|
15
|
+
if (path.trim() !== '') return resolve(path)
|
|
16
|
+
const placeholder = comfy.resolveFromOutput('example-input.png')
|
|
17
|
+
mkdirSync(dirname(placeholder), { recursive: true })
|
|
18
|
+
await sharp({ create: { width: 512, height: 512, channels: 3, background: { r: 210, g: 140, b: 80 } } })
|
|
19
|
+
.png()
|
|
20
|
+
.toFile(placeholder)
|
|
21
|
+
return placeholder
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const img2img = host.defineWorkflow({
|
|
25
|
+
id: 'img2img-upload',
|
|
26
|
+
vars: {
|
|
27
|
+
image: v.text('', 'image path'),
|
|
28
|
+
prompt: v.text('oil painting of a sunset over the sea'),
|
|
29
|
+
negative: v.text('text, watermark'),
|
|
30
|
+
seed: v.seed(7),
|
|
31
|
+
steps: v.int(20, { min: 1, max: 60 }),
|
|
32
|
+
denoise: v.float(0.65, { min: 0, max: 1 }),
|
|
33
|
+
prefix: v.text('comfy-ts-img2img'),
|
|
34
|
+
},
|
|
35
|
+
// async build: the input image is uploaded (hash-named, deduped) per run
|
|
36
|
+
build: async (b, vars, wf) => {
|
|
37
|
+
const img = new MediaImage({ path: asAbsolutePath(await resolveInputImage(vars.image)) })
|
|
38
|
+
const loaded = await img.loadInWorkflow_viaLoadImageNode(wf)
|
|
39
|
+
|
|
40
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'SD1.5\\v1-5-pruned-emaonly.ckpt' })
|
|
41
|
+
const samples = b.KSampler({
|
|
42
|
+
model: ckpt,
|
|
43
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt }),
|
|
44
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: vars.negative }),
|
|
45
|
+
latent_image: b.VAEEncode({ pixels: loaded, vae: ckpt }),
|
|
46
|
+
seed: vars.seed,
|
|
47
|
+
steps: vars.steps,
|
|
48
|
+
cfg: 7,
|
|
49
|
+
sampler_name: 'euler',
|
|
50
|
+
scheduler: 'normal',
|
|
51
|
+
denoise: vars.denoise, // 0.65 keeps 35% of the input image
|
|
52
|
+
})
|
|
53
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: vars.prefix })
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
export default img2img
|
|
58
|
+
|
|
59
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
60
|
+
if (import.meta.main) {
|
|
61
|
+
if (process.argv[2]) img2img.vars.image.set(process.argv[2])
|
|
62
|
+
|
|
63
|
+
const execution = await img2img.run({ log: true })
|
|
64
|
+
for (const out of execution.images) console.log(`🟢 ${out.absPath}`)
|
|
65
|
+
host.disconnect()
|
|
66
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// build a graph OFFLINE (schema from .comfy-ts/ cache) and export both ComfyUI
|
|
2
|
+
// JSON formats: api.json (prompt) + workflow.json (readable litegraph, autolayouted)
|
|
3
|
+
// run directly: bun examples/03-export-workflow-json.cflow.ts (no server needed)
|
|
4
|
+
// in the TUI: bun run tui — r runs it live (PreviewImage), c/C copy the JSONs
|
|
5
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { ComfyTS, 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() // no connection needed
|
|
11
|
+
|
|
12
|
+
export const exportWorkflow = host.defineWorkflow({
|
|
13
|
+
id: 'export-workflow-json',
|
|
14
|
+
vars: {
|
|
15
|
+
prompt: v.text('macro photo of a leaf'),
|
|
16
|
+
seed: v.seed(1),
|
|
17
|
+
steps: v.int(12, { min: 1, max: 60 }),
|
|
18
|
+
size: v.size({ width: 512, height: 512 }),
|
|
19
|
+
},
|
|
20
|
+
build: (b, vars) => {
|
|
21
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'SD1.5\\v1-5-pruned-emaonly.ckpt' })
|
|
22
|
+
const samples = b.KSampler({
|
|
23
|
+
model: ckpt,
|
|
24
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt }),
|
|
25
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: '' }),
|
|
26
|
+
latent_image: b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
27
|
+
seed: vars.seed,
|
|
28
|
+
steps: vars.steps,
|
|
29
|
+
cfg: 6,
|
|
30
|
+
sampler_name: 'euler',
|
|
31
|
+
scheduler: 'normal',
|
|
32
|
+
denoise: 1,
|
|
33
|
+
})
|
|
34
|
+
b.PreviewImage({ images: b.VAEDecode({ samples, vae: ckpt }) })
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export default exportWorkflow
|
|
39
|
+
|
|
40
|
+
// standalone run: write both JSONs offline (skipped when the TUI imports this module)
|
|
41
|
+
if (import.meta.main) {
|
|
42
|
+
mkdirSync(comfy.outputPath, { recursive: true })
|
|
43
|
+
const wf = await exportWorkflow.build()
|
|
44
|
+
|
|
45
|
+
// 1. api.json — what POST /prompt takes
|
|
46
|
+
const apiJson = wf.toApiJson('use_stringified_numbers_only')
|
|
47
|
+
writeFileSync(comfy.resolveFromOutput('example-api.json'), JSON.stringify(apiJson, null, 3))
|
|
48
|
+
|
|
49
|
+
// 2. workflow.json — what the ComfyUI editor opens (autolayouted, readable)
|
|
50
|
+
const workflowJson = await wf.toWorkflowJson()
|
|
51
|
+
writeFileSync(comfy.resolveFromOutput('example-workflow.json'), JSON.stringify(workflowJson, null, 3))
|
|
52
|
+
|
|
53
|
+
console.log(`🟢 wrote ${comfy.resolveFromOutput('example-api.json')}`)
|
|
54
|
+
console.log(`🟢 wrote ${comfy.resolveFromOutput('example-workflow.json')}`)
|
|
55
|
+
console.log(` (drag example-workflow.json into the ComfyUI editor to see the graph)`)
|
|
56
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// krea2 turbo text-to-image, ported from a real production pipeline
|
|
2
|
+
// (rabbits-vs-sheeps "unified"). krea2 turbo UNET + standard LoraLoader chain
|
|
3
|
+
// → KSampler(8 steps, cfg 1) → RMBG cutout → transparent png game sprite.
|
|
4
|
+
//
|
|
5
|
+
// run directly: bun examples/04-krea2-turbo-t2i.cflow.ts ["prompt"] [seed]
|
|
6
|
+
// in the TUI: bun src/cli/comfy-ts-cli.ts tui examples/04-krea2-turbo-t2i.cflow.ts
|
|
7
|
+
// tui browser: bun src/cli/comfy-ts-cli.ts tui examples/ (scans **/*.cflow.ts)
|
|
8
|
+
import { activeLoras, ComfyTS } from 'comfy-ts'
|
|
9
|
+
|
|
10
|
+
const comfy = ComfyTS.create()
|
|
11
|
+
const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
|
|
12
|
+
await host.loadSchemaFromCache() // offline import (lora options come from the cached schema); run() connects lazily
|
|
13
|
+
|
|
14
|
+
export const t2i = host.defineWorkflow({
|
|
15
|
+
id: 'krea2-turbo-t2i',
|
|
16
|
+
// vars as a LAMBDA: it RECEIVES the host-typed `v` (no import), and
|
|
17
|
+
// cross-referencing vars (loras + the prompt that prefixes their
|
|
18
|
+
// keywords) live in one scope, resolved once at define time
|
|
19
|
+
vars: (v) => {
|
|
20
|
+
// multi-select lora stack, DYNAMIC: the regex resolves against the
|
|
21
|
+
// host's loras at define time, fully typed (E_LoraName union) —
|
|
22
|
+
// nothing selected by default, tick/untick + strengths in the TUI
|
|
23
|
+
const loras = v.loras(/krea-?2/i)
|
|
24
|
+
return {
|
|
25
|
+
// v.prompt: `//` lines are comments, `- ` lines are NEGATIVE prompt
|
|
26
|
+
// lines (both stripped from .positive; negatives land in .negative),
|
|
27
|
+
// and the ACTIVE loras' keywords prefix .positive (assigned via ⌃K
|
|
28
|
+
// in the TUI loras overlay, stored in .comfy-ts/lora-keywords.json)
|
|
29
|
+
prompt: v.prompt('top-down, game sprite, spherical sheep', { loraKeywordsFrom: loras }),
|
|
30
|
+
seed: v.seed(517),
|
|
31
|
+
steps: v.int(8, { min: 1, max: 40 }),
|
|
32
|
+
size: v.size({ width: 1024, height: 1024 }),
|
|
33
|
+
removeBg: v.toggle(true, 'remove bg'),
|
|
34
|
+
loras,
|
|
35
|
+
prefix: v.text('krea2-turbo-t2i'),
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
build: (b, vars) => {
|
|
39
|
+
// models
|
|
40
|
+
const unet = b.UNETLoader({ unet_name: 'krea2_turbo_fp8_scaled.safetensors', weight_dtype: 'default' })
|
|
41
|
+
const clipLoader = b.CLIPLoader({
|
|
42
|
+
clip_name: 'qwen3vl_4b_fp8_scaled.safetensors',
|
|
43
|
+
type: 'krea2',
|
|
44
|
+
device: 'default',
|
|
45
|
+
})
|
|
46
|
+
const vae = b.VAELoader({ vae_name: 'qwen_image_vae.safetensors' })
|
|
47
|
+
|
|
48
|
+
// standard LoraLoader chain: one node per active lora, model+clip rethreaded
|
|
49
|
+
let model = unet._MODEL
|
|
50
|
+
let clip = clipLoader._CLIP
|
|
51
|
+
for (const l of activeLoras(vars.loras)) {
|
|
52
|
+
const loaded = b.LoraLoader({
|
|
53
|
+
model,
|
|
54
|
+
clip,
|
|
55
|
+
lora_name: l.lora_name,
|
|
56
|
+
strength_model: l.strength_model,
|
|
57
|
+
strength_clip: l.strength_clip,
|
|
58
|
+
})
|
|
59
|
+
model = loaded._MODEL
|
|
60
|
+
clip = loaded._CLIP
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// prompt → conditioning. `- ` prompt lines arrive in .negative; when
|
|
64
|
+
// there are none, zeroed-out conditioning stays the turbo default
|
|
65
|
+
const positive = b.CLIPTextEncode({ clip, text: vars.prompt.positive })
|
|
66
|
+
const negative =
|
|
67
|
+
vars.prompt.negative === ''
|
|
68
|
+
? b.ConditioningZeroOut({ conditioning: positive })
|
|
69
|
+
: b.CLIPTextEncode({ clip, text: vars.prompt.negative })
|
|
70
|
+
|
|
71
|
+
// size → latent (core node, dims straight from the size var)
|
|
72
|
+
const latent = b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 })
|
|
73
|
+
|
|
74
|
+
// sample + decode
|
|
75
|
+
const samples = b.KSampler({
|
|
76
|
+
model,
|
|
77
|
+
positive,
|
|
78
|
+
negative,
|
|
79
|
+
latent_image: latent,
|
|
80
|
+
seed: vars.seed,
|
|
81
|
+
steps: vars.steps,
|
|
82
|
+
cfg: 1,
|
|
83
|
+
sampler_name: 'euler',
|
|
84
|
+
scheduler: 'simple',
|
|
85
|
+
denoise: 1,
|
|
86
|
+
})
|
|
87
|
+
const image = b.VAEDecode({ samples, vae })
|
|
88
|
+
|
|
89
|
+
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).
|
|
93
|
+
const cutout = b['rmbg.RMBG']({
|
|
94
|
+
image,
|
|
95
|
+
model: 'BEN2',
|
|
96
|
+
sensitivity: 1,
|
|
97
|
+
process_res: 1024,
|
|
98
|
+
mask_blur: 0,
|
|
99
|
+
mask_offset: 0,
|
|
100
|
+
invert_output: false,
|
|
101
|
+
refine_foreground: false,
|
|
102
|
+
background: 'Alpha',
|
|
103
|
+
})
|
|
104
|
+
const rgba = b.JoinImageWithAlpha({
|
|
105
|
+
image: cutout.outputs.IMAGE,
|
|
106
|
+
alpha: b.InvertMask({ mask: cutout.outputs.MASK }),
|
|
107
|
+
})
|
|
108
|
+
b.SaveImage({ images: rgba, filename_prefix: vars.prefix })
|
|
109
|
+
} else {
|
|
110
|
+
b.SaveImage({ images: image, filename_prefix: vars.prefix })
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
export default t2i
|
|
116
|
+
|
|
117
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
118
|
+
if (import.meta.main) {
|
|
119
|
+
if (process.argv[2]) t2i.vars.prompt.set(process.argv[2])
|
|
120
|
+
if (process.argv[3]) t2i.vars.seed.set(Number(process.argv[3]))
|
|
121
|
+
|
|
122
|
+
const execution = await t2i.run({ log: true })
|
|
123
|
+
for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
|
|
124
|
+
host.disconnect()
|
|
125
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// txt2img on Comfy Cloud (https://cloud.comfy.org) — the managed catalog is
|
|
2
|
+
// the same for every account, so its sdk is COMMITTED at examples/comfy-cloud/sdk.d.ts
|
|
3
|
+
// (regenerate deliberately: bun run gen:sdk:cloud)
|
|
4
|
+
// needs COMFY_CLOUD_API_KEY in the env (cloud.comfy.org api key, paid tiers)
|
|
5
|
+
// run directly: COMFY_CLOUD_API_KEY=… bun examples/05-comfy-cloud.cflow.ts ["prompt"] [seed]
|
|
6
|
+
import { ComfyTS, v } from 'comfy-ts'
|
|
7
|
+
|
|
8
|
+
const apiKey = process.env.COMFY_CLOUD_API_KEY
|
|
9
|
+
if (apiKey == null || apiKey === '')
|
|
10
|
+
// the TUI surfaces an import throw as a red ✗ tree row with this message
|
|
11
|
+
throw new Error(
|
|
12
|
+
'[05-comfy-cloud] COMFY_CLOUD_API_KEY is not set — export your Comfy Cloud API key (https://cloud.comfy.org, paid tiers) to load this workflow',
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const comfy = ComfyTS.create()
|
|
16
|
+
const host = comfy.host({
|
|
17
|
+
id: 'comfy-cloud',
|
|
18
|
+
url: 'https://cloud.comfy.org',
|
|
19
|
+
apiKey,
|
|
20
|
+
// the cloud sdk home is the COMMITTED examples/comfy-cloud/sdk.d.ts — a second
|
|
21
|
+
// copy under .comfy-ts/hosts/ would double-declare the globals
|
|
22
|
+
sdkAutoWrite: false,
|
|
23
|
+
})
|
|
24
|
+
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
25
|
+
|
|
26
|
+
export const cloudTxt2img = host.defineWorkflow({
|
|
27
|
+
id: 'cloud-txt2img',
|
|
28
|
+
vars: {
|
|
29
|
+
prompt: v.text('a lighthouse on a cliff at dusk, dramatic clouds'),
|
|
30
|
+
negative: v.text('blurry, low quality'),
|
|
31
|
+
seed: v.seed(42),
|
|
32
|
+
steps: v.int(12, { min: 1, max: 60 }),
|
|
33
|
+
cfg: v.float(7, { min: 0, max: 30 }),
|
|
34
|
+
size: v.size({ width: 512, height: 512 }),
|
|
35
|
+
prefix: v.text('comfy-ts-cloud-example'),
|
|
36
|
+
},
|
|
37
|
+
build: (b, vars) => {
|
|
38
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'v1-5-pruned-emaonly-fp16.safetensors' })
|
|
39
|
+
const samples = b.KSampler({
|
|
40
|
+
model: ckpt,
|
|
41
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt }),
|
|
42
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: vars.negative }),
|
|
43
|
+
latent_image: b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
44
|
+
seed: vars.seed,
|
|
45
|
+
steps: vars.steps,
|
|
46
|
+
cfg: vars.cfg,
|
|
47
|
+
sampler_name: 'euler',
|
|
48
|
+
scheduler: 'normal',
|
|
49
|
+
denoise: 1,
|
|
50
|
+
})
|
|
51
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: vars.prefix })
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
export default cloudTxt2img
|
|
56
|
+
|
|
57
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
58
|
+
if (import.meta.main) {
|
|
59
|
+
if (process.argv[2]) cloudTxt2img.vars.prompt.set(process.argv[2])
|
|
60
|
+
if (process.argv[3]) cloudTxt2img.vars.seed.set(Number(process.argv[3]))
|
|
61
|
+
|
|
62
|
+
const t0 = Date.now()
|
|
63
|
+
const execution = await cloudTxt2img.run({ log: true })
|
|
64
|
+
console.log(`🟢 done in ${((Date.now() - t0) / 1000).toFixed(1)}s — ${execution.images.length} image(s):`)
|
|
65
|
+
for (const img of execution.images) console.log(` ${img.absPath} (${img.width}x${img.height})`)
|
|
66
|
+
host.disconnect()
|
|
67
|
+
}
|