@decartai/sdk 0.0.41 → 0.0.43

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 CHANGED
@@ -4,6 +4,7 @@ import { ProcessClient } from "./process/client.js";
4
4
  import { JobStatus, JobStatusResponse, JobSubmitResponse, QueueJobResult, QueueSubmitAndPollOptions, QueueSubmitOptions } from "./queue/types.js";
5
5
  import { QueueClient } from "./queue/client.js";
6
6
  import { DecartSDKError, ERROR_CODES } from "./utils/errors.js";
7
+ import { SetInput } from "./realtime/methods.js";
7
8
  import { AvatarOptions, RealTimeClient, RealTimeClientConnectOptions, RealTimeClientInitialState } from "./realtime/client.js";
8
9
  import { ModelState } from "./shared/types.js";
9
10
  import { CreateTokenResponse, TokensClient } from "./tokens/client.js";
@@ -117,4 +118,4 @@ declare const createDecartClient: (options?: DecartClientOptions) => {
117
118
  tokens: TokensClient;
118
119
  };
119
120
  //#endregion
120
- export { type AvatarOptions, 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 ReactNativeFile, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type TokensClient, type VideoModelDefinition, type VideoModels, createDecartClient, isImageModel, isRealtimeModel, isVideoModel, models };
121
+ export { type AvatarOptions, 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 ReactNativeFile, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type SetInput, type TokensClient, type VideoModelDefinition, type VideoModels, createDecartClient, isImageModel, isRealtimeModel, isVideoModel, models };
@@ -158,12 +158,6 @@ interface ProcessInputs {
158
158
  * @default true
159
159
  */
160
160
  enhance_prompt?: boolean;
161
- /**
162
- * The number of inference steps.
163
- *
164
- * @default 50
165
- */
166
- num_inference_steps?: number;
167
161
  }
