@d-id/client-sdk 1.1.58-staging.273 → 1.1.58-staging.275
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 +206 -201
- package/dist/index.umd.cjs +3 -3
- package/dist/src/types/entities/agents/manager.d.ts +5 -5
- package/dist/src/types/stream/stream.d.ts +34 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var Et = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var Ce = (e, n, i) =>
|
|
2
|
+
var Mt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
|
+
var Ce = (e, n, i) => Mt(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 }));
|
|
@@ -10,7 +10,7 @@ class Ie extends Error {
|
|
|
10
10
|
this.kind = i, this.description = r, this.error = s;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class kt extends Ie {
|
|
14
14
|
constructor(n, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -48,7 +48,7 @@ const Hn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var E = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(E || {}), 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 || {}), M = /* @__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))(M || {}), 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
53
|
}, ut = (e) => new Promise((n) => setTimeout(n, e)), ge = (e = 16) => {
|
|
54
54
|
const n = new Uint8Array(e);
|
|
@@ -399,8 +399,8 @@ function on(e, n, i, r) {
|
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
401
|
const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), sn = {
|
|
402
|
-
[
|
|
403
|
-
[
|
|
402
|
+
[M.ChatAnswer]: X.Answer,
|
|
403
|
+
[M.ChatPartial]: X.Partial
|
|
404
404
|
};
|
|
405
405
|
function cn(e, n, i) {
|
|
406
406
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
@@ -558,8 +558,8 @@ function ln(e, n) {
|
|
|
558
558
|
a = g, o = l, r = !0, s = setTimeout(t, Se);
|
|
559
559
|
return;
|
|
560
560
|
}
|
|
561
|
-
const v = g - a,
|
|
562
|
-
if (a = g, o = l,
|
|
561
|
+
const v = g - a, P = l - o;
|
|
562
|
+
if (a = g, o = l, P > 0 && v > 0) {
|
|
563
563
|
i = !1, n(c);
|
|
564
564
|
return;
|
|
565
565
|
}
|
|
@@ -577,7 +577,7 @@ function ln(e, n) {
|
|
|
577
577
|
}
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
|
-
const
|
|
580
|
+
const ke = 100, fn = Math.max(Math.ceil(400 / ke), 1), mn = 0.25, gn = 0.28;
|
|
581
581
|
function hn() {
|
|
582
582
|
let e = 0, n, i, r = 0;
|
|
583
583
|
return (s) => {
|
|
@@ -596,27 +596,27 @@ function hn() {
|
|
|
596
596
|
}
|
|
597
597
|
function yt(e, n, i, r, s) {
|
|
598
598
|
let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
|
|
599
|
-
const
|
|
599
|
+
const P = hn();
|
|
600
600
|
async function N() {
|
|
601
601
|
const B = await e();
|
|
602
602
|
if (!B)
|
|
603
603
|
return;
|
|
604
|
-
const { isReceiving: F, avgJitterDelayInInterval:
|
|
604
|
+
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: k } = P(B), Y = un(B);
|
|
605
605
|
if (F)
|
|
606
|
-
t = 0, l = k - v, g =
|
|
606
|
+
t = 0, l = k - v, g = I < mn ? ae.Strong : I > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0), d || (r == null || r(E.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
|
|
607
607
|
else if (d && (t++, t >= fn)) {
|
|
608
|
-
const Q = rt(o,
|
|
609
|
-
r == null || r(
|
|
608
|
+
const Q = rt(o, ke, c);
|
|
609
|
+
r == null || r(E.Stop, Q), n() || i(), v = k, d = !1;
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
return {
|
|
613
613
|
start: () => {
|
|
614
|
-
a || (a = setInterval(N,
|
|
614
|
+
a || (a = setInterval(N, ke));
|
|
615
615
|
},
|
|
616
616
|
stop: () => {
|
|
617
617
|
a && (clearInterval(a), a = null);
|
|
618
618
|
},
|
|
619
|
-
getReport: () => rt(o,
|
|
619
|
+
getReport: () => rt(o, ke, c)
|
|
620
620
|
};
|
|
621
621
|
}
|
|
622
622
|
const it = 2e4;
|
|
@@ -642,26 +642,26 @@ const wn = {
|
|
|
642
642
|
var Ue = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ue || {});
|
|
643
643
|
function Be(e, n, i) {
|
|
644
644
|
var r, s;
|
|
645
|
-
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i,
|
|
645
|
+
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
646
|
}
|
|
647
647
|
async function yn(e, n, i) {
|
|
648
648
|
var Je;
|
|
649
649
|
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await pn(), { callbacks: t, auth: d, baseURL: h, analytics: g } = i;
|
|
650
650
|
let l = null, v = !1;
|
|
651
|
-
const
|
|
651
|
+
const P = se.Fluent;
|
|
652
652
|
let N = null;
|
|
653
653
|
const B = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
|
|
654
|
-
let
|
|
654
|
+
let I = null, k = null, Y = null, Q = !1;
|
|
655
655
|
l = new s({
|
|
656
656
|
adaptiveStream: !1,
|
|
657
657
|
// Must be false to use mediaStreamTrack directly
|
|
658
658
|
dynacast: !0
|
|
659
659
|
});
|
|
660
660
|
let U = null, te = W.Idle, ne = !0;
|
|
661
|
-
const
|
|
661
|
+
const $ = on(d, h || Ee, e, t.onError);
|
|
662
662
|
let K, H, re, de = !0;
|
|
663
663
|
try {
|
|
664
|
-
const u = await
|
|
664
|
+
const u = await $.createStream({
|
|
665
665
|
transport: n.transport,
|
|
666
666
|
chat_persist: n.chat_persist ?? !0
|
|
667
667
|
}), { id: m, session_token: p, session_url: S, interrupt_enabled: _ } = u;
|
|
@@ -690,25 +690,25 @@ async function yn(e, n, i) {
|
|
|
690
690
|
Be(u, r, t);
|
|
691
691
|
}
|
|
692
692
|
g.enrich({
|
|
693
|
-
"stream-type":
|
|
693
|
+
"stream-type": P
|
|
694
694
|
});
|
|
695
695
|
function f(u) {
|
|
696
696
|
var m, p, S, _;
|
|
697
697
|
switch (r("Connection state changed:", u), u) {
|
|
698
698
|
case o.Connecting:
|
|
699
|
-
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t,
|
|
699
|
+
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, x.Connecting, "livekit:connecting");
|
|
700
700
|
break;
|
|
701
701
|
case o.Connected:
|
|
702
702
|
r("LiveKit room connected successfully"), v = !0;
|
|
703
703
|
break;
|
|
704
704
|
case o.Disconnected:
|
|
705
|
-
r("LiveKit room disconnected"), v = !1, Q = !1, B.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t,
|
|
705
|
+
r("LiveKit room disconnected"), v = !1, Q = !1, B.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, x.Disconnected, "livekit:disconnected");
|
|
706
706
|
break;
|
|
707
707
|
case o.Reconnecting:
|
|
708
|
-
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t,
|
|
708
|
+
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, x.Connecting, "livekit:reconnecting");
|
|
709
709
|
break;
|
|
710
710
|
case o.SignalReconnecting:
|
|
711
|
-
r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t,
|
|
711
|
+
r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, x.Connecting, "livekit:signal-reconnecting");
|
|
712
712
|
break;
|
|
713
713
|
}
|
|
714
714
|
}
|
|
@@ -724,14 +724,14 @@ async function yn(e, n, i) {
|
|
|
724
724
|
}
|
|
725
725
|
function D() {
|
|
726
726
|
var u;
|
|
727
|
-
Y !==
|
|
727
|
+
Y !== E.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = E.Start, (u = t.onVideoStateChange) == null || u.call(t, E.Start));
|
|
728
728
|
}
|
|
729
729
|
function b(u) {
|
|
730
730
|
var m;
|
|
731
|
-
Y !==
|
|
731
|
+
Y !== E.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = E.Stop, (m = t.onVideoStateChange) == null || m.call(t, E.Stop, u));
|
|
732
732
|
}
|
|
733
733
|
function J(u, m, p) {
|
|
734
|
-
var _,
|
|
734
|
+
var _, L, q;
|
|
735
735
|
r(`Track subscribed: ${u.kind} from ${p.identity}`);
|
|
736
736
|
const S = u.mediaStreamTrack;
|
|
737
737
|
if (!S) {
|
|
@@ -745,42 +745,46 @@ async function yn(e, n, i) {
|
|
|
745
745
|
const ye = oe.get(!0);
|
|
746
746
|
let ve = 0;
|
|
747
747
|
if (V) {
|
|
748
|
-
const qe = ((We = (Oe =
|
|
748
|
+
const qe = ((We = (Oe = I == null ? void 0 : I.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
|
|
749
749
|
ve = qe > 0 ? Math.round(qe * 1e3) : 0;
|
|
750
750
|
}
|
|
751
751
|
const fe = ye > 0 ? ye + (V ?? 0) + ve : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
|
|
752
752
|
(He = t.onFirstAudioDetected) == null || He.call(t, { latency: fe, networkLatency: ce });
|
|
753
753
|
}
|
|
754
|
-
)), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (
|
|
754
|
+
)), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (L = t.onSrcObjectReady) == null || L.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, x.Connected, "livekit:track-subscribed")), I = yt(
|
|
755
755
|
() => u.getRTCStatsReport(),
|
|
756
756
|
() => v,
|
|
757
757
|
Vt,
|
|
758
758
|
(V, ie) => {
|
|
759
|
-
r(`Video state change: ${V}`), V ===
|
|
759
|
+
r(`Video state change: ${V}`), V === E.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), D()) : V === E.Stop && b(ie);
|
|
760
760
|
}
|
|
761
|
-
),
|
|
761
|
+
), I.start());
|
|
762
762
|
}
|
|
763
763
|
function w(u, m, p) {
|
|
764
|
-
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (b(
|
|
764
|
+
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (b(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
|
|
765
765
|
}
|
|
766
766
|
function y(u, m) {
|
|
767
767
|
var S;
|
|
768
768
|
const p = sn[u];
|
|
769
769
|
p && ((S = t.onMessage) == null || S.call(t, p, { event: p, ...m }));
|
|
770
770
|
}
|
|
771
|
-
function
|
|
772
|
-
var p, S, _;
|
|
773
|
-
if (u ===
|
|
774
|
-
te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t,
|
|
771
|
+
function T(u, m) {
|
|
772
|
+
var p, S, _, L;
|
|
773
|
+
if (u === M.ToolCallStarted) {
|
|
774
|
+
te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, M.ToolCallStarted, m);
|
|
775
775
|
return;
|
|
776
776
|
}
|
|
777
|
-
u ===
|
|
777
|
+
if (u === M.ToolCallDone) {
|
|
778
|
+
(_ = t.onToolEvent) == null || _.call(t, M.ToolCallDone, m);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
u === M.ToolCallError && ((L = t.onToolEvent) == null || L.call(t, M.ToolCallError, m));
|
|
778
782
|
}
|
|
779
|
-
function
|
|
780
|
-
var p, S, _,
|
|
781
|
-
if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u ===
|
|
783
|
+
function j(u, m) {
|
|
784
|
+
var p, S, _, L, q;
|
|
785
|
+
if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === M.StreamVideoCreated) {
|
|
782
786
|
te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), k == null || k.arm({
|
|
783
|
-
sttLatency: (
|
|
787
|
+
sttLatency: (L = m == null ? void 0 : m.stt) == null ? void 0 : L.latency,
|
|
784
788
|
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
785
789
|
});
|
|
786
790
|
return;
|
|
@@ -788,12 +792,12 @@ async function yn(e, n, i) {
|
|
|
788
792
|
ne && (te = W.Idle, (q = t.onAgentActivityStateChange) == null || q.call(t, W.Idle));
|
|
789
793
|
}
|
|
790
794
|
function G(u, m) {
|
|
791
|
-
var
|
|
792
|
-
const p = ((q = (
|
|
795
|
+
var L, q, V, ie;
|
|
796
|
+
const p = ((q = (L = I == null ? void 0 : I.getReport()) == null ? void 0 : L.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: S };
|
|
793
797
|
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (_.sentiment = {
|
|
794
798
|
id: m.metadata.sentiment.id,
|
|
795
799
|
name: m.metadata.sentiment.sentiment
|
|
796
|
-
}), (ie = t.onMessage) == null || ie.call(t, u, _),
|
|
800
|
+
}), (ie = t.onMessage) == null || ie.call(t, u, _), j(u, m);
|
|
797
801
|
}
|
|
798
802
|
function he(u, m) {
|
|
799
803
|
var p;
|
|
@@ -803,25 +807,26 @@ async function yn(e, n, i) {
|
|
|
803
807
|
});
|
|
804
808
|
}
|
|
805
809
|
const Z = {
|
|
806
|
-
[
|
|
807
|
-
[
|
|
808
|
-
[
|
|
809
|
-
[
|
|
810
|
-
[
|
|
811
|
-
[
|
|
812
|
-
[
|
|
813
|
-
[
|
|
814
|
-
[
|
|
810
|
+
[M.ChatAnswer]: y,
|
|
811
|
+
[M.ChatPartial]: y,
|
|
812
|
+
[M.ToolCallStarted]: T,
|
|
813
|
+
[M.ToolCallDone]: T,
|
|
814
|
+
[M.ToolCallError]: T,
|
|
815
|
+
[M.StreamVideoCreated]: G,
|
|
816
|
+
[M.StreamVideoDone]: G,
|
|
817
|
+
[M.StreamVideoError]: G,
|
|
818
|
+
[M.StreamVideoRejected]: G,
|
|
819
|
+
[M.ChatAudioTranscribed]: he
|
|
815
820
|
};
|
|
816
821
|
function z(u, m, p, S) {
|
|
817
822
|
const _ = new TextDecoder().decode(u);
|
|
818
823
|
try {
|
|
819
|
-
const
|
|
820
|
-
if (r("Data received:", { subject: q, data:
|
|
824
|
+
const L = JSON.parse(_), q = S || L.subject;
|
|
825
|
+
if (r("Data received:", { subject: q, data: L }), !q) return;
|
|
821
826
|
const V = Z[q];
|
|
822
|
-
V == null || V(q,
|
|
823
|
-
} catch (
|
|
824
|
-
r("Failed to parse data channel message:",
|
|
827
|
+
V == null || V(q, L);
|
|
828
|
+
} catch (L) {
|
|
829
|
+
r("Failed to parse data channel message:", L);
|
|
825
830
|
}
|
|
826
831
|
}
|
|
827
832
|
function ee(u) {
|
|
@@ -835,16 +840,16 @@ async function yn(e, n, i) {
|
|
|
835
840
|
function le(u, m, p) {
|
|
836
841
|
r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
|
|
837
842
|
}
|
|
838
|
-
function
|
|
843
|
+
function Me(u, m, p) {
|
|
839
844
|
for (const [S, _] of p)
|
|
840
845
|
if (_.source === m && _.track) {
|
|
841
|
-
const
|
|
842
|
-
if (
|
|
846
|
+
const L = _.track.mediaStreamTrack;
|
|
847
|
+
if (L === u || (L == null ? void 0 : L.id) === u.id)
|
|
843
848
|
return _;
|
|
844
849
|
}
|
|
845
850
|
return null;
|
|
846
851
|
}
|
|
847
|
-
async function pe(u, m, p, S, _,
|
|
852
|
+
async function pe(u, m, p, S, _, L) {
|
|
848
853
|
var ye, ve, fe;
|
|
849
854
|
if (!v || !l)
|
|
850
855
|
throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
|
|
@@ -855,7 +860,7 @@ async function yn(e, n, i) {
|
|
|
855
860
|
const q = p(m);
|
|
856
861
|
if (q.length === 0)
|
|
857
862
|
throw new Error(`No ${S} track found in the provided MediaStream`);
|
|
858
|
-
const V = q[0], ie =
|
|
863
|
+
const V = q[0], ie = Me(V, S, _());
|
|
859
864
|
if (ie) {
|
|
860
865
|
r(`${S} track is already published, skipping`, {
|
|
861
866
|
trackId: V.id,
|
|
@@ -865,7 +870,7 @@ async function yn(e, n, i) {
|
|
|
865
870
|
}
|
|
866
871
|
if ((fe = u.publication) != null && fe.track) {
|
|
867
872
|
const ce = u.publication.track.mediaStreamTrack;
|
|
868
|
-
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await
|
|
873
|
+
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await L());
|
|
869
874
|
}
|
|
870
875
|
r(`Publishing ${S} track from provided MediaStream`, { trackId: V.id }), u.isPublishing = !0;
|
|
871
876
|
try {
|
|
@@ -947,7 +952,7 @@ async function yn(e, n, i) {
|
|
|
947
952
|
}
|
|
948
953
|
async function Le(u) {
|
|
949
954
|
var m, p;
|
|
950
|
-
U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t,
|
|
955
|
+
U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([Ae(), _e()]), await l.disconnect()), St(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
|
|
951
956
|
}
|
|
952
957
|
return {
|
|
953
958
|
speak(u) {
|
|
@@ -967,22 +972,22 @@ async function yn(e, n, i) {
|
|
|
967
972
|
}
|
|
968
973
|
if (!l || !re || !H)
|
|
969
974
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
970
|
-
r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t,
|
|
975
|
+
r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, x.Connecting, "user:reconnect");
|
|
971
976
|
try {
|
|
972
977
|
if (await l.connect(re, H), r("Room reconnected"), v = !0, l.remoteParticipants.size === 0) {
|
|
973
978
|
if (r("Waiting for agent to join..."), !await new Promise((S) => {
|
|
974
979
|
const _ = setTimeout(() => {
|
|
975
|
-
l == null || l.off(a.ParticipantConnected,
|
|
976
|
-
}, 5e3),
|
|
977
|
-
clearTimeout(_), l == null || l.off(a.ParticipantConnected,
|
|
980
|
+
l == null || l.off(a.ParticipantConnected, L), S(!1);
|
|
981
|
+
}, 5e3), L = () => {
|
|
982
|
+
clearTimeout(_), l == null || l.off(a.ParticipantConnected, L), S(!0);
|
|
978
983
|
};
|
|
979
|
-
l == null || l.on(a.ParticipantConnected,
|
|
984
|
+
l == null || l.on(a.ParticipantConnected, L);
|
|
980
985
|
}))
|
|
981
986
|
throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
|
|
982
987
|
r("Agent joined, reconnection successful");
|
|
983
988
|
}
|
|
984
989
|
} catch (p) {
|
|
985
|
-
throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t,
|
|
990
|
+
throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, x.Fail, "user:reconnect-failed"), p;
|
|
986
991
|
}
|
|
987
992
|
},
|
|
988
993
|
sendDataChannelMessage: Rt,
|
|
@@ -999,7 +1004,7 @@ async function yn(e, n, i) {
|
|
|
999
1004
|
},
|
|
1000
1005
|
sessionId: K,
|
|
1001
1006
|
streamId: K,
|
|
1002
|
-
streamType:
|
|
1007
|
+
streamType: P,
|
|
1003
1008
|
interruptAvailable: de,
|
|
1004
1009
|
isInterruptible: ne
|
|
1005
1010
|
};
|
|
@@ -1022,7 +1027,7 @@ function Cn(e, n, i) {
|
|
|
1022
1027
|
}
|
|
1023
1028
|
async function Sn(e, n) {
|
|
1024
1029
|
const i = {
|
|
1025
|
-
type:
|
|
1030
|
+
type: M.StreamInterrupt,
|
|
1026
1031
|
videoId: n,
|
|
1027
1032
|
timestamp: Date.now()
|
|
1028
1033
|
};
|
|
@@ -1057,7 +1062,7 @@ async function En(e) {
|
|
|
1057
1062
|
}
|
|
1058
1063
|
return i;
|
|
1059
1064
|
}
|
|
1060
|
-
async function
|
|
1065
|
+
async function Mn(e, n, i, r) {
|
|
1061
1066
|
const s = i != null && i.onMessage ? [i.onMessage] : [], a = await En({
|
|
1062
1067
|
auth: e,
|
|
1063
1068
|
host: n,
|
|
@@ -1079,7 +1084,7 @@ async function kn(e, n, i, r) {
|
|
|
1079
1084
|
subscribeToEvents: (o) => s.push(o)
|
|
1080
1085
|
};
|
|
1081
1086
|
}
|
|
1082
|
-
function
|
|
1087
|
+
function kn(e) {
|
|
1083
1088
|
if (e.answer !== void 0)
|
|
1084
1089
|
return e.answer;
|
|
1085
1090
|
let n = 0, i = "";
|
|
@@ -1125,7 +1130,7 @@ function Dn(e, n, i, r, s, a) {
|
|
|
1125
1130
|
return;
|
|
1126
1131
|
const { content: d, sequence: h } = n;
|
|
1127
1132
|
e === X.Partial ? i[h] = d : i.answer = d;
|
|
1128
|
-
const g =
|
|
1133
|
+
const g = kn(i);
|
|
1129
1134
|
(t.content !== g || e === X.Answer) && (t.content = g, t.parts = Te(g), s == null || s([...r.messages], e));
|
|
1130
1135
|
}
|
|
1131
1136
|
function An(e, n, i, r, s) {
|
|
@@ -1141,22 +1146,22 @@ function An(e, n, i, r, s) {
|
|
|
1141
1146
|
onMessage: (d, h) => {
|
|
1142
1147
|
var g, l;
|
|
1143
1148
|
if ("content" in h) {
|
|
1144
|
-
const v = d ===
|
|
1149
|
+
const v = d === M.ChatAnswer ? X.Answer : d === M.ChatAudioTranscribed ? X.Transcribe : d;
|
|
1145
1150
|
Dn(v, h, a, n, t, o), v === X.Answer && e.track("agent-message-received", {
|
|
1146
1151
|
content: h.content,
|
|
1147
1152
|
messages: n.messages.length,
|
|
1148
1153
|
mode: n.chatMode
|
|
1149
1154
|
});
|
|
1150
1155
|
} else {
|
|
1151
|
-
const v =
|
|
1156
|
+
const v = M, P = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], N = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
|
|
1152
1157
|
if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1153
1158
|
const F = n.messages[n.messages.length - 1];
|
|
1154
1159
|
if ((F == null ? void 0 : F.role) === "assistant") {
|
|
1155
|
-
const
|
|
1156
|
-
n.messages[n.messages.length - 1] =
|
|
1160
|
+
const I = { ...F, sentiment: h.sentiment };
|
|
1161
|
+
n.messages[n.messages.length - 1] = I, t == null || t([...n.messages], c);
|
|
1157
1162
|
}
|
|
1158
1163
|
}
|
|
1159
|
-
if (
|
|
1164
|
+
if (P.includes(d)) {
|
|
1160
1165
|
const F = d.split("/")[1];
|
|
1161
1166
|
N.includes(d) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, d, ["done"]);
|
|
1162
1167
|
}
|
|
@@ -1206,21 +1211,21 @@ const bn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window
|
|
|
1206
1211
|
function at(e) {
|
|
1207
1212
|
switch (e) {
|
|
1208
1213
|
case "connected":
|
|
1209
|
-
return
|
|
1214
|
+
return x.Connected;
|
|
1210
1215
|
case "checking":
|
|
1211
|
-
return
|
|
1216
|
+
return x.Connecting;
|
|
1212
1217
|
case "failed":
|
|
1213
|
-
return
|
|
1218
|
+
return x.Fail;
|
|
1214
1219
|
case "new":
|
|
1215
|
-
return
|
|
1220
|
+
return x.New;
|
|
1216
1221
|
case "closed":
|
|
1217
|
-
return
|
|
1222
|
+
return x.Closed;
|
|
1218
1223
|
case "disconnected":
|
|
1219
|
-
return
|
|
1224
|
+
return x.Disconnected;
|
|
1220
1225
|
case "completed":
|
|
1221
|
-
return
|
|
1226
|
+
return x.Completed;
|
|
1222
1227
|
default:
|
|
1223
|
-
return
|
|
1228
|
+
return x.New;
|
|
1224
1229
|
}
|
|
1225
1230
|
}
|
|
1226
1231
|
const Ln = (e) => (n) => {
|
|
@@ -1239,7 +1244,7 @@ function Pn({
|
|
|
1239
1244
|
report: r,
|
|
1240
1245
|
log: s
|
|
1241
1246
|
}) {
|
|
1242
|
-
e ===
|
|
1247
|
+
e === E.Start && n === E.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && n === E.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, r));
|
|
1243
1248
|
}
|
|
1244
1249
|
function xn({
|
|
1245
1250
|
statsSignal: e,
|
|
@@ -1249,7 +1254,7 @@ function xn({
|
|
|
1249
1254
|
report: s,
|
|
1250
1255
|
log: a
|
|
1251
1256
|
}) {
|
|
1252
|
-
e ===
|
|
1257
|
+
e === E.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, s)), n === E.Start ? r == null || r(W.Talking) : n === E.Stop && (r == null || r(W.Idle));
|
|
1253
1258
|
}
|
|
1254
1259
|
function ot({
|
|
1255
1260
|
statsSignal: e,
|
|
@@ -1272,8 +1277,8 @@ function ot({
|
|
|
1272
1277
|
async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, c) {
|
|
1273
1278
|
var J;
|
|
1274
1279
|
const t = pt(i, "WebRTCStreamingManager"), d = Ln(t);
|
|
1275
|
-
let h = !1, g = !1, l =
|
|
1276
|
-
const { startConnection:
|
|
1280
|
+
let h = !1, g = !1, l = E.Stop, v = E.Stop;
|
|
1281
|
+
const { startConnection: P, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } = _n(
|
|
1277
1282
|
s,
|
|
1278
1283
|
a,
|
|
1279
1284
|
e,
|
|
@@ -1287,7 +1292,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1287
1292
|
interrupt_enabled: ne
|
|
1288
1293
|
} = await F(n, c);
|
|
1289
1294
|
(J = r.onStreamCreated) == null || J.call(r, { stream_id: k, session_id: U, agent_id: e });
|
|
1290
|
-
const
|
|
1295
|
+
const $ = new bn({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
|
|
1291
1296
|
if (!U)
|
|
1292
1297
|
throw new Error("Could not create session_id");
|
|
1293
1298
|
const H = te ? se.Fluent : se.Legacy;
|
|
@@ -1296,9 +1301,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1296
1301
|
});
|
|
1297
1302
|
const re = n.stream_warmup && !te, de = () => h, ue = () => {
|
|
1298
1303
|
var w;
|
|
1299
|
-
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r,
|
|
1304
|
+
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, x.Connected));
|
|
1300
1305
|
}, f = yt(
|
|
1301
|
-
() =>
|
|
1306
|
+
() => $.getStats(),
|
|
1302
1307
|
de,
|
|
1303
1308
|
ue,
|
|
1304
1309
|
(w, y) => ot({
|
|
@@ -1315,11 +1320,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1315
1320
|
return (y = r.onConnectivityStateChange) == null ? void 0 : y.call(r, w);
|
|
1316
1321
|
}
|
|
1317
1322
|
);
|
|
1318
|
-
f.start(),
|
|
1323
|
+
f.start(), $.onicecandidate = (w) => {
|
|
1319
1324
|
var y;
|
|
1320
1325
|
t("peerConnection.onicecandidate", w);
|
|
1321
1326
|
try {
|
|
1322
|
-
w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ?
|
|
1327
|
+
w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? I(
|
|
1323
1328
|
k,
|
|
1324
1329
|
{
|
|
1325
1330
|
candidate: w.candidate.candidate,
|
|
@@ -1328,9 +1333,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1328
1333
|
},
|
|
1329
1334
|
U,
|
|
1330
1335
|
c
|
|
1331
|
-
) :
|
|
1332
|
-
} catch (
|
|
1333
|
-
(y = r.onError) == null || y.call(r,
|
|
1336
|
+
) : I(k, { candidate: null }, U, c);
|
|
1337
|
+
} catch (T) {
|
|
1338
|
+
(y = r.onError) == null || y.call(r, T, { streamId: k });
|
|
1334
1339
|
}
|
|
1335
1340
|
}, K.onopen = () => {
|
|
1336
1341
|
g = !0, (!re || h) && ue();
|
|
@@ -1340,11 +1345,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1340
1345
|
(y = r.onVideoIdChange) == null || y.call(r, w);
|
|
1341
1346
|
};
|
|
1342
1347
|
function R(w, y) {
|
|
1343
|
-
if (w ===
|
|
1344
|
-
const
|
|
1345
|
-
C(
|
|
1348
|
+
if (w === M.StreamStarted && typeof y == "object" && "metadata" in y) {
|
|
1349
|
+
const T = y.metadata;
|
|
1350
|
+
C(T.videoId);
|
|
1346
1351
|
}
|
|
1347
|
-
w ===
|
|
1352
|
+
w === M.StreamDone && C(null), l = w === M.StreamStarted ? E.Start : E.Stop, ot({
|
|
1348
1353
|
statsSignal: H === se.Legacy ? v : void 0,
|
|
1349
1354
|
dataChannelSignal: l,
|
|
1350
1355
|
onVideoStateChange: r.onVideoStateChange,
|
|
@@ -1354,30 +1359,30 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1354
1359
|
});
|
|
1355
1360
|
}
|
|
1356
1361
|
function A(w, y) {
|
|
1357
|
-
var
|
|
1358
|
-
const
|
|
1359
|
-
|
|
1362
|
+
var j;
|
|
1363
|
+
const T = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
|
|
1364
|
+
T && o.enrich({ streamMetadata: T }), (j = r.onStreamReady) == null || j.call(r);
|
|
1360
1365
|
}
|
|
1361
1366
|
const D = {
|
|
1362
|
-
[
|
|
1363
|
-
[
|
|
1364
|
-
[
|
|
1367
|
+
[M.StreamStarted]: R,
|
|
1368
|
+
[M.StreamDone]: R,
|
|
1369
|
+
[M.StreamReady]: A
|
|
1365
1370
|
};
|
|
1366
1371
|
K.onmessage = (w) => {
|
|
1367
|
-
var
|
|
1368
|
-
const { subject: y, data:
|
|
1369
|
-
(
|
|
1370
|
-
},
|
|
1372
|
+
var j;
|
|
1373
|
+
const { subject: y, data: T } = d(w.data);
|
|
1374
|
+
(j = D[y]) == null || j.call(D, y, T);
|
|
1375
|
+
}, $.oniceconnectionstatechange = () => {
|
|
1371
1376
|
var y;
|
|
1372
|
-
t("peerConnection.oniceconnectionstatechange => " +
|
|
1373
|
-
const w = at(
|
|
1374
|
-
w !==
|
|
1375
|
-
},
|
|
1377
|
+
t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
|
|
1378
|
+
const w = at($.iceConnectionState);
|
|
1379
|
+
w !== x.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
|
|
1380
|
+
}, $.ontrack = (w) => {
|
|
1376
1381
|
var y;
|
|
1377
1382
|
t("peerConnection.ontrack", w), t("CALLBACK: onSrcObjectReady"), (y = r.onSrcObjectReady) == null || y.call(r, w.streams[0]);
|
|
1378
|
-
}, await
|
|
1379
|
-
const b = await
|
|
1380
|
-
return t("create answer OK"), await
|
|
1383
|
+
}, await $.setRemoteDescription(Y), t("set remote description OK");
|
|
1384
|
+
const b = await $.createAnswer();
|
|
1385
|
+
return t("create answer OK"), await $.setLocalDescription(b), t("set local description OK"), await P(k, b, U, c), t("start connection OK"), {
|
|
1381
1386
|
/**
|
|
1382
1387
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1383
1388
|
* @param payload
|
|
@@ -1391,19 +1396,19 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1391
1396
|
async disconnect() {
|
|
1392
1397
|
var w;
|
|
1393
1398
|
if (k) {
|
|
1394
|
-
const y = at(
|
|
1395
|
-
if (
|
|
1396
|
-
if (y ===
|
|
1399
|
+
const y = at($.iceConnectionState);
|
|
1400
|
+
if ($) {
|
|
1401
|
+
if (y === x.New) {
|
|
1397
1402
|
f.stop();
|
|
1398
1403
|
return;
|
|
1399
1404
|
}
|
|
1400
|
-
|
|
1405
|
+
$.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
|
|
1401
1406
|
}
|
|
1402
1407
|
try {
|
|
1403
|
-
y ===
|
|
1408
|
+
y === x.Connected && await B(k, U).catch((T) => {
|
|
1404
1409
|
});
|
|
1405
|
-
} catch (
|
|
1406
|
-
t("Error on close stream connection",
|
|
1410
|
+
} catch (T) {
|
|
1411
|
+
t("Error on close stream connection", T);
|
|
1407
1412
|
}
|
|
1408
1413
|
(w = r.onAgentActivityStateChange) == null || w.call(r, W.Idle), f.stop();
|
|
1409
1414
|
}
|
|
@@ -1412,7 +1417,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1412
1417
|
* Method to send data channel messages to the server
|
|
1413
1418
|
*/
|
|
1414
1419
|
sendDataChannelMessage(w) {
|
|
1415
|
-
var y,
|
|
1420
|
+
var y, T;
|
|
1416
1421
|
if (!h || K.readyState !== "open") {
|
|
1417
1422
|
t("Data channel is not ready for sending messages"), (y = r.onError) == null || y.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1418
1423
|
streamId: k
|
|
@@ -1421,8 +1426,8 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1421
1426
|
}
|
|
1422
1427
|
try {
|
|
1423
1428
|
K.send(w);
|
|
1424
|
-
} catch (
|
|
1425
|
-
t("Error sending data channel message",
|
|
1429
|
+
} catch (j) {
|
|
1430
|
+
t("Error sending data channel message", j), (T = r.onError) == null || T.call(r, j, { streamId: k });
|
|
1426
1431
|
}
|
|
1427
1432
|
},
|
|
1428
1433
|
/**
|
|
@@ -1491,7 +1496,7 @@ function Vn(e, n, i, r, s) {
|
|
|
1491
1496
|
s === se.Fluent ? Un(e, n, i, r, s) : Jn(e, n, i, r, s);
|
|
1492
1497
|
}
|
|
1493
1498
|
function Un(e, n, i, r, s) {
|
|
1494
|
-
e ===
|
|
1499
|
+
e === E.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === E.Stop && r.track("stream-session", {
|
|
1495
1500
|
event: "stop",
|
|
1496
1501
|
is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
|
|
1497
1502
|
background: n.presenter.type === "clip" && n.presenter.background,
|
|
@@ -1500,9 +1505,9 @@ function Un(e, n, i, r, s) {
|
|
|
1500
1505
|
});
|
|
1501
1506
|
}
|
|
1502
1507
|
function st(e, n, i, r, s) {
|
|
1503
|
-
e ===
|
|
1504
|
-
|
|
1505
|
-
]) : e ===
|
|
1508
|
+
e === E.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
|
|
1509
|
+
M.StreamVideoCreated
|
|
1510
|
+
]) : e === E.Stop && i.linkTrack(
|
|
1506
1511
|
"agent-video",
|
|
1507
1512
|
{
|
|
1508
1513
|
event: "stop",
|
|
@@ -1511,16 +1516,16 @@ function st(e, n, i, r, s) {
|
|
|
1511
1516
|
"stream-type": r
|
|
1512
1517
|
},
|
|
1513
1518
|
"done",
|
|
1514
|
-
[
|
|
1519
|
+
[M.StreamVideoDone]
|
|
1515
1520
|
);
|
|
1516
1521
|
}
|
|
1517
1522
|
function Jn(e, n, i, r, s) {
|
|
1518
|
-
e ===
|
|
1523
|
+
e === E.Start ? r.linkTrack(
|
|
1519
1524
|
"agent-video",
|
|
1520
1525
|
{ event: "start", latency: oe.get(!0), "stream-type": s },
|
|
1521
1526
|
"start",
|
|
1522
|
-
[
|
|
1523
|
-
) : e ===
|
|
1527
|
+
[M.StreamVideoCreated]
|
|
1528
|
+
) : e === E.Stop && r.linkTrack(
|
|
1524
1529
|
"agent-video",
|
|
1525
1530
|
{
|
|
1526
1531
|
event: "stop",
|
|
@@ -1530,7 +1535,7 @@ function Jn(e, n, i, r, s) {
|
|
|
1530
1535
|
...i
|
|
1531
1536
|
},
|
|
1532
1537
|
"done",
|
|
1533
|
-
[
|
|
1538
|
+
[M.StreamVideoDone]
|
|
1534
1539
|
);
|
|
1535
1540
|
}
|
|
1536
1541
|
function ct(e, n, i, r) {
|
|
@@ -1552,12 +1557,12 @@ function ct(e, n, i, r) {
|
|
|
1552
1557
|
callbacks: {
|
|
1553
1558
|
...n.callbacks,
|
|
1554
1559
|
onConnectionStateChange: (g, l) => {
|
|
1555
|
-
var v,
|
|
1556
|
-
(
|
|
1560
|
+
var v, P;
|
|
1561
|
+
(P = (v = n.callbacks).onConnectionStateChange) == null || P.call(v, g), zn(g, l, i), g === x.Connected && (o ? s(o) : c = !0);
|
|
1557
1562
|
},
|
|
1558
1563
|
onVideoStateChange: (g, l) => {
|
|
1559
|
-
var v,
|
|
1560
|
-
(
|
|
1564
|
+
var v, P;
|
|
1565
|
+
(P = (v = n.callbacks).onVideoStateChange) == null || P.call(v, g), Vn(
|
|
1561
1566
|
g,
|
|
1562
1567
|
e,
|
|
1563
1568
|
l,
|
|
@@ -1567,16 +1572,16 @@ function ct(e, n, i, r) {
|
|
|
1567
1572
|
},
|
|
1568
1573
|
onAgentActivityStateChange: (g) => {
|
|
1569
1574
|
var l, v;
|
|
1570
|
-
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), d = (
|
|
1575
|
+
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), d = (P) => {
|
|
1571
1576
|
st(
|
|
1572
|
-
|
|
1577
|
+
E.Start,
|
|
1573
1578
|
e,
|
|
1574
1579
|
i,
|
|
1575
1580
|
o.streamType,
|
|
1576
|
-
|
|
1581
|
+
P
|
|
1577
1582
|
), d = null;
|
|
1578
1583
|
}, h || d({ latency: oe.get(!0) })) : (je.reset(), d = null, st(
|
|
1579
|
-
|
|
1584
|
+
E.Stop,
|
|
1580
1585
|
e,
|
|
1581
1586
|
i,
|
|
1582
1587
|
o.streamType
|
|
@@ -1602,7 +1607,7 @@ async function On(e, n, i, r, s) {
|
|
|
1602
1607
|
var h, g, l, v;
|
|
1603
1608
|
const a = async () => {
|
|
1604
1609
|
if (Ke(e.presenter.type)) {
|
|
1605
|
-
const
|
|
1610
|
+
const P = await ct(e, n, r), N = `${Bn}_${P.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
|
|
1606
1611
|
return { chatResult: {
|
|
1607
1612
|
chatMode: O.Functional,
|
|
1608
1613
|
chat: {
|
|
@@ -1616,9 +1621,9 @@ async function On(e, n, i, r, s) {
|
|
|
1616
1621
|
chat_mode: O.Functional,
|
|
1617
1622
|
messages: []
|
|
1618
1623
|
}
|
|
1619
|
-
}, streamingManager:
|
|
1624
|
+
}, streamingManager: P };
|
|
1620
1625
|
} else {
|
|
1621
|
-
const
|
|
1626
|
+
const P = new AbortController(), N = P.signal;
|
|
1622
1627
|
let B;
|
|
1623
1628
|
try {
|
|
1624
1629
|
const F = ht(
|
|
@@ -1628,10 +1633,10 @@ async function On(e, n, i, r, s) {
|
|
|
1628
1633
|
n.mode,
|
|
1629
1634
|
n.persistentChat,
|
|
1630
1635
|
s
|
|
1631
|
-
),
|
|
1636
|
+
), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, I]);
|
|
1632
1637
|
return { chatResult: k, streamingManager: Y };
|
|
1633
1638
|
} catch (F) {
|
|
1634
|
-
throw
|
|
1639
|
+
throw P.abort(), B && await B.disconnect().catch(() => {
|
|
1635
1640
|
}), F;
|
|
1636
1641
|
}
|
|
1637
1642
|
}
|
|
@@ -1658,9 +1663,9 @@ async function qn(e, n) {
|
|
|
1658
1663
|
n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
|
|
1659
1664
|
const v = Ke(l.presenter.type);
|
|
1660
1665
|
d.enrich(Gt(l));
|
|
1661
|
-
const { onMessage:
|
|
1666
|
+
const { onMessage: P, clearQueue: N } = An(d, t, n, l, () => {
|
|
1662
1667
|
var f, C, R;
|
|
1663
|
-
(f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C,
|
|
1668
|
+
(f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, x.Disconnected);
|
|
1664
1669
|
});
|
|
1665
1670
|
t.messages = an(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
|
|
1666
1671
|
const B = (f) => {
|
|
@@ -1674,10 +1679,10 @@ async function qn(e, n) {
|
|
|
1674
1679
|
video_duration_to_interrupt: je.get(!0),
|
|
1675
1680
|
message_duration_to_interrupt: oe.get(!0)
|
|
1676
1681
|
}), C.interrupted = !0, (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "answer"), v ? Rn(t.streamingManager) : (Cn(t.streamingManager, (J = t.streamingManager) == null ? void 0 : J.streamType, r), Sn(t.streamingManager, r));
|
|
1677
|
-
},
|
|
1682
|
+
}, I = /* @__PURE__ */ new Map();
|
|
1678
1683
|
function k(f) {
|
|
1679
1684
|
return async (C) => {
|
|
1680
|
-
const R =
|
|
1685
|
+
const R = I.get(f);
|
|
1681
1686
|
if (!R)
|
|
1682
1687
|
throw new Error(`No handler registered for client tool: ${f}`);
|
|
1683
1688
|
try {
|
|
@@ -1690,29 +1695,29 @@ async function qn(e, n) {
|
|
|
1690
1695
|
}
|
|
1691
1696
|
function Y() {
|
|
1692
1697
|
var f, C, R, A;
|
|
1693
|
-
for (const [D] of
|
|
1698
|
+
for (const [D] of I)
|
|
1694
1699
|
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (A = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || A.call(R, D, k(D));
|
|
1695
1700
|
}
|
|
1696
1701
|
function Q(f, C) {
|
|
1697
1702
|
var A, D;
|
|
1698
|
-
const R = !
|
|
1699
|
-
|
|
1703
|
+
const R = !I.has(f);
|
|
1704
|
+
I.set(f, C), R && ((D = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || D.call(A, f, k(f)));
|
|
1700
1705
|
}
|
|
1701
1706
|
function U(f) {
|
|
1702
1707
|
var C, R;
|
|
1703
|
-
|
|
1708
|
+
I.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
|
|
1704
1709
|
}
|
|
1705
1710
|
const te = Date.now();
|
|
1706
1711
|
tt(() => {
|
|
1707
1712
|
d.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
|
|
1708
1713
|
});
|
|
1709
1714
|
async function ne(f) {
|
|
1710
|
-
var J, w, y,
|
|
1711
|
-
(w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J,
|
|
1712
|
-
const C = c === O.DirectPlayback || v ? Promise.resolve(void 0) :
|
|
1715
|
+
var J, w, y, T, j, G, he;
|
|
1716
|
+
(w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J, x.Connecting), oe.reset(), f && !i && (delete t.chat, (T = (y = n.callbacks).onNewMessage) == null || T.call(y, [...t.messages], "answer"));
|
|
1717
|
+
const C = c === O.DirectPlayback || v ? Promise.resolve(void 0) : Mn(
|
|
1713
1718
|
n.auth,
|
|
1714
1719
|
a,
|
|
1715
|
-
{ onMessage:
|
|
1720
|
+
{ onMessage: P, onError: n.callbacks.onError },
|
|
1716
1721
|
n.externalId
|
|
1717
1722
|
), R = xe(
|
|
1718
1723
|
() => On(
|
|
@@ -1723,7 +1728,7 @@ async function qn(e, n) {
|
|
|
1723
1728
|
callbacks: {
|
|
1724
1729
|
...n.callbacks,
|
|
1725
1730
|
onVideoIdChange: B,
|
|
1726
|
-
onMessage:
|
|
1731
|
+
onMessage: P,
|
|
1727
1732
|
onInterruptDetected: F
|
|
1728
1733
|
}
|
|
1729
1734
|
},
|
|
@@ -1740,21 +1745,21 @@ async function qn(e, n) {
|
|
|
1740
1745
|
}
|
|
1741
1746
|
).catch((Z) => {
|
|
1742
1747
|
var z, ee;
|
|
1743
|
-
throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z,
|
|
1748
|
+
throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, x.Fail), Z;
|
|
1744
1749
|
}), [A, { streamingManager: D, chat: b }] = await Promise.all([C, R]);
|
|
1745
|
-
b && b.id !== ((
|
|
1750
|
+
b && b.id !== ((j = t.chat) == null ? void 0 : j.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = D, t.socketManager = A, t.chat = b, Y(), i = !1, d.enrich({
|
|
1746
1751
|
chatId: b == null ? void 0 : b.id,
|
|
1747
1752
|
streamId: D == null ? void 0 : D.streamId,
|
|
1748
1753
|
mode: t.chatMode
|
|
1749
1754
|
}), K((b == null ? void 0 : b.chat_mode) ?? c);
|
|
1750
1755
|
}
|
|
1751
|
-
async function
|
|
1756
|
+
async function $() {
|
|
1752
1757
|
var f, C, R, A;
|
|
1753
|
-
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R,
|
|
1758
|
+
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R, x.Disconnected);
|
|
1754
1759
|
}
|
|
1755
1760
|
async function K(f) {
|
|
1756
1761
|
var C, R;
|
|
1757
|
-
f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await
|
|
1762
|
+
f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
|
|
1758
1763
|
}
|
|
1759
1764
|
return {
|
|
1760
1765
|
agent: l,
|
|
@@ -1785,17 +1790,17 @@ async function qn(e, n) {
|
|
|
1785
1790
|
mode: t.chatMode
|
|
1786
1791
|
});
|
|
1787
1792
|
} catch {
|
|
1788
|
-
await
|
|
1793
|
+
await $(), await ne(!1);
|
|
1789
1794
|
}
|
|
1790
1795
|
return;
|
|
1791
1796
|
}
|
|
1792
|
-
await
|
|
1797
|
+
await $(), await ne(!1), d.track("agent-chat", {
|
|
1793
1798
|
event: "reconnect",
|
|
1794
1799
|
mode: t.chatMode
|
|
1795
1800
|
});
|
|
1796
1801
|
},
|
|
1797
1802
|
async disconnect() {
|
|
1798
|
-
await
|
|
1803
|
+
await $(), d.track("agent-chat", {
|
|
1799
1804
|
event: "disconnect",
|
|
1800
1805
|
mode: t.chatMode
|
|
1801
1806
|
});
|
|
@@ -1840,7 +1845,7 @@ async function qn(e, n) {
|
|
|
1840
1845
|
throw new me("Chat is not initialized");
|
|
1841
1846
|
}
|
|
1842
1847
|
}, R = async () => {
|
|
1843
|
-
var
|
|
1848
|
+
var T, j;
|
|
1844
1849
|
if (!t.chat) {
|
|
1845
1850
|
const G = await ht(
|
|
1846
1851
|
l,
|
|
@@ -1850,11 +1855,11 @@ async function qn(e, n) {
|
|
|
1850
1855
|
n.persistentChat
|
|
1851
1856
|
);
|
|
1852
1857
|
if (!G.chat)
|
|
1853
|
-
throw new
|
|
1854
|
-
t.chat = G.chat, (
|
|
1858
|
+
throw new kt(t.chatMode, !!n.persistentChat);
|
|
1859
|
+
t.chat = G.chat, (j = (T = n.callbacks).onNewChat) == null || j.call(T, t.chat.id);
|
|
1855
1860
|
}
|
|
1856
1861
|
return t.chat.id;
|
|
1857
|
-
}, A = async (
|
|
1862
|
+
}, A = async (T, j) => {
|
|
1858
1863
|
const G = t.chatMode === O.Playground;
|
|
1859
1864
|
return xe(v && !G ? async () => {
|
|
1860
1865
|
var z, ee;
|
|
@@ -1863,12 +1868,12 @@ async function qn(e, n) {
|
|
|
1863
1868
|
var z, ee;
|
|
1864
1869
|
return g.chat(
|
|
1865
1870
|
l.id,
|
|
1866
|
-
|
|
1871
|
+
j,
|
|
1867
1872
|
{
|
|
1868
1873
|
chatMode: t.chatMode,
|
|
1869
1874
|
streamId: (z = t.streamingManager) == null ? void 0 : z.streamId,
|
|
1870
1875
|
sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
|
|
1871
|
-
messages:
|
|
1876
|
+
messages: T.map(({ matches: De, ...le }) => le)
|
|
1872
1877
|
},
|
|
1873
1878
|
{
|
|
1874
1879
|
...gt(t.chatMode),
|
|
@@ -1878,12 +1883,12 @@ async function qn(e, n) {
|
|
|
1878
1883
|
}, {
|
|
1879
1884
|
limit: 2,
|
|
1880
1885
|
shouldRetryFn: (z) => {
|
|
1881
|
-
var le,
|
|
1886
|
+
var le, Me, pe, we;
|
|
1882
1887
|
const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
|
|
1883
|
-
return !((
|
|
1888
|
+
return !((Me = z == null ? void 0 : z.message) == null ? void 0 : Me.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, z), !1) : !0;
|
|
1884
1889
|
},
|
|
1885
1890
|
onRetry: async () => {
|
|
1886
|
-
await
|
|
1891
|
+
await $(), await ne(!1);
|
|
1887
1892
|
}
|
|
1888
1893
|
});
|
|
1889
1894
|
};
|
|
@@ -1895,37 +1900,37 @@ async function qn(e, n) {
|
|
|
1895
1900
|
parts: Te(f),
|
|
1896
1901
|
created_at: new Date(oe.update()).toISOString()
|
|
1897
1902
|
}), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "user");
|
|
1898
|
-
const
|
|
1903
|
+
const T = await R(), j = await A([...t.messages], T);
|
|
1899
1904
|
return t.messages.push({
|
|
1900
1905
|
id: ge(),
|
|
1901
1906
|
role: "assistant",
|
|
1902
|
-
content:
|
|
1903
|
-
parts: Te(
|
|
1907
|
+
content: j.result || "",
|
|
1908
|
+
parts: Te(j.result || ""),
|
|
1904
1909
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1905
|
-
context:
|
|
1906
|
-
matches:
|
|
1910
|
+
context: j.context,
|
|
1911
|
+
matches: j.matches
|
|
1907
1912
|
}), d.track("agent-message-send", {
|
|
1908
1913
|
event: "success",
|
|
1909
1914
|
messages: t.messages.length + 1
|
|
1910
|
-
}),
|
|
1915
|
+
}), j.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), d.track("agent-message-received", {
|
|
1911
1916
|
latency: oe.get(!0),
|
|
1912
1917
|
messages: t.messages.length
|
|
1913
|
-
})),
|
|
1914
|
-
} catch (
|
|
1918
|
+
})), j;
|
|
1919
|
+
} catch (T) {
|
|
1915
1920
|
throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), d.track("agent-message-send", {
|
|
1916
1921
|
event: "error",
|
|
1917
1922
|
messages: t.messages.length
|
|
1918
|
-
}),
|
|
1923
|
+
}), T;
|
|
1919
1924
|
}
|
|
1920
1925
|
},
|
|
1921
1926
|
rate(f, C, R) {
|
|
1922
1927
|
var b, J, w, y;
|
|
1923
|
-
const A = t.messages.find((
|
|
1928
|
+
const A = t.messages.find((T) => T.id === f);
|
|
1924
1929
|
if (t.chat) {
|
|
1925
1930
|
if (!A)
|
|
1926
1931
|
throw new Error("Message not found");
|
|
1927
1932
|
} else throw new Error("Chat is not initialized");
|
|
1928
|
-
const D = ((b = A.matches) == null ? void 0 : b.map((
|
|
1933
|
+
const D = ((b = A.matches) == null ? void 0 : b.map((T) => [T.document_id, T.id])) ?? [];
|
|
1929
1934
|
return d.track("agent-rate", {
|
|
1930
1935
|
event: R ? "update" : "create",
|
|
1931
1936
|
thumb: C === 1 ? "up" : "down",
|
|
@@ -2002,20 +2007,20 @@ async function qn(e, n) {
|
|
|
2002
2007
|
export {
|
|
2003
2008
|
W as AgentActivityState,
|
|
2004
2009
|
bt as AgentStatus,
|
|
2005
|
-
|
|
2010
|
+
kt as ChatCreationFailed,
|
|
2006
2011
|
O as ChatMode,
|
|
2007
2012
|
It as ChatModeDowngraded,
|
|
2008
2013
|
X as ChatProgress,
|
|
2009
|
-
|
|
2014
|
+
x as ConnectionState,
|
|
2010
2015
|
ae as ConnectivityState,
|
|
2011
2016
|
$t as DocumentType,
|
|
2012
2017
|
xt as KnowledgeType,
|
|
2013
2018
|
_t as PlanGroup,
|
|
2014
2019
|
jt as Providers,
|
|
2015
2020
|
Lt as RateState,
|
|
2016
|
-
|
|
2021
|
+
M as StreamEvents,
|
|
2017
2022
|
se as StreamType,
|
|
2018
|
-
|
|
2023
|
+
E as StreamingState,
|
|
2019
2024
|
Pt as Subject,
|
|
2020
2025
|
Ne as TransportProvider,
|
|
2021
2026
|
At as UserPlan,
|