@d-id/client-sdk 1.1.56-staging.255 → 1.1.56-staging.256
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.js +128 -130
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -618,22 +618,22 @@ async function un(e, n, i) {
|
|
|
618
618
|
});
|
|
619
619
|
let K = null, G = W.Idle, ae = !0;
|
|
620
620
|
const $ = Yt(c, h || we, e, t.onError);
|
|
621
|
-
let
|
|
621
|
+
let m, C, E, J = !0;
|
|
622
622
|
try {
|
|
623
623
|
const u = await $.createStream({
|
|
624
624
|
transport: n.transport,
|
|
625
625
|
chat_persist: n.chat_persist ?? !0
|
|
626
|
-
}), { id:
|
|
627
|
-
(ze = t.onStreamCreated) == null || ze.call(t, { session_id:
|
|
626
|
+
}), { id: f, session_token: p, session_url: v, interrupt_enabled: I } = u;
|
|
627
|
+
(ze = t.onStreamCreated) == null || ze.call(t, { session_id: f, stream_id: f, agent_id: e }), m = f, C = p, E = v, J = I ?? !0, await l.prepareConnection(E, C);
|
|
628
628
|
} catch (u) {
|
|
629
629
|
_e(u, r, t);
|
|
630
630
|
}
|
|
631
|
-
if (!E || !C || !
|
|
631
|
+
if (!E || !C || !m)
|
|
632
632
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
633
633
|
l.on(a.ConnectionStateChanged, M).on(a.ConnectionQualityChanged, V).on(a.ParticipantConnected, Y).on(a.ParticipantDisconnected, Z).on(a.TrackSubscribed, ee).on(a.TrackUnsubscribed, S).on(a.DataReceived, ve).on(a.MediaDevicesError, Ce).on(a.TranscriptionReceived, x).on(a.EncryptionError, dt).on(a.TrackSubscriptionFailed, ut);
|
|
634
|
-
function x(u,
|
|
634
|
+
function x(u, f) {
|
|
635
635
|
var p;
|
|
636
|
-
|
|
636
|
+
f != null && f.isLocal && (re.update(), G === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), G = W.Idle));
|
|
637
637
|
}
|
|
638
638
|
try {
|
|
639
639
|
await l.connect(E, C), r("LiveKit room joined successfully"), K = setTimeout(() => {
|
|
@@ -642,8 +642,8 @@ async function un(e, n, i) {
|
|
|
642
642
|
`Track subscription timeout - no track subscribed within ${qe / 1e3} seconds after connect`
|
|
643
643
|
), K = null, g.track("connectivity-error", {
|
|
644
644
|
error: "Track subscription timeout",
|
|
645
|
-
sessionId:
|
|
646
|
-
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId:
|
|
645
|
+
sessionId: m
|
|
646
|
+
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: m }), De("internal:track-subscription-timeout");
|
|
647
647
|
}, qe);
|
|
648
648
|
} catch (u) {
|
|
649
649
|
_e(u, r, t);
|
|
@@ -652,10 +652,10 @@ async function un(e, n, i) {
|
|
|
652
652
|
"stream-type": A
|
|
653
653
|
});
|
|
654
654
|
function M(u) {
|
|
655
|
-
var
|
|
655
|
+
var f, p, v, I;
|
|
656
656
|
switch (r("Connection state changed:", u), u) {
|
|
657
657
|
case s.Connecting:
|
|
658
|
-
r("CALLBACK: onConnectionStateChange(Connecting)"), (
|
|
658
|
+
r("CALLBACK: onConnectionStateChange(Connecting)"), (f = t.onConnectionStateChange) == null || f.call(t, b.Connecting, "livekit:connecting");
|
|
659
659
|
break;
|
|
660
660
|
case s.Connected:
|
|
661
661
|
r("LiveKit room connected successfully"), y = !0;
|
|
@@ -671,9 +671,9 @@ async function un(e, n, i) {
|
|
|
671
671
|
break;
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
|
-
function V(u,
|
|
674
|
+
function V(u, f) {
|
|
675
675
|
var p;
|
|
676
|
-
r("Connection quality:", u),
|
|
676
|
+
r("Connection quality:", u), f != null && f.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, dn[u]));
|
|
677
677
|
}
|
|
678
678
|
function Y(u) {
|
|
679
679
|
r("Participant connected:", u.identity);
|
|
@@ -686,10 +686,10 @@ async function un(e, n, i) {
|
|
|
686
686
|
H !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), H = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
|
|
687
687
|
}
|
|
688
688
|
function U(u) {
|
|
689
|
-
var
|
|
690
|
-
H !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), H = T.Stop, (
|
|
689
|
+
var f;
|
|
690
|
+
H !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), H = T.Stop, (f = t.onVideoStateChange) == null || f.call(t, T.Stop, u));
|
|
691
691
|
}
|
|
692
|
-
function ee(u,
|
|
692
|
+
function ee(u, f, p) {
|
|
693
693
|
var I, P, Q;
|
|
694
694
|
r(`Track subscribed: ${u.kind} from ${p.identity}`);
|
|
695
695
|
const v = u.mediaStreamTrack;
|
|
@@ -701,13 +701,13 @@ async function un(e, n, i) {
|
|
|
701
701
|
() => u.getRTCStatsReport(),
|
|
702
702
|
({ sttLatency: N, serviceLatency: te }) => {
|
|
703
703
|
var Ke, Ne, Ve;
|
|
704
|
-
const
|
|
705
|
-
let
|
|
704
|
+
const fe = re.get(!0);
|
|
705
|
+
let me = 0;
|
|
706
706
|
if (N) {
|
|
707
707
|
const Ue = ((Ne = (Ke = _ == null ? void 0 : _.getReport()) == null ? void 0 : Ke.webRTCStats) == null ? void 0 : Ne.avgRtt) ?? 0;
|
|
708
|
-
|
|
708
|
+
me = Ue > 0 ? Math.round(Ue * 1e3) : 0;
|
|
709
709
|
}
|
|
710
|
-
const de =
|
|
710
|
+
const de = fe > 0 ? fe + (N ?? 0) + me : void 0, oe = de !== void 0 && te !== void 0 ? de - te : void 0;
|
|
711
711
|
(Ve = t.onFirstAudioDetected) == null || Ve.call(t, { latency: de, networkLatency: oe });
|
|
712
712
|
}
|
|
713
713
|
)), u.kind === "video" && ((I = t.onStreamReady) == null || I.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, z), q || (q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (Q = t.onConnectionStateChange) == null || Q.call(t, b.Connected, "livekit:track-subscribed")), _ = ct(
|
|
@@ -719,44 +719,44 @@ async function un(e, n, i) {
|
|
|
719
719
|
}
|
|
720
720
|
), _.start());
|
|
721
721
|
}
|
|
722
|
-
function S(u,
|
|
722
|
+
function S(u, f, p) {
|
|
723
723
|
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (U(_ == null ? void 0 : _.getReport()), _ == null || _.stop(), _ = null);
|
|
724
724
|
}
|
|
725
|
-
function w(u,
|
|
725
|
+
function w(u, f) {
|
|
726
726
|
var v;
|
|
727
727
|
const p = Gt[u];
|
|
728
|
-
p && ((v = t.onMessage) == null || v.call(t, p, { event: p, ...
|
|
728
|
+
p && ((v = t.onMessage) == null || v.call(t, p, { event: p, ...f }));
|
|
729
729
|
}
|
|
730
|
-
function R(u,
|
|
730
|
+
function R(u, f) {
|
|
731
731
|
var p, v, I;
|
|
732
732
|
if (u === D.ToolCalling) {
|
|
733
|
-
G = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (v = t.onToolEvent) == null || v.call(t, D.ToolCalling,
|
|
733
|
+
G = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (v = t.onToolEvent) == null || v.call(t, D.ToolCalling, f);
|
|
734
734
|
return;
|
|
735
735
|
}
|
|
736
|
-
u === D.ToolResult && ((I = t.onToolEvent) == null || I.call(t, D.ToolResult,
|
|
736
|
+
u === D.ToolResult && ((I = t.onToolEvent) == null || I.call(t, D.ToolResult, f));
|
|
737
737
|
}
|
|
738
|
-
function F(u,
|
|
738
|
+
function F(u, f) {
|
|
739
739
|
var p, v, I, P, Q;
|
|
740
|
-
if (ae = ((p =
|
|
740
|
+
if (ae = ((p = f.metadata) == null ? void 0 : p.interruptible) !== !1, (v = t.onInterruptibleChange) == null || v.call(t, ae), u === D.StreamVideoCreated) {
|
|
741
741
|
G = W.Talking, (I = t.onAgentActivityStateChange) == null || I.call(t, W.Talking), k == null || k.arm({
|
|
742
|
-
sttLatency: (P =
|
|
743
|
-
serviceLatency:
|
|
742
|
+
sttLatency: (P = f == null ? void 0 : f.stt) == null ? void 0 : P.latency,
|
|
743
|
+
serviceLatency: f == null ? void 0 : f.serviceLatency
|
|
744
744
|
});
|
|
745
745
|
return;
|
|
746
746
|
}
|
|
747
747
|
ae && (G = W.Idle, (Q = t.onAgentActivityStateChange) == null || Q.call(t, W.Idle));
|
|
748
748
|
}
|
|
749
|
-
function se(u,
|
|
749
|
+
function se(u, f) {
|
|
750
750
|
var P, Q, N, te;
|
|
751
|
-
const p = ((Q = (P = _ == null ? void 0 : _.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : Q.avgRtt) ?? 0, v = p > 0 ? Math.round(p / 2 * 1e3) : 0, I = { ...
|
|
752
|
-
i.debug && ((N =
|
|
753
|
-
id:
|
|
754
|
-
name:
|
|
755
|
-
}), (te = t.onMessage) == null || te.call(t, u, I), F(u,
|
|
751
|
+
const p = ((Q = (P = _ == null ? void 0 : _.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : Q.avgRtt) ?? 0, v = p > 0 ? Math.round(p / 2 * 1e3) : 0, I = { ...f, downstreamNetworkLatency: v };
|
|
752
|
+
i.debug && ((N = f == null ? void 0 : f.metadata) != null && N.sentiment) && (I.sentiment = {
|
|
753
|
+
id: f.metadata.sentiment.id,
|
|
754
|
+
name: f.metadata.sentiment.sentiment
|
|
755
|
+
}), (te = t.onMessage) == null || te.call(t, u, I), F(u, f);
|
|
756
756
|
}
|
|
757
|
-
function ce(u,
|
|
757
|
+
function ce(u, f) {
|
|
758
758
|
var p;
|
|
759
|
-
(p = t.onMessage) == null || p.call(t, X.Transcribe, { event: X.Transcribe, ...
|
|
759
|
+
(p = t.onMessage) == null || p.call(t, X.Transcribe, { event: X.Transcribe, ...f }), queueMicrotask(() => {
|
|
760
760
|
var v;
|
|
761
761
|
(v = t.onAgentActivityStateChange) == null || v.call(t, W.Loading);
|
|
762
762
|
});
|
|
@@ -772,7 +772,7 @@ async function un(e, n, i) {
|
|
|
772
772
|
[D.StreamVideoRejected]: se,
|
|
773
773
|
[D.ChatAudioTranscribed]: ce
|
|
774
774
|
};
|
|
775
|
-
function ve(u,
|
|
775
|
+
function ve(u, f, p, v) {
|
|
776
776
|
const I = new TextDecoder().decode(u);
|
|
777
777
|
try {
|
|
778
778
|
const P = JSON.parse(I), Q = v || P.subject;
|
|
@@ -784,41 +784,41 @@ async function un(e, n, i) {
|
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
786
|
function Ce(u) {
|
|
787
|
-
var
|
|
788
|
-
r("Media devices error:", u), (
|
|
787
|
+
var f;
|
|
788
|
+
r("Media devices error:", u), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
|
|
789
789
|
}
|
|
790
790
|
function dt(u) {
|
|
791
|
-
var
|
|
792
|
-
r("Encryption error:", u), (
|
|
791
|
+
var f;
|
|
792
|
+
r("Encryption error:", u), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
|
|
793
793
|
}
|
|
794
|
-
function ut(u,
|
|
795
|
-
r("Track subscription failed:", { trackSid: u, participant:
|
|
794
|
+
function ut(u, f, p) {
|
|
795
|
+
r("Track subscription failed:", { trackSid: u, participant: f, reason: p });
|
|
796
796
|
}
|
|
797
|
-
function lt(u,
|
|
797
|
+
function lt(u, f, p) {
|
|
798
798
|
for (const [v, I] of p)
|
|
799
|
-
if (I.source ===
|
|
799
|
+
if (I.source === f && I.track) {
|
|
800
800
|
const P = I.track.mediaStreamTrack;
|
|
801
801
|
if (P === u || (P == null ? void 0 : P.id) === u.id)
|
|
802
802
|
return I;
|
|
803
803
|
}
|
|
804
804
|
return null;
|
|
805
805
|
}
|
|
806
|
-
async function Be(u,
|
|
807
|
-
var
|
|
806
|
+
async function Be(u, f, p, v, I, P) {
|
|
807
|
+
var fe, me, de;
|
|
808
808
|
if (!y || !l)
|
|
809
809
|
throw r(`Room is not connected, cannot publish ${v} stream`), new Error("Room is not connected");
|
|
810
810
|
if (u.isPublishing) {
|
|
811
811
|
r(`${v} publish already in progress, skipping`);
|
|
812
812
|
return;
|
|
813
813
|
}
|
|
814
|
-
const Q = p(
|
|
814
|
+
const Q = p(f);
|
|
815
815
|
if (Q.length === 0)
|
|
816
816
|
throw new Error(`No ${v} track found in the provided MediaStream`);
|
|
817
817
|
const N = Q[0], te = lt(N, v, I());
|
|
818
818
|
if (te) {
|
|
819
819
|
r(`${v} track is already published, skipping`, {
|
|
820
820
|
trackId: N.id,
|
|
821
|
-
publishedTrackId: (
|
|
821
|
+
publishedTrackId: (me = (fe = te.track) == null ? void 0 : fe.mediaStreamTrack) == null ? void 0 : me.id
|
|
822
822
|
}), u.publication = te;
|
|
823
823
|
return;
|
|
824
824
|
}
|
|
@@ -835,21 +835,21 @@ async function un(e, n, i) {
|
|
|
835
835
|
u.isPublishing = !1;
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
|
-
async function Fe(u,
|
|
838
|
+
async function Fe(u, f) {
|
|
839
839
|
if (!(!u.publication || !u.publication.track))
|
|
840
840
|
try {
|
|
841
|
-
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${
|
|
841
|
+
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${f} track unpublished`));
|
|
842
842
|
} catch (p) {
|
|
843
|
-
r(`Error unpublishing ${
|
|
843
|
+
r(`Error unpublishing ${f} track:`, p);
|
|
844
844
|
} finally {
|
|
845
845
|
u.publication = null;
|
|
846
846
|
}
|
|
847
847
|
}
|
|
848
|
-
async function
|
|
848
|
+
async function ft(u) {
|
|
849
849
|
return Be(
|
|
850
850
|
L,
|
|
851
851
|
u,
|
|
852
|
-
(
|
|
852
|
+
(f) => f.getAudioTracks(),
|
|
853
853
|
d.Source.Microphone,
|
|
854
854
|
() => l.localParticipant.audioTrackPublications,
|
|
855
855
|
Te
|
|
@@ -858,11 +858,11 @@ async function un(e, n, i) {
|
|
|
858
858
|
async function Te() {
|
|
859
859
|
return Fe(L, "Microphone");
|
|
860
860
|
}
|
|
861
|
-
async function
|
|
861
|
+
async function mt(u) {
|
|
862
862
|
return Be(
|
|
863
863
|
j,
|
|
864
864
|
u,
|
|
865
|
-
(
|
|
865
|
+
(f) => f.getVideoTracks(),
|
|
866
866
|
d.Source.Camera,
|
|
867
867
|
() => l.localParticipant.videoTrackPublications,
|
|
868
868
|
ke
|
|
@@ -874,27 +874,27 @@ async function un(e, n, i) {
|
|
|
874
874
|
function gt() {
|
|
875
875
|
z && (z.getTracks().forEach((u) => u.stop()), z = null);
|
|
876
876
|
}
|
|
877
|
-
async function Ee(u,
|
|
877
|
+
async function Ee(u, f) {
|
|
878
878
|
var p, v;
|
|
879
879
|
if (!y || !l) {
|
|
880
880
|
r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(pe), {
|
|
881
|
-
sessionId:
|
|
881
|
+
sessionId: m
|
|
882
882
|
});
|
|
883
883
|
return;
|
|
884
884
|
}
|
|
885
885
|
try {
|
|
886
|
-
await l.localParticipant.sendText(u, { topic:
|
|
886
|
+
await l.localParticipant.sendText(u, { topic: f }), r("Message sent successfully:", u);
|
|
887
887
|
} catch (I) {
|
|
888
|
-
r("Failed to send message:", I), (v = t.onError) == null || v.call(t, new Error(pe), { sessionId:
|
|
888
|
+
r("Failed to send message:", I), (v = t.onError) == null || v.call(t, new Error(pe), { sessionId: m });
|
|
889
889
|
}
|
|
890
890
|
}
|
|
891
891
|
async function ht(u) {
|
|
892
|
-
var
|
|
892
|
+
var f;
|
|
893
893
|
try {
|
|
894
894
|
const v = JSON.parse(u).topic;
|
|
895
895
|
return Ee("", v);
|
|
896
896
|
} catch (p) {
|
|
897
|
-
r("Failed to send data channel message:", p), (
|
|
897
|
+
r("Failed to send data channel message:", p), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
900
|
function pt(u) {
|
|
@@ -905,21 +905,21 @@ async function un(e, n, i) {
|
|
|
905
905
|
);
|
|
906
906
|
}
|
|
907
907
|
async function De(u) {
|
|
908
|
-
var
|
|
909
|
-
K && (clearTimeout(K), K = null), k == null || k.destroy(), k = null, l && ((
|
|
908
|
+
var f, p;
|
|
909
|
+
K && (clearTimeout(K), K = null), k == null || k.destroy(), k = null, l && ((f = t.onConnectionStateChange) == null || f.call(t, b.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()), gt(), y = !1, q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), G = W.Idle;
|
|
910
910
|
}
|
|
911
911
|
return {
|
|
912
912
|
speak(u) {
|
|
913
|
-
const
|
|
913
|
+
const f = typeof u == "string" ? u : JSON.stringify(u);
|
|
914
914
|
return Ee(
|
|
915
|
-
|
|
915
|
+
f,
|
|
916
916
|
"did.speak"
|
|
917
917
|
/* Speak */
|
|
918
918
|
);
|
|
919
919
|
},
|
|
920
920
|
disconnect: () => De("user:disconnect"),
|
|
921
921
|
async reconnect() {
|
|
922
|
-
var u,
|
|
922
|
+
var u, f;
|
|
923
923
|
if ((l == null ? void 0 : l.state) === s.Connected) {
|
|
924
924
|
r("Room is already connected");
|
|
925
925
|
return;
|
|
@@ -941,17 +941,17 @@ async function un(e, n, i) {
|
|
|
941
941
|
r("Agent joined, reconnection successful");
|
|
942
942
|
}
|
|
943
943
|
} catch (p) {
|
|
944
|
-
throw r("Failed to reconnect:", p), (
|
|
944
|
+
throw r("Failed to reconnect:", p), (f = t.onConnectionStateChange) == null || f.call(t, b.Fail, "user:reconnect-failed"), p;
|
|
945
945
|
}
|
|
946
946
|
},
|
|
947
947
|
sendDataChannelMessage: ht,
|
|
948
948
|
sendTextMessage: pt,
|
|
949
|
-
publishMicrophoneStream:
|
|
949
|
+
publishMicrophoneStream: ft,
|
|
950
950
|
unpublishMicrophoneStream: Te,
|
|
951
|
-
publishCameraStream:
|
|
951
|
+
publishCameraStream: mt,
|
|
952
952
|
unpublishCameraStream: ke,
|
|
953
|
-
sessionId:
|
|
954
|
-
streamId:
|
|
953
|
+
sessionId: m,
|
|
954
|
+
streamId: m,
|
|
955
955
|
streamType: A,
|
|
956
956
|
interruptAvailable: J,
|
|
957
957
|
isInterruptible: ae
|
|
@@ -963,7 +963,7 @@ const ln = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
963
963
|
createLiveKitStreamingManager: un,
|
|
964
964
|
handleInitError: _e
|
|
965
965
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
966
|
-
function
|
|
966
|
+
function fn(e, n, i) {
|
|
967
967
|
if (!e)
|
|
968
968
|
throw new Error("Please connect to the agent first");
|
|
969
969
|
if (!e.interruptAvailable)
|
|
@@ -973,7 +973,7 @@ function mn(e, n, i) {
|
|
|
973
973
|
if (!i)
|
|
974
974
|
throw new Error("No active video to interrupt");
|
|
975
975
|
}
|
|
976
|
-
async function
|
|
976
|
+
async function mn(e, n) {
|
|
977
977
|
const i = {
|
|
978
978
|
type: D.StreamInterrupt,
|
|
979
979
|
videoId: n,
|
|
@@ -1238,7 +1238,7 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
|
|
|
1238
1238
|
interrupt_enabled: ae
|
|
1239
1239
|
} = await j(n, d);
|
|
1240
1240
|
(ee = r.onStreamCreated) == null || ee.call(r, { stream_id: k, session_id: K, agent_id: e });
|
|
1241
|
-
const $ = new Tn({ iceServers: q }),
|
|
1241
|
+
const $ = new Tn({ iceServers: q }), m = $.createDataChannel("JanusDataChannel");
|
|
1242
1242
|
if (!K)
|
|
1243
1243
|
throw new Error("Could not create session_id");
|
|
1244
1244
|
const C = G ? ie.Fluent : ie.Legacy;
|
|
@@ -1283,7 +1283,7 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
|
|
|
1283
1283
|
} catch (R) {
|
|
1284
1284
|
(w = r.onError) == null || w.call(r, R, { streamId: k });
|
|
1285
1285
|
}
|
|
1286
|
-
},
|
|
1286
|
+
}, m.onopen = () => {
|
|
1287
1287
|
g = !0, (!E || h) && x();
|
|
1288
1288
|
};
|
|
1289
1289
|
const V = (S) => {
|
|
@@ -1314,7 +1314,7 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
|
|
|
1314
1314
|
[D.StreamDone]: Y,
|
|
1315
1315
|
[D.StreamReady]: Z
|
|
1316
1316
|
};
|
|
1317
|
-
|
|
1317
|
+
m.onmessage = (S) => {
|
|
1318
1318
|
var F;
|
|
1319
1319
|
const { subject: w, data: R } = c(S.data);
|
|
1320
1320
|
(F = B[w]) == null || F.call(B, w, R);
|
|
@@ -1364,14 +1364,14 @@ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we,
|
|
|
1364
1364
|
*/
|
|
1365
1365
|
sendDataChannelMessage(S) {
|
|
1366
1366
|
var w, R;
|
|
1367
|
-
if (!h ||
|
|
1367
|
+
if (!h || m.readyState !== "open") {
|
|
1368
1368
|
t("Data channel is not ready for sending messages"), (w = r.onError) == null || w.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1369
1369
|
streamId: k
|
|
1370
1370
|
});
|
|
1371
1371
|
return;
|
|
1372
1372
|
}
|
|
1373
1373
|
try {
|
|
1374
|
-
|
|
1374
|
+
m.send(S);
|
|
1375
1375
|
} catch (F) {
|
|
1376
1376
|
t("Error sending data channel message", F), (R = r.onError) == null || R.call(r, F, { streamId: k });
|
|
1377
1377
|
}
|
|
@@ -1610,28 +1610,28 @@ async function Kn(e, n) {
|
|
|
1610
1610
|
const y = Le(l.presenter.type);
|
|
1611
1611
|
c.enrich(Jt(l));
|
|
1612
1612
|
const { onMessage: A, clearQueue: z } = Sn(c, t, n, l, () => {
|
|
1613
|
-
var
|
|
1614
|
-
(
|
|
1613
|
+
var m, C, E;
|
|
1614
|
+
(m = t.socketManager) == null || m.disconnect(), (E = (C = n.callbacks).onConnectionStateChange) == null || E.call(C, b.Disconnected);
|
|
1615
1615
|
});
|
|
1616
1616
|
t.messages = Xt(n.initialMessages), (ae = (G = n.callbacks).onNewMessage) == null || ae.call(G, [...t.messages], "answer");
|
|
1617
|
-
const L = (
|
|
1618
|
-
r =
|
|
1619
|
-
}, j = ({ type:
|
|
1617
|
+
const L = (m) => {
|
|
1618
|
+
r = m;
|
|
1619
|
+
}, j = ({ type: m }) => {
|
|
1620
1620
|
var E, J, x, M, V;
|
|
1621
1621
|
if (!((E = t.streamingManager) != null && E.interruptAvailable) || !((J = t.streamingManager) != null && J.isInterruptible)) return;
|
|
1622
1622
|
const C = t.messages[t.messages.length - 1];
|
|
1623
1623
|
c.track("agent-video-interrupt", {
|
|
1624
|
-
type:
|
|
1624
|
+
type: m || "click",
|
|
1625
1625
|
video_duration_to_interrupt: Ae.get(!0),
|
|
1626
1626
|
message_duration_to_interrupt: re.get(!0)
|
|
1627
|
-
}), C.interrupted = !0, (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "answer"), y ? gn(t.streamingManager) : (
|
|
1627
|
+
}), C.interrupted = !0, (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "answer"), y ? gn(t.streamingManager) : (fn(t.streamingManager, (V = t.streamingManager) == null ? void 0 : V.streamType, r), mn(t.streamingManager, r));
|
|
1628
1628
|
}, _ = Date.now();
|
|
1629
1629
|
Oe(() => {
|
|
1630
1630
|
c.track("agent-sdk", { event: "loaded", ...Ut(l) }, _);
|
|
1631
1631
|
});
|
|
1632
|
-
async function k(
|
|
1632
|
+
async function k(m) {
|
|
1633
1633
|
var V, Y, Z, B, U, ee, S;
|
|
1634
|
-
(Y = (V = n.callbacks).onConnectionStateChange) == null || Y.call(V, b.Connecting), re.reset(),
|
|
1634
|
+
(Y = (V = n.callbacks).onConnectionStateChange) == null || Y.call(V, b.Connecting), re.reset(), m && !i && (delete t.chat, (B = (Z = n.callbacks).onNewMessage) == null || B.call(Z, [...t.messages], "answer"));
|
|
1635
1635
|
const C = d === O.DirectPlayback || y ? Promise.resolve(void 0) : wn(
|
|
1636
1636
|
n.auth,
|
|
1637
1637
|
a,
|
|
@@ -1672,22 +1672,22 @@ async function Kn(e, n) {
|
|
|
1672
1672
|
}), q((M == null ? void 0 : M.chat_mode) ?? d);
|
|
1673
1673
|
}
|
|
1674
1674
|
async function H() {
|
|
1675
|
-
var
|
|
1676
|
-
(
|
|
1675
|
+
var m, C, E, J;
|
|
1676
|
+
(m = t.socketManager) == null || m.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (J = (E = n.callbacks).onConnectionStateChange) == null || J.call(E, b.Disconnected);
|
|
1677
1677
|
}
|
|
1678
|
-
async function q(
|
|
1678
|
+
async function q(m) {
|
|
1679
1679
|
var C, E;
|
|
1680
|
-
|
|
1680
|
+
m !== t.chatMode && (c.track("agent-mode-change", { mode: m }), t.chatMode = m, t.chatMode !== O.Functional && await H(), (E = (C = n.callbacks).onModeChange) == null || E.call(C, m));
|
|
1681
1681
|
}
|
|
1682
1682
|
return {
|
|
1683
1683
|
agent: l,
|
|
1684
1684
|
getStreamType: () => {
|
|
1685
|
-
var
|
|
1686
|
-
return (
|
|
1685
|
+
var m;
|
|
1686
|
+
return (m = t.streamingManager) == null ? void 0 : m.streamType;
|
|
1687
1687
|
},
|
|
1688
1688
|
getIsInterruptAvailable: () => {
|
|
1689
|
-
var
|
|
1690
|
-
return ((
|
|
1689
|
+
var m;
|
|
1690
|
+
return ((m = t.streamingManager) == null ? void 0 : m.interruptAvailable) ?? !1;
|
|
1691
1691
|
},
|
|
1692
1692
|
starterMessages: (($ = l.knowledge) == null ? void 0 : $.starter_message) || [],
|
|
1693
1693
|
getSTTToken: () => g.getSTTToken(l.id),
|
|
@@ -1700,10 +1700,10 @@ async function Kn(e, n) {
|
|
|
1700
1700
|
});
|
|
1701
1701
|
},
|
|
1702
1702
|
async reconnect() {
|
|
1703
|
-
const
|
|
1704
|
-
if (y && (
|
|
1703
|
+
const m = t.streamingManager;
|
|
1704
|
+
if (y && (m != null && m.reconnect)) {
|
|
1705
1705
|
try {
|
|
1706
|
-
await
|
|
1706
|
+
await m.reconnect(), c.track("agent-chat", {
|
|
1707
1707
|
event: "reconnect",
|
|
1708
1708
|
mode: t.chatMode
|
|
1709
1709
|
});
|
|
@@ -1723,38 +1723,36 @@ async function Kn(e, n) {
|
|
|
1723
1723
|
mode: t.chatMode
|
|
1724
1724
|
});
|
|
1725
1725
|
},
|
|
1726
|
-
async publishMicrophoneStream(
|
|
1726
|
+
async publishMicrophoneStream(m) {
|
|
1727
1727
|
var C;
|
|
1728
1728
|
if (!((C = t.streamingManager) != null && C.publishMicrophoneStream))
|
|
1729
1729
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1730
|
-
return t.streamingManager.publishMicrophoneStream(
|
|
1730
|
+
return t.streamingManager.publishMicrophoneStream(m);
|
|
1731
1731
|
},
|
|
1732
1732
|
async unpublishMicrophoneStream() {
|
|
1733
|
-
var
|
|
1734
|
-
if (
|
|
1735
|
-
|
|
1736
|
-
return t.streamingManager.unpublishMicrophoneStream();
|
|
1733
|
+
var m;
|
|
1734
|
+
if ((m = t.streamingManager) != null && m.unpublishMicrophoneStream)
|
|
1735
|
+
return t.streamingManager.unpublishMicrophoneStream();
|
|
1737
1736
|
},
|
|
1738
|
-
async publishCameraStream(
|
|
1737
|
+
async publishCameraStream(m) {
|
|
1739
1738
|
var C;
|
|
1740
1739
|
if (!((C = t.streamingManager) != null && C.publishCameraStream))
|
|
1741
1740
|
throw new Error("publishCameraStream is not available for this streaming manager");
|
|
1742
|
-
return t.streamingManager.publishCameraStream(
|
|
1741
|
+
return t.streamingManager.publishCameraStream(m);
|
|
1743
1742
|
},
|
|
1744
1743
|
async unpublishCameraStream() {
|
|
1745
|
-
var
|
|
1746
|
-
if (
|
|
1747
|
-
|
|
1748
|
-
return t.streamingManager.unpublishCameraStream();
|
|
1744
|
+
var m;
|
|
1745
|
+
if ((m = t.streamingManager) != null && m.unpublishCameraStream)
|
|
1746
|
+
return t.streamingManager.unpublishCameraStream();
|
|
1749
1747
|
},
|
|
1750
|
-
async chat(
|
|
1748
|
+
async chat(m) {
|
|
1751
1749
|
var x, M, V, Y, Z;
|
|
1752
1750
|
const C = () => {
|
|
1753
1751
|
if (nt(d))
|
|
1754
1752
|
throw new ue(`${d} is enabled, chat is disabled`);
|
|
1755
|
-
if (
|
|
1753
|
+
if (m.length >= 800)
|
|
1756
1754
|
throw new ue("Message cannot be more than 800 characters");
|
|
1757
|
-
if (
|
|
1755
|
+
if (m.length === 0)
|
|
1758
1756
|
throw new ue("Message cannot be empty");
|
|
1759
1757
|
if (t.chatMode === O.Maintenance)
|
|
1760
1758
|
throw new ue("Chat is in maintenance mode");
|
|
@@ -1783,7 +1781,7 @@ async function Kn(e, n) {
|
|
|
1783
1781
|
const ee = t.chatMode === O.Playground;
|
|
1784
1782
|
return Ie(y && !ee ? async () => {
|
|
1785
1783
|
var R, F;
|
|
1786
|
-
return await ((F = (R = t.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : F.call(R,
|
|
1784
|
+
return await ((F = (R = t.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : F.call(R, m)), Promise.resolve({});
|
|
1787
1785
|
} : async () => {
|
|
1788
1786
|
var R, F;
|
|
1789
1787
|
return g.chat(
|
|
@@ -1816,7 +1814,7 @@ async function Kn(e, n) {
|
|
|
1816
1814
|
z(), C(), t.messages.push({
|
|
1817
1815
|
id: le(),
|
|
1818
1816
|
role: "user",
|
|
1819
|
-
content:
|
|
1817
|
+
content: m,
|
|
1820
1818
|
created_at: new Date(re.update()).toISOString()
|
|
1821
1819
|
}), (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "user");
|
|
1822
1820
|
const B = await E(), U = await J([...t.messages], B);
|
|
@@ -1841,9 +1839,9 @@ async function Kn(e, n) {
|
|
|
1841
1839
|
}), B;
|
|
1842
1840
|
}
|
|
1843
1841
|
},
|
|
1844
|
-
rate(
|
|
1842
|
+
rate(m, C, E) {
|
|
1845
1843
|
var M, V, Y, Z;
|
|
1846
|
-
const J = t.messages.find((B) => B.id ===
|
|
1844
|
+
const J = t.messages.find((B) => B.id === m);
|
|
1847
1845
|
if (t.chat) {
|
|
1848
1846
|
if (!J)
|
|
1849
1847
|
throw new Error("Message not found");
|
|
@@ -1857,45 +1855,45 @@ async function Kn(e, n) {
|
|
|
1857
1855
|
score: C
|
|
1858
1856
|
}), E ? g.updateRating(l.id, t.chat.id, E, {
|
|
1859
1857
|
knowledge_id: ((Y = l.knowledge) == null ? void 0 : Y.id) ?? "",
|
|
1860
|
-
message_id:
|
|
1858
|
+
message_id: m,
|
|
1861
1859
|
matches: x,
|
|
1862
1860
|
score: C
|
|
1863
1861
|
}) : g.createRating(l.id, t.chat.id, {
|
|
1864
1862
|
knowledge_id: ((Z = l.knowledge) == null ? void 0 : Z.id) ?? "",
|
|
1865
|
-
message_id:
|
|
1863
|
+
message_id: m,
|
|
1866
1864
|
matches: x,
|
|
1867
1865
|
score: C
|
|
1868
1866
|
});
|
|
1869
1867
|
},
|
|
1870
|
-
deleteRate(
|
|
1868
|
+
deleteRate(m) {
|
|
1871
1869
|
if (!t.chat)
|
|
1872
1870
|
throw new Error("Chat is not initialized");
|
|
1873
|
-
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id,
|
|
1871
|
+
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, m);
|
|
1874
1872
|
},
|
|
1875
|
-
async speak(
|
|
1873
|
+
async speak(m) {
|
|
1876
1874
|
var x, M, V;
|
|
1877
1875
|
function C() {
|
|
1878
|
-
if (typeof
|
|
1876
|
+
if (typeof m == "string") {
|
|
1879
1877
|
if (!l.presenter.voice)
|
|
1880
1878
|
throw new Error("Presenter voice is not initialized");
|
|
1881
1879
|
return {
|
|
1882
1880
|
type: "text",
|
|
1883
1881
|
provider: l.presenter.voice,
|
|
1884
|
-
input:
|
|
1882
|
+
input: m,
|
|
1885
1883
|
ssml: !1
|
|
1886
1884
|
};
|
|
1887
1885
|
}
|
|
1888
|
-
if (
|
|
1886
|
+
if (m.type === "text" && !m.provider) {
|
|
1889
1887
|
if (!l.presenter.voice)
|
|
1890
1888
|
throw new Error("Presenter voice is not initialized");
|
|
1891
1889
|
return {
|
|
1892
1890
|
type: "text",
|
|
1893
1891
|
provider: l.presenter.voice,
|
|
1894
|
-
input:
|
|
1895
|
-
ssml:
|
|
1892
|
+
input: m.input,
|
|
1893
|
+
ssml: m.ssml
|
|
1896
1894
|
};
|
|
1897
1895
|
}
|
|
1898
|
-
return
|
|
1896
|
+
return m;
|
|
1899
1897
|
}
|
|
1900
1898
|
const E = C();
|
|
1901
1899
|
if (c.track("agent-speak", E), re.update(), t.messages && E.type === "text" && (t.messages.push({
|