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

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 = (y) => {
116
+ console.error(y), l == null || l("Websocket failed to connect", y), c(y);
117
+ }, h.onopen = (y) => {
118
+ s == null || s(y), 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,196 +208,199 @@ 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 P = (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,
292
+ close: h,
293
293
  createStream: y,
294
- addIceCandidate: x
295
- } = a.videoType === _.Clip ? we(r, s, e, i.onError) : he(r, s, e, i.onError), {
294
+ addIceCandidate: D
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
- session_id: R
300
- } = await y(a), o = new fe({
299
+ session_id: A
300
+ } = await y(r), o = new fe({
301
301
  iceServers: z
302
- }), m = o.createDataChannel("JanusDataChannel");
303
- if (!R)
302
+ }), u = o.createDataChannel("JanusDataChannel");
303
+ if (!A)
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
+ P("peerConnection.onicecandidate", g), g.candidate && g.candidate.sdpMid && g.candidate.sdpMLineIndex !== null ? D(I, {
308
308
  candidate: g.candidate.candidate,
309
309
  sdpMid: g.candidate.sdpMid,
310
310
  sdpMLineIndex: g.candidate.sdpMLineIndex
311
- }, R) : x(I, {
311
+ }, A) : D(I, {
312
312
  candidate: null
313
- }, R);
313
+ }, A);
314
314
  }, o.oniceconnectionstatechange = () => {
315
- var u;
316
- T("peerConnection.oniceconnectionstatechange => " + o.iceConnectionState);
315
+ var m;
316
+ P("peerConnection.oniceconnectionstatechange => " + o.iceConnectionState);
317
317
  const g = H(o.iceConnectionState);
318
- g === E.Connected ? c = setTimeout(() => {
318
+ g === k.Connected ? s = setTimeout(() => {
319
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));
320
+ (p = t.onConnectionStateChange) == null || p.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
+ P("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 [p, w] = g.data.split(":");
329
+ p === 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");
331
+ }, await o.setRemoteDescription(L), P("set remote description OK");
332
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"), {
333
+ return P("create answer OK"), await o.setLocalDescription(S), P("set local description OK"), await d(I, S, A), P("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
337
337
  */
338
338
  speak(g) {
339
- return l(I, R, g);
339
+ return l(I, A, g);
340
340
  },
341
341
  /**
342
342
  * Method to close RTC connection
343
343
  */
344
344
  async disconnect() {
345
- var g, u, p;
345
+ var g, m, p;
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, A).catch((w) => {
356
356
  });
357
- } catch (v) {
358
- T("Error on close stream connection", v);
357
+ } catch (w) {
358
+ P("Error on close stream connection", w);
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), (p = t.onVideoStateChange) == null || p.call(t, x.Stop), clearInterval(f);
361
361
  }
362
362
  },
363
363
  /**
364
364
  * Session identifier information, should be returned in the body of all streaming requests
365
365
  */
366
- sessionId: R,
366
+ sessionId: A,
367
367
  /**
368
368
  * Id of current RTC stream
369
369
  */
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,54 @@ 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, y) => s.events[y] ? {
426
+ ...h,
427
+ ...s.events[y].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
454
  const Se = 1080;
452
- let N = 0;
453
- function Me(e, a) {
454
- var t, i, r;
455
+ let T = 0;
456
+ function Me(e, r) {
457
+ var c, t, a;
455
458
  if (e.presenter) {
456
- if (e.presenter.type === _.Clip)
459
+ if (e.presenter.type === v.Clip)
457
460
  return {
458
- videoType: _.Clip,
461
+ videoType: v.Clip,
459
462
  driver_id: e.presenter.driver_id,
460
463
  presenter_id: e.presenter.presenter_id,
461
464
  stream_warmup: !0
@@ -463,31 +466,31 @@ function Me(e, a) {
463
466
  } else
464
467
  throw new Error("Presenter is not initialized");
465
468
  return {
466
- videoType: _.Talk,
469
+ videoType: v.Talk,
467
470
  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)
471
+ session_timeout: (c = r == null ? void 0 : r.streamOptions) == null ? void 0 : c.session_timeout,
472
+ stream_warmup: ((t = r == null ? void 0 : r.streamOptions) == null ? void 0 : t.stream_warmup) ?? !0,
473
+ compatibility_mode: (a = r == null ? void 0 : r.streamOptions) == null ? void 0 : a.compatibility_mode,
474
+ output_resolution: (r == null ? void 0 : r.outputResolution) || (e.presenter.stitch ? Se : void 0)
472
475
  };
473
476
  }
474
- function Q(e) {
475
- return e === k.Playground ? {
476
- [ue]: "true"
477
+ function Y(e) {
478
+ return e === M.Playground ? {
479
+ [me]: "true"
477
480
  } : {};
478
481
  }
479
- async function Y(e, a, t, i) {
482
+ async function Z(e, r, c, t) {
480
483
  try {
481
- const r = await a.newChat(e, Q(i));
482
- return t.track("agent-chat", {
484
+ const a = await r.newChat(e, Y(t));
485
+ return c.track("agent-chat", {
483
486
  event: "created",
484
- chat_id: r.id,
487
+ chat_id: a.id,
485
488
  agent_id: e
486
- }), r;
487
- } catch (r) {
489
+ }), a;
490
+ } catch (a) {
488
491
  try {
489
- console.error(r);
490
- const n = JSON.parse(r.message);
492
+ console.error(a);
493
+ const n = JSON.parse(a.message);
491
494
  if ((n == null ? void 0 : n.kind) === "InsufficientCreditsError")
492
495
  throw new Error("InsufficientCreditsError");
493
496
  } catch (n) {
@@ -496,134 +499,152 @@ async function Y(e, a, t, i) {
496
499
  throw new Error("Cannot create new chat");
497
500
  }
498
501
  }
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,
502
+ function ke(e, r, c, t, a) {
503
+ return new Promise(async (n, i) => {
504
+ T = 0;
505
+ const s = await ve(e.id, Me(e, r), {
506
+ ...r,
507
+ analytics: t,
505
508
  callbacks: {
506
- ...a.callbacks,
509
+ ...r.callbacks,
507
510
  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);
511
+ var l, h;
512
+ d === k.Connected && (!a && r.mode !== M.DirectPlayback && (a = await Z(e.id, c, t, r.mode).catch((y) => {
513
+ i(y);
514
+ })), s ? n({
515
+ chat: a,
516
+ streamingManager: s
517
+ }) : a && i(new Error("Something went wrong while initializing the manager"))), (h = (l = r.callbacks).onConnectionStateChange) == null || h.call(l, d);
515
518
  },
516
519
  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", {
520
+ var l, h;
521
+ (h = (l = r.callbacks).onVideoStateChange) == null || h.call(l, d), T > 0 && d === x.Start && t.linkTrack("agent-video", {
519
522
  event: "start",
520
- latency: Date.now() - N
521
- }, "start", [U.StreamVideoCreated]);
523
+ latency: Date.now() - T
524
+ }, "start", [F.StreamVideoCreated]);
522
525
  }
523
526
  }
524
- }).catch(s);
527
+ }).catch(i);
525
528
  });
526
529
  }
527
530
  function W(e) {
528
- let a = "";
531
+ let r = "";
529
532
  if (e.greetings && e.greetings.length > 0) {
530
- const t = Math.floor(Math.random() * e.greetings.length);
531
- a = e.greetings[t];
533
+ const c = Math.floor(Math.random() * e.greetings.length);
534
+ r = e.greetings[c];
532
535
  } else
533
- a = `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
536
+ r = `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
534
537
  return [{
535
- content: a,
536
- id: F(),
538
+ content: r,
539
+ id: K(),
537
540
  role: "assistant",
538
541
  created_at: (/* @__PURE__ */ new Date()).toISOString()
539
542
  }];
540
543
  }
541
- async function Ee(e, a) {
542
- var L, z, R;
544
+ function Ie(e) {
545
+ if (e.answer !== void 0)
546
+ return e.answer;
547
+ let r = 0, c = "";
548
+ for (; r in e; )
549
+ c += e[r], r++;
550
+ return c;
551
+ }
552
+ function Re(e, r, c, t, a) {
553
+ if (!(e === N.Partial || e === N.Answer))
554
+ return;
555
+ const n = t.messages[t.messages.length - 1];
556
+ if ((n == null ? void 0 : n.role) !== "assistant")
557
+ return;
558
+ const {
559
+ content: i,
560
+ sequence: s
561
+ } = r;
562
+ e === N.Partial ? c[s] = i : c.answer = i;
563
+ const d = Ie(c);
564
+ n.content !== d && (n.content = d, a == null || a(t.messages, e));
565
+ }
566
+ async function Ee(e, r) {
567
+ var L, z, A;
568
+ let c = {};
543
569
  const t = {
544
570
  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");
571
+ chatMode: r.mode || M.Functional
572
+ }, 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);
573
+ t.messages = W(d), (z = (L = r.callbacks).onNewMessage) == null || z.call(L, t.messages, "answer");
550
574
  const l = Ce({
551
- token: s,
575
+ token: i,
552
576
  agent: d,
553
- ...a
577
+ ...r
554
578
  });
555
579
  l.track("agent-sdk", {
556
580
  event: "loaded",
557
581
  ..._e(d)
558
582
  });
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", {
583
+ const h = {
584
+ onMessage: (o, u) => {
585
+ var f, S, g, m, p;
586
+ if ("content" in u)
587
+ Re(o, u, c, t, r.callbacks.onNewMessage), o === N.Answer && l.track("agent-message-received", {
567
588
  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];
589
+ });
590
+ else {
591
+ const w = F, C = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], R = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected];
571
592
  o = o;
572
- const D = (g = d.llm) == null ? void 0 : g.template;
573
- if (o === h.StreamVideoCreated) {
593
+ const $ = (f = d.llm) == null ? void 0 : f.template;
594
+ if (o === w.StreamVideoCreated) {
574
595
  const {
575
- event: P,
576
- ...A
577
- } = m;
578
- A.llm = {
579
- ...A.llm,
580
- template: D
596
+ event: E,
597
+ ..._
598
+ } = u;
599
+ _.llm = {
600
+ ..._.llm,
601
+ template: $
581
602
  }, 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
603
+ ..._
604
+ }, w.StreamVideoCreated, ["start"]);
605
+ } else if (C.includes(o)) {
606
+ const E = o.split("/")[1], _ = {
607
+ ...u,
608
+ event: E
588
609
  };
589
- A.llm = {
590
- ...A.llm,
591
- template: D
610
+ _.llm = {
611
+ ..._.llm,
612
+ template: $
592
613
  }, l.track("agent-video", {
593
- ...A,
594
- event: P
614
+ ..._,
615
+ event: E
595
616
  });
596
617
  }
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));
618
+ R.includes(o) && ((g = (S = r.callbacks).onError) == null || g.call(S, new Error(`Stream failed with event ${o}`), {
619
+ data: u
620
+ })), u.event === w.StreamDone && ((p = (m = r.callbacks).onConnectionStateChange) == null || p.call(m, k.New));
600
621
  }
