@d-id/client-sdk 1.1.67 → 1.1.68-staging.315
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-DxHW-jum.js → index-_7uj0USX.js} +175 -159
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +4 -4
- package/dist/{livekit-manager-zAbqmsie.js → livekit-manager-B7gYoJ6B.js} +1 -1
- package/dist/src/api/apiClient.test.d.ts +1 -0
- package/dist/src/services/socket-manager/message-queue.d.ts +1 -1
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ class qe extends ce {
|
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}),
|
|
38
|
+
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), N = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(N || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
|
|
39
39
|
const sr = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -171,16 +171,22 @@ const pt = (e) => ue(e, {
|
|
|
171
171
|
});
|
|
172
172
|
function Fe(e, t = de, r, a) {
|
|
173
173
|
const c = async (s, o) => {
|
|
174
|
-
const { skipErrorHandler: n, ...i } = o || {}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
const { skipErrorHandler: n, ...i } = o || {};
|
|
175
|
+
let d;
|
|
176
|
+
try {
|
|
177
|
+
d = await pt(
|
|
178
|
+
() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
179
|
+
...i,
|
|
180
|
+
headers: {
|
|
181
|
+
...i.headers,
|
|
182
|
+
Authorization: ze(e, a),
|
|
183
|
+
"Content-Type": "application/json"
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
} catch (m) {
|
|
188
|
+
throw !((m == null ? void 0 : m.name) === "AbortError") && r && !n && r(m, { url: s, options: i }), m;
|
|
189
|
+
}
|
|
184
190
|
if (!d.ok) {
|
|
185
191
|
let m = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
186
192
|
const l = new Error(m);
|
|
@@ -399,10 +405,10 @@ function It(e) {
|
|
|
399
405
|
function Mt(e) {
|
|
400
406
|
return new Promise((t, r) => {
|
|
401
407
|
const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(ze(s, o))}`);
|
|
402
|
-
l.onmessage = n, l.onclose = d, l.onerror = (
|
|
403
|
-
console.error(
|
|
404
|
-
}, l.onopen = (
|
|
405
|
-
i == null || i(
|
|
408
|
+
l.onmessage = n, l.onclose = d, l.onerror = (h) => {
|
|
409
|
+
console.error(h), m == null || m("Websocket failed to connect", h), r(h);
|
|
410
|
+
}, l.onopen = (h) => {
|
|
411
|
+
i == null || i(h), t(l);
|
|
406
412
|
};
|
|
407
413
|
});
|
|
408
414
|
}
|
|
@@ -464,47 +470,57 @@ function bt(e, t, r) {
|
|
|
464
470
|
};
|
|
465
471
|
t.messages.push(c), r == null || r([...t.messages], "user");
|
|
466
472
|
}
|
|
467
|
-
function At(e, t, r, a, c, s) {
|
|
468
|
-
if (e ===
|
|
473
|
+
function At(e, t, r, a, c, s, o) {
|
|
474
|
+
if (e === N.Transcribe && t.content) {
|
|
469
475
|
bt(t, a, c);
|
|
470
476
|
return;
|
|
471
477
|
}
|
|
472
|
-
if (!(e ===
|
|
478
|
+
if (!(e === N.Partial || e === N.Answer))
|
|
473
479
|
return;
|
|
474
|
-
const
|
|
475
|
-
let
|
|
476
|
-
if ((
|
|
477
|
-
|
|
478
|
-
else if (!
|
|
479
|
-
|
|
480
|
+
const n = a.messages[a.messages.length - 1], i = o === "answer";
|
|
481
|
+
let d;
|
|
482
|
+
if ((n == null ? void 0 : n.role) === "assistant" && !i)
|
|
483
|
+
d = n;
|
|
484
|
+
else if (!n || n.role === "user" || i)
|
|
485
|
+
i && s(), d = {
|
|
480
486
|
id: t.id || `assistant-${Date.now()}`,
|
|
481
487
|
role: t.role || "assistant",
|
|
482
488
|
content: t.content || "",
|
|
483
489
|
parts: [],
|
|
484
490
|
created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
485
|
-
}, a.messages.push(
|
|
491
|
+
}, a.messages.push(d);
|
|
486
492
|
else
|
|
487
493
|
return;
|
|
488
|
-
const { content:
|
|
489
|
-
e ===
|
|
490
|
-
const
|
|
491
|
-
(
|
|
494
|
+
const { content: m, sequence: l } = t;
|
|
495
|
+
e === N.Partial ? r[l] = m : r.answer = m;
|
|
496
|
+
const h = _t(r);
|
|
497
|
+
(d.content !== h || e === N.Answer) && (d.content = h, d.parts = re(h), c == null || c([...a.messages], e));
|
|
492
498
|
}
|
|
493
499
|
function xt(e, t, r, a, c) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
500
|
+
const s = {}, o = () => {
|
|
501
|
+
for (const d of Object.keys(s))
|
|
502
|
+
delete s[d];
|
|
503
|
+
};
|
|
504
|
+
let n = null;
|
|
497
505
|
const i = (d, m) => {
|
|
498
|
-
var l,
|
|
499
|
-
m === "user" && o(),
|
|
506
|
+
var l, h;
|
|
507
|
+
m === "user" && o(), (h = (l = r.callbacks).onNewMessage) == null || h.call(l, d, m);
|
|
500
508
|
};
|
|
501
509
|
return {
|
|
502
510
|
clearQueue: o,
|
|
503
511
|
onMessage: (d, m) => {
|
|
504
|
-
var l,
|
|
512
|
+
var l, h;
|
|
505
513
|
if ("content" in m) {
|
|
506
|
-
const v = d === P.ChatAnswer ?
|
|
507
|
-
At(
|
|
514
|
+
const v = d === P.ChatAnswer ? N.Answer : d === P.ChatAudioTranscribed ? N.Transcribe : d;
|
|
515
|
+
At(
|
|
516
|
+
v,
|
|
517
|
+
m,
|
|
518
|
+
s,
|
|
519
|
+
t,
|
|
520
|
+
i,
|
|
521
|
+
o,
|
|
522
|
+
n
|
|
523
|
+
), v === N.Partial ? n = "partial" : v === N.Answer && (n = "answer", o()), v === N.Answer && e.track("agent-message-received", {
|
|
508
524
|
content: m.content,
|
|
509
525
|
messages: t.messages.length,
|
|
510
526
|
mode: t.chatMode
|
|
@@ -515,14 +531,14 @@ function xt(e, t, r, a, c) {
|
|
|
515
531
|
const D = t.messages[t.messages.length - 1];
|
|
516
532
|
if ((D == null ? void 0 : D.role) === "assistant") {
|
|
517
533
|
const $ = { ...D, sentiment: m.sentiment };
|
|
518
|
-
t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n);
|
|
534
|
+
t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n ?? "answer");
|
|
519
535
|
}
|
|
520
536
|
}
|
|
521
537
|
if (k.includes(d)) {
|
|
522
538
|
const D = d.split("/")[1];
|
|
523
539
|
B.includes(d) ? e.track("agent-video", { ...M, event: D }) : e.linkTrack("agent-video", { ...M, event: D }, d, ["done"]);
|
|
524
540
|
}
|
|
525
|
-
B.includes(d) && ((
|
|
541
|
+
B.includes(d) && ((h = (l = r.callbacks).onError) == null || h.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === v.StreamDone && c();
|
|
526
542
|
}
|
|
527
543
|
}
|
|
528
544
|
};
|
|
@@ -721,13 +737,13 @@ function cr(e, t) {
|
|
|
721
737
|
c = setTimeout(i, ee);
|
|
722
738
|
return;
|
|
723
739
|
}
|
|
724
|
-
const l = m.totalAudioEnergy ?? 0,
|
|
740
|
+
const l = m.totalAudioEnergy ?? 0, h = m.totalSamplesReceived ?? 0;
|
|
725
741
|
if (!a) {
|
|
726
|
-
s = l, o =
|
|
742
|
+
s = l, o = h, a = !0, c = setTimeout(i, ee);
|
|
727
743
|
return;
|
|
728
744
|
}
|
|
729
|
-
const v = l - s, k =
|
|
730
|
-
if (s = l, o =
|
|
745
|
+
const v = l - s, k = h - o;
|
|
746
|
+
if (s = l, o = h, k > 0 && v > 0) {
|
|
731
747
|
r = !1, t(n);
|
|
732
748
|
return;
|
|
733
749
|
}
|
|
@@ -763,7 +779,7 @@ function Vt() {
|
|
|
763
779
|
};
|
|
764
780
|
}
|
|
765
781
|
function Kt(e, t, r, a, c) {
|
|
766
|
-
let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown,
|
|
782
|
+
let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, h = 0, v = 0;
|
|
767
783
|
const k = Vt();
|
|
768
784
|
async function B() {
|
|
769
785
|
const M = await e();
|
|
@@ -771,7 +787,7 @@ function Kt(e, t, r, a, c) {
|
|
|
771
787
|
return;
|
|
772
788
|
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q = $t(M);
|
|
773
789
|
if (D)
|
|
774
|
-
i = 0,
|
|
790
|
+
i = 0, h = _ - v, l = $ < Ft ? te.Strong : $ > Nt && h > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, v += h, h = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
|
|
775
791
|
else if (d && (i++, i >= zt)) {
|
|
776
792
|
const J = _e(o, oe, n);
|
|
777
793
|
a == null || a(S.Stop, J), t() || r(), v = _, d = !1;
|
|
@@ -857,7 +873,7 @@ function Ae({
|
|
|
857
873
|
async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de, analytics: o }, n) {
|
|
858
874
|
var E;
|
|
859
875
|
const i = Pt(r, "WebRTCStreamingManager"), d = Wt(i);
|
|
860
|
-
let m = !1, l = !1,
|
|
876
|
+
let m = !1, l = !1, h = S.Stop, v = S.Stop;
|
|
861
877
|
const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = Lt(
|
|
862
878
|
c,
|
|
863
879
|
s,
|
|
@@ -867,17 +883,17 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
867
883
|
id: _,
|
|
868
884
|
offer: q,
|
|
869
885
|
ice_servers: J,
|
|
870
|
-
session_id:
|
|
886
|
+
session_id: V,
|
|
871
887
|
fluent: X,
|
|
872
888
|
interrupt_enabled: O
|
|
873
889
|
} = await D(t, n);
|
|
874
|
-
(E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id:
|
|
890
|
+
(E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: V, agent_id: e });
|
|
875
891
|
const I = new Ut({ iceServers: J }), Y = I.createDataChannel("JanusDataChannel");
|
|
876
|
-
if (!
|
|
892
|
+
if (!V)
|
|
877
893
|
throw new Error("Could not create session_id");
|
|
878
|
-
const
|
|
894
|
+
const K = X ? W.Fluent : W.Legacy;
|
|
879
895
|
o.enrich({
|
|
880
|
-
"stream-type":
|
|
896
|
+
"stream-type": K
|
|
881
897
|
});
|
|
882
898
|
const ae = t.stream_warmup && !X, ie = () => m, u = () => {
|
|
883
899
|
var f;
|
|
@@ -886,22 +902,22 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
886
902
|
() => I.getStats(),
|
|
887
903
|
ie,
|
|
888
904
|
u,
|
|
889
|
-
(f,
|
|
905
|
+
(f, p) => Ae({
|
|
890
906
|
statsSignal: v = f,
|
|
891
|
-
dataChannelSignal:
|
|
907
|
+
dataChannelSignal: K === W.Legacy ? h : void 0,
|
|
892
908
|
onVideoStateChange: a.onVideoStateChange,
|
|
893
909
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
894
|
-
report:
|
|
895
|
-
streamType:
|
|
910
|
+
report: p,
|
|
911
|
+
streamType: K,
|
|
896
912
|
log: i
|
|
897
913
|
}),
|
|
898
914
|
(f) => {
|
|
899
|
-
var
|
|
900
|
-
return (
|
|
915
|
+
var p;
|
|
916
|
+
return (p = a.onConnectivityStateChange) == null ? void 0 : p.call(a, f);
|
|
901
917
|
}
|
|
902
918
|
);
|
|
903
919
|
g.start(), I.onicecandidate = (f) => {
|
|
904
|
-
var
|
|
920
|
+
var p;
|
|
905
921
|
i("peerConnection.onicecandidate", f);
|
|
906
922
|
try {
|
|
907
923
|
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? $(
|
|
@@ -911,37 +927,37 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
911
927
|
sdpMid: f.candidate.sdpMid,
|
|
912
928
|
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
913
929
|
},
|
|
914
|
-
|
|
930
|
+
V,
|
|
915
931
|
n
|
|
916
|
-
) : $(_, { candidate: null },
|
|
932
|
+
) : $(_, { candidate: null }, V, n);
|
|
917
933
|
} catch (b) {
|
|
918
|
-
(
|
|
934
|
+
(p = a.onError) == null || p.call(a, b, { streamId: _ });
|
|
919
935
|
}
|
|
920
936
|
}, Y.onopen = () => {
|
|
921
937
|
l = !0, (!ae || m) && u();
|
|
922
938
|
};
|
|
923
|
-
let
|
|
939
|
+
let w = null;
|
|
924
940
|
const y = (f) => {
|
|
925
|
-
var
|
|
926
|
-
|
|
941
|
+
var p;
|
|
942
|
+
w = f, (p = a.onVideoIdChange) == null || p.call(a, f);
|
|
927
943
|
};
|
|
928
|
-
function C(f,
|
|
929
|
-
if (f === P.StreamStarted && typeof
|
|
930
|
-
const b =
|
|
944
|
+
function C(f, p) {
|
|
945
|
+
if (f === P.StreamStarted && typeof p == "object" && "metadata" in p) {
|
|
946
|
+
const b = p.metadata;
|
|
931
947
|
y(b.videoId);
|
|
932
948
|
}
|
|
933
|
-
f === P.StreamDone && y(null),
|
|
934
|
-
statsSignal:
|
|
935
|
-
dataChannelSignal:
|
|
949
|
+
f === P.StreamDone && y(null), h = f === P.StreamStarted ? S.Start : S.Stop, Ae({
|
|
950
|
+
statsSignal: K === W.Legacy ? v : void 0,
|
|
951
|
+
dataChannelSignal: h,
|
|
936
952
|
onVideoStateChange: a.onVideoStateChange,
|
|
937
953
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
938
|
-
streamType:
|
|
954
|
+
streamType: K,
|
|
939
955
|
log: i
|
|
940
956
|
});
|
|
941
957
|
}
|
|
942
|
-
function R(f,
|
|
958
|
+
function R(f, p) {
|
|
943
959
|
var T;
|
|
944
|
-
const b = typeof
|
|
960
|
+
const b = typeof p == "string" ? p : p == null ? void 0 : p.metadata;
|
|
945
961
|
b && o.enrich({ streamMetadata: b }), (T = a.onStreamReady) == null || T.call(a);
|
|
946
962
|
}
|
|
947
963
|
const j = {
|
|
@@ -951,23 +967,23 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
951
967
|
};
|
|
952
968
|
Y.onmessage = (f) => {
|
|
953
969
|
var T;
|
|
954
|
-
const { subject:
|
|
955
|
-
(T = j[
|
|
970
|
+
const { subject: p, data: b } = d(f.data);
|
|
971
|
+
(T = j[p]) == null || T.call(j, p, b);
|
|
956
972
|
}, I.oniceconnectionstatechange = () => {
|
|
957
|
-
var
|
|
973
|
+
var p;
|
|
958
974
|
i("peerConnection.oniceconnectionstatechange => " + I.iceConnectionState);
|
|
959
975
|
const f = be(I.iceConnectionState);
|
|
960
|
-
f !== L.Connected && ((
|
|
976
|
+
f !== L.Connected && ((p = a.onConnectionStateChange) == null || p.call(a, f));
|
|
961
977
|
}, I.ontrack = (f) => {
|
|
962
|
-
var
|
|
963
|
-
i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (
|
|
978
|
+
var p;
|
|
979
|
+
i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (p = a.onSrcObjectReady) == null || p.call(a, f.streams[0]);
|
|
964
980
|
}, await I.setRemoteDescription(q), i("set remote description OK");
|
|
965
981
|
const z = await I.createAnswer();
|
|
966
|
-
i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await k(_, z,
|
|
982
|
+
i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await k(_, z, V, n), i("start connection OK");
|
|
967
983
|
function F(f) {
|
|
968
|
-
var
|
|
984
|
+
var p, b;
|
|
969
985
|
if (!m || Y.readyState !== "open") {
|
|
970
|
-
i("Data channel is not ready for sending messages"), (
|
|
986
|
+
i("Data channel is not ready for sending messages"), (p = a.onError) == null || p.call(a, new Error("Data channel is not ready for sending messages"), {
|
|
971
987
|
streamId: _
|
|
972
988
|
});
|
|
973
989
|
return;
|
|
@@ -984,7 +1000,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
984
1000
|
* @param payload
|
|
985
1001
|
*/
|
|
986
1002
|
speak(f) {
|
|
987
|
-
return B(_,
|
|
1003
|
+
return B(_, V, f);
|
|
988
1004
|
},
|
|
989
1005
|
/**
|
|
990
1006
|
* Method to close RTC connection
|
|
@@ -992,16 +1008,16 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
992
1008
|
async disconnect() {
|
|
993
1009
|
var f;
|
|
994
1010
|
if (_) {
|
|
995
|
-
const
|
|
1011
|
+
const p = be(I.iceConnectionState);
|
|
996
1012
|
if (I) {
|
|
997
|
-
if (
|
|
1013
|
+
if (p === L.New) {
|
|
998
1014
|
g.stop();
|
|
999
1015
|
return;
|
|
1000
1016
|
}
|
|
1001
1017
|
I.close(), I.oniceconnectionstatechange = null, I.onnegotiationneeded = null, I.onicecandidate = null, I.ontrack = null;
|
|
1002
1018
|
}
|
|
1003
1019
|
try {
|
|
1004
|
-
|
|
1020
|
+
p === L.Connected && await M(_, V).catch((b) => {
|
|
1005
1021
|
});
|
|
1006
1022
|
} catch (b) {
|
|
1007
1023
|
i("Error on close stream connection", b);
|
|
@@ -1013,27 +1029,27 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
1013
1029
|
/**
|
|
1014
1030
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1015
1031
|
*/
|
|
1016
|
-
sessionId:
|
|
1032
|
+
sessionId: V,
|
|
1017
1033
|
/**
|
|
1018
1034
|
* Id of current RTC stream
|
|
1019
1035
|
*/
|
|
1020
1036
|
streamId: _,
|
|
1021
|
-
streamType:
|
|
1037
|
+
streamType: K,
|
|
1022
1038
|
interruptAvailable: O ?? !1,
|
|
1023
1039
|
isInterruptible: !0,
|
|
1024
1040
|
interrupt(f) {
|
|
1025
1041
|
if (!O)
|
|
1026
1042
|
throw new Error("Interrupt is not enabled for this stream");
|
|
1027
|
-
if (
|
|
1043
|
+
if (K !== W.Fluent)
|
|
1028
1044
|
throw new Error("Interrupt only available for Fluent streams");
|
|
1029
|
-
if (!
|
|
1045
|
+
if (!w)
|
|
1030
1046
|
throw new Error("No active video to interrupt");
|
|
1031
|
-
const
|
|
1047
|
+
const p = {
|
|
1032
1048
|
type: P.StreamInterrupt,
|
|
1033
|
-
videoId:
|
|
1049
|
+
videoId: w,
|
|
1034
1050
|
timestamp: Date.now()
|
|
1035
1051
|
};
|
|
1036
|
-
F(JSON.stringify(
|
|
1052
|
+
F(JSON.stringify(p));
|
|
1037
1053
|
}
|
|
1038
1054
|
};
|
|
1039
1055
|
}
|
|
@@ -1049,7 +1065,7 @@ async function qt(e, t, r, a) {
|
|
|
1049
1065
|
const { version: s, ...o } = t;
|
|
1050
1066
|
switch (o.transport.provider) {
|
|
1051
1067
|
case he.Livekit:
|
|
1052
|
-
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-
|
|
1068
|
+
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-B7gYoJ6B.js");
|
|
1053
1069
|
return n(c, o, r);
|
|
1054
1070
|
default:
|
|
1055
1071
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
@@ -1167,23 +1183,23 @@ function Le(e, t, r, a) {
|
|
|
1167
1183
|
analytics: r,
|
|
1168
1184
|
callbacks: {
|
|
1169
1185
|
...t.callbacks,
|
|
1170
|
-
onConnectionStateChange: (l,
|
|
1186
|
+
onConnectionStateChange: (l, h) => {
|
|
1171
1187
|
var v, k;
|
|
1172
|
-
(k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Zt(l,
|
|
1188
|
+
(k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Zt(l, h, r), l === L.Connected && (o ? c(o) : n = !0);
|
|
1173
1189
|
},
|
|
1174
|
-
onVideoStateChange: (l,
|
|
1190
|
+
onVideoStateChange: (l, h) => {
|
|
1175
1191
|
var v, k;
|
|
1176
1192
|
(k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l), er(
|
|
1177
1193
|
l,
|
|
1178
1194
|
e,
|
|
1179
|
-
|
|
1195
|
+
h,
|
|
1180
1196
|
r,
|
|
1181
1197
|
o.streamType
|
|
1182
1198
|
);
|
|
1183
1199
|
},
|
|
1184
1200
|
onAgentActivityStateChange: (l) => {
|
|
1185
|
-
var
|
|
1186
|
-
(v = (
|
|
1201
|
+
var h, v;
|
|
1202
|
+
(v = (h = t.callbacks).onAgentActivityStateChange) == null || v.call(h, l), l === ne.Talking ? (fe.update(), d = (k) => {
|
|
1187
1203
|
xe(
|
|
1188
1204
|
S.Start,
|
|
1189
1205
|
e,
|
|
@@ -1205,9 +1221,9 @@ function Le(e, t, r, a) {
|
|
|
1205
1221
|
const l = Te.get(!0);
|
|
1206
1222
|
r.track("agent-chat", { event: "ready", latency: l });
|
|
1207
1223
|
},
|
|
1208
|
-
onToolEvent: (l,
|
|
1224
|
+
onToolEvent: (l, h) => {
|
|
1209
1225
|
var v, k;
|
|
1210
|
-
(k = (v = t.callbacks).onToolEvent) == null || k.call(v, l,
|
|
1226
|
+
(k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, h), nr(l, h, r);
|
|
1211
1227
|
}
|
|
1212
1228
|
}
|
|
1213
1229
|
},
|
|
@@ -1219,7 +1235,7 @@ function Le(e, t, r, a) {
|
|
|
1219
1235
|
});
|
|
1220
1236
|
}
|
|
1221
1237
|
async function ar(e, t, r, a, c) {
|
|
1222
|
-
var m, l,
|
|
1238
|
+
var m, l, h, v;
|
|
1223
1239
|
const s = async () => {
|
|
1224
1240
|
if (pe(e.presenter.type)) {
|
|
1225
1241
|
const k = await Le(e, t, a), B = `${Xt}_${k.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -1256,10 +1272,10 @@ async function ar(e, t, r, a, c) {
|
|
|
1256
1272
|
}
|
|
1257
1273
|
}
|
|
1258
1274
|
}, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
|
|
1259
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (
|
|
1275
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (h = t.callbacks).onError) == null || v.call(h, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
|
|
1260
1276
|
}
|
|
1261
1277
|
async function dr(e, t) {
|
|
1262
|
-
var Y,
|
|
1278
|
+
var Y, K, ae, ie;
|
|
1263
1279
|
let r = !0;
|
|
1264
1280
|
const a = t.mixpanelKey || ot, c = t.wsURL || st, s = t.baseURL || de, o = t.mode || x.Functional, n = {
|
|
1265
1281
|
messages: [],
|
|
@@ -1276,17 +1292,17 @@ async function dr(e, t) {
|
|
|
1276
1292
|
});
|
|
1277
1293
|
const m = wt(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
|
|
1278
1294
|
t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
|
|
1279
|
-
const
|
|
1295
|
+
const h = pe(l.presenter.type);
|
|
1280
1296
|
i.enrich(yt(l));
|
|
1281
1297
|
const { onMessage: v, clearQueue: k } = xt(i, n, t, l, () => {
|
|
1282
|
-
var u, g,
|
|
1283
|
-
(u = n.socketManager) == null || u.disconnect(), (
|
|
1298
|
+
var u, g, w;
|
|
1299
|
+
(u = n.socketManager) == null || u.disconnect(), (w = (g = t.callbacks).onConnectionStateChange) == null || w.call(g, L.Disconnected);
|
|
1284
1300
|
});
|
|
1285
|
-
n.messages = It(t.initialMessages), (ae = (
|
|
1301
|
+
n.messages = It(t.initialMessages), (ae = (K = t.callbacks).onNewMessage) == null || ae.call(K, [...n.messages], "answer");
|
|
1286
1302
|
const B = (u) => {
|
|
1287
1303
|
}, M = ({ type: u }) => {
|
|
1288
|
-
var
|
|
1289
|
-
if (!((
|
|
1304
|
+
var w, y, C, R;
|
|
1305
|
+
if (!((w = n.streamingManager) != null && w.interruptAvailable) || !((y = n.streamingManager) != null && y.isInterruptible)) return;
|
|
1290
1306
|
const g = n.messages[n.messages.length - 1];
|
|
1291
1307
|
i.track("agent-video-interrupt", {
|
|
1292
1308
|
type: u || "click",
|
|
@@ -1296,44 +1312,44 @@ async function dr(e, t) {
|
|
|
1296
1312
|
}, D = /* @__PURE__ */ new Map();
|
|
1297
1313
|
function $(u) {
|
|
1298
1314
|
return async (g) => {
|
|
1299
|
-
const
|
|
1300
|
-
if (!
|
|
1315
|
+
const w = D.get(u);
|
|
1316
|
+
if (!w)
|
|
1301
1317
|
throw new Error(`No handler registered for client tool: ${u}`);
|
|
1302
1318
|
try {
|
|
1303
1319
|
const y = JSON.parse(g.payload);
|
|
1304
|
-
return await
|
|
1320
|
+
return await w(y);
|
|
1305
1321
|
} catch (y) {
|
|
1306
1322
|
throw new Error(`Client tool "${u}" failed: ${y.message}`);
|
|
1307
1323
|
}
|
|
1308
1324
|
};
|
|
1309
1325
|
}
|
|
1310
1326
|
function _() {
|
|
1311
|
-
var u, g,
|
|
1327
|
+
var u, g, w, y;
|
|
1312
1328
|
for (const [C] of D)
|
|
1313
|
-
(g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, C), (y = (
|
|
1329
|
+
(g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, C), (y = (w = n.streamingManager) == null ? void 0 : w.registerRpcMethod) == null || y.call(w, C, $(C));
|
|
1314
1330
|
}
|
|
1315
1331
|
function q(u, g) {
|
|
1316
1332
|
var y, C;
|
|
1317
|
-
const
|
|
1318
|
-
D.set(u, g),
|
|
1333
|
+
const w = !D.has(u);
|
|
1334
|
+
D.set(u, g), w && ((C = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, u, $(u)));
|
|
1319
1335
|
}
|
|
1320
1336
|
function J(u) {
|
|
1321
|
-
var g,
|
|
1322
|
-
D.delete(u), (
|
|
1337
|
+
var g, w;
|
|
1338
|
+
D.delete(u), (w = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || w.call(g, u);
|
|
1323
1339
|
}
|
|
1324
|
-
const
|
|
1340
|
+
const V = Date.now();
|
|
1325
1341
|
Ee(() => {
|
|
1326
|
-
i.track("agent-sdk", { event: "loaded", ...vt(l) },
|
|
1342
|
+
i.track("agent-sdk", { event: "loaded", ...vt(l) }, V);
|
|
1327
1343
|
});
|
|
1328
1344
|
async function X(u) {
|
|
1329
|
-
var j, z, F, E, f,
|
|
1345
|
+
var j, z, F, E, f, p, b;
|
|
1330
1346
|
(z = (j = t.callbacks).onConnectionStateChange) == null || z.call(j, L.Connecting), H.reset(), u && !r && (delete n.chat, (E = (F = t.callbacks).onNewMessage) == null || E.call(F, [...n.messages], "answer"));
|
|
1331
|
-
const g = o === x.DirectPlayback ||
|
|
1347
|
+
const g = o === x.DirectPlayback || h ? Promise.resolve(void 0) : Tt(
|
|
1332
1348
|
t.auth,
|
|
1333
1349
|
c,
|
|
1334
1350
|
{ onMessage: v, onError: t.callbacks.onError },
|
|
1335
1351
|
t.externalId
|
|
1336
|
-
),
|
|
1352
|
+
), w = ue(
|
|
1337
1353
|
() => ar(
|
|
1338
1354
|
l,
|
|
1339
1355
|
{
|
|
@@ -1357,22 +1373,22 @@ async function dr(e, t) {
|
|
|
1357
1373
|
delayMs: 1e3
|
|
1358
1374
|
}
|
|
1359
1375
|
).catch((T) => {
|
|
1360
|
-
var A,
|
|
1361
|
-
throw I(x.Maintenance), (
|
|
1362
|
-
}), [y, { streamingManager: C, chat: R }] = await Promise.all([g,
|
|
1363
|
-
R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (
|
|
1376
|
+
var A, U;
|
|
1377
|
+
throw I(x.Maintenance), (U = (A = t.callbacks).onConnectionStateChange) == null || U.call(A, L.Fail), T;
|
|
1378
|
+
}), [y, { streamingManager: C, chat: R }] = await Promise.all([g, w]);
|
|
1379
|
+
R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (p = t.callbacks).onNewChat) == null || b.call(p, R.id)), n.streamingManager = C, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
|
|
1364
1380
|
chatId: R == null ? void 0 : R.id,
|
|
1365
1381
|
streamId: C == null ? void 0 : C.streamId,
|
|
1366
1382
|
mode: n.chatMode
|
|
1367
1383
|
}), I((R == null ? void 0 : R.chat_mode) ?? o);
|
|
1368
1384
|
}
|
|
1369
1385
|
async function O() {
|
|
1370
|
-
var u, g,
|
|
1371
|
-
(u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (
|
|
1386
|
+
var u, g, w, y;
|
|
1387
|
+
(u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (w = t.callbacks).onConnectionStateChange) == null || y.call(w, L.Disconnected);
|
|
1372
1388
|
}
|
|
1373
1389
|
async function I(u) {
|
|
1374
|
-
var g,
|
|
1375
|
-
u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (
|
|
1390
|
+
var g, w;
|
|
1391
|
+
u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (w = (g = t.callbacks).onModeChange) == null || w.call(g, u));
|
|
1376
1392
|
}
|
|
1377
1393
|
return {
|
|
1378
1394
|
agent: l,
|
|
@@ -1396,7 +1412,7 @@ async function dr(e, t) {
|
|
|
1396
1412
|
},
|
|
1397
1413
|
async reconnect() {
|
|
1398
1414
|
const u = n.streamingManager;
|
|
1399
|
-
if (
|
|
1415
|
+
if (h && (u != null && u.reconnect)) {
|
|
1400
1416
|
try {
|
|
1401
1417
|
await u.reconnect(), i.track("agent-chat", {
|
|
1402
1418
|
event: "reconnect",
|
|
@@ -1455,35 +1471,35 @@ async function dr(e, t) {
|
|
|
1455
1471
|
if (!n.chat)
|
|
1456
1472
|
throw new G("Chat is not initialized");
|
|
1457
1473
|
}
|
|
1458
|
-
},
|
|
1474
|
+
}, w = async () => {
|
|
1459
1475
|
var E, f;
|
|
1460
1476
|
if (!n.chat) {
|
|
1461
|
-
const
|
|
1477
|
+
const p = await Ve(
|
|
1462
1478
|
l,
|
|
1463
1479
|
m,
|
|
1464
1480
|
i,
|
|
1465
1481
|
n.chatMode,
|
|
1466
1482
|
t.persistentChat
|
|
1467
1483
|
);
|
|
1468
|
-
if (!
|
|
1484
|
+
if (!p.chat)
|
|
1469
1485
|
throw new Oe(n.chatMode, !!t.persistentChat);
|
|
1470
|
-
n.chat =
|
|
1486
|
+
n.chat = p.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
|
|
1471
1487
|
}
|
|
1472
1488
|
return n.chat.id;
|
|
1473
1489
|
}, y = async (E, f) => {
|
|
1474
|
-
const
|
|
1475
|
-
return ue(
|
|
1476
|
-
var A,
|
|
1477
|
-
return await ((
|
|
1490
|
+
const p = n.chatMode === x.Playground;
|
|
1491
|
+
return ue(h && !p ? async () => {
|
|
1492
|
+
var A, U;
|
|
1493
|
+
return await ((U = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : U.call(A, u)), Promise.resolve({});
|
|
1478
1494
|
} : async () => {
|
|
1479
|
-
var A,
|
|
1495
|
+
var A, U;
|
|
1480
1496
|
return m.chat(
|
|
1481
1497
|
l.id,
|
|
1482
1498
|
f,
|
|
1483
1499
|
{
|
|
1484
1500
|
chatMode: n.chatMode,
|
|
1485
1501
|
streamId: (A = n.streamingManager) == null ? void 0 : A.streamId,
|
|
1486
|
-
sessionId: (
|
|
1502
|
+
sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
|
|
1487
1503
|
messages: E.map(({ matches: Ue, ...se }) => se)
|
|
1488
1504
|
},
|
|
1489
1505
|
{
|
|
@@ -1495,8 +1511,8 @@ async function dr(e, t) {
|
|
|
1495
1511
|
limit: 2,
|
|
1496
1512
|
shouldRetryFn: (A) => {
|
|
1497
1513
|
var se, ve, ye, Ce;
|
|
1498
|
-
const
|
|
1499
|
-
return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !
|
|
1514
|
+
const U = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
|
|
1515
|
+
return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !U ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
|
|
1500
1516
|
},
|
|
1501
1517
|
onRetry: async () => {
|
|
1502
1518
|
await O(), await X(!1);
|
|
@@ -1511,12 +1527,12 @@ async function dr(e, t) {
|
|
|
1511
1527
|
parts: re(u),
|
|
1512
1528
|
created_at: new Date(H.update()).toISOString()
|
|
1513
1529
|
}), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "user");
|
|
1514
|
-
const E = await
|
|
1515
|
-
return n.messages.push({
|
|
1530
|
+
const E = await w(), f = await y([...n.messages], E);
|
|
1531
|
+
return f.result && n.messages.push({
|
|
1516
1532
|
id: Q(),
|
|
1517
1533
|
role: "assistant",
|
|
1518
|
-
content: f.result
|
|
1519
|
-
parts: re(f.result
|
|
1534
|
+
content: f.result,
|
|
1535
|
+
parts: re(f.result),
|
|
1520
1536
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1521
1537
|
context: f.context,
|
|
1522
1538
|
matches: f.matches
|
|
@@ -1534,7 +1550,7 @@ async function dr(e, t) {
|
|
|
1534
1550
|
}), E;
|
|
1535
1551
|
}
|
|
1536
1552
|
},
|
|
1537
|
-
rate(u, g,
|
|
1553
|
+
rate(u, g, w) {
|
|
1538
1554
|
var R, j, z, F;
|
|
1539
1555
|
const y = n.messages.find((E) => E.id === u);
|
|
1540
1556
|
if (n.chat) {
|
|
@@ -1543,12 +1559,12 @@ async function dr(e, t) {
|
|
|
1543
1559
|
} else throw new Error("Chat is not initialized");
|
|
1544
1560
|
const C = ((R = y.matches) == null ? void 0 : R.map((E) => [E.document_id, E.id])) ?? [];
|
|
1545
1561
|
return i.track("agent-rate", {
|
|
1546
|
-
event:
|
|
1562
|
+
event: w ? "update" : "create",
|
|
1547
1563
|
thumb: g === 1 ? "up" : "down",
|
|
1548
1564
|
knowledge_id: ((j = l.knowledge) == null ? void 0 : j.id) ?? "",
|
|
1549
1565
|
matches: C,
|
|
1550
1566
|
score: g
|
|
1551
|
-
}),
|
|
1567
|
+
}), w ? m.updateRating(l.id, n.chat.id, w, {
|
|
1552
1568
|
knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1553
1569
|
message_id: u,
|
|
1554
1570
|
matches: C,
|
|
@@ -1590,12 +1606,12 @@ async function dr(e, t) {
|
|
|
1590
1606
|
}
|
|
1591
1607
|
return u;
|
|
1592
1608
|
}
|
|
1593
|
-
const
|
|
1594
|
-
if (i.track("agent-speak",
|
|
1609
|
+
const w = g();
|
|
1610
|
+
if (i.track("agent-speak", w), H.update(), n.messages && w.type === "text" && (n.messages.push({
|
|
1595
1611
|
id: Q(),
|
|
1596
1612
|
role: "assistant",
|
|
1597
|
-
content:
|
|
1598
|
-
parts: re(
|
|
1613
|
+
content: w.input,
|
|
1614
|
+
parts: re(w.input),
|
|
1599
1615
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1600
1616
|
}), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer")), lt(n.chatMode))
|
|
1601
1617
|
return {
|
|
@@ -1606,7 +1622,7 @@ async function dr(e, t) {
|
|
|
1606
1622
|
if (!n.streamingManager)
|
|
1607
1623
|
throw new Error("Please connect to the agent first");
|
|
1608
1624
|
return n.streamingManager.speak({
|
|
1609
|
-
script:
|
|
1625
|
+
script: w,
|
|
1610
1626
|
metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: l.id }
|
|
1611
1627
|
});
|
|
1612
1628
|
},
|
|
@@ -1617,7 +1633,7 @@ async function dr(e, t) {
|
|
|
1617
1633
|
}
|
|
1618
1634
|
export {
|
|
1619
1635
|
ne as A,
|
|
1620
|
-
|
|
1636
|
+
N as C,
|
|
1621
1637
|
tt as D,
|
|
1622
1638
|
et as K,
|
|
1623
1639
|
Ye as P,
|