@d-id/client-sdk 1.1.56-staging.255 → 1.1.56-staging.256

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
@@ -618,22 +618,22 @@ async function un(e, n, i) {
618
618
  });
619
619
  let K = null, G = W.Idle, ae = !0;
620
620
  const $ = Yt(c, h || we, e, t.onError);
621
- let f, C, E, J = !0;
621
+ let m, C, E, J = !0;
622
622
  try {
623
623
  const u = await $.createStream({
624
624
  transport: n.transport,
625
625
  chat_persist: n.chat_persist ?? !0
626
- }), { id: m, session_token: p, session_url: v, interrupt_enabled: I } = u;
627
- (ze = t.onStreamCreated) == null || ze.call(t, { session_id: m, stream_id: m, agent_id: e }), f = m, C = p, E = v, J = I ?? !0, await l.prepareConnection(E, C);
626
+ }), { id: f, session_token: p, session_url: v, interrupt_enabled: I } = u;
627
+ (ze = t.onStreamCreated) == null || ze.call(t, { session_id: f, stream_id: f, agent_id: e }), m = f, C = p, E = v, J = I ?? !0, await l.prepareConnection(E, C);
628
628
  } catch (u) {
629
629
  _e(u, r, t);
630
630
  }
631
- if (!E || !C || !f)
631
+ if (!E || !C || !m)
632
632
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
633
633
  l.on(a.ConnectionStateChanged, M).on(a.ConnectionQualityChanged, V).on(a.ParticipantConnected, Y).on(a.ParticipantDisconnected, Z).on(a.TrackSubscribed, ee).on(a.TrackUnsubscribed, S).on(a.DataReceived, ve).on(a.MediaDevicesError, Ce).on(a.TranscriptionReceived, x).on(a.EncryptionError, dt).on(a.TrackSubscriptionFailed, ut);
634
- function x(u, m) {
634
+ function x(u, f) {
635
635
  var p;
636
- m != null && m.isLocal && (re.update(), G === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), G = W.Idle));
636
+ f != null && f.isLocal && (re.update(), G === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), G = W.Idle));
637
637
  }
638
638
  try {
639
639
  await l.connect(E, C), r("LiveKit room joined successfully"), K = setTimeout(() => {
@@ -642,8 +642,8 @@ async function un(e, n, i) {
642
642
  `Track subscription timeout - no track subscribed within ${qe / 1e3} seconds after connect`
643
643
  ), K = null, g.track("connectivity-error", {
644
644
  error: "Track subscription timeout",
645
- sessionId: f
646
- }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: f }), De("internal:track-subscription-timeout");
645
+ sessionId: m
646
+ }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: m }), De("internal:track-subscription-timeout");
647
647
  }, qe);
648
648
  } catch (u) {
649
649
  _e(u, r, t);
@@ -652,10 +652,10 @@ async function un(e, n, i) {
652
652
  "stream-type": A
653
653
  });
654
654
  function M(u) {
655
- var m, p, v, I;
655
+ var f, p, v, I;
656
656
  switch (r("Connection state changed:", u), u) {
657
657
  case s.Connecting:
658
- r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, b.Connecting, "livekit:connecting");
658
+ r("CALLBACK: onConnectionStateChange(Connecting)"), (f = t.onConnectionStateChange) == null || f.call(t, b.Connecting, "livekit:connecting");
659
659
  break;
660
660
  case s.Connected:
661
661
  r("LiveKit room connected successfully"), y = !0;
@@ -671,9 +671,9 @@ async function un(e, n, i) {
671
671
  break;
672
672
  }
673
673
  }
674
- function V(u, m) {
674
+ function V(u, f) {
675
675
  var p;
676
- r("Connection quality:", u), m != null && m.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, dn[u]));
676
+ r("Connection quality:", u), f != null && f.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, dn[u]));
677
677
  }
678
678
  function Y(u) {
679
679
  r("Participant connected:", u.identity);
@@ -686,10 +686,10 @@ async function un(e, n, i) {
686
686
  H !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), H = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
687
687
  }
