@d-id/client-sdk 1.1.0-beta.13 → 1.1.0-beta.14
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 +283 -283
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
var he = Object.defineProperty;
|
|
2
|
-
var we = (e, t,
|
|
3
|
-
var V = (e, t,
|
|
2
|
+
var we = (e, t, n) => t in e ? he(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var V = (e, t, n) => (we(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
4
|
class Z extends Error {
|
|
5
5
|
constructor({
|
|
6
|
-
kind:
|
|
6
|
+
kind: n,
|
|
7
7
|
description: r,
|
|
8
8
|
error: s
|
|
9
9
|
}) {
|
|
10
10
|
super(JSON.stringify({
|
|
11
|
-
kind:
|
|
11
|
+
kind: n,
|
|
12
12
|
description: r
|
|
13
13
|
}));
|
|
14
14
|
V(this, "kind");
|
|
15
15
|
V(this, "description");
|
|
16
16
|
V(this, "error");
|
|
17
|
-
this.kind =
|
|
17
|
+
this.kind = n, this.description = r, this.error = s;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
class pe extends Z {
|
|
21
|
-
constructor(t,
|
|
21
|
+
constructor(t, n) {
|
|
22
22
|
super({
|
|
23
23
|
kind: "ChatCreationFailed",
|
|
24
|
-
description: `Failed to create ${
|
|
24
|
+
description: `Failed to create ${n ? "persistent" : ""} chat, mode: ${t}`
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -34,10 +34,10 @@ class ye extends Z {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
class K extends Z {
|
|
37
|
-
constructor(
|
|
37
|
+
constructor(n, r) {
|
|
38
38
|
super({
|
|
39
39
|
kind: "ValidationError",
|
|
40
|
-
description:
|
|
40
|
+
description: n
|
|
41
41
|
});
|
|
42
42
|
V(this, "key");
|
|
43
43
|
this.key = r;
|
|
@@ -65,19 +65,19 @@ const Me = (e) => {
|
|
|
65
65
|
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), X = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(X || {}), Y = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(Y || {}), x = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(x || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(_ || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), _e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(_e || {}), Te = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Te || {});
|
|
66
66
|
const be = 45 * 1e3, je = "X-Playground-Chat", Q = "https://api.d-id.com", Pe = "wss://notifications.d-id.com", Ae = "79f81a83a67430be2bc0fd61042b8faa", oe = (e) => new Promise((t) => setTimeout(t, e)), q = (e = 16) => {
|
|
67
67
|
const t = new Uint8Array(e);
|
|
68
|
-
return window.crypto.getRandomValues(t), Array.from(t, (
|
|
68
|
+
return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
69
69
|
}, Be = (e) => [T.TextOnly, T.Playground, T.Maintenance].includes(e);
|
|
70
70
|
function $e(e, t) {
|
|
71
|
-
let
|
|
71
|
+
let n;
|
|
72
72
|
return {
|
|
73
73
|
promise: new Promise((s, i) => {
|
|
74
|
-
|
|
74
|
+
n = setTimeout(() => i(new Error(t)), e);
|
|
75
75
|
}),
|
|
76
|
-
clear: () => clearTimeout(
|
|
76
|
+
clear: () => clearTimeout(n)
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
async function O(e, t) {
|
|
80
|
-
const
|
|
80
|
+
const n = {
|
|
81
81
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
82
82
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
83
83
|
timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
|
|
@@ -87,19 +87,19 @@ async function O(e, t) {
|
|
|
87
87
|
})
|
|
88
88
|
};
|
|
89
89
|
let r;
|
|
90
|
-
for (let s = 1; s <=
|
|
90
|
+
for (let s = 1; s <= n.limit; s++)
|
|
91
91
|
try {
|
|
92
|
-
if (!
|
|
92
|
+
if (!n.timeout)
|
|
93
93
|
return await e();
|
|
94
94
|
const {
|
|
95
95
|
promise: i,
|
|
96
96
|
clear: c
|
|
97
|
-
} = $e(
|
|
98
|
-
return await Promise.race([
|
|
97
|
+
} = $e(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
|
|
98
|
+
return await Promise.race([a, i]);
|
|
99
99
|
} catch (i) {
|
|
100
|
-
if (r = i, !
|
|
100
|
+
if (r = i, !n.shouldRetryFn(i) || s >= n.limit)
|
|
101
101
|
throw i;
|
|
102
|
-
await oe(
|
|
102
|
+
await oe(n.delayMs), n.onRetry(i);
|
|
103
103
|
}
|
|
104
104
|
throw r;
|
|
105
105
|
}
|
|
@@ -127,15 +127,15 @@ const ze = (e) => O(e, {
|
|
|
127
127
|
timeout: 0,
|
|
128
128
|
shouldRetryFn: (t) => t.status === 429
|
|
129
129
|
});
|
|
130
|
-
function te(e, t = Q,
|
|
130
|
+
function te(e, t = Q, n) {
|
|
131
131
|
const r = async (s, i) => {
|
|
132
132
|
const {
|
|
133
133
|
skipErrorHandler: c,
|
|
134
|
-
...
|
|
134
|
+
...a
|
|
135
135
|
} = i || {}, o = await ze(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
136
|
-
...
|
|
136
|
+
...a,
|
|
137
137
|
headers: {
|
|
138
|
-
...
|
|
138
|
+
...a.headers,
|
|
139
139
|
Authorization: de(e),
|
|
140
140
|
"Content-Type": "application/json"
|
|
141
141
|
}
|
|
@@ -143,9 +143,9 @@ function te(e, t = Q, a) {
|
|
|
143
143
|
if (!o.ok) {
|
|
144
144
|
let d = await o.text().catch(() => `Failed to fetch with status ${o.status}`);
|
|
145
145
|
const u = new Error(d);
|
|
146
|
-
throw
|
|
146
|
+
throw n && !c && n(u, {
|
|
147
147
|
url: s,
|
|
148
|
-
options:
|
|
148
|
+
options: a,
|
|
149
149
|
headers: o.headers
|
|
150
150
|
}), u;
|
|
151
151
|
}
|
|
@@ -181,8 +181,8 @@ function te(e, t = Q, a) {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
function le(e, t = Q,
|
|
185
|
-
const r = te(e, `${t}/agents`,
|
|
184
|
+
function le(e, t = Q, n) {
|
|
185
|
+
const r = te(e, `${t}/agents`, n);
|
|
186
186
|
return {
|
|
187
187
|
create(s, i) {
|
|
188
188
|
return r.post("/", s, i);
|
|
@@ -202,17 +202,17 @@ function le(e, t = Q, a) {
|
|
|
202
202
|
newChat(s, i, c) {
|
|
203
203
|
return r.post(`/${s}/chat`, i, c);
|
|
204
204
|
},
|
|
205
|
-
chat(s, i, c,
|
|
206
|
-
return r.post(`/${s}/chat/${i}`, c,
|
|
205
|
+
chat(s, i, c, a) {
|
|
206
|
+
return r.post(`/${s}/chat/${i}`, c, a);
|
|
207
207
|
},
|
|
208
|
-
createRating(s, i, c,
|
|
209
|
-
return r.post(`/${s}/chat/${i}/ratings`, c,
|
|
208
|
+
createRating(s, i, c, a) {
|
|
209
|
+
return r.post(`/${s}/chat/${i}/ratings`, c, a);
|
|
210
210
|
},
|
|
211
|
-
updateRating(s, i, c,
|
|
212
|
-
return r.patch(`/${s}/chat/${i}/ratings/${c}`,
|
|
211
|
+
updateRating(s, i, c, a, o) {
|
|
212
|
+
return r.patch(`/${s}/chat/${i}/ratings/${c}`, a, o);
|
|
213
213
|
},
|
|
214
|
-
deleteRating(s, i, c,
|
|
215
|
-
return r.delete(`/${s}/chat/${i}/ratings/${c}`,
|
|
214
|
+
deleteRating(s, i, c, a) {
|
|
215
|
+
return r.delete(`/${s}/chat/${i}/ratings/${c}`, a);
|
|
216
216
|
},
|
|
217
217
|
getSTTToken(s, i) {
|
|
218
218
|
return r.get(`/${s}/stt-token`, i);
|
|
@@ -221,25 +221,25 @@ function le(e, t = Q, a) {
|
|
|
221
221
|
}
|
|
222
222
|
const ue = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
223
223
|
function Ne(e) {
|
|
224
|
-
var s, i, c,
|
|
225
|
-
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop",
|
|
224
|
+
var s, i, c, a;
|
|
225
|
+
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
|
|
226
226
|
const o = navigator.platform;
|
|
227
227
|
return o.toLowerCase().includes("win") ? "Windows" : o.toLowerCase().includes("mac") ? "Mac OS X" : o.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
228
228
|
}, r = e.presenter;
|
|
229
229
|
return {
|
|
230
|
-
$os: `${
|
|
230
|
+
$os: `${n()}`,
|
|
231
231
|
isMobile: `${t() == "Mobile"}`,
|
|
232
232
|
browser: navigator.userAgent,
|
|
233
233
|
origin: window.location.origin,
|
|
234
234
|
agentType: ue(r),
|
|
235
235
|
agentVoice: {
|
|
236
236
|
voiceId: (i = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : i.voice_id,
|
|
237
|
-
provider: (
|
|
237
|
+
provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
|
-
const
|
|
242
|
-
function
|
|
241
|
+
const xe = (e) => e.reduce((t, n) => t + n, 0), re = (e) => xe(e) / e.length;
|
|
242
|
+
function Fe(e, t, n) {
|
|
243
243
|
var o, d, u;
|
|
244
244
|
const {
|
|
245
245
|
event: r,
|
|
@@ -263,24 +263,24 @@ function xe(e, t, a) {
|
|
|
263
263
|
}
|
|
264
264
|
},
|
|
265
265
|
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
|
|
266
|
-
...
|
|
266
|
+
...n
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
let G = {};
|
|
270
270
|
const Je = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
271
271
|
function We(e) {
|
|
272
|
-
var i, c,
|
|
273
|
-
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk",
|
|
272
|
+
var i, c, a, o, d, u;
|
|
273
|
+
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", n = e.agent.presenter, r = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, s = {
|
|
274
274
|
token: e.token || "testKey",
|
|
275
275
|
distinct_id: e.distinctId || ce(),
|
|
276
276
|
agentId: e.agent.id,
|
|
277
|
-
agentType: ue(
|
|
277
|
+
agentType: ue(n),
|
|
278
278
|
owner_id: e.agent.owner_id ?? "",
|
|
279
279
|
promptVersion: (c = e.agent.llm) == null ? void 0 : c.prompt_version,
|
|
280
280
|
behavior: {
|
|
281
281
|
role: r == null ? void 0 : r.role,
|
|
282
282
|
personality: r == null ? void 0 : r.personality,
|
|
283
|
-
instructions: (
|
|
283
|
+
instructions: (a = e.agent.llm) == null ? void 0 : a.instructions
|
|
284
284
|
},
|
|
285
285
|
temperature: (o = e.agent.llm) == null ? void 0 : o.temperature,
|
|
286
286
|
knowledgeSource: r == null ? void 0 : r.knowledge_source,
|
|
@@ -342,12 +342,12 @@ function We(e) {
|
|
|
342
342
|
const D = G[h];
|
|
343
343
|
if (D.events[R] = {
|
|
344
344
|
props: b
|
|
345
|
-
}, D.resolvedDependencies.push(R), k.every((
|
|
346
|
-
const
|
|
345
|
+
}, D.resolvedDependencies.push(R), k.every(($) => D.resolvedDependencies.includes($))) {
|
|
346
|
+
const $ = k.reduce((P, l) => D.events[l] ? {
|
|
347
347
|
...P,
|
|
348
348
|
...D.events[l].props
|
|
349
349
|
} : P, {});
|
|
350
|
-
this.track(h,
|
|
350
|
+
this.track(h, $), D.resolvedDependencies = D.resolvedDependencies.filter((P) => !k.includes(P)), k.forEach((P) => {
|
|
351
351
|
delete D.events[P];
|
|
352
352
|
});
|
|
353
353
|
}
|
|
@@ -370,11 +370,11 @@ function fe(e) {
|
|
|
370
370
|
}
|
|
371
371
|
} : {};
|
|
372
372
|
}
|
|
373
|
-
async function me(e, t,
|
|
373
|
+
async function me(e, t, n, r, s = !1, i) {
|
|
374
374
|
try {
|
|
375
375
|
return !i && r !== T.DirectPlayback && (i = await t.newChat(e.id, {
|
|
376
376
|
persist: s
|
|
377
|
-
}, fe(r)),
|
|
377
|
+
}, fe(r)), n.track("agent-chat", {
|
|
378
378
|
event: "created",
|
|
379
379
|
chat_id: i.id,
|
|
380
380
|
agent_id: e.id,
|
|
@@ -385,11 +385,11 @@ async function me(e, t, a, r, s = !1, i) {
|
|
|
385
385
|
};
|
|
386
386
|
} catch (c) {
|
|
387
387
|
try {
|
|
388
|
-
const
|
|
389
|
-
if ((
|
|
388
|
+
const a = JSON.parse(c.message);
|
|
389
|
+
if ((a == null ? void 0 : a.kind) === "InsufficientCreditsError")
|
|
390
390
|
throw new Error("InsufficientCreditsError");
|
|
391
|
-
} catch (
|
|
392
|
-
console.error("Error parsing the error message:",
|
|
391
|
+
} catch (a) {
|
|
392
|
+
console.error("Error parsing the error message:", a);
|
|
393
393
|
}
|
|
394
394
|
throw new Error("Cannot create new chat");
|
|
395
395
|
}
|
|
@@ -397,40 +397,40 @@ async function me(e, t, a, r, s = !1, i) {
|
|
|
397
397
|
function Ke(e) {
|
|
398
398
|
return e && e.length > 0 ? e : [];
|
|
399
399
|
}
|
|
400
|
-
function He(e, t,
|
|
400
|
+
function He(e, t, n, r, s) {
|
|
401
401
|
if (!e || !t)
|
|
402
402
|
throw new Error("Please connect to the agent first");
|
|
403
403
|
if (!e.interruptEnabled)
|
|
404
404
|
throw new Error("Interrupt is not enabled for this stream");
|
|
405
|
-
if (
|
|
405
|
+
if (n !== W.Fluent)
|
|
406
406
|
throw new Error("Interrupt only available for Fluent streams");
|
|
407
407
|
if (!r && !s)
|
|
408
408
|
throw new Error("No active video to interrupt");
|
|
409
409
|
}
|
|
410
410
|
async function ne(e, t) {
|
|
411
|
-
const
|
|
411
|
+
const n = {
|
|
412
412
|
type: x.StreamInterrupt,
|
|
413
413
|
videoId: t,
|
|
414
414
|
timestamp: Date.now()
|
|
415
415
|
};
|
|
416
|
-
e.sendDataChannelMessage(JSON.stringify(
|
|
416
|
+
e.sendDataChannelMessage(JSON.stringify(n));
|
|
417
417
|
}
|
|
418
418
|
function qe(e) {
|
|
419
|
-
return new Promise((t,
|
|
419
|
+
return new Promise((t, n) => {
|
|
420
420
|
const {
|
|
421
421
|
callbacks: r,
|
|
422
422
|
host: s,
|
|
423
423
|
auth: i
|
|
424
424
|
} = e, {
|
|
425
425
|
onMessage: c = null,
|
|
426
|
-
onOpen:
|
|
426
|
+
onOpen: a = null,
|
|
427
427
|
onClose: o = null,
|
|
428
428
|
onError: d = null
|
|
429
429
|
} = r || {}, u = new WebSocket(`${s}?authorization=${de(i)}`);
|
|
430
430
|
u.onmessage = c, u.onclose = o, u.onerror = (h) => {
|
|
431
|
-
console.error(h), d == null || d("Websocket failed to connect", h),
|
|
431
|
+
console.error(h), d == null || d("Websocket failed to connect", h), n(h);
|
|
432
432
|
}, u.onopen = (h) => {
|
|
433
|
-
|
|
433
|
+
a == null || a(h), t(u);
|
|
434
434
|
};
|
|
435
435
|
});
|
|
436
436
|
}
|
|
@@ -438,29 +438,29 @@ async function Ve(e) {
|
|
|
438
438
|
const {
|
|
439
439
|
retries: t = 1
|
|
440
440
|
} = e;
|
|
441
|
-
let
|
|
442
|
-
for (let r = 0; (
|
|
441
|
+
let n = null;
|
|
442
|
+
for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
|
|
443
443
|
try {
|
|
444
|
-
|
|
444
|
+
n = await qe(e);
|
|
445
445
|
} catch (s) {
|
|
446
446
|
if (r === t)
|
|
447
447
|
throw s;
|
|
448
448
|
await oe(r * 500);
|
|
449
449
|
}
|
|
450
|
-
return
|
|
450
|
+
return n;
|
|
451
451
|
}
|
|
452
|
-
async function Xe(e, t,
|
|
453
|
-
const r =
|
|
452
|
+
async function Xe(e, t, n) {
|
|
453
|
+
const r = n != null && n.onMessage ? [n.onMessage] : [], s = await Ve({
|
|
454
454
|
auth: e,
|
|
455
455
|
host: t,
|
|
456
456
|
callbacks: {
|
|
457
457
|
onError: (i) => {
|
|
458
458
|
var c;
|
|
459
|
-
return (c =
|
|
459
|
+
return (c = n.onError) == null ? void 0 : c.call(n, new ve(i));
|
|
460
460
|
},
|
|
461
461
|
onMessage(i) {
|
|
462
462
|
const c = JSON.parse(i.data);
|
|
463
|
-
r.forEach((
|
|
463
|
+
r.forEach((a) => a(c.event, c));
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
});
|
|
@@ -473,36 +473,36 @@ async function Xe(e, t, a) {
|
|
|
473
473
|
function Ye(e) {
|
|
474
474
|
if (e.answer !== void 0)
|
|
475
475
|
return e.answer;
|
|
476
|
-
let t = 0,
|
|
476
|
+
let t = 0, n = "";
|
|
477
477
|
for (; t in e; )
|
|
478
|
-
|
|
479
|
-
return
|
|
478
|
+
n += e[t++];
|
|
479
|
+
return n;
|
|
480
480
|
}
|
|
481
|
-
function Qe(e, t,
|
|
481
|
+
function Qe(e, t, n, r, s) {
|
|
482
482
|
const i = r.messages[r.messages.length - 1];
|
|
483
483
|
if (!(e === H.Partial || e === H.Answer) || (i == null ? void 0 : i.role) !== "assistant")
|
|
484
484
|
return;
|
|
485
485
|
const {
|
|
486
486
|
content: c,
|
|
487
|
-
sequence:
|
|
487
|
+
sequence: a
|
|
488
488
|
} = t;
|
|
489
|
-
e === H.Partial ? a
|
|
490
|
-
const o = Ye(
|
|
489
|
+
e === H.Partial ? n[a] = c : n.answer = c;
|
|
490
|
+
const o = Ye(n);
|
|
491
491
|
(i.content !== o || e === H.Answer) && (i.content = o, s == null || s([...r.messages], e));
|
|
492
492
|
}
|
|
493
|
-
function Ze(e, t,
|
|
493
|
+
function Ze(e, t, n, r, s) {
|
|
494
494
|
let i = {};
|
|
495
495
|
return {
|
|
496
496
|
clearQueue: () => i = {},
|
|
497
|
-
onMessage: (c,
|
|
497
|
+
onMessage: (c, a) => {
|
|
498
498
|
var o, d;
|
|
499
|
-
if ("content" in
|
|
500
|
-
Qe(c,
|
|
499
|
+
if ("content" in a)
|
|
500
|
+
Qe(c, a, i, t, n.callbacks.onNewMessage), c === H.Answer && e.track("agent-message-received", {
|
|
501
501
|
messages: t.messages.length,
|
|
502
502
|
mode: t.chatMode
|
|
503
503
|
});
|
|
504
504
|
else {
|
|
505
|
-
const u = x, h = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], b = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], R =
|
|
505
|
+
const u = x, h = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], b = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], R = Fe(a, r, {
|
|
506
506
|
mode: t.chatMode
|
|
507
507
|
});
|
|
508
508
|
if (c = c, c === u.StreamVideoCreated)
|
|
@@ -517,15 +517,15 @@ function Ze(e, t, a, r, s) {
|
|
|
517
517
|
event: k
|
|
518
518
|
}, c, ["done"]);
|
|
519
519
|
}
|
|
520
|
-
b.includes(c) && ((d = (o =
|
|
521
|
-
data:
|
|
522
|
-
})),
|
|
520
|
+
b.includes(c) && ((d = (o = n.callbacks).onError) == null || d.call(o, new Error(`Stream failed with event ${c}`), {
|
|
521
|
+
data: a
|
|
522
|
+
})), a.event === u.StreamDone && s();
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
};
|
|
526
526
|
}
|
|
527
|
-
function Ge(e, t,
|
|
528
|
-
const s = te(e, `${t}/agents/${
|
|
527
|
+
function Ge(e, t, n, r) {
|
|
528
|
+
const s = te(e, `${t}/agents/${n}`, r);
|
|
529
529
|
return {
|
|
530
530
|
createStream(i) {
|
|
531
531
|
return s.post("/streams", {
|
|
@@ -536,22 +536,22 @@ function Ge(e, t, a, r) {
|
|
|
536
536
|
fluent: i.fluent
|
|
537
537
|
});
|
|
538
538
|
},
|
|
539
|
-
startConnection(i, c,
|
|
539
|
+
startConnection(i, c, a) {
|
|
540
540
|
return s.post(`/streams/${i}/sdp`, {
|
|
541
|
-
session_id:
|
|
541
|
+
session_id: a,
|
|
542
542
|
answer: c
|
|
543
543
|
});
|
|
544
544
|
},
|
|
545
|
-
addIceCandidate(i, c,
|
|
545
|
+
addIceCandidate(i, c, a) {
|
|
546
546
|
return s.post(`/streams/${i}/ice`, {
|
|
547
|
-
session_id:
|
|
547
|
+
session_id: a,
|
|
548
548
|
...c
|
|
549
549
|
});
|
|
550
550
|
},
|
|
551
|
-
sendStreamRequest(i, c,
|
|
551
|
+
sendStreamRequest(i, c, a) {
|
|
552
552
|
return s.post(`/streams/${i}`, {
|
|
553
553
|
session_id: c,
|
|
554
|
-
...
|
|
554
|
+
...a
|
|
555
555
|
});
|
|
556
556
|
},
|
|
557
557
|
close(i, c) {
|
|
@@ -561,8 +561,8 @@ function Ge(e, t, a, r) {
|
|
|
561
561
|
}
|
|
562
562
|
};
|
|
563
563
|
}
|
|
564
|
-
function Oe(e, t,
|
|
565
|
-
const s = te(e, `${t}/agents/${
|
|
564
|
+
function Oe(e, t, n, r) {
|
|
565
|
+
const s = te(e, `${t}/agents/${n}`, r);
|
|
566
566
|
return {
|
|
567
567
|
createStream(i, c) {
|
|
568
568
|
return s.post("/streams", {
|
|
@@ -576,32 +576,32 @@ function Oe(e, t, a, r) {
|
|
|
576
576
|
fluent: i.fluent
|
|
577
577
|
}, c);
|
|
578
578
|
},
|
|
579
|
-
startConnection(i, c,
|
|
579
|
+
startConnection(i, c, a, o) {
|
|
580
580
|
return s.post(`/streams/${i}/sdp`, {
|
|
581
|
-
session_id:
|
|
581
|
+
session_id: a,
|
|
582
582
|
answer: c
|
|
583
583
|
}, o);
|
|
584
584
|
},
|
|
585
|
-
addIceCandidate(i, c,
|
|
585
|
+
addIceCandidate(i, c, a, o) {
|
|
586
586
|
return s.post(`/streams/${i}/ice`, {
|
|
587
|
-
session_id:
|
|
587
|
+
session_id: a,
|
|
588
588
|
...c
|
|
589
589
|
}, o);
|
|
590
590
|
},
|
|
591
|
-
sendStreamRequest(i, c,
|
|
591
|
+
sendStreamRequest(i, c, a, o) {
|
|
592
592
|
return s.post(`/streams/${i}`, {
|
|
593
593
|
session_id: c,
|
|
594
|
-
...
|
|
594
|
+
...a
|
|
595
595
|
}, o);
|
|
596
596
|
},
|
|
597
|
-
close(i, c,
|
|
597
|
+
close(i, c, a) {
|
|
598
598
|
return s.delete(`/streams/${i}`, {
|
|
599
599
|
session_id: c
|
|
600
|
-
},
|
|
600
|
+
}, a);
|
|
601
601
|
}
|
|
602
602
|
};
|
|
603
603
|
}
|
|
604
|
-
function et(e, t,
|
|
604
|
+
function et(e, t, n) {
|
|
605
605
|
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
606
606
|
return {
|
|
607
607
|
duration: r,
|
|
@@ -618,13 +618,13 @@ function et(e, t, a) {
|
|
|
618
618
|
framesPerSecond: t.framesPerSecond,
|
|
619
619
|
freezeCount: t.freezeCount - e.freezeCount,
|
|
620
620
|
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
621
|
-
lowFpsCount:
|
|
621
|
+
lowFpsCount: n
|
|
622
622
|
};
|
|
623
623
|
}
|
|
624
624
|
function tt(e) {
|
|
625
625
|
return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
|
|
626
626
|
const {
|
|
627
|
-
timestamp:
|
|
627
|
+
timestamp: n,
|
|
628
628
|
...r
|
|
629
629
|
} = t, s = [];
|
|
630
630
|
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"), {
|
|
@@ -634,12 +634,12 @@ function tt(e) {
|
|
|
634
634
|
});
|
|
635
635
|
}
|
|
636
636
|
function rt(e) {
|
|
637
|
-
let t = "",
|
|
637
|
+
let t = "", n = 0;
|
|
638
638
|
for (const r of e.values())
|
|
639
|
-
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (
|
|
639
|
+
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (n = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
|
|
640
640
|
return {
|
|
641
641
|
codec: t,
|
|
642
|
-
rtt:
|
|
642
|
+
rtt: n,
|
|
643
643
|
timestamp: r.timestamp,
|
|
644
644
|
bytesReceived: r.bytesReceived,
|
|
645
645
|
packetsReceived: r.packetsReceived,
|
|
@@ -658,24 +658,24 @@ function rt(e) {
|
|
|
658
658
|
};
|
|
659
659
|
return {};
|
|
660
660
|
}
|
|
661
|
-
function nt(e, t,
|
|
662
|
-
const r = e.map((o, d) => d === 0 ?
|
|
661
|
+
function nt(e, t, n) {
|
|
662
|
+
const r = e.map((o, d) => d === 0 ? n ? {
|
|
663
663
|
timestamp: o.timestamp,
|
|
664
664
|
duration: 0,
|
|
665
665
|
rtt: o.rtt,
|
|
666
|
-
bytesReceived: o.bytesReceived -
|
|
667
|
-
bitrate: (o.bytesReceived -
|
|
668
|
-
packetsReceived: o.packetsReceived -
|
|
669
|
-
packetsLost: o.packetsLost -
|
|
670
|
-
framesDropped: o.framesDropped -
|
|
671
|
-
framesDecoded: o.framesDecoded -
|
|
666
|
+
bytesReceived: o.bytesReceived - n.bytesReceived,
|
|
667
|
+
bitrate: (o.bytesReceived - n.bytesReceived) * 8 / (t / 1e3),
|
|
668
|
+
packetsReceived: o.packetsReceived - n.packetsReceived,
|
|
669
|
+
packetsLost: o.packetsLost - n.packetsLost,
|
|
670
|
+
framesDropped: o.framesDropped - n.framesDropped,
|
|
671
|
+
framesDecoded: o.framesDecoded - n.framesDecoded,
|
|
672
672
|
jitter: o.jitter,
|
|
673
|
-
jitterBufferDelay: o.jitterBufferDelay -
|
|
674
|
-
jitterBufferEmittedCount: o.jitterBufferEmittedCount -
|
|
675
|
-
avgJitterDelayInInterval: (o.jitterBufferDelay -
|
|
673
|
+
jitterBufferDelay: o.jitterBufferDelay - n.jitterBufferDelay,
|
|
674
|
+
jitterBufferEmittedCount: o.jitterBufferEmittedCount - n.jitterBufferEmittedCount,
|
|
675
|
+
avgJitterDelayInInterval: (o.jitterBufferDelay - n.jitterBufferDelay) / (o.jitterBufferEmittedCount - n.jitterBufferEmittedCount),
|
|
676
676
|
framesPerSecond: o.framesPerSecond,
|
|
677
|
-
freezeCount: o.freezeCount -
|
|
678
|
-
freezeDuration: o.freezeDuration -
|
|
677
|
+
freezeCount: o.freezeCount - n.freezeCount,
|
|
678
|
+
freezeDuration: o.freezeDuration - n.freezeDuration
|
|
679
679
|
} : {
|
|
680
680
|
timestamp: o.timestamp,
|
|
681
681
|
rtt: o.rtt,
|
|
@@ -710,13 +710,13 @@ function nt(e, t, a) {
|
|
|
710
710
|
framesPerSecond: o.framesPerSecond,
|
|
711
711
|
freezeCount: o.freezeCount - e[d - 1].freezeCount,
|
|
712
712
|
freezeDuration: o.freezeDuration - e[d - 1].freezeDuration
|
|
713
|
-
}), s = tt(r), i = s.reduce((o, d) => o + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((o) => !!o.avgJitterDelayInInterval).map((o) => o.avgJitterDelayInInterval),
|
|
713
|
+
}), s = tt(r), i = s.reduce((o, d) => o + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((o) => !!o.avgJitterDelayInInterval).map((o) => o.avgJitterDelayInInterval), a = r.filter((o) => !!o.rtt).map((o) => o.rtt);
|
|
714
714
|
return {
|
|
715
715
|
webRTCStats: {
|
|
716
716
|
anomalies: s,
|
|
717
|
-
minRtt: Math.min(...
|
|
718
|
-
avgRtt: re(
|
|
719
|
-
maxRtt: Math.max(...
|
|
717
|
+
minRtt: Math.min(...a),
|
|
718
|
+
avgRtt: re(a),
|
|
719
|
+
maxRtt: Math.max(...a),
|
|
720
720
|
aggregateReport: et(e[0], e[e.length - 1], i),
|
|
721
721
|
minJitterDelayInInterval: Math.min(...c),
|
|
722
722
|
maxJitterDelayInInterval: Math.max(...c),
|
|
@@ -728,16 +728,16 @@ function nt(e, t, a) {
|
|
|
728
728
|
}
|
|
729
729
|
const ee = 100, at = Math.max(Math.ceil(400 / ee), 1), it = 0.25, st = 0.28;
|
|
730
730
|
function ot() {
|
|
731
|
-
let e = 0, t,
|
|
731
|
+
let e = 0, t, n, r = 0;
|
|
732
732
|
return (s) => {
|
|
733
733
|
for (const i of s.values())
|
|
734
734
|
if (i && i.type === "inbound-rtp" && i.kind === "video") {
|
|
735
|
-
const c = i.jitterBufferDelay,
|
|
736
|
-
if (
|
|
737
|
-
const u = c - t, h =
|
|
735
|
+
const c = i.jitterBufferDelay, a = i.jitterBufferEmittedCount;
|
|
736
|
+
if (n && a > n) {
|
|
737
|
+
const u = c - t, h = a - n;
|
|
738
738
|
r = u / h;
|
|
739
739
|
}
|
|
740
|
-
t = c,
|
|
740
|
+
t = c, n = a;
|
|
741
741
|
const o = i.framesDecoded, d = o - e > 0;
|
|
742
742
|
return e = o, {
|
|
743
743
|
isReceiving: d,
|
|
@@ -751,25 +751,25 @@ function ot() {
|
|
|
751
751
|
};
|
|
752
752
|
};
|
|
753
753
|
}
|
|
754
|
-
function ct(e, t,
|
|
755
|
-
let c = [],
|
|
754
|
+
function ct(e, t, n, r, s, i = !1) {
|
|
755
|
+
let c = [], a, o = 0, d = !1, u = X.Unknown, h = X.Unknown, b = 0, R = 0;
|
|
756
756
|
const k = ot();
|
|
757
757
|
return setInterval(async () => {
|
|
758
758
|
const D = await e.getStats(), {
|
|
759
759
|
isReceiving: C,
|
|
760
|
-
avgJitterDelayInInterval:
|
|
760
|
+
avgJitterDelayInInterval: $,
|
|
761
761
|
freezeCount: P
|
|
762
762
|
} = k(D), l = rt(D);
|
|
763
763
|
if (C)
|
|
764
|
-
o = 0, b = P - R, h =
|
|
764
|
+
o = 0, b = P - R, h = $ < it ? X.Strong : $ > st && b > 1 ? X.Weak : u, h !== u && (s == null || s(h), u = h, R += b, b = 0), d || (r == null || r(p.Start), a = c[c.length - 1], c = [], d = !0), c.push(l);
|
|
765
765
|
else if (d && (o++, o >= at)) {
|
|
766
|
-
const w = nt(c, ee,
|
|
767
|
-
r == null || r(p.Stop, w), t() ||
|
|
766
|
+
const w = nt(c, ee, a);
|
|
767
|
+
r == null || r(p.Stop, w), t() || n(), R = P, d = !1;
|
|
768
768
|
}
|
|
769
769
|
}, ee);
|
|
770
770
|
}
|
|
771
771
|
let ge = !1;
|
|
772
|
-
const
|
|
772
|
+
const B = (e, t) => ge && console.log(e, t), dt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
773
773
|
function ae(e) {
|
|
774
774
|
switch (e) {
|
|
775
775
|
case "connected":
|
|
@@ -791,10 +791,10 @@ function ae(e) {
|
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
function lt(e) {
|
|
794
|
-
const [t,
|
|
794
|
+
const [t, n = ""] = e.split(/:(.+)/);
|
|
795
795
|
try {
|
|
796
|
-
const r = JSON.parse(
|
|
797
|
-
return
|
|
796
|
+
const r = JSON.parse(n);
|
|
797
|
+
return B("parsed data channel message", {
|
|
798
798
|
subject: t,
|
|
799
799
|
data: r
|
|
800
800
|
}), {
|
|
@@ -802,37 +802,37 @@ function lt(e) {
|
|
|
802
802
|
data: r
|
|
803
803
|
};
|
|
804
804
|
} catch (r) {
|
|
805
|
-
return
|
|
805
|
+
return B("Failed to parse data channel message, returning data as string", {
|
|
806
806
|
subject: t,
|
|
807
|
-
rawData:
|
|
807
|
+
rawData: n,
|
|
808
808
|
error: r
|
|
809
809
|
}), {
|
|
810
810
|
subject: t,
|
|
811
|
-
data:
|
|
811
|
+
data: n
|
|
812
812
|
};
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
815
|
function ut({
|
|
816
816
|
statsSignal: e,
|
|
817
817
|
dataChannelSignal: t,
|
|
818
|
-
onVideoStateChange:
|
|
818
|
+
onVideoStateChange: n,
|
|
819
819
|
report: r
|
|
820
820
|
}) {
|
|
821
|
-
e === p.Start && t === p.Start ?
|
|
821
|
+
e === p.Start && t === p.Start ? n == null || n(p.Start) : e === p.Stop && t === p.Stop && (n == null || n(p.Stop, r));
|
|
822
822
|
}
|
|
823
823
|
function ft({
|
|
824
824
|
statsSignal: e,
|
|
825
825
|
dataChannelSignal: t,
|
|
826
|
-
onVideoStateChange:
|
|
826
|
+
onVideoStateChange: n,
|
|
827
827
|
onAgentActivityStateChange: r,
|
|
828
828
|
report: s
|
|
829
829
|
}) {
|
|
830
|
-
e === p.Start ?
|
|
830
|
+
e === p.Start ? n == null || n(p.Start) : e === p.Stop && (n == null || n(p.Stop, s)), t === p.Start ? r == null || r(Y.Talking) : t === p.Stop && (r == null || r(Y.Idle));
|
|
831
831
|
}
|
|
832
832
|
function ie({
|
|
833
833
|
statsSignal: e,
|
|
834
834
|
dataChannelSignal: t,
|
|
835
|
-
onVideoStateChange:
|
|
835
|
+
onVideoStateChange: n,
|
|
836
836
|
onAgentActivityStateChange: r,
|
|
837
837
|
streamType: s,
|
|
838
838
|
report: i
|
|
@@ -840,25 +840,25 @@ function ie({
|
|
|
840
840
|
s === W.Legacy ? ut({
|
|
841
841
|
statsSignal: e,
|
|
842
842
|
dataChannelSignal: t,
|
|
843
|
-
onVideoStateChange:
|
|
843
|
+
onVideoStateChange: n,
|
|
844
844
|
report: i
|
|
845
845
|
}) : s === W.Fluent && ft({
|
|
846
846
|
statsSignal: e,
|
|
847
847
|
dataChannelSignal: t,
|
|
848
|
-
onVideoStateChange:
|
|
848
|
+
onVideoStateChange: n,
|
|
849
849
|
onAgentActivityStateChange: r,
|
|
850
850
|
report: i
|
|
851
851
|
});
|
|
852
852
|
}
|
|
853
853
|
async function mt(e, t, {
|
|
854
|
-
debug:
|
|
854
|
+
debug: n = !1,
|
|
855
855
|
callbacks: r,
|
|
856
856
|
auth: s,
|
|
857
857
|
baseURL: i = Q,
|
|
858
858
|
analytics: c
|
|
859
859
|
}) {
|
|
860
|
-
ge =
|
|
861
|
-
let
|
|
860
|
+
ge = n;
|
|
861
|
+
let a = !1, o = !1, d = p.Stop, u = p.Stop;
|
|
862
862
|
const {
|
|
863
863
|
startConnection: h,
|
|
864
864
|
sendStreamRequest: b,
|
|
@@ -867,7 +867,7 @@ async function mt(e, t, {
|
|
|
867
867
|
addIceCandidate: D
|
|
868
868
|
} = t.videoType === se.Clip ? Ge(s, i, e, r.onError) : Oe(s, i, e, r.onError), {
|
|
869
869
|
id: C,
|
|
870
|
-
offer:
|
|
870
|
+
offer: $,
|
|
871
871
|
ice_servers: P,
|
|
872
872
|
session_id: l,
|
|
873
873
|
fluent: w,
|
|
@@ -881,10 +881,10 @@ async function mt(e, t, {
|
|
|
881
881
|
c.enrich({
|
|
882
882
|
"stream-type": v
|
|
883
883
|
});
|
|
884
|
-
const A = t.stream_warmup && !w,
|
|
884
|
+
const A = t.stream_warmup && !w, F = () => a, L = () => {
|
|
885
885
|
var f;
|
|
886
|
-
|
|
887
|
-
}, S = ct(g,
|
|
886
|
+
a = !0, o && ((f = r.onConnectionStateChange) == null || f.call(r, _.Connected));
|
|
887
|
+
}, S = ct(g, F, L, (f, m) => ie({
|
|
888
888
|
statsSignal: u = f,
|
|
889
889
|
dataChannelSignal: v === W.Legacy ? d : void 0,
|
|
890
890
|
onVideoStateChange: r.onVideoStateChange,
|
|
@@ -897,7 +897,7 @@ async function mt(e, t, {
|
|
|
897
897
|
}, A);
|
|
898
898
|
g.onicecandidate = (f) => {
|
|
899
899
|
var m;
|
|
900
|
-
|
|
900
|
+
B("peerConnection.onicecandidate", f);
|
|
901
901
|
try {
|
|
902
902
|
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? D(C, {
|
|
903
903
|
candidate: f.candidate.candidate,
|
|
@@ -912,7 +912,7 @@ async function mt(e, t, {
|
|
|
912
912
|
});
|
|
913
913
|
}
|
|
914
914
|
}, E.onopen = () => {
|
|
915
|
-
o = !0, (!A ||
|
|
915
|
+
o = !0, (!A || a) && L();
|
|
916
916
|
};
|
|
917
917
|
function I(f) {
|
|
918
918
|
d = f === x.StreamStarted ? p.Start : p.Stop, ie({
|
|
@@ -931,7 +931,7 @@ async function mt(e, t, {
|
|
|
931
931
|
event: "ready"
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
|
-
const
|
|
934
|
+
const z = {
|
|
935
935
|
[x.StreamStarted]: I,
|
|
936
936
|
[x.StreamDone]: I,
|
|
937
937
|
[x.StreamReady]: M
|
|
@@ -942,18 +942,18 @@ async function mt(e, t, {
|
|
|
942
942
|
subject: m,
|
|
943
943
|
data: j
|
|
944
944
|
} = lt(f.data);
|
|
945
|
-
(U =
|
|
945
|
+
(U = z[m]) == null || U.call(z, m, j);
|
|
946
946
|
}, g.oniceconnectionstatechange = () => {
|
|
947
947
|
var m;
|
|
948
|
-
|
|
948
|
+
B("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
949
949
|
const f = ae(g.iceConnectionState);
|
|
950
950
|
f !== _.Connected && ((m = r.onConnectionStateChange) == null || m.call(r, f));
|
|
951
951
|
}, g.ontrack = (f) => {
|
|
952
952
|
var m;
|
|
953
|
-
|
|
954
|
-
}, await g.setRemoteDescription(
|
|
955
|
-
const
|
|
956
|
-
return
|
|
953
|
+
B("peerConnection.ontrack", f), (m = r.onSrcObjectReady) == null || m.call(r, f.streams[0]);
|
|
954
|
+
}, await g.setRemoteDescription($), B("set remote description OK");
|
|
955
|
+
const N = await g.createAnswer();
|
|
956
|
+
return B("create answer OK"), await g.setLocalDescription(N), B("set local description OK"), await h(C, N, l), B("start connection OK"), {
|
|
957
957
|
/**
|
|
958
958
|
* Method to send request to server to get clip or talk depend on you payload
|
|
959
959
|
* @param payload
|
|
@@ -979,7 +979,7 @@ async function mt(e, t, {
|
|
|
979
979
|
m === _.Connected && await R(C, l).catch((j) => {
|
|
980
980
|
});
|
|
981
981
|
} catch (j) {
|
|
982
|
-
|
|
982
|
+
B("Error on close stream connection", j);
|
|
983
983
|
}
|
|
984
984
|
(f = r.onAgentActivityStateChange) == null || f.call(r, Y.Idle), clearInterval(S);
|
|
985
985
|
}
|
|
@@ -989,8 +989,8 @@ async function mt(e, t, {
|
|
|
989
989
|
*/
|
|
990
990
|
sendDataChannelMessage(f) {
|
|
991
991
|
var m, j;
|
|
992
|
-
if (!
|
|
993
|
-
|
|
992
|
+
if (!a || E.readyState !== "open") {
|
|
993
|
+
B("Data channel is not ready for sending messages"), (m = r.onError) == null || m.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
994
994
|
streamId: C
|
|
995
995
|
});
|
|
996
996
|
return;
|
|
@@ -998,7 +998,7 @@ async function mt(e, t, {
|
|
|
998
998
|
try {
|
|
999
999
|
E.send(f);
|
|
1000
1000
|
} catch (U) {
|
|
1001
|
-
|
|
1001
|
+
B("Error sending data channel message", U), (j = r.onError) == null || j.call(r, U, {
|
|
1002
1002
|
streamId: C
|
|
1003
1003
|
});
|
|
1004
1004
|
}
|
|
@@ -1017,21 +1017,21 @@ async function mt(e, t, {
|
|
|
1017
1017
|
}
|
|
1018
1018
|
function gt(e, t) {
|
|
1019
1019
|
const {
|
|
1020
|
-
streamOptions:
|
|
1020
|
+
streamOptions: n
|
|
1021
1021
|
} = t ?? {};
|
|
1022
1022
|
return {
|
|
1023
1023
|
videoType: Me(e.presenter.type),
|
|
1024
|
-
output_resolution:
|
|
1025
|
-
session_timeout:
|
|
1026
|
-
stream_warmup:
|
|
1027
|
-
compatibility_mode:
|
|
1028
|
-
fluent:
|
|
1024
|
+
output_resolution: n == null ? void 0 : n.outputResolution,
|
|
1025
|
+
session_timeout: n == null ? void 0 : n.sessionTimeout,
|
|
1026
|
+
stream_warmup: n == null ? void 0 : n.streamWarmup,
|
|
1027
|
+
compatibility_mode: n == null ? void 0 : n.compatibilityMode,
|
|
1028
|
+
fluent: n == null ? void 0 : n.fluent
|
|
1029
1029
|
};
|
|
1030
1030
|
}
|
|
1031
|
-
function ht(e, t,
|
|
1032
|
-
s === W.Fluent ? wt(e, t,
|
|
1031
|
+
function ht(e, t, n, r, s) {
|
|
1032
|
+
s === W.Fluent ? wt(e, t, n, r, s) : yt(e, t, n, r, s);
|
|
1033
1033
|
}
|
|
1034
|
-
function wt(e, t,
|
|
1034
|
+
function wt(e, t, n, r, s) {
|
|
1035
1035
|
e === p.Start ? r.track("stream-session", {
|
|
1036
1036
|
event: "start",
|
|
1037
1037
|
"stream-type": s
|
|
@@ -1040,22 +1040,22 @@ function wt(e, t, a, r, s) {
|
|
|
1040
1040
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1041
1041
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1042
1042
|
"stream-type": s,
|
|
1043
|
-
...
|
|
1043
|
+
...n
|
|
1044
1044
|
});
|
|
1045
1045
|
}
|
|
1046
|
-
function pt(e, t,
|
|
1047
|
-
J.get() <= 0 || (e === p.Start ?
|
|
1046
|
+
function pt(e, t, n, r) {
|
|
1047
|
+
J.get() <= 0 || (e === p.Start ? n.linkTrack("agent-video", {
|
|
1048
1048
|
event: "start",
|
|
1049
1049
|
latency: J.get(!0),
|
|
1050
1050
|
"stream-type": r
|
|
1051
|
-
}, "start", [x.StreamVideoCreated]) : e === p.Stop &&
|
|
1051
|
+
}, "start", [x.StreamVideoCreated]) : e === p.Stop && n.linkTrack("agent-video", {
|
|
1052
1052
|
event: "stop",
|
|
1053
1053
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1054
1054
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1055
1055
|
"stream-type": r
|
|
1056
1056
|
}, "done", [x.StreamVideoDone]));
|
|
1057
1057
|
}
|
|
1058
|
-
function yt(e, t,
|
|
1058
|
+
function yt(e, t, n, r, s) {
|
|
1059
1059
|
J.get() <= 0 || (e === p.Start ? r.linkTrack("agent-video", {
|
|
1060
1060
|
event: "start",
|
|
1061
1061
|
latency: J.get(!0),
|
|
@@ -1065,28 +1065,28 @@ function yt(e, t, a, r, s) {
|
|
|
1065
1065
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1066
1066
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1067
1067
|
"stream-type": s,
|
|
1068
|
-
...
|
|
1068
|
+
...n
|
|
1069
1069
|
}, "done", [x.StreamVideoDone]));
|
|
1070
1070
|
}
|
|
1071
|
-
function vt(e, t,
|
|
1071
|
+
function vt(e, t, n) {
|
|
1072
1072
|
return J.reset(), new Promise(async (r, s) => {
|
|
1073
1073
|
try {
|
|
1074
1074
|
const i = await mt(e.id, gt(e, t), {
|
|
1075
1075
|
...t,
|
|
1076
|
-
analytics:
|
|
1076
|
+
analytics: n,
|
|
1077
1077
|
callbacks: {
|
|
1078
1078
|
...t.callbacks,
|
|
1079
1079
|
onConnectionStateChange: (c) => {
|
|
1080
|
-
var
|
|
1081
|
-
(o = (
|
|
1080
|
+
var a, o;
|
|
1081
|
+
(o = (a = t.callbacks).onConnectionStateChange) == null || o.call(a, c), c === _.Connected && r(i);
|
|
1082
1082
|
},
|
|
1083
|
-
onVideoStateChange: (c,
|
|
1083
|
+
onVideoStateChange: (c, a) => {
|
|
1084
1084
|
var o, d;
|
|
1085
|
-
(d = (o = t.callbacks).onVideoStateChange) == null || d.call(o, c), ht(c, e,
|
|
1085
|
+
(d = (o = t.callbacks).onVideoStateChange) == null || d.call(o, c), ht(c, e, a, n, i.streamType);
|
|
1086
1086
|
},
|
|
1087
1087
|
onAgentActivityStateChange: (c) => {
|
|
1088
|
-
var
|
|
1089
|
-
(o = (
|
|
1088
|
+
var a, o;
|
|
1089
|
+
(o = (a = t.callbacks).onAgentActivityStateChange) == null || o.call(a, c), pt(c === Y.Talking ? p.Start : p.Stop, e, n, i.streamType);
|
|
1090
1090
|
}
|
|
1091
1091
|
}
|
|
1092
1092
|
});
|
|
@@ -1095,26 +1095,26 @@ function vt(e, t, a) {
|
|
|
1095
1095
|
}
|
|
1096
1096
|
});
|
|
1097
1097
|
}
|
|
1098
|
-
async function kt(e, t,
|
|
1098
|
+
async function kt(e, t, n, r, s) {
|
|
1099
1099
|
var o, d, u, h;
|
|
1100
1100
|
const {
|
|
1101
1101
|
chat: i,
|
|
1102
1102
|
chatMode: c
|
|
1103
|
-
} = await me(e,
|
|
1103
|
+
} = await me(e, n, r, t.mode, t.persistentChat, s);
|
|
1104
1104
|
if (c && c !== t.mode && (t.mode = c, (d = (o = t.callbacks).onModeChange) == null || d.call(o, c), c === T.TextOnly))
|
|
1105
1105
|
return (h = (u = t.callbacks).onError) == null || h.call(u, new ye(c)), {
|
|
1106
1106
|
chat: i
|
|
1107
1107
|
};
|
|
1108
|
-
const
|
|
1108
|
+
const a = await vt(e, t, r);
|
|
1109
1109
|
return {
|
|
1110
1110
|
chat: i,
|
|
1111
|
-
streamingManager:
|
|
1111
|
+
streamingManager: a
|
|
1112
1112
|
};
|
|
1113
1113
|
}
|
|
1114
1114
|
async function Ct(e, t) {
|
|
1115
|
-
var C,
|
|
1116
|
-
let
|
|
1117
|
-
const s = t.mixpanelKey || Ae, i = t.wsURL || Pe, c = t.baseURL || Q,
|
|
1115
|
+
var C, $, P;
|
|
1116
|
+
let n = !0, r = !1;
|
|
1117
|
+
const s = t.mixpanelKey || Ae, i = t.wsURL || Pe, c = t.baseURL || Q, a = {
|
|
1118
1118
|
messages: [],
|
|
1119
1119
|
chatMode: t.mode || T.Functional
|
|
1120
1120
|
}, o = le(t.auth, c, t.callbacks.onError), d = await o.getById(e), u = We({
|
|
@@ -1125,55 +1125,55 @@ async function Ct(e, t) {
|
|
|
1125
1125
|
}), {
|
|
1126
1126
|
onMessage: h,
|
|
1127
1127
|
clearQueue: b
|
|
1128
|
-
} = Ze(u,
|
|
1128
|
+
} = Ze(u, a, t, d, () => {
|
|
1129
1129
|
var l;
|
|
1130
|
-
return (l =
|
|
1130
|
+
return (l = a.socketManager) == null ? void 0 : l.disconnect();
|
|
1131
1131
|
});
|
|
1132
|
-
|
|
1132
|
+
a.messages = Ke(t.initialMessages), ($ = (C = t.callbacks).onNewMessage) == null || $.call(C, [...a.messages], "answer"), u.track("agent-sdk", {
|
|
1133
1133
|
event: "loaded",
|
|
1134
1134
|
...Ne(d)
|
|
1135
1135
|
});
|
|
1136
1136
|
async function R(l) {
|
|
1137
|
-
var A,
|
|
1138
|
-
(
|
|
1137
|
+
var A, F, L, S, I, M, z;
|
|
1138
|
+
(F = (A = t.callbacks).onConnectionStateChange) == null || F.call(A, _.Connecting), J.reset(), r = !1, l && !n && (delete a.chat, (S = (L = t.callbacks).onNewMessage) == null || S.call(L, [...a.messages], "answer"));
|
|
1139
1139
|
const w = t.mode === T.DirectPlayback ? Promise.resolve(void 0) : Xe(t.auth, i, {
|
|
1140
1140
|
onMessage: h,
|
|
1141
1141
|
onError: t.callbacks.onError
|
|
1142
|
-
}), y = O(() => kt(d, t, o, u,
|
|
1142
|
+
}), y = O(() => kt(d, t, o, u, a.chat), {
|
|
1143
1143
|
limit: 3,
|
|
1144
1144
|
timeout: be,
|
|
1145
1145
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1146
1146
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1147
|
-
shouldRetryFn: (
|
|
1147
|
+
shouldRetryFn: (N) => (N == null ? void 0 : N.message) !== "Could not connect" && N.status !== 429,
|
|
1148
1148
|
delayMs: 1e3
|
|
1149
|
-
}).catch((
|
|
1149
|
+
}).catch((N) => {
|
|
1150
1150
|
var f, m;
|
|
1151
|
-
throw D(T.Maintenance), (m = (f = t.callbacks).onConnectionStateChange) == null || m.call(f, _.Fail),
|
|
1151
|
+
throw D(T.Maintenance), (m = (f = t.callbacks).onConnectionStateChange) == null || m.call(f, _.Fail), N;
|
|
1152
1152
|
}), [g, {
|
|
1153
1153
|
streamingManager: E,
|
|
1154
1154
|
chat: v
|
|
1155
1155
|
}] = await Promise.all([w, y]);
|
|
1156
|
-
v && v.id !== ((I =
|
|
1156
|
+
v && v.id !== ((I = a.chat) == null ? void 0 : I.id) && ((z = (M = t.callbacks).onNewChat) == null || z.call(M, v.id)), a.streamingManager = E, a.socketManager = g, a.chat = v, n = !1, D((v == null ? void 0 : v.chat_mode) ?? t.mode ?? T.Functional);
|
|
1157
1157
|
}
|
|
1158
1158
|
async function k() {
|
|
1159
1159
|
var l, w, y, g;
|
|
1160
|
-
(l =
|
|
1160
|
+
(l = a.socketManager) == null || l.disconnect(), await ((w = a.streamingManager) == null ? void 0 : w.disconnect()), r = !1, delete a.streamingManager, delete a.socketManager, (g = (y = t.callbacks).onConnectionStateChange) == null || g.call(y, _.Disconnected);
|
|
1161
1161
|
}
|
|
1162
1162
|
async function D(l) {
|
|
1163
1163
|
var w, y;
|
|
1164
|
-
l !==
|
|
1164
|
+
l !== a.chatMode && (u.track("agent-mode-change", {
|
|
1165
1165
|
mode: l
|
|
1166
|
-
}),
|
|
1166
|
+
}), a.chatMode = l, a.chatMode !== T.Functional && await k(), (y = (w = t.callbacks).onModeChange) == null || y.call(w, l));
|
|
1167
1167
|
}
|
|
1168
1168
|
return {
|
|
1169
1169
|
agent: d,
|
|
1170
1170
|
getStreamType: () => {
|
|
1171
1171
|
var l;
|
|
1172
|
-
return (l =
|
|
1172
|
+
return (l = a.streamingManager) == null ? void 0 : l.streamType;
|
|
1173
1173
|
},
|
|
1174
1174
|
getIsInterruptEnabled: () => {
|
|
1175
1175
|
var l;
|
|
1176
|
-
return ((l =
|
|
1176
|
+
return ((l = a.streamingManager) == null ? void 0 : l.interruptEnabled) ?? !1;
|
|
1177
1177
|
},
|
|
1178
1178
|
starterMessages: ((P = d.knowledge) == null ? void 0 : P.starter_message) || [],
|
|
1179
1179
|
getSTTToken: () => o.getSTTToken(d.id),
|
|
@@ -1183,31 +1183,31 @@ async function Ct(e, t) {
|
|
|
1183
1183
|
var l;
|
|
1184
1184
|
await R(!0), u.track("agent-chat", {
|
|
1185
1185
|
event: "connect",
|
|
1186
|
-
chatId: (l =
|
|
1186
|
+
chatId: (l = a.chat) == null ? void 0 : l.id,
|
|
1187
1187
|
agentId: d.id,
|
|
1188
|
-
mode:
|
|
1188
|
+
mode: a.chatMode
|
|
1189
1189
|
});
|
|
1190
1190
|
},
|
|
1191
1191
|
async reconnect() {
|
|
1192
1192
|
var l;
|
|
1193
1193
|
await k(), await R(!1), u.track("agent-chat", {
|
|
1194
1194
|
event: "reconnect",
|
|
1195
|
-
chatId: (l =
|
|
1195
|
+
chatId: (l = a.chat) == null ? void 0 : l.id,
|
|
1196
1196
|
agentId: d.id,
|
|
1197
|
-
mode:
|
|
1197
|
+
mode: a.chatMode
|
|
1198
1198
|
});
|
|
1199
1199
|
},
|
|
1200
1200
|
async disconnect() {
|
|
1201
1201
|
var l;
|
|
1202
1202
|
await k(), u.track("agent-chat", {
|
|
1203
1203
|
event: "disconnect",
|
|
1204
|
-
chatId: (l =
|
|
1204
|
+
chatId: (l = a.chat) == null ? void 0 : l.id,
|
|
1205
1205
|
agentId: d.id,
|
|
1206
|
-
mode:
|
|
1206
|
+
mode: a.chatMode
|
|
1207
1207
|
});
|
|
1208
1208
|
},
|
|
1209
1209
|
async chat(l) {
|
|
1210
|
-
var E, v, A,
|
|
1210
|
+
var E, v, A, F, L;
|
|
1211
1211
|
const w = () => {
|
|
1212
1212
|
if (t.mode === T.DirectPlayback)
|
|
1213
1213
|
throw new K("Direct playback is enabled, chat is disabled");
|
|
@@ -1215,57 +1215,57 @@ async function Ct(e, t) {
|
|
|
1215
1215
|
throw new K("Message cannot be more than 800 characters");
|
|
1216
1216
|
if (l.length === 0)
|
|
1217
1217
|
throw new K("Message cannot be empty");
|
|
1218
|
-
if (
|
|
1218
|
+
if (a.chatMode === T.Maintenance)
|
|
1219
1219
|
throw new K("Chat is in maintenance mode");
|
|
1220
|
-
if (![T.TextOnly, T.Playground].includes(
|
|
1221
|
-
if (!
|
|
1220
|
+
if (![T.TextOnly, T.Playground].includes(a.chatMode)) {
|
|
1221
|
+
if (!a.streamingManager)
|
|
1222
1222
|
throw new K("Streaming manager is not initialized");
|
|
1223
|
-
if (!
|
|
1223
|
+
if (!a.chat)
|
|
1224
1224
|
throw new K("Chat is not initialized");
|
|
1225
1225
|
}
|
|
1226
1226
|
}, y = async () => {
|
|
1227
1227
|
var S, I;
|
|
1228
|
-
if (!
|
|
1229
|
-
const M = await me(d, o, u,
|
|
1228
|
+
if (!a.chat) {
|
|
1229
|
+
const M = await me(d, o, u, a.chatMode, t.persistentChat);
|
|
1230
1230
|
if (!M.chat)
|
|
1231
|
-
throw new pe(
|
|
1232
|
-
|
|
1231
|
+
throw new pe(a.chatMode, !!t.persistentChat);
|
|
1232
|
+
a.chat = M.chat, (I = (S = t.callbacks).onNewChat) == null || I.call(S, a.chat.id);
|
|
1233
1233
|
}
|
|
1234
|
-
return
|
|
1234
|
+
return a.chat.id;
|
|
1235
1235
|
}, g = async (S, I) => O(() => {
|
|
1236
|
-
var M,
|
|
1236
|
+
var M, z;
|
|
1237
1237
|
return o.chat(d.id, I, {
|
|
1238
|
-
chatMode:
|
|
1239
|
-
streamId: (M =
|
|
1240
|
-
sessionId: (
|
|
1238
|
+
chatMode: a.chatMode,
|
|
1239
|
+
streamId: (M = a.streamingManager) == null ? void 0 : M.streamId,
|
|
1240
|
+
sessionId: (z = a.streamingManager) == null ? void 0 : z.sessionId,
|
|
1241
1241
|
messages: S.map(({
|
|
1242
|
-
matches:
|
|
1242
|
+
matches: N,
|
|
1243
1243
|
...f
|
|
1244
1244
|
}) => f)
|
|
1245
1245
|
}, {
|
|
1246
|
-
...fe(
|
|
1246
|
+
...fe(a.chatMode),
|
|
1247
1247
|
skipErrorHandler: !0
|
|
1248
1248
|
});
|
|
1249
1249
|
}, {
|
|
1250
1250
|
limit: 2,
|
|
1251
1251
|
shouldRetryFn: (M) => {
|
|
1252
1252
|
var f, m, j, U;
|
|
1253
|
-
const
|
|
1254
|
-
return !((m = M == null ? void 0 : M.message) == null ? void 0 : m.includes("Stream Error")) && !
|
|
1253
|
+
const z = (f = M == null ? void 0 : M.message) == null ? void 0 : f.includes("missing or invalid session_id");
|
|
1254
|
+
return !((m = M == null ? void 0 : M.message) == null ? void 0 : m.includes("Stream Error")) && !z ? ((U = (j = t.callbacks).onError) == null || U.call(j, M), !1) : !0;
|
|
1255
1255
|
},
|
|
1256
1256
|
onRetry: async () => {
|
|
1257
1257
|
await k(), await R(!1);
|
|
1258
1258
|
}
|
|
1259
1259
|
});
|
|
1260
1260
|
try {
|
|
1261
|
-
b(), w(),
|
|
1261
|
+
b(), w(), a.messages.push({
|
|
1262
1262
|
id: q(),
|
|
1263
1263
|
role: "user",
|
|
1264
1264
|
content: l,
|
|
1265
1265
|
created_at: new Date(J.update()).toISOString()
|
|
1266
|
-
}), (v = (E = t.callbacks).onNewMessage) == null || v.call(E, [...
|
|
1267
|
-
const S = await y(), I = await g([...
|
|
1268
|
-
return
|
|
1266
|
+
}), (v = (E = t.callbacks).onNewMessage) == null || v.call(E, [...a.messages], "user");
|
|
1267
|
+
const S = await y(), I = await g([...a.messages], S);
|
|
1268
|
+
return a.messages.push({
|
|
1269
1269
|
id: q(),
|
|
1270
1270
|
role: "assistant",
|
|
1271
1271
|
content: I.result || "",
|
|
@@ -1273,27 +1273,27 @@ async function Ct(e, t) {
|
|
|
1273
1273
|
context: I.context,
|
|
1274
1274
|
matches: I.matches,
|
|
1275
1275
|
videoId: I.videoId
|
|
1276
|
-
}), r && I.videoId &&
|
|
1276
|
+
}), r && I.videoId && a.streamingManager && (r = !1, a.messages[a.messages.length - 1].interrupted = !0, await ne(a.streamingManager, I.videoId)), u.track("agent-message-send", {
|
|
1277
1277
|
event: "success",
|
|
1278
|
-
mode:
|
|
1279
|
-
messages:
|
|
1280
|
-
}), I.result && ((
|
|
1278
|
+
mode: a.chatMode,
|
|
1279
|
+
messages: a.messages.length + 1
|
|
1280
|
+
}), I.result && ((F = (A = t.callbacks).onNewMessage) == null || F.call(A, [...a.messages], "answer"), u.track("agent-message-received", {
|
|
1281
1281
|
latency: J.get(!0),
|
|
1282
|
-
mode:
|
|
1283
|
-
messages:
|
|
1282
|
+
mode: a.chatMode,
|
|
1283
|
+
messages: a.messages.length
|
|
1284
1284
|
})), I;
|
|
1285
1285
|
} catch (S) {
|
|
1286
|
-
throw r = !1, ((
|
|
1286
|
+
throw r = !1, ((L = a.messages[a.messages.length - 1]) == null ? void 0 : L.role) === "assistant" && a.messages.pop(), u.track("agent-message-send", {
|
|
1287
1287
|
event: "error",
|
|
1288
|
-
mode:
|
|
1289
|
-
messages:
|
|
1288
|
+
mode: a.chatMode,
|
|
1289
|
+
messages: a.messages.length
|
|
1290
1290
|
}), S;
|
|
1291
1291
|
}
|
|
1292
1292
|
},
|
|
1293
1293
|
rate(l, w, y) {
|
|
1294
|
-
var v, A,
|
|
1295
|
-
const g =
|
|
1296
|
-
if (
|
|
1294
|
+
var v, A, F, L;
|
|
1295
|
+
const g = a.messages.find((S) => S.id === l);
|
|
1296
|
+
if (a.chat) {
|
|
1297
1297
|
if (!g)
|
|
1298
1298
|
throw new Error("Message not found");
|
|
1299
1299
|
} else
|
|
@@ -1303,16 +1303,16 @@ async function Ct(e, t) {
|
|
|
1303
1303
|
event: y ? "update" : "create",
|
|
1304
1304
|
thumb: w === 1 ? "up" : "down",
|
|
1305
1305
|
knowledge_id: ((A = d.knowledge) == null ? void 0 : A.id) ?? "",
|
|
1306
|
-
mode:
|
|
1306
|
+
mode: a.chatMode,
|
|
1307
1307
|
matches: E,
|
|
1308
1308
|
score: w
|
|
1309
|
-
}), y ? o.updateRating(d.id,
|
|
1310
|
-
knowledge_id: ((
|
|
1309
|
+
}), y ? o.updateRating(d.id, a.chat.id, y, {
|
|
1310
|
+
knowledge_id: ((F = d.knowledge) == null ? void 0 : F.id) ?? "",
|
|
1311
1311
|
message_id: l,
|
|
1312
1312
|
matches: E,
|
|
1313
1313
|
score: w
|
|
1314
|
-
}) : o.createRating(d.id,
|
|
1315
|
-
knowledge_id: ((
|
|
1314
|
+
}) : o.createRating(d.id, a.chat.id, {
|
|
1315
|
+
knowledge_id: ((L = d.knowledge) == null ? void 0 : L.id) ?? "",
|
|
1316
1316
|
message_id: l,
|
|
1317
1317
|
matches: E,
|
|
1318
1318
|
score: w
|
|
@@ -1320,19 +1320,17 @@ async function Ct(e, t) {
|
|
|
1320
1320
|
},
|
|
1321
1321
|
deleteRate(l) {
|
|
1322
1322
|
var w;
|
|
1323
|
-
if (!
|
|
1323
|
+
if (!a.chat)
|
|
1324
1324
|
throw new Error("Chat is not initialized");
|
|
1325
1325
|
return u.track("agent-rate-delete", {
|
|
1326
1326
|
type: "text",
|
|
1327
|
-
chat_id: (w =
|
|
1327
|
+
chat_id: (w = a.chat) == null ? void 0 : w.id,
|
|
1328
1328
|
id: l,
|
|
1329
|
-
mode:
|
|
1330
|
-
}), o.deleteRating(d.id,
|
|
1329
|
+
mode: a.chatMode
|
|
1330
|
+
}), o.deleteRating(d.id, a.chat.id, l);
|
|
1331
1331
|
},
|
|
1332
1332
|
async speak(l) {
|
|
1333
|
-
var E, v, A
|
|
1334
|
-
if (!n.streamingManager)
|
|
1335
|
-
throw new Error("Please connect to the agent first");
|
|
1333
|
+
var E, v, A;
|
|
1336
1334
|
function w() {
|
|
1337
1335
|
if (typeof l == "string") {
|
|
1338
1336
|
if (!d.presenter.voice)
|
|
@@ -1357,39 +1355,41 @@ async function Ct(e, t) {
|
|
|
1357
1355
|
return l;
|
|
1358
1356
|
}
|
|
1359
1357
|
const y = w();
|
|
1360
|
-
u.track("agent-speak", y), J.update(),
|
|
1358
|
+
if (u.track("agent-speak", y), J.update(), a.messages && y.type === "text" && (a.messages.push({
|
|
1361
1359
|
id: q(),
|
|
1362
1360
|
role: "assistant",
|
|
1363
1361
|
content: y.input,
|
|
1364
1362
|
created_at: new Date(J.get(!0)).toISOString()
|
|
1365
|
-
}), (
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1363
|
+
}), (v = (E = t.callbacks).onNewMessage) == null || v.call(E, [...a.messages], "answer")), Be(a.chatMode))
|
|
1364
|
+
return {
|
|
1365
|
+
duration: 0,
|
|
1366
|
+
status: "success"
|
|
1367
|
+
};
|
|
1368
|
+
if (!a.streamingManager)
|
|
1369
|
+
throw new Error("Please connect to the agent first");
|
|
1370
|
+
return a.streamingManager.speak({
|
|
1371
1371
|
script: y,
|
|
1372
1372
|
metadata: {
|
|
1373
|
-
chat_id: (
|
|
1373
|
+
chat_id: (A = a.chat) == null ? void 0 : A.id,
|
|
1374
1374
|
agent_id: d.id
|
|
1375
1375
|
}
|
|
1376
1376
|
});
|
|
1377
1377
|
},
|
|
1378
1378
|
async interrupt() {
|
|
1379
1379
|
var y, g, E;
|
|
1380
|
-
const l =
|
|
1381
|
-
if (He(
|
|
1380
|
+
const l = a.messages[a.messages.length - 1], w = (l == null ? void 0 : l.role) === "user";
|
|
1381
|
+
if (He(a.streamingManager, a.chat, (y = a.streamingManager) == null ? void 0 : y.streamType, w, !!(l != null && l.videoId)), w) {
|
|
1382
1382
|
r = !0;
|
|
1383
1383
|
return;
|
|
1384
1384
|
}
|
|
1385
|
-
l.interrupted = !0, (E = (g = t.callbacks).onNewMessage) == null || E.call(g, [...
|
|
1385
|
+
l.interrupted = !0, (E = (g = t.callbacks).onNewMessage) == null || E.call(g, [...a.messages], "answer"), ne(a.streamingManager, l == null ? void 0 : l.videoId);
|
|
1386
1386
|
}
|
|
1387
1387
|
};
|
|
1388
1388
|
}
|
|
1389
|
-
function Rt(e, t,
|
|
1389
|
+
function Rt(e, t, n) {
|
|
1390
1390
|
const {
|
|
1391
1391
|
getById: r
|
|
1392
|
-
} = le(t,
|
|
1392
|
+
} = le(t, n || Q);
|
|
1393
1393
|
return r(e);
|
|
1394
1394
|
}
|
|
1395
1395
|
export {
|