@d-id/client-sdk 1.1.9 → 1.1.10-staging.35

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,27 +1,27 @@
1
1
  var ye = Object.defineProperty;
2
- var ve = (e, t, a) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
- var Y = (e, t, a) => (ve(e, typeof t != "symbol" ? t + "" : t, a), a);
2
+ var ve = (e, t, n) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Y = (e, t, n) => (ve(e, typeof t != "symbol" ? t + "" : t, n), n);
4
4
  class G extends Error {
5
5
  constructor({
6
- kind: a,
6
+ kind: n,
7
7
  description: r,
8
8
  error: s
9
9
  }) {
10
10
  super(JSON.stringify({
11
- kind: a,
11
+ kind: n,
12
12
  description: r
13
13
  }));
14
14
  Y(this, "kind");
15
15
  Y(this, "description");
16
16
  Y(this, "error");
17
- this.kind = a, this.description = r, this.error = s;
17
+ this.kind = n, this.description = r, this.error = s;
18
18
  }
19
19
  }
20
20
  class ke extends G {
21
- constructor(t, a) {
21
+ constructor(t, n) {
22
22
  super({
23
23
  kind: "ChatCreationFailed",
24
- description: `Failed to create ${a ? "persistent" : ""} chat, mode: ${t}`
24
+ description: `Failed to create ${n ? "persistent" : ""} chat, mode: ${t}`
25
25
  });
26
26
  }
27
27
  }
@@ -34,10 +34,10 @@ class De extends G {
34
34
  }
35
35
  }
36
36
  class H extends G {
37
- constructor(a, r) {
37
+ constructor(n, r) {
38
38
  super({
39
39
  kind: "ValidationError",
40
- description: a
40
+ description: n
41
41
  });
42
42
  Y(this, "key");
43
43
  this.key = r;
@@ -51,8 +51,8 @@ class Ce extends G {
51
51
  });
52
52
  }
53
53
  }
