@d-id/client-sdk 1.1.48 → 1.1.49-staging.216
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +663 -665
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
1
|
+
var nt = Object.defineProperty;
|
|
2
|
+
var rt = (e, t, i) => t in e ? nt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var me = (e, t, i) => rt(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
+
class Se extends Error {
|
|
5
5
|
constructor({ kind: i, description: r, error: o }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: r }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
me(this, "kind");
|
|
8
|
+
me(this, "description");
|
|
9
|
+
me(this, "error");
|
|
10
10
|
this.kind = i, this.description = r, this.error = o;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class it extends Se {
|
|
14
14
|
constructor(t, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,25 +18,25 @@ class st extends Ce {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class at extends Se {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class le extends Se {
|
|
27
27
|
constructor(i, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
me(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class ot extends Se {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var st = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(st || {}), ct = /* @__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))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(dt || {}), ut = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ut || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), lt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(lt || {}), ft = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ft || {}), mt = /* @__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))(mt || {}), He = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(He || {});
|
|
39
|
+
const Sn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,13 +48,13 @@ const Dn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
52
|
-
const
|
|
53
|
-
},
|
|
51
|
+
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(O || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", 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))(A || {}), T = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(T || {}), ie = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ie || {}), ke = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ke || {}), gt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(gt || {}), ht = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ht || {});
|
|
52
|
+
const pt = 45 * 1e3, wt = "X-Playground-Chat", he = "https://api.d-id.com", yt = "wss://notifications.d-id.com", vt = "79f81a83a67430be2bc0fd61042b8faa", Ct = (...e) => {
|
|
53
|
+
}, qe = (e) => new Promise((t) => setTimeout(t, e)), fe = (e = 16) => {
|
|
54
54
|
const t = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(t), Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
|
-
},
|
|
57
|
-
function
|
|
56
|
+
}, Qe = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, _e = (e) => e === He.Expressive, St = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), Xe = (e) => e && [x.DirectPlayback, x.Off].includes(e);
|
|
57
|
+
function kt(e, t) {
|
|
58
58
|
let i;
|
|
59
59
|
return {
|
|
60
60
|
promise: new Promise((o, a) => {
|
|
@@ -63,7 +63,7 @@ function Mt(e, t) {
|
|
|
63
63
|
clear: () => clearTimeout(i)
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
async function
|
|
66
|
+
async function De(e, t) {
|
|
67
67
|
const i = {
|
|
68
68
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
69
69
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -78,12 +78,12 @@ async function Me(e, t) {
|
|
|
78
78
|
try {
|
|
79
79
|
if (!i.timeout)
|
|
80
80
|
return await e();
|
|
81
|
-
const { promise: a, clear: s } =
|
|
81
|
+
const { promise: a, clear: s } = kt(i.timeout, i.timeoutErrorMessage), d = e().finally(s);
|
|
82
82
|
return await Promise.race([d, a]);
|
|
83
83
|
} catch (a) {
|
|
84
84
|
if (r = a, !i.shouldRetryFn(a) || o >= i.limit)
|
|
85
85
|
throw a;
|
|
86
|
-
await
|
|
86
|
+
await qe(i.delayMs), i.onRetry(a);
|
|
87
87
|
}
|
|
88
88
|
throw r;
|
|
89
89
|
}
|
|
@@ -92,43 +92,43 @@ function Ee(e) {
|
|
|
92
92
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
93
93
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
94
94
|
if (!t) {
|
|
95
|
-
let i =
|
|
95
|
+
let i = fe();
|
|
96
96
|
window.localStorage.setItem("did_external_key_id", i), t = i;
|
|
97
97
|
}
|
|
98
98
|
return t;
|
|
99
99
|
}
|
|
100
|
-
let
|
|
101
|
-
function
|
|
100
|
+
let Rt = fe();
|
|
101
|
+
function Ye(e, t) {
|
|
102
102
|
if (e.type === "bearer")
|
|
103
103
|
return `Bearer ${e.token}`;
|
|
104
104
|
if (e.type === "basic")
|
|
105
105
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
106
106
|
if (e.type === "key")
|
|
107
|
-
return `Client-Key ${e.clientKey}.${Ee(t)}_${
|
|
107
|
+
return `Client-Key ${e.clientKey}.${Ee(t)}_${Rt}`;
|
|
108
108
|
throw new Error(`Unknown auth type: ${e}`);
|
|
109
109
|
}
|
|
110
|
-
const
|
|
110
|
+
const Dt = (e) => De(e, {
|
|
111
111
|
limit: 3,
|
|
112
112
|
delayMs: 1e3,
|
|
113
113
|
timeout: 0,
|
|
114
114
|
shouldRetryFn: (t) => t.status === 429
|
|
115
115
|
});
|
|
116
|
-
function
|
|
116
|
+
function Ae(e, t = he, i, r) {
|
|
117
117
|
const o = async (a, s) => {
|
|
118
|
-
const { skipErrorHandler: d, ...n } = s || {}, c = await
|
|
118
|
+
const { skipErrorHandler: d, ...n } = s || {}, c = await Dt(
|
|
119
119
|
() => fetch(t + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
120
120
|
...n,
|
|
121
121
|
headers: {
|
|
122
122
|
...n.headers,
|
|
123
|
-
Authorization:
|
|
123
|
+
Authorization: Ye(e, r),
|
|
124
124
|
"Content-Type": "application/json"
|
|
125
125
|
}
|
|
126
126
|
})
|
|
127
127
|
);
|
|
128
128
|
if (!c.ok) {
|
|
129
|
-
let
|
|
130
|
-
const
|
|
131
|
-
throw i && !d && i(
|
|
129
|
+
let g = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
|
|
130
|
+
const p = new Error(g);
|
|
131
|
+
throw i && !d && i(p, { url: a, options: n, headers: c.headers }), p;
|
|
132
132
|
}
|
|
133
133
|
return c.json();
|
|
134
134
|
};
|
|
@@ -147,8 +147,8 @@ function Le(e, t = pe, i, r) {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
function
|
|
151
|
-
const o =
|
|
150
|
+
function Et(e, t = he, i, r) {
|
|
151
|
+
const o = Ae(e, `${t}/agents`, i, r);
|
|
152
152
|
return {
|
|
153
153
|
create(a, s) {
|
|
154
154
|
return o.post("/", a, s);
|
|
@@ -185,7 +185,7 @@ function Tt(e, t = pe, i, r) {
|
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function Mt(e) {
|
|
189
189
|
var o, a, s, d;
|
|
190
190
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
191
191
|
const n = navigator.platform;
|
|
@@ -196,18 +196,18 @@ function _t(e) {
|
|
|
196
196
|
isMobile: `${t() == "Mobile"}`,
|
|
197
197
|
browser: navigator.userAgent,
|
|
198
198
|
origin: window.location.origin,
|
|
199
|
-
agentType:
|
|
199
|
+
agentType: Qe(r),
|
|
200
200
|
agentVoice: {
|
|
201
201
|
voiceId: (a = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : a.voice_id,
|
|
202
202
|
provider: (d = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : d.type
|
|
203
203
|
}
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
|
-
function
|
|
206
|
+
function It(e) {
|
|
207
207
|
var i, r, o, a, s, d;
|
|
208
208
|
const t = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
209
209
|
return {
|
|
210
|
-
agentType:
|
|
210
|
+
agentType: Qe(e.presenter),
|
|
211
211
|
owner_id: e.owner_id ?? "",
|
|
212
212
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
213
213
|
behavior: {
|
|
@@ -226,25 +226,24 @@ function At(e) {
|
|
|
226
226
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
227
227
|
};
|
|
228
228
|
}
|
|
229
|
-
const
|
|
230
|
-
function
|
|
231
|
-
var n, c,
|
|
229
|
+
const Tt = (e) => e.reduce((t, i) => t + i, 0), ze = (e) => Tt(e) / e.length;
|
|
230
|
+
function _t(e, t, i) {
|
|
231
|
+
var n, c, g;
|
|
232
232
|
const { event: r, ...o } = e, { template: a } = (t == null ? void 0 : t.llm) || {}, { language: s } = ((n = t == null ? void 0 : t.presenter) == null ? void 0 : n.voice) || {};
|
|
233
233
|
return {
|
|
234
234
|
...o,
|
|
235
235
|
llm: { ...o.llm, template: a },
|
|
236
236
|
script: { ...o.script, provider: { ...(c = o == null ? void 0 : o.script) == null ? void 0 : c.provider, language: s } },
|
|
237
|
-
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (
|
|
237
|
+
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (g = t == null ? void 0 : t.presenter) == null ? void 0 : g.stitch : void 0,
|
|
238
238
|
...i
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
|
-
function
|
|
241
|
+
function Ke(e) {
|
|
242
242
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
243
243
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
244
|
+
const At = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
245
|
+
function Lt(e) {
|
|
246
|
+
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
|
|
248
247
|
return {
|
|
249
248
|
token: e.token || "testKey",
|
|
250
249
|
distinct_id: Ee(e.externalId),
|
|
@@ -254,14 +253,14 @@ function jt(e) {
|
|
|
254
253
|
...e.mixpanelAdditionalProperties || {}
|
|
255
254
|
},
|
|
256
255
|
isEnabled: e.isEnabled ?? !0,
|
|
257
|
-
getRandom:
|
|
258
|
-
enrich(
|
|
259
|
-
this.additionalProperties = { ...this.additionalProperties, ...
|
|
256
|
+
getRandom: fe,
|
|
257
|
+
enrich(r) {
|
|
258
|
+
this.additionalProperties = { ...this.additionalProperties, ...r };
|
|
260
259
|
},
|
|
261
|
-
async track(
|
|
260
|
+
async track(r, o, a) {
|
|
262
261
|
if (!this.isEnabled)
|
|
263
262
|
return Promise.resolve();
|
|
264
|
-
const { audioPath:
|
|
263
|
+
const { audioPath: s, ...d } = o || {}, n = a || Date.now(), c = {
|
|
265
264
|
method: "POST",
|
|
266
265
|
headers: {
|
|
267
266
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -269,14 +268,14 @@ function jt(e) {
|
|
|
269
268
|
body: new URLSearchParams({
|
|
270
269
|
data: JSON.stringify([
|
|
271
270
|
{
|
|
272
|
-
event:
|
|
271
|
+
event: r,
|
|
273
272
|
properties: {
|
|
274
273
|
...this.additionalProperties,
|
|
275
|
-
...
|
|
274
|
+
...d,
|
|
276
275
|
agentId: this.agentId,
|
|
277
276
|
source: t,
|
|
278
277
|
token: this.token,
|
|
279
|
-
time:
|
|
278
|
+
time: n,
|
|
280
279
|
$insert_id: this.getRandom(),
|
|
281
280
|
origin: window.location.href,
|
|
282
281
|
"Screen Height": window.screen.height || window.innerWidth,
|
|
@@ -287,28 +286,25 @@ function jt(e) {
|
|
|
287
286
|
])
|
|
288
287
|
})
|
|
289
288
|
};
|
|
290
|
-
return fetch(
|
|
291
|
-
...n,
|
|
292
|
-
keepalive: !0
|
|
293
|
-
}).catch((c) => console.error("Analytics tracking error:", c)), Promise.resolve();
|
|
289
|
+
return fetch(At, c).catch((g) => console.error("Analytics tracking error:", g)), Promise.resolve();
|
|
294
290
|
},
|
|
295
|
-
linkTrack(
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
299
|
-
(
|
|
291
|
+
linkTrack(r, o, a, s) {
|
|
292
|
+
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), s.includes(a) || s.push(a);
|
|
293
|
+
const d = i[r];
|
|
294
|
+
if (d.events[a] = { props: o }, d.resolvedDependencies.push(a), s.every(
|
|
295
|
+
(c) => d.resolvedDependencies.includes(c)
|
|
300
296
|
)) {
|
|
301
|
-
const
|
|
302
|
-
this.track(
|
|
303
|
-
(
|
|
304
|
-
),
|
|
305
|
-
delete
|
|
297
|
+
const c = s.reduce((g, p) => d.events[p] ? { ...g, ...d.events[p].props } : g, {});
|
|
298
|
+
this.track(r, c), d.resolvedDependencies = d.resolvedDependencies.filter(
|
|
299
|
+
(g) => !s.includes(g)
|
|
300
|
+
), s.forEach((g) => {
|
|
301
|
+
delete d.events[g];
|
|
306
302
|
});
|
|
307
303
|
}
|
|
308
304
|
}
|
|
309
305
|
};
|
|
310
306
|
}
|
|
311
|
-
function
|
|
307
|
+
function Le() {
|
|
312
308
|
let e = 0;
|
|
313
309
|
return {
|
|
314
310
|
reset: () => e = 0,
|
|
@@ -316,22 +312,22 @@ function Pe() {
|
|
|
316
312
|
get: (t = !1) => t ? Date.now() - e : e
|
|
317
313
|
};
|
|
318
314
|
}
|
|
319
|
-
const
|
|
320
|
-
function
|
|
321
|
-
return e === x.Playground ? { headers: { [
|
|
315
|
+
const ne = Le(), Me = Le(), Ne = Le();
|
|
316
|
+
function Ge(e) {
|
|
317
|
+
return e === x.Playground ? { headers: { [wt]: "true" } } : {};
|
|
322
318
|
}
|
|
323
|
-
async function
|
|
319
|
+
async function Ze(e, t, i, r, o = !1, a) {
|
|
324
320
|
try {
|
|
325
|
-
return !a && !
|
|
321
|
+
return !a && !Xe(r) && (a = await t.newChat(e.id, { persist: o }, Ge(r)), i.track("agent-chat", {
|
|
326
322
|
event: "created",
|
|
327
323
|
chatId: a.id,
|
|
328
324
|
mode: r
|
|
329
325
|
})), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
|
|
330
326
|
} catch (s) {
|
|
331
|
-
throw
|
|
327
|
+
throw Pt(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
332
328
|
}
|
|
333
329
|
}
|
|
334
|
-
const
|
|
330
|
+
const Pt = (e) => {
|
|
335
331
|
try {
|
|
336
332
|
const t = JSON.parse(e.message);
|
|
337
333
|
return t == null ? void 0 : t.kind;
|
|
@@ -339,19 +335,19 @@ const $t = (e) => {
|
|
|
339
335
|
return "UnknownError";
|
|
340
336
|
}
|
|
341
337
|
};
|
|
342
|
-
function
|
|
338
|
+
function bt(e) {
|
|
343
339
|
return e && e.length > 0 ? e : [];
|
|
344
340
|
}
|
|
345
|
-
function
|
|
346
|
-
const o =
|
|
341
|
+
function jt(e, t, i, r) {
|
|
342
|
+
const o = Ae(e, `${t}/v2/agents/${i}`, r);
|
|
347
343
|
return {
|
|
348
344
|
async createStream(a) {
|
|
349
345
|
return o.post("/sessions", a);
|
|
350
346
|
}
|
|
351
347
|
};
|
|
352
348
|
}
|
|
353
|
-
const
|
|
354
|
-
function
|
|
349
|
+
const et = (e, t) => (i, r) => e && console.log(`[${t}] ${i}`, r ?? "");
|
|
350
|
+
function $t(e, t, i) {
|
|
355
351
|
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
356
352
|
return {
|
|
357
353
|
duration: r,
|
|
@@ -371,7 +367,7 @@ function Ft(e, t, i) {
|
|
|
371
367
|
lowFpsCount: i
|
|
372
368
|
};
|
|
373
369
|
}
|
|
374
|
-
function
|
|
370
|
+
function Bt(e) {
|
|
375
371
|
return e.filter(
|
|
376
372
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
377
373
|
).map((t) => {
|
|
@@ -382,7 +378,7 @@ function zt(e) {
|
|
|
382
378
|
};
|
|
383
379
|
});
|
|
384
380
|
}
|
|
385
|
-
function
|
|
381
|
+
function xt(e) {
|
|
386
382
|
let t = "", i = 0;
|
|
387
383
|
for (const r of e.values()) {
|
|
388
384
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -412,7 +408,7 @@ function Kt(e) {
|
|
|
412
408
|
}
|
|
413
409
|
return {};
|
|
414
410
|
}
|
|
415
|
-
function
|
|
411
|
+
function Ve(e, t, i) {
|
|
416
412
|
const r = e.map((n, c) => c === 0 ? i ? {
|
|
417
413
|
timestamp: n.timestamp,
|
|
418
414
|
duration: 0,
|
|
@@ -464,32 +460,32 @@ function Ne(e, t, i) {
|
|
|
464
460
|
framesPerSecond: n.framesPerSecond,
|
|
465
461
|
freezeCount: n.freezeCount - e[c - 1].freezeCount,
|
|
466
462
|
freezeDuration: n.freezeDuration - e[c - 1].freezeDuration
|
|
467
|
-
}), o =
|
|
463
|
+
}), o = Bt(r), a = o.reduce((n, c) => n + (c.causes.includes("low fps") ? 1 : 0), 0), s = r.filter((n) => !!n.avgJitterDelayInInterval).map((n) => n.avgJitterDelayInInterval), d = r.filter((n) => !!n.rtt).map((n) => n.rtt);
|
|
468
464
|
return {
|
|
469
465
|
webRTCStats: {
|
|
470
466
|
anomalies: o,
|
|
471
467
|
minRtt: Math.min(...d),
|
|
472
|
-
avgRtt:
|
|
468
|
+
avgRtt: ze(d),
|
|
473
469
|
maxRtt: Math.max(...d),
|
|
474
|
-
aggregateReport:
|
|
470
|
+
aggregateReport: $t(e[0], e[e.length - 1], a),
|
|
475
471
|
minJitterDelayInInterval: Math.min(...s),
|
|
476
472
|
maxJitterDelayInInterval: Math.max(...s),
|
|
477
|
-
avgJitterDelayInInterval:
|
|
473
|
+
avgJitterDelayInInterval: ze(s)
|
|
478
474
|
},
|
|
479
475
|
codec: e[0].codec,
|
|
480
476
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
481
477
|
};
|
|
482
478
|
}
|
|
483
|
-
const
|
|
484
|
-
function
|
|
479
|
+
const Ce = 100, Ft = Math.max(Math.ceil(400 / Ce), 1), zt = 0.25, Kt = 0.28;
|
|
480
|
+
function Nt() {
|
|
485
481
|
let e = 0, t, i, r = 0;
|
|
486
482
|
return (o) => {
|
|
487
483
|
for (const a of o.values())
|
|
488
484
|
if (a && a.type === "inbound-rtp" && a.kind === "video") {
|
|
489
485
|
const s = a.jitterBufferDelay, d = a.jitterBufferEmittedCount;
|
|
490
486
|
if (i && d > i) {
|
|
491
|
-
const
|
|
492
|
-
r =
|
|
487
|
+
const g = s - t, p = d - i;
|
|
488
|
+
r = g / p;
|
|
493
489
|
}
|
|
494
490
|
t = s, i = d;
|
|
495
491
|
const n = a.framesDecoded, c = n - e > 0;
|
|
@@ -498,32 +494,33 @@ function Ut() {
|
|
|
498
494
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
499
495
|
};
|
|
500
496
|
}
|
|
501
|
-
function
|
|
502
|
-
let a = null, s = [], d, n = 0, c = !1,
|
|
503
|
-
const
|
|
504
|
-
async function
|
|
505
|
-
const
|
|
506
|
-
if (!
|
|
497
|
+
function tt(e, t, i, r, o) {
|
|
498
|
+
let a = null, s = [], d, n = 0, c = !1, g = re.Unknown, p = re.Unknown, u = 0, v = 0;
|
|
499
|
+
const F = Nt();
|
|
500
|
+
async function P() {
|
|
501
|
+
const k = await e();
|
|
502
|
+
if (!k)
|
|
507
503
|
return;
|
|
508
|
-
const { isReceiving:
|
|
509
|
-
if (
|
|
510
|
-
n = 0,
|
|
511
|
-
else if (c && (n++, n >=
|
|
512
|
-
const
|
|
513
|
-
r == null || r(
|
|
504
|
+
const { isReceiving: S, avgJitterDelayInInterval: N, freezeCount: E } = F(k), b = xt(k);
|
|
505
|
+
if (S)
|
|
506
|
+
n = 0, u = E - v, p = N < zt ? re.Strong : N > Kt && u > 1 ? re.Weak : g, p !== g && (o == null || o(p), g = p, v += u, u = 0), c || (r == null || r(C.Start), d = s[s.length - 1], s = [], c = !0), s.push(b);
|
|
507
|
+
else if (c && (n++, n >= Ft)) {
|
|
508
|
+
const V = Ve(s, Ce, d);
|
|
509
|
+
r == null || r(C.Stop, V), t() || i(), v = E, c = !1;
|
|
514
510
|
}
|
|
515
511
|
}
|
|
516
512
|
return {
|
|
517
513
|
start: () => {
|
|
518
|
-
a || (a = setInterval(
|
|
514
|
+
a || (a = setInterval(P, Ce));
|
|
519
515
|
},
|
|
520
516
|
stop: () => {
|
|
521
517
|
a && (clearInterval(a), a = null);
|
|
522
518
|
},
|
|
523
|
-
getReport: () =>
|
|
519
|
+
getReport: () => Ve(s, Ce, d)
|
|
524
520
|
};
|
|
525
521
|
}
|
|
526
|
-
|
|
522
|
+
const Je = 2e4;
|
|
523
|
+
async function Vt() {
|
|
527
524
|
try {
|
|
528
525
|
return await import("./livekit-client.esm-C1GRQdZY.js");
|
|
529
526
|
} catch {
|
|
@@ -532,275 +529,275 @@ async function Wt() {
|
|
|
532
529
|
);
|
|
533
530
|
}
|
|
534
531
|
}
|
|
535
|
-
const
|
|
536
|
-
excellent:
|
|
537
|
-
good:
|
|
538
|
-
poor:
|
|
539
|
-
lost:
|
|
540
|
-
unknown:
|
|
541
|
-
},
|
|
532
|
+
const Jt = {
|
|
533
|
+
excellent: re.Strong,
|
|
534
|
+
good: re.Strong,
|
|
535
|
+
poor: re.Weak,
|
|
536
|
+
lost: re.Unknown,
|
|
537
|
+
unknown: re.Unknown
|
|
538
|
+
}, ge = JSON.stringify({
|
|
542
539
|
kind: "InternalServerError",
|
|
543
540
|
description: "Stream Error"
|
|
544
541
|
});
|
|
545
|
-
var
|
|
546
|
-
function
|
|
542
|
+
var Pe = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Pe || {});
|
|
543
|
+
function Ie(e, t, i) {
|
|
547
544
|
var r, o;
|
|
548
545
|
throw t("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, T.Fail, "internal:init-error"), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
|
|
549
546
|
}
|
|
550
|
-
async function
|
|
551
|
-
var
|
|
552
|
-
const r =
|
|
553
|
-
let
|
|
554
|
-
const
|
|
555
|
-
let
|
|
556
|
-
|
|
547
|
+
async function Ut(e, t, i) {
|
|
548
|
+
var be;
|
|
549
|
+
const r = et(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await Vt(), { callbacks: n, auth: c, baseURL: g, analytics: p } = i;
|
|
550
|
+
let u = null, v = !1;
|
|
551
|
+
const F = ie.Fluent;
|
|
552
|
+
let P = null, k = null, S = null, N = null, E = !1;
|
|
553
|
+
u = new o({
|
|
557
554
|
adaptiveStream: !1,
|
|
558
555
|
// Must be false to use mediaStreamTrack directly
|
|
559
556
|
dynacast: !0
|
|
560
557
|
});
|
|
561
|
-
let
|
|
562
|
-
const H =
|
|
563
|
-
let Z
|
|
564
|
-
const se = xt(c, w || pe, e, n.onError);
|
|
565
|
-
let N, u, C;
|
|
558
|
+
let b = null, V = O.Idle;
|
|
559
|
+
const H = jt(c, g || he, e, n.onError);
|
|
560
|
+
let z, Z, ee;
|
|
566
561
|
try {
|
|
567
|
-
const
|
|
562
|
+
const f = await H.createStream({
|
|
568
563
|
transport_provider: ke.Livekit,
|
|
569
564
|
chat_persist: t.chat_persist ?? !0
|
|
570
|
-
}), { id: h, session_token:
|
|
571
|
-
(
|
|
572
|
-
} catch (
|
|
573
|
-
|
|
565
|
+
}), { id: h, session_token: y, session_url: I } = f;
|
|
566
|
+
(be = n.onStreamCreated) == null || be.call(n, { session_id: h, stream_id: h, agent_id: e }), z = h, Z = y, ee = I, await u.prepareConnection(ee, Z);
|
|
567
|
+
} catch (f) {
|
|
568
|
+
Ie(f, r, n);
|
|
574
569
|
}
|
|
575
|
-
if (!
|
|
570
|
+
if (!ee || !Z || !z)
|
|
576
571
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
577
|
-
|
|
578
|
-
function
|
|
579
|
-
var
|
|
580
|
-
h != null && h.isLocal && (
|
|
572
|
+
u.on(a.ConnectionStateChanged, D).on(a.ConnectionQualityChanged, R).on(a.ParticipantConnected, K).on(a.ParticipantDisconnected, L).on(a.TrackSubscribed, q).on(a.TrackUnsubscribed, Q).on(a.DataReceived, j).on(a.MediaDevicesError, $).on(a.TranscriptionReceived, l).on(a.EncryptionError, G).on(a.TrackSubscriptionFailed, ae);
|
|
573
|
+
function l(f, h) {
|
|
574
|
+
var y;
|
|
575
|
+
h != null && h.isLocal && (ne.update(), V === O.Talking && ((y = n.onInterruptDetected) == null || y.call(n, { type: "audio" }), V = O.Idle));
|
|
581
576
|
}
|
|
582
577
|
try {
|
|
583
|
-
await
|
|
584
|
-
var
|
|
585
|
-
r(
|
|
578
|
+
await u.connect(ee, Z), r("LiveKit room joined successfully"), b = setTimeout(() => {
|
|
579
|
+
var f;
|
|
580
|
+
r(
|
|
581
|
+
`Track subscription timeout - no track subscribed within ${Je / 1e3} seconds after connect`
|
|
582
|
+
), b = null, p.track("connectivity-error", {
|
|
586
583
|
error: "Track subscription timeout",
|
|
587
|
-
sessionId:
|
|
588
|
-
}), (
|
|
589
|
-
},
|
|
590
|
-
} catch (
|
|
591
|
-
|
|
584
|
+
sessionId: z
|
|
585
|
+
}), (f = n.onError) == null || f.call(n, new Error("Track subscription timeout"), { sessionId: z }), Re("internal:track-subscription-timeout");
|
|
586
|
+
}, Je);
|
|
587
|
+
} catch (f) {
|
|
588
|
+
Ie(f, r, n);
|
|
592
589
|
}
|
|
593
|
-
|
|
594
|
-
"stream-type":
|
|
590
|
+
p.enrich({
|
|
591
|
+
"stream-type": F
|
|
595
592
|
});
|
|
596
|
-
function
|
|
597
|
-
var h,
|
|
598
|
-
switch (r("Connection state changed:",
|
|
593
|
+
function D(f) {
|
|
594
|
+
var h, y, I, U;
|
|
595
|
+
switch (r("Connection state changed:", f), f) {
|
|
599
596
|
case s.Connecting:
|
|
600
597
|
r("CALLBACK: onConnectionStateChange(Connecting)"), (h = n.onConnectionStateChange) == null || h.call(n, T.Connecting, "livekit:connecting");
|
|
601
598
|
break;
|
|
602
599
|
case s.Connected:
|
|
603
|
-
r("LiveKit room connected successfully"),
|
|
600
|
+
r("LiveKit room connected successfully"), v = !0;
|
|
604
601
|
break;
|
|
605
602
|
case s.Disconnected:
|
|
606
|
-
r("LiveKit room disconnected"),
|
|
603
|
+
r("LiveKit room disconnected"), v = !1, E = !1, (y = n.onConnectionStateChange) == null || y.call(n, T.Disconnected, "livekit:disconnected");
|
|
607
604
|
break;
|
|
608
605
|
case s.Reconnecting:
|
|
609
|
-
r("LiveKit room reconnecting..."), (
|
|
606
|
+
r("LiveKit room reconnecting..."), (I = n.onConnectionStateChange) == null || I.call(n, T.Connecting, "livekit:reconnecting");
|
|
610
607
|
break;
|
|
611
608
|
case s.SignalReconnecting:
|
|
612
609
|
r("LiveKit room signal reconnecting..."), (U = n.onConnectionStateChange) == null || U.call(n, T.Connecting, "livekit:signal-reconnecting");
|
|
613
610
|
break;
|
|
614
611
|
}
|
|
615
612
|
}
|
|
616
|
-
function
|
|
617
|
-
var
|
|
618
|
-
r("Connection quality:",
|
|
613
|
+
function R(f, h) {
|
|
614
|
+
var y;
|
|
615
|
+
r("Connection quality:", f), h != null && h.isLocal && ((y = n.onConnectivityStateChange) == null || y.call(n, Jt[f]));
|
|
619
616
|
}
|
|
620
|
-
function
|
|
621
|
-
r("Participant connected:",
|
|
617
|
+
function K(f) {
|
|
618
|
+
r("Participant connected:", f.identity);
|
|
622
619
|
}
|
|
623
|
-
function
|
|
624
|
-
r("Participant disconnected:",
|
|
620
|
+
function L(f) {
|
|
621
|
+
r("Participant disconnected:", f.identity), Re("livekit:participant-disconnected");
|
|
625
622
|
}
|
|
626
|
-
function
|
|
627
|
-
var
|
|
628
|
-
|
|
623
|
+
function _() {
|
|
624
|
+
var f;
|
|
625
|
+
N !== C.Start && (r("CALLBACK: onVideoStateChange(Start)"), N = C.Start, (f = n.onVideoStateChange) == null || f.call(n, C.Start));
|
|
629
626
|
}
|
|
630
|
-
function
|
|
627
|
+
function B(f) {
|
|
631
628
|
var h;
|
|
632
|
-
|
|
629
|
+
N !== C.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), N = C.Stop, (h = n.onVideoStateChange) == null || h.call(n, C.Stop, f));
|
|
633
630
|
}
|
|
634
|
-
function
|
|
635
|
-
var U,
|
|
636
|
-
r(`Track subscribed: ${
|
|
637
|
-
const
|
|
638
|
-
if (!
|
|
639
|
-
r(`No mediaStreamTrack available for ${
|
|
631
|
+
function q(f, h, y) {
|
|
632
|
+
var U, J, oe;
|
|
633
|
+
r(`Track subscribed: ${f.kind} from ${y.identity}`);
|
|
634
|
+
const I = f.mediaStreamTrack;
|
|
635
|
+
if (!I) {
|
|
636
|
+
r(`No mediaStreamTrack available for ${f.kind}`);
|
|
640
637
|
return;
|
|
641
638
|
}
|
|
642
|
-
|
|
643
|
-
() =>
|
|
644
|
-
() =>
|
|
645
|
-
|
|
646
|
-
(
|
|
647
|
-
r(`Video state change: ${
|
|
639
|
+
P ? (P.addTrack(I), r(`Added ${f.kind} track to shared MediaStream`)) : (P = new MediaStream([I]), r(`Created shared MediaStream with ${f.kind} track`)), f.kind === "video" && ((U = n.onStreamReady) == null || U.call(n), r("CALLBACK: onSrcObjectReady"), (J = n.onSrcObjectReady) == null || J.call(n, P), E || (E = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (oe = n.onConnectionStateChange) == null || oe.call(n, T.Connected, "livekit:track-subscribed")), S = tt(
|
|
640
|
+
() => f.getRTCStatsReport(),
|
|
641
|
+
() => v,
|
|
642
|
+
Ct,
|
|
643
|
+
(ue, ye) => {
|
|
644
|
+
r(`Video state change: ${ue}`), ue === C.Start ? (b && (clearTimeout(b), b = null, r("Track subscription timeout cleared")), _()) : ue === C.Stop && B(ye);
|
|
648
645
|
}
|
|
649
|
-
),
|
|
646
|
+
), S.start());
|
|
650
647
|
}
|
|
651
|
-
function
|
|
652
|
-
r(`Track unsubscribed: ${
|
|
648
|
+
function Q(f, h, y) {
|
|
649
|
+
r(`Track unsubscribed: ${f.kind} from ${y.identity}`), f.kind === "video" && (B(S == null ? void 0 : S.getReport()), S == null || S.stop(), S = null);
|
|
653
650
|
}
|
|
654
|
-
function
|
|
655
|
-
var
|
|
656
|
-
const U = new TextDecoder().decode(
|
|
651
|
+
function j(f, h, y, I) {
|
|
652
|
+
var J, oe, ue, ye, je, $e, Be, xe;
|
|
653
|
+
const U = new TextDecoder().decode(f);
|
|
657
654
|
try {
|
|
658
|
-
const
|
|
659
|
-
if (r("Data received:", { subject:
|
|
660
|
-
const te =
|
|
661
|
-
(
|
|
655
|
+
const X = JSON.parse(U), se = I || X.subject;
|
|
656
|
+
if (r("Data received:", { subject: se, data: X }), se === A.ChatAnswer) {
|
|
657
|
+
const te = Y.Answer;
|
|
658
|
+
(J = n.onMessage) == null || J.call(n, te, {
|
|
662
659
|
event: te,
|
|
663
|
-
...
|
|
660
|
+
...X
|
|
664
661
|
});
|
|
665
|
-
} else if (
|
|
666
|
-
const te =
|
|
667
|
-
(
|
|
662
|
+
} else if (se === A.ChatPartial) {
|
|
663
|
+
const te = Y.Partial;
|
|
664
|
+
(oe = n.onMessage) == null || oe.call(n, te, {
|
|
668
665
|
event: te,
|
|
669
|
-
...
|
|
666
|
+
...X
|
|
670
667
|
});
|
|
671
668
|
} else if ([
|
|
672
669
|
A.StreamVideoCreated,
|
|
673
670
|
A.StreamVideoDone,
|
|
674
671
|
A.StreamVideoError,
|
|
675
672
|
A.StreamVideoRejected
|
|
676
|
-
].includes(
|
|
677
|
-
|
|
678
|
-
const
|
|
679
|
-
i.debug && ((
|
|
680
|
-
id:
|
|
681
|
-
name:
|
|
682
|
-
}), (
|
|
683
|
-
} else if (
|
|
684
|
-
const te =
|
|
685
|
-
(
|
|
673
|
+
].includes(se)) {
|
|
674
|
+
V = se === A.StreamVideoCreated ? O.Talking : O.Idle, (ue = n.onAgentActivityStateChange) == null || ue.call(n, V);
|
|
675
|
+
const te = ((je = (ye = S == null ? void 0 : S.getReport()) == null ? void 0 : ye.webRTCStats) == null ? void 0 : je.avgRtt) ?? 0, ve = te > 0 ? Math.round(te / 2 * 1e3) : 0, Fe = { ...X, downstreamNetworkLatency: ve };
|
|
676
|
+
i.debug && (($e = X == null ? void 0 : X.metadata) != null && $e.sentiment) && (Fe.sentiment = {
|
|
677
|
+
id: X.metadata.sentiment.id,
|
|
678
|
+
name: X.metadata.sentiment.sentiment
|
|
679
|
+
}), (Be = n.onMessage) == null || Be.call(n, se, Fe);
|
|
680
|
+
} else if (se === A.ChatAudioTranscribed) {
|
|
681
|
+
const te = Y.Transcribe;
|
|
682
|
+
(xe = n.onMessage) == null || xe.call(n, te, {
|
|
686
683
|
event: te,
|
|
687
|
-
...
|
|
684
|
+
...X
|
|
688
685
|
}), queueMicrotask(() => {
|
|
689
686
|
var ve;
|
|
690
687
|
(ve = n.onAgentActivityStateChange) == null || ve.call(n, O.Loading);
|
|
691
688
|
});
|
|
692
689
|
}
|
|
693
|
-
} catch (
|
|
694
|
-
r("Failed to parse data channel message:",
|
|
690
|
+
} catch (X) {
|
|
691
|
+
r("Failed to parse data channel message:", X);
|
|
695
692
|
}
|
|
696
693
|
}
|
|
697
|
-
function
|
|
694
|
+
function $(f) {
|
|
698
695
|
var h;
|
|
699
|
-
r("Media devices error:",
|
|
696
|
+
r("Media devices error:", f), (h = n.onError) == null || h.call(n, new Error(ge), { sessionId: z });
|
|
700
697
|
}
|
|
701
|
-
function
|
|
698
|
+
function G(f) {
|
|
702
699
|
var h;
|
|
703
|
-
r("Encryption error:",
|
|
700
|
+
r("Encryption error:", f), (h = n.onError) == null || h.call(n, new Error(ge), { sessionId: z });
|
|
704
701
|
}
|
|
705
|
-
function
|
|
706
|
-
r("Track subscription failed:", { trackSid:
|
|
702
|
+
function ae(f, h, y) {
|
|
703
|
+
r("Track subscription failed:", { trackSid: f, participant: h, reason: y });
|
|
707
704
|
}
|
|
708
|
-
function
|
|
709
|
-
if (!
|
|
710
|
-
const h =
|
|
705
|
+
function w(f) {
|
|
706
|
+
if (!u) return null;
|
|
707
|
+
const h = u.localParticipant.audioTrackPublications;
|
|
711
708
|
if (h) {
|
|
712
|
-
for (const [
|
|
713
|
-
if (
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
716
|
-
return
|
|
709
|
+
for (const [y, I] of h)
|
|
710
|
+
if (I.source === d.Source.Microphone && I.track) {
|
|
711
|
+
const J = I.track.mediaStreamTrack;
|
|
712
|
+
if (J === f || J && J.id === f.id)
|
|
713
|
+
return I;
|
|
717
714
|
}
|
|
718
715
|
}
|
|
719
716
|
return null;
|
|
720
717
|
}
|
|
721
|
-
function
|
|
718
|
+
function m(f) {
|
|
722
719
|
if (!k || !k.track)
|
|
723
720
|
return !1;
|
|
724
721
|
const h = k.track.mediaStreamTrack;
|
|
725
|
-
return h !==
|
|
722
|
+
return h !== f && (h == null ? void 0 : h.id) !== f.id;
|
|
726
723
|
}
|
|
727
|
-
async function
|
|
728
|
-
var U,
|
|
729
|
-
if (!
|
|
724
|
+
async function M(f) {
|
|
725
|
+
var U, J;
|
|
726
|
+
if (!v || !u)
|
|
730
727
|
throw r("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
|
|
731
|
-
const h =
|
|
728
|
+
const h = f.getAudioTracks();
|
|
732
729
|
if (h.length === 0) {
|
|
733
730
|
r("No audio track found in the provided MediaStream");
|
|
734
731
|
return;
|
|
735
732
|
}
|
|
736
|
-
const
|
|
737
|
-
if (
|
|
733
|
+
const y = h[0], I = w(y);
|
|
734
|
+
if (I) {
|
|
738
735
|
r("Microphone track is already published, skipping", {
|
|
739
|
-
trackId:
|
|
740
|
-
publishedTrackId: (
|
|
741
|
-
}), k =
|
|
736
|
+
trackId: y.id,
|
|
737
|
+
publishedTrackId: (J = (U = I.track) == null ? void 0 : U.mediaStreamTrack) == null ? void 0 : J.id
|
|
738
|
+
}), k = I;
|
|
742
739
|
return;
|
|
743
740
|
}
|
|
744
|
-
|
|
741
|
+
m(y) && (r("Unpublishing existing microphone track before publishing new one"), await W()), r("Publishing microphone track from provided MediaStream", { trackId: y.id });
|
|
745
742
|
try {
|
|
746
|
-
k = await
|
|
743
|
+
k = await u.localParticipant.publishTrack(y, {
|
|
747
744
|
source: d.Source.Microphone
|
|
748
745
|
}), r("Microphone track published successfully", { trackSid: k.trackSid });
|
|
749
|
-
} catch (
|
|
750
|
-
throw r("Failed to publish microphone track:",
|
|
746
|
+
} catch (oe) {
|
|
747
|
+
throw r("Failed to publish microphone track:", oe), oe;
|
|
751
748
|
}
|
|
752
749
|
}
|
|
753
|
-
async function
|
|
750
|
+
async function W() {
|
|
754
751
|
if (!(!k || !k.track))
|
|
755
752
|
try {
|
|
756
|
-
|
|
757
|
-
} catch (
|
|
758
|
-
r("Error unpublishing microphone track:",
|
|
753
|
+
u && (await u.localParticipant.unpublishTrack(k.track), r("Microphone track unpublished"));
|
|
754
|
+
} catch (f) {
|
|
755
|
+
r("Error unpublishing microphone track:", f);
|
|
759
756
|
} finally {
|
|
760
757
|
k = null;
|
|
761
758
|
}
|
|
762
759
|
}
|
|
763
|
-
function
|
|
764
|
-
|
|
760
|
+
function ce() {
|
|
761
|
+
P && (P.getTracks().forEach((f) => f.stop()), P = null);
|
|
765
762
|
}
|
|
766
|
-
async function
|
|
767
|
-
var
|
|
768
|
-
if (!
|
|
769
|
-
r("Room is not connected for sending messages"), (
|
|
770
|
-
sessionId:
|
|
763
|
+
async function de(f, h) {
|
|
764
|
+
var y, I;
|
|
765
|
+
if (!v || !u) {
|
|
766
|
+
r("Room is not connected for sending messages"), (y = n.onError) == null || y.call(n, new Error(ge), {
|
|
767
|
+
sessionId: z
|
|
771
768
|
});
|
|
772
769
|
return;
|
|
773
770
|
}
|
|
774
771
|
try {
|
|
775
|
-
await
|
|
772
|
+
await u.localParticipant.sendText(f, { topic: h }), r("Message sent successfully:", f);
|
|
776
773
|
} catch (U) {
|
|
777
|
-
r("Failed to send message:", U), (
|
|
774
|
+
r("Failed to send message:", U), (I = n.onError) == null || I.call(n, new Error(ge), { sessionId: z });
|
|
778
775
|
}
|
|
779
776
|
}
|
|
780
|
-
async function
|
|
777
|
+
async function pe(f) {
|
|
781
778
|
var h;
|
|
782
779
|
try {
|
|
783
|
-
const
|
|
784
|
-
return
|
|
785
|
-
} catch (
|
|
786
|
-
r("Failed to send data channel message:",
|
|
780
|
+
const I = JSON.parse(f).topic;
|
|
781
|
+
return de("", I);
|
|
782
|
+
} catch (y) {
|
|
783
|
+
r("Failed to send data channel message:", y), (h = n.onError) == null || h.call(n, new Error(ge), { sessionId: z });
|
|
787
784
|
}
|
|
788
785
|
}
|
|
789
|
-
function
|
|
790
|
-
return
|
|
791
|
-
|
|
786
|
+
function we(f) {
|
|
787
|
+
return de(
|
|
788
|
+
f,
|
|
792
789
|
"lk.chat"
|
|
793
790
|
/* Chat */
|
|
794
791
|
);
|
|
795
792
|
}
|
|
796
|
-
async function Re(
|
|
797
|
-
var h,
|
|
798
|
-
|
|
793
|
+
async function Re(f) {
|
|
794
|
+
var h, y;
|
|
795
|
+
b && (clearTimeout(b), b = null), u && (await W(), (h = n.onConnectionStateChange) == null || h.call(n, T.Disconnecting, f), await u.disconnect()), ce(), v = !1, E = !1, (y = n.onAgentActivityStateChange) == null || y.call(n, O.Idle), V = O.Idle;
|
|
799
796
|
}
|
|
800
797
|
return {
|
|
801
|
-
speak(
|
|
802
|
-
const h = typeof
|
|
803
|
-
return
|
|
798
|
+
speak(f) {
|
|
799
|
+
const h = typeof f == "string" ? f : JSON.stringify(f);
|
|
800
|
+
return de(
|
|
804
801
|
h,
|
|
805
802
|
"did.speak"
|
|
806
803
|
/* Speak */
|
|
@@ -808,59 +805,59 @@ async function Ht(e, t, i) {
|
|
|
808
805
|
},
|
|
809
806
|
disconnect: () => Re("user:disconnect"),
|
|
810
807
|
async reconnect() {
|
|
811
|
-
var
|
|
812
|
-
if ((
|
|
808
|
+
var f, h;
|
|
809
|
+
if ((u == null ? void 0 : u.state) === s.Connected) {
|
|
813
810
|
r("Room is already connected");
|
|
814
811
|
return;
|
|
815
812
|
}
|
|
816
|
-
if (!
|
|
813
|
+
if (!u || !ee || !Z)
|
|
817
814
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
818
|
-
r("Reconnecting to LiveKit room, state:",
|
|
815
|
+
r("Reconnecting to LiveKit room, state:", u.state), E = !1, (f = n.onConnectionStateChange) == null || f.call(n, T.Connecting, "user:reconnect");
|
|
819
816
|
try {
|
|
820
|
-
if (await
|
|
821
|
-
if (r("Waiting for agent to join..."), !await new Promise((
|
|
817
|
+
if (await u.connect(ee, Z), r("Room reconnected"), v = !0, u.remoteParticipants.size === 0) {
|
|
818
|
+
if (r("Waiting for agent to join..."), !await new Promise((I) => {
|
|
822
819
|
const U = setTimeout(() => {
|
|
823
|
-
|
|
824
|
-
}, 5e3),
|
|
825
|
-
clearTimeout(U),
|
|
820
|
+
u == null || u.off(a.ParticipantConnected, J), I(!1);
|
|
821
|
+
}, 5e3), J = () => {
|
|
822
|
+
clearTimeout(U), u == null || u.off(a.ParticipantConnected, J), I(!0);
|
|
826
823
|
};
|
|
827
|
-
|
|
824
|
+
u == null || u.on(a.ParticipantConnected, J);
|
|
828
825
|
}))
|
|
829
|
-
throw r("Agent did not join within timeout"), await
|
|
826
|
+
throw r("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
|
|
830
827
|
r("Agent joined, reconnection successful");
|
|
831
828
|
}
|
|
832
|
-
} catch (
|
|
833
|
-
throw r("Failed to reconnect:",
|
|
829
|
+
} catch (y) {
|
|
830
|
+
throw r("Failed to reconnect:", y), (h = n.onConnectionStateChange) == null || h.call(n, T.Fail, "user:reconnect-failed"), y;
|
|
834
831
|
}
|
|
835
832
|
},
|
|
836
|
-
sendDataChannelMessage:
|
|
837
|
-
sendTextMessage:
|
|
838
|
-
publishMicrophoneStream:
|
|
839
|
-
unpublishMicrophoneStream:
|
|
840
|
-
sessionId:
|
|
841
|
-
streamId:
|
|
842
|
-
streamType:
|
|
833
|
+
sendDataChannelMessage: pe,
|
|
834
|
+
sendTextMessage: we,
|
|
835
|
+
publishMicrophoneStream: M,
|
|
836
|
+
unpublishMicrophoneStream: W,
|
|
837
|
+
sessionId: z,
|
|
838
|
+
streamId: z,
|
|
839
|
+
streamType: F,
|
|
843
840
|
interruptAvailable: !0,
|
|
844
841
|
triggersAvailable: !1
|
|
845
842
|
};
|
|
846
843
|
}
|
|
847
|
-
const
|
|
844
|
+
const Wt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
848
845
|
__proto__: null,
|
|
849
|
-
DataChannelTopic:
|
|
850
|
-
createLiveKitStreamingManager:
|
|
851
|
-
handleInitError:
|
|
846
|
+
DataChannelTopic: Pe,
|
|
847
|
+
createLiveKitStreamingManager: Ut,
|
|
848
|
+
handleInitError: Ie
|
|
852
849
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
853
|
-
function
|
|
850
|
+
function Ot(e, t, i) {
|
|
854
851
|
if (!e)
|
|
855
852
|
throw new Error("Please connect to the agent first");
|
|
856
853
|
if (!e.interruptAvailable)
|
|
857
854
|
throw new Error("Interrupt is not enabled for this stream");
|
|
858
|
-
if (t !==
|
|
855
|
+
if (t !== ie.Fluent)
|
|
859
856
|
throw new Error("Interrupt only available for Fluent streams");
|
|
860
857
|
if (!i)
|
|
861
858
|
throw new Error("No active video to interrupt");
|
|
862
859
|
}
|
|
863
|
-
async function
|
|
860
|
+
async function Ht(e, t) {
|
|
864
861
|
const i = {
|
|
865
862
|
type: A.StreamInterrupt,
|
|
866
863
|
videoId: t,
|
|
@@ -868,44 +865,44 @@ async function Xt(e, t) {
|
|
|
868
865
|
};
|
|
869
866
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
870
867
|
}
|
|
871
|
-
async function
|
|
868
|
+
async function qt(e) {
|
|
872
869
|
const t = {
|
|
873
|
-
topic:
|
|
870
|
+
topic: Pe.Interrupt
|
|
874
871
|
};
|
|
875
872
|
e.sendDataChannelMessage(JSON.stringify(t));
|
|
876
873
|
}
|
|
877
|
-
function
|
|
874
|
+
function Qt(e) {
|
|
878
875
|
return new Promise((t, i) => {
|
|
879
|
-
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: n = null, onClose: c = null, onError:
|
|
880
|
-
|
|
881
|
-
console.error(
|
|
882
|
-
},
|
|
883
|
-
n == null || n(
|
|
876
|
+
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: n = null, onClose: c = null, onError: g = null } = r || {}, p = new WebSocket(`${o}?authorization=${encodeURIComponent(Ye(a, s))}`);
|
|
877
|
+
p.onmessage = d, p.onclose = c, p.onerror = (u) => {
|
|
878
|
+
console.error(u), g == null || g("Websocket failed to connect", u), i(u);
|
|
879
|
+
}, p.onopen = (u) => {
|
|
880
|
+
n == null || n(u), t(p);
|
|
884
881
|
};
|
|
885
882
|
});
|
|
886
883
|
}
|
|
887
|
-
async function
|
|
884
|
+
async function Xt(e) {
|
|
888
885
|
const { retries: t = 1 } = e;
|
|
889
886
|
let i = null;
|
|
890
887
|
for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
|
|
891
888
|
try {
|
|
892
|
-
i = await
|
|
889
|
+
i = await Qt(e);
|
|
893
890
|
} catch (o) {
|
|
894
891
|
if (r === t)
|
|
895
892
|
throw o;
|
|
896
|
-
await
|
|
893
|
+
await qe(r * 500);
|
|
897
894
|
}
|
|
898
895
|
return i;
|
|
899
896
|
}
|
|
900
|
-
async function
|
|
901
|
-
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await
|
|
897
|
+
async function Yt(e, t, i, r) {
|
|
898
|
+
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await Xt({
|
|
902
899
|
auth: e,
|
|
903
900
|
host: t,
|
|
904
901
|
externalId: r,
|
|
905
902
|
callbacks: {
|
|
906
903
|
onError: (s) => {
|
|
907
904
|
var d;
|
|
908
|
-
return (d = i.onError) == null ? void 0 : d.call(i, new
|
|
905
|
+
return (d = i.onError) == null ? void 0 : d.call(i, new ot(s));
|
|
909
906
|
},
|
|
910
907
|
onMessage(s) {
|
|
911
908
|
const d = JSON.parse(s.data);
|
|
@@ -919,7 +916,7 @@ async function en(e, t, i, r) {
|
|
|
919
916
|
subscribeToEvents: (s) => o.push(s)
|
|
920
917
|
};
|
|
921
918
|
}
|
|
922
|
-
function
|
|
919
|
+
function Gt(e) {
|
|
923
920
|
if (e.answer !== void 0)
|
|
924
921
|
return e.answer;
|
|
925
922
|
let t = 0, i = "";
|
|
@@ -927,7 +924,7 @@ function tn(e) {
|
|
|
927
924
|
i += e[t++];
|
|
928
925
|
return i;
|
|
929
926
|
}
|
|
930
|
-
function
|
|
927
|
+
function Zt(e, t, i) {
|
|
931
928
|
if (!e.content)
|
|
932
929
|
return;
|
|
933
930
|
const r = t.messages[t.messages.length - 1];
|
|
@@ -941,17 +938,17 @@ function nn(e, t, i) {
|
|
|
941
938
|
};
|
|
942
939
|
t.messages.push(o), i == null || i([...t.messages], "user");
|
|
943
940
|
}
|
|
944
|
-
function
|
|
945
|
-
if (e ===
|
|
946
|
-
|
|
941
|
+
function en(e, t, i, r, o) {
|
|
942
|
+
if (e === Y.Transcribe && t.content) {
|
|
943
|
+
Zt(t, r, o);
|
|
947
944
|
return;
|
|
948
945
|
}
|
|
949
|
-
if (!(e ===
|
|
946
|
+
if (!(e === Y.Partial || e === Y.Answer))
|
|
950
947
|
return;
|
|
951
948
|
const a = r.messages[r.messages.length - 1];
|
|
952
949
|
let s;
|
|
953
950
|
if (a != null && a.transcribed && a.role === "user")
|
|
954
|
-
e ===
|
|
951
|
+
e === Y.Answer && t.content, s = {
|
|
955
952
|
id: t.id || `assistant-${Date.now()}`,
|
|
956
953
|
role: t.role || "assistant",
|
|
957
954
|
content: t.content || "",
|
|
@@ -962,48 +959,49 @@ function rn(e, t, i, r, o) {
|
|
|
962
959
|
else
|
|
963
960
|
return;
|
|
964
961
|
const { content: d, sequence: n } = t;
|
|
965
|
-
e ===
|
|
966
|
-
const c =
|
|
967
|
-
(s.content !== c || e ===
|
|
962
|
+
e === Y.Partial ? i[n] = d : i.answer = d;
|
|
963
|
+
const c = Gt(i);
|
|
964
|
+
(s.content !== c || e === Y.Answer) && (s.content = c, o == null || o([...r.messages], e));
|
|
968
965
|
}
|
|
969
|
-
function
|
|
966
|
+
function tn(e, t, i, r, o) {
|
|
970
967
|
let a = {};
|
|
971
968
|
const s = () => a = {};
|
|
972
969
|
let d = "answer";
|
|
973
|
-
const n = (c,
|
|
974
|
-
var
|
|
975
|
-
|
|
970
|
+
const n = (c, g) => {
|
|
971
|
+
var p, u;
|
|
972
|
+
g === "user" && s(), d = g, (u = (p = i.callbacks).onNewMessage) == null || u.call(p, c, g);
|
|
976
973
|
};
|
|
977
974
|
return {
|
|
978
975
|
clearQueue: s,
|
|
979
|
-
onMessage: (c,
|
|
980
|
-
var
|
|
981
|
-
if ("content" in
|
|
982
|
-
const
|
|
983
|
-
|
|
976
|
+
onMessage: (c, g) => {
|
|
977
|
+
var p, u;
|
|
978
|
+
if ("content" in g) {
|
|
979
|
+
const v = c === A.ChatAnswer ? Y.Answer : c === A.ChatAudioTranscribed ? Y.Transcribe : c;
|
|
980
|
+
en(v, g, a, t, n), v === Y.Answer && e.track("agent-message-received", {
|
|
981
|
+
content: g.content,
|
|
984
982
|
messages: t.messages.length,
|
|
985
983
|
mode: t.chatMode
|
|
986
984
|
});
|
|
987
985
|
} else {
|
|
988
|
-
const
|
|
989
|
-
if (c = c, c ===
|
|
990
|
-
const
|
|
991
|
-
if ((
|
|
992
|
-
const
|
|
993
|
-
t.messages[t.messages.length - 1] =
|
|
986
|
+
const v = A, F = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], P = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], k = _t(g, r, { mode: t.chatMode });
|
|
987
|
+
if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", k, v.StreamVideoCreated, ["start"]), g.sentiment)) {
|
|
988
|
+
const S = t.messages[t.messages.length - 1];
|
|
989
|
+
if ((S == null ? void 0 : S.role) === "assistant") {
|
|
990
|
+
const N = { ...S, sentiment: g.sentiment };
|
|
991
|
+
t.messages[t.messages.length - 1] = N, n == null || n([...t.messages], d);
|
|
994
992
|
}
|
|
995
993
|
}
|
|
996
|
-
if (
|
|
997
|
-
const
|
|
998
|
-
|
|
994
|
+
if (F.includes(c)) {
|
|
995
|
+
const S = c.split("/")[1];
|
|
996
|
+
P.includes(c) ? e.track("agent-video", { ...k, event: S }) : e.linkTrack("agent-video", { ...k, event: S }, c, ["done"]);
|
|
999
997
|
}
|
|
1000
|
-
|
|
998
|
+
P.includes(c) && ((u = (p = i.callbacks).onError) == null || u.call(p, new Error(`Stream failed with event ${c}`), { data: g })), g.event === v.StreamDone && o();
|
|
1001
999
|
}
|
|
1002
1000
|
}
|
|
1003
1001
|
};
|
|
1004
1002
|
}
|
|
1005
|
-
function
|
|
1006
|
-
const o =
|
|
1003
|
+
function nn(e, t, i, r) {
|
|
1004
|
+
const o = Ae(e, `${t}/agents/${i}`, r);
|
|
1007
1005
|
return {
|
|
1008
1006
|
createStream(a, s) {
|
|
1009
1007
|
return o.post("/streams", a, { signal: s });
|
|
@@ -1039,8 +1037,8 @@ function on(e, t, i, r) {
|
|
|
1039
1037
|
}
|
|
1040
1038
|
};
|
|
1041
1039
|
}
|
|
1042
|
-
const
|
|
1043
|
-
function
|
|
1040
|
+
const rn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1041
|
+
function Ue(e) {
|
|
1044
1042
|
switch (e) {
|
|
1045
1043
|
case "connected":
|
|
1046
1044
|
return T.Connected;
|
|
@@ -1060,7 +1058,7 @@ function Ve(e) {
|
|
|
1060
1058
|
return T.New;
|
|
1061
1059
|
}
|
|
1062
1060
|
}
|
|
1063
|
-
const
|
|
1061
|
+
const an = (e) => (t) => {
|
|
1064
1062
|
const [i, r = ""] = t.split(/:(.+)/);
|
|
1065
1063
|
try {
|
|
1066
1064
|
const o = JSON.parse(r);
|
|
@@ -1069,16 +1067,16 @@ const cn = (e) => (t) => {
|
|
|
1069
1067
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: o }), { subject: i, data: r };
|
|
1070
1068
|
}
|
|
1071
1069
|
};
|
|
1072
|
-
function
|
|
1070
|
+
function on({
|
|
1073
1071
|
statsSignal: e,
|
|
1074
1072
|
dataChannelSignal: t,
|
|
1075
1073
|
onVideoStateChange: i,
|
|
1076
1074
|
report: r,
|
|
1077
1075
|
log: o
|
|
1078
1076
|
}) {
|
|
1079
|
-
e ===
|
|
1077
|
+
e === C.Start && t === C.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(C.Start)) : e === C.Stop && t === C.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(C.Stop, r));
|
|
1080
1078
|
}
|
|
1081
|
-
function
|
|
1079
|
+
function sn({
|
|
1082
1080
|
statsSignal: e,
|
|
1083
1081
|
dataChannelSignal: t,
|
|
1084
1082
|
onVideoStateChange: i,
|
|
@@ -1086,9 +1084,9 @@ function un({
|
|
|
1086
1084
|
report: o,
|
|
1087
1085
|
log: a
|
|
1088
1086
|
}) {
|
|
1089
|
-
e ===
|
|
1087
|
+
e === C.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(C.Start)) : e === C.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(C.Stop, o)), t === C.Start ? r == null || r(O.Talking) : t === C.Stop && (r == null || r(O.Idle));
|
|
1090
1088
|
}
|
|
1091
|
-
function
|
|
1089
|
+
function We({
|
|
1092
1090
|
statsSignal: e,
|
|
1093
1091
|
dataChannelSignal: t,
|
|
1094
1092
|
onVideoStateChange: i,
|
|
@@ -1097,7 +1095,7 @@ function Je({
|
|
|
1097
1095
|
report: a,
|
|
1098
1096
|
log: s
|
|
1099
1097
|
}) {
|
|
1100
|
-
o ===
|
|
1098
|
+
o === ie.Legacy ? on({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: a, log: s }) : o === ie.Fluent && sn({
|
|
1101
1099
|
statsSignal: e,
|
|
1102
1100
|
dataChannelSignal: t,
|
|
1103
1101
|
onVideoStateChange: i,
|
|
@@ -1106,161 +1104,161 @@ function Je({
|
|
|
1106
1104
|
log: s
|
|
1107
1105
|
});
|
|
1108
1106
|
}
|
|
1109
|
-
async function
|
|
1110
|
-
var
|
|
1111
|
-
const n =
|
|
1112
|
-
let
|
|
1113
|
-
const { startConnection:
|
|
1107
|
+
async function cn(e, t, { debug: i = !1, callbacks: r, auth: o, baseURL: a = he, analytics: s }, d) {
|
|
1108
|
+
var ae;
|
|
1109
|
+
const n = et(i, "WebRTCStreamingManager"), c = an(n);
|
|
1110
|
+
let g = !1, p = !1, u = C.Stop, v = C.Stop;
|
|
1111
|
+
const { startConnection: F, sendStreamRequest: P, close: k, createStream: S, addIceCandidate: N } = nn(
|
|
1114
1112
|
o,
|
|
1115
1113
|
a,
|
|
1116
1114
|
e,
|
|
1117
1115
|
r.onError
|
|
1118
1116
|
), {
|
|
1119
|
-
id:
|
|
1120
|
-
offer:
|
|
1121
|
-
ice_servers:
|
|
1117
|
+
id: E,
|
|
1118
|
+
offer: b,
|
|
1119
|
+
ice_servers: V,
|
|
1122
1120
|
session_id: H,
|
|
1123
|
-
fluent:
|
|
1124
|
-
interrupt_enabled:
|
|
1125
|
-
triggers_enabled:
|
|
1126
|
-
} = await
|
|
1127
|
-
(
|
|
1128
|
-
const
|
|
1121
|
+
fluent: z,
|
|
1122
|
+
interrupt_enabled: Z,
|
|
1123
|
+
triggers_enabled: ee
|
|
1124
|
+
} = await S(t, d);
|
|
1125
|
+
(ae = r.onStreamCreated) == null || ae.call(r, { stream_id: E, session_id: H, agent_id: e });
|
|
1126
|
+
const l = new rn({ iceServers: V }), D = l.createDataChannel("JanusDataChannel");
|
|
1129
1127
|
if (!H)
|
|
1130
1128
|
throw new Error("Could not create session_id");
|
|
1131
|
-
const R =
|
|
1129
|
+
const R = z ? ie.Fluent : ie.Legacy;
|
|
1132
1130
|
s.enrich({
|
|
1133
1131
|
"stream-type": R
|
|
1134
1132
|
});
|
|
1135
|
-
const
|
|
1136
|
-
var
|
|
1137
|
-
|
|
1138
|
-
},
|
|
1139
|
-
() =>
|
|
1140
|
-
|
|
1133
|
+
const K = t.stream_warmup && !z, L = () => g, _ = () => {
|
|
1134
|
+
var w;
|
|
1135
|
+
g = !0, p && (n("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, T.Connected));
|
|
1136
|
+
}, B = tt(
|
|
1137
|
+
() => l.getStats(),
|
|
1138
|
+
L,
|
|
1141
1139
|
_,
|
|
1142
|
-
(
|
|
1143
|
-
statsSignal:
|
|
1144
|
-
dataChannelSignal: R ===
|
|
1140
|
+
(w, m) => We({
|
|
1141
|
+
statsSignal: v = w,
|
|
1142
|
+
dataChannelSignal: R === ie.Legacy ? u : void 0,
|
|
1145
1143
|
onVideoStateChange: r.onVideoStateChange,
|
|
1146
1144
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1147
1145
|
report: m,
|
|
1148
1146
|
streamType: R,
|
|
1149
1147
|
log: n
|
|
1150
1148
|
}),
|
|
1151
|
-
(
|
|
1149
|
+
(w) => {
|
|
1152
1150
|
var m;
|
|
1153
|
-
return (m = r.onConnectivityStateChange) == null ? void 0 : m.call(r,
|
|
1151
|
+
return (m = r.onConnectivityStateChange) == null ? void 0 : m.call(r, w);
|
|
1154
1152
|
}
|
|
1155
1153
|
);
|
|
1156
|
-
|
|
1154
|
+
B.start(), l.onicecandidate = (w) => {
|
|
1157
1155
|
var m;
|
|
1158
|
-
n("peerConnection.onicecandidate",
|
|
1156
|
+
n("peerConnection.onicecandidate", w);
|
|
1159
1157
|
try {
|
|
1160
|
-
|
|
1161
|
-
|
|
1158
|
+
w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? N(
|
|
1159
|
+
E,
|
|
1162
1160
|
{
|
|
1163
|
-
candidate:
|
|
1164
|
-
sdpMid:
|
|
1165
|
-
sdpMLineIndex:
|
|
1161
|
+
candidate: w.candidate.candidate,
|
|
1162
|
+
sdpMid: w.candidate.sdpMid,
|
|
1163
|
+
sdpMLineIndex: w.candidate.sdpMLineIndex
|
|
1166
1164
|
},
|
|
1167
1165
|
H,
|
|
1168
1166
|
d
|
|
1169
|
-
) :
|
|
1167
|
+
) : N(E, { candidate: null }, H, d);
|
|
1170
1168
|
} catch (M) {
|
|
1171
|
-
(m = r.onError) == null || m.call(r, M, { streamId:
|
|
1169
|
+
(m = r.onError) == null || m.call(r, M, { streamId: E });
|
|
1172
1170
|
}
|
|
1173
|
-
},
|
|
1174
|
-
|
|
1171
|
+
}, D.onopen = () => {
|
|
1172
|
+
p = !0, (!K || g) && _();
|
|
1175
1173
|
};
|
|
1176
|
-
const q = (
|
|
1174
|
+
const q = (w) => {
|
|
1177
1175
|
var m;
|
|
1178
|
-
(m = r.onVideoIdChange) == null || m.call(r,
|
|
1176
|
+
(m = r.onVideoIdChange) == null || m.call(r, w);
|
|
1179
1177
|
};
|
|
1180
|
-
function
|
|
1181
|
-
if (
|
|
1178
|
+
function Q(w, m) {
|
|
1179
|
+
if (w === A.StreamStarted && typeof m == "object" && "metadata" in m) {
|
|
1182
1180
|
const M = m.metadata;
|
|
1183
1181
|
q(M.videoId);
|
|
1184
1182
|
}
|
|
1185
|
-
|
|
1186
|
-
statsSignal: R ===
|
|
1187
|
-
dataChannelSignal:
|
|
1183
|
+
w === A.StreamDone && q(null), u = w === A.StreamStarted ? C.Start : C.Stop, We({
|
|
1184
|
+
statsSignal: R === ie.Legacy ? v : void 0,
|
|
1185
|
+
dataChannelSignal: u,
|
|
1188
1186
|
onVideoStateChange: r.onVideoStateChange,
|
|
1189
1187
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1190
1188
|
streamType: R,
|
|
1191
1189
|
log: n
|
|
1192
1190
|
});
|
|
1193
1191
|
}
|
|
1194
|
-
function j(
|
|
1195
|
-
var
|
|
1192
|
+
function j(w, m) {
|
|
1193
|
+
var W;
|
|
1196
1194
|
const M = typeof m == "string" ? m : m == null ? void 0 : m.metadata;
|
|
1197
|
-
M && s.enrich({ streamMetadata: M }), (
|
|
1195
|
+
M && s.enrich({ streamMetadata: M }), (W = r.onStreamReady) == null || W.call(r);
|
|
1198
1196
|
}
|
|
1199
|
-
const
|
|
1200
|
-
[A.StreamStarted]:
|
|
1201
|
-
[A.StreamDone]:
|
|
1197
|
+
const $ = {
|
|
1198
|
+
[A.StreamStarted]: Q,
|
|
1199
|
+
[A.StreamDone]: Q,
|
|
1202
1200
|
[A.StreamReady]: j
|
|
1203
1201
|
};
|
|
1204
|
-
|
|
1205
|
-
var
|
|
1206
|
-
const { subject: m, data: M } = c(
|
|
1207
|
-
(
|
|
1208
|
-
},
|
|
1202
|
+
D.onmessage = (w) => {
|
|
1203
|
+
var W;
|
|
1204
|
+
const { subject: m, data: M } = c(w.data);
|
|
1205
|
+
(W = $[m]) == null || W.call($, m, M);
|
|
1206
|
+
}, l.oniceconnectionstatechange = () => {
|
|
1209
1207
|
var m;
|
|
1210
|
-
n("peerConnection.oniceconnectionstatechange => " +
|
|
1211
|
-
const
|
|
1212
|
-
|
|
1213
|
-
},
|
|
1208
|
+
n("peerConnection.oniceconnectionstatechange => " + l.iceConnectionState);
|
|
1209
|
+
const w = Ue(l.iceConnectionState);
|
|
1210
|
+
w !== T.Connected && ((m = r.onConnectionStateChange) == null || m.call(r, w));
|
|
1211
|
+
}, l.ontrack = (w) => {
|
|
1214
1212
|
var m;
|
|
1215
|
-
n("peerConnection.ontrack",
|
|
1216
|
-
}, await
|
|
1217
|
-
const
|
|
1218
|
-
return n("create answer OK"), await
|
|
1213
|
+
n("peerConnection.ontrack", w), n("CALLBACK: onSrcObjectReady"), (m = r.onSrcObjectReady) == null || m.call(r, w.streams[0]);
|
|
1214
|
+
}, await l.setRemoteDescription(b), n("set remote description OK");
|
|
1215
|
+
const G = await l.createAnswer();
|
|
1216
|
+
return n("create answer OK"), await l.setLocalDescription(G), n("set local description OK"), await F(E, G, H, d), n("start connection OK"), {
|
|
1219
1217
|
/**
|
|
1220
1218
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1221
1219
|
* @param payload
|
|
1222
1220
|
*/
|
|
1223
|
-
speak(
|
|
1224
|
-
return
|
|
1221
|
+
speak(w) {
|
|
1222
|
+
return P(E, H, w);
|
|
1225
1223
|
},
|
|
1226
1224
|
/**
|
|
1227
1225
|
* Method to close RTC connection
|
|
1228
1226
|
*/
|
|
1229
1227
|
async disconnect() {
|
|
1230
|
-
var
|
|
1231
|
-
if (
|
|
1232
|
-
const m =
|
|
1233
|
-
if (
|
|
1228
|
+
var w;
|
|
1229
|
+
if (E) {
|
|
1230
|
+
const m = Ue(l.iceConnectionState);
|
|
1231
|
+
if (l) {
|
|
1234
1232
|
if (m === T.New) {
|
|
1235
|
-
|
|
1233
|
+
B.stop();
|
|
1236
1234
|
return;
|
|
1237
1235
|
}
|
|
1238
|
-
|
|
1236
|
+
l.close(), l.oniceconnectionstatechange = null, l.onnegotiationneeded = null, l.onicecandidate = null, l.ontrack = null;
|
|
1239
1237
|
}
|
|
1240
1238
|
try {
|
|
1241
|
-
m === T.Connected && await
|
|
1239
|
+
m === T.Connected && await k(E, H).catch((M) => {
|
|
1242
1240
|
});
|
|
1243
1241
|
} catch (M) {
|
|
1244
1242
|
n("Error on close stream connection", M);
|
|
1245
1243
|
}
|
|
1246
|
-
(
|
|
1244
|
+
(w = r.onAgentActivityStateChange) == null || w.call(r, O.Idle), B.stop();
|
|
1247
1245
|
}
|
|
1248
1246
|
},
|
|
1249
1247
|
/**
|
|
1250
1248
|
* Method to send data channel messages to the server
|
|
1251
1249
|
*/
|
|
1252
|
-
sendDataChannelMessage(
|
|
1250
|
+
sendDataChannelMessage(w) {
|
|
1253
1251
|
var m, M;
|
|
1254
|
-
if (!
|
|
1252
|
+
if (!g || D.readyState !== "open") {
|
|
1255
1253
|
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"), {
|
|
1256
|
-
streamId:
|
|
1254
|
+
streamId: E
|
|
1257
1255
|
});
|
|
1258
1256
|
return;
|
|
1259
1257
|
}
|
|
1260
1258
|
try {
|
|
1261
|
-
|
|
1262
|
-
} catch (
|
|
1263
|
-
n("Error sending data channel message",
|
|
1259
|
+
D.send(w);
|
|
1260
|
+
} catch (W) {
|
|
1261
|
+
n("Error sending data channel message", W), (M = r.onError) == null || M.call(r, W, { streamId: E });
|
|
1264
1262
|
}
|
|
1265
1263
|
},
|
|
1266
1264
|
/**
|
|
@@ -1270,25 +1268,25 @@ async function ln(e, t, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
|
|
|
1270
1268
|
/**
|
|
1271
1269
|
* Id of current RTC stream
|
|
1272
1270
|
*/
|
|
1273
|
-
streamId:
|
|
1271
|
+
streamId: E,
|
|
1274
1272
|
streamType: R,
|
|
1275
|
-
interruptAvailable:
|
|
1276
|
-
triggersAvailable:
|
|
1273
|
+
interruptAvailable: Z ?? !1,
|
|
1274
|
+
triggersAvailable: ee ?? !1
|
|
1277
1275
|
};
|
|
1278
1276
|
}
|
|
1279
|
-
var
|
|
1280
|
-
async function
|
|
1277
|
+
var Te = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Te || {});
|
|
1278
|
+
async function dn(e, t, i, r) {
|
|
1281
1279
|
const o = e.id;
|
|
1282
1280
|
switch (t.version) {
|
|
1283
1281
|
case "v1": {
|
|
1284
1282
|
const { version: a, ...s } = t;
|
|
1285
|
-
return
|
|
1283
|
+
return cn(o, s, i, r);
|
|
1286
1284
|
}
|
|
1287
1285
|
case "v2": {
|
|
1288
1286
|
const { version: a, ...s } = t;
|
|
1289
1287
|
switch (s.transport_provider) {
|
|
1290
1288
|
case ke.Livekit:
|
|
1291
|
-
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() =>
|
|
1289
|
+
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => Wt);
|
|
1292
1290
|
return d(o, s, i);
|
|
1293
1291
|
default:
|
|
1294
1292
|
throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
|
|
@@ -1298,13 +1296,13 @@ async function fn(e, t, i, r) {
|
|
|
1298
1296
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1299
1297
|
}
|
|
1300
1298
|
}
|
|
1301
|
-
const
|
|
1302
|
-
function
|
|
1299
|
+
const un = "cht";
|
|
1300
|
+
function ln() {
|
|
1303
1301
|
return {
|
|
1304
1302
|
transport_provider: ke.Livekit
|
|
1305
1303
|
};
|
|
1306
1304
|
}
|
|
1307
|
-
function
|
|
1305
|
+
function fn(e) {
|
|
1308
1306
|
var o, a;
|
|
1309
1307
|
const { streamOptions: t } = e ?? {}, i = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
|
|
1310
1308
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1317,17 +1315,17 @@ function hn(e) {
|
|
|
1317
1315
|
fluent: t == null ? void 0 : t.fluent
|
|
1318
1316
|
}, ...i && { end_user_data: i } };
|
|
1319
1317
|
}
|
|
1320
|
-
function
|
|
1321
|
-
return
|
|
1318
|
+
function mn(e, t) {
|
|
1319
|
+
return _e(e.presenter.type) ? { version: Te.V2, ...ln() } : { version: Te.V1, ...fn(t) };
|
|
1322
1320
|
}
|
|
1323
|
-
function
|
|
1321
|
+
function gn(e, t, i) {
|
|
1324
1322
|
i.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1325
1323
|
}
|
|
1326
|
-
function
|
|
1327
|
-
o ===
|
|
1324
|
+
function hn(e, t, i, r, o) {
|
|
1325
|
+
o === ie.Fluent ? pn(e, t, i, r, o) : yn(e, t, i, r, o);
|
|
1328
1326
|
}
|
|
1329
|
-
function
|
|
1330
|
-
e ===
|
|
1327
|
+
function pn(e, t, i, r, o) {
|
|
1328
|
+
e === C.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === C.Stop && r.track("stream-session", {
|
|
1331
1329
|
event: "stop",
|
|
1332
1330
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1333
1331
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -1335,13 +1333,13 @@ function vn(e, t, i, r, o) {
|
|
|
1335
1333
|
...i
|
|
1336
1334
|
});
|
|
1337
1335
|
}
|
|
1338
|
-
function
|
|
1339
|
-
|
|
1336
|
+
function wn(e, t, i, r) {
|
|
1337
|
+
ne.get() <= 0 || (e === C.Start ? i.linkTrack(
|
|
1340
1338
|
"agent-video",
|
|
1341
|
-
{ event: "start", latency:
|
|
1339
|
+
{ event: "start", latency: ne.get(!0), "stream-type": r },
|
|
1342
1340
|
"start",
|
|
1343
1341
|
[A.StreamVideoCreated]
|
|
1344
|
-
) : e ===
|
|
1342
|
+
) : e === C.Stop && i.linkTrack(
|
|
1345
1343
|
"agent-video",
|
|
1346
1344
|
{
|
|
1347
1345
|
event: "stop",
|
|
@@ -1353,13 +1351,13 @@ function Sn(e, t, i, r) {
|
|
|
1353
1351
|
[A.StreamVideoDone]
|
|
1354
1352
|
));
|
|
1355
1353
|
}
|
|
1356
|
-
function
|
|
1357
|
-
|
|
1354
|
+
function yn(e, t, i, r, o) {
|
|
1355
|
+
ne.get() <= 0 || (e === C.Start ? r.linkTrack(
|
|
1358
1356
|
"agent-video",
|
|
1359
|
-
{ event: "start", latency:
|
|
1357
|
+
{ event: "start", latency: ne.get(!0), "stream-type": o },
|
|
1360
1358
|
"start",
|
|
1361
1359
|
[A.StreamVideoCreated]
|
|
1362
|
-
) : e ===
|
|
1360
|
+
) : e === C.Stop && r.linkTrack(
|
|
1363
1361
|
"agent-video",
|
|
1364
1362
|
{
|
|
1365
1363
|
event: "stop",
|
|
@@ -1372,14 +1370,14 @@ function Cn(e, t, i, r, o) {
|
|
|
1372
1370
|
[A.StreamVideoDone]
|
|
1373
1371
|
));
|
|
1374
1372
|
}
|
|
1375
|
-
function
|
|
1376
|
-
return
|
|
1373
|
+
function Oe(e, t, i, r) {
|
|
1374
|
+
return ne.reset(), Ne.update(), new Promise(async (o, a) => {
|
|
1377
1375
|
try {
|
|
1378
1376
|
let s, d = !1;
|
|
1379
|
-
const n =
|
|
1377
|
+
const n = mn(e, t);
|
|
1380
1378
|
i.enrich({
|
|
1381
1379
|
"stream-version": n.version.toString()
|
|
1382
|
-
}), s = await
|
|
1380
|
+
}), s = await dn(
|
|
1383
1381
|
e,
|
|
1384
1382
|
n,
|
|
1385
1383
|
{
|
|
@@ -1387,31 +1385,31 @@ function Ue(e, t, i, r) {
|
|
|
1387
1385
|
analytics: i,
|
|
1388
1386
|
callbacks: {
|
|
1389
1387
|
...t.callbacks,
|
|
1390
|
-
onConnectionStateChange: (c,
|
|
1391
|
-
var
|
|
1392
|
-
(
|
|
1388
|
+
onConnectionStateChange: (c, g) => {
|
|
1389
|
+
var p, u;
|
|
1390
|
+
(u = (p = t.callbacks).onConnectionStateChange) == null || u.call(p, c), gn(c, g, i), c === T.Connected && (s ? o(s) : d = !0);
|
|
1393
1391
|
},
|
|
1394
|
-
onVideoStateChange: (c,
|
|
1395
|
-
var
|
|
1396
|
-
(
|
|
1392
|
+
onVideoStateChange: (c, g) => {
|
|
1393
|
+
var p, u;
|
|
1394
|
+
(u = (p = t.callbacks).onVideoStateChange) == null || u.call(p, c), hn(
|
|
1397
1395
|
c,
|
|
1398
1396
|
e,
|
|
1399
|
-
|
|
1397
|
+
g,
|
|
1400
1398
|
i,
|
|
1401
1399
|
s.streamType
|
|
1402
1400
|
);
|
|
1403
1401
|
},
|
|
1404
1402
|
onAgentActivityStateChange: (c) => {
|
|
1405
|
-
var
|
|
1406
|
-
(
|
|
1407
|
-
c === O.Talking ?
|
|
1403
|
+
var g, p;
|
|
1404
|
+
(p = (g = t.callbacks).onAgentActivityStateChange) == null || p.call(g, c), c === O.Talking ? Me.update() : Me.reset(), wn(
|
|
1405
|
+
c === O.Talking ? C.Start : C.Stop,
|
|
1408
1406
|
e,
|
|
1409
1407
|
i,
|
|
1410
1408
|
s.streamType
|
|
1411
1409
|
);
|
|
1412
1410
|
},
|
|
1413
1411
|
onStreamReady: () => {
|
|
1414
|
-
const c =
|
|
1412
|
+
const c = Ne.get(!0);
|
|
1415
1413
|
i.track("agent-chat", { event: "ready", latency: c });
|
|
1416
1414
|
}
|
|
1417
1415
|
}
|
|
@@ -1423,358 +1421,358 @@ function Ue(e, t, i, r) {
|
|
|
1423
1421
|
}
|
|
1424
1422
|
});
|
|
1425
1423
|
}
|
|
1426
|
-
async function
|
|
1427
|
-
var
|
|
1424
|
+
async function vn(e, t, i, r, o) {
|
|
1425
|
+
var g, p, u, v;
|
|
1428
1426
|
const a = async () => {
|
|
1429
|
-
if (
|
|
1430
|
-
const
|
|
1427
|
+
if (_e(e.presenter.type)) {
|
|
1428
|
+
const F = await Oe(e, t, r), P = `${un}_${F.sessionId}`, k = (/* @__PURE__ */ new Date()).toISOString();
|
|
1431
1429
|
return { chatResult: {
|
|
1432
1430
|
chatMode: x.Functional,
|
|
1433
1431
|
chat: {
|
|
1434
|
-
id:
|
|
1432
|
+
id: P,
|
|
1435
1433
|
agent_id: e.id,
|
|
1436
1434
|
owner_id: e.owner_id ?? "",
|
|
1437
|
-
created:
|
|
1438
|
-
modified:
|
|
1439
|
-
agent_id__created_at:
|
|
1440
|
-
agent_id__modified_at:
|
|
1435
|
+
created: k,
|
|
1436
|
+
modified: k,
|
|
1437
|
+
agent_id__created_at: k,
|
|
1438
|
+
agent_id__modified_at: k,
|
|
1441
1439
|
chat_mode: x.Functional,
|
|
1442
1440
|
messages: []
|
|
1443
1441
|
}
|
|
1444
|
-
}, streamingManager:
|
|
1442
|
+
}, streamingManager: F };
|
|
1445
1443
|
} else {
|
|
1446
|
-
const
|
|
1447
|
-
let
|
|
1444
|
+
const F = new AbortController(), P = F.signal;
|
|
1445
|
+
let k;
|
|
1448
1446
|
try {
|
|
1449
|
-
const
|
|
1447
|
+
const S = Ze(
|
|
1450
1448
|
e,
|
|
1451
1449
|
i,
|
|
1452
1450
|
r,
|
|
1453
1451
|
t.mode,
|
|
1454
1452
|
t.persistentChat,
|
|
1455
1453
|
o
|
|
1456
|
-
),
|
|
1457
|
-
return { chatResult:
|
|
1458
|
-
} catch (
|
|
1459
|
-
throw
|
|
1460
|
-
}),
|
|
1454
|
+
), N = Oe(e, t, r, P).then((V) => (k = V, V)), [E, b] = await Promise.all([S, N]);
|
|
1455
|
+
return { chatResult: E, streamingManager: b };
|
|
1456
|
+
} catch (S) {
|
|
1457
|
+
throw F.abort(), k && await k.disconnect().catch(() => {
|
|
1458
|
+
}), S;
|
|
1461
1459
|
}
|
|
1462
1460
|
}
|
|
1463
1461
|
}, { chatResult: s, streamingManager: d } = await a(), { chat: n, chatMode: c } = s;
|
|
1464
|
-
return c && t.mode !== void 0 && c !== t.mode && (t.mode = c, (
|
|
1462
|
+
return c && t.mode !== void 0 && c !== t.mode && (t.mode = c, (p = (g = t.callbacks).onModeChange) == null || p.call(g, c), c !== x.Functional) ? ((v = (u = t.callbacks).onError) == null || v.call(u, new at(c)), d == null || d.disconnect(), { chat: n }) : { chat: n, streamingManager: d };
|
|
1465
1463
|
}
|
|
1466
|
-
async function
|
|
1467
|
-
var H,
|
|
1464
|
+
async function kn(e, t) {
|
|
1465
|
+
var H, z, Z, ee;
|
|
1468
1466
|
let i = !0, r = null;
|
|
1469
|
-
const o = t.mixpanelKey ||
|
|
1467
|
+
const o = t.mixpanelKey || vt, a = t.wsURL || yt, s = t.baseURL || he, d = t.mode || x.Functional, n = {
|
|
1470
1468
|
messages: [],
|
|
1471
1469
|
chatMode: d
|
|
1472
|
-
}, c =
|
|
1470
|
+
}, c = Lt({
|
|
1473
1471
|
token: o,
|
|
1474
1472
|
agentId: e,
|
|
1475
1473
|
isEnabled: t.enableAnalitics,
|
|
1476
1474
|
externalId: t.externalId,
|
|
1477
1475
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1478
|
-
}),
|
|
1479
|
-
|
|
1480
|
-
c.track("agent-sdk", { event: "init" },
|
|
1476
|
+
}), g = Date.now();
|
|
1477
|
+
Ke(() => {
|
|
1478
|
+
c.track("agent-sdk", { event: "init" }, g);
|
|
1481
1479
|
});
|
|
1482
|
-
const
|
|
1483
|
-
t.debug = t.debug || ((H =
|
|
1484
|
-
const
|
|
1485
|
-
c.enrich(
|
|
1486
|
-
const { onMessage:
|
|
1480
|
+
const p = Et(t.auth, s, t.callbacks.onError, t.externalId), u = await p.getById(e);
|
|
1481
|
+
t.debug = t.debug || ((H = u == null ? void 0 : u.advanced_settings) == null ? void 0 : H.ui_debug_mode);
|
|
1482
|
+
const v = _e(u.presenter.type);
|
|
1483
|
+
c.enrich(It(u));
|
|
1484
|
+
const { onMessage: F, clearQueue: P } = tn(
|
|
1487
1485
|
c,
|
|
1488
1486
|
n,
|
|
1489
1487
|
t,
|
|
1490
|
-
|
|
1488
|
+
u,
|
|
1491
1489
|
() => {
|
|
1492
|
-
var
|
|
1493
|
-
return (
|
|
1490
|
+
var l;
|
|
1491
|
+
return (l = n.socketManager) == null ? void 0 : l.disconnect();
|
|
1494
1492
|
}
|
|
1495
1493
|
);
|
|
1496
|
-
n.messages =
|
|
1497
|
-
const
|
|
1498
|
-
r =
|
|
1499
|
-
},
|
|
1500
|
-
var R,
|
|
1501
|
-
const
|
|
1494
|
+
n.messages = bt(t.initialMessages), (Z = (z = t.callbacks).onNewMessage) == null || Z.call(z, [...n.messages], "answer");
|
|
1495
|
+
const k = (l) => {
|
|
1496
|
+
r = l;
|
|
1497
|
+
}, S = ({ type: l }) => {
|
|
1498
|
+
var R, K, L;
|
|
1499
|
+
const D = n.messages[n.messages.length - 1];
|
|
1502
1500
|
c.track("agent-video-interrupt", {
|
|
1503
|
-
type:
|
|
1504
|
-
video_duration_to_interrupt:
|
|
1505
|
-
message_duration_to_interrupt:
|
|
1506
|
-
}),
|
|
1507
|
-
},
|
|
1508
|
-
|
|
1509
|
-
c.track("agent-sdk", { event: "loaded", ...
|
|
1501
|
+
type: l || "click",
|
|
1502
|
+
video_duration_to_interrupt: Me.get(!0),
|
|
1503
|
+
message_duration_to_interrupt: ne.get(!0)
|
|
1504
|
+
}), D.interrupted = !0, (K = (R = t.callbacks).onNewMessage) == null || K.call(R, [...n.messages], "answer"), v ? qt(n.streamingManager) : (Ot(n.streamingManager, (L = n.streamingManager) == null ? void 0 : L.streamType, r), Ht(n.streamingManager, r));
|
|
1505
|
+
}, N = Date.now();
|
|
1506
|
+
Ke(() => {
|
|
1507
|
+
c.track("agent-sdk", { event: "loaded", ...Mt(u) }, N);
|
|
1510
1508
|
});
|
|
1511
|
-
async function
|
|
1512
|
-
var
|
|
1513
|
-
(q = (
|
|
1514
|
-
const
|
|
1509
|
+
async function E(l) {
|
|
1510
|
+
var B, q, Q, j, $, G, ae;
|
|
1511
|
+
(q = (B = t.callbacks).onConnectionStateChange) == null || q.call(B, T.Connecting), ne.reset(), l && !i && (delete n.chat, (j = (Q = t.callbacks).onNewMessage) == null || j.call(Q, [...n.messages], "answer"));
|
|
1512
|
+
const D = d === x.DirectPlayback || v ? Promise.resolve(void 0) : Yt(
|
|
1515
1513
|
t.auth,
|
|
1516
1514
|
a,
|
|
1517
|
-
{ onMessage:
|
|
1515
|
+
{ onMessage: F, onError: t.callbacks.onError },
|
|
1518
1516
|
t.externalId
|
|
1519
|
-
), R =
|
|
1520
|
-
() =>
|
|
1521
|
-
|
|
1517
|
+
), R = De(
|
|
1518
|
+
() => vn(
|
|
1519
|
+
u,
|
|
1522
1520
|
{
|
|
1523
1521
|
...t,
|
|
1524
1522
|
mode: d,
|
|
1525
1523
|
callbacks: {
|
|
1526
1524
|
...t.callbacks,
|
|
1527
|
-
onVideoIdChange:
|
|
1528
|
-
onMessage:
|
|
1529
|
-
onInterruptDetected:
|
|
1525
|
+
onVideoIdChange: k,
|
|
1526
|
+
onMessage: F,
|
|
1527
|
+
onInterruptDetected: S
|
|
1530
1528
|
}
|
|
1531
1529
|
},
|
|
1532
|
-
|
|
1530
|
+
p,
|
|
1533
1531
|
c,
|
|
1534
1532
|
n.chat
|
|
1535
1533
|
),
|
|
1536
1534
|
{
|
|
1537
1535
|
limit: 3,
|
|
1538
|
-
timeout:
|
|
1536
|
+
timeout: pt,
|
|
1539
1537
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1540
|
-
shouldRetryFn: (
|
|
1538
|
+
shouldRetryFn: (w) => (w == null ? void 0 : w.message) !== "Could not connect" && w.status !== 429 && (w == null ? void 0 : w.message) !== "InsufficientCreditsError",
|
|
1541
1539
|
delayMs: 1e3
|
|
1542
1540
|
}
|
|
1543
|
-
).catch((
|
|
1541
|
+
).catch((w) => {
|
|
1544
1542
|
var m, M;
|
|
1545
|
-
throw
|
|
1546
|
-
}), [
|
|
1547
|
-
_ && _.id !== ((
|
|
1543
|
+
throw V(x.Maintenance), (M = (m = t.callbacks).onConnectionStateChange) == null || M.call(m, T.Fail), w;
|
|
1544
|
+
}), [K, { streamingManager: L, chat: _ }] = await Promise.all([D, R]);
|
|
1545
|
+
_ && _.id !== (($ = n.chat) == null ? void 0 : $.id) && ((ae = (G = t.callbacks).onNewChat) == null || ae.call(G, _.id)), n.streamingManager = L, n.socketManager = K, n.chat = _, i = !1, c.enrich({
|
|
1548
1546
|
chatId: _ == null ? void 0 : _.id,
|
|
1549
|
-
streamId:
|
|
1547
|
+
streamId: L == null ? void 0 : L.streamId,
|
|
1550
1548
|
mode: n.chatMode
|
|
1551
|
-
}),
|
|
1549
|
+
}), V((_ == null ? void 0 : _.chat_mode) ?? d);
|
|
1552
1550
|
}
|
|
1553
|
-
async function
|
|
1554
|
-
var
|
|
1555
|
-
(
|
|
1551
|
+
async function b() {
|
|
1552
|
+
var l, D, R, K;
|
|
1553
|
+
(l = n.socketManager) == null || l.disconnect(), await ((D = n.streamingManager) == null ? void 0 : D.disconnect()), delete n.streamingManager, delete n.socketManager, (K = (R = t.callbacks).onConnectionStateChange) == null || K.call(R, T.Disconnected);
|
|
1556
1554
|
}
|
|
1557
|
-
async function
|
|
1558
|
-
var
|
|
1559
|
-
|
|
1555
|
+
async function V(l) {
|
|
1556
|
+
var D, R;
|
|
1557
|
+
l !== n.chatMode && (c.track("agent-mode-change", { mode: l }), n.chatMode = l, n.chatMode !== x.Functional && await b(), (R = (D = t.callbacks).onModeChange) == null || R.call(D, l));
|
|
1560
1558
|
}
|
|
1561
1559
|
return {
|
|
1562
|
-
agent:
|
|
1560
|
+
agent: u,
|
|
1563
1561
|
getStreamType: () => {
|
|
1564
|
-
var
|
|
1565
|
-
return (
|
|
1562
|
+
var l;
|
|
1563
|
+
return (l = n.streamingManager) == null ? void 0 : l.streamType;
|
|
1566
1564
|
},
|
|
1567
1565
|
getIsInterruptAvailable: () => {
|
|
1568
|
-
var
|
|
1569
|
-
return ((
|
|
1566
|
+
var l;
|
|
1567
|
+
return ((l = n.streamingManager) == null ? void 0 : l.interruptAvailable) ?? !1;
|
|
1570
1568
|
},
|
|
1571
1569
|
getIsTriggersAvailable: () => {
|
|
1572
|
-
var
|
|
1573
|
-
return ((
|
|
1570
|
+
var l;
|
|
1571
|
+
return ((l = n.streamingManager) == null ? void 0 : l.triggersAvailable) ?? !1;
|
|
1574
1572
|
},
|
|
1575
|
-
starterMessages: ((
|
|
1576
|
-
getSTTToken: () =>
|
|
1577
|
-
changeMode:
|
|
1573
|
+
starterMessages: ((ee = u.knowledge) == null ? void 0 : ee.starter_message) || [],
|
|
1574
|
+
getSTTToken: () => p.getSTTToken(u.id),
|
|
1575
|
+
changeMode: V,
|
|
1578
1576
|
enrichAnalytics: c.enrich,
|
|
1579
1577
|
async connect() {
|
|
1580
|
-
await
|
|
1578
|
+
await E(!0), c.track("agent-chat", {
|
|
1581
1579
|
event: "connect",
|
|
1582
1580
|
mode: n.chatMode
|
|
1583
1581
|
});
|
|
1584
1582
|
},
|
|
1585
1583
|
async reconnect() {
|
|
1586
|
-
const
|
|
1587
|
-
if (
|
|
1584
|
+
const l = n.streamingManager;
|
|
1585
|
+
if (v && (l != null && l.reconnect)) {
|
|
1588
1586
|
try {
|
|
1589
|
-
await
|
|
1587
|
+
await l.reconnect(), c.track("agent-chat", {
|
|
1590
1588
|
event: "reconnect",
|
|
1591
1589
|
mode: n.chatMode
|
|
1592
1590
|
});
|
|
1593
1591
|
} catch {
|
|
1594
|
-
await
|
|
1592
|
+
await b(), await E(!1);
|
|
1595
1593
|
}
|
|
1596
1594
|
return;
|
|
1597
1595
|
}
|
|
1598
|
-
await
|
|
1596
|
+
await b(), await E(!1), c.track("agent-chat", {
|
|
1599
1597
|
event: "reconnect",
|
|
1600
1598
|
mode: n.chatMode
|
|
1601
1599
|
});
|
|
1602
1600
|
},
|
|
1603
1601
|
async disconnect() {
|
|
1604
|
-
await
|
|
1602
|
+
await b(), c.track("agent-chat", {
|
|
1605
1603
|
event: "disconnect",
|
|
1606
1604
|
mode: n.chatMode
|
|
1607
1605
|
});
|
|
1608
1606
|
},
|
|
1609
|
-
async publishMicrophoneStream(
|
|
1610
|
-
var
|
|
1611
|
-
if (!((
|
|
1607
|
+
async publishMicrophoneStream(l) {
|
|
1608
|
+
var D;
|
|
1609
|
+
if (!((D = n.streamingManager) != null && D.publishMicrophoneStream))
|
|
1612
1610
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1613
|
-
return n.streamingManager.publishMicrophoneStream(
|
|
1611
|
+
return n.streamingManager.publishMicrophoneStream(l);
|
|
1614
1612
|
},
|
|
1615
1613
|
async unpublishMicrophoneStream() {
|
|
1616
|
-
var
|
|
1617
|
-
if (!((
|
|
1614
|
+
var l;
|
|
1615
|
+
if (!((l = n.streamingManager) != null && l.unpublishMicrophoneStream))
|
|
1618
1616
|
throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
|
|
1619
1617
|
return n.streamingManager.unpublishMicrophoneStream();
|
|
1620
1618
|
},
|
|
1621
|
-
async chat(
|
|
1622
|
-
var
|
|
1623
|
-
const
|
|
1624
|
-
if (
|
|
1625
|
-
throw new
|
|
1626
|
-
if (
|
|
1627
|
-
throw new
|
|
1628
|
-
if (
|
|
1629
|
-
throw new
|
|
1619
|
+
async chat(l) {
|
|
1620
|
+
var L, _, B, q, Q;
|
|
1621
|
+
const D = () => {
|
|
1622
|
+
if (Xe(d))
|
|
1623
|
+
throw new le(`${d} is enabled, chat is disabled`);
|
|
1624
|
+
if (l.length >= 800)
|
|
1625
|
+
throw new le("Message cannot be more than 800 characters");
|
|
1626
|
+
if (l.length === 0)
|
|
1627
|
+
throw new le("Message cannot be empty");
|
|
1630
1628
|
if (n.chatMode === x.Maintenance)
|
|
1631
|
-
throw new
|
|
1629
|
+
throw new le("Chat is in maintenance mode");
|
|
1632
1630
|
if (![x.TextOnly, x.Playground].includes(n.chatMode)) {
|
|
1633
1631
|
if (!n.streamingManager)
|
|
1634
|
-
throw new
|
|
1632
|
+
throw new le("Streaming manager is not initialized");
|
|
1635
1633
|
if (!n.chat)
|
|
1636
|
-
throw new
|
|
1634
|
+
throw new le("Chat is not initialized");
|
|
1637
1635
|
}
|
|
1638
1636
|
}, R = async () => {
|
|
1639
|
-
var j,
|
|
1637
|
+
var j, $;
|
|
1640
1638
|
if (!n.chat) {
|
|
1641
|
-
const
|
|
1642
|
-
|
|
1643
|
-
|
|
1639
|
+
const G = await Ze(
|
|
1640
|
+
u,
|
|
1641
|
+
p,
|
|
1644
1642
|
c,
|
|
1645
1643
|
n.chatMode,
|
|
1646
1644
|
t.persistentChat
|
|
1647
1645
|
);
|
|
1648
|
-
if (!
|
|
1649
|
-
throw new
|
|
1650
|
-
n.chat =
|
|
1646
|
+
if (!G.chat)
|
|
1647
|
+
throw new it(n.chatMode, !!t.persistentChat);
|
|
1648
|
+
n.chat = G.chat, ($ = (j = t.callbacks).onNewChat) == null || $.call(j, n.chat.id);
|
|
1651
1649
|
}
|
|
1652
1650
|
return n.chat.id;
|
|
1653
|
-
},
|
|
1654
|
-
const
|
|
1655
|
-
return
|
|
1651
|
+
}, K = async (j, $) => {
|
|
1652
|
+
const G = n.chatMode === x.Playground;
|
|
1653
|
+
return De(v && !G ? async () => {
|
|
1656
1654
|
var m, M;
|
|
1657
|
-
return await ((M = (m = n.streamingManager) == null ? void 0 : m.sendTextMessage) == null ? void 0 : M.call(m,
|
|
1655
|
+
return await ((M = (m = n.streamingManager) == null ? void 0 : m.sendTextMessage) == null ? void 0 : M.call(m, l)), Promise.resolve({});
|
|
1658
1656
|
} : async () => {
|
|
1659
1657
|
var m, M;
|
|
1660
|
-
return
|
|
1661
|
-
|
|
1662
|
-
|
|
1658
|
+
return p.chat(
|
|
1659
|
+
u.id,
|
|
1660
|
+
$,
|
|
1663
1661
|
{
|
|
1664
1662
|
chatMode: n.chatMode,
|
|
1665
1663
|
streamId: (m = n.streamingManager) == null ? void 0 : m.streamId,
|
|
1666
1664
|
sessionId: (M = n.streamingManager) == null ? void 0 : M.sessionId,
|
|
1667
|
-
messages: j.map(({ matches:
|
|
1665
|
+
messages: j.map(({ matches: W, ...ce }) => ce)
|
|
1668
1666
|
},
|
|
1669
1667
|
{
|
|
1670
|
-
...
|
|
1668
|
+
...Ge(n.chatMode),
|
|
1671
1669
|
skipErrorHandler: !0
|
|
1672
1670
|
}
|
|
1673
1671
|
);
|
|
1674
1672
|
}, {
|
|
1675
1673
|
limit: 2,
|
|
1676
1674
|
shouldRetryFn: (m) => {
|
|
1677
|
-
var ce, de,
|
|
1675
|
+
var ce, de, pe, we;
|
|
1678
1676
|
const M = (ce = m == null ? void 0 : m.message) == null ? void 0 : ce.includes("missing or invalid session_id");
|
|
1679
|
-
return !((de = m == null ? void 0 : m.message) == null ? void 0 : de.includes("Stream Error")) && !M ? ((
|
|
1677
|
+
return !((de = m == null ? void 0 : m.message) == null ? void 0 : de.includes("Stream Error")) && !M ? ((we = (pe = t.callbacks).onError) == null || we.call(pe, m), !1) : !0;
|
|
1680
1678
|
},
|
|
1681
1679
|
onRetry: async () => {
|
|
1682
|
-
await
|
|
1680
|
+
await b(), await E(!1);
|
|
1683
1681
|
}
|
|
1684
1682
|
});
|
|
1685
1683
|
};
|
|
1686
1684
|
try {
|
|
1687
|
-
|
|
1688
|
-
id:
|
|
1685
|
+
P(), D(), n.messages.push({
|
|
1686
|
+
id: fe(),
|
|
1689
1687
|
role: "user",
|
|
1690
|
-
content:
|
|
1691
|
-
created_at: new Date(
|
|
1692
|
-
}), (_ = (
|
|
1693
|
-
const j = await R(),
|
|
1688
|
+
content: l,
|
|
1689
|
+
created_at: new Date(ne.update()).toISOString()
|
|
1690
|
+
}), (_ = (L = t.callbacks).onNewMessage) == null || _.call(L, [...n.messages], "user");
|
|
1691
|
+
const j = await R(), $ = await K([...n.messages], j);
|
|
1694
1692
|
return n.messages.push({
|
|
1695
|
-
id:
|
|
1693
|
+
id: fe(),
|
|
1696
1694
|
role: "assistant",
|
|
1697
|
-
content:
|
|
1695
|
+
content: $.result || "",
|
|
1698
1696
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1699
|
-
context:
|
|
1700
|
-
matches:
|
|
1697
|
+
context: $.context,
|
|
1698
|
+
matches: $.matches
|
|
1701
1699
|
}), c.track("agent-message-send", {
|
|
1702
1700
|
event: "success",
|
|
1703
1701
|
messages: n.messages.length + 1
|
|
1704
|
-
}),
|
|
1705
|
-
latency:
|
|
1702
|
+
}), $.result && ((q = (B = t.callbacks).onNewMessage) == null || q.call(B, [...n.messages], "answer"), c.track("agent-message-received", {
|
|
1703
|
+
latency: ne.get(!0),
|
|
1706
1704
|
messages: n.messages.length
|
|
1707
|
-
})),
|
|
1705
|
+
})), $;
|
|
1708
1706
|
} catch (j) {
|
|
1709
|
-
throw ((
|
|
1707
|
+
throw ((Q = n.messages[n.messages.length - 1]) == null ? void 0 : Q.role) === "assistant" && n.messages.pop(), c.track("agent-message-send", {
|
|
1710
1708
|
event: "error",
|
|
1711
1709
|
messages: n.messages.length
|
|
1712
1710
|
}), j;
|
|
1713
1711
|
}
|
|
1714
1712
|
},
|
|
1715
|
-
rate(
|
|
1716
|
-
var _,
|
|
1717
|
-
const
|
|
1713
|
+
rate(l, D, R) {
|
|
1714
|
+
var _, B, q, Q;
|
|
1715
|
+
const K = n.messages.find((j) => j.id === l);
|
|
1718
1716
|
if (n.chat) {
|
|
1719
|
-
if (!
|
|
1717
|
+
if (!K)
|
|
1720
1718
|
throw new Error("Message not found");
|
|
1721
1719
|
} else throw new Error("Chat is not initialized");
|
|
1722
|
-
const
|
|
1720
|
+
const L = ((_ = K.matches) == null ? void 0 : _.map((j) => [j.document_id, j.id])) ?? [];
|
|
1723
1721
|
return c.track("agent-rate", {
|
|
1724
1722
|
event: R ? "update" : "create",
|
|
1725
|
-
thumb:
|
|
1726
|
-
knowledge_id: ((
|
|
1727
|
-
matches:
|
|
1728
|
-
score:
|
|
1729
|
-
}), R ?
|
|
1730
|
-
knowledge_id: ((q =
|
|
1731
|
-
message_id:
|
|
1732
|
-
matches:
|
|
1733
|
-
score:
|
|
1734
|
-
}) :
|
|
1735
|
-
knowledge_id: ((
|
|
1736
|
-
message_id:
|
|
1737
|
-
matches:
|
|
1738
|
-
score:
|
|
1723
|
+
thumb: D === 1 ? "up" : "down",
|
|
1724
|
+
knowledge_id: ((B = u.knowledge) == null ? void 0 : B.id) ?? "",
|
|
1725
|
+
matches: L,
|
|
1726
|
+
score: D
|
|
1727
|
+
}), R ? p.updateRating(u.id, n.chat.id, R, {
|
|
1728
|
+
knowledge_id: ((q = u.knowledge) == null ? void 0 : q.id) ?? "",
|
|
1729
|
+
message_id: l,
|
|
1730
|
+
matches: L,
|
|
1731
|
+
score: D
|
|
1732
|
+
}) : p.createRating(u.id, n.chat.id, {
|
|
1733
|
+
knowledge_id: ((Q = u.knowledge) == null ? void 0 : Q.id) ?? "",
|
|
1734
|
+
message_id: l,
|
|
1735
|
+
matches: L,
|
|
1736
|
+
score: D
|
|
1739
1737
|
});
|
|
1740
1738
|
},
|
|
1741
|
-
deleteRate(
|
|
1739
|
+
deleteRate(l) {
|
|
1742
1740
|
if (!n.chat)
|
|
1743
1741
|
throw new Error("Chat is not initialized");
|
|
1744
|
-
return c.track("agent-rate-delete", { type: "text" }),
|
|
1742
|
+
return c.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, n.chat.id, l);
|
|
1745
1743
|
},
|
|
1746
|
-
async speak(
|
|
1747
|
-
var
|
|
1748
|
-
function
|
|
1749
|
-
if (typeof
|
|
1750
|
-
if (!
|
|
1744
|
+
async speak(l) {
|
|
1745
|
+
var L, _, B;
|
|
1746
|
+
function D() {
|
|
1747
|
+
if (typeof l == "string") {
|
|
1748
|
+
if (!u.presenter.voice)
|
|
1751
1749
|
throw new Error("Presenter voice is not initialized");
|
|
1752
1750
|
return {
|
|
1753
1751
|
type: "text",
|
|
1754
|
-
provider:
|
|
1755
|
-
input:
|
|
1752
|
+
provider: u.presenter.voice,
|
|
1753
|
+
input: l,
|
|
1756
1754
|
ssml: !1
|
|
1757
1755
|
};
|
|
1758
1756
|
}
|
|
1759
|
-
if (
|
|
1760
|
-
if (!
|
|
1757
|
+
if (l.type === "text" && !l.provider) {
|
|
1758
|
+
if (!u.presenter.voice)
|
|
1761
1759
|
throw new Error("Presenter voice is not initialized");
|
|
1762
1760
|
return {
|
|
1763
1761
|
type: "text",
|
|
1764
|
-
provider:
|
|
1765
|
-
input:
|
|
1766
|
-
ssml:
|
|
1762
|
+
provider: u.presenter.voice,
|
|
1763
|
+
input: l.input,
|
|
1764
|
+
ssml: l.ssml
|
|
1767
1765
|
};
|
|
1768
1766
|
}
|
|
1769
|
-
return
|
|
1767
|
+
return l;
|
|
1770
1768
|
}
|
|
1771
|
-
const R =
|
|
1772
|
-
if (c.track("agent-speak", R),
|
|
1773
|
-
id:
|
|
1769
|
+
const R = D();
|
|
1770
|
+
if (c.track("agent-speak", R), ne.update(), n.messages && R.type === "text" && (n.messages.push({
|
|
1771
|
+
id: fe(),
|
|
1774
1772
|
role: "assistant",
|
|
1775
1773
|
content: R.input,
|
|
1776
1774
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1777
|
-
}), (_ = (
|
|
1775
|
+
}), (_ = (L = t.callbacks).onNewMessage) == null || _.call(L, [...n.messages], "answer")), St(n.chatMode))
|
|
1778
1776
|
return {
|
|
1779
1777
|
duration: 0,
|
|
1780
1778
|
video_id: "",
|
|
@@ -1784,36 +1782,36 @@ async function Mn(e, t) {
|
|
|
1784
1782
|
throw new Error("Please connect to the agent first");
|
|
1785
1783
|
return n.streamingManager.speak({
|
|
1786
1784
|
script: R,
|
|
1787
|
-
metadata: { chat_id: (
|
|
1785
|
+
metadata: { chat_id: (B = n.chat) == null ? void 0 : B.id, agent_id: u.id }
|
|
1788
1786
|
});
|
|
1789
1787
|
},
|
|
1790
|
-
interrupt:
|
|
1788
|
+
interrupt: S
|
|
1791
1789
|
};
|
|
1792
1790
|
}
|
|
1793
1791
|
export {
|
|
1794
1792
|
O as AgentActivityState,
|
|
1795
|
-
|
|
1796
|
-
|
|
1793
|
+
dt as AgentStatus,
|
|
1794
|
+
it as ChatCreationFailed,
|
|
1797
1795
|
x as ChatMode,
|
|
1798
|
-
|
|
1799
|
-
|
|
1796
|
+
at as ChatModeDowngraded,
|
|
1797
|
+
Y as ChatProgress,
|
|
1800
1798
|
T as ConnectionState,
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1799
|
+
re as ConnectivityState,
|
|
1800
|
+
mt as DocumentType,
|
|
1801
|
+
ft as KnowledgeType,
|
|
1802
|
+
ct as PlanGroup,
|
|
1803
|
+
gt as Providers,
|
|
1804
|
+
ut as RateState,
|
|
1807
1805
|
A as StreamEvents,
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1806
|
+
ie as StreamType,
|
|
1807
|
+
C as StreamingState,
|
|
1808
|
+
lt as Subject,
|
|
1811
1809
|
ke as TransportProvider,
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1810
|
+
st as UserPlan,
|
|
1811
|
+
le as ValidationError,
|
|
1812
|
+
He as VideoType,
|
|
1813
|
+
ht as VoiceAccess,
|
|
1814
|
+
ot as WsError,
|
|
1815
|
+
kn as createAgentManager,
|
|
1816
|
+
Sn as mapVideoType
|
|
1819
1817
|
};
|