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