@d-id/client-sdk 1.0.19-beta.146 → 1.0.19-beta.147

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,5 +1,5 @@
1
- var re = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(re || {}), ae = /* @__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))(ae || {}), ie = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ie || {}), se = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(se || {}), E = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(E || {}), N = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(N || {}), oe = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(oe || {}), ce = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ce || {}), de = /* @__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))(de || {}), O = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(O || {});
2
- const le = (e) => {
1
+ var ie = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ie || {}), se = /* @__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))(se || {}), oe = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(oe || {}), ce = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ce || {}), I = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(I || {}), B = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(B || {}), de = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(de || {}), le = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(le || {}), me = /* @__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))(me || {}), Z = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(Z || {});
2
+ const ue = (e) => {
3
3
  switch (e) {
4
4
  case "clip":
5
5
  return "clip";
@@ -9,585 +9,594 @@ const le = (e) => {
9
9
  throw new Error(`Unknown video type: ${e}`);
10
10
  }
11
11
  };
12
- var x = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(x || {}), W = /* @__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))(W || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), me = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(me || {}), ue = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ue || {});
13
- const H = "https://api.d-id.com", fe = "wss://notifications.d-id.com", ge = "79f81a83a67430be2bc0fd61042b8faa";
14
- async function X(e, n) {
15
- const s = {
16
- limit: (n == null ? void 0 : n.limit) ?? 3,
17
- delayMs: (n == null ? void 0 : n.delayMs) ?? 0,
18
- timeout: (n == null ? void 0 : n.timeout) ?? 3e4,
19
- timeoutErrorMessage: (n == null ? void 0 : n.timeoutErrorMessage) || "Timeout error",
20
- shouldRetryFn: (n == null ? void 0 : n.shouldRetryFn) ?? function() {
12
+ var j = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(j || {}), W = /* @__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))(W || {}), D = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(D || {}), fe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(fe || {}), ge = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ge || {});
13
+ const H = "https://api.d-id.com", he = "wss://notifications.d-id.com", we = "79f81a83a67430be2bc0fd61042b8faa";
14
+ async function G(e, t) {
15
+ const i = {
16
+ limit: (t == null ? void 0 : t.limit) ?? 3,
17
+ delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
18
+ timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
19
+ timeoutErrorMessage: (t == null ? void 0 : t.timeoutErrorMessage) || "Timeout error",
20
+ shouldRetryFn: (t == null ? void 0 : t.shouldRetryFn) ?? function() {
21
21
  return !0;
22
22
  }
23
23
  };
24
- let i;
25
- for (let t = 1; t <= s.limit; t++)
24
+ let a;
25
+ for (let n = 1; n <= i.limit; n++)
26
26
  try {
27
- if (!s.timeout)
27
+ if (!i.timeout)
28
28
  return await e();
29
- let a;
30
- const r = new Promise((d, u) => {
31
- e().then((l) => {
32
- clearTimeout(a), d(l);
33
- }).catch((l) => {
34
- clearTimeout(a), u(l);
29
+ let s;
30
+ const r = new Promise((d, f) => {
31
+ e().then((m) => {
32
+ clearTimeout(s), d(m);
33
+ }).catch((m) => {
34
+ clearTimeout(s), f(m);
35
35
  });
36
- }), o = new Promise((d, u) => {
37
- a = setTimeout(() => u(new Error(s.timeoutErrorMessage)), s.timeout);
36
+ }), o = new Promise((d, f) => {
37
+ s = setTimeout(() => f(new Error(i.timeoutErrorMessage)), i.timeout);
38
38
  });
39
39
  return await Promise.race([r, o]);
40
- } catch (a) {
41
- if (i = a, !s.shouldRetryFn(a) || t >= s.limit)
42
- throw a;
43
- s.delayMs > 0 && await new Promise((r) => setTimeout(r, s.delayMs));
40
+ } catch (s) {
41
+ if (a = s, !i.shouldRetryFn(s) || n >= i.limit)
42
+ throw s;
43
+ i.delayMs > 0 && await new Promise((r) => setTimeout(r, i.delayMs));
44
44
  }
45
- throw i;
45
+ throw a;
46
46
  }
47
- const K = () => Math.random().toString(16).slice(2);
48
- function Y() {
47
+ const V = () => Math.random().toString(16).slice(2);
48
+ function Q() {
49
49
  let e = window.localStorage.getItem("did_external_key_id");
50
50
  return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
51
51
  }
52
- let he = K();
53
- function Z(e) {
52
+ let pe = V();
53
+ function ee(e) {
54
54
  if (e.type === "bearer")
55
55
  return `Bearer ${e.token}`;
56
56
  if (e.type === "basic")
57
57
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
58
58
  if (e.type === "key")
59
- return `Client-Key ${e.clientKey}.${Y()}_${he}`;
59
+ return `Client-Key ${e.clientKey}.${Q()}_${pe}`;
60
60
  throw new Error(`Unknown auth type: ${e}`);
61
61
  }
62
- const we = (e) => X(e, {
62
+ const ye = (e) => G(e, {
63
63
  limit: 3,
64
64
  delayMs: 1e3,
65
65
  timeout: 0,
66
- shouldRetryFn: (n) => n.status === 429
66
+ shouldRetryFn: (t) => t.status === 429
67
67
  });
68
- function B(e, n = H, s) {
69
- const i = async (t, a) => {
70
- const r = await we(() => fetch(n + (t != null && t.startsWith("/") ? t : `/${t}`), {
71
- ...a,
68
+ function q(e, t = H, i) {
69
+ const a = async (n, s) => {
70
+ const {
71
+ skipErrorHandler: r,
72
+ ...o
73
+ } = s || {}, l = await ye(() => fetch(t + (n != null && n.startsWith("/") ? n : `/${n}`), {
74
+ ...o,
72
75
  headers: {
73
- ...a == null ? void 0 : a.headers,
74
- Authorization: Z(e),
76
+ ...o.headers,
77
+ Authorization: ee(e),
75
78
  "Content-Type": "application/json"
76
79
  }
77
80
  }));
78
- if (!r.ok) {
79
- let o = await r.text().catch(() => "Failed to fetch");
80
- throw s && s(new Error(o), {
81
- url: t,
82
- options: a,
83
- headers: r.headers
84
- }), new Error(o);
81
+ if (!l.ok) {
82
+ let d = await l.text().catch(() => "Failed to fetch");
83
+ throw i && !r && i(new Error(d), {
84
+ url: n,
85
+ options: o,
86
+ headers: l.headers
87
+ }), new Error(d);
85
88
  }
86
- return r.json();
89
+ return l.json();
87
90
  };
88
91
  return {
89
- get(t, a) {
90
- return i(t, {
91
- ...a,
92
+ get(n, s) {
93
+ return a(n, {
94
+ ...s,
92
95
  method: "GET"
93
96
  });
94
97
  },
95
- post(t, a, r) {
96
- return i(t, {
98
+ post(n, s, r) {
99
+ return a(n, {
97
100
  ...r,
98
- body: JSON.stringify(a),
101
+ body: JSON.stringify(s),
99
102
  method: "POST"
100
103
  });
101
104
  },
102
- delete(t, a, r) {
103
- return i(t, {
105
+ delete(n, s, r) {
106
+ return a(n, {
104
107
  ...r,
105
- body: JSON.stringify(a),
108
+ body: JSON.stringify(s),
106
109
  method: "DELETE"
107
110
  });
108
111
  },
109
- patch(t, a, r) {
110
- return i(t, {
112
+ patch(n, s, r) {
113
+ return a(n, {
111
114
  ...r,
112
- body: JSON.stringify(a),
115
+ body: JSON.stringify(s),
113
116
  method: "PATCH"
114
117
  });
115
118
  }
116
119
  };
117
120
  }
118
- function G(e, n = H, s) {
119
- const i = B(e, `${n}/agents`, s);
121
+ function te(e, t = H, i) {
122
+ const a = q(e, `${t}/agents`, i);
120
123
  return {
121
- create(t, a) {
122
- return i.post("/", t, a);
124
+ create(n, s) {
125
+ return a.post("/", n, s);
123
126
  },
124
- getAgents(t, a) {
125
- return i.get(`/${t ? `?tag=${t}` : ""}`, a).then((r) => r ?? []);
127
+ getAgents(n, s) {
128
+ return a.get(`/${n ? `?tag=${n}` : ""}`, s).then((r) => r ?? []);
126
129
  },
127
- getById(t, a) {
128
- return i.get(`/${t}`, a);
130
+ getById(n, s) {
131
+ return a.get(`/${n}`, s);
129
132
  },
130
- delete(t, a) {
131
- return i.delete(`/${t}`, void 0, a);
133
+ delete(n, s) {
134
+ return a.delete(`/${n}`, void 0, s);
132
135
  },
133
- update(t, a, r) {
134
- return i.patch(`/${t}`, a, r);
136
+ update(n, s, r) {
137
+ return a.patch(`/${n}`, s, r);
135
138
  },
136
- newChat(t, a, r) {
137
- return i.post(`/${t}/chat`, a, r);
139
+ newChat(n, s, r) {
140
+ return a.post(`/${n}/chat`, s, r);
138
141
  },
139
- chat(t, a, r, o) {
140
- return i.post(`/${t}/chat/${a}`, r, o);
142
+ chat(n, s, r, o) {
143
+ return a.post(`/${n}/chat/${s}`, r, o);
141
144
  },
142
- createRating(t, a, r, o) {
143
- return i.post(`/${t}/chat/${a}/ratings`, r, o);
145
+ createRating(n, s, r, o) {
146
+ return a.post(`/${n}/chat/${s}/ratings`, r, o);
144
147
  },
145
- updateRating(t, a, r, o, f) {
146
- return i.patch(`/${t}/chat/${a}/ratings/${r}`, o, f);
148
+ updateRating(n, s, r, o, l) {
149
+ return a.patch(`/${n}/chat/${s}/ratings/${r}`, o, l);
147
150
  },
148
- deleteRating(t, a, r, o) {
149
- return i.delete(`/${t}/chat/${a}/ratings/${r}`, o);
151
+ deleteRating(n, s, r, o) {
152
+ return a.delete(`/${n}/chat/${s}/ratings/${r}`, o);
150
153
  },
151
- getSTTToken(t, a) {
152
- return i.get(`/${t}/stt-token`, a);
154
+ getSTTToken(n, s) {
155
+ return a.get(`/${n}/stt-token`, s);
153
156
  }
154
157
  };
155
158
  }
156
- const pe = (e) => new Promise((n) => setTimeout(n, e));
157
- function ye(e) {
158
- return new Promise((n, s) => {
159
+ const ve = (e) => new Promise((t) => setTimeout(t, e));
160
+ function ke(e) {
161
+ return new Promise((t, i) => {
159
162
  const {
160
- callbacks: i,
161
- host: t,
162
- auth: a
163
+ callbacks: a,
164
+ host: n,
165
+ auth: s
163
166
  } = e, {
164
167
  onMessage: r = null,
165
168
  onOpen: o = null,
166
- onClose: f = null,
169
+ onClose: l = null,
167
170
  onError: d = null
168
- } = i || {}, u = new WebSocket(`${t}?authorization=${Z(a)}`);
169
- u.onmessage = r, u.onclose = f, u.onerror = (l) => {
170
- console.error(l), d == null || d("Websocket failed to connect", l), s(l);
171
- }, u.onopen = (l) => {
172
- o == null || o(l), n(u);
171
+ } = a || {}, f = new WebSocket(`${n}?authorization=${ee(s)}`);
172
+ f.onmessage = r, f.onclose = l, f.onerror = (m) => {
173
+ console.error(m), d == null || d("Websocket failed to connect", m), i(m);
174
+ }, f.onopen = (m) => {
175
+ o == null || o(m), t(f);
173
176
  };
174
177
  });
175
178
  }
176
- async function ve(e) {
179
+ async function Ce(e) {
177
180
  const {
178
- retries: n = 1
181
+ retries: t = 1
179
182
  } = e;
180
- let s = null;
181
- for (let i = 0; (s == null ? void 0 : s.readyState) !== WebSocket.OPEN; i++)
183
+ let i = null;
184
+ for (let a = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; a++)
182
185
  try {
183
- s = await ye(e);
184
- } catch (t) {
185
- if (i === n)
186
- throw t;
187
- await pe(i * 500);
186
+ i = await ke(e);
187
+ } catch (n) {
188
+ if (a === t)
189
+ throw n;
190
+ await ve(a * 500);
188
191
  }
189
- return s;
192
+ return i;
190
193
  }
191
- async function ke(e, n, s) {
192
- const i = s != null && s.onMessage ? [s.onMessage] : [], t = await ve({
194
+ async function Re(e, t, i) {
195
+ const a = i != null && i.onMessage ? [i.onMessage] : [], n = await Ce({
193
196
  auth: e,
194
- host: n,
197
+ host: t,
195
198
  callbacks: {
196
- onError: s == null ? void 0 : s.onError,
197
- onMessage: (a) => {
198
- const r = JSON.parse(a.data);
199
- i.forEach((o) => o(r.event, r));
199
+ onError: i == null ? void 0 : i.onError,
200
+ onMessage: (s) => {
201
+ const r = JSON.parse(s.data);
202
+ a.forEach((o) => o(r.event, r));
200
203
  }
201
204
  }
202
205
  });
203
206
  return {
204
- socket: t,
205
- disconnect: () => t.close(),
206
- subscribeToEvents: (a) => i.push(a)
207
+ socket: n,
208
+ disconnect: () => n.close(),
209
+ subscribeToEvents: (s) => a.push(s)
207
210
  };
208
211
  }
209
- const Ce = "X-Playground-Chat";
210
- function Re(e, n, s, i) {
211
- const t = B(e, `${n}/agents/${s}`, i);
212
+ const Se = "X-Playground-Chat";
213
+ function De(e, t, i, a) {
214
+ const n = q(e, `${t}/agents/${i}`, a);
212
215
  return {
213
- createStream(a) {
214
- return t.post("/streams", {
215
- output_resolution: a.output_resolution,
216
- compatibility_mode: a.compatibility_mode,
217
- stream_warmup: a.stream_warmup,
218
- session_timeout: a.session_timeout,
219
- stream_greeting: a.stream_greeting
216
+ createStream(s) {
217
+ return n.post("/streams", {
218
+ output_resolution: s.output_resolution,
219
+ compatibility_mode: s.compatibility_mode,
220
+ stream_warmup: s.stream_warmup,
221
+ session_timeout: s.session_timeout,
222
+ stream_greeting: s.stream_greeting
220
223
  });
221
224
  },
222
- startConnection(a, r, o) {
223
- return t.post(`/streams/${a}/sdp`, {
225
+ startConnection(s, r, o) {
226
+ return n.post(`/streams/${s}/sdp`, {
224
227
  session_id: o,
225
228
  answer: r
226
229
  });
227
230
  },
228
- addIceCandidate(a, r, o) {
229
- return t.post(`/streams/${a}/ice`, {
231
+ addIceCandidate(s, r, o) {
232
+ return n.post(`/streams/${s}/ice`, {
230
233
  session_id: o,
231
234
  ...r
232
235
  });
233
236
  },
234
- sendStreamRequest(a, r, o) {
235
- return t.post(`/streams/${a}`, {
237
+ sendStreamRequest(s, r, o) {
238
+ return n.post(`/streams/${s}`, {
236
239
  session_id: r,
237
240
  ...o
238
241
  });
239
242
  },
240
- close(a, r) {
241
- return t.delete(`/streams/${a}`, {
243
+ close(s, r) {
244
+ return n.delete(`/streams/${s}`, {
242
245
  session_id: r
243
246
  });
244
247
  }
245
248
  };
246
249
  }
247
- function Se(e, n, s, i) {
248
- const t = B(e, `${n}/agents/${s}`, i);
250
+ function _e(e, t, i, a) {
251
+ const n = q(e, `${t}/agents/${i}`, a);
249
252
  return {
250
- createStream(a, r) {
251
- return t.post("/streams", {
252
- driver_url: a.driver_url,
253
- face: a.face,
254
- config: a.config,
255
- output_resolution: a.output_resolution,
256
- compatibility_mode: a.compatibility_mode,
257
- stream_warmup: a.stream_warmup,
258
- session_timeout: a.session_timeout,
259
- stream_greeting: a.stream_greeting
253
+ createStream(s, r) {
254
+ return n.post("/streams", {
255
+ driver_url: s.driver_url,
256
+ face: s.face,
257
+ config: s.config,
258
+ output_resolution: s.output_resolution,
259
+ compatibility_mode: s.compatibility_mode,
260
+ stream_warmup: s.stream_warmup,
261
+ session_timeout: s.session_timeout,
262
+ stream_greeting: s.stream_greeting
260
263
  }, r);
261
264
  },
262
- startConnection(a, r, o, f) {
263
- return t.post(`/streams/${a}/sdp`, {
265
+ startConnection(s, r, o, l) {
266
+ return n.post(`/streams/${s}/sdp`, {
264
267
  session_id: o,
265
268
  answer: r
266
- }, f);
269
+ }, l);
267
270
  },
268
- addIceCandidate(a, r, o, f) {
269
- return t.post(`/streams/${a}/ice`, {
271
+ addIceCandidate(s, r, o, l) {
272
+ return n.post(`/streams/${s}/ice`, {
270
273
  session_id: o,
271
274
  ...r
272
- }, f);
275
+ }, l);
273
276
  },
274
- sendStreamRequest(a, r, o, f) {
275
- return t.post(`/streams/${a}`, {
277
+ sendStreamRequest(s, r, o, l) {
278
+ return n.post(`/streams/${s}`, {
276
279
  session_id: r,
277
280
  ...o
278
- }, f);
281
+ }, l);
279
282
  },
280
- close(a, r, o) {
281
- return t.delete(`/streams/${a}`, {
283
+ close(s, r, o) {
284
+ return n.delete(`/streams/${s}`, {
282
285
  session_id: r
283
286
  }, o);
284
287
  }
285
288
  };
286
289
  }
287
- function _e(e, n, s) {
290
+ function Me(e, t, i) {
291
+ const a = (t.timestamp - e.timestamp) / 1e3;
288
292
  return {
289
- duration: (n.timestamp - e.timestamp) / 1e3,
290
- bytesReceived: n.bytesReceived - e.bytesReceived,
291
- bitrate: Math.round((n.bytesReceived - e.bytesReceived) * 8 / ((n.timestamp - e.timestamp) / 1e3)),
292
- packetsReceived: n.packetsReceived - e.packetsReceived,
293
- packetsLost: n.packetsLost - e.packetsLost,
294
- framesDropped: n.framesDropped - e.framesDropped,
295
- framesDecoded: n.framesDecoded - e.framesDecoded,
296
- jitter: n.jitter,
297
- framesPerSecond: n.framesPerSecond,
298
- freezeCount: n.freezeCount - e.freezeCount,
299
- freezeDuration: n.freezeDuration - e.freezeDuration,
300
- lowFpsCount: s
293
+ duration: a,
294
+ bytesReceived: t.bytesReceived - e.bytesReceived,
295
+ bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / a),
296
+ packetsReceived: t.packetsReceived - e.packetsReceived,
297
+ packetsLost: t.packetsLost - e.packetsLost,
298
+ framesDropped: t.framesDropped - e.framesDropped,
299
+ framesDecoded: t.framesDecoded - e.framesDecoded,
300
+ jitter: t.jitter,
301
+ jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / a,
302
+ framesPerSecond: t.framesPerSecond,
303
+ freezeCount: t.freezeCount - e.freezeCount,
304
+ freezeDuration: t.freezeDuration - e.freezeDuration,
305
+ lowFpsCount: i
301
306
  };
302
307
  }
303
- function Me(e) {
304
- return e.filter((n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0).map((n) => {
308
+ function be(e) {
309
+ return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
305
310
  const {
306
- timestamp: s,
307
- ...i
308
- } = n, t = [];
309
- return n.freezeCount > 0 && t.push("freeze"), n.framesPerSecond < 21 && t.push("low fps"), n.framesDropped > 0 && t.push("frames dropped"), n.packetsLost > 0 && t.push("packet loss"), {
310
- ...i,
311
- causes: t
311
+ timestamp: i,
312
+ ...a
313
+ } = t, n = [];
314
+ return t.freezeCount > 0 && n.push("freeze"), t.framesPerSecond < 21 && n.push("low fps"), t.framesDropped > 0 && n.push("frames dropped"), t.packetsLost > 0 && n.push("packet loss"), {
315
+ ...a,
316
+ causes: n
312
317
  };
313
318
  });
314
319
  }
315
- function De(e) {
316
- let n = "";
317
- for (const s of e.values())
318
- if (s && s.type === "codec" && s.mimeType.startsWith("video") && (n = s.mimeType.split("/")[1]), s && s.type === "inbound-rtp" && s.kind === "video")
320
+ function Ee(e) {
321
+ let t = "";
322
+ for (const i of e.values())
323
+ if (i && i.type === "codec" && i.mimeType.startsWith("video") && (t = i.mimeType.split("/")[1]), i && i.type === "inbound-rtp" && i.kind === "video")
319
324
  return {
320
- codec: n,
321
- timestamp: s.timestamp,
322
- bytesReceived: s.bytesReceived,
323
- packetsReceived: s.packetsReceived,
324
- packetsLost: s.packetsLost,
325
- framesDropped: s.framesDropped,
326
- framesDecoded: s.framesDecoded,
327
- jitter: s.jitter,
328
- frameWidth: s.frameWidth,
329
- frameHeight: s.frameHeight,
330
- framesPerSecond: s.framesPerSecond,
331
- freezeCount: s.freezeCount,
332
- freezeDuration: s.totalFreezesDuration
325
+ codec: t,
326
+ timestamp: i.timestamp,
327
+ bytesReceived: i.bytesReceived,
328
+ packetsReceived: i.packetsReceived,
329
+ packetsLost: i.packetsLost,
330
+ framesDropped: i.framesDropped,
331
+ framesDecoded: i.framesDecoded,
332
+ jitter: i.jitter,
333
+ jitterBufferDelay: i.jitterBufferDelay,
334
+ frameWidth: i.frameWidth,
335
+ frameHeight: i.frameHeight,
336
+ framesPerSecond: i.framesPerSecond,
337
+ freezeCount: i.freezeCount,
338
+ freezeDuration: i.totalFreezesDuration
333
339
  };
334
340
  return {};
335
341
  }
336
- function be(e, n, s) {
337
- const i = e.map((r, o) => o === 0 ? s ? {
342
+ function Ie(e, t, i) {
343
+ const a = e.map((r, o) => o === 0 ? i ? {
338
344
  timestamp: r.timestamp,
339
345
  duration: 0,
340
- bytesReceived: r.bytesReceived - s.bytesReceived,
341
- bitrate: (r.bytesReceived - s.bytesReceived) * 8 / (n / 1e3),
342
- packetsReceived: r.packetsReceived - s.packetsReceived,
343
- packetsLost: r.packetsLost - s.packetsLost,
344
- framesDropped: r.framesDropped - s.framesDropped,
345
- framesDecoded: r.framesDecoded - s.framesDecoded,
346
+ bytesReceived: r.bytesReceived - i.bytesReceived,
347
+ bitrate: (r.bytesReceived - i.bytesReceived) * 8 / (t / 1e3),
348
+ packetsReceived: r.packetsReceived - i.packetsReceived,
349
+ packetsLost: r.packetsLost - i.packetsLost,
350
+ framesDropped: r.framesDropped - i.framesDropped,
351
+ framesDecoded: r.framesDecoded - i.framesDecoded,
346
352
  jitter: r.jitter,
353
+ jitterBufferDelay: r.jitterBufferDelay - i.jitterBufferDelay,
347
354
  framesPerSecond: r.framesPerSecond,
348
- freezeCount: r.freezeCount - s.freezeCount,
349
- freezeDuration: r.freezeDuration - s.freezeDuration
355
+ freezeCount: r.freezeCount - i.freezeCount,
356
+ freezeDuration: r.freezeDuration - i.freezeDuration
350
357
  } : {
351
358
  timestamp: r.timestamp,
352
359
  duration: 0,
353
360
  bytesReceived: r.bytesReceived,
354
- bitrate: r.bytesReceived * 8 / (n / 1e3),
361
+ bitrate: r.bytesReceived * 8 / (t / 1e3),
355
362
  packetsReceived: r.packetsReceived,
356
363
  packetsLost: r.packetsLost,
357
364
  framesDropped: r.framesDropped,
358
365
  framesDecoded: r.framesDecoded,
359
366
  jitter: r.jitter,
367
+ jitterBufferDelay: r.jitterBufferDelay,
360
368
  framesPerSecond: r.framesPerSecond,
361
369
  freezeCount: r.freezeCount,
362
370
  freezeDuration: r.freezeDuration
363
371
  } : {
364
372
  timestamp: r.timestamp,
365
- duration: n * o / 1e3,
373
+ duration: t * o / 1e3,
366
374
  bytesReceived: r.bytesReceived - e[o - 1].bytesReceived,
367
- bitrate: (r.bytesReceived - e[o - 1].bytesReceived) * 8 / (n / 1e3),
375
+ bitrate: (r.bytesReceived - e[o - 1].bytesReceived) * 8 / (t / 1e3),
368
376
  packetsReceived: r.packetsReceived - e[o - 1].packetsReceived,
369
377
  packetsLost: r.packetsLost - e[o - 1].packetsLost,
370
378
  framesDropped: r.framesDropped - e[o - 1].framesDropped,
371
379
  framesDecoded: r.framesDecoded - e[o - 1].framesDecoded,
372
380
  jitter: r.jitter,
381
+ jitterBufferDelay: r.jitterBufferDelay - e[o - 1].jitterBufferDelay,
373
382
  framesPerSecond: r.framesPerSecond,
374
383
  freezeCount: r.freezeCount - e[o - 1].freezeCount,
375
384
  freezeDuration: r.freezeDuration - e[o - 1].freezeDuration
376
- }), t = Me(i), a = t.reduce((r, o) => r + (o.causes.includes("low fps") ? 1 : 0), 0);
385
+ }), n = be(a), s = n.reduce((r, o) => r + (o.causes.includes("low fps") ? 1 : 0), 0);
377
386
  return {
378
387
  webRTCStats: {
379
- anomalies: t,
380
- aggregateReport: _e(e[0], e[e.length - 1], a)
388
+ anomalies: n,
389
+ aggregateReport: Me(e[0], e[e.length - 1], s)
381
390
  },
382
391
  codec: e[0].codec,
383
392
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
384
393
  };
385
394
  }
386
- let Q = !1;
387
- const L = (e, n) => Q && console.log(e, n), Ee = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
388
- function q(e) {
395
+ let ne = !1;
396
+ const z = (e, t) => ne && console.log(e, t), Pe = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
397
+ function X(e) {
389
398
  switch (e) {
390
399
  case "connected":
391
- return S.Connected;
400
+ return D.Connected;
392
401
  case "checking":
393
- return S.Connecting;
402
+ return D.Connecting;
394
403
  case "failed":
395
- return S.Fail;
404
+ return D.Fail;
396
405
  case "new":
397
- return S.New;
406
+ return D.New;
398
407
  case "closed":
399
- return S.Closed;
408
+ return D.Closed;
400
409
  case "disconnected":
401
- return S.Disconnected;
410
+ return D.Disconnected;
402
411
  case "completed":
403
- return S.Completed;
412
+ return D.Completed;
404
413
  default:
405
- return S.New;
414
+ return D.New;
406
415
  }
407
416
  }
408
- function Ie() {
417
+ function $e() {
409
418
  let e = 0;
410
- return (n) => {
411
- for (const s of n.values())
412
- if (s && s.type === "inbound-rtp" && s.kind === "video") {
413
- const i = s.bytesReceived, t = i - e > 0;
414
- return e = i, t;
419
+ return (t) => {
420
+ for (const i of t.values())
421
+ if (i && i.type === "inbound-rtp" && i.kind === "video") {
422
+ const a = i.bytesReceived, n = a - e > 0;
423
+ return e = a, n;
415
424
  }
416
425
  return !1;
417
426
  };
418
427
  }
419
- function Pe(e, n, s = !1, i, t) {
428
+ function Ae(e, t, i = !1, a, n) {
420
429
  const r = Math.max(Math.ceil(10), 1);
421
- let o = [], f, d = 0, u = !1;
422
- const l = s ? 1 : 0;
423
- let g = 0;
424
- const C = Ie();
430
+ let o = [], l, d = 0, f = !1;
431
+ const m = i ? 1 : 0;
432
+ let p = 0;
433
+ const k = $e();
425
434
  return setInterval(async () => {
426
- const y = await e.getStats(), v = C(y), h = De(y);
427
- if (v)
428
- d = 0, u || (n == null || n(x.Start), g >= l && !i() && t(), f = o[o.length - 1], o = [], g++, u = !0), o.push(h);
429
- else if (u && (d++, d >= r)) {
430
- const b = be(o, 100, f);
431
- n == null || n(x.Stop, b), u = !1;
435
+ const y = await e.getStats(), C = k(y), g = Ee(y);
436
+ if (C)
437
+ d = 0, f || (t == null || t(j.Start), p >= m && !a() && n(), l = o[o.length - 1], o = [], p++, f = !0), o.push(g);
438
+ else if (f && (d++, d >= r)) {
439
+ const R = Ie(o, 100, l);
440
+ t == null || t(j.Stop, R), f = !1;
432
441
  }
433
442
  }, 100);
434
443
  }
435
- async function $e(e, n, {
436
- debug: s = !1,
437
- callbacks: i,
438
- auth: t,
439
- baseURL: a = H,
444
+ async function Te(e, t, {
445
+ debug: i = !1,
446
+ callbacks: a,
447
+ auth: n,
448
+ baseURL: s = H,
440
449
  warmup: r
441
450
  }) {
442
- Q = s;
451
+ ne = i;
443
452
  const {
444
453
  startConnection: o,
445
- sendStreamRequest: f,
454
+ sendStreamRequest: l,
446
455
  close: d,
447
- createStream: u,
448
- addIceCandidate: l
449
- } = n.videoType === O.Clip ? Re(t, a, e, i.onError) : Se(t, a, e, i.onError), {
450
- id: g,
451
- offer: C,
456
+ createStream: f,
457
+ addIceCandidate: m
458
+ } = t.videoType === Z.Clip ? De(n, s, e, a.onError) : _e(n, s, e, a.onError), {
459
+ id: p,
460
+ offer: k,
452
461
  ice_servers: y,
453
- session_id: v
454
- } = await u(n), h = new Ee({
462
+ session_id: C
463
+ } = await f(t), g = new Pe({
455
464
  iceServers: y
456
- }), b = h.createDataChannel("JanusDataChannel");
457
- if (!v)
465
+ }), R = g.createDataChannel("JanusDataChannel");
466
+ if (!C)
458
467
  throw new Error("Could not create session_id");
459
- let P = !1;
460
- const c = () => P, w = () => {
461
- var m;
462
- P = !0, (m = i.onConnectionStateChange) == null || m.call(i, S.Connected);
463
- }, k = Pe(h, i.onVideoStateChange, r, c, w);
464
- h.onicecandidate = (m) => {
465
- var p;
466
- L("peerConnection.onicecandidate", m);
468
+ let M = !1;
469
+ const c = () => M, h = () => {
470
+ var u;
471
+ M = !0, (u = a.onConnectionStateChange) == null || u.call(a, D.Connected);
472
+ }, v = Ae(g, a.onVideoStateChange, r, c, h);
473
+ g.onicecandidate = (u) => {
474
+ var w;
475
+ z("peerConnection.onicecandidate", u);
467
476
  try {
468
- m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? l(g, {
469
- candidate: m.candidate.candidate,
470
- sdpMid: m.candidate.sdpMid,
471
- sdpMLineIndex: m.candidate.sdpMLineIndex
472
- }, v) : l(g, {
477
+ u.candidate && u.candidate.sdpMid && u.candidate.sdpMLineIndex !== null ? m(p, {
478
+ candidate: u.candidate.candidate,
479
+ sdpMid: u.candidate.sdpMid,
480
+ sdpMLineIndex: u.candidate.sdpMLineIndex
481
+ }, C) : m(p, {
473
482
  candidate: null
474
- }, v);
475
- } catch (R) {
476
- (p = i.onError) == null || p.call(i, R, {
477
- streamId: g
483
+ }, C);
484
+ } catch (S) {
485
+ (w = a.onError) == null || w.call(a, S, {
486
+ streamId: p
478
487
  });
479
488
  }
480
- }, b.onmessage = (m) => {
481
- if (b.readyState === "open") {
482
- const [p, R] = m.data.split(":");
483
- p === W.StreamReady && !P && w();
489
+ }, R.onmessage = (u) => {
490
+ if (R.readyState === "open") {
491
+ const [w, S] = u.data.split(":");
492
+ w === W.StreamReady && !M && h();
484
493
  }
485
- }, h.oniceconnectionstatechange = () => {
486
- var p;
487
- L("peerConnection.oniceconnectionstatechange => " + h.iceConnectionState);
488
- const m = q(h.iceConnectionState);
489
- m !== S.Connected && ((p = i.onConnectionStateChange) == null || p.call(i, m));
490
- }, h.ontrack = (m) => {
491
- var p;
492
- L("peerConnection.ontrack", m), (p = i.onSrcObjectReady) == null || p.call(i, m.streams[0]);
493
- }, await h.setRemoteDescription(C), L("set remote description OK");
494
- const _ = await h.createAnswer();
495
- return L("create answer OK"), await h.setLocalDescription(_), L("set local description OK"), await o(g, _, v), L("start connection OK"), {
494
+ }, g.oniceconnectionstatechange = () => {
495
+ var w;
496
+ z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
497
+ const u = X(g.iceConnectionState);
498
+ u !== D.Connected && ((w = a.onConnectionStateChange) == null || w.call(a, u));
499
+ }, g.ontrack = (u) => {
500
+ var w;
501
+ z("peerConnection.ontrack", u), (w = a.onSrcObjectReady) == null || w.call(a, u.streams[0]);
502
+ }, await g.setRemoteDescription(k), z("set remote description OK");
503
+ const _ = await g.createAnswer();
504
+ return z("create answer OK"), await g.setLocalDescription(_), z("set local description OK"), await o(p, _, C), z("start connection OK"), {
496
505
  /**
497
506
  * Method to send request to server to get clip or talk depend on you payload
498
507
  * @param payload
499
508
  */