168
162
  /**
169
163
  * ProcessInputs combined with model-specific inputs.
@@ -1,4 +1,5 @@
1
1
  import { DecartSDKError } from "../utils/errors.js";
2
+ import { SetInput } from "./methods.js";
2
3
  import { z } from "zod";
3
4
 
4
5
  //#region src/realtime/client.d.ts
@@ -43,6 +44,7 @@ type Events = {
43
44
  error: DecartSDKError;
44
45
  };
45
46
  type RealTimeClient = {
47
+ set: (input: SetInput) => Promise<void>;
46
48
  setPrompt: (prompt: string, {
47
49
  enhance
48
50
  }?: {
@@ -20,6 +20,18 @@ async function blobToBase64(blob) {
20
20
  reader.readAsDataURL(blob);
21
21
  });
22
22
  }
23
+ async function imageToBase64(image) {
24
+ if (typeof image === "string") {
25
+ let url = null;
26
+ try {
27
+ url = new URL(image);
28
+ } catch {}
29
+ if (url?.protocol === "data:") return image.split(",")[1];
30
+ if (url?.protocol === "http:" || url?.protocol === "https:") return blobToBase64(await (await fetch(image)).blob());
31
+ return image;
32
+ }
33
+ return blobToBase64(image);
34
+ }
23
35
  const realTimeClientInitialStateSchema = modelStateSchema;
24
36
  const createAsyncFunctionSchema = (schema) => z.custom((fn) => schema.implementAsync(fn));
25
37
  const avatarOptionsSchema = z.object({ avatarImage: z.union([
@@ -83,12 +95,13 @@ const createRealTimeClient = (opts) => {
83
95
  initialPrompt
84
96
  });
85
97
  await webrtcManager.connect(inputStream);
86
- const methods = realtimeMethods(webrtcManager);
98
+ const methods = realtimeMethods(webrtcManager, imageToBase64);
87
99
  if (!isAvatarLive && options.initialState?.prompt) {
88
100
  const { text, enhance } = options.initialState.prompt;
89
101
  methods.setPrompt(text, { enhance });
90
102
  }
91
103
  const client = {
104
+ set: methods.set,
92
105
  setPrompt: methods.setPrompt,
93
106
  isConnected: () => webrtcManager.isConnected(),
94
107
  getConnectionState: () => webrtcManager.getConnectionState(),
@@ -101,17 +114,8 @@ const createRealTimeClient = (opts) => {
101
114
  sessionId,
102
115
  setImage: async (image, options$1) => {
103
116
  if (image === null) return webrtcManager.setImage(null, options$1);
104
- let imageBase64;
105
- if (typeof image === "string") {
106
- let url = null;
107
- try {
108
- url = new URL(image);
109
- } catch {}
110
- if (url?.protocol === "data:") imageBase64 = image.split(",")[1];
111
- else if (url?.protocol === "http:" || url?.protocol === "https:") imageBase64 = await blobToBase64(await (await fetch(image)).blob());
112
- else imageBase64 = image;
113
- } else imageBase64 = await blobToBase64(image);
114
- return webrtcManager.setImage(imageBase64, options$1);
117
+ const base64 = await imageToBase64(image);
118
+ return webrtcManager.setImage(base64, options$1);
115
119
  }
116
120
  };
117
121
  if (isAvatarLive && audioStreamManager) {
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/realtime/methods.d.ts
4
+ declare const setInputSchema: z.ZodObject<{
5
+ prompt: z.ZodOptional<z.ZodString>;
6
+ enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
7
+ image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Blob, Blob>, z.ZodCustom<File, File>, z.ZodString, z.ZodNull]>>;
8
+ }, z.core.$strip>;
9
+ type SetInput = z.input<typeof setInputSchema>;
10
+ //#endregion
11
+ export { SetInput };
@@ -2,7 +2,30 @@ import { z } from "zod";
2
2
 
3
3
  //#region src/realtime/methods.ts
4
4
  const PROMPT_TIMEOUT_MS = 15 * 1e3;
5
- const realtimeMethods = (webrtcManager) => {
5
+ const UPDATE_TIMEOUT_MS = 30 * 1e3;
6
+ const setInputSchema = z.object({
7
+ prompt: z.string().min(1).optional(),
8
+ enhance: z.boolean().optional().default(true),
9
+ image: z.union([
10
+ z.instanceof(Blob),
11
+ z.instanceof(File),
12
+ z.string(),
13
+ z.null()
14
+ ]).optional()
15
+ }).refine((data) => data.prompt !== void 0 || data.image !== void 0, { message: "At least one of 'prompt' or 'image' must be provided" });
16
+ const realtimeMethods = (webrtcManager, imageToBase64) => {
17
+ const set = async (input) => {
18
+ const parsed = setInputSchema.safeParse(input);
19
+ if (!parsed.success) throw parsed.error;
20
+ const { prompt, enhance, image } = parsed.data;
21
+ let imageBase64 = null;
22
+ if (image !== void 0 && image !== null) imageBase64 = await imageToBase64(image);
23
+ await webrtcManager.setImage(imageBase64, {
24
+ prompt,
25
+ enhance,
26
+ timeout: UPDATE_TIMEOUT_MS
27
+ });
28
+ };
6
29
  const setPrompt = async (prompt, { enhance } = {}) => {
7
30
  const parsedInput = z.object({
8
31
  prompt: z.string().min(1),
@@ -37,7 +60,10 @@ const realtimeMethods = (webrtcManager) => {
37
60
  if (timeoutId) clearTimeout(timeoutId);
38
61
  }
39
62
  };
40
- return { setPrompt };
63
+ return {
64
+ set,
65
+ setPrompt
66
+ };
41
67
  };
42
68
 
43
69
  //#endregion
@@ -3,7 +3,7 @@ import mitt from "mitt";
3
3
 
4
4
  //#region src/realtime/webrtc-connection.ts
5
5
  const ICE_SERVERS = [{ urls: "stun:stun.l.google.com:19302" }];
6
- const AVATAR_SETUP_TIMEOUT_MS = 15e3;
6
+ const AVATAR_SETUP_TIMEOUT_MS = 3e4;
7
7
  var WebRTCConnection = class {
8
8
  pc = null;
9
9
  ws = null;
@@ -14,7 +14,7 @@ var WebRTCConnection = class {
14
14
  constructor(callbacks = {}) {
15
15
  this.callbacks = callbacks;
16
16
  }
17
- async connect(url, localStream, timeout = 6e4, integration) {
17
+ async connect(url, localStream, timeout, integration) {
18
18
  const deadline = Date.now() + timeout;
19
19
  this.localStream = localStream;
20
20
  const userAgent = encodeURIComponent(buildUserAgent(integration));
@@ -29,7 +29,7 @@ var WebRTCManager = class {
29
29
  }
30
30
  async connect(localStream) {
31
31
  return pRetry(async () => {
32
- await this.connection.connect(this.config.webrtcUrl, localStream, 6e4, this.config.integration);
32
+ await this.connection.connect(this.config.webrtcUrl, localStream, 6e4 * 5, this.config.integration);
33
33
  return true;
34
34
  }, {
35
35
  retries: 5,
@@ -69,7 +69,6 @@ declare const modelInputSchemas: {
69
69
  seed: z.ZodOptional<z.ZodNumber>;
70
70
  resolution: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"720p">>>;
71
71
  enhance_prompt: z.ZodOptional<z.ZodBoolean>;
72
- num_inference_steps: z.ZodOptional<z.ZodNumber>;
73
72
  }, z.core.$strip>;
74
73
  readonly "lucy-fast-v2v": z.ZodObject<{
75
74
  prompt: z.ZodString;
@@ -96,8 +96,7 @@ const modelInputSchemas = {
96
96
  reference_image: fileInputSchema.optional().describe("Optional reference image to guide what to add to the video (File, Blob, ReadableStream, URL, or string URL)"),
97
97
  seed: z.number().optional().describe("The seed to use for the generation"),
98
98
  resolution: proV2vResolutionSchema,
99
- enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt"),
100
- num_inference_steps: z.number().optional().describe("The number of inference steps")
99
+ enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt")
101
100
  }),
102
101
  "lucy-fast-v2v": z.object({
103
102
  prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",