@d-id/client-sdk 1.1.61-staging.286 → 1.1.61-staging.287
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +139 -140
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var Et = Object.defineProperty;
|
|
2
2
|
var kt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
|
-
var
|
|
3
|
+
var ve = (e, n, i) => kt(e, typeof n != "symbol" ? n + "" : n, i);
|
|
4
4
|
class Ie extends Error {
|
|
5
5
|
constructor({ kind: i, description: r, error: s }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: r }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
ve(this, "kind");
|
|
8
|
+
ve(this, "description");
|
|
9
|
+
ve(this, "error");
|
|
10
10
|
this.kind = i, this.description = r, this.error = s;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -26,7 +26,7 @@ class It extends Ie {
|
|
|
26
26
|
class me extends Ie {
|
|
27
27
|
constructor(i, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
ve(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -36,7 +36,7 @@ class Dt extends Ie {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
var _t = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_t || {}), At = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(At || {}), bt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(bt || {}), Lt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Lt || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pt || {}), xt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xt || {}), $t = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))($t || {}), dt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(dt || {});
|
|
39
|
-
const
|
|
39
|
+
const Hn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -50,7 +50,7 @@ const qn = (e) => {
|
|
|
50
50
|
};
|
|
51
51
|
var k = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(k || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), R = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(R || {}), x = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(x || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ne = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ne || {}), jt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(jt || {}), Bt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Bt || {});
|
|
52
52
|
const Ft = 45 * 1e3, Nt = "X-Playground-Chat", Ee = "https://api.d-id.com", Kt = "wss://notifications.d-id.com", zt = "79f81a83a67430be2bc0fd61042b8faa", Vt = (...e) => {
|
|
53
|
-
}, ut = (e) => new Promise((n) => setTimeout(n, e)),
|
|
53
|
+
}, ut = (e) => new Promise((n) => setTimeout(n, e)), Te = (e = 16) => {
|
|
54
54
|
const n = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
56
|
}, lt = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ut = (e) => {
|
|
@@ -142,22 +142,21 @@ function $e(e) {
|
|
|
142
142
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
143
143
|
let n = window.localStorage.getItem("did_external_key_id");
|
|
144
144
|
if (!n) {
|
|
145
|
-
let i =
|
|
145
|
+
let i = Te();
|
|
146
146
|
window.localStorage.setItem("did_external_key_id", i), n = i;
|
|
147
147
|
}
|
|
148
148
|
return n;
|
|
149
149
|
}
|
|
150
|
-
let qt = ge();
|
|
151
150
|
function mt(e, n) {
|
|
152
151
|
if (e.type === "bearer")
|
|
153
152
|
return `Bearer ${e.token}`;
|
|
154
153
|
if (e.type === "basic")
|
|
155
154
|
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
156
155
|
if (e.type === "key")
|
|
157
|
-
return `Client-Key ${e.clientKey}.${$e(n)}
|
|
156
|
+
return `Client-Key ${e.clientKey}.${$e(n)}`;
|
|
158
157
|
throw new Error(`Unknown auth type: ${e}`);
|
|
159
158
|
}
|
|
160
|
-
const
|
|
159
|
+
const qt = (e) => xe(e, {
|
|
161
160
|
limit: 3,
|
|
162
161
|
delayMs: 1e3,
|
|
163
162
|
timeout: 0,
|
|
@@ -165,7 +164,7 @@ const Qt = (e) => xe(e, {
|
|
|
165
164
|
});
|
|
166
165
|
function ze(e, n = Ee, i, r) {
|
|
167
166
|
const s = async (a, o) => {
|
|
168
|
-
const { skipErrorHandler: c, ...t } = o || {}, d = await
|
|
167
|
+
const { skipErrorHandler: c, ...t } = o || {}, d = await qt(
|
|
169
168
|
() => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
170
169
|
...t,
|
|
171
170
|
headers: {
|
|
@@ -197,7 +196,7 @@ function ze(e, n = Ee, i, r) {
|
|
|
197
196
|
}
|
|
198
197
|
};
|
|
199
198
|
}
|
|
200
|
-
function
|
|
199
|
+
function Qt(e, n = Ee, i, r) {
|
|
201
200
|
const s = ze(e, `${n}/agents`, i, r);
|
|
202
201
|
return {
|
|
203
202
|
create(a, o) {
|
|
@@ -235,7 +234,7 @@ function Xt(e, n = Ee, i, r) {
|
|
|
235
234
|
}
|
|
236
235
|
};
|
|
237
236
|
}
|
|
238
|
-
function
|
|
237
|
+
function Xt(e) {
|
|
239
238
|
var s, a, o, c;
|
|
240
239
|
const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
241
240
|
const t = navigator.platform;
|
|
@@ -253,7 +252,7 @@ function Yt(e) {
|
|
|
253
252
|
}
|
|
254
253
|
};
|
|
255
254
|
}
|
|
256
|
-
function
|
|
255
|
+
function Yt(e) {
|
|
257
256
|
var i, r, s, a, o, c;
|
|
258
257
|
const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
259
258
|
return {
|
|
@@ -278,8 +277,8 @@ function Gt(e) {
|
|
|
278
277
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
279
278
|
};
|
|
280
279
|
}
|
|
281
|
-
const
|
|
282
|
-
function
|
|
280
|
+
const Gt = (e) => e.reduce((n, i) => n + i, 0), et = (e) => Gt(e) / e.length;
|
|
281
|
+
function Zt(e, n, i) {
|
|
283
282
|
var t, d, h;
|
|
284
283
|
const { event: r, ...s } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: o } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
|
|
285
284
|
return {
|
|
@@ -293,8 +292,8 @@ function en(e, n, i) {
|
|
|
293
292
|
function tt(e) {
|
|
294
293
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
295
294
|
}
|
|
296
|
-
const
|
|
297
|
-
function
|
|
295
|
+
const en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
296
|
+
function tn(e) {
|
|
298
297
|
const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
|
|
299
298
|
return {
|
|
300
299
|
token: e.token || "testKey",
|
|
@@ -305,7 +304,7 @@ function nn(e) {
|
|
|
305
304
|
...e.mixpanelAdditionalProperties || {}
|
|
306
305
|
},
|
|
307
306
|
isEnabled: e.isEnabled ?? !0,
|
|
308
|
-
getRandom:
|
|
307
|
+
getRandom: Te,
|
|
309
308
|
enrich(r) {
|
|
310
309
|
this.additionalProperties = { ...this.additionalProperties, ...r };
|
|
311
310
|
},
|
|
@@ -338,7 +337,7 @@ function nn(e) {
|
|
|
338
337
|
])
|
|
339
338
|
})
|
|
340
339
|
};
|
|
341
|
-
return fetch(
|
|
340
|
+
return fetch(en, d).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
|
|
342
341
|
},
|
|
343
342
|
linkTrack(r, s, a, o) {
|
|
344
343
|
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), o.includes(a) || o.push(a);
|
|
@@ -376,10 +375,10 @@ async function ht(e, n, i, r, s = !1, a) {
|
|
|
376
375
|
mode: r
|
|
377
376
|
})), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
|
|
378
377
|
} catch (o) {
|
|
379
|
-
throw
|
|
378
|
+
throw nn(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
380
379
|
}
|
|
381
380
|
}
|
|
382
|
-
const
|
|
381
|
+
const nn = (e) => {
|
|
383
382
|
try {
|
|
384
383
|
const n = JSON.parse(e.message);
|
|
385
384
|
return n == null ? void 0 : n.kind;
|
|
@@ -387,10 +386,10 @@ const rn = (e) => {
|
|
|
387
386
|
return "UnknownError";
|
|
388
387
|
}
|
|
389
388
|
};
|
|
390
|
-
function
|
|
389
|
+
function rn(e) {
|
|
391
390
|
return e && e.length > 0 ? e : [];
|
|
392
391
|
}
|
|
393
|
-
function
|
|
392
|
+
function an(e, n, i, r) {
|
|
394
393
|
const s = ze(e, `${n}/v2/agents/${i}`, r);
|
|
395
394
|
return {
|
|
396
395
|
async createStream(a) {
|
|
@@ -398,11 +397,11 @@ function on(e, n, i, r) {
|
|
|
398
397
|
}
|
|
399
398
|
};
|
|
400
399
|
}
|
|
401
|
-
const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""),
|
|
400
|
+
const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), on = {
|
|
402
401
|
[R.ChatAnswer]: X.Answer,
|
|
403
402
|
[R.ChatPartial]: X.Partial
|
|
404
403
|
};
|
|
405
|
-
function
|
|
404
|
+
function sn(e, n, i) {
|
|
406
405
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
407
406
|
return {
|
|
408
407
|
duration: r,
|
|
@@ -422,7 +421,7 @@ function cn(e, n, i) {
|
|
|
422
421
|
lowFpsCount: i
|
|
423
422
|
};
|
|
424
423
|
}
|
|
425
|
-
function
|
|
424
|
+
function cn(e) {
|
|
426
425
|
return e.filter(
|
|
427
426
|
(n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0
|
|
428
427
|
).map((n) => {
|
|
@@ -433,7 +432,7 @@ function dn(e) {
|
|
|
433
432
|
};
|
|
434
433
|
});
|
|
435
434
|
}
|
|
436
|
-
function
|
|
435
|
+
function dn(e) {
|
|
437
436
|
let n = "", i = 0;
|
|
438
437
|
for (const r of e.values()) {
|
|
439
438
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (n = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -515,14 +514,14 @@ function rt(e, n, i) {
|
|
|
515
514
|
framesPerSecond: t.framesPerSecond,
|
|
516
515
|
freezeCount: t.freezeCount - e[d - 1].freezeCount,
|
|
517
516
|
freezeDuration: t.freezeDuration - e[d - 1].freezeDuration
|
|
518
|
-
}), s =
|
|
517
|
+
}), s = cn(r), a = s.reduce((t, d) => t + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), c = r.filter((t) => !!t.rtt).map((t) => t.rtt);
|
|
519
518
|
return {
|
|
520
519
|
webRTCStats: {
|
|
521
520
|
anomalies: s,
|
|
522
521
|
minRtt: Math.min(...c),
|
|
523
522
|
avgRtt: et(c),
|
|
524
523
|
maxRtt: Math.max(...c),
|
|
525
|
-
aggregateReport:
|
|
524
|
+
aggregateReport: sn(e[0], e[e.length - 1], a),
|
|
526
525
|
minJitterDelayInInterval: Math.min(...o),
|
|
527
526
|
maxJitterDelayInInterval: Math.max(...o),
|
|
528
527
|
avgJitterDelayInInterval: et(o)
|
|
@@ -537,25 +536,25 @@ function wt(e, n) {
|
|
|
537
536
|
return i;
|
|
538
537
|
return null;
|
|
539
538
|
}
|
|
540
|
-
const
|
|
541
|
-
function
|
|
539
|
+
const Ce = 10;
|
|
540
|
+
function un(e, n) {
|
|
542
541
|
let i = !1, r = !1, s = null, a = 0, o = 0, c = {};
|
|
543
542
|
async function t() {
|
|
544
543
|
if (i) {
|
|
545
544
|
try {
|
|
546
545
|
const d = await e();
|
|
547
546
|
if (!d) {
|
|
548
|
-
s = setTimeout(t,
|
|
547
|
+
s = setTimeout(t, Ce);
|
|
549
548
|
return;
|
|
550
549
|
}
|
|
551
550
|
const h = wt(d, "audio");
|
|
552
551
|
if (!h) {
|
|
553
|
-
s = setTimeout(t,
|
|
552
|
+
s = setTimeout(t, Ce);
|
|
554
553
|
return;
|
|
555
554
|
}
|
|
556
555
|
const g = h.totalAudioEnergy ?? 0, l = h.totalSamplesReceived ?? 0;
|
|
557
556
|
if (!r) {
|
|
558
|
-
a = g, o = l, r = !0, s = setTimeout(t,
|
|
557
|
+
a = g, o = l, r = !0, s = setTimeout(t, Ce);
|
|
559
558
|
return;
|
|
560
559
|
}
|
|
561
560
|
const p = g - a, D = l - o;
|
|
@@ -565,20 +564,20 @@ function ln(e, n) {
|
|
|
565
564
|
}
|
|
566
565
|
} catch {
|
|
567
566
|
}
|
|
568
|
-
i && (s = setTimeout(t,
|
|
567
|
+
i && (s = setTimeout(t, Ce));
|
|
569
568
|
}
|
|
570
569
|
}
|
|
571
570
|
return {
|
|
572
571
|
arm(d = {}) {
|
|
573
|
-
c = d, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t,
|
|
572
|
+
c = d, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t, Ce);
|
|
574
573
|
},
|
|
575
574
|
destroy() {
|
|
576
575
|
i = !1, s !== null && (clearTimeout(s), s = null);
|
|
577
576
|
}
|
|
578
577
|
};
|
|
579
578
|
}
|
|
580
|
-
const Me = 100,
|
|
581
|
-
function
|
|
579
|
+
const Me = 100, ln = Math.max(Math.ceil(400 / Me), 1), fn = 0.25, mn = 0.28;
|
|
580
|
+
function gn() {
|
|
582
581
|
let e = 0, n, i, r = 0;
|
|
583
582
|
return (s) => {
|
|
584
583
|
const a = wt(s, "video");
|
|
@@ -596,15 +595,15 @@ function hn() {
|
|
|
596
595
|
}
|
|
597
596
|
function yt(e, n, i, r, s) {
|
|
598
597
|
let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0, p = 0;
|
|
599
|
-
const D =
|
|
598
|
+
const D = gn();
|
|
600
599
|
async function N() {
|
|
601
600
|
const B = await e();
|
|
602
601
|
if (!B)
|
|
603
602
|
return;
|
|
604
|
-
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: M } = D(B), Y =
|
|
603
|
+
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: M } = D(B), Y = dn(B);
|
|
605
604
|
if (F)
|
|
606
|
-
t = 0, l = M - p, g = I <
|
|
607
|
-
else if (d && (t++, t >=
|
|
605
|
+
t = 0, l = M - p, g = I < fn ? ae.Strong : I > mn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, p += l, l = 0), d || (r == null || r(k.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
|
|
606
|
+
else if (d && (t++, t >= ln)) {
|
|
608
607
|
const Q = rt(o, Me, c);
|
|
609
608
|
r == null || r(k.Stop, Q), n() || i(), p = M, d = !1;
|
|
610
609
|
}
|
|
@@ -620,7 +619,7 @@ function yt(e, n, i, r, s) {
|
|
|
620
619
|
};
|
|
621
620
|
}
|
|
622
621
|
const it = 2e4;
|
|
623
|
-
async function
|
|
622
|
+
async function hn() {
|
|
624
623
|
try {
|
|
625
624
|
return await import("./livekit-client.esm-RGXA_gNu.js");
|
|
626
625
|
} catch {
|
|
@@ -629,13 +628,13 @@ async function pn() {
|
|
|
629
628
|
);
|
|
630
629
|
}
|
|
631
630
|
}
|
|
632
|
-
const
|
|
631
|
+
const pn = {
|
|
633
632
|
excellent: ae.Strong,
|
|
634
633
|
good: ae.Strong,
|
|
635
634
|
poor: ae.Weak,
|
|
636
635
|
lost: ae.Unknown,
|
|
637
636
|
unknown: ae.Unknown
|
|
638
|
-
},
|
|
637
|
+
}, Se = JSON.stringify({
|
|
639
638
|
kind: "InternalServerError",
|
|
640
639
|
description: "Stream Error"
|
|
641
640
|
});
|
|
@@ -644,9 +643,9 @@ function Be(e, n, i) {
|
|
|
644
643
|
var r, s;
|
|
645
644
|
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, x.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
|
|
646
645
|
}
|
|
647
|
-
async function
|
|
646
|
+
async function wn(e, n, i) {
|
|
648
647
|
var Je;
|
|
649
|
-
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await
|
|
648
|
+
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await hn(), { callbacks: t, auth: d, baseURL: h, analytics: g } = i;
|
|
650
649
|
let l = null, p = !1;
|
|
651
650
|
const D = se.Fluent;
|
|
652
651
|
let N = null;
|
|
@@ -658,7 +657,7 @@ async function yn(e, n, i) {
|
|
|
658
657
|
dynacast: !0
|
|
659
658
|
});
|
|
660
659
|
let U = null, te = W.Idle, ne = !0;
|
|
661
|
-
const $ =
|
|
660
|
+
const $ = an(d, h || Ee, e, t.onError);
|
|
662
661
|
let K, H, re, de = !0;
|
|
663
662
|
try {
|
|
664
663
|
const u = await $.createStream({
|
|
@@ -713,7 +712,7 @@ async function yn(e, n, i) {
|
|
|
713
712
|
}
|
|
714
713
|
function C(u, m) {
|
|
715
714
|
var w;
|
|
716
|
-
r("Connection quality:", u), m != null && m.isLocal && ((w = t.onConnectivityStateChange) == null || w.call(t,
|
|
715
|
+
r("Connection quality:", u), m != null && m.isLocal && ((w = t.onConnectivityStateChange) == null || w.call(t, pn[u]));
|
|
717
716
|
}
|
|
718
717
|
function T(u) {
|
|
719
718
|
r("Participant connected:", u.identity);
|
|
@@ -737,17 +736,17 @@ async function yn(e, n, i) {
|
|
|
737
736
|
r(`No mediaStreamTrack available for ${u.kind}`);
|
|
738
737
|
return;
|
|
739
738
|
}
|
|
740
|
-
N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (M =
|
|
739
|
+
N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (M = un(
|
|
741
740
|
() => u.getRTCStatsReport(),
|
|
742
741
|
({ sttLatency: V, serviceLatency: ie }) => {
|
|
743
742
|
var Oe, We, He;
|
|
744
|
-
const
|
|
745
|
-
let
|
|
743
|
+
const we = oe.get(!0);
|
|
744
|
+
let ye = 0;
|
|
746
745
|
if (V) {
|
|
747
746
|
const qe = ((We = (Oe = I == null ? void 0 : I.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
|
|
748
|
-
|
|
747
|
+
ye = qe > 0 ? Math.round(qe * 1e3) : 0;
|
|
749
748
|
}
|
|
750
|
-
const fe =
|
|
749
|
+
const fe = we > 0 ? we + (V ?? 0) + ye : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
|
|
751
750
|
(He = t.onFirstAudioDetected) == null || He.call(t, { latency: fe, networkLatency: ce });
|
|
752
751
|
}
|
|
753
752
|
)), u.kind === "video" && ((b = t.onStreamReady) == null || b.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, x.Connected, "livekit:track-subscribed")), I = yt(
|
|
@@ -764,7 +763,7 @@ async function yn(e, n, i) {
|
|
|
764
763
|
}
|
|
765
764
|
function v(u, m) {
|
|
766
765
|
var S;
|
|
767
|
-
const w =
|
|
766
|
+
const w = on[u];
|
|
768
767
|
w && ((S = t.onMessage) == null || S.call(t, w, { event: w, ...m }));
|
|
769
768
|
}
|
|
770
769
|
function E(u, m) {
|
|
@@ -798,7 +797,7 @@ async function yn(e, n, i) {
|
|
|
798
797
|
name: m.metadata.sentiment.sentiment
|
|
799
798
|
}), (ie = t.onMessage) == null || ie.call(t, u, b), j(u, m);
|
|
800
799
|
}
|
|
801
|
-
function
|
|
800
|
+
function ge(u, m) {
|
|
802
801
|
var w;
|
|
803
802
|
(w = t.onMessage) == null || w.call(t, X.Transcribe, { event: X.Transcribe, ...m }), queueMicrotask(() => {
|
|
804
803
|
var S;
|
|
@@ -815,7 +814,7 @@ async function yn(e, n, i) {
|
|
|
815
814
|
[R.StreamVideoDone]: G,
|
|
816
815
|
[R.StreamVideoError]: G,
|
|
817
816
|
[R.StreamVideoRejected]: G,
|
|
818
|
-
[R.ChatAudioTranscribed]:
|
|
817
|
+
[R.ChatAudioTranscribed]: ge
|
|
819
818
|
};
|
|
820
819
|
function z(u, m, w, S) {
|
|
821
820
|
const b = new TextDecoder().decode(u);
|
|
@@ -830,11 +829,11 @@ async function yn(e, n, i) {
|
|
|
830
829
|
}
|
|
831
830
|
function ee(u) {
|
|
832
831
|
var m;
|
|
833
|
-
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
832
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Se), { sessionId: K });
|
|
834
833
|
}
|
|
835
834
|
function De(u) {
|
|
836
835
|
var m;
|
|
837
|
-
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
836
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Se), { sessionId: K });
|
|
838
837
|
}
|
|
839
838
|
function le(u, m, w) {
|
|
840
839
|
r("Track subscription failed:", { trackSid: u, participant: m, reason: w });
|
|
@@ -848,8 +847,8 @@ async function yn(e, n, i) {
|
|
|
848
847
|
}
|
|
849
848
|
return null;
|
|
850
849
|
}
|
|
851
|
-
async function
|
|
852
|
-
var
|
|
850
|
+
async function he(u, m, w, S, b, P) {
|
|
851
|
+
var we, ye, fe;
|
|
853
852
|
if (!p || !l)
|
|
854
853
|
throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
|
|
855
854
|
if (u.isPublishing) {
|
|
@@ -863,7 +862,7 @@ async function yn(e, n, i) {
|
|
|
863
862
|
if (ie) {
|
|
864
863
|
r(`${S} track is already published, skipping`, {
|
|
865
864
|
trackId: V.id,
|
|
866
|
-
publishedTrackId: (
|
|
865
|
+
publishedTrackId: (ye = (we = ie.track) == null ? void 0 : we.mediaStreamTrack) == null ? void 0 : ye.id
|
|
867
866
|
}), u.publication = ie;
|
|
868
867
|
return;
|
|
869
868
|
}
|
|
@@ -880,7 +879,7 @@ async function yn(e, n, i) {
|
|
|
880
879
|
u.isPublishing = !1;
|
|
881
880
|
}
|
|
882
881
|
}
|
|
883
|
-
async function
|
|
882
|
+
async function pe(u, m) {
|
|
884
883
|
if (!(!u.publication || !u.publication.track))
|
|
885
884
|
try {
|
|
886
885
|
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${m} track unpublished`));
|
|
@@ -891,7 +890,7 @@ async function yn(e, n, i) {
|
|
|
891
890
|
}
|
|
892
891
|
}
|
|
893
892
|
async function vt(u) {
|
|
894
|
-
return
|
|
893
|
+
return he(
|
|
895
894
|
B,
|
|
896
895
|
u,
|
|
897
896
|
(m) => m.getAudioTracks(),
|
|
@@ -901,10 +900,10 @@ async function yn(e, n, i) {
|
|
|
901
900
|
);
|
|
902
901
|
}
|
|
903
902
|
async function _e() {
|
|
904
|
-
return
|
|
903
|
+
return pe(B, "Microphone");
|
|
905
904
|
}
|
|
906
905
|
async function Ct(u) {
|
|
907
|
-
return
|
|
906
|
+
return he(
|
|
908
907
|
F,
|
|
909
908
|
u,
|
|
910
909
|
(m) => m.getVideoTracks(),
|
|
@@ -914,7 +913,7 @@ async function yn(e, n, i) {
|
|
|
914
913
|
);
|
|
915
914
|
}
|
|
916
915
|
async function Ae() {
|
|
917
|
-
return
|
|
916
|
+
return pe(F, "Camera");
|
|
918
917
|
}
|
|
919
918
|
function St() {
|
|
920
919
|
N && (N.getTracks().forEach((u) => u.stop()), N = null);
|
|
@@ -922,7 +921,7 @@ async function yn(e, n, i) {
|
|
|
922
921
|
async function be(u, m) {
|
|
923
922
|
var w, S;
|
|
924
923
|
if (!p || !l) {
|
|
925
|
-
r("Room is not connected for sending messages"), (w = t.onError) == null || w.call(t, new Error(
|
|
924
|
+
r("Room is not connected for sending messages"), (w = t.onError) == null || w.call(t, new Error(Se), {
|
|
926
925
|
sessionId: K
|
|
927
926
|
});
|
|
928
927
|
return;
|
|
@@ -930,7 +929,7 @@ async function yn(e, n, i) {
|
|
|
930
929
|
try {
|
|
931
930
|
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
932
931
|
} catch (b) {
|
|
933
|
-
r("Failed to send message:", b), (S = t.onError) == null || S.call(t, new Error(
|
|
932
|
+
r("Failed to send message:", b), (S = t.onError) == null || S.call(t, new Error(Se), { sessionId: K });
|
|
934
933
|
}
|
|
935
934
|
}
|
|
936
935
|
async function Tt(u) {
|
|
@@ -939,7 +938,7 @@ async function yn(e, n, i) {
|
|
|
939
938
|
const S = JSON.parse(u).topic;
|
|
940
939
|
return be("", S);
|
|
941
940
|
} catch (w) {
|
|
942
|
-
r("Failed to send data channel message:", w), (m = t.onError) == null || m.call(t, new Error(
|
|
941
|
+
r("Failed to send data channel message:", w), (m = t.onError) == null || m.call(t, new Error(Se), { sessionId: K });
|
|
943
942
|
}
|
|
944
943
|
}
|
|
945
944
|
function Rt(u) {
|
|
@@ -1008,13 +1007,13 @@ async function yn(e, n, i) {
|
|
|
1008
1007
|
isInterruptible: ne
|
|
1009
1008
|
};
|
|
1010
1009
|
}
|
|
1011
|
-
const
|
|
1010
|
+
const yn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1012
1011
|
__proto__: null,
|
|
1013
1012
|
DataChannelTopic: Ue,
|
|
1014
|
-
createLiveKitStreamingManager:
|
|
1013
|
+
createLiveKitStreamingManager: wn,
|
|
1015
1014
|
handleInitError: Be
|
|
1016
1015
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1017
|
-
function
|
|
1016
|
+
function vn(e, n, i) {
|
|
1018
1017
|
if (!e)
|
|
1019
1018
|
throw new Error("Please connect to the agent first");
|
|
1020
1019
|
if (!e.interruptAvailable)
|
|
@@ -1024,7 +1023,7 @@ function Cn(e, n, i) {
|
|
|
1024
1023
|
if (!i)
|
|
1025
1024
|
throw new Error("No active video to interrupt");
|
|
1026
1025
|
}
|
|
1027
|
-
async function
|
|
1026
|
+
async function Cn(e, n) {
|
|
1028
1027
|
const i = {
|
|
1029
1028
|
type: R.StreamInterrupt,
|
|
1030
1029
|
videoId: n,
|
|
@@ -1032,13 +1031,13 @@ async function Sn(e, n) {
|
|
|
1032
1031
|
};
|
|
1033
1032
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
1034
1033
|
}
|
|
1035
|
-
async function
|
|
1034
|
+
async function Sn(e) {
|
|
1036
1035
|
const n = {
|
|
1037
1036
|
topic: Ue.Interrupt
|
|
1038
1037
|
};
|
|
1039
1038
|
e.sendDataChannelMessage(JSON.stringify(n));
|
|
1040
1039
|
}
|
|
1041
|
-
function
|
|
1040
|
+
function Tn(e) {
|
|
1042
1041
|
return new Promise((n, i) => {
|
|
1043
1042
|
const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage: c = null, onOpen: t = null, onClose: d = null, onError: h = null } = r || {}, g = new WebSocket(`${s}?authorization=${encodeURIComponent(mt(a, o))}`);
|
|
1044
1043
|
g.onmessage = c, g.onclose = d, g.onerror = (l) => {
|
|
@@ -1048,12 +1047,12 @@ function Rn(e) {
|
|
|
1048
1047
|
};
|
|
1049
1048
|
});
|
|
1050
1049
|
}
|
|
1051
|
-
async function
|
|
1050
|
+
async function Rn(e) {
|
|
1052
1051
|
const { retries: n = 1 } = e;
|
|
1053
1052
|
let i = null;
|
|
1054
1053
|
for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
|
|
1055
1054
|
try {
|
|
1056
|
-
i = await
|
|
1055
|
+
i = await Tn(e);
|
|
1057
1056
|
} catch (s) {
|
|
1058
1057
|
if (r === n)
|
|
1059
1058
|
throw s;
|
|
@@ -1061,8 +1060,8 @@ async function En(e) {
|
|
|
1061
1060
|
}
|
|
1062
1061
|
return i;
|
|
1063
1062
|
}
|
|
1064
|
-
async function
|
|
1065
|
-
const s = i != null && i.onMessage ? [i.onMessage] : [], a = await
|
|
1063
|
+
async function En(e, n, i, r) {
|
|
1064
|
+
const s = i != null && i.onMessage ? [i.onMessage] : [], a = await Rn({
|
|
1066
1065
|
auth: e,
|
|
1067
1066
|
host: n,
|
|
1068
1067
|
externalId: r,
|
|
@@ -1083,7 +1082,7 @@ async function kn(e, n, i, r) {
|
|
|
1083
1082
|
subscribeToEvents: (o) => s.push(o)
|
|
1084
1083
|
};
|
|
1085
1084
|
}
|
|
1086
|
-
function
|
|
1085
|
+
function kn(e) {
|
|
1087
1086
|
if (e.answer !== void 0)
|
|
1088
1087
|
return e.answer;
|
|
1089
1088
|
let n = 0, i = "";
|
|
@@ -1091,7 +1090,7 @@ function Mn(e) {
|
|
|
1091
1090
|
i += e[n++];
|
|
1092
1091
|
return i;
|
|
1093
1092
|
}
|
|
1094
|
-
function
|
|
1093
|
+
function Mn(e, n, i) {
|
|
1095
1094
|
if (!e.content)
|
|
1096
1095
|
return;
|
|
1097
1096
|
const r = n.messages[n.messages.length - 1];
|
|
@@ -1106,9 +1105,9 @@ function In(e, n, i) {
|
|
|
1106
1105
|
};
|
|
1107
1106
|
n.messages.push(s), i == null || i([...n.messages], "user");
|
|
1108
1107
|
}
|
|
1109
|
-
function
|
|
1108
|
+
function In(e, n, i, r, s, a) {
|
|
1110
1109
|
if (e === X.Transcribe && n.content) {
|
|
1111
|
-
|
|
1110
|
+
Mn(n, r, s);
|
|
1112
1111
|
return;
|
|
1113
1112
|
}
|
|
1114
1113
|
if (!(e === X.Partial || e === X.Answer))
|
|
@@ -1129,10 +1128,10 @@ function Dn(e, n, i, r, s, a) {
|
|
|
1129
1128
|
return;
|
|
1130
1129
|
const { content: d, sequence: h } = n;
|
|
1131
1130
|
e === X.Partial ? i[h] = d : i.answer = d;
|
|
1132
|
-
const g =
|
|
1131
|
+
const g = kn(i);
|
|
1133
1132
|
(t.content !== g || e === X.Answer) && (t.content = g, t.parts = Re(g), s == null || s([...r.messages], e));
|
|
1134
1133
|
}
|
|
1135
|
-
function
|
|
1134
|
+
function Dn(e, n, i, r, s) {
|
|
1136
1135
|
let a = {};
|
|
1137
1136
|
const o = () => a = {};
|
|
1138
1137
|
let c = "answer";
|
|
@@ -1146,13 +1145,13 @@ function _n(e, n, i, r, s) {
|
|
|
1146
1145
|
var g, l;
|
|
1147
1146
|
if ("content" in h) {
|
|
1148
1147
|
const p = d === R.ChatAnswer ? X.Answer : d === R.ChatAudioTranscribed ? X.Transcribe : d;
|
|
1149
|
-
|
|
1148
|
+
In(p, h, a, n, t, o), p === X.Answer && e.track("agent-message-received", {
|
|
1150
1149
|
content: h.content,
|
|
1151
1150
|
messages: n.messages.length,
|
|
1152
1151
|
mode: n.chatMode
|
|
1153
1152
|
});
|
|
1154
1153
|
} else {
|
|
1155
|
-
const p = R, D = [p.StreamVideoDone, p.StreamVideoError, p.StreamVideoRejected], N = [p.StreamFailed, p.StreamVideoError, p.StreamVideoRejected], B =
|
|
1154
|
+
const p = R, D = [p.StreamVideoDone, p.StreamVideoError, p.StreamVideoRejected], N = [p.StreamFailed, p.StreamVideoError, p.StreamVideoRejected], B = Zt(h, r, { mode: n.chatMode });
|
|
1156
1155
|
if (d = d, d === p.StreamVideoCreated && (e.linkTrack("agent-video", B, p.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1157
1156
|
const F = n.messages[n.messages.length - 1];
|
|
1158
1157
|
if ((F == null ? void 0 : F.role) === "assistant") {
|
|
@@ -1169,7 +1168,7 @@ function _n(e, n, i, r, s) {
|
|
|
1169
1168
|
}
|
|
1170
1169
|
};
|
|
1171
1170
|
}
|
|
1172
|
-
function
|
|
1171
|
+
function _n(e, n, i, r) {
|
|
1173
1172
|
const s = ze(e, `${n}/agents/${i}`, r);
|
|
1174
1173
|
return {
|
|
1175
1174
|
createStream(a, o) {
|
|
@@ -1206,7 +1205,7 @@ function An(e, n, i, r) {
|
|
|
1206
1205
|
}
|
|
1207
1206
|
};
|
|
1208
1207
|
}
|
|
1209
|
-
const
|
|
1208
|
+
const An = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1210
1209
|
function at(e) {
|
|
1211
1210
|
switch (e) {
|
|
1212
1211
|
case "connected":
|
|
@@ -1227,7 +1226,7 @@ function at(e) {
|
|
|
1227
1226
|
return x.New;
|
|
1228
1227
|
}
|
|
1229
1228
|
}
|
|
1230
|
-
const
|
|
1229
|
+
const bn = (e) => (n) => {
|
|
1231
1230
|
const [i, r = ""] = n.split(/:(.+)/);
|
|
1232
1231
|
try {
|
|
1233
1232
|
const s = JSON.parse(r);
|
|
@@ -1236,7 +1235,7 @@ const Ln = (e) => (n) => {
|
|
|
1236
1235
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: s }), { subject: i, data: r };
|
|
1237
1236
|
}
|
|
1238
1237
|
};
|
|
1239
|
-
function
|
|
1238
|
+
function Ln({
|
|
1240
1239
|
statsSignal: e,
|
|
1241
1240
|
dataChannelSignal: n,
|
|
1242
1241
|
onVideoStateChange: i,
|
|
@@ -1245,7 +1244,7 @@ function Pn({
|
|
|
1245
1244
|
}) {
|
|
1246
1245
|
e === k.Start && n === k.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(k.Start)) : e === k.Stop && n === k.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(k.Stop, r));
|
|
1247
1246
|
}
|
|
1248
|
-
function
|
|
1247
|
+
function Pn({
|
|
1249
1248
|
statsSignal: e,
|
|
1250
1249
|
dataChannelSignal: n,
|
|
1251
1250
|
onVideoStateChange: i,
|
|
@@ -1264,7 +1263,7 @@ function ot({
|
|
|
1264
1263
|
report: a,
|
|
1265
1264
|
log: o
|
|
1266
1265
|
}) {
|
|
1267
|
-
s === se.Legacy ?
|
|
1266
|
+
s === se.Legacy ? Ln({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: o }) : s === se.Fluent && Pn({
|
|
1268
1267
|
statsSignal: e,
|
|
1269
1268
|
dataChannelSignal: n,
|
|
1270
1269
|
onVideoStateChange: i,
|
|
@@ -1273,11 +1272,11 @@ function ot({
|
|
|
1273
1272
|
log: o
|
|
1274
1273
|
});
|
|
1275
1274
|
}
|
|
1276
|
-
async function
|
|
1275
|
+
async function xn(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, c) {
|
|
1277
1276
|
var J;
|
|
1278
|
-
const t = pt(i, "WebRTCStreamingManager"), d =
|
|
1277
|
+
const t = pt(i, "WebRTCStreamingManager"), d = bn(t);
|
|
1279
1278
|
let h = !1, g = !1, l = k.Stop, p = k.Stop;
|
|
1280
|
-
const { startConnection: D, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } =
|
|
1279
|
+
const { startConnection: D, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } = _n(
|
|
1281
1280
|
s,
|
|
1282
1281
|
a,
|
|
1283
1282
|
e,
|
|
@@ -1291,7 +1290,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1291
1290
|
interrupt_enabled: ne
|
|
1292
1291
|
} = await F(n, c);
|
|
1293
1292
|
(J = r.onStreamCreated) == null || J.call(r, { stream_id: M, session_id: U, agent_id: e });
|
|
1294
|
-
const $ = new
|
|
1293
|
+
const $ = new An({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
|
|
1295
1294
|
if (!U)
|
|
1296
1295
|
throw new Error("Could not create session_id");
|
|
1297
1296
|
const H = te ? se.Fluent : se.Legacy;
|
|
@@ -1443,18 +1442,18 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1443
1442
|
};
|
|
1444
1443
|
}
|
|
1445
1444
|
var Fe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Fe || {});
|
|
1446
|
-
async function
|
|
1445
|
+
async function $n(e, n, i, r) {
|
|
1447
1446
|
const s = e.id;
|
|
1448
1447
|
switch (n.version) {
|
|
1449
1448
|
case "v1": {
|
|
1450
1449
|
const { version: a, ...o } = n;
|
|
1451
|
-
return
|
|
1450
|
+
return xn(s, o, i, r);
|
|
1452
1451
|
}
|
|
1453
1452
|
case "v2": {
|
|
1454
1453
|
const { version: a, ...o } = n;
|
|
1455
1454
|
switch (o.transport.provider) {
|
|
1456
1455
|
case Ne.Livekit:
|
|
1457
|
-
const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() =>
|
|
1456
|
+
const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() => yn);
|
|
1458
1457
|
return c(s, o, i);
|
|
1459
1458
|
default:
|
|
1460
1459
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
@@ -1464,15 +1463,15 @@ async function jn(e, n, i, r) {
|
|
|
1464
1463
|
throw new Error(`Invalid stream version: ${n.version}`);
|
|
1465
1464
|
}
|
|
1466
1465
|
}
|
|
1467
|
-
const
|
|
1468
|
-
function
|
|
1466
|
+
const jn = "cht";
|
|
1467
|
+
function Bn() {
|
|
1469
1468
|
return {
|
|
1470
1469
|
transport: {
|
|
1471
1470
|
provider: Ne.Livekit
|
|
1472
1471
|
}
|
|
1473
1472
|
};
|
|
1474
1473
|
}
|
|
1475
|
-
function
|
|
1474
|
+
function Fn(e) {
|
|
1476
1475
|
var s, a;
|
|
1477
1476
|
const { streamOptions: n } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
|
|
1478
1477
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1485,16 +1484,16 @@ function Nn(e) {
|
|
|
1485
1484
|
fluent: n == null ? void 0 : n.fluent
|
|
1486
1485
|
}, ...i && { end_user_data: i } };
|
|
1487
1486
|
}
|
|
1488
|
-
function
|
|
1489
|
-
return Ke(e.presenter.type) ? { version: Fe.V2, ...
|
|
1487
|
+
function Nn(e, n) {
|
|
1488
|
+
return Ke(e.presenter.type) ? { version: Fe.V2, ...Bn() } : { version: Fe.V1, ...Fn(n) };
|
|
1490
1489
|
}
|
|
1491
|
-
function
|
|
1490
|
+
function Kn(e, n, i) {
|
|
1492
1491
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
1493
1492
|
}
|
|
1494
|
-
function
|
|
1495
|
-
s === se.Fluent ?
|
|
1493
|
+
function zn(e, n, i, r, s) {
|
|
1494
|
+
s === se.Fluent ? Vn(e, n, i, r, s) : Un(e, n, i, r, s);
|
|
1496
1495
|
}
|
|
1497
|
-
function
|
|
1496
|
+
function Vn(e, n, i, r, s) {
|
|
1498
1497
|
e === k.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === k.Stop && r.track("stream-session", {
|
|
1499
1498
|
event: "stop",
|
|
1500
1499
|
is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
|
|
@@ -1518,7 +1517,7 @@ function st(e, n, i, r, s) {
|
|
|
1518
1517
|
[R.StreamVideoDone]
|
|
1519
1518
|
);
|
|
1520
1519
|
}
|
|
1521
|
-
function
|
|
1520
|
+
function Un(e, n, i, r, s) {
|
|
1522
1521
|
e === k.Start ? r.linkTrack(
|
|
1523
1522
|
"agent-video",
|
|
1524
1523
|
{ event: "start", latency: oe.get(!0), "stream-type": s },
|
|
@@ -1537,7 +1536,7 @@ function Jn(e, n, i, r, s) {
|
|
|
1537
1536
|
[R.StreamVideoDone]
|
|
1538
1537
|
);
|
|
1539
1538
|
}
|
|
1540
|
-
function
|
|
1539
|
+
function Jn(e, n, i) {
|
|
1541
1540
|
const r = {
|
|
1542
1541
|
call_id: n.call_id,
|
|
1543
1542
|
name: n.name
|
|
@@ -1558,13 +1557,13 @@ function ct(e, n, i, r) {
|
|
|
1558
1557
|
return oe.reset(), nt.update(), new Promise(async (s, a) => {
|
|
1559
1558
|
try {
|
|
1560
1559
|
let o, c = !1;
|
|
1561
|
-
const t =
|
|
1560
|
+
const t = Nn(e, n);
|
|
1562
1561
|
i.enrich({
|
|
1563
1562
|
"stream-version": t.version.toString()
|
|
1564
1563
|
});
|
|
1565
1564
|
let d = null;
|
|
1566
1565
|
const h = e.presenter.type === "expressive";
|
|
1567
|
-
o = await
|
|
1566
|
+
o = await $n(
|
|
1568
1567
|
e,
|
|
1569
1568
|
t,
|
|
1570
1569
|
{
|
|
@@ -1574,11 +1573,11 @@ function ct(e, n, i, r) {
|
|
|
1574
1573
|
...n.callbacks,
|
|
1575
1574
|
onConnectionStateChange: (g, l) => {
|
|
1576
1575
|
var p, D;
|
|
1577
|
-
(D = (p = n.callbacks).onConnectionStateChange) == null || D.call(p, g),
|
|
1576
|
+
(D = (p = n.callbacks).onConnectionStateChange) == null || D.call(p, g), Kn(g, l, i), g === x.Connected && (o ? s(o) : c = !0);
|
|
1578
1577
|
},
|
|
1579
1578
|
onVideoStateChange: (g, l) => {
|
|
1580
1579
|
var p, D;
|
|
1581
|
-
(D = (p = n.callbacks).onVideoStateChange) == null || D.call(p, g),
|
|
1580
|
+
(D = (p = n.callbacks).onVideoStateChange) == null || D.call(p, g), zn(
|
|
1582
1581
|
g,
|
|
1583
1582
|
e,
|
|
1584
1583
|
l,
|
|
@@ -1612,7 +1611,7 @@ function ct(e, n, i, r) {
|
|
|
1612
1611
|
},
|
|
1613
1612
|
onToolEvent: (g, l) => {
|
|
1614
1613
|
var p, D;
|
|
1615
|
-
(D = (p = n.callbacks).onToolEvent) == null || D.call(p, g, l),
|
|
1614
|
+
(D = (p = n.callbacks).onToolEvent) == null || D.call(p, g, l), Jn(g, l, i);
|
|
1616
1615
|
}
|
|
1617
1616
|
}
|
|
1618
1617
|
},
|
|
@@ -1623,11 +1622,11 @@ function ct(e, n, i, r) {
|
|
|
1623
1622
|
}
|
|
1624
1623
|
});
|
|
1625
1624
|
}
|
|
1626
|
-
async function
|
|
1625
|
+
async function On(e, n, i, r, s) {
|
|
1627
1626
|
var h, g, l, p;
|
|
1628
1627
|
const a = async () => {
|
|
1629
1628
|
if (Ke(e.presenter.type)) {
|
|
1630
|
-
const D = await ct(e, n, r), N = `${
|
|
1629
|
+
const D = await ct(e, n, r), N = `${jn}_${D.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
|
|
1631
1630
|
return { chatResult: {
|
|
1632
1631
|
chatMode: O.Functional,
|
|
1633
1632
|
chat: {
|
|
@@ -1663,13 +1662,13 @@ async function Wn(e, n, i, r, s) {
|
|
|
1663
1662
|
}, { chatResult: o, streamingManager: c } = await a(), { chat: t, chatMode: d } = o;
|
|
1664
1663
|
return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((p = (l = n.callbacks).onError) == null || p.call(l, new It(d)), c == null || c.disconnect(), { chat: t }) : { chat: t, streamingManager: c };
|
|
1665
1664
|
}
|
|
1666
|
-
async function
|
|
1665
|
+
async function qn(e, n) {
|
|
1667
1666
|
var H, re, de, ue;
|
|
1668
1667
|
let i = !0, r = null;
|
|
1669
1668
|
const s = n.mixpanelKey || zt, a = n.wsURL || Kt, o = n.baseURL || Ee, c = n.mode || O.Functional, t = {
|
|
1670
1669
|
messages: [],
|
|
1671
1670
|
chatMode: c
|
|
1672
|
-
}, d =
|
|
1671
|
+
}, d = tn({
|
|
1673
1672
|
token: s,
|
|
1674
1673
|
agentId: e,
|
|
1675
1674
|
isEnabled: n.enableAnalitics,
|
|
@@ -1679,15 +1678,15 @@ async function Qn(e, n) {
|
|
|
1679
1678
|
tt(() => {
|
|
1680
1679
|
d.track("agent-sdk", { event: "init" }, h);
|
|
1681
1680
|
});
|
|
1682
|
-
const g =
|
|
1681
|
+
const g = Qt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1683
1682
|
n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
|
|
1684
1683
|
const p = Ke(l.presenter.type);
|
|
1685
|
-
d.enrich(
|
|
1686
|
-
const { onMessage: D, clearQueue: N } =
|
|
1684
|
+
d.enrich(Yt(l));
|
|
1685
|
+
const { onMessage: D, clearQueue: N } = Dn(d, t, n, l, () => {
|
|
1687
1686
|
var f, C, T;
|
|
1688
1687
|
(f = t.socketManager) == null || f.disconnect(), (T = (C = n.callbacks).onConnectionStateChange) == null || T.call(C, x.Disconnected);
|
|
1689
1688
|
});
|
|
1690
|
-
t.messages =
|
|
1689
|
+
t.messages = rn(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
|
|
1691
1690
|
const B = (f) => {
|
|
1692
1691
|
r = f;
|
|
1693
1692
|
}, F = ({ type: f }) => {
|
|
@@ -1698,7 +1697,7 @@ async function Qn(e, n) {
|
|
|
1698
1697
|
type: f || "click",
|
|
1699
1698
|
video_duration_to_interrupt: je.get(!0),
|
|
1700
1699
|
message_duration_to_interrupt: oe.get(!0)
|
|
1701
|
-
}), C.interrupted = !0, (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "answer"), p ?
|
|
1700
|
+
}), C.interrupted = !0, (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "answer"), p ? Sn(t.streamingManager) : (vn(t.streamingManager, (J = t.streamingManager) == null ? void 0 : J.streamType, r), Cn(t.streamingManager, r));
|
|
1702
1701
|
}, I = /* @__PURE__ */ new Map();
|
|
1703
1702
|
function M(f) {
|
|
1704
1703
|
return async (C) => {
|
|
@@ -1729,18 +1728,18 @@ async function Qn(e, n) {
|
|
|
1729
1728
|
}
|
|
1730
1729
|
const te = Date.now();
|
|
1731
1730
|
tt(() => {
|
|
1732
|
-
d.track("agent-sdk", { event: "loaded", ...
|
|
1731
|
+
d.track("agent-sdk", { event: "loaded", ...Xt(l) }, te);
|
|
1733
1732
|
});
|
|
1734
1733
|
async function ne(f) {
|
|
1735
|
-
var J, y, v, E, j, G,
|
|
1734
|
+
var J, y, v, E, j, G, ge;
|
|
1736
1735
|
(y = (J = n.callbacks).onConnectionStateChange) == null || y.call(J, x.Connecting), oe.reset(), f && !i && (delete t.chat, (E = (v = n.callbacks).onNewMessage) == null || E.call(v, [...t.messages], "answer"));
|
|
1737
|
-
const C = c === O.DirectPlayback || p ? Promise.resolve(void 0) :
|
|
1736
|
+
const C = c === O.DirectPlayback || p ? Promise.resolve(void 0) : En(
|
|
1738
1737
|
n.auth,
|
|
1739
1738
|
a,
|
|
1740
1739
|
{ onMessage: D, onError: n.callbacks.onError },
|
|
1741
1740
|
n.externalId
|
|
1742
1741
|
), T = xe(
|
|
1743
|
-
() =>
|
|
1742
|
+
() => On(
|
|
1744
1743
|
l,
|
|
1745
1744
|
{
|
|
1746
1745
|
...n,
|
|
@@ -1766,7 +1765,7 @@ async function Qn(e, n) {
|
|
|
1766
1765
|
var z, ee;
|
|
1767
1766
|
throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, x.Fail), Z;
|
|
1768
1767
|
}), [A, { streamingManager: _, chat: L }] = await Promise.all([C, T]);
|
|
1769
|
-
L && L.id !== ((j = t.chat) == null ? void 0 : j.id) && ((
|
|
1768
|
+
L && L.id !== ((j = t.chat) == null ? void 0 : j.id) && ((ge = (G = n.callbacks).onNewChat) == null || ge.call(G, L.id)), t.streamingManager = _, t.socketManager = A, t.chat = L, Y(), i = !1, d.enrich({
|
|
1770
1769
|
chatId: L == null ? void 0 : L.id,
|
|
1771
1770
|
streamId: _ == null ? void 0 : _.streamId,
|
|
1772
1771
|
mode: t.chatMode
|
|
@@ -1902,9 +1901,9 @@ async function Qn(e, n) {
|
|
|
1902
1901
|
}, {
|
|
1903
1902
|
limit: 2,
|
|
1904
1903
|
shouldRetryFn: (z) => {
|
|
1905
|
-
var le, ke,
|
|
1904
|
+
var le, ke, he, pe;
|
|
1906
1905
|
const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
|
|
1907
|
-
return !((ke = z == null ? void 0 : z.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((
|
|
1906
|
+
return !((ke = z == null ? void 0 : z.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((pe = (he = n.callbacks).onError) == null || pe.call(he, z), !1) : !0;
|
|
1908
1907
|
},
|
|
1909
1908
|
onRetry: async () => {
|
|
1910
1909
|
await $(), await ne(!1);
|
|
@@ -1913,7 +1912,7 @@ async function Qn(e, n) {
|
|
|
1913
1912
|
};
|
|
1914
1913
|
try {
|
|
1915
1914
|
N(), C(), t.messages.push({
|
|
1916
|
-
id:
|
|
1915
|
+
id: Te(),
|
|
1917
1916
|
role: "user",
|
|
1918
1917
|
content: f,
|
|
1919
1918
|
parts: Re(f),
|
|
@@ -1921,7 +1920,7 @@ async function Qn(e, n) {
|
|
|
1921
1920
|
}), (L = (_ = n.callbacks).onNewMessage) == null || L.call(_, [...t.messages], "user");
|
|
1922
1921
|
const E = await T(), j = await A([...t.messages], E);
|
|
1923
1922
|
return t.messages.push({
|
|
1924
|
-
id:
|
|
1923
|
+
id: Te(),
|
|
1925
1924
|
role: "assistant",
|
|
1926
1925
|
content: j.result || "",
|
|
1927
1926
|
parts: Re(j.result || ""),
|
|
@@ -2000,7 +1999,7 @@ async function Qn(e, n) {
|
|
|
2000
1999
|
}
|
|
2001
2000
|
const T = C();
|
|
2002
2001
|
if (d.track("agent-speak", T), oe.update(), t.messages && T.type === "text" && (t.messages.push({
|
|
2003
|
-
id:
|
|
2002
|
+
id: Te(),
|
|
2004
2003
|
role: "assistant",
|
|
2005
2004
|
content: T.input,
|
|
2006
2005
|
parts: Re(T.input),
|
|
@@ -2047,7 +2046,7 @@ export {
|
|
|
2047
2046
|
dt as VideoType,
|
|
2048
2047
|
Bt as VoiceAccess,
|
|
2049
2048
|
Dt as WsError,
|
|
2050
|
-
|
|
2051
|
-
|
|
2049
|
+
qn as createAgentManager,
|
|
2050
|
+
Hn as mapVideoType,
|
|
2052
2051
|
Wt as parseMessageParts
|
|
2053
2052
|
};
|