@d-id/client-sdk 1.1.0-beta.25 → 1.1.0-beta.27

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