@d-id/client-sdk 1.1.59 → 1.1.60-staging.278

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var Et = Object.defineProperty;
2
- var kt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
3
- var Ce = (e, n, i) => kt(e, typeof n != "symbol" ? n + "" : n, i);
2
+ var Mt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
3
+ var Ce = (e, n, i) => Mt(e, typeof n != "symbol" ? n + "" : n, i);
4
4
  class Ie extends Error {
5
5
  constructor({ kind: i, description: r, error: s }) {
6
6
  super(JSON.stringify({ kind: i, description: r }));
@@ -10,7 +10,7 @@ class Ie extends Error {
10
10
  this.kind = i, this.description = r, this.error = s;
11
11
  }
12
12
  }
13
- class Mt extends Ie {
13
+ class kt extends Ie {
14
14
  constructor(n, i) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -35,7 +35,7 @@ class Dt extends Ie {
35
35
  super({ kind: "WSError", description: n });
36
36
  }
37
37
  }
38
- var _t = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_t || {}), 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 || {}), bt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(bt || {}), Lt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Lt || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pt || {}), xt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xt || {}), $t = /* @__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))($t || {}), dt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(dt || {});
38
+ var At = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(At || {}), _t = /* @__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))(_t || {}), bt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(bt || {}), Lt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Lt || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pt || {}), xt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xt || {}), $t = /* @__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))($t || {}), dt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(dt || {});
39
39
  const Hn = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
@@ -48,8 +48,8 @@ const Hn = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), I = /* @__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.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(I || {}), P = /* @__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))(P || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ke = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ke || {}), jt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(jt || {}), Bt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Bt || {});
52
- const Ft = 45 * 1e3, Kt = "X-Playground-Chat", Ee = "https://api.d-id.com", Nt = "wss://notifications.d-id.com", zt = "79f81a83a67430be2bc0fd61042b8faa", Vt = (...e) => {
51
+ var E = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(E || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), M = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(M || {}), x = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(x || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ne = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ne || {}), jt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(jt || {}), Bt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Bt || {});
52
+ const Ft = 45 * 1e3, Nt = "X-Playground-Chat", Ee = "https://api.d-id.com", Kt = "wss://notifications.d-id.com", zt = "79f81a83a67430be2bc0fd61042b8faa", Vt = (...e) => {
53
53
  }, ut = (e) => new Promise((n) => setTimeout(n, e)), ge = (e = 16) => {
54
54
  const n = new Uint8Array(e);
55
55
  return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
@@ -62,7 +62,7 @@ const Ft = 45 * 1e3, Kt = "X-Playground-Chat", Ee = "https://api.d-id.com", Nt =
62
62
  case "talk":
63
63
  return "v2";
64
64
  }
65
- }, Jt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Ne = (e) => e === dt.Expressive, Ot = (e) => [O.TextOnly, O.Playground, O.Maintenance].includes(e), ft = (e) => e && [O.DirectPlayback, O.Off].includes(e), Qe = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Xe = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ye = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ge = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
65
+ }, Jt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Ke = (e) => e === dt.Expressive, Ot = (e) => [O.TextOnly, O.Playground, O.Maintenance].includes(e), ft = (e) => e && [O.DirectPlayback, O.Off].includes(e), Qe = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Xe = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ye = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ge = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
66
66
  function Wt(e) {
67
67
  if (e.length === 0)
68
68
  return [];
@@ -76,8 +76,8 @@ function Wt(e) {
76
76
  });
77
77
  for (Xe.lastIndex = 0; (i = Xe.exec(e)) !== null; )
78
78
  if (!n.some((o) => i.index >= o.index && i.index < o.index + o.length)) {
79
- const o = i[2], d = { type: "image", src: o, alt: i[1] };
80
- o.toLowerCase().endsWith(".gif") && (d.mimeType = "image/gif"), n.push({ index: i.index, length: i[0].length, part: d });
79
+ const o = i[2], c = { type: "image", src: o, alt: i[1] };
80
+ o.toLowerCase().endsWith(".gif") && (c.mimeType = "image/gif"), n.push({ index: i.index, length: i[0].length, part: c });
81
81
  }
82
82
  for (Ye.lastIndex = 0; (i = Ye.exec(e)) !== null; )
83
83
  n.some((o) => i.index >= o.index && i.index < o.index + o.length) || n.push({
@@ -128,8 +128,8 @@ async function xe(e, n) {
128
128
  try {
129
129
  if (!i.timeout)
130
130
  return await e();
131
- const { promise: a, clear: o } = Ht(i.timeout, i.timeoutErrorMessage), d = e().finally(o);
132
- return await Promise.race([d, a]);
131
+ const { promise: a, clear: o } = Ht(i.timeout, i.timeoutErrorMessage), c = e().finally(o);
132
+ return await Promise.race([c, a]);
133
133
  } catch (a) {
134
134
  if (r = a, !i.shouldRetryFn(a) || s >= i.limit)
135
135
  throw a;
@@ -165,7 +165,7 @@ const Qt = (e) => xe(e, {
165
165
  });
166
166
  function ze(e, n = Ee, i, r) {
167
167
  const s = async (a, o) => {
168
- const { skipErrorHandler: d, ...t } = o || {}, c = await Qt(
168
+ const { skipErrorHandler: c, ...t } = o || {}, d = await Qt(
169
169
  () => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
170
170
  ...t,
171
171
  headers: {
@@ -175,25 +175,25 @@ function ze(e, n = Ee, i, r) {
175
175
  }
176
176
  })
177
177
  );
178
- if (!c.ok) {
179
- let h = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
178
+ if (!d.ok) {
179
+ let h = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
180
180
  const g = new Error(h);
181
- throw i && !d && i(g, { url: a, options: t, headers: c.headers }), g;
181
+ throw i && !c && i(g, { url: a, options: t, headers: d.headers }), g;
182
182
  }
183
- return c.json();
183
+ return d.json();
184
184
  };
185
185
  return {
186
186
  get(a, o) {
187
187
  return s(a, { ...o, method: "GET" });
188
188
  },
189
- post(a, o, d) {
190
- return s(a, { ...d, body: JSON.stringify(o), method: "POST" });
189
+ post(a, o, c) {
190
+ return s(a, { ...c, body: JSON.stringify(o), method: "POST" });
191
191
  },
192
- delete(a, o, d) {
193
- return s(a, { ...d, body: JSON.stringify(o), method: "DELETE" });
192
+ delete(a, o, c) {
193
+ return s(a, { ...c, body: JSON.stringify(o), method: "DELETE" });
194
194
  },
195
- patch(a, o, d) {
196
- return s(a, { ...d, body: JSON.stringify(o), method: "PATCH" });
195
+ patch(a, o, c) {
196
+ return s(a, { ...c, body: JSON.stringify(o), method: "PATCH" });
197
197
  }
198
198
  };
199
199
  }
@@ -204,7 +204,7 @@ function Xt(e, n = Ee, i, r) {
204
204
  return s.post("/", a, o);
205
205
  },
206
206
  getAgents(a, o) {
207
- return s.get(`/${a ? `?tag=${a}` : ""}`, o).then((d) => d ?? []);
207
+ return s.get(`/${a ? `?tag=${a}` : ""}`, o).then((c) => c ?? []);
208
208
  },
209
209
  getById(a, o) {
210
210
  return s.get(`/${a}`, o);
@@ -212,23 +212,23 @@ function Xt(e, n = Ee, i, r) {
212
212
  delete(a, o) {
213
213
  return s.delete(`/${a}`, void 0, o);
214
214
  },
215
- update(a, o, d) {
216
- return s.patch(`/${a}`, o, d);
215
+ update(a, o, c) {
216
+ return s.patch(`/${a}`, o, c);
217
217
  },
218
- newChat(a, o, d) {
219
- return s.post(`/${a}/chat`, o, d);
218
+ newChat(a, o, c) {
219
+ return s.post(`/${a}/chat`, o, c);
220
220
  },
221
- chat(a, o, d, t) {
222
- return s.post(`/${a}/chat/${o}`, d, t);
221
+ chat(a, o, c, t) {
222
+ return s.post(`/${a}/chat/${o}`, c, t);
223
223
  },
224
- createRating(a, o, d, t) {
225
- return s.post(`/${a}/chat/${o}/ratings`, d, t);
224
+ createRating(a, o, c, t) {
225
+ return s.post(`/${a}/chat/${o}/ratings`, c, t);
226
226
  },
227
- updateRating(a, o, d, t, c) {
228
- return s.patch(`/${a}/chat/${o}/ratings/${d}`, t, c);
227
+ updateRating(a, o, c, t, d) {
228
+ return s.patch(`/${a}/chat/${o}/ratings/${c}`, t, d);
229
229
  },
230
- deleteRating(a, o, d, t) {
231
- return s.delete(`/${a}/chat/${o}/ratings/${d}`, t);
230
+ deleteRating(a, o, c, t) {
231
+ return s.delete(`/${a}/chat/${o}/ratings/${c}`, t);
232
232
  },
233
233
  getSTTToken(a, o) {
234
234
  return s.get(`/${a}/stt-token`, o);
@@ -236,7 +236,7 @@ function Xt(e, n = Ee, i, r) {
236
236
  };
237
237
  }
238
238
  function Yt(e) {
239
- var s, a, o, d;
239
+ var s, a, o, c;
240
240
  const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
241
241
  const t = navigator.platform;
242
242
  return t.toLowerCase().includes("win") ? "Windows" : t.toLowerCase().includes("mac") ? "Mac OS X" : t.toLowerCase().includes("linux") ? "Linux" : "Unknown";
@@ -249,12 +249,12 @@ function Yt(e) {
249
249
  agentType: lt(r),
250
250
  agentVoice: {
251
251
  voiceId: (a = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : a.voice_id,
252
- provider: (d = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : d.type
252
+ provider: (c = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : c.type
253
253
  }
254
254
  };
255
255
  }
256
256
  function Gt(e) {
257
- var i, r, s, a, o, d;
257
+ var i, r, s, a, o, c;
258
258
  const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
259
259
  return {
260
260
  agentType: lt(e.presenter),
@@ -269,7 +269,7 @@ function Gt(e) {
269
269
  },
270
270
  temperature: (a = e.llm) == null ? void 0 : a.temperature,
271
271
  knowledgeSource: n == null ? void 0 : n.knowledge_source,
272
- starterQuestionsCount: (d = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : d.length,
272
+ starterQuestionsCount: (c = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : c.length,
273
273
  topicsToAvoid: n == null ? void 0 : n.topics_to_avoid,
274
274
  maxResponseLength: n == null ? void 0 : n.max_response_length,
275
275
  agentId: e.id,
@@ -280,12 +280,12 @@ function Gt(e) {
280
280
  }
281
281
  const Zt = (e) => e.reduce((n, i) => n + i, 0), et = (e) => Zt(e) / e.length;
282
282
  function en(e, n, i) {
283
- var t, c, h;
283
+ var t, d, h;
284
284
  const { event: r, ...s } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: o } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
285
285
  return {
286
286
  ...s,
287
287
  llm: { ...s.llm, template: a },
288
- script: { ...s.script, provider: { ...(c = s == null ? void 0 : s.script) == null ? void 0 : c.provider, language: o } },
288
+ script: { ...s.script, provider: { ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider, language: o } },
289
289
  stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (h = n == null ? void 0 : n.presenter) == null ? void 0 : h.stitch : void 0,
290
290
  ...i
291
291
  };
@@ -312,7 +312,7 @@ function nn(e) {
312
312
  async track(r, s, a) {
313
313
  if (!this.isEnabled)
314
314
  return Promise.resolve();
315
- const { audioPath: o, ...d } = s || {}, t = a || Date.now(), c = {
315
+ const { audioPath: o, ...c } = s || {}, t = a || Date.now(), d = {
316
316
  method: "POST",
317
317
  headers: {
318
318
  "Content-Type": "application/x-www-form-urlencoded"
@@ -323,7 +323,7 @@ function nn(e) {
323
323
  event: r,
324
324
  properties: {
325
325
  ...this.additionalProperties,
326
- ...d,
326
+ ...c,
327
327
  agentId: this.agentId,
328
328
  source: n,
329
329
  token: this.token,
@@ -338,19 +338,19 @@ function nn(e) {
338
338
  ])
339
339
  })
340
340
  };
341
- return fetch(tn, c).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
341
+ return fetch(tn, d).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
342
342
  },
343
343
  linkTrack(r, s, a, o) {
344
344
  i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), o.includes(a) || o.push(a);
345
- const d = i[r];
346
- if (d.events[a] = { props: s }, d.resolvedDependencies.push(a), o.every(
347
- (c) => d.resolvedDependencies.includes(c)
345
+ const c = i[r];
346
+ if (c.events[a] = { props: s }, c.resolvedDependencies.push(a), o.every(
347
+ (d) => c.resolvedDependencies.includes(d)
348
348
  )) {
349
- const c = o.reduce((h, g) => d.events[g] ? { ...h, ...d.events[g].props } : h, {});
350
- this.track(r, c), d.resolvedDependencies = d.resolvedDependencies.filter(
349
+ const d = o.reduce((h, g) => c.events[g] ? { ...h, ...c.events[g].props } : h, {});
350
+ this.track(r, d), c.resolvedDependencies = c.resolvedDependencies.filter(
351
351
  (h) => !o.includes(h)
352
352
  ), o.forEach((h) => {
353
- delete d.events[h];
353
+ delete c.events[h];
354
354
  });
355
355
  }
356
356
  }
@@ -366,7 +366,7 @@ function Ve() {
366
366
  }
367
367
  const oe = Ve(), je = Ve(), nt = Ve();
368
368
  function gt(e) {
369
- return e === O.Playground ? { headers: { [Kt]: "true" } } : {};
369
+ return e === O.Playground ? { headers: { [Nt]: "true" } } : {};
370
370
  }
371
371
  async function ht(e, n, i, r, s = !1, a) {
372
372
  try {
@@ -399,8 +399,8 @@ function on(e, n, i, r) {
399
399
  };
400
400
  }
401
401
  const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), sn = {
402
- [I.ChatAnswer]: X.Answer,
403
- [I.ChatPartial]: X.Partial
402
+ [M.ChatAnswer]: X.Answer,
403
+ [M.ChatPartial]: X.Partial
404
404
  };
405
405
  function cn(e, n, i) {
406
406
  const r = (n.timestamp - e.timestamp) / 1e3;
@@ -464,7 +464,7 @@ function un(e) {
464
464
  return {};
465
465
  }
466
466
  function rt(e, n, i) {
467
- const r = e.map((t, c) => c === 0 ? i ? {
467
+ const r = e.map((t, d) => d === 0 ? i ? {
468
468
  timestamp: t.timestamp,
469
469
  duration: 0,
470
470
  rtt: t.rtt,
@@ -500,28 +500,28 @@ function rt(e, n, i) {
500
500
  freezeDuration: t.freezeDuration
501
501
  } : {
502
502
  timestamp: t.timestamp,
503
- duration: n * c / 1e3,
503
+ duration: n * d / 1e3,
504
504
  rtt: t.rtt,
505
- bytesReceived: t.bytesReceived - e[c - 1].bytesReceived,
506
- bitrate: (t.bytesReceived - e[c - 1].bytesReceived) * 8 / (n / 1e3),
507
- packetsReceived: t.packetsReceived - e[c - 1].packetsReceived,
508
- packetsLost: t.packetsLost - e[c - 1].packetsLost,
509
- framesDropped: t.framesDropped - e[c - 1].framesDropped,
510
- framesDecoded: t.framesDecoded - e[c - 1].framesDecoded,
505
+ bytesReceived: t.bytesReceived - e[d - 1].bytesReceived,
506
+ bitrate: (t.bytesReceived - e[d - 1].bytesReceived) * 8 / (n / 1e3),
507
+ packetsReceived: t.packetsReceived - e[d - 1].packetsReceived,
508
+ packetsLost: t.packetsLost - e[d - 1].packetsLost,
509
+ framesDropped: t.framesDropped - e[d - 1].framesDropped,
510
+ framesDecoded: t.framesDecoded - e[d - 1].framesDecoded,
511
511
  jitter: t.jitter,
512
- jitterBufferDelay: t.jitterBufferDelay - e[c - 1].jitterBufferDelay,
513
- jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[c - 1].jitterBufferEmittedCount,
514
- avgJitterDelayInInterval: (t.jitterBufferDelay - e[c - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[c - 1].jitterBufferEmittedCount),
512
+ jitterBufferDelay: t.jitterBufferDelay - e[d - 1].jitterBufferDelay,
513
+ jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
514
+ avgJitterDelayInInterval: (t.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
515
515
  framesPerSecond: t.framesPerSecond,
516
- freezeCount: t.freezeCount - e[c - 1].freezeCount,
517
- freezeDuration: t.freezeDuration - e[c - 1].freezeDuration
518
- }), s = dn(r), a = s.reduce((t, c) => t + (c.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), d = r.filter((t) => !!t.rtt).map((t) => t.rtt);
516
+ freezeCount: t.freezeCount - e[d - 1].freezeCount,
517
+ freezeDuration: t.freezeDuration - e[d - 1].freezeDuration
518
+ }), s = dn(r), a = s.reduce((t, d) => t + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), c = r.filter((t) => !!t.rtt).map((t) => t.rtt);
519
519
  return {
520
520
  webRTCStats: {
521
521
  anomalies: s,
522
- minRtt: Math.min(...d),
523
- avgRtt: et(d),
524
- maxRtt: Math.max(...d),
522
+ minRtt: Math.min(...c),
523
+ avgRtt: et(c),
524
+ maxRtt: Math.max(...c),
525
525
  aggregateReport: cn(e[0], e[e.length - 1], a),
526
526
  minJitterDelayInInterval: Math.min(...o),
527
527
  maxJitterDelayInInterval: Math.max(...o),
@@ -539,16 +539,16 @@ function wt(e, n) {
539
539
  }
540
540
  const Se = 10;
541
541
  function ln(e, n) {
542
- let i = !1, r = !1, s = null, a = 0, o = 0, d = {};
542
+ let i = !1, r = !1, s = null, a = 0, o = 0, c = {};
543
543
  async function t() {
544
544
  if (i) {
545
545
  try {
546
- const c = await e();
547
- if (!c) {
546
+ const d = await e();
547
+ if (!d) {
548
548
  s = setTimeout(t, Se);
549
549
  return;
550
550
  }
551
- const h = wt(c, "audio");
551
+ const h = wt(d, "audio");
552
552
  if (!h) {
553
553
  s = setTimeout(t, Se);
554
554
  return;
@@ -558,9 +558,9 @@ function ln(e, n) {
558
558
  a = g, o = l, r = !0, s = setTimeout(t, Se);
559
559
  return;
560
560
  }
561
- const v = g - a, L = l - o;
562
- if (a = g, o = l, L > 0 && v > 0) {
563
- i = !1, n(d);
561
+ const v = g - a, P = l - o;
562
+ if (a = g, o = l, P > 0 && v > 0) {
563
+ i = !1, n(c);
564
564
  return;
565
565
  }
566
566
  } catch {
@@ -569,54 +569,54 @@ function ln(e, n) {
569
569
  }
570
570
  }
571
571
  return {
572
- arm(c = {}) {
573
- d = c, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t, Se);
572
+ arm(d = {}) {
573
+ c = d, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t, Se);
574
574
  },
575
575
  destroy() {
576
576
  i = !1, s !== null && (clearTimeout(s), s = null);
577
577
  }
578
578
  };
579
579
  }
580
- const Me = 100, fn = Math.max(Math.ceil(400 / Me), 1), mn = 0.25, gn = 0.28;
580
+ const ke = 100, fn = Math.max(Math.ceil(400 / ke), 1), mn = 0.25, gn = 0.28;
581
581
  function hn() {
582
582
  let e = 0, n, i, r = 0;
583
583
  return (s) => {
584
584
  const a = wt(s, "video");
585
585
  if (!a)
586
586
  return { isReceiving: !1, avgJitterDelayInInterval: r };
587
- const o = a.jitterBufferDelay, d = a.jitterBufferEmittedCount;
588
- if (i && d > i) {
589
- const h = o - n, g = d - i;
587
+ const o = a.jitterBufferDelay, c = a.jitterBufferEmittedCount;
588
+ if (i && c > i) {
589
+ const h = o - n, g = c - i;
590
590
  r = h / g;
591
591
  }
592
- n = o, i = d;
593
- const t = a.framesDecoded, c = t - e > 0;
594
- return e = t, { isReceiving: c, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
592
+ n = o, i = c;
593
+ const t = a.framesDecoded, d = t - e > 0;
594
+ return e = t, { isReceiving: d, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
595
595
  };
596
596
  }
597
597
  function yt(e, n, i, r, s) {
598
- let a = null, o = [], d, t = 0, c = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
599
- const L = hn();
600
- async function K() {
598
+ let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
599
+ const P = hn();
600
+ async function N() {
601
601
  const B = await e();
602
602
  if (!B)
603
603
  return;
604
- const { isReceiving: F, avgJitterDelayInInterval: M, freezeCount: k } = L(B), Y = un(B);
604
+ const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: k } = P(B), Y = un(B);
605
605
  if (F)
606
- t = 0, l = k - v, g = M < mn ? ae.Strong : M > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0), c || (r == null || r(T.Start), d = o[o.length - 1], o = [], c = !0), o.push(Y);
607
- else if (c && (t++, t >= fn)) {
608
- const Q = rt(o, Me, d);
609
- r == null || r(T.Stop, Q), n() || i(), v = k, c = !1;
606
+ t = 0, l = k - v, g = I < mn ? ae.Strong : I > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0), d || (r == null || r(E.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
607
+ else if (d && (t++, t >= fn)) {
608
+ const Q = rt(o, ke, c);
609
+ r == null || r(E.Stop, Q), n() || i(), v = k, d = !1;
610
610
  }
611
611
  }
612
612
  return {
613
613
  start: () => {
614
- a || (a = setInterval(K, Me));
614
+ a || (a = setInterval(N, ke));
615
615
  },
616
616
  stop: () => {
617
617
  a && (clearInterval(a), a = null);
618
618
  },
619
- getReport: () => rt(o, Me, d)
619
+ getReport: () => rt(o, ke, c)
620
620
  };
621
621
  }
622
622
  const it = 2e4;
@@ -642,36 +642,36 @@ const wn = {
642
642
  var Ue = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ue || {});
643
643
  function Be(e, n, i) {
644
644
  var r, s;
645
- throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, P.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
645
+ throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, x.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
646
646
  }
647
647
  async function yn(e, n, i) {
648
648
  var Je;
649
- const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: d } = await pn(), { callbacks: t, auth: c, baseURL: h, analytics: g } = i;
649
+ const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await pn(), { callbacks: t, auth: d, baseURL: h, analytics: g } = i;
650
650
  let l = null, v = !1;
651
- const L = se.Fluent;
652
- let K = null;
651
+ const P = se.Fluent;
652
+ let N = null;
653
653
  const B = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
654
- let M = null, k = null, Y = null, Q = !1;
654
+ let I = null, k = null, Y = null, Q = !1;
655
655
  l = new s({
656
656
  adaptiveStream: !1,
657
657
  // Must be false to use mediaStreamTrack directly
658
658
  dynacast: !0
659
659
  });
660
660
  let U = null, te = W.Idle, ne = !0;
661
- const x = on(c, h || Ee, e, t.onError);
662
- let N, H, re, de = !0;
661
+ const $ = on(d, h || Ee, e, t.onError);
662
+ let K, H, re, de = !0;
663
663
  try {
664
- const u = await x.createStream({
664
+ const u = await $.createStream({
665
665
  transport: n.transport,
666
666
  chat_persist: n.chat_persist ?? !0
667
- }), { id: m, session_token: p, session_url: S, interrupt_enabled: A } = u;
668
- (Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), N = m, H = p, re = S, de = A ?? !0, await l.prepareConnection(re, H);
667
+ }), { id: m, session_token: p, session_url: S, interrupt_enabled: _ } = u;
668
+ (Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H = p, re = S, de = _ ?? !0, await l.prepareConnection(re, H);
669
669
  } catch (u) {
670
670
  Be(u, r, t);
671
671
  }
672
- if (!re || !H || !N)
672
+ if (!re || !H || !K)
673
673
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
674
- l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected, _).on(a.TrackSubscribed, J).on(a.TrackUnsubscribed, w).on(a.DataReceived, z).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
674
+ l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, J).on(a.TrackUnsubscribed, w).on(a.DataReceived, z).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
675
675
  function ue(u, m) {
676
676
  var p;
677
677
  m != null && m.isLocal && (oe.update(), te === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), te = W.Idle));
@@ -683,32 +683,32 @@ async function yn(e, n, i) {
683
683
  `Track subscription timeout - no track subscribed within ${it / 1e3} seconds after connect`
684
684
  ), U = null, g.track("connectivity-error", {
685
685
  error: "Track subscription timeout",
686
- sessionId: N
687
- }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: N }), Le("internal:track-subscription-timeout");
686
+ sessionId: K
687
+ }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: K }), Le("internal:track-subscription-timeout");
688
688
  }, it);
689
689
  } catch (u) {
690
690
  Be(u, r, t);
691
691
  }
692
692
  g.enrich({
693
- "stream-type": L
693
+ "stream-type": P
694
694
  });
695
695
  function f(u) {
696
- var m, p, S, A;
696
+ var m, p, S, _;
697
697
  switch (r("Connection state changed:", u), u) {
698
698
  case o.Connecting:
699
- r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, P.Connecting, "livekit:connecting");
699
+ r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, x.Connecting, "livekit:connecting");
700
700
  break;
701
701
  case o.Connected:
702
702
  r("LiveKit room connected successfully"), v = !0;
703
703
  break;
704
704
  case o.Disconnected:
705
- r("LiveKit room disconnected"), v = !1, Q = !1, B.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, P.Disconnected, "livekit:disconnected");
705
+ r("LiveKit room disconnected"), v = !1, Q = !1, B.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, x.Disconnected, "livekit:disconnected");
706
706
  break;
707
707
  case o.Reconnecting:
708
- r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, P.Connecting, "livekit:reconnecting");
708
+ r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, x.Connecting, "livekit:reconnecting");
709
709
  break;
710
710
  case o.SignalReconnecting:
711
- r("LiveKit room signal reconnecting..."), (A = t.onConnectionStateChange) == null || A.call(t, P.Connecting, "livekit:signal-reconnecting");
711
+ r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, x.Connecting, "livekit:signal-reconnecting");
712
712
  break;
713
713
  }
714
714
  }
@@ -719,68 +719,72 @@ async function yn(e, n, i) {
719
719
  function R(u) {
720
720
  r("Participant connected:", u.identity);
721
721
  }
722
- function _(u) {
722
+ function A(u) {
723
723
  r("Participant disconnected:", u.identity), Le("livekit:participant-disconnected");
724
724
  }
725
725
  function D() {
726
726
  var u;
727
- Y !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
727
+ Y !== E.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = E.Start, (u = t.onVideoStateChange) == null || u.call(t, E.Start));
728
728
  }
729
729
  function b(u) {
730
730
  var m;
731
- Y !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
731
+ Y !== E.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = E.Stop, (m = t.onVideoStateChange) == null || m.call(t, E.Stop, u));
732
732
  }
733
733
  function J(u, m, p) {
734
- var A, j, q;
734
+ var _, L, q;
735
735
  r(`Track subscribed: ${u.kind} from ${p.identity}`);
736
736
  const S = u.mediaStreamTrack;
737
737
  if (!S) {
738
738
  r(`No mediaStreamTrack available for ${u.kind}`);
739
739
  return;
740
740
  }
741
- K ? (K.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (K = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = ln(
741
+ N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = ln(
742
742
  () => u.getRTCStatsReport(),
743
743
  ({ sttLatency: V, serviceLatency: ie }) => {
744
744
  var Oe, We, He;
745
745
  const ye = oe.get(!0);
746
746
  let ve = 0;
747
747
  if (V) {
748
- const qe = ((We = (Oe = M == null ? void 0 : M.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
748
+ const qe = ((We = (Oe = I == null ? void 0 : I.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
749
749
  ve = qe > 0 ? Math.round(qe * 1e3) : 0;
750
750
  }
751
751
  const fe = ye > 0 ? ye + (V ?? 0) + ve : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
752
752
  (He = t.onFirstAudioDetected) == null || He.call(t, { latency: fe, networkLatency: ce });
753
753
  }
754
- )), u.kind === "video" && ((A = t.onStreamReady) == null || A.call(t), r("CALLBACK: onSrcObjectReady"), (j = t.onSrcObjectReady) == null || j.call(t, K), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, P.Connected, "livekit:track-subscribed")), M = yt(
754
+ )), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (L = t.onSrcObjectReady) == null || L.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, x.Connected, "livekit:track-subscribed")), I = yt(
755
755
  () => u.getRTCStatsReport(),
756
756
  () => v,
757
757
  Vt,
758
758
  (V, ie) => {
759
- r(`Video state change: ${V}`), V === T.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), D()) : V === T.Stop && b(ie);
759
+ r(`Video state change: ${V}`), V === E.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), D()) : V === E.Stop && b(ie);
760
760
  }
761
- ), M.start());
761
+ ), I.start());
762
762
  }
763
763
  function w(u, m, p) {
764
- r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (b(M == null ? void 0 : M.getReport()), M == null || M.stop(), M = null);
764
+ r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (b(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
765
765
  }
766
766
  function y(u, m) {
767
767
  var S;
768
768
  const p = sn[u];
769
769
  p && ((S = t.onMessage) == null || S.call(t, p, { event: p, ...m }));
770
770
  }
771
- function E(u, m) {
772
- var p, S, A;
773
- if (u === I.ToolCalling) {
774
- te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, I.ToolCalling, m);
771
+ function T(u, m) {
772
+ var p, S, _, L;
773
+ if (u === M.ToolCallStarted) {
774
+ te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, M.ToolCallStarted, m);
775
775
  return;
776
776
  }
777
- u === I.ToolResult && ((A = t.onToolEvent) == null || A.call(t, I.ToolResult, m));
777
+ if (u === M.ToolCallDone) {
778
+ (_ = t.onToolEvent) == null || _.call(t, M.ToolCallDone, m);
779
+ return;
780
+ }
781
+ u === M.ToolCallError && ((L = t.onToolEvent) == null || L.call(t, M.ToolCallError, m));
778
782
  }
779
- function $(u, m) {
780
- var p, S, A, j, q;
781
- if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === I.StreamVideoCreated) {
782
- te = W.Talking, (A = t.onAgentActivityStateChange) == null || A.call(t, W.Talking), k == null || k.arm({
783
- sttLatency: (j = m == null ? void 0 : m.stt) == null ? void 0 : j.latency,
783
+ function j(u, m) {
784
+ var p, S, _, L, q;
785
+ if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === M.StreamVideoCreated) {
786
+ te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), k == null || k.arm({
787
+ sttLatency: (L = m == null ? void 0 : m.stt) == null ? void 0 : L.latency,
784
788
  serviceLatency: m == null ? void 0 : m.serviceLatency
785
789
  });
786
790
  return;
@@ -788,12 +792,12 @@ async function yn(e, n, i) {
788
792
  ne && (te = W.Idle, (q = t.onAgentActivityStateChange) == null || q.call(t, W.Idle));
789
793
  }
790
794
  function G(u, m) {
791
- var j, q, V, ie;
792
- const p = ((q = (j = M == null ? void 0 : M.getReport()) == null ? void 0 : j.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, A = { ...m, downstreamNetworkLatency: S };
793
- i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (A.sentiment = {
795
+ var L, q, V, ie;
796
+ const p = ((q = (L = I == null ? void 0 : I.getReport()) == null ? void 0 : L.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: S };
797
+ i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (_.sentiment = {
794
798
  id: m.metadata.sentiment.id,
795
799
  name: m.metadata.sentiment.sentiment
796
- }), (ie = t.onMessage) == null || ie.call(t, u, A), $(u, m);
800
+ }), (ie = t.onMessage) == null || ie.call(t, u, _), j(u, m);
797
801
  }
798
802
  function he(u, m) {
799
803
  var p;
@@ -803,48 +807,49 @@ async function yn(e, n, i) {
803
807
  });
804
808
  }
805
809
  const Z = {
806
- [I.ChatAnswer]: y,
807
- [I.ChatPartial]: y,
808
- [I.ToolCalling]: E,
809
- [I.ToolResult]: E,
810
- [I.StreamVideoCreated]: G,
811
- [I.StreamVideoDone]: G,
812
- [I.StreamVideoError]: G,
813
- [I.StreamVideoRejected]: G,
814
- [I.ChatAudioTranscribed]: he
810
+ [M.ChatAnswer]: y,
811
+ [M.ChatPartial]: y,
812
+ [M.ToolCallStarted]: T,
813
+ [M.ToolCallDone]: T,
814
+ [M.ToolCallError]: T,
815
+ [M.StreamVideoCreated]: G,
816
+ [M.StreamVideoDone]: G,
817
+ [M.StreamVideoError]: G,
818
+ [M.StreamVideoRejected]: G,
819
+ [M.ChatAudioTranscribed]: he
815
820
  };
816
821
  function z(u, m, p, S) {
817
- const A = new TextDecoder().decode(u);
822
+ const _ = new TextDecoder().decode(u);
818
823
  try {
819
- const j = JSON.parse(A), q = S || j.subject;
820
- if (r("Data received:", { subject: q, data: j }), !q) return;
824
+ const L = JSON.parse(_), q = S || L.subject;
825
+ if (r("Data received:", { subject: q, data: L }), !q) return;
821
826
  const V = Z[q];
822
- V == null || V(q, j);
823
- } catch (j) {
824
- r("Failed to parse data channel message:", j);
827
+ V == null || V(q, L);
828
+ } catch (L) {
829
+ r("Failed to parse data channel message:", L);
825
830
  }
826
831
  }
827
832
  function ee(u) {
828
833
  var m;
829
- r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: N });
834
+ r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
830
835
  }
831
836
  function De(u) {
832
837
  var m;
833
- r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: N });
838
+ r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
834
839
  }
835
840
  function le(u, m, p) {
836
841
  r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
837
842
  }
838
- function ke(u, m, p) {
839
- for (const [S, A] of p)
840
- if (A.source === m && A.track) {
841
- const j = A.track.mediaStreamTrack;
842
- if (j === u || (j == null ? void 0 : j.id) === u.id)
843
- return A;
843
+ function Me(u, m, p) {
844
+ for (const [S, _] of p)
845
+ if (_.source === m && _.track) {
846
+ const L = _.track.mediaStreamTrack;
847
+ if (L === u || (L == null ? void 0 : L.id) === u.id)
848
+ return _;
844
849
  }
845
850
  return null;
846
851
  }
847
- async function pe(u, m, p, S, A, j) {
852
+ async function pe(u, m, p, S, _, L) {
848
853
  var ye, ve, fe;
849
854
  if (!v || !l)
850
855
  throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
@@ -855,7 +860,7 @@ async function yn(e, n, i) {
855
860
  const q = p(m);
856
861
  if (q.length === 0)
857
862
  throw new Error(`No ${S} track found in the provided MediaStream`);
858
- const V = q[0], ie = ke(V, S, A());
863
+ const V = q[0], ie = Me(V, S, _());
859
864
  if (ie) {
860
865
  r(`${S} track is already published, skipping`, {
861
866
  trackId: V.id,
@@ -865,7 +870,7 @@ async function yn(e, n, i) {
865
870
  }
866
871
  if ((fe = u.publication) != null && fe.track) {
867
872
  const ce = u.publication.track.mediaStreamTrack;
868
- ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await j());
873
+ ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await L());
869
874
  }
870
875
  r(`Publishing ${S} track from provided MediaStream`, { trackId: V.id }), u.isPublishing = !0;
871
876
  try {
@@ -891,12 +896,12 @@ async function yn(e, n, i) {
891
896
  B,
892
897
  u,
893
898
  (m) => m.getAudioTracks(),
894
- d.Source.Microphone,
899
+ c.Source.Microphone,
895
900
  () => l.localParticipant.audioTrackPublications,
896
- _e
901
+ Ae
897
902
  );
898
903
  }
899
- async function _e() {
904
+ async function Ae() {
900
905
  return we(B, "Microphone");
901
906
  }
902
907
  async function Ct(u) {
@@ -904,29 +909,29 @@ async function yn(e, n, i) {
904
909
  F,
905
910
  u,
906
911
  (m) => m.getVideoTracks(),
907
- d.Source.Camera,
912
+ c.Source.Camera,
908
913
  () => l.localParticipant.videoTrackPublications,
909
- Ae
914
+ _e
910
915
  );
911
916
  }
912
- async function Ae() {
917
+ async function _e() {
913
918
  return we(F, "Camera");
914
919
  }
915
920
  function St() {
916
- K && (K.getTracks().forEach((u) => u.stop()), K = null);
921
+ N && (N.getTracks().forEach((u) => u.stop()), N = null);
917
922
  }
918
923
  async function be(u, m) {
919
924
  var p, S;
920
925
  if (!v || !l) {
921
926
  r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(Re), {
922
- sessionId: N
927
+ sessionId: K
923
928
  });
924
929
  return;
925
930
  }
926
931
  try {
927
932
  await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
928
- } catch (A) {
929
- r("Failed to send message:", A), (S = t.onError) == null || S.call(t, new Error(Re), { sessionId: N });
933
+ } catch (_) {
934
+ r("Failed to send message:", _), (S = t.onError) == null || S.call(t, new Error(Re), { sessionId: K });
930
935
  }
931
936
  }
932
937
  async function Rt(u) {
@@ -935,7 +940,7 @@ async function yn(e, n, i) {
935
940
  const S = JSON.parse(u).topic;
936
941
  return be("", S);
937
942
  } catch (p) {
938
- r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: N });
943
+ r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
939
944
  }
940
945
  }
941
946
  function Tt(u) {
@@ -947,7 +952,7 @@ async function yn(e, n, i) {
947
952
  }
948
953
  async function Le(u) {
949
954
  var m, p;
950
- U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, P.Disconnecting, u), await Promise.all([_e(), Ae()]), await l.disconnect()), St(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
955
+ U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([Ae(), _e()]), await l.disconnect()), St(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
951
956
  }
952
957
  return {
953
958
  speak(u) {
@@ -967,39 +972,39 @@ async function yn(e, n, i) {
967
972
  }
968
973
  if (!l || !re || !H)
969
974
  throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
970
- r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, P.Connecting, "user:reconnect");
975
+ r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, x.Connecting, "user:reconnect");
971
976
  try {
972
977
  if (await l.connect(re, H), r("Room reconnected"), v = !0, l.remoteParticipants.size === 0) {
973
978
  if (r("Waiting for agent to join..."), !await new Promise((S) => {
974
- const A = setTimeout(() => {
975
- l == null || l.off(a.ParticipantConnected, j), S(!1);
976
- }, 5e3), j = () => {
977
- clearTimeout(A), l == null || l.off(a.ParticipantConnected, j), S(!0);
979
+ const _ = setTimeout(() => {
980
+ l == null || l.off(a.ParticipantConnected, L), S(!1);
981
+ }, 5e3), L = () => {
982
+ clearTimeout(_), l == null || l.off(a.ParticipantConnected, L), S(!0);
978
983
  };
979
- l == null || l.on(a.ParticipantConnected, j);
984
+ l == null || l.on(a.ParticipantConnected, L);
980
985
  }))
981
986
  throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
982
987
  r("Agent joined, reconnection successful");
983
988
  }
984
989
  } catch (p) {
985
- throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, P.Fail, "user:reconnect-failed"), p;
990
+ throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, x.Fail, "user:reconnect-failed"), p;
986
991
  }
987
992
  },
988
993
  sendDataChannelMessage: Rt,
989
994
  sendTextMessage: Tt,
990
995
  publishMicrophoneStream: vt,
991
- unpublishMicrophoneStream: _e,
996
+ unpublishMicrophoneStream: Ae,
992
997
  publishCameraStream: Ct,
993
- unpublishCameraStream: Ae,
998
+ unpublishCameraStream: _e,
994
999
  registerRpcMethod(u, m) {
995
1000
  l == null || l.registerRpcMethod(u, m);
996
1001
  },
997
1002
  unregisterRpcMethod(u) {
998
1003
  l == null || l.unregisterRpcMethod(u);
999
1004
  },
1000
- sessionId: N,
1001
- streamId: N,
1002
- streamType: L,
1005
+ sessionId: K,
1006
+ streamId: K,
1007
+ streamType: P,
1003
1008
  interruptAvailable: de,
1004
1009
  isInterruptible: ne
1005
1010
  };
@@ -1022,7 +1027,7 @@ function Cn(e, n, i) {
1022
1027
  }
1023
1028
  async function Sn(e, n) {
1024
1029
  const i = {
1025
- type: I.StreamInterrupt,
1030
+ type: M.StreamInterrupt,
1026
1031
  videoId: n,
1027
1032
  timestamp: Date.now()
1028
1033
  };
@@ -1036,8 +1041,8 @@ async function Rn(e) {
1036
1041
  }
1037
1042
  function Tn(e) {
1038
1043
  return new Promise((n, i) => {
1039
- const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: h = null } = r || {}, g = new WebSocket(`${s}?authorization=${encodeURIComponent(mt(a, o))}`);
1040
- g.onmessage = d, g.onclose = c, g.onerror = (l) => {
1044
+ const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage: c = null, onOpen: t = null, onClose: d = null, onError: h = null } = r || {}, g = new WebSocket(`${s}?authorization=${encodeURIComponent(mt(a, o))}`);
1045
+ g.onmessage = c, g.onclose = d, g.onerror = (l) => {
1041
1046
  console.error(l), h == null || h("Websocket failed to connect", l), i(l);
1042
1047
  }, g.onopen = (l) => {
1043
1048
  t == null || t(l), n(g);
@@ -1057,19 +1062,19 @@ async function En(e) {
1057
1062
  }
1058
1063
  return i;
1059
1064
  }
1060
- async function kn(e, n, i, r) {
1065
+ async function Mn(e, n, i, r) {
1061
1066
  const s = i != null && i.onMessage ? [i.onMessage] : [], a = await En({
1062
1067
  auth: e,
1063
1068
  host: n,
1064
1069
  externalId: r,
1065
1070
  callbacks: {
1066
1071
  onError: (o) => {
1067
- var d;
1068
- return (d = i.onError) == null ? void 0 : d.call(i, new Dt(o));
1072
+ var c;
1073
+ return (c = i.onError) == null ? void 0 : c.call(i, new Dt(o));
1069
1074
  },
1070
1075
  onMessage(o) {
1071
- const d = JSON.parse(o.data);
1072
- s.forEach((t) => t(d.event, d));
1076
+ const c = JSON.parse(o.data);
1077
+ s.forEach((t) => t(c.event, c));
1073
1078
  }
1074
1079
  }
1075
1080
  });
@@ -1079,7 +1084,7 @@ async function kn(e, n, i, r) {
1079
1084
  subscribeToEvents: (o) => s.push(o)
1080
1085
  };
1081
1086
  }
1082
- function Mn(e) {
1087
+ function kn(e) {
1083
1088
  if (e.answer !== void 0)
1084
1089
  return e.answer;
1085
1090
  let n = 0, i = "";
@@ -1102,99 +1107,99 @@ function In(e, n, i) {
1102
1107
  };
1103
1108
  n.messages.push(s), i == null || i([...n.messages], "user");
1104
1109
  }
1105
- function Dn(e, n, i, r, s) {
1110
+ function Dn(e, n, i, r, s, a) {
1106
1111
  if (e === X.Transcribe && n.content) {
1107
1112
  In(n, r, s);
1108
1113
  return;
1109
1114
  }
1110
1115
  if (!(e === X.Partial || e === X.Answer))
1111
1116
  return;
1112
- const a = r.messages[r.messages.length - 1];
1113
- let o;
1114
- if ((a == null ? void 0 : a.role) === "assistant")
1115
- o = a;
1116
- else if (!a || a.transcribed && a.role === "user")
1117
- o = {
1117
+ const o = r.messages[r.messages.length - 1], c = n.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== n.id;
1118
+ let t;
1119
+ if ((o == null ? void 0 : o.role) === "assistant" && !c)
1120
+ t = o;
1121
+ else if (!o || o.transcribed && o.role === "user" || c)
1122
+ c && a(), t = {
1118
1123
  id: n.id || `assistant-${Date.now()}`,
1119
1124
  role: n.role || "assistant",
1120
1125
  content: n.content || "",
1121
1126
  parts: [],
1122
1127
  created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString()
1123
- }, r.messages.push(o);
1128
+ }, r.messages.push(t);
1124
1129
  else
1125
1130
  return;
1126
- const { content: d, sequence: t } = n;
1127
- e === X.Partial ? i[t] = d : i.answer = d;
1128
- const c = Mn(i);
1129
- (o.content !== c || e === X.Answer) && (o.content = c, o.parts = Te(c), s == null || s([...r.messages], e));
1131
+ const { content: d, sequence: h } = n;
1132
+ e === X.Partial ? i[h] = d : i.answer = d;
1133
+ const g = kn(i);
1134
+ (t.content !== g || e === X.Answer) && (t.content = g, t.parts = Te(g), s == null || s([...r.messages], e));
1130
1135
  }
1131
- function _n(e, n, i, r, s) {
1136
+ function An(e, n, i, r, s) {
1132
1137
  let a = {};
1133
1138
  const o = () => a = {};
1134
- let d = "answer";
1135
- const t = (c, h) => {
1139
+ let c = "answer";
1140
+ const t = (d, h) => {
1136
1141
  var g, l;
1137
- h === "user" && o(), d = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, h);
1142
+ h === "user" && o(), c = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, d, h);
1138
1143
  };
1139
1144
  return {
1140
1145
  clearQueue: o,
1141
- onMessage: (c, h) => {
1146
+ onMessage: (d, h) => {
1142
1147
  var g, l;
1143
1148
  if ("content" in h) {
1144
- const v = c === I.ChatAnswer ? X.Answer : c === I.ChatAudioTranscribed ? X.Transcribe : c;
1145
- Dn(v, h, a, n, t), v === X.Answer && e.track("agent-message-received", {
1149
+ const v = d === M.ChatAnswer ? X.Answer : d === M.ChatAudioTranscribed ? X.Transcribe : d;
1150
+ Dn(v, h, a, n, t, o), v === X.Answer && e.track("agent-message-received", {
1146
1151
  content: h.content,
1147
1152
  messages: n.messages.length,
1148
1153
  mode: n.chatMode
1149
1154
  });
1150
1155
  } else {
1151
- const v = I, L = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], K = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
1152
- if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
1156
+ const v = M, P = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], N = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
1157
+ if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
1153
1158
  const F = n.messages[n.messages.length - 1];
1154
1159
  if ((F == null ? void 0 : F.role) === "assistant") {
1155
- const M = { ...F, sentiment: h.sentiment };
1156
- n.messages[n.messages.length - 1] = M, t == null || t([...n.messages], d);
1160
+ const I = { ...F, sentiment: h.sentiment };
1161
+ n.messages[n.messages.length - 1] = I, t == null || t([...n.messages], c);
1157
1162
  }
1158
1163
  }
1159
- if (L.includes(c)) {
1160
- const F = c.split("/")[1];
1161
- K.includes(c) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, c, ["done"]);
1164
+ if (P.includes(d)) {
1165
+ const F = d.split("/")[1];
1166
+ N.includes(d) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, d, ["done"]);
1162
1167
  }
1163
- K.includes(c) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${c}`), { data: h })), h.event === v.StreamDone && s();
1168
+ N.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: h })), h.event === v.StreamDone && s();
1164
1169
  }
1165
1170
  }
1166
1171
  };
1167
1172
  }
1168
- function An(e, n, i, r) {
1173
+ function _n(e, n, i, r) {
1169
1174
  const s = ze(e, `${n}/agents/${i}`, r);
1170
1175
  return {
1171
1176
  createStream(a, o) {
1172
1177
  return s.post("/streams", a, { signal: o });
1173
1178
  },
1174
- startConnection(a, o, d, t) {
1179
+ startConnection(a, o, c, t) {
1175
1180
  return s.post(
1176
1181
  `/streams/${a}/sdp`,
1177
1182
  {
1178
- session_id: d,
1183
+ session_id: c,
1179
1184
  answer: o
1180
1185
  },
1181
1186
  { signal: t }
1182
1187
  );
1183
1188
  },
1184
- addIceCandidate(a, o, d, t) {
1189
+ addIceCandidate(a, o, c, t) {
1185
1190
  return s.post(
1186
1191
  `/streams/${a}/ice`,
1187
1192
  {
1188
- session_id: d,
1193
+ session_id: c,
1189
1194
  ...o
1190
1195
  },
1191
1196
  { signal: t }
1192
1197
  );
1193
1198
  },
1194
- sendStreamRequest(a, o, d) {
1199
+ sendStreamRequest(a, o, c) {
1195
1200
  return s.post(`/streams/${a}`, {
1196
1201
  session_id: o,
1197
- ...d
1202
+ ...c
1198
1203
  });
1199
1204
  },
1200
1205
  close(a, o) {
@@ -1206,21 +1211,21 @@ const bn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window
1206
1211
  function at(e) {
1207
1212
  switch (e) {
1208
1213
  case "connected":
1209
- return P.Connected;
1214
+ return x.Connected;
1210
1215
  case "checking":
1211
- return P.Connecting;
1216
+ return x.Connecting;
1212
1217
  case "failed":
1213
- return P.Fail;
1218
+ return x.Fail;
1214
1219
  case "new":
1215
- return P.New;
1220
+ return x.New;
1216
1221
  case "closed":
1217
- return P.Closed;
1222
+ return x.Closed;
1218
1223
  case "disconnected":
1219
- return P.Disconnected;
1224
+ return x.Disconnected;
1220
1225
  case "completed":
1221
- return P.Completed;
1226
+ return x.Completed;
1222
1227
  default:
1223
- return P.New;
1228
+ return x.New;
1224
1229
  }
1225
1230
  }
1226
1231
  const Ln = (e) => (n) => {
@@ -1239,7 +1244,7 @@ function Pn({
1239
1244
  report: r,
1240
1245
  log: s
1241
1246
  }) {
1242
- e === T.Start && n === T.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && n === T.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, r));
1247
+ e === E.Start && n === E.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && n === E.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, r));
1243
1248
  }
1244
1249
  function xn({
1245
1250
  statsSignal: e,
@@ -1249,7 +1254,7 @@ function xn({
1249
1254
  report: s,
1250
1255
  log: a
1251
1256
  }) {
1252
- e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, s)), n === T.Start ? r == null || r(W.Talking) : n === T.Stop && (r == null || r(W.Idle));
1257
+ e === E.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, s)), n === E.Start ? r == null || r(W.Talking) : n === E.Stop && (r == null || r(W.Idle));
1253
1258
  }
1254
1259
  function ot({
1255
1260
  statsSignal: e,
@@ -1269,11 +1274,11 @@ function ot({
1269
1274
  log: o
1270
1275
  });
1271
1276
  }
1272
- async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, d) {
1277
+ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, c) {
1273
1278
  var J;
1274
- const t = pt(i, "WebRTCStreamingManager"), c = Ln(t);
1275
- let h = !1, g = !1, l = T.Stop, v = T.Stop;
1276
- const { startConnection: L, sendStreamRequest: K, close: B, createStream: F, addIceCandidate: M } = An(
1279
+ const t = pt(i, "WebRTCStreamingManager"), d = Ln(t);
1280
+ let h = !1, g = !1, l = E.Stop, v = E.Stop;
1281
+ const { startConnection: P, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } = _n(
1277
1282
  s,
1278
1283
  a,
1279
1284
  e,
@@ -1285,9 +1290,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1285
1290
  session_id: U,
1286
1291
  fluent: te,
1287
1292
  interrupt_enabled: ne
1288
- } = await F(n, d);
1293
+ } = await F(n, c);
1289
1294
  (J = r.onStreamCreated) == null || J.call(r, { stream_id: k, session_id: U, agent_id: e });
1290
- const x = new bn({ iceServers: Q }), N = x.createDataChannel("JanusDataChannel");
1295
+ const $ = new bn({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
1291
1296
  if (!U)
1292
1297
  throw new Error("Could not create session_id");
1293
1298
  const H = te ? se.Fluent : se.Legacy;
@@ -1296,9 +1301,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1296
1301
  });
1297
1302
  const re = n.stream_warmup && !te, de = () => h, ue = () => {
1298
1303
  var w;
1299
- h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, P.Connected));
1304
+ h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, x.Connected));
1300
1305
  }, f = yt(
1301
- () => x.getStats(),
1306
+ () => $.getStats(),
1302
1307
  de,
1303
1308
  ue,
1304
1309
  (w, y) => ot({
@@ -1315,11 +1320,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1315
1320
  return (y = r.onConnectivityStateChange) == null ? void 0 : y.call(r, w);
1316
1321
  }
1317
1322
  );
1318
- f.start(), x.onicecandidate = (w) => {
1323
+ f.start(), $.onicecandidate = (w) => {
1319
1324
  var y;
1320
1325
  t("peerConnection.onicecandidate", w);
1321
1326
  try {
1322
- w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? M(
1327
+ w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? I(
1323
1328
  k,
1324
1329
  {
1325
1330
  candidate: w.candidate.candidate,
@@ -1327,12 +1332,12 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1327
1332
  sdpMLineIndex: w.candidate.sdpMLineIndex
1328
1333
  },
1329
1334
  U,
1330
- d
1331
- ) : M(k, { candidate: null }, U, d);
1332
- } catch (E) {
1333
- (y = r.onError) == null || y.call(r, E, { streamId: k });
1335
+ c
1336
+ ) : I(k, { candidate: null }, U, c);
1337
+ } catch (T) {
1338
+ (y = r.onError) == null || y.call(r, T, { streamId: k });
1334
1339
  }
1335
- }, N.onopen = () => {
1340
+ }, K.onopen = () => {
1336
1341
  g = !0, (!re || h) && ue();
1337
1342
  };
1338
1343
  const C = (w) => {
@@ -1340,11 +1345,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1340
1345
  (y = r.onVideoIdChange) == null || y.call(r, w);
1341
1346
  };
1342
1347
  function R(w, y) {
1343
- if (w === I.StreamStarted && typeof y == "object" && "metadata" in y) {
1344
- const E = y.metadata;
1345
- C(E.videoId);
1348
+ if (w === M.StreamStarted && typeof y == "object" && "metadata" in y) {
1349
+ const T = y.metadata;
1350
+ C(T.videoId);
1346
1351
  }
1347
- w === I.StreamDone && C(null), l = w === I.StreamStarted ? T.Start : T.Stop, ot({
1352
+ w === M.StreamDone && C(null), l = w === M.StreamStarted ? E.Start : E.Stop, ot({
1348
1353
  statsSignal: H === se.Legacy ? v : void 0,
1349
1354
  dataChannelSignal: l,
1350
1355
  onVideoStateChange: r.onVideoStateChange,
@@ -1353,37 +1358,37 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1353
1358
  log: t
1354
1359
  });
1355
1360
  }
1356
- function _(w, y) {
1357
- var $;
1358
- const E = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
1359
- E && o.enrich({ streamMetadata: E }), ($ = r.onStreamReady) == null || $.call(r);
1361
+ function A(w, y) {
1362
+ var j;
1363
+ const T = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
1364
+ T && o.enrich({ streamMetadata: T }), (j = r.onStreamReady) == null || j.call(r);
1360
1365
  }
1361
1366
  const D = {
1362
- [I.StreamStarted]: R,
1363
- [I.StreamDone]: R,
1364
- [I.StreamReady]: _
1367
+ [M.StreamStarted]: R,
1368
+ [M.StreamDone]: R,
1369
+ [M.StreamReady]: A
1365
1370
  };
1366
- N.onmessage = (w) => {
1367
- var $;
1368
- const { subject: y, data: E } = c(w.data);
1369
- ($ = D[y]) == null || $.call(D, y, E);
1370
- }, x.oniceconnectionstatechange = () => {
1371
+ K.onmessage = (w) => {
1372
+ var j;
1373
+ const { subject: y, data: T } = d(w.data);
1374
+ (j = D[y]) == null || j.call(D, y, T);
1375
+ }, $.oniceconnectionstatechange = () => {
1371
1376
  var y;
1372
- t("peerConnection.oniceconnectionstatechange => " + x.iceConnectionState);
1373
- const w = at(x.iceConnectionState);
1374
- w !== P.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
1375
- }, x.ontrack = (w) => {
1377
+ t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
1378
+ const w = at($.iceConnectionState);
1379
+ w !== x.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
1380
+ }, $.ontrack = (w) => {
1376
1381
  var y;
1377
1382
  t("peerConnection.ontrack", w), t("CALLBACK: onSrcObjectReady"), (y = r.onSrcObjectReady) == null || y.call(r, w.streams[0]);
1378
- }, await x.setRemoteDescription(Y), t("set remote description OK");
1379
- const b = await x.createAnswer();
1380
- return t("create answer OK"), await x.setLocalDescription(b), t("set local description OK"), await L(k, b, U, d), t("start connection OK"), {
1383
+ }, await $.setRemoteDescription(Y), t("set remote description OK");
1384
+ const b = await $.createAnswer();
1385
+ return t("create answer OK"), await $.setLocalDescription(b), t("set local description OK"), await P(k, b, U, c), t("start connection OK"), {
1381
1386
  /**
1382
1387
  * Method to send request to server to get clip or talk depend on you payload
1383
1388
  * @param payload
1384
1389
  */
