@d-id/client-sdk 1.2.6 → 1.2.7-staging.363

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.
@@ -14,7 +14,7 @@ class G extends Error {
14
14
  };
15
15
  }
16
16
  }
17
- function bn(e) {
17
+ function _n(e) {
18
18
  return e instanceof Error && typeof e.kind == "string";
19
19
  }
20
20
  class ot extends G {
@@ -79,7 +79,7 @@ class We extends G {
79
79
  super(t, "StreamError", n);
80
80
  }
81
81
  }
82
- class B extends G {
82
+ class $ extends G {
83
83
  constructor(t, n) {
84
84
  super(t, "ValidationError"), this.key = n;
85
85
  }
@@ -89,7 +89,7 @@ class ut extends G {
89
89
  super(t, "WSError");
90
90
  }
91
91
  }
92
- var ft = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ft || {}), mt = /* @__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))(mt || {}), ht = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ht || {}), gt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(gt || {}), b = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(b || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(z || {}), pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(pt || {}), wt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(wt || {}), yt = /* @__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))(yt || {}), He = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(He || {});
92
+ var ft = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ft || {}), mt = /* @__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))(mt || {}), ht = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ht || {}), gt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(gt || {}), _ = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(_ || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(pt || {}), wt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(wt || {}), yt = /* @__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))(yt || {}), He = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(He || {});
93
93
  const An = (e) => {
94
94
  switch (e) {
95
95
  case "clip":
@@ -102,7 +102,7 @@ const An = (e) => {
102
102
  throw new Error(`Unknown video type: ${e}`);
103
103
  }
104
104
  };
105
- var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ie = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ie || {}), x = /* @__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))(x || {}), A = /* @__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))(A || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), ke = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ke || {}), vt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(vt || {}), Ct = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ct || {});
105
+ var k = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(k || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ie = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ie || {}), x = /* @__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))(x || {}), A = /* @__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))(A || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Se = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Se || {}), vt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(vt || {}), Ct = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ct || {});
106
106
  const xn = (...e) => {
107
107
  }, qe = (e) => new Promise((t) => setTimeout(t, e)), ee = (e = 16) => {
108
108
  const t = new Uint8Array(e);
@@ -119,7 +119,7 @@ function we(e) {
119
119
  return t;
120
120
  }
121
121
  let ue = ee();
122
- function St() {
122
+ function kt() {
123
123
  ue = ee();
124
124
  }
125
125
  function Xe(e, t) {
@@ -131,7 +131,7 @@ function Xe(e, t) {
131
131
  return `Client-Key ${e.clientKey}.${we(t)}_${ue}`;
132
132
  throw new Error(`Unknown auth type: ${e}`);
133
133
  }
134
- const kt = 45 * 1e3, Mt = "X-Playground-Chat", Te = 2e3, me = "https://api.d-id.com", Rt = "wss://notifications.d-id.com", Dt = "79f81a83a67430be2bc0fd61042b8faa", Ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, It = (e) => {
134
+ const St = 45 * 1e3, Mt = "X-Playground-Chat", be = 2e3, me = "https://api.d-id.com", Rt = "wss://notifications.d-id.com", Dt = "79f81a83a67430be2bc0fd61042b8faa", Ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, It = (e) => {
135
135
  switch (e.type) {
136
136
  case "expressive":
137
137
  return "v4";
@@ -140,10 +140,10 @@ const kt = 45 * 1e3, Mt = "X-Playground-Chat", Te = 2e3, me = "https://api.d-id.
140
140
  case "talk":
141
141
  return "v2";
142
142
  }
143
- }, Et = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Me = (e) => e === He.Expressive, Tt = (e) => [b.TextOnly, b.Playground, b.Maintenance].includes(e), Qe = (e) => e && [b.DirectPlayback, b.Off].includes(e), _e = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, be = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, _t = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
144
- function bt(e) {
143
+ }, Et = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Me = (e) => e === He.Expressive, bt = (e) => [_.TextOnly, _.Playground, _.Maintenance].includes(e), Qe = (e) => e && [_.DirectPlayback, _.Off].includes(e), Te = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, _e = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Tt = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
144
+ function _t(e) {
145
145
  const t = e.split("?")[0].split("#")[0].toLowerCase();
146
- return _t.some((n) => t.endsWith(n));
146
+ return Tt.some((n) => t.endsWith(n));
147
147
  }
148
148
  const Ae = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), xe = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
149
149
  function At(e) {
@@ -151,17 +151,17 @@ function At(e) {
151
151
  return [];
152
152
  const t = [];
153
153
  let n;
154
- for (_e.lastIndex = 0; (n = _e.exec(e)) !== null; )
154
+ for (Te.lastIndex = 0; (n = Te.exec(e)) !== null; )
155
155
  t.push({
156
156
  index: n.index,
157
157
  length: n[0].length,
158
158
  part: { type: "video", src: n[3], alt: n[1], thumbnail: n[2] }
159
159
  });
160
- for (be.lastIndex = 0; (n = be.exec(e)) !== null; )
160
+ for (_e.lastIndex = 0; (n = _e.exec(e)) !== null; )
161
161
  if (!t.some((s) => n.index >= s.index && n.index < s.index + s.length)) {
162
162
  const s = n[2], r = n[1];
163
163
  let a;
164
- bt(s) ? a = { type: "video", src: s, alt: r } : (a = { type: "image", src: s, alt: r }, s.toLowerCase().endsWith(".gif") && (a.mimeType = "image/gif")), t.push({ index: n.index, length: n[0].length, part: a });
164
+ _t(s) ? a = { type: "video", src: s, alt: r } : (a = { type: "image", src: s, alt: r }, s.toLowerCase().endsWith(".gif") && (a.mimeType = "image/gif")), t.push({ index: n.index, length: n[0].length, part: a });
165
165
  }
166
166
  for (Ae.lastIndex = 0; (n = Ae.exec(e)) !== null; )
167
167
  t.some((s) => n.index >= s.index && n.index < s.index + s.length) || t.push({
@@ -308,6 +308,9 @@ function Lt(e, t = me, n, i) {
308
308
  deleteRating(o, s, r, a) {
309
309
  return c.delete(`/${o}/chat/${s}/ratings/${r}`, a);
310
310
  },
311
+ submitFeedback(o, s, r, a) {
312
+ return c.post(`/${o}/chat/${s}/feedback`, r, a);
313
+ },
311
314
  getSTTToken(o, s) {
312
315
  return c.get(`/${o}/stt-token`, s);
313
316
  }
@@ -362,13 +365,13 @@ const Bt = (e) => {
362
365
  } catch {
363
366
  return "Unknown error";
364
367
  }
365
- }, zt = (e) => e.reduce((t, n) => t + n, 0), Le = (e) => zt(e) / e.length, je = (e) => Math.min(...e), $e = (e) => Math.max(...e), le = (e, t = 0) => {
368
+ }, Ft = (e) => e.reduce((t, n) => t + n, 0), Le = (e) => Ft(e) / e.length, je = (e) => Math.min(...e), $e = (e) => Math.max(...e), le = (e, t = 0) => {
366
369
  const n = 10 ** t;
367
370
  return Math.round(e * n) / n;
368
- }, Nt = (e, t) => {
371
+ }, zt = (e, t) => {
369
372
  const n = [...e].sort((i, c) => i - c);
370
373
  return n[Math.min(n.length - 1, Math.floor(t * (n.length - 1)))];
371
- }, Ft = (e) => Nt(e, 0.5), Vt = (e, t) => {
374
+ }, Nt = (e) => zt(e, 0.5), Vt = (e, t) => {
372
375
  try {
373
376
  return e();
374
377
  } catch {
@@ -392,7 +395,7 @@ function Be(e) {
392
395
  function ge(e) {
393
396
  return e instanceof G ? e.toJson() : { kind: "UnknownError", message: Bt(e) || "UnknownError" };
394
397
  }
395
- const Jt = "1.2.6", Ot = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", Ze = 50, Z = [];
398
+ const Jt = "1.2.7-staging.363", Ot = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", Ze = 50, Z = [];
396
399
  let pe = !1;
397
400
  async function et(e) {
398
401
  const t = await fetch(Ot, {
@@ -482,9 +485,9 @@ function Re() {
482
485
  get: (t = !1) => t ? Date.now() - e : e
483
486
  };
484
487
  }
485
- const X = Re(), Ce = Re(), ze = Re();
488
+ const X = Re(), Ce = Re(), Fe = Re();
486
489
  function tt(e) {
487
- return e === b.Playground ? { headers: { [Mt]: "true" } } : {};
490
+ return e === _.Playground ? { headers: { [Mt]: "true" } } : {};
488
491
  }
489
492
  async function nt(e, t, n, i, c = !1, o) {
490
493
  return !o && !Qe(i) && (o = await t.newChat(e.id, { persist: c }, tt(i)), n.track("agent-chat", {
@@ -541,7 +544,7 @@ async function Gt(e, t, n, i) {
541
544
  subscribeToEvents: (s) => c.push(s)
542
545
  };
543
546
  }
544
- function Ne(e) {
547
+ function ze(e) {
545
548
  if (e.answer !== void 0)
546
549
  return e.answer;
547
550
  let t = 0, n = "";
@@ -563,14 +566,14 @@ function Qt(e, t, n) {
563
566
  t.messages.push(i), n == null || n([...t.messages], "user");
564
567
  }
565
568
  function Yt(e, t, n, i, c, o, s) {
566
- if (e === z.Transcribe && t.content) {
569
+ if (e === F.Transcribe && t.content) {
567
570
  Qt(t, i, c);
568
571
  return;
569
572
  }
570
- if (!(e === z.Partial || e === z.Answer))
573
+ if (!(e === F.Partial || e === F.Answer))
571
574
  return;
572
575
  const r = i.messages[i.messages.length - 1];
573
- if (e === z.Answer && (r == null ? void 0 : r.role) === "user" && s === "partial")
576
+ if (e === F.Answer && (r == null ? void 0 : r.role) === "user" && s === "partial")
574
577
  return;
575
578
  const d = s === "answer";
576
579
  let m;
@@ -587,14 +590,14 @@ function Yt(e, t, n, i, c, o, s) {
587
590
  else
588
591
  return;
589
592
  const { content: u, sequence: f } = t;
590
- if (e === z.Partial)
593
+ if (e === F.Partial)
591
594
  n[f] = u;
592
595
  else {
593
- const v = Ne(n);
596
+ const v = ze(n);
594
597
  !!(u && u.length < v.length) && (m.interrupted = !0), n.answer = u;
595
598
  }
596
- const w = Ne(n);
597
- (m.content !== w || e === z.Answer) && (m.content = w, m.parts = ae(w), c == null || c([...i.messages], e));
599
+ const w = ze(n);
600
+ (m.content !== w || e === F.Answer) && (m.content = w, m.parts = ae(w), c == null || c([...i.messages], e));
598
601
  }
599
602
  function Zt(e, t, n, i, c) {
600
603
  const o = {}, s = () => {
@@ -611,7 +614,7 @@ function Zt(e, t, n, i, c) {
611
614
  onMessage: (d, m) => {
612
615
  var u, f;
613
616
  if ("content" in m) {
614
- const w = d === x.ChatAnswer ? z.Answer : d === x.ChatAudioTranscribed ? z.Transcribe : d;
617
+ const w = d === x.ChatAnswer ? F.Answer : d === x.ChatAudioTranscribed ? F.Transcribe : d;
615
618
  Yt(
616
619
  w,
617
620
  m,
@@ -620,7 +623,7 @@ function Zt(e, t, n, i, c) {
620
623
  a,
621
624
  s,
622
625
  r
623
- ), w === z.Partial ? r = "partial" : w === z.Answer && (r = "answer", s()), w === z.Answer && e.track("agent-message-received", {
626
+ ), w === F.Partial ? r = "partial" : w === F.Answer && (r = "answer", s()), w === F.Answer && e.track("agent-message-received", {
624
627
  content: m.content,
625
628
  messages: t.messages.length,
626
629
  mode: t.chatMode
@@ -628,15 +631,15 @@ function Zt(e, t, n, i, c) {
628
631
  } else {
629
632
  const w = x, v = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], j = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], I = Ut(m, i, { mode: t.chatMode });
630
633
  if (d = d, d === w.StreamVideoCreated && (e.linkTrack("agent-video", I, w.StreamVideoCreated, ["start"]), m.sentiment)) {
631
- const T = t.messages[t.messages.length - 1];
632
- if ((T == null ? void 0 : T.role) === "assistant") {
633
- const P = { ...T, sentiment: m.sentiment };
634
+ const b = t.messages[t.messages.length - 1];
635
+ if ((b == null ? void 0 : b.role) === "assistant") {
636
+ const P = { ...b, sentiment: m.sentiment };
634
637
  t.messages[t.messages.length - 1] = P, a == null || a([...t.messages], r ?? "answer");
635
638
  }
636
639
  }
637
640
  if (v.includes(d)) {
638
- const T = d.split("/")[1];
639
- j.includes(d) ? e.track("agent-video", { ...I, event: T }) : e.linkTrack("agent-video", { ...I, event: T }, d, ["done"]);
641
+ const b = d.split("/")[1];
642
+ j.includes(d) ? e.track("agent-video", { ...I, event: b }) : e.linkTrack("agent-video", { ...I, event: b }, d, ["done"]);
640
643
  }
641
644
  j.includes(d) && ((f = (u = n.callbacks).onError) == null || f.call(u, new We(`Stream failed with event ${d}`), { data: m })), m.event === w.StreamDone && c();
642
645
  }
@@ -693,7 +696,7 @@ function rn(e) {
693
696
  durationMs: le(i),
694
697
  desyncDurationMs: le(i * (o.length / c.length)),
695
698
  maxOffsetMs: le(c.reduce((a, d) => Math.abs(d) > Math.abs(a) ? d : a)),
696
- residualOffsetMs: le(Ft(r))
699
+ residualOffsetMs: le(Nt(r))
697
700
  };
698
701
  }
699
702
  function an(e, t, n) {
@@ -768,7 +771,7 @@ function on(e) {
768
771
  localTs: s.timestamp
769
772
  }), r;
770
773
  }
771
- function Fe(e, t, n) {
774
+ function Ne(e, t, n) {
772
775
  const i = e.map((a, d) => d === 0 ? n ? {
773
776
  timestamp: a.timestamp,
774
777
  duration: 0,
@@ -907,12 +910,12 @@ function fn(e, t, n, i, c) {
907
910
  const I = await e();
908
911
  if (!I)
909
912
  return;
910
- const { isReceiving: T, avgJitterDelayInInterval: P, freezeCount: E } = v(I), Q = on(I);
911
- if (T)
912
- a = 0, f = E - w, u = P < dn ? re.Strong : P > ln && f > 1 ? re.Weak : m, u !== m && (c == null || c(u), m = u, w += f, f = 0), d || (i == null || i(S.Start), r = s[s.length - 1], s = [], d = !0), s.push(Q);
913
+ const { isReceiving: b, avgJitterDelayInInterval: P, freezeCount: E } = v(I), Q = on(I);
914
+ if (b)
915
+ a = 0, f = E - w, u = P < dn ? re.Strong : P > ln && f > 1 ? re.Weak : m, u !== m && (c == null || c(u), m = u, w += f, f = 0), d || (i == null || i(k.Start), r = s[s.length - 1], s = [], d = !0), s.push(Q);
913
916
  else if (d && (a++, a >= cn)) {
914
- const H = Fe(s, fe, r);
915
- i == null || i(S.Stop, H), t() || n(), w = E, d = !1;
917
+ const H = Ne(s, fe, r);
918
+ i == null || i(k.Stop, H), t() || n(), w = E, d = !1;
916
919
  }
917
920
  }
918
921
  return {
@@ -922,7 +925,7 @@ function fn(e, t, n, i, c) {
922
925
  stop: () => {
923
926
  o && (clearInterval(o), o = null);
924
927
  },
925
- getReport: () => Fe(s, fe, r)
928
+ getReport: () => Ne(s, fe, r)
926
929
  };
927
930
  }
928
931
  const mn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
@@ -962,7 +965,7 @@ function gn({
962
965
  report: i,
963
966
  log: c
964
967
  }) {
965
- e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), n == null || n(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), n == null || n(S.Stop, i));
968
+ e === k.Start && t === k.Start ? (c("CALLBACK: onVideoStateChange(Start)"), n == null || n(k.Start)) : e === k.Stop && t === k.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), n == null || n(k.Stop, i));
966
969
  }
967
970
  function pn({
968
971
  statsSignal: e,
@@ -972,7 +975,7 @@ function pn({
972
975
  report: c,
973
976
  log: o
974
977
  }) {
975
- e === S.Start ? (o("CALLBACK: onVideoStateChange(Start)"), n == null || n(S.Start)) : e === S.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), n == null || n(S.Stop, c)), t === S.Start ? i == null || i(ie.Talking) : t === S.Stop && (i == null || i(ie.Idle));
978
+ e === k.Start ? (o("CALLBACK: onVideoStateChange(Start)"), n == null || n(k.Start)) : e === k.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), n == null || n(k.Stop, c)), t === k.Start ? i == null || i(ie.Talking) : t === k.Stop && (i == null || i(ie.Idle));
976
979
  }
977
980
  function Ue({
978
981
  statsSignal: e,
@@ -993,10 +996,10 @@ function Ue({
993
996
  });
994
997
  }
995
998
  async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me, analytics: s }, r) {
996
- var F;
999
+ var N;
997
1000
  const a = tn(n, "WebRTCStreamingManager"), d = hn(a);
998
- let m = !1, u = !1, f = S.Stop, w = S.Stop;
999
- const { startConnection: v, sendStreamRequest: j, close: I, createStream: T, addIceCandidate: P } = en(
1001
+ let m = !1, u = !1, f = k.Stop, w = k.Stop;
1002
+ const { startConnection: v, sendStreamRequest: j, close: I, createStream: b, addIceCandidate: P } = en(
1000
1003
  c,
1001
1004
  o,
1002
1005
  e,
@@ -1008,8 +1011,8 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1008
1011
  session_id: V,
1009
1012
  fluent: se,
1010
1013
  interrupt_enabled: Y
1011
- } = await T(t, r);
1012
- (F = i.onStreamCreated) == null || F.call(i, { stream_id: E, session_id: V, agent_id: e });
1014
+ } = await b(t, r);
1015
+ (N = i.onStreamCreated) == null || N.call(i, { stream_id: E, session_id: V, agent_id: e });
1013
1016
  const R = new mn({ iceServers: H }), q = R.createDataChannel("JanusDataChannel");
1014
1017
  if (!V)
1015
1018
  throw new Error("Could not create session_id");
@@ -1024,22 +1027,22 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1024
1027
  () => R.getStats(),
1025
1028
  ce,
1026
1029
  te,
1027
- (h, g) => Ue({
1030
+ (h, p) => Ue({
1028
1031
  statsSignal: w = h,
1029
1032
  dataChannelSignal: U === W.Legacy ? f : void 0,
1030
1033
  onVideoStateChange: i.onVideoStateChange,
1031
1034
  onAgentActivityStateChange: i.onAgentActivityStateChange,
1032
- report: g,
1035
+ report: p,
1033
1036
  streamType: U,
1034
1037
  log: a
1035
1038
  }),
1036
1039
  (h) => {
1037
- var g;
1038
- return (g = i.onConnectivityStateChange) == null ? void 0 : g.call(i, h);
1040
+ var p;
1041
+ return (p = i.onConnectivityStateChange) == null ? void 0 : p.call(i, h);
1039
1042
  }
1040
1043
  );
1041
1044
  l.start(), R.onicecandidate = (h) => {
1042
- var g;
1045
+ var p;
1043
1046
  a("peerConnection.onicecandidate", h);
1044
1047
  try {
1045
1048
  h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? P(
@@ -1053,22 +1056,22 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1053
1056
  r
1054
1057
  ) : P(E, { candidate: null }, V, r);
1055
1058
  } catch (D) {
1056
- (g = i.onError) == null || g.call(i, D, { streamId: E });
1059
+ (p = i.onError) == null || p.call(i, D, { streamId: E });
1057
1060
  }
1058
1061
  }, q.onopen = () => {
1059
1062
  u = !0, (!oe || m) && te();
1060
1063
  };
1061
- let p = null;
1064
+ let g = null;
1062
1065
  const y = (h) => {
1063
- var g;
1064
- p = h, (g = i.onVideoIdChange) == null || g.call(i, h);
1066
+ var p;
1067
+ g = h, (p = i.onVideoIdChange) == null || p.call(i, h);
1065
1068
  };
1066
- function C(h, g) {
1067
- if (h === x.StreamStarted && typeof g == "object" && "metadata" in g) {
1068
- const D = g.metadata;
1069
+ function C(h, p) {
1070
+ if (h === x.StreamStarted && typeof p == "object" && "metadata" in p) {
1071
+ const D = p.metadata;
1069
1072
  y(D.videoId);
1070
1073
  }
1071
- h === x.StreamDone && y(null), f = h === x.StreamStarted ? S.Start : S.Stop, Ue({
1074
+ h === x.StreamDone && y(null), f = h === x.StreamStarted ? k.Start : k.Stop, Ue({
1072
1075
  statsSignal: U === W.Legacy ? w : void 0,
1073
1076
  dataChannelSignal: f,
1074
1077
  onVideoStateChange: i.onVideoStateChange,
@@ -1077,43 +1080,43 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1077
1080
  log: a
1078
1081
  });
1079
1082
  }
1080
- function k(h, g) {
1081
- var $;
1082
- const D = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
1083
- D && s.enrich({ streamMetadata: D }), ($ = i.onStreamReady) == null || $.call(i);
1083
+ function S(h, p) {
1084
+ var B;
1085
+ const D = typeof p == "string" ? p : p == null ? void 0 : p.metadata;
1086
+ D && s.enrich({ streamMetadata: D }), (B = i.onStreamReady) == null || B.call(i);
1084
1087
  }
1085
1088
  const M = {
1086
1089
  [x.StreamStarted]: C,
1087
1090
  [x.StreamDone]: C,
1088
- [x.StreamReady]: k
1091
+ [x.StreamReady]: S
1089
1092
  };
1090
1093
  q.onmessage = (h) => {
1091
- var $;
1092
- const { subject: g, data: D } = d(h.data);
1093
- ($ = M[g]) == null || $.call(M, g, D);
1094
+ var B;
1095
+ const { subject: p, data: D } = d(h.data);
1096
+ (B = M[p]) == null || B.call(M, p, D);
1094
1097
  }, R.oniceconnectionstatechange = () => {
1095
- var g;
1098
+ var p;
1096
1099
  a("peerConnection.oniceconnectionstatechange => " + R.iceConnectionState);
1097
1100
  const h = Ve(R.iceConnectionState);
1098
- h !== A.Connected && ((g = i.onConnectionStateChange) == null || g.call(i, h, `webrtc:ice-${R.iceConnectionState}`));
1101
+ h !== A.Connected && ((p = i.onConnectionStateChange) == null || p.call(i, h, `webrtc:ice-${R.iceConnectionState}`));
1099
1102
  }, R.ontrack = (h) => {
1100
- var g;
1101
- a("peerConnection.ontrack", h), a("CALLBACK: onSrcObjectReady"), (g = i.onSrcObjectReady) == null || g.call(i, h.streams[0]);
1103
+ var p;
1104
+ a("peerConnection.ontrack", h), a("CALLBACK: onSrcObjectReady"), (p = i.onSrcObjectReady) == null || p.call(i, h.streams[0]);
1102
1105
  }, await R.setRemoteDescription(Q), a("set remote description OK");
1103
1106
  const L = await R.createAnswer();
1104
1107
  a("create answer OK"), await R.setLocalDescription(L), a("set local description OK"), await v(E, L, V, r), a("start connection OK");
1105
- function N(h) {
1106
- var g, D;
1108
+ function z(h) {
1109
+ var p, D;
1107
1110
  if (!m || q.readyState !== "open") {
1108
- a("Data channel is not ready for sending messages"), (g = i.onError) == null || g.call(i, new We("Data channel is not ready for sending messages"), {
1111
+ a("Data channel is not ready for sending messages"), (p = i.onError) == null || p.call(i, new We("Data channel is not ready for sending messages"), {
1109
1112
  streamId: E
1110
1113
  });
1111
1114
  return;
1112
1115
  }
1113
1116
  try {
1114
1117
  q.send(h);
1115
- } catch ($) {
1116
- a("Error sending data channel message", $), (D = i.onError) == null || D.call(i, $, { streamId: E });
1118
+ } catch (B) {
1119
+ a("Error sending data channel message", B), (D = i.onError) == null || D.call(i, B, { streamId: E });
1117
1120
  }
1118
1121
  }
1119
1122
  return {
@@ -1130,16 +1133,16 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1130
1133
  async disconnect() {
1131
1134
  var h;
1132
1135
  if (E) {
1133
- const g = Ve(R.iceConnectionState);
1136
+ const p = Ve(R.iceConnectionState);
1134
1137
  if (R) {
1135
- if (g === A.New) {
1138
+ if (p === A.New) {
1136
1139
  l.stop();
1137
1140
  return;
1138
1141
  }
1139
1142
  R.close(), R.oniceconnectionstatechange = null, R.onnegotiationneeded = null, R.onicecandidate = null, R.ontrack = null;
1140
1143
  }
1141
1144
  try {
1142
- g === A.Connected && await I(E, V).catch((D) => {
1145
+ p === A.Connected && await I(E, V).catch((D) => {
1143
1146
  });
1144
1147
  } catch (D) {
1145
1148
  a("Error on close stream connection", D);
@@ -1147,7 +1150,7 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1147
1150
  (h = i.onAgentActivityStateChange) == null || h.call(i, ie.Idle), l.stop();
1148
1151
  }
1149
1152
  },
1150
- sendDataChannelMessage: N,
1153
+ sendDataChannelMessage: z,
1151
1154
  /**
1152
1155
  * Session identifier information, should be returned in the body of all streaming requests
1153
1156
  */
@@ -1164,18 +1167,18 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1164
1167
  throw new Error("Interrupt is not enabled for this stream");
1165
1168
  if (U !== W.Fluent)
1166
1169
  throw new Error("Interrupt only available for Fluent streams");
1167
- if (!p)
1170
+ if (!g)
1168
1171
  throw new Error("No active video to interrupt");
1169
- const g = {
1172
+ const p = {
1170
1173
  type: x.StreamInterrupt,
1171
- videoId: p,
1174
+ videoId: g,
1172
1175
  timestamp: Date.now()
1173
1176
  };
1174
- N(JSON.stringify(g));
1177
+ z(JSON.stringify(p));
1175
1178
  }
1176
1179
  };
