@d-id/client-sdk 1.1.36-staging.174 → 1.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- var Ge = Object.defineProperty;
2
- var Ze = (e, t, i) => t in e ? Ge(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var he = (e, t, i) => Ze(e, typeof t != "symbol" ? t + "" : t, i);
1
+ var Ze = Object.defineProperty;
2
+ var et = (e, t, i) => t in e ? Ze(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
+ var ge = (e, t, i) => et(e, typeof t != "symbol" ? t + "" : t, i);
4
4
  class Se extends Error {
5
5
  constructor({ kind: i, description: n, error: s }) {
6
6
  super(JSON.stringify({ kind: i, description: n }));
7
- he(this, "kind");
8
- he(this, "description");
9
- he(this, "error");
7
+ ge(this, "kind");
8
+ ge(this, "description");
9
+ ge(this, "error");
10
10
  this.kind = i, this.description = n, this.error = s;
11
11
  }
12
12
  }
13
- class et extends Se {
13
+ class tt extends Se {
14
14
  constructor(t, i) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -18,7 +18,7 @@ class et extends Se {
18
18
  });
19
19
  }
20
20
  }
21
- class tt extends Se {
21
+ class nt extends Se {
22
22
  constructor(t) {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
24
24
  }
@@ -26,16 +26,16 @@ class tt extends Se {
26
26
  class le extends Se {
27
27
  constructor(i, n) {
28
28
  super({ kind: "ValidationError", description: i });
29
- he(this, "key");
29
+ ge(this, "key");
30
30
  this.key = n;
31
31
  }
32
32
  }
33
- class nt extends Se {
33
+ class rt extends Se {
34
34
  constructor(t) {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var rt = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(rt || {}), it = /* @__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))(it || {}), at = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(at || {}), ot = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ot || {}), B = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(B || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), st = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(st || {}), ct = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ct || {}), dt = /* @__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))(dt || {}), Ue = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ue || {});
38
+ var it = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(it || {}), at = /* @__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))(at || {}), ot = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ot || {}), st = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(st || {}), B = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(B || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), ct = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(dt || {}), ut = /* @__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))(ut || {}), Ve = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ve || {});
39
39
  const pn = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
@@ -48,13 +48,13 @@ const pn = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var M = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(M || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(W || {}), L = /* @__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))(L || {}), I = /* @__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))(I || {}), ie = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ie || {}), ke = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ke || {}), ut = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ut || {}), lt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(lt || {});
52
- const ft = 45 * 1e3, mt = "X-Playground-Chat", we = "https://api.d-id.com", gt = "wss://notifications.d-id.com", ht = "79f81a83a67430be2bc0fd61042b8faa", pt = (...e) => {
53
- }, Ve = (e) => new Promise((t) => setTimeout(t, e)), fe = (e = 16) => {
51
+ var E = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(E || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), V = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(V || {}), L = /* @__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))(L || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), ie = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ie || {}), ke = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ke || {}), lt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(lt || {}), mt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(mt || {});
52
+ const ft = 45 * 1e3, gt = "X-Playground-Chat", pe = "https://api.d-id.com", ht = "wss://notifications.d-id.com", pt = "79f81a83a67430be2bc0fd61042b8faa", wt = (...e) => {
53
+ }, We = (e) => new Promise((t) => setTimeout(t, e)), me = (e = 16) => {
54
54
  const t = new Uint8Array(e);
55
55
  return window.crypto.getRandomValues(t), Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
56
- }, We = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Pe = (e) => e === Ue.Expressive, wt = (e) => [B.TextOnly, B.Playground, B.Maintenance].includes(e), Oe = (e) => e && [B.DirectPlayback, B.Off].includes(e);
57
- function yt(e, t) {
56
+ }, Oe = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Pe = (e) => e === Ve.Expressive, yt = (e) => [B.TextOnly, B.Playground, B.Maintenance].includes(e), He = (e) => e && [B.DirectPlayback, B.Off].includes(e);
57
+ function vt(e, t) {
58
58
  let i;
59
59
  return {
60
60
  promise: new Promise((s, o) => {
@@ -78,12 +78,12 @@ async function Ee(e, t) {
78
78
  try {
79
79
  if (!i.timeout)
80
80
  return await e();
81
- const { promise: o, clear: c } = yt(i.timeout, i.timeoutErrorMessage), a = e().finally(c);
81
+ const { promise: o, clear: c } = vt(i.timeout, i.timeoutErrorMessage), a = e().finally(c);
82
82
  return await Promise.race([a, o]);
83
83
  } catch (o) {
84
84
  if (n = o, !i.shouldRetryFn(o) || s >= i.limit)
85
85
  throw o;
86
- await Ve(i.delayMs), i.onRetry(o);
86
+ await We(i.delayMs), i.onRetry(o);
87
87
  }
88
88
  throw n;
89
89
  }
@@ -92,35 +92,35 @@ function Ie(e) {
92
92
  return window.localStorage.setItem("did_external_key_id", e), e;
93
93
  let t = window.localStorage.getItem("did_external_key_id");
94
94
  if (!t) {
95
- let i = fe();
95
+ let i = me();
96
96
  window.localStorage.setItem("did_external_key_id", i), t = i;
97
97
  }
98
98
  return t;
99
99
  }
100
- let vt = fe();
101
- function He(e, t) {
100
+ let Ct = me();
101
+ function qe(e, t) {
102
102
  if (e.type === "bearer")
103
103
  return `Bearer ${e.token}`;
104
104
  if (e.type === "basic")
105
105
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
106
106
  if (e.type === "key")
107
- return `Client-Key ${e.clientKey}.${Ie(t)}_${vt}`;
107
+ return `Client-Key ${e.clientKey}.${Ie(t)}_${Ct}`;
108
108
  throw new Error(`Unknown auth type: ${e}`);
109
109
  }
110
- const Ct = (e) => Ee(e, {
110
+ const St = (e) => Ee(e, {
111
111
  limit: 3,
112
112
  delayMs: 1e3,
113
113
  timeout: 0,
114
114
  shouldRetryFn: (t) => t.status === 429
115
115
  });
116
- function Le(e, t = we, i, n) {
116
+ function Le(e, t = pe, i, n) {
117
117
  const s = async (o, c) => {
118
- const { skipErrorHandler: a, ...r } = c || {}, d = await Ct(
118
+ const { skipErrorHandler: a, ...r } = c || {}, d = await St(
119
119
  () => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
120
120
  ...r,
121
121
  headers: {
122
122
  ...r.headers,
123
- Authorization: He(e, n),
123
+ Authorization: qe(e, n),
124
124
  "Content-Type": "application/json"
125
125
  }
126
126
  })
@@ -147,7 +147,7 @@ function Le(e, t = we, i, n) {
147
147
  }
148
148
  };
149
149
  }
150
- function St(e, t = we, i, n) {
150
+ function kt(e, t = pe, i, n) {
151
151
  const s = Le(e, `${t}/agents`, i, n);
152
152
  return {
153
153
  create(o, c) {
@@ -185,7 +185,7 @@ function St(e, t = we, i, n) {
185
185
  }
186
186
  };
187
187
  }
188
- function kt(e) {
188
+ function Rt(e) {
189
189
  var s, o, c, a;
190
190
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
191
191
  const r = navigator.platform;
@@ -196,18 +196,18 @@ function kt(e) {
196
196
  isMobile: `${t() == "Mobile"}`,
197
197
  browser: navigator.userAgent,
198
198
  origin: window.location.origin,
199
- agentType: We(n),
199
+ agentType: Oe(n),
200
200
  agentVoice: {
201
201
  voiceId: (o = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : o.voice_id,
202
202
  provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
203
203
  }
204
204
  };
205
205
  }
206
- function Rt(e) {
206
+ function Dt(e) {
207
207
  var i, n, s, o, c, a;
208
208
  const t = (i = e.llm) == null ? void 0 : i.prompt_customization;
209
209
  return {
210
- agentType: We(e.presenter),
210
+ agentType: Oe(e.presenter),
211
211
  owner_id: e.owner_id ?? "",
212
212
  promptVersion: (n = e.llm) == null ? void 0 : n.prompt_version,
213
213
  behavior: {
@@ -226,8 +226,8 @@ function Rt(e) {
226
226
  ...e.access === "public" ? { from: "agent-template" } : {}
227
227
  };
228
228
  }
229
- const Dt = (e) => e.reduce((t, i) => t + i, 0), Be = (e) => Dt(e) / e.length;
230
- function Mt(e, t, i) {
229
+ const Mt = (e) => e.reduce((t, i) => t + i, 0), xe = (e) => Mt(e) / e.length;
230
+ function Et(e, t, i) {
231
231
  var r, d, h;
232
232
  const { event: n, ...s } = e, { template: o } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((r = t == null ? void 0 : t.presenter) == null ? void 0 : r.voice) || {};
233
233
  return {
@@ -238,12 +238,12 @@ function Mt(e, t, i) {
238
238
  ...i
239
239
  };
240
240
  }
241
- function xe(e) {
241
+ function Fe(e) {
242
242
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
243
243
  }
244
244
  let De = {};
245
- const Et = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
246
- function It(e) {
245
+ const It = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
246
+ function Tt(e) {
247
247
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
248
248
  return {
249
249
  token: e.token || "testKey",
@@ -254,7 +254,7 @@ function It(e) {
254
254
  ...e.mixpanelAdditionalProperties || {}
255
255
  },
256
256
  isEnabled: e.isEnabled ?? !0,
257
- getRandom: fe,
257
+ getRandom: me,
258
258
  enrich(i) {
259
259
  this.additionalProperties = { ...this.additionalProperties, ...i };
260
260
  },
@@ -287,7 +287,7 @@ function It(e) {
287
287
  ])
288
288
  })
289
289
  };
290
- return fetch(Et, {
290
+ return fetch(It, {
291
291
  ...r,
292
292
  keepalive: !0
293
293
  }).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
@@ -316,22 +316,22 @@ function be() {
316
316
  get: (t = !1) => t ? Date.now() - e : e
317
317
  };
318
318
  }
319
- const ne = be(), Te = be(), Fe = be();
320
- function qe(e) {
321
- return e === B.Playground ? { headers: { [mt]: "true" } } : {};
319
+ const ne = be(), Te = be(), ze = be();
320
+ function Qe(e) {
321
+ return e === B.Playground ? { headers: { [gt]: "true" } } : {};
322
322
  }
323
- async function Qe(e, t, i, n, s = !1, o) {
323
+ async function Xe(e, t, i, n, s = !1, o) {
324
324
  try {
325
- return !o && !Oe(n) && (o = await t.newChat(e.id, { persist: s }, qe(n)), i.track("agent-chat", {
325
+ return !o && !He(n) && (o = await t.newChat(e.id, { persist: s }, Qe(n)), i.track("agent-chat", {
326
326
  event: "created",
327
327
  chatId: o.id,
328
328
  mode: n
329
329
  })), { chat: o, chatMode: (o == null ? void 0 : o.chat_mode) ?? n };
330
330
  } catch (c) {
331
- throw Tt(c) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
331
+ throw _t(c) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
332
332
  }
333
333
  }
334
- const Tt = (e) => {
334
+ const _t = (e) => {
335
335
  try {
336
336
  const t = JSON.parse(e.message);
337
337
  return t == null ? void 0 : t.kind;
@@ -339,10 +339,10 @@ const Tt = (e) => {
339
339
  return "UnknownError";
340
340
  }
341
341
  };
342
- function _t(e) {
342
+ function At(e) {
343
343
  return e && e.length > 0 ? e : [];
344
344
  }
345
- function At(e, t, i, n) {
345
+ function Pt(e, t, i, n) {
346
346
  const s = Le(e, `${t}/v2/agents/${i}`, n);
347
347
  return {
348
348
  async createStream(o) {
@@ -350,8 +350,8 @@ function At(e, t, i, n) {
350
350
  }
351
351
  };
352
352
  }
353
- const Xe = (e, t) => (i, n) => e && console.log(`[${t}] ${i}`, n ?? "");
354
- function Pt(e, t, i) {
353
+ const Ye = (e, t) => (i, n) => e && console.log(`[${t}] ${i}`, n ?? "");
354
+ function Lt(e, t, i) {
355
355
  const n = (t.timestamp - e.timestamp) / 1e3;
356
356
  return {
357
357
  duration: n,
@@ -371,7 +371,7 @@ function Pt(e, t, i) {
371
371
  lowFpsCount: i
372
372
  };
373
373
  }
374
- function Lt(e) {
374
+ function bt(e) {
375
375
  return e.filter(
376
376
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
377
377
  ).map((t) => {
@@ -382,7 +382,7 @@ function Lt(e) {
382
382
  };
383
383
  });
384
384
  }
385
- function bt(e) {
385
+ function jt(e) {
386
386
  let t = "", i = 0;
387
387
  for (const n of e.values()) {
388
388
  if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair") {
@@ -412,7 +412,7 @@ function bt(e) {
412
412
  }
413
413
  return {};
414
414
  }
415
- function ze(e, t, i) {
415
+ function Ke(e, t, i) {
416
416
  const n = e.map((r, d) => d === 0 ? i ? {
417
417
  timestamp: r.timestamp,
418
418
  duration: 0,
@@ -464,24 +464,24 @@ function ze(e, t, i) {
464
464
  framesPerSecond: r.framesPerSecond,
465
465
  freezeCount: r.freezeCount - e[d - 1].freezeCount,
466
466
  freezeDuration: r.freezeDuration - e[d - 1].freezeDuration
467
- }), s = Lt(n), o = s.reduce((r, d) => r + (d.causes.includes("low fps") ? 1 : 0), 0), c = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), a = n.filter((r) => !!r.rtt).map((r) => r.rtt);
467
+ }), s = bt(n), o = s.reduce((r, d) => r + (d.causes.includes("low fps") ? 1 : 0), 0), c = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), a = n.filter((r) => !!r.rtt).map((r) => r.rtt);
468
468
  return {
469
469
  webRTCStats: {
470
470
  anomalies: s,
471
471
  minRtt: Math.min(...a),
472
- avgRtt: Be(a),
472
+ avgRtt: xe(a),
473
473
  maxRtt: Math.max(...a),
474
- aggregateReport: Pt(e[0], e[e.length - 1], o),
474
+ aggregateReport: Lt(e[0], e[e.length - 1], o),
475
475
  minJitterDelayInInterval: Math.min(...c),
476
476
  maxJitterDelayInInterval: Math.max(...c),
477
- avgJitterDelayInInterval: Be(c)
477
+ avgJitterDelayInInterval: xe(c)
478
478
  },
479
479
  codec: e[0].codec,
480
480
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
481
481
  };
482
482
  }
483
- const Ce = 100, jt = Math.max(Math.ceil(400 / Ce), 1), $t = 0.25, Bt = 0.28;
484
- function xt() {
483
+ const Ce = 100, $t = Math.max(Math.ceil(400 / Ce), 1), Bt = 0.25, xt = 0.28;
484
+ function Ft() {
485
485
  let e = 0, t, i, n = 0;
486
486
  return (s) => {
487
487
  for (const o of s.values())
@@ -498,19 +498,19 @@ function xt() {
498
498
  return { isReceiving: !1, avgJitterDelayInInterval: n };
499
499
  };
500
500
  }
501
- function Ye(e, t, i, n, s) {
501
+ function Ge(e, t, i, n, s) {
502
502
  let o = null, c = [], a, r = 0, d = !1, h = re.Unknown, w = re.Unknown, u = 0, v = 0;
503
- const x = xt();
503
+ const x = Ft();
504
504
  async function b() {
505
505
  const C = await e();
506
506
  if (!C)
507
507
  return;
508
- const { isReceiving: R, avgJitterDelayInInterval: F, freezeCount: S } = x(C), O = bt(C);
508
+ const { isReceiving: R, avgJitterDelayInInterval: F, freezeCount: S } = x(C), W = jt(C);
509
509
  if (R)
510
- r = 0, u = S - v, w = F < $t ? re.Strong : F > Bt && u > 1 ? re.Weak : h, w !== h && (s == null || s(w), h = w, v += u, u = 0), d || (n == null || n(M.Start), a = c[c.length - 1], c = [], d = !0), c.push(O);
511
- else if (d && (r++, r >= jt)) {
512
- const J = ze(c, Ce, a);
513
- n == null || n(M.Stop, J), t() || i(), v = S, d = !1;
510
+ r = 0, u = S - v, w = F < Bt ? re.Strong : F > xt && u > 1 ? re.Weak : h, w !== h && (s == null || s(w), h = w, v += u, u = 0), d || (n == null || n(E.Start), a = c[c.length - 1], c = [], d = !0), c.push(W);
511
+ else if (d && (r++, r >= $t)) {
512
+ const J = Ke(c, Ce, a);
513
+ n == null || n(E.Stop, J), t() || i(), v = S, d = !1;
514
514
  }
515
515
  }
516
516
  return {
@@ -520,7 +520,7 @@ function Ye(e, t, i, n, s) {
520
520
  stop: () => {
521
521
  o && (clearInterval(o), o = null);
522
522
  },
523
- getReport: () => ze(c, Ce, a)
523
+ getReport: () => Ke(c, Ce, a)
524
524
  };
525
525
  }
526
526
  async function Me() {
@@ -532,24 +532,24 @@ async function Me() {
532
532
  );
533
533
  }
534
534
  }
535
- const Ft = {
535
+ const zt = {
536
536
  excellent: re.Strong,
537
537
  good: re.Strong,
538
538
  poor: re.Weak,
539
539
  lost: re.Unknown,
540
540
  unknown: re.Unknown
541
- }, pe = JSON.stringify({
541
+ }, he = JSON.stringify({
542
542
  kind: "InternalServerError",
543
543
  description: "Stream Error"
544
544
  });
545
545
  var je = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(je || {});
546
546
  function _e(e, t, i) {
547
547
  var n, s;
548
- throw t("Failed to connect to LiveKit room:", e), (n = i.onConnectionStateChange) == null || n.call(i, I.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
548
+ throw t("Failed to connect to LiveKit room:", e), (n = i.onConnectionStateChange) == null || n.call(i, I.Fail), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
549
549
  }
550
- async function zt(e, t, i) {
551
- var me;
552
- const n = Xe(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: o, ConnectionState: c } = await Me(), { callbacks: a, auth: r, baseURL: d, analytics: h, microphoneStream: w } = i;
550
+ async function Kt(e, t, i) {
551
+ var $e;
552
+ const n = Ye(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: o, ConnectionState: c } = await Me(), { callbacks: a, auth: r, baseURL: d, analytics: h, microphoneStream: w } = i;
553
553
  let u = null, v = !1;
554
554
  const x = ie.Fluent;
555
555
  let b = null, C = null, R = null, F = !1;
@@ -559,276 +559,279 @@ async function zt(e, t, i) {
559
559
  dynacast: !0
560
560
  });
561
561
  let S = null;
562
- const O = 2e4;
563
- let J = W.Idle;
564
- const H = At(r, d || we, e, a.onError);
562
+ const W = 2e4;
563
+ let J = V.Idle;
564
+ const O = Pt(r, d || pe, e, a.onError);
565
565
  let z, ee, te;
566
566
  try {
567
- const f = await H.createStream({
567
+ const m = await O.createStream({
568
568
  transport_provider: ke.Livekit,
569
569
  chat_persist: t.chat_persist ?? !0
570
- }), { id: g, session_token: y, session_url: _ } = f;
571
- (me = a.onStreamCreated) == null || me.call(a, { session_id: g, stream_id: g, agent_id: e }), z = g, ee = y, te = _, await u.prepareConnection(te, ee);
572
- } catch (f) {
573
- _e(f, n, a);
570
+ }), { id: g, session_token: y, session_url: _ } = m;
571
+ ($e = a.onStreamCreated) == null || $e.call(a, { session_id: g, stream_id: g, agent_id: e }), z = g, ee = y, te = _, await u.prepareConnection(te, ee);
572
+ } catch (m) {
573
+ _e(m, n, a);
574
574
  }
575
575
  if (!te || !ee || !z)
576
576
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
577
- u.on(o.ConnectionStateChanged, D).on(o.ConnectionQualityChanged, k).on(o.ParticipantConnected, K).on(o.ParticipantDisconnected, P).on(o.TrackSubscribed, T).on(o.TrackUnsubscribed, N).on(o.DataReceived, q).on(o.MediaDevicesError, Q).on(o.TranscriptionReceived, l).on(o.EncryptionError, j).on(o.TrackSubscriptionFailed, $);
578
- function l(f, g) {
577
+ u.on(o.ConnectionStateChanged, D).on(o.ConnectionQualityChanged, k).on(o.ActiveSpeakersChanged, K).on(o.ParticipantConnected, P).on(o.ParticipantDisconnected, T).on(o.TrackSubscribed, N).on(o.TrackUnsubscribed, H).on(o.DataReceived, q).on(o.MediaDevicesError, j).on(o.TranscriptionReceived, l).on(o.EncryptionError, $).on(o.TrackSubscriptionFailed, Y);
578
+ function l(m, g) {
579
579
  var y;
580
- g != null && g.isLocal && (ne.update(), J === W.Talking && ((y = a.onInterruptDetected) == null || y.call(a, { type: "audio" }), J = W.Idle));
580
+ g != null && g.isLocal && (ne.update(), J === V.Talking && ((y = a.onInterruptDetected) == null || y.call(a, { type: "audio" }), J = V.Idle));
581
581
  }
582
582
  try {
583
583
  await u.connect(te, ee), n("LiveKit room joined successfully"), S = setTimeout(() => {
584
- var f;
584
+ var m;
585
585
  n("Track subscription timeout - no track subscribed within 30 seconds after connect"), S = null, h.track("connectivity-error", {
586
586
  error: "Track subscription timeout",
587
587
  sessionId: z
588
- }), (f = a.onError) == null || f.call(a, new Error("Track subscription timeout"), { sessionId: z }), de("internal:track-subscription-timeout");
589
- }, O);
590
- } catch (f) {
591
- _e(f, n, a);
588
+ }), (m = a.onError) == null || m.call(a, new Error("Track subscription timeout"), { sessionId: z }), de();
589
+ }, W);
590
+ } catch (m) {
591
+ _e(m, n, a);
592
592
  }
593
593
  h.enrich({
594
594
  "stream-type": x
595
595
  });
596
- function D(f) {
596
+ function D(m) {
597
597
  var g, y, _, A;
598
- switch (n("Connection state changed:", f), f) {
598
+ switch (n("Connection state changed:", m), m) {
599
599
  case c.Connecting:
600
- n("CALLBACK: onConnectionStateChange(Connecting)"), (g = a.onConnectionStateChange) == null || g.call(a, I.Connecting, "livekit:connecting");
600
+ n("CALLBACK: onConnectionStateChange(Connecting)"), (g = a.onConnectionStateChange) == null || g.call(a, I.Connecting);
601
601
  break;
602
602
  case c.Connected:
603
603
  n("LiveKit room connected successfully"), v = !0;
604
604
  break;
605
605
  case c.Disconnected:
606
- n("LiveKit room disconnected"), v = !1, F = !1, (y = a.onConnectionStateChange) == null || y.call(a, I.Disconnected, "livekit:disconnected");
606
+ n("LiveKit room disconnected"), v = !1, F = !1, (y = a.onConnectionStateChange) == null || y.call(a, I.Disconnected);
607
607
  break;
608
608
  case c.Reconnecting:
609
- n("LiveKit room reconnecting..."), (_ = a.onConnectionStateChange) == null || _.call(a, I.Connecting, "livekit:reconnecting");
609
+ n("LiveKit room reconnecting..."), (_ = a.onConnectionStateChange) == null || _.call(a, I.Connecting);
610
610
  break;
611
611
  case c.SignalReconnecting:
612
- n("LiveKit room signal reconnecting..."), (A = a.onConnectionStateChange) == null || A.call(a, I.Connecting, "livekit:signal-reconnecting");
612
+ n("LiveKit room signal reconnecting..."), (A = a.onConnectionStateChange) == null || A.call(a, I.Connecting);
613
613
  break;
614
614
  }
615
615
  }
616
- function k(f, g) {
616
+ function k(m, g) {
617
617
  var y;
618
- n("Connection quality:", f), g != null && g.isLocal && ((y = a.onConnectivityStateChange) == null || y.call(a, Ft[f]));
618
+ n("Connection quality:", m), g != null && g.isLocal && ((y = a.onConnectivityStateChange) == null || y.call(a, zt[m]));
619
+ }
620
+ function K(m) {
621
+ n("Active speakers changed:", m);
619
622
  }
620
- function K(f) {
621
- n("Participant connected:", f.identity);
623
+ function P(m) {
624
+ n("Participant connected:", m.identity);
622
625
  }
623
- function P(f) {
624
- n("Participant disconnected:", f.identity), de("livekit:participant-disconnected");
626
+ function T(m) {
627
+ n("Participant disconnected:", m.identity), de();
625
628
  }
626
- function T(f, g, y) {
627
- var A, X, Z, se;
628
- n(`Track subscribed: ${f.kind} from ${y.identity}`), S && (clearTimeout(S), S = null, n("Track subscription timeout cleared"));
629
- const _ = f.mediaStreamTrack;
629
+ function N(m, g, y) {
630
+ var A, Q, Z, ce;
631
+ n(`Track subscribed: ${m.kind} from ${y.identity}`), S && (clearTimeout(S), S = null, n("Track subscription timeout cleared"));
632
+ const _ = m.mediaStreamTrack;
630
633
  if (!_) {
631
- n(`No mediaStreamTrack available for ${f.kind}`);
634
+ n(`No mediaStreamTrack available for ${m.kind}`);
632
635
  return;
633
636
  }
634
- b ? (b.addTrack(_), n(`Added ${f.kind} track to shared MediaStream`)) : (b = new MediaStream([_]), n(`Created shared MediaStream with ${f.kind} track`)), f.kind === "video" && ((A = a.onStreamReady) == null || A.call(a), n("CALLBACK: onSrcObjectReady"), (X = a.onSrcObjectReady) == null || X.call(a, b), F || (F = !0, n("CALLBACK: onConnectionStateChange(Connected)"), (Z = a.onConnectionStateChange) == null || Z.call(a, I.Connected, "livekit:track-subscribed")), n("CALLBACK: onVideoStateChange(Start)"), (se = a.onVideoStateChange) == null || se.call(a, M.Start), R = Ye(
635
- () => f.getRTCStatsReport(),
637
+ b ? (b.addTrack(_), n(`Added ${m.kind} track to shared MediaStream`)) : (b = new MediaStream([_]), n(`Created shared MediaStream with ${m.kind} track`)), m.kind === "video" && ((A = a.onStreamReady) == null || A.call(a), n("CALLBACK: onSrcObjectReady"), (Q = a.onSrcObjectReady) == null || Q.call(a, b), F || (F = !0, n("CALLBACK: onConnectionStateChange(Connected)"), (Z = a.onConnectionStateChange) == null || Z.call(a, I.Connected)), n("CALLBACK: onVideoStateChange(Start)"), (ce = a.onVideoStateChange) == null || ce.call(a, E.Start), R = Ge(
638
+ () => m.getRTCStatsReport(),
636
639
  () => v,
637
- pt,
640
+ wt,
638
641
  (ve, Re) => {
639
642
  n(`Video state change: ${ve}`);
640
643
  }
641
644
  ), R.start());
642
645
  }
643
- function N(f, g, y) {
646
+ function H(m, g, y) {
644
647
  var _;
645
- if (n(`Track unsubscribed: ${f.kind} from ${y.identity}`), f.kind === "video") {
648
+ if (n(`Track unsubscribed: ${m.kind} from ${y.identity}`), m.kind === "video") {
646
649
  const A = R == null ? void 0 : R.getReport();
647
- R == null || R.stop(), R = null, (_ = a.onVideoStateChange) == null || _.call(a, M.Stop, A);
650
+ R == null || R.stop(), R = null, (_ = a.onVideoStateChange) == null || _.call(a, E.Stop, A);
648
651
  }
649
652
  }
650
- function q(f, g, y, _) {
651
- var X, Z, se, ve, Re, $e;
652
- const A = new TextDecoder().decode(f);
653
+ function q(m, g, y, _) {
654
+ var Q, Z, ce, ve, Re, Be;
655
+ const A = new TextDecoder().decode(m);
653
656
  n("Data received:", A);
654
657
  try {
655
658
  const U = JSON.parse(A), ue = _ || U.subject;
656
659
  if (ue === L.ChatAnswer) {
657
- const ae = Y.Answer;
658
- (X = a.onMessage) == null || X.call(a, ae, {
660
+ const ae = X.Answer;
661
+ (Q = a.onMessage) == null || Q.call(a, ae, {
659
662
  event: ae,
660
663
  ...U
661
664
  });
662
665
  } else if (ue === L.ChatPartial) {
663
- const ae = Y.Partial;
666
+ const ae = X.Partial;
664
667
  (Z = a.onMessage) == null || Z.call(a, ae, {
665
668
  event: ae,
666
669
  ...U
667
670
  });
668
671
  } else if ([L.StreamVideoCreated, L.StreamVideoDone].includes(ue)) {
669
- J = ue === L.StreamVideoCreated ? W.Talking : W.Idle, (se = a.onAgentActivityStateChange) == null || se.call(a, J);
670
- const ge = { [(U == null ? void 0 : U.role) || (g == null ? void 0 : g.identity) || "datachannel"]: U };
671
- i.debug && ((ve = U == null ? void 0 : U.metadata) != null && ve.sentiment) && (ge.sentiment = {
672
+ J = ue === L.StreamVideoCreated ? V.Talking : V.Idle, (ce = a.onAgentActivityStateChange) == null || ce.call(a, J);
673
+ const fe = { [(U == null ? void 0 : U.role) || (g == null ? void 0 : g.identity) || "datachannel"]: U };
674
+ i.debug && ((ve = U == null ? void 0 : U.metadata) != null && ve.sentiment) && (fe.sentiment = {
672
675
  id: U.metadata.sentiment.id,
673
676
  name: U.metadata.sentiment.sentiment
674
- }), (Re = a.onMessage) == null || Re.call(a, ue, ge);
677
+ }), (Re = a.onMessage) == null || Re.call(a, ue, fe);
675
678
  } else if (ue === L.ChatAudioTranscribed) {
676
- const ae = Y.Transcribe;
677
- ($e = a.onMessage) == null || $e.call(a, ae, {
679
+ const ae = X.Transcribe;
680
+ (Be = a.onMessage) == null || Be.call(a, ae, {
678
681
  event: ae,
679
682
  ...U
680
683
  }), queueMicrotask(() => {
681
- var ge;
682
- (ge = a.onAgentActivityStateChange) == null || ge.call(a, W.Loading);
684
+ var fe;
685
+ (fe = a.onAgentActivityStateChange) == null || fe.call(a, V.Loading);
683
686
  });
684
687
  }
685
688
  } catch (U) {
686
689
  n("Failed to parse data channel message:", U);
687
690
  }
688
691
  }
689
- function Q(f) {
692
+ function j(m) {
690
693
  var g;
691
- n("Media devices error:", f), (g = a.onError) == null || g.call(a, new Error(pe), { sessionId: z });
694
+ n("Media devices error:", m), (g = a.onError) == null || g.call(a, new Error(he), { sessionId: z });
692
695
  }
693
- function j(f) {
696
+ function $(m) {
694
697
  var g;
695
- n("Encryption error:", f), (g = a.onError) == null || g.call(a, new Error(pe), { sessionId: z });
698
+ n("Encryption error:", m), (g = a.onError) == null || g.call(a, new Error(he), { sessionId: z });
696
699
  }
697
- function $(f, g, y) {
698
- n("Track subscription failed:", { trackSid: f, participant: g, reason: y });
700
+ function Y(m, g, y) {
701
+ n("Track subscription failed:", { trackSid: m, participant: g, reason: y });
699
702
  }
700
- async function G(f) {
703
+ async function oe(m) {
701
704
  if (!u) return null;
702
705
  const { Track: g } = await Me(), y = u.localParticipant.audioTrackPublications;
703
706
  if (y) {
704
707
  for (const [_, A] of y)
705
708
  if (A.source === g.Source.Microphone && A.track) {
706
709
  const Z = A.track.mediaStreamTrack;
707
- if (Z === f || Z && Z.id === f.id)
710
+ if (Z === m || Z && Z.id === m.id)
708
711
  return A;
709
712
  }
710
713
  }
711
714
  return null;
712
715
  }
713
- function oe(f) {
716
+ function p(m) {
714
717
  if (!C || !C.track)
715
718
  return !1;
716
719
  const g = C.track.mediaStreamTrack;
717
- return g !== f && (g == null ? void 0 : g.id) !== f.id;
720
+ return g !== m && (g == null ? void 0 : g.id) !== m.id;
718
721
  }
719
- async function p(f) {
720
- var X, Z;
722
+ async function f(m) {
723
+ var Q, Z;
721
724
  if (!v || !u)
722
725
  throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
723
- const g = f.getAudioTracks();
726
+ const g = m.getAudioTracks();
724
727
  if (g.length === 0) {
725
728
  n("No audio track found in the provided MediaStream");
726
729
  return;
727
730
  }
728
- const y = g[0], { Track: _ } = await Me(), A = await G(y);
731
+ const y = g[0], { Track: _ } = await Me(), A = await oe(y);
729
732
  if (A) {
730
733
  n("Microphone track is already published, skipping", {
731
734
  trackId: y.id,
732
- publishedTrackId: (Z = (X = A.track) == null ? void 0 : X.mediaStreamTrack) == null ? void 0 : Z.id
735
+ publishedTrackId: (Z = (Q = A.track) == null ? void 0 : Q.mediaStreamTrack) == null ? void 0 : Z.id
733
736
  }), C = A;
734
737
  return;
735
738
  }
736
- oe(y) && (n("Unpublishing existing microphone track before publishing new one"), await m()), n("Publishing microphone track from provided MediaStream", { trackId: y.id });
739
+ p(y) && (n("Unpublishing existing microphone track before publishing new one"), await M()), n("Publishing microphone track from provided MediaStream", { trackId: y.id });
737
740
  try {
738
741
  C = await u.localParticipant.publishTrack(y, {
739
742
  source: _.Source.Microphone
740
743
  }), n("Microphone track published successfully", { trackSid: C.trackSid });
741
- } catch (se) {
742
- throw n("Failed to publish microphone track:", se), se;
744
+ } catch (ce) {
745
+ throw n("Failed to publish microphone track:", ce), ce;
743
746
  }
744
747
  }
745
- async function m() {
748
+ async function M() {
746
749
  if (!(!C || !C.track))
747
750
  try {
748
751
  u && (await u.localParticipant.unpublishTrack(C.track), n("Microphone track unpublished"));
749
- } catch (f) {
750
- n("Error unpublishing microphone track:", f);
752
+ } catch (m) {
753
+ n("Error unpublishing microphone track:", m);
751
754
  } finally {
752
755
  C = null;
753
756
  }
754
757
  }
755
- function E() {
756
- b && (b.getTracks().forEach((f) => f.stop()), b = null);
758
+ function G() {
759
+ b && (b.getTracks().forEach((m) => m.stop()), b = null);
757
760
  }
758
- async function V(f, g) {
761
+ async function se(m, g) {
759
762
  var y, _;
760
763
  if (!v || !u) {
761
- n("Room is not connected for sending messages"), (y = a.onError) == null || y.call(a, new Error(pe), {
764
+ n("Room is not connected for sending messages"), (y = a.onError) == null || y.call(a, new Error(he), {
762
765
  sessionId: z
763
766
  });
764
767
  return;
765
768
  }
766
769
  try {
767
- await u.localParticipant.sendText(f, { topic: g }), n("Message sent successfully:", f);
770
+ await u.localParticipant.sendText(m, { topic: g }), n("Message sent successfully:", m);
768
771
  } catch (A) {
769
- n("Failed to send message:", A), (_ = a.onError) == null || _.call(a, new Error(pe), { sessionId: z });
772
+ n("Failed to send message:", A), (_ = a.onError) == null || _.call(a, new Error(he), { sessionId: z });
770
773
  }
771
774
  }
772
- async function ce(f) {
775
+ async function we(m) {
773
776
  var g;
774
777
  try {
775
- const _ = JSON.parse(f).topic;
776
- return V("", _);
778
+ const _ = JSON.parse(m).topic;
779
+ return se("", _);
777
780
  } catch (y) {
778
- n("Failed to send data channel message:", y), (g = a.onError) == null || g.call(a, new Error(pe), { sessionId: z });
781
+ n("Failed to send data channel message:", y), (g = a.onError) == null || g.call(a, new Error(he), { sessionId: z });
779
782
  }
780
783
  }
781
- function ye(f) {
782
- return V(
783
- f,
784
+ function ye(m) {
785
+ return se(
786
+ m,
784
787
  "lk.chat"
785
788
  /* Chat */
786
789
  );
787
790
  }
788
- async function de(f) {
789
- var g, y;
790
- S && (clearTimeout(S), S = null), u && (await m(), (g = a.onConnectionStateChange) == null || g.call(a, I.Disconnecting, f), await u.disconnect()), E(), v = !1, F = !1, (y = a.onAgentActivityStateChange) == null || y.call(a, W.Idle), J = W.Idle;
791
+ async function de() {
792
+ var m, g;
793
+ S && (clearTimeout(S), S = null), u && (await M(), await u.disconnect()), G(), v = !1, F = !1, (m = a.onConnectionStateChange) == null || m.call(a, I.Disconnected), (g = a.onAgentActivityStateChange) == null || g.call(a, V.Idle), J = V.Idle;
791
794
  }
792
795
  return {
793
- speak(f) {
794
- const g = typeof f == "string" ? f : JSON.stringify(f);
795
- return V(
796
+ speak(m) {
797
+ const g = typeof m == "string" ? m : JSON.stringify(m);
798
+ return se(
796
799
  g,
797
800
  "did.speak"
798
801
  /* Speak */
799
802
  );
800
803
  },
801
- disconnect: () => de("user:disconnect"),
804
+ disconnect: de,
802
805
  async reconnect() {
803
- var f, g;
806
+ var m, g;
804
807
  if ((u == null ? void 0 : u.state) === c.Connected) {
805
808
  n("Room is already connected");
806
809
  return;
807
810
  }
808
811
  if (!u || !te || !ee)
809
812
  throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
810
- n("Reconnecting to LiveKit room, state:", u.state), F = !1, (f = a.onConnectionStateChange) == null || f.call(a, I.Connecting, "user:reconnect");
813
+ n("Reconnecting to LiveKit room, state:", u.state), F = !1, (m = a.onConnectionStateChange) == null || m.call(a, I.Connecting);
811
814
  try {
812
815
  if (await u.connect(te, ee), n("Room reconnected"), v = !0, u.remoteParticipants.size === 0) {
813
816
  if (n("Waiting for agent to join..."), !await new Promise((_) => {
814
817
  const A = setTimeout(() => {
815
- u == null || u.off(o.ParticipantConnected, X), _(!1);
816
- }, 5e3), X = () => {
817
- clearTimeout(A), u == null || u.off(o.ParticipantConnected, X), _(!0);
818
+ u == null || u.off(o.ParticipantConnected, Q), _(!1);
819
+ }, 5e3), Q = () => {
820
+ clearTimeout(A), u == null || u.off(o.ParticipantConnected, Q), _(!0);
818
821
  };
819
- u == null || u.on(o.ParticipantConnected, X);
822
+ u == null || u.on(o.ParticipantConnected, Q);
820
823
  }))
821
824
  throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
822
- n("Agent joined, reconnection successful");
825
+ n("Agent joined");
823
826
  }
824
827
  } catch (y) {
825
- throw n("Failed to reconnect:", y), (g = a.onConnectionStateChange) == null || g.call(a, I.Fail, "user:reconnect-failed"), y;
828
+ throw n("Failed to reconnect:", y), (g = a.onConnectionStateChange) == null || g.call(a, I.Fail), y;
826
829
  }
827
830
  },
828
- sendDataChannelMessage: ce,
831
+ sendDataChannelMessage: we,
829
832
  sendTextMessage: ye,
830
- publishMicrophoneStream: p,
831
- unpublishMicrophoneStream: m,
833
+ publishMicrophoneStream: f,
834
+ unpublishMicrophoneStream: M,
832
835
  sessionId: z,
833
836
  streamId: z,
834
837
  streamType: x,
@@ -836,13 +839,13 @@ async function zt(e, t, i) {
836
839
  triggersAvailable: !1
837
840
  };
838
841
  }
839
- const Kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
842
+ const Nt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
840
843
  __proto__: null,
841
844
  DataChannelTopic: je,
842
- createLiveKitStreamingManager: zt,
845
+ createLiveKitStreamingManager: Kt,
843
846
  handleInitError: _e
844
847
  }, Symbol.toStringTag, { value: "Module" }));
845
- function Nt(e, t, i) {
848
+ function Jt(e, t, i) {
846
849
  if (!e)
847
850
  throw new Error("Please connect to the agent first");
848
851
  if (!e.interruptAvailable)
@@ -852,7 +855,7 @@ function Nt(e, t, i) {
852
855
  if (!i)
853
856
  throw new Error("No active video to interrupt");
854
857
  }
855
- async function Jt(e, t) {
858
+ async function Ut(e, t) {
856
859
  const i = {
857
860
  type: L.StreamInterrupt,
858
861
  videoId: t,
@@ -860,15 +863,15 @@ async function Jt(e, t) {
860
863
  };
861
864
  e.sendDataChannelMessage(JSON.stringify(i));
862
865
  }
863
- async function Ut(e) {
866
+ async function Vt(e) {
864
867
  const t = {
865
868
  topic: je.Interrupt
866
869
  };
867
870
  e.sendDataChannelMessage(JSON.stringify(t));
868
871
  }
869
- function Vt(e) {
872
+ function Wt(e) {
870
873
  return new Promise((t, i) => {
871
- const { callbacks: n, host: s, auth: o, externalId: c } = e, { onMessage: a = null, onOpen: r = null, onClose: d = null, onError: h = null } = n || {}, w = new WebSocket(`${s}?authorization=${encodeURIComponent(He(o, c))}`);
874
+ const { callbacks: n, host: s, auth: o, externalId: c } = e, { onMessage: a = null, onOpen: r = null, onClose: d = null, onError: h = null } = n || {}, w = new WebSocket(`${s}?authorization=${encodeURIComponent(qe(o, c))}`);
872
875
  w.onmessage = a, w.onclose = d, w.onerror = (u) => {
873
876
  console.error(u), h == null || h("Websocket failed to connect", u), i(u);
874
877
  }, w.onopen = (u) => {
@@ -876,28 +879,28 @@ function Vt(e) {
876
879
  };
877
880
  });
878
881
  }
879
- async function Wt(e) {
882
+ async function Ot(e) {
880
883
  const { retries: t = 1 } = e;
881
884
  let i = null;
882
885
  for (let n = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; n++)
883
886
  try {
884
- i = await Vt(e);
887
+ i = await Wt(e);
885
888
  } catch (s) {
886
889
  if (n === t)
887
890
  throw s;
888
- await Ve(n * 500);
891
+ await We(n * 500);
889
892
  }
890
893
  return i;
891
894
  }
892
- async function Ot(e, t, i, n) {
893
- const s = i != null && i.onMessage ? [i.onMessage] : [], o = await Wt({
895
+ async function Ht(e, t, i, n) {
896
+ const s = i != null && i.onMessage ? [i.onMessage] : [], o = await Ot({
894
897
  auth: e,
895
898
  host: t,
896
899
  externalId: n,
897
900
  callbacks: {
898
901
  onError: (c) => {
899
902
  var a;
900
- return (a = i.onError) == null ? void 0 : a.call(i, new nt(c));
903
+ return (a = i.onError) == null ? void 0 : a.call(i, new rt(c));
901
904
  },
902
905
  onMessage(c) {
903
906
  const a = JSON.parse(c.data);
@@ -911,7 +914,7 @@ async function Ot(e, t, i, n) {
911
914
  subscribeToEvents: (c) => s.push(c)
912
915
  };
913
916
  }
914
- function Ht(e) {
917
+ function qt(e) {
915
918
  if (e.answer !== void 0)
916
919
  return e.answer;
917
920
  let t = 0, i = "";
@@ -919,7 +922,7 @@ function Ht(e) {
919
922
  i += e[t++];
920
923
  return i;
921
924
  }
922
- function qt(e, t, i) {
925
+ function Qt(e, t, i) {
923
926
  if (!e.content)
924
927
  return;
925
928
  const n = t.messages[t.messages.length - 1];
@@ -933,17 +936,17 @@ function qt(e, t, i) {
933
936
  };
934
937
  t.messages.push(s), i == null || i([...t.messages], "user");
935
938
  }
936
- function Qt(e, t, i, n, s) {
937
- if (e === Y.Transcribe && t.content) {
938
- qt(t, n, s);
939
+ function Xt(e, t, i, n, s) {
940
+ if (e === X.Transcribe && t.content) {
941
+ Qt(t, n, s);
939
942
  return;
940
943
  }
941
- if (!(e === Y.Partial || e === Y.Answer))
944
+ if (!(e === X.Partial || e === X.Answer))
942
945
  return;
943
946
  const o = n.messages[n.messages.length - 1];
944
947
  let c;
945
948
  if (o != null && o.transcribed && o.role === "user")
946
- e === Y.Answer && t.content, c = {
949
+ e === X.Answer && t.content, c = {
947
950
  id: t.id || `assistant-${Date.now()}`,
948
951
  role: t.role || "assistant",
949
952
  content: t.content || "",
@@ -954,11 +957,11 @@ function Qt(e, t, i, n, s) {
954
957
  else
955
958
  return;
956
959
  const { content: a, sequence: r } = t;
957
- e === Y.Partial ? i[r] = a : i.answer = a;
958
- const d = Ht(i);
959
- (c.content !== d || e === Y.Answer) && (c.content = d, s == null || s([...n.messages], e));
960
+ e === X.Partial ? i[r] = a : i.answer = a;
961
+ const d = qt(i);
962
+ (c.content !== d || e === X.Answer) && (c.content = d, s == null || s([...n.messages], e));
960
963
  }
961
- function Xt(e, t, i, n, s) {
964
+ function Yt(e, t, i, n, s) {
962
965
  let o = {};
963
966
  const c = () => o = {};
964
967
  let a = "answer";
@@ -971,13 +974,13 @@ function Xt(e, t, i, n, s) {
971
974
  onMessage: (d, h) => {
972
975
  var w, u;
973
976
  if ("content" in h) {
974
- const v = d === L.ChatAnswer ? Y.Answer : d === L.ChatAudioTranscribed ? Y.Transcribe : d;
975
- Qt(v, h, o, t, r), v === Y.Answer && e.track("agent-message-received", {
977
+ const v = d === L.ChatAnswer ? X.Answer : d === L.ChatAudioTranscribed ? X.Transcribe : d;
978
+ Xt(v, h, o, t, r), v === X.Answer && e.track("agent-message-received", {
976
979
  messages: t.messages.length,
977
980
  mode: t.chatMode
978
981
  });
979
982
  } else {
980
- const v = L, x = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], b = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], C = Mt(h, n, { mode: t.chatMode });
983
+ const v = L, x = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], b = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], C = Et(h, n, { mode: t.chatMode });
981
984
  if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", C, v.StreamVideoCreated, ["start"]), h.sentiment)) {
982
985
  const R = t.messages[t.messages.length - 1];
983
986
  if ((R == null ? void 0 : R.role) === "assistant") {
@@ -994,7 +997,7 @@ function Xt(e, t, i, n, s) {
994
997
  }
995
998
  };
996
999
  }
997
- function Yt(e, t, i, n) {
1000
+ function Gt(e, t, i, n) {
998
1001
  const s = Le(e, `${t}/agents/${i}`, n);
999
1002
  return {
1000
1003
  createStream(o, c) {
@@ -1031,8 +1034,8 @@ function Yt(e, t, i, n) {
1031
1034
  }
1032
1035
  };
1033
1036
  }
1034
- const Gt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1035
- function Ke(e) {
1037
+ const Zt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1038
+ function Ne(e) {
1036
1039
  switch (e) {
1037
1040
  case "connected":
1038
1041
  return I.Connected;
@@ -1052,7 +1055,7 @@ function Ke(e) {
1052
1055
  return I.New;
1053
1056
  }
1054
1057
  }
1055
- const Zt = (e) => (t) => {
1058
+ const en = (e) => (t) => {
1056
1059
  const [i, n = ""] = t.split(/:(.+)/);
1057
1060
  try {
1058
1061
  const s = JSON.parse(n);
@@ -1061,16 +1064,16 @@ const Zt = (e) => (t) => {
1061
1064
  return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: n, error: s }), { subject: i, data: n };
1062
1065
  }
1063
1066
  };
1064
- function en({
1067
+ function tn({
1065
1068
  statsSignal: e,
1066
1069
  dataChannelSignal: t,
1067
1070
  onVideoStateChange: i,
1068
1071
  report: n,
1069
1072
  log: s
1070
1073
  }) {
1071
- e === M.Start && t === M.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(M.Start)) : e === M.Stop && t === M.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(M.Stop, n));
1074
+ e === E.Start && t === E.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && t === E.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, n));
1072
1075
  }
1073
- function tn({
1076
+ function nn({
1074
1077
  statsSignal: e,
1075
1078
  dataChannelSignal: t,
1076
1079
  onVideoStateChange: i,
@@ -1078,9 +1081,9 @@ function tn({
1078
1081
  report: s,
1079
1082
  log: o
1080
1083
  }) {
1081
- e === M.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(M.Start)) : e === M.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(M.Stop, s)), t === M.Start ? n == null || n(W.Talking) : t === M.Stop && (n == null || n(W.Idle));
1084
+ e === E.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, s)), t === E.Start ? n == null || n(V.Talking) : t === E.Stop && (n == null || n(V.Idle));
1082
1085
  }
1083
- function Ne({
1086
+ function Je({
1084
1087
  statsSignal: e,
1085
1088
  dataChannelSignal: t,
1086
1089
  onVideoStateChange: i,
@@ -1089,7 +1092,7 @@ function Ne({
1089
1092
  report: o,
1090
1093
  log: c
1091
1094
  }) {
1092
- s === ie.Legacy ? en({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o, log: c }) : s === ie.Fluent && tn({
1095
+ s === ie.Legacy ? tn({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o, log: c }) : s === ie.Fluent && nn({
1093
1096
  statsSignal: e,
1094
1097
  dataChannelSignal: t,
1095
1098
  onVideoStateChange: i,
@@ -1098,27 +1101,27 @@ function Ne({
1098
1101
  log: c
1099
1102
  });
1100
1103
  }
1101
- async function nn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = we, analytics: c }, a) {
1104
+ async function rn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = pe, analytics: c }, a) {
1102
1105
  var oe;
1103
- const r = Xe(i, "WebRTCStreamingManager"), d = Zt(r);
1104
- let h = !1, w = !1, u = M.Stop, v = M.Stop;
1105
- const { startConnection: x, sendStreamRequest: b, close: C, createStream: R, addIceCandidate: F } = Yt(
1106
+ const r = Ye(i, "WebRTCStreamingManager"), d = en(r);
1107
+ let h = !1, w = !1, u = E.Stop, v = E.Stop;
1108
+ const { startConnection: x, sendStreamRequest: b, close: C, createStream: R, addIceCandidate: F } = Gt(
1106
1109
  s,
1107
1110
  o,
1108
1111
  e,
1109
1112
  n.onError
1110
1113
  ), {
1111
1114
  id: S,
1112
- offer: O,
1115
+ offer: W,
1113
1116
  ice_servers: J,
1114
- session_id: H,
1117
+ session_id: O,
1115
1118
  fluent: z,
1116
1119
  interrupt_enabled: ee,
1117
1120
  triggers_enabled: te
1118
1121
  } = await R(t, a);
1119
- (oe = n.onStreamCreated) == null || oe.call(n, { stream_id: S, session_id: H, agent_id: e });
1120
- const l = new Gt({ iceServers: J }), D = l.createDataChannel("JanusDataChannel");
1121
- if (!H)
1122
+ (oe = n.onStreamCreated) == null || oe.call(n, { stream_id: S, session_id: O, agent_id: e });
1123
+ const l = new Zt({ iceServers: J }), D = l.createDataChannel("JanusDataChannel");
1124
+ if (!O)
1122
1125
  throw new Error("Could not create session_id");
1123
1126
  const k = z ? ie.Fluent : ie.Legacy;
1124
1127
  c.enrich({
@@ -1127,26 +1130,26 @@ async function nn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = we,
1127
1130
  const K = t.stream_warmup && !z, P = () => h, T = () => {
1128
1131
  var p;
1129
1132
  h = !0, w && (r("CALLBACK: onConnectionStateChange(Connected)"), (p = n.onConnectionStateChange) == null || p.call(n, I.Connected));
1130
- }, N = Ye(
1133
+ }, N = Ge(
1131
1134
  () => l.getStats(),
1132
1135
  P,
1133
1136
  T,
1134
- (p, m) => Ne({
1137
+ (p, f) => Je({
1135
1138
  statsSignal: v = p,
1136
1139
  dataChannelSignal: k === ie.Legacy ? u : void 0,
1137
1140
  onVideoStateChange: n.onVideoStateChange,
1138
1141
  onAgentActivityStateChange: n.onAgentActivityStateChange,
1139
- report: m,
1142
+ report: f,
1140
1143
  streamType: k,
1141
1144
  log: r
1142
1145
  }),
1143
1146
  (p) => {
1144
- var m;
1145
- return (m = n.onConnectivityStateChange) == null ? void 0 : m.call(n, p);
1147
+ var f;
1148
+ return (f = n.onConnectivityStateChange) == null ? void 0 : f.call(n, p);
1146
1149
  }
1147
1150
  );
1148
1151
  N.start(), l.onicecandidate = (p) => {
1149
- var m;
1152
+ var f;
1150
1153
  r("peerConnection.onicecandidate", p);
1151
1154
  try {
1152
1155
  p.candidate && p.candidate.sdpMid && p.candidate.sdpMLineIndex !== null ? F(
@@ -1156,25 +1159,25 @@ async function nn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = we,
1156
1159
  sdpMid: p.candidate.sdpMid,
1157
1160
  sdpMLineIndex: p.candidate.sdpMLineIndex
1158
1161
  },
1159
- H,
1162
+ O,
1160
1163
  a
1161
- ) : F(S, { candidate: null }, H, a);
1162
- } catch (E) {
1163
- (m = n.onError) == null || m.call(n, E, { streamId: S });
1164
+ ) : F(S, { candidate: null }, O, a);
1165
+ } catch (M) {
1166
+ (f = n.onError) == null || f.call(n, M, { streamId: S });
1164
1167
  }
1165
1168
  }, D.onopen = () => {
1166
1169
  w = !0, (!K || h) && T();
1167
1170
  };
1168
- const q = (p) => {
1169
- var m;
1170
- (m = n.onVideoIdChange) == null || m.call(n, p);
1171
+ const H = (p) => {
1172
+ var f;
1173
+ (f = n.onVideoIdChange) == null || f.call(n, p);
1171
1174
  };
1172
- function Q(p, m) {
1173
- if (p === L.StreamStarted && typeof m == "object" && "metadata" in m) {
1174
- const E = m.metadata;
1175
- q(E.videoId);
1175
+ function q(p, f) {
1176
+ if (p === L.StreamStarted && typeof f == "object" && "metadata" in f) {
1177
+ const M = f.metadata;
1178
+ H(M.videoId);
1176
1179
  }
1177
- p === L.StreamDone && q(null), u = p === L.StreamStarted ? M.Start : M.Stop, Ne({
1180
+ p === L.StreamDone && H(null), u = p === L.StreamStarted ? E.Start : E.Stop, Je({
1178
1181
  statsSignal: k === ie.Legacy ? v : void 0,
1179
1182
  dataChannelSignal: u,
1180
1183
  onVideoStateChange: n.onVideoStateChange,
@@ -1183,37 +1186,37 @@ async function nn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = we,
1183
1186
  log: r
1184
1187
  });
1185
1188
  }
1186
- function j(p, m) {
1187
- var V;
1188
- const E = typeof m == "string" ? m : m == null ? void 0 : m.metadata;
1189
- E && c.enrich({ streamMetadata: E }), (V = n.onStreamReady) == null || V.call(n);
1189
+ function j(p, f) {
1190
+ var G;
1191
+ const M = typeof f == "string" ? f : f == null ? void 0 : f.metadata;
1192
+ M && c.enrich({ streamMetadata: M }), (G = n.onStreamReady) == null || G.call(n);
1190
1193
  }
1191
1194
  const $ = {
1192
- [L.StreamStarted]: Q,
1193
- [L.StreamDone]: Q,
1195
+ [L.StreamStarted]: q,
1196
+ [L.StreamDone]: q,
1194
1197
  [L.StreamReady]: j
1195
1198
  };
1196
1199
  D.onmessage = (p) => {
1197
- var V;
1198
- const { subject: m, data: E } = d(p.data);
1199
- (V = $[m]) == null || V.call($, m, E);
1200
+ var G;
1201
+ const { subject: f, data: M } = d(p.data);
1202
+ (G = $[f]) == null || G.call($, f, M);
1200
1203
  }, l.oniceconnectionstatechange = () => {
1201
- var m;
1204
+ var f;
1202
1205
  r("peerConnection.oniceconnectionstatechange => " + l.iceConnectionState);
1203
- const p = Ke(l.iceConnectionState);
1204
- p !== I.Connected && ((m = n.onConnectionStateChange) == null || m.call(n, p));
1206
+ const p = Ne(l.iceConnectionState);
1207
+ p !== I.Connected && ((f = n.onConnectionStateChange) == null || f.call(n, p));
1205
1208
  }, l.ontrack = (p) => {
1206
- var m;
1207
- r("peerConnection.ontrack", p), r("CALLBACK: onSrcObjectReady"), (m = n.onSrcObjectReady) == null || m.call(n, p.streams[0]);
1208
- }, await l.setRemoteDescription(O), r("set remote description OK");
1209
- const G = await l.createAnswer();
1210
- return r("create answer OK"), await l.setLocalDescription(G), r("set local description OK"), await x(S, G, H, a), r("start connection OK"), {
1209
+ var f;
1210
+ r("peerConnection.ontrack", p), r("CALLBACK: onSrcObjectReady"), (f = n.onSrcObjectReady) == null || f.call(n, p.streams[0]);
1211
+ }, await l.setRemoteDescription(W), r("set remote description OK");
1212
+ const Y = await l.createAnswer();
1213
+ return r("create answer OK"), await l.setLocalDescription(Y), r("set local description OK"), await x(S, Y, O, a), r("start connection OK"), {
1211
1214
  /**
1212
1215
  * Method to send request to server to get clip or talk depend on you payload
1213
1216
  * @param payload
1214
1217
  */
1215
1218
  speak(p) {
1216
- return b(S, H, p);
1219
+ return b(S, O, p);
1217
1220
  },
1218
1221
  /**
1219
1222
  * Method to close RTC connection
@@ -1221,44 +1224,44 @@ async function nn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = we,
1221
1224
  async disconnect() {
1222
1225
  var p;
1223
1226
  if (S) {
1224
- const m = Ke(l.iceConnectionState);
1227
+ const f = Ne(l.iceConnectionState);
1225
1228
  if (l) {
1226
- if (m === I.New) {
1229
+ if (f === I.New) {
1227
1230
  N.stop();
1228
1231
  return;
1229
1232
  }
1230
1233
  l.close(), l.oniceconnectionstatechange = null, l.onnegotiationneeded = null, l.onicecandidate = null, l.ontrack = null;
1231
1234
  }
1232
1235
  try {
1233
- m === I.Connected && await C(S, H).catch((E) => {
1236
+ f === I.Connected && await C(S, O).catch((M) => {
1234
1237
  });
1235
- } catch (E) {
1236
- r("Error on close stream connection", E);
1238
+ } catch (M) {
1239
+ r("Error on close stream connection", M);
1237
1240
  }
1238
- (p = n.onAgentActivityStateChange) == null || p.call(n, W.Idle), N.stop();
1241
+ (p = n.onAgentActivityStateChange) == null || p.call(n, V.Idle), N.stop();
1239
1242
  }
1240
1243
  },
1241
1244
  /**
1242
1245
  * Method to send data channel messages to the server
1243
1246
  */
1244
1247
  sendDataChannelMessage(p) {
1245
- var m, E;
1248
+ var f, M;
1246
1249
  if (!h || D.readyState !== "open") {
1247
- r("Data channel is not ready for sending messages"), (m = n.onError) == null || m.call(n, new Error("Data channel is not ready for sending messages"), {
1250
+ r("Data channel is not ready for sending messages"), (f = n.onError) == null || f.call(n, new Error("Data channel is not ready for sending messages"), {
1248
1251
  streamId: S
1249
1252
  });
1250
1253
  return;
1251
1254
  }
1252
1255
  try {
1253
1256
  D.send(p);
1254
- } catch (V) {
1255
- r("Error sending data channel message", V), (E = n.onError) == null || E.call(n, V, { streamId: S });
1257
+ } catch (G) {
1258
+ r("Error sending data channel message", G), (M = n.onError) == null || M.call(n, G, { streamId: S });
1256
1259
  }
1257
1260
  },
1258
1261
  /**
1259
1262
  * Session identifier information, should be returned in the body of all streaming requests
1260
1263
  */
1261
- sessionId: H,
1264
+ sessionId: O,
1262
1265
  /**
1263
1266
  * Id of current RTC stream
1264
1267
  */
@@ -1269,18 +1272,18 @@ async function nn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = we,
1269
1272
  };
1270
1273
  }
1271
1274
  var Ae = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ae || {});
1272
- async function rn(e, t, i, n) {
1275
+ async function an(e, t, i, n) {
1273
1276
  const s = e.id;
1274
1277
  switch (t.version) {
1275
1278
  case "v1": {
1276
1279
  const { version: o, ...c } = t;
1277
- return nn(s, c, i, n);
1280
+ return rn(s, c, i, n);
1278
1281
  }
1279
1282
  case "v2": {
1280
1283
  const { version: o, ...c } = t;
1281
1284
  switch (c.transport_provider) {
1282
1285
  case ke.Livekit:
1283
- const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Kt);
1286
+ const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Nt);
1284
1287
  return a(s, c, i);
1285
1288
  default:
1286
1289
  throw new Error(`Unsupported transport provider: ${c.transport_provider}`);
@@ -1290,13 +1293,13 @@ async function rn(e, t, i, n) {
1290
1293
  throw new Error(`Invalid stream version: ${t.version}`);
1291
1294
  }
1292
1295
  }
1293
- const an = "cht";
1294
- function on() {
1296
+ const on = "cht";
1297
+ function sn() {
1295
1298
  return {
1296
1299
  transport_provider: ke.Livekit
1297
1300
  };
1298
1301
  }
1299
- function sn(e) {
1302
+ function cn(e) {
1300
1303
  var s, o;
1301
1304
  const { streamOptions: t } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
1302
1305
  plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
@@ -1309,17 +1312,14 @@ function sn(e) {
1309
1312
  fluent: t == null ? void 0 : t.fluent
1310
1313
  }, ...i && { end_user_data: i } };
1311
1314
  }
1312
- function cn(e, t) {
1313
- return Pe(e.presenter.type) ? { version: Ae.V2, ...on() } : { version: Ae.V1, ...sn(t) };
1314
- }
1315
- function dn(e, t, i) {
1316
- i.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
1315
+ function dn(e, t) {
1316
+ return Pe(e.presenter.type) ? { version: Ae.V2, ...sn() } : { version: Ae.V1, ...cn(t) };
1317
1317
  }
1318
1318
  function un(e, t, i, n, s) {
1319
- s === ie.Fluent ? ln(e, t, i, n, s) : mn(e, t, i, n, s);
1319
+ s === ie.Fluent ? ln(e, t, i, n, s) : fn(e, t, i, n, s);
1320
1320
  }
1321
1321
  function ln(e, t, i, n, s) {
1322
- e === M.Start ? n.track("stream-session", { event: "start", "stream-type": s }) : e === M.Stop && n.track("stream-session", {
1322
+ e === E.Start ? n.track("stream-session", { event: "start", "stream-type": s }) : e === E.Stop && n.track("stream-session", {
1323
1323
  event: "stop",
1324
1324
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1325
1325
  background: t.presenter.type === "clip" && t.presenter.background,
@@ -1327,13 +1327,13 @@ function ln(e, t, i, n, s) {
1327
1327
  ...i
1328
1328
  });
1329
1329
  }
1330
- function fn(e, t, i, n) {
1331
- ne.get() <= 0 || (e === M.Start ? i.linkTrack(
1330
+ function mn(e, t, i, n) {
1331
+ ne.get() <= 0 || (e === E.Start ? i.linkTrack(
1332
1332
  "agent-video",
1333
1333
  { event: "start", latency: ne.get(!0), "stream-type": n },
1334
1334
  "start",
1335
1335
  [L.StreamVideoCreated]
1336
- ) : e === M.Stop && i.linkTrack(
1336
+ ) : e === E.Stop && i.linkTrack(
1337
1337
  "agent-video",
1338
1338
  {
1339
1339
  event: "stop",
@@ -1345,13 +1345,13 @@ function fn(e, t, i, n) {
1345
1345
  [L.StreamVideoDone]
1346
1346
  ));
1347
1347
  }
1348
- function mn(e, t, i, n, s) {
1349
- ne.get() <= 0 || (e === M.Start ? n.linkTrack(
1348
+ function fn(e, t, i, n, s) {
1349
+ ne.get() <= 0 || (e === E.Start ? n.linkTrack(
1350
1350
  "agent-video",
1351
1351
  { event: "start", latency: ne.get(!0), "stream-type": s },
1352
1352
  "start",
1353
1353
  [L.StreamVideoCreated]
1354
- ) : e === M.Stop && n.linkTrack(
1354
+ ) : e === E.Stop && n.linkTrack(
1355
1355
  "agent-video",
1356
1356
  {
1357
1357
  event: "stop",
@@ -1364,14 +1364,14 @@ function mn(e, t, i, n, s) {
1364
1364
  [L.StreamVideoDone]
1365
1365
  ));
1366
1366
  }
1367
- function Je(e, t, i, n) {
1368
- return ne.reset(), Fe.update(), new Promise(async (s, o) => {
1367
+ function Ue(e, t, i, n) {
1368
+ return ne.reset(), ze.update(), new Promise(async (s, o) => {
1369
1369
  try {
1370
1370
  let c, a = !1;
1371
- const r = cn(e, t);
1371
+ const r = dn(e, t);
1372
1372
  i.enrich({
1373
1373
  "stream-version": r.version.toString()
1374
- }), c = await rn(
1374
+ }), c = await an(
1375
1375
  e,
1376
1376
  r,
1377
1377
  {
@@ -1379,9 +1379,9 @@ function Je(e, t, i, n) {
1379
1379
  analytics: i,
1380
1380
  callbacks: {
1381
1381
  ...t.callbacks,
1382
- onConnectionStateChange: (d, h) => {
1383
- var w, u;
1384
- (u = (w = t.callbacks).onConnectionStateChange) == null || u.call(w, d), dn(d, h, i), d === I.Connected && (c ? s(c) : a = !0);
1382
+ onConnectionStateChange: (d) => {
1383
+ var h, w;
1384
+ (w = (h = t.callbacks).onConnectionStateChange) == null || w.call(h, d), d === I.Connected && (c ? s(c) : a = !0);
1385
1385
  },
1386
1386
  onVideoStateChange: (d, h) => {
1387
1387
  var w, u;
@@ -1395,15 +1395,15 @@ function Je(e, t, i, n) {
1395
1395
  },
1396
1396
  onAgentActivityStateChange: (d) => {
1397
1397
  var h, w;
1398
- (w = (h = t.callbacks).onAgentActivityStateChange) == null || w.call(h, d), d === W.Talking ? Te.update() : Te.reset(), fn(
1399
- d === W.Talking ? M.Start : M.Stop,
1398
+ (w = (h = t.callbacks).onAgentActivityStateChange) == null || w.call(h, d), d === V.Talking ? Te.update() : Te.reset(), mn(
1399
+ d === V.Talking ? E.Start : E.Stop,
1400
1400
  e,
1401
1401
  i,
1402
1402
  c.streamType
1403
1403
  );
1404
1404
  },
1405
1405
  onStreamReady: () => {
1406
- const d = Fe.get(!0);
1406
+ const d = ze.get(!0);
1407
1407
  i.track("agent-chat", { event: "ready", latency: d });
1408
1408
  }
1409
1409
  }
@@ -1419,7 +1419,7 @@ async function gn(e, t, i, n, s) {
1419
1419
  var h, w, u, v;
1420
1420
  const o = async () => {
1421
1421
  if (Pe(e.presenter.type)) {
1422
- const x = await Je(e, t, n), b = `${an}_${x.sessionId}`, C = (/* @__PURE__ */ new Date()).toISOString();
1422
+ const x = await Ue(e, t, n), b = `${on}_${x.sessionId}`, C = (/* @__PURE__ */ new Date()).toISOString();
1423
1423
  return { chatResult: {
1424
1424
  chatMode: B.Functional,
1425
1425
  chat: {
@@ -1438,44 +1438,44 @@ async function gn(e, t, i, n, s) {
1438
1438
  const x = new AbortController(), b = x.signal;
1439
1439
  let C;
1440
1440
  try {
1441
- const R = Qe(
1441
+ const R = Xe(
1442
1442
  e,
1443
1443
  i,
1444
1444
  n,
1445
1445
  t.mode,
1446
1446
  t.persistentChat,
1447
1447
  s
1448
- ), F = Je(e, t, n, b).then((J) => (C = J, J)), [S, O] = await Promise.all([R, F]);
1449
- return { chatResult: S, streamingManager: O };
1448
+ ), F = Ue(e, t, n, b).then((J) => (C = J, J)), [S, W] = await Promise.all([R, F]);
1449
+ return { chatResult: S, streamingManager: W };
1450
1450
  } catch (R) {
1451
1451
  throw x.abort(), C && await C.disconnect().catch(() => {
1452
1452
  }), R;
1453
1453
  }
1454
1454
  }
1455
1455
  }, { chatResult: c, streamingManager: a } = await o(), { chat: r, chatMode: d } = c;
1456
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (w = (h = t.callbacks).onModeChange) == null || w.call(h, d), d !== B.Functional) ? ((v = (u = t.callbacks).onError) == null || v.call(u, new tt(d)), a == null || a.disconnect(), { chat: r }) : { chat: r, streamingManager: a };
1456
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (w = (h = t.callbacks).onModeChange) == null || w.call(h, d), d !== B.Functional) ? ((v = (u = t.callbacks).onError) == null || v.call(u, new nt(d)), a == null || a.disconnect(), { chat: r }) : { chat: r, streamingManager: a };
1457
1457
  }
1458
1458
  async function wn(e, t) {
1459
- var H, z, ee, te;
1459
+ var O, z, ee, te;
1460
1460
  let i = !0, n = null;
1461
- const s = t.mixpanelKey || ht, o = t.wsURL || gt, c = t.baseURL || we, a = t.mode || B.Functional, r = {
1461
+ const s = t.mixpanelKey || pt, o = t.wsURL || ht, c = t.baseURL || pe, a = t.mode || B.Functional, r = {
1462
1462
  messages: [],
1463
1463
  chatMode: a
1464
- }, d = It({
1464
+ }, d = Tt({
1465
1465
  token: s,
1466
1466
  agentId: e,
1467
1467
  isEnabled: t.enableAnalitics,
1468
1468
  externalId: t.externalId,
1469
1469
  mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
1470
1470
  }), h = Date.now();
1471
- xe(() => {
1471
+ Fe(() => {
1472
1472
  d.track("agent-sdk", { event: "init" }, h);
1473
1473
  });
1474
- const w = St(t.auth, c, t.callbacks.onError, t.externalId), u = await w.getById(e);
1475
- t.debug = t.debug || ((H = u == null ? void 0 : u.advanced_settings) == null ? void 0 : H.ui_debug_mode);
1474
+ const w = kt(t.auth, c, t.callbacks.onError, t.externalId), u = await w.getById(e);
1475
+ t.debug = t.debug || ((O = u == null ? void 0 : u.advanced_settings) == null ? void 0 : O.ui_debug_mode);
1476
1476
  const v = Pe(u.presenter.type);
1477
- d.enrich(Rt(u));
1478
- const { onMessage: x, clearQueue: b } = Xt(
1477
+ d.enrich(Dt(u));
1478
+ const { onMessage: x, clearQueue: b } = Yt(
1479
1479
  d,
1480
1480
  r,
1481
1481
  t,
@@ -1485,7 +1485,7 @@ async function wn(e, t) {
1485
1485
  return (l = r.socketManager) == null ? void 0 : l.disconnect();
1486
1486
  }
1487
1487
  );
1488
- r.messages = _t(t.initialMessages), (ee = (z = t.callbacks).onNewMessage) == null || ee.call(z, [...r.messages], "answer");
1488
+ r.messages = At(t.initialMessages), (ee = (z = t.callbacks).onNewMessage) == null || ee.call(z, [...r.messages], "answer");
1489
1489
  const C = (l) => {
1490
1490
  n = l;
1491
1491
  }, R = ({ type: l }) => {
@@ -1495,15 +1495,15 @@ async function wn(e, t) {
1495
1495
  type: l || "click",
1496
1496
  video_duration_to_interrupt: Te.get(!0),
1497
1497
  message_duration_to_interrupt: ne.get(!0)
1498
- }), D.interrupted = !0, (K = (k = t.callbacks).onNewMessage) == null || K.call(k, [...r.messages], "answer"), v ? Ut(r.streamingManager) : (Nt(r.streamingManager, (P = r.streamingManager) == null ? void 0 : P.streamType, n), Jt(r.streamingManager, n));
1498
+ }), D.interrupted = !0, (K = (k = t.callbacks).onNewMessage) == null || K.call(k, [...r.messages], "answer"), v ? Vt(r.streamingManager) : (Jt(r.streamingManager, (P = r.streamingManager) == null ? void 0 : P.streamType, n), Ut(r.streamingManager, n));
1499
1499
  }, F = Date.now();
1500
- xe(() => {
1501
- d.track("agent-sdk", { event: "loaded", ...kt(u) }, F);
1500
+ Fe(() => {
1501
+ d.track("agent-sdk", { event: "loaded", ...Rt(u) }, F);
1502
1502
  });
1503
1503
  async function S(l) {
1504
- var N, q, Q, j, $, G, oe;
1505
- (q = (N = t.callbacks).onConnectionStateChange) == null || q.call(N, I.Connecting), ne.reset(), l && !i && (delete r.chat, (j = (Q = t.callbacks).onNewMessage) == null || j.call(Q, [...r.messages], "answer"));
1506
- const D = a === B.DirectPlayback || v ? Promise.resolve(void 0) : Ot(
1504
+ var N, H, q, j, $, Y, oe;
1505
+ (H = (N = t.callbacks).onConnectionStateChange) == null || H.call(N, I.Connecting), ne.reset(), l && !i && (delete r.chat, (j = (q = t.callbacks).onNewMessage) == null || j.call(q, [...r.messages], "answer"));
1506
+ const D = a === B.DirectPlayback || v ? Promise.resolve(void 0) : Ht(
1507
1507
  t.auth,
1508
1508
  o,
1509
1509
  { onMessage: x, onError: t.callbacks.onError },
@@ -1533,22 +1533,22 @@ async function wn(e, t) {
1533
1533
  delayMs: 1e3
1534
1534
  }
1535
1535
  ).catch((p) => {
1536
- var m, E;
1537
- throw J(B.Maintenance), (E = (m = t.callbacks).onConnectionStateChange) == null || E.call(m, I.Fail), p;
1536
+ var f, M;
1537
+ throw J(B.Maintenance), (M = (f = t.callbacks).onConnectionStateChange) == null || M.call(f, I.Fail), p;
1538
1538
  }), [K, { streamingManager: P, chat: T }] = await Promise.all([D, k]);
1539
- T && T.id !== (($ = r.chat) == null ? void 0 : $.id) && ((oe = (G = t.callbacks).onNewChat) == null || oe.call(G, T.id)), r.streamingManager = P, r.socketManager = K, r.chat = T, i = !1, d.enrich({
1539
+ T && T.id !== (($ = r.chat) == null ? void 0 : $.id) && ((oe = (Y = t.callbacks).onNewChat) == null || oe.call(Y, T.id)), r.streamingManager = P, r.socketManager = K, r.chat = T, i = !1, d.enrich({
1540
1540
  chatId: T == null ? void 0 : T.id,
1541
1541
  streamId: P == null ? void 0 : P.streamId,
1542
1542
  mode: r.chatMode
1543
1543
  }), J((T == null ? void 0 : T.chat_mode) ?? a);
1544
1544
  }
1545
- async function O() {
1545
+ async function W() {
1546
1546
  var l, D, k, K;
1547
1547
  (l = r.socketManager) == null || l.disconnect(), await ((D = r.streamingManager) == null ? void 0 : D.disconnect()), delete r.streamingManager, delete r.socketManager, (K = (k = t.callbacks).onConnectionStateChange) == null || K.call(k, I.Disconnected);
1548
1548
  }
1549
1549
  async function J(l) {
1550
1550
  var D, k;
1551
- l !== r.chatMode && (d.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== B.Functional && await O(), (k = (D = t.callbacks).onModeChange) == null || k.call(D, l));
1551
+ l !== r.chatMode && (d.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== B.Functional && await W(), (k = (D = t.callbacks).onModeChange) == null || k.call(D, l));
1552
1552
  }
1553
1553
  return {
1554
1554
  agent: u,
@@ -1583,17 +1583,17 @@ async function wn(e, t) {
1583
1583
  mode: r.chatMode
1584
1584
  });
1585
1585
  } catch {
1586
- await O(), await S(!1);
1586
+ await W(), await S(!1);
1587
1587
  }
1588
1588
  return;
1589
1589
  }
1590
- await O(), await S(!1), d.track("agent-chat", {
1590
+ await W(), await S(!1), d.track("agent-chat", {
1591
1591
  event: "reconnect",
1592
1592
  mode: r.chatMode
1593
1593
  });
1594
1594
  },
1595
1595
  async disconnect() {
1596
- await O(), d.track("agent-chat", {
1596
+ await W(), d.track("agent-chat", {
1597
1597
  event: "disconnect",
1598
1598
  mode: r.chatMode
1599
1599
  });
@@ -1611,9 +1611,9 @@ async function wn(e, t) {
1611
1611
  return r.streamingManager.unpublishMicrophoneStream();
1612
1612
  },
1613
1613
  async chat(l) {
1614
- var P, T, N, q, Q;
1614
+ var P, T, N, H, q;
1615
1615
  const D = () => {
1616
- if (Oe(a))
1616
+ if (He(a))
1617
1617
  throw new le(`${a} is enabled, chat is disabled`);
1618
1618
  if (l.length >= 800)
1619
1619
  throw new le("Message cannot be more than 800 characters");
@@ -1630,61 +1630,61 @@ async function wn(e, t) {
1630
1630
  }, k = async () => {
1631
1631
  var j, $;
1632
1632
  if (!r.chat) {
1633
- const G = await Qe(
1633
+ const Y = await Xe(
1634
1634
  u,
1635
1635
  w,
1636
1636
  d,
1637
1637
  r.chatMode,
1638
1638
  t.persistentChat
1639
1639
  );
1640
- if (!G.chat)
1641
- throw new et(r.chatMode, !!t.persistentChat);
1642
- r.chat = G.chat, ($ = (j = t.callbacks).onNewChat) == null || $.call(j, r.chat.id);
1640
+ if (!Y.chat)
1641
+ throw new tt(r.chatMode, !!t.persistentChat);
1642
+ r.chat = Y.chat, ($ = (j = t.callbacks).onNewChat) == null || $.call(j, r.chat.id);
1643
1643
  }
1644
1644
  return r.chat.id;
1645
1645
  }, K = async (j, $) => {
1646
- const G = r.chatMode === B.Playground;
1647
- return Ee(v && !G ? async () => {
1648
- var m, E;
1649
- return await ((E = (m = r.streamingManager) == null ? void 0 : m.sendTextMessage) == null ? void 0 : E.call(m, l)), Promise.resolve({});
1646
+ const Y = r.chatMode === B.Playground;
1647
+ return Ee(v && !Y ? async () => {
1648
+ var f, M;
1649
+ return await ((M = (f = r.streamingManager) == null ? void 0 : f.sendTextMessage) == null ? void 0 : M.call(f, l)), Promise.resolve({});
1650
1650
  } : async () => {
1651
- var m, E;
1651
+ var f, M;
1652
1652
  return w.chat(
1653
1653
  u.id,
1654
1654
  $,
1655
1655
  {
1656
1656
  chatMode: r.chatMode,
1657
- streamId: (m = r.streamingManager) == null ? void 0 : m.streamId,
1658
- sessionId: (E = r.streamingManager) == null ? void 0 : E.sessionId,
1659
- messages: j.map(({ matches: V, ...ce }) => ce)
1657
+ streamId: (f = r.streamingManager) == null ? void 0 : f.streamId,
1658
+ sessionId: (M = r.streamingManager) == null ? void 0 : M.sessionId,
1659
+ messages: j.map(({ matches: G, ...se }) => se)
1660
1660
  },
1661
1661
  {
1662
- ...qe(r.chatMode),
1662
+ ...Qe(r.chatMode),
1663
1663
  skipErrorHandler: !0
1664
1664
  }
1665
1665
  );
1666
1666
  }, {
1667
1667
  limit: 2,
1668
- shouldRetryFn: (m) => {
1669
- var ce, ye, de, me;
1670
- const E = (ce = m == null ? void 0 : m.message) == null ? void 0 : ce.includes("missing or invalid session_id");
1671
- return !((ye = m == null ? void 0 : m.message) == null ? void 0 : ye.includes("Stream Error")) && !E ? ((me = (de = t.callbacks).onError) == null || me.call(de, m), !1) : !0;
1668
+ shouldRetryFn: (f) => {
1669
+ var se, we, ye, de;
1670
+ const M = (se = f == null ? void 0 : f.message) == null ? void 0 : se.includes("missing or invalid session_id");
1671
+ return !((we = f == null ? void 0 : f.message) == null ? void 0 : we.includes("Stream Error")) && !M ? ((de = (ye = t.callbacks).onError) == null || de.call(ye, f), !1) : !0;
1672
1672
  },
1673
1673
  onRetry: async () => {
1674
- await O(), await S(!1);
1674
+ await W(), await S(!1);
1675
1675
  }
1676
1676
  });
1677
1677
  };
1678
1678
  try {
1679
1679
  b(), D(), r.messages.push({
1680
- id: fe(),
1680
+ id: me(),
1681
1681
  role: "user",
1682
1682
  content: l,
1683
1683
  created_at: new Date(ne.update()).toISOString()
1684
1684
  }), (T = (P = t.callbacks).onNewMessage) == null || T.call(P, [...r.messages], "user");
1685
1685
  const j = await k(), $ = await K([...r.messages], j);
1686
1686
  return r.messages.push({
1687
- id: fe(),
1687
+ id: me(),
1688
1688
  role: "assistant",
1689
1689
  content: $.result || "",
1690
1690
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
@@ -1693,19 +1693,19 @@ async function wn(e, t) {
1693
1693
  }), d.track("agent-message-send", {
1694
1694
  event: "success",
1695
1695
  messages: r.messages.length + 1
1696
- }), $.result && ((q = (N = t.callbacks).onNewMessage) == null || q.call(N, [...r.messages], "answer"), d.track("agent-message-received", {
1696
+ }), $.result && ((H = (N = t.callbacks).onNewMessage) == null || H.call(N, [...r.messages], "answer"), d.track("agent-message-received", {
1697
1697
  latency: ne.get(!0),
1698
1698
  messages: r.messages.length
1699
1699
  })), $;
1700
1700
  } catch (j) {
1701
- throw ((Q = r.messages[r.messages.length - 1]) == null ? void 0 : Q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
1701
+ throw ((q = r.messages[r.messages.length - 1]) == null ? void 0 : q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
1702
1702
  event: "error",
1703
1703
  messages: r.messages.length
1704
1704
  }), j;
1705
1705
  }
1706
1706
  },
1707
1707
  rate(l, D, k) {
1708
- var T, N, q, Q;
1708
+ var T, N, H, q;
1709
1709
  const K = r.messages.find((j) => j.id === l);
1710
1710
  if (r.chat) {
1711
1711
  if (!K)
@@ -1719,12 +1719,12 @@ async function wn(e, t) {
1719
1719
  matches: P,
1720
1720
  score: D
1721
1721
  }), k ? w.updateRating(u.id, r.chat.id, k, {
1722
- knowledge_id: ((q = u.knowledge) == null ? void 0 : q.id) ?? "",
1722
+ knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
1723
1723
  message_id: l,
1724
1724
  matches: P,
1725
1725
  score: D
1726
1726
  }) : w.createRating(u.id, r.chat.id, {
1727
- knowledge_id: ((Q = u.knowledge) == null ? void 0 : Q.id) ?? "",
1727
+ knowledge_id: ((q = u.knowledge) == null ? void 0 : q.id) ?? "",
1728
1728
  message_id: l,
1729
1729
  matches: P,
1730
1730
  score: D
@@ -1762,11 +1762,11 @@ async function wn(e, t) {
1762
1762
  }
1763
1763
  const k = D();
1764
1764
  if (d.track("agent-speak", k), ne.update(), r.messages && k.type === "text" && (r.messages.push({
1765
- id: fe(),
1765
+ id: me(),
1766
1766
  role: "assistant",
1767
1767
  content: k.input,
1768
1768
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1769
- }), (T = (P = t.callbacks).onNewMessage) == null || T.call(P, [...r.messages], "answer")), wt(r.chatMode))
1769
+ }), (T = (P = t.callbacks).onNewMessage) == null || T.call(P, [...r.messages], "answer")), yt(r.chatMode))
1770
1770
  return {
1771
1771
  duration: 0,
1772
1772
  video_id: "",
@@ -1783,29 +1783,29 @@ async function wn(e, t) {
1783
1783
  };
1784
1784
  }
1785
1785
  export {
1786
- W as AgentActivityState,
1787
- at as AgentStatus,
1788
- et as ChatCreationFailed,
1786
+ V as AgentActivityState,
1787
+ ot as AgentStatus,
1788
+ tt as ChatCreationFailed,
1789
1789
  B as ChatMode,
1790
- tt as ChatModeDowngraded,
1791
- Y as ChatProgress,
1790
+ nt as ChatModeDowngraded,
1791
+ X as ChatProgress,
1792
1792
  I as ConnectionState,
1793
1793
  re as ConnectivityState,
1794
- dt as DocumentType,
1795
- ct as KnowledgeType,
1796
- it as PlanGroup,
1797
- ut as Providers,
1798
- ot as RateState,
1794
+ ut as DocumentType,
1795
+ dt as KnowledgeType,
1796
+ at as PlanGroup,
1797
+ lt as Providers,
1798
+ st as RateState,
1799
1799
  L as StreamEvents,
1800
1800
  ie as StreamType,
1801
- M as StreamingState,
1802
- st as Subject,
1801
+ E as StreamingState,
1802
+ ct as Subject,
1803
1803
  ke as TransportProvider,
1804
- rt as UserPlan,
1804
+ it as UserPlan,
1805
1805
  le as ValidationError,
1806
- Ue as VideoType,
1807
- lt as VoiceAccess,
1808
- nt as WsError,
1806
+ Ve as VideoType,
1807
+ mt as VoiceAccess,
1808
+ rt as WsError,
1809
1809
  wn as createAgentManager,
1810
1810
  pn as mapVideoType
1811
1811
  };