@d-id/client-sdk 1.0.19-beta.115 → 1.0.19-beta.117

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