@decartai/sdk 0.0.1 → 0.0.2

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 (2) hide show
  1. package/README.md +14 -350
  2. package/package.json +58 -58
package/README.md CHANGED
@@ -12,6 +12,11 @@ pnpm add @decartai/sdk
12
12
  yarn add @decartai/sdk
13
13
  ```
14
14
 
15
+ ## Documentation
16
+
17
+ For complete documentation, guides, and examples, visit:
18
+ **https://docs.platform.decart.ai/sdks/javascript**
19
+
15
20
  ## Quick Start
16
21
 
17
22
  ### Real-time Video Transformation
@@ -40,13 +45,12 @@ const client = createDecartClient({
40
45
  const realtimeClient = await client.realtime.connect(stream, {
41
46
  model,
42
47
  onRemoteStream: (transformedStream) => {
43
- // Display the transformed video in your app
44
48
  videoElement.srcObject = transformedStream;
45
49
  },
46
50
  initialState: {
47
51
  prompt: {
48
52
  text: "Anime",
49
- enrich: true // We will enhance your prompt for better results
53
+ enrich: true
50
54
  }
51
55
  }
52
56
  });
@@ -58,364 +62,24 @@ realtimeClient.setPrompt("Cyberpunk city");
58
62
  realtimeClient.disconnect();
59
63
  ```
60
64
 
61
- ### Process Video Files
65
+ ### Process Files
62
66
 
