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

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