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