1385
1390
  speak(w) {
1386
- return K(k, U, w);
1391
+ return N(k, U, w);
1387
1392
  },
1388
1393
  /**
1389
1394
  * Method to close RTC connection
@@ -1391,19 +1396,19 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1391
1396
  async disconnect() {
1392
1397
  var w;
1393
1398
  if (k) {
1394
- const y = at(x.iceConnectionState);
1395
- if (x) {
1396
- if (y === P.New) {
1399
+ const y = at($.iceConnectionState);
1400
+ if ($) {
1401
+ if (y === x.New) {
1397
1402
  f.stop();
1398
1403
  return;
1399
1404
  }
1400
- x.close(), x.oniceconnectionstatechange = null, x.onnegotiationneeded = null, x.onicecandidate = null, x.ontrack = null;
1405
+ $.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
1401
1406
  }
1402
1407
  try {
1403
- y === P.Connected && await B(k, U).catch((E) => {
1408
+ y === x.Connected && await B(k, U).catch((T) => {
1404
1409
  });
1405
- } catch (E) {
1406
- t("Error on close stream connection", E);
1410
+ } catch (T) {
1411
+ t("Error on close stream connection", T);
1407
1412
  }
1408
1413
  (w = r.onAgentActivityStateChange) == null || w.call(r, W.Idle), f.stop();
1409
1414
  }
@@ -1412,17 +1417,17 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
1412
1417
  * Method to send data channel messages to the server
1413
1418
  */
