comfy-ts 0.4.0 → 1.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 +385 -255
- package/dist/DefinedWorkflow-BYyu5dK9.js +669 -0
- package/dist/DefinedWorkflow-BYyu5dK9.js.map +1 -0
- package/dist/cli.js +4106 -152
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1560 -333
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7826 -467
- package/dist/index.d.ts +7808 -449
- package/dist/index.js +1550 -333
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-SDSJo1Qf.js → run-tui-DZ22HDHI.js} +631 -657
- package/dist/run-tui-DZ22HDHI.js.map +1 -0
- package/examples/01-txt2img.cflow.ts +50 -0
- package/examples/02-img2img-upload.cflow.ts +55 -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 +51 -0
- package/examples/README.md +30 -0
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/cloudHost.ts +41 -0
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
- package/examples/comfy-cloud/sdk.d.ts +123062 -0
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
- package/examples/images/README.md +18 -0
- package/examples/images/bear_1024x1024.jpg +0 -0
- package/examples/images/deer_768x1344.jpg +0 -0
- package/examples/images/dog_512x512.jpg +0 -0
- package/examples/images/lioness_768x768.jpg +0 -0
- package/examples/images/pug_200x300.jpg +0 -0
- package/examples/images/walrus_1344x768.jpg +0 -0
- package/guide-for-agents.md +172 -0
- package/package.json +20 -4
- package/src/cli/comfy-ts-cli.ts +19 -2
- package/src/cli/gen.ts +21 -12
- package/src/cli/tui/components/PreviewPanel.tsx +9 -8
- package/src/cli/tui/components/StatusBar.tsx +11 -0
- package/src/cli/tui/components/TreePanel.tsx +15 -2
- package/src/cli/tui/components/TuiApp.tsx +18 -0
- package/src/cli/tui/discoverWorkflows.ts +45 -0
- package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
- package/src/cli/tui/imagePicker/fsListing.ts +46 -0
- package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
- package/src/cli/tui/run-tui.tsx +52 -23
- package/src/cli/tui/state/HostSt.ts +2 -3
- package/src/cli/tui/state/LorasSt.ts +14 -36
- package/src/cli/tui/state/PreviewSt.ts +28 -2
- 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 +15 -1
- package/src/exampleAssets.ts +56 -0
- package/src/graph/ComfyNode.ts +4 -1
- package/src/host/ComfyHost.ts +203 -77
- 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 +27 -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/manager/ComfyRegistry.ts +37 -9
- package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
- package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
- package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
- package/src/manager/generated/KnownModel_Base.ts +23 -7
- package/src/manager/generated/KnownModel_FileName.ts +421 -0
- package/src/manager/generated/KnownModel_Name.ts +421 -0
- package/src/manager/generated/KnownModel_SavePath.ts +34 -8
- package/src/manager/generated/KnownModel_Type.ts +18 -14
- package/src/manager/json/alter-list.json +221 -221
- package/src/manager/json/custom-node-list.json +61020 -21946
- package/src/manager/json/extension-node-map.json +81077 -31176
- package/src/manager/json/github-stats.json +29321 -12601
- package/src/manager/json/model-list.json +5935 -4997
- package/src/manager/loaders/parseReport.ts +55 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
- package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
- package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
- package/src/manager/loaders/step4_model-list-loader.ts +25 -36
- package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
- package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
- package/src/manager/script-update-manager.bun.ts +9 -1
- package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
- package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
- package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
- package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
- package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
- package/src/runner/ComfyExecution.ts +4 -5
- package/src/runner/ComfyWorkflow.ts +2 -2
- package/src/runner/wsBinaryFrame.ts +48 -0
- package/src/sdk-generator/ComfySchema.ts +14 -1
- package/src/sdk-generator/Primitives.ts +6 -24
- package/src/sdk-generator/comfy-api-json.ts +3 -1
- package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
- package/src/sdk-generator/inputWidgetKind.ts +196 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
- package/src/state.ts +13 -2
- package/src/vars/ComfyVars.ts +82 -2
- package/src/vars/DefinedWorkflow.ts +7 -2
- package/dist/log-CdfgILde.js +0 -10
- package/dist/log-CdfgILde.js.map +0 -1
- package/dist/run-tui-SDSJo1Qf.js.map +0 -1
- package/src/utils/tryExtracting.ts +0 -41
|
@@ -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,55 @@
|
|
|
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 — activate the `image` var to open the picker (browse, favorites, preview)
|
|
4
|
+
import { asAbsolutePath, ComfyTS, exampleImagePath, MediaImage, 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
|
+
// bundled default input (examples/images/, ships in the tarball) — the TUI picker or argv[2] swap it
|
|
11
|
+
const image = v.image(exampleImagePath('dog_512x512.jpg'))
|
|
12
|
+
|
|
13
|
+
export const img2img = host.defineWorkflow({
|
|
14
|
+
id: 'img2img-upload',
|
|
15
|
+
vars: {
|
|
16
|
+
image,
|
|
17
|
+
prompt: v.text('oil painting of a sunset over the sea'),
|
|
18
|
+
negative: v.text('text, watermark'),
|
|
19
|
+
seed: v.seed(7),
|
|
20
|
+
steps: v.int(20, { min: 1, max: 60 }),
|
|
21
|
+
denoise: v.float(0.65, { min: 0, max: 1 }),
|
|
22
|
+
prefix: v.text('comfy-ts-img2img'),
|
|
23
|
+
},
|
|
24
|
+
// async build: the input image is uploaded (hash-named, deduped) per run
|
|
25
|
+
build: async (b, vars, wf) => {
|
|
26
|
+
const img = new MediaImage({ path: asAbsolutePath(image.absPath()) })
|
|
27
|
+
const loaded = await img.loadInWorkflow_viaLoadImageNode(wf)
|
|
28
|
+
|
|
29
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'SD1.5\\v1-5-pruned-emaonly.ckpt' })
|
|
30
|
+
const samples = b.KSampler({
|
|
31
|
+
model: ckpt,
|
|
32
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt }),
|
|
33
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: vars.negative }),
|
|
34
|
+
latent_image: b.VAEEncode({ pixels: loaded, vae: ckpt }),
|
|
35
|
+
seed: vars.seed,
|
|
36
|
+
steps: vars.steps,
|
|
37
|
+
cfg: 7,
|
|
38
|
+
sampler_name: 'euler',
|
|
39
|
+
scheduler: 'normal',
|
|
40
|
+
denoise: vars.denoise, // 0.65 keeps 35% of the input image
|
|
41
|
+
})
|
|
42
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: vars.prefix })
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export default img2img
|
|
47
|
+
|
|
48
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
49
|
+
if (import.meta.main) {
|
|
50
|
+
if (process.argv[2]) img2img.vars.image.set(process.argv[2])
|
|
51
|
+
|
|
52
|
+
const execution = await img2img.run({ log: true })
|
|
53
|
+
for (const out of execution.images) console.log(`🟢 ${out.absPath}`)
|
|
54
|
+
host.disconnect()
|
|
55
|
+
}
|
|
@@ -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,51 @@
|
|
|
1
|
+
// sd15 t2i on Comfy Cloud — the reference zoo example (agent/examples.md)
|
|
2
|
+
// source template: default.json (official workflow-templates)
|
|
3
|
+
// needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers) — loads fine without, run() needs it
|
|
4
|
+
// run directly: bun examples/05-comfy-cloud.cflow.ts ["prompt"] [seed]
|
|
5
|
+
import { v } from 'comfy-ts'
|
|
6
|
+
import { cloudHost, requireCloudKey } from './comfy-cloud/cloudHost.ts'
|
|
7
|
+
|
|
8
|
+
const host = await cloudHost()
|
|
9
|
+
|
|
10
|
+
export const sd15T2i = host.defineWorkflow({
|
|
11
|
+
id: 'sd15-t2i',
|
|
12
|
+
vars: {
|
|
13
|
+
// ONE prompt var: `- ` lines are the NEGATIVE prompt, `//` lines are comments
|
|
14
|
+
prompt: v.prompt('a lighthouse on a cliff at dusk, dramatic clouds\n- blurry, low quality'),
|
|
15
|
+
seed: v.seed(42),
|
|
16
|
+
steps: v.int(12, { min: 1, max: 60 }),
|
|
17
|
+
cfg: v.float(7, { min: 0, max: 30 }),
|
|
18
|
+
size: v.size({ width: 512, height: 512 }),
|
|
19
|
+
},
|
|
20
|
+
build: (b, vars) => {
|
|
21
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'v1-5-pruned-emaonly-fp16.safetensors' })
|
|
22
|
+
const samples = b.KSampler({
|
|
23
|
+
model: ckpt,
|
|
24
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt.positive }),
|
|
25
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt.negative }),
|
|
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: vars.cfg,
|
|
30
|
+
sampler_name: 'euler',
|
|
31
|
+
scheduler: 'normal',
|
|
32
|
+
denoise: 1,
|
|
33
|
+
})
|
|
34
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }), filename_prefix: 'comfy-ts-zoo/sd15-t2i' })
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export default sd15T2i
|
|
39
|
+
|
|
40
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
41
|
+
if (import.meta.main) {
|
|
42
|
+
requireCloudKey()
|
|
43
|
+
if (process.argv[2]) sd15T2i.vars.prompt.set(process.argv[2])
|
|
44
|
+
if (process.argv[3]) sd15T2i.vars.seed.set(Number(process.argv[3]))
|
|
45
|
+
|
|
46
|
+
const t0 = Date.now()
|
|
47
|
+
const execution = await sd15T2i.run({ log: true })
|
|
48
|
+
console.log(`🟢 done in ${((Date.now() - t0) / 1000).toFixed(1)}s — ${execution.images.length} image(s):`)
|
|
49
|
+
for (const img of execution.images) console.log(` ${img.absPath} (${img.width}x${img.height})`)
|
|
50
|
+
host.disconnect()
|
|
51
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# comfy-ts examples
|
|
2
|
+
|
|
3
|
+
Every `*.cflow.ts` file here is a runnable workflow module: run it directly
|
|
4
|
+
with bun, or browse them all in the TUI (`bunx comfy-ts tui` lists them under
|
|
5
|
+
"comfy-ts examples", tweak vars, ⌃R to run).
|
|
6
|
+
|
|
7
|
+
## Layout
|
|
8
|
+
|
|
9
|
+
- `01…04-*.cflow.ts` — the didactic sequence against a LOCAL ComfyUI host
|
|
10
|
+
(edit the `comfy.host({...})` line to point at yours, then first run
|
|
11
|
+
generates a typed SDK for it).
|
|
12
|
+
- `05-comfy-cloud.cflow.ts` — the same t2i against [Comfy Cloud]
|
|
13
|
+
(https://cloud.comfy.org): no local GPU needed, the typed catalog ships
|
|
14
|
+
committed at `comfy-cloud/sdk.d.ts`.
|
|
15
|
+
- `comfy-cloud/<family>-<mode>.cflow.ts` — the model zoo: one clean example
|
|
16
|
+
per model family × mode (`t2i`, `i2i`, `t2v`, `i2v`, `t2a`), each mirroring
|
|
17
|
+
an official ComfyUI template (flux, qwen-image, z-image, wan, hidream,
|
|
18
|
+
ace-step, …). All share `comfy-cloud/cloudHost.ts`.
|
|
19
|
+
|
|
20
|
+
## Cloud API key
|
|
21
|
+
|
|
22
|
+
Cloud examples read `COMFY_CLOUD_API_KEY` (create one at cloud.comfy.org,
|
|
23
|
+
paid tiers). Without it everything still loads and typechecks — only `run()`
|
|
24
|
+
needs the key:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
COMFY_CLOUD_API_KEY=… bun examples/05-comfy-cloud.cflow.ts "a fox in the snow" 42
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Cloud runs bill compute to your account — start with a small t2i.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// ace-step t2a on Comfy Cloud — ACE-Step v1 3.5B text to song: style tags + lyrics to a full mp3 track
|
|
2
|
+
// source template: audio_ace_step_1_t2a_song.json (official workflow-templates)
|
|
3
|
+
// needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
|
|
4
|
+
// run directly: bun examples/comfy-cloud/ace-step-t2a.cflow.ts ["prompt"] [seed]
|
|
5
|
+
import { v } from 'comfy-ts'
|
|
6
|
+
import { cloudHost, requireCloudKey } from './cloudHost.ts'
|
|
7
|
+
|
|
8
|
+
const host = await cloudHost()
|
|
9
|
+
|
|
10
|
+
export const aceStepT2a = host.defineWorkflow({
|
|
11
|
+
id: 'ace-step-t2a',
|
|
12
|
+
vars: {
|
|
13
|
+
// ONE prompt var: FIRST line = style tags, remaining lines = lyrics (`//` lines are comments)
|
|
14
|
+
prompt: v.prompt(
|
|
15
|
+
[
|
|
16
|
+
'anime, soft female vocals, kawaii pop, j-pop, childish, piano, guitar, synthesizer, fast, happy, cheerful, lighthearted',
|
|
17
|
+
'',
|
|
18
|
+
'Verse',
|
|
19
|
+
'Neon rain on my screen,',
|
|
20
|
+
'Dreams compile in silver sheen.',
|
|
21
|
+
'No weight, just motion,',
|
|
22
|
+
'I’m plugged into emotion.',
|
|
23
|
+
'',
|
|
24
|
+
'Chorus',
|
|
25
|
+
'Comfy Cloud — breathing light,',
|
|
26
|
+
'Code and color, spark and wire.',
|
|
27
|
+
'Drift through data, feel alive,',
|
|
28
|
+
'In your circuits, I arrive.',
|
|
29
|
+
].join('\n'),
|
|
30
|
+
),
|
|
31
|
+
seed: v.seed(42),
|
|
32
|
+
seconds: v.float(120, { min: 1, max: 1000 }),
|
|
33
|
+
steps: v.int(50, { min: 1, max: 100 }),
|
|
34
|
+
},
|
|
35
|
+
build: (b, vars) => {
|
|
36
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'ace_step_v1_3.5b.safetensors' })
|
|
37
|
+
const [tagsLine, ...lyricLines] = vars.prompt.positive.split('\n')
|
|
38
|
+
const positive = b.TextEncodeAceStepAudio({
|
|
39
|
+
clip: ckpt,
|
|
40
|
+
tags: tagsLine ?? '',
|
|
41
|
+
lyrics: lyricLines.join('\n').trim(),
|
|
42
|
+
lyrics_strength: 0.99,
|
|
43
|
+
})
|
|
44
|
+
const samples = b.KSampler({
|
|
45
|
+
// tonemap CFG on the model keeps high-cfg audio from clipping (template's sampling chain)
|
|
46
|
+
model: b.LatentApplyOperationCFG({
|
|
47
|
+
model: b.ModelSamplingSD3({ model: ckpt, shift: 5 }),
|
|
48
|
+
operation: b.LatentOperationTonemapReinhard({ multiplier: 1 }),
|
|
49
|
+
}),
|
|
50
|
+
positive,
|
|
51
|
+
negative: b.ConditioningZeroOut({ conditioning: positive }),
|
|
52
|
+
latent_image: b.EmptyAceStepLatentAudio({ seconds: vars.seconds, batch_size: 1 }),
|
|
53
|
+
seed: vars.seed,
|
|
54
|
+
steps: vars.steps,
|
|
55
|
+
cfg: 5,
|
|
56
|
+
sampler_name: 'euler',
|
|
57
|
+
scheduler: 'simple',
|
|
58
|
+
denoise: 1,
|
|
59
|
+
})
|
|
60
|
+
b.SaveAudioMP3({
|
|
61
|
+
audio: b.VAEDecodeAudio({ samples, vae: ckpt }),
|
|
62
|
+
filename_prefix: 'comfy-ts-zoo/ace-step-t2a',
|
|
63
|
+
quality: 'V0',
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
export default aceStepT2a
|
|
69
|
+
|
|
70
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
71
|
+
if (import.meta.main) {
|
|
72
|
+
requireCloudKey()
|
|
73
|
+
if (process.argv[2]) aceStepT2a.vars.prompt.set(process.argv[2])
|
|
74
|
+
if (process.argv[3]) aceStepT2a.vars.seed.set(Number(process.argv[3]))
|
|
75
|
+
const execution = await aceStepT2a.run({ log: true })
|
|
76
|
+
// SaveAudio outputs land host side (no auto-download for audio yet)
|
|
77
|
+
console.log(`🟢 ${execution.status}: audio saved on the host under comfy-ts-zoo/ace-step-t2a`)
|
|
78
|
+
host.disconnect()
|
|
79
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// anima t2i on Comfy Cloud — Anima preview 3 (anime UNET, qwen3 text encoder), text to image
|
|
2
|
+
// source template: image_anima_preview.json (official workflow-templates)
|
|
3
|
+
// needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
|
|
4
|
+
// run directly: bun examples/comfy-cloud/anima-t2i.cflow.ts ["prompt"] [seed]
|
|
5
|
+
import { v } from 'comfy-ts'
|
|
6
|
+
import { cloudHost, requireCloudKey } from './cloudHost.ts'
|
|
7
|
+
|
|
8
|
+
const host = await cloudHost()
|
|
9
|
+
|
|
10
|
+
export const animaT2i = host.defineWorkflow({
|
|
11
|
+
id: 'anima-t2i',
|
|
12
|
+
vars: {
|
|
13
|
+
// ONE prompt var: `- ` lines are the NEGATIVE prompt, `//` lines are comments
|
|
14
|
+
prompt: v.prompt(
|
|
15
|
+
'masterpiece, best quality, score_7, safe, anime, close-up of a futuristic cyberpunk robotic eye, a glowing Earth reflected in the pupil, neon accent lighting, sharp line art\n- worst quality, low quality, score_1, score_2, score_3, blurry, jpeg artifacts, sepia',
|
|
16
|
+
),
|
|
17
|
+
seed: v.seed(42),
|
|
18
|
+
steps: v.int(30, { min: 1, max: 60 }),
|
|
19
|
+
cfg: v.float(4, { min: 0, max: 30 }),
|
|
20
|
+
size: v.size({ width: 1024, height: 1024 }),
|
|
21
|
+
},
|
|
22
|
+
build: (b, vars) => {
|
|
23
|
+
const clip = b.CLIPLoader({
|
|
24
|
+
clip_name: 'qwen_3_06b_base.safetensors',
|
|
25
|
+
type: 'stable_diffusion',
|
|
26
|
+
device: 'default',
|
|
27
|
+
})
|
|
28
|
+
const samples = b.KSampler({
|
|
29
|
+
model: b.UNETLoader({ unet_name: 'anima-preview3-base.safetensors', weight_dtype: 'default' }),
|
|
30
|
+
positive: b.CLIPTextEncode({ clip, text: vars.prompt.positive }),
|
|
31
|
+
negative: b.CLIPTextEncode({ clip, text: vars.prompt.negative }),
|
|
32
|
+
latent_image: b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
33
|
+
seed: vars.seed,
|
|
34
|
+
steps: vars.steps,
|
|
35
|
+
cfg: vars.cfg,
|
|
36
|
+
sampler_name: 'er_sde',
|
|
37
|
+
scheduler: 'simple',
|
|
38
|
+
denoise: 1,
|
|
39
|
+
})
|
|
40
|
+
b.SaveImage({
|
|
41
|
+
images: b.VAEDecode({ samples, vae: b.VAELoader({ vae_name: 'qwen_image_vae.safetensors' }) }),
|
|
42
|
+
filename_prefix: 'comfy-ts-zoo/anima-t2i',
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
export default animaT2i
|
|
48
|
+
|
|
49
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
50
|
+
if (import.meta.main) {
|
|
51
|
+
requireCloudKey()
|
|
52
|
+
if (process.argv[2]) animaT2i.vars.prompt.set(process.argv[2])
|
|
53
|
+
if (process.argv[3]) animaT2i.vars.seed.set(Number(process.argv[3]))
|
|
54
|
+
const execution = await animaT2i.run({ log: true })
|
|
55
|
+
for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
|
|
56
|
+
host.disconnect()
|
|
57
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// boogu i2i on Comfy Cloud — Boogu Image Edit 0.1, instruction-driven image editing (qwen3vl text encoder)
|
|
2
|
+
// source template: image_boogu_image_0_1_edit.json (official workflow-templates)
|
|
3
|
+
// needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
|
|
4
|
+
// run directly: bun examples/comfy-cloud/boogu-i2i.cflow.ts [path/to/image.png] ["edit instruction"]
|
|
5
|
+
import { asAbsolutePath, exampleImagePath, MediaImage, v } from 'comfy-ts'
|
|
6
|
+
import { cloudHost, requireCloudKey } from './cloudHost.ts'
|
|
7
|
+
|
|
8
|
+
const host = await cloudHost()
|
|
9
|
+
|
|
10
|
+
// bundled default input (examples/images/, ships in the tarball) — the TUI picker or argv[2] swap it
|
|
11
|
+
const image = v.image(exampleImagePath('bear_1024x1024.jpg'))
|
|
12
|
+
|
|
13
|
+
export const booguI2i = host.defineWorkflow({
|
|
14
|
+
id: 'boogu-i2i',
|
|
15
|
+
vars: {
|
|
16
|
+
image,
|
|
17
|
+
prompt: v.prompt('remove the hat'),
|
|
18
|
+
seed: v.seed(42),
|
|
19
|
+
// template defaults: 25 steps / cfg 3.5, dpmpp_2m + simple sigmas
|
|
20
|
+
steps: v.int(25, { min: 1, max: 60 }),
|
|
21
|
+
cfg: v.float(3.5, { min: 0, max: 30 }),
|
|
22
|
+
},
|
|
23
|
+
// async build: the input image is uploaded (hash-named, deduped) per run
|
|
24
|
+
build: async (b, vars, wf) => {
|
|
25
|
+
const img = new MediaImage({ path: asAbsolutePath(image.absPath()) })
|
|
26
|
+
const loaded = await img.loadInWorkflow_viaLoadImageNode(wf)
|
|
27
|
+
// the encode reads the FULL input image; the ~1MP resize only sizes the empty latent
|
|
28
|
+
const size = b.GetImageSize({
|
|
29
|
+
image: b.ImageScaleToTotalPixels({ image: loaded, upscale_method: 'lanczos', megapixels: 1 }),
|
|
30
|
+
})
|
|
31
|
+
const unet = b.UNETLoader({ unet_name: 'boogu_image_edit_fp8_scaled.safetensors', weight_dtype: 'default' })
|
|
32
|
+
const vae = b.VAELoader({ vae_name: 'ae.safetensors' })
|
|
33
|
+
// ONE encode node carries both branches: prompt + negative_prompt in, positive + negative out
|
|
34
|
+
const encode = b.TextEncodeBooguEdit({
|
|
35
|
+
clip: b.CLIPLoader({ clip_name: 'qwen3vl_8b_fp8_scaled.safetensors', type: 'boogu', device: 'default' }),
|
|
36
|
+
prompt: vars.prompt.positive,
|
|
37
|
+
negative_prompt: vars.prompt.negative,
|
|
38
|
+
vae,
|
|
39
|
+
'images.image_1': loaded.outputs.IMAGE,
|
|
40
|
+
})
|
|
41
|
+
// template wiring kept verbatim: the AuraFlow shift (3.16) applies to the
|
|
42
|
+
// sigmas only — BasicScheduler reads the shifted model, SamplerCustom the raw UNET
|
|
43
|
+
const sampled = b.SamplerCustom({
|
|
44
|
+
model: unet,
|
|
45
|
+
positive: encode.outputs.positive,
|
|
46
|
+
negative: encode.outputs.negative,
|
|
47
|
+
sampler: b.KSamplerSelect({ sampler_name: 'dpmpp_2m' }),
|
|
48
|
+
sigmas: b.BasicScheduler({
|
|
49
|
+
model: b.ModelSamplingAuraFlow({ model: unet, shift: 3.16 }),
|
|
50
|
+
scheduler: 'simple',
|
|
51
|
+
steps: vars.steps,
|
|
52
|
+
denoise: 1,
|
|
53
|
+
}),
|
|
54
|
+
latent_image: b.EmptyLatentImage({ width: size.outputs.width, height: size.outputs.height, batch_size: 1 }),
|
|
55
|
+
add_noise: true,
|
|
56
|
+
noise_seed: vars.seed,
|
|
57
|
+
cfg: vars.cfg,
|
|
58
|
+
})
|
|
59
|
+
b.SaveImage({
|
|
60
|
+
images: b.VAEDecode({ samples: sampled.outputs.output, vae }),
|
|
61
|
+
filename_prefix: 'comfy-ts-zoo/boogu-i2i',
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
export default booguI2i
|
|
67
|
+
|
|
68
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
69
|
+
if (import.meta.main) {
|
|
70
|
+
requireCloudKey()
|
|
71
|
+
if (process.argv[2]) booguI2i.vars.image.set(process.argv[2])
|
|
72
|
+
if (process.argv[3]) booguI2i.vars.prompt.set(process.argv[3])
|
|
73
|
+
const execution = await booguI2i.run({ log: true })
|
|
74
|
+
for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
|
|
75
|
+
host.disconnect()
|
|
76
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// capybara i2i on Comfy Cloud — Capybara v0.1 image edit: the input steers a single-frame i2v pass
|
|
2
|
+
// source template: Image_capybara_v0_1_image_edit.json (official workflow-templates)
|
|
3
|
+
// needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
|
|
4
|
+
// run directly: bun examples/comfy-cloud/capybara-i2i.cflow.ts [path/to/image.png] ["prompt"]
|
|
5
|
+
import { asAbsolutePath, exampleImagePath, MediaImage, v } from 'comfy-ts'
|
|
6
|
+
import { cloudHost, requireCloudKey } from './cloudHost.ts'
|
|
7
|
+
|
|
8
|
+
const host = await cloudHost()
|
|
9
|
+
|
|
10
|
+
// bundled default input (examples/images/, ships in the tarball) — the TUI picker or argv[2] swap it
|
|
11
|
+
const image = v.image(exampleImagePath('bear_1024x1024.jpg'))
|
|
12
|
+
|
|
13
|
+
export const capybaraI2i = host.defineWorkflow({
|
|
14
|
+
id: 'capybara-i2i',
|
|
15
|
+
vars: {
|
|
16
|
+
image,
|
|
17
|
+
// ONE prompt var: `- ` lines are the NEGATIVE prompt, `//` lines are comments
|
|
18
|
+
prompt: v.prompt(
|
|
19
|
+
'Keep the characters and fluttering costumes unchanged, replace the indoor scene with an outdoor grassland setting\n- blurry, low quality, distorted, ugly, watermark, text',
|
|
20
|
+
),
|
|
21
|
+
seed: v.seed(42),
|
|
22
|
+
steps: v.int(20, { min: 1, max: 60 }),
|
|
23
|
+
cfg: v.float(6, { min: 0, max: 30 }),
|
|
24
|
+
},
|
|
25
|
+
// async build: the input image is uploaded (hash-named, deduped) per run
|
|
26
|
+
build: async (b, vars, wf) => {
|
|
27
|
+
const img = new MediaImage({ path: asAbsolutePath(image.absPath()) })
|
|
28
|
+
const loaded = await img.loadInWorkflow_viaLoadImageNode(wf)
|
|
29
|
+
|
|
30
|
+
const model = b.ModelSamplingSD3({
|
|
31
|
+
model: b.UNETLoader({ unet_name: 'capybara_v0.1.safetensors', weight_dtype: 'default' }),
|
|
32
|
+
shift: 7,
|
|
33
|
+
})
|
|
34
|
+
const clip = b.DualCLIPLoader({
|
|
35
|
+
clip_name1: 'qwen_2.5_vl_7b.safetensors',
|
|
36
|
+
clip_name2: 'byt5_small_glyphxl_fp16.safetensors',
|
|
37
|
+
type: 'hunyuan_video_15',
|
|
38
|
+
device: 'default',
|
|
39
|
+
})
|
|
40
|
+
const vae = b.VAELoader({ vae_name: 'hunyuanvideo15_vae_fp16.safetensors' })
|
|
41
|
+
// the edit is a length-1 image-to-video pass: input feeds the packaged
|
|
42
|
+
// conditioning+latent and a clip vision pass (1024 = template's resize target)
|
|
43
|
+
const video = b.HunyuanVideo15ImageToVideo({
|
|
44
|
+
positive: b.CLIPTextEncode({ clip, text: vars.prompt.positive }),
|
|
45
|
+
negative: b.CLIPTextEncode({ clip, text: vars.prompt.negative }),
|
|
46
|
+
vae,
|
|
47
|
+
start_image: loaded,
|
|
48
|
+
clip_vision_output: b.CLIPVisionEncode({
|
|
49
|
+
clip_vision: b.CLIPVisionLoader({ clip_name: 'sigclip_vision_patch14_384.safetensors' }),
|
|
50
|
+
image: loaded,
|
|
51
|
+
crop: 'none',
|
|
52
|
+
}),
|
|
53
|
+
width: 1024,
|
|
54
|
+
height: 1024,
|
|
55
|
+
length: 1,
|
|
56
|
+
batch_size: 1,
|
|
57
|
+
})
|
|
58
|
+
// template's SamplerCustomAdvanced pipeline collapsed to KSampler (euler/simple/cfg survive)
|
|
59
|
+
const samples = b.KSampler({
|
|
60
|
+
model,
|
|
61
|
+
positive: video.outputs.positive,
|
|
62
|
+
negative: video.outputs.negative,
|
|
63
|
+
latent_image: video.outputs.latent,
|
|
64
|
+
seed: vars.seed,
|
|
65
|
+
steps: vars.steps,
|
|
66
|
+
cfg: vars.cfg,
|
|
67
|
+
sampler_name: 'euler',
|
|
68
|
+
scheduler: 'simple',
|
|
69
|
+
denoise: 1,
|
|
70
|
+
})
|
|
71
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae }), filename_prefix: 'comfy-ts-zoo/capybara-i2i' })
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
export default capybaraI2i
|
|
76
|
+
|
|
77
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
78
|
+
if (import.meta.main) {
|
|
79
|
+
requireCloudKey()
|
|
80
|
+
if (process.argv[2]) capybaraI2i.vars.image.set(process.argv[2])
|
|
81
|
+
if (process.argv[3]) capybaraI2i.vars.prompt.set(process.argv[3])
|
|
82
|
+
const execution = await capybaraI2i.run({ log: true })
|
|
83
|
+
for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
|
|
84
|
+
host.disconnect()
|
|
85
|
+
}
|