@d-id/client-sdk 1.1.67 → 1.1.68-staging.316
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-DxHW-jum.js → index-DmShldpU.js} +298 -279
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-zAbqmsie.js → livekit-manager-Zdv-HZDQ.js} +1 -1
- package/dist/src/api/apiClient.test.d.ts +1 -0
- package/dist/src/services/socket-manager/message-queue.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var Z = (e, t, r) =>
|
|
1
|
+
var Je = Object.defineProperty;
|
|
2
|
+
var Oe = (e, t, r) => t in e ? Je(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var Z = (e, t, r) => Oe(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
class ce extends Error {
|
|
5
5
|
constructor({ kind: r, description: a, error: c }) {
|
|
6
6
|
super(JSON.stringify({ kind: r, description: a }));
|
|
@@ -10,7 +10,7 @@ class ce extends Error {
|
|
|
10
10
|
this.kind = r, this.description = a, this.error = c;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class He extends ce {
|
|
14
14
|
constructor(t, r) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,7 +18,7 @@ class Oe extends ce {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class qe extends ce {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
@@ -30,12 +30,12 @@ class G extends ce {
|
|
|
30
30
|
this.key = a;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class Xe extends ce {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ye || {}), Ge = /* @__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))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Qe || {}), Ze = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ze || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), N = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(N || {}), et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(tt || {}), rt = /* @__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))(rt || {}), je = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(je || {});
|
|
39
39
|
const sr = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -48,12 +48,12 @@ const sr = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
52
|
-
const
|
|
53
|
-
},
|
|
51
|
+
var k = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(k || {}), te = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ne || {}), P = /* @__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))(P || {}), L = /* @__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))(L || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(pe || {}), nt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(nt || {}), at = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(at || {});
|
|
52
|
+
const it = 45 * 1e3, st = "X-Playground-Chat", de = "https://api.d-id.com", ot = "wss://notifications.d-id.com", ct = "79f81a83a67430be2bc0fd61042b8faa", or = (...e) => {
|
|
53
|
+
}, Be = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
|
|
54
54
|
const t = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
|
-
},
|
|
56
|
+
}, $e = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, dt = (e) => {
|
|
57
57
|
switch (e.type) {
|
|
58
58
|
case "expressive":
|
|
59
59
|
return "v4";
|
|
@@ -62,13 +62,13 @@ const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st =
|
|
|
62
62
|
case "talk":
|
|
63
63
|
return "v2";
|
|
64
64
|
}
|
|
65
|
-
},
|
|
66
|
-
function
|
|
65
|
+
}, lt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, he = (e) => e === je.Expressive, ut = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), ze = (e) => e && [x.DirectPlayback, x.Off].includes(e), Se = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, mt = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
|
|
66
|
+
function ft(e) {
|
|
67
67
|
const t = e.split("?")[0].split("#")[0].toLowerCase();
|
|
68
|
-
return
|
|
68
|
+
return mt.some((r) => t.endsWith(r));
|
|
69
69
|
}
|
|
70
70
|
const Re = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), De = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
71
|
-
function
|
|
71
|
+
function gt(e) {
|
|
72
72
|
if (e.length === 0)
|
|
73
73
|
return [];
|
|
74
74
|
const t = [];
|
|
@@ -83,7 +83,7 @@ function ft(e) {
|
|
|
83
83
|
if (!t.some((o) => r.index >= o.index && r.index < o.index + o.length)) {
|
|
84
84
|
const o = r[2], n = r[1];
|
|
85
85
|
let i;
|
|
86
|
-
|
|
86
|
+
ft(o) ? i = { type: "video", src: o, alt: n } : (i = { type: "image", src: o, alt: n }, o.toLowerCase().endsWith(".gif") && (i.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: i });
|
|
87
87
|
}
|
|
88
88
|
for (Re.lastIndex = 0; (r = Re.exec(e)) !== null; )
|
|
89
89
|
t.some((o) => r.index >= o.index && r.index < o.index + o.length) || t.push({
|
|
@@ -108,9 +108,9 @@ function ft(e) {
|
|
|
108
108
|
}
|
|
109
109
|
let Ie = "", le = [];
|
|
110
110
|
function re(e) {
|
|
111
|
-
return e === Ie || (Ie = e, le =
|
|
111
|
+
return e === Ie || (Ie = e, le = gt(e)), le;
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function pt(e, t) {
|
|
114
114
|
let r;
|
|
115
115
|
return {
|
|
116
116
|
promise: new Promise((c, s) => {
|
|
@@ -134,12 +134,12 @@ async function ue(e, t) {
|
|
|
134
134
|
try {
|
|
135
135
|
if (!r.timeout)
|
|
136
136
|
return await e();
|
|
137
|
-
const { promise: s, clear: o } =
|
|
137
|
+
const { promise: s, clear: o } = pt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
|
|
138
138
|
return await Promise.race([n, s]);
|
|
139
139
|
} catch (s) {
|
|
140
140
|
if (a = s, !r.shouldRetryFn(s) || c >= r.limit)
|
|
141
141
|
throw s;
|
|
142
|
-
await
|
|
142
|
+
await Be(r.delayMs), r.onRetry(s);
|
|
143
143
|
}
|
|
144
144
|
throw a;
|
|
145
145
|
}
|
|
@@ -154,7 +154,7 @@ function me(e) {
|
|
|
154
154
|
return t;
|
|
155
155
|
}
|
|
156
156
|
let ht = Q();
|
|
157
|
-
function
|
|
157
|
+
function Fe(e, t) {
|
|
158
158
|
if (e.type === "bearer")
|
|
159
159
|
return `Bearer ${e.token}`;
|
|
160
160
|
if (e.type === "basic")
|
|
@@ -163,24 +163,30 @@ function ze(e, t) {
|
|
|
163
163
|
return `Client-Key ${e.clientKey}.${me(t)}_${ht}`;
|
|
164
164
|
throw new Error(`Unknown auth type: ${e}`);
|
|
165
165
|
}
|
|
166
|
-
const
|
|
166
|
+
const wt = (e) => ue(e, {
|
|
167
167
|
limit: 3,
|
|
168
168
|
delayMs: 1e3,
|
|
169
169
|
timeout: 0,
|
|
170
170
|
shouldRetryFn: (t) => t.status === 429
|
|
171
171
|
});
|
|
172
|
-
function
|
|
172
|
+
function Ne(e, t = de, r, a) {
|
|
173
173
|
const c = async (s, o) => {
|
|
174
|
-
const { skipErrorHandler: n, ...i } = o || {}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
const { skipErrorHandler: n, ...i } = o || {};
|
|
175
|
+
let d;
|
|
176
|
+
try {
|
|
177
|
+
d = await wt(
|
|
178
|
+
() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
179
|
+
...i,
|
|
180
|
+
headers: {
|
|
181
|
+
...i.headers,
|
|
182
|
+
Authorization: Fe(e, a),
|
|
183
|
+
"Content-Type": "application/json"
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
} catch (m) {
|
|
188
|
+
throw !((m == null ? void 0 : m.name) === "AbortError") && r && !n && r(m, { url: s, options: i }), m;
|
|
189
|
+
}
|
|
184
190
|
if (!d.ok) {
|
|
185
191
|
let m = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
186
192
|
const l = new Error(m);
|
|
@@ -203,8 +209,8 @@ function Fe(e, t = de, r, a) {
|
|
|
203
209
|
}
|
|
204
210
|
};
|
|
205
211
|
}
|
|
206
|
-
function
|
|
207
|
-
const c =
|
|
212
|
+
function vt(e, t = de, r, a) {
|
|
213
|
+
const c = Ne(e, `${t}/agents`, r, a);
|
|
208
214
|
return {
|
|
209
215
|
create(s, o) {
|
|
210
216
|
return c.post("/", s, o);
|
|
@@ -241,7 +247,7 @@ function wt(e, t = de, r, a) {
|
|
|
241
247
|
}
|
|
242
248
|
};
|
|
243
249
|
}
|
|
244
|
-
function
|
|
250
|
+
function yt(e) {
|
|
245
251
|
var c, s, o, n;
|
|
246
252
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", r = () => {
|
|
247
253
|
const i = navigator.platform;
|
|
@@ -252,20 +258,20 @@ function vt(e) {
|
|
|
252
258
|
isMobile: `${t() == "Mobile"}`,
|
|
253
259
|
browser: navigator.userAgent,
|
|
254
260
|
origin: window.location.origin,
|
|
255
|
-
agentType:
|
|
261
|
+
agentType: $e(a),
|
|
256
262
|
agentVoice: {
|
|
257
263
|
voiceId: (s = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : s.voice_id,
|
|
258
264
|
provider: (n = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : n.type
|
|
259
265
|
}
|
|
260
266
|
};
|
|
261
267
|
}
|
|
262
|
-
function
|
|
268
|
+
function Ct(e) {
|
|
263
269
|
var r, a, c, s, o, n;
|
|
264
270
|
const t = (r = e.llm) == null ? void 0 : r.prompt_customization;
|
|
265
271
|
return {
|
|
266
|
-
agentType:
|
|
267
|
-
presenterType:
|
|
268
|
-
presenter:
|
|
272
|
+
agentType: $e(e.presenter),
|
|
273
|
+
presenterType: dt(e.presenter),
|
|
274
|
+
presenter: lt(e.presenter),
|
|
269
275
|
owner_id: e.owner_id ?? "",
|
|
270
276
|
promptVersion: (a = e.llm) == null ? void 0 : a.prompt_version,
|
|
271
277
|
behavior: {
|
|
@@ -284,8 +290,8 @@ function yt(e) {
|
|
|
284
290
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
285
291
|
};
|
|
286
292
|
}
|
|
287
|
-
const
|
|
288
|
-
function
|
|
293
|
+
const St = (e) => e.reduce((t, r) => t + r, 0), Me = (e) => St(e) / e.length;
|
|
294
|
+
function kt(e, t, r) {
|
|
289
295
|
var i, d, m;
|
|
290
296
|
const { event: a, ...c } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
|
|
291
297
|
return {
|
|
@@ -299,8 +305,8 @@ function St(e, t, r) {
|
|
|
299
305
|
function Ee(e) {
|
|
300
306
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
301
307
|
}
|
|
302
|
-
const
|
|
303
|
-
function
|
|
308
|
+
const Rt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
309
|
+
function Dt(e) {
|
|
304
310
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
|
|
305
311
|
return {
|
|
306
312
|
token: e.token || "testKey",
|
|
@@ -344,7 +350,7 @@ function Rt(e) {
|
|
|
344
350
|
])
|
|
345
351
|
})
|
|
346
352
|
};
|
|
347
|
-
return fetch(
|
|
353
|
+
return fetch(Rt, d).catch((m) => console.error("Analytics tracking error:", m)), Promise.resolve();
|
|
348
354
|
},
|
|
349
355
|
linkTrack(a, c, s, o) {
|
|
350
356
|
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
|
|
@@ -371,21 +377,21 @@ function we() {
|
|
|
371
377
|
};
|
|
372
378
|
}
|
|
373
379
|
const H = we(), fe = we(), Te = we();
|
|
374
|
-
function
|
|
375
|
-
return e === x.Playground ? { headers: { [
|
|
380
|
+
function Ve(e) {
|
|
381
|
+
return e === x.Playground ? { headers: { [st]: "true" } } : {};
|
|
376
382
|
}
|
|
377
|
-
async function
|
|
383
|
+
async function Ke(e, t, r, a, c = !1, s) {
|
|
378
384
|
try {
|
|
379
|
-
return !s &&
|
|
385
|
+
return !s && !ze(a) && (s = await t.newChat(e.id, { persist: c }, Ve(a)), r.track("agent-chat", {
|
|
380
386
|
event: "created",
|
|
381
387
|
chatId: s.id,
|
|
382
388
|
mode: a
|
|
383
389
|
})), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? a };
|
|
384
390
|
} catch (o) {
|
|
385
|
-
throw
|
|
391
|
+
throw It(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
386
392
|
}
|
|
387
393
|
}
|
|
388
|
-
const
|
|
394
|
+
const It = (e) => {
|
|
389
395
|
try {
|
|
390
396
|
const t = JSON.parse(e.message);
|
|
391
397
|
return t == null ? void 0 : t.kind;
|
|
@@ -393,41 +399,41 @@ const Dt = (e) => {
|
|
|
393
399
|
return "UnknownError";
|
|
394
400
|
}
|
|
395
401
|
};
|
|
396
|
-
function
|
|
402
|
+
function Mt(e) {
|
|
397
403
|
return e && e.length > 0 ? e : [];
|
|
398
404
|
}
|
|
399
|
-
function
|
|
405
|
+
function Et(e) {
|
|
400
406
|
return new Promise((t, r) => {
|
|
401
|
-
const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(
|
|
402
|
-
l.onmessage = n, l.onclose = d, l.onerror = (
|
|
403
|
-
console.error(
|
|
404
|
-
}, l.onopen = (
|
|
405
|
-
i == null || i(
|
|
407
|
+
const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(Fe(s, o))}`);
|
|
408
|
+
l.onmessage = n, l.onclose = d, l.onerror = (p) => {
|
|
409
|
+
console.error(p), m == null || m("Websocket failed to connect", p), r(p);
|
|
410
|
+
}, l.onopen = (p) => {
|
|
411
|
+
i == null || i(p), t(l);
|
|
406
412
|
};
|
|
407
413
|
});
|
|
408
414
|
}
|
|
409
|
-
async function
|
|
415
|
+
async function Tt(e) {
|
|
410
416
|
const { retries: t = 1 } = e;
|
|
411
417
|
let r = null;
|
|
412
418
|
for (let a = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; a++)
|
|
413
419
|
try {
|
|
414
|
-
r = await
|
|
420
|
+
r = await Et(e);
|
|
415
421
|
} catch (c) {
|
|
416
422
|
if (a === t)
|
|
417
423
|
throw c;
|
|
418
|
-
await
|
|
424
|
+
await Be(a * 500);
|
|
419
425
|
}
|
|
420
426
|
return r;
|
|
421
427
|
}
|
|
422
|
-
async function
|
|
423
|
-
const c = r != null && r.onMessage ? [r.onMessage] : [], s = await
|
|
428
|
+
async function _t(e, t, r, a) {
|
|
429
|
+
const c = r != null && r.onMessage ? [r.onMessage] : [], s = await Tt({
|
|
424
430
|
auth: e,
|
|
425
431
|
host: t,
|
|
426
432
|
externalId: a,
|
|
427
433
|
callbacks: {
|
|
428
434
|
onError: (o) => {
|
|
429
435
|
var n;
|
|
430
|
-
return (n = r.onError) == null ? void 0 : n.call(r, new
|
|
436
|
+
return (n = r.onError) == null ? void 0 : n.call(r, new Xe(o));
|
|
431
437
|
},
|
|
432
438
|
onMessage(o) {
|
|
433
439
|
const n = JSON.parse(o.data);
|
|
@@ -441,7 +447,7 @@ async function Tt(e, t, r, a) {
|
|
|
441
447
|
subscribeToEvents: (o) => c.push(o)
|
|
442
448
|
};
|
|
443
449
|
}
|
|
444
|
-
function
|
|
450
|
+
function _e(e) {
|
|
445
451
|
if (e.answer !== void 0)
|
|
446
452
|
return e.answer;
|
|
447
453
|
let t = 0, r = "";
|
|
@@ -452,9 +458,7 @@ function _t(e) {
|
|
|
452
458
|
function bt(e, t, r) {
|
|
453
459
|
if (!e.content)
|
|
454
460
|
return;
|
|
455
|
-
const a =
|
|
456
|
-
(a == null ? void 0 : a.role) === "assistant" && !a.interrupted && (a.interrupted = !0);
|
|
457
|
-
const c = {
|
|
461
|
+
const a = {
|
|
458
462
|
id: e.id || `user-${Date.now()}`,
|
|
459
463
|
role: e.role,
|
|
460
464
|
content: e.content,
|
|
@@ -462,73 +466,88 @@ function bt(e, t, r) {
|
|
|
462
466
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
463
467
|
transcribed: !0
|
|
464
468
|
};
|
|
465
|
-
t.messages.push(
|
|
469
|
+
t.messages.push(a), r == null || r([...t.messages], "user");
|
|
466
470
|
}
|
|
467
|
-
function At(e, t, r, a, c, s) {
|
|
468
|
-
if (e ===
|
|
471
|
+
function At(e, t, r, a, c, s, o) {
|
|
472
|
+
if (e === N.Transcribe && t.content) {
|
|
469
473
|
bt(t, a, c);
|
|
470
474
|
return;
|
|
471
475
|
}
|
|
472
|
-
if (!(e ===
|
|
476
|
+
if (!(e === N.Partial || e === N.Answer))
|
|
473
477
|
return;
|
|
474
|
-
const
|
|
475
|
-
let
|
|
476
|
-
if ((
|
|
477
|
-
|
|
478
|
-
else if (!
|
|
479
|
-
|
|
478
|
+
const n = a.messages[a.messages.length - 1], i = o === "answer";
|
|
479
|
+
let d;
|
|
480
|
+
if ((n == null ? void 0 : n.role) === "assistant" && !i)
|
|
481
|
+
d = n;
|
|
482
|
+
else if (!n || n.role === "user" || i)
|
|
483
|
+
i && s(), d = {
|
|
480
484
|
id: t.id || `assistant-${Date.now()}`,
|
|
481
485
|
role: t.role || "assistant",
|
|
482
486
|
content: t.content || "",
|
|
483
487
|
parts: [],
|
|
484
488
|
created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
485
|
-
}, a.messages.push(
|
|
489
|
+
}, a.messages.push(d);
|
|
486
490
|
else
|
|
487
491
|
return;
|
|
488
|
-
const { content:
|
|
489
|
-
e ===
|
|
490
|
-
|
|
491
|
-
|
|
492
|
+
const { content: m, sequence: l } = t;
|
|
493
|
+
if (e === N.Partial)
|
|
494
|
+
r[l] = m;
|
|
495
|
+
else {
|
|
496
|
+
const w = _e(r);
|
|
497
|
+
!!(m && m.length < w.length) && (d.interrupted = !0), r.answer = m;
|
|
498
|
+
}
|
|
499
|
+
const p = _e(r);
|
|
500
|
+
(d.content !== p || e === N.Answer) && (d.content = p, d.parts = re(p), c == null || c([...a.messages], e));
|
|
492
501
|
}
|
|
493
502
|
function xt(e, t, r, a, c) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
503
|
+
const s = {}, o = () => {
|
|
504
|
+
for (const d of Object.keys(s))
|
|
505
|
+
delete s[d];
|
|
506
|
+
};
|
|
507
|
+
let n = null;
|
|
497
508
|
const i = (d, m) => {
|
|
498
|
-
var l,
|
|
499
|
-
m === "user" && o(),
|
|
509
|
+
var l, p;
|
|
510
|
+
m === "user" && o(), (p = (l = r.callbacks).onNewMessage) == null || p.call(l, d, m);
|
|
500
511
|
};
|
|
501
512
|
return {
|
|
502
513
|
clearQueue: o,
|
|
503
514
|
onMessage: (d, m) => {
|
|
504
|
-
var l,
|
|
515
|
+
var l, p;
|
|
505
516
|
if ("content" in m) {
|
|
506
|
-
const
|
|
507
|
-
At(
|
|
517
|
+
const w = d === P.ChatAnswer ? N.Answer : d === P.ChatAudioTranscribed ? N.Transcribe : d;
|
|
518
|
+
At(
|
|
519
|
+
w,
|
|
520
|
+
m,
|
|
521
|
+
s,
|
|
522
|
+
t,
|
|
523
|
+
i,
|
|
524
|
+
o,
|
|
525
|
+
n
|
|
526
|
+
), w === N.Partial ? n = "partial" : w === N.Answer && (n = "answer", o()), w === N.Answer && e.track("agent-message-received", {
|
|
508
527
|
content: m.content,
|
|
509
528
|
messages: t.messages.length,
|
|
510
529
|
mode: t.chatMode
|
|
511
530
|
});
|
|
512
531
|
} else {
|
|
513
|
-
const
|
|
514
|
-
if (d = d, d ===
|
|
532
|
+
const w = P, C = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], B = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], M = kt(m, a, { mode: t.chatMode });
|
|
533
|
+
if (d = d, d === w.StreamVideoCreated && (e.linkTrack("agent-video", M, w.StreamVideoCreated, ["start"]), m.sentiment)) {
|
|
515
534
|
const D = t.messages[t.messages.length - 1];
|
|
516
535
|
if ((D == null ? void 0 : D.role) === "assistant") {
|
|
517
536
|
const $ = { ...D, sentiment: m.sentiment };
|
|
518
|
-
t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n);
|
|
537
|
+
t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n ?? "answer");
|
|
519
538
|
}
|
|
520
539
|
}
|
|
521
|
-
if (
|
|
540
|
+
if (C.includes(d)) {
|
|
522
541
|
const D = d.split("/")[1];
|
|
523
542
|
B.includes(d) ? e.track("agent-video", { ...M, event: D }) : e.linkTrack("agent-video", { ...M, event: D }, d, ["done"]);
|
|
524
543
|
}
|
|
525
|
-
B.includes(d) && ((
|
|
544
|
+
B.includes(d) && ((p = (l = r.callbacks).onError) == null || p.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === w.StreamDone && c();
|
|
526
545
|
}
|
|
527
546
|
}
|
|
528
547
|
};
|
|
529
548
|
}
|
|
530
549
|
function Lt(e, t, r, a) {
|
|
531
|
-
const c =
|
|
550
|
+
const c = Ne(e, `${t}/agents/${r}`, a);
|
|
532
551
|
return {
|
|
533
552
|
createStream(s, o) {
|
|
534
553
|
return c.post("/streams", s, { signal: o });
|
|
@@ -631,7 +650,7 @@ function $t(e) {
|
|
|
631
650
|
freezeDuration: s.totalFreezesDuration
|
|
632
651
|
};
|
|
633
652
|
}
|
|
634
|
-
function
|
|
653
|
+
function be(e, t, r) {
|
|
635
654
|
const a = e.map((i, d) => d === 0 ? r ? {
|
|
636
655
|
timestamp: i.timestamp,
|
|
637
656
|
duration: 0,
|
|
@@ -699,7 +718,7 @@ function _e(e, t, r) {
|
|
|
699
718
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
700
719
|
};
|
|
701
720
|
}
|
|
702
|
-
function
|
|
721
|
+
function Ue(e, t) {
|
|
703
722
|
for (const r of e.values())
|
|
704
723
|
if ((r == null ? void 0 : r.type) === "inbound-rtp" && r.kind === t)
|
|
705
724
|
return r;
|
|
@@ -716,18 +735,18 @@ function cr(e, t) {
|
|
|
716
735
|
c = setTimeout(i, ee);
|
|
717
736
|
return;
|
|
718
737
|
}
|
|
719
|
-
const m =
|
|
738
|
+
const m = Ue(d, "audio");
|
|
720
739
|
if (!m) {
|
|
721
740
|
c = setTimeout(i, ee);
|
|
722
741
|
return;
|
|
723
742
|
}
|
|
724
|
-
const l = m.totalAudioEnergy ?? 0,
|
|
743
|
+
const l = m.totalAudioEnergy ?? 0, p = m.totalSamplesReceived ?? 0;
|
|
725
744
|
if (!a) {
|
|
726
|
-
s = l, o =
|
|
745
|
+
s = l, o = p, a = !0, c = setTimeout(i, ee);
|
|
727
746
|
return;
|
|
728
747
|
}
|
|
729
|
-
const
|
|
730
|
-
if (s = l, o =
|
|
748
|
+
const w = l - s, C = p - o;
|
|
749
|
+
if (s = l, o = p, C > 0 && w > 0) {
|
|
731
750
|
r = !1, t(n);
|
|
732
751
|
return;
|
|
733
752
|
}
|
|
@@ -749,7 +768,7 @@ const oe = 100, zt = Math.max(Math.ceil(400 / oe), 1), Ft = 0.25, Nt = 0.28;
|
|
|
749
768
|
function Vt() {
|
|
750
769
|
let e = 0, t, r, a = 0;
|
|
751
770
|
return (c) => {
|
|
752
|
-
const s =
|
|
771
|
+
const s = Ue(c, "video");
|
|
753
772
|
if (!s)
|
|
754
773
|
return { isReceiving: !1, avgJitterDelayInInterval: a };
|
|
755
774
|
const o = s.jitterBufferDelay, n = s.jitterBufferEmittedCount;
|
|
@@ -763,18 +782,18 @@ function Vt() {
|
|
|
763
782
|
};
|
|
764
783
|
}
|
|
765
784
|
function Kt(e, t, r, a, c) {
|
|
766
|
-
let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown,
|
|
767
|
-
const
|
|
785
|
+
let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, p = 0, w = 0;
|
|
786
|
+
const C = Vt();
|
|
768
787
|
async function B() {
|
|
769
788
|
const M = await e();
|
|
770
789
|
if (!M)
|
|
771
790
|
return;
|
|
772
|
-
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } =
|
|
791
|
+
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = C(M), q = $t(M);
|
|
773
792
|
if (D)
|
|
774
|
-
i = 0,
|
|
793
|
+
i = 0, p = _ - w, l = $ < Ft ? te.Strong : $ > Nt && p > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, w += p, p = 0), d || (a == null || a(k.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
|
|
775
794
|
else if (d && (i++, i >= zt)) {
|
|
776
|
-
const J =
|
|
777
|
-
a == null || a(
|
|
795
|
+
const J = be(o, oe, n);
|
|
796
|
+
a == null || a(k.Stop, J), t() || r(), w = _, d = !1;
|
|
778
797
|
}
|
|
779
798
|
}
|
|
780
799
|
return {
|
|
@@ -784,11 +803,11 @@ function Kt(e, t, r, a, c) {
|
|
|
784
803
|
stop: () => {
|
|
785
804
|
s && (clearInterval(s), s = null);
|
|
786
805
|
},
|
|
787
|
-
getReport: () =>
|
|
806
|
+
getReport: () => be(o, oe, n)
|
|
788
807
|
};
|
|
789
808
|
}
|
|
790
809
|
const Ut = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
791
|
-
function
|
|
810
|
+
function Ae(e) {
|
|
792
811
|
switch (e) {
|
|
793
812
|
case "connected":
|
|
794
813
|
return L.Connected;
|
|
@@ -824,7 +843,7 @@ function Jt({
|
|
|
824
843
|
report: a,
|
|
825
844
|
log: c
|
|
826
845
|
}) {
|
|
827
|
-
e ===
|
|
846
|
+
e === k.Start && t === k.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(k.Start)) : e === k.Stop && t === k.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(k.Stop, a));
|
|
828
847
|
}
|
|
829
848
|
function Ot({
|
|
830
849
|
statsSignal: e,
|
|
@@ -834,9 +853,9 @@ function Ot({
|
|
|
834
853
|
report: c,
|
|
835
854
|
log: s
|
|
836
855
|
}) {
|
|
837
|
-
e ===
|
|
856
|
+
e === k.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(k.Start)) : e === k.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(k.Stop, c)), t === k.Start ? a == null || a(ne.Talking) : t === k.Stop && (a == null || a(ne.Idle));
|
|
838
857
|
}
|
|
839
|
-
function
|
|
858
|
+
function xe({
|
|
840
859
|
statsSignal: e,
|
|
841
860
|
dataChannelSignal: t,
|
|
842
861
|
onVideoStateChange: r,
|
|
@@ -857,8 +876,8 @@ function Ae({
|
|
|
857
876
|
async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de, analytics: o }, n) {
|
|
858
877
|
var E;
|
|
859
878
|
const i = Pt(r, "WebRTCStreamingManager"), d = Wt(i);
|
|
860
|
-
let m = !1, l = !1,
|
|
861
|
-
const { startConnection:
|
|
879
|
+
let m = !1, l = !1, p = k.Stop, w = k.Stop;
|
|
880
|
+
const { startConnection: C, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = Lt(
|
|
862
881
|
c,
|
|
863
882
|
s,
|
|
864
883
|
e,
|
|
@@ -867,17 +886,17 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
867
886
|
id: _,
|
|
868
887
|
offer: q,
|
|
869
888
|
ice_servers: J,
|
|
870
|
-
session_id:
|
|
889
|
+
session_id: V,
|
|
871
890
|
fluent: X,
|
|
872
891
|
interrupt_enabled: O
|
|
873
892
|
} = await D(t, n);
|
|
874
|
-
(E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id:
|
|
893
|
+
(E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: V, agent_id: e });
|
|
875
894
|
const I = new Ut({ iceServers: J }), Y = I.createDataChannel("JanusDataChannel");
|
|
876
|
-
if (!
|
|
895
|
+
if (!V)
|
|
877
896
|
throw new Error("Could not create session_id");
|
|
878
|
-
const
|
|
897
|
+
const K = X ? W.Fluent : W.Legacy;
|
|
879
898
|
o.enrich({
|
|
880
|
-
"stream-type":
|
|
899
|
+
"stream-type": K
|
|
881
900
|
});
|
|
882
901
|
const ae = t.stream_warmup && !X, ie = () => m, u = () => {
|
|
883
902
|
var f;
|
|
@@ -886,13 +905,13 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
886
905
|
() => I.getStats(),
|
|
887
906
|
ie,
|
|
888
907
|
u,
|
|
889
|
-
(f, h) =>
|
|
890
|
-
statsSignal:
|
|
891
|
-
dataChannelSignal:
|
|
908
|
+
(f, h) => xe({
|
|
909
|
+
statsSignal: w = f,
|
|
910
|
+
dataChannelSignal: K === W.Legacy ? p : void 0,
|
|
892
911
|
onVideoStateChange: a.onVideoStateChange,
|
|
893
912
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
894
913
|
report: h,
|
|
895
|
-
streamType:
|
|
914
|
+
streamType: K,
|
|
896
915
|
log: i
|
|
897
916
|
}),
|
|
898
917
|
(f) => {
|
|
@@ -911,31 +930,31 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
911
930
|
sdpMid: f.candidate.sdpMid,
|
|
912
931
|
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
913
932
|
},
|
|
914
|
-
|
|
933
|
+
V,
|
|
915
934
|
n
|
|
916
|
-
) : $(_, { candidate: null },
|
|
935
|
+
) : $(_, { candidate: null }, V, n);
|
|
917
936
|
} catch (b) {
|
|
918
937
|
(h = a.onError) == null || h.call(a, b, { streamId: _ });
|
|
919
938
|
}
|
|
920
939
|
}, Y.onopen = () => {
|
|
921
940
|
l = !0, (!ae || m) && u();
|
|
922
941
|
};
|
|
923
|
-
let
|
|
942
|
+
let v = null;
|
|
924
943
|
const y = (f) => {
|
|
925
944
|
var h;
|
|
926
|
-
|
|
945
|
+
v = f, (h = a.onVideoIdChange) == null || h.call(a, f);
|
|
927
946
|
};
|
|
928
|
-
function
|
|
947
|
+
function S(f, h) {
|
|
929
948
|
if (f === P.StreamStarted && typeof h == "object" && "metadata" in h) {
|
|
930
949
|
const b = h.metadata;
|
|
931
950
|
y(b.videoId);
|
|
932
951
|
}
|
|
933
|
-
f === P.StreamDone && y(null),
|
|
934
|
-
statsSignal:
|
|
935
|
-
dataChannelSignal:
|
|
952
|
+
f === P.StreamDone && y(null), p = f === P.StreamStarted ? k.Start : k.Stop, xe({
|
|
953
|
+
statsSignal: K === W.Legacy ? w : void 0,
|
|
954
|
+
dataChannelSignal: p,
|
|
936
955
|
onVideoStateChange: a.onVideoStateChange,
|
|
937
956
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
938
|
-
streamType:
|
|
957
|
+
streamType: K,
|
|
939
958
|
log: i
|
|
940
959
|
});
|
|
941
960
|
}
|
|
@@ -945,8 +964,8 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
945
964
|
b && o.enrich({ streamMetadata: b }), (T = a.onStreamReady) == null || T.call(a);
|
|
946
965
|
}
|
|
947
966
|
const j = {
|
|
948
|
-
[P.StreamStarted]:
|
|
949
|
-
[P.StreamDone]:
|
|
967
|
+
[P.StreamStarted]: S,
|
|
968
|
+
[P.StreamDone]: S,
|
|
950
969
|
[P.StreamReady]: R
|
|
951
970
|
};
|
|
952
971
|
Y.onmessage = (f) => {
|
|
@@ -956,14 +975,14 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
956
975
|
}, I.oniceconnectionstatechange = () => {
|
|
957
976
|
var h;
|
|
958
977
|
i("peerConnection.oniceconnectionstatechange => " + I.iceConnectionState);
|
|
959
|
-
const f =
|
|
978
|
+
const f = Ae(I.iceConnectionState);
|
|
960
979
|
f !== L.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, f));
|
|
961
980
|
}, I.ontrack = (f) => {
|
|
962
981
|
var h;
|
|
963
982
|
i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, f.streams[0]);
|
|
964
983
|
}, await I.setRemoteDescription(q), i("set remote description OK");
|
|
965
984
|
const z = await I.createAnswer();
|
|
966
|
-
i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await
|
|
985
|
+
i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await C(_, z, V, n), i("start connection OK");
|
|
967
986
|
function F(f) {
|
|
968
987
|
var h, b;
|
|
969
988
|
if (!m || Y.readyState !== "open") {
|
|
@@ -984,7 +1003,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
984
1003
|
* @param payload
|
|
985
1004
|
*/
|
|
986
1005
|
speak(f) {
|
|
987
|
-
return B(_,
|
|
1006
|
+
return B(_, V, f);
|
|
988
1007
|
},
|
|
989
1008
|
/**
|
|
990
1009
|
* Method to close RTC connection
|
|
@@ -992,7 +1011,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
992
1011
|
async disconnect() {
|
|
993
1012
|
var f;
|
|
994
1013
|
if (_) {
|
|
995
|
-
const h =
|
|
1014
|
+
const h = Ae(I.iceConnectionState);
|
|
996
1015
|
if (I) {
|
|
997
1016
|
if (h === L.New) {
|
|
998
1017
|
g.stop();
|
|
@@ -1001,7 +1020,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
1001
1020
|
I.close(), I.oniceconnectionstatechange = null, I.onnegotiationneeded = null, I.onicecandidate = null, I.ontrack = null;
|
|
1002
1021
|
}
|
|
1003
1022
|
try {
|
|
1004
|
-
h === L.Connected && await M(_,
|
|
1023
|
+
h === L.Connected && await M(_, V).catch((b) => {
|
|
1005
1024
|
});
|
|
1006
1025
|
} catch (b) {
|
|
1007
1026
|
i("Error on close stream connection", b);
|
|
@@ -1013,24 +1032,24 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
1013
1032
|
/**
|
|
1014
1033
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1015
1034
|
*/
|
|
1016
|
-
sessionId:
|
|
1035
|
+
sessionId: V,
|
|
1017
1036
|
/**
|
|
1018
1037
|
* Id of current RTC stream
|
|
1019
1038
|
*/
|
|
1020
1039
|
streamId: _,
|
|
1021
|
-
streamType:
|
|
1040
|
+
streamType: K,
|
|
1022
1041
|
interruptAvailable: O ?? !1,
|
|
1023
1042
|
isInterruptible: !0,
|
|
1024
1043
|
interrupt(f) {
|
|
1025
1044
|
if (!O)
|
|
1026
1045
|
throw new Error("Interrupt is not enabled for this stream");
|
|
1027
|
-
if (
|
|
1046
|
+
if (K !== W.Fluent)
|
|
1028
1047
|
throw new Error("Interrupt only available for Fluent streams");
|
|
1029
|
-
if (!
|
|
1048
|
+
if (!v)
|
|
1030
1049
|
throw new Error("No active video to interrupt");
|
|
1031
1050
|
const h = {
|
|
1032
1051
|
type: P.StreamInterrupt,
|
|
1033
|
-
videoId:
|
|
1052
|
+
videoId: v,
|
|
1034
1053
|
timestamp: Date.now()
|
|
1035
1054
|
};
|
|
1036
1055
|
F(JSON.stringify(h));
|
|
@@ -1048,8 +1067,8 @@ async function qt(e, t, r, a) {
|
|
|
1048
1067
|
case "v2": {
|
|
1049
1068
|
const { version: s, ...o } = t;
|
|
1050
1069
|
switch (o.transport.provider) {
|
|
1051
|
-
case
|
|
1052
|
-
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-
|
|
1070
|
+
case pe.Livekit:
|
|
1071
|
+
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-Zdv-HZDQ.js");
|
|
1053
1072
|
return n(c, o, r);
|
|
1054
1073
|
default:
|
|
1055
1074
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
@@ -1063,7 +1082,7 @@ const Xt = "cht";
|
|
|
1063
1082
|
function Yt() {
|
|
1064
1083
|
return {
|
|
1065
1084
|
transport: {
|
|
1066
|
-
provider:
|
|
1085
|
+
provider: pe.Livekit
|
|
1067
1086
|
}
|
|
1068
1087
|
};
|
|
1069
1088
|
}
|
|
@@ -1081,7 +1100,7 @@ function Gt(e) {
|
|
|
1081
1100
|
}, ...r && { end_user_data: r } };
|
|
1082
1101
|
}
|
|
1083
1102
|
function Qt(e, t) {
|
|
1084
|
-
return
|
|
1103
|
+
return he(e.presenter.type) ? { version: ge.V2, ...Yt() } : { version: ge.V1, ...Gt(t) };
|
|
1085
1104
|
}
|
|
1086
1105
|
function Zt(e, t, r) {
|
|
1087
1106
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
@@ -1090,7 +1109,7 @@ function er(e, t, r, a, c) {
|
|
|
1090
1109
|
c === W.Fluent ? tr(e, t, r, a, c) : rr(e, t, r, a, c);
|
|
1091
1110
|
}
|
|
1092
1111
|
function tr(e, t, r, a, c) {
|
|
1093
|
-
e ===
|
|
1112
|
+
e === k.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === k.Stop && a.track("stream-session", {
|
|
1094
1113
|
event: "stop",
|
|
1095
1114
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1096
1115
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -1098,10 +1117,10 @@ function tr(e, t, r, a, c) {
|
|
|
1098
1117
|
...r
|
|
1099
1118
|
});
|
|
1100
1119
|
}
|
|
1101
|
-
function
|
|
1102
|
-
e ===
|
|
1120
|
+
function Le(e, t, r, a, c) {
|
|
1121
|
+
e === k.Start ? r.linkTrack("agent-video", { event: "start", ...c, "stream-type": a }, "start", [
|
|
1103
1122
|
P.StreamVideoCreated
|
|
1104
|
-
]) : e ===
|
|
1123
|
+
]) : e === k.Stop && r.linkTrack(
|
|
1105
1124
|
"agent-video",
|
|
1106
1125
|
{
|
|
1107
1126
|
event: "stop",
|
|
@@ -1114,12 +1133,12 @@ function xe(e, t, r, a, c) {
|
|
|
1114
1133
|
);
|
|
1115
1134
|
}
|
|
1116
1135
|
function rr(e, t, r, a, c) {
|
|
1117
|
-
e ===
|
|
1136
|
+
e === k.Start ? a.linkTrack(
|
|
1118
1137
|
"agent-video",
|
|
1119
1138
|
{ event: "start", latency: H.get(!0), "stream-type": c },
|
|
1120
1139
|
"start",
|
|
1121
1140
|
[P.StreamVideoCreated]
|
|
1122
|
-
) : e ===
|
|
1141
|
+
) : e === k.Stop && a.linkTrack(
|
|
1123
1142
|
"agent-video",
|
|
1124
1143
|
{
|
|
1125
1144
|
event: "stop",
|
|
@@ -1149,7 +1168,7 @@ function nr(e, t, r) {
|
|
|
1149
1168
|
extra_keys: c.extra ? Object.keys(c.extra).length : 0
|
|
1150
1169
|
});
|
|
1151
1170
|
}
|
|
1152
|
-
function
|
|
1171
|
+
function Pe(e, t, r, a) {
|
|
1153
1172
|
return H.reset(), Te.update(), new Promise(async (c, s) => {
|
|
1154
1173
|
try {
|
|
1155
1174
|
let o, n = !1;
|
|
@@ -1167,32 +1186,32 @@ function Le(e, t, r, a) {
|
|
|
1167
1186
|
analytics: r,
|
|
1168
1187
|
callbacks: {
|
|
1169
1188
|
...t.callbacks,
|
|
1170
|
-
onConnectionStateChange: (l,
|
|
1171
|
-
var
|
|
1172
|
-
(
|
|
1189
|
+
onConnectionStateChange: (l, p) => {
|
|
1190
|
+
var w, C;
|
|
1191
|
+
(C = (w = t.callbacks).onConnectionStateChange) == null || C.call(w, l), Zt(l, p, r), l === L.Connected && (o ? c(o) : n = !0);
|
|
1173
1192
|
},
|
|
1174
|
-
onVideoStateChange: (l,
|
|
1175
|
-
var
|
|
1176
|
-
(
|
|
1193
|
+
onVideoStateChange: (l, p) => {
|
|
1194
|
+
var w, C;
|
|
1195
|
+
(C = (w = t.callbacks).onVideoStateChange) == null || C.call(w, l), er(
|
|
1177
1196
|
l,
|
|
1178
1197
|
e,
|
|
1179
|
-
|
|
1198
|
+
p,
|
|
1180
1199
|
r,
|
|
1181
1200
|
o.streamType
|
|
1182
1201
|
);
|
|
1183
1202
|
},
|
|
1184
1203
|
onAgentActivityStateChange: (l) => {
|
|
1185
|
-
var
|
|
1186
|
-
(
|
|
1187
|
-
|
|
1188
|
-
|
|
1204
|
+
var p, w;
|
|
1205
|
+
(w = (p = t.callbacks).onAgentActivityStateChange) == null || w.call(p, l), l === ne.Talking ? (fe.update(), d = (C) => {
|
|
1206
|
+
Le(
|
|
1207
|
+
k.Start,
|
|
1189
1208
|
e,
|
|
1190
1209
|
r,
|
|
1191
1210
|
o.streamType,
|
|
1192
|
-
|
|
1211
|
+
C
|
|
1193
1212
|
), d = null;
|
|
1194
|
-
}, m || d({ latency: H.get(!0) })) : (fe.reset(), d = null,
|
|
1195
|
-
|
|
1213
|
+
}, m || d({ latency: H.get(!0) })) : (fe.reset(), d = null, Le(
|
|
1214
|
+
k.Stop,
|
|
1196
1215
|
e,
|
|
1197
1216
|
r,
|
|
1198
1217
|
o.streamType
|
|
@@ -1205,9 +1224,9 @@ function Le(e, t, r, a) {
|
|
|
1205
1224
|
const l = Te.get(!0);
|
|
1206
1225
|
r.track("agent-chat", { event: "ready", latency: l });
|
|
1207
1226
|
},
|
|
1208
|
-
onToolEvent: (l,
|
|
1209
|
-
var
|
|
1210
|
-
(
|
|
1227
|
+
onToolEvent: (l, p) => {
|
|
1228
|
+
var w, C;
|
|
1229
|
+
(C = (w = t.callbacks).onToolEvent) == null || C.call(w, l, p), nr(l, p, r);
|
|
1211
1230
|
}
|
|
1212
1231
|
}
|
|
1213
1232
|
},
|
|
@@ -1219,10 +1238,10 @@ function Le(e, t, r, a) {
|
|
|
1219
1238
|
});
|
|
1220
1239
|
}
|
|
1221
1240
|
async function ar(e, t, r, a, c) {
|
|
1222
|
-
var m, l,
|
|
1241
|
+
var m, l, p, w;
|
|
1223
1242
|
const s = async () => {
|
|
1224
|
-
if (
|
|
1225
|
-
const
|
|
1243
|
+
if (he(e.presenter.type)) {
|
|
1244
|
+
const C = await Pe(e, t, a), B = `${Xt}_${C.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
|
|
1226
1245
|
return { chatResult: {
|
|
1227
1246
|
chatMode: x.Functional,
|
|
1228
1247
|
chat: {
|
|
@@ -1236,35 +1255,35 @@ async function ar(e, t, r, a, c) {
|
|
|
1236
1255
|
chat_mode: x.Functional,
|
|
1237
1256
|
messages: []
|
|
1238
1257
|
}
|
|
1239
|
-
}, streamingManager:
|
|
1258
|
+
}, streamingManager: C };
|
|
1240
1259
|
} else {
|
|
1241
|
-
const
|
|
1260
|
+
const C = new AbortController(), B = C.signal;
|
|
1242
1261
|
let M;
|
|
1243
1262
|
try {
|
|
1244
|
-
const D =
|
|
1263
|
+
const D = Ke(
|
|
1245
1264
|
e,
|
|
1246
1265
|
r,
|
|
1247
1266
|
a,
|
|
1248
1267
|
t.mode,
|
|
1249
1268
|
t.persistentChat,
|
|
1250
1269
|
c
|
|
1251
|
-
), $ =
|
|
1270
|
+
), $ = Pe(e, t, a, B).then((J) => (M = J, J)), [_, q] = await Promise.all([D, $]);
|
|
1252
1271
|
return { chatResult: _, streamingManager: q };
|
|
1253
1272
|
} catch (D) {
|
|
1254
|
-
throw
|
|
1273
|
+
throw C.abort(), M && await M.disconnect().catch(() => {
|
|
1255
1274
|
}), D;
|
|
1256
1275
|
}
|
|
1257
1276
|
}
|
|
1258
1277
|
}, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
|
|
1259
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((
|
|
1278
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((w = (p = t.callbacks).onError) == null || w.call(p, new qe(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
|
|
1260
1279
|
}
|
|
1261
1280
|
async function dr(e, t) {
|
|
1262
|
-
var Y,
|
|
1281
|
+
var Y, K, ae, ie;
|
|
1263
1282
|
let r = !0;
|
|
1264
|
-
const a = t.mixpanelKey ||
|
|
1283
|
+
const a = t.mixpanelKey || ct, c = t.wsURL || ot, s = t.baseURL || de, o = t.mode || x.Functional, n = {
|
|
1265
1284
|
messages: [],
|
|
1266
1285
|
chatMode: o
|
|
1267
|
-
}, i =
|
|
1286
|
+
}, i = Dt({
|
|
1268
1287
|
token: a,
|
|
1269
1288
|
agentId: e,
|
|
1270
1289
|
isEnabled: t.enableAnalitics,
|
|
@@ -1274,66 +1293,66 @@ async function dr(e, t) {
|
|
|
1274
1293
|
Ee(() => {
|
|
1275
1294
|
i.track("agent-sdk", { event: "init" }, d);
|
|
1276
1295
|
});
|
|
1277
|
-
const m =
|
|
1296
|
+
const m = vt(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
|
|
1278
1297
|
t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
|
|
1279
|
-
const
|
|
1280
|
-
i.enrich(
|
|
1281
|
-
const { onMessage:
|
|
1282
|
-
var u, g,
|
|
1283
|
-
(u = n.socketManager) == null || u.disconnect(), (
|
|
1298
|
+
const p = he(l.presenter.type);
|
|
1299
|
+
i.enrich(Ct(l));
|
|
1300
|
+
const { onMessage: w, clearQueue: C } = xt(i, n, t, l, () => {
|
|
1301
|
+
var u, g, v;
|
|
1302
|
+
(u = n.socketManager) == null || u.disconnect(), (v = (g = t.callbacks).onConnectionStateChange) == null || v.call(g, L.Disconnected);
|
|
1284
1303
|
});
|
|
1285
|
-
n.messages =
|
|
1304
|
+
n.messages = Mt(t.initialMessages), (ae = (K = t.callbacks).onNewMessage) == null || ae.call(K, [...n.messages], "answer");
|
|
1286
1305
|
const B = (u) => {
|
|
1287
1306
|
}, M = ({ type: u }) => {
|
|
1288
|
-
var
|
|
1289
|
-
if (!((
|
|
1307
|
+
var v, y, S, R;
|
|
1308
|
+
if (!((v = n.streamingManager) != null && v.interruptAvailable) || !((y = n.streamingManager) != null && y.isInterruptible)) return;
|
|
1290
1309
|
const g = n.messages[n.messages.length - 1];
|
|
1291
1310
|
i.track("agent-video-interrupt", {
|
|
1292
1311
|
type: u || "click",
|
|
1293
1312
|
video_duration_to_interrupt: fe.get(!0),
|
|
1294
1313
|
message_duration_to_interrupt: H.get(!0)
|
|
1295
|
-
}), g.interrupted = !0, (R = (
|
|
1314
|
+
}), g.interrupted = !0, (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "answer"), n.streamingManager.interrupt(u);
|
|
1296
1315
|
}, D = /* @__PURE__ */ new Map();
|
|
1297
1316
|
function $(u) {
|
|
1298
1317
|
return async (g) => {
|
|
1299
|
-
const
|
|
1300
|
-
if (!
|
|
1318
|
+
const v = D.get(u);
|
|
1319
|
+
if (!v)
|
|
1301
1320
|
throw new Error(`No handler registered for client tool: ${u}`);
|
|
1302
1321
|
try {
|
|
1303
1322
|
const y = JSON.parse(g.payload);
|
|
1304
|
-
return await
|
|
1323
|
+
return await v(y);
|
|
1305
1324
|
} catch (y) {
|
|
1306
1325
|
throw new Error(`Client tool "${u}" failed: ${y.message}`);
|
|
1307
1326
|
}
|
|
1308
1327
|
};
|
|
1309
1328
|
}
|
|
1310
1329
|
function _() {
|
|
1311
|
-
var u, g,
|
|
1312
|
-
for (const [
|
|
1313
|
-
(g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u,
|
|
1330
|
+
var u, g, v, y;
|
|
1331
|
+
for (const [S] of D)
|
|
1332
|
+
(g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, S), (y = (v = n.streamingManager) == null ? void 0 : v.registerRpcMethod) == null || y.call(v, S, $(S));
|
|
1314
1333
|
}
|
|
1315
1334
|
function q(u, g) {
|
|
1316
|
-
var y,
|
|
1317
|
-
const
|
|
1318
|
-
D.set(u, g),
|
|
1335
|
+
var y, S;
|
|
1336
|
+
const v = !D.has(u);
|
|
1337
|
+
D.set(u, g), v && ((S = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || S.call(y, u, $(u)));
|
|
1319
1338
|
}
|
|
1320
1339
|
function J(u) {
|
|
1321
|
-
var g,
|
|
1322
|
-
D.delete(u), (
|
|
1340
|
+
var g, v;
|
|
1341
|
+
D.delete(u), (v = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || v.call(g, u);
|
|
1323
1342
|
}
|
|
1324
|
-
const
|
|
1343
|
+
const V = Date.now();
|
|
1325
1344
|
Ee(() => {
|
|
1326
|
-
i.track("agent-sdk", { event: "loaded", ...
|
|
1345
|
+
i.track("agent-sdk", { event: "loaded", ...yt(l) }, V);
|
|
1327
1346
|
});
|
|
1328
1347
|
async function X(u) {
|
|
1329
1348
|
var j, z, F, E, f, h, b;
|
|
1330
1349
|
(z = (j = t.callbacks).onConnectionStateChange) == null || z.call(j, L.Connecting), H.reset(), u && !r && (delete n.chat, (E = (F = t.callbacks).onNewMessage) == null || E.call(F, [...n.messages], "answer"));
|
|
1331
|
-
const g = o === x.DirectPlayback ||
|
|
1350
|
+
const g = o === x.DirectPlayback || p ? Promise.resolve(void 0) : _t(
|
|
1332
1351
|
t.auth,
|
|
1333
1352
|
c,
|
|
1334
|
-
{ onMessage:
|
|
1353
|
+
{ onMessage: w, onError: t.callbacks.onError },
|
|
1335
1354
|
t.externalId
|
|
1336
|
-
),
|
|
1355
|
+
), v = ue(
|
|
1337
1356
|
() => ar(
|
|
1338
1357
|
l,
|
|
1339
1358
|
{
|
|
@@ -1342,7 +1361,7 @@ async function dr(e, t) {
|
|
|
1342
1361
|
callbacks: {
|
|
1343
1362
|
...t.callbacks,
|
|
1344
1363
|
onVideoIdChange: B,
|
|
1345
|
-
onMessage:
|
|
1364
|
+
onMessage: w
|
|
1346
1365
|
}
|
|
1347
1366
|
},
|
|
1348
1367
|
m,
|
|
@@ -1351,28 +1370,28 @@ async function dr(e, t) {
|
|
|
1351
1370
|
),
|
|
1352
1371
|
{
|
|
1353
1372
|
limit: 3,
|
|
1354
|
-
timeout:
|
|
1373
|
+
timeout: it,
|
|
1355
1374
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1356
1375
|
shouldRetryFn: (T) => (T == null ? void 0 : T.message) !== "Could not connect" && T.status !== 429 && (T == null ? void 0 : T.message) !== "InsufficientCreditsError",
|
|
1357
1376
|
delayMs: 1e3
|
|
1358
1377
|
}
|
|
1359
1378
|
).catch((T) => {
|
|
1360
|
-
var A,
|
|
1361
|
-
throw I(x.Maintenance), (
|
|
1362
|
-
}), [y, { streamingManager:
|
|
1363
|
-
R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager =
|
|
1379
|
+
var A, U;
|
|
1380
|
+
throw I(x.Maintenance), (U = (A = t.callbacks).onConnectionStateChange) == null || U.call(A, L.Fail), T;
|
|
1381
|
+
}), [y, { streamingManager: S, chat: R }] = await Promise.all([g, v]);
|
|
1382
|
+
R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager = S, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
|
|
1364
1383
|
chatId: R == null ? void 0 : R.id,
|
|
1365
|
-
streamId:
|
|
1384
|
+
streamId: S == null ? void 0 : S.streamId,
|
|
1366
1385
|
mode: n.chatMode
|
|
1367
1386
|
}), I((R == null ? void 0 : R.chat_mode) ?? o);
|
|
1368
1387
|
}
|
|
1369
1388
|
async function O() {
|
|
1370
|
-
var u, g,
|
|
1371
|
-
(u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (
|
|
1389
|
+
var u, g, v, y;
|
|
1390
|
+
(u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (v = t.callbacks).onConnectionStateChange) == null || y.call(v, L.Disconnected);
|
|
1372
1391
|
}
|
|
1373
1392
|
async function I(u) {
|
|
1374
|
-
var g,
|
|
1375
|
-
u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (
|
|
1393
|
+
var g, v;
|
|
1394
|
+
u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (v = (g = t.callbacks).onModeChange) == null || v.call(g, u));
|
|
1376
1395
|
}
|
|
1377
1396
|
return {
|
|
1378
1397
|
agent: l,
|
|
@@ -1396,7 +1415,7 @@ async function dr(e, t) {
|
|
|
1396
1415
|
},
|
|
1397
1416
|
async reconnect() {
|
|
1398
1417
|
const u = n.streamingManager;
|
|
1399
|
-
if (
|
|
1418
|
+
if (p && (u != null && u.reconnect)) {
|
|
1400
1419
|
try {
|
|
1401
1420
|
await u.reconnect(), i.track("agent-chat", {
|
|
1402
1421
|
event: "reconnect",
|
|
@@ -1439,9 +1458,9 @@ async function dr(e, t) {
|
|
|
1439
1458
|
return (u = n.streamingManager) != null && u.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
|
|
1440
1459
|
},
|
|
1441
1460
|
async chat(u) {
|
|
1442
|
-
var
|
|
1461
|
+
var S, R, j, z, F;
|
|
1443
1462
|
const g = () => {
|
|
1444
|
-
if (
|
|
1463
|
+
if (ze(o))
|
|
1445
1464
|
throw new G(`${o} is enabled, chat is disabled`);
|
|
1446
1465
|
if (u.length >= 800)
|
|
1447
1466
|
throw new G("Message cannot be more than 800 characters");
|
|
@@ -1455,10 +1474,10 @@ async function dr(e, t) {
|
|
|
1455
1474
|
if (!n.chat)
|
|
1456
1475
|
throw new G("Chat is not initialized");
|
|
1457
1476
|
}
|
|
1458
|
-
},
|
|
1477
|
+
}, v = async () => {
|
|
1459
1478
|
var E, f;
|
|
1460
1479
|
if (!n.chat) {
|
|
1461
|
-
const h = await
|
|
1480
|
+
const h = await Ke(
|
|
1462
1481
|
l,
|
|
1463
1482
|
m,
|
|
1464
1483
|
i,
|
|
@@ -1466,28 +1485,28 @@ async function dr(e, t) {
|
|
|
1466
1485
|
t.persistentChat
|
|
1467
1486
|
);
|
|
1468
1487
|
if (!h.chat)
|
|
1469
|
-
throw new
|
|
1488
|
+
throw new He(n.chatMode, !!t.persistentChat);
|
|
1470
1489
|
n.chat = h.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
|
|
1471
1490
|
}
|
|
1472
1491
|
return n.chat.id;
|
|
1473
1492
|
}, y = async (E, f) => {
|
|
1474
1493
|
const h = n.chatMode === x.Playground;
|
|
1475
|
-
return ue(
|
|
1476
|
-
var A,
|
|
1477
|
-
return await ((
|
|
1494
|
+
return ue(p && !h ? async () => {
|
|
1495
|
+
var A, U;
|
|
1496
|
+
return await ((U = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : U.call(A, u)), Promise.resolve({});
|
|
1478
1497
|
} : async () => {
|
|
1479
|
-
var A,
|
|
1498
|
+
var A, U;
|
|
1480
1499
|
return m.chat(
|
|
1481
1500
|
l.id,
|
|
1482
1501
|
f,
|
|
1483
1502
|
{
|
|
1484
1503
|
chatMode: n.chatMode,
|
|
1485
1504
|
streamId: (A = n.streamingManager) == null ? void 0 : A.streamId,
|
|
1486
|
-
sessionId: (
|
|
1487
|
-
messages: E.map(({ matches:
|
|
1505
|
+
sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
|
|
1506
|
+
messages: E.map(({ matches: We, ...se }) => se)
|
|
1488
1507
|
},
|
|
1489
1508
|
{
|
|
1490
|
-
...
|
|
1509
|
+
...Ve(n.chatMode),
|
|
1491
1510
|
skipErrorHandler: !0
|
|
1492
1511
|
}
|
|
1493
1512
|
);
|
|
@@ -1495,8 +1514,8 @@ async function dr(e, t) {
|
|
|
1495
1514
|
limit: 2,
|
|
1496
1515
|
shouldRetryFn: (A) => {
|
|
1497
1516
|
var se, ve, ye, Ce;
|
|
1498
|
-
const
|
|
1499
|
-
return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !
|
|
1517
|
+
const U = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
|
|
1518
|
+
return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !U ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
|
|
1500
1519
|
},
|
|
1501
1520
|
onRetry: async () => {
|
|
1502
1521
|
await O(), await X(!1);
|
|
@@ -1504,19 +1523,19 @@ async function dr(e, t) {
|
|
|
1504
1523
|
});
|
|
1505
1524
|
};
|
|
1506
1525
|
try {
|
|
1507
|
-
|
|
1526
|
+
C(), g(), n.messages.push({
|
|
1508
1527
|
id: Q(),
|
|
1509
1528
|
role: "user",
|
|
1510
1529
|
content: u,
|
|
1511
1530
|
parts: re(u),
|
|
1512
1531
|
created_at: new Date(H.update()).toISOString()
|
|
1513
|
-
}), (R = (
|
|
1514
|
-
const E = await
|
|
1515
|
-
return n.messages.push({
|
|
1532
|
+
}), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "user");
|
|
1533
|
+
const E = await v(), f = await y([...n.messages], E);
|
|
1534
|
+
return f.result && n.messages.push({
|
|
1516
1535
|
id: Q(),
|
|
1517
1536
|
role: "assistant",
|
|
1518
|
-
content: f.result
|
|
1519
|
-
parts: re(f.result
|
|
1537
|
+
content: f.result,
|
|
1538
|
+
parts: re(f.result),
|
|
1520
1539
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1521
1540
|
context: f.context,
|
|
1522
1541
|
matches: f.matches
|
|
@@ -1534,29 +1553,29 @@ async function dr(e, t) {
|
|
|
1534
1553
|
}), E;
|
|
1535
1554
|
}
|
|
1536
1555
|
},
|
|
1537
|
-
rate(u, g,
|
|
1556
|
+
rate(u, g, v) {
|
|
1538
1557
|
var R, j, z, F;
|
|
1539
1558
|
const y = n.messages.find((E) => E.id === u);
|
|
1540
1559
|
if (n.chat) {
|
|
1541
1560
|
if (!y)
|
|
1542
1561
|
throw new Error("Message not found");
|
|
1543
1562
|
} else throw new Error("Chat is not initialized");
|
|
1544
|
-
const
|
|
1563
|
+
const S = ((R = y.matches) == null ? void 0 : R.map((E) => [E.document_id, E.id])) ?? [];
|
|
1545
1564
|
return i.track("agent-rate", {
|
|
1546
|
-
event:
|
|
1565
|
+
event: v ? "update" : "create",
|
|
1547
1566
|
thumb: g === 1 ? "up" : "down",
|
|
1548
1567
|
knowledge_id: ((j = l.knowledge) == null ? void 0 : j.id) ?? "",
|
|
1549
|
-
matches:
|
|
1568
|
+
matches: S,
|
|
1550
1569
|
score: g
|
|
1551
|
-
}),
|
|
1570
|
+
}), v ? m.updateRating(l.id, n.chat.id, v, {
|
|
1552
1571
|
knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1553
1572
|
message_id: u,
|
|
1554
|
-
matches:
|
|
1573
|
+
matches: S,
|
|
1555
1574
|
score: g
|
|
1556
1575
|
}) : m.createRating(l.id, n.chat.id, {
|
|
1557
1576
|
knowledge_id: ((F = l.knowledge) == null ? void 0 : F.id) ?? "",
|
|
1558
1577
|
message_id: u,
|
|
1559
|
-
matches:
|
|
1578
|
+
matches: S,
|
|
1560
1579
|
score: g
|
|
1561
1580
|
});
|
|
1562
1581
|
},
|
|
@@ -1566,7 +1585,7 @@ async function dr(e, t) {
|
|
|
1566
1585
|
return i.track("agent-rate-delete", { type: "text" }), m.deleteRating(l.id, n.chat.id, u);
|
|
1567
1586
|
},
|
|
1568
1587
|
async speak(u) {
|
|
1569
|
-
var
|
|
1588
|
+
var S, R, j;
|
|
1570
1589
|
function g() {
|
|
1571
1590
|
if (typeof u == "string") {
|
|
1572
1591
|
if (!l.presenter.voice)
|
|
@@ -1590,14 +1609,14 @@ async function dr(e, t) {
|
|
|
1590
1609
|
}
|
|
1591
1610
|
return u;
|
|
1592
1611
|
}
|
|
1593
|
-
const
|
|
1594
|
-
if (i.track("agent-speak",
|
|
1612
|
+
const v = g();
|
|
1613
|
+
if (i.track("agent-speak", v), H.update(), n.messages && v.type === "text" && (n.messages.push({
|
|
1595
1614
|
id: Q(),
|
|
1596
1615
|
role: "assistant",
|
|
1597
|
-
content:
|
|
1598
|
-
parts: re(
|
|
1616
|
+
content: v.input,
|
|
1617
|
+
parts: re(v.input),
|
|
1599
1618
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1600
|
-
}), (R = (
|
|
1619
|
+
}), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "answer")), ut(n.chatMode))
|
|
1601
1620
|
return {
|
|
1602
1621
|
duration: 0,
|
|
1603
1622
|
video_id: "",
|
|
@@ -1606,7 +1625,7 @@ async function dr(e, t) {
|
|
|
1606
1625
|
if (!n.streamingManager)
|
|
1607
1626
|
throw new Error("Please connect to the agent first");
|
|
1608
1627
|
return n.streamingManager.speak({
|
|
1609
|
-
script:
|
|
1628
|
+
script: v,
|
|
1610
1629
|
metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: l.id }
|
|
1611
1630
|
});
|
|
1612
1631
|
},
|
|
@@ -1617,36 +1636,36 @@ async function dr(e, t) {
|
|
|
1617
1636
|
}
|
|
1618
1637
|
export {
|
|
1619
1638
|
ne as A,
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1639
|
+
N as C,
|
|
1640
|
+
rt as D,
|
|
1641
|
+
tt as K,
|
|
1642
|
+
Ge as P,
|
|
1643
|
+
Ze as R,
|
|
1625
1644
|
P as S,
|
|
1626
|
-
|
|
1627
|
-
|
|
1645
|
+
pe as T,
|
|
1646
|
+
Ye as U,
|
|
1628
1647
|
G as V,
|
|
1629
|
-
|
|
1648
|
+
Xe as W,
|
|
1630
1649
|
Pt as a,
|
|
1631
1650
|
W as b,
|
|
1632
|
-
|
|
1651
|
+
Ne as c,
|
|
1633
1652
|
de as d,
|
|
1634
1653
|
L as e,
|
|
1635
1654
|
te as f,
|
|
1636
1655
|
Kt as g,
|
|
1637
1656
|
cr as h,
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1657
|
+
k as i,
|
|
1658
|
+
He as j,
|
|
1659
|
+
qe as k,
|
|
1641
1660
|
H as l,
|
|
1642
1661
|
dr as m,
|
|
1643
1662
|
or as n,
|
|
1644
|
-
|
|
1645
|
-
|
|
1663
|
+
Qe as o,
|
|
1664
|
+
gt as p,
|
|
1646
1665
|
x as q,
|
|
1647
|
-
|
|
1648
|
-
|
|
1666
|
+
et as r,
|
|
1667
|
+
je as s,
|
|
1649
1668
|
sr as t,
|
|
1650
|
-
|
|
1651
|
-
|
|
1669
|
+
nt as u,
|
|
1670
|
+
at as v
|
|
1652
1671
|
};
|