comfy-ts 2.19.0 → 2.20.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.
Files changed (57) hide show
  1. package/README.md +9 -4
  2. package/claude-code/skills/setup/SKILL.md +1 -1
  3. package/dist/{ServeApp-qXcQfdgT.js → ServeApp-B469W26E.js} +5 -5
  4. package/dist/{ServeApp-qXcQfdgT.js.map → ServeApp-B469W26E.js.map} +1 -1
  5. package/dist/cli.js +12 -8
  6. package/dist/cli.js.map +1 -1
  7. package/dist/{exampleAssets-CE4PUy3n.js → exampleAssets-j1f26nGc.js} +137 -55
  8. package/dist/exampleAssets-j1f26nGc.js.map +1 -0
  9. package/dist/{findDefinedWorkflow-0lG-VTEd.js → findDefinedWorkflow-B90-xFxX.js} +2 -2
  10. package/dist/{findDefinedWorkflow-0lG-VTEd.js.map → findDefinedWorkflow-B90-xFxX.js.map} +1 -1
  11. package/dist/index.cjs +83 -6
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +12 -2
  14. package/dist/index.d.ts +12 -2
  15. package/dist/index.js +83 -6
  16. package/dist/index.js.map +1 -1
  17. package/dist/{run-run-C_yXY0vl.js → run-run-QEoh7Wbh.js} +5 -5
  18. package/dist/{run-run-C_yXY0vl.js.map → run-run-QEoh7Wbh.js.map} +1 -1
  19. package/dist/{run-serve-DaXzoVTS.js → run-serve-CsEYPGm9.js} +4 -4
  20. package/dist/{run-serve-DaXzoVTS.js.map → run-serve-CsEYPGm9.js.map} +1 -1
  21. package/dist/{run-tui-B3dsftdB.js → run-tui-YxiSoNvK.js} +9 -14
  22. package/dist/run-tui-YxiSoNvK.js.map +1 -0
  23. package/dist/{schemaDrift-CbsABBuk.js → schemaDrift-DaWsE-mt.js} +15 -15
  24. package/dist/{schemaDrift-CbsABBuk.js.map → schemaDrift-DaWsE-mt.js.map} +1 -1
  25. package/dist/web.d.ts +12 -2
  26. package/dist/web.js +83 -6
  27. package/dist/web.js.map +1 -1
  28. package/examples/README.md +1 -1
  29. package/examples/rvion/01-txt2img.cflow.ts +1 -1
  30. package/examples/rvion/02-img2img-upload.cflow.ts +1 -1
  31. package/examples/rvion/03-export-workflow-json.cflow.ts +1 -1
  32. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +1 -1
  33. package/examples/rvion/06-qwen-image-edit.cflow.ts +1 -1
  34. package/examples/rvion/07-local-llm-text-gen.cflow.ts +1 -1
  35. package/examples/rvion/08-qwen-image-21-t2i.cflow.ts +1 -1
  36. package/examples/rvion/09-qwen-image-21-edit.cflow.ts +1 -1
  37. package/examples/rvion/10-anima-t2i.cflow.ts +1 -1
  38. package/examples/rvion/11-yue2-t2a.cflow.ts +1 -1
  39. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +1 -1
  40. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +1 -1
  41. package/examples/rvion/14-video-soundtrack.cflow.ts +1 -1
  42. package/examples/rvion/15-tts-voice-clone.cflow.ts +1 -1
  43. package/examples/rvion/16-tts-voice-design.cflow.ts +1 -1
  44. package/guide-for-agents.md +4 -4
  45. package/package.json +6 -6
  46. package/src/cli/comfy-ts-cli.ts +4 -2
  47. package/src/cli/gen.ts +6 -1
  48. package/src/cli/serve/ServeApp.ts +4 -4
  49. package/src/cli/serve/web/api.ts +1 -1
  50. package/src/cli/tui/components/Header.tsx +1 -4
  51. package/src/cli/tui/components/HostPanel.tsx +1 -4
  52. package/src/cli/tui/state/HostSt.ts +2 -2
  53. package/src/host/ComfyHost.ts +35 -5
  54. package/src/host/hostFile.ts +57 -0
  55. package/src/state.ts +15 -9
  56. package/dist/exampleAssets-CE4PUy3n.js.map +0 -1
  57. package/dist/run-tui-B3dsftdB.js.map +0 -1
