@decartai/sdk 0.0.24 → 0.0.26
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 +19 -1
- package/dist/index.js +6 -0
- package/dist/realtime/client.d.ts +1 -1
- package/dist/realtime/webrtc-connection.js +7 -3
- package/dist/shared/model.d.ts +10 -2
- package/dist/shared/model.js +18 -1
- package/dist/tokens/client.d.ts +21 -0
- package/dist/tokens/client.js +22 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/errors.js +2 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { QueueClient } from "./queue/client.js";
|
|
|
6
6
|
import { DecartSDKError, ERROR_CODES } from "./utils/errors.js";
|
|
7
7
|
import { RealTimeClient, RealTimeClientConnectOptions, RealTimeClientInitialState } from "./realtime/client.js";
|
|
8
8
|
import { ModelState } from "./shared/types.js";
|
|
9
|
+
import { CreateTokenResponse, TokensClient } from "./tokens/client.js";
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
|
|
11
12
|
//#region src/index.d.ts
|
|
@@ -89,6 +90,23 @@ declare const createDecartClient: (options?: DecartClientOptions) => {
|
|
|
89
90
|
* ```
|
|
90
91
|
*/
|
|
91
92
|
queue: QueueClient;
|
|
93
|
+
/**
|
|
94
|
+
* Client for creating client tokens.
|
|
95
|
+
* Client tokens are short-lived API keys safe for client-side use.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // Server-side: Create a client token
|
|
100
|
+
* const serverClient = createDecartClient({ apiKey: process.env.DECART_API_KEY });
|
|
101
|
+
* const token = await serverClient.tokens.create();
|
|
102
|
+
* // Returns: { apiKey: "ek_...", expiresAt: "2024-12-15T12:10:00Z" }
|
|
103
|
+
*
|
|
104
|
+
* // Client-side: Use the client token
|
|
105
|
+
* const client = createDecartClient({ apiKey: token.apiKey });
|
|
106
|
+
* const realtimeClient = await client.realtime.connect(stream, options);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
tokens: TokensClient;
|
|
92
110
|
};
|
|
93
111
|
//#endregion
|
|
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 };
|
|
112
|
+
export { type CreateTokenResponse, 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 TokensClient, type VideoModelDefinition, type VideoModels, createDecartClient, models };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ 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 { createTokensClient } from "./tokens/client.js";
|
|
6
7
|
import { readEnv } from "./utils/env.js";
|
|
7
8
|
import { z } from "zod";
|
|
8
9
|
|
|
@@ -56,6 +57,11 @@ const createDecartClient = (options = {}) => {
|
|
|
56
57
|
baseUrl,
|
|
57
58
|
apiKey,
|
|
58
59
|
integration
|
|
60
|
+
}),
|
|
61
|
+
tokens: createTokensClient({
|
|
62
|
+
baseUrl,
|
|
63
|
+
apiKey,
|
|
64
|
+
integration
|
|
59
65
|
})
|
|
60
66
|
};
|
|
61
67
|
};
|
|
@@ -13,7 +13,7 @@ type OnRemoteStreamFn = (stream: MediaStream) => void;
|
|
|
13
13
|
type RealTimeClientInitialState = z.infer<typeof realTimeClientInitialStateSchema>;
|
|
14
14
|
declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
|
|
15
15
|
model: z.ZodObject<{
|
|
16
|
-
name: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
|
|
16
|
+
name: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">, z.ZodLiteral<"lucy-restyle-v2v">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
|
|
17
17
|
urlPath: z.ZodString;
|
|
18
18
|
queueUrlPath: z.ZodOptional<z.ZodString>;
|
|
19
19
|
fps: z.ZodNumber;
|
|
@@ -129,7 +129,7 @@ var WebRTCConnection = class {
|
|
|
129
129
|
if (!this.localStream) throw new Error("No local stream found");
|
|
130
130
|
if (this.pc) {
|
|
131
131
|
this.pc.getSenders().forEach((sender) => {
|
|
132
|
-
if (sender.track) this.pc.removeTrack(sender);
|
|
132
|
+
if (sender.track && this.pc) this.pc.removeTrack(sender);
|
|
133
133
|
});
|
|
134
134
|
this.pc.close();
|
|
135
135
|
}
|
|
@@ -140,7 +140,9 @@ var WebRTCConnection = class {
|
|
|
140
140
|
username: turnConfig.username
|
|
141
141
|
});
|
|
142
142
|
this.pc = new RTCPeerConnection({ iceServers });
|
|
143
|
-
this.localStream.getTracks().forEach((track) =>
|
|
143
|
+
this.localStream.getTracks().forEach((track) => {
|
|
144
|
+
if (this.pc && this.localStream) this.pc.addTrack(track, this.localStream);
|
|
145
|
+
});
|
|
144
146
|
this.pc.ontrack = (e) => {
|
|
145
147
|
if (e.streams?.[0]) this.callbacks.onRemoteStream?.(e.streams[0]);
|
|
146
148
|
};
|
|
@@ -159,7 +161,9 @@ var WebRTCConnection = class {
|
|
|
159
161
|
this.handleSignalingMessage({ type: "ready" });
|
|
160
162
|
}
|
|
161
163
|
cleanup() {
|
|
162
|
-
this.pc?.getSenders().forEach((s) =>
|
|
164
|
+
this.pc?.getSenders().forEach((s) => {
|
|
165
|
+
s.track?.stop();
|
|
166
|
+
});
|
|
163
167
|
this.pc?.close();
|
|
164
168
|
this.pc = null;
|
|
165
169
|
this.ws?.close();
|
package/dist/shared/model.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { z } from "zod";
|
|
|
2
2
|
|
|
3
3
|
//#region src/shared/model.d.ts
|
|
4
4
|
declare const realtimeModels: z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>;
|
|
5
|
-
declare const videoModels: z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">]>;
|
|
5
|
+
declare const videoModels: z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">, z.ZodLiteral<"lucy-restyle-v2v">]>;
|
|
6
6
|
declare const imageModels: z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>;
|
|
7
|
-
declare const modelSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
|
|
7
|
+
declare const modelSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">, z.ZodLiteral<"lucy-restyle-v2v">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
|
|
8
8
|
type Model = z.infer<typeof modelSchema>;
|
|
9
9
|
type RealTimeModels = z.infer<typeof realtimeModels>;
|
|
10
10
|
type VideoModels = z.infer<typeof videoModels>;
|
|
@@ -88,6 +88,13 @@ declare const modelInputSchemas: {
|
|
|
88
88
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
89
89
|
resolution: z.ZodOptional<z.ZodDefault<z.ZodLiteral<"720p">>>;
|
|
90
90
|
}, z.core.$strip>;
|
|
91
|
+
readonly "lucy-restyle-v2v": z.ZodObject<{
|
|
92
|
+
prompt: z.ZodString;
|
|
93
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL]>;
|
|
94
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
resolution: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"720p">>>;
|
|
96
|
+
enhance_prompt: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
97
|
+
}, z.core.$strip>;
|
|
91
98
|
};
|
|
92
99
|
type ModelInputSchemas = typeof modelInputSchemas;
|
|
93
100
|
type ModelDefinition<T extends Model = Model> = {
|
|
@@ -121,6 +128,7 @@ declare const models: {
|
|
|
121
128
|
* - `"lucy-pro-flf2v"` - First-last-frame-to-video
|
|
122
129
|
* - `"lucy-dev-i2v"` - Image-to-video (Dev quality)
|
|
123
130
|
* - `"lucy-fast-v2v"` - Video-to-video (Fast quality)
|
|
131
|
+
* - `"lucy-restyle-v2v"` - Video-to-video (Restyling)
|
|
124
132
|
*/
|
|
125
133
|
video: <T extends VideoModels>(model: T) => ModelDefinition<T>;
|
|
126
134
|
/**
|
package/dist/shared/model.js
CHANGED
|
@@ -14,7 +14,8 @@ const videoModels = z.union([
|
|
|
14
14
|
z.literal("lucy-pro-i2v"),
|
|
15
15
|
z.literal("lucy-pro-v2v"),
|
|
16
16
|
z.literal("lucy-pro-flf2v"),
|
|
17
|
-
z.literal("lucy-motion")
|
|
17
|
+
z.literal("lucy-motion"),
|
|
18
|
+
z.literal("lucy-restyle-v2v")
|
|
18
19
|
]);
|
|
19
20
|
const imageModels = z.union([z.literal("lucy-pro-t2i"), z.literal("lucy-pro-i2i")]);
|
|
20
21
|
const modelSchema = z.union([
|
|
@@ -111,6 +112,13 @@ const modelInputSchemas = {
|
|
|
111
112
|
})).min(2).max(1e3).describe("The trajectory of the desired movement of the object in the image"),
|
|
112
113
|
seed: z.number().optional().describe("The seed to use for the generation"),
|
|
113
114
|
resolution: motionResolutionSchema
|
|
115
|
+
}),
|
|
116
|
+
"lucy-restyle-v2v": z.object({
|
|
117
|
+
prompt: z.string().min(1).max(1e3).describe("Text prompt for the video editing"),
|
|
118
|
+
data: fileInputSchema.describe("Video file to process (File, Blob, ReadableStream, URL, or string URL)"),
|
|
119
|
+
seed: z.number().optional().describe("Seed for the video generation"),
|
|
120
|
+
resolution: proV2vResolutionSchema,
|
|
121
|
+
enhance_prompt: z.boolean().default(true).optional().describe("Whether to enhance the prompt")
|
|
114
122
|
})
|
|
115
123
|
};
|
|
116
124
|
const modelDefinitionSchema = z.object({
|
|
@@ -232,6 +240,15 @@ const _models = {
|
|
|
232
240
|
width: 1280,
|
|
233
241
|
height: 704,
|
|
234
242
|
inputSchema: modelInputSchemas["lucy-motion"]
|
|
243
|
+
},
|
|
244
|
+
"lucy-restyle-v2v": {
|
|
245
|
+
urlPath: "/v1/generate/lucy-restyle-v2v",
|
|
246
|
+
queueUrlPath: "/v1/jobs/lucy-restyle-v2v",
|
|
247
|
+
name: "lucy-restyle-v2v",
|
|
248
|
+
fps: 22,
|
|
249
|
+
width: 1280,
|
|
250
|
+
height: 704,
|
|
251
|
+
inputSchema: modelInputSchemas["lucy-restyle-v2v"]
|
|
235
252
|
}
|
|
236
253
|
}
|
|
237
254
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/tokens/client.d.ts
|
|
2
|
+
|
|
3
|
+
type CreateTokenResponse = {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
expiresAt: string;
|
|
6
|
+
};
|
|
7
|
+
type TokensClient = {
|
|
8
|
+
/**
|
|
9
|
+
* Create a client token.
|
|
10
|
+
* @returns A short-lived API key safe for client-side use.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const client = createDecartClient({ apiKey: process.env.DECART_API_KEY });
|
|
14
|
+
* const token = await client.tokens.create();
|
|
15
|
+
* // Returns: { apiKey: "ek_...", expiresAt: "2024-12-15T12:10:00Z" }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
create: () => Promise<CreateTokenResponse>;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CreateTokenResponse, TokensClient };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createSDKError } from "../utils/errors.js";
|
|
2
|
+
import { buildAuthHeaders } from "../shared/request.js";
|
|
3
|
+
|
|
4
|
+
//#region src/tokens/client.ts
|
|
5
|
+
const createTokensClient = (opts) => {
|
|
6
|
+
const { baseUrl, apiKey, integration } = opts;
|
|
7
|
+
const create = async () => {
|
|
8
|
+
const response = await fetch(`${baseUrl}/v1/client/tokens`, {
|
|
9
|
+
method: "POST",
|
|
10
|
+
headers: buildAuthHeaders(apiKey, integration)
|
|
11
|
+
});
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
14
|
+
throw createSDKError("TOKEN_CREATE_ERROR", `Failed to create token: ${response.status} - ${errorText}`, { status: response.status });
|
|
15
|
+
}
|
|
16
|
+
return response.json();
|
|
17
|
+
};
|
|
18
|
+
return { create };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { createTokensClient };
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare const ERROR_CODES: {
|
|
|
17
17
|
readonly QUEUE_STATUS_ERROR: "QUEUE_STATUS_ERROR";
|
|
18
18
|
readonly QUEUE_RESULT_ERROR: "QUEUE_RESULT_ERROR";
|
|
19
19
|
readonly JOB_NOT_COMPLETED: "JOB_NOT_COMPLETED";
|
|
20
|
+
readonly TOKEN_CREATE_ERROR: "TOKEN_CREATE_ERROR";
|
|
20
21
|
};
|
|
21
22
|
//#endregion
|
|
22
23
|
export { DecartSDKError, ERROR_CODES };
|
package/dist/utils/errors.js
CHANGED
|
@@ -10,7 +10,8 @@ const ERROR_CODES = {
|
|
|
10
10
|
QUEUE_SUBMIT_ERROR: "QUEUE_SUBMIT_ERROR",
|
|
11
11
|
QUEUE_STATUS_ERROR: "QUEUE_STATUS_ERROR",
|
|
12
12
|
QUEUE_RESULT_ERROR: "QUEUE_RESULT_ERROR",
|
|
13
|
-
JOB_NOT_COMPLETED: "JOB_NOT_COMPLETED"
|
|
13
|
+
JOB_NOT_COMPLETED: "JOB_NOT_COMPLETED",
|
|
14
|
+
TOKEN_CREATE_ERROR: "TOKEN_CREATE_ERROR"
|
|
14
15
|
};
|
|
15
16
|
function createSDKError(code, message, data, cause) {
|
|
16
17
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decartai/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "Decart's JavaScript SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@biomejs/biome": "2.3.8",
|
|
32
33
|
"@types/bun": "^1.3.3",
|
|
33
34
|
"@types/node": "^22.15.17",
|
|
34
|
-
"biome": "^0.3.3",
|
|
35
35
|
"bumpp": "^10.1.0",
|
|
36
36
|
"msw": "^2.11.3",
|
|
37
37
|
"pkg-pr-new": "^0.0.56",
|