@d-id/client-sdk 1.1.11-staging.39 → 1.1.11
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 +377 -234
- package/dist/index.umd.cjs +1 -1
- package/dist/src/api/agents.d.ts +0 -1
- package/dist/src/api/apiClient.d.ts +3 -4
- package/dist/src/api/knowledge.d.ts +0 -1
- package/dist/src/api/streams/streamApi.d.ts +0 -1
- package/dist/src/auth/get-auth-header.d.ts +0 -1
- package/dist/src/errors/chat/chat-creation-failed.d.ts +0 -1
- package/dist/src/errors/chat/chat-mode-downgraded.d.ts +0 -1
- package/dist/src/errors/validation-error.d.ts +0 -1
- package/dist/src/errors/ws-error.d.ts +0 -1
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +0 -1
- package/dist/src/services/agent-manager/index.d.ts +0 -1
- package/dist/src/services/chat/index.d.ts +2 -2
- package/dist/src/services/chat/intial-messages.d.ts +0 -1
- package/dist/src/services/interrupt/index.d.ts +0 -1
- package/dist/src/services/socket-manager/index.d.ts +0 -1
- package/dist/src/services/socket-manager/message-queue.d.ts +0 -1
- package/dist/src/services/streaming-manager/index.d.ts +1 -9
- package/dist/src/services/streaming-manager/stats/poll.d.ts +1 -1
- package/dist/src/services/streaming-manager/stats/report.d.ts +0 -1
- package/dist/src/types/entities/agents/agent.d.ts +0 -1
- package/dist/src/types/entities/agents/manager.d.ts +1 -2
- package/dist/src/types/entities/agents/presenter.d.ts +0 -1
- package/dist/src/types/entities/knowledge/document.d.ts +0 -1
- package/dist/src/types/entities/knowledge/record.d.ts +0 -1
- package/dist/src/types/stream/api/clip.d.ts +0 -1
- package/dist/src/types/stream/api/talk.d.ts +0 -1
- package/dist/src/types/stream/stream.d.ts +0 -1
- package/dist/src/types/stream-script.d.ts +0 -1
- package/dist/src/utils/agent.d.ts +1 -2
- package/dist/src/utils/analytics.d.ts +0 -1
- package/dist/src/utils/chat.d.ts +0 -1
- package/package.json +2 -18
- package/dist/src/services/agent-manager/connect-to-manager.test.d.ts +0 -1
- package/dist/src/services/agent-manager/index.test.d.ts +0 -1
- package/dist/src/services/streaming-manager/advanced.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/business-flows.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/core.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/disconnect.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/edge-cases.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/utils.test.d.ts +0 -5
- package/dist/src/test-utils/factories/agent-manager.factory.d.ts +0 -3
- package/dist/src/test-utils/factories/agent.factory.d.ts +0 -4
- package/dist/src/test-utils/factories/agents-api.factory.d.ts +0 -1
- package/dist/src/test-utils/factories/analytics.factory.d.ts +0 -1
- package/dist/src/test-utils/factories/chat.factory.d.ts +0 -1
- package/dist/src/test-utils/factories/index.d.ts +0 -8
- package/dist/src/test-utils/factories/socket-manager.factory.d.ts +0 -1
- package/dist/src/test-utils/factories/stream-api.factory.d.ts +0 -1
- package/dist/src/test-utils/factories/streaming-manager.factory.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
var ye = Object.defineProperty;
|
|
2
2
|
var ve = (e, t, n) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
-
var Y = (e, t, n) => ve(e, typeof t != "symbol" ? t + "" : t, n);
|
|
3
|
+
var Y = (e, t, n) => (ve(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
4
|
class G extends Error {
|
|
5
|
-
constructor({
|
|
6
|
-
|
|
5
|
+
constructor({
|
|
6
|
+
kind: n,
|
|
7
|
+
description: r,
|
|
8
|
+
error: s
|
|
9
|
+
}) {
|
|
10
|
+
super(JSON.stringify({
|
|
11
|
+
kind: n,
|
|
12
|
+
description: r
|
|
13
|
+
}));
|
|
7
14
|
Y(this, "kind");
|
|
8
15
|
Y(this, "description");
|
|
9
16
|
Y(this, "error");
|
|
@@ -20,19 +27,28 @@ class ke extends G {
|
|
|
20
27
|
}
|
|
21
28
|
class De extends G {
|
|
22
29
|
constructor(t) {
|
|
23
|
-
super({
|
|
30
|
+
super({
|
|
31
|
+
kind: "ChatModeDowngraded",
|
|
32
|
+
description: `Chat mode downgraded to ${t}`
|
|
33
|
+
});
|
|
24
34
|
}
|
|
25
35
|
}
|
|
26
36
|
class H extends G {
|
|
27
37
|
constructor(n, r) {
|
|
28
|
-
super({
|
|
38
|
+
super({
|
|
39
|
+
kind: "ValidationError",
|
|
40
|
+
description: n
|
|
41
|
+
});
|
|
29
42
|
Y(this, "key");
|
|
30
43
|
this.key = r;
|
|
31
44
|
}
|
|
32
45
|
}
|
|
33
46
|
class Ce extends G {
|
|
34
47
|
constructor(t) {
|
|
35
|
-
super({
|
|
48
|
+
super({
|
|
49
|
+
kind: "WSError",
|
|
50
|
+
description: t
|
|
51
|
+
});
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
54
|
var Re = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Re || {}), Se = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Se || {}), Ie = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ie || {}), Ee = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ee || {}), M = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(M || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Me = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Me || {}), _e = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(_e || {}), Te = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(Te || {}), je = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(je || {});
|
|
@@ -75,7 +91,10 @@ async function te(e, t) {
|
|
|
75
91
|
try {
|
|
76
92
|
if (!n.timeout)
|
|
77
93
|
return await e();
|
|
78
|
-
const {
|
|
94
|
+
const {
|
|
95
|
+
promise: o,
|
|
96
|
+
clear: c
|
|
97
|
+
} = Fe(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
|
|
79
98
|
return await Promise.race([a, o]);
|
|
80
99
|
} catch (o) {
|
|
81
100
|
if (r = o, !n.shouldRetryFn(o) || s >= n.limit)
|
|
@@ -110,35 +129,55 @@ const xe = (e) => te(e, {
|
|
|
110
129
|
});
|
|
111
130
|
function ue(e, t = Z, n) {
|
|
112
131
|
const r = async (s, o) => {
|
|
113
|
-
const {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
const {
|
|
133
|
+
skipErrorHandler: c,
|
|
134
|
+
...a
|
|
135
|
+
} = o || {}, i = await xe(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
136
|
+
...a,
|
|
137
|
+
headers: {
|
|
138
|
+
...a.headers,
|
|
139
|
+
Authorization: le(e),
|
|
140
|
+
"Content-Type": "application/json"
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
123
143
|
if (!i.ok) {
|
|
124
144
|
let d = await i.text().catch(() => `Failed to fetch with status ${i.status}`);
|
|
125
145
|
const l = new Error(d);
|
|
126
|
-
throw n && !c && n(l, {
|
|
146
|
+
throw n && !c && n(l, {
|
|
147
|
+
url: s,
|
|
148
|
+
options: a,
|
|
149
|
+
headers: i.headers
|
|
150
|
+
}), l;
|
|
127
151
|
}
|
|
128
152
|
return i.json();
|
|
129
153
|
};
|
|
130
154
|
return {
|
|
131
155
|
get(s, o) {
|
|
132
|
-
return r(s, {
|
|
156
|
+
return r(s, {
|
|
157
|
+
...o,
|
|
158
|
+
method: "GET"
|
|
159
|
+
});
|
|
133
160
|
},
|
|
134
161
|
post(s, o, c) {
|
|
135
|
-
return r(s, {
|
|
162
|
+
return r(s, {
|
|
163
|
+
...c,
|
|
164
|
+
body: JSON.stringify(o),
|
|
165
|
+
method: "POST"
|
|
166
|
+
});
|
|
136
167
|
},
|
|
137
168
|
delete(s, o, c) {
|
|
138
|
-
return r(s, {
|
|
169
|
+
return r(s, {
|
|
170
|
+
...c,
|
|
171
|
+
body: JSON.stringify(o),
|
|
172
|
+
method: "DELETE"
|
|
173
|
+
});
|
|
139
174
|
},
|
|
140
175
|
patch(s, o, c) {
|
|
141
|
-
return r(s, {
|
|
176
|
+
return r(s, {
|
|
177
|
+
...c,
|
|
178
|
+
body: JSON.stringify(o),
|
|
179
|
+
method: "PATCH"
|
|
180
|
+
});
|
|
142
181
|
}
|
|
143
182
|
};
|
|
144
183
|
}
|
|
@@ -219,17 +258,35 @@ function We(e) {
|
|
|
219
258
|
agentId: e.id,
|
|
220
259
|
access: e.access,
|
|
221
260
|
name: e.preview_name,
|
|
222
|
-
...e.access === "public" ? {
|
|
261
|
+
...e.access === "public" ? {
|
|
262
|
+
from: "agent-template"
|
|
263
|
+
} : {}
|
|
223
264
|
};
|
|
224
265
|
}
|
|
225
266
|
const Ue = (e) => e.reduce((t, n) => t + n, 0), ae = (e) => Ue(e) / e.length;
|
|
226
267
|
function Ke(e, t, n) {
|
|
227
268
|
var i, d, l;
|
|
228
|
-
const {
|
|
269
|
+
const {
|
|
270
|
+
event: r,
|
|
271
|
+
...s
|
|
272
|
+
} = e, {
|
|
273
|
+
template: o
|
|
274
|
+
} = (t == null ? void 0 : t.llm) || {}, {
|
|
275
|
+
language: c
|
|
276
|
+
} = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
|
|
229
277
|
return {
|
|
230
278
|
...s,
|
|
231
|
-
llm: {
|
|
232
|
-
|
|
279
|
+
llm: {
|
|
280
|
+
...s.llm,
|
|
281
|
+
template: o
|
|
282
|
+
},
|
|
283
|
+
script: {
|
|
284
|
+
...s.script,
|
|
285
|
+
provider: {
|
|
286
|
+
...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider,
|
|
287
|
+
language: c
|
|
288
|
+
}
|
|
289
|
+
},
|
|
233
290
|
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (l = t == null ? void 0 : t.presenter) == null ? void 0 : l.stitch : void 0,
|
|
234
291
|
...n
|
|
235
292
|
};
|
|
@@ -246,35 +303,39 @@ function qe(e) {
|
|
|
246
303
|
isEnabled: e.isEnabled ?? !0,
|
|
247
304
|
getRandom: V,
|
|
248
305
|
enrich(n) {
|
|
249
|
-
this.additionalProperties = {
|
|
306
|
+
this.additionalProperties = {
|
|
307
|
+
...this.additionalProperties,
|
|
308
|
+
...n
|
|
309
|
+
};
|
|
250
310
|
},
|
|
251
311
|
async track(n, r) {
|
|
252
312
|
if (!this.isEnabled)
|
|
253
313
|
return Promise.resolve();
|
|
254
|
-
const {
|
|
314
|
+
const {
|
|
315
|
+
audioPath: s,
|
|
316
|
+
...o
|
|
317
|
+
} = r || {}, c = {
|
|
255
318
|
method: "POST",
|
|
256
319
|
headers: {
|
|
257
320
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
258
321
|
},
|
|
259
322
|
body: new URLSearchParams({
|
|
260
|
-
data: JSON.stringify([
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
"User Agent": navigator.userAgent
|
|
275
|
-
}
|
|
323
|
+
data: JSON.stringify([{
|
|
324
|
+
event: n,
|
|
325
|
+
properties: {
|
|
326
|
+
...this.additionalProperties,
|
|
327
|
+
...o,
|
|
328
|
+
agentId: this.agentId,
|
|
329
|
+
source: t,
|
|
330
|
+
token: this.token,
|
|
331
|
+
time: Date.now(),
|
|
332
|
+
$insert_id: this.getRandom(),
|
|
333
|
+
origin: window.location.href,
|
|
334
|
+
"Screen Height": window.screen.height || window.innerWidth,
|
|
335
|
+
"Screen Width": window.screen.width || window.innerHeight,
|
|
336
|
+
"User Agent": navigator.userAgent
|
|
276
337
|
}
|
|
277
|
-
])
|
|
338
|
+
}])
|
|
278
339
|
})
|
|
279
340
|
};
|
|
280
341
|
try {
|
|
@@ -284,15 +345,19 @@ function qe(e) {
|
|
|
284
345
|
}
|
|
285
346
|
},
|
|
286
347
|
linkTrack(n, r, s, o) {
|
|
287
|
-
ee[n] || (ee[n] = {
|
|
348
|
+
ee[n] || (ee[n] = {
|
|
349
|
+
events: {},
|
|
350
|
+
resolvedDependencies: []
|
|
351
|
+
}), o.includes(s) || o.push(s);
|
|
288
352
|
const c = ee[n];
|
|
289
|
-
if (c.events[s] = {
|
|
290
|
-
|
|
291
|
-
)) {
|
|
292
|
-
const i = o.reduce((d, l) => c.events[l] ? {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
353
|
+
if (c.events[s] = {
|
|
354
|
+
props: r
|
|
355
|
+
}, c.resolvedDependencies.push(s), o.every((i) => c.resolvedDependencies.includes(i))) {
|
|
356
|
+
const i = o.reduce((d, l) => c.events[l] ? {
|
|
357
|
+
...d,
|
|
358
|
+
...c.events[l].props
|
|
359
|
+
} : d, {});
|
|
360
|
+
this.track(n, i), c.resolvedDependencies = c.resolvedDependencies.filter((d) => !o.includes(d)), o.forEach((d) => {
|
|
296
361
|
delete c.events[d];
|
|
297
362
|
});
|
|
298
363
|
}
|
|
@@ -309,15 +374,24 @@ function ge() {
|
|
|
309
374
|
}
|
|
310
375
|
const N = ge(), re = ge();
|
|
311
376
|
function he(e) {
|
|
312
|
-
return e === M.Playground ? {
|
|
377
|
+
return e === M.Playground ? {
|
|
378
|
+
headers: {
|
|
379
|
+
[Be]: "true"
|
|
380
|
+
}
|
|
381
|
+
} : {};
|
|
313
382
|
}
|
|
314
383
|
async function we(e, t, n, r, s = !1, o) {
|
|
315
384
|
try {
|
|
316
|
-
return !o && !ce(r) && (o = await t.newChat(e.id, {
|
|
385
|
+
return !o && !ce(r) && (o = await t.newChat(e.id, {
|
|
386
|
+
persist: s
|
|
387
|
+
}, he(r)), n.track("agent-chat", {
|
|
317
388
|
event: "created",
|
|
318
389
|
chatId: o.id,
|
|
319
390
|
mode: r
|
|
320
|
-
})), {
|
|
391
|
+
})), {
|
|
392
|
+
chat: o,
|
|
393
|
+
chatMode: (o == null ? void 0 : o.chat_mode) ?? r
|
|
394
|
+
};
|
|
321
395
|
} catch (c) {
|
|
322
396
|
try {
|
|
323
397
|
const a = JSON.parse(c.message);
|
|
@@ -352,7 +426,16 @@ async function Xe(e, t) {
|
|
|
352
426
|
}
|
|
353
427
|
function Ye(e) {
|
|
354
428
|
return new Promise((t, n) => {
|
|
355
|
-
const {
|
|
429
|
+
const {
|
|
430
|
+
callbacks: r,
|
|
431
|
+
host: s,
|
|
432
|
+
auth: o
|
|
433
|
+
} = e, {
|
|
434
|
+
onMessage: c = null,
|
|
435
|
+
onOpen: a = null,
|
|
436
|
+
onClose: i = null,
|
|
437
|
+
onError: d = null
|
|
438
|
+
} = r || {}, l = new WebSocket(`${s}?authorization=${le(o)}`);
|
|
356
439
|
l.onmessage = c, l.onclose = i, l.onerror = (y) => {
|
|
357
440
|
console.error(y), d == null || d("Websocket failed to connect", y), n(y);
|
|
358
441
|
}, l.onopen = (y) => {
|
|
@@ -361,7 +444,9 @@ function Ye(e) {
|
|
|
361
444
|
});
|
|
362
445
|
}
|
|
363
446
|
async function Qe(e) {
|
|
364
|
-
const {
|
|
447
|
+
const {
|
|
448
|
+
retries: t = 1
|
|
449
|
+
} = e;
|
|
365
450
|
let n = null;
|
|
366
451
|
for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
|
|
367
452
|
try {
|
|
@@ -406,7 +491,10 @@ function et(e, t, n, r, s) {
|
|
|
406
491
|
const o = r.messages[r.messages.length - 1];
|
|
407
492
|
if (!(e === q.Partial || e === q.Answer) || (o == null ? void 0 : o.role) !== "assistant")
|
|
408
493
|
return;
|
|
409
|
-
const {
|
|
494
|
+
const {
|
|
495
|
+
content: c,
|
|
496
|
+
sequence: a
|
|
497
|
+
} = t;
|
|
410
498
|
e === q.Partial ? n[a] = c : n.answer = c;
|
|
411
499
|
const i = Ge(n);
|
|
412
500
|
(o.content !== i || e === q.Answer) && (o.content = i, s == null || s([...r.messages], e));
|
|
@@ -423,14 +511,24 @@ function tt(e, t, n, r, s) {
|
|
|
423
511
|
mode: t.chatMode
|
|
424
512
|
});
|
|
425
513
|
else {
|
|
426
|
-
const l = A, y = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], _ = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], T = Ke(a, r, {
|
|
514
|
+
const l = A, y = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], _ = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], T = Ke(a, r, {
|
|
515
|
+
mode: t.chatMode
|
|
516
|
+
});
|
|
427
517
|
if (c = c, c === l.StreamVideoCreated)
|
|
428
518
|
e.linkTrack("agent-video", T, l.StreamVideoCreated, ["start"]);
|
|
429
519
|
else if (y.includes(c)) {
|
|
430
520
|
const j = c.split("/")[1];
|
|
431
|
-
_.includes(c) ? e.track("agent-video", {
|
|
521
|
+
_.includes(c) ? e.track("agent-video", {
|
|
522
|
+
...T,
|
|
523
|
+
event: j
|
|
524
|
+
}) : e.linkTrack("agent-video", {
|
|
525
|
+
...T,
|
|
526
|
+
event: j
|
|
527
|
+
}, c, ["done"]);
|
|
432
528
|
}
|
|
433
|
-
_.includes(c) && ((d = (i = n.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${c}`), {
|
|
529
|
+
_.includes(c) && ((d = (i = n.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${c}`), {
|
|
530
|
+
data: a
|
|
531
|
+
})), a.event === l.StreamDone && s();
|
|
434
532
|
}
|
|
435
533
|
}
|
|
436
534
|
};
|
|
@@ -460,7 +558,9 @@ function rt(e, t, n, r) {
|
|
|
460
558
|
});
|
|
461
559
|
},
|
|
462
560
|
close(o, c) {
|
|
463
|
-
return s.delete(`/streams/${o}`, {
|
|
561
|
+
return s.delete(`/streams/${o}`, {
|
|
562
|
+
session_id: c
|
|
563
|
+
});
|
|
464
564
|
}
|
|
465
565
|
};
|
|
466
566
|
}
|
|
@@ -485,10 +585,11 @@ function nt(e, t, n) {
|
|
|
485
585
|
};
|
|
486
586
|
}
|
|
487
587
|
function at(e) {
|
|
488
|
-
return e.filter(
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
588
|
+
return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
|
|
589
|
+
const {
|
|
590
|
+
timestamp: n,
|
|
591
|
+
...r
|
|
592
|
+
} = t, s = [];
|
|
492
593
|
return t.freezeCount > 0 && s.push("freeze"), t.framesPerSecond < 21 && s.push("low fps"), t.framesDropped > 0 && s.push("frames dropped"), t.packetsLost > 0 && s.push("packet loss"), {
|
|
493
594
|
...r,
|
|
494
595
|
causes: s
|
|
@@ -601,16 +702,27 @@ function lt() {
|
|
|
601
702
|
}
|
|
602
703
|
t = c, n = a;
|
|
603
704
|
const i = o.framesDecoded, d = i - e > 0;
|
|
604
|
-
return e = i, {
|
|
705
|
+
return e = i, {
|
|
706
|
+
isReceiving: d,
|
|
707
|
+
avgJitterDelayInInterval: r,
|
|
708
|
+
freezeCount: o.freezeCount
|
|
709
|
+
};
|
|
605
710
|
}
|
|
606
|
-
return {
|
|
711
|
+
return {
|
|
712
|
+
isReceiving: !1,
|
|
713
|
+
avgJitterDelayInInterval: r
|
|
714
|
+
};
|
|
607
715
|
};
|
|
608
716
|
}
|
|
609
717
|
function ut(e, t, n, r, s, o = !1) {
|
|
610
718
|
let c = [], a, i = 0, d = !1, l = Q.Unknown, y = Q.Unknown, _ = 0, T = 0;
|
|
611
719
|
const j = lt();
|
|
612
720
|
return setInterval(async () => {
|
|
613
|
-
const x = await e.getStats(), {
|
|
721
|
+
const x = await e.getStats(), {
|
|
722
|
+
isReceiving: R,
|
|
723
|
+
avgJitterDelayInInterval: U,
|
|
724
|
+
freezeCount: K
|
|
725
|
+
} = j(x), P = it(x);
|
|
614
726
|
if (R)
|
|
615
727
|
i = 0, _ = K - T, y = U < ct ? Q.Strong : U > dt && _ > 1 ? Q.Weak : l, y !== l && (s == null || s(y), l = y, T += _, _ = 0), d || (r == null || r(h.Start), a = c[c.length - 1], c = [], d = !0), c.push(P);
|
|
616
728
|
else if (d && (i++, i >= ot)) {
|
|
@@ -645,9 +757,22 @@ function mt(e) {
|
|
|
645
757
|
const [t, n = ""] = e.split(/:(.+)/);
|
|
646
758
|
try {
|
|
647
759
|
const r = JSON.parse(n);
|
|
648
|
-
return B("parsed data channel message", {
|
|
760
|
+
return B("parsed data channel message", {
|
|
761
|
+
subject: t,
|
|
762
|
+
data: r
|
|
763
|
+
}), {
|
|
764
|
+
subject: t,
|
|
765
|
+
data: r
|
|
766
|
+
};
|
|
649
767
|
} catch (r) {
|
|
650
|
-
return B("Failed to parse data channel message, returning data as string", {
|
|
768
|
+
return B("Failed to parse data channel message, returning data as string", {
|
|
769
|
+
subject: t,
|
|
770
|
+
rawData: n,
|
|
771
|
+
error: r
|
|
772
|
+
}), {
|
|
773
|
+
subject: t,
|
|
774
|
+
data: n
|
|
775
|
+
};
|
|
651
776
|
}
|
|
652
777
|
}
|
|
653
778
|
function gt({
|
|
@@ -675,7 +800,12 @@ function se({
|
|
|
675
800
|
streamType: s,
|
|
676
801
|
report: o
|
|
677
802
|
}) {
|
|
678
|
-
s === W.Legacy ? gt({
|
|
803
|
+
s === W.Legacy ? gt({
|
|
804
|
+
statsSignal: e,
|
|
805
|
+
dataChannelSignal: t,
|
|
806
|
+
onVideoStateChange: n,
|
|
807
|
+
report: o
|
|
808
|
+
}) : s === W.Fluent && ht({
|
|
679
809
|
statsSignal: e,
|
|
680
810
|
dataChannelSignal: t,
|
|
681
811
|
onVideoStateChange: n,
|
|
@@ -683,16 +813,23 @@ function se({
|
|
|
683
813
|
report: o
|
|
684
814
|
});
|
|
685
815
|
}
|
|
686
|
-
async function wt(e, t, {
|
|
816
|
+
async function wt(e, t, {
|
|
817
|
+
debug: n = !1,
|
|
818
|
+
callbacks: r,
|
|
819
|
+
auth: s,
|
|
820
|
+
baseURL: o = Z,
|
|
821
|
+
analytics: c
|
|
822
|
+
}) {
|
|
687
823
|
var J;
|
|
688
824
|
pe = n;
|
|
689
825
|
let a = !1, i = !1, d = h.Stop, l = h.Stop;
|
|
690
|
-
const {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
826
|
+
const {
|
|
827
|
+
startConnection: y,
|
|
828
|
+
sendStreamRequest: _,
|
|
829
|
+
close: T,
|
|
830
|
+
createStream: j,
|
|
831
|
+
addIceCandidate: x
|
|
832
|
+
} = rt(s, o, e, r.onError), {
|
|
696
833
|
id: R,
|
|
697
834
|
offer: U,
|
|
698
835
|
ice_servers: K,
|
|
@@ -700,48 +837,49 @@ async function wt(e, t, { debug: n = !1, callbacks: r, auth: s, baseURL: o = Z,
|
|
|
700
837
|
fluent: u,
|
|
701
838
|
interrupt_enabled: v
|
|
702
839
|
} = await j(t);
|
|
703
|
-
(J = r.onStreamCreated) == null || J.call(r, {
|
|
704
|
-
|
|
840
|
+
(J = r.onStreamCreated) == null || J.call(r, {
|
|
841
|
+
stream_id: R,
|
|
842
|
+
session_id: P,
|
|
843
|
+
agent_id: e
|
|
844
|
+
});
|
|
845
|
+
const m = new ft({
|
|
846
|
+
iceServers: K
|
|
847
|
+
}), D = m.createDataChannel("JanusDataChannel");
|
|
705
848
|
if (!P)
|
|
706
849
|
throw new Error("Could not create session_id");
|
|
707
850
|
const w = u ? W.Fluent : W.Legacy;
|
|
708
|
-
c.enrich({
|
|
851
|
+
c.enrich({
|
|
852
|
+
"stream-type": w
|
|
853
|
+
});
|
|
709
854
|
const p = t.stream_warmup && !u, b = () => a, L = () => {
|
|
710
855
|
var f;
|
|
711
856
|
a = !0, i && ((f = r.onConnectionStateChange) == null || f.call(r, I.Connected));
|
|
712
|
-
}, $ = ut(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
}),
|
|
724
|
-
(f) => {
|
|
725
|
-
var g;
|
|
726
|
-
return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
|
|
727
|
-
},
|
|
728
|
-
p
|
|
729
|
-
);
|
|
857
|
+
}, $ = ut(m, b, L, (f, g) => se({
|
|
858
|
+
statsSignal: l = f,
|
|
859
|
+
dataChannelSignal: w === W.Legacy ? d : void 0,
|
|
860
|
+
onVideoStateChange: r.onVideoStateChange,
|
|
861
|
+
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
862
|
+
report: g,
|
|
863
|
+
streamType: w
|
|
864
|
+
}), (f) => {
|
|
865
|
+
var g;
|
|
866
|
+
return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
|
|
867
|
+
}, p);
|
|
730
868
|
m.onicecandidate = (f) => {
|
|
731
869
|
var g;
|
|
732
870
|
B("peerConnection.onicecandidate", f);
|
|
733
871
|
try {
|
|
734
|
-
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? x(
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
P
|
|
742
|
-
) : x(R, { candidate: null }, P);
|
|
872
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? x(R, {
|
|
873
|
+
candidate: f.candidate.candidate,
|
|
874
|
+
sdpMid: f.candidate.sdpMid,
|
|
875
|
+
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
876
|
+
}, P) : x(R, {
|
|
877
|
+
candidate: null
|
|
878
|
+
}, P);
|
|
743
879
|
} catch (S) {
|
|
744
|
-
(g = r.onError) == null || g.call(r, S, {
|
|
880
|
+
(g = r.onError) == null || g.call(r, S, {
|
|
881
|
+
streamId: R
|
|
882
|
+
});
|
|
745
883
|
}
|
|
746
884
|
}, D.onopen = () => {
|
|
747
885
|
i = !0, (!p || a) && L();
|
|
@@ -765,7 +903,11 @@ async function wt(e, t, { debug: n = !1, callbacks: r, auth: s, baseURL: o = Z,
|
|
|
765
903
|
}
|
|
766
904
|
function C(f, g) {
|
|
767
905
|
const S = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
|
|
768
|
-
S && c.enrich({
|
|
906
|
+
S && c.enrich({
|
|
907
|
+
streamMetadata: S
|
|
908
|
+
}), c.track("agent-chat", {
|
|
909
|
+
event: "ready"
|
|
910
|
+
});
|
|
769
911
|
}
|
|
770
912
|
const z = {
|
|
771
913
|
[A.StreamStarted]: E,
|
|
@@ -774,7 +916,10 @@ async function wt(e, t, { debug: n = !1, callbacks: r, auth: s, baseURL: o = Z,
|
|
|
774
916
|
};
|
|
775
917
|
D.onmessage = (f) => {
|
|
776
918
|
var X;
|
|
777
|
-
const {
|
|
919
|
+
const {
|
|
920
|
+
subject: g,
|
|
921
|
+
data: S
|
|
922
|
+
} = mt(f.data);
|
|
778
923
|
(X = z[g]) == null || X.call(z, g, S);
|
|
779
924
|
}, m.oniceconnectionstatechange = () => {
|
|
780
925
|
var g;
|
|
@@ -831,7 +976,9 @@ async function wt(e, t, { debug: n = !1, callbacks: r, auth: s, baseURL: o = Z,
|
|
|
831
976
|
try {
|
|
832
977
|
D.send(f);
|
|
833
978
|
} catch (X) {
|
|
834
|
-
B("Error sending data channel message", X), (S = r.onError) == null || S.call(r, X, {
|
|
979
|
+
B("Error sending data channel message", X), (S = r.onError) == null || S.call(r, X, {
|
|
980
|
+
streamId: R
|
|
981
|
+
});
|
|
835
982
|
}
|
|
836
983
|
},
|
|
837
984
|
/**
|
|
@@ -847,7 +994,9 @@ async function wt(e, t, { debug: n = !1, callbacks: r, auth: s, baseURL: o = Z,
|
|
|
847
994
|
};
|
|
848
995
|
}
|
|
849
996
|
function pt(e) {
|
|
850
|
-
const {
|
|
997
|
+
const {
|
|
998
|
+
streamOptions: t
|
|
999
|
+
} = e ?? {};
|
|
851
1000
|
return {
|
|
852
1001
|
output_resolution: t == null ? void 0 : t.outputResolution,
|
|
853
1002
|
session_timeout: t == null ? void 0 : t.sessionTimeout,
|
|
@@ -860,7 +1009,10 @@ function yt(e, t, n, r, s) {
|
|
|
860
1009
|
s === W.Fluent ? vt(e, t, n, r, s) : Dt(e, t, n, r, s);
|
|
861
1010
|
}
|
|
862
1011
|
function vt(e, t, n, r, s) {
|
|
863
|
-
e === h.Start ? r.track("stream-session", {
|
|
1012
|
+
e === h.Start ? r.track("stream-session", {
|
|
1013
|
+
event: "start",
|
|
1014
|
+
"stream-type": s
|
|
1015
|
+
}) : e === h.Stop && r.track("stream-session", {
|
|
864
1016
|
event: "stop",
|
|
865
1017
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
866
1018
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -869,41 +1021,29 @@ function vt(e, t, n, r, s) {
|
|
|
869
1021
|
});
|
|
870
1022
|
}
|
|
871
1023
|
function kt(e, t, n, r) {
|
|
872
|
-
N.get() <= 0 || (e === h.Start ? n.linkTrack(
|
|
873
|
-
"
|
|
874
|
-
|
|
875
|
-
"
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
"
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
background: t.presenter.type === "clip" && t.presenter.background,
|
|
883
|
-
"stream-type": r
|
|
884
|
-
},
|
|
885
|
-
"done",
|
|
886
|
-
[A.StreamVideoDone]
|
|
887
|
-
));
|
|
1024
|
+
N.get() <= 0 || (e === h.Start ? n.linkTrack("agent-video", {
|
|
1025
|
+
event: "start",
|
|
1026
|
+
latency: N.get(!0),
|
|
1027
|
+
"stream-type": r
|
|
1028
|
+
}, "start", [A.StreamVideoCreated]) : e === h.Stop && n.linkTrack("agent-video", {
|
|
1029
|
+
event: "stop",
|
|
1030
|
+
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1031
|
+
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1032
|
+
"stream-type": r
|
|
1033
|
+
}, "done", [A.StreamVideoDone]));
|
|
888
1034
|
}
|
|
889
1035
|
function Dt(e, t, n, r, s) {
|
|
890
|
-
N.get() <= 0 || (e === h.Start ? r.linkTrack(
|
|
891
|
-
"
|
|
892
|
-
|
|
893
|
-
"
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
"
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
"stream-type": s,
|
|
902
|
-
...n
|
|
903
|
-
},
|
|
904
|
-
"done",
|
|
905
|
-
[A.StreamVideoDone]
|
|
906
|
-
));
|
|
1036
|
+
N.get() <= 0 || (e === h.Start ? r.linkTrack("agent-video", {
|
|
1037
|
+
event: "start",
|
|
1038
|
+
latency: N.get(!0),
|
|
1039
|
+
"stream-type": s
|
|
1040
|
+
}, "start", [A.StreamVideoCreated]) : e === h.Stop && r.linkTrack("agent-video", {
|
|
1041
|
+
event: "stop",
|
|
1042
|
+
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1043
|
+
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1044
|
+
"stream-type": s,
|
|
1045
|
+
...n
|
|
1046
|
+
}, "done", [A.StreamVideoDone]));
|
|
907
1047
|
}
|
|
908
1048
|
function Ct(e, t, n) {
|
|
909
1049
|
return N.reset(), new Promise(async (r, s) => {
|
|
@@ -919,22 +1059,11 @@ function Ct(e, t, n) {
|
|
|
919
1059
|
},
|
|
920
1060
|
onVideoStateChange: (c, a) => {
|
|
921
1061
|
var i, d;
|
|
922
|
-
(d = (i = t.callbacks).onVideoStateChange) == null || d.call(i, c), yt(
|
|
923
|
-
c,
|
|
924
|
-
e,
|
|
925
|
-
a,
|
|
926
|
-
n,
|
|
927
|
-
o.streamType
|
|
928
|
-
);
|
|
1062
|
+
(d = (i = t.callbacks).onVideoStateChange) == null || d.call(i, c), yt(c, e, a, n, o.streamType);
|
|
929
1063
|
},
|
|
930
1064
|
onAgentActivityStateChange: (c) => {
|
|
931
1065
|
var a, i;
|
|
932
|
-
(i = (a = t.callbacks).onAgentActivityStateChange) == null || i.call(a, c), c === O.Talking ? re.update() : re.reset(), kt(
|
|
933
|
-
c === O.Talking ? h.Start : h.Stop,
|
|
934
|
-
e,
|
|
935
|
-
n,
|
|
936
|
-
o.streamType
|
|
937
|
-
);
|
|
1066
|
+
(i = (a = t.callbacks).onAgentActivityStateChange) == null || i.call(a, c), c === O.Talking ? re.update() : re.reset(), kt(c === O.Talking ? h.Start : h.Stop, e, n, o.streamType);
|
|
938
1067
|
}
|
|
939
1068
|
}
|
|
940
1069
|
});
|
|
@@ -945,8 +1074,16 @@ function Ct(e, t, n) {
|
|
|
945
1074
|
}
|
|
946
1075
|
async function Rt(e, t, n, r, s) {
|
|
947
1076
|
var y, _, T, j;
|
|
948
|
-
const o = we(e, n, r, t.mode, t.persistentChat, s), c = Ct(e, t, r), [a, i] = await Promise.all([o, c]), {
|
|
949
|
-
|
|
1077
|
+
const o = we(e, n, r, t.mode, t.persistentChat, s), c = Ct(e, t, r), [a, i] = await Promise.all([o, c]), {
|
|
1078
|
+
chat: d,
|
|
1079
|
+
chatMode: l
|
|
1080
|
+
} = a;
|
|
1081
|
+
return l && l !== t.mode && (t.mode = l, (_ = (y = t.callbacks).onModeChange) == null || _.call(y, l), l !== M.Functional) ? ((j = (T = t.callbacks).onError) == null || j.call(T, new De(l)), i == null || i.disconnect(), {
|
|
1082
|
+
chat: d
|
|
1083
|
+
}) : {
|
|
1084
|
+
chat: d,
|
|
1085
|
+
streamingManager: i
|
|
1086
|
+
};
|
|
950
1087
|
}
|
|
951
1088
|
async function Et(e, t) {
|
|
952
1089
|
var U, K, P;
|
|
@@ -960,47 +1097,52 @@ async function Et(e, t) {
|
|
|
960
1097
|
isEnabled: t.enableAnalitics,
|
|
961
1098
|
distinctId: t.distinctId
|
|
962
1099
|
});
|
|
963
|
-
i.track("agent-sdk", {
|
|
1100
|
+
i.track("agent-sdk", {
|
|
1101
|
+
event: "init"
|
|
1102
|
+
});
|
|
964
1103
|
const d = fe(t.auth, c, t.callbacks.onError), l = await d.getById(e);
|
|
965
1104
|
i.enrich(We(l));
|
|
966
|
-
const {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
()
|
|
972
|
-
|
|
973
|
-
return (u = a.socketManager) == null ? void 0 : u.disconnect();
|
|
974
|
-
}
|
|
975
|
-
);
|
|
1105
|
+
const {
|
|
1106
|
+
onMessage: y,
|
|
1107
|
+
clearQueue: _
|
|
1108
|
+
} = tt(i, a, t, l, () => {
|
|
1109
|
+
var u;
|
|
1110
|
+
return (u = a.socketManager) == null ? void 0 : u.disconnect();
|
|
1111
|
+
});
|
|
976
1112
|
a.messages = Ve(t.initialMessages), (K = (U = t.callbacks).onNewMessage) == null || K.call(U, [...a.messages], "answer");
|
|
977
1113
|
const T = (u) => {
|
|
978
1114
|
r = u;
|
|
979
1115
|
};
|
|
980
|
-
i.track("agent-sdk", {
|
|
1116
|
+
i.track("agent-sdk", {
|
|
1117
|
+
event: "loaded",
|
|
1118
|
+
...Je(l)
|
|
1119
|
+
});
|
|
981
1120
|
async function j(u) {
|
|
982
1121
|
var b, L, $, k, E, C, z;
|
|
983
1122
|
(L = (b = t.callbacks).onConnectionStateChange) == null || L.call(b, I.Connecting), N.reset(), u && !n && (delete a.chat, (k = ($ = t.callbacks).onNewMessage) == null || k.call($, [...a.messages], "answer"));
|
|
984
|
-
const v = t.mode === M.DirectPlayback ? Promise.resolve(void 0) : Ze(t.auth, o, {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
{
|
|
993
|
-
limit: 3,
|
|
994
|
-
timeout: Ae,
|
|
995
|
-
timeoutErrorMessage: "Timeout initializing the stream",
|
|
996
|
-
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
997
|
-
shouldRetryFn: (F) => (F == null ? void 0 : F.message) !== "Could not connect" && F.status !== 429,
|
|
998
|
-
delayMs: 1e3
|
|
1123
|
+
const v = t.mode === M.DirectPlayback ? Promise.resolve(void 0) : Ze(t.auth, o, {
|
|
1124
|
+
onMessage: y,
|
|
1125
|
+
onError: t.callbacks.onError
|
|
1126
|
+
}), m = te(() => Rt(l, {
|
|
1127
|
+
...t,
|
|
1128
|
+
callbacks: {
|
|
1129
|
+
...t.callbacks,
|
|
1130
|
+
onVideoIdChange: T
|
|
999
1131
|
}
|
|
1000
|
-
|
|
1132
|
+
}, d, i, a.chat), {
|
|
1133
|
+
limit: 3,
|
|
1134
|
+
timeout: Ae,
|
|
1135
|
+
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1136
|
+
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1137
|
+
shouldRetryFn: (F) => (F == null ? void 0 : F.message) !== "Could not connect" && F.status !== 429,
|
|
1138
|
+
delayMs: 1e3
|
|
1139
|
+
}).catch((F) => {
|
|
1001
1140
|
var J, f;
|
|
1002
1141
|
throw R(M.Maintenance), (f = (J = t.callbacks).onConnectionStateChange) == null || f.call(J, I.Fail), F;
|
|
1003
|
-
}), [D, {
|
|
1142
|
+
}), [D, {
|
|
1143
|
+
streamingManager: w,
|
|
1144
|
+
chat: p
|
|
1145
|
+
}] = await Promise.all([v, m]);
|
|
1004
1146
|
p && p.id !== ((E = a.chat) == null ? void 0 : E.id) && ((z = (C = t.callbacks).onNewChat) == null || z.call(C, p.id)), a.streamingManager = w, a.socketManager = D, a.chat = p, n = !1, i.enrich({
|
|
1005
1147
|
chatId: p == null ? void 0 : p.id,
|
|
1006
1148
|
streamId: w == null ? void 0 : w.streamId,
|
|
@@ -1013,7 +1155,9 @@ async function Et(e, t) {
|
|
|
1013
1155
|
}
|
|
1014
1156
|
async function R(u) {
|
|
1015
1157
|
var v, m;
|
|
1016
|
-
u !== a.chatMode && (i.track("agent-mode-change", {
|
|
1158
|
+
u !== a.chatMode && (i.track("agent-mode-change", {
|
|
1159
|
+
mode: u
|
|
1160
|
+
}), a.chatMode = u, a.chatMode !== M.Functional && await x(), (m = (v = t.callbacks).onModeChange) == null || m.call(v, u));
|
|
1017
1161
|
}
|
|
1018
1162
|
return {
|
|
1019
1163
|
agent: l,
|
|
@@ -1067,48 +1211,37 @@ async function Et(e, t) {
|
|
|
1067
1211
|
}, m = async () => {
|
|
1068
1212
|
var k, E;
|
|
1069
1213
|
if (!a.chat) {
|
|
1070
|
-
const C = await we(
|
|
1071
|
-
l,
|
|
1072
|
-
d,
|
|
1073
|
-
i,
|
|
1074
|
-
a.chatMode,
|
|
1075
|
-
t.persistentChat
|
|
1076
|
-
);
|
|
1214
|
+
const C = await we(l, d, i, a.chatMode, t.persistentChat);
|
|
1077
1215
|
if (!C.chat)
|
|
1078
1216
|
throw new ke(a.chatMode, !!t.persistentChat);
|
|
1079
1217
|
a.chat = C.chat, (E = (k = t.callbacks).onNewChat) == null || E.call(k, a.chat.id);
|
|
1080
1218
|
}
|
|
1081
1219
|
return a.chat.id;
|
|
1082
|
-
}, D = async (k, E) => te(
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1220
|
+
}, D = async (k, E) => te(() => {
|
|
1221
|
+
var C, z;
|
|
1222
|
+
return d.chat(l.id, E, {
|
|
1223
|
+
chatMode: a.chatMode,
|
|
1224
|
+
streamId: (C = a.streamingManager) == null ? void 0 : C.streamId,
|
|
1225
|
+
sessionId: (z = a.streamingManager) == null ? void 0 : z.sessionId,
|
|
1226
|
+
messages: k.map(({
|
|
1227
|
+
matches: F,
|
|
1228
|
+
...J
|
|
1229
|
+
}) => J)
|
|
1230
|
+
}, {
|
|
1231
|
+
...he(a.chatMode),
|
|
1232
|
+
skipErrorHandler: !0
|
|
1233
|
+
});
|
|
1234
|
+
}, {
|
|
1235
|
+
limit: 2,
|
|
1236
|
+
shouldRetryFn: (C) => {
|
|
1237
|
+
var J, f, g, S;
|
|
1238
|
+
const z = (J = C == null ? void 0 : C.message) == null ? void 0 : J.includes("missing or invalid session_id");
|
|
1239
|
+
return !((f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("Stream Error")) && !z ? ((S = (g = t.callbacks).onError) == null || S.call(g, C), !1) : !0;
|
|
1099
1240
|
},
|
|
1100
|
-
{
|
|
1101
|
-
|
|
1102
|
-
shouldRetryFn: (C) => {
|
|
1103
|
-
var J, f, g, S;
|
|
1104
|
-
const z = (J = C == null ? void 0 : C.message) == null ? void 0 : J.includes("missing or invalid session_id");
|
|
1105
|
-
return !((f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("Stream Error")) && !z ? ((S = (g = t.callbacks).onError) == null || S.call(g, C), !1) : !0;
|
|
1106
|
-
},
|
|
1107
|
-
onRetry: async () => {
|
|
1108
|
-
await x(), await j(!1);
|
|
1109
|
-
}
|
|
1241
|
+
onRetry: async () => {
|
|
1242
|
+
await x(), await j(!1);
|
|
1110
1243
|
}
|
|
1111
|
-
);
|
|
1244
|
+
});
|
|
1112
1245
|
try {
|
|
1113
1246
|
_(), v(), a.messages.push({
|
|
1114
1247
|
id: V(),
|
|
@@ -1144,7 +1277,8 @@ async function Et(e, t) {
|
|
|
1144
1277
|
if (a.chat) {
|
|
1145
1278
|
if (!D)
|
|
1146
1279
|
throw new Error("Message not found");
|
|
1147
|
-
} else
|
|
1280
|
+
} else
|
|
1281
|
+
throw new Error("Chat is not initialized");
|
|
1148
1282
|
const w = ((p = D.matches) == null ? void 0 : p.map((k) => [k.document_id, k.id])) ?? [];
|
|
1149
1283
|
return i.track("agent-rate", {
|
|
1150
1284
|
event: m ? "update" : "create",
|
|
@@ -1167,7 +1301,9 @@ async function Et(e, t) {
|
|
|
1167
1301
|
deleteRate(u) {
|
|
1168
1302
|
if (!a.chat)
|
|
1169
1303
|
throw new Error("Chat is not initialized");
|
|
1170
|
-
return i.track("agent-rate-delete", {
|
|
1304
|
+
return i.track("agent-rate-delete", {
|
|
1305
|
+
type: "text"
|
|
1306
|
+
}), d.deleteRating(l.id, a.chat.id, u);
|
|
1171
1307
|
},
|
|
1172
1308
|
async speak(u) {
|
|
1173
1309
|
var w, p, b;
|
|
@@ -1210,10 +1346,15 @@ async function Et(e, t) {
|
|
|
1210
1346
|
throw new Error("Please connect to the agent first");
|
|
1211
1347
|
return a.streamingManager.speak({
|
|
1212
1348
|
script: m,
|
|
1213
|
-
metadata: {
|
|
1349
|
+
metadata: {
|
|
1350
|
+
chat_id: (b = a.chat) == null ? void 0 : b.id,
|
|
1351
|
+
agent_id: l.id
|
|
1352
|
+
}
|
|
1214
1353
|
});
|
|
1215
1354
|
},
|
|
1216
|
-
async interrupt({
|
|
1355
|
+
async interrupt({
|
|
1356
|
+
type: u
|
|
1357
|
+
}) {
|
|
1217
1358
|
var m, D, w;
|
|
1218
1359
|
Oe(a.streamingManager, (m = a.streamingManager) == null ? void 0 : m.streamType, r);
|
|
1219
1360
|
const v = a.messages[a.messages.length - 1];
|
|
@@ -1226,7 +1367,9 @@ async function Et(e, t) {
|
|
|
1226
1367
|
};
|
|
1227
1368
|
}
|
|
1228
1369
|
function Mt(e, t, n) {
|
|
1229
|
-
const {
|
|
1370
|
+
const {
|
|
1371
|
+
getById: r
|
|
1372
|
+
} = fe(t, n || Z);
|
|
1230
1373
|
return r(e);
|
|
1231
1374
|
}
|
|
1232
1375
|
export {
|