500
- speak(m) {
501
- return f(g, v, m);
509
+ speak(u) {
510
+ return l(p, C, u);
502
511
  },
503
512
  /**
504
513
  * Method to close RTC connection
505
514
  */
506
515
  async disconnect() {
507
- var m, p;
508
- if (g) {
509
- const R = q(h.iceConnectionState);
510
- if (h) {
511
- if (R === S.New) {
512
- (m = i.onVideoStateChange) == null || m.call(i, x.Stop), clearInterval(k);
516
+ var u, w;
517
+ if (p) {
518
+ const S = X(g.iceConnectionState);
519
+ if (g) {
520
+ if (S === D.New) {
521
+ (u = a.onVideoStateChange) == null || u.call(a, j.Stop), clearInterval(v);
513
522
  return;
514
523
  }
515
- h.close(), h.oniceconnectionstatechange = null, h.onnegotiationneeded = null, h.onicecandidate = null, h.ontrack = null;
524
+ g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
516
525
  }
517
526
  try {
518
- R === S.Connected && await d(g, v).catch((M) => {
527
+ S === D.Connected && await d(p, C).catch((b) => {
519
528
  });
520
- } catch (M) {
521
- L("Error on close stream connection", M);
529
+ } catch (b) {
530
+ z("Error on close stream connection", b);
522
531
  }
523
- (p = i.onVideoStateChange) == null || p.call(i, x.Stop), clearInterval(k);
532
+ (w = a.onVideoStateChange) == null || w.call(a, j.Stop), clearInterval(v);
524
533
  }
525
534
  },
526
535
  /**
527
536
  * Session identifier information, should be returned in the body of all streaming requests
528
537
  */
529
- sessionId: v,
538
+ sessionId: C,
530
539
  /**
531
540
  * Id of current RTC stream
532
541
  */
533
- streamId: g
542
+ streamId: p
534
543
  };
535
544
  }
536
545
  let U = {};
537
- function Ae(e) {
538
- var a, r, o, f, d;
539
- const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", s = e.agent.presenter, i = (a = e.agent.llm) == null ? void 0 : a.prompt_customization, t = {
546
+ function ze(e) {
547
+ var s, r, o, l, d;
548
+ const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = e.agent.presenter, a = (s = e.agent.llm) == null ? void 0 : s.prompt_customization, n = {
540
549
  token: e.token || "testKey",
541
- distinct_id: e.distinctId || Y(),
550
+ distinct_id: e.distinctId || Q(),
542
551
  agentId: e.agent.id,
543
- agentType: s.type === "clip" && s.presenter_id.startsWith("v2_") ? "clip_v2" : s.type,
552
+ agentType: i.type === "clip" && i.presenter_id.startsWith("v2_") ? "clip_v2" : i.type,
544
553
  owner_id: e.agent.owner_id ?? "",
545
554
  behavior: {
546
- role: i == null ? void 0 : i.role,
547
- personality: i == null ? void 0 : i.personality,
555
+ role: a == null ? void 0 : a.role,
556
+ personality: a == null ? void 0 : a.personality,
548
557
  instructions: (r = e.agent.llm) == null ? void 0 : r.instructions
549
558
  },
550
559
  temperature: (o = e.agent.llm) == null ? void 0 : o.temperature,
551
- knowledgeSource: i == null ? void 0 : i.knowledge_source,
552
- starterQuestionsCount: (d = (f = e.agent.knowledge) == null ? void 0 : f.starter_message) == null ? void 0 : d.length,
553
- topicsToAvoid: i == null ? void 0 : i.topics_to_avoid,
554
- maxResponseLength: i == null ? void 0 : i.max_response_length
560
+ knowledgeSource: a == null ? void 0 : a.knowledge_source,
561
+ starterQuestionsCount: (d = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : d.length,
562
+ topicsToAvoid: a == null ? void 0 : a.topics_to_avoid,
563
+ maxResponseLength: a == null ? void 0 : a.max_response_length
555
564
  };
556
565
  return {
557
- ...t,
566
+ ...n,
558
567
  additionalProperties: {},
559
568
  isEnabled: e.isEnabled ?? !0,
560
569
  getRandom: () => Math.random().toString(16).slice(2),
561
- enrich(u) {
562
- const l = {};
563
- if (u && typeof u != "object")
570
+ enrich(f) {
571
+ const m = {};
572
+ if (f && typeof f != "object")
564
573
  throw new Error("properties must be a flat json object");
565
- for (let g in u)
566
- (typeof u[g] == "string" || typeof u[g] == "number") && (l[g] = u[g]);
574
+ for (let p in f)
575
+ (typeof f[p] == "string" || typeof f[p] == "number") && (m[p] = f[p]);
567
576
  this.additionalProperties = {
568
577
  ...this.additionalProperties,
569
- ...l
578
+ ...m
570
579
  };
571
580
  },
572
- track(u, l) {
581
+ track(f, m) {
573
582
  if (!this.isEnabled)
574
583
  return Promise.resolve();
575
584
  const {
576
- audioPath: g,
577
- ...C
578
- } = l || {}, y = {
585
+ audioPath: p,
586
+ ...k
587
+ } = m || {}, y = {
579
588
  method: "POST",
580
589
  headers: {
581
590
  "Content-Type": "application/x-www-form-urlencoded"
582
591
  },
583
592
  body: new URLSearchParams({
584
593
  data: JSON.stringify([{
585
- event: u,
594
+ event: f,
586
595
  properties: {
587
596
  ...this.additionalProperties,
588
- ...C,
589
- ...t,
590
- source: n,
597
+ ...k,
598
+ ...n,
599
+ source: t,
591
600
  time: Date.now(),
592
601
  $insert_id: this.getRandom(),
593
602
  origin: window.location.href,
@@ -598,422 +607,440 @@ function Ae(e) {
598
607
  }])
599
608
  })
600
609
  };
601
- return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1", y).then((v) => v.json()).catch((v) => console.error(v));
610
+ return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1", y).then((C) => C.json()).catch((C) => console.error(C));
602
611
  },
603
- linkTrack(u, l, g, C) {
604
- U[u] || (U[u] = {
612
+ linkTrack(f, m, p, k) {
613
+ U[f] || (U[f] = {
605
614
  events: {},
606
615
  resolvedDependencies: []
607
- }), C.includes(g) || C.push(g);
608
- const y = U[u];
609
- if (y.events[g] = {
610
- props: l
611
- }, y.resolvedDependencies.push(g), C.every((h) => y.resolvedDependencies.includes(h))) {
612
- const h = C.reduce((b, P) => y.events[P] ? {
613
- ...b,
614
- ...y.events[P].props
615
- } : b, {});
616
- this.track(u, h), y.resolvedDependencies = y.resolvedDependencies.filter((b) => !C.includes(b)), C.forEach((b) => {
617
- delete y.events[b];
616
+ }), k.includes(p) || k.push(p);
617
+ const y = U[f];
618
+ if (y.events[p] = {
619
+ props: m
620
+ }, y.resolvedDependencies.push(p), k.every((g) => y.resolvedDependencies.includes(g))) {
621
+ const g = k.reduce((R, M) => y.events[M] ? {
622
+ ...R,
623
+ ...y.events[M].props
624
+ } : R, {});
625
+ this.track(f, g), y.resolvedDependencies = y.resolvedDependencies.filter((R) => !k.includes(R)), k.forEach((R) => {
626
+ delete y.events[R];
618
627
  });
619
628
  }
620
629
  }
621
630
  };
622
631
  }
623
- function Te(e) {
624
- var t, a, r, o;
625
- const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", s = () => {
626
- const f = navigator.platform;
627
- return f.toLowerCase().includes("win") ? "Windows" : f.toLowerCase().includes("mac") ? "Mac OS X" : f.toLowerCase().includes("linux") ? "Linux" : "Unknown";
628
- }, i = e.presenter;
632
+ function Le(e) {
633
+ var n, s, r, o;
634
+ const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
635
+ const l = navigator.platform;
636
+ return l.toLowerCase().includes("win") ? "Windows" : l.toLowerCase().includes("mac") ? "Mac OS X" : l.toLowerCase().includes("linux") ? "Linux" : "Unknown";
637
+ }, a = e.presenter;
629
638
  return {
630
- $os: `${s()}`,
631
- isMobile: `${n() == "Mobile"}`,
639
+ $os: `${i()}`,
640
+ isMobile: `${t() == "Mobile"}`,
632
641
  browser: navigator.userAgent,
633
642
  origin: window.location.origin,
634
- agentType: i.type === "clip" && i.presenter_id.startsWith("v2_") ? "clip_v2" : i.type,
643
+ agentType: a.type === "clip" && a.presenter_id.startsWith("v2_") ? "clip_v2" : a.type,
635
644
  agentVoice: {
636
- voiceId: (a = (t = e.presenter) == null ? void 0 : t.voice) == null ? void 0 : a.voice_id,
645
+ voiceId: (s = (n = e.presenter) == null ? void 0 : n.voice) == null ? void 0 : s.voice_id,
637
646
  provider: (o = (r = e.presenter) == null ? void 0 : r.voice) == null ? void 0 : o.type
638
647
  }
639
648
  };
640
649
  }
641
- function Le(e, n, s) {
642
- var d, u;
650
+ function je(e, t, i) {
651
+ var d, f;
643
652
  const {
644
- event: i,
645
- ...t
653
+ event: a,
654
+ ...n
646
655
  } = e, {
647
- template: a
648
- } = (n == null ? void 0 : n.llm) || {}, {
656
+ template: s
657
+ } = (t == null ? void 0 : t.llm) || {}, {
649
658
  language: r
650
- } = ((d = n == null ? void 0 : n.presenter) == null ? void 0 : d.voice) || {}, {
659
+ } = ((d = t == null ? void 0 : t.presenter) == null ? void 0 : d.voice) || {}, {
651
660
  stitch: o
652
- } = (n == null ? void 0 : n.presenter) || {};
661
+ } = (t == null ? void 0 : t.presenter) || {};
653
662
  return {
654
- ...t,
663
+ ...n,
655
664
  llm: {
656
- ...t.llm,
657
- template: a
665
+ ...n.llm,
666
+ template: s
658
667
  },
659
668
  script: {
660
- ...t.script,
669
+ ...n.script,
661
670
  provider: {
662
- ...(u = t == null ? void 0 : t.script) == null ? void 0 : u.provider,
671
+ ...(f = n == null ? void 0 : n.script) == null ? void 0 : f.provider,
663
672
  language: r
664
673
  }
665
674
  },
666
675
  stitch: o,
667
- ...s
676
+ ...i
668
677
  };
669
678
  }
670
- let z = 0;
671
- const ze = 20 * 1e3;
672
- function xe(e, n, s) {
673
- var i, t, a, r, o;
679
+ let L = 0;
680
+ const xe = 45 * 1e3;
681
+ function Ne(e, t, i) {
682
+ var a, n, s, r, o;
674
683
  return {
675
- videoType: le(e.presenter.type),
676
- output_resolution: (i = n == null ? void 0 : n.streamOptions) == null ? void 0 : i.outputResolution,
677
- session_timeout: (t = n == null ? void 0 : n.streamOptions) == null ? void 0 : t.sessionTimeout,
678
- stream_warmup: (a = n == null ? void 0 : n.streamOptions) == null ? void 0 : a.streamWarmup,
679
- compatibility_mode: (r = n == null ? void 0 : n.streamOptions) == null ? void 0 : r.compatibilityMode,
680
- stream_greeting: (o = n == null ? void 0 : n.streamOptions) != null && o.streamGreeting ? s : void 0
684
+ videoType: ue(e.presenter.type),
685
+ output_resolution: (a = t == null ? void 0 : t.streamOptions) == null ? void 0 : a.outputResolution,
686
+ session_timeout: (n = t == null ? void 0 : t.streamOptions) == null ? void 0 : n.sessionTimeout,
687
+ stream_warmup: (s = t == null ? void 0 : t.streamOptions) == null ? void 0 : s.streamWarmup,
688
+ compatibility_mode: (r = t == null ? void 0 : t.streamOptions) == null ? void 0 : r.compatibilityMode,
689
+ stream_greeting: (o = t == null ? void 0 : t.streamOptions) != null && o.streamGreeting ? i : void 0
681
690
  };
682
691
  }
683
- function ee(e) {
684
- return e === E.Playground ? {
692
+ function re(e) {
693
+ return e === I.Playground ? {
685
694
  headers: {
686
- [Ce]: "true"
695
+ [Se]: "true"
687
696
  }
688
697
  } : {};
689
698
  }
690
- async function te(e, n, s, i, t) {
699
+ async function ae(e, t, i, a, n) {
691
700
  try {
692
- const a = await n.newChat(e, {
693
- persist: t ?? !1
694
- }, ee(i));
695
- return s.track("agent-chat", {
701
+ const s = await t.newChat(e, {
702
+ persist: n ?? !1
703
+ }, re(a));
704
+ return i.track("agent-chat", {
696
705
  event: "created",
697
- chat_id: a.id,
706
+ chat_id: s.id,
698
707
  agent_id: e,
699
- mode: i
700
- }), a;
701
- } catch (a) {
708
+ mode: a
709
+ }), s;
710
+ } catch (s) {
702
711
  let r;
703
712
  try {
704
- r = JSON.parse(a.message);
713
+ r = JSON.parse(s.message);
705
714
  } catch (o) {
706
715
  console.error("Error parsing the error message:", o);
707
716
  }
708
717
  throw (r == null ? void 0 : r.kind) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
709
718
  }
710
719
  }
711
- function Ne(e, n, s, i, t, a) {
720
+ class Be extends Error {
721
+ constructor({
722
+ kind: t,
723
+ description: i
724
+ }) {
725
+ const a = JSON.stringify({
726
+ kind: t,
727
+ description: i
728
+ });
729
+ super(a);
730
+ }
731
+ }
732
+ function Fe(e, t, i, a, n, s) {
712
733
  return new Promise(async (r, o) => {
713
- var d, u, l;
714
- if (z = 0, !t && n.mode !== E.DirectPlayback)
734
+ var m, p, k, y, C;
735
+ L = 0;
736
+ const l = String(t.mode);
737
+ if (!n && t.mode !== I.DirectPlayback)
715
738
  try {
716
- t = await te(e.id, s, i, n.mode, n.persistentChat);
739
+ n = await ae(e.id, i, a, t.mode, t.persistentChat);
717
740
  } catch (g) {
718
741
  return o(g);
719
742
  }
720
- if ((t == null ? void 0 : t.chat_mode) === E.TextOnly)
721
- return (u = (d = n.callbacks) == null ? void 0 : d.onError) == null || u.call(d, new Error(JSON.stringify({
722
- kind: "InsufficientCreditsError"
723
- })), {
724
- fromSdk: !0
725
- }), r({
726
- chat: t
743
+ const d = (n == null ? void 0 : n.chat_mode) || l;
744
+ if (d !== l && (t.mode = d, (p = (m = t.callbacks).onModeChange) == null || p.call(m, d), d === I.TextOnly && ((y = (k = t.callbacks) == null ? void 0 : k.onError) == null || y.call(k, new Be({
745
+ kind: "ModeUnavailable",
746
+ description: `Chat mode changed from ${l} to ${d} when creating the chat`
747
+ }), {}))), d === I.TextOnly)
748
+ return r({
749
+ chat: n
727
750
  });
728
- const f = await $e(e.id, xe(e, n, a), {
729
- ...n,
730
- analytics: i,
731
- warmup: (l = n.streamOptions) == null ? void 0 : l.streamWarmup,
751
+ const f = await Te(e.id, Ne(e, t, s), {
752
+ ...t,
753
+ analytics: a,
754
+ warmup: (C = t.streamOptions) == null ? void 0 : C.streamWarmup,
732
755
  callbacks: {
733
- ...n.callbacks,
756
+ ...t.callbacks,
734
757
  onConnectionStateChange: async (g) => {
735
- var C, y, v, h;
736
- g === S.Connected ? f ? ((y = (C = n.callbacks).onConnectionStateChange) == null || y.call(C, g), r({
737
- chat: t,
758
+ var R, M, c, h;
759
+ g === D.Connected ? f ? ((M = (R = t.callbacks).onConnectionStateChange) == null || M.call(R, g), r({
760
+ chat: n,
738
761
  streamingManager: f
739
- })) : t && o(new Error("Something went wrong while initializing the manager")) : (h = (v = n.callbacks).onConnectionStateChange) == null || h.call(v, g);
762
+ })) : n && o(new Error("Something went wrong while initializing the manager")) : (h = (c = t.callbacks).onConnectionStateChange) == null || h.call(c, g);
740
763
  },
741
- onVideoStateChange(g, C) {
742
- var y, v;
743
- (v = (y = n.callbacks).onVideoStateChange) == null || v.call(y, g), z > 0 && (g === x.Start ? i.linkTrack("agent-video", {
764
+ onVideoStateChange(g, R) {
765
+ var M, c;
766
+ (c = (M = t.callbacks).onVideoStateChange) == null || c.call(M, g), L > 0 && (g === j.Start ? a.linkTrack("agent-video", {
744
767
  event: "start",
745
- latency: Date.now() - z
746
- }, "start", [W.StreamVideoCreated]) : g === x.Stop && i.linkTrack("agent-video", {
768
+ latency: Date.now() - L
769
+ }, "start", [W.StreamVideoCreated]) : g === j.Stop && a.linkTrack("agent-video", {
747
770
  event: "stop",
748
771
  is_greenscreen: e.presenter.type === "clip" && e.presenter.is_greenscreen,
749
772
  background: e.presenter.type === "clip" && e.presenter.background,
750
- ...C
773
+ ...R
751
774
  }, "done", [W.StreamVideoDone]));
752
775
  }
753
776
  }
754
777
  }).catch(o);
755
778
  });
756
779
  }
757
- function je(e) {
758
- var s;
759
- const n = (s = e.greetings) == null ? void 0 : s.filter((i) => i.length > 0);
760
- if (n && n.length > 0) {
761
- const i = Math.floor(Math.random() * n.length);
762
- return n[i];
780
+ function We(e) {
781
+ var i;
782
+ const t = (i = e.greetings) == null ? void 0 : i.filter((a) => a.length > 0);
783
+ if (t && t.length > 0) {
784
+ const a = Math.floor(Math.random() * t.length);
785
+ return t[a];
763
786
  } else
764
787
  return `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
765
788
  }
766
- function J(e, n) {
767
- return n && n.length > 0 ? n : [{
789
+ function Y(e, t) {
790
+ return t && t.length > 0 ? t : [{
768
791
  content: e,
769
- id: K(),
792
+ id: V(),
770
793
  role: "assistant",
771
794
  created_at: (/* @__PURE__ */ new Date()).toISOString()
772
795
  }];
773
796
  }
774
- function Fe(e) {
797
+ function He(e) {
775
798
  if (e.answer !== void 0)
776
799
  return e.answer;
777
- let n = 0, s = "";
778
- for (; n in e; )
779
- s += e[n], n++;
780
- return s;
800
+ let t = 0, i = "";
801
+ for (; t in e; )
802
+ i += e[t], t++;
803
+ return i;
781
804
  }
782
- function We(e, n, s, i, t) {
783
- if (!(e === N.Partial || e === N.Answer))
805
+ function Ke(e, t, i, a, n) {
806
+ if (!(e === B.Partial || e === B.Answer))
784
807
  return;
785
- const a = i.messages[i.messages.length - 1];
786
- if ((a == null ? void 0 : a.role) !== "assistant")
808
+ const s = a.messages[a.messages.length - 1];
809
+ if ((s == null ? void 0 : s.role) !== "assistant")
787
810
  return;
788
811
  const {
789
812
  content: r,
790
813
  sequence: o
791
- } = n;
792
- e === N.Partial ? s[o] = r : s.answer = r;
793
- const f = Fe(s);
794
- (a.content !== f || e === N.Answer) && (a.content = f, t == null || t([...i.messages], e));
814
+ } = t;
815
+ e === B.Partial ? i[o] = r : i.answer = r;
816
+ const l = He(i);
817
+ (s.content !== l || e === B.Answer) && (s.content = l, n == null || n([...a.messages], e));
795
818
  }
796
- async function He(e, n) {
797
- var h, b, P;
798
- let s = {}, i = !0;
799
- const t = {
819
+ async function Ve(e, t) {
820
+ var g, R, M;
821
+ let i = {}, a = !0;
822
+ const n = {
800
823
  messages: [],
801
- chatMode: n.mode || E.Functional
802
- }, a = n.baseURL || H, r = n.wsURL || fe, o = n.mixpanelKey || ge, f = G(n.auth, a, n.callbacks.onError), d = await f.getById(e), u = je(d);
803
- t.messages = J(u, n.initialMessages), (b = (h = n.callbacks).onNewMessage) == null || b.call(h, [...t.messages], "answer");
804
- const l = Ae({
824
+ chatMode: t.mode || I.Functional
825
+ }, s = t.baseURL || H, r = t.wsURL || he, o = t.mixpanelKey || we, l = te(t.auth, s, t.callbacks.onError), d = await l.getById(e), f = We(d);
826
+ n.messages = Y(f, t.initialMessages), (R = (g = t.callbacks).onNewMessage) == null || R.call(g, [...n.messages], "answer");
827
+ const m = ze({
805
828
  token: o,
806
829
  agent: d,
807
- isEnabled: n.enableAnalitics,
808
- distinctId: n.distinctId
830
+ isEnabled: t.enableAnalitics,
831
+ distinctId: t.distinctId
809
832
  });
810
- l.track("agent-sdk", {
833
+ m.track("agent-sdk", {
811
834
  event: "loaded",
812
- ...Te(d)
835
+ ...Le(d)
813
836
  });
814
- const g = {
815
- onMessage: (c, w) => {
816
- var k, _;
817
- if ("content" in w)
818
- We(c, w, s, t, n.callbacks.onNewMessage), c === N.Answer && l.track("agent-message-received", {
819
- messages: t.messages.length,
820
- mode: t.chatMode
837
+ const p = {
838
+ onMessage: (c, h) => {
839
+ var v, _;
840
+ if ("content" in h)
841
+ Ke(c, h, i, n, t.callbacks.onNewMessage), c === B.Answer && m.track("agent-message-received", {
842
+ messages: n.messages.length,
843
+ mode: n.chatMode
821
844
  });
822
845
  else {
823
- const m = W, p = [m.StreamVideoDone, m.StreamVideoError, m.StreamVideoRejected], R = [m.StreamFailed, m.StreamVideoError, m.StreamVideoRejected], M = Le(w, d, {
824
- mode: t.chatMode
846
+ const u = W, w = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], S = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], b = je(h, d, {
847
+ mode: n.chatMode
825
848
  });
826
- if (c = c, c === m.StreamVideoCreated)
827
- l.linkTrack("agent-video", M, m.StreamVideoCreated, ["start"]);
828
- else if (p.includes(c)) {
829
- const D = c.split("/")[1];
830
- R.includes(c) ? l.track("agent-video", {
831
- ...M,
832
- event: D
833
- }) : l.linkTrack("agent-video", {
834
- ...M,
835
- event: D
849
+ if (c = c, c === u.StreamVideoCreated)
850
+ m.linkTrack("agent-video", b, u.StreamVideoCreated, ["start"]);
851
+ else if (w.includes(c)) {
852
+ const E = c.split("/")[1];
853
+ S.includes(c) ? m.track("agent-video", {
854
+ ...b,
855
+ event: E
856
+ }) : m.linkTrack("agent-video", {
857
+ ...b,
858
+ event: E
836
859
  }, c, ["done"]);
837
860
  }
838
- R.includes(c) && ((_ = (k = n.callbacks).onError) == null || _.call(k, new Error(`Stream failed with event ${c}`), {
839
- data: w
840
- })), w.event === m.StreamDone && y();
861
+ S.includes(c) && ((_ = (v = t.callbacks).onError) == null || _.call(v, new Error(`Stream failed with event ${c}`), {
862
+ data: h
863
+ })), h.event === u.StreamDone && y();
841
864
  }
842
865
  }
843
866
  };
844
- async function C(c) {
845
- var R, M, D, $, j, T, A;
846
- (M = (R = n.callbacks).onConnectionStateChange) == null || M.call(R, S.Connecting), z = 0, c && !i && (delete t.chat, t.messages = J(u), ($ = (D = n.callbacks).onNewMessage) == null || $.call(D, [...t.messages], "answer"));
847
- const w = n.mode === E.DirectPlayback ? Promise.resolve(void 0) : ke(n.auth, r, g), k = X(() => Ne(d, n, f, l, t.chat, c ? u : void 0), {
867
+ async function k(c) {
868
+ var S, b, E, A, F, T, P;
869
+ (b = (S = t.callbacks).onConnectionStateChange) == null || b.call(S, D.Connecting), L = 0, c && !a && (delete n.chat, n.messages = Y(f), (A = (E = t.callbacks).onNewMessage) == null || A.call(E, [...n.messages], "answer"));
870
+ const h = t.mode === I.DirectPlayback ? Promise.resolve(void 0) : Re(t.auth, r, p), v = G(() => Fe(d, t, l, m, n.chat, c ? f : void 0), {
848
871
  limit: 3,
849
- timeout: ze,
850
- timeoutErrorMessage: "Could not connect",
872
+ timeout: xe,
873
+ timeoutErrorMessage: "Timeout initializing the stream",
851
874
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
852
- shouldRetryFn: (I) => (I == null ? void 0 : I.message) !== "Could not connect" && I.status !== 429,
875
+ shouldRetryFn: ($) => ($ == null ? void 0 : $.message) !== "Could not connect" && $.status !== 429,
853
876
  delayMs: 1e3
854
- }).catch((I) => {
855
- var F, V;
856
- throw v(E.Maintenance), (V = (F = n.callbacks).onConnectionStateChange) == null || V.call(F, S.Fail), I;
877
+ }).catch(($) => {
878
+ var x, N;
879
+ throw C(I.Maintenance), (N = (x = t.callbacks).onConnectionStateChange) == null || N.call(x, D.Fail), $;
857
880
  }), [_, {
858
- streamingManager: m,
859
- chat: p
860
- }] = await Promise.all([w, k]);
861
- p && p.id !== ((j = t.chat) == null ? void 0 : j.id) && ((A = (T = n.callbacks).onNewChat) == null || A.call(T, p.id)), t.streamingManager = m, t.socketManager = _, t.chat = p, i = !1, v((p == null ? void 0 : p.chat_mode) ?? n.mode ?? E.Functional);
881
+ streamingManager: u,
882
+ chat: w
883
+ }] = await Promise.all([h, v]);
884
+ w && w.id !== ((F = n.chat) == null ? void 0 : F.id) && ((P = (T = t.callbacks).onNewChat) == null || P.call(T, w.id)), n.streamingManager = u, n.socketManager = _, n.chat = w, a = !1, C((w == null ? void 0 : w.chat_mode) ?? t.mode ?? I.Functional);
862
885
  }
863
886
  async function y() {
864
- var c, w, k, _;
865
- (c = t.socketManager) == null || c.disconnect(), await ((w = t.streamingManager) == null ? void 0 : w.disconnect()), delete t.streamingManager, delete t.socketManager, (_ = (k = n.callbacks).onConnectionStateChange) == null || _.call(k, S.Disconnected);
887
+ var c, h, v, _;
888
+ (c = n.socketManager) == null || c.disconnect(), await ((h = n.streamingManager) == null ? void 0 : h.disconnect()), delete n.streamingManager, delete n.socketManager, (_ = (v = t.callbacks).onConnectionStateChange) == null || _.call(v, D.Disconnected);
866
889
  }
867
- async function v(c) {
868
- var w, k;
869
- c !== t.chatMode && (l.track("agent-mode-change", {
890
+ async function C(c) {
891
+ var h, v;
892
+ c !== n.chatMode && (m.track("agent-mode-change", {
870
893
  mode: c
871
- }), t.chatMode = c, t.chatMode !== E.Functional && await y(), (k = (w = n.callbacks).onModeChange) == null || k.call(w, c));
894
+ }), n.chatMode = c, n.chatMode !== I.Functional && await y(), (v = (h = t.callbacks).onModeChange) == null || v.call(h, c));
872
895
  }
873
896
  return {
874
897
  agent: d,
875
- starterMessages: ((P = d.knowledge) == null ? void 0 : P.starter_message) || [],
876
- getSTTToken: () => f.getSTTToken(d.id),
877
- changeMode: v,
878
- enrichAnalytics: l.enrich,
898
+ starterMessages: ((M = d.knowledge) == null ? void 0 : M.starter_message) || [],
899
+ getSTTToken: () => l.getSTTToken(d.id),
900
+ changeMode: C,
901
+ enrichAnalytics: m.enrich,
879
902
  async connect() {
880
903
  var c;
881
- await C(!0), l.track("agent-chat", {
904
+ await k(!0), m.track("agent-chat", {
882
905
  event: "connect",
883
- chatId: (c = t.chat) == null ? void 0 : c.id,
906
+ chatId: (c = n.chat) == null ? void 0 : c.id,
884
907
  agentId: d.id,
885
- mode: t.chatMode
908
+ mode: n.chatMode
886
909
  });
887
910
  },
888
911
  async reconnect() {
889
912
  var c;
890
- await y(), await C(!1), l.track("agent-chat", {
913
+ await y(), await k(!1), m.track("agent-chat", {
891
914
  event: "reconnect",
892
- chatId: (c = t.chat) == null ? void 0 : c.id,
915
+ chatId: (c = n.chat) == null ? void 0 : c.id,
893
916
  agentId: d.id,
894
- mode: t.chatMode
917
+ mode: n.chatMode
895
918
  });
896
919
  },
897
920
  async disconnect() {
898
921
  var c;
899
- await y(), l.track("agent-chat", {
922
+ await y(), m.track("agent-chat", {
900
923
  event: "disconnect",
901
- chatId: (c = t.chat) == null ? void 0 : c.id,
924
+ chatId: (c = n.chat) == null ? void 0 : c.id,
902
925
  agentId: d.id,
903
- mode: t.chatMode
926
+ mode: n.chatMode
904
927
  });
905
928
  },
906
929
  async chat(c) {
907
- var k, _, m, p, R, M;
908
- const w = K();
909
- s = {};
930
+ var v, _, u, w, S, b;
931
+ const h = V();
932
+ i = {};
910
933
  try {
911
- if (z = Date.now(), n.mode === E.DirectPlayback)
934
+ if (L = Date.now(), t.mode === I.DirectPlayback)
912
935
  throw new Error("Direct playback is enabled, chat is disabled");
913
936
  if (c.length >= 800)
914
937
  throw new Error("Message cannot be more than 800 characters");
915
938
  if (c.length === 0)
916
939
  throw new Error("Message cannot be empty");
917
- if (t.chatMode === E.Maintenance)
940
+ if (n.chatMode === I.Maintenance)
918
941
  throw new Error("Chat is in maintenance mode");
919
- if (![E.TextOnly, E.Playground].includes(t.chatMode))
920
- if (t.streamingManager) {
921
- if (!t.chat)
942
+ if (![I.TextOnly, I.Playground].includes(n.chatMode))
943
+ if (n.streamingManager) {
944
+ if (!n.chat)
922
945
  throw new Error("Chat is not initialized");
923
946
  } else
924
947
  throw new Error("Streaming manager is not initialized");
925
- t.messages.push({
926
- id: K(),
948
+ n.messages.push({
949
+ id: V(),
927
950
  role: "user",
928
951
  content: c,
929
- created_at: new Date(z).toISOString()
930
- }), (_ = (k = n.callbacks).onNewMessage) == null || _.call(k, [...t.messages], "user"), t.chat || (t.chat = await te(d.id, f, l, t.chatMode, n.persistentChat), (p = (m = n.callbacks).onNewChat) == null || p.call(m, t.chat.id));
931
- const D = {
932
- id: w,
952
+ created_at: new Date(L).toISOString()
953
+ }), (_ = (v = t.callbacks).onNewMessage) == null || _.call(v, [...n.messages], "user"), n.chat || (n.chat = await ae(d.id, l, m, n.chatMode, t.persistentChat), (w = (u = t.callbacks).onNewChat) == null || w.call(u, n.chat.id));
954
+ const E = {
955
+ id: h,
933
956
  role: "assistant",
934
957
  content: "",
935
958
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
936
959
  matches: []
937
- }, $ = [...t.messages];
938
- t.messages.push(D);
939
- const j = (A) => {
940
- var I, F;
941
- return f.chat(d.id, A, {
942
- sessionId: (I = t.streamingManager) == null ? void 0 : I.sessionId,
943
- streamId: (F = t.streamingManager) == null ? void 0 : F.streamId,
944
- chatMode: t.chatMode,
945
- messages: $.map(({
946
- matches: V,
947
- ...ne
948
- }) => ne)
949
- }, ee(t.chatMode));
950
- }, T = await j(t.chat.id).catch(async (A) => {
951
- var I;
952
- if (!((I = A == null ? void 0 : A.message) != null && I.includes("missing or invalid session_id")))
953
- throw A;
954
- return await y(), await C(!1), j(t.chat.id);
960
+ }, A = [...n.messages];
961
+ n.messages.push(E);
962
+ const F = (P) => {
963
+ var $, x;
964
+ return l.chat(d.id, P, {
965
+ sessionId: ($ = n.streamingManager) == null ? void 0 : $.sessionId,
966
+ streamId: (x = n.streamingManager) == null ? void 0 : x.streamId,
967
+ chatMode: n.chatMode,
968
+ messages: A.map(({
969
+ matches: N,
970
+ ...K
971
+ }) => K)
972
+ }, {
973
+ ...re(n.chatMode),
974
+ skipErrorHandler: !0
975
+ });
976
+ }, T = await F(n.chat.id).catch(async (P) => {
977
+ var N, K, J, O;
978
+ const $ = (N = P == null ? void 0 : P.message) == null ? void 0 : N.includes("missing or invalid session_id");
979
+ if (!((K = P == null ? void 0 : P.message) == null ? void 0 : K.includes("Stream Error")) && !$)
980
+ throw (O = (J = t.callbacks).onError) == null || O.call(J, P, {}), P;
981
+ return await y(), await k(!1), F(n.chat.id);
955
982
  });
956
- return l.track("agent-message-send", {
983
+ return m.track("agent-message-send", {
957
984
  event: "success",
958
- mode: t.chatMode,
959
- messages: t.messages.length + 1
960
- }), D.context = T.context, D.matches = T.matches, T.result && (D.content = T.result, l.track("agent-message-received", {
961
- latency: Date.now() - z,
962
- mode: t.chatMode,
963
- messages: t.messages.length
964
- }), (M = (R = n.callbacks).onNewMessage) == null || M.call(R, [...t.messages], "answer")), T;
965
- } catch (D) {
966
- throw t.messages[t.messages.length - 1].id === w && t.messages.pop(), l.track("agent-message-send", {
985
+ mode: n.chatMode,
986
+ messages: n.messages.length + 1
987
+ }), E.context = T.context, E.matches = T.matches, T.result && (E.content = T.result, m.track("agent-message-received", {
988
+ latency: Date.now() - L,
989
+ mode: n.chatMode,
990
+ messages: n.messages.length
991
+ }), (b = (S = t.callbacks).onNewMessage) == null || b.call(S, [...n.messages], "answer")), T;
992
+ } catch (E) {
993
+ throw n.messages[n.messages.length - 1].id === h && n.messages.pop(), m.track("agent-message-send", {
967
994
  event: "error",
968
- mode: t.chatMode,
969
- messages: t.messages.length
970
- }), D;
995
+ mode: n.chatMode,
996
+ messages: n.messages.length
997
+ }), E;
971
998
  }
972
999
  },
973
- rate(c, w, k) {
974
- var p, R, M, D;
975
- const _ = t.messages.find(($) => $.id === c);
976
- if (t.chat) {
1000
+ rate(c, h, v) {
1001
+ var w, S, b, E;
1002
+ const _ = n.messages.find((A) => A.id === c);
1003
+ if (n.chat) {
977
1004
  if (!_)
978
1005
  throw new Error("Message not found");
979
1006
  } else
980
1007
  throw new Error("Chat is not initialized");
981
- const m = ((p = _.matches) == null ? void 0 : p.map(($) => [$.document_id, $.id])) ?? [];
982
- return l.track("agent-rate", {
983
- event: k ? "update" : "create",
984
- thumb: w === 1 ? "up" : "down",
985
- knowledge_id: ((R = d.knowledge) == null ? void 0 : R.id) ?? "",
986
- mode: t.chatMode,
987
- matches: m,
988
- score: w
989
- }), k ? f.updateRating(d.id, t.chat.id, k, {
990
- knowledge_id: ((M = d.knowledge) == null ? void 0 : M.id) ?? "",
1008
+ const u = ((w = _.matches) == null ? void 0 : w.map((A) => [A.document_id, A.id])) ?? [];
1009
+ return m.track("agent-rate", {
1010
+ event: v ? "update" : "create",
1011
+ thumb: h === 1 ? "up" : "down",
1012
+ knowledge_id: ((S = d.knowledge) == null ? void 0 : S.id) ?? "",
1013
+ mode: n.chatMode,
1014
+ matches: u,
1015
+ score: h
1016
+ }), v ? l.updateRating(d.id, n.chat.id, v, {
1017
+ knowledge_id: ((b = d.knowledge) == null ? void 0 : b.id) ?? "",
991
1018
  message_id: c,
992
- matches: m,
993
- score: w
994
- }) : f.createRating(d.id, t.chat.id, {
995
- knowledge_id: ((D = d.knowledge) == null ? void 0 : D.id) ?? "",
1019
+ matches: u,
1020
+ score: h
1021
+ }) : l.createRating(d.id, n.chat.id, {
1022
+ knowledge_id: ((E = d.knowledge) == null ? void 0 : E.id) ?? "",
996
1023
  message_id: c,
997
- matches: m,
998
- score: w
1024
+ matches: u,
1025
+ score: h
999
1026
  });
1000
1027
  },
1001
1028
  deleteRate(c) {
1002
- var w;
1003
- if (!t.chat)
1029
+ var h;
1030
+ if (!n.chat)
1004
1031
  throw new Error("Chat is not initialized");
1005
- return l.track("agent-rate-delete", {
1032
+ return m.track("agent-rate-delete", {
1006
1033
  type: "text",
1007
- chat_id: (w = t.chat) == null ? void 0 : w.id,
1034
+ chat_id: (h = n.chat) == null ? void 0 : h.id,
1008
1035
  id: c,
1009
- mode: t.chatMode
1010
- }), f.deleteRating(d.id, t.chat.id, c);
1036
+ mode: n.chatMode
1037
+ }), l.deleteRating(d.id, n.chat.id, c);
1011
1038
  },
1012
1039
  speak(c) {
1013
- if (!t.streamingManager)
1040
+ if (!n.streamingManager)
1014
1041
  throw new Error("Please connect to the agent first");
1015
- z = Date.now();
1016
- function w() {
1042
+ L = Date.now();
1043
+ function h() {
1017
1044
  if (typeof c == "string") {
1018
1045
  if (!d.presenter.voice)
1019
1046
  throw new Error("Presenter voice is not initialized");
@@ -1036,36 +1063,36 @@ async function He(e, n) {
1036
1063
  }
1037
1064
  return c;
1038
1065
  }
1039
- const k = w();
1040
- return l.track("agent-speak", k), t.streamingManager.speak({
1041
- script: k
1066
+ const v = h();
1067
+ return m.track("agent-speak", v), n.streamingManager.speak({
1068
+ script: v
1042
1069
  });
1043
1070
  }
1044
1071
  };
1045
1072
  }
1046
- function Ke(e, n, s) {
1073
+ function Ue(e, t, i) {
1047
1074
  const {
1048
- getById: i
1049
- } = G(n, s || H);
1050
- return i(e);
1075
+ getById: a
1076
+ } = te(t, i || H);
1077
+ return a(e);
1051
1078
  }
1052
1079
  export {
1053
- ie as AgentStatus,
1054
- E as ChatMode,
1055
- N as ChatProgress,
1056
- S as ConnectionState,
1057
- de as DocumentType,
1058
- ce as KnowledgeType,
1059
- ae as PlanGroup,
1060
- me as Providers,
1061
- se as RateState,
1080
+ oe as AgentStatus,
1081
+ I as ChatMode,
1082
+ B as ChatProgress,
1083
+ D as ConnectionState,
1084
+ me as DocumentType,
1085
+ le as KnowledgeType,
1086
+ se as PlanGroup,
1087
+ fe as Providers,
1088
+ ce as RateState,
1062
1089
  W as StreamEvents,
1063
- x as StreamingState,
1064
- oe as Subject,
1065
- re as UserPlan,
1066
- O as VideoType,
1067
- ue as VoiceAccess,
1068
- He as createAgentManager,
1069
- Ke as getAgent,
1070
- le as mapVideoType
1090
+ j as StreamingState,
1091
+ de as Subject,
1092
+ ie as UserPlan,
1093
+ Z as VideoType,
1094
+ ge as VoiceAccess,
1095
+ Ve as createAgentManager,
1096
+ Ue as getAgent,
1097
+ ue as mapVideoType
1071
1098
  };