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