@d-id/client-sdk 1.1.66 → 1.1.67-staging.312
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-Bxdy--2d.js → index-BPiQZpON.js} +161 -149
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-CW6M36Wj.js → livekit-manager-BtTtY9lx.js} +87 -86
- package/dist/src/api/apiClient.test.d.ts +1 -0
- package/dist/src/types/stream/stream.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var Z = (e, t, r) =>
|
|
1
|
+
var We = Object.defineProperty;
|
|
2
|
+
var Je = (e, t, r) => t in e ? We(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var Z = (e, t, r) => Je(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 }));
|
|
@@ -35,8 +35,8 @@ class qe extends ce {
|
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}),
|
|
39
|
-
const
|
|
38
|
+
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), U = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(U || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__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))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
|
|
39
|
+
const sr = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,8 +48,8 @@ const ar = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), 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 || {}),
|
|
52
|
-
const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st = "wss://notifications.d-id.com", ot = "79f81a83a67430be2bc0fd61042b8faa",
|
|
51
|
+
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), 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 || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), nt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(nt || {});
|
|
52
|
+
const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st = "wss://notifications.d-id.com", ot = "79f81a83a67430be2bc0fd61042b8faa", or = (...e) => {
|
|
53
53
|
}, je = (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);
|
|
@@ -62,8 +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
|
-
}, dt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, pe = (e) => e === Pe.Expressive, lt = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), $e = (e) => e && [x.DirectPlayback, x.Off].includes(e), Se = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g,
|
|
66
|
-
function
|
|
65
|
+
}, dt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, pe = (e) => e === Pe.Expressive, lt = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), $e = (e) => e && [x.DirectPlayback, x.Off].includes(e), Se = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, ut = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
|
|
66
|
+
function mt(e) {
|
|
67
|
+
const t = e.split("?")[0].split("#")[0].toLowerCase();
|
|
68
|
+
return ut.some((r) => t.endsWith(r));
|
|
69
|
+
}
|
|
70
|
+
const Re = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), De = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
71
|
+
function ft(e) {
|
|
67
72
|
if (e.length === 0)
|
|
68
73
|
return [];
|
|
69
74
|
const t = [];
|
|
@@ -76,8 +81,9 @@ function ut(e) {
|
|
|
76
81
|
});
|
|
77
82
|
for (ke.lastIndex = 0; (r = ke.exec(e)) !== null; )
|
|
78
83
|
if (!t.some((o) => r.index >= o.index && r.index < o.index + o.length)) {
|
|
79
|
-
const o = r[2], n =
|
|
80
|
-
|
|
84
|
+
const o = r[2], n = r[1];
|
|
85
|
+
let i;
|
|
86
|
+
mt(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 });
|
|
81
87
|
}
|
|
82
88
|
for (Re.lastIndex = 0; (r = Re.exec(e)) !== null; )
|
|
83
89
|
t.some((o) => r.index >= o.index && r.index < o.index + o.length) || t.push({
|
|
@@ -102,9 +108,9 @@ function ut(e) {
|
|
|
102
108
|
}
|
|
103
109
|
let Ie = "", le = [];
|
|
104
110
|
function re(e) {
|
|
105
|
-
return e === Ie || (Ie = e, le =
|
|
111
|
+
return e === Ie || (Ie = e, le = ft(e)), le;
|
|
106
112
|
}
|
|
107
|
-
function
|
|
113
|
+
function gt(e, t) {
|
|
108
114
|
let r;
|
|
109
115
|
return {
|
|
110
116
|
promise: new Promise((c, s) => {
|
|
@@ -128,7 +134,7 @@ async function ue(e, t) {
|
|
|
128
134
|
try {
|
|
129
135
|
if (!r.timeout)
|
|
130
136
|
return await e();
|
|
131
|
-
const { promise: s, clear: o } =
|
|
137
|
+
const { promise: s, clear: o } = gt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
|
|
132
138
|
return await Promise.race([n, s]);
|
|
133
139
|
} catch (s) {
|
|
134
140
|
if (a = s, !r.shouldRetryFn(s) || c >= r.limit)
|
|
@@ -147,17 +153,17 @@ function me(e) {
|
|
|
147
153
|
}
|
|
148
154
|
return t;
|
|
149
155
|
}
|
|
150
|
-
let
|
|
156
|
+
let ht = Q();
|
|
151
157
|
function ze(e, t) {
|
|
152
158
|
if (e.type === "bearer")
|
|
153
159
|
return `Bearer ${e.token}`;
|
|
154
160
|
if (e.type === "basic")
|
|
155
161
|
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
156
162
|
if (e.type === "key")
|
|
157
|
-
return `Client-Key ${e.clientKey}.${me(t)}_${
|
|
163
|
+
return `Client-Key ${e.clientKey}.${me(t)}_${ht}`;
|
|
158
164
|
throw new Error(`Unknown auth type: ${e}`);
|
|
159
165
|
}
|
|
160
|
-
const
|
|
166
|
+
const pt = (e) => ue(e, {
|
|
161
167
|
limit: 3,
|
|
162
168
|
delayMs: 1e3,
|
|
163
169
|
timeout: 0,
|
|
@@ -165,16 +171,22 @@ const gt = (e) => ue(e, {
|
|
|
165
171
|
});
|
|
166
172
|
function Fe(e, t = de, r, a) {
|
|
167
173
|
const c = async (s, o) => {
|
|
168
|
-
const { skipErrorHandler: n, ...i } = o || {}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
const { skipErrorHandler: n, ...i } = o || {};
|
|
175
|
+
let d;
|
|
176
|
+
try {
|
|
177
|
+
d = await pt(
|
|
178
|
+
() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
179
|
+
...i,
|
|
180
|
+
headers: {
|
|
181
|
+
...i.headers,
|
|
182
|
+
Authorization: ze(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
|
+
}
|
|
178
190
|
if (!d.ok) {
|
|
179
191
|
let m = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
180
192
|
const l = new Error(m);
|
|
@@ -197,7 +209,7 @@ function Fe(e, t = de, r, a) {
|
|
|
197
209
|
}
|
|
198
210
|
};
|
|
199
211
|
}
|
|
200
|
-
function
|
|
212
|
+
function wt(e, t = de, r, a) {
|
|
201
213
|
const c = Fe(e, `${t}/agents`, r, a);
|
|
202
214
|
return {
|
|
203
215
|
create(s, o) {
|
|
@@ -235,7 +247,7 @@ function ht(e, t = de, r, a) {
|
|
|
235
247
|
}
|
|
236
248
|
};
|
|
237
249
|
}
|
|
238
|
-
function
|
|
250
|
+
function vt(e) {
|
|
239
251
|
var c, s, o, n;
|
|
240
252
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", r = () => {
|
|
241
253
|
const i = navigator.platform;
|
|
@@ -253,7 +265,7 @@ function pt(e) {
|
|
|
253
265
|
}
|
|
254
266
|
};
|
|
255
267
|
}
|
|
256
|
-
function
|
|
268
|
+
function yt(e) {
|
|
257
269
|
var r, a, c, s, o, n;
|
|
258
270
|
const t = (r = e.llm) == null ? void 0 : r.prompt_customization;
|
|
259
271
|
return {
|
|
@@ -278,8 +290,8 @@ function wt(e) {
|
|
|
278
290
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
279
291
|
};
|
|
280
292
|
}
|
|
281
|
-
const
|
|
282
|
-
function
|
|
293
|
+
const Ct = (e) => e.reduce((t, r) => t + r, 0), Me = (e) => Ct(e) / e.length;
|
|
294
|
+
function St(e, t, r) {
|
|
283
295
|
var i, d, m;
|
|
284
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) || {};
|
|
285
297
|
return {
|
|
@@ -293,8 +305,8 @@ function yt(e, t, r) {
|
|
|
293
305
|
function Ee(e) {
|
|
294
306
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
295
307
|
}
|
|
296
|
-
const
|
|
297
|
-
function
|
|
308
|
+
const kt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
309
|
+
function Rt(e) {
|
|
298
310
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
|
|
299
311
|
return {
|
|
300
312
|
token: e.token || "testKey",
|
|
@@ -338,7 +350,7 @@ function St(e) {
|
|
|
338
350
|
])
|
|
339
351
|
})
|
|
340
352
|
};
|
|
341
|
-
return fetch(
|
|
353
|
+
return fetch(kt, d).catch((m) => console.error("Analytics tracking error:", m)), Promise.resolve();
|
|
342
354
|
},
|
|
343
355
|
linkTrack(a, c, s, o) {
|
|
344
356
|
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
|
|
@@ -368,7 +380,7 @@ const H = we(), fe = we(), Te = we();
|
|
|
368
380
|
function Ne(e) {
|
|
369
381
|
return e === x.Playground ? { headers: { [it]: "true" } } : {};
|
|
370
382
|
}
|
|
371
|
-
async function
|
|
383
|
+
async function Ve(e, t, r, a, c = !1, s) {
|
|
372
384
|
try {
|
|
373
385
|
return !s && !$e(a) && (s = await t.newChat(e.id, { persist: c }, Ne(a)), r.track("agent-chat", {
|
|
374
386
|
event: "created",
|
|
@@ -376,10 +388,10 @@ async function Ke(e, t, r, a, c = !1, s) {
|
|
|
376
388
|
mode: a
|
|
377
389
|
})), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? a };
|
|
378
390
|
} catch (o) {
|
|
379
|
-
throw
|
|
391
|
+
throw Dt(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
380
392
|
}
|
|
381
393
|
}
|
|
382
|
-
const
|
|
394
|
+
const Dt = (e) => {
|
|
383
395
|
try {
|
|
384
396
|
const t = JSON.parse(e.message);
|
|
385
397
|
return t == null ? void 0 : t.kind;
|
|
@@ -387,10 +399,10 @@ const kt = (e) => {
|
|
|
387
399
|
return "UnknownError";
|
|
388
400
|
}
|
|
389
401
|
};
|
|
390
|
-
function
|
|
402
|
+
function It(e) {
|
|
391
403
|
return e && e.length > 0 ? e : [];
|
|
392
404
|
}
|
|
393
|
-
function
|
|
405
|
+
function Mt(e) {
|
|
394
406
|
return new Promise((t, r) => {
|
|
395
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(ze(s, o))}`);
|
|
396
408
|
l.onmessage = n, l.onclose = d, l.onerror = (w) => {
|
|
@@ -400,12 +412,12 @@ function Dt(e) {
|
|
|
400
412
|
};
|
|
401
413
|
});
|
|
402
414
|
}
|
|
403
|
-
async function
|
|
415
|
+
async function Et(e) {
|
|
404
416
|
const { retries: t = 1 } = e;
|
|
405
417
|
let r = null;
|
|
406
418
|
for (let a = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; a++)
|
|
407
419
|
try {
|
|
408
|
-
r = await
|
|
420
|
+
r = await Mt(e);
|
|
409
421
|
} catch (c) {
|
|
410
422
|
if (a === t)
|
|
411
423
|
throw c;
|
|
@@ -413,8 +425,8 @@ async function It(e) {
|
|
|
413
425
|
}
|
|
414
426
|
return r;
|
|
415
427
|
}
|
|
416
|
-
async function
|
|
417
|
-
const c = r != null && r.onMessage ? [r.onMessage] : [], s = await
|
|
428
|
+
async function Tt(e, t, r, a) {
|
|
429
|
+
const c = r != null && r.onMessage ? [r.onMessage] : [], s = await Et({
|
|
418
430
|
auth: e,
|
|
419
431
|
host: t,
|
|
420
432
|
externalId: a,
|
|
@@ -435,7 +447,7 @@ async function Mt(e, t, r, a) {
|
|
|
435
447
|
subscribeToEvents: (o) => c.push(o)
|
|
436
448
|
};
|
|
437
449
|
}
|
|
438
|
-
function
|
|
450
|
+
function _t(e) {
|
|
439
451
|
if (e.answer !== void 0)
|
|
440
452
|
return e.answer;
|
|
441
453
|
let t = 0, r = "";
|
|
@@ -443,7 +455,7 @@ function Et(e) {
|
|
|
443
455
|
r += e[t++];
|
|
444
456
|
return r;
|
|
445
457
|
}
|
|
446
|
-
function
|
|
458
|
+
function bt(e, t, r) {
|
|
447
459
|
if (!e.content)
|
|
448
460
|
return;
|
|
449
461
|
const a = t.messages[t.messages.length - 1];
|
|
@@ -458,12 +470,12 @@ function Tt(e, t, r) {
|
|
|
458
470
|
};
|
|
459
471
|
t.messages.push(c), r == null || r([...t.messages], "user");
|
|
460
472
|
}
|
|
461
|
-
function
|
|
462
|
-
if (e ===
|
|
463
|
-
|
|
473
|
+
function At(e, t, r, a, c, s) {
|
|
474
|
+
if (e === U.Transcribe && t.content) {
|
|
475
|
+
bt(t, a, c);
|
|
464
476
|
return;
|
|
465
477
|
}
|
|
466
|
-
if (!(e ===
|
|
478
|
+
if (!(e === U.Partial || e === U.Answer))
|
|
467
479
|
return;
|
|
468
480
|
const o = a.messages[a.messages.length - 1], n = t.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== t.id;
|
|
469
481
|
let i;
|
|
@@ -480,11 +492,11 @@ function _t(e, t, r, a, c, s) {
|
|
|
480
492
|
else
|
|
481
493
|
return;
|
|
482
494
|
const { content: d, sequence: m } = t;
|
|
483
|
-
e ===
|
|
484
|
-
const l =
|
|
485
|
-
(i.content !== l || e ===
|
|
495
|
+
e === U.Partial ? r[m] = d : r.answer = d;
|
|
496
|
+
const l = _t(r);
|
|
497
|
+
(i.content !== l || e === U.Answer) && (i.content = l, i.parts = re(l), c == null || c([...a.messages], e));
|
|
486
498
|
}
|
|
487
|
-
function
|
|
499
|
+
function xt(e, t, r, a, c) {
|
|
488
500
|
let s = {};
|
|
489
501
|
const o = () => s = {};
|
|
490
502
|
let n = "answer";
|
|
@@ -497,14 +509,14 @@ function bt(e, t, r, a, c) {
|
|
|
497
509
|
onMessage: (d, m) => {
|
|
498
510
|
var l, w;
|
|
499
511
|
if ("content" in m) {
|
|
500
|
-
const v = d === P.ChatAnswer ?
|
|
501
|
-
|
|
512
|
+
const v = d === P.ChatAnswer ? U.Answer : d === P.ChatAudioTranscribed ? U.Transcribe : d;
|
|
513
|
+
At(v, m, s, t, i, o), v === U.Answer && e.track("agent-message-received", {
|
|
502
514
|
content: m.content,
|
|
503
515
|
messages: t.messages.length,
|
|
504
516
|
mode: t.chatMode
|
|
505
517
|
});
|
|
506
518
|
} else {
|
|
507
|
-
const v = P, k = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], M =
|
|
519
|
+
const v = P, k = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], M = St(m, a, { mode: t.chatMode });
|
|
508
520
|
if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", M, v.StreamVideoCreated, ["start"]), m.sentiment)) {
|
|
509
521
|
const D = t.messages[t.messages.length - 1];
|
|
510
522
|
if ((D == null ? void 0 : D.role) === "assistant") {
|
|
@@ -521,7 +533,7 @@ function bt(e, t, r, a, c) {
|
|
|
521
533
|
}
|
|
522
534
|
};
|
|
523
535
|
}
|
|
524
|
-
function
|
|
536
|
+
function Lt(e, t, r, a) {
|
|
525
537
|
const c = Fe(e, `${t}/agents/${r}`, a);
|
|
526
538
|
return {
|
|
527
539
|
createStream(s, o) {
|
|
@@ -558,8 +570,8 @@ function At(e, t, r, a) {
|
|
|
558
570
|
}
|
|
559
571
|
};
|
|
560
572
|
}
|
|
561
|
-
const
|
|
562
|
-
function
|
|
573
|
+
const Pt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
|
|
574
|
+
function jt(e, t, r) {
|
|
563
575
|
const a = (t.timestamp - e.timestamp) / 1e3;
|
|
564
576
|
return {
|
|
565
577
|
duration: a,
|
|
@@ -579,7 +591,7 @@ function Lt(e, t, r) {
|
|
|
579
591
|
lowFpsCount: r
|
|
580
592
|
};
|
|
581
593
|
}
|
|
582
|
-
function
|
|
594
|
+
function Bt(e) {
|
|
583
595
|
return e.filter(
|
|
584
596
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
585
597
|
).map((t) => {
|
|
@@ -590,7 +602,7 @@ function Pt(e) {
|
|
|
590
602
|
};
|
|
591
603
|
});
|
|
592
604
|
}
|
|
593
|
-
function
|
|
605
|
+
function $t(e) {
|
|
594
606
|
var o;
|
|
595
607
|
let t = "", r = 0, a = null;
|
|
596
608
|
const c = /* @__PURE__ */ new Map();
|
|
@@ -677,14 +689,14 @@ function _e(e, t, r) {
|
|
|
677
689
|
framesPerSecond: i.framesPerSecond,
|
|
678
690
|
freezeCount: i.freezeCount - e[d - 1].freezeCount,
|
|
679
691
|
freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
|
|
680
|
-
}), c =
|
|
692
|
+
}), c = Bt(a), s = c.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), o = a.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), n = a.filter((i) => !!i.rtt).map((i) => i.rtt);
|
|
681
693
|
return {
|
|
682
694
|
webRTCStats: {
|
|
683
695
|
anomalies: c,
|
|
684
696
|
minRtt: Math.min(...n),
|
|
685
697
|
avgRtt: Me(n),
|
|
686
698
|
maxRtt: Math.max(...n),
|
|
687
|
-
aggregateReport:
|
|
699
|
+
aggregateReport: jt(e[0], e[e.length - 1], s),
|
|
688
700
|
minJitterDelayInInterval: Math.min(...o),
|
|
689
701
|
maxJitterDelayInInterval: Math.max(...o),
|
|
690
702
|
avgJitterDelayInInterval: Me(o)
|
|
@@ -693,14 +705,14 @@ function _e(e, t, r) {
|
|
|
693
705
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
694
706
|
};
|
|
695
707
|
}
|
|
696
|
-
function
|
|
708
|
+
function Ke(e, t) {
|
|
697
709
|
for (const r of e.values())
|
|
698
710
|
if ((r == null ? void 0 : r.type) === "inbound-rtp" && r.kind === t)
|
|
699
711
|
return r;
|
|
700
712
|
return null;
|
|
701
713
|
}
|
|
702
714
|
const ee = 10;
|
|
703
|
-
function
|
|
715
|
+
function cr(e, t) {
|
|
704
716
|
let r = !1, a = !1, c = null, s = 0, o = 0, n = {};
|
|
705
717
|
async function i() {
|
|
706
718
|
if (r) {
|
|
@@ -710,7 +722,7 @@ function sr(e, t) {
|
|
|
710
722
|
c = setTimeout(i, ee);
|
|
711
723
|
return;
|
|
712
724
|
}
|
|
713
|
-
const m =
|
|
725
|
+
const m = Ke(d, "audio");
|
|
714
726
|
if (!m) {
|
|
715
727
|
c = setTimeout(i, ee);
|
|
716
728
|
return;
|
|
@@ -739,11 +751,11 @@ function sr(e, t) {
|
|
|
739
751
|
}
|
|
740
752
|
};
|
|
741
753
|
}
|
|
742
|
-
const oe = 100,
|
|
743
|
-
function
|
|
754
|
+
const oe = 100, zt = Math.max(Math.ceil(400 / oe), 1), Ft = 0.25, Nt = 0.28;
|
|
755
|
+
function Vt() {
|
|
744
756
|
let e = 0, t, r, a = 0;
|
|
745
757
|
return (c) => {
|
|
746
|
-
const s =
|
|
758
|
+
const s = Ke(c, "video");
|
|
747
759
|
if (!s)
|
|
748
760
|
return { isReceiving: !1, avgJitterDelayInInterval: a };
|
|
749
761
|
const o = s.jitterBufferDelay, n = s.jitterBufferEmittedCount;
|
|
@@ -756,19 +768,19 @@ function Ft() {
|
|
|
756
768
|
return e = i, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: s.freezeCount };
|
|
757
769
|
};
|
|
758
770
|
}
|
|
759
|
-
function
|
|
771
|
+
function Kt(e, t, r, a, c) {
|
|
760
772
|
let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, w = 0, v = 0;
|
|
761
|
-
const k =
|
|
773
|
+
const k = Vt();
|
|
762
774
|
async function B() {
|
|
763
775
|
const M = await e();
|
|
764
776
|
if (!M)
|
|
765
777
|
return;
|
|
766
|
-
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q =
|
|
778
|
+
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q = $t(M);
|
|
767
779
|
if (D)
|
|
768
|
-
i = 0, w = _ - v, l = $ <
|
|
769
|
-
else if (d && (i++, i >=
|
|
770
|
-
const
|
|
771
|
-
a == null || a(S.Stop,
|
|
780
|
+
i = 0, w = _ - v, l = $ < Ft ? te.Strong : $ > Nt && w > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, v += w, w = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
|
|
781
|
+
else if (d && (i++, i >= zt)) {
|
|
782
|
+
const J = _e(o, oe, n);
|
|
783
|
+
a == null || a(S.Stop, J), t() || r(), v = _, d = !1;
|
|
772
784
|
}
|
|
773
785
|
}
|
|
774
786
|
return {
|
|
@@ -781,7 +793,7 @@ function Nt(e, t, r, a, c) {
|
|
|
781
793
|
getReport: () => _e(o, oe, n)
|
|
782
794
|
};
|
|
783
795
|
}
|
|
784
|
-
const
|
|
796
|
+
const Ut = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
785
797
|
function be(e) {
|
|
786
798
|
switch (e) {
|
|
787
799
|
case "connected":
|
|
@@ -802,7 +814,7 @@ function be(e) {
|
|
|
802
814
|
return L.New;
|
|
803
815
|
}
|
|
804
816
|
}
|
|
805
|
-
const
|
|
817
|
+
const Wt = (e) => (t) => {
|
|
806
818
|
const [r, a = ""] = t.split(/:(.+)/);
|
|
807
819
|
try {
|
|
808
820
|
const c = JSON.parse(a);
|
|
@@ -820,7 +832,7 @@ function Jt({
|
|
|
820
832
|
}) {
|
|
821
833
|
e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, a));
|
|
822
834
|
}
|
|
823
|
-
function
|
|
835
|
+
function Ot({
|
|
824
836
|
statsSignal: e,
|
|
825
837
|
dataChannelSignal: t,
|
|
826
838
|
onVideoStateChange: r,
|
|
@@ -839,7 +851,7 @@ function Ae({
|
|
|
839
851
|
report: s,
|
|
840
852
|
log: o
|
|
841
853
|
}) {
|
|
842
|
-
c ===
|
|
854
|
+
c === W.Legacy ? Jt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: o }) : c === W.Fluent && Ot({
|
|
843
855
|
statsSignal: e,
|
|
844
856
|
dataChannelSignal: t,
|
|
845
857
|
onVideoStateChange: r,
|
|
@@ -848,11 +860,11 @@ function Ae({
|
|
|
848
860
|
log: o
|
|
849
861
|
});
|
|
850
862
|
}
|
|
851
|
-
async function
|
|
863
|
+
async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de, analytics: o }, n) {
|
|
852
864
|
var E;
|
|
853
|
-
const i =
|
|
865
|
+
const i = Pt(r, "WebRTCStreamingManager"), d = Wt(i);
|
|
854
866
|
let m = !1, l = !1, w = S.Stop, v = S.Stop;
|
|
855
|
-
const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } =
|
|
867
|
+
const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = Lt(
|
|
856
868
|
c,
|
|
857
869
|
s,
|
|
858
870
|
e,
|
|
@@ -860,33 +872,33 @@ async function Wt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
860
872
|
), {
|
|
861
873
|
id: _,
|
|
862
874
|
offer: q,
|
|
863
|
-
ice_servers:
|
|
875
|
+
ice_servers: J,
|
|
864
876
|
session_id: N,
|
|
865
877
|
fluent: X,
|
|
866
878
|
interrupt_enabled: O
|
|
867
879
|
} = await D(t, n);
|
|
868
880
|
(E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: N, agent_id: e });
|
|
869
|
-
const I = new
|
|
881
|
+
const I = new Ut({ iceServers: J }), Y = I.createDataChannel("JanusDataChannel");
|
|
870
882
|
if (!N)
|
|
871
883
|
throw new Error("Could not create session_id");
|
|
872
|
-
const
|
|
884
|
+
const V = X ? W.Fluent : W.Legacy;
|
|
873
885
|
o.enrich({
|
|
874
|
-
"stream-type":
|
|
886
|
+
"stream-type": V
|
|
875
887
|
});
|
|
876
888
|
const ae = t.stream_warmup && !X, ie = () => m, u = () => {
|
|
877
889
|
var f;
|
|
878
890
|
m = !0, l && (i("CALLBACK: onConnectionStateChange(Connected)"), (f = a.onConnectionStateChange) == null || f.call(a, L.Connected));
|
|
879
|
-
}, g =
|
|
891
|
+
}, g = Kt(
|
|
880
892
|
() => I.getStats(),
|
|
881
893
|
ie,
|
|
882
894
|
u,
|
|
883
895
|
(f, h) => Ae({
|
|
884
896
|
statsSignal: v = f,
|
|
885
|
-
dataChannelSignal:
|
|
897
|
+
dataChannelSignal: V === W.Legacy ? w : void 0,
|
|
886
898
|
onVideoStateChange: a.onVideoStateChange,
|
|
887
899
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
888
900
|
report: h,
|
|
889
|
-
streamType:
|
|
901
|
+
streamType: V,
|
|
890
902
|
log: i
|
|
891
903
|
}),
|
|
892
904
|
(f) => {
|
|
@@ -925,11 +937,11 @@ async function Wt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
925
937
|
y(b.videoId);
|
|
926
938
|
}
|
|
927
939
|
f === P.StreamDone && y(null), w = f === P.StreamStarted ? S.Start : S.Stop, Ae({
|
|
928
|
-
statsSignal:
|
|
940
|
+
statsSignal: V === W.Legacy ? v : void 0,
|
|
929
941
|
dataChannelSignal: w,
|
|
930
942
|
onVideoStateChange: a.onVideoStateChange,
|
|
931
943
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
932
|
-
streamType:
|
|
944
|
+
streamType: V,
|
|
933
945
|
log: i
|
|
934
946
|
});
|
|
935
947
|
}
|
|
@@ -1012,13 +1024,13 @@ async function Wt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
1012
1024
|
* Id of current RTC stream
|
|
1013
1025
|
*/
|
|
1014
1026
|
streamId: _,
|
|
1015
|
-
streamType:
|
|
1027
|
+
streamType: V,
|
|
1016
1028
|
interruptAvailable: O ?? !1,
|
|
1017
1029
|
isInterruptible: !0,
|
|
1018
1030
|
interrupt(f) {
|
|
1019
1031
|
if (!O)
|
|
1020
1032
|
throw new Error("Interrupt is not enabled for this stream");
|
|
1021
|
-
if (
|
|
1033
|
+
if (V !== W.Fluent)
|
|
1022
1034
|
throw new Error("Interrupt only available for Fluent streams");
|
|
1023
1035
|
if (!p)
|
|
1024
1036
|
throw new Error("No active video to interrupt");
|
|
@@ -1032,18 +1044,18 @@ async function Wt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
1032
1044
|
};
|
|
1033
1045
|
}
|
|
1034
1046
|
var ge = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ge || {});
|
|
1035
|
-
async function
|
|
1047
|
+
async function qt(e, t, r, a) {
|
|
1036
1048
|
const c = e.id;
|
|
1037
1049
|
switch (t.version) {
|
|
1038
1050
|
case "v1": {
|
|
1039
1051
|
const { version: s, ...o } = t;
|
|
1040
|
-
return
|
|
1052
|
+
return Ht(c, o, r, a);
|
|
1041
1053
|
}
|
|
1042
1054
|
case "v2": {
|
|
1043
1055
|
const { version: s, ...o } = t;
|
|
1044
1056
|
switch (o.transport.provider) {
|
|
1045
1057
|
case he.Livekit:
|
|
1046
|
-
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-
|
|
1058
|
+
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-BtTtY9lx.js");
|
|
1047
1059
|
return n(c, o, r);
|
|
1048
1060
|
default:
|
|
1049
1061
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
@@ -1053,15 +1065,15 @@ async function Ot(e, t, r, a) {
|
|
|
1053
1065
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1054
1066
|
}
|
|
1055
1067
|
}
|
|
1056
|
-
const
|
|
1057
|
-
function
|
|
1068
|
+
const Xt = "cht";
|
|
1069
|
+
function Yt() {
|
|
1058
1070
|
return {
|
|
1059
1071
|
transport: {
|
|
1060
1072
|
provider: he.Livekit
|
|
1061
1073
|
}
|
|
1062
1074
|
};
|
|
1063
1075
|
}
|
|
1064
|
-
function
|
|
1076
|
+
function Gt(e) {
|
|
1065
1077
|
var c, s;
|
|
1066
1078
|
const { streamOptions: t } = e ?? {}, r = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
1067
1079
|
plan: (s = e.mixpanelAdditionalProperties) == null ? void 0 : s.plan
|
|
@@ -1074,16 +1086,16 @@ function Xt(e) {
|
|
|
1074
1086
|
fluent: t == null ? void 0 : t.fluent
|
|
1075
1087
|
}, ...r && { end_user_data: r } };
|
|
1076
1088
|
}
|
|
1077
|
-
function
|
|
1078
|
-
return pe(e.presenter.type) ? { version: ge.V2, ...
|
|
1089
|
+
function Qt(e, t) {
|
|
1090
|
+
return pe(e.presenter.type) ? { version: ge.V2, ...Yt() } : { version: ge.V1, ...Gt(t) };
|
|
1079
1091
|
}
|
|
1080
|
-
function
|
|
1092
|
+
function Zt(e, t, r) {
|
|
1081
1093
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1082
1094
|
}
|
|
1083
|
-
function
|
|
1084
|
-
c ===
|
|
1095
|
+
function er(e, t, r, a, c) {
|
|
1096
|
+
c === W.Fluent ? tr(e, t, r, a, c) : rr(e, t, r, a, c);
|
|
1085
1097
|
}
|
|
1086
|
-
function
|
|
1098
|
+
function tr(e, t, r, a, c) {
|
|
1087
1099
|
e === S.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && a.track("stream-session", {
|
|
1088
1100
|
event: "stop",
|
|
1089
1101
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
@@ -1107,7 +1119,7 @@ function xe(e, t, r, a, c) {
|
|
|
1107
1119
|
[P.StreamVideoDone]
|
|
1108
1120
|
);
|
|
1109
1121
|
}
|
|
1110
|
-
function
|
|
1122
|
+
function rr(e, t, r, a, c) {
|
|
1111
1123
|
e === S.Start ? a.linkTrack(
|
|
1112
1124
|
"agent-video",
|
|
1113
1125
|
{ event: "start", latency: H.get(!0), "stream-type": c },
|
|
@@ -1126,7 +1138,7 @@ function er(e, t, r, a, c) {
|
|
|
1126
1138
|
[P.StreamVideoDone]
|
|
1127
1139
|
);
|
|
1128
1140
|
}
|
|
1129
|
-
function
|
|
1141
|
+
function nr(e, t, r) {
|
|
1130
1142
|
const a = {
|
|
1131
1143
|
call_id: t.call_id,
|
|
1132
1144
|
name: t.name
|
|
@@ -1147,13 +1159,13 @@ function Le(e, t, r, a) {
|
|
|
1147
1159
|
return H.reset(), Te.update(), new Promise(async (c, s) => {
|
|
1148
1160
|
try {
|
|
1149
1161
|
let o, n = !1;
|
|
1150
|
-
const i =
|
|
1162
|
+
const i = Qt(e, t);
|
|
1151
1163
|
r.enrich({
|
|
1152
1164
|
"stream-version": i.version.toString()
|
|
1153
1165
|
});
|
|
1154
1166
|
let d = null;
|
|
1155
1167
|
const m = e.presenter.type === "expressive";
|
|
1156
|
-
o = await
|
|
1168
|
+
o = await qt(
|
|
1157
1169
|
e,
|
|
1158
1170
|
i,
|
|
1159
1171
|
{
|
|
@@ -1163,11 +1175,11 @@ function Le(e, t, r, a) {
|
|
|
1163
1175
|
...t.callbacks,
|
|
1164
1176
|
onConnectionStateChange: (l, w) => {
|
|
1165
1177
|
var v, k;
|
|
1166
|
-
(k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l),
|
|
1178
|
+
(k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Zt(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
|
|
1167
1179
|
},
|
|
1168
1180
|
onVideoStateChange: (l, w) => {
|
|
1169
1181
|
var v, k;
|
|
1170
|
-
(k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l),
|
|
1182
|
+
(k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l), er(
|
|
1171
1183
|
l,
|
|
1172
1184
|
e,
|
|
1173
1185
|
w,
|
|
@@ -1201,7 +1213,7 @@ function Le(e, t, r, a) {
|
|
|
1201
1213
|
},
|
|
1202
1214
|
onToolEvent: (l, w) => {
|
|
1203
1215
|
var v, k;
|
|
1204
|
-
(k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w),
|
|
1216
|
+
(k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w), nr(l, w, r);
|
|
1205
1217
|
}
|
|
1206
1218
|
}
|
|
1207
1219
|
},
|
|
@@ -1212,11 +1224,11 @@ function Le(e, t, r, a) {
|
|
|
1212
1224
|
}
|
|
1213
1225
|
});
|
|
1214
1226
|
}
|
|
1215
|
-
async function
|
|
1227
|
+
async function ar(e, t, r, a, c) {
|
|
1216
1228
|
var m, l, w, v;
|
|
1217
1229
|
const s = async () => {
|
|
1218
1230
|
if (pe(e.presenter.type)) {
|
|
1219
|
-
const k = await Le(e, t, a), B = `${
|
|
1231
|
+
const k = await Le(e, t, a), B = `${Xt}_${k.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
|
|
1220
1232
|
return { chatResult: {
|
|
1221
1233
|
chatMode: x.Functional,
|
|
1222
1234
|
chat: {
|
|
@@ -1235,14 +1247,14 @@ async function rr(e, t, r, a, c) {
|
|
|
1235
1247
|
const k = new AbortController(), B = k.signal;
|
|
1236
1248
|
let M;
|
|
1237
1249
|
try {
|
|
1238
|
-
const D =
|
|
1250
|
+
const D = Ve(
|
|
1239
1251
|
e,
|
|
1240
1252
|
r,
|
|
1241
1253
|
a,
|
|
1242
1254
|
t.mode,
|
|
1243
1255
|
t.persistentChat,
|
|
1244
1256
|
c
|
|
1245
|
-
), $ = Le(e, t, a, B).then((
|
|
1257
|
+
), $ = Le(e, t, a, B).then((J) => (M = J, J)), [_, q] = await Promise.all([D, $]);
|
|
1246
1258
|
return { chatResult: _, streamingManager: q };
|
|
1247
1259
|
} catch (D) {
|
|
1248
1260
|
throw k.abort(), M && await M.disconnect().catch(() => {
|
|
@@ -1252,13 +1264,13 @@ async function rr(e, t, r, a, c) {
|
|
|
1252
1264
|
}, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
|
|
1253
1265
|
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) ? ((v = (w = t.callbacks).onError) == null || v.call(w, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
|
|
1254
1266
|
}
|
|
1255
|
-
async function
|
|
1256
|
-
var Y,
|
|
1267
|
+
async function dr(e, t) {
|
|
1268
|
+
var Y, V, ae, ie;
|
|
1257
1269
|
let r = !0;
|
|
1258
1270
|
const a = t.mixpanelKey || ot, c = t.wsURL || st, s = t.baseURL || de, o = t.mode || x.Functional, n = {
|
|
1259
1271
|
messages: [],
|
|
1260
1272
|
chatMode: o
|
|
1261
|
-
}, i =
|
|
1273
|
+
}, i = Rt({
|
|
1262
1274
|
token: a,
|
|
1263
1275
|
agentId: e,
|
|
1264
1276
|
isEnabled: t.enableAnalitics,
|
|
@@ -1268,15 +1280,15 @@ async function or(e, t) {
|
|
|
1268
1280
|
Ee(() => {
|
|
1269
1281
|
i.track("agent-sdk", { event: "init" }, d);
|
|
1270
1282
|
});
|
|
1271
|
-
const m =
|
|
1283
|
+
const m = wt(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
|
|
1272
1284
|
t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
|
|
1273
1285
|
const w = pe(l.presenter.type);
|
|
1274
|
-
i.enrich(
|
|
1275
|
-
const { onMessage: v, clearQueue: k } =
|
|
1286
|
+
i.enrich(yt(l));
|
|
1287
|
+
const { onMessage: v, clearQueue: k } = xt(i, n, t, l, () => {
|
|
1276
1288
|
var u, g, p;
|
|
1277
1289
|
(u = n.socketManager) == null || u.disconnect(), (p = (g = t.callbacks).onConnectionStateChange) == null || p.call(g, L.Disconnected);
|
|
1278
1290
|
});
|
|
1279
|
-
n.messages =
|
|
1291
|
+
n.messages = It(t.initialMessages), (ae = (V = t.callbacks).onNewMessage) == null || ae.call(V, [...n.messages], "answer");
|
|
1280
1292
|
const B = (u) => {
|
|
1281
1293
|
}, M = ({ type: u }) => {
|
|
1282
1294
|
var p, y, C, R;
|
|
@@ -1311,24 +1323,24 @@ async function or(e, t) {
|
|
|
1311
1323
|
const p = !D.has(u);
|
|
1312
1324
|
D.set(u, g), p && ((C = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, u, $(u)));
|
|
1313
1325
|
}
|
|
1314
|
-
function
|
|
1326
|
+
function J(u) {
|
|
1315
1327
|
var g, p;
|
|
1316
1328
|
D.delete(u), (p = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || p.call(g, u);
|
|
1317
1329
|
}
|
|
1318
1330
|
const N = Date.now();
|
|
1319
1331
|
Ee(() => {
|
|
1320
|
-
i.track("agent-sdk", { event: "loaded", ...
|
|
1332
|
+
i.track("agent-sdk", { event: "loaded", ...vt(l) }, N);
|
|
1321
1333
|
});
|
|
1322
1334
|
async function X(u) {
|
|
1323
1335
|
var j, z, F, E, f, h, b;
|
|
1324
1336
|
(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"));
|
|
1325
|
-
const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) :
|
|
1337
|
+
const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) : Tt(
|
|
1326
1338
|
t.auth,
|
|
1327
1339
|
c,
|
|
1328
1340
|
{ onMessage: v, onError: t.callbacks.onError },
|
|
1329
1341
|
t.externalId
|
|
1330
1342
|
), p = ue(
|
|
1331
|
-
() =>
|
|
1343
|
+
() => ar(
|
|
1332
1344
|
l,
|
|
1333
1345
|
{
|
|
1334
1346
|
...t,
|
|
@@ -1351,8 +1363,8 @@ async function or(e, t) {
|
|
|
1351
1363
|
delayMs: 1e3
|
|
1352
1364
|
}
|
|
1353
1365
|
).catch((T) => {
|
|
1354
|
-
var A,
|
|
1355
|
-
throw I(x.Maintenance), (
|
|
1366
|
+
var A, K;
|
|
1367
|
+
throw I(x.Maintenance), (K = (A = t.callbacks).onConnectionStateChange) == null || K.call(A, L.Fail), T;
|
|
1356
1368
|
}), [y, { streamingManager: C, chat: R }] = await Promise.all([g, p]);
|
|
1357
1369
|
R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager = C, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
|
|
1358
1370
|
chatId: R == null ? void 0 : R.id,
|
|
@@ -1452,7 +1464,7 @@ async function or(e, t) {
|
|
|
1452
1464
|
}, p = async () => {
|
|
1453
1465
|
var E, f;
|
|
1454
1466
|
if (!n.chat) {
|
|
1455
|
-
const h = await
|
|
1467
|
+
const h = await Ve(
|
|
1456
1468
|
l,
|
|
1457
1469
|
m,
|
|
1458
1470
|
i,
|
|
@@ -1467,18 +1479,18 @@ async function or(e, t) {
|
|
|
1467
1479
|
}, y = async (E, f) => {
|
|
1468
1480
|
const h = n.chatMode === x.Playground;
|
|
1469
1481
|
return ue(w && !h ? async () => {
|
|
1470
|
-
var A,
|
|
1471
|
-
return await ((
|
|
1482
|
+
var A, K;
|
|
1483
|
+
return await ((K = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : K.call(A, u)), Promise.resolve({});
|
|
1472
1484
|
} : async () => {
|
|
1473
|
-
var A,
|
|
1485
|
+
var A, K;
|
|
1474
1486
|
return m.chat(
|
|
1475
1487
|
l.id,
|
|
1476
1488
|
f,
|
|
1477
1489
|
{
|
|
1478
1490
|
chatMode: n.chatMode,
|
|
1479
1491
|
streamId: (A = n.streamingManager) == null ? void 0 : A.streamId,
|
|
1480
|
-
sessionId: (
|
|
1481
|
-
messages: E.map(({ matches:
|
|
1492
|
+
sessionId: (K = n.streamingManager) == null ? void 0 : K.sessionId,
|
|
1493
|
+
messages: E.map(({ matches: Ue, ...se }) => se)
|
|
1482
1494
|
},
|
|
1483
1495
|
{
|
|
1484
1496
|
...Ne(n.chatMode),
|
|
@@ -1489,8 +1501,8 @@ async function or(e, t) {
|
|
|
1489
1501
|
limit: 2,
|
|
1490
1502
|
shouldRetryFn: (A) => {
|
|
1491
1503
|
var se, ve, ye, Ce;
|
|
1492
|
-
const
|
|
1493
|
-
return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !
|
|
1504
|
+
const K = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
|
|
1505
|
+
return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !K ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
|
|
1494
1506
|
},
|
|
1495
1507
|
onRetry: async () => {
|
|
1496
1508
|
await O(), await X(!1);
|
|
@@ -1606,12 +1618,12 @@ async function or(e, t) {
|
|
|
1606
1618
|
},
|
|
1607
1619
|
interrupt: M,
|
|
1608
1620
|
registerClientTool: q,
|
|
1609
|
-
unregisterClientTool:
|
|
1621
|
+
unregisterClientTool: J
|
|
1610
1622
|
};
|
|
1611
1623
|
}
|
|
1612
1624
|
export {
|
|
1613
1625
|
ne as A,
|
|
1614
|
-
|
|
1626
|
+
U as C,
|
|
1615
1627
|
tt as D,
|
|
1616
1628
|
et as K,
|
|
1617
1629
|
Ye as P,
|
|
@@ -1621,26 +1633,26 @@ export {
|
|
|
1621
1633
|
Xe as U,
|
|
1622
1634
|
G as V,
|
|
1623
1635
|
qe as W,
|
|
1624
|
-
|
|
1625
|
-
|
|
1636
|
+
Pt as a,
|
|
1637
|
+
W as b,
|
|
1626
1638
|
Fe as c,
|
|
1627
1639
|
de as d,
|
|
1628
1640
|
L as e,
|
|
1629
1641
|
te as f,
|
|
1630
|
-
|
|
1631
|
-
|
|
1642
|
+
Kt as g,
|
|
1643
|
+
cr as h,
|
|
1632
1644
|
S as i,
|
|
1633
1645
|
Oe as j,
|
|
1634
1646
|
He as k,
|
|
1635
1647
|
H as l,
|
|
1636
|
-
|
|
1637
|
-
|
|
1648
|
+
dr as m,
|
|
1649
|
+
or as n,
|
|
1638
1650
|
Ge as o,
|
|
1639
|
-
|
|
1651
|
+
ft as p,
|
|
1640
1652
|
x as q,
|
|
1641
1653
|
Ze as r,
|
|
1642
1654
|
Pe as s,
|
|
1643
|
-
|
|
1655
|
+
sr as t,
|
|
1644
1656
|
rt as u,
|
|
1645
1657
|
nt as v
|
|
1646
1658
|
};
|