@d-id/client-sdk 1.2.1-staging.341 → 1.2.1-staging.342

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ class G extends Error {
14
14
  };
15
15
  }
16
16
  }
17
- function gr(e) {
17
+ function hr(e) {
18
18
  return e instanceof Error && typeof e.kind == "string";
19
19
  }
20
20
  class Ze extends G {
@@ -37,8 +37,8 @@ function tt(e) {
37
37
  }
38
38
  class ze extends G {
39
39
  constructor(r, a, c = {}) {
40
- const i = tt(a);
41
- super(((i == null ? void 0 : i.description) ?? a).slice(0, 256), (i == null ? void 0 : i.kind) ?? "HttpError");
40
+ const s = tt(a);
41
+ super(((s == null ? void 0 : s.description) ?? a).slice(0, 256), (s == null ? void 0 : s.kind) ?? "HttpError");
42
42
  Z(this, "status");
43
43
  Z(this, "url");
44
44
  Z(this, "method");
@@ -83,8 +83,8 @@ class nt extends G {
83
83
  super(t, "WSError");
84
84
  }
85
85
  }
86
- var at = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(at || {}), it = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(it || {}), st = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(st || {}), ot = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ot || {}), A = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(A || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(z || {}), ct = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(dt || {}), lt = /* @__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))(lt || {}), Fe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Fe || {});
87
- const hr = (e) => {
86
+ var at = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(at || {}), st = /* @__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))(st || {}), it = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(it || {}), ot = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ot || {}), A = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(A || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(z || {}), ct = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(dt || {}), lt = /* @__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))(lt || {}), Fe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Fe || {});
87
+ const pr = (e) => {
88
88
  switch (e) {
89
89
  case "clip":
90
90
  return "clip";
@@ -97,7 +97,7 @@ const hr = (e) => {
97
97
  }
98
98
  };
99
99
  var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ae || {}), x = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(x || {}), b = /* @__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))(b || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(pe || {}), ut = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ut || {}), mt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(mt || {});
100
- const pr = (...e) => {
100
+ const wr = (...e) => {
101
101
  }, Ve = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
102
102
  const t = new Uint8Array(e);
103
103
  return window.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
@@ -154,8 +154,8 @@ function Rt(e) {
154
154
  for (De.lastIndex = 0; (r = De.exec(e)) !== null; )
155
155
  if (!t.some((o) => r.index >= o.index && r.index < o.index + o.length)) {
156
156
  const o = r[2], n = r[1];
157
- let s;
158
- kt(o) ? s = { type: "video", src: o, alt: n } : (s = { type: "image", src: o, alt: n }, o.toLowerCase().endsWith(".gif") && (s.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: s });
157
+ let i;
158
+ kt(o) ? i = { type: "video", src: o, alt: n } : (i = { type: "image", src: o, alt: n }, o.toLowerCase().endsWith(".gif") && (i.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: i });
159
159
  }
160
160
  for (Ie.lastIndex = 0; (r = Ie.exec(e)) !== null; )
161
161
  t.some((o) => r.index >= o.index && r.index < o.index + o.length) || t.push({
@@ -171,11 +171,11 @@ function Rt(e) {
171
171
  });
172
172
  if (t.length === 0)
173
173
  return [{ type: "text", text: e }];
174
- t.sort((i, o) => i.index - o.index);
174
+ t.sort((s, o) => s.index - o.index);
175
175
  const a = [];
176
176
  let c = 0;
177
- for (const i of t)
178
- i.index > c && a.push({ type: "text", text: e.slice(c, i.index) }), a.push(i.part), c = i.index + i.length;
177
+ for (const s of t)
178
+ s.index > c && a.push({ type: "text", text: e.slice(c, s.index) }), a.push(s.part), c = s.index + s.length;
179
179
  return c < e.length && a.push({ type: "text", text: e.slice(c) }), a;
180
180
  }
181
181
  let Ee = "", ue = [];
@@ -185,8 +185,8 @@ function ne(e) {
185
185
  function Dt(e, t) {
186
186
  let r;
187
187
  return {
188
- promise: new Promise((c, i) => {
189
- r = setTimeout(() => i(new Error(t)), e);
188
+ promise: new Promise((c, s) => {
189
+ r = setTimeout(() => s(new Error(t)), e);
190
190
  }),
191
191
  clear: () => clearTimeout(r)
192
192
  };
@@ -206,12 +206,12 @@ async function fe(e, t) {
206
206
  try {
207
207
  if (!r.timeout)
208
208
  return await e();
209
- const { promise: i, clear: o } = Dt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
210
- return await Promise.race([n, i]);
211
- } catch (i) {
212
- if (a = i, !r.shouldRetryFn(i) || c >= r.limit)
213
- throw i;
214
- await Ve(r.delayMs), r.onRetry(i);
209
+ const { promise: s, clear: o } = Dt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
210
+ return await Promise.race([n, s]);
211
+ } catch (s) {
212
+ if (a = s, !r.shouldRetryFn(s) || c >= r.limit)
213
+ throw s;
214
+ await Ve(r.delayMs), r.onRetry(s);
215
215
  }
216
216
  throw a;
217
217
  }
@@ -222,15 +222,15 @@ const It = (e) => fe(e, {
222
222
  shouldRetryFn: (t) => t.status === 429
223
223
  });
224
224
  function He(e, t = le, r, a) {
225
- const c = async (i, o) => {
226
- const { skipErrorHandler: n, ...s } = o || {};
225
+ const c = async (s, o) => {
226
+ const { skipErrorHandler: n, ...i } = o || {};
227
227
  let d;
228
228
  try {
229
229
  d = await It(
230
- () => fetch(t + (i != null && i.startsWith("/") ? i : `/${i}`), {
231
- ...s,
230
+ () => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
231
+ ...i,
232
232
  headers: {
233
- ...s.headers,
233
+ ...i.headers,
234
234
  Authorization: Ue(e, a),
235
235
  "Content-Type": "application/json"
236
236
  }
@@ -239,73 +239,73 @@ function He(e, t = le, r, a) {
239
239
  } catch (u) {
240
240
  if ((u == null ? void 0 : u.name) === "AbortError")
241
241
  throw u;
242
- const m = new rt(u, { url: i, method: s.method ?? "GET" });
243
- throw n || r == null || r(m, { url: i, options: s }), m;
242
+ const m = new rt(u, { url: s, method: i.method ?? "GET" });
243
+ throw n || r == null || r(m, { url: s, options: i }), m;
244
244
  }
245
245
  if (!d.ok) {
246
- const u = await d.text().catch(() => `Failed to fetch with status ${d.status}`), f = new ze(d.status, u, { url: i, method: s.method ?? "GET" });
247
- throw n || r == null || r(f, { url: i, options: s, headers: d.headers }), f;
246
+ const u = await d.text().catch(() => `Failed to fetch with status ${d.status}`), f = new ze(d.status, u, { url: s, method: i.method ?? "GET" });
247
+ throw n || r == null || r(f, { url: s, options: i, headers: d.headers }), f;
248
248
  }
249
249
  return d.json();
250
250
  };
251
251
  return {
252
- get(i, o) {
253
- return c(i, { ...o, method: "GET" });
252
+ get(s, o) {
253
+ return c(s, { ...o, method: "GET" });
254
254
  },
255
- post(i, o, n) {
256
- return c(i, { ...n, body: JSON.stringify(o), method: "POST" });
255
+ post(s, o, n) {
256
+ return c(s, { ...n, body: JSON.stringify(o), method: "POST" });
257
257
  },
258
- delete(i, o, n) {
259
- return c(i, { ...n, body: JSON.stringify(o), method: "DELETE" });
258
+ delete(s, o, n) {
259
+ return c(s, { ...n, body: JSON.stringify(o), method: "DELETE" });
260
260
  },
261
- patch(i, o, n) {
262
- return c(i, { ...n, body: JSON.stringify(o), method: "PATCH" });
261
+ patch(s, o, n) {
262
+ return c(s, { ...n, body: JSON.stringify(o), method: "PATCH" });
263
263
  }
264
264
  };
265
265
  }
266
266
  function Mt(e, t = le, r, a) {
267
267
  const c = He(e, `${t}/agents`, r, a);
268
268
  return {
269
- create(i, o) {
270
- return c.post("/", i, o);
269
+ create(s, o) {
270
+ return c.post("/", s, o);
271
271
  },
272
- getAgents(i, o) {
273
- return c.get(`/${i ? `?tag=${i}` : ""}`, o).then((n) => n ?? []);
272
+ getAgents(s, o) {
273
+ return c.get(`/${s ? `?tag=${s}` : ""}`, o).then((n) => n ?? []);
274
274
  },
275
- getById(i, o) {
276
- return c.get(`/${i}`, o);
275
+ getById(s, o) {
276
+ return c.get(`/${s}`, o);
277
277
  },
278
- delete(i, o) {
279
- return c.delete(`/${i}`, void 0, o);
278
+ delete(s, o) {
279
+ return c.delete(`/${s}`, void 0, o);
280
280
  },
281
- update(i, o, n) {
282
- return c.patch(`/${i}`, o, n);
281
+ update(s, o, n) {
282
+ return c.patch(`/${s}`, o, n);
283
283
  },
284
- newChat(i, o, n) {
285
- return c.post(`/${i}/chat`, o, n);
284
+ newChat(s, o, n) {
285
+ return c.post(`/${s}/chat`, o, n);
286
286
  },
287
- chat(i, o, n, s) {
288
- return c.post(`/${i}/chat/${o}`, n, s);
287
+ chat(s, o, n, i) {
288
+ return c.post(`/${s}/chat/${o}`, n, i);
289
289
  },
290
- createRating(i, o, n, s) {
291
- return c.post(`/${i}/chat/${o}/ratings`, n, s);
290
+ createRating(s, o, n, i) {
291
+ return c.post(`/${s}/chat/${o}/ratings`, n, i);
292
292
  },
293
- updateRating(i, o, n, s, d) {
294
- return c.patch(`/${i}/chat/${o}/ratings/${n}`, s, d);
293
+ updateRating(s, o, n, i, d) {
294
+ return c.patch(`/${s}/chat/${o}/ratings/${n}`, i, d);
295
295
  },
296
- deleteRating(i, o, n, s) {
297
- return c.delete(`/${i}/chat/${o}/ratings/${n}`, s);
296
+ deleteRating(s, o, n, i) {
297
+ return c.delete(`/${s}/chat/${o}/ratings/${n}`, i);
298
298
  },
299
- getSTTToken(i, o) {
300
- return c.get(`/${i}/stt-token`, o);
299
+ getSTTToken(s, o) {
300
+ return c.get(`/${s}/stt-token`, o);
301
301
  }
302
302
  };
303
303
  }
304
304
  function Et(e) {
305
- var c, i, o, n;
305
+ var c, s, o, n;
306
306
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", r = () => {
307
- const s = navigator.platform;
308
- return s.toLowerCase().includes("win") ? "Windows" : s.toLowerCase().includes("mac") ? "Mac OS X" : s.toLowerCase().includes("linux") ? "Linux" : "Unknown";
307
+ const i = navigator.platform;
308
+ return i.toLowerCase().includes("win") ? "Windows" : i.toLowerCase().includes("mac") ? "Mac OS X" : i.toLowerCase().includes("linux") ? "Linux" : "Unknown";
309
309
  }, a = e.presenter;
310
310
  return {
311
311
  $os: `${r()}`,
@@ -314,13 +314,13 @@ function Et(e) {
314
314
  origin: window.location.origin,
315
315
  agentType: Ke(a),
316
316
  agentVoice: {
317
- voiceId: (i = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : i.voice_id,
317
+ voiceId: (s = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : s.voice_id,
318
318
  provider: (n = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : n.type
319
319
  }
320
320
  };
321
321
  }
322
- function Tt(e) {
323
- var r, a, c, i, o, n;
322
+ function _t(e) {
323
+ var r, a, c, s, o, n;
324
324
  const t = (r = e.llm) == null ? void 0 : r.prompt_customization;
325
325
  return {
326
326
  agentType: Ke(e.presenter),
@@ -333,7 +333,7 @@ function Tt(e) {
333
333
  personality: t == null ? void 0 : t.personality,
334
334
  instructions: (c = e.llm) == null ? void 0 : c.instructions
335
335
  },
336
- temperature: (i = e.llm) == null ? void 0 : i.temperature,
336
+ temperature: (s = e.llm) == null ? void 0 : s.temperature,
337
337
  knowledgeSource: t == null ? void 0 : t.knowledge_source,
338
338
  starterQuestionsCount: (n = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : n.length,
339
339
  topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
@@ -344,32 +344,32 @@ function Tt(e) {
344
344
  ...e.access === "public" ? { from: "agent-template" } : {}
345
345
  };
346
346
  }
347
- const _t = (e) => {
347
+ const Tt = (e) => {
348
348
  try {
349
349
  return String((e == null ? void 0 : e.message) ?? e ?? "").slice(0, 256);
350
350
  } catch {
351
351
  return "Unknown error";
352
352
  }
353
- }, At = (e) => e.reduce((t, r) => t + r, 0), Te = (e) => At(e) / e.length;
353
+ }, At = (e) => e.reduce((t, r) => t + r, 0), _e = (e) => At(e) / e.length;
354
354
  function bt(e, t, r) {
355
- var s, d, u;
356
- const { event: a, ...c } = e, { template: i } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((s = t == null ? void 0 : t.presenter) == null ? void 0 : s.voice) || {};
355
+ var i, d, u;
356
+ const { event: a, ...c } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
357
357
  return {
358
358
  ...c,
359
- llm: { ...c.llm, template: i },
359
+ llm: { ...c.llm, template: s },
360
360
  script: { ...c.script, provider: { ...(d = c == null ? void 0 : c.script) == null ? void 0 : d.provider, language: o } },
361
361
  stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
362
362
  ...r
363
363
  };
364
364
  }
365
- function _e(e) {
365
+ function Te(e) {
366
366
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
367
367
  }
368
368
  function Ae(e) {
369
- return e instanceof G ? e.toJson() : { kind: "UnknownError", message: _t(e) || "UnknownError" };
369
+ return e instanceof G ? e.toJson() : { kind: "UnknownError", message: Tt(e) || "UnknownError" };
370
370
  }
371
- const xt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
372
- function Lt(e) {
371
+ const xt = "1.2.1-staging.342", Lt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
372
+ function Pt(e) {
373
373
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
374
374
  return {
375
375
  token: e.token || "testKey",
@@ -384,10 +384,10 @@ function Lt(e) {
384
384
  enrich(a) {
385
385
  this.additionalProperties = { ...this.additionalProperties, ...a };
386
386
  },
387
- async track(a, c, i) {
387
+ async track(a, c, s) {
388
388
  if (!this.isEnabled)
389
389
  return Promise.resolve();
390
- const { audioPath: o, ...n } = c || {}, s = i || Date.now(), d = {
390
+ const { audioPath: o, ...n } = c || {}, i = s || Date.now(), d = {
391
391
  method: "POST",
392
392
  headers: {
393
393
  "Content-Type": "application/x-www-form-urlencoded"
@@ -401,8 +401,10 @@ function Lt(e) {
401
401
  ...n,
402
402
  agentId: this.agentId,
403
403
  source: t,
404
+ emittedBy: "agents-sdk",
405
+ sdkVersion: xt,
404
406
  token: this.token,
405
- time: s,
407
+ time: i,
406
408
  $insert_id: this.getRandom(),
407
409
  origin: window.location.href,
408
410
  "Screen Height": window.screen.height || window.innerWidth,
@@ -413,12 +415,12 @@ function Lt(e) {
413
415
  ])
414
416
  })
415
417
  };
416
- return fetch(xt, d).catch((u) => console.error("Analytics tracking error:", u)), Promise.resolve();
418
+ return fetch(Lt, d).catch((u) => console.error("Analytics tracking error:", u)), Promise.resolve();
417
419
  },
418
- linkTrack(a, c, i, o) {
419
- r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(i) || o.push(i);
420
+ linkTrack(a, c, s, o) {
421
+ r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
420
422
  const n = r[a];
421
- if (n.events[i] = { props: c }, n.resolvedDependencies.push(i), o.every(
423
+ if (n.events[s] = { props: c }, n.resolvedDependencies.push(s), o.every(
422
424
  (d) => n.resolvedDependencies.includes(d)
423
425
  )) {
424
426
  const d = o.reduce((u, f) => n.events[f] ? { ...u, ...n.events[f].props } : u, {});
@@ -443,32 +445,32 @@ const q = ve(), ge = ve(), be = ve();
443
445
  function Oe(e) {
444
446
  return e === A.Playground ? { headers: { [ht]: "true" } } : {};
445
447
  }
446
- async function qe(e, t, r, a, c = !1, i) {
447
- return !i && !We(a) && (i = await t.newChat(e.id, { persist: c }, Oe(a)), r.track("agent-chat", {
448
+ async function qe(e, t, r, a, c = !1, s) {
449
+ return !s && !We(a) && (s = await t.newChat(e.id, { persist: c }, Oe(a)), r.track("agent-chat", {
448
450
  event: "created",
449
- chatId: i.id,
451
+ chatId: s.id,
450
452
  mode: a
451
- })), { chat: i, chatMode: (i == null ? void 0 : i.chat_mode) ?? a };
453
+ })), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? a };
452
454
  }
453
- function Pt(e) {
455
+ function jt(e) {
454
456
  return e && e.length > 0 ? e : [];
455
457
  }
456
- function jt(e) {
458
+ function Bt(e) {
457
459
  return new Promise((t, r) => {
458
- const { callbacks: a, host: c, auth: i, externalId: o } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: u = null } = a || {}, f = new WebSocket(`${c}?authorization=${encodeURIComponent(Ue(i, o))}`);
460
+ const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: u = null } = a || {}, f = new WebSocket(`${c}?authorization=${encodeURIComponent(Ue(s, o))}`);
459
461
  f.onmessage = n, f.onclose = d, f.onerror = (m) => {
460
462
  console.error(m), u == null || u("Websocket failed to connect", m), r(m);
461
463
  }, f.onopen = (m) => {
462
- s == null || s(m), t(f);
464
+ i == null || i(m), t(f);
463
465
  };
464
466
  });
465
467
  }
466
- async function Bt(e) {
468
+ async function $t(e) {
467
469
  const { retries: t = 1 } = e;
468
470
  let r = null;
469
471
  for (let a = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; a++)
470
472
  try {
471
- r = await jt(e);
473
+ r = await Bt(e);
472
474
  } catch (c) {
473
475
  if (a === t)
474
476
  throw c;
@@ -476,8 +478,8 @@ async function Bt(e) {
476
478
  }
477
479
  return r;
478
480
  }
479
- async function $t(e, t, r, a) {
480
- const c = r != null && r.onMessage ? [r.onMessage] : [], i = await Bt({
481
+ async function zt(e, t, r, a) {
482
+ const c = r != null && r.onMessage ? [r.onMessage] : [], s = await $t({
481
483
  auth: e,
482
484
  host: t,
483
485
  externalId: a,
@@ -488,13 +490,13 @@ async function $t(e, t, r, a) {
488
490
  },
489
491
  onMessage(o) {
490
492
  const n = JSON.parse(o.data);
491
- c.forEach((s) => s(n.event, n));
493
+ c.forEach((i) => i(n.event, n));
492
494
  }
493
495
  }
494
496
  });
495
497
  return {
496
- socket: i,
497
- disconnect: () => i.close(),
498
+ socket: s,
499
+ disconnect: () => s.close(),
498
500
  subscribeToEvents: (o) => c.push(o)
499
501
  };
500
502
  }
@@ -506,7 +508,7 @@ function xe(e) {
506
508
  r += e[t++];
507
509
  return r;
508
510
  }
509
- function zt(e, t, r) {
511
+ function Nt(e, t, r) {
510
512
  if (!e.content)
511
513
  return;
512
514
  const a = {
@@ -519,9 +521,9 @@ function zt(e, t, r) {
519
521
  };
520
522
  t.messages.push(a), r == null || r([...t.messages], "user");
521
523
  }
522
- function Nt(e, t, r, a, c, i, o) {
524
+ function Ft(e, t, r, a, c, s, o) {
523
525
  if (e === z.Transcribe && t.content) {
524
- zt(t, a, c);
526
+ Nt(t, a, c);
525
527
  return;
526
528
  }
527
529
  if (!(e === z.Partial || e === z.Answer))
@@ -534,7 +536,7 @@ function Nt(e, t, r, a, c, i, o) {
534
536
  if ((n == null ? void 0 : n.role) === "assistant" && !d)
535
537
  u = n;
536
538
  else if (!n || n.role === "user" || d)
537
- d && i(), u = {
539
+ d && s(), u = {
538
540
  id: t.id || `assistant-${Date.now()}`,
539
541
  role: t.role || "assistant",
540
542
  content: t.content || "",
@@ -553,13 +555,13 @@ function Nt(e, t, r, a, c, i, o) {
553
555
  const w = xe(r);
554
556
  (u.content !== w || e === z.Answer) && (u.content = w, u.parts = ne(w), c == null || c([...a.messages], e));
555
557
  }
556
- function Ft(e, t, r, a, c) {
557
- const i = {}, o = () => {
558
- for (const d of Object.keys(i))
559
- delete i[d];
558
+ function Vt(e, t, r, a, c) {
559
+ const s = {}, o = () => {
560
+ for (const d of Object.keys(s))
561
+ delete s[d];
560
562
  };
561
563
  let n = null;
562
- const s = (d, u) => {
564
+ const i = (d, u) => {
563
565
  var f, m;
564
566
  u === "user" && o(), (m = (f = r.callbacks).onNewMessage) == null || m.call(f, d, u);
565
567
  };
@@ -569,12 +571,12 @@ function Ft(e, t, r, a, c) {
569
571
  var f, m;
570
572
  if ("content" in u) {
571
573
  const w = d === x.ChatAnswer ? z.Answer : d === x.ChatAudioTranscribed ? z.Transcribe : d;
572
- Nt(
574
+ Ft(
573
575
  w,
574
576
  u,
575
- i,
576
- t,
577
577
  s,
578
+ t,
579
+ i,
578
580
  o,
579
581
  n
580
582
  ), w === z.Partial ? n = "partial" : w === z.Answer && (n = "answer", o()), w === z.Answer && e.track("agent-message-received", {
@@ -585,60 +587,60 @@ function Ft(e, t, r, a, c) {
585
587
  } else {
586
588
  const w = x, y = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], j = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], M = bt(u, a, { mode: t.chatMode });
587
589
  if (d = d, d === w.StreamVideoCreated && (e.linkTrack("agent-video", M, w.StreamVideoCreated, ["start"]), u.sentiment)) {
588
- const T = t.messages[t.messages.length - 1];
589
- if ((T == null ? void 0 : T.role) === "assistant") {
590
- const L = { ...T, sentiment: u.sentiment };
591
- t.messages[t.messages.length - 1] = L, s == null || s([...t.messages], n ?? "answer");
590
+ const _ = t.messages[t.messages.length - 1];
591
+ if ((_ == null ? void 0 : _.role) === "assistant") {
592
+ const L = { ..._, sentiment: u.sentiment };
593
+ t.messages[t.messages.length - 1] = L, i == null || i([...t.messages], n ?? "answer");
592
594
  }
593
595
  }
594
596
  if (y.includes(d)) {
595
- const T = d.split("/")[1];
596
- j.includes(d) ? e.track("agent-video", { ...M, event: T }) : e.linkTrack("agent-video", { ...M, event: T }, d, ["done"]);
597
+ const _ = d.split("/")[1];
598
+ j.includes(d) ? e.track("agent-video", { ...M, event: _ }) : e.linkTrack("agent-video", { ...M, event: _ }, d, ["done"]);
597
599
  }
598
600
  j.includes(d) && ((m = (f = r.callbacks).onError) == null || m.call(f, new Ne(`Stream failed with event ${d}`), { data: u })), u.event === w.StreamDone && c();
599
601
  }
600
602
  }
601
603
  };
602
604
  }
603
- function Vt(e, t, r, a) {
605
+ function Jt(e, t, r, a) {
604
606
  const c = He(e, `${t}/agents/${r}`, a);
605
607
  return {
606
- createStream(i, o) {
607
- return c.post("/streams", i, { signal: o });
608
+ createStream(s, o) {
609
+ return c.post("/streams", s, { signal: o });
608
610
  },
609
- startConnection(i, o, n, s) {
611
+ startConnection(s, o, n, i) {
610
612
  return c.post(
611
- `/streams/${i}/sdp`,
613
+ `/streams/${s}/sdp`,
612
614
  {
613
615
  session_id: n,
614
616
  answer: o
615
617
  },
616
- { signal: s }
618
+ { signal: i }
617
619
  );
618
620
  },
619
- addIceCandidate(i, o, n, s) {
621
+ addIceCandidate(s, o, n, i) {
620
622
  return c.post(
621
- `/streams/${i}/ice`,
623
+ `/streams/${s}/ice`,
622
624
  {
623
625
  session_id: n,
624
626
  ...o
625
627
  },
626
- { signal: s }
628
+ { signal: i }
627
629
  );
628
630
  },
629
- sendStreamRequest(i, o, n) {
630
- return c.post(`/streams/${i}`, {
631
+ sendStreamRequest(s, o, n) {
632
+ return c.post(`/streams/${s}`, {
631
633
  session_id: o,
632
634
  ...n
633
635
  });
634
636
  },
635
- close(i, o) {
636
- return c.delete(`/streams/${i}`, { session_id: o });
637
+ close(s, o) {
638
+ return c.delete(`/streams/${s}`, { session_id: o });
637
639
  }
638
640
  };
639
641
  }
640
- const Jt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
641
- function Ut(e, t, r) {
642
+ const Ut = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
643
+ function Kt(e, t, r) {
642
644
  const a = (t.timestamp - e.timestamp) / 1e3;
643
645
  return {
644
646
  duration: a,
@@ -658,7 +660,7 @@ function Ut(e, t, r) {
658
660
  lowFpsCount: r
659
661
  };
660
662
  }
661
- function Kt(e) {
663
+ function Wt(e) {
662
664
  return e.filter(
663
665
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
664
666
  ).map((t) => {
@@ -669,7 +671,7 @@ function Kt(e) {
669
671
  };
670
672
  });
671
673
  }
672
- function Wt(e) {
674
+ function Ht(e) {
673
675
  var o;
674
676
  let t = "", r = 0, a = null;
675
677
  const c = /* @__PURE__ */ new Map();
@@ -678,56 +680,17 @@ function Wt(e) {
678
680
  if (n.type === "codec" && ((o = n.mimeType) != null && o.startsWith("video")))
679
681
  c.set(n.id, n.mimeType.split("/")[1]);
680
682
  else if (n.type === "candidate-pair") {
681
- const s = n, d = s.currentRoundTripTime ?? 0;
682
- d > 0 && (s.nominated === !0 || r === 0) && (r = d);
683
+ const i = n, d = i.currentRoundTripTime ?? 0;
684
+ d > 0 && (i.nominated === !0 || r === 0) && (r = d);
683
685
  } else n.type === "inbound-rtp" && n.kind === "video" && (a = n);
684
686
  if (!a)
685
687
  return {};
686
- const i = a;
687
- return i.codecId && c.has(i.codecId) ? t = c.get(i.codecId) : c.size > 0 && (t = c.values().next().value ?? ""), {
688
+ const s = a;
689
+ return s.codecId && c.has(s.codecId) ? t = c.get(s.codecId) : c.size > 0 && (t = c.values().next().value ?? ""), {
688
690
  codec: t,
689
691
  rtt: r,
690
- timestamp: i.timestamp,
691
- bytesReceived: i.bytesReceived,
692
- packetsReceived: i.packetsReceived,
693
- packetsLost: i.packetsLost,
694
- framesDropped: i.framesDropped,
695
- framesDecoded: i.framesDecoded,
696
- jitter: i.jitter,
697
- jitterBufferDelay: i.jitterBufferDelay,
698
- jitterBufferEmittedCount: i.jitterBufferEmittedCount,
699
- avgJitterDelayInInterval: i.jitterBufferDelay / i.jitterBufferEmittedCount,
700
- frameWidth: i.frameWidth,
701
- frameHeight: i.frameHeight,
702
- framesPerSecond: i.framesPerSecond,
703
- freezeCount: i.freezeCount,
704
- freezeDuration: i.totalFreezesDuration
705
- };
706
- }
707
- function Le(e, t, r) {
708
- const a = e.map((s, d) => d === 0 ? r ? {
709
- timestamp: s.timestamp,
710
- duration: 0,
711
- rtt: s.rtt,
712
- bytesReceived: s.bytesReceived - r.bytesReceived,
713
- bitrate: (s.bytesReceived - r.bytesReceived) * 8 / (t / 1e3),
714
- packetsReceived: s.packetsReceived - r.packetsReceived,
715
- packetsLost: s.packetsLost - r.packetsLost,
716
- framesDropped: s.framesDropped - r.framesDropped,
717
- framesDecoded: s.framesDecoded - r.framesDecoded,
718
- jitter: s.jitter,
719
- jitterBufferDelay: s.jitterBufferDelay - r.jitterBufferDelay,
720
- jitterBufferEmittedCount: s.jitterBufferEmittedCount - r.jitterBufferEmittedCount,
721
- avgJitterDelayInInterval: (s.jitterBufferDelay - r.jitterBufferDelay) / (s.jitterBufferEmittedCount - r.jitterBufferEmittedCount),
722
- framesPerSecond: s.framesPerSecond,
723
- freezeCount: s.freezeCount - r.freezeCount,
724
- freezeDuration: s.freezeDuration - r.freezeDuration
725
- } : {
726
692
  timestamp: s.timestamp,
727
- rtt: s.rtt,
728
- duration: 0,
729
693
  bytesReceived: s.bytesReceived,
730
- bitrate: s.bytesReceived * 8 / (t / 1e3),
731
694
  packetsReceived: s.packetsReceived,
732
695
  packetsLost: s.packetsLost,
733
696
  framesDropped: s.framesDropped,
@@ -736,37 +699,76 @@ function Le(e, t, r) {
736
699
  jitterBufferDelay: s.jitterBufferDelay,
737
700
  jitterBufferEmittedCount: s.jitterBufferEmittedCount,
738
701
  avgJitterDelayInInterval: s.jitterBufferDelay / s.jitterBufferEmittedCount,
702
+ frameWidth: s.frameWidth,
703
+ frameHeight: s.frameHeight,
739
704
  framesPerSecond: s.framesPerSecond,
740
705
  freezeCount: s.freezeCount,
741
- freezeDuration: s.freezeDuration
706
+ freezeDuration: s.totalFreezesDuration
707
+ };
708
+ }
709
+ function Le(e, t, r) {
710
+ const a = e.map((i, d) => d === 0 ? r ? {
711
+ timestamp: i.timestamp,
712
+ duration: 0,
713
+ rtt: i.rtt,
714
+ bytesReceived: i.bytesReceived - r.bytesReceived,
715
+ bitrate: (i.bytesReceived - r.bytesReceived) * 8 / (t / 1e3),
716
+ packetsReceived: i.packetsReceived - r.packetsReceived,
717
+ packetsLost: i.packetsLost - r.packetsLost,
718
+ framesDropped: i.framesDropped - r.framesDropped,
719
+ framesDecoded: i.framesDecoded - r.framesDecoded,
720
+ jitter: i.jitter,
721
+ jitterBufferDelay: i.jitterBufferDelay - r.jitterBufferDelay,
722
+ jitterBufferEmittedCount: i.jitterBufferEmittedCount - r.jitterBufferEmittedCount,
723
+ avgJitterDelayInInterval: (i.jitterBufferDelay - r.jitterBufferDelay) / (i.jitterBufferEmittedCount - r.jitterBufferEmittedCount),
724
+ framesPerSecond: i.framesPerSecond,
725
+ freezeCount: i.freezeCount - r.freezeCount,
726
+ freezeDuration: i.freezeDuration - r.freezeDuration
742
727
  } : {
743
- timestamp: s.timestamp,
728
+ timestamp: i.timestamp,
729
+ rtt: i.rtt,
730
+ duration: 0,
731
+ bytesReceived: i.bytesReceived,
732
+ bitrate: i.bytesReceived * 8 / (t / 1e3),
733
+ packetsReceived: i.packetsReceived,
734
+ packetsLost: i.packetsLost,
735
+ framesDropped: i.framesDropped,
736
+ framesDecoded: i.framesDecoded,
737
+ jitter: i.jitter,
738
+ jitterBufferDelay: i.jitterBufferDelay,
739
+ jitterBufferEmittedCount: i.jitterBufferEmittedCount,
740
+ avgJitterDelayInInterval: i.jitterBufferDelay / i.jitterBufferEmittedCount,
741
+ framesPerSecond: i.framesPerSecond,
742
+ freezeCount: i.freezeCount,
743
+ freezeDuration: i.freezeDuration
744
+ } : {
745
+ timestamp: i.timestamp,
744
746
  duration: t * d / 1e3,
745
- rtt: s.rtt,
746
- bytesReceived: s.bytesReceived - e[d - 1].bytesReceived,
747
- bitrate: (s.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
748
- packetsReceived: s.packetsReceived - e[d - 1].packetsReceived,
749
- packetsLost: s.packetsLost - e[d - 1].packetsLost,
750
- framesDropped: s.framesDropped - e[d - 1].framesDropped,
751
- framesDecoded: s.framesDecoded - e[d - 1].framesDecoded,
752
- jitter: s.jitter,
753
- jitterBufferDelay: s.jitterBufferDelay - e[d - 1].jitterBufferDelay,
754
- jitterBufferEmittedCount: s.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
755
- avgJitterDelayInInterval: (s.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (s.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
756
- framesPerSecond: s.framesPerSecond,
757
- freezeCount: s.freezeCount - e[d - 1].freezeCount,
758
- freezeDuration: s.freezeDuration - e[d - 1].freezeDuration
759
- }), c = Kt(a), i = c.reduce((s, d) => s + (d.causes.includes("low fps") ? 1 : 0), 0), o = a.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), n = a.filter((s) => !!s.rtt).map((s) => s.rtt);
747
+ rtt: i.rtt,
748
+ bytesReceived: i.bytesReceived - e[d - 1].bytesReceived,
749
+ bitrate: (i.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
750
+ packetsReceived: i.packetsReceived - e[d - 1].packetsReceived,
751
+ packetsLost: i.packetsLost - e[d - 1].packetsLost,
752
+ framesDropped: i.framesDropped - e[d - 1].framesDropped,
753
+ framesDecoded: i.framesDecoded - e[d - 1].framesDecoded,
754
+ jitter: i.jitter,
755
+ jitterBufferDelay: i.jitterBufferDelay - e[d - 1].jitterBufferDelay,
756
+ jitterBufferEmittedCount: i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
757
+ avgJitterDelayInInterval: (i.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
758
+ framesPerSecond: i.framesPerSecond,
759
+ freezeCount: i.freezeCount - e[d - 1].freezeCount,
760
+ freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
761
+ }), c = Wt(a), s = c.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), o = a.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), n = a.filter((i) => !!i.rtt).map((i) => i.rtt);
760
762
  return {
761
763
  webRTCStats: {
762
764
  anomalies: c,
763
765
  minRtt: Math.min(...n),
764
- avgRtt: Te(n),
766
+ avgRtt: _e(n),
765
767
  maxRtt: Math.max(...n),
766
- aggregateReport: Ut(e[0], e[e.length - 1], i),
768
+ aggregateReport: Kt(e[0], e[e.length - 1], s),
767
769
  minJitterDelayInInterval: Math.min(...o),
768
770
  maxJitterDelayInInterval: Math.max(...o),
769
- avgJitterDelayInInterval: Te(o)
771
+ avgJitterDelayInInterval: _e(o)
770
772
  },
771
773
  codec: e[0].codec,
772
774
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
@@ -779,88 +781,88 @@ function Ge(e, t) {
779
781
  return null;
780
782
  }
781
783
  const te = 10;
782
- function wr(e, t) {
783
- let r = !1, a = !1, c = null, i = 0, o = 0, n = {};
784
- async function s() {
784
+ function vr(e, t) {
785
+ let r = !1, a = !1, c = null, s = 0, o = 0, n = {};
786
+ async function i() {
785
787
  if (r) {
786
788
  try {
787
789
  const d = await e();
788
790
  if (!d) {
789
- c = setTimeout(s, te);
791
+ c = setTimeout(i, te);
790
792
  return;
791
793
  }
792
794
  const u = Ge(d, "audio");
793
795
  if (!u) {
794
- c = setTimeout(s, te);
796
+ c = setTimeout(i, te);
795
797
  return;
796
798
  }
797
799
  const f = u.totalAudioEnergy ?? 0, m = u.totalSamplesReceived ?? 0;
798
800
  if (!a) {
799
- i = f, o = m, a = !0, c = setTimeout(s, te);
801
+ s = f, o = m, a = !0, c = setTimeout(i, te);
800
802
  return;
801
803
  }
802
- const w = f - i, y = m - o;
803
- if (i = f, o = m, y > 0 && w > 0) {
804
+ const w = f - s, y = m - o;
805
+ if (s = f, o = m, y > 0 && w > 0) {
804
806
  r = !1, t(n);
805
807
  return;
806
808
  }
807
809
  } catch {
808
810
  }
809
- r && (c = setTimeout(s, te));
811
+ r && (c = setTimeout(i, te));
810
812
  }
811
813
  }
812
814
  return {
813
815
  arm(d = {}) {
814
- n = d, r = !0, a = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(s, te);
816
+ n = d, r = !0, a = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(i, te);
815
817
  },
816
818
  destroy() {
817
819
  r = !1, c !== null && (clearTimeout(c), c = null);
818
820
  }
819
821
  };
820
822
  }
821
- const de = 100, Ht = Math.max(Math.ceil(400 / de), 1), Ot = 0.25, qt = 0.28;
822
- function Gt() {
823
+ const de = 100, Ot = Math.max(Math.ceil(400 / de), 1), qt = 0.25, Gt = 0.28;
824
+ function Xt() {
823
825
  let e = 0, t, r, a = 0;
824
826
  return (c) => {
825
- const i = Ge(c, "video");
826
- if (!i)
827
+ const s = Ge(c, "video");
828
+ if (!s)
827
829
  return { isReceiving: !1, avgJitterDelayInInterval: a };
828
- const o = i.jitterBufferDelay, n = i.jitterBufferEmittedCount;
830
+ const o = s.jitterBufferDelay, n = s.jitterBufferEmittedCount;
829
831
  if (r && n > r) {
830
832
  const u = o - t, f = n - r;
831
833
  a = u / f;
832
834
  }
833
835
  t = o, r = n;
834
- const s = i.framesDecoded, d = s - e > 0;
835
- return e = s, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: i.freezeCount };
836
+ const i = s.framesDecoded, d = i - e > 0;
837
+ return e = i, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: s.freezeCount };
836
838
  };
837
839
  }
838
- function Xt(e, t, r, a, c) {
839
- let i = null, o = [], n, s = 0, d = !1, u = re.Unknown, f = re.Unknown, m = 0, w = 0;
840
- const y = Gt();
840
+ function Yt(e, t, r, a, c) {
841
+ let s = null, o = [], n, i = 0, d = !1, u = re.Unknown, f = re.Unknown, m = 0, w = 0;
842
+ const y = Xt();
841
843
  async function j() {
842
844
  const M = await e();
843
845
  if (!M)
844
846
  return;
845
- const { isReceiving: T, avgJitterDelayInInterval: L, freezeCount: E } = y(M), X = Wt(M);
846
- if (T)
847
- s = 0, m = E - w, f = L < Ot ? re.Strong : L > qt && m > 1 ? re.Weak : u, f !== u && (c == null || c(f), u = f, w += m, m = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(X);
848
- else if (d && (s++, s >= Ht)) {
847
+ const { isReceiving: _, avgJitterDelayInInterval: L, freezeCount: E } = y(M), X = Ht(M);
848
+ if (_)
849
+ i = 0, m = E - w, f = L < qt ? re.Strong : L > Gt && m > 1 ? re.Weak : u, f !== u && (c == null || c(f), u = f, w += m, m = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(X);
850
+ else if (d && (i++, i >= Ot)) {
849
851
  const H = Le(o, de, n);
850
852
  a == null || a(S.Stop, H), t() || r(), w = E, d = !1;
851
853
  }
852
854
  }
853
855
  return {
854
856
  start: () => {
855
- i || (i = setInterval(j, de));
857
+ s || (s = setInterval(j, de));
856
858
  },
857
859
  stop: () => {
858
- i && (clearInterval(i), i = null);
860
+ s && (clearInterval(s), s = null);
859
861
  },
860
862
  getReport: () => Le(o, de, n)
861
863
  };
862
864
  }
863
- const Yt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
865
+ const Qt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
864
866
  function Pe(e) {
865
867
  switch (e) {
866
868
  case "connected":
@@ -881,7 +883,7 @@ function Pe(e) {
881
883
  return b.New;
882
884
  }
883
885
  }
884
- const Qt = (e) => (t) => {
886
+ const Zt = (e) => (t) => {
885
887
  const [r, a = ""] = t.split(/:(.+)/);
886
888
  try {
887
889
  const c = JSON.parse(a);
@@ -890,7 +892,7 @@ const Qt = (e) => (t) => {
890
892
  return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: c }), { subject: r, data: a };
891
893
  }
892
894
  };
893
- function Zt({
895
+ function er({
894
896
  statsSignal: e,
895
897
  dataChannelSignal: t,
896
898
  onVideoStateChange: r,
@@ -899,15 +901,15 @@ function Zt({
899
901
  }) {
900
902
  e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, a));
901
903
  }
902
- function er({
904
+ function tr({
903
905
  statsSignal: e,
904
906
  dataChannelSignal: t,
905
907
  onVideoStateChange: r,
906
908
  onAgentActivityStateChange: a,
907
909
  report: c,
908
- log: i
910
+ log: s
909
911
  }) {
910
- e === S.Start ? (i("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, c)), t === S.Start ? a == null || a(ae.Talking) : t === S.Stop && (a == null || a(ae.Idle));
912
+ e === S.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, c)), t === S.Start ? a == null || a(ae.Talking) : t === S.Stop && (a == null || a(ae.Idle));
911
913
  }
912
914
  function je({
913
915
  statsSignal: e,
@@ -915,25 +917,25 @@ function je({
915
917
  onVideoStateChange: r,
916
918
  onAgentActivityStateChange: a,
917
919
  streamType: c,
918
- report: i,
920
+ report: s,
919
921
  log: o
920
922
  }) {
921
- c === W.Legacy ? Zt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: i, log: o }) : c === W.Fluent && er({
923
+ c === W.Legacy ? er({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: o }) : c === W.Fluent && tr({
922
924
  statsSignal: e,
923
925
  dataChannelSignal: t,
924
926
  onVideoStateChange: r,
925
927
  onAgentActivityStateChange: a,
926
- report: i,
928
+ report: s,
927
929
  log: o
928
930
  });
929
931
  }
930
- async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le, analytics: o }, n) {
932
+ async function rr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = le, analytics: o }, n) {
931
933
  var F;
932
- const s = Jt(r, "WebRTCStreamingManager"), d = Qt(s);
934
+ const i = Ut(r, "WebRTCStreamingManager"), d = Zt(i);
933
935
  let u = !1, f = !1, m = S.Stop, w = S.Stop;
934
- const { startConnection: y, sendStreamRequest: j, close: M, createStream: T, addIceCandidate: L } = Vt(
936
+ const { startConnection: y, sendStreamRequest: j, close: M, createStream: _, addIceCandidate: L } = Jt(
935
937
  c,
936
- i,
938
+ s,
937
939
  e,
938
940
  a.onError
939
941
  ), {
@@ -941,21 +943,21 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
941
943
  offer: X,
942
944
  ice_servers: H,
943
945
  session_id: V,
944
- fluent: ie,
946
+ fluent: se,
945
947
  interrupt_enabled: Y
946
- } = await T(t, n);
948
+ } = await _(t, n);
947
949
  (F = a.onStreamCreated) == null || F.call(a, { stream_id: E, session_id: V, agent_id: e });
948
- const D = new Yt({ iceServers: H }), O = D.createDataChannel("JanusDataChannel");
950
+ const D = new Qt({ iceServers: H }), O = D.createDataChannel("JanusDataChannel");
949
951
  if (!V)
950
952
  throw new Error("Could not create session_id");
951
- const J = ie ? W.Fluent : W.Legacy;
953
+ const J = se ? W.Fluent : W.Legacy;
952
954
  o.enrich({
953
955
  "stream-type": J
954
956
  });
955
- const se = t.stream_warmup && !ie, oe = () => u, ee = () => {
957
+ const ie = t.stream_warmup && !se, oe = () => u, ee = () => {
956
958
  var g;
957
- u = !0, f && (s("CALLBACK: onConnectionStateChange(Connected)"), (g = a.onConnectionStateChange) == null || g.call(a, b.Connected));
958
- }, l = Xt(
959
+ u = !0, f && (i("CALLBACK: onConnectionStateChange(Connected)"), (g = a.onConnectionStateChange) == null || g.call(a, b.Connected));
960
+ }, l = Yt(
959
961
  () => D.getStats(),
960
962
  oe,
961
963
  ee,
@@ -966,7 +968,7 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
966
968
  onAgentActivityStateChange: a.onAgentActivityStateChange,
967
969
  report: h,
968
970
  streamType: J,
969
- log: s
971
+ log: i
970
972
  }),
971
973
  (g) => {
972
974
  var h;
@@ -975,7 +977,7 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
975
977
  );
976
978
  l.start(), D.onicecandidate = (g) => {
977
979
  var h;
978
- s("peerConnection.onicecandidate", g);
980
+ i("peerConnection.onicecandidate", g);
979
981
  try {
980
982
  g.candidate && g.candidate.sdpMid && g.candidate.sdpMLineIndex !== null ? L(
981
983
  E,
@@ -991,7 +993,7 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
991
993
  (h = a.onError) == null || h.call(a, I, { streamId: E });
992
994
  }
993
995
  }, O.onopen = () => {
994
- f = !0, (!se || u) && ee();
996
+ f = !0, (!ie || u) && ee();
995
997
  };
996
998
  let p = null;
997
999
  const v = (g) => {
@@ -1009,7 +1011,7 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
1009
1011
  onVideoStateChange: a.onVideoStateChange,
1010
1012
  onAgentActivityStateChange: a.onAgentActivityStateChange,
1011
1013
  streamType: J,
1012
- log: s
1014
+ log: i
1013
1015
  });
1014
1016
  }
1015
1017
  function k(g, h) {
@@ -1028,19 +1030,19 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
1028
1030
  (B = R[h]) == null || B.call(R, h, I);
1029
1031
  }, D.oniceconnectionstatechange = () => {
1030
1032
  var h;
1031
- s("peerConnection.oniceconnectionstatechange => " + D.iceConnectionState);
1033
+ i("peerConnection.oniceconnectionstatechange => " + D.iceConnectionState);
1032
1034
  const g = Pe(D.iceConnectionState);
1033
1035
  g !== b.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, g));
1034
1036
  }, D.ontrack = (g) => {
1035
1037
  var h;
1036
- s("peerConnection.ontrack", g), s("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, g.streams[0]);
1037
- }, await D.setRemoteDescription(X), s("set remote description OK");
1038
+ i("peerConnection.ontrack", g), i("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, g.streams[0]);
1039
+ }, await D.setRemoteDescription(X), i("set remote description OK");
1038
1040
  const P = await D.createAnswer();
1039
- s("create answer OK"), await D.setLocalDescription(P), s("set local description OK"), await y(E, P, V, n), s("start connection OK");
1041
+ i("create answer OK"), await D.setLocalDescription(P), i("set local description OK"), await y(E, P, V, n), i("start connection OK");
1040
1042
  function N(g) {
1041
1043
  var h, I;
1042
1044
  if (!u || O.readyState !== "open") {
1043
- s("Data channel is not ready for sending messages"), (h = a.onError) == null || h.call(a, new Ne("Data channel is not ready for sending messages"), {
1045
+ i("Data channel is not ready for sending messages"), (h = a.onError) == null || h.call(a, new Ne("Data channel is not ready for sending messages"), {
1044
1046
  streamId: E
1045
1047
  });
1046
1048
  return;
@@ -1048,7 +1050,7 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
1048
1050
  try {
1049
1051
  O.send(g);
1050
1052
  } catch (B) {
1051
- s("Error sending data channel message", B), (I = a.onError) == null || I.call(a, B, { streamId: E });
1053
+ i("Error sending data channel message", B), (I = a.onError) == null || I.call(a, B, { streamId: E });
1052
1054
  }
1053
1055
  }
1054
1056
  return {
@@ -1077,7 +1079,7 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
1077
1079
  h === b.Connected && await M(E, V).catch((I) => {
1078
1080
  });
1079
1081
  } catch (I) {
1080
- s("Error on close stream connection", I);
1082
+ i("Error on close stream connection", I);
1081
1083
  }
1082
1084
  (g = a.onAgentActivityStateChange) == null || g.call(a, ae.Idle), l.stop();
1083
1085
  }
@@ -1111,18 +1113,18 @@ async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le,
1111
1113
  };
1112
1114
  }
1113
1115
  var he = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(he || {});
1114
- async function rr(e, t, r, a) {
1116
+ async function nr(e, t, r, a) {
1115
1117
  const c = e.id;
1116
1118
  switch (t.version) {
1117
1119
  case "v1": {
1118
- const { version: i, ...o } = t;
1119
- return tr(c, o, r, a);
1120
+ const { version: s, ...o } = t;
1121
+ return rr(c, o, r, a);
1120
1122
  }
1121
1123
  case "v2": {
1122
- const { version: i, ...o } = t;
1124
+ const { version: s, ...o } = t;
1123
1125
  switch (o.transport.provider) {
1124
1126
  case pe.Livekit:
1125
- const { createLiveKitStreamingManager: n } = await import("./livekit-manager-CFuAnjAa.js");
1127
+ const { createLiveKitStreamingManager: n } = await import("./livekit-manager-Cn2SQGJF.js");
1126
1128
  return n(c, o, r);
1127
1129
  default:
1128
1130
  throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
@@ -1132,8 +1134,8 @@ async function rr(e, t, r, a) {
1132
1134
  throw new Error(`Invalid stream version: ${t.version}`);
1133
1135
  }
1134
1136
  }
1135
- const nr = "cht";
1136
- function ar() {
1137
+ const ar = "cht";
1138
+ function sr() {
1137
1139
  return {
1138
1140
  transport: {
1139
1141
  provider: pe.Livekit
@@ -1141,9 +1143,9 @@ function ar() {
1141
1143
  };
1142
1144
  }
1143
1145
  function ir(e) {
1144
- var c, i;
1146
+ var c, s;
1145
1147
  const { streamOptions: t } = e ?? {}, r = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
1146
- plan: (i = e.mixpanelAdditionalProperties) == null ? void 0 : i.plan
1148
+ plan: (s = e.mixpanelAdditionalProperties) == null ? void 0 : s.plan
1147
1149
  } : void 0;
1148
1150
  return { ...{
1149
1151
  output_resolution: t == null ? void 0 : t.outputResolution,
@@ -1153,16 +1155,16 @@ function ir(e) {
1153
1155
  fluent: t == null ? void 0 : t.fluent
1154
1156
  }, ...r && { end_user_data: r } };
1155
1157
  }
1156
- function sr(e, t) {
1157
- return we(e.presenter.type) ? { version: he.V2, ...ar() } : { version: he.V1, ...ir(t) };
1158
+ function or(e, t) {
1159
+ return we(e.presenter.type) ? { version: he.V2, ...sr() } : { version: he.V1, ...ir(t) };
1158
1160
  }
1159
- function or(e, t, r) {
1161
+ function cr(e, t, r) {
1160
1162
  r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
1161
1163
  }
1162
- function cr(e, t, r, a, c) {
1163
- c === W.Fluent ? dr(e, t, r, a, c) : lr(e, t, r, a, c);
1164
- }
1165
1164
  function dr(e, t, r, a, c) {
1165
+ c === W.Fluent ? lr(e, t, r, a, c) : ur(e, t, r, a, c);
1166
+ }
1167
+ function lr(e, t, r, a, c) {
1166
1168
  e === S.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && a.track("stream-session", {
1167
1169
  event: "stop",
1168
1170
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
@@ -1186,7 +1188,7 @@ function Be(e, t, r, a, c) {
1186
1188
  [x.StreamVideoDone]
1187
1189
  );
1188
1190
  }
1189
- function lr(e, t, r, a, c) {
1191
+ function ur(e, t, r, a, c) {
1190
1192
  e === S.Start ? a.linkTrack(
1191
1193
  "agent-video",
1192
1194
  { event: "start", latency: q.get(!0), "stream-type": c },
@@ -1205,7 +1207,7 @@ function lr(e, t, r, a, c) {
1205
1207
  [x.StreamVideoDone]
1206
1208
  );
1207
1209
  }
1208
- function ur(e, t, r) {
1210
+ function mr(e, t, r) {
1209
1211
  const a = {
1210
1212
  call_id: t.call_id,
1211
1213
  name: t.name
@@ -1223,18 +1225,18 @@ function ur(e, t, r) {
1223
1225
  });
1224
1226
  }
1225
1227
  function $e(e, t, r, a) {
1226
- return q.reset(), be.update(), new Promise(async (c, i) => {
1228
+ return q.reset(), be.update(), new Promise(async (c, s) => {
1227
1229
  try {
1228
1230
  let o, n = !1;
1229
- const s = sr(e, t);
1231
+ const i = or(e, t);
1230
1232
  r.enrich({
1231
- "stream-version": s.version.toString()
1233
+ "stream-version": i.version.toString()
1232
1234
  });
1233
1235
  let d = null;
1234
1236
  const u = e.presenter.type === "expressive";
1235
- o = await rr(
1237
+ o = await nr(
1236
1238
  e,
1237
- s,
1239
+ i,
1238
1240
  {
1239
1241
  ...t,
1240
1242
  analytics: r,
@@ -1242,11 +1244,11 @@ function $e(e, t, r, a) {
1242
1244
  ...t.callbacks,
1243
1245
  onConnectionStateChange: (f, m) => {
1244
1246
  var w, y;
1245
- (y = (w = t.callbacks).onConnectionStateChange) == null || y.call(w, f), or(f, m, r), f === b.Connected && (o ? c(o) : n = !0);
1247
+ (y = (w = t.callbacks).onConnectionStateChange) == null || y.call(w, f), cr(f, m, r), f === b.Connected && (o ? c(o) : n = !0);
1246
1248
  },
1247
1249
  onVideoStateChange: (f, m) => {
1248
1250
  var w, y;
1249
- (y = (w = t.callbacks).onVideoStateChange) == null || y.call(w, f), cr(
1251
+ (y = (w = t.callbacks).onVideoStateChange) == null || y.call(w, f), dr(
1250
1252
  f,
1251
1253
  e,
1252
1254
  m,
@@ -1280,22 +1282,22 @@ function $e(e, t, r, a) {
1280
1282
  },
1281
1283
  onToolEvent: ((f, m) => {
1282
1284
  var w, y;
1283
- (y = (w = t.callbacks).onToolEvent) == null || y.call(w, f, m), ur(f, m, r);
1285
+ (y = (w = t.callbacks).onToolEvent) == null || y.call(w, f, m), mr(f, m, r);
1284
1286
  })
1285
1287
  }
1286
1288
  },
1287
1289
  a
1288
1290
  ), n && c(o);
1289
1291
  } catch (o) {
1290
- i(o);
1292
+ s(o);
1291
1293
  }
1292
1294
  });
1293
1295
  }
1294
- async function mr(e, t, r, a, c) {
1296
+ async function fr(e, t, r, a, c) {
1295
1297
  var u, f, m, w;
1296
- const i = async () => {
1298
+ const s = async () => {
1297
1299
  if (we(e.presenter.type)) {
1298
- const y = await $e(e, t, a), j = `${nr}_${y.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1300
+ const y = await $e(e, t, a), j = `${ar}_${y.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1299
1301
  return { chatResult: {
1300
1302
  chatMode: A.Functional,
1301
1303
  chat: {
@@ -1314,58 +1316,58 @@ async function mr(e, t, r, a, c) {
1314
1316
  const y = new AbortController(), j = y.signal;
1315
1317
  let M;
1316
1318
  try {
1317
- const T = qe(
1319
+ const _ = qe(
1318
1320
  e,
1319
1321
  r,
1320
1322
  a,
1321
1323
  t.mode,
1322
1324
  t.persistentChat,
1323
1325
  c
1324
- ), L = $e(e, t, a, j).then((H) => (M = H, H)), [E, X] = await Promise.all([T, L]);
1326
+ ), L = $e(e, t, a, j).then((H) => (M = H, H)), [E, X] = await Promise.all([_, L]);
1325
1327
  return { chatResult: E, streamingManager: X };
1326
- } catch (T) {
1328
+ } catch (_) {
1327
1329
  throw y.abort(), M && await M.disconnect().catch(() => {
1328
- }), T;
1330
+ }), _;
1329
1331
  }
1330
1332
  }
1331
- }, { chatResult: o, streamingManager: n } = await i(), { chat: s, chatMode: d } = o;
1332
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (f = (u = t.callbacks).onModeChange) == null || f.call(u, d), d !== A.Functional) ? ((w = (m = t.callbacks).onError) == null || w.call(m, new et(d)), n == null || n.disconnect(), { chat: s }) : { chat: s, streamingManager: n };
1333
+ }, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
1334
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (f = (u = t.callbacks).onModeChange) == null || f.call(u, d), d !== A.Functional) ? ((w = (m = t.callbacks).onError) == null || w.call(m, new et(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
1333
1335
  }
1334
- async function vr(e, t) {
1335
- var J, se, oe, ee;
1336
+ async function yr(e, t) {
1337
+ var J, ie, oe, ee;
1336
1338
  let r = !0;
1337
- const a = t.mixpanelKey || wt, c = t.wsURL || pt, i = t.baseURL || le, o = t.mode || A.Functional, n = {
1339
+ const a = t.mixpanelKey || wt, c = t.wsURL || pt, s = t.baseURL || le, o = t.mode || A.Functional, n = {
1338
1340
  messages: [],
1339
1341
  chatMode: o
1340
- }, s = Lt({
1342
+ }, i = Pt({
1341
1343
  token: a,
1342
1344
  agentId: e,
1343
1345
  isEnabled: t.enableAnalitics,
1344
1346
  externalId: t.externalId,
1345
1347
  mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
1346
1348
  }), d = Date.now();
1347
- _e(() => {
1348
- s.track("agent-sdk", { event: "init" }, d);
1349
+ Te(() => {
1350
+ i.track("agent-sdk", { event: "init" }, d);
1349
1351
  });
1350
1352
  const u = t.callbacks.onError;
1351
1353
  t.callbacks.onError = (l, p) => {
1352
- s.track("agent-error", { error: Ae(l) }), u == null || u(l, p);
1354
+ i.track("agent-error", { error: Ae(l) }), u == null || u(l, p);
1353
1355
  };
1354
- const f = Mt(t.auth, i, t.callbacks.onError, t.externalId), m = await f.getById(e);
1356
+ const f = Mt(t.auth, s, t.callbacks.onError, t.externalId), m = await f.getById(e);
1355
1357
  t.debug = t.debug || ((J = m == null ? void 0 : m.advanced_settings) == null ? void 0 : J.ui_debug_mode);
1356
1358
  const w = we(m.presenter.type);
1357
- s.enrich(Tt(m));
1358
- const { onMessage: y, clearQueue: j } = Ft(s, n, t, m, () => {
1359
+ i.enrich(_t(m));
1360
+ const { onMessage: y, clearQueue: j } = Vt(i, n, t, m, () => {
1359
1361
  var l, p, v;
1360
1362
  (l = n.socketManager) == null || l.disconnect(), (v = (p = t.callbacks).onConnectionStateChange) == null || v.call(p, b.Disconnected);
1361
1363
  });
1362
- n.messages = Pt(t.initialMessages), (oe = (se = t.callbacks).onNewMessage) == null || oe.call(se, [...n.messages], "answer");
1364
+ n.messages = jt(t.initialMessages), (oe = (ie = t.callbacks).onNewMessage) == null || oe.call(ie, [...n.messages], "answer");
1363
1365
  const M = (l) => {
1364
- }, T = ({ type: l }) => {
1366
+ }, _ = ({ type: l }) => {
1365
1367
  var v, C, k, R;
1366
1368
  if (!((v = n.streamingManager) != null && v.interruptAvailable) || !((C = n.streamingManager) != null && C.isInterruptible)) return;
1367
1369
  const p = n.messages[n.messages.length - 1];
1368
- s.track("agent-video-interrupt", {
1370
+ i.track("agent-video-interrupt", {
1369
1371
  type: l || "click",
1370
1372
  video_duration_to_interrupt: ge.get(!0),
1371
1373
  message_duration_to_interrupt: q.get(!0)
@@ -1398,20 +1400,20 @@ async function vr(e, t) {
1398
1400
  var p, v;
1399
1401
  L.delete(l), (v = (p = n.streamingManager) == null ? void 0 : p.unregisterRpcMethod) == null || v.call(p, l);
1400
1402
  }
1401
- const ie = Date.now();
1402
- _e(() => {
1403
- s.track("agent-sdk", { event: "loaded", ...Et(m) }, ie);
1403
+ const se = Date.now();
1404
+ Te(() => {
1405
+ i.track("agent-sdk", { event: "loaded", ...Et(m) }, se);
1404
1406
  });
1405
1407
  async function Y(l) {
1406
1408
  var P, N, F, g, h, I, B;
1407
1409
  ft(), (N = (P = t.callbacks).onConnectionStateChange) == null || N.call(P, b.Connecting), q.reset(), l && !r && (delete n.chat, (g = (F = t.callbacks).onNewMessage) == null || g.call(F, [...n.messages], "answer"));
1408
- const p = o === A.DirectPlayback || w ? Promise.resolve(void 0) : $t(
1410
+ const p = o === A.DirectPlayback || w ? Promise.resolve(void 0) : zt(
1409
1411
  t.auth,
1410
1412
  c,
1411
1413
  { onMessage: y, onError: t.callbacks.onError },
1412
1414
  t.externalId
1413
1415
  ), v = fe(
1414
- () => mr(
1416
+ () => fr(
1415
1417
  m,
1416
1418
  {
1417
1419
  ...t,
@@ -1423,7 +1425,7 @@ async function vr(e, t) {
1423
1425
  }
1424
1426
  },
1425
1427
  f,
1426
- s,
1428
+ i,
1427
1429
  n.chat
1428
1430
  ),
1429
1431
  {
@@ -1434,10 +1436,10 @@ async function vr(e, t) {
1434
1436
  delayMs: 1e3
1435
1437
  }
1436
1438
  ).catch((K) => {
1437
- var _, U;
1438
- throw O(A.Maintenance), (U = (_ = t.callbacks).onConnectionStateChange) == null || U.call(_, b.Fail), K;
1439
+ var T, U;
1440
+ throw O(A.Maintenance), (U = (T = t.callbacks).onConnectionStateChange) == null || U.call(T, b.Fail), K;
1439
1441
  }), [C, { streamingManager: k, chat: R }] = await Promise.all([p, v]);
1440
- R && R.id !== ((h = n.chat) == null ? void 0 : h.id) && ((B = (I = t.callbacks).onNewChat) == null || B.call(I, R.id)), n.streamingManager = k, n.socketManager = C, n.chat = R, X(), r = !1, s.enrich({
1442
+ R && R.id !== ((h = n.chat) == null ? void 0 : h.id) && ((B = (I = t.callbacks).onNewChat) == null || B.call(I, R.id)), n.streamingManager = k, n.socketManager = C, n.chat = R, X(), r = !1, i.enrich({
1441
1443
  chatId: R == null ? void 0 : R.id,
1442
1444
  streamId: k == null ? void 0 : k.streamId,
1443
1445
  mode: n.chatMode
@@ -1449,7 +1451,7 @@ async function vr(e, t) {
1449
1451
  }
1450
1452
  async function O(l) {
1451
1453
  var p, v;
1452
- l !== n.chatMode && (s.track("agent-mode-change", { mode: l }), n.chatMode = l, n.chatMode !== A.Functional && await D(), (v = (p = t.callbacks).onModeChange) == null || v.call(p, l));
1454
+ l !== n.chatMode && (i.track("agent-mode-change", { mode: l }), n.chatMode = l, n.chatMode !== A.Functional && await D(), (v = (p = t.callbacks).onModeChange) == null || v.call(p, l));
1453
1455
  }
1454
1456
  return {
1455
1457
  agent: m,
@@ -1464,9 +1466,9 @@ async function vr(e, t) {
1464
1466
  starterMessages: ((ee = m.knowledge) == null ? void 0 : ee.starter_message) || [],
1465
1467
  getSTTToken: () => f.getSTTToken(m.id),
1466
1468
  changeMode: O,
1467
- enrichAnalytics: s.enrich,
1469
+ enrichAnalytics: i.enrich,
1468
1470
  async connect() {
1469
- await Y(!0), s.track("agent-chat", {
1471
+ await Y(!0), i.track("agent-chat", {
1470
1472
  event: "connect",
1471
1473
  mode: n.chatMode
1472
1474
  });
@@ -1475,7 +1477,7 @@ async function vr(e, t) {
1475
1477
  const l = n.streamingManager;
1476
1478
  if (w && (l != null && l.reconnect)) {
1477
1479
  try {
1478
- await l.reconnect(), s.track("agent-chat", {
1480
+ await l.reconnect(), i.track("agent-chat", {
1479
1481
  event: "reconnect",
1480
1482
  mode: n.chatMode
1481
1483
  });
@@ -1484,13 +1486,13 @@ async function vr(e, t) {
1484
1486
  }
1485
1487
  return;
1486
1488
  }
1487
- await D(), await Y(!1), s.track("agent-chat", {
1489
+ await D(), await Y(!1), i.track("agent-chat", {
1488
1490
  event: "reconnect",
1489
1491
  mode: n.chatMode
1490
1492
  });
1491
1493
  },
1492
1494
  async disconnect() {
1493
- await D(), s.track("agent-chat", {
1495
+ await D(), i.track("agent-chat", {
1494
1496
  event: "disconnect",
1495
1497
  mode: n.chatMode
1496
1498
  });
@@ -1538,7 +1540,7 @@ async function vr(e, t) {
1538
1540
  const I = await qe(
1539
1541
  m,
1540
1542
  f,
1541
- s,
1543
+ i,
1542
1544
  n.chatMode,
1543
1545
  t.persistentChat
1544
1546
  );
@@ -1550,16 +1552,16 @@ async function vr(e, t) {
1550
1552
  }, C = async (g, h) => {
1551
1553
  const I = n.chatMode === A.Playground;
1552
1554
  return fe(w && !I ? async () => {
1553
- var _, U;
1554
- return await ((U = (_ = n.streamingManager) == null ? void 0 : _.sendTextMessage) == null ? void 0 : U.call(_, l)), Promise.resolve({});
1555
+ var T, U;
1556
+ return await ((U = (T = n.streamingManager) == null ? void 0 : T.sendTextMessage) == null ? void 0 : U.call(T, l)), Promise.resolve({});
1555
1557
  } : async () => {
1556
- var _, U;
1558
+ var T, U;
1557
1559
  return f.chat(
1558
1560
  m.id,
1559
1561
  h,
1560
1562
  {
1561
1563
  chatMode: n.chatMode,
1562
- streamId: (_ = n.streamingManager) == null ? void 0 : _.streamId,
1564
+ streamId: (T = n.streamingManager) == null ? void 0 : T.streamId,
1563
1565
  sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
1564
1566
  messages: g.map(({ matches: Xe, ...ce }) => ce)
1565
1567
  },
@@ -1570,10 +1572,10 @@ async function vr(e, t) {
1570
1572
  );
1571
1573
  }, {
1572
1574
  limit: 2,
1573
- shouldRetryFn: (_) => {
1575
+ shouldRetryFn: (T) => {
1574
1576
  var ce, ye, Ce, Se;
1575
- const U = (ce = _ == null ? void 0 : _.message) == null ? void 0 : ce.includes("missing or invalid session_id");
1576
- return !((ye = _ == null ? void 0 : _.message) == null ? void 0 : ye.includes("Stream Error")) && !U ? ((Se = (Ce = t.callbacks).onError) == null || Se.call(Ce, _), !1) : !0;
1577
+ const U = (ce = T == null ? void 0 : T.message) == null ? void 0 : ce.includes("missing or invalid session_id");
1578
+ return !((ye = T == null ? void 0 : T.message) == null ? void 0 : ye.includes("Stream Error")) && !U ? ((Se = (Ce = t.callbacks).onError) == null || Se.call(Ce, T), !1) : !0;
1577
1579
  },
1578
1580
  onRetry: async () => {
1579
1581
  await D(), await Y(!1);
@@ -1597,15 +1599,15 @@ async function vr(e, t) {
1597
1599
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1598
1600
  context: h.context,
1599
1601
  matches: h.matches
1600
- }), s.track("agent-message-send", {
1602
+ }), i.track("agent-message-send", {
1601
1603
  event: "success",
1602
1604
  messages: n.messages.length + 1
1603
- }), h.result && ((N = (P = t.callbacks).onNewMessage) == null || N.call(P, [...n.messages], "answer"), s.track("agent-message-received", {
1605
+ }), h.result && ((N = (P = t.callbacks).onNewMessage) == null || N.call(P, [...n.messages], "answer"), i.track("agent-message-received", {
1604
1606
  latency: q.get(!0),
1605
1607
  messages: n.messages.length
1606
1608
  })), h;
1607
1609
  } catch (g) {
1608
- throw ((F = n.messages[n.messages.length - 1]) == null ? void 0 : F.role) === "assistant" && n.messages.pop(), s.track("agent-message-send", {
1610
+ throw ((F = n.messages[n.messages.length - 1]) == null ? void 0 : F.role) === "assistant" && n.messages.pop(), i.track("agent-message-send", {
1609
1611
  event: "error",
1610
1612
  messages: n.messages.length,
1611
1613
  error: Ae(g)
@@ -1620,7 +1622,7 @@ async function vr(e, t) {
1620
1622
  throw new $("Message not found");
1621
1623
  } else throw new $("Chat is not initialized");
1622
1624
  const k = ((R = C.matches) == null ? void 0 : R.map((g) => [g.document_id, g.id])) ?? [];
1623
- return s.track("agent-rate", {
1625
+ return i.track("agent-rate", {
1624
1626
  event: v ? "update" : "create",
1625
1627
  thumb: p === 1 ? "up" : "down",
1626
1628
  knowledge_id: ((P = m.knowledge) == null ? void 0 : P.id) ?? "",
@@ -1641,7 +1643,7 @@ async function vr(e, t) {
1641
1643
  deleteRate(l) {
1642
1644
  if (!n.chat)
1643
1645
  throw new $("Chat is not initialized");
1644
- return s.track("agent-rate-delete", { type: "text" }), f.deleteRating(m.id, n.chat.id, l);
1646
+ return i.track("agent-rate-delete", { type: "text" }), f.deleteRating(m.id, n.chat.id, l);
1645
1647
  },
1646
1648
  async speak(l) {
1647
1649
  var k, R, P;
@@ -1669,7 +1671,7 @@ async function vr(e, t) {
1669
1671
  return l;
1670
1672
  }
1671
1673
  const v = p();
1672
- if (s.track("agent-speak", v), q.update(), n.messages && v.type === "text" && (n.messages.push({
1674
+ if (i.track("agent-speak", v), q.update(), n.messages && v.type === "text" && (n.messages.push({
1673
1675
  id: Q(),
1674
1676
  role: "assistant",
1675
1677
  content: v.input,
@@ -1688,7 +1690,7 @@ async function vr(e, t) {
1688
1690
  metadata: { chat_id: (P = n.chat) == null ? void 0 : P.id, agent_id: m.id }
1689
1691
  });
1690
1692
  },
1691
- interrupt: T,
1693
+ interrupt: _,
1692
1694
  registerClientTool: H,
1693
1695
  unregisterClientTool: V
1694
1696
  };
@@ -1701,36 +1703,37 @@ export {
1701
1703
  ze as H,
1702
1704
  dt as K,
1703
1705
  rt as N,
1704
- it as P,
1706
+ st as P,
1705
1707
  ot as R,
1706
1708
  x as S,
1707
1709
  pe as T,
1708
1710
  at as U,
1709
1711
  $ as V,
1710
1712
  nt as W,
1711
- Jt as a,
1713
+ Ut as a,
1712
1714
  W as b,
1713
1715
  He as c,
1714
1716
  le as d,
1715
1717
  Ne as e,
1716
1718
  b as f,
1717
1719
  re as g,
1718
- Xt as h,
1719
- wr as i,
1720
+ Yt as h,
1721
+ vr as i,
1720
1722
  S as j,
1721
- st as k,
1723
+ it as k,
1722
1724
  q as l,
1723
1725
  Ze as m,
1724
- pr as n,
1726
+ wr as n,
1725
1727
  A as o,
1726
1728
  et as p,
1727
1729
  ut as q,
1728
- ct as r,
1729
- Fe as s,
1730
+ xt as r,
1731
+ ct as s,
1730
1732
  Ae as t,
1731
- mt as u,
1732
- vr as v,
1733
- gr as w,
1733
+ Fe as u,
1734
+ mt as v,
1735
+ yr as w,
1734
1736
  hr as x,
1735
- Rt as y
1737
+ pr as y,
1738
+ Rt as z
1736
1739
  };