@d-id/client-sdk 1.0.19-beta.151 → 1.0.19-beta.153

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
@@ -9,10 +9,10 @@ const ue = (e) => {
9
9
  throw new Error(`Unknown video type: ${e}`);
10
10
  }
11
11
  };
12
- var j = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(j || {}), W = /* @__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.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(W || {}), D = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(D || {}), fe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(fe || {}), ge = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ge || {});
12
+ var j = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(j || {}), K = /* @__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.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(K || {}), D = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(D || {}), fe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(fe || {}), ge = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ge || {});
13
13
  const H = "https://api.d-id.com", he = "wss://notifications.d-id.com", we = "79f81a83a67430be2bc0fd61042b8faa";
14
- async function G(e, t) {
15
- const i = {
14
+ async function Q(e, t) {
15
+ const s = {
16
16
  limit: (t == null ? void 0 : t.limit) ?? 3,
17
17
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
18
18
  timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
@@ -21,31 +21,31 @@ async function G(e, t) {
21
21
  return !0;
22
22
  }
23
23
  };
24
- let a;
25
- for (let n = 1; n <= i.limit; n++)
24
+ let r;
25
+ for (let n = 1; n <= s.limit; n++)
26
26
  try {
27
- if (!i.timeout)
27
+ if (!s.timeout)
28
28
  return await e();
29
- let s;
30
- const r = new Promise((d, f) => {
29
+ let i;
30
+ const a = new Promise((d, f) => {
31
31
  e().then((m) => {
32
- clearTimeout(s), d(m);
32
+ clearTimeout(i), d(m);
33
33
  }).catch((m) => {
34
- clearTimeout(s), f(m);
34
+ clearTimeout(i), f(m);
35
35
  });
36
36
  }), o = new Promise((d, f) => {
37
- s = setTimeout(() => f(new Error(i.timeoutErrorMessage)), i.timeout);
37
+ i = setTimeout(() => f(new Error(s.timeoutErrorMessage)), s.timeout);
38
38
  });
39
- return await Promise.race([r, o]);
40
- } catch (s) {
41
- if (a = s, !i.shouldRetryFn(s) || n >= i.limit)
42
- throw s;
43
- i.delayMs > 0 && await new Promise((r) => setTimeout(r, i.delayMs));
39
+ return await Promise.race([a, o]);
40
+ } catch (i) {
41
+ if (r = i, !s.shouldRetryFn(i) || n >= s.limit)
42
+ throw i;
43
+ s.delayMs > 0 && await new Promise((a) => setTimeout(a, s.delayMs));
44
44
  }
45
- throw a;
45
+ throw r;
46
46
  }
47
47
  const V = () => Math.random().toString(16).slice(2);
48
- function Q() {
48
+ function G() {
49
49
  let e = window.localStorage.getItem("did_external_key_id");
50
50
  return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
51
51
  }
@@ -56,21 +56,21 @@ function ee(e) {
56
56
  if (e.type === "basic")
57
57
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
58
58
  if (e.type === "key")
59
- return `Client-Key ${e.clientKey}.${Q()}_${pe}`;
59
+ return `Client-Key ${e.clientKey}.${G()}_${pe}`;
60
60
  throw new Error(`Unknown auth type: ${e}`);
61
61
  }
62
- const ye = (e) => G(e, {
62
+ const ye = (e) => Q(e, {
63
63
  limit: 3,
64
64
  delayMs: 1e3,
65
65
  timeout: 0,
66
66
  shouldRetryFn: (t) => t.status === 429
67
67
  });
68
- function q(e, t = H, i) {
69
- const a = async (n, s) => {
68
+ function q(e, t = H, s) {
69
+ const r = async (n, i) => {
70
70
  const {
71
- skipErrorHandler: r,
71
+ skipErrorHandler: a,
72
72
  ...o
73
- } = s || {}, l = await ye(() => fetch(t + (n != null && n.startsWith("/") ? n : `/${n}`), {
73
+ } = i || {}, l = await ye(() => fetch(t + (n != null && n.startsWith("/") ? n : `/${n}`), {
74
74
  ...o,
75
75
  headers: {
76
76
  ...o.headers,
@@ -80,7 +80,7 @@ function q(e, t = H, i) {
80
80
  }));
81
81
  if (!l.ok) {
82
82
  let d = await l.text().catch(() => "Failed to fetch");
83
- throw i && !r && i(new Error(d), {
83
+ throw s && !a && s(new Error(d), {
84
84
  url: n,
85
85
  options: o,
86
86
  headers: l.headers
@@ -89,88 +89,88 @@ function q(e, t = H, i) {
89
89
  return l.json();
90
90
  };
91
91
  return {
92
- get(n, s) {
93
- return a(n, {
94
- ...s,
92
+ get(n, i) {
93
+ return r(n, {
94
+ ...i,
95
95
  method: "GET"
96
96
  });
97
97
  },
98
- post(n, s, r) {
99
- return a(n, {
100
- ...r,
101
- body: JSON.stringify(s),
98
+ post(n, i, a) {
99
+ return r(n, {
100
+ ...a,
101
+ body: JSON.stringify(i),
102
102
  method: "POST"
103
103
  });
104
104
  },
105
- delete(n, s, r) {
106
- return a(n, {
107
- ...r,
108
- body: JSON.stringify(s),
105
+ delete(n, i, a) {
106
+ return r(n, {
107
+ ...a,
108
+ body: JSON.stringify(i),
109
109
  method: "DELETE"
110
110
  });
111
111
  },
112
- patch(n, s, r) {
113
- return a(n, {
114
- ...r,
115
- body: JSON.stringify(s),
112
+ patch(n, i, a) {
113
+ return r(n, {
114
+ ...a,
115
+ body: JSON.stringify(i),
116
116
  method: "PATCH"
117
117
  });
118
118
  }
119
119
  };
120
120
  }
121
- function te(e, t = H, i) {
122
- const a = q(e, `${t}/agents`, i);
121
+ function te(e, t = H, s) {
122
+ const r = q(e, `${t}/agents`, s);
123
123
  return {
124
- create(n, s) {
125
- return a.post("/", n, s);
124
+ create(n, i) {
125
+ return r.post("/", n, i);
126
126
  },
127
- getAgents(n, s) {
128
- return a.get(`/${n ? `?tag=${n}` : ""}`, s).then((r) => r ?? []);
127
+ getAgents(n, i) {
128
+ return r.get(`/${n ? `?tag=${n}` : ""}`, i).then((a) => a ?? []);
129
129
  },
130
- getById(n, s) {
131
- return a.get(`/${n}`, s);
130
+ getById(n, i) {
131
+ return r.get(`/${n}`, i);
132
132
  },
133
- delete(n, s) {
134
- return a.delete(`/${n}`, void 0, s);
133
+ delete(n, i) {
134
+ return r.delete(`/${n}`, void 0, i);
135
135
  },
136
- update(n, s, r) {
137
- return a.patch(`/${n}`, s, r);
136
+ update(n, i, a) {
137
+ return r.patch(`/${n}`, i, a);
138
138
  },
139
- newChat(n, s, r) {
140
- return a.post(`/${n}/chat`, s, r);
139
+ newChat(n, i, a) {
140
+ return r.post(`/${n}/chat`, i, a);
141
141
  },
142
- chat(n, s, r, o) {
143
- return a.post(`/${n}/chat/${s}`, r, o);
142
+ chat(n, i, a, o) {
143
+ return r.post(`/${n}/chat/${i}`, a, o);
144
144
  },
145
- createRating(n, s, r, o) {
146
- return a.post(`/${n}/chat/${s}/ratings`, r, o);
145
+ createRating(n, i, a, o) {
146
+ return r.post(`/${n}/chat/${i}/ratings`, a, o);
147
147
  },
148
- updateRating(n, s, r, o, l) {
149
- return a.patch(`/${n}/chat/${s}/ratings/${r}`, o, l);
148
+ updateRating(n, i, a, o, l) {
149
+ return r.patch(`/${n}/chat/${i}/ratings/${a}`, o, l);
150
150
  },
151
- deleteRating(n, s, r, o) {
152
- return a.delete(`/${n}/chat/${s}/ratings/${r}`, o);
151
+ deleteRating(n, i, a, o) {
152
+ return r.delete(`/${n}/chat/${i}/ratings/${a}`, o);
153
153
  },
154
- getSTTToken(n, s) {
155
- return a.get(`/${n}/stt-token`, s);
154
+ getSTTToken(n, i) {
155
+ return r.get(`/${n}/stt-token`, i);
156
156
  }
157
157
  };
158
158
  }
159
159
  const ve = (e) => new Promise((t) => setTimeout(t, e));
160
160
  function ke(e) {
161
- return new Promise((t, i) => {
161
+ return new Promise((t, s) => {
162
162
  const {
163
- callbacks: a,
163
+ callbacks: r,
164
164
  host: n,
165
- auth: s
165
+ auth: i
166
166
  } = e, {
167
- onMessage: r = null,
167
+ onMessage: a = null,
168
168
  onOpen: o = null,
169
169
  onClose: l = null,
170
170
  onError: d = null
171
- } = a || {}, f = new WebSocket(`${n}?authorization=${ee(s)}`);
172
- f.onmessage = r, f.onclose = l, f.onerror = (m) => {
173
- console.error(m), d == null || d("Websocket failed to connect", m), i(m);
171
+ } = r || {}, f = new WebSocket(`${n}?authorization=${ee(i)}`);
172
+ f.onmessage = a, f.onclose = l, f.onerror = (m) => {
173
+ console.error(m), d == null || d("Websocket failed to connect", m), s(m);
174
174
  }, f.onopen = (m) => {
175
175
  o == null || o(m), t(f);
176
176
  };
@@ -180,213 +180,213 @@ async function Ce(e) {
180
180
  const {
181
181
  retries: t = 1
182
182
  } = e;
183
- let i = null;
184
- for (let a = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; a++)
183
+ let s = null;
184
+ for (let r = 0; (s == null ? void 0 : s.readyState) !== WebSocket.OPEN; r++)
185
185
  try {
186
- i = await ke(e);
186
+ s = await ke(e);
187
187
  } catch (n) {
188
- if (a === t)
188
+ if (r === t)
189
189
  throw n;
190
- await ve(a * 500);
190
+ await ve(r * 500);
191
191
  }
192
- return i;
192
+ return s;
193
193
  }
194
- async function Re(e, t, i) {
195
- const a = i != null && i.onMessage ? [i.onMessage] : [], n = await Ce({
194
+ async function Re(e, t, s) {
195
+ const r = s != null && s.onMessage ? [s.onMessage] : [], n = await Ce({
196
196
  auth: e,
197
197
  host: t,
198
198
  callbacks: {
199
- onError: i == null ? void 0 : i.onError,
200
- onMessage: (s) => {
201
- const r = JSON.parse(s.data);
202
- a.forEach((o) => o(r.event, r));
199
+ onError: s == null ? void 0 : s.onError,
200
+ onMessage: (i) => {
201
+ const a = JSON.parse(i.data);
202
+ r.forEach((o) => o(a.event, a));
203
203
  }
204
204
  }
205
205
  });
206
206
  return {
207
207
  socket: n,
208
208
  disconnect: () => n.close(),
209
- subscribeToEvents: (s) => a.push(s)
209
+ subscribeToEvents: (i) => r.push(i)
210
210
  };
211
211
  }
212
- const Se = "X-Playground-Chat";
213
- function De(e, t, i, a) {
214
- const n = q(e, `${t}/agents/${i}`, a);
212
+ const De = "X-Playground-Chat";
213
+ function Se(e, t, s, r) {
214
+ const n = q(e, `${t}/agents/${s}`, r);
215
215
  return {
216
- createStream(s) {
216
+ createStream(i) {
217
217
  return n.post("/streams", {
218
- output_resolution: s.output_resolution,
219
- compatibility_mode: s.compatibility_mode,
220
- stream_warmup: s.stream_warmup,
221
- session_timeout: s.session_timeout,
222
- stream_greeting: s.stream_greeting
218
+ output_resolution: i.output_resolution,
219
+ compatibility_mode: i.compatibility_mode,
220
+ stream_warmup: i.stream_warmup,
221
+ session_timeout: i.session_timeout,
222
+ stream_greeting: i.stream_greeting
223
223
  });
224
224
  },
225
- startConnection(s, r, o) {
226
- return n.post(`/streams/${s}/sdp`, {
225
+ startConnection(i, a, o) {
226
+ return n.post(`/streams/${i}/sdp`, {
227
227
  session_id: o,
228
- answer: r
228
+ answer: a
229
229
  });
230
230
  },
231
- addIceCandidate(s, r, o) {
232
- return n.post(`/streams/${s}/ice`, {
231
+ addIceCandidate(i, a, o) {
232
+ return n.post(`/streams/${i}/ice`, {
233
233
  session_id: o,
234
- ...r
234
+ ...a
235
235
  });
236
236
  },
237
- sendStreamRequest(s, r, o) {
238
- return n.post(`/streams/${s}`, {
239
- session_id: r,
237
+ sendStreamRequest(i, a, o) {
238
+ return n.post(`/streams/${i}`, {
239
+ session_id: a,
240
240
  ...o
241
241
  });
242
242
  },
243
- close(s, r) {
244
- return n.delete(`/streams/${s}`, {
245
- session_id: r
243
+ close(i, a) {
244
+ return n.delete(`/streams/${i}`, {
245
+ session_id: a
246
246
  });
247
247
  }
248
248
  };
249
249
  }
250
- function _e(e, t, i, a) {
251
- const n = q(e, `${t}/agents/${i}`, a);
250
+ function _e(e, t, s, r) {
251
+ const n = q(e, `${t}/agents/${s}`, r);
252
252
  return {
253
- createStream(s, r) {
253
+ createStream(i, a) {
254
254
  return n.post("/streams", {
255
- driver_url: s.driver_url,
256
- face: s.face,
257
- config: s.config,
258
- output_resolution: s.output_resolution,
259
- compatibility_mode: s.compatibility_mode,
260
- stream_warmup: s.stream_warmup,
261
- session_timeout: s.session_timeout,
262
- stream_greeting: s.stream_greeting
263
- }, r);
255
+ driver_url: i.driver_url,
256
+ face: i.face,
257
+ config: i.config,
258
+ output_resolution: i.output_resolution,
259
+ compatibility_mode: i.compatibility_mode,
260
+ stream_warmup: i.stream_warmup,
261
+ session_timeout: i.session_timeout,
262
+ stream_greeting: i.stream_greeting
263
+ }, a);
264
264
  },
265
- startConnection(s, r, o, l) {
266
- return n.post(`/streams/${s}/sdp`, {
265
+ startConnection(i, a, o, l) {
266
+ return n.post(`/streams/${i}/sdp`, {
267
267
  session_id: o,
268
- answer: r
268
+ answer: a
269
269
  }, l);
270
270
  },
271
- addIceCandidate(s, r, o, l) {
272
- return n.post(`/streams/${s}/ice`, {
271
+ addIceCandidate(i, a, o, l) {
272
+ return n.post(`/streams/${i}/ice`, {
273
273
  session_id: o,
274
- ...r
274
+ ...a
275
275
  }, l);
276
276
  },
277
- sendStreamRequest(s, r, o, l) {
278
- return n.post(`/streams/${s}`, {
279
- session_id: r,
277
+ sendStreamRequest(i, a, o, l) {
278
+ return n.post(`/streams/${i}`, {
279
+ session_id: a,
280
280
  ...o
281
281
  }, l);
282
282
  },
283
- close(s, r, o) {
284
- return n.delete(`/streams/${s}`, {
285
- session_id: r
283
+ close(i, a, o) {
284
+ return n.delete(`/streams/${i}`, {
285
+ session_id: a
286
286
  }, o);
287
287
  }
288
288
  };
289
289
  }
290
- function Me(e, t, i) {
291
- const a = (t.timestamp - e.timestamp) / 1e3;
290
+ function Me(e, t, s) {
291
+ const r = (t.timestamp - e.timestamp) / 1e3;
292
292
  return {
293
- duration: a,
293
+ duration: r,
294
294
  bytesReceived: t.bytesReceived - e.bytesReceived,
295
- bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / a),
295
+ bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / r),
296
296
  packetsReceived: t.packetsReceived - e.packetsReceived,
297
297
  packetsLost: t.packetsLost - e.packetsLost,
298
298
  framesDropped: t.framesDropped - e.framesDropped,
299
299
  framesDecoded: t.framesDecoded - e.framesDecoded,
300
300
  jitter: t.jitter,
301
- jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / a,
301
+ jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / r,
302
302
  framesPerSecond: t.framesPerSecond,
303
303
  freezeCount: t.freezeCount - e.freezeCount,
304
304
  freezeDuration: t.freezeDuration - e.freezeDuration,
305
- lowFpsCount: i
305
+ lowFpsCount: s
306
306
  };
307
307
  }
308
308
  function be(e) {
309
309
  return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
310
310
  const {
311
- timestamp: i,
312
- ...a
311
+ timestamp: s,
312
+ ...r
313
313
  } = t, n = [];
314
314
  return t.freezeCount > 0 && n.push("freeze"), t.framesPerSecond < 21 && n.push("low fps"), t.framesDropped > 0 && n.push("frames dropped"), t.packetsLost > 0 && n.push("packet loss"), {
315
- ...a,
315
+ ...r,
316
316
  causes: n
317
317
  };
318
318
  });
319
319
  }
320
320
  function Ee(e) {
321
321
  let t = "";
322
- for (const i of e.values())
323
- if (i && i.type === "codec" && i.mimeType.startsWith("video") && (t = i.mimeType.split("/")[1]), i && i.type === "inbound-rtp" && i.kind === "video")
322
+ for (const s of e.values())
323
+ if (s && s.type === "codec" && s.mimeType.startsWith("video") && (t = s.mimeType.split("/")[1]), s && s.type === "inbound-rtp" && s.kind === "video")
324
324
  return {
325
325
  codec: t,
326
- timestamp: i.timestamp,
327
- bytesReceived: i.bytesReceived,
328
- packetsReceived: i.packetsReceived,
329
- packetsLost: i.packetsLost,
330
- framesDropped: i.framesDropped,
331
- framesDecoded: i.framesDecoded,
332
- jitter: i.jitter,
333
- jitterBufferDelay: i.jitterBufferDelay,
334
- frameWidth: i.frameWidth,
335
- frameHeight: i.frameHeight,
336
- framesPerSecond: i.framesPerSecond,
337
- freezeCount: i.freezeCount,
338
- freezeDuration: i.totalFreezesDuration
326
+ timestamp: s.timestamp,
327
+ bytesReceived: s.bytesReceived,
328
+ packetsReceived: s.packetsReceived,
329
+ packetsLost: s.packetsLost,
330
+ framesDropped: s.framesDropped,
331
+ framesDecoded: s.framesDecoded,
332
+ jitter: s.jitter,
333
+ jitterBufferDelay: s.jitterBufferDelay,
334
+ frameWidth: s.frameWidth,
335
+ frameHeight: s.frameHeight,
336
+ framesPerSecond: s.framesPerSecond,
337
+ freezeCount: s.freezeCount,
338
+ freezeDuration: s.totalFreezesDuration
339
339
  };
340
340
  return {};
341
341
  }
342
- function Ie(e, t, i) {
343
- const a = e.map((r, o) => o === 0 ? i ? {
344
- timestamp: r.timestamp,
342
+ function Ie(e, t, s) {
343
+ const r = e.map((a, o) => o === 0 ? s ? {
344
+ timestamp: a.timestamp,
345
345
  duration: 0,
346
- bytesReceived: r.bytesReceived - i.bytesReceived,
347
- bitrate: (r.bytesReceived - i.bytesReceived) * 8 / (t / 1e3),
348
- packetsReceived: r.packetsReceived - i.packetsReceived,
349
- packetsLost: r.packetsLost - i.packetsLost,
350
- framesDropped: r.framesDropped - i.framesDropped,
351
- framesDecoded: r.framesDecoded - i.framesDecoded,
352
- jitter: r.jitter,
353
- jitterBufferDelay: r.jitterBufferDelay - i.jitterBufferDelay,
354
- framesPerSecond: r.framesPerSecond,
355
- freezeCount: r.freezeCount - i.freezeCount,
356
- freezeDuration: r.freezeDuration - i.freezeDuration
346
+ bytesReceived: a.bytesReceived - s.bytesReceived,
347
+ bitrate: (a.bytesReceived - s.bytesReceived) * 8 / (t / 1e3),
348
+ packetsReceived: a.packetsReceived - s.packetsReceived,
349
+ packetsLost: a.packetsLost - s.packetsLost,
350
+ framesDropped: a.framesDropped - s.framesDropped,
351
+ framesDecoded: a.framesDecoded - s.framesDecoded,
352
+ jitter: a.jitter,
353
+ jitterBufferDelay: a.jitterBufferDelay - s.jitterBufferDelay,
354
+ framesPerSecond: a.framesPerSecond,
355
+ freezeCount: a.freezeCount - s.freezeCount,
356
+ freezeDuration: a.freezeDuration - s.freezeDuration
357
357
  } : {
358
- timestamp: r.timestamp,
358
+ timestamp: a.timestamp,
359
359
  duration: 0,
360
- bytesReceived: r.bytesReceived,
361
- bitrate: r.bytesReceived * 8 / (t / 1e3),
362
- packetsReceived: r.packetsReceived,
363
- packetsLost: r.packetsLost,
364
- framesDropped: r.framesDropped,
365
- framesDecoded: r.framesDecoded,
366
- jitter: r.jitter,
367
- jitterBufferDelay: r.jitterBufferDelay,
368
- framesPerSecond: r.framesPerSecond,
369
- freezeCount: r.freezeCount,
370
- freezeDuration: r.freezeDuration
360
+ bytesReceived: a.bytesReceived,
361
+ bitrate: a.bytesReceived * 8 / (t / 1e3),
362
+ packetsReceived: a.packetsReceived,
363
+ packetsLost: a.packetsLost,
364
+ framesDropped: a.framesDropped,
365
+ framesDecoded: a.framesDecoded,
366
+ jitter: a.jitter,
367
+ jitterBufferDelay: a.jitterBufferDelay,
368
+ framesPerSecond: a.framesPerSecond,
369
+ freezeCount: a.freezeCount,
370
+ freezeDuration: a.freezeDuration
371
371
  } : {
372
- timestamp: r.timestamp,
372
+ timestamp: a.timestamp,
373
373
  duration: t * o / 1e3,
374
- bytesReceived: r.bytesReceived - e[o - 1].bytesReceived,
375
- bitrate: (r.bytesReceived - e[o - 1].bytesReceived) * 8 / (t / 1e3),
376
- packetsReceived: r.packetsReceived - e[o - 1].packetsReceived,
377
- packetsLost: r.packetsLost - e[o - 1].packetsLost,
378
- framesDropped: r.framesDropped - e[o - 1].framesDropped,
379
- framesDecoded: r.framesDecoded - e[o - 1].framesDecoded,
380
- jitter: r.jitter,
381
- jitterBufferDelay: r.jitterBufferDelay - e[o - 1].jitterBufferDelay,
382
- framesPerSecond: r.framesPerSecond,
383
- freezeCount: r.freezeCount - e[o - 1].freezeCount,
384
- freezeDuration: r.freezeDuration - e[o - 1].freezeDuration
385
- }), n = be(a), s = n.reduce((r, o) => r + (o.causes.includes("low fps") ? 1 : 0), 0);
374
+ bytesReceived: a.bytesReceived - e[o - 1].bytesReceived,
375
+ bitrate: (a.bytesReceived - e[o - 1].bytesReceived) * 8 / (t / 1e3),
376
+ packetsReceived: a.packetsReceived - e[o - 1].packetsReceived,
377
+ packetsLost: a.packetsLost - e[o - 1].packetsLost,
378
+ framesDropped: a.framesDropped - e[o - 1].framesDropped,
379
+ framesDecoded: a.framesDecoded - e[o - 1].framesDecoded,
380
+ jitter: a.jitter,
381
+ jitterBufferDelay: a.jitterBufferDelay - e[o - 1].jitterBufferDelay,
382
+ framesPerSecond: a.framesPerSecond,
383
+ freezeCount: a.freezeCount - e[o - 1].freezeCount,
384
+ freezeDuration: a.freezeDuration - e[o - 1].freezeDuration
385
+ }), n = be(r), i = n.reduce((a, o) => a + (o.causes.includes("low fps") ? 1 : 0), 0);
386
386
  return {
387
387
  webRTCStats: {
388
388
  anomalies: n,
389
- aggregateReport: Me(e[0], e[e.length - 1], s)
389
+ aggregateReport: Me(e[0], e[e.length - 1], i)
390
390
  },
391
391
  codec: e[0].codec,
392
392
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
@@ -417,45 +417,45 @@ function X(e) {
417
417
  function $e() {
418
418
  let e = 0;
419
419
  return (t) => {
420
- for (const i of t.values())
421
- if (i && i.type === "inbound-rtp" && i.kind === "video") {
422
- const a = i.bytesReceived, n = a - e > 0;
423
- return e = a, n;
420
+ for (const s of t.values())
421
+ if (s && s.type === "inbound-rtp" && s.kind === "video") {
422
+ const r = s.bytesReceived, n = r - e > 0;
423
+ return e = r, n;
424
424
  }
425
425
  return !1;
426
426
  };
427
427
  }
428
- function Ae(e, t, i = !1, a, n) {
429
- const r = Math.max(Math.ceil(10), 1);
430
- let o = [], l, d = 0, f = !1;
431
- const m = i ? 1 : 0;
432
- let p = 0;
433
- const k = $e();
428
+ function Ae(e, t, s = !1, r, n, i = !1) {
429
+ const o = Math.max(Math.ceil(10), 1);
430
+ let l = [], d, f = 0, m = !1;
431
+ const p = s ? 1 : 0;
432
+ let k = 0;
433
+ const y = $e();
434
434
  return setInterval(async () => {
435
- const y = await e.getStats(), C = k(y), g = Ee(y);
436
- if (C)
437
- d = 0, f || (t == null || t(j.Start), p >= m && !a() && n(), l = o[o.length - 1], o = [], p++, f = !0), o.push(g);
438
- else if (f && (d++, d >= r)) {
439
- const R = Ie(o, 100, l);
440
- t == null || t(j.Stop, R), f = !1;
435
+ const C = await e.getStats(), g = y(C), R = Ee(C);
436
+ if (g)
437
+ f = 0, console.log("isReceiving", g), m || (t == null || t(j.Start), i && k >= p && !r() && n(), d = l[l.length - 1], l = [], k++, m = !0), l.push(R);
438
+ else if (m && (console.log("notReceiving", g), f++, f >= o)) {
439
+ const S = Ie(l, 100, d);
440
+ t == null || t(j.Stop, S), !i && !r() && n(), m = !1;
441
441
  }
442
442
  }, 100);
443
443
  }
444
444
  async function Te(e, t, {
445
- debug: i = !1,
446
- callbacks: a,
445
+ debug: s = !1,
446
+ callbacks: r,
447
447
  auth: n,
448
- baseURL: s = H,
449
- warmup: r
448
+ baseURL: i = H,
449
+ warmup: a
450
450
  }) {
451
- ne = i;
451
+ ne = s;
452
452
  const {
453
453
  startConnection: o,
454
454
  sendStreamRequest: l,
455
455
  close: d,
456
456
  createStream: f,
457
457
  addIceCandidate: m
458
- } = t.videoType === Z.Clip ? De(n, s, e, a.onError) : _e(n, s, e, a.onError), {
458
+ } = t.videoType === Z.Clip ? Se(n, i, e, r.onError) : _e(n, i, e, r.onError), {
459
459
  id: p,
460
460
  offer: k,
461
461
  ice_servers: y,
@@ -465,11 +465,11 @@ async function Te(e, t, {
465
465
  }), R = g.createDataChannel("JanusDataChannel");
466
466
  if (!C)
467
467
  throw new Error("Could not create session_id");
468
- let M = !1;
469
- const c = () => M, h = () => {
468
+ let S = !1;
469
+ const c = () => S, h = () => {
470
470
  var u;
471
- M = !0, (u = a.onConnectionStateChange) == null || u.call(a, D.Connected);
472
- }, v = Ae(g, a.onVideoStateChange, r, c, h);
471
+ console.log("On connected"), S = !0, (u = r.onConnectionStateChange) == null || u.call(r, D.Connected);
472
+ }, v = Ae(g, r.onVideoStateChange, a, c, h, !!t.stream_greeting);
473
473
  g.onicecandidate = (u) => {
474
474
  var w;
475
475
  z("peerConnection.onicecandidate", u);
@@ -481,26 +481,21 @@ async function Te(e, t, {
481
481
  }, C) : m(p, {
482
482
  candidate: null
483
483
  }, C);
484
- } catch (S) {
485
- (w = a.onError) == null || w.call(a, S, {
484
+ } catch (M) {
485
+ (w = r.onError) == null || w.call(r, M, {
486
486
  streamId: p
487
487
  });
488
488
  }
489
- }, R.onmessage = (u) => {
490
- if (console.log("data channel message", u.data), R.readyState === "open") {
491
- const [w, S] = u.data.split(":");
492
- w === W.StreamReady && !M && h();
493
- }
494
489
  }, R.onopen = () => {
495
490
  !t.stream_warmup && !t.stream_greeting && h();
496
491
  }, g.oniceconnectionstatechange = () => {
497
492
  var w;
498
493
  z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
499
494
  const u = X(g.iceConnectionState);
500
- u !== D.Connected && ((w = a.onConnectionStateChange) == null || w.call(a, u));
495
+ u !== D.Connected && ((w = r.onConnectionStateChange) == null || w.call(r, u));
501
496
  }, g.ontrack = (u) => {
502
497
  var w;
503
- z("peerConnection.ontrack", u), (w = a.onSrcObjectReady) == null || w.call(a, u.streams[0]);
498
+ z("peerConnection.ontrack", u), (w = r.onSrcObjectReady) == null || w.call(r, u.streams[0]);
504
499
  }, await g.setRemoteDescription(k), z("set remote description OK");
505
500
  const _ = await g.createAnswer();
506
501
  return z("create answer OK"), await g.setLocalDescription(_), z("set local description OK"), await o(p, _, C), z("start connection OK"), {
@@ -517,21 +512,21 @@ async function Te(e, t, {
517
512
  async disconnect() {
518
513
  var u, w;
519
514
  if (p) {
520
- const S = X(g.iceConnectionState);
515
+ const M = X(g.iceConnectionState);
521
516
  if (g) {
522
- if (S === D.New) {
523
- (u = a.onVideoStateChange) == null || u.call(a, j.Stop), clearInterval(v);
517
+ if (M === D.New) {
518
+ (u = r.onVideoStateChange) == null || u.call(r, j.Stop), clearInterval(v);
524
519
  return;
525
520
  }
526
521
  g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
527
522
  }
528
523
  try {
529
- S === D.Connected && await d(p, C).catch((b) => {
524
+ M === D.Connected && await d(p, C).catch((b) => {
530
525
  });
531
526
  } catch (b) {
532
527
  z("Error on close stream connection", b);
533
528
  }
534
- (w = a.onVideoStateChange) == null || w.call(a, j.Stop), clearInterval(v);
529
+ (w = r.onVideoStateChange) == null || w.call(r, j.Stop), clearInterval(v);
535
530
  }
536
531
  },
537
532
  /**
@@ -546,23 +541,23 @@ async function Te(e, t, {
546
541
  }
547
542
  let U = {};
548
543
  function ze(e) {
549
- var s, r, o, l, d;
550
- const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = e.agent.presenter, a = (s = e.agent.llm) == null ? void 0 : s.prompt_customization, n = {
544
+ var i, a, o, l, d;
545
+ const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", s = e.agent.presenter, r = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, n = {
551
546
  token: e.token || "testKey",
552
- distinct_id: e.distinctId || Q(),
547
+ distinct_id: e.distinctId || G(),
553
548
  agentId: e.agent.id,
554
- agentType: i.type === "clip" && i.presenter_id.startsWith("v2_") ? "clip_v2" : i.type,
549
+ agentType: s.type === "clip" && s.presenter_id.startsWith("v2_") ? "clip_v2" : s.type,
555
550
  owner_id: e.agent.owner_id ?? "",
556
551
  behavior: {
557
- role: a == null ? void 0 : a.role,
558
- personality: a == null ? void 0 : a.personality,
559
- instructions: (r = e.agent.llm) == null ? void 0 : r.instructions
552
+ role: r == null ? void 0 : r.role,
553
+ personality: r == null ? void 0 : r.personality,
554
+ instructions: (a = e.agent.llm) == null ? void 0 : a.instructions
560
555
  },
561
556
  temperature: (o = e.agent.llm) == null ? void 0 : o.temperature,
562
- knowledgeSource: a == null ? void 0 : a.knowledge_source,
557
+ knowledgeSource: r == null ? void 0 : r.knowledge_source,
563
558
  starterQuestionsCount: (d = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : d.length,
564
- topicsToAvoid: a == null ? void 0 : a.topics_to_avoid,
565
- maxResponseLength: a == null ? void 0 : a.max_response_length
559
+ topicsToAvoid: r == null ? void 0 : r.topics_to_avoid,
560
+ maxResponseLength: r == null ? void 0 : r.max_response_length
566
561
  };
567
562
  return {
568
563
  ...n,
@@ -620,9 +615,9 @@ function ze(e) {
620
615
  if (y.events[p] = {
621
616
  props: m
622
617
  }, y.resolvedDependencies.push(p), k.every((g) => y.resolvedDependencies.includes(g))) {
623
- const g = k.reduce((R, M) => y.events[M] ? {
618
+ const g = k.reduce((R, S) => y.events[S] ? {
624
619
  ...R,
625
- ...y.events[M].props
620
+ ...y.events[S].props
626
621
  } : R, {});
627
622
  this.track(f, g), y.resolvedDependencies = y.resolvedDependencies.filter((R) => !k.includes(R)), k.forEach((R) => {
628
623
  delete y.events[R];
@@ -632,32 +627,32 @@ function ze(e) {
632
627
  };
633
628
  }
634
629
  function Le(e) {
635
- var n, s, r, o;
636
- const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
630
+ var n, i, a, o;
631
+ const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", s = () => {
637
632
  const l = navigator.platform;
638
633
  return l.toLowerCase().includes("win") ? "Windows" : l.toLowerCase().includes("mac") ? "Mac OS X" : l.toLowerCase().includes("linux") ? "Linux" : "Unknown";
639
- }, a = e.presenter;
634
+ }, r = e.presenter;
640
635
  return {
641
- $os: `${i()}`,
636
+ $os: `${s()}`,
642
637
  isMobile: `${t() == "Mobile"}`,
643
638
  browser: navigator.userAgent,
644
639
  origin: window.location.origin,
645
- agentType: a.type === "clip" && a.presenter_id.startsWith("v2_") ? "clip_v2" : a.type,
640
+ agentType: r.type === "clip" && r.presenter_id.startsWith("v2_") ? "clip_v2" : r.type,
646
641
  agentVoice: {
647
- voiceId: (s = (n = e.presenter) == null ? void 0 : n.voice) == null ? void 0 : s.voice_id,
648
- provider: (o = (r = e.presenter) == null ? void 0 : r.voice) == null ? void 0 : o.type
642
+ voiceId: (i = (n = e.presenter) == null ? void 0 : n.voice) == null ? void 0 : i.voice_id,
643
+ provider: (o = (a = e.presenter) == null ? void 0 : a.voice) == null ? void 0 : o.type
649
644
  }
650
645
  };
651
646
  }
652
- function je(e, t, i) {
647
+ function je(e, t, s) {
653
648
  var d, f;
654
649
  const {
655
- event: a,
650
+ event: r,
656
651
  ...n
657
652
  } = e, {
658
- template: s
653
+ template: i
659
654
  } = (t == null ? void 0 : t.llm) || {}, {
660
- language: r
655
+ language: a
661
656
  } = ((d = t == null ? void 0 : t.presenter) == null ? void 0 : d.voice) || {}, {
662
657
  stitch: o
663
658
  } = (t == null ? void 0 : t.presenter) || {};
@@ -665,80 +660,80 @@ function je(e, t, i) {
665
660
  ...n,
666
661
  llm: {
667
662
  ...n.llm,
668
- template: s
663
+ template: i
669
664
  },
670
665
  script: {
671
666
  ...n.script,
672
667
  provider: {
673
668
  ...(f = n == null ? void 0 : n.script) == null ? void 0 : f.provider,
674
- language: r
669
+ language: a
675
670
  }
676
671
  },
677
672
  stitch: o,
678
- ...i
673
+ ...s
679
674
  };
680
675
  }
681
676
  class xe extends Error {
682
677
  constructor({
683
678
  kind: t,
684
- description: i
679
+ description: s
685
680
  }) {
686
- const a = JSON.stringify({
681
+ const r = JSON.stringify({
687
682
  kind: t,
688
- description: i
683
+ description: s
689
684
  });
690
- super(a);
685
+ super(r);
691
686
  }
692
687
  }
693
688
  let L = 0;
694
689
  const Ne = 45 * 1e3;
695
- function Be(e, t, i) {
696
- var a, n, s, r, o;
690
+ function Be(e, t, s) {
691
+ var r, n, i, a, o;
697
692
  return {
698
693
  videoType: ue(e.presenter.type),
699
- output_resolution: (a = t == null ? void 0 : t.streamOptions) == null ? void 0 : a.outputResolution,
694
+ output_resolution: (r = t == null ? void 0 : t.streamOptions) == null ? void 0 : r.outputResolution,
700
695
  session_timeout: (n = t == null ? void 0 : t.streamOptions) == null ? void 0 : n.sessionTimeout,
701
- stream_warmup: (s = t == null ? void 0 : t.streamOptions) == null ? void 0 : s.streamWarmup,
702
- compatibility_mode: (r = t == null ? void 0 : t.streamOptions) == null ? void 0 : r.compatibilityMode,
703
- stream_greeting: (o = t == null ? void 0 : t.streamOptions) != null && o.streamGreeting ? i : void 0
696
+ stream_warmup: (i = t == null ? void 0 : t.streamOptions) == null ? void 0 : i.streamWarmup,
697
+ compatibility_mode: (a = t == null ? void 0 : t.streamOptions) == null ? void 0 : a.compatibilityMode,
698
+ stream_greeting: (o = t == null ? void 0 : t.streamOptions) != null && o.streamGreeting ? s : void 0
704
699
  };
705
700
  }
706
701
  function re(e) {
707
702
  return e === I.Playground ? {
708
703
  headers: {
709
- [Se]: "true"
704
+ [De]: "true"
710
705
  }
711
706
  } : {};
712
707
  }
713
- async function ae(e, t, i, a, n) {
708
+ async function ae(e, t, s, r, n) {
714
709
  try {
715
- const s = await t.newChat(e, {
710
+ const i = await t.newChat(e, {
716
711
  persist: n ?? !1
717
- }, re(a));
718
- return i.track("agent-chat", {
712
+ }, re(r));
713
+ return s.track("agent-chat", {
719
714
  event: "created",
720
- chat_id: s.id,
715
+ chat_id: i.id,
721
716
  agent_id: e,
722
- mode: a
723
- }), s;
724
- } catch (s) {
725
- let r;
717
+ mode: r
718
+ }), i;
719
+ } catch (i) {
720
+ let a;
726
721
  try {
727
- r = JSON.parse(s.message);
722
+ a = JSON.parse(i.message);
728
723
  } catch (o) {
729
724
  console.error("Error parsing the error message:", o);
730
725
  }
731
- throw (r == null ? void 0 : r.kind) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
726
+ throw (a == null ? void 0 : a.kind) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
732
727
  }
733
728
  }
734
- function Fe(e, t, i, a, n, s) {
735
- return new Promise(async (r, o) => {
729
+ function Fe(e, t, s, r, n, i) {
730
+ return new Promise(async (a, o) => {
736
731
  var m, p, k, y, C;
737
732
  L = 0;
738
733
  const l = String(t.mode);
739
734
  if (!n && t.mode !== I.DirectPlayback)
740
735
  try {
741
- n = await ae(e.id, i, a, t.mode, t.persistentChat);
736
+ n = await ae(e.id, s, r, t.mode, t.persistentChat);
742
737
  } catch (g) {
743
738
  return o(g);
744
739
  }
@@ -747,44 +742,44 @@ function Fe(e, t, i, a, n, s) {
747
742
  kind: "ChatModeDowngraded",
748
743
  description: `Chat mode changed from ${l} to ${d} when creating the chat`
749
744
  }), {}))), d === I.TextOnly)
750
- return r({
745
+ return a({
751
746
  chat: n
752
747
  });
753
- const f = await Te(e.id, Be(e, t, s), {
748
+ const f = await Te(e.id, Be(e, t, i), {
754
749
  ...t,
755
- analytics: a,
750
+ analytics: r,
756
751
  warmup: (C = t.streamOptions) == null ? void 0 : C.streamWarmup,
757
752
  callbacks: {
758
753
  ...t.callbacks,
759
754
  onConnectionStateChange: async (g) => {
760
- var R, M, c, h;
761
- g === D.Connected ? f ? ((M = (R = t.callbacks).onConnectionStateChange) == null || M.call(R, g), r({
755
+ var R, S, c, h;
756
+ g === D.Connected ? f ? ((S = (R = t.callbacks).onConnectionStateChange) == null || S.call(R, g), a({
762
757
  chat: n,
763
758
  streamingManager: f
764
759
  })) : n && o(new Error("Something went wrong while initializing the manager")) : (h = (c = t.callbacks).onConnectionStateChange) == null || h.call(c, g);
765
760
  },
766
761
  onVideoStateChange(g, R) {
767
- var M, c;
768
- (c = (M = t.callbacks).onVideoStateChange) == null || c.call(M, g), L > 0 && (g === j.Start ? a.linkTrack("agent-video", {
762
+ var S, c;
763
+ (c = (S = t.callbacks).onVideoStateChange) == null || c.call(S, g), L > 0 && (g === j.Start ? r.linkTrack("agent-video", {
769
764
  event: "start",
770
765
  latency: Date.now() - L
771
- }, "start", [W.StreamVideoCreated]) : g === j.Stop && a.linkTrack("agent-video", {
766
+ }, "start", [K.StreamVideoCreated]) : g === j.Stop && r.linkTrack("agent-video", {
772
767
  event: "stop",
773
768
  is_greenscreen: e.presenter.type === "clip" && e.presenter.is_greenscreen,
774
769
  background: e.presenter.type === "clip" && e.presenter.background,
775
770
  ...R
776
- }, "done", [W.StreamVideoDone]));
771
+ }, "done", [K.StreamVideoDone]));
777
772
  }
778
773
  }
779
774
  }).catch(o);
780
775
  });
781
776
  }
782
- function We(e) {
783
- var i;
784
- const t = (i = e.greetings) == null ? void 0 : i.filter((a) => a.length > 0);
777
+ function He(e) {
778
+ var s;
779
+ const t = (s = e.greetings) == null ? void 0 : s.filter((r) => r.length > 0);
785
780
  if (t && t.length > 0) {
786
- const a = Math.floor(Math.random() * t.length);
787
- return t[a];
781
+ const r = Math.floor(Math.random() * t.length);
782
+ return t[r];
788
783
  } else
789
784
  return `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
790
785
  }
@@ -796,35 +791,35 @@ function Y(e, t) {
796
791
  created_at: (/* @__PURE__ */ new Date()).toISOString()
