@d-id/client-sdk 1.1.64-staging.299 → 1.1.64-staging.301
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.
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var Ue = Object.defineProperty;
|
|
2
2
|
var We = (e, t, r) => t in e ? Ue(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
3
|
+
var Z = (e, t, r) => We(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
class ce extends Error {
|
|
5
5
|
constructor({ kind: r, description: a, error: c }) {
|
|
6
6
|
super(JSON.stringify({ kind: r, description: a }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
Z(this, "kind");
|
|
8
|
+
Z(this, "description");
|
|
9
|
+
Z(this, "error");
|
|
10
10
|
this.kind = r, this.description = a, this.error = c;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -26,7 +26,7 @@ class He extends ce {
|
|
|
26
26
|
class G extends ce {
|
|
27
27
|
constructor(r, a) {
|
|
28
28
|
super({ kind: "ValidationError", description: r });
|
|
29
|
-
|
|
29
|
+
Z(this, "key");
|
|
30
30
|
this.key = a;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -36,7 +36,7 @@ class qe extends ce {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(J || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__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))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
|
|
39
|
-
const
|
|
39
|
+
const ar = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,9 +48,9 @@ const nr = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}),
|
|
52
|
-
const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st = "wss://notifications.d-id.com", ot = "79f81a83a67430be2bc0fd61042b8faa",
|
|
53
|
-
}, je = (e) => new Promise((t) => setTimeout(t, e)),
|
|
51
|
+
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), te = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ne || {}), P = /* @__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))(P || {}), L = /* @__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))(L || {}), U = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(U || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), nt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(nt || {});
|
|
52
|
+
const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st = "wss://notifications.d-id.com", ot = "79f81a83a67430be2bc0fd61042b8faa", ir = (...e) => {
|
|
53
|
+
}, je = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
|
|
54
54
|
const t = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
56
|
}, Be = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, ct = (e) => {
|
|
@@ -142,21 +142,22 @@ function me(e) {
|
|
|
142
142
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
143
143
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
144
144
|
if (!t) {
|
|
145
|
-
let r =
|
|
145
|
+
let r = Q();
|
|
146
146
|
window.localStorage.setItem("did_external_key_id", r), t = r;
|
|
147
147
|
}
|
|
148
148
|
return t;
|
|
149
149
|
}
|
|
150
|
+
let ft = Q();
|
|
150
151
|
function ze(e, t) {
|
|
151
152
|
if (e.type === "bearer")
|
|
152
153
|
return `Bearer ${e.token}`;
|
|
153
154
|
if (e.type === "basic")
|
|
154
155
|
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
155
156
|
if (e.type === "key")
|
|
156
|
-
return `Client-Key ${e.clientKey}.${me(t)}`;
|
|
157
|
+
return `Client-Key ${e.clientKey}.${me(t)}_${ft}`;
|
|
157
158
|
throw new Error(`Unknown auth type: ${e}`);
|
|
158
159
|
}
|
|
159
|
-
const
|
|
160
|
+
const gt = (e) => ue(e, {
|
|
160
161
|
limit: 3,
|
|
161
162
|
delayMs: 1e3,
|
|
162
163
|
timeout: 0,
|
|
@@ -164,7 +165,7 @@ const ft = (e) => ue(e, {
|
|
|
164
165
|
});
|
|
165
166
|
function Fe(e, t = de, r, a) {
|
|
166
167
|
const c = async (s, o) => {
|
|
167
|
-
const { skipErrorHandler: n, ...i } = o || {}, d = await
|
|
168
|
+
const { skipErrorHandler: n, ...i } = o || {}, d = await gt(
|
|
168
169
|
() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
169
170
|
...i,
|
|
170
171
|
headers: {
|
|
@@ -196,7 +197,7 @@ function Fe(e, t = de, r, a) {
|
|
|
196
197
|
}
|
|
197
198
|
};
|
|
198
199
|
}
|
|
199
|
-
function
|
|
200
|
+
function ht(e, t = de, r, a) {
|
|
200
201
|
const c = Fe(e, `${t}/agents`, r, a);
|
|
201
202
|
return {
|
|
202
203
|
create(s, o) {
|
|
@@ -234,7 +235,7 @@ function gt(e, t = de, r, a) {
|
|
|
234
235
|
}
|
|
235
236
|
};
|
|
236
237
|
}
|
|
237
|
-
function
|
|
238
|
+
function pt(e) {
|
|
238
239
|
var c, s, o, n;
|
|
239
240
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", r = () => {
|
|
240
241
|
const i = navigator.platform;
|
|
@@ -252,7 +253,7 @@ function ht(e) {
|
|
|
252
253
|
}
|
|
253
254
|
};
|
|
254
255
|
}
|
|
255
|
-
function
|
|
256
|
+
function wt(e) {
|
|
256
257
|
var r, a, c, s, o, n;
|
|
257
258
|
const t = (r = e.llm) == null ? void 0 : r.prompt_customization;
|
|
258
259
|
return {
|
|
@@ -277,8 +278,8 @@ function pt(e) {
|
|
|
277
278
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
278
279
|
};
|
|
279
280
|
}
|
|
280
|
-
const
|
|
281
|
-
function
|
|
281
|
+
const vt = (e) => e.reduce((t, r) => t + r, 0), Me = (e) => vt(e) / e.length;
|
|
282
|
+
function yt(e, t, r) {
|
|
282
283
|
var i, d, m;
|
|
283
284
|
const { event: a, ...c } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
|
|
284
285
|
return {
|
|
@@ -292,8 +293,8 @@ function vt(e, t, r) {
|
|
|
292
293
|
function Ee(e) {
|
|
293
294
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
294
295
|
}
|
|
295
|
-
const
|
|
296
|
-
function
|
|
296
|
+
const Ct = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
297
|
+
function St(e) {
|
|
297
298
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
|
|
298
299
|
return {
|
|
299
300
|
token: e.token || "testKey",
|
|
@@ -304,7 +305,7 @@ function Ct(e) {
|
|
|
304
305
|
...e.mixpanelAdditionalProperties || {}
|
|
305
306
|
},
|
|
306
307
|
isEnabled: e.isEnabled ?? !0,
|
|
307
|
-
getRandom:
|
|
308
|
+
getRandom: Q,
|
|
308
309
|
enrich(a) {
|
|
309
310
|
this.additionalProperties = { ...this.additionalProperties, ...a };
|
|
310
311
|
},
|
|
@@ -337,7 +338,7 @@ function Ct(e) {
|
|
|
337
338
|
])
|
|
338
339
|
})
|
|
339
340
|
};
|
|
340
|
-
return fetch(
|
|
341
|
+
return fetch(Ct, d).catch((m) => console.error("Analytics tracking error:", m)), Promise.resolve();
|
|
341
342
|
},
|
|
342
343
|
linkTrack(a, c, s, o) {
|
|
343
344
|
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
|
|
@@ -375,10 +376,10 @@ async function Ke(e, t, r, a, c = !1, s) {
|
|
|
375
376
|
mode: a
|
|
376
377
|
})), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? a };
|
|
377
378
|
} catch (o) {
|
|
378
|
-
throw
|
|
379
|
+
throw kt(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
379
380
|
}
|
|
380
381
|
}
|
|
381
|
-
const
|
|
382
|
+
const kt = (e) => {
|
|
382
383
|
try {
|
|
383
384
|
const t = JSON.parse(e.message);
|
|
384
385
|
return t == null ? void 0 : t.kind;
|
|
@@ -386,10 +387,10 @@ const St = (e) => {
|
|
|
386
387
|
return "UnknownError";
|
|
387
388
|
}
|
|
388
389
|
};
|
|
389
|
-
function
|
|
390
|
+
function Rt(e) {
|
|
390
391
|
return e && e.length > 0 ? e : [];
|
|
391
392
|
}
|
|
392
|
-
function
|
|
393
|
+
function Dt(e) {
|
|
393
394
|
return new Promise((t, r) => {
|
|
394
395
|
const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(ze(s, o))}`);
|
|
395
396
|
l.onmessage = n, l.onclose = d, l.onerror = (w) => {
|
|
@@ -399,12 +400,12 @@ function Rt(e) {
|
|
|
399
400
|
};
|
|
400
401
|
});
|
|
401
402
|
}
|
|
402
|
-
async function
|
|
403
|
+
async function It(e) {
|
|
403
404
|
const { retries: t = 1 } = e;
|
|
404
405
|
let r = null;
|
|
405
406
|
for (let a = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; a++)
|
|
406
407
|
try {
|
|
407
|
-
r = await
|
|
408
|
+
r = await Dt(e);
|
|
408
409
|
} catch (c) {
|
|
409
410
|
if (a === t)
|
|
410
411
|
throw c;
|
|
@@ -412,8 +413,8 @@ async function Dt(e) {
|
|
|
412
413
|
}
|
|
413
414
|
return r;
|
|
414
415
|
}
|
|
415
|
-
async function
|
|
416
|
-
const c = r != null && r.onMessage ? [r.onMessage] : [], s = await
|
|
416
|
+
async function Mt(e, t, r, a) {
|
|
417
|
+
const c = r != null && r.onMessage ? [r.onMessage] : [], s = await It({
|
|
417
418
|
auth: e,
|
|
418
419
|
host: t,
|
|
419
420
|
externalId: a,
|
|
@@ -434,7 +435,7 @@ async function It(e, t, r, a) {
|
|
|
434
435
|
subscribeToEvents: (o) => c.push(o)
|
|
435
436
|
};
|
|
436
437
|
}
|
|
437
|
-
function
|
|
438
|
+
function Et(e) {
|
|
438
439
|
if (e.answer !== void 0)
|
|
439
440
|
return e.answer;
|
|
440
441
|
let t = 0, r = "";
|
|
@@ -442,7 +443,7 @@ function Mt(e) {
|
|
|
442
443
|
r += e[t++];
|
|
443
444
|
return r;
|
|
444
445
|
}
|
|
445
|
-
function
|
|
446
|
+
function Tt(e, t, r) {
|
|
446
447
|
if (!e.content)
|
|
447
448
|
return;
|
|
448
449
|
const a = t.messages[t.messages.length - 1];
|
|
@@ -457,9 +458,9 @@ function Et(e, t, r) {
|
|
|
457
458
|
};
|
|
458
459
|
t.messages.push(c), r == null || r([...t.messages], "user");
|
|
459
460
|
}
|
|
460
|
-
function
|
|
461
|
+
function _t(e, t, r, a, c, s) {
|
|
461
462
|
if (e === J.Transcribe && t.content) {
|
|
462
|
-
|
|
463
|
+
Tt(t, a, c);
|
|
463
464
|
return;
|
|
464
465
|
}
|
|
465
466
|
if (!(e === J.Partial || e === J.Answer))
|
|
@@ -480,10 +481,10 @@ function Tt(e, t, r, a, c, s) {
|
|
|
480
481
|
return;
|
|
481
482
|
const { content: d, sequence: m } = t;
|
|
482
483
|
e === J.Partial ? r[m] = d : r.answer = d;
|
|
483
|
-
const l =
|
|
484
|
+
const l = Et(r);
|
|
484
485
|
(i.content !== l || e === J.Answer) && (i.content = l, i.parts = re(l), c == null || c([...a.messages], e));
|
|
485
486
|
}
|
|
486
|
-
function
|
|
487
|
+
function bt(e, t, r, a, c) {
|
|
487
488
|
let s = {};
|
|
488
489
|
const o = () => s = {};
|
|
489
490
|
let n = "answer";
|
|
@@ -497,13 +498,13 @@ function _t(e, t, r, a, c) {
|
|
|
497
498
|
var l, w;
|
|
498
499
|
if ("content" in m) {
|
|
499
500
|
const v = d === P.ChatAnswer ? J.Answer : d === P.ChatAudioTranscribed ? J.Transcribe : d;
|
|
500
|
-
|
|
501
|
+
_t(v, m, s, t, i, o), v === J.Answer && e.track("agent-message-received", {
|
|
501
502
|
content: m.content,
|
|
502
503
|
messages: t.messages.length,
|
|
503
504
|
mode: t.chatMode
|
|
504
505
|
});
|
|
505
506
|
} else {
|
|
506
|
-
const v = P, k = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], M =
|
|
507
|
+
const v = P, k = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], M = yt(m, a, { mode: t.chatMode });
|
|
507
508
|
if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", M, v.StreamVideoCreated, ["start"]), m.sentiment)) {
|
|
508
509
|
const D = t.messages[t.messages.length - 1];
|
|
509
510
|
if ((D == null ? void 0 : D.role) === "assistant") {
|
|
@@ -520,7 +521,7 @@ function _t(e, t, r, a, c) {
|
|
|
520
521
|
}
|
|
521
522
|
};
|
|
522
523
|
}
|
|
523
|
-
function
|
|
524
|
+
function At(e, t, r, a) {
|
|
524
525
|
const c = Fe(e, `${t}/agents/${r}`, a);
|
|
525
526
|
return {
|
|
526
527
|
createStream(s, o) {
|
|
@@ -557,8 +558,8 @@ function bt(e, t, r, a) {
|
|
|
557
558
|
}
|
|
558
559
|
};
|
|
559
560
|
}
|
|
560
|
-
const
|
|
561
|
-
function
|
|
561
|
+
const xt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
|
|
562
|
+
function Lt(e, t, r) {
|
|
562
563
|
const a = (t.timestamp - e.timestamp) / 1e3;
|
|
563
564
|
return {
|
|
564
565
|
duration: a,
|
|
@@ -578,7 +579,7 @@ function xt(e, t, r) {
|
|
|
578
579
|
lowFpsCount: r
|
|
579
580
|
};
|
|
580
581
|
}
|
|
581
|
-
function
|
|
582
|
+
function Pt(e) {
|
|
582
583
|
return e.filter(
|
|
583
584
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
584
585
|
).map((t) => {
|
|
@@ -589,7 +590,7 @@ function Lt(e) {
|
|
|
589
590
|
};
|
|
590
591
|
});
|
|
591
592
|
}
|
|
592
|
-
function
|
|
593
|
+
function jt(e) {
|
|
593
594
|
var o;
|
|
594
595
|
let t = "", r = 0, a = null;
|
|
595
596
|
const c = /* @__PURE__ */ new Map();
|
|
@@ -676,14 +677,14 @@ function _e(e, t, r) {
|
|
|
676
677
|
framesPerSecond: i.framesPerSecond,
|
|
677
678
|
freezeCount: i.freezeCount - e[d - 1].freezeCount,
|
|
678
679
|
freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
|
|
679
|
-
}), c =
|
|
680
|
+
}), c = Pt(a), s = c.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), o = a.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), n = a.filter((i) => !!i.rtt).map((i) => i.rtt);
|
|
680
681
|
return {
|
|
681
682
|
webRTCStats: {
|
|
682
683
|
anomalies: c,
|
|
683
684
|
minRtt: Math.min(...n),
|
|
684
685
|
avgRtt: Me(n),
|
|
685
686
|
maxRtt: Math.max(...n),
|
|
686
|
-
aggregateReport:
|
|
687
|
+
aggregateReport: Lt(e[0], e[e.length - 1], s),
|
|
687
688
|
minJitterDelayInInterval: Math.min(...o),
|
|
688
689
|
maxJitterDelayInInterval: Math.max(...o),
|
|
689
690
|
avgJitterDelayInInterval: Me(o)
|
|
@@ -698,25 +699,25 @@ function Ve(e, t) {
|
|
|
698
699
|
return r;
|
|
699
700
|
return null;
|
|
700
701
|
}
|
|
701
|
-
const
|
|
702
|
-
function
|
|
702
|
+
const ee = 10;
|
|
703
|
+
function sr(e, t) {
|
|
703
704
|
let r = !1, a = !1, c = null, s = 0, o = 0, n = {};
|
|
704
705
|
async function i() {
|
|
705
706
|
if (r) {
|
|
706
707
|
try {
|
|
707
708
|
const d = await e();
|
|
708
709
|
if (!d) {
|
|
709
|
-
c = setTimeout(i,
|
|
710
|
+
c = setTimeout(i, ee);
|
|
710
711
|
return;
|
|
711
712
|
}
|
|
712
713
|
const m = Ve(d, "audio");
|
|
713
714
|
if (!m) {
|
|
714
|
-
c = setTimeout(i,
|
|
715
|
+
c = setTimeout(i, ee);
|
|
715
716
|
return;
|
|
716
717
|
}
|
|
717
718
|
const l = m.totalAudioEnergy ?? 0, w = m.totalSamplesReceived ?? 0;
|
|
718
719
|
if (!a) {
|
|
719
|
-
s = l, o = w, a = !0, c = setTimeout(i,
|
|
720
|
+
s = l, o = w, a = !0, c = setTimeout(i, ee);
|
|
720
721
|
return;
|
|
721
722
|
}
|
|
722
723
|
const v = l - s, k = w - o;
|
|
@@ -726,20 +727,20 @@ function ir(e, t) {
|
|
|
726
727
|
}
|
|
727
728
|
} catch {
|
|
728
729
|
}
|
|
729
|
-
r && (c = setTimeout(i,
|
|
730
|
+
r && (c = setTimeout(i, ee));
|
|
730
731
|
}
|
|
731
732
|
}
|
|
732
733
|
return {
|
|
733
734
|
arm(d = {}) {
|
|
734
|
-
n = d, r = !0, a = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(i,
|
|
735
|
+
n = d, r = !0, a = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(i, ee);
|
|
735
736
|
},
|
|
736
737
|
destroy() {
|
|
737
738
|
r = !1, c !== null && (clearTimeout(c), c = null);
|
|
738
739
|
}
|
|
739
740
|
};
|
|
740
741
|
}
|
|
741
|
-
const oe = 100,
|
|
742
|
-
function
|
|
742
|
+
const oe = 100, Bt = Math.max(Math.ceil(400 / oe), 1), $t = 0.25, zt = 0.28;
|
|
743
|
+
function Ft() {
|
|
743
744
|
let e = 0, t, r, a = 0;
|
|
744
745
|
return (c) => {
|
|
745
746
|
const s = Ve(c, "video");
|
|
@@ -755,17 +756,17 @@ function zt() {
|
|
|
755
756
|
return e = i, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: s.freezeCount };
|
|
756
757
|
};
|
|
757
758
|
}
|
|
758
|
-
function
|
|
759
|
-
let s = null, o = [], n, i = 0, d = !1, m =
|
|
760
|
-
const k =
|
|
759
|
+
function Nt(e, t, r, a, c) {
|
|
760
|
+
let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, w = 0, v = 0;
|
|
761
|
+
const k = Ft();
|
|
761
762
|
async function B() {
|
|
762
763
|
const M = await e();
|
|
763
764
|
if (!M)
|
|
764
765
|
return;
|
|
765
|
-
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q =
|
|
766
|
+
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q = jt(M);
|
|
766
767
|
if (D)
|
|
767
|
-
i = 0, w = _ - v, l = $ <
|
|
768
|
-
else if (d && (i++, i >=
|
|
768
|
+
i = 0, w = _ - v, l = $ < $t ? te.Strong : $ > zt && w > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, v += w, w = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
|
|
769
|
+
else if (d && (i++, i >= Bt)) {
|
|
769
770
|
const W = _e(o, oe, n);
|
|
770
771
|
a == null || a(S.Stop, W), t() || r(), v = _, d = !1;
|
|
771
772
|
}
|
|
@@ -780,7 +781,7 @@ function Ft(e, t, r, a, c) {
|
|
|
780
781
|
getReport: () => _e(o, oe, n)
|
|
781
782
|
};
|
|
782
783
|
}
|
|
783
|
-
const
|
|
784
|
+
const Kt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
784
785
|
function be(e) {
|
|
785
786
|
switch (e) {
|
|
786
787
|
case "connected":
|
|
@@ -801,7 +802,7 @@ function be(e) {
|
|
|
801
802
|
return L.New;
|
|
802
803
|
}
|
|
803
804
|
}
|
|
804
|
-
const
|
|
805
|
+
const Vt = (e) => (t) => {
|
|
805
806
|
const [r, a = ""] = t.split(/:(.+)/);
|
|
806
807
|
try {
|
|
807
808
|
const c = JSON.parse(a);
|
|
@@ -810,7 +811,7 @@ const Kt = (e) => (t) => {
|
|
|
810
811
|
return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: c }), { subject: r, data: a };
|
|
811
812
|
}
|
|
812
813
|
};
|
|
813
|
-
function
|
|
814
|
+
function Jt({
|
|
814
815
|
statsSignal: e,
|
|
815
816
|
dataChannelSignal: t,
|
|
816
817
|
onVideoStateChange: r,
|
|
@@ -819,7 +820,7 @@ function Vt({
|
|
|
819
820
|
}) {
|
|
820
821
|
e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, a));
|
|
821
822
|
}
|
|
822
|
-
function
|
|
823
|
+
function Ut({
|
|
823
824
|
statsSignal: e,
|
|
824
825
|
dataChannelSignal: t,
|
|
825
826
|
onVideoStateChange: r,
|
|
@@ -838,7 +839,7 @@ function Ae({
|
|
|
838
839
|
report: s,
|
|
839
840
|
log: o
|
|
840
841
|
}) {
|
|
841
|
-
c === U.Legacy ?
|
|
842
|
+
c === U.Legacy ? Jt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: o }) : c === U.Fluent && Ut({
|
|
842
843
|
statsSignal: e,
|
|
843
844
|
dataChannelSignal: t,
|
|
844
845
|
onVideoStateChange: r,
|
|
@@ -847,11 +848,11 @@ function Ae({
|
|
|
847
848
|
log: o
|
|
848
849
|
});
|
|
849
850
|
}
|
|
850
|
-
async function
|
|
851
|
+
async function Wt(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de, analytics: o }, n) {
|
|
851
852
|
var E;
|
|
852
|
-
const i =
|
|
853
|
+
const i = xt(r, "WebRTCStreamingManager"), d = Vt(i);
|
|
853
854
|
let m = !1, l = !1, w = S.Stop, v = S.Stop;
|
|
854
|
-
const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } =
|
|
855
|
+
const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = At(
|
|
855
856
|
c,
|
|
856
857
|
s,
|
|
857
858
|
e,
|
|
@@ -865,7 +866,7 @@ async function Ut(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
865
866
|
interrupt_enabled: O
|
|
866
867
|
} = await D(t, n);
|
|
867
868
|
(E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: N, agent_id: e });
|
|
868
|
-
const I = new
|
|
869
|
+
const I = new Kt({ iceServers: W }), Y = I.createDataChannel("JanusDataChannel");
|
|
869
870
|
if (!N)
|
|
870
871
|
throw new Error("Could not create session_id");
|
|
871
872
|
const K = X ? U.Fluent : U.Legacy;
|
|
@@ -875,7 +876,7 @@ async function Ut(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
875
876
|
const ae = t.stream_warmup && !X, ie = () => m, u = () => {
|
|
876
877
|
var f;
|
|
877
878
|
m = !0, l && (i("CALLBACK: onConnectionStateChange(Connected)"), (f = a.onConnectionStateChange) == null || f.call(a, L.Connected));
|
|
878
|
-
}, g =
|
|
879
|
+
}, g = Nt(
|
|
879
880
|
() => I.getStats(),
|
|
880
881
|
ie,
|
|
881
882
|
u,
|
|
@@ -1031,18 +1032,18 @@ async function Ut(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
|
|
|
1031
1032
|
};
|
|
1032
1033
|
}
|
|
1033
1034
|
var ge = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ge || {});
|
|
1034
|
-
async function
|
|
1035
|
+
async function Ot(e, t, r, a) {
|
|
1035
1036
|
const c = e.id;
|
|
1036
1037
|
switch (t.version) {
|
|
1037
1038
|
case "v1": {
|
|
1038
1039
|
const { version: s, ...o } = t;
|
|
1039
|
-
return
|
|
1040
|
+
return Wt(c, o, r, a);
|
|
1040
1041
|
}
|
|
1041
1042
|
case "v2": {
|
|
1042
1043
|
const { version: s, ...o } = t;
|
|
1043
1044
|
switch (o.transport.provider) {
|
|
1044
1045
|
case he.Livekit:
|
|
1045
|
-
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-
|
|
1046
|
+
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-CW6M36Wj.js");
|
|
1046
1047
|
return n(c, o, r);
|
|
1047
1048
|
default:
|
|
1048
1049
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
@@ -1052,15 +1053,15 @@ async function Wt(e, t, r, a) {
|
|
|
1052
1053
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1053
1054
|
}
|
|
1054
1055
|
}
|
|
1055
|
-
const
|
|
1056
|
-
function
|
|
1056
|
+
const Ht = "cht";
|
|
1057
|
+
function qt() {
|
|
1057
1058
|
return {
|
|
1058
1059
|
transport: {
|
|
1059
1060
|
provider: he.Livekit
|
|
1060
1061
|
}
|
|
1061
1062
|
};
|
|
1062
1063
|
}
|
|
1063
|
-
function
|
|
1064
|
+
function Xt(e) {
|
|
1064
1065
|
var c, s;
|
|
1065
1066
|
const { streamOptions: t } = e ?? {}, r = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
1066
1067
|
plan: (s = e.mixpanelAdditionalProperties) == null ? void 0 : s.plan
|
|
@@ -1073,16 +1074,16 @@ function qt(e) {
|
|
|
1073
1074
|
fluent: t == null ? void 0 : t.fluent
|
|
1074
1075
|
}, ...r && { end_user_data: r } };
|
|
1075
1076
|
}
|
|
1076
|
-
function
|
|
1077
|
-
return pe(e.presenter.type) ? { version: ge.V2, ...
|
|
1077
|
+
function Yt(e, t) {
|
|
1078
|
+
return pe(e.presenter.type) ? { version: ge.V2, ...qt() } : { version: ge.V1, ...Xt(t) };
|
|
1078
1079
|
}
|
|
1079
|
-
function
|
|
1080
|
+
function Gt(e, t, r) {
|
|
1080
1081
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1081
1082
|
}
|
|
1082
|
-
function Gt(e, t, r, a, c) {
|
|
1083
|
-
c === U.Fluent ? Qt(e, t, r, a, c) : Zt(e, t, r, a, c);
|
|
1084
|
-
}
|
|
1085
1083
|
function Qt(e, t, r, a, c) {
|
|
1084
|
+
c === U.Fluent ? Zt(e, t, r, a, c) : er(e, t, r, a, c);
|
|
1085
|
+
}
|
|
1086
|
+
function Zt(e, t, r, a, c) {
|
|
1086
1087
|
e === S.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && a.track("stream-session", {
|
|
1087
1088
|
event: "stop",
|
|
1088
1089
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
@@ -1106,7 +1107,7 @@ function xe(e, t, r, a, c) {
|
|
|
1106
1107
|
[P.StreamVideoDone]
|
|
1107
1108
|
);
|
|
1108
1109
|
}
|
|
1109
|
-
function
|
|
1110
|
+
function er(e, t, r, a, c) {
|
|
1110
1111
|
e === S.Start ? a.linkTrack(
|
|
1111
1112
|
"agent-video",
|
|
1112
1113
|
{ event: "start", latency: H.get(!0), "stream-type": c },
|
|
@@ -1125,7 +1126,7 @@ function Zt(e, t, r, a, c) {
|
|
|
1125
1126
|
[P.StreamVideoDone]
|
|
1126
1127
|
);
|
|
1127
1128
|
}
|
|
1128
|
-
function
|
|
1129
|
+
function tr(e, t, r) {
|
|
1129
1130
|
const a = {
|
|
1130
1131
|
call_id: t.call_id,
|
|
1131
1132
|
name: t.name
|
|
@@ -1146,13 +1147,13 @@ function Le(e, t, r, a) {
|
|
|
1146
1147
|
return H.reset(), Te.update(), new Promise(async (c, s) => {
|
|
1147
1148
|
try {
|
|
1148
1149
|
let o, n = !1;
|
|
1149
|
-
const i =
|
|
1150
|
+
const i = Yt(e, t);
|
|
1150
1151
|
r.enrich({
|
|
1151
1152
|
"stream-version": i.version.toString()
|
|
1152
1153
|
});
|
|
1153
1154
|
let d = null;
|
|
1154
1155
|
const m = e.presenter.type === "expressive";
|
|
1155
|
-
o = await
|
|
1156
|
+
o = await Ot(
|
|
1156
1157
|
e,
|
|
1157
1158
|
i,
|
|
1158
1159
|
{
|
|
@@ -1162,11 +1163,11 @@ function Le(e, t, r, a) {
|
|
|
1162
1163
|
...t.callbacks,
|
|
1163
1164
|
onConnectionStateChange: (l, w) => {
|
|
1164
1165
|
var v, k;
|
|
1165
|
-
(k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l),
|
|
1166
|
+
(k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Gt(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
|
|
1166
1167
|
},
|
|
1167
1168
|
onVideoStateChange: (l, w) => {
|
|
1168
1169
|
var v, k;
|
|
1169
|
-
(k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l),
|
|
1170
|
+
(k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l), Qt(
|
|
1170
1171
|
l,
|
|
1171
1172
|
e,
|
|
1172
1173
|
w,
|
|
@@ -1200,7 +1201,7 @@ function Le(e, t, r, a) {
|
|
|
1200
1201
|
},
|
|
1201
1202
|
onToolEvent: (l, w) => {
|
|
1202
1203
|
var v, k;
|
|
1203
|
-
(k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w),
|
|
1204
|
+
(k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w), tr(l, w, r);
|
|
1204
1205
|
}
|
|
1205
1206
|
}
|
|
1206
1207
|
},
|
|
@@ -1211,11 +1212,11 @@ function Le(e, t, r, a) {
|
|
|
1211
1212
|
}
|
|
1212
1213
|
});
|
|
1213
1214
|
}
|
|
1214
|
-
async function
|
|
1215
|
+
async function rr(e, t, r, a, c) {
|
|
1215
1216
|
var m, l, w, v;
|
|
1216
1217
|
const s = async () => {
|
|
1217
1218
|
if (pe(e.presenter.type)) {
|
|
1218
|
-
const k = await Le(e, t, a), B = `${
|
|
1219
|
+
const k = await Le(e, t, a), B = `${Ht}_${k.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
|
|
1219
1220
|
return { chatResult: {
|
|
1220
1221
|
chatMode: x.Functional,
|
|
1221
1222
|
chat: {
|
|
@@ -1251,13 +1252,13 @@ async function tr(e, t, r, a, c) {
|
|
|
1251
1252
|
}, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
|
|
1252
1253
|
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (w = t.callbacks).onError) == null || v.call(w, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
|
|
1253
1254
|
}
|
|
1254
|
-
async function
|
|
1255
|
+
async function or(e, t) {
|
|
1255
1256
|
var Y, K, ae, ie;
|
|
1256
1257
|
let r = !0;
|
|
1257
1258
|
const a = t.mixpanelKey || ot, c = t.wsURL || st, s = t.baseURL || de, o = t.mode || x.Functional, n = {
|
|
1258
1259
|
messages: [],
|
|
1259
1260
|
chatMode: o
|
|
1260
|
-
}, i =
|
|
1261
|
+
}, i = St({
|
|
1261
1262
|
token: a,
|
|
1262
1263
|
agentId: e,
|
|
1263
1264
|
isEnabled: t.enableAnalitics,
|
|
@@ -1267,15 +1268,15 @@ async function sr(e, t) {
|
|
|
1267
1268
|
Ee(() => {
|
|
1268
1269
|
i.track("agent-sdk", { event: "init" }, d);
|
|
1269
1270
|
});
|
|
1270
|
-
const m =
|
|
1271
|
+
const m = ht(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
|
|
1271
1272
|
t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
|
|
1272
1273
|
const w = pe(l.presenter.type);
|
|
1273
|
-
i.enrich(
|
|
1274
|
-
const { onMessage: v, clearQueue: k } =
|
|
1274
|
+
i.enrich(wt(l));
|
|
1275
|
+
const { onMessage: v, clearQueue: k } = bt(i, n, t, l, () => {
|
|
1275
1276
|
var u, g, p;
|
|
1276
1277
|
(u = n.socketManager) == null || u.disconnect(), (p = (g = t.callbacks).onConnectionStateChange) == null || p.call(g, L.Disconnected);
|
|
1277
1278
|
});
|
|
1278
|
-
n.messages =
|
|
1279
|
+
n.messages = Rt(t.initialMessages), (ae = (K = t.callbacks).onNewMessage) == null || ae.call(K, [...n.messages], "answer");
|
|
1279
1280
|
const B = (u) => {
|
|
1280
1281
|
}, M = ({ type: u }) => {
|
|
1281
1282
|
var p, y, C, R;
|
|
@@ -1316,18 +1317,18 @@ async function sr(e, t) {
|
|
|
1316
1317
|
}
|
|
1317
1318
|
const N = Date.now();
|
|
1318
1319
|
Ee(() => {
|
|
1319
|
-
i.track("agent-sdk", { event: "loaded", ...
|
|
1320
|
+
i.track("agent-sdk", { event: "loaded", ...pt(l) }, N);
|
|
1320
1321
|
});
|
|
1321
1322
|
async function X(u) {
|
|
1322
1323
|
var j, z, F, E, f, h, b;
|
|
1323
1324
|
(z = (j = t.callbacks).onConnectionStateChange) == null || z.call(j, L.Connecting), H.reset(), u && !r && (delete n.chat, (E = (F = t.callbacks).onNewMessage) == null || E.call(F, [...n.messages], "answer"));
|
|
1324
|
-
const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) :
|
|
1325
|
+
const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) : Mt(
|
|
1325
1326
|
t.auth,
|
|
1326
1327
|
c,
|
|
1327
1328
|
{ onMessage: v, onError: t.callbacks.onError },
|
|
1328
1329
|
t.externalId
|
|
1329
1330
|
), p = ue(
|
|
1330
|
-
() =>
|
|
1331
|
+
() => rr(
|
|
1331
1332
|
l,
|
|
1332
1333
|
{
|
|
1333
1334
|
...t,
|
|
@@ -1498,7 +1499,7 @@ async function sr(e, t) {
|
|
|
1498
1499
|
};
|
|
1499
1500
|
try {
|
|
1500
1501
|
k(), g(), n.messages.push({
|
|
1501
|
-
id:
|
|
1502
|
+
id: Q(),
|
|
1502
1503
|
role: "user",
|
|
1503
1504
|
content: u,
|
|
1504
1505
|
parts: re(u),
|
|
@@ -1506,7 +1507,7 @@ async function sr(e, t) {
|
|
|
1506
1507
|
}), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "user");
|
|
1507
1508
|
const E = await p(), f = await y([...n.messages], E);
|
|
1508
1509
|
return n.messages.push({
|
|
1509
|
-
id:
|
|
1510
|
+
id: Q(),
|
|
1510
1511
|
role: "assistant",
|
|
1511
1512
|
content: f.result || "",
|
|
1512
1513
|
parts: re(f.result || ""),
|
|
@@ -1585,7 +1586,7 @@ async function sr(e, t) {
|
|
|
1585
1586
|
}
|
|
1586
1587
|
const p = g();
|
|
1587
1588
|
if (i.track("agent-speak", p), H.update(), n.messages && p.type === "text" && (n.messages.push({
|
|
1588
|
-
id:
|
|
1589
|
+
id: Q(),
|
|
1589
1590
|
role: "assistant",
|
|
1590
1591
|
content: p.input,
|
|
1591
1592
|
parts: re(p.input),
|
|
@@ -1620,26 +1621,26 @@ export {
|
|
|
1620
1621
|
Xe as U,
|
|
1621
1622
|
G as V,
|
|
1622
1623
|
qe as W,
|
|
1623
|
-
|
|
1624
|
+
xt as a,
|
|
1624
1625
|
U as b,
|
|
1625
1626
|
Fe as c,
|
|
1626
1627
|
de as d,
|
|
1627
1628
|
L as e,
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1629
|
+
te as f,
|
|
1630
|
+
Nt as g,
|
|
1631
|
+
sr as h,
|
|
1631
1632
|
S as i,
|
|
1632
1633
|
Oe as j,
|
|
1633
1634
|
He as k,
|
|
1634
1635
|
H as l,
|
|
1635
|
-
|
|
1636
|
-
|
|
1636
|
+
or as m,
|
|
1637
|
+
ir as n,
|
|
1637
1638
|
Ge as o,
|
|
1638
1639
|
ut as p,
|
|
1639
1640
|
x as q,
|
|
1640
1641
|
Ze as r,
|
|
1641
1642
|
Pe as s,
|
|
1642
|
-
|
|
1643
|
+
ar as t,
|
|
1643
1644
|
rt as u,
|
|
1644
1645
|
nt as v
|
|
1645
1646
|
};
|