@decartai/sdk 0.0.22 → 0.0.23
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 +36 -8
- package/dist/index.js +15 -18
- package/dist/process/client.js +1 -1
- package/dist/process/types.d.ts +12 -5
- package/dist/queue/client.js +2 -2
- package/dist/queue/types.d.ts +0 -4
- package/dist/realtime/client.js +1 -2
- package/dist/realtime/webrtc-connection.js +1 -2
- package/dist/shared/model.js +5 -5
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -62,7 +62,9 @@ realtimeClient.setPrompt("Cyberpunk city");
|
|
|
62
62
|
realtimeClient.disconnect();
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### Async Processing (Queue API)
|
|
66
|
+
|
|
67
|
+
For video generation jobs, use the queue API to submit jobs and poll for results:
|
|
66
68
|
|
|
67
69
|
```typescript
|
|
68
70
|
import { createDecartClient, models } from "@decartai/sdk";
|
|
@@ -71,15 +73,41 @@ const client = createDecartClient({
|
|
|
71
73
|
apiKey: "your-api-key-here"
|
|
72
74
|
});
|
|
73
75
|
|
|
74
|
-
//
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
// Submit and poll automatically
|
|
77
|
+
const result = await client.queue.submitAndPoll({
|
|
78
|
+
model: models.video("lucy-pro-t2v"),
|
|
79
|
+
prompt: "A cat playing piano",
|
|
80
|
+
onStatusChange: (job) => {
|
|
81
|
+
console.log(`Status: ${job.status}`);
|
|
82
|
+
}
|
|
80
83
|
});
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
if (result.status === "completed") {
|
|
86
|
+
videoElement.src = URL.createObjectURL(result.data);
|
|
87
|
+
} else {
|
|
88
|
+
console.error("Job failed:", result.error);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Or manage the polling manually:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Submit the job
|
|
96
|
+
const job = await client.queue.submit({
|
|
97
|
+
model: models.video("lucy-pro-t2v"),
|
|
98
|
+
prompt: "A cat playing piano"
|
|
99
|
+
});
|
|
100
|
+
console.log(`Job ID: ${job.job_id}`);
|
|
101
|
+
|
|
102
|
+
// Poll for status
|
|
103
|
+
const status = await client.queue.status(job.job_id);
|
|
104
|
+
console.log(`Status: ${status.status}`);
|
|
105
|
+
|
|
106
|
+
// Get result when completed
|
|
107
|
+
if (status.status === "completed") {
|
|
108
|
+
const blob = await client.queue.result(job.job_id);
|
|
109
|
+
videoElement.src = URL.createObjectURL(blob);
|
|
110
|
+
}
|
|
83
111
|
```
|
|
84
112
|
|
|
85
113
|
## Development
|
package/dist/index.js
CHANGED
|
@@ -41,25 +41,22 @@ const createDecartClient = (options = {}) => {
|
|
|
41
41
|
throw parsedOptions.error;
|
|
42
42
|
}
|
|
43
43
|
const { baseUrl = "https://api.decart.ai", integration } = parsedOptions.data;
|
|
44
|
-
const realtime = createRealTimeClient({
|
|
45
|
-
baseUrl: "wss://api3.decart.ai",
|
|
46
|
-
apiKey,
|
|
47
|
-
integration
|
|
48
|
-
});
|
|
49
|
-
const process = createProcessClient({
|
|
50
|
-
baseUrl,
|
|
51
|
-
apiKey,
|
|
52
|
-
integration
|
|
53
|
-
});
|
|
54
|
-
const queue = createQueueClient({
|
|
55
|
-
baseUrl,
|
|
56
|
-
apiKey,
|
|
57
|
-
integration
|
|
58
|
-
});
|
|
59
44
|
return {
|
|
60
|
-
realtime
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
realtime: createRealTimeClient({
|
|
46
|
+
baseUrl: "wss://api3.decart.ai",
|
|
47
|
+
apiKey,
|
|
48
|
+
integration
|
|
49
|
+
}),
|
|
50
|
+
process: createProcessClient({
|
|
51
|
+
baseUrl,
|
|
52
|
+
apiKey,
|
|
53
|
+
integration
|
|
54
|
+
}),
|
|
55
|
+
queue: createQueueClient({
|
|
56
|
+
baseUrl,
|
|
57
|
+
apiKey,
|
|
58
|
+
integration
|
|
59
|
+
})
|
|
63
60
|
};
|
|
64
61
|
};
|
|
65
62
|
|
package/dist/process/client.js
CHANGED
|
@@ -6,7 +6,7 @@ import { sendRequest } from "./request.js";
|
|
|
6
6
|
const createProcessClient = (opts) => {
|
|
7
7
|
const { apiKey, baseUrl, integration } = opts;
|
|
8
8
|
const _process = async (options) => {
|
|
9
|
-
const { model, signal
|
|
9
|
+
const { model, signal, ...inputs } = options;
|
|
10
10
|
const parsedInputs = model.inputSchema.safeParse(inputs);
|
|
11
11
|
if (!parsedInputs.success) throw createInvalidInputError(`Invalid inputs for ${model.name}: ${parsedInputs.error.message}`);
|
|
12
12
|
const processedInputs = {};
|
package/dist/process/types.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ interface ImageEditingInputs {
|
|
|
25
25
|
* It's highly recommended to read our [Prompt Engineering for Edits](https://docs.platform.decart.ai/models/image/image-editing#prompt-engineering-for-edits) guide for how to write effective editing prompts.
|
|
26
26
|
*/
|
|
27
27
|
prompt: string;
|
|
28
|
+
/**
|
|
29
|
+
* The data to use for generation (for image-to-image).
|
|
30
|
+
* Can be a File, Blob, ReadableStream, URL, or string URL.
|
|
31
|
+
*/
|
|
32
|
+
data?: FileInput;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* Model-specific input documentation for video models.
|
|
@@ -36,6 +41,13 @@ interface VideoModelInputs {
|
|
|
36
41
|
* See our [Prompt Engineering](https://docs.platform.decart.ai/models/video/video-generation#prompt-engineering) guide for how to write prompt for Decart video models effectively.
|
|
37
42
|
*/
|
|
38
43
|
prompt: string;
|
|
44
|
+
/**
|
|
45
|
+
* The data to use for generation (for image-to-video and video-to-video).
|
|
46
|
+
* Can be a File, Blob, ReadableStream, URL, or string URL.
|
|
47
|
+
*
|
|
48
|
+
* Output video is limited to 5 seconds.
|
|
49
|
+
*/
|
|
50
|
+
data?: FileInput;
|
|
39
51
|
}
|
|
40
52
|
/**
|
|
41
53
|
* Default inputs for models that only require a prompt.
|
|
@@ -73,11 +85,6 @@ interface ProcessInputs {
|
|
|
73
85
|
* @default "landscape"
|
|
74
86
|
*/
|
|
75
87
|
orientation?: "landscape" | "portrait";
|
|
76
|
-
/**
|
|
77
|
-
* The data to use for generation (for image-to-image and video-to-video).
|
|
78
|
-
* Can be a File, Blob, ReadableStream, URL, or string URL.
|
|
79
|
-
*/
|
|
80
|
-
data?: FileInput;
|
|
81
88
|
/**
|
|
82
89
|
* The start frame image (for first-last-frame models).
|
|
83
90
|
* Can be a File, Blob, ReadableStream, URL, or string URL.
|
package/dist/queue/client.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getJobContent, getJobStatus, submitJob } from "./request.js";
|
|
|
7
7
|
const createQueueClient = (opts) => {
|
|
8
8
|
const { apiKey, baseUrl, integration } = opts;
|
|
9
9
|
const submit = async (options) => {
|
|
10
|
-
const { model, signal
|
|
10
|
+
const { model, signal, ...inputs } = options;
|
|
11
11
|
const parsedInputs = model.inputSchema.safeParse(inputs);
|
|
12
12
|
if (!parsedInputs.success) throw createInvalidInputError(`Invalid inputs for ${model.name}: ${parsedInputs.error.message}`);
|
|
13
13
|
const processedInputs = {};
|
|
@@ -39,7 +39,7 @@ const createQueueClient = (opts) => {
|
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
const submitAndPoll = async (options) => {
|
|
42
|
-
const { onStatusChange, signal
|
|
42
|
+
const { onStatusChange, signal, ...submitOptions } = options;
|
|
43
43
|
const job = await submit(submitOptions);
|
|
44
44
|
if (onStatusChange) onStatusChange(job);
|
|
45
45
|
return pollUntilComplete({
|
package/dist/queue/types.d.ts
CHANGED
|
@@ -36,10 +36,6 @@ type QueueJobResult = {
|
|
|
36
36
|
* Re-exports ProcessInputs fields with queue-specific documentation.
|
|
37
37
|
*/
|
|
38
38
|
interface QueueInputs extends ProcessInputs {
|
|
39
|
-
/**
|
|
40
|
-
* The data to use for generation (for image-to-image and video-to-video).
|
|
41
|
-
*/
|
|
42
|
-
data?: FileInput;
|
|
43
39
|
/**
|
|
44
40
|
* The start frame image (for first-last-frame models).
|
|
45
41
|
*/
|
package/dist/realtime/client.js
CHANGED
|
@@ -24,9 +24,8 @@ const createRealTimeClient = (opts) => {
|
|
|
24
24
|
if (!parsedOptions.success) throw parsedOptions.error;
|
|
25
25
|
const sessionId = v4();
|
|
26
26
|
const { onRemoteStream, initialState } = parsedOptions.data;
|
|
27
|
-
const url = `${baseUrl}${options.model.urlPath}`;
|
|
28
27
|
const webrtcManager = new WebRTCManager({
|
|
29
|
-
webrtcUrl: `${
|
|
28
|
+
webrtcUrl: `${`${baseUrl}${options.model.urlPath}`}?api_key=${apiKey}&model=${options.model.name}`,
|
|
30
29
|
apiKey,
|
|
31
30
|
sessionId,
|
|
32
31
|
fps: options.model.fps,
|
|
@@ -17,8 +17,7 @@ var WebRTCConnection = class {
|
|
|
17
17
|
const deadline = Date.now() + timeout;
|
|
18
18
|
this.localStream = localStream;
|
|
19
19
|
const userAgent = encodeURIComponent(buildUserAgent(integration));
|
|
20
|
-
const
|
|
21
|
-
const wsUrl = `${url}${separator}user_agent=${userAgent}`;
|
|
20
|
+
const wsUrl = `${url}${url.includes("?") ? "&" : "?"}user_agent=${userAgent}`;
|
|
22
21
|
await new Promise((resolve, reject) => {
|
|
23
22
|
this.connectionReject = reject;
|
|
24
23
|
const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("WebSocket timeout")), timeout);
|
package/dist/shared/model.js
CHANGED
|
@@ -63,19 +63,19 @@ const modelInputSchemas = {
|
|
|
63
63
|
}),
|
|
64
64
|
"lucy-pro-i2v": z.object({
|
|
65
65
|
prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
|
|
66
|
-
data: fileInputSchema.describe("The image data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
|
|
66
|
+
data: fileInputSchema.describe("The image data to use for generation (File, Blob, ReadableStream, URL, or string URL). Output video is limited to 5 seconds."),
|
|
67
67
|
seed: z.number().optional().describe("The seed to use for the generation"),
|
|
68
68
|
resolution: proResolutionSchema()
|
|
69
69
|
}),
|
|
70
70
|
"lucy-dev-i2v": z.object({
|
|
71
71
|
prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
|
|
72
|
-
data: fileInputSchema.describe("The image data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
|
|
72
|
+
data: fileInputSchema.describe("The image data to use for generation (File, Blob, ReadableStream, URL, or string URL). Output video is limited to 5 seconds."),
|
|
73
73
|
seed: z.number().optional().describe("The seed to use for the generation"),
|
|
74
74
|
resolution: devResolutionSchema
|
|
75
75
|
}),
|
|
76
76
|
"lucy-pro-v2v": z.object({
|
|
77
77
|
prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
|
|
78
|
-
data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
|
|
78
|
+
data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL). Output video is limited to 5 seconds."),
|
|
79
79
|
seed: z.number().optional().describe("The seed to use for the generation"),
|
|
80
80
|
resolution: proV2vResolutionSchema,
|
|
81
81
|
enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt"),
|
|
@@ -83,7 +83,7 @@ const modelInputSchemas = {
|
|
|
83
83
|
}),
|
|
84
84
|
"lucy-fast-v2v": z.object({
|
|
85
85
|
prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
|
|
86
|
-
data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
|
|
86
|
+
data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL). Output video is limited to 5 seconds."),
|
|
87
87
|
seed: z.number().optional().describe("The seed to use for the generation"),
|
|
88
88
|
resolution: proV2vResolutionSchema,
|
|
89
89
|
enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt")
|
|
@@ -103,7 +103,7 @@ const modelInputSchemas = {
|
|
|
103
103
|
enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt")
|
|
104
104
|
}),
|
|
105
105
|
"lucy-motion": z.object({
|
|
106
|
-
data: fileInputSchema.describe("The image data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
|
|
106
|
+
data: fileInputSchema.describe("The image data to use for generation (File, Blob, ReadableStream, URL, or string URL). Output video is limited to 5 seconds."),
|
|
107
107
|
trajectory: z.array(z.object({
|
|
108
108
|
frame: z.number().min(0),
|
|
109
109
|
x: z.number().min(0),
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decartai/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Decart's JavaScript SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"mitt": "^3.0.1",
|
|
44
44
|
"p-retry": "^6.2.1",
|
|
45
|
-
"uuid": "^
|
|
45
|
+
"uuid": "^13.0.0",
|
|
46
46
|
"zod": "^4.0.17"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|