601
622
  }
602
623
  };
603
624
  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), $;
625
+ var p, w, C, R, $;
626
+ T = 0, o && (delete t.chat, t.messages = W(d), (w = (p = r.callbacks).onNewMessage) == null || w.call(p, t.messages, "answer"));
627
+ const u = r.mode === M.DirectPlayback ? Promise.resolve(void 0) : ue(r.auth, n, h), f = ke(d, r, s, l, t.chat).catch((E) => {
628
+ throw I(M.Maintenance), E;
608
629
  }), [S, {
609
630
  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);
631
+ chat: m
632
+ }] = await Promise.all([u, f]);
633
+ m && m.id !== ((C = t.chat) == null ? void 0 : C.id) && (($ = (R = r.callbacks).onNewChat) == null || $.call(R, m.id)), t.streamingManager = g, t.socketManager = S, t.chat = m, I((m == null ? void 0 : m.chat_mode) ?? r.mode ?? M.Functional);
613
634
  }
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;
635
+ async function D() {
636
+ var o, u;
637
+ (o = t.socketManager) == null || o.disconnect(), await ((u = t.streamingManager) == null ? void 0 : u.disconnect()), delete t.streamingManager, delete t.socketManager;
617
638
  }
618
639
  async function I(o) {
619
- var m, f;
640
+ var u, f;
620
641
  o !== t.chatMode && (l.track("agent-mode-change", {
621
642
  mode: o
622
- }), t.chatMode = o, t.chatMode !== k.Functional && await x(), (f = (m = a.callbacks).onModeChange) == null || f.call(m, o));
643
+ }), t.chatMode = o, t.chatMode !== M.Functional && await D(), (f = (u = r.callbacks).onModeChange) == null || f.call(u, o));
623
644
  }
