@d-id/client-sdk 1.2.5-staging.357 → 1.2.5
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.
|
@@ -35,7 +35,7 @@ function dt(e) {
|
|
|
35
35
|
} catch {
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
class
|
|
38
|
+
class Oe extends G {
|
|
39
39
|
constructor(n, i, c = {}) {
|
|
40
40
|
const o = dt(i);
|
|
41
41
|
super(((o == null ? void 0 : o.description) ?? i).slice(0, 256), (o == null ? void 0 : o.kind) ?? "HttpError");
|
|
@@ -74,12 +74,12 @@ class lt extends G {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
class
|
|
77
|
+
class Ke extends G {
|
|
78
78
|
constructor(t, n) {
|
|
79
79
|
super(t, "StreamError", n);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
class
|
|
82
|
+
class $ extends G {
|
|
83
83
|
constructor(t, n) {
|
|
84
84
|
super(t, "ValidationError"), this.key = n;
|
|
85
85
|
}
|
|
@@ -89,7 +89,7 @@ class ut extends G {
|
|
|
89
89
|
super(t, "WSError");
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
var ft = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ft || {}), mt = /* @__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))(mt || {}),
|
|
92
|
+
var ft = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ft || {}), mt = /* @__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))(mt || {}), ht = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ht || {}), gt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(gt || {}), b = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(b || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(z || {}), pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(pt || {}), wt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(wt || {}), yt = /* @__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))(yt || {}), We = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(We || {});
|
|
93
93
|
const An = (e) => {
|
|
94
94
|
switch (e) {
|
|
95
95
|
case "clip":
|
|
@@ -102,13 +102,13 @@ const An = (e) => {
|
|
|
102
102
|
throw new Error(`Unknown video type: ${e}`);
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ie = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ie || {}), x = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(x || {}), A = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(A || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}),
|
|
105
|
+
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ie = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ie || {}), x = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(x || {}), A = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(A || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Se = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Se || {}), vt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(vt || {}), Ct = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ct || {});
|
|
106
106
|
const xn = (...e) => {
|
|
107
|
-
},
|
|
107
|
+
}, He = (e) => new Promise((t) => setTimeout(t, e)), ee = (e = 16) => {
|
|
108
108
|
const t = new Uint8Array(e);
|
|
109
109
|
return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
110
110
|
};
|
|
111
|
-
function
|
|
111
|
+
function pe(e) {
|
|
112
112
|
if (e !== void 0)
|
|
113
113
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
114
114
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
@@ -118,20 +118,20 @@ function we(e) {
|
|
|
118
118
|
}
|
|
119
119
|
return t;
|
|
120
120
|
}
|
|
121
|
-
let
|
|
121
|
+
let qe = ee();
|
|
122
122
|
function St() {
|
|
123
|
-
|
|
123
|
+
qe = ee();
|
|
124
124
|
}
|
|
125
125
|
function Xe(e, t) {
|
|
126
126
|
if (e.type === "bearer")
|
|
127
|
-
return `Bearer ${e.token}
|
|
127
|
+
return `Bearer ${e.token}`;
|
|
128
128
|
if (e.type === "basic")
|
|
129
|
-
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}
|
|
129
|
+
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
130
130
|
if (e.type === "key")
|
|
131
|
-
return `Client-Key ${e.clientKey}.${
|
|
131
|
+
return `Client-Key ${e.clientKey}.${pe(t)}_${qe}`;
|
|
132
132
|
throw new Error(`Unknown auth type: ${e}`);
|
|
133
133
|
}
|
|
134
|
-
const kt = 45 * 1e3, Mt = "X-Playground-Chat",
|
|
134
|
+
const kt = 45 * 1e3, Mt = "X-Playground-Chat", Ee = 2e3, fe = "https://api.d-id.com", Rt = "wss://notifications.d-id.com", Dt = "79f81a83a67430be2bc0fd61042b8faa", Ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, It = (e) => {
|
|
135
135
|
switch (e.type) {
|
|
136
136
|
case "expressive":
|
|
137
137
|
return "v4";
|
|
@@ -140,36 +140,36 @@ const kt = 45 * 1e3, Mt = "X-Playground-Chat", Te = 2e3, me = "https://api.d-id.
|
|
|
140
140
|
case "talk":
|
|
141
141
|
return "v2";
|
|
142
142
|
}
|
|
143
|
-
}, Et = (e) => e.type === "talk" ? e.source_url : e.presenter_id,
|
|
143
|
+
}, Et = (e) => e.type === "talk" ? e.source_url : e.presenter_id, ke = (e) => e === We.Expressive, Tt = (e) => [b.TextOnly, b.Playground, b.Maintenance].includes(e), Qe = (e) => e && [b.DirectPlayback, b.Off].includes(e), Te = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, _e = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, _t = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
|
|
144
144
|
function bt(e) {
|
|
145
145
|
const t = e.split("?")[0].split("#")[0].toLowerCase();
|
|
146
146
|
return _t.some((n) => t.endsWith(n));
|
|
147
147
|
}
|
|
148
|
-
const
|
|
148
|
+
const be = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ae = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
149
149
|
function At(e) {
|
|
150
150
|
if (e.length === 0)
|
|
151
151
|
return [];
|
|
152
152
|
const t = [];
|
|
153
153
|
let n;
|
|
154
|
-
for (
|
|
154
|
+
for (Te.lastIndex = 0; (n = Te.exec(e)) !== null; )
|
|
155
155
|
t.push({
|
|
156
156
|
index: n.index,
|
|
157
157
|
length: n[0].length,
|
|
158
158
|
part: { type: "video", src: n[3], alt: n[1], thumbnail: n[2] }
|
|
159
159
|
});
|
|
160
|
-
for (
|
|
160
|
+
for (_e.lastIndex = 0; (n = _e.exec(e)) !== null; )
|
|
161
161
|
if (!t.some((s) => n.index >= s.index && n.index < s.index + s.length)) {
|
|
162
162
|
const s = n[2], r = n[1];
|
|
163
163
|
let a;
|
|
164
164
|
bt(s) ? a = { type: "video", src: s, alt: r } : (a = { type: "image", src: s, alt: r }, s.toLowerCase().endsWith(".gif") && (a.mimeType = "image/gif")), t.push({ index: n.index, length: n[0].length, part: a });
|
|
165
165
|
}
|
|
166
|
-
for (
|
|
166
|
+
for (be.lastIndex = 0; (n = be.exec(e)) !== null; )
|
|
167
167
|
t.some((s) => n.index >= s.index && n.index < s.index + s.length) || t.push({
|
|
168
168
|
index: n.index,
|
|
169
169
|
length: n[0].length,
|
|
170
170
|
part: { type: "link", href: n[2], label: n[1] }
|
|
171
171
|
});
|
|
172
|
-
for (
|
|
172
|
+
for (Ae.lastIndex = 0; (n = Ae.exec(e)) !== null; )
|
|
173
173
|
t.some((s) => n.index >= s.index && n.index < s.index + s.length) || t.push({
|
|
174
174
|
index: n.index,
|
|
175
175
|
length: n[0].length,
|
|
@@ -184,9 +184,9 @@ function At(e) {
|
|
|
184
184
|
o.index > c && i.push({ type: "text", text: e.slice(c, o.index) }), i.push(o.part), c = o.index + o.length;
|
|
185
185
|
return c < e.length && i.push({ type: "text", text: e.slice(c) }), i;
|
|
186
186
|
}
|
|
187
|
-
let
|
|
187
|
+
let xe = "", me = [];
|
|
188
188
|
function ae(e) {
|
|
189
|
-
return e ===
|
|
189
|
+
return e === xe || (xe = e, me = At(e)), me;
|
|
190
190
|
}
|
|
191
191
|
function xt(e, t) {
|
|
192
192
|
let n;
|
|
@@ -197,7 +197,7 @@ function xt(e, t) {
|
|
|
197
197
|
clear: () => clearTimeout(n)
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
|
-
async function
|
|
200
|
+
async function we(e, t) {
|
|
201
201
|
const n = {
|
|
202
202
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
203
203
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -217,17 +217,17 @@ async function ye(e, t) {
|
|
|
217
217
|
} catch (o) {
|
|
218
218
|
if (i = o, !n.shouldRetryFn(o) || c >= n.limit)
|
|
219
219
|
throw o;
|
|
220
|
-
await
|
|
220
|
+
await He(n.delayMs), n.onRetry(o);
|
|
221
221
|
}
|
|
222
222
|
throw i;
|
|
223
223
|
}
|
|
224
|
-
const Pt = (e) =>
|
|
224
|
+
const Pt = (e) => we(e, {
|
|
225
225
|
limit: 3,
|
|
226
226
|
delayMs: 1e3,
|
|
227
227
|
timeout: 0,
|
|
228
228
|
shouldRetryFn: (t) => t.status === 429
|
|
229
229
|
});
|
|
230
|
-
function Ye(e, t =
|
|
230
|
+
function Ye(e, t = fe, n, i) {
|
|
231
231
|
const c = async (o, s) => {
|
|
232
232
|
const { skipErrorHandler: r, ...a } = s || {}, d = a.method ?? "GET", m = performance.now();
|
|
233
233
|
let u;
|
|
@@ -255,7 +255,7 @@ function Ye(e, t = me, n, i) {
|
|
|
255
255
|
throw r || n == null || n(v, { url: o, options: a }), v;
|
|
256
256
|
}
|
|
257
257
|
if (!u.ok) {
|
|
258
|
-
const f = await u.text().catch(() => `Failed to fetch with status ${u.status}`), w = new
|
|
258
|
+
const f = await u.text().catch(() => `Failed to fetch with status ${u.status}`), w = new Oe(u.status, f, { url: o, method: d });
|
|
259
259
|
throw r || n == null || n(w, { url: o, options: a, headers: u.headers }), w;
|
|
260
260
|
}
|
|
261
261
|
return u.json();
|
|
@@ -275,7 +275,7 @@ function Ye(e, t = me, n, i) {
|
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
}
|
|
278
|
-
function Lt(e, t =
|
|
278
|
+
function Lt(e, t = fe, n, i) {
|
|
279
279
|
const c = Ye(e, `${t}/agents`, n, i);
|
|
280
280
|
return {
|
|
281
281
|
create(o, s) {
|
|
@@ -331,7 +331,7 @@ function jt(e) {
|
|
|
331
331
|
}
|
|
332
332
|
};
|
|
333
333
|
}
|
|
334
|
-
function
|
|
334
|
+
function Bt(e) {
|
|
335
335
|
var n, i, c, o, s, r;
|
|
336
336
|
const t = (n = e.llm) == null ? void 0 : n.prompt_customization;
|
|
337
337
|
return {
|
|
@@ -356,13 +356,13 @@ function $t(e) {
|
|
|
356
356
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
357
357
|
};
|
|
358
358
|
}
|
|
359
|
-
const
|
|
359
|
+
const $t = (e) => {
|
|
360
360
|
try {
|
|
361
361
|
return String((e == null ? void 0 : e.message) ?? e ?? "").slice(0, 256);
|
|
362
362
|
} catch {
|
|
363
363
|
return "Unknown error";
|
|
364
364
|
}
|
|
365
|
-
}, zt = (e) => e.reduce((t, n) => t + n, 0),
|
|
365
|
+
}, zt = (e) => e.reduce((t, n) => t + n, 0), Pe = (e) => zt(e) / e.length, Le = (e) => Math.min(...e), je = (e) => Math.max(...e), le = (e, t = 0) => {
|
|
366
366
|
const n = 10 ** t;
|
|
367
367
|
return Math.round(e * n) / n;
|
|
368
368
|
}, Nt = (e, t) => {
|
|
@@ -390,10 +390,10 @@ function Be(e) {
|
|
|
390
390
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
391
391
|
}
|
|
392
392
|
function he(e) {
|
|
393
|
-
return e instanceof G ? e.toJson() : { kind: "UnknownError", message:
|
|
393
|
+
return e instanceof G ? e.toJson() : { kind: "UnknownError", message: $t(e) || "UnknownError" };
|
|
394
394
|
}
|
|
395
|
-
const Jt = "1.2.5
|
|
396
|
-
let
|
|
395
|
+
const Jt = "1.2.5", Ot = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", Ze = 50, Z = [];
|
|
396
|
+
let ge = !1;
|
|
397
397
|
async function et(e) {
|
|
398
398
|
const t = await fetch(Ot, {
|
|
399
399
|
method: "POST",
|
|
@@ -406,28 +406,28 @@ async function et(e) {
|
|
|
406
406
|
function Kt(e) {
|
|
407
407
|
Z.push(e), Z.splice(Ze);
|
|
408
408
|
}
|
|
409
|
-
function
|
|
410
|
-
if (
|
|
409
|
+
function ye() {
|
|
410
|
+
if (ge || !Z.length)
|
|
411
411
|
return;
|
|
412
|
-
|
|
412
|
+
ge = !0;
|
|
413
413
|
const e = Z.splice(0, Z.length);
|
|
414
414
|
et(e).catch(() => {
|
|
415
415
|
Z.unshift(...e), Z.splice(Ze);
|
|
416
416
|
}).finally(() => {
|
|
417
|
-
|
|
417
|
+
ge = !1;
|
|
418
418
|
});
|
|
419
419
|
}
|
|
420
|
-
typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online",
|
|
421
|
-
document.visibilityState === "visible" &&
|
|
420
|
+
typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online", ye), typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
421
|
+
document.visibilityState === "visible" && ye();
|
|
422
422
|
}));
|
|
423
423
|
function Wt(e) {
|
|
424
424
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", n = {};
|
|
425
425
|
return {
|
|
426
426
|
token: e.token || "testKey",
|
|
427
|
-
distinct_id:
|
|
427
|
+
distinct_id: pe(e.externalId),
|
|
428
428
|
agentId: e.agentId,
|
|
429
429
|
additionalProperties: {
|
|
430
|
-
id:
|
|
430
|
+
id: pe(e.externalId),
|
|
431
431
|
...e.mixpanelAdditionalProperties || {}
|
|
432
432
|
},
|
|
433
433
|
isEnabled: e.isEnabled ?? !0,
|
|
@@ -456,7 +456,7 @@ function Wt(e) {
|
|
|
456
456
|
"User Agent": navigator.userAgent
|
|
457
457
|
}
|
|
458
458
|
};
|
|
459
|
-
return
|
|
459
|
+
return ye(), et([d]).catch(() => Kt(d)), Promise.resolve();
|
|
460
460
|
},
|
|
461
461
|
linkTrack(i, c, o, s) {
|
|
462
462
|
n[i] || (n[i] = { events: {}, resolvedDependencies: [] }), s.includes(o) || s.push(o);
|
|
@@ -474,7 +474,7 @@ function Wt(e) {
|
|
|
474
474
|
}
|
|
475
475
|
};
|
|
476
476
|
}
|
|
477
|
-
function
|
|
477
|
+
function Me() {
|
|
478
478
|
let e = 0;
|
|
479
479
|
return {
|
|
480
480
|
reset: () => e = 0,
|
|
@@ -482,7 +482,7 @@ function Re() {
|
|
|
482
482
|
get: (t = !1) => t ? Date.now() - e : e
|
|
483
483
|
};
|
|
484
484
|
}
|
|
485
|
-
const X =
|
|
485
|
+
const X = Me(), ve = Me(), $e = Me();
|
|
486
486
|
function tt(e) {
|
|
487
487
|
return e === b.Playground ? { headers: { [Mt]: "true" } } : {};
|
|
488
488
|
}
|
|
@@ -515,7 +515,7 @@ async function Xt(e) {
|
|
|
515
515
|
} catch (c) {
|
|
516
516
|
if (i === t)
|
|
517
517
|
throw c;
|
|
518
|
-
await
|
|
518
|
+
await He(i * 500);
|
|
519
519
|
}
|
|
520
520
|
return n;
|
|
521
521
|
}
|
|
@@ -541,7 +541,7 @@ async function Gt(e, t, n, i) {
|
|
|
541
541
|
subscribeToEvents: (s) => c.push(s)
|
|
542
542
|
};
|
|
543
543
|
}
|
|
544
|
-
function
|
|
544
|
+
function ze(e) {
|
|
545
545
|
if (e.answer !== void 0)
|
|
546
546
|
return e.answer;
|
|
547
547
|
let t = 0, n = "";
|
|
@@ -590,10 +590,10 @@ function Yt(e, t, n, i, c, o, s) {
|
|
|
590
590
|
if (e === z.Partial)
|
|
591
591
|
n[f] = u;
|
|
592
592
|
else {
|
|
593
|
-
const v =
|
|
593
|
+
const v = ze(n);
|
|
594
594
|
!!(u && u.length < v.length) && (m.interrupted = !0), n.answer = u;
|
|
595
595
|
}
|
|
596
|
-
const w =
|
|
596
|
+
const w = ze(n);
|
|
597
597
|
(m.content !== w || e === z.Answer) && (m.content = w, m.parts = ae(w), c == null || c([...i.messages], e));
|
|
598
598
|
}
|
|
599
599
|
function Zt(e, t, n, i, c) {
|
|
@@ -638,7 +638,7 @@ function Zt(e, t, n, i, c) {
|
|
|
638
638
|
const T = d.split("/")[1];
|
|
639
639
|
j.includes(d) ? e.track("agent-video", { ...I, event: T }) : e.linkTrack("agent-video", { ...I, event: T }, d, ["done"]);
|
|
640
640
|
}
|
|
641
|
-
j.includes(d) && ((f = (u = n.callbacks).onError) == null || f.call(u, new
|
|
641
|
+
j.includes(d) && ((f = (u = n.callbacks).onError) == null || f.call(u, new Ke(`Stream failed with event ${d}`), { data: m })), m.event === w.StreamDone && c();
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
644
|
};
|
|
@@ -768,7 +768,7 @@ function on(e) {
|
|
|
768
768
|
localTs: s.timestamp
|
|
769
769
|
}), r;
|
|
770
770
|
}
|
|
771
|
-
function
|
|
771
|
+
function Ne(e, t, n) {
|
|
772
772
|
const i = e.map((a, d) => d === 0 ? n ? {
|
|
773
773
|
timestamp: a.timestamp,
|
|
774
774
|
duration: 0,
|
|
@@ -825,13 +825,13 @@ function Fe(e, t, n) {
|
|
|
825
825
|
webRTCStats: {
|
|
826
826
|
anomalies: c,
|
|
827
827
|
avSync: Vt(() => rn(e), null),
|
|
828
|
-
minRtt:
|
|
829
|
-
avgRtt:
|
|
830
|
-
maxRtt:
|
|
828
|
+
minRtt: Le(r),
|
|
829
|
+
avgRtt: Pe(r),
|
|
830
|
+
maxRtt: je(r),
|
|
831
831
|
aggregateReport: an(e[0], e[e.length - 1], o),
|
|
832
|
-
minJitterDelayInInterval:
|
|
833
|
-
maxJitterDelayInInterval:
|
|
834
|
-
avgJitterDelayInInterval:
|
|
832
|
+
minJitterDelayInInterval: Le(s),
|
|
833
|
+
maxJitterDelayInInterval: je(s),
|
|
834
|
+
avgJitterDelayInInterval: Pe(s)
|
|
835
835
|
},
|
|
836
836
|
codec: e[0].codec,
|
|
837
837
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
@@ -883,7 +883,7 @@ function Pn(e, t) {
|
|
|
883
883
|
}
|
|
884
884
|
};
|
|
885
885
|
}
|
|
886
|
-
const
|
|
886
|
+
const ue = 100, cn = Math.max(Math.ceil(400 / ue), 1), dn = 0.25, ln = 0.28;
|
|
887
887
|
function un() {
|
|
888
888
|
let e = 0, t, n, i = 0;
|
|
889
889
|
return (c) => {
|
|
@@ -911,22 +911,22 @@ function fn(e, t, n, i, c) {
|
|
|
911
911
|
if (T)
|
|
912
912
|
a = 0, f = E - w, u = P < dn ? re.Strong : P > ln && f > 1 ? re.Weak : m, u !== m && (c == null || c(u), m = u, w += f, f = 0), d || (i == null || i(S.Start), r = s[s.length - 1], s = [], d = !0), s.push(Q);
|
|
913
913
|
else if (d && (a++, a >= cn)) {
|
|
914
|
-
const H =
|
|
914
|
+
const H = Ne(s, ue, r);
|
|
915
915
|
i == null || i(S.Stop, H), t() || n(), w = E, d = !1;
|
|
916
916
|
}
|
|
917
917
|
}
|
|
918
918
|
return {
|
|
919
919
|
start: () => {
|
|
920
|
-
o || (o = setInterval(j,
|
|
920
|
+
o || (o = setInterval(j, ue));
|
|
921
921
|
},
|
|
922
922
|
stop: () => {
|
|
923
923
|
o && (clearInterval(o), o = null);
|
|
924
924
|
},
|
|
925
|
-
getReport: () =>
|
|
925
|
+
getReport: () => Ne(s, ue, r)
|
|
926
926
|
};
|
|
927
927
|
}
|
|
928
928
|
const mn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
929
|
-
function
|
|
929
|
+
function Fe(e) {
|
|
930
930
|
switch (e) {
|
|
931
931
|
case "connected":
|
|
932
932
|
return A.Connected;
|
|
@@ -946,7 +946,7 @@ function Ve(e) {
|
|
|
946
946
|
return A.New;
|
|
947
947
|
}
|
|
948
948
|
}
|
|
949
|
-
const
|
|
949
|
+
const hn = (e) => (t) => {
|
|
950
950
|
const [n, i = ""] = t.split(/:(.+)/);
|
|
951
951
|
try {
|
|
952
952
|
const c = JSON.parse(i);
|
|
@@ -955,7 +955,7 @@ const gn = (e) => (t) => {
|
|
|
955
955
|
return e("Failed to parse data channel message, returning data as string", { subject: n, rawData: i, error: c }), { subject: n, data: i };
|
|
956
956
|
}
|
|
957
957
|
};
|
|
958
|
-
function
|
|
958
|
+
function gn({
|
|
959
959
|
statsSignal: e,
|
|
960
960
|
dataChannelSignal: t,
|
|
961
961
|
onVideoStateChange: n,
|
|
@@ -974,7 +974,7 @@ function pn({
|
|
|
974
974
|
}) {
|
|
975
975
|
e === S.Start ? (o("CALLBACK: onVideoStateChange(Start)"), n == null || n(S.Start)) : e === S.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), n == null || n(S.Stop, c)), t === S.Start ? i == null || i(ie.Talking) : t === S.Stop && (i == null || i(ie.Idle));
|
|
976
976
|
}
|
|
977
|
-
function
|
|
977
|
+
function Ve({
|
|
978
978
|
statsSignal: e,
|
|
979
979
|
dataChannelSignal: t,
|
|
980
980
|
onVideoStateChange: n,
|
|
@@ -983,7 +983,7 @@ function Ue({
|
|
|
983
983
|
report: o,
|
|
984
984
|
log: s
|
|
985
985
|
}) {
|
|
986
|
-
c === W.Legacy ?
|
|
986
|
+
c === W.Legacy ? gn({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: o, log: s }) : c === W.Fluent && pn({
|
|
987
987
|
statsSignal: e,
|
|
988
988
|
dataChannelSignal: t,
|
|
989
989
|
onVideoStateChange: n,
|
|
@@ -992,9 +992,9 @@ function Ue({
|
|
|
992
992
|
log: s
|
|
993
993
|
});
|
|
994
994
|
}
|
|
995
|
-
async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o =
|
|
995
|
+
async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = fe, analytics: s }, r) {
|
|
996
996
|
var F;
|
|
997
|
-
const a = tn(n, "WebRTCStreamingManager"), d =
|
|
997
|
+
const a = tn(n, "WebRTCStreamingManager"), d = hn(a);
|
|
998
998
|
let m = !1, u = !1, f = S.Stop, w = S.Stop;
|
|
999
999
|
const { startConnection: v, sendStreamRequest: j, close: I, createStream: T, addIceCandidate: P } = en(
|
|
1000
1000
|
c,
|
|
@@ -1018,57 +1018,57 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1018
1018
|
"stream-type": U
|
|
1019
1019
|
});
|
|
1020
1020
|
const oe = t.stream_warmup && !se, ce = () => m, te = () => {
|
|
1021
|
-
var
|
|
1022
|
-
m = !0, u && (a("CALLBACK: onConnectionStateChange(Connected)"), (
|
|
1021
|
+
var h;
|
|
1022
|
+
m = !0, u && (a("CALLBACK: onConnectionStateChange(Connected)"), (h = i.onConnectionStateChange) == null || h.call(i, A.Connected));
|
|
1023
1023
|
}, l = fn(
|
|
1024
1024
|
() => R.getStats(),
|
|
1025
1025
|
ce,
|
|
1026
1026
|
te,
|
|
1027
|
-
(
|
|
1028
|
-
statsSignal: w =
|
|
1027
|
+
(h, g) => Ve({
|
|
1028
|
+
statsSignal: w = h,
|
|
1029
1029
|
dataChannelSignal: U === W.Legacy ? f : void 0,
|
|
1030
1030
|
onVideoStateChange: i.onVideoStateChange,
|
|
1031
1031
|
onAgentActivityStateChange: i.onAgentActivityStateChange,
|
|
1032
|
-
report:
|
|
1032
|
+
report: g,
|
|
1033
1033
|
streamType: U,
|
|
1034
1034
|
log: a
|
|
1035
1035
|
}),
|
|
1036
|
-
(
|
|
1037
|
-
var
|
|
1038
|
-
return (
|
|
1036
|
+
(h) => {
|
|
1037
|
+
var g;
|
|
1038
|
+
return (g = i.onConnectivityStateChange) == null ? void 0 : g.call(i, h);
|
|
1039
1039
|
}
|
|
1040
1040
|
);
|
|
1041
|
-
l.start(), R.onicecandidate = (
|
|
1042
|
-
var
|
|
1043
|
-
a("peerConnection.onicecandidate",
|
|
1041
|
+
l.start(), R.onicecandidate = (h) => {
|
|
1042
|
+
var g;
|
|
1043
|
+
a("peerConnection.onicecandidate", h);
|
|
1044
1044
|
try {
|
|
1045
|
-
|
|
1045
|
+
h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? P(
|
|
1046
1046
|
E,
|
|
1047
1047
|
{
|
|
1048
|
-
candidate:
|
|
1049
|
-
sdpMid:
|
|
1050
|
-
sdpMLineIndex:
|
|
1048
|
+
candidate: h.candidate.candidate,
|
|
1049
|
+
sdpMid: h.candidate.sdpMid,
|
|
1050
|
+
sdpMLineIndex: h.candidate.sdpMLineIndex
|
|
1051
1051
|
},
|
|
1052
1052
|
V,
|
|
1053
1053
|
r
|
|
1054
1054
|
) : P(E, { candidate: null }, V, r);
|
|
1055
1055
|
} catch (D) {
|
|
1056
|
-
(
|
|
1056
|
+
(g = i.onError) == null || g.call(i, D, { streamId: E });
|
|
1057
1057
|
}
|
|
1058
1058
|
}, q.onopen = () => {
|
|
1059
1059
|
u = !0, (!oe || m) && te();
|
|
1060
1060
|
};
|
|
1061
1061
|
let p = null;
|
|
1062
|
-
const y = (
|
|
1063
|
-
var
|
|
1064
|
-
p =
|
|
1062
|
+
const y = (h) => {
|
|
1063
|
+
var g;
|
|
1064
|
+
p = h, (g = i.onVideoIdChange) == null || g.call(i, h);
|
|
1065
1065
|
};
|
|
1066
|
-
function C(
|
|
1067
|
-
if (
|
|
1068
|
-
const D =
|
|
1066
|
+
function C(h, g) {
|
|
1067
|
+
if (h === x.StreamStarted && typeof g == "object" && "metadata" in g) {
|
|
1068
|
+
const D = g.metadata;
|
|
1069
1069
|
y(D.videoId);
|
|
1070
1070
|
}
|
|
1071
|
-
|
|
1071
|
+
h === x.StreamDone && y(null), f = h === x.StreamStarted ? S.Start : S.Stop, Ve({
|
|
1072
1072
|
statsSignal: U === W.Legacy ? w : void 0,
|
|
1073
1073
|
dataChannelSignal: f,
|
|
1074
1074
|
onVideoStateChange: i.onVideoStateChange,
|
|
@@ -1077,43 +1077,43 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1077
1077
|
log: a
|
|
1078
1078
|
});
|
|
1079
1079
|
}
|
|
1080
|
-
function k(
|
|
1081
|
-
var
|
|
1082
|
-
const D = typeof
|
|
1083
|
-
D && s.enrich({ streamMetadata: D }), (
|
|
1080
|
+
function k(h, g) {
|
|
1081
|
+
var B;
|
|
1082
|
+
const D = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
|
|
1083
|
+
D && s.enrich({ streamMetadata: D }), (B = i.onStreamReady) == null || B.call(i);
|
|
1084
1084
|
}
|
|
1085
1085
|
const M = {
|
|
1086
1086
|
[x.StreamStarted]: C,
|
|
1087
1087
|
[x.StreamDone]: C,
|
|
1088
1088
|
[x.StreamReady]: k
|
|
1089
1089
|
};
|
|
1090
|
-
q.onmessage = (
|
|
1091
|
-
var
|
|
1092
|
-
const { subject:
|
|
1093
|
-
(
|
|
1090
|
+
q.onmessage = (h) => {
|
|
1091
|
+
var B;
|
|
1092
|
+
const { subject: g, data: D } = d(h.data);
|
|
1093
|
+
(B = M[g]) == null || B.call(M, g, D);
|
|
1094
1094
|
}, R.oniceconnectionstatechange = () => {
|
|
1095
|
-
var
|
|
1095
|
+
var g;
|
|
1096
1096
|
a("peerConnection.oniceconnectionstatechange => " + R.iceConnectionState);
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
}, R.ontrack = (
|
|
1100
|
-
var
|
|
1101
|
-
a("peerConnection.ontrack",
|
|
1097
|
+
const h = Fe(R.iceConnectionState);
|
|
1098
|
+
h !== A.Connected && ((g = i.onConnectionStateChange) == null || g.call(i, h, `webrtc:ice-${R.iceConnectionState}`));
|
|
1099
|
+
}, R.ontrack = (h) => {
|
|
1100
|
+
var g;
|
|
1101
|
+
a("peerConnection.ontrack", h), a("CALLBACK: onSrcObjectReady"), (g = i.onSrcObjectReady) == null || g.call(i, h.streams[0]);
|
|
1102
1102
|
}, await R.setRemoteDescription(Q), a("set remote description OK");
|
|
1103
1103
|
const L = await R.createAnswer();
|
|
1104
1104
|
a("create answer OK"), await R.setLocalDescription(L), a("set local description OK"), await v(E, L, V, r), a("start connection OK");
|
|
1105
|
-
function N(
|
|
1106
|
-
var
|
|
1105
|
+
function N(h) {
|
|
1106
|
+
var g, D;
|
|
1107
1107
|
if (!m || q.readyState !== "open") {
|
|
1108
|
-
a("Data channel is not ready for sending messages"), (
|
|
1108
|
+
a("Data channel is not ready for sending messages"), (g = i.onError) == null || g.call(i, new Ke("Data channel is not ready for sending messages"), {
|
|
1109
1109
|
streamId: E
|
|
1110
1110
|
});
|
|
1111
1111
|
return;
|
|
1112
1112
|
}
|
|
1113
1113
|
try {
|
|
1114
|
-
q.send(
|
|
1115
|
-
} catch (
|
|
1116
|
-
a("Error sending data channel message",
|
|
1114
|
+
q.send(h);
|
|
1115
|
+
} catch (B) {
|
|
1116
|
+
a("Error sending data channel message", B), (D = i.onError) == null || D.call(i, B, { streamId: E });
|
|
1117
1117
|
}
|
|
1118
1118
|
}
|
|
1119
1119
|
return {
|
|
@@ -1121,30 +1121,30 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1121
1121
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1122
1122
|
* @param payload
|
|
1123
1123
|
*/
|
|
1124
|
-
speak(
|
|
1125
|
-
return j(E, V,
|
|
1124
|
+
speak(h) {
|
|
1125
|
+
return j(E, V, h);
|
|
1126
1126
|
},
|
|
1127
1127
|
/**
|
|
1128
1128
|
* Method to close RTC connection
|
|
1129
1129
|
*/
|
|
1130
1130
|
async disconnect() {
|
|
1131
|
-
var
|
|
1131
|
+
var h;
|
|
1132
1132
|
if (E) {
|
|
1133
|
-
const
|
|
1133
|
+
const g = Fe(R.iceConnectionState);
|
|
1134
1134
|
if (R) {
|
|
1135
|
-
if (
|
|
1135
|
+
if (g === A.New) {
|
|
1136
1136
|
l.stop();
|
|
1137
1137
|
return;
|
|
1138
1138
|
}
|
|
1139
1139
|
R.close(), R.oniceconnectionstatechange = null, R.onnegotiationneeded = null, R.onicecandidate = null, R.ontrack = null;
|
|
1140
1140
|
}
|
|
1141
1141
|
try {
|
|
1142
|
-
|
|
1142
|
+
g === A.Connected && await I(E, V).catch((D) => {
|
|
1143
1143
|
});
|
|
1144
1144
|
} catch (D) {
|
|
1145
1145
|
a("Error on close stream connection", D);
|
|
1146
1146
|
}
|
|
1147
|
-
(
|
|
1147
|
+
(h = i.onAgentActivityStateChange) == null || h.call(i, ie.Idle), l.stop();
|
|
1148
1148
|
}
|
|
1149
1149
|
},
|
|
1150
1150
|
sendDataChannelMessage: N,
|
|
@@ -1159,23 +1159,23 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1159
1159
|
streamType: U,
|
|
1160
1160
|
interruptAvailable: Y ?? !1,
|
|
1161
1161
|
isInterruptible: !0,
|
|
1162
|
-
interrupt(
|
|
1162
|
+
interrupt(h) {
|
|
1163
1163
|
if (!Y)
|
|
1164
1164
|
throw new Error("Interrupt is not enabled for this stream");
|
|
1165
1165
|
if (U !== W.Fluent)
|
|
1166
1166
|
throw new Error("Interrupt only available for Fluent streams");
|
|
1167
1167
|
if (!p)
|
|
1168
1168
|
throw new Error("No active video to interrupt");
|
|
1169
|
-
const
|
|
1169
|
+
const g = {
|
|
1170
1170
|
type: x.StreamInterrupt,
|
|
1171
1171
|
videoId: p,
|
|
1172
1172
|
timestamp: Date.now()
|
|
1173
1173
|
};
|
|
1174
|
-
N(JSON.stringify(
|
|
1174
|
+
N(JSON.stringify(g));
|
|
1175
1175
|
}
|
|
1176
1176
|
};
|
|
1177
1177
|
}
|
|
1178
|
-
var
|
|
1178
|
+
var Ce = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ce || {});
|
|
1179
1179
|
async function yn(e, t, n, i) {
|
|
1180
1180
|
const c = e.id;
|
|
1181
1181
|
switch (t.version) {
|
|
@@ -1186,8 +1186,8 @@ async function yn(e, t, n, i) {
|
|
|
1186
1186
|
case "v2": {
|
|
1187
1187
|
const { version: o, ...s } = t;
|
|
1188
1188
|
switch (s.transport.provider) {
|
|
1189
|
-
case
|
|
1190
|
-
const { createLiveKitStreamingManager: r } = await import("./livekit-manager-
|
|
1189
|
+
case Se.Livekit:
|
|
1190
|
+
const { createLiveKitStreamingManager: r } = await import("./livekit-manager-BLc5LMRQ.js");
|
|
1191
1191
|
return r(c, s, n);
|
|
1192
1192
|
default:
|
|
1193
1193
|
throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
|
|
@@ -1201,7 +1201,7 @@ const vn = "cht";
|
|
|
1201
1201
|
function Cn() {
|
|
1202
1202
|
return {
|
|
1203
1203
|
transport: {
|
|
1204
|
-
provider:
|
|
1204
|
+
provider: Se.Livekit
|
|
1205
1205
|
}
|
|
1206
1206
|
};
|
|
1207
1207
|
}
|
|
@@ -1219,7 +1219,7 @@ function Sn(e) {
|
|
|
1219
1219
|
}, ...n && { end_user_data: n } };
|
|
1220
1220
|
}
|
|
1221
1221
|
function kn(e, t) {
|
|
1222
|
-
return
|
|
1222
|
+
return ke(e.presenter.type) ? { version: Ce.V2, ...Cn() } : { version: Ce.V1, ...Sn(t) };
|
|
1223
1223
|
}
|
|
1224
1224
|
function Mn(e, t, n) {
|
|
1225
1225
|
n.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
@@ -1236,7 +1236,7 @@ function Dn(e, t, n, i, c) {
|
|
|
1236
1236
|
...n
|
|
1237
1237
|
});
|
|
1238
1238
|
}
|
|
1239
|
-
function
|
|
1239
|
+
function Ue(e, t, n, i, c) {
|
|
1240
1240
|
e === S.Start ? n.linkTrack("agent-video", { event: "start", ...c, "stream-type": i }, "start", [
|
|
1241
1241
|
x.StreamVideoCreated
|
|
1242
1242
|
]) : e === S.Stop && n.linkTrack(
|
|
@@ -1287,8 +1287,8 @@ function En(e, t, n) {
|
|
|
1287
1287
|
extra_keys: c.extra ? Object.keys(c.extra).length : 0
|
|
1288
1288
|
});
|
|
1289
1289
|
}
|
|
1290
|
-
function
|
|
1291
|
-
return X.reset(),
|
|
1290
|
+
function Je(e, t, n, i) {
|
|
1291
|
+
return X.reset(), $e.update(), new Promise(async (c, o) => {
|
|
1292
1292
|
try {
|
|
1293
1293
|
let s, r = !1;
|
|
1294
1294
|
const a = kn(e, t);
|
|
@@ -1321,15 +1321,15 @@ function Oe(e, t, n, i) {
|
|
|
1321
1321
|
},
|
|
1322
1322
|
onAgentActivityStateChange: (u) => {
|
|
1323
1323
|
var f, w;
|
|
1324
|
-
(w = (f = t.callbacks).onAgentActivityStateChange) == null || w.call(f, u), u === ie.Talking ? (
|
|
1325
|
-
|
|
1324
|
+
(w = (f = t.callbacks).onAgentActivityStateChange) == null || w.call(f, u), u === ie.Talking ? (ve.update(), d = (v) => {
|
|
1325
|
+
Ue(
|
|
1326
1326
|
S.Start,
|
|
1327
1327
|
e,
|
|
1328
1328
|
n,
|
|
1329
1329
|
s.streamType,
|
|
1330
1330
|
v
|
|
1331
1331
|
), d = null;
|
|
1332
|
-
}, m || d({ latency: X.get(!0) })) : (
|
|
1332
|
+
}, m || d({ latency: X.get(!0) })) : (ve.reset(), d = null, Ue(
|
|
1333
1333
|
S.Stop,
|
|
1334
1334
|
e,
|
|
1335
1335
|
n,
|
|
@@ -1340,7 +1340,7 @@ function Oe(e, t, n, i) {
|
|
|
1340
1340
|
d == null || d(u);
|
|
1341
1341
|
},
|
|
1342
1342
|
onStreamReady: () => {
|
|
1343
|
-
const u =
|
|
1343
|
+
const u = $e.get(!0);
|
|
1344
1344
|
n.track("agent-chat", { event: "ready", latency: u });
|
|
1345
1345
|
},
|
|
1346
1346
|
onToolEvent: ((u, f) => {
|
|
@@ -1359,8 +1359,8 @@ function Oe(e, t, n, i) {
|
|
|
1359
1359
|
async function Tn(e, t, n, i, c) {
|
|
1360
1360
|
var m, u, f, w;
|
|
1361
1361
|
const o = async () => {
|
|
1362
|
-
if (
|
|
1363
|
-
const v = await
|
|
1362
|
+
if (ke(e.presenter.type)) {
|
|
1363
|
+
const v = await Je(e, t, i), j = `${vn}_${v.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
|
|
1364
1364
|
return { chatResult: {
|
|
1365
1365
|
chatMode: b.Functional,
|
|
1366
1366
|
chat: {
|
|
@@ -1386,7 +1386,7 @@ async function Tn(e, t, n, i, c) {
|
|
|
1386
1386
|
t.mode,
|
|
1387
1387
|
t.persistentChat,
|
|
1388
1388
|
c
|
|
1389
|
-
), P =
|
|
1389
|
+
), P = Je(e, t, i, j).then((H) => (I = H, H)), [E, Q] = await Promise.all([T, P]);
|
|
1390
1390
|
return { chatResult: E, streamingManager: Q };
|
|
1391
1391
|
} catch (T) {
|
|
1392
1392
|
throw v.abort(), I && await I.disconnect().catch(() => {
|
|
@@ -1399,7 +1399,7 @@ async function Tn(e, t, n, i, c) {
|
|
|
1399
1399
|
async function Ln(e, t) {
|
|
1400
1400
|
var U, oe, ce, te;
|
|
1401
1401
|
let n = !0;
|
|
1402
|
-
const i = t.mixpanelKey || Dt, c = t.wsURL || Rt, o = t.baseURL ||
|
|
1402
|
+
const i = t.mixpanelKey || Dt, c = t.wsURL || Rt, o = t.baseURL || fe, s = t.mode || b.Functional, r = {
|
|
1403
1403
|
messages: [],
|
|
1404
1404
|
chatMode: s
|
|
1405
1405
|
}, a = Wt({
|
|
@@ -1418,8 +1418,8 @@ async function Ln(e, t) {
|
|
|
1418
1418
|
};
|
|
1419
1419
|
const u = Lt(t.auth, o, t.callbacks.onError, t.externalId), f = await u.getById(e);
|
|
1420
1420
|
t.debug = t.debug || ((U = f == null ? void 0 : f.advanced_settings) == null ? void 0 : U.ui_debug_mode);
|
|
1421
|
-
const w =
|
|
1422
|
-
a.enrich(
|
|
1421
|
+
const w = ke(f.presenter.type);
|
|
1422
|
+
a.enrich(Bt(f));
|
|
1423
1423
|
const { onMessage: v, clearQueue: j } = Zt(a, r, t, f, () => {
|
|
1424
1424
|
var l, p, y;
|
|
1425
1425
|
(l = r.socketManager) == null || l.disconnect(), (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, A.Disconnected);
|
|
@@ -1433,7 +1433,7 @@ async function Ln(e, t) {
|
|
|
1433
1433
|
const p = r.messages[r.messages.length - 1];
|
|
1434
1434
|
a.track("agent-video-interrupt", {
|
|
1435
1435
|
type: l || "click",
|
|
1436
|
-
video_duration_to_interrupt:
|
|
1436
|
+
video_duration_to_interrupt: ve.get(!0),
|
|
1437
1437
|
message_duration_to_interrupt: X.get(!0)
|
|
1438
1438
|
}), p.interrupted = !0, (M = (k = t.callbacks).onNewMessage) == null || M.call(k, [...r.messages], "answer"), r.streamingManager.interrupt(l);
|
|
1439
1439
|
}, P = /* @__PURE__ */ new Map();
|
|
@@ -1469,14 +1469,14 @@ async function Ln(e, t) {
|
|
|
1469
1469
|
a.track("agent-sdk", { event: "loaded", ...jt(f) }, se);
|
|
1470
1470
|
});
|
|
1471
1471
|
async function Y(l) {
|
|
1472
|
-
var L, N, F,
|
|
1473
|
-
St(), (N = (L = t.callbacks).onConnectionStateChange) == null || N.call(L, A.Connecting), X.reset(), l && !n && (delete r.chat, (
|
|
1472
|
+
var L, N, F, h, g, D, B;
|
|
1473
|
+
St(), (N = (L = t.callbacks).onConnectionStateChange) == null || N.call(L, A.Connecting), X.reset(), l && !n && (delete r.chat, (h = (F = t.callbacks).onNewMessage) == null || h.call(F, [...r.messages], "answer"));
|
|
1474
1474
|
const p = s === b.DirectPlayback || w ? Promise.resolve(void 0) : Gt(
|
|
1475
1475
|
t.auth,
|
|
1476
1476
|
c,
|
|
1477
1477
|
{ onMessage: v, onError: t.callbacks.onError },
|
|
1478
1478
|
t.externalId
|
|
1479
|
-
), y =
|
|
1479
|
+
), y = we(
|
|
1480
1480
|
() => Tn(
|
|
1481
1481
|
f,
|
|
1482
1482
|
{
|
|
@@ -1496,14 +1496,14 @@ async function Ln(e, t) {
|
|
|
1496
1496
|
limit: 3,
|
|
1497
1497
|
timeout: kt,
|
|
1498
1498
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1499
|
-
shouldRetryFn: (O) => (O == null ? void 0 : O.message) !== "Could not connect" && !(O instanceof
|
|
1499
|
+
shouldRetryFn: (O) => (O == null ? void 0 : O.message) !== "Could not connect" && !(O instanceof Oe && (O.status === 429 || O.kind === "InsufficientCreditsError")),
|
|
1500
1500
|
delayMs: 1e3
|
|
1501
1501
|
}
|
|
1502
1502
|
).catch((O) => {
|
|
1503
1503
|
var _, J;
|
|
1504
1504
|
throw q(b.Maintenance), (J = (_ = t.callbacks).onConnectionStateChange) == null || J.call(_, A.Fail), O;
|
|
1505
1505
|
}), [C, { streamingManager: k, chat: M }] = await Promise.all([p, y]);
|
|
1506
|
-
M && M.id !== ((
|
|
1506
|
+
M && M.id !== ((g = r.chat) == null ? void 0 : g.id) && ((B = (D = t.callbacks).onNewChat) == null || B.call(D, M.id)), r.streamingManager = k, r.socketManager = C, r.chat = M, Q(), n = !1, a.enrich({
|
|
1507
1507
|
chatId: M == null ? void 0 : M.id,
|
|
1508
1508
|
streamId: k == null ? void 0 : k.streamId,
|
|
1509
1509
|
mode: r.chatMode
|
|
@@ -1585,21 +1585,21 @@ async function Ln(e, t) {
|
|
|
1585
1585
|
var k, M, L, N, F;
|
|
1586
1586
|
const p = () => {
|
|
1587
1587
|
if (Qe(s))
|
|
1588
|
-
throw new
|
|
1589
|
-
if (l.length >=
|
|
1590
|
-
throw new
|
|
1588
|
+
throw new $(`${s} is enabled, chat is disabled`);
|
|
1589
|
+
if (l.length >= Ee)
|
|
1590
|
+
throw new $(`Message cannot be more than ${Ee} characters`);
|
|
1591
1591
|
if (l.length === 0)
|
|
1592
|
-
throw new
|
|
1592
|
+
throw new $("Message cannot be empty");
|
|
1593
1593
|
if (r.chatMode === b.Maintenance)
|
|
1594
|
-
throw new
|
|
1594
|
+
throw new $("Chat is in maintenance mode");
|
|
1595
1595
|
if (![b.TextOnly, b.Playground].includes(r.chatMode)) {
|
|
1596
1596
|
if (!r.streamingManager)
|
|
1597
|
-
throw new
|
|
1597
|
+
throw new $("Streaming manager is not initialized");
|
|
1598
1598
|
if (!r.chat)
|
|
1599
|
-
throw new
|
|
1599
|
+
throw new $("Chat is not initialized");
|
|
1600
1600
|
}
|
|
1601
1601
|
}, y = async () => {
|
|
1602
|
-
var
|
|
1602
|
+
var h, g;
|
|
1603
1603
|
if (!r.chat) {
|
|
1604
1604
|
const D = await nt(
|
|
1605
1605
|
f,
|
|
@@ -1610,24 +1610,24 @@ async function Ln(e, t) {
|
|
|
1610
1610
|
);
|
|
1611
1611
|
if (!D.chat)
|
|
1612
1612
|
throw new ot(r.chatMode, !!t.persistentChat);
|
|
1613
|
-
r.chat = D.chat, (
|
|
1613
|
+
r.chat = D.chat, (g = (h = t.callbacks).onNewChat) == null || g.call(h, r.chat.id);
|
|
1614
1614
|
}
|
|
1615
1615
|
return r.chat.id;
|
|
1616
|
-
}, C = async (
|
|
1616
|
+
}, C = async (h, g) => {
|
|
1617
1617
|
const D = r.chatMode === b.Playground;
|
|
1618
|
-
return
|
|
1618
|
+
return we(w && !D ? async () => {
|
|
1619
1619
|
var _, J;
|
|
1620
1620
|
return await ((J = (_ = r.streamingManager) == null ? void 0 : _.sendTextMessage) == null ? void 0 : J.call(_, l)), Promise.resolve({});
|
|
1621
1621
|
} : async () => {
|
|
1622
1622
|
var _, J;
|
|
1623
1623
|
return u.chat(
|
|
1624
1624
|
f.id,
|
|
1625
|
-
|
|
1625
|
+
g,
|
|
1626
1626
|
{
|
|
1627
1627
|
chatMode: r.chatMode,
|
|
1628
1628
|
streamId: (_ = r.streamingManager) == null ? void 0 : _.streamId,
|
|
1629
1629
|
sessionId: (J = r.streamingManager) == null ? void 0 : J.sessionId,
|
|
1630
|
-
messages:
|
|
1630
|
+
messages: h.map(({ matches: at, ...de }) => de)
|
|
1631
1631
|
},
|
|
1632
1632
|
{
|
|
1633
1633
|
...tt(r.chatMode),
|
|
@@ -1637,9 +1637,9 @@ async function Ln(e, t) {
|
|
|
1637
1637
|
}, {
|
|
1638
1638
|
limit: 2,
|
|
1639
1639
|
shouldRetryFn: (_) => {
|
|
1640
|
-
var de, De, Ie
|
|
1640
|
+
var de, Re, De, Ie;
|
|
1641
1641
|
const J = (de = _ == null ? void 0 : _.message) == null ? void 0 : de.includes("missing or invalid session_id");
|
|
1642
|
-
return !((
|
|
1642
|
+
return !((Re = _ == null ? void 0 : _.message) == null ? void 0 : Re.includes("Stream Error")) && !J ? ((Ie = (De = t.callbacks).onError) == null || Ie.call(De, _), !1) : !0;
|
|
1643
1643
|
},
|
|
1644
1644
|
onRetry: async () => {
|
|
1645
1645
|
await R(), await Y(!1);
|
|
@@ -1654,38 +1654,38 @@ async function Ln(e, t) {
|
|
|
1654
1654
|
parts: ae(l),
|
|
1655
1655
|
created_at: new Date(X.update()).toISOString()
|
|
1656
1656
|
}), (M = (k = t.callbacks).onNewMessage) == null || M.call(k, [...r.messages], "user");
|
|
1657
|
-
const
|
|
1658
|
-
return
|
|
1657
|
+
const h = await y(), g = await C([...r.messages], h);
|
|
1658
|
+
return g.result && r.messages.push({
|
|
1659
1659
|
id: ee(),
|
|
1660
1660
|
role: "assistant",
|
|
1661
|
-
content:
|
|
1662
|
-
parts: ae(
|
|
1661
|
+
content: g.result,
|
|
1662
|
+
parts: ae(g.result),
|
|
1663
1663
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1664
|
-
context:
|
|
1665
|
-
matches:
|
|
1664
|
+
context: g.context,
|
|
1665
|
+
matches: g.matches
|
|
1666
1666
|
}), a.track("agent-message-send", {
|
|
1667
1667
|
event: "success",
|
|
1668
1668
|
messages: r.messages.length + 1
|
|
1669
|
-
}),
|
|
1669
|
+
}), g.result && ((N = (L = t.callbacks).onNewMessage) == null || N.call(L, [...r.messages], "answer"), a.track("agent-message-received", {
|
|
1670
1670
|
latency: X.get(!0),
|
|
1671
1671
|
messages: r.messages.length
|
|
1672
|
-
})),
|
|
1673
|
-
} catch (
|
|
1672
|
+
})), g;
|
|
1673
|
+
} catch (h) {
|
|
1674
1674
|
throw ((F = r.messages[r.messages.length - 1]) == null ? void 0 : F.role) === "assistant" && r.messages.pop(), a.track("agent-message-send", {
|
|
1675
1675
|
event: "error",
|
|
1676
1676
|
messages: r.messages.length,
|
|
1677
|
-
error: he(
|
|
1678
|
-
}),
|
|
1677
|
+
error: he(h)
|
|
1678
|
+
}), h;
|
|
1679
1679
|
}
|
|
1680
1680
|
},
|
|
1681
1681
|
rate(l, p, y) {
|
|
1682
1682
|
var M, L, N, F;
|
|
1683
|
-
const C = r.messages.find((
|
|
1683
|
+
const C = r.messages.find((h) => h.id === l);
|
|
1684
1684
|
if (r.chat) {
|
|
1685
1685
|
if (!C)
|
|
1686
|
-
throw new
|
|
1687
|
-
} else throw new
|
|
1688
|
-
const k = ((M = C.matches) == null ? void 0 : M.map((
|
|
1686
|
+
throw new $("Message not found");
|
|
1687
|
+
} else throw new $("Chat is not initialized");
|
|
1688
|
+
const k = ((M = C.matches) == null ? void 0 : M.map((h) => [h.document_id, h.id])) ?? [];
|
|
1689
1689
|
return a.track("agent-rate", {
|
|
1690
1690
|
event: y ? "update" : "create",
|
|
1691
1691
|
thumb: p === 1 ? "up" : "down",
|
|
@@ -1706,7 +1706,7 @@ async function Ln(e, t) {
|
|
|
1706
1706
|
},
|
|
1707
1707
|
deleteRate(l) {
|
|
1708
1708
|
if (!r.chat)
|
|
1709
|
-
throw new
|
|
1709
|
+
throw new $("Chat is not initialized");
|
|
1710
1710
|
return a.track("agent-rate-delete", { type: "text" }), u.deleteRating(f.id, r.chat.id, l);
|
|
1711
1711
|
},
|
|
1712
1712
|
async speak(l) {
|
|
@@ -1714,7 +1714,7 @@ async function Ln(e, t) {
|
|
|
1714
1714
|
function p() {
|
|
1715
1715
|
if (typeof l == "string") {
|
|
1716
1716
|
if (!f.presenter.voice)
|
|
1717
|
-
throw new
|
|
1717
|
+
throw new $("Presenter voice is not initialized");
|
|
1718
1718
|
return {
|
|
1719
1719
|
type: "text",
|
|
1720
1720
|
provider: f.presenter.voice,
|
|
@@ -1724,7 +1724,7 @@ async function Ln(e, t) {
|
|
|
1724
1724
|
}
|
|
1725
1725
|
if (l.type === "text" && !l.provider) {
|
|
1726
1726
|
if (!f.presenter.voice)
|
|
1727
|
-
throw new
|
|
1727
|
+
throw new $("Presenter voice is not initialized");
|
|
1728
1728
|
return {
|
|
1729
1729
|
type: "text",
|
|
1730
1730
|
provider: f.presenter.voice,
|
|
@@ -1748,7 +1748,7 @@ async function Ln(e, t) {
|
|
|
1748
1748
|
status: "success"
|
|
1749
1749
|
};
|
|
1750
1750
|
if (!r.streamingManager)
|
|
1751
|
-
throw new
|
|
1751
|
+
throw new $("Please connect to the agent first");
|
|
1752
1752
|
return r.streamingManager.speak({
|
|
1753
1753
|
script: y,
|
|
1754
1754
|
metadata: { chat_id: (L = r.chat) == null ? void 0 : L.id, agent_id: f.id }
|
|
@@ -1764,27 +1764,27 @@ export {
|
|
|
1764
1764
|
G as B,
|
|
1765
1765
|
z as C,
|
|
1766
1766
|
yt as D,
|
|
1767
|
-
|
|
1767
|
+
Oe as H,
|
|
1768
1768
|
wt as K,
|
|
1769
1769
|
lt as N,
|
|
1770
1770
|
mt as P,
|
|
1771
|
-
|
|
1771
|
+
gt as R,
|
|
1772
1772
|
x as S,
|
|
1773
|
-
|
|
1773
|
+
Se as T,
|
|
1774
1774
|
ft as U,
|
|
1775
|
-
|
|
1775
|
+
$ as V,
|
|
1776
1776
|
ut as W,
|
|
1777
1777
|
tn as a,
|
|
1778
1778
|
W as b,
|
|
1779
1779
|
Ye as c,
|
|
1780
|
-
|
|
1781
|
-
|
|
1780
|
+
fe as d,
|
|
1781
|
+
Ke as e,
|
|
1782
1782
|
A as f,
|
|
1783
1783
|
re as g,
|
|
1784
1784
|
fn as h,
|
|
1785
1785
|
Pn as i,
|
|
1786
1786
|
S as j,
|
|
1787
|
-
|
|
1787
|
+
ht as k,
|
|
1788
1788
|
X as l,
|
|
1789
1789
|
ot as m,
|
|
1790
1790
|
xn as n,
|
|
@@ -1794,7 +1794,7 @@ export {
|
|
|
1794
1794
|
Jt as r,
|
|
1795
1795
|
pt as s,
|
|
1796
1796
|
he as t,
|
|
1797
|
-
|
|
1797
|
+
We as u,
|
|
1798
1798
|
Ct as v,
|
|
1799
1799
|
Ln as w,
|
|
1800
1800
|
bn as x,
|