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