@decartai/sdk 0.0.42 → 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 +2 -1
- package/dist/realtime/client.d.ts +2 -0
- package/dist/realtime/client.js +16 -12
- package/dist/realtime/methods.d.ts +11 -0
- package/dist/realtime/methods.js +28 -2
- package/package.json +1 -1
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 };
|
|
@@ -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
|
}?: {
|
package/dist/realtime/client.js
CHANGED
|
@@ -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
|
-
|
|
105
|
-
|
|
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 };
|
package/dist/realtime/methods.js
CHANGED
|
@@ -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
|
|
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 {
|
|
63
|
+
return {
|
|
64
|
+
set,
|
|
65
|
+
setPrompt
|
|
66
|
+
};
|
|
41
67
|
};
|
|
42
68
|
|
|
43
69
|
//#endregion
|