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