@d-id/client-sdk 1.1.1-staging.2 → 1.1.1-staging.4
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 +665 -669
- package/dist/index.umd.cjs +1 -1
- package/dist/src/services/chat/index.d.ts +2 -1
- package/dist/src/services/interrupt/index.d.ts +1 -1
- package/dist/src/types/entities/agents/chat.d.ts +2 -1
- package/dist/src/types/entities/agents/manager.d.ts +6 -0
- package/dist/src/types/stream/stream.d.ts +5 -0
- package/dist/src/utils/chat.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var ve = Object.defineProperty;
|
|
2
|
+
var ke = (e, t, n) => t in e ? ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var Q = (e, t, n) => (ke(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
|
+
Q(this, "kind");
|
|
15
|
+
Q(this, "description");
|
|
16
|
+
Q(this, "error");
|
|
17
|
+
this.kind = n, this.description = r, this.error = o;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
class
|
|
20
|
+
class De 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 Ce 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
|
+
Q(this, "key");
|
|
43
43
|
this.key = r;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
class
|
|
46
|
+
class Re 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 Se = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Se || {}),
|
|
55
|
-
const
|
|
54
|
+
var Se = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Se || {}), Ie = /* @__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))(Ie || {}), _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 || {}), M = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(M || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Me = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Me || {}), Te = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Te || {}), je = /* @__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))(je || {}), ce = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ce || {});
|
|
55
|
+
const be = (e) => {
|
|
56
56
|
switch (e) {
|
|
57
57
|
case "clip":
|
|
58
58
|
return "clip";
|
|
@@ -62,15 +62,15 @@ const Pe = (e) => {
|
|
|
62
62
|
throw new Error(`Unknown video type: ${e}`);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
var
|
|
66
|
-
const $e = 45 * 1e3,
|
|
65
|
+
var h = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(h || {}), O = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), j = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Ae = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Ae || {}), Pe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Pe || {});
|
|
66
|
+
const $e = 45 * 1e3, Be = "X-Playground-Chat", Z = "https://api.d-id.com", Le = "wss://notifications.d-id.com", ze = "79f81a83a67430be2bc0fd61042b8faa", de = (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
|
+
}, Ne = (e) => [M.TextOnly, M.Playground, M.Maintenance].includes(e), ue = (e) => e && [M.DirectPlayback, M.Off].includes(e);
|
|
70
|
+
function xe(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)
|
|
@@ -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
|
+
} = xe(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 de(n.delayMs), n.onRetry(i);
|
|
103
103
|
}
|
|
104
104
|
throw r;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
106
|
+
function le() {
|
|
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 Fe = V();
|
|
115
|
+
function fe(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}.${le()}_${Fe}`;
|
|
122
122
|
throw new Error(`Unknown auth type: ${e}`);
|
|
123
123
|
}
|
|
124
|
-
const
|
|
124
|
+
const Je = (e) => te(e, {
|
|
125
125
|
limit: 3,
|
|
126
126
|
delayMs: 1e3,
|
|
127
127
|
timeout: 0,
|
|
128
128
|
shouldRetryFn: (t) => t.status === 429
|
|
129
129
|
});
|
|
130
|
-
function ae(e, t =
|
|
131
|
-
const r = async (
|
|
130
|
+
function ae(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 Je(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
136
|
+
...a,
|
|
137
137
|
headers: {
|
|
138
|
-
...
|
|
139
|
-
Authorization:
|
|
138
|
+
...a.headers,
|
|
139
|
+
Authorization: fe(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 u = await s.text().catch(() => `Failed to fetch with status ${s.status}`);
|
|
145
|
+
const d = new Error(u);
|
|
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
|
|
184
|
+
function me(e, t = Z, n) {
|
|
185
185
|
const r = ae(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 ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
223
|
+
function We(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: ge(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 Ue(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: ge(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 Ke = (e) => e.reduce((t, n) => t + n, 0), ie = (e) => Ke(e) / e.length;
|
|
261
|
+
function He(e, t, n) {
|
|
262
|
+
var s, u, 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
|
+
...(u = o == null ? void 0 : o.script) == null ? void 0 : u.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
|
-
let
|
|
289
|
-
const
|
|
290
|
-
function
|
|
288
|
+
let ee = {};
|
|
289
|
+
const qe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
290
|
+
function Ve(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 || le(),
|
|
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(qe, c).then((a) => a.json());
|
|
336
|
+
} catch (a) {
|
|
337
|
+
return console.error(a);
|
|
338
338
|
}
|
|
339
339
|
},
|
|
340
|
-
linkTrack(n, r,
|
|
341
|
-
|
|
340
|
+
linkTrack(n, r, o, i) {
|
|
341
|
+
ee[n] || (ee[n] = {
|
|
342
342
|
events: {},
|
|
343
343
|
resolvedDependencies: []
|
|
344
|
-
}), i.includes(
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
344
|
+
}), i.includes(o) || i.push(o);
|
|
345
|
+
const c = ee[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((u, d) => c.events[d] ? {
|
|
350
|
+
...u,
|
|
351
|
+
...c.events[d].props
|
|
352
|
+
} : u, {});
|
|
353
|
+
this.track(n, s), c.resolvedDependencies = c.resolvedDependencies.filter((u) => !i.includes(u)), i.forEach((u) => {
|
|
354
|
+
delete c.events[u];
|
|
355
355
|
});
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
|
-
function
|
|
360
|
+
function he() {
|
|
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 = he(), re = he();
|
|
369
|
+
function we(e) {
|
|
370
|
+
return e === M.Playground ? {
|
|
371
371
|
headers: {
|
|
372
|
-
[
|
|
372
|
+
[Be]: "true"
|
|
373
373
|
}
|
|
374
374
|
} : {};
|
|
375
375
|
}
|
|
376
|
-
async function
|
|
376
|
+
async function pe(e, t, n, r, o = !1, i) {
|
|
377
377
|
try {
|
|
378
|
-
return !i && r
|
|
379
|
-
persist:
|
|
380
|
-
},
|
|
378
|
+
return !i && !ue(r) && (i = await t.newChat(e.id, {
|
|
379
|
+
persist: o
|
|
380
|
+
}, we(r)), n.track("agent-chat", {
|
|
381
381
|
event: "created",
|
|
382
382
|
chat_id: i.id,
|
|
383
383
|
agent_id: e.id,
|
|
@@ -386,90 +386,90 @@ 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 Xe(e) {
|
|
401
401
|
return e && e.length > 0 ? e : [];
|
|
402
402
|
}
|
|
403
|
-
function
|
|
403
|
+
function Ye(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 !== W.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 Qe(e, t) {
|
|
414
414
|
const n = {
|
|
415
|
-
type:
|
|
415
|
+
type: j.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 Oe(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: u = null
|
|
432
|
+
} = r || {}, d = new WebSocket(`${o}?authorization=${fe(i)}`);
|
|
433
|
+
d.onmessage = c, d.onclose = s, d.onerror = (y) => {
|
|
434
|
+
console.error(y), u == null || u("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 Ze(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 Oe(e);
|
|
448
|
+
} catch (o) {
|
|
449
449
|
if (r === t)
|
|
450
|
-
throw
|
|
451
|
-
await
|
|
450
|
+
throw o;
|
|
451
|
+
await de(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 Ge(e, t, n) {
|
|
456
|
+
const r = n != null && n.onMessage ? [n.onMessage] : [], o = await Ze({
|
|
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 Re(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
|
}
|
|
@@ -481,57 +481,57 @@ function et(e) {
|
|
|
481
481
|
n += e[t++];
|
|
482
482
|
return n;
|
|
483
483
|
}
|
|
484
|
-
function tt(e, t, n, r,
|
|
484
|
+
function tt(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 = et(n);
|
|
494
|
+
(i.content !== s || e === q.Answer) && (i.content = s, o == null || o([...r.messages], e));
|
|
495
495
|
}
|
|
496
|
-
function rt(e, t, n, r,
|
|
496
|
+
function rt(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
|
-
tt(
|
|
500
|
+
onMessage: (c, a) => {
|
|
501
|
+
var s, u;
|
|
502
|
+
if ("content" in a)
|
|
503
|
+
tt(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 = j, y = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], A = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], P = He(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) && ((u = (s = n.callbacks).onError) == null || u.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
530
|
function nt(e, t, n, r) {
|
|
531
|
-
const
|
|
531
|
+
const o = ae(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
567
|
function at(e, t, n, r) {
|
|
568
|
-
const
|
|
568
|
+
const o = ae(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,30 +577,30 @@ 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);
|
|
593
|
+
},
|
|
594
|
+
sendStreamRequest(i, c, a, s) {
|
|
595
|
+
return o.post(`/streams/${i}`, {
|
|
596
|
+
session_id: c,
|
|
597
|
+
...a
|
|
598
|
+
}, s);
|
|
599
599
|
},
|
|
600
|
-
close(i,
|
|
601
|
-
return
|
|
602
|
-
session_id:
|
|
603
|
-
},
|
|
600
|
+
close(i, c, a) {
|
|
601
|
+
return o.delete(`/streams/${i}`, {
|
|
602
|
+
session_id: c
|
|
603
|
+
}, a);
|
|
604
604
|
}
|
|
605
605
|
};
|
|
606
606
|
}
|
|
@@ -629,10 +629,10 @@ function st(e) {
|
|
|
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
|
}
|
|
@@ -662,88 +662,88 @@ function ot(e) {
|
|
|
662
662
|
return {};
|
|
663
663
|
}
|
|
664
664
|
function ct(e, t, n) {
|
|
665
|
-
const r = e.map((
|
|
666
|
-
timestamp:
|
|
665
|
+
const r = e.map((s, u) => u === 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 * u / 1e3,
|
|
702
|
+
rtt: s.rtt,
|
|
703
|
+
bytesReceived: s.bytesReceived - e[u - 1].bytesReceived,
|
|
704
|
+
bitrate: (s.bytesReceived - e[u - 1].bytesReceived) * 8 / (t / 1e3),
|
|
705
|
+
packetsReceived: s.packetsReceived - e[u - 1].packetsReceived,
|
|
706
|
+
packetsLost: s.packetsLost - e[u - 1].packetsLost,
|
|
707
|
+
framesDropped: s.framesDropped - e[u - 1].framesDropped,
|
|
708
|
+
framesDecoded: s.framesDecoded - e[u - 1].framesDecoded,
|
|
709
|
+
jitter: s.jitter,
|
|
710
|
+
jitterBufferDelay: s.jitterBufferDelay - e[u - 1].jitterBufferDelay,
|
|
711
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount - e[u - 1].jitterBufferEmittedCount,
|
|
712
|
+
avgJitterDelayInInterval: (s.jitterBufferDelay - e[u - 1].jitterBufferDelay) / (s.jitterBufferEmittedCount - e[u - 1].jitterBufferEmittedCount),
|
|
713
|
+
framesPerSecond: s.framesPerSecond,
|
|
714
|
+
freezeCount: s.freezeCount - e[u - 1].freezeCount,
|
|
715
|
+
freezeDuration: s.freezeDuration - e[u - 1].freezeDuration
|
|
716
|
+
}), o = st(r), i = o.reduce((s, u) => s + (u.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(...
|
|
719
|
+
anomalies: o,
|
|
720
|
+
minRtt: Math.min(...a),
|
|
721
|
+
avgRtt: ie(a),
|
|
722
|
+
maxRtt: Math.max(...a),
|
|
723
723
|
aggregateReport: it(e[0], e[e.length - 1], i),
|
|
724
|
-
minJitterDelayInInterval: Math.min(...
|
|
725
|
-
maxJitterDelayInInterval: Math.max(...
|
|
726
|
-
avgJitterDelayInInterval:
|
|
724
|
+
minJitterDelayInInterval: Math.min(...c),
|
|
725
|
+
maxJitterDelayInInterval: Math.max(...c),
|
|
726
|
+
avgJitterDelayInInterval: ie(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 ne = 100, dt = Math.max(Math.ceil(400 / ne), 1),
|
|
732
|
+
const ne = 100, dt = Math.max(Math.ceil(400 / ne), 1), ut = 0.25, lt = 0.28;
|
|
733
733
|
function ft() {
|
|
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, u = s - e > 0;
|
|
745
|
+
return e = s, {
|
|
746
|
+
isReceiving: u,
|
|
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 mt(e, t, n, r,
|
|
758
|
-
let
|
|
759
|
-
const
|
|
757
|
+
function mt(e, t, n, r, o, i = !1) {
|
|
758
|
+
let c = [], a, s = 0, u = !1, d = O.Unknown, y = O.Unknown, A = 0, P = 0;
|
|
759
|
+
const x = ft();
|
|
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: R,
|
|
763
|
+
avgJitterDelayInInterval: U,
|
|
764
|
+
freezeCount: K
|
|
765
|
+
} = x(F), T = ot(F);
|
|
766
|
+
if (R)
|
|
767
|
+
s = 0, A = K - P, y = U < ut ? O.Strong : U > lt && A > 1 ? O.Weak : d, y !== d && (o == null || o(y), d = y, P += A, A = 0), u || (r == null || r(h.Start), a = c[c.length - 1], c = [], u = !0), c.push(T);
|
|
768
|
+
else if (u && (s++, s >= dt)) {
|
|
769
|
+
const l = ct(c, ne, a);
|
|
770
|
+
r == null || r(h.Stop, l), t() || n(), P = K, u = !1;
|
|
771
771
|
}
|
|
772
772
|
}, ne);
|
|
773
773
|
}
|
|
774
|
-
let
|
|
775
|
-
const
|
|
776
|
-
function
|
|
774
|
+
let ye = !1;
|
|
775
|
+
const b = (e, t) => ye && console.log(e, t), gt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
776
|
+
function se(e) {
|
|
777
777
|
switch (e) {
|
|
778
778
|
case "connected":
|
|
779
|
-
return
|
|
779
|
+
return I.Connected;
|
|
780
780
|
case "checking":
|
|
781
|
-
return
|
|
781
|
+
return I.Connecting;
|
|
782
782
|
case "failed":
|
|
783
|
-
return
|
|
783
|
+
return I.Fail;
|
|
784
784
|
case "new":
|
|
785
|
-
return
|
|
785
|
+
return I.New;
|
|
786
786
|
case "closed":
|
|
787
|
-
return
|
|
787
|
+
return I.Closed;
|
|
788
788
|
case "disconnected":
|
|
789
|
-
return
|
|
789
|
+
return I.Disconnected;
|
|
790
790
|
case "completed":
|
|
791
|
-
return
|
|
791
|
+
return I.Completed;
|
|
792
792
|
default:
|
|
793
|
-
return
|
|
793
|
+
return I.New;
|
|
794
794
|
}
|
|
795
795
|
}
|
|
796
796
|
function ht(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
|
|
@@ -821,31 +821,31 @@ function wt({
|
|
|
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
826
|
function pt({
|
|
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 oe({
|
|
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 === W.Legacy ? wt({
|
|
844
844
|
statsSignal: e,
|
|
845
845
|
dataChannelSignal: t,
|
|
846
846
|
onVideoStateChange: n,
|
|
847
847
|
report: i
|
|
848
|
-
}) :
|
|
848
|
+
}) : o === W.Fluent && pt({
|
|
849
849
|
statsSignal: e,
|
|
850
850
|
dataChannelSignal: t,
|
|
851
851
|
onVideoStateChange: n,
|
|
@@ -856,174 +856,181 @@ function de({
|
|
|
856
856
|
async function yt(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
|
-
|
|
863
|
+
var J;
|
|
864
|
+
ye = n;
|
|
865
|
+
let a = !1, s = !1, u = h.Stop, d = h.Stop;
|
|
865
866
|
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
|
-
|
|
880
|
-
|
|
881
|
-
|
|
867
|
+
startConnection: y,
|
|
868
|
+
sendStreamRequest: A,
|
|
869
|
+
close: P,
|
|
870
|
+
createStream: x,
|
|
871
|
+
addIceCandidate: F
|
|
872
|
+
} = t.videoType === ce.Clip ? nt(o, i, e, r.onError) : at(o, i, e, r.onError), {
|
|
873
|
+
id: R,
|
|
874
|
+
offer: U,
|
|
875
|
+
ice_servers: K,
|
|
876
|
+
session_id: T,
|
|
877
|
+
fluent: l,
|
|
878
|
+
interrupt_enabled: w
|
|
879
|
+
} = await x(t);
|
|
880
|
+
(J = r.onStreamCreated) == null || J.call(r, {
|
|
881
|
+
stream_id: R,
|
|
882
|
+
session_id: T,
|
|
883
|
+
agent_id: e
|
|
884
|
+
});
|
|
885
|
+
const m = new gt({
|
|
886
|
+
iceServers: K
|
|
887
|
+
}), D = m.createDataChannel("JanusDataChannel");
|
|
888
|
+
if (!T)
|
|
882
889
|
throw new Error("Could not create session_id");
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
"stream-type":
|
|
890
|
+
const v = l ? W.Fluent : W.Legacy;
|
|
891
|
+
c.enrich({
|
|
892
|
+
"stream-type": v
|
|
886
893
|
});
|
|
887
|
-
const
|
|
894
|
+
const p = t.stream_warmup && !l, _ = () => a, $ = () => {
|
|
888
895
|
var f;
|
|
889
|
-
|
|
890
|
-
},
|
|
891
|
-
statsSignal:
|
|
892
|
-
dataChannelSignal:
|
|
896
|
+
a = !0, s && ((f = r.onConnectionStateChange) == null || f.call(r, I.Connected));
|
|
897
|
+
}, B = mt(m, _, $, (f, g) => oe({
|
|
898
|
+
statsSignal: d = f,
|
|
899
|
+
dataChannelSignal: v === W.Legacy ? u : void 0,
|
|
893
900
|
onVideoStateChange: r.onVideoStateChange,
|
|
894
901
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
895
|
-
report:
|
|
896
|
-
streamType:
|
|
902
|
+
report: g,
|
|
903
|
+
streamType: v
|
|
897
904
|
}), (f) => {
|
|
898
|
-
var
|
|
899
|
-
return (
|
|
900
|
-
},
|
|
901
|
-
|
|
902
|
-
var
|
|
903
|
-
|
|
905
|
+
var g;
|
|
906
|
+
return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
|
|
907
|
+
}, p);
|
|
908
|
+
m.onicecandidate = (f) => {
|
|
909
|
+
var g;
|
|
910
|
+
b("peerConnection.onicecandidate", f);
|
|
904
911
|
try {
|
|
905
|
-
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ?
|
|
912
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? F(R, {
|
|
906
913
|
candidate: f.candidate.candidate,
|
|
907
914
|
sdpMid: f.candidate.sdpMid,
|
|
908
915
|
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
909
|
-
},
|
|
916
|
+
}, T) : F(R, {
|
|
910
917
|
candidate: null
|
|
911
|
-
},
|
|
912
|
-
} catch (
|
|
913
|
-
(
|
|
914
|
-
streamId:
|
|
918
|
+
}, T);
|
|
919
|
+
} catch (S) {
|
|
920
|
+
(g = r.onError) == null || g.call(r, S, {
|
|
921
|
+
streamId: R
|
|
915
922
|
});
|
|
916
923
|
}
|
|
917
|
-
},
|
|
918
|
-
|
|
924
|
+
}, D.onopen = () => {
|
|
925
|
+
s = !0, (!p || a) && $();
|
|
919
926
|
};
|
|
920
|
-
const
|
|
921
|
-
var
|
|
922
|
-
(
|
|
927
|
+
const k = (f) => {
|
|
928
|
+
var g;
|
|
929
|
+
(g = r.onVideoIdChange) == null || g.call(r, f);
|
|
923
930
|
};
|
|
924
|
-
function
|
|
925
|
-
if (f ===
|
|
926
|
-
const
|
|
927
|
-
S
|
|
931
|
+
function E(f, g) {
|
|
932
|
+
if (f === j.StreamStarted && typeof g == "object" && "metadata" in g) {
|
|
933
|
+
const S = g.metadata;
|
|
934
|
+
k(S.videoId);
|
|
928
935
|
}
|
|
929
|
-
f ===
|
|
930
|
-
statsSignal:
|
|
931
|
-
dataChannelSignal:
|
|
936
|
+
f === j.StreamDone && k(null), u = f === j.StreamStarted ? h.Start : h.Stop, oe({
|
|
937
|
+
statsSignal: v === W.Legacy ? d : void 0,
|
|
938
|
+
dataChannelSignal: u,
|
|
932
939
|
onVideoStateChange: r.onVideoStateChange,
|
|
933
940
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
934
|
-
streamType:
|
|
941
|
+
streamType: v
|
|
935
942
|
});
|
|
936
943
|
}
|
|
937
|
-
function
|
|
938
|
-
const
|
|
939
|
-
|
|
940
|
-
streamMetadata:
|
|
941
|
-
}),
|
|
944
|
+
function C(f, g) {
|
|
945
|
+
const S = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
|
|
946
|
+
S && c.enrich({
|
|
947
|
+
streamMetadata: S
|
|
948
|
+
}), c.track("agent-chat", {
|
|
942
949
|
event: "ready"
|
|
943
950
|
});
|
|
944
951
|
}
|
|
945
|
-
const
|
|
946
|
-
[
|
|
947
|
-
[
|
|
948
|
-
[
|
|
952
|
+
const L = {
|
|
953
|
+
[j.StreamStarted]: E,
|
|
954
|
+
[j.StreamDone]: E,
|
|
955
|
+
[j.StreamReady]: C
|
|
949
956
|
};
|
|
950
|
-
|
|
951
|
-
var
|
|
957
|
+
D.onmessage = (f) => {
|
|
958
|
+
var Y;
|
|
952
959
|
const {
|
|
953
|
-
subject:
|
|
954
|
-
data:
|
|
960
|
+
subject: g,
|
|
961
|
+
data: S
|
|
955
962
|
} = ht(f.data);
|
|
956
|
-
(
|
|
957
|
-
},
|
|
958
|
-
var
|
|
959
|
-
|
|
960
|
-
const f =
|
|
961
|
-
f !==
|
|
962
|
-
},
|
|
963
|
-
var
|
|
964
|
-
|
|
965
|
-
}, await
|
|
966
|
-
const
|
|
967
|
-
return
|
|
963
|
+
(Y = L[g]) == null || Y.call(L, g, S);
|
|
964
|
+
}, m.oniceconnectionstatechange = () => {
|
|
965
|
+
var g;
|
|
966
|
+
b("peerConnection.oniceconnectionstatechange => " + m.iceConnectionState);
|
|
967
|
+
const f = se(m.iceConnectionState);
|
|
968
|
+
f !== I.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
|
|
969
|
+
}, m.ontrack = (f) => {
|
|
970
|
+
var g;
|
|
971
|
+
b("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
|
|
972
|
+
}, await m.setRemoteDescription(U), b("set remote description OK");
|
|
973
|
+
const z = await m.createAnswer();
|
|
974
|
+
return b("create answer OK"), await m.setLocalDescription(z), b("set local description OK"), await y(R, z, T), b("start connection OK"), {
|
|
968
975
|
/**
|
|
969
976
|
* Method to send request to server to get clip or talk depend on you payload
|
|
970
977
|
* @param payload
|
|
971
978
|
*/
|
|
972
979
|
speak(f) {
|
|
973
|
-
return
|
|
980
|
+
return A(R, T, f);
|
|
974
981
|
},
|
|
975
982
|
/**
|
|
976
983
|
* Method to close RTC connection
|
|
977
984
|
*/
|
|
978
985
|
async disconnect() {
|
|
979
986
|
var f;
|
|
980
|
-
if (
|
|
981
|
-
const
|
|
982
|
-
if (
|
|
983
|
-
if (
|
|
984
|
-
clearInterval(
|
|
987
|
+
if (R) {
|
|
988
|
+
const g = se(m.iceConnectionState);
|
|
989
|
+
if (m) {
|
|
990
|
+
if (g === I.New) {
|
|
991
|
+
clearInterval(B);
|
|
985
992
|
return;
|
|
986
993
|
}
|
|
987
|
-
|
|
994
|
+
m.close(), m.oniceconnectionstatechange = null, m.onnegotiationneeded = null, m.onicecandidate = null, m.ontrack = null;
|
|
988
995
|
}
|
|
989
996
|
try {
|
|
990
|
-
|
|
997
|
+
g === I.Connected && await P(R, T).catch((S) => {
|
|
991
998
|
});
|
|
992
|
-
} catch (
|
|
993
|
-
|
|
999
|
+
} catch (S) {
|
|
1000
|
+
b("Error on close stream connection", S);
|
|
994
1001
|
}
|
|
995
|
-
(f = r.onAgentActivityStateChange) == null || f.call(r,
|
|
1002
|
+
(f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval(B);
|
|
996
1003
|
}
|
|
997
1004
|
},
|
|
998
1005
|
/**
|
|
999
1006
|
* Method to send data channel messages to the server
|
|
1000
1007
|
*/
|
|
1001
1008
|
sendDataChannelMessage(f) {
|
|
1002
|
-
var
|
|
1003
|
-
if (!
|
|
1004
|
-
|
|
1005
|
-
streamId:
|
|
1009
|
+
var g, S;
|
|
1010
|
+
if (!a || D.readyState !== "open") {
|
|
1011
|
+
b("Data channel is not ready for sending messages"), (g = r.onError) == null || g.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1012
|
+
streamId: R
|
|
1006
1013
|
});
|
|
1007
1014
|
return;
|
|
1008
1015
|
}
|
|
1009
1016
|
try {
|
|
1010
|
-
|
|
1011
|
-
} catch (
|
|
1012
|
-
|
|
1013
|
-
streamId:
|
|
1017
|
+
D.send(f);
|
|
1018
|
+
} catch (Y) {
|
|
1019
|
+
b("Error sending data channel message", Y), (S = r.onError) == null || S.call(r, Y, {
|
|
1020
|
+
streamId: R
|
|
1014
1021
|
});
|
|
1015
1022
|
}
|
|
1016
1023
|
},
|
|
1017
1024
|
/**
|
|
1018
1025
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1019
1026
|
*/
|
|
1020
|
-
sessionId:
|
|
1027
|
+
sessionId: T,
|
|
1021
1028
|
/**
|
|
1022
1029
|
* Id of current RTC stream
|
|
1023
1030
|
*/
|
|
1024
|
-
streamId:
|
|
1025
|
-
streamType:
|
|
1026
|
-
interruptAvailable:
|
|
1031
|
+
streamId: R,
|
|
1032
|
+
streamType: v,
|
|
1033
|
+
interruptAvailable: w
|
|
1027
1034
|
};
|
|
1028
1035
|
}
|
|
1029
1036
|
function vt(e, t) {
|
|
@@ -1031,7 +1038,7 @@ function vt(e, t) {
|
|
|
1031
1038
|
streamOptions: n
|
|
1032
1039
|
} = t ?? {};
|
|
1033
1040
|
return {
|
|
1034
|
-
videoType:
|
|
1041
|
+
videoType: be(e.presenter.type),
|
|
1035
1042
|
output_resolution: n == null ? void 0 : n.outputResolution,
|
|
1036
1043
|
session_timeout: n == null ? void 0 : n.sessionTimeout,
|
|
1037
1044
|
stream_warmup: n == null ? void 0 : n.streamWarmup,
|
|
@@ -1039,161 +1046,161 @@ function vt(e, t) {
|
|
|
1039
1046
|
fluent: n == null ? void 0 : n.fluent
|
|
1040
1047
|
};
|
|
1041
1048
|
}
|
|
1042
|
-
function kt(e, t, n, r,
|
|
1043
|
-
|
|
1049
|
+
function kt(e, t, n, r, o) {
|
|
1050
|
+
o === W.Fluent ? Dt(e, t, n, r, o) : Rt(e, t, n, r, o);
|
|
1044
1051
|
}
|
|
1045
|
-
function Dt(e, t, n, r,
|
|
1046
|
-
e ===
|
|
1052
|
+
function Dt(e, t, n, r, o) {
|
|
1053
|
+
e === h.Start ? r.track("stream-session", {
|
|
1047
1054
|
event: "start",
|
|
1048
|
-
"stream-type":
|
|
1049
|
-
}) : e ===
|
|
1055
|
+
"stream-type": o
|
|
1056
|
+
}) : e === h.Stop && r.track("stream-session", {
|
|
1050
1057
|
event: "stop",
|
|
1051
1058
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1052
1059
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1053
|
-
"stream-type":
|
|
1060
|
+
"stream-type": o,
|
|
1054
1061
|
...n
|
|
1055
1062
|
});
|
|
1056
1063
|
}
|
|
1057
1064
|
function Ct(e, t, n, r) {
|
|
1058
|
-
|
|
1065
|
+
N.get() <= 0 || (e === h.Start ? n.linkTrack("agent-video", {
|
|
1059
1066
|
event: "start",
|
|
1060
|
-
latency:
|
|
1067
|
+
latency: N.get(!0),
|
|
1061
1068
|
"stream-type": r
|
|
1062
|
-
}, "start", [
|
|
1069
|
+
}, "start", [j.StreamVideoCreated]) : e === h.Stop && n.linkTrack("agent-video", {
|
|
1063
1070
|
event: "stop",
|
|
1064
1071
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1065
1072
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1066
1073
|
"stream-type": r
|
|
1067
|
-
}, "done", [
|
|
1074
|
+
}, "done", [j.StreamVideoDone]));
|
|
1068
1075
|
}
|
|
1069
|
-
function Rt(e, t, n, r,
|
|
1070
|
-
|
|
1076
|
+
function Rt(e, t, n, r, o) {
|
|
1077
|
+
N.get() <= 0 || (e === h.Start ? r.linkTrack("agent-video", {
|
|
1071
1078
|
event: "start",
|
|
1072
|
-
latency:
|
|
1073
|
-
"stream-type":
|
|
1074
|
-
}, "start", [
|
|
1079
|
+
latency: N.get(!0),
|
|
1080
|
+
"stream-type": o
|
|
1081
|
+
}, "start", [j.StreamVideoCreated]) : e === h.Stop && r.linkTrack("agent-video", {
|
|
1075
1082
|
event: "stop",
|
|
1076
1083
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1077
1084
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1078
|
-
"stream-type":
|
|
1085
|
+
"stream-type": o,
|
|
1079
1086
|
...n
|
|
1080
|
-
}, "done", [
|
|
1087
|
+
}, "done", [j.StreamVideoDone]));
|
|
1081
1088
|
}
|
|
1082
|
-
function
|
|
1083
|
-
return
|
|
1089
|
+
function St(e, t, n) {
|
|
1090
|
+
return N.reset(), new Promise(async (r, o) => {
|
|
1084
1091
|
try {
|
|
1085
1092
|
const i = await yt(e.id, vt(e, t), {
|
|
1086
1093
|
...t,
|
|
1087
1094
|
analytics: n,
|
|
1088
1095
|
callbacks: {
|
|
1089
1096
|
...t.callbacks,
|
|
1090
|
-
onConnectionStateChange: (
|
|
1091
|
-
var
|
|
1092
|
-
(
|
|
1097
|
+
onConnectionStateChange: (c) => {
|
|
1098
|
+
var a, s;
|
|
1099
|
+
(s = (a = t.callbacks).onConnectionStateChange) == null || s.call(a, c), c === I.Connected && r(i);
|
|
1093
1100
|
},
|
|
1094
|
-
onVideoStateChange: (
|
|
1095
|
-
var
|
|
1096
|
-
(
|
|
1101
|
+
onVideoStateChange: (c, a) => {
|
|
1102
|
+
var s, u;
|
|
1103
|
+
(u = (s = t.callbacks).onVideoStateChange) == null || u.call(s, c), kt(c, e, a, n, i.streamType);
|
|
1097
1104
|
},
|
|
1098
|
-
onAgentActivityStateChange: (
|
|
1099
|
-
var
|
|
1100
|
-
(
|
|
1105
|
+
onAgentActivityStateChange: (c) => {
|
|
1106
|
+
var a, s;
|
|
1107
|
+
(s = (a = t.callbacks).onAgentActivityStateChange) == null || s.call(a, c), c === X.Talking ? re.update() : re.reset(), Ct(c === X.Talking ? h.Start : h.Stop, e, n, i.streamType);
|
|
1101
1108
|
}
|
|
1102
1109
|
}
|
|
1103
1110
|
});
|
|
1104
1111
|
} catch (i) {
|
|
1105
|
-
|
|
1112
|
+
o(i);
|
|
1106
1113
|
}
|
|
1107
1114
|
});
|
|
1108
1115
|
}
|
|
1109
|
-
async function
|
|
1110
|
-
var
|
|
1116
|
+
async function It(e, t, n, r, o) {
|
|
1117
|
+
var s, u, d, y;
|
|
1111
1118
|
const {
|
|
1112
1119
|
chat: i,
|
|
1113
|
-
chatMode:
|
|
1114
|
-
} = await
|
|
1115
|
-
if (
|
|
1116
|
-
return (
|
|
1120
|
+
chatMode: c
|
|
1121
|
+
} = await pe(e, n, r, t.mode, t.persistentChat, o);
|
|
1122
|
+
if (c && c !== t.mode && (t.mode = c, (u = (s = t.callbacks).onModeChange) == null || u.call(s, c), c === M.TextOnly))
|
|
1123
|
+
return (y = (d = t.callbacks).onError) == null || y.call(d, new Ce(c)), {
|
|
1117
1124
|
chat: i
|
|
1118
1125
|
};
|
|
1119
|
-
const
|
|
1126
|
+
const a = await St(e, t, r);
|
|
1120
1127
|
return {
|
|
1121
1128
|
chat: i,
|
|
1122
|
-
streamingManager:
|
|
1129
|
+
streamingManager: a
|
|
1123
1130
|
};
|
|
1124
1131
|
}
|
|
1125
1132
|
async function Et(e, t) {
|
|
1126
|
-
var
|
|
1127
|
-
let n = !0, r =
|
|
1128
|
-
const o = t.mixpanelKey ||
|
|
1133
|
+
var U, K, T;
|
|
1134
|
+
let n = !0, r = null;
|
|
1135
|
+
const o = t.mixpanelKey || ze, i = t.wsURL || Le, c = t.baseURL || Z, a = {
|
|
1129
1136
|
messages: [],
|
|
1130
|
-
chatMode: t.mode ||
|
|
1131
|
-
},
|
|
1137
|
+
chatMode: t.mode || M.Functional
|
|
1138
|
+
}, s = Ve({
|
|
1132
1139
|
token: o,
|
|
1133
1140
|
agentId: e,
|
|
1134
1141
|
isEnabled: t.enableAnalitics,
|
|
1135
1142
|
distinctId: t.distinctId
|
|
1136
1143
|
});
|
|
1137
|
-
|
|
1144
|
+
s.track("agent-sdk", {
|
|
1138
1145
|
event: "init"
|
|
1139
1146
|
});
|
|
1140
|
-
const
|
|
1141
|
-
|
|
1147
|
+
const u = me(t.auth, c, t.callbacks.onError), d = await u.getById(e);
|
|
1148
|
+
s.enrich(Ue(d));
|
|
1142
1149
|
const {
|
|
1143
|
-
onMessage:
|
|
1144
|
-
clearQueue:
|
|
1145
|
-
} = rt(
|
|
1150
|
+
onMessage: y,
|
|
1151
|
+
clearQueue: A
|
|
1152
|
+
} = rt(s, a, t, d, () => {
|
|
1146
1153
|
var l;
|
|
1147
1154
|
return (l = a.socketManager) == null ? void 0 : l.disconnect();
|
|
1148
1155
|
});
|
|
1149
|
-
a.messages =
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1156
|
+
a.messages = Xe(t.initialMessages), (K = (U = t.callbacks).onNewMessage) == null || K.call(U, [...a.messages], "answer");
|
|
1157
|
+
const P = (l) => {
|
|
1158
|
+
r = l;
|
|
1152
1159
|
};
|
|
1153
|
-
|
|
1160
|
+
s.track("agent-sdk", {
|
|
1154
1161
|
event: "loaded",
|
|
1155
|
-
...
|
|
1162
|
+
...We(d)
|
|
1156
1163
|
});
|
|
1157
|
-
async function
|
|
1158
|
-
var
|
|
1159
|
-
(
|
|
1160
|
-
const
|
|
1161
|
-
onMessage:
|
|
1164
|
+
async function x(l) {
|
|
1165
|
+
var _, $, B, k, E, C, L;
|
|
1166
|
+
($ = (_ = t.callbacks).onConnectionStateChange) == null || $.call(_, I.Connecting), N.reset(), l && !n && (delete a.chat, (k = (B = t.callbacks).onNewMessage) == null || k.call(B, [...a.messages], "answer"));
|
|
1167
|
+
const w = t.mode === M.DirectPlayback ? Promise.resolve(void 0) : Ge(t.auth, i, {
|
|
1168
|
+
onMessage: y,
|
|
1162
1169
|
onError: t.callbacks.onError
|
|
1163
|
-
}),
|
|
1170
|
+
}), m = te(() => It(d, {
|
|
1164
1171
|
...t,
|
|
1165
1172
|
callbacks: {
|
|
1166
1173
|
...t.callbacks,
|
|
1167
|
-
onVideoIdChange:
|
|
1174
|
+
onVideoIdChange: P
|
|
1168
1175
|
}
|
|
1169
|
-
},
|
|
1176
|
+
}, u, s, a.chat), {
|
|
1170
1177
|
limit: 3,
|
|
1171
1178
|
timeout: $e,
|
|
1172
1179
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1173
1180
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1174
|
-
shouldRetryFn: (
|
|
1181
|
+
shouldRetryFn: (z) => (z == null ? void 0 : z.message) !== "Could not connect" && z.status !== 429,
|
|
1175
1182
|
delayMs: 1e3
|
|
1176
|
-
}).catch((
|
|
1177
|
-
var
|
|
1178
|
-
throw
|
|
1179
|
-
}), [
|
|
1180
|
-
streamingManager:
|
|
1181
|
-
chat:
|
|
1182
|
-
}] = await Promise.all([
|
|
1183
|
-
|
|
1183
|
+
}).catch((z) => {
|
|
1184
|
+
var J, f;
|
|
1185
|
+
throw R(M.Maintenance), (f = (J = t.callbacks).onConnectionStateChange) == null || f.call(J, I.Fail), z;
|
|
1186
|
+
}), [D, {
|
|
1187
|
+
streamingManager: v,
|
|
1188
|
+
chat: p
|
|
1189
|
+
}] = await Promise.all([w, m]);
|
|
1190
|
+
p && p.id !== ((E = a.chat) == null ? void 0 : E.id) && ((L = (C = t.callbacks).onNewChat) == null || L.call(C, p.id)), a.streamingManager = v, a.socketManager = D, a.chat = p, n = !1, R((p == null ? void 0 : p.chat_mode) ?? t.mode ?? M.Functional);
|
|
1184
1191
|
}
|
|
1185
|
-
async function
|
|
1186
|
-
var l,
|
|
1187
|
-
(l = a.socketManager) == null || l.disconnect(), await ((
|
|
1192
|
+
async function F() {
|
|
1193
|
+
var l, w, m, D;
|
|
1194
|
+
(l = a.socketManager) == null || l.disconnect(), await ((w = a.streamingManager) == null ? void 0 : w.disconnect()), delete a.streamingManager, delete a.socketManager, (D = (m = t.callbacks).onConnectionStateChange) == null || D.call(m, I.Disconnected);
|
|
1188
1195
|
}
|
|
1189
|
-
async function
|
|
1190
|
-
var
|
|
1191
|
-
l !== a.chatMode && (
|
|
1196
|
+
async function R(l) {
|
|
1197
|
+
var w, m;
|
|
1198
|
+
l !== a.chatMode && (s.track("agent-mode-change", {
|
|
1192
1199
|
mode: l
|
|
1193
|
-
}), a.chatMode = l, a.chatMode !==
|
|
1200
|
+
}), a.chatMode = l, a.chatMode !== M.Functional && await F(), (m = (w = t.callbacks).onModeChange) == null || m.call(w, l));
|
|
1194
1201
|
}
|
|
1195
1202
|
return {
|
|
1196
|
-
agent:
|
|
1203
|
+
agent: d,
|
|
1197
1204
|
getStreamType: () => {
|
|
1198
1205
|
var l;
|
|
1199
1206
|
return (l = a.streamingManager) == null ? void 0 : l.streamType;
|
|
@@ -1202,192 +1209,191 @@ async function Et(e, t) {
|
|
|
1202
1209
|
var l;
|
|
1203
1210
|
return ((l = a.streamingManager) == null ? void 0 : l.interruptAvailable) ?? !1;
|
|
1204
1211
|
},
|
|
1205
|
-
starterMessages: ((
|
|
1206
|
-
getSTTToken: () =>
|
|
1207
|
-
changeMode:
|
|
1208
|
-
enrichAnalytics:
|
|
1212
|
+
starterMessages: ((T = d.knowledge) == null ? void 0 : T.starter_message) || [],
|
|
1213
|
+
getSTTToken: () => u.getSTTToken(d.id),
|
|
1214
|
+
changeMode: R,
|
|
1215
|
+
enrichAnalytics: s.enrich,
|
|
1209
1216
|
async connect() {
|
|
1210
1217
|
var l;
|
|
1211
|
-
await
|
|
1218
|
+
await x(!0), s.track("agent-chat", {
|
|
1212
1219
|
event: "connect",
|
|
1213
1220
|
chatId: (l = a.chat) == null ? void 0 : l.id,
|
|
1214
|
-
agentId:
|
|
1221
|
+
agentId: d.id,
|
|
1215
1222
|
mode: a.chatMode
|
|
1216
1223
|
});
|
|
1217
1224
|
},
|
|
1218
1225
|
async reconnect() {
|
|
1219
1226
|
var l;
|
|
1220
|
-
await
|
|
1227
|
+
await F(), await x(!1), s.track("agent-chat", {
|
|
1221
1228
|
event: "reconnect",
|
|
1222
1229
|
chatId: (l = a.chat) == null ? void 0 : l.id,
|
|
1223
|
-
agentId:
|
|
1230
|
+
agentId: d.id,
|
|
1224
1231
|
mode: a.chatMode
|
|
1225
1232
|
});
|
|
1226
1233
|
},
|
|
1227
1234
|
async disconnect() {
|
|
1228
1235
|
var l;
|
|
1229
|
-
await
|
|
1236
|
+
await F(), s.track("agent-chat", {
|
|
1230
1237
|
event: "disconnect",
|
|
1231
1238
|
chatId: (l = a.chat) == null ? void 0 : l.id,
|
|
1232
|
-
agentId:
|
|
1239
|
+
agentId: d.id,
|
|
1233
1240
|
mode: a.chatMode
|
|
1234
1241
|
});
|
|
1235
1242
|
},
|
|
1236
1243
|
async chat(l) {
|
|
1237
|
-
var
|
|
1238
|
-
const
|
|
1239
|
-
if (t.mode
|
|
1240
|
-
throw new
|
|
1244
|
+
var v, p, _, $, B;
|
|
1245
|
+
const w = () => {
|
|
1246
|
+
if (ue(t.mode))
|
|
1247
|
+
throw new H(`${t.mode} is enabled, chat is disabled`);
|
|
1241
1248
|
if (l.length >= 800)
|
|
1242
|
-
throw new
|
|
1249
|
+
throw new H("Message cannot be more than 800 characters");
|
|
1243
1250
|
if (l.length === 0)
|
|
1244
|
-
throw new
|
|
1245
|
-
if (a.chatMode ===
|
|
1246
|
-
throw new
|
|
1247
|
-
if (![
|
|
1251
|
+
throw new H("Message cannot be empty");
|
|
1252
|
+
if (a.chatMode === M.Maintenance)
|
|
1253
|
+
throw new H("Chat is in maintenance mode");
|
|
1254
|
+
if (![M.TextOnly, M.Playground].includes(a.chatMode)) {
|
|
1248
1255
|
if (!a.streamingManager)
|
|
1249
|
-
throw new
|
|
1256
|
+
throw new H("Streaming manager is not initialized");
|
|
1250
1257
|
if (!a.chat)
|
|
1251
|
-
throw new
|
|
1258
|
+
throw new H("Chat is not initialized");
|
|
1252
1259
|
}
|
|
1253
|
-
},
|
|
1254
|
-
var
|
|
1260
|
+
}, m = async () => {
|
|
1261
|
+
var k, E;
|
|
1255
1262
|
if (!a.chat) {
|
|
1256
|
-
const
|
|
1257
|
-
if (!
|
|
1258
|
-
throw new
|
|
1259
|
-
a.chat =
|
|
1263
|
+
const C = await pe(d, u, s, a.chatMode, t.persistentChat);
|
|
1264
|
+
if (!C.chat)
|
|
1265
|
+
throw new De(a.chatMode, !!t.persistentChat);
|
|
1266
|
+
a.chat = C.chat, (E = (k = t.callbacks).onNewChat) == null || E.call(k, a.chat.id);
|
|
1260
1267
|
}
|
|
1261
1268
|
return a.chat.id;
|
|
1262
|
-
},
|
|
1263
|
-
var
|
|
1264
|
-
return
|
|
1269
|
+
}, D = async (k, E) => te(() => {
|
|
1270
|
+
var C, L;
|
|
1271
|
+
return u.chat(d.id, E, {
|
|
1265
1272
|
chatMode: a.chatMode,
|
|
1266
|
-
streamId: (
|
|
1267
|
-
sessionId: (
|
|
1268
|
-
messages:
|
|
1269
|
-
matches:
|
|
1270
|
-
...
|
|
1271
|
-
}) =>
|
|
1273
|
+
streamId: (C = a.streamingManager) == null ? void 0 : C.streamId,
|
|
1274
|
+
sessionId: (L = a.streamingManager) == null ? void 0 : L.sessionId,
|
|
1275
|
+
messages: k.map(({
|
|
1276
|
+
matches: z,
|
|
1277
|
+
...J
|
|
1278
|
+
}) => J)
|
|
1272
1279
|
}, {
|
|
1273
|
-
...
|
|
1280
|
+
...we(a.chatMode),
|
|
1274
1281
|
skipErrorHandler: !0
|
|
1275
1282
|
});
|
|
1276
1283
|
}, {
|
|
1277
1284
|
limit: 2,
|
|
1278
|
-
shouldRetryFn: (
|
|
1279
|
-
var
|
|
1280
|
-
const
|
|
1281
|
-
return !((
|
|
1285
|
+
shouldRetryFn: (C) => {
|
|
1286
|
+
var J, f, g, S;
|
|
1287
|
+
const L = (J = C == null ? void 0 : C.message) == null ? void 0 : J.includes("missing or invalid session_id");
|
|
1288
|
+
return !((f = C == null ? void 0 : C.message) == null ? void 0 : f.includes("Stream Error")) && !L ? ((S = (g = t.callbacks).onError) == null || S.call(g, C), !1) : !0;
|
|
1282
1289
|
},
|
|
1283
1290
|
onRetry: async () => {
|
|
1284
|
-
await
|
|
1291
|
+
await F(), await x(!1);
|
|
1285
1292
|
}
|
|
1286
1293
|
});
|
|
1287
1294
|
try {
|
|
1288
|
-
|
|
1289
|
-
id:
|
|
1295
|
+
A(), w(), a.messages.push({
|
|
1296
|
+
id: V(),
|
|
1290
1297
|
role: "user",
|
|
1291
1298
|
content: l,
|
|
1292
|
-
created_at: new Date(
|
|
1293
|
-
}), (
|
|
1294
|
-
const
|
|
1299
|
+
created_at: new Date(N.update()).toISOString()
|
|
1300
|
+
}), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...a.messages], "user");
|
|
1301
|
+
const k = await m(), E = await D([...a.messages], k);
|
|
1295
1302
|
return a.messages.push({
|
|
1296
|
-
id:
|
|
1303
|
+
id: V(),
|
|
1297
1304
|
role: "assistant",
|
|
1298
|
-
content:
|
|
1305
|
+
content: E.result || "",
|
|
1299
1306
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1300
|
-
context:
|
|
1301
|
-
matches:
|
|
1302
|
-
|
|
1303
|
-
}), r && C.videoId && a.streamingManager && (r = !1, a.messages[a.messages.length - 1].interrupted = !0, await ee(a.streamingManager, C.videoId)), u.track("agent-message-send", {
|
|
1307
|
+
context: E.context,
|
|
1308
|
+
matches: E.matches
|
|
1309
|
+
}), s.track("agent-message-send", {
|
|
1304
1310
|
event: "success",
|
|
1305
1311
|
mode: a.chatMode,
|
|
1306
1312
|
messages: a.messages.length + 1
|
|
1307
|
-
}),
|
|
1308
|
-
latency:
|
|
1313
|
+
}), E.result && (($ = (_ = t.callbacks).onNewMessage) == null || $.call(_, [...a.messages], "answer"), s.track("agent-message-received", {
|
|
1314
|
+
latency: N.get(!0),
|
|
1309
1315
|
mode: a.chatMode,
|
|
1310
1316
|
messages: a.messages.length
|
|
1311
|
-
})),
|
|
1312
|
-
} catch (
|
|
1313
|
-
throw
|
|
1317
|
+
})), E;
|
|
1318
|
+
} catch (k) {
|
|
1319
|
+
throw ((B = a.messages[a.messages.length - 1]) == null ? void 0 : B.role) === "assistant" && a.messages.pop(), s.track("agent-message-send", {
|
|
1314
1320
|
event: "error",
|
|
1315
1321
|
mode: a.chatMode,
|
|
1316
1322
|
messages: a.messages.length
|
|
1317
|
-
}),
|
|
1323
|
+
}), k;
|
|
1318
1324
|
}
|
|
1319
1325
|
},
|
|
1320
|
-
rate(l,
|
|
1321
|
-
var
|
|
1322
|
-
const
|
|
1326
|
+
rate(l, w, m) {
|
|
1327
|
+
var p, _, $, B;
|
|
1328
|
+
const D = a.messages.find((k) => k.id === l);
|
|
1323
1329
|
if (a.chat) {
|
|
1324
|
-
if (!
|
|
1330
|
+
if (!D)
|
|
1325
1331
|
throw new Error("Message not found");
|
|
1326
1332
|
} else
|
|
1327
1333
|
throw new Error("Chat is not initialized");
|
|
1328
|
-
const
|
|
1329
|
-
return
|
|
1330
|
-
event:
|
|
1331
|
-
thumb:
|
|
1332
|
-
knowledge_id: ((
|
|
1334
|
+
const v = ((p = D.matches) == null ? void 0 : p.map((k) => [k.document_id, k.id])) ?? [];
|
|
1335
|
+
return s.track("agent-rate", {
|
|
1336
|
+
event: m ? "update" : "create",
|
|
1337
|
+
thumb: w === 1 ? "up" : "down",
|
|
1338
|
+
knowledge_id: ((_ = d.knowledge) == null ? void 0 : _.id) ?? "",
|
|
1333
1339
|
mode: a.chatMode,
|
|
1334
|
-
matches:
|
|
1335
|
-
score:
|
|
1336
|
-
}),
|
|
1337
|
-
knowledge_id: ((
|
|
1340
|
+
matches: v,
|
|
1341
|
+
score: w
|
|
1342
|
+
}), m ? u.updateRating(d.id, a.chat.id, m, {
|
|
1343
|
+
knowledge_id: (($ = d.knowledge) == null ? void 0 : $.id) ?? "",
|
|
1338
1344
|
message_id: l,
|
|
1339
|
-
matches:
|
|
1340
|
-
score:
|
|
1341
|
-
}) :
|
|
1342
|
-
knowledge_id: ((
|
|
1345
|
+
matches: v,
|
|
1346
|
+
score: w
|
|
1347
|
+
}) : u.createRating(d.id, a.chat.id, {
|
|
1348
|
+
knowledge_id: ((B = d.knowledge) == null ? void 0 : B.id) ?? "",
|
|
1343
1349
|
message_id: l,
|
|
1344
|
-
matches:
|
|
1345
|
-
score:
|
|
1350
|
+
matches: v,
|
|
1351
|
+
score: w
|
|
1346
1352
|
});
|
|
1347
1353
|
},
|
|
1348
1354
|
deleteRate(l) {
|
|
1349
|
-
var
|
|
1355
|
+
var w;
|
|
1350
1356
|
if (!a.chat)
|
|
1351
1357
|
throw new Error("Chat is not initialized");
|
|
1352
|
-
return
|
|
1358
|
+
return s.track("agent-rate-delete", {
|
|
1353
1359
|
type: "text",
|
|
1354
|
-
chat_id: (
|
|
1360
|
+
chat_id: (w = a.chat) == null ? void 0 : w.id,
|
|
1355
1361
|
id: l,
|
|
1356
1362
|
mode: a.chatMode
|
|
1357
|
-
}),
|
|
1363
|
+
}), u.deleteRating(d.id, a.chat.id, l);
|
|
1358
1364
|
},
|
|
1359
1365
|
async speak(l) {
|
|
1360
|
-
var
|
|
1361
|
-
function
|
|
1366
|
+
var v, p, _;
|
|
1367
|
+
function w() {
|
|
1362
1368
|
if (typeof l == "string") {
|
|
1363
|
-
if (!
|
|
1369
|
+
if (!d.presenter.voice)
|
|
1364
1370
|
throw new Error("Presenter voice is not initialized");
|
|
1365
1371
|
return {
|
|
1366
1372
|
type: "text",
|
|
1367
|
-
provider:
|
|
1373
|
+
provider: d.presenter.voice,
|
|
1368
1374
|
input: l,
|
|
1369
1375
|
ssml: !1
|
|
1370
1376
|
};
|
|
1371
1377
|
}
|
|
1372
1378
|
if (l.type === "text" && !l.provider) {
|
|
1373
|
-
if (!
|
|
1379
|
+
if (!d.presenter.voice)
|
|
1374
1380
|
throw new Error("Presenter voice is not initialized");
|
|
1375
1381
|
return {
|
|
1376
1382
|
type: "text",
|
|
1377
|
-
provider:
|
|
1383
|
+
provider: d.presenter.voice,
|
|
1378
1384
|
input: l.input,
|
|
1379
1385
|
ssml: l.ssml
|
|
1380
1386
|
};
|
|
1381
1387
|
}
|
|
1382
1388
|
return l;
|
|
1383
1389
|
}
|
|
1384
|
-
const
|
|
1385
|
-
if (
|
|
1386
|
-
id:
|
|
1390
|
+
const m = w();
|
|
1391
|
+
if (s.track("agent-speak", m), N.update(), a.messages && m.type === "text" && (a.messages.push({
|
|
1392
|
+
id: V(),
|
|
1387
1393
|
role: "assistant",
|
|
1388
|
-
content:
|
|
1389
|
-
created_at: new Date(
|
|
1390
|
-
}), (
|
|
1394
|
+
content: m.input,
|
|
1395
|
+
created_at: new Date(N.get(!0)).toISOString()
|
|
1396
|
+
}), (p = (v = t.callbacks).onNewMessage) == null || p.call(v, [...a.messages], "answer")), Ne(a.chatMode))
|
|
1391
1397
|
return {
|
|
1392
1398
|
duration: 0,
|
|
1393
1399
|
video_id: "",
|
|
@@ -1395,73 +1401,63 @@ async function Et(e, t) {
|
|
|
1395
1401
|
};
|
|
1396
1402
|
if (!a.streamingManager)
|
|
1397
1403
|
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
|
-
}
|
|
1404
|
+
return a.streamingManager.speak({
|
|
1405
|
+
script: m,
|
|
1406
|
+
metadata: {
|
|
1407
|
+
chat_id: (_ = a.chat) == null ? void 0 : _.id,
|
|
1408
|
+
agent_id: d.id
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
1411
|
},
|
|
1412
1412
|
async interrupt({
|
|
1413
1413
|
type: l
|
|
1414
1414
|
}) {
|
|
1415
|
-
var
|
|
1416
|
-
|
|
1417
|
-
|
|
1415
|
+
var m, D, v, p, _;
|
|
1416
|
+
Ye(a.streamingManager, (m = a.streamingManager) == null ? void 0 : m.streamType, r);
|
|
1417
|
+
const w = a.messages[a.messages.length - 1];
|
|
1418
|
+
s.track("agent-video-interrupt", {
|
|
1418
1419
|
type: l || "click",
|
|
1419
|
-
stream_id: (
|
|
1420
|
-
agent_id:
|
|
1421
|
-
owner_id:
|
|
1420
|
+
stream_id: (D = a.streamingManager) == null ? void 0 : D.streamId,
|
|
1421
|
+
agent_id: d.id,
|
|
1422
|
+
owner_id: d.owner_id,
|
|
1422
1423
|
video_duration_to_interrupt: re.get(!0),
|
|
1423
|
-
message_duration_to_interrupt:
|
|
1424
|
-
chat_id: (
|
|
1425
|
-
mode: a.chatMode
|
|
1426
|
-
|
|
1427
|
-
}), T) {
|
|
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);
|
|
1424
|
+
message_duration_to_interrupt: N.get(!0),
|
|
1425
|
+
chat_id: (v = a.chat) == null ? void 0 : v.id,
|
|
1426
|
+
mode: a.chatMode
|
|
1427
|
+
}), w.interrupted = !0, (_ = (p = t.callbacks).onNewMessage) == null || _.call(p, [...a.messages], "answer"), Qe(a.streamingManager, r);
|
|
1432
1428
|
}
|
|
1433
1429
|
};
|
|
1434
1430
|
}
|
|
1435
1431
|
function Mt(e, t, n) {
|
|
1436
1432
|
const {
|
|
1437
1433
|
getById: r
|
|
1438
|
-
} =
|
|
1434
|
+
} = me(t, n || Z);
|
|
1439
1435
|
return r(e);
|
|
1440
1436
|
}
|
|
1441
1437
|
export {
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1438
|
+
X as AgentActivityState,
|
|
1439
|
+
_e as AgentStatus,
|
|
1440
|
+
De as ChatCreationFailed,
|
|
1441
|
+
M as ChatMode,
|
|
1442
|
+
Ce as ChatModeDowngraded,
|
|
1443
|
+
q as ChatProgress,
|
|
1444
|
+
I as ConnectionState,
|
|
1445
|
+
O as ConnectivityState,
|
|
1450
1446
|
je as DocumentType,
|
|
1451
|
-
|
|
1452
|
-
|
|
1447
|
+
Te as KnowledgeType,
|
|
1448
|
+
Ie as PlanGroup,
|
|
1453
1449
|
Ae as Providers,
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1450
|
+
Ee as RateState,
|
|
1451
|
+
j as StreamEvents,
|
|
1452
|
+
W as StreamType,
|
|
1453
|
+
h as StreamingState,
|
|
1454
|
+
Me as Subject,
|
|
1459
1455
|
Se as UserPlan,
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1456
|
+
H as ValidationError,
|
|
1457
|
+
ce as VideoType,
|
|
1458
|
+
Pe as VoiceAccess,
|
|
1459
|
+
Re as WsError,
|
|
1464
1460
|
Et as createAgentManager,
|
|
1465
1461
|
Mt as getAgent,
|
|
1466
|
-
|
|
1462
|
+
be as mapVideoType
|
|
1467
1463
|
};
|