@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  var Et = Object.defineProperty;
2
- var kt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
3
- var Ce = (e, n, i) => kt(e, typeof n != "symbol" ? n + "" : 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 Mt extends Ie {
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 T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), 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 || {}), I = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(I || {}), P = /* @__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))(P || {}), 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 || {});
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
- [I.ChatAnswer]: X.Answer,
403
- [I.ChatPartial]: X.Partial
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, L = l - o;
562
- if (a = g, o = l, L > 0 && v > 0) {
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 Me = 100, fn = Math.max(Math.ceil(400 / Me), 1), mn = 0.25, gn = 0.28;
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 L = hn();
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: M, freezeCount: k } = L(B), Y = un(B);
604
+ const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: k } = P(B), Y = un(B);
605
605
  if (F)
606
- t = 0, l = k - v, g = M < mn ? ae.Strong : M > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0), d || (r == null || r(T.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
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, Me, c);
609
- r == null || r(T.Stop, Q), n() || i(), v = k, d = !1;
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, Me));
614
+ a || (a = setInterval(N, ke));
615
615
  },
616
616
  stop: () => {
617
617
  a && (clearInterval(a), a = null);
618
618
  },
619
- getReport: () => rt(o, Me, c)
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, P.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
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 L = se.Fluent;
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 M = null, k = null, Y = null, Q = !1;
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 x = on(d, h || Ee, e, t.onError);
661
+ const $ = on(d, h || Ee, e, t.onError);
662
662
  let K, H, re, de = !0;
663
663
  try {
664
- const u = await x.createStream({
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": L
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, P.Connecting, "livekit:connecting");
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, P.Disconnected, "livekit:disconnected");
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, P.Connecting, "livekit:reconnecting");
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, P.Connecting, "livekit:signal-reconnecting");
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 !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
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 !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
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 _, j, q;
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 = M == null ? void 0 : M.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
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"), (j = t.onSrcObjectReady) == null || j.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, P.Connected, "livekit:track-subscribed")), M = yt(
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 === T.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), D()) : V === T.Stop && b(ie);
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
- ), M.start());
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(M == null ? void 0 : M.getReport()), M == null || M.stop(), M = null);
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 E(u, m) {
772
- var p, S, _;
773
- if (u === I.ToolCalling) {
774
- te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, I.ToolCalling, m);
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 === I.ToolResult && ((_ = t.onToolEvent) == null || _.call(t, I.ToolResult, m));
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 $(u, m) {
780
- var p, S, _, j, q;
781
- if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === I.StreamVideoCreated) {
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: (j = m == null ? void 0 : m.stt) == null ? void 0 : j.latency,
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 j, q, V, ie;
792
- const p = ((q = (j = M == null ? void 0 : M.getReport()) == null ? void 0 : j.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: S };
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, _), $(u, m);
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
- [I.ChatAnswer]: y,
807
- [I.ChatPartial]: y,
808
- [I.ToolCalling]: E,
809
- [I.ToolResult]: E,
810
- [I.StreamVideoCreated]: G,
811
- [I.StreamVideoDone]: G,
812
- [I.StreamVideoError]: G,
813
- [I.StreamVideoRejected]: G,
814
- [I.ChatAudioTranscribed]: he
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 j = JSON.parse(_), q = S || j.subject;
820
- if (r("Data received:", { subject: q, data: j }), !q) return;
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, j);
823
- } catch (j) {
824
- r("Failed to parse data channel message:", j);
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 ke(u, m, p) {
843
+ function Me(u, m, p) {
839
844
  for (const [S, _] of p)
840
845
  if (_.source === m && _.track) {
841
- const j = _.track.mediaStreamTrack;
842
- if (j === u || (j == null ? void 0 : j.id) === u.id)
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, _, j) {
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 = ke(V, S, _());
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 j());
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, P.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;
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, P.Connecting, "user:reconnect");
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, j), S(!1);
976
- }, 5e3), j = () => {
977
- clearTimeout(_), l == null || l.off(a.ParticipantConnected, j), S(!0);
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, j);
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, P.Fail, "user:reconnect-failed"), p;
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: L,
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: I.StreamInterrupt,
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 kn(e, n, i, r) {
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 Mn(e) {
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 = Mn(i);
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 === I.ChatAnswer ? X.Answer : d === I.ChatAudioTranscribed ? X.Transcribe : 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 = I, L = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], N = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
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 M = { ...F, sentiment: h.sentiment };
1156
- n.messages[n.messages.length - 1] = M, t == null || t([...n.messages], c);
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 (L.includes(d)) {
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 P.Connected;
1214
+ return x.Connected;
1210
1215
  case "checking":
1211
- return P.Connecting;
1216
+ return x.Connecting;
1212
1217
  case "failed":
1213
- return P.Fail;
1218
+ return x.Fail;
1214
1219
  case "new":
1215
- return P.New;
1220
+ return x.New;
1216
1221
  case "closed":
1217
- return P.Closed;
1222
+ return x.Closed;
1218
1223
  case "disconnected":
1219
- return P.Disconnected;
1224
+ return x.Disconnected;
1220
1225
  case "completed":
1221
- return P.Completed;
1226
+ return x.Completed;
1222
1227
  default:
1223
- return P.New;
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 === T.Start && n === T.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && n === T.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, r));
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 === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, s)), n === T.Start ? r == null || r(W.Talking) : n === T.Stop && (r == null || r(W.Idle));
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 = T.Stop, v = T.Stop;
1276
- const { startConnection: L, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: M } = _n(
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 x = new bn({ iceServers: Q }), K = x.createDataChannel("JanusDataChannel");
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, P.Connected));
1304
+ h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, x.Connected));
1300
1305
  }, f = yt(
1301
- () => x.getStats(),
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(), x.onicecandidate = (w) => {
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 ? M(
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
- ) : M(k, { candidate: null }, U, c);
1332
- } catch (E) {
1333
- (y = r.onError) == null || y.call(r, E, { streamId: k });
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 === I.StreamStarted && typeof y == "object" && "metadata" in y) {
1344
- const E = y.metadata;
1345
- C(E.videoId);
1348
+ if (w === M.StreamStarted && typeof y == "object" && "metadata" in y) {
1349
+ const T = y.metadata;
1350
+ C(T.videoId);
1346
1351
  }
1347
- w === I.StreamDone && C(null), l = w === I.StreamStarted ? T.Start : T.Stop, ot({
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 E = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
1359
- E && o.enrich({ streamMetadata: E }), ($ = r.onStreamReady) == null || $.call(r);
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
- [I.StreamStarted]: R,
1363
- [I.StreamDone]: R,
1364
- [I.StreamReady]: A
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: E } = d(w.data);
1369
- ($ = D[y]) == null || $.call(D, y, E);
1370
- }, x.oniceconnectionstatechange = () => {
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 => " + x.iceConnectionState);
1373
- const w = at(x.iceConnectionState);
1374
- w !== P.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
1375
- }, x.ontrack = (w) => {
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 x.setRemoteDescription(Y), t("set remote description OK");
1379
- const b = await x.createAnswer();
1380
- return t("create answer OK"), await x.setLocalDescription(b), t("set local description OK"), await L(k, b, U, c), t("start connection OK"), {
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(x.iceConnectionState);
1395
- if (x) {
1396
- if (y === P.New) {
1399
+ const y = at($.iceConnectionState);
1400
+ if ($) {
1401
+ if (y === x.New) {
1397
1402
  f.stop();
1398
1403
  return;
1399
1404
  }
1400
- x.close(), x.oniceconnectionstatechange = null, x.onnegotiationneeded = null, x.onicecandidate = null, x.ontrack = null;
1405
+ $.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
1401
1406
  }
1402
1407
  try {
1403
- y === P.Connected && await B(k, U).catch((E) => {
1408
+ y === x.Connected && await B(k, U).catch((T) => {
1404
1409
  });
1405
- } catch (E) {
1406
- t("Error on close stream connection", E);
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, E;
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", $), (E = r.onError) == null || E.call(r, $, { streamId: k });
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 === T.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === T.Stop && r.track("stream-session", {
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 === T.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
1504
- I.StreamVideoCreated
1505
- ]) : e === T.Stop && i.linkTrack(
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
- [I.StreamVideoDone]
1519
+ [M.StreamVideoDone]
1515
1520
  );
1516
1521
  }
1517
1522
  function Jn(e, n, i, r, s) {
1518
- e === T.Start ? r.linkTrack(
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
- [I.StreamVideoCreated]
1523
- ) : e === T.Stop && r.linkTrack(
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
- [I.StreamVideoDone]
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, L;
1556
- (L = (v = n.callbacks).onConnectionStateChange) == null || L.call(v, g), zn(g, l, i), g === P.Connected && (o ? s(o) : c = !0);
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, L;
1560
- (L = (v = n.callbacks).onVideoStateChange) == null || L.call(v, g), Vn(
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 = (L) => {
1575
+ (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), d = (P) => {
1571
1576
  st(
1572
- T.Start,
1577
+ E.Start,
1573
1578
  e,
1574
1579
  i,
1575
1580
  o.streamType,
1576
- L
1581
+ P
1577
1582
  ), d = null;
1578
1583
  }, h || d({ latency: oe.get(!0) })) : (je.reset(), d = null, st(
1579
- T.Stop,
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 L = await ct(e, n, r), N = `${Bn}_${L.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
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: L };
1624
+ }, streamingManager: P };
1620
1625
  } else {
1621
- const L = new AbortController(), N = L.signal;
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
- ), M = ct(e, n, r, N).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, M]);
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 L.abort(), B && await B.disconnect().catch(() => {
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: L, clearQueue: N } = An(d, t, n, l, () => {
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, P.Disconnected);
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
- }, M = /* @__PURE__ */ new Map();
1682
+ }, I = /* @__PURE__ */ new Map();
1678
1683
  function k(f) {
1679
1684
  return async (C) => {
1680
- const R = M.get(f);
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 M)
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 = !M.has(f);
1699
- M.set(f, C), R && ((D = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || D.call(A, f, k(f)));
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
- M.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
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, E, $, G, he;
1711
- (w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J, P.Connecting), oe.reset(), f && !i && (delete t.chat, (E = (y = n.callbacks).onNewMessage) == null || E.call(y, [...t.messages], "answer"));
1712
- const C = c === O.DirectPlayback || v ? Promise.resolve(void 0) : kn(
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: L, onError: n.callbacks.onError },
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: L,
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, P.Fail), 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 !== (($ = t.chat) == null ? void 0 : $.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({
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 x() {
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, P.Disconnected);
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 x(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
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 x(), await ne(!1);
1793
+ await $(), await ne(!1);
1789
1794
  }
1790
1795
  return;
1791
1796
  }
1792
- await x(), await ne(!1), d.track("agent-chat", {
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 x(), d.track("agent-chat", {
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 E, $;
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 Mt(t.chatMode, !!n.persistentChat);
1854
- t.chat = G.chat, ($ = (E = n.callbacks).onNewChat) == null || $.call(E, t.chat.id);
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 (E, $) => {
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: E.map(({ matches: De, ...le }) => le)
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, ke, pe, we;
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 !((ke = z == null ? void 0 : z.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, z), !1) : !0;
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 x(), await ne(!1);
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 E = await R(), $ = await A([...t.messages], E);
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: $.result || "",
1903
- parts: Te($.result || ""),
1907
+ content: j.result || "",
1908
+ parts: Te(j.result || ""),
1904
1909
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1905
- context: $.context,
1906
- matches: $.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
- }), $.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), d.track("agent-message-received", {
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 (E) {
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
- }), E;
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((E) => E.id === f);
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((E) => [E.document_id, E.id])) ?? [];
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
- Mt as ChatCreationFailed,
2010
+ kt as ChatCreationFailed,
2006
2011
  O as ChatMode,
2007
2012
  It as ChatModeDowngraded,
2008
2013
  X as ChatProgress,
2009
- P as ConnectionState,
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
- I as StreamEvents,
2021
+ M as StreamEvents,
2017
2022
  se as StreamType,
2018
- T as StreamingState,
2023
+ E as StreamingState,
2019
2024
  Pt as Subject,
2020
2025
  Ne as TransportProvider,
2021
2026
  At as UserPlan,