@d-id/client-sdk 1.0.19-beta.140 → 1.0.19-beta.143

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,5 +1,5 @@
1
- var ie = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ie || {}), se = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(se || {}), oe = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(oe || {}), ce = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ce || {}), I = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(I || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(z || {}), de = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(de || {}), le = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(le || {}), ge = /* @__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))(ge || {}), G = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(G || {});
2
- const me = (e) => {
1
+ var re = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(re || {}), ae = /* @__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))(ae || {}), ie = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ie || {}), se = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(se || {}), I = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(I || {}), L = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(L || {}), oe = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(oe || {}), ce = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ce || {}), de = /* @__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))(de || {}), O = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(O || {});
2
+ const le = (e) => {
3
3
  switch (e) {
4
4
  case "clip":
5
5
  return "clip";
@@ -9,32 +9,66 @@ const me = (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 || {}), H = /* @__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))(H || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ue = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ue || {}), he = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(he || {});
13
- const V = "https://api.d-id.com", we = "wss://notifications.d-id.com", fe = "79f81a83a67430be2bc0fd61042b8faa", B = () => Math.random().toString(16).slice(2);
14
- function Q() {
12
+ var F = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(F || {}), 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.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), M = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(M || {}), me = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(me || {}), ge = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ge || {});
13
+ const U = "https://api.d-id.com", ue = "wss://notifications.d-id.com", he = "79f81a83a67430be2bc0fd61042b8faa";
14
+ async function X(e, n) {
15
+ const s = {
16
+ limit: (n == null ? void 0 : n.limit) ?? 3,
17
+ delayMs: (n == null ? void 0 : n.delayMs) ?? 0,
18
+ timeout: (n == null ? void 0 : n.timeout) ?? 3e4,
19
+ timeoutErrorMessage: (n == null ? void 0 : n.timeoutErrorMessage) || "Timeout error",
20
+ shouldRetryFn: (n == null ? void 0 : n.shouldRetryFn) ?? function() {
21
+ return !0;
22
+ }
23
+ };
24
+ let a;
25
+ for (let t = 1; t <= s.limit; t++)
26
+ try {
27
+ if (!s.timeout)
28
+ return await e();
29
+ let r;
30
+ const i = new Promise((l, d) => {
31
+ r = setTimeout(() => d(new Error(s.timeoutErrorMessage)), s.timeout);
32
+ });
33
+ return await Promise.race([e().then((l) => (clearTimeout(r), l)), i]);
34
+ } catch (r) {
35
+ if (a = r, !s.shouldRetryFn(r) || t >= s.limit)
36
+ throw r;
37
+ s.delayMs > 0 && await new Promise((i) => setTimeout(i, s.delayMs));
38
+ }
39
+ throw a;
40
+ }
41
+ const V = () => Math.random().toString(16).slice(2);
42
+ function Y() {
15
43
  let e = window.localStorage.getItem("did_external_key_id");
16
44
  return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
17
45
  }
18
- let pe = B();
19
- function ee(e) {
46
+ let we = V();
47
+ function Z(e) {
20
48
  if (e.type === "bearer")
21
49
  return `Bearer ${e.token}`;
22
50
  if (e.type === "basic")
23
51
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
24
52
  if (e.type === "key")
25
- return `Client-Key ${e.clientKey}.${Q()}_${pe}`;
53
+ return `Client-Key ${e.clientKey}.${Y()}_${we}`;
26
54
  throw new Error(`Unknown auth type: ${e}`);
27
55
  }
28
- function J(e, n = V, s) {
56
+ const fe = (e) => X(e, {
57
+ limit: 3,
58
+ delayMs: 1e3,
59
+ timeout: 0,
60
+ shouldRetryFn: (n) => n.status === 429
61
+ });
62
+ function q(e, n = U, s) {
29
63
  const a = async (t, r) => {
30
- const i = await fetch(n + (t != null && t.startsWith("/") ? t : `/${t}`), {
64
+ const i = await fe(() => fetch(n + (t != null && t.startsWith("/") ? t : `/${t}`), {
31
65
  ...r,
32
66
  headers: {
33
67
  ...r == null ? void 0 : r.headers,
34
- Authorization: ee(e),
68
+ Authorization: Z(e),
35
69
  "Content-Type": "application/json"
36
70
  }
37
- });
71
+ }));
38
72
  if (!i.ok) {
39
73
  let o = await i.text().catch(() => "Failed to fetch");
40
74
  throw s && s(new Error(o), {
@@ -75,8 +109,8 @@ function J(e, n = V, s) {
75
109
  }
76
110
  };
77
111
  }
78
- function te(e, n = V, s) {
79
- const a = J(e, `${n}/agents`, s);
112
+ function G(e, n = U, s) {
113
+ const a = q(e, `${n}/agents`, s);
80
114
  return {
81
115
  create(t, r) {
82
116
  return a.post("/", t, r);
@@ -102,8 +136,8 @@ function te(e, n = V, s) {
102
136
  createRating(t, r, i, o) {
103
137
  return a.post(`/${t}/chat/${r}/ratings`, i, o);
104
138
  },
105
- updateRating(t, r, i, o, d) {
106
- return a.patch(`/${t}/chat/${r}/ratings/${i}`, o, d);
139
+ updateRating(t, r, i, o, l) {
140
+ return a.patch(`/${t}/chat/${r}/ratings/${i}`, o, l);
107
141
  },
108
142
  deleteRating(t, r, i, o) {
109
143
  return a.delete(`/${t}/chat/${r}/ratings/${i}`, o);
@@ -123,17 +157,17 @@ function ve(e) {
123
157
  } = e, {
124
158
  onMessage: i = null,
125
159
  onOpen: o = null,
126
- onClose: d = null,
127
- onError: g = null
128
- } = a || {}, h = new WebSocket(`${t}?authorization=${ee(r)}`);
129
- h.onmessage = i, h.onclose = d, h.onerror = (m) => {
130
- console.error(m), g == null || g("Websocket failed to connect", m), s(m);
131
- }, h.onopen = (m) => {
132
- o == null || o(m), n(h);
160
+ onClose: l = null,
161
+ onError: d = null
162
+ } = a || {}, u = new WebSocket(`${t}?authorization=${Z(r)}`);
163
+ u.onmessage = i, u.onclose = l, u.onerror = (g) => {
164
+ console.error(g), d == null || d("Websocket failed to connect", g), s(g);
165
+ }, u.onopen = (g) => {
166
+ o == null || o(g), n(u);
133
167
  };
134
168
  });
135
169
  }
136
- async function Ce(e) {
170
+ async function pe(e) {
137
171
  const {
138
172
  retries: n = 1
139
173
  } = e;
@@ -148,8 +182,8 @@ async function Ce(e) {
148
182
  }
149
183
  return s;
150
184
  }
151
- async function _e(e, n, s) {
152
- const a = s != null && s.onMessage ? [s.onMessage] : [], t = await Ce({
185
+ async function Ce(e, n, s) {
186
+ const a = s != null && s.onMessage ? [s.onMessage] : [], t = await pe({
153
187
  auth: e,
154
188
  host: n,
155
189
  callbacks: {
@@ -166,9 +200,9 @@ async function _e(e, n, s) {
166
200
  subscribeToEvents: (r) => a.push(r)
167
201
  };
168
202
  }
169
- const Se = "X-Playground-Chat";
170
- function ke(e, n, s, a) {
171
- const t = J(e, `${n}/agents/${s}`, a);
203
+ const _e = "X-Playground-Chat";
204
+ function Me(e, n, s, a) {
205
+ const t = q(e, `${n}/agents/${s}`, a);
172
206
  return {
173
207
  createStream(r) {
174
208
  return t.post("/streams", {
@@ -204,8 +238,8 @@ function ke(e, n, s, a) {
204
238
  }
205
239
  };
206
240
  }
207
- function Me(e, n, s, a) {
208
- const t = J(e, `${n}/agents/${s}`, a);
241
+ function Se(e, n, s, a) {
242
+ const t = q(e, `${n}/agents/${s}`, a);
209
243
  return {
210
244
  createStream(r, i) {
211
245
  return t.post("/streams", {
@@ -219,23 +253,23 @@ function Me(e, n, s, a) {
219
253
  stream_greeting: r.stream_greeting
220
254
  }, i);
221
255
  },
222
- startConnection(r, i, o, d) {
256
+ startConnection(r, i, o, l) {
223
257
  return t.post(`/streams/${r}/sdp`, {
224
258
  session_id: o,
225
259
  answer: i
226
- }, d);
260
+ }, l);
227
261
  },
228
- addIceCandidate(r, i, o, d) {
262
+ addIceCandidate(r, i, o, l) {
229
263
  return t.post(`/streams/${r}/ice`, {
230
264
  session_id: o,
231
265
  ...i
232
- }, d);
266
+ }, l);
233
267
  },
234
- sendStreamRequest(r, i, o, d) {
268
+ sendStreamRequest(r, i, o, l) {
235
269
  return t.post(`/streams/${r}`, {
236
270
  session_id: i,
237
271
  ...o
238
- }, d);
272
+ }, l);
239
273
  },
240
274
  close(r, i, o) {
241
275
  return t.delete(`/streams/${r}`, {
@@ -244,26 +278,26 @@ function Me(e, n, s, a) {
244
278
  }
245
279
  };
246
280
  }
247
- let ne = !1;
248
- const x = (e, n) => ne && console.log(e, n), Re = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
249
- function Y(e) {
281
+ let Q = !1;
282
+ const x = (e, n) => Q && console.log(e, n), ke = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
283
+ function J(e) {
250
284
  switch (e) {
251
285
  case "connected":
252
- return S.Connected;
286
+ return M.Connected;
253
287
  case "checking":
254
- return S.Connecting;
288
+ return M.Connecting;
255
289
  case "failed":
256
- return S.Fail;
290
+ return M.Fail;
257
291
  case "new":
258
- return S.New;
292
+ return M.New;
259
293
  case "closed":
260
- return S.Closed;
294
+ return M.Closed;
261
295
  case "disconnected":
262
- return S.Disconnected;
296
+ return M.Disconnected;
263
297
  case "completed":
264
- return S.Completed;
298
+ return M.Completed;
265
299
  default:
266
- return S.New;
300
+ return M.New;
267
301
  }
268
302
  }
269
303
  function Ee() {
@@ -277,106 +311,106 @@ function Ee() {
277
311
  return !1;
278
312
  };
279
313
  }
280
- function Ie(e, n, s = !1, a, t) {
314
+ function Re(e, n, s = !1, a, t) {
281
315
  const i = Math.max(Math.ceil(10), 1);
282
- let o = 0, d = !1;
283
- const g = s ? 1 : 0;
284
- let h = 0;
285
- const m = Ee();
316
+ let o = 0, l = !1;
317
+ const d = s ? 1 : 0;
318
+ let u = 0;
319
+ const g = Ee();
286
320
  return setInterval(async () => {
287
- const C = await e.getStats();
288
- m(C) ? (o = 0, d || (n == null || n(j.Start), h >= g && !a() && t(), h++, d = !0)) : d && (o++, o >= i && (n == null || n(j.Stop), d = !1));
321
+ const h = await e.getStats();
322
+ g(h) ? (o = 0, l || (n == null || n(F.Start), u >= d && !a() && t(), u++, l = !0)) : l && (o++, o >= i && (n == null || n(F.Stop), l = !1));
289
323
  }, 100);
290
324
  }
291
- async function $e(e, n, {
325
+ async function Ie(e, n, {
292
326
  debug: s = !1,
293
327
  callbacks: a,
294
328
  auth: t,
295
- baseURL: r = V,
329
+ baseURL: r = U,
296
330
  warmup: i
297
331
  }) {
298
- ne = s;
332
+ Q = s;
299
333
  const {
300
334
  startConnection: o,
301
- sendStreamRequest: d,
302
- close: g,
303
- createStream: h,
304
- addIceCandidate: m
305
- } = n.videoType === G.Clip ? ke(t, r, e, a.onError) : Me(t, r, e, a.onError), {
306
- id: C,
307
- offer: y,
308
- ice_servers: E,
335
+ sendStreamRequest: l,
336
+ close: d,
337
+ createStream: u,
338
+ addIceCandidate: g
339
+ } = n.videoType === O.Clip ? Me(t, r, e, a.onError) : Se(t, r, e, a.onError), {
340
+ id: h,
341
+ offer: C,
342
+ ice_servers: v,
309
343
  session_id: _
310
- } = await h(n), w = new Re({
311
- iceServers: E
312
- }), P = w.createDataChannel("JanusDataChannel");
344
+ } = await u(n), y = new ke({
345
+ iceServers: v
346
+ }), $ = y.createDataChannel("JanusDataChannel");
313
347
  if (!_)
314
348
  throw new Error("Could not create session_id");
315
- let L = !1;
316
- const c = () => L, u = () => {
317
- var l;
318
- L = !0, (l = a.onConnectionStateChange) == null || l.call(a, S.Connected);
319
- }, f = Ie(w, a.onVideoStateChange, i, c, u);
320
- w.onicecandidate = (l) => {
321
- var p;
322
- x("peerConnection.onicecandidate", l);
349
+ let P = !1;
350
+ const c = () => P, w = () => {
351
+ var m;
352
+ P = !0, (m = a.onConnectionStateChange) == null || m.call(a, M.Connected);
353
+ }, p = Re(y, a.onVideoStateChange, i, c, w);
354
+ y.onicecandidate = (m) => {
355
+ var f;
356
+ x("peerConnection.onicecandidate", m);
323
357
  try {
324
- l.candidate && l.candidate.sdpMid && l.candidate.sdpMLineIndex !== null ? m(C, {
325
- candidate: l.candidate.candidate,
326
- sdpMid: l.candidate.sdpMid,
327
- sdpMLineIndex: l.candidate.sdpMLineIndex
328
- }, _) : m(C, {
358
+ m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? g(h, {
359
+ candidate: m.candidate.candidate,
360
+ sdpMid: m.candidate.sdpMid,
361
+ sdpMLineIndex: m.candidate.sdpMLineIndex
362
+ }, _) : g(h, {
329
363
  candidate: null
330
364
  }, _);
331
- } catch (M) {
332
- (p = a.onError) == null || p.call(a, M, {
333
- streamId: C
365
+ } catch (k) {
366
+ (f = a.onError) == null || f.call(a, k, {
367
+ streamId: h
334
368
  });
335
369
  }
336
- }, P.onmessage = (l) => {
337
- if (P.readyState === "open") {
338
- const [p, M] = l.data.split(":");
339
- p === H.StreamReady && !L && u();
370
+ }, $.onmessage = (m) => {
371
+ if ($.readyState === "open") {
372
+ const [f, k] = m.data.split(":");
373
+ f === j.StreamReady && !P && w();
340
374
  }
341
- }, w.oniceconnectionstatechange = () => {
342
- var p;
343
- x("peerConnection.oniceconnectionstatechange => " + w.iceConnectionState);
344
- const l = Y(w.iceConnectionState);
345
- l !== S.Connected && ((p = a.onConnectionStateChange) == null || p.call(a, l));
346
- }, w.ontrack = (l) => {
347
- var p;
348
- x("peerConnection.ontrack", l), (p = a.onSrcObjectReady) == null || p.call(a, l.streams[0]);
349
- }, await w.setRemoteDescription(y), x("set remote description OK");
350
- const k = await w.createAnswer();
351
- return x("create answer OK"), await w.setLocalDescription(k), x("set local description OK"), await o(C, k, _), x("start connection OK"), {
375
+ }, y.oniceconnectionstatechange = () => {
376
+ var f;
377
+ x("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
378
+ const m = J(y.iceConnectionState);
379
+ m !== M.Connected && ((f = a.onConnectionStateChange) == null || f.call(a, m));
380
+ }, y.ontrack = (m) => {
381
+ var f;
382
+ x("peerConnection.ontrack", m), (f = a.onSrcObjectReady) == null || f.call(a, m.streams[0]);
383
+ }, await y.setRemoteDescription(C), x("set remote description OK");
384
+ const S = await y.createAnswer();
385
+ return x("create answer OK"), await y.setLocalDescription(S), x("set local description OK"), await o(h, S, _), x("start connection OK"), {
352
386
  /**
353
387
  * Method to send request to server to get clip or talk depend on you payload
354
388
  * @param payload
355
389
  */
356
- speak(l) {
357
- return d(C, _, l);
390
+ speak(m) {
391
+ return l(h, _, m);
358
392
  },
359
393
  /**
360
394
  * Method to close RTC connection
361
395
  */
362
396
  async disconnect() {
363
- var l, p;
364
- if (C) {
365
- const M = Y(w.iceConnectionState);
366
- if (w) {
367
- if (M === S.New) {
368
- (l = a.onVideoStateChange) == null || l.call(a, j.Stop), clearInterval(f);
397
+ var m, f;
398
+ if (h) {
399
+ const k = J(y.iceConnectionState);
400
+ if (y) {
401
+ if (k === M.New) {
402
+ (m = a.onVideoStateChange) == null || m.call(a, F.Stop), clearInterval(p);
369
403
  return;
370
404
  }
371
- w.close(), w.oniceconnectionstatechange = null, w.onnegotiationneeded = null, w.onicecandidate = null, w.ontrack = null;
405
+ y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
372
406
  }
373
407
  try {
374
- M === S.Connected && await g(C, _).catch((v) => {
408
+ k === M.Connected && await d(h, _).catch((E) => {
375
409
  });
376
- } catch (v) {
377
- x("Error on close stream connection", v);
410
+ } catch (E) {
411
+ x("Error on close stream connection", E);
378
412
  }
379
- (p = a.onVideoStateChange) == null || p.call(a, j.Stop), clearInterval(f);
413
+ (f = a.onVideoStateChange) == null || f.call(a, F.Stop), clearInterval(p);
380
414
  }
381
415
  },
382
416
  /**
@@ -386,52 +420,63 @@ async function $e(e, n, {
386
420
  /**
387
421
  * Id of current RTC stream
388
422
  */
389
- streamId: C
423
+ streamId: h
390
424
  };
391
425
  }
392
- let q = {};
393
- function Ae(e) {
394
- const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", s = e.agent.presenter, a = {
426
+ let H = {};
427
+ function $e(e) {
428
+ var r, i, o, l, d;
429
+ const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", s = e.agent.presenter, a = (r = e.agent.llm) == null ? void 0 : r.prompt_customization, t = {
395
430
  token: e.token || "testKey",
396
- distinct_id: e.distinctId || Q(),
431
+ distinct_id: e.distinctId || Y(),
397
432
  agentId: e.agent.id,
398
433
  agentType: s.type === "clip" && s.presenter_id.startsWith("v2_") ? "clip_v2" : s.type,
399
- owner_id: e.agent.owner_id ?? ""
434
+ owner_id: e.agent.owner_id ?? "",
435
+ behavior: {
436
+ role: a == null ? void 0 : a.role,
437
+ personality: a == null ? void 0 : a.personality,
438
+ instructions: (i = e.agent.llm) == null ? void 0 : i.instructions
439
+ },
440
+ temperature: (o = e.agent.llm) == null ? void 0 : o.temperature,
441
+ knowledgeSource: a == null ? void 0 : a.knowledge_source,
442
+ starterQuestionsCount: (d = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : d.length,
443
+ topicsToAvoid: a == null ? void 0 : a.topics_to_avoid,
444
+ maxResponseLength: a == null ? void 0 : a.max_response_length
400
445
  };
401
446
  return {
402
- ...a,
447
+ ...t,
403
448
  additionalProperties: {},
404
449
  isEnabled: e.isEnabled ?? !0,
405
450
  getRandom: () => Math.random().toString(16).slice(2),
406
- enrich(t) {
407
- const r = {};
408
- if (t && typeof t != "object")
451
+ enrich(u) {
452
+ const g = {};
453
+ if (u && typeof u != "object")
409
454
  throw new Error("properties must be a flat json object");
410
- for (let i in t)
411
- (typeof t[i] == "string" || typeof t[i] == "number") && (r[i] = t[i]);
455
+ for (let h in u)
456
+ (typeof u[h] == "string" || typeof u[h] == "number") && (g[h] = u[h]);
412
457
  this.additionalProperties = {
413
458
  ...this.additionalProperties,
414
- ...r
459
+ ...g
415
460
  };
416
461
  },
417
- track(t, r) {
462
+ track(u, g) {
418
463
  if (!this.isEnabled)
419
464
  return Promise.resolve();
420
465
  const {
421
- audioPath: i,
422
- ...o
423
- } = r || {}, d = {
466
+ audioPath: h,
467
+ ...C
468
+ } = g || {}, v = {
424
469
  method: "POST",
425
470
  headers: {
426
471
  "Content-Type": "application/x-www-form-urlencoded"
427
472
  },
428
473
  body: new URLSearchParams({
429
474
  data: JSON.stringify([{
430
- event: t,
475
+ event: u,
431
476
  properties: {
432
477
  ...this.additionalProperties,
433
- ...o,
434
- ...a,
478
+ ...C,
479
+ ...t,
435
480
  source: n,
436
481
  time: Date.now(),
437
482
  $insert_id: this.getRandom(),
@@ -443,33 +488,33 @@ function Ae(e) {
443
488
  }])
444
489
  })
445
490
  };
446
- return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1", d).then((g) => g.json()).catch((g) => console.error(g));
491
+ return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1", v).then((_) => _.json()).catch((_) => console.error(_));
447
492
  },
448
- linkTrack(t, r, i, o) {
449
- q[t] || (q[t] = {
493
+ linkTrack(u, g, h, C) {
494
+ H[u] || (H[u] = {
450
495
  events: {},
451
496
  resolvedDependencies: []
452
- }), o.includes(i) || o.push(i);
453
- const d = q[t];
454
- if (d.events[i] = {
455
- props: r
456
- }, d.resolvedDependencies.push(i), o.every((h) => d.resolvedDependencies.includes(h))) {
457
- const h = o.reduce((m, C) => d.events[C] ? {
458
- ...m,
459
- ...d.events[C].props
460
- } : m, {});
461
- this.track(t, h), d.resolvedDependencies = d.resolvedDependencies.filter((m) => !o.includes(m)), o.forEach((m) => {
462
- delete d.events[m];
497
+ }), C.includes(h) || C.push(h);
498
+ const v = H[u];
499
+ if (v.events[h] = {
500
+ props: g
501
+ }, v.resolvedDependencies.push(h), C.every((y) => v.resolvedDependencies.includes(y))) {
502
+ const y = C.reduce(($, P) => v.events[P] ? {
503
+ ...$,
504
+ ...v.events[P].props
505
+ } : $, {});
506
+ this.track(u, y), v.resolvedDependencies = v.resolvedDependencies.filter(($) => !C.includes($)), C.forEach(($) => {
507
+ delete v.events[$];
463
508
  });
464
509
  }
465
510
  }
466
511
  };
467
512
  }
468
- function be(e) {
513
+ function Ae(e) {
469
514
  var t, r, i, o;
470
515
  const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", s = () => {
471
- const d = navigator.platform;
472
- return d.toLowerCase().includes("win") ? "Windows" : d.toLowerCase().includes("mac") ? "Mac OS X" : d.toLowerCase().includes("linux") ? "Linux" : "Unknown";
516
+ const l = navigator.platform;
517
+ return l.toLowerCase().includes("win") ? "Windows" : l.toLowerCase().includes("mac") ? "Mac OS X" : l.toLowerCase().includes("linux") ? "Linux" : "Unknown";
473
518
  }, a = e.presenter;
474
519
  return {
475
520
  $os: `${s()}`,
@@ -484,7 +529,7 @@ function be(e) {
484
529
  };
485
530
  }
486
531
  function Pe(e, n, s) {
487
- var g, h;
532
+ var d, u;
488
533
  const {
489
534
  event: a,
490
535
  ...t
@@ -492,7 +537,7 @@ function Pe(e, n, s) {
492
537
  template: r
493
538
  } = (n == null ? void 0 : n.llm) || {}, {
494
539
  language: i
495
- } = ((g = n == null ? void 0 : n.presenter) == null ? void 0 : g.voice) || {}, {
540
+ } = ((d = n == null ? void 0 : n.presenter) == null ? void 0 : d.voice) || {}, {
496
541
  stitch: o
497
542
  } = (n == null ? void 0 : n.presenter) || {};
498
543
  return {
@@ -504,7 +549,7 @@ function Pe(e, n, s) {
504
549
  script: {
505
550
  ...t.script,
506
551
  provider: {
507
- ...(h = t == null ? void 0 : t.script) == null ? void 0 : h.provider,
552
+ ...(u = t == null ? void 0 : t.script) == null ? void 0 : u.provider,
508
553
  language: i
509
554
  }
510
555
  },
@@ -512,12 +557,12 @@ function Pe(e, n, s) {
512
557
  ...s
513
558
  };
514
559
  }
515
- let O = 0;
516
- const Te = 20 * 1e3;
517
- function De(e, n, s) {
560
+ let N = 0;
561
+ const be = 20 * 1e3;
562
+ function Te(e, n, s) {
518
563
  var a, t, r, i, o;
519
564
  return {
520
- videoType: me(e.presenter.type),
565
+ videoType: le(e.presenter.type),
521
566
  output_resolution: (a = n == null ? void 0 : n.streamOptions) == null ? void 0 : a.outputResolution,
522
567
  session_timeout: (t = n == null ? void 0 : n.streamOptions) == null ? void 0 : t.sessionTimeout,
523
568
  stream_warmup: (r = n == null ? void 0 : n.streamOptions) == null ? void 0 : r.streamWarmup,
@@ -525,18 +570,18 @@ function De(e, n, s) {
525
570
  stream_greeting: (o = n == null ? void 0 : n.streamOptions) != null && o.streamGreeting ? s : void 0
526
571
  };
527
572
  }
528
- function re(e) {
573
+ function ee(e) {
529
574
  return e === I.Playground ? {
530
575
  headers: {
531
- [Se]: "true"
576
+ [_e]: "true"
532
577
  }
533
578
  } : {};
534
579
  }
535
- async function ae(e, n, s, a, t) {
580
+ async function te(e, n, s, a, t) {
536
581
  try {
537
582
  const r = await n.newChat(e, {
538
583
  persist: t ?? !1
539
- }, re(a));
584
+ }, ee(a));
540
585
  return s.track("agent-chat", {
541
586
  event: "created",
542
587
  chat_id: r.id,
@@ -553,48 +598,48 @@ async function ae(e, n, s, a, t) {
553
598
  throw (i == null ? void 0 : i.kind) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
554
599
  }
555
600
  }
556
- function xe(e, n, s, a, t, r) {
601
+ function De(e, n, s, a, t, r) {
557
602
  return new Promise(async (i, o) => {
558
- var C;
559
- O = 0;
560
- const d = setTimeout(() => {
561
- h(new Error("Could not connect"));
562
- }, Te), g = (y) => {
563
- clearTimeout(d), i(y);
564
- }, h = (y) => {
565
- clearTimeout(d), o(y);
566
- };
567
- if (!t && n.mode !== I.DirectPlayback)
603
+ var d, u, g;
604
+ if (N = 0, !t && n.mode !== I.DirectPlayback)
568
605
  try {
569
- t = await ae(e.id, s, a, n.mode, n.persistentChat);
570
- } catch (y) {
571
- return h(y);
606
+ t = await te(e.id, s, a, n.mode, n.persistentChat);
607
+ } catch (h) {
608
+ return o(h);
572
609
  }
573
- const m = await $e(e.id, De(e, n, r), {
610
+ if ((t == null ? void 0 : t.chat_mode) === I.TextOnly)
611
+ return (u = (d = n.callbacks) == null ? void 0 : d.onError) == null || u.call(d, new Error(JSON.stringify({
612
+ kind: "InsufficientCreditsError"
613
+ })), {
614
+ fromSdk: !0
615
+ }), i({
616
+ chat: t
617
+ });
618
+ const l = await Ie(e.id, Te(e, n, r), {
574
619
  ...n,
575
620
  analytics: a,
576
- warmup: (C = n.streamOptions) == null ? void 0 : C.streamWarmup,
621
+ warmup: (g = n.streamOptions) == null ? void 0 : g.streamWarmup,
577
622
  callbacks: {
578
623
  ...n.callbacks,
579
- onConnectionStateChange: async (y) => {
580
- var E, _, w, P;
581
- y === S.Connected ? m ? ((_ = (E = n.callbacks).onConnectionStateChange) == null || _.call(E, y), g({
624
+ onConnectionStateChange: async (h) => {
625
+ var C, v, _, y;
626
+ h === M.Connected ? l ? ((v = (C = n.callbacks).onConnectionStateChange) == null || v.call(C, h), i({
582
627
  chat: t,
583
- streamingManager: m
584
- })) : t && h(new Error("Something went wrong while initializing the manager")) : (P = (w = n.callbacks).onConnectionStateChange) == null || P.call(w, y);
628
+ streamingManager: l
629
+ })) : t && o(new Error("Something went wrong while initializing the manager")) : (y = (_ = n.callbacks).onConnectionStateChange) == null || y.call(_, h);
585
630
  },
586
- onVideoStateChange(y) {
587
- var E, _;
588
- (_ = (E = n.callbacks).onVideoStateChange) == null || _.call(E, y), O > 0 && y === j.Start && a.linkTrack("agent-video", {
631
+ onVideoStateChange(h) {
632
+ var C, v;
633
+ (v = (C = n.callbacks).onVideoStateChange) == null || v.call(C, h), N > 0 && h === F.Start && a.linkTrack("agent-video", {
589
634
  event: "start",
590
- latency: Date.now() - O
591
- }, "start", [H.StreamVideoCreated]);
635
+ latency: Date.now() - N
636
+ }, "start", [j.StreamVideoCreated]);
592
637
  }
593
638
  }
594
- }).catch(h);
639
+ }).catch(o);
595
640
  });
596
641
  }
597
- function Ne(e) {
642
+ function xe(e) {
598
643
  var s;
599
644
  const n = (s = e.greetings) == null ? void 0 : s.filter((a) => a.length > 0);
600
645
  if (n && n.length > 0) {
@@ -603,15 +648,15 @@ function Ne(e) {
603
648
  } else
604
649
  return `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
605
650
  }
606
- function Z(e, n) {
651
+ function z(e, n) {
607
652
  return n && n.length > 0 ? n : [{
608
653
  content: e,
609
- id: B(),
654
+ id: V(),
610
655
  role: "assistant",
611
656
  created_at: (/* @__PURE__ */ new Date()).toISOString()
612
657
  }];
613
658
  }
614
- function Oe(e) {
659
+ function Ne(e) {
615
660
  if (e.answer !== void 0)
616
661
  return e.answer;
617
662
  let n = 0, s = "";
@@ -620,7 +665,7 @@ function Oe(e) {
620
665
  return s;
621
666
  }
622
667
  function Le(e, n, s, a, t) {
623
- if (!(e === z.Partial || e === z.Answer))
668
+ if (!(e === L.Partial || e === L.Answer))
624
669
  return;
625
670
  const r = a.messages[a.messages.length - 1];
626
671
  if ((r == null ? void 0 : r.role) !== "assistant")
@@ -629,131 +674,123 @@ function Le(e, n, s, a, t) {
629
674
  content: i,
630
675
  sequence: o
631
676
  } = n;
632
- e === z.Partial ? s[o] = i : s.answer = i;
633
- const d = Oe(s);
634
- (r.content !== d || e === z.Answer) && (r.content = d, t == null || t([...a.messages], e));
677
+ e === L.Partial ? s[o] = i : s.answer = i;
678
+ const l = Ne(s);
679
+ (r.content !== l || e === L.Answer) && (r.content = l, t == null || t([...a.messages], e));
635
680
  }
636
- async function ze(e, n) {
637
- var w, P, L;
681
+ async function Fe(e, n) {
682
+ var y, $, P;
638
683
  let s = {}, a = !0;
639
684
  const t = {
640
685
  messages: [],
641
686
  chatMode: n.mode || I.Functional
642
- }, r = n.baseURL || V, i = n.wsURL || we, o = n.mixpanelKey || fe, d = te(n.auth, r, n.callbacks.onError), g = await d.getById(e), h = Ne(g);
643
- t.messages = Z(h, n.initialMessages), (P = (w = n.callbacks).onNewMessage) == null || P.call(w, [...t.messages], "answer");
644
- const m = Ae({
687
+ }, r = n.baseURL || U, i = n.wsURL || ue, o = n.mixpanelKey || he, l = G(n.auth, r, n.callbacks.onError), d = await l.getById(e), u = xe(d);
688
+ t.messages = z(u, n.initialMessages), ($ = (y = n.callbacks).onNewMessage) == null || $.call(y, [...t.messages], "answer");
689
+ const g = $e({
645
690
  token: o,
646
- agent: g,
691
+ agent: d,
647
692
  isEnabled: n.enableAnalitics,
648
693
  distinctId: n.distinctId
649
694
  });
650
- m.track("agent-sdk", {
695
+ g.track("agent-sdk", {
651
696
  event: "loaded",
652
- ...be(g)
697
+ ...Ae(d)
653
698
  });
654
- const C = {
655
- onMessage: (c, u) => {
656
- var f, k;
657
- if ("content" in u)
658
- Le(c, u, s, t, n.callbacks.onNewMessage), c === z.Answer && m.track("agent-message-received", {
699
+ const h = {
700
+ onMessage: (c, w) => {
701
+ var p, S;
702
+ if ("content" in w)
703
+ Le(c, w, s, t, n.callbacks.onNewMessage), c === L.Answer && g.track("agent-message-received", {
659
704
  messages: t.messages.length,
660
705
  mode: t.chatMode
661
706
  });
662
707
  else {
663
- const l = H, p = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], M = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], v = Pe(u, g, {
708
+ const m = j, f = [m.StreamVideoDone, m.StreamVideoError, m.StreamVideoRejected], k = [m.StreamFailed, m.StreamVideoError, m.StreamVideoRejected], E = Pe(w, d, {
664
709
  mode: t.chatMode
665
710
  });
666
- if (c = c, c === l.StreamVideoCreated)
667
- m.linkTrack("agent-video", v, l.StreamVideoCreated, ["start"]);
668
- else if (p.includes(c)) {
711
+ if (c = c, c === m.StreamVideoCreated)
712
+ g.linkTrack("agent-video", E, m.StreamVideoCreated, ["start"]);
713
+ else if (f.includes(c)) {
669
714
  const R = c.split("/")[1];
670
- m.track("agent-video", {
671
- ...v,
715
+ g.track("agent-video", {
716
+ ...E,
672
717
  event: R
673
718
  });
674
719
  }
675
- M.includes(c) && ((k = (f = n.callbacks).onError) == null || k.call(f, new Error(`Stream failed with event ${c}`), {
676
- data: u
677
- })), u.event === l.StreamDone && E();
720
+ k.includes(c) && ((S = (p = n.callbacks).onError) == null || S.call(p, new Error(`Stream failed with event ${c}`), {
721
+ data: w
722
+ })), w.event === m.StreamDone && v();
678
723
  }
679
724
  }
680
725
  };
681
- async function y(c) {
682
- var R, A, K, T, b, D, W;
683
- (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R, S.Connecting), O = 0;
684
- const u = 3;
685
- c && !a && (delete t.chat, t.messages = Z(h), (T = (K = n.callbacks).onNewMessage) == null || T.call(K, [...t.messages], "answer"));
686
- const f = n.mode === I.DirectPlayback ? Promise.resolve(void 0) : _e(n.auth, i, C);
687
- async function k() {
688
- var F, N, U;
689
- for (let X = 1; X <= u; X++)
690
- try {
691
- const $ = await xe(g, n, d, m, t.chat, c ? h : void 0);
692
- return $.chat && $.chat.id !== ((F = t.chat) == null ? void 0 : F.id) && (t.chat = $.chat, (U = (N = n.callbacks).onNewChat) == null || U.call(N, $.chat.id)), $;
693
- } catch ($) {
694
- if (($ == null ? void 0 : $.message) !== "Could not connect")
695
- throw $;
696
- }
697
- throw new Error("Could not connect");
698
- }
699
- const l = k().catch((F) => {
700
- var N, U;
701
- throw _(I.Maintenance), (U = (N = n.callbacks).onConnectionStateChange) == null || U.call(N, S.Fail), F;
702
- }), [p, {
703
- streamingManager: M,
704
- chat: v
705
- }] = await Promise.all([f, l]);
706
- v && v.id !== ((b = t.chat) == null ? void 0 : b.id) && ((W = (D = n.callbacks).onNewChat) == null || W.call(D, v.id)), t.streamingManager = M, t.socketManager = p, t.chat = v, a = !1, _((v == null ? void 0 : v.chat_mode) ?? n.mode ?? I.Functional);
726
+ async function C(c) {
727
+ var k, E, R, b, K, D, T;
728
+ (E = (k = n.callbacks).onConnectionStateChange) == null || E.call(k, M.Connecting), N = 0, c && !a && (delete t.chat, t.messages = z(u), (b = (R = n.callbacks).onNewMessage) == null || b.call(R, [...t.messages], "answer"));
729
+ const w = n.mode === I.DirectPlayback ? Promise.resolve(void 0) : Ce(n.auth, i, h), p = X(() => De(d, n, l, g, t.chat, c ? u : void 0), {
730
+ limit: 3,
731
+ timeout: be,
732
+ timeoutErrorMessage: "Could not connect",
733
+ // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
734
+ shouldRetryFn: (A) => (A == null ? void 0 : A.message) !== "Could not connect" && A.status !== 429,
735
+ delayMs: 1e3
736
+ }).catch((A) => {
737
+ var W, B;
738
+ throw _(I.Maintenance), (B = (W = n.callbacks).onConnectionStateChange) == null || B.call(W, M.Fail), A;
739
+ }), [S, {
740
+ streamingManager: m,
741
+ chat: f
742
+ }] = await Promise.all([w, p]);
743
+ f && f.id !== ((K = t.chat) == null ? void 0 : K.id) && ((T = (D = n.callbacks).onNewChat) == null || T.call(D, f.id)), t.streamingManager = m, t.socketManager = S, t.chat = f, a = !1, _((f == null ? void 0 : f.chat_mode) ?? n.mode ?? I.Functional);
707
744
  }
708
- async function E() {
709
- var c, u, f, k;
710
- (c = t.socketManager) == null || c.disconnect(), await ((u = t.streamingManager) == null ? void 0 : u.disconnect()), delete t.streamingManager, delete t.socketManager, (k = (f = n.callbacks).onConnectionStateChange) == null || k.call(f, S.Disconnected);
745
+ async function v() {
746
+ var c, w, p, S;
747
+ (c = t.socketManager) == null || c.disconnect(), await ((w = t.streamingManager) == null ? void 0 : w.disconnect()), delete t.streamingManager, delete t.socketManager, (S = (p = n.callbacks).onConnectionStateChange) == null || S.call(p, M.Disconnected);
711
748
  }
712
749
  async function _(c) {
713
- var u, f;
714
- c !== t.chatMode && (m.track("agent-mode-change", {
750
+ var w, p;
751
+ c !== t.chatMode && (g.track("agent-mode-change", {
715
752
  mode: c
716
- }), t.chatMode = c, t.chatMode !== I.Functional && await E(), (f = (u = n.callbacks).onModeChange) == null || f.call(u, c));
753
+ }), t.chatMode = c, t.chatMode !== I.Functional && await v(), (p = (w = n.callbacks).onModeChange) == null || p.call(w, c));
717
754
  }
718
755
  return {
719
- agent: g,
720
- starterMessages: ((L = g.knowledge) == null ? void 0 : L.starter_message) || [],
721
- getSTTToken: () => d.getSTTToken(g.id),
756
+ agent: d,
757
+ starterMessages: ((P = d.knowledge) == null ? void 0 : P.starter_message) || [],
758
+ getSTTToken: () => l.getSTTToken(d.id),
722
759
  changeMode: _,
723
- enrichAnalytics: m.enrich,
760
+ enrichAnalytics: g.enrich,
724
761
  async connect() {
725
762
  var c;
726
- await y(!0), m.track("agent-chat", {
763
+ await C(!0), g.track("agent-chat", {
727
764
  event: "connect",
728
765
  chatId: (c = t.chat) == null ? void 0 : c.id,
729
- agentId: g.id,
766
+ agentId: d.id,
730
767
  mode: t.chatMode
731
768
  });
732
769
  },
733
770
  async reconnect() {
734
771
  var c;
735
- await E(), await y(!1), m.track("agent-chat", {
772
+ await v(), await C(!1), g.track("agent-chat", {
736
773
  event: "reconnect",
737
774
  chatId: (c = t.chat) == null ? void 0 : c.id,
738
- agentId: g.id,
775
+ agentId: d.id,
739
776
  mode: t.chatMode
740
777
  });
741
778
  },
742
779
  async disconnect() {
743
780
  var c;
744
- await E(), m.track("agent-chat", {
781
+ await v(), g.track("agent-chat", {
745
782
  event: "disconnect",
746
783
  chatId: (c = t.chat) == null ? void 0 : c.id,
747
- agentId: g.id,
784
+ agentId: d.id,
748
785
  mode: t.chatMode
749
786
  });
750
787
  },
751
788
  async chat(c) {
752
- var f, k, l, p, M, v;
753
- const u = B();
789
+ var p, S, m, f, k, E;
790
+ const w = V();
754
791
  s = {};
755
792
  try {
756
- if (O = Date.now(), n.mode === I.DirectPlayback)
793
+ if (N = Date.now(), n.mode === I.DirectPlayback)
757
794
  throw new Error("Direct playback is enabled, chat is disabled");
758
795
  if (c.length >= 800)
759
796
  throw new Error("Message cannot be more than 800 characters");
@@ -768,148 +805,148 @@ async function ze(e, n) {
768
805
  } else
769
806
  throw new Error("Streaming manager is not initialized");
770
807
  t.messages.push({
771
- id: B(),
808
+ id: V(),
772
809
  role: "user",
773
810
  content: c,
774
- created_at: new Date(O).toISOString()
775
- }), (k = (f = n.callbacks).onNewMessage) == null || k.call(f, [...t.messages], "user"), t.chat || (t.chat = await ae(g.id, d, m, t.chatMode, n.persistentChat), (p = (l = n.callbacks).onNewChat) == null || p.call(l, t.chat.id));
811
+ created_at: new Date(N).toISOString()
812
+ }), (S = (p = n.callbacks).onNewMessage) == null || S.call(p, [...t.messages], "user"), t.chat || (t.chat = await te(d.id, l, g, t.chatMode, n.persistentChat), (f = (m = n.callbacks).onNewChat) == null || f.call(m, t.chat.id));
776
813
  const R = {
777
- id: u,
814
+ id: w,
778
815
  role: "assistant",
779
816
  content: "",
780
817
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
781
818
  matches: []
782
- }, A = [...t.messages];
819
+ }, b = [...t.messages];
783
820
  t.messages.push(R);
784
- const K = (b) => {
785
- var D, W;
786
- return d.chat(g.id, b, {
787
- sessionId: (D = t.streamingManager) == null ? void 0 : D.sessionId,
821
+ const K = (T) => {
822
+ var A, W;
823
+ return l.chat(d.id, T, {
824
+ sessionId: (A = t.streamingManager) == null ? void 0 : A.sessionId,
788
825
  streamId: (W = t.streamingManager) == null ? void 0 : W.streamId,
789
826
  chatMode: t.chatMode,
790
- messages: A.map(({
791
- matches: F,
792
- ...N
793
- }) => N)
794
- }, re(t.chatMode));
795
- }, T = await K(t.chat.id).catch(async (b) => {
796
- var D;
797
- if (!((D = b == null ? void 0 : b.message) != null && D.includes("missing or invalid session_id")))
798
- throw b;
799
- return await E(), await y(!1), K(t.chat.id);
827
+ messages: b.map(({
828
+ matches: B,
829
+ ...ne
830
+ }) => ne)
831
+ }, ee(t.chatMode));
832
+ }, D = await K(t.chat.id).catch(async (T) => {
833
+ var A;
834
+ if (!((A = T == null ? void 0 : T.message) != null && A.includes("missing or invalid session_id")))
835
+ throw T;
836
+ return await v(), await C(!1), K(t.chat.id);
800
837
  });
801
- return m.track("agent-message-send", {
838
+ return g.track("agent-message-send", {
802
839
  event: "success",
803
840
  mode: t.chatMode,
804
841
  messages: t.messages.length + 1
805
- }), R.context = T.context, R.matches = T.matches, T.result && (R.content = T.result, m.track("agent-message-received", {
806
- latency: Date.now() - O,
842
+ }), R.context = D.context, R.matches = D.matches, D.result && (R.content = D.result, g.track("agent-message-received", {
843
+ latency: Date.now() - N,
807
844
  mode: t.chatMode,
808
845
  messages: t.messages.length
809
- }), (v = (M = n.callbacks).onNewMessage) == null || v.call(M, [...t.messages], "answer")), T;
846
+ }), (E = (k = n.callbacks).onNewMessage) == null || E.call(k, [...t.messages], "answer")), D;
810
847
  } catch (R) {
811
- throw t.messages[t.messages.length - 1].id === u && t.messages.pop(), m.track("agent-message-send", {
848
+ throw t.messages[t.messages.length - 1].id === w && t.messages.pop(), g.track("agent-message-send", {
812
849
  event: "error",
813
850
  mode: t.chatMode,
814
851
  messages: t.messages.length
815
852
  }), R;
816
853
  }
817
854
  },
818
- rate(c, u, f) {
819
- var p, M, v, R;
820
- const k = t.messages.find((A) => A.id === c);
855
+ rate(c, w, p) {
856
+ var f, k, E, R;
857
+ const S = t.messages.find((b) => b.id === c);
821
858
  if (t.chat) {
822
- if (!k)
859
+ if (!S)
823
860
  throw new Error("Message not found");
824
861
  } else
825
862
  throw new Error("Chat is not initialized");
826
- const l = ((p = k.matches) == null ? void 0 : p.map((A) => [A.document_id, A.id])) ?? [];
827
- return m.track("agent-rate", {
828
- event: f ? "update" : "create",
829
- thumb: u === 1 ? "up" : "down",
830
- knowledge_id: ((M = g.knowledge) == null ? void 0 : M.id) ?? "",
863
+ const m = ((f = S.matches) == null ? void 0 : f.map((b) => [b.document_id, b.id])) ?? [];
864
+ return g.track("agent-rate", {
865
+ event: p ? "update" : "create",
866
+ thumb: w === 1 ? "up" : "down",
867
+ knowledge_id: ((k = d.knowledge) == null ? void 0 : k.id) ?? "",
831
868
  mode: t.chatMode,
832
- matches: l,
833
- score: u
834
- }), f ? d.updateRating(g.id, t.chat.id, f, {
835
- knowledge_id: ((v = g.knowledge) == null ? void 0 : v.id) ?? "",
869
+ matches: m,
870
+ score: w
871
+ }), p ? l.updateRating(d.id, t.chat.id, p, {
872
+ knowledge_id: ((E = d.knowledge) == null ? void 0 : E.id) ?? "",
836
873
  message_id: c,
837
- matches: l,
838
- score: u
839
- }) : d.createRating(g.id, t.chat.id, {
840
- knowledge_id: ((R = g.knowledge) == null ? void 0 : R.id) ?? "",
874
+ matches: m,
875
+ score: w
876
+ }) : l.createRating(d.id, t.chat.id, {
877
+ knowledge_id: ((R = d.knowledge) == null ? void 0 : R.id) ?? "",
841
878
  message_id: c,
842
- matches: l,
843
- score: u
879
+ matches: m,
880
+ score: w
844
881
  });
845
882
  },
846
883
  deleteRate(c) {
847
- var u;
884
+ var w;
848
885
  if (!t.chat)
849
886
  throw new Error("Chat is not initialized");
850
- return m.track("agent-rate-delete", {
887
+ return g.track("agent-rate-delete", {
851
888
  type: "text",
852
- chat_id: (u = t.chat) == null ? void 0 : u.id,
889
+ chat_id: (w = t.chat) == null ? void 0 : w.id,
853
890
  id: c,
854
891
  mode: t.chatMode
855
- }), d.deleteRating(g.id, t.chat.id, c);
892
+ }), l.deleteRating(d.id, t.chat.id, c);
856
893
  },
857
894
  speak(c) {
858
895
  if (!t.streamingManager)
859
896
  throw new Error("Please connect to the agent first");
860
- function u() {
897
+ function w() {
861
898
  if (typeof c == "string") {
862
- if (!g.presenter.voice)
899
+ if (!d.presenter.voice)
863
900
  throw new Error("Presenter voice is not initialized");
864
901
  return {
865
902
  type: "text",
866
- provider: g.presenter.voice,
903
+ provider: d.presenter.voice,
867
904
  input: c,
868
905
  ssml: !1
869
906
  };
870
907
  }
871
908
  if (c.type === "text" && !c.provider) {
872
- if (!g.presenter.voice)
909
+ if (!d.presenter.voice)
873
910
  throw new Error("Presenter voice is not initialized");
874
911
  return {
875
912
  type: "text",
876
- provider: g.presenter.voice,
913
+ provider: d.presenter.voice,
877
914
  input: c.input,
878
915
  ssml: c.ssml
879
916
  };
880
917
  }
881
918
  return c;
882
919
  }
883
- const f = u();
884
- return m.track("agent-speak", f), t.streamingManager.speak({
885
- script: f
920
+ const p = w();
921
+ return g.track("agent-speak", p), t.streamingManager.speak({
922
+ script: p
886
923
  });
887
924
  }
888
925
  };
889
926
  }
890
- function je(e, n, s) {
927
+ function Ke(e, n, s) {
891
928
  const {
892
929
  getById: a
893
- } = te(n, s || V);
930
+ } = G(n, s || U);
894
931
  return a(e);
895
932
  }
896
933
  export {
897
- oe as AgentStatus,
934
+ ie as AgentStatus,
898
935
  I as ChatMode,
899
- z as ChatProgress,
900
- S as ConnectionState,
901
- ge as DocumentType,
902
- le as KnowledgeType,
903
- se as PlanGroup,
904
- ue as Providers,
905
- ce as RateState,
906
- H as StreamEvents,
907
- j as StreamingState,
908
- de as Subject,
909
- ie as UserPlan,
910
- G as VideoType,
911
- he as VoiceAccess,
912
- ze as createAgentManager,
913
- je as getAgent,
914
- me as mapVideoType
936
+ L as ChatProgress,
937
+ M as ConnectionState,
938
+ de as DocumentType,
939
+ ce as KnowledgeType,
940
+ ae as PlanGroup,
941
+ me as Providers,
942
+ se as RateState,
943
+ j as StreamEvents,
944
+ F as StreamingState,
945
+ oe as Subject,
946
+ re as UserPlan,
947
+ O as VideoType,
948
+ ge as VoiceAccess,
949
+ Fe as createAgentManager,
950
+ Ke as getAgent,
951
+ le as mapVideoType
915
952
  };