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,62 @@
|
|
|
1
|
+
// z-image t2i on Comfy Cloud — Z-Image Turbo bf16, 8-step distilled text to image (cfg 1)
|
|
2
|
+
// source template: image_z_image_turbo.json (official workflow-templates)
|
|
3
|
+
// needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
|
|
4
|
+
// run directly: bun examples/comfy-cloud/z-image-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 zImageT2i = host.defineWorkflow({
|
|
11
|
+
id: 'z-image-t2i',
|
|
12
|
+
vars: {
|
|
13
|
+
// ONE prompt var: `- ` lines are the NEGATIVE prompt, `//` lines are comments
|
|
14
|
+
prompt: v.prompt(
|
|
15
|
+
'Latina female with thick wavy hair, harbor boats and pastel houses behind. Breezy seaside light, warm tones, cinematic close-up.',
|
|
16
|
+
),
|
|
17
|
+
seed: v.seed(42),
|
|
18
|
+
steps: v.int(8, { min: 1, max: 40 }),
|
|
19
|
+
size: v.size({ width: 1024, height: 1024 }),
|
|
20
|
+
},
|
|
21
|
+
build: (b, vars) => {
|
|
22
|
+
const model = b.ModelSamplingAuraFlow({
|
|
23
|
+
model: b.UNETLoader({ unet_name: 'z_image_turbo_bf16.safetensors', weight_dtype: 'default' }),
|
|
24
|
+
shift: 3,
|
|
25
|
+
})
|
|
26
|
+
const clip = b.CLIPLoader({ clip_name: 'qwen_3_4b.safetensors', type: 'lumina2', device: 'default' })
|
|
27
|
+
const positive = b.CLIPTextEncode({ clip, text: vars.prompt.positive })
|
|
28
|
+
// turbo distill: no negative lines → zeroed-out conditioning (the template's own default)
|
|
29
|
+
const negative =
|
|
30
|
+
vars.prompt.negative === ''
|
|
31
|
+
? b.ConditioningZeroOut({ conditioning: positive })
|
|
32
|
+
: b.CLIPTextEncode({ clip, text: vars.prompt.negative })
|
|
33
|
+
const samples = b.KSampler({
|
|
34
|
+
model,
|
|
35
|
+
positive,
|
|
36
|
+
negative,
|
|
37
|
+
latent_image: b.EmptySD3LatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
38
|
+
seed: vars.seed,
|
|
39
|
+
steps: vars.steps,
|
|
40
|
+
cfg: 1,
|
|
41
|
+
sampler_name: 'res_multistep',
|
|
42
|
+
scheduler: 'simple',
|
|
43
|
+
denoise: 1,
|
|
44
|
+
})
|
|
45
|
+
b.SaveImage({
|
|
46
|
+
images: b.VAEDecode({ samples, vae: b.VAELoader({ vae_name: 'ae.safetensors' }) }),
|
|
47
|
+
filename_prefix: 'comfy-ts-zoo/z-image-t2i',
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
export default zImageT2i
|
|
53
|
+
|
|
54
|
+
// standalone run (skipped when another driver — e.g. the TUI — imports this module)
|
|
55
|
+
if (import.meta.main) {
|
|
56
|
+
requireCloudKey()
|
|
57
|
+
if (process.argv[2]) zImageT2i.vars.prompt.set(process.argv[2])
|
|
58
|
+
if (process.argv[3]) zImageT2i.vars.seed.set(Number(process.argv[3]))
|
|
59
|
+
const execution = await zImageT2i.run({ log: true })
|
|
60
|
+
for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
|
|
61
|
+
host.disconnect()
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Bundled example input images
|
|
2
|
+
|
|
3
|
+
Default inputs for the i2i/i2v examples — they ship in the npm tarball so
|
|
4
|
+
every example runs out of the box. The exact pixel size is in each filename.
|
|
5
|
+
|
|
6
|
+
Source: [picsum.photos](https://picsum.photos), which serves Unsplash-sourced
|
|
7
|
+
photos, free to use. Fetched and re-encoded (jpeg q80, metadata stripped) by
|
|
8
|
+
`scripts/fetch-example-images.ts` — the manifest in that script is the source
|
|
9
|
+
of truth; regeneration is deliberate (`bun run examples:images`).
|
|
10
|
+
|
|
11
|
+
| file | size | picsum id | author |
|
|
12
|
+
| --------------------- | --------- | ------------------------------------------ | ------------------------------------------------------------ |
|
|
13
|
+
| `dog_512x512.jpg` | 512×512 | [237](https://picsum.photos/id/237/info) | [André Spieker](https://unsplash.com/photos/8wTPqxlnKM4) |
|
|
14
|
+
| `lioness_768x768.jpg` | 768×768 | [1074](https://picsum.photos/id/1074/info) | [Samuel Scrimshaw](https://unsplash.com/photos/sseiVD2XsOk) |
|
|
15
|
+
| `bear_1024x1024.jpg` | 1024×1024 | [433](https://picsum.photos/id/433/info) | [Thomas Lefebvre](https://unsplash.com/photos/aRXPJnXQ9lU) |
|
|
16
|
+
| `walrus_1344x768.jpg` | 1344×768 | [1084](https://picsum.photos/id/1084/info) | [Jay Ruzesky](https://unsplash.com/photos/h13Y8vyIXNU) |
|
|
17
|
+
| `deer_768x1344.jpg` | 768×1344 | [1003](https://picsum.photos/id/1003/info) | [E+N Photographies](https://unsplash.com/photos/GYumuBnTqKc) |
|
|
18
|
+
| `pug_200x300.jpg` | 200×300 | [1025](https://picsum.photos/id/1025/info) | [Matthew Wiebe](https://unsplash.com/photos/U5rMrSI7Pn4) |
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# comfy-ts, guide for coding agents
|
|
2
|
+
|
|
3
|
+
You are working in a project that uses `comfy-ts`, a type-safe ComfyUI
|
|
4
|
+
companion for TypeScript. It connects to one or more ComfyUI hosts, generates
|
|
5
|
+
one typed SDK per host (global `Comfy.<HostNs>.*` namespaces), builds
|
|
6
|
+
workflows in code with full autocomplete, executes them over websocket, and
|
|
7
|
+
downloads the output images. Include this file from the project's CLAUDE.md:
|
|
8
|
+
`@./node_modules/comfy-ts/guide-for-agents.md`.
|
|
9
|
+
|
|
10
|
+
## Setup flow
|
|
11
|
+
|
|
12
|
+
1. Install: `bun add comfy-ts` (npm/pnpm/yarn work too, node >= 20).
|
|
13
|
+
2. Generate the per-host schema cache + typed SDK once per host:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bunx comfy-ts gen --id my-gpu --host http://127.0.0.1:8188
|
|
17
|
+
# writes .comfy-ts/hosts/my-gpu/{object_info.json,embeddings.json,sdk.d.ts}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or skip the CLI: a first `await host.connect()` fetches the schema and
|
|
21
|
+
writes the same files.
|
|
22
|
+
3. Activate the generated types in tsconfig:
|
|
23
|
+
|
|
24
|
+
```jsonc
|
|
25
|
+
{ "include": ["src", ".comfy-ts/hosts/**/sdk.d.ts"] }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
4. Gitignore `.comfy-ts/` entirely. It is local state: host schema dumps
|
|
29
|
+
(often ~10MB, they describe that machine's models and paths), run outputs,
|
|
30
|
+
TUI drafts and settings, lora keywords, preview cache. Everything in it is
|
|
31
|
+
regenerable. (Exception: a private repo may commit `hosts/` to get typed CI.)
|
|
32
|
+
|
|
33
|
+
Before the first codegen the builder falls back to permissive base types, so
|
|
34
|
+
code compiles either way. Types sharpen once a generated sdk.d.ts is in scope.
|
|
35
|
+
|
|
36
|
+
## The workflow pattern: defineWorkflow + vars + build
|
|
37
|
+
|
|
38
|
+
A workflow module is a `*.cflow.ts` file (that suffix is what the TUI scans
|
|
39
|
+
for). Minimal complete example:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { ComfyTS, v } from 'comfy-ts'
|
|
43
|
+
|
|
44
|
+
const comfy = ComfyTS.create()
|
|
45
|
+
const host = comfy.host({ id: 'my-gpu', host: '127.0.0.1', port: 8188 })
|
|
46
|
+
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
47
|
+
|
|
48
|
+
export const txt2img = host.defineWorkflow({
|
|
49
|
+
id: 'txt2img',
|
|
50
|
+
vars: {
|
|
51
|
+
prompt: v.text('a cozy house in a snowy forest'),
|
|
52
|
+
seed: v.seed(42),
|
|
53
|
+
steps: v.int(20, { min: 1, max: 60 }),
|
|
54
|
+
size: v.size({ width: 512, height: 512 }),
|
|
55
|
+
},
|
|
56
|
+
build: (b, vars) => {
|
|
57
|
+
// b is Comfy.MyGpu.Builder: one typed factory per node of THIS host
|
|
58
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'SD1.5\\v1-5-pruned-emaonly.ckpt' })
|
|
59
|
+
const samples = b.KSampler({
|
|
60
|
+
model: ckpt,
|
|
61
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt }),
|
|
62
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: 'blurry, low quality' }),
|
|
63
|
+
latent_image: b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
64
|
+
seed: vars.seed,
|
|
65
|
+
steps: vars.steps,
|
|
66
|
+
cfg: 7,
|
|
67
|
+
sampler_name: 'euler',
|
|
68
|
+
scheduler: 'normal',
|
|
69
|
+
denoise: 1,
|
|
70
|
+
})
|
|
71
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }) })
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
export default txt2img
|
|
76
|
+
|
|
77
|
+
// standalone run, skipped when a driver (the TUI) imports this module
|
|
78
|
+
if (import.meta.main) {
|
|
79
|
+
const execution = await txt2img.run({ log: true })
|
|
80
|
+
for (const img of execution.images) console.log(img.absPath)
|
|
81
|
+
host.disconnect()
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Var kinds: `v.text`, `v.int`, `v.float`, `v.seed`, `v.toggle`, `v.choice`,
|
|
86
|
+
`v.size`, `v.loras`, `v.prompt`, `v.image`. Notes:
|
|
87
|
+
|
|
88
|
+
- `v.loras(/regex/)` resolves against the host's real lora list;
|
|
89
|
+
`activeLoras(vars.loras)` returns `{ lora_name, strength_model, strength_clip }[]`
|
|
90
|
+
for a standard `LoraLoader` chain.
|
|
91
|
+
- `v.prompt` is structured: `//` lines are comments (stripped), `- ` lines go
|
|
92
|
+
to the negative prompt, `{ loraKeywordsFrom: lorasVar }` prefixes lora
|
|
93
|
+
trigger keywords. The value is `{ positive, negative }`.
|
|
94
|
+
- `v.image` holds a local image path as a plain string; an empty value throws
|
|
95
|
+
at build time instead of running a silent placeholder. Capture the var in a
|
|
96
|
+
const and call `image.absPath()` in `build`. Default it to a bundled sample
|
|
97
|
+
with `exampleImagePath('bear_1024x1024.jpg')` (ships in the package). In
|
|
98
|
+
the TUI it opens an image picker (browse, favorite folders, recents,
|
|
99
|
+
preview).
|
|
100
|
+
- `vars` may be a lambda `(v) => ({ ... })` so vars can reference each other.
|
|
101
|
+
- `build` may be async, for uploads: the third param `wf` feeds `MediaImage`
|
|
102
|
+
helpers (`new MediaImage({ path }).loadInWorkflow_viaLoadImageNode(wf)`).
|
|
103
|
+
Uploads are hash-named and deduped, nothing is re-sent.
|
|
104
|
+
|
|
105
|
+
## Running and getting images
|
|
106
|
+
|
|
107
|
+
- `await workflow.run({ log: true })` connects (idempotent, one websocket per
|
|
108
|
+
host), builds a fresh graph from current var values, executes, streams
|
|
109
|
+
progress, and returns a `ComfyExecution`.
|
|
110
|
+
- `execution.images` are downloaded `MediaImage`s: `img.absPath`,
|
|
111
|
+
`img.width`, `img.height`.
|
|
112
|
+
- Tweak then re-run: `workflow.vars.seed.randomize()` or
|
|
113
|
+
`workflow.vars.prompt.set('...')`, then `run()` again.
|
|
114
|
+
- `run({ onProgress })` gives a progress callback instead of console logs.
|
|
115
|
+
- Call `host.disconnect()` at the end of a standalone script or the process
|
|
116
|
+
stays alive on the open websocket.
|
|
117
|
+
|
|
118
|
+
## CLI
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
bunx comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188] # codegen
|
|
122
|
+
bunx comfy-ts outline [file] [--section Name] [--lines N] # inspect a sdk.d.ts
|
|
123
|
+
bunx comfy-ts tui [dir | module.cflow.ts] # interactive tweak & re-run
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The TUI scans `**/*.cflow.ts` (no arg: cwd PLUS the examples bundled with
|
|
127
|
+
the package, grouped apart in the tree; an explicit dir or file limits to
|
|
128
|
+
that scope), shows vars as editable knobs, runs with live progress and
|
|
129
|
+
previews, and saves named drafts under `.comfy-ts/drafts/`. It re-execs
|
|
130
|
+
through bun when launched under node (workflow modules are TypeScript, and
|
|
131
|
+
node cannot import .ts from node_modules). Point users at it; as an agent
|
|
132
|
+
you run modules with `bun path/to/module.cflow.ts`.
|
|
133
|
+
|
|
134
|
+
## Import and export ComfyUI JSON
|
|
135
|
+
|
|
136
|
+
- `host.importApiJson(json)` turns an `api.json` (prompt format) into a
|
|
137
|
+
`ComfyWorkflow`.
|
|
138
|
+
- `host.importWorkflowJson(json)` does the same for a saved `workflow.json`
|
|
139
|
+
(litegraph format, handles muted nodes, Note/Reroute/PrimitiveNode).
|
|
140
|
+
- `wf.toApiJson()` exports the prompt format;
|
|
141
|
+
`await wf.toWorkflowJson()` exports an autolayouted `workflow.json` you can
|
|
142
|
+
drag into the ComfyUI editor. Both work fully offline:
|
|
143
|
+
`const wf = await workflow.build()` never needs a live server.
|
|
144
|
+
|
|
145
|
+
## Gotchas
|
|
146
|
+
|
|
147
|
+
- **Offline cache vs live connect.** `host.loadSchemaFromCache()` reads
|
|
148
|
+
`.comfy-ts/hosts/<id>/` and never touches the network, so modules import
|
|
149
|
+
instantly and offline. `run()` connects lazily. If the cache is missing,
|
|
150
|
+
the import still works: you get the permissive base types plus a loud
|
|
151
|
+
console message; run the `gen` command or `connect()` once to fix it.
|
|
152
|
+
`connect()` reuses a cache
|
|
153
|
+
younger than 24h; `connect({ schema: 'refresh' })` forces a re-fetch.
|
|
154
|
+
- **Per-host namespaces.** Types come from `Comfy.<HostNs>` keyed by the host
|
|
155
|
+
`id` you pass to `comfy.host({ id })` (`my-gpu` becomes `Comfy.MyGpu`). A
|
|
156
|
+
new id has no generated sdk yet, so you silently get permissive base types:
|
|
157
|
+
model names widen to `string` and typos stop being caught. Keep the id
|
|
158
|
+
stable and regenerate after installing custom nodes on the host.
|
|
159
|
+
- **Registries.** `ComfyTS.create()` returns the existing global instance,
|
|
160
|
+
and `comfy.host({ id })` returns the already-registered host for that id.
|
|
161
|
+
Modules can import each other safely in one process.
|
|
162
|
+
- **Seeds.** `v.seed` carries a mode (`+` increment, `-` decrement, `=`
|
|
163
|
+
fixed, `?` reroll) and advances itself after every run, so a batch of runs
|
|
164
|
+
gets distinct seeds by default. When reproducibility matters, pin both the
|
|
165
|
+
mode and the value: `vars.seed.setMode('=')` then `vars.seed.set(N)`.
|
|
166
|
+
`set()` alone keeps the current mode, so a prior `?` would still reroll.
|
|
167
|
+
- **`auto<T>()` slots.** From `import { auto } from 'comfy-ts'`: leave an
|
|
168
|
+
input blank and comfy-ts wires the most recent node producing that type.
|
|
169
|
+
Handy, but implicit; prefer explicit wiring in code meant to be read.
|
|
170
|
+
- **Errors before the server.** Invalid graphs accumulate messages in
|
|
171
|
+
`workflow.problems` before ComfyUI ever sees them. Check it when a run
|
|
172
|
+
misbehaves.
|
package/package.json
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comfy-ts",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
7
|
-
"
|
|
7
|
+
"generative-ai",
|
|
8
8
|
"typescript",
|
|
9
|
+
"type-safe",
|
|
10
|
+
"sdk",
|
|
9
11
|
"codegen",
|
|
10
|
-
"
|
|
12
|
+
"image-generation",
|
|
13
|
+
"video-generation",
|
|
14
|
+
"audio-generation",
|
|
15
|
+
"3d",
|
|
16
|
+
"stable-diffusion",
|
|
17
|
+
"flux",
|
|
18
|
+
"workflow",
|
|
19
|
+
"cli",
|
|
20
|
+
"tui"
|
|
11
21
|
],
|
|
12
22
|
"author": "Rémi Vion <vion.remi@gmail.com>",
|
|
13
23
|
"license": "MIT",
|
|
@@ -42,7 +52,9 @@
|
|
|
42
52
|
"files": [
|
|
43
53
|
"dist",
|
|
44
54
|
"src",
|
|
55
|
+
"examples",
|
|
45
56
|
"README.md",
|
|
57
|
+
"guide-for-agents.md",
|
|
46
58
|
"LICENSE"
|
|
47
59
|
],
|
|
48
60
|
"scripts": {
|
|
@@ -63,7 +75,11 @@
|
|
|
63
75
|
"ci:local": "bun run ci && bun run typecheck",
|
|
64
76
|
"gen:manager": "bun src/manager/script-update-manager.bun.ts",
|
|
65
77
|
"gen:sdk": "bun scripts/gen-sdk-from-cache.ts",
|
|
78
|
+
"gen:sdk:cloud": "bun src/cli/comfy-ts-cli.ts gen --id comfy-cloud --host https://cloud.comfy.org --out examples/comfy-cloud/sdk.d.ts && oxfmt examples/comfy-cloud/sdk.d.ts",
|
|
66
79
|
"sdk:outline": "bun scripts/sdk-outline.ts",
|
|
80
|
+
"examples:images": "bun scripts/fetch-example-images.ts",
|
|
81
|
+
"templates:fetch": "bun scripts/fetch-templates.ts",
|
|
82
|
+
"templates:check": "bun scripts/check-templates.ts",
|
|
67
83
|
"hooks:install": "git config core.hooksPath .githooks",
|
|
68
84
|
"prepublishOnly": "bun run ci && bun run build",
|
|
69
85
|
"tui": "bun src/cli/comfy-ts-cli.ts tui"
|
package/src/cli/comfy-ts-cli.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// sidekick CLI: `bunx comfy-ts <command>` — codegen without writing any code
|
|
3
|
+
import { spawnSync } from 'node:child_process'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
3
5
|
import { runGen } from 'src/cli/gen.ts'
|
|
4
6
|
import { runOutline } from 'src/cli/outline.ts'
|
|
5
7
|
|
|
6
8
|
const HELP = `comfy-ts — typed SDK codegen for ComfyUI
|
|
7
9
|
|
|
8
10
|
Usage:
|
|
9
|
-
comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188]
|
|
11
|
+
comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188] [--api-key <key>] [--out <sdk-path>]
|
|
10
12
|
fetch object_info + embeddings from a live ComfyUI host and write
|
|
11
13
|
.comfy-ts/hosts/<host-id>/{object_info.json,embeddings.json,sdk.d.ts}
|
|
14
|
+
(--api-key or COMFY_CLOUD_API_KEY authenticates via X-API-Key;
|
|
15
|
+
--out relocates ONLY the sdk.d.ts, e.g. a committed cloud catalog)
|
|
12
16
|
|
|
13
17
|
comfy-ts outline [file] [--lines N] [--section Name]
|
|
14
18
|
outline a generated sdk.d.ts (defaults to the first one in .comfy-ts/hosts/)
|
|
15
19
|
|
|
16
20
|
comfy-ts tui [dir | workflow-module.ts]
|
|
17
21
|
interactive tweak & re-run over **/*.cflow.ts modules (exporting
|
|
18
|
-
host.defineWorkflow(...)); no arg scans cwd
|
|
22
|
+
host.defineWorkflow(...)); no arg scans cwd + the examples bundled
|
|
23
|
+
with comfy-ts, an explicit dir/file limits to it (file preselected)
|
|
19
24
|
|
|
20
25
|
comfy-ts help
|
|
21
26
|
`
|
|
@@ -25,6 +30,18 @@ async function main(): Promise<number> {
|
|
|
25
30
|
if (cmd === 'gen') return runGen(rest)
|
|
26
31
|
if (cmd === 'outline') return runOutline(rest)
|
|
27
32
|
if (cmd === 'tui') {
|
|
33
|
+
// .cflow.ts workflow modules need bun: node refuses to strip types under
|
|
34
|
+
// node_modules, exactly where the packaged examples live — and the bin's
|
|
35
|
+
// node shebang means `bunx comfy-ts tui` lands here under NODE. Hop to
|
|
36
|
+
// bun when we are not already in it; without bun, runTui degrades loudly.
|
|
37
|
+
if (process.versions.bun == null) {
|
|
38
|
+
const self = fileURLToPath(import.meta.url)
|
|
39
|
+
const res = spawnSync('bun', [self, 'tui', ...rest], { stdio: 'inherit' })
|
|
40
|
+
if (res.error == null) return res.status ?? 1
|
|
41
|
+
console.error(
|
|
42
|
+
`[comfy-ts tui] bun not found (${res.error.message}) — continuing under node: the examples packaged in node_modules cannot load here, and your own .cflow.ts modules rely on node's type stripping`,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
28
45
|
// lazy import: keeps ink/react out of the codegen paths
|
|
29
46
|
const { runTui } = await import('src/cli/tui/run-tui.tsx')
|
|
30
47
|
return runTui(rest)
|
package/src/cli/gen.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// fetch a live host's schema and generate its typed sdk
|
|
2
2
|
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
3
|
-
import { join } from 'pathe'
|
|
3
|
+
import { dirname, join, resolve } from 'pathe'
|
|
4
4
|
import { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'
|
|
5
5
|
import type { ComfySchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'
|
|
6
|
+
import { ComfyTS } from 'src/state.ts'
|
|
6
7
|
import { readableStringify } from 'src/utils/stringifyReadable.ts'
|
|
7
8
|
|
|
8
9
|
export async function runGen(args: string[]): Promise<number> {
|
|
@@ -17,16 +18,18 @@ export async function runGen(args: string[]): Promise<number> {
|
|
|
17
18
|
return 1
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
//
|
|
21
|
+
// the lib's own authed host.fetch does the /api-first probing + X-API-Key
|
|
22
|
+
const comfy = ComfyTS.create()
|
|
23
|
+
const apiKey = getFlag('api-key') ?? process.env.COMFY_CLOUD_API_KEY
|
|
24
|
+
const host = comfy.host({ id, url: hostUrl, apiKey: apiKey ?? undefined })
|
|
25
|
+
|
|
21
26
|
const fetchJSON = async <T>(route: string): Promise<T> => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
throw new Error(`GET ${route} failed on ${hostUrl} (tried /api${route} and ${route})`)
|
|
27
|
+
console.log(`[comfy-ts gen] fetching ${hostUrl} ${route} …`)
|
|
28
|
+
const res = await host.fetch(route)
|
|
29
|
+
if (!res.ok) throw new Error(`GET ${route} failed on ${hostUrl}: ${res.status}`)
|
|
30
|
+
if (!(res.headers.get('content-type') ?? '').includes('json'))
|
|
31
|
+
throw new Error(`GET ${route} on ${hostUrl} did not answer json`)
|
|
32
|
+
return (await res.json()) as T
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
const spec = await fetchJSON<ComfySchemaJSON>('/object_info')
|
|
@@ -39,9 +42,15 @@ export async function runGen(args: string[]): Promise<number> {
|
|
|
39
42
|
|
|
40
43
|
const parsed = new ComfySchema({ spec, embeddings })
|
|
41
44
|
const dts = parsed.codegenDTS({ hostId: id })
|
|
42
|
-
|
|
45
|
+
// --out: explicit sdk home (the committed cloud catalog) — the json dumps
|
|
46
|
+
// above still cache under .comfy-ts/hosts/<id>/, but the sdk must exist at
|
|
47
|
+
// ONE tsconfig-visible path only, so it skips the hosts dir entirely
|
|
48
|
+
const out = getFlag('out')
|
|
49
|
+
const outPath = out != null ? resolve(process.cwd(), out) : join(dir, 'sdk.d.ts')
|
|
50
|
+
if (out != null) mkdirSync(dirname(outPath), { recursive: true })
|
|
43
51
|
writeFileSync(outPath, dts, 'utf8')
|
|
44
52
|
console.log(`[comfy-ts gen] 🟢 ${outPath} (${parsed.nodes.length} nodes, ${(dts.length / 1024).toFixed(0)}kB)`)
|
|
45
|
-
|
|
53
|
+
if (out == null)
|
|
54
|
+
console.log(`[comfy-ts gen] add ".comfy-ts/hosts/**/sdk.d.ts" to your tsconfig "include" to activate the types`)
|
|
46
55
|
return 0
|
|
47
56
|
}
|
|
@@ -33,26 +33,27 @@ export const PreviewPanel = observer((p: { st: TuiSt }) => {
|
|
|
33
33
|
)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// an overlay owns the vars area (loras / image picker): its slot owns the panel too
|
|
37
|
+
const overlayMode = pv.overlayActive
|
|
37
38
|
const running = s.exec.running
|
|
38
39
|
const wantLatent = running && pv.duringRun !== 'last-output'
|
|
39
|
-
const showLatent = !
|
|
40
|
-
const label =
|
|
41
|
-
?
|
|
40
|
+
const showLatent = !overlayMode && wantLatent && (pv.latentAnsi != null || pv.latentBytes != null)
|
|
41
|
+
const label = overlayMode
|
|
42
|
+
? (pv.overlay?.name ?? (s.mode === 'overlay-loras' ? 'lora' : 'image'))
|
|
42
43
|
: showLatent
|
|
43
44
|
? pv.duringRun === 'latent-small'
|
|
44
45
|
? 'latent small'
|
|
45
46
|
: 'latent'
|
|
46
47
|
: 'output'
|
|
47
|
-
const placeholder =
|
|
48
|
-
? (s.loras
|
|
48
|
+
const placeholder = overlayMode
|
|
49
|
+
? (pv.overlay?.note ?? (s.mode === 'overlay-loras' ? '(pick a lora)' : '(pick an image)'))
|
|
49
50
|
: pv.latentsMissing
|
|
50
51
|
? '(no latents from the server — launch comfy with --preview-method auto)'
|
|
51
52
|
: '(no image yet)'
|
|
52
53
|
const content = pv.useNative
|
|
53
54
|
? null
|
|
54
|
-
:
|
|
55
|
-
?
|
|
55
|
+
: overlayMode
|
|
56
|
+
? (pv.overlay?.ansi ?? null)
|
|
56
57
|
: showLatent
|
|
57
58
|
? (pv.latentAnsi ?? pv.outputAnsi)
|
|
58
59
|
: pv.outputAnsi
|
|
@@ -65,6 +65,7 @@ const KIND_KEYS: Record<string, Hint[]> = {
|
|
|
65
65
|
choice: [['⏎/→', 'pick']],
|
|
66
66
|
size: [['⏎/→', 'pick']],
|
|
67
67
|
loras: [['⏎/→', 'select']],
|
|
68
|
+
image: [['⏎/→', 'browse']],
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
/** shown INSIDE the text editor box (TextOverlay footer), not in the keybar */
|
|
@@ -118,6 +119,16 @@ const MODE_KEYS: Partial<Record<string, Hint[]>> = {
|
|
|
118
119
|
['⌃N', 'none'],
|
|
119
120
|
['esc', 'done'],
|
|
120
121
|
],
|
|
122
|
+
'overlay-image': [
|
|
123
|
+
['⏎', 'pick / enter dir'],
|
|
124
|
+
['←', 'parent'],
|
|
125
|
+
['→', 'enter dir'],
|
|
126
|
+
['tab', 'pane'],
|
|
127
|
+
['↑↓', 'move'],
|
|
128
|
+
['type', 'filter'],
|
|
129
|
+
['⌃F', 'fav folder'],
|
|
130
|
+
['esc', 'cancel'],
|
|
131
|
+
],
|
|
121
132
|
'overlay-drafts': [['⏎', 'load / new'], ...DRAFT_OP_HINTS, ['↑↓', 'move'], ['esc', 'cancel']],
|
|
122
133
|
tree: [['⏎', 'load'], ['↑↓', 'move'], ['←', 'fold'], ['→', 'unfold / vars'], ...DRAFT_OP_HINTS, ['t/esc', 'back']],
|
|
123
134
|
host: [
|
|
@@ -24,12 +24,25 @@ export const TreePanel = observer((p: { st: TuiSt }) => {
|
|
|
24
24
|
</Box>
|
|
25
25
|
{tree.rows.map((row, ix) => {
|
|
26
26
|
const sel = focused && ix === tree.ix
|
|
27
|
+
if (row.kind === 'section') {
|
|
28
|
+
return (
|
|
29
|
+
<Text key={`section·${row.label}`} color="gray" dimColor wrap="truncate">
|
|
30
|
+
─ {row.label}
|
|
31
|
+
</Text>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
27
34
|
if (row.kind === 'workflow') {
|
|
28
35
|
const arrow = row.hasDrafts ? (row.expanded ? '▾' : '▸') : ' '
|
|
36
|
+
const marker = row.error != null ? '✗' : row.current ? '●' : ' '
|
|
29
37
|
return (
|
|
30
|
-
<Text
|
|
38
|
+
<Text
|
|
39
|
+
key={row.file}
|
|
40
|
+
inverse={sel}
|
|
41
|
+
color={row.error != null ? 'red' : row.current ? 'green' : undefined}
|
|
42
|
+
wrap="truncate"
|
|
43
|
+
>
|
|
31
44
|
{arrow}
|
|
32
|
-
{
|
|
45
|
+
{marker} {row.name}
|
|
33
46
|
</Text>
|
|
34
47
|
)
|
|
35
48
|
}
|
|
@@ -9,6 +9,7 @@ import { ChoiceOverlay, SizeOverlay } from 'src/cli/tui/components/PickerOverlay
|
|
|
9
9
|
import { PreviewPanel } from 'src/cli/tui/components/PreviewPanel.tsx'
|
|
10
10
|
import { PromptOverlay } from 'src/cli/tui/components/PromptOverlay.tsx'
|
|
11
11
|
import { KeyBar, ProgressLine } from 'src/cli/tui/components/StatusBar.tsx'
|
|
12
|
+
import { ImagePickerOverlay } from 'src/cli/tui/imagePicker/ImagePickerOverlay.tsx'
|
|
12
13
|
import { LogsPanel } from 'src/cli/tui/components/LogsPanel.tsx'
|
|
13
14
|
import { TextOverlay } from 'src/cli/tui/components/TextOverlay.tsx'
|
|
14
15
|
import { TreePanel } from 'src/cli/tui/components/TreePanel.tsx'
|
|
@@ -97,6 +98,21 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
|
|
|
97
98
|
if (input && !key.ctrl && !key.meta) return lo.filterInput(input)
|
|
98
99
|
return
|
|
99
100
|
}
|
|
101
|
+
if (s.mode === 'overlay-image') {
|
|
102
|
+
const ip = s.imagePicker
|
|
103
|
+
if (key.escape) return ip.cancel()
|
|
104
|
+
if (key.tab || input === '\t') return ip.cyclePane()
|
|
105
|
+
if (key.ctrl && input === 'f') return ip.toggleFavorite()
|
|
106
|
+
if (key.return) return ip.commit()
|
|
107
|
+
if (key.upArrow) return ip.move(-1)
|
|
108
|
+
if (key.downArrow) return ip.move(1)
|
|
109
|
+
if (key.leftArrow) return ip.goParent()
|
|
110
|
+
if (key.rightArrow) return ip.enter()
|
|
111
|
+
if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return ip.filterDeleteWord()
|
|
112
|
+
if (key.backspace || key.delete) return ip.filterBackspace()
|
|
113
|
+
if (input && !key.ctrl && !key.meta) return ip.filterInput(input)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
100
116
|
if (s.mode === 'tree') {
|
|
101
117
|
const tr = s.tree
|
|
102
118
|
if (key.escape || input === 't') return tr.blur()
|
|
@@ -218,6 +234,8 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
|
|
|
218
234
|
<SizeOverlay st={s} />
|
|
219
235
|
) : s.mode === 'overlay-loras' ? (
|
|
220
236
|
<LorasOverlay st={s} />
|
|
237
|
+
) : s.mode === 'overlay-image' ? (
|
|
238
|
+
<ImagePickerOverlay st={s} />
|
|
221
239
|
) : s.mode === 'overlay-drafts' ? (
|
|
222
240
|
<DraftsOverlay st={s} />
|
|
223
241
|
) : (
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readdirSync } from 'node:fs'
|
|
2
|
+
import { join } from 'pathe'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* recursive scan for the workflow-module naming convention. Entries BELOW a
|
|
6
|
+
* node_modules segment are skipped: packaged examples arrive via
|
|
7
|
+
* bundledExamplesDir (src/exampleAssets.ts — symlinked layouts like pnpm would
|
|
8
|
+
* otherwise list them twice, un-deduped, as the user's own files), and
|
|
9
|
+
* third-party packages shipping *.cflow.ts are not this project's workflows. A
|
|
10
|
+
* scan root that is ITSELF inside node_modules still works (the filter is
|
|
11
|
+
* relative to the root).
|
|
12
|
+
*/
|
|
13
|
+
export function scanCflowFiles(dir: string): string[] {
|
|
14
|
+
const hits = readdirSync(dir, { recursive: true })
|
|
15
|
+
.map((f) => String(f))
|
|
16
|
+
.filter((f) => !f.split('/').includes('node_modules'))
|
|
17
|
+
.map((f) => join(dir, f))
|
|
18
|
+
.filter((f) => f.endsWith('.cflow.ts') || f.endsWith('.cflow.tsx'))
|
|
19
|
+
return hits.sort()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type WorkflowDiscovery = {
|
|
23
|
+
/** every module the tree lists, user files first, bundled examples last */
|
|
24
|
+
files: string[]
|
|
25
|
+
/** the subset that came from the PACKAGED examples (grouped apart in the tree) */
|
|
26
|
+
bundled: Set<string>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* PURE merge of the scan with the packaged examples (headless-tested). An
|
|
31
|
+
* explicit target keeps its scope only. Bundled files ALWAYS group under the
|
|
32
|
+
* bundled section, also when the scan already found them (repo dev: ./examples
|
|
33
|
+
* is under cwd) — dedupe relies on the caller passing realpath-normalized
|
|
34
|
+
* strings on both sides.
|
|
35
|
+
*/
|
|
36
|
+
export function mergeWorkflowSources(p: {
|
|
37
|
+
explicitTarget: boolean
|
|
38
|
+
scanned: string[]
|
|
39
|
+
bundledFiles: string[]
|
|
40
|
+
}): WorkflowDiscovery {
|
|
41
|
+
if (p.explicitTarget) return { files: p.scanned, bundled: new Set() }
|
|
42
|
+
const bundled = new Set(p.bundledFiles)
|
|
43
|
+
const userFiles = p.scanned.filter((f) => !bundled.has(f))
|
|
44
|
+
return { files: [...userFiles, ...p.bundledFiles], bundled }
|
|
45
|
+
}
|