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