@d-id/client-sdk 1.1.18-staging.83 → 1.1.19
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-DcoRNuxp.js → index-DKb-cXkg.js} +427 -433
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +6 -6
- package/dist/{livekit-manager-CNKaXUpT.js → livekit-manager-D7QkEucf.js} +1 -1
- package/dist/src/services/analytics/mixpanel.d.ts +1 -1
- package/package.json +1 -1
- package/dist/src/utils/defer.d.ts +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var Q = (e, t, a) =>
|
|
1
|
+
var De = Object.defineProperty;
|
|
2
|
+
var Se = (e, t, a) => t in e ? De(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var Q = (e, t, a) => Se(e, typeof t != "symbol" ? t + "" : t, a);
|
|
4
4
|
class ee extends Error {
|
|
5
5
|
constructor({ kind: a, description: r, error: o }) {
|
|
6
6
|
super(JSON.stringify({ kind: a, description: r }));
|
|
@@ -10,7 +10,7 @@ class ee extends Error {
|
|
|
10
10
|
this.kind = a, this.description = r, this.error = o;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class Ie extends ee {
|
|
14
14
|
constructor(t, a) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,25 +18,25 @@ class Ee extends ee {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Ee extends ee {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class H extends ee {
|
|
27
27
|
constructor(a, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: a });
|
|
29
29
|
Q(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class Me extends ee {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var _e = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_e || {}), Te = /* @__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))(Te || {}), Ae = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ae || {}), je = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(je || {}), _ = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(_ || {}), V = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(V || {}), Pe = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pe || {}), be = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(be || {}), Le = /* @__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))(Le || {}), he = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(he || {});
|
|
39
|
+
const bt = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,12 +48,12 @@ const Lt = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), Z = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Z || {}),
|
|
52
|
-
const
|
|
51
|
+
var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), Z = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Z || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}), P = /* @__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))(P || {}), 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 || {}), de = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(de || {}), xe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(xe || {}), Be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Be || {});
|
|
52
|
+
const $e = 45 * 1e3, ze = "X-Playground-Chat", te = "https://api.d-id.com", Fe = "wss://notifications.d-id.com", Ne = "79f81a83a67430be2bc0fd61042b8faa", we = (e) => new Promise((t) => setTimeout(t, e)), q = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
54
|
return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
-
},
|
|
56
|
-
function
|
|
55
|
+
}, pe = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, le = (e) => e === he.Expressive, Je = (e) => [_.TextOnly, _.Playground, _.Maintenance].includes(e), ve = (e) => e && [_.DirectPlayback, _.Off].includes(e);
|
|
56
|
+
function We(e, t) {
|
|
57
57
|
let a;
|
|
58
58
|
return {
|
|
59
59
|
promise: new Promise((o, i) => {
|
|
@@ -77,12 +77,12 @@ async function ne(e, t) {
|
|
|
77
77
|
try {
|
|
78
78
|
if (!a.timeout)
|
|
79
79
|
return await e();
|
|
80
|
-
const { promise: i, clear: c } =
|
|
80
|
+
const { promise: i, clear: c } = We(a.timeout, a.timeoutErrorMessage), n = e().finally(c);
|
|
81
81
|
return await Promise.race([n, i]);
|
|
82
82
|
} catch (i) {
|
|
83
83
|
if (r = i, !a.shouldRetryFn(i) || o >= a.limit)
|
|
84
84
|
throw i;
|
|
85
|
-
await
|
|
85
|
+
await we(a.delayMs), a.onRetry(i);
|
|
86
86
|
}
|
|
87
87
|
throw r;
|
|
88
88
|
}
|
|
@@ -91,43 +91,43 @@ function ae(e) {
|
|
|
91
91
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
92
92
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
93
93
|
if (!t) {
|
|
94
|
-
let a =
|
|
94
|
+
let a = q();
|
|
95
95
|
window.localStorage.setItem("did_external_key_id", a), t = a;
|
|
96
96
|
}
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
|
-
let
|
|
100
|
-
function
|
|
99
|
+
let Ue = q();
|
|
100
|
+
function ye(e, t) {
|
|
101
101
|
if (e.type === "bearer")
|
|
102
102
|
return `Bearer ${e.token}`;
|
|
103
103
|
if (e.type === "basic")
|
|
104
104
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
105
105
|
if (e.type === "key")
|
|
106
|
-
return `Client-Key ${e.clientKey}.${ae(t)}_${
|
|
106
|
+
return `Client-Key ${e.clientKey}.${ae(t)}_${Ue}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const Ke = (e) => ne(e, {
|
|
110
110
|
limit: 3,
|
|
111
111
|
delayMs: 1e3,
|
|
112
112
|
timeout: 0,
|
|
113
113
|
shouldRetryFn: (t) => t.status === 429
|
|
114
114
|
});
|
|
115
|
-
function
|
|
115
|
+
function ke(e, t = te, a, r) {
|
|
116
116
|
const o = async (i, c) => {
|
|
117
|
-
const { skipErrorHandler: n, ...s } = c || {}, d = await
|
|
117
|
+
const { skipErrorHandler: n, ...s } = c || {}, d = await Ke(
|
|
118
118
|
() => fetch(t + (i != null && i.startsWith("/") ? i : `/${i}`), {
|
|
119
119
|
...s,
|
|
120
120
|
headers: {
|
|
121
121
|
...s.headers,
|
|
122
|
-
Authorization:
|
|
122
|
+
Authorization: ye(e, r),
|
|
123
123
|
"Content-Type": "application/json"
|
|
124
124
|
}
|
|
125
125
|
})
|
|
126
126
|
);
|
|
127
127
|
if (!d.ok) {
|
|
128
128
|
let l = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
129
|
-
const
|
|
130
|
-
throw a && !n && a(
|
|
129
|
+
const h = new Error(l);
|
|
130
|
+
throw a && !n && a(h, { url: i, options: s, headers: d.headers }), h;
|
|
131
131
|
}
|
|
132
132
|
return d.json();
|
|
133
133
|
};
|
|
@@ -146,8 +146,8 @@ function Ce(e, t = te, a, r) {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const o =
|
|
149
|
+
function He(e, t = te, a, r) {
|
|
150
|
+
const o = ke(e, `${t}/agents`, a, r);
|
|
151
151
|
return {
|
|
152
152
|
create(i, c) {
|
|
153
153
|
return o.post("/", i, c);
|
|
@@ -184,7 +184,7 @@ function Ve(e, t = te, a, r) {
|
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function Ve(e) {
|
|
188
188
|
var o, i, c, n;
|
|
189
189
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
|
|
190
190
|
const s = navigator.platform;
|
|
@@ -195,18 +195,18 @@ function qe(e) {
|
|
|
195
195
|
isMobile: `${t() == "Mobile"}`,
|
|
196
196
|
browser: navigator.userAgent,
|
|
197
197
|
origin: window.location.origin,
|
|
198
|
-
agentType:
|
|
198
|
+
agentType: pe(r),
|
|
199
199
|
agentVoice: {
|
|
200
200
|
voiceId: (i = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : i.voice_id,
|
|
201
201
|
provider: (n = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : n.type
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function qe(e) {
|
|
206
206
|
var a, r, o, i, c, n;
|
|
207
207
|
const t = (a = e.llm) == null ? void 0 : a.prompt_customization;
|
|
208
208
|
return {
|
|
209
|
-
agentType:
|
|
209
|
+
agentType: pe(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
211
211
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
212
212
|
behavior: {
|
|
@@ -225,8 +225,8 @@ function Oe(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
228
|
+
const Oe = (e) => e.reduce((t, a) => t + a, 0), ue = (e) => Oe(e) / e.length;
|
|
229
|
+
function Xe(e, t, a) {
|
|
230
230
|
var s, d, l;
|
|
231
231
|
const { event: r, ...o } = e, { template: i } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((s = t == null ? void 0 : t.presenter) == null ? void 0 : s.voice) || {};
|
|
232
232
|
return {
|
|
@@ -237,12 +237,9 @@ function Ye(e, t, a) {
|
|
|
237
237
|
...a
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
function fe(e) {
|
|
241
|
-
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
|
-
}
|
|
243
240
|
let re = {};
|
|
244
|
-
const
|
|
245
|
-
function
|
|
241
|
+
const Ye = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
242
|
+
function Qe(e) {
|
|
246
243
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
247
244
|
return {
|
|
248
245
|
token: e.token || "testKey",
|
|
@@ -253,14 +250,14 @@ function Ze(e) {
|
|
|
253
250
|
...e.mixpanelAdditionalProperties || {}
|
|
254
251
|
},
|
|
255
252
|
isEnabled: e.isEnabled ?? !0,
|
|
256
|
-
getRandom:
|
|
253
|
+
getRandom: q,
|
|
257
254
|
enrich(a) {
|
|
258
255
|
this.additionalProperties = { ...this.additionalProperties, ...a };
|
|
259
256
|
},
|
|
260
|
-
async track(a, r
|
|
257
|
+
async track(a, r) {
|
|
261
258
|
if (!this.isEnabled)
|
|
262
259
|
return Promise.resolve();
|
|
263
|
-
const { audioPath:
|
|
260
|
+
const { audioPath: o, ...i } = r || {}, c = {
|
|
264
261
|
method: "POST",
|
|
265
262
|
headers: {
|
|
266
263
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -271,11 +268,11 @@ function Ze(e) {
|
|
|
271
268
|
event: a,
|
|
272
269
|
properties: {
|
|
273
270
|
...this.additionalProperties,
|
|
274
|
-
...
|
|
271
|
+
...i,
|
|
275
272
|
agentId: this.agentId,
|
|
276
273
|
source: t,
|
|
277
274
|
token: this.token,
|
|
278
|
-
time:
|
|
275
|
+
time: Date.now(),
|
|
279
276
|
$insert_id: this.getRandom(),
|
|
280
277
|
origin: window.location.href,
|
|
281
278
|
"Screen Height": window.screen.height || window.innerWidth,
|
|
@@ -286,10 +283,11 @@ function Ze(e) {
|
|
|
286
283
|
])
|
|
287
284
|
})
|
|
288
285
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
286
|
+
try {
|
|
287
|
+
return await fetch(Ye, c).then((n) => n.json());
|
|
288
|
+
} catch (n) {
|
|
289
|
+
return console.error(n);
|
|
290
|
+
}
|
|
293
291
|
},
|
|
294
292
|
linkTrack(a, r, o, i) {
|
|
295
293
|
re[a] || (re[a] = { events: {}, resolvedDependencies: [] }), i.includes(o) || i.push(o);
|
|
@@ -307,7 +305,7 @@ function Ze(e) {
|
|
|
307
305
|
}
|
|
308
306
|
};
|
|
309
307
|
}
|
|
310
|
-
function
|
|
308
|
+
function Re() {
|
|
311
309
|
let e = 0;
|
|
312
310
|
return {
|
|
313
311
|
reset: () => e = 0,
|
|
@@ -315,13 +313,13 @@ function De() {
|
|
|
315
313
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
314
|
};
|
|
317
315
|
}
|
|
318
|
-
const N =
|
|
319
|
-
function
|
|
320
|
-
return e ===
|
|
316
|
+
const N = Re(), ie = Re();
|
|
317
|
+
function Ce(e) {
|
|
318
|
+
return e === _.Playground ? { headers: { [ze]: "true" } } : {};
|
|
321
319
|
}
|
|
322
320
|
async function se(e, t, a, r, o = !1, i) {
|
|
323
321
|
try {
|
|
324
|
-
return !i && !
|
|
322
|
+
return !i && !ve(r) && (i = await t.newChat(e.id, { persist: o }, Ce(r)), a.track("agent-chat", {
|
|
325
323
|
event: "created",
|
|
326
324
|
chatId: i.id,
|
|
327
325
|
mode: r
|
|
@@ -337,59 +335,59 @@ async function se(e, t, a, r, o = !1, i) {
|
|
|
337
335
|
throw new Error("Cannot create new chat");
|
|
338
336
|
}
|
|
339
337
|
}
|
|
340
|
-
function
|
|
338
|
+
function Ze(e) {
|
|
341
339
|
return e && e.length > 0 ? e : [];
|
|
342
340
|
}
|
|
343
|
-
function
|
|
341
|
+
function Ge(e, t, a) {
|
|
344
342
|
if (!e)
|
|
345
343
|
throw new Error("Please connect to the agent first");
|
|
346
344
|
if (!e.interruptAvailable)
|
|
347
345
|
throw new Error("Interrupt is not enabled for this stream");
|
|
348
|
-
if (t !==
|
|
346
|
+
if (t !== W.Fluent)
|
|
349
347
|
throw new Error("Interrupt only available for Fluent streams");
|
|
350
348
|
if (!a)
|
|
351
349
|
throw new Error("No active video to interrupt");
|
|
352
350
|
}
|
|
353
|
-
async function
|
|
351
|
+
async function et(e, t) {
|
|
354
352
|
const a = {
|
|
355
|
-
type:
|
|
353
|
+
type: P.StreamInterrupt,
|
|
356
354
|
videoId: t,
|
|
357
355
|
timestamp: Date.now()
|
|
358
356
|
};
|
|
359
357
|
e.sendDataChannelMessage(JSON.stringify(a));
|
|
360
358
|
}
|
|
361
|
-
function
|
|
359
|
+
function tt(e) {
|
|
362
360
|
return new Promise((t, a) => {
|
|
363
|
-
const { callbacks: r, host: o, auth: i, externalId: c } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: l = null } = r || {},
|
|
364
|
-
|
|
361
|
+
const { callbacks: r, host: o, auth: i, externalId: c } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: l = null } = r || {}, h = new WebSocket(`${o}?authorization=${encodeURIComponent(ye(i, c))}`);
|
|
362
|
+
h.onmessage = n, h.onclose = d, h.onerror = (y) => {
|
|
365
363
|
console.error(y), l == null || l("Websocket failed to connect", y), a(y);
|
|
366
|
-
},
|
|
367
|
-
s == null || s(y), t(
|
|
364
|
+
}, h.onopen = (y) => {
|
|
365
|
+
s == null || s(y), t(h);
|
|
368
366
|
};
|
|
369
367
|
});
|
|
370
368
|
}
|
|
371
|
-
async function
|
|
369
|
+
async function rt(e) {
|
|
372
370
|
const { retries: t = 1 } = e;
|
|
373
371
|
let a = null;
|
|
374
372
|
for (let r = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; r++)
|
|
375
373
|
try {
|
|
376
|
-
a = await
|
|
374
|
+
a = await tt(e);
|
|
377
375
|
} catch (o) {
|
|
378
376
|
if (r === t)
|
|
379
377
|
throw o;
|
|
380
|
-
await
|
|
378
|
+
await we(r * 500);
|
|
381
379
|
}
|
|
382
380
|
return a;
|
|
383
381
|
}
|
|
384
|
-
async function
|
|
385
|
-
const o = a != null && a.onMessage ? [a.onMessage] : [], i = await
|
|
382
|
+
async function nt(e, t, a, r) {
|
|
383
|
+
const o = a != null && a.onMessage ? [a.onMessage] : [], i = await rt({
|
|
386
384
|
auth: e,
|
|
387
385
|
host: t,
|
|
388
386
|
externalId: r,
|
|
389
387
|
callbacks: {
|
|
390
388
|
onError: (c) => {
|
|
391
389
|
var n;
|
|
392
|
-
return (n = a.onError) == null ? void 0 : n.call(a, new
|
|
390
|
+
return (n = a.onError) == null ? void 0 : n.call(a, new Me(c));
|
|
393
391
|
},
|
|
394
392
|
onMessage(c) {
|
|
395
393
|
const n = JSON.parse(c.data);
|
|
@@ -403,7 +401,7 @@ async function at(e, t, a, r) {
|
|
|
403
401
|
subscribeToEvents: (c) => o.push(c)
|
|
404
402
|
};
|
|
405
403
|
}
|
|
406
|
-
function
|
|
404
|
+
function at(e) {
|
|
407
405
|
if (e.answer !== void 0)
|
|
408
406
|
return e.answer;
|
|
409
407
|
let t = 0, a = "";
|
|
@@ -411,41 +409,41 @@ function it(e) {
|
|
|
411
409
|
a += e[t++];
|
|
412
410
|
return a;
|
|
413
411
|
}
|
|
414
|
-
function
|
|
412
|
+
function it(e, t, a, r, o) {
|
|
415
413
|
const i = r.messages[r.messages.length - 1];
|
|
416
|
-
if (!(e ===
|
|
414
|
+
if (!(e === V.Partial || e === V.Answer) || (i == null ? void 0 : i.role) !== "assistant")
|
|
417
415
|
return;
|
|
418
416
|
const { content: c, sequence: n } = t;
|
|
419
|
-
e ===
|
|
420
|
-
const s =
|
|
421
|
-
(i.content !== s || e ===
|
|
417
|
+
e === V.Partial ? a[n] = c : a.answer = c;
|
|
418
|
+
const s = at(a);
|
|
419
|
+
(i.content !== s || e === V.Answer) && (i.content = s, o == null || o([...r.messages], e));
|
|
422
420
|
}
|
|
423
|
-
function
|
|
421
|
+
function st(e, t, a, r, o) {
|
|
424
422
|
let i = {};
|
|
425
423
|
return {
|
|
426
424
|
clearQueue: () => i = {},
|
|
427
425
|
onMessage: (c, n) => {
|
|
428
426
|
var s, d;
|
|
429
427
|
if ("content" in n)
|
|
430
|
-
|
|
428
|
+
it(c, n, i, t, a.callbacks.onNewMessage), c === V.Answer && e.track("agent-message-received", {
|
|
431
429
|
messages: t.messages.length,
|
|
432
430
|
mode: t.chatMode
|
|
433
431
|
});
|
|
434
432
|
else {
|
|
435
|
-
const l =
|
|
433
|
+
const l = P, h = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], y = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], b = Xe(n, r, { mode: t.chatMode });
|
|
436
434
|
if (c = c, c === l.StreamVideoCreated)
|
|
437
|
-
e.linkTrack("agent-video",
|
|
438
|
-
else if (
|
|
439
|
-
const
|
|
440
|
-
y.includes(c) ? e.track("agent-video", { ...
|
|
435
|
+
e.linkTrack("agent-video", b, l.StreamVideoCreated, ["start"]);
|
|
436
|
+
else if (h.includes(c)) {
|
|
437
|
+
const L = c.split("/")[1];
|
|
438
|
+
y.includes(c) ? e.track("agent-video", { ...b, event: L }) : e.linkTrack("agent-video", { ...b, event: L }, c, ["done"]);
|
|
441
439
|
}
|
|
442
440
|
y.includes(c) && ((d = (s = a.callbacks).onError) == null || d.call(s, new Error(`Stream failed with event ${c}`), { data: n })), n.event === l.StreamDone && o();
|
|
443
441
|
}
|
|
444
442
|
}
|
|
445
443
|
};
|
|
446
444
|
}
|
|
447
|
-
function
|
|
448
|
-
const o =
|
|
445
|
+
function ot(e, t, a, r) {
|
|
446
|
+
const o = ke(e, `${t}/agents/${a}`, r);
|
|
449
447
|
return {
|
|
450
448
|
createStream(i) {
|
|
451
449
|
return o.post("/streams", i);
|
|
@@ -473,8 +471,8 @@ function ct(e, t, a, r) {
|
|
|
473
471
|
}
|
|
474
472
|
};
|
|
475
473
|
}
|
|
476
|
-
const
|
|
477
|
-
function
|
|
474
|
+
const ct = (e, t) => (a, r) => e && console.log(`[${t}] ${a}`, r ?? "");
|
|
475
|
+
function dt(e, t, a) {
|
|
478
476
|
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
479
477
|
return {
|
|
480
478
|
duration: r,
|
|
@@ -494,7 +492,7 @@ function lt(e, t, a) {
|
|
|
494
492
|
lowFpsCount: a
|
|
495
493
|
};
|
|
496
494
|
}
|
|
497
|
-
function
|
|
495
|
+
function lt(e) {
|
|
498
496
|
return e.filter(
|
|
499
497
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
500
498
|
).map((t) => {
|
|
@@ -505,7 +503,7 @@ function ut(e) {
|
|
|
505
503
|
};
|
|
506
504
|
});
|
|
507
505
|
}
|
|
508
|
-
function
|
|
506
|
+
function ut(e) {
|
|
509
507
|
let t = "", a = 0;
|
|
510
508
|
for (const r of e.values()) {
|
|
511
509
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -535,7 +533,7 @@ function ft(e) {
|
|
|
535
533
|
}
|
|
536
534
|
return {};
|
|
537
535
|
}
|
|
538
|
-
function
|
|
536
|
+
function ft(e, t, a) {
|
|
539
537
|
const r = e.map((s, d) => d === 0 ? a ? {
|
|
540
538
|
timestamp: s.timestamp,
|
|
541
539
|
duration: 0,
|
|
@@ -587,14 +585,14 @@ function mt(e, t, a) {
|
|
|
587
585
|
framesPerSecond: s.framesPerSecond,
|
|
588
586
|
freezeCount: s.freezeCount - e[d - 1].freezeCount,
|
|
589
587
|
freezeDuration: s.freezeDuration - e[d - 1].freezeDuration
|
|
590
|
-
}), o =
|
|
588
|
+
}), o = lt(r), i = o.reduce((s, d) => s + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), n = r.filter((s) => !!s.rtt).map((s) => s.rtt);
|
|
591
589
|
return {
|
|
592
590
|
webRTCStats: {
|
|
593
591
|
anomalies: o,
|
|
594
592
|
minRtt: Math.min(...n),
|
|
595
593
|
avgRtt: ue(n),
|
|
596
594
|
maxRtt: Math.max(...n),
|
|
597
|
-
aggregateReport:
|
|
595
|
+
aggregateReport: dt(e[0], e[e.length - 1], i),
|
|
598
596
|
minJitterDelayInInterval: Math.min(...c),
|
|
599
597
|
maxJitterDelayInInterval: Math.max(...c),
|
|
600
598
|
avgJitterDelayInInterval: ue(c)
|
|
@@ -603,16 +601,16 @@ function mt(e, t, a) {
|
|
|
603
601
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
604
602
|
};
|
|
605
603
|
}
|
|
606
|
-
const oe = 100,
|
|
607
|
-
function
|
|
604
|
+
const oe = 100, mt = Math.max(Math.ceil(400 / oe), 1), gt = 0.25, ht = 0.28;
|
|
605
|
+
function wt() {
|
|
608
606
|
let e = 0, t, a, r = 0;
|
|
609
607
|
return (o) => {
|
|
610
608
|
for (const i of o.values())
|
|
611
609
|
if (i && i.type === "inbound-rtp" && i.kind === "video") {
|
|
612
610
|
const c = i.jitterBufferDelay, n = i.jitterBufferEmittedCount;
|
|
613
611
|
if (a && n > a) {
|
|
614
|
-
const l = c - t,
|
|
615
|
-
r = l /
|
|
612
|
+
const l = c - t, h = n - a;
|
|
613
|
+
r = l / h;
|
|
616
614
|
}
|
|
617
615
|
t = c, a = n;
|
|
618
616
|
const s = i.framesDecoded, d = s - e > 0;
|
|
@@ -621,41 +619,41 @@ function pt() {
|
|
|
621
619
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
622
620
|
};
|
|
623
621
|
}
|
|
624
|
-
function
|
|
625
|
-
let i = [], c, n = 0, s = !1, d = Z.Unknown, l = Z.Unknown,
|
|
626
|
-
const
|
|
622
|
+
function pt(e, t, a, r, o) {
|
|
623
|
+
let i = [], c, n = 0, s = !1, d = Z.Unknown, l = Z.Unknown, h = 0, y = 0;
|
|
624
|
+
const b = wt();
|
|
627
625
|
return setInterval(async () => {
|
|
628
|
-
const
|
|
629
|
-
if (
|
|
630
|
-
n = 0,
|
|
631
|
-
else if (s && (n++, n >=
|
|
632
|
-
const K =
|
|
633
|
-
r == null || r(w.Stop, K), t() || a(), y =
|
|
626
|
+
const L = await e.getStats(), { isReceiving: x, avgJitterDelayInInterval: j, freezeCount: B } = b(L), D = ut(L);
|
|
627
|
+
if (x)
|
|
628
|
+
n = 0, h = B - y, l = j < gt ? Z.Strong : j > ht && h > 1 ? Z.Weak : d, l !== d && (o == null || o(l), d = l, y += h, h = 0), s || (r == null || r(w.Start), c = i[i.length - 1], i = [], s = !0), i.push(D);
|
|
629
|
+
else if (s && (n++, n >= mt)) {
|
|
630
|
+
const K = ft(i, oe, c);
|
|
631
|
+
r == null || r(w.Stop, K), t() || a(), y = B, s = !1;
|
|
634
632
|
}
|
|
635
633
|
}, oe);
|
|
636
634
|
}
|
|
637
|
-
const
|
|
638
|
-
function
|
|
635
|
+
const vt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
636
|
+
function fe(e) {
|
|
639
637
|
switch (e) {
|
|
640
638
|
case "connected":
|
|
641
|
-
return
|
|
639
|
+
return I.Connected;
|
|
642
640
|
case "checking":
|
|
643
|
-
return
|
|
641
|
+
return I.Connecting;
|
|
644
642
|
case "failed":
|
|
645
|
-
return
|
|
643
|
+
return I.Fail;
|
|
646
644
|
case "new":
|
|
647
|
-
return
|
|
645
|
+
return I.New;
|
|
648
646
|
case "closed":
|
|
649
|
-
return
|
|
647
|
+
return I.Closed;
|
|
650
648
|
case "disconnected":
|
|
651
|
-
return
|
|
649
|
+
return I.Disconnected;
|
|
652
650
|
case "completed":
|
|
653
|
-
return
|
|
651
|
+
return I.Completed;
|
|
654
652
|
default:
|
|
655
|
-
return
|
|
653
|
+
return I.New;
|
|
656
654
|
}
|
|
657
655
|
}
|
|
658
|
-
const
|
|
656
|
+
const yt = (e) => (t) => {
|
|
659
657
|
const [a, r = ""] = t.split(/:(.+)/);
|
|
660
658
|
try {
|
|
661
659
|
const o = JSON.parse(r);
|
|
@@ -664,7 +662,7 @@ const kt = (e) => (t) => {
|
|
|
664
662
|
return e("Failed to parse data channel message, returning data as string", { subject: a, rawData: r, error: o }), { subject: a, data: r };
|
|
665
663
|
}
|
|
666
664
|
};
|
|
667
|
-
function
|
|
665
|
+
function kt({
|
|
668
666
|
statsSignal: e,
|
|
669
667
|
dataChannelSignal: t,
|
|
670
668
|
onVideoStateChange: a,
|
|
@@ -672,16 +670,16 @@ function Ct({
|
|
|
672
670
|
}) {
|
|
673
671
|
e === w.Start && t === w.Start ? a == null || a(w.Start) : e === w.Stop && t === w.Stop && (a == null || a(w.Stop, r));
|
|
674
672
|
}
|
|
675
|
-
function
|
|
673
|
+
function Rt({
|
|
676
674
|
statsSignal: e,
|
|
677
675
|
dataChannelSignal: t,
|
|
678
676
|
onVideoStateChange: a,
|
|
679
677
|
onAgentActivityStateChange: r,
|
|
680
678
|
report: o
|
|
681
679
|
}) {
|
|
682
|
-
e === w.Start ? a == null || a(w.Start) : e === w.Stop && (a == null || a(w.Stop, o)), t === w.Start ? r == null || r(
|
|
680
|
+
e === w.Start ? a == null || a(w.Start) : e === w.Stop && (a == null || a(w.Stop, o)), t === w.Start ? r == null || r(O.Talking) : t === w.Stop && (r == null || r(O.Idle));
|
|
683
681
|
}
|
|
684
|
-
function
|
|
682
|
+
function me({
|
|
685
683
|
statsSignal: e,
|
|
686
684
|
dataChannelSignal: t,
|
|
687
685
|
onVideoStateChange: a,
|
|
@@ -689,7 +687,7 @@ function ge({
|
|
|
689
687
|
streamType: o,
|
|
690
688
|
report: i
|
|
691
689
|
}) {
|
|
692
|
-
o ===
|
|
690
|
+
o === W.Legacy ? kt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: a, report: i }) : o === W.Fluent && Rt({
|
|
693
691
|
statsSignal: e,
|
|
694
692
|
dataChannelSignal: t,
|
|
695
693
|
onVideoStateChange: a,
|
|
@@ -697,185 +695,185 @@ function ge({
|
|
|
697
695
|
report: i
|
|
698
696
|
});
|
|
699
697
|
}
|
|
700
|
-
async function
|
|
701
|
-
var
|
|
702
|
-
const n =
|
|
703
|
-
let d = !1, l = !1,
|
|
704
|
-
const { startConnection:
|
|
698
|
+
async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te, analytics: c }) {
|
|
699
|
+
var X;
|
|
700
|
+
const n = ct(a, "WebRTCStreamingManager"), s = yt(n);
|
|
701
|
+
let d = !1, l = !1, h = w.Stop, y = w.Stop;
|
|
702
|
+
const { startConnection: b, sendStreamRequest: L, close: x, createStream: j, addIceCandidate: B } = ot(
|
|
705
703
|
o,
|
|
706
704
|
i,
|
|
707
705
|
e,
|
|
708
706
|
r.onError
|
|
709
707
|
), {
|
|
710
|
-
id:
|
|
708
|
+
id: D,
|
|
711
709
|
offer: K,
|
|
712
710
|
ice_servers: G,
|
|
713
|
-
session_id:
|
|
714
|
-
fluent:
|
|
715
|
-
interrupt_enabled:
|
|
716
|
-
triggers_enabled:
|
|
717
|
-
} = await
|
|
718
|
-
(
|
|
719
|
-
const g = new
|
|
720
|
-
if (!
|
|
711
|
+
session_id: u,
|
|
712
|
+
fluent: k,
|
|
713
|
+
interrupt_enabled: v,
|
|
714
|
+
triggers_enabled: T
|
|
715
|
+
} = await j(t);
|
|
716
|
+
(X = r.onStreamCreated) == null || X.call(r, { stream_id: D, session_id: u, agent_id: e });
|
|
717
|
+
const g = new vt({ iceServers: G }), p = g.createDataChannel("JanusDataChannel");
|
|
718
|
+
if (!u)
|
|
721
719
|
throw new Error("Could not create session_id");
|
|
722
|
-
const
|
|
720
|
+
const S = k ? W.Fluent : W.Legacy;
|
|
723
721
|
c.enrich({
|
|
724
|
-
"stream-type":
|
|
722
|
+
"stream-type": S
|
|
725
723
|
});
|
|
726
|
-
const
|
|
727
|
-
var
|
|
728
|
-
d = !0, l && ((
|
|
729
|
-
},
|
|
724
|
+
const $ = t.stream_warmup && !k, z = () => d, C = () => {
|
|
725
|
+
var f;
|
|
726
|
+
d = !0, l && ((f = r.onConnectionStateChange) == null || f.call(r, I.Connected));
|
|
727
|
+
}, E = pt(
|
|
730
728
|
g,
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
(
|
|
734
|
-
statsSignal: y =
|
|
735
|
-
dataChannelSignal:
|
|
729
|
+
z,
|
|
730
|
+
C,
|
|
731
|
+
(f, m) => me({
|
|
732
|
+
statsSignal: y = f,
|
|
733
|
+
dataChannelSignal: S === W.Legacy ? h : void 0,
|
|
736
734
|
onVideoStateChange: r.onVideoStateChange,
|
|
737
735
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
738
|
-
report:
|
|
739
|
-
streamType:
|
|
736
|
+
report: m,
|
|
737
|
+
streamType: S
|
|
740
738
|
}),
|
|
741
|
-
(
|
|
742
|
-
var
|
|
743
|
-
return (
|
|
739
|
+
(f) => {
|
|
740
|
+
var m;
|
|
741
|
+
return (m = r.onConnectivityStateChange) == null ? void 0 : m.call(r, f);
|
|
744
742
|
}
|
|
745
743
|
);
|
|
746
|
-
g.onicecandidate = (
|
|
747
|
-
var
|
|
748
|
-
n("peerConnection.onicecandidate",
|
|
744
|
+
g.onicecandidate = (f) => {
|
|
745
|
+
var m;
|
|
746
|
+
n("peerConnection.onicecandidate", f);
|
|
749
747
|
try {
|
|
750
|
-
|
|
751
|
-
|
|
748
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? B(
|
|
749
|
+
D,
|
|
752
750
|
{
|
|
753
|
-
candidate:
|
|
754
|
-
sdpMid:
|
|
755
|
-
sdpMLineIndex:
|
|
751
|
+
candidate: f.candidate.candidate,
|
|
752
|
+
sdpMid: f.candidate.sdpMid,
|
|
753
|
+
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
756
754
|
},
|
|
757
|
-
|
|
758
|
-
) :
|
|
759
|
-
} catch (
|
|
760
|
-
(
|
|
755
|
+
u
|
|
756
|
+
) : B(D, { candidate: null }, u);
|
|
757
|
+
} catch (A) {
|
|
758
|
+
(m = r.onError) == null || m.call(r, A, { streamId: D });
|
|
761
759
|
}
|
|
762
|
-
},
|
|
763
|
-
l = !0, (
|
|
760
|
+
}, p.onopen = () => {
|
|
761
|
+
l = !0, (!$ || d) && C();
|
|
764
762
|
};
|
|
765
|
-
const
|
|
766
|
-
var
|
|
767
|
-
(
|
|
763
|
+
const J = (f) => {
|
|
764
|
+
var m;
|
|
765
|
+
(m = r.onVideoIdChange) == null || m.call(r, f);
|
|
768
766
|
};
|
|
769
|
-
function
|
|
770
|
-
if (
|
|
771
|
-
const
|
|
772
|
-
|
|
767
|
+
function R(f, m) {
|
|
768
|
+
if (f === P.StreamStarted && typeof m == "object" && "metadata" in m) {
|
|
769
|
+
const A = m.metadata;
|
|
770
|
+
J(A.videoId);
|
|
773
771
|
}
|
|
774
|
-
|
|
775
|
-
statsSignal:
|
|
776
|
-
dataChannelSignal:
|
|
772
|
+
f === P.StreamDone && J(null), h = f === P.StreamStarted ? w.Start : w.Stop, me({
|
|
773
|
+
statsSignal: S === W.Legacy ? y : void 0,
|
|
774
|
+
dataChannelSignal: h,
|
|
777
775
|
onVideoStateChange: r.onVideoStateChange,
|
|
778
776
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
779
|
-
streamType:
|
|
777
|
+
streamType: S
|
|
780
778
|
});
|
|
781
779
|
}
|
|
782
|
-
function
|
|
783
|
-
const
|
|
784
|
-
|
|
780
|
+
function M(f, m) {
|
|
781
|
+
const A = typeof m == "string" ? m : m == null ? void 0 : m.metadata;
|
|
782
|
+
A && c.enrich({ streamMetadata: A }), c.track("agent-chat", { event: "ready" });
|
|
785
783
|
}
|
|
786
|
-
const
|
|
787
|
-
[
|
|
788
|
-
[
|
|
789
|
-
[
|
|
784
|
+
const U = {
|
|
785
|
+
[P.StreamStarted]: R,
|
|
786
|
+
[P.StreamDone]: R,
|
|
787
|
+
[P.StreamReady]: M
|
|
790
788
|
};
|
|
791
|
-
|
|
792
|
-
var
|
|
793
|
-
const { subject:
|
|
794
|
-
(
|
|
789
|
+
p.onmessage = (f) => {
|
|
790
|
+
var Y;
|
|
791
|
+
const { subject: m, data: A } = s(f.data);
|
|
792
|
+
(Y = U[m]) == null || Y.call(U, m, A);
|
|
795
793
|
}, g.oniceconnectionstatechange = () => {
|
|
796
|
-
var
|
|
794
|
+
var m;
|
|
797
795
|
n("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
}, g.ontrack = (
|
|
801
|
-
var
|
|
802
|
-
n("peerConnection.ontrack",
|
|
796
|
+
const f = fe(g.iceConnectionState);
|
|
797
|
+
f !== I.Connected && ((m = r.onConnectionStateChange) == null || m.call(r, f));
|
|
798
|
+
}, g.ontrack = (f) => {
|
|
799
|
+
var m;
|
|
800
|
+
n("peerConnection.ontrack", f), (m = r.onSrcObjectReady) == null || m.call(r, f.streams[0]);
|
|
803
801
|
}, await g.setRemoteDescription(K), n("set remote description OK");
|
|
804
|
-
const
|
|
805
|
-
return n("create answer OK"), await g.setLocalDescription(
|
|
802
|
+
const F = await g.createAnswer();
|
|
803
|
+
return n("create answer OK"), await g.setLocalDescription(F), n("set local description OK"), await b(D, F, u), n("start connection OK"), {
|
|
806
804
|
/**
|
|
807
805
|
* Method to send request to server to get clip or talk depend on you payload
|
|
808
806
|
* @param payload
|
|
809
807
|
*/
|
|
810
|
-
speak(
|
|
811
|
-
return
|
|
808
|
+
speak(f) {
|
|
809
|
+
return L(D, u, f);
|
|
812
810
|
},
|
|
813
811
|
/**
|
|
814
812
|
* Method to close RTC connection
|
|
815
813
|
*/
|
|
816
814
|
async disconnect() {
|
|
817
|
-
var
|
|
818
|
-
if (
|
|
819
|
-
const
|
|
815
|
+
var f;
|
|
816
|
+
if (D) {
|
|
817
|
+
const m = fe(g.iceConnectionState);
|
|
820
818
|
if (g) {
|
|
821
|
-
if (
|
|
822
|
-
clearInterval(
|
|
819
|
+
if (m === I.New) {
|
|
820
|
+
clearInterval(E);
|
|
823
821
|
return;
|
|
824
822
|
}
|
|
825
823
|
g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
|
|
826
824
|
}
|
|
827
825
|
try {
|
|
828
|
-
|
|
826
|
+
m === I.Connected && await x(D, u).catch((A) => {
|
|
829
827
|
});
|
|
830
|
-
} catch (
|
|
831
|
-
n("Error on close stream connection",
|
|
828
|
+
} catch (A) {
|
|
829
|
+
n("Error on close stream connection", A);
|
|
832
830
|
}
|
|
833
|
-
(
|
|
831
|
+
(f = r.onAgentActivityStateChange) == null || f.call(r, O.Idle), clearInterval(E);
|
|
834
832
|
}
|
|
835
833
|
},
|
|
836
834
|
/**
|
|
837
835
|
* Method to send data channel messages to the server
|
|
838
836
|
*/
|
|
839
|
-
sendDataChannelMessage(
|
|
840
|
-
var
|
|
841
|
-
if (!d ||
|
|
842
|
-
n("Data channel is not ready for sending messages"), (
|
|
843
|
-
streamId:
|
|
837
|
+
sendDataChannelMessage(f) {
|
|
838
|
+
var m, A;
|
|
839
|
+
if (!d || p.readyState !== "open") {
|
|
840
|
+
n("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"), {
|
|
841
|
+
streamId: D
|
|
844
842
|
});
|
|
845
843
|
return;
|
|
846
844
|
}
|
|
847
845
|
try {
|
|
848
|
-
|
|
849
|
-
} catch (
|
|
850
|
-
n("Error sending data channel message",
|
|
846
|
+
p.send(f);
|
|
847
|
+
} catch (Y) {
|
|
848
|
+
n("Error sending data channel message", Y), (A = r.onError) == null || A.call(r, Y, { streamId: D });
|
|
851
849
|
}
|
|
852
850
|
},
|
|
853
851
|
/**
|
|
854
852
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
855
853
|
*/
|
|
856
|
-
sessionId:
|
|
854
|
+
sessionId: u,
|
|
857
855
|
/**
|
|
858
856
|
* Id of current RTC stream
|
|
859
857
|
*/
|
|
860
|
-
streamId:
|
|
861
|
-
streamType:
|
|
862
|
-
interruptAvailable:
|
|
863
|
-
triggersAvailable:
|
|
858
|
+
streamId: D,
|
|
859
|
+
streamType: S,
|
|
860
|
+
interruptAvailable: v ?? !1,
|
|
861
|
+
triggersAvailable: T ?? !1
|
|
864
862
|
};
|
|
865
863
|
}
|
|
866
864
|
var ce = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ce || {});
|
|
867
|
-
async function
|
|
865
|
+
async function Dt(e, t, a) {
|
|
868
866
|
const r = e.id;
|
|
869
867
|
switch (t.version) {
|
|
870
868
|
case "v1": {
|
|
871
869
|
const { version: o, ...i } = t;
|
|
872
|
-
return
|
|
870
|
+
return Ct(r, i, a);
|
|
873
871
|
}
|
|
874
872
|
case "v2": {
|
|
875
873
|
const { version: o, ...i } = t;
|
|
876
874
|
switch (i.transport_provider) {
|
|
877
875
|
case de.Livekit:
|
|
878
|
-
const { createLiveKitStreamingManager: c } = await import("./livekit-manager-
|
|
876
|
+
const { createLiveKitStreamingManager: c } = await import("./livekit-manager-D7QkEucf.js");
|
|
879
877
|
return c(r, i, a);
|
|
880
878
|
default:
|
|
881
879
|
throw new Error(`Unsupported transport provider: ${i.transport_provider}`);
|
|
@@ -885,13 +883,13 @@ async function St(e, t, a) {
|
|
|
885
883
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
886
884
|
}
|
|
887
885
|
}
|
|
888
|
-
function
|
|
886
|
+
function St(e) {
|
|
889
887
|
return {
|
|
890
888
|
transport_provider: de.Livekit,
|
|
891
889
|
chat_id: e == null ? void 0 : e.chatId
|
|
892
890
|
};
|
|
893
891
|
}
|
|
894
|
-
function
|
|
892
|
+
function It(e) {
|
|
895
893
|
var o, i;
|
|
896
894
|
const { streamOptions: t } = e ?? {}, a = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
|
|
897
895
|
plan: (i = e.mixpanelAdditionalProperties) == null ? void 0 : i.plan
|
|
@@ -904,13 +902,13 @@ function Et(e) {
|
|
|
904
902
|
fluent: t == null ? void 0 : t.fluent
|
|
905
903
|
}, ...a && { end_user_data: a } };
|
|
906
904
|
}
|
|
907
|
-
function
|
|
908
|
-
return le(e.presenter.type) ? { version: ce.V2, ...
|
|
905
|
+
function Et(e, t) {
|
|
906
|
+
return le(e.presenter.type) ? { version: ce.V2, ...St(t) } : { version: ce.V1, ...It(t) };
|
|
909
907
|
}
|
|
910
|
-
function
|
|
911
|
-
o ===
|
|
908
|
+
function Mt(e, t, a, r, o) {
|
|
909
|
+
o === W.Fluent ? _t(e, t, a, r, o) : At(e, t, a, r, o);
|
|
912
910
|
}
|
|
913
|
-
function
|
|
911
|
+
function _t(e, t, a, r, o) {
|
|
914
912
|
e === w.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === w.Stop && r.track("stream-session", {
|
|
915
913
|
event: "stop",
|
|
916
914
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
@@ -919,12 +917,12 @@ function Tt(e, t, a, r, o) {
|
|
|
919
917
|
...a
|
|
920
918
|
});
|
|
921
919
|
}
|
|
922
|
-
function
|
|
920
|
+
function Tt(e, t, a, r) {
|
|
923
921
|
N.get() <= 0 || (e === w.Start ? a.linkTrack(
|
|
924
922
|
"agent-video",
|
|
925
923
|
{ event: "start", latency: N.get(!0), "stream-type": r },
|
|
926
924
|
"start",
|
|
927
|
-
[
|
|
925
|
+
[P.StreamVideoCreated]
|
|
928
926
|
) : e === w.Stop && a.linkTrack(
|
|
929
927
|
"agent-video",
|
|
930
928
|
{
|
|
@@ -934,15 +932,15 @@ function At(e, t, a, r) {
|
|
|
934
932
|
"stream-type": r
|
|
935
933
|
},
|
|
936
934
|
"done",
|
|
937
|
-
[
|
|
935
|
+
[P.StreamVideoDone]
|
|
938
936
|
));
|
|
939
937
|
}
|
|
940
|
-
function
|
|
938
|
+
function At(e, t, a, r, o) {
|
|
941
939
|
N.get() <= 0 || (e === w.Start ? r.linkTrack(
|
|
942
940
|
"agent-video",
|
|
943
941
|
{ event: "start", latency: N.get(!0), "stream-type": o },
|
|
944
942
|
"start",
|
|
945
|
-
[
|
|
943
|
+
[P.StreamVideoCreated]
|
|
946
944
|
) : e === w.Stop && r.linkTrack(
|
|
947
945
|
"agent-video",
|
|
948
946
|
{
|
|
@@ -953,25 +951,25 @@ function Pt(e, t, a, r, o) {
|
|
|
953
951
|
...a
|
|
954
952
|
},
|
|
955
953
|
"done",
|
|
956
|
-
[
|
|
954
|
+
[P.StreamVideoDone]
|
|
957
955
|
));
|
|
958
956
|
}
|
|
959
|
-
function
|
|
957
|
+
function ge(e, t, a) {
|
|
960
958
|
return N.reset(), new Promise(async (r, o) => {
|
|
961
959
|
try {
|
|
962
960
|
let i, c = !1;
|
|
963
|
-
i = await
|
|
961
|
+
i = await Dt(e, Et(e, t), {
|
|
964
962
|
...t,
|
|
965
963
|
analytics: a,
|
|
966
964
|
callbacks: {
|
|
967
965
|
...t.callbacks,
|
|
968
966
|
onConnectionStateChange: (n) => {
|
|
969
967
|
var s, d;
|
|
970
|
-
(d = (s = t.callbacks).onConnectionStateChange) == null || d.call(s, n), n ===
|
|
968
|
+
(d = (s = t.callbacks).onConnectionStateChange) == null || d.call(s, n), n === I.Connected && (i ? r(i) : c = !0);
|
|
971
969
|
},
|
|
972
970
|
onVideoStateChange: (n, s) => {
|
|
973
971
|
var d, l;
|
|
974
|
-
(l = (d = t.callbacks).onVideoStateChange) == null || l.call(d, n),
|
|
972
|
+
(l = (d = t.callbacks).onVideoStateChange) == null || l.call(d, n), Mt(
|
|
975
973
|
n,
|
|
976
974
|
e,
|
|
977
975
|
s,
|
|
@@ -981,8 +979,8 @@ function he(e, t, a) {
|
|
|
981
979
|
},
|
|
982
980
|
onAgentActivityStateChange: (n) => {
|
|
983
981
|
var s, d;
|
|
984
|
-
(d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n ===
|
|
985
|
-
n ===
|
|
982
|
+
(d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n === O.Talking ? ie.update() : ie.reset(), Tt(
|
|
983
|
+
n === O.Talking ? w.Start : w.Stop,
|
|
986
984
|
e,
|
|
987
985
|
a,
|
|
988
986
|
i.streamType
|
|
@@ -995,308 +993,304 @@ function he(e, t, a) {
|
|
|
995
993
|
}
|
|
996
994
|
});
|
|
997
995
|
}
|
|
998
|
-
async function
|
|
999
|
-
var l,
|
|
996
|
+
async function jt(e, t, a, r, o) {
|
|
997
|
+
var l, h, y, b;
|
|
1000
998
|
const i = async () => {
|
|
1001
|
-
var
|
|
999
|
+
var L;
|
|
1002
1000
|
if (le(e.presenter.type)) {
|
|
1003
|
-
const
|
|
1001
|
+
const x = await se(
|
|
1004
1002
|
e,
|
|
1005
1003
|
a,
|
|
1006
1004
|
r,
|
|
1007
1005
|
t.mode,
|
|
1008
1006
|
t.persistentChat,
|
|
1009
1007
|
o
|
|
1010
|
-
),
|
|
1008
|
+
), j = await ge(
|
|
1011
1009
|
e,
|
|
1012
|
-
{ ...t, chatId: (
|
|
1010
|
+
{ ...t, chatId: (L = x.chat) == null ? void 0 : L.id },
|
|
1013
1011
|
r
|
|
1014
1012
|
);
|
|
1015
|
-
return { chatResult:
|
|
1013
|
+
return { chatResult: x, streamingManager: j };
|
|
1016
1014
|
} else {
|
|
1017
|
-
const
|
|
1015
|
+
const x = se(
|
|
1018
1016
|
e,
|
|
1019
1017
|
a,
|
|
1020
1018
|
r,
|
|
1021
1019
|
t.mode,
|
|
1022
1020
|
t.persistentChat,
|
|
1023
1021
|
o
|
|
1024
|
-
),
|
|
1025
|
-
return { chatResult:
|
|
1022
|
+
), j = ge(e, t, r), [B, D] = await Promise.all([x, j]);
|
|
1023
|
+
return { chatResult: B, streamingManager: D };
|
|
1026
1024
|
}
|
|
1027
1025
|
}, { chatResult: c, streamingManager: n } = await i(), { chat: s, chatMode: d } = c;
|
|
1028
|
-
return d && d !== t.mode && (t.mode = d, (
|
|
1026
|
+
return d && d !== t.mode && (t.mode = d, (h = (l = t.callbacks).onModeChange) == null || h.call(l, d), d !== _.Functional) ? ((b = (y = t.callbacks).onError) == null || b.call(y, new Ee(d)), n == null || n.disconnect(), { chat: s }) : { chat: s, streamingManager: n };
|
|
1029
1027
|
}
|
|
1030
|
-
async function
|
|
1031
|
-
var
|
|
1028
|
+
async function Lt(e, t) {
|
|
1029
|
+
var D, K, G;
|
|
1032
1030
|
let a = !0, r = null;
|
|
1033
|
-
const o = t.mixpanelKey ||
|
|
1031
|
+
const o = t.mixpanelKey || Ne, i = t.wsURL || Fe, c = t.baseURL || te, n = {
|
|
1034
1032
|
messages: [],
|
|
1035
|
-
chatMode: t.mode ||
|
|
1036
|
-
}, s =
|
|
1033
|
+
chatMode: t.mode || _.Functional
|
|
1034
|
+
}, s = Qe({
|
|
1037
1035
|
token: o,
|
|
1038
1036
|
agentId: e,
|
|
1039
1037
|
isEnabled: t.enableAnalitics,
|
|
1040
1038
|
externalId: t.externalId,
|
|
1041
1039
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1042
|
-
}), d = Date.now();
|
|
1043
|
-
fe(() => {
|
|
1044
|
-
s.track("agent-sdk", { event: "init" }, d);
|
|
1045
1040
|
});
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1041
|
+
s.track("agent-sdk", { event: "init" });
|
|
1042
|
+
const d = He(t.auth, c, t.callbacks.onError, t.externalId), l = await d.getById(e), h = le(l.presenter.type);
|
|
1043
|
+
s.enrich(qe(l));
|
|
1044
|
+
const { onMessage: y, clearQueue: b } = st(
|
|
1049
1045
|
s,
|
|
1050
1046
|
n,
|
|
1051
1047
|
t,
|
|
1052
|
-
|
|
1048
|
+
l,
|
|
1053
1049
|
() => {
|
|
1054
|
-
var
|
|
1055
|
-
return (
|
|
1050
|
+
var u;
|
|
1051
|
+
return (u = n.socketManager) == null ? void 0 : u.disconnect();
|
|
1056
1052
|
}
|
|
1057
1053
|
);
|
|
1058
|
-
n.messages =
|
|
1059
|
-
const
|
|
1060
|
-
r =
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
(B = (P = t.callbacks).onConnectionStateChange) == null || B.call(P, M.Connecting), N.reset(), f && !a && (delete n.chat, (R = ($ = t.callbacks).onNewMessage) == null || R.call($, [...n.messages], "answer"));
|
|
1068
|
-
const D = t.mode === T.DirectPlayback || y ? Promise.resolve(void 0) : at(
|
|
1054
|
+
n.messages = Ze(t.initialMessages), (K = (D = t.callbacks).onNewMessage) == null || K.call(D, [...n.messages], "answer");
|
|
1055
|
+
const L = (u) => {
|
|
1056
|
+
r = u;
|
|
1057
|
+
};
|
|
1058
|
+
s.track("agent-sdk", { event: "loaded", ...Ve(l) });
|
|
1059
|
+
async function x(u) {
|
|
1060
|
+
var S, $, z, C, E, J, R;
|
|
1061
|
+
($ = (S = t.callbacks).onConnectionStateChange) == null || $.call(S, I.Connecting), N.reset(), u && !a && (delete n.chat, (C = (z = t.callbacks).onNewMessage) == null || C.call(z, [...n.messages], "answer"));
|
|
1062
|
+
const k = t.mode === _.DirectPlayback || h ? Promise.resolve(void 0) : nt(
|
|
1069
1063
|
t.auth,
|
|
1070
1064
|
i,
|
|
1071
|
-
{ onMessage:
|
|
1065
|
+
{ onMessage: y, onError: t.callbacks.onError },
|
|
1072
1066
|
t.externalId
|
|
1073
|
-
),
|
|
1074
|
-
() =>
|
|
1075
|
-
|
|
1067
|
+
), v = ne(
|
|
1068
|
+
() => jt(
|
|
1069
|
+
l,
|
|
1076
1070
|
{
|
|
1077
1071
|
...t,
|
|
1078
|
-
callbacks: { ...t.callbacks, onVideoIdChange:
|
|
1072
|
+
callbacks: { ...t.callbacks, onVideoIdChange: L, onMessage: y }
|
|
1079
1073
|
},
|
|
1080
|
-
|
|
1074
|
+
d,
|
|
1081
1075
|
s,
|
|
1082
1076
|
n.chat
|
|
1083
1077
|
),
|
|
1084
1078
|
{
|
|
1085
1079
|
limit: 3,
|
|
1086
|
-
timeout:
|
|
1080
|
+
timeout: $e,
|
|
1087
1081
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1088
1082
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1089
|
-
shouldRetryFn: (
|
|
1083
|
+
shouldRetryFn: (M) => (M == null ? void 0 : M.message) !== "Could not connect" && M.status !== 429,
|
|
1090
1084
|
delayMs: 1e3
|
|
1091
1085
|
}
|
|
1092
|
-
).catch((
|
|
1093
|
-
var
|
|
1094
|
-
throw
|
|
1095
|
-
}), [
|
|
1096
|
-
|
|
1097
|
-
chatId:
|
|
1098
|
-
streamId:
|
|
1086
|
+
).catch((M) => {
|
|
1087
|
+
var U, F;
|
|
1088
|
+
throw B(_.Maintenance), (F = (U = t.callbacks).onConnectionStateChange) == null || F.call(U, I.Fail), M;
|
|
1089
|
+
}), [T, { streamingManager: g, chat: p }] = await Promise.all([k, v]);
|
|
1090
|
+
p && p.id !== ((E = n.chat) == null ? void 0 : E.id) && ((R = (J = t.callbacks).onNewChat) == null || R.call(J, p.id)), n.streamingManager = g, n.socketManager = T, n.chat = p, a = !1, s.enrich({
|
|
1091
|
+
chatId: p == null ? void 0 : p.id,
|
|
1092
|
+
streamId: g == null ? void 0 : g.streamId,
|
|
1099
1093
|
mode: n.chatMode
|
|
1100
|
-
}),
|
|
1094
|
+
}), B((p == null ? void 0 : p.chat_mode) ?? t.mode ?? _.Functional);
|
|
1101
1095
|
}
|
|
1102
|
-
async function
|
|
1103
|
-
var
|
|
1104
|
-
(
|
|
1096
|
+
async function j() {
|
|
1097
|
+
var u, k, v, T;
|
|
1098
|
+
(u = n.socketManager) == null || u.disconnect(), await ((k = n.streamingManager) == null ? void 0 : k.disconnect()), delete n.streamingManager, delete n.socketManager, (T = (v = t.callbacks).onConnectionStateChange) == null || T.call(v, I.Disconnected);
|
|
1105
1099
|
}
|
|
1106
|
-
async function
|
|
1107
|
-
var
|
|
1108
|
-
|
|
1100
|
+
async function B(u) {
|
|
1101
|
+
var k, v;
|
|
1102
|
+
u !== n.chatMode && (s.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== _.Functional && await j(), (v = (k = t.callbacks).onModeChange) == null || v.call(k, u));
|
|
1109
1103
|
}
|
|
1110
1104
|
return {
|
|
1111
|
-
agent:
|
|
1105
|
+
agent: l,
|
|
1112
1106
|
getStreamType: () => {
|
|
1113
|
-
var
|
|
1114
|
-
return (
|
|
1107
|
+
var u;
|
|
1108
|
+
return (u = n.streamingManager) == null ? void 0 : u.streamType;
|
|
1115
1109
|
},
|
|
1116
1110
|
getIsInterruptAvailable: () => {
|
|
1117
|
-
var
|
|
1118
|
-
return ((
|
|
1111
|
+
var u;
|
|
1112
|
+
return ((u = n.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
|
|
1119
1113
|
},
|
|
1120
1114
|
getIsTriggersAvailable: () => {
|
|
1121
|
-
var
|
|
1122
|
-
return ((
|
|
1115
|
+
var u;
|
|
1116
|
+
return ((u = n.streamingManager) == null ? void 0 : u.triggersAvailable) ?? !1;
|
|
1123
1117
|
},
|
|
1124
|
-
starterMessages: ((
|
|
1125
|
-
getSTTToken: () =>
|
|
1126
|
-
changeMode:
|
|
1118
|
+
starterMessages: ((G = l.knowledge) == null ? void 0 : G.starter_message) || [],
|
|
1119
|
+
getSTTToken: () => d.getSTTToken(l.id),
|
|
1120
|
+
changeMode: B,
|
|
1127
1121
|
enrichAnalytics: s.enrich,
|
|
1128
1122
|
async connect() {
|
|
1129
|
-
await
|
|
1123
|
+
await x(!0), s.track("agent-chat", {
|
|
1130
1124
|
event: "connect",
|
|
1131
1125
|
mode: n.chatMode
|
|
1132
1126
|
});
|
|
1133
1127
|
},
|
|
1134
1128
|
async reconnect() {
|
|
1135
|
-
await
|
|
1129
|
+
await j(), await x(!1), s.track("agent-chat", {
|
|
1136
1130
|
event: "reconnect",
|
|
1137
1131
|
mode: n.chatMode
|
|
1138
1132
|
});
|
|
1139
1133
|
},
|
|
1140
1134
|
async disconnect() {
|
|
1141
|
-
await
|
|
1135
|
+
await j(), s.track("agent-chat", {
|
|
1142
1136
|
event: "disconnect",
|
|
1143
1137
|
mode: n.chatMode
|
|
1144
1138
|
});
|
|
1145
1139
|
},
|
|
1146
|
-
async chat(
|
|
1147
|
-
var
|
|
1148
|
-
const
|
|
1149
|
-
if (
|
|
1150
|
-
throw new
|
|
1151
|
-
if (
|
|
1152
|
-
throw new
|
|
1153
|
-
if (
|
|
1154
|
-
throw new
|
|
1155
|
-
if (n.chatMode ===
|
|
1156
|
-
throw new
|
|
1157
|
-
if (![
|
|
1140
|
+
async chat(u) {
|
|
1141
|
+
var g, p, S, $, z;
|
|
1142
|
+
const k = () => {
|
|
1143
|
+
if (ve(t.mode))
|
|
1144
|
+
throw new H(`${t.mode} is enabled, chat is disabled`);
|
|
1145
|
+
if (u.length >= 800)
|
|
1146
|
+
throw new H("Message cannot be more than 800 characters");
|
|
1147
|
+
if (u.length === 0)
|
|
1148
|
+
throw new H("Message cannot be empty");
|
|
1149
|
+
if (n.chatMode === _.Maintenance)
|
|
1150
|
+
throw new H("Chat is in maintenance mode");
|
|
1151
|
+
if (![_.TextOnly, _.Playground].includes(n.chatMode)) {
|
|
1158
1152
|
if (!n.streamingManager)
|
|
1159
|
-
throw new
|
|
1153
|
+
throw new H("Streaming manager is not initialized");
|
|
1160
1154
|
if (!n.chat)
|
|
1161
|
-
throw new
|
|
1155
|
+
throw new H("Chat is not initialized");
|
|
1162
1156
|
}
|
|
1163
|
-
},
|
|
1164
|
-
var
|
|
1157
|
+
}, v = async () => {
|
|
1158
|
+
var C, E;
|
|
1165
1159
|
if (!n.chat) {
|
|
1166
|
-
const
|
|
1167
|
-
u,
|
|
1160
|
+
const J = await se(
|
|
1168
1161
|
l,
|
|
1162
|
+
d,
|
|
1169
1163
|
s,
|
|
1170
1164
|
n.chatMode,
|
|
1171
1165
|
t.persistentChat
|
|
1172
1166
|
);
|
|
1173
|
-
if (!
|
|
1174
|
-
throw new
|
|
1175
|
-
n.chat =
|
|
1167
|
+
if (!J.chat)
|
|
1168
|
+
throw new Ie(n.chatMode, !!t.persistentChat);
|
|
1169
|
+
n.chat = J.chat, (E = (C = t.callbacks).onNewChat) == null || E.call(C, n.chat.id);
|
|
1176
1170
|
}
|
|
1177
1171
|
return n.chat.id;
|
|
1178
|
-
},
|
|
1179
|
-
var
|
|
1180
|
-
return await ((
|
|
1172
|
+
}, T = async (C, E) => ne(h ? async () => {
|
|
1173
|
+
var R, M;
|
|
1174
|
+
return await ((M = (R = n.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : M.call(R, u)), Promise.resolve({});
|
|
1181
1175
|
} : async () => {
|
|
1182
|
-
var
|
|
1183
|
-
return
|
|
1184
|
-
|
|
1185
|
-
|
|
1176
|
+
var R, M;
|
|
1177
|
+
return d.chat(
|
|
1178
|
+
l.id,
|
|
1179
|
+
E,
|
|
1186
1180
|
{
|
|
1187
1181
|
chatMode: n.chatMode,
|
|
1188
|
-
streamId: (
|
|
1189
|
-
sessionId: (
|
|
1190
|
-
messages:
|
|
1182
|
+
streamId: (R = n.streamingManager) == null ? void 0 : R.streamId,
|
|
1183
|
+
sessionId: (M = n.streamingManager) == null ? void 0 : M.sessionId,
|
|
1184
|
+
messages: C.map(({ matches: U, ...F }) => F)
|
|
1191
1185
|
},
|
|
1192
1186
|
{
|
|
1193
|
-
...
|
|
1187
|
+
...Ce(n.chatMode),
|
|
1194
1188
|
skipErrorHandler: !0
|
|
1195
1189
|
}
|
|
1196
1190
|
);
|
|
1197
1191
|
}, {
|
|
1198
1192
|
limit: 2,
|
|
1199
|
-
shouldRetryFn: (
|
|
1200
|
-
var
|
|
1201
|
-
const
|
|
1202
|
-
return !((
|
|
1193
|
+
shouldRetryFn: (R) => {
|
|
1194
|
+
var F, X, f, m;
|
|
1195
|
+
const M = (F = R == null ? void 0 : R.message) == null ? void 0 : F.includes("missing or invalid session_id");
|
|
1196
|
+
return !((X = R == null ? void 0 : R.message) == null ? void 0 : X.includes("Stream Error")) && !M ? ((m = (f = t.callbacks).onError) == null || m.call(f, R), !1) : !0;
|
|
1203
1197
|
},
|
|
1204
1198
|
onRetry: async () => {
|
|
1205
|
-
await
|
|
1199
|
+
await j(), await x(!1);
|
|
1206
1200
|
}
|
|
1207
1201
|
});
|
|
1208
1202
|
try {
|
|
1209
|
-
|
|
1210
|
-
id:
|
|
1203
|
+
b(), k(), n.messages.push({
|
|
1204
|
+
id: q(),
|
|
1211
1205
|
role: "user",
|
|
1212
|
-
content:
|
|
1206
|
+
content: u,
|
|
1213
1207
|
created_at: new Date(N.update()).toISOString()
|
|
1214
|
-
}), (
|
|
1215
|
-
const
|
|
1208
|
+
}), (p = (g = t.callbacks).onNewMessage) == null || p.call(g, [...n.messages], "user");
|
|
1209
|
+
const C = await v(), E = await T([...n.messages], C);
|
|
1216
1210
|
return n.messages.push({
|
|
1217
|
-
id:
|
|
1211
|
+
id: q(),
|
|
1218
1212
|
role: "assistant",
|
|
1219
|
-
content:
|
|
1213
|
+
content: E.result || "",
|
|
1220
1214
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1221
|
-
context:
|
|
1222
|
-
matches:
|
|
1215
|
+
context: E.context,
|
|
1216
|
+
matches: E.matches
|
|
1223
1217
|
}), s.track("agent-message-send", {
|
|
1224
1218
|
event: "success",
|
|
1225
1219
|
messages: n.messages.length + 1
|
|
1226
|
-
}),
|
|
1220
|
+
}), E.result && (($ = (S = t.callbacks).onNewMessage) == null || $.call(S, [...n.messages], "answer"), s.track("agent-message-received", {
|
|
1227
1221
|
latency: N.get(!0),
|
|
1228
1222
|
messages: n.messages.length
|
|
1229
|
-
})),
|
|
1230
|
-
} catch (
|
|
1231
|
-
throw ((
|
|
1223
|
+
})), E;
|
|
1224
|
+
} catch (C) {
|
|
1225
|
+
throw ((z = n.messages[n.messages.length - 1]) == null ? void 0 : z.role) === "assistant" && n.messages.pop(), s.track("agent-message-send", {
|
|
1232
1226
|
event: "error",
|
|
1233
1227
|
messages: n.messages.length
|
|
1234
|
-
}),
|
|
1228
|
+
}), C;
|
|
1235
1229
|
}
|
|
1236
1230
|
},
|
|
1237
|
-
rate(
|
|
1238
|
-
var
|
|
1239
|
-
const
|
|
1231
|
+
rate(u, k, v) {
|
|
1232
|
+
var p, S, $, z;
|
|
1233
|
+
const T = n.messages.find((C) => C.id === u);
|
|
1240
1234
|
if (n.chat) {
|
|
1241
|
-
if (!
|
|
1235
|
+
if (!T)
|
|
1242
1236
|
throw new Error("Message not found");
|
|
1243
1237
|
} else throw new Error("Chat is not initialized");
|
|
1244
|
-
const
|
|
1238
|
+
const g = ((p = T.matches) == null ? void 0 : p.map((C) => [C.document_id, C.id])) ?? [];
|
|
1245
1239
|
return s.track("agent-rate", {
|
|
1246
|
-
event:
|
|
1247
|
-
thumb:
|
|
1248
|
-
knowledge_id: ((
|
|
1249
|
-
matches:
|
|
1250
|
-
score:
|
|
1251
|
-
}),
|
|
1252
|
-
knowledge_id: ((
|
|
1253
|
-
message_id:
|
|
1254
|
-
matches:
|
|
1255
|
-
score:
|
|
1256
|
-
}) :
|
|
1257
|
-
knowledge_id: ((
|
|
1258
|
-
message_id:
|
|
1259
|
-
matches:
|
|
1260
|
-
score:
|
|
1240
|
+
event: v ? "update" : "create",
|
|
1241
|
+
thumb: k === 1 ? "up" : "down",
|
|
1242
|
+
knowledge_id: ((S = l.knowledge) == null ? void 0 : S.id) ?? "",
|
|
1243
|
+
matches: g,
|
|
1244
|
+
score: k
|
|
1245
|
+
}), v ? d.updateRating(l.id, n.chat.id, v, {
|
|
1246
|
+
knowledge_id: (($ = l.knowledge) == null ? void 0 : $.id) ?? "",
|
|
1247
|
+
message_id: u,
|
|
1248
|
+
matches: g,
|
|
1249
|
+
score: k
|
|
1250
|
+
}) : d.createRating(l.id, n.chat.id, {
|
|
1251
|
+
knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1252
|
+
message_id: u,
|
|
1253
|
+
matches: g,
|
|
1254
|
+
score: k
|
|
1261
1255
|
});
|
|
1262
1256
|
},
|
|
1263
|
-
deleteRate(
|
|
1257
|
+
deleteRate(u) {
|
|
1264
1258
|
if (!n.chat)
|
|
1265
1259
|
throw new Error("Chat is not initialized");
|
|
1266
|
-
return s.track("agent-rate-delete", { type: "text" }),
|
|
1260
|
+
return s.track("agent-rate-delete", { type: "text" }), d.deleteRating(l.id, n.chat.id, u);
|
|
1267
1261
|
},
|
|
1268
|
-
async speak(
|
|
1269
|
-
var
|
|
1270
|
-
function
|
|
1271
|
-
if (typeof
|
|
1272
|
-
if (!
|
|
1262
|
+
async speak(u) {
|
|
1263
|
+
var g, p, S;
|
|
1264
|
+
function k() {
|
|
1265
|
+
if (typeof u == "string") {
|
|
1266
|
+
if (!l.presenter.voice)
|
|
1273
1267
|
throw new Error("Presenter voice is not initialized");
|
|
1274
1268
|
return {
|
|
1275
1269
|
type: "text",
|
|
1276
|
-
provider:
|
|
1277
|
-
input:
|
|
1270
|
+
provider: l.presenter.voice,
|
|
1271
|
+
input: u,
|
|
1278
1272
|
ssml: !1
|
|
1279
1273
|
};
|
|
1280
1274
|
}
|
|
1281
|
-
if (
|
|
1282
|
-
if (!
|
|
1275
|
+
if (u.type === "text" && !u.provider) {
|
|
1276
|
+
if (!l.presenter.voice)
|
|
1283
1277
|
throw new Error("Presenter voice is not initialized");
|
|
1284
1278
|
return {
|
|
1285
1279
|
type: "text",
|
|
1286
|
-
provider:
|
|
1287
|
-
input:
|
|
1288
|
-
ssml:
|
|
1280
|
+
provider: l.presenter.voice,
|
|
1281
|
+
input: u.input,
|
|
1282
|
+
ssml: u.ssml
|
|
1289
1283
|
};
|
|
1290
1284
|
}
|
|
1291
|
-
return
|
|
1285
|
+
return u;
|
|
1292
1286
|
}
|
|
1293
|
-
const
|
|
1294
|
-
if (s.track("agent-speak",
|
|
1295
|
-
id:
|
|
1287
|
+
const v = k();
|
|
1288
|
+
if (s.track("agent-speak", v), N.update(), n.messages && v.type === "text" && (n.messages.push({
|
|
1289
|
+
id: q(),
|
|
1296
1290
|
role: "assistant",
|
|
1297
|
-
content:
|
|
1291
|
+
content: v.input,
|
|
1298
1292
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1299
|
-
}), (
|
|
1293
|
+
}), (p = (g = t.callbacks).onNewMessage) == null || p.call(g, [...n.messages], "answer")), Je(n.chatMode))
|
|
1300
1294
|
return {
|
|
1301
1295
|
duration: 0,
|
|
1302
1296
|
video_id: "",
|
|
@@ -1305,49 +1299,49 @@ async function xt(e, t) {
|
|
|
1305
1299
|
if (!n.streamingManager)
|
|
1306
1300
|
throw new Error("Please connect to the agent first");
|
|
1307
1301
|
return n.streamingManager.speak({
|
|
1308
|
-
script:
|
|
1309
|
-
metadata: { chat_id: (
|
|
1302
|
+
script: v,
|
|
1303
|
+
metadata: { chat_id: (S = n.chat) == null ? void 0 : S.id, agent_id: l.id }
|
|
1310
1304
|
});
|
|
1311
1305
|
},
|
|
1312
|
-
async interrupt({ type:
|
|
1313
|
-
var
|
|
1314
|
-
|
|
1315
|
-
const
|
|
1306
|
+
async interrupt({ type: u }) {
|
|
1307
|
+
var v, T, g;
|
|
1308
|
+
Ge(n.streamingManager, (v = n.streamingManager) == null ? void 0 : v.streamType, r);
|
|
1309
|
+
const k = n.messages[n.messages.length - 1];
|
|
1316
1310
|
s.track("agent-video-interrupt", {
|
|
1317
|
-
type:
|
|
1311
|
+
type: u || "click",
|
|
1318
1312
|
video_duration_to_interrupt: ie.get(!0),
|
|
1319
1313
|
message_duration_to_interrupt: N.get(!0)
|
|
1320
|
-
}),
|
|
1314
|
+
}), k.interrupted = !0, (g = (T = t.callbacks).onNewMessage) == null || g.call(T, [...n.messages], "answer"), et(n.streamingManager, r);
|
|
1321
1315
|
}
|
|
1322
1316
|
};
|
|
1323
1317
|
}
|
|
1324
1318
|
export {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1319
|
+
O as A,
|
|
1320
|
+
I as C,
|
|
1321
|
+
Le as D,
|
|
1322
|
+
be as K,
|
|
1323
|
+
Te as P,
|
|
1324
|
+
je as R,
|
|
1325
|
+
W as S,
|
|
1332
1326
|
de as T,
|
|
1333
|
-
|
|
1334
|
-
V,
|
|
1335
|
-
|
|
1336
|
-
|
|
1327
|
+
_e as U,
|
|
1328
|
+
H as V,
|
|
1329
|
+
Me as W,
|
|
1330
|
+
ct as a,
|
|
1337
1331
|
Z as b,
|
|
1338
|
-
|
|
1332
|
+
ke as c,
|
|
1339
1333
|
te as d,
|
|
1340
1334
|
w as e,
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1335
|
+
P as f,
|
|
1336
|
+
V as g,
|
|
1337
|
+
Ie as h,
|
|
1338
|
+
Ee as i,
|
|
1339
|
+
Lt as j,
|
|
1340
|
+
Ae as k,
|
|
1341
|
+
_ as l,
|
|
1342
|
+
Pe as m,
|
|
1343
|
+
he as n,
|
|
1344
|
+
bt as o,
|
|
1345
|
+
xe as p,
|
|
1346
|
+
Be as q
|
|
1353
1347
|
};
|