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