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