comfy-ts 0.2.0 → 0.4.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/LICENSE +21 -0
- package/README.md +363 -0
- package/dist/cli.js +764 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +4171 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9910 -0
- package/dist/index.d.ts +9894 -58
- package/dist/index.js +4092 -2
- package/dist/index.js.map +1 -1
- package/dist/log-CdfgILde.js +10 -0
- package/dist/log-CdfgILde.js.map +1 -0
- package/dist/run-tui-SDSJo1Qf.js +3896 -0
- package/dist/run-tui-SDSJo1Qf.js.map +1 -0
- package/package.json +103 -75
- package/src/cli/comfy-ts-cli.ts +36 -0
- package/src/cli/gen.ts +47 -0
- package/src/cli/outline.ts +82 -0
- package/src/cli/tui/components/DraftsOverlay.tsx +44 -0
- package/src/cli/tui/components/EditField.tsx +27 -0
- package/src/cli/tui/components/Header.tsx +56 -0
- package/src/cli/tui/components/HostPanel.tsx +37 -0
- package/src/cli/tui/components/LogsPanel.tsx +23 -0
- package/src/cli/tui/components/LorasOverlay.tsx +49 -0
- package/src/cli/tui/components/OverlayList.tsx +25 -0
- package/src/cli/tui/components/PickerOverlays.tsx +66 -0
- package/src/cli/tui/components/PreviewPanel.tsx +78 -0
- package/src/cli/tui/components/PromptOverlay.tsx +16 -0
- package/src/cli/tui/components/StatusBar.tsx +171 -0
- package/src/cli/tui/components/TextOverlay.tsx +72 -0
- package/src/cli/tui/components/TreePanel.tsx +51 -0
- package/src/cli/tui/components/TuiApp.tsx +246 -0
- package/src/cli/tui/components/VarsPanel.tsx +86 -0
- package/src/cli/tui/findDefinedWorkflow.ts +16 -0
- package/src/cli/tui/keys.ts +20 -0
- package/src/cli/tui/protocolImagePainter.ts +95 -0
- package/src/cli/tui/run-tui.tsx +76 -0
- package/src/cli/tui/state/DraftsSt.ts +273 -0
- package/src/cli/tui/state/EditorSt.ts +289 -0
- package/src/cli/tui/state/ExecSt.ts +173 -0
- package/src/cli/tui/state/HostSt.ts +230 -0
- package/src/cli/tui/state/LogsSt.ts +107 -0
- package/src/cli/tui/state/LorasSt.ts +185 -0
- package/src/cli/tui/state/PickerSt.ts +112 -0
- package/src/cli/tui/state/PreviewSt.ts +288 -0
- package/src/cli/tui/state/QueueSt.ts +59 -0
- package/src/cli/tui/state/SettingsSt.ts +100 -0
- package/src/cli/tui/state/TreeSt.ts +122 -0
- package/src/cli/tui/state/TuiSt.ts +175 -0
- package/src/cli/tui/state/WorkflowsSt.ts +93 -0
- package/src/cli/tui-env.ts +8 -0
- package/src/errors/InvalidPromptError.ts +12 -0
- package/src/graph/ComfyNode.ts +403 -0
- package/src/graph/ComfyNodeID.ts +28 -0
- package/src/graph/ComfyNodeOutput.ts +16 -0
- package/src/graph/NodeSlotSize.ts +4 -0
- package/src/graph/autoValue.ts +17 -0
- package/src/host/ComfyHost.ts +690 -0
- package/src/host/ComfyInstallType.ts +15 -0
- package/src/host/ComfyManager.ts +232 -0
- package/src/host/ComfyUploader.ts +110 -0
- package/src/host/ComfyWorkflowBuilder.ts +60 -0
- package/src/host/Requirements.ts +55 -0
- package/src/host/ResilientWebsocket.ts +147 -0
- package/src/host/loraManagerApi.ts +98 -0
- package/src/image-utils/_getPngMetadata.ts +53 -0
- package/src/image-utils/_getWebpMetadata.ts +38 -0
- package/src/image-utils/_parseExifData.ts +53 -0
- package/src/index.ts +89 -0
- package/src/litegraph/LiteGraphGroup.ts +22 -0
- package/src/litegraph/LiteGraphJSON.ts +46 -0
- package/src/litegraph/LiteGraphLink.ts +23 -0
- package/src/litegraph/LiteGraphLinkID.ts +6 -0
- package/src/litegraph/LiteGraphNode.ts +69 -0
- package/src/litegraph/LiteGraphNodeInput.ts +27 -0
- package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
- package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
- package/src/manager/ComfyRegistry.ts +124 -0
- package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
- package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
- package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
- package/src/manager/generated/KnownModel_Base.ts +126 -0
- package/src/manager/generated/KnownModel_FileName.ts +2287 -0
- package/src/manager/generated/KnownModel_Name.ts +2287 -0
- package/src/manager/generated/KnownModel_SavePath.ts +263 -0
- package/src/manager/generated/KnownModel_Type.ts +97 -0
- package/src/manager/json/alter-list.json +224 -0
- package/src/manager/json/custom-node-list.extra.ts +13 -0
- package/src/manager/json/custom-node-list.json +21948 -0
- package/src/manager/json/extension-node-map.json +31282 -0
- package/src/manager/json/github-stats.json +12602 -0
- package/src/manager/json/model-list.extra.ts +26 -0
- package/src/manager/json/model-list.json +5052 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
- package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
- package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
- package/src/manager/loaders/step4_model-list-loader.ts +159 -0
- package/src/manager/script-update-manager.bun.ts +18 -0
- package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
- package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
- package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
- package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
- package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
- package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
- package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
- package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
- package/src/runner/ComfyExecution.ts +301 -0
- package/src/runner/ComfyExecutionStatus.ts +2 -0
- package/src/runner/ComfyWorkflow.ts +395 -0
- package/src/runner/ComfyWorkflowLayout.ts +96 -0
- package/src/runner/ComfyWsApi.ts +170 -0
- package/src/runner/MediaImage.ts +262 -0
- package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
- package/src/sdk-generator/ComfySchema.ts +369 -0
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
- package/src/sdk-generator/Primitives.ts +76 -0
- package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
- package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
- package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
- package/src/sdk-generator/comfy-api-json.ts +16 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
- package/src/sdk-generator/comfyui-types.ts +56 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
- package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
- package/src/ssh-host-manager/ssh-config.windows.md +32 -0
- package/src/ssh-host-manager/ssh-manager.ts +114 -0
- package/src/state.ts +136 -0
- package/src/types/comfy-sdk.ts +106 -0
- package/src/types/index.ts +55 -0
- package/src/utils/CodeBuffer.ts +61 -0
- package/src/utils/ComfyColors.ts +38 -0
- package/src/utils/ansi.ts +33 -0
- package/src/utils/ansiImage.ts +36 -0
- package/src/utils/bang.ts +39 -0
- package/src/utils/deepCopyNaive.ts +1 -0
- package/src/utils/downloadFile.ts +77 -0
- package/src/utils/escapeJSKey.ts +32 -0
- package/src/utils/exhaust.ts +4 -0
- package/src/utils/extractErrorMessage.ts +11 -0
- package/src/utils/fuzzyMatch.ts +8 -0
- package/src/utils/githubRegexes.ts +2 -0
- package/src/utils/hashArrayBuffer.ts +6 -0
- package/src/utils/log.ts +9 -0
- package/src/utils/loraTag.ts +10 -0
- package/src/utils/mojibake.ts +60 -0
- package/src/utils/printArkResultInConsole.ts +16 -0
- package/src/utils/softValidate.ts +8 -0
- package/src/utils/stringifyReadable.ts +32 -0
- package/src/utils/toposort.ts +59 -0
- package/src/utils/tryExtracting.ts +41 -0
- package/src/utils/writeFile.ts +16 -0
- package/src/vars/ComfyVars.ts +531 -0
- package/src/vars/DefinedWorkflow.ts +112 -0
- package/src/vars/loraKeywords.ts +56 -0
- package/dist/index.d.mts +0 -74
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/readme.md +0 -40
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Rémi Vion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# comfy-ts
|
|
2
|
+
|
|
3
|
+
> Type-safe ComfyUI companion for TypeScript. Connect to any number of ComfyUI
|
|
4
|
+
> hosts, get ONE generated SDK per host (global `Comfy.<HostNs>.*` namespaces),
|
|
5
|
+
> build workflows in code with full autocomplete, execute them over websocket,
|
|
6
|
+
> get your images back. Plus a terminal UI to tweak and re-run any workflow.
|
|
7
|
+
|
|
8
|
+
[](https://github.com/rvion/comfy-ts/actions/workflows/ci.yml)
|
|
9
|
+
[](https://www.npmjs.com/package/comfy-ts)
|
|
10
|
+
|
|
11
|
+
## Table of contents
|
|
12
|
+
|
|
13
|
+
- [Goals](#goals)
|
|
14
|
+
- [Install](#install)
|
|
15
|
+
- [Quick start](#quick-start)
|
|
16
|
+
- [The per-host typed SDK](#the-per-host-typed-sdk)
|
|
17
|
+
- [Vars: tweak and re-run](#vars-tweak-and-re-run)
|
|
18
|
+
- [The TUI](#the-tui)
|
|
19
|
+
- [The sidekick CLI](#the-sidekick-cli)
|
|
20
|
+
- [Examples](#examples)
|
|
21
|
+
- [The `.comfy-ts/` folder](#the-comfy-ts-folder)
|
|
22
|
+
- [Feature status](#feature-status)
|
|
23
|
+
- [DX goodies](#dx-goodies)
|
|
24
|
+
- [Related projects](#related-projects)
|
|
25
|
+
|
|
26
|
+
## Goals
|
|
27
|
+
|
|
28
|
+
1. **Create and execute workflows from TypeScript**, including uploading and
|
|
29
|
+
retrieving assets, with smart abstractions leaning on content addressing
|
|
30
|
+
(uploads are hash-named and deduped before any byte is sent).
|
|
31
|
+
2. **Fully type-safe, per host.** Every host you connect to gets its own
|
|
32
|
+
generated SDK: node inputs, model names, samplers, loras, embeddings are
|
|
33
|
+
literal types **from that actual install**.
|
|
34
|
+
3. **Ecosystem discovery codegen**: typed unions of every custom node,
|
|
35
|
+
plugin, and model known to the ComfyUI-Manager registry.
|
|
36
|
+
4. **Import both ComfyUI JSON formats**: `api.json` (prompt) and
|
|
37
|
+
`workflow.json` (litegraph graph) into code.
|
|
38
|
+
5. **Export both formats**: `api.json` for execution, plus an easy-to-read,
|
|
39
|
+
autolayouted `workflow.json` you can drag into the ComfyUI editor.
|
|
40
|
+
6. **Local and remote instances**: same API whether Comfy runs next to you
|
|
41
|
+
or on a GPU box over ssh.
|
|
42
|
+
7. **A sidekick CLI**: codegen and an interactive TUI, without writing a line
|
|
43
|
+
of code.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
bun add comfy-ts # or npm / pnpm / yarn
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Runs under Bun and node ≥ 20. Ships dual ESM/CJS.
|
|
52
|
+
|
|
53
|
+
## Quick start
|
|
54
|
+
|
|
55
|
+
A workflow module (from [`examples/01-txt2img.cflow.ts`](examples/01-txt2img.cflow.ts)):
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { ComfyTS, v } from 'comfy-ts'
|
|
59
|
+
|
|
60
|
+
const comfy = ComfyTS.create()
|
|
61
|
+
const host = comfy.host({ id: 'my-gpu', host: '127.0.0.1', port: 8188 })
|
|
62
|
+
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
63
|
+
|
|
64
|
+
export const txt2img = host.defineWorkflow({
|
|
65
|
+
id: 'txt2img',
|
|
66
|
+
vars: {
|
|
67
|
+
prompt: v.text('a cozy house in a snowy forest, warm windows'),
|
|
68
|
+
seed: v.seed(42),
|
|
69
|
+
steps: v.int(20, { min: 1, max: 60 }),
|
|
70
|
+
size: v.size({ width: 512, height: 512 }),
|
|
71
|
+
},
|
|
72
|
+
build: (b, vars) => {
|
|
73
|
+
// b is typed: Comfy.MyGpu.Builder, autocomplete on EVERY node of THIS host
|
|
74
|
+
const ckpt = b.CheckpointLoaderSimple({ ckpt_name: 'SD1.5\\v1-5-pruned-emaonly.ckpt' })
|
|
75
|
+
const samples = b.KSampler({
|
|
76
|
+
model: ckpt,
|
|
77
|
+
positive: b.CLIPTextEncode({ clip: ckpt, text: vars.prompt }),
|
|
78
|
+
negative: b.CLIPTextEncode({ clip: ckpt, text: 'blurry, low quality' }),
|
|
79
|
+
latent_image: b.EmptyLatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
|
|
80
|
+
seed: vars.seed,
|
|
81
|
+
steps: vars.steps,
|
|
82
|
+
cfg: 7,
|
|
83
|
+
sampler_name: 'euler',
|
|
84
|
+
scheduler: 'normal',
|
|
85
|
+
denoise: 1,
|
|
86
|
+
})
|
|
87
|
+
b.SaveImage({ images: b.VAEDecode({ samples, vae: ckpt }) })
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
export default txt2img
|
|
92
|
+
|
|
93
|
+
// standalone run, skipped when a driver (e.g. the TUI) imports this module
|
|
94
|
+
if (import.meta.main) {
|
|
95
|
+
const execution = await txt2img.run({ log: true }) // ▶ [██████░░] 71% · KSampler · 10s
|
|
96
|
+
for (const img of execution.images) console.log(img.absPath) // downloaded outputs
|
|
97
|
+
host.disconnect()
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
First time on a host, generate its schema cache and typed SDK once:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
bunx comfy-ts gen --id my-gpu --host http://127.0.0.1:8188
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
(or replace `loadSchemaFromCache()` with `await host.connect()`, which fetches
|
|
108
|
+
the schema and writes the SDK itself). One tsconfig line activates the
|
|
109
|
+
generated types:
|
|
110
|
+
|
|
111
|
+
```jsonc
|
|
112
|
+
{ "include": ["src", ".comfy-ts/hosts/**/sdk.d.ts"] }
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Before the first codegen, builder methods fall back to permissive base types.
|
|
116
|
+
Your code compiles either way; the types sharpen once the generated sdk is in
|
|
117
|
+
scope.
|
|
118
|
+
|
|
119
|
+
## The per-host typed SDK
|
|
120
|
+
|
|
121
|
+
Each host gets its own namespace inside the global `Comfy` namespace, plus a
|
|
122
|
+
registry entry, so several hosts coexist in one codebase:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
declare global {
|
|
126
|
+
namespace Comfy {
|
|
127
|
+
namespace MyGpu { // ← generated from THIS host's /object_info
|
|
128
|
+
interface IN { … } // input types per node
|
|
129
|
+
interface OUT { … } // output slots per node
|
|
130
|
+
interface Builder { … } // one factory per node
|
|
131
|
+
interface Union { … } // every enum: model names, samplers, loras, …
|
|
132
|
+
// + Node, Slots, Accepts, Producer, Embeddings, Schemas, NodeType
|
|
133
|
+
}
|
|
134
|
+
interface Hosts { 'my-gpu': MyGpu.Sdk }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`workflow.builder` resolves through `Comfy.Hosts`, so a workflow created on
|
|
140
|
+
`comfy.host({ id: 'my-gpu', … })` is typed with **that** host's nodes and
|
|
141
|
+
models. Unknown host ids fall back to permissive base types.
|
|
142
|
+
|
|
143
|
+
## Vars: tweak and re-run
|
|
144
|
+
|
|
145
|
+
`host.defineWorkflow({ vars, build })` is the re-run contract: declare the
|
|
146
|
+
knobs once, and `build` re-executes with the current values on every `run()`,
|
|
147
|
+
producing a fresh graph each time.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
export const asset = host.defineWorkflow({
|
|
151
|
+
id: 'asset',
|
|
152
|
+
vars: {
|
|
153
|
+
prompt: v.text('spherical sheep'),
|
|
154
|
+
seed: v.seed(517),
|
|
155
|
+
steps: v.int(8, { min: 1, max: 40 }),
|
|
156
|
+
size: v.size({ width: 1024, height: 1024 }), // SDXL-bucket presets + WxH custom
|
|
157
|
+
removeBg: v.toggle(true, 'remove bg'),
|
|
158
|
+
ratio: v.choice(['square', 'wide'] as const, 'square'),
|
|
159
|
+
loras: v.loras(/krea-?2/i), // multi-select, resolved against the host's real loras
|
|
160
|
+
},
|
|
161
|
+
build: async (b, vars, wf) => { /* typed builder code reading vars.* */ },
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
await asset.run({ log: true })
|
|
165
|
+
asset.vars.seed.randomize()
|
|
166
|
+
await asset.run({ log: true })
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
- var kinds: `v.text` / `v.int` / `v.float` / `v.seed` / `v.toggle` /
|
|
170
|
+
`v.choice` / `v.size` / `v.loras` / `v.prompt`.
|
|
171
|
+
- `v.loras` takes a RegExp (resolved against the host's real lora list at
|
|
172
|
+
define time) or any dynamic list such as `host.schema.getLoras(/xl/i)`;
|
|
173
|
+
`activeLoras(vars.loras)` normalizes the selection to
|
|
174
|
+
`{ lora_name, strength_model, strength_clip }[]`, ready for a standard
|
|
175
|
+
`LoraLoader` chain.
|
|
176
|
+
- `v.prompt` builds a structured `{ positive, negative }`: `//` lines are
|
|
177
|
+
comments (stripped), `- ` lines become the negative prompt, and
|
|
178
|
+
`v.prompt({ loraKeywordsFrom: lorasVar })` prefixes the active loras'
|
|
179
|
+
trigger keywords.
|
|
180
|
+
- `v.seed` is a mode plus a number (`+ N` / `- N` / `= N` / `? N`) and advances
|
|
181
|
+
itself after every run, so a queued batch gets distinct seeds.
|
|
182
|
+
- `vars` may be a lambda that RECEIVES `v`, giving cross-referencing vars one
|
|
183
|
+
scope with the host's own types injected:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
export const asset = host.defineWorkflow({
|
|
187
|
+
id: 'asset',
|
|
188
|
+
vars: (v) => {
|
|
189
|
+
const loras = v.loras(/krea-?2/i)
|
|
190
|
+
return { loras, prompt: v.prompt('a cozy house', { loraKeywordsFrom: loras }) }
|
|
191
|
+
},
|
|
192
|
+
build: async (b, vars, wf) => { /* … */ },
|
|
193
|
+
})
|
|
194
|
+
```
|
|
195
|
+
- `build` may be async (image uploads etc., the third `wf` param feeds
|
|
196
|
+
`MediaImage` upload helpers).
|
|
197
|
+
- `run()` opens with `await host.connect()`, which is idempotent (cached ready
|
|
198
|
+
promise, one websocket per host, ever). Modules import OFFLINE from the
|
|
199
|
+
schema cache and connect lazily on first run.
|
|
200
|
+
- `ComfyTS.create()` returns the existing global instance or creates it, and
|
|
201
|
+
`comfy.host({ id })` is a registry (same id, same instance back). Many
|
|
202
|
+
workflow modules can safely import each other, or be co-imported by the TUI,
|
|
203
|
+
in one process.
|
|
204
|
+
- fast start: `connect()` reuses the `.comfy-ts/` schema cache when younger
|
|
205
|
+
than 24h (`connect({ schema: 'refresh' })` forces a re-fetch,
|
|
206
|
+
`{ schema: 'cache' }` never fetches).
|
|
207
|
+
|
|
208
|
+
Name your workflow modules `*.cflow.ts` and the TUI finds them.
|
|
209
|
+
|
|
210
|
+
## The TUI
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
bunx comfy-ts tui examples/ # a dir: scans **/*.cflow.ts
|
|
214
|
+
bunx comfy-ts tui my.cflow.ts # a file: scans its folder, file preselected
|
|
215
|
+
bunx comfy-ts tui # no arg: scans cwd
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
┌ comfy-ts ┐┌ (w)orkflow ─┐┌ (d)raft ─┐┌ (h)ost ────────────────────┐
|
|
220
|
+
│ comfy-ts ││ 01-txt2img ││ default ││ ● windows-1 (127.0.0.1:8085)│
|
|
221
|
+
└──────────┘└─────────────┘└──────────┘└────────────────────────────┘
|
|
222
|
+
┌ (t)ree ────────────┐┌ (v)ars ─────────────────────────────┐┌ (p)review ─────┐
|
|
223
|
+
│ ▾ 01-txt2img ││ ▸ prompt [text] a cozy house in a… ││ │
|
|
224
|
+
│ default ││ seed [seed] ? 42 ││ ▄▓▓▒▒░▄▄▓▒░░ │
|
|
225
|
+
│ night-take ││ steps [int] 20 ││ ▓▒░▄▄▓▓▒▒░▄▓ │
|
|
226
|
+
│ ▸ 04-krea2-turbo ││ size [size] 512×512 ││ live latent / │
|
|
227
|
+
│ ││ loras [loras] (2) styleA, styleB ││ last output │
|
|
228
|
+
└────────────────────┘└──────────────────────────────────────┘└────────────────┘
|
|
229
|
+
▶ [██████░░░░░░░░░░] 42% · KSampler · 12s · queue 1
|
|
230
|
+
↑↓ select · ← tree · ⏎/→ edit
|
|
231
|
+
r run · s reroll+run · e rename draft · o open image · c/C copy wf/api · q quit
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Keyboard-first, three panels, a persistent keybar showing every key available
|
|
235
|
+
in the current mode. Every panel and header box is titled with the key that
|
|
236
|
+
opens it, and no key is advertised twice.
|
|
237
|
+
|
|
238
|
+
- **(t)ree** (left): every `*.cflow.ts` workflow found, with its drafts nested
|
|
239
|
+
under it. ↑↓ move, ← folds, → unfolds a workflow or hops into the vars panel
|
|
240
|
+
from a draft row, ⏎ loads a workflow or a draft directly.
|
|
241
|
+
- **(v)ars** (center): the knobs of the loaded workflow. You are always in a
|
|
242
|
+
draft (`default` auto-active per workflow); edits autosave to
|
|
243
|
+
`.comfy-ts/drafts/`, `e` renames the active draft inline, `d` opens the
|
|
244
|
+
drafts overlay (load / new / duplicate / delete). Drafts are named var-value
|
|
245
|
+
snapshots, so one workflow carries many setups, and reopening a workflow
|
|
246
|
+
lands back in the draft you left it in.
|
|
247
|
+
- **(p)review** (right, `p` cycles native → ansi → off): LIVE latent previews
|
|
248
|
+
while a run is in flight (launch ComfyUI with `--preview-method auto`), then
|
|
249
|
+
the final output. On iTerm2, WezTerm and VS Code terminals "native" paints
|
|
250
|
+
the REAL image over the panel; everywhere else it renders truecolor
|
|
251
|
+
half-blocks.
|
|
252
|
+
- **(h)ost** (header box): node / lora / embedding counts, live server queue
|
|
253
|
+
length, and actions — re-run the SDK codegen, restart ComfyUI, clear the
|
|
254
|
+
pending queue, interrupt the current run.
|
|
255
|
+
|
|
256
|
+
Editing a var opens the right surface for its kind: numbers edit inline
|
|
257
|
+
(readline word ops included), text and prompt vars open a real multiline editor
|
|
258
|
+
(⏎ saves, ⇧⏎ or ⌥⏎ inserts a newline, ⌘←→ and ⌃A/⌃E move by logical line, ⌥↑↓
|
|
259
|
+
move a line, ⌘/ toggles a `// ` comment), choice and size open a
|
|
260
|
+
fuzzy-filterable picker (type `WxH` for a custom size), loras open a
|
|
261
|
+
multi-select overlay (type to filter, space ticks, ←→ steps strengths, ⌃A/⌃N
|
|
262
|
+
tick/untick all filtered, ⌃K assigns that lora's trigger keywords). A seed row
|
|
263
|
+
takes `+` `-` `=` `?` to set its mode and `*` to reroll. If the host has the
|
|
264
|
+
[ComfyUI-Lora-Manager](https://github.com/willmiao/ComfyUI-Lora-Manager)
|
|
265
|
+
extension installed, the preview panel shows the selected lora's preview image
|
|
266
|
+
while you browse; without it, everything else keeps working.
|
|
267
|
+
|
|
268
|
+
Global keys: `r` run, `s` reroll seed + run, `o` open the last output in the
|
|
269
|
+
OS image viewer (full resolution), `c` copy workflow.json, `C` copy api.json,
|
|
270
|
+
`⌃R` run from any mode, `q` quit. Pressing `r` while a run is in flight QUEUES
|
|
271
|
+
another prompt on the server (built from the values as they are right now), and
|
|
272
|
+
the progress bar, latent preview and outputs follow each queued run in turn.
|
|
273
|
+
|
|
274
|
+
## The sidekick CLI
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
bunx comfy-ts gen --id my-gpu --host http://127.0.0.1:8188
|
|
278
|
+
# → .comfy-ts/hosts/my-gpu/{object_info.json, embeddings.json, sdk.d.ts}
|
|
279
|
+
|
|
280
|
+
bunx comfy-ts outline # what's inside that 2MB sdk.d.ts?
|
|
281
|
+
bunx comfy-ts outline --section Builder --lines 40
|
|
282
|
+
|
|
283
|
+
bunx comfy-ts tui [dir | module.cflow.ts] # see above
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Examples
|
|
287
|
+
|
|
288
|
+
Runnable from the repo (they expect a live ComfyUI). Every example is a
|
|
289
|
+
`*.cflow.ts` workflow module: run it standalone with bun, or point the TUI at
|
|
290
|
+
`examples/`.
|
|
291
|
+
|
|
292
|
+
| example | shows |
|
|
293
|
+
| -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
294
|
+
| [`examples/01-txt2img.cflow.ts`](examples/01-txt2img.cflow.ts) | typed builder, vars, execution, downloaded outputs |
|
|
295
|
+
| [`examples/02-img2img-upload.cflow.ts`](examples/02-img2img-upload.cflow.ts) | hash-named deduped upload, img2img, async build |
|
|
296
|
+
| [`examples/03-export-workflow-json.cflow.ts`](examples/03-export-workflow-json.cflow.ts) | OFFLINE graph building, export api.json + readable workflow.json |
|
|
297
|
+
| [`examples/04-krea2-turbo-t2i.cflow.ts`](examples/04-krea2-turbo-t2i.cflow.ts) | a real pipeline: krea2 turbo + `v.loras` multi-select stack (standard LoraLoader chain) + RMBG cutout → transparent png |
|
|
298
|
+
|
|
299
|
+
## The `.comfy-ts/` folder
|
|
300
|
+
|
|
301
|
+
Every repo using comfy-ts gets one `.comfy-ts/` folder at its root:
|
|
302
|
+
|
|
303
|
+
```
|
|
304
|
+
.comfy-ts/
|
|
305
|
+
hosts/<host-id>/object_info.json raw schema dump from the host
|
|
306
|
+
hosts/<host-id>/embeddings.json embeddings list
|
|
307
|
+
hosts/<host-id>/sdk.d.ts the generated typed SDK (per host)
|
|
308
|
+
outputs/ images and workflows produced by runs
|
|
309
|
+
drafts/<module-basename>/<name>.json named var snapshots from the TUI
|
|
310
|
+
settings.json TUI settings (preview mode, last draft)
|
|
311
|
+
lora-keywords.json trigger keywords you assigned to loras
|
|
312
|
+
cache/ lora preview images, refetchable
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Everything under `.comfy-ts/` is local state: gitignore it. `hosts/` in
|
|
316
|
+
particular is a full dump of that machine's models, loras and paths (often
|
|
317
|
+
~10MB per host), so committing it publishes your setup — regenerate it instead
|
|
318
|
+
with `bun run gen:sdk` or a first `connect()`. In a PRIVATE repo, committing
|
|
319
|
+
`hosts/` is what buys you typed CI. This repo does not commit it, and the
|
|
320
|
+
library is built to typecheck with no generated SDK on disk at all.
|
|
321
|
+
|
|
322
|
+
## Feature status
|
|
323
|
+
|
|
324
|
+
| feature | status |
|
|
325
|
+
| -------------------------------------------------------------- | :----: |
|
|
326
|
+
| typed workflow builder + execution + progress + outputs | ✅ |
|
|
327
|
+
| vars + `defineWorkflow` tweak and re-run | ✅ |
|
|
328
|
+
| structured prompts (`v.prompt`: negatives, comments, keywords) | ✅ |
|
|
329
|
+
| TUI drafts, persisted settings, queued runs | ✅ |
|
|
330
|
+
| per-host namespace codegen (`Comfy.<HostNs>.*`) | ✅ |
|
|
331
|
+
| idempotent connect, resilient websocket, latent previews | ✅ |
|
|
332
|
+
| hash-named, deduped image upload | ✅ |
|
|
333
|
+
| export api.json + autolayouted workflow.json | ✅ |
|
|
334
|
+
| import api.json into a live workflow | ✅ |
|
|
335
|
+
| import workflow.json (litegraph → api conversion) | ✅ |
|
|
336
|
+
| sidekick CLI (`gen`, `outline`, `tui`) | ✅ |
|
|
337
|
+
| ComfyUI-Manager registry mirror + Known\* ecosystem unions | ✅ |
|
|
338
|
+
| install custom nodes / models via ComfyUI-Manager | ✅ |
|
|
339
|
+
| locality-aware media retrieval fast-path (local vs remote) | 🔶 |
|
|
340
|
+
| content-addressed local asset cache | 🔶 |
|
|
341
|
+
|
|
342
|
+
✅ working and exercised · 🔶 partial / in progress
|
|
343
|
+
|
|
344
|
+
## DX goodies
|
|
345
|
+
|
|
346
|
+
- **`auto<T>()`**: leave a slot blank; comfy-ts wires the most recent node
|
|
347
|
+
producing the right type.
|
|
348
|
+
- **functional inputs**: any input accepts `(producers) => value`, with
|
|
349
|
+
`producers` narrowed to the nodes able to output the expected type.
|
|
350
|
+
- **`HasSingle` shortcuts**: pass a whole node wherever it has exactly one
|
|
351
|
+
output of the expected type (`model: ckpt` instead of `ckpt._MODEL`).
|
|
352
|
+
- **problems, not crashes**: invalid graphs accumulate precise messages in
|
|
353
|
+
`workflow.problems` before Comfy ever sees them.
|
|
354
|
+
|
|
355
|
+
## Related projects
|
|
356
|
+
|
|
357
|
+
- [CushyStudio](https://github.com/rvion/CushyStudio), where this library was born.
|
|
358
|
+
- [@saintno/comfyui-sdk](https://www.npmjs.com/package/@saintno/comfyui-sdk), polished API, but unsafe workflow building, no typed registry.
|
|
359
|
+
- [comfyui-bun-client](https://github.com/KaruroChori/comfyui-bun-client), similar spirit, less codegen, not on npm.
|
|
360
|
+
|
|
361
|
+
## License
|
|
362
|
+
|
|
363
|
+
MIT © [Rémi Vion](https://github.com/rvion)
|