688
688
  function U(u) {
689
- var m;
690
- H !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), H = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
689
+ var f;
690
+ H !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), H = T.Stop, (f = t.onVideoStateChange) == null || f.call(t, T.Stop, u));
691
691
  }
692
- function ee(u, m, p) {
692
+ function ee(u, f, p) {
693
693
  var I, P, Q;
694
694
  r(`Track subscribed: ${u.kind} from ${p.identity}`);
695
695
  const v = u.mediaStreamTrack;
@@ -701,13 +701,13 @@ async function un(e, n, i) {
701
701
  () => u.getRTCStatsReport(),
702
702
  ({ sttLatency: N, serviceLatency: te }) => {
703
703
  var Ke, Ne, Ve;
704
- const me = re.get(!0);
705
- let fe = 0;
704
+ const fe = re.get(!0);
705
+ let me = 0;
706
706
  if (N) {
707
707
  const Ue = ((Ne = (Ke = _ == null ? void 0 : _.getReport()) == null ? void 0 : Ke.webRTCStats) == null ? void 0 : Ne.avgRtt) ?? 0;
708
- fe = Ue > 0 ? Math.round(Ue * 1e3) : 0;
708
+ me = Ue > 0 ? Math.round(Ue * 1e3) : 0;
709
709
  }
710
- const de = me > 0 ? me + (N ?? 0) + fe : void 0, oe = de !== void 0 && te !== void 0 ? de - te : void 0;
710
+ const de = fe > 0 ? fe + (N ?? 0) + me : void 0, oe = de !== void 0 && te !== void 0 ? de - te : void 0;
711
711
  (Ve = t.onFirstAudioDetected) == null || Ve.call(t, { latency: de, networkLatency: oe });
712
712
  }
713
713
  )), u.kind === "video" && ((I = t.onStreamReady) == null || I.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, z), q || (q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (Q = t.onConnectionStateChange) == null || Q.call(t, b.Connected, "livekit:track-subscribed")), _ = ct(
@@ -719,44 +719,44 @@ async function un(e, n, i) {
719
719
  }
720
720
  ), _.start());
721
721
  }
