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