@d-id/client-sdk 1.1.61-staging.284 → 1.1.61-staging.286
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 +318 -297
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,8 +35,8 @@ class Dt extends Ie {
|
|
|
35
35
|
super({ kind: "WSError", description: n });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var _t = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_t || {}), At = /* @__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))(At || {}), bt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(bt || {}), Lt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Lt || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pt || {}), xt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xt || {}), $t = /* @__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))($t || {}), dt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(dt || {});
|
|
39
|
+
const qn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,7 +48,7 @@ const Hn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var k = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(k || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), R = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(R || {}), x = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(x || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ne = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ne || {}), jt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(jt || {}), Bt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Bt || {});
|
|
52
52
|
const Ft = 45 * 1e3, Nt = "X-Playground-Chat", Ee = "https://api.d-id.com", Kt = "wss://notifications.d-id.com", zt = "79f81a83a67430be2bc0fd61042b8faa", Vt = (...e) => {
|
|
53
53
|
}, ut = (e) => new Promise((n) => setTimeout(n, e)), ge = (e = 16) => {
|
|
54
54
|
const n = new Uint8Array(e);
|
|
@@ -101,7 +101,7 @@ function Wt(e) {
|
|
|
101
101
|
return s < e.length && r.push({ type: "text", text: e.slice(s) }), r;
|
|
102
102
|
}
|
|
103
103
|
let Ze = "", Pe = [];
|
|
104
|
-
function
|
|
104
|
+
function Re(e) {
|
|
105
105
|
return e === Ze || (Ze = e, Pe = Wt(e)), Pe;
|
|
106
106
|
}
|
|
107
107
|
function Ht(e, n) {
|
|
@@ -399,8 +399,8 @@ function on(e, n, i, r) {
|
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
401
|
const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), sn = {
|
|
402
|
-
[
|
|
403
|
-
[
|
|
402
|
+
[R.ChatAnswer]: X.Answer,
|
|
403
|
+
[R.ChatPartial]: X.Partial
|
|
404
404
|
};
|
|
405
405
|
function cn(e, n, i) {
|
|
406
406
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
@@ -558,8 +558,8 @@ function ln(e, n) {
|
|
|
558
558
|
a = g, o = l, r = !0, s = setTimeout(t, Se);
|
|
559
559
|
return;
|
|
560
560
|
}
|
|
561
|
-
const
|
|
562
|
-
if (a = g, o = l,
|
|
561
|
+
const p = g - a, D = l - o;
|
|
562
|
+
if (a = g, o = l, D > 0 && p > 0) {
|
|
563
563
|
i = !1, n(c);
|
|
564
564
|
return;
|
|
565
565
|
}
|
|
@@ -595,18 +595,18 @@ function hn() {
|
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
597
|
function yt(e, n, i, r, s) {
|
|
598
|
-
let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0,
|
|
599
|
-
const
|
|
598
|
+
let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0, p = 0;
|
|
599
|
+
const D = hn();
|
|
600
600
|
async function N() {
|
|
601
601
|
const B = await e();
|
|
602
602
|
if (!B)
|
|
603
603
|
return;
|
|
604
|
-
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: M } =
|
|
604
|
+
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: M } = D(B), Y = un(B);
|
|
605
605
|
if (F)
|
|
606
|
-
t = 0, l = M -
|
|
606
|
+
t = 0, l = M - p, g = I < mn ? ae.Strong : I > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, p += l, l = 0), d || (r == null || r(k.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
|
|
607
607
|
else if (d && (t++, t >= fn)) {
|
|
608
608
|
const Q = rt(o, Me, c);
|
|
609
|
-
r == null || r(
|
|
609
|
+
r == null || r(k.Stop, Q), n() || i(), p = M, d = !1;
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
return {
|
|
@@ -635,7 +635,7 @@ const wn = {
|
|
|
635
635
|
poor: ae.Weak,
|
|
636
636
|
lost: ae.Unknown,
|
|
637
637
|
unknown: ae.Unknown
|
|
638
|
-
},
|
|
638
|
+
}, Te = JSON.stringify({
|
|
639
639
|
kind: "InternalServerError",
|
|
640
640
|
description: "Stream Error"
|
|
641
641
|
});
|
|
@@ -647,8 +647,8 @@ function Be(e, n, i) {
|
|
|
647
647
|
async function yn(e, n, i) {
|
|
648
648
|
var Je;
|
|
649
649
|
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await pn(), { callbacks: t, auth: d, baseURL: h, analytics: g } = i;
|
|
650
|
-
let l = null,
|
|
651
|
-
const
|
|
650
|
+
let l = null, p = !1;
|
|
651
|
+
const D = se.Fluent;
|
|
652
652
|
let N = null;
|
|
653
653
|
const B = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
|
|
654
654
|
let I = null, M = null, Y = null, Q = !1;
|
|
@@ -664,14 +664,14 @@ async function yn(e, n, i) {
|
|
|
664
664
|
const u = await $.createStream({
|
|
665
665
|
transport: n.transport,
|
|
666
666
|
chat_persist: n.chat_persist ?? !0
|
|
667
|
-
}), { id: m, session_token:
|
|
668
|
-
(Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H =
|
|
667
|
+
}), { id: m, session_token: w, session_url: S, interrupt_enabled: b } = u;
|
|
668
|
+
(Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H = w, re = S, de = b ?? !0, await l.prepareConnection(re, H);
|
|
669
669
|
} catch (u) {
|
|
670
670
|
Be(u, r, t);
|
|
671
671
|
}
|
|
672
672
|
if (!re || !H || !K)
|
|
673
673
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
674
|
-
l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected,
|
|
674
|
+
l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, T).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, J).on(a.TrackUnsubscribed, y).on(a.DataReceived, z).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
|
|
675
675
|
function ue(u, m) {
|
|
676
676
|
m != null && m.isLocal && (oe.update(), te === W.Talking && (te = W.Idle));
|
|
677
677
|
}
|
|
@@ -689,49 +689,49 @@ async function yn(e, n, i) {
|
|
|
689
689
|
Be(u, r, t);
|
|
690
690
|
}
|
|
691
691
|
g.enrich({
|
|
692
|
-
"stream-type":
|
|
692
|
+
"stream-type": D
|
|
693
693
|
});
|
|
694
694
|
function f(u) {
|
|
695
|
-
var m,
|
|
695
|
+
var m, w, S, b;
|
|
696
696
|
switch (r("Connection state changed:", u), u) {
|
|
697
697
|
case o.Connecting:
|
|
698
698
|
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, x.Connecting, "livekit:connecting");
|
|
699
699
|
break;
|
|
700
700
|
case o.Connected:
|
|
701
|
-
r("LiveKit room connected successfully"),
|
|
701
|
+
r("LiveKit room connected successfully"), p = !0;
|
|
702
702
|
break;
|
|
703
703
|
case o.Disconnected:
|
|
704
|
-
r("LiveKit room disconnected"),
|
|
704
|
+
r("LiveKit room disconnected"), p = !1, Q = !1, B.publication = null, F.publication = null, (w = t.onConnectionStateChange) == null || w.call(t, x.Disconnected, "livekit:disconnected");
|
|
705
705
|
break;
|
|
706
706
|
case o.Reconnecting:
|
|
707
707
|
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, x.Connecting, "livekit:reconnecting");
|
|
708
708
|
break;
|
|
709
709
|
case o.SignalReconnecting:
|
|
710
|
-
r("LiveKit room signal reconnecting..."), (
|
|
710
|
+
r("LiveKit room signal reconnecting..."), (b = t.onConnectionStateChange) == null || b.call(t, x.Connecting, "livekit:signal-reconnecting");
|
|
711
711
|
break;
|
|
712
712
|
}
|
|
713
713
|
}
|
|
714
714
|
function C(u, m) {
|
|
715
|
-
var
|
|
716
|
-
r("Connection quality:", u), m != null && m.isLocal && ((
|
|
715
|
+
var w;
|
|
716
|
+
r("Connection quality:", u), m != null && m.isLocal && ((w = t.onConnectivityStateChange) == null || w.call(t, wn[u]));
|
|
717
717
|
}
|
|
718
|
-
function
|
|
718
|
+
function T(u) {
|
|
719
719
|
r("Participant connected:", u.identity);
|
|
720
720
|
}
|
|
721
721
|
function A(u) {
|
|
722
722
|
r("Participant disconnected:", u.identity), Le("livekit:participant-disconnected");
|
|
723
723
|
}
|
|
724
|
-
function
|
|
724
|
+
function _() {
|
|
725
725
|
var u;
|
|
726
|
-
Y !==
|
|
726
|
+
Y !== k.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = k.Start, (u = t.onVideoStateChange) == null || u.call(t, k.Start));
|
|
727
727
|
}
|
|
728
|
-
function
|
|
728
|
+
function L(u) {
|
|
729
729
|
var m;
|
|
730
|
-
Y !==
|
|
730
|
+
Y !== k.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = k.Stop, (m = t.onVideoStateChange) == null || m.call(t, k.Stop, u));
|
|
731
731
|
}
|
|
732
|
-
function J(u, m,
|
|
733
|
-
var
|
|
734
|
-
r(`Track subscribed: ${u.kind} from ${
|
|
732
|
+
function J(u, m, w) {
|
|
733
|
+
var b, P, q;
|
|
734
|
+
r(`Track subscribed: ${u.kind} from ${w.identity}`);
|
|
735
735
|
const S = u.mediaStreamTrack;
|
|
736
736
|
if (!S) {
|
|
737
737
|
r(`No mediaStreamTrack available for ${u.kind}`);
|
|
@@ -750,40 +750,40 @@ async function yn(e, n, i) {
|
|
|
750
750
|
const fe = ye > 0 ? ye + (V ?? 0) + ve : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
|
|
751
751
|
(He = t.onFirstAudioDetected) == null || He.call(t, { latency: fe, networkLatency: ce });
|
|
752
752
|
}
|
|
753
|
-
)), u.kind === "video" && ((
|
|
753
|
+
)), u.kind === "video" && ((b = t.onStreamReady) == null || b.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, x.Connected, "livekit:track-subscribed")), I = yt(
|
|
754
754
|
() => u.getRTCStatsReport(),
|
|
755
|
-
() =>
|
|
755
|
+
() => p,
|
|
756
756
|
Vt,
|
|
757
757
|
(V, ie) => {
|
|
758
|
-
r(`Video state change: ${V}`), V ===
|
|
758
|
+
r(`Video state change: ${V}`), V === k.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), _()) : V === k.Stop && L(ie);
|
|
759
759
|
}
|
|
760
760
|
), I.start());
|
|
761
761
|
}
|
|
762
|
-
function
|
|
763
|
-
r(`Track unsubscribed: ${u.kind} from ${
|
|
762
|
+
function y(u, m, w) {
|
|
763
|
+
r(`Track unsubscribed: ${u.kind} from ${w.identity}`), u.kind === "audio" && (M == null || M.destroy(), M = null), u.kind === "video" && (L(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
|
|
764
764
|
}
|
|
765
|
-
function
|
|
765
|
+
function v(u, m) {
|
|
766
766
|
var S;
|
|
767
|
-
const
|
|
768
|
-
|
|
767
|
+
const w = sn[u];
|
|
768
|
+
w && ((S = t.onMessage) == null || S.call(t, w, { event: w, ...m }));
|
|
769
769
|
}
|
|
770
|
-
function
|
|
771
|
-
var
|
|
772
|
-
if (u ===
|
|
773
|
-
te = W.ToolActive, (
|
|
770
|
+
function E(u, m) {
|
|
771
|
+
var w, S, b, P;
|
|
772
|
+
if (u === R.ToolCallStarted) {
|
|
773
|
+
te = W.ToolActive, (w = t.onAgentActivityStateChange) == null || w.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, R.ToolCallStarted, m);
|
|
774
774
|
return;
|
|
775
775
|
}
|
|
776
|
-
if (u ===
|
|
777
|
-
(
|
|
776
|
+
if (u === R.ToolCallDone) {
|
|
777
|
+
(b = t.onToolEvent) == null || b.call(t, R.ToolCallDone, m);
|
|
778
778
|
return;
|
|
779
779
|
}
|
|
780
|
-
u ===
|
|
780
|
+
u === R.ToolCallError && ((P = t.onToolEvent) == null || P.call(t, R.ToolCallError, m));
|
|
781
781
|
}
|
|
782
782
|
function j(u, m) {
|
|
783
|
-
var
|
|
784
|
-
if (ne = ((
|
|
785
|
-
te = W.Talking, (
|
|
786
|
-
sttLatency: (
|
|
783
|
+
var w, S, b, P, q;
|
|
784
|
+
if (ne = ((w = m.metadata) == null ? void 0 : w.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === R.StreamVideoCreated) {
|
|
785
|
+
te = W.Talking, (b = t.onAgentActivityStateChange) == null || b.call(t, W.Talking), M == null || M.arm({
|
|
786
|
+
sttLatency: (P = m == null ? void 0 : m.stt) == null ? void 0 : P.latency,
|
|
787
787
|
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
788
788
|
});
|
|
789
789
|
return;
|
|
@@ -791,75 +791,75 @@ async function yn(e, n, i) {
|
|
|
791
791
|
ne && (te = W.Idle, (q = t.onAgentActivityStateChange) == null || q.call(t, W.Idle));
|
|
792
792
|
}
|
|
793
793
|
function G(u, m) {
|
|
794
|
-
var
|
|
795
|
-
const
|
|
796
|
-
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (
|
|
794
|
+
var P, q, V, ie;
|
|
795
|
+
const w = ((q = (P = I == null ? void 0 : I.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = w > 0 ? Math.round(w / 2 * 1e3) : 0, b = { ...m, downstreamNetworkLatency: S };
|
|
796
|
+
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (b.sentiment = {
|
|
797
797
|
id: m.metadata.sentiment.id,
|
|
798
798
|
name: m.metadata.sentiment.sentiment
|
|
799
|
-
}), (ie = t.onMessage) == null || ie.call(t, u,
|
|
799
|
+
}), (ie = t.onMessage) == null || ie.call(t, u, b), j(u, m);
|
|
800
800
|
}
|
|
801
801
|
function he(u, m) {
|
|
802
|
-
var
|
|
803
|
-
(
|
|
802
|
+
var w;
|
|
803
|
+
(w = t.onMessage) == null || w.call(t, X.Transcribe, { event: X.Transcribe, ...m }), queueMicrotask(() => {
|
|
804
804
|
var S;
|
|
805
805
|
(S = t.onAgentActivityStateChange) == null || S.call(t, W.Loading);
|
|
806
806
|
});
|
|
807
807
|
}
|
|
808
808
|
const Z = {
|
|
809
|
-
[
|
|
810
|
-
[
|
|
811
|
-
[
|
|
812
|
-
[
|
|
813
|
-
[
|
|
814
|
-
[
|
|
815
|
-
[
|
|
816
|
-
[
|
|
817
|
-
[
|
|
818
|
-
[
|
|
809
|
+
[R.ChatAnswer]: v,
|
|
810
|
+
[R.ChatPartial]: v,
|
|
811
|
+
[R.ToolCallStarted]: E,
|
|
812
|
+
[R.ToolCallDone]: E,
|
|
813
|
+
[R.ToolCallError]: E,
|
|
814
|
+
[R.StreamVideoCreated]: G,
|
|
815
|
+
[R.StreamVideoDone]: G,
|
|
816
|
+
[R.StreamVideoError]: G,
|
|
817
|
+
[R.StreamVideoRejected]: G,
|
|
818
|
+
[R.ChatAudioTranscribed]: he
|
|
819
819
|
};
|
|
820
|
-
function z(u, m,
|
|
821
|
-
const
|
|
820
|
+
function z(u, m, w, S) {
|
|
821
|
+
const b = new TextDecoder().decode(u);
|
|
822
822
|
try {
|
|
823
|
-
const
|
|
824
|
-
if (r("Data received:", { subject: q, data:
|
|
823
|
+
const P = JSON.parse(b), q = S || P.subject;
|
|
824
|
+
if (r("Data received:", { subject: q, data: P }), !q) return;
|
|
825
825
|
const V = Z[q];
|
|
826
|
-
V == null || V(q,
|
|
827
|
-
} catch (
|
|
828
|
-
r("Failed to parse data channel message:",
|
|
826
|
+
V == null || V(q, P);
|
|
827
|
+
} catch (P) {
|
|
828
|
+
r("Failed to parse data channel message:", P);
|
|
829
829
|
}
|
|
830
830
|
}
|
|
831
831
|
function ee(u) {
|
|
832
832
|
var m;
|
|
833
|
-
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
833
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Te), { sessionId: K });
|
|
834
834
|
}
|
|
835
835
|
function De(u) {
|
|
836
836
|
var m;
|
|
837
|
-
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
837
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Te), { sessionId: K });
|
|
838
838
|
}
|
|
839
|
-
function le(u, m,
|
|
840
|
-
r("Track subscription failed:", { trackSid: u, participant: m, reason:
|
|
839
|
+
function le(u, m, w) {
|
|
840
|
+
r("Track subscription failed:", { trackSid: u, participant: m, reason: w });
|
|
841
841
|
}
|
|
842
|
-
function ke(u, m,
|
|
843
|
-
for (const [S,
|
|
844
|
-
if (
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
847
|
-
return
|
|
842
|
+
function ke(u, m, w) {
|
|
843
|
+
for (const [S, b] of w)
|
|
844
|
+
if (b.source === m && b.track) {
|
|
845
|
+
const P = b.track.mediaStreamTrack;
|
|
846
|
+
if (P === u || (P == null ? void 0 : P.id) === u.id)
|
|
847
|
+
return b;
|
|
848
848
|
}
|
|
849
849
|
return null;
|
|
850
850
|
}
|
|
851
|
-
async function pe(u, m,
|
|
851
|
+
async function pe(u, m, w, S, b, P) {
|
|
852
852
|
var ye, ve, fe;
|
|
853
|
-
if (!
|
|
853
|
+
if (!p || !l)
|
|
854
854
|
throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
|
|
855
855
|
if (u.isPublishing) {
|
|
856
856
|
r(`${S} publish already in progress, skipping`);
|
|
857
857
|
return;
|
|
858
858
|
}
|
|
859
|
-
const q =
|
|
859
|
+
const q = w(m);
|
|
860
860
|
if (q.length === 0)
|
|
861
861
|
throw new Error(`No ${S} track found in the provided MediaStream`);
|
|
862
|
-
const V = q[0], ie = ke(V, S,
|
|
862
|
+
const V = q[0], ie = ke(V, S, b());
|
|
863
863
|
if (ie) {
|
|
864
864
|
r(`${S} track is already published, skipping`, {
|
|
865
865
|
trackId: V.id,
|
|
@@ -869,7 +869,7 @@ async function yn(e, n, i) {
|
|
|
869
869
|
}
|
|
870
870
|
if ((fe = u.publication) != null && fe.track) {
|
|
871
871
|
const ce = u.publication.track.mediaStreamTrack;
|
|
872
|
-
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await
|
|
872
|
+
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await P());
|
|
873
873
|
}
|
|
874
874
|
r(`Publishing ${S} track from provided MediaStream`, { trackId: V.id }), u.isPublishing = !0;
|
|
875
875
|
try {
|
|
@@ -884,8 +884,8 @@ async function yn(e, n, i) {
|
|
|
884
884
|
if (!(!u.publication || !u.publication.track))
|
|
885
885
|
try {
|
|
886
886
|
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${m} track unpublished`));
|
|
887
|
-
} catch (
|
|
888
|
-
r(`Error unpublishing ${m} track:`,
|
|
887
|
+
} catch (w) {
|
|
888
|
+
r(`Error unpublishing ${m} track:`, w);
|
|
889
889
|
} finally {
|
|
890
890
|
u.publication = null;
|
|
891
891
|
}
|
|
@@ -897,10 +897,10 @@ async function yn(e, n, i) {
|
|
|
897
897
|
(m) => m.getAudioTracks(),
|
|
898
898
|
c.Source.Microphone,
|
|
899
899
|
() => l.localParticipant.audioTrackPublications,
|
|
900
|
-
|
|
900
|
+
_e
|
|
901
901
|
);
|
|
902
902
|
}
|
|
903
|
-
async function
|
|
903
|
+
async function _e() {
|
|
904
904
|
return we(B, "Microphone");
|
|
905
905
|
}
|
|
906
906
|
async function Ct(u) {
|
|
@@ -910,39 +910,39 @@ async function yn(e, n, i) {
|
|
|
910
910
|
(m) => m.getVideoTracks(),
|
|
911
911
|
c.Source.Camera,
|
|
912
912
|
() => l.localParticipant.videoTrackPublications,
|
|
913
|
-
|
|
913
|
+
Ae
|
|
914
914
|
);
|
|
915
915
|
}
|
|
916
|
-
async function
|
|
916
|
+
async function Ae() {
|
|
917
917
|
return we(F, "Camera");
|
|
918
918
|
}
|
|
919
919
|
function St() {
|
|
920
920
|
N && (N.getTracks().forEach((u) => u.stop()), N = null);
|
|
921
921
|
}
|
|
922
922
|
async function be(u, m) {
|
|
923
|
-
var
|
|
924
|
-
if (!
|
|
925
|
-
r("Room is not connected for sending messages"), (
|
|
923
|
+
var w, S;
|
|
924
|
+
if (!p || !l) {
|
|
925
|
+
r("Room is not connected for sending messages"), (w = t.onError) == null || w.call(t, new Error(Te), {
|
|
926
926
|
sessionId: K
|
|
927
927
|
});
|
|
928
928
|
return;
|
|
929
929
|
}
|
|
930
930
|
try {
|
|
931
931
|
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
932
|
-
} catch (
|
|
933
|
-
r("Failed to send message:",
|
|
932
|
+
} catch (b) {
|
|
933
|
+
r("Failed to send message:", b), (S = t.onError) == null || S.call(t, new Error(Te), { sessionId: K });
|
|
934
934
|
}
|
|
935
935
|
}
|
|
936
|
-
async function
|
|
936
|
+
async function Tt(u) {
|
|
937
937
|
var m;
|
|
938
938
|
try {
|
|
939
939
|
const S = JSON.parse(u).topic;
|
|
940
940
|
return be("", S);
|
|
941
|
-
} catch (
|
|
942
|
-
r("Failed to send data channel message:",
|
|
941
|
+
} catch (w) {
|
|
942
|
+
r("Failed to send data channel message:", w), (m = t.onError) == null || m.call(t, new Error(Te), { sessionId: K });
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
|
-
function
|
|
945
|
+
function Rt(u) {
|
|
946
946
|
return be(
|
|
947
947
|
u,
|
|
948
948
|
"lk.chat"
|
|
@@ -950,8 +950,8 @@ async function yn(e, n, i) {
|
|
|
950
950
|
);
|
|
951
951
|
}
|
|
952
952
|
async function Le(u) {
|
|
953
|
-
var m,
|
|
954
|
-
U && (clearTimeout(U), U = null), M == null || M.destroy(), M = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([
|
|
953
|
+
var m, w;
|
|
954
|
+
U && (clearTimeout(U), U = null), M == null || M.destroy(), M = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([_e(), Ae()]), await l.disconnect()), St(), p = !1, Q = !1, (w = t.onAgentActivityStateChange) == null || w.call(t, W.Idle), te = W.Idle;
|
|
955
955
|
}
|
|
956
956
|
return {
|
|
957
957
|
speak(u) {
|
|
@@ -973,28 +973,28 @@ async function yn(e, n, i) {
|
|
|
973
973
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
974
974
|
r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, x.Connecting, "user:reconnect");
|
|
975
975
|
try {
|
|
976
|
-
if (await l.connect(re, H), r("Room reconnected"),
|
|
976
|
+
if (await l.connect(re, H), r("Room reconnected"), p = !0, l.remoteParticipants.size === 0) {
|
|
977
977
|
if (r("Waiting for agent to join..."), !await new Promise((S) => {
|
|
978
|
-
const
|
|
979
|
-
l == null || l.off(a.ParticipantConnected,
|
|
980
|
-
}, 5e3),
|
|
981
|
-
clearTimeout(
|
|
978
|
+
const b = setTimeout(() => {
|
|
979
|
+
l == null || l.off(a.ParticipantConnected, P), S(!1);
|
|
980
|
+
}, 5e3), P = () => {
|
|
981
|
+
clearTimeout(b), l == null || l.off(a.ParticipantConnected, P), S(!0);
|
|
982
982
|
};
|
|
983
|
-
l == null || l.on(a.ParticipantConnected,
|
|
983
|
+
l == null || l.on(a.ParticipantConnected, P);
|
|
984
984
|
}))
|
|
985
985
|
throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
|
|
986
986
|
r("Agent joined, reconnection successful");
|
|
987
987
|
}
|
|
988
|
-
} catch (
|
|
989
|
-
throw r("Failed to reconnect:",
|
|
988
|
+
} catch (w) {
|
|
989
|
+
throw r("Failed to reconnect:", w), (m = t.onConnectionStateChange) == null || m.call(t, x.Fail, "user:reconnect-failed"), w;
|
|
990
990
|
}
|
|
991
991
|
},
|
|
992
|
-
sendDataChannelMessage:
|
|
993
|
-
sendTextMessage:
|
|
992
|
+
sendDataChannelMessage: Tt,
|
|
993
|
+
sendTextMessage: Rt,
|
|
994
994
|
publishMicrophoneStream: vt,
|
|
995
|
-
unpublishMicrophoneStream:
|
|
995
|
+
unpublishMicrophoneStream: _e,
|
|
996
996
|
publishCameraStream: Ct,
|
|
997
|
-
unpublishCameraStream:
|
|
997
|
+
unpublishCameraStream: Ae,
|
|
998
998
|
registerRpcMethod(u, m) {
|
|
999
999
|
l == null || l.registerRpcMethod(u, m);
|
|
1000
1000
|
},
|
|
@@ -1003,7 +1003,7 @@ async function yn(e, n, i) {
|
|
|
1003
1003
|
},
|
|
1004
1004
|
sessionId: K,
|
|
1005
1005
|
streamId: K,
|
|
1006
|
-
streamType:
|
|
1006
|
+
streamType: D,
|
|
1007
1007
|
interruptAvailable: de,
|
|
1008
1008
|
isInterruptible: ne
|
|
1009
1009
|
};
|
|
@@ -1026,19 +1026,19 @@ function Cn(e, n, i) {
|
|
|
1026
1026
|
}
|
|
1027
1027
|
async function Sn(e, n) {
|
|
1028
1028
|
const i = {
|
|
1029
|
-
type:
|
|
1029
|
+
type: R.StreamInterrupt,
|
|
1030
1030
|
videoId: n,
|
|
1031
1031
|
timestamp: Date.now()
|
|
1032
1032
|
};
|
|
1033
1033
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
1034
1034
|
}
|
|
1035
|
-
async function
|
|
1035
|
+
async function Tn(e) {
|
|
1036
1036
|
const n = {
|
|
1037
1037
|
topic: Ue.Interrupt
|
|
1038
1038
|
};
|
|
1039
1039
|
e.sendDataChannelMessage(JSON.stringify(n));
|
|
1040
1040
|
}
|
|
1041
|
-
function
|
|
1041
|
+
function Rn(e) {
|
|
1042
1042
|
return new Promise((n, i) => {
|
|
1043
1043
|
const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage: c = null, onOpen: t = null, onClose: d = null, onError: h = null } = r || {}, g = new WebSocket(`${s}?authorization=${encodeURIComponent(mt(a, o))}`);
|
|
1044
1044
|
g.onmessage = c, g.onclose = d, g.onerror = (l) => {
|
|
@@ -1053,7 +1053,7 @@ async function En(e) {
|
|
|
1053
1053
|
let i = null;
|
|
1054
1054
|
for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
|
|
1055
1055
|
try {
|
|
1056
|
-
i = await
|
|
1056
|
+
i = await Rn(e);
|
|
1057
1057
|
} catch (s) {
|
|
1058
1058
|
if (r === n)
|
|
1059
1059
|
throw s;
|
|
@@ -1100,7 +1100,7 @@ function In(e, n, i) {
|
|
|
1100
1100
|
id: e.id || `user-${Date.now()}`,
|
|
1101
1101
|
role: e.role,
|
|
1102
1102
|
content: e.content,
|
|
1103
|
-
parts:
|
|
1103
|
+
parts: Re(e.content),
|
|
1104
1104
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1105
1105
|
transcribed: !0
|
|
1106
1106
|
};
|
|
@@ -1130,9 +1130,9 @@ function Dn(e, n, i, r, s, a) {
|
|
|
1130
1130
|
const { content: d, sequence: h } = n;
|
|
1131
1131
|
e === X.Partial ? i[h] = d : i.answer = d;
|
|
1132
1132
|
const g = Mn(i);
|
|
1133
|
-
(t.content !== g || e === X.Answer) && (t.content = g, t.parts =
|
|
1133
|
+
(t.content !== g || e === X.Answer) && (t.content = g, t.parts = Re(g), s == null || s([...r.messages], e));
|
|
1134
1134
|
}
|
|
1135
|
-
function
|
|
1135
|
+
function _n(e, n, i, r, s) {
|
|
1136
1136
|
let a = {};
|
|
1137
1137
|
const o = () => a = {};
|
|
1138
1138
|
let c = "answer";
|
|
@@ -1145,31 +1145,31 @@ function An(e, n, i, r, s) {
|
|
|
1145
1145
|
onMessage: (d, h) => {
|
|
1146
1146
|
var g, l;
|
|
1147
1147
|
if ("content" in h) {
|
|
1148
|
-
const
|
|
1149
|
-
Dn(
|
|
1148
|
+
const p = d === R.ChatAnswer ? X.Answer : d === R.ChatAudioTranscribed ? X.Transcribe : d;
|
|
1149
|
+
Dn(p, h, a, n, t, o), p === X.Answer && e.track("agent-message-received", {
|
|
1150
1150
|
content: h.content,
|
|
1151
1151
|
messages: n.messages.length,
|
|
1152
1152
|
mode: n.chatMode
|
|
1153
1153
|
});
|
|
1154
1154
|
} else {
|
|
1155
|
-
const
|
|
1156
|
-
if (d = d, d ===
|
|
1155
|
+
const p = R, D = [p.StreamVideoDone, p.StreamVideoError, p.StreamVideoRejected], N = [p.StreamFailed, p.StreamVideoError, p.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
|
|
1156
|
+
if (d = d, d === p.StreamVideoCreated && (e.linkTrack("agent-video", B, p.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1157
1157
|
const F = n.messages[n.messages.length - 1];
|
|
1158
1158
|
if ((F == null ? void 0 : F.role) === "assistant") {
|
|
1159
1159
|
const I = { ...F, sentiment: h.sentiment };
|
|
1160
1160
|
n.messages[n.messages.length - 1] = I, t == null || t([...n.messages], c);
|
|
1161
1161
|
}
|
|
1162
1162
|
}
|
|
1163
|
-
if (
|
|
1163
|
+
if (D.includes(d)) {
|
|
1164
1164
|
const F = d.split("/")[1];
|
|
1165
1165
|
N.includes(d) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, d, ["done"]);
|
|
1166
1166
|
}
|
|
1167
|
-
N.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: h })), h.event ===
|
|
1167
|
+
N.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: h })), h.event === p.StreamDone && s();
|
|
1168
1168
|
}
|
|
1169
1169
|
}
|
|
1170
1170
|
};
|
|
1171
1171
|
}
|
|
1172
|
-
function
|
|
1172
|
+
function An(e, n, i, r) {
|
|
1173
1173
|
const s = ze(e, `${n}/agents/${i}`, r);
|
|
1174
1174
|
return {
|
|
1175
1175
|
createStream(a, o) {
|
|
@@ -1243,7 +1243,7 @@ function Pn({
|
|
|
1243
1243
|
report: r,
|
|
1244
1244
|
log: s
|
|
1245
1245
|
}) {
|
|
1246
|
-
e ===
|
|
1246
|
+
e === k.Start && n === k.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(k.Start)) : e === k.Stop && n === k.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(k.Stop, r));
|
|
1247
1247
|
}
|
|
1248
1248
|
function xn({
|
|
1249
1249
|
statsSignal: e,
|
|
@@ -1253,7 +1253,7 @@ function xn({
|
|
|
1253
1253
|
report: s,
|
|
1254
1254
|
log: a
|
|
1255
1255
|
}) {
|
|
1256
|
-
e ===
|
|
1256
|
+
e === k.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(k.Start)) : e === k.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(k.Stop, s)), n === k.Start ? r == null || r(W.Talking) : n === k.Stop && (r == null || r(W.Idle));
|
|
1257
1257
|
}
|
|
1258
1258
|
function ot({
|
|
1259
1259
|
statsSignal: e,
|
|
@@ -1276,8 +1276,8 @@ function ot({
|
|
|
1276
1276
|
async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, c) {
|
|
1277
1277
|
var J;
|
|
1278
1278
|
const t = pt(i, "WebRTCStreamingManager"), d = Ln(t);
|
|
1279
|
-
let h = !1, g = !1, l =
|
|
1280
|
-
const { startConnection:
|
|
1279
|
+
let h = !1, g = !1, l = k.Stop, p = k.Stop;
|
|
1280
|
+
const { startConnection: D, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } = An(
|
|
1281
1281
|
s,
|
|
1282
1282
|
a,
|
|
1283
1283
|
e,
|
|
@@ -1299,57 +1299,57 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1299
1299
|
"stream-type": H
|
|
1300
1300
|
});
|
|
1301
1301
|
const re = n.stream_warmup && !te, de = () => h, ue = () => {
|
|
1302
|
-
var
|
|
1303
|
-
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (
|
|
1302
|
+
var y;
|
|
1303
|
+
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (y = r.onConnectionStateChange) == null || y.call(r, x.Connected));
|
|
1304
1304
|
}, f = yt(
|
|
1305
1305
|
() => $.getStats(),
|
|
1306
1306
|
de,
|
|
1307
1307
|
ue,
|
|
1308
|
-
(
|
|
1309
|
-
statsSignal:
|
|
1308
|
+
(y, v) => ot({
|
|
1309
|
+
statsSignal: p = y,
|
|
1310
1310
|
dataChannelSignal: H === se.Legacy ? l : void 0,
|
|
1311
1311
|
onVideoStateChange: r.onVideoStateChange,
|
|
1312
1312
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1313
|
-
report:
|
|
1313
|
+
report: v,
|
|
1314
1314
|
streamType: H,
|
|
1315
1315
|
log: t
|
|
1316
1316
|
}),
|
|
1317
|
-
(
|
|
1318
|
-
var
|
|
1319
|
-
return (
|
|
1317
|
+
(y) => {
|
|
1318
|
+
var v;
|
|
1319
|
+
return (v = r.onConnectivityStateChange) == null ? void 0 : v.call(r, y);
|
|
1320
1320
|
}
|
|
1321
1321
|
);
|
|
1322
|
-
f.start(), $.onicecandidate = (
|
|
1323
|
-
var
|
|
1324
|
-
t("peerConnection.onicecandidate",
|
|
1322
|
+
f.start(), $.onicecandidate = (y) => {
|
|
1323
|
+
var v;
|
|
1324
|
+
t("peerConnection.onicecandidate", y);
|
|
1325
1325
|
try {
|
|
1326
|
-
|
|
1326
|
+
y.candidate && y.candidate.sdpMid && y.candidate.sdpMLineIndex !== null ? I(
|
|
1327
1327
|
M,
|
|
1328
1328
|
{
|
|
1329
|
-
candidate:
|
|
1330
|
-
sdpMid:
|
|
1331
|
-
sdpMLineIndex:
|
|
1329
|
+
candidate: y.candidate.candidate,
|
|
1330
|
+
sdpMid: y.candidate.sdpMid,
|
|
1331
|
+
sdpMLineIndex: y.candidate.sdpMLineIndex
|
|
1332
1332
|
},
|
|
1333
1333
|
U,
|
|
1334
1334
|
c
|
|
1335
1335
|
) : I(M, { candidate: null }, U, c);
|
|
1336
|
-
} catch (
|
|
1337
|
-
(
|
|
1336
|
+
} catch (E) {
|
|
1337
|
+
(v = r.onError) == null || v.call(r, E, { streamId: M });
|
|
1338
1338
|
}
|
|
1339
1339
|
}, K.onopen = () => {
|
|
1340
1340
|
g = !0, (!re || h) && ue();
|
|
1341
1341
|
};
|
|
1342
|
-
const C = (
|
|
1343
|
-
var
|
|
1344
|
-
(
|
|
1342
|
+
const C = (y) => {
|
|
1343
|
+
var v;
|
|
1344
|
+
(v = r.onVideoIdChange) == null || v.call(r, y);
|
|
1345
1345
|
};
|
|
1346
|
-
function
|
|
1347
|
-
if (
|
|
1348
|
-
const
|
|
1349
|
-
C(
|
|
1346
|
+
function T(y, v) {
|
|
1347
|
+
if (y === R.StreamStarted && typeof v == "object" && "metadata" in v) {
|
|
1348
|
+
const E = v.metadata;
|
|
1349
|
+
C(E.videoId);
|
|
1350
1350
|
}
|
|
1351
|
-
|
|
1352
|
-
statsSignal: H === se.Legacy ?
|
|
1351
|
+
y === R.StreamDone && C(null), l = y === R.StreamStarted ? k.Start : k.Stop, ot({
|
|
1352
|
+
statsSignal: H === se.Legacy ? p : void 0,
|
|
1353
1353
|
dataChannelSignal: l,
|
|
1354
1354
|
onVideoStateChange: r.onVideoStateChange,
|
|
1355
1355
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
@@ -1357,76 +1357,76 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1357
1357
|
log: t
|
|
1358
1358
|
});
|
|
1359
1359
|
}
|
|
1360
|
-
function A(
|
|
1360
|
+
function A(y, v) {
|
|
1361
1361
|
var j;
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1362
|
+
const E = typeof v == "string" ? v : v == null ? void 0 : v.metadata;
|
|
1363
|
+
E && o.enrich({ streamMetadata: E }), (j = r.onStreamReady) == null || j.call(r);
|
|
1364
1364
|
}
|
|
1365
|
-
const
|
|
1366
|
-
[
|
|
1367
|
-
[
|
|
1368
|
-
[
|
|
1365
|
+
const _ = {
|
|
1366
|
+
[R.StreamStarted]: T,
|
|
1367
|
+
[R.StreamDone]: T,
|
|
1368
|
+
[R.StreamReady]: A
|
|
1369
1369
|
};
|
|
1370
|
-
K.onmessage = (
|
|
1370
|
+
K.onmessage = (y) => {
|
|
1371
1371
|
var j;
|
|
1372
|
-
const { subject:
|
|
1373
|
-
(j =
|
|
1372
|
+
const { subject: v, data: E } = d(y.data);
|
|
1373
|
+
(j = _[v]) == null || j.call(_, v, E);
|
|
1374
1374
|
}, $.oniceconnectionstatechange = () => {
|
|
1375
|
-
var
|
|
1375
|
+
var v;
|
|
1376
1376
|
t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
}, $.ontrack = (
|
|
1380
|
-
var
|
|
1381
|
-
t("peerConnection.ontrack",
|
|
1377
|
+
const y = at($.iceConnectionState);
|
|
1378
|
+
y !== x.Connected && ((v = r.onConnectionStateChange) == null || v.call(r, y));
|
|
1379
|
+
}, $.ontrack = (y) => {
|
|
1380
|
+
var v;
|
|
1381
|
+
t("peerConnection.ontrack", y), t("CALLBACK: onSrcObjectReady"), (v = r.onSrcObjectReady) == null || v.call(r, y.streams[0]);
|
|
1382
1382
|
}, await $.setRemoteDescription(Y), t("set remote description OK");
|
|
1383
|
-
const
|
|
1384
|
-
return t("create answer OK"), await $.setLocalDescription(
|
|
1383
|
+
const L = await $.createAnswer();
|
|
1384
|
+
return t("create answer OK"), await $.setLocalDescription(L), t("set local description OK"), await D(M, L, U, c), t("start connection OK"), {
|
|
1385
1385
|
/**
|
|
1386
1386
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1387
1387
|
* @param payload
|
|
1388
1388
|
*/
|
|
1389
|
-
speak(
|
|
1390
|
-
return N(M, U,
|
|
1389
|
+
speak(y) {
|
|
1390
|
+
return N(M, U, y);
|
|
1391
1391
|
},
|
|
1392
1392
|
/**
|
|
1393
1393
|
* Method to close RTC connection
|
|
1394
1394
|
*/
|
|
1395
1395
|
async disconnect() {
|
|
1396
|
-
var
|
|
1396
|
+
var y;
|
|
1397
1397
|
if (M) {
|
|
1398
|
-
const
|
|
1398
|
+
const v = at($.iceConnectionState);
|
|
1399
1399
|
if ($) {
|
|
1400
|
-
if (
|
|
1400
|
+
if (v === x.New) {
|
|
1401
1401
|
f.stop();
|
|
1402
1402
|
return;
|
|
1403
1403
|
}
|
|
1404
1404
|
$.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
|
|
1405
1405
|
}
|
|
1406
1406
|
try {
|
|
1407
|
-
|
|
1407
|
+
v === x.Connected && await B(M, U).catch((E) => {
|
|
1408
1408
|
});
|
|
1409
|
-
} catch (
|
|
1410
|
-
t("Error on close stream connection",
|
|
1409
|
+
} catch (E) {
|
|
1410
|
+
t("Error on close stream connection", E);
|
|
1411
1411
|
}
|
|
1412
|
-
(
|
|
1412
|
+
(y = r.onAgentActivityStateChange) == null || y.call(r, W.Idle), f.stop();
|
|
1413
1413
|
}
|
|
1414
1414
|
},
|
|
1415
1415
|
/**
|
|
1416
1416
|
* Method to send data channel messages to the server
|
|
1417
1417
|
*/
|
|
1418
|
-
sendDataChannelMessage(
|
|
1419
|
-
var
|
|
1418
|
+
sendDataChannelMessage(y) {
|
|
1419
|
+
var v, E;
|
|
1420
1420
|
if (!h || K.readyState !== "open") {
|
|
1421
|
-
t("Data channel is not ready for sending messages"), (
|
|
1421
|
+
t("Data channel is not ready for sending messages"), (v = r.onError) == null || v.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1422
1422
|
streamId: M
|
|
1423
1423
|
});
|
|
1424
1424
|
return;
|
|
1425
1425
|
}
|
|
1426
1426
|
try {
|
|
1427
|
-
K.send(
|
|
1427
|
+
K.send(y);
|
|
1428
1428
|
} catch (j) {
|
|
1429
|
-
t("Error sending data channel message", j), (
|
|
1429
|
+
t("Error sending data channel message", j), (E = r.onError) == null || E.call(r, j, { streamId: M });
|
|
1430
1430
|
}
|
|
1431
1431
|
},
|
|
1432
1432
|
/**
|
|
@@ -1495,7 +1495,7 @@ function Vn(e, n, i, r, s) {
|
|
|
1495
1495
|
s === se.Fluent ? Un(e, n, i, r, s) : Jn(e, n, i, r, s);
|
|
1496
1496
|
}
|
|
1497
1497
|
function Un(e, n, i, r, s) {
|
|
1498
|
-
e ===
|
|
1498
|
+
e === k.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === k.Stop && r.track("stream-session", {
|
|
1499
1499
|
event: "stop",
|
|
1500
1500
|
is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
|
|
1501
1501
|
background: n.presenter.type === "clip" && n.presenter.background,
|
|
@@ -1504,9 +1504,9 @@ function Un(e, n, i, r, s) {
|
|
|
1504
1504
|
});
|
|
1505
1505
|
}
|
|
1506
1506
|
function st(e, n, i, r, s) {
|
|
1507
|
-
e ===
|
|
1508
|
-
|
|
1509
|
-
]) : e ===
|
|
1507
|
+
e === k.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
|
|
1508
|
+
R.StreamVideoCreated
|
|
1509
|
+
]) : e === k.Stop && i.linkTrack(
|
|
1510
1510
|
"agent-video",
|
|
1511
1511
|
{
|
|
1512
1512
|
event: "stop",
|
|
@@ -1515,16 +1515,16 @@ function st(e, n, i, r, s) {
|
|
|
1515
1515
|
"stream-type": r
|
|
1516
1516
|
},
|
|
1517
1517
|
"done",
|
|
1518
|
-
[
|
|
1518
|
+
[R.StreamVideoDone]
|
|
1519
1519
|
);
|
|
1520
1520
|
}
|
|
1521
1521
|
function Jn(e, n, i, r, s) {
|
|
1522
|
-
e ===
|
|
1522
|
+
e === k.Start ? r.linkTrack(
|
|
1523
1523
|
"agent-video",
|
|
1524
1524
|
{ event: "start", latency: oe.get(!0), "stream-type": s },
|
|
1525
1525
|
"start",
|
|
1526
|
-
[
|
|
1527
|
-
) : e ===
|
|
1526
|
+
[R.StreamVideoCreated]
|
|
1527
|
+
) : e === k.Stop && r.linkTrack(
|
|
1528
1528
|
"agent-video",
|
|
1529
1529
|
{
|
|
1530
1530
|
event: "stop",
|
|
@@ -1534,9 +1534,26 @@ function Jn(e, n, i, r, s) {
|
|
|
1534
1534
|
...i
|
|
1535
1535
|
},
|
|
1536
1536
|
"done",
|
|
1537
|
-
[
|
|
1537
|
+
[R.StreamVideoDone]
|
|
1538
1538
|
);
|
|
1539
1539
|
}
|
|
1540
|
+
function On(e, n, i) {
|
|
1541
|
+
const r = {
|
|
1542
|
+
call_id: n.call_id,
|
|
1543
|
+
name: n.name
|
|
1544
|
+
};
|
|
1545
|
+
if (e === R.ToolCallStarted) {
|
|
1546
|
+
i.track("agent-tool-call", { ...r, event: "started" });
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
const s = n;
|
|
1550
|
+
i.track("agent-tool-call", {
|
|
1551
|
+
...r,
|
|
1552
|
+
event: e === R.ToolCallDone ? "done" : "error",
|
|
1553
|
+
duration_ms: s.duration_ms,
|
|
1554
|
+
extra_keys: s.extra ? Object.keys(s.extra).length : 0
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1540
1557
|
function ct(e, n, i, r) {
|
|
1541
1558
|
return oe.reset(), nt.update(), new Promise(async (s, a) => {
|
|
1542
1559
|
try {
|
|
@@ -1556,12 +1573,12 @@ function ct(e, n, i, r) {
|
|
|
1556
1573
|
callbacks: {
|
|
1557
1574
|
...n.callbacks,
|
|
1558
1575
|
onConnectionStateChange: (g, l) => {
|
|
1559
|
-
var
|
|
1560
|
-
(
|
|
1576
|
+
var p, D;
|
|
1577
|
+
(D = (p = n.callbacks).onConnectionStateChange) == null || D.call(p, g), zn(g, l, i), g === x.Connected && (o ? s(o) : c = !0);
|
|
1561
1578
|
},
|
|
1562
1579
|
onVideoStateChange: (g, l) => {
|
|
1563
|
-
var
|
|
1564
|
-
(
|
|
1580
|
+
var p, D;
|
|
1581
|
+
(D = (p = n.callbacks).onVideoStateChange) == null || D.call(p, g), Vn(
|
|
1565
1582
|
g,
|
|
1566
1583
|
e,
|
|
1567
1584
|
l,
|
|
@@ -1570,17 +1587,17 @@ function ct(e, n, i, r) {
|
|
|
1570
1587
|
);
|
|
1571
1588
|
},
|
|
1572
1589
|
onAgentActivityStateChange: (g) => {
|
|
1573
|
-
var l,
|
|
1574
|
-
(
|
|
1590
|
+
var l, p;
|
|
1591
|
+
(p = (l = n.callbacks).onAgentActivityStateChange) == null || p.call(l, g), g === W.Talking ? (je.update(), d = (D) => {
|
|
1575
1592
|
st(
|
|
1576
|
-
|
|
1593
|
+
k.Start,
|
|
1577
1594
|
e,
|
|
1578
1595
|
i,
|
|
1579
1596
|
o.streamType,
|
|
1580
|
-
|
|
1597
|
+
D
|
|
1581
1598
|
), d = null;
|
|
1582
1599
|
}, h || d({ latency: oe.get(!0) })) : (je.reset(), d = null, st(
|
|
1583
|
-
|
|
1600
|
+
k.Stop,
|
|
1584
1601
|
e,
|
|
1585
1602
|
i,
|
|
1586
1603
|
o.streamType
|
|
@@ -1592,6 +1609,10 @@ function ct(e, n, i, r) {
|
|
|
1592
1609
|
onStreamReady: () => {
|
|
1593
1610
|
const g = nt.get(!0);
|
|
1594
1611
|
i.track("agent-chat", { event: "ready", latency: g });
|
|
1612
|
+
},
|
|
1613
|
+
onToolEvent: (g, l) => {
|
|
1614
|
+
var p, D;
|
|
1615
|
+
(D = (p = n.callbacks).onToolEvent) == null || D.call(p, g, l), On(g, l, i);
|
|
1595
1616
|
}
|
|
1596
1617
|
}
|
|
1597
1618
|
},
|
|
@@ -1602,11 +1623,11 @@ function ct(e, n, i, r) {
|
|
|
1602
1623
|
}
|
|
1603
1624
|
});
|
|
1604
1625
|
}
|
|
1605
|
-
async function
|
|
1606
|
-
var h, g, l,
|
|
1626
|
+
async function Wn(e, n, i, r, s) {
|
|
1627
|
+
var h, g, l, p;
|
|
1607
1628
|
const a = async () => {
|
|
1608
1629
|
if (Ke(e.presenter.type)) {
|
|
1609
|
-
const
|
|
1630
|
+
const D = await ct(e, n, r), N = `${Bn}_${D.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
|
|
1610
1631
|
return { chatResult: {
|
|
1611
1632
|
chatMode: O.Functional,
|
|
1612
1633
|
chat: {
|
|
@@ -1620,9 +1641,9 @@ async function On(e, n, i, r, s) {
|
|
|
1620
1641
|
chat_mode: O.Functional,
|
|
1621
1642
|
messages: []
|
|
1622
1643
|
}
|
|
1623
|
-
}, streamingManager:
|
|
1644
|
+
}, streamingManager: D };
|
|
1624
1645
|
} else {
|
|
1625
|
-
const
|
|
1646
|
+
const D = new AbortController(), N = D.signal;
|
|
1626
1647
|
let B;
|
|
1627
1648
|
try {
|
|
1628
1649
|
const F = ht(
|
|
@@ -1635,14 +1656,14 @@ async function On(e, n, i, r, s) {
|
|
|
1635
1656
|
), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [M, Y] = await Promise.all([F, I]);
|
|
1636
1657
|
return { chatResult: M, streamingManager: Y };
|
|
1637
1658
|
} catch (F) {
|
|
1638
|
-
throw
|
|
1659
|
+
throw D.abort(), B && await B.disconnect().catch(() => {
|
|
1639
1660
|
}), F;
|
|
1640
1661
|
}
|
|
1641
1662
|
}
|
|
1642
1663
|
}, { chatResult: o, streamingManager: c } = await a(), { chat: t, chatMode: d } = o;
|
|
1643
|
-
return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((
|
|
1664
|
+
return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((p = (l = n.callbacks).onError) == null || p.call(l, new It(d)), c == null || c.disconnect(), { chat: t }) : { chat: t, streamingManager: c };
|
|
1644
1665
|
}
|
|
1645
|
-
async function
|
|
1666
|
+
async function Qn(e, n) {
|
|
1646
1667
|
var H, re, de, ue;
|
|
1647
1668
|
let i = !0, r = null;
|
|
1648
1669
|
const s = n.mixpanelKey || zt, a = n.wsURL || Kt, o = n.baseURL || Ee, c = n.mode || O.Functional, t = {
|
|
@@ -1660,66 +1681,66 @@ async function qn(e, n) {
|
|
|
1660
1681
|
});
|
|
1661
1682
|
const g = Xt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1662
1683
|
n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
|
|
1663
|
-
const
|
|
1684
|
+
const p = Ke(l.presenter.type);
|
|
1664
1685
|
d.enrich(Gt(l));
|
|
1665
|
-
const { onMessage:
|
|
1666
|
-
var f, C,
|
|
1667
|
-
(f = t.socketManager) == null || f.disconnect(), (
|
|
1686
|
+
const { onMessage: D, clearQueue: N } = _n(d, t, n, l, () => {
|
|
1687
|
+
var f, C, T;
|
|
1688
|
+
(f = t.socketManager) == null || f.disconnect(), (T = (C = n.callbacks).onConnectionStateChange) == null || T.call(C, x.Disconnected);
|
|
1668
1689
|
});
|
|
1669
1690
|
t.messages = an(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
|
|
1670
1691
|
const B = (f) => {
|
|
1671
1692
|
r = f;
|
|
1672
1693
|
}, F = ({ type: f }) => {
|
|
1673
|
-
var
|
|
1674
|
-
if (!((
|
|
1694
|
+
var T, A, _, L, J;
|
|
1695
|
+
if (!((T = t.streamingManager) != null && T.interruptAvailable) || !((A = t.streamingManager) != null && A.isInterruptible)) return;
|
|
1675
1696
|
const C = t.messages[t.messages.length - 1];
|
|
1676
1697
|
d.track("agent-video-interrupt", {
|
|
1677
1698
|
type: f || "click",
|
|
1678
1699
|
video_duration_to_interrupt: je.get(!0),
|
|
1679
1700
|
message_duration_to_interrupt: oe.get(!0)
|
|
1680
|
-
}), C.interrupted = !0, (
|
|
1701
|
+
}), C.interrupted = !0, (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "answer"), p ? Tn(t.streamingManager) : (Cn(t.streamingManager, (J = t.streamingManager) == null ? void 0 : J.streamType, r), Sn(t.streamingManager, r));
|
|
1681
1702
|
}, I = /* @__PURE__ */ new Map();
|
|
1682
1703
|
function M(f) {
|
|
1683
1704
|
return async (C) => {
|
|
1684
|
-
const
|
|
1685
|
-
if (!
|
|
1705
|
+
const T = I.get(f);
|
|
1706
|
+
if (!T)
|
|
1686
1707
|
throw new Error(`No handler registered for client tool: ${f}`);
|
|
1687
1708
|
try {
|
|
1688
1709
|
const A = JSON.parse(C.payload);
|
|
1689
|
-
return await
|
|
1710
|
+
return await T(A);
|
|
1690
1711
|
} catch (A) {
|
|
1691
1712
|
throw new Error(`Client tool "${f}" failed: ${A.message}`);
|
|
1692
1713
|
}
|
|
1693
1714
|
};
|
|
1694
1715
|
}
|
|
1695
1716
|
function Y() {
|
|
1696
|
-
var f, C,
|
|
1697
|
-
for (const [
|
|
1698
|
-
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f,
|
|
1717
|
+
var f, C, T, A;
|
|
1718
|
+
for (const [_] of I)
|
|
1719
|
+
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, _), (A = (T = t.streamingManager) == null ? void 0 : T.registerRpcMethod) == null || A.call(T, _, M(_));
|
|
1699
1720
|
}
|
|
1700
1721
|
function Q(f, C) {
|
|
1701
|
-
var A,
|
|
1702
|
-
const
|
|
1703
|
-
I.set(f, C),
|
|
1722
|
+
var A, _;
|
|
1723
|
+
const T = !I.has(f);
|
|
1724
|
+
I.set(f, C), T && ((_ = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || _.call(A, f, M(f)));
|
|
1704
1725
|
}
|
|
1705
1726
|
function U(f) {
|
|
1706
|
-
var C,
|
|
1707
|
-
I.delete(f), (
|
|
1727
|
+
var C, T;
|
|
1728
|
+
I.delete(f), (T = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || T.call(C, f);
|
|
1708
1729
|
}
|
|
1709
1730
|
const te = Date.now();
|
|
1710
1731
|
tt(() => {
|
|
1711
1732
|
d.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
|
|
1712
1733
|
});
|
|
1713
1734
|
async function ne(f) {
|
|
1714
|
-
var J,
|
|
1715
|
-
(
|
|
1716
|
-
const C = c === O.DirectPlayback ||
|
|
1735
|
+
var J, y, v, E, j, G, he;
|
|
1736
|
+
(y = (J = n.callbacks).onConnectionStateChange) == null || y.call(J, x.Connecting), oe.reset(), f && !i && (delete t.chat, (E = (v = n.callbacks).onNewMessage) == null || E.call(v, [...t.messages], "answer"));
|
|
1737
|
+
const C = c === O.DirectPlayback || p ? Promise.resolve(void 0) : kn(
|
|
1717
1738
|
n.auth,
|
|
1718
1739
|
a,
|
|
1719
|
-
{ onMessage:
|
|
1740
|
+
{ onMessage: D, onError: n.callbacks.onError },
|
|
1720
1741
|
n.externalId
|
|
1721
|
-
),
|
|
1722
|
-
() =>
|
|
1742
|
+
), T = xe(
|
|
1743
|
+
() => Wn(
|
|
1723
1744
|
l,
|
|
1724
1745
|
{
|
|
1725
1746
|
...n,
|
|
@@ -1727,7 +1748,7 @@ async function qn(e, n) {
|
|
|
1727
1748
|
callbacks: {
|
|
1728
1749
|
...n.callbacks,
|
|
1729
1750
|
onVideoIdChange: B,
|
|
1730
|
-
onMessage:
|
|
1751
|
+
onMessage: D
|
|
1731
1752
|
}
|
|
1732
1753
|
},
|
|
1733
1754
|
g,
|
|
@@ -1744,20 +1765,20 @@ async function qn(e, n) {
|
|
|
1744
1765
|
).catch((Z) => {
|
|
1745
1766
|
var z, ee;
|
|
1746
1767
|
throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, x.Fail), Z;
|
|
1747
|
-
}), [A, { streamingManager:
|
|
1748
|
-
|
|
1749
|
-
chatId:
|
|
1750
|
-
streamId:
|
|
1768
|
+
}), [A, { streamingManager: _, chat: L }] = await Promise.all([C, T]);
|
|
1769
|
+
L && L.id !== ((j = t.chat) == null ? void 0 : j.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, L.id)), t.streamingManager = _, t.socketManager = A, t.chat = L, Y(), i = !1, d.enrich({
|
|
1770
|
+
chatId: L == null ? void 0 : L.id,
|
|
1771
|
+
streamId: _ == null ? void 0 : _.streamId,
|
|
1751
1772
|
mode: t.chatMode
|
|
1752
|
-
}), K((
|
|
1773
|
+
}), K((L == null ? void 0 : L.chat_mode) ?? c);
|
|
1753
1774
|
}
|
|
1754
1775
|
async function $() {
|
|
1755
|
-
var f, C,
|
|
1756
|
-
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (
|
|
1776
|
+
var f, C, T, A;
|
|
1777
|
+
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (T = n.callbacks).onConnectionStateChange) == null || A.call(T, x.Disconnected);
|
|
1757
1778
|
}
|
|
1758
1779
|
async function K(f) {
|
|
1759
|
-
var C,
|
|
1760
|
-
f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (
|
|
1780
|
+
var C, T;
|
|
1781
|
+
f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (T = (C = n.callbacks).onModeChange) == null || T.call(C, f));
|
|
1761
1782
|
}
|
|
1762
1783
|
return {
|
|
1763
1784
|
agent: l,
|
|
@@ -1781,7 +1802,7 @@ async function qn(e, n) {
|
|
|
1781
1802
|
},
|
|
1782
1803
|
async reconnect() {
|
|
1783
1804
|
const f = t.streamingManager;
|
|
1784
|
-
if (
|
|
1805
|
+
if (p && (f != null && f.reconnect)) {
|
|
1785
1806
|
try {
|
|
1786
1807
|
await f.reconnect(), d.track("agent-chat", {
|
|
1787
1808
|
event: "reconnect",
|
|
@@ -1826,7 +1847,7 @@ async function qn(e, n) {
|
|
|
1826
1847
|
return t.streamingManager.unpublishCameraStream();
|
|
1827
1848
|
},
|
|
1828
1849
|
async chat(f) {
|
|
1829
|
-
var
|
|
1850
|
+
var _, L, J, y, v;
|
|
1830
1851
|
const C = () => {
|
|
1831
1852
|
if (ft(c))
|
|
1832
1853
|
throw new me(`${c} is enabled, chat is disabled`);
|
|
@@ -1842,8 +1863,8 @@ async function qn(e, n) {
|
|
|
1842
1863
|
if (!t.chat)
|
|
1843
1864
|
throw new me("Chat is not initialized");
|
|
1844
1865
|
}
|
|
1845
|
-
},
|
|
1846
|
-
var
|
|
1866
|
+
}, T = async () => {
|
|
1867
|
+
var E, j;
|
|
1847
1868
|
if (!t.chat) {
|
|
1848
1869
|
const G = await ht(
|
|
1849
1870
|
l,
|
|
@@ -1854,12 +1875,12 @@ async function qn(e, n) {
|
|
|
1854
1875
|
);
|
|
1855
1876
|
if (!G.chat)
|
|
1856
1877
|
throw new Mt(t.chatMode, !!n.persistentChat);
|
|
1857
|
-
t.chat = G.chat, (j = (
|
|
1878
|
+
t.chat = G.chat, (j = (E = n.callbacks).onNewChat) == null || j.call(E, t.chat.id);
|
|
1858
1879
|
}
|
|
1859
1880
|
return t.chat.id;
|
|
1860
|
-
}, A = async (
|
|
1881
|
+
}, A = async (E, j) => {
|
|
1861
1882
|
const G = t.chatMode === O.Playground;
|
|
1862
|
-
return xe(
|
|
1883
|
+
return xe(p && !G ? async () => {
|
|
1863
1884
|
var z, ee;
|
|
1864
1885
|
return await ((ee = (z = t.streamingManager) == null ? void 0 : z.sendTextMessage) == null ? void 0 : ee.call(z, f)), Promise.resolve({});
|
|
1865
1886
|
} : async () => {
|
|
@@ -1871,7 +1892,7 @@ async function qn(e, n) {
|
|
|
1871
1892
|
chatMode: t.chatMode,
|
|
1872
1893
|
streamId: (z = t.streamingManager) == null ? void 0 : z.streamId,
|
|
1873
1894
|
sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
|
|
1874
|
-
messages:
|
|
1895
|
+
messages: E.map(({ matches: De, ...le }) => le)
|
|
1875
1896
|
},
|
|
1876
1897
|
{
|
|
1877
1898
|
...gt(t.chatMode),
|
|
@@ -1895,55 +1916,55 @@ async function qn(e, n) {
|
|
|
1895
1916
|
id: ge(),
|
|
1896
1917
|
role: "user",
|
|
1897
1918
|
content: f,
|
|
1898
|
-
parts:
|
|
1919
|
+
parts: Re(f),
|
|
1899
1920
|
created_at: new Date(oe.update()).toISOString()
|
|
1900
|
-
}), (
|
|
1901
|
-
const
|
|
1921
|
+
}), (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "user");
|
|
1922
|
+
const E = await T(), j = await A([...t.messages], E);
|
|
1902
1923
|
return t.messages.push({
|
|
1903
1924
|
id: ge(),
|
|
1904
1925
|
role: "assistant",
|
|
1905
1926
|
content: j.result || "",
|
|
1906
|
-
parts:
|
|
1927
|
+
parts: Re(j.result || ""),
|
|
1907
1928
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1908
1929
|
context: j.context,
|
|
1909
1930
|
matches: j.matches
|
|
1910
1931
|
}), d.track("agent-message-send", {
|
|
1911
1932
|
event: "success",
|
|
1912
1933
|
messages: t.messages.length + 1
|
|
1913
|
-
}), j.result && ((
|
|
1934
|
+
}), j.result && ((y = (J = n.callbacks).onNewMessage) == null || y.call(J, [...t.messages], "answer"), d.track("agent-message-received", {
|
|
1914
1935
|
latency: oe.get(!0),
|
|
1915
1936
|
messages: t.messages.length
|
|
1916
1937
|
})), j;
|
|
1917
|
-
} catch (
|
|
1918
|
-
throw ((
|
|
1938
|
+
} catch (E) {
|
|
1939
|
+
throw ((v = t.messages[t.messages.length - 1]) == null ? void 0 : v.role) === "assistant" && t.messages.pop(), d.track("agent-message-send", {
|
|
1919
1940
|
event: "error",
|
|
1920
1941
|
messages: t.messages.length
|
|
1921
|
-
}),
|
|
1942
|
+
}), E;
|
|
1922
1943
|
}
|
|
1923
1944
|
},
|
|
1924
|
-
rate(f, C,
|
|
1925
|
-
var
|
|
1926
|
-
const A = t.messages.find((
|
|
1945
|
+
rate(f, C, T) {
|
|
1946
|
+
var L, J, y, v;
|
|
1947
|
+
const A = t.messages.find((E) => E.id === f);
|
|
1927
1948
|
if (t.chat) {
|
|
1928
1949
|
if (!A)
|
|
1929
1950
|
throw new Error("Message not found");
|
|
1930
1951
|
} else throw new Error("Chat is not initialized");
|
|
1931
|
-
const
|
|
1952
|
+
const _ = ((L = A.matches) == null ? void 0 : L.map((E) => [E.document_id, E.id])) ?? [];
|
|
1932
1953
|
return d.track("agent-rate", {
|
|
1933
|
-
event:
|
|
1954
|
+
event: T ? "update" : "create",
|
|
1934
1955
|
thumb: C === 1 ? "up" : "down",
|
|
1935
1956
|
knowledge_id: ((J = l.knowledge) == null ? void 0 : J.id) ?? "",
|
|
1936
|
-
matches:
|
|
1957
|
+
matches: _,
|
|
1937
1958
|
score: C
|
|
1938
|
-
}),
|
|
1939
|
-
knowledge_id: ((
|
|
1959
|
+
}), T ? g.updateRating(l.id, t.chat.id, T, {
|
|
1960
|
+
knowledge_id: ((y = l.knowledge) == null ? void 0 : y.id) ?? "",
|
|
1940
1961
|
message_id: f,
|
|
1941
|
-
matches:
|
|
1962
|
+
matches: _,
|
|
1942
1963
|
score: C
|
|
1943
1964
|
}) : g.createRating(l.id, t.chat.id, {
|
|
1944
|
-
knowledge_id: ((
|
|
1965
|
+
knowledge_id: ((v = l.knowledge) == null ? void 0 : v.id) ?? "",
|
|
1945
1966
|
message_id: f,
|
|
1946
|
-
matches:
|
|
1967
|
+
matches: _,
|
|
1947
1968
|
score: C
|
|
1948
1969
|
});
|
|
1949
1970
|
},
|
|
@@ -1953,7 +1974,7 @@ async function qn(e, n) {
|
|
|
1953
1974
|
return d.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
|
|
1954
1975
|
},
|
|
1955
1976
|
async speak(f) {
|
|
1956
|
-
var
|
|
1977
|
+
var _, L, J;
|
|
1957
1978
|
function C() {
|
|
1958
1979
|
if (typeof f == "string") {
|
|
1959
1980
|
if (!l.presenter.voice)
|
|
@@ -1977,14 +1998,14 @@ async function qn(e, n) {
|
|
|
1977
1998
|
}
|
|
1978
1999
|
return f;
|
|
1979
2000
|
}
|
|
1980
|
-
const
|
|
1981
|
-
if (d.track("agent-speak",
|
|
2001
|
+
const T = C();
|
|
2002
|
+
if (d.track("agent-speak", T), oe.update(), t.messages && T.type === "text" && (t.messages.push({
|
|
1982
2003
|
id: ge(),
|
|
1983
2004
|
role: "assistant",
|
|
1984
|
-
content:
|
|
1985
|
-
parts:
|
|
2005
|
+
content: T.input,
|
|
2006
|
+
parts: Re(T.input),
|
|
1986
2007
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1987
|
-
}), (
|
|
2008
|
+
}), (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "answer")), Ot(t.chatMode))
|
|
1988
2009
|
return {
|
|
1989
2010
|
duration: 0,
|
|
1990
2011
|
video_id: "",
|
|
@@ -1993,7 +2014,7 @@ async function qn(e, n) {
|
|
|
1993
2014
|
if (!t.streamingManager)
|
|
1994
2015
|
throw new Error("Please connect to the agent first");
|
|
1995
2016
|
return t.streamingManager.speak({
|
|
1996
|
-
script:
|
|
2017
|
+
script: T,
|
|
1997
2018
|
metadata: { chat_id: (J = t.chat) == null ? void 0 : J.id, agent_id: l.id }
|
|
1998
2019
|
});
|
|
1999
2020
|
},
|
|
@@ -2013,20 +2034,20 @@ export {
|
|
|
2013
2034
|
ae as ConnectivityState,
|
|
2014
2035
|
$t as DocumentType,
|
|
2015
2036
|
xt as KnowledgeType,
|
|
2016
|
-
|
|
2037
|
+
At as PlanGroup,
|
|
2017
2038
|
jt as Providers,
|
|
2018
2039
|
Lt as RateState,
|
|
2019
|
-
|
|
2040
|
+
R as StreamEvents,
|
|
2020
2041
|
se as StreamType,
|
|
2021
|
-
|
|
2042
|
+
k as StreamingState,
|
|
2022
2043
|
Pt as Subject,
|
|
2023
2044
|
Ne as TransportProvider,
|
|
2024
|
-
|
|
2045
|
+
_t as UserPlan,
|
|
2025
2046
|
me as ValidationError,
|
|
2026
2047
|
dt as VideoType,
|
|
2027
2048
|
Bt as VoiceAccess,
|
|
2028
2049
|
Dt as WsError,
|
|
2029
|
-
|
|
2030
|
-
|
|
2050
|
+
Qn as createAgentManager,
|
|
2051
|
+
qn as mapVideoType,
|
|
2031
2052
|
Wt as parseMessageParts
|
|
2032
2053
|
};
|