@d-id/client-sdk 1.0.19-beta.71 → 1.0.19-beta.73

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