63
67
  ```typescript
64
- import { createDecartClient } from "@decartai/sdk";
68
+ import { createDecartClient, models } from "@decartai/sdk";
65
69
 
66
- // Create a client
67
70
  const client = createDecartClient({
68
71
  apiKey: "your-api-key-here"
69
72
  });
70
73
 
71
- // Process a local video file
72
- const fileInput = document.querySelector('input[type="file"]');
73
- const file = fileInput.files[0];
74
-
75
- const result = await client.process.video(file, {
76
- model: models.realtime("mirage"),
77
- prompt: {
78
- text: "Lego World",
79
- enrich: true
80
- },
81
- mirror: false
82
- });
83
-
84
- // Display the processed video
85
- const video = document.querySelector('video');
86
- video.src = URL.createObjectURL(result);
87
-
88
- // Process a video from URL
89
- const urlResult = await client.process.video(
90
- "https://example.com/video.mp4",
91
- {
92
- model: models.realtime("mirage"),
93
- prompt: {
94
- text: "Anime style"
95
- }
96
- }
97
- );
98
- ```
99
-
100
- ## Features
101
-
102
- - **Real-time video transformation** - Transform video streams with minimal latency using WebRTC
103
- - **Video file processing** - Transform video files and URLs on-demand
104
- - **Dynamic prompt switching** - Change styles on the fly without reconnecting
105
- - **Automatic prompt enhancement** - Decart enriches simple prompts for better results
106
- - **Mirror mode** - Built-in support for front-facing camera scenarios
107
- - **Connection state management** - Monitor and react to connection changes
108
- - **TypeScript support** - Full type definitions included
109
-
110
- ## Usage Guide
111
-
112
- ### Real-time API
113
-
114
- #### 1. Creating a Client
115
-
116
- ```typescript
117
- const client = createDecartClient({
118
- apiKey: "your-api-key-here",
119
- baseUrl: "https://custom-endpoint.com" // optional, uses default Decart endpoint
120
- });
121
- ```
122
-
123
- #### 2. Connecting to the Real-time API
124
-
125
- ```typescript
126
- const realtimeClient = await client.realtime.connect(stream, {
127
- model: models.realtime("mirage"),
128
- onRemoteStream: (stream: MediaStream) => {
129
- // Handle the transformed video stream
130
- videoElement.srcObject = stream;
131
- },
132
- initialState: {
133
- prompt: {
134
- text: "Lego World",
135
- enrich: true // Let Decart enhance the prompt (recommended)
136
- },
137
- mirror: false // Set to true for front-facing cameras
138
- }
139
- });
140
- ```
141
-
142
- #### 3. Managing Prompts
143
-
144
- ```typescript
145
- // Simple prompt with automatic enhancement
146
- realtimeClient.setPrompt("Anime style");
147
-
148
- // Use your own detailed prompt without enhancement
149
- realtimeClient.setPrompt(
150
- "A detailed artistic style with specific colors and mood...",
151
- { enrich: false }
152
- );
153
-
154
- // Get an enhanced prompt without applying it (for preview/debugging)
155
- const enhanced = await realtimeClient.enrichPrompt("Pixel art");
156
- console.log(enhanced);
157
- realtimeClient.setPrompt(enhanced, { enrich: false });
158
- ```
159
-
160
- #### 4. Camera Mirroring
161
-
162
- ```typescript
163
- // Toggle mirror mode (useful for front-facing cameras)
164
- realtimeClient.setMirror(true);
165
- ```
166
-
167
- #### 5. Connection State Management
168
-
169
- ```typescript
170
- // Check connection state synchronously
171
- const isConnected = realtimeClient.isConnected();
172
- const state = realtimeClient.getConnectionState(); // "connected" | "connecting" | "disconnected"
173
-
174
- // Listen to connection changes
175
- realtimeClient.on("connectionChange", (state) => {
176
- console.log(`Connection state: ${state}`);
177
- if (state === "disconnected") {
178
- // Handle disconnection
179
- }
180
- });
181
- ```
182
-
183
- #### 6. Error Handling
184
-
185
- ```typescript
186
- import type { DecartSDKError } from "@decartai/sdk";
187
-
188
- realtimeClient.on("error", (error: DecartSDKError) => {
189
- console.error("SDK error:", error.code, error.message);
190
-
191
- // Handle specific errors
192
- switch(error.code) {
193
- case "INVALID_API_KEY":
194
- // Handle invalid API key
195
- break;
196
- case "WEB_RTC_ERROR":
197
- // Handle WebRTC connection issues
198
- break;
199
- }
200
- });
201
- ```
202
-
203
- #### 7. Cleanup
204
-
205
- ```typescript
206
- // Always disconnect when done
207
- realtimeClient.disconnect();
208
-
209
- // Remove event listeners
210
- realtimeClient.off("connectionChange", onConnectionChange);
211
- realtimeClient.off("error", onError);
212
- ```
213
-
214
- ### Complete Example
215
-
216
- ```typescript
217
- import { createDecartClient, type DecartSDKError } from "@decartai/sdk";
218
-
219
- async function setupSDK() {
220
- try {
221
- // Get camera stream
222
- const stream = await navigator.mediaDevices.getUserMedia({
223
- audio: true,
224
- video: { frameRate: 14 }
225
- });
226
-
227
- // Create client
228
- const client = createDecartClient({
229
- apiKey: process.env.MIRAGE_API_KEY
230
- });
231
-
232
- // Connect with initial prompt
233
- const realtimeClient = await client.realtime.connect(stream, {
234
- onRemoteStream: (stream) => {
235
- const video = document.getElementById("output-video");
236
- video.srcObject = stream;
237
- },
238
- initialState: {
239
- prompt: {
240
- text: "Studio Ghibli animation style",
241
- enrich: true
242
- },
243
- mirror: true // Using front camera
244
- }
245
- });
246
-
247
- // Set up event handlers
248
- realtimeClient.on("connectionChange", (state) => {
249
- updateUIConnectionStatus(state);
250
- });
251
-
252
- realtimeClient.on("error", (error) => {
253
- console.error("SDK error:", error);
254
- showErrorToUser(error.message);
255
- });
256
-
257
- // Allow user to change styles
258
- document.getElementById("style-input").addEventListener("change", async (e) => {
259
- realtimeClient.setPrompt(e.target.value);
260
- });
261
-
262
- // Cleanup on page unload
263
- window.addEventListener("beforeunload", async () => {
264
- realtimeClient.disconnect();
265
- });
266
-
267
- return realtimeClient;
268
- } catch (error) {
269
- console.error("Failed to setup DecartSDK:", error);
270
- }
271
- }
272
-
273
- setupSDK();
274
- ```
275
-
276
- ## Process API
277
-
278
- #### 1. Creating a Client
279
-
280
- ```typescript
281
- const client = createDecartClient({
282
- apiKey: "your-api-key-here",
283
- baseUrl: "https://custom-endpoint.com" // optional, uses default Decart endpoint
284
- });
285
- ```
286
-
287
- #### 2. Process Video Files
288
-
289
- ```typescript
290
- // 1. Process a local file (browser)
291
- const fileInput = document.querySelector('input[type="file"]');
74
+ // Process a video file
292
75
  const file = fileInput.files[0];
293
-
294
- const result = await client.process.video(file, {
295
- prompt: {
296
- text: "Cartoon style",
297
- enrich: true
298
- },
299
- mirror: false
300
- });
301
-
302
- // Use the processed video
303
- const video = document.querySelector('video');
304
- video.src = URL.createObjectURL(result);
305
-
306
- // 3. With cancellation
307
- const controller = new AbortController();
308
- const result = await client.process.video(file, {
309
- prompt: { text: "Watercolor painting" },
310
- signal: controller.signal
76
+ const result = await client.process({
77
+ model: models.video("lucy-pro-v2v"),
78
+ prompt: "Lego World",
79
+ data: file
311
80
  });
312
81
 
313
- // Cancel if needed
314
- controller.abort();
315
- ```
316
-
317
- ## API Reference
318
-
319
- ### `createDecartClient(options)`
320
- Creates a new Decart client instance.
321
-
322
- - `options.apiKey` (required) - Your Decart API key
323
- - `options.baseUrl` (optional) - Custom API endpoint (defaults to Decart)
324
-
325
- ### Real-time API
326
-
327
- #### `client.realtime.connect(stream, options)`
328
- Connects to the real-time transformation service.
329
-
330
- - `stream` - MediaStream from getUserMedia
331
- - `options.onRemoteStream` - Callback for transformed video stream
332
- - `options.initialState.prompt` - Initial transformation prompt
333
- - `options.initialState.mirror` - Enable mirror mode
334
-
335
- #### `realtimeClient.setPrompt(prompt, options?)`
336
- Changes the transformation style.
337
-
338
- - `prompt` - Text description of desired style
339
- - `options.enrich` - Whether to enhance the prompt (default: true)
340
-
341
- #### `realtimeClient.enrichPrompt(prompt)`
342
- Gets an enhanced version of your prompt without applying it.
343
-
344
- #### `realtimeClient.setMirror(enabled)`
345
- Toggles video mirroring.
346
-
347
- #### `realtimeClient.sessionId`
348
- The id of the current real-time inference session.
349
-
350
- #### `realtimeClient.disconnect()`
351
- Closes the connection and cleans up resources.
352
-
353
- #### Event: `'connectionChange'`
354
- Fired when connection state changes.
355
-
356
- #### Event: `'error'`
357
- Fired when an error occurs.
358
-
359
- ### Process API
360
-
361
- #### `client.process.video(input, options?)`
362
- Process a video file or URL.
363
-
364
- **Parameters:**
365
- - `input: FileInput` - Video input, can be:
366
- - `File` - File object from input element (browser)
367
- - `Blob` - Binary data (browser)
368
- - `ReadableStream` - Streaming input
369
- - `URL` or `string` - HTTP/HTTPS URL to video
370
-
371
- - `options?: ProcessOptions` - Optional configuration:
372
- - `prompt?: { text: string; enrich?: boolean }` - Style transformation
373
- - `text` - Style description (required if prompt is provided)
374
- - `enrich` - Enable prompt enhancement (default: `true`)
375
- - `mirror?: boolean` - Mirror the video horizontally (default: `false`)
376
- - `signal?: AbortSignal` - AbortSignal for cancellation
377
-
378
- **Returns:** `Promise<Blob>` - The transformed video
379
-
380
- **Type Definitions:**
381
- ```typescript
382
- type FileInput = File | Blob | ReadableStream | URL | string;
383
-
384
- type ProcessOptions = {
385
- prompt?: {
386
- text: string;
387
- enrich?: boolean;
388
- };
389
- mirror?: boolean;
390
- signal?: AbortSignal;
391
- };
392
- ```
393
-
394
- ## Development
395
-
396
- ### Install dependencies
397
- ```bash
398
- pnpm install
399
- ```
400
-
401
- ### Run tests
402
- ```bash
403
- pnpm test
404
- ```
405
-
406
- ### Build the library
407
- ```bash
408
- pnpm build
409
- ```
410
-
411
- ### Run development mode
412
- ```bash
413
- pnpm dev
414
- ```
415
-
416
- ### Run examples
417
- ```bash
418
- pnpm dev:example
82
+ videoElement.src = URL.createObjectURL(result);
419
83
  ```
