@d-id/client-sdk 1.0.19-beta.90 → 1.0.19-beta.91

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