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

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 ve = Object.defineProperty;
2
+ var ke = (e, t, n) => t in e ? ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Q = (e, t, n) => (ke(e, typeof t != "symbol" ? t + "" : t, n), n);
4
4
  class G extends Error {
5
5
  constructor({
6
6
  kind: n,
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
+ Q(this, "kind");
15
+ Q(this, "description");
16
+ Q(this, "error");
17
+ this.kind = n, this.description = r, this.error = o;
18
18
  }
19
19
  }
20
- class Ce extends G {
20
+ class De 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 Ce 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
+ Q(this, "key");
43
43
  this.key = r;
44
44
  }
45
45
  }
46
- class Ie extends G {
46
+ class Re 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 Se = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Se || {}), Ie = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ie || {}), _e = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(_e || {}), Ee = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ee || {}), M = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(M || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Me = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Me || {}), Te = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Te || {}), je = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(je || {}), ce = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ce || {});
55
+ const be = (e) => {
56
56
  switch (e) {
57
57
  case "clip":
58
58
  return "clip";
@@ -62,15 +62,15 @@ 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 || {}), O = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), j = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Ae = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Ae || {}), Pe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Pe || {});
66
+ const $e = 45 * 1e3, Be = "X-Playground-Chat", Z = "https://api.d-id.com", Le = "wss://notifications.d-id.com", ze = "79f81a83a67430be2bc0fd61042b8faa", de = (e) => new Promise((t) => setTimeout(t, e)), V = (e = 16) => {
67
67
  const t = new Uint8Array(e);
68
68
  return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
69
- }, xe = (e) => [j.TextOnly, j.Playground, j.Maintenance].includes(e);
70
- function Fe(e, t) {
69
+ }, Ne = (e) => [M.TextOnly, M.Playground, M.Maintenance].includes(e), ue = (e) => e && [M.DirectPlayback, M.Off].includes(e);
70
+ function xe(e, t) {
71
71
  let n;
72
72
  return {
73
- 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)
@@ -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
+ } = xe(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 de(n.delayMs), n.onRetry(i);
103
103
  }
104
104
  throw r;
105
105
  }
