@d-id/client-sdk 1.1.0-beta.25 → 1.1.0-beta.27
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,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var Y = (e, t, a) => (
|
|
1
|
+
var ye = Object.defineProperty;
|
|
2
|
+
var ve = (e, t, a) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var Y = (e, t, a) => (ve(e, typeof t != "symbol" ? t + "" : t, a), a);
|
|
4
4
|
class Z extends Error {
|
|
5
5
|
constructor({
|
|
6
6
|
kind: a,
|
|
7
|
-
description:
|
|
8
|
-
error:
|
|
7
|
+
description: r,
|
|
8
|
+
error: o
|
|
9
9
|
}) {
|
|
10
10
|
super(JSON.stringify({
|
|
11
11
|
kind: a,
|
|
12
|
-
description:
|
|
12
|
+
description: r
|
|
13
13
|
}));
|
|
14
14
|
Y(this, "kind");
|
|
15
15
|
Y(this, "description");
|
|
16
16
|
Y(this, "error");
|
|
17
|
-
this.kind = a, this.description =
|
|
17
|
+
this.kind = a, this.description = r, this.error = o;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
class
|
|
20
|
+
class ke extends Z {
|
|
21
21
|
constructor(t, a) {
|
|
22
22
|
super({
|
|
23
23
|
kind: "ChatCreationFailed",
|
|
@@ -25,7 +25,7 @@ class De extends Z {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
class
|
|
28
|
+
class De extends Z {
|
|
29
29
|
constructor(t) {
|
|
30
30
|
super({
|
|
31
31
|
kind: "ChatModeDowngraded",
|
|
@@ -34,16 +34,16 @@ class Ce extends Z {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
class H extends Z {
|
|
37
|
-
constructor(a,
|
|
37
|
+
constructor(a, r) {
|
|
38
38
|
super({
|
|
39
39
|
kind: "ValidationError",
|
|
40
40
|
description: a
|
|
41
41
|
});
|
|
42
42
|
Y(this, "key");
|
|
43
|
-
this.key =
|
|
43
|
+
this.key = r;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
class
|
|
46
|
+
class Ce extends Z {
|
|
47
47
|
constructor(t) {
|
|
48
48
|
super({
|
|
49
49
|
kind: "WSError",
|
|
@@ -51,8 +51,8 @@ class Re extends Z {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
var
|
|
55
|
-
const
|
|
54
|
+
var Re = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Re || {}), Se = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Se || {}), _e = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(_e || {}), Ee = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ee || {}), j = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(j || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Ie = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ie || {}), Me = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Me || {}), Te = /* @__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))(Te || {}), oe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(oe || {});
|
|
55
|
+
const je = (e) => {
|
|
56
56
|
switch (e) {
|
|
57
57
|
case "clip":
|
|
58
58
|
return "clip";
|
|
@@ -62,21 +62,21 @@ const be = (e) => {
|
|
|
62
62
|
throw new Error(`Unknown video type: ${e}`);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), Q = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Q || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}),
|
|
66
|
-
const
|
|
65
|
+
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), Q = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Q || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), B = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(B || {}), E = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(E || {}), U = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(U || {}), be = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(be || {}), Ae = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ae || {});
|
|
66
|
+
const Pe = 45 * 1e3, $e = "X-Playground-Chat", O = "https://api.d-id.com", Be = "wss://notifications.d-id.com", Le = "79f81a83a67430be2bc0fd61042b8faa", ce = (e) => new Promise((t) => setTimeout(t, e)), V = (e = 16) => {
|
|
67
67
|
const t = new Uint8Array(e);
|
|
68
68
|
return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
69
|
-
},
|
|
70
|
-
function
|
|
69
|
+
}, ze = (e) => [j.TextOnly, j.Playground, j.Maintenance].includes(e), de = (e) => e && [j.DirectPlayback, j.Off].includes(e);
|
|
70
|
+
function Ne(e, t) {
|
|
71
71
|
let a;
|
|
72
72
|
return {
|
|
73
|
-
promise: new Promise((
|
|
73
|
+
promise: new Promise((o, i) => {
|
|
74
74
|
a = setTimeout(() => i(new Error(t)), e);
|
|
75
75
|
}),
|
|
76
76
|
clear: () => clearTimeout(a)
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
async function
|
|
79
|
+
async function ee(e, t) {
|
|
80
80
|
const a = {
|
|
81
81
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
82
82
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -86,22 +86,22 @@ async function re(e, t) {
|
|
|
86
86
|
onRetry: (t == null ? void 0 : t.onRetry) ?? (() => {
|
|
87
87
|
})
|
|
88
88
|
};
|
|
89
|
-
let
|
|
90
|
-
for (let
|
|
89
|
+
let r;
|
|
90
|
+
for (let o = 1; o <= a.limit; o++)
|
|
91
91
|
try {
|
|
92
92
|
if (!a.timeout)
|
|
93
93
|
return await e();
|
|
94
94
|
const {
|
|
95
95
|
promise: i,
|
|
96
|
-
clear:
|
|
97
|
-
} =
|
|
98
|
-
return await Promise.race([
|
|
96
|
+
clear: c
|
|
97
|
+
} = Ne(a.timeout, a.timeoutErrorMessage), n = e().finally(c);
|
|
98
|
+
return await Promise.race([n, i]);
|
|
99
99
|
} catch (i) {
|
|
100
|
-
if (
|
|
100
|
+
if (r = i, !a.shouldRetryFn(i) || o >= a.limit)
|
|
101
101
|
throw i;
|
|
102
|
-
await
|
|
102
|
+
await ce(a.delayMs), a.onRetry(i);
|
|
103
103
|
}
|
|
104
|
-
throw
|
|
104
|
+
throw r;
|
|
105
105
|
}
|
|
106
106
|
function ue() {
|
|
107
107
|
let e = window.localStorage.getItem("did_external_key_id");
|
|
@@ -111,212 +111,212 @@ function ue() {
|
|
|
111
111
|
}
|
|
112
112
|
return e;
|
|
113
113
|
}
|
|
114
|
-
let
|
|
115
|
-
function
|
|
114
|
+
let xe = V();
|
|
115
|
+
function le(e) {
|
|
116
116
|
if (e.type === "bearer")
|
|
117
117
|
return `Bearer ${e.token}`;
|
|
118
118
|
if (e.type === "basic")
|
|
119
119
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
120
120
|
if (e.type === "key")
|
|
121
|
-
return `Client-Key ${e.clientKey}.${ue()}_${
|
|
121
|
+
return `Client-Key ${e.clientKey}.${ue()}_${xe}`;
|
|
122
122
|
throw new Error(`Unknown auth type: ${e}`);
|
|
123
123
|
}
|
|
124
|
-
const
|
|
124
|
+
const Fe = (e) => ee(e, {
|
|
125
125
|
limit: 3,
|
|
126
126
|
delayMs: 1e3,
|
|
127
127
|
timeout: 0,
|
|
128
128
|
shouldRetryFn: (t) => t.status === 429
|
|
129
129
|
});
|
|
130
|
-
function
|
|
131
|
-
const
|
|
130
|
+
function ne(e, t = O, a) {
|
|
131
|
+
const r = async (o, i) => {
|
|
132
132
|
const {
|
|
133
|
-
skipErrorHandler:
|
|
134
|
-
...
|
|
135
|
-
} = i || {},
|
|
136
|
-
...
|
|
133
|
+
skipErrorHandler: c,
|
|
134
|
+
...n
|
|
135
|
+
} = i || {}, s = await Fe(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
136
|
+
...n,
|
|
137
137
|
headers: {
|
|
138
|
-
...
|
|
139
|
-
Authorization:
|
|
138
|
+
...n.headers,
|
|
139
|
+
Authorization: le(e),
|
|
140
140
|
"Content-Type": "application/json"
|
|
141
141
|
}
|
|
142
142
|
}));
|
|
143
|
-
if (!
|
|
144
|
-
let
|
|
145
|
-
const
|
|
146
|
-
throw a && !
|
|
147
|
-
url:
|
|
148
|
-
options:
|
|
149
|
-
headers:
|
|
150
|
-
}),
|
|
143
|
+
if (!s.ok) {
|
|
144
|
+
let d = await s.text().catch(() => `Failed to fetch with status ${s.status}`);
|
|
145
|
+
const l = new Error(d);
|
|
146
|
+
throw a && !c && a(l, {
|
|
147
|
+
url: o,
|
|
148
|
+
options: n,
|
|
149
|
+
headers: s.headers
|
|
150
|
+
}), l;
|
|
151
151
|
}
|
|
152
|
-
return
|
|
152
|
+
return s.json();
|
|
153
153
|
};
|
|
154
154
|
return {
|
|
155
|
-
get(
|
|
156
|
-
return
|
|
155
|
+
get(o, i) {
|
|
156
|
+
return r(o, {
|
|
157
157
|
...i,
|
|
158
158
|
method: "GET"
|
|
159
159
|
});
|
|
160
160
|
},
|
|
161
|
-
post(
|
|
162
|
-
return
|
|
163
|
-
...
|
|
161
|
+
post(o, i, c) {
|
|
162
|
+
return r(o, {
|
|
163
|
+
...c,
|
|
164
164
|
body: JSON.stringify(i),
|
|
165
165
|
method: "POST"
|
|
166
166
|
});
|
|
167
167
|
},
|
|
168
|
-
delete(
|
|
169
|
-
return
|
|
170
|
-
...
|
|
168
|
+
delete(o, i, c) {
|
|
169
|
+
return r(o, {
|
|
170
|
+
...c,
|
|
171
171
|
body: JSON.stringify(i),
|
|
172
172
|
method: "DELETE"
|
|
173
173
|
});
|
|
174
174
|
},
|
|
175
|
-
patch(
|
|
176
|
-
return
|
|
177
|
-
...
|
|
175
|
+
patch(o, i, c) {
|
|
176
|
+
return r(o, {
|
|
177
|
+
...c,
|
|
178
178
|
body: JSON.stringify(i),
|
|
179
179
|
method: "PATCH"
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
function
|
|
185
|
-
const
|
|
184
|
+
function fe(e, t = O, a) {
|
|
185
|
+
const r = ne(e, `${t}/agents`, a);
|
|
186
186
|
return {
|
|
187
|
-
create(
|
|
188
|
-
return
|
|
187
|
+
create(o, i) {
|
|
188
|
+
return r.post("/", o, i);
|
|
189
189
|
},
|
|
190
|
-
getAgents(
|
|
191
|
-
return
|
|
190
|
+
getAgents(o, i) {
|
|
191
|
+
return r.get(`/${o ? `?tag=${o}` : ""}`, i).then((c) => c ?? []);
|
|
192
192
|
},
|
|
193
|
-
getById(
|
|
194
|
-
return
|
|
193
|
+
getById(o, i) {
|
|
194
|
+
return r.get(`/${o}`, i);
|
|
195
195
|
},
|
|
196
|
-
delete(
|
|
197
|
-
return
|
|
196
|
+
delete(o, i) {
|
|
197
|
+
return r.delete(`/${o}`, void 0, i);
|
|
198
198
|
},
|
|
199
|
-
update(
|
|
200
|
-
return
|
|
199
|
+
update(o, i, c) {
|
|
200
|
+
return r.patch(`/${o}`, i, c);
|
|
201
201
|
},
|
|
202
|
-
newChat(
|
|
203
|
-
return
|
|
202
|
+
newChat(o, i, c) {
|
|
203
|
+
return r.post(`/${o}/chat`, i, c);
|
|
204
204
|
},
|
|
205
|
-
chat(
|
|
206
|
-
return
|
|
205
|
+
chat(o, i, c, n) {
|
|
206
|
+
return r.post(`/${o}/chat/${i}`, c, n);
|
|
207
207
|
},
|
|
208
|
-
createRating(
|
|
209
|
-
return
|
|
208
|
+
createRating(o, i, c, n) {
|
|
209
|
+
return r.post(`/${o}/chat/${i}/ratings`, c, n);
|
|
210
210
|
},
|
|
211
|
-
updateRating(
|
|
212
|
-
return
|
|
211
|
+
updateRating(o, i, c, n, s) {
|
|
212
|
+
return r.patch(`/${o}/chat/${i}/ratings/${c}`, n, s);
|
|
213
213
|
},
|
|
214
|
-
deleteRating(
|
|
215
|
-
return
|
|
214
|
+
deleteRating(o, i, c, n) {
|
|
215
|
+
return r.delete(`/${o}/chat/${i}/ratings/${c}`, n);
|
|
216
216
|
},
|
|
217
|
-
getSTTToken(
|
|
218
|
-
return
|
|
217
|
+
getSTTToken(o, i) {
|
|
218
|
+
return r.get(`/${o}/stt-token`, i);
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
-
const
|
|
223
|
-
function
|
|
224
|
-
var
|
|
222
|
+
const me = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
223
|
+
function Je(e) {
|
|
224
|
+
var o, i, c, n;
|
|
225
225
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
|
|
226
|
-
const
|
|
227
|
-
return
|
|
228
|
-
},
|
|
226
|
+
const s = navigator.platform;
|
|
227
|
+
return s.toLowerCase().includes("win") ? "Windows" : s.toLowerCase().includes("mac") ? "Mac OS X" : s.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
228
|
+
}, r = e.presenter;
|
|
229
229
|
return {
|
|
230
230
|
$os: `${a()}`,
|
|
231
231
|
isMobile: `${t() == "Mobile"}`,
|
|
232
232
|
browser: navigator.userAgent,
|
|
233
233
|
origin: window.location.origin,
|
|
234
|
-
agentType:
|
|
234
|
+
agentType: me(r),
|
|
235
235
|
agentVoice: {
|
|
236
|
-
voiceId: (i = (
|
|
237
|
-
provider: (
|
|
236
|
+
voiceId: (i = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : i.voice_id,
|
|
237
|
+
provider: (n = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : n.type
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
|
-
const
|
|
242
|
-
function
|
|
243
|
-
var
|
|
241
|
+
const We = (e) => e.reduce((t, a) => t + a, 0), ae = (e) => We(e) / e.length;
|
|
242
|
+
function Ue(e, t, a) {
|
|
243
|
+
var s, d, l;
|
|
244
244
|
const {
|
|
245
|
-
event:
|
|
246
|
-
...
|
|
245
|
+
event: r,
|
|
246
|
+
...o
|
|
247
247
|
} = e, {
|
|
248
248
|
template: i
|
|
249
249
|
} = (t == null ? void 0 : t.llm) || {}, {
|
|
250
|
-
language:
|
|
251
|
-
} = ((
|
|
250
|
+
language: c
|
|
251
|
+
} = ((s = t == null ? void 0 : t.presenter) == null ? void 0 : s.voice) || {};
|
|
252
252
|
return {
|
|
253
|
-
...
|
|
253
|
+
...o,
|
|
254
254
|
llm: {
|
|
255
|
-
...
|
|
255
|
+
...o.llm,
|
|
256
256
|
template: i
|
|
257
257
|
},
|
|
258
258
|
script: {
|
|
259
|
-
...
|
|
259
|
+
...o.script,
|
|
260
260
|
provider: {
|
|
261
|
-
...(
|
|
262
|
-
language:
|
|
261
|
+
...(d = o == null ? void 0 : o.script) == null ? void 0 : d.provider,
|
|
262
|
+
language: c
|
|
263
263
|
}
|
|
264
264
|
},
|
|
265
|
-
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (
|
|
265
|
+
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (l = t == null ? void 0 : t.presenter) == null ? void 0 : l.stitch : void 0,
|
|
266
266
|
...a
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
let G = {};
|
|
270
|
-
const
|
|
271
|
-
function
|
|
272
|
-
var i,
|
|
273
|
-
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter,
|
|
270
|
+
const Ke = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
271
|
+
function He(e) {
|
|
272
|
+
var i, c, n, s, d, l;
|
|
273
|
+
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter, r = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, o = {
|
|
274
274
|
token: e.token || "testKey",
|
|
275
275
|
distinct_id: e.distinctId || ue(),
|
|
276
276
|
agentId: e.agent.id,
|
|
277
|
-
agentType:
|
|
277
|
+
agentType: me(a),
|
|
278
278
|
owner_id: e.agent.owner_id ?? "",
|
|
279
|
-
promptVersion: (
|
|
279
|
+
promptVersion: (c = e.agent.llm) == null ? void 0 : c.prompt_version,
|
|
280
280
|
behavior: {
|
|
281
|
-
role:
|
|
282
|
-
personality:
|
|
283
|
-
instructions: (
|
|
281
|
+
role: r == null ? void 0 : r.role,
|
|
282
|
+
personality: r == null ? void 0 : r.personality,
|
|
283
|
+
instructions: (n = e.agent.llm) == null ? void 0 : n.instructions
|
|
284
284
|
},
|
|
285
|
-
temperature: (
|
|
286
|
-
knowledgeSource:
|
|
287
|
-
starterQuestionsCount: (
|
|
288
|
-
topicsToAvoid:
|
|
289
|
-
maxResponseLength:
|
|
285
|
+
temperature: (s = e.agent.llm) == null ? void 0 : s.temperature,
|
|
286
|
+
knowledgeSource: r == null ? void 0 : r.knowledge_source,
|
|
287
|
+
starterQuestionsCount: (l = (d = e.agent.knowledge) == null ? void 0 : d.starter_message) == null ? void 0 : l.length,
|
|
288
|
+
topicsToAvoid: r == null ? void 0 : r.topics_to_avoid,
|
|
289
|
+
maxResponseLength: r == null ? void 0 : r.max_response_length
|
|
290
290
|
};
|
|
291
291
|
return {
|
|
292
|
-
...
|
|
292
|
+
...o,
|
|
293
293
|
additionalProperties: {},
|
|
294
294
|
isEnabled: e.isEnabled ?? !0,
|
|
295
295
|
getRandom: V,
|
|
296
|
-
enrich(
|
|
296
|
+
enrich(g) {
|
|
297
297
|
this.additionalProperties = {
|
|
298
298
|
...this.additionalProperties,
|
|
299
|
-
...
|
|
299
|
+
...g
|
|
300
300
|
};
|
|
301
301
|
},
|
|
302
|
-
async track(
|
|
302
|
+
async track(g, P) {
|
|
303
303
|
if (!this.isEnabled)
|
|
304
304
|
return Promise.resolve();
|
|
305
305
|
const {
|
|
306
306
|
audioPath: I,
|
|
307
|
-
...
|
|
308
|
-
} =
|
|
307
|
+
...C
|
|
308
|
+
} = P || {}, y = {
|
|
309
309
|
method: "POST",
|
|
310
310
|
headers: {
|
|
311
311
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
312
312
|
},
|
|
313
313
|
body: new URLSearchParams({
|
|
314
314
|
data: JSON.stringify([{
|
|
315
|
-
event:
|
|
315
|
+
event: g,
|
|
316
316
|
properties: {
|
|
317
317
|
...this.additionalProperties,
|
|
318
|
-
...
|
|
319
|
-
...
|
|
318
|
+
...C,
|
|
319
|
+
...o,
|
|
320
320
|
source: t,
|
|
321
321
|
time: Date.now(),
|
|
322
322
|
$insert_id: this.getRandom(),
|
|
@@ -329,32 +329,32 @@ function qe(e) {
|
|
|
329
329
|
})
|
|
330
330
|
};
|
|
331
331
|
try {
|
|
332
|
-
return await fetch(
|
|
332
|
+
return await fetch(Ke, y).then((v) => v.json());
|
|
333
333
|
} catch (v) {
|
|
334
334
|
return console.error(v);
|
|
335
335
|
}
|
|
336
336
|
},
|
|
337
|
-
linkTrack(
|
|
338
|
-
G[
|
|
337
|
+
linkTrack(g, P, I, C) {
|
|
338
|
+
G[g] || (G[g] = {
|
|
339
339
|
events: {},
|
|
340
340
|
resolvedDependencies: []
|
|
341
|
-
}),
|
|
342
|
-
const
|
|
343
|
-
if (
|
|
344
|
-
props:
|
|
345
|
-
},
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
...
|
|
349
|
-
} :
|
|
350
|
-
this.track(
|
|
351
|
-
delete
|
|
341
|
+
}), C.includes(I) || C.push(I);
|
|
342
|
+
const y = G[g];
|
|
343
|
+
if (y.events[I] = {
|
|
344
|
+
props: P
|
|
345
|
+
}, y.resolvedDependencies.push(I), C.every((z) => y.resolvedDependencies.includes(z))) {
|
|
346
|
+
const z = C.reduce(($, M) => y.events[M] ? {
|
|
347
|
+
...$,
|
|
348
|
+
...y.events[M].props
|
|
349
|
+
} : $, {});
|
|
350
|
+
this.track(g, z), y.resolvedDependencies = y.resolvedDependencies.filter(($) => !C.includes($)), C.forEach(($) => {
|
|
351
|
+
delete y.events[$];
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
|
-
function
|
|
357
|
+
function ge() {
|
|
358
358
|
let e = 0;
|
|
359
359
|
return {
|
|
360
360
|
reset: () => e = 0,
|
|
@@ -362,54 +362,54 @@ function he() {
|
|
|
362
362
|
get: (t = !1) => t ? Date.now() - e : e
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
-
const
|
|
366
|
-
function
|
|
367
|
-
return e ===
|
|
365
|
+
const J = ge(), te = ge();
|
|
366
|
+
function he(e) {
|
|
367
|
+
return e === j.Playground ? {
|
|
368
368
|
headers: {
|
|
369
|
-
[
|
|
369
|
+
[$e]: "true"
|
|
370
370
|
}
|
|
371
371
|
} : {};
|
|
372
372
|
}
|
|
373
|
-
async function
|
|
373
|
+
async function we(e, t, a, r, o = !1, i) {
|
|
374
374
|
try {
|
|
375
|
-
return !i && !
|
|
376
|
-
persist:
|
|
377
|
-
},
|
|
375
|
+
return !i && !de(r) && (i = await t.newChat(e.id, {
|
|
376
|
+
persist: o
|
|
377
|
+
}, he(r)), a.track("agent-chat", {
|
|
378
378
|
event: "created",
|
|
379
379
|
chat_id: i.id,
|
|
380
380
|
agent_id: e.id,
|
|
381
|
-
mode:
|
|
381
|
+
mode: r
|
|
382
382
|
})), {
|
|
383
383
|
chat: i,
|
|
384
|
-
chatMode: (i == null ? void 0 : i.chat_mode) ??
|
|
384
|
+
chatMode: (i == null ? void 0 : i.chat_mode) ?? r
|
|
385
385
|
};
|
|
386
|
-
} catch (
|
|
386
|
+
} catch (c) {
|
|
387
387
|
try {
|
|
388
|
-
const
|
|
389
|
-
if ((
|
|
388
|
+
const n = JSON.parse(c.message);
|
|
389
|
+
if ((n == null ? void 0 : n.kind) === "InsufficientCreditsError")
|
|
390
390
|
throw new Error("InsufficientCreditsError");
|
|
391
|
-
} catch (
|
|
392
|
-
console.error("Error parsing the error message:",
|
|
391
|
+
} catch (n) {
|
|
392
|
+
console.error("Error parsing the error message:", n);
|
|
393
393
|
}
|
|
394
394
|
throw new Error("Cannot create new chat");
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
|
-
function
|
|
397
|
+
function qe(e) {
|
|
398
398
|
return e && e.length > 0 ? e : [];
|
|
399
399
|
}
|
|
400
|
-
function
|
|
400
|
+
function Ve(e, t, a) {
|
|
401
401
|
if (!e)
|
|
402
402
|
throw new Error("Please connect to the agent first");
|
|
403
403
|
if (!e.interruptAvailable)
|
|
404
404
|
throw new Error("Interrupt is not enabled for this stream");
|
|
405
405
|
if (t !== U.Fluent)
|
|
406
406
|
throw new Error("Interrupt only available for Fluent streams");
|
|
407
|
-
if (!a
|
|
407
|
+
if (!a)
|
|
408
408
|
throw new Error("No active video to interrupt");
|
|
409
409
|
}
|
|
410
|
-
async function
|
|
410
|
+
async function Xe(e, t) {
|
|
411
411
|
const a = {
|
|
412
|
-
type:
|
|
412
|
+
type: B.StreamInterrupt,
|
|
413
413
|
videoId: t,
|
|
414
414
|
timestamp: Date.now()
|
|
415
415
|
};
|
|
@@ -418,19 +418,19 @@ async function ee(e, t) {
|
|
|
418
418
|
function Ye(e) {
|
|
419
419
|
return new Promise((t, a) => {
|
|
420
420
|
const {
|
|
421
|
-
callbacks:
|
|
422
|
-
host:
|
|
421
|
+
callbacks: r,
|
|
422
|
+
host: o,
|
|
423
423
|
auth: i
|
|
424
424
|
} = e, {
|
|
425
|
-
onMessage:
|
|
426
|
-
onOpen:
|
|
427
|
-
onClose:
|
|
428
|
-
onError:
|
|
429
|
-
} =
|
|
430
|
-
|
|
431
|
-
console.error(
|
|
432
|
-
},
|
|
433
|
-
|
|
425
|
+
onMessage: c = null,
|
|
426
|
+
onOpen: n = null,
|
|
427
|
+
onClose: s = null,
|
|
428
|
+
onError: d = null
|
|
429
|
+
} = r || {}, l = new WebSocket(`${o}?authorization=${le(i)}`);
|
|
430
|
+
l.onmessage = c, l.onclose = s, l.onerror = (g) => {
|
|
431
|
+
console.error(g), d == null || d("Websocket failed to connect", g), a(g);
|
|
432
|
+
}, l.onopen = (g) => {
|
|
433
|
+
n == null || n(g), t(l);
|
|
434
434
|
};
|
|
435
435
|
});
|
|
436
436
|
}
|
|
@@ -439,35 +439,35 @@ async function Qe(e) {
|
|
|
439
439
|
retries: t = 1
|
|
440
440
|
} = e;
|
|
441
441
|
let a = null;
|
|
442
|
-
for (let
|
|
442
|
+
for (let r = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; r++)
|
|
443
443
|
try {
|
|
444
444
|
a = await Ye(e);
|
|
445
|
-
} catch (
|
|
446
|
-
if (
|
|
447
|
-
throw
|
|
448
|
-
await
|
|
445
|
+
} catch (o) {
|
|
446
|
+
if (r === t)
|
|
447
|
+
throw o;
|
|
448
|
+
await ce(r * 500);
|
|
449
449
|
}
|
|
450
450
|
return a;
|
|
451
451
|
}
|
|
452
452
|
async function Oe(e, t, a) {
|
|
453
|
-
const
|
|
453
|
+
const r = a != null && a.onMessage ? [a.onMessage] : [], o = await Qe({
|
|
454
454
|
auth: e,
|
|
455
455
|
host: t,
|
|
456
456
|
callbacks: {
|
|
457
457
|
onError: (i) => {
|
|
458
|
-
var
|
|
459
|
-
return (
|
|
458
|
+
var c;
|
|
459
|
+
return (c = a.onError) == null ? void 0 : c.call(a, new Ce(i));
|
|
460
460
|
},
|
|
461
461
|
onMessage(i) {
|
|
462
|
-
const
|
|
463
|
-
|
|
462
|
+
const c = JSON.parse(i.data);
|
|
463
|
+
r.forEach((n) => n(c.event, c));
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
});
|
|
467
467
|
return {
|
|
468
|
-
socket:
|
|
469
|
-
disconnect: () =>
|
|
470
|
-
subscribeToEvents: (i) =>
|
|
468
|
+
socket: o,
|
|
469
|
+
disconnect: () => o.close(),
|
|
470
|
+
subscribeToEvents: (i) => r.push(i)
|
|
471
471
|
};
|
|
472
472
|
}
|
|
473
473
|
function Ze(e) {
|
|
@@ -478,57 +478,58 @@ function Ze(e) {
|
|
|
478
478
|
a += e[t++];
|
|
479
479
|
return a;
|
|
480
480
|
}
|
|
481
|
-
function Ge(e, t, a,
|
|
482
|
-
const i =
|
|
481
|
+
function Ge(e, t, a, r, o) {
|
|
482
|
+
const i = r.messages[r.messages.length - 1];
|
|
483
483
|
if (!(e === q.Partial || e === q.Answer) || (i == null ? void 0 : i.role) !== "assistant")
|
|
484
484
|
return;
|
|
485
485
|
const {
|
|
486
|
-
content:
|
|
487
|
-
sequence:
|
|
486
|
+
content: c,
|
|
487
|
+
sequence: n
|
|
488
488
|
} = t;
|
|
489
|
-
e === q.Partial ? a[
|
|
490
|
-
const
|
|
491
|
-
(i.content !==
|
|
489
|
+
e === q.Partial ? a[n] = c : a.answer = c;
|
|
490
|
+
const s = Ze(a);
|
|
491
|
+
(i.content !== s || e === q.Answer) && (i.content = s, o == null || o([...r.messages], e));
|
|
492
492
|
}
|
|
493
|
-
function et(e, t, a,
|
|
494
|
-
let
|
|
493
|
+
function et(e, t, a, r, o, i) {
|
|
494
|
+
let c = {};
|
|
495
495
|
return {
|
|
496
|
-
clearQueue: () =>
|
|
497
|
-
onMessage: (
|
|
498
|
-
var
|
|
499
|
-
if ("content" in
|
|
500
|
-
Ge(
|
|
496
|
+
clearQueue: () => c = {},
|
|
497
|
+
onMessage: (n, s) => {
|
|
498
|
+
var d, l;
|
|
499
|
+
if ("content" in s)
|
|
500
|
+
Ge(n, s, c, t, a.callbacks.onNewMessage), n === q.Answer && e.track("agent-message-received", {
|
|
501
501
|
messages: t.messages.length,
|
|
502
502
|
mode: t.chatMode
|
|
503
503
|
});
|
|
504
504
|
else {
|
|
505
|
-
const
|
|
505
|
+
const g = B, P = [g.StreamVideoDone, g.StreamVideoError, g.StreamVideoRejected], I = [g.StreamFailed, g.StreamVideoError, g.StreamVideoRejected], C = Ue(s, r, {
|
|
506
506
|
mode: t.chatMode
|
|
507
507
|
});
|
|
508
|
-
if (
|
|
509
|
-
e.linkTrack("agent-video",
|
|
510
|
-
else if (
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
...
|
|
514
|
-
event:
|
|
508
|
+
if (n = n, n === g.StreamVideoCreated)
|
|
509
|
+
e.linkTrack("agent-video", C, g.StreamVideoCreated, ["start"]);
|
|
510
|
+
else if (P.includes(n)) {
|
|
511
|
+
const y = n.split("/")[1];
|
|
512
|
+
I.includes(n) ? e.track("agent-video", {
|
|
513
|
+
...C,
|
|
514
|
+
event: y
|
|
515
515
|
}) : e.linkTrack("agent-video", {
|
|
516
|
-
...
|
|
517
|
-
event:
|
|
518
|
-
},
|
|
516
|
+
...C,
|
|
517
|
+
event: y
|
|
518
|
+
}, n, ["done"]);
|
|
519
519
|
}
|
|
520
|
-
|
|
521
|
-
data:
|
|
522
|
-
})),
|
|
520
|
+
I.includes(n) && ((l = (d = a.callbacks).onError) == null || l.call(d, new Error(`Stream failed with event ${n}`), {
|
|
521
|
+
data: s
|
|
522
|
+
})), s.event === g.StreamDone && o();
|
|
523
523
|
}
|
|
524
|
+
i == null || i(n, s);
|
|
524
525
|
}
|
|
525
526
|
};
|
|
526
527
|
}
|
|
527
|
-
function tt(e, t, a,
|
|
528
|
-
const
|
|
528
|
+
function tt(e, t, a, r) {
|
|
529
|
+
const o = ne(e, `${t}/agents/${a}`, r);
|
|
529
530
|
return {
|
|
530
531
|
createStream(i) {
|
|
531
|
-
return
|
|
532
|
+
return o.post("/streams", {
|
|
532
533
|
output_resolution: i.output_resolution,
|
|
533
534
|
compatibility_mode: i.compatibility_mode,
|
|
534
535
|
stream_warmup: i.stream_warmup,
|
|
@@ -536,36 +537,36 @@ function tt(e, t, a, n) {
|
|
|
536
537
|
fluent: i.fluent
|
|
537
538
|
});
|
|
538
539
|
},
|
|
539
|
-
startConnection(i,
|
|
540
|
-
return
|
|
541
|
-
session_id:
|
|
542
|
-
answer:
|
|
540
|
+
startConnection(i, c, n) {
|
|
541
|
+
return o.post(`/streams/${i}/sdp`, {
|
|
542
|
+
session_id: n,
|
|
543
|
+
answer: c
|
|
543
544
|
});
|
|
544
545
|
},
|
|
545
|
-
addIceCandidate(i,
|
|
546
|
-
return
|
|
547
|
-
session_id:
|
|
548
|
-
...
|
|
546
|
+
addIceCandidate(i, c, n) {
|
|
547
|
+
return o.post(`/streams/${i}/ice`, {
|
|
548
|
+
session_id: n,
|
|
549
|
+
...c
|
|
549
550
|
});
|
|
550
551
|
},
|
|
551
|
-
sendStreamRequest(i,
|
|
552
|
-
return
|
|
553
|
-
session_id:
|
|
554
|
-
...
|
|
552
|
+
sendStreamRequest(i, c, n) {
|
|
553
|
+
return o.post(`/streams/${i}`, {
|
|
554
|
+
session_id: c,
|
|
555
|
+
...n
|
|
555
556
|
});
|
|
556
557
|
},
|
|
557
|
-
close(i,
|
|
558
|
-
return
|
|
559
|
-
session_id:
|
|
558
|
+
close(i, c) {
|
|
559
|
+
return o.delete(`/streams/${i}`, {
|
|
560
|
+
session_id: c
|
|
560
561
|
});
|
|
561
562
|
}
|
|
562
563
|
};
|
|
563
564
|
}
|
|
564
|
-
function rt(e, t, a,
|
|
565
|
-
const
|
|
565
|
+
function rt(e, t, a, r) {
|
|
566
|
+
const o = ne(e, `${t}/agents/${a}`, r);
|
|
566
567
|
return {
|
|
567
|
-
createStream(i,
|
|
568
|
-
return
|
|
568
|
+
createStream(i, c) {
|
|
569
|
+
return o.post("/streams", {
|
|
569
570
|
driver_url: i.driver_url,
|
|
570
571
|
face: i.face,
|
|
571
572
|
config: i.config,
|
|
@@ -574,39 +575,39 @@ function rt(e, t, a, n) {
|
|
|
574
575
|
stream_warmup: i.stream_warmup,
|
|
575
576
|
session_timeout: i.session_timeout,
|
|
576
577
|
fluent: i.fluent
|
|
577
|
-
},
|
|
578
|
+
}, c);
|
|
578
579
|
},
|
|
579
|
-
startConnection(i,
|
|
580
|
-
return
|
|
581
|
-
session_id:
|
|
582
|
-
answer:
|
|
583
|
-
},
|
|
580
|
+
startConnection(i, c, n, s) {
|
|
581
|
+
return o.post(`/streams/${i}/sdp`, {
|
|
582
|
+
session_id: n,
|
|
583
|
+
answer: c
|
|
584
|
+
}, s);
|
|
584
585
|
},
|
|
585
|
-
addIceCandidate(i,
|
|
586
|
-
return
|
|
587
|
-
session_id:
|
|
588
|
-
...o
|
|
589
|
-
}, r);
|
|
590
|
-
},
|
|
591
|
-
sendStreamRequest(i, o, c, r) {
|
|
592
|
-
return s.post(`/streams/${i}`, {
|
|
593
|
-
session_id: o,
|
|
586
|
+
addIceCandidate(i, c, n, s) {
|
|
587
|
+
return o.post(`/streams/${i}/ice`, {
|
|
588
|
+
session_id: n,
|
|
594
589
|
...c
|
|
595
|
-
},
|
|
590
|
+
}, s);
|
|
596
591
|
},
|
|
597
|
-
|
|
598
|
-
return
|
|
599
|
-
session_id:
|
|
600
|
-
|
|
592
|
+
sendStreamRequest(i, c, n, s) {
|
|
593
|
+
return o.post(`/streams/${i}`, {
|
|
594
|
+
session_id: c,
|
|
595
|
+
...n
|
|
596
|
+
}, s);
|
|
597
|
+
},
|
|
598
|
+
close(i, c, n) {
|
|
599
|
+
return o.delete(`/streams/${i}`, {
|
|
600
|
+
session_id: c
|
|
601
|
+
}, n);
|
|
601
602
|
}
|
|
602
603
|
};
|
|
603
604
|
}
|
|
604
605
|
function nt(e, t, a) {
|
|
605
|
-
const
|
|
606
|
+
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
606
607
|
return {
|
|
607
|
-
duration:
|
|
608
|
+
duration: r,
|
|
608
609
|
bytesReceived: t.bytesReceived - e.bytesReceived,
|
|
609
|
-
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 /
|
|
610
|
+
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / r),
|
|
610
611
|
packetsReceived: t.packetsReceived - e.packetsReceived,
|
|
611
612
|
packetsLost: t.packetsLost - e.packetsLost,
|
|
612
613
|
framesDropped: t.framesDropped - e.framesDropped,
|
|
@@ -614,7 +615,7 @@ function nt(e, t, a) {
|
|
|
614
615
|
jitter: t.jitter,
|
|
615
616
|
avgJitterDelayInInterval: (t.jitterBufferDelay - e.jitterBufferDelay) / (t.jitterBufferEmittedCount - e.jitterBufferEmittedCount),
|
|
616
617
|
jitterBufferEmittedCount: t.jitterBufferEmittedCount - e.jitterBufferEmittedCount,
|
|
617
|
-
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) /
|
|
618
|
+
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / r,
|
|
618
619
|
framesPerSecond: t.framesPerSecond,
|
|
619
620
|
freezeCount: t.freezeCount - e.freezeCount,
|
|
620
621
|
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
@@ -625,187 +626,187 @@ function at(e) {
|
|
|
625
626
|
return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
|
|
626
627
|
const {
|
|
627
628
|
timestamp: a,
|
|
628
|
-
...
|
|
629
|
-
} = t,
|
|
630
|
-
return t.freezeCount > 0 &&
|
|
631
|
-
...
|
|
632
|
-
causes:
|
|
629
|
+
...r
|
|
630
|
+
} = t, o = [];
|
|
631
|
+
return t.freezeCount > 0 && o.push("freeze"), t.framesPerSecond < 21 && o.push("low fps"), t.framesDropped > 0 && o.push("frames dropped"), t.packetsLost > 0 && o.push("packet loss"), {
|
|
632
|
+
...r,
|
|
633
|
+
causes: o
|
|
633
634
|
};
|
|
634
635
|
});
|
|
635
636
|
}
|
|
636
637
|
function it(e) {
|
|
637
638
|
let t = "", a = 0;
|
|
638
|
-
for (const
|
|
639
|
-
if (
|
|
639
|
+
for (const r of e.values())
|
|
640
|
+
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (a = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
|
|
640
641
|
return {
|
|
641
642
|
codec: t,
|
|
642
643
|
rtt: a,
|
|
643
|
-
timestamp:
|
|
644
|
-
bytesReceived:
|
|
645
|
-
packetsReceived:
|
|
646
|
-
packetsLost:
|
|
647
|
-
framesDropped:
|
|
648
|
-
framesDecoded:
|
|
649
|
-
jitter:
|
|
650
|
-
jitterBufferDelay:
|
|
651
|
-
jitterBufferEmittedCount:
|
|
652
|
-
avgJitterDelayInInterval:
|
|
653
|
-
frameWidth:
|
|
654
|
-
frameHeight:
|
|
655
|
-
framesPerSecond:
|
|
656
|
-
freezeCount:
|
|
657
|
-
freezeDuration:
|
|
644
|
+
timestamp: r.timestamp,
|
|
645
|
+
bytesReceived: r.bytesReceived,
|
|
646
|
+
packetsReceived: r.packetsReceived,
|
|
647
|
+
packetsLost: r.packetsLost,
|
|
648
|
+
framesDropped: r.framesDropped,
|
|
649
|
+
framesDecoded: r.framesDecoded,
|
|
650
|
+
jitter: r.jitter,
|
|
651
|
+
jitterBufferDelay: r.jitterBufferDelay,
|
|
652
|
+
jitterBufferEmittedCount: r.jitterBufferEmittedCount,
|
|
653
|
+
avgJitterDelayInInterval: r.jitterBufferDelay / r.jitterBufferEmittedCount,
|
|
654
|
+
frameWidth: r.frameWidth,
|
|
655
|
+
frameHeight: r.frameHeight,
|
|
656
|
+
framesPerSecond: r.framesPerSecond,
|
|
657
|
+
freezeCount: r.freezeCount,
|
|
658
|
+
freezeDuration: r.totalFreezesDuration
|
|
658
659
|
};
|
|
659
660
|
return {};
|
|
660
661
|
}
|
|
661
662
|
function st(e, t, a) {
|
|
662
|
-
const
|
|
663
|
-
timestamp:
|
|
663
|
+
const r = e.map((s, d) => d === 0 ? a ? {
|
|
664
|
+
timestamp: s.timestamp,
|
|
664
665
|
duration: 0,
|
|
665
|
-
rtt:
|
|
666
|
-
bytesReceived:
|
|
667
|
-
bitrate: (
|
|
668
|
-
packetsReceived:
|
|
669
|
-
packetsLost:
|
|
670
|
-
framesDropped:
|
|
671
|
-
framesDecoded:
|
|
672
|
-
jitter:
|
|
673
|
-
jitterBufferDelay:
|
|
674
|
-
jitterBufferEmittedCount:
|
|
675
|
-
avgJitterDelayInInterval: (
|
|
676
|
-
framesPerSecond:
|
|
677
|
-
freezeCount:
|
|
678
|
-
freezeDuration:
|
|
666
|
+
rtt: s.rtt,
|
|
667
|
+
bytesReceived: s.bytesReceived - a.bytesReceived,
|
|
668
|
+
bitrate: (s.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
|
|
669
|
+
packetsReceived: s.packetsReceived - a.packetsReceived,
|
|
670
|
+
packetsLost: s.packetsLost - a.packetsLost,
|
|
671
|
+
framesDropped: s.framesDropped - a.framesDropped,
|
|
672
|
+
framesDecoded: s.framesDecoded - a.framesDecoded,
|
|
673
|
+
jitter: s.jitter,
|
|
674
|
+
jitterBufferDelay: s.jitterBufferDelay - a.jitterBufferDelay,
|
|
675
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount - a.jitterBufferEmittedCount,
|
|
676
|
+
avgJitterDelayInInterval: (s.jitterBufferDelay - a.jitterBufferDelay) / (s.jitterBufferEmittedCount - a.jitterBufferEmittedCount),
|
|
677
|
+
framesPerSecond: s.framesPerSecond,
|
|
678
|
+
freezeCount: s.freezeCount - a.freezeCount,
|
|
679
|
+
freezeDuration: s.freezeDuration - a.freezeDuration
|
|
679
680
|
} : {
|
|
680
|
-
timestamp:
|
|
681
|
-
rtt:
|
|
681
|
+
timestamp: s.timestamp,
|
|
682
|
+
rtt: s.rtt,
|
|
682
683
|
duration: 0,
|
|
683
|
-
bytesReceived:
|
|
684
|
-
bitrate:
|
|
685
|
-
packetsReceived:
|
|
686
|
-
packetsLost:
|
|
687
|
-
framesDropped:
|
|
688
|
-
framesDecoded:
|
|
689
|
-
jitter:
|
|
690
|
-
jitterBufferDelay:
|
|
691
|
-
jitterBufferEmittedCount:
|
|
692
|
-
avgJitterDelayInInterval:
|
|
693
|
-
framesPerSecond:
|
|
694
|
-
freezeCount:
|
|
695
|
-
freezeDuration:
|
|
684
|
+
bytesReceived: s.bytesReceived,
|
|
685
|
+
bitrate: s.bytesReceived * 8 / (t / 1e3),
|
|
686
|
+
packetsReceived: s.packetsReceived,
|
|
687
|
+
packetsLost: s.packetsLost,
|
|
688
|
+
framesDropped: s.framesDropped,
|
|
689
|
+
framesDecoded: s.framesDecoded,
|
|
690
|
+
jitter: s.jitter,
|
|
691
|
+
jitterBufferDelay: s.jitterBufferDelay,
|
|
692
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount,
|
|
693
|
+
avgJitterDelayInInterval: s.jitterBufferDelay / s.jitterBufferEmittedCount,
|
|
694
|
+
framesPerSecond: s.framesPerSecond,
|
|
695
|
+
freezeCount: s.freezeCount,
|
|
696
|
+
freezeDuration: s.freezeDuration
|
|
696
697
|
} : {
|
|
697
|
-
timestamp:
|
|
698
|
-
duration: t *
|
|
699
|
-
rtt:
|
|
700
|
-
bytesReceived:
|
|
701
|
-
bitrate: (
|
|
702
|
-
packetsReceived:
|
|
703
|
-
packetsLost:
|
|
704
|
-
framesDropped:
|
|
705
|
-
framesDecoded:
|
|
706
|
-
jitter:
|
|
707
|
-
jitterBufferDelay:
|
|
708
|
-
jitterBufferEmittedCount:
|
|
709
|
-
avgJitterDelayInInterval: (
|
|
710
|
-
framesPerSecond:
|
|
711
|
-
freezeCount:
|
|
712
|
-
freezeDuration:
|
|
713
|
-
}),
|
|
698
|
+
timestamp: s.timestamp,
|
|
699
|
+
duration: t * d / 1e3,
|
|
700
|
+
rtt: s.rtt,
|
|
701
|
+
bytesReceived: s.bytesReceived - e[d - 1].bytesReceived,
|
|
702
|
+
bitrate: (s.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
|
|
703
|
+
packetsReceived: s.packetsReceived - e[d - 1].packetsReceived,
|
|
704
|
+
packetsLost: s.packetsLost - e[d - 1].packetsLost,
|
|
705
|
+
framesDropped: s.framesDropped - e[d - 1].framesDropped,
|
|
706
|
+
framesDecoded: s.framesDecoded - e[d - 1].framesDecoded,
|
|
707
|
+
jitter: s.jitter,
|
|
708
|
+
jitterBufferDelay: s.jitterBufferDelay - e[d - 1].jitterBufferDelay,
|
|
709
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
|
|
710
|
+
avgJitterDelayInInterval: (s.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (s.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
|
|
711
|
+
framesPerSecond: s.framesPerSecond,
|
|
712
|
+
freezeCount: s.freezeCount - e[d - 1].freezeCount,
|
|
713
|
+
freezeDuration: s.freezeDuration - e[d - 1].freezeDuration
|
|
714
|
+
}), o = at(r), i = o.reduce((s, d) => s + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), n = r.filter((s) => !!s.rtt).map((s) => s.rtt);
|
|
714
715
|
return {
|
|
715
716
|
webRTCStats: {
|
|
716
|
-
anomalies:
|
|
717
|
-
minRtt: Math.min(...
|
|
718
|
-
avgRtt:
|
|
719
|
-
maxRtt: Math.max(...
|
|
717
|
+
anomalies: o,
|
|
718
|
+
minRtt: Math.min(...n),
|
|
719
|
+
avgRtt: ae(n),
|
|
720
|
+
maxRtt: Math.max(...n),
|
|
720
721
|
aggregateReport: nt(e[0], e[e.length - 1], i),
|
|
721
|
-
minJitterDelayInInterval: Math.min(...
|
|
722
|
-
maxJitterDelayInInterval: Math.max(...
|
|
723
|
-
avgJitterDelayInInterval:
|
|
722
|
+
minJitterDelayInInterval: Math.min(...c),
|
|
723
|
+
maxJitterDelayInInterval: Math.max(...c),
|
|
724
|
+
avgJitterDelayInInterval: ae(c)
|
|
724
725
|
},
|
|
725
726
|
codec: e[0].codec,
|
|
726
727
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
727
728
|
};
|
|
728
729
|
}
|
|
729
|
-
const
|
|
730
|
-
function
|
|
731
|
-
let e = 0, t, a,
|
|
732
|
-
return (
|
|
733
|
-
for (const i of
|
|
730
|
+
const re = 100, ot = Math.max(Math.ceil(400 / re), 1), ct = 0.25, dt = 0.28;
|
|
731
|
+
function ut() {
|
|
732
|
+
let e = 0, t, a, r = 0;
|
|
733
|
+
return (o) => {
|
|
734
|
+
for (const i of o.values())
|
|
734
735
|
if (i && i.type === "inbound-rtp" && i.kind === "video") {
|
|
735
|
-
const
|
|
736
|
-
if (a &&
|
|
737
|
-
const
|
|
738
|
-
|
|
736
|
+
const c = i.jitterBufferDelay, n = i.jitterBufferEmittedCount;
|
|
737
|
+
if (a && n > a) {
|
|
738
|
+
const l = c - t, g = n - a;
|
|
739
|
+
r = l / g;
|
|
739
740
|
}
|
|
740
|
-
t =
|
|
741
|
-
const
|
|
742
|
-
return e =
|
|
743
|
-
isReceiving:
|
|
744
|
-
avgJitterDelayInInterval:
|
|
741
|
+
t = c, a = n;
|
|
742
|
+
const s = i.framesDecoded, d = s - e > 0;
|
|
743
|
+
return e = s, {
|
|
744
|
+
isReceiving: d,
|
|
745
|
+
avgJitterDelayInInterval: r,
|
|
745
746
|
freezeCount: i.freezeCount
|
|
746
747
|
};
|
|
747
748
|
}
|
|
748
749
|
return {
|
|
749
750
|
isReceiving: !1,
|
|
750
|
-
avgJitterDelayInInterval:
|
|
751
|
+
avgJitterDelayInInterval: r
|
|
751
752
|
};
|
|
752
753
|
};
|
|
753
754
|
}
|
|
754
|
-
function
|
|
755
|
-
let
|
|
756
|
-
const
|
|
755
|
+
function lt(e, t, a, r, o, i = !1) {
|
|
756
|
+
let c = [], n, s = 0, d = !1, l = Q.Unknown, g = Q.Unknown, P = 0, I = 0;
|
|
757
|
+
const C = ut();
|
|
757
758
|
return setInterval(async () => {
|
|
758
|
-
const
|
|
759
|
+
const y = await e.getStats(), {
|
|
759
760
|
isReceiving: v,
|
|
760
|
-
avgJitterDelayInInterval:
|
|
761
|
-
freezeCount:
|
|
762
|
-
} =
|
|
761
|
+
avgJitterDelayInInterval: z,
|
|
762
|
+
freezeCount: $
|
|
763
|
+
} = C(y), M = it(y);
|
|
763
764
|
if (v)
|
|
764
|
-
|
|
765
|
-
else if (
|
|
766
|
-
const u = st(
|
|
767
|
-
|
|
765
|
+
s = 0, P = $ - I, g = z < ct ? Q.Strong : z > dt && P > 1 ? Q.Weak : l, g !== l && (o == null || o(g), l = g, I += P, P = 0), d || (r == null || r(p.Start), n = c[c.length - 1], c = [], d = !0), c.push(M);
|
|
766
|
+
else if (d && (s++, s >= ot)) {
|
|
767
|
+
const u = st(c, re, n);
|
|
768
|
+
r == null || r(p.Stop, u), t() || a(), I = $, d = !1;
|
|
768
769
|
}
|
|
769
|
-
},
|
|
770
|
+
}, re);
|
|
770
771
|
}
|
|
771
|
-
let
|
|
772
|
-
const
|
|
773
|
-
function
|
|
772
|
+
let pe = !1;
|
|
773
|
+
const L = (e, t) => pe && console.log(e, t), ft = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
774
|
+
function ie(e) {
|
|
774
775
|
switch (e) {
|
|
775
776
|
case "connected":
|
|
776
|
-
return
|
|
777
|
+
return E.Connected;
|
|
777
778
|
case "checking":
|
|
778
|
-
return
|
|
779
|
+
return E.Connecting;
|
|
779
780
|
case "failed":
|
|
780
|
-
return
|
|
781
|
+
return E.Fail;
|
|
781
782
|
case "new":
|
|
782
|
-
return
|
|
783
|
+
return E.New;
|
|
783
784
|
case "closed":
|
|
784
|
-
return
|
|
785
|
+
return E.Closed;
|
|
785
786
|
case "disconnected":
|
|
786
|
-
return
|
|
787
|
+
return E.Disconnected;
|
|
787
788
|
case "completed":
|
|
788
|
-
return
|
|
789
|
+
return E.Completed;
|
|
789
790
|
default:
|
|
790
|
-
return
|
|
791
|
+
return E.New;
|
|
791
792
|
}
|
|
792
793
|
}
|
|
793
794
|
function mt(e) {
|
|
794
795
|
const [t, a = ""] = e.split(/:(.+)/);
|
|
795
796
|
try {
|
|
796
|
-
const
|
|
797
|
-
return
|
|
797
|
+
const r = JSON.parse(a);
|
|
798
|
+
return L("parsed data channel message", {
|
|
798
799
|
subject: t,
|
|
799
|
-
data:
|
|
800
|
+
data: r
|
|
800
801
|
}), {
|
|
801
802
|
subject: t,
|
|
802
|
-
data:
|
|
803
|
+
data: r
|
|
803
804
|
};
|
|
804
|
-
} catch (
|
|
805
|
-
return
|
|
805
|
+
} catch (r) {
|
|
806
|
+
return L("Failed to parse data channel message, returning data as string", {
|
|
806
807
|
subject: t,
|
|
807
808
|
rawData: a,
|
|
808
|
-
error:
|
|
809
|
+
error: r
|
|
809
810
|
}), {
|
|
810
811
|
subject: t,
|
|
811
812
|
data: a
|
|
@@ -816,196 +817,196 @@ function gt({
|
|
|
816
817
|
statsSignal: e,
|
|
817
818
|
dataChannelSignal: t,
|
|
818
819
|
onVideoStateChange: a,
|
|
819
|
-
report:
|
|
820
|
+
report: r
|
|
820
821
|
}) {
|
|
821
|
-
e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop,
|
|
822
|
+
e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop, r));
|
|
822
823
|
}
|
|
823
824
|
function ht({
|
|
824
825
|
statsSignal: e,
|
|
825
826
|
dataChannelSignal: t,
|
|
826
827
|
onVideoStateChange: a,
|
|
827
|
-
onAgentActivityStateChange:
|
|
828
|
-
report:
|
|
828
|
+
onAgentActivityStateChange: r,
|
|
829
|
+
report: o
|
|
829
830
|
}) {
|
|
830
|
-
e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop,
|
|
831
|
+
e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, o)), t === p.Start ? r == null || r(X.Talking) : t === p.Stop && (r == null || r(X.Idle));
|
|
831
832
|
}
|
|
832
|
-
function
|
|
833
|
+
function se({
|
|
833
834
|
statsSignal: e,
|
|
834
835
|
dataChannelSignal: t,
|
|
835
836
|
onVideoStateChange: a,
|
|
836
|
-
onAgentActivityStateChange:
|
|
837
|
-
streamType:
|
|
837
|
+
onAgentActivityStateChange: r,
|
|
838
|
+
streamType: o,
|
|
838
839
|
report: i
|
|
839
840
|
}) {
|
|
840
|
-
|
|
841
|
+
o === U.Legacy ? gt({
|
|
841
842
|
statsSignal: e,
|
|
842
843
|
dataChannelSignal: t,
|
|
843
844
|
onVideoStateChange: a,
|
|
844
845
|
report: i
|
|
845
|
-
}) :
|
|
846
|
+
}) : o === U.Fluent && ht({
|
|
846
847
|
statsSignal: e,
|
|
847
848
|
dataChannelSignal: t,
|
|
848
849
|
onVideoStateChange: a,
|
|
849
|
-
onAgentActivityStateChange:
|
|
850
|
+
onAgentActivityStateChange: r,
|
|
850
851
|
report: i
|
|
851
852
|
});
|
|
852
853
|
}
|
|
853
854
|
async function wt(e, t, {
|
|
854
855
|
debug: a = !1,
|
|
855
|
-
callbacks:
|
|
856
|
-
auth:
|
|
856
|
+
callbacks: r,
|
|
857
|
+
auth: o,
|
|
857
858
|
baseURL: i = O,
|
|
858
|
-
analytics:
|
|
859
|
+
analytics: c
|
|
859
860
|
}) {
|
|
860
|
-
var
|
|
861
|
-
|
|
862
|
-
let
|
|
861
|
+
var F;
|
|
862
|
+
pe = a;
|
|
863
|
+
let n = !1, s = !1, d = p.Stop, l = p.Stop;
|
|
863
864
|
const {
|
|
864
|
-
startConnection:
|
|
865
|
-
sendStreamRequest:
|
|
865
|
+
startConnection: g,
|
|
866
|
+
sendStreamRequest: P,
|
|
866
867
|
close: I,
|
|
867
|
-
createStream:
|
|
868
|
-
addIceCandidate:
|
|
869
|
-
} = t.videoType ===
|
|
868
|
+
createStream: C,
|
|
869
|
+
addIceCandidate: y
|
|
870
|
+
} = t.videoType === oe.Clip ? tt(o, i, e, r.onError) : rt(o, i, e, r.onError), {
|
|
870
871
|
id: v,
|
|
871
|
-
offer:
|
|
872
|
-
ice_servers:
|
|
873
|
-
session_id:
|
|
872
|
+
offer: z,
|
|
873
|
+
ice_servers: $,
|
|
874
|
+
session_id: M,
|
|
874
875
|
fluent: u,
|
|
875
876
|
interrupt_enabled: w
|
|
876
|
-
} = await
|
|
877
|
-
(
|
|
877
|
+
} = await C(t);
|
|
878
|
+
(F = r.onStreamCreated) == null || F.call(r, {
|
|
878
879
|
stream_id: v,
|
|
879
|
-
session_id:
|
|
880
|
+
session_id: M,
|
|
880
881
|
agent_id: e
|
|
881
882
|
});
|
|
882
|
-
const
|
|
883
|
-
iceServers:
|
|
884
|
-
}),
|
|
885
|
-
if (!
|
|
883
|
+
const m = new ft({
|
|
884
|
+
iceServers: $
|
|
885
|
+
}), _ = m.createDataChannel("JanusDataChannel");
|
|
886
|
+
if (!M)
|
|
886
887
|
throw new Error("Could not create session_id");
|
|
887
|
-
const
|
|
888
|
-
|
|
889
|
-
"stream-type":
|
|
888
|
+
const D = u ? U.Fluent : U.Legacy;
|
|
889
|
+
c.enrich({
|
|
890
|
+
"stream-type": D
|
|
890
891
|
});
|
|
891
|
-
const k = t.stream_warmup && !u,
|
|
892
|
-
var
|
|
893
|
-
|
|
894
|
-
},
|
|
895
|
-
statsSignal:
|
|
896
|
-
dataChannelSignal:
|
|
897
|
-
onVideoStateChange:
|
|
898
|
-
onAgentActivityStateChange:
|
|
892
|
+
const k = t.stream_warmup && !u, T = () => n, N = () => {
|
|
893
|
+
var f;
|
|
894
|
+
n = !0, s && ((f = r.onConnectionStateChange) == null || f.call(r, E.Connected));
|
|
895
|
+
}, x = lt(m, T, N, (f, h) => se({
|
|
896
|
+
statsSignal: l = f,
|
|
897
|
+
dataChannelSignal: D === U.Legacy ? d : void 0,
|
|
898
|
+
onVideoStateChange: r.onVideoStateChange,
|
|
899
|
+
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
899
900
|
report: h,
|
|
900
|
-
streamType:
|
|
901
|
-
}), (
|
|
901
|
+
streamType: D
|
|
902
|
+
}), (f) => {
|
|
902
903
|
var h;
|
|
903
|
-
return (h =
|
|
904
|
+
return (h = r.onConnectivityStateChange) == null ? void 0 : h.call(r, f);
|
|
904
905
|
}, k);
|
|
905
|
-
|
|
906
|
+
m.onicecandidate = (f) => {
|
|
906
907
|
var h;
|
|
907
|
-
|
|
908
|
+
L("peerConnection.onicecandidate", f);
|
|
908
909
|
try {
|
|
909
|
-
|
|
910
|
-
candidate:
|
|
911
|
-
sdpMid:
|
|
912
|
-
sdpMLineIndex:
|
|
913
|
-
},
|
|
910
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? y(v, {
|
|
911
|
+
candidate: f.candidate.candidate,
|
|
912
|
+
sdpMid: f.candidate.sdpMid,
|
|
913
|
+
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
914
|
+
}, M) : y(v, {
|
|
914
915
|
candidate: null
|
|
915
|
-
},
|
|
916
|
-
} catch (
|
|
917
|
-
(h =
|
|
916
|
+
}, M);
|
|
917
|
+
} catch (A) {
|
|
918
|
+
(h = r.onError) == null || h.call(r, A, {
|
|
918
919
|
streamId: v
|
|
919
920
|
});
|
|
920
921
|
}
|
|
921
|
-
},
|
|
922
|
-
|
|
922
|
+
}, _.onopen = () => {
|
|
923
|
+
s = !0, (!k || n) && N();
|
|
923
924
|
};
|
|
924
|
-
function
|
|
925
|
-
|
|
926
|
-
statsSignal:
|
|
927
|
-
dataChannelSignal:
|
|
928
|
-
onVideoStateChange:
|
|
929
|
-
onAgentActivityStateChange:
|
|
930
|
-
streamType:
|
|
925
|
+
function S(f) {
|
|
926
|
+
d = f === B.StreamStarted ? p.Start : p.Stop, se({
|
|
927
|
+
statsSignal: D === U.Legacy ? l : void 0,
|
|
928
|
+
dataChannelSignal: d,
|
|
929
|
+
onVideoStateChange: r.onVideoStateChange,
|
|
930
|
+
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
931
|
+
streamType: D
|
|
931
932
|
});
|
|
932
933
|
}
|
|
933
|
-
function
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
streamMetadata:
|
|
937
|
-
}),
|
|
934
|
+
function b(f, h) {
|
|
935
|
+
const A = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
|
|
936
|
+
A && c.enrich({
|
|
937
|
+
streamMetadata: A
|
|
938
|
+
}), c.track("agent-chat", {
|
|
938
939
|
event: "ready"
|
|
939
940
|
});
|
|
940
941
|
}
|
|
941
942
|
const R = {
|
|
942
|
-
[
|
|
943
|
-
[
|
|
944
|
-
[
|
|
943
|
+
[B.StreamStarted]: S,
|
|
944
|
+
[B.StreamDone]: S,
|
|
945
|
+
[B.StreamReady]: b
|
|
945
946
|
};
|
|
946
|
-
|
|
947
|
+
_.onmessage = (f) => {
|
|
947
948
|
var K;
|
|
948
949
|
const {
|
|
949
950
|
subject: h,
|
|
950
|
-
data:
|
|
951
|
-
} = mt(
|
|
952
|
-
(K = R[h]) == null || K.call(R, h,
|
|
953
|
-
},
|
|
951
|
+
data: A
|
|
952
|
+
} = mt(f.data);
|
|
953
|
+
(K = R[h]) == null || K.call(R, h, A);
|
|
954
|
+
}, m.oniceconnectionstatechange = () => {
|
|
954
955
|
var h;
|
|
955
|
-
|
|
956
|
-
const
|
|
957
|
-
|
|
958
|
-
},
|
|
956
|
+
L("peerConnection.oniceconnectionstatechange => " + m.iceConnectionState);
|
|
957
|
+
const f = ie(m.iceConnectionState);
|
|
958
|
+
f !== E.Connected && ((h = r.onConnectionStateChange) == null || h.call(r, f));
|
|
959
|
+
}, m.ontrack = (f) => {
|
|
959
960
|
var h;
|
|
960
|
-
|
|
961
|
-
}, await
|
|
962
|
-
const W = await
|
|
963
|
-
return
|
|
961
|
+
L("peerConnection.ontrack", f), (h = r.onSrcObjectReady) == null || h.call(r, f.streams[0]);
|
|
962
|
+
}, await m.setRemoteDescription(z), L("set remote description OK");
|
|
963
|
+
const W = await m.createAnswer();
|
|
964
|
+
return L("create answer OK"), await m.setLocalDescription(W), L("set local description OK"), await g(v, W, M), L("start connection OK"), {
|
|
964
965
|
/**
|
|
965
966
|
* Method to send request to server to get clip or talk depend on you payload
|
|
966
967
|
* @param payload
|
|
967
968
|
*/
|
|
968
|
-
speak(
|
|
969
|
-
return
|
|
969
|
+
speak(f) {
|
|
970
|
+
return P(v, M, f);
|
|
970
971
|
},
|
|
971
972
|
/**
|
|
972
973
|
* Method to close RTC connection
|
|
973
974
|
*/
|
|
974
975
|
async disconnect() {
|
|
975
|
-
var
|
|
976
|
+
var f;
|
|
976
977
|
if (v) {
|
|
977
|
-
const h =
|
|
978
|
-
if (
|
|
979
|
-
if (h ===
|
|
980
|
-
clearInterval(
|
|
978
|
+
const h = ie(m.iceConnectionState);
|
|
979
|
+
if (m) {
|
|
980
|
+
if (h === E.New) {
|
|
981
|
+
clearInterval(x);
|
|
981
982
|
return;
|
|
982
983
|
}
|
|
983
|
-
|
|
984
|
+
m.close(), m.oniceconnectionstatechange = null, m.onnegotiationneeded = null, m.onicecandidate = null, m.ontrack = null;
|
|
984
985
|
}
|
|
985
986
|
try {
|
|
986
|
-
h ===
|
|
987
|
+
h === E.Connected && await I(v, M).catch((A) => {
|
|
987
988
|
});
|
|
988
|
-
} catch (
|
|
989
|
-
|
|
989
|
+
} catch (A) {
|
|
990
|
+
L("Error on close stream connection", A);
|
|
990
991
|
}
|
|
991
|
-
(
|
|
992
|
+
(f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval(x);
|
|
992
993
|
}
|
|
993
994
|
},
|
|
994
995
|
/**
|
|
995
996
|
* Method to send data channel messages to the server
|
|
996
997
|
*/
|
|
997
|
-
sendDataChannelMessage(
|
|
998
|
-
var h,
|
|
999
|
-
if (!
|
|
1000
|
-
|
|
998
|
+
sendDataChannelMessage(f) {
|
|
999
|
+
var h, A;
|
|
1000
|
+
if (!n || _.readyState !== "open") {
|
|
1001
|
+
L("Data channel is not ready for sending messages"), (h = r.onError) == null || h.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1001
1002
|
streamId: v
|
|
1002
1003
|
});
|
|
1003
1004
|
return;
|
|
1004
1005
|
}
|
|
1005
1006
|
try {
|
|
1006
|
-
|
|
1007
|
+
_.send(f);
|
|
1007
1008
|
} catch (K) {
|
|
1008
|
-
|
|
1009
|
+
L("Error sending data channel message", K), (A = r.onError) == null || A.call(r, K, {
|
|
1009
1010
|
streamId: v
|
|
1010
1011
|
});
|
|
1011
1012
|
}
|
|
@@ -1013,12 +1014,12 @@ async function wt(e, t, {
|
|
|
1013
1014
|
/**
|
|
1014
1015
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1015
1016
|
*/
|
|
1016
|
-
sessionId:
|
|
1017
|
+
sessionId: M,
|
|
1017
1018
|
/**
|
|
1018
1019
|
* Id of current RTC stream
|
|
1019
1020
|
*/
|
|
1020
1021
|
streamId: v,
|
|
1021
|
-
streamType:
|
|
1022
|
+
streamType: D,
|
|
1022
1023
|
interruptAvailable: w
|
|
1023
1024
|
};
|
|
1024
1025
|
}
|
|
@@ -1027,7 +1028,7 @@ function pt(e, t) {
|
|
|
1027
1028
|
streamOptions: a
|
|
1028
1029
|
} = t ?? {};
|
|
1029
1030
|
return {
|
|
1030
|
-
videoType:
|
|
1031
|
+
videoType: je(e.presenter.type),
|
|
1031
1032
|
output_resolution: a == null ? void 0 : a.outputResolution,
|
|
1032
1033
|
session_timeout: a == null ? void 0 : a.sessionTimeout,
|
|
1033
1034
|
stream_warmup: a == null ? void 0 : a.streamWarmup,
|
|
@@ -1035,309 +1036,310 @@ function pt(e, t) {
|
|
|
1035
1036
|
fluent: a == null ? void 0 : a.fluent
|
|
1036
1037
|
};
|
|
1037
1038
|
}
|
|
1038
|
-
function yt(e, t, a,
|
|
1039
|
-
|
|
1039
|
+
function yt(e, t, a, r, o) {
|
|
1040
|
+
o === U.Fluent ? vt(e, t, a, r, o) : Dt(e, t, a, r, o);
|
|
1040
1041
|
}
|
|
1041
|
-
function vt(e, t, a,
|
|
1042
|
-
e === p.Start ?
|
|
1042
|
+
function vt(e, t, a, r, o) {
|
|
1043
|
+
e === p.Start ? r.track("stream-session", {
|
|
1043
1044
|
event: "start",
|
|
1044
|
-
"stream-type":
|
|
1045
|
-
}) : e === p.Stop &&
|
|
1045
|
+
"stream-type": o
|
|
1046
|
+
}) : e === p.Stop && r.track("stream-session", {
|
|
1046
1047
|
event: "stop",
|
|
1047
1048
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1048
1049
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1049
|
-
"stream-type":
|
|
1050
|
+
"stream-type": o,
|
|
1050
1051
|
...a
|
|
1051
1052
|
});
|
|
1052
1053
|
}
|
|
1053
|
-
function kt(e, t, a,
|
|
1054
|
-
|
|
1054
|
+
function kt(e, t, a, r) {
|
|
1055
|
+
J.get() <= 0 || (e === p.Start ? a.linkTrack("agent-video", {
|
|
1055
1056
|
event: "start",
|
|
1056
|
-
latency:
|
|
1057
|
-
"stream-type":
|
|
1058
|
-
}, "start", [
|
|
1057
|
+
latency: J.get(!0),
|
|
1058
|
+
"stream-type": r
|
|
1059
|
+
}, "start", [B.StreamVideoCreated]) : e === p.Stop && a.linkTrack("agent-video", {
|
|
1059
1060
|
event: "stop",
|
|
1060
1061
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1061
1062
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1062
|
-
"stream-type":
|
|
1063
|
-
}, "done", [
|
|
1063
|
+
"stream-type": r
|
|
1064
|
+
}, "done", [B.StreamVideoDone]));
|
|
1064
1065
|
}
|
|
1065
|
-
function Dt(e, t, a,
|
|
1066
|
-
|
|
1066
|
+
function Dt(e, t, a, r, o) {
|
|
1067
|
+
J.get() <= 0 || (e === p.Start ? r.linkTrack("agent-video", {
|
|
1067
1068
|
event: "start",
|
|
1068
|
-
latency:
|
|
1069
|
-
"stream-type":
|
|
1070
|
-
}, "start", [
|
|
1069
|
+
latency: J.get(!0),
|
|
1070
|
+
"stream-type": o
|
|
1071
|
+
}, "start", [B.StreamVideoCreated]) : e === p.Stop && r.linkTrack("agent-video", {
|
|
1071
1072
|
event: "stop",
|
|
1072
1073
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1073
1074
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1074
|
-
"stream-type":
|
|
1075
|
+
"stream-type": o,
|
|
1075
1076
|
...a
|
|
1076
|
-
}, "done", [
|
|
1077
|
+
}, "done", [B.StreamVideoDone]));
|
|
1077
1078
|
}
|
|
1078
1079
|
function Ct(e, t, a) {
|
|
1079
|
-
return
|
|
1080
|
+
return J.reset(), new Promise(async (r, o) => {
|
|
1080
1081
|
try {
|
|
1081
1082
|
const i = await wt(e.id, pt(e, t), {
|
|
1082
1083
|
...t,
|
|
1083
1084
|
analytics: a,
|
|
1084
1085
|
callbacks: {
|
|
1085
1086
|
...t.callbacks,
|
|
1086
|
-
onConnectionStateChange: (
|
|
1087
|
-
var
|
|
1088
|
-
(
|
|
1087
|
+
onConnectionStateChange: (c) => {
|
|
1088
|
+
var n, s;
|
|
1089
|
+
(s = (n = t.callbacks).onConnectionStateChange) == null || s.call(n, c), c === E.Connected && r(i);
|
|
1089
1090
|
},
|
|
1090
|
-
onVideoStateChange: (
|
|
1091
|
-
var
|
|
1092
|
-
(
|
|
1091
|
+
onVideoStateChange: (c, n) => {
|
|
1092
|
+
var s, d;
|
|
1093
|
+
(d = (s = t.callbacks).onVideoStateChange) == null || d.call(s, c), yt(c, e, n, a, i.streamType);
|
|
1093
1094
|
},
|
|
1094
|
-
onAgentActivityStateChange: (
|
|
1095
|
-
var
|
|
1096
|
-
(
|
|
1095
|
+
onAgentActivityStateChange: (c) => {
|
|
1096
|
+
var n, s;
|
|
1097
|
+
(s = (n = t.callbacks).onAgentActivityStateChange) == null || s.call(n, c), c === X.Talking ? te.update() : te.reset(), kt(c === X.Talking ? p.Start : p.Stop, e, a, i.streamType);
|
|
1097
1098
|
}
|
|
1098
1099
|
}
|
|
1099
1100
|
});
|
|
1100
1101
|
} catch (i) {
|
|
1101
|
-
|
|
1102
|
+
o(i);
|
|
1102
1103
|
}
|
|
1103
1104
|
});
|
|
1104
1105
|
}
|
|
1105
|
-
async function Rt(e, t, a,
|
|
1106
|
-
var
|
|
1106
|
+
async function Rt(e, t, a, r, o) {
|
|
1107
|
+
var s, d, l, g;
|
|
1107
1108
|
const {
|
|
1108
1109
|
chat: i,
|
|
1109
|
-
chatMode:
|
|
1110
|
-
} = await
|
|
1111
|
-
if (
|
|
1112
|
-
return (
|
|
1110
|
+
chatMode: c
|
|
1111
|
+
} = await we(e, a, r, t.mode, t.persistentChat, o);
|
|
1112
|
+
if (c && c !== t.mode && (t.mode = c, (d = (s = t.callbacks).onModeChange) == null || d.call(s, c), c === j.TextOnly))
|
|
1113
|
+
return (g = (l = t.callbacks).onError) == null || g.call(l, new De(c)), {
|
|
1113
1114
|
chat: i
|
|
1114
1115
|
};
|
|
1115
|
-
const
|
|
1116
|
+
const n = await Ct(e, t, r);
|
|
1116
1117
|
return {
|
|
1117
1118
|
chat: i,
|
|
1118
|
-
streamingManager:
|
|
1119
|
+
streamingManager: n
|
|
1119
1120
|
};
|
|
1120
1121
|
}
|
|
1121
|
-
async function
|
|
1122
|
-
var
|
|
1123
|
-
let a = !0,
|
|
1124
|
-
const
|
|
1122
|
+
async function _t(e, t) {
|
|
1123
|
+
var z, $, M;
|
|
1124
|
+
let a = !0, r = null;
|
|
1125
|
+
const o = t.mixpanelKey || Le, i = t.wsURL || Be, c = t.baseURL || O, n = {
|
|
1125
1126
|
messages: [],
|
|
1126
|
-
chatMode: t.mode ||
|
|
1127
|
-
},
|
|
1128
|
-
token:
|
|
1127
|
+
chatMode: t.mode || j.Functional
|
|
1128
|
+
}, s = fe(t.auth, c, t.callbacks.onError), d = await s.getById(e), l = He({
|
|
1129
|
+
token: o,
|
|
1129
1130
|
agent: d,
|
|
1130
1131
|
isEnabled: t.enableAnalitics,
|
|
1131
1132
|
distinctId: t.distinctId
|
|
1132
|
-
}), {
|
|
1133
|
-
|
|
1133
|
+
}), g = (u, w) => {
|
|
1134
|
+
u === B.StreamVideoCreated && (r = w.videoId), u === B.StreamVideoDone && (r = null);
|
|
1135
|
+
}, {
|
|
1136
|
+
onMessage: P,
|
|
1134
1137
|
clearQueue: I
|
|
1135
|
-
} = et(
|
|
1138
|
+
} = et(l, n, t, d, () => {
|
|
1136
1139
|
var u;
|
|
1137
|
-
return (u =
|
|
1138
|
-
});
|
|
1139
|
-
|
|
1140
|
+
return (u = n.socketManager) == null ? void 0 : u.disconnect();
|
|
1141
|
+
}, (u, w) => g(u, w));
|
|
1142
|
+
n.messages = qe(t.initialMessages), ($ = (z = t.callbacks).onNewMessage) == null || $.call(z, [...n.messages], "answer"), l.track("agent-sdk", {
|
|
1140
1143
|
event: "loaded",
|
|
1141
|
-
...
|
|
1144
|
+
...Je(d)
|
|
1142
1145
|
});
|
|
1143
|
-
async function
|
|
1144
|
-
var
|
|
1145
|
-
(
|
|
1146
|
-
const w =
|
|
1147
|
-
onMessage:
|
|
1146
|
+
async function C(u) {
|
|
1147
|
+
var T, N, x, S, b, R, W;
|
|
1148
|
+
(N = (T = t.callbacks).onConnectionStateChange) == null || N.call(T, E.Connecting), J.reset(), u && !a && (delete n.chat, (S = (x = t.callbacks).onNewMessage) == null || S.call(x, [...n.messages], "answer"));
|
|
1149
|
+
const w = t.mode === j.DirectPlayback ? Promise.resolve(void 0) : Oe(t.auth, i, {
|
|
1150
|
+
onMessage: P,
|
|
1148
1151
|
onError: t.callbacks.onError
|
|
1149
|
-
}),
|
|
1152
|
+
}), m = ee(() => Rt(d, t, s, l, n.chat), {
|
|
1150
1153
|
limit: 3,
|
|
1151
|
-
timeout:
|
|
1154
|
+
timeout: Pe,
|
|
1152
1155
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1153
1156
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1154
|
-
shouldRetryFn: (
|
|
1157
|
+
shouldRetryFn: (F) => (F == null ? void 0 : F.message) !== "Could not connect" && F.status !== 429,
|
|
1155
1158
|
delayMs: 1e3
|
|
1156
|
-
}).catch((
|
|
1157
|
-
var
|
|
1158
|
-
throw v(
|
|
1159
|
-
}), [
|
|
1160
|
-
streamingManager:
|
|
1159
|
+
}).catch((F) => {
|
|
1160
|
+
var f, h;
|
|
1161
|
+
throw v(j.Maintenance), (h = (f = t.callbacks).onConnectionStateChange) == null || h.call(f, E.Fail), F;
|
|
1162
|
+
}), [_, {
|
|
1163
|
+
streamingManager: D,
|
|
1161
1164
|
chat: k
|
|
1162
|
-
}] = await Promise.all([w,
|
|
1163
|
-
k && k.id !== ((
|
|
1165
|
+
}] = await Promise.all([w, m]);
|
|
1166
|
+
k && k.id !== ((b = n.chat) == null ? void 0 : b.id) && ((W = (R = t.callbacks).onNewChat) == null || W.call(R, k.id)), n.streamingManager = D, n.socketManager = _, n.chat = k, a = !1, v((k == null ? void 0 : k.chat_mode) ?? t.mode ?? j.Functional);
|
|
1164
1167
|
}
|
|
1165
|
-
async function
|
|
1166
|
-
var u, w,
|
|
1167
|
-
(u =
|
|
1168
|
+
async function y() {
|
|
1169
|
+
var u, w, m, _;
|
|
1170
|
+
(u = n.socketManager) == null || u.disconnect(), await ((w = n.streamingManager) == null ? void 0 : w.disconnect()), delete n.streamingManager, delete n.socketManager, (_ = (m = t.callbacks).onConnectionStateChange) == null || _.call(m, E.Disconnected);
|
|
1168
1171
|
}
|
|
1169
1172
|
async function v(u) {
|
|
1170
|
-
var w,
|
|
1171
|
-
u !==
|
|
1173
|
+
var w, m;
|
|
1174
|
+
u !== n.chatMode && (l.track("agent-mode-change", {
|
|
1172
1175
|
mode: u
|
|
1173
|
-
}),
|
|
1176
|
+
}), n.chatMode = u, n.chatMode !== j.Functional && await y(), (m = (w = t.callbacks).onModeChange) == null || m.call(w, u));
|
|
1174
1177
|
}
|
|
1175
1178
|
return {
|
|
1176
1179
|
agent: d,
|
|
1177
1180
|
getStreamType: () => {
|
|
1178
1181
|
var u;
|
|
1179
|
-
return (u =
|
|
1182
|
+
return (u = n.streamingManager) == null ? void 0 : u.streamType;
|
|
1180
1183
|
},
|
|
1181
1184
|
getIsInterruptAvailable: () => {
|
|
1182
1185
|
var u;
|
|
1183
|
-
return ((u =
|
|
1186
|
+
return ((u = n.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
|
|
1184
1187
|
},
|
|
1185
|
-
starterMessages: ((
|
|
1186
|
-
getSTTToken: () =>
|
|
1188
|
+
starterMessages: ((M = d.knowledge) == null ? void 0 : M.starter_message) || [],
|
|
1189
|
+
getSTTToken: () => s.getSTTToken(d.id),
|
|
1187
1190
|
changeMode: v,
|
|
1188
|
-
enrichAnalytics:
|
|
1191
|
+
enrichAnalytics: l.enrich,
|
|
1189
1192
|
async connect() {
|
|
1190
1193
|
var u;
|
|
1191
|
-
await
|
|
1194
|
+
await C(!0), l.track("agent-chat", {
|
|
1192
1195
|
event: "connect",
|
|
1193
|
-
chatId: (u =
|
|
1196
|
+
chatId: (u = n.chat) == null ? void 0 : u.id,
|
|
1194
1197
|
agentId: d.id,
|
|
1195
|
-
mode:
|
|
1198
|
+
mode: n.chatMode
|
|
1196
1199
|
});
|
|
1197
1200
|
},
|
|
1198
1201
|
async reconnect() {
|
|
1199
1202
|
var u;
|
|
1200
|
-
await
|
|
1203
|
+
await y(), await C(!1), l.track("agent-chat", {
|
|
1201
1204
|
event: "reconnect",
|
|
1202
|
-
chatId: (u =
|
|
1205
|
+
chatId: (u = n.chat) == null ? void 0 : u.id,
|
|
1203
1206
|
agentId: d.id,
|
|
1204
|
-
mode:
|
|
1207
|
+
mode: n.chatMode
|
|
1205
1208
|
});
|
|
1206
1209
|
},
|
|
1207
1210
|
async disconnect() {
|
|
1208
1211
|
var u;
|
|
1209
|
-
await
|
|
1212
|
+
await y(), l.track("agent-chat", {
|
|
1210
1213
|
event: "disconnect",
|
|
1211
|
-
chatId: (u =
|
|
1214
|
+
chatId: (u = n.chat) == null ? void 0 : u.id,
|
|
1212
1215
|
agentId: d.id,
|
|
1213
|
-
mode:
|
|
1216
|
+
mode: n.chatMode
|
|
1214
1217
|
});
|
|
1215
1218
|
},
|
|
1216
1219
|
async chat(u) {
|
|
1217
|
-
var
|
|
1220
|
+
var D, k, T, N, x;
|
|
1218
1221
|
const w = () => {
|
|
1219
|
-
if (
|
|
1222
|
+
if (de(t.mode))
|
|
1220
1223
|
throw new H(`${t.mode} is enabled, chat is disabled`);
|
|
1221
1224
|
if (u.length >= 800)
|
|
1222
1225
|
throw new H("Message cannot be more than 800 characters");
|
|
1223
1226
|
if (u.length === 0)
|
|
1224
1227
|
throw new H("Message cannot be empty");
|
|
1225
|
-
if (
|
|
1228
|
+
if (n.chatMode === j.Maintenance)
|
|
1226
1229
|
throw new H("Chat is in maintenance mode");
|
|
1227
|
-
if (![
|
|
1228
|
-
if (!
|
|
1230
|
+
if (![j.TextOnly, j.Playground].includes(n.chatMode)) {
|
|
1231
|
+
if (!n.streamingManager)
|
|
1229
1232
|
throw new H("Streaming manager is not initialized");
|
|
1230
|
-
if (!
|
|
1233
|
+
if (!n.chat)
|
|
1231
1234
|
throw new H("Chat is not initialized");
|
|
1232
1235
|
}
|
|
1233
|
-
},
|
|
1234
|
-
var
|
|
1235
|
-
if (!
|
|
1236
|
-
const R = await
|
|
1236
|
+
}, m = async () => {
|
|
1237
|
+
var S, b;
|
|
1238
|
+
if (!n.chat) {
|
|
1239
|
+
const R = await we(d, s, l, n.chatMode, t.persistentChat);
|
|
1237
1240
|
if (!R.chat)
|
|
1238
|
-
throw new
|
|
1239
|
-
|
|
1241
|
+
throw new ke(n.chatMode, !!t.persistentChat);
|
|
1242
|
+
n.chat = R.chat, (b = (S = t.callbacks).onNewChat) == null || b.call(S, n.chat.id);
|
|
1240
1243
|
}
|
|
1241
|
-
return
|
|
1242
|
-
},
|
|
1244
|
+
return n.chat.id;
|
|
1245
|
+
}, _ = async (S, b) => ee(() => {
|
|
1243
1246
|
var R, W;
|
|
1244
|
-
return
|
|
1245
|
-
chatMode:
|
|
1246
|
-
streamId: (R =
|
|
1247
|
-
sessionId: (W =
|
|
1248
|
-
messages:
|
|
1249
|
-
matches:
|
|
1250
|
-
...
|
|
1251
|
-
}) =>
|
|
1247
|
+
return s.chat(d.id, b, {
|
|
1248
|
+
chatMode: n.chatMode,
|
|
1249
|
+
streamId: (R = n.streamingManager) == null ? void 0 : R.streamId,
|
|
1250
|
+
sessionId: (W = n.streamingManager) == null ? void 0 : W.sessionId,
|
|
1251
|
+
messages: S.map(({
|
|
1252
|
+
matches: F,
|
|
1253
|
+
...f
|
|
1254
|
+
}) => f)
|
|
1252
1255
|
}, {
|
|
1253
|
-
...
|
|
1256
|
+
...he(n.chatMode),
|
|
1254
1257
|
skipErrorHandler: !0
|
|
1255
1258
|
});
|
|
1256
1259
|
}, {
|
|
1257
1260
|
limit: 2,
|
|
1258
1261
|
shouldRetryFn: (R) => {
|
|
1259
|
-
var
|
|
1260
|
-
const W = (
|
|
1261
|
-
return !((h = R == null ? void 0 : R.message) == null ? void 0 : h.includes("Stream Error")) && !W ? ((K = (
|
|
1262
|
+
var f, h, A, K;
|
|
1263
|
+
const W = (f = R == null ? void 0 : R.message) == null ? void 0 : f.includes("missing or invalid session_id");
|
|
1264
|
+
return !((h = R == null ? void 0 : R.message) == null ? void 0 : h.includes("Stream Error")) && !W ? ((K = (A = t.callbacks).onError) == null || K.call(A, R), !1) : !0;
|
|
1262
1265
|
},
|
|
1263
1266
|
onRetry: async () => {
|
|
1264
|
-
await
|
|
1267
|
+
await y(), await C(!1);
|
|
1265
1268
|
}
|
|
1266
1269
|
});
|
|
1267
1270
|
try {
|
|
1268
|
-
I(), w(),
|
|
1271
|
+
I(), w(), n.messages.push({
|
|
1269
1272
|
id: V(),
|
|
1270
1273
|
role: "user",
|
|
1271
1274
|
content: u,
|
|
1272
|
-
created_at: new Date(
|
|
1273
|
-
}), (k = (
|
|
1274
|
-
const
|
|
1275
|
-
return
|
|
1275
|
+
created_at: new Date(J.update()).toISOString()
|
|
1276
|
+
}), (k = (D = t.callbacks).onNewMessage) == null || k.call(D, [...n.messages], "user");
|
|
1277
|
+
const S = await m(), b = await _([...n.messages], S);
|
|
1278
|
+
return n.messages.push({
|
|
1276
1279
|
id: V(),
|
|
1277
1280
|
role: "assistant",
|
|
1278
|
-
content:
|
|
1281
|
+
content: b.result || "",
|
|
1279
1282
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1280
|
-
context:
|
|
1281
|
-
matches:
|
|
1282
|
-
|
|
1283
|
-
}), n && E.videoId && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await ee(r.streamingManager, E.videoId)), f.track("agent-message-send", {
|
|
1283
|
+
context: b.context,
|
|
1284
|
+
matches: b.matches
|
|
1285
|
+
}), l.track("agent-message-send", {
|
|
1284
1286
|
event: "success",
|
|
1285
|
-
mode:
|
|
1286
|
-
messages:
|
|
1287
|
-
}),
|
|
1288
|
-
latency:
|
|
1289
|
-
mode:
|
|
1290
|
-
messages:
|
|
1291
|
-
})),
|
|
1292
|
-
} catch (
|
|
1293
|
-
throw
|
|
1287
|
+
mode: n.chatMode,
|
|
1288
|
+
messages: n.messages.length + 1
|
|
1289
|
+
}), b.result && ((N = (T = t.callbacks).onNewMessage) == null || N.call(T, [...n.messages], "answer"), l.track("agent-message-received", {
|
|
1290
|
+
latency: J.get(!0),
|
|
1291
|
+
mode: n.chatMode,
|
|
1292
|
+
messages: n.messages.length
|
|
1293
|
+
})), b;
|
|
1294
|
+
} catch (S) {
|
|
1295
|
+
throw ((x = n.messages[n.messages.length - 1]) == null ? void 0 : x.role) === "assistant" && n.messages.pop(), l.track("agent-message-send", {
|
|
1294
1296
|
event: "error",
|
|
1295
|
-
mode:
|
|
1296
|
-
messages:
|
|
1297
|
-
}),
|
|
1297
|
+
mode: n.chatMode,
|
|
1298
|
+
messages: n.messages.length
|
|
1299
|
+
}), S;
|
|
1298
1300
|
}
|
|
1299
1301
|
},
|
|
1300
|
-
rate(u, w,
|
|
1301
|
-
var k,
|
|
1302
|
-
const
|
|
1303
|
-
if (
|
|
1304
|
-
if (!
|
|
1302
|
+
rate(u, w, m) {
|
|
1303
|
+
var k, T, N, x;
|
|
1304
|
+
const _ = n.messages.find((S) => S.id === u);
|
|
1305
|
+
if (n.chat) {
|
|
1306
|
+
if (!_)
|
|
1305
1307
|
throw new Error("Message not found");
|
|
1306
1308
|
} else
|
|
1307
1309
|
throw new Error("Chat is not initialized");
|
|
1308
|
-
const
|
|
1309
|
-
return
|
|
1310
|
-
event:
|
|
1310
|
+
const D = ((k = _.matches) == null ? void 0 : k.map((S) => [S.document_id, S.id])) ?? [];
|
|
1311
|
+
return l.track("agent-rate", {
|
|
1312
|
+
event: m ? "update" : "create",
|
|
1311
1313
|
thumb: w === 1 ? "up" : "down",
|
|
1312
|
-
knowledge_id: ((
|
|
1313
|
-
mode:
|
|
1314
|
-
matches:
|
|
1314
|
+
knowledge_id: ((T = d.knowledge) == null ? void 0 : T.id) ?? "",
|
|
1315
|
+
mode: n.chatMode,
|
|
1316
|
+
matches: D,
|
|
1315
1317
|
score: w
|
|
1316
|
-
}),
|
|
1317
|
-
knowledge_id: ((
|
|
1318
|
+
}), m ? s.updateRating(d.id, n.chat.id, m, {
|
|
1319
|
+
knowledge_id: ((N = d.knowledge) == null ? void 0 : N.id) ?? "",
|
|
1318
1320
|
message_id: u,
|
|
1319
|
-
matches:
|
|
1321
|
+
matches: D,
|
|
1320
1322
|
score: w
|
|
1321
|
-
}) :
|
|
1322
|
-
knowledge_id: ((
|
|
1323
|
+
}) : s.createRating(d.id, n.chat.id, {
|
|
1324
|
+
knowledge_id: ((x = d.knowledge) == null ? void 0 : x.id) ?? "",
|
|
1323
1325
|
message_id: u,
|
|
1324
|
-
matches:
|
|
1326
|
+
matches: D,
|
|
1325
1327
|
score: w
|
|
1326
1328
|
});
|
|
1327
1329
|
},
|
|
1328
1330
|
deleteRate(u) {
|
|
1329
1331
|
var w;
|
|
1330
|
-
if (!
|
|
1332
|
+
if (!n.chat)
|
|
1331
1333
|
throw new Error("Chat is not initialized");
|
|
1332
|
-
return
|
|
1334
|
+
return l.track("agent-rate-delete", {
|
|
1333
1335
|
type: "text",
|
|
1334
|
-
chat_id: (w =
|
|
1336
|
+
chat_id: (w = n.chat) == null ? void 0 : w.id,
|
|
1335
1337
|
id: u,
|
|
1336
|
-
mode:
|
|
1337
|
-
}),
|
|
1338
|
+
mode: n.chatMode
|
|
1339
|
+
}), s.deleteRating(d.id, n.chat.id, u);
|
|
1338
1340
|
},
|
|
1339
1341
|
async speak(u) {
|
|
1340
|
-
var
|
|
1342
|
+
var D, k, T;
|
|
1341
1343
|
function w() {
|
|
1342
1344
|
if (typeof u == "string") {
|
|
1343
1345
|
if (!d.presenter.voice)
|
|
@@ -1361,87 +1363,77 @@ async function St(e, t) {
|
|
|
1361
1363
|
}
|
|
1362
1364
|
return u;
|
|
1363
1365
|
}
|
|
1364
|
-
const
|
|
1365
|
-
if (
|
|
1366
|
+
const m = w();
|
|
1367
|
+
if (l.track("agent-speak", m), J.update(), n.messages && m.type === "text" && (n.messages.push({
|
|
1366
1368
|
id: V(),
|
|
1367
1369
|
role: "assistant",
|
|
1368
|
-
content:
|
|
1369
|
-
created_at: new Date(
|
|
1370
|
-
}), (k = (
|
|
1370
|
+
content: m.input,
|
|
1371
|
+
created_at: new Date(J.get(!0)).toISOString()
|
|
1372
|
+
}), (k = (D = t.callbacks).onNewMessage) == null || k.call(D, [...n.messages], "answer")), ze(n.chatMode))
|
|
1371
1373
|
return {
|
|
1372
1374
|
duration: 0,
|
|
1373
1375
|
video_id: "",
|
|
1374
1376
|
status: "success"
|
|
1375
1377
|
};
|
|
1376
|
-
if (!
|
|
1378
|
+
if (!n.streamingManager)
|
|
1377
1379
|
throw new Error("Please connect to the agent first");
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
});
|
|
1387
|
-
return s = !1, r.messages[r.messages.length - 1].videoId = y.video_id, n && y.video_id && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await ee(r.streamingManager, y.video_id)), (T = (M = t.callbacks).onNewMessage) == null || T.call(M, [...r.messages], "answer"), y;
|
|
1388
|
-
} finally {
|
|
1389
|
-
s = !1;
|
|
1390
|
-
}
|
|
1380
|
+
return n.streamingManager.speak({
|
|
1381
|
+
script: m,
|
|
1382
|
+
metadata: {
|
|
1383
|
+
chat_id: (T = n.chat) == null ? void 0 : T.id,
|
|
1384
|
+
agent_id: d.id
|
|
1385
|
+
}
|
|
1386
|
+
});
|
|
1391
1387
|
},
|
|
1392
1388
|
async interrupt({
|
|
1393
1389
|
type: u
|
|
1394
1390
|
}) {
|
|
1395
|
-
var
|
|
1396
|
-
|
|
1397
|
-
|
|
1391
|
+
var m, _, D, k, T;
|
|
1392
|
+
Ve(n.streamingManager, (m = n.streamingManager) == null ? void 0 : m.streamType, r);
|
|
1393
|
+
const w = n.messages[n.messages.length - 1];
|
|
1394
|
+
l.track("agent-video-interrupt", {
|
|
1398
1395
|
type: u || "click",
|
|
1399
|
-
stream_id: (
|
|
1396
|
+
stream_id: (_ = n.streamingManager) == null ? void 0 : _.streamId,
|
|
1400
1397
|
agent_id: d.id,
|
|
1401
1398
|
owner_id: d.owner_id,
|
|
1402
|
-
video_duration_to_interrupt:
|
|
1403
|
-
message_duration_to_interrupt:
|
|
1404
|
-
chat_id: (
|
|
1405
|
-
mode:
|
|
1406
|
-
|
|
1407
|
-
}), S) {
|
|
1408
|
-
n = !0;
|
|
1409
|
-
return;
|
|
1410
|
-
}
|
|
1411
|
-
w.interrupted = !0, (T = (M = t.callbacks).onNewMessage) == null || T.call(M, [...r.messages], "answer"), ee(r.streamingManager, w.videoId);
|
|
1399
|
+
video_duration_to_interrupt: te.get(!0),
|
|
1400
|
+
message_duration_to_interrupt: J.get(!0),
|
|
1401
|
+
chat_id: (D = n.chat) == null ? void 0 : D.id,
|
|
1402
|
+
mode: n.chatMode
|
|
1403
|
+
}), w.interrupted = !0, (T = (k = t.callbacks).onNewMessage) == null || T.call(k, [...n.messages], "answer"), Xe(n.streamingManager, r);
|
|
1412
1404
|
}
|
|
1413
1405
|
};
|
|
1414
1406
|
}
|
|
1415
1407
|
function Et(e, t, a) {
|
|
1416
1408
|
const {
|
|
1417
|
-
getById:
|
|
1418
|
-
} =
|
|
1419
|
-
return
|
|
1409
|
+
getById: r
|
|
1410
|
+
} = fe(t, a || O);
|
|
1411
|
+
return r(e);
|
|
1420
1412
|
}
|
|
1421
1413
|
export {
|
|
1422
1414
|
X as AgentActivityState,
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1415
|
+
_e as AgentStatus,
|
|
1416
|
+
ke as ChatCreationFailed,
|
|
1417
|
+
j as ChatMode,
|
|
1418
|
+
De as ChatModeDowngraded,
|
|
1427
1419
|
q as ChatProgress,
|
|
1428
|
-
|
|
1420
|
+
E as ConnectionState,
|
|
1429
1421
|
Q as ConnectivityState,
|
|
1430
|
-
|
|
1431
|
-
|
|
1422
|
+
Te as DocumentType,
|
|
1423
|
+
Me as KnowledgeType,
|
|
1432
1424
|
Se as PlanGroup,
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1425
|
+
be as Providers,
|
|
1426
|
+
Ee as RateState,
|
|
1427
|
+
B as StreamEvents,
|
|
1436
1428
|
U as StreamType,
|
|
1437
1429
|
p as StreamingState,
|
|
1438
|
-
|
|
1439
|
-
|
|
1430
|
+
Ie as Subject,
|
|
1431
|
+
Re as UserPlan,
|
|
1440
1432
|
H as ValidationError,
|
|
1441
|
-
|
|
1433
|
+
oe as VideoType,
|
|
1442
1434
|
Ae as VoiceAccess,
|
|
1443
|
-
|
|
1444
|
-
|
|
1435
|
+
Ce as WsError,
|
|
1436
|
+
_t as createAgentManager,
|
|
1445
1437
|
Et as getAgent,
|
|
1446
|
-
|
|
1438
|
+
je as mapVideoType
|
|
1447
1439
|
};
|