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
@@ -1,8 +1,109 @@
1
- import { X as ansi, a as DefinedWorkflow, at as extractErrorMessage, ct as getComfyStorage, dt as logError, ft as logInfo, ht as sha1HexOfString, it as hashArrayBuffer, lt as resolveComfyStorage, mt as statelessRegex, n as diffSchemas, nt as isVideoFilename, ot as isRecord$1, pt as logSuccess, rt as mediaMime, st as bang, t as MODEL_LISTS, ut as isQuiet } from "./schemaDrift-CbsABBuk.js";
2
- import { basename, join } from "pathe";
1
+ import { X as ansi, a as DefinedWorkflow, at as isRecord$1, ct as resolveComfyStorage, dt as logInfo, ft as logSuccess, ht as extractErrorMessage, it as hashArrayBuffer, lt as isQuiet, mt as sha1HexOfString, n as diffSchemas, nt as isVideoFilename, ot as bang, pt as statelessRegex, rt as mediaMime, st as getComfyStorage, t as MODEL_LISTS, ut as logError } from "./schemaDrift-DaWsE-mt.js";
2
+ import { fileURLToPath } from "node:url";
3
+ import { existsSync, readFileSync } from "node:fs";
4
+ import { basename, dirname, join } from "pathe";
3
5
  import { scope, type } from "arktype";
4
6
  import { nanoid } from "nanoid";
5
7
  import { imageMeta } from "image-meta";
8
+ //#region src/host/hostUrl.ts
9
+ /** exactly ONE of `url` or the legacy `host`+`port` (+`https?`) spelling */
10
+ function parseHostBase(p) {
11
+ const hasLegacy = p.host != null || p.port != null || p.https != null;
12
+ if (p.url != null && hasLegacy) throw new Error(`host '${p.id}': give either url OR host/port/https, not both spellings at once`);
13
+ if (p.url == null) {
14
+ if (p.host == null || p.port == null) throw new Error(`host '${p.id}': needs either url, or host AND port (got host=${p.host}, port=${p.port})`);
15
+ return {
16
+ scheme: p.https ? "https" : "http",
17
+ host: p.host,
18
+ port: p.port,
19
+ basePath: ""
20
+ };
21
+ }
22
+ let parsed;
23
+ try {
24
+ parsed = new URL(p.url);
25
+ } catch {
26
+ throw new Error(`host '${p.id}': unparseable url '${p.url}'`);
27
+ }
28
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error(`host '${p.id}': url scheme must be http or https, got '${parsed.protocol}' in '${p.url}'`);
29
+ if (parsed.search !== "" || parsed.hash !== "") throw new Error(`host '${p.id}': url must be a plain base (no ?query or #hash), got '${p.url}'`);
30
+ const scheme = parsed.protocol === "https:" ? "https" : "http";
31
+ const port = parsed.port !== "" ? Number(parsed.port) : scheme === "https" ? 443 : 80;
32
+ const basePath = parsed.pathname.replace(/\/+$/, "");
33
+ return {
34
+ scheme,
35
+ host: parsed.hostname,
36
+ port,
37
+ basePath
38
+ };
39
+ }
40
+ /** http(s) base, port omitted when it is the scheme default */
41
+ function renderHttpBase(p) {
42
+ return `${p.scheme}://${p.host}${renderPort(p)}${p.basePath}`;
43
+ }
44
+ /** ws(s) endpoint; auth rides the upgrade headers — EXCEPT headerless
45
+ * transports (browser), where the ws client remaps X-API-Key to ?token= */
46
+ function renderWsUrl(p) {
47
+ return `${p.scheme === "https" ? "wss" : "ws"}://${p.host}${renderPort(p)}${p.basePath}/ws`;
48
+ }
49
+ function renderPort(p) {
50
+ const schemeDefault = p.scheme === "https" ? 443 : 80;
51
+ return p.port === schemeDefault ? "" : `:${p.port}`;
52
+ }
53
+ //#endregion
54
+ //#region src/host/hostFile.ts
55
+ const HOST_FILE_NAME = "host.json";
56
+ /** true when the caller gave no address at all: the id alone asks for the saved one */
57
+ function namesNoAddress(p) {
58
+ return p.url == null && p.host == null && p.port == null && p.https == null;
59
+ }
60
+ function hostFilePath(hostFolder) {
61
+ return join(hostFolder, HOST_FILE_NAME);
62
+ }
63
+ function writeHostFile(storage, hostFolder, file) {
64
+ const path = hostFilePath(hostFolder);
65
+ storage.writeText(path, `${JSON.stringify(file, null, 3)}\n`);
66
+ return path;
67
+ }
68
+ /** the saved address of `id`, parsed; when there is none, the error text names the command that writes it */
69
+ function readHostFile(storage, hostFolder, id) {
70
+ const path = hostFilePath(hostFolder);
71
+ const gen = `\`comfy-ts gen --host <url> --id ${id}\``;
72
+ const text = storage.readTextIfExists(path);
73
+ if (text == null) return {
74
+ base: null,
75
+ error: `host '${id}': no address given and no ${path}. ${storage.kind === "node" ? `run ${gen} once from this project (it saves the address), or pass the address: host({ id: '${id}', url: '<url>' })` : `this runtime has no saved hosts (${storage.kind} storage): pass the address, host({ id: '${id}', url: '<url>' })`}`
76
+ };
77
+ let json;
78
+ try {
79
+ json = JSON.parse(text);
80
+ } catch {
81
+ return {
82
+ base: null,
83
+ error: `host '${id}': ${path} is not valid json. Write it again with ${gen}`
84
+ };
85
+ }
86
+ const url = json != null && typeof json === "object" && "url" in json ? json.url : null;
87
+ if (typeof url !== "string" || url === "") return {
88
+ base: null,
89
+ error: `host '${id}': ${path} has no "url" string. Write it again with ${gen}`
90
+ };
91
+ try {
92
+ return {
93
+ base: parseHostBase({
94
+ id,
95
+ url
96
+ }),
97
+ error: null
98
+ };
99
+ } catch (e) {
100
+ return {
101
+ base: null,
102
+ error: `${extractErrorMessage(e)} (read from ${path})`
103
+ };
104
+ }
105
+ }
106
+ //#endregion
6
107
  //#region src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts
7
108
  /** having a bunch of sensible default will help slightly */
8
109
  function getUnionNameBasedOnFirstFoundEnumName(enumName, hash, hashContent) {
@@ -902,7 +1003,7 @@ var ComfySchema = class {
902
1003
  };
903
1004
  //#endregion
904
1005
  //#region package.json
905
- var version = "2.18.1";
1006
+ var version = "2.20.0";
906
1007
  //#endregion
907
1008
  //#region src/litegraph/LiteGraphLinkID.ts
908
1009
  const asLiteGraphLinkID = (id) => id;
@@ -4671,52 +4772,6 @@ var ComfyUploader = class {
4671
4772
  }
4672
4773
  };
4673
4774
  //#endregion
4674
- //#region src/host/hostUrl.ts
4675
- /** exactly ONE of `url` or the legacy `host`+`port` (+`https?`) spelling */
4676
- function parseHostBase(p) {
4677
- const hasLegacy = p.host != null || p.port != null || p.https != null;
4678
- if (p.url != null && hasLegacy) throw new Error(`host '${p.id}': give either url OR host/port/https, not both spellings at once`);
4679
- if (p.url == null) {
4680
- if (p.host == null || p.port == null) throw new Error(`host '${p.id}': needs either url, or host AND port (got host=${p.host}, port=${p.port})`);
4681
- return {
4682
- scheme: p.https ? "https" : "http",
4683
- host: p.host,
4684
- port: p.port,
4685
- basePath: ""
4686
- };
4687
- }
4688
- let parsed;
4689
- try {
4690
- parsed = new URL(p.url);
4691
- } catch {
4692
- throw new Error(`host '${p.id}': unparseable url '${p.url}'`);
4693
- }
4694
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error(`host '${p.id}': url scheme must be http or https, got '${parsed.protocol}' in '${p.url}'`);
4695
- if (parsed.search !== "" || parsed.hash !== "") throw new Error(`host '${p.id}': url must be a plain base (no ?query or #hash), got '${p.url}'`);
4696
- const scheme = parsed.protocol === "https:" ? "https" : "http";
4697
- const port = parsed.port !== "" ? Number(parsed.port) : scheme === "https" ? 443 : 80;
4698
- const basePath = parsed.pathname.replace(/\/+$/, "");
4699
- return {
4700
- scheme,
4701
- host: parsed.hostname,
4702
- port,
4703
- basePath
4704
- };
4705
- }
4706
- /** http(s) base, port omitted when it is the scheme default */
4707
- function renderHttpBase(p) {
4708
- return `${p.scheme}://${p.host}${renderPort(p)}${p.basePath}`;
4709
- }
4710
- /** ws(s) endpoint; auth rides the upgrade headers — EXCEPT headerless
4711
- * transports (browser), where the ws client remaps X-API-Key to ?token= */
4712
- function renderWsUrl(p) {
4713
- return `${p.scheme === "https" ? "wss" : "ws"}://${p.host}${renderPort(p)}${p.basePath}/ws`;
4714
- }
4715
- function renderPort(p) {
4716
- const schemeDefault = p.scheme === "https" ? 443 : 80;
4717
- return p.port === schemeDefault ? "" : `:${p.port}`;
4718
- }
4719
- //#endregion
4720
4775
  //#region src/host/ResilientWebsocket.ts
