@d-id/client-sdk 1.1.67-staging.312 → 1.1.67-staging.314

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.
@@ -35,7 +35,7 @@ class qe extends ce {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), U = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(U || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
38
+ var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), N = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(N || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
39
39
  const sr = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
@@ -405,10 +405,10 @@ function It(e) {
405
405
  function Mt(e) {
406
406
  return new Promise((t, r) => {
407
407
  const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(ze(s, o))}`);
408
- l.onmessage = n, l.onclose = d, l.onerror = (w) => {
409
- console.error(w), m == null || m("Websocket failed to connect", w), r(w);
410
- }, l.onopen = (w) => {
411
- i == null || i(w), t(l);
408
+ l.onmessage = n, l.onclose = d, l.onerror = (h) => {
409
+ console.error(h), m == null || m("Websocket failed to connect", h), r(h);
410
+ }, l.onopen = (h) => {
411
+ i == null || i(h), t(l);
412
412
  };
413
413
  });
414
414
  }
@@ -470,47 +470,57 @@ function bt(e, t, r) {
470
470
  };
471
471
  t.messages.push(c), r == null || r([...t.messages], "user");
472
472
  }
473
- function At(e, t, r, a, c, s) {
474
- if (e === U.Transcribe && t.content) {
473
+ function At(e, t, r, a, c, s, o) {
474
+ if (e === N.Transcribe && t.content) {
475
475
  bt(t, a, c);
476
476
  return;
477
477
  }
478
- if (!(e === U.Partial || e === U.Answer))
478
+ if (!(e === N.Partial || e === N.Answer))
479
479
  return;
480
- const o = a.messages[a.messages.length - 1], n = t.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== t.id;
481
- let i;
482
- if ((o == null ? void 0 : o.role) === "assistant" && !n)
483
- i = o;
484
- else if (!o || o.transcribed && o.role === "user" || n)
485
- n && s(), i = {
480
+ const n = a.messages[a.messages.length - 1], i = o === "answer";
481
+ let d;
482
+ if ((n == null ? void 0 : n.role) === "assistant" && !i)
483
+ d = n;
484
+ else if (!n || n.role === "user" || i)
485
+ i && s(), d = {
486
486
  id: t.id || `assistant-${Date.now()}`,
487
487
  role: t.role || "assistant",
488
488
  content: t.content || "",
489
489
  parts: [],
490
490
  created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
491
- }, a.messages.push(i);
491
+ }, a.messages.push(d);
492
492
  else
493
493
  return;
494
- const { content: d, sequence: m } = t;
495
- e === U.Partial ? r[m] = d : r.answer = d;
496
- const l = _t(r);
497
- (i.content !== l || e === U.Answer) && (i.content = l, i.parts = re(l), c == null || c([...a.messages], e));
494
+ const { content: m, sequence: l } = t;
495
+ e === N.Partial ? r[l] = m : r.answer = m;
496
+ const h = _t(r);
497
+ (d.content !== h || e === N.Answer) && (d.content = h, d.parts = re(h), c == null || c([...a.messages], e));
498
498
  }
499
499
  function xt(e, t, r, a, c) {
500
- let s = {};
501
- const o = () => s = {};
502
- let n = "answer";
500
+ const s = {}, o = () => {
501
+ for (const d of Object.keys(s))
502
+ delete s[d];
503
+ };
504
+ let n = null;
503
505
  const i = (d, m) => {
504
- var l, w;
505
- m === "user" && o(), n = m, (w = (l = r.callbacks).onNewMessage) == null || w.call(l, d, m);
506
+ var l, h;
507
+ m === "user" && o(), (h = (l = r.callbacks).onNewMessage) == null || h.call(l, d, m);
506
508
  };
507
509
  return {
508
510
  clearQueue: o,
509
511
  onMessage: (d, m) => {
510
- var l, w;
512
+ var l, h;
511
513
  if ("content" in m) {
512
- const v = d === P.ChatAnswer ? U.Answer : d === P.ChatAudioTranscribed ? U.Transcribe : d;
513
- At(v, m, s, t, i, o), v === U.Answer && e.track("agent-message-received", {
514
+ const v = d === P.ChatAnswer ? N.Answer : d === P.ChatAudioTranscribed ? N.Transcribe : d;
515
+ At(
516
+ v,
517
+ m,
518
+ s,
519
+ t,
520
+ i,
521
+ o,
522
+ n
523
+ ), v === N.Partial ? n = "partial" : v === N.Answer && (n = "answer", o()), v === N.Answer && e.track("agent-message-received", {
514
524
  content: m.content,
515
525
  messages: t.messages.length,
516
526
  mode: t.chatMode
@@ -521,14 +531,14 @@ function xt(e, t, r, a, c) {
521
531
  const D = t.messages[t.messages.length - 1];
522
532
  if ((D == null ? void 0 : D.role) === "assistant") {
523
533
  const $ = { ...D, sentiment: m.sentiment };
524
- t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n);
534
+ t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n ?? "answer");
525
535
  }
526
536
  }
527
537
  if (k.includes(d)) {
528
538
  const D = d.split("/")[1];
529
539
  B.includes(d) ? e.track("agent-video", { ...M, event: D }) : e.linkTrack("agent-video", { ...M, event: D }, d, ["done"]);
530
540
  }
531
- B.includes(d) && ((w = (l = r.callbacks).onError) == null || w.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === v.StreamDone && c();
541
+ B.includes(d) && ((h = (l = r.callbacks).onError) == null || h.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === v.StreamDone && c();
532
542
  }
533
543
  }
534
544
  };
@@ -727,13 +737,13 @@ function cr(e, t) {
727
737
  c = setTimeout(i, ee);
728
738
  return;
729
739
  }
730
- const l = m.totalAudioEnergy ?? 0, w = m.totalSamplesReceived ?? 0;
740
+ const l = m.totalAudioEnergy ?? 0, h = m.totalSamplesReceived ?? 0;
731
741
  if (!a) {
732
- s = l, o = w, a = !0, c = setTimeout(i, ee);
742
+ s = l, o = h, a = !0, c = setTimeout(i, ee);
733
743
  return;
734
744
  }
735
- const v = l - s, k = w - o;
736
- if (s = l, o = w, k > 0 && v > 0) {
745
+ const v = l - s, k = h - o;
746
+ if (s = l, o = h, k > 0 && v > 0) {
737
747
  r = !1, t(n);
738
748
  return;
739
749
  }
@@ -769,7 +779,7 @@ function Vt() {
769
779
  };
770
780
  }
771
781
  function Kt(e, t, r, a, c) {
772
- let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, w = 0, v = 0;
782
+ let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, h = 0, v = 0;
773
783
  const k = Vt();
774
784
  async function B() {
775
785
  const M = await e();
@@ -777,7 +787,7 @@ function Kt(e, t, r, a, c) {
777
787
  return;
778
788
  const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q = $t(M);
779
789
  if (D)
780
- i = 0, w = _ - v, l = $ < Ft ? te.Strong : $ > Nt && w > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, v += w, w = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
790
+ i = 0, h = _ - v, l = $ < Ft ? te.Strong : $ > Nt && h > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, v += h, h = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
781
791
  else if (d && (i++, i >= zt)) {
782
792
  const J = _e(o, oe, n);
783
793
  a == null || a(S.Stop, J), t() || r(), v = _, d = !1;
@@ -863,7 +873,7 @@ function Ae({
863
873
  async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de, analytics: o }, n) {
864
874
  var E;
865
875
  const i = Pt(r, "WebRTCStreamingManager"), d = Wt(i);
866
- let m = !1, l = !1, w = S.Stop, v = S.Stop;
876
+ let m = !1, l = !1, h = S.Stop, v = S.Stop;
867
877
  const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = Lt(
868
878
  c,
869
879
  s,
@@ -873,17 +883,17 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
873
883
  id: _,
874
884
  offer: q,
875
885
  ice_servers: J,
876
- session_id: N,
886
+ session_id: V,
877
887
  fluent: X,
878
888
  interrupt_enabled: O
879
889
  } = await D(t, n);
880
- (E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: N, agent_id: e });
890
+ (E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: V, agent_id: e });
881
891
  const I = new Ut({ iceServers: J }), Y = I.createDataChannel("JanusDataChannel");
882
- if (!N)
892
+ if (!V)
883
893
  throw new Error("Could not create session_id");
884
- const V = X ? W.Fluent : W.Legacy;
894
+ const K = X ? W.Fluent : W.Legacy;
885
895
  o.enrich({
886
- "stream-type": V
896
+ "stream-type": K
887
897
  });
888
898
  const ae = t.stream_warmup && !X, ie = () => m, u = () => {
889
899
  var f;
@@ -892,22 +902,22 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
892
902
  () => I.getStats(),
893
903
  ie,
894
904
  u,
895
- (f, h) => Ae({
905
+ (f, p) => Ae({
896
906
  statsSignal: v = f,
897
- dataChannelSignal: V === W.Legacy ? w : void 0,
907
+ dataChannelSignal: K === W.Legacy ? h : void 0,
898
908
  onVideoStateChange: a.onVideoStateChange,
899
909
  onAgentActivityStateChange: a.onAgentActivityStateChange,
900
- report: h,
901
- streamType: V,
910
+ report: p,
911
+ streamType: K,
902
912
  log: i
903
913
  }),
904
914
  (f) => {
905
- var h;
906
- return (h = a.onConnectivityStateChange) == null ? void 0 : h.call(a, f);
915
+ var p;
916
+ return (p = a.onConnectivityStateChange) == null ? void 0 : p.call(a, f);
907
917
  }
908
918
  );
909
919
  g.start(), I.onicecandidate = (f) => {
910
- var h;
920
+ var p;
911
921
  i("peerConnection.onicecandidate", f);
912
922
  try {
913
923
  f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? $(
@@ -917,37 +927,37 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
917
927
  sdpMid: f.candidate.sdpMid,
918
928
  sdpMLineIndex: f.candidate.sdpMLineIndex
919
929
  },
920
- N,
930
+ V,
921
931
  n
922
- ) : $(_, { candidate: null }, N, n);
932
+ ) : $(_, { candidate: null }, V, n);
923
933
  } catch (b) {
924
- (h = a.onError) == null || h.call(a, b, { streamId: _ });
934
+ (p = a.onError) == null || p.call(a, b, { streamId: _ });
925
935
  }
926
936
  }, Y.onopen = () => {
927
937
  l = !0, (!ae || m) && u();
928
938
  };
929
- let p = null;
939
+ let w = null;
930
940
  const y = (f) => {
931
- var h;
932
- p = f, (h = a.onVideoIdChange) == null || h.call(a, f);
941
+ var p;
942
+ w = f, (p = a.onVideoIdChange) == null || p.call(a, f);
933
943
  };
934
- function C(f, h) {
935
- if (f === P.StreamStarted && typeof h == "object" && "metadata" in h) {
936
- const b = h.metadata;
944
+ function C(f, p) {
945
+ if (f === P.StreamStarted && typeof p == "object" && "metadata" in p) {
946
+ const b = p.metadata;
937
947
  y(b.videoId);
938
948
  }
939
- f === P.StreamDone && y(null), w = f === P.StreamStarted ? S.Start : S.Stop, Ae({
940
- statsSignal: V === W.Legacy ? v : void 0,
941
- dataChannelSignal: w,
949
+ f === P.StreamDone && y(null), h = f === P.StreamStarted ? S.Start : S.Stop, Ae({
950
+ statsSignal: K === W.Legacy ? v : void 0,
951
+ dataChannelSignal: h,
942
952
  onVideoStateChange: a.onVideoStateChange,
943
953
  onAgentActivityStateChange: a.onAgentActivityStateChange,
944
- streamType: V,
954
+ streamType: K,
945
955
  log: i
946
956
  });
947
957
  }
948
- function R(f, h) {
958
+ function R(f, p) {
949
959
  var T;
950
- const b = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
960
+ const b = typeof p == "string" ? p : p == null ? void 0 : p.metadata;
951
961
  b && o.enrich({ streamMetadata: b }), (T = a.onStreamReady) == null || T.call(a);
952
962
  }
953
963
  const j = {
@@ -957,23 +967,23 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
957
967
  };
958
968
  Y.onmessage = (f) => {
959
969
  var T;
960
- const { subject: h, data: b } = d(f.data);
961
- (T = j[h]) == null || T.call(j, h, b);
970
+ const { subject: p, data: b } = d(f.data);
971
+ (T = j[p]) == null || T.call(j, p, b);
962
972
  }, I.oniceconnectionstatechange = () => {
963
- var h;
973
+ var p;
964
974
  i("peerConnection.oniceconnectionstatechange => " + I.iceConnectionState);
965
975
  const f = be(I.iceConnectionState);
966
- f !== L.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, f));
976
+ f !== L.Connected && ((p = a.onConnectionStateChange) == null || p.call(a, f));
967
977
  }, I.ontrack = (f) => {
968
- var h;
969
- i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, f.streams[0]);
978
+ var p;
979
+ i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (p = a.onSrcObjectReady) == null || p.call(a, f.streams[0]);
970
980
  }, await I.setRemoteDescription(q), i("set remote description OK");
971
981
  const z = await I.createAnswer();
972
- i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await k(_, z, N, n), i("start connection OK");
982
+ i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await k(_, z, V, n), i("start connection OK");
973
983
  function F(f) {
974
- var h, b;
984
+ var p, b;
975
985
  if (!m || Y.readyState !== "open") {
976
- i("Data channel is not ready for sending messages"), (h = a.onError) == null || h.call(a, new Error("Data channel is not ready for sending messages"), {
986
+ i("Data channel is not ready for sending messages"), (p = a.onError) == null || p.call(a, new Error("Data channel is not ready for sending messages"), {
977
987
  streamId: _
978
988
  });
979
989
  return;
@@ -990,7 +1000,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
990
1000
  * @param payload
991
1001
  */
992
1002
  speak(f) {
993
- return B(_, N, f);
1003
+ return B(_, V, f);
994
1004
  },
995
1005
  /**
996
1006
  * Method to close RTC connection
@@ -998,16 +1008,16 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
998
1008
  async disconnect() {
999
1009
  var f;
1000
1010
  if (_) {
1001
- const h = be(I.iceConnectionState);
1011
+ const p = be(I.iceConnectionState);
1002
1012
  if (I) {
1003
- if (h === L.New) {
1013
+ if (p === L.New) {
1004
1014
  g.stop();
1005
1015
  return;
1006
1016
  }
1007
1017
  I.close(), I.oniceconnectionstatechange = null, I.onnegotiationneeded = null, I.onicecandidate = null, I.ontrack = null;
1008
1018
  }
1009
1019
  try {
1010
- h === L.Connected && await M(_, N).catch((b) => {
1020
+ p === L.Connected && await M(_, V).catch((b) => {
1011
1021
  });
1012
1022
  } catch (b) {
1013
1023
  i("Error on close stream connection", b);
@@ -1019,27 +1029,27 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
1019
1029
  /**
1020
1030
  * Session identifier information, should be returned in the body of all streaming requests
1021
1031
  */
1022
- sessionId: N,
1032
+ sessionId: V,
1023
1033
  /**
1024
1034
  * Id of current RTC stream
1025
1035
  */
1026
1036
  streamId: _,
1027
- streamType: V,
1037
+ streamType: K,
1028
1038
  interruptAvailable: O ?? !1,
1029
1039
  isInterruptible: !0,
1030
1040
  interrupt(f) {
1031
1041
  if (!O)
1032
1042
  throw new Error("Interrupt is not enabled for this stream");
1033
- if (V !== W.Fluent)
1043
+ if (K !== W.Fluent)
1034
1044
  throw new Error("Interrupt only available for Fluent streams");
1035
- if (!p)
1045
+ if (!w)
1036
1046
  throw new Error("No active video to interrupt");
1037
- const h = {
1047
+ const p = {
1038
1048
  type: P.StreamInterrupt,
1039
- videoId: p,
1049
+ videoId: w,
1040
1050
  timestamp: Date.now()
1041
1051
  };
1042
- F(JSON.stringify(h));
1052
+ F(JSON.stringify(p));
1043
1053
  }
1044
1054
  };
1045
1055
  }
@@ -1055,7 +1065,7 @@ async function qt(e, t, r, a) {
1055
1065
  const { version: s, ...o } = t;
1056
1066
  switch (o.transport.provider) {
1057
1067
  case he.Livekit:
1058
- const { createLiveKitStreamingManager: n } = await import("./livekit-manager-BtTtY9lx.js");
1068
+ const { createLiveKitStreamingManager: n } = await import("./livekit-manager-B7gYoJ6B.js");
1059
1069
  return n(c, o, r);
1060
1070
  default:
1061
1071
  throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
@@ -1173,23 +1183,23 @@ function Le(e, t, r, a) {
1173
1183
  analytics: r,
1174
1184
  callbacks: {
1175
1185
  ...t.callbacks,
1176
- onConnectionStateChange: (l, w) => {
1186
+ onConnectionStateChange: (l, h) => {
1177
1187
  var v, k;
1178
- (k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Zt(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
1188
+ (k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Zt(l, h, r), l === L.Connected && (o ? c(o) : n = !0);
1179
1189
  },
1180
- onVideoStateChange: (l, w) => {
1190
+ onVideoStateChange: (l, h) => {
1181
1191
  var v, k;
1182
1192
  (k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l), er(
1183
1193
  l,
1184
1194
  e,
1185
- w,
1195
+ h,
1186
1196
  r,
1187
1197
  o.streamType
1188
1198
  );
1189
1199
  },
1190
1200
  onAgentActivityStateChange: (l) => {
1191
- var w, v;
1192
- (v = (w = t.callbacks).onAgentActivityStateChange) == null || v.call(w, l), l === ne.Talking ? (fe.update(), d = (k) => {
1201
+ var h, v;
1202
+ (v = (h = t.callbacks).onAgentActivityStateChange) == null || v.call(h, l), l === ne.Talking ? (fe.update(), d = (k) => {
1193
1203
  xe(
1194
1204
  S.Start,
1195
1205
  e,
@@ -1211,9 +1221,9 @@ function Le(e, t, r, a) {
1211
1221
  const l = Te.get(!0);
1212
1222
  r.track("agent-chat", { event: "ready", latency: l });
1213
1223
  },
1214
- onToolEvent: (l, w) => {
1224
+ onToolEvent: (l, h) => {
1215
1225
  var v, k;
1216
- (k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w), nr(l, w, r);
1226
+ (k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, h), nr(l, h, r);
1217
1227
  }
1218
1228
  }
1219
1229
  },
@@ -1225,7 +1235,7 @@ function Le(e, t, r, a) {
1225
1235
  });
1226
1236
  }
1227
1237
  async function ar(e, t, r, a, c) {
1228
- var m, l, w, v;
1238
+ var m, l, h, v;
1229
1239
  const s = async () => {
1230
1240
  if (pe(e.presenter.type)) {
1231
1241
  const k = await Le(e, t, a), B = `${Xt}_${k.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
@@ -1262,10 +1272,10 @@ async function ar(e, t, r, a, c) {
1262
1272
  }
1263
1273
  }
1264
1274
  }, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
1265
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (w = t.callbacks).onError) == null || v.call(w, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
1275
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (h = t.callbacks).onError) == null || v.call(h, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
1266
1276
  }
1267
1277
  async function dr(e, t) {
1268
- var Y, V, ae, ie;
1278
+ var Y, K, ae, ie;
1269
1279
  let r = !0;
1270
1280
  const a = t.mixpanelKey || ot, c = t.wsURL || st, s = t.baseURL || de, o = t.mode || x.Functional, n = {
1271
1281
  messages: [],
@@ -1282,17 +1292,17 @@ async function dr(e, t) {
1282
1292
  });
1283
1293
  const m = wt(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
1284
1294
  t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
1285
- const w = pe(l.presenter.type);
1295
+ const h = pe(l.presenter.type);
1286
1296
  i.enrich(yt(l));
1287
1297
  const { onMessage: v, clearQueue: k } = xt(i, n, t, l, () => {
1288
- var u, g, p;
1289
- (u = n.socketManager) == null || u.disconnect(), (p = (g = t.callbacks).onConnectionStateChange) == null || p.call(g, L.Disconnected);
1298
+ var u, g, w;
1299
+ (u = n.socketManager) == null || u.disconnect(), (w = (g = t.callbacks).onConnectionStateChange) == null || w.call(g, L.Disconnected);
1290
1300
  });
1291
- n.messages = It(t.initialMessages), (ae = (V = t.callbacks).onNewMessage) == null || ae.call(V, [...n.messages], "answer");
1301
+ n.messages = It(t.initialMessages), (ae = (K = t.callbacks).onNewMessage) == null || ae.call(K, [...n.messages], "answer");
1292
1302
  const B = (u) => {
1293
1303
  }, M = ({ type: u }) => {
1294
- var p, y, C, R;
1295
- if (!((p = n.streamingManager) != null && p.interruptAvailable) || !((y = n.streamingManager) != null && y.isInterruptible)) return;
1304
+ var w, y, C, R;
1305
+ if (!((w = n.streamingManager) != null && w.interruptAvailable) || !((y = n.streamingManager) != null && y.isInterruptible)) return;
1296
1306
  const g = n.messages[n.messages.length - 1];
1297
1307
  i.track("agent-video-interrupt", {
1298
1308
  type: u || "click",
@@ -1302,44 +1312,44 @@ async function dr(e, t) {
1302
1312
  }, D = /* @__PURE__ */ new Map();
1303
1313
  function $(u) {
1304
1314
  return async (g) => {
1305
- const p = D.get(u);
1306
- if (!p)
1315
+ const w = D.get(u);
1316
+ if (!w)
1307
1317
  throw new Error(`No handler registered for client tool: ${u}`);
1308
1318
  try {
1309
1319
  const y = JSON.parse(g.payload);
1310
- return await p(y);
1320
+ return await w(y);
1311
1321
  } catch (y) {
1312
1322
  throw new Error(`Client tool "${u}" failed: ${y.message}`);
1313
1323
  }
1314
1324
  };
1315
1325
  }
1316
1326
  function _() {
1317
- var u, g, p, y;
1327
+ var u, g, w, y;
1318
1328
  for (const [C] of D)
1319
- (g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, C), (y = (p = n.streamingManager) == null ? void 0 : p.registerRpcMethod) == null || y.call(p, C, $(C));
1329
+ (g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, C), (y = (w = n.streamingManager) == null ? void 0 : w.registerRpcMethod) == null || y.call(w, C, $(C));
1320
1330
  }
1321
1331
  function q(u, g) {
1322
1332
  var y, C;
1323
- const p = !D.has(u);
1324
- D.set(u, g), p && ((C = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, u, $(u)));
1333
+ const w = !D.has(u);
1334
+ D.set(u, g), w && ((C = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, u, $(u)));
1325
1335
  }
1326
1336
  function J(u) {
1327
- var g, p;
1328
- D.delete(u), (p = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || p.call(g, u);
1337
+ var g, w;
1338
+ D.delete(u), (w = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || w.call(g, u);
1329
1339
  }
1330
- const N = Date.now();
1340
+ const V = Date.now();
1331
1341
  Ee(() => {
1332
- i.track("agent-sdk", { event: "loaded", ...vt(l) }, N);
1342
+ i.track("agent-sdk", { event: "loaded", ...vt(l) }, V);
1333
1343
  });
1334
1344
  async function X(u) {
1335
- var j, z, F, E, f, h, b;
1345
+ var j, z, F, E, f, p, b;
1336
1346
  (z = (j = t.callbacks).onConnectionStateChange) == null || z.call(j, L.Connecting), H.reset(), u && !r && (delete n.chat, (E = (F = t.callbacks).onNewMessage) == null || E.call(F, [...n.messages], "answer"));
1337
- const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) : Tt(
1347
+ const g = o === x.DirectPlayback || h ? Promise.resolve(void 0) : Tt(
1338
1348
  t.auth,
1339
1349
  c,
1340
1350
  { onMessage: v, onError: t.callbacks.onError },
1341
1351
  t.externalId
1342
- ), p = ue(
1352
+ ), w = ue(
1343
1353
  () => ar(
1344
1354
  l,
1345
1355
  {
@@ -1363,22 +1373,22 @@ async function dr(e, t) {
1363
1373
  delayMs: 1e3
1364
1374
  }
1365
1375
  ).catch((T) => {
1366
- var A, K;
1367
- throw I(x.Maintenance), (K = (A = t.callbacks).onConnectionStateChange) == null || K.call(A, L.Fail), T;
1368
- }), [y, { streamingManager: C, chat: R }] = await Promise.all([g, p]);
1369
- R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager = C, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
1376
+ var A, U;
1377
+ throw I(x.Maintenance), (U = (A = t.callbacks).onConnectionStateChange) == null || U.call(A, L.Fail), T;
1378
+ }), [y, { streamingManager: C, chat: R }] = await Promise.all([g, w]);
1379
+ R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (p = t.callbacks).onNewChat) == null || b.call(p, R.id)), n.streamingManager = C, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
1370
1380
  chatId: R == null ? void 0 : R.id,
1371
1381
  streamId: C == null ? void 0 : C.streamId,
1372
1382
  mode: n.chatMode
1373
1383
  }), I((R == null ? void 0 : R.chat_mode) ?? o);
1374
1384
  }
1375
1385
  async function O() {
1376
- var u, g, p, y;
1377
- (u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, L.Disconnected);
1386
+ var u, g, w, y;
1387
+ (u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (w = t.callbacks).onConnectionStateChange) == null || y.call(w, L.Disconnected);
1378
1388
  }
1379
1389
  async function I(u) {
1380
- var g, p;
1381
- u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (p = (g = t.callbacks).onModeChange) == null || p.call(g, u));
1390
+ var g, w;
1391
+ u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (w = (g = t.callbacks).onModeChange) == null || w.call(g, u));
1382
1392
  }
1383
1393
  return {
1384
1394
  agent: l,
@@ -1402,7 +1412,7 @@ async function dr(e, t) {
1402
1412
  },
1403
1413
  async reconnect() {
1404
1414
  const u = n.streamingManager;
1405
- if (w && (u != null && u.reconnect)) {
1415
+ if (h && (u != null && u.reconnect)) {
1406
1416
  try {
1407
1417
  await u.reconnect(), i.track("agent-chat", {
1408
1418
  event: "reconnect",
@@ -1461,35 +1471,35 @@ async function dr(e, t) {
1461
1471
  if (!n.chat)
1462
1472
  throw new G("Chat is not initialized");
1463
1473
  }
1464
- }, p = async () => {
1474
+ }, w = async () => {
1465
1475
  var E, f;
1466
1476
  if (!n.chat) {
1467
- const h = await Ve(
1477
+ const p = await Ve(
1468
1478
  l,
1469
1479
  m,
1470
1480
  i,
1471
1481
  n.chatMode,
1472
1482
  t.persistentChat
1473
1483
  );
1474
- if (!h.chat)
1484
+ if (!p.chat)
1475
1485
  throw new Oe(n.chatMode, !!t.persistentChat);
1476
- n.chat = h.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
1486
+ n.chat = p.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
1477
1487
  }
1478
1488
  return n.chat.id;
1479
1489
  }, y = async (E, f) => {
1480
- const h = n.chatMode === x.Playground;
1481
- return ue(w && !h ? async () => {
1482
- var A, K;
1483
- return await ((K = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : K.call(A, u)), Promise.resolve({});
1490
+ const p = n.chatMode === x.Playground;
1491
+ return ue(h && !p ? async () => {
1492
+ var A, U;
1493
+ return await ((U = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : U.call(A, u)), Promise.resolve({});
1484
1494
  } : async () => {
1485
- var A, K;
1495
+ var A, U;
1486
1496
  return m.chat(
1487
1497
  l.id,
1488
1498
  f,
1489
1499
  {
1490
1500
  chatMode: n.chatMode,
1491
1501
  streamId: (A = n.streamingManager) == null ? void 0 : A.streamId,
1492
- sessionId: (K = n.streamingManager) == null ? void 0 : K.sessionId,
1502
+ sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
1493
1503
  messages: E.map(({ matches: Ue, ...se }) => se)
1494
1504
  },
1495
1505
  {
@@ -1501,8 +1511,8 @@ async function dr(e, t) {
1501
1511
  limit: 2,
1502
1512
  shouldRetryFn: (A) => {
1503
1513
  var se, ve, ye, Ce;
1504
- const K = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
1505
- return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !K ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
1514
+ const U = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
1515
+ return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !U ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
1506
1516
  },
1507
1517
  onRetry: async () => {
1508
1518
  await O(), await X(!1);
@@ -1517,12 +1527,12 @@ async function dr(e, t) {
1517
1527
  parts: re(u),
1518
1528
  created_at: new Date(H.update()).toISOString()
1519
1529
  }), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "user");
1520
- const E = await p(), f = await y([...n.messages], E);
1521
- return n.messages.push({
1530
+ const E = await w(), f = await y([...n.messages], E);
1531
+ return f.result && n.messages.push({
1522
1532
  id: Q(),
1523
1533
  role: "assistant",
1524
- content: f.result || "",
1525
- parts: re(f.result || ""),
1534
+ content: f.result,
1535
+ parts: re(f.result),
1526
1536
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1527
1537
  context: f.context,
1528
1538
  matches: f.matches
@@ -1540,7 +1550,7 @@ async function dr(e, t) {
1540
1550
  }), E;
1541
1551
  }
1542
1552
  },
1543
- rate(u, g, p) {
1553
+ rate(u, g, w) {
1544
1554
  var R, j, z, F;
1545
1555
  const y = n.messages.find((E) => E.id === u);
1546
1556
  if (n.chat) {
@@ -1549,12 +1559,12 @@ async function dr(e, t) {
1549
1559
  } else throw new Error("Chat is not initialized");
1550
1560
  const C = ((R = y.matches) == null ? void 0 : R.map((E) => [E.document_id, E.id])) ?? [];
1551
1561
  return i.track("agent-rate", {
1552
- event: p ? "update" : "create",
1562
+ event: w ? "update" : "create",
1553
1563
  thumb: g === 1 ? "up" : "down",
1554
1564
  knowledge_id: ((j = l.knowledge) == null ? void 0 : j.id) ?? "",
1555
1565
  matches: C,
1556
1566
  score: g
1557
- }), p ? m.updateRating(l.id, n.chat.id, p, {
1567
+ }), w ? m.updateRating(l.id, n.chat.id, w, {
1558
1568
  knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
1559
1569
  message_id: u,
1560
1570
  matches: C,
@@ -1596,12 +1606,12 @@ async function dr(e, t) {
1596
1606
  }
1597
1607
  return u;
1598
1608
  }
1599
- const p = g();
1600
- if (i.track("agent-speak", p), H.update(), n.messages && p.type === "text" && (n.messages.push({
1609
+ const w = g();
1610
+ if (i.track("agent-speak", w), H.update(), n.messages && w.type === "text" && (n.messages.push({
1601
1611
  id: Q(),
1602
1612
  role: "assistant",
1603
- content: p.input,
1604
- parts: re(p.input),
1613
+ content: w.input,
1614
+ parts: re(w.input),
1605
1615
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1606
1616
  }), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer")), lt(n.chatMode))
1607
1617
  return {
@@ -1612,7 +1622,7 @@ async function dr(e, t) {
1612
1622
  if (!n.streamingManager)
1613
1623
  throw new Error("Please connect to the agent first");
1614
1624
  return n.streamingManager.speak({
1615
- script: p,
1625
+ script: w,
1616
1626
  metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: l.id }
1617
1627
  });
1618
1628
  },
@@ -1623,7 +1633,7 @@ async function dr(e, t) {
1623
1633
  }
1624
1634
  export {
1625
1635
  ne as A,
1626
- U as C,
1636
+ N as C,
1627
1637
  tt as D,
1628
1638
  et as K,
1629
1639
  Ye as P,