@d-id/client-sdk 1.1.56-staging.253 → 1.1.56-staging.254
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
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var pt = Object.defineProperty;
|
|
2
2
|
var wt = (e, n, i) => n in e ? pt(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
|
-
var
|
|
4
|
-
class
|
|
3
|
+
var fe = (e, n, i) => wt(e, typeof n != "symbol" ? n + "" : n, 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
|
+
fe(this, "kind");
|
|
8
|
+
fe(this, "description");
|
|
9
|
+
fe(this, "error");
|
|
10
10
|
this.kind = i, this.description = r, this.error = o;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class yt extends
|
|
13
|
+
class yt extends Se {
|
|
14
14
|
constructor(n, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,24 +18,24 @@ class yt extends Re {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class vt extends
|
|
21
|
+
class vt extends Se {
|
|
22
22
|
constructor(n) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${n}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class de extends Se {
|
|
27
27
|
constructor(i, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
fe(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class Ct extends
|
|
33
|
+
class Ct extends Se {
|
|
34
34
|
constructor(n) {
|
|
35
35
|
super({ kind: "WSError", description: n });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var St = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(St || {}), Rt = /* @__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))(Rt || {}), Tt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Tt || {}), kt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(kt || {}),
|
|
38
|
+
var St = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(St || {}), Rt = /* @__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))(Rt || {}), Tt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Tt || {}), kt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(kt || {}), U = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(U || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Et || {}), Dt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Dt || {}), It = /* @__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))(It || {}), Ze = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ze || {});
|
|
39
39
|
const Fn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -48,9 +48,9 @@ const Fn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}),
|
|
52
|
-
const _t = 45 * 1e3, bt = "X-Playground-Chat",
|
|
53
|
-
}, et = (e) => new Promise((n) => setTimeout(n, e)),
|
|
51
|
+
var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), 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.ToolActive = "TOOL_ACTIVE", e))(O || {}), D = /* @__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.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(D || {}), b = /* @__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))(b || {}), ie = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ie || {}), Pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Pe || {}), Mt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Mt || {}), At = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(At || {});
|
|
52
|
+
const _t = 45 * 1e3, bt = "X-Playground-Chat", pe = "https://api.d-id.com", Pt = "wss://notifications.d-id.com", Lt = "79f81a83a67430be2bc0fd61042b8faa", jt = (...e) => {
|
|
53
|
+
}, et = (e) => new Promise((n) => setTimeout(n, e)), ue = (e = 16) => {
|
|
54
54
|
const n = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
56
|
}, tt = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, $t = (e) => {
|
|
@@ -62,7 +62,7 @@ const _t = 45 * 1e3, bt = "X-Playground-Chat", we = "https://api.d-id.com", Pt =
|
|
|
62
62
|
case "talk":
|
|
63
63
|
return "v2";
|
|
64
64
|
}
|
|
65
|
-
}, xt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Le = (e) => e === Ze.Expressive, Bt = (e) => [
|
|
65
|
+
}, xt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Le = (e) => e === Ze.Expressive, Bt = (e) => [U.TextOnly, U.Playground, U.Maintenance].includes(e), nt = (e) => e && [U.DirectPlayback, U.Off].includes(e);
|
|
66
66
|
function Ft(e, n) {
|
|
67
67
|
let i;
|
|
68
68
|
return {
|
|
@@ -101,12 +101,12 @@ function Me(e) {
|
|
|
101
101
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
102
102
|
let n = window.localStorage.getItem("did_external_key_id");
|
|
103
103
|
if (!n) {
|
|
104
|
-
let i =
|
|
104
|
+
let i = ue();
|
|
105
105
|
window.localStorage.setItem("did_external_key_id", i), n = i;
|
|
106
106
|
}
|
|
107
107
|
return n;
|
|
108
108
|
}
|
|
109
|
-
let zt =
|
|
109
|
+
let zt = ue();
|
|
110
110
|
function rt(e, n) {
|
|
111
111
|
if (e.type === "bearer")
|
|
112
112
|
return `Bearer ${e.token}`;
|
|
@@ -122,7 +122,7 @@ const Kt = (e) => Ie(e, {
|
|
|
122
122
|
timeout: 0,
|
|
123
123
|
shouldRetryFn: (n) => n.status === 429
|
|
124
124
|
});
|
|
125
|
-
function je(e, n =
|
|
125
|
+
function je(e, n = pe, i, r) {
|
|
126
126
|
const o = async (a, s) => {
|
|
127
127
|
const { skipErrorHandler: d, ...t } = s || {}, c = await Kt(
|
|
128
128
|
() => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
@@ -135,8 +135,8 @@ function je(e, n = we, i, r) {
|
|
|
135
135
|
})
|
|
136
136
|
);
|
|
137
137
|
if (!c.ok) {
|
|
138
|
-
let
|
|
139
|
-
const g = new Error(
|
|
138
|
+
let h = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
|
|
139
|
+
const g = new Error(h);
|
|
140
140
|
throw i && !d && i(g, { url: a, options: t, headers: c.headers }), g;
|
|
141
141
|
}
|
|
142
142
|
return c.json();
|
|
@@ -156,7 +156,7 @@ function je(e, n = we, i, r) {
|
|
|
156
156
|
}
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
function Nt(e, n =
|
|
159
|
+
function Nt(e, n = pe, i, r) {
|
|
160
160
|
const o = je(e, `${n}/agents`, i, r);
|
|
161
161
|
return {
|
|
162
162
|
create(a, s) {
|
|
@@ -239,13 +239,13 @@ function Ut(e) {
|
|
|
239
239
|
}
|
|
240
240
|
const Jt = (e) => e.reduce((n, i) => n + i, 0), Je = (e) => Jt(e) / e.length;
|
|
241
241
|
function Ot(e, n, i) {
|
|
242
|
-
var t, c,
|
|
242
|
+
var t, c, h;
|
|
243
243
|
const { event: r, ...o } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: s } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
|
|
244
244
|
return {
|
|
245
245
|
...o,
|
|
246
246
|
llm: { ...o.llm, template: a },
|
|
247
247
|
script: { ...o.script, provider: { ...(c = o == null ? void 0 : o.script) == null ? void 0 : c.provider, language: s } },
|
|
248
|
-
stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (
|
|
248
|
+
stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (h = n == null ? void 0 : n.presenter) == null ? void 0 : h.stitch : void 0,
|
|
249
249
|
...i
|
|
250
250
|
};
|
|
251
251
|
}
|
|
@@ -264,7 +264,7 @@ function Ht(e) {
|
|
|
264
264
|
...e.mixpanelAdditionalProperties || {}
|
|
265
265
|
},
|
|
266
266
|
isEnabled: e.isEnabled ?? !0,
|
|
267
|
-
getRandom:
|
|
267
|
+
getRandom: ue,
|
|
268
268
|
enrich(r) {
|
|
269
269
|
this.additionalProperties = { ...this.additionalProperties, ...r };
|
|
270
270
|
},
|
|
@@ -297,7 +297,7 @@ function Ht(e) {
|
|
|
297
297
|
])
|
|
298
298
|
})
|
|
299
299
|
};
|
|
300
|
-
return fetch(Wt, c).catch((
|
|
300
|
+
return fetch(Wt, c).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
|
|
301
301
|
},
|
|
302
302
|
linkTrack(r, o, a, s) {
|
|
303
303
|
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), s.includes(a) || s.push(a);
|
|
@@ -305,11 +305,11 @@ function Ht(e) {
|
|
|
305
305
|
if (d.events[a] = { props: o }, d.resolvedDependencies.push(a), s.every(
|
|
306
306
|
(c) => d.resolvedDependencies.includes(c)
|
|
307
307
|
)) {
|
|
308
|
-
const c = s.reduce((
|
|
308
|
+
const c = s.reduce((h, g) => d.events[g] ? { ...h, ...d.events[g].props } : h, {});
|
|
309
309
|
this.track(r, c), d.resolvedDependencies = d.resolvedDependencies.filter(
|
|
310
|
-
(
|
|
311
|
-
), s.forEach((
|
|
312
|
-
delete d.events[
|
|
310
|
+
(h) => !s.includes(h)
|
|
311
|
+
), s.forEach((h) => {
|
|
312
|
+
delete d.events[h];
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
315
|
}
|
|
@@ -323,9 +323,9 @@ function $e() {
|
|
|
323
323
|
get: (n = !1) => n ? Date.now() - e : e
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
|
-
const
|
|
326
|
+
const re = $e(), Ae = $e(), We = $e();
|
|
327
327
|
function it(e) {
|
|
328
|
-
return e ===
|
|
328
|
+
return e === U.Playground ? { headers: { [bt]: "true" } } : {};
|
|
329
329
|
}
|
|
330
330
|
async function at(e, n, i, r, o = !1, a) {
|
|
331
331
|
try {
|
|
@@ -358,8 +358,8 @@ function Xt(e, n, i, r) {
|
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
360
|
const ot = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), Yt = {
|
|
361
|
-
[
|
|
362
|
-
[
|
|
361
|
+
[D.ChatAnswer]: X.Answer,
|
|
362
|
+
[D.ChatPartial]: X.Partial
|
|
363
363
|
};
|
|
364
364
|
function Gt(e, n, i) {
|
|
365
365
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
@@ -496,7 +496,7 @@ function st(e, n) {
|
|
|
496
496
|
return i;
|
|
497
497
|
return null;
|
|
498
498
|
}
|
|
499
|
-
const
|
|
499
|
+
const ge = 10;
|
|
500
500
|
function tn(e, n) {
|
|
501
501
|
let i = !1, r = !1, o = null, a = 0, s = 0, d = {};
|
|
502
502
|
async function t() {
|
|
@@ -504,39 +504,39 @@ function tn(e, n) {
|
|
|
504
504
|
try {
|
|
505
505
|
const c = await e();
|
|
506
506
|
if (!c) {
|
|
507
|
-
o = setTimeout(t,
|
|
507
|
+
o = setTimeout(t, ge);
|
|
508
508
|
return;
|
|
509
509
|
}
|
|
510
|
-
const
|
|
511
|
-
if (!
|
|
512
|
-
o = setTimeout(t,
|
|
510
|
+
const h = st(c, "audio");
|
|
511
|
+
if (!h) {
|
|
512
|
+
o = setTimeout(t, ge);
|
|
513
513
|
return;
|
|
514
514
|
}
|
|
515
|
-
const g =
|
|
515
|
+
const g = h.totalAudioEnergy ?? 0, l = h.totalSamplesReceived ?? 0;
|
|
516
516
|
if (!r) {
|
|
517
|
-
a = g, s = l, r = !0, o = setTimeout(t,
|
|
517
|
+
a = g, s = l, r = !0, o = setTimeout(t, ge);
|
|
518
518
|
return;
|
|
519
519
|
}
|
|
520
|
-
const
|
|
521
|
-
if (a = g, s = l,
|
|
520
|
+
const y = g - a, M = l - s;
|
|
521
|
+
if (a = g, s = l, M > 0 && y > 0) {
|
|
522
522
|
i = !1, n(d);
|
|
523
523
|
return;
|
|
524
524
|
}
|
|
525
525
|
} catch {
|
|
526
526
|
}
|
|
527
|
-
i && (o = setTimeout(t,
|
|
527
|
+
i && (o = setTimeout(t, ge));
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
return {
|
|
531
531
|
arm(c = {}) {
|
|
532
|
-
d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t,
|
|
532
|
+
d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t, ge);
|
|
533
533
|
},
|
|
534
534
|
destroy() {
|
|
535
535
|
i = !1, o !== null && (clearTimeout(o), o = null);
|
|
536
536
|
}
|
|
537
537
|
};
|
|
538
538
|
}
|
|
539
|
-
const
|
|
539
|
+
const Ce = 100, nn = Math.max(Math.ceil(400 / Ce), 1), rn = 0.25, an = 0.28;
|
|
540
540
|
function on() {
|
|
541
541
|
let e = 0, n, i, r = 0;
|
|
542
542
|
return (o) => {
|
|
@@ -545,8 +545,8 @@ function on() {
|
|
|
545
545
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
546
546
|
const s = a.jitterBufferDelay, d = a.jitterBufferEmittedCount;
|
|
547
547
|
if (i && d > i) {
|
|
548
|
-
const
|
|
549
|
-
r =
|
|
548
|
+
const h = s - n, g = d - i;
|
|
549
|
+
r = h / g;
|
|
550
550
|
}
|
|
551
551
|
n = s, i = d;
|
|
552
552
|
const t = a.framesDecoded, c = t - e > 0;
|
|
@@ -554,28 +554,28 @@ function on() {
|
|
|
554
554
|
};
|
|
555
555
|
}
|
|
556
556
|
function ct(e, n, i, r, o) {
|
|
557
|
-
let a = null, s = [], d, t = 0, c = !1,
|
|
558
|
-
const
|
|
559
|
-
async function
|
|
557
|
+
let a = null, s = [], d, t = 0, c = !1, h = ne.Unknown, g = ne.Unknown, l = 0, y = 0;
|
|
558
|
+
const M = on();
|
|
559
|
+
async function z() {
|
|
560
560
|
const L = await e();
|
|
561
561
|
if (!L)
|
|
562
562
|
return;
|
|
563
|
-
const { isReceiving:
|
|
564
|
-
if (
|
|
565
|
-
t = 0, l = k -
|
|
563
|
+
const { isReceiving: $, avgJitterDelayInInterval: A, freezeCount: k } = M(L), W = en(L);
|
|
564
|
+
if ($)
|
|
565
|
+
t = 0, l = k - y, g = A < rn ? ne.Strong : A > an && l > 1 ? ne.Weak : h, g !== h && (o == null || o(g), h = g, y += l, l = 0), c || (r == null || r(T.Start), d = s[s.length - 1], s = [], c = !0), s.push(W);
|
|
566
566
|
else if (c && (t++, t >= nn)) {
|
|
567
|
-
const
|
|
568
|
-
r == null || r(T.Stop,
|
|
567
|
+
const H = He(s, Ce, d);
|
|
568
|
+
r == null || r(T.Stop, H), n() || i(), y = k, c = !1;
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
return {
|
|
572
572
|
start: () => {
|
|
573
|
-
a || (a = setInterval(
|
|
573
|
+
a || (a = setInterval(z, Ce));
|
|
574
574
|
},
|
|
575
575
|
stop: () => {
|
|
576
576
|
a && (clearInterval(a), a = null);
|
|
577
577
|
},
|
|
578
|
-
getReport: () => He(s,
|
|
578
|
+
getReport: () => He(s, Ce, d)
|
|
579
579
|
};
|
|
580
580
|
}
|
|
581
581
|
const qe = 2e4;
|
|
@@ -589,12 +589,12 @@ async function sn() {
|
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
591
|
const cn = {
|
|
592
|
-
excellent:
|
|
593
|
-
good:
|
|
594
|
-
poor:
|
|
595
|
-
lost:
|
|
596
|
-
unknown:
|
|
597
|
-
},
|
|
592
|
+
excellent: ne.Strong,
|
|
593
|
+
good: ne.Strong,
|
|
594
|
+
poor: ne.Weak,
|
|
595
|
+
lost: ne.Unknown,
|
|
596
|
+
unknown: ne.Unknown
|
|
597
|
+
}, he = JSON.stringify({
|
|
598
598
|
kind: "InternalServerError",
|
|
599
599
|
description: "Stream Error"
|
|
600
600
|
});
|
|
@@ -605,242 +605,242 @@ function _e(e, n, i) {
|
|
|
605
605
|
}
|
|
606
606
|
async function dn(e, n, i) {
|
|
607
607
|
var ze;
|
|
608
|
-
const r = ot(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await sn(), { callbacks: t, auth: c, baseURL:
|
|
609
|
-
let l = null,
|
|
610
|
-
const
|
|
611
|
-
let
|
|
612
|
-
const L = { isPublishing: !1, publication: null },
|
|
613
|
-
let
|
|
608
|
+
const r = ot(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await sn(), { callbacks: t, auth: c, baseURL: h, analytics: g } = i;
|
|
609
|
+
let l = null, y = !1;
|
|
610
|
+
const M = ie.Fluent;
|
|
611
|
+
let z = null;
|
|
612
|
+
const L = { isPublishing: !1, publication: null }, $ = { isPublishing: !1, publication: null };
|
|
613
|
+
let A = null, k = null, W = null, H = !1;
|
|
614
614
|
l = new o({
|
|
615
615
|
adaptiveStream: !1,
|
|
616
616
|
// Must be false to use mediaStreamTrack directly
|
|
617
617
|
dynacast: !0
|
|
618
618
|
});
|
|
619
|
-
let
|
|
620
|
-
const
|
|
621
|
-
let
|
|
619
|
+
let K = null, G = O.Idle, ae = !0;
|
|
620
|
+
const B = Xt(c, h || pe, e, t.onError);
|
|
621
|
+
let f, S, E;
|
|
622
622
|
try {
|
|
623
|
-
const u = await
|
|
623
|
+
const u = await B.createStream({
|
|
624
624
|
transport: n.transport,
|
|
625
625
|
chat_persist: n.chat_persist ?? !0
|
|
626
|
-
}), { id:
|
|
627
|
-
(ze = t.onStreamCreated) == null || ze.call(t, { session_id:
|
|
626
|
+
}), { id: m, session_token: p, session_url: v } = u;
|
|
627
|
+
(ze = t.onStreamCreated) == null || ze.call(t, { session_id: m, stream_id: m, agent_id: e }), f = m, S = p, E = v, await l.prepareConnection(E, S);
|
|
628
628
|
} catch (u) {
|
|
629
629
|
_e(u, r, t);
|
|
630
630
|
}
|
|
631
|
-
if (!
|
|
631
|
+
if (!E || !S || !f)
|
|
632
632
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
633
|
-
l.on(a.ConnectionStateChanged,
|
|
634
|
-
function
|
|
635
|
-
var
|
|
636
|
-
|
|
633
|
+
l.on(a.ConnectionStateChanged, F).on(a.ConnectionQualityChanged, I).on(a.ParticipantConnected, q).on(a.ParticipantDisconnected, Y).on(a.TrackSubscribed, V).on(a.TrackUnsubscribed, ee).on(a.DataReceived, we).on(a.MediaDevicesError, ye).on(a.TranscriptionReceived, J).on(a.EncryptionError, ve).on(a.TrackSubscriptionFailed, dt);
|
|
634
|
+
function J(u, m) {
|
|
635
|
+
var p;
|
|
636
|
+
m != null && m.isLocal && (re.update(), G === O.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), G = O.Idle));
|
|
637
637
|
}
|
|
638
638
|
try {
|
|
639
|
-
await l.connect(
|
|
639
|
+
await l.connect(E, S), r("LiveKit room joined successfully"), K = setTimeout(() => {
|
|
640
640
|
var u;
|
|
641
641
|
r(
|
|
642
642
|
`Track subscription timeout - no track subscribed within ${qe / 1e3} seconds after connect`
|
|
643
|
-
),
|
|
643
|
+
), K = null, g.track("connectivity-error", {
|
|
644
644
|
error: "Track subscription timeout",
|
|
645
|
-
sessionId:
|
|
646
|
-
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId:
|
|
645
|
+
sessionId: f
|
|
646
|
+
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: f }), De("internal:track-subscription-timeout");
|
|
647
647
|
}, qe);
|
|
648
648
|
} catch (u) {
|
|
649
649
|
_e(u, r, t);
|
|
650
650
|
}
|
|
651
651
|
g.enrich({
|
|
652
|
-
"stream-type":
|
|
652
|
+
"stream-type": M
|
|
653
653
|
});
|
|
654
|
-
function
|
|
655
|
-
var
|
|
654
|
+
function F(u) {
|
|
655
|
+
var m, p, v, _;
|
|
656
656
|
switch (r("Connection state changed:", u), u) {
|
|
657
657
|
case s.Connecting:
|
|
658
|
-
r("CALLBACK: onConnectionStateChange(Connecting)"), (
|
|
658
|
+
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, b.Connecting, "livekit:connecting");
|
|
659
659
|
break;
|
|
660
660
|
case s.Connected:
|
|
661
|
-
r("LiveKit room connected successfully"),
|
|
661
|
+
r("LiveKit room connected successfully"), y = !0;
|
|
662
662
|
break;
|
|
663
663
|
case s.Disconnected:
|
|
664
|
-
r("LiveKit room disconnected"),
|
|
664
|
+
r("LiveKit room disconnected"), y = !1, H = !1, L.publication = null, $.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, b.Disconnected, "livekit:disconnected");
|
|
665
665
|
break;
|
|
666
666
|
case s.Reconnecting:
|
|
667
|
-
r("LiveKit room reconnecting..."), (
|
|
667
|
+
r("LiveKit room reconnecting..."), (v = t.onConnectionStateChange) == null || v.call(t, b.Connecting, "livekit:reconnecting");
|
|
668
668
|
break;
|
|
669
669
|
case s.SignalReconnecting:
|
|
670
670
|
r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, b.Connecting, "livekit:signal-reconnecting");
|
|
671
671
|
break;
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
|
-
function
|
|
675
|
-
var
|
|
676
|
-
r("Connection quality:", u),
|
|
674
|
+
function I(u, m) {
|
|
675
|
+
var p;
|
|
676
|
+
r("Connection quality:", u), m != null && m.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, cn[u]));
|
|
677
677
|
}
|
|
678
|
-
function
|
|
678
|
+
function q(u) {
|
|
679
679
|
r("Participant connected:", u.identity);
|
|
680
680
|
}
|
|
681
|
-
function
|
|
681
|
+
function Y(u) {
|
|
682
682
|
r("Participant disconnected:", u.identity), De("livekit:participant-disconnected");
|
|
683
683
|
}
|
|
684
|
-
function
|
|
684
|
+
function Z() {
|
|
685
685
|
var u;
|
|
686
|
-
|
|
686
|
+
W !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), W = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
|
|
687
687
|
}
|
|
688
688
|
function x(u) {
|
|
689
|
-
var
|
|
690
|
-
|
|
689
|
+
var m;
|
|
690
|
+
W !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), W = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
|
|
691
691
|
}
|
|
692
|
-
function
|
|
693
|
-
var _, P,
|
|
694
|
-
r(`Track subscribed: ${u.kind} from ${
|
|
695
|
-
const
|
|
696
|
-
if (!
|
|
692
|
+
function V(u, m, p) {
|
|
693
|
+
var _, P, Q;
|
|
694
|
+
r(`Track subscribed: ${u.kind} from ${p.identity}`);
|
|
695
|
+
const v = u.mediaStreamTrack;
|
|
696
|
+
if (!v) {
|
|
697
697
|
r(`No mediaStreamTrack available for ${u.kind}`);
|
|
698
698
|
return;
|
|
699
699
|
}
|
|
700
|
-
|
|
700
|
+
z ? (z.addTrack(v), r(`Added ${u.kind} track to shared MediaStream`)) : (z = new MediaStream([v]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = tn(
|
|
701
701
|
() => u.getRTCStatsReport(),
|
|
702
|
-
({ sttLatency:
|
|
702
|
+
({ sttLatency: N, serviceLatency: te }) => {
|
|
703
703
|
var Ke, Ne, Ve;
|
|
704
|
-
const
|
|
705
|
-
let
|
|
706
|
-
if (
|
|
707
|
-
const Ue = ((Ne = (Ke =
|
|
708
|
-
|
|
704
|
+
const le = re.get(!0);
|
|
705
|
+
let me = 0;
|
|
706
|
+
if (N) {
|
|
707
|
+
const Ue = ((Ne = (Ke = A == null ? void 0 : A.getReport()) == null ? void 0 : Ke.webRTCStats) == null ? void 0 : Ne.avgRtt) ?? 0;
|
|
708
|
+
me = Ue > 0 ? Math.round(Ue * 1e3) : 0;
|
|
709
709
|
}
|
|
710
|
-
const
|
|
711
|
-
(Ve = t.onFirstAudioDetected) == null || Ve.call(t, { latency:
|
|
710
|
+
const ce = le > 0 ? le + (N ?? 0) + me : void 0, oe = ce !== void 0 && te !== void 0 ? ce - te : void 0;
|
|
711
|
+
(Ve = t.onFirstAudioDetected) == null || Ve.call(t, { latency: ce, networkLatency: oe });
|
|
712
712
|
}
|
|
713
|
-
)), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t,
|
|
713
|
+
)), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, z), H || (H = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (Q = t.onConnectionStateChange) == null || Q.call(t, b.Connected, "livekit:track-subscribed")), A = ct(
|
|
714
714
|
() => u.getRTCStatsReport(),
|
|
715
|
-
() =>
|
|
715
|
+
() => y,
|
|
716
716
|
jt,
|
|
717
|
-
(
|
|
718
|
-
r(`Video state change: ${
|
|
717
|
+
(N, te) => {
|
|
718
|
+
r(`Video state change: ${N}`), N === T.Start ? (K && (clearTimeout(K), K = null, r("Track subscription timeout cleared")), Z()) : N === T.Stop && x(te);
|
|
719
719
|
}
|
|
720
|
-
),
|
|
720
|
+
), A.start());
|
|
721
721
|
}
|
|
722
|
-
function
|
|
723
|
-
r(`Track unsubscribed: ${u.kind} from ${
|
|
722
|
+
function ee(u, m, p) {
|
|
723
|
+
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (x(A == null ? void 0 : A.getReport()), A == null || A.stop(), A = null);
|
|
724
724
|
}
|
|
725
|
-
function
|
|
726
|
-
var
|
|
727
|
-
const
|
|
728
|
-
|
|
725
|
+
function C(u, m) {
|
|
726
|
+
var v;
|
|
727
|
+
const p = Yt[u];
|
|
728
|
+
p && ((v = t.onMessage) == null || v.call(t, p, { event: p, ...m }));
|
|
729
729
|
}
|
|
730
|
-
function
|
|
731
|
-
var
|
|
732
|
-
if (u ===
|
|
733
|
-
|
|
730
|
+
function w(u, m) {
|
|
731
|
+
var p, v, _;
|
|
732
|
+
if (u === D.ToolCalling) {
|
|
733
|
+
G = O.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, O.ToolActive), (v = t.onToolEvent) == null || v.call(t, D.ToolCalling, m);
|
|
734
734
|
return;
|
|
735
735
|
}
|
|
736
|
-
u ===
|
|
736
|
+
u === D.ToolResult && ((_ = t.onToolEvent) == null || _.call(t, D.ToolResult, m));
|
|
737
737
|
}
|
|
738
|
-
function
|
|
739
|
-
var
|
|
740
|
-
if (
|
|
741
|
-
|
|
742
|
-
sttLatency: (P =
|
|
743
|
-
serviceLatency:
|
|
738
|
+
function R(u, m) {
|
|
739
|
+
var p, v, _, P, Q;
|
|
740
|
+
if (ae = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (v = t.onInterruptibleChange) == null || v.call(t, ae), u === D.StreamVideoCreated) {
|
|
741
|
+
G = O.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, O.Talking), k == null || k.arm({
|
|
742
|
+
sttLatency: (P = m == null ? void 0 : m.stt) == null ? void 0 : P.latency,
|
|
743
|
+
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
744
744
|
});
|
|
745
745
|
return;
|
|
746
746
|
}
|
|
747
|
-
|
|
747
|
+
ae && (G = O.Idle, (Q = t.onAgentActivityStateChange) == null || Q.call(t, O.Idle));
|
|
748
748
|
}
|
|
749
|
-
function
|
|
750
|
-
var P,
|
|
751
|
-
const
|
|
752
|
-
i.debug && ((
|
|
753
|
-
id:
|
|
754
|
-
name:
|
|
755
|
-
}), (
|
|
749
|
+
function j(u, m) {
|
|
750
|
+
var P, Q, N, te;
|
|
751
|
+
const p = ((Q = (P = A == null ? void 0 : A.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : Q.avgRtt) ?? 0, v = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: v };
|
|
752
|
+
i.debug && ((N = m == null ? void 0 : m.metadata) != null && N.sentiment) && (_.sentiment = {
|
|
753
|
+
id: m.metadata.sentiment.id,
|
|
754
|
+
name: m.metadata.sentiment.sentiment
|
|
755
|
+
}), (te = t.onMessage) == null || te.call(t, u, _), R(u, m);
|
|
756
756
|
}
|
|
757
|
-
function
|
|
758
|
-
var
|
|
759
|
-
(
|
|
760
|
-
var
|
|
761
|
-
(
|
|
757
|
+
function Re(u, m) {
|
|
758
|
+
var p;
|
|
759
|
+
(p = t.onMessage) == null || p.call(t, X.Transcribe, { event: X.Transcribe, ...m }), queueMicrotask(() => {
|
|
760
|
+
var v;
|
|
761
|
+
(v = t.onAgentActivityStateChange) == null || v.call(t, O.Loading);
|
|
762
762
|
});
|
|
763
763
|
}
|
|
764
|
-
const
|
|
765
|
-
[
|
|
766
|
-
[
|
|
767
|
-
[
|
|
768
|
-
[
|
|
769
|
-
[
|
|
770
|
-
[
|
|
771
|
-
[
|
|
772
|
-
[
|
|
773
|
-
[
|
|
764
|
+
const se = {
|
|
765
|
+
[D.ChatAnswer]: C,
|
|
766
|
+
[D.ChatPartial]: C,
|
|
767
|
+
[D.ToolCalling]: w,
|
|
768
|
+
[D.ToolResult]: w,
|
|
769
|
+
[D.StreamVideoCreated]: j,
|
|
770
|
+
[D.StreamVideoDone]: j,
|
|
771
|
+
[D.StreamVideoError]: j,
|
|
772
|
+
[D.StreamVideoRejected]: j,
|
|
773
|
+
[D.ChatAudioTranscribed]: Re
|
|
774
774
|
};
|
|
775
|
-
function
|
|
775
|
+
function we(u, m, p, v) {
|
|
776
776
|
const _ = new TextDecoder().decode(u);
|
|
777
777
|
try {
|
|
778
|
-
const P = JSON.parse(_),
|
|
779
|
-
if (r("Data received:", { subject:
|
|
780
|
-
const
|
|
781
|
-
|
|
778
|
+
const P = JSON.parse(_), Q = v || P.subject;
|
|
779
|
+
if (r("Data received:", { subject: Q, data: P }), !Q) return;
|
|
780
|
+
const N = se[Q];
|
|
781
|
+
N == null || N(Q, P);
|
|
782
782
|
} catch (P) {
|
|
783
783
|
r("Failed to parse data channel message:", P);
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
|
-
function
|
|
787
|
-
var
|
|
788
|
-
r("Media devices error:", u), (
|
|
786
|
+
function ye(u) {
|
|
787
|
+
var m;
|
|
788
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(he), { sessionId: f });
|
|
789
789
|
}
|
|
790
|
-
function
|
|
791
|
-
var
|
|
792
|
-
r("Encryption error:", u), (
|
|
790
|
+
function ve(u) {
|
|
791
|
+
var m;
|
|
792
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(he), { sessionId: f });
|
|
793
793
|
}
|
|
794
|
-
function dt(u,
|
|
795
|
-
r("Track subscription failed:", { trackSid: u, participant:
|
|
794
|
+
function dt(u, m, p) {
|
|
795
|
+
r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
|
|
796
796
|
}
|
|
797
|
-
function ut(u,
|
|
798
|
-
for (const [
|
|
799
|
-
if (_.source ===
|
|
797
|
+
function ut(u, m, p) {
|
|
798
|
+
for (const [v, _] of p)
|
|
799
|
+
if (_.source === m && _.track) {
|
|
800
800
|
const P = _.track.mediaStreamTrack;
|
|
801
801
|
if (P === u || (P == null ? void 0 : P.id) === u.id)
|
|
802
802
|
return _;
|
|
803
803
|
}
|
|
804
804
|
return null;
|
|
805
805
|
}
|
|
806
|
-
async function Be(u,
|
|
807
|
-
var
|
|
808
|
-
if (!
|
|
809
|
-
throw r(`Room is not connected, cannot publish ${
|
|
806
|
+
async function Be(u, m, p, v, _, P) {
|
|
807
|
+
var le, me, ce;
|
|
808
|
+
if (!y || !l)
|
|
809
|
+
throw r(`Room is not connected, cannot publish ${v} stream`), new Error("Room is not connected");
|
|
810
810
|
if (u.isPublishing) {
|
|
811
|
-
r(`${
|
|
811
|
+
r(`${v} publish already in progress, skipping`);
|
|
812
812
|
return;
|
|
813
813
|
}
|
|
814
|
-
const
|
|
815
|
-
if (
|
|
816
|
-
throw new Error(`No ${
|
|
817
|
-
const
|
|
818
|
-
if (
|
|
819
|
-
r(`${
|
|
820
|
-
trackId:
|
|
821
|
-
publishedTrackId: (
|
|
822
|
-
}), u.publication =
|
|
814
|
+
const Q = p(m);
|
|
815
|
+
if (Q.length === 0)
|
|
816
|
+
throw new Error(`No ${v} track found in the provided MediaStream`);
|
|
817
|
+
const N = Q[0], te = ut(N, v, _());
|
|
818
|
+
if (te) {
|
|
819
|
+
r(`${v} track is already published, skipping`, {
|
|
820
|
+
trackId: N.id,
|
|
821
|
+
publishedTrackId: (me = (le = te.track) == null ? void 0 : le.mediaStreamTrack) == null ? void 0 : me.id
|
|
822
|
+
}), u.publication = te;
|
|
823
823
|
return;
|
|
824
824
|
}
|
|
825
|
-
if ((
|
|
825
|
+
if ((ce = u.publication) != null && ce.track) {
|
|
826
826
|
const oe = u.publication.track.mediaStreamTrack;
|
|
827
|
-
oe !==
|
|
827
|
+
oe !== N && (oe == null ? void 0 : oe.id) !== N.id && (r(`Unpublishing existing ${v} track before publishing new one`), await P());
|
|
828
828
|
}
|
|
829
|
-
r(`Publishing ${
|
|
829
|
+
r(`Publishing ${v} track from provided MediaStream`, { trackId: N.id }), u.isPublishing = !0;
|
|
830
830
|
try {
|
|
831
|
-
u.publication = await l.localParticipant.publishTrack(
|
|
831
|
+
u.publication = await l.localParticipant.publishTrack(N, { source: v }), r(`${v} track published successfully`, { trackSid: u.publication.trackSid });
|
|
832
832
|
} catch (oe) {
|
|
833
|
-
throw r(`Failed to publish ${
|
|
833
|
+
throw r(`Failed to publish ${v} track:`, oe), oe;
|
|
834
834
|
} finally {
|
|
835
835
|
u.isPublishing = !1;
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
|
-
async function Fe(u,
|
|
838
|
+
async function Fe(u, m) {
|
|
839
839
|
if (!(!u.publication || !u.publication.track))
|
|
840
840
|
try {
|
|
841
|
-
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${
|
|
842
|
-
} catch (
|
|
843
|
-
r(`Error unpublishing ${
|
|
841
|
+
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${m} track unpublished`));
|
|
842
|
+
} catch (p) {
|
|
843
|
+
r(`Error unpublishing ${m} track:`, p);
|
|
844
844
|
} finally {
|
|
845
845
|
u.publication = null;
|
|
846
846
|
}
|
|
@@ -849,7 +849,7 @@ async function dn(e, n, i) {
|
|
|
849
849
|
return Be(
|
|
850
850
|
L,
|
|
851
851
|
u,
|
|
852
|
-
(
|
|
852
|
+
(m) => m.getAudioTracks(),
|
|
853
853
|
d.Source.Microphone,
|
|
854
854
|
() => l.localParticipant.audioTrackPublications,
|
|
855
855
|
Te
|
|
@@ -860,41 +860,41 @@ async function dn(e, n, i) {
|
|
|
860
860
|
}
|
|
861
861
|
async function mt(u) {
|
|
862
862
|
return Be(
|
|
863
|
-
|
|
863
|
+
$,
|
|
864
864
|
u,
|
|
865
|
-
(
|
|
865
|
+
(m) => m.getVideoTracks(),
|
|
866
866
|
d.Source.Camera,
|
|
867
867
|
() => l.localParticipant.videoTrackPublications,
|
|
868
868
|
ke
|
|
869
869
|
);
|
|
870
870
|
}
|
|
871
871
|
async function ke() {
|
|
872
|
-
return Fe(
|
|
872
|
+
return Fe($, "Camera");
|
|
873
873
|
}
|
|
874
874
|
function ft() {
|
|
875
|
-
|
|
875
|
+
z && (z.getTracks().forEach((u) => u.stop()), z = null);
|
|
876
876
|
}
|
|
877
|
-
async function Ee(u,
|
|
878
|
-
var
|
|
879
|
-
if (!
|
|
880
|
-
r("Room is not connected for sending messages"), (
|
|
881
|
-
sessionId:
|
|
877
|
+
async function Ee(u, m) {
|
|
878
|
+
var p, v;
|
|
879
|
+
if (!y || !l) {
|
|
880
|
+
r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(he), {
|
|
881
|
+
sessionId: f
|
|
882
882
|
});
|
|
883
883
|
return;
|
|
884
884
|
}
|
|
885
885
|
try {
|
|
886
|
-
await l.localParticipant.sendText(u, { topic:
|
|
886
|
+
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
887
887
|
} catch (_) {
|
|
888
|
-
r("Failed to send message:", _), (
|
|
888
|
+
r("Failed to send message:", _), (v = t.onError) == null || v.call(t, new Error(he), { sessionId: f });
|
|
889
889
|
}
|
|
890
890
|
}
|
|
891
891
|
async function gt(u) {
|
|
892
|
-
var
|
|
892
|
+
var m;
|
|
893
893
|
try {
|
|
894
|
-
const
|
|
895
|
-
return Ee("",
|
|
896
|
-
} catch (
|
|
897
|
-
r("Failed to send data channel message:",
|
|
894
|
+
const v = JSON.parse(u).topic;
|
|
895
|
+
return Ee("", v);
|
|
896
|
+
} catch (p) {
|
|
897
|
+
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(he), { sessionId: f });
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
900
|
function ht(u) {
|
|
@@ -905,43 +905,43 @@ async function dn(e, n, i) {
|
|
|
905
905
|
);
|
|
906
906
|
}
|
|
907
907
|
async function De(u) {
|
|
908
|
-
var
|
|
909
|
-
|
|
908
|
+
var m, p;
|
|
909
|
+
K && (clearTimeout(K), K = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, b.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()), ft(), y = !1, H = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, O.Idle), G = O.Idle;
|
|
910
910
|
}
|
|
911
911
|
return {
|
|
912
912
|
speak(u) {
|
|
913
|
-
const
|
|
913
|
+
const m = typeof u == "string" ? u : JSON.stringify(u);
|
|
914
914
|
return Ee(
|
|
915
|
-
|
|
915
|
+
m,
|
|
916
916
|
"did.speak"
|
|
917
917
|
/* Speak */
|
|
918
918
|
);
|
|
919
919
|
},
|
|
920
920
|
disconnect: () => De("user:disconnect"),
|
|
921
921
|
async reconnect() {
|
|
922
|
-
var u,
|
|
922
|
+
var u, m;
|
|
923
923
|
if ((l == null ? void 0 : l.state) === s.Connected) {
|
|
924
924
|
r("Room is already connected");
|
|
925
925
|
return;
|
|
926
926
|
}
|
|
927
|
-
if (!l || !
|
|
927
|
+
if (!l || !E || !S)
|
|
928
928
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
929
|
-
r("Reconnecting to LiveKit room, state:", l.state),
|
|
929
|
+
r("Reconnecting to LiveKit room, state:", l.state), H = !1, (u = t.onConnectionStateChange) == null || u.call(t, b.Connecting, "user:reconnect");
|
|
930
930
|
try {
|
|
931
|
-
if (await l.connect(
|
|
932
|
-
if (r("Waiting for agent to join..."), !await new Promise((
|
|
931
|
+
if (await l.connect(E, S), r("Room reconnected"), y = !0, l.remoteParticipants.size === 0) {
|
|
932
|
+
if (r("Waiting for agent to join..."), !await new Promise((v) => {
|
|
933
933
|
const _ = setTimeout(() => {
|
|
934
|
-
l == null || l.off(a.ParticipantConnected, P),
|
|
934
|
+
l == null || l.off(a.ParticipantConnected, P), v(!1);
|
|
935
935
|
}, 5e3), P = () => {
|
|
936
|
-
clearTimeout(_), l == null || l.off(a.ParticipantConnected, P),
|
|
936
|
+
clearTimeout(_), l == null || l.off(a.ParticipantConnected, P), v(!0);
|
|
937
937
|
};
|
|
938
938
|
l == null || l.on(a.ParticipantConnected, P);
|
|
939
939
|
}))
|
|
940
940
|
throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
|
|
941
941
|
r("Agent joined, reconnection successful");
|
|
942
942
|
}
|
|
943
|
-
} catch (
|
|
944
|
-
throw r("Failed to reconnect:",
|
|
943
|
+
} catch (p) {
|
|
944
|
+
throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, b.Fail, "user:reconnect-failed"), p;
|
|
945
945
|
}
|
|
946
946
|
},
|
|
947
947
|
sendDataChannelMessage: gt,
|
|
@@ -950,12 +950,11 @@ async function dn(e, n, i) {
|
|
|
950
950
|
unpublishMicrophoneStream: Te,
|
|
951
951
|
publishCameraStream: mt,
|
|
952
952
|
unpublishCameraStream: ke,
|
|
953
|
-
sessionId:
|
|
954
|
-
streamId:
|
|
955
|
-
streamType:
|
|
953
|
+
sessionId: f,
|
|
954
|
+
streamId: f,
|
|
955
|
+
streamType: M,
|
|
956
956
|
interruptAvailable: !0,
|
|
957
|
-
isInterruptible:
|
|
958
|
-
triggersAvailable: !1
|
|
957
|
+
isInterruptible: ae
|
|
959
958
|
};
|
|
960
959
|
}
|
|
961
960
|
const un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
@@ -969,14 +968,14 @@ function ln(e, n, i) {
|
|
|
969
968
|
throw new Error("Please connect to the agent first");
|
|
970
969
|
if (!e.interruptAvailable)
|
|
971
970
|
throw new Error("Interrupt is not enabled for this stream");
|
|
972
|
-
if (n !==
|
|
971
|
+
if (n !== ie.Fluent)
|
|
973
972
|
throw new Error("Interrupt only available for Fluent streams");
|
|
974
973
|
if (!i)
|
|
975
974
|
throw new Error("No active video to interrupt");
|
|
976
975
|
}
|
|
977
976
|
async function mn(e, n) {
|
|
978
977
|
const i = {
|
|
979
|
-
type:
|
|
978
|
+
type: D.StreamInterrupt,
|
|
980
979
|
videoId: n,
|
|
981
980
|
timestamp: Date.now()
|
|
982
981
|
};
|
|
@@ -990,9 +989,9 @@ async function fn(e) {
|
|
|
990
989
|
}
|
|
991
990
|
function gn(e) {
|
|
992
991
|
return new Promise((n, i) => {
|
|
993
|
-
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError:
|
|
992
|
+
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: h = null } = r || {}, g = new WebSocket(`${o}?authorization=${encodeURIComponent(rt(a, s))}`);
|
|
994
993
|
g.onmessage = d, g.onclose = c, g.onerror = (l) => {
|
|
995
|
-
console.error(l),
|
|
994
|
+
console.error(l), h == null || h("Websocket failed to connect", l), i(l);
|
|
996
995
|
}, g.onopen = (l) => {
|
|
997
996
|
t == null || t(l), n(g);
|
|
998
997
|
};
|
|
@@ -1056,16 +1055,16 @@ function yn(e, n, i) {
|
|
|
1056
1055
|
n.messages.push(o), i == null || i([...n.messages], "user");
|
|
1057
1056
|
}
|
|
1058
1057
|
function vn(e, n, i, r, o) {
|
|
1059
|
-
if (e ===
|
|
1058
|
+
if (e === X.Transcribe && n.content) {
|
|
1060
1059
|
yn(n, r, o);
|
|
1061
1060
|
return;
|
|
1062
1061
|
}
|
|
1063
|
-
if (!(e ===
|
|
1062
|
+
if (!(e === X.Partial || e === X.Answer))
|
|
1064
1063
|
return;
|
|
1065
1064
|
const a = r.messages[r.messages.length - 1];
|
|
1066
1065
|
let s;
|
|
1067
1066
|
if (a != null && a.transcribed && a.role === "user")
|
|
1068
|
-
e ===
|
|
1067
|
+
e === X.Answer && n.content, s = {
|
|
1069
1068
|
id: n.id || `assistant-${Date.now()}`,
|
|
1070
1069
|
role: n.role || "assistant",
|
|
1071
1070
|
content: n.content || "",
|
|
@@ -1076,43 +1075,43 @@ function vn(e, n, i, r, o) {
|
|
|
1076
1075
|
else
|
|
1077
1076
|
return;
|
|
1078
1077
|
const { content: d, sequence: t } = n;
|
|
1079
|
-
e ===
|
|
1078
|
+
e === X.Partial ? i[t] = d : i.answer = d;
|
|
1080
1079
|
const c = wn(i);
|
|
1081
|
-
(s.content !== c || e ===
|
|
1080
|
+
(s.content !== c || e === X.Answer) && (s.content = c, o == null || o([...r.messages], e));
|
|
1082
1081
|
}
|
|
1083
1082
|
function Cn(e, n, i, r, o) {
|
|
1084
1083
|
let a = {};
|
|
1085
1084
|
const s = () => a = {};
|
|
1086
1085
|
let d = "answer";
|
|
1087
|
-
const t = (c,
|
|
1086
|
+
const t = (c, h) => {
|
|
1088
1087
|
var g, l;
|
|
1089
|
-
|
|
1088
|
+
h === "user" && s(), d = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, h);
|
|
1090
1089
|
};
|
|
1091
1090
|
return {
|
|
1092
1091
|
clearQueue: s,
|
|
1093
|
-
onMessage: (c,
|
|
1092
|
+
onMessage: (c, h) => {
|
|
1094
1093
|
var g, l;
|
|
1095
|
-
if ("content" in
|
|
1096
|
-
const
|
|
1097
|
-
vn(
|
|
1098
|
-
content:
|
|
1094
|
+
if ("content" in h) {
|
|
1095
|
+
const y = c === D.ChatAnswer ? X.Answer : c === D.ChatAudioTranscribed ? X.Transcribe : c;
|
|
1096
|
+
vn(y, h, a, n, t), y === X.Answer && e.track("agent-message-received", {
|
|
1097
|
+
content: h.content,
|
|
1099
1098
|
messages: n.messages.length,
|
|
1100
1099
|
mode: n.chatMode
|
|
1101
1100
|
});
|
|
1102
1101
|
} else {
|
|
1103
|
-
const
|
|
1104
|
-
if (c = c, c ===
|
|
1105
|
-
const
|
|
1106
|
-
if ((
|
|
1107
|
-
const
|
|
1108
|
-
n.messages[n.messages.length - 1] =
|
|
1102
|
+
const y = D, M = [y.StreamVideoDone, y.StreamVideoError, y.StreamVideoRejected], z = [y.StreamFailed, y.StreamVideoError, y.StreamVideoRejected], L = Ot(h, r, { mode: n.chatMode });
|
|
1103
|
+
if (c = c, c === y.StreamVideoCreated && (e.linkTrack("agent-video", L, y.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1104
|
+
const $ = n.messages[n.messages.length - 1];
|
|
1105
|
+
if (($ == null ? void 0 : $.role) === "assistant") {
|
|
1106
|
+
const A = { ...$, sentiment: h.sentiment };
|
|
1107
|
+
n.messages[n.messages.length - 1] = A, t == null || t([...n.messages], d);
|
|
1109
1108
|
}
|
|
1110
1109
|
}
|
|
1111
|
-
if (
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1110
|
+
if (M.includes(c)) {
|
|
1111
|
+
const $ = c.split("/")[1];
|
|
1112
|
+
z.includes(c) ? e.track("agent-video", { ...L, event: $ }) : e.linkTrack("agent-video", { ...L, event: $ }, c, ["done"]);
|
|
1114
1113
|
}
|
|
1115
|
-
|
|
1114
|
+
z.includes(c) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${c}`), { data: h })), h.event === y.StreamDone && o();
|
|
1116
1115
|
}
|
|
1117
1116
|
}
|
|
1118
1117
|
};
|
|
@@ -1201,7 +1200,7 @@ function En({
|
|
|
1201
1200
|
report: o,
|
|
1202
1201
|
log: a
|
|
1203
1202
|
}) {
|
|
1204
|
-
e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(
|
|
1203
|
+
e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(O.Talking) : n === T.Stop && (r == null || r(O.Idle));
|
|
1205
1204
|
}
|
|
1206
1205
|
function Xe({
|
|
1207
1206
|
statsSignal: e,
|
|
@@ -1212,7 +1211,7 @@ function Xe({
|
|
|
1212
1211
|
report: a,
|
|
1213
1212
|
log: s
|
|
1214
1213
|
}) {
|
|
1215
|
-
o ===
|
|
1214
|
+
o === ie.Legacy ? kn({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === ie.Fluent && En({
|
|
1216
1215
|
statsSignal: e,
|
|
1217
1216
|
dataChannelSignal: n,
|
|
1218
1217
|
onVideoStateChange: i,
|
|
@@ -1221,175 +1220,173 @@ function Xe({
|
|
|
1221
1220
|
log: s
|
|
1222
1221
|
});
|
|
1223
1222
|
}
|
|
1224
|
-
async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a =
|
|
1225
|
-
var
|
|
1223
|
+
async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe, analytics: s }, d) {
|
|
1224
|
+
var ee;
|
|
1226
1225
|
const t = ot(i, "WebRTCStreamingManager"), c = Tn(t);
|
|
1227
|
-
let
|
|
1228
|
-
const { startConnection:
|
|
1226
|
+
let h = !1, g = !1, l = T.Stop, y = T.Stop;
|
|
1227
|
+
const { startConnection: M, sendStreamRequest: z, close: L, createStream: $, addIceCandidate: A } = Sn(
|
|
1229
1228
|
o,
|
|
1230
1229
|
a,
|
|
1231
1230
|
e,
|
|
1232
1231
|
r.onError
|
|
1233
1232
|
), {
|
|
1234
1233
|
id: k,
|
|
1235
|
-
offer:
|
|
1236
|
-
ice_servers:
|
|
1237
|
-
session_id:
|
|
1238
|
-
fluent:
|
|
1239
|
-
interrupt_enabled:
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
if (!F)
|
|
1234
|
+
offer: W,
|
|
1235
|
+
ice_servers: H,
|
|
1236
|
+
session_id: K,
|
|
1237
|
+
fluent: G,
|
|
1238
|
+
interrupt_enabled: ae
|
|
1239
|
+
} = await $(n, d);
|
|
1240
|
+
(ee = r.onStreamCreated) == null || ee.call(r, { stream_id: k, session_id: K, agent_id: e });
|
|
1241
|
+
const B = new Rn({ iceServers: H }), f = B.createDataChannel("JanusDataChannel");
|
|
1242
|
+
if (!K)
|
|
1245
1243
|
throw new Error("Could not create session_id");
|
|
1246
|
-
const
|
|
1244
|
+
const S = G ? ie.Fluent : ie.Legacy;
|
|
1247
1245
|
s.enrich({
|
|
1248
|
-
"stream-type":
|
|
1246
|
+
"stream-type": S
|
|
1249
1247
|
});
|
|
1250
|
-
const
|
|
1251
|
-
var
|
|
1252
|
-
|
|
1253
|
-
},
|
|
1254
|
-
() =>
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
(
|
|
1258
|
-
statsSignal:
|
|
1259
|
-
dataChannelSignal:
|
|
1248
|
+
const E = n.stream_warmup && !G, J = () => h, F = () => {
|
|
1249
|
+
var C;
|
|
1250
|
+
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (C = r.onConnectionStateChange) == null || C.call(r, b.Connected));
|
|
1251
|
+
}, I = ct(
|
|
1252
|
+
() => B.getStats(),
|
|
1253
|
+
J,
|
|
1254
|
+
F,
|
|
1255
|
+
(C, w) => Xe({
|
|
1256
|
+
statsSignal: y = C,
|
|
1257
|
+
dataChannelSignal: S === ie.Legacy ? l : void 0,
|
|
1260
1258
|
onVideoStateChange: r.onVideoStateChange,
|
|
1261
1259
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1262
|
-
report:
|
|
1263
|
-
streamType:
|
|
1260
|
+
report: w,
|
|
1261
|
+
streamType: S,
|
|
1264
1262
|
log: t
|
|
1265
1263
|
}),
|
|
1266
|
-
(
|
|
1267
|
-
var
|
|
1268
|
-
return (
|
|
1264
|
+
(C) => {
|
|
1265
|
+
var w;
|
|
1266
|
+
return (w = r.onConnectivityStateChange) == null ? void 0 : w.call(r, C);
|
|
1269
1267
|
}
|
|
1270
1268
|
);
|
|
1271
|
-
|
|
1272
|
-
var
|
|
1273
|
-
t("peerConnection.onicecandidate",
|
|
1269
|
+
I.start(), B.onicecandidate = (C) => {
|
|
1270
|
+
var w;
|
|
1271
|
+
t("peerConnection.onicecandidate", C);
|
|
1274
1272
|
try {
|
|
1275
|
-
|
|
1273
|
+
C.candidate && C.candidate.sdpMid && C.candidate.sdpMLineIndex !== null ? A(
|
|
1276
1274
|
k,
|
|
1277
1275
|
{
|
|
1278
|
-
candidate:
|
|
1279
|
-
sdpMid:
|
|
1280
|
-
sdpMLineIndex:
|
|
1276
|
+
candidate: C.candidate.candidate,
|
|
1277
|
+
sdpMid: C.candidate.sdpMid,
|
|
1278
|
+
sdpMLineIndex: C.candidate.sdpMLineIndex
|
|
1281
1279
|
},
|
|
1282
|
-
|
|
1280
|
+
K,
|
|
1283
1281
|
d
|
|
1284
|
-
) :
|
|
1285
|
-
} catch (
|
|
1286
|
-
(
|
|
1282
|
+
) : A(k, { candidate: null }, K, d);
|
|
1283
|
+
} catch (R) {
|
|
1284
|
+
(w = r.onError) == null || w.call(r, R, { streamId: k });
|
|
1287
1285
|
}
|
|
1288
|
-
},
|
|
1289
|
-
g = !0, (!
|
|
1286
|
+
}, f.onopen = () => {
|
|
1287
|
+
g = !0, (!E || h) && F();
|
|
1290
1288
|
};
|
|
1291
|
-
const
|
|
1292
|
-
var
|
|
1293
|
-
(
|
|
1289
|
+
const q = (C) => {
|
|
1290
|
+
var w;
|
|
1291
|
+
(w = r.onVideoIdChange) == null || w.call(r, C);
|
|
1294
1292
|
};
|
|
1295
|
-
function
|
|
1296
|
-
if (
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1293
|
+
function Y(C, w) {
|
|
1294
|
+
if (C === D.StreamStarted && typeof w == "object" && "metadata" in w) {
|
|
1295
|
+
const R = w.metadata;
|
|
1296
|
+
q(R.videoId);
|
|
1299
1297
|
}
|
|
1300
|
-
|
|
1301
|
-
statsSignal:
|
|
1298
|
+
C === D.StreamDone && q(null), l = C === D.StreamStarted ? T.Start : T.Stop, Xe({
|
|
1299
|
+
statsSignal: S === ie.Legacy ? y : void 0,
|
|
1302
1300
|
dataChannelSignal: l,
|
|
1303
1301
|
onVideoStateChange: r.onVideoStateChange,
|
|
1304
1302
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1305
|
-
streamType:
|
|
1303
|
+
streamType: S,
|
|
1306
1304
|
log: t
|
|
1307
1305
|
});
|
|
1308
1306
|
}
|
|
1309
|
-
function
|
|
1310
|
-
var
|
|
1311
|
-
const
|
|
1312
|
-
|
|
1307
|
+
function Z(C, w) {
|
|
1308
|
+
var j;
|
|
1309
|
+
const R = typeof w == "string" ? w : w == null ? void 0 : w.metadata;
|
|
1310
|
+
R && s.enrich({ streamMetadata: R }), (j = r.onStreamReady) == null || j.call(r);
|
|
1313
1311
|
}
|
|
1314
|
-
const
|
|
1315
|
-
[
|
|
1316
|
-
[
|
|
1317
|
-
[
|
|
1312
|
+
const x = {
|
|
1313
|
+
[D.StreamStarted]: Y,
|
|
1314
|
+
[D.StreamDone]: Y,
|
|
1315
|
+
[D.StreamReady]: Z
|
|
1318
1316
|
};
|
|
1319
|
-
|
|
1320
|
-
var
|
|
1321
|
-
const { subject:
|
|
1322
|
-
(
|
|
1323
|
-
},
|
|
1324
|
-
var
|
|
1325
|
-
t("peerConnection.oniceconnectionstatechange => " +
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1328
|
-
},
|
|
1329
|
-
var
|
|
1330
|
-
t("peerConnection.ontrack",
|
|
1331
|
-
}, await
|
|
1332
|
-
const
|
|
1333
|
-
return t("create answer OK"), await
|
|
1317
|
+
f.onmessage = (C) => {
|
|
1318
|
+
var j;
|
|
1319
|
+
const { subject: w, data: R } = c(C.data);
|
|
1320
|
+
(j = x[w]) == null || j.call(x, w, R);
|
|
1321
|
+
}, B.oniceconnectionstatechange = () => {
|
|
1322
|
+
var w;
|
|
1323
|
+
t("peerConnection.oniceconnectionstatechange => " + B.iceConnectionState);
|
|
1324
|
+
const C = Qe(B.iceConnectionState);
|
|
1325
|
+
C !== b.Connected && ((w = r.onConnectionStateChange) == null || w.call(r, C));
|
|
1326
|
+
}, B.ontrack = (C) => {
|
|
1327
|
+
var w;
|
|
1328
|
+
t("peerConnection.ontrack", C), t("CALLBACK: onSrcObjectReady"), (w = r.onSrcObjectReady) == null || w.call(r, C.streams[0]);
|
|
1329
|
+
}, await B.setRemoteDescription(W), t("set remote description OK");
|
|
1330
|
+
const V = await B.createAnswer();
|
|
1331
|
+
return t("create answer OK"), await B.setLocalDescription(V), t("set local description OK"), await M(k, V, K, d), t("start connection OK"), {
|
|
1334
1332
|
/**
|
|
1335
1333
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1336
1334
|
* @param payload
|
|
1337
1335
|
*/
|
|
1338
|
-
speak(
|
|
1339
|
-
return
|
|
1336
|
+
speak(C) {
|
|
1337
|
+
return z(k, K, C);
|
|
1340
1338
|
},
|
|
1341
1339
|
/**
|
|
1342
1340
|
* Method to close RTC connection
|
|
1343
1341
|
*/
|
|
1344
1342
|
async disconnect() {
|
|
1345
|
-
var
|
|
1343
|
+
var C;
|
|
1346
1344
|
if (k) {
|
|
1347
|
-
const
|
|
1348
|
-
if (
|
|
1349
|
-
if (
|
|
1350
|
-
|
|
1345
|
+
const w = Qe(B.iceConnectionState);
|
|
1346
|
+
if (B) {
|
|
1347
|
+
if (w === b.New) {
|
|
1348
|
+
I.stop();
|
|
1351
1349
|
return;
|
|
1352
1350
|
}
|
|
1353
|
-
|
|
1351
|
+
B.close(), B.oniceconnectionstatechange = null, B.onnegotiationneeded = null, B.onicecandidate = null, B.ontrack = null;
|
|
1354
1352
|
}
|
|
1355
1353
|
try {
|
|
1356
|
-
|
|
1354
|
+
w === b.Connected && await L(k, K).catch((R) => {
|
|
1357
1355
|
});
|
|
1358
|
-
} catch (
|
|
1359
|
-
t("Error on close stream connection",
|
|
1356
|
+
} catch (R) {
|
|
1357
|
+
t("Error on close stream connection", R);
|
|
1360
1358
|
}
|
|
1361
|
-
(
|
|
1359
|
+
(C = r.onAgentActivityStateChange) == null || C.call(r, O.Idle), I.stop();
|
|
1362
1360
|
}
|
|
1363
1361
|
},
|
|
1364
1362
|
/**
|
|
1365
1363
|
* Method to send data channel messages to the server
|
|
1366
1364
|
*/
|
|
1367
|
-
sendDataChannelMessage(
|
|
1368
|
-
var
|
|
1369
|
-
if (!
|
|
1370
|
-
t("Data channel is not ready for sending messages"), (
|
|
1365
|
+
sendDataChannelMessage(C) {
|
|
1366
|
+
var w, R;
|
|
1367
|
+
if (!h || f.readyState !== "open") {
|
|
1368
|
+
t("Data channel is not ready for sending messages"), (w = r.onError) == null || w.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1371
1369
|
streamId: k
|
|
1372
1370
|
});
|
|
1373
1371
|
return;
|
|
1374
1372
|
}
|
|
1375
1373
|
try {
|
|
1376
|
-
|
|
1377
|
-
} catch (
|
|
1378
|
-
t("Error sending data channel message",
|
|
1374
|
+
f.send(C);
|
|
1375
|
+
} catch (j) {
|
|
1376
|
+
t("Error sending data channel message", j), (R = r.onError) == null || R.call(r, j, { streamId: k });
|
|
1379
1377
|
}
|
|
1380
1378
|
},
|
|
1381
1379
|
/**
|
|
1382
1380
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1383
1381
|
*/
|
|
1384
|
-
sessionId:
|
|
1382
|
+
sessionId: K,
|
|
1385
1383
|
/**
|
|
1386
1384
|
* Id of current RTC stream
|
|
1387
1385
|
*/
|
|
1388
1386
|
streamId: k,
|
|
1389
|
-
streamType:
|
|
1390
|
-
interruptAvailable:
|
|
1391
|
-
isInterruptible: !0
|
|
1392
|
-
triggersAvailable: se ?? !1
|
|
1387
|
+
streamType: S,
|
|
1388
|
+
interruptAvailable: ae ?? !1,
|
|
1389
|
+
isInterruptible: !0
|
|
1393
1390
|
};
|
|
1394
1391
|
}
|
|
1395
1392
|
var be = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(be || {});
|
|
@@ -1442,7 +1439,7 @@ function Pn(e, n, i) {
|
|
|
1442
1439
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
1443
1440
|
}
|
|
1444
1441
|
function Ln(e, n, i, r, o) {
|
|
1445
|
-
o ===
|
|
1442
|
+
o === ie.Fluent ? jn(e, n, i, r, o) : $n(e, n, i, r, o);
|
|
1446
1443
|
}
|
|
1447
1444
|
function jn(e, n, i, r, o) {
|
|
1448
1445
|
e === T.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === T.Stop && r.track("stream-session", {
|
|
@@ -1455,7 +1452,7 @@ function jn(e, n, i, r, o) {
|
|
|
1455
1452
|
}
|
|
1456
1453
|
function Ye(e, n, i, r, o) {
|
|
1457
1454
|
e === T.Start ? i.linkTrack("agent-video", { event: "start", ...o, "stream-type": r }, "start", [
|
|
1458
|
-
|
|
1455
|
+
D.StreamVideoCreated
|
|
1459
1456
|
]) : e === T.Stop && i.linkTrack(
|
|
1460
1457
|
"agent-video",
|
|
1461
1458
|
{
|
|
@@ -1465,15 +1462,15 @@ function Ye(e, n, i, r, o) {
|
|
|
1465
1462
|
"stream-type": r
|
|
1466
1463
|
},
|
|
1467
1464
|
"done",
|
|
1468
|
-
[
|
|
1465
|
+
[D.StreamVideoDone]
|
|
1469
1466
|
);
|
|
1470
1467
|
}
|
|
1471
1468
|
function $n(e, n, i, r, o) {
|
|
1472
1469
|
e === T.Start ? r.linkTrack(
|
|
1473
1470
|
"agent-video",
|
|
1474
|
-
{ event: "start", latency:
|
|
1471
|
+
{ event: "start", latency: re.get(!0), "stream-type": o },
|
|
1475
1472
|
"start",
|
|
1476
|
-
[
|
|
1473
|
+
[D.StreamVideoCreated]
|
|
1477
1474
|
) : e === T.Stop && r.linkTrack(
|
|
1478
1475
|
"agent-video",
|
|
1479
1476
|
{
|
|
@@ -1484,11 +1481,11 @@ function $n(e, n, i, r, o) {
|
|
|
1484
1481
|
...i
|
|
1485
1482
|
},
|
|
1486
1483
|
"done",
|
|
1487
|
-
[
|
|
1484
|
+
[D.StreamVideoDone]
|
|
1488
1485
|
);
|
|
1489
1486
|
}
|
|
1490
1487
|
function Ge(e, n, i, r) {
|
|
1491
|
-
return
|
|
1488
|
+
return re.reset(), We.update(), new Promise(async (o, a) => {
|
|
1492
1489
|
try {
|
|
1493
1490
|
let s, d = !1;
|
|
1494
1491
|
const t = bn(e, n);
|
|
@@ -1496,7 +1493,7 @@ function Ge(e, n, i, r) {
|
|
|
1496
1493
|
"stream-version": t.version.toString()
|
|
1497
1494
|
});
|
|
1498
1495
|
let c = null;
|
|
1499
|
-
const
|
|
1496
|
+
const h = e.presenter.type === "expressive";
|
|
1500
1497
|
s = await In(
|
|
1501
1498
|
e,
|
|
1502
1499
|
t,
|
|
@@ -1506,12 +1503,12 @@ function Ge(e, n, i, r) {
|
|
|
1506
1503
|
callbacks: {
|
|
1507
1504
|
...n.callbacks,
|
|
1508
1505
|
onConnectionStateChange: (g, l) => {
|
|
1509
|
-
var
|
|
1510
|
-
(
|
|
1506
|
+
var y, M;
|
|
1507
|
+
(M = (y = n.callbacks).onConnectionStateChange) == null || M.call(y, g), Pn(g, l, i), g === b.Connected && (s ? o(s) : d = !0);
|
|
1511
1508
|
},
|
|
1512
1509
|
onVideoStateChange: (g, l) => {
|
|
1513
|
-
var
|
|
1514
|
-
(
|
|
1510
|
+
var y, M;
|
|
1511
|
+
(M = (y = n.callbacks).onVideoStateChange) == null || M.call(y, g), Ln(
|
|
1515
1512
|
g,
|
|
1516
1513
|
e,
|
|
1517
1514
|
l,
|
|
@@ -1520,16 +1517,16 @@ function Ge(e, n, i, r) {
|
|
|
1520
1517
|
);
|
|
1521
1518
|
},
|
|
1522
1519
|
onAgentActivityStateChange: (g) => {
|
|
1523
|
-
var l,
|
|
1524
|
-
(
|
|
1520
|
+
var l, y;
|
|
1521
|
+
(y = (l = n.callbacks).onAgentActivityStateChange) == null || y.call(l, g), g === O.Talking ? (Ae.update(), c = (M) => {
|
|
1525
1522
|
Ye(
|
|
1526
1523
|
T.Start,
|
|
1527
1524
|
e,
|
|
1528
1525
|
i,
|
|
1529
1526
|
s.streamType,
|
|
1530
|
-
|
|
1527
|
+
M
|
|
1531
1528
|
), c = null;
|
|
1532
|
-
},
|
|
1529
|
+
}, h || c({ latency: re.get(!0) })) : (Ae.reset(), c = null, Ye(
|
|
1533
1530
|
T.Stop,
|
|
1534
1531
|
e,
|
|
1535
1532
|
i,
|
|
@@ -1553,49 +1550,49 @@ function Ge(e, n, i, r) {
|
|
|
1553
1550
|
});
|
|
1554
1551
|
}
|
|
1555
1552
|
async function xn(e, n, i, r, o) {
|
|
1556
|
-
var
|
|
1553
|
+
var h, g, l, y;
|
|
1557
1554
|
const a = async () => {
|
|
1558
1555
|
if (Le(e.presenter.type)) {
|
|
1559
|
-
const
|
|
1556
|
+
const M = await Ge(e, n, r), z = `${Mn}_${M.sessionId}`, L = (/* @__PURE__ */ new Date()).toISOString();
|
|
1560
1557
|
return { chatResult: {
|
|
1561
|
-
chatMode:
|
|
1558
|
+
chatMode: U.Functional,
|
|
1562
1559
|
chat: {
|
|
1563
|
-
id:
|
|
1560
|
+
id: z,
|
|
1564
1561
|
agent_id: e.id,
|
|
1565
1562
|
owner_id: e.owner_id ?? "",
|
|
1566
1563
|
created: L,
|
|
1567
1564
|
modified: L,
|
|
1568
1565
|
agent_id__created_at: L,
|
|
1569
1566
|
agent_id__modified_at: L,
|
|
1570
|
-
chat_mode:
|
|
1567
|
+
chat_mode: U.Functional,
|
|
1571
1568
|
messages: []
|
|
1572
1569
|
}
|
|
1573
|
-
}, streamingManager:
|
|
1570
|
+
}, streamingManager: M };
|
|
1574
1571
|
} else {
|
|
1575
|
-
const
|
|
1572
|
+
const M = new AbortController(), z = M.signal;
|
|
1576
1573
|
let L;
|
|
1577
1574
|
try {
|
|
1578
|
-
const
|
|
1575
|
+
const $ = at(
|
|
1579
1576
|
e,
|
|
1580
1577
|
i,
|
|
1581
1578
|
r,
|
|
1582
1579
|
n.mode,
|
|
1583
1580
|
n.persistentChat,
|
|
1584
1581
|
o
|
|
1585
|
-
),
|
|
1586
|
-
return { chatResult: k, streamingManager:
|
|
1587
|
-
} catch (
|
|
1588
|
-
throw
|
|
1589
|
-
}),
|
|
1582
|
+
), A = Ge(e, n, r, z).then((H) => (L = H, H)), [k, W] = await Promise.all([$, A]);
|
|
1583
|
+
return { chatResult: k, streamingManager: W };
|
|
1584
|
+
} catch ($) {
|
|
1585
|
+
throw M.abort(), L && await L.disconnect().catch(() => {
|
|
1586
|
+
}), $;
|
|
1590
1587
|
}
|
|
1591
1588
|
}
|
|
1592
1589
|
}, { chatResult: s, streamingManager: d } = await a(), { chat: t, chatMode: c } = s;
|
|
1593
|
-
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (
|
|
1590
|
+
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (h = n.callbacks).onModeChange) == null || g.call(h, c), c !== U.Functional) ? ((y = (l = n.callbacks).onError) == null || y.call(l, new vt(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
|
|
1594
1591
|
}
|
|
1595
1592
|
async function zn(e, n) {
|
|
1596
|
-
var
|
|
1593
|
+
var K, G, ae, B;
|
|
1597
1594
|
let i = !0, r = null;
|
|
1598
|
-
const o = n.mixpanelKey || Lt, a = n.wsURL || Pt, s = n.baseURL ||
|
|
1595
|
+
const o = n.mixpanelKey || Lt, a = n.wsURL || Pt, s = n.baseURL || pe, d = n.mode || U.Functional, t = {
|
|
1599
1596
|
messages: [],
|
|
1600
1597
|
chatMode: d
|
|
1601
1598
|
}, c = Ht({
|
|
@@ -1604,43 +1601,43 @@ async function zn(e, n) {
|
|
|
1604
1601
|
isEnabled: n.enableAnalitics,
|
|
1605
1602
|
externalId: n.externalId,
|
|
1606
1603
|
mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
|
|
1607
|
-
}),
|
|
1604
|
+
}), h = Date.now();
|
|
1608
1605
|
Oe(() => {
|
|
1609
|
-
c.track("agent-sdk", { event: "init" },
|
|
1606
|
+
c.track("agent-sdk", { event: "init" }, h);
|
|
1610
1607
|
});
|
|
1611
1608
|
const g = Nt(n.auth, s, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1612
|
-
n.debug = n.debug || ((
|
|
1613
|
-
const
|
|
1609
|
+
n.debug = n.debug || ((K = l == null ? void 0 : l.advanced_settings) == null ? void 0 : K.ui_debug_mode);
|
|
1610
|
+
const y = Le(l.presenter.type);
|
|
1614
1611
|
c.enrich(Ut(l));
|
|
1615
|
-
const { onMessage:
|
|
1616
|
-
var
|
|
1617
|
-
(
|
|
1612
|
+
const { onMessage: M, clearQueue: z } = Cn(c, t, n, l, () => {
|
|
1613
|
+
var f, S, E;
|
|
1614
|
+
(f = t.socketManager) == null || f.disconnect(), (E = (S = n.callbacks).onConnectionStateChange) == null || E.call(S, b.Disconnected);
|
|
1618
1615
|
});
|
|
1619
|
-
t.messages = Qt(n.initialMessages), (
|
|
1620
|
-
const L = (
|
|
1621
|
-
r =
|
|
1622
|
-
},
|
|
1623
|
-
var
|
|
1624
|
-
if (!((
|
|
1616
|
+
t.messages = Qt(n.initialMessages), (ae = (G = n.callbacks).onNewMessage) == null || ae.call(G, [...t.messages], "answer");
|
|
1617
|
+
const L = (f) => {
|
|
1618
|
+
r = f;
|
|
1619
|
+
}, $ = ({ type: f }) => {
|
|
1620
|
+
var E, J, F, I;
|
|
1621
|
+
if (!((E = t.streamingManager) != null && E.isInterruptible)) return;
|
|
1625
1622
|
const S = t.messages[t.messages.length - 1];
|
|
1626
1623
|
c.track("agent-video-interrupt", {
|
|
1627
|
-
type:
|
|
1624
|
+
type: f || "click",
|
|
1628
1625
|
video_duration_to_interrupt: Ae.get(!0),
|
|
1629
|
-
message_duration_to_interrupt:
|
|
1630
|
-
}), S.interrupted = !0, (
|
|
1631
|
-
},
|
|
1626
|
+
message_duration_to_interrupt: re.get(!0)
|
|
1627
|
+
}), S.interrupted = !0, (F = (J = n.callbacks).onNewMessage) == null || F.call(J, [...t.messages], "answer"), y ? fn(t.streamingManager) : (ln(t.streamingManager, (I = t.streamingManager) == null ? void 0 : I.streamType, r), mn(t.streamingManager, r));
|
|
1628
|
+
}, A = Date.now();
|
|
1632
1629
|
Oe(() => {
|
|
1633
|
-
c.track("agent-sdk", { event: "loaded", ...Vt(l) },
|
|
1630
|
+
c.track("agent-sdk", { event: "loaded", ...Vt(l) }, A);
|
|
1634
1631
|
});
|
|
1635
|
-
async function k(
|
|
1636
|
-
var
|
|
1637
|
-
(
|
|
1638
|
-
const S = d ===
|
|
1632
|
+
async function k(f) {
|
|
1633
|
+
var q, Y, Z, x, V, ee, C;
|
|
1634
|
+
(Y = (q = n.callbacks).onConnectionStateChange) == null || Y.call(q, b.Connecting), re.reset(), f && !i && (delete t.chat, (x = (Z = n.callbacks).onNewMessage) == null || x.call(Z, [...t.messages], "answer"));
|
|
1635
|
+
const S = d === U.DirectPlayback || y ? Promise.resolve(void 0) : pn(
|
|
1639
1636
|
n.auth,
|
|
1640
1637
|
a,
|
|
1641
|
-
{ onMessage:
|
|
1638
|
+
{ onMessage: M, onError: n.callbacks.onError },
|
|
1642
1639
|
n.externalId
|
|
1643
|
-
),
|
|
1640
|
+
), E = Ie(
|
|
1644
1641
|
() => xn(
|
|
1645
1642
|
l,
|
|
1646
1643
|
{
|
|
@@ -1649,8 +1646,8 @@ async function zn(e, n) {
|
|
|
1649
1646
|
callbacks: {
|
|
1650
1647
|
...n.callbacks,
|
|
1651
1648
|
onVideoIdChange: L,
|
|
1652
|
-
onMessage:
|
|
1653
|
-
onInterruptDetected:
|
|
1649
|
+
onMessage: M,
|
|
1650
|
+
onInterruptDetected: $
|
|
1654
1651
|
}
|
|
1655
1652
|
},
|
|
1656
1653
|
g,
|
|
@@ -1661,44 +1658,40 @@ async function zn(e, n) {
|
|
|
1661
1658
|
limit: 3,
|
|
1662
1659
|
timeout: _t,
|
|
1663
1660
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1664
|
-
shouldRetryFn: (
|
|
1661
|
+
shouldRetryFn: (w) => (w == null ? void 0 : w.message) !== "Could not connect" && w.status !== 429 && (w == null ? void 0 : w.message) !== "InsufficientCreditsError",
|
|
1665
1662
|
delayMs: 1e3
|
|
1666
1663
|
}
|
|
1667
|
-
).catch((
|
|
1668
|
-
var
|
|
1669
|
-
throw
|
|
1670
|
-
}), [
|
|
1671
|
-
|
|
1672
|
-
chatId:
|
|
1673
|
-
streamId:
|
|
1664
|
+
).catch((w) => {
|
|
1665
|
+
var R, j;
|
|
1666
|
+
throw H(U.Maintenance), (j = (R = n.callbacks).onConnectionStateChange) == null || j.call(R, b.Fail), w;
|
|
1667
|
+
}), [J, { streamingManager: F, chat: I }] = await Promise.all([S, E]);
|
|
1668
|
+
I && I.id !== ((V = t.chat) == null ? void 0 : V.id) && ((C = (ee = n.callbacks).onNewChat) == null || C.call(ee, I.id)), t.streamingManager = F, t.socketManager = J, t.chat = I, i = !1, c.enrich({
|
|
1669
|
+
chatId: I == null ? void 0 : I.id,
|
|
1670
|
+
streamId: F == null ? void 0 : F.streamId,
|
|
1674
1671
|
mode: t.chatMode
|
|
1675
|
-
}),
|
|
1672
|
+
}), H((I == null ? void 0 : I.chat_mode) ?? d);
|
|
1676
1673
|
}
|
|
1677
|
-
async function
|
|
1678
|
-
var
|
|
1679
|
-
(
|
|
1674
|
+
async function W() {
|
|
1675
|
+
var f, S, E, J;
|
|
1676
|
+
(f = t.socketManager) == null || f.disconnect(), await ((S = t.streamingManager) == null ? void 0 : S.disconnect()), delete t.streamingManager, delete t.socketManager, (J = (E = n.callbacks).onConnectionStateChange) == null || J.call(E, b.Disconnected);
|
|
1680
1677
|
}
|
|
1681
|
-
async function
|
|
1682
|
-
var S,
|
|
1683
|
-
|
|
1678
|
+
async function H(f) {
|
|
1679
|
+
var S, E;
|
|
1680
|
+
f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== U.Functional && await W(), (E = (S = n.callbacks).onModeChange) == null || E.call(S, f));
|
|
1684
1681
|
}
|
|
1685
1682
|
return {
|
|
1686
1683
|
agent: l,
|
|
1687
1684
|
getStreamType: () => {
|
|
1688
|
-
var
|
|
1689
|
-
return (
|
|
1685
|
+
var f;
|
|
1686
|
+
return (f = t.streamingManager) == null ? void 0 : f.streamType;
|
|
1690
1687
|
},
|
|
1691
1688
|
getIsInterruptAvailable: () => {
|
|
1692
|
-
var
|
|
1693
|
-
return ((
|
|
1694
|
-
},
|
|
1695
|
-
getIsTriggersAvailable: () => {
|
|
1696
|
-
var m;
|
|
1697
|
-
return ((m = t.streamingManager) == null ? void 0 : m.triggersAvailable) ?? !1;
|
|
1689
|
+
var f;
|
|
1690
|
+
return ((f = t.streamingManager) == null ? void 0 : f.interruptAvailable) ?? !1;
|
|
1698
1691
|
},
|
|
1699
|
-
starterMessages: ((
|
|
1692
|
+
starterMessages: ((B = l.knowledge) == null ? void 0 : B.starter_message) || [],
|
|
1700
1693
|
getSTTToken: () => g.getSTTToken(l.id),
|
|
1701
|
-
changeMode:
|
|
1694
|
+
changeMode: H,
|
|
1702
1695
|
enrichAnalytics: c.enrich,
|
|
1703
1696
|
async connect() {
|
|
1704
1697
|
await k(!0), c.track("agent-chat", {
|
|
@@ -1707,100 +1700,100 @@ async function zn(e, n) {
|
|
|
1707
1700
|
});
|
|
1708
1701
|
},
|
|
1709
1702
|
async reconnect() {
|
|
1710
|
-
const
|
|
1711
|
-
if (
|
|
1703
|
+
const f = t.streamingManager;
|
|
1704
|
+
if (y && (f != null && f.reconnect)) {
|
|
1712
1705
|
try {
|
|
1713
|
-
await
|
|
1706
|
+
await f.reconnect(), c.track("agent-chat", {
|
|
1714
1707
|
event: "reconnect",
|
|
1715
1708
|
mode: t.chatMode
|
|
1716
1709
|
});
|
|
1717
1710
|
} catch {
|
|
1718
|
-
await
|
|
1711
|
+
await W(), await k(!1);
|
|
1719
1712
|
}
|
|
1720
1713
|
return;
|
|
1721
1714
|
}
|
|
1722
|
-
await
|
|
1715
|
+
await W(), await k(!1), c.track("agent-chat", {
|
|
1723
1716
|
event: "reconnect",
|
|
1724
1717
|
mode: t.chatMode
|
|
1725
1718
|
});
|
|
1726
1719
|
},
|
|
1727
1720
|
async disconnect() {
|
|
1728
|
-
await
|
|
1721
|
+
await W(), c.track("agent-chat", {
|
|
1729
1722
|
event: "disconnect",
|
|
1730
1723
|
mode: t.chatMode
|
|
1731
1724
|
});
|
|
1732
1725
|
},
|
|
1733
|
-
async publishMicrophoneStream(
|
|
1726
|
+
async publishMicrophoneStream(f) {
|
|
1734
1727
|
var S;
|
|
1735
1728
|
if (!((S = t.streamingManager) != null && S.publishMicrophoneStream))
|
|
1736
1729
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1737
|
-
return t.streamingManager.publishMicrophoneStream(
|
|
1730
|
+
return t.streamingManager.publishMicrophoneStream(f);
|
|
1738
1731
|
},
|
|
1739
1732
|
async unpublishMicrophoneStream() {
|
|
1740
|
-
var
|
|
1741
|
-
if (!((
|
|
1733
|
+
var f;
|
|
1734
|
+
if (!((f = t.streamingManager) != null && f.unpublishMicrophoneStream))
|
|
1742
1735
|
throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
|
|
1743
1736
|
return t.streamingManager.unpublishMicrophoneStream();
|
|
1744
1737
|
},
|
|
1745
|
-
async publishCameraStream(
|
|
1738
|
+
async publishCameraStream(f) {
|
|
1746
1739
|
var S;
|
|
1747
1740
|
if (!((S = t.streamingManager) != null && S.publishCameraStream))
|
|
1748
1741
|
throw new Error("publishCameraStream is not available for this streaming manager");
|
|
1749
|
-
return t.streamingManager.publishCameraStream(
|
|
1742
|
+
return t.streamingManager.publishCameraStream(f);
|
|
1750
1743
|
},
|
|
1751
1744
|
async unpublishCameraStream() {
|
|
1752
|
-
var
|
|
1753
|
-
if (!((
|
|
1745
|
+
var f;
|
|
1746
|
+
if (!((f = t.streamingManager) != null && f.unpublishCameraStream))
|
|
1754
1747
|
throw new Error("unpublishCameraStream is not available for this streaming manager");
|
|
1755
1748
|
return t.streamingManager.unpublishCameraStream();
|
|
1756
1749
|
},
|
|
1757
|
-
async chat(
|
|
1758
|
-
var
|
|
1750
|
+
async chat(f) {
|
|
1751
|
+
var F, I, q, Y, Z;
|
|
1759
1752
|
const S = () => {
|
|
1760
1753
|
if (nt(d))
|
|
1761
|
-
throw new
|
|
1762
|
-
if (
|
|
1763
|
-
throw new
|
|
1764
|
-
if (
|
|
1765
|
-
throw new
|
|
1766
|
-
if (t.chatMode ===
|
|
1767
|
-
throw new
|
|
1768
|
-
if (![
|
|
1754
|
+
throw new de(`${d} is enabled, chat is disabled`);
|
|
1755
|
+
if (f.length >= 800)
|
|
1756
|
+
throw new de("Message cannot be more than 800 characters");
|
|
1757
|
+
if (f.length === 0)
|
|
1758
|
+
throw new de("Message cannot be empty");
|
|
1759
|
+
if (t.chatMode === U.Maintenance)
|
|
1760
|
+
throw new de("Chat is in maintenance mode");
|
|
1761
|
+
if (![U.TextOnly, U.Playground].includes(t.chatMode)) {
|
|
1769
1762
|
if (!t.streamingManager)
|
|
1770
|
-
throw new
|
|
1763
|
+
throw new de("Streaming manager is not initialized");
|
|
1771
1764
|
if (!t.chat)
|
|
1772
|
-
throw new
|
|
1765
|
+
throw new de("Chat is not initialized");
|
|
1773
1766
|
}
|
|
1774
|
-
},
|
|
1775
|
-
var x,
|
|
1767
|
+
}, E = async () => {
|
|
1768
|
+
var x, V;
|
|
1776
1769
|
if (!t.chat) {
|
|
1777
|
-
const
|
|
1770
|
+
const ee = await at(
|
|
1778
1771
|
l,
|
|
1779
1772
|
g,
|
|
1780
1773
|
c,
|
|
1781
1774
|
t.chatMode,
|
|
1782
1775
|
n.persistentChat
|
|
1783
1776
|
);
|
|
1784
|
-
if (!
|
|
1777
|
+
if (!ee.chat)
|
|
1785
1778
|
throw new yt(t.chatMode, !!n.persistentChat);
|
|
1786
|
-
t.chat =
|
|
1779
|
+
t.chat = ee.chat, (V = (x = n.callbacks).onNewChat) == null || V.call(x, t.chat.id);
|
|
1787
1780
|
}
|
|
1788
1781
|
return t.chat.id;
|
|
1789
|
-
},
|
|
1790
|
-
const
|
|
1791
|
-
return Ie(
|
|
1792
|
-
var
|
|
1793
|
-
return await ((
|
|
1782
|
+
}, J = async (x, V) => {
|
|
1783
|
+
const ee = t.chatMode === U.Playground;
|
|
1784
|
+
return Ie(y && !ee ? async () => {
|
|
1785
|
+
var R, j;
|
|
1786
|
+
return await ((j = (R = t.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : j.call(R, f)), Promise.resolve({});
|
|
1794
1787
|
} : async () => {
|
|
1795
|
-
var
|
|
1788
|
+
var R, j;
|
|
1796
1789
|
return g.chat(
|
|
1797
1790
|
l.id,
|
|
1798
|
-
|
|
1791
|
+
V,
|
|
1799
1792
|
{
|
|
1800
1793
|
chatMode: t.chatMode,
|
|
1801
|
-
streamId: (
|
|
1802
|
-
sessionId: (
|
|
1803
|
-
messages: x.map(({ matches:
|
|
1794
|
+
streamId: (R = t.streamingManager) == null ? void 0 : R.streamId,
|
|
1795
|
+
sessionId: (j = t.streamingManager) == null ? void 0 : j.sessionId,
|
|
1796
|
+
messages: x.map(({ matches: Re, ...se }) => se)
|
|
1804
1797
|
},
|
|
1805
1798
|
{
|
|
1806
1799
|
...it(t.chatMode),
|
|
@@ -1809,108 +1802,108 @@ async function zn(e, n) {
|
|
|
1809
1802
|
);
|
|
1810
1803
|
}, {
|
|
1811
1804
|
limit: 2,
|
|
1812
|
-
shouldRetryFn: (
|
|
1813
|
-
var
|
|
1814
|
-
const
|
|
1815
|
-
return !((
|
|
1805
|
+
shouldRetryFn: (R) => {
|
|
1806
|
+
var se, we, ye, ve;
|
|
1807
|
+
const j = (se = R == null ? void 0 : R.message) == null ? void 0 : se.includes("missing or invalid session_id");
|
|
1808
|
+
return !((we = R == null ? void 0 : R.message) == null ? void 0 : we.includes("Stream Error")) && !j ? ((ve = (ye = n.callbacks).onError) == null || ve.call(ye, R), !1) : !0;
|
|
1816
1809
|
},
|
|
1817
1810
|
onRetry: async () => {
|
|
1818
|
-
await
|
|
1811
|
+
await W(), await k(!1);
|
|
1819
1812
|
}
|
|
1820
1813
|
});
|
|
1821
1814
|
};
|
|
1822
1815
|
try {
|
|
1823
|
-
|
|
1824
|
-
id:
|
|
1816
|
+
z(), S(), t.messages.push({
|
|
1817
|
+
id: ue(),
|
|
1825
1818
|
role: "user",
|
|
1826
|
-
content:
|
|
1827
|
-
created_at: new Date(
|
|
1828
|
-
}), (
|
|
1829
|
-
const x = await
|
|
1819
|
+
content: f,
|
|
1820
|
+
created_at: new Date(re.update()).toISOString()
|
|
1821
|
+
}), (I = (F = n.callbacks).onNewMessage) == null || I.call(F, [...t.messages], "user");
|
|
1822
|
+
const x = await E(), V = await J([...t.messages], x);
|
|
1830
1823
|
return t.messages.push({
|
|
1831
|
-
id:
|
|
1824
|
+
id: ue(),
|
|
1832
1825
|
role: "assistant",
|
|
1833
|
-
content:
|
|
1826
|
+
content: V.result || "",
|
|
1834
1827
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1835
|
-
context:
|
|
1836
|
-
matches:
|
|
1828
|
+
context: V.context,
|
|
1829
|
+
matches: V.matches
|
|
1837
1830
|
}), c.track("agent-message-send", {
|
|
1838
1831
|
event: "success",
|
|
1839
1832
|
messages: t.messages.length + 1
|
|
1840
|
-
}),
|
|
1841
|
-
latency:
|
|
1833
|
+
}), V.result && ((Y = (q = n.callbacks).onNewMessage) == null || Y.call(q, [...t.messages], "answer"), c.track("agent-message-received", {
|
|
1834
|
+
latency: re.get(!0),
|
|
1842
1835
|
messages: t.messages.length
|
|
1843
|
-
})),
|
|
1836
|
+
})), V;
|
|
1844
1837
|
} catch (x) {
|
|
1845
|
-
throw ((
|
|
1838
|
+
throw ((Z = t.messages[t.messages.length - 1]) == null ? void 0 : Z.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
|
|
1846
1839
|
event: "error",
|
|
1847
1840
|
messages: t.messages.length
|
|
1848
1841
|
}), x;
|
|
1849
1842
|
}
|
|
1850
1843
|
},
|
|
1851
|
-
rate(
|
|
1852
|
-
var
|
|
1853
|
-
const
|
|
1844
|
+
rate(f, S, E) {
|
|
1845
|
+
var I, q, Y, Z;
|
|
1846
|
+
const J = t.messages.find((x) => x.id === f);
|
|
1854
1847
|
if (t.chat) {
|
|
1855
|
-
if (!
|
|
1848
|
+
if (!J)
|
|
1856
1849
|
throw new Error("Message not found");
|
|
1857
1850
|
} else throw new Error("Chat is not initialized");
|
|
1858
|
-
const
|
|
1851
|
+
const F = ((I = J.matches) == null ? void 0 : I.map((x) => [x.document_id, x.id])) ?? [];
|
|
1859
1852
|
return c.track("agent-rate", {
|
|
1860
|
-
event:
|
|
1853
|
+
event: E ? "update" : "create",
|
|
1861
1854
|
thumb: S === 1 ? "up" : "down",
|
|
1862
|
-
knowledge_id: ((
|
|
1863
|
-
matches:
|
|
1855
|
+
knowledge_id: ((q = l.knowledge) == null ? void 0 : q.id) ?? "",
|
|
1856
|
+
matches: F,
|
|
1864
1857
|
score: S
|
|
1865
|
-
}),
|
|
1866
|
-
knowledge_id: ((
|
|
1867
|
-
message_id:
|
|
1868
|
-
matches:
|
|
1858
|
+
}), E ? g.updateRating(l.id, t.chat.id, E, {
|
|
1859
|
+
knowledge_id: ((Y = l.knowledge) == null ? void 0 : Y.id) ?? "",
|
|
1860
|
+
message_id: f,
|
|
1861
|
+
matches: F,
|
|
1869
1862
|
score: S
|
|
1870
1863
|
}) : g.createRating(l.id, t.chat.id, {
|
|
1871
|
-
knowledge_id: ((
|
|
1872
|
-
message_id:
|
|
1873
|
-
matches:
|
|
1864
|
+
knowledge_id: ((Z = l.knowledge) == null ? void 0 : Z.id) ?? "",
|
|
1865
|
+
message_id: f,
|
|
1866
|
+
matches: F,
|
|
1874
1867
|
score: S
|
|
1875
1868
|
});
|
|
1876
1869
|
},
|
|
1877
|
-
deleteRate(
|
|
1870
|
+
deleteRate(f) {
|
|
1878
1871
|
if (!t.chat)
|
|
1879
1872
|
throw new Error("Chat is not initialized");
|
|
1880
|
-
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id,
|
|
1873
|
+
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
|
|
1881
1874
|
},
|
|
1882
|
-
async speak(
|
|
1883
|
-
var
|
|
1875
|
+
async speak(f) {
|
|
1876
|
+
var F, I, q;
|
|
1884
1877
|
function S() {
|
|
1885
|
-
if (typeof
|
|
1878
|
+
if (typeof f == "string") {
|
|
1886
1879
|
if (!l.presenter.voice)
|
|
1887
1880
|
throw new Error("Presenter voice is not initialized");
|
|
1888
1881
|
return {
|
|
1889
1882
|
type: "text",
|
|
1890
1883
|
provider: l.presenter.voice,
|
|
1891
|
-
input:
|
|
1884
|
+
input: f,
|
|
1892
1885
|
ssml: !1
|
|
1893
1886
|
};
|
|
1894
1887
|
}
|
|
1895
|
-
if (
|
|
1888
|
+
if (f.type === "text" && !f.provider) {
|
|
1896
1889
|
if (!l.presenter.voice)
|
|
1897
1890
|
throw new Error("Presenter voice is not initialized");
|
|
1898
1891
|
return {
|
|
1899
1892
|
type: "text",
|
|
1900
1893
|
provider: l.presenter.voice,
|
|
1901
|
-
input:
|
|
1902
|
-
ssml:
|
|
1894
|
+
input: f.input,
|
|
1895
|
+
ssml: f.ssml
|
|
1903
1896
|
};
|
|
1904
1897
|
}
|
|
1905
|
-
return
|
|
1898
|
+
return f;
|
|
1906
1899
|
}
|
|
1907
|
-
const
|
|
1908
|
-
if (c.track("agent-speak",
|
|
1909
|
-
id:
|
|
1900
|
+
const E = S();
|
|
1901
|
+
if (c.track("agent-speak", E), re.update(), t.messages && E.type === "text" && (t.messages.push({
|
|
1902
|
+
id: ue(),
|
|
1910
1903
|
role: "assistant",
|
|
1911
|
-
content:
|
|
1904
|
+
content: E.input,
|
|
1912
1905
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1913
|
-
}), (
|
|
1906
|
+
}), (I = (F = n.callbacks).onNewMessage) == null || I.call(F, [...t.messages], "answer")), Bt(t.chatMode))
|
|
1914
1907
|
return {
|
|
1915
1908
|
duration: 0,
|
|
1916
1909
|
video_id: "",
|
|
@@ -1919,34 +1912,34 @@ async function zn(e, n) {
|
|
|
1919
1912
|
if (!t.streamingManager)
|
|
1920
1913
|
throw new Error("Please connect to the agent first");
|
|
1921
1914
|
return t.streamingManager.speak({
|
|
1922
|
-
script:
|
|
1923
|
-
metadata: { chat_id: (
|
|
1915
|
+
script: E,
|
|
1916
|
+
metadata: { chat_id: (q = t.chat) == null ? void 0 : q.id, agent_id: l.id }
|
|
1924
1917
|
});
|
|
1925
1918
|
},
|
|
1926
|
-
interrupt:
|
|
1919
|
+
interrupt: $
|
|
1927
1920
|
};
|
|
1928
1921
|
}
|
|
1929
1922
|
export {
|
|
1930
|
-
|
|
1923
|
+
O as AgentActivityState,
|
|
1931
1924
|
Tt as AgentStatus,
|
|
1932
1925
|
yt as ChatCreationFailed,
|
|
1933
|
-
|
|
1926
|
+
U as ChatMode,
|
|
1934
1927
|
vt as ChatModeDowngraded,
|
|
1935
|
-
|
|
1928
|
+
X as ChatProgress,
|
|
1936
1929
|
b as ConnectionState,
|
|
1937
|
-
|
|
1930
|
+
ne as ConnectivityState,
|
|
1938
1931
|
It as DocumentType,
|
|
1939
1932
|
Dt as KnowledgeType,
|
|
1940
1933
|
Rt as PlanGroup,
|
|
1941
1934
|
Mt as Providers,
|
|
1942
1935
|
kt as RateState,
|
|
1943
|
-
|
|
1944
|
-
|
|
1936
|
+
D as StreamEvents,
|
|
1937
|
+
ie as StreamType,
|
|
1945
1938
|
T as StreamingState,
|
|
1946
1939
|
Et as Subject,
|
|
1947
1940
|
Pe as TransportProvider,
|
|
1948
1941
|
St as UserPlan,
|
|
1949
|
-
|
|
1942
|
+
de as ValidationError,
|
|
1950
1943
|
Ze as VideoType,
|
|
1951
1944
|
At as VoiceAccess,
|
|
1952
1945
|
Ct as WsError,
|