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