1414
1419
  sendDataChannelMessage(w) {
1415
- var y, E;
1416
- if (!h || N.readyState !== "open") {
1420
+ var y, T;
1421
+ if (!h || K.readyState !== "open") {
1417
1422
  t("Data channel is not ready for sending messages"), (y = r.onError) == null || y.call(r, new Error("Data channel is not ready for sending messages"), {
1418
1423
  streamId: k
1419
1424
  });
1420
1425
  return;
1421
1426
  }
1422
1427
  try {
1423
- N.send(w);
1424
- } catch ($) {
1425
- t("Error sending data channel message", $), (E = r.onError) == null || E.call(r, $, { streamId: k });
1428
+ K.send(w);
1429
+ } catch (j) {
1430
+ t("Error sending data channel message", j), (T = r.onError) == null || T.call(r, j, { streamId: k });
1426
1431
  }
1427
1432
  },
1428
1433
  /**
@@ -1449,9 +1454,9 @@ async function jn(e, n, i, r) {
1449
1454
  case "v2": {
1450
1455
  const { version: a, ...o } = n;
1451
1456
  switch (o.transport.provider) {
1452
- case Ke.Livekit:
1453
- const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => vn);
1454
- return d(s, o, i);
1457
+ case Ne.Livekit:
1458
+ const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() => vn);
1459
+ return c(s, o, i);
1455
1460
  default:
1456
1461
  throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
1457
1462
  }
@@ -1464,11 +1469,11 @@ const Bn = "cht";
1464
1469
  function Fn() {
1465
1470
  return {
1466
1471
  transport: {
1467
- provider: Ke.Livekit
1472
+ provider: Ne.Livekit
1468
1473
  }
1469
1474
  };
1470
1475
  }
1471
- function Kn(e) {
1476
+ function Nn(e) {
1472
1477
  var s, a;
1473
1478
  const { streamOptions: n } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
1474
1479
  plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
@@ -1481,8 +1486,8 @@ function Kn(e) {
1481
1486
  fluent: n == null ? void 0 : n.fluent
1482
1487
  }, ...i && { end_user_data: i } };
1483
1488
  }
1484
- function Nn(e, n) {
1485
- return Ne(e.presenter.type) ? { version: Fe.V2, ...Fn() } : { version: Fe.V1, ...Kn(n) };
1489
+ function Kn(e, n) {
1490
+ return Ke(e.presenter.type) ? { version: Fe.V2, ...Fn() } : { version: Fe.V1, ...Nn(n) };
1486
1491
  }
1487
1492
  function zn(e, n, i) {
1488
1493
  i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
@@ -1491,7 +1496,7 @@ function Vn(e, n, i, r, s) {
1491
1496
  s === se.Fluent ? Un(e, n, i, r, s) : Jn(e, n, i, r, s);
1492
1497
  }
1493
1498
  function Un(e, n, i, r, s) {
1494
- e === T.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === T.Stop && r.track("stream-session", {
1499
+ e === E.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === E.Stop && r.track("stream-session", {
1495
1500
  event: "stop",
1496
1501
  is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
1497
1502
  background: n.presenter.type === "clip" && n.presenter.background,
@@ -1500,9 +1505,9 @@ function Un(e, n, i, r, s) {
1500
1505
  });
1501
1506
  }
1502
1507
  function st(e, n, i, r, s) {
1503
- e === T.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
1504
- I.StreamVideoCreated
1505
- ]) : e === T.Stop && i.linkTrack(
1508
+ e === E.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
1509
+ M.StreamVideoCreated
1510
+ ]) : e === E.Stop && i.linkTrack(
1506
1511
  "agent-video",
1507
1512
  {
1508
1513
  event: "stop",
@@ -1511,16 +1516,16 @@ function st(e, n, i, r, s) {
1511
1516
  "stream-type": r
1512
1517
  },
1513
1518
  "done",
1514
- [I.StreamVideoDone]
1519
+ [M.StreamVideoDone]
1515
1520
  );
1516
1521
  }
1517
1522
  function Jn(e, n, i, r, s) {
1518
- e === T.Start ? r.linkTrack(
1523
+ e === E.Start ? r.linkTrack(
1519
1524
  "agent-video",
1520
1525
  { event: "start", latency: oe.get(!0), "stream-type": s },
1521
1526
  "start",
1522
- [I.StreamVideoCreated]
1523
- ) : e === T.Stop && r.linkTrack(
1527
+ [M.StreamVideoCreated]
1528
+ ) : e === E.Stop && r.linkTrack(
1524
1529
  "agent-video",
1525
1530
  {
1526
1531
  event: "stop",
@@ -1530,18 +1535,18 @@ function Jn(e, n, i, r, s) {
1530
1535
  ...i
1531
1536
  },
1532
1537
  "done",
1533
- [I.StreamVideoDone]
1538
+ [M.StreamVideoDone]
1534
1539
  );
1535
1540
  }
1536
1541
  function ct(e, n, i, r) {
1537
1542
  return oe.reset(), nt.update(), new Promise(async (s, a) => {
1538
1543
  try {
1539
- let o, d = !1;
1540
- const t = Nn(e, n);
1544
+ let o, c = !1;
1545
+ const t = Kn(e, n);
1541
1546
  i.enrich({
1542
1547
  "stream-version": t.version.toString()
1543
1548
  });
1544
- let c = null;
1549
+ let d = null;
1545
1550
  const h = e.presenter.type === "expressive";
1546
1551
  o = await jn(
1547
1552
  e,
@@ -1552,12 +1557,12 @@ function ct(e, n, i, r) {
1552
1557
  callbacks: {
1553
1558
  ...n.callbacks,
1554
1559
  onConnectionStateChange: (g, l) => {
1555
- var v, L;
1556
- (L = (v = n.callbacks).onConnectionStateChange) == null || L.call(v, g), zn(g, l, i), g === P.Connected && (o ? s(o) : d = !0);
1560
+ var v, P;
1561
+ (P = (v = n.callbacks).onConnectionStateChange) == null || P.call(v, g), zn(g, l, i), g === x.Connected && (o ? s(o) : c = !0);
1557
1562
  },
1558
1563
  onVideoStateChange: (g, l) => {
1559
- var v, L;
1560
- (L = (v = n.callbacks).onVideoStateChange) == null || L.call(v, g), Vn(
1564
+ var v, P;
1565
+ (P = (v = n.callbacks).onVideoStateChange) == null || P.call(v, g), Vn(
1561
1566
  g,
1562
1567
  e,
1563
1568
  l,
@@ -1567,23 +1572,23 @@ function ct(e, n, i, r) {
1567
1572
  },
1568
1573
  onAgentActivityStateChange: (g) => {
1569
1574
  var l, v;
1570
- (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), c = (L) => {
1575
+ (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), d = (P) => {
1571
1576
  st(
1572
- T.Start,
1577
+ E.Start,
1573
1578
  e,
1574
1579
  i,
1575
1580
  o.streamType,
1576
- L
1577
- ), c = null;
1578
- }, h || c({ latency: oe.get(!0) })) : (je.reset(), c = null, st(
1579
- T.Stop,
1581
+ P
1582
+ ), d = null;
1583
+ }, h || d({ latency: oe.get(!0) })) : (je.reset(), d = null, st(
1584
+ E.Stop,
1580
1585
  e,
1581
1586
  i,
1582
1587
  o.streamType
1583
1588
  ));
1584
1589
  },
1585
1590
  onFirstAudioDetected: (g) => {
1586
- c == null || c(g);
1591
+ d == null || d(g);
1587
1592
  },
1588
1593
  onStreamReady: () => {
1589
1594
  const g = nt.get(!0);
@@ -1592,7 +1597,7 @@ function ct(e, n, i, r) {
1592
1597
  }
1593
1598
  },
1594
1599
  r
1595
- ), d && s(o);
1600
+ ), c && s(o);
1596
1601
  } catch (o) {
1597
1602
  a(o);
1598
1603
  }
@@ -1601,12 +1606,12 @@ function ct(e, n, i, r) {
1601
1606
  async function On(e, n, i, r, s) {
1602
1607
  var h, g, l, v;
1603
1608
  const a = async () => {
1604
- if (Ne(e.presenter.type)) {
1605
- const L = await ct(e, n, r), K = `${Bn}_${L.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
1609
+ if (Ke(e.presenter.type)) {
1610
+ const P = await ct(e, n, r), N = `${Bn}_${P.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
1606
1611
  return { chatResult: {
1607
1612
  chatMode: O.Functional,
1608
1613
  chat: {
1609
- id: K,
1614
+ id: N,
1610
1615
  agent_id: e.id,
1611
1616
  owner_id: e.owner_id ?? "",
1612
1617
  created: B,
@@ -1616,9 +1621,9 @@ async function On(e, n, i, r, s) {
1616
1621
  chat_mode: O.Functional,
1617
1622
  messages: []
1618
1623
  }
1619
- }, streamingManager: L };
1624
+ }, streamingManager: P };
1620
1625
  } else {
1621
- const L = new AbortController(), K = L.signal;
1626
+ const P = new AbortController(), N = P.signal;
1622
1627
  let B;
1623
1628
  try {
1624
1629
  const F = ht(
@@ -1628,23 +1633,23 @@ async function On(e, n, i, r, s) {
1628
1633
  n.mode,
1629
1634
  n.persistentChat,
1630
1635
  s
1631
- ), M = ct(e, n, r, K).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, M]);
1636
+ ), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, I]);
1632
1637
  return { chatResult: k, streamingManager: Y };
1633
1638
  } catch (F) {
1634
- throw L.abort(), B && await B.disconnect().catch(() => {
1639
+ throw P.abort(), B && await B.disconnect().catch(() => {
1635
1640
  }), F;
1636
1641
  }
1637
1642
  }
1638
- }, { chatResult: o, streamingManager: d } = await a(), { chat: t, chatMode: c } = o;
1639
- return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (h = n.callbacks).onModeChange) == null || g.call(h, c), c !== O.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new It(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
1643
+ }, { chatResult: o, streamingManager: c } = await a(), { chat: t, chatMode: d } = o;
1644
+ return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new It(d)), c == null || c.disconnect(), { chat: t }) : { chat: t, streamingManager: c };
1640
1645
  }
1641
1646
  async function qn(e, n) {
1642
1647
  var H, re, de, ue;
1643
1648
  let i = !0, r = null;
1644
- const s = n.mixpanelKey || zt, a = n.wsURL || Nt, o = n.baseURL || Ee, d = n.mode || O.Functional, t = {
1649
+ const s = n.mixpanelKey || zt, a = n.wsURL || Kt, o = n.baseURL || Ee, c = n.mode || O.Functional, t = {
1645
1650
  messages: [],
1646
- chatMode: d
1647
- }, c = nn({
1651
+ chatMode: c
1652
+ }, d = nn({
1648
1653
  token: s,
1649
1654
  agentId: e,
1650
1655
  isEnabled: n.enableAnalitics,
@@ -1652,83 +1657,83 @@ async function qn(e, n) {
1652
1657
  mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
1653
1658
  }), h = Date.now();
1654
1659
  tt(() => {
1655
- c.track("agent-sdk", { event: "init" }, h);
1660
+ d.track("agent-sdk", { event: "init" }, h);
1656
1661
  });
1657
1662
  const g = Xt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
1658
1663
  n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
1659
- const v = Ne(l.presenter.type);
1660
- c.enrich(Gt(l));
1661
- const { onMessage: L, clearQueue: K } = _n(c, t, n, l, () => {
1664
+ const v = Ke(l.presenter.type);
1665
+ d.enrich(Gt(l));
1666
+ const { onMessage: P, clearQueue: N } = An(d, t, n, l, () => {
1662
1667
  var f, C, R;
1663
- (f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, P.Disconnected);
1668
+ (f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, x.Disconnected);
1664
1669
  });
1665
1670
  t.messages = an(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
1666
1671
  const B = (f) => {
1667
1672
  r = f;
1668
1673
  }, F = ({ type: f }) => {
1669
- var R, _, D, b, J;
1670
- if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((_ = t.streamingManager) != null && _.isInterruptible)) return;
1674
+ var R, A, D, b, J;
1675
+ if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((A = t.streamingManager) != null && A.isInterruptible)) return;
1671
1676
  const C = t.messages[t.messages.length - 1];
1672
- c.track("agent-video-interrupt", {
1677
+ d.track("agent-video-interrupt", {
1673
1678
  type: f || "click",
1674
1679
  video_duration_to_interrupt: je.get(!0),
1675
1680
  message_duration_to_interrupt: oe.get(!0)
1676
1681
  }), C.interrupted = !0, (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "answer"), v ? Rn(t.streamingManager) : (Cn(t.streamingManager, (J = t.streamingManager) == null ? void 0 : J.streamType, r), Sn(t.streamingManager, r));
1677
- }, M = /* @__PURE__ */ new Map();
1682
+ }, I = /* @__PURE__ */ new Map();
1678
1683
  function k(f) {
1679
1684
  return async (C) => {
1680
- const R = M.get(f);
1685
+ const R = I.get(f);
1681
1686
  if (!R)
1682
1687
  throw new Error(`No handler registered for client tool: ${f}`);
1683
1688
  try {
1684
- const _ = JSON.parse(C.payload);
1685
- return await R(_);
1686
- } catch (_) {
1687
- throw new Error(`Client tool "${f}" failed: ${_.message}`);
1689
+ const A = JSON.parse(C.payload);
1690
+ return await R(A);
1691
+ } catch (A) {
1692
+ throw new Error(`Client tool "${f}" failed: ${A.message}`);
1688
1693
  }
1689
1694
  };
1690
1695
  }