106
- function fe() {
106
+ function le() {
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 Fe = V();
115
+ function fe(e) {
116
116
  if (e.type === "bearer")
117
117
  return `Bearer ${e.token}`;
118
118
  if (e.type === "basic")
119
119
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
120
120
  if (e.type === "key")
121
- return `Client-Key ${e.clientKey}.${fe()}_${Je}`;
121
+ return `Client-Key ${e.clientKey}.${le()}_${Fe}`;
122
122
  throw new Error(`Unknown auth type: ${e}`);
123
123
  }
124
- const We = (e) => te(e, {
124
+ const Je = (e) => te(e, {
125
125
  limit: 3,
126
126
  delayMs: 1e3,
127
127
  timeout: 0,
128
128
  shouldRetryFn: (t) => t.status === 429
129
129
  });
130
- function ae(e, t = Q, n) {
131
- const r = async (s, i) => {
130
+ function ae(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 Je(() => 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: fe(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 u = await s.text().catch(() => `Failed to fetch with status ${s.status}`);
145
+ const d = new Error(u);
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) {
184
+ function me(e, t = Z, n) {
185
185
  const r = ae(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 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
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: ge(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 Ue(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: ge(e.presenter),
246
246
  owner_id: e.owner_id ?? "",
247
247
  promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
248
248
  behavior: {
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 Ke = (e) => e.reduce((t, n) => t + n, 0), ie = (e) => Ke(e) / e.length;
261
+ function He(e, t, n) {
262
+ var s, u, d;
263
263
  const {
264
264
  event: r,
265
- ...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
+ ...(u = o == null ? void 0 : o.script) == null ? void 0 : u.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
- let O = {};
289
- const Ve = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
290
- function Xe(e) {
288
+ let ee = {};
289
+ const qe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
290
+ function Ve(e) {
291
291
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
292
292
  return {
293
293
  token: e.token || "testKey",
294
- distinct_id: e.distinctId || fe(),
294
+ distinct_id: e.distinctId || le(),
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(qe, c).then((a) => a.json());
336
+ } catch (a) {
337
+ return console.error(a);
338
338
  }
339
339
  },
340
- linkTrack(n, r, s, i) {
341
- O[n] || (O[n] = {
340
+ linkTrack(n, r, o, i) {
341
+ ee[n] || (ee[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 = ee[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((u, d) => c.events[d] ? {
350
+ ...u,
351
+ ...c.events[d].props
352
+ } : u, {});
353
+ this.track(n, s), c.resolvedDependencies = c.resolvedDependencies.filter((u) => !i.includes(u)), i.forEach((u) => {
354
+ delete c.events[u];
355
355
  });
356
356
  }
357
357
  }
358
358
  };
359
359
  }
360
- function we() {
360
+ function he() {
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 = he(), re = he();
369
+ function we(e) {
370
+ return e === M.Playground ? {
371
371
  headers: {
372
- [Le]: "true"
372
+ [Be]: "true"
373
373
  }
374
374
  } : {};
375
375
  }
376
- async function ye(e, t, n, r, s = !1, i) {
376
+ async function pe(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 && !ue(r) && (i = await t.newChat(e.id, {
379
+ persist: o
380
+ }, we(r)), n.track("agent-chat", {
381
381
  event: "created",
382
382
  chat_id: i.id,
383
383
  agent_id: e.id,
@@ -386,90 +386,90 @@ 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 Xe(e) {
401
401
  return e && e.length > 0 ? e : [];
402
402
  }
403
- function Qe(e, t, n, r) {
403
+ function Ye(e, t, n) {
404
404
  if (!e)
405
405
  throw new Error("Please connect to the agent first");
406
406
  if (!e.interruptAvailable)
407
407
  throw new Error("Interrupt is not enabled for this stream");
408
- if (t !== x.Fluent)
408
+ if (t !== W.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 Qe(e, t) {
414
414
  const n = {
415
- type: P.StreamInterrupt,
415
+ type: j.StreamInterrupt,
416
416
  videoId: t,
417
417
  timestamp: Date.now()
418
418
  };
419
419
  e.sendDataChannelMessage(JSON.stringify(n));
420
420
  }
421
- function Ze(e) {
421
+ function Oe(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: u = null
432
+ } = r || {}, d = new WebSocket(`${o}?authorization=${fe(i)}`);
433
+ d.onmessage = c, d.onclose = s, d.onerror = (y) => {
434
+ console.error(y), u == null || u("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 Ze(e) {
441
441
  const {
442
442
  retries: t = 1
443
443
  } = e;
444
444
  let n = null;
445
445
  for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
446
446
  try {
447
- n = await Ze(e);
448
- } catch (s) {
447
+ n = await Oe(e);
448
+ } catch (o) {
449
449
  if (r === t)
450
- throw s;
451
- await ue(r * 500);
450
+ throw o;
451
+ await de(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 Ge(e, t, n) {
456
+ const r = n != null && n.onMessage ? [n.onMessage] : [], o = await Ze({
457
457
  auth: e,
458
458
  host: t,
459
459
  callbacks: {
460
460
  onError: (i) => {
461
- 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 Re(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
  }
@@ -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 tt(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 = et(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 rt(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, u;
502
+ if ("content" in a)
503
+ tt(c, a, i, t, n.callbacks.onNewMessage), c === q.Answer && e.track("agent-message-received", {
504
504
  messages: t.messages.length,
505
505
  mode: t.chatMode
506
506
  });
507
507
  else {
508
- const u = P, w = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], g = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], $ = qe(d, r, {
508
+ const d = j, y = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], A = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], P = He(a, r, {
509
509
  mode: t.chatMode
510
510
  });
511
- 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) && ((u = (s = n.callbacks).onError) == null || u.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
530
  function nt(e, t, n, r) {
531
- const s = ae(e, `${t}/agents/${n}`, r);
531
+ const o = ae(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
567
  function at(e, t, n, r) {
568
- const s = ae(e, `${t}/agents/${n}`, r);
568
+ const o = ae(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,30 +577,30 @@ 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);
593
+ },
594
+ sendStreamRequest(i, c, a, s) {
595
+ return o.post(`/streams/${i}`, {
596
+ session_id: c,
597
+ ...a
598
+ }, s);
599
599
  },
600
- close(i, o, d) {
601
- return s.delete(`/streams/${i}`, {
602
- session_id: o
603
- }, d);
600
+ close(i, c, a) {
601
+ return o.delete(`/streams/${i}`, {
602
+ session_id: c
603
+ }, a);
604
604
  }
605
605
  };
606
606
  }
@@ -629,10 +629,10 @@ function st(e) {
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
  }
@@ -662,88 +662,88 @@ function ot(e) {
662
662
  return {};
663
663
  }
664
664
  function ct(e, t, n) {
665
- const r = e.map((c, a) => a === 0 ? n ? {
666
- timestamp: c.timestamp,
665
+ const r = e.map((s, u) => u === 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 * u / 1e3,
702
+ rtt: s.rtt,
703
+ bytesReceived: s.bytesReceived - e[u - 1].bytesReceived,
704
+ bitrate: (s.bytesReceived - e[u - 1].bytesReceived) * 8 / (t / 1e3),
705
+ packetsReceived: s.packetsReceived - e[u - 1].packetsReceived,
706
+ packetsLost: s.packetsLost - e[u - 1].packetsLost,
707
+ framesDropped: s.framesDropped - e[u - 1].framesDropped,
708
+ framesDecoded: s.framesDecoded - e[u - 1].framesDecoded,
709
+ jitter: s.jitter,
710
+ jitterBufferDelay: s.jitterBufferDelay - e[u - 1].jitterBufferDelay,
711
+ jitterBufferEmittedCount: s.jitterBufferEmittedCount - e[u - 1].jitterBufferEmittedCount,
712
+ avgJitterDelayInInterval: (s.jitterBufferDelay - e[u - 1].jitterBufferDelay) / (s.jitterBufferEmittedCount - e[u - 1].jitterBufferEmittedCount),
713
+ framesPerSecond: s.framesPerSecond,
714
+ freezeCount: s.freezeCount - e[u - 1].freezeCount,
715
+ freezeDuration: s.freezeDuration - e[u - 1].freezeDuration
716
+ }), o = st(r), i = o.reduce((s, u) => s + (u.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), a = r.filter((s) => !!s.rtt).map((s) => s.rtt);
717
717
  return {
718
718
  webRTCStats: {
719
- anomalies: s,
720
- minRtt: Math.min(...d),
721
- avgRtt: oe(d),
722
- maxRtt: Math.max(...d),
719
+ anomalies: o,
720
+ minRtt: Math.min(...a),
721
+ avgRtt: ie(a),
722
+ maxRtt: Math.max(...a),
723
723
  aggregateReport: it(e[0], e[e.length - 1], i),
724
- minJitterDelayInInterval: Math.min(...o),
725
- maxJitterDelayInInterval: Math.max(...o),
726
- avgJitterDelayInInterval: oe(o)
724
+ minJitterDelayInInterval: Math.min(...c),
725
+ maxJitterDelayInInterval: Math.max(...c),
726
+ avgJitterDelayInInterval: ie(c)
727
727
  },
728
728
  codec: e[0].codec,
729
729
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
730
730
  };
731
731
  }
732
- const ne = 100, dt = Math.max(Math.ceil(400 / ne), 1), lt = 0.25, ut = 0.28;
732
+ const ne = 100, dt = Math.max(Math.ceil(400 / ne), 1), ut = 0.25, lt = 0.28;
733
733
  function ft() {
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, u = s - e > 0;
745
+ return e = s, {
746
+ isReceiving: u,
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 mt(e, t, n, r, o, i = !1) {
758
+ let c = [], a, s = 0, u = !1, d = O.Unknown, y = O.Unknown, A = 0, P = 0;
759
+ const x = ft();
760
760
  return setInterval(async () => {
761
- 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: R,
763
+ avgJitterDelayInInterval: U,
764
+ freezeCount: K
765
+ } = x(F), T = ot(F);
766
+ if (R)
767
+ s = 0, A = K - P, y = U < ut ? O.Strong : U > lt && A > 1 ? O.Weak : d, y !== d && (o == null || o(y), d = y, P += A, A = 0), u || (r == null || r(h.Start), a = c[c.length - 1], c = [], u = !0), c.push(T);
768
+ else if (u && (s++, s >= dt)) {
769
+ const l = ct(c, ne, a);
770
+ r == null || r(h.Stop, l), t() || n(), P = K, u = !1;
771
771
  }
772
772
  }, ne);
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 ye = !1;
775
+ const b = (e, t) => ye && console.log(e, t), gt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
776
+ function se(e) {
777
777
  switch (e) {
778
778
  case "connected":
779
- return E.Connected;
779
+ return I.Connected;
780
780
  case "checking":
781
- return E.Connecting;
781
+ return I.Connecting;
782
782
  case "failed":
783
- return E.Fail;
783
+ return I.Fail;
784
784
  case "new":
785
- return E.New;
785
+ return I.New;
786
786
  case "closed":
787
- return E.Closed;
787
+ return I.Closed;
788
788
  case "disconnected":
789
- return E.Disconnected;
789
+ return I.Disconnected;
790
790
  case "completed":
791
- return E.Completed;
791
+ return I.Completed;
792
792
  default:
793
- return E.New;
793
+ return I.New;
794
794
  }
795
795
  }
796
796
  function ht(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
@@ -821,31 +821,31 @@ function wt({
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
826
  function pt({
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 oe({
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 === W.Legacy ? wt({
844
844
  statsSignal: e,
845
845
  dataChannelSignal: t,
846
846
  onVideoStateChange: n,
847
847
  report: i
848
- }) : s === x.Fluent && pt({
848
+ }) : o === W.Fluent && pt({
849
849
  statsSignal: e,
850
850
  dataChannelSignal: t,
851
851
  onVideoStateChange: n,
@@ -856,174 +856,181 @@ function de({
856
856
  async function yt(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
+ var J;
864
+ ye = n;
865
+ let a = !1, s = !1, u = h.Stop, d = h.Stop;
865
866
  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)
867
+ startConnection: y,
868
+ sendStreamRequest: A,
869
+ close: P,
870
+ createStream: x,
871
+ addIceCandidate: F
872
+ } = t.videoType === ce.Clip ? nt(o, i, e, r.onError) : at(o, i, e, r.onError), {
873
+ id: R,
874
+ offer: U,
875
+ ice_servers: K,
876
+ session_id: T,
877
+ fluent: l,
878
+ interrupt_enabled: w
879
+ } = await x(t);
880
+ (J = r.onStreamCreated) == null || J.call(r, {
881
+ stream_id: R,
882
+ session_id: T,
883
+ agent_id: e
884
+ });
885
+ const m = new gt({
886
+ iceServers: K
887
+ }), D = m.createDataChannel("JanusDataChannel");
888
+ if (!T)
882
889
  throw new Error("Could not create session_id");
883
- const p = U ? x.Fluent : x.Legacy;
884
- o.enrich({
885
- "stream-type": p
890
+ const v = l ? W.Fluent : W.Legacy;
891
+ c.enrich({
892
+ "stream-type": v
886
893
  });
887
- const T = t.stream_warmup && !U, b = () => d, k = () => {
894
+ const p = t.stream_warmup && !l, _ = () => a, $ = () => {
888
895
  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,
896
+ a = !0, s && ((f = r.onConnectionStateChange) == null || f.call(r, I.Connected));
897
+ }, B = mt(m, _, $, (f, g) => oe({
898
+ statsSignal: d = f,
899
+ dataChannelSignal: v === W.Legacy ? u : void 0,
893
900
  onVideoStateChange: r.onVideoStateChange,
894
901
  onAgentActivityStateChange: r.onAgentActivityStateChange,
895
- report: m,
896
- streamType: p
902
+ report: g,
903
+ streamType: v
897
904
  }), (f) => {
898
- var m;
899
- return (m = r.onConnectivityStateChange) == null ? void 0 : m.call(r, f);
900
- }, T);
901
- l.onicecandidate = (f) => {
902
- var m;
903
- B("peerConnection.onicecandidate", f);
905
+ var g;
906
+ return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
907
+ }, p);
908
+ m.onicecandidate = (f) => {
909
+ var g;
910
+ b("peerConnection.onicecandidate", f);
904
911
  try {
905
- f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? W(M, {
912
+ f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? F(R, {
906
913
  candidate: f.candidate.candidate,
907
914
  sdpMid: f.candidate.sdpMid,
908
915
  sdpMLineIndex: f.candidate.sdpMLineIndex
909
- }, A) : W(M, {
916
+ }, T) : F(R, {
910
917
  candidate: null
911
- }, A);
912
- } catch (D) {
913
- (m = r.onError) == null || m.call(r, D, {
914
- streamId: M
918
+ }, T);
919
+ } catch (S) {
920
+ (g = r.onError) == null || g.call(r, S, {
921
+ streamId: R
915
922
  });
916
923
  }
917
- }, h.onopen = () => {
918
- c = !0, (!T || d) && k();
924
+ }, D.onopen = () => {
925
+ s = !0, (!p || a) && $();
919
926
  };
920
- const S = (f) => {
921
- var m;
922
- (m = r.onVideoIdChange) == null || m.call(r, f);
927
+ const k = (f) => {
928
+ var g;
929
+ (g = r.onVideoIdChange) == null || g.call(r, f);
923
930
  };
924
- function _(f, m) {
925
- if (f === P.StreamStarted && typeof m == "object" && "metadata" in m) {
926
- const D = m.metadata;
927
- S(D.videoId);
931
+ function E(f, g) {
932
+ if (f === j.StreamStarted && typeof g == "object" && "metadata" in g) {
933
+ const S = g.metadata;
934
+ k(S.videoId);
928
935
  }
929
- f === P.StreamDone && S(null), a = f === P.StreamStarted ? y.Start : y.Stop, de({
930
- statsSignal: p === x.Legacy ? u : void 0,
931
- dataChannelSignal: a,
936
+ f === j.StreamDone && k(null), u = f === j.StreamStarted ? h.Start : h.Stop, oe({
937
+ statsSignal: v === W.Legacy ? d : void 0,
938
+ dataChannelSignal: u,
932
939
  onVideoStateChange: r.onVideoStateChange,
933
940
  onAgentActivityStateChange: r.onAgentActivityStateChange,
934
- streamType: p
941
+ streamType: v
935
942
  });
936
943
  }
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", {
944
+ function C(f, g) {
945
+ const S = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
946
+ S && c.enrich({
947
+ streamMetadata: S
948
+ }), c.track("agent-chat", {
942
949
  event: "ready"
943
950
  });
944
951
  }
945
- const C = {
946
- [P.StreamStarted]: _,
947
- [P.StreamDone]: _,
948
- [P.StreamReady]: v
952
+ const L = {
953
+ [j.StreamStarted]: E,
954
+ [j.StreamDone]: E,
955
+ [j.StreamReady]: C
949
956
  };
950
- h.onmessage = (f) => {
951
- var L;
957
+ D.onmessage = (f) => {
958
+ var Y;
952
959
  const {
953
- subject: m,
954
- data: D
960
+ subject: g,
961
+ data: S
955
962
  } = ht(f.data);
956
- (L = C[m]) == null || L.call(C, m, D);
957
- }, l.oniceconnectionstatechange = () => {
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) => {
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"), {
963
+ (Y = L[g]) == null || Y.call(L, g, S);
964
+ }, m.oniceconnectionstatechange = () => {
965
+ var g;
966
+ b("peerConnection.oniceconnectionstatechange => " + m.iceConnectionState);
967
+ const f = se(m.iceConnectionState);
968
+ f !== I.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
969
+ }, m.ontrack = (f) => {
970
+ var g;
971
+ b("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
972
+ }, await m.setRemoteDescription(U), b("set remote description OK");
973
+ const z = await m.createAnswer();
974
+ return b("create answer OK"), await m.setLocalDescription(z), b("set local description OK"), await y(R, z, T), b("start connection OK"), {
968
975
  /**
969
976
  * Method to send request to server to get clip or talk depend on you payload
970
977
  * @param payload
971
978
  */
972
979
  speak(f) {
973
- return g(M, A, f);
980
+ return A(R, T, f);
974
981
  },
975
982
  /**
976
983
  * Method to close RTC connection
977
984
  */
978
985
  async disconnect() {
979
986
  var f;
980
- if (M) {
981
- const m = ce(l.iceConnectionState);
982
- if (l) {
983
- if (m === E.New) {
984
- clearInterval(I);
987
+ if (R) {
988
+ const g = se(m.iceConnectionState);
989
+ if (m) {
990
+ if (g === I.New) {
991
+ clearInterval(B);
985
992
  return;
986
993
  }
987
- l.close(), l.oniceconnectionstatechange = null, l.onnegotiationneeded = null, l.onicecandidate = null, l.ontrack = null;
994
+ m.close(), m.oniceconnectionstatechange = null, m.onnegotiationneeded = null, m.onicecandidate = null, m.ontrack = null;
988
995
  }
989
996
  try {
990
- m === E.Connected && await $(M, A).catch((D) => {
997
+ g === I.Connected && await P(R, T).catch((S) => {
991
998
  });
992
- } catch (D) {
993
- B("Error on close stream connection", D);
999
+ } catch (S) {
1000
+ b("Error on close stream connection", S);
994
1001
  }
995
- (f = r.onAgentActivityStateChange) == null || f.call(r, V.Idle), clearInterval(I);
1002
+ (f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval(B);
996
1003
  }
997
1004
  },
998
1005
  /**
999
1006
  * Method to send data channel messages to the server
1000
1007
  */
1001
1008
  sendDataChannelMessage(f) {
1002
- var m, 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
1009
+ var g, S;
1010
+ if (!a || D.readyState !== "open") {
1011
+ b("Data channel is not ready for sending messages"), (g = r.onError) == null || g.call(r, new Error("Data channel is not ready for sending messages"), {
1012
+ streamId: R
1006
1013
  });
1007
1014
  return;
1008
1015
  }
1009
1016
  try {
1010
- 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
1017
+ D.send(f);
1018
+ } catch (Y) {
1019
+ b("Error sending data channel message", Y), (S = r.onError) == null || S.call(r, Y, {
1020
+ streamId: R
1014
1021
  });
1015
1022
  }
1016
1023
  },
1017
1024
  /**
1018
1025
  * Session identifier information, should be returned in the body of all streaming requests
1019
1026
  */
1020
- sessionId: A,
1027
+ sessionId: T,
1021
1028
  /**
1022
1029
  * Id of current RTC stream
1023
1030
  */
1024
- streamId: M,
1025
- streamType: p,
1026
- interruptAvailable: Z
1031
+ streamId: R,
1032
+ streamType: v,
1033
+ interruptAvailable: w
1027
1034
  };
1028
1035
  }
1029
1036
  function vt(e, t) {
@@ -1031,7 +1038,7 @@ function vt(e, t) {
1031
1038
  streamOptions: n
1032
1039
  } = t ?? {};
1033
1040
  return {
1034
- videoType: Pe(e.presenter.type),
1041
+ videoType: be(e.presenter.type),
1035
1042
  output_resolution: n == null ? void 0 : n.outputResolution,
1036
1043
  session_timeout: n == null ? void 0 : n.sessionTimeout,
1037
1044
  stream_warmup: n == null ? void 0 : n.streamWarmup,
@@ -1039,161 +1046,161 @@ function vt(e, t) {
1039
1046
  fluent: n == null ? void 0 : n.fluent
1040
1047
  };
1041
1048
  }
1042
- function kt(e, t, n, r, s) {
1043
- s === x.Fluent ? Dt(e, t, n, r, s) : Rt(e, t, n, r, s);
1049
+ function kt(e, t, n, r, o) {
1050
+ o === W.Fluent ? Dt(e, t, n, r, o) : Rt(e, t, n, r, o);
1044
1051
  }
1045
- function Dt(e, t, n, r, s) {
1046
- e === y.Start ? r.track("stream-session", {
1052
+ function Dt(e, t, n, r, o) {
1053
+ e === h.Start ? r.track("stream-session", {
1047
1054
  event: "start",
1048
- "stream-type": s
1049
- }) : e === y.Stop && r.track("stream-session", {
1055
+ "stream-type": o
1056
+ }) : e === h.Stop && r.track("stream-session", {
1050
1057
  event: "stop",
1051
1058
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1052
1059
  background: t.presenter.type === "clip" && t.presenter.background,
1053
- "stream-type": s,
1060
+ "stream-type": o,
1054
1061
  ...n
1055
1062
  });
1056
1063
  }
1057
1064
  function Ct(e, t, n, r) {
1058
- z.get() <= 0 || (e === y.Start ? n.linkTrack("agent-video", {
1065
+ N.get() <= 0 || (e === h.Start ? n.linkTrack("agent-video", {
1059
1066
  event: "start",
1060
- latency: z.get(!0),
1067
+ latency: N.get(!0),
1061
1068
  "stream-type": r
1062
- }, "start", [P.StreamVideoCreated]) : e === y.Stop && n.linkTrack("agent-video", {
1069
+ }, "start", [j.StreamVideoCreated]) : e === h.Stop && n.linkTrack("agent-video", {
1063
1070
  event: "stop",
1064
1071
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1065
1072
  background: t.presenter.type === "clip" && t.presenter.background,
1066
1073
  "stream-type": r
1067
- }, "done", [P.StreamVideoDone]));
1074
+ }, "done", [j.StreamVideoDone]));
1068
1075
  }
1069
- function Rt(e, t, n, r, s) {
1070
- z.get() <= 0 || (e === y.Start ? r.linkTrack("agent-video", {
1076
+ function Rt(e, t, n, r, o) {
1077
+ N.get() <= 0 || (e === h.Start ? r.linkTrack("agent-video", {
1071
1078
  event: "start",
1072
- latency: z.get(!0),
1073
- "stream-type": s
1074
- }, "start", [P.StreamVideoCreated]) : e === y.Stop && r.linkTrack("agent-video", {
1079
+ latency: N.get(!0),
1080
+ "stream-type": o
1081
+ }, "start", [j.StreamVideoCreated]) : e === h.Stop && r.linkTrack("agent-video", {
1075
1082
  event: "stop",
1076
1083
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1077
1084
  background: t.presenter.type === "clip" && t.presenter.background,
1078
- "stream-type": s,
1085
+ "stream-type": o,
1079
1086
  ...n
1080
- }, "done", [P.StreamVideoDone]));
1087
+ }, "done", [j.StreamVideoDone]));
1081
1088
  }
1082
- function It(e, t, n) {
1083
- return z.reset(), new Promise(async (r, s) => {
1089
+ function St(e, t, n) {
1090
+ return N.reset(), new Promise(async (r, o) => {
1084
1091
  try {
1085
1092
  const i = await yt(e.id, vt(e, t), {
1086
1093
  ...t,
1087
1094
  analytics: n,
1088
1095
  callbacks: {
1089
1096
  ...t.callbacks,
1090
- onConnectionStateChange: (o) => {
1091
- var d, c;
1092
- (c = (d = t.callbacks).onConnectionStateChange) == null || c.call(d, o), o === E.Connected && r(i);
1097
+ onConnectionStateChange: (c) => {
1098
+ var a, s;
1099
+ (s = (a = t.callbacks).onConnectionStateChange) == null || s.call(a, c), c === I.Connected && r(i);
1093
1100
  },
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);
1101
+ onVideoStateChange: (c, a) => {
1102
+ var s, u;
1103
+ (u = (s = t.callbacks).onVideoStateChange) == null || u.call(s, c), kt(c, e, a, n, i.streamType);
1097
1104
  },
1098
- 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);
1105
+ onAgentActivityStateChange: (c) => {
1106
+ var a, s;
1107
+ (s = (a = t.callbacks).onAgentActivityStateChange) == null || s.call(a, c), c === X.Talking ? re.update() : re.reset(), Ct(c === X.Talking ? h.Start : h.Stop, e, n, i.streamType);
1101
1108
  }
1102
1109
  }
1103
1110
  });
1104
1111
  } catch (i) {
1105
- s(i);
1112
+ o(i);
1106
1113
  }
1107
1114
  });
1108
1115
  }
1109
- async function St(e, t, n, r, s) {
1110
- var c, a, u, w;
1116
+ async function It(e, t, n, r, o) {
1117
+ var s, u, d, y;
1111
1118
  const {
1112
1119
  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)), {
1120
+ chatMode: c
1121
+ } = await pe(e, n, r, t.mode, t.persistentChat, o);
1122
+ if (c && c !== t.mode && (t.mode = c, (u = (s = t.callbacks).onModeChange) == null || u.call(s, c), c === M.TextOnly))
1123
+ return (y = (d = t.callbacks).onError) == null || y.call(d, new Ce(c)), {
1117
1124
  chat: i
1118
1125
  };
1119
- const d = await It(e, t, r);
1126
+ const a = await St(e, t, r);
1120
1127
  return {
1121
1128
  chat: i,
1122
- streamingManager: d
1129
+ streamingManager: a
1123
1130
  };
1124
1131
  }
1125
1132
  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 = {
1133
+ var U, K, T;
1134
+ let n = !0, r = null;
1135
+ const o = t.mixpanelKey || ze, i = t.wsURL || Le, c = t.baseURL || Z, a = {
1129
1136
  messages: [],
1130
- chatMode: t.mode || j.Functional
1131
- }, u = Xe({
1137
+ chatMode: t.mode || M.Functional
1138
+ }, s = Ve({
1132
1139
  token: o,
1133
1140
  agentId: e,
1134
1141
  isEnabled: t.enableAnalitics,
1135
1142
  distinctId: t.distinctId
1136
1143
  });
1137
- u.track("agent-sdk", {
1144
+ s.track("agent-sdk", {
1138
1145
  event: "init"
1139
1146
  });
1140
- const w = ge(t.auth, c, t.callbacks.onError), g = await w.getById(e);
1141
- u.enrich(Ke(g));
1147
+ const u = me(t.auth, c, t.callbacks.onError), d = await u.getById(e);
1148
+ s.enrich(Ue(d));
1142
1149
  const {
1143
- onMessage: $,
1144
- clearQueue: F
1145
- } = rt(u, a, t, g, () => {
1150
+ onMessage: y,
1151
+ clearQueue: A
1152
+ } = rt(s, a, t, d, () => {
1146
1153
  var l;
1147
1154
  return (l = a.socketManager) == null ? void 0 : l.disconnect();
1148
1155
  });
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;
1156
+ a.messages = Xe(t.initialMessages), (K = (U = t.callbacks).onNewMessage) == null || K.call(U, [...a.messages], "answer");
1157
+ const P = (l) => {
1158
+ r = l;
1152
1159
  };
1153
- u.track("agent-sdk", {
1160
+ s.track("agent-sdk", {
1154
1161
  event: "loaded",
1155
- ...Ue(g)
1162
+ ...We(d)
1156
1163
  });
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: $,
1164
+ async function x(l) {
1165
+ var _, $, B, k, E, C, L;
1166
+ ($ = (_ = t.callbacks).onConnectionStateChange) == null || $.call(_, I.Connecting), N.reset(), l && !n && (delete a.chat, (k = (B = t.callbacks).onNewMessage) == null || k.call(B, [...a.messages], "answer"));
1167
+ const w = t.mode === M.DirectPlayback ? Promise.resolve(void 0) : Ge(t.auth, i, {
1168
+ onMessage: y,
1162
1169
  onError: t.callbacks.onError
1163
- }), p = te(() => St(g, {
1170
+ }), m = te(() => It(d, {
1164
1171
  ...t,
1165
1172
  callbacks: {
1166
1173
  ...t.callbacks,
1167
- onVideoIdChange: W
1174
+ onVideoIdChange: P
1168
1175
  }
1169
- }, w, u, a.chat), {
1176
+ }, u, s, a.chat), {
1170
1177
  limit: 3,
1171
1178
  timeout: $e,
1172
1179
  timeoutErrorMessage: "Timeout initializing the stream",
1173
1180
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
1174
- shouldRetryFn: (m) => (m == null ? void 0 : m.message) !== "Could not connect" && m.status !== 429,
1181
+ shouldRetryFn: (z) => (z == null ? void 0 : z.message) !== "Could not connect" && z.status !== 429,
1175
1182
  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);
1183
+ }).catch((z) => {
1184
+ var J, f;
1185
+ throw R(M.Maintenance), (f = (J = t.callbacks).onConnectionStateChange) == null || f.call(J, I.Fail), z;
1186
+ }), [D, {
1187
+ streamingManager: v,
1188
+ chat: p
1189
+ }] = await Promise.all([w, m]);
1190
+ p && p.id !== ((E = a.chat) == null ? void 0 : E.id) && ((L = (C = t.callbacks).onNewChat) == null || L.call(C, p.id)), a.streamingManager = v, a.socketManager = D, a.chat = p, n = !1, R((p == null ? void 0 : p.chat_mode) ?? t.mode ?? M.Functional);
1184
1191
  }
1185
- 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);
1192
+ async function F() {
1193
+ var l, w, m, D;
1194
+ (l = a.socketManager) == null || l.disconnect(), await ((w = a.streamingManager) == null ? void 0 : w.disconnect()), delete a.streamingManager, delete a.socketManager, (D = (m = t.callbacks).onConnectionStateChange) == null || D.call(m, I.Disconnected);
1188
1195
  }
1189
- async function J(l) {
1190
- var h, p;
1191
- l !== a.chatMode && (u.track("agent-mode-change", {
1196
+ async function R(l) {
1197
+ var w, m;
1198
+ l !== a.chatMode && (s.track("agent-mode-change", {
1192
1199
  mode: l
1193
- }), a.chatMode = l, a.chatMode !== j.Functional && await N(), (p = (h = t.callbacks).onModeChange) == null || p.call(h, l));
1200
+ }), a.chatMode = l, a.chatMode !== M.Functional && await F(), (m = (w = t.callbacks).onModeChange) == null || m.call(w, l));
1194
1201
  }
1195
1202
  return {
1196
- agent: g,
1203
+ agent: d,
1197
1204
  getStreamType: () => {
1198
1205
  var l;
1199
1206
  return (l = a.streamingManager) == null ? void 0 : l.streamType;
@@ -1202,192 +1209,191 @@ async function Et(e, t) {
1202
1209
  var l;
1203
1210
  return ((l = a.streamingManager) == null ? void 0 : l.interruptAvailable) ?? !1;
1204
1211
  },
1205
- starterMessages: ((Z = g.knowledge) == null ? void 0 : Z.starter_message) || [],
1206
- getSTTToken: () => w.getSTTToken(g.id),
1207
- changeMode: J,
1208
- enrichAnalytics: u.enrich,
1212
+ starterMessages: ((T = d.knowledge) == null ? void 0 : T.starter_message) || [],
1213
+ getSTTToken: () => u.getSTTToken(d.id),
1214
+ changeMode: R,
1215
+ enrichAnalytics: s.enrich,
1209
1216
  async connect() {
1210
1217
  var l;
1211
- await M(!0), u.track("agent-chat", {
1218
+ await x(!0), s.track("agent-chat", {
1212
1219
  event: "connect",
1213
1220
  chatId: (l = a.chat) == null ? void 0 : l.id,
1214
- agentId: g.id,
1221
+ agentId: d.id,
1215
1222
  mode: a.chatMode
1216
1223
  });
1217
1224
  },
1218
1225
  async reconnect() {
1219
1226
  var l;
1220
- await N(), await M(!1), u.track("agent-chat", {
1227
+ await F(), await x(!1), s.track("agent-chat", {
1221
1228
  event: "reconnect",
1222
1229
  chatId: (l = a.chat) == null ? void 0 : l.id,
1223
- agentId: g.id,
1230
+ agentId: d.id,
1224
1231
  mode: a.chatMode
1225
1232
  });
1226
1233
  },
1227
1234
  async disconnect() {
1228
1235
  var l;
1229
- await N(), u.track("agent-chat", {
1236
+ await F(), s.track("agent-chat", {
1230
1237
  event: "disconnect",
1231
1238
  chatId: (l = a.chat) == null ? void 0 : l.id,
1232
- agentId: g.id,
1239
+ agentId: d.id,
1233
1240
  mode: a.chatMode
1234
1241
  });
1235
1242
  },
1236
1243
  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");
1244
+ var v, p, _, $, B;
1245
+ const w = () => {
1246
+ if (ue(t.mode))
1247
+ throw new H(`${t.mode} is enabled, chat is disabled`);
1241
1248
  if (l.length >= 800)
1242
- throw new K("Message cannot be more than 800 characters");
1249
+ throw new H("Message cannot be more than 800 characters");
1243
1250
  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)) {
1251
+ throw new H("Message cannot be empty");
1252
+ if (a.chatMode === M.Maintenance)
1253
+ throw new H("Chat is in maintenance mode");
1254
+ if (![M.TextOnly, M.Playground].includes(a.chatMode)) {
1248
1255
  if (!a.streamingManager)
1249
- throw new K("Streaming manager is not initialized");
1256
+ throw new H("Streaming manager is not initialized");
1250
1257
  if (!a.chat)
1251
- throw new K("Chat is not initialized");
1258
+ throw new H("Chat is not initialized");
1252
1259
  }
1253
- }, p = async () => {
1254
- var v, C;
1260
+ }, m = async () => {
1261
+ var k, E;
1255
1262
  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);
1263
+ const C = await pe(d, u, s, a.chatMode, t.persistentChat);
1264
+ if (!C.chat)
1265
+ throw new De(a.chatMode, !!t.persistentChat);
1266
+ a.chat = C.chat, (E = (k = t.callbacks).onNewChat) == null || E.call(k, a.chat.id);
1260
1267
  }
1261
1268
  return a.chat.id;
1262
- }, T = async (v, C) => te(() => {
1263
- var R, f;
1264
- return w.chat(g.id, C, {
1269
+ }, D = async (k, E) => te(() => {
1270
+ var C, L;
1271
+ return u.chat(d.id, E, {
1265
1272
  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)
1273
+ streamId: (C = a.streamingManager) == null ? void 0 : C.streamId,
1274
+ sessionId: (L = a.streamingManager) == null ? void 0 : L.sessionId,
1275
+ messages: k.map(({
1276
+ matches: z,
1277
+ ...J
1278
+ }) => J)
1272
1279
  }, {
1273
- ...pe(a.chatMode),
1280
+ ...we(a.chatMode),
1274
1281
  skipErrorHandler: !0
1275
1282
  });
1276
1283
  }, {
1277
1284
  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;
1285
+ shouldRetryFn: (C) => {
1286
+ var J, f, g, S;
1287
+ const L = (J = C == null ? void 0 : C.message) == null ? void 0 : J.includes("missing or invalid session_id");
1288
+ return !((f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("Stream Error")) && !L ? ((S = (g = t.callbacks).onError) == null || S.call(g, C), !1) : !0;
1282
1289
  },
1283
1290
  onRetry: async () => {
1284
- await N(), await M(!1);
1291
+ await F(), await x(!1);
1285
1292
  }
1286
1293
  });
1287
1294
  try {
1288
- F(), h(), a.messages.push({
1289
- id: q(),
1295
+ A(), w(), a.messages.push({
1296
+ id: V(),
1290
1297
  role: "user",
1291
1298
  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);
1299
+ created_at: new Date(N.update()).toISOString()
1300
+ }), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...a.messages], "user");
1301
+ const k = await m(), E = await D([...a.messages], k);
1295
1302
  return a.messages.push({
1296
- id: q(),
1303
+ id: V(),
1297
1304
  role: "assistant",
1298
- content: C.result || "",
1305
+ content: E.result || "",
1299
1306
  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", {
1307
+ context: E.context,
1308
+ matches: E.matches
1309
+ }), s.track("agent-message-send", {
1304
1310
  event: "success",
1305
1311
  mode: a.chatMode,
1306
1312
  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),
1313
+ }), E.result && (($ = (_ = t.callbacks).onNewMessage) == null || $.call(_, [...a.messages], "answer"), s.track("agent-message-received", {
1314
+ latency: N.get(!0),
1309
1315
  mode: a.chatMode,
1310
1316
  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", {
1317
+ })), E;
1318
+ } catch (k) {
1319
+ throw ((B = a.messages[a.messages.length - 1]) == null ? void 0 : B.role) === "assistant" && a.messages.pop(), s.track("agent-message-send", {
1314
1320
  event: "error",
1315
1321
  mode: a.chatMode,
1316
1322
  messages: a.messages.length
1317
- }), v;
1323
+ }), k;
1318
1324
  }
1319
1325
  },
1320
- rate(l, h, p) {
1321
- var k, I, S, _;
1322
- const T = a.messages.find((v) => v.id === l);
1326
+ rate(l, w, m) {
1327
+ var p, _, $, B;
1328
+ const D = a.messages.find((k) => k.id === l);
1323
1329
  if (a.chat) {
1324
- if (!T)
1330
+ if (!D)
1325
1331
  throw new Error("Message not found");
1326
1332
  } else
1327
1333
  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) ?? "",
1334
+ const v = ((p = D.matches) == null ? void 0 : p.map((k) => [k.document_id, k.id])) ?? [];
1335
+ return s.track("agent-rate", {
1336
+ event: m ? "update" : "create",
1337
+ thumb: w === 1 ? "up" : "down",
1338
+ knowledge_id: ((_ = d.knowledge) == null ? void 0 : _.id) ?? "",
1333
1339
  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) ?? "",
1340
+ matches: v,
1341
+ score: w
1342
+ }), m ? u.updateRating(d.id, a.chat.id, m, {
1343
+ knowledge_id: (($ = d.knowledge) == null ? void 0 : $.id) ?? "",
1338
1344
  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) ?? "",
1345
+ matches: v,
1346
+ score: w
1347
+ }) : u.createRating(d.id, a.chat.id, {
1348
+ knowledge_id: ((B = d.knowledge) == null ? void 0 : B.id) ?? "",
1343
1349
  message_id: l,
1344
- matches: b,
1345
- score: h
1350
+ matches: v,
1351
+ score: w
1346
1352
  });
1347
1353
  },
1348
1354
  deleteRate(l) {
1349
- var h;
1355
+ var w;
1350
1356
  if (!a.chat)
1351
1357
  throw new Error("Chat is not initialized");
1352
- return u.track("agent-rate-delete", {
1358
+ return s.track("agent-rate-delete", {
1353
1359
  type: "text",
1354
- chat_id: (h = a.chat) == null ? void 0 : h.id,
1360
+ chat_id: (w = a.chat) == null ? void 0 : w.id,
1355
1361
  id: l,
1356
1362
  mode: a.chatMode
1357
- }), w.deleteRating(g.id, a.chat.id, l);
1363
+ }), u.deleteRating(d.id, a.chat.id, l);
1358
1364
  },
1359
1365
  async speak(l) {
1360
- var b, k, I, S, _;
1361
- function h() {
1366
+ var v, p, _;
1367
+ function w() {
1362
1368
  if (typeof l == "string") {
1363
- if (!g.presenter.voice)
1369
+ if (!d.presenter.voice)
1364
1370
  throw new Error("Presenter voice is not initialized");
1365
1371
  return {
1366
1372
  type: "text",
1367
- provider: g.presenter.voice,
1373
+ provider: d.presenter.voice,
1368
1374
  input: l,
1369
1375
  ssml: !1
1370
1376
  };
1371
1377
  }
1372
1378
  if (l.type === "text" && !l.provider) {
1373
- if (!g.presenter.voice)
1379
+ if (!d.presenter.voice)
1374
1380
  throw new Error("Presenter voice is not initialized");
1375
1381
  return {
1376
1382
  type: "text",
1377
- provider: g.presenter.voice,
1383
+ provider: d.presenter.voice,
1378
1384
  input: l.input,
1379
1385
  ssml: l.ssml
1380
1386
  };
1381
1387
  }
1382
1388
  return l;
1383
1389
  }
1384
- const p = h();
1385
- if (u.track("agent-speak", p), z.update(), a.messages && p.type === "text" && (a.messages.push({
1386
- id: q(),
1390
+ const m = w();
1391
+ if (s.track("agent-speak", m), N.update(), a.messages && m.type === "text" && (a.messages.push({
1392
+ id: V(),
1387
1393
  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))
1394
+ content: m.input,
1395
+ created_at: new Date(N.get(!0)).toISOString()
1396
+ }), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...a.messages], "answer")), Ne(a.chatMode))
1391
1397
  return {
1392
1398
  duration: 0,
1393
1399
  video_id: "",
@@ -1395,73 +1401,63 @@ async function Et(e, t) {
1395
1401
  };
1396
1402
  if (!a.streamingManager)
1397
1403
  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
- }
1404
+ return a.streamingManager.speak({
1405
+ script: m,
1406
+ metadata: {
1407
+ chat_id: (_ = a.chat) == null ? void 0 : _.id,
1408
+ agent_id: d.id
1409
+ }
1410
+ });
1411
1411
  },
1412
1412
  async interrupt({
1413
1413
  type: l
1414
1414
  }) {
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", {
1415
+ var m, D, v, p, _;
1416
+ Ye(a.streamingManager, (m = a.streamingManager) == null ? void 0 : m.streamType, r);
1417
+ const w = a.messages[a.messages.length - 1];
1418
+ s.track("agent-video-interrupt", {
1418
1419
  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,
1420
+ stream_id: (D = a.streamingManager) == null ? void 0 : D.streamId,
1421
+ agent_id: d.id,
1422
+ owner_id: d.owner_id,
1422
1423
  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);
1424
+ message_duration_to_interrupt: N.get(!0),
1425
+ chat_id: (v = a.chat) == null ? void 0 : v.id,
1426
+ mode: a.chatMode
1427
+ }), w.interrupted = !0, (_ = (p = t.callbacks).onNewMessage) == null || _.call(p, [...a.messages], "answer"), Qe(a.streamingManager, r);
1432
1428
  }
1433
1429
  };
1434
1430
  }
1435
1431
  function Mt(e, t, n) {
1436
1432
  const {
1437
1433
  getById: r
1438
- } = ge(t, n || Q);
1434
+ } = me(t, n || Z);
1439
1435
  return r(e);
1440
1436
  }
1441
1437
  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,
1438
+ X as AgentActivityState,
1439
+ _e as AgentStatus,
1440
+ De as ChatCreationFailed,
1441
+ M as ChatMode,
1442
+ Ce as ChatModeDowngraded,
1443
+ q as ChatProgress,
1444
+ I as ConnectionState,
1445
+ O as ConnectivityState,
1450
1446
  je as DocumentType,
1451
- be as KnowledgeType,
1452
- _e as PlanGroup,
1447
+ Te as KnowledgeType,
1448
+ Ie as PlanGroup,
1453
1449
  Ae as Providers,
1454
- Me as RateState,
1455
- P as StreamEvents,
1456
- x as StreamType,
1457
- y as StreamingState,
1458
- Te as Subject,
1450
+ Ee as RateState,
1451
+ j as StreamEvents,
1452
+ W as StreamType,
1453
+ h as StreamingState,
1454
+ Me as Subject,
1459
1455
  Se as UserPlan,
1460
- K as ValidationError,
1461
- le as VideoType,
1462
- Be as VoiceAccess,
1463
- Ie as WsError,
1456
+ H as ValidationError,
1457
+ ce as VideoType,
1458
+ Pe as VoiceAccess,
1459
+ Re as WsError,
1464
1460
  Et as createAgentManager,
1465
1461
  Mt as getAgent,
1466
- Pe as mapVideoType
1462
+ be as mapVideoType
1467
1463
  };