@d-id/client-sdk 1.1.0-beta.22 → 1.1.0-beta.23
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 +327 -320
- package/dist/index.umd.cjs +1 -1
- package/dist/src/services/chat/index.d.ts +2 -1
- package/dist/src/services/interrupt/index.d.ts +2 -2
- package/dist/src/types/entities/agents/chat.d.ts +2 -1
- package/dist/src/types/entities/agents/manager.d.ts +6 -0
- package/dist/src/types/stream/stream.d.ts +5 -0
- package/dist/src/utils/chat.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var ve = Object.defineProperty;
|
|
2
|
+
var ke = (e, t, a) => t in e ? ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var Y = (e, t, a) => (ke(e, typeof t != "symbol" ? t + "" : t, a), a);
|
|
4
4
|
class Z extends Error {
|
|
5
5
|
constructor({
|
|
6
6
|
kind: a,
|
|
@@ -11,13 +11,13 @@ class Z extends Error {
|
|
|
11
11
|
kind: a,
|
|
12
12
|
description: n
|
|
13
13
|
}));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Y(this, "kind");
|
|
15
|
+
Y(this, "description");
|
|
16
|
+
Y(this, "error");
|
|
17
17
|
this.kind = a, this.description = n, this.error = s;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
class
|
|
20
|
+
class De extends Z {
|
|
21
21
|
constructor(t, a) {
|
|
22
22
|
super({
|
|
23
23
|
kind: "ChatCreationFailed",
|
|
@@ -25,7 +25,7 @@ class ke extends Z {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
class
|
|
28
|
+
class Ce extends Z {
|
|
29
29
|
constructor(t) {
|
|
30
30
|
super({
|
|
31
31
|
kind: "ChatModeDowngraded",
|
|
@@ -33,13 +33,13 @@ class De extends Z {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
class
|
|
36
|
+
class H extends Z {
|
|
37
37
|
constructor(a, n) {
|
|
38
38
|
super({
|
|
39
39
|
kind: "ValidationError",
|
|
40
40
|
description: a
|
|
41
41
|
});
|
|
42
|
-
|
|
42
|
+
Y(this, "key");
|
|
43
43
|
this.key = n;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -51,7 +51,7 @@ class Re extends Z {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
var
|
|
54
|
+
var _e = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_e || {}), 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 || {}), Ee = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ee || {}), Ie = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ie || {}), B = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(B || {}), 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 || {}), Te = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Te || {}), je = /* @__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))(je || {}), de = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(de || {});
|
|
55
55
|
const be = (e) => {
|
|
56
56
|
switch (e) {
|
|
57
57
|
case "clip":
|
|
@@ -62,12 +62,12 @@ const be = (e) => {
|
|
|
62
62
|
throw new Error(`Unknown video type: ${e}`);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}),
|
|
66
|
-
const
|
|
65
|
+
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), Q = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Q || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), J = /* @__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))(J || {}), j = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(j || {}), U = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(U || {}), Pe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Pe || {}), Ae = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ae || {});
|
|
66
|
+
const $e = 45 * 1e3, Be = "X-Playground-Chat", O = "https://api.d-id.com", Le = "wss://notifications.d-id.com", ze = "79f81a83a67430be2bc0fd61042b8faa", le = (e) => new Promise((t) => setTimeout(t, e)), V = (e = 16) => {
|
|
67
67
|
const t = new Uint8Array(e);
|
|
68
68
|
return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
69
|
-
},
|
|
70
|
-
function
|
|
69
|
+
}, Ne = (e) => [B.TextOnly, B.Playground, B.Maintenance].includes(e), te = (e) => e && [B.DirectPlayback, B.Off].includes(e);
|
|
70
|
+
function xe(e, t) {
|
|
71
71
|
let a;
|
|
72
72
|
return {
|
|
73
73
|
promise: new Promise((s, i) => {
|
|
@@ -76,7 +76,7 @@ function Ne(e, t) {
|
|
|
76
76
|
clear: () => clearTimeout(a)
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
async function
|
|
79
|
+
async function re(e, t) {
|
|
80
80
|
const a = {
|
|
81
81
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
82
82
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -94,49 +94,49 @@ async function ee(e, t) {
|
|
|
94
94
|
const {
|
|
95
95
|
promise: i,
|
|
96
96
|
clear: o
|
|
97
|
-
} =
|
|
97
|
+
} = xe(a.timeout, a.timeoutErrorMessage), c = e().finally(o);
|
|
98
98
|
return await Promise.race([c, i]);
|
|
99
99
|
} catch (i) {
|
|
100
100
|
if (n = i, !a.shouldRetryFn(i) || s >= a.limit)
|
|
101
101
|
throw i;
|
|
102
|
-
await
|
|
102
|
+
await le(a.delayMs), a.onRetry(i);
|
|
103
103
|
}
|
|
104
104
|
throw n;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
106
|
+
function ue() {
|
|
107
107
|
let e = window.localStorage.getItem("did_external_key_id");
|
|
108
108
|
if (!e) {
|
|
109
|
-
let t =
|
|
109
|
+
let t = V();
|
|
110
110
|
window.localStorage.setItem("did_external_key_id", t), e = t;
|
|
111
111
|
}
|
|
112
112
|
return e;
|
|
113
113
|
}
|
|
114
|
-
let
|
|
115
|
-
function
|
|
114
|
+
let Fe = V();
|
|
115
|
+
function fe(e) {
|
|
116
116
|
if (e.type === "bearer")
|
|
117
117
|
return `Bearer ${e.token}`;
|
|
118
118
|
if (e.type === "basic")
|
|
119
119
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
120
120
|
if (e.type === "key")
|
|
121
|
-
return `Client-Key ${e.clientKey}.${
|
|
121
|
+
return `Client-Key ${e.clientKey}.${ue()}_${Fe}`;
|
|
122
122
|
throw new Error(`Unknown auth type: ${e}`);
|
|
123
123
|
}
|
|
124
|
-
const
|
|
124
|
+
const Je = (e) => re(e, {
|
|
125
125
|
limit: 3,
|
|
126
126
|
delayMs: 1e3,
|
|
127
127
|
timeout: 0,
|
|
128
128
|
shouldRetryFn: (t) => t.status === 429
|
|
129
129
|
});
|
|
130
|
-
function
|
|
130
|
+
function ie(e, t = O, a) {
|
|
131
131
|
const n = async (s, i) => {
|
|
132
132
|
const {
|
|
133
133
|
skipErrorHandler: o,
|
|
134
134
|
...c
|
|
135
|
-
} = i || {}, r = await
|
|
135
|
+
} = i || {}, r = await Je(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
136
136
|
...c,
|
|
137
137
|
headers: {
|
|
138
138
|
...c.headers,
|
|
139
|
-
Authorization:
|
|
139
|
+
Authorization: fe(e),
|
|
140
140
|
"Content-Type": "application/json"
|
|
141
141
|
}
|
|
142
142
|
}));
|
|
@@ -181,8 +181,8 @@ function ne(e, t = Q, a) {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
function
|
|
185
|
-
const n =
|
|
184
|
+
function me(e, t = O, a) {
|
|
185
|
+
const n = ie(e, `${t}/agents`, a);
|
|
186
186
|
return {
|
|
187
187
|
create(s, i) {
|
|
188
188
|
return n.post("/", s, i);
|
|
@@ -219,8 +219,8 @@ function fe(e, t = Q, a) {
|
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
-
const
|
|
223
|
-
function
|
|
222
|
+
const ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
223
|
+
function We(e) {
|
|
224
224
|
var s, i, o, c;
|
|
225
225
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
|
|
226
226
|
const r = navigator.platform;
|
|
@@ -231,15 +231,15 @@ function Je(e) {
|
|
|
231
231
|
isMobile: `${t() == "Mobile"}`,
|
|
232
232
|
browser: navigator.userAgent,
|
|
233
233
|
origin: window.location.origin,
|
|
234
|
-
agentType:
|
|
234
|
+
agentType: ge(n),
|
|
235
235
|
agentVoice: {
|
|
236
236
|
voiceId: (i = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : i.voice_id,
|
|
237
237
|
provider: (c = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : c.type
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
|
-
const
|
|
242
|
-
function
|
|
241
|
+
const Ue = (e) => e.reduce((t, a) => t + a, 0), se = (e) => Ue(e) / e.length;
|
|
242
|
+
function Ke(e, t, a) {
|
|
243
243
|
var r, l, d;
|
|
244
244
|
const {
|
|
245
245
|
event: n,
|
|
@@ -267,14 +267,14 @@ function Ue(e, t, a) {
|
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
let G = {};
|
|
270
|
-
const
|
|
271
|
-
function
|
|
270
|
+
const He = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
271
|
+
function qe(e) {
|
|
272
272
|
var i, o, c, r, l, d;
|
|
273
273
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter, n = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, s = {
|
|
274
274
|
token: e.token || "testKey",
|
|
275
|
-
distinct_id: e.distinctId ||
|
|
275
|
+
distinct_id: e.distinctId || ue(),
|
|
276
276
|
agentId: e.agent.id,
|
|
277
|
-
agentType:
|
|
277
|
+
agentType: ge(a),
|
|
278
278
|
owner_id: e.agent.owner_id ?? "",
|
|
279
279
|
promptVersion: (o = e.agent.llm) == null ? void 0 : o.prompt_version,
|
|
280
280
|
behavior: {
|
|
@@ -292,20 +292,20 @@ function He(e) {
|
|
|
292
292
|
...s,
|
|
293
293
|
additionalProperties: {},
|
|
294
294
|
isEnabled: e.isEnabled ?? !0,
|
|
295
|
-
getRandom:
|
|
295
|
+
getRandom: V,
|
|
296
296
|
enrich(f) {
|
|
297
297
|
this.additionalProperties = {
|
|
298
298
|
...this.additionalProperties,
|
|
299
299
|
...f
|
|
300
300
|
};
|
|
301
301
|
},
|
|
302
|
-
async track(f,
|
|
302
|
+
async track(f, A) {
|
|
303
303
|
if (!this.isEnabled)
|
|
304
304
|
return Promise.resolve();
|
|
305
305
|
const {
|
|
306
|
-
audioPath:
|
|
306
|
+
audioPath: I,
|
|
307
307
|
..._
|
|
308
|
-
} =
|
|
308
|
+
} = A || {}, D = {
|
|
309
309
|
method: "POST",
|
|
310
310
|
headers: {
|
|
311
311
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -329,32 +329,32 @@ function He(e) {
|
|
|
329
329
|
})
|
|
330
330
|
};
|
|
331
331
|
try {
|
|
332
|
-
return await fetch(
|
|
333
|
-
} catch (
|
|
334
|
-
return console.error(
|
|
332
|
+
return await fetch(He, D).then((v) => v.json());
|
|
333
|
+
} catch (v) {
|
|
334
|
+
return console.error(v);
|
|
335
335
|
}
|
|
336
336
|
},
|
|
337
|
-
linkTrack(f,
|
|
337
|
+
linkTrack(f, A, I, _) {
|
|
338
338
|
G[f] || (G[f] = {
|
|
339
339
|
events: {},
|
|
340
340
|
resolvedDependencies: []
|
|
341
|
-
}), _.includes(
|
|
342
|
-
const
|
|
343
|
-
if (
|
|
344
|
-
props:
|
|
345
|
-
},
|
|
346
|
-
const N = _.reduce((L,
|
|
341
|
+
}), _.includes(I) || _.push(I);
|
|
342
|
+
const D = G[f];
|
|
343
|
+
if (D.events[I] = {
|
|
344
|
+
props: A
|
|
345
|
+
}, D.resolvedDependencies.push(I), _.every((N) => D.resolvedDependencies.includes(N))) {
|
|
346
|
+
const N = _.reduce((L, b) => D.events[b] ? {
|
|
347
347
|
...L,
|
|
348
|
-
...
|
|
348
|
+
...D.events[b].props
|
|
349
349
|
} : L, {});
|
|
350
|
-
this.track(f, N),
|
|
351
|
-
delete
|
|
350
|
+
this.track(f, N), D.resolvedDependencies = D.resolvedDependencies.filter((L) => !_.includes(L)), _.forEach((L) => {
|
|
351
|
+
delete D.events[L];
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
|
-
function
|
|
357
|
+
function he() {
|
|
358
358
|
let e = 0;
|
|
359
359
|
return {
|
|
360
360
|
reset: () => e = 0,
|
|
@@ -362,19 +362,19 @@ function ge() {
|
|
|
362
362
|
get: (t = !1) => t ? Date.now() - e : e
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
-
const
|
|
366
|
-
function
|
|
367
|
-
return e ===
|
|
365
|
+
const F = he(), ne = he();
|
|
366
|
+
function we(e) {
|
|
367
|
+
return e === B.Playground ? {
|
|
368
368
|
headers: {
|
|
369
369
|
[Be]: "true"
|
|
370
370
|
}
|
|
371
371
|
} : {};
|
|
372
372
|
}
|
|
373
|
-
async function
|
|
373
|
+
async function pe(e, t, a, n, s = !1, i) {
|
|
374
374
|
try {
|
|
375
|
-
return !i && n
|
|
375
|
+
return !i && !te(n) && (i = await t.newChat(e.id, {
|
|
376
376
|
persist: s
|
|
377
|
-
},
|
|
377
|
+
}, we(n)), a.track("agent-chat", {
|
|
378
378
|
event: "created",
|
|
379
379
|
chat_id: i.id,
|
|
380
380
|
agent_id: e.id,
|
|
@@ -394,28 +394,28 @@ async function we(e, t, a, n, s = !1, i) {
|
|
|
394
394
|
throw new Error("Cannot create new chat");
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
|
-
function
|
|
397
|
+
function Ve(e) {
|
|
398
398
|
return e && e.length > 0 ? e : [];
|
|
399
399
|
}
|
|
400
|
-
function
|
|
401
|
-
if (!e
|
|
400
|
+
function Xe(e, t, a, n) {
|
|
401
|
+
if (!e)
|
|
402
402
|
throw new Error("Please connect to the agent first");
|
|
403
403
|
if (!e.interruptAvailable)
|
|
404
404
|
throw new Error("Interrupt is not enabled for this stream");
|
|
405
|
-
if (
|
|
405
|
+
if (t !== U.Fluent)
|
|
406
406
|
throw new Error("Interrupt only available for Fluent streams");
|
|
407
|
-
if (!
|
|
407
|
+
if (!a && !n)
|
|
408
408
|
throw new Error("No active video to interrupt");
|
|
409
409
|
}
|
|
410
|
-
async function
|
|
410
|
+
async function ee(e, t) {
|
|
411
411
|
const a = {
|
|
412
|
-
type:
|
|
412
|
+
type: J.StreamInterrupt,
|
|
413
413
|
videoId: t,
|
|
414
414
|
timestamp: Date.now()
|
|
415
415
|
};
|
|
416
416
|
e.sendDataChannelMessage(JSON.stringify(a));
|
|
417
417
|
}
|
|
418
|
-
function
|
|
418
|
+
function Ye(e) {
|
|
419
419
|
return new Promise((t, a) => {
|
|
420
420
|
const {
|
|
421
421
|
callbacks: n,
|
|
@@ -426,7 +426,7 @@ function Xe(e) {
|
|
|
426
426
|
onOpen: c = null,
|
|
427
427
|
onClose: r = null,
|
|
428
428
|
onError: l = null
|
|
429
|
-
} = n || {}, d = new WebSocket(`${s}?authorization=${
|
|
429
|
+
} = n || {}, d = new WebSocket(`${s}?authorization=${fe(i)}`);
|
|
430
430
|
d.onmessage = o, d.onclose = r, d.onerror = (f) => {
|
|
431
431
|
console.error(f), l == null || l("Websocket failed to connect", f), a(f);
|
|
432
432
|
}, d.onopen = (f) => {
|
|
@@ -434,23 +434,23 @@ function Xe(e) {
|
|
|
434
434
|
};
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
|
-
async function
|
|
437
|
+
async function Qe(e) {
|
|
438
438
|
const {
|
|
439
439
|
retries: t = 1
|
|
440
440
|
} = e;
|
|
441
441
|
let a = null;
|
|
442
442
|
for (let n = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; n++)
|
|
443
443
|
try {
|
|
444
|
-
a = await
|
|
444
|
+
a = await Ye(e);
|
|
445
445
|
} catch (s) {
|
|
446
446
|
if (n === t)
|
|
447
447
|
throw s;
|
|
448
|
-
await
|
|
448
|
+
await le(n * 500);
|
|
449
449
|
}
|
|
450
450
|
return a;
|
|
451
451
|
}
|
|
452
|
-
async function
|
|
453
|
-
const n = a != null && a.onMessage ? [a.onMessage] : [], s = await
|
|
452
|
+
async function Oe(e, t, a) {
|
|
453
|
+
const n = a != null && a.onMessage ? [a.onMessage] : [], s = await Qe({
|
|
454
454
|
auth: e,
|
|
455
455
|
host: t,
|
|
456
456
|
callbacks: {
|
|
@@ -480,52 +480,52 @@ function Ze(e) {
|
|
|
480
480
|
}
|
|
481
481
|
function Ge(e, t, a, n, s) {
|
|
482
482
|
const i = n.messages[n.messages.length - 1];
|
|
483
|
-
if (!(e ===
|
|
483
|
+
if (!(e === q.Partial || e === q.Answer) || (i == null ? void 0 : i.role) !== "assistant")
|
|
484
484
|
return;
|
|
485
485
|
const {
|
|
486
486
|
content: o,
|
|
487
487
|
sequence: c
|
|
488
488
|
} = t;
|
|
489
|
-
e ===
|
|
489
|
+
e === q.Partial ? a[c] = o : a.answer = o;
|
|
490
490
|
const r = Ze(a);
|
|
491
|
-
(i.content !== r || e ===
|
|
491
|
+
(i.content !== r || e === q.Answer) && (i.content = r, s == null || s([...n.messages], e));
|
|
492
492
|
}
|
|
493
|
-
function
|
|
493
|
+
function et(e, t, a, n, s) {
|
|
494
494
|
let i = {};
|
|
495
495
|
return {
|
|
496
496
|
clearQueue: () => i = {},
|
|
497
497
|
onMessage: (o, c) => {
|
|
498
498
|
var r, l;
|
|
499
499
|
if ("content" in c)
|
|
500
|
-
Ge(o, c, i, t, a.callbacks.onNewMessage), o ===
|
|
500
|
+
Ge(o, c, i, t, a.callbacks.onNewMessage), o === q.Answer && e.track("agent-message-received", {
|
|
501
501
|
messages: t.messages.length,
|
|
502
502
|
mode: t.chatMode
|
|
503
503
|
});
|
|
504
504
|
else {
|
|
505
|
-
const d =
|
|
505
|
+
const d = J, f = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], A = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], I = Ke(c, n, {
|
|
506
506
|
mode: t.chatMode
|
|
507
507
|
});
|
|
508
508
|
if (o = o, o === d.StreamVideoCreated)
|
|
509
|
-
e.linkTrack("agent-video",
|
|
509
|
+
e.linkTrack("agent-video", I, d.StreamVideoCreated, ["start"]);
|
|
510
510
|
else if (f.includes(o)) {
|
|
511
511
|
const _ = o.split("/")[1];
|
|
512
|
-
|
|
513
|
-
...
|
|
512
|
+
A.includes(o) ? e.track("agent-video", {
|
|
513
|
+
...I,
|
|
514
514
|
event: _
|
|
515
515
|
}) : e.linkTrack("agent-video", {
|
|
516
|
-
...
|
|
516
|
+
...I,
|
|
517
517
|
event: _
|
|
518
518
|
}, o, ["done"]);
|
|
519
519
|
}
|
|
520
|
-
|
|
520
|
+
A.includes(o) && ((l = (r = a.callbacks).onError) == null || l.call(r, new Error(`Stream failed with event ${o}`), {
|
|
521
521
|
data: c
|
|
522
522
|
})), c.event === d.StreamDone && s();
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
};
|
|
526
526
|
}
|
|
527
|
-
function
|
|
528
|
-
const s =
|
|
527
|
+
function tt(e, t, a, n) {
|
|
528
|
+
const s = ie(e, `${t}/agents/${a}`, n);
|
|
529
529
|
return {
|
|
530
530
|
createStream(i) {
|
|
531
531
|
return s.post("/streams", {
|
|
@@ -561,8 +561,8 @@ function et(e, t, a, n) {
|
|
|
561
561
|
}
|
|
562
562
|
};
|
|
563
563
|
}
|
|
564
|
-
function
|
|
565
|
-
const s =
|
|
564
|
+
function rt(e, t, a, n) {
|
|
565
|
+
const s = ie(e, `${t}/agents/${a}`, n);
|
|
566
566
|
return {
|
|
567
567
|
createStream(i, o) {
|
|
568
568
|
return s.post("/streams", {
|
|
@@ -601,7 +601,7 @@ function tt(e, t, a, n) {
|
|
|
601
601
|
}
|
|
602
602
|
};
|
|
603
603
|
}
|
|
604
|
-
function
|
|
604
|
+
function nt(e, t, a) {
|
|
605
605
|
const n = (t.timestamp - e.timestamp) / 1e3;
|
|
606
606
|
return {
|
|
607
607
|
duration: n,
|
|
@@ -621,7 +621,7 @@ function rt(e, t, a) {
|
|
|
621
621
|
lowFpsCount: a
|
|
622
622
|
};
|
|
623
623
|
}
|
|
624
|
-
function
|
|
624
|
+
function at(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
627
|
timestamp: a,
|
|
@@ -633,7 +633,7 @@ function nt(e) {
|
|
|
633
633
|
};
|
|
634
634
|
});
|
|
635
635
|
}
|
|
636
|
-
function
|
|
636
|
+
function it(e) {
|
|
637
637
|
let t = "", a = 0;
|
|
638
638
|
for (const n of e.values())
|
|
639
639
|
if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair" && (a = n.currentRoundTripTime), n && n.type === "inbound-rtp" && n.kind === "video")
|
|
@@ -658,7 +658,7 @@ function at(e) {
|
|
|
658
658
|
};
|
|
659
659
|
return {};
|
|
660
660
|
}
|
|
661
|
-
function
|
|
661
|
+
function st(e, t, a) {
|
|
662
662
|
const n = e.map((r, l) => l === 0 ? a ? {
|
|
663
663
|
timestamp: r.timestamp,
|
|
664
664
|
duration: 0,
|
|
@@ -710,24 +710,24 @@ function it(e, t, a) {
|
|
|
710
710
|
framesPerSecond: r.framesPerSecond,
|
|
711
711
|
freezeCount: r.freezeCount - e[l - 1].freezeCount,
|
|
712
712
|
freezeDuration: r.freezeDuration - e[l - 1].freezeDuration
|
|
713
|
-
}), s =
|
|
713
|
+
}), s = at(n), i = s.reduce((r, l) => r + (l.causes.includes("low fps") ? 1 : 0), 0), o = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), c = n.filter((r) => !!r.rtt).map((r) => r.rtt);
|
|
714
714
|
return {
|
|
715
715
|
webRTCStats: {
|
|
716
716
|
anomalies: s,
|
|
717
717
|
minRtt: Math.min(...c),
|
|
718
|
-
avgRtt:
|
|
718
|
+
avgRtt: se(c),
|
|
719
719
|
maxRtt: Math.max(...c),
|
|
720
|
-
aggregateReport:
|
|
720
|
+
aggregateReport: nt(e[0], e[e.length - 1], i),
|
|
721
721
|
minJitterDelayInInterval: Math.min(...o),
|
|
722
722
|
maxJitterDelayInInterval: Math.max(...o),
|
|
723
|
-
avgJitterDelayInInterval:
|
|
723
|
+
avgJitterDelayInInterval: se(o)
|
|
724
724
|
},
|
|
725
725
|
codec: e[0].codec,
|
|
726
726
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
727
727
|
};
|
|
728
728
|
}
|
|
729
|
-
const
|
|
730
|
-
function
|
|
729
|
+
const ae = 100, ot = Math.max(Math.ceil(400 / ae), 1), ct = 0.25, dt = 0.28;
|
|
730
|
+
function lt() {
|
|
731
731
|
let e = 0, t, a, n = 0;
|
|
732
732
|
return (s) => {
|
|
733
733
|
for (const i of s.values())
|
|
@@ -751,26 +751,26 @@ function dt() {
|
|
|
751
751
|
};
|
|
752
752
|
};
|
|
753
753
|
}
|
|
754
|
-
function
|
|
755
|
-
let o = [], c, r = 0, l = !1, d =
|
|
756
|
-
const _ =
|
|
754
|
+
function ut(e, t, a, n, s, i = !1) {
|
|
755
|
+
let o = [], c, r = 0, l = !1, d = Q.Unknown, f = Q.Unknown, A = 0, I = 0;
|
|
756
|
+
const _ = lt();
|
|
757
757
|
return setInterval(async () => {
|
|
758
|
-
const
|
|
759
|
-
isReceiving:
|
|
758
|
+
const D = await e.getStats(), {
|
|
759
|
+
isReceiving: v,
|
|
760
760
|
avgJitterDelayInInterval: N,
|
|
761
761
|
freezeCount: L
|
|
762
|
-
} = _(
|
|
763
|
-
if (
|
|
764
|
-
r = 0,
|
|
765
|
-
else if (l && (r++, r >=
|
|
766
|
-
const u =
|
|
767
|
-
n == null || n(p.Stop, u), t() || a(),
|
|
762
|
+
} = _(D), b = it(D);
|
|
763
|
+
if (v)
|
|
764
|
+
r = 0, A = L - I, f = N < ct ? Q.Strong : N > dt && A > 1 ? Q.Weak : d, f !== d && (s == null || s(f), d = f, I += A, A = 0), l || (n == null || n(p.Start), c = o[o.length - 1], o = [], l = !0), o.push(b);
|
|
765
|
+
else if (l && (r++, r >= ot)) {
|
|
766
|
+
const u = st(o, ae, c);
|
|
767
|
+
n == null || n(p.Stop, u), t() || a(), I = L, l = !1;
|
|
768
768
|
}
|
|
769
|
-
},
|
|
769
|
+
}, ae);
|
|
770
770
|
}
|
|
771
|
-
let
|
|
772
|
-
const z = (e, t) =>
|
|
773
|
-
function
|
|
771
|
+
let ye = !1;
|
|
772
|
+
const z = (e, t) => ye && console.log(e, t), ft = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
773
|
+
function oe(e) {
|
|
774
774
|
switch (e) {
|
|
775
775
|
case "connected":
|
|
776
776
|
return j.Connected;
|
|
@@ -790,7 +790,7 @@ function se(e) {
|
|
|
790
790
|
return j.New;
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
|
-
function
|
|
793
|
+
function mt(e) {
|
|
794
794
|
const [t, a = ""] = e.split(/:(.+)/);
|
|
795
795
|
try {
|
|
796
796
|
const n = JSON.parse(a);
|
|
@@ -812,7 +812,7 @@ function ft(e) {
|
|
|
812
812
|
};
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
|
-
function
|
|
815
|
+
function gt({
|
|
816
816
|
statsSignal: e,
|
|
817
817
|
dataChannelSignal: t,
|
|
818
818
|
onVideoStateChange: a,
|
|
@@ -820,16 +820,16 @@ function mt({
|
|
|
820
820
|
}) {
|
|
821
821
|
e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop, n));
|
|
822
822
|
}
|
|
823
|
-
function
|
|
823
|
+
function ht({
|
|
824
824
|
statsSignal: e,
|
|
825
825
|
dataChannelSignal: t,
|
|
826
826
|
onVideoStateChange: a,
|
|
827
827
|
onAgentActivityStateChange: n,
|
|
828
828
|
report: s
|
|
829
829
|
}) {
|
|
830
|
-
e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, s)), t === p.Start ? n == null || n(
|
|
830
|
+
e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, s)), t === p.Start ? n == null || n(X.Talking) : t === p.Stop && (n == null || n(X.Idle));
|
|
831
831
|
}
|
|
832
|
-
function
|
|
832
|
+
function ce({
|
|
833
833
|
statsSignal: e,
|
|
834
834
|
dataChannelSignal: t,
|
|
835
835
|
onVideoStateChange: a,
|
|
@@ -837,12 +837,12 @@ function oe({
|
|
|
837
837
|
streamType: s,
|
|
838
838
|
report: i
|
|
839
839
|
}) {
|
|
840
|
-
s ===
|
|
840
|
+
s === U.Legacy ? gt({
|
|
841
841
|
statsSignal: e,
|
|
842
842
|
dataChannelSignal: t,
|
|
843
843
|
onVideoStateChange: a,
|
|
844
844
|
report: i
|
|
845
|
-
}) : s ===
|
|
845
|
+
}) : s === U.Fluent && ht({
|
|
846
846
|
statsSignal: e,
|
|
847
847
|
dataChannelSignal: t,
|
|
848
848
|
onVideoStateChange: a,
|
|
@@ -850,172 +850,179 @@ function oe({
|
|
|
850
850
|
report: i
|
|
851
851
|
});
|
|
852
852
|
}
|
|
853
|
-
async function
|
|
853
|
+
async function wt(e, t, {
|
|
854
854
|
debug: a = !1,
|
|
855
855
|
callbacks: n,
|
|
856
856
|
auth: s,
|
|
857
|
-
baseURL: i =
|
|
857
|
+
baseURL: i = O,
|
|
858
858
|
analytics: o
|
|
859
859
|
}) {
|
|
860
|
-
|
|
860
|
+
var x;
|
|
861
|
+
ye = a;
|
|
861
862
|
let c = !1, r = !1, l = p.Stop, d = p.Stop;
|
|
862
863
|
const {
|
|
863
864
|
startConnection: f,
|
|
864
|
-
sendStreamRequest:
|
|
865
|
-
close:
|
|
865
|
+
sendStreamRequest: A,
|
|
866
|
+
close: I,
|
|
866
867
|
createStream: _,
|
|
867
|
-
addIceCandidate:
|
|
868
|
-
} = t.videoType ===
|
|
869
|
-
id:
|
|
868
|
+
addIceCandidate: D
|
|
869
|
+
} = t.videoType === de.Clip ? tt(s, i, e, n.onError) : rt(s, i, e, n.onError), {
|
|
870
|
+
id: v,
|
|
870
871
|
offer: N,
|
|
871
872
|
ice_servers: L,
|
|
872
|
-
session_id:
|
|
873
|
+
session_id: b,
|
|
873
874
|
fluent: u,
|
|
874
875
|
interrupt_enabled: w
|
|
875
|
-
} = await _(t)
|
|
876
|
+
} = await _(t);
|
|
877
|
+
(x = n.onStreamCreated) == null || x.call(n, {
|
|
878
|
+
stream_id: v,
|
|
879
|
+
session_id: b,
|
|
880
|
+
agent_id: e
|
|
881
|
+
});
|
|
882
|
+
const g = new ft({
|
|
876
883
|
iceServers: L
|
|
877
884
|
}), S = g.createDataChannel("JanusDataChannel");
|
|
878
|
-
if (
|
|
885
|
+
if (!b)
|
|
879
886
|
throw new Error("Could not create session_id");
|
|
880
|
-
const
|
|
887
|
+
const C = u ? U.Fluent : U.Legacy;
|
|
881
888
|
o.enrich({
|
|
882
|
-
"stream-type":
|
|
889
|
+
"stream-type": C
|
|
883
890
|
});
|
|
884
|
-
const
|
|
891
|
+
const k = t.stream_warmup && !u, P = () => c, M = () => {
|
|
885
892
|
var m;
|
|
886
893
|
c = !0, r && ((m = n.onConnectionStateChange) == null || m.call(n, j.Connected));
|
|
887
|
-
},
|
|
894
|
+
}, T = ut(g, P, M, (m, h) => ce({
|
|
888
895
|
statsSignal: d = m,
|
|
889
|
-
dataChannelSignal:
|
|
896
|
+
dataChannelSignal: C === U.Legacy ? l : void 0,
|
|
890
897
|
onVideoStateChange: n.onVideoStateChange,
|
|
891
898
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
892
899
|
report: h,
|
|
893
|
-
streamType:
|
|
900
|
+
streamType: C
|
|
894
901
|
}), (m) => {
|
|
895
902
|
var h;
|
|
896
903
|
return (h = n.onConnectivityStateChange) == null ? void 0 : h.call(n, m);
|
|
897
|
-
},
|
|
904
|
+
}, k);
|
|
898
905
|
g.onicecandidate = (m) => {
|
|
899
906
|
var h;
|
|
900
907
|
z("peerConnection.onicecandidate", m);
|
|
901
908
|
try {
|
|
902
|
-
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ?
|
|
909
|
+
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? D(v, {
|
|
903
910
|
candidate: m.candidate.candidate,
|
|
904
911
|
sdpMid: m.candidate.sdpMid,
|
|
905
912
|
sdpMLineIndex: m.candidate.sdpMLineIndex
|
|
906
|
-
},
|
|
913
|
+
}, b) : D(v, {
|
|
907
914
|
candidate: null
|
|
908
|
-
},
|
|
909
|
-
} catch (
|
|
910
|
-
(h = n.onError) == null || h.call(n,
|
|
911
|
-
streamId:
|
|
915
|
+
}, b);
|
|
916
|
+
} catch ($) {
|
|
917
|
+
(h = n.onError) == null || h.call(n, $, {
|
|
918
|
+
streamId: v
|
|
912
919
|
});
|
|
913
920
|
}
|
|
914
921
|
}, S.onopen = () => {
|
|
915
|
-
r = !0, (!
|
|
922
|
+
r = !0, (!k || c) && M();
|
|
916
923
|
};
|
|
917
924
|
function y(m) {
|
|
918
|
-
l = m ===
|
|
919
|
-
statsSignal:
|
|
925
|
+
l = m === J.StreamStarted ? p.Start : p.Stop, ce({
|
|
926
|
+
statsSignal: C === U.Legacy ? d : void 0,
|
|
920
927
|
dataChannelSignal: l,
|
|
921
928
|
onVideoStateChange: n.onVideoStateChange,
|
|
922
929
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
923
|
-
streamType:
|
|
930
|
+
streamType: C
|
|
924
931
|
});
|
|
925
932
|
}
|
|
926
|
-
function
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
streamMetadata:
|
|
933
|
+
function E(m, h) {
|
|
934
|
+
const $ = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
|
|
935
|
+
$ && o.enrich({
|
|
936
|
+
streamMetadata: $
|
|
930
937
|
}), o.track("agent-chat", {
|
|
931
938
|
event: "ready"
|
|
932
939
|
});
|
|
933
940
|
}
|
|
934
|
-
const
|
|
935
|
-
[
|
|
936
|
-
[
|
|
937
|
-
[
|
|
941
|
+
const R = {
|
|
942
|
+
[J.StreamStarted]: y,
|
|
943
|
+
[J.StreamDone]: y,
|
|
944
|
+
[J.StreamReady]: E
|
|
938
945
|
};
|
|
939
946
|
S.onmessage = (m) => {
|
|
940
|
-
var
|
|
947
|
+
var K;
|
|
941
948
|
const {
|
|
942
949
|
subject: h,
|
|
943
|
-
data:
|
|
944
|
-
} =
|
|
945
|
-
(
|
|
950
|
+
data: $
|
|
951
|
+
} = mt(m.data);
|
|
952
|
+
(K = R[h]) == null || K.call(R, h, $);
|
|
946
953
|
}, g.oniceconnectionstatechange = () => {
|
|
947
954
|
var h;
|
|
948
955
|
z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
949
|
-
const m =
|
|
956
|
+
const m = oe(g.iceConnectionState);
|
|
950
957
|
m !== j.Connected && ((h = n.onConnectionStateChange) == null || h.call(n, m));
|
|
951
958
|
}, g.ontrack = (m) => {
|
|
952
959
|
var h;
|
|
953
960
|
z("peerConnection.ontrack", m), (h = n.onSrcObjectReady) == null || h.call(n, m.streams[0]);
|
|
954
961
|
}, await g.setRemoteDescription(N), z("set remote description OK");
|
|
955
|
-
const
|
|
956
|
-
return z("create answer OK"), await g.setLocalDescription(
|
|
962
|
+
const W = await g.createAnswer();
|
|
963
|
+
return z("create answer OK"), await g.setLocalDescription(W), z("set local description OK"), await f(v, W, b), z("start connection OK"), {
|
|
957
964
|
/**
|
|
958
965
|
* Method to send request to server to get clip or talk depend on you payload
|
|
959
966
|
* @param payload
|
|
960
967
|
*/
|
|
961
968
|
speak(m) {
|
|
962
|
-
return
|
|
969
|
+
return A(v, b, m);
|
|
963
970
|
},
|
|
964
971
|
/**
|
|
965
972
|
* Method to close RTC connection
|
|
966
973
|
*/
|
|
967
974
|
async disconnect() {
|
|
968
975
|
var m;
|
|
969
|
-
if (
|
|
970
|
-
const h =
|
|
976
|
+
if (v) {
|
|
977
|
+
const h = oe(g.iceConnectionState);
|
|
971
978
|
if (g) {
|
|
972
979
|
if (h === j.New) {
|
|
973
|
-
clearInterval(
|
|
980
|
+
clearInterval(T);
|
|
974
981
|
return;
|
|
975
982
|
}
|
|
976
983
|
g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
|
|
977
984
|
}
|
|
978
985
|
try {
|
|
979
|
-
h === j.Connected && await
|
|
986
|
+
h === j.Connected && await I(v, b).catch(($) => {
|
|
980
987
|
});
|
|
981
|
-
} catch (
|
|
982
|
-
z("Error on close stream connection",
|
|
988
|
+
} catch ($) {
|
|
989
|
+
z("Error on close stream connection", $);
|
|
983
990
|
}
|
|
984
|
-
(m = n.onAgentActivityStateChange) == null || m.call(n,
|
|
991
|
+
(m = n.onAgentActivityStateChange) == null || m.call(n, X.Idle), clearInterval(T);
|
|
985
992
|
}
|
|
986
993
|
},
|
|
987
994
|
/**
|
|
988
995
|
* Method to send data channel messages to the server
|
|
989
996
|
*/
|
|
990
997
|
sendDataChannelMessage(m) {
|
|
991
|
-
var h,
|
|
998
|
+
var h, $;
|
|
992
999
|
if (!c || S.readyState !== "open") {
|
|
993
1000
|
z("Data channel is not ready for sending messages"), (h = n.onError) == null || h.call(n, new Error("Data channel is not ready for sending messages"), {
|
|
994
|
-
streamId:
|
|
1001
|
+
streamId: v
|
|
995
1002
|
});
|
|
996
1003
|
return;
|
|
997
1004
|
}
|
|
998
1005
|
try {
|
|
999
1006
|
S.send(m);
|
|
1000
|
-
} catch (
|
|
1001
|
-
z("Error sending data channel message",
|
|
1002
|
-
streamId:
|
|
1007
|
+
} catch (K) {
|
|
1008
|
+
z("Error sending data channel message", K), ($ = n.onError) == null || $.call(n, K, {
|
|
1009
|
+
streamId: v
|
|
1003
1010
|
});
|
|
1004
1011
|
}
|
|
1005
1012
|
},
|
|
1006
1013
|
/**
|
|
1007
1014
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1008
1015
|
*/
|
|
1009
|
-
sessionId:
|
|
1016
|
+
sessionId: b,
|
|
1010
1017
|
/**
|
|
1011
1018
|
* Id of current RTC stream
|
|
1012
1019
|
*/
|
|
1013
|
-
streamId:
|
|
1014
|
-
streamType:
|
|
1020
|
+
streamId: v,
|
|
1021
|
+
streamType: C,
|
|
1015
1022
|
interruptAvailable: w
|
|
1016
1023
|
};
|
|
1017
1024
|
}
|
|
1018
|
-
function
|
|
1025
|
+
function pt(e, t) {
|
|
1019
1026
|
const {
|
|
1020
1027
|
streamOptions: a
|
|
1021
1028
|
} = t ?? {};
|
|
@@ -1028,10 +1035,10 @@ function wt(e, t) {
|
|
|
1028
1035
|
fluent: a == null ? void 0 : a.fluent
|
|
1029
1036
|
};
|
|
1030
1037
|
}
|
|
1031
|
-
function pt(e, t, a, n, s) {
|
|
1032
|
-
s === W.Fluent ? yt(e, t, a, n, s) : kt(e, t, a, n, s);
|
|
1033
|
-
}
|
|
1034
1038
|
function yt(e, t, a, n, s) {
|
|
1039
|
+
s === U.Fluent ? vt(e, t, a, n, s) : Dt(e, t, a, n, s);
|
|
1040
|
+
}
|
|
1041
|
+
function vt(e, t, a, n, s) {
|
|
1035
1042
|
e === p.Start ? n.track("stream-session", {
|
|
1036
1043
|
event: "start",
|
|
1037
1044
|
"stream-type": s
|
|
@@ -1043,35 +1050,35 @@ function yt(e, t, a, n, s) {
|
|
|
1043
1050
|
...a
|
|
1044
1051
|
});
|
|
1045
1052
|
}
|
|
1046
|
-
function
|
|
1047
|
-
|
|
1053
|
+
function kt(e, t, a, n) {
|
|
1054
|
+
F.get() <= 0 || (e === p.Start ? a.linkTrack("agent-video", {
|
|
1048
1055
|
event: "start",
|
|
1049
|
-
latency:
|
|
1056
|
+
latency: F.get(!0),
|
|
1050
1057
|
"stream-type": n
|
|
1051
|
-
}, "start", [
|
|
1058
|
+
}, "start", [J.StreamVideoCreated]) : e === p.Stop && a.linkTrack("agent-video", {
|
|
1052
1059
|
event: "stop",
|
|
1053
1060
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1054
1061
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1055
1062
|
"stream-type": n
|
|
1056
|
-
}, "done", [
|
|
1063
|
+
}, "done", [J.StreamVideoDone]));
|
|
1057
1064
|
}
|
|
1058
|
-
function
|
|
1059
|
-
|
|
1065
|
+
function Dt(e, t, a, n, s) {
|
|
1066
|
+
F.get() <= 0 || (e === p.Start ? n.linkTrack("agent-video", {
|
|
1060
1067
|
event: "start",
|
|
1061
|
-
latency:
|
|
1068
|
+
latency: F.get(!0),
|
|
1062
1069
|
"stream-type": s
|
|
1063
|
-
}, "start", [
|
|
1070
|
+
}, "start", [J.StreamVideoCreated]) : e === p.Stop && n.linkTrack("agent-video", {
|
|
1064
1071
|
event: "stop",
|
|
1065
1072
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1066
1073
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1067
1074
|
"stream-type": s,
|
|
1068
1075
|
...a
|
|
1069
|
-
}, "done", [
|
|
1076
|
+
}, "done", [J.StreamVideoDone]));
|
|
1070
1077
|
}
|
|
1071
|
-
function
|
|
1072
|
-
return
|
|
1078
|
+
function Ct(e, t, a) {
|
|
1079
|
+
return F.reset(), new Promise(async (n, s) => {
|
|
1073
1080
|
try {
|
|
1074
|
-
const i = await
|
|
1081
|
+
const i = await wt(e.id, pt(e, t), {
|
|
1075
1082
|
...t,
|
|
1076
1083
|
analytics: a,
|
|
1077
1084
|
callbacks: {
|
|
@@ -1082,11 +1089,11 @@ function Dt(e, t, a) {
|
|
|
1082
1089
|
},
|
|
1083
1090
|
onVideoStateChange: (o, c) => {
|
|
1084
1091
|
var r, l;
|
|
1085
|
-
(l = (r = t.callbacks).onVideoStateChange) == null || l.call(r, o),
|
|
1092
|
+
(l = (r = t.callbacks).onVideoStateChange) == null || l.call(r, o), yt(o, e, c, a, i.streamType);
|
|
1086
1093
|
},
|
|
1087
1094
|
onAgentActivityStateChange: (o) => {
|
|
1088
1095
|
var c, r;
|
|
1089
|
-
(r = (c = t.callbacks).onAgentActivityStateChange) == null || r.call(c, o), o ===
|
|
1096
|
+
(r = (c = t.callbacks).onAgentActivityStateChange) == null || r.call(c, o), o === X.Talking ? ne.update() : ne.reset(), kt(o === X.Talking ? p.Start : p.Stop, e, a, i.streamType);
|
|
1090
1097
|
}
|
|
1091
1098
|
}
|
|
1092
1099
|
});
|
|
@@ -1100,70 +1107,70 @@ async function Rt(e, t, a, n, s) {
|
|
|
1100
1107
|
const {
|
|
1101
1108
|
chat: i,
|
|
1102
1109
|
chatMode: o
|
|
1103
|
-
} = await
|
|
1104
|
-
if (o && o !== t.mode && (t.mode = o, (l = (r = t.callbacks).onModeChange) == null || l.call(r, o), o ===
|
|
1105
|
-
return (f = (d = t.callbacks).onError) == null || f.call(d, new
|
|
1110
|
+
} = await pe(e, a, n, t.mode, t.persistentChat, s);
|
|
1111
|
+
if (o && o !== t.mode && (t.mode = o, (l = (r = t.callbacks).onModeChange) == null || l.call(r, o), o === B.TextOnly))
|
|
1112
|
+
return (f = (d = t.callbacks).onError) == null || f.call(d, new Ce(o)), {
|
|
1106
1113
|
chat: i
|
|
1107
1114
|
};
|
|
1108
|
-
const c = await
|
|
1115
|
+
const c = await Ct(e, t, n);
|
|
1109
1116
|
return {
|
|
1110
1117
|
chat: i,
|
|
1111
1118
|
streamingManager: c
|
|
1112
1119
|
};
|
|
1113
1120
|
}
|
|
1114
|
-
async function
|
|
1115
|
-
var N, L,
|
|
1121
|
+
async function St(e, t) {
|
|
1122
|
+
var N, L, b;
|
|
1116
1123
|
let a = !0, n = !1, s = !1;
|
|
1117
|
-
const i = t.mixpanelKey ||
|
|
1124
|
+
const i = t.mixpanelKey || ze, o = t.wsURL || Le, c = t.baseURL || O, r = {
|
|
1118
1125
|
messages: [],
|
|
1119
|
-
chatMode: t.mode ||
|
|
1120
|
-
}, l =
|
|
1126
|
+
chatMode: t.mode || B.Functional
|
|
1127
|
+
}, l = me(t.auth, c, t.callbacks.onError), d = await l.getById(e), f = qe({
|
|
1121
1128
|
token: i,
|
|
1122
1129
|
agent: d,
|
|
1123
1130
|
isEnabled: t.enableAnalitics,
|
|
1124
1131
|
distinctId: t.distinctId
|
|
1125
1132
|
}), {
|
|
1126
|
-
onMessage:
|
|
1127
|
-
clearQueue:
|
|
1128
|
-
} =
|
|
1133
|
+
onMessage: A,
|
|
1134
|
+
clearQueue: I
|
|
1135
|
+
} = et(f, r, t, d, () => {
|
|
1129
1136
|
var u;
|
|
1130
1137
|
return (u = r.socketManager) == null ? void 0 : u.disconnect();
|
|
1131
1138
|
});
|
|
1132
|
-
r.messages =
|
|
1139
|
+
r.messages = Ve(t.initialMessages), (L = (N = t.callbacks).onNewMessage) == null || L.call(N, [...r.messages], "answer"), f.track("agent-sdk", {
|
|
1133
1140
|
event: "loaded",
|
|
1134
|
-
...
|
|
1141
|
+
...We(d)
|
|
1135
1142
|
});
|
|
1136
1143
|
async function _(u) {
|
|
1137
|
-
var P,
|
|
1138
|
-
(
|
|
1139
|
-
const w = t.mode
|
|
1140
|
-
onMessage:
|
|
1144
|
+
var P, M, T, y, E, R, W;
|
|
1145
|
+
(M = (P = t.callbacks).onConnectionStateChange) == null || M.call(P, j.Connecting), F.reset(), n = !1, s = !1, u && !a && (delete r.chat, (y = (T = t.callbacks).onNewMessage) == null || y.call(T, [...r.messages], "answer"));
|
|
1146
|
+
const w = te(t.mode) ? Promise.resolve(void 0) : Oe(t.auth, o, {
|
|
1147
|
+
onMessage: A,
|
|
1141
1148
|
onError: t.callbacks.onError
|
|
1142
|
-
}), g =
|
|
1149
|
+
}), g = re(() => Rt(d, t, l, f, r.chat), {
|
|
1143
1150
|
limit: 3,
|
|
1144
|
-
timeout:
|
|
1151
|
+
timeout: $e,
|
|
1145
1152
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1146
1153
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1147
|
-
shouldRetryFn: (
|
|
1154
|
+
shouldRetryFn: (x) => (x == null ? void 0 : x.message) !== "Could not connect" && x.status !== 429,
|
|
1148
1155
|
delayMs: 1e3
|
|
1149
|
-
}).catch((
|
|
1150
|
-
var
|
|
1151
|
-
throw
|
|
1156
|
+
}).catch((x) => {
|
|
1157
|
+
var m, h;
|
|
1158
|
+
throw v(B.Maintenance), (h = (m = t.callbacks).onConnectionStateChange) == null || h.call(m, j.Fail), x;
|
|
1152
1159
|
}), [S, {
|
|
1153
|
-
streamingManager:
|
|
1154
|
-
chat:
|
|
1160
|
+
streamingManager: C,
|
|
1161
|
+
chat: k
|
|
1155
1162
|
}] = await Promise.all([w, g]);
|
|
1156
|
-
|
|
1163
|
+
k && k.id !== ((E = r.chat) == null ? void 0 : E.id) && ((W = (R = t.callbacks).onNewChat) == null || W.call(R, k.id)), r.streamingManager = C, r.socketManager = S, r.chat = k, a = !1, v((k == null ? void 0 : k.chat_mode) ?? t.mode ?? B.Functional);
|
|
1157
1164
|
}
|
|
1158
|
-
async function
|
|
1165
|
+
async function D() {
|
|
1159
1166
|
var u, w, g, S;
|
|
1160
1167
|
(u = r.socketManager) == null || u.disconnect(), await ((w = r.streamingManager) == null ? void 0 : w.disconnect()), n = !1, s = !1, delete r.streamingManager, delete r.socketManager, (S = (g = t.callbacks).onConnectionStateChange) == null || S.call(g, j.Disconnected);
|
|
1161
1168
|
}
|
|
1162
|
-
async function
|
|
1169
|
+
async function v(u) {
|
|
1163
1170
|
var w, g;
|
|
1164
1171
|
u !== r.chatMode && (f.track("agent-mode-change", {
|
|
1165
1172
|
mode: u
|
|
1166
|
-
}), r.chatMode = u, r.chatMode !==
|
|
1173
|
+
}), r.chatMode = u, r.chatMode !== B.Functional && await D(), (g = (w = t.callbacks).onModeChange) == null || g.call(w, u));
|
|
1167
1174
|
}
|
|
1168
1175
|
return {
|
|
1169
1176
|
agent: d,
|
|
@@ -1175,9 +1182,9 @@ async function _t(e, t) {
|
|
|
1175
1182
|
var u;
|
|
1176
1183
|
return ((u = r.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
|
|
1177
1184
|
},
|
|
1178
|
-
starterMessages: ((
|
|
1185
|
+
starterMessages: ((b = d.knowledge) == null ? void 0 : b.starter_message) || [],
|
|
1179
1186
|
getSTTToken: () => l.getSTTToken(d.id),
|
|
1180
|
-
changeMode:
|
|
1187
|
+
changeMode: v,
|
|
1181
1188
|
enrichAnalytics: f.enrich,
|
|
1182
1189
|
async connect() {
|
|
1183
1190
|
var u;
|
|
@@ -1190,7 +1197,7 @@ async function _t(e, t) {
|
|
|
1190
1197
|
},
|
|
1191
1198
|
async reconnect() {
|
|
1192
1199
|
var u;
|
|
1193
|
-
await
|
|
1200
|
+
await D(), await _(!1), f.track("agent-chat", {
|
|
1194
1201
|
event: "reconnect",
|
|
1195
1202
|
chatId: (u = r.chat) == null ? void 0 : u.id,
|
|
1196
1203
|
agentId: d.id,
|
|
@@ -1199,7 +1206,7 @@ async function _t(e, t) {
|
|
|
1199
1206
|
},
|
|
1200
1207
|
async disconnect() {
|
|
1201
1208
|
var u;
|
|
1202
|
-
await
|
|
1209
|
+
await D(), f.track("agent-chat", {
|
|
1203
1210
|
event: "disconnect",
|
|
1204
1211
|
chatId: (u = r.chat) == null ? void 0 : u.id,
|
|
1205
1212
|
agentId: d.id,
|
|
@@ -1207,83 +1214,83 @@ async function _t(e, t) {
|
|
|
1207
1214
|
});
|
|
1208
1215
|
},
|
|
1209
1216
|
async chat(u) {
|
|
1210
|
-
var
|
|
1217
|
+
var C, k, P, M, T;
|
|
1211
1218
|
const w = () => {
|
|
1212
|
-
if (t.mode
|
|
1213
|
-
throw new
|
|
1219
|
+
if (te(t.mode))
|
|
1220
|
+
throw new H(`${t.mode} is enabled, chat is disabled`);
|
|
1214
1221
|
if (u.length >= 800)
|
|
1215
|
-
throw new
|
|
1222
|
+
throw new H("Message cannot be more than 800 characters");
|
|
1216
1223
|
if (u.length === 0)
|
|
1217
|
-
throw new
|
|
1218
|
-
if (r.chatMode ===
|
|
1219
|
-
throw new
|
|
1220
|
-
if (![
|
|
1224
|
+
throw new H("Message cannot be empty");
|
|
1225
|
+
if (r.chatMode === B.Maintenance)
|
|
1226
|
+
throw new H("Chat is in maintenance mode");
|
|
1227
|
+
if (![B.TextOnly, B.Playground].includes(r.chatMode)) {
|
|
1221
1228
|
if (!r.streamingManager)
|
|
1222
|
-
throw new
|
|
1229
|
+
throw new H("Streaming manager is not initialized");
|
|
1223
1230
|
if (!r.chat)
|
|
1224
|
-
throw new
|
|
1231
|
+
throw new H("Chat is not initialized");
|
|
1225
1232
|
}
|
|
1226
1233
|
}, g = async () => {
|
|
1227
|
-
var y,
|
|
1234
|
+
var y, E;
|
|
1228
1235
|
if (!r.chat) {
|
|
1229
|
-
const
|
|
1230
|
-
if (!
|
|
1231
|
-
throw new
|
|
1232
|
-
r.chat =
|
|
1236
|
+
const R = await pe(d, l, f, r.chatMode, t.persistentChat);
|
|
1237
|
+
if (!R.chat)
|
|
1238
|
+
throw new De(r.chatMode, !!t.persistentChat);
|
|
1239
|
+
r.chat = R.chat, (E = (y = t.callbacks).onNewChat) == null || E.call(y, r.chat.id);
|
|
1233
1240
|
}
|
|
1234
1241
|
return r.chat.id;
|
|
1235
|
-
}, S = async (y,
|
|
1236
|
-
var
|
|
1237
|
-
return l.chat(d.id,
|
|
1242
|
+
}, S = async (y, E) => re(() => {
|
|
1243
|
+
var R, W;
|
|
1244
|
+
return l.chat(d.id, E, {
|
|
1238
1245
|
chatMode: r.chatMode,
|
|
1239
|
-
streamId: (
|
|
1240
|
-
sessionId: (
|
|
1246
|
+
streamId: (R = r.streamingManager) == null ? void 0 : R.streamId,
|
|
1247
|
+
sessionId: (W = r.streamingManager) == null ? void 0 : W.sessionId,
|
|
1241
1248
|
messages: y.map(({
|
|
1242
|
-
matches:
|
|
1243
|
-
...
|
|
1244
|
-
}) =>
|
|
1249
|
+
matches: x,
|
|
1250
|
+
...m
|
|
1251
|
+
}) => m)
|
|
1245
1252
|
}, {
|
|
1246
|
-
...
|
|
1253
|
+
...we(r.chatMode),
|
|
1247
1254
|
skipErrorHandler: !0
|
|
1248
1255
|
});
|
|
1249
1256
|
}, {
|
|
1250
1257
|
limit: 2,
|
|
1251
|
-
shouldRetryFn: (
|
|
1252
|
-
var
|
|
1253
|
-
const
|
|
1254
|
-
return !((
|
|
1258
|
+
shouldRetryFn: (R) => {
|
|
1259
|
+
var m, h, $, K;
|
|
1260
|
+
const W = (m = R == null ? void 0 : R.message) == null ? void 0 : m.includes("missing or invalid session_id");
|
|
1261
|
+
return !((h = R == null ? void 0 : R.message) == null ? void 0 : h.includes("Stream Error")) && !W ? ((K = ($ = t.callbacks).onError) == null || K.call($, R), !1) : !0;
|
|
1255
1262
|
},
|
|
1256
1263
|
onRetry: async () => {
|
|
1257
|
-
await
|
|
1264
|
+
await D(), await _(!1);
|
|
1258
1265
|
}
|
|
1259
1266
|
});
|
|
1260
1267
|
try {
|
|
1261
|
-
|
|
1262
|
-
id:
|
|
1268
|
+
I(), w(), r.messages.push({
|
|
1269
|
+
id: V(),
|
|
1263
1270
|
role: "user",
|
|
1264
1271
|
content: u,
|
|
1265
|
-
created_at: new Date(
|
|
1266
|
-
}), (
|
|
1267
|
-
const y = await g(),
|
|
1272
|
+
created_at: new Date(F.update()).toISOString()
|
|
1273
|
+
}), (k = (C = t.callbacks).onNewMessage) == null || k.call(C, [...r.messages], "user");
|
|
1274
|
+
const y = await g(), E = await S([...r.messages], y);
|
|
1268
1275
|
return r.messages.push({
|
|
1269
|
-
id:
|
|
1276
|
+
id: V(),
|
|
1270
1277
|
role: "assistant",
|
|
1271
|
-
content:
|
|
1278
|
+
content: E.result || "",
|
|
1272
1279
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1273
|
-
context:
|
|
1274
|
-
matches:
|
|
1275
|
-
videoId:
|
|
1276
|
-
}), n &&
|
|
1280
|
+
context: E.context,
|
|
1281
|
+
matches: E.matches,
|
|
1282
|
+
videoId: E.videoId
|
|
1283
|
+
}), n && E.videoId && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await ee(r.streamingManager, E.videoId)), f.track("agent-message-send", {
|
|
1277
1284
|
event: "success",
|
|
1278
1285
|
mode: r.chatMode,
|
|
1279
1286
|
messages: r.messages.length + 1
|
|
1280
|
-
}),
|
|
1281
|
-
latency:
|
|
1287
|
+
}), E.result && ((M = (P = t.callbacks).onNewMessage) == null || M.call(P, [...r.messages], "answer"), f.track("agent-message-received", {
|
|
1288
|
+
latency: F.get(!0),
|
|
1282
1289
|
mode: r.chatMode,
|
|
1283
1290
|
messages: r.messages.length
|
|
1284
|
-
})),
|
|
1291
|
+
})), E;
|
|
1285
1292
|
} catch (y) {
|
|
1286
|
-
throw n = !1, ((
|
|
1293
|
+
throw n = !1, ((T = r.messages[r.messages.length - 1]) == null ? void 0 : T.role) === "assistant" && r.messages.pop(), f.track("agent-message-send", {
|
|
1287
1294
|
event: "error",
|
|
1288
1295
|
mode: r.chatMode,
|
|
1289
1296
|
messages: r.messages.length
|
|
@@ -1291,30 +1298,30 @@ async function _t(e, t) {
|
|
|
1291
1298
|
}
|
|
1292
1299
|
},
|
|
1293
1300
|
rate(u, w, g) {
|
|
1294
|
-
var
|
|
1301
|
+
var k, P, M, T;
|
|
1295
1302
|
const S = r.messages.find((y) => y.id === u);
|
|
1296
1303
|
if (r.chat) {
|
|
1297
1304
|
if (!S)
|
|
1298
1305
|
throw new Error("Message not found");
|
|
1299
1306
|
} else
|
|
1300
1307
|
throw new Error("Chat is not initialized");
|
|
1301
|
-
const
|
|
1308
|
+
const C = ((k = S.matches) == null ? void 0 : k.map((y) => [y.document_id, y.id])) ?? [];
|
|
1302
1309
|
return f.track("agent-rate", {
|
|
1303
1310
|
event: g ? "update" : "create",
|
|
1304
1311
|
thumb: w === 1 ? "up" : "down",
|
|
1305
1312
|
knowledge_id: ((P = d.knowledge) == null ? void 0 : P.id) ?? "",
|
|
1306
1313
|
mode: r.chatMode,
|
|
1307
|
-
matches:
|
|
1314
|
+
matches: C,
|
|
1308
1315
|
score: w
|
|
1309
1316
|
}), g ? l.updateRating(d.id, r.chat.id, g, {
|
|
1310
|
-
knowledge_id: ((
|
|
1317
|
+
knowledge_id: ((M = d.knowledge) == null ? void 0 : M.id) ?? "",
|
|
1311
1318
|
message_id: u,
|
|
1312
|
-
matches:
|
|
1319
|
+
matches: C,
|
|
1313
1320
|
score: w
|
|
1314
1321
|
}) : l.createRating(d.id, r.chat.id, {
|
|
1315
|
-
knowledge_id: ((
|
|
1322
|
+
knowledge_id: ((T = d.knowledge) == null ? void 0 : T.id) ?? "",
|
|
1316
1323
|
message_id: u,
|
|
1317
|
-
matches:
|
|
1324
|
+
matches: C,
|
|
1318
1325
|
score: w
|
|
1319
1326
|
});
|
|
1320
1327
|
},
|
|
@@ -1330,7 +1337,7 @@ async function _t(e, t) {
|
|
|
1330
1337
|
}), l.deleteRating(d.id, r.chat.id, u);
|
|
1331
1338
|
},
|
|
1332
1339
|
async speak(u) {
|
|
1333
|
-
var
|
|
1340
|
+
var C, k, P, M, T;
|
|
1334
1341
|
function w() {
|
|
1335
1342
|
if (typeof u == "string") {
|
|
1336
1343
|
if (!d.presenter.voice)
|
|
@@ -1355,12 +1362,12 @@ async function _t(e, t) {
|
|
|
1355
1362
|
return u;
|
|
1356
1363
|
}
|
|
1357
1364
|
const g = w();
|
|
1358
|
-
if (f.track("agent-speak", g),
|
|
1359
|
-
id:
|
|
1365
|
+
if (f.track("agent-speak", g), F.update(), r.messages && g.type === "text" && (r.messages.push({
|
|
1366
|
+
id: V(),
|
|
1360
1367
|
role: "assistant",
|
|
1361
1368
|
content: g.input,
|
|
1362
|
-
created_at: new Date(
|
|
1363
|
-
}), (
|
|
1369
|
+
created_at: new Date(F.get(!0)).toISOString()
|
|
1370
|
+
}), (k = (C = t.callbacks).onNewMessage) == null || k.call(C, [...r.messages], "answer")), Ne(r.chatMode))
|
|
1364
1371
|
return {
|
|
1365
1372
|
duration: 0,
|
|
1366
1373
|
video_id: "",
|
|
@@ -1377,7 +1384,7 @@ async function _t(e, t) {
|
|
|
1377
1384
|
agent_id: d.id
|
|
1378
1385
|
}
|
|
1379
1386
|
});
|
|
1380
|
-
return s = !1, r.messages[r.messages.length - 1].videoId = y.video_id, n && y.video_id && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await
|
|
1387
|
+
return s = !1, r.messages[r.messages.length - 1].videoId = y.video_id, n && y.video_id && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await ee(r.streamingManager, y.video_id)), (T = (M = t.callbacks).onNewMessage) == null || T.call(M, [...r.messages], "answer"), y;
|
|
1381
1388
|
} finally {
|
|
1382
1389
|
s = !1;
|
|
1383
1390
|
}
|
|
@@ -1385,15 +1392,15 @@ async function _t(e, t) {
|
|
|
1385
1392
|
async interrupt({
|
|
1386
1393
|
type: u
|
|
1387
1394
|
}) {
|
|
1388
|
-
var
|
|
1395
|
+
var C, k, P, M, T;
|
|
1389
1396
|
const w = r.messages[r.messages.length - 1], g = (w == null ? void 0 : w.role) === "user", S = g || s;
|
|
1390
|
-
if (
|
|
1397
|
+
if (Xe(r.streamingManager, (C = r.streamingManager) == null ? void 0 : C.streamType, S, !!(w != null && w.videoId)), f.track("agent-video-interrupt", {
|
|
1391
1398
|
type: u || "click",
|
|
1392
|
-
stream_id: (
|
|
1399
|
+
stream_id: (k = r.streamingManager) == null ? void 0 : k.streamId,
|
|
1393
1400
|
agent_id: d.id,
|
|
1394
1401
|
owner_id: d.owner_id,
|
|
1395
|
-
video_duration_to_interrupt:
|
|
1396
|
-
message_duration_to_interrupt:
|
|
1402
|
+
video_duration_to_interrupt: ne.get(!0),
|
|
1403
|
+
message_duration_to_interrupt: F.get(!0),
|
|
1397
1404
|
chat_id: (P = r.chat) == null ? void 0 : P.id,
|
|
1398
1405
|
mode: r.chatMode,
|
|
1399
1406
|
queued_interrupt: g
|
|
@@ -1401,40 +1408,40 @@ async function _t(e, t) {
|
|
|
1401
1408
|
n = !0;
|
|
1402
1409
|
return;
|
|
1403
1410
|
}
|
|
1404
|
-
w.interrupted = !0, (
|
|
1411
|
+
w.interrupted = !0, (T = (M = t.callbacks).onNewMessage) == null || T.call(M, [...r.messages], "answer"), ee(r.streamingManager, w.videoId);
|
|
1405
1412
|
}
|
|
1406
1413
|
};
|
|
1407
1414
|
}
|
|
1408
|
-
function
|
|
1415
|
+
function Et(e, t, a) {
|
|
1409
1416
|
const {
|
|
1410
1417
|
getById: n
|
|
1411
|
-
} =
|
|
1418
|
+
} = me(t, a || O);
|
|
1412
1419
|
return n(e);
|
|
1413
1420
|
}
|
|
1414
1421
|
export {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1422
|
+
X as AgentActivityState,
|
|
1423
|
+
Ee as AgentStatus,
|
|
1424
|
+
De as ChatCreationFailed,
|
|
1425
|
+
B as ChatMode,
|
|
1426
|
+
Ce as ChatModeDowngraded,
|
|
1427
|
+
q as ChatProgress,
|
|
1421
1428
|
j as ConnectionState,
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1429
|
+
Q as ConnectivityState,
|
|
1430
|
+
je as DocumentType,
|
|
1431
|
+
Te as KnowledgeType,
|
|
1432
|
+
Se as PlanGroup,
|
|
1433
|
+
Pe as Providers,
|
|
1427
1434
|
Ie as RateState,
|
|
1428
|
-
|
|
1429
|
-
|
|
1435
|
+
J as StreamEvents,
|
|
1436
|
+
U as StreamType,
|
|
1430
1437
|
p as StreamingState,
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1438
|
+
Me as Subject,
|
|
1439
|
+
_e as UserPlan,
|
|
1440
|
+
H as ValidationError,
|
|
1441
|
+
de as VideoType,
|
|
1442
|
+
Ae as VoiceAccess,
|
|
1436
1443
|
Re as WsError,
|
|
1437
|
-
|
|
1438
|
-
|
|
1444
|
+
St as createAgentManager,
|
|
1445
|
+
Et as getAgent,
|
|
1439
1446
|
be as mapVideoType
|
|
1440
1447
|
};
|