@decartai/sdk 0.0.61 → 0.0.62
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.
|
@@ -16,6 +16,11 @@ declare const realTimeClientInitialStateSchema: z.ZodObject<{
|
|
|
16
16
|
image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Blob, Blob>, z.ZodCustom<File, File>, z.ZodString]>>;
|
|
17
17
|
}, z.core.$strip>;
|
|
18
18
|
type OnRemoteStreamFn = (stream: MediaStream) => void;
|
|
19
|
+
type OnStatusFn = (status: string) => void;
|
|
20
|
+
type OnQueuePositionFn = (data: {
|
|
21
|
+
position: number;
|
|
22
|
+
queueSize: number;
|
|
23
|
+
}) => void;
|
|
19
24
|
type RealTimeClientInitialState = z.infer<typeof realTimeClientInitialStateSchema>;
|
|
20
25
|
declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
|
|
21
26
|
model: z.ZodObject<{
|
|
@@ -36,6 +41,8 @@ declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
|
|
|
36
41
|
image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Blob, Blob>, z.ZodCustom<File, File>, z.ZodString]>>;
|
|
37
42
|
}, z.core.$strip>>;
|
|
38
43
|
customizeOffer: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>, z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>>>;
|
|
44
|
+
onStatus: z.ZodOptional<z.ZodCustom<OnStatusFn, OnStatusFn>>;
|
|
45
|
+
onQueuePosition: z.ZodOptional<z.ZodCustom<OnQueuePositionFn, OnQueuePositionFn>>;
|
|
39
46
|
}, z.core.$strip>;
|
|
40
47
|
type RealTimeClientConnectOptions = Omit<z.infer<typeof realTimeClientConnectOptionsSchema>, "model"> & {
|
|
41
48
|
model: ModelDefinition | CustomModelDefinition;
|
|
@@ -46,6 +53,11 @@ type Events = {
|
|
|
46
53
|
generationTick: {
|
|
47
54
|
seconds: number;
|
|
48
55
|
};
|
|
56
|
+
status: string;
|
|
57
|
+
queuePosition: {
|
|
58
|
+
position: number;
|
|
59
|
+
queueSize: number;
|
|
60
|
+
};
|
|
49
61
|
diagnostic: DiagnosticEvent;
|
|
50
62
|
stats: WebRTCStats;
|
|
51
63
|
};
|
package/dist/realtime/client.js
CHANGED
|
@@ -57,7 +57,9 @@ const realTimeClientConnectOptionsSchema = z.object({
|
|
|
57
57
|
model: modelDefinitionSchema,
|
|
58
58
|
onRemoteStream: z.custom((val) => typeof val === "function", { message: "onRemoteStream must be a function" }),
|
|
59
59
|
initialState: realTimeClientInitialStateSchema.optional(),
|
|
60
|
-
customizeOffer: createAsyncFunctionSchema(z.function()).optional()
|
|
60
|
+
customizeOffer: createAsyncFunctionSchema(z.function()).optional(),
|
|
61
|
+
onStatus: z.custom((val) => typeof val === "function", { message: "onStatus must be a function" }).optional(),
|
|
62
|
+
onQueuePosition: z.custom((val) => typeof val === "function", { message: "onQueuePosition must be a function" }).optional()
|
|
61
63
|
});
|
|
62
64
|
const createRealTimeClient = (opts) => {
|
|
63
65
|
const { baseUrl, apiKey, integration, logger } = opts;
|
|
@@ -65,7 +67,7 @@ const createRealTimeClient = (opts) => {
|
|
|
65
67
|
const parsedOptions = realTimeClientConnectOptionsSchema.safeParse(options);
|
|
66
68
|
if (!parsedOptions.success) throw parsedOptions.error;
|
|
67
69
|
const isAvatarLive = options.model.name === "live_avatar" || options.model.name === "live-avatar";
|
|
68
|
-
const { onRemoteStream, initialState } = parsedOptions.data;
|
|
70
|
+
const { onRemoteStream, initialState, onStatus, onQueuePosition } = parsedOptions.data;
|
|
69
71
|
let audioStreamManager;
|
|
70
72
|
let inputStream;
|
|
71
73
|
if (isAvatarLive && !stream) {
|
|
@@ -155,6 +157,19 @@ const createRealTimeClient = (opts) => {
|
|
|
155
157
|
emitOrBuffer("generationTick", { seconds: msg.seconds });
|
|
156
158
|
};
|
|
157
159
|
manager.getWebsocketMessageEmitter().on("generationTick", tickListener);
|
|
160
|
+
const wsEmitter = manager.getWebsocketMessageEmitter();
|
|
161
|
+
wsEmitter.on("status", (msg) => {
|
|
162
|
+
emitOrBuffer("status", msg.status);
|
|
163
|
+
onStatus?.(msg.status);
|
|
164
|
+
});
|
|
165
|
+
wsEmitter.on("queuePosition", (msg) => {
|
|
166
|
+
const data = {
|
|
167
|
+
position: msg.position,
|
|
168
|
+
queueSize: msg.queue_size
|
|
169
|
+
};
|
|
170
|
+
emitOrBuffer("queuePosition", data);
|
|
171
|
+
onQueuePosition?.(data);
|
|
172
|
+
});
|
|
158
173
|
await manager.connect(inputStream);
|
|
159
174
|
const methods = realtimeMethods(manager, imageToBase64);
|
|
160
175
|
let statsCollector = null;
|
|
@@ -183,6 +183,14 @@ var WebRTCConnection = class {
|
|
|
183
183
|
this.websocketMessagesEmitter.emit("sessionId", msg);
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
|
+
if (msg.type === "status") {
|
|
187
|
+
this.websocketMessagesEmitter.emit("status", msg);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (msg.type === "queue_position") {
|
|
191
|
+
this.websocketMessagesEmitter.emit("queuePosition", msg);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
186
194
|
if (!this.pc) return;
|
|
187
195
|
switch (msg.type) {
|
|
188
196
|
case "ready": {
|