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