722
- function S(u, m, p) {
722
+ function S(u, f, p) {
723
723
  r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (U(_ == null ? void 0 : _.getReport()), _ == null || _.stop(), _ = null);
724
724
  }
725
- function w(u, m) {
725
+ function w(u, f) {
726
726
  var v;
727
727
  const p = Gt[u];
728
- p && ((v = t.onMessage) == null || v.call(t, p, { event: p, ...m }));
728
+ p && ((v = t.onMessage) == null || v.call(t, p, { event: p, ...f }));
729
729
  }
730
- function R(u, m) {
730
+ function R(u, f) {
731
731
  var p, v, I;
732
732
  if (u === D.ToolCalling) {
733
- G = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (v = t.onToolEvent) == null || v.call(t, D.ToolCalling, m);
733
+ G = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (v = t.onToolEvent) == null || v.call(t, D.ToolCalling, f);
734
734
  return;
735
735
  }
736
- u === D.ToolResult && ((I = t.onToolEvent) == null || I.call(t, D.ToolResult, m));
736
+ u === D.ToolResult && ((I = t.onToolEvent) == null || I.call(t, D.ToolResult, f));
737
737
  }
738
- function F(u, m) {
738
+ function F(u, f) {
739
739
  var p, v, I, P, Q;
740
- if (ae = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (v = t.onInterruptibleChange) == null || v.call(t, ae), u === D.StreamVideoCreated) {
740
+ if (ae = ((p = f.metadata) == null ? void 0 : p.interruptible) !== !1, (v = t.onInterruptibleChange) == null || v.call(t, ae), u === D.StreamVideoCreated) {
741
741
  G = W.Talking, (I = t.onAgentActivityStateChange) == null || I.call(t, W.Talking), k == null || k.arm({
742
- sttLatency: (P = m == null ? void 0 : m.stt) == null ? void 0 : P.latency,
743
- serviceLatency: m == null ? void 0 : m.serviceLatency
742
+ sttLatency: (P = f == null ? void 0 : f.stt) == null ? void 0 : P.latency,
743
+ serviceLatency: f == null ? void 0 : f.serviceLatency
744
744
  });
745
745
  return;
746
746
  }
747
747
  ae && (G = W.Idle, (Q = t.onAgentActivityStateChange) == null || Q.call(t, W.Idle));
748
748
  }
749
- function se(u, m) {
749
+ function se(u, f) {
750
750
  var P, Q, N, te;
751
- const p = ((Q = (P = _ == null ? void 0 : _.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : Q.avgRtt) ?? 0, v = p > 0 ? Math.round(p / 2 * 1e3) : 0, I = { ...m, downstreamNetworkLatency: v };
752
- i.debug && ((N = m == null ? void 0 : m.metadata) != null && N.sentiment) && (I.sentiment = {
753
- id: m.metadata.sentiment.id,
754
- name: m.metadata.sentiment.sentiment
755
- }), (te = t.onMessage) == null || te.call(t, u, I), F(u, m);
751
+ const p = ((Q = (P = _ == null ? void 0 : _.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : Q.avgRtt) ?? 0, v = p > 0 ? Math.round(p / 2 * 1e3) : 0, I = { ...f, downstreamNetworkLatency: v };
752
+ i.debug && ((N = f == null ? void 0 : f.metadata) != null && N.sentiment) && (I.sentiment = {
753
+ id: f.metadata.sentiment.id,
754
+ name: f.metadata.sentiment.sentiment
755
+ }), (te = t.onMessage) == null || te.call(t, u, I), F(u, f);
756
756
  }
757
- function ce(u, m) {
757
+ function ce(u, f) {
758
758
  var p;
759
- (p = t.onMessage) == null || p.call(t, X.Transcribe, { event: X.Transcribe, ...m }), queueMicrotask(() => {
759
+ (p = t.onMessage) == null || p.call(t, X.Transcribe, { event: X.Transcribe, ...f }), queueMicrotask(() => {
760
760
  var v;
761
761
  (v = t.onAgentActivityStateChange) == null || v.call(t, W.Loading);
762
762
  });
@@ -772,7 +772,7 @@ async function un(e, n, i) {
772
772
  [D.StreamVideoRejected]: se,
773
773
  [D.ChatAudioTranscribed]: ce
774
774
  };
775
- function ve(u, m, p, v) {
775
+ function ve(u, f, p, v) {
776
776
  const I = new TextDecoder().decode(u);
777
777
  try {
778
778
  const P = JSON.parse(I), Q = v || P.subject;
@@ -784,41 +784,41 @@ async function un(e, n, i) {
784
784
  }
785
785
  }
786
786
  function Ce(u) {
787
- var m;
788
- r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(pe), { sessionId: f });
787
+ var f;
788
+ r("Media devices error:", u), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
789
789
  }
790
790
  function dt(u) {
791
- var m;
792
- r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(pe), { sessionId: f });
791
+ var f;
792
+ r("Encryption error:", u), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
793
793
  }
794
- function ut(u, m, p) {
795
- r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
794
+ function ut(u, f, p) {
795
+ r("Track subscription failed:", { trackSid: u, participant: f, reason: p });
796
796
  }
797
- function lt(u, m, p) {
797
+ function lt(u, f, p) {
798
798
  for (const [v, I] of p)
799
- if (I.source === m && I.track) {
799
+ if (I.source === f && I.track) {
800
800
  const P = I.track.mediaStreamTrack;
801
801
  if (P === u || (P == null ? void 0 : P.id) === u.id)
802
802
  return I;
803
803
  }
804
804
  return null;
805
805
  }
806
- async function Be(u, m, p, v, I, P) {
807
- var me, fe, de;
806
+ async function Be(u, f, p, v, I, P) {
807
+ var fe, me, de;
808
808
  if (!y || !l)
809
809
  throw r(`Room is not connected, cannot publish ${v} stream`), new Error("Room is not connected");
810
810
  if (u.isPublishing) {
811
811
  r(`${v} publish already in progress, skipping`);
812
812
  return;
813
813
  }
814
- const Q = p(m);
814
+ const Q = p(f);
815
815
  if (Q.length === 0)
816
816
  throw new Error(`No ${v} track found in the provided MediaStream`);
817
817
  const N = Q[0], te = lt(N, v, I());
818
818
  if (te) {
819
819
  r(`${v} track is already published, skipping`, {
820
820
  trackId: N.id,
821
- publishedTrackId: (fe = (me = te.track) == null ? void 0 : me.mediaStreamTrack) == null ? void 0 : fe.id
821
+ publishedTrackId: (me = (fe = te.track) == null ? void 0 : fe.mediaStreamTrack) == null ? void 0 : me.id
822
822
  }), u.publication = te;
823
823
  return;
824
824
  }
@@ -835,21 +835,21 @@ async function un(e, n, i) {
835
835
  u.isPublishing = !1;
836
836
  }
837
837
  }
838
- async function Fe(u, m) {
838
+ async function Fe(u, f) {
839
839
  if (!(!u.publication || !u.publication.track))
840
840
  try {
841
- l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${m} track unpublished`));
841
+ l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${f} track unpublished`));
842
842
  } catch (p) {
843
- r(`Error unpublishing ${m} track:`, p);
843
+ r(`Error unpublishing ${f} track:`, p);
844
844
  } finally {
845
845
  u.publication = null;
846
846
  }
847
847
  }
848
- async function mt(u) {
848
+ async function ft(u) {
849
849
  return Be(
850
850
  L,
851
851
  u,
852
- (m) => m.getAudioTracks(),
852
+ (f) => f.getAudioTracks(),
853
853
  d.Source.Microphone,
854
854
  () => l.localParticipant.audioTrackPublications,
855
855
  Te
@@ -858,11 +858,11 @@ async function un(e, n, i) {
858
858
  async function Te() {
859
859
  return Fe(L, "Microphone");
860
860
  }
861
- async function ft(u) {
861
+ async function mt(u) {
862
862
  return Be(
863
863
  j,
864
864
  u,
865
- (m) => m.getVideoTracks(),
865
+ (f) => f.getVideoTracks(),
866
866
  d.Source.Camera,
867
867
  () => l.localParticipant.videoTrackPublications,
868
868
  ke
@@ -874,27 +874,27 @@ async function un(e, n, i) {
874
874
  function gt() {
875
875
  z && (z.getTracks().forEach((u) => u.stop()), z = null);
876
876
  }
877
- async function Ee(u, m) {
877
+ async function Ee(u, f) {
878
878
  var p, v;
879
879
  if (!y || !l) {
880
880
  r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(pe), {
881
- sessionId: f
881
+ sessionId: m
882
882
  });
883
883
  return;
884
884
  }
885
885
  try {
886
- await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
886
+ await l.localParticipant.sendText(u, { topic: f }), r("Message sent successfully:", u);
887
887
  } catch (I) {
888
- r("Failed to send message:", I), (v = t.onError) == null || v.call(t, new Error(pe), { sessionId: f });
888
+ r("Failed to send message:", I), (v = t.onError) == null || v.call(t, new Error(pe), { sessionId: m });
889
889
  }
890
890
  }
891
891
  async function ht(u) {
892
- var m;
892
+ var f;
893
893
  try {
894
894
  const v = JSON.parse(u).topic;
895
895
  return Ee("", v);
896
896
  } catch (p) {
897
- r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(pe), { sessionId: f });
897
+ r("Failed to send data channel message:", p), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
898
898
  }
899
899
  }
900
900
  function pt(u) {
@@ -905,21 +905,21 @@ async function un(e, n, i) {
905
905
  );
906
906
  }
907
907
  async function De(u) {
908
- var m, p;
909
- K && (clearTimeout(K), K = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, b.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()), gt(), y = !1, q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), G = W.Idle;
908
+ var f, p;
909
+ K && (clearTimeout(K), K = null), k == null || k.destroy(), k = null, l && ((f = t.onConnectionStateChange) == null || f.call(t, b.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()), gt(), y = !1, q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), G = W.Idle;
910
910
  }
911
911
  return {
912
912
  speak(u) {
913
- const m = typeof u == "string" ? u : JSON.stringify(u);
913
+ const f = typeof u == "string" ? u : JSON.stringify(u);
914
914
  return Ee(
915
- m,
915
+ f,
916
916
  "did.speak"
917
917
  /* Speak */
918
918
  );
919
919
  },
920
920
  disconnect: () => De("user:disconnect"),
921
921
  async reconnect() {
922
- var u, m;
922
+ var u, f;
923
923
  if ((l == null ? void 0 : l.state) === s.Connected) {
924
924
  r("Room is already connected");
925
925
  return;
@@ -941,17 +941,17 @@ async function un(e, n, i) {
941
941
  r("Agent joined, reconnection successful");
942
942
  }
943
943
  } catch (p) {
944
- throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, b.Fail, "user:reconnect-failed"), p;
944
+ throw r("Failed to reconnect:", p), (f = t.onConnectionStateChange) == null || f.call(t, b.Fail, "user:reconnect-failed"), p;
945
945
  }
946
946
  },
947
947
  sendDataChannelMessage: ht,
948
948
  sendTextMessage: pt,
949
- publishMicrophoneStream: mt,
949
+ publishMicrophoneStream: ft,
950
950
  unpublishMicrophoneStream: Te,
951
- publishCameraStream: ft,
951
+ publishCameraStream: mt,
952
952
  unpublishCameraStream: ke,
953
- sessionId: f,
954
- streamId: f,
953
+ sessionId: m,
954
+ streamId: m,
955
955
  streamType: A,
956
956
  interruptAvailable: J,
957
957
  isInterruptible: ae
@@ -963,7 +963,7 @@ const ln = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
963
963
  createLiveKitStreamingManager: un,
964
964
  handleInitError: _e
965
965
  }, Symbol.toStringTag, { value: "Module" }));
966
- function mn(e, n, i) {
966
+ function fn(e, n, i) {
967
967
  if (!e)
968
968
  throw new Error("Please connect to the agent first");
969
969
  if (!e.interruptAvailable)
@@ -973,7 +973,7 @@ function mn(e, n, i) {
973
973
  if (!i)
974
974
  throw new Error("No active video to interrupt");
975
975
  }
976
- async function fn(e, n) {
976
+ async function mn(e, n) {
977
977
  const i = {
978
978
  type: D.StreamInterrupt,
979
979
  videoId: n,
@@ -1238,7 +1238,7 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
1238
1238
  interrupt_enabled: ae
1239
1239
  } = await j(n, d);
1240
1240
  (ee = r.onStreamCreated) == null || ee.call(r, { stream_id: k, session_id: K, agent_id: e });
1241
- const $ = new Tn({ iceServers: q }), f = $.createDataChannel("JanusDataChannel");
1241
+ const $ = new Tn({ iceServers: q }), m = $.createDataChannel("JanusDataChannel");
1242
1242
  if (!K)
1243
1243
  throw new Error("Could not create session_id");
1244
1244
  const C = G ? ie.Fluent : ie.Legacy;
@@ -1283,7 +1283,7 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
1283
1283
  } catch (R) {
1284
1284
  (w = r.onError) == null || w.call(r, R, { streamId: k });
1285
1285
  }
1286
- }, f.onopen = () => {
1286
+ }, m.onopen = () => {
1287
1287
  g = !0, (!E || h) && x();
1288
1288
  };
1289
1289
  const V = (S) => {
@@ -1314,7 +1314,7 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
1314
1314
  [D.StreamDone]: Y,
1315
1315
  [D.StreamReady]: Z
1316
1316
  };
1317
- f.onmessage = (S) => {
1317
+ m.onmessage = (S) => {
1318
1318
  var F;
1319
1319
  const { subject: w, data: R } = c(S.data);
1320
1320
  (F = B[w]) == null || F.call(B, w, R);
@@ -1364,14 +1364,14 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
1364
1364
  */
1365
1365
  sendDataChannelMessage(S) {
1366
1366
  var w, R;
1367
- if (!h || f.readyState !== "open") {
1367
+ if (!h || m.readyState !== "open") {
1368
1368
  t("Data channel is not ready for sending messages"), (w = r.onError) == null || w.call(r, new Error("Data channel is not ready for sending messages"), {
1369
1369
  streamId: k
1370
1370
  });
1371
1371
  return;
1372
1372
  }
1373
1373
  try {
1374
- f.send(S);
1374
+ m.send(S);
1375
1375
  } catch (F) {
1376
1376
  t("Error sending data channel message", F), (R = r.onError) == null || R.call(r, F, { streamId: k });
1377
1377
  }
@@ -1610,28 +1610,28 @@ async function Kn(e, n) {
1610
1610
  const y = Le(l.presenter.type);
1611
1611
  c.enrich(Jt(l));
1612
1612
  const { onMessage: A, clearQueue: z } = Sn(c, t, n, l, () => {
1613
- var f, C, E;
1614
- (f = t.socketManager) == null || f.disconnect(), (E = (C = n.callbacks).onConnectionStateChange) == null || E.call(C, b.Disconnected);
1613
+ var m, C, E;
1614
+ (m = t.socketManager) == null || m.disconnect(), (E = (C = n.callbacks).onConnectionStateChange) == null || E.call(C, b.Disconnected);
1615
1615
  });
1616
1616
  t.messages = Xt(n.initialMessages), (ae = (G = n.callbacks).onNewMessage) == null || ae.call(G, [...t.messages], "answer");
1617
- const L = (f) => {
1618
- r = f;
1619
- }, j = ({ type: f }) => {
1617
+ const L = (m) => {
1618
+ r = m;
1619
+ }, j = ({ type: m }) => {
1620
1620
  var E, J, x, M, V;
1621
1621
  if (!((E = t.streamingManager) != null && E.interruptAvailable) || !((J = t.streamingManager) != null && J.isInterruptible)) return;
1622
1622
  const C = t.messages[t.messages.length - 1];
1623
1623
  c.track("agent-video-interrupt", {
1624
- type: f || "click",
1624
+ type: m || "click",
1625
1625
  video_duration_to_interrupt: Ae.get(!0),
1626
1626
  message_duration_to_interrupt: re.get(!0)
1627
- }), C.interrupted = !0, (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "answer"), y ? gn(t.streamingManager) : (mn(t.streamingManager, (V = t.streamingManager) == null ? void 0 : V.streamType, r), fn(t.streamingManager, r));
1627
+ }), C.interrupted = !0, (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "answer"), y ? gn(t.streamingManager) : (fn(t.streamingManager, (V = t.streamingManager) == null ? void 0 : V.streamType, r), mn(t.streamingManager, r));
1628
1628
  }, _ = Date.now();
1629
1629
  Oe(() => {
1630
1630
  c.track("agent-sdk", { event: "loaded", ...Ut(l) }, _);
1631
1631
  });
1632
- async function k(f) {
1632
+ async function k(m) {
1633
1633
  var V, Y, Z, B, U, ee, S;
1634
- (Y = (V = n.callbacks).onConnectionStateChange) == null || Y.call(V, b.Connecting), re.reset(), f && !i && (delete t.chat, (B = (Z = n.callbacks).onNewMessage) == null || B.call(Z, [...t.messages], "answer"));
1634
+ (Y = (V = n.callbacks).onConnectionStateChange) == null || Y.call(V, b.Connecting), re.reset(), m && !i && (delete t.chat, (B = (Z = n.callbacks).onNewMessage) == null || B.call(Z, [...t.messages], "answer"));
1635
1635
  const C = d === O.DirectPlayback || y ? Promise.resolve(void 0) : wn(
1636
1636
  n.auth,
1637
1637
  a,
@@ -1672,22 +1672,22 @@ async function Kn(e, n) {
1672
1672
  }), q((M == null ? void 0 : M.chat_mode) ?? d);
1673
1673
  }
1674
1674
  async function H() {
1675
- var f, C, E, J;
1676
- (f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (J = (E = n.callbacks).onConnectionStateChange) == null || J.call(E, b.Disconnected);
1675
+ var m, C, E, J;
1676
+ (m = t.socketManager) == null || m.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (J = (E = n.callbacks).onConnectionStateChange) == null || J.call(E, b.Disconnected);
1677
1677
  }
1678
- async function q(f) {
1678
+ async function q(m) {
1679
1679
  var C, E;
1680
- f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await H(), (E = (C = n.callbacks).onModeChange) == null || E.call(C, f));
1680
+ m !== t.chatMode && (c.track("agent-mode-change", { mode: m }), t.chatMode = m, t.chatMode !== O.Functional && await H(), (E = (C = n.callbacks).onModeChange) == null || E.call(C, m));
1681
1681
  }
1682
1682
  return {
1683
1683
  agent: l,
1684
1684
  getStreamType: () => {
1685
- var f;
1686
- return (f = t.streamingManager) == null ? void 0 : f.streamType;
1685
+ var m;
1686
+ return (m = t.streamingManager) == null ? void 0 : m.streamType;
1687
1687
  },
1688
1688
  getIsInterruptAvailable: () => {
1689
- var f;
1690
- return ((f = t.streamingManager) == null ? void 0 : f.interruptAvailable) ?? !1;
1689
+ var m;
1690
+ return ((m = t.streamingManager) == null ? void 0 : m.interruptAvailable) ?? !1;
1691
1691
  },
1692
1692
  starterMessages: (($ = l.knowledge) == null ? void 0 : $.starter_message) || [],
1693
1693
  getSTTToken: () => g.getSTTToken(l.id),
@@ -1700,10 +1700,10 @@ async function Kn(e, n) {
1700
1700
  });
1701
1701
  },
1702
1702
  async reconnect() {
1703
- const f = t.streamingManager;
1704
- if (y && (f != null && f.reconnect)) {
1703
+ const m = t.streamingManager;
1704
+ if (y && (m != null && m.reconnect)) {
1705
1705
  try {
1706
- await f.reconnect(), c.track("agent-chat", {
1706
+ await m.reconnect(), c.track("agent-chat", {
1707
1707
  event: "reconnect",
1708
1708
  mode: t.chatMode
1709
1709
  });
@@ -1723,38 +1723,36 @@ async function Kn(e, n) {
1723
1723
  mode: t.chatMode
1724
1724
  });
1725
1725
  },
1726
- async publishMicrophoneStream(f) {
1726
+ async publishMicrophoneStream(m) {
1727
1727
  var C;
1728
1728
  if (!((C = t.streamingManager) != null && C.publishMicrophoneStream))
1729
1729
  throw new Error("publishMicrophoneStream is not available for this streaming manager");
1730
- return t.streamingManager.publishMicrophoneStream(f);
1730
+ return t.streamingManager.publishMicrophoneStream(m);
1731
1731
  },
1732
1732
  async unpublishMicrophoneStream() {
1733
- var f;
1734
- if (!((f = t.streamingManager) != null && f.unpublishMicrophoneStream))
1735
- throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
1736
- return t.streamingManager.unpublishMicrophoneStream();
1733
+ var m;
1734
+ if ((m = t.streamingManager) != null && m.unpublishMicrophoneStream)
1735
+ return t.streamingManager.unpublishMicrophoneStream();
1737
1736
  },
1738
- async publishCameraStream(f) {
1737
+ async publishCameraStream(m) {
1739
1738
  var C;
1740
1739
  if (!((C = t.streamingManager) != null && C.publishCameraStream))
1741
1740
  throw new Error("publishCameraStream is not available for this streaming manager");
1742
- return t.streamingManager.publishCameraStream(f);
1741
+ return t.streamingManager.publishCameraStream(m);
1743
1742
  },
1744
1743
  async unpublishCameraStream() {
1745
- var f;
1746
- if (!((f = t.streamingManager) != null && f.unpublishCameraStream))
1747
- throw new Error("unpublishCameraStream is not available for this streaming manager");
1748
- return t.streamingManager.unpublishCameraStream();
1744
+ var m;
1745
+ if ((m = t.streamingManager) != null && m.unpublishCameraStream)
1746
+ return t.streamingManager.unpublishCameraStream();
1749
1747
  },
1750
- async chat(f) {
1748
+ async chat(m) {
1751
1749
  var x, M, V, Y, Z;
1752
1750
  const C = () => {
1753
1751
  if (nt(d))
1754
1752
  throw new ue(`${d} is enabled, chat is disabled`);
1755
- if (f.length >= 800)
1753
+ if (m.length >= 800)
1756
1754
  throw new ue("Message cannot be more than 800 characters");
1757
- if (f.length === 0)
1755
+ if (m.length === 0)
1758
1756
  throw new ue("Message cannot be empty");
1759
1757
  if (t.chatMode === O.Maintenance)
1760
1758
  throw new ue("Chat is in maintenance mode");
@@ -1783,7 +1781,7 @@ async function Kn(e, n) {
1783
1781
  const ee = t.chatMode === O.Playground;
1784
1782
  return Ie(y && !ee ? async () => {
1785
1783
  var R, F;
1786
- return await ((F = (R = t.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : F.call(R, f)), Promise.resolve({});
1784
+ return await ((F = (R = t.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : F.call(R, m)), Promise.resolve({});
1787
1785
  } : async () => {
1788
1786
  var R, F;
1789
1787
  return g.chat(
@@ -1816,7 +1814,7 @@ async function Kn(e, n) {
1816
1814
  z(), C(), t.messages.push({
1817
1815
  id: le(),
1818
1816
  role: "user",
1819
- content: f,
1817
+ content: m,
1820
1818
  created_at: new Date(re.update()).toISOString()
1821
1819
  }), (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "user");
1822
1820
  const B = await E(), U = await J([...t.messages], B);
@@ -1841,9 +1839,9 @@ async function Kn(e, n) {
1841
1839
  }), B;
1842
1840
  }
1843
1841
  },
1844
- rate(f, C, E) {
1842
+ rate(m, C, E) {
1845
1843
  var M, V, Y, Z;
1846
- const J = t.messages.find((B) => B.id === f);
1844
+ const J = t.messages.find((B) => B.id === m);
1847
1845
  if (t.chat) {
1848
1846
  if (!J)
1849
1847
  throw new Error("Message not found");
@@ -1857,45 +1855,45 @@ async function Kn(e, n) {
1857
1855
  score: C
1858
1856
  }), E ? g.updateRating(l.id, t.chat.id, E, {
1859
1857
  knowledge_id: ((Y = l.knowledge) == null ? void 0 : Y.id) ?? "",
1860
- message_id: f,
1858
+ message_id: m,
1861
1859
  matches: x,
1862
1860
  score: C
1863
1861
  }) : g.createRating(l.id, t.chat.id, {
1864
1862
  knowledge_id: ((Z = l.knowledge) == null ? void 0 : Z.id) ?? "",
1865
- message_id: f,
1863
+ message_id: m,
1866
1864
  matches: x,
1867
1865
  score: C
1868
1866
  });
1869
1867
  },
1870
- deleteRate(f) {
1868
+ deleteRate(m) {
1871
1869
  if (!t.chat)
1872
1870
  throw new Error("Chat is not initialized");
1873
- return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
1871
+ return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, m);
1874
1872
  },
1875
- async speak(f) {
1873
+ async speak(m) {
1876
1874
  var x, M, V;
1877
1875
  function C() {
1878
- if (typeof f == "string") {
1876
+ if (typeof m == "string") {
1879
1877
  if (!l.presenter.voice)
1880
1878
  throw new Error("Presenter voice is not initialized");
1881
1879
  return {
1882
1880
  type: "text",
1883
1881
  provider: l.presenter.voice,
1884
- input: f,
1882
+ input: m,
1885
1883
  ssml: !1
1886
1884
  };
1887
1885
  }
1888
- if (f.type === "text" && !f.provider) {
1886
+ if (m.type === "text" && !m.provider) {
1889
1887
  if (!l.presenter.voice)
1890
1888
  throw new Error("Presenter voice is not initialized");
1891
1889
  return {
1892
1890
  type: "text",
1893
1891
  provider: l.presenter.voice,
1894
- input: f.input,
1895
- ssml: f.ssml
1892
+ input: m.input,
1893
+ ssml: m.ssml
1896
1894
  };
1897
1895
  }
1898
- return f;
1896
+ return m;
1899
1897
  }
1900
1898
  const E = C();
1901
1899
  if (c.track("agent-speak", E), re.update(), t.messages && E.type === "text" && (t.messages.push({