1177
1180
  }
1178
- var Se = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Se || {});
1181
+ var ke = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ke || {});
1179
1182
  async function yn(e, t, n, i) {
1180
1183
  const c = e.id;
1181
1184
  switch (t.version) {
@@ -1186,8 +1189,8 @@ async function yn(e, t, n, i) {
1186
1189
  case "v2": {
1187
1190
  const { version: o, ...s } = t;
1188
1191
  switch (s.transport.provider) {
1189
- case ke.Livekit:
1190
- const { createLiveKitStreamingManager: r } = await import("./livekit-manager-ni7hYg9q.js");
1192
+ case Se.Livekit:
1193
+ const { createLiveKitStreamingManager: r } = await import("./livekit-manager-CmGl5koh.js");
1191
1194
  return r(c, s, n);
1192
1195
  default:
1193
1196
  throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
@@ -1201,11 +1204,11 @@ const vn = "cht";
1201
1204
  function Cn() {
1202
1205
  return {
1203
1206
  transport: {
1204
- provider: ke.Livekit
1207
+ provider: Se.Livekit
1205
1208
  }
1206
1209
  };
1207
1210
  }
1208
- function Sn(e) {
1211
+ function kn(e) {
1209
1212
  var c, o;
1210
1213
  const { streamOptions: t } = e ?? {}, n = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
1211
1214
  plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
@@ -1218,8 +1221,8 @@ function Sn(e) {
1218
1221
  fluent: t == null ? void 0 : t.fluent
1219
1222
  }, ...n && { end_user_data: n } };
1220
1223
  }
1221
- function kn(e, t) {
1222
- return Me(e.presenter.type) ? { version: Se.V2, ...Cn() } : { version: Se.V1, ...Sn(t) };
1224
+ function Sn(e, t) {
1225
+ return Me(e.presenter.type) ? { version: ke.V2, ...Cn() } : { version: ke.V1, ...kn(t) };
1223
1226
  }
1224
1227
  function Mn(e, t, n) {
1225
1228
  n.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
@@ -1228,7 +1231,7 @@ function Rn(e, t, n, i, c) {
1228
1231
  c === W.Fluent ? Dn(e, t, n, i, c) : In(e, t, n, i, c);
1229
1232
  }
1230
1233
  function Dn(e, t, n, i, c) {
1231
- e === S.Start ? i.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && i.track("stream-session", {
1234
+ e === k.Start ? i.track("stream-session", { event: "start", "stream-type": c }) : e === k.Stop && i.track("stream-session", {
1232
1235
  event: "stop",
1233
1236
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1234
1237
  background: t.presenter.type === "clip" && t.presenter.background,
@@ -1237,9 +1240,9 @@ function Dn(e, t, n, i, c) {
1237
1240
  });
1238
1241
  }
1239
1242
  function Je(e, t, n, i, c) {
1240
- e === S.Start ? n.linkTrack("agent-video", { event: "start", ...c, "stream-type": i }, "start", [
1243
+ e === k.Start ? n.linkTrack("agent-video", { event: "start", ...c, "stream-type": i }, "start", [
1241
1244
  x.StreamVideoCreated
1242
- ]) : e === S.Stop && n.linkTrack(
1245
+ ]) : e === k.Stop && n.linkTrack(
1243
1246
  "agent-video",
1244
1247
  {
1245
1248
  event: "stop",
@@ -1252,12 +1255,12 @@ function Je(e, t, n, i, c) {
1252
1255
  );
1253
1256
  }
1254
1257
  function In(e, t, n, i, c) {
1255
- e === S.Start ? i.linkTrack(
1258
+ e === k.Start ? i.linkTrack(
1256
1259
  "agent-video",
1257
1260
  { event: "start", latency: X.get(!0), "stream-type": c },
1258
1261
  "start",
1259
1262
  [x.StreamVideoCreated]
1260
- ) : e === S.Stop && i.linkTrack(
1263
+ ) : e === k.Stop && i.linkTrack(
1261
1264
  "agent-video",
1262
1265
  {
1263
1266
  event: "stop",
@@ -1288,10 +1291,10 @@ function En(e, t, n) {
1288
1291
  });
1289
1292
  }
1290
1293
  function Oe(e, t, n, i) {
1291
- return X.reset(), ze.update(), new Promise(async (c, o) => {
1294
+ return X.reset(), Fe.update(), new Promise(async (c, o) => {
1292
1295
  try {
1293
1296
  let s, r = !1;
1294
- const a = kn(e, t);
1297
+ const a = Sn(e, t);
1295
1298
  n.enrich({
1296
1299
  "stream-version": a.version.toString()
1297
1300
  });
@@ -1323,14 +1326,14 @@ function Oe(e, t, n, i) {
1323
1326
  var f, w;
1324
1327
  (w = (f = t.callbacks).onAgentActivityStateChange) == null || w.call(f, u), u === ie.Talking ? (Ce.update(), d = (v) => {
1325
1328
  Je(
1326
- S.Start,
1329
+ k.Start,
1327
1330
  e,
1328
1331
  n,
1329
1332
  s.streamType,
1330
1333
  v
1331
1334
  ), d = null;
1332
1335
  }, m || d({ latency: X.get(!0) })) : (Ce.reset(), d = null, Je(
1333
- S.Stop,
1336
+ k.Stop,
1334
1337
  e,
1335
1338
  n,
1336
1339
  s.streamType
@@ -1340,7 +1343,7 @@ function Oe(e, t, n, i) {
1340
1343
  d == null || d(u);
1341
1344
  },
1342
1345
  onStreamReady: () => {
1343
- const u = ze.get(!0);
1346
+ const u = Fe.get(!0);
1344
1347
  n.track("agent-chat", { event: "ready", latency: u });
1345
1348
  },
1346
1349
  onToolEvent: ((u, f) => {
@@ -1356,13 +1359,13 @@ function Oe(e, t, n, i) {
1356
1359
  }
1357
1360
  });
1358
1361
  }
1359
- async function Tn(e, t, n, i, c) {
1362
+ async function bn(e, t, n, i, c) {
1360
1363
  var m, u, f, w;
1361
1364
  const o = async () => {
1362
1365
  if (Me(e.presenter.type)) {
1363
1366
  const v = await Oe(e, t, i), j = `${vn}_${v.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
1364
1367
  return { chatResult: {
1365
- chatMode: b.Functional,
1368
+ chatMode: _.Functional,
1366
1369
  chat: {
1367
1370
  id: j,
1368
1371
  agent_id: e.id,
@@ -1371,7 +1374,7 @@ async function Tn(e, t, n, i, c) {
1371
1374
  modified: I,
1372
1375
  agent_id__created_at: I,
1373
1376
  agent_id__modified_at: I,
1374
- chat_mode: b.Functional,
1377
+ chat_mode: _.Functional,
1375
1378
  messages: []
1376
1379
  }
1377
1380
  }, streamingManager: v };
@@ -1379,27 +1382,27 @@ async function Tn(e, t, n, i, c) {
1379
1382
  const v = new AbortController(), j = v.signal;
1380
1383
  let I;
1381
1384
  try {
1382
- const T = nt(
1385
+ const b = nt(
1383
1386
  e,
1384
1387
  n,
1385
1388
  i,
1386
1389
  t.mode,
1387
1390
  t.persistentChat,
1388
1391
  c
1389
- ), P = Oe(e, t, i, j).then((H) => (I = H, H)), [E, Q] = await Promise.all([T, P]);
1392
+ ), P = Oe(e, t, i, j).then((H) => (I = H, H)), [E, Q] = await Promise.all([b, P]);
1390
1393
  return { chatResult: E, streamingManager: Q };
1391
- } catch (T) {
1394
+ } catch (b) {
1392
1395
  throw v.abort(), I && await I.disconnect().catch(() => {
1393
- }), T;
1396
+ }), b;
1394
1397
  }
1395
1398
  }
1396
1399
  }, { chatResult: s, streamingManager: r } = await o(), { chat: a, chatMode: d } = s;
1397
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (u = (m = t.callbacks).onModeChange) == null || u.call(m, d), d !== b.Functional) ? ((w = (f = t.callbacks).onError) == null || w.call(f, new ct(d)), r == null || r.disconnect(), { chat: a }) : { chat: a, streamingManager: r };
1400
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (u = (m = t.callbacks).onModeChange) == null || u.call(m, d), d !== _.Functional) ? ((w = (f = t.callbacks).onError) == null || w.call(f, new ct(d)), r == null || r.disconnect(), { chat: a }) : { chat: a, streamingManager: r };
1398
1401
  }
1399
1402
  async function Ln(e, t) {
1400
1403
  var U, oe, ce, te;
1401
1404
  let n = !0;
1402
- const i = t.mixpanelKey || Dt, c = t.wsURL || Rt, o = t.baseURL || me, s = t.mode || b.Functional, r = {
1405
+ const i = t.mixpanelKey || Dt, c = t.wsURL || Rt, o = t.baseURL || me, s = t.mode || _.Functional, r = {
1403
1406
  messages: [],
1404
1407
  chatMode: s
1405
1408
  }, a = Wt({
@@ -1413,37 +1416,37 @@ async function Ln(e, t) {
1413
1416
  a.track("agent-sdk", { event: "init" }, d);
1414
1417
  });
1415
1418
  const m = t.callbacks.onError;
1416
- t.callbacks.onError = (l, p) => {
1417
- a.track("agent-error", { error: ge(l) }), m == null || m(l, p);
1419
+ t.callbacks.onError = (l, g) => {
1420
+ a.track("agent-error", { error: ge(l) }), m == null || m(l, g);
1418
1421
  };
1419
1422
  const u = Lt(t.auth, o, t.callbacks.onError, t.externalId), f = await u.getById(e);
1420
1423
  t.debug = t.debug || ((U = f == null ? void 0 : f.advanced_settings) == null ? void 0 : U.ui_debug_mode);
1421
1424
  const w = Me(f.presenter.type);
1422
1425
  a.enrich($t(f));
1423
1426
  const { onMessage: v, clearQueue: j } = Zt(a, r, t, f, () => {
1424
- var l, p, y;
1425
- (l = r.socketManager) == null || l.disconnect(), (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, A.Disconnected);
1427
+ var l, g, y;
1428
+ (l = r.socketManager) == null || l.disconnect(), (y = (g = t.callbacks).onConnectionStateChange) == null || y.call(g, A.Disconnected);
1426
1429
  });
1427
1430
  r.messages = Ht(t.initialMessages), (ce = (oe = t.callbacks).onNewMessage) == null || ce.call(oe, [...r.messages], "answer");
1428
1431
  const I = (l) => {
1429
1432
  a.enrich({ videoId: l });
1430
- }, T = ({ type: l }) => {
1431
- var y, C, k, M;
1433
+ }, b = ({ type: l }) => {
1434
+ var y, C, S, M;
1432
1435
  if (!((y = r.streamingManager) != null && y.interruptAvailable) || !((C = r.streamingManager) != null && C.isInterruptible)) return;
1433
- const p = r.messages[r.messages.length - 1];
1436
+ const g = r.messages[r.messages.length - 1];
1434
1437
  a.track("agent-video-interrupt", {
1435
1438
  type: l || "click",
1436
1439
  video_duration_to_interrupt: Ce.get(!0),
1437
1440
  message_duration_to_interrupt: X.get(!0)
1438
- }), p.interrupted = !0, (M = (k = t.callbacks).onNewMessage) == null || M.call(k, [...r.messages], "answer"), r.streamingManager.interrupt(l);
1441
+ }), g.interrupted = !0, (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "answer"), r.streamingManager.interrupt(l);
1439
1442
  }, P = /* @__PURE__ */ new Map();
1440
1443
  function E(l) {
1441
- return async (p) => {
1444
+ return async (g) => {
1442
1445
  const y = P.get(l);
1443
1446
  if (!y)
1444
1447
  throw new Error(`No handler registered for client tool: ${l}`);
1445
1448
  try {
1446
- const C = JSON.parse(p.payload);
1449
+ const C = JSON.parse(g.payload);
1447
1450
  return await y(C);
1448
1451
  } catch (C) {
1449
1452
  throw new Error(`Client tool "${l}" failed: ${C.message}`);
@@ -1451,33 +1454,33 @@ async function Ln(e, t) {
1451
1454
  };
1452
1455
  }
1453
1456
  function Q() {
1454
- var l, p, y, C;
1455
- for (const [k] of P)
1456
- (p = (l = r.streamingManager) == null ? void 0 : l.unregisterRpcMethod) == null || p.call(l, k), (C = (y = r.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, k, E(k));
1457
+ var l, g, y, C;
1458
+ for (const [S] of P)
1459
+ (g = (l = r.streamingManager) == null ? void 0 : l.unregisterRpcMethod) == null || g.call(l, S), (C = (y = r.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, S, E(S));
1457
1460
  }
1458
- function H(l, p) {
1459
- var C, k;
1461
+ function H(l, g) {
1462
+ var C, S;
1460
1463
  const y = !P.has(l);
1461
- P.set(l, p), y && ((k = (C = r.streamingManager) == null ? void 0 : C.registerRpcMethod) == null || k.call(C, l, E(l)));
1464
+ P.set(l, g), y && ((S = (C = r.streamingManager) == null ? void 0 : C.registerRpcMethod) == null || S.call(C, l, E(l)));
1462
1465
  }
1463
1466
  function V(l) {
1464
- var p, y;
1465
- P.delete(l), (y = (p = r.streamingManager) == null ? void 0 : p.unregisterRpcMethod) == null || y.call(p, l);
1467
+ var g, y;
1468
+ P.delete(l), (y = (g = r.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || y.call(g, l);
1466
1469
  }
1467
1470
  const se = Date.now();
1468
1471
  Be(() => {
1469
1472
  a.track("agent-sdk", { event: "loaded", ...jt(f) }, se);
1470
1473
  });
1471
1474
  async function Y(l) {
1472
- var L, N, F, h, g, D, $;
1473
- St(), (N = (L = t.callbacks).onConnectionStateChange) == null || N.call(L, A.Connecting), X.reset(), l && !n && (delete r.chat, (h = (F = t.callbacks).onNewMessage) == null || h.call(F, [...r.messages], "answer"));
1474
- const p = s === b.DirectPlayback || w ? Promise.resolve(void 0) : Gt(
1475
+ var L, z, N, h, p, D, B;
1476
+ kt(), (z = (L = t.callbacks).onConnectionStateChange) == null || z.call(L, A.Connecting), X.reset(), l && !n && (delete r.chat, (h = (N = t.callbacks).onNewMessage) == null || h.call(N, [...r.messages], "answer"));
1477
+ const g = s === _.DirectPlayback || w ? Promise.resolve(void 0) : Gt(
1475
1478
  t.auth,
1476
1479
  c,
1477
1480
  { onMessage: v, onError: t.callbacks.onError },
1478
1481
  t.externalId
1479
1482
  ), y = ye(
1480
- () => Tn(
1483
+ () => bn(
1481
1484
  f,
1482
1485
  {
1483
1486
  ...t,
@@ -1494,28 +1497,28 @@ async function Ln(e, t) {
1494
1497
  ),
1495
1498
  {
1496
1499
  limit: 3,
1497
- timeout: kt,
1500
+ timeout: St,
1498
1501
  timeoutErrorMessage: "Timeout initializing the stream",
1499
1502
  shouldRetryFn: (O) => (O == null ? void 0 : O.message) !== "Could not connect" && !(O instanceof Ke && (O.status === 429 || O.kind === "InsufficientCreditsError")),
1500
1503
  delayMs: 1e3
1501
1504
  }
1502
1505
  ).catch((O) => {
1503
- var _, J;
1504
- throw q(b.Maintenance), (J = (_ = t.callbacks).onConnectionStateChange) == null || J.call(_, A.Fail), O;
1505
- }), [C, { streamingManager: k, chat: M }] = await Promise.all([p, y]);
1506
- M && M.id !== ((g = r.chat) == null ? void 0 : g.id) && (($ = (D = t.callbacks).onNewChat) == null || $.call(D, M.id)), r.streamingManager = k, r.socketManager = C, r.chat = M, Q(), n = !1, a.enrich({
1506
+ var T, J;
1507
+ throw q(_.Maintenance), (J = (T = t.callbacks).onConnectionStateChange) == null || J.call(T, A.Fail), O;
1508
+ }), [C, { streamingManager: S, chat: M }] = await Promise.all([g, y]);
1509
+ M && M.id !== ((p = r.chat) == null ? void 0 : p.id) && ((B = (D = t.callbacks).onNewChat) == null || B.call(D, M.id)), r.streamingManager = S, r.socketManager = C, r.chat = M, Q(), n = !1, a.enrich({
1507
1510
  chatId: M == null ? void 0 : M.id,
1508
- streamId: k == null ? void 0 : k.streamId,
1511
+ streamId: S == null ? void 0 : S.streamId,
1509
1512
  mode: r.chatMode
1510
1513
  }), q((M == null ? void 0 : M.chat_mode) ?? s);
1511
1514
  }
1512
1515
  async function R() {
1513
- var l, p, y, C;
1514
- (l = r.socketManager) == null || l.disconnect(), await ((p = r.streamingManager) == null ? void 0 : p.disconnect()), delete r.streamingManager, delete r.socketManager, (C = (y = t.callbacks).onConnectionStateChange) == null || C.call(y, A.Disconnected);
1516
+ var l, g, y, C;
1517
+ (l = r.socketManager) == null || l.disconnect(), await ((g = r.streamingManager) == null ? void 0 : g.disconnect()), delete r.streamingManager, delete r.socketManager, (C = (y = t.callbacks).onConnectionStateChange) == null || C.call(y, A.Disconnected);
1515
1518
  }
1516
1519
  async function q(l) {
1517
- var p, y;
1518
- l !== r.chatMode && (a.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== b.Functional && await R(), (y = (p = t.callbacks).onModeChange) == null || y.call(p, l));
1520
+ var g, y;
1521
+ l !== r.chatMode && (a.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== _.Functional && await R(), (y = (g = t.callbacks).onModeChange) == null || y.call(g, l));
1519
1522
  }
1520
1523
  return {
1521
1524
  agent: f,
@@ -1539,12 +1542,12 @@ async function Ln(e, t) {
1539
1542
  },
1540
1543
  async reconnect() {
1541
1544
  const l = r.streamingManager;
1542
- let p;
1545
+ let g;
1543
1546
  if (w && (l != null && l.reconnect))
1544
1547
  try {
1545
1548
  await l.reconnect();
1546
1549
  } catch (y) {
1547
- p = ge(y).kind, await R(), await Y(!1);
1550
+ g = ge(y).kind, await R(), await Y(!1);
1548
1551
  }
1549
1552
  else
1550
1553
  await R(), await Y(!1);
@@ -1552,7 +1555,7 @@ async function Ln(e, t) {
1552
1555
  event: "reconnect",
1553
1556
  mode: r.chatMode,
1554
1557
  success: !0,
1555
- ...p && { fallbackReason: p }
1558
+ ...g && { fallbackReason: g }
1556
1559
  });
1557
1560
  },
1558
1561
  async disconnect() {
@@ -1562,44 +1565,44 @@ async function Ln(e, t) {
1562
1565
  });
1563
1566
  },
1564
1567
  publishMicrophoneStream(l) {
1565
- var p;
1566
- return (p = r.streamingManager) != null && p.publishMicrophoneStream ? r.streamingManager.publishMicrophoneStream(l) : Promise.reject(new Error("publishMicrophoneStream is not available for this streaming manager"));
1568
+ var g;
1569
+ return (g = r.streamingManager) != null && g.publishMicrophoneStream ? r.streamingManager.publishMicrophoneStream(l) : Promise.reject(new Error("publishMicrophoneStream is not available for this streaming manager"));
1567
1570
  },
1568
1571
  unpublishMicrophoneStream() {
1569
1572
  var l;
1570
1573
  return (l = r.streamingManager) != null && l.unpublishMicrophoneStream ? r.streamingManager.unpublishMicrophoneStream() : Promise.resolve();
1571
1574
  },
1572
1575
  replaceMicrophoneTrack(l) {
1573
- var p;
1574
- return (p = r.streamingManager) != null && p.replaceMicrophoneTrack ? r.streamingManager.replaceMicrophoneTrack(l) : Promise.reject(new Error("replaceMicrophoneTrack is not available for this streaming manager"));
1576
+ var g;
1577
+ return (g = r.streamingManager) != null && g.replaceMicrophoneTrack ? r.streamingManager.replaceMicrophoneTrack(l) : Promise.reject(new Error("replaceMicrophoneTrack is not available for this streaming manager"));
1575
1578
  },
1576
1579
  publishCameraStream(l) {
1577
- var p;
1578
- return (p = r.streamingManager) != null && p.publishCameraStream ? r.streamingManager.publishCameraStream(l) : Promise.reject(new Error("publishCameraStream is not available for this streaming manager"));
1580
+ var g;
1581
+ return (g = r.streamingManager) != null && g.publishCameraStream ? r.streamingManager.publishCameraStream(l) : Promise.reject(new Error("publishCameraStream is not available for this streaming manager"));
1579
1582
  },
1580
1583
  unpublishCameraStream() {
1581
1584
  var l;
1582
1585
  return (l = r.streamingManager) != null && l.unpublishCameraStream ? r.streamingManager.unpublishCameraStream() : Promise.resolve();
1583
1586
  },
1584
1587
  async chat(l) {
1585
- var k, M, L, N, F;
1586
- const p = () => {
1588
+ var S, M, L, z, N;
1589
+ const g = () => {
1587
1590
  if (Qe(s))
1588
- throw new B(`${s} is enabled, chat is disabled`);
1589
- if (l.length >= Te)
1590
- throw new B(`Message cannot be more than ${Te} characters`);
1591
+ throw new $(`${s} is enabled, chat is disabled`);
1592
+ if (l.length >= be)
1593
+ throw new $(`Message cannot be more than ${be} characters`);
1591
1594
  if (l.length === 0)
1592
- throw new B("Message cannot be empty");
1593
- if (r.chatMode === b.Maintenance)
1594
- throw new B("Chat is in maintenance mode");
1595
- if (![b.TextOnly, b.Playground].includes(r.chatMode)) {
1595
+ throw new $("Message cannot be empty");
1596
+ if (r.chatMode === _.Maintenance)
1597
+ throw new $("Chat is in maintenance mode");
1598
+ if (![_.TextOnly, _.Playground].includes(r.chatMode)) {
1596
1599
  if (!r.streamingManager)
1597
- throw new B("Streaming manager is not initialized");
1600
+ throw new $("Streaming manager is not initialized");
1598
1601
  if (!r.chat)
1599
- throw new B("Chat is not initialized");
1602
+ throw new $("Chat is not initialized");
1600
1603
  }
1601
1604
  }, y = async () => {
1602
- var h, g;
1605
+ var h, p;
1603
1606
  if (!r.chat) {
1604
1607
  const D = await nt(
1605
1608
  f,
@@ -1610,22 +1613,22 @@ async function Ln(e, t) {
1610
1613
  );
1611
1614
  if (!D.chat)
1612
1615
  throw new ot(r.chatMode, !!t.persistentChat);
1613
- r.chat = D.chat, (g = (h = t.callbacks).onNewChat) == null || g.call(h, r.chat.id);
1616
+ r.chat = D.chat, (p = (h = t.callbacks).onNewChat) == null || p.call(h, r.chat.id);
1614
1617
  }
1615
1618
  return r.chat.id;
1616
- }, C = async (h, g) => {
1617
- const D = r.chatMode === b.Playground;
1619
+ }, C = async (h, p) => {
1620
+ const D = r.chatMode === _.Playground;
1618
1621
  return ye(w && !D ? async () => {
1619
- var _, J;
1620
- return await ((J = (_ = r.streamingManager) == null ? void 0 : _.sendTextMessage) == null ? void 0 : J.call(_, l)), Promise.resolve({});
1622
+ var T, J;
1623
+ return await ((J = (T = r.streamingManager) == null ? void 0 : T.sendTextMessage) == null ? void 0 : J.call(T, l)), Promise.resolve({});
1621
1624
  } : async () => {
1622
- var _, J;
1625
+ var T, J;
1623
1626
  return u.chat(
1624
1627
  f.id,
1625
- g,
1628
+ p,
1626
1629
  {
1627
1630
  chatMode: r.chatMode,
1628
- streamId: (_ = r.streamingManager) == null ? void 0 : _.streamId,
1631
+ streamId: (T = r.streamingManager) == null ? void 0 : T.streamId,
1629
1632
  sessionId: (J = r.streamingManager) == null ? void 0 : J.sessionId,
1630
1633
  messages: h.map(({ matches: at, ...de }) => de)
1631
1634
  },
@@ -1636,10 +1639,10 @@ async function Ln(e, t) {
1636
1639
  );
1637
1640
  }, {
1638
1641
  limit: 2,
1639
- shouldRetryFn: (_) => {
1642
+ shouldRetryFn: (T) => {
1640
1643
  var de, De, Ie, Ee;
1641
- const J = (de = _ == null ? void 0 : _.message) == null ? void 0 : de.includes("missing or invalid session_id");
1642
- return !((De = _ == null ? void 0 : _.message) == null ? void 0 : De.includes("Stream Error")) && !J ? ((Ee = (Ie = t.callbacks).onError) == null || Ee.call(Ie, _), !1) : !0;
1644
+ const J = (de = T == null ? void 0 : T.message) == null ? void 0 : de.includes("missing or invalid session_id");
1645
+ return !((De = T == null ? void 0 : T.message) == null ? void 0 : De.includes("Stream Error")) && !J ? ((Ee = (Ie = t.callbacks).onError) == null || Ee.call(Ie, T), !1) : !0;
1643
1646
  },
1644
1647
  onRetry: async () => {
1645
1648
  await R(), await Y(!1);
@@ -1647,74 +1650,79 @@ async function Ln(e, t) {
1647
1650
  });
1648
1651
  };
1649
1652
  try {
1650
- j(), p(), r.messages.push({
1653
+ j(), g(), r.messages.push({
1651
1654
  id: ee(),
1652
1655
  role: "user",
1653
1656
  content: l,
1654
1657
  parts: ae(l),
1655
1658
  created_at: new Date(X.update()).toISOString()
1656
- }), (M = (k = t.callbacks).onNewMessage) == null || M.call(k, [...r.messages], "user");
1657
- const h = await y(), g = await C([...r.messages], h);
1658
- return g.result && r.messages.push({
1659
+ }), (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "user");
1660
+ const h = await y(), p = await C([...r.messages], h);
1661
+ return p.result && r.messages.push({
1659
1662
  id: ee(),
1660
1663
  role: "assistant",
1661
- content: g.result,
1662
- parts: ae(g.result),
1664
+ content: p.result,
1665
+ parts: ae(p.result),
1663
1666
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1664
- context: g.context,
1665
- matches: g.matches
1667
+ context: p.context,
1668
+ matches: p.matches
1666
1669
  }), a.track("agent-message-send", {
1667
1670
  event: "success",
1668
1671
  messages: r.messages.length + 1
1669
- }), g.result && ((N = (L = t.callbacks).onNewMessage) == null || N.call(L, [...r.messages], "answer"), a.track("agent-message-received", {
1672
+ }), p.result && ((z = (L = t.callbacks).onNewMessage) == null || z.call(L, [...r.messages], "answer"), a.track("agent-message-received", {
1670
1673
  latency: X.get(!0),
1671
1674
  messages: r.messages.length
1672
- })), g;
1675
+ })), p;
1673
1676
  } catch (h) {
1674
- throw ((F = r.messages[r.messages.length - 1]) == null ? void 0 : F.role) === "assistant" && r.messages.pop(), a.track("agent-message-send", {
1677
+ throw ((N = r.messages[r.messages.length - 1]) == null ? void 0 : N.role) === "assistant" && r.messages.pop(), a.track("agent-message-send", {
1675
1678
  event: "error",
1676
1679
  messages: r.messages.length,
1677
1680
  error: ge(h)
1678
1681
  }), h;
1679
1682
  }
1680
1683
  },
1681
- rate(l, p, y) {
1682
- var M, L, N, F;
1684
+ rate(l, g, y) {
1685
+ var M, L, z, N;
1683
1686
  const C = r.messages.find((h) => h.id === l);
1684
1687
  if (r.chat) {
1685
1688
  if (!C)
1686
- throw new B("Message not found");
1687
- } else throw new B("Chat is not initialized");
1688
- const k = ((M = C.matches) == null ? void 0 : M.map((h) => [h.document_id, h.id])) ?? [];
1689
+ throw new $("Message not found");
1690
+ } else throw new $("Chat is not initialized");
1691
+ const S = ((M = C.matches) == null ? void 0 : M.map((h) => [h.document_id, h.id])) ?? [];
1689
1692
  return a.track("agent-rate", {
1690
1693
  event: y ? "update" : "create",
1691
- thumb: p === 1 ? "up" : "down",
1694
+ thumb: g === 1 ? "up" : "down",
1692
1695
  knowledge_id: ((L = f.knowledge) == null ? void 0 : L.id) ?? "",
1693
- matches: k,
1694
- score: p
1696
+ matches: S,
1697
+ score: g
1695
1698
  }), y ? u.updateRating(f.id, r.chat.id, y, {
1696
- knowledge_id: ((N = f.knowledge) == null ? void 0 : N.id) ?? "",
1699
+ knowledge_id: ((z = f.knowledge) == null ? void 0 : z.id) ?? "",
1697
1700
  message_id: l,
1698
- matches: k,
1699
- score: p
1701
+ matches: S,
1702
+ score: g
1700
1703
  }) : u.createRating(f.id, r.chat.id, {
1701
- knowledge_id: ((F = f.knowledge) == null ? void 0 : F.id) ?? "",
1704
+ knowledge_id: ((N = f.knowledge) == null ? void 0 : N.id) ?? "",
1702
1705
  message_id: l,
1703
- matches: k,
1704
- score: p
1706
+ matches: S,
1707
+ score: g
1705
1708
  });
1706
1709
  },
1707
1710
  deleteRate(l) {
1708
1711
  if (!r.chat)
1709
- throw new B("Chat is not initialized");
1712
+ throw new $("Chat is not initialized");
1710
1713
  return a.track("agent-rate-delete", { type: "text" }), u.deleteRating(f.id, r.chat.id, l);
1711
1714
  },
1715
+ submitFeedback(l, g) {
1716
+ if (!r.chat)
1717
+ throw new $("Chat is not initialized");
1718
+ return a.track("agent-feedback", { rating: l, hasAnswer: !!g }), u.submitFeedback(f.id, r.chat.id, { rating: l, answer: g });
1719
+ },
1712
1720
  async speak(l) {
1713
- var k, M, L;
1714
- function p() {
1721
+ var S, M, L;
1722
+ function g() {
1715
1723
  if (typeof l == "string") {
1716
1724
  if (!f.presenter.voice)
1717
- throw new B("Presenter voice is not initialized");
1725
+ throw new $("Presenter voice is not initialized");
1718
1726
  return {
1719
1727
  type: "text",
1720
1728
  provider: f.presenter.voice,
@@ -1724,7 +1732,7 @@ async function Ln(e, t) {
1724
1732
  }
1725
1733
  if (l.type === "text" && !l.provider) {
1726
1734
  if (!f.presenter.voice)
1727
- throw new B("Presenter voice is not initialized");
1735
+ throw new $("Presenter voice is not initialized");
1728
1736
  return {
1729
1737
  type: "text",
1730
1738
  provider: f.presenter.voice,
@@ -1734,27 +1742,27 @@ async function Ln(e, t) {
1734
1742
  }
1735
1743
  return l;
1736
1744
  }
1737
- const y = p();
1745
+ const y = g();
1738
1746
  if (a.track("agent-speak", y), X.update(), r.messages && y.type === "text" && (r.messages.push({
1739
1747
  id: ee(),
1740
1748
  role: "assistant",
1741
1749
  content: y.input,
1742
1750
  parts: ae(y.input),
1743
1751
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1744
- }), (M = (k = t.callbacks).onNewMessage) == null || M.call(k, [...r.messages], "answer")), Tt(r.chatMode))
1752
+ }), (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "answer")), bt(r.chatMode))
1745
1753
  return {
1746
1754
  duration: 0,
1747
1755
  video_id: "",
1748
1756
  status: "success"
1749
1757
  };
1750
1758
  if (!r.streamingManager)
1751
- throw new B("Please connect to the agent first");
1759
+ throw new $("Please connect to the agent first");
1752
1760
  return r.streamingManager.speak({
1753
1761
  script: y,
1754
1762
  metadata: { chat_id: (L = r.chat) == null ? void 0 : L.id, agent_id: f.id }
1755
1763
  });
1756
1764
  },
1757
- interrupt: T,
1765
+ interrupt: b,
1758
1766
  registerClientTool: H,
1759
1767
  unregisterClientTool: V
1760
1768
  };
@@ -1762,7 +1770,7 @@ async function Ln(e, t) {
1762
1770
  export {
1763
1771
  ie as A,
1764
1772
  G as B,
1765
- z as C,
1773
+ F as C,
1766
1774
  yt as D,
1767
1775
  Ke as H,
1768
1776
  wt as K,
@@ -1770,9 +1778,9 @@ export {
1770
1778
  mt as P,
1771
1779
  gt as R,
1772
1780
  x as S,
1773
- ke as T,
1781
+ Se as T,
1774
1782
  ft as U,
1775
- B as V,
1783
+ $ as V,
1776
1784
  ut as W,
1777
1785
  tn as a,
1778
1786
  W as b,
@@ -1783,12 +1791,12 @@ export {
1783
1791
  re as g,
1784
1792
  fn as h,
1785
1793
  Pn as i,
1786
- S as j,
1794
+ k as j,
1787
1795
  ht as k,
1788
1796
  X as l,
1789
1797
  ot as m,
1790
1798
  xn as n,
1791
- b as o,
1799
+ _ as o,
1792
1800
  ct as p,
1793
1801
  vt as q,
1794
1802
  Jt as r,
@@ -1797,7 +1805,7 @@ export {
1797
1805
  He as u,
1798
1806
  Ct as v,
1799
1807
  Ln as w,
1800
- bn as x,
1808
+ _n as x,
1801
1809
  An as y,
1802
1810
  At as z
1803
1811
  };