@d-id/client-sdk 1.0.18-beta.10 → 1.0.18-beta.12
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
CHANGED
|
@@ -189,7 +189,12 @@ async function SocketManager(auth, host = didSocketApiUrl) {
|
|
|
189
189
|
host,
|
|
190
190
|
callbacks: {
|
|
191
191
|
onMessage: (event) => {
|
|
192
|
-
|
|
192
|
+
const data = JSON.parse(event.data);
|
|
193
|
+
let payload;
|
|
194
|
+
if (data.event === "answer") {
|
|
195
|
+
payload = data.content;
|
|
196
|
+
}
|
|
197
|
+
messageCallbacks.forEach((callback) => callback(data.event, payload));
|
|
193
198
|
}
|
|
194
199
|
}
|
|
195
200
|
});
|
|
@@ -230,6 +235,14 @@ var RateState = /* @__PURE__ */ ((RateState2) => {
|
|
|
230
235
|
RateState2["Negative"] = "Negative";
|
|
231
236
|
return RateState2;
|
|
232
237
|
})(RateState || {});
|
|
238
|
+
var ChatProgress = /* @__PURE__ */ ((ChatProgress2) => {
|
|
239
|
+
ChatProgress2["Embed"] = "embed";
|
|
240
|
+
ChatProgress2["Query"] = "query";
|
|
241
|
+
ChatProgress2["Partial"] = "chat/partial";
|
|
242
|
+
ChatProgress2["Answer"] = "answer";
|
|
243
|
+
ChatProgress2["Complete"] = "done";
|
|
244
|
+
return ChatProgress2;
|
|
245
|
+
})(ChatProgress || {});
|
|
233
246
|
var Subject = /* @__PURE__ */ ((Subject2) => {
|
|
234
247
|
Subject2["KnowledgeProcessing"] = "knowledge/processing";
|
|
235
248
|
Subject2["KnowledgeIndexing"] = "knowledge/indexing";
|
|
@@ -297,6 +310,12 @@ function initializeStreamAndChat(agent, options, agentsApi, chat) {
|
|
|
297
310
|
reject(new Error("Cannot create connection"));
|
|
298
311
|
}
|
|
299
312
|
(_b = (_a = options.callbacks).onConnectionStateChange) == null ? void 0 : _b.call(_a, state);
|
|
313
|
+
},
|
|
314
|
+
onMessage: (event, data) => {
|
|
315
|
+
var _a, _b;
|
|
316
|
+
if (event === StreamEvents.ChatPartial) {
|
|
317
|
+
(_b = (_a = options.callbacks).onChatEvents) == null ? void 0 : _b.call(_a, ChatProgress.Partial, data);
|
|
318
|
+
}
|
|
300
319
|
}
|
|
301
320
|
}
|
|
302
321
|
});
|
|
@@ -307,6 +326,7 @@ async function createAgentManager(agentId, options) {
|
|
|
307
326
|
const abortController = new AbortController();
|
|
308
327
|
const agentsApi = createAgentsApi(options.auth, baseURL);
|
|
309
328
|
const ratingsAPI = createRatingsApi(options.auth, baseURL);
|
|
329
|
+
const knowledgeApi = createKnowledgeApi(options.auth, baseURL);
|
|
310
330
|
const agent = await agentsApi.getById(agentId);
|
|
311
331
|
const socketManager = await SocketManager(options.auth);
|
|
312
332
|
let {
|
|
@@ -327,16 +347,14 @@ async function createAgentManager(agentId, options) {
|
|
|
327
347
|
return streamingManager.terminate();
|
|
328
348
|
},
|
|
329
349
|
chatId: chat.id,
|
|
330
|
-
|
|
331
|
-
|
|
350
|
+
chat(messages) {
|
|
351
|
+
return agentsApi.chat(agentId, chat.id, {
|
|
332
352
|
sessionId: streamingManager.sessionId,
|
|
333
353
|
streamId: streamingManager.streamId,
|
|
334
354
|
messages
|
|
335
355
|
}, {
|
|
336
356
|
signal: abortController.signal
|
|
337
357
|
});
|
|
338
|
-
console.log(result);
|
|
339
|
-
return result;
|
|
340
358
|
},
|
|
341
359
|
rate(payload, id) {
|
|
342
360
|
if (id) {
|
|
@@ -376,6 +394,12 @@ async function createAgentManager(agentId, options) {
|
|
|
376
394
|
},
|
|
377
395
|
onVideoEvents(callback) {
|
|
378
396
|
streamingManager.onCallback("onVideoStateChange", callback);
|
|
397
|
+
},
|
|
398
|
+
getStarterMessages() {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
if (!((_a = agent.knowledge) == null ? void 0 : _a.id))
|
|
401
|
+
return Promise.resolve([]);
|
|
402
|
+
return knowledgeApi.getKnowledge((_b = agent.knowledge) == null ? void 0 : _b.id).then((knowledge) => (knowledge == null ? void 0 : knowledge.starter_message) || []);
|
|
379
403
|
}
|
|
380
404
|
};
|
|
381
405
|
}
|
|
@@ -450,6 +474,44 @@ function createApi(auth, host) {
|
|
|
450
474
|
}
|
|
451
475
|
};
|
|
452
476
|
}
|
|
477
|
+
function createVideoStatsReport(stats, previousStats) {
|
|
478
|
+
return stats.map((report, index) => {
|
|
479
|
+
if (index === 0) {
|
|
480
|
+
return !previousStats ? {
|
|
481
|
+
index,
|
|
482
|
+
timestamp: report.timestamp,
|
|
483
|
+
bytesReceived: report.bytesReceived,
|
|
484
|
+
packetsReceived: report.packetsReceived,
|
|
485
|
+
packetsLost: report.packetsLost,
|
|
486
|
+
jitter: report.jitter,
|
|
487
|
+
frameWidth: report.frameWidth,
|
|
488
|
+
frameHeight: report.frameHeight,
|
|
489
|
+
frameRate: report.frameRate
|
|
490
|
+
} : {
|
|
491
|
+
index,
|
|
492
|
+
timestamp: report.timestamp,
|
|
493
|
+
bytesReceived: report.bytesReceived - previousStats.bytesReceived,
|
|
494
|
+
packetsReceived: report.packetsReceived - previousStats.packetsReceived,
|
|
495
|
+
packetsLost: report.packetsLost - previousStats.packetsLost,
|
|
496
|
+
jitter: report.jitter,
|
|
497
|
+
frameWidth: report.frameWidth,
|
|
498
|
+
frameHeight: report.frameHeight,
|
|
499
|
+
frameRate: report.frameRate
|
|
500
|
+
};
|
|
501
|
+
} else
|
|
502
|
+
return {
|
|
503
|
+
index,
|
|
504
|
+
timestamp: report.timestamp,
|
|
505
|
+
bytesReceived: report.bytesReceived - stats[index - 1].bytesReceived,
|
|
506
|
+
packetsReceived: report.packetsReceived - stats[index - 1].packetsReceived,
|
|
507
|
+
packetsLost: report.packetsLost - stats[index - 1].packetsLost,
|
|
508
|
+
jitter: report.jitter,
|
|
509
|
+
frameWidth: report.frameWidth,
|
|
510
|
+
frameHeight: report.frameHeight,
|
|
511
|
+
frameRate: report.frameRate
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
}
|
|
453
515
|
let _debug = false;
|
|
454
516
|
const log = (message, extra) => _debug && console.log(message, extra);
|
|
455
517
|
const actualRTCPC = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
@@ -480,6 +542,9 @@ async function createStreamingManager(agent, {
|
|
|
480
542
|
iceServers: ice_servers
|
|
481
543
|
});
|
|
482
544
|
const pcDataChannel = peerConnection.createDataChannel("JanusDataChannel");
|
|
545
|
+
const videoStats = [];
|
|
546
|
+
let videoStatsStartIndex = 0;
|
|
547
|
+
let videoStatsInterval;
|
|
483
548
|
if (!session_id) {
|
|
484
549
|
throw new Error("Could not create session_id");
|
|
485
550
|
}
|
|
@@ -507,10 +572,28 @@ async function createStreamingManager(agent, {
|
|
|
507
572
|
var _a, _b, _c;
|
|
508
573
|
if (pcDataChannel.readyState === "open") {
|
|
509
574
|
const [event, data] = message.data.split(":");
|
|
510
|
-
if (event === StreamEvents.
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
575
|
+
if (event === StreamEvents.StreamStarted) {
|
|
576
|
+
videoStatsStartIndex = videoStats.length;
|
|
577
|
+
videoStatsInterval = setInterval(() => {
|
|
578
|
+
const stats = peerConnection.getStats();
|
|
579
|
+
stats.then((result) => {
|
|
580
|
+
result.forEach((report) => {
|
|
581
|
+
if (report.type === "inbound-rtp" && report.kind === "video") {
|
|
582
|
+
videoStats.push(report);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
}, 1e3);
|
|
587
|
+
(_a = callbacksObj.onVideoStateChange) == null ? void 0 : _a.call(callbacksObj, StreamingState.Start);
|
|
588
|
+
} else if (event === StreamEvents.StreamDone) {
|
|
589
|
+
clearInterval(videoStatsInterval);
|
|
590
|
+
const stats = videoStats.slice(videoStatsStartIndex);
|
|
591
|
+
if (stats) {
|
|
592
|
+
const previousStats = videoStatsStartIndex === 0 ? void 0 : videoStats[videoStatsStartIndex - 1];
|
|
593
|
+
const videoStatsReport = createVideoStatsReport(stats, previousStats);
|
|
594
|
+
videoStatsStartIndex = videoStats.length;
|
|
595
|
+
(_b = callbacksObj.onVideoStateChange) == null ? void 0 : _b.call(callbacksObj, StreamingState.Stop, videoStatsReport.sort((a, b) => b.packetsLost - a.packetsLost).slice(0, 5));
|
|
596
|
+
}
|
|
514
597
|
} else {
|
|
515
598
|
(_c = callbacksObj.onMessage) == null ? void 0 : _c.call(callbacksObj, event, decodeURIComponent(data));
|
|
516
599
|
}
|
|
@@ -570,11 +653,13 @@ async function createStreamingManager(agent, {
|
|
|
570
653
|
};
|
|
571
654
|
}
|
|
572
655
|
export {
|
|
656
|
+
ChatProgress,
|
|
573
657
|
DocumentType,
|
|
574
658
|
KnowledgeType,
|
|
575
659
|
Providers,
|
|
576
660
|
RateState,
|
|
577
661
|
SocketManager,
|
|
662
|
+
StreamEvents,
|
|
578
663
|
Subject,
|
|
579
664
|
VoiceAccess,
|
|
580
665
|
createAgentManager,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -193,7 +193,12 @@
|
|
|
193
193
|
host,
|
|
194
194
|
callbacks: {
|
|
195
195
|
onMessage: (event) => {
|
|
196
|
-
|
|
196
|
+
const data = JSON.parse(event.data);
|
|
197
|
+
let payload;
|
|
198
|
+
if (data.event === "answer") {
|
|
199
|
+
payload = data.content;
|
|
200
|
+
}
|
|
201
|
+
messageCallbacks.forEach((callback) => callback(data.event, payload));
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
});
|
|
@@ -234,6 +239,14 @@
|
|
|
234
239
|
RateState2["Negative"] = "Negative";
|
|
235
240
|
return RateState2;
|
|
236
241
|
})(RateState || {});
|
|
242
|
+
var ChatProgress = /* @__PURE__ */ ((ChatProgress2) => {
|
|
243
|
+
ChatProgress2["Embed"] = "embed";
|
|
244
|
+
ChatProgress2["Query"] = "query";
|
|
245
|
+
ChatProgress2["Partial"] = "chat/partial";
|
|
246
|
+
ChatProgress2["Answer"] = "answer";
|
|
247
|
+
ChatProgress2["Complete"] = "done";
|
|
248
|
+
return ChatProgress2;
|
|
249
|
+
})(ChatProgress || {});
|
|
237
250
|
var Subject = /* @__PURE__ */ ((Subject2) => {
|
|
238
251
|
Subject2["KnowledgeProcessing"] = "knowledge/processing";
|
|
239
252
|
Subject2["KnowledgeIndexing"] = "knowledge/indexing";
|
|
@@ -301,6 +314,12 @@
|
|
|
301
314
|
reject(new Error("Cannot create connection"));
|
|
302
315
|
}
|
|
303
316
|
(_b = (_a = options.callbacks).onConnectionStateChange) == null ? void 0 : _b.call(_a, state);
|
|
317
|
+
},
|
|
318
|
+
onMessage: (event, data) => {
|
|
319
|
+
var _a, _b;
|
|
320
|
+
if (event === StreamEvents.ChatPartial) {
|
|
321
|
+
(_b = (_a = options.callbacks).onChatEvents) == null ? void 0 : _b.call(_a, ChatProgress.Partial, data);
|
|
322
|
+
}
|
|
304
323
|
}
|
|
305
324
|
}
|
|
306
325
|
});
|
|
@@ -311,6 +330,7 @@
|
|
|
311
330
|
const abortController = new AbortController();
|
|
312
331
|
const agentsApi = createAgentsApi(options.auth, baseURL);
|
|
313
332
|
const ratingsAPI = createRatingsApi(options.auth, baseURL);
|
|
333
|
+
const knowledgeApi = createKnowledgeApi(options.auth, baseURL);
|
|
314
334
|
const agent = await agentsApi.getById(agentId);
|
|
315
335
|
const socketManager = await SocketManager(options.auth);
|
|
316
336
|
let {
|
|
@@ -331,16 +351,14 @@
|
|
|
331
351
|
return streamingManager.terminate();
|
|
332
352
|
},
|
|
333
353
|
chatId: chat.id,
|
|
334
|
-
|
|
335
|
-
|
|
354
|
+
chat(messages) {
|
|
355
|
+
return agentsApi.chat(agentId, chat.id, {
|
|
336
356
|
sessionId: streamingManager.sessionId,
|
|
337
357
|
streamId: streamingManager.streamId,
|
|
338
358
|
messages
|
|
339
359
|
}, {
|
|
340
360
|
signal: abortController.signal
|
|
341
361
|
});
|
|
342
|
-
console.log(result);
|
|
343
|
-
return result;
|
|
344
362
|
},
|
|
345
363
|
rate(payload, id) {
|
|
346
364
|
if (id) {
|
|
@@ -380,6 +398,12 @@
|
|
|
380
398
|
},
|
|
381
399
|
onVideoEvents(callback) {
|
|
382
400
|
streamingManager.onCallback("onVideoStateChange", callback);
|
|
401
|
+
},
|
|
402
|
+
getStarterMessages() {
|
|
403
|
+
var _a, _b;
|
|
404
|
+
if (!((_a = agent.knowledge) == null ? void 0 : _a.id))
|
|
405
|
+
return Promise.resolve([]);
|
|
406
|
+
return knowledgeApi.getKnowledge((_b = agent.knowledge) == null ? void 0 : _b.id).then((knowledge) => (knowledge == null ? void 0 : knowledge.starter_message) || []);
|
|
383
407
|
}
|
|
384
408
|
};
|
|
385
409
|
}
|
|
@@ -454,6 +478,44 @@
|
|
|
454
478
|
}
|
|
455
479
|
};
|
|
456
480
|
}
|
|
481
|
+
function createVideoStatsReport(stats, previousStats) {
|
|
482
|
+
return stats.map((report, index) => {
|
|
483
|
+
if (index === 0) {
|
|
484
|
+
return !previousStats ? {
|
|
485
|
+
index,
|
|
486
|
+
timestamp: report.timestamp,
|
|
487
|
+
bytesReceived: report.bytesReceived,
|
|
488
|
+
packetsReceived: report.packetsReceived,
|
|
489
|
+
packetsLost: report.packetsLost,
|
|
490
|
+
jitter: report.jitter,
|
|
491
|
+
frameWidth: report.frameWidth,
|
|
492
|
+
frameHeight: report.frameHeight,
|
|
493
|
+
frameRate: report.frameRate
|
|
494
|
+
} : {
|
|
495
|
+
index,
|
|
496
|
+
timestamp: report.timestamp,
|
|
497
|
+
bytesReceived: report.bytesReceived - previousStats.bytesReceived,
|
|
498
|
+
packetsReceived: report.packetsReceived - previousStats.packetsReceived,
|
|
499
|
+
packetsLost: report.packetsLost - previousStats.packetsLost,
|
|
500
|
+
jitter: report.jitter,
|
|
501
|
+
frameWidth: report.frameWidth,
|
|
502
|
+
frameHeight: report.frameHeight,
|
|
503
|
+
frameRate: report.frameRate
|
|
504
|
+
};
|
|
505
|
+
} else
|
|
506
|
+
return {
|
|
507
|
+
index,
|
|
508
|
+
timestamp: report.timestamp,
|
|
509
|
+
bytesReceived: report.bytesReceived - stats[index - 1].bytesReceived,
|
|
510
|
+
packetsReceived: report.packetsReceived - stats[index - 1].packetsReceived,
|
|
511
|
+
packetsLost: report.packetsLost - stats[index - 1].packetsLost,
|
|
512
|
+
jitter: report.jitter,
|
|
513
|
+
frameWidth: report.frameWidth,
|
|
514
|
+
frameHeight: report.frameHeight,
|
|
515
|
+
frameRate: report.frameRate
|
|
516
|
+
};
|
|
517
|
+
});
|
|
518
|
+
}
|
|
457
519
|
let _debug = false;
|
|
458
520
|
const log = (message, extra) => _debug && console.log(message, extra);
|
|
459
521
|
const actualRTCPC = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
@@ -484,6 +546,9 @@
|
|
|
484
546
|
iceServers: ice_servers
|
|
485
547
|
});
|
|
486
548
|
const pcDataChannel = peerConnection.createDataChannel("JanusDataChannel");
|
|
549
|
+
const videoStats = [];
|
|
550
|
+
let videoStatsStartIndex = 0;
|
|
551
|
+
let videoStatsInterval;
|
|
487
552
|
if (!session_id) {
|
|
488
553
|
throw new Error("Could not create session_id");
|
|
489
554
|
}
|
|
@@ -511,10 +576,28 @@
|
|
|
511
576
|
var _a, _b, _c;
|
|
512
577
|
if (pcDataChannel.readyState === "open") {
|
|
513
578
|
const [event, data] = message.data.split(":");
|
|
514
|
-
if (event === StreamEvents.
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
579
|
+
if (event === StreamEvents.StreamStarted) {
|
|
580
|
+
videoStatsStartIndex = videoStats.length;
|
|
581
|
+
videoStatsInterval = setInterval(() => {
|
|
582
|
+
const stats = peerConnection.getStats();
|
|
583
|
+
stats.then((result) => {
|
|
584
|
+
result.forEach((report) => {
|
|
585
|
+
if (report.type === "inbound-rtp" && report.kind === "video") {
|
|
586
|
+
videoStats.push(report);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
}, 1e3);
|
|
591
|
+
(_a = callbacksObj.onVideoStateChange) == null ? void 0 : _a.call(callbacksObj, StreamingState.Start);
|
|
592
|
+
} else if (event === StreamEvents.StreamDone) {
|
|
593
|
+
clearInterval(videoStatsInterval);
|
|
594
|
+
const stats = videoStats.slice(videoStatsStartIndex);
|
|
595
|
+
if (stats) {
|
|
596
|
+
const previousStats = videoStatsStartIndex === 0 ? void 0 : videoStats[videoStatsStartIndex - 1];
|
|
597
|
+
const videoStatsReport = createVideoStatsReport(stats, previousStats);
|
|
598
|
+
videoStatsStartIndex = videoStats.length;
|
|
599
|
+
(_b = callbacksObj.onVideoStateChange) == null ? void 0 : _b.call(callbacksObj, StreamingState.Stop, videoStatsReport.sort((a, b) => b.packetsLost - a.packetsLost).slice(0, 5));
|
|
600
|
+
}
|
|
518
601
|
} else {
|
|
519
602
|
(_c = callbacksObj.onMessage) == null ? void 0 : _c.call(callbacksObj, event, decodeURIComponent(data));
|
|
520
603
|
}
|
|
@@ -573,11 +656,13 @@
|
|
|
573
656
|
}
|
|
574
657
|
};
|
|
575
658
|
}
|
|
659
|
+
exports2.ChatProgress = ChatProgress;
|
|
576
660
|
exports2.DocumentType = DocumentType;
|
|
577
661
|
exports2.KnowledgeType = KnowledgeType;
|
|
578
662
|
exports2.Providers = Providers;
|
|
579
663
|
exports2.RateState = RateState;
|
|
580
664
|
exports2.SocketManager = SocketManager;
|
|
665
|
+
exports2.StreamEvents = StreamEvents;
|
|
581
666
|
exports2.Subject = Subject;
|
|
582
667
|
exports2.VoiceAccess = VoiceAccess;
|
|
583
668
|
exports2.createAgentManager = createAgentManager;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Agent,
|
|
1
|
+
import { Agent, AgentManager, AgentManagerOptions, CreateStreamOptions } from '../types/index';
|
|
2
2
|
export declare function getAgentStreamArgs(agent: Agent): CreateStreamOptions;
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
|
|
5
5
|
*
|
|
6
6
|
* @param {string} agentId - The ID of the agent to chat with.
|
|
7
7
|
* @param {AgentManagerOptions} options - Configurations for the Agent Manager API.
|
|
8
|
-
* * @returns {Promise<
|
|
8
|
+
* * @returns {Promise<AgentManager>} - A promise that resolves to an instance of the AgentsAPI interface.
|
|
9
9
|
*
|
|
10
10
|
* @throws {Error} Throws an error if the agent is not initialized.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const agentManager = await createAgentManager('id-agent123', { auth: { type: 'key', clientKey: '123', externalId: '123' } });
|
|
14
14
|
*/
|
|
15
|
-
export declare function createAgentManager(agentId: string, options: AgentManagerOptions): Promise<
|
|
15
|
+
export declare function createAgentManager(agentId: string, options: AgentManagerOptions): Promise<AgentManager>;
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import { SupportedStreamScipt } from '../../../types/StreamScript';
|
|
2
2
|
import { Auth } from '../../auth';
|
|
3
|
-
import { SendStreamPayloadResponse, StreamingState } from '../../stream';
|
|
3
|
+
import { SendStreamPayloadResponse, SlimRTCStatsReport, StreamingState } from '../../stream';
|
|
4
4
|
import { Agent } from './agent';
|
|
5
5
|
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 = "chat/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
|
-
export type VideoStateChangeCallback = (state: StreamingState) => void;
|
|
33
|
+
export type VideoStateChangeCallback = (state: StreamingState, stats?: SlimRTCStatsReport[]) => void;
|
|
30
34
|
interface ManagerCallbacks {
|
|
31
35
|
/**
|
|
32
36
|
* This callback will be triggered each time the RTC connection changes state
|
|
@@ -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;
|
|
@@ -59,7 +63,7 @@ export interface AgentManagerOptions {
|
|
|
59
63
|
debug?: boolean;
|
|
60
64
|
auth: Auth;
|
|
61
65
|
}
|
|
62
|
-
export interface
|
|
66
|
+
export interface AgentManager {
|
|
63
67
|
/**
|
|
64
68
|
* Agent instance you are working with.
|
|
65
69
|
* To know more about agents go to https://docs.d-id.com/reference/agents
|
|
@@ -99,7 +103,7 @@ export interface AgentsManager {
|
|
|
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;
|
|
106
|
+
onChatEvents: (callback: (ChatProgressCallback)) => void;
|
|
103
107
|
/**
|
|
104
108
|
* Optional callback function that will be triggered each time the RTC connection gets new status
|
|
105
109
|
* @param callback
|
|
@@ -110,5 +114,11 @@ export interface AgentsManager {
|
|
|
110
114
|
* @param callback
|
|
111
115
|
*/
|
|
112
116
|
onVideoEvents: (callback: VideoStateChangeCallback) => void;
|
|
117
|
+
/**
|
|
118
|
+
* Get Starter messages from agent knowledge
|
|
119
|
+
* Used as a proposal for a user to ask Agent these questions
|
|
120
|
+
* @param agent
|
|
121
|
+
*/
|
|
122
|
+
getStarterMessages: () => Promise<string[]>;
|
|
113
123
|
}
|
|
114
124
|
export {};
|
|
@@ -16,7 +16,7 @@ export declare enum StreamEvents {
|
|
|
16
16
|
export interface ManagerCallbacks {
|
|
17
17
|
onMessage?: (event: string, data: string) => void;
|
|
18
18
|
onConnectionStateChange?: (state: RTCIceConnectionState) => void;
|
|
19
|
-
onVideoStateChange?: (state: StreamingState) => void;
|
|
19
|
+
onVideoStateChange?: (state: StreamingState, stats?: SlimRTCStatsReport[]) => void;
|
|
20
20
|
onSrcObjectReady?: (value: MediaStream) => void;
|
|
21
21
|
}
|
|
22
22
|
export type ManagerCallbackKeys = keyof ManagerCallbacks;
|
|
@@ -41,3 +41,14 @@ export interface StreamingManagerOptions {
|
|
|
41
41
|
debug?: boolean;
|
|
42
42
|
auth: Auth;
|
|
43
43
|
}
|
|
44
|
+
export interface SlimRTCStatsReport {
|
|
45
|
+
index: number;
|
|
46
|
+
timestamp: any;
|
|
47
|
+
bytesReceived: any;
|
|
48
|
+
packetsReceived: any;
|
|
49
|
+
packetsLost: any;
|
|
50
|
+
jitter: any;
|
|
51
|
+
frameWidth: any;
|
|
52
|
+
frameHeight: any;
|
|
53
|
+
frameRate: any;
|
|
54
|
+
}
|