@comfyorg/sdk 0.1.2 → 0.1.4

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 CHANGED
@@ -14,7 +14,7 @@ JavaScript is async-native).
14
14
  import { Comfy } from "@comfyorg/sdk";
15
15
 
16
16
  const client = new Comfy("http://127.0.0.1:8189"); // local proxy, no key needed
17
- // const client = new Comfy("https://api.comfy.org", { apiKey: "..." }); // Comfy Cloud
17
+ // const client = new Comfy({ apiKey: "..." }); // Comfy Cloud (default base URL)
18
18
 
19
19
  const wf = await client.workflows.fromFile("workflow_api.json");
20
20
  const asset = client.assets.fromFile("photo.png"); // lazy; hashed + uploaded on first use
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  * import { Comfy } from "@comfyorg/sdk";
15
15
  *
16
16
  * const client = new Comfy("http://127.0.0.1:8189"); // local proxy
17
- * // const client = new Comfy("https://api.comfy.org", { apiKey: "..." }) // Comfy Cloud
17
+ * // const client = new Comfy({ apiKey: "..." }) // Comfy Cloud (default base URL)
18
18
  *
19
19
  * const wf = await client.workflows.fromFile("workflow_api.json");
20
20
  * const asset = client.assets.fromFile("photo.png"); // lazy; uploaded on use
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@
14
14
  * import { Comfy } from "@comfyorg/sdk";
15
15
  *
16
16
  * const client = new Comfy("http://127.0.0.1:8189"); // local proxy
17
- * // const client = new Comfy("https://api.comfy.org", { apiKey: "..." }) // Comfy Cloud
17
+ * // const client = new Comfy({ apiKey: "..." }) // Comfy Cloud (default base URL)
18
18
  *
19
19
  * const wf = await client.workflows.fromFile("workflow_api.json");
20
20
  * const asset = client.assets.fromFile("photo.png"); // lazy; uploaded on use
@@ -1,5 +1,5 @@
1
1
  export type ClientOptions = {
2
- baseUrl: 'http://127.0.0.1:8189' | 'https://api.comfy.org' | 'https://{deployment}.comfy.org' | (string & {});
2
+ baseUrl: 'http://127.0.0.1:8189' | 'https://cloud.comfy.org' | 'https://{deployment}.comfy.org' | (string & {});
3
3
  };
4
4
  /**
5
5
  * A user-owned record identified by a server-assigned UUID, backing an immutable blob whose content carries a server-computed blake3 hash. `hash` may be computed lazily: an asset record (and its retrievable bytes) can exist before its hash is filled in.
@@ -27,13 +27,9 @@
27
27
  */
28
28
  import { errorFromEnvelope } from "./errors.js";
29
29
  import { iterateSse } from "./sse.js";
30
+ import { SDK_VERSION } from "./version.js";
30
31
  const API_PREFIX = "/api/v2";
31
32
  const DEFAULT_TIMEOUT_MS = 30_000;
32
- // Mirrors `version` in package.json. Hand-kept in sync: this package builds
33
- // with plain `tsc` (no bundler/codegen step to inline it), and importing
34
- // `../../package.json` directly would step outside `tsc`'s configured
35
- // `rootDir`.
36
- const SDK_VERSION = "0.1.0";
37
33
  function looksLikePath(value) {
38
34
  return value.startsWith("http") || value.startsWith("/");
39
35
  }
