@decartai/sdk 0.0.17 → 0.0.19

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.
@@ -8,13 +8,12 @@ declare const realTimeClientInitialStateSchema: z.ZodObject<{
8
8
  text: z.ZodString;
9
9
  enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
10
10
  }, z.core.$strip>>;
11
- mirror: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
12
11
  }, z.core.$strip>;
13
12
  type OnRemoteStreamFn = (stream: MediaStream) => void;
14
13
  type RealTimeClientInitialState = z.infer<typeof realTimeClientInitialStateSchema>;
15
14
  declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
16
15
  model: z.ZodObject<{
17
- 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-dev-v2v">, 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.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
18
17
  urlPath: z.ZodString;
19
18
  fps: z.ZodNumber;
20
19
  width: z.ZodNumber;
@@ -27,7 +26,6 @@ declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
27
26
  text: z.ZodString;
28
27
  enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
29
28
  }, z.core.$strip>>;
30
- mirror: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
31
29
  }, z.core.$strip>>;
32
30
  customizeOffer: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>, z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>>>;
33
31
  }, z.core.$strip>;
@@ -41,13 +39,12 @@ type RealTimeClient = {
41
39
  enhance
42
40
  }?: {
43
41
  enhance?: boolean;
44
- }) => void;
45
- setMirror: (enabled: boolean) => void;
42
+ }) => Promise<void>;
46
43
  isConnected: () => boolean;
47
44
  getConnectionState: () => "connected" | "connecting" | "disconnected";
48
45
  disconnect: () => void;
49
- on: (event: keyof Events, listener: (...args: Events[keyof Events][]) => void) => void;
50
- off: (event: keyof Events, listener: (...args: Events[keyof Events][]) => void) => void;
46
+ on: <K extends keyof Events>(event: K, listener: (data: Events[K]) => void) => void;
47
+ off: <K extends keyof Events>(event: K, listener: (data: Events[K]) => void) => void;
51
48
  sessionId: string;
52
49
  };
53
50
  //#endregion
@@ -51,11 +51,9 @@ const createRealTimeClient = (opts) => {
51
51
  const { text, enhance } = options.initialState.prompt;
52
52
  methods.setPrompt(text, { enhance });
53
53
  }
54
- if (options.initialState.mirror) methods.setMirror(options.initialState.mirror);
55
54
  }
