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