@d-id/client-sdk 3.0.5-staging.440 → 3.0.6-staging.442
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-DpJtiBF-.js → index-B6ILepDc.js} +156 -155
- package/dist/index-B6ILepDc.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-DqUJXeku.js → livekit-manager-D4bHd2x6.js} +2 -2
- package/dist/{livekit-manager-DqUJXeku.js.map → livekit-manager-D4bHd2x6.js.map} +1 -1
- package/package.json +1 -1
- package/dist/index-DpJtiBF-.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var Rt = Object.defineProperty;
|
|
2
2
|
var Et = (e, t, r) => t in e ? Rt(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 Re = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Re || {}), 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 || {}), ne = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e.Image = "image", e))(ne || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ge = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ge || {}),
|
|
4
|
+
var Re = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Re || {}), 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 || {}), ne = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e.Image = "image", e))(ne || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ge = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ge || {}), ye = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ye || {}), k = /* @__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))(k || {}), $e = /* @__PURE__ */ ((e) => (e.Started = "tool-call/started", e.Done = "tool-call/done", e.Error = "tool-call/error", e))($e || {}), kt = /* @__PURE__ */ ((e) => (e.Presentation = "did.presentation", e))(kt || {}), R = /* @__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))(R || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), he = /* @__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))(he || {}), Ue = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ue || {}), Tt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Elevenlabs = "elevenlabs", e.Cartesia = "cartesia", e))(Tt || {}), _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
|
}, mt = (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 Ne(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 $e(e) {
|
|
|
18
18
|
return t;
|
|
19
19
|
}
|
|
20
20
|
let gt;
|
|
21
|
-
function
|
|
21
|
+
function Pe() {
|
|
22
22
|
return gt ?? (gt = Z());
|
|
23
23
|
}
|
|
24
24
|
function At() {
|
|
@@ -26,14 +26,14 @@ function At() {
|
|
|
26
26
|
}
|
|
27
27
|
function ht(e, t) {
|
|
28
28
|
if (e.type === "bearer")
|
|
29
|
-
return `Bearer ${e.token}~${
|
|
29
|
+
return `Bearer ${e.token}~${Pe()}`;
|
|
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}`)}~${Pe()}`;
|
|
32
32
|
if (e.type === "key")
|
|
33
|
-
return `Client-Key ${e.clientKey}.${
|
|
33
|
+
return `Client-Key ${e.clientKey}.${Ne(t)}_${Pe()}`;
|
|
34
34
|
throw new Error(`Unknown auth type: ${e}`);
|
|
35
35
|
}
|
|
36
|
-
const Pt = 45 * 1e3, bt = "X-Playground-Chat", We = 2e3,
|
|
36
|
+
const Pt = 45 * 1e3, bt = "X-Playground-Chat", We = 2e3, Te = "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.
|
|
@@ -125,7 +125,7 @@ function $t(e) {
|
|
|
125
125
|
} catch {
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
class
|
|
128
|
+
class Oe extends q {
|
|
129
129
|
/**
|
|
130
130
|
* Builds the error from the failing response.
|
|
131
131
|
* @internal The SDK builds this itself; applications catch the error rather than construct it.
|
|
@@ -292,13 +292,13 @@ class Ot extends q {
|
|
|
292
292
|
x(this, "kind", "WSError");
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
const
|
|
295
|
+
const yt = (e) => e.type, zt = (e) => e.type === ne.Expressive ? "v4" : e.type === ne.Clip ? "v3-pro" : e.type === ne.Image ? "image" : "v2", Ee = (e) => e === ne.Expressive || e === ne.Image, be = (e) => [L.TextOnly, L.Playground, L.Maintenance].includes(e), te = (e) => e && [L.DirectPlayback, L.Off].includes(e), Ke = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, qe = /!\[([^\[\]]*)\]\(([^)\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));
|
|
299
299
|
}
|
|
300
300
|
const Ge = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Xe = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
301
|
-
function
|
|
301
|
+
function wt(e) {
|
|
302
302
|
if (e.length === 0)
|
|
303
303
|
return [];
|
|
304
304
|
const t = [];
|
|
@@ -336,9 +336,9 @@ function yt(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 Ye = "",
|
|
339
|
+
let Ye = "", xe = [];
|
|
340
340
|
function pe(e) {
|
|
341
|
-
return e === Ye || (Ye = e,
|
|
341
|
+
return e === Ye || (Ye = e, xe = wt(e)), xe;
|
|
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 ze(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 Qe {
|
|
|
379
379
|
this.response = t;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
const Jt = (e) =>
|
|
382
|
+
const Jt = (e) => ze(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 = Te, 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;
|
|
@@ -420,7 +420,7 @@ function vt(e, t = ke, r, a) {
|
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
if (!f.ok) {
|
|
423
|
-
const g = await f.text().catch(() => `Failed to fetch with status ${f.status}`), l = new
|
|
423
|
+
const g = await f.text().catch(() => `Failed to fetch with status ${f.status}`), l = new Oe(f.status, g, { endpoint: s, method: d });
|
|
424
424
|
throw u || r == null || r(l, { endpoint: s, method: d }), l;
|
|
425
425
|
}
|
|
426
426
|
return f.json();
|
|
@@ -440,7 +440,7 @@ function vt(e, t = ke, r, a) {
|
|
|
440
440
|
}
|
|
441
441
|
};
|
|
442
442
|
}
|
|
443
|
-
function Ht(e, t =
|
|
443
|
+
function Ht(e, t = Te, r, a) {
|
|
444
444
|
const o = vt(e, `${t}/agents`, r, a);
|
|
445
445
|
return {
|
|
446
446
|
getRuntimeById(s, i) {
|
|
@@ -480,7 +480,7 @@ function Wt(e) {
|
|
|
480
480
|
isMobile: `${t() == "Mobile"}`,
|
|
481
481
|
browser: navigator.userAgent,
|
|
482
482
|
origin: window.location.origin,
|
|
483
|
-
agentType:
|
|
483
|
+
agentType: yt(a),
|
|
484
484
|
agentVoice: {
|
|
485
485
|
language: (s = (o = e.avatar) == null ? void 0 : o.voice) == null ? void 0 : s.language
|
|
486
486
|
}
|
|
@@ -489,7 +489,7 @@ function Wt(e) {
|
|
|
489
489
|
function Kt(e) {
|
|
490
490
|
var t;
|
|
491
491
|
return {
|
|
492
|
-
agentType:
|
|
492
|
+
agentType: yt(e.avatar),
|
|
493
493
|
presenterType: zt(e.avatar),
|
|
494
494
|
owner_id: e.owner_id ?? "",
|
|
495
495
|
starterQuestionsCount: (t = e.starter_message) == null ? void 0 : t.length,
|
|
@@ -528,11 +528,11 @@ function nt(e, t, r) {
|
|
|
528
528
|
function rt(e) {
|
|
529
529
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function Le(e) {
|
|
532
532
|
return e instanceof q ? e.toJson() : { kind: "UnknownError", message: qt(e) || "UnknownError" };
|
|
533
533
|
}
|
|
534
|
-
const Zt = "3.0.
|
|
535
|
-
let
|
|
534
|
+
const Zt = "3.0.6-staging.442", en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", St = 50, Q = [];
|
|
535
|
+
let je = !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 Fe() {
|
|
549
|
+
if (je || !Q.length)
|
|
550
550
|
return;
|
|
551
|
-
|
|
551
|
+
je = !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
|
+
je = !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", Fe), typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
560
|
+
document.visibilityState === "visible" && Fe();
|
|
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: Ne(e.externalId),
|
|
567
567
|
agentId: e.agentId,
|
|
568
568
|
additionalProperties: {
|
|
569
|
-
id:
|
|
569
|
+
id: Ne(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 Fe(), 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);
|
|
@@ -621,7 +621,7 @@ function Je() {
|
|
|
621
621
|
get: (t = !1) => t ? Date.now() - e : e
|
|
622
622
|
};
|
|
623
623
|
}
|
|
624
|
-
const K = Je(),
|
|
624
|
+
const K = Je(), Ve = Je(), at = Je();
|
|
625
625
|
function Mt(e) {
|
|
626
626
|
return e === L.Playground ? { headers: { [bt]: "true" } } : {};
|
|
627
627
|
}
|
|
@@ -634,7 +634,7 @@ async function Dt(e, t, r, a, o = !1, s) {
|
|
|
634
634
|
}
|
|
635
635
|
function rn(e) {
|
|
636
636
|
return !e || e.length === 0 ? [] : e.map(
|
|
637
|
-
(t) => Array.isArray(t.parts) && t.parts.length > 0 ? t : { ...t, parts:
|
|
637
|
+
(t) => Array.isArray(t.parts) && t.parts.length > 0 ? t : { ...t, parts: wt(typeof t.content == "string" ? t.content : "") }
|
|
638
638
|
);
|
|
639
639
|
}
|
|
640
640
|
function an(e) {
|
|
@@ -850,7 +850,7 @@ function gn(e, t, r, a) {
|
|
|
850
850
|
};
|
|
851
851
|
}
|
|
852
852
|
const hn = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? ""), pn = 45;
|
|
853
|
-
function
|
|
853
|
+
function yn(e) {
|
|
854
854
|
const t = e.map((n) => n.av).filter((n) => !!n && n.audioPlayout > 0 && n.videoPlayout > 0);
|
|
855
855
|
if (t.length < 2)
|
|
856
856
|
return null;
|
|
@@ -865,7 +865,7 @@ function wn(e) {
|
|
|
865
865
|
residualOffsetMs: De(Yt(u))
|
|
866
866
|
};
|
|
867
867
|
}
|
|
868
|
-
function
|
|
868
|
+
function wn(e, t, r) {
|
|
869
869
|
const a = (t.timestamp - e.timestamp) / 1e3;
|
|
870
870
|
return {
|
|
871
871
|
duration: a,
|
|
@@ -995,11 +995,11 @@ function ot(e, t, r) {
|
|
|
995
995
|
return {
|
|
996
996
|
webRTCStats: {
|
|
997
997
|
anomalies: o,
|
|
998
|
-
avSync: Qt(() =>
|
|
998
|
+
avSync: Qt(() => yn(e), null),
|
|
999
999
|
minRtt: et(u),
|
|
1000
1000
|
avgRtt: Ze(u),
|
|
1001
1001
|
maxRtt: tt(u),
|
|
1002
|
-
aggregateReport:
|
|
1002
|
+
aggregateReport: wn(e[0], e[e.length - 1], s),
|
|
1003
1003
|
minJitterDelayInInterval: et(i),
|
|
1004
1004
|
maxJitterDelayInInterval: tt(i),
|
|
1005
1005
|
avgJitterDelayInInterval: Ze(i)
|
|
@@ -1148,7 +1148,7 @@ function _n({
|
|
|
1148
1148
|
report: o,
|
|
1149
1149
|
log: s
|
|
1150
1150
|
}) {
|
|
1151
|
-
e === C.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(C.Start)) : e === C.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(C.Stop, o)), t === C.Start ? a == null || a(
|
|
1151
|
+
e === C.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(C.Start)) : e === C.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(C.Stop, o)), t === C.Start ? a == null || a(ye.Talking) : t === C.Stop && (a == null || a(ye.Idle));
|
|
1152
1152
|
}
|
|
1153
1153
|
function dt({
|
|
1154
1154
|
statsSignal: e,
|
|
@@ -1159,7 +1159,7 @@ function dt({
|
|
|
1159
1159
|
report: s,
|
|
1160
1160
|
log: i
|
|
1161
1161
|
}) {
|
|
1162
|
-
o ===
|
|
1162
|
+
o === J.Legacy ? Tn({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: i }) : o === J.Fluent && _n({
|
|
1163
1163
|
statsSignal: e,
|
|
1164
1164
|
dataChannelSignal: t,
|
|
1165
1165
|
onVideoStateChange: r,
|
|
@@ -1168,7 +1168,7 @@ function dt({
|
|
|
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 = Te, analytics: i }, u) {
|
|
1172
1172
|
var fe;
|
|
1173
1173
|
const n = hn(r, "WebRTCStreamingManager"), d = kn(n);
|
|
1174
1174
|
let h = !1, f = !1, g = C.Stop, l = C.Stop;
|
|
@@ -1183,48 +1183,48 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1183
1183
|
ice_servers: ae,
|
|
1184
1184
|
session_id: O,
|
|
1185
1185
|
fluent: ee,
|
|
1186
|
-
interrupt_enabled:
|
|
1186
|
+
interrupt_enabled: we
|
|
1187
1187
|
} = await P(t, u);
|
|
1188
1188
|
if (!O)
|
|
1189
1189
|
throw new Error("Could not create session_id");
|
|
1190
1190
|
(fe = a.onStreamCreated) == null || fe.call(a, { streamId: j, sessionId: O, agentId: e });
|
|
1191
|
-
const ie = (
|
|
1191
|
+
const ie = (w) => {
|
|
1192
1192
|
var v;
|
|
1193
|
-
return (v = a.onError) == null ? void 0 : v.call(a,
|
|
1194
|
-
}, T = new (En())({ iceServers: ae }), G = T.createDataChannel("JanusDataChannel"), B = ee ?
|
|
1193
|
+
return (v = a.onError) == null ? void 0 : v.call(a, w, { streamId: j });
|
|
1194
|
+
}, T = new (En())({ iceServers: ae }), G = T.createDataChannel("JanusDataChannel"), B = ee ? J.Fluent : J.Legacy;
|
|
1195
1195
|
i.enrich({
|
|
1196
1196
|
"stream-type": B
|
|
1197
1197
|
});
|
|
1198
1198
|
const X = t.stream_warmup && !ee, ve = () => h, se = () => {
|
|
1199
|
-
var
|
|
1200
|
-
h = !0, f && (n("CALLBACK: onConnectionStateChange(Connected)"), (
|
|
1199
|
+
var w;
|
|
1200
|
+
h = !0, f && (n("CALLBACK: onConnectionStateChange(Connected)"), (w = a.onConnectionStateChange) == null || w.call(a, R.Connected));
|
|
1201
1201
|
}, Y = Rn(
|
|
1202
1202
|
() => T.getStats(),
|
|
1203
1203
|
ve,
|
|
1204
1204
|
se,
|
|
1205
|
-
(
|
|
1206
|
-
statsSignal: l =
|
|
1207
|
-
dataChannelSignal: B ===
|
|
1205
|
+
(w, v) => dt({
|
|
1206
|
+
statsSignal: l = w,
|
|
1207
|
+
dataChannelSignal: B === J.Legacy ? g : void 0,
|
|
1208
1208
|
onVideoStateChange: a.onVideoStateChange,
|
|
1209
1209
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
1210
1210
|
report: v,
|
|
1211
1211
|
streamType: B,
|
|
1212
1212
|
log: n
|
|
1213
1213
|
}),
|
|
1214
|
-
(
|
|
1214
|
+
(w) => {
|
|
1215
1215
|
var v;
|
|
1216
|
-
return (v = a.onConnectivityStateChange) == null ? void 0 : v.call(a,
|
|
1216
|
+
return (v = a.onConnectivityStateChange) == null ? void 0 : v.call(a, w);
|
|
1217
1217
|
}
|
|
1218
1218
|
);
|
|
1219
|
-
Y.start(), T.onicecandidate = (
|
|
1220
|
-
n("peerConnection.onicecandidate",
|
|
1219
|
+
Y.start(), T.onicecandidate = (w) => {
|
|
1220
|
+
n("peerConnection.onicecandidate", w);
|
|
1221
1221
|
try {
|
|
1222
|
-
|
|
1222
|
+
w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? U(
|
|
1223
1223
|
j,
|
|
1224
1224
|
{
|
|
1225
|
-
candidate:
|
|
1226
|
-
sdpMid:
|
|
1227
|
-
sdpMLineIndex:
|
|
1225
|
+
candidate: w.candidate.candidate,
|
|
1226
|
+
sdpMid: w.candidate.sdpMid,
|
|
1227
|
+
sdpMLineIndex: w.candidate.sdpMLineIndex
|
|
1228
1228
|
},
|
|
1229
1229
|
O,
|
|
1230
1230
|
u
|
|
@@ -1236,17 +1236,17 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1236
1236
|
f = !0, (!X || h) && se();
|
|
1237
1237
|
};
|
|
1238
1238
|
let V = null;
|
|
1239
|
-
const oe = (
|
|
1239
|
+
const oe = (w) => {
|
|
1240
1240
|
var v;
|
|
1241
|
-
V =
|
|
1241
|
+
V = w, (v = a.onVideoIdChange) == null || v.call(a, w);
|
|
1242
1242
|
};
|
|
1243
|
-
function Se(
|
|
1244
|
-
if (
|
|
1243
|
+
function Se(w, v) {
|
|
1244
|
+
if (w === k.StreamStarted && typeof v == "object" && "metadata" in v) {
|
|
1245
1245
|
const c = v.metadata;
|
|
1246
1246
|
oe(c.videoId);
|
|
1247
1247
|
}
|
|
1248
|
-
|
|
1249
|
-
statsSignal: B ===
|
|
1248
|
+
w === k.StreamDone && oe(null), g = w === k.StreamStarted ? C.Start : C.Stop, dt({
|
|
1249
|
+
statsSignal: B === J.Legacy ? l : void 0,
|
|
1250
1250
|
dataChannelSignal: g,
|
|
1251
1251
|
onVideoStateChange: a.onVideoStateChange,
|
|
1252
1252
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
@@ -1254,7 +1254,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1254
1254
|
log: n
|
|
1255
1255
|
});
|
|
1256
1256
|
}
|
|
1257
|
-
function ce(
|
|
1257
|
+
function ce(w, v) {
|
|
1258
1258
|
var m;
|
|
1259
1259
|
const c = typeof v == "string" ? v : v == null ? void 0 : v.metadata;
|
|
1260
1260
|
c && i.enrich({ streamMetadata: c }), (m = a.onStreamReady) == null || m.call(a);
|
|
@@ -1264,22 +1264,22 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1264
1264
|
[k.StreamDone]: Se,
|
|
1265
1265
|
[k.StreamReady]: ce
|
|
1266
1266
|
};
|
|
1267
|
-
G.onmessage = (
|
|
1267
|
+
G.onmessage = (w) => {
|
|
1268
1268
|
var m;
|
|
1269
|
-
const { subject: v, data: c } = d(
|
|
1269
|
+
const { subject: v, data: c } = d(w.data);
|
|
1270
1270
|
(m = de[v]) == null || m.call(de, v, c);
|
|
1271
1271
|
}, T.oniceconnectionstatechange = () => {
|
|
1272
1272
|
var v;
|
|
1273
1273
|
n("peerConnection.oniceconnectionstatechange => " + T.iceConnectionState);
|
|
1274
|
-
const
|
|
1275
|
-
|
|
1276
|
-
}, T.ontrack = (
|
|
1274
|
+
const w = ct(T.iceConnectionState);
|
|
1275
|
+
w !== R.Connected && ((v = a.onConnectionStateChange) == null || v.call(a, w, `webrtc:ice-${T.iceConnectionState}`));
|
|
1276
|
+
}, T.ontrack = (w) => {
|
|
1277
1277
|
var v;
|
|
1278
|
-
n("peerConnection.ontrack",
|
|
1278
|
+
n("peerConnection.ontrack", w), n("CALLBACK: onSrcObjectReady"), (v = a.onSrcObjectReady) == null || v.call(a, w.streams[0]);
|
|
1279
1279
|
}, await T.setRemoteDescription(re), n("set remote description OK");
|
|
1280
1280
|
const ue = await T.createAnswer();
|
|
1281
1281
|
n("create answer OK"), await T.setLocalDescription(ue), n("set local description OK"), await p(j, ue, O, u), n("start connection OK");
|
|
1282
|
-
async function le(
|
|
1282
|
+
async function le(w, v) {
|
|
1283
1283
|
if (!h || G.readyState !== "open") {
|
|
1284
1284
|
n("Data channel is not ready for sending messages"), ie(new pt("Data channel is not ready for sending messages"));
|
|
1285
1285
|
return;
|
|
@@ -1295,14 +1295,14 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1295
1295
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1296
1296
|
* @param payload
|
|
1297
1297
|
*/
|
|
1298
|
-
speak(
|
|
1299
|
-
return D(j, O,
|
|
1298
|
+
speak(w) {
|
|
1299
|
+
return D(j, O, w);
|
|
1300
1300
|
},
|
|
1301
1301
|
/**
|
|
1302
1302
|
* Method to close RTC connection
|
|
1303
1303
|
*/
|
|
1304
1304
|
async disconnect() {
|
|
1305
|
-
var
|
|
1305
|
+
var w;
|
|
1306
1306
|
if (j) {
|
|
1307
1307
|
const v = ct(T.iceConnectionState);
|
|
1308
1308
|
if (T) {
|
|
@@ -1317,7 +1317,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1317
1317
|
} catch (c) {
|
|
1318
1318
|
n("Error on close stream connection", c);
|
|
1319
1319
|
}
|
|
1320
|
-
(
|
|
1320
|
+
(w = a.onAgentActivityStateChange) == null || w.call(a, ye.Idle), Y.stop();
|
|
1321
1321
|
}
|
|
1322
1322
|
},
|
|
1323
1323
|
sendDataChannelMessage: le,
|
|
@@ -1330,10 +1330,10 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1330
1330
|
*/
|
|
1331
1331
|
streamId: j,
|
|
1332
1332
|
streamType: B,
|
|
1333
|
-
interruptAvailable:
|
|
1333
|
+
interruptAvailable: we ?? !1,
|
|
1334
1334
|
isInterruptible: !0,
|
|
1335
|
-
interrupt(
|
|
1336
|
-
if (!
|
|
1335
|
+
interrupt(w) {
|
|
1336
|
+
if (!we || B !== J.Fluent || !V || !h || G.readyState !== "open")
|
|
1337
1337
|
return !1;
|
|
1338
1338
|
const v = {
|
|
1339
1339
|
type: k.StreamInterrupt,
|
|
@@ -1344,7 +1344,7 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = ke,
|
|
|
1344
1344
|
}
|
|
1345
1345
|
};
|
|
1346
1346
|
}
|
|
1347
|
-
var
|
|
1347
|
+
var ke = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ke || {});
|
|
1348
1348
|
async function Pn(e, t, r, a) {
|
|
1349
1349
|
const o = e.id;
|
|
1350
1350
|
switch (t.version) {
|
|
@@ -1355,8 +1355,8 @@ async function Pn(e, t, r, a) {
|
|
|
1355
1355
|
case "v2": {
|
|
1356
1356
|
const { version: s, ...i } = t;
|
|
1357
1357
|
switch (i.transport.provider) {
|
|
1358
|
-
case
|
|
1359
|
-
const { createLiveKitStreamingManager: u } = await import("./livekit-manager-
|
|
1358
|
+
case Ue.Livekit:
|
|
1359
|
+
const { createLiveKitStreamingManager: u } = await import("./livekit-manager-D4bHd2x6.js");
|
|
1360
1360
|
return u(o, i, r);
|
|
1361
1361
|
default:
|
|
1362
1362
|
throw new Error(`Unsupported transport provider: ${i.transport.provider}`);
|
|
@@ -1370,7 +1370,7 @@ const bn = "cht";
|
|
|
1370
1370
|
function xn(e) {
|
|
1371
1371
|
return {
|
|
1372
1372
|
transport: {
|
|
1373
|
-
provider:
|
|
1373
|
+
provider: Ue.Livekit
|
|
1374
1374
|
},
|
|
1375
1375
|
...(e == null ? void 0 : e.persistentChat) !== void 0 && { chat_persist: e.persistentChat }
|
|
1376
1376
|
};
|
|
@@ -1388,13 +1388,13 @@ function Ln(e) {
|
|
|
1388
1388
|
}, ...r && { end_user_data: r } };
|
|
1389
1389
|
}
|
|
1390
1390
|
function jn(e, t) {
|
|
1391
|
-
return
|
|
1391
|
+
return Ee(e.avatar.type) ? { version: ke.V2, ...xn(t) } : { version: ke.V1, ...Ln(t) };
|
|
1392
1392
|
}
|
|
1393
1393
|
function Bn(e, t, r) {
|
|
1394
1394
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1395
1395
|
}
|
|
1396
1396
|
function $n(e, t, r, a, o) {
|
|
1397
|
-
o ===
|
|
1397
|
+
o === J.Fluent ? Nn(e, t, r, a, o) : On(e, t, r, a, o);
|
|
1398
1398
|
}
|
|
1399
1399
|
function Nn(e, t, r, a, o) {
|
|
1400
1400
|
e === C.Start ? a.track("stream-session", { event: "start", "stream-type": o }) : e === C.Stop && a.track("stream-session", {
|
|
@@ -1438,14 +1438,14 @@ function zn(e, t, r) {
|
|
|
1438
1438
|
call_id: t.callId,
|
|
1439
1439
|
name: t.name
|
|
1440
1440
|
};
|
|
1441
|
-
if (e ===
|
|
1441
|
+
if (e === $e.Started) {
|
|
1442
1442
|
r.track("agent-tool-call", { ...a, event: "started" });
|
|
1443
1443
|
return;
|
|
1444
1444
|
}
|
|
1445
1445
|
const o = t;
|
|
1446
1446
|
r.track("agent-tool-call", {
|
|
1447
1447
|
...a,
|
|
1448
|
-
event: e ===
|
|
1448
|
+
event: e === $e.Done ? "done" : "error",
|
|
1449
1449
|
duration_ms: o.durationMs,
|
|
1450
1450
|
extra_keys: o.extra ? Object.keys(o.extra).length : 0
|
|
1451
1451
|
});
|
|
@@ -1459,7 +1459,7 @@ function lt(e, t, r, a) {
|
|
|
1459
1459
|
"stream-version": n.version.toString()
|
|
1460
1460
|
});
|
|
1461
1461
|
let d = null;
|
|
1462
|
-
const h = n.version ===
|
|
1462
|
+
const h = n.version === ke.V2;
|
|
1463
1463
|
i = await Pn(
|
|
1464
1464
|
e,
|
|
1465
1465
|
n,
|
|
@@ -1484,7 +1484,7 @@ function lt(e, t, r, a) {
|
|
|
1484
1484
|
},
|
|
1485
1485
|
onAgentActivityStateChange: (f) => {
|
|
1486
1486
|
var g, l;
|
|
1487
|
-
(l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f ===
|
|
1487
|
+
(l = (g = t.callbacks).onAgentActivityStateChange) == null || l.call(g, f), f === ye.Talking ? (Ve.update(), d = (p) => {
|
|
1488
1488
|
ut(
|
|
1489
1489
|
C.Start,
|
|
1490
1490
|
e,
|
|
@@ -1492,7 +1492,7 @@ function lt(e, t, r, a) {
|
|
|
1492
1492
|
i.streamType,
|
|
1493
1493
|
p
|
|
1494
1494
|
), d = null;
|
|
1495
|
-
}, h || d({ latency: K.get(!0) })) : (
|
|
1495
|
+
}, h || d({ latency: K.get(!0) })) : (Ve.reset(), d = null, ut(
|
|
1496
1496
|
C.Stop,
|
|
1497
1497
|
e,
|
|
1498
1498
|
r,
|
|
@@ -1522,7 +1522,7 @@ function lt(e, t, r, a) {
|
|
|
1522
1522
|
async function Fn(e, t, r, a, o) {
|
|
1523
1523
|
var h, f;
|
|
1524
1524
|
const s = async () => {
|
|
1525
|
-
if (
|
|
1525
|
+
if (Ee(e.avatar.type)) {
|
|
1526
1526
|
const g = await lt(e, t, a), l = `${bn}_${g.sessionId}`, p = (/* @__PURE__ */ new Date()).toISOString();
|
|
1527
1527
|
return { chatResult: {
|
|
1528
1528
|
chatMode: L.Functional,
|
|
@@ -1559,13 +1559,13 @@ async function Fn(e, t, r, a, o) {
|
|
|
1559
1559
|
}, { chatResult: i, streamingManager: u } = await s(), { chat: n, chatMode: d } = i;
|
|
1560
1560
|
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 };
|
|
1561
1561
|
}
|
|
1562
|
-
const
|
|
1562
|
+
const Be = "ChatMode.Off and ChatMode.DirectPlayback are not supported for Expressive agents", ft = "callbacks.onSrcObjectReady is required in every chat mode that streams video; it is optional only in ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance", Vn = [R.Disconnected, R.Closed, R.Fail];
|
|
1563
1563
|
async function Kn(e, t) {
|
|
1564
|
-
var ue, le, fe,
|
|
1564
|
+
var ue, le, fe, w, v;
|
|
1565
1565
|
const r = { ...t.callbacks };
|
|
1566
1566
|
let a = !0;
|
|
1567
|
-
const o = ((ue = t.analytics) == null ? void 0 : ue.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL ||
|
|
1568
|
-
if (!r.onSrcObjectReady && !
|
|
1567
|
+
const o = ((ue = t.analytics) == null ? void 0 : ue.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL || Te, u = t.mode || L.Functional;
|
|
1568
|
+
if (!r.onSrcObjectReady && !be(u))
|
|
1569
1569
|
throw new I(ft);
|
|
1570
1570
|
const n = {
|
|
1571
1571
|
messages: [],
|
|
@@ -1584,37 +1584,37 @@ async function Kn(e, t) {
|
|
|
1584
1584
|
const l = {
|
|
1585
1585
|
...r,
|
|
1586
1586
|
onError(c, m) {
|
|
1587
|
-
var
|
|
1588
|
-
d.track("agent-error", { error:
|
|
1587
|
+
var y;
|
|
1588
|
+
d.track("agent-error", { error: Le(c) }), (y = r.onError) == null || y.call(r, c, m);
|
|
1589
1589
|
},
|
|
1590
1590
|
onConnectionStateChange(c, m) {
|
|
1591
|
-
var
|
|
1592
|
-
f = c, (
|
|
1591
|
+
var y;
|
|
1592
|
+
f = c, (y = r.onConnectionStateChange) == null || y.call(r, c, m);
|
|
1593
1593
|
},
|
|
1594
1594
|
onStreamCreated(c) {
|
|
1595
1595
|
var m;
|
|
1596
1596
|
g = c, (m = r.onStreamCreated) == null || m.call(r, c);
|
|
1597
1597
|
}
|
|
1598
1598
|
}, p = { ...t, callbacks: l }, D = Ht(p.auth, i, l.onError, p.externalId), S = await D.getRuntimeById(e);
|
|
1599
|
-
p.debug = p.debug || ((
|
|
1600
|
-
const P =
|
|
1599
|
+
p.debug = p.debug || ((w = S == null ? void 0 : S.advanced_settings) == null ? void 0 : w.ui_debug_mode);
|
|
1600
|
+
const P = Ee(S.avatar.type);
|
|
1601
1601
|
if (P && te(u))
|
|
1602
|
-
throw new I(
|
|
1603
|
-
P && import("./livekit-manager-
|
|
1602
|
+
throw new I(Be);
|
|
1603
|
+
P && import("./livekit-manager-D4bHd2x6.js").then(({ preloadLiveKit: c }) => c()).catch(() => {
|
|
1604
1604
|
}), d.enrich(Kt(S));
|
|
1605
1605
|
const { onMessage: U, clearQueue: j } = mn(d, n, p, S, (c) => {
|
|
1606
|
-
var m,
|
|
1607
|
-
(m = n.socketManager) == null || m.disconnect(), (
|
|
1606
|
+
var m, y;
|
|
1607
|
+
(m = n.socketManager) == null || m.disconnect(), (y = l.onConnectionStateChange) == null || y.call(l, R.Disconnected, c);
|
|
1608
1608
|
});
|
|
1609
1609
|
n.messages = rn(p.initialMessages), n.messages.length && ((v = l.onNewMessage) == null || v.call(l, [...n.messages], "answer"));
|
|
1610
1610
|
const re = (c) => d.enrich({ videoId: c }), ae = (c) => {
|
|
1611
1611
|
var z;
|
|
1612
|
-
const m = (c == null ? void 0 : c.type) ?? "click",
|
|
1613
|
-
if (!(
|
|
1612
|
+
const m = (c == null ? void 0 : c.type) ?? "click", y = n.streamingManager;
|
|
1613
|
+
if (!(y != null && y.interruptAvailable) || !y.isInterruptible || !y.interrupt(m))
|
|
1614
1614
|
return;
|
|
1615
1615
|
d.track("agent-video-interrupt", {
|
|
1616
1616
|
type: m,
|
|
1617
|
-
video_duration_to_interrupt:
|
|
1617
|
+
video_duration_to_interrupt: Ve.get(!0),
|
|
1618
1618
|
message_duration_to_interrupt: K.get(!0)
|
|
1619
1619
|
});
|
|
1620
1620
|
const E = n.messages[n.messages.length - 1];
|
|
@@ -1622,28 +1622,28 @@ async function Kn(e, t) {
|
|
|
1622
1622
|
}, O = /* @__PURE__ */ new Map();
|
|
1623
1623
|
function ee(c) {
|
|
1624
1624
|
return async (m) => {
|
|
1625
|
-
const
|
|
1626
|
-
if (!
|
|
1625
|
+
const y = O.get(c);
|
|
1626
|
+
if (!y)
|
|
1627
1627
|
throw new Error(`No handler registered for client tool: ${c}`);
|
|
1628
1628
|
const M = JSON.parse(m.payload);
|
|
1629
|
-
return
|
|
1629
|
+
return y(M);
|
|
1630
1630
|
};
|
|
1631
1631
|
}
|
|
1632
|
-
function
|
|
1633
|
-
var c, m,
|
|
1632
|
+
function we() {
|
|
1633
|
+
var c, m, y, M;
|
|
1634
1634
|
for (const [E] of O)
|
|
1635
|
-
(m = (c = n.streamingManager) == null ? void 0 : c.unregisterRpcMethod) == null || m.call(c, E), (M = (
|
|
1635
|
+
(m = (c = n.streamingManager) == null ? void 0 : c.unregisterRpcMethod) == null || m.call(c, E), (M = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || M.call(y, E, ee(E));
|
|
1636
1636
|
}
|
|
1637
1637
|
function ie(c, m) {
|
|
1638
1638
|
var M, E;
|
|
1639
1639
|
if (!P)
|
|
1640
1640
|
throw new I("registerClientTool is only available on Expressive (V4) agents");
|
|
1641
|
-
const
|
|
1642
|
-
O.set(c, m),
|
|
1641
|
+
const y = !O.has(c);
|
|
1642
|
+
O.set(c, m), y && ((E = (M = n.streamingManager) == null ? void 0 : M.registerRpcMethod) == null || E.call(M, c, ee(c)));
|
|
1643
1643
|
}
|
|
1644
1644
|
function T(c) {
|
|
1645
|
-
var m,
|
|
1646
|
-
O.delete(c), (
|
|
1645
|
+
var m, y;
|
|
1646
|
+
O.delete(c), (y = (m = n.streamingManager) == null ? void 0 : m.unregisterRpcMethod) == null || y.call(m, c);
|
|
1647
1647
|
}
|
|
1648
1648
|
const G = Date.now();
|
|
1649
1649
|
rt(() => {
|
|
@@ -1659,16 +1659,16 @@ async function Kn(e, t) {
|
|
|
1659
1659
|
return B || ve(() => Y(c));
|
|
1660
1660
|
}
|
|
1661
1661
|
async function Y(c) {
|
|
1662
|
-
var
|
|
1662
|
+
var H, _e, Ae, $;
|
|
1663
1663
|
if (X)
|
|
1664
1664
|
return;
|
|
1665
|
-
n.streamingManager && await V(), At(), (
|
|
1665
|
+
n.streamingManager && await V(), At(), (H = l.onConnectionStateChange) == null || H.call(l, R.Connecting), K.reset(), c && !a && (delete n.chat, (_e = l.onNewMessage) == null || _e.call(l, [...n.messages], "answer"));
|
|
1666
1666
|
const m = oe(n.chatMode) ? on(
|
|
1667
1667
|
p.auth,
|
|
1668
1668
|
s,
|
|
1669
1669
|
{ onMessage: U, onError: l.onError },
|
|
1670
1670
|
p.externalId
|
|
1671
|
-
) : Promise.resolve(void 0),
|
|
1671
|
+
) : Promise.resolve(void 0), y = ze(
|
|
1672
1672
|
() => Fn(
|
|
1673
1673
|
S,
|
|
1674
1674
|
{
|
|
@@ -1689,33 +1689,33 @@ async function Kn(e, t) {
|
|
|
1689
1689
|
limit: 3,
|
|
1690
1690
|
timeout: Pt,
|
|
1691
1691
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1692
|
-
shouldRetryFn: (N) => !(N instanceof
|
|
1692
|
+
shouldRetryFn: (N) => !(N instanceof Oe && (N.status === 429 || N.status === 409 || N.code === "InsufficientCreditsError")),
|
|
1693
1693
|
delayMs: 1e3
|
|
1694
1694
|
}
|
|
1695
1695
|
).catch(async (N) => {
|
|
1696
1696
|
var Ce;
|
|
1697
1697
|
throw m.then((W) => W == null ? void 0 : W.disconnect()).catch(() => {
|
|
1698
|
-
}), N instanceof
|
|
1699
|
-
}), M = (
|
|
1698
|
+
}), N instanceof Oe && N.code === "NotReadyError" || await ce(L.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, R.Fail), N;
|
|
1699
|
+
}), M = (Ae = n.chat) == null ? void 0 : Ae.id, [E, { streamingManager: z, chat: _ }] = await Promise.all([m, y]), b = !!_ && _.id !== M;
|
|
1700
1700
|
if (_ && b && (($ = l.onNewChat) == null || $.call(l, _.id)), n.streamingManager = z, n.socketManager = E, n.chat = _, X) {
|
|
1701
1701
|
await V();
|
|
1702
1702
|
return;
|
|
1703
1703
|
}
|
|
1704
|
-
|
|
1704
|
+
we(), a = !1, d.enrich({
|
|
1705
1705
|
chatId: _ == null ? void 0 : _.id,
|
|
1706
1706
|
streamId: z == null ? void 0 : z.streamId,
|
|
1707
1707
|
mode: n.chatMode
|
|
1708
1708
|
});
|
|
1709
1709
|
const A = (b ? _ == null ? void 0 : _.chat_mode : void 0) ?? n.chatMode;
|
|
1710
1710
|
if (P && te(A)) {
|
|
1711
|
-
console.warn(`[AgentManager] Ignoring chat mode "${A}": ${
|
|
1711
|
+
console.warn(`[AgentManager] Ignoring chat mode "${A}": ${Be}`);
|
|
1712
1712
|
return;
|
|
1713
1713
|
}
|
|
1714
1714
|
await ce(A);
|
|
1715
1715
|
}
|
|
1716
1716
|
async function V() {
|
|
1717
|
-
var c, m,
|
|
1718
|
-
(c = n.socketManager) == null || c.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, g = void 0, (
|
|
1717
|
+
var c, m, y;
|
|
1718
|
+
(c = n.socketManager) == null || c.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, g = void 0, (y = l.onConnectionStateChange) == null || y.call(l, R.Disconnected);
|
|
1719
1719
|
}
|
|
1720
1720
|
function oe(c) {
|
|
1721
1721
|
return !P && c !== L.DirectPlayback;
|
|
@@ -1728,20 +1728,21 @@ async function Kn(e, t) {
|
|
|
1728
1728
|
var m;
|
|
1729
1729
|
if (c !== n.chatMode) {
|
|
1730
1730
|
d.track("agent-mode-change", { mode: c }), n.chatMode = c;
|
|
1731
|
-
const
|
|
1732
|
-
(c !== L.Functional ||
|
|
1731
|
+
const y = !!n.streamingManager || !!n.socketManager;
|
|
1732
|
+
(c !== L.Functional || y && !Se(c)) && await V(), (m = l.onModeChange) == null || m.call(l, c);
|
|
1733
1733
|
}
|
|
1734
1734
|
}
|
|
1735
1735
|
async function de(c) {
|
|
1736
1736
|
if (P && te(c))
|
|
1737
|
-
throw new I(
|
|
1737
|
+
throw new I(Be);
|
|
1738
1738
|
await ce(c);
|
|
1739
1739
|
}
|
|
1740
1740
|
return {
|
|
1741
1741
|
agent: S,
|
|
1742
|
+
// A streams-V2 agent's session is always fluent, so its type is known before connect()
|
|
1742
1743
|
getStreamType: () => {
|
|
1743
1744
|
var c;
|
|
1744
|
-
return (c = n.streamingManager) == null ? void 0 : c.streamType;
|
|
1745
|
+
return Ee(S.avatar.type) ? J.Fluent : (c = n.streamingManager) == null ? void 0 : c.streamType;
|
|
1745
1746
|
},
|
|
1746
1747
|
isInterruptAvailable: () => {
|
|
1747
1748
|
var c;
|
|
@@ -1757,7 +1758,7 @@ async function Kn(e, t) {
|
|
|
1757
1758
|
changeMode: de,
|
|
1758
1759
|
enrichAnalytics: (c) => d.enrich(c),
|
|
1759
1760
|
async connect() {
|
|
1760
|
-
if (!l.onSrcObjectReady && !
|
|
1761
|
+
if (!l.onSrcObjectReady && !be(n.chatMode))
|
|
1761
1762
|
throw new I(ft);
|
|
1762
1763
|
if (B)
|
|
1763
1764
|
return X = !1, B;
|
|
@@ -1777,8 +1778,8 @@ async function Kn(e, t) {
|
|
|
1777
1778
|
if (P && (c != null && c.reconnect))
|
|
1778
1779
|
try {
|
|
1779
1780
|
await c.reconnect();
|
|
1780
|
-
} catch (
|
|
1781
|
-
const M =
|
|
1781
|
+
} catch (y) {
|
|
1782
|
+
const M = Le(y);
|
|
1782
1783
|
m = M.code ?? M.kind, await V(), await Y(!1);
|
|
1783
1784
|
}
|
|
1784
1785
|
else
|
|
@@ -1863,7 +1864,7 @@ async function Kn(e, t) {
|
|
|
1863
1864
|
if (!n.chat)
|
|
1864
1865
|
throw new I("Chat is not initialized");
|
|
1865
1866
|
}
|
|
1866
|
-
},
|
|
1867
|
+
}, y = async () => {
|
|
1867
1868
|
var b;
|
|
1868
1869
|
if (!n.chat) {
|
|
1869
1870
|
const A = await Dt(
|
|
@@ -1879,8 +1880,8 @@ async function Kn(e, t) {
|
|
|
1879
1880
|
}
|
|
1880
1881
|
return n.chat.id;
|
|
1881
1882
|
}, M = async (b, A) => {
|
|
1882
|
-
const
|
|
1883
|
-
return
|
|
1883
|
+
const H = n.chatMode === L.Playground;
|
|
1884
|
+
return ze(P && !H ? async () => {
|
|
1884
1885
|
var $;
|
|
1885
1886
|
return await (($ = n.streamingManager) == null ? void 0 : $.sendDataChannelMessage(
|
|
1886
1887
|
Re.Chat,
|
|
@@ -1926,7 +1927,7 @@ async function Kn(e, t) {
|
|
|
1926
1927
|
parts: pe(c),
|
|
1927
1928
|
createdAt: new Date(K.update()).toISOString()
|
|
1928
1929
|
}), (E = l.onNewMessage) == null || E.call(l, [...n.messages], "user");
|
|
1929
|
-
const b = await
|
|
1930
|
+
const b = await y(), A = await M([...n.messages], b);
|
|
1930
1931
|
return A.result && n.messages.push({
|
|
1931
1932
|
id: Z(),
|
|
1932
1933
|
role: "assistant",
|
|
@@ -1946,25 +1947,25 @@ async function Kn(e, t) {
|
|
|
1946
1947
|
throw ((_ = n.messages[n.messages.length - 1]) == null ? void 0 : _.role) === "assistant" && n.messages.pop(), d.track("agent-message-send", {
|
|
1947
1948
|
event: "error",
|
|
1948
1949
|
messages: n.messages.length,
|
|
1949
|
-
error:
|
|
1950
|
+
error: Le(b)
|
|
1950
1951
|
}), b;
|
|
1951
1952
|
}
|
|
1952
1953
|
},
|
|
1953
|
-
async rate(c, m,
|
|
1954
|
+
async rate(c, m, y) {
|
|
1954
1955
|
var z, _, b, A;
|
|
1955
|
-
const M = n.messages.find((
|
|
1956
|
+
const M = n.messages.find((H) => H.id === c);
|
|
1956
1957
|
if (n.chat) {
|
|
1957
1958
|
if (!M)
|
|
1958
1959
|
throw new I("Message not found");
|
|
1959
1960
|
} else throw new I("Chat is not initialized");
|
|
1960
|
-
const E = ((z = M.matches) == null ? void 0 : z.map((
|
|
1961
|
+
const E = ((z = M.matches) == null ? void 0 : z.map((H) => [H.document_id, H.id])) ?? [];
|
|
1961
1962
|
return d.track("agent-rate", {
|
|
1962
|
-
event:
|
|
1963
|
+
event: y ? "update" : "create",
|
|
1963
1964
|
thumb: m === 1 ? "up" : "down",
|
|
1964
1965
|
knowledge_id: ((_ = S.knowledge) == null ? void 0 : _.id) ?? "",
|
|
1965
1966
|
matches: E,
|
|
1966
1967
|
score: m
|
|
1967
|
-
}),
|
|
1968
|
+
}), y ? D.updateRating(S.id, n.chat.id, y, {
|
|
1968
1969
|
knowledge_id: ((b = S.knowledge) == null ? void 0 : b.id) ?? "",
|
|
1969
1970
|
message_id: c,
|
|
1970
1971
|
matches: E,
|
|
@@ -2001,8 +2002,8 @@ async function Kn(e, t) {
|
|
|
2001
2002
|
sentiment: c.sentiment
|
|
2002
2003
|
} : c;
|
|
2003
2004
|
}
|
|
2004
|
-
const
|
|
2005
|
-
if (!
|
|
2005
|
+
const y = be(n.chatMode);
|
|
2006
|
+
if (!y && !n.streamingManager)
|
|
2006
2007
|
throw new I("Please connect to the agent first");
|
|
2007
2008
|
const M = m();
|
|
2008
2009
|
d.track("agent-speak", M), K.update(), n.messages && M.type === "text" && (n.messages.push({
|
|
@@ -2013,7 +2014,7 @@ async function Kn(e, t) {
|
|
|
2013
2014
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2014
2015
|
}), (_ = l.onNewMessage) == null || _.call(l, [...n.messages], "answer"));
|
|
2015
2016
|
const E = { duration: 0, videoId: "", status: "success" };
|
|
2016
|
-
return
|
|
2017
|
+
return y || !n.streamingManager ? E : await n.streamingManager.speak({
|
|
2017
2018
|
script: M,
|
|
2018
2019
|
metadata: { chat_id: (b = n.chat) == null ? void 0 : b.id, agent_id: S.id }
|
|
2019
2020
|
}) ?? E;
|
|
@@ -2027,22 +2028,22 @@ function qn(e) {
|
|
|
2027
2028
|
return e.some((t) => t.executionMode === "blocking");
|
|
2028
2029
|
}
|
|
2029
2030
|
export {
|
|
2030
|
-
|
|
2031
|
+
ye as A,
|
|
2031
2032
|
q as B,
|
|
2032
2033
|
F as C,
|
|
2033
2034
|
kt as D,
|
|
2034
|
-
|
|
2035
|
+
Oe as H,
|
|
2035
2036
|
Re as I,
|
|
2036
2037
|
Nt as N,
|
|
2037
2038
|
Tt as P,
|
|
2038
2039
|
k as S,
|
|
2039
|
-
|
|
2040
|
+
$e as T,
|
|
2040
2041
|
I as V,
|
|
2041
2042
|
Ot as W,
|
|
2042
2043
|
hn as a,
|
|
2043
|
-
|
|
2044
|
+
J as b,
|
|
2044
2045
|
vt as c,
|
|
2045
|
-
|
|
2046
|
+
Te as d,
|
|
2046
2047
|
pt as e,
|
|
2047
2048
|
R as f,
|
|
2048
2049
|
ge as g,
|
|
@@ -2058,9 +2059,9 @@ export {
|
|
|
2058
2059
|
he as q,
|
|
2059
2060
|
_t as r,
|
|
2060
2061
|
Kn as s,
|
|
2061
|
-
|
|
2062
|
+
Le as t,
|
|
2062
2063
|
qn as u,
|
|
2063
2064
|
Hn as v,
|
|
2064
|
-
|
|
2065
|
+
wt as w
|
|
2065
2066
|
};
|
|
2066
|
-
//# sourceMappingURL=index-
|
|
2067
|
+
//# sourceMappingURL=index-B6ILepDc.js.map
|