@@ -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. Edit the `comfy.host({...})` line to point at yours, and the first run generates a typed SDK for it.
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
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', host: 'desktop-im18794', port: 8085 })
11
+ const host = comfy.host({ id: 'windows-1' })
12
12
  await host.loadSchemaFromCache() // offline import; run() connects lazily
13
13
 
14
14
  const LANGUAGES = [
@@ -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', host: '127.0.0.1', port: 8188 })
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.19.0",
3
+ "version": "2.20.0",
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",
@@ -71,8 +71,8 @@
71
71
  "build:watch": "tsdown --watch",
72
72
  "test": "bun test --parallel --no-isolate",
73
73
  "test:watch": "bun test --watch",
74
- "typecheck": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
75
- "typecheck:lib": "tsc -p tsconfig.lib.json && tsc -p src/cli/serve/web/tsconfig.json",
74
+ "typecheck": "tsc -p tsconfig.lib.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
75
+ "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
76
  "lint": "oxlint src examples scripts tests",
77
77
  "format": "oxfmt src examples scripts tests",
78
78
  "format:check": "oxfmt --check src examples scripts tests",
@@ -80,8 +80,8 @@
80
80
  "imports:fix": "rvt imports --fix",
81
81
  "cycles": "rvt cycles 1",
82
82
  "rename": "rvt rename",
83
- "ci": "bun run typecheck:lib && bun run lint && bun run format:check && bun run imports:check && bun run test",
84
- "ci:local": "bun run ci && bun run typecheck",
83
+ "ci": "bun run typecheck && bun run lint && bun run format:check && bun run imports:check && bun run test",
84
+ "ci:local": "bun run ci && bun run typecheck:full",
85
85
  "gen:manager": "bun src/manager/script-update-manager.bun.ts",
86
86
  "gen:sdk": "bun scripts/gen-sdk-from-cache.ts",
87
87
  "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 +141,7 @@
141
141
  "oxfmt": "^0.60.0",
142
142
  "oxlint": "^1.75.0",
143
143
  "oxlint-tsgolint": "^7.0.2001",
144
- "rvlib-shipkit": "^2.25.0",
144
+ "rvlib-shipkit": "^2.26.0",
145
145
  "rvlib-ts-tools": "^0.3.3",
146
146
  "tsdown": "^0.22.14",
147
147
  "typescript": "^7.0.2"
@@ -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
- (--api-key or COMFY_CLOUD_API_KEY authenticates via X-API-Key;
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 = join(process.cwd(), '.comfy-ts', 'hosts', id)
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: `${host.base.host}:${host.base.port}`,
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) {
@@ -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
  }
@@ -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.base.host}:${host.base.port})`,
254
+ label: `${host.data.id} (${host.addressLabel})`,
255
255
  active: this.st.hostOverride === host,
256
256
  })
257
257
  }
@@ -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 or legacy host/port/https) — the url ground truth */
143
- readonly base: ParsedHostBase
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
- constructor(public data: ComfyHostData & { id: ID }) {
146
- this.base = parseHostBase(this.data)
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
@@ -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
- const incoming = parseHostBase(data)
60
- const cur = existing.base
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
- cur.scheme === incoming.scheme &&
63
- cur.host === incoming.host &&
64
- cur.port === incoming.port &&
65
- cur.basePath === incoming.basePath
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 at ${renderHttpBase(cur)}${existing.data.apiKey != null ? ' (authed)' : ''} — refusing ${renderHttpBase(incoming)}${data.apiKey != null ? ' (authed)' : ''}`,
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
  }