624
645
  return {
625
646
  agent: d,
626
- starterMessages: ((R = d.knowledge) == null ? void 0 : R.starter_message) || [],
647
+ starterMessages: ((A = d.knowledge) == null ? void 0 : A.starter_message) || [],
627
648
  changeMode: I,
628
649
  async connect() {
629
650
  var o;
@@ -636,7 +657,7 @@ async function Ee(e, a) {
636
657
  },
637
658
  async reconnect() {
638
659
  var o;
639
- await x(), await y(!1), l.track("agent-chat", {
660
+ await D(), await y(!1), l.track("agent-chat", {
640
661
  event: "reconnect",
641
662
  chatId: (o = t.chat) == null ? void 0 : o.id,
642
663
  agentId: d.id,
@@ -645,7 +666,7 @@ async function Ee(e, a) {
645
666
  },
646
667
  async disconnect() {
647
668
  var o;
648
- await x(), l.track("agent-chat", {
669
+ await D(), l.track("agent-chat", {
649
670
  event: "disconnect",
650
671
  chatId: (o = t.chat) == null ? void 0 : o.id,
651
672
  agentId: d.id,
@@ -653,106 +674,107 @@ async function Ee(e, a) {
653
674
  });
654
675
  },
655
676
  async chat(o) {
656
- var f, S, g, u, p, v;
657
- const m = F();
677
+ var f, S, g, m, p, w;
678
+ const u = K();
679
+ c = {};
658
680
  try {
659
- if (N = Date.now(), a.mode === k.DirectPlayback)
681
+ if (T = Date.now(), r.mode === M.DirectPlayback)
660
682
  throw new Error("Direct playback is enabled, chat is disabled");
661
683
  if (o.length >= 800)
662
684
  throw new Error("Message cannot be more than 800 characters");
663
685
  if (o.length === 0)
664
686
  throw new Error("Message cannot be empty");
665
- if (t.chatMode === k.Maintenance)
687
+ if (t.chatMode === M.Maintenance)
666
688
  throw new Error("Chat is in maintenance mode");
667
- if (![k.TextOnly, k.Playground].includes(t.chatMode))
689
+ if (![M.TextOnly, M.Playground].includes(t.chatMode))
668
690
  if (t.streamingManager) {
669
691
  if (!t.chat)
670
692
  throw new Error("Chat is not initialized");
671
693
  } else
672
694
  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(),
695
+ t.chat || (t.chat = await Z(d.id, s, l, t.chatMode), (S = (f = r.callbacks).onNewChat) == null || S.call(f, t.chat.id)), t.messages.push({
696
+ id: K(),
675
697
  role: "user",
676
698
  content: o,
677
- created_at: new Date(N).toISOString()
678
- }), (u = (g = a.callbacks).onNewMessage) == null || u.call(g, t.messages, "user");
699
+ created_at: new Date(T).toISOString()
700
+ }), (m = (g = r.callbacks).onNewMessage) == null || m.call(g, t.messages, "user");
679
701
  const C = {
680
- id: m,
702
+ id: u,
681
703
  role: "assistant",
682
704
  content: "",
683
705
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
684
706
  matches: []
685
- }, h = [...t.messages];
707
+ }, R = [...t.messages];
686
708
  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,
709
+ const $ = (_) => {
710
+ var b, B;
711
+ return s.chat(d.id, _, {
712
+ sessionId: (b = t.streamingManager) == null ? void 0 : b.sessionId,
713
+ streamId: (B = t.streamingManager) == null ? void 0 : B.streamId,
692
714
  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);
715
+ messages: R
716
+ }, Y(t.chatMode));
717
+ }, E = await $(t.chat.id).catch(async (_) => {
718
+ var b;
719
+ if (!((b = _ == null ? void 0 : _.message) != null && b.includes("missing or invalid session_id")))
720
+ throw _;
721
+ return await D(), await y(!1), $(t.chat.id);
700
722
  });
701
723
  return l.track("agent-message-send", {
702
724
  event: "success",
703
725
  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,
726
+ }), E.result && (C.content = E.result, C.matches = E.matches, C.context = E.context, l.track("agent-message-received", {
727
+ latency: Date.now() - T,
706
728
  messages: t.messages.length
707
- }), (v = (p = a.callbacks).onNewMessage) == null || v.call(p, t.messages, "answer")), $;
729
+ }), (w = (p = r.callbacks).onNewMessage) == null || w.call(p, t.messages, "answer")), E;
708
730
  } catch (C) {
709
- throw t.messages[t.messages.length - 1].id === m && t.messages.pop(), l.track("agent-message-send", {
731
+ throw t.messages[t.messages.length - 1].id === u && t.messages.pop(), l.track("agent-message-send", {
710
732
  event: "error",
711
733
  messages: t.messages.length
712
734
  }), C;
713
735
  }
714
736
  },
715
- rate(o, m, f) {
716
- var u, p, v, C;
717
- const S = t.messages.find((h) => h.id === o);
737
+ rate(o, u, f) {
738
+ var m, p, w, C;
739
+ const S = t.messages.find((R) => R.id === o);
718
740
  if (t.chat) {
719
741
  if (!S)
720
742
  throw new Error("Message not found");
721
743
  } else
722
744
  throw new Error("Chat is not initialized");
723
- const g = ((u = S.matches) == null ? void 0 : u.map((h) => [h.document_id, h.id])) ?? [];
745
+ const g = ((m = S.matches) == null ? void 0 : m.map((R) => [R.document_id, R.id])) ?? [];
724
746
  return l.track("agent-rate", {
725
747
  event: f ? "update" : "create",
726
- thumb: m === 1 ? "up" : "down",
748
+ thumb: u === 1 ? "up" : "down",
727
749
  knowledge_id: ((p = d.knowledge) == null ? void 0 : p.id) ?? "",
728
750
  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) ?? "",
751
+ score: u
752
+ }), f ? s.updateRating(d.id, t.chat.id, f, {
753
+ knowledge_id: ((w = d.knowledge) == null ? void 0 : w.id) ?? "",
732
754
  message_id: o,
733
755
  matches: g,
734
- score: m
735
- }) : c.createRating(d.id, t.chat.id, {
756
+ score: u
757
+ }) : s.createRating(d.id, t.chat.id, {
736
758
  knowledge_id: ((C = d.knowledge) == null ? void 0 : C.id) ?? "",
737
759
  message_id: o,
738
760
  matches: g,
739
- score: m
761
+ score: u
740
762
  });
741
763
  },
742
764
  deleteRate(o) {
743
- var m;
765
+ var u;
744
766
  if (!t.chat)
745
767
  throw new Error("Chat is not initialized");
746
768
  return l.track("agent-rate-delete", {
747
769
  type: "text",
748
- chat_id: (m = t.chat) == null ? void 0 : m.id,
770
+ chat_id: (u = t.chat) == null ? void 0 : u.id,
749
771
  id: o
750
- }), c.deleteRating(d.id, t.chat.id, o);
772
+ }), s.deleteRating(d.id, t.chat.id, o);
751
773
  },
752
774
  speak(o) {
753
775
  if (!t.streamingManager)
754
776
  throw new Error("Please connect to the agent first");
755
- function m() {
777
+ function u() {
756
778
  if (typeof o == "string") {
757
779
  if (!d.presenter)
758
780
  throw new Error("Presenter is not initialized");
@@ -765,34 +787,34 @@ async function Ee(e, a) {
765
787
  }
766
788
  return o;
767
789
  }
768
- const f = m();
790
+ const f = u();
769
791
  return l.track("agent-speak", f), t.streamingManager.speak({
770
792
  script: f
771
793
  });
772
794
  }
773
795
  };
774
796
  }
775
- function Ie(e, a, t) {
797
+ function Ae(e, r, c) {
776
798
  const {
777
- getById: i
778
- } = q(a, t || O);
779
- return i(e);
799
+ getById: t
800
+ } = j(r, c || O);
801
+ return t(e);
780
802
  }
781
803
  export {
782
- k as ChatMode,
783
- K as ChatProgress,
784
- E as ConnectionState,
804
+ M as ChatMode,
805
+ N as ChatProgress,
806
+ k as ConnectionState,
785
807
  re as DocumentType,
786
808
  ne as KnowledgeType,
787
809
  G as PlanGroup,
788
810
  ae as Providers,
789
811
  ee as RateState,
790
- U as StreamEvents,
791
- b as StreamingState,
812
+ F as StreamEvents,
813
+ x as StreamingState,
792
814
  te as Subject,
793
- Z as UserPlan,
794
- _ as VideoType,
815
+ Q as UserPlan,
816
+ v as VideoType,
795
817
  ie as VoiceAccess,
796
818
  Ee as createAgentManager,
797
- Ie as getAgent
819
+ Ae as getAgent
798
820
  };