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