@d-id/client-sdk 1.1.52 → 1.1.53
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/README.md +105 -57
- package/dist/index.js +111 -100
- package/dist/index.umd.cjs +5 -5
- package/dist/src/types/auth.d.ts +5 -2
- package/dist/src/types/entities/agents/presenter.d.ts +1 -0
- package/dist/src/utils/agent.d.ts +3 -0
- package/dist/src/utils/analytics.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ class ut extends Ee {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
var lt = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(lt || {}), 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 || {}), ft = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ft || {}), gt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(gt || {}), F = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(F || {}), G = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(G || {}), ht = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ht || {}), pt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(pt || {}), wt = /* @__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))(wt || {}), qe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(qe || {});
|
|
39
|
-
const
|
|
39
|
+
const In = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -53,8 +53,17 @@ const Ct = 45 * 1e3, St = "X-Playground-Chat", Se = "https://api.d-id.com", kt =
|
|
|
53
53
|
}, Qe = (e) => new Promise((n) => setTimeout(n, e)), he = (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
|
-
}, Xe = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type,
|
|
57
|
-
|
|
56
|
+
}, Xe = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Et = (e) => {
|
|
57
|
+
switch (e.type) {
|
|
58
|
+
case "expressive":
|
|
59
|
+
return "v4";
|
|
60
|
+
case "clip":
|
|
61
|
+
return "v3-pro";
|
|
62
|
+
case "talk":
|
|
63
|
+
return "v2";
|
|
64
|
+
}
|
|
65
|
+
}, Mt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, je = (e) => e === qe.Expressive, It = (e) => [F.TextOnly, F.Playground, F.Maintenance].includes(e), Ye = (e) => e && [F.DirectPlayback, F.Off].includes(e);
|
|
66
|
+
function Tt(e, n) {
|
|
58
67
|
let i;
|
|
59
68
|
return {
|
|
60
69
|
promise: new Promise((o, a) => {
|
|
@@ -78,7 +87,7 @@ async function _e(e, n) {
|
|
|
78
87
|
try {
|
|
79
88
|
if (!i.timeout)
|
|
80
89
|
return await e();
|
|
81
|
-
const { promise: a, clear: s } =
|
|
90
|
+
const { promise: a, clear: s } = Tt(i.timeout, i.timeoutErrorMessage), d = e().finally(s);
|
|
82
91
|
return await Promise.race([d, a]);
|
|
83
92
|
} catch (a) {
|
|
84
93
|
if (r = a, !i.shouldRetryFn(a) || o >= i.limit)
|
|
@@ -97,17 +106,17 @@ function Ae(e) {
|
|
|
97
106
|
}
|
|
98
107
|
return n;
|
|
99
108
|
}
|
|
100
|
-
let
|
|
109
|
+
let _t = he();
|
|
101
110
|
function Ge(e, n) {
|
|
102
111
|
if (e.type === "bearer")
|
|
103
112
|
return `Bearer ${e.token}`;
|
|
104
113
|
if (e.type === "basic")
|
|
105
|
-
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
114
|
+
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
106
115
|
if (e.type === "key")
|
|
107
|
-
return `Client-Key ${e.clientKey}.${Ae(n)}_${
|
|
116
|
+
return `Client-Key ${e.clientKey}.${Ae(n)}_${_t}`;
|
|
108
117
|
throw new Error(`Unknown auth type: ${e}`);
|
|
109
118
|
}
|
|
110
|
-
const
|
|
119
|
+
const At = (e) => _e(e, {
|
|
111
120
|
limit: 3,
|
|
112
121
|
delayMs: 1e3,
|
|
113
122
|
timeout: 0,
|
|
@@ -115,7 +124,7 @@ const Tt = (e) => _e(e, {
|
|
|
115
124
|
});
|
|
116
125
|
function $e(e, n = Se, i, r) {
|
|
117
126
|
const o = async (a, s) => {
|
|
118
|
-
const { skipErrorHandler: d, ...t } = s || {}, c = await
|
|
127
|
+
const { skipErrorHandler: d, ...t } = s || {}, c = await At(
|
|
119
128
|
() => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
120
129
|
...t,
|
|
121
130
|
headers: {
|
|
@@ -147,7 +156,7 @@ function $e(e, n = Se, i, r) {
|
|
|
147
156
|
}
|
|
148
157
|
};
|
|
149
158
|
}
|
|
150
|
-
function
|
|
159
|
+
function bt(e, n = Se, i, r) {
|
|
151
160
|
const o = $e(e, `${n}/agents`, i, r);
|
|
152
161
|
return {
|
|
153
162
|
create(a, s) {
|
|
@@ -185,7 +194,7 @@ function _t(e, n = Se, i, r) {
|
|
|
185
194
|
}
|
|
186
195
|
};
|
|
187
196
|
}
|
|
188
|
-
function
|
|
197
|
+
function Pt(e) {
|
|
189
198
|
var o, a, s, d;
|
|
190
199
|
const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
191
200
|
const t = navigator.platform;
|
|
@@ -203,11 +212,13 @@ function At(e) {
|
|
|
203
212
|
}
|
|
204
213
|
};
|
|
205
214
|
}
|
|
206
|
-
function
|
|
215
|
+
function Lt(e) {
|
|
207
216
|
var i, r, o, a, s, d;
|
|
208
217
|
const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
209
218
|
return {
|
|
210
219
|
agentType: Xe(e.presenter),
|
|
220
|
+
presenterType: Et(e.presenter),
|
|
221
|
+
presenter: Mt(e.presenter),
|
|
211
222
|
owner_id: e.owner_id ?? "",
|
|
212
223
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
213
224
|
behavior: {
|
|
@@ -226,8 +237,8 @@ function bt(e) {
|
|
|
226
237
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
227
238
|
};
|
|
228
239
|
}
|
|
229
|
-
const
|
|
230
|
-
function
|
|
240
|
+
const jt = (e) => e.reduce((n, i) => n + i, 0), Ke = (e) => jt(e) / e.length;
|
|
241
|
+
function $t(e, n, i) {
|
|
231
242
|
var t, c, g;
|
|
232
243
|
const { event: r, ...o } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: s } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
|
|
233
244
|
return {
|
|
@@ -241,8 +252,8 @@ function Lt(e, n, i) {
|
|
|
241
252
|
function Ne(e) {
|
|
242
253
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
243
254
|
}
|
|
244
|
-
const
|
|
245
|
-
function
|
|
255
|
+
const Bt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
256
|
+
function xt(e) {
|
|
246
257
|
const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
|
|
247
258
|
return {
|
|
248
259
|
token: e.token || "testKey",
|
|
@@ -286,7 +297,7 @@ function $t(e) {
|
|
|
286
297
|
])
|
|
287
298
|
})
|
|
288
299
|
};
|
|
289
|
-
return fetch(
|
|
300
|
+
return fetch(Bt, c).catch((g) => console.error("Analytics tracking error:", g)), Promise.resolve();
|
|
290
301
|
},
|
|
291
302
|
linkTrack(r, o, a, s) {
|
|
292
303
|
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), s.includes(a) || s.push(a);
|
|
@@ -324,10 +335,10 @@ async function et(e, n, i, r, o = !1, a) {
|
|
|
324
335
|
mode: r
|
|
325
336
|
})), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
|
|
326
337
|
} catch (s) {
|
|
327
|
-
throw
|
|
338
|
+
throw Ft(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
328
339
|
}
|
|
329
340
|
}
|
|
330
|
-
const
|
|
341
|
+
const Ft = (e) => {
|
|
331
342
|
try {
|
|
332
343
|
const n = JSON.parse(e.message);
|
|
333
344
|
return n == null ? void 0 : n.kind;
|
|
@@ -335,10 +346,10 @@ const Bt = (e) => {
|
|
|
335
346
|
return "UnknownError";
|
|
336
347
|
}
|
|
337
348
|
};
|
|
338
|
-
function
|
|
349
|
+
function zt(e) {
|
|
339
350
|
return e && e.length > 0 ? e : [];
|
|
340
351
|
}
|
|
341
|
-
function
|
|
352
|
+
function Kt(e, n, i, r) {
|
|
342
353
|
const o = $e(e, `${n}/v2/agents/${i}`, r);
|
|
343
354
|
return {
|
|
344
355
|
async createStream(a) {
|
|
@@ -347,7 +358,7 @@ function Ft(e, n, i, r) {
|
|
|
347
358
|
};
|
|
348
359
|
}
|
|
349
360
|
const tt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? "");
|
|
350
|
-
function
|
|
361
|
+
function Nt(e, n, i) {
|
|
351
362
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
352
363
|
return {
|
|
353
364
|
duration: r,
|
|
@@ -367,7 +378,7 @@ function zt(e, n, i) {
|
|
|
367
378
|
lowFpsCount: i
|
|
368
379
|
};
|
|
369
380
|
}
|
|
370
|
-
function
|
|
381
|
+
function Vt(e) {
|
|
371
382
|
return e.filter(
|
|
372
383
|
(n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0
|
|
373
384
|
).map((n) => {
|
|
@@ -378,7 +389,7 @@ function Kt(e) {
|
|
|
378
389
|
};
|
|
379
390
|
});
|
|
380
391
|
}
|
|
381
|
-
function
|
|
392
|
+
function Jt(e) {
|
|
382
393
|
let n = "", i = 0;
|
|
383
394
|
for (const r of e.values()) {
|
|
384
395
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (n = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -460,14 +471,14 @@ function Je(e, n, i) {
|
|
|
460
471
|
framesPerSecond: t.framesPerSecond,
|
|
461
472
|
freezeCount: t.freezeCount - e[c - 1].freezeCount,
|
|
462
473
|
freezeDuration: t.freezeDuration - e[c - 1].freezeDuration
|
|
463
|
-
}), o =
|
|
474
|
+
}), o = Vt(r), a = o.reduce((t, c) => t + (c.causes.includes("low fps") ? 1 : 0), 0), s = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), d = r.filter((t) => !!t.rtt).map((t) => t.rtt);
|
|
464
475
|
return {
|
|
465
476
|
webRTCStats: {
|
|
466
477
|
anomalies: o,
|
|
467
478
|
minRtt: Math.min(...d),
|
|
468
479
|
avgRtt: Ke(d),
|
|
469
480
|
maxRtt: Math.max(...d),
|
|
470
|
-
aggregateReport:
|
|
481
|
+
aggregateReport: Nt(e[0], e[e.length - 1], a),
|
|
471
482
|
minJitterDelayInInterval: Math.min(...s),
|
|
472
483
|
maxJitterDelayInInterval: Math.max(...s),
|
|
473
484
|
avgJitterDelayInInterval: Ke(s)
|
|
@@ -476,8 +487,8 @@ function Je(e, n, i) {
|
|
|
476
487
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
477
488
|
};
|
|
478
489
|
}
|
|
479
|
-
const De = 100,
|
|
480
|
-
function
|
|
490
|
+
const De = 100, Ut = Math.max(Math.ceil(400 / De), 1), Wt = 0.25, Ot = 0.28;
|
|
491
|
+
function Ht() {
|
|
481
492
|
let e = 0, n, i, r = 0;
|
|
482
493
|
return (o) => {
|
|
483
494
|
for (const a of o.values())
|
|
@@ -496,15 +507,15 @@ function Wt() {
|
|
|
496
507
|
}
|
|
497
508
|
function nt(e, n, i, r, o) {
|
|
498
509
|
let a = null, s = [], d, t = 0, c = !1, g = ie.Unknown, p = ie.Unknown, u = 0, v = 0;
|
|
499
|
-
const z =
|
|
510
|
+
const z = Ht();
|
|
500
511
|
async function L() {
|
|
501
512
|
const I = await e();
|
|
502
513
|
if (!I)
|
|
503
514
|
return;
|
|
504
|
-
const { isReceiving: A, avgJitterDelayInInterval: T, freezeCount: E } = z(I), K =
|
|
515
|
+
const { isReceiving: A, avgJitterDelayInInterval: T, freezeCount: E } = z(I), K = Jt(I);
|
|
505
516
|
if (A)
|
|
506
|
-
t = 0, u = E - v, p = T <
|
|
507
|
-
else if (c && (t++, t >=
|
|
517
|
+
t = 0, u = E - v, p = T < Wt ? ie.Strong : T > Ot && u > 1 ? ie.Weak : g, p !== g && (o == null || o(p), g = p, v += u, u = 0), c || (r == null || r(C.Start), d = s[s.length - 1], s = [], c = !0), s.push(K);
|
|
518
|
+
else if (c && (t++, t >= Ut)) {
|
|
508
519
|
const $ = Je(s, De, d);
|
|
509
520
|
r == null || r(C.Stop, $), n() || i(), v = E, c = !1;
|
|
510
521
|
}
|
|
@@ -520,7 +531,7 @@ function nt(e, n, i, r, o) {
|
|
|
520
531
|
};
|
|
521
532
|
}
|
|
522
533
|
const Ue = 2e4;
|
|
523
|
-
async function
|
|
534
|
+
async function qt() {
|
|
524
535
|
try {
|
|
525
536
|
return await import("./livekit-client.esm-RGXA_gNu.js");
|
|
526
537
|
} catch {
|
|
@@ -529,7 +540,7 @@ async function Ot() {
|
|
|
529
540
|
);
|
|
530
541
|
}
|
|
531
542
|
}
|
|
532
|
-
const
|
|
543
|
+
const Qt = {
|
|
533
544
|
excellent: ie.Strong,
|
|
534
545
|
good: ie.Strong,
|
|
535
546
|
poor: ie.Weak,
|
|
@@ -544,9 +555,9 @@ function Pe(e, n, i) {
|
|
|
544
555
|
var r, o;
|
|
545
556
|
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, M.Fail, "internal:init-error"), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
|
|
546
557
|
}
|
|
547
|
-
async function
|
|
558
|
+
async function Xt(e, n, i) {
|
|
548
559
|
var Fe;
|
|
549
|
-
const r = tt(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await
|
|
560
|
+
const r = tt(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await qt(), { callbacks: t, auth: c, baseURL: g, analytics: p } = i;
|
|
550
561
|
let u = null, v = !1;
|
|
551
562
|
const z = ae.Fluent;
|
|
552
563
|
let L = null;
|
|
@@ -558,7 +569,7 @@ async function qt(e, n, i) {
|
|
|
558
569
|
dynacast: !0
|
|
559
570
|
});
|
|
560
571
|
let $ = null, N = H.Idle;
|
|
561
|
-
const de =
|
|
572
|
+
const de = Kt(c, g || Se, e, t.onError);
|
|
562
573
|
let U, ee, l;
|
|
563
574
|
try {
|
|
564
575
|
const m = await de.createStream({
|
|
@@ -614,7 +625,7 @@ async function qt(e, n, i) {
|
|
|
614
625
|
}
|
|
615
626
|
function V(m, h) {
|
|
616
627
|
var y;
|
|
617
|
-
r("Connection quality:", m), h != null && h.isLocal && ((y = t.onConnectivityStateChange) == null || y.call(t,
|
|
628
|
+
r("Connection quality:", m), h != null && h.isLocal && ((y = t.onConnectivityStateChange) == null || y.call(t, Qt[m]));
|
|
618
629
|
}
|
|
619
630
|
function P(m) {
|
|
620
631
|
r("Participant connected:", m.identity);
|
|
@@ -867,13 +878,13 @@ async function qt(e, n, i) {
|
|
|
867
878
|
triggersAvailable: !1
|
|
868
879
|
};
|
|
869
880
|
}
|
|
870
|
-
const
|
|
881
|
+
const Yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
871
882
|
__proto__: null,
|
|
872
883
|
DataChannelTopic: xe,
|
|
873
|
-
createLiveKitStreamingManager:
|
|
884
|
+
createLiveKitStreamingManager: Xt,
|
|
874
885
|
handleInitError: Pe
|
|
875
886
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
876
|
-
function
|
|
887
|
+
function Gt(e, n, i) {
|
|
877
888
|
if (!e)
|
|
878
889
|
throw new Error("Please connect to the agent first");
|
|
879
890
|
if (!e.interruptAvailable)
|
|
@@ -883,7 +894,7 @@ function Xt(e, n, i) {
|
|
|
883
894
|
if (!i)
|
|
884
895
|
throw new Error("No active video to interrupt");
|
|
885
896
|
}
|
|
886
|
-
async function
|
|
897
|
+
async function Zt(e, n) {
|
|
887
898
|
const i = {
|
|
888
899
|
type: b.StreamInterrupt,
|
|
889
900
|
videoId: n,
|
|
@@ -891,13 +902,13 @@ async function Yt(e, n) {
|
|
|
891
902
|
};
|
|
892
903
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
893
904
|
}
|
|
894
|
-
async function
|
|
905
|
+
async function en(e) {
|
|
895
906
|
const n = {
|
|
896
907
|
topic: xe.Interrupt
|
|
897
908
|
};
|
|
898
909
|
e.sendDataChannelMessage(JSON.stringify(n));
|
|
899
910
|
}
|
|
900
|
-
function
|
|
911
|
+
function tn(e) {
|
|
901
912
|
return new Promise((n, i) => {
|
|
902
913
|
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: g = null } = r || {}, p = new WebSocket(`${o}?authorization=${encodeURIComponent(Ge(a, s))}`);
|
|
903
914
|
p.onmessage = d, p.onclose = c, p.onerror = (u) => {
|
|
@@ -907,12 +918,12 @@ function Zt(e) {
|
|
|
907
918
|
};
|
|
908
919
|
});
|
|
909
920
|
}
|
|
910
|
-
async function
|
|
921
|
+
async function nn(e) {
|
|
911
922
|
const { retries: n = 1 } = e;
|
|
912
923
|
let i = null;
|
|
913
924
|
for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
|
|
914
925
|
try {
|
|
915
|
-
i = await
|
|
926
|
+
i = await tn(e);
|
|
916
927
|
} catch (o) {
|
|
917
928
|
if (r === n)
|
|
918
929
|
throw o;
|
|
@@ -920,8 +931,8 @@ async function en(e) {
|
|
|
920
931
|
}
|
|
921
932
|
return i;
|
|
922
933
|
}
|
|
923
|
-
async function
|
|
924
|
-
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await
|
|
934
|
+
async function rn(e, n, i, r) {
|
|
935
|
+
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await nn({
|
|
925
936
|
auth: e,
|
|
926
937
|
host: n,
|
|
927
938
|
externalId: r,
|
|
@@ -942,7 +953,7 @@ async function tn(e, n, i, r) {
|
|
|
942
953
|
subscribeToEvents: (s) => o.push(s)
|
|
943
954
|
};
|
|
944
955
|
}
|
|
945
|
-
function
|
|
956
|
+
function an(e) {
|
|
946
957
|
if (e.answer !== void 0)
|
|
947
958
|
return e.answer;
|
|
948
959
|
let n = 0, i = "";
|
|
@@ -950,7 +961,7 @@ function nn(e) {
|
|
|
950
961
|
i += e[n++];
|
|
951
962
|
return i;
|
|
952
963
|
}
|
|
953
|
-
function
|
|
964
|
+
function on(e, n, i) {
|
|
954
965
|
if (!e.content)
|
|
955
966
|
return;
|
|
956
967
|
const r = n.messages[n.messages.length - 1];
|
|
@@ -964,9 +975,9 @@ function rn(e, n, i) {
|
|
|
964
975
|
};
|
|
965
976
|
n.messages.push(o), i == null || i([...n.messages], "user");
|
|
966
977
|
}
|
|
967
|
-
function
|
|
978
|
+
function sn(e, n, i, r, o) {
|
|
968
979
|
if (e === G.Transcribe && n.content) {
|
|
969
|
-
|
|
980
|
+
on(n, r, o);
|
|
970
981
|
return;
|
|
971
982
|
}
|
|
972
983
|
if (!(e === G.Partial || e === G.Answer))
|
|
@@ -986,10 +997,10 @@ function an(e, n, i, r, o) {
|
|
|
986
997
|
return;
|
|
987
998
|
const { content: d, sequence: t } = n;
|
|
988
999
|
e === G.Partial ? i[t] = d : i.answer = d;
|
|
989
|
-
const c =
|
|
1000
|
+
const c = an(i);
|
|
990
1001
|
(s.content !== c || e === G.Answer) && (s.content = c, o == null || o([...r.messages], e));
|
|
991
1002
|
}
|
|
992
|
-
function
|
|
1003
|
+
function cn(e, n, i, r, o) {
|
|
993
1004
|
let a = {};
|
|
994
1005
|
const s = () => a = {};
|
|
995
1006
|
let d = "answer";
|
|
@@ -1003,13 +1014,13 @@ function on(e, n, i, r, o) {
|
|
|
1003
1014
|
var p, u;
|
|
1004
1015
|
if ("content" in g) {
|
|
1005
1016
|
const v = c === b.ChatAnswer ? G.Answer : c === b.ChatAudioTranscribed ? G.Transcribe : c;
|
|
1006
|
-
|
|
1017
|
+
sn(v, g, a, n, t), v === G.Answer && e.track("agent-message-received", {
|
|
1007
1018
|
content: g.content,
|
|
1008
1019
|
messages: n.messages.length,
|
|
1009
1020
|
mode: n.chatMode
|
|
1010
1021
|
});
|
|
1011
1022
|
} else {
|
|
1012
|
-
const v = b, z = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], L = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], I =
|
|
1023
|
+
const v = b, z = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], L = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], I = $t(g, r, { mode: n.chatMode });
|
|
1013
1024
|
if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", I, v.StreamVideoCreated, ["start"]), g.sentiment)) {
|
|
1014
1025
|
const A = n.messages[n.messages.length - 1];
|
|
1015
1026
|
if ((A == null ? void 0 : A.role) === "assistant") {
|
|
@@ -1026,7 +1037,7 @@ function on(e, n, i, r, o) {
|
|
|
1026
1037
|
}
|
|
1027
1038
|
};
|
|
1028
1039
|
}
|
|
1029
|
-
function
|
|
1040
|
+
function dn(e, n, i, r) {
|
|
1030
1041
|
const o = $e(e, `${n}/agents/${i}`, r);
|
|
1031
1042
|
return {
|
|
1032
1043
|
createStream(a, s) {
|
|
@@ -1063,7 +1074,7 @@ function sn(e, n, i, r) {
|
|
|
1063
1074
|
}
|
|
1064
1075
|
};
|
|
1065
1076
|
}
|
|
1066
|
-
const
|
|
1077
|
+
const un = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1067
1078
|
function We(e) {
|
|
1068
1079
|
switch (e) {
|
|
1069
1080
|
case "connected":
|
|
@@ -1084,7 +1095,7 @@ function We(e) {
|
|
|
1084
1095
|
return M.New;
|
|
1085
1096
|
}
|
|
1086
1097
|
}
|
|
1087
|
-
const
|
|
1098
|
+
const ln = (e) => (n) => {
|
|
1088
1099
|
const [i, r = ""] = n.split(/:(.+)/);
|
|
1089
1100
|
try {
|
|
1090
1101
|
const o = JSON.parse(r);
|
|
@@ -1093,7 +1104,7 @@ const dn = (e) => (n) => {
|
|
|
1093
1104
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: o }), { subject: i, data: r };
|
|
1094
1105
|
}
|
|
1095
1106
|
};
|
|
1096
|
-
function
|
|
1107
|
+
function mn({
|
|
1097
1108
|
statsSignal: e,
|
|
1098
1109
|
dataChannelSignal: n,
|
|
1099
1110
|
onVideoStateChange: i,
|
|
@@ -1102,7 +1113,7 @@ function un({
|
|
|
1102
1113
|
}) {
|
|
1103
1114
|
e === C.Start && n === C.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(C.Start)) : e === C.Stop && n === C.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(C.Stop, r));
|
|
1104
1115
|
}
|
|
1105
|
-
function
|
|
1116
|
+
function fn({
|
|
1106
1117
|
statsSignal: e,
|
|
1107
1118
|
dataChannelSignal: n,
|
|
1108
1119
|
onVideoStateChange: i,
|
|
@@ -1121,7 +1132,7 @@ function Oe({
|
|
|
1121
1132
|
report: a,
|
|
1122
1133
|
log: s
|
|
1123
1134
|
}) {
|
|
1124
|
-
o === ae.Legacy ?
|
|
1135
|
+
o === ae.Legacy ? mn({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === ae.Fluent && fn({
|
|
1125
1136
|
statsSignal: e,
|
|
1126
1137
|
dataChannelSignal: n,
|
|
1127
1138
|
onVideoStateChange: i,
|
|
@@ -1130,11 +1141,11 @@ function Oe({
|
|
|
1130
1141
|
log: s
|
|
1131
1142
|
});
|
|
1132
1143
|
}
|
|
1133
|
-
async function
|
|
1144
|
+
async function gn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Se, analytics: s }, d) {
|
|
1134
1145
|
var oe;
|
|
1135
|
-
const t = tt(i, "WebRTCStreamingManager"), c =
|
|
1146
|
+
const t = tt(i, "WebRTCStreamingManager"), c = ln(t);
|
|
1136
1147
|
let g = !1, p = !1, u = C.Stop, v = C.Stop;
|
|
1137
|
-
const { startConnection: z, sendStreamRequest: L, close: I, createStream: A, addIceCandidate: T } =
|
|
1148
|
+
const { startConnection: z, sendStreamRequest: L, close: I, createStream: A, addIceCandidate: T } = dn(
|
|
1138
1149
|
o,
|
|
1139
1150
|
a,
|
|
1140
1151
|
e,
|
|
@@ -1149,7 +1160,7 @@ async function mn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Se,
|
|
|
1149
1160
|
triggers_enabled: ee
|
|
1150
1161
|
} = await A(n, d);
|
|
1151
1162
|
(oe = r.onStreamCreated) == null || oe.call(r, { stream_id: E, session_id: N, agent_id: e });
|
|
1152
|
-
const l = new
|
|
1163
|
+
const l = new un({ iceServers: $ }), S = l.createDataChannel("JanusDataChannel");
|
|
1153
1164
|
if (!N)
|
|
1154
1165
|
throw new Error("Could not create session_id");
|
|
1155
1166
|
const k = de ? ae.Fluent : ae.Legacy;
|
|
@@ -1301,18 +1312,18 @@ async function mn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Se,
|
|
|
1301
1312
|
};
|
|
1302
1313
|
}
|
|
1303
1314
|
var Le = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Le || {});
|
|
1304
|
-
async function
|
|
1315
|
+
async function hn(e, n, i, r) {
|
|
1305
1316
|
const o = e.id;
|
|
1306
1317
|
switch (n.version) {
|
|
1307
1318
|
case "v1": {
|
|
1308
1319
|
const { version: a, ...s } = n;
|
|
1309
|
-
return
|
|
1320
|
+
return gn(o, s, i, r);
|
|
1310
1321
|
}
|
|
1311
1322
|
case "v2": {
|
|
1312
1323
|
const { version: a, ...s } = n;
|
|
1313
1324
|
switch (s.transport_provider) {
|
|
1314
1325
|
case Me.Livekit:
|
|
1315
|
-
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() =>
|
|
1326
|
+
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => Yt);
|
|
1316
1327
|
return d(o, s, i);
|
|
1317
1328
|
default:
|
|
1318
1329
|
throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
|
|
@@ -1322,13 +1333,13 @@ async function fn(e, n, i, r) {
|
|
|
1322
1333
|
throw new Error(`Invalid stream version: ${n.version}`);
|
|
1323
1334
|
}
|
|
1324
1335
|
}
|
|
1325
|
-
const
|
|
1326
|
-
function
|
|
1336
|
+
const pn = "cht";
|
|
1337
|
+
function wn() {
|
|
1327
1338
|
return {
|
|
1328
1339
|
transport_provider: Me.Livekit
|
|
1329
1340
|
};
|
|
1330
1341
|
}
|
|
1331
|
-
function
|
|
1342
|
+
function yn(e) {
|
|
1332
1343
|
var o, a;
|
|
1333
1344
|
const { streamOptions: n } = e ?? {}, i = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
|
|
1334
1345
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1341,16 +1352,16 @@ function pn(e) {
|
|
|
1341
1352
|
fluent: n == null ? void 0 : n.fluent
|
|
1342
1353
|
}, ...i && { end_user_data: i } };
|
|
1343
1354
|
}
|
|
1344
|
-
function
|
|
1345
|
-
return je(e.presenter.type) ? { version: Le.V2, ...
|
|
1355
|
+
function vn(e, n) {
|
|
1356
|
+
return je(e.presenter.type) ? { version: Le.V2, ...wn() } : { version: Le.V1, ...yn(n) };
|
|
1346
1357
|
}
|
|
1347
|
-
function
|
|
1358
|
+
function Cn(e, n, i) {
|
|
1348
1359
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
1349
1360
|
}
|
|
1350
|
-
function
|
|
1351
|
-
o === ae.Fluent ?
|
|
1361
|
+
function Sn(e, n, i, r, o) {
|
|
1362
|
+
o === ae.Fluent ? kn(e, n, i, r, o) : Dn(e, n, i, r, o);
|
|
1352
1363
|
}
|
|
1353
|
-
function
|
|
1364
|
+
function kn(e, n, i, r, o) {
|
|
1354
1365
|
e === C.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === C.Stop && r.track("stream-session", {
|
|
1355
1366
|
event: "stop",
|
|
1356
1367
|
is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
|
|
@@ -1359,7 +1370,7 @@ function Cn(e, n, i, r, o) {
|
|
|
1359
1370
|
...i
|
|
1360
1371
|
});
|
|
1361
1372
|
}
|
|
1362
|
-
function
|
|
1373
|
+
function Rn(e, n, i, r) {
|
|
1363
1374
|
ne.get() <= 0 || (e === C.Start ? i.linkTrack(
|
|
1364
1375
|
"agent-video",
|
|
1365
1376
|
{ event: "start", latency: ne.get(!0), "stream-type": r },
|
|
@@ -1377,7 +1388,7 @@ function Sn(e, n, i, r) {
|
|
|
1377
1388
|
[b.StreamVideoDone]
|
|
1378
1389
|
));
|
|
1379
1390
|
}
|
|
1380
|
-
function
|
|
1391
|
+
function Dn(e, n, i, r, o) {
|
|
1381
1392
|
ne.get() <= 0 || (e === C.Start ? r.linkTrack(
|
|
1382
1393
|
"agent-video",
|
|
1383
1394
|
{ event: "start", latency: ne.get(!0), "stream-type": o },
|
|
@@ -1400,10 +1411,10 @@ function He(e, n, i, r) {
|
|
|
1400
1411
|
return ne.reset(), Ve.update(), new Promise(async (o, a) => {
|
|
1401
1412
|
try {
|
|
1402
1413
|
let s, d = !1;
|
|
1403
|
-
const t =
|
|
1414
|
+
const t = vn(e, n);
|
|
1404
1415
|
i.enrich({
|
|
1405
1416
|
"stream-version": t.version.toString()
|
|
1406
|
-
}), s = await
|
|
1417
|
+
}), s = await hn(
|
|
1407
1418
|
e,
|
|
1408
1419
|
t,
|
|
1409
1420
|
{
|
|
@@ -1413,11 +1424,11 @@ function He(e, n, i, r) {
|
|
|
1413
1424
|
...n.callbacks,
|
|
1414
1425
|
onConnectionStateChange: (c, g) => {
|
|
1415
1426
|
var p, u;
|
|
1416
|
-
(u = (p = n.callbacks).onConnectionStateChange) == null || u.call(p, c),
|
|
1427
|
+
(u = (p = n.callbacks).onConnectionStateChange) == null || u.call(p, c), Cn(c, g, i), c === M.Connected && (s ? o(s) : d = !0);
|
|
1417
1428
|
},
|
|
1418
1429
|
onVideoStateChange: (c, g) => {
|
|
1419
1430
|
var p, u;
|
|
1420
|
-
(u = (p = n.callbacks).onVideoStateChange) == null || u.call(p, c),
|
|
1431
|
+
(u = (p = n.callbacks).onVideoStateChange) == null || u.call(p, c), Sn(
|
|
1421
1432
|
c,
|
|
1422
1433
|
e,
|
|
1423
1434
|
g,
|
|
@@ -1427,7 +1438,7 @@ function He(e, n, i, r) {
|
|
|
1427
1438
|
},
|
|
1428
1439
|
onAgentActivityStateChange: (c) => {
|
|
1429
1440
|
var g, p;
|
|
1430
|
-
(p = (g = n.callbacks).onAgentActivityStateChange) == null || p.call(g, c), c === H.Talking ? be.update() : be.reset(),
|
|
1441
|
+
(p = (g = n.callbacks).onAgentActivityStateChange) == null || p.call(g, c), c === H.Talking ? be.update() : be.reset(), Rn(
|
|
1431
1442
|
c === H.Talking ? C.Start : C.Stop,
|
|
1432
1443
|
e,
|
|
1433
1444
|
i,
|
|
@@ -1447,11 +1458,11 @@ function He(e, n, i, r) {
|
|
|
1447
1458
|
}
|
|
1448
1459
|
});
|
|
1449
1460
|
}
|
|
1450
|
-
async function
|
|
1461
|
+
async function En(e, n, i, r, o) {
|
|
1451
1462
|
var g, p, u, v;
|
|
1452
1463
|
const a = async () => {
|
|
1453
1464
|
if (je(e.presenter.type)) {
|
|
1454
|
-
const z = await He(e, n, r), L = `${
|
|
1465
|
+
const z = await He(e, n, r), L = `${pn}_${z.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
|
|
1455
1466
|
return { chatResult: {
|
|
1456
1467
|
chatMode: F.Functional,
|
|
1457
1468
|
chat: {
|
|
@@ -1487,13 +1498,13 @@ async function Rn(e, n, i, r, o) {
|
|
|
1487
1498
|
}, { chatResult: s, streamingManager: d } = await a(), { chat: t, chatMode: c } = s;
|
|
1488
1499
|
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (p = (g = n.callbacks).onModeChange) == null || p.call(g, c), c !== F.Functional) ? ((v = (u = n.callbacks).onError) == null || v.call(u, new dt(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
|
|
1489
1500
|
}
|
|
1490
|
-
async function
|
|
1501
|
+
async function Tn(e, n) {
|
|
1491
1502
|
var N, de, U, ee;
|
|
1492
1503
|
let i = !0, r = null;
|
|
1493
1504
|
const o = n.mixpanelKey || Rt, a = n.wsURL || kt, s = n.baseURL || Se, d = n.mode || F.Functional, t = {
|
|
1494
1505
|
messages: [],
|
|
1495
1506
|
chatMode: d
|
|
1496
|
-
}, c =
|
|
1507
|
+
}, c = xt({
|
|
1497
1508
|
token: o,
|
|
1498
1509
|
agentId: e,
|
|
1499
1510
|
isEnabled: n.enableAnalitics,
|
|
@@ -1503,11 +1514,11 @@ async function Mn(e, n) {
|
|
|
1503
1514
|
Ne(() => {
|
|
1504
1515
|
c.track("agent-sdk", { event: "init" }, g);
|
|
1505
1516
|
});
|
|
1506
|
-
const p =
|
|
1517
|
+
const p = bt(n.auth, s, n.callbacks.onError, n.externalId), u = await p.getById(e);
|
|
1507
1518
|
n.debug = n.debug || ((N = u == null ? void 0 : u.advanced_settings) == null ? void 0 : N.ui_debug_mode);
|
|
1508
1519
|
const v = je(u.presenter.type);
|
|
1509
|
-
c.enrich(
|
|
1510
|
-
const { onMessage: z, clearQueue: L } =
|
|
1520
|
+
c.enrich(Lt(u));
|
|
1521
|
+
const { onMessage: z, clearQueue: L } = cn(
|
|
1511
1522
|
c,
|
|
1512
1523
|
t,
|
|
1513
1524
|
n,
|
|
@@ -1517,7 +1528,7 @@ async function Mn(e, n) {
|
|
|
1517
1528
|
return (l = t.socketManager) == null ? void 0 : l.disconnect();
|
|
1518
1529
|
}
|
|
1519
1530
|
);
|
|
1520
|
-
t.messages =
|
|
1531
|
+
t.messages = zt(n.initialMessages), (U = (de = n.callbacks).onNewMessage) == null || U.call(de, [...t.messages], "answer");
|
|
1521
1532
|
const I = (l) => {
|
|
1522
1533
|
r = l;
|
|
1523
1534
|
}, A = ({ type: l }) => {
|
|
@@ -1527,21 +1538,21 @@ async function Mn(e, n) {
|
|
|
1527
1538
|
type: l || "click",
|
|
1528
1539
|
video_duration_to_interrupt: be.get(!0),
|
|
1529
1540
|
message_duration_to_interrupt: ne.get(!0)
|
|
1530
|
-
}), S.interrupted = !0, (V = (k = n.callbacks).onNewMessage) == null || V.call(k, [...t.messages], "answer"), v ?
|
|
1541
|
+
}), S.interrupted = !0, (V = (k = n.callbacks).onNewMessage) == null || V.call(k, [...t.messages], "answer"), v ? en(t.streamingManager) : (Gt(t.streamingManager, (P = t.streamingManager) == null ? void 0 : P.streamType, r), Zt(t.streamingManager, r));
|
|
1531
1542
|
}, T = Date.now();
|
|
1532
1543
|
Ne(() => {
|
|
1533
|
-
c.track("agent-sdk", { event: "loaded", ...
|
|
1544
|
+
c.track("agent-sdk", { event: "loaded", ...Pt(u) }, T);
|
|
1534
1545
|
});
|
|
1535
1546
|
async function E(l) {
|
|
1536
1547
|
var J, O, q, j, B, Z, oe;
|
|
1537
1548
|
(O = (J = n.callbacks).onConnectionStateChange) == null || O.call(J, M.Connecting), ne.reset(), l && !i && (delete t.chat, (j = (q = n.callbacks).onNewMessage) == null || j.call(q, [...t.messages], "answer"));
|
|
1538
|
-
const S = d === F.DirectPlayback || v ? Promise.resolve(void 0) :
|
|
1549
|
+
const S = d === F.DirectPlayback || v ? Promise.resolve(void 0) : rn(
|
|
1539
1550
|
n.auth,
|
|
1540
1551
|
a,
|
|
1541
1552
|
{ onMessage: z, onError: n.callbacks.onError },
|
|
1542
1553
|
n.externalId
|
|
1543
1554
|
), k = _e(
|
|
1544
|
-
() =>
|
|
1555
|
+
() => En(
|
|
1545
1556
|
u,
|
|
1546
1557
|
{
|
|
1547
1558
|
...n,
|
|
@@ -1810,7 +1821,7 @@ async function Mn(e, n) {
|
|
|
1810
1821
|
role: "assistant",
|
|
1811
1822
|
content: k.input,
|
|
1812
1823
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1813
|
-
}), (_ = (P = n.callbacks).onNewMessage) == null || _.call(P, [...t.messages], "answer")),
|
|
1824
|
+
}), (_ = (P = n.callbacks).onNewMessage) == null || _.call(P, [...t.messages], "answer")), It(t.chatMode))
|
|
1814
1825
|
return {
|
|
1815
1826
|
duration: 0,
|
|
1816
1827
|
video_id: "",
|
|
@@ -1850,6 +1861,6 @@ export {
|
|
|
1850
1861
|
qe as VideoType,
|
|
1851
1862
|
vt as VoiceAccess,
|
|
1852
1863
|
ut as WsError,
|
|
1853
|
-
|
|
1854
|
-
|
|
1864
|
+
Tn as createAgentManager,
|
|
1865
|
+
In as mapVideoType
|
|
1855
1866
|
};
|