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