comfy-ts 2.18.1 → 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 (65) hide show
  1. package/README.md +147 -97
  2. package/claude-code/.claude-plugin/plugin.json +9 -0
  3. package/claude-code/skills/convert/SKILL.md +25 -0
  4. package/claude-code/skills/guide/SKILL.md +21 -0
  5. package/claude-code/skills/run/SKILL.md +12 -0
  6. package/claude-code/skills/setup/SKILL.md +15 -0
  7. package/claude-code/skills/workflow/SKILL.md +19 -0
  8. package/dist/{ServeApp-qXcQfdgT.js → ServeApp-B469W26E.js} +5 -5
  9. package/dist/{ServeApp-qXcQfdgT.js.map → ServeApp-B469W26E.js.map} +1 -1
  10. package/dist/cli.js +228 -11
  11. package/dist/cli.js.map +1 -1
  12. package/dist/{state-C067Kbew.js → exampleAssets-j1f26nGc.js} +177 -56
  13. package/dist/{state-C067Kbew.js.map → exampleAssets-j1f26nGc.js.map} +1 -1
  14. package/dist/{findDefinedWorkflow-0lG-VTEd.js → findDefinedWorkflow-B90-xFxX.js} +2 -2
  15. package/dist/{findDefinedWorkflow-0lG-VTEd.js.map → findDefinedWorkflow-B90-xFxX.js.map} +1 -1
  16. package/dist/index.cjs +92 -10
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +12 -2
  19. package/dist/index.d.ts +12 -2
  20. package/dist/index.js +92 -10
  21. package/dist/index.js.map +1 -1
  22. package/dist/{run-run-Zr699h2S.js → run-run-QEoh7Wbh.js} +5 -6
  23. package/dist/{run-run-Zr699h2S.js.map → run-run-QEoh7Wbh.js.map} +1 -1
  24. package/dist/{run-serve-DaXzoVTS.js → run-serve-CsEYPGm9.js} +4 -4
  25. package/dist/{run-serve-DaXzoVTS.js.map → run-serve-CsEYPGm9.js.map} +1 -1
  26. package/dist/{run-tui-CeM1GOJP.js → run-tui-YxiSoNvK.js} +9 -15
  27. package/dist/run-tui-YxiSoNvK.js.map +1 -0
  28. package/dist/{schemaDrift-CbsABBuk.js → schemaDrift-DaWsE-mt.js} +15 -15
  29. package/dist/{schemaDrift-CbsABBuk.js.map → schemaDrift-DaWsE-mt.js.map} +1 -1
  30. package/dist/web.d.ts +30 -20
  31. package/dist/web.js +83 -6
  32. package/dist/web.js.map +1 -1
  33. package/examples/README.md +17 -11
  34. package/examples/rvion/01-txt2img.cflow.ts +1 -1
  35. package/examples/rvion/02-img2img-upload.cflow.ts +1 -1
  36. package/examples/rvion/03-export-workflow-json.cflow.ts +1 -1
  37. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +1 -1
  38. package/examples/rvion/06-qwen-image-edit.cflow.ts +1 -1
  39. package/examples/rvion/07-local-llm-text-gen.cflow.ts +1 -1
  40. package/examples/rvion/08-qwen-image-21-t2i.cflow.ts +1 -1
  41. package/examples/rvion/09-qwen-image-21-edit.cflow.ts +1 -1
  42. package/examples/rvion/10-anima-t2i.cflow.ts +1 -1
  43. package/examples/rvion/11-yue2-t2a.cflow.ts +1 -1
  44. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +1 -1
  45. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +1 -1
  46. package/examples/rvion/14-video-soundtrack.cflow.ts +1 -1
  47. package/examples/rvion/15-tts-voice-clone.cflow.ts +1 -1
  48. package/examples/rvion/16-tts-voice-design.cflow.ts +1 -1
  49. package/guide-for-agents.md +8 -5
  50. package/package.json +8 -7
  51. package/src/cli/comfy-ts-cli.ts +12 -2
  52. package/src/cli/gen.ts +6 -1
  53. package/src/cli/serve/ServeApp.ts +4 -4
  54. package/src/cli/serve/web/api.ts +1 -1
  55. package/src/cli/skill.ts +207 -0
  56. package/src/cli/tui/components/Header.tsx +1 -4
  57. package/src/cli/tui/components/HostPanel.tsx +1 -4
  58. package/src/cli/tui/state/HostSt.ts +2 -2
  59. package/src/exampleAssets.ts +10 -4
  60. package/src/host/ComfyHost.ts +35 -5
  61. package/src/host/hostFile.ts +57 -0
  62. package/src/state.ts +15 -9
  63. package/dist/exampleAssets-BfWzygoM.js +0 -38
  64. package/dist/exampleAssets-BfWzygoM.js.map +0 -1
  65. package/dist/run-tui-CeM1GOJP.js.map +0 -1
@@ -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
  }
@@ -12,6 +12,15 @@ import { dirname, join } from 'pathe'
12
12
  * package.json all the way up is a broken install and throws.
13
13
  */