420
84
 
421
85
  ## License
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
1
  {
2
- "name": "@decartai/sdk",
3
- "version": "0.0.1",
4
- "description": "Decart's JavaScript SDK",
5
- "type": "module",
6
- "license": "MIT",
7
- "homepage": "https://github.com/decartai/mirage-sdk#readme",
8
- "bugs": {
9
- "url": "https://github.com/decartai/mirage-sdk/issues"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/decartai/mirage-sdk.git"
14
- },
15
- "author": "Adir Amsalem <adir@decart.ai>",
16
- "sideEffects": false,
17
- "files": [
18
- "dist"
19
- ],
20
- "main": "./dist/index.js",
21
- "module": "./dist/index.js",
22
- "types": "./dist/index.d.ts",
23
- "exports": {
24
- ".": "./dist/index.js",
25
- "./package.json": "./package.json"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "scripts": {
31
- "build": "tsdown",
32
- "dev": "tsdown --watch",
33
- "dev:example": "vite dev --port 3000",
34
- "test": "vitest",
35
- "typecheck": "tsc --noEmit",
36
- "format": "biome format --write",
37
- "format:check": "biome check",
38
- "lint": "biome lint",
39
- "prepublishOnly": "pnpm build",
40
- "release": "bumpp && npm publish"
41
- },
42
- "devDependencies": {
43
- "@types/node": "^22.15.17",
44
- "biome": "^0.3.3",
45
- "bumpp": "^10.1.0",
46
- "msw": "^2.11.3",
47
- "pkg-pr-new": "^0.0.56",
48
- "tsdown": "^0.14.1",
49
- "typescript": "^5.8.3",
50
- "vite": "^7.1.2",
51
- "vitest": "^3.1.3"
52
- },
53
- "dependencies": {
54
- "mitt": "^3.0.1",
55
- "p-retry": "^6.2.1",
56
- "uuid": "^11.1.0",
57
- "zod": "^4.0.17"
58
- }
59
- }
2
+ "name": "@decartai/sdk",
3
+ "version": "0.0.2",
4
+ "description": "Decart's JavaScript SDK",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "homepage": "https://github.com/decartai/sdk#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/decartai/sdk/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/decartai/sdk.git"
15
+ },
16
+ "author": "Adir Amsalem <adir@decart.ai>",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": "./dist/index.js",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^22.15.17",
33
+ "biome": "^0.3.3",
34
+ "bumpp": "^10.1.0",
35
+ "msw": "^2.11.3",
36
+ "pkg-pr-new": "^0.0.56",
37
+ "tsdown": "^0.14.1",
38
+ "typescript": "^5.8.3",
39
+ "vite": "^7.1.2",
40
+ "vitest": "^3.1.3"
41
+ },
42
+ "dependencies": {
43
+ "mitt": "^3.0.1",
44
+ "p-retry": "^6.2.1",
45
+ "uuid": "^11.1.0",
46
+ "zod": "^4.0.17"
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown",
50
+ "dev": "tsdown --watch",
51
+ "dev:example": "vite dev --port 3000",
52
+ "test": "vitest",
53
+ "typecheck": "tsc --noEmit",
54
+ "format": "biome format --write",
55
+ "format:check": "biome check",
56
+ "lint": "biome lint",
57
+ "release": "bumpp && npm publish"
58
+ }
59
+ }