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