@d-id/client-sdk 1.2.7 → 1.2.8-staging.366
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-BXPWkNzW.js → index-DutjNwn9.js} +229 -220
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/livekit-manager-C3HASruw.js +471 -0
- package/dist/src/api/agents.d.ts +5 -1
- package/dist/src/types/entities/agents/agent.d.ts +11 -0
- package/dist/src/types/entities/agents/chat.d.ts +6 -0
- package/dist/src/types/entities/agents/manager.d.ts +7 -1
- package/dist/src/types/stream-script.d.ts +5 -0
- package/dist/src/utils/user-context.d.ts +15 -0
- package/dist/src/utils/user-context.test.d.ts +1 -0
- package/package.json +1 -1
- package/dist/livekit-manager-D2P6tClx.js +0 -440
|
@@ -14,7 +14,7 @@ class G extends Error {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function Tn(e) {
|
|
18
18
|
return e instanceof Error && typeof e.kind == "string";
|
|
19
19
|
}
|
|
20
20
|
class ot extends G {
|
|
@@ -79,7 +79,7 @@ class We extends G {
|
|
|
79
79
|
super(t, "StreamError", n);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
class
|
|
82
|
+
class $ extends G {
|
|
83
83
|
constructor(t, n) {
|
|
84
84
|
super(t, "ValidationError"), this.key = n;
|
|
85
85
|
}
|
|
@@ -89,7 +89,7 @@ class ut extends G {
|
|
|
89
89
|
super(t, "WSError");
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
var ft = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ft || {}), mt = /* @__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))(mt || {}), ht = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ht || {}), gt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(gt || {}),
|
|
92
|
+
var ft = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ft || {}), mt = /* @__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))(mt || {}), ht = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ht || {}), gt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(gt || {}), T = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(T || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(pt || {}), wt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(wt || {}), yt = /* @__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))(yt || {}), He = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(He || {});
|
|
93
93
|
const An = (e) => {
|
|
94
94
|
switch (e) {
|
|
95
95
|
case "clip":
|
|
@@ -102,7 +102,7 @@ const An = (e) => {
|
|
|
102
102
|
throw new Error(`Unknown video type: ${e}`);
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
var
|
|
105
|
+
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ie = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ie || {}), x = /* @__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))(x || {}), A = /* @__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))(A || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Se = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Se || {}), vt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(vt || {}), kt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(kt || {});
|
|
106
106
|
const xn = (...e) => {
|
|
107
107
|
}, qe = (e) => new Promise((t) => setTimeout(t, e)), ee = (e = 16) => {
|
|
108
108
|
const t = new Uint8Array(e);
|
|
@@ -119,7 +119,7 @@ function we(e) {
|
|
|
119
119
|
return t;
|
|
120
120
|
}
|
|
121
121
|
let ue = ee();
|
|
122
|
-
function
|
|
122
|
+
function Ct() {
|
|
123
123
|
ue = ee();
|
|
124
124
|
}
|
|
125
125
|
function Xe(e, t) {
|
|
@@ -131,7 +131,7 @@ function Xe(e, t) {
|
|
|
131
131
|
return `Client-Key ${e.clientKey}.${we(t)}_${ue}`;
|
|
132
132
|
throw new Error(`Unknown auth type: ${e}`);
|
|
133
133
|
}
|
|
134
|
-
const
|
|
134
|
+
const St = 45 * 1e3, Mt = "X-Playground-Chat", be = 2e3, me = "https://api.d-id.com", Rt = "wss://notifications.d-id.com", Dt = "79f81a83a67430be2bc0fd61042b8faa", Ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, It = (e) => {
|
|
135
135
|
switch (e.type) {
|
|
136
136
|
case "expressive":
|
|
137
137
|
return "v4";
|
|
@@ -140,8 +140,8 @@ const kt = 45 * 1e3, Mt = "X-Playground-Chat", Te = 2e3, me = "https://api.d-id.
|
|
|
140
140
|
case "talk":
|
|
141
141
|
return "v2";
|
|
142
142
|
}
|
|
143
|
-
}, Et = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Me = (e) => e === He.Expressive,
|
|
144
|
-
function
|
|
143
|
+
}, Et = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Me = (e) => e === He.Expressive, bt = (e) => [T.TextOnly, T.Playground, T.Maintenance].includes(e), Qe = (e) => e && [T.DirectPlayback, T.Off].includes(e), _e = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Te = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, _t = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
|
|
144
|
+
function Tt(e) {
|
|
145
145
|
const t = e.split("?")[0].split("#")[0].toLowerCase();
|
|
146
146
|
return _t.some((n) => t.endsWith(n));
|
|
147
147
|
}
|
|
@@ -157,11 +157,11 @@ function At(e) {
|
|
|
157
157
|
length: n[0].length,
|
|
158
158
|
part: { type: "video", src: n[3], alt: n[1], thumbnail: n[2] }
|
|
159
159
|
});
|
|
160
|
-
for (
|
|
160
|
+
for (Te.lastIndex = 0; (n = Te.exec(e)) !== null; )
|
|
161
161
|
if (!t.some((s) => n.index >= s.index && n.index < s.index + s.length)) {
|
|
162
162
|
const s = n[2], r = n[1];
|
|
163
163
|
let a;
|
|
164
|
-
|
|
164
|
+
Tt(s) ? a = { type: "video", src: s, alt: r } : (a = { type: "image", src: s, alt: r }, s.toLowerCase().endsWith(".gif") && (a.mimeType = "image/gif")), t.push({ index: n.index, length: n[0].length, part: a });
|
|
165
165
|
}
|
|
166
166
|
for (Ae.lastIndex = 0; (n = Ae.exec(e)) !== null; )
|
|
167
167
|
t.some((s) => n.index >= s.index && n.index < s.index + s.length) || t.push({
|
|
@@ -308,6 +308,9 @@ function Lt(e, t = me, n, i) {
|
|
|
308
308
|
deleteRating(o, s, r, a) {
|
|
309
309
|
return c.delete(`/${o}/chat/${s}/ratings/${r}`, a);
|
|
310
310
|
},
|
|
311
|
+
submitFeedback(o, s, r, a) {
|
|
312
|
+
return c.post(`/${o}/chat/${s}/feedback`, r, a);
|
|
313
|
+
},
|
|
311
314
|
getSTTToken(o, s) {
|
|
312
315
|
return c.get(`/${o}/stt-token`, s);
|
|
313
316
|
}
|
|
@@ -362,13 +365,13 @@ const Bt = (e) => {
|
|
|
362
365
|
} catch {
|
|
363
366
|
return "Unknown error";
|
|
364
367
|
}
|
|
365
|
-
},
|
|
368
|
+
}, Ft = (e) => e.reduce((t, n) => t + n, 0), Le = (e) => Ft(e) / e.length, je = (e) => Math.min(...e), $e = (e) => Math.max(...e), le = (e, t = 0) => {
|
|
366
369
|
const n = 10 ** t;
|
|
367
370
|
return Math.round(e * n) / n;
|
|
368
|
-
},
|
|
371
|
+
}, zt = (e, t) => {
|
|
369
372
|
const n = [...e].sort((i, c) => i - c);
|
|
370
373
|
return n[Math.min(n.length - 1, Math.floor(t * (n.length - 1)))];
|
|
371
|
-
},
|
|
374
|
+
}, Nt = (e) => zt(e, 0.5), Vt = (e, t) => {
|
|
372
375
|
try {
|
|
373
376
|
return e();
|
|
374
377
|
} catch {
|
|
@@ -392,7 +395,7 @@ function Be(e) {
|
|
|
392
395
|
function ge(e) {
|
|
393
396
|
return e instanceof G ? e.toJson() : { kind: "UnknownError", message: Bt(e) || "UnknownError" };
|
|
394
397
|
}
|
|
395
|
-
const Jt = "1.2.
|
|
398
|
+
const Jt = "1.2.8-staging.366", Ot = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", Ze = 50, Z = [];
|
|
396
399
|
let pe = !1;
|
|
397
400
|
async function et(e) {
|
|
398
401
|
const t = await fetch(Ot, {
|
|
@@ -482,9 +485,9 @@ function Re() {
|
|
|
482
485
|
get: (t = !1) => t ? Date.now() - e : e
|
|
483
486
|
};
|
|
484
487
|
}
|
|
485
|
-
const X = Re(),
|
|
488
|
+
const X = Re(), ke = Re(), Fe = Re();
|
|
486
489
|
function tt(e) {
|
|
487
|
-
return e ===
|
|
490
|
+
return e === T.Playground ? { headers: { [Mt]: "true" } } : {};
|
|
488
491
|
}
|
|
489
492
|
async function nt(e, t, n, i, c = !1, o) {
|
|
490
493
|
return !o && !Qe(i) && (o = await t.newChat(e.id, { persist: c }, tt(i)), n.track("agent-chat", {
|
|
@@ -541,7 +544,7 @@ async function Gt(e, t, n, i) {
|
|
|
541
544
|
subscribeToEvents: (s) => c.push(s)
|
|
542
545
|
};
|
|
543
546
|
}
|
|
544
|
-
function
|
|
547
|
+
function ze(e) {
|
|
545
548
|
if (e.answer !== void 0)
|
|
546
549
|
return e.answer;
|
|
547
550
|
let t = 0, n = "";
|
|
@@ -563,14 +566,14 @@ function Qt(e, t, n) {
|
|
|
563
566
|
t.messages.push(i), n == null || n([...t.messages], "user");
|
|
564
567
|
}
|
|
565
568
|
function Yt(e, t, n, i, c, o, s) {
|
|
566
|
-
if (e ===
|
|
569
|
+
if (e === F.Transcribe && t.content) {
|
|
567
570
|
Qt(t, i, c);
|
|
568
571
|
return;
|
|
569
572
|
}
|
|
570
|
-
if (!(e ===
|
|
573
|
+
if (!(e === F.Partial || e === F.Answer))
|
|
571
574
|
return;
|
|
572
575
|
const r = i.messages[i.messages.length - 1];
|
|
573
|
-
if (e ===
|
|
576
|
+
if (e === F.Answer && (r == null ? void 0 : r.role) === "user" && s === "partial")
|
|
574
577
|
return;
|
|
575
578
|
const d = s === "answer";
|
|
576
579
|
let m;
|
|
@@ -587,14 +590,14 @@ function Yt(e, t, n, i, c, o, s) {
|
|
|
587
590
|
else
|
|
588
591
|
return;
|
|
589
592
|
const { content: u, sequence: f } = t;
|
|
590
|
-
if (e ===
|
|
593
|
+
if (e === F.Partial)
|
|
591
594
|
n[f] = u;
|
|
592
595
|
else {
|
|
593
|
-
const v =
|
|
596
|
+
const v = ze(n);
|
|
594
597
|
!!(u && u.length < v.length) && (m.interrupted = !0), n.answer = u;
|
|
595
598
|
}
|
|
596
|
-
const w =
|
|
597
|
-
(m.content !== w || e ===
|
|
599
|
+
const w = ze(n);
|
|
600
|
+
(m.content !== w || e === F.Answer) && (m.content = w, m.parts = ae(w), c == null || c([...i.messages], e));
|
|
598
601
|
}
|
|
599
602
|
function Zt(e, t, n, i, c) {
|
|
600
603
|
const o = {}, s = () => {
|
|
@@ -611,7 +614,7 @@ function Zt(e, t, n, i, c) {
|
|
|
611
614
|
onMessage: (d, m) => {
|
|
612
615
|
var u, f;
|
|
613
616
|
if ("content" in m) {
|
|
614
|
-
const w = d === x.ChatAnswer ?
|
|
617
|
+
const w = d === x.ChatAnswer ? F.Answer : d === x.ChatAudioTranscribed ? F.Transcribe : d;
|
|
615
618
|
Yt(
|
|
616
619
|
w,
|
|
617
620
|
m,
|
|
@@ -620,7 +623,7 @@ function Zt(e, t, n, i, c) {
|
|
|
620
623
|
a,
|
|
621
624
|
s,
|
|
622
625
|
r
|
|
623
|
-
), w ===
|
|
626
|
+
), w === F.Partial ? r = "partial" : w === F.Answer && (r = "answer", s()), w === F.Answer && e.track("agent-message-received", {
|
|
624
627
|
content: m.content,
|
|
625
628
|
messages: t.messages.length,
|
|
626
629
|
mode: t.chatMode
|
|
@@ -628,15 +631,15 @@ function Zt(e, t, n, i, c) {
|
|
|
628
631
|
} else {
|
|
629
632
|
const w = x, v = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], j = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], I = Ut(m, i, { mode: t.chatMode });
|
|
630
633
|
if (d = d, d === w.StreamVideoCreated && (e.linkTrack("agent-video", I, w.StreamVideoCreated, ["start"]), m.sentiment)) {
|
|
631
|
-
const
|
|
632
|
-
if ((
|
|
633
|
-
const P = { ...
|
|
634
|
+
const b = t.messages[t.messages.length - 1];
|
|
635
|
+
if ((b == null ? void 0 : b.role) === "assistant") {
|
|
636
|
+
const P = { ...b, sentiment: m.sentiment };
|
|
634
637
|
t.messages[t.messages.length - 1] = P, a == null || a([...t.messages], r ?? "answer");
|
|
635
638
|
}
|
|
636
639
|
}
|
|
637
640
|
if (v.includes(d)) {
|
|
638
|
-
const
|
|
639
|
-
j.includes(d) ? e.track("agent-video", { ...I, event:
|
|
641
|
+
const b = d.split("/")[1];
|
|
642
|
+
j.includes(d) ? e.track("agent-video", { ...I, event: b }) : e.linkTrack("agent-video", { ...I, event: b }, d, ["done"]);
|
|
640
643
|
}
|
|
641
644
|
j.includes(d) && ((f = (u = n.callbacks).onError) == null || f.call(u, new We(`Stream failed with event ${d}`), { data: m })), m.event === w.StreamDone && c();
|
|
642
645
|
}
|
|
@@ -693,7 +696,7 @@ function rn(e) {
|
|
|
693
696
|
durationMs: le(i),
|
|
694
697
|
desyncDurationMs: le(i * (o.length / c.length)),
|
|
695
698
|
maxOffsetMs: le(c.reduce((a, d) => Math.abs(d) > Math.abs(a) ? d : a)),
|
|
696
|
-
residualOffsetMs: le(
|
|
699
|
+
residualOffsetMs: le(Nt(r))
|
|
697
700
|
};
|
|
698
701
|
}
|
|
699
702
|
function an(e, t, n) {
|
|
@@ -768,7 +771,7 @@ function on(e) {
|
|
|
768
771
|
localTs: s.timestamp
|
|
769
772
|
}), r;
|
|
770
773
|
}
|
|
771
|
-
function
|
|
774
|
+
function Ne(e, t, n) {
|
|
772
775
|
const i = e.map((a, d) => d === 0 ? n ? {
|
|
773
776
|
timestamp: a.timestamp,
|
|
774
777
|
duration: 0,
|
|
@@ -907,12 +910,12 @@ function fn(e, t, n, i, c) {
|
|
|
907
910
|
const I = await e();
|
|
908
911
|
if (!I)
|
|
909
912
|
return;
|
|
910
|
-
const { isReceiving:
|
|
911
|
-
if (
|
|
912
|
-
a = 0, f = E - w, u = P < dn ? re.Strong : P > ln && f > 1 ? re.Weak : m, u !== m && (c == null || c(u), m = u, w += f, f = 0), d || (i == null || i(
|
|
913
|
+
const { isReceiving: b, avgJitterDelayInInterval: P, freezeCount: E } = v(I), Q = on(I);
|
|
914
|
+
if (b)
|
|
915
|
+
a = 0, f = E - w, u = P < dn ? re.Strong : P > ln && f > 1 ? re.Weak : m, u !== m && (c == null || c(u), m = u, w += f, f = 0), d || (i == null || i(C.Start), r = s[s.length - 1], s = [], d = !0), s.push(Q);
|
|
913
916
|
else if (d && (a++, a >= cn)) {
|
|
914
|
-
const H =
|
|
915
|
-
i == null || i(
|
|
917
|
+
const H = Ne(s, fe, r);
|
|
918
|
+
i == null || i(C.Stop, H), t() || n(), w = E, d = !1;
|
|
916
919
|
}
|
|
917
920
|
}
|
|
918
921
|
return {
|
|
@@ -922,7 +925,7 @@ function fn(e, t, n, i, c) {
|
|
|
922
925
|
stop: () => {
|
|
923
926
|
o && (clearInterval(o), o = null);
|
|
924
927
|
},
|
|
925
|
-
getReport: () =>
|
|
928
|
+
getReport: () => Ne(s, fe, r)
|
|
926
929
|
};
|
|
927
930
|
}
|
|
928
931
|
const mn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
@@ -962,7 +965,7 @@ function gn({
|
|
|
962
965
|
report: i,
|
|
963
966
|
log: c
|
|
964
967
|
}) {
|
|
965
|
-
e ===
|
|
968
|
+
e === C.Start && t === C.Start ? (c("CALLBACK: onVideoStateChange(Start)"), n == null || n(C.Start)) : e === C.Stop && t === C.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), n == null || n(C.Stop, i));
|
|
966
969
|
}
|
|
967
970
|
function pn({
|
|
968
971
|
statsSignal: e,
|
|
@@ -972,7 +975,7 @@ function pn({
|
|
|
972
975
|
report: c,
|
|
973
976
|
log: o
|
|
974
977
|
}) {
|
|
975
|
-
e ===
|
|
978
|
+
e === C.Start ? (o("CALLBACK: onVideoStateChange(Start)"), n == null || n(C.Start)) : e === C.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), n == null || n(C.Stop, c)), t === C.Start ? i == null || i(ie.Talking) : t === C.Stop && (i == null || i(ie.Idle));
|
|
976
979
|
}
|
|
977
980
|
function Ue({
|
|
978
981
|
statsSignal: e,
|
|
@@ -993,10 +996,10 @@ function Ue({
|
|
|
993
996
|
});
|
|
994
997
|
}
|
|
995
998
|
async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me, analytics: s }, r) {
|
|
996
|
-
var
|
|
999
|
+
var N;
|
|
997
1000
|
const a = tn(n, "WebRTCStreamingManager"), d = hn(a);
|
|
998
|
-
let m = !1, u = !1, f =
|
|
999
|
-
const { startConnection: v, sendStreamRequest: j, close: I, createStream:
|
|
1001
|
+
let m = !1, u = !1, f = C.Stop, w = C.Stop;
|
|
1002
|
+
const { startConnection: v, sendStreamRequest: j, close: I, createStream: b, addIceCandidate: P } = en(
|
|
1000
1003
|
c,
|
|
1001
1004
|
o,
|
|
1002
1005
|
e,
|
|
@@ -1008,8 +1011,8 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1008
1011
|
session_id: V,
|
|
1009
1012
|
fluent: se,
|
|
1010
1013
|
interrupt_enabled: Y
|
|
1011
|
-
} = await
|
|
1012
|
-
(
|
|
1014
|
+
} = await b(t, r);
|
|
1015
|
+
(N = i.onStreamCreated) == null || N.call(i, { stream_id: E, session_id: V, agent_id: e });
|
|
1013
1016
|
const R = new mn({ iceServers: H }), q = R.createDataChannel("JanusDataChannel");
|
|
1014
1017
|
if (!V)
|
|
1015
1018
|
throw new Error("Could not create session_id");
|
|
@@ -1024,22 +1027,22 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1024
1027
|
() => R.getStats(),
|
|
1025
1028
|
ce,
|
|
1026
1029
|
te,
|
|
1027
|
-
(h,
|
|
1030
|
+
(h, p) => Ue({
|
|
1028
1031
|
statsSignal: w = h,
|
|
1029
1032
|
dataChannelSignal: U === W.Legacy ? f : void 0,
|
|
1030
1033
|
onVideoStateChange: i.onVideoStateChange,
|
|
1031
1034
|
onAgentActivityStateChange: i.onAgentActivityStateChange,
|
|
1032
|
-
report:
|
|
1035
|
+
report: p,
|
|
1033
1036
|
streamType: U,
|
|
1034
1037
|
log: a
|
|
1035
1038
|
}),
|
|
1036
1039
|
(h) => {
|
|
1037
|
-
var
|
|
1038
|
-
return (
|
|
1040
|
+
var p;
|
|
1041
|
+
return (p = i.onConnectivityStateChange) == null ? void 0 : p.call(i, h);
|
|
1039
1042
|
}
|
|
1040
1043
|
);
|
|
1041
1044
|
l.start(), R.onicecandidate = (h) => {
|
|
1042
|
-
var
|
|
1045
|
+
var p;
|
|
1043
1046
|
a("peerConnection.onicecandidate", h);
|
|
1044
1047
|
try {
|
|
1045
1048
|
h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? P(
|
|
@@ -1053,22 +1056,22 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1053
1056
|
r
|
|
1054
1057
|
) : P(E, { candidate: null }, V, r);
|
|
1055
1058
|
} catch (D) {
|
|
1056
|
-
(
|
|
1059
|
+
(p = i.onError) == null || p.call(i, D, { streamId: E });
|
|
1057
1060
|
}
|
|
1058
1061
|
}, q.onopen = () => {
|
|
1059
1062
|
u = !0, (!oe || m) && te();
|
|
1060
1063
|
};
|
|
1061
|
-
let
|
|
1064
|
+
let g = null;
|
|
1062
1065
|
const y = (h) => {
|
|
1063
|
-
var
|
|
1064
|
-
|
|
1066
|
+
var p;
|
|
1067
|
+
g = h, (p = i.onVideoIdChange) == null || p.call(i, h);
|
|
1065
1068
|
};
|
|
1066
|
-
function
|
|
1067
|
-
if (h === x.StreamStarted && typeof
|
|
1068
|
-
const D =
|
|
1069
|
+
function k(h, p) {
|
|
1070
|
+
if (h === x.StreamStarted && typeof p == "object" && "metadata" in p) {
|
|
1071
|
+
const D = p.metadata;
|
|
1069
1072
|
y(D.videoId);
|
|
1070
1073
|
}
|
|
1071
|
-
h === x.StreamDone && y(null), f = h === x.StreamStarted ?
|
|
1074
|
+
h === x.StreamDone && y(null), f = h === x.StreamStarted ? C.Start : C.Stop, Ue({
|
|
1072
1075
|
statsSignal: U === W.Legacy ? w : void 0,
|
|
1073
1076
|
dataChannelSignal: f,
|
|
1074
1077
|
onVideoStateChange: i.onVideoStateChange,
|
|
@@ -1077,43 +1080,43 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1077
1080
|
log: a
|
|
1078
1081
|
});
|
|
1079
1082
|
}
|
|
1080
|
-
function
|
|
1081
|
-
var
|
|
1082
|
-
const D = typeof
|
|
1083
|
-
D && s.enrich({ streamMetadata: D }), (
|
|
1083
|
+
function S(h, p) {
|
|
1084
|
+
var B;
|
|
1085
|
+
const D = typeof p == "string" ? p : p == null ? void 0 : p.metadata;
|
|
1086
|
+
D && s.enrich({ streamMetadata: D }), (B = i.onStreamReady) == null || B.call(i);
|
|
1084
1087
|
}
|
|
1085
1088
|
const M = {
|
|
1086
|
-
[x.StreamStarted]:
|
|
1087
|
-
[x.StreamDone]:
|
|
1088
|
-
[x.StreamReady]:
|
|
1089
|
+
[x.StreamStarted]: k,
|
|
1090
|
+
[x.StreamDone]: k,
|
|
1091
|
+
[x.StreamReady]: S
|
|
1089
1092
|
};
|
|
1090
1093
|
q.onmessage = (h) => {
|
|
1091
|
-
var
|
|
1092
|
-
const { subject:
|
|
1093
|
-
(
|
|
1094
|
+
var B;
|
|
1095
|
+
const { subject: p, data: D } = d(h.data);
|
|
1096
|
+
(B = M[p]) == null || B.call(M, p, D);
|
|
1094
1097
|
}, R.oniceconnectionstatechange = () => {
|
|
1095
|
-
var
|
|
1098
|
+
var p;
|
|
1096
1099
|
a("peerConnection.oniceconnectionstatechange => " + R.iceConnectionState);
|
|
1097
1100
|
const h = Ve(R.iceConnectionState);
|
|
1098
|
-
h !== A.Connected && ((
|
|
1101
|
+
h !== A.Connected && ((p = i.onConnectionStateChange) == null || p.call(i, h, `webrtc:ice-${R.iceConnectionState}`));
|
|
1099
1102
|
}, R.ontrack = (h) => {
|
|
1100
|
-
var
|
|
1101
|
-
a("peerConnection.ontrack", h), a("CALLBACK: onSrcObjectReady"), (
|
|
1103
|
+
var p;
|
|
1104
|
+
a("peerConnection.ontrack", h), a("CALLBACK: onSrcObjectReady"), (p = i.onSrcObjectReady) == null || p.call(i, h.streams[0]);
|
|
1102
1105
|
}, await R.setRemoteDescription(Q), a("set remote description OK");
|
|
1103
1106
|
const L = await R.createAnswer();
|
|
1104
1107
|
a("create answer OK"), await R.setLocalDescription(L), a("set local description OK"), await v(E, L, V, r), a("start connection OK");
|
|
1105
|
-
function
|
|
1106
|
-
var
|
|
1108
|
+
function z(h) {
|
|
1109
|
+
var p, D;
|
|
1107
1110
|
if (!m || q.readyState !== "open") {
|
|
1108
|
-
a("Data channel is not ready for sending messages"), (
|
|
1111
|
+
a("Data channel is not ready for sending messages"), (p = i.onError) == null || p.call(i, new We("Data channel is not ready for sending messages"), {
|
|
1109
1112
|
streamId: E
|
|
1110
1113
|
});
|
|
1111
1114
|
return;
|
|
1112
1115
|
}
|
|
1113
1116
|
try {
|
|
1114
1117
|
q.send(h);
|
|
1115
|
-
} catch (
|
|
1116
|
-
a("Error sending data channel message",
|
|
1118
|
+
} catch (B) {
|
|
1119
|
+
a("Error sending data channel message", B), (D = i.onError) == null || D.call(i, B, { streamId: E });
|
|
1117
1120
|
}
|
|
1118
1121
|
}
|
|
1119
1122
|
return {
|
|
@@ -1130,16 +1133,16 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1130
1133
|
async disconnect() {
|
|
1131
1134
|
var h;
|
|
1132
1135
|
if (E) {
|
|
1133
|
-
const
|
|
1136
|
+
const p = Ve(R.iceConnectionState);
|
|
1134
1137
|
if (R) {
|
|
1135
|
-
if (
|
|
1138
|
+
if (p === A.New) {
|
|
1136
1139
|
l.stop();
|
|
1137
1140
|
return;
|
|
1138
1141
|
}
|
|
1139
1142
|
R.close(), R.oniceconnectionstatechange = null, R.onnegotiationneeded = null, R.onicecandidate = null, R.ontrack = null;
|
|
1140
1143
|
}
|
|
1141
1144
|
try {
|
|
1142
|
-
|
|
1145
|
+
p === A.Connected && await I(E, V).catch((D) => {
|
|
1143
1146
|
});
|
|
1144
1147
|
} catch (D) {
|
|
1145
1148
|
a("Error on close stream connection", D);
|
|
@@ -1147,7 +1150,7 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1147
1150
|
(h = i.onAgentActivityStateChange) == null || h.call(i, ie.Idle), l.stop();
|
|
1148
1151
|
}
|
|
1149
1152
|
},
|
|
1150
|
-
sendDataChannelMessage:
|
|
1153
|
+
sendDataChannelMessage: z,
|
|
1151
1154
|
/**
|
|
1152
1155
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1153
1156
|
*/
|
|
@@ -1164,18 +1167,18 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
|
|
|
1164
1167
|
throw new Error("Interrupt is not enabled for this stream");
|
|
1165
1168
|
if (U !== W.Fluent)
|
|
1166
1169
|
throw new Error("Interrupt only available for Fluent streams");
|
|
1167
|
-
if (!
|
|
1170
|
+
if (!g)
|
|
1168
1171
|
throw new Error("No active video to interrupt");
|
|
1169
|
-
const
|
|
1172
|
+
const p = {
|
|
1170
1173
|
type: x.StreamInterrupt,
|
|
1171
|
-
videoId:
|
|
1174
|
+
videoId: g,
|
|
1172
1175
|
timestamp: Date.now()
|
|
1173
1176
|
};
|
|
1174
|
-
|
|
1177
|
+
z(JSON.stringify(p));
|
|
1175
1178
|
}
|
|
1176
1179
|
};
|
|
1177
1180
|
}
|
|
1178
|
-
var
|
|
1181
|
+
var Ce = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ce || {});
|
|
1179
1182
|
async function yn(e, t, n, i) {
|
|
1180
1183
|
const c = e.id;
|
|
1181
1184
|
switch (t.version) {
|
|
@@ -1186,8 +1189,8 @@ async function yn(e, t, n, i) {
|
|
|
1186
1189
|
case "v2": {
|
|
1187
1190
|
const { version: o, ...s } = t;
|
|
1188
1191
|
switch (s.transport.provider) {
|
|
1189
|
-
case
|
|
1190
|
-
const { createLiveKitStreamingManager: r } = await import("./livekit-manager-
|
|
1192
|
+
case Se.Livekit:
|
|
1193
|
+
const { createLiveKitStreamingManager: r } = await import("./livekit-manager-C3HASruw.js");
|
|
1191
1194
|
return r(c, s, n);
|
|
1192
1195
|
default:
|
|
1193
1196
|
throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
|
|
@@ -1198,14 +1201,14 @@ async function yn(e, t, n, i) {
|
|
|
1198
1201
|
}
|
|
1199
1202
|
}
|
|
1200
1203
|
const vn = "cht";
|
|
1201
|
-
function
|
|
1204
|
+
function kn() {
|
|
1202
1205
|
return {
|
|
1203
1206
|
transport: {
|
|
1204
|
-
provider:
|
|
1207
|
+
provider: Se.Livekit
|
|
1205
1208
|
}
|
|
1206
1209
|
};
|
|
1207
1210
|
}
|
|
1208
|
-
function
|
|
1211
|
+
function Cn(e) {
|
|
1209
1212
|
var c, o;
|
|
1210
1213
|
const { streamOptions: t } = e ?? {}, n = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
1211
1214
|
plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
|
|
@@ -1218,8 +1221,8 @@ function Sn(e) {
|
|
|
1218
1221
|
fluent: t == null ? void 0 : t.fluent
|
|
1219
1222
|
}, ...n && { end_user_data: n } };
|
|
1220
1223
|
}
|
|
1221
|
-
function
|
|
1222
|
-
return Me(e.presenter.type) ? { version:
|
|
1224
|
+
function Sn(e, t) {
|
|
1225
|
+
return Me(e.presenter.type) ? { version: Ce.V2, ...kn() } : { version: Ce.V1, ...Cn(t) };
|
|
1223
1226
|
}
|
|
1224
1227
|
function Mn(e, t, n) {
|
|
1225
1228
|
n.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
@@ -1228,7 +1231,7 @@ function Rn(e, t, n, i, c) {
|
|
|
1228
1231
|
c === W.Fluent ? Dn(e, t, n, i, c) : In(e, t, n, i, c);
|
|
1229
1232
|
}
|
|
1230
1233
|
function Dn(e, t, n, i, c) {
|
|
1231
|
-
e ===
|
|
1234
|
+
e === C.Start ? i.track("stream-session", { event: "start", "stream-type": c }) : e === C.Stop && i.track("stream-session", {
|
|
1232
1235
|
event: "stop",
|
|
1233
1236
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1234
1237
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -1237,9 +1240,9 @@ function Dn(e, t, n, i, c) {
|
|
|
1237
1240
|
});
|
|
1238
1241
|
}
|
|
1239
1242
|
function Je(e, t, n, i, c) {
|
|
1240
|
-
e ===
|
|
1243
|
+
e === C.Start ? n.linkTrack("agent-video", { event: "start", ...c, "stream-type": i }, "start", [
|
|
1241
1244
|
x.StreamVideoCreated
|
|
1242
|
-
]) : e ===
|
|
1245
|
+
]) : e === C.Stop && n.linkTrack(
|
|
1243
1246
|
"agent-video",
|
|
1244
1247
|
{
|
|
1245
1248
|
event: "stop",
|
|
@@ -1252,12 +1255,12 @@ function Je(e, t, n, i, c) {
|
|
|
1252
1255
|
);
|
|
1253
1256
|
}
|
|
1254
1257
|
function In(e, t, n, i, c) {
|
|
1255
|
-
e ===
|
|
1258
|
+
e === C.Start ? i.linkTrack(
|
|
1256
1259
|
"agent-video",
|
|
1257
1260
|
{ event: "start", latency: X.get(!0), "stream-type": c },
|
|
1258
1261
|
"start",
|
|
1259
1262
|
[x.StreamVideoCreated]
|
|
1260
|
-
) : e ===
|
|
1263
|
+
) : e === C.Stop && i.linkTrack(
|
|
1261
1264
|
"agent-video",
|
|
1262
1265
|
{
|
|
1263
1266
|
event: "stop",
|
|
@@ -1288,10 +1291,10 @@ function En(e, t, n) {
|
|
|
1288
1291
|
});
|
|
1289
1292
|
}
|
|
1290
1293
|
function Oe(e, t, n, i) {
|
|
1291
|
-
return X.reset(),
|
|
1294
|
+
return X.reset(), Fe.update(), new Promise(async (c, o) => {
|
|
1292
1295
|
try {
|
|
1293
1296
|
let s, r = !1;
|
|
1294
|
-
const a =
|
|
1297
|
+
const a = Sn(e, t);
|
|
1295
1298
|
n.enrich({
|
|
1296
1299
|
"stream-version": a.version.toString()
|
|
1297
1300
|
});
|
|
@@ -1321,16 +1324,16 @@ function Oe(e, t, n, i) {
|
|
|
1321
1324
|
},
|
|
1322
1325
|
onAgentActivityStateChange: (u) => {
|
|
1323
1326
|
var f, w;
|
|
1324
|
-
(w = (f = t.callbacks).onAgentActivityStateChange) == null || w.call(f, u), u === ie.Talking ? (
|
|
1327
|
+
(w = (f = t.callbacks).onAgentActivityStateChange) == null || w.call(f, u), u === ie.Talking ? (ke.update(), d = (v) => {
|
|
1325
1328
|
Je(
|
|
1326
|
-
|
|
1329
|
+
C.Start,
|
|
1327
1330
|
e,
|
|
1328
1331
|
n,
|
|
1329
1332
|
s.streamType,
|
|
1330
1333
|
v
|
|
1331
1334
|
), d = null;
|
|
1332
|
-
}, m || d({ latency: X.get(!0) })) : (
|
|
1333
|
-
|
|
1335
|
+
}, m || d({ latency: X.get(!0) })) : (ke.reset(), d = null, Je(
|
|
1336
|
+
C.Stop,
|
|
1334
1337
|
e,
|
|
1335
1338
|
n,
|
|
1336
1339
|
s.streamType
|
|
@@ -1340,7 +1343,7 @@ function Oe(e, t, n, i) {
|
|
|
1340
1343
|
d == null || d(u);
|
|
1341
1344
|
},
|
|
1342
1345
|
onStreamReady: () => {
|
|
1343
|
-
const u =
|
|
1346
|
+
const u = Fe.get(!0);
|
|
1344
1347
|
n.track("agent-chat", { event: "ready", latency: u });
|
|
1345
1348
|
},
|
|
1346
1349
|
onToolEvent: ((u, f) => {
|
|
@@ -1356,13 +1359,13 @@ function Oe(e, t, n, i) {
|
|
|
1356
1359
|
}
|
|
1357
1360
|
});
|
|
1358
1361
|
}
|
|
1359
|
-
async function
|
|
1362
|
+
async function bn(e, t, n, i, c) {
|
|
1360
1363
|
var m, u, f, w;
|
|
1361
1364
|
const o = async () => {
|
|
1362
1365
|
if (Me(e.presenter.type)) {
|
|
1363
1366
|
const v = await Oe(e, t, i), j = `${vn}_${v.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
|
|
1364
1367
|
return { chatResult: {
|
|
1365
|
-
chatMode:
|
|
1368
|
+
chatMode: T.Functional,
|
|
1366
1369
|
chat: {
|
|
1367
1370
|
id: j,
|
|
1368
1371
|
agent_id: e.id,
|
|
@@ -1371,7 +1374,7 @@ async function Tn(e, t, n, i, c) {
|
|
|
1371
1374
|
modified: I,
|
|
1372
1375
|
agent_id__created_at: I,
|
|
1373
1376
|
agent_id__modified_at: I,
|
|
1374
|
-
chat_mode:
|
|
1377
|
+
chat_mode: T.Functional,
|
|
1375
1378
|
messages: []
|
|
1376
1379
|
}
|
|
1377
1380
|
}, streamingManager: v };
|
|
@@ -1379,27 +1382,27 @@ async function Tn(e, t, n, i, c) {
|
|
|
1379
1382
|
const v = new AbortController(), j = v.signal;
|
|
1380
1383
|
let I;
|
|
1381
1384
|
try {
|
|
1382
|
-
const
|
|
1385
|
+
const b = nt(
|
|
1383
1386
|
e,
|
|
1384
1387
|
n,
|
|
1385
1388
|
i,
|
|
1386
1389
|
t.mode,
|
|
1387
1390
|
t.persistentChat,
|
|
1388
1391
|
c
|
|
1389
|
-
), P = Oe(e, t, i, j).then((H) => (I = H, H)), [E, Q] = await Promise.all([
|
|
1392
|
+
), P = Oe(e, t, i, j).then((H) => (I = H, H)), [E, Q] = await Promise.all([b, P]);
|
|
1390
1393
|
return { chatResult: E, streamingManager: Q };
|
|
1391
|
-
} catch (
|
|
1394
|
+
} catch (b) {
|
|
1392
1395
|
throw v.abort(), I && await I.disconnect().catch(() => {
|
|
1393
|
-
}),
|
|
1396
|
+
}), b;
|
|
1394
1397
|
}
|
|
1395
1398
|
}
|
|
1396
1399
|
}, { chatResult: s, streamingManager: r } = await o(), { chat: a, chatMode: d } = s;
|
|
1397
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (u = (m = t.callbacks).onModeChange) == null || u.call(m, d), d !==
|
|
1400
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (u = (m = t.callbacks).onModeChange) == null || u.call(m, d), d !== T.Functional) ? ((w = (f = t.callbacks).onError) == null || w.call(f, new ct(d)), r == null || r.disconnect(), { chat: a }) : { chat: a, streamingManager: r };
|
|
1398
1401
|
}
|
|
1399
1402
|
async function Ln(e, t) {
|
|
1400
1403
|
var U, oe, ce, te;
|
|
1401
1404
|
let n = !0;
|
|
1402
|
-
const i = t.mixpanelKey || Dt, c = t.wsURL || Rt, o = t.baseURL || me, s = t.mode ||
|
|
1405
|
+
const i = t.mixpanelKey || Dt, c = t.wsURL || Rt, o = t.baseURL || me, s = t.mode || T.Functional, r = {
|
|
1403
1406
|
messages: [],
|
|
1404
1407
|
chatMode: s
|
|
1405
1408
|
}, a = Wt({
|
|
@@ -1413,71 +1416,71 @@ async function Ln(e, t) {
|
|
|
1413
1416
|
a.track("agent-sdk", { event: "init" }, d);
|
|
1414
1417
|
});
|
|
1415
1418
|
const m = t.callbacks.onError;
|
|
1416
|
-
t.callbacks.onError = (l,
|
|
1417
|
-
a.track("agent-error", { error: ge(l) }), m == null || m(l,
|
|
1419
|
+
t.callbacks.onError = (l, g) => {
|
|
1420
|
+
a.track("agent-error", { error: ge(l) }), m == null || m(l, g);
|
|
1418
1421
|
};
|
|
1419
1422
|
const u = Lt(t.auth, o, t.callbacks.onError, t.externalId), f = await u.getById(e);
|
|
1420
1423
|
t.debug = t.debug || ((U = f == null ? void 0 : f.advanced_settings) == null ? void 0 : U.ui_debug_mode);
|
|
1421
1424
|
const w = Me(f.presenter.type);
|
|
1422
1425
|
a.enrich($t(f));
|
|
1423
1426
|
const { onMessage: v, clearQueue: j } = Zt(a, r, t, f, () => {
|
|
1424
|
-
var l,
|
|
1425
|
-
(l = r.socketManager) == null || l.disconnect(), (y = (
|
|
1427
|
+
var l, g, y;
|
|
1428
|
+
(l = r.socketManager) == null || l.disconnect(), (y = (g = t.callbacks).onConnectionStateChange) == null || y.call(g, A.Disconnected);
|
|
1426
1429
|
});
|
|
1427
1430
|
r.messages = Ht(t.initialMessages), (ce = (oe = t.callbacks).onNewMessage) == null || ce.call(oe, [...r.messages], "answer");
|
|
1428
1431
|
const I = (l) => {
|
|
1429
1432
|
a.enrich({ videoId: l });
|
|
1430
|
-
},
|
|
1431
|
-
var y,
|
|
1432
|
-
if (!((y = r.streamingManager) != null && y.interruptAvailable) || !((
|
|
1433
|
-
const
|
|
1433
|
+
}, b = ({ type: l }) => {
|
|
1434
|
+
var y, k, S, M;
|
|
1435
|
+
if (!((y = r.streamingManager) != null && y.interruptAvailable) || !((k = r.streamingManager) != null && k.isInterruptible)) return;
|
|
1436
|
+
const g = r.messages[r.messages.length - 1];
|
|
1434
1437
|
a.track("agent-video-interrupt", {
|
|
1435
1438
|
type: l || "click",
|
|
1436
|
-
video_duration_to_interrupt:
|
|
1439
|
+
video_duration_to_interrupt: ke.get(!0),
|
|
1437
1440
|
message_duration_to_interrupt: X.get(!0)
|
|
1438
|
-
}),
|
|
1441
|
+
}), g.interrupted = !0, (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "answer"), r.streamingManager.interrupt(l);
|
|
1439
1442
|
}, P = /* @__PURE__ */ new Map();
|
|
1440
1443
|
function E(l) {
|
|
1441
|
-
return async (
|
|
1444
|
+
return async (g) => {
|
|
1442
1445
|
const y = P.get(l);
|
|
1443
1446
|
if (!y)
|
|
1444
1447
|
throw new Error(`No handler registered for client tool: ${l}`);
|
|
1445
1448
|
try {
|
|
1446
|
-
const
|
|
1447
|
-
return await y(
|
|
1448
|
-
} catch (
|
|
1449
|
-
throw new Error(`Client tool "${l}" failed: ${
|
|
1449
|
+
const k = JSON.parse(g.payload);
|
|
1450
|
+
return await y(k);
|
|
1451
|
+
} catch (k) {
|
|
1452
|
+
throw new Error(`Client tool "${l}" failed: ${k.message}`);
|
|
1450
1453
|
}
|
|
1451
1454
|
};
|
|
1452
1455
|
}
|
|
1453
1456
|
function Q() {
|
|
1454
|
-
var l,
|
|
1455
|
-
for (const [
|
|
1456
|
-
(
|
|
1457
|
+
var l, g, y, k;
|
|
1458
|
+
for (const [S] of P)
|
|
1459
|
+
(g = (l = r.streamingManager) == null ? void 0 : l.unregisterRpcMethod) == null || g.call(l, S), (k = (y = r.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || k.call(y, S, E(S));
|
|
1457
1460
|
}
|
|
1458
|
-
function H(l,
|
|
1459
|
-
var
|
|
1461
|
+
function H(l, g) {
|
|
1462
|
+
var k, S;
|
|
1460
1463
|
const y = !P.has(l);
|
|
1461
|
-
P.set(l,
|
|
1464
|
+
P.set(l, g), y && ((S = (k = r.streamingManager) == null ? void 0 : k.registerRpcMethod) == null || S.call(k, l, E(l)));
|
|
1462
1465
|
}
|
|
1463
1466
|
function V(l) {
|
|
1464
|
-
var
|
|
1465
|
-
P.delete(l), (y = (
|
|
1467
|
+
var g, y;
|
|
1468
|
+
P.delete(l), (y = (g = r.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || y.call(g, l);
|
|
1466
1469
|
}
|
|
1467
1470
|
const se = Date.now();
|
|
1468
1471
|
Be(() => {
|
|
1469
1472
|
a.track("agent-sdk", { event: "loaded", ...jt(f) }, se);
|
|
1470
1473
|
});
|
|
1471
1474
|
async function Y(l) {
|
|
1472
|
-
var L,
|
|
1473
|
-
|
|
1474
|
-
const
|
|
1475
|
+
var L, z, N, h, p, D, B;
|
|
1476
|
+
Ct(), (z = (L = t.callbacks).onConnectionStateChange) == null || z.call(L, A.Connecting), X.reset(), l && !n && (delete r.chat, (h = (N = t.callbacks).onNewMessage) == null || h.call(N, [...r.messages], "answer"));
|
|
1477
|
+
const g = s === T.DirectPlayback || w ? Promise.resolve(void 0) : Gt(
|
|
1475
1478
|
t.auth,
|
|
1476
1479
|
c,
|
|
1477
1480
|
{ onMessage: v, onError: t.callbacks.onError },
|
|
1478
1481
|
t.externalId
|
|
1479
1482
|
), y = ye(
|
|
1480
|
-
() =>
|
|
1483
|
+
() => bn(
|
|
1481
1484
|
f,
|
|
1482
1485
|
{
|
|
1483
1486
|
...t,
|
|
@@ -1494,28 +1497,28 @@ async function Ln(e, t) {
|
|
|
1494
1497
|
),
|
|
1495
1498
|
{
|
|
1496
1499
|
limit: 3,
|
|
1497
|
-
timeout:
|
|
1500
|
+
timeout: St,
|
|
1498
1501
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1499
1502
|
shouldRetryFn: (O) => (O == null ? void 0 : O.message) !== "Could not connect" && !(O instanceof Ke && (O.status === 429 || O.kind === "InsufficientCreditsError")),
|
|
1500
1503
|
delayMs: 1e3
|
|
1501
1504
|
}
|
|
1502
1505
|
).catch((O) => {
|
|
1503
1506
|
var _, J;
|
|
1504
|
-
throw q(
|
|
1505
|
-
}), [
|
|
1506
|
-
M && M.id !== ((
|
|
1507
|
+
throw q(T.Maintenance), (J = (_ = t.callbacks).onConnectionStateChange) == null || J.call(_, A.Fail), O;
|
|
1508
|
+
}), [k, { streamingManager: S, chat: M }] = await Promise.all([g, y]);
|
|
1509
|
+
M && M.id !== ((p = r.chat) == null ? void 0 : p.id) && ((B = (D = t.callbacks).onNewChat) == null || B.call(D, M.id)), r.streamingManager = S, r.socketManager = k, r.chat = M, Q(), n = !1, a.enrich({
|
|
1507
1510
|
chatId: M == null ? void 0 : M.id,
|
|
1508
|
-
streamId:
|
|
1511
|
+
streamId: S == null ? void 0 : S.streamId,
|
|
1509
1512
|
mode: r.chatMode
|
|
1510
1513
|
}), q((M == null ? void 0 : M.chat_mode) ?? s);
|
|
1511
1514
|
}
|
|
1512
1515
|
async function R() {
|
|
1513
|
-
var l,
|
|
1514
|
-
(l = r.socketManager) == null || l.disconnect(), await ((
|
|
1516
|
+
var l, g, y, k;
|
|
1517
|
+
(l = r.socketManager) == null || l.disconnect(), await ((g = r.streamingManager) == null ? void 0 : g.disconnect()), delete r.streamingManager, delete r.socketManager, (k = (y = t.callbacks).onConnectionStateChange) == null || k.call(y, A.Disconnected);
|
|
1515
1518
|
}
|
|
1516
1519
|
async function q(l) {
|
|
1517
|
-
var
|
|
1518
|
-
l !== r.chatMode && (a.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !==
|
|
1520
|
+
var g, y;
|
|
1521
|
+
l !== r.chatMode && (a.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== T.Functional && await R(), (y = (g = t.callbacks).onModeChange) == null || y.call(g, l));
|
|
1519
1522
|
}
|
|
1520
1523
|
return {
|
|
1521
1524
|
agent: f,
|
|
@@ -1539,12 +1542,12 @@ async function Ln(e, t) {
|
|
|
1539
1542
|
},
|
|
1540
1543
|
async reconnect() {
|
|
1541
1544
|
const l = r.streamingManager;
|
|
1542
|
-
let
|
|
1545
|
+
let g;
|
|
1543
1546
|
if (w && (l != null && l.reconnect))
|
|
1544
1547
|
try {
|
|
1545
1548
|
await l.reconnect();
|
|
1546
1549
|
} catch (y) {
|
|
1547
|
-
|
|
1550
|
+
g = ge(y).kind, await R(), await Y(!1);
|
|
1548
1551
|
}
|
|
1549
1552
|
else
|
|
1550
1553
|
await R(), await Y(!1);
|
|
@@ -1552,7 +1555,7 @@ async function Ln(e, t) {
|
|
|
1552
1555
|
event: "reconnect",
|
|
1553
1556
|
mode: r.chatMode,
|
|
1554
1557
|
success: !0,
|
|
1555
|
-
...
|
|
1558
|
+
...g && { fallbackReason: g }
|
|
1556
1559
|
});
|
|
1557
1560
|
},
|
|
1558
1561
|
async disconnect() {
|
|
@@ -1562,44 +1565,44 @@ async function Ln(e, t) {
|
|
|
1562
1565
|
});
|
|
1563
1566
|
},
|
|
1564
1567
|
publishMicrophoneStream(l) {
|
|
1565
|
-
var
|
|
1566
|
-
return (
|
|
1568
|
+
var g;
|
|
1569
|
+
return (g = r.streamingManager) != null && g.publishMicrophoneStream ? r.streamingManager.publishMicrophoneStream(l) : Promise.reject(new Error("publishMicrophoneStream is not available for this streaming manager"));
|
|
1567
1570
|
},
|
|
1568
1571
|
unpublishMicrophoneStream() {
|
|
1569
1572
|
var l;
|
|
1570
1573
|
return (l = r.streamingManager) != null && l.unpublishMicrophoneStream ? r.streamingManager.unpublishMicrophoneStream() : Promise.resolve();
|
|
1571
1574
|
},
|
|
1572
1575
|
replaceMicrophoneTrack(l) {
|
|
1573
|
-
var
|
|
1574
|
-
return (
|
|
1576
|
+
var g;
|
|
1577
|
+
return (g = r.streamingManager) != null && g.replaceMicrophoneTrack ? r.streamingManager.replaceMicrophoneTrack(l) : Promise.reject(new Error("replaceMicrophoneTrack is not available for this streaming manager"));
|
|
1575
1578
|
},
|
|
1576
1579
|
publishCameraStream(l) {
|
|
1577
|
-
var
|
|
1578
|
-
return (
|
|
1580
|
+
var g;
|
|
1581
|
+
return (g = r.streamingManager) != null && g.publishCameraStream ? r.streamingManager.publishCameraStream(l) : Promise.reject(new Error("publishCameraStream is not available for this streaming manager"));
|
|
1579
1582
|
},
|
|
1580
1583
|
unpublishCameraStream() {
|
|
1581
1584
|
var l;
|
|
1582
1585
|
return (l = r.streamingManager) != null && l.unpublishCameraStream ? r.streamingManager.unpublishCameraStream() : Promise.resolve();
|
|
1583
1586
|
},
|
|
1584
1587
|
async chat(l) {
|
|
1585
|
-
var
|
|
1586
|
-
const
|
|
1588
|
+
var S, M, L, z, N;
|
|
1589
|
+
const g = () => {
|
|
1587
1590
|
if (Qe(s))
|
|
1588
|
-
throw new
|
|
1589
|
-
if (l.length >=
|
|
1590
|
-
throw new
|
|
1591
|
+
throw new $(`${s} is enabled, chat is disabled`);
|
|
1592
|
+
if (l.length >= be)
|
|
1593
|
+
throw new $(`Message cannot be more than ${be} characters`);
|
|
1591
1594
|
if (l.length === 0)
|
|
1592
|
-
throw new
|
|
1593
|
-
if (r.chatMode ===
|
|
1594
|
-
throw new
|
|
1595
|
-
if (![
|
|
1595
|
+
throw new $("Message cannot be empty");
|
|
1596
|
+
if (r.chatMode === T.Maintenance)
|
|
1597
|
+
throw new $("Chat is in maintenance mode");
|
|
1598
|
+
if (![T.TextOnly, T.Playground].includes(r.chatMode)) {
|
|
1596
1599
|
if (!r.streamingManager)
|
|
1597
|
-
throw new
|
|
1600
|
+
throw new $("Streaming manager is not initialized");
|
|
1598
1601
|
if (!r.chat)
|
|
1599
|
-
throw new
|
|
1602
|
+
throw new $("Chat is not initialized");
|
|
1600
1603
|
}
|
|
1601
1604
|
}, y = async () => {
|
|
1602
|
-
var h,
|
|
1605
|
+
var h, p;
|
|
1603
1606
|
if (!r.chat) {
|
|
1604
1607
|
const D = await nt(
|
|
1605
1608
|
f,
|
|
@@ -1610,11 +1613,11 @@ async function Ln(e, t) {
|
|
|
1610
1613
|
);
|
|
1611
1614
|
if (!D.chat)
|
|
1612
1615
|
throw new ot(r.chatMode, !!t.persistentChat);
|
|
1613
|
-
r.chat = D.chat, (
|
|
1616
|
+
r.chat = D.chat, (p = (h = t.callbacks).onNewChat) == null || p.call(h, r.chat.id);
|
|
1614
1617
|
}
|
|
1615
1618
|
return r.chat.id;
|
|
1616
|
-
},
|
|
1617
|
-
const D = r.chatMode ===
|
|
1619
|
+
}, k = async (h, p) => {
|
|
1620
|
+
const D = r.chatMode === T.Playground;
|
|
1618
1621
|
return ye(w && !D ? async () => {
|
|
1619
1622
|
var _, J;
|
|
1620
1623
|
return await ((J = (_ = r.streamingManager) == null ? void 0 : _.sendTextMessage) == null ? void 0 : J.call(_, l)), Promise.resolve({});
|
|
@@ -1622,7 +1625,7 @@ async function Ln(e, t) {
|
|
|
1622
1625
|
var _, J;
|
|
1623
1626
|
return u.chat(
|
|
1624
1627
|
f.id,
|
|
1625
|
-
|
|
1628
|
+
p,
|
|
1626
1629
|
{
|
|
1627
1630
|
chatMode: r.chatMode,
|
|
1628
1631
|
streamId: (_ = r.streamingManager) == null ? void 0 : _.streamId,
|
|
@@ -1647,74 +1650,79 @@ async function Ln(e, t) {
|
|
|
1647
1650
|
});
|
|
1648
1651
|
};
|
|
1649
1652
|
try {
|
|
1650
|
-
j(),
|
|
1653
|
+
j(), g(), r.messages.push({
|
|
1651
1654
|
id: ee(),
|
|
1652
1655
|
role: "user",
|
|
1653
1656
|
content: l,
|
|
1654
1657
|
parts: ae(l),
|
|
1655
1658
|
created_at: new Date(X.update()).toISOString()
|
|
1656
|
-
}), (M = (
|
|
1657
|
-
const h = await y(),
|
|
1658
|
-
return
|
|
1659
|
+
}), (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "user");
|
|
1660
|
+
const h = await y(), p = await k([...r.messages], h);
|
|
1661
|
+
return p.result && r.messages.push({
|
|
1659
1662
|
id: ee(),
|
|
1660
1663
|
role: "assistant",
|
|
1661
|
-
content:
|
|
1662
|
-
parts: ae(
|
|
1664
|
+
content: p.result,
|
|
1665
|
+
parts: ae(p.result),
|
|
1663
1666
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1664
|
-
context:
|
|
1665
|
-
matches:
|
|
1667
|
+
context: p.context,
|
|
1668
|
+
matches: p.matches
|
|
1666
1669
|
}), a.track("agent-message-send", {
|
|
1667
1670
|
event: "success",
|
|
1668
1671
|
messages: r.messages.length + 1
|
|
1669
|
-
}),
|
|
1672
|
+
}), p.result && ((z = (L = t.callbacks).onNewMessage) == null || z.call(L, [...r.messages], "answer"), a.track("agent-message-received", {
|
|
1670
1673
|
latency: X.get(!0),
|
|
1671
1674
|
messages: r.messages.length
|
|
1672
|
-
})),
|
|
1675
|
+
})), p;
|
|
1673
1676
|
} catch (h) {
|
|
1674
|
-
throw ((
|
|
1677
|
+
throw ((N = r.messages[r.messages.length - 1]) == null ? void 0 : N.role) === "assistant" && r.messages.pop(), a.track("agent-message-send", {
|
|
1675
1678
|
event: "error",
|
|
1676
1679
|
messages: r.messages.length,
|
|
1677
1680
|
error: ge(h)
|
|
1678
1681
|
}), h;
|
|
1679
1682
|
}
|
|
1680
1683
|
},
|
|
1681
|
-
rate(l,
|
|
1682
|
-
var M, L,
|
|
1683
|
-
const
|
|
1684
|
+
rate(l, g, y) {
|
|
1685
|
+
var M, L, z, N;
|
|
1686
|
+
const k = r.messages.find((h) => h.id === l);
|
|
1684
1687
|
if (r.chat) {
|
|
1685
|
-
if (!
|
|
1686
|
-
throw new
|
|
1687
|
-
} else throw new
|
|
1688
|
-
const
|
|
1688
|
+
if (!k)
|
|
1689
|
+
throw new $("Message not found");
|
|
1690
|
+
} else throw new $("Chat is not initialized");
|
|
1691
|
+
const S = ((M = k.matches) == null ? void 0 : M.map((h) => [h.document_id, h.id])) ?? [];
|
|
1689
1692
|
return a.track("agent-rate", {
|
|
1690
1693
|
event: y ? "update" : "create",
|
|
1691
|
-
thumb:
|
|
1694
|
+
thumb: g === 1 ? "up" : "down",
|
|
1692
1695
|
knowledge_id: ((L = f.knowledge) == null ? void 0 : L.id) ?? "",
|
|
1693
|
-
matches:
|
|
1694
|
-
score:
|
|
1696
|
+
matches: S,
|
|
1697
|
+
score: g
|
|
1695
1698
|
}), y ? u.updateRating(f.id, r.chat.id, y, {
|
|
1696
|
-
knowledge_id: ((
|
|
1699
|
+
knowledge_id: ((z = f.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1697
1700
|
message_id: l,
|
|
1698
|
-
matches:
|
|
1699
|
-
score:
|
|
1701
|
+
matches: S,
|
|
1702
|
+
score: g
|
|
1700
1703
|
}) : u.createRating(f.id, r.chat.id, {
|
|
1701
|
-
knowledge_id: ((
|
|
1704
|
+
knowledge_id: ((N = f.knowledge) == null ? void 0 : N.id) ?? "",
|
|
1702
1705
|
message_id: l,
|
|
1703
|
-
matches:
|
|
1704
|
-
score:
|
|
1706
|
+
matches: S,
|
|
1707
|
+
score: g
|
|
1705
1708
|
});
|
|
1706
1709
|
},
|
|
1707
1710
|
deleteRate(l) {
|
|
1708
1711
|
if (!r.chat)
|
|
1709
|
-
throw new
|
|
1712
|
+
throw new $("Chat is not initialized");
|
|
1710
1713
|
return a.track("agent-rate-delete", { type: "text" }), u.deleteRating(f.id, r.chat.id, l);
|
|
1711
1714
|
},
|
|
1715
|
+
submitFeedback(l, g) {
|
|
1716
|
+
if (!r.chat)
|
|
1717
|
+
throw new $("Chat is not initialized");
|
|
1718
|
+
return a.track("agent-feedback", { rating: l, hasAnswer: !!g }), u.submitFeedback(f.id, r.chat.id, { rating: l, answer: g });
|
|
1719
|
+
},
|
|
1712
1720
|
async speak(l) {
|
|
1713
|
-
var
|
|
1714
|
-
function
|
|
1721
|
+
var S, M, L;
|
|
1722
|
+
function g() {
|
|
1715
1723
|
if (typeof l == "string") {
|
|
1716
1724
|
if (!f.presenter.voice)
|
|
1717
|
-
throw new
|
|
1725
|
+
throw new $("Presenter voice is not initialized");
|
|
1718
1726
|
return {
|
|
1719
1727
|
type: "text",
|
|
1720
1728
|
provider: f.presenter.voice,
|
|
@@ -1724,37 +1732,38 @@ async function Ln(e, t) {
|
|
|
1724
1732
|
}
|
|
1725
1733
|
if (l.type === "text" && !l.provider) {
|
|
1726
1734
|
if (!f.presenter.voice)
|
|
1727
|
-
throw new
|
|
1735
|
+
throw new $("Presenter voice is not initialized");
|
|
1728
1736
|
return {
|
|
1729
1737
|
type: "text",
|
|
1730
1738
|
provider: f.presenter.voice,
|
|
1731
1739
|
input: l.input,
|
|
1732
|
-
ssml: l.ssml
|
|
1740
|
+
ssml: l.ssml,
|
|
1741
|
+
should_queue_speaks: l.should_queue_speaks
|
|
1733
1742
|
};
|
|
1734
1743
|
}
|
|
1735
1744
|
return l;
|
|
1736
1745
|
}
|
|
1737
|
-
const y =
|
|
1746
|
+
const y = g();
|
|
1738
1747
|
if (a.track("agent-speak", y), X.update(), r.messages && y.type === "text" && (r.messages.push({
|
|
1739
1748
|
id: ee(),
|
|
1740
1749
|
role: "assistant",
|
|
1741
1750
|
content: y.input,
|
|
1742
1751
|
parts: ae(y.input),
|
|
1743
1752
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1744
|
-
}), (M = (
|
|
1753
|
+
}), (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "answer")), bt(r.chatMode))
|
|
1745
1754
|
return {
|
|
1746
1755
|
duration: 0,
|
|
1747
1756
|
video_id: "",
|
|
1748
1757
|
status: "success"
|
|
1749
1758
|
};
|
|
1750
1759
|
if (!r.streamingManager)
|
|
1751
|
-
throw new
|
|
1760
|
+
throw new $("Please connect to the agent first");
|
|
1752
1761
|
return r.streamingManager.speak({
|
|
1753
1762
|
script: y,
|
|
1754
1763
|
metadata: { chat_id: (L = r.chat) == null ? void 0 : L.id, agent_id: f.id }
|
|
1755
1764
|
});
|
|
1756
1765
|
},
|
|
1757
|
-
interrupt:
|
|
1766
|
+
interrupt: b,
|
|
1758
1767
|
registerClientTool: H,
|
|
1759
1768
|
unregisterClientTool: V
|
|
1760
1769
|
};
|
|
@@ -1762,7 +1771,7 @@ async function Ln(e, t) {
|
|
|
1762
1771
|
export {
|
|
1763
1772
|
ie as A,
|
|
1764
1773
|
G as B,
|
|
1765
|
-
|
|
1774
|
+
F as C,
|
|
1766
1775
|
yt as D,
|
|
1767
1776
|
Ke as H,
|
|
1768
1777
|
wt as K,
|
|
@@ -1770,9 +1779,9 @@ export {
|
|
|
1770
1779
|
mt as P,
|
|
1771
1780
|
gt as R,
|
|
1772
1781
|
x as S,
|
|
1773
|
-
|
|
1782
|
+
Se as T,
|
|
1774
1783
|
ft as U,
|
|
1775
|
-
|
|
1784
|
+
$ as V,
|
|
1776
1785
|
ut as W,
|
|
1777
1786
|
tn as a,
|
|
1778
1787
|
W as b,
|
|
@@ -1783,21 +1792,21 @@ export {
|
|
|
1783
1792
|
re as g,
|
|
1784
1793
|
fn as h,
|
|
1785
1794
|
Pn as i,
|
|
1786
|
-
|
|
1795
|
+
C as j,
|
|
1787
1796
|
ht as k,
|
|
1788
1797
|
X as l,
|
|
1789
1798
|
ot as m,
|
|
1790
1799
|
xn as n,
|
|
1791
|
-
|
|
1800
|
+
T as o,
|
|
1792
1801
|
ct as p,
|
|
1793
1802
|
vt as q,
|
|
1794
1803
|
Jt as r,
|
|
1795
1804
|
pt as s,
|
|
1796
1805
|
ge as t,
|
|
1797
1806
|
He as u,
|
|
1798
|
-
|
|
1807
|
+
kt as v,
|
|
1799
1808
|
Ln as w,
|
|
1800
|
-
|
|
1809
|
+
Tn as x,
|
|
1801
1810
|
An as y,
|
|
1802
1811
|
At as z
|
|
1803
1812
|
};
|