56
55
  return {
57
56
  setPrompt: methods.setPrompt,
58
- setMirror: methods.setMirror,
59
57
  isConnected: () => webrtcManager.isConnected(),
60
58
  getConnectionState: () => webrtcManager.getConnectionState(),
61
59
  disconnect: () => webrtcManager.cleanup(),
@@ -1,8 +1,9 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  //#region src/realtime/methods.ts
4
+ const PROMPT_TIMEOUT_MS = 15 * 1e3;
4
5
  const realtimeMethods = (webrtcManager) => {
5
- const setPrompt = (prompt, { enhance } = {}) => {
6
+ const setPrompt = async (prompt, { enhance } = {}) => {
6
7
  const parsedInput = z.object({
7
8
  prompt: z.string().min(1),
8
9
  enhance: z.boolean().optional().default(true)
@@ -11,24 +12,32 @@ const realtimeMethods = (webrtcManager) => {
11
12
  enhance
12
13
  });
13
14
  if (!parsedInput.success) throw parsedInput.error;
14
- webrtcManager.sendMessage({
15
- type: "prompt",
16
- prompt: parsedInput.data.prompt,
17
- enhance_prompt: parsedInput.data.enhance
18
- });
19
- };
20
- const setMirror = (enabled) => {
21
- const parsedInput = z.object({ enabled: z.boolean() }).safeParse({ enabled });
22
- if (!parsedInput.success) throw parsedInput.error;
23
- webrtcManager.sendMessage({
24
- type: "switch_camera",
25
- rotateY: parsedInput.data.enabled ? 2 : 0
26
- });
27
- };
28
- return {
29
- setPrompt,
30
- setMirror
15
+ const emitter = webrtcManager.getWebsocketMessageEmitter();
16
+ let promptAckListener;
17
+ let timeoutId;
18
+ try {
19
+ const ackPromise = new Promise((resolve, reject) => {
20
+ promptAckListener = (promptAckMessage) => {
21
+ if (promptAckMessage.prompt === parsedInput.data.prompt) if (promptAckMessage.success) resolve();
22
+ else reject(promptAckMessage.error);
23
+ };
24
+ emitter.on("promptAck", promptAckListener);
25
+ });
26
+ webrtcManager.sendMessage({
27
+ type: "prompt",
28
+ prompt: parsedInput.data.prompt,
29
+ enhance_prompt: parsedInput.data.enhance
30
+ });
31
+ const timeoutPromise = new Promise((_, reject) => {
32
+ timeoutId = setTimeout(() => reject(/* @__PURE__ */ new Error("Prompt timed out")), PROMPT_TIMEOUT_MS);
33
+ });
34
+ await Promise.race([ackPromise, timeoutPromise]);
35
+ } finally {
36
+ if (promptAckListener) emitter.off("promptAck", promptAckListener);
37
+ if (timeoutId) clearTimeout(timeoutId);
38
+ }
31
39
  };
40
+ return { setPrompt };
32
41
  };
33
42
 
34
43
  //#endregion
@@ -1,4 +1,5 @@
1
1
  import { buildUserAgent } from "../utils/user-agent.js";
2
+ import mitt from "mitt";
2
3
 
3
4
  //#region src/realtime/webrtc-connection.ts
4
5
  const ICE_SERVERS = [{ urls: "stun:stun.l.google.com:19302" }];
@@ -8,6 +9,7 @@ var WebRTCConnection = class {
8
9
  localStream = null;
9
10
  connectionReject = null;
10
11
  state = "disconnected";
12
+ websocketMessagesEmitter = mitt();
11
13
  constructor(callbacks = {}) {
12
14
  this.callbacks = callbacks;
13
15
  }
@@ -105,6 +107,9 @@ var WebRTCConnection = class {
105
107
  if (turnConfig) await this.setupNewPeerConnection(turnConfig);
106
108
  break;
107
109
  }
110
+ case "prompt_ack":
111
+ this.websocketMessagesEmitter.emit("promptAck", msg);
112
+ break;
108
113
  }
109
114
  } catch (error) {
110
115
  console.error("[WebRTC] Error:", error);
@@ -55,6 +55,9 @@ var WebRTCManager = class {
55
55
  getConnectionState() {
56
56
  return this.connection.state;
57
57
  }
58
+ getWebsocketMessageEmitter() {
59
+ return this.connection.websocketMessagesEmitter;
60
+ }
58
61
  };
59
62
 
60
63
  //#endregion
@@ -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-dev-v2v">, 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">]>;
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-dev-v2v">, 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.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>;
@@ -51,13 +51,6 @@ declare const modelInputSchemas: {
51
51
  enhance_prompt: z.ZodOptional<z.ZodBoolean>;
52
52
  num_inference_steps: z.ZodOptional<z.ZodNumber>;
53
53
  }, z.core.$strip>;
54
- readonly "lucy-dev-v2v": z.ZodObject<{
55
- prompt: z.ZodString;
56
- data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL]>;
57
- seed: z.ZodOptional<z.ZodNumber>;
58
- resolution: z.ZodOptional<z.ZodDefault<z.ZodLiteral<"720p">>>;
59
- enhance_prompt: z.ZodOptional<z.ZodBoolean>;
60
- }, z.core.$strip>;
61
54
  readonly "lucy-fast-v2v": z.ZodObject<{
62
55
  prompt: z.ZodString;
63
56
  data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL]>;
@@ -116,7 +109,7 @@ declare const models: {
116
109
  * - `"lucy-pro-v2v"` - Video-to-video
117
110
  * - `"lucy-pro-flf2v"` - First-last-frame-to-video
118
111
  * - `"lucy-dev-i2v"` - Image-to-video (Dev quality)
119
- * - `"lucy-dev-v2v"` - Video-to-video (Dev quality)
112
+ * - `"lucy-fast-v2v"` - Video-to-video (Fast quality)
120
113
  */
121
114
  video: <T extends VideoModels>(model: T) => ModelDefinition<T>;
122
115
  /**
@@ -9,7 +9,6 @@ const realtimeModels = z.union([
9
9
  ]);
10
10
  const videoModels = z.union([
11
11
  z.literal("lucy-dev-i2v"),
12
- z.literal("lucy-dev-v2v"),
13
12
  z.literal("lucy-fast-v2v"),
14
13
  z.literal("lucy-pro-t2v"),
15
14
  z.literal("lucy-pro-i2v"),
@@ -82,13 +81,6 @@ const modelInputSchemas = {
82
81
  enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt"),
83
82
  num_inference_steps: z.number().optional().describe("The number of inference steps")
84
83
  }),
85
- "lucy-dev-v2v": z.object({
86
- prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
87
- data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
88
- seed: z.number().optional().describe("The seed to use for the generation"),
89
- resolution: devResolutionSchema,
90
- enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt")
91
- }),
92
84
  "lucy-fast-v2v": z.object({
93
85
  prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
94
86
  data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
@@ -183,14 +175,6 @@ const _models = {
183
175
  height: 704,
184
176
  inputSchema: modelInputSchemas["lucy-dev-i2v"]
185
177
  },
186
- "lucy-dev-v2v": {
187
- urlPath: "/v1/generate/lucy-dev-v2v",
188
- name: "lucy-dev-v2v",
189
- fps: 25,
190
- width: 1280,
191
- height: 704,
192
- inputSchema: modelInputSchemas["lucy-dev-v2v"]
193
- },
194
178
  "lucy-fast-v2v": {
195
179
  urlPath: "/v1/generate/lucy-fast-v2v",
196
180
  name: "lucy-fast-v2v",
@@ -6,7 +6,6 @@ declare const modelStateSchema: z.ZodObject<{
6
6
  text: z.ZodString;
7
7
  enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
8
8
  }, z.core.$strip>>;
9
- mirror: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
10
9
  }, z.core.$strip>;
11
10
  type ModelState = z.infer<typeof modelStateSchema>;
12
11
  //#endregion
@@ -1,13 +1,10 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  //#region src/shared/types.ts
4
- const modelStateSchema = z.object({
5
- prompt: z.object({
6
- text: z.string().min(1),
7
- enhance: z.boolean().optional().default(true)
8
- }).optional(),
9
- mirror: z.boolean().optional().default(false)
10
- });
4
+ const modelStateSchema = z.object({ prompt: z.object({
5
+ text: z.string().min(1),
6
+ enhance: z.boolean().optional().default(true)
7
+ }).optional() });
11
8
 
12
9
  //#endregion
13
10
  export { modelStateSchema };
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.17";
7
+ const VERSION = "0.0.19";
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.17",
3
+ "version": "0.0.19",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",