@d-id/client-sdk 1.1.32-staging.149 → 1.1.32-staging.150

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