54
- var Re = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Re || {}), Ie = /* @__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))(Ie || {}), Se = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Se || {}), Ee = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ee || {}), _ = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(_ || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Me = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Me || {}), _e = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(_e || {}), Te = /* @__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))(Te || {}), je = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(je || {});
55
- const St = (e) => {
54
+ var Re = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Re || {}), Se = /* @__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))(Se || {}), Ie = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ie || {}), Ee = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ee || {}), M = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(M || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Me = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Me || {}), _e = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(_e || {}), Te = /* @__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))(Te || {}), je = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(je || {});
55
+ const It = (e) => {
56
56
  switch (e) {
57
57
  case "clip":
58
58
  return "clip";
@@ -62,22 +62,22 @@ const St = (e) => {
62
62
  throw new Error(`Unknown video type: ${e}`);
63
63
  }
64
64
  };
65
- var h = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(h || {}), Q = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Q || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", 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))(A || {}), 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 || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), be = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(be || {}), Pe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Pe || {});
65
+ var h = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(h || {}), Q = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Q || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", 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))(A || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Pe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Pe || {}), be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(be || {});
66
66
  const Ae = 45 * 1e3, Be = "X-Playground-Chat", Z = "https://api.d-id.com", Le = "wss://notifications.d-id.com", $e = "79f81a83a67430be2bc0fd61042b8faa", oe = (e) => new Promise((t) => setTimeout(t, e)), V = (e = 16) => {
67
67
  const t = new Uint8Array(e);
68
- return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
69
- }, ze = (e) => [_.TextOnly, _.Playground, _.Maintenance].includes(e), ce = (e) => e && [_.DirectPlayback, _.Off].includes(e);
68
+ return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
69
+ }, ze = (e) => [M.TextOnly, M.Playground, M.Maintenance].includes(e), ce = (e) => e && [M.DirectPlayback, M.Off].includes(e);
70
70
  function Fe(e, t) {
71
- let a;
71
+ let n;
72
72
  return {
73
73
  promise: new Promise((s, o) => {
74
- a = setTimeout(() => o(new Error(t)), e);
74
+ n = setTimeout(() => o(new Error(t)), e);
75
75
  }),
76
- clear: () => clearTimeout(a)
76
+ clear: () => clearTimeout(n)
77
77
  };
78
78
  }
79
79
  async function te(e, t) {
80
- const a = {
80
+ const n = {
81
81
  limit: (t == null ? void 0 : t.limit) ?? 3,
82
82
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
83
83
  timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
@@ -87,19 +87,19 @@ async function te(e, t) {
87
87
  })
88
88
  };
89
89
  let r;
90
- for (let s = 1; s <= a.limit; s++)
90
+ for (let s = 1; s <= n.limit; s++)
91
91
  try {
92
- if (!a.timeout)
92
+ if (!n.timeout)
93
93
  return await e();
94
94
  const {
95
95
  promise: o,
96
96
  clear: c
97
- } = Fe(a.timeout, a.timeoutErrorMessage), n = e().finally(c);
98
- return await Promise.race([n, o]);
97
+ } = Fe(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
98
+ return await Promise.race([a, o]);
99
99
  } catch (o) {
100
- if (r = o, !a.shouldRetryFn(o) || s >= a.limit)
100
+ if (r = o, !n.shouldRetryFn(o) || s >= n.limit)
101
101
  throw o;
102
- await oe(a.delayMs), a.onRetry(o);
102
+ await oe(n.delayMs), n.onRetry(o);
103
103
  }
104
104
  throw r;
105
105
  }
@@ -127,27 +127,27 @@ const xe = (e) => te(e, {
127
127
  timeout: 0,
128
128
  shouldRetryFn: (t) => t.status === 429
129
129
  });
130
- function ue(e, t = Z, a) {
130
+ function ue(e, t = Z, n) {
131
131
  const r = async (s, o) => {
132
132
  const {
133
133
  skipErrorHandler: c,
134
- ...n
134
+ ...a
135
135
  } = o || {}, i = await xe(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
136
- ...n,
136
+ ...a,
137
137
  headers: {
138
- ...n.headers,
138
+ ...a.headers,
139
139
  Authorization: le(e),
140
140
  "Content-Type": "application/json"
141
141
  }
142
142
  }));
143
143
  if (!i.ok) {
144
- let l = await i.text().catch(() => `Failed to fetch with status ${i.status}`);
145
- const d = new Error(l);
146
- throw a && !c && a(d, {
144
+ let d = await i.text().catch(() => `Failed to fetch with status ${i.status}`);
145
+ const l = new Error(d);
146
+ throw n && !c && n(l, {
147
147
  url: s,
148
- options: n,
148
+ options: a,
149
149
  headers: i.headers
150
- }), d;
150
+ }), l;
151
151
  }
152
152
  return i.json();
153
153
  };
@@ -181,8 +181,8 @@ function ue(e, t = Z, a) {
181
181
  }
182
182
  };
183
183
  }
184
- function fe(e, t = Z, a) {
185
- const r = ue(e, `${t}/agents`, a);
184
+ function fe(e, t = Z, n) {
185
+ const r = ue(e, `${t}/agents`, n);
186
186
  return {
187
187
  create(s, o) {
188
188
  return r.post("/", s, o);
@@ -202,17 +202,17 @@ function fe(e, t = Z, a) {
202
202
  newChat(s, o, c) {
203
203
  return r.post(`/${s}/chat`, o, c);
204
204
  },
205
- chat(s, o, c, n) {
206
- return r.post(`/${s}/chat/${o}`, c, n);
205
+ chat(s, o, c, a) {
206
+ return r.post(`/${s}/chat/${o}`, c, a);
207
207
  },
208
- createRating(s, o, c, n) {
209
- return r.post(`/${s}/chat/${o}/ratings`, c, n);
208
+ createRating(s, o, c, a) {
209
+ return r.post(`/${s}/chat/${o}/ratings`, c, a);
210
210
  },
211
- updateRating(s, o, c, n, i) {
212
- return r.patch(`/${s}/chat/${o}/ratings/${c}`, n, i);
211
+ updateRating(s, o, c, a, i) {
212
+ return r.patch(`/${s}/chat/${o}/ratings/${c}`, a, i);
213
213
  },
214
- deleteRating(s, o, c, n) {
215
- return r.delete(`/${s}/chat/${o}/ratings/${c}`, n);
214
+ deleteRating(s, o, c, a) {
215
+ return r.delete(`/${s}/chat/${o}/ratings/${c}`, a);
216
216
  },
217
217
  getSTTToken(s, o) {
218
218
  return r.get(`/${s}/stt-token`, o);
@@ -221,26 +221,26 @@ function fe(e, t = Z, a) {
221
221
  }
222
222
  const me = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
223
223
  function Je(e) {
224
- var s, o, c, n;
225
- const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
224
+ var s, o, c, a;
225
+ const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
226
226
  const i = navigator.platform;
227
227
  return i.toLowerCase().includes("win") ? "Windows" : i.toLowerCase().includes("mac") ? "Mac OS X" : i.toLowerCase().includes("linux") ? "Linux" : "Unknown";
228
228
  }, r = e.presenter;
229
229
  return {
230
- $os: `${a()}`,
230
+ $os: `${n()}`,
231
231
  isMobile: `${t() == "Mobile"}`,
232
232
  browser: navigator.userAgent,
233
233
  origin: window.location.origin,
234
234
  agentType: me(r),
235
235
  agentVoice: {
236
236
  voiceId: (o = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : o.voice_id,
237
- provider: (n = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : n.type
237
+ provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
238
238
  }
239
239
  };
240
240
  }
241
241
  function We(e) {
242
- var a, r, s, o, c, n;
243
- const t = (a = e.llm) == null ? void 0 : a.prompt_customization;
242
+ var n, r, s, o, c, a;
243
+ const t = (n = e.llm) == null ? void 0 : n.prompt_customization;
244
244
  return {
245
245
  agentType: me(e.presenter),
246
246
  owner_id: e.owner_id ?? "",
@@ -252,14 +252,20 @@ function We(e) {
252
252
  },
253
253
  temperature: (o = e.llm) == null ? void 0 : o.temperature,
254
254
  knowledgeSource: t == null ? void 0 : t.knowledge_source,
255
- starterQuestionsCount: (n = (c = e.knowledge) == null ? void 0 : c.starter_message) == null ? void 0 : n.length,
255
+ starterQuestionsCount: (a = (c = e.knowledge) == null ? void 0 : c.starter_message) == null ? void 0 : a.length,
256
256
  topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
257
- maxResponseLength: t == null ? void 0 : t.max_response_length
257
+ maxResponseLength: t == null ? void 0 : t.max_response_length,
258
+ agentId: e.id,
259
+ access: e.access,
260
+ name: e.preview_name,
261
+ ...e.access === "public" ? {
262
+ from: "agent-template"
263
+ } : {}
258
264
  };
259
265
  }
260
- const Ue = (e) => e.reduce((t, a) => t + a, 0), ae = (e) => Ue(e) / e.length;
261
- function Ke(e, t, a) {
262
- var i, l, d;
266
+ const Ue = (e) => e.reduce((t, n) => t + n, 0), ae = (e) => Ue(e) / e.length;
267
+ function Ke(e, t, n) {
268
+ var i, d, l;
263
269
  const {
264
270
  event: r,
265
271
  ...s
@@ -277,12 +283,12 @@ function Ke(e, t, a) {
277
283
  script: {
278
284
  ...s.script,
279
285
  provider: {
280
- ...(l = s == null ? void 0 : s.script) == null ? void 0 : l.provider,
286
+ ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider,
281
287
  language: c
282
288
  }
283
289
  },
284
- stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (d = t == null ? void 0 : t.presenter) == null ? void 0 : d.stitch : void 0,
285
- ...a
290
+ stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (l = t == null ? void 0 : t.presenter) == null ? void 0 : l.stitch : void 0,
291
+ ...n
286
292
  };
287
293
  }
288
294
  let ee = {};
@@ -296,13 +302,13 @@ function qe(e) {
296
302
  additionalProperties: {},
297
303
  isEnabled: e.isEnabled ?? !0,
298
304
  getRandom: V,
299
- enrich(a) {
305
+ enrich(n) {
300
306
  this.additionalProperties = {
301
307
  ...this.additionalProperties,
302
- ...a
308
+ ...n
303
309
  };
304
310
  },
305
- async track(a, r) {
311
+ async track(n, r) {
306
312
  if (!this.isEnabled)
307
313
  return Promise.resolve();
308
314
  const {
@@ -315,7 +321,7 @@ function qe(e) {
315
321
  },
316
322
  body: new URLSearchParams({
317
323
  data: JSON.stringify([{
318
- event: a,
324
+ event: n,
319
325
  properties: {
320
326
  ...this.additionalProperties,
321
327
  ...o,
@@ -333,26 +339,26 @@ function qe(e) {
333
339
  })
334
340
  };
335
341
  try {
336
- return await fetch(He, c).then((n) => n.json());
337
- } catch (n) {
338
- return console.error(n);
342
+ return await fetch(He, c).then((a) => a.json());
343
+ } catch (a) {
344
+ return console.error(a);
339
345
  }
340
346
  },
341
- linkTrack(a, r, s, o) {
342
- ee[a] || (ee[a] = {
347
+ linkTrack(n, r, s, o) {
348
+ ee[n] || (ee[n] = {
343
349
  events: {},
344
350
  resolvedDependencies: []
345
351
  }), o.includes(s) || o.push(s);
346
- const c = ee[a];
352
+ const c = ee[n];
347
353
  if (c.events[s] = {
348
354
  props: r
349
355
  }, c.resolvedDependencies.push(s), o.every((i) => c.resolvedDependencies.includes(i))) {
350
- const i = o.reduce((l, d) => c.events[d] ? {
351
- ...l,
352
- ...c.events[d].props
353
- } : l, {});
354
- this.track(a, i), c.resolvedDependencies = c.resolvedDependencies.filter((l) => !o.includes(l)), o.forEach((l) => {
355
- delete c.events[l];
356
+ const i = o.reduce((d, l) => c.events[l] ? {
357
+ ...d,
358
+ ...c.events[l].props
359
+ } : d, {});
360
+ this.track(n, i), c.resolvedDependencies = c.resolvedDependencies.filter((d) => !o.includes(d)), o.forEach((d) => {
361
+ delete c.events[d];
356
362
  });
357
363
  }
358
364
  }
@@ -368,37 +374,31 @@ function ge() {
368
374
  }
369
375
  const N = ge(), re = ge();
370
376
  function he(e) {
371
- return e === _.Playground ? {
377
+ return e === M.Playground ? {
372
378
  headers: {
373
379
  [Be]: "true"
374
380
  }
375
381
  } : {};
376
382
  }
377
- async function we(e, t, a, r, s = !1, o) {
383
+ async function we(e, t, n, r, s = !1, o) {
378
384
  try {
379
385
  return !o && !ce(r) && (o = await t.newChat(e.id, {
380
386
  persist: s
381
- }, he(r)), a.track("agent-chat", {
387
+ }, he(r)), n.track("agent-chat", {
382
388
  event: "created",
383
389
  chatId: o.id,
384
- agentId: e.id,
385
- mode: r,
386
- access: e.access,
387
- name: e.preview_name,
388
- ...e.access === "public" ? {
389
- from: "agent-template"
390
- } : {}
390
+ mode: r
391
391
  })), {
392
392
  chat: o,
393
393
  chatMode: (o == null ? void 0 : o.chat_mode) ?? r
394
394
  };
395
395
  } catch (c) {
396
396
  try {
397
- const n = JSON.parse(c.message);
398
- if ((n == null ? void 0 : n.kind) === "InsufficientCreditsError")
397
+ const a = JSON.parse(c.message);
398
+ if ((a == null ? void 0 : a.kind) === "InsufficientCreditsError")
399
399
  throw new Error("InsufficientCreditsError");
400
- } catch (n) {
401
- console.error("Error parsing the error message:", n);
400
+ } catch (a) {
401
+ console.error("Error parsing the error message:", a);
402
402
  }
403
403
  throw new Error("Cannot create new chat");
404
404
  }
@@ -406,40 +406,40 @@ async function we(e, t, a, r, s = !1, o) {
406
406
  function Ve(e) {
407
407
  return e && e.length > 0 ? e : [];
408
408
  }
409
- function Oe(e, t, a) {
409
+ function Oe(e, t, n) {
410
410
  if (!e)
411
411
  throw new Error("Please connect to the agent first");
412
412
  if (!e.interruptAvailable)
413
413
  throw new Error("Interrupt is not enabled for this stream");
414
414
  if (t !== W.Fluent)
415
415
  throw new Error("Interrupt only available for Fluent streams");
416
- if (!a)
416
+ if (!n)
417
417
  throw new Error("No active video to interrupt");
418
418
  }
419
419
  async function Xe(e, t) {
420
- const a = {
420
+ const n = {
421
421
  type: A.StreamInterrupt,
422
422
  videoId: t,
423
423
  timestamp: Date.now()
424
424
  };
425
- e.sendDataChannelMessage(JSON.stringify(a));
425
+ e.sendDataChannelMessage(JSON.stringify(n));
426
426
  }
427
427
  function Ye(e) {
428
- return new Promise((t, a) => {
428
+ return new Promise((t, n) => {
429
429
  const {
430
430
  callbacks: r,
431
431
  host: s,
432
432
  auth: o
433
433
  } = e, {
434
434
  onMessage: c = null,
435
- onOpen: n = null,
435
+ onOpen: a = null,
436
436
  onClose: i = null,
437
- onError: l = null
438
- } = r || {}, d = new WebSocket(`${s}?authorization=${le(o)}`);
439
- d.onmessage = c, d.onclose = i, d.onerror = (y) => {
440
- console.error(y), l == null || l("Websocket failed to connect", y), a(y);
441
- }, d.onopen = (y) => {
442
- n == null || n(y), t(d);
437
+ onError: d = null
438
+ } = r || {}, l = new WebSocket(`${s}?authorization=${le(o)}`);
439
+ l.onmessage = c, l.onclose = i, l.onerror = (y) => {
440
+ console.error(y), d == null || d("Websocket failed to connect", y), n(y);
441
+ }, l.onopen = (y) => {
442
+ a == null || a(y), t(l);
443
443
  };
444
444
  });
445
445
  }
@@ -447,29 +447,29 @@ async function Qe(e) {
447
447
  const {
448
448
  retries: t = 1
449
449
  } = e;
450
- let a = null;
451
- for (let r = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; r++)
450
+ let n = null;
451
+ for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
452
452
  try {
453
- a = await Ye(e);
453
+ n = await Ye(e);
454
454
  } catch (s) {
455
455
  if (r === t)
456
456
  throw s;
457
457
  await oe(r * 500);
458
458
  }
459
- return a;
459
+ return n;
460
460
  }
461
- async function Ze(e, t, a) {
462
- const r = a != null && a.onMessage ? [a.onMessage] : [], s = await Qe({
461
+ async function Ze(e, t, n) {
462
+ const r = n != null && n.onMessage ? [n.onMessage] : [], s = await Qe({
463
463
  auth: e,
464
464
  host: t,
465
465
  callbacks: {
466
466
  onError: (o) => {
467
467
  var c;
468
- return (c = a.onError) == null ? void 0 : c.call(a, new Ce(o));
468
+ return (c = n.onError) == null ? void 0 : c.call(n, new Ce(o));
469
469
  },
470
470
  onMessage(o) {
471
471
  const c = JSON.parse(o.data);
472
- r.forEach((n) => n(c.event, c));
472
+ r.forEach((a) => a(c.event, c));
473
473
  }
474
474
  }
475
475
  });
@@ -482,79 +482,79 @@ async function Ze(e, t, a) {
482
482
  function Ge(e) {
483
483
  if (e.answer !== void 0)
484
484
  return e.answer;
485
- let t = 0, a = "";
485
+ let t = 0, n = "";
486
486
  for (; t in e; )
487
- a += e[t++];
488
- return a;
487
+ n += e[t++];
488
+ return n;
489
489
  }
490
- function et(e, t, a, r, s) {
490
+ function et(e, t, n, r, s) {
491
491
  const o = r.messages[r.messages.length - 1];
492
492
  if (!(e === q.Partial || e === q.Answer) || (o == null ? void 0 : o.role) !== "assistant")
493
493
  return;
494
494
  const {
495
495
  content: c,
496
- sequence: n
496
+ sequence: a
497
497
  } = t;
498
- e === q.Partial ? a[n] = c : a.answer = c;
499
- const i = Ge(a);
498
+ e === q.Partial ? n[a] = c : n.answer = c;
499
+ const i = Ge(n);
500
500
  (o.content !== i || e === q.Answer) && (o.content = i, s == null || s([...r.messages], e));
501
501
  }
502
- function tt(e, t, a, r, s) {
502
+ function tt(e, t, n, r, s) {
503
503
  let o = {};
504
504
  return {
505
505
  clearQueue: () => o = {},
506
- onMessage: (c, n) => {
507
- var i, l;
508
- if ("content" in n)
509
- et(c, n, o, t, a.callbacks.onNewMessage), c === q.Answer && e.track("agent-message-received", {
506
+ onMessage: (c, a) => {
507
+ var i, d;
508
+ if ("content" in a)
509
+ et(c, a, o, t, n.callbacks.onNewMessage), c === q.Answer && e.track("agent-message-received", {
510
510
  messages: t.messages.length,
511
511
  mode: t.chatMode
512
512
  });
513
513
  else {
514
- const d = A, y = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], T = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], j = Ke(n, r, {
514
+ const l = A, y = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], _ = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], T = Ke(a, r, {
515
515
  mode: t.chatMode
516
516
  });
517
- if (c = c, c === d.StreamVideoCreated)
518
- e.linkTrack("agent-video", j, d.StreamVideoCreated, ["start"]);
517
+ if (c = c, c === l.StreamVideoCreated)
518
+ e.linkTrack("agent-video", T, l.StreamVideoCreated, ["start"]);
519
519
  else if (y.includes(c)) {
520
- const b = c.split("/")[1];
521
- T.includes(c) ? e.track("agent-video", {
522
- ...j,
523
- event: b
520
+ const j = c.split("/")[1];
521
+ _.includes(c) ? e.track("agent-video", {
522
+ ...T,
523
+ event: j
524
524
  }) : e.linkTrack("agent-video", {
525
- ...j,
526
- event: b
525
+ ...T,
526
+ event: j
527
527
  }, c, ["done"]);
528
528
  }
529
- T.includes(c) && ((l = (i = a.callbacks).onError) == null || l.call(i, new Error(`Stream failed with event ${c}`), {
530
- data: n
531
- })), n.event === d.StreamDone && s();
529
+ _.includes(c) && ((d = (i = n.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${c}`), {
530
+ data: a
531
+ })), a.event === l.StreamDone && s();
532
532
  }
533
533
  }
534
534
  };
535
535
  }
536
- function rt(e, t, a, r) {
537
- const s = ue(e, `${t}/agents/${a}`, r);
536
+ function rt(e, t, n, r) {
537
+ const s = ue(e, `${t}/agents/${n}`, r);
538
538
  return {
539
539
  createStream(o) {
540
540
  return s.post("/streams", o);
541
541
  },
542
- startConnection(o, c, n) {
542
+ startConnection(o, c, a) {
543
543
  return s.post(`/streams/${o}/sdp`, {
544
- session_id: n,
544
+ session_id: a,
545
545
  answer: c
546
546
  });
547
547
  },
548
- addIceCandidate(o, c, n) {
548
+ addIceCandidate(o, c, a) {
549
549
  return s.post(`/streams/${o}/ice`, {
550
- session_id: n,
550
+ session_id: a,
551
551
  ...c
552
552
  });
553
553
  },
554
- sendStreamRequest(o, c, n) {
554
+ sendStreamRequest(o, c, a) {
555
555
  return s.post(`/streams/${o}`, {
556
556
  session_id: c,
557
- ...n
557
+ ...a
558
558
  });
559
559
  },
560
560
  close(o, c) {
@@ -564,7 +564,7 @@ function rt(e, t, a, r) {
564
564
  }
565
565
  };
566
566
  }
567
- function nt(e, t, a) {
567
+ function nt(e, t, n) {
568
568
  const r = (t.timestamp - e.timestamp) / 1e3;
569
569
  return {
570
570
  duration: r,
@@ -581,13 +581,13 @@ function nt(e, t, a) {
581
581
  framesPerSecond: t.framesPerSecond,
582
582
  freezeCount: t.freezeCount - e.freezeCount,
583
583
  freezeDuration: t.freezeDuration - e.freezeDuration,
584
- lowFpsCount: a
584
+ lowFpsCount: n
585
585
  };
586
586
  }
587
587
  function at(e) {
588
588
  return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
589
589
  const {
590
- timestamp: a,
590
+ timestamp: n,
591
591
  ...r
592
592
  } = t, s = [];
593
593
  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"), {
@@ -597,12 +597,12 @@ function at(e) {
597
597
  });
598
598
  }
599
599
  function it(e) {
600
- let t = "", a = 0;
600
+ let t = "", n = 0;
601
601
  for (const r of e.values())
602
- if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (a = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
602
+ if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (n = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
603
603
  return {
604
604
  codec: t,
605
- rtt: a,
605
+ rtt: n,
606
606
  timestamp: r.timestamp,
607
607
  bytesReceived: r.bytesReceived,
608
608
  packetsReceived: r.packetsReceived,
@@ -621,24 +621,24 @@ function it(e) {
621
621
  };
622
622
  return {};
623
623
  }
624
- function st(e, t, a) {
625
- const r = e.map((i, l) => l === 0 ? a ? {
624
+ function st(e, t, n) {
625
+ const r = e.map((i, d) => d === 0 ? n ? {
626
626
  timestamp: i.timestamp,
627
627
  duration: 0,
628
628
  rtt: i.rtt,
629
- bytesReceived: i.bytesReceived - a.bytesReceived,
630
- bitrate: (i.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
631
- packetsReceived: i.packetsReceived - a.packetsReceived,
632
- packetsLost: i.packetsLost - a.packetsLost,
633
- framesDropped: i.framesDropped - a.framesDropped,
634
- framesDecoded: i.framesDecoded - a.framesDecoded,
629
+ bytesReceived: i.bytesReceived - n.bytesReceived,
630
+ bitrate: (i.bytesReceived - n.bytesReceived) * 8 / (t / 1e3),
631
+ packetsReceived: i.packetsReceived - n.packetsReceived,
632
+ packetsLost: i.packetsLost - n.packetsLost,
633
+ framesDropped: i.framesDropped - n.framesDropped,
634
+ framesDecoded: i.framesDecoded - n.framesDecoded,
635
635
  jitter: i.jitter,
636
- jitterBufferDelay: i.jitterBufferDelay - a.jitterBufferDelay,
637
- jitterBufferEmittedCount: i.jitterBufferEmittedCount - a.jitterBufferEmittedCount,
638
- avgJitterDelayInInterval: (i.jitterBufferDelay - a.jitterBufferDelay) / (i.jitterBufferEmittedCount - a.jitterBufferEmittedCount),
636
+ jitterBufferDelay: i.jitterBufferDelay - n.jitterBufferDelay,
637
+ jitterBufferEmittedCount: i.jitterBufferEmittedCount - n.jitterBufferEmittedCount,
638
+ avgJitterDelayInInterval: (i.jitterBufferDelay - n.jitterBufferDelay) / (i.jitterBufferEmittedCount - n.jitterBufferEmittedCount),
639
639
  framesPerSecond: i.framesPerSecond,
640
- freezeCount: i.freezeCount - a.freezeCount,
641
- freezeDuration: i.freezeDuration - a.freezeDuration
640
+ freezeCount: i.freezeCount - n.freezeCount,
641
+ freezeDuration: i.freezeDuration - n.freezeDuration
642
642
  } : {
643
643
  timestamp: i.timestamp,
644
644
  rtt: i.rtt,
@@ -658,28 +658,28 @@ function st(e, t, a) {
658
658
  freezeDuration: i.freezeDuration
659
659
  } : {
660
660
  timestamp: i.timestamp,
661
- duration: t * l / 1e3,
661
+ duration: t * d / 1e3,
662
662
  rtt: i.rtt,
663
- bytesReceived: i.bytesReceived - e[l - 1].bytesReceived,
664
- bitrate: (i.bytesReceived - e[l - 1].bytesReceived) * 8 / (t / 1e3),
665
- packetsReceived: i.packetsReceived - e[l - 1].packetsReceived,
666
- packetsLost: i.packetsLost - e[l - 1].packetsLost,
667
- framesDropped: i.framesDropped - e[l - 1].framesDropped,
668
- framesDecoded: i.framesDecoded - e[l - 1].framesDecoded,
663
+ bytesReceived: i.bytesReceived - e[d - 1].bytesReceived,
664
+ bitrate: (i.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
665
+ packetsReceived: i.packetsReceived - e[d - 1].packetsReceived,
666
+ packetsLost: i.packetsLost - e[d - 1].packetsLost,
667
+ framesDropped: i.framesDropped - e[d - 1].framesDropped,
668
+ framesDecoded: i.framesDecoded - e[d - 1].framesDecoded,
669
669
  jitter: i.jitter,
670
- jitterBufferDelay: i.jitterBufferDelay - e[l - 1].jitterBufferDelay,
671
- jitterBufferEmittedCount: i.jitterBufferEmittedCount - e[l - 1].jitterBufferEmittedCount,
672
- avgJitterDelayInInterval: (i.jitterBufferDelay - e[l - 1].jitterBufferDelay) / (i.jitterBufferEmittedCount - e[l - 1].jitterBufferEmittedCount),
670
+ jitterBufferDelay: i.jitterBufferDelay - e[d - 1].jitterBufferDelay,
671
+ jitterBufferEmittedCount: i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
672
+ avgJitterDelayInInterval: (i.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
673
673
  framesPerSecond: i.framesPerSecond,
674
- freezeCount: i.freezeCount - e[l - 1].freezeCount,
675
- freezeDuration: i.freezeDuration - e[l - 1].freezeDuration
676
- }), s = at(r), o = s.reduce((i, l) => i + (l.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), n = r.filter((i) => !!i.rtt).map((i) => i.rtt);
674
+ freezeCount: i.freezeCount - e[d - 1].freezeCount,
675
+ freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
676
+ }), s = at(r), o = s.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), a = r.filter((i) => !!i.rtt).map((i) => i.rtt);
677
677
  return {
678
678
  webRTCStats: {
679
679
  anomalies: s,
680
- minRtt: Math.min(...n),
681
- avgRtt: ae(n),
682
- maxRtt: Math.max(...n),
680
+ minRtt: Math.min(...a),
681
+ avgRtt: ae(a),
682
+ maxRtt: Math.max(...a),
683
683
  aggregateReport: nt(e[0], e[e.length - 1], o),
684
684
  minJitterDelayInInterval: Math.min(...c),
685
685
  maxJitterDelayInInterval: Math.max(...c),
@@ -691,19 +691,19 @@ function st(e, t, a) {
691
691
  }
692
692
  const ne = 100, ot = Math.max(Math.ceil(400 / ne), 1), ct = 0.25, dt = 0.28;
693
693
  function lt() {
694
- let e = 0, t, a, r = 0;
694
+ let e = 0, t, n, r = 0;
695
695
  return (s) => {
696
696
  for (const o of s.values())
697
697
  if (o && o.type === "inbound-rtp" && o.kind === "video") {
698
- const c = o.jitterBufferDelay, n = o.jitterBufferEmittedCount;
699
- if (a && n > a) {
700
- const d = c - t, y = n - a;
701
- r = d / y;
698
+ const c = o.jitterBufferDelay, a = o.jitterBufferEmittedCount;
699
+ if (n && a > n) {
700
+ const l = c - t, y = a - n;
701
+ r = l / y;
702
702
  }
703
- t = c, a = n;
704
- const i = o.framesDecoded, l = i - e > 0;
703
+ t = c, n = a;
704
+ const i = o.framesDecoded, d = i - e > 0;
705
705
  return e = i, {
706
- isReceiving: l,
706
+ isReceiving: d,
707
707
  avgJitterDelayInInterval: r,
708
708
  freezeCount: o.freezeCount
709
709
  };
@@ -714,20 +714,20 @@ function lt() {
714
714
  };
715
715
  };
716
716
  }
717
- function ut(e, t, a, r, s, o = !1) {
718
- let c = [], n, i = 0, l = !1, d = Q.Unknown, y = Q.Unknown, T = 0, j = 0;
719
- const b = lt();
717
+ function ut(e, t, n, r, s, o = !1) {
718
+ let c = [], a, i = 0, d = !1, l = Q.Unknown, y = Q.Unknown, _ = 0, T = 0;
719
+ const j = lt();
720
720
  return setInterval(async () => {
721
721
  const x = await e.getStats(), {
722
722
  isReceiving: R,
723
723
  avgJitterDelayInInterval: U,
724
724
  freezeCount: K
725
- } = b(x), P = it(x);
725
+ } = j(x), P = it(x);
726
726
  if (R)
727
- i = 0, T = K - j, y = U < ct ? Q.Strong : U > dt && T > 1 ? Q.Weak : d, y !== d && (s == null || s(y), d = y, j += T, T = 0), l || (r == null || r(h.Start), n = c[c.length - 1], c = [], l = !0), c.push(P);
728
- else if (l && (i++, i >= ot)) {
729
- const u = st(c, ne, n);
730
- r == null || r(h.Stop, u), t() || a(), j = K, l = !1;
727
+ i = 0, _ = K - T, y = U < ct ? Q.Strong : U > dt && _ > 1 ? Q.Weak : l, y !== l && (s == null || s(y), l = y, T += _, _ = 0), d || (r == null || r(h.Start), a = c[c.length - 1], c = [], d = !0), c.push(P);
728
+ else if (d && (i++, i >= ot)) {
729
+ const u = st(c, ne, a);
730
+ r == null || r(h.Stop, u), t() || n(), T = K, d = !1;
731
731
  }
732
732
  }, ne);
733
733
  }
@@ -736,27 +736,27 @@ const B = (e, t) => pe && console.log(e, t), ft = (window.RTCPeerConnection || w
736
736
  function ie(e) {
737
737
  switch (e) {
738
738
  case "connected":
739
- return S.Connected;
739
+ return I.Connected;
740
740
  case "checking":
741
- return S.Connecting;
741
+ return I.Connecting;
742
742
  case "failed":
743
- return S.Fail;
743
+ return I.Fail;
744
744
  case "new":
745
- return S.New;
745
+ return I.New;
746
746
  case "closed":
747
- return S.Closed;
747
+ return I.Closed;
748
748
  case "disconnected":
749
- return S.Disconnected;
749
+ return I.Disconnected;
750
750
  case "completed":
751
- return S.Completed;
751
+ return I.Completed;
752
752
  default:
753
- return S.New;
753
+ return I.New;
754
754
  }
755
755
  }
756
756
  function mt(e) {
757
- const [t, a = ""] = e.split(/:(.+)/);
757
+ const [t, n = ""] = e.split(/:(.+)/);
758
758
  try {
759
- const r = JSON.parse(a);
759
+ const r = JSON.parse(n);
760
760
  return B("parsed data channel message", {
761
761
  subject: t,
762
762
  data: r
@@ -767,35 +767,35 @@ function mt(e) {
767
767
  } catch (r) {
768
768
  return B("Failed to parse data channel message, returning data as string", {
769
769
  subject: t,
770
- rawData: a,
770
+ rawData: n,
771
771
  error: r
772
772
  }), {
773
773
  subject: t,
774
- data: a
774
+ data: n
775
775
  };
776
776
  }
777
777
  }
778
778
  function gt({
779
779
  statsSignal: e,
780
780
  dataChannelSignal: t,
781
- onVideoStateChange: a,
781
+ onVideoStateChange: n,
782
782
  report: r
783
783
  }) {
784
- e === h.Start && t === h.Start ? a == null || a(h.Start) : e === h.Stop && t === h.Stop && (a == null || a(h.Stop, r));
784
+ e === h.Start && t === h.Start ? n == null || n(h.Start) : e === h.Stop && t === h.Stop && (n == null || n(h.Stop, r));
785
785
  }
786
786
  function ht({
787
787
  statsSignal: e,
788
788
  dataChannelSignal: t,
789
- onVideoStateChange: a,
789
+ onVideoStateChange: n,
790
790
  onAgentActivityStateChange: r,
791
791
  report: s
792
792
  }) {
793
- e === h.Start ? a == null || a(h.Start) : e === h.Stop && (a == null || a(h.Stop, s)), t === h.Start ? r == null || r(O.Talking) : t === h.Stop && (r == null || r(O.Idle));
793
+ e === h.Start ? n == null || n(h.Start) : e === h.Stop && (n == null || n(h.Stop, s)), t === h.Start ? r == null || r(O.Talking) : t === h.Stop && (r == null || r(O.Idle));
794
794
  }
795
795
  function se({
796
796
  statsSignal: e,
797
797
  dataChannelSignal: t,
798
- onVideoStateChange: a,
798
+ onVideoStateChange: n,
799
799
  onAgentActivityStateChange: r,
800
800
  streamType: s,
801
801
  report: o
@@ -803,31 +803,31 @@ function se({
803
803
  s === W.Legacy ? gt({
804
804
  statsSignal: e,
805
805
  dataChannelSignal: t,
806
- onVideoStateChange: a,
806
+ onVideoStateChange: n,
807
807
  report: o
808
808
  }) : s === W.Fluent && ht({
809
809
  statsSignal: e,
810
810
  dataChannelSignal: t,
811
- onVideoStateChange: a,
811
+ onVideoStateChange: n,
812
812
  onAgentActivityStateChange: r,
813
813
  report: o
814
814
  });
815
815
  }
816
816
  async function wt(e, t, {
817
- debug: a = !1,
817
+ debug: n = !1,
818
818
  callbacks: r,
819
819
  auth: s,
820
820
  baseURL: o = Z,
821
821
  analytics: c
822
822
  }) {
823
823
  var J;
824
- pe = a;
825
- let n = !1, i = !1, l = h.Stop, d = h.Stop;
824
+ pe = n;
825
+ let a = !1, i = !1, d = h.Stop, l = h.Stop;
826
826
  const {
827
827
  startConnection: y,
828
- sendStreamRequest: T,
829
- close: j,
830
- createStream: b,
828
+ sendStreamRequest: _,
829
+ close: T,
830
+ createStream: j,
831
831
  addIceCandidate: x
832
832
  } = rt(s, o, e, r.onError), {
833
833
  id: R,
@@ -835,8 +835,8 @@ async function wt(e, t, {
835
835
  ice_servers: K,
836
836
  session_id: P,
837
837
  fluent: u,
838
- interrupt_enabled: w
839
- } = await b(t);
838
+ interrupt_enabled: v
839
+ } = await j(t);
840
840
  (J = r.onStreamCreated) == null || J.call(r, {
841
841
  stream_id: R,
842
842
  session_id: P,
@@ -847,20 +847,20 @@ async function wt(e, t, {
847
847
  }), D = m.createDataChannel("JanusDataChannel");
848
848
  if (!P)
849
849
  throw new Error("Could not create session_id");
850
- const v = u ? W.Fluent : W.Legacy;
850
+ const w = u ? W.Fluent : W.Legacy;
851
851
  c.enrich({
852
- "stream-type": v
852
+ "stream-type": w
853
853
  });
854
- const p = t.stream_warmup && !u, E = () => n, L = () => {
854
+ const p = t.stream_warmup && !u, b = () => a, L = () => {
855
855
  var f;
856
- n = !0, i && ((f = r.onConnectionStateChange) == null || f.call(r, S.Connected));
857
- }, $ = ut(m, E, L, (f, g) => se({
858
- statsSignal: d = f,
859
- dataChannelSignal: v === W.Legacy ? l : void 0,
856
+ a = !0, i && ((f = r.onConnectionStateChange) == null || f.call(r, I.Connected));
857
+ }, $ = ut(m, b, L, (f, g) => se({
858
+ statsSignal: l = f,
859
+ dataChannelSignal: w === W.Legacy ? d : void 0,
860
860
  onVideoStateChange: r.onVideoStateChange,
861
861
  onAgentActivityStateChange: r.onAgentActivityStateChange,
862
862
  report: g,
863
- streamType: v
863
+ streamType: w
864
864
  }), (f) => {
865
865
  var g;
866
866
  return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
@@ -876,56 +876,56 @@ async function wt(e, t, {
876
876
  }, P) : x(R, {
877
877
  candidate: null
878
878
  }, P);
879
- } catch (I) {
880
- (g = r.onError) == null || g.call(r, I, {
879
+ } catch (S) {
880
+ (g = r.onError) == null || g.call(r, S, {
881
881
  streamId: R
882
882
  });
883
883
  }
884
884
  }, D.onopen = () => {
885
- i = !0, (!p || n) && L();
885
+ i = !0, (!p || a) && L();
886
886
  };
887
887
  const k = (f) => {
888
888
  var g;
889
889
  (g = r.onVideoIdChange) == null || g.call(r, f);
890
890
  };
891
- function M(f, g) {
891
+ function E(f, g) {
892
892
  if (f === A.StreamStarted && typeof g == "object" && "metadata" in g) {
893
- const I = g.metadata;
894
- k(I.videoId);
893
+ const S = g.metadata;
894
+ k(S.videoId);
895
895
  }
896
- f === A.StreamDone && k(null), l = f === A.StreamStarted ? h.Start : h.Stop, se({
897
- statsSignal: v === W.Legacy ? d : void 0,
898
- dataChannelSignal: l,
896
+ f === A.StreamDone && k(null), d = f === A.StreamStarted ? h.Start : h.Stop, se({
897
+ statsSignal: w === W.Legacy ? l : void 0,
898
+ dataChannelSignal: d,
899
899
  onVideoStateChange: r.onVideoStateChange,
900
900
  onAgentActivityStateChange: r.onAgentActivityStateChange,
901
- streamType: v
901
+ streamType: w
902
902
  });
903
903
  }
904
904
  function C(f, g) {
905
- const I = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
906
- I && c.enrich({
907
- streamMetadata: I
905
+ const S = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
906
+ S && c.enrich({
907
+ streamMetadata: S
908
908
  }), c.track("agent-chat", {
909
909
  event: "ready"
910
910
  });
911
911
  }
912
912
  const z = {
913
- [A.StreamStarted]: M,
914
- [A.StreamDone]: M,
913
+ [A.StreamStarted]: E,
914
+ [A.StreamDone]: E,
915
915
  [A.StreamReady]: C
916
916
  };
917
917
  D.onmessage = (f) => {
918
918
  var X;
919
919
  const {
920
920
  subject: g,
921
- data: I
921
+ data: S
922
922
  } = mt(f.data);
923
- (X = z[g]) == null || X.call(z, g, I);
923
+ (X = z[g]) == null || X.call(z, g, S);
924
924
  }, m.oniceconnectionstatechange = () => {
925
925
  var g;
926
926
  B("peerConnection.oniceconnectionstatechange => " + m.iceConnectionState);
927
927
  const f = ie(m.iceConnectionState);
928
- f !== S.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
928
+ f !== I.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
929
929
  }, m.ontrack = (f) => {
930
930
  var g;
931
931
  B("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
@@ -937,7 +937,7 @@ async function wt(e, t, {
937
937
  * @param payload
938
938
  */
