@d-id/client-sdk 1.1.61 → 1.1.62

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 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);
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);
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 kt extends Ie {
13
+ class Mt 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 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 || {});
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 || {}), k = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.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))(k || {}), 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
- [M.ChatAnswer]: X.Answer,
403
- [M.ChatPartial]: X.Partial
402
+ [k.ChatAnswer]: X.Answer,
403
+ [k.ChatPartial]: X.Partial
404
404
  };
405
405
  function cn(e, n, i) {
406
406
  const r = (n.timestamp - e.timestamp) / 1e3;
@@ -577,7 +577,7 @@ function ln(e, n) {
577
577
  }
578
578
  };
579
579
  }
580
- const ke = 100, fn = Math.max(Math.ceil(400 / ke), 1), mn = 0.25, gn = 0.28;
580
+ const Me = 100, fn = Math.max(Math.ceil(400 / Me), 1), mn = 0.25, gn = 0.28;
581
581
  function hn() {
582
582
  let e = 0, n, i, r = 0;
583
583
  return (s) => {
@@ -601,22 +601,22 @@ function yt(e, n, i, r, s) {
601
601
  const B = await e();
602
602
  if (!B)
603
603
  return;
604
- const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: k } = P(B), Y = un(B);
604
+ const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: M } = P(B), Y = un(B);
605
605
  if (F)
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);
606
+ t = 0, l = M - 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, ke, c);
609
- r == null || r(E.Stop, Q), n() || i(), v = k, d = !1;
608
+ const Q = rt(o, Me, c);
609
+ r == null || r(E.Stop, Q), n() || i(), v = M, d = !1;
610
610
  }
611
611
  }
612
612
  return {
613
613
  start: () => {
614
- a || (a = setInterval(N, ke));
614
+ a || (a = setInterval(N, Me));
615
615
  },
616
616
  stop: () => {
617
617
  a && (clearInterval(a), a = null);
618
618
  },
619
- getReport: () => rt(o, ke, c)
619
+ getReport: () => rt(o, Me, c)
620
620
  };
621
621
  }
622
622
  const it = 2e4;
