@d-id/client-sdk 1.1.71 → 1.2.1-staging.341
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-OAVAtXjd.js → index-vpTphBDp.js} +703 -656
- package/dist/index.js +31 -26
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-B01_ssBG.js → livekit-manager-CFuAnjAa.js} +109 -110
- package/dist/src/errors/base-error.d.ts +9 -8
- package/dist/src/errors/errors.test.d.ts +1 -0
- package/dist/src/errors/http-error.d.ts +12 -0
- package/dist/src/errors/index.d.ts +4 -0
- package/dist/src/errors/network-error.d.ts +11 -0
- package/dist/src/errors/stream-error.d.ts +5 -0
- package/dist/src/errors/validation-error.d.ts +2 -2
- package/dist/src/services/chat/index.d.ts +3 -1
- package/dist/src/services/chat/index.test.d.ts +1 -0
- package/dist/src/utils/error-analytics.d.ts +4 -0
- package/dist/src/utils/error-analytics.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,42 +1,90 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var Z = (e, t, r) =>
|
|
4
|
-
class
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var Ye = Object.defineProperty;
|
|
2
|
+
var Qe = (e, t, r) => t in e ? Ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var Z = (e, t, r) => Qe(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
class G extends Error {
|
|
5
|
+
constructor(t, r = "Error", a) {
|
|
6
|
+
super(t), this.kind = r, this.originalError = a, Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
}
|
|
8
|
+
toJson() {
|
|
9
|
+
const t = this.originalError instanceof Error ? this.originalError.message.slice(0, 256) : void 0;
|
|
10
|
+
return {
|
|
11
|
+
kind: this.kind,
|
|
12
|
+
message: this.message,
|
|
13
|
+
...t && t !== this.message ? { cause: t } : {}
|
|
14
|
+
};
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
|
-
|
|
17
|
+
function gr(e) {
|
|
18
|
+
return e instanceof Error && typeof e.kind == "string";
|
|
19
|
+
}
|
|
20
|
+
class Ze extends G {
|
|
14
21
|
constructor(t, r) {
|
|
15
|
-
super({
|
|
16
|
-
kind: "ChatCreationFailed",
|
|
17
|
-
description: `Failed to create ${r ? "persistent" : ""} chat, mode: ${t}`
|
|
18
|
-
});
|
|
22
|
+
super(`Failed to create ${r ? "persistent" : ""} chat, mode: ${t}`, "ChatCreationFailed");
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
|
-
class
|
|
25
|
+
class et extends G {
|
|
22
26
|
constructor(t) {
|
|
23
|
-
super(
|
|
27
|
+
super(`Chat mode downgraded to ${t}`, "ChatModeDowngraded");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function tt(e) {
|
|
31
|
+
try {
|
|
32
|
+
const t = JSON.parse(e);
|
|
33
|
+
if (t && typeof t == "object" && typeof t.kind == "string")
|
|
34
|
+
return t;
|
|
35
|
+
} catch {
|
|
24
36
|
}
|
|
25
37
|
}
|
|
26
|
-
class
|
|
27
|
-
constructor(r, a) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this
|
|
38
|
+
class ze extends G {
|
|
39
|
+
constructor(r, a, c = {}) {
|
|
40
|
+
const i = tt(a);
|
|
41
|
+
super(((i == null ? void 0 : i.description) ?? a).slice(0, 256), (i == null ? void 0 : i.kind) ?? "HttpError");
|
|
42
|
+
Z(this, "status");
|
|
43
|
+
Z(this, "url");
|
|
44
|
+
Z(this, "method");
|
|
45
|
+
this.status = r, this.url = c.url, this.method = c.method;
|
|
46
|
+
}
|
|
47
|
+
toJson() {
|
|
48
|
+
return {
|
|
49
|
+
...super.toJson(),
|
|
50
|
+
httpStatus: this.status,
|
|
51
|
+
...this.url ? { endpoint: this.url } : {},
|
|
52
|
+
...this.method ? { method: this.method } : {}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class rt extends G {
|
|
57
|
+
constructor(r, a = {}) {
|
|
58
|
+
super("Network request failed", "NetworkError", r);
|
|
59
|
+
Z(this, "endpoint");
|
|
60
|
+
Z(this, "method");
|
|
61
|
+
this.endpoint = a.url, this.method = a.method;
|
|
62
|
+
}
|
|
63
|
+
toJson() {
|
|
64
|
+
return {
|
|
65
|
+
...super.toJson(),
|
|
66
|
+
...this.endpoint ? { endpoint: this.endpoint } : {},
|
|
67
|
+
...this.method ? { method: this.method } : {}
|
|
68
|
+
};
|
|
31
69
|
}
|
|
32
70
|
}
|
|
33
|
-
class
|
|
71
|
+
class Ne extends G {
|
|
72
|
+
constructor(t, r) {
|
|
73
|
+
super(t, "StreamError", r);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class $ extends G {
|
|
77
|
+
constructor(t, r) {
|
|
78
|
+
super(t, "ValidationError"), this.key = r;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class nt extends G {
|
|
34
82
|
constructor(t) {
|
|
35
|
-
super(
|
|
83
|
+
super(t, "WSError");
|
|
36
84
|
}
|
|
37
85
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
86
|
+
var at = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(at || {}), it = /* @__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))(it || {}), st = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(st || {}), ot = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ot || {}), A = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(A || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(z || {}), ct = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(dt || {}), lt = /* @__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))(lt || {}), Fe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Fe || {});
|
|
87
|
+
const hr = (e) => {
|
|
40
88
|
switch (e) {
|
|
41
89
|
case "clip":
|
|
42
90
|
return "clip";
|
|
@@ -48,9 +96,9 @@ const lr = (e) => {
|
|
|
48
96
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
97
|
}
|
|
50
98
|
};
|
|
51
|
-
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}),
|
|
52
|
-
const
|
|
53
|
-
},
|
|
99
|
+
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ae || {}), x = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", 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.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(x || {}), b = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(b || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(pe || {}), ut = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ut || {}), mt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(mt || {});
|
|
100
|
+
const pr = (...e) => {
|
|
101
|
+
}, Ve = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
|
|
54
102
|
const t = new Uint8Array(e);
|
|
55
103
|
return window.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
104
|
};
|
|
@@ -59,25 +107,25 @@ function me(e) {
|
|
|
59
107
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
60
108
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
61
109
|
if (!t) {
|
|
62
|
-
let r =
|
|
110
|
+
let r = Q();
|
|
63
111
|
window.localStorage.setItem("did_external_key_id", r), t = r;
|
|
64
112
|
}
|
|
65
113
|
return t;
|
|
66
114
|
}
|
|
67
|
-
let
|
|
68
|
-
function
|
|
69
|
-
|
|
115
|
+
let Je = Q();
|
|
116
|
+
function ft() {
|
|
117
|
+
Je = Q();
|
|
70
118
|
}
|
|
71
|
-
function
|
|
119
|
+
function Ue(e, t) {
|
|
72
120
|
if (e.type === "bearer")
|
|
73
121
|
return `Bearer ${e.token}`;
|
|
74
122
|
if (e.type === "basic")
|
|
75
123
|
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
76
124
|
if (e.type === "key")
|
|
77
|
-
return `Client-Key ${e.clientKey}.${me(t)}_${
|
|
125
|
+
return `Client-Key ${e.clientKey}.${me(t)}_${Je}`;
|
|
78
126
|
throw new Error(`Unknown auth type: ${e}`);
|
|
79
127
|
}
|
|
80
|
-
const
|
|
128
|
+
const gt = 45 * 1e3, ht = "X-Playground-Chat", ke = 2e3, le = "https://api.d-id.com", pt = "wss://notifications.d-id.com", wt = "79f81a83a67430be2bc0fd61042b8faa", Ke = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, vt = (e) => {
|
|
81
129
|
switch (e.type) {
|
|
82
130
|
case "expressive":
|
|
83
131
|
return "v4";
|
|
@@ -86,13 +134,13 @@ const lt = 45 * 1e3, ut = "X-Playground-Chat", ke = 2e3, le = "https://api.d-id.
|
|
|
86
134
|
case "talk":
|
|
87
135
|
return "v2";
|
|
88
136
|
}
|
|
89
|
-
},
|
|
90
|
-
function
|
|
137
|
+
}, yt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, we = (e) => e === Fe.Expressive, Ct = (e) => [A.TextOnly, A.Playground, A.Maintenance].includes(e), We = (e) => e && [A.DirectPlayback, A.Off].includes(e), Re = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, De = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, St = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
|
|
138
|
+
function kt(e) {
|
|
91
139
|
const t = e.split("?")[0].split("#")[0].toLowerCase();
|
|
92
|
-
return
|
|
140
|
+
return St.some((r) => t.endsWith(r));
|
|
93
141
|
}
|
|
94
|
-
const
|
|
95
|
-
function
|
|
142
|
+
const Ie = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Me = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
143
|
+
function Rt(e) {
|
|
96
144
|
if (e.length === 0)
|
|
97
145
|
return [];
|
|
98
146
|
const t = [];
|
|
@@ -103,13 +151,13 @@ function yt(e) {
|
|
|
103
151
|
length: r[0].length,
|
|
104
152
|
part: { type: "video", src: r[3], alt: r[1], thumbnail: r[2] }
|
|
105
153
|
});
|
|
106
|
-
for (
|
|
154
|
+
for (De.lastIndex = 0; (r = De.exec(e)) !== null; )
|
|
107
155
|
if (!t.some((o) => r.index >= o.index && r.index < o.index + o.length)) {
|
|
108
156
|
const o = r[2], n = r[1];
|
|
109
|
-
let
|
|
110
|
-
|
|
157
|
+
let s;
|
|
158
|
+
kt(o) ? s = { type: "video", src: o, alt: n } : (s = { type: "image", src: o, alt: n }, o.toLowerCase().endsWith(".gif") && (s.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: s });
|
|
111
159
|
}
|
|
112
|
-
for (
|
|
160
|
+
for (Ie.lastIndex = 0; (r = Ie.exec(e)) !== null; )
|
|
113
161
|
t.some((o) => r.index >= o.index && r.index < o.index + o.length) || t.push({
|
|
114
162
|
index: r.index,
|
|
115
163
|
length: r[0].length,
|
|
@@ -123,22 +171,22 @@ function yt(e) {
|
|
|
123
171
|
});
|
|
124
172
|
if (t.length === 0)
|
|
125
173
|
return [{ type: "text", text: e }];
|
|
126
|
-
t.sort((
|
|
174
|
+
t.sort((i, o) => i.index - o.index);
|
|
127
175
|
const a = [];
|
|
128
176
|
let c = 0;
|
|
129
|
-
for (const
|
|
130
|
-
|
|
177
|
+
for (const i of t)
|
|
178
|
+
i.index > c && a.push({ type: "text", text: e.slice(c, i.index) }), a.push(i.part), c = i.index + i.length;
|
|
131
179
|
return c < e.length && a.push({ type: "text", text: e.slice(c) }), a;
|
|
132
180
|
}
|
|
133
181
|
let Ee = "", ue = [];
|
|
134
|
-
function
|
|
135
|
-
return e === Ee || (Ee = e, ue =
|
|
182
|
+
function ne(e) {
|
|
183
|
+
return e === Ee || (Ee = e, ue = Rt(e)), ue;
|
|
136
184
|
}
|
|
137
|
-
function
|
|
185
|
+
function Dt(e, t) {
|
|
138
186
|
let r;
|
|
139
187
|
return {
|
|
140
|
-
promise: new Promise((c,
|
|
141
|
-
r = setTimeout(() =>
|
|
188
|
+
promise: new Promise((c, i) => {
|
|
189
|
+
r = setTimeout(() => i(new Error(t)), e);
|
|
142
190
|
}),
|
|
143
191
|
clear: () => clearTimeout(r)
|
|
144
192
|
};
|
|
@@ -158,104 +206,106 @@ async function fe(e, t) {
|
|
|
158
206
|
try {
|
|
159
207
|
if (!r.timeout)
|
|
160
208
|
return await e();
|
|
161
|
-
const { promise:
|
|
162
|
-
return await Promise.race([n,
|
|
163
|
-
} catch (
|
|
164
|
-
if (a =
|
|
165
|
-
throw
|
|
166
|
-
await
|
|
209
|
+
const { promise: i, clear: o } = Dt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
|
|
210
|
+
return await Promise.race([n, i]);
|
|
211
|
+
} catch (i) {
|
|
212
|
+
if (a = i, !r.shouldRetryFn(i) || c >= r.limit)
|
|
213
|
+
throw i;
|
|
214
|
+
await Ve(r.delayMs), r.onRetry(i);
|
|
167
215
|
}
|
|
168
216
|
throw a;
|
|
169
217
|
}
|
|
170
|
-
const
|
|
218
|
+
const It = (e) => fe(e, {
|
|
171
219
|
limit: 3,
|
|
172
220
|
delayMs: 1e3,
|
|
173
221
|
timeout: 0,
|
|
174
222
|
shouldRetryFn: (t) => t.status === 429
|
|
175
223
|
});
|
|
176
|
-
function
|
|
177
|
-
const c = async (
|
|
178
|
-
const { skipErrorHandler: n, ...
|
|
224
|
+
function He(e, t = le, r, a) {
|
|
225
|
+
const c = async (i, o) => {
|
|
226
|
+
const { skipErrorHandler: n, ...s } = o || {};
|
|
179
227
|
let d;
|
|
180
228
|
try {
|
|
181
|
-
d = await
|
|
182
|
-
() => fetch(t + (
|
|
183
|
-
...
|
|
229
|
+
d = await It(
|
|
230
|
+
() => fetch(t + (i != null && i.startsWith("/") ? i : `/${i}`), {
|
|
231
|
+
...s,
|
|
184
232
|
headers: {
|
|
185
|
-
...
|
|
186
|
-
Authorization:
|
|
233
|
+
...s.headers,
|
|
234
|
+
Authorization: Ue(e, a),
|
|
187
235
|
"Content-Type": "application/json"
|
|
188
236
|
}
|
|
189
237
|
})
|
|
190
238
|
);
|
|
191
239
|
} catch (u) {
|
|
192
|
-
|
|
240
|
+
if ((u == null ? void 0 : u.name) === "AbortError")
|
|
241
|
+
throw u;
|
|
242
|
+
const m = new rt(u, { url: i, method: s.method ?? "GET" });
|
|
243
|
+
throw n || r == null || r(m, { url: i, options: s }), m;
|
|
193
244
|
}
|
|
194
245
|
if (!d.ok) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
throw r && !n && r(m, { url: s, options: i, headers: d.headers }), m;
|
|
246
|
+
const u = await d.text().catch(() => `Failed to fetch with status ${d.status}`), f = new ze(d.status, u, { url: i, method: s.method ?? "GET" });
|
|
247
|
+
throw n || r == null || r(f, { url: i, options: s, headers: d.headers }), f;
|
|
198
248
|
}
|
|
199
249
|
return d.json();
|
|
200
250
|
};
|
|
201
251
|
return {
|
|
202
|
-
get(
|
|
203
|
-
return c(
|
|
252
|
+
get(i, o) {
|
|
253
|
+
return c(i, { ...o, method: "GET" });
|
|
204
254
|
},
|
|
205
|
-
post(
|
|
206
|
-
return c(
|
|
255
|
+
post(i, o, n) {
|
|
256
|
+
return c(i, { ...n, body: JSON.stringify(o), method: "POST" });
|
|
207
257
|
},
|
|
208
|
-
delete(
|
|
209
|
-
return c(
|
|
258
|
+
delete(i, o, n) {
|
|
259
|
+
return c(i, { ...n, body: JSON.stringify(o), method: "DELETE" });
|
|
210
260
|
},
|
|
211
|
-
patch(
|
|
212
|
-
return c(
|
|
261
|
+
patch(i, o, n) {
|
|
262
|
+
return c(i, { ...n, body: JSON.stringify(o), method: "PATCH" });
|
|
213
263
|
}
|
|
214
264
|
};
|
|
215
265
|
}
|
|
216
|
-
function
|
|
217
|
-
const c =
|
|
266
|
+
function Mt(e, t = le, r, a) {
|
|
267
|
+
const c = He(e, `${t}/agents`, r, a);
|
|
218
268
|
return {
|
|
219
|
-
create(
|
|
220
|
-
return c.post("/",
|
|
269
|
+
create(i, o) {
|
|
270
|
+
return c.post("/", i, o);
|
|
221
271
|
},
|
|
222
|
-
getAgents(
|
|
223
|
-
return c.get(`/${
|
|
272
|
+
getAgents(i, o) {
|
|
273
|
+
return c.get(`/${i ? `?tag=${i}` : ""}`, o).then((n) => n ?? []);
|
|
224
274
|
},
|
|
225
|
-
getById(
|
|
226
|
-
return c.get(`/${
|
|
275
|
+
getById(i, o) {
|
|
276
|
+
return c.get(`/${i}`, o);
|
|
227
277
|
},
|
|
228
|
-
delete(
|
|
229
|
-
return c.delete(`/${
|
|
278
|
+
delete(i, o) {
|
|
279
|
+
return c.delete(`/${i}`, void 0, o);
|
|
230
280
|
},
|
|
231
|
-
update(
|
|
232
|
-
return c.patch(`/${
|
|
281
|
+
update(i, o, n) {
|
|
282
|
+
return c.patch(`/${i}`, o, n);
|
|
233
283
|
},
|
|
234
|
-
newChat(
|
|
235
|
-
return c.post(`/${
|
|
284
|
+
newChat(i, o, n) {
|
|
285
|
+
return c.post(`/${i}/chat`, o, n);
|
|
236
286
|
},
|
|
237
|
-
chat(
|
|
238
|
-
return c.post(`/${
|
|
287
|
+
chat(i, o, n, s) {
|
|
288
|
+
return c.post(`/${i}/chat/${o}`, n, s);
|
|
239
289
|
},
|
|
240
|
-
createRating(
|
|
241
|
-
return c.post(`/${
|
|
290
|
+
createRating(i, o, n, s) {
|
|
291
|
+
return c.post(`/${i}/chat/${o}/ratings`, n, s);
|
|
242
292
|
},
|
|
243
|
-
updateRating(
|
|
244
|
-
return c.patch(`/${
|
|
293
|
+
updateRating(i, o, n, s, d) {
|
|
294
|
+
return c.patch(`/${i}/chat/${o}/ratings/${n}`, s, d);
|
|
245
295
|
},
|
|
246
|
-
deleteRating(
|
|
247
|
-
return c.delete(`/${
|
|
296
|
+
deleteRating(i, o, n, s) {
|
|
297
|
+
return c.delete(`/${i}/chat/${o}/ratings/${n}`, s);
|
|
248
298
|
},
|
|
249
|
-
getSTTToken(
|
|
250
|
-
return c.get(`/${
|
|
299
|
+
getSTTToken(i, o) {
|
|
300
|
+
return c.get(`/${i}/stt-token`, o);
|
|
251
301
|
}
|
|
252
302
|
};
|
|
253
303
|
}
|
|
254
|
-
function
|
|
255
|
-
var c,
|
|
304
|
+
function Et(e) {
|
|
305
|
+
var c, i, o, n;
|
|
256
306
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", r = () => {
|
|
257
|
-
const
|
|
258
|
-
return
|
|
307
|
+
const s = navigator.platform;
|
|
308
|
+
return s.toLowerCase().includes("win") ? "Windows" : s.toLowerCase().includes("mac") ? "Mac OS X" : s.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
259
309
|
}, a = e.presenter;
|
|
260
310
|
return {
|
|
261
311
|
$os: `${r()}`,
|
|
@@ -264,18 +314,18 @@ function Rt(e) {
|
|
|
264
314
|
origin: window.location.origin,
|
|
265
315
|
agentType: Ke(a),
|
|
266
316
|
agentVoice: {
|
|
267
|
-
voiceId: (
|
|
317
|
+
voiceId: (i = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : i.voice_id,
|
|
268
318
|
provider: (n = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : n.type
|
|
269
319
|
}
|
|
270
320
|
};
|
|
271
321
|
}
|
|
272
|
-
function
|
|
273
|
-
var r, a, c,
|
|
322
|
+
function Tt(e) {
|
|
323
|
+
var r, a, c, i, o, n;
|
|
274
324
|
const t = (r = e.llm) == null ? void 0 : r.prompt_customization;
|
|
275
325
|
return {
|
|
276
326
|
agentType: Ke(e.presenter),
|
|
277
|
-
presenterType:
|
|
278
|
-
presenter:
|
|
327
|
+
presenterType: vt(e.presenter),
|
|
328
|
+
presenter: yt(e.presenter),
|
|
279
329
|
owner_id: e.owner_id ?? "",
|
|
280
330
|
promptVersion: (a = e.llm) == null ? void 0 : a.prompt_version,
|
|
281
331
|
behavior: {
|
|
@@ -283,7 +333,7 @@ function It(e) {
|
|
|
283
333
|
personality: t == null ? void 0 : t.personality,
|
|
284
334
|
instructions: (c = e.llm) == null ? void 0 : c.instructions
|
|
285
335
|
},
|
|
286
|
-
temperature: (
|
|
336
|
+
temperature: (i = e.llm) == null ? void 0 : i.temperature,
|
|
287
337
|
knowledgeSource: t == null ? void 0 : t.knowledge_source,
|
|
288
338
|
starterQuestionsCount: (n = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : n.length,
|
|
289
339
|
topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
|
|
@@ -294,29 +344,32 @@ function It(e) {
|
|
|
294
344
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
295
345
|
};
|
|
296
346
|
}
|
|
297
|
-
const
|
|
347
|
+
const _t = (e) => {
|
|
298
348
|
try {
|
|
299
349
|
return String((e == null ? void 0 : e.message) ?? e ?? "").slice(0, 256);
|
|
300
350
|
} catch {
|
|
301
351
|
return "Unknown error";
|
|
302
352
|
}
|
|
303
|
-
},
|
|
304
|
-
function
|
|
305
|
-
var
|
|
306
|
-
const { event: a, ...c } = e, { template:
|
|
353
|
+
}, At = (e) => e.reduce((t, r) => t + r, 0), Te = (e) => At(e) / e.length;
|
|
354
|
+
function bt(e, t, r) {
|
|
355
|
+
var s, d, u;
|
|
356
|
+
const { event: a, ...c } = e, { template: i } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((s = t == null ? void 0 : t.presenter) == null ? void 0 : s.voice) || {};
|
|
307
357
|
return {
|
|
308
358
|
...c,
|
|
309
|
-
llm: { ...c.llm, template:
|
|
359
|
+
llm: { ...c.llm, template: i },
|
|
310
360
|
script: { ...c.script, provider: { ...(d = c == null ? void 0 : c.script) == null ? void 0 : d.provider, language: o } },
|
|
311
361
|
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
|
|
312
362
|
...r
|
|
313
363
|
};
|
|
314
364
|
}
|
|
315
|
-
function
|
|
365
|
+
function _e(e) {
|
|
316
366
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
317
367
|
}
|
|
318
|
-
|
|
319
|
-
|
|
368
|
+
function Ae(e) {
|
|
369
|
+
return e instanceof G ? e.toJson() : { kind: "UnknownError", message: _t(e) || "UnknownError" };
|
|
370
|
+
}
|
|
371
|
+
const xt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
372
|
+
function Lt(e) {
|
|
320
373
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
|
|
321
374
|
return {
|
|
322
375
|
token: e.token || "testKey",
|
|
@@ -327,14 +380,14 @@ function _t(e) {
|
|
|
327
380
|
...e.mixpanelAdditionalProperties || {}
|
|
328
381
|
},
|
|
329
382
|
isEnabled: e.isEnabled ?? !0,
|
|
330
|
-
getRandom:
|
|
383
|
+
getRandom: Q,
|
|
331
384
|
enrich(a) {
|
|
332
385
|
this.additionalProperties = { ...this.additionalProperties, ...a };
|
|
333
386
|
},
|
|
334
|
-
async track(a, c,
|
|
387
|
+
async track(a, c, i) {
|
|
335
388
|
if (!this.isEnabled)
|
|
336
389
|
return Promise.resolve();
|
|
337
|
-
const { audioPath: o, ...n } = c || {},
|
|
390
|
+
const { audioPath: o, ...n } = c || {}, s = i || Date.now(), d = {
|
|
338
391
|
method: "POST",
|
|
339
392
|
headers: {
|
|
340
393
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -349,7 +402,7 @@ function _t(e) {
|
|
|
349
402
|
agentId: this.agentId,
|
|
350
403
|
source: t,
|
|
351
404
|
token: this.token,
|
|
352
|
-
time:
|
|
405
|
+
time: s,
|
|
353
406
|
$insert_id: this.getRandom(),
|
|
354
407
|
origin: window.location.href,
|
|
355
408
|
"Screen Height": window.screen.height || window.innerWidth,
|
|
@@ -360,15 +413,15 @@ function _t(e) {
|
|
|
360
413
|
])
|
|
361
414
|
})
|
|
362
415
|
};
|
|
363
|
-
return fetch(
|
|
416
|
+
return fetch(xt, d).catch((u) => console.error("Analytics tracking error:", u)), Promise.resolve();
|
|
364
417
|
},
|
|
365
|
-
linkTrack(a, c,
|
|
366
|
-
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(
|
|
418
|
+
linkTrack(a, c, i, o) {
|
|
419
|
+
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(i) || o.push(i);
|
|
367
420
|
const n = r[a];
|
|
368
|
-
if (n.events[
|
|
421
|
+
if (n.events[i] = { props: c }, n.resolvedDependencies.push(i), o.every(
|
|
369
422
|
(d) => n.resolvedDependencies.includes(d)
|
|
370
423
|
)) {
|
|
371
|
-
const d = o.reduce((u,
|
|
424
|
+
const d = o.reduce((u, f) => n.events[f] ? { ...u, ...n.events[f].props } : u, {});
|
|
372
425
|
this.track(a, d), n.resolvedDependencies = n.resolvedDependencies.filter(
|
|
373
426
|
(u) => !o.includes(u)
|
|
374
427
|
), o.forEach((u) => {
|
|
@@ -386,74 +439,62 @@ function ve() {
|
|
|
386
439
|
get: (t = !1) => t ? Date.now() - e : e
|
|
387
440
|
};
|
|
388
441
|
}
|
|
389
|
-
const
|
|
390
|
-
function
|
|
391
|
-
return e === A.Playground ? { headers: { [
|
|
442
|
+
const q = ve(), ge = ve(), be = ve();
|
|
443
|
+
function Oe(e) {
|
|
444
|
+
return e === A.Playground ? { headers: { [ht]: "true" } } : {};
|
|
392
445
|
}
|
|
393
|
-
async function
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
})), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? a };
|
|
400
|
-
} catch (o) {
|
|
401
|
-
throw Tt(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
402
|
-
}
|
|
446
|
+
async function qe(e, t, r, a, c = !1, i) {
|
|
447
|
+
return !i && !We(a) && (i = await t.newChat(e.id, { persist: c }, Oe(a)), r.track("agent-chat", {
|
|
448
|
+
event: "created",
|
|
449
|
+
chatId: i.id,
|
|
450
|
+
mode: a
|
|
451
|
+
})), { chat: i, chatMode: (i == null ? void 0 : i.chat_mode) ?? a };
|
|
403
452
|
}
|
|
404
|
-
|
|
405
|
-
try {
|
|
406
|
-
const t = JSON.parse(e.message);
|
|
407
|
-
return t == null ? void 0 : t.kind;
|
|
408
|
-
} catch {
|
|
409
|
-
return "UnknownError";
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
function At(e) {
|
|
453
|
+
function Pt(e) {
|
|
413
454
|
return e && e.length > 0 ? e : [];
|
|
414
455
|
}
|
|
415
|
-
function
|
|
456
|
+
function jt(e) {
|
|
416
457
|
return new Promise((t, r) => {
|
|
417
|
-
const { callbacks: a, host: c, auth:
|
|
418
|
-
|
|
419
|
-
console.error(
|
|
420
|
-
},
|
|
421
|
-
|
|
458
|
+
const { callbacks: a, host: c, auth: i, externalId: o } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: u = null } = a || {}, f = new WebSocket(`${c}?authorization=${encodeURIComponent(Ue(i, o))}`);
|
|
459
|
+
f.onmessage = n, f.onclose = d, f.onerror = (m) => {
|
|
460
|
+
console.error(m), u == null || u("Websocket failed to connect", m), r(m);
|
|
461
|
+
}, f.onopen = (m) => {
|
|
462
|
+
s == null || s(m), t(f);
|
|
422
463
|
};
|
|
423
464
|
});
|
|
424
465
|
}
|
|
425
|
-
async function
|
|
466
|
+
async function Bt(e) {
|
|
426
467
|
const { retries: t = 1 } = e;
|
|
427
468
|
let r = null;
|
|
428
469
|
for (let a = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; a++)
|
|
429
470
|
try {
|
|
430
|
-
r = await
|
|
471
|
+
r = await jt(e);
|
|
431
472
|
} catch (c) {
|
|
432
473
|
if (a === t)
|
|
433
474
|
throw c;
|
|
434
|
-
await
|
|
475
|
+
await Ve(a * 500);
|
|
435
476
|
}
|
|
436
477
|
return r;
|
|
437
478
|
}
|
|
438
|
-
async function
|
|
439
|
-
const c = r != null && r.onMessage ? [r.onMessage] : [],
|
|
479
|
+
async function $t(e, t, r, a) {
|
|
480
|
+
const c = r != null && r.onMessage ? [r.onMessage] : [], i = await Bt({
|
|
440
481
|
auth: e,
|
|
441
482
|
host: t,
|
|
442
483
|
externalId: a,
|
|
443
484
|
callbacks: {
|
|
444
485
|
onError: (o) => {
|
|
445
486
|
var n;
|
|
446
|
-
return (n = r.onError) == null ? void 0 : n.call(r, new
|
|
487
|
+
return (n = r.onError) == null ? void 0 : n.call(r, new nt(o));
|
|
447
488
|
},
|
|
448
489
|
onMessage(o) {
|
|
449
490
|
const n = JSON.parse(o.data);
|
|
450
|
-
c.forEach((
|
|
491
|
+
c.forEach((s) => s(n.event, n));
|
|
451
492
|
}
|
|
452
493
|
}
|
|
453
494
|
});
|
|
454
495
|
return {
|
|
455
|
-
socket:
|
|
456
|
-
disconnect: () =>
|
|
496
|
+
socket: i,
|
|
497
|
+
disconnect: () => i.close(),
|
|
457
498
|
subscribeToEvents: (o) => c.push(o)
|
|
458
499
|
};
|
|
459
500
|
}
|
|
@@ -465,35 +506,35 @@ function xe(e) {
|
|
|
465
506
|
r += e[t++];
|
|
466
507
|
return r;
|
|
467
508
|
}
|
|
468
|
-
function
|
|
509
|
+
function zt(e, t, r) {
|
|
469
510
|
if (!e.content)
|
|
470
511
|
return;
|
|
471
512
|
const a = {
|
|
472
513
|
id: e.id || `user-${Date.now()}`,
|
|
473
514
|
role: e.role,
|
|
474
515
|
content: e.content,
|
|
475
|
-
parts:
|
|
516
|
+
parts: ne(e.content),
|
|
476
517
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
477
518
|
transcribed: !0
|
|
478
519
|
};
|
|
479
520
|
t.messages.push(a), r == null || r([...t.messages], "user");
|
|
480
521
|
}
|
|
481
|
-
function
|
|
482
|
-
if (e ===
|
|
483
|
-
|
|
522
|
+
function Nt(e, t, r, a, c, i, o) {
|
|
523
|
+
if (e === z.Transcribe && t.content) {
|
|
524
|
+
zt(t, a, c);
|
|
484
525
|
return;
|
|
485
526
|
}
|
|
486
|
-
if (!(e ===
|
|
527
|
+
if (!(e === z.Partial || e === z.Answer))
|
|
487
528
|
return;
|
|
488
529
|
const n = a.messages[a.messages.length - 1];
|
|
489
|
-
if (e ===
|
|
530
|
+
if (e === z.Answer && (n == null ? void 0 : n.role) === "user" && o === "partial")
|
|
490
531
|
return;
|
|
491
532
|
const d = o === "answer";
|
|
492
533
|
let u;
|
|
493
534
|
if ((n == null ? void 0 : n.role) === "assistant" && !d)
|
|
494
535
|
u = n;
|
|
495
536
|
else if (!n || n.role === "user" || d)
|
|
496
|
-
d &&
|
|
537
|
+
d && i(), u = {
|
|
497
538
|
id: t.id || `assistant-${Date.now()}`,
|
|
498
539
|
role: t.role || "assistant",
|
|
499
540
|
content: t.content || "",
|
|
@@ -502,102 +543,102 @@ function jt(e, t, r, a, c, s, o) {
|
|
|
502
543
|
}, a.messages.push(u);
|
|
503
544
|
else
|
|
504
545
|
return;
|
|
505
|
-
const { content:
|
|
506
|
-
if (e ===
|
|
507
|
-
r[
|
|
546
|
+
const { content: f, sequence: m } = t;
|
|
547
|
+
if (e === z.Partial)
|
|
548
|
+
r[m] = f;
|
|
508
549
|
else {
|
|
509
550
|
const y = xe(r);
|
|
510
|
-
!!(
|
|
551
|
+
!!(f && f.length < y.length) && (u.interrupted = !0), r.answer = f;
|
|
511
552
|
}
|
|
512
553
|
const w = xe(r);
|
|
513
|
-
(u.content !== w || e ===
|
|
554
|
+
(u.content !== w || e === z.Answer) && (u.content = w, u.parts = ne(w), c == null || c([...a.messages], e));
|
|
514
555
|
}
|
|
515
|
-
function
|
|
516
|
-
const
|
|
517
|
-
for (const d of Object.keys(
|
|
518
|
-
delete
|
|
556
|
+
function Ft(e, t, r, a, c) {
|
|
557
|
+
const i = {}, o = () => {
|
|
558
|
+
for (const d of Object.keys(i))
|
|
559
|
+
delete i[d];
|
|
519
560
|
};
|
|
520
561
|
let n = null;
|
|
521
|
-
const
|
|
522
|
-
var
|
|
523
|
-
u === "user" && o(), (
|
|
562
|
+
const s = (d, u) => {
|
|
563
|
+
var f, m;
|
|
564
|
+
u === "user" && o(), (m = (f = r.callbacks).onNewMessage) == null || m.call(f, d, u);
|
|
524
565
|
};
|
|
525
566
|
return {
|
|
526
567
|
clearQueue: o,
|
|
527
568
|
onMessage: (d, u) => {
|
|
528
|
-
var
|
|
569
|
+
var f, m;
|
|
529
570
|
if ("content" in u) {
|
|
530
|
-
const w = d === x.ChatAnswer ?
|
|
531
|
-
|
|
571
|
+
const w = d === x.ChatAnswer ? z.Answer : d === x.ChatAudioTranscribed ? z.Transcribe : d;
|
|
572
|
+
Nt(
|
|
532
573
|
w,
|
|
533
574
|
u,
|
|
534
|
-
s,
|
|
535
|
-
t,
|
|
536
575
|
i,
|
|
576
|
+
t,
|
|
577
|
+
s,
|
|
537
578
|
o,
|
|
538
579
|
n
|
|
539
|
-
), w ===
|
|
580
|
+
), w === z.Partial ? n = "partial" : w === z.Answer && (n = "answer", o()), w === z.Answer && e.track("agent-message-received", {
|
|
540
581
|
content: u.content,
|
|
541
582
|
messages: t.messages.length,
|
|
542
583
|
mode: t.chatMode
|
|
543
584
|
});
|
|
544
585
|
} else {
|
|
545
|
-
const w = x, y = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], j = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], M =
|
|
586
|
+
const w = x, y = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], j = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], M = bt(u, a, { mode: t.chatMode });
|
|
546
587
|
if (d = d, d === w.StreamVideoCreated && (e.linkTrack("agent-video", M, w.StreamVideoCreated, ["start"]), u.sentiment)) {
|
|
547
|
-
const
|
|
548
|
-
if ((
|
|
549
|
-
const L = { ...
|
|
550
|
-
t.messages[t.messages.length - 1] = L,
|
|
588
|
+
const T = t.messages[t.messages.length - 1];
|
|
589
|
+
if ((T == null ? void 0 : T.role) === "assistant") {
|
|
590
|
+
const L = { ...T, sentiment: u.sentiment };
|
|
591
|
+
t.messages[t.messages.length - 1] = L, s == null || s([...t.messages], n ?? "answer");
|
|
551
592
|
}
|
|
552
593
|
}
|
|
553
594
|
if (y.includes(d)) {
|
|
554
|
-
const
|
|
555
|
-
j.includes(d) ? e.track("agent-video", { ...M, event:
|
|
595
|
+
const T = d.split("/")[1];
|
|
596
|
+
j.includes(d) ? e.track("agent-video", { ...M, event: T }) : e.linkTrack("agent-video", { ...M, event: T }, d, ["done"]);
|
|
556
597
|
}
|
|
557
|
-
j.includes(d) && ((
|
|
598
|
+
j.includes(d) && ((m = (f = r.callbacks).onError) == null || m.call(f, new Ne(`Stream failed with event ${d}`), { data: u })), u.event === w.StreamDone && c();
|
|
558
599
|
}
|
|
559
600
|
}
|
|
560
601
|
};
|
|
561
602
|
}
|
|
562
|
-
function
|
|
563
|
-
const c =
|
|
603
|
+
function Vt(e, t, r, a) {
|
|
604
|
+
const c = He(e, `${t}/agents/${r}`, a);
|
|
564
605
|
return {
|
|
565
|
-
createStream(
|
|
566
|
-
return c.post("/streams",
|
|
606
|
+
createStream(i, o) {
|
|
607
|
+
return c.post("/streams", i, { signal: o });
|
|
567
608
|
},
|
|
568
|
-
startConnection(
|
|
609
|
+
startConnection(i, o, n, s) {
|
|
569
610
|
return c.post(
|
|
570
|
-
`/streams/${
|
|
611
|
+
`/streams/${i}/sdp`,
|
|
571
612
|
{
|
|
572
613
|
session_id: n,
|
|
573
614
|
answer: o
|
|
574
615
|
},
|
|
575
|
-
{ signal:
|
|
616
|
+
{ signal: s }
|
|
576
617
|
);
|
|
577
618
|
},
|
|
578
|
-
addIceCandidate(
|
|
619
|
+
addIceCandidate(i, o, n, s) {
|
|
579
620
|
return c.post(
|
|
580
|
-
`/streams/${
|
|
621
|
+
`/streams/${i}/ice`,
|
|
581
622
|
{
|
|
582
623
|
session_id: n,
|
|
583
624
|
...o
|
|
584
625
|
},
|
|
585
|
-
{ signal:
|
|
626
|
+
{ signal: s }
|
|
586
627
|
);
|
|
587
628
|
},
|
|
588
|
-
sendStreamRequest(
|
|
589
|
-
return c.post(`/streams/${
|
|
629
|
+
sendStreamRequest(i, o, n) {
|
|
630
|
+
return c.post(`/streams/${i}`, {
|
|
590
631
|
session_id: o,
|
|
591
632
|
...n
|
|
592
633
|
});
|
|
593
634
|
},
|
|
594
|
-
close(
|
|
595
|
-
return c.delete(`/streams/${
|
|
635
|
+
close(i, o) {
|
|
636
|
+
return c.delete(`/streams/${i}`, { session_id: o });
|
|
596
637
|
}
|
|
597
638
|
};
|
|
598
639
|
}
|
|
599
|
-
const
|
|
600
|
-
function
|
|
640
|
+
const Jt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
|
|
641
|
+
function Ut(e, t, r) {
|
|
601
642
|
const a = (t.timestamp - e.timestamp) / 1e3;
|
|
602
643
|
return {
|
|
603
644
|
duration: a,
|
|
@@ -617,7 +658,7 @@ function Ft(e, t, r) {
|
|
|
617
658
|
lowFpsCount: r
|
|
618
659
|
};
|
|
619
660
|
}
|
|
620
|
-
function
|
|
661
|
+
function Kt(e) {
|
|
621
662
|
return e.filter(
|
|
622
663
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
623
664
|
).map((t) => {
|
|
@@ -628,7 +669,7 @@ function Nt(e) {
|
|
|
628
669
|
};
|
|
629
670
|
});
|
|
630
671
|
}
|
|
631
|
-
function
|
|
672
|
+
function Wt(e) {
|
|
632
673
|
var o;
|
|
633
674
|
let t = "", r = 0, a = null;
|
|
634
675
|
const c = /* @__PURE__ */ new Map();
|
|
@@ -637,56 +678,17 @@ function Vt(e) {
|
|
|
637
678
|
if (n.type === "codec" && ((o = n.mimeType) != null && o.startsWith("video")))
|
|
638
679
|
c.set(n.id, n.mimeType.split("/")[1]);
|
|
639
680
|
else if (n.type === "candidate-pair") {
|
|
640
|
-
const
|
|
641
|
-
d > 0 && (
|
|
681
|
+
const s = n, d = s.currentRoundTripTime ?? 0;
|
|
682
|
+
d > 0 && (s.nominated === !0 || r === 0) && (r = d);
|
|
642
683
|
} else n.type === "inbound-rtp" && n.kind === "video" && (a = n);
|
|
643
684
|
if (!a)
|
|
644
685
|
return {};
|
|
645
|
-
const
|
|
646
|
-
return
|
|
686
|
+
const i = a;
|
|
687
|
+
return i.codecId && c.has(i.codecId) ? t = c.get(i.codecId) : c.size > 0 && (t = c.values().next().value ?? ""), {
|
|
647
688
|
codec: t,
|
|
648
689
|
rtt: r,
|
|
649
|
-
timestamp: s.timestamp,
|
|
650
|
-
bytesReceived: s.bytesReceived,
|
|
651
|
-
packetsReceived: s.packetsReceived,
|
|
652
|
-
packetsLost: s.packetsLost,
|
|
653
|
-
framesDropped: s.framesDropped,
|
|
654
|
-
framesDecoded: s.framesDecoded,
|
|
655
|
-
jitter: s.jitter,
|
|
656
|
-
jitterBufferDelay: s.jitterBufferDelay,
|
|
657
|
-
jitterBufferEmittedCount: s.jitterBufferEmittedCount,
|
|
658
|
-
avgJitterDelayInInterval: s.jitterBufferDelay / s.jitterBufferEmittedCount,
|
|
659
|
-
frameWidth: s.frameWidth,
|
|
660
|
-
frameHeight: s.frameHeight,
|
|
661
|
-
framesPerSecond: s.framesPerSecond,
|
|
662
|
-
freezeCount: s.freezeCount,
|
|
663
|
-
freezeDuration: s.totalFreezesDuration
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
function Le(e, t, r) {
|
|
667
|
-
const a = e.map((i, d) => d === 0 ? r ? {
|
|
668
690
|
timestamp: i.timestamp,
|
|
669
|
-
duration: 0,
|
|
670
|
-
rtt: i.rtt,
|
|
671
|
-
bytesReceived: i.bytesReceived - r.bytesReceived,
|
|
672
|
-
bitrate: (i.bytesReceived - r.bytesReceived) * 8 / (t / 1e3),
|
|
673
|
-
packetsReceived: i.packetsReceived - r.packetsReceived,
|
|
674
|
-
packetsLost: i.packetsLost - r.packetsLost,
|
|
675
|
-
framesDropped: i.framesDropped - r.framesDropped,
|
|
676
|
-
framesDecoded: i.framesDecoded - r.framesDecoded,
|
|
677
|
-
jitter: i.jitter,
|
|
678
|
-
jitterBufferDelay: i.jitterBufferDelay - r.jitterBufferDelay,
|
|
679
|
-
jitterBufferEmittedCount: i.jitterBufferEmittedCount - r.jitterBufferEmittedCount,
|
|
680
|
-
avgJitterDelayInInterval: (i.jitterBufferDelay - r.jitterBufferDelay) / (i.jitterBufferEmittedCount - r.jitterBufferEmittedCount),
|
|
681
|
-
framesPerSecond: i.framesPerSecond,
|
|
682
|
-
freezeCount: i.freezeCount - r.freezeCount,
|
|
683
|
-
freezeDuration: i.freezeDuration - r.freezeDuration
|
|
684
|
-
} : {
|
|
685
|
-
timestamp: i.timestamp,
|
|
686
|
-
rtt: i.rtt,
|
|
687
|
-
duration: 0,
|
|
688
691
|
bytesReceived: i.bytesReceived,
|
|
689
|
-
bitrate: i.bytesReceived * 8 / (t / 1e3),
|
|
690
692
|
packetsReceived: i.packetsReceived,
|
|
691
693
|
packetsLost: i.packetsLost,
|
|
692
694
|
framesDropped: i.framesDropped,
|
|
@@ -695,34 +697,73 @@ function Le(e, t, r) {
|
|
|
695
697
|
jitterBufferDelay: i.jitterBufferDelay,
|
|
696
698
|
jitterBufferEmittedCount: i.jitterBufferEmittedCount,
|
|
697
699
|
avgJitterDelayInInterval: i.jitterBufferDelay / i.jitterBufferEmittedCount,
|
|
700
|
+
frameWidth: i.frameWidth,
|
|
701
|
+
frameHeight: i.frameHeight,
|
|
698
702
|
framesPerSecond: i.framesPerSecond,
|
|
699
703
|
freezeCount: i.freezeCount,
|
|
700
|
-
freezeDuration: i.
|
|
704
|
+
freezeDuration: i.totalFreezesDuration
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function Le(e, t, r) {
|
|
708
|
+
const a = e.map((s, d) => d === 0 ? r ? {
|
|
709
|
+
timestamp: s.timestamp,
|
|
710
|
+
duration: 0,
|
|
711
|
+
rtt: s.rtt,
|
|
712
|
+
bytesReceived: s.bytesReceived - r.bytesReceived,
|
|
713
|
+
bitrate: (s.bytesReceived - r.bytesReceived) * 8 / (t / 1e3),
|
|
714
|
+
packetsReceived: s.packetsReceived - r.packetsReceived,
|
|
715
|
+
packetsLost: s.packetsLost - r.packetsLost,
|
|
716
|
+
framesDropped: s.framesDropped - r.framesDropped,
|
|
717
|
+
framesDecoded: s.framesDecoded - r.framesDecoded,
|
|
718
|
+
jitter: s.jitter,
|
|
719
|
+
jitterBufferDelay: s.jitterBufferDelay - r.jitterBufferDelay,
|
|
720
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount - r.jitterBufferEmittedCount,
|
|
721
|
+
avgJitterDelayInInterval: (s.jitterBufferDelay - r.jitterBufferDelay) / (s.jitterBufferEmittedCount - r.jitterBufferEmittedCount),
|
|
722
|
+
framesPerSecond: s.framesPerSecond,
|
|
723
|
+
freezeCount: s.freezeCount - r.freezeCount,
|
|
724
|
+
freezeDuration: s.freezeDuration - r.freezeDuration
|
|
701
725
|
} : {
|
|
702
|
-
timestamp:
|
|
726
|
+
timestamp: s.timestamp,
|
|
727
|
+
rtt: s.rtt,
|
|
728
|
+
duration: 0,
|
|
729
|
+
bytesReceived: s.bytesReceived,
|
|
730
|
+
bitrate: s.bytesReceived * 8 / (t / 1e3),
|
|
731
|
+
packetsReceived: s.packetsReceived,
|
|
732
|
+
packetsLost: s.packetsLost,
|
|
733
|
+
framesDropped: s.framesDropped,
|
|
734
|
+
framesDecoded: s.framesDecoded,
|
|
735
|
+
jitter: s.jitter,
|
|
736
|
+
jitterBufferDelay: s.jitterBufferDelay,
|
|
737
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount,
|
|
738
|
+
avgJitterDelayInInterval: s.jitterBufferDelay / s.jitterBufferEmittedCount,
|
|
739
|
+
framesPerSecond: s.framesPerSecond,
|
|
740
|
+
freezeCount: s.freezeCount,
|
|
741
|
+
freezeDuration: s.freezeDuration
|
|
742
|
+
} : {
|
|
743
|
+
timestamp: s.timestamp,
|
|
703
744
|
duration: t * d / 1e3,
|
|
704
|
-
rtt:
|
|
705
|
-
bytesReceived:
|
|
706
|
-
bitrate: (
|
|
707
|
-
packetsReceived:
|
|
708
|
-
packetsLost:
|
|
709
|
-
framesDropped:
|
|
710
|
-
framesDecoded:
|
|
711
|
-
jitter:
|
|
712
|
-
jitterBufferDelay:
|
|
713
|
-
jitterBufferEmittedCount:
|
|
714
|
-
avgJitterDelayInInterval: (
|
|
715
|
-
framesPerSecond:
|
|
716
|
-
freezeCount:
|
|
717
|
-
freezeDuration:
|
|
718
|
-
}), c =
|
|
745
|
+
rtt: s.rtt,
|
|
746
|
+
bytesReceived: s.bytesReceived - e[d - 1].bytesReceived,
|
|
747
|
+
bitrate: (s.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
|
|
748
|
+
packetsReceived: s.packetsReceived - e[d - 1].packetsReceived,
|
|
749
|
+
packetsLost: s.packetsLost - e[d - 1].packetsLost,
|
|
750
|
+
framesDropped: s.framesDropped - e[d - 1].framesDropped,
|
|
751
|
+
framesDecoded: s.framesDecoded - e[d - 1].framesDecoded,
|
|
752
|
+
jitter: s.jitter,
|
|
753
|
+
jitterBufferDelay: s.jitterBufferDelay - e[d - 1].jitterBufferDelay,
|
|
754
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
|
|
755
|
+
avgJitterDelayInInterval: (s.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (s.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
|
|
756
|
+
framesPerSecond: s.framesPerSecond,
|
|
757
|
+
freezeCount: s.freezeCount - e[d - 1].freezeCount,
|
|
758
|
+
freezeDuration: s.freezeDuration - e[d - 1].freezeDuration
|
|
759
|
+
}), c = Kt(a), i = c.reduce((s, d) => s + (d.causes.includes("low fps") ? 1 : 0), 0), o = a.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), n = a.filter((s) => !!s.rtt).map((s) => s.rtt);
|
|
719
760
|
return {
|
|
720
761
|
webRTCStats: {
|
|
721
762
|
anomalies: c,
|
|
722
763
|
minRtt: Math.min(...n),
|
|
723
764
|
avgRtt: Te(n),
|
|
724
765
|
maxRtt: Math.max(...n),
|
|
725
|
-
aggregateReport:
|
|
766
|
+
aggregateReport: Ut(e[0], e[e.length - 1], i),
|
|
726
767
|
minJitterDelayInInterval: Math.min(...o),
|
|
727
768
|
maxJitterDelayInInterval: Math.max(...o),
|
|
728
769
|
avgJitterDelayInInterval: Te(o)
|
|
@@ -731,95 +772,95 @@ function Le(e, t, r) {
|
|
|
731
772
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
732
773
|
};
|
|
733
774
|
}
|
|
734
|
-
function
|
|
775
|
+
function Ge(e, t) {
|
|
735
776
|
for (const r of e.values())
|
|
736
777
|
if ((r == null ? void 0 : r.type) === "inbound-rtp" && r.kind === t)
|
|
737
778
|
return r;
|
|
738
779
|
return null;
|
|
739
780
|
}
|
|
740
|
-
const
|
|
741
|
-
function
|
|
742
|
-
let r = !1, a = !1, c = null,
|
|
743
|
-
async function
|
|
781
|
+
const te = 10;
|
|
782
|
+
function wr(e, t) {
|
|
783
|
+
let r = !1, a = !1, c = null, i = 0, o = 0, n = {};
|
|
784
|
+
async function s() {
|
|
744
785
|
if (r) {
|
|
745
786
|
try {
|
|
746
787
|
const d = await e();
|
|
747
788
|
if (!d) {
|
|
748
|
-
c = setTimeout(
|
|
789
|
+
c = setTimeout(s, te);
|
|
749
790
|
return;
|
|
750
791
|
}
|
|
751
|
-
const u =
|
|
792
|
+
const u = Ge(d, "audio");
|
|
752
793
|
if (!u) {
|
|
753
|
-
c = setTimeout(
|
|
794
|
+
c = setTimeout(s, te);
|
|
754
795
|
return;
|
|
755
796
|
}
|
|
756
|
-
const
|
|
797
|
+
const f = u.totalAudioEnergy ?? 0, m = u.totalSamplesReceived ?? 0;
|
|
757
798
|
if (!a) {
|
|
758
|
-
|
|
799
|
+
i = f, o = m, a = !0, c = setTimeout(s, te);
|
|
759
800
|
return;
|
|
760
801
|
}
|
|
761
|
-
const w =
|
|
762
|
-
if (
|
|
802
|
+
const w = f - i, y = m - o;
|
|
803
|
+
if (i = f, o = m, y > 0 && w > 0) {
|
|
763
804
|
r = !1, t(n);
|
|
764
805
|
return;
|
|
765
806
|
}
|
|
766
807
|
} catch {
|
|
767
808
|
}
|
|
768
|
-
r && (c = setTimeout(
|
|
809
|
+
r && (c = setTimeout(s, te));
|
|
769
810
|
}
|
|
770
811
|
}
|
|
771
812
|
return {
|
|
772
813
|
arm(d = {}) {
|
|
773
|
-
n = d, r = !0, a = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(
|
|
814
|
+
n = d, r = !0, a = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(s, te);
|
|
774
815
|
},
|
|
775
816
|
destroy() {
|
|
776
817
|
r = !1, c !== null && (clearTimeout(c), c = null);
|
|
777
818
|
}
|
|
778
819
|
};
|
|
779
820
|
}
|
|
780
|
-
const
|
|
781
|
-
function
|
|
821
|
+
const de = 100, Ht = Math.max(Math.ceil(400 / de), 1), Ot = 0.25, qt = 0.28;
|
|
822
|
+
function Gt() {
|
|
782
823
|
let e = 0, t, r, a = 0;
|
|
783
824
|
return (c) => {
|
|
784
|
-
const
|
|
785
|
-
if (!
|
|
825
|
+
const i = Ge(c, "video");
|
|
826
|
+
if (!i)
|
|
786
827
|
return { isReceiving: !1, avgJitterDelayInInterval: a };
|
|
787
|
-
const o =
|
|
828
|
+
const o = i.jitterBufferDelay, n = i.jitterBufferEmittedCount;
|
|
788
829
|
if (r && n > r) {
|
|
789
|
-
const u = o - t,
|
|
790
|
-
a = u /
|
|
830
|
+
const u = o - t, f = n - r;
|
|
831
|
+
a = u / f;
|
|
791
832
|
}
|
|
792
833
|
t = o, r = n;
|
|
793
|
-
const
|
|
794
|
-
return e =
|
|
834
|
+
const s = i.framesDecoded, d = s - e > 0;
|
|
835
|
+
return e = s, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: i.freezeCount };
|
|
795
836
|
};
|
|
796
837
|
}
|
|
797
|
-
function
|
|
798
|
-
let
|
|
799
|
-
const y =
|
|
838
|
+
function Xt(e, t, r, a, c) {
|
|
839
|
+
let i = null, o = [], n, s = 0, d = !1, u = re.Unknown, f = re.Unknown, m = 0, w = 0;
|
|
840
|
+
const y = Gt();
|
|
800
841
|
async function j() {
|
|
801
842
|
const M = await e();
|
|
802
843
|
if (!M)
|
|
803
844
|
return;
|
|
804
|
-
const { isReceiving:
|
|
805
|
-
if (
|
|
806
|
-
|
|
807
|
-
else if (d && (
|
|
808
|
-
const
|
|
809
|
-
a == null || a(S.Stop,
|
|
845
|
+
const { isReceiving: T, avgJitterDelayInInterval: L, freezeCount: E } = y(M), X = Wt(M);
|
|
846
|
+
if (T)
|
|
847
|
+
s = 0, m = E - w, f = L < Ot ? re.Strong : L > qt && m > 1 ? re.Weak : u, f !== u && (c == null || c(f), u = f, w += m, m = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(X);
|
|
848
|
+
else if (d && (s++, s >= Ht)) {
|
|
849
|
+
const H = Le(o, de, n);
|
|
850
|
+
a == null || a(S.Stop, H), t() || r(), w = E, d = !1;
|
|
810
851
|
}
|
|
811
852
|
}
|
|
812
853
|
return {
|
|
813
854
|
start: () => {
|
|
814
|
-
|
|
855
|
+
i || (i = setInterval(j, de));
|
|
815
856
|
},
|
|
816
857
|
stop: () => {
|
|
817
|
-
|
|
858
|
+
i && (clearInterval(i), i = null);
|
|
818
859
|
},
|
|
819
|
-
getReport: () => Le(o,
|
|
860
|
+
getReport: () => Le(o, de, n)
|
|
820
861
|
};
|
|
821
862
|
}
|
|
822
|
-
const
|
|
863
|
+
const Yt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
823
864
|
function Pe(e) {
|
|
824
865
|
switch (e) {
|
|
825
866
|
case "connected":
|
|
@@ -840,7 +881,7 @@ function Pe(e) {
|
|
|
840
881
|
return b.New;
|
|
841
882
|
}
|
|
842
883
|
}
|
|
843
|
-
const
|
|
884
|
+
const Qt = (e) => (t) => {
|
|
844
885
|
const [r, a = ""] = t.split(/:(.+)/);
|
|
845
886
|
try {
|
|
846
887
|
const c = JSON.parse(a);
|
|
@@ -849,7 +890,7 @@ const qt = (e) => (t) => {
|
|
|
849
890
|
return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: c }), { subject: r, data: a };
|
|
850
891
|
}
|
|
851
892
|
};
|
|
852
|
-
function
|
|
893
|
+
function Zt({
|
|
853
894
|
statsSignal: e,
|
|
854
895
|
dataChannelSignal: t,
|
|
855
896
|
onVideoStateChange: r,
|
|
@@ -858,15 +899,15 @@ function Xt({
|
|
|
858
899
|
}) {
|
|
859
900
|
e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, a));
|
|
860
901
|
}
|
|
861
|
-
function
|
|
902
|
+
function er({
|
|
862
903
|
statsSignal: e,
|
|
863
904
|
dataChannelSignal: t,
|
|
864
905
|
onVideoStateChange: r,
|
|
865
906
|
onAgentActivityStateChange: a,
|
|
866
907
|
report: c,
|
|
867
|
-
log:
|
|
908
|
+
log: i
|
|
868
909
|
}) {
|
|
869
|
-
e === S.Start ? (
|
|
910
|
+
e === S.Start ? (i("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, c)), t === S.Start ? a == null || a(ae.Talking) : t === S.Stop && (a == null || a(ae.Idle));
|
|
870
911
|
}
|
|
871
912
|
function je({
|
|
872
913
|
statsSignal: e,
|
|
@@ -874,67 +915,67 @@ function je({
|
|
|
874
915
|
onVideoStateChange: r,
|
|
875
916
|
onAgentActivityStateChange: a,
|
|
876
917
|
streamType: c,
|
|
877
|
-
report:
|
|
918
|
+
report: i,
|
|
878
919
|
log: o
|
|
879
920
|
}) {
|
|
880
|
-
c === W.Legacy ?
|
|
921
|
+
c === W.Legacy ? Zt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: i, log: o }) : c === W.Fluent && er({
|
|
881
922
|
statsSignal: e,
|
|
882
923
|
dataChannelSignal: t,
|
|
883
924
|
onVideoStateChange: r,
|
|
884
925
|
onAgentActivityStateChange: a,
|
|
885
|
-
report:
|
|
926
|
+
report: i,
|
|
886
927
|
log: o
|
|
887
928
|
});
|
|
888
929
|
}
|
|
889
|
-
async function
|
|
930
|
+
async function tr(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: i = le, analytics: o }, n) {
|
|
890
931
|
var F;
|
|
891
|
-
const
|
|
892
|
-
let u = !1,
|
|
893
|
-
const { startConnection: y, sendStreamRequest: j, close: M, createStream:
|
|
932
|
+
const s = Jt(r, "WebRTCStreamingManager"), d = Qt(s);
|
|
933
|
+
let u = !1, f = !1, m = S.Stop, w = S.Stop;
|
|
934
|
+
const { startConnection: y, sendStreamRequest: j, close: M, createStream: T, addIceCandidate: L } = Vt(
|
|
894
935
|
c,
|
|
895
|
-
|
|
936
|
+
i,
|
|
896
937
|
e,
|
|
897
938
|
a.onError
|
|
898
939
|
), {
|
|
899
940
|
id: E,
|
|
900
|
-
offer:
|
|
901
|
-
ice_servers:
|
|
902
|
-
session_id:
|
|
903
|
-
fluent:
|
|
904
|
-
interrupt_enabled:
|
|
905
|
-
} = await
|
|
906
|
-
(F = a.onStreamCreated) == null || F.call(a, { stream_id: E, session_id:
|
|
907
|
-
const
|
|
908
|
-
if (!
|
|
941
|
+
offer: X,
|
|
942
|
+
ice_servers: H,
|
|
943
|
+
session_id: V,
|
|
944
|
+
fluent: ie,
|
|
945
|
+
interrupt_enabled: Y
|
|
946
|
+
} = await T(t, n);
|
|
947
|
+
(F = a.onStreamCreated) == null || F.call(a, { stream_id: E, session_id: V, agent_id: e });
|
|
948
|
+
const D = new Yt({ iceServers: H }), O = D.createDataChannel("JanusDataChannel");
|
|
949
|
+
if (!V)
|
|
909
950
|
throw new Error("Could not create session_id");
|
|
910
|
-
const
|
|
951
|
+
const J = ie ? W.Fluent : W.Legacy;
|
|
911
952
|
o.enrich({
|
|
912
|
-
"stream-type":
|
|
953
|
+
"stream-type": J
|
|
913
954
|
});
|
|
914
|
-
const
|
|
955
|
+
const se = t.stream_warmup && !ie, oe = () => u, ee = () => {
|
|
915
956
|
var g;
|
|
916
|
-
u = !0,
|
|
917
|
-
}, l =
|
|
918
|
-
() =>
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
(g,
|
|
957
|
+
u = !0, f && (s("CALLBACK: onConnectionStateChange(Connected)"), (g = a.onConnectionStateChange) == null || g.call(a, b.Connected));
|
|
958
|
+
}, l = Xt(
|
|
959
|
+
() => D.getStats(),
|
|
960
|
+
oe,
|
|
961
|
+
ee,
|
|
962
|
+
(g, h) => je({
|
|
922
963
|
statsSignal: w = g,
|
|
923
|
-
dataChannelSignal:
|
|
964
|
+
dataChannelSignal: J === W.Legacy ? m : void 0,
|
|
924
965
|
onVideoStateChange: a.onVideoStateChange,
|
|
925
966
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
926
|
-
report:
|
|
927
|
-
streamType:
|
|
928
|
-
log:
|
|
967
|
+
report: h,
|
|
968
|
+
streamType: J,
|
|
969
|
+
log: s
|
|
929
970
|
}),
|
|
930
971
|
(g) => {
|
|
931
|
-
var
|
|
932
|
-
return (
|
|
972
|
+
var h;
|
|
973
|
+
return (h = a.onConnectivityStateChange) == null ? void 0 : h.call(a, g);
|
|
933
974
|
}
|
|
934
975
|
);
|
|
935
|
-
l.start(),
|
|
936
|
-
var
|
|
937
|
-
|
|
976
|
+
l.start(), D.onicecandidate = (g) => {
|
|
977
|
+
var h;
|
|
978
|
+
s("peerConnection.onicecandidate", g);
|
|
938
979
|
try {
|
|
939
980
|
g.candidate && g.candidate.sdpMid && g.candidate.sdpMLineIndex !== null ? L(
|
|
940
981
|
E,
|
|
@@ -943,38 +984,38 @@ async function Yt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = le,
|
|
|
943
984
|
sdpMid: g.candidate.sdpMid,
|
|
944
985
|
sdpMLineIndex: g.candidate.sdpMLineIndex
|
|
945
986
|
},
|
|
946
|
-
|
|
987
|
+
V,
|
|
947
988
|
n
|
|
948
|
-
) : L(E, { candidate: null },
|
|
949
|
-
} catch (
|
|
950
|
-
(
|
|
989
|
+
) : L(E, { candidate: null }, V, n);
|
|
990
|
+
} catch (I) {
|
|
991
|
+
(h = a.onError) == null || h.call(a, I, { streamId: E });
|
|
951
992
|
}
|
|
952
993
|
}, O.onopen = () => {
|
|
953
|
-
|
|
994
|
+
f = !0, (!se || u) && ee();
|
|
954
995
|
};
|
|
955
|
-
let
|
|
996
|
+
let p = null;
|
|
956
997
|
const v = (g) => {
|
|
957
|
-
var
|
|
958
|
-
|
|
998
|
+
var h;
|
|
999
|
+
p = g, (h = a.onVideoIdChange) == null || h.call(a, g);
|
|
959
1000
|
};
|
|
960
|
-
function C(g,
|
|
961
|
-
if (g === x.StreamStarted && typeof
|
|
962
|
-
const
|
|
963
|
-
v(
|
|
1001
|
+
function C(g, h) {
|
|
1002
|
+
if (g === x.StreamStarted && typeof h == "object" && "metadata" in h) {
|
|
1003
|
+
const I = h.metadata;
|
|
1004
|
+
v(I.videoId);
|
|
964
1005
|
}
|
|
965
|
-
g === x.StreamDone && v(null),
|
|
966
|
-
statsSignal:
|
|
967
|
-
dataChannelSignal:
|
|
1006
|
+
g === x.StreamDone && v(null), m = g === x.StreamStarted ? S.Start : S.Stop, je({
|
|
1007
|
+
statsSignal: J === W.Legacy ? w : void 0,
|
|
1008
|
+
dataChannelSignal: m,
|
|
968
1009
|
onVideoStateChange: a.onVideoStateChange,
|
|
969
1010
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
970
|
-
streamType:
|
|
971
|
-
log:
|
|
1011
|
+
streamType: J,
|
|
1012
|
+
log: s
|
|
972
1013
|
});
|
|
973
1014
|
}
|
|
974
|
-
function k(g,
|
|
975
|
-
var
|
|
976
|
-
const
|
|
977
|
-
|
|
1015
|
+
function k(g, h) {
|
|
1016
|
+
var B;
|
|
1017
|
+
const I = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
|
|
1018
|
+
I && o.enrich({ streamMetadata: I }), (B = a.onStreamReady) == null || B.call(a);
|
|
978
1019
|
}
|
|
979
1020
|
const R = {
|
|
980
1021
|
[x.StreamStarted]: C,
|
|
@@ -982,32 +1023,32 @@ async function Yt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = le,
|
|
|
982
1023
|
[x.StreamReady]: k
|
|
983
1024
|
};
|
|
984
1025
|
O.onmessage = (g) => {
|
|
985
|
-
var
|
|
986
|
-
const { subject:
|
|
987
|
-
(
|
|
988
|
-
},
|
|
989
|
-
var
|
|
990
|
-
|
|
991
|
-
const g = Pe(
|
|
992
|
-
g !== b.Connected && ((
|
|
993
|
-
},
|
|
994
|
-
var
|
|
995
|
-
|
|
996
|
-
}, await
|
|
997
|
-
const P = await
|
|
998
|
-
|
|
999
|
-
function
|
|
1000
|
-
var
|
|
1026
|
+
var B;
|
|
1027
|
+
const { subject: h, data: I } = d(g.data);
|
|
1028
|
+
(B = R[h]) == null || B.call(R, h, I);
|
|
1029
|
+
}, D.oniceconnectionstatechange = () => {
|
|
1030
|
+
var h;
|
|
1031
|
+
s("peerConnection.oniceconnectionstatechange => " + D.iceConnectionState);
|
|
1032
|
+
const g = Pe(D.iceConnectionState);
|
|
1033
|
+
g !== b.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, g));
|
|
1034
|
+
}, D.ontrack = (g) => {
|
|
1035
|
+
var h;
|
|
1036
|
+
s("peerConnection.ontrack", g), s("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, g.streams[0]);
|
|
1037
|
+
}, await D.setRemoteDescription(X), s("set remote description OK");
|
|
1038
|
+
const P = await D.createAnswer();
|
|
1039
|
+
s("create answer OK"), await D.setLocalDescription(P), s("set local description OK"), await y(E, P, V, n), s("start connection OK");
|
|
1040
|
+
function N(g) {
|
|
1041
|
+
var h, I;
|
|
1001
1042
|
if (!u || O.readyState !== "open") {
|
|
1002
|
-
|
|
1043
|
+
s("Data channel is not ready for sending messages"), (h = a.onError) == null || h.call(a, new Ne("Data channel is not ready for sending messages"), {
|
|
1003
1044
|
streamId: E
|
|
1004
1045
|
});
|
|
1005
1046
|
return;
|
|
1006
1047
|
}
|
|
1007
1048
|
try {
|
|
1008
1049
|
O.send(g);
|
|
1009
|
-
} catch (
|
|
1010
|
-
|
|
1050
|
+
} catch (B) {
|
|
1051
|
+
s("Error sending data channel message", B), (I = a.onError) == null || I.call(a, B, { streamId: E });
|
|
1011
1052
|
}
|
|
1012
1053
|
}
|
|
1013
1054
|
return {
|
|
@@ -1016,7 +1057,7 @@ async function Yt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = le,
|
|
|
1016
1057
|
* @param payload
|
|
1017
1058
|
*/
|
|
1018
1059
|
speak(g) {
|
|
1019
|
-
return j(E,
|
|
1060
|
+
return j(E, V, g);
|
|
1020
1061
|
},
|
|
1021
1062
|
/**
|
|
1022
1063
|
* Method to close RTC connection
|
|
@@ -1024,64 +1065,64 @@ async function Yt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = le,
|
|
|
1024
1065
|
async disconnect() {
|
|
1025
1066
|
var g;
|
|
1026
1067
|
if (E) {
|
|
1027
|
-
const
|
|
1028
|
-
if (
|
|
1029
|
-
if (
|
|
1068
|
+
const h = Pe(D.iceConnectionState);
|
|
1069
|
+
if (D) {
|
|
1070
|
+
if (h === b.New) {
|
|
1030
1071
|
l.stop();
|
|
1031
1072
|
return;
|
|
1032
1073
|
}
|
|
1033
|
-
|
|
1074
|
+
D.close(), D.oniceconnectionstatechange = null, D.onnegotiationneeded = null, D.onicecandidate = null, D.ontrack = null;
|
|
1034
1075
|
}
|
|
1035
1076
|
try {
|
|
1036
|
-
|
|
1077
|
+
h === b.Connected && await M(E, V).catch((I) => {
|
|
1037
1078
|
});
|
|
1038
|
-
} catch (
|
|
1039
|
-
|
|
1079
|
+
} catch (I) {
|
|
1080
|
+
s("Error on close stream connection", I);
|
|
1040
1081
|
}
|
|
1041
|
-
(g = a.onAgentActivityStateChange) == null || g.call(a,
|
|
1082
|
+
(g = a.onAgentActivityStateChange) == null || g.call(a, ae.Idle), l.stop();
|
|
1042
1083
|
}
|
|
1043
1084
|
},
|
|
1044
|
-
sendDataChannelMessage:
|
|
1085
|
+
sendDataChannelMessage: N,
|
|
1045
1086
|
/**
|
|
1046
1087
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1047
1088
|
*/
|
|
1048
|
-
sessionId:
|
|
1089
|
+
sessionId: V,
|
|
1049
1090
|
/**
|
|
1050
1091
|
* Id of current RTC stream
|
|
1051
1092
|
*/
|
|
1052
1093
|
streamId: E,
|
|
1053
|
-
streamType:
|
|
1054
|
-
interruptAvailable:
|
|
1094
|
+
streamType: J,
|
|
1095
|
+
interruptAvailable: Y ?? !1,
|
|
1055
1096
|
isInterruptible: !0,
|
|
1056
1097
|
interrupt(g) {
|
|
1057
|
-
if (!
|
|
1098
|
+
if (!Y)
|
|
1058
1099
|
throw new Error("Interrupt is not enabled for this stream");
|
|
1059
|
-
if (
|
|
1100
|
+
if (J !== W.Fluent)
|
|
1060
1101
|
throw new Error("Interrupt only available for Fluent streams");
|
|
1061
|
-
if (!
|
|
1102
|
+
if (!p)
|
|
1062
1103
|
throw new Error("No active video to interrupt");
|
|
1063
|
-
const
|
|
1104
|
+
const h = {
|
|
1064
1105
|
type: x.StreamInterrupt,
|
|
1065
|
-
videoId:
|
|
1106
|
+
videoId: p,
|
|
1066
1107
|
timestamp: Date.now()
|
|
1067
1108
|
};
|
|
1068
|
-
|
|
1109
|
+
N(JSON.stringify(h));
|
|
1069
1110
|
}
|
|
1070
1111
|
};
|
|
1071
1112
|
}
|
|
1072
|
-
var
|
|
1073
|
-
async function
|
|
1113
|
+
var he = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(he || {});
|
|
1114
|
+
async function rr(e, t, r, a) {
|
|
1074
1115
|
const c = e.id;
|
|
1075
1116
|
switch (t.version) {
|
|
1076
1117
|
case "v1": {
|
|
1077
|
-
const { version:
|
|
1078
|
-
return
|
|
1118
|
+
const { version: i, ...o } = t;
|
|
1119
|
+
return tr(c, o, r, a);
|
|
1079
1120
|
}
|
|
1080
1121
|
case "v2": {
|
|
1081
|
-
const { version:
|
|
1122
|
+
const { version: i, ...o } = t;
|
|
1082
1123
|
switch (o.transport.provider) {
|
|
1083
|
-
case
|
|
1084
|
-
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-
|
|
1124
|
+
case pe.Livekit:
|
|
1125
|
+
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-CFuAnjAa.js");
|
|
1085
1126
|
return n(c, o, r);
|
|
1086
1127
|
default:
|
|
1087
1128
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
@@ -1091,18 +1132,18 @@ async function Qt(e, t, r, a) {
|
|
|
1091
1132
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1092
1133
|
}
|
|
1093
1134
|
}
|
|
1094
|
-
const
|
|
1095
|
-
function
|
|
1135
|
+
const nr = "cht";
|
|
1136
|
+
function ar() {
|
|
1096
1137
|
return {
|
|
1097
1138
|
transport: {
|
|
1098
|
-
provider:
|
|
1139
|
+
provider: pe.Livekit
|
|
1099
1140
|
}
|
|
1100
1141
|
};
|
|
1101
1142
|
}
|
|
1102
|
-
function
|
|
1103
|
-
var c,
|
|
1143
|
+
function ir(e) {
|
|
1144
|
+
var c, i;
|
|
1104
1145
|
const { streamOptions: t } = e ?? {}, r = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
1105
|
-
plan: (
|
|
1146
|
+
plan: (i = e.mixpanelAdditionalProperties) == null ? void 0 : i.plan
|
|
1106
1147
|
} : void 0;
|
|
1107
1148
|
return { ...{
|
|
1108
1149
|
output_resolution: t == null ? void 0 : t.outputResolution,
|
|
@@ -1112,16 +1153,16 @@ function tr(e) {
|
|
|
1112
1153
|
fluent: t == null ? void 0 : t.fluent
|
|
1113
1154
|
}, ...r && { end_user_data: r } };
|
|
1114
1155
|
}
|
|
1115
|
-
function
|
|
1116
|
-
return we(e.presenter.type) ? { version:
|
|
1156
|
+
function sr(e, t) {
|
|
1157
|
+
return we(e.presenter.type) ? { version: he.V2, ...ar() } : { version: he.V1, ...ir(t) };
|
|
1117
1158
|
}
|
|
1118
|
-
function
|
|
1159
|
+
function or(e, t, r) {
|
|
1119
1160
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1120
1161
|
}
|
|
1121
|
-
function
|
|
1122
|
-
c === W.Fluent ?
|
|
1162
|
+
function cr(e, t, r, a, c) {
|
|
1163
|
+
c === W.Fluent ? dr(e, t, r, a, c) : lr(e, t, r, a, c);
|
|
1123
1164
|
}
|
|
1124
|
-
function
|
|
1165
|
+
function dr(e, t, r, a, c) {
|
|
1125
1166
|
e === S.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && a.track("stream-session", {
|
|
1126
1167
|
event: "stop",
|
|
1127
1168
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
@@ -1130,7 +1171,7 @@ function ir(e, t, r, a, c) {
|
|
|
1130
1171
|
...r
|
|
1131
1172
|
});
|
|
1132
1173
|
}
|
|
1133
|
-
function
|
|
1174
|
+
function Be(e, t, r, a, c) {
|
|
1134
1175
|
e === S.Start ? r.linkTrack("agent-video", { event: "start", ...c, "stream-type": a }, "start", [
|
|
1135
1176
|
x.StreamVideoCreated
|
|
1136
1177
|
]) : e === S.Stop && r.linkTrack(
|
|
@@ -1145,10 +1186,10 @@ function $e(e, t, r, a, c) {
|
|
|
1145
1186
|
[x.StreamVideoDone]
|
|
1146
1187
|
);
|
|
1147
1188
|
}
|
|
1148
|
-
function
|
|
1189
|
+
function lr(e, t, r, a, c) {
|
|
1149
1190
|
e === S.Start ? a.linkTrack(
|
|
1150
1191
|
"agent-video",
|
|
1151
|
-
{ event: "start", latency:
|
|
1192
|
+
{ event: "start", latency: q.get(!0), "stream-type": c },
|
|
1152
1193
|
"start",
|
|
1153
1194
|
[x.StreamVideoCreated]
|
|
1154
1195
|
) : e === S.Stop && a.linkTrack(
|
|
@@ -1164,7 +1205,7 @@ function sr(e, t, r, a, c) {
|
|
|
1164
1205
|
[x.StreamVideoDone]
|
|
1165
1206
|
);
|
|
1166
1207
|
}
|
|
1167
|
-
function
|
|
1208
|
+
function ur(e, t, r) {
|
|
1168
1209
|
const a = {
|
|
1169
1210
|
call_id: t.call_id,
|
|
1170
1211
|
name: t.name
|
|
@@ -1181,80 +1222,80 @@ function or(e, t, r) {
|
|
|
1181
1222
|
extra_keys: c.extra ? Object.keys(c.extra).length : 0
|
|
1182
1223
|
});
|
|
1183
1224
|
}
|
|
1184
|
-
function
|
|
1185
|
-
return
|
|
1225
|
+
function $e(e, t, r, a) {
|
|
1226
|
+
return q.reset(), be.update(), new Promise(async (c, i) => {
|
|
1186
1227
|
try {
|
|
1187
1228
|
let o, n = !1;
|
|
1188
|
-
const
|
|
1229
|
+
const s = sr(e, t);
|
|
1189
1230
|
r.enrich({
|
|
1190
|
-
"stream-version":
|
|
1231
|
+
"stream-version": s.version.toString()
|
|
1191
1232
|
});
|
|
1192
1233
|
let d = null;
|
|
1193
1234
|
const u = e.presenter.type === "expressive";
|
|
1194
|
-
o = await
|
|
1235
|
+
o = await rr(
|
|
1195
1236
|
e,
|
|
1196
|
-
|
|
1237
|
+
s,
|
|
1197
1238
|
{
|
|
1198
1239
|
...t,
|
|
1199
1240
|
analytics: r,
|
|
1200
1241
|
callbacks: {
|
|
1201
1242
|
...t.callbacks,
|
|
1202
|
-
onConnectionStateChange: (
|
|
1243
|
+
onConnectionStateChange: (f, m) => {
|
|
1203
1244
|
var w, y;
|
|
1204
|
-
(y = (w = t.callbacks).onConnectionStateChange) == null || y.call(w,
|
|
1245
|
+
(y = (w = t.callbacks).onConnectionStateChange) == null || y.call(w, f), or(f, m, r), f === b.Connected && (o ? c(o) : n = !0);
|
|
1205
1246
|
},
|
|
1206
|
-
onVideoStateChange: (
|
|
1247
|
+
onVideoStateChange: (f, m) => {
|
|
1207
1248
|
var w, y;
|
|
1208
|
-
(y = (w = t.callbacks).onVideoStateChange) == null || y.call(w,
|
|
1209
|
-
m,
|
|
1210
|
-
e,
|
|
1249
|
+
(y = (w = t.callbacks).onVideoStateChange) == null || y.call(w, f), cr(
|
|
1211
1250
|
f,
|
|
1251
|
+
e,
|
|
1252
|
+
m,
|
|
1212
1253
|
r,
|
|
1213
1254
|
o.streamType
|
|
1214
1255
|
);
|
|
1215
1256
|
},
|
|
1216
|
-
onAgentActivityStateChange: (
|
|
1217
|
-
var
|
|
1218
|
-
(w = (
|
|
1219
|
-
|
|
1257
|
+
onAgentActivityStateChange: (f) => {
|
|
1258
|
+
var m, w;
|
|
1259
|
+
(w = (m = t.callbacks).onAgentActivityStateChange) == null || w.call(m, f), f === ae.Talking ? (ge.update(), d = (y) => {
|
|
1260
|
+
Be(
|
|
1220
1261
|
S.Start,
|
|
1221
1262
|
e,
|
|
1222
1263
|
r,
|
|
1223
1264
|
o.streamType,
|
|
1224
1265
|
y
|
|
1225
1266
|
), d = null;
|
|
1226
|
-
}, u || d({ latency:
|
|
1267
|
+
}, u || d({ latency: q.get(!0) })) : (ge.reset(), d = null, Be(
|
|
1227
1268
|
S.Stop,
|
|
1228
1269
|
e,
|
|
1229
1270
|
r,
|
|
1230
1271
|
o.streamType
|
|
1231
1272
|
));
|
|
1232
1273
|
},
|
|
1233
|
-
onFirstAudioDetected: (
|
|
1234
|
-
d == null || d(
|
|
1274
|
+
onFirstAudioDetected: (f) => {
|
|
1275
|
+
d == null || d(f);
|
|
1235
1276
|
},
|
|
1236
1277
|
onStreamReady: () => {
|
|
1237
|
-
const
|
|
1238
|
-
r.track("agent-chat", { event: "ready", latency:
|
|
1278
|
+
const f = be.get(!0);
|
|
1279
|
+
r.track("agent-chat", { event: "ready", latency: f });
|
|
1239
1280
|
},
|
|
1240
|
-
onToolEvent: ((
|
|
1281
|
+
onToolEvent: ((f, m) => {
|
|
1241
1282
|
var w, y;
|
|
1242
|
-
(y = (w = t.callbacks).onToolEvent) == null || y.call(w,
|
|
1283
|
+
(y = (w = t.callbacks).onToolEvent) == null || y.call(w, f, m), ur(f, m, r);
|
|
1243
1284
|
})
|
|
1244
1285
|
}
|
|
1245
1286
|
},
|
|
1246
1287
|
a
|
|
1247
1288
|
), n && c(o);
|
|
1248
1289
|
} catch (o) {
|
|
1249
|
-
|
|
1290
|
+
i(o);
|
|
1250
1291
|
}
|
|
1251
1292
|
});
|
|
1252
1293
|
}
|
|
1253
|
-
async function
|
|
1254
|
-
var u,
|
|
1255
|
-
const
|
|
1294
|
+
async function mr(e, t, r, a, c) {
|
|
1295
|
+
var u, f, m, w;
|
|
1296
|
+
const i = async () => {
|
|
1256
1297
|
if (we(e.presenter.type)) {
|
|
1257
|
-
const y = await
|
|
1298
|
+
const y = await $e(e, t, a), j = `${nr}_${y.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
|
|
1258
1299
|
return { chatResult: {
|
|
1259
1300
|
chatMode: A.Functional,
|
|
1260
1301
|
chat: {
|
|
@@ -1273,105 +1314,105 @@ async function cr(e, t, r, a, c) {
|
|
|
1273
1314
|
const y = new AbortController(), j = y.signal;
|
|
1274
1315
|
let M;
|
|
1275
1316
|
try {
|
|
1276
|
-
const
|
|
1317
|
+
const T = qe(
|
|
1277
1318
|
e,
|
|
1278
1319
|
r,
|
|
1279
1320
|
a,
|
|
1280
1321
|
t.mode,
|
|
1281
1322
|
t.persistentChat,
|
|
1282
1323
|
c
|
|
1283
|
-
), L =
|
|
1284
|
-
return { chatResult: E, streamingManager:
|
|
1285
|
-
} catch (
|
|
1324
|
+
), L = $e(e, t, a, j).then((H) => (M = H, H)), [E, X] = await Promise.all([T, L]);
|
|
1325
|
+
return { chatResult: E, streamingManager: X };
|
|
1326
|
+
} catch (T) {
|
|
1286
1327
|
throw y.abort(), M && await M.disconnect().catch(() => {
|
|
1287
|
-
}),
|
|
1328
|
+
}), T;
|
|
1288
1329
|
}
|
|
1289
1330
|
}
|
|
1290
|
-
}, { chatResult: o, streamingManager: n } = await
|
|
1291
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (
|
|
1331
|
+
}, { chatResult: o, streamingManager: n } = await i(), { chat: s, chatMode: d } = o;
|
|
1332
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (f = (u = t.callbacks).onModeChange) == null || f.call(u, d), d !== A.Functional) ? ((w = (m = t.callbacks).onError) == null || w.call(m, new et(d)), n == null || n.disconnect(), { chat: s }) : { chat: s, streamingManager: n };
|
|
1292
1333
|
}
|
|
1293
|
-
async function
|
|
1294
|
-
var
|
|
1334
|
+
async function vr(e, t) {
|
|
1335
|
+
var J, se, oe, ee;
|
|
1295
1336
|
let r = !0;
|
|
1296
|
-
const a = t.mixpanelKey ||
|
|
1337
|
+
const a = t.mixpanelKey || wt, c = t.wsURL || pt, i = t.baseURL || le, o = t.mode || A.Functional, n = {
|
|
1297
1338
|
messages: [],
|
|
1298
1339
|
chatMode: o
|
|
1299
|
-
},
|
|
1340
|
+
}, s = Lt({
|
|
1300
1341
|
token: a,
|
|
1301
1342
|
agentId: e,
|
|
1302
1343
|
isEnabled: t.enableAnalitics,
|
|
1303
1344
|
externalId: t.externalId,
|
|
1304
1345
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1305
1346
|
}), d = Date.now();
|
|
1306
|
-
|
|
1307
|
-
|
|
1347
|
+
_e(() => {
|
|
1348
|
+
s.track("agent-sdk", { event: "init" }, d);
|
|
1308
1349
|
});
|
|
1309
1350
|
const u = t.callbacks.onError;
|
|
1310
|
-
t.callbacks.onError = (l,
|
|
1311
|
-
|
|
1351
|
+
t.callbacks.onError = (l, p) => {
|
|
1352
|
+
s.track("agent-error", { error: Ae(l) }), u == null || u(l, p);
|
|
1312
1353
|
};
|
|
1313
|
-
const
|
|
1314
|
-
t.debug = t.debug || ((
|
|
1315
|
-
const w = we(
|
|
1316
|
-
|
|
1317
|
-
const { onMessage: y, clearQueue: j } =
|
|
1318
|
-
var l,
|
|
1319
|
-
(l = n.socketManager) == null || l.disconnect(), (v = (
|
|
1354
|
+
const f = Mt(t.auth, i, t.callbacks.onError, t.externalId), m = await f.getById(e);
|
|
1355
|
+
t.debug = t.debug || ((J = m == null ? void 0 : m.advanced_settings) == null ? void 0 : J.ui_debug_mode);
|
|
1356
|
+
const w = we(m.presenter.type);
|
|
1357
|
+
s.enrich(Tt(m));
|
|
1358
|
+
const { onMessage: y, clearQueue: j } = Ft(s, n, t, m, () => {
|
|
1359
|
+
var l, p, v;
|
|
1360
|
+
(l = n.socketManager) == null || l.disconnect(), (v = (p = t.callbacks).onConnectionStateChange) == null || v.call(p, b.Disconnected);
|
|
1320
1361
|
});
|
|
1321
|
-
n.messages =
|
|
1362
|
+
n.messages = Pt(t.initialMessages), (oe = (se = t.callbacks).onNewMessage) == null || oe.call(se, [...n.messages], "answer");
|
|
1322
1363
|
const M = (l) => {
|
|
1323
|
-
},
|
|
1364
|
+
}, T = ({ type: l }) => {
|
|
1324
1365
|
var v, C, k, R;
|
|
1325
1366
|
if (!((v = n.streamingManager) != null && v.interruptAvailable) || !((C = n.streamingManager) != null && C.isInterruptible)) return;
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1367
|
+
const p = n.messages[n.messages.length - 1];
|
|
1368
|
+
s.track("agent-video-interrupt", {
|
|
1328
1369
|
type: l || "click",
|
|
1329
1370
|
video_duration_to_interrupt: ge.get(!0),
|
|
1330
|
-
message_duration_to_interrupt:
|
|
1331
|
-
}),
|
|
1371
|
+
message_duration_to_interrupt: q.get(!0)
|
|
1372
|
+
}), p.interrupted = !0, (R = (k = t.callbacks).onNewMessage) == null || R.call(k, [...n.messages], "answer"), n.streamingManager.interrupt(l);
|
|
1332
1373
|
}, L = /* @__PURE__ */ new Map();
|
|
1333
1374
|
function E(l) {
|
|
1334
|
-
return async (
|
|
1375
|
+
return async (p) => {
|
|
1335
1376
|
const v = L.get(l);
|
|
1336
1377
|
if (!v)
|
|
1337
1378
|
throw new Error(`No handler registered for client tool: ${l}`);
|
|
1338
1379
|
try {
|
|
1339
|
-
const C = JSON.parse(
|
|
1380
|
+
const C = JSON.parse(p.payload);
|
|
1340
1381
|
return await v(C);
|
|
1341
1382
|
} catch (C) {
|
|
1342
1383
|
throw new Error(`Client tool "${l}" failed: ${C.message}`);
|
|
1343
1384
|
}
|
|
1344
1385
|
};
|
|
1345
1386
|
}
|
|
1346
|
-
function
|
|
1347
|
-
var l,
|
|
1387
|
+
function X() {
|
|
1388
|
+
var l, p, v, C;
|
|
1348
1389
|
for (const [k] of L)
|
|
1349
|
-
(
|
|
1390
|
+
(p = (l = n.streamingManager) == null ? void 0 : l.unregisterRpcMethod) == null || p.call(l, k), (C = (v = n.streamingManager) == null ? void 0 : v.registerRpcMethod) == null || C.call(v, k, E(k));
|
|
1350
1391
|
}
|
|
1351
|
-
function
|
|
1392
|
+
function H(l, p) {
|
|
1352
1393
|
var C, k;
|
|
1353
1394
|
const v = !L.has(l);
|
|
1354
|
-
L.set(l,
|
|
1395
|
+
L.set(l, p), v && ((k = (C = n.streamingManager) == null ? void 0 : C.registerRpcMethod) == null || k.call(C, l, E(l)));
|
|
1355
1396
|
}
|
|
1356
|
-
function
|
|
1357
|
-
var
|
|
1358
|
-
L.delete(l), (v = (
|
|
1397
|
+
function V(l) {
|
|
1398
|
+
var p, v;
|
|
1399
|
+
L.delete(l), (v = (p = n.streamingManager) == null ? void 0 : p.unregisterRpcMethod) == null || v.call(p, l);
|
|
1359
1400
|
}
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1401
|
+
const ie = Date.now();
|
|
1402
|
+
_e(() => {
|
|
1403
|
+
s.track("agent-sdk", { event: "loaded", ...Et(m) }, ie);
|
|
1363
1404
|
});
|
|
1364
|
-
async function
|
|
1365
|
-
var P,
|
|
1366
|
-
|
|
1367
|
-
const
|
|
1405
|
+
async function Y(l) {
|
|
1406
|
+
var P, N, F, g, h, I, B;
|
|
1407
|
+
ft(), (N = (P = t.callbacks).onConnectionStateChange) == null || N.call(P, b.Connecting), q.reset(), l && !r && (delete n.chat, (g = (F = t.callbacks).onNewMessage) == null || g.call(F, [...n.messages], "answer"));
|
|
1408
|
+
const p = o === A.DirectPlayback || w ? Promise.resolve(void 0) : $t(
|
|
1368
1409
|
t.auth,
|
|
1369
1410
|
c,
|
|
1370
1411
|
{ onMessage: y, onError: t.callbacks.onError },
|
|
1371
1412
|
t.externalId
|
|
1372
1413
|
), v = fe(
|
|
1373
|
-
() =>
|
|
1374
|
-
|
|
1414
|
+
() => mr(
|
|
1415
|
+
m,
|
|
1375
1416
|
{
|
|
1376
1417
|
...t,
|
|
1377
1418
|
mode: o,
|
|
@@ -1381,37 +1422,37 @@ async function fr(e, t) {
|
|
|
1381
1422
|
onMessage: y
|
|
1382
1423
|
}
|
|
1383
1424
|
},
|
|
1384
|
-
|
|
1385
|
-
|
|
1425
|
+
f,
|
|
1426
|
+
s,
|
|
1386
1427
|
n.chat
|
|
1387
1428
|
),
|
|
1388
1429
|
{
|
|
1389
1430
|
limit: 3,
|
|
1390
|
-
timeout:
|
|
1431
|
+
timeout: gt,
|
|
1391
1432
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1392
|
-
shouldRetryFn: (K) => (K == null ? void 0 : K.message) !== "Could not connect" && K
|
|
1433
|
+
shouldRetryFn: (K) => (K == null ? void 0 : K.message) !== "Could not connect" && !(K instanceof ze && (K.status === 429 || K.kind === "InsufficientCreditsError")),
|
|
1393
1434
|
delayMs: 1e3
|
|
1394
1435
|
}
|
|
1395
1436
|
).catch((K) => {
|
|
1396
|
-
var
|
|
1397
|
-
throw O(A.Maintenance), (U = (
|
|
1398
|
-
}), [C, { streamingManager: k, chat: R }] = await Promise.all([
|
|
1399
|
-
R && R.id !== ((
|
|
1437
|
+
var _, U;
|
|
1438
|
+
throw O(A.Maintenance), (U = (_ = t.callbacks).onConnectionStateChange) == null || U.call(_, b.Fail), K;
|
|
1439
|
+
}), [C, { streamingManager: k, chat: R }] = await Promise.all([p, v]);
|
|
1440
|
+
R && R.id !== ((h = n.chat) == null ? void 0 : h.id) && ((B = (I = t.callbacks).onNewChat) == null || B.call(I, R.id)), n.streamingManager = k, n.socketManager = C, n.chat = R, X(), r = !1, s.enrich({
|
|
1400
1441
|
chatId: R == null ? void 0 : R.id,
|
|
1401
1442
|
streamId: k == null ? void 0 : k.streamId,
|
|
1402
1443
|
mode: n.chatMode
|
|
1403
1444
|
}), O((R == null ? void 0 : R.chat_mode) ?? o);
|
|
1404
1445
|
}
|
|
1405
|
-
async function
|
|
1406
|
-
var l,
|
|
1407
|
-
(l = n.socketManager) == null || l.disconnect(), await ((
|
|
1446
|
+
async function D() {
|
|
1447
|
+
var l, p, v, C;
|
|
1448
|
+
(l = n.socketManager) == null || l.disconnect(), await ((p = n.streamingManager) == null ? void 0 : p.disconnect()), delete n.streamingManager, delete n.socketManager, (C = (v = t.callbacks).onConnectionStateChange) == null || C.call(v, b.Disconnected);
|
|
1408
1449
|
}
|
|
1409
1450
|
async function O(l) {
|
|
1410
|
-
var
|
|
1411
|
-
l !== n.chatMode && (
|
|
1451
|
+
var p, v;
|
|
1452
|
+
l !== n.chatMode && (s.track("agent-mode-change", { mode: l }), n.chatMode = l, n.chatMode !== A.Functional && await D(), (v = (p = t.callbacks).onModeChange) == null || v.call(p, l));
|
|
1412
1453
|
}
|
|
1413
1454
|
return {
|
|
1414
|
-
agent:
|
|
1455
|
+
agent: m,
|
|
1415
1456
|
getStreamType: () => {
|
|
1416
1457
|
var l;
|
|
1417
1458
|
return (l = n.streamingManager) == null ? void 0 : l.streamType;
|
|
@@ -1420,12 +1461,12 @@ async function fr(e, t) {
|
|
|
1420
1461
|
var l;
|
|
1421
1462
|
return ((l = n.streamingManager) == null ? void 0 : l.interruptAvailable) ?? !1;
|
|
1422
1463
|
},
|
|
1423
|
-
starterMessages: ((
|
|
1424
|
-
getSTTToken: () =>
|
|
1464
|
+
starterMessages: ((ee = m.knowledge) == null ? void 0 : ee.starter_message) || [],
|
|
1465
|
+
getSTTToken: () => f.getSTTToken(m.id),
|
|
1425
1466
|
changeMode: O,
|
|
1426
|
-
enrichAnalytics:
|
|
1467
|
+
enrichAnalytics: s.enrich,
|
|
1427
1468
|
async connect() {
|
|
1428
|
-
await
|
|
1469
|
+
await Y(!0), s.track("agent-chat", {
|
|
1429
1470
|
event: "connect",
|
|
1430
1471
|
mode: n.chatMode
|
|
1431
1472
|
});
|
|
@@ -1434,256 +1475,262 @@ async function fr(e, t) {
|
|
|
1434
1475
|
const l = n.streamingManager;
|
|
1435
1476
|
if (w && (l != null && l.reconnect)) {
|
|
1436
1477
|
try {
|
|
1437
|
-
await l.reconnect(),
|
|
1478
|
+
await l.reconnect(), s.track("agent-chat", {
|
|
1438
1479
|
event: "reconnect",
|
|
1439
1480
|
mode: n.chatMode
|
|
1440
1481
|
});
|
|
1441
1482
|
} catch {
|
|
1442
|
-
await
|
|
1483
|
+
await D(), await Y(!1);
|
|
1443
1484
|
}
|
|
1444
1485
|
return;
|
|
1445
1486
|
}
|
|
1446
|
-
await
|
|
1487
|
+
await D(), await Y(!1), s.track("agent-chat", {
|
|
1447
1488
|
event: "reconnect",
|
|
1448
1489
|
mode: n.chatMode
|
|
1449
1490
|
});
|
|
1450
1491
|
},
|
|
1451
1492
|
async disconnect() {
|
|
1452
|
-
await
|
|
1493
|
+
await D(), s.track("agent-chat", {
|
|
1453
1494
|
event: "disconnect",
|
|
1454
1495
|
mode: n.chatMode
|
|
1455
1496
|
});
|
|
1456
1497
|
},
|
|
1457
1498
|
publishMicrophoneStream(l) {
|
|
1458
|
-
var
|
|
1459
|
-
return (
|
|
1499
|
+
var p;
|
|
1500
|
+
return (p = n.streamingManager) != null && p.publishMicrophoneStream ? n.streamingManager.publishMicrophoneStream(l) : Promise.reject(new Error("publishMicrophoneStream is not available for this streaming manager"));
|
|
1460
1501
|
},
|
|
1461
1502
|
unpublishMicrophoneStream() {
|
|
1462
1503
|
var l;
|
|
1463
1504
|
return (l = n.streamingManager) != null && l.unpublishMicrophoneStream ? n.streamingManager.unpublishMicrophoneStream() : Promise.resolve();
|
|
1464
1505
|
},
|
|
1465
1506
|
replaceMicrophoneTrack(l) {
|
|
1466
|
-
var
|
|
1467
|
-
return (
|
|
1507
|
+
var p;
|
|
1508
|
+
return (p = n.streamingManager) != null && p.replaceMicrophoneTrack ? n.streamingManager.replaceMicrophoneTrack(l) : Promise.reject(new Error("replaceMicrophoneTrack is not available for this streaming manager"));
|
|
1468
1509
|
},
|
|
1469
1510
|
publishCameraStream(l) {
|
|
1470
|
-
var
|
|
1471
|
-
return (
|
|
1511
|
+
var p;
|
|
1512
|
+
return (p = n.streamingManager) != null && p.publishCameraStream ? n.streamingManager.publishCameraStream(l) : Promise.reject(new Error("publishCameraStream is not available for this streaming manager"));
|
|
1472
1513
|
},
|
|
1473
1514
|
unpublishCameraStream() {
|
|
1474
1515
|
var l;
|
|
1475
1516
|
return (l = n.streamingManager) != null && l.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
|
|
1476
1517
|
},
|
|
1477
1518
|
async chat(l) {
|
|
1478
|
-
var k, R, P,
|
|
1479
|
-
const
|
|
1480
|
-
if (
|
|
1481
|
-
throw new
|
|
1519
|
+
var k, R, P, N, F;
|
|
1520
|
+
const p = () => {
|
|
1521
|
+
if (We(o))
|
|
1522
|
+
throw new $(`${o} is enabled, chat is disabled`);
|
|
1482
1523
|
if (l.length >= ke)
|
|
1483
|
-
throw new
|
|
1524
|
+
throw new $(`Message cannot be more than ${ke} characters`);
|
|
1484
1525
|
if (l.length === 0)
|
|
1485
|
-
throw new
|
|
1526
|
+
throw new $("Message cannot be empty");
|
|
1486
1527
|
if (n.chatMode === A.Maintenance)
|
|
1487
|
-
throw new
|
|
1528
|
+
throw new $("Chat is in maintenance mode");
|
|
1488
1529
|
if (![A.TextOnly, A.Playground].includes(n.chatMode)) {
|
|
1489
1530
|
if (!n.streamingManager)
|
|
1490
|
-
throw new
|
|
1531
|
+
throw new $("Streaming manager is not initialized");
|
|
1491
1532
|
if (!n.chat)
|
|
1492
|
-
throw new
|
|
1533
|
+
throw new $("Chat is not initialized");
|
|
1493
1534
|
}
|
|
1494
1535
|
}, v = async () => {
|
|
1495
|
-
var g,
|
|
1536
|
+
var g, h;
|
|
1496
1537
|
if (!n.chat) {
|
|
1497
|
-
const
|
|
1498
|
-
f,
|
|
1538
|
+
const I = await qe(
|
|
1499
1539
|
m,
|
|
1500
|
-
|
|
1540
|
+
f,
|
|
1541
|
+
s,
|
|
1501
1542
|
n.chatMode,
|
|
1502
1543
|
t.persistentChat
|
|
1503
1544
|
);
|
|
1504
|
-
if (!
|
|
1505
|
-
throw new
|
|
1506
|
-
n.chat =
|
|
1545
|
+
if (!I.chat)
|
|
1546
|
+
throw new Ze(n.chatMode, !!t.persistentChat);
|
|
1547
|
+
n.chat = I.chat, (h = (g = t.callbacks).onNewChat) == null || h.call(g, n.chat.id);
|
|
1507
1548
|
}
|
|
1508
1549
|
return n.chat.id;
|
|
1509
|
-
}, C = async (g,
|
|
1510
|
-
const
|
|
1511
|
-
return fe(w && !
|
|
1512
|
-
var
|
|
1513
|
-
return await ((U = (
|
|
1550
|
+
}, C = async (g, h) => {
|
|
1551
|
+
const I = n.chatMode === A.Playground;
|
|
1552
|
+
return fe(w && !I ? async () => {
|
|
1553
|
+
var _, U;
|
|
1554
|
+
return await ((U = (_ = n.streamingManager) == null ? void 0 : _.sendTextMessage) == null ? void 0 : U.call(_, l)), Promise.resolve({});
|
|
1514
1555
|
} : async () => {
|
|
1515
|
-
var
|
|
1516
|
-
return
|
|
1517
|
-
|
|
1518
|
-
|
|
1556
|
+
var _, U;
|
|
1557
|
+
return f.chat(
|
|
1558
|
+
m.id,
|
|
1559
|
+
h,
|
|
1519
1560
|
{
|
|
1520
1561
|
chatMode: n.chatMode,
|
|
1521
|
-
streamId: (
|
|
1562
|
+
streamId: (_ = n.streamingManager) == null ? void 0 : _.streamId,
|
|
1522
1563
|
sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
|
|
1523
|
-
messages: g.map(({ matches:
|
|
1564
|
+
messages: g.map(({ matches: Xe, ...ce }) => ce)
|
|
1524
1565
|
},
|
|
1525
1566
|
{
|
|
1526
|
-
...
|
|
1567
|
+
...Oe(n.chatMode),
|
|
1527
1568
|
skipErrorHandler: !0
|
|
1528
1569
|
}
|
|
1529
1570
|
);
|
|
1530
1571
|
}, {
|
|
1531
1572
|
limit: 2,
|
|
1532
|
-
shouldRetryFn: (
|
|
1533
|
-
var
|
|
1534
|
-
const U = (
|
|
1535
|
-
return !((ye =
|
|
1573
|
+
shouldRetryFn: (_) => {
|
|
1574
|
+
var ce, ye, Ce, Se;
|
|
1575
|
+
const U = (ce = _ == null ? void 0 : _.message) == null ? void 0 : ce.includes("missing or invalid session_id");
|
|
1576
|
+
return !((ye = _ == null ? void 0 : _.message) == null ? void 0 : ye.includes("Stream Error")) && !U ? ((Se = (Ce = t.callbacks).onError) == null || Se.call(Ce, _), !1) : !0;
|
|
1536
1577
|
},
|
|
1537
1578
|
onRetry: async () => {
|
|
1538
|
-
await
|
|
1579
|
+
await D(), await Y(!1);
|
|
1539
1580
|
}
|
|
1540
1581
|
});
|
|
1541
1582
|
};
|
|
1542
1583
|
try {
|
|
1543
|
-
j(),
|
|
1544
|
-
id:
|
|
1584
|
+
j(), p(), n.messages.push({
|
|
1585
|
+
id: Q(),
|
|
1545
1586
|
role: "user",
|
|
1546
1587
|
content: l,
|
|
1547
|
-
parts:
|
|
1548
|
-
created_at: new Date(
|
|
1588
|
+
parts: ne(l),
|
|
1589
|
+
created_at: new Date(q.update()).toISOString()
|
|
1549
1590
|
}), (R = (k = t.callbacks).onNewMessage) == null || R.call(k, [...n.messages], "user");
|
|
1550
|
-
const g = await v(),
|
|
1551
|
-
return
|
|
1552
|
-
id:
|
|
1591
|
+
const g = await v(), h = await C([...n.messages], g);
|
|
1592
|
+
return h.result && n.messages.push({
|
|
1593
|
+
id: Q(),
|
|
1553
1594
|
role: "assistant",
|
|
1554
|
-
content:
|
|
1555
|
-
parts:
|
|
1595
|
+
content: h.result,
|
|
1596
|
+
parts: ne(h.result),
|
|
1556
1597
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1557
|
-
context:
|
|
1558
|
-
matches:
|
|
1559
|
-
}),
|
|
1598
|
+
context: h.context,
|
|
1599
|
+
matches: h.matches
|
|
1600
|
+
}), s.track("agent-message-send", {
|
|
1560
1601
|
event: "success",
|
|
1561
1602
|
messages: n.messages.length + 1
|
|
1562
|
-
}),
|
|
1563
|
-
latency:
|
|
1603
|
+
}), h.result && ((N = (P = t.callbacks).onNewMessage) == null || N.call(P, [...n.messages], "answer"), s.track("agent-message-received", {
|
|
1604
|
+
latency: q.get(!0),
|
|
1564
1605
|
messages: n.messages.length
|
|
1565
|
-
})),
|
|
1606
|
+
})), h;
|
|
1566
1607
|
} catch (g) {
|
|
1567
|
-
throw ((F = n.messages[n.messages.length - 1]) == null ? void 0 : F.role) === "assistant" && n.messages.pop(),
|
|
1608
|
+
throw ((F = n.messages[n.messages.length - 1]) == null ? void 0 : F.role) === "assistant" && n.messages.pop(), s.track("agent-message-send", {
|
|
1568
1609
|
event: "error",
|
|
1569
1610
|
messages: n.messages.length,
|
|
1570
|
-
error:
|
|
1611
|
+
error: Ae(g)
|
|
1571
1612
|
}), g;
|
|
1572
1613
|
}
|
|
1573
1614
|
},
|
|
1574
|
-
rate(l,
|
|
1575
|
-
var R, P,
|
|
1615
|
+
rate(l, p, v) {
|
|
1616
|
+
var R, P, N, F;
|
|
1576
1617
|
const C = n.messages.find((g) => g.id === l);
|
|
1577
1618
|
if (n.chat) {
|
|
1578
1619
|
if (!C)
|
|
1579
|
-
throw new
|
|
1580
|
-
} else throw new
|
|
1620
|
+
throw new $("Message not found");
|
|
1621
|
+
} else throw new $("Chat is not initialized");
|
|
1581
1622
|
const k = ((R = C.matches) == null ? void 0 : R.map((g) => [g.document_id, g.id])) ?? [];
|
|
1582
|
-
return
|
|
1623
|
+
return s.track("agent-rate", {
|
|
1583
1624
|
event: v ? "update" : "create",
|
|
1584
|
-
thumb:
|
|
1585
|
-
knowledge_id: ((P =
|
|
1625
|
+
thumb: p === 1 ? "up" : "down",
|
|
1626
|
+
knowledge_id: ((P = m.knowledge) == null ? void 0 : P.id) ?? "",
|
|
1586
1627
|
matches: k,
|
|
1587
|
-
score:
|
|
1588
|
-
}), v ?
|
|
1589
|
-
knowledge_id: ((
|
|
1628
|
+
score: p
|
|
1629
|
+
}), v ? f.updateRating(m.id, n.chat.id, v, {
|
|
1630
|
+
knowledge_id: ((N = m.knowledge) == null ? void 0 : N.id) ?? "",
|
|
1590
1631
|
message_id: l,
|
|
1591
1632
|
matches: k,
|
|
1592
|
-
score:
|
|
1593
|
-
}) :
|
|
1594
|
-
knowledge_id: ((F =
|
|
1633
|
+
score: p
|
|
1634
|
+
}) : f.createRating(m.id, n.chat.id, {
|
|
1635
|
+
knowledge_id: ((F = m.knowledge) == null ? void 0 : F.id) ?? "",
|
|
1595
1636
|
message_id: l,
|
|
1596
1637
|
matches: k,
|
|
1597
|
-
score:
|
|
1638
|
+
score: p
|
|
1598
1639
|
});
|
|
1599
1640
|
},
|
|
1600
1641
|
deleteRate(l) {
|
|
1601
1642
|
if (!n.chat)
|
|
1602
|
-
throw new
|
|
1603
|
-
return
|
|
1643
|
+
throw new $("Chat is not initialized");
|
|
1644
|
+
return s.track("agent-rate-delete", { type: "text" }), f.deleteRating(m.id, n.chat.id, l);
|
|
1604
1645
|
},
|
|
1605
1646
|
async speak(l) {
|
|
1606
1647
|
var k, R, P;
|
|
1607
|
-
function
|
|
1648
|
+
function p() {
|
|
1608
1649
|
if (typeof l == "string") {
|
|
1609
|
-
if (!
|
|
1610
|
-
throw new
|
|
1650
|
+
if (!m.presenter.voice)
|
|
1651
|
+
throw new $("Presenter voice is not initialized");
|
|
1611
1652
|
return {
|
|
1612
1653
|
type: "text",
|
|
1613
|
-
provider:
|
|
1654
|
+
provider: m.presenter.voice,
|
|
1614
1655
|
input: l,
|
|
1615
1656
|
ssml: !1
|
|
1616
1657
|
};
|
|
1617
1658
|
}
|
|
1618
1659
|
if (l.type === "text" && !l.provider) {
|
|
1619
|
-
if (!
|
|
1620
|
-
throw new
|
|
1660
|
+
if (!m.presenter.voice)
|
|
1661
|
+
throw new $("Presenter voice is not initialized");
|
|
1621
1662
|
return {
|
|
1622
1663
|
type: "text",
|
|
1623
|
-
provider:
|
|
1664
|
+
provider: m.presenter.voice,
|
|
1624
1665
|
input: l.input,
|
|
1625
1666
|
ssml: l.ssml
|
|
1626
1667
|
};
|
|
1627
1668
|
}
|
|
1628
1669
|
return l;
|
|
1629
1670
|
}
|
|
1630
|
-
const v =
|
|
1631
|
-
if (
|
|
1632
|
-
id:
|
|
1671
|
+
const v = p();
|
|
1672
|
+
if (s.track("agent-speak", v), q.update(), n.messages && v.type === "text" && (n.messages.push({
|
|
1673
|
+
id: Q(),
|
|
1633
1674
|
role: "assistant",
|
|
1634
1675
|
content: v.input,
|
|
1635
|
-
parts:
|
|
1676
|
+
parts: ne(v.input),
|
|
1636
1677
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1637
|
-
}), (R = (k = t.callbacks).onNewMessage) == null || R.call(k, [...n.messages], "answer")),
|
|
1678
|
+
}), (R = (k = t.callbacks).onNewMessage) == null || R.call(k, [...n.messages], "answer")), Ct(n.chatMode))
|
|
1638
1679
|
return {
|
|
1639
1680
|
duration: 0,
|
|
1640
1681
|
video_id: "",
|
|
1641
1682
|
status: "success"
|
|
1642
1683
|
};
|
|
1643
1684
|
if (!n.streamingManager)
|
|
1644
|
-
throw new
|
|
1685
|
+
throw new $("Please connect to the agent first");
|
|
1645
1686
|
return n.streamingManager.speak({
|
|
1646
1687
|
script: v,
|
|
1647
|
-
metadata: { chat_id: (P = n.chat) == null ? void 0 : P.id, agent_id:
|
|
1688
|
+
metadata: { chat_id: (P = n.chat) == null ? void 0 : P.id, agent_id: m.id }
|
|
1648
1689
|
});
|
|
1649
1690
|
},
|
|
1650
|
-
interrupt:
|
|
1651
|
-
registerClientTool:
|
|
1652
|
-
unregisterClientTool:
|
|
1691
|
+
interrupt: T,
|
|
1692
|
+
registerClientTool: H,
|
|
1693
|
+
unregisterClientTool: V
|
|
1653
1694
|
};
|
|
1654
1695
|
}
|
|
1655
1696
|
export {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1697
|
+
ae as A,
|
|
1698
|
+
G as B,
|
|
1699
|
+
z as C,
|
|
1700
|
+
lt as D,
|
|
1701
|
+
ze as H,
|
|
1702
|
+
dt as K,
|
|
1703
|
+
rt as N,
|
|
1704
|
+
it as P,
|
|
1705
|
+
ot as R,
|
|
1662
1706
|
x as S,
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1707
|
+
pe as T,
|
|
1708
|
+
at as U,
|
|
1709
|
+
$ as V,
|
|
1710
|
+
nt as W,
|
|
1711
|
+
Jt as a,
|
|
1668
1712
|
W as b,
|
|
1669
|
-
|
|
1713
|
+
He as c,
|
|
1670
1714
|
le as d,
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1715
|
+
Ne as e,
|
|
1716
|
+
b as f,
|
|
1717
|
+
re as g,
|
|
1718
|
+
Xt as h,
|
|
1719
|
+
wr as i,
|
|
1720
|
+
S as j,
|
|
1721
|
+
st as k,
|
|
1722
|
+
q as l,
|
|
1723
|
+
Ze as m,
|
|
1724
|
+
pr as n,
|
|
1725
|
+
A as o,
|
|
1726
|
+
et as p,
|
|
1727
|
+
ut as q,
|
|
1728
|
+
ct as r,
|
|
1729
|
+
Fe as s,
|
|
1730
|
+
Ae as t,
|
|
1731
|
+
mt as u,
|
|
1732
|
+
vr as v,
|
|
1733
|
+
gr as w,
|
|
1734
|
+
hr as x,
|
|
1735
|
+
Rt as y
|
|
1689
1736
|
};
|