939
939
  speak(f) {
940
- return T(R, P, f);
940
+ return _(R, P, f);
941
941
  },
942
942
  /**
943
943
  * Method to close RTC connection
@@ -947,17 +947,17 @@ async function wt(e, t, {
947
947
  if (R) {
948
948
  const g = ie(m.iceConnectionState);
949
949
  if (m) {
950
- if (g === S.New) {
950
+ if (g === I.New) {
951
951
  clearInterval($);
952
952
  return;
953
953
  }
954
954
  m.close(), m.oniceconnectionstatechange = null, m.onnegotiationneeded = null, m.onicecandidate = null, m.ontrack = null;
955
955
  }
956
956
  try {
957
- g === S.Connected && await j(R, P).catch((I) => {
957
+ g === I.Connected && await T(R, P).catch((S) => {
958
958
  });
959
- } catch (I) {
960
- B("Error on close stream connection", I);
959
+ } catch (S) {
960
+ B("Error on close stream connection", S);
961
961
  }
962
962
  (f = r.onAgentActivityStateChange) == null || f.call(r, O.Idle), clearInterval($);
963
963
  }
@@ -966,8 +966,8 @@ async function wt(e, t, {
966
966
  * Method to send data channel messages to the server
967
967
  */
968
968
  sendDataChannelMessage(f) {
969
- var g, I;
970
- if (!n || D.readyState !== "open") {
969
+ var g, S;
970
+ if (!a || D.readyState !== "open") {
971
971
  B("Data channel is not ready for sending messages"), (g = r.onError) == null || g.call(r, new Error("Data channel is not ready for sending messages"), {
972
972
  streamId: R
973
973
  });
@@ -976,7 +976,7 @@ async function wt(e, t, {
976
976
  try {
977
977
  D.send(f);
978
978
  } catch (X) {
979
- B("Error sending data channel message", X), (I = r.onError) == null || I.call(r, X, {
979
+ B("Error sending data channel message", X), (S = r.onError) == null || S.call(r, X, {
980
980
  streamId: R
981
981
  });
982
982
  }
@@ -989,8 +989,8 @@ async function wt(e, t, {
989
989
  * Id of current RTC stream
990
990
  */
991
991
  streamId: R,
992
- streamType: v,
993
- interruptAvailable: w
992
+ streamType: w,
993
+ interruptAvailable: v
994
994
  };
995
995
  }
996
996
  function pt(e) {
@@ -1005,10 +1005,10 @@ function pt(e) {
1005
1005
  fluent: t == null ? void 0 : t.fluent
1006
1006
  };
1007
1007
  }
1008
- function yt(e, t, a, r, s) {
1009
- s === W.Fluent ? vt(e, t, a, r, s) : Dt(e, t, a, r, s);
1008
+ function yt(e, t, n, r, s) {
1009
+ s === W.Fluent ? vt(e, t, n, r, s) : Dt(e, t, n, r, s);
1010
1010
  }
1011
- function vt(e, t, a, r, s) {
1011
+ function vt(e, t, n, r, s) {
1012
1012
  e === h.Start ? r.track("stream-session", {
1013
1013
  event: "start",
1014
1014
  "stream-type": s
@@ -1017,22 +1017,22 @@ function vt(e, t, a, r, s) {
1017
1017
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1018
1018
  background: t.presenter.type === "clip" && t.presenter.background,
1019
1019
  "stream-type": s,
1020
- ...a
1020
+ ...n
1021
1021
  });
1022
1022
  }
1023
- function kt(e, t, a, r) {
1024
- N.get() <= 0 || (e === h.Start ? a.linkTrack("agent-video", {
1023
+ function kt(e, t, n, r) {
1024
+ N.get() <= 0 || (e === h.Start ? n.linkTrack("agent-video", {
1025
1025
  event: "start",
1026
1026
  latency: N.get(!0),
1027
1027
  "stream-type": r
1028
- }, "start", [A.StreamVideoCreated]) : e === h.Stop && a.linkTrack("agent-video", {
1028
+ }, "start", [A.StreamVideoCreated]) : e === h.Stop && n.linkTrack("agent-video", {
1029
1029
  event: "stop",
1030
1030
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1031
1031
  background: t.presenter.type === "clip" && t.presenter.background,
1032
1032
  "stream-type": r
1033
1033
  }, "done", [A.StreamVideoDone]));
1034
1034
  }
1035
- function Dt(e, t, a, r, s) {
1035
+ function Dt(e, t, n, r, s) {
1036
1036
  N.get() <= 0 || (e === h.Start ? r.linkTrack("agent-video", {
1037
1037
  event: "start",
1038
1038
  latency: N.get(!0),
@@ -1042,28 +1042,28 @@ function Dt(e, t, a, r, s) {
1042
1042
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1043
1043
  background: t.presenter.type === "clip" && t.presenter.background,
1044
1044
  "stream-type": s,
1045
- ...a
1045
+ ...n
1046
1046
  }, "done", [A.StreamVideoDone]));
1047
1047
  }
1048
- function Ct(e, t, a) {
1048
+ function Ct(e, t, n) {
1049
1049
  return N.reset(), new Promise(async (r, s) => {
1050
1050
  try {
1051
1051
  const o = await wt(e.id, pt(t), {
1052
1052
  ...t,
1053
- analytics: a,
1053
+ analytics: n,
1054
1054
  callbacks: {
1055
1055
  ...t.callbacks,
1056
1056
  onConnectionStateChange: (c) => {
1057
- var n, i;
1058
- (i = (n = t.callbacks).onConnectionStateChange) == null || i.call(n, c), c === S.Connected && r(o);
1057
+ var a, i;
1058
+ (i = (a = t.callbacks).onConnectionStateChange) == null || i.call(a, c), c === I.Connected && r(o);
1059
1059
  },
1060
- onVideoStateChange: (c, n) => {
1061
- var i, l;
1062
- (l = (i = t.callbacks).onVideoStateChange) == null || l.call(i, c), yt(c, e, n, a, o.streamType);
1060
+ onVideoStateChange: (c, a) => {
1061
+ var i, d;
1062
+ (d = (i = t.callbacks).onVideoStateChange) == null || d.call(i, c), yt(c, e, a, n, o.streamType);
1063
1063
  },
1064
1064
  onAgentActivityStateChange: (c) => {
1065
- var n, i;
1066
- (i = (n = t.callbacks).onAgentActivityStateChange) == null || i.call(n, c), c === O.Talking ? re.update() : re.reset(), kt(c === O.Talking ? h.Start : h.Stop, e, a, o.streamType);
1065
+ var a, i;
1066
+ (i = (a = t.callbacks).onAgentActivityStateChange) == null || i.call(a, c), c === O.Talking ? re.update() : re.reset(), kt(c === O.Talking ? h.Start : h.Stop, e, n, o.streamType);
1067
1067
  }
1068
1068
  }
1069
1069
  });
@@ -1072,25 +1072,25 @@ function Ct(e, t, a) {
1072
1072
  }
1073
1073
  });
1074
1074
  }
1075
- async function Rt(e, t, a, r, s) {
1076
- var y, T, j, b;
1077
- const o = we(e, a, r, t.mode, t.persistentChat, s), c = Ct(e, t, r), [n, i] = await Promise.all([o, c]), {
1078
- chat: l,
1079
- chatMode: d
1080
- } = n;
1081
- return d && d !== t.mode && (t.mode = d, (T = (y = t.callbacks).onModeChange) == null || T.call(y, d), d !== _.Functional) ? ((b = (j = t.callbacks).onError) == null || b.call(j, new De(d)), i == null || i.disconnect(), {
1082
- chat: l
1075
+ async function Rt(e, t, n, r, s) {
1076
+ var y, _, T, j;
1077
+ const o = we(e, n, r, t.mode, t.persistentChat, s), c = Ct(e, t, r), [a, i] = await Promise.all([o, c]), {
1078
+ chat: d,
1079
+ chatMode: l
1080
+ } = a;
1081
+ return l && l !== t.mode && (t.mode = l, (_ = (y = t.callbacks).onModeChange) == null || _.call(y, l), l !== M.Functional) ? ((j = (T = t.callbacks).onError) == null || j.call(T, new De(l)), i == null || i.disconnect(), {
1082
+ chat: d
1083
1083
  }) : {
1084
- chat: l,
1084
+ chat: d,
1085
1085
  streamingManager: i
1086
1086
  };
1087
1087
  }
1088
1088
  async function Et(e, t) {
1089
1089
  var U, K, P;
1090
- let a = !0, r = null;
1091
- const s = t.mixpanelKey || $e, o = t.wsURL || Le, c = t.baseURL || Z, n = {
1090
+ let n = !0, r = null;
1091
+ const s = t.mixpanelKey || $e, o = t.wsURL || Le, c = t.baseURL || Z, a = {
1092
1092
  messages: [],
1093
- chatMode: t.mode || _.Functional
1093
+ chatMode: t.mode || M.Functional
1094
1094
  }, i = qe({
1095
1095
  token: s,
1096
1096
  agentId: e,
@@ -1100,36 +1100,36 @@ async function Et(e, t) {
1100
1100
  i.track("agent-sdk", {
1101
1101
  event: "init"
1102
1102
  });
1103
- const l = fe(t.auth, c, t.callbacks.onError), d = await l.getById(e);
1104
- i.enrich(We(d));
1103
+ const d = fe(t.auth, c, t.callbacks.onError), l = await d.getById(e);
1104
+ i.enrich(We(l));
1105
1105
  const {
1106
1106
  onMessage: y,
1107
- clearQueue: T
1108
- } = tt(i, n, t, d, () => {
1107
+ clearQueue: _
1108
+ } = tt(i, a, t, l, () => {
1109
1109
  var u;
1110
- return (u = n.socketManager) == null ? void 0 : u.disconnect();
1110
+ return (u = a.socketManager) == null ? void 0 : u.disconnect();
1111
1111
  });
1112
- n.messages = Ve(t.initialMessages), (K = (U = t.callbacks).onNewMessage) == null || K.call(U, [...n.messages], "answer");
1113
- const j = (u) => {
1112
+ a.messages = Ve(t.initialMessages), (K = (U = t.callbacks).onNewMessage) == null || K.call(U, [...a.messages], "answer");
1113
+ const T = (u) => {
1114
1114
  r = u;
1115
1115
  };
1116
1116
  i.track("agent-sdk", {
1117
1117
  event: "loaded",
1118
- ...Je(d)
1118
+ ...Je(l)
1119
1119
  });
1120
- async function b(u) {
1121
- var E, L, $, k, M, C, z;
1122
- (L = (E = t.callbacks).onConnectionStateChange) == null || L.call(E, S.Connecting), N.reset(), u && !a && (delete n.chat, (k = ($ = t.callbacks).onNewMessage) == null || k.call($, [...n.messages], "answer"));
1123
- const w = t.mode === _.DirectPlayback ? Promise.resolve(void 0) : Ze(t.auth, o, {
1120
+ async function j(u) {
1121
+ var b, L, $, k, E, C, z;
1122
+ (L = (b = t.callbacks).onConnectionStateChange) == null || L.call(b, I.Connecting), N.reset(), u && !n && (delete a.chat, (k = ($ = t.callbacks).onNewMessage) == null || k.call($, [...a.messages], "answer"));
1123
+ const v = t.mode === M.DirectPlayback ? Promise.resolve(void 0) : Ze(t.auth, o, {
1124
1124
  onMessage: y,
1125
1125
  onError: t.callbacks.onError
1126
- }), m = te(() => Rt(d, {
1126
+ }), m = te(() => Rt(l, {
1127
1127
  ...t,
1128
1128
  callbacks: {
1129
1129
  ...t.callbacks,
1130
- onVideoIdChange: j
1130
+ onVideoIdChange: T
1131
1131
  }
1132
- }, l, i, n.chat), {
1132
+ }, d, i, a.chat), {
1133
1133
  limit: 3,
1134
1134
  timeout: Ae,
1135
1135
  timeoutErrorMessage: "Timeout initializing the stream",
@@ -1138,286 +1138,253 @@ async function Et(e, t) {
1138
1138
  delayMs: 1e3
1139
1139
  }).catch((F) => {
1140
1140
  var J, f;
1141
- throw R(_.Maintenance), (f = (J = t.callbacks).onConnectionStateChange) == null || f.call(J, S.Fail), F;
1141
+ throw R(M.Maintenance), (f = (J = t.callbacks).onConnectionStateChange) == null || f.call(J, I.Fail), F;
1142
1142
  }), [D, {
1143
- streamingManager: v,
1143
+ streamingManager: w,
1144
1144
  chat: p
1145
- }] = await Promise.all([w, m]);
1146
- p && p.id !== ((M = n.chat) == null ? void 0 : M.id) && ((z = (C = t.callbacks).onNewChat) == null || z.call(C, p.id)), n.streamingManager = v, n.socketManager = D, n.chat = p, a = !1, R((p == null ? void 0 : p.chat_mode) ?? t.mode ?? _.Functional);
1145
+ }] = await Promise.all([v, m]);
1146
+ p && p.id !== ((E = a.chat) == null ? void 0 : E.id) && ((z = (C = t.callbacks).onNewChat) == null || z.call(C, p.id)), a.streamingManager = w, a.socketManager = D, a.chat = p, n = !1, i.enrich({
1147
+ chatId: p == null ? void 0 : p.id,
1148
+ streamId: w == null ? void 0 : w.streamId,
1149
+ mode: a.chatMode
1150
+ }), R((p == null ? void 0 : p.chat_mode) ?? t.mode ?? M.Functional);
1147
1151
  }
1148
1152
  async function x() {
1149
- var u, w, m, D;
1150
- (u = n.socketManager) == null || u.disconnect(), await ((w = n.streamingManager) == null ? void 0 : w.disconnect()), delete n.streamingManager, delete n.socketManager, (D = (m = t.callbacks).onConnectionStateChange) == null || D.call(m, S.Disconnected);
1153
+ var u, v, m, D;
1154
+ (u = a.socketManager) == null || u.disconnect(), await ((v = a.streamingManager) == null ? void 0 : v.disconnect()), delete a.streamingManager, delete a.socketManager, (D = (m = t.callbacks).onConnectionStateChange) == null || D.call(m, I.Disconnected);
1151
1155
  }
1152
1156
  async function R(u) {
1153
- var w, m;
1154
- u !== n.chatMode && (i.track("agent-mode-change", {
1157
+ var v, m;
1158
+ u !== a.chatMode && (i.track("agent-mode-change", {
1155
1159
  mode: u
1156
- }), n.chatMode = u, n.chatMode !== _.Functional && await x(), (m = (w = t.callbacks).onModeChange) == null || m.call(w, u));
1160
+ }), a.chatMode = u, a.chatMode !== M.Functional && await x(), (m = (v = t.callbacks).onModeChange) == null || m.call(v, u));
1157
1161
  }
1158
1162
  return {
1159
- agent: d,
1163
+ agent: l,
1160
1164
  getStreamType: () => {
1161
1165
  var u;
1162
- return (u = n.streamingManager) == null ? void 0 : u.streamType;
1166
+ return (u = a.streamingManager) == null ? void 0 : u.streamType;
1163
1167
  },
1164
1168
  getIsInterruptAvailable: () => {
1165
1169
  var u;
1166
- return ((u = n.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
1170
+ return ((u = a.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
1167
1171
  },
1168
- starterMessages: ((P = d.knowledge) == null ? void 0 : P.starter_message) || [],
1169
- getSTTToken: () => l.getSTTToken(d.id),
1172
+ starterMessages: ((P = l.knowledge) == null ? void 0 : P.starter_message) || [],
1173
+ getSTTToken: () => d.getSTTToken(l.id),
1170
1174
  changeMode: R,
1171
1175
  enrichAnalytics: i.enrich,
1172
1176
  async connect() {
1173
- var u;
1174
- await b(!0), i.track("agent-chat", {
1177
+ await j(!0), i.track("agent-chat", {
1175
1178
  event: "connect",
1176
- chatId: (u = n.chat) == null ? void 0 : u.id,
1177
- agentId: d.id,
1178
- mode: n.chatMode,
1179
- access: d.access,
1180
- name: d.preview_name,
1181
- ...d.access === "public" ? {
1182
- from: "agent-template"
1183
- } : {}
1179
+ mode: a.chatMode
1184
1180
  });
1185
1181
  },
1186
1182
  async reconnect() {
1187
- var u;
1188
- await x(), await b(!1), i.track("agent-chat", {
1183
+ await x(), await j(!1), i.track("agent-chat", {
1189
1184
  event: "reconnect",
1190
- chatId: (u = n.chat) == null ? void 0 : u.id,
1191
- agentId: d.id,
1192
- mode: n.chatMode,
1193
- access: d.access,
1194
- name: d.preview_name,
1195
- ...d.access === "public" ? {
1196
- from: "agent-template"
1197
- } : {}
1185
+ mode: a.chatMode
1198
1186
  });
1199
1187
  },
1200
1188
  async disconnect() {
1201
- var u;
1202
1189
  await x(), i.track("agent-chat", {
1203
1190
  event: "disconnect",
1204
- chatId: (u = n.chat) == null ? void 0 : u.id,
1205
- agentId: d.id,
1206
- mode: n.chatMode,
1207
- access: d.access,
1208
- name: d.preview_name,
1209
- ...d.access === "public" ? {
1210
- from: "agent-template"
1211
- } : {}
1191
+ mode: a.chatMode
1212
1192
  });
1213
1193
  },
1214
1194
  async chat(u) {
1215
- var v, p, E, L, $;
1216
- const w = () => {
1195
+ var w, p, b, L, $;
1196
+ const v = () => {
1217
1197
  if (ce(t.mode))
1218
1198
  throw new H(`${t.mode} is enabled, chat is disabled`);
1219
1199
  if (u.length >= 800)
1220
1200
  throw new H("Message cannot be more than 800 characters");
1221
1201
  if (u.length === 0)
1222
1202
  throw new H("Message cannot be empty");
1223
- if (n.chatMode === _.Maintenance)
1203
+ if (a.chatMode === M.Maintenance)
1224
1204
  throw new H("Chat is in maintenance mode");
1225
- if (![_.TextOnly, _.Playground].includes(n.chatMode)) {
1226
- if (!n.streamingManager)
1205
+ if (![M.TextOnly, M.Playground].includes(a.chatMode)) {
1206
+ if (!a.streamingManager)
1227
1207
  throw new H("Streaming manager is not initialized");
1228
- if (!n.chat)
1208
+ if (!a.chat)
1229
1209
  throw new H("Chat is not initialized");
1230
1210
  }
1231
1211
  }, m = async () => {
1232
- var k, M;
1233
- if (!n.chat) {
1234
- const C = await we(d, l, i, n.chatMode, t.persistentChat);
1212
+ var k, E;
1213
+ if (!a.chat) {
1214
+ const C = await we(l, d, i, a.chatMode, t.persistentChat);
1235
1215
  if (!C.chat)
1236
- throw new ke(n.chatMode, !!t.persistentChat);
1237
- n.chat = C.chat, (M = (k = t.callbacks).onNewChat) == null || M.call(k, n.chat.id);
1216
+ throw new ke(a.chatMode, !!t.persistentChat);
1217
+ a.chat = C.chat, (E = (k = t.callbacks).onNewChat) == null || E.call(k, a.chat.id);
1238
1218
  }
1239
- return n.chat.id;
1240
- }, D = async (k, M) => te(() => {
1219
+ return a.chat.id;
1220
+ }, D = async (k, E) => te(() => {
1241
1221
  var C, z;
1242
- return l.chat(d.id, M, {
1243
- chatMode: n.chatMode,
1244
- streamId: (C = n.streamingManager) == null ? void 0 : C.streamId,
1245
- sessionId: (z = n.streamingManager) == null ? void 0 : z.sessionId,
1222
+ return d.chat(l.id, E, {
1223
+ chatMode: a.chatMode,
1224
+ streamId: (C = a.streamingManager) == null ? void 0 : C.streamId,
1225
+ sessionId: (z = a.streamingManager) == null ? void 0 : z.sessionId,
1246
1226
  messages: k.map(({
1247
1227
  matches: F,
1248
1228
  ...J
1249
1229
  }) => J)
1250
1230
  }, {
1251
- ...he(n.chatMode),
1231
+ ...he(a.chatMode),
1252
1232
  skipErrorHandler: !0
1253
1233
  });
1254
1234
  }, {
1255
1235
  limit: 2,
1256
1236
  shouldRetryFn: (C) => {
1257
- var J, f, g, I;
1237
+ var J, f, g, S;
1258
1238
  const z = (J = C == null ? void 0 : C.message) == null ? void 0 : J.includes("missing or invalid session_id");
1259
- return !((f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("Stream Error")) && !z ? ((I = (g = t.callbacks).onError) == null || I.call(g, C), !1) : !0;
1239
+ return !((f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("Stream Error")) && !z ? ((S = (g = t.callbacks).onError) == null || S.call(g, C), !1) : !0;
1260
1240
  },
1261
1241
  onRetry: async () => {
1262
- await x(), await b(!1);
1242
+ await x(), await j(!1);
1263
1243
  }
1264
1244
  });
1265
1245
  try {
1266
- T(), w(), n.messages.push({
1246
+ _(), v(), a.messages.push({
1267
1247
  id: V(),
1268
1248
  role: "user",
1269
1249
  content: u,
1270
1250
  created_at: new Date(N.update()).toISOString()
1271
- }), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...n.messages], "user");
1272
- const k = await m(), M = await D([...n.messages], k);
1273
- return n.messages.push({
1251
+ }), (p = (w = t.callbacks).onNewMessage) == null || p.call(w, [...a.messages], "user");
1252
+ const k = await m(), E = await D([...a.messages], k);
1253
+ return a.messages.push({
1274
1254
  id: V(),
1275
1255
  role: "assistant",
1276
- content: M.result || "",
1256
+ content: E.result || "",
1277
1257
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1278
- context: M.context,
1279
- matches: M.matches
1258
+ context: E.context,
1259
+ matches: E.matches
1280
1260
  }), i.track("agent-message-send", {
1281
1261
  event: "success",
1282
- mode: n.chatMode,
1283
- messages: n.messages.length + 1
1284
- }), M.result && ((L = (E = t.callbacks).onNewMessage) == null || L.call(E, [...n.messages], "answer"), i.track("agent-message-received", {
1262
+ messages: a.messages.length + 1
1263
+ }), E.result && ((L = (b = t.callbacks).onNewMessage) == null || L.call(b, [...a.messages], "answer"), i.track("agent-message-received", {
1285
1264
  latency: N.get(!0),
1286
- mode: n.chatMode,
1287
- messages: n.messages.length
1288
- })), M;
1265
+ messages: a.messages.length
1266
+ })), E;
1289
1267
  } catch (k) {
1290
- throw (($ = n.messages[n.messages.length - 1]) == null ? void 0 : $.role) === "assistant" && n.messages.pop(), i.track("agent-message-send", {
1268
+ throw (($ = a.messages[a.messages.length - 1]) == null ? void 0 : $.role) === "assistant" && a.messages.pop(), i.track("agent-message-send", {
1291
1269
  event: "error",
1292
- mode: n.chatMode,
1293
- messages: n.messages.length
1270
+ messages: a.messages.length
1294
1271
  }), k;
1295
1272
  }
1296
1273
  },
1297
- rate(u, w, m) {
1298
- var p, E, L, $;
1299
- const D = n.messages.find((k) => k.id === u);
1300
- if (n.chat) {
1274
+ rate(u, v, m) {
1275
+ var p, b, L, $;
1276
+ const D = a.messages.find((k) => k.id === u);
1277
+ if (a.chat) {
1301
1278
  if (!D)
1302
1279
  throw new Error("Message not found");
1303
1280
  } else
1304
1281
  throw new Error("Chat is not initialized");
1305
- const v = ((p = D.matches) == null ? void 0 : p.map((k) => [k.document_id, k.id])) ?? [];
1282
+ const w = ((p = D.matches) == null ? void 0 : p.map((k) => [k.document_id, k.id])) ?? [];
1306
1283
  return i.track("agent-rate", {
1307
1284
  event: m ? "update" : "create",
1308
- thumb: w === 1 ? "up" : "down",
1309
- knowledge_id: ((E = d.knowledge) == null ? void 0 : E.id) ?? "",
1310
- mode: n.chatMode,
1311
- matches: v,
1312
- score: w
1313
- }), m ? l.updateRating(d.id, n.chat.id, m, {
1314
- knowledge_id: ((L = d.knowledge) == null ? void 0 : L.id) ?? "",
1285
+ thumb: v === 1 ? "up" : "down",
1286
+ knowledge_id: ((b = l.knowledge) == null ? void 0 : b.id) ?? "",
1287
+ matches: w,
1288
+ score: v
1289
+ }), m ? d.updateRating(l.id, a.chat.id, m, {
1290
+ knowledge_id: ((L = l.knowledge) == null ? void 0 : L.id) ?? "",
1315
1291
  message_id: u,
1316
- matches: v,
1317
- score: w
1318
- }) : l.createRating(d.id, n.chat.id, {
1319
- knowledge_id: (($ = d.knowledge) == null ? void 0 : $.id) ?? "",
1292
+ matches: w,
1293
+ score: v
1294
+ }) : d.createRating(l.id, a.chat.id, {
1295
+ knowledge_id: (($ = l.knowledge) == null ? void 0 : $.id) ?? "",
1320
1296
  message_id: u,
1321
- matches: v,
1322
- score: w
1297
+ matches: w,
1298
+ score: v
1323
1299
  });
1324
1300
  },
1325
1301
  deleteRate(u) {
1326
- var w;
1327
- if (!n.chat)
1302
+ if (!a.chat)
1328
1303
  throw new Error("Chat is not initialized");
1329
1304
  return i.track("agent-rate-delete", {
1330
- type: "text",
1331
- chat_id: (w = n.chat) == null ? void 0 : w.id,
1332
- id: u,
1333
- mode: n.chatMode
1334
- }), l.deleteRating(d.id, n.chat.id, u);
1305
+ type: "text"
1306
+ }), d.deleteRating(l.id, a.chat.id, u);
1335
1307
  },
1336
1308
  async speak(u) {
1337
- var v, p, E;
1338
- function w() {
1309
+ var w, p, b;
1310
+ function v() {
1339
1311
  if (typeof u == "string") {
1340
- if (!d.presenter.voice)
1312
+ if (!l.presenter.voice)
1341
1313
  throw new Error("Presenter voice is not initialized");
1342
1314
  return {
1343
1315
  type: "text",
1344
- provider: d.presenter.voice,
1316
+ provider: l.presenter.voice,
1345
1317
  input: u,
1346
1318
  ssml: !1
1347
1319
  };
1348
1320
  }
1349
1321
  if (u.type === "text" && !u.provider) {
1350
- if (!d.presenter.voice)
1322
+ if (!l.presenter.voice)
1351
1323
  throw new Error("Presenter voice is not initialized");
1352
1324
  return {
1353
1325
  type: "text",
1354
- provider: d.presenter.voice,
1326
+ provider: l.presenter.voice,
1355
1327
  input: u.input,
1356
1328
  ssml: u.ssml
1357
1329
  };
1358
1330
  }
1359
1331
  return u;
1360
1332
  }
1361
- const m = w();
1362
- if (i.track("agent-speak", m), N.update(), n.messages && m.type === "text" && (n.messages.push({
1333
+ const m = v();
1334
+ if (i.track("agent-speak", m), N.update(), a.messages && m.type === "text" && (a.messages.push({
1363
1335
  id: V(),
1364
1336
  role: "assistant",
1365
1337
  content: m.input,
1366
1338
  created_at: new Date(N.get(!0)).toISOString()
1367
- }), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...n.messages], "answer")), ze(n.chatMode))
1339
+ }), (p = (w = t.callbacks).onNewMessage) == null || p.call(w, [...a.messages], "answer")), ze(a.chatMode))
1368
1340
  return {
1369
1341
  duration: 0,
1370
1342
  video_id: "",
1371
1343
  status: "success"
1372
1344
  };
1373
- if (!n.streamingManager)
1345
+ if (!a.streamingManager)
1374
1346
  throw new Error("Please connect to the agent first");
1375
- return n.streamingManager.speak({
1347
+ return a.streamingManager.speak({
1376
1348
  script: m,
1377
1349
  metadata: {
1378
- chat_id: (E = n.chat) == null ? void 0 : E.id,
1379
- agent_id: d.id
1350
+ chat_id: (b = a.chat) == null ? void 0 : b.id,
1351
+ agent_id: l.id
1380
1352
  }
1381
1353
  });
1382
1354
  },
1383
1355
  async interrupt({
1384
1356
  type: u
1385
1357
  }) {
1386
- var m, D, v, p, E;
1387
- Oe(n.streamingManager, (m = n.streamingManager) == null ? void 0 : m.streamType, r);
1388
- const w = n.messages[n.messages.length - 1];
1358
+ var m, D, w;
1359
+ Oe(a.streamingManager, (m = a.streamingManager) == null ? void 0 : m.streamType, r);
1360
+ const v = a.messages[a.messages.length - 1];
1389
1361
  i.track("agent-video-interrupt", {
1390
1362
  type: u || "click",
1391
- stream_id: (D = n.streamingManager) == null ? void 0 : D.streamId,
1392
- agent_id: d.id,
1393
- owner_id: d.owner_id,
1394
1363
  video_duration_to_interrupt: re.get(!0),
1395
- message_duration_to_interrupt: N.get(!0),
1396
- chat_id: (v = n.chat) == null ? void 0 : v.id,
1397
- mode: n.chatMode
1398
- }), w.interrupted = !0, (E = (p = t.callbacks).onNewMessage) == null || E.call(p, [...n.messages], "answer"), Xe(n.streamingManager, r);
1364
+ message_duration_to_interrupt: N.get(!0)
1365
+ }), v.interrupted = !0, (w = (D = t.callbacks).onNewMessage) == null || w.call(D, [...a.messages], "answer"), Xe(a.streamingManager, r);
1399
1366
  }
1400
1367
  };
1401
1368
  }
1402
- function Mt(e, t, a) {
1369
+ function Mt(e, t, n) {
1403
1370
  const {
1404
1371
  getById: r
1405
- } = fe(t, a || Z);
1372
+ } = fe(t, n || Z);
1406
1373
  return r(e);
1407
1374
  }
1408
1375
  export {
1409
1376
  O as AgentActivityState,
1410
- Se as AgentStatus,
1377
+ Ie as AgentStatus,
1411
1378
  ke as ChatCreationFailed,
1412
- _ as ChatMode,
1379
+ M as ChatMode,
1413
1380
  De as ChatModeDowngraded,
1414
1381
  q as ChatProgress,
1415
- S as ConnectionState,
1382
+ I as ConnectionState,
1416
1383
  Q as ConnectivityState,
1417
1384
  Te as DocumentType,
1418
1385
  _e as KnowledgeType,
1419
- Ie as PlanGroup,
1420
- be as Providers,
1386
+ Se as PlanGroup,
1387
+ Pe as Providers,
1421
1388
  Ee as RateState,
1422
1389
  A as StreamEvents,
1423
1390
  W as StreamType,
@@ -1426,9 +1393,9 @@ export {
1426
1393
  Re as UserPlan,
1427
1394
  H as ValidationError,
1428
1395
  je as VideoType,
1429
- Pe as VoiceAccess,
1396
+ be as VoiceAccess,
1430
1397
  Ce as WsError,
1431
1398
  Et as createAgentManager,
1432
1399
  Mt as getAgent,
1433
- St as mapVideoType
1400
+ It as mapVideoType
1434
1401
  };