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