@d-id/client-sdk 1.0.19-beta.151 → 1.0.19-beta.153
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 +330 -335
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,10 +9,10 @@ const ue = (e) => {
|
|
|
9
9
|
throw new Error(`Unknown video type: ${e}`);
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
var j = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(j || {}),
|
|
12
|
+
var j = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(j || {}), K = /* @__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))(K || {}), D = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(D || {}), fe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(fe || {}), ge = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ge || {});
|
|
13
13
|
const H = "https://api.d-id.com", he = "wss://notifications.d-id.com", we = "79f81a83a67430be2bc0fd61042b8faa";
|
|
14
|
-
async function
|
|
15
|
-
const
|
|
14
|
+
async function Q(e, t) {
|
|
15
|
+
const s = {
|
|
16
16
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
17
17
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
18
18
|
timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
|
|
@@ -21,31 +21,31 @@ async function G(e, t) {
|
|
|
21
21
|
return !0;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
let
|
|
25
|
-
for (let n = 1; n <=
|
|
24
|
+
let r;
|
|
25
|
+
for (let n = 1; n <= s.limit; n++)
|
|
26
26
|
try {
|
|
27
|
-
if (!
|
|
27
|
+
if (!s.timeout)
|
|
28
28
|
return await e();
|
|
29
|
-
let
|
|
30
|
-
const
|
|
29
|
+
let i;
|
|
30
|
+
const a = new Promise((d, f) => {
|
|
31
31
|
e().then((m) => {
|
|
32
|
-
clearTimeout(
|
|
32
|
+
clearTimeout(i), d(m);
|
|
33
33
|
}).catch((m) => {
|
|
34
|
-
clearTimeout(
|
|
34
|
+
clearTimeout(i), f(m);
|
|
35
35
|
});
|
|
36
36
|
}), o = new Promise((d, f) => {
|
|
37
|
-
|
|
37
|
+
i = setTimeout(() => f(new Error(s.timeoutErrorMessage)), s.timeout);
|
|
38
38
|
});
|
|
39
|
-
return await Promise.race([
|
|
40
|
-
} catch (
|
|
41
|
-
if (
|
|
42
|
-
throw
|
|
43
|
-
|
|
39
|
+
return await Promise.race([a, o]);
|
|
40
|
+
} catch (i) {
|
|
41
|
+
if (r = i, !s.shouldRetryFn(i) || n >= s.limit)
|
|
42
|
+
throw i;
|
|
43
|
+
s.delayMs > 0 && await new Promise((a) => setTimeout(a, s.delayMs));
|
|
44
44
|
}
|
|
45
|
-
throw
|
|
45
|
+
throw r;
|
|
46
46
|
}
|
|
47
47
|
const V = () => Math.random().toString(16).slice(2);
|
|
48
|
-
function
|
|
48
|
+
function G() {
|
|
49
49
|
let e = window.localStorage.getItem("did_external_key_id");
|
|
50
50
|
return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
|
|
51
51
|
}
|
|
@@ -56,21 +56,21 @@ function ee(e) {
|
|
|
56
56
|
if (e.type === "basic")
|
|
57
57
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
58
58
|
if (e.type === "key")
|
|
59
|
-
return `Client-Key ${e.clientKey}.${
|
|
59
|
+
return `Client-Key ${e.clientKey}.${G()}_${pe}`;
|
|
60
60
|
throw new Error(`Unknown auth type: ${e}`);
|
|
61
61
|
}
|
|
62
|
-
const ye = (e) =>
|
|
62
|
+
const ye = (e) => Q(e, {
|
|
63
63
|
limit: 3,
|
|
64
64
|
delayMs: 1e3,
|
|
65
65
|
timeout: 0,
|
|
66
66
|
shouldRetryFn: (t) => t.status === 429
|
|
67
67
|
});
|
|
68
|
-
function q(e, t = H,
|
|
69
|
-
const
|
|
68
|
+
function q(e, t = H, s) {
|
|
69
|
+
const r = async (n, i) => {
|
|
70
70
|
const {
|
|
71
|
-
skipErrorHandler:
|
|
71
|
+
skipErrorHandler: a,
|
|
72
72
|
...o
|
|
73
|
-
} =
|
|
73
|
+
} = i || {}, l = await ye(() => fetch(t + (n != null && n.startsWith("/") ? n : `/${n}`), {
|
|
74
74
|
...o,
|
|
75
75
|
headers: {
|
|
76
76
|
...o.headers,
|
|
@@ -80,7 +80,7 @@ function q(e, t = H, i) {
|
|
|
80
80
|
}));
|
|
81
81
|
if (!l.ok) {
|
|
82
82
|
let d = await l.text().catch(() => "Failed to fetch");
|
|
83
|
-
throw
|
|
83
|
+
throw s && !a && s(new Error(d), {
|
|
84
84
|
url: n,
|
|
85
85
|
options: o,
|
|
86
86
|
headers: l.headers
|
|
@@ -89,88 +89,88 @@ function q(e, t = H, i) {
|
|
|
89
89
|
return l.json();
|
|
90
90
|
};
|
|
91
91
|
return {
|
|
92
|
-
get(n,
|
|
93
|
-
return
|
|
94
|
-
...
|
|
92
|
+
get(n, i) {
|
|
93
|
+
return r(n, {
|
|
94
|
+
...i,
|
|
95
95
|
method: "GET"
|
|
96
96
|
});
|
|
97
97
|
},
|
|
98
|
-
post(n,
|
|
99
|
-
return
|
|
100
|
-
...
|
|
101
|
-
body: JSON.stringify(
|
|
98
|
+
post(n, i, a) {
|
|
99
|
+
return r(n, {
|
|
100
|
+
...a,
|
|
101
|
+
body: JSON.stringify(i),
|
|
102
102
|
method: "POST"
|
|
103
103
|
});
|
|
104
104
|
},
|
|
105
|
-
delete(n,
|
|
106
|
-
return
|
|
107
|
-
...
|
|
108
|
-
body: JSON.stringify(
|
|
105
|
+
delete(n, i, a) {
|
|
106
|
+
return r(n, {
|
|
107
|
+
...a,
|
|
108
|
+
body: JSON.stringify(i),
|
|
109
109
|
method: "DELETE"
|
|
110
110
|
});
|
|
111
111
|
},
|
|
112
|
-
patch(n,
|
|
113
|
-
return
|
|
114
|
-
...
|
|
115
|
-
body: JSON.stringify(
|
|
112
|
+
patch(n, i, a) {
|
|
113
|
+
return r(n, {
|
|
114
|
+
...a,
|
|
115
|
+
body: JSON.stringify(i),
|
|
116
116
|
method: "PATCH"
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
function te(e, t = H,
|
|
122
|
-
const
|
|
121
|
+
function te(e, t = H, s) {
|
|
122
|
+
const r = q(e, `${t}/agents`, s);
|
|
123
123
|
return {
|
|
124
|
-
create(n,
|
|
125
|
-
return
|
|
124
|
+
create(n, i) {
|
|
125
|
+
return r.post("/", n, i);
|
|
126
126
|
},
|
|
127
|
-
getAgents(n,
|
|
128
|
-
return
|
|
127
|
+
getAgents(n, i) {
|
|
128
|
+
return r.get(`/${n ? `?tag=${n}` : ""}`, i).then((a) => a ?? []);
|
|
129
129
|
},
|
|
130
|
-
getById(n,
|
|
131
|
-
return
|
|
130
|
+
getById(n, i) {
|
|
131
|
+
return r.get(`/${n}`, i);
|
|
132
132
|
},
|
|
133
|
-
delete(n,
|
|
134
|
-
return
|
|
133
|
+
delete(n, i) {
|
|
134
|
+
return r.delete(`/${n}`, void 0, i);
|
|
135
135
|
},
|
|
136
|
-
update(n,
|
|
137
|
-
return
|
|
136
|
+
update(n, i, a) {
|
|
137
|
+
return r.patch(`/${n}`, i, a);
|
|
138
138
|
},
|
|
139
|
-
newChat(n,
|
|
140
|
-
return
|
|
139
|
+
newChat(n, i, a) {
|
|
140
|
+
return r.post(`/${n}/chat`, i, a);
|
|
141
141
|
},
|
|
142
|
-
chat(n,
|
|
143
|
-
return
|
|
142
|
+
chat(n, i, a, o) {
|
|
143
|
+
return r.post(`/${n}/chat/${i}`, a, o);
|
|
144
144
|
},
|
|
145
|
-
createRating(n,
|
|
146
|
-
return
|
|
145
|
+
createRating(n, i, a, o) {
|
|
146
|
+
return r.post(`/${n}/chat/${i}/ratings`, a, o);
|
|
147
147
|
},
|
|
148
|
-
updateRating(n,
|
|
149
|
-
return
|
|
148
|
+
updateRating(n, i, a, o, l) {
|
|
149
|
+
return r.patch(`/${n}/chat/${i}/ratings/${a}`, o, l);
|
|
150
150
|
},
|
|
151
|
-
deleteRating(n,
|
|
152
|
-
return
|
|
151
|
+
deleteRating(n, i, a, o) {
|
|
152
|
+
return r.delete(`/${n}/chat/${i}/ratings/${a}`, o);
|
|
153
153
|
},
|
|
154
|
-
getSTTToken(n,
|
|
155
|
-
return
|
|
154
|
+
getSTTToken(n, i) {
|
|
155
|
+
return r.get(`/${n}/stt-token`, i);
|
|
156
156
|
}
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
const ve = (e) => new Promise((t) => setTimeout(t, e));
|
|
160
160
|
function ke(e) {
|
|
161
|
-
return new Promise((t,
|
|
161
|
+
return new Promise((t, s) => {
|
|
162
162
|
const {
|
|
163
|
-
callbacks:
|
|
163
|
+
callbacks: r,
|
|
164
164
|
host: n,
|
|
165
|
-
auth:
|
|
165
|
+
auth: i
|
|
166
166
|
} = e, {
|
|
167
|
-
onMessage:
|
|
167
|
+
onMessage: a = null,
|
|
168
168
|
onOpen: o = null,
|
|
169
169
|
onClose: l = null,
|
|
170
170
|
onError: d = null
|
|
171
|
-
} =
|
|
172
|
-
f.onmessage =
|
|
173
|
-
console.error(m), d == null || d("Websocket failed to connect", m),
|
|
171
|
+
} = r || {}, f = new WebSocket(`${n}?authorization=${ee(i)}`);
|
|
172
|
+
f.onmessage = a, f.onclose = l, f.onerror = (m) => {
|
|
173
|
+
console.error(m), d == null || d("Websocket failed to connect", m), s(m);
|
|
174
174
|
}, f.onopen = (m) => {
|
|
175
175
|
o == null || o(m), t(f);
|
|
176
176
|
};
|
|
@@ -180,213 +180,213 @@ async function Ce(e) {
|
|
|
180
180
|
const {
|
|
181
181
|
retries: t = 1
|
|
182
182
|
} = e;
|
|
183
|
-
let
|
|
184
|
-
for (let
|
|
183
|
+
let s = null;
|
|
184
|
+
for (let r = 0; (s == null ? void 0 : s.readyState) !== WebSocket.OPEN; r++)
|
|
185
185
|
try {
|
|
186
|
-
|
|
186
|
+
s = await ke(e);
|
|
187
187
|
} catch (n) {
|
|
188
|
-
if (
|
|
188
|
+
if (r === t)
|
|
189
189
|
throw n;
|
|
190
|
-
await ve(
|
|
190
|
+
await ve(r * 500);
|
|
191
191
|
}
|
|
192
|
-
return
|
|
192
|
+
return s;
|
|
193
193
|
}
|
|
194
|
-
async function Re(e, t,
|
|
195
|
-
const
|
|
194
|
+
async function Re(e, t, s) {
|
|
195
|
+
const r = s != null && s.onMessage ? [s.onMessage] : [], n = await Ce({
|
|
196
196
|
auth: e,
|
|
197
197
|
host: t,
|
|
198
198
|
callbacks: {
|
|
199
|
-
onError:
|
|
200
|
-
onMessage: (
|
|
201
|
-
const
|
|
202
|
-
|
|
199
|
+
onError: s == null ? void 0 : s.onError,
|
|
200
|
+
onMessage: (i) => {
|
|
201
|
+
const a = JSON.parse(i.data);
|
|
202
|
+
r.forEach((o) => o(a.event, a));
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
});
|
|
206
206
|
return {
|
|
207
207
|
socket: n,
|
|
208
208
|
disconnect: () => n.close(),
|
|
209
|
-
subscribeToEvents: (
|
|
209
|
+
subscribeToEvents: (i) => r.push(i)
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
-
const
|
|
213
|
-
function
|
|
214
|
-
const n = q(e, `${t}/agents/${
|
|
212
|
+
const De = "X-Playground-Chat";
|
|
213
|
+
function Se(e, t, s, r) {
|
|
214
|
+
const n = q(e, `${t}/agents/${s}`, r);
|
|
215
215
|
return {
|
|
216
|
-
createStream(
|
|
216
|
+
createStream(i) {
|
|
217
217
|
return n.post("/streams", {
|
|
218
|
-
output_resolution:
|
|
219
|
-
compatibility_mode:
|
|
220
|
-
stream_warmup:
|
|
221
|
-
session_timeout:
|
|
222
|
-
stream_greeting:
|
|
218
|
+
output_resolution: i.output_resolution,
|
|
219
|
+
compatibility_mode: i.compatibility_mode,
|
|
220
|
+
stream_warmup: i.stream_warmup,
|
|
221
|
+
session_timeout: i.session_timeout,
|
|
222
|
+
stream_greeting: i.stream_greeting
|
|
223
223
|
});
|
|
224
224
|
},
|
|
225
|
-
startConnection(
|
|
226
|
-
return n.post(`/streams/${
|
|
225
|
+
startConnection(i, a, o) {
|
|
226
|
+
return n.post(`/streams/${i}/sdp`, {
|
|
227
227
|
session_id: o,
|
|
228
|
-
answer:
|
|
228
|
+
answer: a
|
|
229
229
|
});
|
|
230
230
|
},
|
|
231
|
-
addIceCandidate(
|
|
232
|
-
return n.post(`/streams/${
|
|
231
|
+
addIceCandidate(i, a, o) {
|
|
232
|
+
return n.post(`/streams/${i}/ice`, {
|
|
233
233
|
session_id: o,
|
|
234
|
-
...
|
|
234
|
+
...a
|
|
235
235
|
});
|
|
236
236
|
},
|
|
237
|
-
sendStreamRequest(
|
|
238
|
-
return n.post(`/streams/${
|
|
239
|
-
session_id:
|
|
237
|
+
sendStreamRequest(i, a, o) {
|
|
238
|
+
return n.post(`/streams/${i}`, {
|
|
239
|
+
session_id: a,
|
|
240
240
|
...o
|
|
241
241
|
});
|
|
242
242
|
},
|
|
243
|
-
close(
|
|
244
|
-
return n.delete(`/streams/${
|
|
245
|
-
session_id:
|
|
243
|
+
close(i, a) {
|
|
244
|
+
return n.delete(`/streams/${i}`, {
|
|
245
|
+
session_id: a
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
function _e(e, t,
|
|
251
|
-
const n = q(e, `${t}/agents/${
|
|
250
|
+
function _e(e, t, s, r) {
|
|
251
|
+
const n = q(e, `${t}/agents/${s}`, r);
|
|
252
252
|
return {
|
|
253
|
-
createStream(
|
|
253
|
+
createStream(i, a) {
|
|
254
254
|
return n.post("/streams", {
|
|
255
|
-
driver_url:
|
|
256
|
-
face:
|
|
257
|
-
config:
|
|
258
|
-
output_resolution:
|
|
259
|
-
compatibility_mode:
|
|
260
|
-
stream_warmup:
|
|
261
|
-
session_timeout:
|
|
262
|
-
stream_greeting:
|
|
263
|
-
},
|
|
255
|
+
driver_url: i.driver_url,
|
|
256
|
+
face: i.face,
|
|
257
|
+
config: i.config,
|
|
258
|
+
output_resolution: i.output_resolution,
|
|
259
|
+
compatibility_mode: i.compatibility_mode,
|
|
260
|
+
stream_warmup: i.stream_warmup,
|
|
261
|
+
session_timeout: i.session_timeout,
|
|
262
|
+
stream_greeting: i.stream_greeting
|
|
263
|
+
}, a);
|
|
264
264
|
},
|
|
265
|
-
startConnection(
|
|
266
|
-
return n.post(`/streams/${
|
|
265
|
+
startConnection(i, a, o, l) {
|
|
266
|
+
return n.post(`/streams/${i}/sdp`, {
|
|
267
267
|
session_id: o,
|
|
268
|
-
answer:
|
|
268
|
+
answer: a
|
|
269
269
|
}, l);
|
|
270
270
|
},
|
|
271
|
-
addIceCandidate(
|
|
272
|
-
return n.post(`/streams/${
|
|
271
|
+
addIceCandidate(i, a, o, l) {
|
|
272
|
+
return n.post(`/streams/${i}/ice`, {
|
|
273
273
|
session_id: o,
|
|
274
|
-
...
|
|
274
|
+
...a
|
|
275
275
|
}, l);
|
|
276
276
|
},
|
|
277
|
-
sendStreamRequest(
|
|
278
|
-
return n.post(`/streams/${
|
|
279
|
-
session_id:
|
|
277
|
+
sendStreamRequest(i, a, o, l) {
|
|
278
|
+
return n.post(`/streams/${i}`, {
|
|
279
|
+
session_id: a,
|
|
280
280
|
...o
|
|
281
281
|
}, l);
|
|
282
282
|
},
|
|
283
|
-
close(
|
|
284
|
-
return n.delete(`/streams/${
|
|
285
|
-
session_id:
|
|
283
|
+
close(i, a, o) {
|
|
284
|
+
return n.delete(`/streams/${i}`, {
|
|
285
|
+
session_id: a
|
|
286
286
|
}, o);
|
|
287
287
|
}
|
|
288
288
|
};
|
|
289
289
|
}
|
|
290
|
-
function Me(e, t,
|
|
291
|
-
const
|
|
290
|
+
function Me(e, t, s) {
|
|
291
|
+
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
292
292
|
return {
|
|
293
|
-
duration:
|
|
293
|
+
duration: r,
|
|
294
294
|
bytesReceived: t.bytesReceived - e.bytesReceived,
|
|
295
|
-
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 /
|
|
295
|
+
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / r),
|
|
296
296
|
packetsReceived: t.packetsReceived - e.packetsReceived,
|
|
297
297
|
packetsLost: t.packetsLost - e.packetsLost,
|
|
298
298
|
framesDropped: t.framesDropped - e.framesDropped,
|
|
299
299
|
framesDecoded: t.framesDecoded - e.framesDecoded,
|
|
300
300
|
jitter: t.jitter,
|
|
301
|
-
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) /
|
|
301
|
+
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / r,
|
|
302
302
|
framesPerSecond: t.framesPerSecond,
|
|
303
303
|
freezeCount: t.freezeCount - e.freezeCount,
|
|
304
304
|
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
305
|
-
lowFpsCount:
|
|
305
|
+
lowFpsCount: s
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
308
|
function be(e) {
|
|
309
309
|
return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
|
|
310
310
|
const {
|
|
311
|
-
timestamp:
|
|
312
|
-
...
|
|
311
|
+
timestamp: s,
|
|
312
|
+
...r
|
|
313
313
|
} = t, n = [];
|
|
314
314
|
return t.freezeCount > 0 && n.push("freeze"), t.framesPerSecond < 21 && n.push("low fps"), t.framesDropped > 0 && n.push("frames dropped"), t.packetsLost > 0 && n.push("packet loss"), {
|
|
315
|
-
...
|
|
315
|
+
...r,
|
|
316
316
|
causes: n
|
|
317
317
|
};
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
320
|
function Ee(e) {
|
|
321
321
|
let t = "";
|
|
322
|
-
for (const
|
|
323
|
-
if (
|
|
322
|
+
for (const s of e.values())
|
|
323
|
+
if (s && s.type === "codec" && s.mimeType.startsWith("video") && (t = s.mimeType.split("/")[1]), s && s.type === "inbound-rtp" && s.kind === "video")
|
|
324
324
|
return {
|
|
325
325
|
codec: t,
|
|
326
|
-
timestamp:
|
|
327
|
-
bytesReceived:
|
|
328
|
-
packetsReceived:
|
|
329
|
-
packetsLost:
|
|
330
|
-
framesDropped:
|
|
331
|
-
framesDecoded:
|
|
332
|
-
jitter:
|
|
333
|
-
jitterBufferDelay:
|
|
334
|
-
frameWidth:
|
|
335
|
-
frameHeight:
|
|
336
|
-
framesPerSecond:
|
|
337
|
-
freezeCount:
|
|
338
|
-
freezeDuration:
|
|
326
|
+
timestamp: s.timestamp,
|
|
327
|
+
bytesReceived: s.bytesReceived,
|
|
328
|
+
packetsReceived: s.packetsReceived,
|
|
329
|
+
packetsLost: s.packetsLost,
|
|
330
|
+
framesDropped: s.framesDropped,
|
|
331
|
+
framesDecoded: s.framesDecoded,
|
|
332
|
+
jitter: s.jitter,
|
|
333
|
+
jitterBufferDelay: s.jitterBufferDelay,
|
|
334
|
+
frameWidth: s.frameWidth,
|
|
335
|
+
frameHeight: s.frameHeight,
|
|
336
|
+
framesPerSecond: s.framesPerSecond,
|
|
337
|
+
freezeCount: s.freezeCount,
|
|
338
|
+
freezeDuration: s.totalFreezesDuration
|
|
339
339
|
};
|
|
340
340
|
return {};
|
|
341
341
|
}
|
|
342
|
-
function Ie(e, t,
|
|
343
|
-
const
|
|
344
|
-
timestamp:
|
|
342
|
+
function Ie(e, t, s) {
|
|
343
|
+
const r = e.map((a, o) => o === 0 ? s ? {
|
|
344
|
+
timestamp: a.timestamp,
|
|
345
345
|
duration: 0,
|
|
346
|
-
bytesReceived:
|
|
347
|
-
bitrate: (
|
|
348
|
-
packetsReceived:
|
|
349
|
-
packetsLost:
|
|
350
|
-
framesDropped:
|
|
351
|
-
framesDecoded:
|
|
352
|
-
jitter:
|
|
353
|
-
jitterBufferDelay:
|
|
354
|
-
framesPerSecond:
|
|
355
|
-
freezeCount:
|
|
356
|
-
freezeDuration:
|
|
346
|
+
bytesReceived: a.bytesReceived - s.bytesReceived,
|
|
347
|
+
bitrate: (a.bytesReceived - s.bytesReceived) * 8 / (t / 1e3),
|
|
348
|
+
packetsReceived: a.packetsReceived - s.packetsReceived,
|
|
349
|
+
packetsLost: a.packetsLost - s.packetsLost,
|
|
350
|
+
framesDropped: a.framesDropped - s.framesDropped,
|
|
351
|
+
framesDecoded: a.framesDecoded - s.framesDecoded,
|
|
352
|
+
jitter: a.jitter,
|
|
353
|
+
jitterBufferDelay: a.jitterBufferDelay - s.jitterBufferDelay,
|
|
354
|
+
framesPerSecond: a.framesPerSecond,
|
|
355
|
+
freezeCount: a.freezeCount - s.freezeCount,
|
|
356
|
+
freezeDuration: a.freezeDuration - s.freezeDuration
|
|
357
357
|
} : {
|
|
358
|
-
timestamp:
|
|
358
|
+
timestamp: a.timestamp,
|
|
359
359
|
duration: 0,
|
|
360
|
-
bytesReceived:
|
|
361
|
-
bitrate:
|
|
362
|
-
packetsReceived:
|
|
363
|
-
packetsLost:
|
|
364
|
-
framesDropped:
|
|
365
|
-
framesDecoded:
|
|
366
|
-
jitter:
|
|
367
|
-
jitterBufferDelay:
|
|
368
|
-
framesPerSecond:
|
|
369
|
-
freezeCount:
|
|
370
|
-
freezeDuration:
|
|
360
|
+
bytesReceived: a.bytesReceived,
|
|
361
|
+
bitrate: a.bytesReceived * 8 / (t / 1e3),
|
|
362
|
+
packetsReceived: a.packetsReceived,
|
|
363
|
+
packetsLost: a.packetsLost,
|
|
364
|
+
framesDropped: a.framesDropped,
|
|
365
|
+
framesDecoded: a.framesDecoded,
|
|
366
|
+
jitter: a.jitter,
|
|
367
|
+
jitterBufferDelay: a.jitterBufferDelay,
|
|
368
|
+
framesPerSecond: a.framesPerSecond,
|
|
369
|
+
freezeCount: a.freezeCount,
|
|
370
|
+
freezeDuration: a.freezeDuration
|
|
371
371
|
} : {
|
|
372
|
-
timestamp:
|
|
372
|
+
timestamp: a.timestamp,
|
|
373
373
|
duration: t * o / 1e3,
|
|
374
|
-
bytesReceived:
|
|
375
|
-
bitrate: (
|
|
376
|
-
packetsReceived:
|
|
377
|
-
packetsLost:
|
|
378
|
-
framesDropped:
|
|
379
|
-
framesDecoded:
|
|
380
|
-
jitter:
|
|
381
|
-
jitterBufferDelay:
|
|
382
|
-
framesPerSecond:
|
|
383
|
-
freezeCount:
|
|
384
|
-
freezeDuration:
|
|
385
|
-
}), n = be(
|
|
374
|
+
bytesReceived: a.bytesReceived - e[o - 1].bytesReceived,
|
|
375
|
+
bitrate: (a.bytesReceived - e[o - 1].bytesReceived) * 8 / (t / 1e3),
|
|
376
|
+
packetsReceived: a.packetsReceived - e[o - 1].packetsReceived,
|
|
377
|
+
packetsLost: a.packetsLost - e[o - 1].packetsLost,
|
|
378
|
+
framesDropped: a.framesDropped - e[o - 1].framesDropped,
|
|
379
|
+
framesDecoded: a.framesDecoded - e[o - 1].framesDecoded,
|
|
380
|
+
jitter: a.jitter,
|
|
381
|
+
jitterBufferDelay: a.jitterBufferDelay - e[o - 1].jitterBufferDelay,
|
|
382
|
+
framesPerSecond: a.framesPerSecond,
|
|
383
|
+
freezeCount: a.freezeCount - e[o - 1].freezeCount,
|
|
384
|
+
freezeDuration: a.freezeDuration - e[o - 1].freezeDuration
|
|
385
|
+
}), n = be(r), i = n.reduce((a, o) => a + (o.causes.includes("low fps") ? 1 : 0), 0);
|
|
386
386
|
return {
|
|
387
387
|
webRTCStats: {
|
|
388
388
|
anomalies: n,
|
|
389
|
-
aggregateReport: Me(e[0], e[e.length - 1],
|
|
389
|
+
aggregateReport: Me(e[0], e[e.length - 1], i)
|
|
390
390
|
},
|
|
391
391
|
codec: e[0].codec,
|
|
392
392
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
@@ -417,45 +417,45 @@ function X(e) {
|
|
|
417
417
|
function $e() {
|
|
418
418
|
let e = 0;
|
|
419
419
|
return (t) => {
|
|
420
|
-
for (const
|
|
421
|
-
if (
|
|
422
|
-
const
|
|
423
|
-
return e =
|
|
420
|
+
for (const s of t.values())
|
|
421
|
+
if (s && s.type === "inbound-rtp" && s.kind === "video") {
|
|
422
|
+
const r = s.bytesReceived, n = r - e > 0;
|
|
423
|
+
return e = r, n;
|
|
424
424
|
}
|
|
425
425
|
return !1;
|
|
426
426
|
};
|
|
427
427
|
}
|
|
428
|
-
function Ae(e, t,
|
|
429
|
-
const
|
|
430
|
-
let
|
|
431
|
-
const
|
|
432
|
-
let
|
|
433
|
-
const
|
|
428
|
+
function Ae(e, t, s = !1, r, n, i = !1) {
|
|
429
|
+
const o = Math.max(Math.ceil(10), 1);
|
|
430
|
+
let l = [], d, f = 0, m = !1;
|
|
431
|
+
const p = s ? 1 : 0;
|
|
432
|
+
let k = 0;
|
|
433
|
+
const y = $e();
|
|
434
434
|
return setInterval(async () => {
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
else if (
|
|
439
|
-
const
|
|
440
|
-
t == null || t(j.Stop,
|
|
435
|
+
const C = await e.getStats(), g = y(C), R = Ee(C);
|
|
436
|
+
if (g)
|
|
437
|
+
f = 0, console.log("isReceiving", g), m || (t == null || t(j.Start), i && k >= p && !r() && n(), d = l[l.length - 1], l = [], k++, m = !0), l.push(R);
|
|
438
|
+
else if (m && (console.log("notReceiving", g), f++, f >= o)) {
|
|
439
|
+
const S = Ie(l, 100, d);
|
|
440
|
+
t == null || t(j.Stop, S), !i && !r() && n(), m = !1;
|
|
441
441
|
}
|
|
442
442
|
}, 100);
|
|
443
443
|
}
|
|
444
444
|
async function Te(e, t, {
|
|
445
|
-
debug:
|
|
446
|
-
callbacks:
|
|
445
|
+
debug: s = !1,
|
|
446
|
+
callbacks: r,
|
|
447
447
|
auth: n,
|
|
448
|
-
baseURL:
|
|
449
|
-
warmup:
|
|
448
|
+
baseURL: i = H,
|
|
449
|
+
warmup: a
|
|
450
450
|
}) {
|
|
451
|
-
ne =
|
|
451
|
+
ne = s;
|
|
452
452
|
const {
|
|
453
453
|
startConnection: o,
|
|
454
454
|
sendStreamRequest: l,
|
|
455
455
|
close: d,
|
|
456
456
|
createStream: f,
|
|
457
457
|
addIceCandidate: m
|
|
458
|
-
} = t.videoType === Z.Clip ?
|
|
458
|
+
} = t.videoType === Z.Clip ? Se(n, i, e, r.onError) : _e(n, i, e, r.onError), {
|
|
459
459
|
id: p,
|
|
460
460
|
offer: k,
|
|
461
461
|
ice_servers: y,
|
|
@@ -465,11 +465,11 @@ async function Te(e, t, {
|
|
|
465
465
|
}), R = g.createDataChannel("JanusDataChannel");
|
|
466
466
|
if (!C)
|
|
467
467
|
throw new Error("Could not create session_id");
|
|
468
|
-
let
|
|
469
|
-
const c = () =>
|
|
468
|
+
let S = !1;
|
|
469
|
+
const c = () => S, h = () => {
|
|
470
470
|
var u;
|
|
471
|
-
|
|
472
|
-
}, v = Ae(g,
|
|
471
|
+
console.log("On connected"), S = !0, (u = r.onConnectionStateChange) == null || u.call(r, D.Connected);
|
|
472
|
+
}, v = Ae(g, r.onVideoStateChange, a, c, h, !!t.stream_greeting);
|
|
473
473
|
g.onicecandidate = (u) => {
|
|
474
474
|
var w;
|
|
475
475
|
z("peerConnection.onicecandidate", u);
|
|
@@ -481,26 +481,21 @@ async function Te(e, t, {
|
|
|
481
481
|
}, C) : m(p, {
|
|
482
482
|
candidate: null
|
|
483
483
|
}, C);
|
|
484
|
-
} catch (
|
|
485
|
-
(w =
|
|
484
|
+
} catch (M) {
|
|
485
|
+
(w = r.onError) == null || w.call(r, M, {
|
|
486
486
|
streamId: p
|
|
487
487
|
});
|
|
488
488
|
}
|
|
489
|
-
}, R.onmessage = (u) => {
|
|
490
|
-
if (console.log("data channel message", u.data), R.readyState === "open") {
|
|
491
|
-
const [w, S] = u.data.split(":");
|
|
492
|
-
w === W.StreamReady && !M && h();
|
|
493
|
-
}
|
|
494
489
|
}, R.onopen = () => {
|
|
495
490
|
!t.stream_warmup && !t.stream_greeting && h();
|
|
496
491
|
}, g.oniceconnectionstatechange = () => {
|
|
497
492
|
var w;
|
|
498
493
|
z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
499
494
|
const u = X(g.iceConnectionState);
|
|
500
|
-
u !== D.Connected && ((w =
|
|
495
|
+
u !== D.Connected && ((w = r.onConnectionStateChange) == null || w.call(r, u));
|
|
501
496
|
}, g.ontrack = (u) => {
|
|
502
497
|
var w;
|
|
503
|
-
z("peerConnection.ontrack", u), (w =
|
|
498
|
+
z("peerConnection.ontrack", u), (w = r.onSrcObjectReady) == null || w.call(r, u.streams[0]);
|
|
504
499
|
}, await g.setRemoteDescription(k), z("set remote description OK");
|
|
505
500
|
const _ = await g.createAnswer();
|
|
506
501
|
return z("create answer OK"), await g.setLocalDescription(_), z("set local description OK"), await o(p, _, C), z("start connection OK"), {
|
|
@@ -517,21 +512,21 @@ async function Te(e, t, {
|
|
|
517
512
|
async disconnect() {
|
|
518
513
|
var u, w;
|
|
519
514
|
if (p) {
|
|
520
|
-
const
|
|
515
|
+
const M = X(g.iceConnectionState);
|
|
521
516
|
if (g) {
|
|
522
|
-
if (
|
|
523
|
-
(u =
|
|
517
|
+
if (M === D.New) {
|
|
518
|
+
(u = r.onVideoStateChange) == null || u.call(r, j.Stop), clearInterval(v);
|
|
524
519
|
return;
|
|
525
520
|
}
|
|
526
521
|
g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
|
|
527
522
|
}
|
|
528
523
|
try {
|
|
529
|
-
|
|
524
|
+
M === D.Connected && await d(p, C).catch((b) => {
|
|
530
525
|
});
|
|
531
526
|
} catch (b) {
|
|
532
527
|
z("Error on close stream connection", b);
|
|
533
528
|
}
|
|
534
|
-
(w =
|
|
529
|
+
(w = r.onVideoStateChange) == null || w.call(r, j.Stop), clearInterval(v);
|
|
535
530
|
}
|
|
536
531
|
},
|
|
537
532
|
/**
|
|
@@ -546,23 +541,23 @@ async function Te(e, t, {
|
|
|
546
541
|
}
|
|
547
542
|
let U = {};
|
|
548
543
|
function ze(e) {
|
|
549
|
-
var
|
|
550
|
-
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk",
|
|
544
|
+
var i, a, o, l, d;
|
|
545
|
+
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", s = e.agent.presenter, r = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, n = {
|
|
551
546
|
token: e.token || "testKey",
|
|
552
|
-
distinct_id: e.distinctId ||
|
|
547
|
+
distinct_id: e.distinctId || G(),
|
|
553
548
|
agentId: e.agent.id,
|
|
554
|
-
agentType:
|
|
549
|
+
agentType: s.type === "clip" && s.presenter_id.startsWith("v2_") ? "clip_v2" : s.type,
|
|
555
550
|
owner_id: e.agent.owner_id ?? "",
|
|
556
551
|
behavior: {
|
|
557
|
-
role:
|
|
558
|
-
personality:
|
|
559
|
-
instructions: (
|
|
552
|
+
role: r == null ? void 0 : r.role,
|
|
553
|
+
personality: r == null ? void 0 : r.personality,
|
|
554
|
+
instructions: (a = e.agent.llm) == null ? void 0 : a.instructions
|
|
560
555
|
},
|
|
561
556
|
temperature: (o = e.agent.llm) == null ? void 0 : o.temperature,
|
|
562
|
-
knowledgeSource:
|
|
557
|
+
knowledgeSource: r == null ? void 0 : r.knowledge_source,
|
|
563
558
|
starterQuestionsCount: (d = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : d.length,
|
|
564
|
-
topicsToAvoid:
|
|
565
|
-
maxResponseLength:
|
|
559
|
+
topicsToAvoid: r == null ? void 0 : r.topics_to_avoid,
|
|
560
|
+
maxResponseLength: r == null ? void 0 : r.max_response_length
|
|
566
561
|
};
|
|
567
562
|
return {
|
|
568
563
|
...n,
|
|
@@ -620,9 +615,9 @@ function ze(e) {
|
|
|
620
615
|
if (y.events[p] = {
|
|
621
616
|
props: m
|
|
622
617
|
}, y.resolvedDependencies.push(p), k.every((g) => y.resolvedDependencies.includes(g))) {
|
|
623
|
-
const g = k.reduce((R,
|
|
618
|
+
const g = k.reduce((R, S) => y.events[S] ? {
|
|
624
619
|
...R,
|
|
625
|
-
...y.events[
|
|
620
|
+
...y.events[S].props
|
|
626
621
|
} : R, {});
|
|
627
622
|
this.track(f, g), y.resolvedDependencies = y.resolvedDependencies.filter((R) => !k.includes(R)), k.forEach((R) => {
|
|
628
623
|
delete y.events[R];
|
|
@@ -632,32 +627,32 @@ function ze(e) {
|
|
|
632
627
|
};
|
|
633
628
|
}
|
|
634
629
|
function Le(e) {
|
|
635
|
-
var n,
|
|
636
|
-
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop",
|
|
630
|
+
var n, i, a, o;
|
|
631
|
+
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", s = () => {
|
|
637
632
|
const l = navigator.platform;
|
|
638
633
|
return l.toLowerCase().includes("win") ? "Windows" : l.toLowerCase().includes("mac") ? "Mac OS X" : l.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
639
|
-
},
|
|
634
|
+
}, r = e.presenter;
|
|
640
635
|
return {
|
|
641
|
-
$os: `${
|
|
636
|
+
$os: `${s()}`,
|
|
642
637
|
isMobile: `${t() == "Mobile"}`,
|
|
643
638
|
browser: navigator.userAgent,
|
|
644
639
|
origin: window.location.origin,
|
|
645
|
-
agentType:
|
|
640
|
+
agentType: r.type === "clip" && r.presenter_id.startsWith("v2_") ? "clip_v2" : r.type,
|
|
646
641
|
agentVoice: {
|
|
647
|
-
voiceId: (
|
|
648
|
-
provider: (o = (
|
|
642
|
+
voiceId: (i = (n = e.presenter) == null ? void 0 : n.voice) == null ? void 0 : i.voice_id,
|
|
643
|
+
provider: (o = (a = e.presenter) == null ? void 0 : a.voice) == null ? void 0 : o.type
|
|
649
644
|
}
|
|
650
645
|
};
|
|
651
646
|
}
|
|
652
|
-
function je(e, t,
|
|
647
|
+
function je(e, t, s) {
|
|
653
648
|
var d, f;
|
|
654
649
|
const {
|
|
655
|
-
event:
|
|
650
|
+
event: r,
|
|
656
651
|
...n
|
|
657
652
|
} = e, {
|
|
658
|
-
template:
|
|
653
|
+
template: i
|
|
659
654
|
} = (t == null ? void 0 : t.llm) || {}, {
|
|
660
|
-
language:
|
|
655
|
+
language: a
|
|
661
656
|
} = ((d = t == null ? void 0 : t.presenter) == null ? void 0 : d.voice) || {}, {
|
|
662
657
|
stitch: o
|
|
663
658
|
} = (t == null ? void 0 : t.presenter) || {};
|
|
@@ -665,80 +660,80 @@ function je(e, t, i) {
|
|
|
665
660
|
...n,
|
|
666
661
|
llm: {
|
|
667
662
|
...n.llm,
|
|
668
|
-
template:
|
|
663
|
+
template: i
|
|
669
664
|
},
|
|
670
665
|
script: {
|
|
671
666
|
...n.script,
|
|
672
667
|
provider: {
|
|
673
668
|
...(f = n == null ? void 0 : n.script) == null ? void 0 : f.provider,
|
|
674
|
-
language:
|
|
669
|
+
language: a
|
|
675
670
|
}
|
|
676
671
|
},
|
|
677
672
|
stitch: o,
|
|
678
|
-
...
|
|
673
|
+
...s
|
|
679
674
|
};
|
|
680
675
|
}
|
|
681
676
|
class xe extends Error {
|
|
682
677
|
constructor({
|
|
683
678
|
kind: t,
|
|
684
|
-
description:
|
|
679
|
+
description: s
|
|
685
680
|
}) {
|
|
686
|
-
const
|
|
681
|
+
const r = JSON.stringify({
|
|
687
682
|
kind: t,
|
|
688
|
-
description:
|
|
683
|
+
description: s
|
|
689
684
|
});
|
|
690
|
-
super(
|
|
685
|
+
super(r);
|
|
691
686
|
}
|
|
692
687
|
}
|
|
693
688
|
let L = 0;
|
|
694
689
|
const Ne = 45 * 1e3;
|
|
695
|
-
function Be(e, t,
|
|
696
|
-
var
|
|
690
|
+
function Be(e, t, s) {
|
|
691
|
+
var r, n, i, a, o;
|
|
697
692
|
return {
|
|
698
693
|
videoType: ue(e.presenter.type),
|
|
699
|
-
output_resolution: (
|
|
694
|
+
output_resolution: (r = t == null ? void 0 : t.streamOptions) == null ? void 0 : r.outputResolution,
|
|
700
695
|
session_timeout: (n = t == null ? void 0 : t.streamOptions) == null ? void 0 : n.sessionTimeout,
|
|
701
|
-
stream_warmup: (
|
|
702
|
-
compatibility_mode: (
|
|
703
|
-
stream_greeting: (o = t == null ? void 0 : t.streamOptions) != null && o.streamGreeting ?
|
|
696
|
+
stream_warmup: (i = t == null ? void 0 : t.streamOptions) == null ? void 0 : i.streamWarmup,
|
|
697
|
+
compatibility_mode: (a = t == null ? void 0 : t.streamOptions) == null ? void 0 : a.compatibilityMode,
|
|
698
|
+
stream_greeting: (o = t == null ? void 0 : t.streamOptions) != null && o.streamGreeting ? s : void 0
|
|
704
699
|
};
|
|
705
700
|
}
|
|
706
701
|
function re(e) {
|
|
707
702
|
return e === I.Playground ? {
|
|
708
703
|
headers: {
|
|
709
|
-
[
|
|
704
|
+
[De]: "true"
|
|
710
705
|
}
|
|
711
706
|
} : {};
|
|
712
707
|
}
|
|
713
|
-
async function ae(e, t,
|
|
708
|
+
async function ae(e, t, s, r, n) {
|
|
714
709
|
try {
|
|
715
|
-
const
|
|
710
|
+
const i = await t.newChat(e, {
|
|
716
711
|
persist: n ?? !1
|
|
717
|
-
}, re(
|
|
718
|
-
return
|
|
712
|
+
}, re(r));
|
|
713
|
+
return s.track("agent-chat", {
|
|
719
714
|
event: "created",
|
|
720
|
-
chat_id:
|
|
715
|
+
chat_id: i.id,
|
|
721
716
|
agent_id: e,
|
|
722
|
-
mode:
|
|
723
|
-
}),
|
|
724
|
-
} catch (
|
|
725
|
-
let
|
|
717
|
+
mode: r
|
|
718
|
+
}), i;
|
|
719
|
+
} catch (i) {
|
|
720
|
+
let a;
|
|
726
721
|
try {
|
|
727
|
-
|
|
722
|
+
a = JSON.parse(i.message);
|
|
728
723
|
} catch (o) {
|
|
729
724
|
console.error("Error parsing the error message:", o);
|
|
730
725
|
}
|
|
731
|
-
throw (
|
|
726
|
+
throw (a == null ? void 0 : a.kind) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
732
727
|
}
|
|
733
728
|
}
|
|
734
|
-
function Fe(e, t,
|
|
735
|
-
return new Promise(async (
|
|
729
|
+
function Fe(e, t, s, r, n, i) {
|
|
730
|
+
return new Promise(async (a, o) => {
|
|
736
731
|
var m, p, k, y, C;
|
|
737
732
|
L = 0;
|
|
738
733
|
const l = String(t.mode);
|
|
739
734
|
if (!n && t.mode !== I.DirectPlayback)
|
|
740
735
|
try {
|
|
741
|
-
n = await ae(e.id,
|
|
736
|
+
n = await ae(e.id, s, r, t.mode, t.persistentChat);
|
|
742
737
|
} catch (g) {
|
|
743
738
|
return o(g);
|
|
744
739
|
}
|
|
@@ -747,44 +742,44 @@ function Fe(e, t, i, a, n, s) {
|
|
|
747
742
|
kind: "ChatModeDowngraded",
|
|
748
743
|
description: `Chat mode changed from ${l} to ${d} when creating the chat`
|
|
749
744
|
}), {}))), d === I.TextOnly)
|
|
750
|
-
return
|
|
745
|
+
return a({
|
|
751
746
|
chat: n
|
|
752
747
|
});
|
|
753
|
-
const f = await Te(e.id, Be(e, t,
|
|
748
|
+
const f = await Te(e.id, Be(e, t, i), {
|
|
754
749
|
...t,
|
|
755
|
-
analytics:
|
|
750
|
+
analytics: r,
|
|
756
751
|
warmup: (C = t.streamOptions) == null ? void 0 : C.streamWarmup,
|
|
757
752
|
callbacks: {
|
|
758
753
|
...t.callbacks,
|
|
759
754
|
onConnectionStateChange: async (g) => {
|
|
760
|
-
var R,
|
|
761
|
-
g === D.Connected ? f ? ((
|
|
755
|
+
var R, S, c, h;
|
|
756
|
+
g === D.Connected ? f ? ((S = (R = t.callbacks).onConnectionStateChange) == null || S.call(R, g), a({
|
|
762
757
|
chat: n,
|
|
763
758
|
streamingManager: f
|
|
764
759
|
})) : n && o(new Error("Something went wrong while initializing the manager")) : (h = (c = t.callbacks).onConnectionStateChange) == null || h.call(c, g);
|
|
765
760
|
},
|
|
766
761
|
onVideoStateChange(g, R) {
|
|
767
|
-
var
|
|
768
|
-
(c = (
|
|
762
|
+
var S, c;
|
|
763
|
+
(c = (S = t.callbacks).onVideoStateChange) == null || c.call(S, g), L > 0 && (g === j.Start ? r.linkTrack("agent-video", {
|
|
769
764
|
event: "start",
|
|
770
765
|
latency: Date.now() - L
|
|
771
|
-
}, "start", [
|
|
766
|
+
}, "start", [K.StreamVideoCreated]) : g === j.Stop && r.linkTrack("agent-video", {
|
|
772
767
|
event: "stop",
|
|
773
768
|
is_greenscreen: e.presenter.type === "clip" && e.presenter.is_greenscreen,
|
|
774
769
|
background: e.presenter.type === "clip" && e.presenter.background,
|
|
775
770
|
...R
|
|
776
|
-
}, "done", [
|
|
771
|
+
}, "done", [K.StreamVideoDone]));
|
|
777
772
|
}
|
|
778
773
|
}
|
|
779
774
|
}).catch(o);
|
|
780
775
|
});
|
|
781
776
|
}
|
|
782
|
-
function
|
|
783
|
-
var
|
|
784
|
-
const t = (
|
|
777
|
+
function He(e) {
|
|
778
|
+
var s;
|
|
779
|
+
const t = (s = e.greetings) == null ? void 0 : s.filter((r) => r.length > 0);
|
|
785
780
|
if (t && t.length > 0) {
|
|
786
|
-
const
|
|
787
|
-
return t[
|
|
781
|
+
const r = Math.floor(Math.random() * t.length);
|
|
782
|
+
return t[r];
|
|
788
783
|
} else
|
|
789
784
|
return `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
|
|
790
785
|
}
|
|
@@ -796,35 +791,35 @@ function Y(e, t) {
|
|
|
796
791
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
797
792
|
}];
|
|
798
793
|
}
|
|
799
|
-
function
|
|
794
|
+
function We(e) {
|
|
800
795
|
if (e.answer !== void 0)
|
|
801
796
|
return e.answer;
|
|
802
|
-
let t = 0,
|
|
797
|
+
let t = 0, s = "";
|
|
803
798
|
for (; t in e; )
|
|
804
|
-
|
|
805
|
-
return
|
|
799
|
+
s += e[t], t++;
|
|
800
|
+
return s;
|
|
806
801
|
}
|
|
807
|
-
function Ke(e, t,
|
|
802
|
+
function Ke(e, t, s, r, n) {
|
|
808
803
|
if (!(e === B.Partial || e === B.Answer))
|
|
809
804
|
return;
|
|
810
|
-
const
|
|
811
|
-
if ((
|
|
805
|
+
const i = r.messages[r.messages.length - 1];
|
|
806
|
+
if ((i == null ? void 0 : i.role) !== "assistant")
|
|
812
807
|
return;
|
|
813
808
|
const {
|
|
814
|
-
content:
|
|
809
|
+
content: a,
|
|
815
810
|
sequence: o
|
|
816
811
|
} = t;
|
|
817
|
-
e === B.Partial ?
|
|
818
|
-
const l =
|
|
819
|
-
(
|
|
812
|
+
e === B.Partial ? s[o] = a : s.answer = a;
|
|
813
|
+
const l = We(s);
|
|
814
|
+
(i.content !== l || e === B.Answer) && (i.content = l, n == null || n([...r.messages], e));
|
|
820
815
|
}
|
|
821
816
|
async function Ve(e, t) {
|
|
822
|
-
var g, R,
|
|
823
|
-
let
|
|
817
|
+
var g, R, S;
|
|
818
|
+
let s = {}, r = !0;
|
|
824
819
|
const n = {
|
|
825
820
|
messages: [],
|
|
826
821
|
chatMode: t.mode || I.Functional
|
|
827
|
-
},
|
|
822
|
+
}, i = t.baseURL || H, a = t.wsURL || he, o = t.mixpanelKey || we, l = te(t.auth, i, t.callbacks.onError), d = await l.getById(e), f = He(d);
|
|
828
823
|
n.messages = Y(f, t.initialMessages), (R = (g = t.callbacks).onNewMessage) == null || R.call(g, [...n.messages], "answer");
|
|
829
824
|
const m = ze({
|
|
830
825
|
token: o,
|
|
@@ -840,19 +835,19 @@ async function Ve(e, t) {
|
|
|
840
835
|
onMessage: (c, h) => {
|
|
841
836
|
var v, _;
|
|
842
837
|
if ("content" in h)
|
|
843
|
-
Ke(c, h,
|
|
838
|
+
Ke(c, h, s, n, t.callbacks.onNewMessage), c === B.Answer && m.track("agent-message-received", {
|
|
844
839
|
messages: n.messages.length,
|
|
845
840
|
mode: n.chatMode
|
|
846
841
|
});
|
|
847
842
|
else {
|
|
848
|
-
const u =
|
|
843
|
+
const u = K, w = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], M = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], b = je(h, d, {
|
|
849
844
|
mode: n.chatMode
|
|
850
845
|
});
|
|
851
846
|
if (c = c, c === u.StreamVideoCreated)
|
|
852
847
|
m.linkTrack("agent-video", b, u.StreamVideoCreated, ["start"]);
|
|
853
848
|
else if (w.includes(c)) {
|
|
854
849
|
const E = c.split("/")[1];
|
|
855
|
-
|
|
850
|
+
M.includes(c) ? m.track("agent-video", {
|
|
856
851
|
...b,
|
|
857
852
|
event: E
|
|
858
853
|
}) : m.linkTrack("agent-video", {
|
|
@@ -860,16 +855,16 @@ async function Ve(e, t) {
|
|
|
860
855
|
event: E
|
|
861
856
|
}, c, ["done"]);
|
|
862
857
|
}
|
|
863
|
-
|
|
858
|
+
M.includes(c) && ((_ = (v = t.callbacks).onError) == null || _.call(v, new Error(`Stream failed with event ${c}`), {
|
|
864
859
|
data: h
|
|
865
860
|
})), h.event === u.StreamDone && y();
|
|
866
861
|
}
|
|
867
862
|
}
|
|
868
863
|
};
|
|
869
864
|
async function k(c) {
|
|
870
|
-
var
|
|
871
|
-
(b = (
|
|
872
|
-
const h = t.mode === I.DirectPlayback ? Promise.resolve(void 0) : Re(t.auth,
|
|
865
|
+
var M, b, E, A, F, T, P;
|
|
866
|
+
(b = (M = t.callbacks).onConnectionStateChange) == null || b.call(M, D.Connecting), L = 0, c && !r && (delete n.chat, n.messages = Y(f), (A = (E = t.callbacks).onNewMessage) == null || A.call(E, [...n.messages], "answer"));
|
|
867
|
+
const h = t.mode === I.DirectPlayback ? Promise.resolve(void 0) : Re(t.auth, a, p), v = Q(() => Fe(d, t, l, m, n.chat, c ? f : void 0), {
|
|
873
868
|
limit: 3,
|
|
874
869
|
timeout: Ne,
|
|
875
870
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
@@ -883,7 +878,7 @@ async function Ve(e, t) {
|
|
|
883
878
|
streamingManager: u,
|
|
884
879
|
chat: w
|
|
885
880
|
}] = await Promise.all([h, v]);
|
|
886
|
-
w && w.id !== ((F = n.chat) == null ? void 0 : F.id) && ((P = (T = t.callbacks).onNewChat) == null || P.call(T, w.id)), n.streamingManager = u, n.socketManager = _, n.chat = w,
|
|
881
|
+
w && w.id !== ((F = n.chat) == null ? void 0 : F.id) && ((P = (T = t.callbacks).onNewChat) == null || P.call(T, w.id)), n.streamingManager = u, n.socketManager = _, n.chat = w, r = !1, C((w == null ? void 0 : w.chat_mode) ?? t.mode ?? I.Functional);
|
|
887
882
|
}
|
|
888
883
|
async function y() {
|
|
889
884
|
var c, h, v, _;
|
|
@@ -897,7 +892,7 @@ async function Ve(e, t) {
|
|
|
897
892
|
}
|
|
898
893
|
return {
|
|
899
894
|
agent: d,
|
|
900
|
-
starterMessages: ((
|
|
895
|
+
starterMessages: ((S = d.knowledge) == null ? void 0 : S.starter_message) || [],
|
|
901
896
|
getSTTToken: () => l.getSTTToken(d.id),
|
|
902
897
|
changeMode: C,
|
|
903
898
|
enrichAnalytics: m.enrich,
|
|
@@ -929,9 +924,9 @@ async function Ve(e, t) {
|
|
|
929
924
|
});
|
|
930
925
|
},
|
|
931
926
|
async chat(c) {
|
|
932
|
-
var v, _, u, w,
|
|
927
|
+
var v, _, u, w, M, b;
|
|
933
928
|
const h = V();
|
|
934
|
-
|
|
929
|
+
s = {};
|
|
935
930
|
try {
|
|
936
931
|
if (L = Date.now(), t.mode === I.DirectPlayback)
|
|
937
932
|
throw new Error("Direct playback is enabled, chat is disabled");
|
|
@@ -969,16 +964,16 @@ async function Ve(e, t) {
|
|
|
969
964
|
chatMode: n.chatMode,
|
|
970
965
|
messages: A.map(({
|
|
971
966
|
matches: N,
|
|
972
|
-
...
|
|
973
|
-
}) =>
|
|
967
|
+
...W
|
|
968
|
+
}) => W)
|
|
974
969
|
}, {
|
|
975
970
|
...re(n.chatMode),
|
|
976
971
|
skipErrorHandler: !0
|
|
977
972
|
});
|
|
978
973
|
}, T = await F(n.chat.id).catch(async (P) => {
|
|
979
|
-
var N,
|
|
974
|
+
var N, W, J, O;
|
|
980
975
|
const $ = (N = P == null ? void 0 : P.message) == null ? void 0 : N.includes("missing or invalid session_id");
|
|
981
|
-
if (!((
|
|
976
|
+
if (!((W = P == null ? void 0 : P.message) == null ? void 0 : W.includes("Stream Error")) && !$)
|
|
982
977
|
throw (O = (J = t.callbacks).onError) == null || O.call(J, P, {}), P;
|
|
983
978
|
return await y(), await k(!1), F(n.chat.id);
|
|
984
979
|
});
|
|
@@ -990,7 +985,7 @@ async function Ve(e, t) {
|
|
|
990
985
|
latency: Date.now() - L,
|
|
991
986
|
mode: n.chatMode,
|
|
992
987
|
messages: n.messages.length
|
|
993
|
-
}), (b = (
|
|
988
|
+
}), (b = (M = t.callbacks).onNewMessage) == null || b.call(M, [...n.messages], "answer")), T;
|
|
994
989
|
} catch (E) {
|
|
995
990
|
throw n.messages[n.messages.length - 1].id === h && n.messages.pop(), m.track("agent-message-send", {
|
|
996
991
|
event: "error",
|
|
@@ -1000,7 +995,7 @@ async function Ve(e, t) {
|
|
|
1000
995
|
}
|
|
1001
996
|
},
|
|
1002
997
|
rate(c, h, v) {
|
|
1003
|
-
var w,
|
|
998
|
+
var w, M, b, E;
|
|
1004
999
|
const _ = n.messages.find((A) => A.id === c);
|
|
1005
1000
|
if (n.chat) {
|
|
1006
1001
|
if (!_)
|
|
@@ -1011,7 +1006,7 @@ async function Ve(e, t) {
|
|
|
1011
1006
|
return m.track("agent-rate", {
|
|
1012
1007
|
event: v ? "update" : "create",
|
|
1013
1008
|
thumb: h === 1 ? "up" : "down",
|
|
1014
|
-
knowledge_id: ((
|
|
1009
|
+
knowledge_id: ((M = d.knowledge) == null ? void 0 : M.id) ?? "",
|
|
1015
1010
|
mode: n.chatMode,
|
|
1016
1011
|
matches: u,
|
|
1017
1012
|
score: h
|
|
@@ -1072,11 +1067,11 @@ async function Ve(e, t) {
|
|
|
1072
1067
|
}
|
|
1073
1068
|
};
|
|
1074
1069
|
}
|
|
1075
|
-
function Ue(e, t,
|
|
1070
|
+
function Ue(e, t, s) {
|
|
1076
1071
|
const {
|
|
1077
|
-
getById:
|
|
1078
|
-
} = te(t,
|
|
1079
|
-
return
|
|
1072
|
+
getById: r
|
|
1073
|
+
} = te(t, s || H);
|
|
1074
|
+
return r(e);
|
|
1080
1075
|
}
|
|
1081
1076
|
export {
|
|
1082
1077
|
oe as AgentStatus,
|
|
@@ -1088,7 +1083,7 @@ export {
|
|
|
1088
1083
|
se as PlanGroup,
|
|
1089
1084
|
fe as Providers,
|
|
1090
1085
|
ce as RateState,
|
|
1091
|
-
|
|
1086
|
+
K as StreamEvents,
|
|
1092
1087
|
j as StreamingState,
|
|
1093
1088
|
de as Subject,
|
|
1094
1089
|
ie as UserPlan,
|