1691
1696
  function Y() {
1692
- var f, C, R, _;
1693
- for (const [D] of M)
1694
- (C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (_ = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || _.call(R, D, k(D));
1697
+ var f, C, R, A;
1698
+ for (const [D] of I)
1699
+ (C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (A = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || A.call(R, D, k(D));
1695
1700
  }
1696
1701
  function Q(f, C) {
1697
- var _, D;
1698
- const R = !M.has(f);
1699
- M.set(f, C), R && ((D = (_ = t.streamingManager) == null ? void 0 : _.registerRpcMethod) == null || D.call(_, f, k(f)));
1702
+ var A, D;
1703
+ const R = !I.has(f);
1704
+ I.set(f, C), R && ((D = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || D.call(A, f, k(f)));
1700
1705
  }
1701
1706
  function U(f) {
1702
1707
  var C, R;
1703
- M.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
1708
+ I.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
1704
1709
  }
1705
1710
  const te = Date.now();
1706
1711
  tt(() => {
1707
- c.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
1712
+ d.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
1708
1713
  });
1709
1714
  async function ne(f) {
1710
- var J, w, y, E, $, G, he;
1711
- (w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J, P.Connecting), oe.reset(), f && !i && (delete t.chat, (E = (y = n.callbacks).onNewMessage) == null || E.call(y, [...t.messages], "answer"));
1712
- const C = d === O.DirectPlayback || v ? Promise.resolve(void 0) : kn(
1715
+ var J, w, y, T, j, G, he;
1716
+ (w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J, x.Connecting), oe.reset(), f && !i && (delete t.chat, (T = (y = n.callbacks).onNewMessage) == null || T.call(y, [...t.messages], "answer"));
1717
+ const C = c === O.DirectPlayback || v ? Promise.resolve(void 0) : Mn(
1713
1718
  n.auth,
1714
1719
  a,
1715
- { onMessage: L, onError: n.callbacks.onError },
1720
+ { onMessage: P, onError: n.callbacks.onError },
1716
1721
  n.externalId
1717
1722
  ), R = xe(
1718
1723
  () => On(
1719
1724
  l,
1720
1725
  {
1721
1726
  ...n,
1722
- mode: d,
1727
+ mode: c,
1723
1728
  callbacks: {
1724
1729
  ...n.callbacks,
1725
1730
  onVideoIdChange: B,
1726
- onMessage: L,
1731
+ onMessage: P,
1727
1732
  onInterruptDetected: F
1728
1733
  }
1729
1734
  },
1730
1735
  g,
1731
- c,
1736
+ d,
1732
1737
  t.chat
1733
1738
  ),
1734
1739
  {
@@ -1740,21 +1745,21 @@ async function qn(e, n) {
1740
1745
  }
1741
1746
  ).catch((Z) => {
1742
1747
  var z, ee;
1743
- throw N(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, P.Fail), Z;
1744
- }), [_, { streamingManager: D, chat: b }] = await Promise.all([C, R]);
1745
- b && b.id !== (($ = t.chat) == null ? void 0 : $.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = D, t.socketManager = _, t.chat = b, Y(), i = !1, c.enrich({
1748
+ throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, x.Fail), Z;
1749
+ }), [A, { streamingManager: D, chat: b }] = await Promise.all([C, R]);
1750
+ b && b.id !== ((j = t.chat) == null ? void 0 : j.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = D, t.socketManager = A, t.chat = b, Y(), i = !1, d.enrich({
1746
1751
  chatId: b == null ? void 0 : b.id,
1747
1752
  streamId: D == null ? void 0 : D.streamId,
1748
1753
  mode: t.chatMode
1749
- }), N((b == null ? void 0 : b.chat_mode) ?? d);
1754
+ }), K((b == null ? void 0 : b.chat_mode) ?? c);
1750
1755
  }
1751
- async function x() {
1752
- var f, C, R, _;
1753
- (f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (_ = (R = n.callbacks).onConnectionStateChange) == null || _.call(R, P.Disconnected);
1756
+ async function $() {
1757
+ var f, C, R, A;
1758
+ (f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R, x.Disconnected);
1754
1759
  }
1755
- async function N(f) {
1760
+ async function K(f) {
1756
1761
  var C, R;
1757
- f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await x(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
1762
+ f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
1758
1763
  }
1759
1764
  return {
1760
1765
  agent: l,
@@ -1768,10 +1773,10 @@ async function qn(e, n) {
1768
1773
  },
1769
1774
  starterMessages: ((ue = l.knowledge) == null ? void 0 : ue.starter_message) || [],
1770
1775
  getSTTToken: () => g.getSTTToken(l.id),
1771
- changeMode: N,
1772
- enrichAnalytics: c.enrich,
1776
+ changeMode: K,
1777
+ enrichAnalytics: d.enrich,
1773
1778
  async connect() {
1774
- await ne(!0), c.track("agent-chat", {
1779
+ await ne(!0), d.track("agent-chat", {
1775
1780
  event: "connect",
1776
1781
  mode: t.chatMode
1777
1782
  });
@@ -1780,22 +1785,22 @@ async function qn(e, n) {
1780
1785
  const f = t.streamingManager;
1781
1786
  if (v && (f != null && f.reconnect)) {
1782
1787
  try {
1783
- await f.reconnect(), c.track("agent-chat", {
1788
+ await f.reconnect(), d.track("agent-chat", {
1784
1789
  event: "reconnect",
1785
1790
  mode: t.chatMode
1786
1791
  });
1787
1792
  } catch {
1788
- await x(), await ne(!1);
1793
+ await $(), await ne(!1);
1789
1794
  }
1790
1795
  return;
1791
1796
  }
1792
- await x(), await ne(!1), c.track("agent-chat", {
1797
+ await $(), await ne(!1), d.track("agent-chat", {
1793
1798
  event: "reconnect",
1794
1799
  mode: t.chatMode
1795
1800
  });
1796
1801
  },
1797
1802
  async disconnect() {
1798
- await x(), c.track("agent-chat", {
1803
+ await $(), d.track("agent-chat", {
1799
1804
  event: "disconnect",
1800
1805
  mode: t.chatMode
1801
1806
  });
@@ -1825,8 +1830,8 @@ async function qn(e, n) {
1825
1830
  async chat(f) {
1826
1831
  var D, b, J, w, y;
1827
1832
  const C = () => {
1828
- if (ft(d))
1829
- throw new me(`${d} is enabled, chat is disabled`);
1833
+ if (ft(c))
1834
+ throw new me(`${c} is enabled, chat is disabled`);
1830
1835
  if (f.length >= 800)
1831
1836
  throw new me("Message cannot be more than 800 characters");
1832
1837
  if (f.length === 0)
@@ -1840,21 +1845,21 @@ async function qn(e, n) {
1840
1845
  throw new me("Chat is not initialized");
1841
1846
  }
1842
1847
  }, R = async () => {
1843
- var E, $;
1848
+ var T, j;
1844
1849
  if (!t.chat) {
1845
1850
  const G = await ht(
1846
1851
  l,
1847
1852
  g,
1848
- c,
1853
+ d,
1849
1854
  t.chatMode,
1850
1855
  n.persistentChat
1851
1856
  );
1852
1857
  if (!G.chat)
1853
- throw new Mt(t.chatMode, !!n.persistentChat);
1854
- t.chat = G.chat, ($ = (E = n.callbacks).onNewChat) == null || $.call(E, t.chat.id);
1858
+ throw new kt(t.chatMode, !!n.persistentChat);
1859
+ t.chat = G.chat, (j = (T = n.callbacks).onNewChat) == null || j.call(T, t.chat.id);
1855
1860
  }
1856
1861
  return t.chat.id;
1857
- }, _ = async (E, $) => {
1862
+ }, A = async (T, j) => {
1858
1863
  const G = t.chatMode === O.Playground;
1859
1864
  return xe(v && !G ? async () => {
1860
1865
  var z, ee;
@@ -1863,12 +1868,12 @@ async function qn(e, n) {
1863
1868
  var z, ee;
1864
1869
  return g.chat(
1865
1870
  l.id,
1866
- $,
1871
+ j,
1867
1872
  {
1868
1873
  chatMode: t.chatMode,
1869
1874
  streamId: (z = t.streamingManager) == null ? void 0 : z.streamId,
1870
1875
  sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
1871
- messages: E.map(({ matches: De, ...le }) => le)
1876
+ messages: T.map(({ matches: De, ...le }) => le)
1872
1877
  },
1873
1878
  {
1874
1879
  ...gt(t.chatMode),
@@ -1878,55 +1883,55 @@ async function qn(e, n) {
1878
1883
  }, {
1879
1884
  limit: 2,
1880
1885
  shouldRetryFn: (z) => {
1881
- var le, ke, pe, we;
1886
+ var le, Me, pe, we;
1882
1887
  const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
1883
- return !((ke = z == null ? void 0 : z.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, z), !1) : !0;
1888
+ return !((Me = z == null ? void 0 : z.message) == null ? void 0 : Me.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, z), !1) : !0;
1884
1889
  },
1885
1890
  onRetry: async () => {
1886
- await x(), await ne(!1);
1891
+ await $(), await ne(!1);
1887
1892
  }
1888
1893
  });
1889
1894
  };
1890
1895
  try {
1891
- K(), C(), t.messages.push({
1896
+ N(), C(), t.messages.push({
1892
1897
  id: ge(),
1893
1898
  role: "user",
1894
1899
  content: f,
1895
1900
  parts: Te(f),
1896
1901
  created_at: new Date(oe.update()).toISOString()
1897
1902
  }), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "user");
1898
- const E = await R(), $ = await _([...t.messages], E);
1903
+ const T = await R(), j = await A([...t.messages], T);
1899
1904
  return t.messages.push({
1900
1905
  id: ge(),
1901
1906
  role: "assistant",
1902
- content: $.result || "",
1903
- parts: Te($.result || ""),
1907
+ content: j.result || "",
1908
+ parts: Te(j.result || ""),
1904
1909
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1905
- context: $.context,
1906
- matches: $.matches
1907
- }), c.track("agent-message-send", {
1910
+ context: j.context,
1911
+ matches: j.matches
1912
+ }), d.track("agent-message-send", {
1908
1913
  event: "success",
1909
1914
  messages: t.messages.length + 1
1910
- }), $.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), c.track("agent-message-received", {
1915
+ }), j.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), d.track("agent-message-received", {
1911
1916
  latency: oe.get(!0),
1912
1917
  messages: t.messages.length
1913
- })), $;
1914
- } catch (E) {
1915
- throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
1918
+ })), j;
1919
+ } catch (T) {
1920
+ throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), d.track("agent-message-send", {
1916
1921
  event: "error",
1917
1922
  messages: t.messages.length
1918
- }), E;
1923
+ }), T;
1919
1924
  }
1920
1925
  },
1921
1926
  rate(f, C, R) {
1922
1927
  var b, J, w, y;
1923
- const _ = t.messages.find((E) => E.id === f);
1928
+ const A = t.messages.find((T) => T.id === f);
1924
1929
  if (t.chat) {
1925
- if (!_)
1930
+ if (!A)
1926
1931
  throw new Error("Message not found");
1927
1932
  } else throw new Error("Chat is not initialized");
1928
- const D = ((b = _.matches) == null ? void 0 : b.map((E) => [E.document_id, E.id])) ?? [];
1929
- return c.track("agent-rate", {
1933
+ const D = ((b = A.matches) == null ? void 0 : b.map((T) => [T.document_id, T.id])) ?? [];
1934
+ return d.track("agent-rate", {
1930
1935
  event: R ? "update" : "create",
1931
1936
  thumb: C === 1 ? "up" : "down",
1932
1937
  knowledge_id: ((J = l.knowledge) == null ? void 0 : J.id) ?? "",
@@ -1947,7 +1952,7 @@ async function qn(e, n) {
1947
1952
  deleteRate(f) {
1948
1953
  if (!t.chat)
1949
1954
  throw new Error("Chat is not initialized");
1950
- return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
1955
+ return d.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
1951
1956
  },
1952
1957
  async speak(f) {
1953
1958
  var D, b, J;
@@ -1975,7 +1980,7 @@ async function qn(e, n) {
1975
1980
  return f;
1976
1981
  }
1977
1982
  const R = C();
1978
- if (c.track("agent-speak", R), oe.update(), t.messages && R.type === "text" && (t.messages.push({
1983
+ if (d.track("agent-speak", R), oe.update(), t.messages && R.type === "text" && (t.messages.push({
1979
1984
  id: ge(),
1980
1985
  role: "assistant",
1981
1986
  content: R.input,
@@ -2002,23 +2007,23 @@ async function qn(e, n) {
2002
2007
  export {
2003
2008
  W as AgentActivityState,
2004
2009
  bt as AgentStatus,
2005
- Mt as ChatCreationFailed,
2010
+ kt as ChatCreationFailed,
2006
2011
  O as ChatMode,
2007
2012
  It as ChatModeDowngraded,
2008
2013
  X as ChatProgress,
2009
- P as ConnectionState,
2014
+ x as ConnectionState,
2010
2015
  ae as ConnectivityState,
2011
2016
  $t as DocumentType,
2012
2017
  xt as KnowledgeType,
2013
- At as PlanGroup,
2018
+ _t as PlanGroup,
2014
2019
  jt as Providers,
2015
2020
  Lt as RateState,
2016
- I as StreamEvents,
2021
+ M as StreamEvents,
2017
2022
  se as StreamType,
2018
- T as StreamingState,
2023
+ E as StreamingState,
2019
2024
  Pt as Subject,
2020
- Ke as TransportProvider,
2021
- _t as UserPlan,
2025
+ Ne as TransportProvider,
2026
+ At as UserPlan,
2022
2027
  me as ValidationError,
2023
2028
  dt as VideoType,
2024
2029
  Bt as VoiceAccess,