@d-id/client-sdk 1.1.20 → 1.1.21
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-DcoRNuxp.js → index-BH8ByqOr.js} +249 -248
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-CNKaXUpT.js → livekit-manager-D9xuX-OS.js} +62 -68
- package/dist/src/api/streams/streamsApiV2.d.ts +2 -2
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +2 -2
- package/dist/src/services/streaming-manager/common.d.ts +2 -2
- package/dist/src/services/streaming-manager/factory.d.ts +3 -3
- package/dist/src/services/streaming-manager/livekit-manager.d.ts +2 -2
- package/dist/src/types/stream/streams-v2.d.ts +6 -7
- package/package.json +1 -1
|
@@ -35,8 +35,8 @@ class _e extends ee {
|
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var Te = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Te || {}), Ae = /* @__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))(Ae || {}), Pe = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Pe || {}), be = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(be || {}),
|
|
39
|
-
const
|
|
38
|
+
var Te = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Te || {}), Ae = /* @__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))(Ae || {}), Pe = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Pe || {}), be = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(be || {}), I = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(I || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), je = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(je || {}), Le = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Le || {}), xe = /* @__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))(xe || {}), he = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(he || {});
|
|
39
|
+
const xt = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,11 +48,11 @@ const Lt = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), Z = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Z || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), L = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", 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))(L || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(_ || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), ce = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ce || {}), $e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))($e || {}), Be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Be || {});
|
|
52
52
|
const ze = 45 * 1e3, Fe = "X-Playground-Chat", te = "https://api.d-id.com", Ne = "wss://notifications.d-id.com", Je = "79f81a83a67430be2bc0fd61042b8faa", pe = (e) => new Promise((t) => setTimeout(t, e)), O = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
54
|
return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
-
},
|
|
55
|
+
}, we = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, de = (e) => e === he.Expressive, We = (e) => [I.TextOnly, I.Playground, I.Maintenance].includes(e), ve = (e) => e && [I.DirectPlayback, I.Off].includes(e);
|
|
56
56
|
function Ue(e, t) {
|
|
57
57
|
let a;
|
|
58
58
|
return {
|
|
@@ -97,7 +97,7 @@ function ae(e) {
|
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
99
|
let Ke = O();
|
|
100
|
-
function
|
|
100
|
+
function ye(e, t) {
|
|
101
101
|
if (e.type === "bearer")
|
|
102
102
|
return `Bearer ${e.token}`;
|
|
103
103
|
if (e.type === "basic")
|
|
@@ -112,14 +112,14 @@ const He = (e) => ne(e, {
|
|
|
112
112
|
timeout: 0,
|
|
113
113
|
shouldRetryFn: (t) => t.status === 429
|
|
114
114
|
});
|
|
115
|
-
function
|
|
115
|
+
function ke(e, t = te, a, r) {
|
|
116
116
|
const o = async (i, c) => {
|
|
117
117
|
const { skipErrorHandler: n, ...s } = c || {}, d = await He(
|
|
118
118
|
() => fetch(t + (i != null && i.startsWith("/") ? i : `/${i}`), {
|
|
119
119
|
...s,
|
|
120
120
|
headers: {
|
|
121
121
|
...s.headers,
|
|
122
|
-
Authorization:
|
|
122
|
+
Authorization: ye(e, r),
|
|
123
123
|
"Content-Type": "application/json"
|
|
124
124
|
}
|
|
125
125
|
})
|
|
@@ -147,7 +147,7 @@ function Ce(e, t = te, a, r) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
function Ve(e, t = te, a, r) {
|
|
150
|
-
const o =
|
|
150
|
+
const o = ke(e, `${t}/agents`, a, r);
|
|
151
151
|
return {
|
|
152
152
|
create(i, c) {
|
|
153
153
|
return o.post("/", i, c);
|
|
@@ -195,7 +195,7 @@ function qe(e) {
|
|
|
195
195
|
isMobile: `${t() == "Mobile"}`,
|
|
196
196
|
browser: navigator.userAgent,
|
|
197
197
|
origin: window.location.origin,
|
|
198
|
-
agentType:
|
|
198
|
+
agentType: we(r),
|
|
199
199
|
agentVoice: {
|
|
200
200
|
voiceId: (i = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : i.voice_id,
|
|
201
201
|
provider: (n = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : n.type
|
|
@@ -206,7 +206,7 @@ function Oe(e) {
|
|
|
206
206
|
var a, r, o, i, c, n;
|
|
207
207
|
const t = (a = e.llm) == null ? void 0 : a.prompt_customization;
|
|
208
208
|
return {
|
|
209
|
-
agentType:
|
|
209
|
+
agentType: we(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
211
211
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
212
212
|
behavior: {
|
|
@@ -225,7 +225,7 @@ function Oe(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const Xe = (e) => e.reduce((t, a) => t + a, 0),
|
|
228
|
+
const Xe = (e) => e.reduce((t, a) => t + a, 0), le = (e) => Xe(e) / e.length;
|
|
229
229
|
function Ye(e, t, a) {
|
|
230
230
|
var s, d, l;
|
|
231
231
|
const { event: r, ...o } = e, { template: i } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((s = t == null ? void 0 : t.presenter) == null ? void 0 : s.voice) || {};
|
|
@@ -237,7 +237,7 @@ function Ye(e, t, a) {
|
|
|
237
237
|
...a
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function ue(e) {
|
|
241
241
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
242
|
}
|
|
243
243
|
let re = {};
|
|
@@ -315,13 +315,13 @@ function De() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const
|
|
319
|
-
function
|
|
320
|
-
return e ===
|
|
318
|
+
const F = De(), ie = De();
|
|
319
|
+
function Ce(e) {
|
|
320
|
+
return e === I.Playground ? { headers: { [Fe]: "true" } } : {};
|
|
321
321
|
}
|
|
322
|
-
async function
|
|
322
|
+
async function Re(e, t, a, r, o = !1, i) {
|
|
323
323
|
try {
|
|
324
|
-
return !i && !
|
|
324
|
+
return !i && !ve(r) && (i = await t.newChat(e.id, { persist: o }, Ce(r)), a.track("agent-chat", {
|
|
325
325
|
event: "created",
|
|
326
326
|
chatId: i.id,
|
|
327
327
|
mode: r
|
|
@@ -352,7 +352,7 @@ function et(e, t, a) {
|
|
|
352
352
|
}
|
|
353
353
|
async function tt(e, t) {
|
|
354
354
|
const a = {
|
|
355
|
-
type:
|
|
355
|
+
type: L.StreamInterrupt,
|
|
356
356
|
videoId: t,
|
|
357
357
|
timestamp: Date.now()
|
|
358
358
|
};
|
|
@@ -360,7 +360,7 @@ async function tt(e, t) {
|
|
|
360
360
|
}
|
|
361
361
|
function rt(e) {
|
|
362
362
|
return new Promise((t, a) => {
|
|
363
|
-
const { callbacks: r, host: o, auth: i, externalId: c } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: l = null } = r || {}, u = new WebSocket(`${o}?authorization=${encodeURIComponent(
|
|
363
|
+
const { callbacks: r, host: o, auth: i, externalId: c } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: l = null } = r || {}, u = new WebSocket(`${o}?authorization=${encodeURIComponent(ye(i, c))}`);
|
|
364
364
|
u.onmessage = n, u.onclose = d, u.onerror = (y) => {
|
|
365
365
|
console.error(y), l == null || l("Websocket failed to connect", y), a(y);
|
|
366
366
|
}, u.onopen = (y) => {
|
|
@@ -432,12 +432,12 @@ function ot(e, t, a, r, o) {
|
|
|
432
432
|
mode: t.chatMode
|
|
433
433
|
});
|
|
434
434
|
else {
|
|
435
|
-
const l =
|
|
435
|
+
const l = L, u = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], y = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], P = Ye(n, r, { mode: t.chatMode });
|
|
436
436
|
if (c = c, c === l.StreamVideoCreated)
|
|
437
|
-
e.linkTrack("agent-video",
|
|
437
|
+
e.linkTrack("agent-video", P, l.StreamVideoCreated, ["start"]);
|
|
438
438
|
else if (u.includes(c)) {
|
|
439
|
-
const
|
|
440
|
-
y.includes(c) ? e.track("agent-video", { ...
|
|
439
|
+
const A = c.split("/")[1];
|
|
440
|
+
y.includes(c) ? e.track("agent-video", { ...P, event: A }) : e.linkTrack("agent-video", { ...P, event: A }, c, ["done"]);
|
|
441
441
|
}
|
|
442
442
|
y.includes(c) && ((d = (s = a.callbacks).onError) == null || d.call(s, new Error(`Stream failed with event ${c}`), { data: n })), n.event === l.StreamDone && o();
|
|
443
443
|
}
|
|
@@ -445,7 +445,7 @@ function ot(e, t, a, r, o) {
|
|
|
445
445
|
};
|
|
446
446
|
}
|
|
447
447
|
function ct(e, t, a, r) {
|
|
448
|
-
const o =
|
|
448
|
+
const o = ke(e, `${t}/agents/${a}`, r);
|
|
449
449
|
return {
|
|
450
450
|
createStream(i) {
|
|
451
451
|
return o.post("/streams", i);
|
|
@@ -592,19 +592,19 @@ function mt(e, t, a) {
|
|
|
592
592
|
webRTCStats: {
|
|
593
593
|
anomalies: o,
|
|
594
594
|
minRtt: Math.min(...n),
|
|
595
|
-
avgRtt:
|
|
595
|
+
avgRtt: le(n),
|
|
596
596
|
maxRtt: Math.max(...n),
|
|
597
597
|
aggregateReport: lt(e[0], e[e.length - 1], i),
|
|
598
598
|
minJitterDelayInInterval: Math.min(...c),
|
|
599
599
|
maxJitterDelayInInterval: Math.max(...c),
|
|
600
|
-
avgJitterDelayInInterval:
|
|
600
|
+
avgJitterDelayInInterval: le(c)
|
|
601
601
|
},
|
|
602
602
|
codec: e[0].codec,
|
|
603
603
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
|
-
const
|
|
607
|
-
function
|
|
606
|
+
const se = 100, gt = Math.max(Math.ceil(400 / se), 1), ht = 0.25, pt = 0.28;
|
|
607
|
+
function wt() {
|
|
608
608
|
let e = 0, t, a, r = 0;
|
|
609
609
|
return (o) => {
|
|
610
610
|
for (const i of o.values())
|
|
@@ -623,36 +623,36 @@ function pt() {
|
|
|
623
623
|
}
|
|
624
624
|
function vt(e, t, a, r, o) {
|
|
625
625
|
let i = [], c, n = 0, s = !1, d = Z.Unknown, l = Z.Unknown, u = 0, y = 0;
|
|
626
|
-
const
|
|
626
|
+
const P = wt();
|
|
627
627
|
return setInterval(async () => {
|
|
628
|
-
const
|
|
629
|
-
if (
|
|
630
|
-
n = 0, u =
|
|
628
|
+
const A = await e.getStats(), { isReceiving: N, avgJitterDelayInInterval: b, freezeCount: x } = P(A), R = ft(A);
|
|
629
|
+
if (N)
|
|
630
|
+
n = 0, u = x - y, l = b < ht ? Z.Strong : b > pt && u > 1 ? Z.Weak : d, l !== d && (o == null || o(l), d = l, y += u, u = 0), s || (r == null || r(p.Start), c = i[i.length - 1], i = [], s = !0), i.push(R);
|
|
631
631
|
else if (s && (n++, n >= gt)) {
|
|
632
|
-
const K = mt(i,
|
|
633
|
-
r == null || r(
|
|
632
|
+
const K = mt(i, se, c);
|
|
633
|
+
r == null || r(p.Stop, K), t() || a(), y = x, s = !1;
|
|
634
634
|
}
|
|
635
|
-
},
|
|
635
|
+
}, se);
|
|
636
636
|
}
|
|
637
637
|
const yt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
638
|
-
function
|
|
638
|
+
function fe(e) {
|
|
639
639
|
switch (e) {
|
|
640
640
|
case "connected":
|
|
641
|
-
return
|
|
641
|
+
return _.Connected;
|
|
642
642
|
case "checking":
|
|
643
|
-
return
|
|
643
|
+
return _.Connecting;
|
|
644
644
|
case "failed":
|
|
645
|
-
return
|
|
645
|
+
return _.Fail;
|
|
646
646
|
case "new":
|
|
647
|
-
return
|
|
647
|
+
return _.New;
|
|
648
648
|
case "closed":
|
|
649
|
-
return
|
|
649
|
+
return _.Closed;
|
|
650
650
|
case "disconnected":
|
|
651
|
-
return
|
|
651
|
+
return _.Disconnected;
|
|
652
652
|
case "completed":
|
|
653
|
-
return
|
|
653
|
+
return _.Completed;
|
|
654
654
|
default:
|
|
655
|
-
return
|
|
655
|
+
return _.New;
|
|
656
656
|
}
|
|
657
657
|
}
|
|
658
658
|
const kt = (e) => (t) => {
|
|
@@ -664,24 +664,24 @@ const kt = (e) => (t) => {
|
|
|
664
664
|
return e("Failed to parse data channel message, returning data as string", { subject: a, rawData: r, error: o }), { subject: a, data: r };
|
|
665
665
|
}
|
|
666
666
|
};
|
|
667
|
-
function
|
|
667
|
+
function Dt({
|
|
668
668
|
statsSignal: e,
|
|
669
669
|
dataChannelSignal: t,
|
|
670
670
|
onVideoStateChange: a,
|
|
671
671
|
report: r
|
|
672
672
|
}) {
|
|
673
|
-
e ===
|
|
673
|
+
e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop, r));
|
|
674
674
|
}
|
|
675
|
-
function
|
|
675
|
+
function Ct({
|
|
676
676
|
statsSignal: e,
|
|
677
677
|
dataChannelSignal: t,
|
|
678
678
|
onVideoStateChange: a,
|
|
679
679
|
onAgentActivityStateChange: r,
|
|
680
680
|
report: o
|
|
681
681
|
}) {
|
|
682
|
-
e ===
|
|
682
|
+
e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, o)), t === p.Start ? r == null || r(X.Talking) : t === p.Stop && (r == null || r(X.Idle));
|
|
683
683
|
}
|
|
684
|
-
function
|
|
684
|
+
function me({
|
|
685
685
|
statsSignal: e,
|
|
686
686
|
dataChannelSignal: t,
|
|
687
687
|
onVideoStateChange: a,
|
|
@@ -689,7 +689,7 @@ function ge({
|
|
|
689
689
|
streamType: o,
|
|
690
690
|
report: i
|
|
691
691
|
}) {
|
|
692
|
-
o === J.Legacy ?
|
|
692
|
+
o === J.Legacy ? Dt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: a, report: i }) : o === J.Fluent && Ct({
|
|
693
693
|
statsSignal: e,
|
|
694
694
|
dataChannelSignal: t,
|
|
695
695
|
onVideoStateChange: a,
|
|
@@ -700,43 +700,43 @@ function ge({
|
|
|
700
700
|
async function Rt(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te, analytics: c }) {
|
|
701
701
|
var H;
|
|
702
702
|
const n = dt(a, "WebRTCStreamingManager"), s = kt(n);
|
|
703
|
-
let d = !1, l = !1, u =
|
|
704
|
-
const { startConnection:
|
|
703
|
+
let d = !1, l = !1, u = p.Stop, y = p.Stop;
|
|
704
|
+
const { startConnection: P, sendStreamRequest: A, close: N, createStream: b, addIceCandidate: x } = ct(
|
|
705
705
|
o,
|
|
706
706
|
i,
|
|
707
707
|
e,
|
|
708
708
|
r.onError
|
|
709
709
|
), {
|
|
710
|
-
id:
|
|
710
|
+
id: R,
|
|
711
711
|
offer: K,
|
|
712
712
|
ice_servers: G,
|
|
713
|
-
session_id:
|
|
713
|
+
session_id: $,
|
|
714
714
|
fluent: Y,
|
|
715
715
|
interrupt_enabled: f,
|
|
716
716
|
triggers_enabled: D
|
|
717
|
-
} = await
|
|
718
|
-
(H = r.onStreamCreated) == null || H.call(r, { stream_id:
|
|
717
|
+
} = await b(t);
|
|
718
|
+
(H = r.onStreamCreated) == null || H.call(r, { stream_id: R, session_id: $, agent_id: e });
|
|
719
719
|
const g = new yt({ iceServers: G }), S = g.createDataChannel("JanusDataChannel");
|
|
720
|
-
if (
|
|
720
|
+
if (!$)
|
|
721
721
|
throw new Error("Could not create session_id");
|
|
722
|
-
const
|
|
722
|
+
const w = Y ? J.Fluent : J.Legacy;
|
|
723
723
|
c.enrich({
|
|
724
|
-
"stream-type":
|
|
724
|
+
"stream-type": w
|
|
725
725
|
});
|
|
726
|
-
const k = t.stream_warmup && !Y,
|
|
726
|
+
const k = t.stream_warmup && !Y, j = () => d, B = () => {
|
|
727
727
|
var m;
|
|
728
|
-
d = !0, l && ((m = r.onConnectionStateChange) == null || m.call(r,
|
|
729
|
-
},
|
|
728
|
+
d = !0, l && ((m = r.onConnectionStateChange) == null || m.call(r, _.Connected));
|
|
729
|
+
}, z = vt(
|
|
730
730
|
g,
|
|
731
|
-
|
|
731
|
+
j,
|
|
732
732
|
B,
|
|
733
|
-
(m, h) =>
|
|
733
|
+
(m, h) => me({
|
|
734
734
|
statsSignal: y = m,
|
|
735
|
-
dataChannelSignal:
|
|
735
|
+
dataChannelSignal: w === J.Legacy ? u : void 0,
|
|
736
736
|
onVideoStateChange: r.onVideoStateChange,
|
|
737
737
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
738
738
|
report: h,
|
|
739
|
-
streamType:
|
|
739
|
+
streamType: w
|
|
740
740
|
}),
|
|
741
741
|
(m) => {
|
|
742
742
|
var h;
|
|
@@ -747,123 +747,123 @@ async function Rt(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te,
|
|
|
747
747
|
var h;
|
|
748
748
|
n("peerConnection.onicecandidate", m);
|
|
749
749
|
try {
|
|
750
|
-
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ?
|
|
751
|
-
|
|
750
|
+
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? x(
|
|
751
|
+
R,
|
|
752
752
|
{
|
|
753
753
|
candidate: m.candidate.candidate,
|
|
754
754
|
sdpMid: m.candidate.sdpMid,
|
|
755
755
|
sdpMLineIndex: m.candidate.sdpMLineIndex
|
|
756
756
|
},
|
|
757
|
-
|
|
758
|
-
) :
|
|
759
|
-
} catch (
|
|
760
|
-
(h = r.onError) == null || h.call(r,
|
|
757
|
+
$
|
|
758
|
+
) : x(R, { candidate: null }, $);
|
|
759
|
+
} catch (M) {
|
|
760
|
+
(h = r.onError) == null || h.call(r, M, { streamId: R });
|
|
761
761
|
}
|
|
762
762
|
}, S.onopen = () => {
|
|
763
763
|
l = !0, (!k || d) && B();
|
|
764
764
|
};
|
|
765
|
-
const
|
|
765
|
+
const C = (m) => {
|
|
766
766
|
var h;
|
|
767
767
|
(h = r.onVideoIdChange) == null || h.call(r, m);
|
|
768
768
|
};
|
|
769
|
-
function
|
|
770
|
-
if (m ===
|
|
771
|
-
const
|
|
772
|
-
|
|
769
|
+
function T(m, h) {
|
|
770
|
+
if (m === L.StreamStarted && typeof h == "object" && "metadata" in h) {
|
|
771
|
+
const M = h.metadata;
|
|
772
|
+
C(M.videoId);
|
|
773
773
|
}
|
|
774
|
-
m ===
|
|
775
|
-
statsSignal:
|
|
774
|
+
m === L.StreamDone && C(null), u = m === L.StreamStarted ? p.Start : p.Stop, me({
|
|
775
|
+
statsSignal: w === J.Legacy ? y : void 0,
|
|
776
776
|
dataChannelSignal: u,
|
|
777
777
|
onVideoStateChange: r.onVideoStateChange,
|
|
778
778
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
779
|
-
streamType:
|
|
779
|
+
streamType: w
|
|
780
780
|
});
|
|
781
781
|
}
|
|
782
782
|
function W(m, h) {
|
|
783
|
-
const
|
|
784
|
-
|
|
783
|
+
const M = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
|
|
784
|
+
M && c.enrich({ streamMetadata: M }), c.track("agent-chat", { event: "ready" });
|
|
785
785
|
}
|
|
786
786
|
const v = {
|
|
787
|
-
[
|
|
788
|
-
[
|
|
789
|
-
[
|
|
787
|
+
[L.StreamStarted]: T,
|
|
788
|
+
[L.StreamDone]: T,
|
|
789
|
+
[L.StreamReady]: W
|
|
790
790
|
};
|
|
791
791
|
S.onmessage = (m) => {
|
|
792
792
|
var U;
|
|
793
|
-
const { subject: h, data:
|
|
794
|
-
(U = v[h]) == null || U.call(v, h,
|
|
793
|
+
const { subject: h, data: M } = s(m.data);
|
|
794
|
+
(U = v[h]) == null || U.call(v, h, M);
|
|
795
795
|
}, g.oniceconnectionstatechange = () => {
|
|
796
796
|
var h;
|
|
797
797
|
n("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
798
|
-
const m =
|
|
799
|
-
m !==
|
|
798
|
+
const m = fe(g.iceConnectionState);
|
|
799
|
+
m !== _.Connected && ((h = r.onConnectionStateChange) == null || h.call(r, m));
|
|
800
800
|
}, g.ontrack = (m) => {
|
|
801
801
|
var h;
|
|
802
802
|
n("peerConnection.ontrack", m), (h = r.onSrcObjectReady) == null || h.call(r, m.streams[0]);
|
|
803
803
|
}, await g.setRemoteDescription(K), n("set remote description OK");
|
|
804
|
-
const
|
|
805
|
-
return n("create answer OK"), await g.setLocalDescription(
|
|
804
|
+
const E = await g.createAnswer();
|
|
805
|
+
return n("create answer OK"), await g.setLocalDescription(E), n("set local description OK"), await P(R, E, $), n("start connection OK"), {
|
|
806
806
|
/**
|
|
807
807
|
* Method to send request to server to get clip or talk depend on you payload
|
|
808
808
|
* @param payload
|
|
809
809
|
*/
|
|
810
810
|
speak(m) {
|
|
811
|
-
return
|
|
811
|
+
return A(R, $, m);
|
|
812
812
|
},
|
|
813
813
|
/**
|
|
814
814
|
* Method to close RTC connection
|
|
815
815
|
*/
|
|
816
816
|
async disconnect() {
|
|
817
817
|
var m;
|
|
818
|
-
if (
|
|
819
|
-
const h =
|
|
818
|
+
if (R) {
|
|
819
|
+
const h = fe(g.iceConnectionState);
|
|
820
820
|
if (g) {
|
|
821
|
-
if (h ===
|
|
822
|
-
clearInterval(
|
|
821
|
+
if (h === _.New) {
|
|
822
|
+
clearInterval(z);
|
|
823
823
|
return;
|
|
824
824
|
}
|
|
825
825
|
g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
|
|
826
826
|
}
|
|
827
827
|
try {
|
|
828
|
-
h ===
|
|
828
|
+
h === _.Connected && await N(R, $).catch((M) => {
|
|
829
829
|
});
|
|
830
|
-
} catch (
|
|
831
|
-
n("Error on close stream connection",
|
|
830
|
+
} catch (M) {
|
|
831
|
+
n("Error on close stream connection", M);
|
|
832
832
|
}
|
|
833
|
-
(m = r.onAgentActivityStateChange) == null || m.call(r, X.Idle), clearInterval(
|
|
833
|
+
(m = r.onAgentActivityStateChange) == null || m.call(r, X.Idle), clearInterval(z);
|
|
834
834
|
}
|
|
835
835
|
},
|
|
836
836
|
/**
|
|
837
837
|
* Method to send data channel messages to the server
|
|
838
838
|
*/
|
|
839
839
|
sendDataChannelMessage(m) {
|
|
840
|
-
var h,
|
|
840
|
+
var h, M;
|
|
841
841
|
if (!d || S.readyState !== "open") {
|
|
842
842
|
n("Data channel is not ready for sending messages"), (h = r.onError) == null || h.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
843
|
-
streamId:
|
|
843
|
+
streamId: R
|
|
844
844
|
});
|
|
845
845
|
return;
|
|
846
846
|
}
|
|
847
847
|
try {
|
|
848
848
|
S.send(m);
|
|
849
849
|
} catch (U) {
|
|
850
|
-
n("Error sending data channel message", U), (
|
|
850
|
+
n("Error sending data channel message", U), (M = r.onError) == null || M.call(r, U, { streamId: R });
|
|
851
851
|
}
|
|
852
852
|
},
|
|
853
853
|
/**
|
|
854
854
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
855
855
|
*/
|
|
856
|
-
sessionId:
|
|
856
|
+
sessionId: $,
|
|
857
857
|
/**
|
|
858
858
|
* Id of current RTC stream
|
|
859
859
|
*/
|
|
860
|
-
streamId:
|
|
861
|
-
streamType:
|
|
860
|
+
streamId: R,
|
|
861
|
+
streamType: w,
|
|
862
862
|
interruptAvailable: f ?? !1,
|
|
863
863
|
triggersAvailable: D ?? !1
|
|
864
864
|
};
|
|
865
865
|
}
|
|
866
|
-
var
|
|
866
|
+
var oe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(oe || {});
|
|
867
867
|
async function St(e, t, a) {
|
|
868
868
|
const r = e.id;
|
|
869
869
|
switch (t.version) {
|
|
@@ -874,8 +874,8 @@ async function St(e, t, a) {
|
|
|
874
874
|
case "v2": {
|
|
875
875
|
const { version: o, ...i } = t;
|
|
876
876
|
switch (i.transport_provider) {
|
|
877
|
-
case
|
|
878
|
-
const { createLiveKitStreamingManager: c } = await import("./livekit-manager-
|
|
877
|
+
case ce.Livekit:
|
|
878
|
+
const { createLiveKitStreamingManager: c } = await import("./livekit-manager-D9xuX-OS.js");
|
|
879
879
|
return c(r, i, a);
|
|
880
880
|
default:
|
|
881
881
|
throw new Error(`Unsupported transport provider: ${i.transport_provider}`);
|
|
@@ -885,13 +885,13 @@ async function St(e, t, a) {
|
|
|
885
885
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
886
886
|
}
|
|
887
887
|
}
|
|
888
|
-
|
|
888
|
+
const It = "cht";
|
|
889
|
+
function Et() {
|
|
889
890
|
return {
|
|
890
|
-
transport_provider:
|
|
891
|
-
chat_id: e == null ? void 0 : e.chatId
|
|
891
|
+
transport_provider: ce.Livekit
|
|
892
892
|
};
|
|
893
893
|
}
|
|
894
|
-
function
|
|
894
|
+
function Mt(e) {
|
|
895
895
|
var o, i;
|
|
896
896
|
const { streamOptions: t } = e ?? {}, a = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
|
|
897
897
|
plan: (i = e.mixpanelAdditionalProperties) == null ? void 0 : i.plan
|
|
@@ -904,14 +904,14 @@ function Et(e) {
|
|
|
904
904
|
fluent: t == null ? void 0 : t.fluent
|
|
905
905
|
}, ...a && { end_user_data: a } };
|
|
906
906
|
}
|
|
907
|
-
function
|
|
908
|
-
return
|
|
909
|
-
}
|
|
910
|
-
function _t(e, t, a, r, o) {
|
|
911
|
-
o === J.Fluent ? Tt(e, t, a, r, o) : Pt(e, t, a, r, o);
|
|
907
|
+
function _t(e, t) {
|
|
908
|
+
return de(e.presenter.type) ? { version: oe.V2, ...Et() } : { version: oe.V1, ...Mt(t) };
|
|
912
909
|
}
|
|
913
910
|
function Tt(e, t, a, r, o) {
|
|
914
|
-
|
|
911
|
+
o === J.Fluent ? At(e, t, a, r, o) : bt(e, t, a, r, o);
|
|
912
|
+
}
|
|
913
|
+
function At(e, t, a, r, o) {
|
|
914
|
+
e === p.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === p.Stop && r.track("stream-session", {
|
|
915
915
|
event: "stop",
|
|
916
916
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
917
917
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -919,13 +919,13 @@ function Tt(e, t, a, r, o) {
|
|
|
919
919
|
...a
|
|
920
920
|
});
|
|
921
921
|
}
|
|
922
|
-
function
|
|
923
|
-
|
|
922
|
+
function Pt(e, t, a, r) {
|
|
923
|
+
F.get() <= 0 || (e === p.Start ? a.linkTrack(
|
|
924
924
|
"agent-video",
|
|
925
|
-
{ event: "start", latency:
|
|
925
|
+
{ event: "start", latency: F.get(!0), "stream-type": r },
|
|
926
926
|
"start",
|
|
927
|
-
[
|
|
928
|
-
) : e ===
|
|
927
|
+
[L.StreamVideoCreated]
|
|
928
|
+
) : e === p.Stop && a.linkTrack(
|
|
929
929
|
"agent-video",
|
|
930
930
|
{
|
|
931
931
|
event: "stop",
|
|
@@ -934,16 +934,16 @@ function At(e, t, a, r) {
|
|
|
934
934
|
"stream-type": r
|
|
935
935
|
},
|
|
936
936
|
"done",
|
|
937
|
-
[
|
|
937
|
+
[L.StreamVideoDone]
|
|
938
938
|
));
|
|
939
939
|
}
|
|
940
|
-
function
|
|
941
|
-
|
|
940
|
+
function bt(e, t, a, r, o) {
|
|
941
|
+
F.get() <= 0 || (e === p.Start ? r.linkTrack(
|
|
942
942
|
"agent-video",
|
|
943
|
-
{ event: "start", latency:
|
|
943
|
+
{ event: "start", latency: F.get(!0), "stream-type": o },
|
|
944
944
|
"start",
|
|
945
|
-
[
|
|
946
|
-
) : e ===
|
|
945
|
+
[L.StreamVideoCreated]
|
|
946
|
+
) : e === p.Stop && r.linkTrack(
|
|
947
947
|
"agent-video",
|
|
948
948
|
{
|
|
949
949
|
event: "stop",
|
|
@@ -953,25 +953,25 @@ function Pt(e, t, a, r, o) {
|
|
|
953
953
|
...a
|
|
954
954
|
},
|
|
955
955
|
"done",
|
|
956
|
-
[
|
|
956
|
+
[L.StreamVideoDone]
|
|
957
957
|
));
|
|
958
958
|
}
|
|
959
|
-
function
|
|
960
|
-
return
|
|
959
|
+
function ge(e, t, a) {
|
|
960
|
+
return F.reset(), new Promise(async (r, o) => {
|
|
961
961
|
try {
|
|
962
962
|
let i, c = !1;
|
|
963
|
-
i = await St(e,
|
|
963
|
+
i = await St(e, _t(e, t), {
|
|
964
964
|
...t,
|
|
965
965
|
analytics: a,
|
|
966
966
|
callbacks: {
|
|
967
967
|
...t.callbacks,
|
|
968
968
|
onConnectionStateChange: (n) => {
|
|
969
969
|
var s, d;
|
|
970
|
-
(d = (s = t.callbacks).onConnectionStateChange) == null || d.call(s, n), n ===
|
|
970
|
+
(d = (s = t.callbacks).onConnectionStateChange) == null || d.call(s, n), n === _.Connected && (i ? r(i) : c = !0);
|
|
971
971
|
},
|
|
972
972
|
onVideoStateChange: (n, s) => {
|
|
973
973
|
var d, l;
|
|
974
|
-
(l = (d = t.callbacks).onVideoStateChange) == null || l.call(d, n),
|
|
974
|
+
(l = (d = t.callbacks).onVideoStateChange) == null || l.call(d, n), Tt(
|
|
975
975
|
n,
|
|
976
976
|
e,
|
|
977
977
|
s,
|
|
@@ -981,8 +981,8 @@ function he(e, t, a) {
|
|
|
981
981
|
},
|
|
982
982
|
onAgentActivityStateChange: (n) => {
|
|
983
983
|
var s, d;
|
|
984
|
-
(d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n === X.Talking ? ie.update() : ie.reset(),
|
|
985
|
-
n === X.Talking ?
|
|
984
|
+
(d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n === X.Talking ? ie.update() : ie.reset(), Pt(
|
|
985
|
+
n === X.Talking ? p.Start : p.Stop,
|
|
986
986
|
e,
|
|
987
987
|
a,
|
|
988
988
|
i.streamType
|
|
@@ -995,44 +995,45 @@ function he(e, t, a) {
|
|
|
995
995
|
}
|
|
996
996
|
});
|
|
997
997
|
}
|
|
998
|
-
async function
|
|
999
|
-
var l, u, y,
|
|
998
|
+
async function jt(e, t, a, r, o) {
|
|
999
|
+
var l, u, y, P;
|
|
1000
1000
|
const i = async () => {
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1001
|
+
if (de(e.presenter.type)) {
|
|
1002
|
+
const A = await ge(e, t, r), N = `${It}_${A.sessionId}`, b = (/* @__PURE__ */ new Date()).toISOString();
|
|
1003
|
+
return { chatResult: {
|
|
1004
|
+
chatMode: I.Functional,
|
|
1005
|
+
chat: {
|
|
1006
|
+
id: N,
|
|
1007
|
+
agent_id: e.id,
|
|
1008
|
+
owner_id: e.owner_id ?? "",
|
|
1009
|
+
created: b,
|
|
1010
|
+
modified: b,
|
|
1011
|
+
agent_id__created_at: b,
|
|
1012
|
+
agent_id__modified_at: b,
|
|
1013
|
+
chat_mode: I.Functional,
|
|
1014
|
+
messages: []
|
|
1015
|
+
}
|
|
1016
|
+
}, streamingManager: A };
|
|
1016
1017
|
} else {
|
|
1017
|
-
const
|
|
1018
|
+
const A = Re(
|
|
1018
1019
|
e,
|
|
1019
1020
|
a,
|
|
1020
1021
|
r,
|
|
1021
1022
|
t.mode,
|
|
1022
1023
|
t.persistentChat,
|
|
1023
1024
|
o
|
|
1024
|
-
),
|
|
1025
|
-
return { chatResult:
|
|
1025
|
+
), N = ge(e, t, r), [b, x] = await Promise.all([A, N]);
|
|
1026
|
+
return { chatResult: b, streamingManager: x };
|
|
1026
1027
|
}
|
|
1027
1028
|
}, { chatResult: c, streamingManager: n } = await i(), { chat: s, chatMode: d } = c;
|
|
1028
|
-
return d && d !== t.mode && (t.mode = d, (u = (l = t.callbacks).onModeChange) == null || u.call(l, d), d !==
|
|
1029
|
+
return d && d !== t.mode && (t.mode = d, (u = (l = t.callbacks).onModeChange) == null || u.call(l, d), d !== I.Functional) ? ((P = (y = t.callbacks).onError) == null || P.call(y, new Me(d)), n == null || n.disconnect(), { chat: s }) : { chat: s, streamingManager: n };
|
|
1029
1030
|
}
|
|
1030
|
-
async function
|
|
1031
|
-
var G,
|
|
1031
|
+
async function $t(e, t) {
|
|
1032
|
+
var G, $, Y;
|
|
1032
1033
|
let a = !0, r = null;
|
|
1033
1034
|
const o = t.mixpanelKey || Je, i = t.wsURL || Ne, c = t.baseURL || te, n = {
|
|
1034
1035
|
messages: [],
|
|
1035
|
-
chatMode: t.mode ||
|
|
1036
|
+
chatMode: t.mode || I.Functional
|
|
1036
1037
|
}, s = Ze({
|
|
1037
1038
|
token: o,
|
|
1038
1039
|
agentId: e,
|
|
@@ -1040,12 +1041,12 @@ async function xt(e, t) {
|
|
|
1040
1041
|
externalId: t.externalId,
|
|
1041
1042
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1042
1043
|
}), d = Date.now();
|
|
1043
|
-
|
|
1044
|
+
ue(() => {
|
|
1044
1045
|
s.track("agent-sdk", { event: "init" }, d);
|
|
1045
1046
|
});
|
|
1046
|
-
const l = Ve(t.auth, c, t.callbacks.onError, t.externalId), u = await l.getById(e), y =
|
|
1047
|
+
const l = Ve(t.auth, c, t.callbacks.onError, t.externalId), u = await l.getById(e), y = de(u.presenter.type);
|
|
1047
1048
|
s.enrich(Oe(u));
|
|
1048
|
-
const { onMessage:
|
|
1049
|
+
const { onMessage: P, clearQueue: A } = ot(
|
|
1049
1050
|
s,
|
|
1050
1051
|
n,
|
|
1051
1052
|
t,
|
|
@@ -1055,27 +1056,27 @@ async function xt(e, t) {
|
|
|
1055
1056
|
return (f = n.socketManager) == null ? void 0 : f.disconnect();
|
|
1056
1057
|
}
|
|
1057
1058
|
);
|
|
1058
|
-
n.messages = Ge(t.initialMessages), (
|
|
1059
|
-
const
|
|
1059
|
+
n.messages = Ge(t.initialMessages), ($ = (G = t.callbacks).onNewMessage) == null || $.call(G, [...n.messages], "answer");
|
|
1060
|
+
const N = (f) => {
|
|
1060
1061
|
r = f;
|
|
1061
|
-
},
|
|
1062
|
-
|
|
1063
|
-
s.track("agent-sdk", { event: "loaded", ...qe(u) },
|
|
1062
|
+
}, b = Date.now();
|
|
1063
|
+
ue(() => {
|
|
1064
|
+
s.track("agent-sdk", { event: "loaded", ...qe(u) }, b);
|
|
1064
1065
|
});
|
|
1065
|
-
async function
|
|
1066
|
-
var
|
|
1067
|
-
(B = (
|
|
1068
|
-
const D = t.mode ===
|
|
1066
|
+
async function x(f) {
|
|
1067
|
+
var j, B, z, C, T, W, v;
|
|
1068
|
+
(B = (j = t.callbacks).onConnectionStateChange) == null || B.call(j, _.Connecting), F.reset(), f && !a && (delete n.chat, (C = (z = t.callbacks).onNewMessage) == null || C.call(z, [...n.messages], "answer"));
|
|
1069
|
+
const D = t.mode === I.DirectPlayback || y ? Promise.resolve(void 0) : at(
|
|
1069
1070
|
t.auth,
|
|
1070
1071
|
i,
|
|
1071
|
-
{ onMessage:
|
|
1072
|
+
{ onMessage: P, onError: t.callbacks.onError },
|
|
1072
1073
|
t.externalId
|
|
1073
1074
|
), g = ne(
|
|
1074
|
-
() =>
|
|
1075
|
+
() => jt(
|
|
1075
1076
|
u,
|
|
1076
1077
|
{
|
|
1077
1078
|
...t,
|
|
1078
|
-
callbacks: { ...t.callbacks, onVideoIdChange:
|
|
1079
|
+
callbacks: { ...t.callbacks, onVideoIdChange: N, onMessage: P }
|
|
1079
1080
|
},
|
|
1080
1081
|
l,
|
|
1081
1082
|
s,
|
|
@@ -1086,26 +1087,26 @@ async function xt(e, t) {
|
|
|
1086
1087
|
timeout: ze,
|
|
1087
1088
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1088
1089
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1089
|
-
shouldRetryFn: (
|
|
1090
|
+
shouldRetryFn: (E) => (E == null ? void 0 : E.message) !== "Could not connect" && E.status !== 429,
|
|
1090
1091
|
delayMs: 1e3
|
|
1091
1092
|
}
|
|
1092
|
-
).catch((
|
|
1093
|
+
).catch((E) => {
|
|
1093
1094
|
var H, m;
|
|
1094
|
-
throw K(
|
|
1095
|
-
}), [S, { streamingManager:
|
|
1096
|
-
k && k.id !== ((
|
|
1095
|
+
throw K(I.Maintenance), (m = (H = t.callbacks).onConnectionStateChange) == null || m.call(H, _.Fail), E;
|
|
1096
|
+
}), [S, { streamingManager: w, chat: k }] = await Promise.all([D, g]);
|
|
1097
|
+
k && k.id !== ((T = n.chat) == null ? void 0 : T.id) && ((v = (W = t.callbacks).onNewChat) == null || v.call(W, k.id)), n.streamingManager = w, n.socketManager = S, n.chat = k, a = !1, s.enrich({
|
|
1097
1098
|
chatId: k == null ? void 0 : k.id,
|
|
1098
|
-
streamId:
|
|
1099
|
+
streamId: w == null ? void 0 : w.streamId,
|
|
1099
1100
|
mode: n.chatMode
|
|
1100
|
-
}), K((k == null ? void 0 : k.chat_mode) ?? t.mode ??
|
|
1101
|
+
}), K((k == null ? void 0 : k.chat_mode) ?? t.mode ?? I.Functional);
|
|
1101
1102
|
}
|
|
1102
|
-
async function
|
|
1103
|
+
async function R() {
|
|
1103
1104
|
var f, D, g, S;
|
|
1104
|
-
(f = n.socketManager) == null || f.disconnect(), await ((D = n.streamingManager) == null ? void 0 : D.disconnect()), delete n.streamingManager, delete n.socketManager, (S = (g = t.callbacks).onConnectionStateChange) == null || S.call(g,
|
|
1105
|
+
(f = n.socketManager) == null || f.disconnect(), await ((D = n.streamingManager) == null ? void 0 : D.disconnect()), delete n.streamingManager, delete n.socketManager, (S = (g = t.callbacks).onConnectionStateChange) == null || S.call(g, _.Disconnected);
|
|
1105
1106
|
}
|
|
1106
1107
|
async function K(f) {
|
|
1107
1108
|
var D, g;
|
|
1108
|
-
f !== n.chatMode && (s.track("agent-mode-change", { mode: f }), n.chatMode = f, n.chatMode !==
|
|
1109
|
+
f !== n.chatMode && (s.track("agent-mode-change", { mode: f }), n.chatMode = f, n.chatMode !== I.Functional && await R(), (g = (D = t.callbacks).onModeChange) == null || g.call(D, f));
|
|
1109
1110
|
}
|
|
1110
1111
|
return {
|
|
1111
1112
|
agent: u,
|
|
@@ -1126,44 +1127,44 @@ async function xt(e, t) {
|
|
|
1126
1127
|
changeMode: K,
|
|
1127
1128
|
enrichAnalytics: s.enrich,
|
|
1128
1129
|
async connect() {
|
|
1129
|
-
await
|
|
1130
|
+
await x(!0), s.track("agent-chat", {
|
|
1130
1131
|
event: "connect",
|
|
1131
1132
|
mode: n.chatMode
|
|
1132
1133
|
});
|
|
1133
1134
|
},
|
|
1134
1135
|
async reconnect() {
|
|
1135
|
-
await
|
|
1136
|
+
await R(), await x(!1), s.track("agent-chat", {
|
|
1136
1137
|
event: "reconnect",
|
|
1137
1138
|
mode: n.chatMode
|
|
1138
1139
|
});
|
|
1139
1140
|
},
|
|
1140
1141
|
async disconnect() {
|
|
1141
|
-
await
|
|
1142
|
+
await R(), s.track("agent-chat", {
|
|
1142
1143
|
event: "disconnect",
|
|
1143
1144
|
mode: n.chatMode
|
|
1144
1145
|
});
|
|
1145
1146
|
},
|
|
1146
1147
|
async chat(f) {
|
|
1147
|
-
var
|
|
1148
|
+
var w, k, j, B, z;
|
|
1148
1149
|
const D = () => {
|
|
1149
|
-
if (
|
|
1150
|
+
if (ve(t.mode))
|
|
1150
1151
|
throw new V(`${t.mode} is enabled, chat is disabled`);
|
|
1151
1152
|
if (f.length >= 800)
|
|
1152
1153
|
throw new V("Message cannot be more than 800 characters");
|
|
1153
1154
|
if (f.length === 0)
|
|
1154
1155
|
throw new V("Message cannot be empty");
|
|
1155
|
-
if (n.chatMode ===
|
|
1156
|
+
if (n.chatMode === I.Maintenance)
|
|
1156
1157
|
throw new V("Chat is in maintenance mode");
|
|
1157
|
-
if (![
|
|
1158
|
+
if (![I.TextOnly, I.Playground].includes(n.chatMode)) {
|
|
1158
1159
|
if (!n.streamingManager)
|
|
1159
1160
|
throw new V("Streaming manager is not initialized");
|
|
1160
1161
|
if (!n.chat)
|
|
1161
1162
|
throw new V("Chat is not initialized");
|
|
1162
1163
|
}
|
|
1163
1164
|
}, g = async () => {
|
|
1164
|
-
var
|
|
1165
|
+
var C, T;
|
|
1165
1166
|
if (!n.chat) {
|
|
1166
|
-
const W = await
|
|
1167
|
+
const W = await Re(
|
|
1167
1168
|
u,
|
|
1168
1169
|
l,
|
|
1169
1170
|
s,
|
|
@@ -1172,91 +1173,91 @@ async function xt(e, t) {
|
|
|
1172
1173
|
);
|
|
1173
1174
|
if (!W.chat)
|
|
1174
1175
|
throw new Ee(n.chatMode, !!t.persistentChat);
|
|
1175
|
-
n.chat = W.chat, (
|
|
1176
|
+
n.chat = W.chat, (T = (C = t.callbacks).onNewChat) == null || T.call(C, n.chat.id);
|
|
1176
1177
|
}
|
|
1177
1178
|
return n.chat.id;
|
|
1178
|
-
}, S = async (
|
|
1179
|
-
var v,
|
|
1180
|
-
return await ((
|
|
1179
|
+
}, S = async (C, T) => ne(y ? async () => {
|
|
1180
|
+
var v, E;
|
|
1181
|
+
return await ((E = (v = n.streamingManager) == null ? void 0 : v.sendTextMessage) == null ? void 0 : E.call(v, f)), Promise.resolve({});
|
|
1181
1182
|
} : async () => {
|
|
1182
|
-
var v,
|
|
1183
|
+
var v, E;
|
|
1183
1184
|
return l.chat(
|
|
1184
1185
|
u.id,
|
|
1185
|
-
|
|
1186
|
+
T,
|
|
1186
1187
|
{
|
|
1187
1188
|
chatMode: n.chatMode,
|
|
1188
1189
|
streamId: (v = n.streamingManager) == null ? void 0 : v.streamId,
|
|
1189
|
-
sessionId: (
|
|
1190
|
-
messages:
|
|
1190
|
+
sessionId: (E = n.streamingManager) == null ? void 0 : E.sessionId,
|
|
1191
|
+
messages: C.map(({ matches: H, ...m }) => m)
|
|
1191
1192
|
},
|
|
1192
1193
|
{
|
|
1193
|
-
...
|
|
1194
|
+
...Ce(n.chatMode),
|
|
1194
1195
|
skipErrorHandler: !0
|
|
1195
1196
|
}
|
|
1196
1197
|
);
|
|
1197
1198
|
}, {
|
|
1198
1199
|
limit: 2,
|
|
1199
1200
|
shouldRetryFn: (v) => {
|
|
1200
|
-
var m, h,
|
|
1201
|
-
const
|
|
1202
|
-
return !((h = v == null ? void 0 : v.message) == null ? void 0 : h.includes("Stream Error")) && !
|
|
1201
|
+
var m, h, M, U;
|
|
1202
|
+
const E = (m = v == null ? void 0 : v.message) == null ? void 0 : m.includes("missing or invalid session_id");
|
|
1203
|
+
return !((h = v == null ? void 0 : v.message) == null ? void 0 : h.includes("Stream Error")) && !E ? ((U = (M = t.callbacks).onError) == null || U.call(M, v), !1) : !0;
|
|
1203
1204
|
},
|
|
1204
1205
|
onRetry: async () => {
|
|
1205
|
-
await
|
|
1206
|
+
await R(), await x(!1);
|
|
1206
1207
|
}
|
|
1207
1208
|
});
|
|
1208
1209
|
try {
|
|
1209
|
-
|
|
1210
|
+
A(), D(), n.messages.push({
|
|
1210
1211
|
id: O(),
|
|
1211
1212
|
role: "user",
|
|
1212
1213
|
content: f,
|
|
1213
|
-
created_at: new Date(
|
|
1214
|
-
}), (k = (
|
|
1215
|
-
const
|
|
1214
|
+
created_at: new Date(F.update()).toISOString()
|
|
1215
|
+
}), (k = (w = t.callbacks).onNewMessage) == null || k.call(w, [...n.messages], "user");
|
|
1216
|
+
const C = await g(), T = await S([...n.messages], C);
|
|
1216
1217
|
return n.messages.push({
|
|
1217
1218
|
id: O(),
|
|
1218
1219
|
role: "assistant",
|
|
1219
|
-
content:
|
|
1220
|
+
content: T.result || "",
|
|
1220
1221
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1221
|
-
context:
|
|
1222
|
-
matches:
|
|
1222
|
+
context: T.context,
|
|
1223
|
+
matches: T.matches
|
|
1223
1224
|
}), s.track("agent-message-send", {
|
|
1224
1225
|
event: "success",
|
|
1225
1226
|
messages: n.messages.length + 1
|
|
1226
|
-
}),
|
|
1227
|
-
latency:
|
|
1227
|
+
}), T.result && ((B = (j = t.callbacks).onNewMessage) == null || B.call(j, [...n.messages], "answer"), s.track("agent-message-received", {
|
|
1228
|
+
latency: F.get(!0),
|
|
1228
1229
|
messages: n.messages.length
|
|
1229
|
-
})),
|
|
1230
|
-
} catch (
|
|
1231
|
-
throw ((
|
|
1230
|
+
})), T;
|
|
1231
|
+
} catch (C) {
|
|
1232
|
+
throw ((z = n.messages[n.messages.length - 1]) == null ? void 0 : z.role) === "assistant" && n.messages.pop(), s.track("agent-message-send", {
|
|
1232
1233
|
event: "error",
|
|
1233
1234
|
messages: n.messages.length
|
|
1234
|
-
}),
|
|
1235
|
+
}), C;
|
|
1235
1236
|
}
|
|
1236
1237
|
},
|
|
1237
1238
|
rate(f, D, g) {
|
|
1238
|
-
var k,
|
|
1239
|
-
const S = n.messages.find((
|
|
1239
|
+
var k, j, B, z;
|
|
1240
|
+
const S = n.messages.find((C) => C.id === f);
|
|
1240
1241
|
if (n.chat) {
|
|
1241
1242
|
if (!S)
|
|
1242
1243
|
throw new Error("Message not found");
|
|
1243
1244
|
} else throw new Error("Chat is not initialized");
|
|
1244
|
-
const
|
|
1245
|
+
const w = ((k = S.matches) == null ? void 0 : k.map((C) => [C.document_id, C.id])) ?? [];
|
|
1245
1246
|
return s.track("agent-rate", {
|
|
1246
1247
|
event: g ? "update" : "create",
|
|
1247
1248
|
thumb: D === 1 ? "up" : "down",
|
|
1248
|
-
knowledge_id: ((
|
|
1249
|
-
matches:
|
|
1249
|
+
knowledge_id: ((j = u.knowledge) == null ? void 0 : j.id) ?? "",
|
|
1250
|
+
matches: w,
|
|
1250
1251
|
score: D
|
|
1251
1252
|
}), g ? l.updateRating(u.id, n.chat.id, g, {
|
|
1252
1253
|
knowledge_id: ((B = u.knowledge) == null ? void 0 : B.id) ?? "",
|
|
1253
1254
|
message_id: f,
|
|
1254
|
-
matches:
|
|
1255
|
+
matches: w,
|
|
1255
1256
|
score: D
|
|
1256
1257
|
}) : l.createRating(u.id, n.chat.id, {
|
|
1257
|
-
knowledge_id: ((
|
|
1258
|
+
knowledge_id: ((z = u.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1258
1259
|
message_id: f,
|
|
1259
|
-
matches:
|
|
1260
|
+
matches: w,
|
|
1260
1261
|
score: D
|
|
1261
1262
|
});
|
|
1262
1263
|
},
|
|
@@ -1266,7 +1267,7 @@ async function xt(e, t) {
|
|
|
1266
1267
|
return s.track("agent-rate-delete", { type: "text" }), l.deleteRating(u.id, n.chat.id, f);
|
|
1267
1268
|
},
|
|
1268
1269
|
async speak(f) {
|
|
1269
|
-
var
|
|
1270
|
+
var w, k, j;
|
|
1270
1271
|
function D() {
|
|
1271
1272
|
if (typeof f == "string") {
|
|
1272
1273
|
if (!u.presenter.voice)
|
|
@@ -1291,12 +1292,12 @@ async function xt(e, t) {
|
|
|
1291
1292
|
return f;
|
|
1292
1293
|
}
|
|
1293
1294
|
const g = D();
|
|
1294
|
-
if (s.track("agent-speak", g),
|
|
1295
|
+
if (s.track("agent-speak", g), F.update(), n.messages && g.type === "text" && (n.messages.push({
|
|
1295
1296
|
id: O(),
|
|
1296
1297
|
role: "assistant",
|
|
1297
1298
|
content: g.input,
|
|
1298
1299
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1299
|
-
}), (k = (
|
|
1300
|
+
}), (k = (w = t.callbacks).onNewMessage) == null || k.call(w, [...n.messages], "answer")), We(n.chatMode))
|
|
1300
1301
|
return {
|
|
1301
1302
|
duration: 0,
|
|
1302
1303
|
video_id: "",
|
|
@@ -1306,48 +1307,48 @@ async function xt(e, t) {
|
|
|
1306
1307
|
throw new Error("Please connect to the agent first");
|
|
1307
1308
|
return n.streamingManager.speak({
|
|
1308
1309
|
script: g,
|
|
1309
|
-
metadata: { chat_id: (
|
|
1310
|
+
metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: u.id }
|
|
1310
1311
|
});
|
|
1311
1312
|
},
|
|
1312
1313
|
async interrupt({ type: f }) {
|
|
1313
|
-
var g, S,
|
|
1314
|
+
var g, S, w;
|
|
1314
1315
|
et(n.streamingManager, (g = n.streamingManager) == null ? void 0 : g.streamType, r);
|
|
1315
1316
|
const D = n.messages[n.messages.length - 1];
|
|
1316
1317
|
s.track("agent-video-interrupt", {
|
|
1317
1318
|
type: f || "click",
|
|
1318
1319
|
video_duration_to_interrupt: ie.get(!0),
|
|
1319
|
-
message_duration_to_interrupt:
|
|
1320
|
-
}), D.interrupted = !0, (
|
|
1320
|
+
message_duration_to_interrupt: F.get(!0)
|
|
1321
|
+
}), D.interrupted = !0, (w = (S = t.callbacks).onNewMessage) == null || w.call(S, [...n.messages], "answer"), tt(n.streamingManager, r);
|
|
1321
1322
|
}
|
|
1322
1323
|
};
|
|
1323
1324
|
}
|
|
1324
1325
|
export {
|
|
1325
1326
|
X as A,
|
|
1326
|
-
|
|
1327
|
+
_ as C,
|
|
1327
1328
|
xe as D,
|
|
1328
1329
|
Le as K,
|
|
1329
1330
|
Ae as P,
|
|
1330
1331
|
be as R,
|
|
1331
1332
|
J as S,
|
|
1332
|
-
|
|
1333
|
+
ce as T,
|
|
1333
1334
|
Te as U,
|
|
1334
1335
|
V,
|
|
1335
1336
|
_e as W,
|
|
1336
1337
|
dt as a,
|
|
1337
1338
|
Z as b,
|
|
1338
|
-
|
|
1339
|
+
ke as c,
|
|
1339
1340
|
te as d,
|
|
1340
|
-
|
|
1341
|
-
|
|
1341
|
+
p as e,
|
|
1342
|
+
L as f,
|
|
1342
1343
|
q as g,
|
|
1343
1344
|
Ee as h,
|
|
1344
1345
|
Me as i,
|
|
1345
|
-
|
|
1346
|
+
$t as j,
|
|
1346
1347
|
Pe as k,
|
|
1347
|
-
|
|
1348
|
+
I as l,
|
|
1348
1349
|
je as m,
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1350
|
+
he as n,
|
|
1351
|
+
xt as o,
|
|
1352
|
+
$e as p,
|
|
1353
|
+
Be as q
|
|
1353
1354
|
};
|