@d-id/client-sdk 1.0.19-beta.106 → 1.0.19-beta.108

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