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