@d-id/client-sdk 3.0.0-staging.426 → 3.0.1-staging.428

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,9 +1,9 @@
1
1
  var Rt = Object.defineProperty;
2
2
  var Et = (e, t, r) => t in e ? Rt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var x = (e, t, r) => Et(e, typeof t != "symbol" ? t + "" : t, r);
4
- var Re = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Re || {}), L = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(L || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), ne = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e.Image = "image", e))(ne || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ge = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ge || {}), we = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(we || {}), k = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.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.TurnStarted = "turn/started", e.TurnEnded = "turn/ended", e))(k || {}), Be = /* @__PURE__ */ ((e) => (e.Started = "tool-call/started", e.Done = "tool-call/done", e.Error = "tool-call/error", e))(Be || {}), kt = /* @__PURE__ */ ((e) => (e.Presentation = "did.presentation", e))(kt || {}), R = /* @__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))(R || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), he = /* @__PURE__ */ ((e) => (e.Ok = "ok", e.UnknownError = "unknown_error", e.NetworkIssue = "network_issue", e.MessageLimit = "message_limit", e.TimeLimit = "time_limit", e.Inactivity = "inactivity", e.EndedByAgent = "ended_by_agent", e))(he || {}), Fe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Fe || {}), Tt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Elevenlabs = "elevenlabs", e.Cartesia = "cartesia", e))(Tt || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e.ExternalPrivate = "external-private", e))(_t || {});
4
+ var Re = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Re || {}), L = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(L || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), ne = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e.Image = "image", e))(ne || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ge = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ge || {}), we = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(we || {}), k = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.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.TurnStarted = "turn/started", e.TurnEnded = "turn/ended", e))(k || {}), Be = /* @__PURE__ */ ((e) => (e.Started = "tool-call/started", e.Done = "tool-call/done", e.Error = "tool-call/error", e))(Be || {}), kt = /* @__PURE__ */ ((e) => (e.Presentation = "did.presentation", e))(kt || {}), R = /* @__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))(R || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), he = /* @__PURE__ */ ((e) => (e.Ok = "ok", e.UnknownError = "unknown_error", e.NetworkIssue = "network_issue", e.MessageLimit = "message_limit", e.TimeLimit = "time_limit", e.Inactivity = "inactivity", e.EndedByAgent = "ended_by_agent", e))(he || {}), Ve = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ve || {}), Tt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Elevenlabs = "elevenlabs", e.Cartesia = "cartesia", e))(Tt || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e.ExternalPrivate = "external-private", e))(_t || {});
5
5
  const Jn = (...e) => {
6
- }, ft = (e) => new Promise((t) => setTimeout(t, e)), Z = (e = 16) => {
6
+ }, mt = (e) => new Promise((t) => setTimeout(t, e)), Z = (e = 16) => {
7
7
  const t = new Uint8Array(e);
8
8
  return globalThis.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
9
9
  };
@@ -17,14 +17,14 @@ function $e(e) {
17
17
  }
18
18
  return t;
19
19
  }
20
- let mt;
20
+ let gt;
21
21
  function Ae() {
22
- return mt ?? (mt = Z());
22
+ return gt ?? (gt = Z());
23
23
  }
24
24
  function At() {
25
- mt = Z();
25
+ gt = Z();
26
26
  }