@@ -651,7 +651,7 @@ async function yn(e, n, i) {
651
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 I = null, k = null, Y = null, Q = !1;
654
+ let I = null, M = null, Y = null, Q = !1;
655
655
  l = new s({
656
656
  adaptiveStream: !1,
657
657
  // Must be false to use mediaStreamTrack directly
@@ -673,8 +673,7 @@ async function yn(e, n, i) {
673
673
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
674
674
  l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, J).on(a.TrackUnsubscribed, w).on(a.DataReceived, z).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
675
675
  function ue(u, m) {
676
- var p;
677
- m != null && m.isLocal && (oe.update(), te === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), te = W.Idle));
676
+ m != null && m.isLocal && (oe.update(), te === W.Talking && (te = W.Idle));
678
677
  }
679
678
  try {
680
679
  await l.connect(re, H), r("LiveKit room joined successfully"), U = setTimeout(() => {
@@ -738,7 +737,7 @@ async function yn(e, n, i) {
738
737
  r(`No mediaStreamTrack available for ${u.kind}`);
739
738
  return;
740
739
  }
741
- N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = ln(
740
+ N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (M = ln(
742
741
  () => u.getRTCStatsReport(),
743
742
  ({ sttLatency: V, serviceLatency: ie }) => {
744
743
  var Oe, We, He;
@@ -761,7 +760,7 @@ async function yn(e, n, i) {
761
760
  ), I.start());
762
761
  }
763
762
  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(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
763
+ r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (M == null || M.destroy(), M = null), u.kind === "video" && (b(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
765
764
  }
766
765
  function y(u, m) {
767
766
  var S;
@@ -770,20 +769,20 @@ async function yn(e, n, i) {
770
769
  }
771
770
  function T(u, m) {
772
771
  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);
772
+ if (u === k.ToolCallStarted) {
773
+ te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, k.ToolCallStarted, m);
775
774
  return;
776
775
  }
777
- if (u === M.ToolCallDone) {
778
- (_ = t.onToolEvent) == null || _.call(t, M.ToolCallDone, m);
776
+ if (u === k.ToolCallDone) {
777
+ (_ = t.onToolEvent) == null || _.call(t, k.ToolCallDone, m);
779
778
  return;
780
779
  }
781
- u === M.ToolCallError && ((L = t.onToolEvent) == null || L.call(t, M.ToolCallError, m));
780
+ u === k.ToolCallError && ((L = t.onToolEvent) == null || L.call(t, k.ToolCallError, m));
782
781
  }
783
782
  function j(u, m) {
784
783
  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) {
786
- te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), k == null || k.arm({
784
+ if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === k.StreamVideoCreated) {
785
+ te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), M == null || M.arm({
787
786
  sttLatency: (L = m == null ? void 0 : m.stt) == null ? void 0 : L.latency,
788
787
  serviceLatency: m == null ? void 0 : m.serviceLatency
789
788
  });
@@ -807,16 +806,16 @@ async function yn(e, n, i) {
807
806
  });
808
807
  }
809
808
  const Z = {
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
809
+ [k.ChatAnswer]: y,
810
+ [k.ChatPartial]: y,
811
+ [k.ToolCallStarted]: T,
812
+ [k.ToolCallDone]: T,
813
+ [k.ToolCallError]: T,
814
+ [k.StreamVideoCreated]: G,
815
+ [k.StreamVideoDone]: G,
816
+ [k.StreamVideoError]: G,
817
+ [k.StreamVideoRejected]: G,
818
+ [k.ChatAudioTranscribed]: he
820
819
  };
821
820
  function z(u, m, p, S) {
822
821
  const _ = new TextDecoder().decode(u);
@@ -840,7 +839,7 @@ async function yn(e, n, i) {
840
839
  function le(u, m, p) {
841
840
  r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
842
841
  }
843
- function Me(u, m, p) {
842
+ function ke(u, m, p) {
844
843
  for (const [S, _] of p)
845
844
  if (_.source === m && _.track) {
846
845
  const L = _.track.mediaStreamTrack;
@@ -860,7 +859,7 @@ async function yn(e, n, i) {
860
859
  const q = p(m);
861
860
  if (q.length === 0)
862
861
  throw new Error(`No ${S} track found in the provided MediaStream`);
863
- const V = q[0], ie = Me(V, S, _());
862
+ const V = q[0], ie = ke(V, S, _());
864
863
  if (ie) {
865
864
  r(`${S} track is already published, skipping`, {
866
865
  trackId: V.id,
@@ -952,7 +951,7 @@ async function yn(e, n, i) {
952
951
  }
953
952
  async function Le(u) {
954
953
  var m, p;
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;
954
+ U && (clearTimeout(U), U = null), M == null || M.destroy(), M = 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;
956
955
  }
957
956
  return {
958
957
  speak(u) {
@@ -1027,7 +1026,7 @@ function Cn(e, n, i) {
1027
1026
  }
1028
1027
  async function Sn(e, n) {
1029
1028
  const i = {
1030
- type: M.StreamInterrupt,
1029
+ type: k.StreamInterrupt,
1031
1030
  videoId: n,
1032
1031
  timestamp: Date.now()
1033
1032
  };
@@ -1062,7 +1061,7 @@ async function En(e) {
1062
1061
  }
1063
1062
  return i;
1064
1063
  }
1065
- async function Mn(e, n, i, r) {
1064
+ async function kn(e, n, i, r) {
1066
1065
  const s = i != null && i.onMessage ? [i.onMessage] : [], a = await En({
1067
1066
  auth: e,
1068
1067
  host: n,
@@ -1084,7 +1083,7 @@ async function Mn(e, n, i, r) {
1084
1083
  subscribeToEvents: (o) => s.push(o)
1085
1084
  };
1086
1085
  }
1087
- function kn(e) {
1086
+ function Mn(e) {
1088
1087
  if (e.answer !== void 0)
1089
1088
  return e.answer;
1090
1089
  let n = 0, i = "";
@@ -1130,7 +1129,7 @@ function Dn(e, n, i, r, s, a) {
1130
1129
  return;
1131
1130
  const { content: d, sequence: h } = n;
1132
1131
  e === X.Partial ? i[h] = d : i.answer = d;
1133
- const g = kn(i);
1132
+ const g = Mn(i);
1134
1133
  (t.content !== g || e === X.Answer) && (t.content = g, t.parts = Te(g), s == null || s([...r.messages], e));
1135
1134
  }
1136
1135
  function An(e, n, i, r, s) {
@@ -1146,14 +1145,14 @@ function An(e, n, i, r, s) {
1146
1145
  onMessage: (d, h) => {
1147
1146
  var g, l;
1148
1147
  if ("content" in h) {
1149
- const v = d === M.ChatAnswer ? X.Answer : d === M.ChatAudioTranscribed ? X.Transcribe : d;
1148
+ const v = d === k.ChatAnswer ? X.Answer : d === k.ChatAudioTranscribed ? X.Transcribe : d;
1150
1149
  Dn(v, h, a, n, t, o), v === X.Answer && e.track("agent-message-received", {
1151
1150
  content: h.content,
1152
1151
  messages: n.messages.length,
1153
1152
  mode: n.chatMode
1154
1153
  });
1155
1154
  } else {
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 });
1155
+ const v = k, P = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], N = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
1157
1156
  if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
1158
1157
  const F = n.messages[n.messages.length - 1];
1159
1158
  if ((F == null ? void 0 : F.role) === "assistant") {
@@ -1284,14 +1283,14 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1284
1283
  e,
1285
1284
  r.onError
1286
1285
  ), {
1287
- id: k,
1286
+ id: M,
1288
1287
  offer: Y,
1289
1288
  ice_servers: Q,
1290
1289
  session_id: U,
1291
1290
  fluent: te,
1292
1291
  interrupt_enabled: ne
1293
1292
  } = await F(n, c);
1294
- (J = r.onStreamCreated) == null || J.call(r, { stream_id: k, session_id: U, agent_id: e });
1293
+ (J = r.onStreamCreated) == null || J.call(r, { stream_id: M, session_id: U, agent_id: e });
1295
1294
  const $ = new bn({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
1296
1295
  if (!U)
1297
1296
  throw new Error("Could not create session_id");
@@ -1325,7 +1324,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1325
1324
  t("peerConnection.onicecandidate", w);
1326
1325
  try {
1327
1326
  w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? I(
1328
- k,
1327
+ M,
1329
1328
  {
1330
1329
  candidate: w.candidate.candidate,
1331
1330
  sdpMid: w.candidate.sdpMid,
@@ -1333,9 +1332,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1333
1332
  },
1334
1333
  U,
1335
1334
  c
1336
- ) : I(k, { candidate: null }, U, c);
1335
+ ) : I(M, { candidate: null }, U, c);
1337
1336
  } catch (T) {
1338
- (y = r.onError) == null || y.call(r, T, { streamId: k });
1337
+ (y = r.onError) == null || y.call(r, T, { streamId: M });
1339
1338
  }
1340
1339
  }, K.onopen = () => {
1341
1340
  g = !0, (!re || h) && ue();
@@ -1345,11 +1344,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1345
1344
  (y = r.onVideoIdChange) == null || y.call(r, w);
1346
1345
  };
1347
1346
  function R(w, y) {
1348
- if (w === M.StreamStarted && typeof y == "object" && "metadata" in y) {
1347
+ if (w === k.StreamStarted && typeof y == "object" && "metadata" in y) {
1349
1348
  const T = y.metadata;
1350
1349
  C(T.videoId);
1351
1350
  }
1352
- w === M.StreamDone && C(null), l = w === M.StreamStarted ? E.Start : E.Stop, ot({
1351
+ w === k.StreamDone && C(null), l = w === k.StreamStarted ? E.Start : E.Stop, ot({
1353
1352
  statsSignal: H === se.Legacy ? v : void 0,
1354
1353
  dataChannelSignal: l,
1355
1354
  onVideoStateChange: r.onVideoStateChange,
@@ -1364,9 +1363,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1364
1363
  T && o.enrich({ streamMetadata: T }), (j = r.onStreamReady) == null || j.call(r);
1365
1364
  }
1366
1365
  const D = {
1367
- [M.StreamStarted]: R,
1368
- [M.StreamDone]: R,
1369
- [M.StreamReady]: A
1366
+ [k.StreamStarted]: R,
1367
+ [k.StreamDone]: R,
1368
+ [k.StreamReady]: A
1370
1369
  };
1371
1370
  K.onmessage = (w) => {
1372
1371
  var j;
@@ -1382,20 +1381,20 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1382
1381
  t("peerConnection.ontrack", w), t("CALLBACK: onSrcObjectReady"), (y = r.onSrcObjectReady) == null || y.call(r, w.streams[0]);
1383
1382
  }, await $.setRemoteDescription(Y), t("set remote description OK");
1384
1383
  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"), {
1384
+ return t("create answer OK"), await $.setLocalDescription(b), t("set local description OK"), await P(M, b, U, c), t("start connection OK"), {
1386
1385
  /**
1387
1386
  * Method to send request to server to get clip or talk depend on you payload
1388
1387
  * @param payload
1389
1388
  */
1390
1389
  speak(w) {
1391
- return N(k, U, w);
1390
+ return N(M, U, w);
1392
1391
  },
1393
1392
  /**
1394
1393
  * Method to close RTC connection
1395
1394
  */
1396
1395
  async disconnect() {
1397
1396
  var w;
1398
- if (k) {
1397
+ if (M) {
1399
1398
  const y = at($.iceConnectionState);
1400
1399
  if ($) {
1401
1400
  if (y === x.New) {
@@ -1405,7 +1404,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1405
1404
  $.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
1406
1405
  }
1407
1406
  try {
1408
- y === x.Connected && await B(k, U).catch((T) => {
1407
+ y === x.Connected && await B(M, U).catch((T) => {
1409
1408
  });
1410
1409
  } catch (T) {
1411
1410
  t("Error on close stream connection", T);
@@ -1420,14 +1419,14 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1420
1419
  var y, T;
1421
1420
  if (!h || K.readyState !== "open") {
1422
1421
  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"), {
1423
- streamId: k
1422
+ streamId: M
1424
1423
  });
1425
1424
  return;
1426
1425
  }
1427
1426
  try {
1428
1427
  K.send(w);
1429
1428
  } catch (j) {
1430
- t("Error sending data channel message", j), (T = r.onError) == null || T.call(r, j, { streamId: k });
1429
+ t("Error sending data channel message", j), (T = r.onError) == null || T.call(r, j, { streamId: M });
1431
1430
  }
1432
1431
  },
1433
1432
  /**
@@ -1437,7 +1436,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1437
1436
  /**
1438
1437
  * Id of current RTC stream
1439
1438
  */
1440
- streamId: k,
1439
+ streamId: M,
1441
1440
  streamType: H,
1442
1441
  interruptAvailable: ne ?? !1,
1443
1442
  isInterruptible: !0
@@ -1506,7 +1505,7 @@ function Un(e, n, i, r, s) {
1506
1505
  }
1507
1506
  function st(e, n, i, r, s) {
1508
1507
  e === E.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
1509
- M.StreamVideoCreated
1508
+ k.StreamVideoCreated
1510
1509
  ]) : e === E.Stop && i.linkTrack(
1511
1510
  "agent-video",
1512
1511
  {
@@ -1516,7 +1515,7 @@ function st(e, n, i, r, s) {
1516
1515
  "stream-type": r
1517
1516
  },
1518
1517
  "done",
1519
- [M.StreamVideoDone]
1518
+ [k.StreamVideoDone]
1520
1519
  );
1521
1520
  }
1522
1521
  function Jn(e, n, i, r, s) {
@@ -1524,7 +1523,7 @@ function Jn(e, n, i, r, s) {
1524
1523
  "agent-video",
1525
1524
  { event: "start", latency: oe.get(!0), "stream-type": s },
1526
1525
  "start",
1527
- [M.StreamVideoCreated]
1526
+ [k.StreamVideoCreated]
1528
1527
  ) : e === E.Stop && r.linkTrack(
1529
1528
  "agent-video",
1530
1529
  {
@@ -1535,7 +1534,7 @@ function Jn(e, n, i, r, s) {
1535
1534
  ...i
1536
1535
  },
1537
1536
  "done",
1538
- [M.StreamVideoDone]
1537
+ [k.StreamVideoDone]
1539
1538
  );
1540
1539
  }
1541
1540
  function ct(e, n, i, r) {
@@ -1633,8 +1632,8 @@ async function On(e, n, i, r, s) {
1633
1632
  n.mode,
1634
1633
  n.persistentChat,
1635
1634
  s
1636
- ), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, I]);
1637
- return { chatResult: k, streamingManager: Y };
1635
+ ), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [M, Y] = await Promise.all([F, I]);
1636
+ return { chatResult: M, streamingManager: Y };
1638
1637
  } catch (F) {
1639
1638
  throw P.abort(), B && await B.disconnect().catch(() => {
1640
1639
  }), F;
@@ -1680,7 +1679,7 @@ async function qn(e, n) {
1680
1679
  message_duration_to_interrupt: oe.get(!0)
1681
1680
  }), 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));
1682
1681
  }, I = /* @__PURE__ */ new Map();
1683
- function k(f) {
1682
+ function M(f) {
1684
1683
  return async (C) => {
1685
1684
  const R = I.get(f);
1686
1685
  if (!R)
@@ -1696,12 +1695,12 @@ async function qn(e, n) {
1696
1695
  function Y() {
1697
1696
  var f, C, R, A;
1698
1697
  for (const [D] of I)
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));
1698
+ (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, M(D));
1700
1699
  }
1701
1700
  function Q(f, C) {
1702
1701
  var A, D;
1703
1702
  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)));
1703
+ I.set(f, C), R && ((D = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || D.call(A, f, M(f)));
1705
1704
  }
1706
1705
  function U(f) {
1707
1706
  var C, R;
@@ -1714,7 +1713,7 @@ async function qn(e, n) {
1714
1713
  async function ne(f) {
1715
1714
  var J, w, y, T, j, G, he;
1716
1715
  (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(
1716
+ const C = c === O.DirectPlayback || v ? Promise.resolve(void 0) : kn(
1718
1717
  n.auth,
1719
1718
  a,
1720
1719
  { onMessage: P, onError: n.callbacks.onError },
@@ -1728,8 +1727,7 @@ async function qn(e, n) {
1728
1727
  callbacks: {
1729
1728
  ...n.callbacks,
1730
1729
  onVideoIdChange: B,
1731
- onMessage: P,
1732
- onInterruptDetected: F
1730
+ onMessage: P
1733
1731
  }
1734
1732
  },
1735
1733
  g,
@@ -1855,7 +1853,7 @@ async function qn(e, n) {
1855
1853
  n.persistentChat
1856
1854
  );
1857
1855
  if (!G.chat)
1858
- throw new kt(t.chatMode, !!n.persistentChat);
1856
+ throw new Mt(t.chatMode, !!n.persistentChat);
1859
1857
  t.chat = G.chat, (j = (T = n.callbacks).onNewChat) == null || j.call(T, t.chat.id);
1860
1858
  }
1861
1859
  return t.chat.id;
@@ -1883,9 +1881,9 @@ async function qn(e, n) {
1883
1881
  }, {
1884
1882
  limit: 2,
1885
1883
  shouldRetryFn: (z) => {
1886
- var le, Me, pe, we;
1884
+ var le, ke, pe, we;
1887
1885
  const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
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;
1886
+ 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;
1889
1887
  },
1890
1888
  onRetry: async () => {
1891
1889
  await $(), await ne(!1);
@@ -2007,7 +2005,7 @@ async function qn(e, n) {
2007
2005
  export {
2008
2006
  W as AgentActivityState,
2009
2007
  bt as AgentStatus,
2010
- kt as ChatCreationFailed,
2008
+ Mt as ChatCreationFailed,
2011
2009
  O as ChatMode,
2012
2010
  It as ChatModeDowngraded,
2013
2011
  X as ChatProgress,
@@ -2018,7 +2016,7 @@ export {
2018
2016
  _t as PlanGroup,
2019
2017
  jt as Providers,
2020
2018
  Lt as RateState,
2021
- M as StreamEvents,
2019
+ k as StreamEvents,
2022
2020
  se as StreamType,
2023
2021
  E as StreamingState,
2024
2022
  Pt as Subject,