@d-id/client-sdk 1.0.19-beta.128 → 1.0.19-beta.129

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