4721
4776
  let transportPromise = null;
4722
4777
  /** node: the ws package (headers on the upgrade). browser: native WebSocket. */
@@ -4907,9 +4962,30 @@ var ComfyHostAuthError = class extends Error {
4907
4962
  }
4908
4963
  };
4909
4964
  var ComfyHost = class {
4965
+ /** parsed ONCE from data (url-first, legacy host/port/https, or the address `gen` saved for
4966
+ * the id alone): the url ground truth. Throws the noAddress text when there is none */
4967
+ get base() {
4968
+ this.readSavedAddress();
4969
+ if (this._base == null) throw new Error(this.noAddress ?? `host '${this.data.id}': no address`);
4970
+ return this._base;
4971
+ }
4972
+ /** `host:port` for labels, or a short note when there is no address; never throws */
4973
+ get addressLabel() {
4974
+ return this._base == null ? "no saved address" : `${this._base.host}:${this._base.port}`;
4975
+ }
4976
+ /** read again at each use until found: a `comfy-ts gen` run after the import (a TUI or a
4977
+ * serve that stays up) makes the host usable without a restart */
4978
+ readSavedAddress() {
4979
+ if (this._base != null || !namesNoAddress(this.data)) return;
4980
+ const saved = readHostFile(getComfyStorage(), this.cacheFolder, this.data.id);
4981
+ this._base = saved.base;
4982
+ this.noAddress = saved.error;
4983
+ }
4910
4984
  constructor(data) {
4911
4985
  this.data = data;
4912
4986
  this.uploader = new ComfyUploader(this);
4987
+ this._base = null;
4988
+ this.noAddress = null;
4913
4989
  this.matchRequirements = (requirements) => this.manager.matchRequirements(requirements);
4914
4990
  this.checkRequirements = (requirements) => this.manager.checkRequirements(requirements);
4915
4991
  this.serverLogs = [];
@@ -5019,6 +5095,8 @@ var ComfyHost = class {
5019
5095
  this._schemaStrategy = "auto";
5020
5096
  this._schemaMaxAgeMs = 24 * 36e5;
5021
5097
  this.connect = (p = {}) => {
5098
+ this.readSavedAddress();
5099
+ if (this.noAddress != null) return Promise.reject(new Error(this.noAddress));
5022
5100
  if (this._ready == null) {
5023
5101
  this._schemaStrategy = p.schema ?? "auto";
5024
5102
  this._schemaMaxAgeMs = p.maxAgeMs ?? 24 * 36e5;
@@ -5178,10 +5256,13 @@ var ComfyHost = class {
5178
5256
  this._unknownWsEventTypes = /* @__PURE__ */ new Set();
5179
5257
  this.status = null;
5180
5258
  this.lastWsMessageAt = null;
5181
- this.base = parseHostBase(this.data);
5182
5259
  /** folder where file related to the host config will be cached */
5183
5260
  this.cacheFolder = comfyts.resolveFromHosts(this.data.id);
5184
5261
  const storage = getComfyStorage();
5262
+ if (namesNoAddress(this.data)) {
5263
+ this.readSavedAddress();
5264
+ if (this.noAddress != null) logError(this.noAddress);
5265
+ } else this._base = parseHostBase(this.data);
5185
5266
  if (!storage.exists(this.cacheFolder)) {
5186
5267
  console.log("🟢 creating folder", this.cacheFolder);
5187
5268
  storage.mkdirp(this.cacheFolder);
@@ -6083,11 +6164,14 @@ var ComfyTS = class ComfyTS {
6083
6164
  host(data) {
6084
6165
  const existing = this.hosts.get(data.id);
6085
6166
  if (existing != null) {
6086
- const incoming = parseHostBase(data);
6087
- const cur = existing.base;
6088
- const sameBase = cur.scheme === incoming.scheme && cur.host === incoming.host && cur.port === incoming.port && cur.basePath === incoming.basePath;
6167
+ const incoming = namesNoAddress(data) ? null : parseHostBase(data);
6168
+ const cur = existing.noAddress == null ? existing.base : null;
6169
+ const sameBase = incoming == null || cur != null && cur.scheme === incoming.scheme && cur.host === incoming.host && cur.port === incoming.port && cur.basePath === incoming.basePath;
6089
6170
  const sameAuth = existing.data.apiKey == null === (data.apiKey == null);
6090
- if (!sameBase || !sameAuth) throw new Error(`host id '${data.id}' already registered at ${renderHttpBase(cur)}${existing.data.apiKey != null ? " (authed)" : ""} — refusing ${renderHttpBase(incoming)}${data.apiKey != null ? " (authed)" : ""}`);
6171
+ if (!sameBase || !sameAuth) {
6172
+ const authed = (p) => p.apiKey != null ? " (authed)" : "";
6173
+ throw new Error(`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)}`);
6174
+ }
6091
6175
  return existing;
6092
6176
  }
6093
6177
  const created = new ComfyHost(data);
@@ -6136,6 +6220,43 @@ var ComfyTS = class ComfyTS {
6136
6220
  }
6137
6221
  };
6138
6222
  //#endregion
6139
- export { ComfySchema as a, importSharp as i, settingsPathFor as n, readableStringify as r, ComfyTS as t };
6223
+ //#region src/exampleAssets.ts
6224
+ /**
6225
+ * the examples/ folder shipped in the npm tarball, resolved from THIS module's
6226
+ * own location (NEVER cwd): walking up to the nearest NAMED package.json finds
6227
+ * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from
6228
+ * this repo's src/. Returns null when the examples are absent (a consumer may
6229
+ * prune the folder) or when the nearest named package is not comfy-ts (the lib
6230
+ * was inlined into someone else's bundle — its examples are not on disk); no
6231
+ * package.json all the way up is a broken install and throws.
6232
+ */
6233
+ function bundledExamplesDir(moduleUrl = import.meta.url) {
6234
+ const pkgDir = comfyTsPackageDir(moduleUrl);
6235
+ if (pkgDir == null) return null;
6236
+ const examples = join(pkgDir, "examples");
6237
+ return existsSync(examples) ? examples : null;
6238
+ }
6239
+ /** the comfy-ts package root (the folder of its package.json), by the same walk: null when the
6240
+ * nearest named package is another one, a throw when no package.json is found at all */
6241
+ function comfyTsPackageDir(moduleUrl = import.meta.url) {
6242
+ let dir = dirname(fileURLToPath(moduleUrl));
6243
+ let prev = "";
6244
+ while (dir !== prev) {
6245
+ const pkgPath = join(dir, "package.json");
6246
+ if (existsSync(pkgPath)) {
6247
+ let pkg = {};
6248
+ try {
6249
+ pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
6250
+ } catch {}
6251
+ if (pkg.name === "comfy-ts") return dir;
6252
+ if (pkg.name != null) return null;
6253
+ }
6254
+ prev = dir;
6255
+ dir = dirname(dir);
6256
+ }
6257
+ throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`);
6258
+ }
6259
+ //#endregion
6260
+ export { readableStringify as a, writeHostFile as c, settingsPathFor as i, renderHttpBase as l, comfyTsPackageDir as n, importSharp as o, ComfyTS as r, ComfySchema as s, bundledExamplesDir as t };
6140
6261
 
6141
- //# sourceMappingURL=state-C067Kbew.js.map
6262
+ //# sourceMappingURL=exampleAssets-j1f26nGc.js.map