@d-id/client-sdk 1.1.61-staging.284 → 1.1.61-staging.287
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 +411 -391
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var Et = Object.defineProperty;
|
|
2
2
|
var kt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
|
-
var
|
|
3
|
+
var ve = (e, n, i) => kt(e, typeof n != "symbol" ? n + "" : n, i);
|
|
4
4
|
class Ie extends Error {
|
|
5
5
|
constructor({ kind: i, description: r, error: s }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: r }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
ve(this, "kind");
|
|
8
|
+
ve(this, "description");
|
|
9
|
+
ve(this, "error");
|
|
10
10
|
this.kind = i, this.description = r, this.error = s;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -26,7 +26,7 @@ class It extends Ie {
|
|
|
26
26
|
class me extends Ie {
|
|
27
27
|
constructor(i, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
ve(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -35,7 +35,7 @@ class Dt extends Ie {
|
|
|
35
35
|
super({ kind: "WSError", description: n });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var _t = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_t || {}), At = /* @__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))(At || {}), bt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(bt || {}), Lt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Lt || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pt || {}), xt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xt || {}), $t = /* @__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))($t || {}), dt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(dt || {});
|
|
39
39
|
const Hn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -48,9 +48,9 @@ const Hn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var k = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(k || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), R = /* @__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.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(R || {}), x = /* @__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))(x || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ne = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ne || {}), jt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(jt || {}), Bt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Bt || {});
|
|
52
52
|
const Ft = 45 * 1e3, Nt = "X-Playground-Chat", Ee = "https://api.d-id.com", Kt = "wss://notifications.d-id.com", zt = "79f81a83a67430be2bc0fd61042b8faa", Vt = (...e) => {
|
|
53
|
-
}, ut = (e) => new Promise((n) => setTimeout(n, e)),
|
|
53
|
+
}, ut = (e) => new Promise((n) => setTimeout(n, e)), Te = (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
|
}, lt = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ut = (e) => {
|
|
@@ -101,7 +101,7 @@ function Wt(e) {
|
|
|
101
101
|
return s < e.length && r.push({ type: "text", text: e.slice(s) }), r;
|
|
102
102
|
}
|
|
103
103
|
let Ze = "", Pe = [];
|
|
104
|
-
function
|
|
104
|
+
function Re(e) {
|
|
105
105
|
return e === Ze || (Ze = e, Pe = Wt(e)), Pe;
|
|
106
106
|
}
|
|
107
107
|
function Ht(e, n) {
|
|
@@ -142,22 +142,21 @@ function $e(e) {
|
|
|
142
142
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
143
143
|
let n = window.localStorage.getItem("did_external_key_id");
|
|
144
144
|
if (!n) {
|
|
145
|
-
let i =
|
|
145
|
+
let i = Te();
|
|
146
146
|
window.localStorage.setItem("did_external_key_id", i), n = i;
|
|
147
147
|
}
|
|
148
148
|
return n;
|
|
149
149
|
}
|
|
150
|
-
let qt = ge();
|
|
151
150
|
function mt(e, n) {
|
|
152
151
|
if (e.type === "bearer")
|
|
153
152
|
return `Bearer ${e.token}`;
|
|
154
153
|
if (e.type === "basic")
|
|
155
154
|
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
156
155
|
if (e.type === "key")
|
|
157
|
-
return `Client-Key ${e.clientKey}.${$e(n)}
|
|
156
|
+
return `Client-Key ${e.clientKey}.${$e(n)}`;
|
|
158
157
|
throw new Error(`Unknown auth type: ${e}`);
|
|
159
158
|
}
|
|
160
|
-
const
|
|
159
|
+
const qt = (e) => xe(e, {
|
|
161
160
|
limit: 3,
|
|
162
161
|
delayMs: 1e3,
|
|
163
162
|
timeout: 0,
|
|
@@ -165,7 +164,7 @@ const Qt = (e) => xe(e, {
|
|
|
165
164
|
});
|
|
166
165
|
function ze(e, n = Ee, i, r) {
|
|
167
166
|
const s = async (a, o) => {
|
|
168
|
-
const { skipErrorHandler: c, ...t } = o || {}, d = await
|
|
167
|
+
const { skipErrorHandler: c, ...t } = o || {}, d = await qt(
|
|
169
168
|
() => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
170
169
|
...t,
|
|
171
170
|
headers: {
|
|
@@ -197,7 +196,7 @@ function ze(e, n = Ee, i, r) {
|
|
|
197
196
|
}
|
|
198
197
|
};
|
|
199
198
|
}
|
|
200
|
-
function
|
|
199
|
+
function Qt(e, n = Ee, i, r) {
|
|
201
200
|
const s = ze(e, `${n}/agents`, i, r);
|
|
202
201
|
return {
|
|
203
202
|
create(a, o) {
|
|
@@ -235,7 +234,7 @@ function Xt(e, n = Ee, i, r) {
|
|
|
235
234
|
}
|
|
236
235
|
};
|
|
237
236
|
}
|
|
238
|
-
function
|
|
237
|
+
function Xt(e) {
|
|
239
238
|
var s, a, o, c;
|
|
240
239
|
const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
241
240
|
const t = navigator.platform;
|
|
@@ -253,7 +252,7 @@ function Yt(e) {
|
|
|
253
252
|
}
|
|
254
253
|
};
|
|
255
254
|
}
|
|
256
|
-
function
|
|
255
|
+
function Yt(e) {
|
|
257
256
|
var i, r, s, a, o, c;
|
|
258
257
|
const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
259
258
|
return {
|
|
@@ -278,8 +277,8 @@ function Gt(e) {
|
|
|
278
277
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
279
278
|
};
|
|
280
279
|
}
|
|
281
|
-
const
|
|
282
|
-
function
|
|
280
|
+
const Gt = (e) => e.reduce((n, i) => n + i, 0), et = (e) => Gt(e) / e.length;
|
|
281
|
+
function Zt(e, n, i) {
|
|
283
282
|
var t, d, h;
|
|
284
283
|
const { event: r, ...s } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: o } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
|
|
285
284
|
return {
|
|
@@ -293,8 +292,8 @@ function en(e, n, i) {
|
|
|
293
292
|
function tt(e) {
|
|
294
293
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
295
294
|
}
|
|
296
|
-
const
|
|
297
|
-
function
|
|
295
|
+
const en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
296
|
+
function tn(e) {
|
|
298
297
|
const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
|
|
299
298
|
return {
|
|
300
299
|
token: e.token || "testKey",
|
|
@@ -305,7 +304,7 @@ function nn(e) {
|
|
|
305
304
|
...e.mixpanelAdditionalProperties || {}
|
|
306
305
|
},
|
|
307
306
|
isEnabled: e.isEnabled ?? !0,
|
|
308
|
-
getRandom:
|
|
307
|
+
getRandom: Te,
|
|
309
308
|
enrich(r) {
|
|
310
309
|
this.additionalProperties = { ...this.additionalProperties, ...r };
|
|
311
310
|
},
|
|
@@ -338,7 +337,7 @@ function nn(e) {
|
|
|
338
337
|
])
|
|
339
338
|
})
|
|
340
339
|
};
|
|
341
|
-
return fetch(
|
|
340
|
+
return fetch(en, d).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
|
|
342
341
|
},
|
|
343
342
|
linkTrack(r, s, a, o) {
|
|
344
343
|
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), o.includes(a) || o.push(a);
|
|
@@ -376,10 +375,10 @@ async function ht(e, n, i, r, s = !1, a) {
|
|
|
376
375
|
mode: r
|
|
377
376
|
})), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
|
|
378
377
|
} catch (o) {
|
|
379
|
-
throw
|
|
378
|
+
throw nn(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
380
379
|
}
|
|
381
380
|
}
|
|
382
|
-
const
|
|
381
|
+
const nn = (e) => {
|
|
383
382
|
try {
|
|
384
383
|
const n = JSON.parse(e.message);
|
|
385
384
|
return n == null ? void 0 : n.kind;
|
|
@@ -387,10 +386,10 @@ const rn = (e) => {
|
|
|
387
386
|
return "UnknownError";
|
|
388
387
|
}
|
|
389
388
|
};
|
|
390
|
-
function
|
|
389
|
+
function rn(e) {
|
|
391
390
|
return e && e.length > 0 ? e : [];
|
|
392
391
|
}
|
|
393
|
-
function
|
|
392
|
+
function an(e, n, i, r) {
|
|
394
393
|
const s = ze(e, `${n}/v2/agents/${i}`, r);
|
|
395
394
|
return {
|
|
396
395
|
async createStream(a) {
|
|
@@ -398,11 +397,11 @@ function on(e, n, i, r) {
|
|
|
398
397
|
}
|
|
399
398
|
};
|
|
400
399
|
}
|
|
401
|
-
const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""),
|
|
402
|
-
[
|
|
403
|
-
[
|
|
400
|
+
const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), on = {
|
|
401
|
+
[R.ChatAnswer]: X.Answer,
|
|
402
|
+
[R.ChatPartial]: X.Partial
|
|
404
403
|
};
|
|
405
|
-
function
|
|
404
|
+
function sn(e, n, i) {
|
|
406
405
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
407
406
|
return {
|
|
408
407
|
duration: r,
|
|
@@ -422,7 +421,7 @@ function cn(e, n, i) {
|
|
|
422
421
|
lowFpsCount: i
|
|
423
422
|
};
|
|
424
423
|
}
|
|
425
|
-
function
|
|
424
|
+
function cn(e) {
|
|
426
425
|
return e.filter(
|
|
427
426
|
(n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0
|
|
428
427
|
).map((n) => {
|
|
@@ -433,7 +432,7 @@ function dn(e) {
|
|
|
433
432
|
};
|
|
434
433
|
});
|
|
435
434
|
}
|
|
436
|
-
function
|
|
435
|
+
function dn(e) {
|
|
437
436
|
let n = "", i = 0;
|
|
438
437
|
for (const r of e.values()) {
|
|
439
438
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (n = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -515,14 +514,14 @@ function rt(e, n, i) {
|
|
|
515
514
|
framesPerSecond: t.framesPerSecond,
|
|
516
515
|
freezeCount: t.freezeCount - e[d - 1].freezeCount,
|
|
517
516
|
freezeDuration: t.freezeDuration - e[d - 1].freezeDuration
|
|
518
|
-
}), s =
|
|
517
|
+
}), s = cn(r), a = s.reduce((t, d) => t + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), c = r.filter((t) => !!t.rtt).map((t) => t.rtt);
|
|
519
518
|
return {
|
|
520
519
|
webRTCStats: {
|
|
521
520
|
anomalies: s,
|
|
522
521
|
minRtt: Math.min(...c),
|
|
523
522
|
avgRtt: et(c),
|
|
524
523
|
maxRtt: Math.max(...c),
|
|
525
|
-
aggregateReport:
|
|
524
|
+
aggregateReport: sn(e[0], e[e.length - 1], a),
|
|
526
525
|
minJitterDelayInInterval: Math.min(...o),
|
|
527
526
|
maxJitterDelayInInterval: Math.max(...o),
|
|
528
527
|
avgJitterDelayInInterval: et(o)
|
|
@@ -537,48 +536,48 @@ function wt(e, n) {
|
|
|
537
536
|
return i;
|
|
538
537
|
return null;
|
|
539
538
|
}
|
|
540
|
-
const
|
|
541
|
-
function
|
|
539
|
+
const Ce = 10;
|
|
540
|
+
function un(e, n) {
|
|
542
541
|
let i = !1, r = !1, s = null, a = 0, o = 0, c = {};
|
|
543
542
|
async function t() {
|
|
544
543
|
if (i) {
|
|
545
544
|
try {
|
|
546
545
|
const d = await e();
|
|
547
546
|
if (!d) {
|
|
548
|
-
s = setTimeout(t,
|
|
547
|
+
s = setTimeout(t, Ce);
|
|
549
548
|
return;
|
|
550
549
|
}
|
|
551
550
|
const h = wt(d, "audio");
|
|
552
551
|
if (!h) {
|
|
553
|
-
s = setTimeout(t,
|
|
552
|
+
s = setTimeout(t, Ce);
|
|
554
553
|
return;
|
|
555
554
|
}
|
|
556
555
|
const g = h.totalAudioEnergy ?? 0, l = h.totalSamplesReceived ?? 0;
|
|
557
556
|
if (!r) {
|
|
558
|
-
a = g, o = l, r = !0, s = setTimeout(t,
|
|
557
|
+
a = g, o = l, r = !0, s = setTimeout(t, Ce);
|
|
559
558
|
return;
|
|
560
559
|
}
|
|
561
|
-
const
|
|
562
|
-
if (a = g, o = l,
|
|
560
|
+
const p = g - a, D = l - o;
|
|
561
|
+
if (a = g, o = l, D > 0 && p > 0) {
|
|
563
562
|
i = !1, n(c);
|
|
564
563
|
return;
|
|
565
564
|
}
|
|
566
565
|
} catch {
|
|
567
566
|
}
|
|
568
|
-
i && (s = setTimeout(t,
|
|
567
|
+
i && (s = setTimeout(t, Ce));
|
|
569
568
|
}
|
|
570
569
|
}
|
|
571
570
|
return {
|
|
572
571
|
arm(d = {}) {
|
|
573
|
-
c = d, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t,
|
|
572
|
+
c = d, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t, Ce);
|
|
574
573
|
},
|
|
575
574
|
destroy() {
|
|
576
575
|
i = !1, s !== null && (clearTimeout(s), s = null);
|
|
577
576
|
}
|
|
578
577
|
};
|
|
579
578
|
}
|
|
580
|
-
const Me = 100,
|
|
581
|
-
function
|
|
579
|
+
const Me = 100, ln = Math.max(Math.ceil(400 / Me), 1), fn = 0.25, mn = 0.28;
|
|
580
|
+
function gn() {
|
|
582
581
|
let e = 0, n, i, r = 0;
|
|
583
582
|
return (s) => {
|
|
584
583
|
const a = wt(s, "video");
|
|
@@ -595,18 +594,18 @@ function hn() {
|
|
|
595
594
|
};
|
|
596
595
|
}
|
|
597
596
|
function yt(e, n, i, r, s) {
|
|
598
|
-
let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0,
|
|
599
|
-
const
|
|
597
|
+
let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0, p = 0;
|
|
598
|
+
const D = gn();
|
|
600
599
|
async function N() {
|
|
601
600
|
const B = await e();
|
|
602
601
|
if (!B)
|
|
603
602
|
return;
|
|
604
|
-
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: M } =
|
|
603
|
+
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: M } = D(B), Y = dn(B);
|
|
605
604
|
if (F)
|
|
606
|
-
t = 0, l = M -
|
|
607
|
-
else if (d && (t++, t >=
|
|
605
|
+
t = 0, l = M - p, g = I < fn ? ae.Strong : I > mn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, p += l, l = 0), d || (r == null || r(k.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
|
|
606
|
+
else if (d && (t++, t >= ln)) {
|
|
608
607
|
const Q = rt(o, Me, c);
|
|
609
|
-
r == null || r(
|
|
608
|
+
r == null || r(k.Stop, Q), n() || i(), p = M, d = !1;
|
|
610
609
|
}
|
|
611
610
|
}
|
|
612
611
|
return {
|
|
@@ -620,7 +619,7 @@ function yt(e, n, i, r, s) {
|
|
|
620
619
|
};
|
|
621
620
|
}
|
|
622
621
|
const it = 2e4;
|
|
623
|
-
async function
|
|
622
|
+
async function hn() {
|
|
624
623
|
try {
|
|
625
624
|
return await import("./livekit-client.esm-RGXA_gNu.js");
|
|
626
625
|
} catch {
|
|
@@ -629,13 +628,13 @@ async function pn() {
|
|
|
629
628
|
);
|
|
630
629
|
}
|
|
631
630
|
}
|
|
632
|
-
const
|
|
631
|
+
const pn = {
|
|
633
632
|
excellent: ae.Strong,
|
|
634
633
|
good: ae.Strong,
|
|
635
634
|
poor: ae.Weak,
|
|
636
635
|
lost: ae.Unknown,
|
|
637
636
|
unknown: ae.Unknown
|
|
638
|
-
},
|
|
637
|
+
}, Se = JSON.stringify({
|
|
639
638
|
kind: "InternalServerError",
|
|
640
639
|
description: "Stream Error"
|
|
641
640
|
});
|
|
@@ -644,11 +643,11 @@ function Be(e, n, i) {
|
|
|
644
643
|
var r, s;
|
|
645
644
|
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, x.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
|
|
646
645
|
}
|
|
647
|
-
async function
|
|
646
|
+
async function wn(e, n, i) {
|
|
648
647
|
var Je;
|
|
649
|
-
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await
|
|
650
|
-
let l = null,
|
|
651
|
-
const
|
|
648
|
+
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await hn(), { callbacks: t, auth: d, baseURL: h, analytics: g } = i;
|
|
649
|
+
let l = null, p = !1;
|
|
650
|
+
const D = se.Fluent;
|
|
652
651
|
let N = null;
|
|
653
652
|
const B = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
|
|
654
653
|
let I = null, M = null, Y = null, Q = !1;
|
|
@@ -658,20 +657,20 @@ async function yn(e, n, i) {
|
|
|
658
657
|
dynacast: !0
|
|
659
658
|
});
|
|
660
659
|
let U = null, te = W.Idle, ne = !0;
|
|
661
|
-
const $ =
|
|
660
|
+
const $ = an(d, h || Ee, e, t.onError);
|
|
662
661
|
let K, H, re, de = !0;
|
|
663
662
|
try {
|
|
664
663
|
const u = await $.createStream({
|
|
665
664
|
transport: n.transport,
|
|
666
665
|
chat_persist: n.chat_persist ?? !0
|
|
667
|
-
}), { id: m, session_token:
|
|
668
|
-
(Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H =
|
|
666
|
+
}), { id: m, session_token: w, session_url: S, interrupt_enabled: b } = u;
|
|
667
|
+
(Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H = w, re = S, de = b ?? !0, await l.prepareConnection(re, H);
|
|
669
668
|
} catch (u) {
|
|
670
669
|
Be(u, r, t);
|
|
671
670
|
}
|
|
672
671
|
if (!re || !H || !K)
|
|
673
672
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
674
|
-
l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected,
|
|
673
|
+
l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, T).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, J).on(a.TrackUnsubscribed, y).on(a.DataReceived, z).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
|
|
675
674
|
function ue(u, m) {
|
|
676
675
|
m != null && m.isLocal && (oe.update(), te === W.Talking && (te = W.Idle));
|
|
677
676
|
}
|
|
@@ -689,101 +688,101 @@ async function yn(e, n, i) {
|
|
|
689
688
|
Be(u, r, t);
|
|
690
689
|
}
|
|
691
690
|
g.enrich({
|
|
692
|
-
"stream-type":
|
|
691
|
+
"stream-type": D
|
|
693
692
|
});
|
|
694
693
|
function f(u) {
|
|
695
|
-
var m,
|
|
694
|
+
var m, w, S, b;
|
|
696
695
|
switch (r("Connection state changed:", u), u) {
|
|
697
696
|
case o.Connecting:
|
|
698
697
|
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, x.Connecting, "livekit:connecting");
|
|
699
698
|
break;
|
|
700
699
|
case o.Connected:
|
|
701
|
-
r("LiveKit room connected successfully"),
|
|
700
|
+
r("LiveKit room connected successfully"), p = !0;
|
|
702
701
|
break;
|
|
703
702
|
case o.Disconnected:
|
|
704
|
-
r("LiveKit room disconnected"),
|
|
703
|
+
r("LiveKit room disconnected"), p = !1, Q = !1, B.publication = null, F.publication = null, (w = t.onConnectionStateChange) == null || w.call(t, x.Disconnected, "livekit:disconnected");
|
|
705
704
|
break;
|
|
706
705
|
case o.Reconnecting:
|
|
707
706
|
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, x.Connecting, "livekit:reconnecting");
|
|
708
707
|
break;
|
|
709
708
|
case o.SignalReconnecting:
|
|
710
|
-
r("LiveKit room signal reconnecting..."), (
|
|
709
|
+
r("LiveKit room signal reconnecting..."), (b = t.onConnectionStateChange) == null || b.call(t, x.Connecting, "livekit:signal-reconnecting");
|
|
711
710
|
break;
|
|
712
711
|
}
|
|
713
712
|
}
|
|
714
713
|
function C(u, m) {
|
|
715
|
-
var
|
|
716
|
-
r("Connection quality:", u), m != null && m.isLocal && ((
|
|
714
|
+
var w;
|
|
715
|
+
r("Connection quality:", u), m != null && m.isLocal && ((w = t.onConnectivityStateChange) == null || w.call(t, pn[u]));
|
|
717
716
|
}
|
|
718
|
-
function
|
|
717
|
+
function T(u) {
|
|
719
718
|
r("Participant connected:", u.identity);
|
|
720
719
|
}
|
|
721
720
|
function A(u) {
|
|
722
721
|
r("Participant disconnected:", u.identity), Le("livekit:participant-disconnected");
|
|
723
722
|
}
|
|
724
|
-
function
|
|
723
|
+
function _() {
|
|
725
724
|
var u;
|
|
726
|
-
Y !==
|
|
725
|
+
Y !== k.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = k.Start, (u = t.onVideoStateChange) == null || u.call(t, k.Start));
|
|
727
726
|
}
|
|
728
|
-
function
|
|
727
|
+
function L(u) {
|
|
729
728
|
var m;
|
|
730
|
-
Y !==
|
|
729
|
+
Y !== k.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = k.Stop, (m = t.onVideoStateChange) == null || m.call(t, k.Stop, u));
|
|
731
730
|
}
|
|
732
|
-
function J(u, m,
|
|
733
|
-
var
|
|
734
|
-
r(`Track subscribed: ${u.kind} from ${
|
|
731
|
+
function J(u, m, w) {
|
|
732
|
+
var b, P, q;
|
|
733
|
+
r(`Track subscribed: ${u.kind} from ${w.identity}`);
|
|
735
734
|
const S = u.mediaStreamTrack;
|
|
736
735
|
if (!S) {
|
|
737
736
|
r(`No mediaStreamTrack available for ${u.kind}`);
|
|
738
737
|
return;
|
|
739
738
|
}
|
|
740
|
-
N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (M =
|
|
739
|
+
N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (M = un(
|
|
741
740
|
() => u.getRTCStatsReport(),
|
|
742
741
|
({ sttLatency: V, serviceLatency: ie }) => {
|
|
743
742
|
var Oe, We, He;
|
|
744
|
-
const
|
|
745
|
-
let
|
|
743
|
+
const we = oe.get(!0);
|
|
744
|
+
let ye = 0;
|
|
746
745
|
if (V) {
|
|
747
746
|
const qe = ((We = (Oe = I == null ? void 0 : I.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
|
|
748
|
-
|
|
747
|
+
ye = qe > 0 ? Math.round(qe * 1e3) : 0;
|
|
749
748
|
}
|
|
750
|
-
const fe =
|
|
749
|
+
const fe = we > 0 ? we + (V ?? 0) + ye : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
|
|
751
750
|
(He = t.onFirstAudioDetected) == null || He.call(t, { latency: fe, networkLatency: ce });
|
|
752
751
|
}
|
|
753
|
-
)), u.kind === "video" && ((
|
|
752
|
+
)), u.kind === "video" && ((b = t.onStreamReady) == null || b.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, x.Connected, "livekit:track-subscribed")), I = yt(
|
|
754
753
|
() => u.getRTCStatsReport(),
|
|
755
|
-
() =>
|
|
754
|
+
() => p,
|
|
756
755
|
Vt,
|
|
757
756
|
(V, ie) => {
|
|
758
|
-
r(`Video state change: ${V}`), V ===
|
|
757
|
+
r(`Video state change: ${V}`), V === k.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), _()) : V === k.Stop && L(ie);
|
|
759
758
|
}
|
|
760
759
|
), I.start());
|
|
761
760
|
}
|
|
762
|
-
function
|
|
763
|
-
r(`Track unsubscribed: ${u.kind} from ${
|
|
761
|
+
function y(u, m, w) {
|
|
762
|
+
r(`Track unsubscribed: ${u.kind} from ${w.identity}`), u.kind === "audio" && (M == null || M.destroy(), M = null), u.kind === "video" && (L(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
|
|
764
763
|
}
|
|
765
|
-
function
|
|
764
|
+
function v(u, m) {
|
|
766
765
|
var S;
|
|
767
|
-
const
|
|
768
|
-
|
|
766
|
+
const w = on[u];
|
|
767
|
+
w && ((S = t.onMessage) == null || S.call(t, w, { event: w, ...m }));
|
|
769
768
|
}
|
|
770
|
-
function
|
|
771
|
-
var
|
|
772
|
-
if (u ===
|
|
773
|
-
te = W.ToolActive, (
|
|
769
|
+
function E(u, m) {
|
|
770
|
+
var w, S, b, P;
|
|
771
|
+
if (u === R.ToolCallStarted) {
|
|
772
|
+
te = W.ToolActive, (w = t.onAgentActivityStateChange) == null || w.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, R.ToolCallStarted, m);
|
|
774
773
|
return;
|
|
775
774
|
}
|
|
776
|
-
if (u ===
|
|
777
|
-
(
|
|
775
|
+
if (u === R.ToolCallDone) {
|
|
776
|
+
(b = t.onToolEvent) == null || b.call(t, R.ToolCallDone, m);
|
|
778
777
|
return;
|
|
779
778
|
}
|
|
780
|
-
u ===
|
|
779
|
+
u === R.ToolCallError && ((P = t.onToolEvent) == null || P.call(t, R.ToolCallError, m));
|
|
781
780
|
}
|
|
782
781
|
function j(u, m) {
|
|
783
|
-
var
|
|
784
|
-
if (ne = ((
|
|
785
|
-
te = W.Talking, (
|
|
786
|
-
sttLatency: (
|
|
782
|
+
var w, S, b, P, q;
|
|
783
|
+
if (ne = ((w = m.metadata) == null ? void 0 : w.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === R.StreamVideoCreated) {
|
|
784
|
+
te = W.Talking, (b = t.onAgentActivityStateChange) == null || b.call(t, W.Talking), M == null || M.arm({
|
|
785
|
+
sttLatency: (P = m == null ? void 0 : m.stt) == null ? void 0 : P.latency,
|
|
787
786
|
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
788
787
|
});
|
|
789
788
|
return;
|
|
@@ -791,85 +790,85 @@ async function yn(e, n, i) {
|
|
|
791
790
|
ne && (te = W.Idle, (q = t.onAgentActivityStateChange) == null || q.call(t, W.Idle));
|
|
792
791
|
}
|
|
793
792
|
function G(u, m) {
|
|
794
|
-
var
|
|
795
|
-
const
|
|
796
|
-
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (
|
|
793
|
+
var P, q, V, ie;
|
|
794
|
+
const w = ((q = (P = I == null ? void 0 : I.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = w > 0 ? Math.round(w / 2 * 1e3) : 0, b = { ...m, downstreamNetworkLatency: S };
|
|
795
|
+
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (b.sentiment = {
|
|
797
796
|
id: m.metadata.sentiment.id,
|
|
798
797
|
name: m.metadata.sentiment.sentiment
|
|
799
|
-
}), (ie = t.onMessage) == null || ie.call(t, u,
|
|
798
|
+
}), (ie = t.onMessage) == null || ie.call(t, u, b), j(u, m);
|
|
800
799
|
}
|
|
801
|
-
function
|
|
802
|
-
var
|
|
803
|
-
(
|
|
800
|
+
function ge(u, m) {
|
|
801
|
+
var w;
|
|
802
|
+
(w = t.onMessage) == null || w.call(t, X.Transcribe, { event: X.Transcribe, ...m }), queueMicrotask(() => {
|
|
804
803
|
var S;
|
|
805
804
|
(S = t.onAgentActivityStateChange) == null || S.call(t, W.Loading);
|
|
806
805
|
});
|
|
807
806
|
}
|
|
808
807
|
const Z = {
|
|
809
|
-
[
|
|
810
|
-
[
|
|
811
|
-
[
|
|
812
|
-
[
|
|
813
|
-
[
|
|
814
|
-
[
|
|
815
|
-
[
|
|
816
|
-
[
|
|
817
|
-
[
|
|
818
|
-
[
|
|
808
|
+
[R.ChatAnswer]: v,
|
|
809
|
+
[R.ChatPartial]: v,
|
|
810
|
+
[R.ToolCallStarted]: E,
|
|
811
|
+
[R.ToolCallDone]: E,
|
|
812
|
+
[R.ToolCallError]: E,
|
|
813
|
+
[R.StreamVideoCreated]: G,
|
|
814
|
+
[R.StreamVideoDone]: G,
|
|
815
|
+
[R.StreamVideoError]: G,
|
|
816
|
+
[R.StreamVideoRejected]: G,
|
|
817
|
+
[R.ChatAudioTranscribed]: ge
|
|
819
818
|
};
|
|
820
|
-
function z(u, m,
|
|
821
|
-
const
|
|
819
|
+
function z(u, m, w, S) {
|
|
820
|
+
const b = new TextDecoder().decode(u);
|
|
822
821
|
try {
|
|
823
|
-
const
|
|
824
|
-
if (r("Data received:", { subject: q, data:
|
|
822
|
+
const P = JSON.parse(b), q = S || P.subject;
|
|
823
|
+
if (r("Data received:", { subject: q, data: P }), !q) return;
|
|
825
824
|
const V = Z[q];
|
|
826
|
-
V == null || V(q,
|
|
827
|
-
} catch (
|
|
828
|
-
r("Failed to parse data channel message:",
|
|
825
|
+
V == null || V(q, P);
|
|
826
|
+
} catch (P) {
|
|
827
|
+
r("Failed to parse data channel message:", P);
|
|
829
828
|
}
|
|
830
829
|
}
|
|
831
830
|
function ee(u) {
|
|
832
831
|
var m;
|
|
833
|
-
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
832
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Se), { sessionId: K });
|
|
834
833
|
}
|
|
835
834
|
function De(u) {
|
|
836
835
|
var m;
|
|
837
|
-
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
836
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Se), { sessionId: K });
|
|
838
837
|
}
|
|
839
|
-
function le(u, m,
|
|
840
|
-
r("Track subscription failed:", { trackSid: u, participant: m, reason:
|
|
838
|
+
function le(u, m, w) {
|
|
839
|
+
r("Track subscription failed:", { trackSid: u, participant: m, reason: w });
|
|
841
840
|
}
|
|
842
|
-
function ke(u, m,
|
|
843
|
-
for (const [S,
|
|
844
|
-
if (
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
847
|
-
return
|
|
841
|
+
function ke(u, m, w) {
|
|
842
|
+
for (const [S, b] of w)
|
|
843
|
+
if (b.source === m && b.track) {
|
|
844
|
+
const P = b.track.mediaStreamTrack;
|
|
845
|
+
if (P === u || (P == null ? void 0 : P.id) === u.id)
|
|
846
|
+
return b;
|
|
848
847
|
}
|
|
849
848
|
return null;
|
|
850
849
|
}
|
|
851
|
-
async function
|
|
852
|
-
var
|
|
853
|
-
if (!
|
|
850
|
+
async function he(u, m, w, S, b, P) {
|
|
851
|
+
var we, ye, fe;
|
|
852
|
+
if (!p || !l)
|
|
854
853
|
throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
|
|
855
854
|
if (u.isPublishing) {
|
|
856
855
|
r(`${S} publish already in progress, skipping`);
|
|
857
856
|
return;
|
|
858
857
|
}
|
|
859
|
-
const q =
|
|
858
|
+
const q = w(m);
|
|
860
859
|
if (q.length === 0)
|
|
861
860
|
throw new Error(`No ${S} track found in the provided MediaStream`);
|
|
862
|
-
const V = q[0], ie = ke(V, S,
|
|
861
|
+
const V = q[0], ie = ke(V, S, b());
|
|
863
862
|
if (ie) {
|
|
864
863
|
r(`${S} track is already published, skipping`, {
|
|
865
864
|
trackId: V.id,
|
|
866
|
-
publishedTrackId: (
|
|
865
|
+
publishedTrackId: (ye = (we = ie.track) == null ? void 0 : we.mediaStreamTrack) == null ? void 0 : ye.id
|
|
867
866
|
}), u.publication = ie;
|
|
868
867
|
return;
|
|
869
868
|
}
|
|
870
869
|
if ((fe = u.publication) != null && fe.track) {
|
|
871
870
|
const ce = u.publication.track.mediaStreamTrack;
|
|
872
|
-
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await
|
|
871
|
+
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await P());
|
|
873
872
|
}
|
|
874
873
|
r(`Publishing ${S} track from provided MediaStream`, { trackId: V.id }), u.isPublishing = !0;
|
|
875
874
|
try {
|
|
@@ -880,69 +879,69 @@ async function yn(e, n, i) {
|
|
|
880
879
|
u.isPublishing = !1;
|
|
881
880
|
}
|
|
882
881
|
}
|
|
883
|
-
async function
|
|
882
|
+
async function pe(u, m) {
|
|
884
883
|
if (!(!u.publication || !u.publication.track))
|
|
885
884
|
try {
|
|
886
885
|
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${m} track unpublished`));
|
|
887
|
-
} catch (
|
|
888
|
-
r(`Error unpublishing ${m} track:`,
|
|
886
|
+
} catch (w) {
|
|
887
|
+
r(`Error unpublishing ${m} track:`, w);
|
|
889
888
|
} finally {
|
|
890
889
|
u.publication = null;
|
|
891
890
|
}
|
|
892
891
|
}
|
|
893
892
|
async function vt(u) {
|
|
894
|
-
return
|
|
893
|
+
return he(
|
|
895
894
|
B,
|
|
896
895
|
u,
|
|
897
896
|
(m) => m.getAudioTracks(),
|
|
898
897
|
c.Source.Microphone,
|
|
899
898
|
() => l.localParticipant.audioTrackPublications,
|
|
900
|
-
|
|
899
|
+
_e
|
|
901
900
|
);
|
|
902
901
|
}
|
|
903
|
-
async function
|
|
904
|
-
return
|
|
902
|
+
async function _e() {
|
|
903
|
+
return pe(B, "Microphone");
|
|
905
904
|
}
|
|
906
905
|
async function Ct(u) {
|
|
907
|
-
return
|
|
906
|
+
return he(
|
|
908
907
|
F,
|
|
909
908
|
u,
|
|
910
909
|
(m) => m.getVideoTracks(),
|
|
911
910
|
c.Source.Camera,
|
|
912
911
|
() => l.localParticipant.videoTrackPublications,
|
|
913
|
-
|
|
912
|
+
Ae
|
|
914
913
|
);
|
|
915
914
|
}
|
|
916
|
-
async function
|
|
917
|
-
return
|
|
915
|
+
async function Ae() {
|
|
916
|
+
return pe(F, "Camera");
|
|
918
917
|
}
|
|
919
918
|
function St() {
|
|
920
919
|
N && (N.getTracks().forEach((u) => u.stop()), N = null);
|
|
921
920
|
}
|
|
922
921
|
async function be(u, m) {
|
|
923
|
-
var
|
|
924
|
-
if (!
|
|
925
|
-
r("Room is not connected for sending messages"), (
|
|
922
|
+
var w, S;
|
|
923
|
+
if (!p || !l) {
|
|
924
|
+
r("Room is not connected for sending messages"), (w = t.onError) == null || w.call(t, new Error(Se), {
|
|
926
925
|
sessionId: K
|
|
927
926
|
});
|
|
928
927
|
return;
|
|
929
928
|
}
|
|
930
929
|
try {
|
|
931
930
|
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
932
|
-
} catch (
|
|
933
|
-
r("Failed to send message:",
|
|
931
|
+
} catch (b) {
|
|
932
|
+
r("Failed to send message:", b), (S = t.onError) == null || S.call(t, new Error(Se), { sessionId: K });
|
|
934
933
|
}
|
|
935
934
|
}
|
|
936
|
-
async function
|
|
935
|
+
async function Tt(u) {
|
|
937
936
|
var m;
|
|
938
937
|
try {
|
|
939
938
|
const S = JSON.parse(u).topic;
|
|
940
939
|
return be("", S);
|
|
941
|
-
} catch (
|
|
942
|
-
r("Failed to send data channel message:",
|
|
940
|
+
} catch (w) {
|
|
941
|
+
r("Failed to send data channel message:", w), (m = t.onError) == null || m.call(t, new Error(Se), { sessionId: K });
|
|
943
942
|
}
|
|
944
943
|
}
|
|
945
|
-
function
|
|
944
|
+
function Rt(u) {
|
|
946
945
|
return be(
|
|
947
946
|
u,
|
|
948
947
|
"lk.chat"
|
|
@@ -950,8 +949,8 @@ async function yn(e, n, i) {
|
|
|
950
949
|
);
|
|
951
950
|
}
|
|
952
951
|
async function Le(u) {
|
|
953
|
-
var m,
|
|
954
|
-
U && (clearTimeout(U), U = null), M == null || M.destroy(), M = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([
|
|
952
|
+
var m, w;
|
|
953
|
+
U && (clearTimeout(U), U = null), M == null || M.destroy(), M = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([_e(), Ae()]), await l.disconnect()), St(), p = !1, Q = !1, (w = t.onAgentActivityStateChange) == null || w.call(t, W.Idle), te = W.Idle;
|
|
955
954
|
}
|
|
956
955
|
return {
|
|
957
956
|
speak(u) {
|
|
@@ -973,28 +972,28 @@ async function yn(e, n, i) {
|
|
|
973
972
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
974
973
|
r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, x.Connecting, "user:reconnect");
|
|
975
974
|
try {
|
|
976
|
-
if (await l.connect(re, H), r("Room reconnected"),
|
|
975
|
+
if (await l.connect(re, H), r("Room reconnected"), p = !0, l.remoteParticipants.size === 0) {
|
|
977
976
|
if (r("Waiting for agent to join..."), !await new Promise((S) => {
|
|
978
|
-
const
|
|
979
|
-
l == null || l.off(a.ParticipantConnected,
|
|
980
|
-
}, 5e3),
|
|
981
|
-
clearTimeout(
|
|
977
|
+
const b = setTimeout(() => {
|
|
978
|
+
l == null || l.off(a.ParticipantConnected, P), S(!1);
|
|
979
|
+
}, 5e3), P = () => {
|
|
980
|
+
clearTimeout(b), l == null || l.off(a.ParticipantConnected, P), S(!0);
|
|
982
981
|
};
|
|
983
|
-
l == null || l.on(a.ParticipantConnected,
|
|
982
|
+
l == null || l.on(a.ParticipantConnected, P);
|
|
984
983
|
}))
|
|
985
984
|
throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
|
|
986
985
|
r("Agent joined, reconnection successful");
|
|
987
986
|
}
|
|
988
|
-
} catch (
|
|
989
|
-
throw r("Failed to reconnect:",
|
|
987
|
+
} catch (w) {
|
|
988
|
+
throw r("Failed to reconnect:", w), (m = t.onConnectionStateChange) == null || m.call(t, x.Fail, "user:reconnect-failed"), w;
|
|
990
989
|
}
|
|
991
990
|
},
|
|
992
|
-
sendDataChannelMessage:
|
|
993
|
-
sendTextMessage:
|
|
991
|
+
sendDataChannelMessage: Tt,
|
|
992
|
+
sendTextMessage: Rt,
|
|
994
993
|
publishMicrophoneStream: vt,
|
|
995
|
-
unpublishMicrophoneStream:
|
|
994
|
+
unpublishMicrophoneStream: _e,
|
|
996
995
|
publishCameraStream: Ct,
|
|
997
|
-
unpublishCameraStream:
|
|
996
|
+
unpublishCameraStream: Ae,
|
|
998
997
|
registerRpcMethod(u, m) {
|
|
999
998
|
l == null || l.registerRpcMethod(u, m);
|
|
1000
999
|
},
|
|
@@ -1003,18 +1002,18 @@ async function yn(e, n, i) {
|
|
|
1003
1002
|
},
|
|
1004
1003
|
sessionId: K,
|
|
1005
1004
|
streamId: K,
|
|
1006
|
-
streamType:
|
|
1005
|
+
streamType: D,
|
|
1007
1006
|
interruptAvailable: de,
|
|
1008
1007
|
isInterruptible: ne
|
|
1009
1008
|
};
|
|
1010
1009
|
}
|
|
1011
|
-
const
|
|
1010
|
+
const yn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1012
1011
|
__proto__: null,
|
|
1013
1012
|
DataChannelTopic: Ue,
|
|
1014
|
-
createLiveKitStreamingManager:
|
|
1013
|
+
createLiveKitStreamingManager: wn,
|
|
1015
1014
|
handleInitError: Be
|
|
1016
1015
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1017
|
-
function
|
|
1016
|
+
function vn(e, n, i) {
|
|
1018
1017
|
if (!e)
|
|
1019
1018
|
throw new Error("Please connect to the agent first");
|
|
1020
1019
|
if (!e.interruptAvailable)
|
|
@@ -1024,15 +1023,15 @@ function Cn(e, n, i) {
|
|
|
1024
1023
|
if (!i)
|
|
1025
1024
|
throw new Error("No active video to interrupt");
|
|
1026
1025
|
}
|
|
1027
|
-
async function
|
|
1026
|
+
async function Cn(e, n) {
|
|
1028
1027
|
const i = {
|
|
1029
|
-
type:
|
|
1028
|
+
type: R.StreamInterrupt,
|
|
1030
1029
|
videoId: n,
|
|
1031
1030
|
timestamp: Date.now()
|
|
1032
1031
|
};
|
|
1033
1032
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
1034
1033
|
}
|
|
1035
|
-
async function
|
|
1034
|
+
async function Sn(e) {
|
|
1036
1035
|
const n = {
|
|
1037
1036
|
topic: Ue.Interrupt
|
|
1038
1037
|
};
|
|
@@ -1048,7 +1047,7 @@ function Tn(e) {
|
|
|
1048
1047
|
};
|
|
1049
1048
|
});
|
|
1050
1049
|
}
|
|
1051
|
-
async function
|
|
1050
|
+
async function Rn(e) {
|
|
1052
1051
|
const { retries: n = 1 } = e;
|
|
1053
1052
|
let i = null;
|
|
1054
1053
|
for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
|
|
@@ -1061,8 +1060,8 @@ async function En(e) {
|
|
|
1061
1060
|
}
|
|
1062
1061
|
return i;
|
|
1063
1062
|
}
|
|
1064
|
-
async function
|
|
1065
|
-
const s = i != null && i.onMessage ? [i.onMessage] : [], a = await
|
|
1063
|
+
async function En(e, n, i, r) {
|
|
1064
|
+
const s = i != null && i.onMessage ? [i.onMessage] : [], a = await Rn({
|
|
1066
1065
|
auth: e,
|
|
1067
1066
|
host: n,
|
|
1068
1067
|
externalId: r,
|
|
@@ -1083,7 +1082,7 @@ async function kn(e, n, i, r) {
|
|
|
1083
1082
|
subscribeToEvents: (o) => s.push(o)
|
|
1084
1083
|
};
|
|
1085
1084
|
}
|
|
1086
|
-
function
|
|
1085
|
+
function kn(e) {
|
|
1087
1086
|
if (e.answer !== void 0)
|
|
1088
1087
|
return e.answer;
|
|
1089
1088
|
let n = 0, i = "";
|
|
@@ -1091,7 +1090,7 @@ function Mn(e) {
|
|
|
1091
1090
|
i += e[n++];
|
|
1092
1091
|
return i;
|
|
1093
1092
|
}
|
|
1094
|
-
function
|
|
1093
|
+
function Mn(e, n, i) {
|
|
1095
1094
|
if (!e.content)
|
|
1096
1095
|
return;
|
|
1097
1096
|
const r = n.messages[n.messages.length - 1];
|
|
@@ -1100,15 +1099,15 @@ function In(e, n, i) {
|
|
|
1100
1099
|
id: e.id || `user-${Date.now()}`,
|
|
1101
1100
|
role: e.role,
|
|
1102
1101
|
content: e.content,
|
|
1103
|
-
parts:
|
|
1102
|
+
parts: Re(e.content),
|
|
1104
1103
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1105
1104
|
transcribed: !0
|
|
1106
1105
|
};
|
|
1107
1106
|
n.messages.push(s), i == null || i([...n.messages], "user");
|
|
1108
1107
|
}
|
|
1109
|
-
function
|
|
1108
|
+
function In(e, n, i, r, s, a) {
|
|
1110
1109
|
if (e === X.Transcribe && n.content) {
|
|
1111
|
-
|
|
1110
|
+
Mn(n, r, s);
|
|
1112
1111
|
return;
|
|
1113
1112
|
}
|
|
1114
1113
|
if (!(e === X.Partial || e === X.Answer))
|
|
@@ -1129,10 +1128,10 @@ function Dn(e, n, i, r, s, a) {
|
|
|
1129
1128
|
return;
|
|
1130
1129
|
const { content: d, sequence: h } = n;
|
|
1131
1130
|
e === X.Partial ? i[h] = d : i.answer = d;
|
|
1132
|
-
const g =
|
|
1133
|
-
(t.content !== g || e === X.Answer) && (t.content = g, t.parts =
|
|
1131
|
+
const g = kn(i);
|
|
1132
|
+
(t.content !== g || e === X.Answer) && (t.content = g, t.parts = Re(g), s == null || s([...r.messages], e));
|
|
1134
1133
|
}
|
|
1135
|
-
function
|
|
1134
|
+
function Dn(e, n, i, r, s) {
|
|
1136
1135
|
let a = {};
|
|
1137
1136
|
const o = () => a = {};
|
|
1138
1137
|
let c = "answer";
|
|
@@ -1145,26 +1144,26 @@ function An(e, n, i, r, s) {
|
|
|
1145
1144
|
onMessage: (d, h) => {
|
|
1146
1145
|
var g, l;
|
|
1147
1146
|
if ("content" in h) {
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1147
|
+
const p = d === R.ChatAnswer ? X.Answer : d === R.ChatAudioTranscribed ? X.Transcribe : d;
|
|
1148
|
+
In(p, h, a, n, t, o), p === X.Answer && e.track("agent-message-received", {
|
|
1150
1149
|
content: h.content,
|
|
1151
1150
|
messages: n.messages.length,
|
|
1152
1151
|
mode: n.chatMode
|
|
1153
1152
|
});
|
|
1154
1153
|
} else {
|
|
1155
|
-
const
|
|
1156
|
-
if (d = d, d ===
|
|
1154
|
+
const p = R, D = [p.StreamVideoDone, p.StreamVideoError, p.StreamVideoRejected], N = [p.StreamFailed, p.StreamVideoError, p.StreamVideoRejected], B = Zt(h, r, { mode: n.chatMode });
|
|
1155
|
+
if (d = d, d === p.StreamVideoCreated && (e.linkTrack("agent-video", B, p.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1157
1156
|
const F = n.messages[n.messages.length - 1];
|
|
1158
1157
|
if ((F == null ? void 0 : F.role) === "assistant") {
|
|
1159
1158
|
const I = { ...F, sentiment: h.sentiment };
|
|
1160
1159
|
n.messages[n.messages.length - 1] = I, t == null || t([...n.messages], c);
|
|
1161
1160
|
}
|
|
1162
1161
|
}
|
|
1163
|
-
if (
|
|
1162
|
+
if (D.includes(d)) {
|
|
1164
1163
|
const F = d.split("/")[1];
|
|
1165
1164
|
N.includes(d) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, d, ["done"]);
|
|
1166
1165
|
}
|
|
1167
|
-
N.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: h })), h.event ===
|
|
1166
|
+
N.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: h })), h.event === p.StreamDone && s();
|
|
1168
1167
|
}
|
|
1169
1168
|
}
|
|
1170
1169
|
};
|
|
@@ -1206,7 +1205,7 @@ function _n(e, n, i, r) {
|
|
|
1206
1205
|
}
|
|
1207
1206
|
};
|
|
1208
1207
|
}
|
|
1209
|
-
const
|
|
1208
|
+
const An = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1210
1209
|
function at(e) {
|
|
1211
1210
|
switch (e) {
|
|
1212
1211
|
case "connected":
|
|
@@ -1227,7 +1226,7 @@ function at(e) {
|
|
|
1227
1226
|
return x.New;
|
|
1228
1227
|
}
|
|
1229
1228
|
}
|
|
1230
|
-
const
|
|
1229
|
+
const bn = (e) => (n) => {
|
|
1231
1230
|
const [i, r = ""] = n.split(/:(.+)/);
|
|
1232
1231
|
try {
|
|
1233
1232
|
const s = JSON.parse(r);
|
|
@@ -1236,16 +1235,16 @@ const Ln = (e) => (n) => {
|
|
|
1236
1235
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: s }), { subject: i, data: r };
|
|
1237
1236
|
}
|
|
1238
1237
|
};
|
|
1239
|
-
function
|
|
1238
|
+
function Ln({
|
|
1240
1239
|
statsSignal: e,
|
|
1241
1240
|
dataChannelSignal: n,
|
|
1242
1241
|
onVideoStateChange: i,
|
|
1243
1242
|
report: r,
|
|
1244
1243
|
log: s
|
|
1245
1244
|
}) {
|
|
1246
|
-
e ===
|
|
1245
|
+
e === k.Start && n === k.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(k.Start)) : e === k.Stop && n === k.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(k.Stop, r));
|
|
1247
1246
|
}
|
|
1248
|
-
function
|
|
1247
|
+
function Pn({
|
|
1249
1248
|
statsSignal: e,
|
|
1250
1249
|
dataChannelSignal: n,
|
|
1251
1250
|
onVideoStateChange: i,
|
|
@@ -1253,7 +1252,7 @@ function xn({
|
|
|
1253
1252
|
report: s,
|
|
1254
1253
|
log: a
|
|
1255
1254
|
}) {
|
|
1256
|
-
e ===
|
|
1255
|
+
e === k.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(k.Start)) : e === k.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(k.Stop, s)), n === k.Start ? r == null || r(W.Talking) : n === k.Stop && (r == null || r(W.Idle));
|
|
1257
1256
|
}
|
|
1258
1257
|
function ot({
|
|
1259
1258
|
statsSignal: e,
|
|
@@ -1264,7 +1263,7 @@ function ot({
|
|
|
1264
1263
|
report: a,
|
|
1265
1264
|
log: o
|
|
1266
1265
|
}) {
|
|
1267
|
-
s === se.Legacy ?
|
|
1266
|
+
s === se.Legacy ? Ln({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: o }) : s === se.Fluent && Pn({
|
|
1268
1267
|
statsSignal: e,
|
|
1269
1268
|
dataChannelSignal: n,
|
|
1270
1269
|
onVideoStateChange: i,
|
|
@@ -1273,11 +1272,11 @@ function ot({
|
|
|
1273
1272
|
log: o
|
|
1274
1273
|
});
|
|
1275
1274
|
}
|
|
1276
|
-
async function
|
|
1275
|
+
async function xn(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, c) {
|
|
1277
1276
|
var J;
|
|
1278
|
-
const t = pt(i, "WebRTCStreamingManager"), d =
|
|
1279
|
-
let h = !1, g = !1, l =
|
|
1280
|
-
const { startConnection:
|
|
1277
|
+
const t = pt(i, "WebRTCStreamingManager"), d = bn(t);
|
|
1278
|
+
let h = !1, g = !1, l = k.Stop, p = k.Stop;
|
|
1279
|
+
const { startConnection: D, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } = _n(
|
|
1281
1280
|
s,
|
|
1282
1281
|
a,
|
|
1283
1282
|
e,
|
|
@@ -1291,7 +1290,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1291
1290
|
interrupt_enabled: ne
|
|
1292
1291
|
} = await F(n, c);
|
|
1293
1292
|
(J = r.onStreamCreated) == null || J.call(r, { stream_id: M, session_id: U, agent_id: e });
|
|
1294
|
-
const $ = new
|
|
1293
|
+
const $ = new An({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
|
|
1295
1294
|
if (!U)
|
|
1296
1295
|
throw new Error("Could not create session_id");
|
|
1297
1296
|
const H = te ? se.Fluent : se.Legacy;
|
|
@@ -1299,57 +1298,57 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1299
1298
|
"stream-type": H
|
|
1300
1299
|
});
|
|
1301
1300
|
const re = n.stream_warmup && !te, de = () => h, ue = () => {
|
|
1302
|
-
var
|
|
1303
|
-
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (
|
|
1301
|
+
var y;
|
|
1302
|
+
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (y = r.onConnectionStateChange) == null || y.call(r, x.Connected));
|
|
1304
1303
|
}, f = yt(
|
|
1305
1304
|
() => $.getStats(),
|
|
1306
1305
|
de,
|
|
1307
1306
|
ue,
|
|
1308
|
-
(
|
|
1309
|
-
statsSignal:
|
|
1307
|
+
(y, v) => ot({
|
|
1308
|
+
statsSignal: p = y,
|
|
1310
1309
|
dataChannelSignal: H === se.Legacy ? l : void 0,
|
|
1311
1310
|
onVideoStateChange: r.onVideoStateChange,
|
|
1312
1311
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1313
|
-
report:
|
|
1312
|
+
report: v,
|
|
1314
1313
|
streamType: H,
|
|
1315
1314
|
log: t
|
|
1316
1315
|
}),
|
|
1317
|
-
(
|
|
1318
|
-
var
|
|
1319
|
-
return (
|
|
1316
|
+
(y) => {
|
|
1317
|
+
var v;
|
|
1318
|
+
return (v = r.onConnectivityStateChange) == null ? void 0 : v.call(r, y);
|
|
1320
1319
|
}
|
|
1321
1320
|
);
|
|
1322
|
-
f.start(), $.onicecandidate = (
|
|
1323
|
-
var
|
|
1324
|
-
t("peerConnection.onicecandidate",
|
|
1321
|
+
f.start(), $.onicecandidate = (y) => {
|
|
1322
|
+
var v;
|
|
1323
|
+
t("peerConnection.onicecandidate", y);
|
|
1325
1324
|
try {
|
|
1326
|
-
|
|
1325
|
+
y.candidate && y.candidate.sdpMid && y.candidate.sdpMLineIndex !== null ? I(
|
|
1327
1326
|
M,
|
|
1328
1327
|
{
|
|
1329
|
-
candidate:
|
|
1330
|
-
sdpMid:
|
|
1331
|
-
sdpMLineIndex:
|
|
1328
|
+
candidate: y.candidate.candidate,
|
|
1329
|
+
sdpMid: y.candidate.sdpMid,
|
|
1330
|
+
sdpMLineIndex: y.candidate.sdpMLineIndex
|
|
1332
1331
|
},
|
|
1333
1332
|
U,
|
|
1334
1333
|
c
|
|
1335
1334
|
) : I(M, { candidate: null }, U, c);
|
|
1336
|
-
} catch (
|
|
1337
|
-
(
|
|
1335
|
+
} catch (E) {
|
|
1336
|
+
(v = r.onError) == null || v.call(r, E, { streamId: M });
|
|
1338
1337
|
}
|
|
1339
1338
|
}, K.onopen = () => {
|
|
1340
1339
|
g = !0, (!re || h) && ue();
|
|
1341
1340
|
};
|
|
1342
|
-
const C = (
|
|
1343
|
-
var
|
|
1344
|
-
(
|
|
1341
|
+
const C = (y) => {
|
|
1342
|
+
var v;
|
|
1343
|
+
(v = r.onVideoIdChange) == null || v.call(r, y);
|
|
1345
1344
|
};
|
|
1346
|
-
function
|
|
1347
|
-
if (
|
|
1348
|
-
const
|
|
1349
|
-
C(
|
|
1345
|
+
function T(y, v) {
|
|
1346
|
+
if (y === R.StreamStarted && typeof v == "object" && "metadata" in v) {
|
|
1347
|
+
const E = v.metadata;
|
|
1348
|
+
C(E.videoId);
|
|
1350
1349
|
}
|
|
1351
|
-
|
|
1352
|
-
statsSignal: H === se.Legacy ?
|
|
1350
|
+
y === R.StreamDone && C(null), l = y === R.StreamStarted ? k.Start : k.Stop, ot({
|
|
1351
|
+
statsSignal: H === se.Legacy ? p : void 0,
|
|
1353
1352
|
dataChannelSignal: l,
|
|
1354
1353
|
onVideoStateChange: r.onVideoStateChange,
|
|
1355
1354
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
@@ -1357,76 +1356,76 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1357
1356
|
log: t
|
|
1358
1357
|
});
|
|
1359
1358
|
}
|
|
1360
|
-
function A(
|
|
1359
|
+
function A(y, v) {
|
|
1361
1360
|
var j;
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1361
|
+
const E = typeof v == "string" ? v : v == null ? void 0 : v.metadata;
|
|
1362
|
+
E && o.enrich({ streamMetadata: E }), (j = r.onStreamReady) == null || j.call(r);
|
|
1364
1363
|
}
|
|
1365
|
-
const
|
|
1366
|
-
[
|
|
1367
|
-
[
|
|
1368
|
-
[
|
|
1364
|
+
const _ = {
|
|
1365
|
+
[R.StreamStarted]: T,
|
|
1366
|
+
[R.StreamDone]: T,
|
|
1367
|
+
[R.StreamReady]: A
|
|
1369
1368
|
};
|
|
1370
|
-
K.onmessage = (
|
|
1369
|
+
K.onmessage = (y) => {
|
|
1371
1370
|
var j;
|
|
1372
|
-
const { subject:
|
|
1373
|
-
(j =
|
|
1371
|
+
const { subject: v, data: E } = d(y.data);
|
|
1372
|
+
(j = _[v]) == null || j.call(_, v, E);
|
|
1374
1373
|
}, $.oniceconnectionstatechange = () => {
|
|
1375
|
-
var
|
|
1374
|
+
var v;
|
|
1376
1375
|
t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
}, $.ontrack = (
|
|
1380
|
-
var
|
|
1381
|
-
t("peerConnection.ontrack",
|
|
1376
|
+
const y = at($.iceConnectionState);
|
|
1377
|
+
y !== x.Connected && ((v = r.onConnectionStateChange) == null || v.call(r, y));
|
|
1378
|
+
}, $.ontrack = (y) => {
|
|
1379
|
+
var v;
|
|
1380
|
+
t("peerConnection.ontrack", y), t("CALLBACK: onSrcObjectReady"), (v = r.onSrcObjectReady) == null || v.call(r, y.streams[0]);
|
|
1382
1381
|
}, await $.setRemoteDescription(Y), t("set remote description OK");
|
|
1383
|
-
const
|
|
1384
|
-
return t("create answer OK"), await $.setLocalDescription(
|
|
1382
|
+
const L = await $.createAnswer();
|
|
1383
|
+
return t("create answer OK"), await $.setLocalDescription(L), t("set local description OK"), await D(M, L, U, c), t("start connection OK"), {
|
|
1385
1384
|
/**
|
|
1386
1385
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1387
1386
|
* @param payload
|
|
1388
1387
|
*/
|
|
1389
|
-
speak(
|
|
1390
|
-
return N(M, U,
|
|
1388
|
+
speak(y) {
|
|
1389
|
+
return N(M, U, y);
|
|
1391
1390
|
},
|
|
1392
1391
|
/**
|
|
1393
1392
|
* Method to close RTC connection
|
|
1394
1393
|
*/
|
|
1395
1394
|
async disconnect() {
|
|
1396
|
-
var
|
|
1395
|
+
var y;
|
|
1397
1396
|
if (M) {
|
|
1398
|
-
const
|
|
1397
|
+
const v = at($.iceConnectionState);
|
|
1399
1398
|
if ($) {
|
|
1400
|
-
if (
|
|
1399
|
+
if (v === x.New) {
|
|
1401
1400
|
f.stop();
|
|
1402
1401
|
return;
|
|
1403
1402
|
}
|
|
1404
1403
|
$.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
|
|
1405
1404
|
}
|
|
1406
1405
|
try {
|
|
1407
|
-
|
|
1406
|
+
v === x.Connected && await B(M, U).catch((E) => {
|
|
1408
1407
|
});
|
|
1409
|
-
} catch (
|
|
1410
|
-
t("Error on close stream connection",
|
|
1408
|
+
} catch (E) {
|
|
1409
|
+
t("Error on close stream connection", E);
|
|
1411
1410
|
}
|
|
1412
|
-
(
|
|
1411
|
+
(y = r.onAgentActivityStateChange) == null || y.call(r, W.Idle), f.stop();
|
|
1413
1412
|
}
|
|
1414
1413
|
},
|
|
1415
1414
|
/**
|
|
1416
1415
|
* Method to send data channel messages to the server
|
|
1417
1416
|
*/
|
|
1418
|
-
sendDataChannelMessage(
|
|
1419
|
-
var
|
|
1417
|
+
sendDataChannelMessage(y) {
|
|
1418
|
+
var v, E;
|
|
1420
1419
|
if (!h || K.readyState !== "open") {
|
|
1421
|
-
t("Data channel is not ready for sending messages"), (
|
|
1420
|
+
t("Data channel is not ready for sending messages"), (v = r.onError) == null || v.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1422
1421
|
streamId: M
|
|
1423
1422
|
});
|
|
1424
1423
|
return;
|
|
1425
1424
|
}
|
|
1426
1425
|
try {
|
|
1427
|
-
K.send(
|
|
1426
|
+
K.send(y);
|
|
1428
1427
|
} catch (j) {
|
|
1429
|
-
t("Error sending data channel message", j), (
|
|
1428
|
+
t("Error sending data channel message", j), (E = r.onError) == null || E.call(r, j, { streamId: M });
|
|
1430
1429
|
}
|
|
1431
1430
|
},
|
|
1432
1431
|
/**
|
|
@@ -1443,18 +1442,18 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1443
1442
|
};
|
|
1444
1443
|
}
|
|
1445
1444
|
var Fe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Fe || {});
|
|
1446
|
-
async function
|
|
1445
|
+
async function $n(e, n, i, r) {
|
|
1447
1446
|
const s = e.id;
|
|
1448
1447
|
switch (n.version) {
|
|
1449
1448
|
case "v1": {
|
|
1450
1449
|
const { version: a, ...o } = n;
|
|
1451
|
-
return
|
|
1450
|
+
return xn(s, o, i, r);
|
|
1452
1451
|
}
|
|
1453
1452
|
case "v2": {
|
|
1454
1453
|
const { version: a, ...o } = n;
|
|
1455
1454
|
switch (o.transport.provider) {
|
|
1456
1455
|
case Ne.Livekit:
|
|
1457
|
-
const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() =>
|
|
1456
|
+
const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() => yn);
|
|
1458
1457
|
return c(s, o, i);
|
|
1459
1458
|
default:
|
|
1460
1459
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
@@ -1464,15 +1463,15 @@ async function jn(e, n, i, r) {
|
|
|
1464
1463
|
throw new Error(`Invalid stream version: ${n.version}`);
|
|
1465
1464
|
}
|
|
1466
1465
|
}
|
|
1467
|
-
const
|
|
1468
|
-
function
|
|
1466
|
+
const jn = "cht";
|
|
1467
|
+
function Bn() {
|
|
1469
1468
|
return {
|
|
1470
1469
|
transport: {
|
|
1471
1470
|
provider: Ne.Livekit
|
|
1472
1471
|
}
|
|
1473
1472
|
};
|
|
1474
1473
|
}
|
|
1475
|
-
function
|
|
1474
|
+
function Fn(e) {
|
|
1476
1475
|
var s, a;
|
|
1477
1476
|
const { streamOptions: n } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
|
|
1478
1477
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1485,17 +1484,17 @@ function Nn(e) {
|
|
|
1485
1484
|
fluent: n == null ? void 0 : n.fluent
|
|
1486
1485
|
}, ...i && { end_user_data: i } };
|
|
1487
1486
|
}
|
|
1488
|
-
function
|
|
1489
|
-
return Ke(e.presenter.type) ? { version: Fe.V2, ...
|
|
1487
|
+
function Nn(e, n) {
|
|
1488
|
+
return Ke(e.presenter.type) ? { version: Fe.V2, ...Bn() } : { version: Fe.V1, ...Fn(n) };
|
|
1490
1489
|
}
|
|
1491
|
-
function
|
|
1490
|
+
function Kn(e, n, i) {
|
|
1492
1491
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
1493
1492
|
}
|
|
1494
|
-
function
|
|
1495
|
-
s === se.Fluent ?
|
|
1493
|
+
function zn(e, n, i, r, s) {
|
|
1494
|
+
s === se.Fluent ? Vn(e, n, i, r, s) : Un(e, n, i, r, s);
|
|
1496
1495
|
}
|
|
1497
|
-
function
|
|
1498
|
-
e ===
|
|
1496
|
+
function Vn(e, n, i, r, s) {
|
|
1497
|
+
e === k.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === k.Stop && r.track("stream-session", {
|
|
1499
1498
|
event: "stop",
|
|
1500
1499
|
is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
|
|
1501
1500
|
background: n.presenter.type === "clip" && n.presenter.background,
|
|
@@ -1504,9 +1503,9 @@ function Un(e, n, i, r, s) {
|
|
|
1504
1503
|
});
|
|
1505
1504
|
}
|
|
1506
1505
|
function st(e, n, i, r, s) {
|
|
1507
|
-
e ===
|
|
1508
|
-
|
|
1509
|
-
]) : e ===
|
|
1506
|
+
e === k.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
|
|
1507
|
+
R.StreamVideoCreated
|
|
1508
|
+
]) : e === k.Stop && i.linkTrack(
|
|
1510
1509
|
"agent-video",
|
|
1511
1510
|
{
|
|
1512
1511
|
event: "stop",
|
|
@@ -1515,16 +1514,16 @@ function st(e, n, i, r, s) {
|
|
|
1515
1514
|
"stream-type": r
|
|
1516
1515
|
},
|
|
1517
1516
|
"done",
|
|
1518
|
-
[
|
|
1517
|
+
[R.StreamVideoDone]
|
|
1519
1518
|
);
|
|
1520
1519
|
}
|
|
1521
|
-
function
|
|
1522
|
-
e ===
|
|
1520
|
+
function Un(e, n, i, r, s) {
|
|
1521
|
+
e === k.Start ? r.linkTrack(
|
|
1523
1522
|
"agent-video",
|
|
1524
1523
|
{ event: "start", latency: oe.get(!0), "stream-type": s },
|
|
1525
1524
|
"start",
|
|
1526
|
-
[
|
|
1527
|
-
) : e ===
|
|
1525
|
+
[R.StreamVideoCreated]
|
|
1526
|
+
) : e === k.Stop && r.linkTrack(
|
|
1528
1527
|
"agent-video",
|
|
1529
1528
|
{
|
|
1530
1529
|
event: "stop",
|
|
@@ -1534,20 +1533,37 @@ function Jn(e, n, i, r, s) {
|
|
|
1534
1533
|
...i
|
|
1535
1534
|
},
|
|
1536
1535
|
"done",
|
|
1537
|
-
[
|
|
1536
|
+
[R.StreamVideoDone]
|
|
1538
1537
|
);
|
|
1539
1538
|
}
|
|
1539
|
+
function Jn(e, n, i) {
|
|
1540
|
+
const r = {
|
|
1541
|
+
call_id: n.call_id,
|
|
1542
|
+
name: n.name
|
|
1543
|
+
};
|
|
1544
|
+
if (e === R.ToolCallStarted) {
|
|
1545
|
+
i.track("agent-tool-call", { ...r, event: "started" });
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
const s = n;
|
|
1549
|
+
i.track("agent-tool-call", {
|
|
1550
|
+
...r,
|
|
1551
|
+
event: e === R.ToolCallDone ? "done" : "error",
|
|
1552
|
+
duration_ms: s.duration_ms,
|
|
1553
|
+
extra_keys: s.extra ? Object.keys(s.extra).length : 0
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1540
1556
|
function ct(e, n, i, r) {
|
|
1541
1557
|
return oe.reset(), nt.update(), new Promise(async (s, a) => {
|
|
1542
1558
|
try {
|
|
1543
1559
|
let o, c = !1;
|
|
1544
|
-
const t =
|
|
1560
|
+
const t = Nn(e, n);
|
|
1545
1561
|
i.enrich({
|
|
1546
1562
|
"stream-version": t.version.toString()
|
|
1547
1563
|
});
|
|
1548
1564
|
let d = null;
|
|
1549
1565
|
const h = e.presenter.type === "expressive";
|
|
1550
|
-
o = await
|
|
1566
|
+
o = await $n(
|
|
1551
1567
|
e,
|
|
1552
1568
|
t,
|
|
1553
1569
|
{
|
|
@@ -1556,12 +1572,12 @@ function ct(e, n, i, r) {
|
|
|
1556
1572
|
callbacks: {
|
|
1557
1573
|
...n.callbacks,
|
|
1558
1574
|
onConnectionStateChange: (g, l) => {
|
|
1559
|
-
var
|
|
1560
|
-
(
|
|
1575
|
+
var p, D;
|
|
1576
|
+
(D = (p = n.callbacks).onConnectionStateChange) == null || D.call(p, g), Kn(g, l, i), g === x.Connected && (o ? s(o) : c = !0);
|
|
1561
1577
|
},
|
|
1562
1578
|
onVideoStateChange: (g, l) => {
|
|
1563
|
-
var
|
|
1564
|
-
(
|
|
1579
|
+
var p, D;
|
|
1580
|
+
(D = (p = n.callbacks).onVideoStateChange) == null || D.call(p, g), zn(
|
|
1565
1581
|
g,
|
|
1566
1582
|
e,
|
|
1567
1583
|
l,
|
|
@@ -1570,17 +1586,17 @@ function ct(e, n, i, r) {
|
|
|
1570
1586
|
);
|
|
1571
1587
|
},
|
|
1572
1588
|
onAgentActivityStateChange: (g) => {
|
|
1573
|
-
var l,
|
|
1574
|
-
(
|
|
1589
|
+
var l, p;
|
|
1590
|
+
(p = (l = n.callbacks).onAgentActivityStateChange) == null || p.call(l, g), g === W.Talking ? (je.update(), d = (D) => {
|
|
1575
1591
|
st(
|
|
1576
|
-
|
|
1592
|
+
k.Start,
|
|
1577
1593
|
e,
|
|
1578
1594
|
i,
|
|
1579
1595
|
o.streamType,
|
|
1580
|
-
|
|
1596
|
+
D
|
|
1581
1597
|
), d = null;
|
|
1582
1598
|
}, h || d({ latency: oe.get(!0) })) : (je.reset(), d = null, st(
|
|
1583
|
-
|
|
1599
|
+
k.Stop,
|
|
1584
1600
|
e,
|
|
1585
1601
|
i,
|
|
1586
1602
|
o.streamType
|
|
@@ -1592,6 +1608,10 @@ function ct(e, n, i, r) {
|
|
|
1592
1608
|
onStreamReady: () => {
|
|
1593
1609
|
const g = nt.get(!0);
|
|
1594
1610
|
i.track("agent-chat", { event: "ready", latency: g });
|
|
1611
|
+
},
|
|
1612
|
+
onToolEvent: (g, l) => {
|
|
1613
|
+
var p, D;
|
|
1614
|
+
(D = (p = n.callbacks).onToolEvent) == null || D.call(p, g, l), Jn(g, l, i);
|
|
1595
1615
|
}
|
|
1596
1616
|
}
|
|
1597
1617
|
},
|
|
@@ -1603,10 +1623,10 @@ function ct(e, n, i, r) {
|
|
|
1603
1623
|
});
|
|
1604
1624
|
}
|
|
1605
1625
|
async function On(e, n, i, r, s) {
|
|
1606
|
-
var h, g, l,
|
|
1626
|
+
var h, g, l, p;
|
|
1607
1627
|
const a = async () => {
|
|
1608
1628
|
if (Ke(e.presenter.type)) {
|
|
1609
|
-
const
|
|
1629
|
+
const D = await ct(e, n, r), N = `${jn}_${D.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
|
|
1610
1630
|
return { chatResult: {
|
|
1611
1631
|
chatMode: O.Functional,
|
|
1612
1632
|
chat: {
|
|
@@ -1620,9 +1640,9 @@ async function On(e, n, i, r, s) {
|
|
|
1620
1640
|
chat_mode: O.Functional,
|
|
1621
1641
|
messages: []
|
|
1622
1642
|
}
|
|
1623
|
-
}, streamingManager:
|
|
1643
|
+
}, streamingManager: D };
|
|
1624
1644
|
} else {
|
|
1625
|
-
const
|
|
1645
|
+
const D = new AbortController(), N = D.signal;
|
|
1626
1646
|
let B;
|
|
1627
1647
|
try {
|
|
1628
1648
|
const F = ht(
|
|
@@ -1635,12 +1655,12 @@ async function On(e, n, i, r, s) {
|
|
|
1635
1655
|
), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [M, Y] = await Promise.all([F, I]);
|
|
1636
1656
|
return { chatResult: M, streamingManager: Y };
|
|
1637
1657
|
} catch (F) {
|
|
1638
|
-
throw
|
|
1658
|
+
throw D.abort(), B && await B.disconnect().catch(() => {
|
|
1639
1659
|
}), F;
|
|
1640
1660
|
}
|
|
1641
1661
|
}
|
|
1642
1662
|
}, { chatResult: o, streamingManager: c } = await a(), { chat: t, chatMode: d } = o;
|
|
1643
|
-
return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((
|
|
1663
|
+
return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((p = (l = n.callbacks).onError) == null || p.call(l, new It(d)), c == null || c.disconnect(), { chat: t }) : { chat: t, streamingManager: c };
|
|
1644
1664
|
}
|
|
1645
1665
|
async function qn(e, n) {
|
|
1646
1666
|
var H, re, de, ue;
|
|
@@ -1648,7 +1668,7 @@ async function qn(e, n) {
|
|
|
1648
1668
|
const s = n.mixpanelKey || zt, a = n.wsURL || Kt, o = n.baseURL || Ee, c = n.mode || O.Functional, t = {
|
|
1649
1669
|
messages: [],
|
|
1650
1670
|
chatMode: c
|
|
1651
|
-
}, d =
|
|
1671
|
+
}, d = tn({
|
|
1652
1672
|
token: s,
|
|
1653
1673
|
agentId: e,
|
|
1654
1674
|
isEnabled: n.enableAnalitics,
|
|
@@ -1658,67 +1678,67 @@ async function qn(e, n) {
|
|
|
1658
1678
|
tt(() => {
|
|
1659
1679
|
d.track("agent-sdk", { event: "init" }, h);
|
|
1660
1680
|
});
|
|
1661
|
-
const g =
|
|
1681
|
+
const g = Qt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1662
1682
|
n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
|
|
1663
|
-
const
|
|
1664
|
-
d.enrich(
|
|
1665
|
-
const { onMessage:
|
|
1666
|
-
var f, C,
|
|
1667
|
-
(f = t.socketManager) == null || f.disconnect(), (
|
|
1683
|
+
const p = Ke(l.presenter.type);
|
|
1684
|
+
d.enrich(Yt(l));
|
|
1685
|
+
const { onMessage: D, clearQueue: N } = Dn(d, t, n, l, () => {
|
|
1686
|
+
var f, C, T;
|
|
1687
|
+
(f = t.socketManager) == null || f.disconnect(), (T = (C = n.callbacks).onConnectionStateChange) == null || T.call(C, x.Disconnected);
|
|
1668
1688
|
});
|
|
1669
|
-
t.messages =
|
|
1689
|
+
t.messages = rn(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
|
|
1670
1690
|
const B = (f) => {
|
|
1671
1691
|
r = f;
|
|
1672
1692
|
}, F = ({ type: f }) => {
|
|
1673
|
-
var
|
|
1674
|
-
if (!((
|
|
1693
|
+
var T, A, _, L, J;
|
|
1694
|
+
if (!((T = t.streamingManager) != null && T.interruptAvailable) || !((A = t.streamingManager) != null && A.isInterruptible)) return;
|
|
1675
1695
|
const C = t.messages[t.messages.length - 1];
|
|
1676
1696
|
d.track("agent-video-interrupt", {
|
|
1677
1697
|
type: f || "click",
|
|
1678
1698
|
video_duration_to_interrupt: je.get(!0),
|
|
1679
1699
|
message_duration_to_interrupt: oe.get(!0)
|
|
1680
|
-
}), C.interrupted = !0, (
|
|
1700
|
+
}), C.interrupted = !0, (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "answer"), p ? Sn(t.streamingManager) : (vn(t.streamingManager, (J = t.streamingManager) == null ? void 0 : J.streamType, r), Cn(t.streamingManager, r));
|
|
1681
1701
|
}, I = /* @__PURE__ */ new Map();
|
|
1682
1702
|
function M(f) {
|
|
1683
1703
|
return async (C) => {
|
|
1684
|
-
const
|
|
1685
|
-
if (!
|
|
1704
|
+
const T = I.get(f);
|
|
1705
|
+
if (!T)
|
|
1686
1706
|
throw new Error(`No handler registered for client tool: ${f}`);
|
|
1687
1707
|
try {
|
|
1688
1708
|
const A = JSON.parse(C.payload);
|
|
1689
|
-
return await
|
|
1709
|
+
return await T(A);
|
|
1690
1710
|
} catch (A) {
|
|
1691
1711
|
throw new Error(`Client tool "${f}" failed: ${A.message}`);
|
|
1692
1712
|
}
|
|
1693
1713
|
};
|
|
1694
1714
|
}
|
|
1695
1715
|
function Y() {
|
|
1696
|
-
var f, C,
|
|
1697
|
-
for (const [
|
|
1698
|
-
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f,
|
|
1716
|
+
var f, C, T, A;
|
|
1717
|
+
for (const [_] of I)
|
|
1718
|
+
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, _), (A = (T = t.streamingManager) == null ? void 0 : T.registerRpcMethod) == null || A.call(T, _, M(_));
|
|
1699
1719
|
}
|
|
1700
1720
|
function Q(f, C) {
|
|
1701
|
-
var A,
|
|
1702
|
-
const
|
|
1703
|
-
I.set(f, C),
|
|
1721
|
+
var A, _;
|
|
1722
|
+
const T = !I.has(f);
|
|
1723
|
+
I.set(f, C), T && ((_ = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || _.call(A, f, M(f)));
|
|
1704
1724
|
}
|
|
1705
1725
|
function U(f) {
|
|
1706
|
-
var C,
|
|
1707
|
-
I.delete(f), (
|
|
1726
|
+
var C, T;
|
|
1727
|
+
I.delete(f), (T = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || T.call(C, f);
|
|
1708
1728
|
}
|
|
1709
1729
|
const te = Date.now();
|
|
1710
1730
|
tt(() => {
|
|
1711
|
-
d.track("agent-sdk", { event: "loaded", ...
|
|
1731
|
+
d.track("agent-sdk", { event: "loaded", ...Xt(l) }, te);
|
|
1712
1732
|
});
|
|
1713
1733
|
async function ne(f) {
|
|
1714
|
-
var J,
|
|
1715
|
-
(
|
|
1716
|
-
const C = c === O.DirectPlayback ||
|
|
1734
|
+
var J, y, v, E, j, G, ge;
|
|
1735
|
+
(y = (J = n.callbacks).onConnectionStateChange) == null || y.call(J, x.Connecting), oe.reset(), f && !i && (delete t.chat, (E = (v = n.callbacks).onNewMessage) == null || E.call(v, [...t.messages], "answer"));
|
|
1736
|
+
const C = c === O.DirectPlayback || p ? Promise.resolve(void 0) : En(
|
|
1717
1737
|
n.auth,
|
|
1718
1738
|
a,
|
|
1719
|
-
{ onMessage:
|
|
1739
|
+
{ onMessage: D, onError: n.callbacks.onError },
|
|
1720
1740
|
n.externalId
|
|
1721
|
-
),
|
|
1741
|
+
), T = xe(
|
|
1722
1742
|
() => On(
|
|
1723
1743
|
l,
|
|
1724
1744
|
{
|
|
@@ -1727,7 +1747,7 @@ async function qn(e, n) {
|
|
|
1727
1747
|
callbacks: {
|
|
1728
1748
|
...n.callbacks,
|
|
1729
1749
|
onVideoIdChange: B,
|
|
1730
|
-
onMessage:
|
|
1750
|
+
onMessage: D
|
|
1731
1751
|
}
|
|
1732
1752
|
},
|
|
1733
1753
|
g,
|
|
@@ -1744,20 +1764,20 @@ async function qn(e, n) {
|
|
|
1744
1764
|
).catch((Z) => {
|
|
1745
1765
|
var z, ee;
|
|
1746
1766
|
throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, x.Fail), Z;
|
|
1747
|
-
}), [A, { streamingManager:
|
|
1748
|
-
|
|
1749
|
-
chatId:
|
|
1750
|
-
streamId:
|
|
1767
|
+
}), [A, { streamingManager: _, chat: L }] = await Promise.all([C, T]);
|
|
1768
|
+
L && L.id !== ((j = t.chat) == null ? void 0 : j.id) && ((ge = (G = n.callbacks).onNewChat) == null || ge.call(G, L.id)), t.streamingManager = _, t.socketManager = A, t.chat = L, Y(), i = !1, d.enrich({
|
|
1769
|
+
chatId: L == null ? void 0 : L.id,
|
|
1770
|
+
streamId: _ == null ? void 0 : _.streamId,
|
|
1751
1771
|
mode: t.chatMode
|
|
1752
|
-
}), K((
|
|
1772
|
+
}), K((L == null ? void 0 : L.chat_mode) ?? c);
|
|
1753
1773
|
}
|
|
1754
1774
|
async function $() {
|
|
1755
|
-
var f, C,
|
|
1756
|
-
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (
|
|
1775
|
+
var f, C, T, A;
|
|
1776
|
+
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (T = n.callbacks).onConnectionStateChange) == null || A.call(T, x.Disconnected);
|
|
1757
1777
|
}
|
|
1758
1778
|
async function K(f) {
|
|
1759
|
-
var C,
|
|
1760
|
-
f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (
|
|
1779
|
+
var C, T;
|
|
1780
|
+
f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (T = (C = n.callbacks).onModeChange) == null || T.call(C, f));
|
|
1761
1781
|
}
|
|
1762
1782
|
return {
|
|
1763
1783
|
agent: l,
|
|
@@ -1781,7 +1801,7 @@ async function qn(e, n) {
|
|
|
1781
1801
|
},
|
|
1782
1802
|
async reconnect() {
|
|
1783
1803
|
const f = t.streamingManager;
|
|
1784
|
-
if (
|
|
1804
|
+
if (p && (f != null && f.reconnect)) {
|
|
1785
1805
|
try {
|
|
1786
1806
|
await f.reconnect(), d.track("agent-chat", {
|
|
1787
1807
|
event: "reconnect",
|
|
@@ -1826,7 +1846,7 @@ async function qn(e, n) {
|
|
|
1826
1846
|
return t.streamingManager.unpublishCameraStream();
|
|
1827
1847
|
},
|
|
1828
1848
|
async chat(f) {
|
|
1829
|
-
var
|
|
1849
|
+
var _, L, J, y, v;
|
|
1830
1850
|
const C = () => {
|
|
1831
1851
|
if (ft(c))
|
|
1832
1852
|
throw new me(`${c} is enabled, chat is disabled`);
|
|
@@ -1842,8 +1862,8 @@ async function qn(e, n) {
|
|
|
1842
1862
|
if (!t.chat)
|
|
1843
1863
|
throw new me("Chat is not initialized");
|
|
1844
1864
|
}
|
|
1845
|
-
},
|
|
1846
|
-
var
|
|
1865
|
+
}, T = async () => {
|
|
1866
|
+
var E, j;
|
|
1847
1867
|
if (!t.chat) {
|
|
1848
1868
|
const G = await ht(
|
|
1849
1869
|
l,
|
|
@@ -1854,12 +1874,12 @@ async function qn(e, n) {
|
|
|
1854
1874
|
);
|
|
1855
1875
|
if (!G.chat)
|
|
1856
1876
|
throw new Mt(t.chatMode, !!n.persistentChat);
|
|
1857
|
-
t.chat = G.chat, (j = (
|
|
1877
|
+
t.chat = G.chat, (j = (E = n.callbacks).onNewChat) == null || j.call(E, t.chat.id);
|
|
1858
1878
|
}
|
|
1859
1879
|
return t.chat.id;
|
|
1860
|
-
}, A = async (
|
|
1880
|
+
}, A = async (E, j) => {
|
|
1861
1881
|
const G = t.chatMode === O.Playground;
|
|
1862
|
-
return xe(
|
|
1882
|
+
return xe(p && !G ? async () => {
|
|
1863
1883
|
var z, ee;
|
|
1864
1884
|
return await ((ee = (z = t.streamingManager) == null ? void 0 : z.sendTextMessage) == null ? void 0 : ee.call(z, f)), Promise.resolve({});
|
|
1865
1885
|
} : async () => {
|
|
@@ -1871,7 +1891,7 @@ async function qn(e, n) {
|
|
|
1871
1891
|
chatMode: t.chatMode,
|
|
1872
1892
|
streamId: (z = t.streamingManager) == null ? void 0 : z.streamId,
|
|
1873
1893
|
sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
|
|
1874
|
-
messages:
|
|
1894
|
+
messages: E.map(({ matches: De, ...le }) => le)
|
|
1875
1895
|
},
|
|
1876
1896
|
{
|
|
1877
1897
|
...gt(t.chatMode),
|
|
@@ -1881,9 +1901,9 @@ async function qn(e, n) {
|
|
|
1881
1901
|
}, {
|
|
1882
1902
|
limit: 2,
|
|
1883
1903
|
shouldRetryFn: (z) => {
|
|
1884
|
-
var le, ke,
|
|
1904
|
+
var le, ke, he, pe;
|
|
1885
1905
|
const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
|
|
1886
|
-
return !((ke = z == null ? void 0 : z.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((
|
|
1906
|
+
return !((ke = z == null ? void 0 : z.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((pe = (he = n.callbacks).onError) == null || pe.call(he, z), !1) : !0;
|
|
1887
1907
|
},
|
|
1888
1908
|
onRetry: async () => {
|
|
1889
1909
|
await $(), await ne(!1);
|
|
@@ -1892,58 +1912,58 @@ async function qn(e, n) {
|
|
|
1892
1912
|
};
|
|
1893
1913
|
try {
|
|
1894
1914
|
N(), C(), t.messages.push({
|
|
1895
|
-
id:
|
|
1915
|
+
id: Te(),
|
|
1896
1916
|
role: "user",
|
|
1897
1917
|
content: f,
|
|
1898
|
-
parts:
|
|
1918
|
+
parts: Re(f),
|
|
1899
1919
|
created_at: new Date(oe.update()).toISOString()
|
|
1900
|
-
}), (
|
|
1901
|
-
const
|
|
1920
|
+
}), (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "user");
|
|
1921
|
+
const E = await T(), j = await A([...t.messages], E);
|
|
1902
1922
|
return t.messages.push({
|
|
1903
|
-
id:
|
|
1923
|
+
id: Te(),
|
|
1904
1924
|
role: "assistant",
|
|
1905
1925
|
content: j.result || "",
|
|
1906
|
-
parts:
|
|
1926
|
+
parts: Re(j.result || ""),
|
|
1907
1927
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1908
1928
|
context: j.context,
|
|
1909
1929
|
matches: j.matches
|
|
1910
1930
|
}), d.track("agent-message-send", {
|
|
1911
1931
|
event: "success",
|
|
1912
1932
|
messages: t.messages.length + 1
|
|
1913
|
-
}), j.result && ((
|
|
1933
|
+
}), j.result && ((y = (J = n.callbacks).onNewMessage) == null || y.call(J, [...t.messages], "answer"), d.track("agent-message-received", {
|
|
1914
1934
|
latency: oe.get(!0),
|
|
1915
1935
|
messages: t.messages.length
|
|
1916
1936
|
})), j;
|
|
1917
|
-
} catch (
|
|
1918
|
-
throw ((
|
|
1937
|
+
} catch (E) {
|
|
1938
|
+
throw ((v = t.messages[t.messages.length - 1]) == null ? void 0 : v.role) === "assistant" && t.messages.pop(), d.track("agent-message-send", {
|
|
1919
1939
|
event: "error",
|
|
1920
1940
|
messages: t.messages.length
|
|
1921
|
-
}),
|
|
1941
|
+
}), E;
|
|
1922
1942
|
}
|
|
1923
1943
|
},
|
|
1924
|
-
rate(f, C,
|
|
1925
|
-
var
|
|
1926
|
-
const A = t.messages.find((
|
|
1944
|
+
rate(f, C, T) {
|
|
1945
|
+
var L, J, y, v;
|
|
1946
|
+
const A = t.messages.find((E) => E.id === f);
|
|
1927
1947
|
if (t.chat) {
|
|
1928
1948
|
if (!A)
|
|
1929
1949
|
throw new Error("Message not found");
|
|
1930
1950
|
} else throw new Error("Chat is not initialized");
|
|
1931
|
-
const
|
|
1951
|
+
const _ = ((L = A.matches) == null ? void 0 : L.map((E) => [E.document_id, E.id])) ?? [];
|
|
1932
1952
|
return d.track("agent-rate", {
|
|
1933
|
-
event:
|
|
1953
|
+
event: T ? "update" : "create",
|
|
1934
1954
|
thumb: C === 1 ? "up" : "down",
|
|
1935
1955
|
knowledge_id: ((J = l.knowledge) == null ? void 0 : J.id) ?? "",
|
|
1936
|
-
matches:
|
|
1956
|
+
matches: _,
|
|
1937
1957
|
score: C
|
|
1938
|
-
}),
|
|
1939
|
-
knowledge_id: ((
|
|
1958
|
+
}), T ? g.updateRating(l.id, t.chat.id, T, {
|
|
1959
|
+
knowledge_id: ((y = l.knowledge) == null ? void 0 : y.id) ?? "",
|
|
1940
1960
|
message_id: f,
|
|
1941
|
-
matches:
|
|
1961
|
+
matches: _,
|
|
1942
1962
|
score: C
|
|
1943
1963
|
}) : g.createRating(l.id, t.chat.id, {
|
|
1944
|
-
knowledge_id: ((
|
|
1964
|
+
knowledge_id: ((v = l.knowledge) == null ? void 0 : v.id) ?? "",
|
|
1945
1965
|
message_id: f,
|
|
1946
|
-
matches:
|
|
1966
|
+
matches: _,
|
|
1947
1967
|
score: C
|
|
1948
1968
|
});
|
|
1949
1969
|
},
|
|
@@ -1953,7 +1973,7 @@ async function qn(e, n) {
|
|
|
1953
1973
|
return d.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
|
|
1954
1974
|
},
|
|
1955
1975
|
async speak(f) {
|
|
1956
|
-
var
|
|
1976
|
+
var _, L, J;
|
|
1957
1977
|
function C() {
|
|
1958
1978
|
if (typeof f == "string") {
|
|
1959
1979
|
if (!l.presenter.voice)
|
|
@@ -1977,14 +1997,14 @@ async function qn(e, n) {
|
|
|
1977
1997
|
}
|
|
1978
1998
|
return f;
|
|
1979
1999
|
}
|
|
1980
|
-
const
|
|
1981
|
-
if (d.track("agent-speak",
|
|
1982
|
-
id:
|
|
2000
|
+
const T = C();
|
|
2001
|
+
if (d.track("agent-speak", T), oe.update(), t.messages && T.type === "text" && (t.messages.push({
|
|
2002
|
+
id: Te(),
|
|
1983
2003
|
role: "assistant",
|
|
1984
|
-
content:
|
|
1985
|
-
parts:
|
|
2004
|
+
content: T.input,
|
|
2005
|
+
parts: Re(T.input),
|
|
1986
2006
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1987
|
-
}), (
|
|
2007
|
+
}), (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "answer")), Ot(t.chatMode))
|
|
1988
2008
|
return {
|
|
1989
2009
|
duration: 0,
|
|
1990
2010
|
video_id: "",
|
|
@@ -1993,7 +2013,7 @@ async function qn(e, n) {
|
|
|
1993
2013
|
if (!t.streamingManager)
|
|
1994
2014
|
throw new Error("Please connect to the agent first");
|
|
1995
2015
|
return t.streamingManager.speak({
|
|
1996
|
-
script:
|
|
2016
|
+
script: T,
|
|
1997
2017
|
metadata: { chat_id: (J = t.chat) == null ? void 0 : J.id, agent_id: l.id }
|
|
1998
2018
|
});
|
|
1999
2019
|
},
|
|
@@ -2013,15 +2033,15 @@ export {
|
|
|
2013
2033
|
ae as ConnectivityState,
|
|
2014
2034
|
$t as DocumentType,
|
|
2015
2035
|
xt as KnowledgeType,
|
|
2016
|
-
|
|
2036
|
+
At as PlanGroup,
|
|
2017
2037
|
jt as Providers,
|
|
2018
2038
|
Lt as RateState,
|
|
2019
|
-
|
|
2039
|
+
R as StreamEvents,
|
|
2020
2040
|
se as StreamType,
|
|
2021
|
-
|
|
2041
|
+
k as StreamingState,
|
|
2022
2042
|
Pt as Subject,
|
|
2023
2043
|
Ne as TransportProvider,
|
|
2024
|
-
|
|
2044
|
+
_t as UserPlan,
|
|
2025
2045
|
me as ValidationError,
|
|
2026
2046
|
dt as VideoType,
|
|
2027
2047
|
Bt as VoiceAccess,
|