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