@d-id/client-sdk 1.1.17-staging.75 → 1.1.17-staging.77

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.
@@ -1,12 +1,12 @@
1
1
  var De = Object.defineProperty;
2
2
  var Se = (e, t, a) => t in e ? De(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
- var Z = (e, t, a) => Se(e, typeof t != "symbol" ? t + "" : t, a);
3
+ var Q = (e, t, a) => Se(e, typeof t != "symbol" ? t + "" : t, a);
4
4
  class ee extends Error {
5
5
  constructor({ kind: a, description: r, error: o }) {
6
6
  super(JSON.stringify({ kind: a, description: r }));
7
- Z(this, "kind");
8
- Z(this, "description");
9
- Z(this, "error");
7
+ Q(this, "kind");
8
+ Q(this, "description");
9
+ Q(this, "error");
10
10
  this.kind = a, this.description = r, this.error = o;
11
11
  }
12
12
  }
@@ -23,10 +23,10 @@ class Ee extends ee {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
24
24
  }
25
25
  }
26
- class V extends ee {
26
+ class H extends ee {
27
27
  constructor(a, r) {
28
28
  super({ kind: "ValidationError", description: a });
29
- Z(this, "key");
29
+ Q(this, "key");
30
30
  this.key = r;
31
31
  }
32
32
  }
@@ -35,19 +35,21 @@ class Me extends ee {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var _e = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_e || {}), Te = /* @__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))(Te || {}), Ae = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ae || {}), je = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(je || {}), _ = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(_ || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), be = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(be || {}), Pe = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Pe || {}), Le = /* @__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))(Le || {}), he = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(he || {});
39
- const Pt = (e) => {
38
+ var _e = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_e || {}), Te = /* @__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))(Te || {}), Ae = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ae || {}), je = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(je || {}), _ = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(_ || {}), V = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(V || {}), Pe = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pe || {}), be = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(be || {}), Le = /* @__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))(Le || {}), he = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(he || {});
39
+ const bt = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
42
42
  return "clip";
43
43
  case "talk":
44
44
  return "talk";
45
+ case "expressive":
46
+ return "expressive";
45
47
  default:
46
48
  throw new Error(`Unknown video type: ${e}`);
47
49
  }
48
50
  };
49
- var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), G = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(G || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), P = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", 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))(P || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), de = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(de || {}), Be = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Be || {}), $e = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))($e || {});
50
- const xe = 45 * 1e3, ze = "X-Playground-Chat", te = "https://api.d-id.com", Fe = "wss://notifications.d-id.com", Ne = "79f81a83a67430be2bc0fd61042b8faa", we = (e) => new Promise((t) => setTimeout(t, e)), O = (e = 16) => {
51
+ var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), Z = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Z || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}), P = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", 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))(P || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), de = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(de || {}), xe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(xe || {}), Be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Be || {});
52
+ const $e = 45 * 1e3, ze = "X-Playground-Chat", te = "https://api.d-id.com", Fe = "wss://notifications.d-id.com", Ne = "79f81a83a67430be2bc0fd61042b8faa", we = (e) => new Promise((t) => setTimeout(t, e)), q = (e = 16) => {
51
53
  const t = new Uint8Array(e);
52
54
  return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
53
55
  }, pe = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, le = (e) => e === he.Expressive, Je = (e) => [_.TextOnly, _.Playground, _.Maintenance].includes(e), ve = (e) => e && [_.DirectPlayback, _.Off].includes(e);
@@ -89,12 +91,12 @@ function ae(e) {
89
91
  return window.localStorage.setItem("did_external_key_id", e), e;
90
92
  let t = window.localStorage.getItem("did_external_key_id");
91
93
  if (!t) {
92
- let a = O();
94
+ let a = q();
93
95
  window.localStorage.setItem("did_external_key_id", a), t = a;
94
96
  }
95
97
  return t;
96
98
  }
97
- let Ue = O();
99
+ let Ue = q();
98
100
  function ye(e, t) {
99
101
  if (e.type === "bearer")
100
102
  return `Bearer ${e.token}`;
@@ -248,7 +250,7 @@ function Qe(e) {
248
250
  ...e.mixpanelAdditionalProperties || {}
249
251
  },
250
252
  isEnabled: e.isEnabled ?? !0,
251
- getRandom: O,
253
+ getRandom: q,
252
254
  enrich(a) {
253
255
  this.additionalProperties = { ...this.additionalProperties, ...a };
254
256
  },
@@ -409,12 +411,12 @@ function at(e) {
409
411
  }
410
412
  function it(e, t, a, r, o) {
411
413
  const i = r.messages[r.messages.length - 1];
412
- if (!(e === q.Partial || e === q.Answer) || (i == null ? void 0 : i.role) !== "assistant")
414
+ if (!(e === V.Partial || e === V.Answer) || (i == null ? void 0 : i.role) !== "assistant")
413
415
  return;
414
416
  const { content: c, sequence: n } = t;
415
- e === q.Partial ? a[n] = c : a.answer = c;
417
+ e === V.Partial ? a[n] = c : a.answer = c;
416
418
  const s = at(a);
417
- (i.content !== s || e === q.Answer) && (i.content = s, o == null || o([...r.messages], e));
419
+ (i.content !== s || e === V.Answer) && (i.content = s, o == null || o([...r.messages], e));
418
420
  }
419
421
  function st(e, t, a, r, o) {
420
422
  let i = {};
@@ -423,17 +425,17 @@ function st(e, t, a, r, o) {
423
425
  onMessage: (c, n) => {
424
426
  var s, d;
425
427
  if ("content" in n)
426
- it(c, n, i, t, a.callbacks.onNewMessage), c === q.Answer && e.track("agent-message-received", {
428
+ it(c, n, i, t, a.callbacks.onNewMessage), c === V.Answer && e.track("agent-message-received", {
427
429
  messages: t.messages.length,
428
430
  mode: t.chatMode
429
431
  });
430
432
  else {
431
- const l = P, h = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], y = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], A = Xe(n, r, { mode: t.chatMode });
433
+ const l = P, h = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], y = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], b = Xe(n, r, { mode: t.chatMode });
432
434
  if (c = c, c === l.StreamVideoCreated)
433
- e.linkTrack("agent-video", A, l.StreamVideoCreated, ["start"]);
435
+ e.linkTrack("agent-video", b, l.StreamVideoCreated, ["start"]);
434
436
  else if (h.includes(c)) {
435
- const B = c.split("/")[1];
436
- y.includes(c) ? e.track("agent-video", { ...A, event: B }) : e.linkTrack("agent-video", { ...A, event: B }, c, ["done"]);
437
+ const L = c.split("/")[1];
438
+ y.includes(c) ? e.track("agent-video", { ...b, event: L }) : e.linkTrack("agent-video", { ...b, event: L }, c, ["done"]);
437
439
  }
438
440
  y.includes(c) && ((d = (s = a.callbacks).onError) == null || d.call(s, new Error(`Stream failed with event ${c}`), { data: n })), n.event === l.StreamDone && o();
439
441
  }
@@ -503,8 +505,12 @@ function lt(e) {
503
505
  }
504
506
  function ut(e) {
505
507
  let t = "", a = 0;
506
- for (const r of e.values())
507
- if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (a = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
508
+ for (const r of e.values()) {
509
+ if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
510
+ const o = r.currentRoundTripTime, c = r.nominated === !0;
511
+ o > 0 && (c || a === 0) && (a = o);
512
+ }
513
+ if (r && r.type === "inbound-rtp" && r.kind === "video")
508
514
  return {
509
515
  codec: t,
510
516
  rtt: a,
@@ -524,6 +530,7 @@ function ut(e) {
524
530
  freezeCount: r.freezeCount,
525
531
  freezeDuration: r.totalFreezesDuration
526
532
  };
533
+ }
527
534
  return {};
528
535
  }
529
536
  function ft(e, t, a) {
@@ -612,16 +619,16 @@ function wt() {
612
619
  return { isReceiving: !1, avgJitterDelayInInterval: r };
613
620
  };
614
621
  }
615
- function pt(e, t, a, r, o, i = !1) {
616
- let c = [], n, s = 0, d = !1, l = G.Unknown, h = G.Unknown, y = 0, A = 0;
617
- const B = wt();
622
+ function pt(e, t, a, r, o) {
623
+ let i = [], c, n = 0, s = !1, d = Z.Unknown, l = Z.Unknown, h = 0, y = 0;
624
+ const b = wt();
618
625
  return setInterval(async () => {
619
- const b = await e.getStats(), { isReceiving: L, avgJitterDelayInInterval: $, freezeCount: C } = B(b), K = ut(b);
620
- if (L)
621
- s = 0, y = C - A, h = $ < gt ? G.Strong : $ > ht && y > 1 ? G.Weak : l, h !== l && (o == null || o(h), l = h, A += y, y = 0), d || (r == null || r(w.Start), n = c[c.length - 1], c = [], d = !0), c.push(K);
622
- else if (d && (s++, s >= mt)) {
623
- const H = ft(c, oe, n);
624
- r == null || r(w.Stop, H), t() || a(), A = C, d = !1;
626
+ const L = await e.getStats(), { isReceiving: x, avgJitterDelayInInterval: j, freezeCount: B } = b(L), D = ut(L);
627
+ if (x)
628
+ n = 0, h = B - y, l = j < gt ? Z.Strong : j > ht && h > 1 ? Z.Weak : d, l !== d && (o == null || o(l), d = l, y += h, h = 0), s || (r == null || r(w.Start), c = i[i.length - 1], i = [], s = !0), i.push(D);
629
+ else if (s && (n++, n >= mt)) {
630
+ const K = ft(i, oe, c);
631
+ r == null || r(w.Stop, K), t() || a(), y = B, s = !1;
625
632
  }
626
633
  }, oe);
627
634
  }
@@ -670,7 +677,7 @@ function Rt({
670
677
  onAgentActivityStateChange: r,
671
678
  report: o
672
679
  }) {
673
- e === w.Start ? a == null || a(w.Start) : e === w.Stop && (a == null || a(w.Stop, o)), t === w.Start ? r == null || r(X.Talking) : t === w.Stop && (r == null || r(X.Idle));
680
+ e === w.Start ? a == null || a(w.Start) : e === w.Stop && (a == null || a(w.Stop, o)), t === w.Start ? r == null || r(O.Talking) : t === w.Stop && (r == null || r(O.Idle));
674
681
  }
675
682
  function me({
676
683
  statsSignal: e,
@@ -689,38 +696,38 @@ function me({
689
696
  });
690
697
  }
691
698
  async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te, analytics: c }) {
692
- var Y;
699
+ var X;
693
700
  const n = ct(a, "WebRTCStreamingManager"), s = yt(n);
694
701
  let d = !1, l = !1, h = w.Stop, y = w.Stop;
695
- const { startConnection: A, sendStreamRequest: B, close: b, createStream: L, addIceCandidate: $ } = ot(
702
+ const { startConnection: b, sendStreamRequest: L, close: x, createStream: j, addIceCandidate: B } = ot(
696
703
  o,
697
704
  i,
698
705
  e,
699
706
  r.onError
700
707
  ), {
701
- id: C,
708
+ id: D,
702
709
  offer: K,
703
- ice_servers: H,
710
+ ice_servers: G,
704
711
  session_id: u,
705
712
  fluent: k,
706
713
  interrupt_enabled: v,
707
714
  triggers_enabled: T
708
- } = await L(t);
709
- (Y = r.onStreamCreated) == null || Y.call(r, { stream_id: C, session_id: u, agent_id: e });
710
- const g = new vt({ iceServers: H }), p = g.createDataChannel("JanusDataChannel");
715
+ } = await j(t);
716
+ (X = r.onStreamCreated) == null || X.call(r, { stream_id: D, session_id: u, agent_id: e });
717
+ const g = new vt({ iceServers: G }), p = g.createDataChannel("JanusDataChannel");
711
718
  if (!u)
712
719
  throw new Error("Could not create session_id");
713
720
  const S = k ? W.Fluent : W.Legacy;
714
721
  c.enrich({
715
722
  "stream-type": S
716
723
  });
717
- const x = t.stream_warmup && !k, z = () => d, D = () => {
724
+ const $ = t.stream_warmup && !k, z = () => d, C = () => {
718
725
  var f;
719
726
  d = !0, l && ((f = r.onConnectionStateChange) == null || f.call(r, I.Connected));
720
727
  }, E = pt(
721
728
  g,
722
729
  z,
723
- D,
730
+ C,
724
731
  (f, m) => me({
725
732
  statsSignal: y = f,
726
733
  dataChannelSignal: S === W.Legacy ? h : void 0,
@@ -732,27 +739,26 @@ async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
732
739
  (f) => {
733
740
  var m;
734
741
  return (m = r.onConnectivityStateChange) == null ? void 0 : m.call(r, f);
735
- },
736
- x
742
+ }
737
743
  );
738
744
  g.onicecandidate = (f) => {
739
745
  var m;
740
746
  n("peerConnection.onicecandidate", f);
741
747
  try {
742
- f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? $(
743
- C,
748
+ f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? B(
749
+ D,
744
750
  {
745
751
  candidate: f.candidate.candidate,
746
752
  sdpMid: f.candidate.sdpMid,
747
753
  sdpMLineIndex: f.candidate.sdpMLineIndex
748
754
  },
749
755
  u
750
- ) : $(C, { candidate: null }, u);
751
- } catch (j) {
752
- (m = r.onError) == null || m.call(r, j, { streamId: C });
756
+ ) : B(D, { candidate: null }, u);
757
+ } catch (A) {
758
+ (m = r.onError) == null || m.call(r, A, { streamId: D });
753
759
  }
754
760
  }, p.onopen = () => {
755
- l = !0, (!x || d) && D();
761
+ l = !0, (!$ || d) && C();
756
762
  };
757
763
  const J = (f) => {
758
764
  var m;
@@ -760,8 +766,8 @@ async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
760
766
  };
761
767
  function R(f, m) {
762
768
  if (f === P.StreamStarted && typeof m == "object" && "metadata" in m) {
763
- const j = m.metadata;
764
- J(j.videoId);
769
+ const A = m.metadata;
770
+ J(A.videoId);
765
771
  }
766
772
  f === P.StreamDone && J(null), h = f === P.StreamStarted ? w.Start : w.Stop, me({
767
773
  statsSignal: S === W.Legacy ? y : void 0,
@@ -772,8 +778,8 @@ async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
772
778
  });
773
779
  }
774
780
  function M(f, m) {
775
- const j = typeof m == "string" ? m : m == null ? void 0 : m.metadata;
776
- j && c.enrich({ streamMetadata: j }), c.track("agent-chat", { event: "ready" });
781
+ const A = typeof m == "string" ? m : m == null ? void 0 : m.metadata;
782
+ A && c.enrich({ streamMetadata: A }), c.track("agent-chat", { event: "ready" });
777
783
  }
778
784
  const U = {
779
785
  [P.StreamStarted]: R,
@@ -781,9 +787,9 @@ async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
781
787
  [P.StreamReady]: M
782
788
  };
783
789
  p.onmessage = (f) => {
784
- var Q;
785
- const { subject: m, data: j } = s(f.data);
786
- (Q = U[m]) == null || Q.call(U, m, j);
790
+ var Y;
791
+ const { subject: m, data: A } = s(f.data);
792
+ (Y = U[m]) == null || Y.call(U, m, A);
787
793
  }, g.oniceconnectionstatechange = () => {
788
794
  var m;
789
795
  n("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
@@ -794,20 +800,20 @@ async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
794
800
  n("peerConnection.ontrack", f), (m = r.onSrcObjectReady) == null || m.call(r, f.streams[0]);
795
801
  }, await g.setRemoteDescription(K), n("set remote description OK");
796
802
  const F = await g.createAnswer();
797
- return n("create answer OK"), await g.setLocalDescription(F), n("set local description OK"), await A(C, F, u), n("start connection OK"), {
803
+ return n("create answer OK"), await g.setLocalDescription(F), n("set local description OK"), await b(D, F, u), n("start connection OK"), {
798
804
  /**
799
805
  * Method to send request to server to get clip or talk depend on you payload
800
806
  * @param payload
801
807
  */
802
808
  speak(f) {
803
- return B(C, u, f);
809
+ return L(D, u, f);
804
810
  },
805
811
  /**
806
812
  * Method to close RTC connection
807
813
  */
808
814
  async disconnect() {
809
815
  var f;
810
- if (C) {
816
+ if (D) {
811
817
  const m = fe(g.iceConnectionState);
812
818
  if (g) {
813
819
  if (m === I.New) {
@@ -817,29 +823,29 @@ async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
817
823
  g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
818
824
  }
819
825
  try {
820
- m === I.Connected && await b(C, u).catch((j) => {
826
+ m === I.Connected && await x(D, u).catch((A) => {
821
827
  });
822
- } catch (j) {
823
- n("Error on close stream connection", j);
828
+ } catch (A) {
829
+ n("Error on close stream connection", A);
824
830
  }
825
- (f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval(E);
831
+ (f = r.onAgentActivityStateChange) == null || f.call(r, O.Idle), clearInterval(E);
826
832
  }
827
833
  },
828
834
  /**
829
835
  * Method to send data channel messages to the server
830
836
  */
831
837
  sendDataChannelMessage(f) {
832
- var m, j;
838
+ var m, A;
833
839
  if (!d || p.readyState !== "open") {
834
840
  n("Data channel is not ready for sending messages"), (m = r.onError) == null || m.call(r, new Error("Data channel is not ready for sending messages"), {
835
- streamId: C
841
+ streamId: D
836
842
  });
837
843
  return;
838
844
  }
839
845
  try {
840
846
  p.send(f);
841
- } catch (Q) {
842
- n("Error sending data channel message", Q), (j = r.onError) == null || j.call(r, Q, { streamId: C });
847
+ } catch (Y) {
848
+ n("Error sending data channel message", Y), (A = r.onError) == null || A.call(r, Y, { streamId: D });
843
849
  }
844
850
  },
845
851
  /**
@@ -849,7 +855,7 @@ async function Ct(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
849
855
  /**
850
856
  * Id of current RTC stream
851
857
  */
852
- streamId: C,
858
+ streamId: D,
853
859
  streamType: S,
854
860
  interruptAvailable: v ?? !1,
855
861
  triggersAvailable: T ?? !1
@@ -867,7 +873,7 @@ async function Dt(e, t, a) {
867
873
  const { version: o, ...i } = t;
868
874
  switch (i.transport_provider) {
869
875
  case de.Livekit:
870
- const { createLiveKitStreamingManager: c } = await import("./livekit-manager-jsPsU3VP.js");
876
+ const { createLiveKitStreamingManager: c } = await import("./livekit-manager-D7QkEucf.js");
871
877
  return c(r, i, a);
872
878
  default:
873
879
  throw new Error(`Unsupported transport provider: ${i.transport_provider}`);
@@ -973,8 +979,8 @@ function ge(e, t, a) {
973
979
  },
974
980
  onAgentActivityStateChange: (n) => {
975
981
  var s, d;
976
- (d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n === X.Talking ? ie.update() : ie.reset(), Tt(
977
- n === X.Talking ? w.Start : w.Stop,
982
+ (d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n === O.Talking ? ie.update() : ie.reset(), Tt(
983
+ n === O.Talking ? w.Start : w.Stop,
978
984
  e,
979
985
  a,
980
986
  i.streamType
@@ -988,39 +994,39 @@ function ge(e, t, a) {
988
994
  });
989
995
  }
990
996
  async function jt(e, t, a, r, o) {
991
- var l, h, y, A;
997
+ var l, h, y, b;
992
998
  const i = async () => {
993
- var B;
999
+ var L;
994
1000
  if (le(e.presenter.type)) {
995
- const b = await se(
1001
+ const x = await se(
996
1002
  e,
997
1003
  a,
998
1004
  r,
999
1005
  t.mode,
1000
1006
  t.persistentChat,
1001
1007
  o
1002
- ), L = await ge(
1008
+ ), j = await ge(
1003
1009
  e,
1004
- { ...t, chatId: (B = b.chat) == null ? void 0 : B.id },
1010
+ { ...t, chatId: (L = x.chat) == null ? void 0 : L.id },
1005
1011
  r
1006
1012
  );
1007
- return { chatResult: b, streamingManager: L };
1013
+ return { chatResult: x, streamingManager: j };
1008
1014
  } else {
1009
- const b = se(
1015
+ const x = se(
1010
1016
  e,
1011
1017
  a,
1012
1018
  r,
1013
1019
  t.mode,
1014
1020
  t.persistentChat,
1015
1021
  o
1016
- ), L = ge(e, t, r), [$, C] = await Promise.all([b, L]);
1017
- return { chatResult: $, streamingManager: C };
1022
+ ), j = ge(e, t, r), [B, D] = await Promise.all([x, j]);
1023
+ return { chatResult: B, streamingManager: D };
1018
1024
  }
1019
1025
  }, { chatResult: c, streamingManager: n } = await i(), { chat: s, chatMode: d } = c;
1020
- return d && d !== t.mode && (t.mode = d, (h = (l = t.callbacks).onModeChange) == null || h.call(l, d), d !== _.Functional) ? ((A = (y = t.callbacks).onError) == null || A.call(y, new Ee(d)), n == null || n.disconnect(), { chat: s }) : { chat: s, streamingManager: n };
1026
+ return d && d !== t.mode && (t.mode = d, (h = (l = t.callbacks).onModeChange) == null || h.call(l, d), d !== _.Functional) ? ((b = (y = t.callbacks).onError) == null || b.call(y, new Ee(d)), n == null || n.disconnect(), { chat: s }) : { chat: s, streamingManager: n };
1021
1027
  }
1022
1028
  async function Lt(e, t) {
1023
- var C, K, H;
1029
+ var D, K, G;
1024
1030
  let a = !0, r = null;
1025
1031
  const o = t.mixpanelKey || Ne, i = t.wsURL || Fe, c = t.baseURL || te, n = {
1026
1032
  messages: [],
@@ -1035,7 +1041,7 @@ async function Lt(e, t) {
1035
1041
  s.track("agent-sdk", { event: "init" });
1036
1042
  const d = He(t.auth, c, t.callbacks.onError, t.externalId), l = await d.getById(e), h = le(l.presenter.type);
1037
1043
  s.enrich(qe(l));
1038
- const { onMessage: y, clearQueue: A } = st(
1044
+ const { onMessage: y, clearQueue: b } = st(
1039
1045
  s,
1040
1046
  n,
1041
1047
  t,
@@ -1045,14 +1051,14 @@ async function Lt(e, t) {
1045
1051
  return (u = n.socketManager) == null ? void 0 : u.disconnect();
1046
1052
  }
1047
1053
  );
1048
- n.messages = Ze(t.initialMessages), (K = (C = t.callbacks).onNewMessage) == null || K.call(C, [...n.messages], "answer");
1049
- const B = (u) => {
1054
+ n.messages = Ze(t.initialMessages), (K = (D = t.callbacks).onNewMessage) == null || K.call(D, [...n.messages], "answer");
1055
+ const L = (u) => {
1050
1056
  r = u;
1051
1057
  };
1052
1058
  s.track("agent-sdk", { event: "loaded", ...Ve(l) });
1053
- async function b(u) {
1054
- var S, x, z, D, E, J, R;
1055
- (x = (S = t.callbacks).onConnectionStateChange) == null || x.call(S, I.Connecting), N.reset(), u && !a && (delete n.chat, (D = (z = t.callbacks).onNewMessage) == null || D.call(z, [...n.messages], "answer"));
1059
+ async function x(u) {
1060
+ var S, $, z, C, E, J, R;
1061
+ ($ = (S = t.callbacks).onConnectionStateChange) == null || $.call(S, I.Connecting), N.reset(), u && !a && (delete n.chat, (C = (z = t.callbacks).onNewMessage) == null || C.call(z, [...n.messages], "answer"));
1056
1062
  const k = t.mode === _.DirectPlayback || h ? Promise.resolve(void 0) : nt(
1057
1063
  t.auth,
1058
1064
  i,
@@ -1061,14 +1067,17 @@ async function Lt(e, t) {
1061
1067
  ), v = ne(
1062
1068
  () => jt(
1063
1069
  l,
1064
- { ...t, callbacks: { ...t.callbacks, onVideoIdChange: B } },
1070
+ {
1071
+ ...t,
1072
+ callbacks: { ...t.callbacks, onVideoIdChange: L, onMessage: y }
1073
+ },
1065
1074
  d,
1066
1075
  s,
1067
1076
  n.chat
1068
1077
  ),
1069
1078
  {
1070
1079
  limit: 3,
1071
- timeout: xe,
1080
+ timeout: $e,
1072
1081
  timeoutErrorMessage: "Timeout initializing the stream",
1073
1082
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
1074
1083
  shouldRetryFn: (M) => (M == null ? void 0 : M.message) !== "Could not connect" && M.status !== 429,
@@ -1076,21 +1085,21 @@ async function Lt(e, t) {
1076
1085
  }
1077
1086
  ).catch((M) => {
1078
1087
  var U, F;
1079
- throw $(_.Maintenance), (F = (U = t.callbacks).onConnectionStateChange) == null || F.call(U, I.Fail), M;
1088
+ throw B(_.Maintenance), (F = (U = t.callbacks).onConnectionStateChange) == null || F.call(U, I.Fail), M;
1080
1089
  }), [T, { streamingManager: g, chat: p }] = await Promise.all([k, v]);
1081
1090
  p && p.id !== ((E = n.chat) == null ? void 0 : E.id) && ((R = (J = t.callbacks).onNewChat) == null || R.call(J, p.id)), n.streamingManager = g, n.socketManager = T, n.chat = p, a = !1, s.enrich({
1082
1091
  chatId: p == null ? void 0 : p.id,
1083
1092
  streamId: g == null ? void 0 : g.streamId,
1084
1093
  mode: n.chatMode
1085
- }), $((p == null ? void 0 : p.chat_mode) ?? t.mode ?? _.Functional);
1094
+ }), B((p == null ? void 0 : p.chat_mode) ?? t.mode ?? _.Functional);
1086
1095
  }
1087
- async function L() {
1096
+ async function j() {
1088
1097
  var u, k, v, T;
1089
1098
  (u = n.socketManager) == null || u.disconnect(), await ((k = n.streamingManager) == null ? void 0 : k.disconnect()), delete n.streamingManager, delete n.socketManager, (T = (v = t.callbacks).onConnectionStateChange) == null || T.call(v, I.Disconnected);
1090
1099
  }
1091
- async function $(u) {
1100
+ async function B(u) {
1092
1101
  var k, v;
1093
- u !== n.chatMode && (s.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== _.Functional && await L(), (v = (k = t.callbacks).onModeChange) == null || v.call(k, u));
1102
+ u !== n.chatMode && (s.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== _.Functional && await j(), (v = (k = t.callbacks).onModeChange) == null || v.call(k, u));
1094
1103
  }
1095
1104
  return {
1096
1105
  agent: l,
@@ -1106,47 +1115,47 @@ async function Lt(e, t) {
1106
1115
  var u;
1107
1116
  return ((u = n.streamingManager) == null ? void 0 : u.triggersAvailable) ?? !1;
1108
1117
  },
1109
- starterMessages: ((H = l.knowledge) == null ? void 0 : H.starter_message) || [],
1118
+ starterMessages: ((G = l.knowledge) == null ? void 0 : G.starter_message) || [],
1110
1119
  getSTTToken: () => d.getSTTToken(l.id),
1111
- changeMode: $,
1120
+ changeMode: B,
1112
1121
  enrichAnalytics: s.enrich,
1113
1122
  async connect() {
1114
- await b(!0), s.track("agent-chat", {
1123
+ await x(!0), s.track("agent-chat", {
1115
1124
  event: "connect",
1116
1125
  mode: n.chatMode
1117
1126
  });
1118
1127
  },
1119
1128
  async reconnect() {
1120
- await L(), await b(!1), s.track("agent-chat", {
1129
+ await j(), await x(!1), s.track("agent-chat", {
1121
1130
  event: "reconnect",
1122
1131
  mode: n.chatMode
1123
1132
  });
1124
1133
  },
1125
1134
  async disconnect() {
1126
- await L(), s.track("agent-chat", {
1135
+ await j(), s.track("agent-chat", {
1127
1136
  event: "disconnect",
1128
1137
  mode: n.chatMode
1129
1138
  });
1130
1139
  },
1131
1140
  async chat(u) {
1132
- var g, p, S, x, z;
1141
+ var g, p, S, $, z;
1133
1142
  const k = () => {
1134
1143
  if (ve(t.mode))
1135
- throw new V(`${t.mode} is enabled, chat is disabled`);
1144
+ throw new H(`${t.mode} is enabled, chat is disabled`);
1136
1145
  if (u.length >= 800)
1137
- throw new V("Message cannot be more than 800 characters");
1146
+ throw new H("Message cannot be more than 800 characters");
1138
1147
  if (u.length === 0)
1139
- throw new V("Message cannot be empty");
1148
+ throw new H("Message cannot be empty");
1140
1149
  if (n.chatMode === _.Maintenance)
1141
- throw new V("Chat is in maintenance mode");
1150
+ throw new H("Chat is in maintenance mode");
1142
1151
  if (![_.TextOnly, _.Playground].includes(n.chatMode)) {
1143
1152
  if (!n.streamingManager)
1144
- throw new V("Streaming manager is not initialized");
1153
+ throw new H("Streaming manager is not initialized");
1145
1154
  if (!n.chat)
1146
- throw new V("Chat is not initialized");
1155
+ throw new H("Chat is not initialized");
1147
1156
  }
1148
1157
  }, v = async () => {
1149
- var D, E;
1158
+ var C, E;
1150
1159
  if (!n.chat) {
1151
1160
  const J = await se(
1152
1161
  l,
@@ -1157,14 +1166,12 @@ async function Lt(e, t) {
1157
1166
  );
1158
1167
  if (!J.chat)
1159
1168
  throw new Ie(n.chatMode, !!t.persistentChat);
1160
- n.chat = J.chat, (E = (D = t.callbacks).onNewChat) == null || E.call(D, n.chat.id);
1169
+ n.chat = J.chat, (E = (C = t.callbacks).onNewChat) == null || E.call(C, n.chat.id);
1161
1170
  }
1162
1171
  return n.chat.id;
1163
- }, T = async (D, E) => ne(h ? async () => {
1172
+ }, T = async (C, E) => ne(h ? async () => {
1164
1173
  var R, M;
1165
- return await ((M = (R = n.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : M.call(R, u)), Promise.resolve({
1166
- result: "This is a mock message until the data channel is implemented."
1167
- });
1174
+ return await ((M = (R = n.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : M.call(R, u)), Promise.resolve({});
1168
1175
  } : async () => {
1169
1176
  var R, M;
1170
1177
  return d.chat(
@@ -1174,7 +1181,7 @@ async function Lt(e, t) {
1174
1181
  chatMode: n.chatMode,
1175
1182
  streamId: (R = n.streamingManager) == null ? void 0 : R.streamId,
1176
1183
  sessionId: (M = n.streamingManager) == null ? void 0 : M.sessionId,
1177
- messages: D.map(({ matches: U, ...F }) => F)
1184
+ messages: C.map(({ matches: U, ...F }) => F)
1178
1185
  },
1179
1186
  {
1180
1187
  ...Ce(n.chatMode),
@@ -1184,24 +1191,24 @@ async function Lt(e, t) {
1184
1191
  }, {
1185
1192
  limit: 2,
1186
1193
  shouldRetryFn: (R) => {
1187
- var F, Y, f, m;
1194
+ var F, X, f, m;
1188
1195
  const M = (F = R == null ? void 0 : R.message) == null ? void 0 : F.includes("missing or invalid session_id");
1189
- return !((Y = R == null ? void 0 : R.message) == null ? void 0 : Y.includes("Stream Error")) && !M ? ((m = (f = t.callbacks).onError) == null || m.call(f, R), !1) : !0;
1196
+ return !((X = R == null ? void 0 : R.message) == null ? void 0 : X.includes("Stream Error")) && !M ? ((m = (f = t.callbacks).onError) == null || m.call(f, R), !1) : !0;
1190
1197
  },
1191
1198
  onRetry: async () => {
1192
- await L(), await b(!1);
1199
+ await j(), await x(!1);
1193
1200
  }
1194
1201
  });
1195
1202
  try {
1196
- A(), k(), n.messages.push({
1197
- id: O(),
1203
+ b(), k(), n.messages.push({
1204
+ id: q(),
1198
1205
  role: "user",
1199
1206
  content: u,
1200
1207
  created_at: new Date(N.update()).toISOString()
1201
1208
  }), (p = (g = t.callbacks).onNewMessage) == null || p.call(g, [...n.messages], "user");
1202
- const D = await v(), E = await T([...n.messages], D);
1209
+ const C = await v(), E = await T([...n.messages], C);
1203
1210
  return n.messages.push({
1204
- id: O(),
1211
+ id: q(),
1205
1212
  role: "assistant",
1206
1213
  content: E.result || "",
1207
1214
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
@@ -1210,25 +1217,25 @@ async function Lt(e, t) {
1210
1217
  }), s.track("agent-message-send", {
1211
1218
  event: "success",
1212
1219
  messages: n.messages.length + 1
1213
- }), E.result && ((x = (S = t.callbacks).onNewMessage) == null || x.call(S, [...n.messages], "answer"), s.track("agent-message-received", {
1220
+ }), E.result && (($ = (S = t.callbacks).onNewMessage) == null || $.call(S, [...n.messages], "answer"), s.track("agent-message-received", {
1214
1221
  latency: N.get(!0),
1215
1222
  messages: n.messages.length
1216
1223
  })), E;
1217
- } catch (D) {
1224
+ } catch (C) {
1218
1225
  throw ((z = n.messages[n.messages.length - 1]) == null ? void 0 : z.role) === "assistant" && n.messages.pop(), s.track("agent-message-send", {
1219
1226
  event: "error",
1220
1227
  messages: n.messages.length
1221
- }), D;
1228
+ }), C;
1222
1229
  }
1223
1230
  },
1224
1231
  rate(u, k, v) {
1225
- var p, S, x, z;
1226
- const T = n.messages.find((D) => D.id === u);
1232
+ var p, S, $, z;
1233
+ const T = n.messages.find((C) => C.id === u);
1227
1234
  if (n.chat) {
1228
1235
  if (!T)
1229
1236
  throw new Error("Message not found");
1230
1237
  } else throw new Error("Chat is not initialized");
1231
- const g = ((p = T.matches) == null ? void 0 : p.map((D) => [D.document_id, D.id])) ?? [];
1238
+ const g = ((p = T.matches) == null ? void 0 : p.map((C) => [C.document_id, C.id])) ?? [];
1232
1239
  return s.track("agent-rate", {
1233
1240
  event: v ? "update" : "create",
1234
1241
  thumb: k === 1 ? "up" : "down",
@@ -1236,7 +1243,7 @@ async function Lt(e, t) {
1236
1243
  matches: g,
1237
1244
  score: k
1238
1245
  }), v ? d.updateRating(l.id, n.chat.id, v, {
1239
- knowledge_id: ((x = l.knowledge) == null ? void 0 : x.id) ?? "",
1246
+ knowledge_id: (($ = l.knowledge) == null ? void 0 : $.id) ?? "",
1240
1247
  message_id: u,
1241
1248
  matches: g,
1242
1249
  score: k
@@ -1279,7 +1286,7 @@ async function Lt(e, t) {
1279
1286
  }
1280
1287
  const v = k();
1281
1288
  if (s.track("agent-speak", v), N.update(), n.messages && v.type === "text" && (n.messages.push({
1282
- id: O(),
1289
+ id: q(),
1283
1290
  role: "assistant",
1284
1291
  content: v.input,
1285
1292
  created_at: (/* @__PURE__ */ new Date()).toISOString()
@@ -1309,32 +1316,32 @@ async function Lt(e, t) {
1309
1316
  };
1310
1317
  }
1311
1318
  export {
1312
- X as A,
1319
+ O as A,
1313
1320
  I as C,
1314
1321
  Le as D,
1315
- Pe as K,
1322
+ be as K,
1316
1323
  Te as P,
1317
1324
  je as R,
1318
1325
  W as S,
1319
1326
  de as T,
1320
1327
  _e as U,
1321
- V,
1328
+ H as V,
1322
1329
  Me as W,
1323
1330
  ct as a,
1324
- G as b,
1331
+ Z as b,
1325
1332
  ke as c,
1326
1333
  te as d,
1327
1334
  w as e,
1328
1335
  P as f,
1329
- Ie as g,
1330
- Ee as h,
1331
- Lt as i,
1332
- Ae as j,
1333
- _ as k,
1334
- q as l,
1335
- be as m,
1336
+ V as g,
1337
+ Ie as h,
1338
+ Ee as i,
1339
+ Lt as j,
1340
+ Ae as k,
1341
+ _ as l,
1342
+ Pe as m,
1336
1343
  he as n,
1337
- Pt as o,
1338
- Be as p,
1339
- $e as q
1344
+ bt as o,
1345
+ xe as p,
1346
+ Be as q
1340
1347
  };