@decartai/sdk 0.0.12 → 0.0.14

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.
@@ -17,6 +17,7 @@ async function fileInputToBlob(input) {
17
17
  async function sendRequest({ baseUrl, apiKey, model, inputs, signal, integration }) {
18
18
  const formData = new FormData();
19
19
  for (const [key, value] of Object.entries(inputs)) if (value !== void 0 && value !== null) if (value instanceof Blob) formData.append(key, value);
20
+ else if (typeof value === "object" && value !== null) formData.append(key, JSON.stringify(value));
20
21
  else formData.append(key, String(value));
21
22
  const endpoint = `${baseUrl}${model.urlPath}`;
22
23
  const response = await fetch(endpoint, {
@@ -14,7 +14,7 @@ type OnRemoteStreamFn = (stream: MediaStream) => void;
14
14
  type RealTimeClientInitialState = z.infer<typeof realTimeClientInitialStateSchema>;
15
15
  declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
16
16
  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-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
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-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
18
  urlPath: z.ZodString;
19
19
  fps: z.ZodNumber;
20
20
  width: z.ZodNumber;
@@ -40,7 +40,9 @@ const createRealTimeClient = (opts) => {
40
40
  console.error("WebRTC error:", error);
41
41
  eventEmitter.emit("error", createWebrtcError(error));
42
42
  },
43
- customizeOffer: options.customizeOffer
43
+ customizeOffer: options.customizeOffer,
44
+ vp8MinBitrate: 200,
45
+ vp8StartBitrate: 600
44
46
  });
45
47
  await webrtcManager.connect(stream);
46
48
  const methods = realtimeMethods(webrtcManager);
@@ -11,7 +11,7 @@ var WebRTCConnection = class {
11
11
  constructor(callbacks = {}) {
12
12
  this.callbacks = callbacks;
13
13
  }
14
- async connect(url, localStream, timeout = 25e3, integration) {
14
+ async connect(url, localStream, timeout = 35e3, integration) {
15
15
  const deadline = Date.now() + timeout;
16
16
  this.localStream = localStream;
17
17
  const userAgent = encodeURIComponent(buildUserAgent(integration));
@@ -69,6 +69,7 @@ var WebRTCConnection = class {
69
69
  case "ready": {
70
70
  await this.applyCodecPreference("video/VP8");
71
71
  const offer = await this.pc.createOffer();
72
+ this.modifyVP8Bitrate(offer);
72
73
  await this.callbacks.customizeOffer?.(offer);
73
74
  await this.pc.setLocalDescription(offer);
74
75
  this.send({
@@ -187,6 +188,43 @@ var WebRTCConnection = class {
187
188
  }
188
189
  await videoTransceiver.setCodecPreferences(orderedCodecs);
189
190
  }
191
+ modifyVP8Bitrate(offer) {
192
+ if (!offer.sdp) return;
193
+ const minBitrateInKbps = this.callbacks.vp8MinBitrate;
194
+ const startBitrateInKbps = this.callbacks.vp8StartBitrate;
195
+ if (minBitrateInKbps === 0 && startBitrateInKbps === 0) return;
196
+ const bitrateParams = `x-google-min-bitrate=${minBitrateInKbps};x-google-start-bitrate=${startBitrateInKbps}`;
197
+ const sdpLines = offer.sdp.split("\r\n");
198
+ const modifiedLines = [];
199
+ for (let i = 0; i < sdpLines.length; i++) {
200
+ if (sdpLines[i].includes("VP8/90000")) {
201
+ const match = sdpLines[i].match(/a=rtpmap:(\d+) VP8/);
202
+ if (match) {
203
+ const payloadType = match[1];
204
+ let fmtpIndex = -1;
205
+ let insertAfterIndex = i;
206
+ for (let j = i + 1; j < sdpLines.length && sdpLines[j].startsWith("a="); j++) {
207
+ if (sdpLines[j].startsWith(`a=fmtp:${payloadType}`)) {
208
+ fmtpIndex = j;
209
+ break;
210
+ }
211
+ if (sdpLines[j].startsWith(`a=rtcp-fb:${payloadType}`)) insertAfterIndex = j;
212
+ if (sdpLines[j].startsWith("a=rtpmap:")) break;
213
+ }
214
+ if (fmtpIndex !== -1) {
215
+ if (!sdpLines[fmtpIndex].includes("x-google-min-bitrate")) sdpLines[fmtpIndex] += `;${bitrateParams}`;
216
+ } else {
217
+ for (let k = i; k <= insertAfterIndex; k++) modifiedLines.push(sdpLines[k]);
218
+ modifiedLines.push(`a=fmtp:${payloadType} ${bitrateParams}`);
219
+ i = insertAfterIndex;
220
+ continue;
221
+ }
222
+ }
223
+ }
224
+ modifiedLines.push(sdpLines[i]);
225
+ }
226
+ offer.sdp = modifiedLines.join("\r\n");
227
+ }
190
228
  };
191
229
 
192
230
  //#endregion
@@ -19,7 +19,9 @@ var WebRTCManager = class {
19
19
  onRemoteStream: config.onRemoteStream,
20
20
  onStateChange: config.onConnectionStateChange,
21
21
  onError: config.onError,
22
- customizeOffer: config.customizeOffer
22
+ customizeOffer: config.customizeOffer,
23
+ vp8MinBitrate: config.vp8MinBitrate,
24
+ vp8StartBitrate: config.vp8StartBitrate
23
25
  });
24
26
  }
25
27
  async connect(localStream) {
@@ -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-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">]>;
5
+ declare const videoModels: z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-dev-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-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">]>, 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-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>;
@@ -81,6 +81,16 @@ declare const modelInputSchemas: {
81
81
  }>>>;
82
82
  enhance_prompt: z.ZodOptional<z.ZodBoolean>;
83
83
  }, z.core.$strip>;
84
+ readonly "lucy-motion": z.ZodObject<{
85
+ data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL]>;
86
+ trajectory: z.ZodArray<z.ZodObject<{
87
+ frame: z.ZodNumber;
88
+ x: z.ZodNumber;
89
+ y: z.ZodNumber;
90
+ }, z.core.$strip>>;
91
+ seed: z.ZodOptional<z.ZodNumber>;
92
+ resolution: z.ZodOptional<z.ZodDefault<z.ZodLiteral<"720p">>>;
93
+ }, z.core.$strip>;
84
94
  };
85
95
  type ModelInputSchemas = typeof modelInputSchemas;
86
96
  type ModelDefinition<T extends Model = Model> = {
@@ -13,7 +13,8 @@ const videoModels = z.union([
13
13
  z.literal("lucy-pro-t2v"),
14
14
  z.literal("lucy-pro-i2v"),
15
15
  z.literal("lucy-pro-v2v"),
16
- z.literal("lucy-pro-flf2v")
16
+ z.literal("lucy-pro-flf2v"),
17
+ z.literal("lucy-motion")
17
18
  ]);
18
19
  const imageModels = z.union([z.literal("lucy-pro-t2i"), z.literal("lucy-pro-i2i")]);
19
20
  const modelSchema = z.union([
@@ -40,6 +41,10 @@ const proResolutionSchema = () => {
40
41
  return z.enum(["720p", "480p"]).optional().describe("The resolution to use for the generation").default("720p");
41
42
  };
42
43
  /**
44
+ * Resolution schema for lucy-motion.
45
+ */
46
+ const motionResolutionSchema = z.literal("720p").default("720p").optional().describe("The resolution to use for the generation");
47
+ /**
43
48
  * Resolution schema for lucy-pro-v2v (supports 720p and 480p).
44
49
  */
45
50
  const proV2vResolutionSchema = z.enum(["720p", "480p"]).optional().describe("The resolution to use for the generation").default("720p");
@@ -96,6 +101,16 @@ const modelInputSchemas = {
96
101
  seed: z.number().optional().describe("The seed to use for the generation"),
97
102
  resolution: proResolutionSchema(),
98
103
  enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt")
104
+ }),
105
+ "lucy-motion": z.object({
106
+ data: fileInputSchema.describe("The image data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
107
+ trajectory: z.array(z.object({
108
+ frame: z.number().min(0),
109
+ x: z.number().min(0),
110
+ y: z.number().min(0)
111
+ })).min(2).max(121).describe("The trajectory of the desired movement of the object in the image"),
112
+ seed: z.number().optional().describe("The seed to use for the generation"),
113
+ resolution: motionResolutionSchema
99
114
  })
100
115
  };
101
116
  const modelDefinitionSchema = z.object({
@@ -199,6 +214,14 @@ const _models = {
199
214
  width: 1280,
200
215
  height: 704,
201
216
  inputSchema: modelInputSchemas["lucy-pro-flf2v"]
217
+ },
218
+ "lucy-motion": {
219
+ urlPath: "/v1/generate/lucy-motion",
220
+ name: "lucy-motion",
221
+ fps: 25,
222
+ width: 1280,
223
+ height: 704,
224
+ inputSchema: modelInputSchemas["lucy-motion"]
202
225
  }
203
226
  }
204
227
  };
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.12";
7
+ const VERSION = "0.0.14";
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.12",
3
+ "version": "0.0.14",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",