@d-id/client-sdk 1.1.6-staging.21 → 1.1.7-staging.23

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