14
14
  export function bundledExamplesDir(moduleUrl: string = import.meta.url): string | null {
15
+ const pkgDir = comfyTsPackageDir(moduleUrl)
16
+ if (pkgDir == null) return null
17
+ const examples = join(pkgDir, 'examples')
18
+ return existsSync(examples) ? examples : null
19
+ }
20
+
21
+ /** the comfy-ts package root (the folder of its package.json), by the same walk: null when the
22
+ * nearest named package is another one, a throw when no package.json is found at all */
23
+ export function comfyTsPackageDir(moduleUrl: string = import.meta.url): string | null {
15
24
  let dir = dirname(fileURLToPath(moduleUrl))
16
25
  let prev = ''
17
26
  while (dir !== prev) {
@@ -24,10 +33,7 @@ export function bundledExamplesDir(moduleUrl: string = import.meta.url): string
24
33
  // a malformed package.json on the walk (someone's broken fixture
25
34
  // dir) must not take the whole TUI down; treat as unnamed
26
35
  }
27
- if (pkg.name === 'comfy-ts') {
28
- const examples = join(dir, 'examples')
29
- return existsSync(examples) ? examples : null
30
- }
36
+ if (pkg.name === 'comfy-ts') return dir
31
37
  if (pkg.name != null) return null
32
38
  }
33
39
  prev = dir
@@ -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
  }
@@ -1,38 +0,0 @@
1
- import { fileURLToPath } from "node:url";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import { dirname, join } from "pathe";
4
- //#region src/exampleAssets.ts
5
- /**
6
- * the examples/ folder shipped in the npm tarball, resolved from THIS module's
7
- * own location (NEVER cwd): walking up to the nearest NAMED package.json finds
8
- * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from
9
- * this repo's src/. Returns null when the examples are absent (a consumer may
10
- * prune the folder) or when the nearest named package is not comfy-ts (the lib
11
- * was inlined into someone else's bundle — its examples are not on disk); no
12
- * package.json all the way up is a broken install and throws.
13
- */
14
- function bundledExamplesDir(moduleUrl = import.meta.url) {
15
- let dir = dirname(fileURLToPath(moduleUrl));
16
- let prev = "";
17
- while (dir !== prev) {
18
- const pkgPath = join(dir, "package.json");
19
- if (existsSync(pkgPath)) {
20
- let pkg = {};
21
- try {
22
- pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
23
- } catch {}
24
- if (pkg.name === "comfy-ts") {
25
- const examples = join(dir, "examples");
26
- return existsSync(examples) ? examples : null;
27
- }
28
- if (pkg.name != null) return null;
29
- }
30
- prev = dir;
31
- dir = dirname(dir);
32
- }
33
- throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`);
34
- }
35
- //#endregion
36
- export { bundledExamplesDir as t };
37
-
38
- //# sourceMappingURL=exampleAssets-BfWzygoM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exampleAssets-BfWzygoM.js","names":[],"sources":["../src/exampleAssets.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { dirname, join } from 'pathe'\n\n/**\n * the examples/ folder shipped in the npm tarball, resolved from THIS module's\n * own location (NEVER cwd): walking up to the nearest NAMED package.json finds\n * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from\n * this repo's src/. Returns null when the examples are absent (a consumer may\n * prune the folder) or when the nearest named package is not comfy-ts (the lib\n * was inlined into someone else's bundle — its examples are not on disk); no\n * package.json all the way up is a broken install and throws.\n */\nexport function bundledExamplesDir(moduleUrl: string = import.meta.url): string | null {\n let dir = dirname(fileURLToPath(moduleUrl))\n let prev = ''\n while (dir !== prev) {\n const pkgPath = join(dir, 'package.json')\n if (existsSync(pkgPath)) {\n let pkg: { name?: string } = {}\n try {\n pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))\n } catch {\n // a malformed package.json on the walk (someone's broken fixture\n // dir) must not take the whole TUI down; treat as unnamed\n }\n if (pkg.name === 'comfy-ts') {\n const examples = join(dir, 'examples')\n return existsSync(examples) ? examples : null\n }\n if (pkg.name != null) return null\n }\n prev = dir\n dir = dirname(dir)\n }\n throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`)\n}\n\n/**\n * absolute path of a bundled `examples/images/` input image, e.g.\n * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for\n * i2i/i2v example image vars, valid from this repo AND from a consumer's\n * node_modules/comfy-ts/. Loud throw naming the path when the file is missing\n * or the package's examples/ folder was pruned.\n */\nexport function exampleImagePath(name: string): string {\n return bundledExampleFile('images', name)\n}\n\n/** the same for a bundled `examples/media/` audio or video file, e.g.\n * `exampleMediaPath('sine_440hz_3s.flac')` — the default of audio and video example vars */\nexport function exampleMediaPath(name: string): string {\n return bundledExampleFile('media', name)\n}\n\nfunction bundledExampleFile(folder: 'images' | 'media', name: string): string {\n const examples = bundledExamplesDir()\n if (examples == null) {\n throw new Error(\n `[comfy-ts] cannot resolve bundled example file '${name}': the package's examples/ folder is not on disk`,\n )\n }\n const abs = join(examples, folder, name)\n if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example file not found: ${abs}`)\n return abs\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,YAAoB,OAAO,KAAK,KAAoB;CACpF,IAAI,MAAM,QAAQ,cAAc,SAAS,CAAC;CAC1C,IAAI,OAAO;CACX,OAAO,QAAQ,MAAM;EAClB,MAAM,UAAU,KAAK,KAAK,cAAc;EACxC,IAAI,WAAW,OAAO,GAAG;GACtB,IAAI,MAAyB,CAAC;GAC9B,IAAI;IACD,MAAM,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC;GACjD,QAAQ,CAGR;GACA,IAAI,IAAI,SAAS,YAAY;IAC1B,MAAM,WAAW,KAAK,KAAK,UAAU;IACrC,OAAO,WAAW,QAAQ,IAAI,WAAW;GAC5C;GACA,IAAI,IAAI,QAAQ,MAAM,OAAO;EAChC;EACA,OAAO;EACP,MAAM,QAAQ,GAAG;CACpB;CACA,MAAM,IAAI,MAAM,oDAAoD,cAAc,SAAS,GAAG;AACjG"}