@d-id/client-sdk 3.0.0-staging.420 → 3.0.0-staging.423
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-BrPt8AuN.js → index-WHsoBMGg.js} +104 -100
- package/dist/index-WHsoBMGg.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-me8pKdKj.js → livekit-manager-BCxu61o7.js} +2 -2
- package/dist/{livekit-manager-me8pKdKj.js.map → livekit-manager-BCxu61o7.js.map} +1 -1
- package/package.json +1 -1
- package/dist/index-BrPt8AuN.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var It = Object.defineProperty;
|
|
2
2
|
var Et = (e, t, r) => t in e ? It(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
3
|
var x = (e, t, r) => Et(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
-
var
|
|
4
|
+
var Ie = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Ie || {}), L = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(L || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(pe || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), me = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(me || {}), ye = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ye || {}), T = /* @__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.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.TurnStarted = "turn/started", e.TurnEnded = "turn/ended", e))(T || {}), je = /* @__PURE__ */ ((e) => (e.Started = "tool-call/started", e.Done = "tool-call/done", e.Error = "tool-call/error", e))(je || {}), Tt = /* @__PURE__ */ ((e) => (e.Presentation = "did.presentation", e))(Tt || {}), I = /* @__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))(I || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), ge = /* @__PURE__ */ ((e) => (e.Ok = "ok", e.UnknownError = "unknown_error", e.NetworkIssue = "network_issue", e.MessageLimit = "message_limit", e.TimeLimit = "time_limit", e.Inactivity = "inactivity", e.EndedByAgent = "ended_by_agent", e))(ge || {}), Fe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Fe || {}), kt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Elevenlabs = "elevenlabs", e.Cartesia = "cartesia", e))(kt || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e.ExternalPrivate = "external-private", e))(_t || {});
|
|
5
5
|
const Jn = (...e) => {
|
|
6
6
|
}, ft = (e) => new Promise((t) => setTimeout(t, e)), Z = (e = 16) => {
|
|
7
7
|
const t = new Uint8Array(e);
|
|
8
8
|
return globalThis.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
9
9
|
};
|
|
10
|
-
function
|
|
10
|
+
function Be(e) {
|
|
11
11
|
if (e !== void 0)
|
|
12
12
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
13
13
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
@@ -18,7 +18,7 @@ function je(e) {
|
|
|
18
18
|
return t;
|
|
19
19
|
}
|
|
20
20
|
let mt;
|
|
21
|
-
function
|
|
21
|
+
function _e() {
|
|
22
22
|
return mt ?? (mt = Z());
|
|
23
23
|
}
|
|
24
24
|
function At() {
|
|
@@ -26,14 +26,14 @@ function At() {
|
|
|
26
26
|
}
|
|
27
27
|
function gt(e, t) {
|
|
28
28
|
if (e.type === "bearer")
|
|
29
|
-
return `Bearer ${e.token}~${
|
|
29
|
+
return `Bearer ${e.token}~${_e()}`;
|
|
30
30
|
if (e.type === "basic")
|
|
31
|
-
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${
|
|
31
|
+
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${_e()}`;
|
|
32
32
|
if (e.type === "key")
|
|
33
|
-
return `Client-Key ${e.clientKey}.${
|
|
33
|
+
return `Client-Key ${e.clientKey}.${Be(t)}_${_e()}`;
|
|
34
34
|
throw new Error(`Unknown auth type: ${e}`);
|
|
35
35
|
}
|
|
36
|
-
const Pt = 45 * 1e3, bt = "X-Playground-Chat", He = 2e3,
|
|
36
|
+
const Pt = 45 * 1e3, bt = "X-Playground-Chat", He = 2e3, Ee = "https://api.d-id.com", xt = "wss://notifications.d-id.com", Lt = "79f81a83a67430be2bc0fd61042b8faa";
|
|
37
37
|
class q extends Error {
|
|
38
38
|
/**
|
|
39
39
|
* Creates an SDK error. The SDK builds these itself; applications normally only catch them.
|
|
@@ -279,7 +279,7 @@ class R extends q {
|
|
|
279
279
|
this.key = a;
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
class
|
|
282
|
+
class Ot extends q {
|
|
283
283
|
/**
|
|
284
284
|
* Wraps a web socket failure, built from the socket's `error` event.
|
|
285
285
|
* @internal The SDK builds this itself; applications catch the error rather than construct it.
|
|
@@ -292,7 +292,7 @@ class zt extends q {
|
|
|
292
292
|
x(this, "kind", "WSError");
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
const yt = (e) => e.type,
|
|
295
|
+
const yt = (e) => e.type, zt = (e) => e.type === pe.Expressive ? "v4" : e.type === pe.Clip ? "v3-pro" : "v2", Ve = (e) => e === pe.Expressive, Ae = (e) => [L.TextOnly, L.Playground, L.Maintenance].includes(e), te = (e) => e && [L.DirectPlayback, L.Off].includes(e), We = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ft = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
|
|
296
296
|
function Vt(e) {
|
|
297
297
|
const t = e.split("?")[0].split("#")[0].toLowerCase();
|
|
298
298
|
return Ft.some((r) => t.endsWith(r));
|
|
@@ -336,9 +336,9 @@ function wt(e) {
|
|
|
336
336
|
s.index > o && a.push({ type: "text", text: e.slice(o, s.index) }), a.push(s.part), o = s.index + s.length;
|
|
337
337
|
return o < e.length && a.push({ type: "text", text: e.slice(o) }), a;
|
|
338
338
|
}
|
|
339
|
-
let Xe = "",
|
|
339
|
+
let Xe = "", Pe = [];
|
|
340
340
|
function he(e) {
|
|
341
|
-
return e === Xe || (Xe = e,
|
|
341
|
+
return e === Xe || (Xe = e, Pe = wt(e)), Pe;
|
|
342
342
|
}
|
|
343
343
|
function Ut(e, t) {
|
|
344
344
|
let r;
|
|
@@ -349,7 +349,7 @@ function Ut(e, t) {
|
|
|
349
349
|
clear: () => clearTimeout(r)
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
async function
|
|
352
|
+
async function $e(e, t) {
|
|
353
353
|
const r = {
|
|
354
354
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
355
355
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -379,13 +379,13 @@ class Ye {
|
|
|
379
379
|
this.response = t;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
const Jt = (e) =>
|
|
382
|
+
const Jt = (e) => $e(e, {
|
|
383
383
|
limit: 3,
|
|
384
384
|
delayMs: 1e3,
|
|
385
385
|
timeout: 0,
|
|
386
386
|
shouldRetryFn: (t) => t.status === 429
|
|
387
387
|
});
|
|
388
|
-
function vt(e, t =
|
|
388
|
+
function vt(e, t = Ee, r, a) {
|
|
389
389
|
const o = async (s, i) => {
|
|
390
390
|
const { skipErrorHandler: u, ...n } = i || {}, d = n.method ?? "GET", h = performance.now();
|
|
391
391
|
let f;
|
|
@@ -440,7 +440,7 @@ function vt(e, t = Ie, r, a) {
|
|
|
440
440
|
}
|
|
441
441
|
};
|
|
442
442
|
}
|
|
443
|
-
function Ht(e, t =
|
|
443
|
+
function Ht(e, t = Ee, r, a) {
|
|
444
444
|
const o = vt(e, `${t}/agents`, r, a);
|
|
445
445
|
return {
|
|
446
446
|
getRuntimeById(s, i) {
|
|
@@ -490,7 +490,7 @@ function Kt(e) {
|
|
|
490
490
|
var t;
|
|
491
491
|
return {
|
|
492
492
|
agentType: yt(e.avatar),
|
|
493
|
-
presenterType:
|
|
493
|
+
presenterType: zt(e.avatar),
|
|
494
494
|
owner_id: e.owner_id ?? "",
|
|
495
495
|
starterQuestionsCount: (t = e.starter_message) == null ? void 0 : t.length,
|
|
496
496
|
agentId: e.id,
|
|
@@ -503,7 +503,7 @@ const qt = (e) => {
|
|
|
503
503
|
} catch {
|
|
504
504
|
return "Unknown error";
|
|
505
505
|
}
|
|
506
|
-
}, Gt = (e) => e.reduce((t, r) => t + r, 0), Qe = (e) => Gt(e) / e.length, Ze = (e) => Math.min(...e), et = (e) => Math.max(...e),
|
|
506
|
+
}, Gt = (e) => e.reduce((t, r) => t + r, 0), Qe = (e) => Gt(e) / e.length, Ze = (e) => Math.min(...e), et = (e) => Math.max(...e), De = (e, t = 0) => {
|
|
507
507
|
const r = 10 ** t;
|
|
508
508
|
return Math.round(e * r) / r;
|
|
509
509
|
}, Xt = (e, t) => {
|
|
@@ -528,11 +528,11 @@ function tt(e, t, r) {
|
|
|
528
528
|
function nt(e) {
|
|
529
529
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function be(e) {
|
|
532
532
|
return e instanceof q ? e.toJson() : { kind: "UnknownError", message: qt(e) || "UnknownError" };
|
|
533
533
|
}
|
|
534
|
-
const Zt = "3.0.0-staging.
|
|
535
|
-
let
|
|
534
|
+
const Zt = "3.0.0-staging.423", en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", St = 50, Q = [];
|
|
535
|
+
let xe = !1;
|
|
536
536
|
async function Ct(e) {
|
|
537
537
|
const t = await fetch(en, {
|
|
538
538
|
method: "POST",
|
|
@@ -545,28 +545,28 @@ async function Ct(e) {
|
|
|
545
545
|
function tn(e) {
|
|
546
546
|
Q.push(e), Q.splice(St);
|
|
547
547
|
}
|
|
548
|
-
function
|
|
549
|
-
if (
|
|
548
|
+
function Ne() {
|
|
549
|
+
if (xe || !Q.length)
|
|
550
550
|
return;
|
|
551
|
-
|
|
551
|
+
xe = !0;
|
|
552
552
|
const e = Q.splice(0, Q.length);
|
|
553
553
|
Ct(e).catch(() => {
|
|
554
554
|
Q.unshift(...e), Q.splice(St);
|
|
555
555
|
}).finally(() => {
|
|
556
|
-
|
|
556
|
+
xe = !1;
|
|
557
557
|
});
|
|
558
558
|
}
|
|
559
|
-
typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online",
|
|
560
|
-
document.visibilityState === "visible" &&
|
|
559
|
+
typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online", Ne), typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
560
|
+
document.visibilityState === "visible" && Ne();
|
|
561
561
|
}));
|
|
562
562
|
function nn(e) {
|
|
563
563
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
|
|
564
564
|
return {
|
|
565
565
|
token: e.token || "testKey",
|
|
566
|
-
distinct_id:
|
|
566
|
+
distinct_id: Be(e.externalId),
|
|
567
567
|
agentId: e.agentId,
|
|
568
568
|
additionalProperties: {
|
|
569
|
-
id:
|
|
569
|
+
id: Be(e.externalId),
|
|
570
570
|
...e.mixpanelAdditionalProperties || {}
|
|
571
571
|
},
|
|
572
572
|
isEnabled: e.isEnabled ?? !0,
|
|
@@ -595,7 +595,7 @@ function nn(e) {
|
|
|
595
595
|
"User Agent": navigator.userAgent
|
|
596
596
|
}
|
|
597
597
|
};
|
|
598
|
-
return
|
|
598
|
+
return Ne(), Ct([d]).catch(() => tn(d)), Promise.resolve();
|
|
599
599
|
},
|
|
600
600
|
linkTrack(a, o, s, i) {
|
|
601
601
|
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), i.includes(s) || i.push(s);
|
|
@@ -613,7 +613,7 @@ function nn(e) {
|
|
|
613
613
|
}
|
|
614
614
|
};
|
|
615
615
|
}
|
|
616
|
-
function
|
|
616
|
+
function Ue() {
|
|
617
617
|
let e = 0;
|
|
618
618
|
return {
|
|
619
619
|
reset: () => e = 0,
|
|
@@ -621,7 +621,7 @@ function Ve() {
|
|
|
621
621
|
get: (t = !1) => t ? Date.now() - e : e
|
|
622
622
|
};
|
|
623
623
|
}
|
|
624
|
-
const K =
|
|
624
|
+
const K = Ue(), Oe = Ue(), rt = Ue();
|
|
625
625
|
function Mt(e) {
|
|
626
626
|
return e === L.Playground ? { headers: { [bt]: "true" } } : {};
|
|
627
627
|
}
|
|
@@ -668,7 +668,7 @@ async function on(e, t, r, a) {
|
|
|
668
668
|
callbacks: {
|
|
669
669
|
onError: (i) => {
|
|
670
670
|
var u;
|
|
671
|
-
return (u = r.onError) == null ? void 0 : u.call(r, new
|
|
671
|
+
return (u = r.onError) == null ? void 0 : u.call(r, new Ot(i));
|
|
672
672
|
},
|
|
673
673
|
onMessage(i) {
|
|
674
674
|
const u = JSON.parse(i.data);
|
|
@@ -859,10 +859,10 @@ function yn(e) {
|
|
|
859
859
|
), i = t.filter((n) => n.localTs - r >= Math.min(5e3, a / 2)), u = (i.length ? i : t).map((n) => n.audioPlayout - n.videoPlayout);
|
|
860
860
|
return {
|
|
861
861
|
sampleCount: t.length,
|
|
862
|
-
durationMs:
|
|
863
|
-
desyncDurationMs:
|
|
864
|
-
maxOffsetMs:
|
|
865
|
-
residualOffsetMs:
|
|
862
|
+
durationMs: De(a),
|
|
863
|
+
desyncDurationMs: De(a * (s.length / o.length)),
|
|
864
|
+
maxOffsetMs: De(o.reduce((n, d) => Math.abs(d) > Math.abs(n) ? d : n)),
|
|
865
|
+
residualOffsetMs: De(Yt(u))
|
|
866
866
|
};
|
|
867
867
|
}
|
|
868
868
|
function wn(e, t, r) {
|
|
@@ -1054,7 +1054,7 @@ function Wn(e, t) {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
};
|
|
1056
1056
|
}
|
|
1057
|
-
const
|
|
1057
|
+
const Re = 100, Cn = Math.max(Math.ceil(400 / Re), 1), Mn = 0.25, Dn = 0.28;
|
|
1058
1058
|
function Rn() {
|
|
1059
1059
|
let e = 0, t, r, a = 0;
|
|
1060
1060
|
return (o) => {
|
|
@@ -1082,18 +1082,18 @@ function In(e, t, r, a, o) {
|
|
|
1082
1082
|
if (P)
|
|
1083
1083
|
n = 0, g = j - l, f = U < Mn ? me.Strong : U > Dn && g > 1 ? me.Weak : h, f !== h && (o == null || o(f), h = f, l += g, g = 0), d || (a == null || a(C.Start), u = i[i.length - 1], i = [], d = !0), i.push(ne);
|
|
1084
1084
|
else if (d && (n++, n >= Cn)) {
|
|
1085
|
-
const re = st(i,
|
|
1085
|
+
const re = st(i, Re, u);
|
|
1086
1086
|
a == null || a(C.Stop, re ?? void 0), t() || r(), l = j, d = !1;
|
|
1087
1087
|
}
|
|
1088
1088
|
}
|
|
1089
1089
|
return {
|
|
1090
1090
|
start: () => {
|
|
1091
|
-
s || (s = setInterval(D,
|
|
1091
|
+
s || (s = setInterval(D, Re));
|
|
1092
1092
|
},
|
|
1093
1093
|
stop: () => {
|
|
1094
1094
|
s && (clearInterval(s), s = null);
|
|
1095
1095
|
},
|
|
1096
|
-
getReport: () => st(i,
|
|
1096
|
+
getReport: () => st(i, Re, u)
|
|
1097
1097
|
};
|
|
1098
1098
|
}
|
|
1099
1099
|
const En = () => {
|
|
@@ -1168,7 +1168,7 @@ function ct({
|
|
|
1168
1168
|
log: i
|
|
1169
1169
|
});
|
|
1170
1170
|
}
|
|
1171
|
-
async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s =
|
|
1171
|
+
async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ee, analytics: i }, u) {
|
|
1172
1172
|
var le;
|
|
1173
1173
|
const n = hn(r, "WebRTCStreamingManager"), d = Tn(n);
|
|
1174
1174
|
let h = !1, f = !1, g = C.Stop, l = C.Stop;
|
|
@@ -1341,7 +1341,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ie,
|
|
|
1341
1341
|
videoId: V,
|
|
1342
1342
|
timestamp: Date.now()
|
|
1343
1343
|
};
|
|
1344
|
-
return ue(
|
|
1344
|
+
return ue(Ie.Interrupt, JSON.stringify(v)), !0;
|
|
1345
1345
|
}
|
|
1346
1346
|
};
|
|
1347
1347
|
}
|
|
@@ -1356,8 +1356,8 @@ async function Pn(e, t, r, a) {
|
|
|
1356
1356
|
case "v2": {
|
|
1357
1357
|
const { version: s, ...i } = t;
|
|
1358
1358
|
switch (i.transport.provider) {
|
|
1359
|
-
case
|
|
1360
|
-
const { createLiveKitStreamingManager: u } = await import("./livekit-manager-
|
|
1359
|
+
case Fe.Livekit:
|
|
1360
|
+
const { createLiveKitStreamingManager: u } = await import("./livekit-manager-BCxu61o7.js");
|
|
1361
1361
|
return u(o, i, r);
|
|
1362
1362
|
default:
|
|
1363
1363
|
throw new Error(`Unsupported transport provider: ${i.transport.provider}`);
|
|
@@ -1371,7 +1371,7 @@ const bn = "cht";
|
|
|
1371
1371
|
function xn(e) {
|
|
1372
1372
|
return {
|
|
1373
1373
|
transport: {
|
|
1374
|
-
provider:
|
|
1374
|
+
provider: Fe.Livekit
|
|
1375
1375
|
},
|
|
1376
1376
|
...(e == null ? void 0 : e.persistentChat) !== void 0 && { chat_persist: e.persistentChat }
|
|
1377
1377
|
};
|
|
@@ -1389,13 +1389,13 @@ function Ln(e) {
|
|
|
1389
1389
|
}, ...r && { end_user_data: r } };
|
|
1390
1390
|
}
|
|
1391
1391
|
function jn(e, t) {
|
|
1392
|
-
return
|
|
1392
|
+
return Ve(e.avatar.type) ? { version: ze.V2, ...xn(t) } : { version: ze.V1, ...Ln(t) };
|
|
1393
1393
|
}
|
|
1394
1394
|
function Bn(e, t, r) {
|
|
1395
1395
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1396
1396
|
}
|
|
1397
1397
|
function $n(e, t, r, a, o) {
|
|
1398
|
-
o === H.Fluent ? Nn(e, t, r, a, o) :
|
|
1398
|
+
o === H.Fluent ? Nn(e, t, r, a, o) : On(e, t, r, a, o);
|
|
1399
1399
|
}
|
|
1400
1400
|
function Nn(e, t, r, a, o) {
|
|
1401
1401
|
e === C.Start ? a.track("stream-session", { event: "start", "stream-type": o }) : e === C.Stop && a.track("stream-session", {
|
|
@@ -1417,7 +1417,7 @@ function dt(e, t, r, a, o) {
|
|
|
1417
1417
|
[T.StreamVideoDone]
|
|
1418
1418
|
);
|
|
1419
1419
|
}
|
|
1420
|
-
function
|
|
1420
|
+
function On(e, t, r, a, o) {
|
|
1421
1421
|
e === C.Start ? a.linkTrack(
|
|
1422
1422
|
"agent-video",
|
|
1423
1423
|
{ event: "start", latency: K.get(!0), "stream-type": o },
|
|
@@ -1434,19 +1434,19 @@ function zn(e, t, r, a, o) {
|
|
|
1434
1434
|
[T.StreamVideoDone]
|
|
1435
1435
|
);
|
|
1436
1436
|
}
|
|
1437
|
-
function
|
|
1437
|
+
function zn(e, t, r) {
|
|
1438
1438
|
const a = {
|
|
1439
1439
|
call_id: t.callId,
|
|
1440
1440
|
name: t.name
|
|
1441
1441
|
};
|
|
1442
|
-
if (e ===
|
|
1442
|
+
if (e === je.Started) {
|
|
1443
1443
|
r.track("agent-tool-call", { ...a, event: "started" });
|
|
1444
1444
|
return;
|
|
1445
1445
|
}
|
|
1446
1446
|
const o = t;
|
|
1447
1447
|
r.track("agent-tool-call", {
|
|
1448
1448
|
...a,
|
|
1449
|
-
event: e ===
|
|
1449
|
+
event: e === je.Done ? "done" : "error",
|
|
1450
1450
|
duration_ms: o.durationMs,
|
|
1451
1451
|
extra_keys: o.extra ? Object.keys(o.extra).length : 0
|
|
1452
1452
|
});
|
|
@@ -1485,7 +1485,7 @@ function ut(e, t, r, a) {
|
|
|
1485
1485
|
},
|
|
1486
1486
|
onAgentActivityStateChange: (f) => {
|
|
1487
1487
|
var g, l;
|
|
1488
|
-
(l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f === ye.Talking ? (
|
|
1488
|
+
(l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f === ye.Talking ? (Oe.update(), d = (p) => {
|
|
1489
1489
|
dt(
|
|
1490
1490
|
C.Start,
|
|
1491
1491
|
e,
|
|
@@ -1493,7 +1493,7 @@ function ut(e, t, r, a) {
|
|
|
1493
1493
|
i.streamType,
|
|
1494
1494
|
p
|
|
1495
1495
|
), d = null;
|
|
1496
|
-
}, h || d({ latency: K.get(!0) })) : (
|
|
1496
|
+
}, h || d({ latency: K.get(!0) })) : (Oe.reset(), d = null, dt(
|
|
1497
1497
|
C.Stop,
|
|
1498
1498
|
e,
|
|
1499
1499
|
r,
|
|
@@ -1509,7 +1509,7 @@ function ut(e, t, r, a) {
|
|
|
1509
1509
|
},
|
|
1510
1510
|
onToolEvent: ((f, g) => {
|
|
1511
1511
|
var l, p;
|
|
1512
|
-
(p = (l = t.callbacks).onToolEvent) == null || p.call(l, f, g),
|
|
1512
|
+
(p = (l = t.callbacks).onToolEvent) == null || p.call(l, f, g), zn(f, g, r);
|
|
1513
1513
|
})
|
|
1514
1514
|
}
|
|
1515
1515
|
},
|
|
@@ -1523,7 +1523,7 @@ function ut(e, t, r, a) {
|
|
|
1523
1523
|
async function Fn(e, t, r, a, o) {
|
|
1524
1524
|
var h, f;
|
|
1525
1525
|
const s = async () => {
|
|
1526
|
-
if (
|
|
1526
|
+
if (Ve(e.avatar.type)) {
|
|
1527
1527
|
const g = await ut(e, t, a), l = `${bn}_${g.sessionId}`, p = (/* @__PURE__ */ new Date()).toISOString();
|
|
1528
1528
|
return { chatResult: {
|
|
1529
1529
|
chatMode: L.Functional,
|
|
@@ -1560,13 +1560,13 @@ async function Fn(e, t, r, a, o) {
|
|
|
1560
1560
|
}, { chatResult: i, streamingManager: u } = await s(), { chat: n, chatMode: d } = i;
|
|
1561
1561
|
return d && t.mode !== void 0 && d !== t.mode && d !== L.Functional ? ((f = (h = t.callbacks).onError) == null || f.call(h, new Bt(d)), u == null || u.disconnect(), { chat: n }) : { chat: n, streamingManager: u };
|
|
1562
1562
|
}
|
|
1563
|
-
const
|
|
1563
|
+
const Le = "ChatMode.Off and ChatMode.DirectPlayback are not supported for Expressive agents", lt = "callbacks.onSrcObjectReady is required in every chat mode that streams video; it is optional only in ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance", Vn = [I.Disconnected, I.Closed, I.Fail];
|
|
1564
1564
|
async function Kn(e, t) {
|
|
1565
1565
|
var de, ue, le, w, v;
|
|
1566
1566
|
const r = { ...t.callbacks };
|
|
1567
1567
|
let a = !0;
|
|
1568
|
-
const o = ((de = t.analytics) == null ? void 0 : de.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL ||
|
|
1569
|
-
if (!r.onSrcObjectReady && !
|
|
1568
|
+
const o = ((de = t.analytics) == null ? void 0 : de.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL || Ee, u = t.mode || L.Functional;
|
|
1569
|
+
if (!r.onSrcObjectReady && !Ae(u))
|
|
1570
1570
|
throw new R(lt);
|
|
1571
1571
|
const n = {
|
|
1572
1572
|
messages: [],
|
|
@@ -1586,7 +1586,7 @@ async function Kn(e, t) {
|
|
|
1586
1586
|
...r,
|
|
1587
1587
|
onError(c, m) {
|
|
1588
1588
|
var y;
|
|
1589
|
-
d.track("agent-error", { error:
|
|
1589
|
+
d.track("agent-error", { error: be(c) }), (y = r.onError) == null || y.call(r, c, m);
|
|
1590
1590
|
},
|
|
1591
1591
|
onConnectionStateChange(c, m) {
|
|
1592
1592
|
var y;
|
|
@@ -1598,10 +1598,10 @@ async function Kn(e, t) {
|
|
|
1598
1598
|
}
|
|
1599
1599
|
}, p = { ...t, callbacks: l }, D = Ht(p.auth, i, l.onError, p.externalId), S = await D.getRuntimeById(e);
|
|
1600
1600
|
p.debug = p.debug || ((w = S == null ? void 0 : S.advanced_settings) == null ? void 0 : w.ui_debug_mode);
|
|
1601
|
-
const P =
|
|
1601
|
+
const P = Ve(S.avatar.type);
|
|
1602
1602
|
if (P && te(u))
|
|
1603
|
-
throw new R(
|
|
1604
|
-
P && import("./livekit-manager-
|
|
1603
|
+
throw new R(Le);
|
|
1604
|
+
P && import("./livekit-manager-BCxu61o7.js").then(({ preloadLiveKit: c }) => c()).catch(() => {
|
|
1605
1605
|
}), d.enrich(Kt(S));
|
|
1606
1606
|
const { onMessage: U, clearQueue: j } = mn(d, n, p, S, (c) => {
|
|
1607
1607
|
var m, y;
|
|
@@ -1609,17 +1609,17 @@ async function Kn(e, t) {
|
|
|
1609
1609
|
});
|
|
1610
1610
|
n.messages = rn(p.initialMessages), n.messages.length && ((v = l.onNewMessage) == null || v.call(l, [...n.messages], "answer"));
|
|
1611
1611
|
const ne = (c) => d.enrich({ videoId: c }), re = (c) => {
|
|
1612
|
-
var
|
|
1612
|
+
var O;
|
|
1613
1613
|
const m = (c == null ? void 0 : c.type) ?? "click", y = n.streamingManager;
|
|
1614
1614
|
if (!(y != null && y.interruptAvailable) || !y.isInterruptible || !y.interrupt(m))
|
|
1615
1615
|
return;
|
|
1616
1616
|
d.track("agent-video-interrupt", {
|
|
1617
1617
|
type: m,
|
|
1618
|
-
video_duration_to_interrupt:
|
|
1618
|
+
video_duration_to_interrupt: Oe.get(!0),
|
|
1619
1619
|
message_duration_to_interrupt: K.get(!0)
|
|
1620
1620
|
});
|
|
1621
1621
|
const E = n.messages[n.messages.length - 1];
|
|
1622
|
-
E && (E.interrupted = !0, (
|
|
1622
|
+
E && (E.interrupted = !0, (O = l.onNewMessage) == null || O.call(l, [...n.messages], "answer"));
|
|
1623
1623
|
}, N = /* @__PURE__ */ new Map();
|
|
1624
1624
|
function ee(c) {
|
|
1625
1625
|
return async (m) => {
|
|
@@ -1660,16 +1660,16 @@ async function Kn(e, t) {
|
|
|
1660
1660
|
return B || ve(() => Y(c));
|
|
1661
1661
|
}
|
|
1662
1662
|
async function Y(c) {
|
|
1663
|
-
var J,
|
|
1663
|
+
var J, Te, ke, $;
|
|
1664
1664
|
if (X)
|
|
1665
1665
|
return;
|
|
1666
|
-
n.streamingManager && await V(), At(), (J = l.onConnectionStateChange) == null || J.call(l, I.Connecting), K.reset(), c && !a && (delete n.chat, (
|
|
1666
|
+
n.streamingManager && await V(), At(), (J = l.onConnectionStateChange) == null || J.call(l, I.Connecting), K.reset(), c && !a && (delete n.chat, (Te = l.onNewMessage) == null || Te.call(l, [...n.messages], "answer"));
|
|
1667
1667
|
const m = se(n.chatMode) ? on(
|
|
1668
1668
|
p.auth,
|
|
1669
1669
|
s,
|
|
1670
1670
|
{ onMessage: U, onError: l.onError },
|
|
1671
1671
|
p.externalId
|
|
1672
|
-
) : Promise.resolve(void 0), y =
|
|
1672
|
+
) : Promise.resolve(void 0), y = $e(
|
|
1673
1673
|
() => Fn(
|
|
1674
1674
|
S,
|
|
1675
1675
|
{
|
|
@@ -1680,7 +1680,7 @@ async function Kn(e, t) {
|
|
|
1680
1680
|
onVideoIdChange: ne,
|
|
1681
1681
|
onMessage: U
|
|
1682
1682
|
},
|
|
1683
|
-
rpcMethods: new Map([...N.keys()].map((
|
|
1683
|
+
rpcMethods: new Map([...N.keys()].map((z) => [z, ee(z)]))
|
|
1684
1684
|
},
|
|
1685
1685
|
D,
|
|
1686
1686
|
d,
|
|
@@ -1690,26 +1690,26 @@ async function Kn(e, t) {
|
|
|
1690
1690
|
limit: 3,
|
|
1691
1691
|
timeout: Pt,
|
|
1692
1692
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1693
|
-
shouldRetryFn: (
|
|
1693
|
+
shouldRetryFn: (z) => !(z instanceof ht && (z.status === 429 || z.code === "InsufficientCreditsError")),
|
|
1694
1694
|
delayMs: 1e3
|
|
1695
1695
|
}
|
|
1696
|
-
).catch(async (
|
|
1696
|
+
).catch(async (z) => {
|
|
1697
1697
|
var Ce;
|
|
1698
1698
|
throw m.then((W) => W == null ? void 0 : W.disconnect()).catch(() => {
|
|
1699
|
-
}), await oe(L.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, I.Fail),
|
|
1700
|
-
}), M = (
|
|
1701
|
-
if (_ && b && (($ = l.onNewChat) == null || $.call(l, _.id)), n.streamingManager =
|
|
1699
|
+
}), await oe(L.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, I.Fail), z;
|
|
1700
|
+
}), M = (ke = n.chat) == null ? void 0 : ke.id, [E, { streamingManager: O, chat: _ }] = await Promise.all([m, y]), b = !!_ && _.id !== M;
|
|
1701
|
+
if (_ && b && (($ = l.onNewChat) == null || $.call(l, _.id)), n.streamingManager = O, n.socketManager = E, n.chat = _, X) {
|
|
1702
1702
|
await V();
|
|
1703
1703
|
return;
|
|
1704
1704
|
}
|
|
1705
1705
|
we(), a = !1, d.enrich({
|
|
1706
1706
|
chatId: _ == null ? void 0 : _.id,
|
|
1707
|
-
streamId:
|
|
1707
|
+
streamId: O == null ? void 0 : O.streamId,
|
|
1708
1708
|
mode: n.chatMode
|
|
1709
1709
|
});
|
|
1710
1710
|
const A = (b ? _ == null ? void 0 : _.chat_mode : void 0) ?? n.chatMode;
|
|
1711
1711
|
if (P && te(A)) {
|
|
1712
|
-
console.warn(`[AgentManager] Ignoring chat mode "${A}": ${
|
|
1712
|
+
console.warn(`[AgentManager] Ignoring chat mode "${A}": ${Le}`);
|
|
1713
1713
|
return;
|
|
1714
1714
|
}
|
|
1715
1715
|
await oe(A);
|
|
@@ -1735,7 +1735,7 @@ async function Kn(e, t) {
|
|
|
1735
1735
|
}
|
|
1736
1736
|
async function ce(c) {
|
|
1737
1737
|
if (P && te(c))
|
|
1738
|
-
throw new R(
|
|
1738
|
+
throw new R(Le);
|
|
1739
1739
|
await oe(c);
|
|
1740
1740
|
}
|
|
1741
1741
|
return {
|
|
@@ -1758,7 +1758,7 @@ async function Kn(e, t) {
|
|
|
1758
1758
|
changeMode: ce,
|
|
1759
1759
|
enrichAnalytics: (c) => d.enrich(c),
|
|
1760
1760
|
async connect() {
|
|
1761
|
-
if (!l.onSrcObjectReady && !
|
|
1761
|
+
if (!l.onSrcObjectReady && !Ae(n.chatMode))
|
|
1762
1762
|
throw new R(lt);
|
|
1763
1763
|
if (B)
|
|
1764
1764
|
return X = !1, B;
|
|
@@ -1779,7 +1779,7 @@ async function Kn(e, t) {
|
|
|
1779
1779
|
try {
|
|
1780
1780
|
await c.reconnect();
|
|
1781
1781
|
} catch (y) {
|
|
1782
|
-
const M =
|
|
1782
|
+
const M = be(y);
|
|
1783
1783
|
m = M.code ?? M.kind, await V(), await Y(!1);
|
|
1784
1784
|
}
|
|
1785
1785
|
else
|
|
@@ -1812,7 +1812,7 @@ async function Kn(e, t) {
|
|
|
1812
1812
|
return !P || !n.streamingManager ? Promise.reject(
|
|
1813
1813
|
new R("setSttLanguage is only available on Expressive (V4) agents, after connect()")
|
|
1814
1814
|
) : (d.track("agent-stt-language-change", { language: c }), n.streamingManager.sendDataChannelMessage(
|
|
1815
|
-
|
|
1815
|
+
Ie.SttLanguage,
|
|
1816
1816
|
JSON.stringify({ language: c })
|
|
1817
1817
|
));
|
|
1818
1818
|
},
|
|
@@ -1848,7 +1848,7 @@ async function Kn(e, t) {
|
|
|
1848
1848
|
return (c = n.streamingManager) != null && c.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
|
|
1849
1849
|
},
|
|
1850
1850
|
async chat(c) {
|
|
1851
|
-
var E,
|
|
1851
|
+
var E, O, _;
|
|
1852
1852
|
const m = () => {
|
|
1853
1853
|
if (te(n.chatMode))
|
|
1854
1854
|
throw new R(`${n.chatMode} is enabled, chat is disabled`);
|
|
@@ -1881,22 +1881,26 @@ async function Kn(e, t) {
|
|
|
1881
1881
|
return n.chat.id;
|
|
1882
1882
|
}, M = async (b, A) => {
|
|
1883
1883
|
const J = n.chatMode === L.Playground;
|
|
1884
|
-
return
|
|
1884
|
+
return $e(P && !J ? async () => {
|
|
1885
1885
|
var $;
|
|
1886
1886
|
return await (($ = n.streamingManager) == null ? void 0 : $.sendDataChannelMessage(
|
|
1887
|
-
|
|
1887
|
+
Ie.Chat,
|
|
1888
1888
|
c
|
|
1889
1889
|
)), Promise.resolve({});
|
|
1890
1890
|
} : async () => {
|
|
1891
|
-
var $,
|
|
1891
|
+
var $, z;
|
|
1892
1892
|
return D.chat(
|
|
1893
1893
|
S.id,
|
|
1894
1894
|
A,
|
|
1895
1895
|
{
|
|
1896
1896
|
chatMode: n.chatMode,
|
|
1897
1897
|
streamId: ($ = n.streamingManager) == null ? void 0 : $.streamId,
|
|
1898
|
-
sessionId: (
|
|
1899
|
-
messages: b.map(({ matches: Ce,
|
|
1898
|
+
sessionId: (z = n.streamingManager) == null ? void 0 : z.sessionId,
|
|
1899
|
+
messages: b.map(({ matches: Ce, createdAt: W, ...Me }) => ({
|
|
1900
|
+
...Me,
|
|
1901
|
+
// A restored `initialMessages` row may carry no timestamp; the API requires one.
|
|
1902
|
+
created_at: W ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1903
|
+
}))
|
|
1900
1904
|
},
|
|
1901
1905
|
{
|
|
1902
1906
|
...Mt(n.chatMode),
|
|
@@ -1906,9 +1910,9 @@ async function Kn(e, t) {
|
|
|
1906
1910
|
}, {
|
|
1907
1911
|
limit: 2,
|
|
1908
1912
|
shouldRetryFn: ($) => {
|
|
1909
|
-
var W,
|
|
1910
|
-
const
|
|
1911
|
-
return !((
|
|
1913
|
+
var W, Me, Je;
|
|
1914
|
+
const z = (W = $ == null ? void 0 : $.message) == null ? void 0 : W.includes("missing or invalid session_id");
|
|
1915
|
+
return !((Me = $ == null ? void 0 : $.message) == null ? void 0 : Me.includes("Stream Error")) && !z ? ((Je = l.onError) == null || Je.call(l, $), !1) : !0;
|
|
1912
1916
|
},
|
|
1913
1917
|
onRetry: async () => {
|
|
1914
1918
|
await V(), await ie(!1);
|
|
@@ -1935,7 +1939,7 @@ async function Kn(e, t) {
|
|
|
1935
1939
|
}), d.track("agent-message-send", {
|
|
1936
1940
|
event: "success",
|
|
1937
1941
|
messages: n.messages.length + 1
|
|
1938
|
-
}), A.result && ((
|
|
1942
|
+
}), A.result && ((O = l.onNewMessage) == null || O.call(l, [...n.messages], "answer"), d.track("agent-message-received", {
|
|
1939
1943
|
latency: K.get(!0),
|
|
1940
1944
|
messages: n.messages.length
|
|
1941
1945
|
})), A;
|
|
@@ -1943,18 +1947,18 @@ async function Kn(e, t) {
|
|
|
1943
1947
|
throw ((_ = n.messages[n.messages.length - 1]) == null ? void 0 : _.role) === "assistant" && n.messages.pop(), d.track("agent-message-send", {
|
|
1944
1948
|
event: "error",
|
|
1945
1949
|
messages: n.messages.length,
|
|
1946
|
-
error:
|
|
1950
|
+
error: be(b)
|
|
1947
1951
|
}), b;
|
|
1948
1952
|
}
|
|
1949
1953
|
},
|
|
1950
1954
|
async rate(c, m, y) {
|
|
1951
|
-
var
|
|
1955
|
+
var O, _, b, A;
|
|
1952
1956
|
const M = n.messages.find((J) => J.id === c);
|
|
1953
1957
|
if (n.chat) {
|
|
1954
1958
|
if (!M)
|
|
1955
1959
|
throw new R("Message not found");
|
|
1956
1960
|
} else throw new R("Chat is not initialized");
|
|
1957
|
-
const E = ((
|
|
1961
|
+
const E = ((O = M.matches) == null ? void 0 : O.map((J) => [J.document_id, J.id])) ?? [];
|
|
1958
1962
|
return d.track("agent-rate", {
|
|
1959
1963
|
event: y ? "update" : "create",
|
|
1960
1964
|
thumb: m === 1 ? "up" : "down",
|
|
@@ -1998,7 +2002,7 @@ async function Kn(e, t) {
|
|
|
1998
2002
|
sentiment: c.sentiment
|
|
1999
2003
|
} : c;
|
|
2000
2004
|
}
|
|
2001
|
-
const y =
|
|
2005
|
+
const y = Ae(n.chatMode);
|
|
2002
2006
|
if (!y && !n.streamingManager)
|
|
2003
2007
|
throw new R("Please connect to the agent first");
|
|
2004
2008
|
const M = m();
|
|
@@ -2029,17 +2033,17 @@ export {
|
|
|
2029
2033
|
F as C,
|
|
2030
2034
|
Tt as D,
|
|
2031
2035
|
ht as H,
|
|
2032
|
-
|
|
2036
|
+
Ie as I,
|
|
2033
2037
|
Nt as N,
|
|
2034
2038
|
kt as P,
|
|
2035
2039
|
T as S,
|
|
2036
|
-
|
|
2040
|
+
je as T,
|
|
2037
2041
|
R as V,
|
|
2038
|
-
|
|
2042
|
+
Ot as W,
|
|
2039
2043
|
hn as a,
|
|
2040
2044
|
H as b,
|
|
2041
2045
|
vt as c,
|
|
2042
|
-
|
|
2046
|
+
Ee as d,
|
|
2043
2047
|
pt as e,
|
|
2044
2048
|
I as f,
|
|
2045
2049
|
me as g,
|
|
@@ -2055,9 +2059,9 @@ export {
|
|
|
2055
2059
|
ge as q,
|
|
2056
2060
|
_t as r,
|
|
2057
2061
|
Kn as s,
|
|
2058
|
-
|
|
2062
|
+
be as t,
|
|
2059
2063
|
qn as u,
|
|
2060
2064
|
Hn as v,
|
|
2061
2065
|
wt as w
|
|
2062
2066
|
};
|
|
2063
|
-
//# sourceMappingURL=index-
|
|
2067
|
+
//# sourceMappingURL=index-WHsoBMGg.js.map
|