@d-id/client-sdk 1.1.0-beta.10 → 1.1.0-beta.12
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 +1003 -1482
- package/dist/index.umd.cjs +1 -1851
- package/dist/src/types/stream/stream.d.ts +0 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,525 +1,323 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
class BaseError extends Error {
|
|
1
|
+
var me = Object.defineProperty;
|
|
2
|
+
var ge = (e, t, a) => t in e ? me(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var q = (e, t, a) => (ge(e, typeof t != "symbol" ? t + "" : t, a), a);
|
|
4
|
+
class Q extends Error {
|
|
8
5
|
constructor({
|
|
9
|
-
kind,
|
|
10
|
-
description,
|
|
11
|
-
error
|
|
6
|
+
kind: a,
|
|
7
|
+
description: r,
|
|
8
|
+
error: o
|
|
12
9
|
}) {
|
|
13
10
|
super(JSON.stringify({
|
|
14
|
-
kind,
|
|
15
|
-
description
|
|
11
|
+
kind: a,
|
|
12
|
+
description: r
|
|
16
13
|
}));
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.kind =
|
|
21
|
-
this.description = description;
|
|
22
|
-
this.error = error;
|
|
14
|
+
q(this, "kind");
|
|
15
|
+
q(this, "description");
|
|
16
|
+
q(this, "error");
|
|
17
|
+
this.kind = a, this.description = r, this.error = o;
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
|
-
class
|
|
26
|
-
constructor(
|
|
20
|
+
class he extends Q {
|
|
21
|
+
constructor(t, a) {
|
|
27
22
|
super({
|
|
28
23
|
kind: "ChatCreationFailed",
|
|
29
|
-
description: `Failed to create ${
|
|
24
|
+
description: `Failed to create ${a ? "persistent" : ""} chat, mode: ${t}`
|
|
30
25
|
});
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
|
-
class
|
|
34
|
-
constructor(
|
|
28
|
+
class we extends Q {
|
|
29
|
+
constructor(t) {
|
|
35
30
|
super({
|
|
36
31
|
kind: "ChatModeDowngraded",
|
|
37
|
-
description: `Chat mode downgraded to ${
|
|
32
|
+
description: `Chat mode downgraded to ${t}`
|
|
38
33
|
});
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
|
-
class
|
|
42
|
-
constructor(
|
|
36
|
+
class W extends Q {
|
|
37
|
+
constructor(a, r) {
|
|
43
38
|
super({
|
|
44
39
|
kind: "ValidationError",
|
|
45
|
-
description:
|
|
40
|
+
description: a
|
|
46
41
|
});
|
|
47
|
-
|
|
48
|
-
this.key =
|
|
42
|
+
q(this, "key");
|
|
43
|
+
this.key = r;
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
|
-
class
|
|
52
|
-
constructor(
|
|
46
|
+
class pe extends Q {
|
|
47
|
+
constructor(t) {
|
|
53
48
|
super({
|
|
54
49
|
kind: "WSError",
|
|
55
|
-
description:
|
|
50
|
+
description: t
|
|
56
51
|
});
|
|
57
52
|
}
|
|
58
53
|
}
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
UserPlan2["ENTERPRISE"] = "enterprise";
|
|
63
|
-
UserPlan2["LITE"] = "lite";
|
|
64
|
-
UserPlan2["ADVANCED"] = "advanced";
|
|
65
|
-
return UserPlan2;
|
|
66
|
-
})(UserPlan || {});
|
|
67
|
-
var PlanGroup = /* @__PURE__ */ ((PlanGroup2) => {
|
|
68
|
-
PlanGroup2["TRIAL"] = "deid-trial";
|
|
69
|
-
PlanGroup2["PRO"] = "deid-pro";
|
|
70
|
-
PlanGroup2["ENTERPRISE"] = "deid-enterprise";
|
|
71
|
-
PlanGroup2["LITE"] = "deid-lite";
|
|
72
|
-
PlanGroup2["ADVANCED"] = "deid-advanced";
|
|
73
|
-
PlanGroup2["BUILD"] = "deid-api-build";
|
|
74
|
-
PlanGroup2["LAUNCH"] = "deid-api-launch";
|
|
75
|
-
PlanGroup2["SCALE"] = "deid-api-scale";
|
|
76
|
-
return PlanGroup2;
|
|
77
|
-
})(PlanGroup || {});
|
|
78
|
-
var AgentStatus = /* @__PURE__ */ ((AgentStatus2) => {
|
|
79
|
-
AgentStatus2["Created"] = "created";
|
|
80
|
-
AgentStatus2["Started"] = "started";
|
|
81
|
-
AgentStatus2["Done"] = "done";
|
|
82
|
-
AgentStatus2["Error"] = "error";
|
|
83
|
-
AgentStatus2["Rejected"] = "rejected";
|
|
84
|
-
AgentStatus2["Ready"] = "ready";
|
|
85
|
-
return AgentStatus2;
|
|
86
|
-
})(AgentStatus || {});
|
|
87
|
-
var RateState = /* @__PURE__ */ ((RateState2) => {
|
|
88
|
-
RateState2["Unrated"] = "Unrated";
|
|
89
|
-
RateState2["Positive"] = "Positive";
|
|
90
|
-
RateState2["Negative"] = "Negative";
|
|
91
|
-
return RateState2;
|
|
92
|
-
})(RateState || {});
|
|
93
|
-
var ChatMode = /* @__PURE__ */ ((ChatMode2) => {
|
|
94
|
-
ChatMode2["Functional"] = "Functional";
|
|
95
|
-
ChatMode2["TextOnly"] = "TextOnly";
|
|
96
|
-
ChatMode2["Maintenance"] = "Maintenance";
|
|
97
|
-
ChatMode2["Playground"] = "Playground";
|
|
98
|
-
ChatMode2["DirectPlayback"] = "DirectPlayback";
|
|
99
|
-
return ChatMode2;
|
|
100
|
-
})(ChatMode || {});
|
|
101
|
-
var ChatProgress = /* @__PURE__ */ ((ChatProgress2) => {
|
|
102
|
-
ChatProgress2["Embed"] = "embed";
|
|
103
|
-
ChatProgress2["Query"] = "query";
|
|
104
|
-
ChatProgress2["Partial"] = "partial";
|
|
105
|
-
ChatProgress2["Answer"] = "answer";
|
|
106
|
-
ChatProgress2["Complete"] = "done";
|
|
107
|
-
return ChatProgress2;
|
|
108
|
-
})(ChatProgress || {});
|
|
109
|
-
var Subject = /* @__PURE__ */ ((Subject2) => {
|
|
110
|
-
Subject2["KnowledgeProcessing"] = "knowledge/processing";
|
|
111
|
-
Subject2["KnowledgeIndexing"] = "knowledge/indexing";
|
|
112
|
-
Subject2["KnowledgeFailed"] = "knowledge/error";
|
|
113
|
-
Subject2["KnowledgeDone"] = "knowledge/done";
|
|
114
|
-
return Subject2;
|
|
115
|
-
})(Subject || {});
|
|
116
|
-
var KnowledgeType = /* @__PURE__ */ ((KnowledgeType2) => {
|
|
117
|
-
KnowledgeType2["Knowledge"] = "knowledge";
|
|
118
|
-
KnowledgeType2["Document"] = "document";
|
|
119
|
-
KnowledgeType2["Record"] = "record";
|
|
120
|
-
return KnowledgeType2;
|
|
121
|
-
})(KnowledgeType || {});
|
|
122
|
-
var DocumentType = /* @__PURE__ */ ((DocumentType2) => {
|
|
123
|
-
DocumentType2["Pdf"] = "pdf";
|
|
124
|
-
DocumentType2["Text"] = "text";
|
|
125
|
-
DocumentType2["Html"] = "html";
|
|
126
|
-
DocumentType2["Word"] = "word";
|
|
127
|
-
DocumentType2["Json"] = "json";
|
|
128
|
-
DocumentType2["Markdown"] = "markdown";
|
|
129
|
-
DocumentType2["Csv"] = "csv";
|
|
130
|
-
DocumentType2["Excel"] = "excel";
|
|
131
|
-
DocumentType2["Powerpoint"] = "powerpoint";
|
|
132
|
-
DocumentType2["Archive"] = "archive";
|
|
133
|
-
DocumentType2["Image"] = "image";
|
|
134
|
-
DocumentType2["Audio"] = "audio";
|
|
135
|
-
DocumentType2["Video"] = "video";
|
|
136
|
-
return DocumentType2;
|
|
137
|
-
})(DocumentType || {});
|
|
138
|
-
var VideoType = /* @__PURE__ */ ((VideoType2) => {
|
|
139
|
-
VideoType2["Clip"] = "clip";
|
|
140
|
-
VideoType2["Talk"] = "talk";
|
|
141
|
-
return VideoType2;
|
|
142
|
-
})(VideoType || {});
|
|
143
|
-
const mapVideoType = (type) => {
|
|
144
|
-
switch (type) {
|
|
54
|
+
var ye = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ye || {}), ve = /* @__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))(ve || {}), ke = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ke || {}), De = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(De || {}), b = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(b || {}), U = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(U || {}), Re = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Re || {}), Ce = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Ce || {}), Se = /* @__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))(Se || {}), ae = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ae || {});
|
|
55
|
+
const Ee = (e) => {
|
|
56
|
+
switch (e) {
|
|
145
57
|
case "clip":
|
|
146
58
|
return "clip";
|
|
147
59
|
case "talk":
|
|
148
60
|
return "talk";
|
|
149
61
|
default:
|
|
150
|
-
throw new Error(`Unknown video type: ${
|
|
62
|
+
throw new Error(`Unknown video type: ${e}`);
|
|
151
63
|
}
|
|
152
64
|
};
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
ConnectivityState2["Weak"] = "WEAK";
|
|
161
|
-
ConnectivityState2["Unknown"] = "UNKNOWN";
|
|
162
|
-
return ConnectivityState2;
|
|
163
|
-
})(ConnectivityState || {});
|
|
164
|
-
var AgentActivityState = /* @__PURE__ */ ((AgentActivityState2) => {
|
|
165
|
-
AgentActivityState2["Idle"] = "IDLE";
|
|
166
|
-
AgentActivityState2["Talking"] = "TALKING";
|
|
167
|
-
return AgentActivityState2;
|
|
168
|
-
})(AgentActivityState || {});
|
|
169
|
-
const DataChannelSignalMap = {
|
|
170
|
-
"stream/started": "START",
|
|
171
|
-
"stream/done": "STOP"
|
|
172
|
-
/* Stop */
|
|
173
|
-
};
|
|
174
|
-
var StreamEvents = /* @__PURE__ */ ((StreamEvents2) => {
|
|
175
|
-
StreamEvents2["ChatAnswer"] = "chat/answer";
|
|
176
|
-
StreamEvents2["ChatPartial"] = "chat/partial";
|
|
177
|
-
StreamEvents2["StreamDone"] = "stream/done";
|
|
178
|
-
StreamEvents2["StreamStarted"] = "stream/started";
|
|
179
|
-
StreamEvents2["StreamFailed"] = "stream/error";
|
|
180
|
-
StreamEvents2["StreamReady"] = "stream/ready";
|
|
181
|
-
StreamEvents2["StreamCreated"] = "stream/created";
|
|
182
|
-
StreamEvents2["StreamVideoCreated"] = "stream-video/started";
|
|
183
|
-
StreamEvents2["StreamVideoDone"] = "stream-video/done";
|
|
184
|
-
StreamEvents2["StreamVideoError"] = "stream-video/error";
|
|
185
|
-
StreamEvents2["StreamVideoRejected"] = "stream-video/rejected";
|
|
186
|
-
return StreamEvents2;
|
|
187
|
-
})(StreamEvents || {});
|
|
188
|
-
var ConnectionState = /* @__PURE__ */ ((ConnectionState2) => {
|
|
189
|
-
ConnectionState2["New"] = "new";
|
|
190
|
-
ConnectionState2["Fail"] = "fail";
|
|
191
|
-
ConnectionState2["Connected"] = "connected";
|
|
192
|
-
ConnectionState2["Connecting"] = "connecting";
|
|
193
|
-
ConnectionState2["Closed"] = "closed";
|
|
194
|
-
ConnectionState2["Completed"] = "completed";
|
|
195
|
-
ConnectionState2["Disconnected"] = "disconnected";
|
|
196
|
-
return ConnectionState2;
|
|
197
|
-
})(ConnectionState || {});
|
|
198
|
-
var StreamType = /* @__PURE__ */ ((StreamType2) => {
|
|
199
|
-
StreamType2["Legacy"] = "legacy";
|
|
200
|
-
StreamType2["Fluent"] = "fluent";
|
|
201
|
-
return StreamType2;
|
|
202
|
-
})(StreamType || {});
|
|
203
|
-
var Providers = /* @__PURE__ */ ((Providers2) => {
|
|
204
|
-
Providers2["Amazon"] = "amazon";
|
|
205
|
-
Providers2["Microsoft"] = "microsoft";
|
|
206
|
-
Providers2["Afflorithmics"] = "afflorithmics";
|
|
207
|
-
Providers2["Elevenlabs"] = "elevenlabs";
|
|
208
|
-
return Providers2;
|
|
209
|
-
})(Providers || {});
|
|
210
|
-
var VoiceAccess = /* @__PURE__ */ ((VoiceAccess2) => {
|
|
211
|
-
VoiceAccess2["Public"] = "public";
|
|
212
|
-
VoiceAccess2["Premium"] = "premium";
|
|
213
|
-
VoiceAccess2["Private"] = "private";
|
|
214
|
-
return VoiceAccess2;
|
|
215
|
-
})(VoiceAccess || {});
|
|
216
|
-
const CONNECTION_RETRY_TIMEOUT_MS = 45 * 1e3;
|
|
217
|
-
const PLAYGROUND_HEADER = "X-Playground-Chat";
|
|
218
|
-
const didApiUrl = "https://api-dev.d-id.com";
|
|
219
|
-
const didSocketApiUrl = "wss://notifications-dev.d-id.com";
|
|
220
|
-
const mixpanelKey = "79f81a83a67430be2bc0fd61042b8faa";
|
|
221
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
222
|
-
const getRandom = (length = 16) => {
|
|
223
|
-
const arr = new Uint8Array(length);
|
|
224
|
-
window.crypto.getRandomValues(arr);
|
|
225
|
-
return Array.from(arr, (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
226
|
-
};
|
|
227
|
-
const isTextualChat = (chatMode) => [ChatMode.TextOnly, ChatMode.Playground, ChatMode.Maintenance].includes(chatMode);
|
|
228
|
-
function createRacePromise(timeout, timeoutErrorMessage) {
|
|
229
|
-
let timeId;
|
|
230
|
-
const promise = new Promise((_, reject) => {
|
|
231
|
-
timeId = setTimeout(() => reject(new Error(timeoutErrorMessage)), timeout);
|
|
232
|
-
});
|
|
65
|
+
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), V = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(V || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), N = /* @__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.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(N || {}), M = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(M || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), _e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(_e || {}), Me = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Me || {});
|
|
66
|
+
const Ie = 45 * 1e3, be = "X-Playground-Chat", Y = "https://api.d-id.com", Te = "wss://notifications.d-id.com", je = "79f81a83a67430be2bc0fd61042b8faa", ie = (e) => new Promise((t) => setTimeout(t, e)), K = (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
|
+
}, Pe = (e) => [b.TextOnly, b.Playground, b.Maintenance].includes(e);
|
|
70
|
+
function Ae(e, t) {
|
|
71
|
+
let a;
|
|
233
72
|
return {
|
|
234
|
-
promise,
|
|
235
|
-
|
|
73
|
+
promise: new Promise((o, s) => {
|
|
74
|
+
a = setTimeout(() => s(new Error(t)), e);
|
|
75
|
+
}),
|
|
76
|
+
clear: () => clearTimeout(a)
|
|
236
77
|
};
|
|
237
78
|
}
|
|
238
|
-
async function
|
|
239
|
-
const
|
|
240
|
-
limit: (
|
|
241
|
-
delayMs: (
|
|
242
|
-
timeout: (
|
|
243
|
-
timeoutErrorMessage: (
|
|
244
|
-
shouldRetryFn: (
|
|
245
|
-
onRetry: (
|
|
79
|
+
async function G(e, t) {
|
|
80
|
+
const a = {
|
|
81
|
+
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
82
|
+
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
83
|
+
timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
|
|
84
|
+
timeoutErrorMessage: (t == null ? void 0 : t.timeoutErrorMessage) || "Timeout error",
|
|
85
|
+
shouldRetryFn: (t == null ? void 0 : t.shouldRetryFn) ?? (() => !0),
|
|
86
|
+
onRetry: (t == null ? void 0 : t.onRetry) ?? (() => {
|
|
246
87
|
})
|
|
247
88
|
};
|
|
248
|
-
let
|
|
249
|
-
for (let
|
|
89
|
+
let r;
|
|
90
|
+
for (let o = 1; o <= a.limit; o++)
|
|
250
91
|
try {
|
|
251
|
-
if (!
|
|
252
|
-
return await
|
|
253
|
-
}
|
|
92
|
+
if (!a.timeout)
|
|
93
|
+
return await e();
|
|
254
94
|
const {
|
|
255
|
-
promise,
|
|
256
|
-
clear
|
|
257
|
-
} =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
throw error;
|
|
264
|
-
}
|
|
265
|
-
await sleep(options.delayMs);
|
|
266
|
-
options.onRetry(error);
|
|
95
|
+
promise: s,
|
|
96
|
+
clear: n
|
|
97
|
+
} = Ae(a.timeout, a.timeoutErrorMessage), c = e().finally(n);
|
|
98
|
+
return await Promise.race([c, s]);
|
|
99
|
+
} catch (s) {
|
|
100
|
+
if (r = s, !a.shouldRetryFn(s) || o >= a.limit)
|
|
101
|
+
throw s;
|
|
102
|
+
await ie(a.delayMs), a.onRetry(s);
|
|
267
103
|
}
|
|
268
|
-
|
|
269
|
-
throw lastError;
|
|
104
|
+
throw r;
|
|
270
105
|
}
|
|
271
|
-
function
|
|
272
|
-
let
|
|
273
|
-
if (!
|
|
274
|
-
let
|
|
275
|
-
window.localStorage.setItem("did_external_key_id",
|
|
276
|
-
key = newKey;
|
|
106
|
+
function se() {
|
|
107
|
+
let e = window.localStorage.getItem("did_external_key_id");
|
|
108
|
+
if (!e) {
|
|
109
|
+
let t = K();
|
|
110
|
+
window.localStorage.setItem("did_external_key_id", t), e = t;
|
|
277
111
|
}
|
|
278
|
-
return
|
|
112
|
+
return e;
|
|
279
113
|
}
|
|
280
|
-
let
|
|
281
|
-
function
|
|
282
|
-
if (
|
|
283
|
-
return `Bearer ${
|
|
284
|
-
|
|
285
|
-
return `Basic ${btoa(`${
|
|
286
|
-
|
|
287
|
-
return `Client-Key ${
|
|
288
|
-
|
|
289
|
-
throw new Error(`Unknown auth type: ${auth}`);
|
|
290
|
-
}
|
|
114
|
+
let Be = K();
|
|
115
|
+
function oe(e) {
|
|
116
|
+
if (e.type === "bearer")
|
|
117
|
+
return `Bearer ${e.token}`;
|
|
118
|
+
if (e.type === "basic")
|
|
119
|
+
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
120
|
+
if (e.type === "key")
|
|
121
|
+
return `Client-Key ${e.clientKey}.${se()}_${Be}`;
|
|
122
|
+
throw new Error(`Unknown auth type: ${e}`);
|
|
291
123
|
}
|
|
292
|
-
const
|
|
124
|
+
const $e = (e) => G(e, {
|
|
293
125
|
limit: 3,
|
|
294
126
|
delayMs: 1e3,
|
|
295
127
|
timeout: 0,
|
|
296
|
-
shouldRetryFn: (
|
|
128
|
+
shouldRetryFn: (t) => t.status === 429
|
|
297
129
|
});
|
|
298
|
-
function
|
|
299
|
-
const
|
|
130
|
+
function ee(e, t = Y, a) {
|
|
131
|
+
const r = async (o, s) => {
|
|
300
132
|
const {
|
|
301
|
-
skipErrorHandler,
|
|
302
|
-
...
|
|
303
|
-
} =
|
|
304
|
-
|
|
305
|
-
...fetchOptions,
|
|
133
|
+
skipErrorHandler: n,
|
|
134
|
+
...c
|
|
135
|
+
} = s || {}, i = await $e(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
136
|
+
...c,
|
|
306
137
|
headers: {
|
|
307
|
-
...
|
|
308
|
-
Authorization:
|
|
138
|
+
...c.headers,
|
|
139
|
+
Authorization: oe(e),
|
|
309
140
|
"Content-Type": "application/json"
|
|
310
141
|
}
|
|
311
142
|
}));
|
|
312
|
-
if (!
|
|
313
|
-
let
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
throw error;
|
|
143
|
+
if (!i.ok) {
|
|
144
|
+
let d = await i.text().catch(() => `Failed to fetch with status ${i.status}`);
|
|
145
|
+
const u = new Error(d);
|
|
146
|
+
throw a && !n && a(u, {
|
|
147
|
+
url: o,
|
|
148
|
+
options: c,
|
|
149
|
+
headers: i.headers
|
|
150
|
+
}), u;
|
|
323
151
|
}
|
|
324
|
-
return
|
|
152
|
+
return i.json();
|
|
325
153
|
};
|
|
326
154
|
return {
|
|
327
|
-
get(
|
|
328
|
-
return
|
|
329
|
-
...
|
|
155
|
+
get(o, s) {
|
|
156
|
+
return r(o, {
|
|
157
|
+
...s,
|
|
330
158
|
method: "GET"
|
|
331
159
|
});
|
|
332
160
|
},
|
|
333
|
-
post(
|
|
334
|
-
return
|
|
335
|
-
...
|
|
336
|
-
body: JSON.stringify(
|
|
161
|
+
post(o, s, n) {
|
|
162
|
+
return r(o, {
|
|
163
|
+
...n,
|
|
164
|
+
body: JSON.stringify(s),
|
|
337
165
|
method: "POST"
|
|
338
166
|
});
|
|
339
167
|
},
|
|
340
|
-
delete(
|
|
341
|
-
return
|
|
342
|
-
...
|
|
343
|
-
body: JSON.stringify(
|
|
168
|
+
delete(o, s, n) {
|
|
169
|
+
return r(o, {
|
|
170
|
+
...n,
|
|
171
|
+
body: JSON.stringify(s),
|
|
344
172
|
method: "DELETE"
|
|
345
173
|
});
|
|
346
174
|
},
|
|
347
|
-
patch(
|
|
348
|
-
return
|
|
349
|
-
...
|
|
350
|
-
body: JSON.stringify(
|
|
175
|
+
patch(o, s, n) {
|
|
176
|
+
return r(o, {
|
|
177
|
+
...n,
|
|
178
|
+
body: JSON.stringify(s),
|
|
351
179
|
method: "PATCH"
|
|
352
180
|
});
|
|
353
181
|
}
|
|
354
182
|
};
|
|
355
183
|
}
|
|
356
|
-
function
|
|
357
|
-
const
|
|
184
|
+
function ce(e, t = Y, a) {
|
|
185
|
+
const r = ee(e, `${t}/agents`, a);
|
|
358
186
|
return {
|
|
359
|
-
create(
|
|
360
|
-
return
|
|
187
|
+
create(o, s) {
|
|
188
|
+
return r.post("/", o, s);
|
|
361
189
|
},
|
|
362
|
-
getAgents(
|
|
363
|
-
return
|
|
190
|
+
getAgents(o, s) {
|
|
191
|
+
return r.get(`/${o ? `?tag=${o}` : ""}`, s).then((n) => n ?? []);
|
|
364
192
|
},
|
|
365
|
-
getById(
|
|
366
|
-
return
|
|
193
|
+
getById(o, s) {
|
|
194
|
+
return r.get(`/${o}`, s);
|
|
367
195
|
},
|
|
368
|
-
delete(
|
|
369
|
-
return
|
|
196
|
+
delete(o, s) {
|
|
197
|
+
return r.delete(`/${o}`, void 0, s);
|
|
370
198
|
},
|
|
371
|
-
update(
|
|
372
|
-
return
|
|
199
|
+
update(o, s, n) {
|
|
200
|
+
return r.patch(`/${o}`, s, n);
|
|
373
201
|
},
|
|
374
|
-
newChat(
|
|
375
|
-
return
|
|
202
|
+
newChat(o, s, n) {
|
|
203
|
+
return r.post(`/${o}/chat`, s, n);
|
|
376
204
|
},
|
|
377
|
-
chat(
|
|
378
|
-
return
|
|
205
|
+
chat(o, s, n, c) {
|
|
206
|
+
return r.post(`/${o}/chat/${s}`, n, c);
|
|
379
207
|
},
|
|
380
|
-
createRating(
|
|
381
|
-
return
|
|
208
|
+
createRating(o, s, n, c) {
|
|
209
|
+
return r.post(`/${o}/chat/${s}/ratings`, n, c);
|
|
382
210
|
},
|
|
383
|
-
updateRating(
|
|
384
|
-
return
|
|
211
|
+
updateRating(o, s, n, c, i) {
|
|
212
|
+
return r.patch(`/${o}/chat/${s}/ratings/${n}`, c, i);
|
|
385
213
|
},
|
|
386
|
-
deleteRating(
|
|
387
|
-
return
|
|
214
|
+
deleteRating(o, s, n, c) {
|
|
215
|
+
return r.delete(`/${o}/chat/${s}/ratings/${n}`, c);
|
|
388
216
|
},
|
|
389
|
-
getSTTToken(
|
|
390
|
-
return
|
|
217
|
+
getSTTToken(o, s) {
|
|
218
|
+
return r.get(`/${o}/stt-token`, s);
|
|
391
219
|
}
|
|
392
220
|
};
|
|
393
221
|
}
|
|
394
|
-
const
|
|
395
|
-
function
|
|
396
|
-
var
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const platform = navigator.platform;
|
|
402
|
-
if (platform.toLowerCase().includes("win")) {
|
|
403
|
-
return "Windows";
|
|
404
|
-
} else if (platform.toLowerCase().includes("mac")) {
|
|
405
|
-
return "Mac OS X";
|
|
406
|
-
} else if (platform.toLowerCase().includes("linux")) {
|
|
407
|
-
return "Linux";
|
|
408
|
-
} else {
|
|
409
|
-
return "Unknown";
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
const presenter = agent.presenter;
|
|
222
|
+
const de = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
223
|
+
function Le(e) {
|
|
224
|
+
var o, s, n, c;
|
|
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
|
+
}, r = e.presenter;
|
|
413
229
|
return {
|
|
414
|
-
$os: `${
|
|
415
|
-
isMobile: `${
|
|
230
|
+
$os: `${a()}`,
|
|
231
|
+
isMobile: `${t() == "Mobile"}`,
|
|
416
232
|
browser: navigator.userAgent,
|
|
417
233
|
origin: window.location.origin,
|
|
418
|
-
agentType:
|
|
234
|
+
agentType: de(r),
|
|
419
235
|
agentVoice: {
|
|
420
|
-
voiceId: (
|
|
421
|
-
provider: (
|
|
236
|
+
voiceId: (s = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : s.voice_id,
|
|
237
|
+
provider: (c = (n = e.presenter) == null ? void 0 : n.voice) == null ? void 0 : c.type
|
|
422
238
|
}
|
|
423
239
|
};
|
|
424
240
|
}
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
var _a, _b, _c;
|
|
429
|
-
const {
|
|
430
|
-
event,
|
|
431
|
-
...baseProps
|
|
432
|
-
} = data;
|
|
241
|
+
const ze = (e) => e.reduce((t, a) => t + a, 0), te = (e) => ze(e) / e.length;
|
|
242
|
+
function xe(e, t, a) {
|
|
243
|
+
var i, d, u;
|
|
433
244
|
const {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
} = (
|
|
439
|
-
|
|
440
|
-
|
|
245
|
+
event: r,
|
|
246
|
+
...o
|
|
247
|
+
} = e, {
|
|
248
|
+
template: s
|
|
249
|
+
} = (t == null ? void 0 : t.llm) || {}, {
|
|
250
|
+
language: n
|
|
251
|
+
} = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
|
|
252
|
+
return {
|
|
253
|
+
...o,
|
|
441
254
|
llm: {
|
|
442
|
-
...
|
|
443
|
-
template
|
|
255
|
+
...o.llm,
|
|
256
|
+
template: s
|
|
444
257
|
},
|
|
445
258
|
script: {
|
|
446
|
-
...
|
|
259
|
+
...o.script,
|
|
447
260
|
provider: {
|
|
448
|
-
...(
|
|
449
|
-
language
|
|
261
|
+
...(d = o == null ? void 0 : o.script) == null ? void 0 : d.provider,
|
|
262
|
+
language: n
|
|
450
263
|
}
|
|
451
264
|
},
|
|
452
|
-
stitch: (
|
|
453
|
-
...
|
|
265
|
+
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
|
|
266
|
+
...a
|
|
454
267
|
};
|
|
455
|
-
return props;
|
|
456
268
|
}
|
|
457
|
-
let
|
|
458
|
-
const
|
|
459
|
-
function
|
|
460
|
-
var
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
agentType: getAgentType(presenter),
|
|
469
|
-
owner_id: config.agent.owner_id ?? "",
|
|
470
|
-
promptVersion: (_b = config.agent.llm) == null ? void 0 : _b.prompt_version,
|
|
269
|
+
let Z = {};
|
|
270
|
+
const Fe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
271
|
+
function Ne(e) {
|
|
272
|
+
var s, n, c, i, d, u;
|
|
273
|
+
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter, r = (s = e.agent.llm) == null ? void 0 : s.prompt_customization, o = {
|
|
274
|
+
token: e.token || "testKey",
|
|
275
|
+
distinct_id: e.distinctId || se(),
|
|
276
|
+
agentId: e.agent.id,
|
|
277
|
+
agentType: de(a),
|
|
278
|
+
owner_id: e.agent.owner_id ?? "",
|
|
279
|
+
promptVersion: (n = e.agent.llm) == null ? void 0 : n.prompt_version,
|
|
471
280
|
behavior: {
|
|
472
|
-
role:
|
|
473
|
-
personality:
|
|
474
|
-
instructions: (
|
|
281
|
+
role: r == null ? void 0 : r.role,
|
|
282
|
+
personality: r == null ? void 0 : r.personality,
|
|
283
|
+
instructions: (c = e.agent.llm) == null ? void 0 : c.instructions
|
|
475
284
|
},
|
|
476
|
-
temperature: (
|
|
477
|
-
knowledgeSource:
|
|
478
|
-
starterQuestionsCount: (
|
|
479
|
-
topicsToAvoid:
|
|
480
|
-
maxResponseLength:
|
|
285
|
+
temperature: (i = e.agent.llm) == null ? void 0 : i.temperature,
|
|
286
|
+
knowledgeSource: r == null ? void 0 : r.knowledge_source,
|
|
287
|
+
starterQuestionsCount: (u = (d = e.agent.knowledge) == null ? void 0 : d.starter_message) == null ? void 0 : u.length,
|
|
288
|
+
topicsToAvoid: r == null ? void 0 : r.topics_to_avoid,
|
|
289
|
+
maxResponseLength: r == null ? void 0 : r.max_response_length
|
|
481
290
|
};
|
|
482
291
|
return {
|
|
483
|
-
...
|
|
292
|
+
...o,
|
|
484
293
|
additionalProperties: {},
|
|
485
|
-
isEnabled:
|
|
486
|
-
getRandom,
|
|
487
|
-
enrich(
|
|
488
|
-
const props = {};
|
|
489
|
-
if (properties && typeof properties !== "object") {
|
|
490
|
-
throw new Error("properties must be a flat json object");
|
|
491
|
-
}
|
|
492
|
-
for (let prop in properties) {
|
|
493
|
-
if (typeof properties[prop] === "string" || typeof properties[prop] === "number") {
|
|
494
|
-
props[prop] = properties[prop];
|
|
495
|
-
}
|
|
496
|
-
}
|
|
294
|
+
isEnabled: e.isEnabled ?? !0,
|
|
295
|
+
getRandom: K,
|
|
296
|
+
enrich(h) {
|
|
497
297
|
this.additionalProperties = {
|
|
498
298
|
...this.additionalProperties,
|
|
499
|
-
...
|
|
299
|
+
...h
|
|
500
300
|
};
|
|
501
301
|
},
|
|
502
|
-
async track(
|
|
503
|
-
if (!this.isEnabled)
|
|
302
|
+
async track(h, _) {
|
|
303
|
+
if (!this.isEnabled)
|
|
504
304
|
return Promise.resolve();
|
|
505
|
-
}
|
|
506
305
|
const {
|
|
507
|
-
audioPath,
|
|
508
|
-
...
|
|
509
|
-
} =
|
|
510
|
-
const options = {
|
|
306
|
+
audioPath: k,
|
|
307
|
+
...D
|
|
308
|
+
} = _ || {}, R = {
|
|
511
309
|
method: "POST",
|
|
512
310
|
headers: {
|
|
513
311
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
514
312
|
},
|
|
515
313
|
body: new URLSearchParams({
|
|
516
314
|
data: JSON.stringify([{
|
|
517
|
-
event,
|
|
315
|
+
event: h,
|
|
518
316
|
properties: {
|
|
519
317
|
...this.additionalProperties,
|
|
520
|
-
...
|
|
521
|
-
...
|
|
522
|
-
source,
|
|
318
|
+
...D,
|
|
319
|
+
...o,
|
|
320
|
+
source: t,
|
|
523
321
|
time: Date.now(),
|
|
524
322
|
$insert_id: this.getRandom(),
|
|
525
323
|
origin: window.location.href,
|
|
@@ -531,1317 +329,1040 @@ function initializeAnalytics(config) {
|
|
|
531
329
|
})
|
|
532
330
|
};
|
|
533
331
|
try {
|
|
534
|
-
return await fetch(
|
|
535
|
-
} catch (
|
|
536
|
-
return console.error(
|
|
332
|
+
return await fetch(Fe, R).then((S) => S.json());
|
|
333
|
+
} catch (S) {
|
|
334
|
+
return console.error(S);
|
|
537
335
|
}
|
|
538
336
|
},
|
|
539
|
-
linkTrack(
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const allDependenciesResolved = dependencies.every((value) => linkedEvent.resolvedDependencies.includes(value));
|
|
555
|
-
if (allDependenciesResolved) {
|
|
556
|
-
const aggregatedProps = dependencies.reduce((acc, curr) => {
|
|
557
|
-
if (linkedEvent.events[curr]) {
|
|
558
|
-
return {
|
|
559
|
-
...acc,
|
|
560
|
-
...linkedEvent.events[curr].props
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
return acc;
|
|
564
|
-
}, {});
|
|
565
|
-
this.track(mixpanelEvent, aggregatedProps);
|
|
566
|
-
linkedEvent.resolvedDependencies = linkedEvent.resolvedDependencies.filter((event2) => !dependencies.includes(event2));
|
|
567
|
-
dependencies.forEach((event2) => {
|
|
568
|
-
delete linkedEvent.events[event2];
|
|
337
|
+
linkTrack(h, _, k, D) {
|
|
338
|
+
Z[h] || (Z[h] = {
|
|
339
|
+
events: {},
|
|
340
|
+
resolvedDependencies: []
|
|
341
|
+
}), D.includes(k) || D.push(k);
|
|
342
|
+
const R = Z[h];
|
|
343
|
+
if (R.events[k] = {
|
|
344
|
+
props: _
|
|
345
|
+
}, R.resolvedDependencies.push(k), D.every((B) => R.resolvedDependencies.includes(B))) {
|
|
346
|
+
const B = D.reduce((l, m) => R.events[m] ? {
|
|
347
|
+
...l,
|
|
348
|
+
...R.events[m].props
|
|
349
|
+
} : l, {});
|
|
350
|
+
this.track(h, B), R.resolvedDependencies = R.resolvedDependencies.filter((l) => !D.includes(l)), D.forEach((l) => {
|
|
351
|
+
delete R.events[l];
|
|
569
352
|
});
|
|
570
353
|
}
|
|
571
354
|
}
|
|
572
355
|
};
|
|
573
356
|
}
|
|
574
|
-
function
|
|
575
|
-
let
|
|
357
|
+
function Je() {
|
|
358
|
+
let e = 0;
|
|
576
359
|
return {
|
|
577
|
-
reset: () =>
|
|
578
|
-
update: () =>
|
|
579
|
-
get: (
|
|
360
|
+
reset: () => e = 0,
|
|
361
|
+
update: () => e = Date.now(),
|
|
362
|
+
get: (t = !1) => t ? Date.now() - e : e
|
|
580
363
|
};
|
|
581
364
|
}
|
|
582
|
-
const
|
|
583
|
-
function
|
|
584
|
-
return
|
|
365
|
+
const F = Je();
|
|
366
|
+
function le(e) {
|
|
367
|
+
return e === b.Playground ? {
|
|
585
368
|
headers: {
|
|
586
|
-
[
|
|
369
|
+
[be]: "true"
|
|
587
370
|
}
|
|
588
371
|
} : {};
|
|
589
372
|
}
|
|
590
|
-
async function
|
|
373
|
+
async function ue(e, t, a, r, o = !1, s) {
|
|
591
374
|
try {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
return {
|
|
604
|
-
chat,
|
|
605
|
-
chatMode: (chat == null ? void 0 : chat.chat_mode) ?? chatMode
|
|
375
|
+
return !s && r !== b.DirectPlayback && (s = await t.newChat(e.id, {
|
|
376
|
+
persist: o
|
|
377
|
+
}, le(r)), a.track("agent-chat", {
|
|
378
|
+
event: "created",
|
|
379
|
+
chat_id: s.id,
|
|
380
|
+
agent_id: e.id,
|
|
381
|
+
mode: r
|
|
382
|
+
})), {
|
|
383
|
+
chat: s,
|
|
384
|
+
chatMode: (s == null ? void 0 : s.chat_mode) ?? r
|
|
606
385
|
};
|
|
607
|
-
} catch (
|
|
386
|
+
} catch (n) {
|
|
608
387
|
try {
|
|
609
|
-
const
|
|
610
|
-
if ((
|
|
388
|
+
const c = JSON.parse(n.message);
|
|
389
|
+
if ((c == null ? void 0 : c.kind) === "InsufficientCreditsError")
|
|
611
390
|
throw new Error("InsufficientCreditsError");
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
console.error("Error parsing the error message:", e);
|
|
391
|
+
} catch (c) {
|
|
392
|
+
console.error("Error parsing the error message:", c);
|
|
615
393
|
}
|
|
616
394
|
throw new Error("Cannot create new chat");
|
|
617
395
|
}
|
|
618
396
|
}
|
|
619
|
-
function
|
|
620
|
-
|
|
621
|
-
return initialMessages;
|
|
622
|
-
}
|
|
623
|
-
return [];
|
|
397
|
+
function We(e) {
|
|
398
|
+
return e && e.length > 0 ? e : [];
|
|
624
399
|
}
|
|
625
|
-
function
|
|
626
|
-
return new Promise((
|
|
627
|
-
const {
|
|
628
|
-
callbacks,
|
|
629
|
-
host,
|
|
630
|
-
auth
|
|
631
|
-
} = options;
|
|
400
|
+
function Ue(e) {
|
|
401
|
+
return new Promise((t, a) => {
|
|
632
402
|
const {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
socket.onopen = (e) => {
|
|
647
|
-
onOpen == null ? void 0 : onOpen(e);
|
|
648
|
-
resolve(socket);
|
|
403
|
+
callbacks: r,
|
|
404
|
+
host: o,
|
|
405
|
+
auth: s
|
|
406
|
+
} = e, {
|
|
407
|
+
onMessage: n = null,
|
|
408
|
+
onOpen: c = null,
|
|
409
|
+
onClose: i = null,
|
|
410
|
+
onError: d = null
|
|
411
|
+
} = r || {}, u = new WebSocket(`${o}?authorization=${oe(s)}`);
|
|
412
|
+
u.onmessage = n, u.onclose = i, u.onerror = (h) => {
|
|
413
|
+
console.error(h), d == null || d("Websocket failed to connect", h), a(h);
|
|
414
|
+
}, u.onopen = (h) => {
|
|
415
|
+
c == null || c(h), t(u);
|
|
649
416
|
};
|
|
650
417
|
});
|
|
651
418
|
}
|
|
652
|
-
async function
|
|
419
|
+
async function Ke(e) {
|
|
653
420
|
const {
|
|
654
|
-
retries = 1
|
|
655
|
-
} =
|
|
656
|
-
let
|
|
657
|
-
for (let
|
|
421
|
+
retries: t = 1
|
|
422
|
+
} = e;
|
|
423
|
+
let a = null;
|
|
424
|
+
for (let r = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; r++)
|
|
658
425
|
try {
|
|
659
|
-
|
|
660
|
-
} catch (
|
|
661
|
-
if (
|
|
662
|
-
throw
|
|
663
|
-
|
|
664
|
-
await sleep(attempt * 500);
|
|
426
|
+
a = await Ue(e);
|
|
427
|
+
} catch (o) {
|
|
428
|
+
if (r === t)
|
|
429
|
+
throw o;
|
|
430
|
+
await ie(r * 500);
|
|
665
431
|
}
|
|
666
|
-
|
|
667
|
-
return socket;
|
|
432
|
+
return a;
|
|
668
433
|
}
|
|
669
|
-
async function
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
host,
|
|
434
|
+
async function He(e, t, a) {
|
|
435
|
+
const r = a != null && a.onMessage ? [a.onMessage] : [], o = await Ke({
|
|
436
|
+
auth: e,
|
|
437
|
+
host: t,
|
|
674
438
|
callbacks: {
|
|
675
|
-
onError: (
|
|
676
|
-
var
|
|
677
|
-
return (
|
|
439
|
+
onError: (s) => {
|
|
440
|
+
var n;
|
|
441
|
+
return (n = a.onError) == null ? void 0 : n.call(a, new pe(s));
|
|
678
442
|
},
|
|
679
|
-
onMessage(
|
|
680
|
-
const
|
|
681
|
-
|
|
443
|
+
onMessage(s) {
|
|
444
|
+
const n = JSON.parse(s.data);
|
|
445
|
+
r.forEach((c) => c(n.event, n));
|
|
682
446
|
}
|
|
683
447
|
}
|
|
684
448
|
});
|
|
685
449
|
return {
|
|
686
|
-
socket,
|
|
687
|
-
disconnect: () =>
|
|
688
|
-
subscribeToEvents: (
|
|
450
|
+
socket: o,
|
|
451
|
+
disconnect: () => o.close(),
|
|
452
|
+
subscribeToEvents: (s) => r.push(s)
|
|
689
453
|
};
|
|
690
454
|
}
|
|
691
|
-
function
|
|
692
|
-
if (
|
|
693
|
-
return
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
content += chatEventQueue[currentSequence++];
|
|
699
|
-
}
|
|
700
|
-
return content;
|
|
455
|
+
function qe(e) {
|
|
456
|
+
if (e.answer !== void 0)
|
|
457
|
+
return e.answer;
|
|
458
|
+
let t = 0, a = "";
|
|
459
|
+
for (; t in e; )
|
|
460
|
+
a += e[t++];
|
|
461
|
+
return a;
|
|
701
462
|
}
|
|
702
|
-
function
|
|
703
|
-
const
|
|
704
|
-
if (!(
|
|
463
|
+
function Ve(e, t, a, r, o) {
|
|
464
|
+
const s = r.messages[r.messages.length - 1];
|
|
465
|
+
if (!(e === U.Partial || e === U.Answer) || (s == null ? void 0 : s.role) !== "assistant")
|
|
705
466
|
return;
|
|
706
|
-
}
|
|
707
467
|
const {
|
|
708
|
-
content,
|
|
709
|
-
sequence
|
|
710
|
-
} =
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
chatEventQueue["answer"] = content;
|
|
715
|
-
}
|
|
716
|
-
const messageContent = getMessageContent(chatEventQueue);
|
|
717
|
-
if (lastMessage.content !== messageContent || event === ChatProgress.Answer) {
|
|
718
|
-
lastMessage.content = messageContent;
|
|
719
|
-
onNewMessage == null ? void 0 : onNewMessage([...items.messages], event);
|
|
720
|
-
}
|
|
468
|
+
content: n,
|
|
469
|
+
sequence: c
|
|
470
|
+
} = t;
|
|
471
|
+
e === U.Partial ? a[c] = n : a.answer = n;
|
|
472
|
+
const i = qe(a);
|
|
473
|
+
(s.content !== i || e === U.Answer) && (s.content = i, o == null || o([...r.messages], e));
|
|
721
474
|
}
|
|
722
|
-
function
|
|
723
|
-
let
|
|
475
|
+
function Xe(e, t, a, r, o) {
|
|
476
|
+
let s = {};
|
|
724
477
|
return {
|
|
725
|
-
clearQueue: () =>
|
|
726
|
-
onMessage: (
|
|
727
|
-
var
|
|
728
|
-
if ("content" in
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
messages: items.messages.length,
|
|
733
|
-
mode: items.chatMode
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
} else {
|
|
737
|
-
const SEvent = StreamEvents;
|
|
738
|
-
const completedEvents = [SEvent.StreamVideoDone, SEvent.StreamVideoError, SEvent.StreamVideoRejected];
|
|
739
|
-
const failedEvents = [SEvent.StreamFailed, SEvent.StreamVideoError, SEvent.StreamVideoRejected];
|
|
740
|
-
const props = getStreamAnalyticsProps(data, agentEntity, {
|
|
741
|
-
mode: items.chatMode
|
|
478
|
+
clearQueue: () => s = {},
|
|
479
|
+
onMessage: (n, c) => {
|
|
480
|
+
var i, d;
|
|
481
|
+
if ("content" in c)
|
|
482
|
+
Ve(n, c, s, t, a.callbacks.onNewMessage), n === U.Answer && e.track("agent-message-received", {
|
|
483
|
+
messages: t.messages.length,
|
|
484
|
+
mode: t.chatMode
|
|
742
485
|
});
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
if (failedEvents.includes(event)) {
|
|
761
|
-
(_b = (_a = options.callbacks).onError) == null ? void 0 : _b.call(_a, new Error(`Stream failed with event ${event}`), {
|
|
762
|
-
data
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
if (data.event === SEvent.StreamDone) {
|
|
766
|
-
onStreamDone();
|
|
486
|
+
else {
|
|
487
|
+
const u = N, h = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], _ = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], k = xe(c, r, {
|
|
488
|
+
mode: t.chatMode
|
|
489
|
+
});
|
|
490
|
+
if (n = n, n === u.StreamVideoCreated)
|
|
491
|
+
e.linkTrack("agent-video", k, u.StreamVideoCreated, ["start"]);
|
|
492
|
+
else if (h.includes(n)) {
|
|
493
|
+
const D = n.split("/")[1];
|
|
494
|
+
_.includes(n) ? e.track("agent-video", {
|
|
495
|
+
...k,
|
|
496
|
+
event: D
|
|
497
|
+
}) : e.linkTrack("agent-video", {
|
|
498
|
+
...k,
|
|
499
|
+
event: D
|
|
500
|
+
}, n, ["done"]);
|
|
767
501
|
}
|
|
502
|
+
_.includes(n) && ((d = (i = a.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${n}`), {
|
|
503
|
+
data: c
|
|
504
|
+
})), c.event === u.StreamDone && o();
|
|
768
505
|
}
|
|
769
506
|
}
|
|
770
507
|
};
|
|
771
508
|
}
|
|
772
|
-
function
|
|
773
|
-
const
|
|
509
|
+
function Ye(e, t, a, r) {
|
|
510
|
+
const o = ee(e, `${t}/agents/${a}`, r);
|
|
774
511
|
return {
|
|
775
|
-
createStream(
|
|
776
|
-
return
|
|
777
|
-
output_resolution:
|
|
778
|
-
compatibility_mode:
|
|
779
|
-
stream_warmup:
|
|
780
|
-
session_timeout:
|
|
781
|
-
fluent:
|
|
512
|
+
createStream(s) {
|
|
513
|
+
return o.post("/streams", {
|
|
514
|
+
output_resolution: s.output_resolution,
|
|
515
|
+
compatibility_mode: s.compatibility_mode,
|
|
516
|
+
stream_warmup: s.stream_warmup,
|
|
517
|
+
session_timeout: s.session_timeout,
|
|
518
|
+
fluent: s.fluent
|
|
782
519
|
});
|
|
783
520
|
},
|
|
784
|
-
startConnection(
|
|
785
|
-
return
|
|
786
|
-
session_id:
|
|
787
|
-
answer
|
|
521
|
+
startConnection(s, n, c) {
|
|
522
|
+
return o.post(`/streams/${s}/sdp`, {
|
|
523
|
+
session_id: c,
|
|
524
|
+
answer: n
|
|
788
525
|
});
|
|
789
526
|
},
|
|
790
|
-
addIceCandidate(
|
|
791
|
-
return
|
|
792
|
-
session_id:
|
|
793
|
-
...
|
|
527
|
+
addIceCandidate(s, n, c) {
|
|
528
|
+
return o.post(`/streams/${s}/ice`, {
|
|
529
|
+
session_id: c,
|
|
530
|
+
...n
|
|
794
531
|
});
|
|
795
532
|
},
|
|
796
|
-
sendStreamRequest(
|
|
797
|
-
return
|
|
798
|
-
session_id:
|
|
799
|
-
...
|
|
533
|
+
sendStreamRequest(s, n, c) {
|
|
534
|
+
return o.post(`/streams/${s}`, {
|
|
535
|
+
session_id: n,
|
|
536
|
+
...c
|
|
800
537
|
});
|
|
801
538
|
},
|
|
802
|
-
close(
|
|
803
|
-
return
|
|
804
|
-
session_id:
|
|
539
|
+
close(s, n) {
|
|
540
|
+
return o.delete(`/streams/${s}`, {
|
|
541
|
+
session_id: n
|
|
805
542
|
});
|
|
806
543
|
}
|
|
807
544
|
};
|
|
808
545
|
}
|
|
809
|
-
function
|
|
810
|
-
const
|
|
546
|
+
function Qe(e, t, a, r) {
|
|
547
|
+
const o = ee(e, `${t}/agents/${a}`, r);
|
|
811
548
|
return {
|
|
812
|
-
createStream(
|
|
813
|
-
return
|
|
814
|
-
driver_url:
|
|
815
|
-
face:
|
|
816
|
-
config:
|
|
817
|
-
output_resolution:
|
|
818
|
-
compatibility_mode:
|
|
819
|
-
stream_warmup:
|
|
820
|
-
session_timeout:
|
|
821
|
-
fluent:
|
|
822
|
-
},
|
|
549
|
+
createStream(s, n) {
|
|
550
|
+
return o.post("/streams", {
|
|
551
|
+
driver_url: s.driver_url,
|
|
552
|
+
face: s.face,
|
|
553
|
+
config: s.config,
|
|
554
|
+
output_resolution: s.output_resolution,
|
|
555
|
+
compatibility_mode: s.compatibility_mode,
|
|
556
|
+
stream_warmup: s.stream_warmup,
|
|
557
|
+
session_timeout: s.session_timeout,
|
|
558
|
+
fluent: s.fluent
|
|
559
|
+
}, n);
|
|
823
560
|
},
|
|
824
|
-
startConnection(
|
|
825
|
-
return
|
|
826
|
-
session_id:
|
|
827
|
-
answer
|
|
828
|
-
},
|
|
561
|
+
startConnection(s, n, c, i) {
|
|
562
|
+
return o.post(`/streams/${s}/sdp`, {
|
|
563
|
+
session_id: c,
|
|
564
|
+
answer: n
|
|
565
|
+
}, i);
|
|
829
566
|
},
|
|
830
|
-
addIceCandidate(
|
|
831
|
-
return
|
|
832
|
-
session_id:
|
|
833
|
-
...
|
|
834
|
-
},
|
|
567
|
+
addIceCandidate(s, n, c, i) {
|
|
568
|
+
return o.post(`/streams/${s}/ice`, {
|
|
569
|
+
session_id: c,
|
|
570
|
+
...n
|
|
571
|
+
}, i);
|
|
835
572
|
},
|
|
836
|
-
sendStreamRequest(
|
|
837
|
-
return
|
|
838
|
-
session_id:
|
|
839
|
-
...
|
|
840
|
-
},
|
|
573
|
+
sendStreamRequest(s, n, c, i) {
|
|
574
|
+
return o.post(`/streams/${s}`, {
|
|
575
|
+
session_id: n,
|
|
576
|
+
...c
|
|
577
|
+
}, i);
|
|
841
578
|
},
|
|
842
|
-
close(
|
|
843
|
-
return
|
|
844
|
-
session_id:
|
|
845
|
-
},
|
|
579
|
+
close(s, n, c) {
|
|
580
|
+
return o.delete(`/streams/${s}`, {
|
|
581
|
+
session_id: n
|
|
582
|
+
}, c);
|
|
846
583
|
}
|
|
847
584
|
};
|
|
848
585
|
}
|
|
849
|
-
function
|
|
850
|
-
const
|
|
586
|
+
function Ze(e, t, a) {
|
|
587
|
+
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
851
588
|
return {
|
|
852
|
-
duration,
|
|
853
|
-
bytesReceived:
|
|
854
|
-
bitrate: Math.round((
|
|
855
|
-
packetsReceived:
|
|
856
|
-
packetsLost:
|
|
857
|
-
framesDropped:
|
|
858
|
-
framesDecoded:
|
|
859
|
-
jitter:
|
|
860
|
-
avgJitterDelayInInterval: (
|
|
861
|
-
jitterBufferEmittedCount:
|
|
862
|
-
jitterBufferDelay: (
|
|
863
|
-
framesPerSecond:
|
|
864
|
-
freezeCount:
|
|
865
|
-
freezeDuration:
|
|
866
|
-
lowFpsCount
|
|
589
|
+
duration: r,
|
|
590
|
+
bytesReceived: t.bytesReceived - e.bytesReceived,
|
|
591
|
+
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / r),
|
|
592
|
+
packetsReceived: t.packetsReceived - e.packetsReceived,
|
|
593
|
+
packetsLost: t.packetsLost - e.packetsLost,
|
|
594
|
+
framesDropped: t.framesDropped - e.framesDropped,
|
|
595
|
+
framesDecoded: t.framesDecoded - e.framesDecoded,
|
|
596
|
+
jitter: t.jitter,
|
|
597
|
+
avgJitterDelayInInterval: (t.jitterBufferDelay - e.jitterBufferDelay) / (t.jitterBufferEmittedCount - e.jitterBufferEmittedCount),
|
|
598
|
+
jitterBufferEmittedCount: t.jitterBufferEmittedCount - e.jitterBufferEmittedCount,
|
|
599
|
+
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / r,
|
|
600
|
+
framesPerSecond: t.framesPerSecond,
|
|
601
|
+
freezeCount: t.freezeCount - e.freezeCount,
|
|
602
|
+
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
603
|
+
lowFpsCount: a
|
|
867
604
|
};
|
|
868
605
|
}
|
|
869
|
-
function
|
|
870
|
-
return
|
|
606
|
+
function Ge(e) {
|
|
607
|
+
return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
|
|
871
608
|
const {
|
|
872
|
-
timestamp,
|
|
873
|
-
...
|
|
874
|
-
} =
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
causes
|
|
878
|
-
}
|
|
879
|
-
if (report.framesPerSecond < 21) {
|
|
880
|
-
causes.push("low fps");
|
|
881
|
-
}
|
|
882
|
-
if (report.framesDropped > 0) {
|
|
883
|
-
causes.push("frames dropped");
|
|
884
|
-
}
|
|
885
|
-
if (report.packetsLost > 0) {
|
|
886
|
-
causes.push("packet loss");
|
|
887
|
-
}
|
|
888
|
-
return {
|
|
889
|
-
...updatedReport,
|
|
890
|
-
causes
|
|
609
|
+
timestamp: a,
|
|
610
|
+
...r
|
|
611
|
+
} = t, o = [];
|
|
612
|
+
return t.freezeCount > 0 && o.push("freeze"), t.framesPerSecond < 21 && o.push("low fps"), t.framesDropped > 0 && o.push("frames dropped"), t.packetsLost > 0 && o.push("packet loss"), {
|
|
613
|
+
...r,
|
|
614
|
+
causes: o
|
|
891
615
|
};
|
|
892
616
|
});
|
|
893
617
|
}
|
|
894
|
-
function
|
|
895
|
-
let
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
if (report && report.type === "codec" && report.mimeType.startsWith("video")) {
|
|
899
|
-
codec = report.mimeType.split("/")[1];
|
|
900
|
-
}
|
|
901
|
-
if (report && report.type === "candidate-pair") {
|
|
902
|
-
currRtt = report.currentRoundTripTime;
|
|
903
|
-
}
|
|
904
|
-
if (report && report.type === "inbound-rtp" && report.kind === "video") {
|
|
618
|
+
function Oe(e) {
|
|
619
|
+
let t = "", a = 0;
|
|
620
|
+
for (const r of e.values())
|
|
621
|
+
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")
|
|
905
622
|
return {
|
|
906
|
-
codec,
|
|
907
|
-
rtt:
|
|
908
|
-
timestamp:
|
|
909
|
-
bytesReceived:
|
|
910
|
-
packetsReceived:
|
|
911
|
-
packetsLost:
|
|
912
|
-
framesDropped:
|
|
913
|
-
framesDecoded:
|
|
914
|
-
jitter:
|
|
915
|
-
jitterBufferDelay:
|
|
916
|
-
jitterBufferEmittedCount:
|
|
917
|
-
avgJitterDelayInInterval:
|
|
918
|
-
frameWidth:
|
|
919
|
-
frameHeight:
|
|
920
|
-
framesPerSecond:
|
|
921
|
-
freezeCount:
|
|
922
|
-
freezeDuration:
|
|
623
|
+
codec: t,
|
|
624
|
+
rtt: a,
|
|
625
|
+
timestamp: r.timestamp,
|
|
626
|
+
bytesReceived: r.bytesReceived,
|
|
627
|
+
packetsReceived: r.packetsReceived,
|
|
628
|
+
packetsLost: r.packetsLost,
|
|
629
|
+
framesDropped: r.framesDropped,
|
|
630
|
+
framesDecoded: r.framesDecoded,
|
|
631
|
+
jitter: r.jitter,
|
|
632
|
+
jitterBufferDelay: r.jitterBufferDelay,
|
|
633
|
+
jitterBufferEmittedCount: r.jitterBufferEmittedCount,
|
|
634
|
+
avgJitterDelayInInterval: r.jitterBufferDelay / r.jitterBufferEmittedCount,
|
|
635
|
+
frameWidth: r.frameWidth,
|
|
636
|
+
frameHeight: r.frameHeight,
|
|
637
|
+
framesPerSecond: r.framesPerSecond,
|
|
638
|
+
freezeCount: r.freezeCount,
|
|
639
|
+
freezeDuration: r.totalFreezesDuration
|
|
923
640
|
};
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
641
|
return {};
|
|
927
642
|
}
|
|
928
|
-
function
|
|
929
|
-
const
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
jitterBufferDelay: report.jitterBufferDelay - stats[index - 1].jitterBufferDelay,
|
|
982
|
-
jitterBufferEmittedCount: report.jitterBufferEmittedCount - stats[index - 1].jitterBufferEmittedCount,
|
|
983
|
-
avgJitterDelayInInterval: (report.jitterBufferDelay - stats[index - 1].jitterBufferDelay) / (report.jitterBufferEmittedCount - stats[index - 1].jitterBufferEmittedCount),
|
|
984
|
-
framesPerSecond: report.framesPerSecond,
|
|
985
|
-
freezeCount: report.freezeCount - stats[index - 1].freezeCount,
|
|
986
|
-
freezeDuration: report.freezeDuration - stats[index - 1].freezeDuration
|
|
987
|
-
};
|
|
988
|
-
});
|
|
989
|
-
const anomalies = extractAnomalies(differentialReport);
|
|
990
|
-
const lowFpsCount = anomalies.reduce((acc, report) => acc + (report.causes.includes("low fps") ? 1 : 0), 0);
|
|
991
|
-
const avgJittersSamples = differentialReport.filter((stat) => !!stat.avgJitterDelayInInterval).map((stat) => stat.avgJitterDelayInInterval);
|
|
992
|
-
const avgRttSamples = differentialReport.filter((stat) => !!stat.rtt).map((stat) => stat.rtt);
|
|
643
|
+
function et(e, t, a) {
|
|
644
|
+
const r = e.map((i, d) => d === 0 ? a ? {
|
|
645
|
+
timestamp: i.timestamp,
|
|
646
|
+
duration: 0,
|
|
647
|
+
rtt: i.rtt,
|
|
648
|
+
bytesReceived: i.bytesReceived - a.bytesReceived,
|
|
649
|
+
bitrate: (i.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
|
|
650
|
+
packetsReceived: i.packetsReceived - a.packetsReceived,
|
|
651
|
+
packetsLost: i.packetsLost - a.packetsLost,
|
|
652
|
+
framesDropped: i.framesDropped - a.framesDropped,
|
|
653
|
+
framesDecoded: i.framesDecoded - a.framesDecoded,
|
|
654
|
+
jitter: i.jitter,
|
|
655
|
+
jitterBufferDelay: i.jitterBufferDelay - a.jitterBufferDelay,
|
|
656
|
+
jitterBufferEmittedCount: i.jitterBufferEmittedCount - a.jitterBufferEmittedCount,
|
|
657
|
+
avgJitterDelayInInterval: (i.jitterBufferDelay - a.jitterBufferDelay) / (i.jitterBufferEmittedCount - a.jitterBufferEmittedCount),
|
|
658
|
+
framesPerSecond: i.framesPerSecond,
|
|
659
|
+
freezeCount: i.freezeCount - a.freezeCount,
|
|
660
|
+
freezeDuration: i.freezeDuration - a.freezeDuration
|
|
661
|
+
} : {
|
|
662
|
+
timestamp: i.timestamp,
|
|
663
|
+
rtt: i.rtt,
|
|
664
|
+
duration: 0,
|
|
665
|
+
bytesReceived: i.bytesReceived,
|
|
666
|
+
bitrate: i.bytesReceived * 8 / (t / 1e3),
|
|
667
|
+
packetsReceived: i.packetsReceived,
|
|
668
|
+
packetsLost: i.packetsLost,
|
|
669
|
+
framesDropped: i.framesDropped,
|
|
670
|
+
framesDecoded: i.framesDecoded,
|
|
671
|
+
jitter: i.jitter,
|
|
672
|
+
jitterBufferDelay: i.jitterBufferDelay,
|
|
673
|
+
jitterBufferEmittedCount: i.jitterBufferEmittedCount,
|
|
674
|
+
avgJitterDelayInInterval: i.jitterBufferDelay / i.jitterBufferEmittedCount,
|
|
675
|
+
framesPerSecond: i.framesPerSecond,
|
|
676
|
+
freezeCount: i.freezeCount,
|
|
677
|
+
freezeDuration: i.freezeDuration
|
|
678
|
+
} : {
|
|
679
|
+
timestamp: i.timestamp,
|
|
680
|
+
duration: t * d / 1e3,
|
|
681
|
+
rtt: i.rtt,
|
|
682
|
+
bytesReceived: i.bytesReceived - e[d - 1].bytesReceived,
|
|
683
|
+
bitrate: (i.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
|
|
684
|
+
packetsReceived: i.packetsReceived - e[d - 1].packetsReceived,
|
|
685
|
+
packetsLost: i.packetsLost - e[d - 1].packetsLost,
|
|
686
|
+
framesDropped: i.framesDropped - e[d - 1].framesDropped,
|
|
687
|
+
framesDecoded: i.framesDecoded - e[d - 1].framesDecoded,
|
|
688
|
+
jitter: i.jitter,
|
|
689
|
+
jitterBufferDelay: i.jitterBufferDelay - e[d - 1].jitterBufferDelay,
|
|
690
|
+
jitterBufferEmittedCount: i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
|
|
691
|
+
avgJitterDelayInInterval: (i.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
|
|
692
|
+
framesPerSecond: i.framesPerSecond,
|
|
693
|
+
freezeCount: i.freezeCount - e[d - 1].freezeCount,
|
|
694
|
+
freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
|
|
695
|
+
}), o = Ge(r), s = o.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), n = r.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), c = r.filter((i) => !!i.rtt).map((i) => i.rtt);
|
|
993
696
|
return {
|
|
994
697
|
webRTCStats: {
|
|
995
|
-
anomalies,
|
|
996
|
-
minRtt: Math.min(...
|
|
997
|
-
avgRtt:
|
|
998
|
-
maxRtt: Math.max(...
|
|
999
|
-
aggregateReport:
|
|
1000
|
-
minJitterDelayInInterval: Math.min(...
|
|
1001
|
-
maxJitterDelayInInterval: Math.max(...
|
|
1002
|
-
avgJitterDelayInInterval:
|
|
698
|
+
anomalies: o,
|
|
699
|
+
minRtt: Math.min(...c),
|
|
700
|
+
avgRtt: te(c),
|
|
701
|
+
maxRtt: Math.max(...c),
|
|
702
|
+
aggregateReport: Ze(e[0], e[e.length - 1], s),
|
|
703
|
+
minJitterDelayInInterval: Math.min(...n),
|
|
704
|
+
maxJitterDelayInInterval: Math.max(...n),
|
|
705
|
+
avgJitterDelayInInterval: te(n)
|
|
1003
706
|
},
|
|
1004
|
-
codec:
|
|
1005
|
-
resolution: `${
|
|
707
|
+
codec: e[0].codec,
|
|
708
|
+
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
1006
709
|
};
|
|
1007
710
|
}
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
for (const report of stats.values()) {
|
|
1019
|
-
if (report && report.type === "inbound-rtp" && report.kind === "video") {
|
|
1020
|
-
const delay = report.jitterBufferDelay;
|
|
1021
|
-
const count = report.jitterBufferEmittedCount;
|
|
1022
|
-
if (prevCount && count > prevCount) {
|
|
1023
|
-
const deltaDelay = delay - prevDelay;
|
|
1024
|
-
const deltaCount = count - prevCount;
|
|
1025
|
-
avgJitterDelayInInterval = deltaDelay / deltaCount;
|
|
711
|
+
const O = 100, tt = Math.max(Math.ceil(400 / O), 1), rt = 0.25, nt = 0.28;
|
|
712
|
+
function at() {
|
|
713
|
+
let e = 0, t, a, r = 0;
|
|
714
|
+
return (o) => {
|
|
715
|
+
for (const s of o.values())
|
|
716
|
+
if (s && s.type === "inbound-rtp" && s.kind === "video") {
|
|
717
|
+
const n = s.jitterBufferDelay, c = s.jitterBufferEmittedCount;
|
|
718
|
+
if (a && c > a) {
|
|
719
|
+
const u = n - t, h = c - a;
|
|
720
|
+
r = u / h;
|
|
1026
721
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
isReceiving,
|
|
1034
|
-
avgJitterDelayInInterval,
|
|
1035
|
-
freezeCount: report.freezeCount
|
|
722
|
+
t = n, a = c;
|
|
723
|
+
const i = s.framesDecoded, d = i - e > 0;
|
|
724
|
+
return e = i, {
|
|
725
|
+
isReceiving: d,
|
|
726
|
+
avgJitterDelayInInterval: r,
|
|
727
|
+
freezeCount: s.freezeCount
|
|
1036
728
|
};
|
|
1037
729
|
}
|
|
1038
|
-
}
|
|
1039
730
|
return {
|
|
1040
|
-
isReceiving:
|
|
1041
|
-
avgJitterDelayInInterval
|
|
731
|
+
isReceiving: !1,
|
|
732
|
+
avgJitterDelayInInterval: r
|
|
1042
733
|
};
|
|
1043
734
|
};
|
|
1044
735
|
}
|
|
1045
|
-
function
|
|
1046
|
-
let
|
|
1047
|
-
|
|
1048
|
-
let notReceivingNumIntervals = 0;
|
|
1049
|
-
let isStreaming = false;
|
|
1050
|
-
let prevLowConnState = ConnectivityState.Unknown;
|
|
1051
|
-
let currLowConnState = ConnectivityState.Unknown;
|
|
1052
|
-
let currFreezeCount = 0;
|
|
1053
|
-
let prevFreezeCount = 0;
|
|
1054
|
-
const isReceivingVideoBytes = createVideoStatsAnalyzer();
|
|
736
|
+
function it(e, t, a, r, o, s = !1) {
|
|
737
|
+
let n = [], c, i = 0, d = !1, u = V.Unknown, h = V.Unknown, _ = 0, k = 0;
|
|
738
|
+
const D = at();
|
|
1055
739
|
return setInterval(async () => {
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
if (
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
currLowConnState = avgJitterDelayInInterval < LOW_JITTER_TRESHOLD ? ConnectivityState.Strong : avgJitterDelayInInterval > HIGH_JITTER_TRESHOLD && currFreezeCount > 1 ? ConnectivityState.Weak : prevLowConnState;
|
|
1067
|
-
if (currLowConnState !== prevLowConnState) {
|
|
1068
|
-
onConnectivityStateChange == null ? void 0 : onConnectivityStateChange(currLowConnState);
|
|
1069
|
-
prevLowConnState = currLowConnState;
|
|
1070
|
-
prevFreezeCount += currFreezeCount;
|
|
1071
|
-
currFreezeCount = 0;
|
|
1072
|
-
}
|
|
1073
|
-
if (!isStreaming) {
|
|
1074
|
-
onVideoStateChange == null ? void 0 : onVideoStateChange(StreamingState.Start);
|
|
1075
|
-
previousStats = allStats[allStats.length - 1];
|
|
1076
|
-
allStats = [];
|
|
1077
|
-
isStreaming = true;
|
|
1078
|
-
}
|
|
1079
|
-
allStats.push(slimStats);
|
|
1080
|
-
} else if (isStreaming) {
|
|
1081
|
-
notReceivingNumIntervals++;
|
|
1082
|
-
if (notReceivingNumIntervals >= notReceivingIntervalsThreshold) {
|
|
1083
|
-
const statsReport = createVideoStatsReport(allStats, interval, previousStats);
|
|
1084
|
-
onVideoStateChange == null ? void 0 : onVideoStateChange(StreamingState.Stop, statsReport);
|
|
1085
|
-
if (!getIsConnected()) {
|
|
1086
|
-
onConnected();
|
|
1087
|
-
}
|
|
1088
|
-
prevFreezeCount = freezeCount;
|
|
1089
|
-
isStreaming = false;
|
|
1090
|
-
}
|
|
740
|
+
const R = await e.getStats(), {
|
|
741
|
+
isReceiving: S,
|
|
742
|
+
avgJitterDelayInInterval: B,
|
|
743
|
+
freezeCount: l
|
|
744
|
+
} = D(R), m = Oe(R);
|
|
745
|
+
if (S)
|
|
746
|
+
i = 0, _ = l - k, h = B < rt ? V.Strong : B > nt && _ > 1 ? V.Weak : u, h !== u && (o == null || o(h), u = h, k += _, _ = 0), d || (r == null || r(p.Start), c = n[n.length - 1], n = [], d = !0), n.push(m);
|
|
747
|
+
else if (d && (i++, i >= tt)) {
|
|
748
|
+
const y = et(n, O, c);
|
|
749
|
+
r == null || r(p.Stop, y), t() || a(), k = l, d = !1;
|
|
1091
750
|
}
|
|
1092
|
-
},
|
|
751
|
+
}, O);
|
|
1093
752
|
}
|
|
1094
|
-
let
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
switch (state) {
|
|
753
|
+
let fe = !1;
|
|
754
|
+
const x = (e, t) => fe && console.log(e, t), st = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
755
|
+
function re(e) {
|
|
756
|
+
switch (e) {
|
|
1099
757
|
case "connected":
|
|
1100
|
-
return
|
|
758
|
+
return M.Connected;
|
|
1101
759
|
case "checking":
|
|
1102
|
-
return
|
|
760
|
+
return M.Connecting;
|
|
1103
761
|
case "failed":
|
|
1104
|
-
return
|
|
762
|
+
return M.Fail;
|
|
1105
763
|
case "new":
|
|
1106
|
-
return
|
|
764
|
+
return M.New;
|
|
1107
765
|
case "closed":
|
|
1108
|
-
return
|
|
766
|
+
return M.Closed;
|
|
1109
767
|
case "disconnected":
|
|
1110
|
-
return
|
|
768
|
+
return M.Disconnected;
|
|
1111
769
|
case "completed":
|
|
1112
|
-
return
|
|
770
|
+
return M.Completed;
|
|
1113
771
|
default:
|
|
1114
|
-
return
|
|
772
|
+
return M.New;
|
|
1115
773
|
}
|
|
1116
774
|
}
|
|
1117
|
-
function
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
775
|
+
function ot(e) {
|
|
776
|
+
const [t, a = ""] = e.split(/:(.+)/);
|
|
777
|
+
try {
|
|
778
|
+
const r = JSON.parse(a);
|
|
779
|
+
return x("parsed data channel message", {
|
|
780
|
+
subject: t,
|
|
781
|
+
data: r
|
|
782
|
+
}), {
|
|
783
|
+
subject: t,
|
|
784
|
+
data: r
|
|
785
|
+
};
|
|
786
|
+
} catch (r) {
|
|
787
|
+
return x("Failed to parse data channel message, returning data as string", {
|
|
788
|
+
subject: t,
|
|
789
|
+
rawData: a,
|
|
790
|
+
error: r
|
|
791
|
+
}), {
|
|
792
|
+
subject: t,
|
|
793
|
+
data: a
|
|
794
|
+
};
|
|
1127
795
|
}
|
|
1128
796
|
}
|
|
1129
|
-
function
|
|
1130
|
-
statsSignal,
|
|
1131
|
-
dataChannelSignal,
|
|
1132
|
-
onVideoStateChange,
|
|
1133
|
-
|
|
1134
|
-
report
|
|
797
|
+
function ct({
|
|
798
|
+
statsSignal: e,
|
|
799
|
+
dataChannelSignal: t,
|
|
800
|
+
onVideoStateChange: a,
|
|
801
|
+
report: r
|
|
1135
802
|
}) {
|
|
1136
|
-
|
|
1137
|
-
onVideoStateChange == null ? void 0 : onVideoStateChange(StreamingState.Start);
|
|
1138
|
-
} else if (statsSignal === StreamingState.Stop) {
|
|
1139
|
-
onVideoStateChange == null ? void 0 : onVideoStateChange(StreamingState.Stop, report);
|
|
1140
|
-
}
|
|
1141
|
-
if (dataChannelSignal === StreamingState.Start) {
|
|
1142
|
-
onAgentActivityStateChange == null ? void 0 : onAgentActivityStateChange(AgentActivityState.Talking);
|
|
1143
|
-
} else if (dataChannelSignal === StreamingState.Stop) {
|
|
1144
|
-
onAgentActivityStateChange == null ? void 0 : onAgentActivityStateChange(AgentActivityState.Idle);
|
|
1145
|
-
}
|
|
803
|
+
e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop, r));
|
|
1146
804
|
}
|
|
1147
|
-
function
|
|
1148
|
-
statsSignal,
|
|
1149
|
-
dataChannelSignal,
|
|
1150
|
-
onVideoStateChange,
|
|
1151
|
-
onAgentActivityStateChange,
|
|
1152
|
-
|
|
1153
|
-
report
|
|
805
|
+
function dt({
|
|
806
|
+
statsSignal: e,
|
|
807
|
+
dataChannelSignal: t,
|
|
808
|
+
onVideoStateChange: a,
|
|
809
|
+
onAgentActivityStateChange: r,
|
|
810
|
+
report: o
|
|
1154
811
|
}) {
|
|
1155
|
-
|
|
1156
|
-
handleLegacyStreamState({
|
|
1157
|
-
statsSignal,
|
|
1158
|
-
dataChannelSignal,
|
|
1159
|
-
onVideoStateChange,
|
|
1160
|
-
report
|
|
1161
|
-
});
|
|
1162
|
-
} else if (streamType === StreamType.Fluent) {
|
|
1163
|
-
handleFluentStreamState({
|
|
1164
|
-
statsSignal,
|
|
1165
|
-
dataChannelSignal,
|
|
1166
|
-
onVideoStateChange,
|
|
1167
|
-
onAgentActivityStateChange,
|
|
1168
|
-
report
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
812
|
+
e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, o)), t === p.Start ? r == null || r(X.Talking) : t === p.Stop && (r == null || r(X.Idle));
|
|
1171
813
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
814
|
+
function ne({
|
|
815
|
+
statsSignal: e,
|
|
816
|
+
dataChannelSignal: t,
|
|
817
|
+
onVideoStateChange: a,
|
|
818
|
+
onAgentActivityStateChange: r,
|
|
819
|
+
streamType: o,
|
|
820
|
+
report: s
|
|
1178
821
|
}) {
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
} = agent.videoType === VideoType.Clip ? createClipApi(auth, baseURL, agentId, callbacks.onError) : createTalkApi(auth, baseURL, agentId, callbacks.onError);
|
|
1191
|
-
const {
|
|
1192
|
-
id: streamIdFromServer,
|
|
1193
|
-
offer,
|
|
1194
|
-
ice_servers,
|
|
1195
|
-
session_id,
|
|
1196
|
-
fluent
|
|
1197
|
-
} = await createStream(agent);
|
|
1198
|
-
const peerConnection = new actualRTCPC({
|
|
1199
|
-
iceServers: ice_servers
|
|
822
|
+
o === J.Legacy ? ct({
|
|
823
|
+
statsSignal: e,
|
|
824
|
+
dataChannelSignal: t,
|
|
825
|
+
onVideoStateChange: a,
|
|
826
|
+
report: s
|
|
827
|
+
}) : o === J.Fluent && dt({
|
|
828
|
+
statsSignal: e,
|
|
829
|
+
dataChannelSignal: t,
|
|
830
|
+
onVideoStateChange: a,
|
|
831
|
+
onAgentActivityStateChange: r,
|
|
832
|
+
report: s
|
|
1200
833
|
});
|
|
1201
|
-
|
|
1202
|
-
|
|
834
|
+
}
|
|
835
|
+
async function lt(e, t, {
|
|
836
|
+
debug: a = !1,
|
|
837
|
+
callbacks: r,
|
|
838
|
+
auth: o,
|
|
839
|
+
baseURL: s = Y,
|
|
840
|
+
analytics: n
|
|
841
|
+
}) {
|
|
842
|
+
fe = a;
|
|
843
|
+
let c = !1, i = !1, d = p.Stop, u = p.Stop;
|
|
844
|
+
const {
|
|
845
|
+
startConnection: h,
|
|
846
|
+
sendStreamRequest: _,
|
|
847
|
+
close: k,
|
|
848
|
+
createStream: D,
|
|
849
|
+
addIceCandidate: R
|
|
850
|
+
} = t.videoType === ae.Clip ? Ye(o, s, e, r.onError) : Qe(o, s, e, r.onError), {
|
|
851
|
+
id: S,
|
|
852
|
+
offer: B,
|
|
853
|
+
ice_servers: l,
|
|
854
|
+
session_id: m,
|
|
855
|
+
fluent: y
|
|
856
|
+
} = await D(t), w = new st({
|
|
857
|
+
iceServers: l
|
|
858
|
+
}), T = w.createDataChannel("JanusDataChannel");
|
|
859
|
+
if (!m)
|
|
1203
860
|
throw new Error("Could not create session_id");
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
"stream-type": streamType
|
|
861
|
+
const v = y ? J.Fluent : J.Legacy;
|
|
862
|
+
n.enrich({
|
|
863
|
+
"stream-type": v
|
|
1208
864
|
});
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
var _a;
|
|
1227
|
-
return (_a = callbacks.onConnectivityStateChange) == null ? void 0 : _a.call(callbacks, state);
|
|
1228
|
-
}, warmup);
|
|
1229
|
-
peerConnection.onicecandidate = (event) => {
|
|
1230
|
-
var _a;
|
|
1231
|
-
log("peerConnection.onicecandidate", event);
|
|
865
|
+
const j = t.stream_warmup && !y, P = () => c, $ = () => {
|
|
866
|
+
var f;
|
|
867
|
+
c = !0, i && ((f = r.onConnectionStateChange) == null || f.call(r, M.Connected));
|
|
868
|
+
}, C = it(w, P, $, (f, g) => ne({
|
|
869
|
+
statsSignal: u = f,
|
|
870
|
+
dataChannelSignal: v === J.Legacy ? d : void 0,
|
|
871
|
+
onVideoStateChange: r.onVideoStateChange,
|
|
872
|
+
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
873
|
+
report: g,
|
|
874
|
+
streamType: v
|
|
875
|
+
}), (f) => {
|
|
876
|
+
var g;
|
|
877
|
+
return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
|
|
878
|
+
}, j);
|
|
879
|
+
w.onicecandidate = (f) => {
|
|
880
|
+
var g;
|
|
881
|
+
x("peerConnection.onicecandidate", f);
|
|
1232
882
|
try {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
}
|
|
1244
|
-
} catch (e) {
|
|
1245
|
-
(_a = callbacks.onError) == null ? void 0 : _a.call(callbacks, e, {
|
|
1246
|
-
streamId: streamIdFromServer
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
pcDataChannel.onopen = () => {
|
|
1251
|
-
isDatachannelOpen = true;
|
|
1252
|
-
if (!warmup || isConnected) {
|
|
1253
|
-
onConnected();
|
|
1254
|
-
}
|
|
1255
|
-
};
|
|
1256
|
-
pcDataChannel.onmessage = (event) => {
|
|
1257
|
-
if (event.data in DataChannelSignalMap) {
|
|
1258
|
-
dataChannelSignal = DataChannelSignalMap[event.data];
|
|
1259
|
-
handleStreamState({
|
|
1260
|
-
statsSignal: streamType === StreamType.Legacy ? statsSignal : void 0,
|
|
1261
|
-
dataChannelSignal,
|
|
1262
|
-
onVideoStateChange: callbacks.onVideoStateChange,
|
|
1263
|
-
onAgentActivityStateChange: callbacks.onAgentActivityStateChange,
|
|
1264
|
-
streamType
|
|
883
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? R(S, {
|
|
884
|
+
candidate: f.candidate.candidate,
|
|
885
|
+
sdpMid: f.candidate.sdpMid,
|
|
886
|
+
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
887
|
+
}, m) : R(S, {
|
|
888
|
+
candidate: null
|
|
889
|
+
}, m);
|
|
890
|
+
} catch (A) {
|
|
891
|
+
(g = r.onError) == null || g.call(r, A, {
|
|
892
|
+
streamId: S
|
|
1265
893
|
});
|
|
1266
894
|
}
|
|
895
|
+
}, T.onopen = () => {
|
|
896
|
+
i = !0, (!j || c) && $();
|
|
1267
897
|
};
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
898
|
+
function I(f) {
|
|
899
|
+
d = f === N.StreamStarted ? p.Start : p.Stop, ne({
|
|
900
|
+
statsSignal: v === J.Legacy ? u : void 0,
|
|
901
|
+
dataChannelSignal: d,
|
|
902
|
+
onVideoStateChange: r.onVideoStateChange,
|
|
903
|
+
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
904
|
+
streamType: v
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
function E(f, g) {
|
|
908
|
+
const A = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
|
|
909
|
+
A && n.enrich({
|
|
910
|
+
streamMetadata: A
|
|
911
|
+
}), n.track("agent-chat", {
|
|
912
|
+
event: "ready"
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
const L = {
|
|
916
|
+
[N.StreamStarted]: I,
|
|
917
|
+
[N.StreamDone]: I,
|
|
918
|
+
[N.StreamReady]: E
|
|
1280
919
|
};
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
920
|
+
T.onmessage = (f) => {
|
|
921
|
+
var H;
|
|
922
|
+
const {
|
|
923
|
+
subject: g,
|
|
924
|
+
data: A
|
|
925
|
+
} = ot(f.data);
|
|
926
|
+
(H = L[g]) == null || H.call(L, g, A);
|
|
927
|
+
}, w.oniceconnectionstatechange = () => {
|
|
928
|
+
var g;
|
|
929
|
+
x("peerConnection.oniceconnectionstatechange => " + w.iceConnectionState);
|
|
930
|
+
const f = re(w.iceConnectionState);
|
|
931
|
+
f !== M.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
|
|
932
|
+
}, w.ontrack = (f) => {
|
|
933
|
+
var g;
|
|
934
|
+
x("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
|
|
935
|
+
}, await w.setRemoteDescription(B), x("set remote description OK");
|
|
936
|
+
const z = await w.createAnswer();
|
|
937
|
+
return x("create answer OK"), await w.setLocalDescription(z), x("set local description OK"), await h(S, z, m), x("start connection OK"), {
|
|
1290
938
|
/**
|
|
1291
939
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1292
940
|
* @param payload
|
|
1293
941
|
*/
|
|
1294
|
-
speak(
|
|
1295
|
-
return
|
|
942
|
+
speak(f) {
|
|
943
|
+
return _(S, m, f);
|
|
1296
944
|
},
|
|
1297
945
|
/**
|
|
1298
946
|
* Method to close RTC connection
|
|
1299
947
|
*/
|
|
1300
948
|
async disconnect() {
|
|
1301
|
-
var
|
|
1302
|
-
if (
|
|
1303
|
-
const
|
|
1304
|
-
if (
|
|
1305
|
-
if (
|
|
1306
|
-
clearInterval(
|
|
949
|
+
var f;
|
|
950
|
+
if (S) {
|
|
951
|
+
const g = re(w.iceConnectionState);
|
|
952
|
+
if (w) {
|
|
953
|
+
if (g === M.New) {
|
|
954
|
+
clearInterval(C);
|
|
1307
955
|
return;
|
|
1308
956
|
}
|
|
1309
|
-
|
|
1310
|
-
peerConnection.oniceconnectionstatechange = null;
|
|
1311
|
-
peerConnection.onnegotiationneeded = null;
|
|
1312
|
-
peerConnection.onicecandidate = null;
|
|
1313
|
-
peerConnection.ontrack = null;
|
|
957
|
+
w.close(), w.oniceconnectionstatechange = null, w.onnegotiationneeded = null, w.onicecandidate = null, w.ontrack = null;
|
|
1314
958
|
}
|
|
1315
959
|
try {
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
} catch (e) {
|
|
1321
|
-
log("Error on close stream connection", e);
|
|
960
|
+
g === M.Connected && await k(S, m).catch((A) => {
|
|
961
|
+
});
|
|
962
|
+
} catch (A) {
|
|
963
|
+
x("Error on close stream connection", A);
|
|
1322
964
|
}
|
|
1323
|
-
(
|
|
1324
|
-
clearInterval(videoStatsInterval);
|
|
965
|
+
(f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval(C);
|
|
1325
966
|
}
|
|
1326
967
|
},
|
|
1327
968
|
/**
|
|
1328
969
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1329
970
|
*/
|
|
1330
|
-
sessionId:
|
|
971
|
+
sessionId: m,
|
|
1331
972
|
/**
|
|
1332
973
|
* Id of current RTC stream
|
|
1333
974
|
*/
|
|
1334
|
-
streamId:
|
|
1335
|
-
streamType
|
|
975
|
+
streamId: S,
|
|
976
|
+
streamType: v
|
|
1336
977
|
};
|
|
1337
978
|
}
|
|
1338
|
-
function
|
|
979
|
+
function ut(e, t) {
|
|
1339
980
|
const {
|
|
1340
|
-
streamOptions
|
|
1341
|
-
} =
|
|
981
|
+
streamOptions: a
|
|
982
|
+
} = t ?? {};
|
|
1342
983
|
return {
|
|
1343
|
-
videoType:
|
|
1344
|
-
output_resolution:
|
|
1345
|
-
session_timeout:
|
|
1346
|
-
stream_warmup:
|
|
1347
|
-
compatibility_mode:
|
|
1348
|
-
fluent:
|
|
984
|
+
videoType: Ee(e.presenter.type),
|
|
985
|
+
output_resolution: a == null ? void 0 : a.outputResolution,
|
|
986
|
+
session_timeout: a == null ? void 0 : a.sessionTimeout,
|
|
987
|
+
stream_warmup: a == null ? void 0 : a.streamWarmup,
|
|
988
|
+
compatibility_mode: a == null ? void 0 : a.compatibilityMode,
|
|
989
|
+
fluent: a == null ? void 0 : a.fluent
|
|
1349
990
|
};
|
|
1350
991
|
}
|
|
1351
|
-
function
|
|
1352
|
-
|
|
1353
|
-
trackVideoStreamAnalytics(state, agent, statsReport, analytics, streamType);
|
|
1354
|
-
} else {
|
|
1355
|
-
trackLegacyVideoAnalytics(state, agent, statsReport, analytics, streamType);
|
|
1356
|
-
}
|
|
992
|
+
function ft(e, t, a, r, o) {
|
|
993
|
+
o === J.Fluent ? mt(e, t, a, r, o) : ht(e, t, a, r, o);
|
|
1357
994
|
}
|
|
1358
|
-
function
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
"stream-type": streamType,
|
|
1370
|
-
...statsReport
|
|
1371
|
-
});
|
|
1372
|
-
}
|
|
995
|
+
function mt(e, t, a, r, o) {
|
|
996
|
+
e === p.Start ? r.track("stream-session", {
|
|
997
|
+
event: "start",
|
|
998
|
+
"stream-type": o
|
|
999
|
+
}) : e === p.Stop && r.track("stream-session", {
|
|
1000
|
+
event: "stop",
|
|
1001
|
+
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1002
|
+
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1003
|
+
"stream-type": o,
|
|
1004
|
+
...a
|
|
1005
|
+
});
|
|
1373
1006
|
}
|
|
1374
|
-
function
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
event: "stop",
|
|
1386
|
-
is_greenscreen: agent.presenter.type === "clip" && agent.presenter.is_greenscreen,
|
|
1387
|
-
background: agent.presenter.type === "clip" && agent.presenter.background,
|
|
1388
|
-
"stream-type": streamType
|
|
1389
|
-
}, "done", [StreamEvents.StreamVideoDone]);
|
|
1390
|
-
}
|
|
1007
|
+
function gt(e, t, a, r) {
|
|
1008
|
+
F.get() <= 0 || (e === p.Start ? a.linkTrack("agent-video", {
|
|
1009
|
+
event: "start",
|
|
1010
|
+
latency: F.get(!0),
|
|
1011
|
+
"stream-type": r
|
|
1012
|
+
}, "start", [N.StreamVideoCreated]) : e === p.Stop && a.linkTrack("agent-video", {
|
|
1013
|
+
event: "stop",
|
|
1014
|
+
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1015
|
+
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1016
|
+
"stream-type": r
|
|
1017
|
+
}, "done", [N.StreamVideoDone]));
|
|
1391
1018
|
}
|
|
1392
|
-
function
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
is_greenscreen: agent.presenter.type === "clip" && agent.presenter.is_greenscreen,
|
|
1405
|
-
background: agent.presenter.type === "clip" && agent.presenter.background,
|
|
1406
|
-
"stream-type": streamType,
|
|
1407
|
-
...statsReport
|
|
1408
|
-
}, "done", [StreamEvents.StreamVideoDone]);
|
|
1409
|
-
}
|
|
1019
|
+
function ht(e, t, a, r, o) {
|
|
1020
|
+
F.get() <= 0 || (e === p.Start ? r.linkTrack("agent-video", {
|
|
1021
|
+
event: "start",
|
|
1022
|
+
latency: F.get(!0),
|
|
1023
|
+
"stream-type": o
|
|
1024
|
+
}, "start", [N.StreamVideoCreated]) : e === p.Stop && r.linkTrack("agent-video", {
|
|
1025
|
+
event: "stop",
|
|
1026
|
+
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1027
|
+
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1028
|
+
"stream-type": o,
|
|
1029
|
+
...a
|
|
1030
|
+
}, "done", [N.StreamVideoDone]));
|
|
1410
1031
|
}
|
|
1411
|
-
function
|
|
1412
|
-
|
|
1413
|
-
return new Promise(async (resolve, reject) => {
|
|
1032
|
+
function wt(e, t, a) {
|
|
1033
|
+
return F.reset(), new Promise(async (r, o) => {
|
|
1414
1034
|
try {
|
|
1415
|
-
const
|
|
1416
|
-
...
|
|
1417
|
-
analytics,
|
|
1035
|
+
const s = await lt(e.id, ut(e, t), {
|
|
1036
|
+
...t,
|
|
1037
|
+
analytics: a,
|
|
1418
1038
|
callbacks: {
|
|
1419
|
-
...
|
|
1420
|
-
onConnectionStateChange: (
|
|
1421
|
-
var
|
|
1422
|
-
(
|
|
1423
|
-
if (state === ConnectionState.Connected) {
|
|
1424
|
-
resolve(streamingManager);
|
|
1425
|
-
}
|
|
1039
|
+
...t.callbacks,
|
|
1040
|
+
onConnectionStateChange: (n) => {
|
|
1041
|
+
var c, i;
|
|
1042
|
+
(i = (c = t.callbacks).onConnectionStateChange) == null || i.call(c, n), n === M.Connected && r(s);
|
|
1426
1043
|
},
|
|
1427
|
-
onVideoStateChange: (
|
|
1428
|
-
var
|
|
1429
|
-
(
|
|
1430
|
-
trackVideoStateChangeAnalytics(state, agent, statsReport, analytics, streamingManager.streamType);
|
|
1044
|
+
onVideoStateChange: (n, c) => {
|
|
1045
|
+
var i, d;
|
|
1046
|
+
(d = (i = t.callbacks).onVideoStateChange) == null || d.call(i, n), ft(n, e, c, a, s.streamType);
|
|
1431
1047
|
},
|
|
1432
|
-
onAgentActivityStateChange: (
|
|
1433
|
-
var
|
|
1434
|
-
(
|
|
1435
|
-
trackAgentActivityAnalytics(state === AgentActivityState.Talking ? StreamingState.Start : StreamingState.Stop, agent, analytics, streamingManager.streamType);
|
|
1048
|
+
onAgentActivityStateChange: (n) => {
|
|
1049
|
+
var c, i;
|
|
1050
|
+
(i = (c = t.callbacks).onAgentActivityStateChange) == null || i.call(c, n), gt(n === X.Talking ? p.Start : p.Stop, e, a, s.streamType);
|
|
1436
1051
|
}
|
|
1437
1052
|
}
|
|
1438
1053
|
});
|
|
1439
|
-
} catch (
|
|
1440
|
-
|
|
1054
|
+
} catch (s) {
|
|
1055
|
+
o(s);
|
|
1441
1056
|
}
|
|
1442
1057
|
});
|
|
1443
1058
|
}
|
|
1444
|
-
async function
|
|
1445
|
-
var
|
|
1059
|
+
async function pt(e, t, a, r, o) {
|
|
1060
|
+
var i, d, u, h;
|
|
1446
1061
|
const {
|
|
1447
|
-
chat:
|
|
1448
|
-
chatMode
|
|
1449
|
-
} = await
|
|
1450
|
-
if (
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
return {
|
|
1456
|
-
chat: newChat
|
|
1457
|
-
};
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
const streamingManager = await connectToManager(agent, options, analytics);
|
|
1062
|
+
chat: s,
|
|
1063
|
+
chatMode: n
|
|
1064
|
+
} = await ue(e, a, r, t.mode, t.persistentChat, o);
|
|
1065
|
+
if (n && n !== t.mode && (t.mode = n, (d = (i = t.callbacks).onModeChange) == null || d.call(i, n), n === b.TextOnly))
|
|
1066
|
+
return (h = (u = t.callbacks).onError) == null || h.call(u, new we(n)), {
|
|
1067
|
+
chat: s
|
|
1068
|
+
};
|
|
1069
|
+
const c = await wt(e, t, r);
|
|
1461
1070
|
return {
|
|
1462
|
-
chat:
|
|
1463
|
-
streamingManager
|
|
1071
|
+
chat: s,
|
|
1072
|
+
streamingManager: c
|
|
1464
1073
|
};
|
|
1465
1074
|
}
|
|
1466
|
-
async function
|
|
1467
|
-
var
|
|
1468
|
-
let
|
|
1469
|
-
const
|
|
1470
|
-
const wsURL = options.wsURL || didSocketApiUrl;
|
|
1471
|
-
const baseURL = options.baseURL || didApiUrl;
|
|
1472
|
-
const items = {
|
|
1075
|
+
async function vt(e, t) {
|
|
1076
|
+
var R, S, B;
|
|
1077
|
+
let a = !0;
|
|
1078
|
+
const r = t.mixpanelKey || je, o = t.wsURL || Te, s = t.baseURL || Y, n = {
|
|
1473
1079
|
messages: [],
|
|
1474
|
-
chatMode:
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
})
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
clearQueue
|
|
1487
|
-
} = createMessageEventQueue(analytics, items, options, agentEntity, () => {
|
|
1488
|
-
var _a2;
|
|
1489
|
-
return (_a2 = items.socketManager) == null ? void 0 : _a2.disconnect();
|
|
1080
|
+
chatMode: t.mode || b.Functional
|
|
1081
|
+
}, c = ce(t.auth, s, t.callbacks.onError), i = await c.getById(e), d = Ne({
|
|
1082
|
+
token: r,
|
|
1083
|
+
agent: i,
|
|
1084
|
+
isEnabled: t.enableAnalitics,
|
|
1085
|
+
distinctId: t.distinctId
|
|
1086
|
+
}), {
|
|
1087
|
+
onMessage: u,
|
|
1088
|
+
clearQueue: h
|
|
1089
|
+
} = Xe(d, n, t, i, () => {
|
|
1090
|
+
var l;
|
|
1091
|
+
return (l = n.socketManager) == null ? void 0 : l.disconnect();
|
|
1490
1092
|
});
|
|
1491
|
-
|
|
1492
|
-
(_b = (_a = options.callbacks).onNewMessage) == null ? void 0 : _b.call(_a, [...items.messages], "answer");
|
|
1493
|
-
analytics.track("agent-sdk", {
|
|
1093
|
+
n.messages = We(t.initialMessages), (S = (R = t.callbacks).onNewMessage) == null || S.call(R, [...n.messages], "answer"), d.track("agent-sdk", {
|
|
1494
1094
|
event: "loaded",
|
|
1495
|
-
...
|
|
1095
|
+
...Le(i)
|
|
1496
1096
|
});
|
|
1497
|
-
async function
|
|
1498
|
-
var
|
|
1499
|
-
(
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
}
|
|
1505
|
-
const websocketPromise = options.mode === ChatMode.DirectPlayback ? Promise.resolve(void 0) : createSocketManager(options.auth, wsURL, {
|
|
1506
|
-
onMessage,
|
|
1507
|
-
onError: options.callbacks.onError
|
|
1508
|
-
});
|
|
1509
|
-
const initPromise = retryOperation(() => {
|
|
1510
|
-
return initializeStreamAndChat(agentEntity, options, agentsApi, analytics, items.chat);
|
|
1511
|
-
}, {
|
|
1097
|
+
async function _(l) {
|
|
1098
|
+
var j, P, $, C, I, E, L;
|
|
1099
|
+
(P = (j = t.callbacks).onConnectionStateChange) == null || P.call(j, M.Connecting), F.reset(), l && !a && (delete n.chat, (C = ($ = t.callbacks).onNewMessage) == null || C.call($, [...n.messages], "answer"));
|
|
1100
|
+
const m = t.mode === b.DirectPlayback ? Promise.resolve(void 0) : He(t.auth, o, {
|
|
1101
|
+
onMessage: u,
|
|
1102
|
+
onError: t.callbacks.onError
|
|
1103
|
+
}), y = G(() => pt(i, t, c, d, n.chat), {
|
|
1512
1104
|
limit: 3,
|
|
1513
|
-
timeout:
|
|
1105
|
+
timeout: Ie,
|
|
1514
1106
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1515
1107
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1516
|
-
shouldRetryFn: (
|
|
1108
|
+
shouldRetryFn: (z) => (z == null ? void 0 : z.message) !== "Could not connect" && z.status !== 429,
|
|
1517
1109
|
delayMs: 1e3
|
|
1518
|
-
}).catch((
|
|
1519
|
-
var
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
chat
|
|
1527
|
-
}] = await Promise.all([websocketPromise, initPromise]);
|
|
1528
|
-
if (chat && chat.id !== ((_e = items.chat) == null ? void 0 : _e.id)) {
|
|
1529
|
-
(_g = (_f = options.callbacks).onNewChat) == null ? void 0 : _g.call(_f, chat.id);
|
|
1530
|
-
}
|
|
1531
|
-
items.streamingManager = streamingManager;
|
|
1532
|
-
items.socketManager = socketManager;
|
|
1533
|
-
items.chat = chat;
|
|
1534
|
-
firstConnection = false;
|
|
1535
|
-
changeMode((chat == null ? void 0 : chat.chat_mode) ?? options.mode ?? ChatMode.Functional);
|
|
1110
|
+
}).catch((z) => {
|
|
1111
|
+
var f, g;
|
|
1112
|
+
throw D(b.Maintenance), (g = (f = t.callbacks).onConnectionStateChange) == null || g.call(f, M.Fail), z;
|
|
1113
|
+
}), [w, {
|
|
1114
|
+
streamingManager: T,
|
|
1115
|
+
chat: v
|
|
1116
|
+
}] = await Promise.all([m, y]);
|
|
1117
|
+
v && v.id !== ((I = n.chat) == null ? void 0 : I.id) && ((L = (E = t.callbacks).onNewChat) == null || L.call(E, v.id)), n.streamingManager = T, n.socketManager = w, n.chat = v, a = !1, D((v == null ? void 0 : v.chat_mode) ?? t.mode ?? b.Functional);
|
|
1536
1118
|
}
|
|
1537
|
-
async function
|
|
1538
|
-
var
|
|
1539
|
-
(
|
|
1540
|
-
await ((_b2 = items.streamingManager) == null ? void 0 : _b2.disconnect());
|
|
1541
|
-
delete items.streamingManager;
|
|
1542
|
-
delete items.socketManager;
|
|
1543
|
-
(_d = (_c2 = options.callbacks).onConnectionStateChange) == null ? void 0 : _d.call(_c2, ConnectionState.Disconnected);
|
|
1119
|
+
async function k() {
|
|
1120
|
+
var l, m, y, w;
|
|
1121
|
+
(l = n.socketManager) == null || l.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, (w = (y = t.callbacks).onConnectionStateChange) == null || w.call(y, M.Disconnected);
|
|
1544
1122
|
}
|
|
1545
|
-
async function
|
|
1546
|
-
var
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
});
|
|
1551
|
-
items.chatMode = mode;
|
|
1552
|
-
if (items.chatMode !== ChatMode.Functional) {
|
|
1553
|
-
await disconnect();
|
|
1554
|
-
}
|
|
1555
|
-
(_b2 = (_a2 = options.callbacks).onModeChange) == null ? void 0 : _b2.call(_a2, mode);
|
|
1556
|
-
}
|
|
1123
|
+
async function D(l) {
|
|
1124
|
+
var m, y;
|
|
1125
|
+
l !== n.chatMode && (d.track("agent-mode-change", {
|
|
1126
|
+
mode: l
|
|
1127
|
+
}), n.chatMode = l, n.chatMode !== b.Functional && await k(), (y = (m = t.callbacks).onModeChange) == null || y.call(m, l));
|
|
1557
1128
|
}
|
|
1558
1129
|
return {
|
|
1559
|
-
agent:
|
|
1130
|
+
agent: i,
|
|
1560
1131
|
getStreamType: () => {
|
|
1561
|
-
var
|
|
1562
|
-
return (
|
|
1132
|
+
var l;
|
|
1133
|
+
return (l = n.streamingManager) == null ? void 0 : l.streamType;
|
|
1563
1134
|
},
|
|
1564
|
-
starterMessages: ((
|
|
1565
|
-
getSTTToken: () =>
|
|
1566
|
-
changeMode,
|
|
1567
|
-
enrichAnalytics:
|
|
1135
|
+
starterMessages: ((B = i.knowledge) == null ? void 0 : B.starter_message) || [],
|
|
1136
|
+
getSTTToken: () => c.getSTTToken(i.id),
|
|
1137
|
+
changeMode: D,
|
|
1138
|
+
enrichAnalytics: d.enrich,
|
|
1568
1139
|
async connect() {
|
|
1569
|
-
var
|
|
1570
|
-
await
|
|
1571
|
-
analytics.track("agent-chat", {
|
|
1140
|
+
var l;
|
|
1141
|
+
await _(!0), d.track("agent-chat", {
|
|
1572
1142
|
event: "connect",
|
|
1573
|
-
chatId: (
|
|
1574
|
-
agentId:
|
|
1575
|
-
mode:
|
|
1143
|
+
chatId: (l = n.chat) == null ? void 0 : l.id,
|
|
1144
|
+
agentId: i.id,
|
|
1145
|
+
mode: n.chatMode
|
|
1576
1146
|
});
|
|
1577
1147
|
},
|
|
1578
1148
|
async reconnect() {
|
|
1579
|
-
var
|
|
1580
|
-
await
|
|
1581
|
-
await connect2(false);
|
|
1582
|
-
analytics.track("agent-chat", {
|
|
1149
|
+
var l;
|
|
1150
|
+
await k(), await _(!1), d.track("agent-chat", {
|
|
1583
1151
|
event: "reconnect",
|
|
1584
|
-
chatId: (
|
|
1585
|
-
agentId:
|
|
1586
|
-
mode:
|
|
1152
|
+
chatId: (l = n.chat) == null ? void 0 : l.id,
|
|
1153
|
+
agentId: i.id,
|
|
1154
|
+
mode: n.chatMode
|
|
1587
1155
|
});
|
|
1588
1156
|
},
|
|
1589
1157
|
async disconnect() {
|
|
1590
|
-
var
|
|
1591
|
-
await
|
|
1592
|
-
analytics.track("agent-chat", {
|
|
1158
|
+
var l;
|
|
1159
|
+
await k(), d.track("agent-chat", {
|
|
1593
1160
|
event: "disconnect",
|
|
1594
|
-
chatId: (
|
|
1595
|
-
agentId:
|
|
1596
|
-
mode:
|
|
1161
|
+
chatId: (l = n.chat) == null ? void 0 : l.id,
|
|
1162
|
+
agentId: i.id,
|
|
1163
|
+
mode: n.chatMode
|
|
1597
1164
|
});
|
|
1598
1165
|
},
|
|
1599
|
-
async chat(
|
|
1600
|
-
var
|
|
1601
|
-
const
|
|
1602
|
-
if (
|
|
1603
|
-
throw new
|
|
1604
|
-
|
|
1605
|
-
throw new
|
|
1606
|
-
|
|
1607
|
-
throw new
|
|
1608
|
-
|
|
1609
|
-
throw new
|
|
1610
|
-
|
|
1611
|
-
if (!
|
|
1612
|
-
throw new
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
throw new ValidationError("Chat is not initialized");
|
|
1616
|
-
}
|
|
1166
|
+
async chat(l) {
|
|
1167
|
+
var T, v, j, P, $;
|
|
1168
|
+
const m = () => {
|
|
1169
|
+
if (t.mode === b.DirectPlayback)
|
|
1170
|
+
throw new W("Direct playback is enabled, chat is disabled");
|
|
1171
|
+
if (l.length >= 800)
|
|
1172
|
+
throw new W("Message cannot be more than 800 characters");
|
|
1173
|
+
if (l.length === 0)
|
|
1174
|
+
throw new W("Message cannot be empty");
|
|
1175
|
+
if (n.chatMode === b.Maintenance)
|
|
1176
|
+
throw new W("Chat is in maintenance mode");
|
|
1177
|
+
if (![b.TextOnly, b.Playground].includes(n.chatMode)) {
|
|
1178
|
+
if (!n.streamingManager)
|
|
1179
|
+
throw new W("Streaming manager is not initialized");
|
|
1180
|
+
if (!n.chat)
|
|
1181
|
+
throw new W("Chat is not initialized");
|
|
1617
1182
|
}
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
}
|
|
1626
|
-
items.chat = newChat.chat;
|
|
1627
|
-
(_b3 = (_a3 = options.callbacks).onNewChat) == null ? void 0 : _b3.call(_a3, items.chat.id);
|
|
1183
|
+
}, y = async () => {
|
|
1184
|
+
var C, I;
|
|
1185
|
+
if (!n.chat) {
|
|
1186
|
+
const E = await ue(i, c, d, n.chatMode, t.persistentChat);
|
|
1187
|
+
if (!E.chat)
|
|
1188
|
+
throw new he(n.chatMode, !!t.persistentChat);
|
|
1189
|
+
n.chat = E.chat, (I = (C = t.callbacks).onNewChat) == null || I.call(C, n.chat.id);
|
|
1628
1190
|
}
|
|
1629
|
-
return
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
return
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
...message
|
|
1641
|
-
}) => message)
|
|
1642
|
-
}, {
|
|
1643
|
-
...getRequestHeaders(items.chatMode),
|
|
1644
|
-
skipErrorHandler: true
|
|
1645
|
-
});
|
|
1191
|
+
return n.chat.id;
|
|
1192
|
+
}, w = async (C, I) => G(() => {
|
|
1193
|
+
var E, L;
|
|
1194
|
+
return c.chat(i.id, I, {
|
|
1195
|
+
chatMode: n.chatMode,
|
|
1196
|
+
streamId: (E = n.streamingManager) == null ? void 0 : E.streamId,
|
|
1197
|
+
sessionId: (L = n.streamingManager) == null ? void 0 : L.sessionId,
|
|
1198
|
+
messages: C.map(({
|
|
1199
|
+
matches: z,
|
|
1200
|
+
...f
|
|
1201
|
+
}) => f)
|
|
1646
1202
|
}, {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
var _a3, _b3, _c3, _d2;
|
|
1650
|
-
const isInvalidSessionId = (_a3 = error == null ? void 0 : error.message) == null ? void 0 : _a3.includes("missing or invalid session_id");
|
|
1651
|
-
const isStreamError = (_b3 = error == null ? void 0 : error.message) == null ? void 0 : _b3.includes("Stream Error");
|
|
1652
|
-
if (!isStreamError && !isInvalidSessionId) {
|
|
1653
|
-
(_d2 = (_c3 = options.callbacks).onError) == null ? void 0 : _d2.call(_c3, error);
|
|
1654
|
-
return false;
|
|
1655
|
-
}
|
|
1656
|
-
return true;
|
|
1657
|
-
},
|
|
1658
|
-
onRetry: async () => {
|
|
1659
|
-
await disconnect();
|
|
1660
|
-
await connect2(false);
|
|
1661
|
-
}
|
|
1203
|
+
...le(n.chatMode),
|
|
1204
|
+
skipErrorHandler: !0
|
|
1662
1205
|
});
|
|
1663
|
-
}
|
|
1206
|
+
}, {
|
|
1207
|
+
limit: 2,
|
|
1208
|
+
shouldRetryFn: (E) => {
|
|
1209
|
+
var f, g, A, H;
|
|
1210
|
+
const L = (f = E == null ? void 0 : E.message) == null ? void 0 : f.includes("missing or invalid session_id");
|
|
1211
|
+
return !((g = E == null ? void 0 : E.message) == null ? void 0 : g.includes("Stream Error")) && !L ? ((H = (A = t.callbacks).onError) == null || H.call(A, E), !1) : !0;
|
|
1212
|
+
},
|
|
1213
|
+
onRetry: async () => {
|
|
1214
|
+
await k(), await _(!1);
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1664
1217
|
try {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
items.messages.push({
|
|
1668
|
-
id: getRandom(),
|
|
1218
|
+
h(), m(), n.messages.push({
|
|
1219
|
+
id: K(),
|
|
1669
1220
|
role: "user",
|
|
1670
|
-
content:
|
|
1671
|
-
created_at: new Date(
|
|
1672
|
-
});
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
items.messages.push({
|
|
1677
|
-
id: getRandom(),
|
|
1221
|
+
content: l,
|
|
1222
|
+
created_at: new Date(F.update()).toISOString()
|
|
1223
|
+
}), (v = (T = t.callbacks).onNewMessage) == null || v.call(T, [...n.messages], "user");
|
|
1224
|
+
const C = await y(), I = await w([...n.messages], C);
|
|
1225
|
+
return n.messages.push({
|
|
1226
|
+
id: K(),
|
|
1678
1227
|
role: "assistant",
|
|
1679
|
-
content:
|
|
1228
|
+
content: I.result || "",
|
|
1680
1229
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1681
|
-
context:
|
|
1682
|
-
matches:
|
|
1683
|
-
})
|
|
1684
|
-
analytics.track("agent-message-send", {
|
|
1230
|
+
context: I.context,
|
|
1231
|
+
matches: I.matches
|
|
1232
|
+
}), d.track("agent-message-send", {
|
|
1685
1233
|
event: "success",
|
|
1686
|
-
mode:
|
|
1687
|
-
messages:
|
|
1688
|
-
})
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
});
|
|
1696
|
-
}
|
|
1697
|
-
return response;
|
|
1698
|
-
} catch (e) {
|
|
1699
|
-
if (((_e = items.messages[items.messages.length - 1]) == null ? void 0 : _e.role) === "assistant") {
|
|
1700
|
-
items.messages.pop();
|
|
1701
|
-
}
|
|
1702
|
-
analytics.track("agent-message-send", {
|
|
1234
|
+
mode: n.chatMode,
|
|
1235
|
+
messages: n.messages.length + 1
|
|
1236
|
+
}), I.result && ((P = (j = t.callbacks).onNewMessage) == null || P.call(j, [...n.messages], "answer"), d.track("agent-message-received", {
|
|
1237
|
+
latency: F.get(!0),
|
|
1238
|
+
mode: n.chatMode,
|
|
1239
|
+
messages: n.messages.length
|
|
1240
|
+
})), I;
|
|
1241
|
+
} catch (C) {
|
|
1242
|
+
throw (($ = n.messages[n.messages.length - 1]) == null ? void 0 : $.role) === "assistant" && n.messages.pop(), d.track("agent-message-send", {
|
|
1703
1243
|
event: "error",
|
|
1704
|
-
mode:
|
|
1705
|
-
messages:
|
|
1706
|
-
});
|
|
1707
|
-
throw e;
|
|
1244
|
+
mode: n.chatMode,
|
|
1245
|
+
messages: n.messages.length
|
|
1246
|
+
}), C;
|
|
1708
1247
|
}
|
|
1709
1248
|
},
|
|
1710
|
-
rate(
|
|
1711
|
-
var
|
|
1712
|
-
const
|
|
1713
|
-
if (
|
|
1249
|
+
rate(l, m, y) {
|
|
1250
|
+
var v, j, P, $;
|
|
1251
|
+
const w = n.messages.find((C) => C.id === l);
|
|
1252
|
+
if (n.chat) {
|
|
1253
|
+
if (!w)
|
|
1254
|
+
throw new Error("Message not found");
|
|
1255
|
+
} else
|
|
1714
1256
|
throw new Error("Chat is not initialized");
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
});
|
|
1734
|
-
}
|
|
1735
|
-
return agentsApi.createRating(agentEntity.id, items.chat.id, {
|
|
1736
|
-
knowledge_id: ((_d = agentEntity.knowledge) == null ? void 0 : _d.id) ?? "",
|
|
1737
|
-
message_id: messageId,
|
|
1738
|
-
matches,
|
|
1739
|
-
score
|
|
1257
|
+
const T = ((v = w.matches) == null ? void 0 : v.map((C) => [C.document_id, C.id])) ?? [];
|
|
1258
|
+
return d.track("agent-rate", {
|
|
1259
|
+
event: y ? "update" : "create",
|
|
1260
|
+
thumb: m === 1 ? "up" : "down",
|
|
1261
|
+
knowledge_id: ((j = i.knowledge) == null ? void 0 : j.id) ?? "",
|
|
1262
|
+
mode: n.chatMode,
|
|
1263
|
+
matches: T,
|
|
1264
|
+
score: m
|
|
1265
|
+
}), y ? c.updateRating(i.id, n.chat.id, y, {
|
|
1266
|
+
knowledge_id: ((P = i.knowledge) == null ? void 0 : P.id) ?? "",
|
|
1267
|
+
message_id: l,
|
|
1268
|
+
matches: T,
|
|
1269
|
+
score: m
|
|
1270
|
+
}) : c.createRating(i.id, n.chat.id, {
|
|
1271
|
+
knowledge_id: (($ = i.knowledge) == null ? void 0 : $.id) ?? "",
|
|
1272
|
+
message_id: l,
|
|
1273
|
+
matches: T,
|
|
1274
|
+
score: m
|
|
1740
1275
|
});
|
|
1741
1276
|
},
|
|
1742
|
-
deleteRate(
|
|
1743
|
-
var
|
|
1744
|
-
if (!
|
|
1277
|
+
deleteRate(l) {
|
|
1278
|
+
var m;
|
|
1279
|
+
if (!n.chat)
|
|
1745
1280
|
throw new Error("Chat is not initialized");
|
|
1746
|
-
|
|
1747
|
-
analytics.track("agent-rate-delete", {
|
|
1281
|
+
return d.track("agent-rate-delete", {
|
|
1748
1282
|
type: "text",
|
|
1749
|
-
chat_id: (
|
|
1750
|
-
id,
|
|
1751
|
-
mode:
|
|
1752
|
-
});
|
|
1753
|
-
return agentsApi.deleteRating(agentEntity.id, items.chat.id, id);
|
|
1283
|
+
chat_id: (m = n.chat) == null ? void 0 : m.id,
|
|
1284
|
+
id: l,
|
|
1285
|
+
mode: n.chatMode
|
|
1286
|
+
}), c.deleteRating(i.id, n.chat.id, l);
|
|
1754
1287
|
},
|
|
1755
|
-
async speak(
|
|
1756
|
-
var
|
|
1757
|
-
if (!
|
|
1288
|
+
async speak(l) {
|
|
1289
|
+
var T, v, j, P;
|
|
1290
|
+
if (!n.streamingManager)
|
|
1758
1291
|
throw new Error("Please connect to the agent first");
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
if (!agentEntity.presenter.voice) {
|
|
1292
|
+
function m() {
|
|
1293
|
+
if (typeof l == "string") {
|
|
1294
|
+
if (!i.presenter.voice)
|
|
1763
1295
|
throw new Error("Presenter voice is not initialized");
|
|
1764
|
-
}
|
|
1765
1296
|
return {
|
|
1766
1297
|
type: "text",
|
|
1767
|
-
provider:
|
|
1768
|
-
input:
|
|
1769
|
-
ssml:
|
|
1298
|
+
provider: i.presenter.voice,
|
|
1299
|
+
input: l,
|
|
1300
|
+
ssml: !1
|
|
1770
1301
|
};
|
|
1771
1302
|
}
|
|
1772
|
-
if (
|
|
1773
|
-
if (!
|
|
1303
|
+
if (l.type === "text" && !l.provider) {
|
|
1304
|
+
if (!i.presenter.voice)
|
|
1774
1305
|
throw new Error("Presenter voice is not initialized");
|
|
1775
|
-
}
|
|
1776
1306
|
return {
|
|
1777
1307
|
type: "text",
|
|
1778
|
-
provider:
|
|
1779
|
-
input:
|
|
1780
|
-
ssml:
|
|
1308
|
+
provider: i.presenter.voice,
|
|
1309
|
+
input: l.input,
|
|
1310
|
+
ssml: l.ssml
|
|
1781
1311
|
};
|
|
1782
1312
|
}
|
|
1783
|
-
return
|
|
1784
|
-
}
|
|
1785
|
-
const script = getScript();
|
|
1786
|
-
analytics.track("agent-speak", script);
|
|
1787
|
-
timestampTracker.update();
|
|
1788
|
-
if (((_a2 = items.chat) == null ? void 0 : _a2.id) && script.type === "text") {
|
|
1789
|
-
items.messages.push({
|
|
1790
|
-
id: getRandom(),
|
|
1791
|
-
role: "assistant",
|
|
1792
|
-
content: script.input,
|
|
1793
|
-
created_at: new Date(timestampTracker.get(true)).toISOString()
|
|
1794
|
-
});
|
|
1795
|
-
(_c2 = (_b2 = options.callbacks).onNewMessage) == null ? void 0 : _c2.call(_b2, [...items.messages], "answer");
|
|
1313
|
+
return l;
|
|
1796
1314
|
}
|
|
1797
|
-
const
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
}
|
|
1804
|
-
|
|
1805
|
-
|
|
1315
|
+
const y = m();
|
|
1316
|
+
d.track("agent-speak", y), F.update(), (T = n.chat) != null && T.id && y.type === "text" && (n.messages.push({
|
|
1317
|
+
id: K(),
|
|
1318
|
+
role: "assistant",
|
|
1319
|
+
content: y.input,
|
|
1320
|
+
created_at: new Date(F.get(!0)).toISOString()
|
|
1321
|
+
}), (j = (v = t.callbacks).onNewMessage) == null || j.call(v, [...n.messages], "answer"));
|
|
1322
|
+
const w = Pe(n.chatMode);
|
|
1323
|
+
return n.chat && w ? {
|
|
1324
|
+
duration: 0,
|
|
1325
|
+
status: "success"
|
|
1326
|
+
} : n.streamingManager.speak({
|
|
1327
|
+
script: y,
|
|
1806
1328
|
metadata: {
|
|
1807
|
-
chat_id: (
|
|
1808
|
-
agent_id:
|
|
1329
|
+
chat_id: (P = n.chat) == null ? void 0 : P.id,
|
|
1330
|
+
agent_id: i.id
|
|
1809
1331
|
}
|
|
1810
1332
|
});
|
|
1811
1333
|
}
|
|
1812
1334
|
};
|
|
1813
1335
|
}
|
|
1814
|
-
function
|
|
1336
|
+
function kt(e, t, a) {
|
|
1815
1337
|
const {
|
|
1816
|
-
getById
|
|
1817
|
-
} =
|
|
1818
|
-
return
|
|
1338
|
+
getById: r
|
|
1339
|
+
} = ce(t, a || Y);
|
|
1340
|
+
return r(e);
|
|
1819
1341
|
}
|
|
1820
1342
|
export {
|
|
1821
|
-
AgentActivityState,
|
|
1822
|
-
AgentStatus,
|
|
1823
|
-
ChatCreationFailed,
|
|
1824
|
-
ChatMode,
|
|
1825
|
-
ChatModeDowngraded,
|
|
1826
|
-
ChatProgress,
|
|
1827
|
-
ConnectionState,
|
|
1828
|
-
ConnectivityState,
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
mapVideoType
|
|
1343
|
+
X as AgentActivityState,
|
|
1344
|
+
ke as AgentStatus,
|
|
1345
|
+
he as ChatCreationFailed,
|
|
1346
|
+
b as ChatMode,
|
|
1347
|
+
we as ChatModeDowngraded,
|
|
1348
|
+
U as ChatProgress,
|
|
1349
|
+
M as ConnectionState,
|
|
1350
|
+
V as ConnectivityState,
|
|
1351
|
+
Se as DocumentType,
|
|
1352
|
+
Ce as KnowledgeType,
|
|
1353
|
+
ve as PlanGroup,
|
|
1354
|
+
_e as Providers,
|
|
1355
|
+
De as RateState,
|
|
1356
|
+
N as StreamEvents,
|
|
1357
|
+
J as StreamType,
|
|
1358
|
+
p as StreamingState,
|
|
1359
|
+
Re as Subject,
|
|
1360
|
+
ye as UserPlan,
|
|
1361
|
+
W as ValidationError,
|
|
1362
|
+
ae as VideoType,
|
|
1363
|
+
Me as VoiceAccess,
|
|
1364
|
+
pe as WsError,
|
|
1365
|
+
vt as createAgentManager,
|
|
1366
|
+
kt as getAgent,
|
|
1367
|
+
Ee as mapVideoType
|
|
1847
1368
|
};
|