@d-id/client-sdk 1.1.24-staging.114 → 1.1.25

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