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