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