@d-id/client-sdk 1.1.1-staging.3 → 1.1.1-staging.5

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 pe = Object.defineProperty;
2
- var ye = (e, t, n) => t in e ? pe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var Y = (e, t, n) => (ye(e, typeof t != "symbol" ? t + "" : t, n), n);
1
+ var ve = Object.defineProperty;
2
+ var ke = (e, t, n) => t in e ? ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Q = (e, t, n) => (ke(e, typeof t != "symbol" ? t + "" : t, n), n);
4
4
  class G extends Error {
5
5
  constructor({
6
6
  kind: n,
@@ -11,13 +11,13 @@ class G extends Error {
11
11
  kind: n,
12
12
  description: r
13
13
  }));
14
- Y(this, "kind");
15
- Y(this, "description");
16
- Y(this, "error");
14
+ Q(this, "kind");
15
+ Q(this, "description");
16
+ Q(this, "error");
17
17
  this.kind = n, this.description = r, this.error = o;
18
18
  }
19
19
  }
20
- class ve extends G {
20
+ class De extends G {
21
21
  constructor(t, n) {
22
22
  super({
23
23
  kind: "ChatCreationFailed",
@@ -25,7 +25,7 @@ class ve extends G {
25
25
  });
26
26
  }
27
27
  }
28
- class ke extends G {
28
+ class Ce extends G {
29
29
  constructor(t) {
30
30
  super({
31
31
  kind: "ChatModeDowngraded",
@@ -39,11 +39,11 @@ class H extends G {
39
39
  kind: "ValidationError",
40
40
  description: n
41
41
  });
42
- Y(this, "key");
42
+ Q(this, "key");
43
43
  this.key = r;
44
44
  }
45
45
  }
46
- class De extends G {
46
+ class Re extends G {
47
47
  constructor(t) {
48
48
  super({
49
49
  kind: "WSError",
@@ -51,8 +51,8 @@ class De extends G {
51
51
  });
52
52
  }
53
53
  }
54
- var Ce = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ce || {}), Re = /* @__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))(Re || {}), Ie = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ie || {}), Se = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Se || {}), M = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(M || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Ee = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ee || {}), _e = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(_e || {}), Me = /* @__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))(Me || {}), oe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(oe || {});
55
- const Te = (e) => {
54
+ var Se = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Se || {}), 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 || {}), _e = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(_e || {}), 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 || {}), Te = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Te || {}), je = /* @__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))(je || {}), ce = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ce || {});
55
+ const be = (e) => {
56
56
  switch (e) {
57
57
  case "clip":
58
58
  return "clip";
@@ -62,12 +62,12 @@ const Te = (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 || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), T = /* @__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))(T || {}), 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 || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), je = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(je || {}), be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(be || {});
66
- const Ae = 45 * 1e3, Pe = "X-Playground-Chat", Z = "https://api.d-id.com", Be = "wss://notifications.d-id.com", $e = "79f81a83a67430be2bc0fd61042b8faa", ce = (e) => new Promise((t) => setTimeout(t, e)), V = (e = 16) => {
65
+ var h = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(h || {}), O = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), j = /* @__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))(j || {}), 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 || {}), Ae = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Ae || {}), Pe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Pe || {});
66
+ const $e = 45 * 1e3, Be = "X-Playground-Chat", Z = "https://api.d-id.com", Le = "wss://notifications.d-id.com", ze = "79f81a83a67430be2bc0fd61042b8faa", de = (e) => new Promise((t) => setTimeout(t, e)), V = (e = 16) => {
67
67
  const t = new Uint8Array(e);
68
68
  return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
69
- }, Le = (e) => [M.TextOnly, M.Playground, M.Maintenance].includes(e);
70
- function ze(e, t) {
69
+ }, Ne = (e) => [M.TextOnly, M.Playground, M.Maintenance].includes(e), ue = (e) => e && [M.DirectPlayback, M.Off].includes(e);
70
+ function xe(e, t) {
71
71
  let n;
72
72
  return {
73
73
  promise: new Promise((o, i) => {
@@ -76,7 +76,7 @@ function ze(e, t) {
76
76
  clear: () => clearTimeout(n)
77
77
  };
78
78
  }
79
- async function ee(e, t) {
79
+ async function te(e, t) {
80
80
  const n = {
81
81
  limit: (t == null ? void 0 : t.limit) ?? 3,
82
82
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
@@ -94,16 +94,16 @@ async function ee(e, t) {
94
94
  const {
95
95
  promise: i,
96
96
  clear: c
97
- } = ze(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
97
+ } = xe(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
98
98
  return await Promise.race([a, i]);
99
99
  } catch (i) {
100
100
  if (r = i, !n.shouldRetryFn(i) || o >= n.limit)
101
101
  throw i;
102
- await ce(n.delayMs), n.onRetry(i);
102
+ await de(n.delayMs), n.onRetry(i);
103
103
  }
104
104
  throw r;
105
105
  }
106
- function de() {
106
+ function le() {
107
107
  let e = window.localStorage.getItem("did_external_key_id");
108
108
  if (!e) {
109
109
  let t = V();
@@ -111,38 +111,38 @@ function de() {
111
111
  }
112
112
  return e;
113
113
  }
114
- let Ne = V();
115
- function le(e) {
114
+ let Fe = V();
115
+ function fe(e) {
116
116
  if (e.type === "bearer")
117
117
  return `Bearer ${e.token}`;
118
118
  if (e.type === "basic")
119
119
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
120
120
  if (e.type === "key")
121
- return `Client-Key ${e.clientKey}.${de()}_${Ne}`;
121
+ return `Client-Key ${e.clientKey}.${le()}_${Fe}`;
122
122
  throw new Error(`Unknown auth type: ${e}`);
123
123
  }
124
- const xe = (e) => ee(e, {
124
+ const Je = (e) => te(e, {
125
125
  limit: 3,
126
126
  delayMs: 1e3,
127
127
  timeout: 0,
128
128
  shouldRetryFn: (t) => t.status === 429
129
129
  });
130
- function ne(e, t = Z, n) {
130
+ function ae(e, t = Z, n) {
131
131
  const r = async (o, i) => {
132
132
  const {
133
133
  skipErrorHandler: c,
134
134
  ...a
135
- } = i || {}, s = await xe(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
135
+ } = i || {}, s = await Je(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
136
136
  ...a,
137
137
  headers: {
138
138
  ...a.headers,
139
- Authorization: le(e),
139
+ Authorization: fe(e),
140
140
  "Content-Type": "application/json"
141
141
  }
142
142
  }));
143
143
  if (!s.ok) {
144
- let l = await s.text().catch(() => `Failed to fetch with status ${s.status}`);
145
- const d = new Error(l);
144
+ let u = await s.text().catch(() => `Failed to fetch with status ${s.status}`);
145
+ const d = new Error(u);
146
146
  throw n && !c && n(d, {
147
147
  url: o,
148
148
  options: a,
@@ -181,8 +181,8 @@ function ne(e, t = Z, n) {
181
181
  }
182
182
  };
183
183
  }
184
- function ue(e, t = Z, n) {
185
- const r = ne(e, `${t}/agents`, n);
184
+ function me(e, t = Z, n) {
185
+ const r = ae(e, `${t}/agents`, n);
186
186
  return {
187
187
  create(o, i) {
188
188
  return r.post("/", o, i);
@@ -219,8 +219,8 @@ function ue(e, t = Z, n) {
219
219
  }
220
220
  };
221
221
  }
222
- const fe = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
223
- function Fe(e) {
222
+ const ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
223
+ function We(e) {
224
224
  var o, i, c, a;
225
225
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
226
226
  const s = navigator.platform;
@@ -231,18 +231,18 @@ function Fe(e) {
231
231
  isMobile: `${t() == "Mobile"}`,
232
232
  browser: navigator.userAgent,
233
233
  origin: window.location.origin,
234
- agentType: fe(r),
234
+ agentType: ge(r),
235
235
  agentVoice: {
236
236
  voiceId: (i = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : i.voice_id,
237
237
  provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
238
238
  }
239
239
  };
240
240
  }
241
- function Je(e) {
241
+ function Ue(e) {
242
242
  var n, r, o, i, c, a;
243
243
  const t = (n = e.llm) == null ? void 0 : n.prompt_customization;
244
244
  return {
245
- agentType: fe(e.presenter),
245
+ agentType: ge(e.presenter),
246
246
  owner_id: e.owner_id ?? "",
247
247
  promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
248
248
  behavior: {
@@ -257,9 +257,9 @@ function Je(e) {
257
257
  maxResponseLength: t == null ? void 0 : t.max_response_length
258
258
  };
259
259
  }
260
- const We = (e) => e.reduce((t, n) => t + n, 0), ae = (e) => We(e) / e.length;
261
- function Ue(e, t, n) {
262
- var s, l, d;
260
+ const Ke = (e) => e.reduce((t, n) => t + n, 0), ie = (e) => Ke(e) / e.length;
261
+ function He(e, t, n) {
262
+ var s, u, d;
263
263
  const {
264
264
  event: r,
265
265
  ...o
@@ -277,7 +277,7 @@ function Ue(e, t, n) {
277
277
  script: {
278
278
  ...o.script,
279
279
  provider: {
280
- ...(l = o == null ? void 0 : o.script) == null ? void 0 : l.provider,
280
+ ...(u = o == null ? void 0 : o.script) == null ? void 0 : u.provider,
281
281
  language: c
282
282
  }
283
283
  },
@@ -285,13 +285,13 @@ function Ue(e, t, n) {
285
285
  ...n
286
286
  };
287
287
  }
288
- let O = {};
289
- const Ke = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
290
- function He(e) {
288
+ let ee = {};
289
+ const qe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
290
+ function Ve(e) {
291
291
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
292
292
  return {
293
293
  token: e.token || "testKey",
294
- distinct_id: e.distinctId || de(),
294
+ distinct_id: e.distinctId || le(),
295
295
  agentId: e.agentId,
296
296
  additionalProperties: {},
297
297
  isEnabled: e.isEnabled ?? !0,
@@ -332,32 +332,32 @@ function He(e) {
332
332
  })
333
333
  };
334
334
  try {
335
- return await fetch(Ke, c).then((a) => a.json());
335
+ return await fetch(qe, c).then((a) => a.json());
336
336
  } catch (a) {
337
337
  return console.error(a);
338
338
  }
339
339
  },
340
340
  linkTrack(n, r, o, i) {
341
- O[n] || (O[n] = {
341
+ ee[n] || (ee[n] = {
342
342
  events: {},
343
343
  resolvedDependencies: []
344
344
  }), i.includes(o) || i.push(o);
345
- const c = O[n];
345
+ const c = ee[n];
346
346
  if (c.events[o] = {
347
347
  props: r
348
348
  }, c.resolvedDependencies.push(o), i.every((s) => c.resolvedDependencies.includes(s))) {
349
- const s = i.reduce((l, d) => c.events[d] ? {
350
- ...l,
349
+ const s = i.reduce((u, d) => c.events[d] ? {
350
+ ...u,
351
351
  ...c.events[d].props
352
- } : l, {});
353
- this.track(n, s), c.resolvedDependencies = c.resolvedDependencies.filter((l) => !i.includes(l)), i.forEach((l) => {
354
- delete c.events[l];
352
+ } : u, {});
353
+ this.track(n, s), c.resolvedDependencies = c.resolvedDependencies.filter((u) => !i.includes(u)), i.forEach((u) => {
354
+ delete c.events[u];
355
355
  });
356
356
  }
357
357
  }
358
358
  };
359
359
  }
360
- function me() {
360
+ function he() {
361
361
  let e = 0;
362
362
  return {
363
363
  reset: () => e = 0,
@@ -365,19 +365,19 @@ function me() {
365
365
  get: (t = !1) => t ? Date.now() - e : e
366
366
  };
367
367
  }
368
- const N = me(), te = me();
369
- function ge(e) {
368
+ const N = he(), re = he();
369
+ function we(e) {
370
370
  return e === M.Playground ? {
371
371
  headers: {
372
- [Pe]: "true"
372
+ [Be]: "true"
373
373
  }
374
374
  } : {};
375
375
  }
376
- async function he(e, t, n, r, o = !1, i) {
376
+ async function pe(e, t, n, r, o = !1, i) {
377
377
  try {
378
- return !i && r !== M.DirectPlayback && (i = await t.newChat(e.id, {
378
+ return !i && !ue(r) && (i = await t.newChat(e.id, {
379
379
  persist: o
380
- }, ge(r)), n.track("agent-chat", {
380
+ }, we(r)), n.track("agent-chat", {
381
381
  event: "created",
382
382
  chat_id: i.id,
383
383
  agent_id: e.id,
@@ -397,28 +397,28 @@ async function he(e, t, n, r, o = !1, i) {
397
397
  throw new Error("Cannot create new chat");
398
398
  }
399
399
  }
400
- function qe(e) {
400
+ function Xe(e) {
401
401
  return e && e.length > 0 ? e : [];
402
402
  }
403
- function Ve(e, t, n) {
403
+ function Ye(e, t, n) {
404
404
  if (!e)
405
405
  throw new Error("Please connect to the agent first");
406
406
  if (!e.interruptAvailable)
407
407
  throw new Error("Interrupt is not enabled for this stream");
408
- if (t !== J.Fluent)
408
+ if (t !== W.Fluent)
409
409
  throw new Error("Interrupt only available for Fluent streams");
410
410
  if (!n)
411
411
  throw new Error("No active video to interrupt");
412
412
  }
413
- async function Xe(e, t) {
413
+ async function Qe(e, t) {
414
414
  const n = {
415
- type: T.StreamInterrupt,
415
+ type: j.StreamInterrupt,
416
416
  videoId: t,
417
417
  timestamp: Date.now()
418
418
  };
419
419
  e.sendDataChannelMessage(JSON.stringify(n));
420
420
  }
421
- function Ye(e) {
421
+ function Oe(e) {
422
422
  return new Promise((t, n) => {
423
423
  const {
424
424
  callbacks: r,
@@ -428,38 +428,38 @@ function Ye(e) {
428
428
  onMessage: c = null,
429
429
  onOpen: a = null,
430
430
  onClose: s = null,
431
- onError: l = null
432
- } = r || {}, d = new WebSocket(`${o}?authorization=${le(i)}`);
431
+ onError: u = null
432
+ } = r || {}, d = new WebSocket(`${o}?authorization=${fe(i)}`);
433
433
  d.onmessage = c, d.onclose = s, d.onerror = (y) => {
434
- console.error(y), l == null || l("Websocket failed to connect", y), n(y);
434
+ console.error(y), u == null || u("Websocket failed to connect", y), n(y);
435
435
  }, d.onopen = (y) => {
436
436
  a == null || a(y), t(d);
437
437
  };
438
438
  });
439
439
  }
440
- async function Qe(e) {
440
+ async function Ze(e) {
441
441
  const {
442
442
  retries: t = 1
443
443
  } = e;
444
444
  let n = null;
445
445
  for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
446
446
  try {
447
- n = await Ye(e);
447
+ n = await Oe(e);
448
448
  } catch (o) {
449
449
  if (r === t)
450
450
  throw o;
451
- await ce(r * 500);
451
+ await de(r * 500);
452
452
  }
453
453
  return n;
454
454
  }
455
- async function Ze(e, t, n) {
456
- const r = n != null && n.onMessage ? [n.onMessage] : [], o = await Qe({
455
+ async function Ge(e, t, n) {
456
+ const r = n != null && n.onMessage ? [n.onMessage] : [], o = await Ze({
457
457
  auth: e,
458
458
  host: t,
459
459
  callbacks: {
460
460
  onError: (i) => {
461
461
  var c;
462
- return (c = n.onError) == null ? void 0 : c.call(n, new De(i));
462
+ return (c = n.onError) == null ? void 0 : c.call(n, new Re(i));
463
463
  },
464
464
  onMessage(i) {
465
465
  const c = JSON.parse(i.data);
@@ -473,7 +473,7 @@ async function Ze(e, t, n) {
473
473
  subscribeToEvents: (i) => r.push(i)
474
474
  };
475
475
  }
476
- function Ge(e) {
476
+ function et(e) {
477
477
  if (e.answer !== void 0)
478
478
  return e.answer;
479
479
  let t = 0, n = "";
@@ -481,7 +481,7 @@ function Ge(e) {
481
481
  n += e[t++];
482
482
  return n;
483
483
  }
484
- function Oe(e, t, n, r, o) {
484
+ function tt(e, t, n, r, o) {
485
485
  const i = r.messages[r.messages.length - 1];
486
486
  if (!(e === q.Partial || e === q.Answer) || (i == null ? void 0 : i.role) !== "assistant")
487
487
  return;
@@ -490,22 +490,22 @@ function Oe(e, t, n, r, o) {
490
490
  sequence: a
491
491
  } = t;
492
492
  e === q.Partial ? n[a] = c : n.answer = c;
493
- const s = Ge(n);
493
+ const s = et(n);
494
494
  (i.content !== s || e === q.Answer) && (i.content = s, o == null || o([...r.messages], e));
495
495
  }
496
- function et(e, t, n, r, o) {
496
+ function rt(e, t, n, r, o) {
497
497
  let i = {};
498
498
  return {
499
499
  clearQueue: () => i = {},
500
500
  onMessage: (c, a) => {
501
- var s, l;
501
+ var s, u;
502
502
  if ("content" in a)
503
- Oe(c, a, i, t, n.callbacks.onNewMessage), c === q.Answer && e.track("agent-message-received", {
503
+ tt(c, a, i, t, n.callbacks.onNewMessage), c === q.Answer && e.track("agent-message-received", {
504
504
  messages: t.messages.length,
505
505
  mode: t.chatMode
506
506
  });
507
507
  else {
508
- const d = T, y = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], A = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], P = Ue(a, r, {
508
+ const d = j, y = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], A = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], P = He(a, r, {
509
509
  mode: t.chatMode
510
510
  });
511
511
  if (c = c, c === d.StreamVideoCreated)
@@ -520,15 +520,15 @@ function et(e, t, n, r, o) {
520
520
  event: x
521
521
  }, c, ["done"]);
522
522
  }
523
- A.includes(c) && ((l = (s = n.callbacks).onError) == null || l.call(s, new Error(`Stream failed with event ${c}`), {
523
+ A.includes(c) && ((u = (s = n.callbacks).onError) == null || u.call(s, new Error(`Stream failed with event ${c}`), {
524
524
  data: a
525
525
  })), a.event === d.StreamDone && o();
526
526
  }
527
527
  }
528
528
  };
529
529
  }
530
- function tt(e, t, n, r) {
531
- const o = ne(e, `${t}/agents/${n}`, r);
530
+ function nt(e, t, n, r) {
531
+ const o = ae(e, `${t}/agents/${n}`, r);
532
532
  return {
533
533
  createStream(i) {
534
534
  return o.post("/streams", {
@@ -564,8 +564,8 @@ function tt(e, t, n, r) {
564
564
  }
565
565
  };
566
566
  }
567
- function rt(e, t, n, r) {
568
- const o = ne(e, `${t}/agents/${n}`, r);
567
+ function at(e, t, n, r) {
568
+ const o = ae(e, `${t}/agents/${n}`, r);
569
569
  return {
570
570
  createStream(i, c) {
571
571
  return o.post("/streams", {
@@ -604,7 +604,7 @@ function rt(e, t, n, r) {
604
604
  }
605
605
  };
606
606
  }
607
- function nt(e, t, n) {
607
+ function it(e, t, n) {
608
608
  const r = (t.timestamp - e.timestamp) / 1e3;
609
609
  return {
610
610
  duration: r,
@@ -624,7 +624,7 @@ function nt(e, t, n) {
624
624
  lowFpsCount: n
625
625
  };
626
626
  }
627
- function at(e) {
627
+ function st(e) {
628
628
  return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
629
629
  const {
630
630
  timestamp: n,
@@ -636,7 +636,7 @@ function at(e) {
636
636
  };
637
637
  });
638
638
  }
639
- function it(e) {
639
+ function ot(e) {
640
640
  let t = "", n = 0;
641
641
  for (const r of e.values())
642
642
  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")
@@ -661,8 +661,8 @@ function it(e) {
661
661
  };
662
662
  return {};
663
663
  }
664
- function st(e, t, n) {
665
- const r = e.map((s, l) => l === 0 ? n ? {
664
+ function ct(e, t, n) {
665
+ const r = e.map((s, u) => u === 0 ? n ? {
666
666
  timestamp: s.timestamp,
667
667
  duration: 0,
668
668
  rtt: s.rtt,
@@ -698,39 +698,39 @@ function st(e, t, n) {
698
698
  freezeDuration: s.freezeDuration
699
699
  } : {
700
700
  timestamp: s.timestamp,
701
- duration: t * l / 1e3,
701
+ duration: t * u / 1e3,
702
702
  rtt: s.rtt,
703
- bytesReceived: s.bytesReceived - e[l - 1].bytesReceived,
704
- bitrate: (s.bytesReceived - e[l - 1].bytesReceived) * 8 / (t / 1e3),
705
- packetsReceived: s.packetsReceived - e[l - 1].packetsReceived,
706
- packetsLost: s.packetsLost - e[l - 1].packetsLost,
707
- framesDropped: s.framesDropped - e[l - 1].framesDropped,
708
- framesDecoded: s.framesDecoded - e[l - 1].framesDecoded,
703
+ bytesReceived: s.bytesReceived - e[u - 1].bytesReceived,
704
+ bitrate: (s.bytesReceived - e[u - 1].bytesReceived) * 8 / (t / 1e3),
705
+ packetsReceived: s.packetsReceived - e[u - 1].packetsReceived,
706
+ packetsLost: s.packetsLost - e[u - 1].packetsLost,
707
+ framesDropped: s.framesDropped - e[u - 1].framesDropped,
708
+ framesDecoded: s.framesDecoded - e[u - 1].framesDecoded,
709
709
  jitter: s.jitter,
710
- jitterBufferDelay: s.jitterBufferDelay - e[l - 1].jitterBufferDelay,
711
- jitterBufferEmittedCount: s.jitterBufferEmittedCount - e[l - 1].jitterBufferEmittedCount,
712
- avgJitterDelayInInterval: (s.jitterBufferDelay - e[l - 1].jitterBufferDelay) / (s.jitterBufferEmittedCount - e[l - 1].jitterBufferEmittedCount),
710
+ jitterBufferDelay: s.jitterBufferDelay - e[u - 1].jitterBufferDelay,
711
+ jitterBufferEmittedCount: s.jitterBufferEmittedCount - e[u - 1].jitterBufferEmittedCount,
712
+ avgJitterDelayInInterval: (s.jitterBufferDelay - e[u - 1].jitterBufferDelay) / (s.jitterBufferEmittedCount - e[u - 1].jitterBufferEmittedCount),
713
713
  framesPerSecond: s.framesPerSecond,
714
- freezeCount: s.freezeCount - e[l - 1].freezeCount,
715
- freezeDuration: s.freezeDuration - e[l - 1].freezeDuration
716
- }), o = at(r), i = o.reduce((s, l) => s + (l.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), a = r.filter((s) => !!s.rtt).map((s) => s.rtt);
714
+ freezeCount: s.freezeCount - e[u - 1].freezeCount,
715
+ freezeDuration: s.freezeDuration - e[u - 1].freezeDuration
716
+ }), o = st(r), i = o.reduce((s, u) => s + (u.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), a = r.filter((s) => !!s.rtt).map((s) => s.rtt);
717
717
  return {
718
718
  webRTCStats: {
719
719
  anomalies: o,
720
720
  minRtt: Math.min(...a),
721
- avgRtt: ae(a),
721
+ avgRtt: ie(a),
722
722
  maxRtt: Math.max(...a),
723
- aggregateReport: nt(e[0], e[e.length - 1], i),
723
+ aggregateReport: it(e[0], e[e.length - 1], i),
724
724
  minJitterDelayInInterval: Math.min(...c),
725
725
  maxJitterDelayInInterval: Math.max(...c),
726
- avgJitterDelayInInterval: ae(c)
726
+ avgJitterDelayInInterval: ie(c)
727
727
  },
728
728
  codec: e[0].codec,
729
729
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
730
730
  };
731
731
  }
732
- const re = 100, ot = Math.max(Math.ceil(400 / re), 1), ct = 0.25, dt = 0.28;
733
- function lt() {
732
+ const ne = 100, dt = Math.max(Math.ceil(400 / ne), 1), ut = 0.25, lt = 0.28;
733
+ function ft() {
734
734
  let e = 0, t, n, r = 0;
735
735
  return (o) => {
736
736
  for (const i of o.values())
@@ -741,9 +741,9 @@ function lt() {
741
741
  r = d / y;
742
742
  }
743
743
  t = c, n = a;
744
- const s = i.framesDecoded, l = s - e > 0;
744
+ const s = i.framesDecoded, u = s - e > 0;
745
745
  return e = s, {
746
- isReceiving: l,
746
+ isReceiving: u,
747
747
  avgJitterDelayInInterval: r,
748
748
  freezeCount: i.freezeCount
749
749
  };
@@ -754,46 +754,46 @@ function lt() {
754
754
  };
755
755
  };
756
756
  }
757
- function ut(e, t, n, r, o, i = !1) {
758
- let c = [], a, s = 0, l = !1, d = Q.Unknown, y = Q.Unknown, A = 0, P = 0;
759
- const x = lt();
757
+ function mt(e, t, n, r, o, i = !1) {
758
+ let c = [], a, s = 0, u = !1, d = O.Unknown, y = O.Unknown, A = 0, P = 0;
759
+ const x = ft();
760
760
  return setInterval(async () => {
761
761
  const F = await e.getStats(), {
762
- isReceiving: E,
762
+ isReceiving: R,
763
763
  avgJitterDelayInInterval: U,
764
764
  freezeCount: K
765
- } = x(F), j = it(F);
766
- if (E)
767
- s = 0, A = K - P, y = U < ct ? Q.Strong : U > dt && A > 1 ? Q.Weak : d, y !== d && (o == null || o(y), d = y, P += A, A = 0), l || (r == null || r(h.Start), a = c[c.length - 1], c = [], l = !0), c.push(j);
768
- else if (l && (s++, s >= ot)) {
769
- const u = st(c, re, a);
770
- r == null || r(h.Stop, u), t() || n(), P = K, l = !1;
765
+ } = x(F), T = ot(F);
766
+ if (R)
767
+ s = 0, A = K - P, y = U < ut ? O.Strong : U > lt && A > 1 ? O.Weak : d, y !== d && (o == null || o(y), d = y, P += A, A = 0), u || (r == null || r(h.Start), a = c[c.length - 1], c = [], u = !0), c.push(T);
768
+ else if (u && (s++, s >= dt)) {
769
+ const l = ct(c, ne, a);
770
+ r == null || r(h.Stop, l), t() || n(), P = K, u = !1;
771
771
  }
772
- }, re);
772
+ }, ne);
773
773
  }
774
- let we = !1;
775
- const b = (e, t) => we && console.log(e, t), ft = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
776
- function ie(e) {
774
+ let ye = !1;
775
+ const b = (e, t) => ye && console.log(e, t), gt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
776
+ function se(e) {
777
777
  switch (e) {
778
778
  case "connected":
779
- return S.Connected;
779
+ return I.Connected;
780
780
  case "checking":
781
- return S.Connecting;
781
+ return I.Connecting;
782
782
  case "failed":
783
- return S.Fail;
783
+ return I.Fail;
784
784
  case "new":
785
- return S.New;
785
+ return I.New;
786
786
  case "closed":
787
- return S.Closed;
787
+ return I.Closed;
788
788
  case "disconnected":
789
- return S.Disconnected;
789
+ return I.Disconnected;
790
790
  case "completed":
791
- return S.Completed;
791
+ return I.Completed;
792
792
  default:
793
- return S.New;
793
+ return I.New;
794
794
  }
795
795
  }
796
- function mt(e) {
796
+ function ht(e) {
797
797
  const [t, n = ""] = e.split(/:(.+)/);
798
798
  try {
799
799
  const r = JSON.parse(n);
@@ -815,7 +815,7 @@ function mt(e) {
815
815
  };
816
816
  }
817
817
  }
818
- function gt({
818
+ function wt({
819
819
  statsSignal: e,
820
820
  dataChannelSignal: t,
821
821
  onVideoStateChange: n,
@@ -823,7 +823,7 @@ function gt({
823
823
  }) {
824
824
  e === h.Start && t === h.Start ? n == null || n(h.Start) : e === h.Stop && t === h.Stop && (n == null || n(h.Stop, r));
825
825
  }
826
- function ht({
826
+ function pt({
827
827
  statsSignal: e,
828
828
  dataChannelSignal: t,
829
829
  onVideoStateChange: n,
@@ -832,7 +832,7 @@ function ht({
832
832
  }) {
833
833
  e === h.Start ? n == null || n(h.Start) : e === h.Stop && (n == null || n(h.Stop, o)), t === h.Start ? r == null || r(X.Talking) : t === h.Stop && (r == null || r(X.Idle));
834
834
  }
835
- function se({
835
+ function oe({
836
836
  statsSignal: e,
837
837
  dataChannelSignal: t,
838
838
  onVideoStateChange: n,
@@ -840,12 +840,12 @@ function se({
840
840
  streamType: o,
841
841
  report: i
842
842
  }) {
843
- o === J.Legacy ? gt({
843
+ o === W.Legacy ? wt({
844
844
  statsSignal: e,
845
845
  dataChannelSignal: t,
846
846
  onVideoStateChange: n,
847
847
  report: i
848
- }) : o === J.Fluent && ht({
848
+ }) : o === W.Fluent && pt({
849
849
  statsSignal: e,
850
850
  dataChannelSignal: t,
851
851
  onVideoStateChange: n,
@@ -853,185 +853,192 @@ function se({
853
853
  report: i
854
854
  });
855
855
  }
856
- async function wt(e, t, {
856
+ async function yt(e, t, {
857
857
  debug: n = !1,
858
858
  callbacks: r,
859
859
  auth: o,
860
860
  baseURL: i = Z,
861
861
  analytics: c
862
862
  }) {
863
- we = n;
864
- let a = !1, s = !1, l = h.Stop, d = h.Stop;
863
+ var J;
864
+ ye = n;
865
+ let a = !1, s = !1, u = h.Stop, d = h.Stop;
865
866
  const {
866
867
  startConnection: y,
867
868
  sendStreamRequest: A,
868
869
  close: P,
869
870
  createStream: x,
870
871
  addIceCandidate: F
871
- } = t.videoType === oe.Clip ? tt(o, i, e, r.onError) : rt(o, i, e, r.onError), {
872
- id: E,
872
+ } = t.videoType === ce.Clip ? nt(o, i, e, r.onError) : at(o, i, e, r.onError), {
873
+ id: R,
873
874
  offer: U,
874
875
  ice_servers: K,
875
- session_id: j,
876
- fluent: u,
876
+ session_id: T,
877
+ fluent: l,
877
878
  interrupt_enabled: w
878
- } = await x(t), g = new ft({
879
+ } = await x(t);
880
+ (J = r.onStreamCreated) == null || J.call(r, {
881
+ stream_id: R,
882
+ session_id: T,
883
+ agent_id: e
884
+ });
885
+ const m = new gt({
879
886
  iceServers: K
880
- }), D = g.createDataChannel("JanusDataChannel");
881
- if (!j)
887
+ }), D = m.createDataChannel("JanusDataChannel");
888
+ if (!T)
882
889
  throw new Error("Could not create session_id");
883
- const v = u ? J.Fluent : J.Legacy;
890
+ const v = l ? W.Fluent : W.Legacy;
884
891
  c.enrich({
885
892
  "stream-type": v
886
893
  });
887
- const p = t.stream_warmup && !u, _ = () => a, B = () => {
894
+ const p = t.stream_warmup && !l, _ = () => a, $ = () => {
888
895
  var f;
889
- a = !0, s && ((f = r.onConnectionStateChange) == null || f.call(r, S.Connected));
890
- }, $ = ut(g, _, B, (f, m) => se({
896
+ a = !0, s && ((f = r.onConnectionStateChange) == null || f.call(r, I.Connected));
897
+ }, B = mt(m, _, $, (f, g) => oe({
891
898
  statsSignal: d = f,
892
- dataChannelSignal: v === J.Legacy ? l : void 0,
899
+ dataChannelSignal: v === W.Legacy ? u : void 0,
893
900
  onVideoStateChange: r.onVideoStateChange,
894
901
  onAgentActivityStateChange: r.onAgentActivityStateChange,
895
- report: m,
902
+ report: g,
896
903
  streamType: v
897
904
  }), (f) => {
898
- var m;
899
- return (m = r.onConnectivityStateChange) == null ? void 0 : m.call(r, f);
905
+ var g;
906
+ return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
900
907
  }, p);
901
- g.onicecandidate = (f) => {
902
- var m;
908
+ m.onicecandidate = (f) => {
909
+ var g;
903
910
  b("peerConnection.onicecandidate", f);
904
911
  try {
905
- f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? F(E, {
912
+ f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? F(R, {
906
913
  candidate: f.candidate.candidate,
907
914
  sdpMid: f.candidate.sdpMid,
908
915
  sdpMLineIndex: f.candidate.sdpMLineIndex
909
- }, j) : F(E, {
916
+ }, T) : F(R, {
910
917
  candidate: null
911
- }, j);
912
- } catch (I) {
913
- (m = r.onError) == null || m.call(r, I, {
914
- streamId: E
918
+ }, T);
919
+ } catch (S) {
920
+ (g = r.onError) == null || g.call(r, S, {
921
+ streamId: R
915
922
  });
916
923
  }
917
924
  }, D.onopen = () => {
918
- s = !0, (!p || a) && B();
925
+ s = !0, (!p || a) && $();
919
926
  };
920
927
  const k = (f) => {
921
- var m;
922
- (m = r.onVideoIdChange) == null || m.call(r, f);
928
+ var g;
929
+ (g = r.onVideoIdChange) == null || g.call(r, f);
923
930
  };
924
- function R(f, m) {
925
- if (f === T.StreamStarted && typeof m == "object" && "metadata" in m) {
926
- const I = m.metadata;
927
- k(I.videoId);
931
+ function E(f, g) {
932
+ if (f === j.StreamStarted && typeof g == "object" && "metadata" in g) {
933
+ const S = g.metadata;
934
+ k(S.videoId);
928
935
  }
929
- f === T.StreamDone && k(null), l = f === T.StreamStarted ? h.Start : h.Stop, se({
930
- statsSignal: v === J.Legacy ? d : void 0,
931
- dataChannelSignal: l,
936
+ f === j.StreamDone && k(null), u = f === j.StreamStarted ? h.Start : h.Stop, oe({
937
+ statsSignal: v === W.Legacy ? d : void 0,
938
+ dataChannelSignal: u,
932
939
  onVideoStateChange: r.onVideoStateChange,
933
940
  onAgentActivityStateChange: r.onAgentActivityStateChange,
934
941
  streamType: v
935
942
  });
936
943
  }
937
- function C(f, m) {
938
- const I = typeof m == "string" ? m : m == null ? void 0 : m.metadata;
939
- I && c.enrich({
940
- streamMetadata: I
944
+ function C(f, g) {
945
+ const S = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
946
+ S && c.enrich({
947
+ streamMetadata: S
941
948
  }), c.track("agent-chat", {
942
949
  event: "ready"
943
950
  });
944
951
  }
945
952
  const L = {
946
- [T.StreamStarted]: R,
947
- [T.StreamDone]: R,
948
- [T.StreamReady]: C
953
+ [j.StreamStarted]: E,
954
+ [j.StreamDone]: E,
955
+ [j.StreamReady]: C
949
956
  };
950
957
  D.onmessage = (f) => {
951
- var W;
958
+ var Y;
952
959
  const {
953
- subject: m,
954
- data: I
955
- } = mt(f.data);
956
- (W = L[m]) == null || W.call(L, m, I);
957
- }, g.oniceconnectionstatechange = () => {
958
- var m;
959
- b("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
960
- const f = ie(g.iceConnectionState);
961
- f !== S.Connected && ((m = r.onConnectionStateChange) == null || m.call(r, f));
962
- }, g.ontrack = (f) => {
963
- var m;
964
- b("peerConnection.ontrack", f), (m = r.onSrcObjectReady) == null || m.call(r, f.streams[0]);
965
- }, await g.setRemoteDescription(U), b("set remote description OK");
966
- const z = await g.createAnswer();
967
- return b("create answer OK"), await g.setLocalDescription(z), b("set local description OK"), await y(E, z, j), b("start connection OK"), {
960
+ subject: g,
961
+ data: S
962
+ } = ht(f.data);
963
+ (Y = L[g]) == null || Y.call(L, g, S);
964
+ }, m.oniceconnectionstatechange = () => {
965
+ var g;
966
+ b("peerConnection.oniceconnectionstatechange => " + m.iceConnectionState);
967
+ const f = se(m.iceConnectionState);
968
+ f !== I.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
969
+ }, m.ontrack = (f) => {
970
+ var g;
971
+ b("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
972
+ }, await m.setRemoteDescription(U), b("set remote description OK");
973
+ const z = await m.createAnswer();
974
+ return b("create answer OK"), await m.setLocalDescription(z), b("set local description OK"), await y(R, z, T), b("start connection OK"), {
968
975
  /**
969
976
  * Method to send request to server to get clip or talk depend on you payload
970
977
  * @param payload
971
978
  */
972
979
  speak(f) {
973
- return A(E, j, f);
980
+ return A(R, T, f);
974
981
  },
975
982
  /**
976
983
  * Method to close RTC connection
977
984
  */
978
985
  async disconnect() {
979
986
  var f;
980
- if (E) {
981
- const m = ie(g.iceConnectionState);
982
- if (g) {
983
- if (m === S.New) {
984
- clearInterval($);
987
+ if (R) {
988
+ const g = se(m.iceConnectionState);
989
+ if (m) {
990
+ if (g === I.New) {
991
+ clearInterval(B);
985
992
  return;
986
993
  }
987
- g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
994
+ m.close(), m.oniceconnectionstatechange = null, m.onnegotiationneeded = null, m.onicecandidate = null, m.ontrack = null;
988
995
  }
989
996
  try {
990
- m === S.Connected && await P(E, j).catch((I) => {
997
+ g === I.Connected && await P(R, T).catch((S) => {
991
998
  });
992
- } catch (I) {
993
- b("Error on close stream connection", I);
999
+ } catch (S) {
1000
+ b("Error on close stream connection", S);
994
1001
  }
995
- (f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval($);
1002
+ (f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval(B);
996
1003
  }
997
1004
  },
998
1005
  /**
999
1006
  * Method to send data channel messages to the server
1000
1007
  */
1001
1008
  sendDataChannelMessage(f) {
1002
- var m, I;
1009
+ var g, S;
1003
1010
  if (!a || D.readyState !== "open") {
1004
- b("Data channel is not ready for sending messages"), (m = r.onError) == null || m.call(r, new Error("Data channel is not ready for sending messages"), {
1005
- streamId: E
1011
+ 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"), {
1012
+ streamId: R
1006
1013
  });
1007
1014
  return;
1008
1015
  }
1009
1016
  try {
1010
1017
  D.send(f);
1011
- } catch (W) {
1012
- b("Error sending data channel message", W), (I = r.onError) == null || I.call(r, W, {
1013
- streamId: E
1018
+ } catch (Y) {
1019
+ b("Error sending data channel message", Y), (S = r.onError) == null || S.call(r, Y, {
1020
+ streamId: R
1014
1021
  });
1015
1022
  }
1016
1023
  },
1017
1024
  /**
1018
1025
  * Session identifier information, should be returned in the body of all streaming requests
1019
1026
  */
1020
- sessionId: j,
1027
+ sessionId: T,
1021
1028
  /**
1022
1029
  * Id of current RTC stream
1023
1030
  */
1024
- streamId: E,
1031
+ streamId: R,
1025
1032
  streamType: v,
1026
1033
  interruptAvailable: w
1027
1034
  };
1028
1035
  }
1029
- function pt(e, t) {
1036
+ function vt(e, t) {
1030
1037
  const {
1031
1038
  streamOptions: n
1032
1039
  } = t ?? {};
1033
1040
  return {
1034
- videoType: Te(e.presenter.type),
1041
+ videoType: be(e.presenter.type),
1035
1042
  output_resolution: n == null ? void 0 : n.outputResolution,
1036
1043
  session_timeout: n == null ? void 0 : n.sessionTimeout,
1037
1044
  stream_warmup: n == null ? void 0 : n.streamWarmup,
@@ -1039,10 +1046,10 @@ function pt(e, t) {
1039
1046
  fluent: n == null ? void 0 : n.fluent
1040
1047
  };
1041
1048
  }
1042
- function yt(e, t, n, r, o) {
1043
- o === J.Fluent ? vt(e, t, n, r, o) : Dt(e, t, n, r, o);
1049
+ function kt(e, t, n, r, o) {
1050
+ o === W.Fluent ? Dt(e, t, n, r, o) : Rt(e, t, n, r, o);
1044
1051
  }
1045
- function vt(e, t, n, r, o) {
1052
+ function Dt(e, t, n, r, o) {
1046
1053
  e === h.Start ? r.track("stream-session", {
1047
1054
  event: "start",
1048
1055
  "stream-type": o
@@ -1054,50 +1061,50 @@ function vt(e, t, n, r, o) {
1054
1061
  ...n
1055
1062
  });
1056
1063
  }
1057
- function kt(e, t, n, r) {
1064
+ function Ct(e, t, n, r) {
1058
1065
  N.get() <= 0 || (e === h.Start ? n.linkTrack("agent-video", {
1059
1066
  event: "start",
1060
1067
  latency: N.get(!0),
1061
1068
  "stream-type": r
1062
- }, "start", [T.StreamVideoCreated]) : e === h.Stop && n.linkTrack("agent-video", {
1069
+ }, "start", [j.StreamVideoCreated]) : e === h.Stop && n.linkTrack("agent-video", {
1063
1070
  event: "stop",
1064
1071
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1065
1072
  background: t.presenter.type === "clip" && t.presenter.background,
1066
1073
  "stream-type": r
1067
- }, "done", [T.StreamVideoDone]));
1074
+ }, "done", [j.StreamVideoDone]));
1068
1075
  }
1069
- function Dt(e, t, n, r, o) {
1076
+ function Rt(e, t, n, r, o) {
1070
1077
  N.get() <= 0 || (e === h.Start ? r.linkTrack("agent-video", {
1071
1078
  event: "start",
1072
1079
  latency: N.get(!0),
1073
1080
  "stream-type": o
1074
- }, "start", [T.StreamVideoCreated]) : e === h.Stop && r.linkTrack("agent-video", {
1081
+ }, "start", [j.StreamVideoCreated]) : e === h.Stop && r.linkTrack("agent-video", {
1075
1082
  event: "stop",
1076
1083
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1077
1084
  background: t.presenter.type === "clip" && t.presenter.background,
1078
1085
  "stream-type": o,
1079
1086
  ...n
1080
- }, "done", [T.StreamVideoDone]));
1087
+ }, "done", [j.StreamVideoDone]));
1081
1088
  }
1082
- function Ct(e, t, n) {
1089
+ function St(e, t, n) {
1083
1090
  return N.reset(), new Promise(async (r, o) => {
1084
1091
  try {
1085
- const i = await wt(e.id, pt(e, t), {
1092
+ const i = await yt(e.id, vt(e, t), {
1086
1093
  ...t,
1087
1094
  analytics: n,
1088
1095
  callbacks: {
1089
1096
  ...t.callbacks,
1090
1097
  onConnectionStateChange: (c) => {
1091
1098
  var a, s;
1092
- (s = (a = t.callbacks).onConnectionStateChange) == null || s.call(a, c), c === S.Connected && r(i);
1099
+ (s = (a = t.callbacks).onConnectionStateChange) == null || s.call(a, c), c === I.Connected && r(i);
1093
1100
  },
1094
1101
  onVideoStateChange: (c, a) => {
1095
- var s, l;
1096
- (l = (s = t.callbacks).onVideoStateChange) == null || l.call(s, c), yt(c, e, a, n, i.streamType);
1102
+ var s, u;
1103
+ (u = (s = t.callbacks).onVideoStateChange) == null || u.call(s, c), kt(c, e, a, n, i.streamType);
1097
1104
  },
1098
1105
  onAgentActivityStateChange: (c) => {
1099
1106
  var a, s;
1100
- (s = (a = t.callbacks).onAgentActivityStateChange) == null || s.call(a, c), c === X.Talking ? te.update() : te.reset(), kt(c === X.Talking ? h.Start : h.Stop, e, n, i.streamType);
1107
+ (s = (a = t.callbacks).onAgentActivityStateChange) == null || s.call(a, c), c === X.Talking ? re.update() : re.reset(), Ct(c === X.Talking ? h.Start : h.Stop, e, n, i.streamType);
1101
1108
  }
1102
1109
  }
1103
1110
  });
@@ -1106,29 +1113,29 @@ function Ct(e, t, n) {
1106
1113
  }
1107
1114
  });
1108
1115
  }
1109
- async function Rt(e, t, n, r, o) {
1110
- var s, l, d, y;
1116
+ async function It(e, t, n, r, o) {
1117
+ var s, u, d, y;
1111
1118
  const {
1112
1119
  chat: i,
1113
1120
  chatMode: c
1114
- } = await he(e, n, r, t.mode, t.persistentChat, o);
1115
- if (c && c !== t.mode && (t.mode = c, (l = (s = t.callbacks).onModeChange) == null || l.call(s, c), c === M.TextOnly))
1116
- return (y = (d = t.callbacks).onError) == null || y.call(d, new ke(c)), {
1121
+ } = await pe(e, n, r, t.mode, t.persistentChat, o);
1122
+ if (c && c !== t.mode && (t.mode = c, (u = (s = t.callbacks).onModeChange) == null || u.call(s, c), c === M.TextOnly))
1123
+ return (y = (d = t.callbacks).onError) == null || y.call(d, new Ce(c)), {
1117
1124
  chat: i
1118
1125
  };
1119
- const a = await Ct(e, t, r);
1126
+ const a = await St(e, t, r);
1120
1127
  return {
1121
1128
  chat: i,
1122
1129
  streamingManager: a
1123
1130
  };
1124
1131
  }
1125
- async function St(e, t) {
1126
- var U, K, j;
1132
+ async function Et(e, t) {
1133
+ var U, K, T;
1127
1134
  let n = !0, r = null;
1128
- const o = t.mixpanelKey || $e, i = t.wsURL || Be, c = t.baseURL || Z, a = {
1135
+ const o = t.mixpanelKey || ze, i = t.wsURL || Le, c = t.baseURL || Z, a = {
1129
1136
  messages: [],
1130
1137
  chatMode: t.mode || M.Functional
1131
- }, s = He({
1138
+ }, s = Ve({
1132
1139
  token: o,
1133
1140
  agentId: e,
1134
1141
  isEnabled: t.enableAnalitics,
@@ -1137,110 +1144,110 @@ async function St(e, t) {
1137
1144
  s.track("agent-sdk", {
1138
1145
  event: "init"
1139
1146
  });
1140
- const l = ue(t.auth, c, t.callbacks.onError), d = await l.getById(e);
1141
- s.enrich(Je(d));
1147
+ const u = me(t.auth, c, t.callbacks.onError), d = await u.getById(e);
1148
+ s.enrich(Ue(d));
1142
1149
  const {
1143
1150
  onMessage: y,
1144
1151
  clearQueue: A
1145
- } = et(s, a, t, d, () => {
1146
- var u;
1147
- return (u = a.socketManager) == null ? void 0 : u.disconnect();
1152
+ } = rt(s, a, t, d, () => {
1153
+ var l;
1154
+ return (l = a.socketManager) == null ? void 0 : l.disconnect();
1148
1155
  });
1149
- a.messages = qe(t.initialMessages), (K = (U = t.callbacks).onNewMessage) == null || K.call(U, [...a.messages], "answer");
1150
- const P = (u) => {
1151
- r = u;
1156
+ a.messages = Xe(t.initialMessages), (K = (U = t.callbacks).onNewMessage) == null || K.call(U, [...a.messages], "answer");
1157
+ const P = (l) => {
1158
+ r = l;
1152
1159
  };
1153
1160
  s.track("agent-sdk", {
1154
1161
  event: "loaded",
1155
- ...Fe(d)
1162
+ ...We(d)
1156
1163
  });
1157
- async function x(u) {
1158
- var _, B, $, k, R, C, L;
1159
- (B = (_ = t.callbacks).onConnectionStateChange) == null || B.call(_, S.Connecting), N.reset(), u && !n && (delete a.chat, (k = ($ = t.callbacks).onNewMessage) == null || k.call($, [...a.messages], "answer"));
1160
- const w = t.mode === M.DirectPlayback ? Promise.resolve(void 0) : Ze(t.auth, i, {
1164
+ async function x(l) {
1165
+ var _, $, B, k, E, C, L;
1166
+ ($ = (_ = t.callbacks).onConnectionStateChange) == null || $.call(_, I.Connecting), N.reset(), l && !n && (delete a.chat, (k = (B = t.callbacks).onNewMessage) == null || k.call(B, [...a.messages], "answer"));
1167
+ const w = t.mode === M.DirectPlayback ? Promise.resolve(void 0) : Ge(t.auth, i, {
1161
1168
  onMessage: y,
1162
1169
  onError: t.callbacks.onError
1163
- }), g = ee(() => Rt(d, {
1170
+ }), m = te(() => It(d, {
1164
1171
  ...t,
1165
1172
  callbacks: {
1166
1173
  ...t.callbacks,
1167
1174
  onVideoIdChange: P
1168
1175
  }
1169
- }, l, s, a.chat), {
1176
+ }, u, s, a.chat), {
1170
1177
  limit: 3,
1171
- timeout: Ae,
1178
+ timeout: $e,
1172
1179
  timeoutErrorMessage: "Timeout initializing the stream",
1173
1180
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
1174
1181
  shouldRetryFn: (z) => (z == null ? void 0 : z.message) !== "Could not connect" && z.status !== 429,
1175
1182
  delayMs: 1e3
1176
1183
  }).catch((z) => {
1177
- var f, m;
1178
- throw E(M.Maintenance), (m = (f = t.callbacks).onConnectionStateChange) == null || m.call(f, S.Fail), z;
1184
+ var J, f;
1185
+ throw R(M.Maintenance), (f = (J = t.callbacks).onConnectionStateChange) == null || f.call(J, I.Fail), z;
1179
1186
  }), [D, {
1180
1187
  streamingManager: v,
1181
1188
  chat: p
1182
- }] = await Promise.all([w, g]);
1183
- p && p.id !== ((R = a.chat) == null ? void 0 : R.id) && ((L = (C = t.callbacks).onNewChat) == null || L.call(C, p.id)), a.streamingManager = v, a.socketManager = D, a.chat = p, n = !1, E((p == null ? void 0 : p.chat_mode) ?? t.mode ?? M.Functional);
1189
+ }] = await Promise.all([w, m]);
1190
+ p && p.id !== ((E = a.chat) == null ? void 0 : E.id) && ((L = (C = t.callbacks).onNewChat) == null || L.call(C, p.id)), a.streamingManager = v, a.socketManager = D, a.chat = p, n = !1, R((p == null ? void 0 : p.chat_mode) ?? t.mode ?? M.Functional);
1184
1191
  }
1185
1192
  async function F() {
1186
- var u, w, g, D;
1187
- (u = a.socketManager) == null || u.disconnect(), await ((w = a.streamingManager) == null ? void 0 : w.disconnect()), delete a.streamingManager, delete a.socketManager, (D = (g = t.callbacks).onConnectionStateChange) == null || D.call(g, S.Disconnected);
1193
+ var l, w, m, D;
1194
+ (l = a.socketManager) == null || l.disconnect(), await ((w = a.streamingManager) == null ? void 0 : w.disconnect()), delete a.streamingManager, delete a.socketManager, (D = (m = t.callbacks).onConnectionStateChange) == null || D.call(m, I.Disconnected);
1188
1195
  }
1189
- async function E(u) {
1190
- var w, g;
1191
- u !== a.chatMode && (s.track("agent-mode-change", {
1192
- mode: u
1193
- }), a.chatMode = u, a.chatMode !== M.Functional && await F(), (g = (w = t.callbacks).onModeChange) == null || g.call(w, u));
1196
+ async function R(l) {
1197
+ var w, m;
1198
+ l !== a.chatMode && (s.track("agent-mode-change", {
1199
+ mode: l
1200
+ }), a.chatMode = l, a.chatMode !== M.Functional && await F(), (m = (w = t.callbacks).onModeChange) == null || m.call(w, l));
1194
1201
  }
1195
1202
  return {
1196
1203
  agent: d,
1197
1204
  getStreamType: () => {
1198
- var u;
1199
- return (u = a.streamingManager) == null ? void 0 : u.streamType;
1205
+ var l;
1206
+ return (l = a.streamingManager) == null ? void 0 : l.streamType;
1200
1207
  },
1201
1208
  getIsInterruptAvailable: () => {
1202
- var u;
1203
- return ((u = a.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
1209
+ var l;
1210
+ return ((l = a.streamingManager) == null ? void 0 : l.interruptAvailable) ?? !1;
1204
1211
  },
1205
- starterMessages: ((j = d.knowledge) == null ? void 0 : j.starter_message) || [],
1206
- getSTTToken: () => l.getSTTToken(d.id),
1207
- changeMode: E,
1212
+ starterMessages: ((T = d.knowledge) == null ? void 0 : T.starter_message) || [],
1213
+ getSTTToken: () => u.getSTTToken(d.id),
1214
+ changeMode: R,
1208
1215
  enrichAnalytics: s.enrich,
1209
1216
  async connect() {
1210
- var u;
1217
+ var l;
1211
1218
  await x(!0), s.track("agent-chat", {
1212
1219
  event: "connect",
1213
- chatId: (u = a.chat) == null ? void 0 : u.id,
1220
+ chatId: (l = a.chat) == null ? void 0 : l.id,
1214
1221
  agentId: d.id,
1215
1222
  mode: a.chatMode
1216
1223
  });
1217
1224
  },
1218
1225
  async reconnect() {
1219
- var u;
1226
+ var l;
1220
1227
  await F(), await x(!1), s.track("agent-chat", {
1221
1228
  event: "reconnect",
1222
- chatId: (u = a.chat) == null ? void 0 : u.id,
1229
+ chatId: (l = a.chat) == null ? void 0 : l.id,
1223
1230
  agentId: d.id,
1224
1231
  mode: a.chatMode
1225
1232
  });
1226
1233
  },
1227
1234
  async disconnect() {
1228
- var u;
1235
+ var l;
1229
1236
  await F(), s.track("agent-chat", {
1230
1237
  event: "disconnect",
1231
- chatId: (u = a.chat) == null ? void 0 : u.id,
1238
+ chatId: (l = a.chat) == null ? void 0 : l.id,
1232
1239
  agentId: d.id,
1233
1240
  mode: a.chatMode
1234
1241
  });
1235
1242
  },
1236
- async chat(u) {
1237
- var v, p, _, B, $;
1243
+ async chat(l) {
1244
+ var v, p, _, $, B;
1238
1245
  const w = () => {
1239
- if (t.mode === M.DirectPlayback)
1240
- throw new H("Direct playback is enabled, chat is disabled");
1241
- if (u.length >= 800)
1246
+ if (ue(t.mode))
1247
+ throw new H(`${t.mode} is enabled, chat is disabled`);
1248
+ if (l.length >= 800)
1242
1249
  throw new H("Message cannot be more than 800 characters");
1243
- if (u.length === 0)
1250
+ if (l.length === 0)
1244
1251
  throw new H("Message cannot be empty");
1245
1252
  if (a.chatMode === M.Maintenance)
1246
1253
  throw new H("Chat is in maintenance mode");
@@ -1250,35 +1257,35 @@ async function St(e, t) {
1250
1257
  if (!a.chat)
1251
1258
  throw new H("Chat is not initialized");
1252
1259
  }
1253
- }, g = async () => {
1254
- var k, R;
1260
+ }, m = async () => {
1261
+ var k, E;
1255
1262
  if (!a.chat) {
1256
- const C = await he(d, l, s, a.chatMode, t.persistentChat);
1263
+ const C = await pe(d, u, s, a.chatMode, t.persistentChat);
1257
1264
  if (!C.chat)
1258
- throw new ve(a.chatMode, !!t.persistentChat);
1259
- a.chat = C.chat, (R = (k = t.callbacks).onNewChat) == null || R.call(k, a.chat.id);
1265
+ throw new De(a.chatMode, !!t.persistentChat);
1266
+ a.chat = C.chat, (E = (k = t.callbacks).onNewChat) == null || E.call(k, a.chat.id);
1260
1267
  }
1261
1268
  return a.chat.id;
1262
- }, D = async (k, R) => ee(() => {
1269
+ }, D = async (k, E) => te(() => {
1263
1270
  var C, L;
1264
- return l.chat(d.id, R, {
1271
+ return u.chat(d.id, E, {
1265
1272
  chatMode: a.chatMode,
1266
1273
  streamId: (C = a.streamingManager) == null ? void 0 : C.streamId,
1267
1274
  sessionId: (L = a.streamingManager) == null ? void 0 : L.sessionId,
1268
1275
  messages: k.map(({
1269
1276
  matches: z,
1270
- ...f
1271
- }) => f)
1277
+ ...J
1278
+ }) => J)
1272
1279
  }, {
1273
- ...ge(a.chatMode),
1280
+ ...we(a.chatMode),
1274
1281
  skipErrorHandler: !0
1275
1282
  });
1276
1283
  }, {
1277
1284
  limit: 2,
1278
1285
  shouldRetryFn: (C) => {
1279
- var f, m, I, W;
1280
- const L = (f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("missing or invalid session_id");
1281
- return !((m = C == null ? void 0 : C.message) == null ? void 0 : m.includes("Stream Error")) && !L ? ((W = (I = t.callbacks).onError) == null || W.call(I, C), !1) : !0;
1286
+ var J, f, g, S;
1287
+ const L = (J = C == null ? void 0 : C.message) == null ? void 0 : J.includes("missing or invalid session_id");
1288
+ return !((f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("Stream Error")) && !L ? ((S = (g = t.callbacks).onError) == null || S.call(g, C), !1) : !0;
1282
1289
  },
1283
1290
  onRetry: async () => {
1284
1291
  await F(), await x(!1);
@@ -1288,38 +1295,37 @@ async function St(e, t) {
1288
1295
  A(), w(), a.messages.push({
1289
1296
  id: V(),
1290
1297
  role: "user",
1291
- content: u,
1298
+ content: l,
1292
1299
  created_at: new Date(N.update()).toISOString()
1293
1300
  }), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...a.messages], "user");
1294
- const k = await g(), R = await D([...a.messages], k);
1301
+ const k = await m(), E = await D([...a.messages], k);
1295
1302
  return a.messages.push({
1296
1303
  id: V(),
1297
1304
  role: "assistant",
1298
- content: R.result || "",
1305
+ content: E.result || "",
1299
1306
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1300
- context: R.context,
1301
- matches: R.matches,
1302
- videoId: R.videoId
1307
+ context: E.context,
1308
+ matches: E.matches
1303
1309
  }), s.track("agent-message-send", {
1304
1310
  event: "success",
1305
1311
  mode: a.chatMode,
1306
1312
  messages: a.messages.length + 1
1307
- }), R.result && ((B = (_ = t.callbacks).onNewMessage) == null || B.call(_, [...a.messages], "answer"), s.track("agent-message-received", {
1313
+ }), E.result && (($ = (_ = t.callbacks).onNewMessage) == null || $.call(_, [...a.messages], "answer"), s.track("agent-message-received", {
1308
1314
  latency: N.get(!0),
1309
1315
  mode: a.chatMode,
1310
1316
  messages: a.messages.length
1311
- })), R;
1317
+ })), E;
1312
1318
  } catch (k) {
1313
- throw (($ = a.messages[a.messages.length - 1]) == null ? void 0 : $.role) === "assistant" && a.messages.pop(), s.track("agent-message-send", {
1319
+ throw ((B = a.messages[a.messages.length - 1]) == null ? void 0 : B.role) === "assistant" && a.messages.pop(), s.track("agent-message-send", {
1314
1320
  event: "error",
1315
1321
  mode: a.chatMode,
1316
1322
  messages: a.messages.length
1317
1323
  }), k;
1318
1324
  }
1319
1325
  },
1320
- rate(u, w, g) {
1321
- var p, _, B, $;
1322
- const D = a.messages.find((k) => k.id === u);
1326
+ rate(l, w, m) {
1327
+ var p, _, $, B;
1328
+ const D = a.messages.find((k) => k.id === l);
1323
1329
  if (a.chat) {
1324
1330
  if (!D)
1325
1331
  throw new Error("Message not found");
@@ -1327,67 +1333,67 @@ async function St(e, t) {
1327
1333
  throw new Error("Chat is not initialized");
1328
1334
  const v = ((p = D.matches) == null ? void 0 : p.map((k) => [k.document_id, k.id])) ?? [];
1329
1335
  return s.track("agent-rate", {
1330
- event: g ? "update" : "create",
1336
+ event: m ? "update" : "create",
1331
1337
  thumb: w === 1 ? "up" : "down",
1332
1338
  knowledge_id: ((_ = d.knowledge) == null ? void 0 : _.id) ?? "",
1333
1339
  mode: a.chatMode,
1334
1340
  matches: v,
1335
1341
  score: w
1336
- }), g ? l.updateRating(d.id, a.chat.id, g, {
1337
- knowledge_id: ((B = d.knowledge) == null ? void 0 : B.id) ?? "",
1338
- message_id: u,
1342
+ }), m ? u.updateRating(d.id, a.chat.id, m, {
1343
+ knowledge_id: (($ = d.knowledge) == null ? void 0 : $.id) ?? "",
1344
+ message_id: l,
1339
1345
  matches: v,
1340
1346
  score: w
1341
- }) : l.createRating(d.id, a.chat.id, {
1342
- knowledge_id: (($ = d.knowledge) == null ? void 0 : $.id) ?? "",
1343
- message_id: u,
1347
+ }) : u.createRating(d.id, a.chat.id, {
1348
+ knowledge_id: ((B = d.knowledge) == null ? void 0 : B.id) ?? "",
1349
+ message_id: l,
1344
1350
  matches: v,
1345
1351
  score: w
1346
1352
  });
1347
1353
  },
1348
- deleteRate(u) {
1354
+ deleteRate(l) {
1349
1355
  var w;
1350
1356
  if (!a.chat)
1351
1357
  throw new Error("Chat is not initialized");
1352
1358
  return s.track("agent-rate-delete", {
1353
1359
  type: "text",
1354
1360
  chat_id: (w = a.chat) == null ? void 0 : w.id,
1355
- id: u,
1361
+ id: l,
1356
1362
  mode: a.chatMode
1357
- }), l.deleteRating(d.id, a.chat.id, u);
1363
+ }), u.deleteRating(d.id, a.chat.id, l);
1358
1364
  },
1359
- async speak(u) {
1365
+ async speak(l) {
1360
1366
  var v, p, _;
1361
1367
  function w() {
1362
- if (typeof u == "string") {
1368
+ if (typeof l == "string") {
1363
1369
  if (!d.presenter.voice)
1364
1370
  throw new Error("Presenter voice is not initialized");
1365
1371
  return {
1366
1372
  type: "text",
1367
1373
  provider: d.presenter.voice,
1368
- input: u,
1374
+ input: l,
1369
1375
  ssml: !1
1370
1376
  };
1371
1377
  }
1372
- if (u.type === "text" && !u.provider) {
1378
+ if (l.type === "text" && !l.provider) {
1373
1379
  if (!d.presenter.voice)
1374
1380
  throw new Error("Presenter voice is not initialized");
1375
1381
  return {
1376
1382
  type: "text",
1377
1383
  provider: d.presenter.voice,
1378
- input: u.input,
1379
- ssml: u.ssml
1384
+ input: l.input,
1385
+ ssml: l.ssml
1380
1386
  };
1381
1387
  }
1382
- return u;
1388
+ return l;
1383
1389
  }
1384
- const g = w();
1385
- if (s.track("agent-speak", g), N.update(), a.messages && g.type === "text" && (a.messages.push({
1390
+ const m = w();
1391
+ if (s.track("agent-speak", m), N.update(), a.messages && m.type === "text" && (a.messages.push({
1386
1392
  id: V(),
1387
1393
  role: "assistant",
1388
- content: g.input,
1394
+ content: m.input,
1389
1395
  created_at: new Date(N.get(!0)).toISOString()
1390
- }), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...a.messages], "answer")), Le(a.chatMode))
1396
+ }), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...a.messages], "answer")), Ne(a.chatMode))
1391
1397
  return {
1392
1398
  duration: 0,
1393
1399
  video_id: "",
@@ -1396,7 +1402,7 @@ async function St(e, t) {
1396
1402
  if (!a.streamingManager)
1397
1403
  throw new Error("Please connect to the agent first");
1398
1404
  return a.streamingManager.speak({
1399
- script: g,
1405
+ script: m,
1400
1406
  metadata: {
1401
1407
  chat_id: (_ = a.chat) == null ? void 0 : _.id,
1402
1408
  agent_id: d.id
@@ -1404,54 +1410,54 @@ async function St(e, t) {
1404
1410
  });
1405
1411
  },
1406
1412
  async interrupt({
1407
- type: u
1413
+ type: l
1408
1414
  }) {
1409
- var g, D, v, p, _;
1410
- Ve(a.streamingManager, (g = a.streamingManager) == null ? void 0 : g.streamType, r);
1415
+ var m, D, v, p, _;
1416
+ Ye(a.streamingManager, (m = a.streamingManager) == null ? void 0 : m.streamType, r);
1411
1417
  const w = a.messages[a.messages.length - 1];
1412
1418
  s.track("agent-video-interrupt", {
1413
- type: u || "click",
1419
+ type: l || "click",
1414
1420
  stream_id: (D = a.streamingManager) == null ? void 0 : D.streamId,
1415
1421
  agent_id: d.id,
1416
1422
  owner_id: d.owner_id,
1417
- video_duration_to_interrupt: te.get(!0),
1423
+ video_duration_to_interrupt: re.get(!0),
1418
1424
  message_duration_to_interrupt: N.get(!0),
1419
1425
  chat_id: (v = a.chat) == null ? void 0 : v.id,
1420
1426
  mode: a.chatMode
1421
- }), w.interrupted = !0, (_ = (p = t.callbacks).onNewMessage) == null || _.call(p, [...a.messages], "answer"), Xe(a.streamingManager, r);
1427
+ }), w.interrupted = !0, (_ = (p = t.callbacks).onNewMessage) == null || _.call(p, [...a.messages], "answer"), Qe(a.streamingManager, r);
1422
1428
  }
1423
1429
  };
1424
1430
  }
1425
- function Et(e, t, n) {
1431
+ function Mt(e, t, n) {
1426
1432
  const {
1427
1433
  getById: r
1428
- } = ue(t, n || Z);
1434
+ } = me(t, n || Z);
1429
1435
  return r(e);
1430
1436
  }
1431
1437
  export {
1432
1438
  X as AgentActivityState,
1433
- Ie as AgentStatus,
1434
- ve as ChatCreationFailed,
1439
+ _e as AgentStatus,
1440
+ De as ChatCreationFailed,
1435
1441
  M as ChatMode,
1436
- ke as ChatModeDowngraded,
1442
+ Ce as ChatModeDowngraded,
1437
1443
  q as ChatProgress,
1438
- S as ConnectionState,
1439
- Q as ConnectivityState,
1440
- Me as DocumentType,
1441
- _e as KnowledgeType,
1442
- Re as PlanGroup,
1443
- je as Providers,
1444
- Se as RateState,
1445
- T as StreamEvents,
1446
- J as StreamType,
1444
+ I as ConnectionState,
1445
+ O as ConnectivityState,
1446
+ je as DocumentType,
1447
+ Te as KnowledgeType,
1448
+ Ie as PlanGroup,
1449
+ Ae as Providers,
1450
+ Ee as RateState,
1451
+ j as StreamEvents,
1452
+ W as StreamType,
1447
1453
  h as StreamingState,
1448
- Ee as Subject,
1449
- Ce as UserPlan,
1454
+ Me as Subject,
1455
+ Se as UserPlan,
1450
1456
  H as ValidationError,
1451
- oe as VideoType,
1452
- be as VoiceAccess,
1453
- De as WsError,
1454
- St as createAgentManager,
1455
- Et as getAgent,
1456
- Te as mapVideoType
1457
+ ce as VideoType,
1458
+ Pe as VoiceAccess,
1459
+ Re as WsError,
1460
+ Et as createAgentManager,
1461
+ Mt as getAgent,
1462
+ be as mapVideoType
1457
1463
  };