@@ -102,8 +98,17 @@ export class ComfyLow {
102
98
  urlFor(path) {
103
99
  if (path.startsWith("http"))
104
100
  return path;
105
- if (path.startsWith("/api/"))
106
- return this.baseUrl + path;
101
+ // A server link (job.urls.*, marked by containing /api/) already carries
102
+ // the server's mount prefix, so it resolves against the origin — joining
103
+ // it to baseUrl would double the prefix on a prefix-mounted surface.
104
+ if (path.startsWith("/") && path.includes("/api/")) {
105
+ try {
106
+ return new URL(this.baseUrl).origin + path;
107
+ }
108
+ catch {
109
+ return this.baseUrl + path;
110
+ }
111
+ }
107
112
  return this.baseUrl + API_PREFIX + path;
108
113
  }
109
114
  /**
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "0.1.4";
@@ -0,0 +1,2 @@
1
+ // GENERATED by scripts/gen-version.mjs from package.json — do not edit.
2
+ export const SDK_VERSION = "0.1.4";
@@ -18,7 +18,7 @@
18
18
  * import { Comfy } from "@comfyorg/sdk";
19
19
  *
20
20
  * const client = new Comfy("http://127.0.0.1:8189"); // self-hosted, no key
21
- * // const client = new Comfy("https://api.comfy.org", { apiKey: "ck_..." });
21
+ * // const client = new Comfy({ apiKey: "ck_..." }); // Comfy Cloud (default base URL)
22
22
  *
23
23
  * const wf = await client.workflows.fromFile("workflow_api.json");
24
24
  * const asset = client.assets.fromFile("photo.png"); // lazy; uploaded on use
@@ -33,6 +33,9 @@ import { AssetFactory } from "./assets.js";
33
33
  import { Job, JobFactory } from "./jobs.js";
34
34
  import type { Workflow } from "./workflows.js";
35
35
  import { WorkflowFactory } from "./workflows.js";
36
+ /** Base URL of the hosted Comfy Cloud deployment, used when none is given.
37
+ * Self-hosted ComfyUI and serverless deployments must pass their own baseUrl. */
38
+ export declare const COMFY_CLOUD_BASE_URL = "https://cloud.comfy.org";
36
39
  export interface ComfyOptions {
37
40
  apiKey?: string;
38
41
  timeoutMs?: number;
@@ -46,6 +49,9 @@ export declare class Comfy {
46
49
  readonly assets: AssetFactory;
47
50
  readonly workflows: WorkflowFactory;
48
51
  readonly jobs: JobFactory;
52
+ /** Connect to the hosted Comfy Cloud deployment. */
53
+ constructor(options?: ComfyOptions);
54
+ /** Connect to a specific deployment — self-hosted ComfyUI, or a serverless one. */
49
55
  constructor(baseUrl: string, options?: ComfyOptions);
50
56
  private materialize;
51
57
  /**
@@ -18,7 +18,7 @@
18
18
  * import { Comfy } from "@comfyorg/sdk";
19
19
  *
20
20
  * const client = new Comfy("http://127.0.0.1:8189"); // self-hosted, no key
21
- * // const client = new Comfy("https://api.comfy.org", { apiKey: "ck_..." });
21
+ * // const client = new Comfy({ apiKey: "ck_..." }); // Comfy Cloud (default base URL)
22
22
  *
23
23
  * const wf = await client.workflows.fromFile("workflow_api.json");
24
24
  * const asset = client.assets.fromFile("photo.png"); // lazy; uploaded on use
@@ -37,6 +37,9 @@ import { Job, JobFactory } from "./jobs.js";
37
37
  import { WorkflowFactory } from "./workflows.js";
38
38
  // How long to keep retrying a full queue before giving up (ms).
39
39
  const QUEUE_RETRY_BUDGET_MS = 60_000;
40
+ /** Base URL of the hosted Comfy Cloud deployment, used when none is given.
41
+ * Self-hosted ComfyUI and serverless deployments must pass their own baseUrl. */
42
+ export const COMFY_CLOUD_BASE_URL = "https://cloud.comfy.org";
40
43
  const DEFAULT_RETRY_AFTER_S = 2;
41
44
  function guardUiFormat(workflow) {
42
45
  if (looksLikeUiFormat(workflow.json)) {
@@ -48,7 +51,10 @@ export class Comfy {
48
51
  assets;
49
52
  workflows;
50
53
  jobs;
51
- constructor(baseUrl, options = {}) {
54
+ constructor(baseUrlOrOptions, maybeOptions = {}) {
55
+ const isUrl = typeof baseUrlOrOptions === "string";
56
+ const baseUrl = isUrl ? baseUrlOrOptions : COMFY_CLOUD_BASE_URL;
57
+ const options = isUrl ? maybeOptions : (baseUrlOrOptions ?? {});
52
58
  this.low = new ComfyLow(baseUrl, options.apiKey, {
53
59
  timeoutMs: options.timeoutMs,
54
60
  fetch: options.fetch,
@@ -4,7 +4,7 @@
4
4
  * Mirrors `comfy_sdk`'s `__init__.py` in the Python SDK, minus the
5
5
  * sync/async duplication (JS is async-native).
6
6
  */
7
- export { Comfy, type ComfyOptions } from "./client.js";
7
+ export { Comfy, COMFY_CLOUD_BASE_URL, type ComfyOptions } from "./client.js";
8
8
  export { Asset, AssetFactory } from "./assets.js";
9
9
  export { Workflow, WorkflowFactory, type WorkflowGraph } from "./workflows.js";
10
10
  export { Job, JobFactory } from "./jobs.js";
package/dist/sdk/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Mirrors `comfy_sdk`'s `__init__.py` in the Python SDK, minus the
5
5
  * sync/async duplication (JS is async-native).
6
6
  */
7
- export { Comfy } from "./client.js";
7
+ export { Comfy, COMFY_CLOUD_BASE_URL } from "./client.js";
8
8
  export { Asset, AssetFactory } from "./assets.js";
9
9
  export { Workflow, WorkflowFactory } from "./workflows.js";
10
10
  export { Job, JobFactory } from "./jobs.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comfyorg/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "TypeScript SDK for running ComfyUI workflows via the Comfy API v2 (self-hosted, Comfy Cloud, serverless).",
6
6
  "homepage": "https://github.com/Comfy-Org/ComfyTypeScriptSDK#readme",
@@ -46,7 +46,7 @@
46
46
  "node": ">=22"
47
47
  },
48
48
  "scripts": {
49
- "build": "tsc",
49
+ "build": "node scripts/gen-version.mjs && tsc",
50
50
  "generate": "openapi-ts",
51
51
  "lint": "oxlint .",
52
52
  "format": "oxfmt --write .",