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