@decartai/sdk 0.0.20 → 0.0.22

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ImageModels, Model, ModelDefinition, RealTimeModels, VideoModels, models } from "./shared/model.js";
1
+ import { ImageModelDefinition, ImageModels, Model, ModelDefinition, RealTimeModels, VideoModelDefinition, VideoModels, models } from "./shared/model.js";
2
2
  import { FileInput, ProcessOptions } from "./process/types.js";
3
3
  import { ProcessClient } from "./process/client.js";
4
4
  import { JobStatus, JobStatusResponse, JobSubmitResponse, QueueJobResult, QueueSubmitAndPollOptions, QueueSubmitOptions } from "./queue/types.js";
@@ -10,30 +10,49 @@ import { z } from "zod";
10
10
 
11
11
  //#region src/index.d.ts
12
12
  declare const decartClientOptionsSchema: z.ZodObject<{
13
- apiKey: z.ZodString;
13
+ apiKey: z.ZodOptional<z.ZodString>;
14
14
  baseUrl: z.ZodOptional<z.ZodURL>;
15
15
  integration: z.ZodOptional<z.ZodString>;
16
16
  }, z.core.$strip>;
17
17
  type DecartClientOptions = z.infer<typeof decartClientOptionsSchema>;
18
- declare const createDecartClient: (options: DecartClientOptions) => {
18
+ /**
19
+ * Create a Decart API client.
20
+ *
21
+ * @param options - Configuration options
22
+ * @param options.apiKey - API key for authentication. Defaults to the DECART_API_KEY environment variable.
23
+ * @param options.baseUrl - Override the default API base URL.
24
+ * @param options.integration - Optional integration identifier.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * // Option 1: Explicit API key
29
+ * const client = createDecartClient({ apiKey: "your-api-key" });
30
+ *
31
+ * // Option 2: Using DECART_API_KEY environment variable
32
+ * const client = createDecartClient();
33
+ * ```
34
+ */
35
+ declare const createDecartClient: (options?: DecartClientOptions) => {
19
36
  realtime: {
20
37
  connect: (stream: MediaStream, options: RealTimeClientConnectOptions) => Promise<RealTimeClient>;
21
38
  };
22
39
  /**
23
- * Client for video and image generation.
40
+ * Client for synchronous image generation.
41
+ * Only image models support the sync/process API.
24
42
  *
25
43
  * @example
26
44
  * ```ts
27
45
  * const client = createDecartClient({ apiKey: "your-api-key" });
28
46
  * const result = await client.process({
29
- * model: models.video("lucy-pro-t2v"),
47
+ * model: models.image("lucy-pro-t2i"),
30
48
  * prompt: "A beautiful sunset over the ocean"
31
49
  * });
32
50
  * ```
33
51
  */
34
52
  process: ProcessClient;
35
53
  /**
36
- * Client for queue-based async video and image generation.
54
+ * Client for queue-based async video generation.
55
+ * Only video models support the queue API.
37
56
  * Jobs are submitted and processed asynchronously.
38
57
  *
39
58
  * @example
@@ -72,4 +91,4 @@ declare const createDecartClient: (options: DecartClientOptions) => {
72
91
  queue: QueueClient;
73
92
  };
74
93
  //#endregion
75
- export { DecartClientOptions, type DecartSDKError, ERROR_CODES, type FileInput, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type Model, type ModelDefinition, type ModelState, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type VideoModels, createDecartClient, models };
94
+ export { DecartClientOptions, type DecartSDKError, ERROR_CODES, type FileInput, type ImageModelDefinition, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type Model, type ModelDefinition, type ModelState, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type VideoModelDefinition, type VideoModels, createDecartClient, models };
package/dist/index.js CHANGED
@@ -3,23 +3,44 @@ import { createProcessClient } from "./process/client.js";
3
3
  import { createQueueClient } from "./queue/client.js";
4
4
  import { models } from "./shared/model.js";
5
5
  import { createRealTimeClient } from "./realtime/client.js";
6
+ import { readEnv } from "./utils/env.js";
6
7
  import { z } from "zod";
7
8
 
8
9
  //#region src/index.ts
9
10
  const decartClientOptionsSchema = z.object({
10
- apiKey: z.string().min(1),
11
+ apiKey: z.string().min(1).optional(),
11
12
  baseUrl: z.url().optional(),
12
13
  integration: z.string().optional()
13
14
  });
14
- const createDecartClient = (options) => {
15
- const parsedOptions = decartClientOptionsSchema.safeParse(options);
15
+ /**
16
+ * Create a Decart API client.
17
+ *
18
+ * @param options - Configuration options
19
+ * @param options.apiKey - API key for authentication. Defaults to the DECART_API_KEY environment variable.
20
+ * @param options.baseUrl - Override the default API base URL.
21
+ * @param options.integration - Optional integration identifier.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // Option 1: Explicit API key
26
+ * const client = createDecartClient({ apiKey: "your-api-key" });
27
+ *
28
+ * // Option 2: Using DECART_API_KEY environment variable
29
+ * const client = createDecartClient();
30
+ * ```
31
+ */
32
+ const createDecartClient = (options = {}) => {
33
+ const apiKey = options.apiKey ?? readEnv("DECART_API_KEY");
34
+ if (!apiKey) throw createInvalidApiKeyError();
35
+ const parsedOptions = decartClientOptionsSchema.safeParse({
36
+ ...options,
37
+ apiKey
38
+ });
16
39
  if (!parsedOptions.success) {
17
- const issue = parsedOptions.error.issues[0];
18
- if (issue.path.includes("apiKey")) throw createInvalidApiKeyError();
19
- if (issue.path.includes("baseUrl")) throw createInvalidBaseUrlError(options.baseUrl);
40
+ if (parsedOptions.error.issues[0].path.includes("baseUrl")) throw createInvalidBaseUrlError(options.baseUrl);
20
41
  throw parsedOptions.error;
21
42
  }
22
- const { baseUrl = "https://api.decart.ai", apiKey, integration } = parsedOptions.data;
43
+ const { baseUrl = "https://api.decart.ai", integration } = parsedOptions.data;
23
44
  const realtime = createRealTimeClient({
24
45
  baseUrl: "wss://api3.decart.ai",
25
46
  apiKey,
@@ -1,7 +1,12 @@
1
- import { ModelDefinition } from "../shared/model.js";
1
+ import { ImageModelDefinition } from "../shared/model.js";
2
2
  import { ProcessOptions } from "./types.js";
3
3
 
4
4
  //#region src/process/client.d.ts
5
- type ProcessClient = <T extends ModelDefinition>(options: ProcessOptions<T>) => Promise<Blob>;
5
+
6
+ /**
7
+ * Client for synchronous image generation.
8
+ * Only image models (t2i, i2i) support the sync/process API.
9
+ */
10
+ type ProcessClient = <T extends ImageModelDefinition>(options: ProcessOptions<T>) => Promise<Blob>;
6
11
  //#endregion
7
12
  export { ProcessClient };
@@ -1,4 +1,4 @@
1
- import { ImageModels, ModelDefinition, ModelInputSchemas, VideoModels } from "../shared/model.js";
1
+ import { ImageModelDefinition, ImageModels, ModelDefinition, ModelInputSchemas, VideoModels } from "../shared/model.js";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/process/types.d.ts
@@ -127,11 +127,12 @@ type PickDocumentedInputs<T extends ModelDefinition> = Pick<ModelSpecificProcess
127
127
  */
128
128
  type MergeDocumentedInputs<T extends ModelDefinition> = PickDocumentedInputs<T> & InferModelInputs<T>;
129
129
  /**
130
- * Options for the process client to generate video or image content.
130
+ * Options for the process client to generate image content.
131
+ * Only image models support the sync/process API.
131
132
  *
132
- * @template T - The model definition type
133
+ * @template T - The image model definition type
133
134
  */
134
- type ProcessOptions<T extends ModelDefinition = ModelDefinition> = {
135
+ type ProcessOptions<T extends ImageModelDefinition = ImageModelDefinition> = {
135
136
  /**
136
137
  * The model definition to use.
137
138
  */
@@ -1,7 +1,12 @@
1
- import { ModelDefinition } from "../shared/model.js";
1
+ import { VideoModelDefinition } from "../shared/model.js";
2
2
  import { JobStatusResponse, JobSubmitResponse, QueueJobResult, QueueSubmitAndPollOptions, QueueSubmitOptions } from "./types.js";
3
3
 
4
4
  //#region src/queue/client.d.ts
5
+
6
+ /**
7
+ * Client for queue-based async video generation.
8
+ * Only video models support the queue API.
9
+ */
5
10
  type QueueClient = {
6
11
  /**
7
12
  * Submit a job to the queue for async processing.
@@ -16,7 +21,7 @@ type QueueClient = {
16
21
  * console.log(job.job_id); // "job_abc123"
17
22
  * ```
18
23
  */
19
- submit: <T extends ModelDefinition>(options: QueueSubmitOptions<T>) => Promise<JobSubmitResponse>;
24
+ submit: <T extends VideoModelDefinition>(options: QueueSubmitOptions<T>) => Promise<JobSubmitResponse>;
20
25
  /**
21
26
  * Get the current status of a job.
22
27
  *
@@ -59,7 +64,7 @@ type QueueClient = {
59
64
  * }
60
65
  * ```
61
66
  */
62
- submitAndPoll: <T extends ModelDefinition>(options: QueueSubmitAndPollOptions<T>) => Promise<QueueJobResult>;
67
+ submitAndPoll: <T extends VideoModelDefinition>(options: QueueSubmitAndPollOptions<T>) => Promise<QueueJobResult>;
63
68
  };
64
69
  //#endregion
65
70
  export { QueueClient };
@@ -1,4 +1,4 @@
1
- import { ModelDefinition } from "../shared/model.js";
1
+ import { ModelDefinition, VideoModelDefinition } from "../shared/model.js";
2
2
  import { FileInput, InferModelInputs, ModelSpecificInputs, ProcessInputs } from "../process/types.js";
3
3
 
4
4
  //#region src/queue/types.d.ts
@@ -54,8 +54,9 @@ type PickDocumentedInputs<T extends ModelDefinition> = Pick<ModelSpecificQueueIn
54
54
  type MergeDocumentedInputs<T extends ModelDefinition> = PickDocumentedInputs<T> & InferModelInputs<T>;
55
55
  /**
56
56
  * Options for queue.submit() - submit a job for async processing.
57
+ * Only video models support the queue API.
57
58
  */
58
- type QueueSubmitOptions<T extends ModelDefinition = ModelDefinition> = {
59
+ type QueueSubmitOptions<T extends VideoModelDefinition = VideoModelDefinition> = {
59
60
  /**
60
61
  * The model definition to use.
61
62
  */
@@ -67,8 +68,9 @@ type QueueSubmitOptions<T extends ModelDefinition = ModelDefinition> = {
67
68
  } & MergeDocumentedInputs<T>;
68
69
  /**
69
70
  * Options for queue.submitAndPoll() - submit and wait for completion.
71
+ * Only video models support the queue API.
70
72
  */
71
- type QueueSubmitAndPollOptions<T extends ModelDefinition = ModelDefinition> = QueueSubmitOptions<T> & {
73
+ type QueueSubmitAndPollOptions<T extends VideoModelDefinition = VideoModelDefinition> = QueueSubmitOptions<T> & {
72
74
  /**
73
75
  * Callback invoked when job status changes during polling.
74
76
  * Receives the full job status response object.
@@ -99,6 +99,16 @@ type ModelDefinition<T extends Model = Model> = {
99
99
  height: number;
100
100
  inputSchema: T extends keyof ModelInputSchemas ? ModelInputSchemas[T] : z.ZodTypeAny;
101
101
  };
102
+ /**
103
+ * Type alias for model definitions that support synchronous processing.
104
+ * Only image models support the sync/process API.
105
+ */
106
+ type ImageModelDefinition = ModelDefinition<ImageModels>;
107
+ /**
108
+ * Type alias for model definitions that support queue processing.
109
+ * Only video models support the queue API.
110
+ */
111
+ type VideoModelDefinition = ModelDefinition<VideoModels>;
102
112
  declare const models: {
103
113
  realtime: <T extends RealTimeModels>(model: T) => ModelDefinition<T>;
104
114
  /**
@@ -123,4 +133,4 @@ declare const models: {
123
133
  image: <T extends ImageModels>(model: T) => ModelDefinition<T>;
124
134
  };
125
135
  //#endregion
126
- export { ImageModels, Model, ModelDefinition, ModelInputSchemas, RealTimeModels, VideoModels, models };
136
+ export { ImageModelDefinition, ImageModels, Model, ModelDefinition, ModelInputSchemas, RealTimeModels, VideoModelDefinition, VideoModels, models };
@@ -0,0 +1,9 @@
1
+ //#region src/utils/env.ts
2
+ const readEnv = (env) => {
3
+ const globalThisAny = globalThis;
4
+ if (typeof globalThisAny.process !== "undefined") return globalThisAny.process.env?.[env]?.trim();
5
+ if (typeof globalThisAny.Deno !== "undefined") return globalThisAny.Deno.env?.get?.(env)?.trim();
6
+ };
7
+
8
+ //#endregion
9
+ export { readEnv };
@@ -21,7 +21,7 @@ function createSDKError(code, message, data, cause) {
21
21
  };
22
22
  }
23
23
  function createInvalidApiKeyError() {
24
- return createSDKError(ERROR_CODES.INVALID_API_KEY, "API key is required and must be a non-empty string");
24
+ return createSDKError(ERROR_CODES.INVALID_API_KEY, "Missing API key. Pass `apiKey` to createDecartClient() or set the DECART_API_KEY environment variable.");
25
25
  }
26
26
  function createInvalidBaseUrlError(url) {
27
27
  return createSDKError(ERROR_CODES.INVALID_BASE_URL, `Invalid base URL${url ? `: ${url}` : ""}`);
package/dist/version.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Injected at build time from package.json.
5
5
  * Falls back to '0.0.0-dev' in development.
6
6
  */
7
- const VERSION = "0.0.20";
7
+ const VERSION = "0.0.22";
8
8
 
9
9
  //#endregion
10
10
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",