797
792
  }];
798
793
  }
799
- function He(e) {
794
+ function We(e) {
800
795
  if (e.answer !== void 0)
801
796
  return e.answer;
802
- let t = 0, i = "";
797
+ let t = 0, s = "";
803
798
  for (; t in e; )
804
- i += e[t], t++;
805
- return i;
799
+ s += e[t], t++;
800
+ return s;
806
801
  }
807
- function Ke(e, t, i, a, n) {
802
+ function Ke(e, t, s, r, n) {
808
803
  if (!(e === B.Partial || e === B.Answer))
809
804
  return;
810
- const s = a.messages[a.messages.length - 1];
811
- if ((s == null ? void 0 : s.role) !== "assistant")
805
+ const i = r.messages[r.messages.length - 1];
806
+ if ((i == null ? void 0 : i.role) !== "assistant")
812
807
  return;
813
808
  const {
814
- content: r,
809
+ content: a,
815
810
  sequence: o
816
811
  } = t;
817
- e === B.Partial ? i[o] = r : i.answer = r;
818
- const l = He(i);
819
- (s.content !== l || e === B.Answer) && (s.content = l, n == null || n([...a.messages], e));
812
+ e === B.Partial ? s[o] = a : s.answer = a;
813
+ const l = We(s);
814
+ (i.content !== l || e === B.Answer) && (i.content = l, n == null || n([...r.messages], e));
820
815
  }
821
816
  async function Ve(e, t) {
822
- var g, R, M;
823
- let i = {}, a = !0;
817
+ var g, R, S;
818
+ let s = {}, r = !0;
824
819
  const n = {
825
820
  messages: [],
826
821
  chatMode: t.mode || I.Functional
827
- }, s = t.baseURL || H, r = t.wsURL || he, o = t.mixpanelKey || we, l = te(t.auth, s, t.callbacks.onError), d = await l.getById(e), f = We(d);
822
+ }, i = t.baseURL || H, a = t.wsURL || he, o = t.mixpanelKey || we, l = te(t.auth, i, t.callbacks.onError), d = await l.getById(e), f = He(d);
828
823
  n.messages = Y(f, t.initialMessages), (R = (g = t.callbacks).onNewMessage) == null || R.call(g, [...n.messages], "answer");
829
824
  const m = ze({
830
825
  token: o,
@@ -840,19 +835,19 @@ async function Ve(e, t) {
840
835
  onMessage: (c, h) => {
841
836
  var v, _;
842
837
  if ("content" in h)
843
- Ke(c, h, i, n, t.callbacks.onNewMessage), c === B.Answer && m.track("agent-message-received", {
838
+ Ke(c, h, s, n, t.callbacks.onNewMessage), c === B.Answer && m.track("agent-message-received", {
844
839
  messages: n.messages.length,
845
840
  mode: n.chatMode
846
841
  });
847
842
  else {
848
- const u = W, w = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], S = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], b = je(h, d, {
843
+ const u = K, w = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], M = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], b = je(h, d, {
849
844
  mode: n.chatMode
850
845
  });
851
846
  if (c = c, c === u.StreamVideoCreated)
852
847
  m.linkTrack("agent-video", b, u.StreamVideoCreated, ["start"]);
853
848
  else if (w.includes(c)) {
854
849
  const E = c.split("/")[1];
855
- S.includes(c) ? m.track("agent-video", {
850
+ M.includes(c) ? m.track("agent-video", {
856
851
  ...b,
857
852
  event: E
858
853
  }) : m.linkTrack("agent-video", {
@@ -860,16 +855,16 @@ async function Ve(e, t) {
860
855
  event: E
861
856
  }, c, ["done"]);
862
857
  }
863
- S.includes(c) && ((_ = (v = t.callbacks).onError) == null || _.call(v, new Error(`Stream failed with event ${c}`), {
858
+ M.includes(c) && ((_ = (v = t.callbacks).onError) == null || _.call(v, new Error(`Stream failed with event ${c}`), {
864
859
  data: h
865
860
  })), h.event === u.StreamDone && y();
866
861
  }
867
862
  }
868
863
  };
869
864
  async function k(c) {
870
- var S, b, E, A, F, T, P;
871
- (b = (S = t.callbacks).onConnectionStateChange) == null || b.call(S, D.Connecting), L = 0, c && !a && (delete n.chat, n.messages = Y(f), (A = (E = t.callbacks).onNewMessage) == null || A.call(E, [...n.messages], "answer"));
872
- const h = t.mode === I.DirectPlayback ? Promise.resolve(void 0) : Re(t.auth, r, p), v = G(() => Fe(d, t, l, m, n.chat, c ? f : void 0), {
865
+ var M, b, E, A, F, T, P;
866
+ (b = (M = t.callbacks).onConnectionStateChange) == null || b.call(M, D.Connecting), L = 0, c && !r && (delete n.chat, n.messages = Y(f), (A = (E = t.callbacks).onNewMessage) == null || A.call(E, [...n.messages], "answer"));
867
+ const h = t.mode === I.DirectPlayback ? Promise.resolve(void 0) : Re(t.auth, a, p), v = Q(() => Fe(d, t, l, m, n.chat, c ? f : void 0), {
873
868
  limit: 3,
874
869
  timeout: Ne,
875
870
  timeoutErrorMessage: "Timeout initializing the stream",
@@ -883,7 +878,7 @@ async function Ve(e, t) {
883
878
  streamingManager: u,
884
879
  chat: w
885
880
  }] = await Promise.all([h, v]);
886
- w && w.id !== ((F = n.chat) == null ? void 0 : F.id) && ((P = (T = t.callbacks).onNewChat) == null || P.call(T, w.id)), n.streamingManager = u, n.socketManager = _, n.chat = w, a = !1, C((w == null ? void 0 : w.chat_mode) ?? t.mode ?? I.Functional);
881
+ w && w.id !== ((F = n.chat) == null ? void 0 : F.id) && ((P = (T = t.callbacks).onNewChat) == null || P.call(T, w.id)), n.streamingManager = u, n.socketManager = _, n.chat = w, r = !1, C((w == null ? void 0 : w.chat_mode) ?? t.mode ?? I.Functional);
887
882
  }
888
883
  async function y() {
889
884
  var c, h, v, _;
@@ -897,7 +892,7 @@ async function Ve(e, t) {
897
892
  }
898
893
  return {
899
894
  agent: d,
900
- starterMessages: ((M = d.knowledge) == null ? void 0 : M.starter_message) || [],
895
+ starterMessages: ((S = d.knowledge) == null ? void 0 : S.starter_message) || [],
901
896
  getSTTToken: () => l.getSTTToken(d.id),
902
897
  changeMode: C,
903
898
  enrichAnalytics: m.enrich,
@@ -929,9 +924,9 @@ async function Ve(e, t) {
929
924
  });
930
925
  },
931
926
  async chat(c) {
932
- var v, _, u, w, S, b;
927
+ var v, _, u, w, M, b;
933
928
  const h = V();
934
- i = {};
929
+ s = {};
935
930
  try {
936
931
  if (L = Date.now(), t.mode === I.DirectPlayback)
937
932
  throw new Error("Direct playback is enabled, chat is disabled");
@@ -969,16 +964,16 @@ async function Ve(e, t) {
969
964
  chatMode: n.chatMode,
970
965
  messages: A.map(({
971
966
  matches: N,
972
- ...K
973
- }) => K)
967
+ ...W
968
+ }) => W)
974
969
  }, {
975
970
  ...re(n.chatMode),
976
971
  skipErrorHandler: !0
977
972
  });
978
973
  }, T = await F(n.chat.id).catch(async (P) => {
979
- var N, K, J, O;
974
+ var N, W, J, O;
980
975
  const $ = (N = P == null ? void 0 : P.message) == null ? void 0 : N.includes("missing or invalid session_id");
981
- if (!((K = P == null ? void 0 : P.message) == null ? void 0 : K.includes("Stream Error")) && !$)
976
+ if (!((W = P == null ? void 0 : P.message) == null ? void 0 : W.includes("Stream Error")) && !$)
982
977
  throw (O = (J = t.callbacks).onError) == null || O.call(J, P, {}), P;
983
978
  return await y(), await k(!1), F(n.chat.id);
984
979
  });
@@ -990,7 +985,7 @@ async function Ve(e, t) {
990
985
  latency: Date.now() - L,
991
986
  mode: n.chatMode,
992
987
  messages: n.messages.length
993
- }), (b = (S = t.callbacks).onNewMessage) == null || b.call(S, [...n.messages], "answer")), T;
988
+ }), (b = (M = t.callbacks).onNewMessage) == null || b.call(M, [...n.messages], "answer")), T;
994
989
  } catch (E) {
995
990
  throw n.messages[n.messages.length - 1].id === h && n.messages.pop(), m.track("agent-message-send", {
996
991
  event: "error",
@@ -1000,7 +995,7 @@ async function Ve(e, t) {
1000
995
  }
1001
996
  },
1002
997
  rate(c, h, v) {
1003
- var w, S, b, E;
998
+ var w, M, b, E;
1004
999
  const _ = n.messages.find((A) => A.id === c);
1005
1000
  if (n.chat) {
1006
1001
  if (!_)
@@ -1011,7 +1006,7 @@ async function Ve(e, t) {
1011
1006
  return m.track("agent-rate", {
1012
1007
  event: v ? "update" : "create",
1013
1008
  thumb: h === 1 ? "up" : "down",
1014
- knowledge_id: ((S = d.knowledge) == null ? void 0 : S.id) ?? "",
1009
+ knowledge_id: ((M = d.knowledge) == null ? void 0 : M.id) ?? "",
1015
1010
  mode: n.chatMode,
1016
1011
  matches: u,
1017
1012
  score: h
@@ -1072,11 +1067,11 @@ async function Ve(e, t) {
1072
1067
  }
1073
1068
  };
1074
1069
  }
1075
- function Ue(e, t, i) {
1070
+ function Ue(e, t, s) {
1076
1071
  const {
1077
- getById: a
1078
- } = te(t, i || H);
1079
- return a(e);
1072
+ getById: r
1073
+ } = te(t, s || H);
1074
+ return r(e);
1080
1075
  }
1081
1076
  export {
1082
1077
  oe as AgentStatus,
@@ -1088,7 +1083,7 @@ export {
1088
1083
  se as PlanGroup,
1089
1084
  fe as Providers,
1090
1085
  ce as RateState,
1091
- W as StreamEvents,
1086
+ K as StreamEvents,
1092
1087
  j as StreamingState,
1093
1088
  de as Subject,
1094
1089
  ie as UserPlan,