27
- function gt(e, t) {
27
+ function ht(e, t) {
28
28
  if (e.type === "bearer")
29
29
  return `Bearer ${e.token}~${Ae()}`;
30
30
  if (e.type === "basic")
@@ -33,7 +33,7 @@ function gt(e, t) {
33
33
  return `Client-Key ${e.clientKey}.${$e(t)}_${Ae()}`;
34
34
  throw new Error(`Unknown auth type: ${e}`);
35
35
  }
36
- const Pt = 45 * 1e3, bt = "X-Playground-Chat", He = 2e3, ke = "https://api.d-id.com", xt = "wss://notifications.d-id.com", Lt = "79f81a83a67430be2bc0fd61042b8faa";
36
+ const Pt = 45 * 1e3, bt = "X-Playground-Chat", We = 2e3, ke = "https://api.d-id.com", xt = "wss://notifications.d-id.com", Lt = "79f81a83a67430be2bc0fd61042b8faa";
37
37
  class q extends Error {
38
38
  /**
39
39
  * Creates an SDK error. The SDK builds these itself; applications normally only catch them.
@@ -125,7 +125,7 @@ function $t(e) {
125
125
  } catch {
126
126
  }
127
127
  }
128
- class ht extends q {
128
+ class Ne extends q {
129
129
  /**
130
130
  * Builds the error from the failing response.
131
131
  * @internal The SDK builds this itself; applications catch the error rather than construct it.
@@ -292,36 +292,36 @@ class Ot extends q {
292
292
  x(this, "kind", "WSError");
293
293
  }
294
294
  }
295
- const wt = (e) => e.type, zt = (e) => e.type === ne.Expressive ? "v4" : e.type === ne.Clip ? "v3-pro" : e.type === ne.Image ? "image" : "v2", Ve = (e) => e === ne.Expressive || e === ne.Image, Pe = (e) => [L.TextOnly, L.Playground, L.Maintenance].includes(e), te = (e) => e && [L.DirectPlayback, L.Off].includes(e), We = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ft = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
295
+ const wt = (e) => e.type, zt = (e) => e.type === ne.Expressive ? "v4" : e.type === ne.Clip ? "v3-pro" : e.type === ne.Image ? "image" : "v2", Ue = (e) => e === ne.Expressive || e === ne.Image, Pe = (e) => [L.TextOnly, L.Playground, L.Maintenance].includes(e), te = (e) => e && [L.DirectPlayback, L.Off].includes(e), Ke = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, qe = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ft = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
296
296
  function Vt(e) {
297
297
  const t = e.split("?")[0].split("#")[0].toLowerCase();
298
298
  return Ft.some((r) => t.endsWith(r));
299
299
  }
300
- const qe = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ge = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
300
+ const Ge = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Xe = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
301
301
  function yt(e) {
302
302
  if (e.length === 0)
303
303
  return [];
304
304
  const t = [];
305
305
  let r;
306
- for (We.lastIndex = 0; (r = We.exec(e)) !== null; )
306
+ for (Ke.lastIndex = 0; (r = Ke.exec(e)) !== null; )
307
307
  t.push({
308
308
  index: r.index,
309
309
  length: r[0].length,
310
310
  part: { type: "video", src: r[3], alt: r[1], thumbnail: r[2] }
311
311
  });
312
- for (Ke.lastIndex = 0; (r = Ke.exec(e)) !== null; )
312
+ for (qe.lastIndex = 0; (r = qe.exec(e)) !== null; )
313
313
  if (!t.some((i) => r.index >= i.index && r.index < i.index + i.length)) {
314
314
  const i = r[2], u = r[1];
315
315
  let n;
316
316
  Vt(i) ? n = { type: "video", src: i, alt: u } : (n = { type: "image", src: i, alt: u }, i.toLowerCase().endsWith(".gif") && (n.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: n });
317
317
  }
318
- for (qe.lastIndex = 0; (r = qe.exec(e)) !== null; )
318
+ for (Ge.lastIndex = 0; (r = Ge.exec(e)) !== null; )
319
319
  t.some((i) => r.index >= i.index && r.index < i.index + i.length) || t.push({
320
320
  index: r.index,
321
321
  length: r[0].length,
322
322
  part: { type: "link", href: r[2], label: r[1] }
323
323
  });
324
- for (Ge.lastIndex = 0; (r = Ge.exec(e)) !== null; )
324
+ for (Xe.lastIndex = 0; (r = Xe.exec(e)) !== null; )
325
325
  t.some((i) => r.index >= i.index && r.index < i.index + i.length) || t.push({
326
326
  index: r.index,
327
327
  length: r[0].length,
@@ -336,9 +336,9 @@ function yt(e) {
336
336
  s.index > o && a.push({ type: "text", text: e.slice(o, s.index) }), a.push(s.part), o = s.index + s.length;
337
337
  return o < e.length && a.push({ type: "text", text: e.slice(o) }), a;
338
338
  }
339
- let Xe = "", be = [];
339
+ let Ye = "", be = [];
340
340
  function pe(e) {
341
- return e === Xe || (Xe = e, be = yt(e)), be;
341
+ return e === Ye || (Ye = e, be = yt(e)), be;
342
342
  }
343
343
  function Ut(e, t) {
344
344
  let r;
@@ -349,7 +349,7 @@ function Ut(e, t) {
349
349
  clear: () => clearTimeout(r)
350
350
  };
351
351
  }
352
- async function Ne(e, t) {
352
+ async function Oe(e, t) {
353
353
  const r = {
354
354
  limit: (t == null ? void 0 : t.limit) ?? 3,
355
355
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
@@ -369,17 +369,17 @@ async function Ne(e, t) {
369
369
  } catch (s) {
370
370
  if (a = s, !r.shouldRetryFn(s) || o >= r.limit)
371
371
  throw s;
372
- await ft(r.delayMs), await r.onRetry(s);
372
+ await mt(r.delayMs), await r.onRetry(s);
373
373
  }
374
374
  throw a;
375
375
  }
376
- class Ye {
376
+ class Qe {
377
377
  constructor(t) {
378
378
  x(this, "status", 429);
379
379
  this.response = t;
380
380
  }
381
381
  }
382
- const Jt = (e) => Ne(e, {
382
+ const Jt = (e) => Oe(e, {
383
383
  limit: 3,
384
384
  delayMs: 1e3,
385
385
  timeout: 0,
@@ -395,16 +395,16 @@ function vt(e, t = ke, r, a) {
395
395
  ...n,
396
396
  headers: {
397
397
  ...n.headers,
398
- Authorization: gt(e, a),
398
+ Authorization: ht(e, a),
399
399
  "Content-Type": "application/json"
400
400
  }
401
401
  });
402
402
  if (g.status === 429)
403
- throw new Ye(g);
403
+ throw new Qe(g);
404
404
  return g;
405
405
  });
406
406
  } catch (g) {
407
- if (g instanceof Ye)
407
+ if (g instanceof Qe)
408
408
  f = g.response;
409
409
  else {
410
410
  if ((g == null ? void 0 : g.name) === "AbortError")
@@ -420,7 +420,7 @@ function vt(e, t = ke, r, a) {
420
420
  }
421
421
  }
422
422
  if (!f.ok) {
423
- const g = await f.text().catch(() => `Failed to fetch with status ${f.status}`), l = new ht(f.status, g, { endpoint: s, method: d });
423
+ const g = await f.text().catch(() => `Failed to fetch with status ${f.status}`), l = new Ne(f.status, g, { endpoint: s, method: d });
424
424
  throw u || r == null || r(l, { endpoint: s, method: d }), l;
425
425
  }
426
426
  return f.json();
@@ -503,7 +503,7 @@ const qt = (e) => {
503
503
  } catch {
504
504
  return "Unknown error";
505
505
  }
506
- }, Gt = (e) => e.reduce((t, r) => t + r, 0), Qe = (e) => Gt(e) / e.length, Ze = (e) => Math.min(...e), et = (e) => Math.max(...e), De = (e, t = 0) => {
506
+ }, Gt = (e) => e.reduce((t, r) => t + r, 0), Ze = (e) => Gt(e) / e.length, et = (e) => Math.min(...e), tt = (e) => Math.max(...e), De = (e, t = 0) => {
507
507
  const r = 10 ** t;
508
508
  return Math.round(e * r) / r;
509
509
  }, Xt = (e, t) => {
@@ -516,7 +516,7 @@ const qt = (e) => {
516
516
  return t;
517
517
  }
518
518
  };
519
- function tt(e, t, r) {
519
+ function nt(e, t, r) {
520
520
  var u, n;
521
521
  const { event: a, ...o } = e, { language: s } = ((u = t == null ? void 0 : t.avatar) == null ? void 0 : u.voice) || {};
522
522
  return {
@@ -525,13 +525,13 @@ function tt(e, t, r) {
525
525
  ...r
526
526
  };
527
527
  }
528
- function nt(e) {
528
+ function rt(e) {
529
529
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
530
530
  }
531
531
  function xe(e) {
532
532
  return e instanceof q ? e.toJson() : { kind: "UnknownError", message: qt(e) || "UnknownError" };
533
533
  }
534
- const Zt = "3.0.0-staging.426", en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", St = 50, Q = [];
534
+ const Zt = "3.0.1-staging.428", en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", St = 50, Q = [];
535
535
  let Le = !1;
536
536
  async function Ct(e) {
537
537
  const t = await fetch(en, {
@@ -545,7 +545,7 @@ async function Ct(e) {
545
545
  function tn(e) {
546
546
  Q.push(e), Q.splice(St);
547
547
  }
548
- function Oe() {
548
+ function ze() {
549
549
  if (Le || !Q.length)
550
550
  return;
551
551
  Le = !0;
@@ -556,8 +556,8 @@ function Oe() {
556
556
  Le = !1;
557
557
  });
558
558
  }
559
- typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online", Oe), typeof document < "u" && document.addEventListener("visibilitychange", () => {
560
- document.visibilityState === "visible" && Oe();
559
+ typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online", ze), typeof document < "u" && document.addEventListener("visibilitychange", () => {
560
+ document.visibilityState === "visible" && ze();
561
561
  }));
562
562
  function nn(e) {
563
563
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
@@ -595,7 +595,7 @@ function nn(e) {
595
595
  "User Agent": navigator.userAgent
596
596
  }
597
597
  };
598
- return Oe(), Ct([d]).catch(() => tn(d)), Promise.resolve();
598
+ return ze(), Ct([d]).catch(() => tn(d)), Promise.resolve();
599
599
  },
600
600
  linkTrack(a, o, s, i) {
601
601
  r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), i.includes(s) || i.push(s);
@@ -613,7 +613,7 @@ function nn(e) {
613
613
  }
614
614
  };
615
615
  }
616
- function Ue() {
616
+ function Je() {
617
617
  let e = 0;
618
618
  return {
619
619
  reset: () => e = 0,
@@ -621,7 +621,7 @@ function Ue() {
621
621
  get: (t = !1) => t ? Date.now() - e : e
622
622
  };
623
623
  }
624
- const K = Ue(), ze = Ue(), rt = Ue();
624
+ const K = Je(), Fe = Je(), at = Je();
625
625
  function Mt(e) {
626
626
  return e === L.Playground ? { headers: { [bt]: "true" } } : {};
627
627
  }
@@ -639,7 +639,7 @@ function rn(e) {
639
639
  }
640
640
  function an(e) {
641
641
  return new Promise((t, r) => {
642
- const { callbacks: a, host: o, auth: s, externalId: i } = e, { onMessage: u = null, onOpen: n = null, onClose: d = null, onError: h = null } = a || {}, f = new WebSocket(`${o}?authorization=${encodeURIComponent(gt(s, i))}`);
642
+ const { callbacks: a, host: o, auth: s, externalId: i } = e, { onMessage: u = null, onOpen: n = null, onClose: d = null, onError: h = null } = a || {}, f = new WebSocket(`${o}?authorization=${encodeURIComponent(ht(s, i))}`);
643
643
  f.onmessage = u, f.onclose = d, f.onerror = (g) => {
644
644
  console.error(g), h == null || h("Websocket failed to connect", g), r(g);
645
645
  }, f.onopen = (g) => {
@@ -656,7 +656,7 @@ async function sn(e) {
656
656
  } catch (o) {
657
657
  if (a === t)
658
658
  throw o;
659
- await ft(a * 500);
659
+ await mt(a * 500);
660
660
  }
661
661
  return r;
662
662
  }
@@ -695,8 +695,8 @@ const un = [
695
695
  k.StreamVideoDone,
696
696
  k.StreamVideoError,
697
697
  k.StreamVideoRejected
698
- ], at = [k.StreamFailed, k.StreamVideoError, k.StreamVideoRejected];
699
- function it(e) {
698
+ ], it = [k.StreamFailed, k.StreamVideoError, k.StreamVideoRejected];
699
+ function st(e) {
700
700
  if (e.answer !== void 0)
701
701
  return e.answer;
702
702
  let t = 0, r = "";
@@ -748,10 +748,10 @@ function fn(e, t, r, a, o, s, i) {
748
748
  if (e === F.Partial)
749
749
  r[g] = f;
750
750
  else {
751
- const p = it(r);
751
+ const p = st(r);
752
752
  !!(f && f.length < p.length) && (h.interrupted = !0), r.answer = f;
753
753
  }
754
- const l = it(r);
754
+ const l = st(r);
755
755
  (h.content !== l || e === F.Answer) && (h.content = l, h.parts = pe(l), o == null || o([...a.messages], e));
756
756
  }
757
757
  function mn(e, t, r, a, o) {
@@ -786,7 +786,7 @@ function mn(e, t, r, a, o) {
786
786
  } else {
787
787
  const p = k;
788
788
  if (d = d, d === p.StreamVideoCreated) {
789
- const D = tt(h, a, { mode: t.chatMode });
789
+ const D = nt(h, a, { mode: t.chatMode });
790
790
  if (e.linkTrack("agent-video", D, p.StreamVideoCreated, ["start"]), h.sentiment) {
791
791
  const S = t.messages[t.messages.length - 1];
792
792
  if ((S == null ? void 0 : S.role) === "assistant") {
@@ -796,10 +796,10 @@ function mn(e, t, r, a, o) {
796
796
  }
797
797
  }
798
798
  if (un.includes(d)) {
799
- const D = d.split("/")[1], S = tt(h, a, { mode: t.chatMode });
800
- at.includes(d) ? e.track("agent-video", { ...S, event: D }) : e.linkTrack("agent-video", { ...S, event: D }, d, ["done"]);
799
+ const D = d.split("/")[1], S = nt(h, a, { mode: t.chatMode });
800
+ it.includes(d) ? e.track("agent-video", { ...S, event: D }) : e.linkTrack("agent-video", { ...S, event: D }, d, ["done"]);
801
801
  }
802
- at.includes(d) && ((l = (g = r.callbacks).onError) == null || l.call(g, new pt(`Stream failed with event ${d}`), {
802
+ it.includes(d) && ((l = (g = r.callbacks).onError) == null || l.call(g, new pt(`Stream failed with event ${d}`), {
803
803
  streamId: (f = t.streamingManager) == null ? void 0 : f.streamId
804
804
  })), h.event === p.StreamDone && o(dn(h));
805
805
  }
@@ -937,7 +937,7 @@ function Sn(e) {
937
937
  localTs: i.timestamp
938
938
  }), u;
939
939
  }
940
- function st(e, t, r) {
940
+ function ot(e, t, r) {
941
941
  if (e.length === 0)
942
942
  return null;
943
943
  const a = e.map((n, d) => d === 0 ? r ? {
@@ -996,13 +996,13 @@ function st(e, t, r) {
996
996
  webRTCStats: {
997
997
  anomalies: o,
998
998
  avSync: Qt(() => wn(e), null),
999
- minRtt: Ze(u),
1000
- avgRtt: Qe(u),
1001
- maxRtt: et(u),
999
+ minRtt: et(u),
1000
+ avgRtt: Ze(u),
1001
+ maxRtt: tt(u),
1002
1002
  aggregateReport: yn(e[0], e[e.length - 1], s),
1003
- minJitterDelayInInterval: Ze(i),
1004
- maxJitterDelayInInterval: et(i),
1005
- avgJitterDelayInInterval: Qe(i)
1003
+ minJitterDelayInInterval: et(i),
1004
+ maxJitterDelayInInterval: tt(i),
1005
+ avgJitterDelayInInterval: Ze(i)
1006
1006
  },
1007
1007
  codec: e[0].codec,
1008
1008
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
@@ -1082,7 +1082,7 @@ function Rn(e, t, r, a, o) {
1082
1082
  if (P)
1083
1083
  n = 0, g = j - l, f = U < Mn ? ge.Strong : U > Dn && g > 1 ? ge.Weak : h, f !== h && (o == null || o(f), h = f, l += g, g = 0), d || (a == null || a(C.Start), u = i[i.length - 1], i = [], d = !0), i.push(re);
1084
1084
  else if (d && (n++, n >= Cn)) {
1085
- const ae = st(i, Ie, u);
1085
+ const ae = ot(i, Ie, u);
1086
1086
  a == null || a(C.Stop, ae ?? void 0), t() || r(), l = j, d = !1;
1087
1087
  }
1088
1088
  }
@@ -1093,7 +1093,7 @@ function Rn(e, t, r, a, o) {
1093
1093
  stop: () => {
1094
1094
  s && (clearInterval(s), s = null);
1095
1095
  },
1096
- getReport: () => st(i, Ie, u)
1096
+ getReport: () => ot(i, Ie, u)
1097
1097
  };
1098
1098
  }
1099
1099
  const En = () => {
@@ -1102,7 +1102,7 @@ const En = () => {
1102
1102
  throw new Error("RTCPeerConnection is not available in this environment");
1103
1103
  return t.bind(e);
1104
1104
  };
1105
- function ot(e) {
1105
+ function ct(e) {
1106
1106
  switch (e) {
1107
1107
  case "connected":
1108
1108
  return R.Connected;
@@ -1150,7 +1150,7 @@ function _n({
1150
1150
  }) {
1151
1151
  e === C.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(C.Start)) : e === C.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(C.Stop, o)), t === C.Start ? a == null || a(we.Talking) : t === C.Stop && (a == null || a(we.Idle));
1152
1152
  }
1153
- function ct({
1153
+ function dt({
1154
1154
  statsSignal: e,
1155
1155
  dataChannelSignal: t,
1156
1156
  onVideoStateChange: r,
@@ -1181,13 +1181,13 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1181
1181
  id: j,
1182
1182
  offer: re,
1183
1183
  ice_servers: ae,
1184
- session_id: N,
1184
+ session_id: O,
1185
1185
  fluent: ee,
1186
1186
  interrupt_enabled: ye
1187
1187
  } = await P(t, u);
1188
- if (!N)
1188
+ if (!O)
1189
1189
  throw new Error("Could not create session_id");
1190
- (fe = a.onStreamCreated) == null || fe.call(a, { streamId: j, sessionId: N, agentId: e });
1190
+ (fe = a.onStreamCreated) == null || fe.call(a, { streamId: j, sessionId: O, agentId: e });
1191
1191
  const ie = (y) => {
1192
1192
  var v;
1193
1193
  return (v = a.onError) == null ? void 0 : v.call(a, y, { streamId: j });
@@ -1202,7 +1202,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1202
1202
  () => T.getStats(),
1203
1203
  ve,
1204
1204
  se,
1205
- (y, v) => ct({
1205
+ (y, v) => dt({
1206
1206
  statsSignal: l = y,
1207
1207
  dataChannelSignal: B === H.Legacy ? g : void 0,
1208
1208
  onVideoStateChange: a.onVideoStateChange,
@@ -1226,9 +1226,9 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1226
1226
  sdpMid: y.candidate.sdpMid,
1227
1227
  sdpMLineIndex: y.candidate.sdpMLineIndex
1228
1228
  },
1229
- N,
1229
+ O,
1230
1230
  u
1231
- ) : U(j, { candidate: null }, N, u);
1231
+ ) : U(j, { candidate: null }, O, u);
1232
1232
  } catch (v) {
1233
1233
  ie(v);
1234
1234
  }
@@ -1245,7 +1245,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1245
1245
  const c = v.metadata;
1246
1246
  oe(c.videoId);
1247
1247
  }
1248
- y === k.StreamDone && oe(null), g = y === k.StreamStarted ? C.Start : C.Stop, ct({
1248
+ y === k.StreamDone && oe(null), g = y === k.StreamStarted ? C.Start : C.Stop, dt({
1249
1249
  statsSignal: B === H.Legacy ? l : void 0,
1250
1250
  dataChannelSignal: g,
1251
1251
  onVideoStateChange: a.onVideoStateChange,
@@ -1271,14 +1271,14 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1271
1271
  }, T.oniceconnectionstatechange = () => {
1272
1272
  var v;
1273
1273
  n("peerConnection.oniceconnectionstatechange => " + T.iceConnectionState);
1274
- const y = ot(T.iceConnectionState);
1274
+ const y = ct(T.iceConnectionState);
1275
1275
  y !== R.Connected && ((v = a.onConnectionStateChange) == null || v.call(a, y, `webrtc:ice-${T.iceConnectionState}`));
1276
1276
  }, T.ontrack = (y) => {
1277
1277
  var v;
1278
1278
  n("peerConnection.ontrack", y), n("CALLBACK: onSrcObjectReady"), (v = a.onSrcObjectReady) == null || v.call(a, y.streams[0]);
1279
1279
  }, await T.setRemoteDescription(re), n("set remote description OK");
1280
1280
  const ue = await T.createAnswer();
1281
- n("create answer OK"), await T.setLocalDescription(ue), n("set local description OK"), await p(j, ue, N, u), n("start connection OK");
1281
+ n("create answer OK"), await T.setLocalDescription(ue), n("set local description OK"), await p(j, ue, O, u), n("start connection OK");
1282
1282
  async function le(y, v) {
1283
1283
  if (!h || G.readyState !== "open") {
1284
1284
  n("Data channel is not ready for sending messages"), ie(new pt("Data channel is not ready for sending messages"));
@@ -1296,7 +1296,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1296
1296
  * @param payload
1297
1297
  */
1298
1298
  speak(y) {
1299
- return D(j, N, y);
1299
+ return D(j, O, y);
1300
1300
  },
1301
1301
  /**
1302
1302
  * Method to close RTC connection
@@ -1304,7 +1304,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1304
1304
  async disconnect() {
1305
1305
  var y;
1306
1306
  if (j) {
1307
- const v = ot(T.iceConnectionState);
1307
+ const v = ct(T.iceConnectionState);
1308
1308
  if (T) {
1309
1309
  if (v === R.New) {
1310
1310
  Y.stop();
@@ -1313,7 +1313,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1313
1313
  T.close(), T.oniceconnectionstatechange = null, T.onnegotiationneeded = null, T.onicecandidate = null, T.ontrack = null;
1314
1314
  }
1315
1315
  try {
1316
- v === R.Connected && await S(j, N);
1316
+ v === R.Connected && await S(j, O);
1317
1317
  } catch (c) {
1318
1318
  n("Error on close stream connection", c);
1319
1319
  }
@@ -1324,7 +1324,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
1324
1324
  /**
1325
1325
  * Session identifier information, should be returned in the body of all streaming requests
1326
1326
  */
1327
- sessionId: N,
1327
+ sessionId: O,
1328
1328
  /**
1329
1329
  * Id of current RTC stream
1330
1330
  */
@@ -1355,8 +1355,8 @@ async function Pn(e, t, r, a) {
1355
1355
  case "v2": {
1356
1356
  const { version: s, ...i } = t;
1357
1357
  switch (i.transport.provider) {
1358
- case Fe.Livekit:
1359
- const { createLiveKitStreamingManager: u } = await import("./livekit-manager-CAbeu0Rj.js");
1358
+ case Ve.Livekit:
1359
+ const { createLiveKitStreamingManager: u } = await import("./livekit-manager-DOm-nWKQ.js");
1360
1360
  return u(o, i, r);
1361
1361
  default:
1362
1362
  throw new Error(`Unsupported transport provider: ${i.transport.provider}`);
@@ -1370,7 +1370,7 @@ const bn = "cht";
1370
1370
  function xn(e) {
1371
1371
  return {
1372
1372
  transport: {
1373
- provider: Fe.Livekit
1373
+ provider: Ve.Livekit
1374
1374
  },
1375
1375
  ...(e == null ? void 0 : e.persistentChat) !== void 0 && { chat_persist: e.persistentChat }
1376
1376
  };
@@ -1388,7 +1388,7 @@ function Ln(e) {
1388
1388
  }, ...r && { end_user_data: r } };
1389
1389
  }
1390
1390
  function jn(e, t) {
1391
- return Ve(e.avatar.type) ? { version: Ee.V2, ...xn(t) } : { version: Ee.V1, ...Ln(t) };
1391
+ return Ue(e.avatar.type) ? { version: Ee.V2, ...xn(t) } : { version: Ee.V1, ...Ln(t) };
1392
1392
  }
1393
1393
  function Bn(e, t, r) {
1394
1394
  r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
@@ -1403,7 +1403,7 @@ function Nn(e, t, r, a, o) {
1403
1403
  ...r
1404
1404
  });
1405
1405
  }
1406
- function dt(e, t, r, a, o) {
1406
+ function ut(e, t, r, a, o) {
1407
1407
  e === C.Start ? r.linkTrack("agent-video", { event: "start", ...o, "stream-type": a }, "start", [
1408
1408
  k.StreamVideoCreated
1409
1409
  ]) : e === C.Stop && r.linkTrack(
@@ -1450,8 +1450,8 @@ function zn(e, t, r) {
1450
1450
  extra_keys: o.extra ? Object.keys(o.extra).length : 0
1451
1451
  });
1452
1452
  }
1453
- function ut(e, t, r, a) {
1454
- return K.reset(), rt.update(), new Promise(async (o, s) => {
1453
+ function lt(e, t, r, a) {
1454
+ return K.reset(), at.update(), new Promise(async (o, s) => {
1455
1455
  try {
1456
1456
  let i, u = !1;
1457
1457
  const n = jn(e, t);
@@ -1484,15 +1484,15 @@ function ut(e, t, r, a) {
1484
1484
  },
1485
1485
  onAgentActivityStateChange: (f) => {
1486
1486
  var g, l;
1487
- (l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f === we.Talking ? (ze.update(), d = (p) => {
1488
- dt(
1487
+ (l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f === we.Talking ? (Fe.update(), d = (p) => {
1488
+ ut(
1489
1489
  C.Start,
1490
1490
  e,
1491
1491
  r,
1492
1492
  i.streamType,
1493
1493
  p
1494
1494
  ), d = null;
1495
- }, h || d({ latency: K.get(!0) })) : (ze.reset(), d = null, dt(
1495
+ }, h || d({ latency: K.get(!0) })) : (Fe.reset(), d = null, ut(
1496
1496
  C.Stop,
1497
1497
  e,
1498
1498
  r,
@@ -1503,7 +1503,7 @@ function ut(e, t, r, a) {
1503
1503
  d == null || d(f);
1504
1504
  },
1505
1505
  onStreamReady: () => {
1506
- const f = rt.get(!0);
1506
+ const f = at.get(!0);
1507
1507
  r.track("agent-chat", { event: "ready", latency: f });
1508
1508
  },
1509
1509
  onToolEvent: ((f, g) => {
@@ -1522,8 +1522,8 @@ function ut(e, t, r, a) {
1522
1522
  async function Fn(e, t, r, a, o) {
1523
1523
  var h, f;
1524
1524
  const s = async () => {
1525
- if (Ve(e.avatar.type)) {
1526
- const g = await ut(e, t, a), l = `${bn}_${g.sessionId}`, p = (/* @__PURE__ */ new Date()).toISOString();
1525
+ if (Ue(e.avatar.type)) {
1526
+ const g = await lt(e, t, a), l = `${bn}_${g.sessionId}`, p = (/* @__PURE__ */ new Date()).toISOString();
1527
1527
  return { chatResult: {
1528
1528
  chatMode: L.Functional,
1529
1529
  chat: {
@@ -1549,7 +1549,7 @@ async function Fn(e, t, r, a, o) {
1549
1549
  t.mode,
1550
1550
  t.persistentChat,
1551
1551
  o
1552
- ), S = ut(e, t, a, l).then((j) => (p = j, j)), [P, U] = await Promise.all([D, S]);
1552
+ ), S = lt(e, t, a, l).then((j) => (p = j, j)), [P, U] = await Promise.all([D, S]);
1553
1553
  return { chatResult: P, streamingManager: U };
1554
1554
  } catch (D) {
1555
1555
  throw g.abort(), p && await p.disconnect().catch(() => {
@@ -1559,14 +1559,14 @@ async function Fn(e, t, r, a, o) {
1559
1559
  }, { chatResult: i, streamingManager: u } = await s(), { chat: n, chatMode: d } = i;
1560
1560
  return d && t.mode !== void 0 && d !== t.mode && d !== L.Functional ? ((f = (h = t.callbacks).onError) == null || f.call(h, new Bt(d)), u == null || u.disconnect(), { chat: n }) : { chat: n, streamingManager: u };
1561
1561
  }
1562
- const je = "ChatMode.Off and ChatMode.DirectPlayback are not supported for Expressive agents", lt = "callbacks.onSrcObjectReady is required in every chat mode that streams video; it is optional only in ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance", Vn = [R.Disconnected, R.Closed, R.Fail];
1562
+ const je = "ChatMode.Off and ChatMode.DirectPlayback are not supported for Expressive agents", ft = "callbacks.onSrcObjectReady is required in every chat mode that streams video; it is optional only in ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance", Vn = [R.Disconnected, R.Closed, R.Fail];
1563
1563
  async function Kn(e, t) {
1564
1564
  var ue, le, fe, y, v;
1565
1565
  const r = { ...t.callbacks };
1566
1566
  let a = !0;
1567
1567
  const o = ((ue = t.analytics) == null ? void 0 : ue.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL || ke, u = t.mode || L.Functional;
1568
1568
  if (!r.onSrcObjectReady && !Pe(u))
1569
- throw new I(lt);
1569
+ throw new I(ft);
1570
1570
  const n = {
1571
1571
  messages: [],
1572
1572
  chatMode: u
@@ -1577,7 +1577,7 @@ async function Kn(e, t) {
1577
1577
  externalId: t.externalId,
1578
1578
  mixpanelAdditionalProperties: (fe = t.analytics) == null ? void 0 : fe.additionalProperties
1579
1579
  }), h = Date.now();
1580
- nt(() => {
1580
+ rt(() => {
1581
1581
  d.track("agent-sdk", { event: "init" }, h);
1582
1582
  });
1583
1583
  let f = R.New, g;
@@ -1597,10 +1597,10 @@ async function Kn(e, t) {
1597
1597
  }
1598
1598
  }, p = { ...t, callbacks: l }, D = Ht(p.auth, i, l.onError, p.externalId), S = await D.getRuntimeById(e);
1599
1599
  p.debug = p.debug || ((y = S == null ? void 0 : S.advanced_settings) == null ? void 0 : y.ui_debug_mode);
1600
- const P = Ve(S.avatar.type);
1600
+ const P = Ue(S.avatar.type);
1601
1601
  if (P && te(u))
1602
1602
  throw new I(je);
1603
- P && import("./livekit-manager-CAbeu0Rj.js").then(({ preloadLiveKit: c }) => c()).catch(() => {
1603
+ P && import("./livekit-manager-DOm-nWKQ.js").then(({ preloadLiveKit: c }) => c()).catch(() => {
1604
1604
  }), d.enrich(Kt(S));
1605
1605
  const { onMessage: U, clearQueue: j } = mn(d, n, p, S, (c) => {
1606
1606
  var m, w;
@@ -1608,21 +1608,21 @@ async function Kn(e, t) {
1608
1608
  });
1609
1609
  n.messages = rn(p.initialMessages), n.messages.length && ((v = l.onNewMessage) == null || v.call(l, [...n.messages], "answer"));
1610
1610
  const re = (c) => d.enrich({ videoId: c }), ae = (c) => {
1611
- var O;
1611
+ var z;
1612
1612
  const m = (c == null ? void 0 : c.type) ?? "click", w = n.streamingManager;
1613
1613
  if (!(w != null && w.interruptAvailable) || !w.isInterruptible || !w.interrupt(m))
1614
1614
  return;
1615
1615
  d.track("agent-video-interrupt", {
1616
1616
  type: m,
1617
- video_duration_to_interrupt: ze.get(!0),
1617
+ video_duration_to_interrupt: Fe.get(!0),
1618
1618
  message_duration_to_interrupt: K.get(!0)
1619
1619
  });
1620
1620
  const E = n.messages[n.messages.length - 1];
1621
- E && (E.interrupted = !0, (O = l.onNewMessage) == null || O.call(l, [...n.messages], "answer"));
1622
- }, N = /* @__PURE__ */ new Map();
1621
+ E && (E.interrupted = !0, (z = l.onNewMessage) == null || z.call(l, [...n.messages], "answer"));
1622
+ }, O = /* @__PURE__ */ new Map();
1623
1623
  function ee(c) {
1624
1624
  return async (m) => {
1625
- const w = N.get(c);
1625
+ const w = O.get(c);
1626
1626
  if (!w)
1627
1627
  throw new Error(`No handler registered for client tool: ${c}`);
1628
1628
  const M = JSON.parse(m.payload);
@@ -1631,22 +1631,22 @@ async function Kn(e, t) {
1631
1631
  }
1632
1632
  function ye() {
1633
1633
  var c, m, w, M;
1634
- for (const [E] of N)
1634
+ for (const [E] of O)
1635
1635
  (m = (c = n.streamingManager) == null ? void 0 : c.unregisterRpcMethod) == null || m.call(c, E), (M = (w = n.streamingManager) == null ? void 0 : w.registerRpcMethod) == null || M.call(w, E, ee(E));
1636
1636
  }
1637
1637
  function ie(c, m) {
1638
1638
  var M, E;
1639
1639
  if (!P)
1640
1640
  throw new I("registerClientTool is only available on Expressive (V4) agents");
1641
- const w = !N.has(c);
1642
- N.set(c, m), w && ((E = (M = n.streamingManager) == null ? void 0 : M.registerRpcMethod) == null || E.call(M, c, ee(c)));
1641
+ const w = !O.has(c);
1642
+ O.set(c, m), w && ((E = (M = n.streamingManager) == null ? void 0 : M.registerRpcMethod) == null || E.call(M, c, ee(c)));
1643
1643
  }
1644
1644
  function T(c) {
1645
1645
  var m, w;
1646
- N.delete(c), (w = (m = n.streamingManager) == null ? void 0 : m.unregisterRpcMethod) == null || w.call(m, c);
1646
+ O.delete(c), (w = (m = n.streamingManager) == null ? void 0 : m.unregisterRpcMethod) == null || w.call(m, c);
1647
1647
  }
1648
1648
  const G = Date.now();
1649
- nt(() => {
1649
+ rt(() => {
1650
1650
  d.track("agent-sdk", { event: "loaded", ...Wt(S) }, G);
1651
1651
  });
1652
1652
  let B, X = !1;
@@ -1668,7 +1668,7 @@ async function Kn(e, t) {
1668
1668
  s,
1669
1669
  { onMessage: U, onError: l.onError },
1670
1670
  p.externalId
1671
- ) : Promise.resolve(void 0), w = Ne(
1671
+ ) : Promise.resolve(void 0), w = Oe(
1672
1672
  () => Fn(
1673
1673
  S,
1674
1674
  {
@@ -1679,7 +1679,7 @@ async function Kn(e, t) {
1679
1679
  onVideoIdChange: re,
1680
1680
  onMessage: U
1681
1681
  },
1682
- rpcMethods: new Map([...N.keys()].map((z) => [z, ee(z)]))
1682
+ rpcMethods: new Map([...O.keys()].map((N) => [N, ee(N)]))
1683
1683
  },
1684
1684
  D,
1685
1685
  d,
@@ -1689,21 +1689,21 @@ async function Kn(e, t) {
1689
1689
  limit: 3,
1690
1690
  timeout: Pt,
1691
1691
  timeoutErrorMessage: "Timeout initializing the stream",
1692
- shouldRetryFn: (z) => !(z instanceof ht && (z.status === 429 || z.code === "InsufficientCreditsError")),
1692
+ shouldRetryFn: (N) => !(N instanceof Ne && (N.status === 429 || N.code === "InsufficientCreditsError" || N.code === "AgentUpgradingError")),
1693
1693
  delayMs: 1e3
1694
1694
  }
1695
- ).catch(async (z) => {
1695
+ ).catch(async (N) => {
1696
1696
  var Ce;
1697
1697
  throw m.then((W) => W == null ? void 0 : W.disconnect()).catch(() => {
1698
- }), await ce(L.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, R.Fail), z;
1699
- }), M = (_e = n.chat) == null ? void 0 : _e.id, [E, { streamingManager: O, chat: _ }] = await Promise.all([m, w]), b = !!_ && _.id !== M;
1700
- if (_ && b && (($ = l.onNewChat) == null || $.call(l, _.id)), n.streamingManager = O, n.socketManager = E, n.chat = _, X) {
1698
+ }), N instanceof Ne && N.code === "AgentUpgradingError" || await ce(L.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, R.Fail), N;
1699
+ }), M = (_e = n.chat) == null ? void 0 : _e.id, [E, { streamingManager: z, chat: _ }] = await Promise.all([m, w]), b = !!_ && _.id !== M;
1700
+ if (_ && b && (($ = l.onNewChat) == null || $.call(l, _.id)), n.streamingManager = z, n.socketManager = E, n.chat = _, X) {
1701
1701
  await V();
1702
1702
  return;
1703
1703
  }
1704
1704
  ye(), a = !1, d.enrich({
1705
1705
  chatId: _ == null ? void 0 : _.id,
1706
- streamId: O == null ? void 0 : O.streamId,
1706
+ streamId: z == null ? void 0 : z.streamId,
1707
1707
  mode: n.chatMode
1708
1708
  });
1709
1709
  const A = (b ? _ == null ? void 0 : _.chat_mode : void 0) ?? n.chatMode;
@@ -1758,7 +1758,7 @@ async function Kn(e, t) {
1758
1758
  enrichAnalytics: (c) => d.enrich(c),
1759
1759
  async connect() {
1760
1760
  if (!l.onSrcObjectReady && !Pe(n.chatMode))
1761
- throw new I(lt);
1761
+ throw new I(ft);
1762
1762
  if (B)
1763
1763
  return X = !1, B;
1764
1764
  if (n.streamingManager && !Vn.includes(f))
@@ -1847,12 +1847,12 @@ async function Kn(e, t) {
1847
1847
  return (c = n.streamingManager) != null && c.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
1848
1848
  },
1849
1849
  async chat(c) {
1850
- var E, O, _;
1850
+ var E, z, _;
1851
1851
  const m = () => {
1852
1852
  if (te(n.chatMode))
1853
1853
  throw new I(`${n.chatMode} is enabled, chat is disabled`);
1854
- if (c.length >= He)
1855
- throw new I(`Message cannot be more than ${He} characters`);
1854
+ if (c.length >= We)
1855
+ throw new I(`Message cannot be more than ${We} characters`);
1856
1856
  if (c.length === 0)
1857
1857
  throw new I("Message cannot be empty");
1858
1858
  if (n.chatMode === L.Maintenance)
@@ -1880,21 +1880,21 @@ async function Kn(e, t) {
1880
1880
  return n.chat.id;
1881
1881
  }, M = async (b, A) => {
1882
1882
  const J = n.chatMode === L.Playground;
1883
- return Ne(P && !J ? async () => {
1883
+ return Oe(P && !J ? async () => {
1884
1884
  var $;
1885
1885
  return await (($ = n.streamingManager) == null ? void 0 : $.sendDataChannelMessage(
1886
1886
  Re.Chat,
1887
1887
  c
1888
1888
  )), Promise.resolve({});
1889
1889
  } : async () => {
1890
- var $, z;
1890
+ var $, N;
1891
1891
  return D.chat(
1892
1892
  S.id,
1893
1893
  A,
1894
1894
  {
1895
1895
  chatMode: n.chatMode,
1896
1896
  streamId: ($ = n.streamingManager) == null ? void 0 : $.streamId,
1897
- sessionId: (z = n.streamingManager) == null ? void 0 : z.sessionId,
1897
+ sessionId: (N = n.streamingManager) == null ? void 0 : N.sessionId,
1898
1898
  messages: b.map(({ matches: Ce, createdAt: W, ...Me }) => ({
1899
1899
  ...Me,
1900
1900
  // A restored `initialMessages` row may carry no timestamp; the API requires one.
@@ -1909,9 +1909,9 @@ async function Kn(e, t) {
1909
1909
  }, {
1910
1910
  limit: 2,
1911
1911
  shouldRetryFn: ($) => {
1912
- var W, Me, Je;
1913
- const z = (W = $ == null ? void 0 : $.message) == null ? void 0 : W.includes("missing or invalid session_id");
1914
- return !((Me = $ == null ? void 0 : $.message) == null ? void 0 : Me.includes("Stream Error")) && !z ? ((Je = l.onError) == null || Je.call(l, $), !1) : !0;
1912
+ var W, Me, He;
1913
+ const N = (W = $ == null ? void 0 : $.message) == null ? void 0 : W.includes("missing or invalid session_id");
1914
+ return !((Me = $ == null ? void 0 : $.message) == null ? void 0 : Me.includes("Stream Error")) && !N ? ((He = l.onError) == null || He.call(l, $), !1) : !0;
1915
1915
  },
1916
1916
  onRetry: async () => {
1917
1917
  await V(), await se(!1);
@@ -1938,7 +1938,7 @@ async function Kn(e, t) {
1938
1938
  }), d.track("agent-message-send", {
1939
1939
  event: "success",
1940
1940
  messages: n.messages.length + 1
1941
- }), A.result && ((O = l.onNewMessage) == null || O.call(l, [...n.messages], "answer"), d.track("agent-message-received", {
1941
+ }), A.result && ((z = l.onNewMessage) == null || z.call(l, [...n.messages], "answer"), d.track("agent-message-received", {
1942
1942
  latency: K.get(!0),
1943
1943
  messages: n.messages.length
1944
1944
  })), A;
@@ -1951,13 +1951,13 @@ async function Kn(e, t) {
1951
1951
  }
1952
1952
  },
1953
1953
  async rate(c, m, w) {
1954
- var O, _, b, A;
1954
+ var z, _, b, A;
1955
1955
  const M = n.messages.find((J) => J.id === c);
1956
1956
  if (n.chat) {
1957
1957
  if (!M)
1958
1958
  throw new I("Message not found");
1959
1959
  } else throw new I("Chat is not initialized");
1960
- const E = ((O = M.matches) == null ? void 0 : O.map((J) => [J.document_id, J.id])) ?? [];
1960
+ const E = ((z = M.matches) == null ? void 0 : z.map((J) => [J.document_id, J.id])) ?? [];
1961
1961
  return d.track("agent-rate", {
1962
1962
  event: w ? "update" : "create",
1963
1963
  thumb: m === 1 ? "up" : "down",
@@ -2031,7 +2031,7 @@ export {
2031
2031
  q as B,
2032
2032
  F as C,
2033
2033
  kt as D,
2034
- ht as H,
2034
+ Ne as H,
2035
2035
  Re as I,
2036
2036
  Nt as N,
2037
2037
  Tt as P,
@@ -2063,4 +2063,4 @@ export {
2063
2063
  Hn as v,
2064
2064
  yt as w
2065
2065
  };
2066
- //# sourceMappingURL=index-D_aN1Y2k.js.map
2066
+ //# sourceMappingURL=index-BZ_8x5zH.js.map