@d-id/client-sdk 1.0.18-beta.11 → 1.0.18-beta.13
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.js +25 -16
- package/dist/index.umd.cjs +25 -16
- package/dist/src/lib/connectToSocket.d.ts +2 -1
- package/dist/src/types/entities/agents/manager.d.ts +12 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -182,14 +182,15 @@ async function connectWithRetries(options) {
|
|
|
182
182
|
}
|
|
183
183
|
return socket;
|
|
184
184
|
}
|
|
185
|
-
async function SocketManager(auth, host = didSocketApiUrl) {
|
|
186
|
-
const messageCallbacks = [];
|
|
185
|
+
async function SocketManager(auth, onMessage, host = didSocketApiUrl) {
|
|
186
|
+
const messageCallbacks = onMessage ? [onMessage] : [];
|
|
187
187
|
const socket = await connectWithRetries({
|
|
188
188
|
auth,
|
|
189
189
|
host,
|
|
190
190
|
callbacks: {
|
|
191
191
|
onMessage: (event) => {
|
|
192
|
-
|
|
192
|
+
const parsedData = JSON.parse(event.data);
|
|
193
|
+
messageCallbacks.forEach((callback) => callback(parsedData.event, parsedData));
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
});
|
|
@@ -230,6 +231,14 @@ var RateState = /* @__PURE__ */ ((RateState2) => {
|
|
|
230
231
|
RateState2["Negative"] = "Negative";
|
|
231
232
|
return RateState2;
|
|
232
233
|
})(RateState || {});
|
|
234
|
+
var ChatProgress = /* @__PURE__ */ ((ChatProgress2) => {
|
|
235
|
+
ChatProgress2["Embed"] = "embed";
|
|
236
|
+
ChatProgress2["Query"] = "query";
|
|
237
|
+
ChatProgress2["Partial"] = "partial";
|
|
238
|
+
ChatProgress2["Answer"] = "answer";
|
|
239
|
+
ChatProgress2["Complete"] = "done";
|
|
240
|
+
return ChatProgress2;
|
|
241
|
+
})(ChatProgress || {});
|
|
233
242
|
var Subject = /* @__PURE__ */ ((Subject2) => {
|
|
234
243
|
Subject2["KnowledgeProcessing"] = "knowledge/processing";
|
|
235
244
|
Subject2["KnowledgeIndexing"] = "knowledge/indexing";
|
|
@@ -297,6 +306,16 @@ function initializeStreamAndChat(agent, options, agentsApi, chat) {
|
|
|
297
306
|
reject(new Error("Cannot create connection"));
|
|
298
307
|
}
|
|
299
308
|
(_b = (_a = options.callbacks).onConnectionStateChange) == null ? void 0 : _b.call(_a, state);
|
|
309
|
+
},
|
|
310
|
+
// TODO remove when webscoket will return partial
|
|
311
|
+
onMessage: (event, data) => {
|
|
312
|
+
var _a, _b;
|
|
313
|
+
if (event === StreamEvents.ChatPartial) {
|
|
314
|
+
(_b = (_a = options.callbacks).onChatEvents) == null ? void 0 : _b.call(_a, ChatProgress.Partial, {
|
|
315
|
+
content: data,
|
|
316
|
+
event: ChatProgress.Partial
|
|
317
|
+
});
|
|
318
|
+
}
|
|
300
319
|
}
|
|
301
320
|
}
|
|
302
321
|
});
|
|
@@ -309,7 +328,7 @@ async function createAgentManager(agentId, options) {
|
|
|
309
328
|
const ratingsAPI = createRatingsApi(options.auth, baseURL);
|
|
310
329
|
const knowledgeApi = createKnowledgeApi(options.auth, baseURL);
|
|
311
330
|
const agent = await agentsApi.getById(agentId);
|
|
312
|
-
const socketManager = await SocketManager(options.auth);
|
|
331
|
+
const socketManager = await SocketManager(options.auth, options.callbacks.onChatEvents);
|
|
313
332
|
let {
|
|
314
333
|
chat,
|
|
315
334
|
streamingManager
|
|
@@ -344,9 +363,6 @@ async function createAgentManager(agentId, options) {
|
|
|
344
363
|
return ratingsAPI.create(payload);
|
|
345
364
|
},
|
|
346
365
|
speak(payload) {
|
|
347
|
-
if (!agent) {
|
|
348
|
-
throw new Error("Agent not initializated");
|
|
349
|
-
}
|
|
350
366
|
let completePayload;
|
|
351
367
|
if (payload.type === "text") {
|
|
352
368
|
completePayload = {
|
|
@@ -367,15 +383,6 @@ async function createAgentManager(agentId, options) {
|
|
|
367
383
|
}
|
|
368
384
|
return streamingManager.speak(completePayload);
|
|
369
385
|
},
|
|
370
|
-
onChatEvents(callback) {
|
|
371
|
-
socketManager.subscribeToEvents(callback);
|
|
372
|
-
},
|
|
373
|
-
onConnectionEvents(callback) {
|
|
374
|
-
streamingManager.onCallback("onConnectionStateChange", callback);
|
|
375
|
-
},
|
|
376
|
-
onVideoEvents(callback) {
|
|
377
|
-
streamingManager.onCallback("onVideoStateChange", callback);
|
|
378
|
-
},
|
|
379
386
|
getStarterMessages() {
|
|
380
387
|
var _a, _b;
|
|
381
388
|
if (!((_a = agent.knowledge) == null ? void 0 : _a.id))
|
|
@@ -634,11 +641,13 @@ async function createStreamingManager(agent, {
|
|
|
634
641
|
};
|
|
635
642
|
}
|
|
636
643
|
export {
|
|
644
|
+
ChatProgress,
|
|
637
645
|
DocumentType,
|
|
638
646
|
KnowledgeType,
|
|
639
647
|
Providers,
|
|
640
648
|
RateState,
|
|
641
649
|
SocketManager,
|
|
650
|
+
StreamEvents,
|
|
642
651
|
Subject,
|
|
643
652
|
VoiceAccess,
|
|
644
653
|
createAgentManager,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -186,14 +186,15 @@
|
|
|
186
186
|
}
|
|
187
187
|
return socket;
|
|
188
188
|
}
|
|
189
|
-
async function SocketManager(auth, host = didSocketApiUrl) {
|
|
190
|
-
const messageCallbacks = [];
|
|
189
|
+
async function SocketManager(auth, onMessage, host = didSocketApiUrl) {
|
|
190
|
+
const messageCallbacks = onMessage ? [onMessage] : [];
|
|
191
191
|
const socket = await connectWithRetries({
|
|
192
192
|
auth,
|
|
193
193
|
host,
|
|
194
194
|
callbacks: {
|
|
195
195
|
onMessage: (event) => {
|
|
196
|
-
|
|
196
|
+
const parsedData = JSON.parse(event.data);
|
|
197
|
+
messageCallbacks.forEach((callback) => callback(parsedData.event, parsedData));
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
});
|
|
@@ -234,6 +235,14 @@
|
|
|
234
235
|
RateState2["Negative"] = "Negative";
|
|
235
236
|
return RateState2;
|
|
236
237
|
})(RateState || {});
|
|
238
|
+
var ChatProgress = /* @__PURE__ */ ((ChatProgress2) => {
|
|
239
|
+
ChatProgress2["Embed"] = "embed";
|
|
240
|
+
ChatProgress2["Query"] = "query";
|
|
241
|
+
ChatProgress2["Partial"] = "partial";
|
|
242
|
+
ChatProgress2["Answer"] = "answer";
|
|
243
|
+
ChatProgress2["Complete"] = "done";
|
|
244
|
+
return ChatProgress2;
|
|
245
|
+
})(ChatProgress || {});
|
|
237
246
|
var Subject = /* @__PURE__ */ ((Subject2) => {
|
|
238
247
|
Subject2["KnowledgeProcessing"] = "knowledge/processing";
|
|
239
248
|
Subject2["KnowledgeIndexing"] = "knowledge/indexing";
|
|
@@ -301,6 +310,16 @@
|
|
|
301
310
|
reject(new Error("Cannot create connection"));
|
|
302
311
|
}
|
|
303
312
|
(_b = (_a = options.callbacks).onConnectionStateChange) == null ? void 0 : _b.call(_a, state);
|
|
313
|
+
},
|
|
314
|
+
// TODO remove when webscoket will return partial
|
|
315
|
+
onMessage: (event, data) => {
|
|
316
|
+
var _a, _b;
|
|
317
|
+
if (event === StreamEvents.ChatPartial) {
|
|
318
|
+
(_b = (_a = options.callbacks).onChatEvents) == null ? void 0 : _b.call(_a, ChatProgress.Partial, {
|
|
319
|
+
content: data,
|
|
320
|
+
event: ChatProgress.Partial
|
|
321
|
+
});
|
|
322
|
+
}
|
|
304
323
|
}
|
|
305
324
|
}
|
|
306
325
|
});
|
|
@@ -313,7 +332,7 @@
|
|
|
313
332
|
const ratingsAPI = createRatingsApi(options.auth, baseURL);
|
|
314
333
|
const knowledgeApi = createKnowledgeApi(options.auth, baseURL);
|
|
315
334
|
const agent = await agentsApi.getById(agentId);
|
|
316
|
-
const socketManager = await SocketManager(options.auth);
|
|
335
|
+
const socketManager = await SocketManager(options.auth, options.callbacks.onChatEvents);
|
|
317
336
|
let {
|
|
318
337
|
chat,
|
|
319
338
|
streamingManager
|
|
@@ -348,9 +367,6 @@
|
|
|
348
367
|
return ratingsAPI.create(payload);
|
|
349
368
|
},
|
|
350
369
|
speak(payload) {
|
|
351
|
-
if (!agent) {
|
|
352
|
-
throw new Error("Agent not initializated");
|
|
353
|
-
}
|
|
354
370
|
let completePayload;
|
|
355
371
|
if (payload.type === "text") {
|
|
356
372
|
completePayload = {
|
|
@@ -371,15 +387,6 @@
|
|
|
371
387
|
}
|
|
372
388
|
return streamingManager.speak(completePayload);
|
|
373
389
|
},
|
|
374
|
-
onChatEvents(callback) {
|
|
375
|
-
socketManager.subscribeToEvents(callback);
|
|
376
|
-
},
|
|
377
|
-
onConnectionEvents(callback) {
|
|
378
|
-
streamingManager.onCallback("onConnectionStateChange", callback);
|
|
379
|
-
},
|
|
380
|
-
onVideoEvents(callback) {
|
|
381
|
-
streamingManager.onCallback("onVideoStateChange", callback);
|
|
382
|
-
},
|
|
383
390
|
getStarterMessages() {
|
|
384
391
|
var _a, _b;
|
|
385
392
|
if (!((_a = agent.knowledge) == null ? void 0 : _a.id))
|
|
@@ -637,11 +644,13 @@
|
|
|
637
644
|
}
|
|
638
645
|
};
|
|
639
646
|
}
|
|
647
|
+
exports2.ChatProgress = ChatProgress;
|
|
640
648
|
exports2.DocumentType = DocumentType;
|
|
641
649
|
exports2.KnowledgeType = KnowledgeType;
|
|
642
650
|
exports2.Providers = Providers;
|
|
643
651
|
exports2.RateState = RateState;
|
|
644
652
|
exports2.SocketManager = SocketManager;
|
|
653
|
+
exports2.StreamEvents = StreamEvents;
|
|
645
654
|
exports2.Subject = Subject;
|
|
646
655
|
exports2.VoiceAccess = VoiceAccess;
|
|
647
656
|
exports2.createAgentManager = createAgentManager;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Auth } from '../types/auth';
|
|
2
|
+
import { ChatProgressCallback } from '..';
|
|
2
3
|
interface SocketManager {
|
|
3
4
|
socket?: WebSocket;
|
|
4
5
|
terminate: () => void;
|
|
5
6
|
subscribeToEvents: (data: any) => void;
|
|
6
7
|
}
|
|
7
|
-
export declare function SocketManager(auth: Auth, host?: string): Promise<SocketManager>;
|
|
8
|
+
export declare function SocketManager(auth: Auth, onMessage?: ChatProgressCallback, host?: string): Promise<SocketManager>;
|
|
8
9
|
export {};
|
|
@@ -6,30 +6,34 @@ import { ChatResponse, Message, RatingEntity, RatingPayload } from './chat';
|
|
|
6
6
|
/**
|
|
7
7
|
* Types of events provided in Chat Progress Callback
|
|
8
8
|
*/
|
|
9
|
-
declare enum ChatProgress {
|
|
9
|
+
export declare enum ChatProgress {
|
|
10
10
|
/**
|
|
11
11
|
* Chat was successfully embedded
|
|
12
12
|
*/
|
|
13
|
-
Embed =
|
|
13
|
+
Embed = "embed",
|
|
14
14
|
/**
|
|
15
15
|
* Server processing chat message
|
|
16
16
|
*/
|
|
17
|
-
Query =
|
|
17
|
+
Query = "query",
|
|
18
|
+
/**
|
|
19
|
+
* Server returns a part of the message
|
|
20
|
+
*/
|
|
21
|
+
Partial = "partial",
|
|
18
22
|
/**
|
|
19
23
|
* Server processed message and returned response
|
|
20
24
|
*/
|
|
21
|
-
Answer =
|
|
25
|
+
Answer = "answer",
|
|
22
26
|
/**
|
|
23
27
|
* Chat was closed
|
|
24
28
|
*/
|
|
25
|
-
Complete =
|
|
29
|
+
Complete = "done"
|
|
26
30
|
}
|
|
27
|
-
export type ChatProgressCallback = (progress: ChatProgress) => void;
|
|
31
|
+
export type ChatProgressCallback = (progress: ChatProgress, data: string) => void;
|
|
28
32
|
export type ConnectionStateChangeCallback = (state: RTCIceConnectionState) => void;
|
|
29
33
|
export type VideoStateChangeCallback = (state: StreamingState, stats?: SlimRTCStatsReport[]) => void;
|
|
30
34
|
interface ManagerCallbacks {
|
|
31
35
|
/**
|
|
32
|
-
*
|
|
36
|
+
* Optional callback will be triggered each time the RTC connection changes state
|
|
33
37
|
* @param state
|
|
34
38
|
*/
|
|
35
39
|
onConnectionStateChange?(state: RTCIceConnectionState): void;
|
|
@@ -51,7 +55,7 @@ interface ManagerCallbacks {
|
|
|
51
55
|
* Optional callback function that will be triggered each time any changes happen in the chat
|
|
52
56
|
* @param progress
|
|
53
57
|
*/
|
|
54
|
-
onChatEvents?(progress: ChatProgress): void;
|
|
58
|
+
onChatEvents?(progress: ChatProgress, data: any): void;
|
|
55
59
|
}
|
|
56
60
|
export interface AgentManagerOptions {
|
|
57
61
|
callbacks: ManagerCallbacks;
|
|
@@ -99,21 +103,6 @@ export interface AgentManager {
|
|
|
99
103
|
* Optional callback function that will be triggered each time any changes happen in the chat
|
|
100
104
|
* @param callback
|
|
101
105
|
*/
|
|
102
|
-
onChatEvents: (callback: ChatProgressCallback) => void;
|
|
103
|
-
/**
|
|
104
|
-
* Optional callback function that will be triggered each time the RTC connection gets new status
|
|
105
|
-
* @param callback
|
|
106
|
-
*/
|
|
107
|
-
onConnectionEvents: (callback: ConnectionStateChangeCallback) => void;
|
|
108
|
-
/**
|
|
109
|
-
* Optional callback function that will be triggered each time video events happen
|
|
110
|
-
* @param callback
|
|
111
|
-
*/
|
|
112
|
-
onVideoEvents: (callback: VideoStateChangeCallback) => void;
|
|
113
|
-
/**
|
|
114
|
-
* Get Starter messages from agent knowledge
|
|
115
|
-
* @param agent
|
|
116
|
-
*/
|
|
117
106
|
getStarterMessages: () => Promise<string[]>;
|
|
118
107
|
}
|
|
119
108
|
export {};
|