comfy-ts 2.19.0 → 2.20.1
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 +9 -4
- package/claude-code/skills/setup/SKILL.md +1 -1
- package/dist/{ServeApp-qXcQfdgT.js → ServeApp-B469W26E.js} +5 -5
- package/dist/{ServeApp-qXcQfdgT.js.map → ServeApp-B469W26E.js.map} +1 -1
- package/dist/cli.js +12 -8
- package/dist/cli.js.map +1 -1
- package/dist/{exampleAssets-CE4PUy3n.js → exampleAssets-8MycEthF.js} +141 -55
- package/dist/exampleAssets-8MycEthF.js.map +1 -0
- package/dist/{findDefinedWorkflow-0lG-VTEd.js → findDefinedWorkflow-B90-xFxX.js} +2 -2
- package/dist/{findDefinedWorkflow-0lG-VTEd.js.map → findDefinedWorkflow-B90-xFxX.js.map} +1 -1
- package/dist/index.cjs +87 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +87 -6
- package/dist/index.js.map +1 -1
- package/dist/{run-run-C_yXY0vl.js → run-run-BslhZ0Qm.js} +5 -5
- package/dist/{run-run-C_yXY0vl.js.map → run-run-BslhZ0Qm.js.map} +1 -1
- package/dist/{run-serve-DaXzoVTS.js → run-serve-CsEYPGm9.js} +4 -4
- package/dist/{run-serve-DaXzoVTS.js.map → run-serve-CsEYPGm9.js.map} +1 -1
- package/dist/{run-tui-B3dsftdB.js → run-tui-Cxa8ksav.js} +9 -14
- package/dist/run-tui-Cxa8ksav.js.map +1 -0
- package/dist/{schemaDrift-CbsABBuk.js → schemaDrift-DaWsE-mt.js} +15 -15
- package/dist/{schemaDrift-CbsABBuk.js.map → schemaDrift-DaWsE-mt.js.map} +1 -1
- package/dist/serve-web.js +28 -28
- package/dist/web.d.ts +12 -2
- package/dist/web.js +87 -6
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -1
- package/examples/rvion/01-txt2img.cflow.ts +1 -1
- package/examples/rvion/02-img2img-upload.cflow.ts +1 -1
- package/examples/rvion/03-export-workflow-json.cflow.ts +1 -1
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +1 -1
- package/examples/rvion/06-qwen-image-edit.cflow.ts +1 -1
- package/examples/rvion/07-local-llm-text-gen.cflow.ts +1 -1
- package/examples/rvion/08-qwen-image-21-t2i.cflow.ts +1 -1
- package/examples/rvion/09-qwen-image-21-edit.cflow.ts +1 -1
- package/examples/rvion/10-anima-t2i.cflow.ts +1 -1
- package/examples/rvion/11-yue2-t2a.cflow.ts +1 -1
- package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +1 -1
- package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +1 -1
- package/examples/rvion/14-video-soundtrack.cflow.ts +1 -1
- package/examples/rvion/15-tts-voice-clone.cflow.ts +1 -1
- package/examples/rvion/16-tts-voice-design.cflow.ts +1 -1
- package/guide-for-agents.md +4 -4
- package/package.json +7 -6
- package/src/cli/comfy-ts-cli.ts +4 -2
- package/src/cli/gen.ts +6 -1
- package/src/cli/serve/ServeApp.ts +4 -4
- package/src/cli/serve/web/api.ts +1 -1
- package/src/cli/serve/web/state/RunSt.poll.test.ts +38 -0
- package/src/cli/serve/web/state/RunSt.ts +6 -2
- package/src/cli/tui/components/Header.tsx +1 -4
- package/src/cli/tui/components/HostPanel.tsx +1 -4
- package/src/cli/tui/state/HostSt.ts +2 -2
- package/src/host/ComfyHost.ts +37 -5
- package/src/host/hostFile.ts +57 -0
- package/src/state.ts +15 -9
- package/dist/exampleAssets-CE4PUy3n.js.map +0 -1
- package/dist/run-tui-B3dsftdB.js.map +0 -1
package/examples/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Every `*.cflow.ts` file here is a runnable workflow module. Run it directly with
|
|
|
4
4
|
|
|
5
5
|
## Layout
|
|
6
6
|
|
|
7
|
-
- `rvion/01…04-*.cflow.ts`: the didactic sequence against a LOCAL ComfyUI host
|
|
7
|
+
- `rvion/01…04-*.cflow.ts`: the didactic sequence against a LOCAL ComfyUI host, named by id only: `comfy.host({ id: 'windows-1' })`. Run `bunx comfy-ts gen --id windows-1 --host http://<your-comfy>:8188` once: it saves the address and generates the typed SDK.
|
|
8
8
|
- `rvion/05-comfy-cloud.cflow.ts`: the same t2i against [Comfy Cloud](https://cloud.comfy.org). No local GPU needed: the typed catalog ships committed at `comfy-cloud/sdk.d.ts`.
|
|
9
9
|
- `rvion/06-qwen-image-edit.cflow.ts`: image editing (qwen image edit 2511) against the same local host.
|
|
10
10
|
- `rvion/07-local-llm-text-gen.cflow.ts`: a local LLM, no image. Core's `TextGenerate` runs a chat model loaded through `CLIPLoader`, and the text comes back in `execution.text`. `--sweep` reports which text encoders on your host actually generate.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { ComfyTS, v } from 'comfy-ts'
|
|
5
5
|
|
|
6
6
|
const comfy = ComfyTS.create()
|
|
7
|
-
const host = comfy.host({ id: 'windows-1'
|
|
7
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
8
8
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
9
9
|
|
|
10
10
|
export const txt2img = host.defineWorkflow({
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { asAbsolutePath, ComfyTS, exampleImagePath, MediaImage, v } from 'comfy-ts'
|
|
5
5
|
|
|
6
6
|
const comfy = ComfyTS.create()
|
|
7
|
-
const host = comfy.host({ id: 'windows-1'
|
|
7
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
8
8
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
9
9
|
|
|
10
10
|
// bundled default input (examples/images/, ships in the tarball) — the TUI picker or argv[2] swap it
|
|
@@ -6,7 +6,7 @@ import { mkdirSync, writeFileSync } from 'node:fs'
|
|
|
6
6
|
import { ComfyTS, v } from 'comfy-ts'
|
|
7
7
|
|
|
8
8
|
const comfy = ComfyTS.create()
|
|
9
|
-
const host = comfy.host({ id: 'windows-1'
|
|
9
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
10
10
|
await host.loadSchemaFromCache() // no connection needed
|
|
11
11
|
|
|
12
12
|
export const exportWorkflow = host.defineWorkflow({
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { activeLoras, ComfyTS } from 'comfy-ts'
|
|
9
9
|
|
|
10
10
|
const comfy = ComfyTS.create()
|
|
11
|
-
const host = comfy.host({ id: 'windows-1'
|
|
11
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
12
12
|
await host.loadSchemaFromCache() // offline import (lora options come from the cached schema); run() connects lazily
|
|
13
13
|
|
|
14
14
|
export const t2i = host.defineWorkflow({
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { asAbsolutePath, ComfyTS, exampleImagePath, MediaImage, v } from 'comfy-ts'
|
|
8
8
|
|
|
9
9
|
const comfy = ComfyTS.create()
|
|
10
|
-
const host = comfy.host({ id: 'windows-1'
|
|
10
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
11
11
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
12
12
|
|
|
13
13
|
// bundled default input (examples/images/, ships in the tarball) — the TUI picker or argv[2] swap it
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { ComfyTS, promptEnhancerPresets, v } from 'comfy-ts'
|
|
14
14
|
|
|
15
15
|
const comfy = ComfyTS.create()
|
|
16
|
-
const host = comfy.host({ id: 'windows-1'
|
|
16
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
17
17
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
18
18
|
|
|
19
19
|
// generative on this box (measured, see --sweep). Every entry is a plain text_encoders/
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { ComfyTS, v } from 'comfy-ts'
|
|
6
6
|
|
|
7
7
|
const comfy = ComfyTS.create()
|
|
8
|
-
const host = comfy.host({ id: 'windows-1'
|
|
8
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
9
9
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
10
10
|
|
|
11
11
|
export const qwenImage21T2i = host.defineWorkflow({
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { asAbsolutePath, ComfyTS, exampleImagePath, MediaImage, v } from 'comfy-ts'
|
|
7
7
|
|
|
8
8
|
const comfy = ComfyTS.create()
|
|
9
|
-
const host = comfy.host({ id: 'windows-1'
|
|
9
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
10
10
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
11
11
|
|
|
12
12
|
// bundled default input (examples/images/, ships in the tarball) — the TUI picker or argv[2] swap it
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { activeLoras, ComfyTS } from 'comfy-ts'
|
|
8
8
|
|
|
9
9
|
const comfy = ComfyTS.create()
|
|
10
|
-
const host = comfy.host({ id: 'windows-1'
|
|
10
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
11
11
|
await host.loadSchemaFromCache()
|
|
12
12
|
|
|
13
13
|
const TURBO_LORA = 'anima\\anima-turbo-lora-v0.2.safetensors'
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { ComfyTS, v } from 'comfy-ts'
|
|
8
8
|
|
|
9
9
|
const comfy = ComfyTS.create()
|
|
10
|
-
const host = comfy.host({ id: 'windows-1'
|
|
10
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
11
11
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
12
12
|
|
|
13
13
|
export const yue2T2a = host.defineWorkflow({
|
|
@@ -8,7 +8,7 @@ import { ComfyTS, v } from 'comfy-ts'
|
|
|
8
8
|
import { SA3_CATEGORIES, sa3Reprompt } from './stableAudio3Prompts.ts'
|
|
9
9
|
|
|
10
10
|
const comfy = ComfyTS.create()
|
|
11
|
-
const host = comfy.host({ id: 'windows-1'
|
|
11
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
12
12
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
13
13
|
|
|
14
14
|
export const stableAudio3T2a = host.defineWorkflow({
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { ComfyTS, v } from 'comfy-ts'
|
|
9
9
|
|
|
10
10
|
const comfy = ComfyTS.create()
|
|
11
|
-
const host = comfy.host({ id: 'windows-1'
|
|
11
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
12
12
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
13
13
|
|
|
14
14
|
const MODELS = {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { ComfyTS, exampleMediaPath, v } from 'comfy-ts'
|
|
8
8
|
|
|
9
9
|
const comfy = ComfyTS.create()
|
|
10
|
-
const host = comfy.host({ id: 'windows-1'
|
|
10
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
11
11
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
12
12
|
|
|
13
13
|
// bundled defaults (examples/media/, ship in the tarball)
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { ComfyTS, exampleMediaPath, v } from 'comfy-ts'
|
|
10
10
|
|
|
11
11
|
const comfy = ComfyTS.create()
|
|
12
|
-
const host = comfy.host({ id: 'windows-1'
|
|
12
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
13
13
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
14
14
|
|
|
15
15
|
const ENGINES = ['chatterbox', 'qwen3', 'fishs2', 'cosyvoice3', 'omnivoice'] as const
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { ComfyTS, v } from 'comfy-ts'
|
|
9
9
|
|
|
10
10
|
const comfy = ComfyTS.create()
|
|
11
|
-
const host = comfy.host({ id: 'windows-1'
|
|
11
|
+
const host = comfy.host({ id: 'windows-1' })
|
|
12
12
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
13
13
|
|
|
14
14
|
const LANGUAGES = [
|
package/guide-for-agents.md
CHANGED
|
@@ -9,17 +9,17 @@ You are working in a project that uses `comfy-ts`, a type-safe ComfyUI companion
|
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
11
|
bunx comfy-ts gen --id my-gpu --host http://127.0.0.1:8188
|
|
12
|
-
# writes .comfy-ts/hosts/my-gpu/{object_info.json,embeddings.json,sdk.d.ts}
|
|
12
|
+
# writes .comfy-ts/hosts/my-gpu/{object_info.json,embeddings.json,sdk.d.ts,host.json}
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Or skip the CLI: a first `await host.connect()` fetches the schema and writes the same files.
|
|
15
|
+
`host.json` is the saved address: from then on `comfy.host({ id: 'my-gpu' })` finds the host, so committed code never names a machine. No saved address and no `url` or `host`/`port`: the module still imports (a loud log), and the first connect or run throws and names the `gen` command to run. Or skip the CLI: a first `await host.connect()` fetches the schema and writes the same files, except `host.json`.
|
|
16
16
|
3. Activate the generated types in tsconfig:
|
|
17
17
|
|
|
18
18
|
```jsonc
|
|
19
19
|
{ "include": ["src", ".comfy-ts/hosts/**/sdk.d.ts"] }
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
4. Gitignore `.comfy-ts/` entirely. It is local state: host schema dumps (often ~10MB, they describe that machine's models and paths), run outputs, TUI drafts and settings, lora keywords, preview cache. Everything in it is regenerable. (Exception: a private repo may commit `hosts/` to get typed CI.)
|
|
22
|
+
4. Gitignore `.comfy-ts/` entirely. It is local state: host schema dumps (often ~10MB, they describe that machine's models and paths), host addresses, run outputs, TUI drafts and settings, lora keywords, preview cache. Everything in it is regenerable. (Exception: a private repo may commit `hosts/` to get typed CI.)
|
|
23
23
|
|
|
24
24
|
Before the first codegen the builder falls back to permissive base types, so code compiles either way when `noUncheckedIndexedAccess` is off. With that flag on, every `b.Node(...)` call is an error until a generated sdk.d.ts is in scope, so run the codegen first. Types sharpen once the generated sdk is in scope.
|
|
25
25
|
|
|
@@ -31,7 +31,7 @@ A workflow module is a `*.cflow.ts` file (that suffix is what the TUI scans for)
|
|
|
31
31
|
import { ComfyTS, v } from 'comfy-ts'
|
|
32
32
|
|
|
33
33
|
const comfy = ComfyTS.create()
|
|
34
|
-
const host = comfy.host({ id: 'my-gpu'
|
|
34
|
+
const host = comfy.host({ id: 'my-gpu' }) // the address `comfy-ts gen` saved
|
|
35
35
|
await host.loadSchemaFromCache() // offline import; run() connects lazily
|
|
36
36
|
|
|
37
37
|
export const txt2img = host.defineWorkflow({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comfy-ts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.1",
|
|
4
4
|
"description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 80+ 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",
|
|
@@ -70,9 +70,10 @@
|
|
|
70
70
|
"build": "tsdown && bun scripts/build-serve-web.ts",
|
|
71
71
|
"build:watch": "tsdown --watch",
|
|
72
72
|
"test": "bun test --parallel --no-isolate",
|
|
73
|
+
"test:raw": "bun test",
|
|
73
74
|
"test:watch": "bun test --watch",
|
|
74
|
-
"typecheck": "tsc
|
|
75
|
-
"typecheck:
|
|
75
|
+
"typecheck": "tsc -p tsconfig.lib.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
|
|
76
|
+
"typecheck:full": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
|
|
76
77
|
"lint": "oxlint src examples scripts tests",
|
|
77
78
|
"format": "oxfmt src examples scripts tests",
|
|
78
79
|
"format:check": "oxfmt --check src examples scripts tests",
|
|
@@ -80,8 +81,8 @@
|
|
|
80
81
|
"imports:fix": "rvt imports --fix",
|
|
81
82
|
"cycles": "rvt cycles 1",
|
|
82
83
|
"rename": "rvt rename",
|
|
83
|
-
"ci": "bun run typecheck
|
|
84
|
-
"ci:local": "bun run ci && bun run typecheck",
|
|
84
|
+
"ci": "bun run typecheck && bun run lint && bun run format:check && bun run imports:check && bun run test",
|
|
85
|
+
"ci:local": "bun run ci && bun run typecheck:full",
|
|
85
86
|
"gen:manager": "bun src/manager/script-update-manager.bun.ts",
|
|
86
87
|
"gen:sdk": "bun scripts/gen-sdk-from-cache.ts",
|
|
87
88
|
"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",
|
|
@@ -141,7 +142,7 @@
|
|
|
141
142
|
"oxfmt": "^0.60.0",
|
|
142
143
|
"oxlint": "^1.75.0",
|
|
143
144
|
"oxlint-tsgolint": "^7.0.2001",
|
|
144
|
-
"rvlib-shipkit": "^2.
|
|
145
|
+
"rvlib-shipkit": "^2.26.0",
|
|
145
146
|
"rvlib-ts-tools": "^0.3.3",
|
|
146
147
|
"tsdown": "^0.22.14",
|
|
147
148
|
"typescript": "^7.0.2"
|
package/src/cli/comfy-ts-cli.ts
CHANGED
|
@@ -12,8 +12,10 @@ const HELP = `comfy-ts — typed SDK codegen for ComfyUI
|
|
|
12
12
|
Usage:
|
|
13
13
|
comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188] [--api-key <key>] [--out <sdk-path>]
|
|
14
14
|
fetch object_info + embeddings from a live ComfyUI host and write
|
|
15
|
-
.comfy-ts/hosts/<host-id>/{object_info.json,embeddings.json,sdk.d.ts}
|
|
16
|
-
(
|
|
15
|
+
.comfy-ts/hosts/<host-id>/{object_info.json,embeddings.json,sdk.d.ts,host.json}
|
|
16
|
+
(host.json saves the address: code then names the host by id alone,
|
|
17
|
+
comfy.host({ id: '<host-id>' }); the api key is never written;
|
|
18
|
+
--api-key or COMFY_CLOUD_API_KEY authenticates via X-API-Key;
|
|
17
19
|
--out relocates ONLY the sdk.d.ts, e.g. a committed cloud catalog)
|
|
18
20
|
|
|
19
21
|
comfy-ts outline [file] [--lines N] [--section Name]
|
package/src/cli/gen.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
3
3
|
import { dirname, join, resolve } from 'pathe'
|
|
4
4
|
import { flagReader } from 'src/cli/flags.ts'
|
|
5
|
+
import { writeHostFile } from 'src/host/hostFile.ts'
|
|
6
|
+
import { renderHttpBase } from 'src/host/hostUrl.ts'
|
|
5
7
|
import { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'
|
|
6
8
|
import type { ComfySchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'
|
|
7
9
|
import { ComfyTS } from 'src/state.ts'
|
|
@@ -33,10 +35,13 @@ export async function runGen(args: string[]): Promise<number> {
|
|
|
33
35
|
const spec = await fetchJSON<ComfySchemaJSON>('/object_info')
|
|
34
36
|
const embeddings = await fetchJSON<string[]>('/embeddings').catch(() => [] as string[])
|
|
35
37
|
|
|
36
|
-
const dir =
|
|
38
|
+
const dir = host.cacheFolder
|
|
37
39
|
mkdirSync(dir, { recursive: true })
|
|
38
40
|
writeFileSync(join(dir, 'object_info.json'), readableStringify(spec, 4), 'utf8')
|
|
39
41
|
writeFileSync(join(dir, 'embeddings.json'), JSON.stringify(embeddings), 'utf8')
|
|
42
|
+
// the address, so code names this host by id alone: comfy.host({ id })
|
|
43
|
+
const hostFile = writeHostFile(comfy.storage, dir, { url: renderHttpBase(host.base) })
|
|
44
|
+
console.log(`[comfy-ts gen] 🟢 ${hostFile}: comfy.host({ id: '${id}' }) now finds this host`)
|
|
40
45
|
|
|
41
46
|
const parsed = new ComfySchema({ spec, embeddings })
|
|
42
47
|
const dts = parsed.codegenDTS({ hostId: id })
|
|
@@ -894,14 +894,14 @@ export class ServeApp {
|
|
|
894
894
|
|
|
895
895
|
// #region hosts (run a workflow somewhere else, the TUI's host override) ----
|
|
896
896
|
/** every host this process registered: the modules' own, plus anything they created */
|
|
897
|
-
private knownHosts(): { id: string; url: string; httpUrl: string; modules: string[] }[] {
|
|
898
|
-
const byId = new Map<string, { id: string; url: string; httpUrl: string; modules: string[] }>()
|
|
897
|
+
private knownHosts(): { id: string; url: string; httpUrl: string | null; modules: string[] }[] {
|
|
898
|
+
const byId = new Map<string, { id: string; url: string; httpUrl: string | null; modules: string[] }>()
|
|
899
899
|
for (const [id, host] of comfyts.hosts)
|
|
900
900
|
byId.set(id, {
|
|
901
901
|
id,
|
|
902
|
-
url:
|
|
902
|
+
url: host.addressLabel,
|
|
903
903
|
// the browser needs the REAL base to open the host's own pages (lora manager)
|
|
904
|
-
httpUrl: host.getServerHostHTTP(),
|
|
904
|
+
httpUrl: host.noAddress == null ? host.getServerHostHTTP() : null,
|
|
905
905
|
modules: [],
|
|
906
906
|
})
|
|
907
907
|
for (const mod of this.modules) {
|
package/src/cli/serve/web/api.ts
CHANGED
|
@@ -229,7 +229,7 @@ export function saveSettings(p: {
|
|
|
229
229
|
|
|
230
230
|
/** every host the serve process knows, and where each module currently runs */
|
|
231
231
|
export type HostsPayload = {
|
|
232
|
-
hosts: { id: string; url: string; httpUrl: string; modules: string[] }[]
|
|
232
|
+
hosts: { id: string; url: string; httpUrl: string | null; modules: string[] }[]
|
|
233
233
|
defaults: Record<string, string>
|
|
234
234
|
overrides: Record<string, string>
|
|
235
235
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// the run poll: a prompt that samples in about a second must be read several times while it runs,
|
|
2
|
+
// or the panel never shows its latent; and once it is done, the panel asks nothing more
|
|
3
|
+
import { afterEach, beforeEach, expect, it } from 'bun:test'
|
|
4
|
+
import { RunSt } from 'src/cli/serve/web/state/RunSt.ts'
|
|
5
|
+
|
|
6
|
+
const realFetch = globalThis.fetch
|
|
7
|
+
let statusReads = 0
|
|
8
|
+
const json = (body: unknown): Response =>
|
|
9
|
+
new Response(JSON.stringify(body), { headers: { 'content-type': 'application/json' } })
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
statusReads = 0
|
|
13
|
+
globalThis.fetch = (async (input: string | URL | Request): Promise<Response> => {
|
|
14
|
+
const url = String(input instanceof Request ? input.url : input)
|
|
15
|
+
if (url.startsWith('/run/')) {
|
|
16
|
+
statusReads++
|
|
17
|
+
return json({ running: true, percent: 50, hasPreview: true, previewSeq: statusReads })
|
|
18
|
+
}
|
|
19
|
+
if (url.startsWith('/generate/')) {
|
|
20
|
+
await new Promise((r) => setTimeout(r, 400))
|
|
21
|
+
return json({ promptId: 'p1', module: 'm', draft: 'd', seeds: {}, outputs: [] })
|
|
22
|
+
}
|
|
23
|
+
return json({ runs: [], memory: { usedBytes: 0, budgetBytes: 1, outputs: 0, runs: 0 } })
|
|
24
|
+
}) as typeof fetch
|
|
25
|
+
})
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
globalThis.fetch = realFetch
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('reads the run status several times during a short run, and not at all once it is done', async () => {
|
|
31
|
+
const run = new RunSt()
|
|
32
|
+
run.enqueue({ module: 'm', draft: 'd', payload: {} })
|
|
33
|
+
while (run.queue.length > 0) await new Promise((r) => setTimeout(r, 20))
|
|
34
|
+
expect(statusReads).toBeGreaterThanOrEqual(2)
|
|
35
|
+
const atEnd = statusReads
|
|
36
|
+
await new Promise((r) => setTimeout(r, 300))
|
|
37
|
+
expect(statusReads).toBe(atEnd)
|
|
38
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// the run QUEUE + results. Clicking generate repeatedly enqueues; the drainer
|
|
2
2
|
// sends ONE prompt at a time so anything still pending can be dropped before it
|
|
3
3
|
// ever reaches the host: queued prompts must be clearable, singly or
|
|
4
|
-
// all). Progress + latent preview are polled
|
|
4
|
+
// all). Progress + latent preview are polled every RUN_POLL_MS while a prompt is in flight, never
|
|
5
|
+
// while idle
|
|
5
6
|
import { makeAutoObservable, observableShallow, runInAction } from 'mobx'
|
|
6
7
|
import {
|
|
7
8
|
deleteKeptResults,
|
|
@@ -29,6 +30,9 @@ export type QueueEntry = {
|
|
|
29
30
|
sent: boolean
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
/** a sampler often ends within a second: a slower poll misses every latent frame of it */
|
|
34
|
+
const RUN_POLL_MS = 150
|
|
35
|
+
|
|
32
36
|
function sleep(ms: number): Promise<void> {
|
|
33
37
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
34
38
|
}
|
|
@@ -194,7 +198,7 @@ export class RunSt {
|
|
|
194
198
|
|
|
195
199
|
private async poll(module: string, gen: number): Promise<void> {
|
|
196
200
|
while (gen === this.pollGen) {
|
|
197
|
-
await sleep(
|
|
201
|
+
await sleep(RUN_POLL_MS)
|
|
198
202
|
if (gen !== this.pollGen) return
|
|
199
203
|
try {
|
|
200
204
|
const status = await fetchRunStatus({ module })
|
|
@@ -42,10 +42,7 @@ export const Header = observer((p: { st: TuiSt }) => {
|
|
|
42
42
|
<Text bold color="green">
|
|
43
43
|
{runHost.data.id}
|
|
44
44
|
</Text>
|
|
45
|
-
<Text color="gray">
|
|
46
|
-
{' '}
|
|
47
|
-
({runHost.base.host}:{runHost.base.port})
|
|
48
|
-
</Text>
|
|
45
|
+
<Text color="gray"> ({runHost.addressLabel})</Text>
|
|
49
46
|
{/* the override must stay loud: every run bypasses the workflow's own host */}
|
|
50
47
|
{s.hostOverride != null && s.hostOverride !== s.wf.host && (
|
|
51
48
|
<Text color="yellow"> ⇄ overrides {s.wf.host.data.id}</Text>
|
|
@@ -9,10 +9,7 @@ export const HostPanel = observer((p: { st: TuiSt }) => {
|
|
|
9
9
|
return (
|
|
10
10
|
<Box borderStyle="double" paddingX={1} flexDirection="column">
|
|
11
11
|
<Text bold>
|
|
12
|
-
host actions · <Text color="green">{h.host.data.id}</Text>{
|
|
13
|
-
<Text color="gray">
|
|
14
|
-
({h.host.base.host}:{h.host.base.port})
|
|
15
|
-
</Text>
|
|
12
|
+
host actions · <Text color="green">{h.host.data.id}</Text> <Text color="gray">({h.host.addressLabel})</Text>
|
|
16
13
|
{s.hostOverride != null && <Text color="yellow"> ⇄ override</Text>}
|
|
17
14
|
</Text>
|
|
18
15
|
{h.stats.map((row) => (
|
|
@@ -225,7 +225,7 @@ export class HostSt {
|
|
|
225
225
|
{ label: 'loras', value: String(schema.getLoras().length) },
|
|
226
226
|
{ label: 'embeddings', value: String(schema.data.embeddings.length) },
|
|
227
227
|
{ label: 'queue', value: String(this.st.queue.remaining) },
|
|
228
|
-
{ label: 'ws', value: this.host.getWSUrl() },
|
|
228
|
+
{ label: 'ws', value: this.host.noAddress ?? this.host.getWSUrl() },
|
|
229
229
|
]
|
|
230
230
|
}
|
|
231
231
|
|
|
@@ -251,7 +251,7 @@ export class HostSt {
|
|
|
251
251
|
for (const host of comfyts.hosts.values()) {
|
|
252
252
|
rows.push({
|
|
253
253
|
host,
|
|
254
|
-
label: `${host.data.id} (${host.
|
|
254
|
+
label: `${host.data.id} (${host.addressLabel})`,
|
|
255
255
|
active: this.st.hostOverride === host,
|
|
256
256
|
})
|
|
257
257
|
}
|
package/src/host/ComfyHost.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { logError as toastError, logInfo } from 'src/utils/log.ts'
|
|
|
40
40
|
import type { ComfyInstallType } from 'src/host/ComfyInstallType.ts'
|
|
41
41
|
import { ComfyManager } from 'src/host/ComfyManager.ts'
|
|
42
42
|
import { ComfyUploader } from 'src/host/ComfyUploader.ts'
|
|
43
|
+
import { namesNoAddress, readHostFile } from 'src/host/hostFile.ts'
|
|
43
44
|
import { type ParsedHostBase, parseHostBase, renderHttpBase, renderWsUrl } from 'src/host/hostUrl.ts'
|
|
44
45
|
import type { Requirements } from 'src/host/Requirements.ts'
|
|
45
46
|
import { ResilientWebSocketClient, type WsMessageEvent } from 'src/host/ResilientWebsocket.ts'
|
|
@@ -139,17 +140,44 @@ export class ComfyHost<ID extends string = string> {
|
|
|
139
140
|
schema: ComfySchema
|
|
140
141
|
uploader = new ComfyUploader(this)
|
|
141
142
|
|
|
142
|
-
/** parsed ONCE from data (url-first
|
|
143
|
-
|
|
143
|
+
/** parsed ONCE from data (url-first, legacy host/port/https, or the address `gen` saved for
|
|
144
|
+
* the id alone): the url ground truth. Throws the noAddress text when there is none */
|
|
145
|
+
get base(): ParsedHostBase {
|
|
146
|
+
this.readSavedAddress()
|
|
147
|
+
if (this._base == null) throw new Error(this.noAddress ?? `host '${this.data.id}': no address`)
|
|
148
|
+
return this._base
|
|
149
|
+
}
|
|
150
|
+
private _base: ParsedHostBase | null = null
|
|
144
151
|
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
/** why the id alone found no saved address; null when the host has one. An import stays safe
|
|
153
|
+
* (like a missing schema cache): the error is logged once, then thrown at first use */
|
|
154
|
+
noAddress: string | null = null
|
|
155
|
+
|
|
156
|
+
/** `host:port` for labels, or a short note when there is no address; never throws */
|
|
157
|
+
get addressLabel(): string {
|
|
158
|
+
return this._base == null ? 'no saved address' : `${this._base.host}:${this._base.port}`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** read again at each use until found: a `comfy-ts gen` run after the import (a TUI or a
|
|
162
|
+
* serve that stays up) makes the host usable without a restart */
|
|
163
|
+
private readSavedAddress(): void {
|
|
164
|
+
if (this._base != null || !namesNoAddress(this.data)) return
|
|
165
|
+
const saved = readHostFile(getComfyStorage(), this.cacheFolder, this.data.id)
|
|
166
|
+
this._base = saved.base
|
|
167
|
+
this.noAddress = saved.error
|
|
168
|
+
}
|
|
147
169
|
|
|
170
|
+
constructor(public data: ComfyHostData & { id: ID }) {
|
|
148
171
|
/** folder where file related to the host config will be cached */
|
|
149
172
|
this.cacheFolder = comfyts.resolveFromHosts(this.data.id)
|
|
173
|
+
const storage = getComfyStorage()
|
|
174
|
+
|
|
175
|
+
if (namesNoAddress(this.data)) {
|
|
176
|
+
this.readSavedAddress()
|
|
177
|
+
if (this.noAddress != null) toastError(this.noAddress)
|
|
178
|
+
} else this._base = parseHostBase(this.data)
|
|
150
179
|
|
|
151
180
|
// create the folder if it does not exist
|
|
152
|
-
const storage = getComfyStorage()
|
|
153
181
|
if (!storage.exists(this.cacheFolder)) {
|
|
154
182
|
console.log('🟢 creating folder', this.cacheFolder)
|
|
155
183
|
storage.mkdirp(this.cacheFolder)
|
|
@@ -398,6 +426,8 @@ export class ComfyHost<ID extends string = string> {
|
|
|
398
426
|
* - 'cache': never fetch (throws when no cache exists)
|
|
399
427
|
*/
|
|
400
428
|
connect = (p: ConnectOptions = {}): Promise<void> => {
|
|
429
|
+
this.readSavedAddress()
|
|
430
|
+
if (this.noAddress != null) return Promise.reject(new Error(this.noAddress))
|
|
401
431
|
if (this._ready == null) {
|
|
402
432
|
this._schemaStrategy = p.schema ?? 'auto'
|
|
403
433
|
this._schemaMaxAgeMs = p.maxAgeMs ?? 24 * 3600_000
|
|
@@ -689,6 +719,8 @@ export class ComfyHost<ID extends string = string> {
|
|
|
689
719
|
* cannot be reached, which is itself the signal a caller watches for a restart */
|
|
690
720
|
checkSchemaDrift = async (p: { full: boolean }): Promise<SchemaDrift> => {
|
|
691
721
|
const loaded: Record<string, unknown> = this.schema.data.spec
|
|
722
|
+
// no schema loaded yet (a TUI probes a host before its first run loads one): nothing to compare
|
|
723
|
+
if (Object.keys(loaded).length === 0) return { nodes: null, models: [] }
|
|
692
724
|
const live: Record<string, unknown> = {}
|
|
693
725
|
if (p.full) Object.assign(live, await this.fetchJSON_<Record<string, unknown>>('/object_info'))
|
|
694
726
|
else
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// .comfy-ts/hosts/<id>/host.json: the address `comfy-ts gen` saves, so code names a host by id
|
|
2
|
+
// alone. It holds the url only: an api key is never written to disk by comfy-ts.
|
|
3
|
+
import { join } from 'pathe'
|
|
4
|
+
import { type ParsedHostBase, parseHostBase } from 'src/host/hostUrl.ts'
|
|
5
|
+
import type { ComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
6
|
+
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
7
|
+
|
|
8
|
+
export type HostFile = { url: string }
|
|
9
|
+
|
|
10
|
+
export const HOST_FILE_NAME = 'host.json'
|
|
11
|
+
|
|
12
|
+
/** true when the caller gave no address at all: the id alone asks for the saved one */
|
|
13
|
+
export function namesNoAddress(p: { url?: string; host?: string; port?: number; https?: boolean }): boolean {
|
|
14
|
+
return p.url == null && p.host == null && p.port == null && p.https == null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function hostFilePath(hostFolder: string): string {
|
|
18
|
+
return join(hostFolder, HOST_FILE_NAME)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function writeHostFile(storage: ComfyStorage, hostFolder: string, file: HostFile): string {
|
|
22
|
+
const path = hostFilePath(hostFolder)
|
|
23
|
+
storage.writeText(path, `${JSON.stringify(file, null, 3)}\n`)
|
|
24
|
+
return path
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** the saved address of `id`, parsed; when there is none, the error text names the command that writes it */
|
|
28
|
+
export function readHostFile(
|
|
29
|
+
storage: ComfyStorage,
|
|
30
|
+
hostFolder: string,
|
|
31
|
+
id: string,
|
|
32
|
+
): { base: ParsedHostBase; error: null } | { base: null; error: string } {
|
|
33
|
+
const path = hostFilePath(hostFolder)
|
|
34
|
+
const gen = `\`comfy-ts gen --host <url> --id ${id}\``
|
|
35
|
+
const text = storage.readTextIfExists(path)
|
|
36
|
+
if (text == null) {
|
|
37
|
+
const fix =
|
|
38
|
+
storage.kind === 'node'
|
|
39
|
+
? `run ${gen} once from this project (it saves the address), or pass the address: host({ id: '${id}', url: '<url>' })`
|
|
40
|
+
: `this runtime has no saved hosts (${storage.kind} storage): pass the address, host({ id: '${id}', url: '<url>' })`
|
|
41
|
+
return { base: null, error: `host '${id}': no address given and no ${path}. ${fix}` }
|
|
42
|
+
}
|
|
43
|
+
let json: unknown
|
|
44
|
+
try {
|
|
45
|
+
json = JSON.parse(text)
|
|
46
|
+
} catch {
|
|
47
|
+
return { base: null, error: `host '${id}': ${path} is not valid json. Write it again with ${gen}` }
|
|
48
|
+
}
|
|
49
|
+
const url = json != null && typeof json === 'object' && 'url' in json ? json.url : null
|
|
50
|
+
if (typeof url !== 'string' || url === '')
|
|
51
|
+
return { base: null, error: `host '${id}': ${path} has no "url" string. Write it again with ${gen}` }
|
|
52
|
+
try {
|
|
53
|
+
return { base: parseHostBase({ id, url }), error: null }
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return { base: null, error: `${extractErrorMessage(e)} (read from ${path})` }
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/state.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join } from 'pathe'
|
|
2
2
|
import pkgJson from '../package.json' with { type: 'json' }
|
|
3
3
|
import { ComfyHost, type ComfyHostData } from 'src/host/ComfyHost.ts'
|
|
4
|
+
import { namesNoAddress } from 'src/host/hostFile.ts'
|
|
4
5
|
import { parseHostBase, renderHttpBase } from 'src/host/hostUrl.ts'
|
|
5
6
|
import { ComfyRegistry } from 'src/manager/ComfyRegistry.ts'
|
|
6
7
|
import { type ComfyStorage, resolveComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
@@ -55,19 +56,24 @@ export class ComfyTS {
|
|
|
55
56
|
const existing = this.hosts.get(data.id)
|
|
56
57
|
if (existing != null) {
|
|
57
58
|
// identity = the parsed base quad + apiKey PRESENCE (equivalent url and
|
|
58
|
-
// host/port spellings unify; the key VALUE never appears in the error)
|
|
59
|
-
|
|
60
|
-
const
|
|
59
|
+
// host/port spellings unify; the key VALUE never appears in the error).
|
|
60
|
+
// The id alone names no address, so it asks for whatever is registered
|
|
61
|
+
const incoming = namesNoAddress(data) ? null : parseHostBase(data)
|
|
62
|
+
const cur = existing.noAddress == null ? existing.base : null
|
|
61
63
|
const sameBase =
|
|
62
|
-
|
|
63
|
-
cur
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
incoming == null ||
|
|
65
|
+
(cur != null &&
|
|
66
|
+
cur.scheme === incoming.scheme &&
|
|
67
|
+
cur.host === incoming.host &&
|
|
68
|
+
cur.port === incoming.port &&
|
|
69
|
+
cur.basePath === incoming.basePath)
|
|
66
70
|
const sameAuth = (existing.data.apiKey == null) === (data.apiKey == null)
|
|
67
|
-
if (!sameBase || !sameAuth)
|
|
71
|
+
if (!sameBase || !sameAuth) {
|
|
72
|
+
const authed = (p: { apiKey?: string }): string => (p.apiKey != null ? ' (authed)' : '')
|
|
68
73
|
throw new Error(
|
|
69
|
-
`host id '${data.id}' already registered
|
|
74
|
+
`host id '${data.id}' already registered ${cur == null ? 'with no address' : `at ${renderHttpBase(cur)}`}${authed(existing.data)} — refusing ${incoming == null ? 'the id alone' : renderHttpBase(incoming)}${authed(data)}`,
|
|
70
75
|
)
|
|
76
|
+
}
|
|
71
77
|
// cast: whitelist item 7 (agent/coding.md) — id equality checked just above
|
|
72
78
|
return existing as ComfyHost<ID>
|
|
73
79
|
}
|