@d-id/client-sdk 3.0.0-staging.423 → 3.0.0-staging.425
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-WHsoBMGg.js → index-DfRq-xUG.js} +280 -281
- package/dist/index-DfRq-xUG.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-BCxu61o7.js → livekit-manager-CfUQtpsF.js} +2 -2
- package/dist/{livekit-manager-BCxu61o7.js.map → livekit-manager-CfUQtpsF.js.map} +1 -1
- package/package.json +1 -1
- package/dist/index-WHsoBMGg.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Et = (e, t, r) => t in e ?
|
|
1
|
+
var Rt = Object.defineProperty;
|
|
2
|
+
var Et = (e, t, r) => t in e ? Rt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
3
|
var x = (e, t, r) => Et(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
-
var
|
|
4
|
+
var Re = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Re || {}), L = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(L || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), ne = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e.Image = "image", e))(ne || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ge = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ge || {}), we = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(we || {}), k = /* @__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.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.TurnStarted = "turn/started", e.TurnEnded = "turn/ended", e))(k || {}), Be = /* @__PURE__ */ ((e) => (e.Started = "tool-call/started", e.Done = "tool-call/done", e.Error = "tool-call/error", e))(Be || {}), kt = /* @__PURE__ */ ((e) => (e.Presentation = "did.presentation", e))(kt || {}), R = /* @__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))(R || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), he = /* @__PURE__ */ ((e) => (e.Ok = "ok", e.UnknownError = "unknown_error", e.NetworkIssue = "network_issue", e.MessageLimit = "message_limit", e.TimeLimit = "time_limit", e.Inactivity = "inactivity", e.EndedByAgent = "ended_by_agent", e))(he || {}), Fe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Fe || {}), Tt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Elevenlabs = "elevenlabs", e.Cartesia = "cartesia", e))(Tt || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e.ExternalPrivate = "external-private", e))(_t || {});
|
|
5
5
|
const Jn = (...e) => {
|
|
6
6
|
}, ft = (e) => new Promise((t) => setTimeout(t, e)), Z = (e = 16) => {
|
|
7
7
|
const t = new Uint8Array(e);
|
|
8
8
|
return globalThis.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
9
9
|
};
|
|
10
|
-
function
|
|
10
|
+
function $e(e) {
|
|
11
11
|
if (e !== void 0)
|
|
12
12
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
13
13
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
@@ -18,7 +18,7 @@ function Be(e) {
|
|
|
18
18
|
return t;
|
|
19
19
|
}
|
|
20
20
|
let mt;
|
|
21
|
-
function
|
|
21
|
+
function Ae() {
|
|
22
22
|
return mt ?? (mt = Z());
|
|
23
23
|
}
|
|
24
24
|
function At() {
|
|
@@ -26,14 +26,14 @@ function At() {
|
|
|
26
26
|
}
|
|
27
27
|
function gt(e, t) {
|
|
28
28
|
if (e.type === "bearer")
|
|
29
|
-
return `Bearer ${e.token}~${
|
|
29
|
+
return `Bearer ${e.token}~${Ae()}`;
|
|
30
30
|
if (e.type === "basic")
|
|
31
|
-
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${
|
|
31
|
+
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${Ae()}`;
|
|
32
32
|
if (e.type === "key")
|
|
33
|
-
return `Client-Key ${e.clientKey}.${
|
|
33
|
+
return `Client-Key ${e.clientKey}.${$e(t)}_${Ae()}`;
|
|
34
34
|
throw new Error(`Unknown auth type: ${e}`);
|
|
35
35
|
}
|
|
36
|
-
const Pt = 45 * 1e3, bt = "X-Playground-Chat", He = 2e3,
|
|
36
|
+
const Pt = 45 * 1e3, bt = "X-Playground-Chat", He = 2e3, ke = "https://api.d-id.com", xt = "wss://notifications.d-id.com", Lt = "79f81a83a67430be2bc0fd61042b8faa";
|
|
37
37
|
class q extends Error {
|
|
38
38
|
/**
|
|
39
39
|
* Creates an SDK error. The SDK builds these itself; applications normally only catch them.
|
|
@@ -262,7 +262,7 @@ class pt extends q {
|
|
|
262
262
|
x(this, "kind", "StreamError");
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
class
|
|
265
|
+
class I extends q {
|
|
266
266
|
/**
|
|
267
267
|
* Builds a validation failure. The SDK does this itself before it performs a request.
|
|
268
268
|
*
|
|
@@ -292,13 +292,13 @@ class Ot extends q {
|
|
|
292
292
|
x(this, "kind", "WSError");
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
const
|
|
295
|
+
const wt = (e) => e.type, zt = (e) => e.type === ne.Expressive ? "v4" : e.type === ne.Clip ? "v3-pro" : e.type === ne.Image ? "image" : "v2", Ve = (e) => e === ne.Expressive || e === ne.Image, Pe = (e) => [L.TextOnly, L.Playground, L.Maintenance].includes(e), te = (e) => e && [L.DirectPlayback, L.Off].includes(e), We = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ft = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
|
|
296
296
|
function Vt(e) {
|
|
297
297
|
const t = e.split("?")[0].split("#")[0].toLowerCase();
|
|
298
298
|
return Ft.some((r) => t.endsWith(r));
|
|
299
299
|
}
|
|
300
300
|
const qe = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ge = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
301
|
-
function
|
|
301
|
+
function yt(e) {
|
|
302
302
|
if (e.length === 0)
|
|
303
303
|
return [];
|
|
304
304
|
const t = [];
|
|
@@ -336,9 +336,9 @@ function wt(e) {
|
|
|
336
336
|
s.index > o && a.push({ type: "text", text: e.slice(o, s.index) }), a.push(s.part), o = s.index + s.length;
|
|
337
337
|
return o < e.length && a.push({ type: "text", text: e.slice(o) }), a;
|
|
338
338
|
}
|
|
339
|
-
let Xe = "",
|
|
340
|
-
function
|
|
341
|
-
return e === Xe || (Xe = e,
|
|
339
|
+
let Xe = "", be = [];
|
|
340
|
+
function pe(e) {
|
|
341
|
+
return e === Xe || (Xe = e, be = yt(e)), be;
|
|
342
342
|
}
|
|
343
343
|
function Ut(e, t) {
|
|
344
344
|
let r;
|
|
@@ -349,7 +349,7 @@ function Ut(e, t) {
|
|
|
349
349
|
clear: () => clearTimeout(r)
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
async function
|
|
352
|
+
async function Ne(e, t) {
|
|
353
353
|
const r = {
|
|
354
354
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
355
355
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -379,13 +379,13 @@ class Ye {
|
|
|
379
379
|
this.response = t;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
const Jt = (e) =>
|
|
382
|
+
const Jt = (e) => Ne(e, {
|
|
383
383
|
limit: 3,
|
|
384
384
|
delayMs: 1e3,
|
|
385
385
|
timeout: 0,
|
|
386
386
|
shouldRetryFn: (t) => t.status === 429
|
|
387
387
|
});
|
|
388
|
-
function vt(e, t =
|
|
388
|
+
function vt(e, t = ke, r, a) {
|
|
389
389
|
const o = async (s, i) => {
|
|
390
390
|
const { skipErrorHandler: u, ...n } = i || {}, d = n.method ?? "GET", h = performance.now();
|
|
391
391
|
let f;
|
|
@@ -440,7 +440,7 @@ function vt(e, t = Ee, r, a) {
|
|
|
440
440
|
}
|
|
441
441
|
};
|
|
442
442
|
}
|
|
443
|
-
function Ht(e, t =
|
|
443
|
+
function Ht(e, t = ke, r, a) {
|
|
444
444
|
const o = vt(e, `${t}/agents`, r, a);
|
|
445
445
|
return {
|
|
446
446
|
getRuntimeById(s, i) {
|
|
@@ -480,7 +480,7 @@ function Wt(e) {
|
|
|
480
480
|
isMobile: `${t() == "Mobile"}`,
|
|
481
481
|
browser: navigator.userAgent,
|
|
482
482
|
origin: window.location.origin,
|
|
483
|
-
agentType:
|
|
483
|
+
agentType: wt(a),
|
|
484
484
|
agentVoice: {
|
|
485
485
|
language: (s = (o = e.avatar) == null ? void 0 : o.voice) == null ? void 0 : s.language
|
|
486
486
|
}
|
|
@@ -489,7 +489,7 @@ function Wt(e) {
|
|
|
489
489
|
function Kt(e) {
|
|
490
490
|
var t;
|
|
491
491
|
return {
|
|
492
|
-
agentType:
|
|
492
|
+
agentType: wt(e.avatar),
|
|
493
493
|
presenterType: zt(e.avatar),
|
|
494
494
|
owner_id: e.owner_id ?? "",
|
|
495
495
|
starterQuestionsCount: (t = e.starter_message) == null ? void 0 : t.length,
|
|
@@ -528,11 +528,11 @@ function tt(e, t, r) {
|
|
|
528
528
|
function nt(e) {
|
|
529
529
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function xe(e) {
|
|
532
532
|
return e instanceof q ? e.toJson() : { kind: "UnknownError", message: qt(e) || "UnknownError" };
|
|
533
533
|
}
|
|
534
|
-
const Zt = "3.0.0-staging.
|
|
535
|
-
let
|
|
534
|
+
const Zt = "3.0.0-staging.425", en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", St = 50, Q = [];
|
|
535
|
+
let Le = !1;
|
|
536
536
|
async function Ct(e) {
|
|
537
537
|
const t = await fetch(en, {
|
|
538
538
|
method: "POST",
|
|
@@ -545,28 +545,28 @@ async function Ct(e) {
|
|
|
545
545
|
function tn(e) {
|
|
546
546
|
Q.push(e), Q.splice(St);
|
|
547
547
|
}
|
|
548
|
-
function
|
|
549
|
-
if (
|
|
548
|
+
function Oe() {
|
|
549
|
+
if (Le || !Q.length)
|
|
550
550
|
return;
|
|
551
|
-
|
|
551
|
+
Le = !0;
|
|
552
552
|
const e = Q.splice(0, Q.length);
|
|
553
553
|
Ct(e).catch(() => {
|
|
554
554
|
Q.unshift(...e), Q.splice(St);
|
|
555
555
|
}).finally(() => {
|
|
556
|
-
|
|
556
|
+
Le = !1;
|
|
557
557
|
});
|
|
558
558
|
}
|
|
559
|
-
typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online",
|
|
560
|
-
document.visibilityState === "visible" &&
|
|
559
|
+
typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online", Oe), typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
560
|
+
document.visibilityState === "visible" && Oe();
|
|
561
561
|
}));
|
|
562
562
|
function nn(e) {
|
|
563
563
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
|
|
564
564
|
return {
|
|
565
565
|
token: e.token || "testKey",
|
|
566
|
-
distinct_id:
|
|
566
|
+
distinct_id: $e(e.externalId),
|
|
567
567
|
agentId: e.agentId,
|
|
568
568
|
additionalProperties: {
|
|
569
|
-
id:
|
|
569
|
+
id: $e(e.externalId),
|
|
570
570
|
...e.mixpanelAdditionalProperties || {}
|
|
571
571
|
},
|
|
572
572
|
isEnabled: e.isEnabled ?? !0,
|
|
@@ -595,7 +595,7 @@ function nn(e) {
|
|
|
595
595
|
"User Agent": navigator.userAgent
|
|
596
596
|
}
|
|
597
597
|
};
|
|
598
|
-
return
|
|
598
|
+
return Oe(), Ct([d]).catch(() => tn(d)), Promise.resolve();
|
|
599
599
|
},
|
|
600
600
|
linkTrack(a, o, s, i) {
|
|
601
601
|
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), i.includes(s) || i.push(s);
|
|
@@ -621,7 +621,7 @@ function Ue() {
|
|
|
621
621
|
get: (t = !1) => t ? Date.now() - e : e
|
|
622
622
|
};
|
|
623
623
|
}
|
|
624
|
-
const K = Ue(),
|
|
624
|
+
const K = Ue(), ze = Ue(), rt = Ue();
|
|
625
625
|
function Mt(e) {
|
|
626
626
|
return e === L.Playground ? { headers: { [bt]: "true" } } : {};
|
|
627
627
|
}
|
|
@@ -634,7 +634,7 @@ async function Dt(e, t, r, a, o = !1, s) {
|
|
|
634
634
|
}
|
|
635
635
|
function rn(e) {
|
|
636
636
|
return !e || e.length === 0 ? [] : e.map(
|
|
637
|
-
(t) => Array.isArray(t.parts) && t.parts.length > 0 ? t : { ...t, parts:
|
|
637
|
+
(t) => Array.isArray(t.parts) && t.parts.length > 0 ? t : { ...t, parts: yt(typeof t.content == "string" ? t.content : "") }
|
|
638
638
|
);
|
|
639
639
|
}
|
|
640
640
|
function an(e) {
|
|
@@ -683,19 +683,19 @@ async function on(e, t, r, a) {
|
|
|
683
683
|
};
|
|
684
684
|
}
|
|
685
685
|
const cn = {
|
|
686
|
-
manual:
|
|
687
|
-
inactivity:
|
|
688
|
-
peer_disconnected:
|
|
689
|
-
shutdown:
|
|
686
|
+
manual: he.Ok,
|
|
687
|
+
inactivity: he.Inactivity,
|
|
688
|
+
peer_disconnected: he.NetworkIssue,
|
|
689
|
+
shutdown: he.UnknownError
|
|
690
690
|
};
|
|
691
691
|
function dn(e) {
|
|
692
692
|
return cn[e.close_reason] ?? e.close_reason;
|
|
693
693
|
}
|
|
694
694
|
const un = [
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
], at = [
|
|
695
|
+
k.StreamVideoDone,
|
|
696
|
+
k.StreamVideoError,
|
|
697
|
+
k.StreamVideoRejected
|
|
698
|
+
], at = [k.StreamFailed, k.StreamVideoError, k.StreamVideoRejected];
|
|
699
699
|
function it(e) {
|
|
700
700
|
if (e.answer !== void 0)
|
|
701
701
|
return e.answer;
|
|
@@ -711,7 +711,7 @@ function ln(e, t, r) {
|
|
|
711
711
|
id: e.id || `user-${Date.now()}`,
|
|
712
712
|
role: e.role,
|
|
713
713
|
content: e.content,
|
|
714
|
-
parts:
|
|
714
|
+
parts: pe(e.content),
|
|
715
715
|
createdAt: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
716
716
|
transcribed: !0
|
|
717
717
|
};
|
|
@@ -752,7 +752,7 @@ function fn(e, t, r, a, o, s, i) {
|
|
|
752
752
|
!!(f && f.length < p.length) && (h.interrupted = !0), r.answer = f;
|
|
753
753
|
}
|
|
754
754
|
const l = it(r);
|
|
755
|
-
(h.content !== l || e === F.Answer) && (h.content = l, h.parts =
|
|
755
|
+
(h.content !== l || e === F.Answer) && (h.content = l, h.parts = pe(l), o == null || o([...a.messages], e));
|
|
756
756
|
}
|
|
757
757
|
function mn(e, t, r, a, o) {
|
|
758
758
|
const s = {}, i = () => {
|
|
@@ -769,7 +769,7 @@ function mn(e, t, r, a, o) {
|
|
|
769
769
|
onMessage: (d, h) => {
|
|
770
770
|
var f, g, l;
|
|
771
771
|
if ("content" in h) {
|
|
772
|
-
const p = d ===
|
|
772
|
+
const p = d === k.ChatAnswer ? F.Answer : d === k.ChatAudioTranscribed ? F.Transcribe : d;
|
|
773
773
|
fn(
|
|
774
774
|
p,
|
|
775
775
|
h,
|
|
@@ -784,7 +784,7 @@ function mn(e, t, r, a, o) {
|
|
|
784
784
|
mode: t.chatMode
|
|
785
785
|
});
|
|
786
786
|
} else {
|
|
787
|
-
const p =
|
|
787
|
+
const p = k;
|
|
788
788
|
if (d = d, d === p.StreamVideoCreated) {
|
|
789
789
|
const D = tt(h, a, { mode: t.chatMode });
|
|
790
790
|
if (e.linkTrack("agent-video", D, p.StreamVideoCreated, ["start"]), h.sentiment) {
|
|
@@ -845,12 +845,12 @@ function gn(e, t, r, a) {
|
|
|
845
845
|
};
|
|
846
846
|
},
|
|
847
847
|
close(s, i) {
|
|
848
|
-
return o.delete(`/streams/${s}`, { session_id: i });
|
|
848
|
+
return o.delete(`/streams/${s}`, { session_id: i }, { skipErrorHandler: !0 });
|
|
849
849
|
}
|
|
850
850
|
};
|
|
851
851
|
}
|
|
852
852
|
const hn = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? ""), pn = 45;
|
|
853
|
-
function
|
|
853
|
+
function wn(e) {
|
|
854
854
|
const t = e.map((n) => n.av).filter((n) => !!n && n.audioPlayout > 0 && n.videoPlayout > 0);
|
|
855
855
|
if (t.length < 2)
|
|
856
856
|
return null;
|
|
@@ -865,7 +865,7 @@ function yn(e) {
|
|
|
865
865
|
residualOffsetMs: De(Yt(u))
|
|
866
866
|
};
|
|
867
867
|
}
|
|
868
|
-
function
|
|
868
|
+
function yn(e, t, r) {
|
|
869
869
|
const a = (t.timestamp - e.timestamp) / 1e3;
|
|
870
870
|
return {
|
|
871
871
|
duration: a,
|
|
@@ -995,11 +995,11 @@ function st(e, t, r) {
|
|
|
995
995
|
return {
|
|
996
996
|
webRTCStats: {
|
|
997
997
|
anomalies: o,
|
|
998
|
-
avSync: Qt(() =>
|
|
998
|
+
avSync: Qt(() => wn(e), null),
|
|
999
999
|
minRtt: Ze(u),
|
|
1000
1000
|
avgRtt: Qe(u),
|
|
1001
1001
|
maxRtt: et(u),
|
|
1002
|
-
aggregateReport:
|
|
1002
|
+
aggregateReport: yn(e[0], e[e.length - 1], s),
|
|
1003
1003
|
minJitterDelayInInterval: Ze(i),
|
|
1004
1004
|
maxJitterDelayInInterval: et(i),
|
|
1005
1005
|
avgJitterDelayInInterval: Qe(i)
|
|
@@ -1008,13 +1008,13 @@ function st(e, t, r) {
|
|
|
1008
1008
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
1009
1009
|
};
|
|
1010
1010
|
}
|
|
1011
|
-
function
|
|
1011
|
+
function It(e, t) {
|
|
1012
1012
|
for (const r of e.values())
|
|
1013
1013
|
if ((r == null ? void 0 : r.type) === "inbound-rtp" && r.kind === t)
|
|
1014
1014
|
return r;
|
|
1015
1015
|
return null;
|
|
1016
1016
|
}
|
|
1017
|
-
const
|
|
1017
|
+
const me = 10;
|
|
1018
1018
|
function Wn(e, t) {
|
|
1019
1019
|
let r = !1, a = !1, o = null, s = 0, i = 0, u = {};
|
|
1020
1020
|
async function n() {
|
|
@@ -1022,17 +1022,17 @@ function Wn(e, t) {
|
|
|
1022
1022
|
try {
|
|
1023
1023
|
const d = await e();
|
|
1024
1024
|
if (!d) {
|
|
1025
|
-
o = setTimeout(n,
|
|
1025
|
+
o = setTimeout(n, me);
|
|
1026
1026
|
return;
|
|
1027
1027
|
}
|
|
1028
|
-
const h =
|
|
1028
|
+
const h = It(d, "audio");
|
|
1029
1029
|
if (!h) {
|
|
1030
|
-
o = setTimeout(n,
|
|
1030
|
+
o = setTimeout(n, me);
|
|
1031
1031
|
return;
|
|
1032
1032
|
}
|
|
1033
1033
|
const f = h.totalAudioEnergy ?? 0, g = h.totalSamplesReceived ?? 0;
|
|
1034
1034
|
if (!a) {
|
|
1035
|
-
s = f, i = g, a = !0, o = setTimeout(n,
|
|
1035
|
+
s = f, i = g, a = !0, o = setTimeout(n, me);
|
|
1036
1036
|
return;
|
|
1037
1037
|
}
|
|
1038
1038
|
const l = f - s, p = g - i;
|
|
@@ -1042,23 +1042,23 @@ function Wn(e, t) {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
} catch {
|
|
1044
1044
|
}
|
|
1045
|
-
r && (o = setTimeout(n,
|
|
1045
|
+
r && (o = setTimeout(n, me));
|
|
1046
1046
|
}
|
|
1047
1047
|
}
|
|
1048
1048
|
return {
|
|
1049
1049
|
arm(d = {}) {
|
|
1050
|
-
u = d, r = !0, a = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(n,
|
|
1050
|
+
u = d, r = !0, a = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(n, me);
|
|
1051
1051
|
},
|
|
1052
1052
|
destroy() {
|
|
1053
1053
|
r = !1, o !== null && (clearTimeout(o), o = null);
|
|
1054
1054
|
}
|
|
1055
1055
|
};
|
|
1056
1056
|
}
|
|
1057
|
-
const
|
|
1058
|
-
function
|
|
1057
|
+
const Ie = 100, Cn = Math.max(Math.ceil(400 / Ie), 1), Mn = 0.25, Dn = 0.28;
|
|
1058
|
+
function In() {
|
|
1059
1059
|
let e = 0, t, r, a = 0;
|
|
1060
1060
|
return (o) => {
|
|
1061
|
-
const s =
|
|
1061
|
+
const s = It(o, "video");
|
|
1062
1062
|
if (!s)
|
|
1063
1063
|
return { isReceiving: !1, avgJitterDelayInInterval: a };
|
|
1064
1064
|
const i = s.jitterBufferDelay, u = s.jitterBufferEmittedCount;
|
|
@@ -1071,29 +1071,29 @@ function Rn() {
|
|
|
1071
1071
|
return e = n, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: s.freezeCount };
|
|
1072
1072
|
};
|
|
1073
1073
|
}
|
|
1074
|
-
function
|
|
1075
|
-
let s = null, i = [], u, n = 0, d = !1, h =
|
|
1076
|
-
const p =
|
|
1074
|
+
function Rn(e, t, r, a, o) {
|
|
1075
|
+
let s = null, i = [], u, n = 0, d = !1, h = ge.Unknown, f = ge.Unknown, g = 0, l = 0;
|
|
1076
|
+
const p = In();
|
|
1077
1077
|
async function D() {
|
|
1078
1078
|
const S = await e();
|
|
1079
1079
|
if (!S)
|
|
1080
1080
|
return;
|
|
1081
|
-
const { isReceiving: P, avgJitterDelayInInterval: U, freezeCount: j } = p(S),
|
|
1081
|
+
const { isReceiving: P, avgJitterDelayInInterval: U, freezeCount: j } = p(S), re = Sn(S);
|
|
1082
1082
|
if (P)
|
|
1083
|
-
n = 0, g = j - l, f = U < Mn ?
|
|
1083
|
+
n = 0, g = j - l, f = U < Mn ? ge.Strong : U > Dn && g > 1 ? ge.Weak : h, f !== h && (o == null || o(f), h = f, l += g, g = 0), d || (a == null || a(C.Start), u = i[i.length - 1], i = [], d = !0), i.push(re);
|
|
1084
1084
|
else if (d && (n++, n >= Cn)) {
|
|
1085
|
-
const
|
|
1086
|
-
a == null || a(C.Stop,
|
|
1085
|
+
const ae = st(i, Ie, u);
|
|
1086
|
+
a == null || a(C.Stop, ae ?? void 0), t() || r(), l = j, d = !1;
|
|
1087
1087
|
}
|
|
1088
1088
|
}
|
|
1089
1089
|
return {
|
|
1090
1090
|
start: () => {
|
|
1091
|
-
s || (s = setInterval(D,
|
|
1091
|
+
s || (s = setInterval(D, Ie));
|
|
1092
1092
|
},
|
|
1093
1093
|
stop: () => {
|
|
1094
1094
|
s && (clearInterval(s), s = null);
|
|
1095
1095
|
},
|
|
1096
|
-
getReport: () => st(i,
|
|
1096
|
+
getReport: () => st(i, Ie, u)
|
|
1097
1097
|
};
|
|
1098
1098
|
}
|
|
1099
1099
|
const En = () => {
|
|
@@ -1105,24 +1105,24 @@ const En = () => {
|
|
|
1105
1105
|
function ot(e) {
|
|
1106
1106
|
switch (e) {
|
|
1107
1107
|
case "connected":
|
|
1108
|
-
return
|
|
1108
|
+
return R.Connected;
|
|
1109
1109
|
case "checking":
|
|
1110
|
-
return
|
|
1110
|
+
return R.Connecting;
|
|
1111
1111
|
case "failed":
|
|
1112
|
-
return
|
|
1112
|
+
return R.Fail;
|
|
1113
1113
|
case "new":
|
|
1114
|
-
return
|
|
1114
|
+
return R.New;
|
|
1115
1115
|
case "closed":
|
|
1116
|
-
return
|
|
1116
|
+
return R.Closed;
|
|
1117
1117
|
case "disconnected":
|
|
1118
|
-
return
|
|
1118
|
+
return R.Disconnected;
|
|
1119
1119
|
case "completed":
|
|
1120
|
-
return
|
|
1120
|
+
return R.Completed;
|
|
1121
1121
|
default:
|
|
1122
|
-
return
|
|
1122
|
+
return R.New;
|
|
1123
1123
|
}
|
|
1124
1124
|
}
|
|
1125
|
-
const
|
|
1125
|
+
const kn = (e) => (t) => {
|
|
1126
1126
|
const [r, a = ""] = t.split(/:(.+)/);
|
|
1127
1127
|
try {
|
|
1128
1128
|
const o = JSON.parse(a);
|
|
@@ -1131,7 +1131,7 @@ const Tn = (e) => (t) => {
|
|
|
1131
1131
|
return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: o }), { subject: r, data: a };
|
|
1132
1132
|
}
|
|
1133
1133
|
};
|
|
1134
|
-
function
|
|
1134
|
+
function Tn({
|
|
1135
1135
|
statsSignal: e,
|
|
1136
1136
|
dataChannelSignal: t,
|
|
1137
1137
|
onVideoStateChange: r,
|
|
@@ -1148,7 +1148,7 @@ function _n({
|
|
|
1148
1148
|
report: o,
|
|
1149
1149
|
log: s
|
|
1150
1150
|
}) {
|
|
1151
|
-
e === C.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(C.Start)) : e === C.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(C.Stop, o)), t === C.Start ? a == null || a(
|
|
1151
|
+
e === C.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(C.Start)) : e === C.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(C.Stop, o)), t === C.Start ? a == null || a(we.Talking) : t === C.Stop && (a == null || a(we.Idle));
|
|
1152
1152
|
}
|
|
1153
1153
|
function ct({
|
|
1154
1154
|
statsSignal: e,
|
|
@@ -1159,7 +1159,7 @@ function ct({
|
|
|
1159
1159
|
report: s,
|
|
1160
1160
|
log: i
|
|
1161
1161
|
}) {
|
|
1162
|
-
o === H.Legacy ?
|
|
1162
|
+
o === H.Legacy ? Tn({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: i }) : o === H.Fluent && _n({
|
|
1163
1163
|
statsSignal: e,
|
|
1164
1164
|
dataChannelSignal: t,
|
|
1165
1165
|
onVideoStateChange: r,
|
|
@@ -1168,9 +1168,9 @@ function ct({
|
|
|
1168
1168
|
log: i
|
|
1169
1169
|
});
|
|
1170
1170
|
}
|
|
1171
|
-
async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s =
|
|
1172
|
-
var
|
|
1173
|
-
const n = hn(r, "WebRTCStreamingManager"), d =
|
|
1171
|
+
async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke, analytics: i }, u) {
|
|
1172
|
+
var fe;
|
|
1173
|
+
const n = hn(r, "WebRTCStreamingManager"), d = kn(n);
|
|
1174
1174
|
let h = !1, f = !1, g = C.Stop, l = C.Stop;
|
|
1175
1175
|
const { startConnection: p, sendStreamRequest: D, close: S, createStream: P, addIceCandidate: U } = gn(
|
|
1176
1176
|
o,
|
|
@@ -1179,31 +1179,31 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ee,
|
|
|
1179
1179
|
a.onError
|
|
1180
1180
|
), {
|
|
1181
1181
|
id: j,
|
|
1182
|
-
offer:
|
|
1183
|
-
ice_servers:
|
|
1182
|
+
offer: re,
|
|
1183
|
+
ice_servers: ae,
|
|
1184
1184
|
session_id: N,
|
|
1185
1185
|
fluent: ee,
|
|
1186
|
-
interrupt_enabled:
|
|
1186
|
+
interrupt_enabled: ye
|
|
1187
1187
|
} = await P(t, u);
|
|
1188
1188
|
if (!N)
|
|
1189
1189
|
throw new Error("Could not create session_id");
|
|
1190
|
-
(
|
|
1191
|
-
const
|
|
1190
|
+
(fe = a.onStreamCreated) == null || fe.call(a, { streamId: j, sessionId: N, agentId: e });
|
|
1191
|
+
const ie = (y) => {
|
|
1192
1192
|
var v;
|
|
1193
|
-
return (v = a.onError) == null ? void 0 : v.call(a,
|
|
1194
|
-
},
|
|
1193
|
+
return (v = a.onError) == null ? void 0 : v.call(a, y, { streamId: j });
|
|
1194
|
+
}, T = new (En())({ iceServers: ae }), G = T.createDataChannel("JanusDataChannel"), B = ee ? H.Fluent : H.Legacy;
|
|
1195
1195
|
i.enrich({
|
|
1196
1196
|
"stream-type": B
|
|
1197
1197
|
});
|
|
1198
|
-
const X = t.stream_warmup && !ee, ve = () => h,
|
|
1199
|
-
var
|
|
1200
|
-
h = !0, f && (n("CALLBACK: onConnectionStateChange(Connected)"), (
|
|
1201
|
-
}, Y =
|
|
1202
|
-
() =>
|
|
1198
|
+
const X = t.stream_warmup && !ee, ve = () => h, se = () => {
|
|
1199
|
+
var y;
|
|
1200
|
+
h = !0, f && (n("CALLBACK: onConnectionStateChange(Connected)"), (y = a.onConnectionStateChange) == null || y.call(a, R.Connected));
|
|
1201
|
+
}, Y = Rn(
|
|
1202
|
+
() => T.getStats(),
|
|
1203
1203
|
ve,
|
|
1204
|
-
|
|
1205
|
-
(
|
|
1206
|
-
statsSignal: l =
|
|
1204
|
+
se,
|
|
1205
|
+
(y, v) => ct({
|
|
1206
|
+
statsSignal: l = y,
|
|
1207
1207
|
dataChannelSignal: B === H.Legacy ? g : void 0,
|
|
1208
1208
|
onVideoStateChange: a.onVideoStateChange,
|
|
1209
1209
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
@@ -1211,41 +1211,41 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ee,
|
|
|
1211
1211
|
streamType: B,
|
|
1212
1212
|
log: n
|
|
1213
1213
|
}),
|
|
1214
|
-
(
|
|
1214
|
+
(y) => {
|
|
1215
1215
|
var v;
|
|
1216
|
-
return (v = a.onConnectivityStateChange) == null ? void 0 : v.call(a,
|
|
1216
|
+
return (v = a.onConnectivityStateChange) == null ? void 0 : v.call(a, y);
|
|
1217
1217
|
}
|
|
1218
1218
|
);
|
|
1219
|
-
Y.start(),
|
|
1220
|
-
n("peerConnection.onicecandidate",
|
|
1219
|
+
Y.start(), T.onicecandidate = (y) => {
|
|
1220
|
+
n("peerConnection.onicecandidate", y);
|
|
1221
1221
|
try {
|
|
1222
|
-
|
|
1222
|
+
y.candidate && y.candidate.sdpMid && y.candidate.sdpMLineIndex !== null ? U(
|
|
1223
1223
|
j,
|
|
1224
1224
|
{
|
|
1225
|
-
candidate:
|
|
1226
|
-
sdpMid:
|
|
1227
|
-
sdpMLineIndex:
|
|
1225
|
+
candidate: y.candidate.candidate,
|
|
1226
|
+
sdpMid: y.candidate.sdpMid,
|
|
1227
|
+
sdpMLineIndex: y.candidate.sdpMLineIndex
|
|
1228
1228
|
},
|
|
1229
1229
|
N,
|
|
1230
1230
|
u
|
|
1231
1231
|
) : U(j, { candidate: null }, N, u);
|
|
1232
1232
|
} catch (v) {
|
|
1233
|
-
|
|
1233
|
+
ie(v);
|
|
1234
1234
|
}
|
|
1235
1235
|
}, G.onopen = () => {
|
|
1236
|
-
f = !0, (!X || h) &&
|
|
1236
|
+
f = !0, (!X || h) && se();
|
|
1237
1237
|
};
|
|
1238
1238
|
let V = null;
|
|
1239
|
-
const
|
|
1239
|
+
const oe = (y) => {
|
|
1240
1240
|
var v;
|
|
1241
|
-
V =
|
|
1241
|
+
V = y, (v = a.onVideoIdChange) == null || v.call(a, y);
|
|
1242
1242
|
};
|
|
1243
|
-
function Se(
|
|
1244
|
-
if (
|
|
1243
|
+
function Se(y, v) {
|
|
1244
|
+
if (y === k.StreamStarted && typeof v == "object" && "metadata" in v) {
|
|
1245
1245
|
const c = v.metadata;
|
|
1246
|
-
|
|
1246
|
+
oe(c.videoId);
|
|
1247
1247
|
}
|
|
1248
|
-
|
|
1248
|
+
y === k.StreamDone && oe(null), g = y === k.StreamStarted ? C.Start : C.Stop, ct({
|
|
1249
1249
|
statsSignal: B === H.Legacy ? l : void 0,
|
|
1250
1250
|
dataChannelSignal: g,
|
|
1251
1251
|
onVideoStateChange: a.onVideoStateChange,
|
|
@@ -1254,40 +1254,40 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ee,
|
|
|
1254
1254
|
log: n
|
|
1255
1255
|
});
|
|
1256
1256
|
}
|
|
1257
|
-
function
|
|
1257
|
+
function ce(y, v) {
|
|
1258
1258
|
var m;
|
|
1259
1259
|
const c = typeof v == "string" ? v : v == null ? void 0 : v.metadata;
|
|
1260
1260
|
c && i.enrich({ streamMetadata: c }), (m = a.onStreamReady) == null || m.call(a);
|
|
1261
1261
|
}
|
|
1262
|
-
const
|
|
1263
|
-
[
|
|
1264
|
-
[
|
|
1265
|
-
[
|
|
1262
|
+
const de = {
|
|
1263
|
+
[k.StreamStarted]: Se,
|
|
1264
|
+
[k.StreamDone]: Se,
|
|
1265
|
+
[k.StreamReady]: ce
|
|
1266
1266
|
};
|
|
1267
|
-
G.onmessage = (
|
|
1267
|
+
G.onmessage = (y) => {
|
|
1268
1268
|
var m;
|
|
1269
|
-
const { subject: v, data: c } = d(
|
|
1270
|
-
(m =
|
|
1271
|
-
},
|
|
1269
|
+
const { subject: v, data: c } = d(y.data);
|
|
1270
|
+
(m = de[v]) == null || m.call(de, v, c);
|
|
1271
|
+
}, T.oniceconnectionstatechange = () => {
|
|
1272
1272
|
var v;
|
|
1273
|
-
n("peerConnection.oniceconnectionstatechange => " +
|
|
1274
|
-
const
|
|
1275
|
-
|
|
1276
|
-
},
|
|
1273
|
+
n("peerConnection.oniceconnectionstatechange => " + T.iceConnectionState);
|
|
1274
|
+
const y = ot(T.iceConnectionState);
|
|
1275
|
+
y !== R.Connected && ((v = a.onConnectionStateChange) == null || v.call(a, y, `webrtc:ice-${T.iceConnectionState}`));
|
|
1276
|
+
}, T.ontrack = (y) => {
|
|
1277
1277
|
var v;
|
|
1278
|
-
n("peerConnection.ontrack",
|
|
1279
|
-
}, await
|
|
1280
|
-
const
|
|
1281
|
-
n("create answer OK"), await
|
|
1282
|
-
async function
|
|
1278
|
+
n("peerConnection.ontrack", y), n("CALLBACK: onSrcObjectReady"), (v = a.onSrcObjectReady) == null || v.call(a, y.streams[0]);
|
|
1279
|
+
}, await T.setRemoteDescription(re), n("set remote description OK");
|
|
1280
|
+
const ue = await T.createAnswer();
|
|
1281
|
+
n("create answer OK"), await T.setLocalDescription(ue), n("set local description OK"), await p(j, ue, N, u), n("start connection OK");
|
|
1282
|
+
async function le(y, v) {
|
|
1283
1283
|
if (!h || G.readyState !== "open") {
|
|
1284
|
-
n("Data channel is not ready for sending messages"),
|
|
1284
|
+
n("Data channel is not ready for sending messages"), ie(new pt("Data channel is not ready for sending messages"));
|
|
1285
1285
|
return;
|
|
1286
1286
|
}
|
|
1287
1287
|
try {
|
|
1288
1288
|
G.send(v);
|
|
1289
1289
|
} catch (c) {
|
|
1290
|
-
n("Error sending data channel message", c),
|
|
1290
|
+
n("Error sending data channel message", c), ie(c);
|
|
1291
1291
|
}
|
|
1292
1292
|
}
|
|
1293
1293
|
return {
|
|
@@ -1295,33 +1295,32 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ee,
|
|
|
1295
1295
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1296
1296
|
* @param payload
|
|
1297
1297
|
*/
|
|
1298
|
-
speak(
|
|
1299
|
-
return D(j, N,
|
|
1298
|
+
speak(y) {
|
|
1299
|
+
return D(j, N, y);
|
|
1300
1300
|
},
|
|
1301
1301
|
/**
|
|
1302
1302
|
* Method to close RTC connection
|
|
1303
1303
|
*/
|
|
1304
1304
|
async disconnect() {
|
|
1305
|
-
var
|
|
1305
|
+
var y;
|
|
1306
1306
|
if (j) {
|
|
1307
|
-
const v = ot(
|
|
1308
|
-
if (
|
|
1309
|
-
if (v ===
|
|
1307
|
+
const v = ot(T.iceConnectionState);
|
|
1308
|
+
if (T) {
|
|
1309
|
+
if (v === R.New) {
|
|
1310
1310
|
Y.stop();
|
|
1311
1311
|
return;
|
|
1312
1312
|
}
|
|
1313
|
-
|
|
1313
|
+
T.close(), T.oniceconnectionstatechange = null, T.onnegotiationneeded = null, T.onicecandidate = null, T.ontrack = null;
|
|
1314
1314
|
}
|
|
1315
1315
|
try {
|
|
1316
|
-
v ===
|
|
1317
|
-
});
|
|
1316
|
+
v === R.Connected && await S(j, N);
|
|
1318
1317
|
} catch (c) {
|
|
1319
1318
|
n("Error on close stream connection", c);
|
|
1320
1319
|
}
|
|
1321
|
-
(
|
|
1320
|
+
(y = a.onAgentActivityStateChange) == null || y.call(a, we.Idle), Y.stop();
|
|
1322
1321
|
}
|
|
1323
1322
|
},
|
|
1324
|
-
sendDataChannelMessage:
|
|
1323
|
+
sendDataChannelMessage: le,
|
|
1325
1324
|
/**
|
|
1326
1325
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1327
1326
|
*/
|
|
@@ -1331,21 +1330,21 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ee,
|
|
|
1331
1330
|
*/
|
|
1332
1331
|
streamId: j,
|
|
1333
1332
|
streamType: B,
|
|
1334
|
-
interruptAvailable:
|
|
1333
|
+
interruptAvailable: ye ?? !1,
|
|
1335
1334
|
isInterruptible: !0,
|
|
1336
|
-
interrupt(
|
|
1337
|
-
if (!
|
|
1335
|
+
interrupt(y) {
|
|
1336
|
+
if (!ye || B !== H.Fluent || !V || !h || G.readyState !== "open")
|
|
1338
1337
|
return !1;
|
|
1339
1338
|
const v = {
|
|
1340
|
-
type:
|
|
1339
|
+
type: k.StreamInterrupt,
|
|
1341
1340
|
videoId: V,
|
|
1342
1341
|
timestamp: Date.now()
|
|
1343
1342
|
};
|
|
1344
|
-
return
|
|
1343
|
+
return le(Re.Interrupt, JSON.stringify(v)), !0;
|
|
1345
1344
|
}
|
|
1346
1345
|
};
|
|
1347
1346
|
}
|
|
1348
|
-
var
|
|
1347
|
+
var Ee = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ee || {});
|
|
1349
1348
|
async function Pn(e, t, r, a) {
|
|
1350
1349
|
const o = e.id;
|
|
1351
1350
|
switch (t.version) {
|
|
@@ -1357,7 +1356,7 @@ async function Pn(e, t, r, a) {
|
|
|
1357
1356
|
const { version: s, ...i } = t;
|
|
1358
1357
|
switch (i.transport.provider) {
|
|
1359
1358
|
case Fe.Livekit:
|
|
1360
|
-
const { createLiveKitStreamingManager: u } = await import("./livekit-manager-
|
|
1359
|
+
const { createLiveKitStreamingManager: u } = await import("./livekit-manager-CfUQtpsF.js");
|
|
1361
1360
|
return u(o, i, r);
|
|
1362
1361
|
default:
|
|
1363
1362
|
throw new Error(`Unsupported transport provider: ${i.transport.provider}`);
|
|
@@ -1389,7 +1388,7 @@ function Ln(e) {
|
|
|
1389
1388
|
}, ...r && { end_user_data: r } };
|
|
1390
1389
|
}
|
|
1391
1390
|
function jn(e, t) {
|
|
1392
|
-
return Ve(e.avatar.type) ? { version:
|
|
1391
|
+
return Ve(e.avatar.type) ? { version: Ee.V2, ...xn(t) } : { version: Ee.V1, ...Ln(t) };
|
|
1393
1392
|
}
|
|
1394
1393
|
function Bn(e, t, r) {
|
|
1395
1394
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
@@ -1406,7 +1405,7 @@ function Nn(e, t, r, a, o) {
|
|
|
1406
1405
|
}
|
|
1407
1406
|
function dt(e, t, r, a, o) {
|
|
1408
1407
|
e === C.Start ? r.linkTrack("agent-video", { event: "start", ...o, "stream-type": a }, "start", [
|
|
1409
|
-
|
|
1408
|
+
k.StreamVideoCreated
|
|
1410
1409
|
]) : e === C.Stop && r.linkTrack(
|
|
1411
1410
|
"agent-video",
|
|
1412
1411
|
{
|
|
@@ -1414,7 +1413,7 @@ function dt(e, t, r, a, o) {
|
|
|
1414
1413
|
"stream-type": a
|
|
1415
1414
|
},
|
|
1416
1415
|
"done",
|
|
1417
|
-
[
|
|
1416
|
+
[k.StreamVideoDone]
|
|
1418
1417
|
);
|
|
1419
1418
|
}
|
|
1420
1419
|
function On(e, t, r, a, o) {
|
|
@@ -1422,7 +1421,7 @@ function On(e, t, r, a, o) {
|
|
|
1422
1421
|
"agent-video",
|
|
1423
1422
|
{ event: "start", latency: K.get(!0), "stream-type": o },
|
|
1424
1423
|
"start",
|
|
1425
|
-
[
|
|
1424
|
+
[k.StreamVideoCreated]
|
|
1426
1425
|
) : e === C.Stop && a.linkTrack(
|
|
1427
1426
|
"agent-video",
|
|
1428
1427
|
{
|
|
@@ -1431,7 +1430,7 @@ function On(e, t, r, a, o) {
|
|
|
1431
1430
|
...r
|
|
1432
1431
|
},
|
|
1433
1432
|
"done",
|
|
1434
|
-
[
|
|
1433
|
+
[k.StreamVideoDone]
|
|
1435
1434
|
);
|
|
1436
1435
|
}
|
|
1437
1436
|
function zn(e, t, r) {
|
|
@@ -1439,14 +1438,14 @@ function zn(e, t, r) {
|
|
|
1439
1438
|
call_id: t.callId,
|
|
1440
1439
|
name: t.name
|
|
1441
1440
|
};
|
|
1442
|
-
if (e ===
|
|
1441
|
+
if (e === Be.Started) {
|
|
1443
1442
|
r.track("agent-tool-call", { ...a, event: "started" });
|
|
1444
1443
|
return;
|
|
1445
1444
|
}
|
|
1446
1445
|
const o = t;
|
|
1447
1446
|
r.track("agent-tool-call", {
|
|
1448
1447
|
...a,
|
|
1449
|
-
event: e ===
|
|
1448
|
+
event: e === Be.Done ? "done" : "error",
|
|
1450
1449
|
duration_ms: o.durationMs,
|
|
1451
1450
|
extra_keys: o.extra ? Object.keys(o.extra).length : 0
|
|
1452
1451
|
});
|
|
@@ -1460,7 +1459,7 @@ function ut(e, t, r, a) {
|
|
|
1460
1459
|
"stream-version": n.version.toString()
|
|
1461
1460
|
});
|
|
1462
1461
|
let d = null;
|
|
1463
|
-
const h =
|
|
1462
|
+
const h = n.version === Ee.V2;
|
|
1464
1463
|
i = await Pn(
|
|
1465
1464
|
e,
|
|
1466
1465
|
n,
|
|
@@ -1471,7 +1470,7 @@ function ut(e, t, r, a) {
|
|
|
1471
1470
|
...t.callbacks,
|
|
1472
1471
|
onConnectionStateChange: (f, g) => {
|
|
1473
1472
|
var l, p;
|
|
1474
|
-
(p = (l = t.callbacks).onConnectionStateChange) == null || p.call(l, f, g), Bn(f, g, r), f ===
|
|
1473
|
+
(p = (l = t.callbacks).onConnectionStateChange) == null || p.call(l, f, g), Bn(f, g, r), f === R.Connected && (i ? o(i) : u = !0);
|
|
1475
1474
|
},
|
|
1476
1475
|
onVideoStateChange: (f, g) => {
|
|
1477
1476
|
var l, p;
|
|
@@ -1485,7 +1484,7 @@ function ut(e, t, r, a) {
|
|
|
1485
1484
|
},
|
|
1486
1485
|
onAgentActivityStateChange: (f) => {
|
|
1487
1486
|
var g, l;
|
|
1488
|
-
(l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f ===
|
|
1487
|
+
(l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f === we.Talking ? (ze.update(), d = (p) => {
|
|
1489
1488
|
dt(
|
|
1490
1489
|
C.Start,
|
|
1491
1490
|
e,
|
|
@@ -1493,7 +1492,7 @@ function ut(e, t, r, a) {
|
|
|
1493
1492
|
i.streamType,
|
|
1494
1493
|
p
|
|
1495
1494
|
), d = null;
|
|
1496
|
-
}, h || d({ latency: K.get(!0) })) : (
|
|
1495
|
+
}, h || d({ latency: K.get(!0) })) : (ze.reset(), d = null, dt(
|
|
1497
1496
|
C.Stop,
|
|
1498
1497
|
e,
|
|
1499
1498
|
r,
|
|
@@ -1560,62 +1559,62 @@ async function Fn(e, t, r, a, o) {
|
|
|
1560
1559
|
}, { chatResult: i, streamingManager: u } = await s(), { chat: n, chatMode: d } = i;
|
|
1561
1560
|
return d && t.mode !== void 0 && d !== t.mode && d !== L.Functional ? ((f = (h = t.callbacks).onError) == null || f.call(h, new Bt(d)), u == null || u.disconnect(), { chat: n }) : { chat: n, streamingManager: u };
|
|
1562
1561
|
}
|
|
1563
|
-
const
|
|
1562
|
+
const je = "ChatMode.Off and ChatMode.DirectPlayback are not supported for Expressive agents", lt = "callbacks.onSrcObjectReady is required in every chat mode that streams video; it is optional only in ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance", Vn = [R.Disconnected, R.Closed, R.Fail];
|
|
1564
1563
|
async function Kn(e, t) {
|
|
1565
|
-
var
|
|
1564
|
+
var ue, le, fe, y, v;
|
|
1566
1565
|
const r = { ...t.callbacks };
|
|
1567
1566
|
let a = !0;
|
|
1568
|
-
const o = ((
|
|
1569
|
-
if (!r.onSrcObjectReady && !
|
|
1570
|
-
throw new
|
|
1567
|
+
const o = ((ue = t.analytics) == null ? void 0 : ue.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL || ke, u = t.mode || L.Functional;
|
|
1568
|
+
if (!r.onSrcObjectReady && !Pe(u))
|
|
1569
|
+
throw new I(lt);
|
|
1571
1570
|
const n = {
|
|
1572
1571
|
messages: [],
|
|
1573
1572
|
chatMode: u
|
|
1574
1573
|
}, d = nn({
|
|
1575
1574
|
token: o,
|
|
1576
1575
|
agentId: e,
|
|
1577
|
-
isEnabled: (
|
|
1576
|
+
isEnabled: (le = t.analytics) == null ? void 0 : le.enabled,
|
|
1578
1577
|
externalId: t.externalId,
|
|
1579
|
-
mixpanelAdditionalProperties: (
|
|
1578
|
+
mixpanelAdditionalProperties: (fe = t.analytics) == null ? void 0 : fe.additionalProperties
|
|
1580
1579
|
}), h = Date.now();
|
|
1581
1580
|
nt(() => {
|
|
1582
1581
|
d.track("agent-sdk", { event: "init" }, h);
|
|
1583
1582
|
});
|
|
1584
|
-
let f =
|
|
1583
|
+
let f = R.New, g;
|
|
1585
1584
|
const l = {
|
|
1586
1585
|
...r,
|
|
1587
1586
|
onError(c, m) {
|
|
1588
|
-
var
|
|
1589
|
-
d.track("agent-error", { error:
|
|
1587
|
+
var w;
|
|
1588
|
+
d.track("agent-error", { error: xe(c) }), (w = r.onError) == null || w.call(r, c, m);
|
|
1590
1589
|
},
|
|
1591
1590
|
onConnectionStateChange(c, m) {
|
|
1592
|
-
var
|
|
1593
|
-
f = c, (
|
|
1591
|
+
var w;
|
|
1592
|
+
f = c, (w = r.onConnectionStateChange) == null || w.call(r, c, m);
|
|
1594
1593
|
},
|
|
1595
1594
|
onStreamCreated(c) {
|
|
1596
1595
|
var m;
|
|
1597
1596
|
g = c, (m = r.onStreamCreated) == null || m.call(r, c);
|
|
1598
1597
|
}
|
|
1599
1598
|
}, p = { ...t, callbacks: l }, D = Ht(p.auth, i, l.onError, p.externalId), S = await D.getRuntimeById(e);
|
|
1600
|
-
p.debug = p.debug || ((
|
|
1599
|
+
p.debug = p.debug || ((y = S == null ? void 0 : S.advanced_settings) == null ? void 0 : y.ui_debug_mode);
|
|
1601
1600
|
const P = Ve(S.avatar.type);
|
|
1602
1601
|
if (P && te(u))
|
|
1603
|
-
throw new
|
|
1604
|
-
P && import("./livekit-manager-
|
|
1602
|
+
throw new I(je);
|
|
1603
|
+
P && import("./livekit-manager-CfUQtpsF.js").then(({ preloadLiveKit: c }) => c()).catch(() => {
|
|
1605
1604
|
}), d.enrich(Kt(S));
|
|
1606
1605
|
const { onMessage: U, clearQueue: j } = mn(d, n, p, S, (c) => {
|
|
1607
|
-
var m,
|
|
1608
|
-
(m = n.socketManager) == null || m.disconnect(), (
|
|
1606
|
+
var m, w;
|
|
1607
|
+
(m = n.socketManager) == null || m.disconnect(), (w = l.onConnectionStateChange) == null || w.call(l, R.Disconnected, c);
|
|
1609
1608
|
});
|
|
1610
1609
|
n.messages = rn(p.initialMessages), n.messages.length && ((v = l.onNewMessage) == null || v.call(l, [...n.messages], "answer"));
|
|
1611
|
-
const
|
|
1610
|
+
const re = (c) => d.enrich({ videoId: c }), ae = (c) => {
|
|
1612
1611
|
var O;
|
|
1613
|
-
const m = (c == null ? void 0 : c.type) ?? "click",
|
|
1614
|
-
if (!(
|
|
1612
|
+
const m = (c == null ? void 0 : c.type) ?? "click", w = n.streamingManager;
|
|
1613
|
+
if (!(w != null && w.interruptAvailable) || !w.isInterruptible || !w.interrupt(m))
|
|
1615
1614
|
return;
|
|
1616
1615
|
d.track("agent-video-interrupt", {
|
|
1617
1616
|
type: m,
|
|
1618
|
-
video_duration_to_interrupt:
|
|
1617
|
+
video_duration_to_interrupt: ze.get(!0),
|
|
1619
1618
|
message_duration_to_interrupt: K.get(!0)
|
|
1620
1619
|
});
|
|
1621
1620
|
const E = n.messages[n.messages.length - 1];
|
|
@@ -1623,28 +1622,28 @@ async function Kn(e, t) {
|
|
|
1623
1622
|
}, N = /* @__PURE__ */ new Map();
|
|
1624
1623
|
function ee(c) {
|
|
1625
1624
|
return async (m) => {
|
|
1626
|
-
const
|
|
1627
|
-
if (!
|
|
1625
|
+
const w = N.get(c);
|
|
1626
|
+
if (!w)
|
|
1628
1627
|
throw new Error(`No handler registered for client tool: ${c}`);
|
|
1629
1628
|
const M = JSON.parse(m.payload);
|
|
1630
|
-
return
|
|
1629
|
+
return w(M);
|
|
1631
1630
|
};
|
|
1632
1631
|
}
|
|
1633
|
-
function
|
|
1634
|
-
var c, m,
|
|
1632
|
+
function ye() {
|
|
1633
|
+
var c, m, w, M;
|
|
1635
1634
|
for (const [E] of N)
|
|
1636
|
-
(m = (c = n.streamingManager) == null ? void 0 : c.unregisterRpcMethod) == null || m.call(c, E), (M = (
|
|
1635
|
+
(m = (c = n.streamingManager) == null ? void 0 : c.unregisterRpcMethod) == null || m.call(c, E), (M = (w = n.streamingManager) == null ? void 0 : w.registerRpcMethod) == null || M.call(w, E, ee(E));
|
|
1637
1636
|
}
|
|
1638
|
-
function
|
|
1637
|
+
function ie(c, m) {
|
|
1639
1638
|
var M, E;
|
|
1640
1639
|
if (!P)
|
|
1641
|
-
throw new
|
|
1642
|
-
const
|
|
1643
|
-
N.set(c, m),
|
|
1640
|
+
throw new I("registerClientTool is only available on Expressive (V4) agents");
|
|
1641
|
+
const w = !N.has(c);
|
|
1642
|
+
N.set(c, m), w && ((E = (M = n.streamingManager) == null ? void 0 : M.registerRpcMethod) == null || E.call(M, c, ee(c)));
|
|
1644
1643
|
}
|
|
1645
|
-
function
|
|
1646
|
-
var m,
|
|
1647
|
-
N.delete(c), (
|
|
1644
|
+
function T(c) {
|
|
1645
|
+
var m, w;
|
|
1646
|
+
N.delete(c), (w = (m = n.streamingManager) == null ? void 0 : m.unregisterRpcMethod) == null || w.call(m, c);
|
|
1648
1647
|
}
|
|
1649
1648
|
const G = Date.now();
|
|
1650
1649
|
nt(() => {
|
|
@@ -1656,20 +1655,20 @@ async function Kn(e, t) {
|
|
|
1656
1655
|
B = void 0;
|
|
1657
1656
|
}), B;
|
|
1658
1657
|
}
|
|
1659
|
-
function
|
|
1658
|
+
function se(c) {
|
|
1660
1659
|
return B || ve(() => Y(c));
|
|
1661
1660
|
}
|
|
1662
1661
|
async function Y(c) {
|
|
1663
|
-
var J, Te,
|
|
1662
|
+
var J, Te, _e, $;
|
|
1664
1663
|
if (X)
|
|
1665
1664
|
return;
|
|
1666
|
-
n.streamingManager && await V(), At(), (J = l.onConnectionStateChange) == null || J.call(l,
|
|
1667
|
-
const m =
|
|
1665
|
+
n.streamingManager && await V(), At(), (J = l.onConnectionStateChange) == null || J.call(l, R.Connecting), K.reset(), c && !a && (delete n.chat, (Te = l.onNewMessage) == null || Te.call(l, [...n.messages], "answer"));
|
|
1666
|
+
const m = oe(n.chatMode) ? on(
|
|
1668
1667
|
p.auth,
|
|
1669
1668
|
s,
|
|
1670
1669
|
{ onMessage: U, onError: l.onError },
|
|
1671
1670
|
p.externalId
|
|
1672
|
-
) : Promise.resolve(void 0),
|
|
1671
|
+
) : Promise.resolve(void 0), w = Ne(
|
|
1673
1672
|
() => Fn(
|
|
1674
1673
|
S,
|
|
1675
1674
|
{
|
|
@@ -1677,7 +1676,7 @@ async function Kn(e, t) {
|
|
|
1677
1676
|
mode: n.chatMode,
|
|
1678
1677
|
callbacks: {
|
|
1679
1678
|
...l,
|
|
1680
|
-
onVideoIdChange:
|
|
1679
|
+
onVideoIdChange: re,
|
|
1681
1680
|
onMessage: U
|
|
1682
1681
|
},
|
|
1683
1682
|
rpcMethods: new Map([...N.keys()].map((z) => [z, ee(z)]))
|
|
@@ -1696,47 +1695,47 @@ async function Kn(e, t) {
|
|
|
1696
1695
|
).catch(async (z) => {
|
|
1697
1696
|
var Ce;
|
|
1698
1697
|
throw m.then((W) => W == null ? void 0 : W.disconnect()).catch(() => {
|
|
1699
|
-
}), await
|
|
1700
|
-
}), M = (
|
|
1698
|
+
}), await ce(L.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, R.Fail), z;
|
|
1699
|
+
}), M = (_e = n.chat) == null ? void 0 : _e.id, [E, { streamingManager: O, chat: _ }] = await Promise.all([m, w]), b = !!_ && _.id !== M;
|
|
1701
1700
|
if (_ && b && (($ = l.onNewChat) == null || $.call(l, _.id)), n.streamingManager = O, n.socketManager = E, n.chat = _, X) {
|
|
1702
1701
|
await V();
|
|
1703
1702
|
return;
|
|
1704
1703
|
}
|
|
1705
|
-
|
|
1704
|
+
ye(), a = !1, d.enrich({
|
|
1706
1705
|
chatId: _ == null ? void 0 : _.id,
|
|
1707
1706
|
streamId: O == null ? void 0 : O.streamId,
|
|
1708
1707
|
mode: n.chatMode
|
|
1709
1708
|
});
|
|
1710
1709
|
const A = (b ? _ == null ? void 0 : _.chat_mode : void 0) ?? n.chatMode;
|
|
1711
1710
|
if (P && te(A)) {
|
|
1712
|
-
console.warn(`[AgentManager] Ignoring chat mode "${A}": ${
|
|
1711
|
+
console.warn(`[AgentManager] Ignoring chat mode "${A}": ${je}`);
|
|
1713
1712
|
return;
|
|
1714
1713
|
}
|
|
1715
|
-
await
|
|
1714
|
+
await ce(A);
|
|
1716
1715
|
}
|
|
1717
1716
|
async function V() {
|
|
1718
|
-
var c, m,
|
|
1719
|
-
(c = n.socketManager) == null || c.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, g = void 0, (
|
|
1717
|
+
var c, m, w;
|
|
1718
|
+
(c = n.socketManager) == null || c.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, g = void 0, (w = l.onConnectionStateChange) == null || w.call(l, R.Disconnected);
|
|
1720
1719
|
}
|
|
1721
|
-
function
|
|
1720
|
+
function oe(c) {
|
|
1722
1721
|
return !P && c !== L.DirectPlayback;
|
|
1723
1722
|
}
|
|
1724
1723
|
function Se(c) {
|
|
1725
1724
|
const m = !te(c);
|
|
1726
|
-
return (!
|
|
1725
|
+
return (!oe(c) || !!n.socketManager) && (!m || !!n.chat);
|
|
1727
1726
|
}
|
|
1728
|
-
async function
|
|
1727
|
+
async function ce(c) {
|
|
1729
1728
|
var m;
|
|
1730
1729
|
if (c !== n.chatMode) {
|
|
1731
1730
|
d.track("agent-mode-change", { mode: c }), n.chatMode = c;
|
|
1732
|
-
const
|
|
1733
|
-
(c !== L.Functional ||
|
|
1731
|
+
const w = !!n.streamingManager || !!n.socketManager;
|
|
1732
|
+
(c !== L.Functional || w && !Se(c)) && await V(), (m = l.onModeChange) == null || m.call(l, c);
|
|
1734
1733
|
}
|
|
1735
1734
|
}
|
|
1736
|
-
async function
|
|
1735
|
+
async function de(c) {
|
|
1737
1736
|
if (P && te(c))
|
|
1738
|
-
throw new
|
|
1739
|
-
await
|
|
1737
|
+
throw new I(je);
|
|
1738
|
+
await ce(c);
|
|
1740
1739
|
}
|
|
1741
1740
|
return {
|
|
1742
1741
|
agent: S,
|
|
@@ -1755,31 +1754,31 @@ async function Kn(e, t) {
|
|
|
1755
1754
|
getChatMode: () => n.chatMode,
|
|
1756
1755
|
getConnectionState: () => f,
|
|
1757
1756
|
getSessionInfo: () => g,
|
|
1758
|
-
changeMode:
|
|
1757
|
+
changeMode: de,
|
|
1759
1758
|
enrichAnalytics: (c) => d.enrich(c),
|
|
1760
1759
|
async connect() {
|
|
1761
|
-
if (!l.onSrcObjectReady && !
|
|
1762
|
-
throw new
|
|
1760
|
+
if (!l.onSrcObjectReady && !Pe(n.chatMode))
|
|
1761
|
+
throw new I(lt);
|
|
1763
1762
|
if (B)
|
|
1764
1763
|
return X = !1, B;
|
|
1765
1764
|
if (n.streamingManager && !Vn.includes(f))
|
|
1766
|
-
throw new
|
|
1767
|
-
await
|
|
1765
|
+
throw new I("Already connected; call disconnect() first");
|
|
1766
|
+
await se(!0), n.streamingManager && d.track("agent-chat", {
|
|
1768
1767
|
event: "connect",
|
|
1769
1768
|
mode: n.chatMode
|
|
1770
1769
|
});
|
|
1771
1770
|
},
|
|
1772
1771
|
async reconnect() {
|
|
1773
1772
|
if (B)
|
|
1774
|
-
throw new
|
|
1773
|
+
throw new I("A connect() is in flight; wait for it before calling reconnect()");
|
|
1775
1774
|
return ve(async () => {
|
|
1776
1775
|
const c = n.streamingManager;
|
|
1777
1776
|
let m;
|
|
1778
1777
|
if (P && (c != null && c.reconnect))
|
|
1779
1778
|
try {
|
|
1780
1779
|
await c.reconnect();
|
|
1781
|
-
} catch (
|
|
1782
|
-
const M =
|
|
1780
|
+
} catch (w) {
|
|
1781
|
+
const M = xe(w);
|
|
1783
1782
|
m = M.code ?? M.kind, await V(), await Y(!1);
|
|
1784
1783
|
}
|
|
1785
1784
|
else
|
|
@@ -1803,22 +1802,22 @@ async function Kn(e, t) {
|
|
|
1803
1802
|
publishMicrophoneStream(c) {
|
|
1804
1803
|
var m;
|
|
1805
1804
|
return (m = n.streamingManager) != null && m.publishMicrophoneStream ? n.streamingManager.publishMicrophoneStream(c) : Promise.reject(
|
|
1806
|
-
new
|
|
1805
|
+
new I(
|
|
1807
1806
|
"publishMicrophoneStream is only available on Expressive (V4) agents, after connect()"
|
|
1808
1807
|
)
|
|
1809
1808
|
);
|
|
1810
1809
|
},
|
|
1811
1810
|
setSttLanguage(c) {
|
|
1812
1811
|
return !P || !n.streamingManager ? Promise.reject(
|
|
1813
|
-
new
|
|
1812
|
+
new I("setSttLanguage is only available on Expressive (V4) agents, after connect()")
|
|
1814
1813
|
) : (d.track("agent-stt-language-change", { language: c }), n.streamingManager.sendDataChannelMessage(
|
|
1815
|
-
|
|
1814
|
+
Re.SttLanguage,
|
|
1816
1815
|
JSON.stringify({ language: c })
|
|
1817
1816
|
));
|
|
1818
1817
|
},
|
|
1819
1818
|
sendDataChannelMessage(c, m) {
|
|
1820
1819
|
return !P || !n.streamingManager ? Promise.reject(
|
|
1821
|
-
new
|
|
1820
|
+
new I(
|
|
1822
1821
|
"sendDataChannelMessage is only available on Expressive (V4) agents, after connect()"
|
|
1823
1822
|
)
|
|
1824
1823
|
) : (d.track("agent-data-message", { topic: c }), n.streamingManager.sendDataChannelMessage(c, JSON.stringify(m)));
|
|
@@ -1830,7 +1829,7 @@ async function Kn(e, t) {
|
|
|
1830
1829
|
replaceMicrophoneTrack(c) {
|
|
1831
1830
|
var m;
|
|
1832
1831
|
return (m = n.streamingManager) != null && m.replaceMicrophoneTrack ? n.streamingManager.replaceMicrophoneTrack(c) : Promise.reject(
|
|
1833
|
-
new
|
|
1832
|
+
new I(
|
|
1834
1833
|
"replaceMicrophoneTrack is only available on Expressive (V4) agents, after connect()"
|
|
1835
1834
|
)
|
|
1836
1835
|
);
|
|
@@ -1838,7 +1837,7 @@ async function Kn(e, t) {
|
|
|
1838
1837
|
publishCameraStream(c) {
|
|
1839
1838
|
var m;
|
|
1840
1839
|
return (m = n.streamingManager) != null && m.publishCameraStream ? n.streamingManager.publishCameraStream(c) : Promise.reject(
|
|
1841
|
-
new
|
|
1840
|
+
new I(
|
|
1842
1841
|
"publishCameraStream is only available on Expressive (V4) agents, after connect()"
|
|
1843
1842
|
)
|
|
1844
1843
|
);
|
|
@@ -1851,20 +1850,20 @@ async function Kn(e, t) {
|
|
|
1851
1850
|
var E, O, _;
|
|
1852
1851
|
const m = () => {
|
|
1853
1852
|
if (te(n.chatMode))
|
|
1854
|
-
throw new
|
|
1853
|
+
throw new I(`${n.chatMode} is enabled, chat is disabled`);
|
|
1855
1854
|
if (c.length >= He)
|
|
1856
|
-
throw new
|
|
1855
|
+
throw new I(`Message cannot be more than ${He} characters`);
|
|
1857
1856
|
if (c.length === 0)
|
|
1858
|
-
throw new
|
|
1857
|
+
throw new I("Message cannot be empty");
|
|
1859
1858
|
if (n.chatMode === L.Maintenance)
|
|
1860
|
-
throw new
|
|
1859
|
+
throw new I("Chat is in maintenance mode");
|
|
1861
1860
|
if (![L.TextOnly, L.Playground].includes(n.chatMode)) {
|
|
1862
1861
|
if (!n.streamingManager)
|
|
1863
|
-
throw new
|
|
1862
|
+
throw new I("Streaming manager is not initialized");
|
|
1864
1863
|
if (!n.chat)
|
|
1865
|
-
throw new
|
|
1864
|
+
throw new I("Chat is not initialized");
|
|
1866
1865
|
}
|
|
1867
|
-
},
|
|
1866
|
+
}, w = async () => {
|
|
1868
1867
|
var b;
|
|
1869
1868
|
if (!n.chat) {
|
|
1870
1869
|
const A = await Dt(
|
|
@@ -1881,10 +1880,10 @@ async function Kn(e, t) {
|
|
|
1881
1880
|
return n.chat.id;
|
|
1882
1881
|
}, M = async (b, A) => {
|
|
1883
1882
|
const J = n.chatMode === L.Playground;
|
|
1884
|
-
return
|
|
1883
|
+
return Ne(P && !J ? async () => {
|
|
1885
1884
|
var $;
|
|
1886
1885
|
return await (($ = n.streamingManager) == null ? void 0 : $.sendDataChannelMessage(
|
|
1887
|
-
|
|
1886
|
+
Re.Chat,
|
|
1888
1887
|
c
|
|
1889
1888
|
)), Promise.resolve({});
|
|
1890
1889
|
} : async () => {
|
|
@@ -1915,7 +1914,7 @@ async function Kn(e, t) {
|
|
|
1915
1914
|
return !((Me = $ == null ? void 0 : $.message) == null ? void 0 : Me.includes("Stream Error")) && !z ? ((Je = l.onError) == null || Je.call(l, $), !1) : !0;
|
|
1916
1915
|
},
|
|
1917
1916
|
onRetry: async () => {
|
|
1918
|
-
await V(), await
|
|
1917
|
+
await V(), await se(!1);
|
|
1919
1918
|
}
|
|
1920
1919
|
});
|
|
1921
1920
|
};
|
|
@@ -1924,15 +1923,15 @@ async function Kn(e, t) {
|
|
|
1924
1923
|
id: Z(),
|
|
1925
1924
|
role: "user",
|
|
1926
1925
|
content: c,
|
|
1927
|
-
parts:
|
|
1926
|
+
parts: pe(c),
|
|
1928
1927
|
createdAt: new Date(K.update()).toISOString()
|
|
1929
1928
|
}), (E = l.onNewMessage) == null || E.call(l, [...n.messages], "user");
|
|
1930
|
-
const b = await
|
|
1929
|
+
const b = await w(), A = await M([...n.messages], b);
|
|
1931
1930
|
return A.result && n.messages.push({
|
|
1932
1931
|
id: Z(),
|
|
1933
1932
|
role: "assistant",
|
|
1934
1933
|
content: A.result,
|
|
1935
|
-
parts:
|
|
1934
|
+
parts: pe(A.result),
|
|
1936
1935
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1937
1936
|
context: A.context,
|
|
1938
1937
|
matches: A.matches
|
|
@@ -1947,25 +1946,25 @@ async function Kn(e, t) {
|
|
|
1947
1946
|
throw ((_ = n.messages[n.messages.length - 1]) == null ? void 0 : _.role) === "assistant" && n.messages.pop(), d.track("agent-message-send", {
|
|
1948
1947
|
event: "error",
|
|
1949
1948
|
messages: n.messages.length,
|
|
1950
|
-
error:
|
|
1949
|
+
error: xe(b)
|
|
1951
1950
|
}), b;
|
|
1952
1951
|
}
|
|
1953
1952
|
},
|
|
1954
|
-
async rate(c, m,
|
|
1953
|
+
async rate(c, m, w) {
|
|
1955
1954
|
var O, _, b, A;
|
|
1956
1955
|
const M = n.messages.find((J) => J.id === c);
|
|
1957
1956
|
if (n.chat) {
|
|
1958
1957
|
if (!M)
|
|
1959
|
-
throw new
|
|
1960
|
-
} else throw new
|
|
1958
|
+
throw new I("Message not found");
|
|
1959
|
+
} else throw new I("Chat is not initialized");
|
|
1961
1960
|
const E = ((O = M.matches) == null ? void 0 : O.map((J) => [J.document_id, J.id])) ?? [];
|
|
1962
1961
|
return d.track("agent-rate", {
|
|
1963
|
-
event:
|
|
1962
|
+
event: w ? "update" : "create",
|
|
1964
1963
|
thumb: m === 1 ? "up" : "down",
|
|
1965
1964
|
knowledge_id: ((_ = S.knowledge) == null ? void 0 : _.id) ?? "",
|
|
1966
1965
|
matches: E,
|
|
1967
1966
|
score: m
|
|
1968
|
-
}),
|
|
1967
|
+
}), w ? D.updateRating(S.id, n.chat.id, w, {
|
|
1969
1968
|
knowledge_id: ((b = S.knowledge) == null ? void 0 : b.id) ?? "",
|
|
1970
1969
|
message_id: c,
|
|
1971
1970
|
matches: E,
|
|
@@ -1979,12 +1978,12 @@ async function Kn(e, t) {
|
|
|
1979
1978
|
},
|
|
1980
1979
|
async deleteRate(c) {
|
|
1981
1980
|
if (!n.chat)
|
|
1982
|
-
throw new
|
|
1981
|
+
throw new I("Chat is not initialized");
|
|
1983
1982
|
return d.track("agent-rate-delete", { type: "text" }), D.deleteRating(S.id, n.chat.id, c);
|
|
1984
1983
|
},
|
|
1985
1984
|
async submitFeedback(c, m) {
|
|
1986
1985
|
if (!n.chat)
|
|
1987
|
-
throw new
|
|
1986
|
+
throw new I("Chat is not initialized");
|
|
1988
1987
|
return d.track("agent-feedback", { rating: c, hasAnswer: !!m }), D.submitFeedback(S.id, n.chat.id, { rating: c, answer: m });
|
|
1989
1988
|
},
|
|
1990
1989
|
async speak(c) {
|
|
@@ -2002,66 +2001,66 @@ async function Kn(e, t) {
|
|
|
2002
2001
|
sentiment: c.sentiment
|
|
2003
2002
|
} : c;
|
|
2004
2003
|
}
|
|
2005
|
-
const
|
|
2006
|
-
if (!
|
|
2007
|
-
throw new
|
|
2004
|
+
const w = Pe(n.chatMode);
|
|
2005
|
+
if (!w && !n.streamingManager)
|
|
2006
|
+
throw new I("Please connect to the agent first");
|
|
2008
2007
|
const M = m();
|
|
2009
2008
|
d.track("agent-speak", M), K.update(), n.messages && M.type === "text" && (n.messages.push({
|
|
2010
2009
|
id: Z(),
|
|
2011
2010
|
role: "assistant",
|
|
2012
2011
|
content: M.input,
|
|
2013
|
-
parts:
|
|
2012
|
+
parts: pe(M.input),
|
|
2014
2013
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2015
2014
|
}), (_ = l.onNewMessage) == null || _.call(l, [...n.messages], "answer"));
|
|
2016
2015
|
const E = { duration: 0, videoId: "", status: "success" };
|
|
2017
|
-
return
|
|
2016
|
+
return w || !n.streamingManager ? E : await n.streamingManager.speak({
|
|
2018
2017
|
script: M,
|
|
2019
2018
|
metadata: { chat_id: (b = n.chat) == null ? void 0 : b.id, agent_id: S.id }
|
|
2020
2019
|
}) ?? E;
|
|
2021
2020
|
},
|
|
2022
|
-
interrupt:
|
|
2023
|
-
registerClientTool:
|
|
2024
|
-
unregisterClientTool:
|
|
2021
|
+
interrupt: ae,
|
|
2022
|
+
registerClientTool: ie,
|
|
2023
|
+
unregisterClientTool: T
|
|
2025
2024
|
};
|
|
2026
2025
|
}
|
|
2027
2026
|
function qn(e) {
|
|
2028
2027
|
return e.some((t) => t.executionMode === "blocking");
|
|
2029
2028
|
}
|
|
2030
2029
|
export {
|
|
2031
|
-
|
|
2030
|
+
we as A,
|
|
2032
2031
|
q as B,
|
|
2033
2032
|
F as C,
|
|
2034
|
-
|
|
2033
|
+
kt as D,
|
|
2035
2034
|
ht as H,
|
|
2036
|
-
|
|
2035
|
+
Re as I,
|
|
2037
2036
|
Nt as N,
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2037
|
+
Tt as P,
|
|
2038
|
+
k as S,
|
|
2039
|
+
Be as T,
|
|
2040
|
+
I as V,
|
|
2042
2041
|
Ot as W,
|
|
2043
2042
|
hn as a,
|
|
2044
2043
|
H as b,
|
|
2045
2044
|
vt as c,
|
|
2046
|
-
|
|
2045
|
+
ke as d,
|
|
2047
2046
|
pt as e,
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2047
|
+
R as f,
|
|
2048
|
+
ge as g,
|
|
2049
|
+
Rn as h,
|
|
2051
2050
|
Wn as i,
|
|
2052
2051
|
C as j,
|
|
2053
|
-
|
|
2052
|
+
ne as k,
|
|
2054
2053
|
K as l,
|
|
2055
2054
|
jt as m,
|
|
2056
2055
|
Jn as n,
|
|
2057
2056
|
L as o,
|
|
2058
2057
|
Bt as p,
|
|
2059
|
-
|
|
2058
|
+
he as q,
|
|
2060
2059
|
_t as r,
|
|
2061
2060
|
Kn as s,
|
|
2062
|
-
|
|
2061
|
+
xe as t,
|
|
2063
2062
|
qn as u,
|
|
2064
2063
|
Hn as v,
|
|
2065
|
-
|
|
2064
|
+
yt as w
|
|
2066
2065
|
};
|
|
2067
|
-
//# sourceMappingURL=index-
|
|
2066
|
+
//# sourceMappingURL=index-DfRq-xUG.js.map
|