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