@d-id/client-sdk 1.1.0-beta.5 → 1.1.0-beta.6
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var ge = Object.defineProperty;
|
|
2
2
|
var he = (e, t, n) => t in e ? ge(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
-
var
|
|
4
|
-
class
|
|
3
|
+
var H = (e, t, n) => (he(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
|
+
class Q extends Error {
|
|
5
5
|
constructor({
|
|
6
6
|
kind: n,
|
|
7
7
|
description: a,
|
|
@@ -11,13 +11,13 @@ class Y extends Error {
|
|
|
11
11
|
kind: n,
|
|
12
12
|
description: a
|
|
13
13
|
}));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
H(this, "kind");
|
|
15
|
+
H(this, "description");
|
|
16
|
+
H(this, "error");
|
|
17
17
|
this.kind = n, this.description = a, this.error = o;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
class we extends
|
|
20
|
+
class we extends Q {
|
|
21
21
|
constructor(t, n) {
|
|
22
22
|
super({
|
|
23
23
|
kind: "ChatCreationFailed",
|
|
@@ -25,7 +25,7 @@ class we extends Y {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
class pe extends
|
|
28
|
+
class pe extends Q {
|
|
29
29
|
constructor(t) {
|
|
30
30
|
super({
|
|
31
31
|
kind: "ChatModeDowngraded",
|
|
@@ -33,17 +33,17 @@ class pe extends Y {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
class
|
|
36
|
+
class F extends Q {
|
|
37
37
|
constructor(n, a) {
|
|
38
38
|
super({
|
|
39
39
|
kind: "ValidationError",
|
|
40
40
|
description: n
|
|
41
41
|
});
|
|
42
|
-
|
|
42
|
+
H(this, "key");
|
|
43
43
|
this.key = a;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
class ye extends
|
|
46
|
+
class ye extends Q {
|
|
47
47
|
constructor(t) {
|
|
48
48
|
super({
|
|
49
49
|
kind: "WSError",
|
|
@@ -51,7 +51,7 @@ class ye extends Y {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
var ve = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ve || {}), ke = /* @__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))(ke || {}),
|
|
54
|
+
var ve = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ve || {}), ke = /* @__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))(ke || {}), Ce = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ce || {}), De = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(De || {}), j = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(j || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(J || {}), Re = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Re || {}), Ee = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Ee || {}), Se = /* @__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))(Se || {}), ie = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ie || {});
|
|
55
55
|
const Me = (e) => {
|
|
56
56
|
switch (e) {
|
|
57
57
|
case "clip":
|
|
@@ -62,15 +62,15 @@ const Me = (e) => {
|
|
|
62
62
|
throw new Error(`Unknown video type: ${e}`);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
var v = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(v || {}), W = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(W || {}),
|
|
65
|
+
var v = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(v || {}), W = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(W || {}), K = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(K || {});
|
|
66
66
|
const te = {
|
|
67
67
|
"stream/started": "START",
|
|
68
68
|
"stream/done": "STOP"
|
|
69
69
|
/* Stop */
|
|
70
70
|
};
|
|
71
|
-
var
|
|
72
|
-
const Te = 45 * 1e3, je = "X-Playground-Chat",
|
|
73
|
-
function
|
|
71
|
+
var Y = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(Y || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), N = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(N || {}), _e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(_e || {}), Ie = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ie || {});
|
|
72
|
+
const Te = 45 * 1e3, je = "X-Playground-Chat", q = "https://api.d-id.com", be = "wss://notifications.d-id.com", Pe = "79f81a83a67430be2bc0fd61042b8faa", se = (e) => new Promise((t) => setTimeout(t, e)), X = () => Math.random().toString(16).slice(2), Be = (e) => [j.TextOnly, j.Playground, j.Maintenance].includes(e);
|
|
73
|
+
function $e(e, t) {
|
|
74
74
|
let n;
|
|
75
75
|
return {
|
|
76
76
|
promise: new Promise((o, s) => {
|
|
@@ -79,7 +79,7 @@ function Be(e, t) {
|
|
|
79
79
|
clear: () => clearTimeout(n)
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
async function
|
|
82
|
+
async function Z(e, t) {
|
|
83
83
|
const n = {
|
|
84
84
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
85
85
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -97,7 +97,7 @@ async function V(e, t) {
|
|
|
97
97
|
const {
|
|
98
98
|
promise: s,
|
|
99
99
|
clear: r
|
|
100
|
-
} =
|
|
100
|
+
} = $e(n.timeout, n.timeoutErrorMessage), i = e().finally(r);
|
|
101
101
|
return await Promise.race([i, s]);
|
|
102
102
|
} catch (s) {
|
|
103
103
|
if (a = s, !n.shouldRetryFn(s) || o >= n.limit)
|
|
@@ -110,28 +110,28 @@ function oe() {
|
|
|
110
110
|
let e = window.localStorage.getItem("did_external_key_id");
|
|
111
111
|
return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
|
|
112
112
|
}
|
|
113
|
-
let
|
|
113
|
+
let Le = X();
|
|
114
114
|
function ce(e) {
|
|
115
115
|
if (e.type === "bearer")
|
|
116
116
|
return `Bearer ${e.token}`;
|
|
117
117
|
if (e.type === "basic")
|
|
118
118
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
119
119
|
if (e.type === "key")
|
|
120
|
-
return `Client-Key ${e.clientKey}.${oe()}_${
|
|
120
|
+
return `Client-Key ${e.clientKey}.${oe()}_${Le}`;
|
|
121
121
|
throw new Error(`Unknown auth type: ${e}`);
|
|
122
122
|
}
|
|
123
|
-
const
|
|
123
|
+
const Ae = (e) => Z(e, {
|
|
124
124
|
limit: 3,
|
|
125
125
|
delayMs: 1e3,
|
|
126
126
|
timeout: 0,
|
|
127
127
|
shouldRetryFn: (t) => t.status === 429
|
|
128
128
|
});
|
|
129
|
-
function
|
|
129
|
+
function O(e, t = q, n) {
|
|
130
130
|
const a = async (o, s) => {
|
|
131
131
|
const {
|
|
132
132
|
skipErrorHandler: r,
|
|
133
133
|
...i
|
|
134
|
-
} = s || {}, c = await
|
|
134
|
+
} = s || {}, c = await Ae(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
135
135
|
...i,
|
|
136
136
|
headers: {
|
|
137
137
|
...i.headers,
|
|
@@ -141,12 +141,12 @@ function G(e, t = K, n) {
|
|
|
141
141
|
}));
|
|
142
142
|
if (!c.ok) {
|
|
143
143
|
let l = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
|
|
144
|
-
const
|
|
145
|
-
throw n && !r && n(
|
|
144
|
+
const u = new Error(l);
|
|
145
|
+
throw n && !r && n(u, {
|
|
146
146
|
url: o,
|
|
147
147
|
options: i,
|
|
148
148
|
headers: c.headers
|
|
149
|
-
}),
|
|
149
|
+
}), u;
|
|
150
150
|
}
|
|
151
151
|
return c.json();
|
|
152
152
|
};
|
|
@@ -180,8 +180,8 @@ function G(e, t = K, n) {
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
-
function de(e, t =
|
|
184
|
-
const a =
|
|
183
|
+
function de(e, t = q, n) {
|
|
184
|
+
const a = O(e, `${t}/agents`, n);
|
|
185
185
|
return {
|
|
186
186
|
create(o, s) {
|
|
187
187
|
return a.post("/", o, s);
|
|
@@ -219,7 +219,7 @@ function de(e, t = K, n) {
|
|
|
219
219
|
};
|
|
220
220
|
}
|
|
221
221
|
const le = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
222
|
-
function
|
|
222
|
+
function ze(e) {
|
|
223
223
|
var o, s, r, i;
|
|
224
224
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
|
|
225
225
|
const c = navigator.platform;
|
|
@@ -237,9 +237,9 @@ function Ae(e) {
|
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
const
|
|
240
|
+
const xe = (e) => e.reduce((t, n) => t + n, 0), Ne = (e) => xe(e) / e.length;
|
|
241
241
|
function Fe(e, t, n) {
|
|
242
|
-
var c, l,
|
|
242
|
+
var c, l, u;
|
|
243
243
|
const {
|
|
244
244
|
event: a,
|
|
245
245
|
...o
|
|
@@ -261,14 +261,14 @@ function Fe(e, t, n) {
|
|
|
261
261
|
language: r
|
|
262
262
|
}
|
|
263
263
|
},
|
|
264
|
-
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (
|
|
264
|
+
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
|
|
265
265
|
...n
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
|
-
let
|
|
269
|
-
const
|
|
270
|
-
function
|
|
271
|
-
var s, r, i, c, l,
|
|
268
|
+
let V = {};
|
|
269
|
+
const Je = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
270
|
+
function We(e) {
|
|
271
|
+
var s, r, i, c, l, u;
|
|
272
272
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", n = e.agent.presenter, a = (s = e.agent.llm) == null ? void 0 : s.prompt_customization, o = {
|
|
273
273
|
token: e.token || "testKey",
|
|
274
274
|
distinct_id: e.distinctId || oe(),
|
|
@@ -283,7 +283,7 @@ function Je(e) {
|
|
|
283
283
|
},
|
|
284
284
|
temperature: (c = e.agent.llm) == null ? void 0 : c.temperature,
|
|
285
285
|
knowledgeSource: a == null ? void 0 : a.knowledge_source,
|
|
286
|
-
starterQuestionsCount: (
|
|
286
|
+
starterQuestionsCount: (u = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : u.length,
|
|
287
287
|
topicsToAvoid: a == null ? void 0 : a.topics_to_avoid,
|
|
288
288
|
maxResponseLength: a == null ? void 0 : a.max_response_length
|
|
289
289
|
};
|
|
@@ -292,31 +292,31 @@ function Je(e) {
|
|
|
292
292
|
additionalProperties: {},
|
|
293
293
|
isEnabled: e.isEnabled ?? !0,
|
|
294
294
|
getRandom: () => Math.random().toString(16).slice(2),
|
|
295
|
-
enrich(
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
295
|
+
enrich(f) {
|
|
296
|
+
const k = {};
|
|
297
|
+
if (f && typeof f != "object")
|
|
298
298
|
throw new Error("properties must be a flat json object");
|
|
299
|
-
for (let
|
|
300
|
-
(typeof
|
|
299
|
+
for (let y in f)
|
|
300
|
+
(typeof f[y] == "string" || typeof f[y] == "number") && (k[y] = f[y]);
|
|
301
301
|
this.additionalProperties = {
|
|
302
302
|
...this.additionalProperties,
|
|
303
|
-
...
|
|
303
|
+
...k
|
|
304
304
|
};
|
|
305
305
|
},
|
|
306
|
-
async track(
|
|
306
|
+
async track(f, k) {
|
|
307
307
|
if (!this.isEnabled)
|
|
308
308
|
return Promise.resolve();
|
|
309
309
|
const {
|
|
310
|
-
audioPath:
|
|
310
|
+
audioPath: y,
|
|
311
311
|
...C
|
|
312
|
-
} =
|
|
312
|
+
} = k || {}, S = {
|
|
313
313
|
method: "POST",
|
|
314
314
|
headers: {
|
|
315
315
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
316
316
|
},
|
|
317
317
|
body: new URLSearchParams({
|
|
318
318
|
data: JSON.stringify([{
|
|
319
|
-
event:
|
|
319
|
+
event: f,
|
|
320
320
|
properties: {
|
|
321
321
|
...this.additionalProperties,
|
|
322
322
|
...C,
|
|
@@ -333,32 +333,32 @@ function Je(e) {
|
|
|
333
333
|
})
|
|
334
334
|
};
|
|
335
335
|
try {
|
|
336
|
-
return await fetch(
|
|
337
|
-
} catch (
|
|
338
|
-
return console.error(
|
|
336
|
+
return await fetch(Je, S).then((B) => B.json());
|
|
337
|
+
} catch (B) {
|
|
338
|
+
return console.error(B);
|
|
339
339
|
}
|
|
340
340
|
},
|
|
341
|
-
linkTrack(
|
|
342
|
-
|
|
341
|
+
linkTrack(f, k, y, C) {
|
|
342
|
+
V[f] || (V[f] = {
|
|
343
343
|
events: {},
|
|
344
344
|
resolvedDependencies: []
|
|
345
|
-
}), C.includes(
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
props:
|
|
349
|
-
},
|
|
350
|
-
const
|
|
345
|
+
}), C.includes(y) || C.push(y);
|
|
346
|
+
const S = V[f];
|
|
347
|
+
if (S.events[y] = {
|
|
348
|
+
props: k
|
|
349
|
+
}, S.resolvedDependencies.push(y), C.every((M) => S.resolvedDependencies.includes(M))) {
|
|
350
|
+
const M = C.reduce((d, w) => S.events[w] ? {
|
|
351
351
|
...d,
|
|
352
|
-
...
|
|
352
|
+
...S.events[w].props
|
|
353
353
|
} : d, {});
|
|
354
|
-
this.track(
|
|
355
|
-
delete
|
|
354
|
+
this.track(f, M), S.resolvedDependencies = S.resolvedDependencies.filter((d) => !C.includes(d)), C.forEach((d) => {
|
|
355
|
+
delete S.events[d];
|
|
356
356
|
});
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
};
|
|
360
360
|
}
|
|
361
|
-
function
|
|
361
|
+
function Ue() {
|
|
362
362
|
let e = 0;
|
|
363
363
|
return {
|
|
364
364
|
reset: () => e = 0,
|
|
@@ -366,9 +366,9 @@ function We() {
|
|
|
366
366
|
get: (t = !1) => t ? Date.now() - e : e
|
|
367
367
|
};
|
|
368
368
|
}
|
|
369
|
-
const
|
|
369
|
+
const x = Ue();
|
|
370
370
|
function ue(e) {
|
|
371
|
-
return e ===
|
|
371
|
+
return e === j.Playground ? {
|
|
372
372
|
headers: {
|
|
373
373
|
[je]: "true"
|
|
374
374
|
}
|
|
@@ -376,7 +376,7 @@ function ue(e) {
|
|
|
376
376
|
}
|
|
377
377
|
async function fe(e, t, n, a, o = !1, s) {
|
|
378
378
|
try {
|
|
379
|
-
return !s && a !==
|
|
379
|
+
return !s && a !== j.DirectPlayback && (s = await t.newChat(e.id, {
|
|
380
380
|
persist: o
|
|
381
381
|
}, ue(a)), n.track("agent-chat", {
|
|
382
382
|
event: "created",
|
|
@@ -398,10 +398,10 @@ async function fe(e, t, n, a, o = !1, s) {
|
|
|
398
398
|
throw new Error("Cannot create new chat");
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
|
-
function
|
|
401
|
+
function He(e) {
|
|
402
402
|
return e && e.length > 0 ? e : [];
|
|
403
403
|
}
|
|
404
|
-
function
|
|
404
|
+
function Ke(e) {
|
|
405
405
|
return new Promise((t, n) => {
|
|
406
406
|
const {
|
|
407
407
|
callbacks: a,
|
|
@@ -412,22 +412,22 @@ function He(e) {
|
|
|
412
412
|
onOpen: i = null,
|
|
413
413
|
onClose: c = null,
|
|
414
414
|
onError: l = null
|
|
415
|
-
} = a || {},
|
|
416
|
-
|
|
417
|
-
console.error(
|
|
418
|
-
},
|
|
419
|
-
i == null || i(
|
|
415
|
+
} = a || {}, u = new WebSocket(`${o}?authorization=${ce(s)}`);
|
|
416
|
+
u.onmessage = r, u.onclose = c, u.onerror = (f) => {
|
|
417
|
+
console.error(f), l == null || l("Websocket failed to connect", f), n(f);
|
|
418
|
+
}, u.onopen = (f) => {
|
|
419
|
+
i == null || i(f), t(u);
|
|
420
420
|
};
|
|
421
421
|
});
|
|
422
422
|
}
|
|
423
|
-
async function
|
|
423
|
+
async function qe(e) {
|
|
424
424
|
const {
|
|
425
425
|
retries: t = 1
|
|
426
426
|
} = e;
|
|
427
427
|
let n = null;
|
|
428
428
|
for (let a = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; a++)
|
|
429
429
|
try {
|
|
430
|
-
n = await
|
|
430
|
+
n = await Ke(e);
|
|
431
431
|
} catch (o) {
|
|
432
432
|
if (a === t)
|
|
433
433
|
throw o;
|
|
@@ -435,8 +435,8 @@ async function Ke(e) {
|
|
|
435
435
|
}
|
|
436
436
|
return n;
|
|
437
437
|
}
|
|
438
|
-
async function
|
|
439
|
-
const a = n != null && n.onMessage ? [n.onMessage] : [], o = await
|
|
438
|
+
async function Xe(e, t, n) {
|
|
439
|
+
const a = n != null && n.onMessage ? [n.onMessage] : [], o = await qe({
|
|
440
440
|
auth: e,
|
|
441
441
|
host: t,
|
|
442
442
|
callbacks: {
|
|
@@ -456,7 +456,7 @@ async function qe(e, t, n) {
|
|
|
456
456
|
subscribeToEvents: (s) => a.push(s)
|
|
457
457
|
};
|
|
458
458
|
}
|
|
459
|
-
function
|
|
459
|
+
function Ye(e) {
|
|
460
460
|
if (e.answer !== void 0)
|
|
461
461
|
return e.answer;
|
|
462
462
|
let t = 0, n = "";
|
|
@@ -464,7 +464,7 @@ function Xe(e) {
|
|
|
464
464
|
n += e[t++];
|
|
465
465
|
return n;
|
|
466
466
|
}
|
|
467
|
-
function
|
|
467
|
+
function Qe(e, t, n, a, o) {
|
|
468
468
|
const s = a.messages[a.messages.length - 1];
|
|
469
469
|
if (!(e === J.Partial || e === J.Answer) || (s == null ? void 0 : s.role) !== "assistant")
|
|
470
470
|
return;
|
|
@@ -473,45 +473,45 @@ function Ye(e, t, n, a, o) {
|
|
|
473
473
|
sequence: i
|
|
474
474
|
} = t;
|
|
475
475
|
e === J.Partial ? n[i] = r : n.answer = r;
|
|
476
|
-
const c =
|
|
476
|
+
const c = Ye(n);
|
|
477
477
|
(s.content !== c || e === J.Answer) && (s.content = c, o == null || o([...a.messages], e));
|
|
478
478
|
}
|
|
479
|
-
function
|
|
479
|
+
function Ve(e, t, n, a, o) {
|
|
480
480
|
let s = {};
|
|
481
481
|
return {
|
|
482
482
|
clearQueue: () => s = {},
|
|
483
483
|
onMessage: (r, i) => {
|
|
484
484
|
var c, l;
|
|
485
485
|
if ("content" in i)
|
|
486
|
-
|
|
486
|
+
Qe(r, i, s, t, n.callbacks.onNewMessage), r === J.Answer && e.track("agent-message-received", {
|
|
487
487
|
messages: t.messages.length,
|
|
488
488
|
mode: t.chatMode
|
|
489
489
|
});
|
|
490
490
|
else {
|
|
491
|
-
const
|
|
491
|
+
const u = Y, f = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], k = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], y = Fe(i, a, {
|
|
492
492
|
mode: t.chatMode
|
|
493
493
|
});
|
|
494
|
-
if (r = r, r ===
|
|
495
|
-
e.linkTrack("agent-video",
|
|
496
|
-
else if (
|
|
494
|
+
if (r = r, r === u.StreamVideoCreated)
|
|
495
|
+
e.linkTrack("agent-video", y, u.StreamVideoCreated, ["start"]);
|
|
496
|
+
else if (f.includes(r)) {
|
|
497
497
|
const C = r.split("/")[1];
|
|
498
|
-
|
|
499
|
-
...
|
|
498
|
+
k.includes(r) ? e.track("agent-video", {
|
|
499
|
+
...y,
|
|
500
500
|
event: C
|
|
501
501
|
}) : e.linkTrack("agent-video", {
|
|
502
|
-
...
|
|
502
|
+
...y,
|
|
503
503
|
event: C
|
|
504
504
|
}, r, ["done"]);
|
|
505
505
|
}
|
|
506
|
-
|
|
506
|
+
k.includes(r) && ((l = (c = n.callbacks).onError) == null || l.call(c, new Error(`Stream failed with event ${r}`), {
|
|
507
507
|
data: i
|
|
508
|
-
})), i.event ===
|
|
508
|
+
})), i.event === u.StreamDone && o();
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
};
|
|
512
512
|
}
|
|
513
|
-
function
|
|
514
|
-
const o =
|
|
513
|
+
function Ze(e, t, n, a) {
|
|
514
|
+
const o = O(e, `${t}/agents/${n}`, a);
|
|
515
515
|
return {
|
|
516
516
|
createStream(s) {
|
|
517
517
|
return o.post("/streams", {
|
|
@@ -547,8 +547,8 @@ function Ve(e, t, n, a) {
|
|
|
547
547
|
}
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
|
-
function
|
|
551
|
-
const o =
|
|
550
|
+
function Ge(e, t, n, a) {
|
|
551
|
+
const o = O(e, `${t}/agents/${n}`, a);
|
|
552
552
|
return {
|
|
553
553
|
createStream(s, r) {
|
|
554
554
|
return o.post("/streams", {
|
|
@@ -587,7 +587,7 @@ function Ze(e, t, n, a) {
|
|
|
587
587
|
}
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
|
-
function
|
|
590
|
+
function Oe(e, t, n) {
|
|
591
591
|
const a = (t.timestamp - e.timestamp) / 1e3;
|
|
592
592
|
return {
|
|
593
593
|
duration: a,
|
|
@@ -607,7 +607,7 @@ function Ge(e, t, n) {
|
|
|
607
607
|
lowFpsCount: n
|
|
608
608
|
};
|
|
609
609
|
}
|
|
610
|
-
function
|
|
610
|
+
function et(e) {
|
|
611
611
|
return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
|
|
612
612
|
const {
|
|
613
613
|
timestamp: n,
|
|
@@ -619,7 +619,7 @@ function Oe(e) {
|
|
|
619
619
|
};
|
|
620
620
|
});
|
|
621
621
|
}
|
|
622
|
-
function
|
|
622
|
+
function tt(e) {
|
|
623
623
|
let t = "";
|
|
624
624
|
for (const n of e.values())
|
|
625
625
|
if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "inbound-rtp" && n.kind === "video")
|
|
@@ -643,7 +643,7 @@ function et(e) {
|
|
|
643
643
|
};
|
|
644
644
|
return {};
|
|
645
645
|
}
|
|
646
|
-
function
|
|
646
|
+
function rt(e, t, n) {
|
|
647
647
|
const a = e.map((i, c) => c === 0 ? n ? {
|
|
648
648
|
timestamp: i.timestamp,
|
|
649
649
|
duration: 0,
|
|
@@ -692,11 +692,11 @@ function tt(e, t, n) {
|
|
|
692
692
|
framesPerSecond: i.framesPerSecond,
|
|
693
693
|
freezeCount: i.freezeCount - e[c - 1].freezeCount,
|
|
694
694
|
freezeDuration: i.freezeDuration - e[c - 1].freezeDuration
|
|
695
|
-
}), o =
|
|
695
|
+
}), o = et(a), s = o.reduce((i, c) => i + (c.causes.includes("low fps") ? 1 : 0), 0), r = a.map((i) => i.avgJitterDelayInInterval);
|
|
696
696
|
return {
|
|
697
697
|
webRTCStats: {
|
|
698
698
|
anomalies: o,
|
|
699
|
-
aggregateReport:
|
|
699
|
+
aggregateReport: Oe(e[0], e[e.length - 1], s),
|
|
700
700
|
minJitterDelayInInterval: Math.min(...r),
|
|
701
701
|
maxJitterDelayInInterval: Math.max(...r),
|
|
702
702
|
avgJitterDelayInInterval: Ne(r)
|
|
@@ -705,16 +705,16 @@ function tt(e, t, n) {
|
|
|
705
705
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
|
-
const
|
|
709
|
-
function
|
|
708
|
+
const G = 100, nt = Math.max(Math.ceil(400 / G), 1), at = 0.25, it = 0.28;
|
|
709
|
+
function st() {
|
|
710
710
|
let e = 0, t, n, a = 0;
|
|
711
711
|
return (o) => {
|
|
712
712
|
for (const s of o.values())
|
|
713
713
|
if (s && s.type === "inbound-rtp" && s.kind === "video") {
|
|
714
714
|
const r = s.jitterBufferDelay, i = s.jitterBufferEmittedCount;
|
|
715
715
|
if (n && i > n) {
|
|
716
|
-
const
|
|
717
|
-
a =
|
|
716
|
+
const u = r - t, f = i - n;
|
|
717
|
+
a = u / f;
|
|
718
718
|
}
|
|
719
719
|
t = r, n = i;
|
|
720
720
|
const c = s.framesDecoded, l = c - e > 0;
|
|
@@ -730,46 +730,46 @@ function it() {
|
|
|
730
730
|
};
|
|
731
731
|
};
|
|
732
732
|
}
|
|
733
|
-
function
|
|
734
|
-
let r = [], i, c = 0, l = !1,
|
|
735
|
-
const C =
|
|
733
|
+
function ot(e, t, n, a, o, s = !1) {
|
|
734
|
+
let r = [], i, c = 0, l = !1, u = W.Unknown, f = W.Unknown, k = 0, y = 0;
|
|
735
|
+
const C = st();
|
|
736
736
|
return setInterval(async () => {
|
|
737
|
-
const
|
|
738
|
-
isReceiving:
|
|
739
|
-
avgJitterDelayInInterval:
|
|
737
|
+
const S = await e.getStats(), {
|
|
738
|
+
isReceiving: B,
|
|
739
|
+
avgJitterDelayInInterval: M,
|
|
740
740
|
freezeCount: d
|
|
741
|
-
} = C(
|
|
742
|
-
if (
|
|
743
|
-
c = 0,
|
|
744
|
-
else if (l && (c++, c >=
|
|
745
|
-
const
|
|
746
|
-
a == null || a(v.Stop,
|
|
741
|
+
} = C(S), w = tt(S);
|
|
742
|
+
if (B)
|
|
743
|
+
c = 0, k = d - y, f = M < at ? W.Strong : M > it && k > 1 ? W.Weak : u, f !== u && (o == null || o(f), u = f, y += k, k = 0), l || (a == null || a(v.Start), i = r[r.length - 1], r = [], l = !0), r.push(w);
|
|
744
|
+
else if (l && (c++, c >= nt)) {
|
|
745
|
+
const h = rt(r, G, i);
|
|
746
|
+
a == null || a(v.Stop, h), t() || n(), l = !1;
|
|
747
747
|
}
|
|
748
|
-
},
|
|
748
|
+
}, G);
|
|
749
749
|
}
|
|
750
750
|
let me = !1;
|
|
751
|
-
const z = (e, t) => me && console.log(e, t),
|
|
751
|
+
const z = (e, t) => me && console.log(e, t), ct = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
752
752
|
function re(e) {
|
|
753
753
|
switch (e) {
|
|
754
754
|
case "connected":
|
|
755
|
-
return
|
|
755
|
+
return I.Connected;
|
|
756
756
|
case "checking":
|
|
757
|
-
return
|
|
757
|
+
return I.Connecting;
|
|
758
758
|
case "failed":
|
|
759
|
-
return
|
|
759
|
+
return I.Fail;
|
|
760
760
|
case "new":
|
|
761
|
-
return
|
|
761
|
+
return I.New;
|
|
762
762
|
case "closed":
|
|
763
|
-
return
|
|
763
|
+
return I.Closed;
|
|
764
764
|
case "disconnected":
|
|
765
|
-
return
|
|
765
|
+
return I.Disconnected;
|
|
766
766
|
case "completed":
|
|
767
|
-
return
|
|
767
|
+
return I.Completed;
|
|
768
768
|
default:
|
|
769
|
-
return
|
|
769
|
+
return I.New;
|
|
770
770
|
}
|
|
771
771
|
}
|
|
772
|
-
function
|
|
772
|
+
function dt({
|
|
773
773
|
statsSignal: e,
|
|
774
774
|
dataChannelSignal: t,
|
|
775
775
|
onVideoStateChange: n,
|
|
@@ -777,14 +777,14 @@ function ct({
|
|
|
777
777
|
}) {
|
|
778
778
|
e === v.Start && t === v.Start ? n == null || n(v.Start) : e === v.Stop && t === v.Stop && (n == null || n(v.Stop, a));
|
|
779
779
|
}
|
|
780
|
-
function
|
|
780
|
+
function lt({
|
|
781
781
|
statsSignal: e,
|
|
782
782
|
dataChannelSignal: t,
|
|
783
783
|
onVideoStateChange: n,
|
|
784
784
|
onAgentActivityStateChange: a,
|
|
785
785
|
report: o
|
|
786
786
|
}) {
|
|
787
|
-
e === v.Start ? n == null || n(v.Start) : e === v.Stop && (n == null || n(v.Stop, o)), t === v.Start ? a == null || a(
|
|
787
|
+
e === v.Start ? n == null || n(v.Start) : e === v.Stop && (n == null || n(v.Stop, o)), t === v.Start ? a == null || a(K.Talking) : t === v.Stop && (a == null || a(K.Idle));
|
|
788
788
|
}
|
|
789
789
|
function ne({
|
|
790
790
|
statsSignal: e,
|
|
@@ -794,12 +794,12 @@ function ne({
|
|
|
794
794
|
streamType: o,
|
|
795
795
|
report: s
|
|
796
796
|
}) {
|
|
797
|
-
o ===
|
|
797
|
+
o === N.Legacy ? dt({
|
|
798
798
|
statsSignal: e,
|
|
799
799
|
dataChannelSignal: t,
|
|
800
800
|
onVideoStateChange: n,
|
|
801
801
|
report: s
|
|
802
|
-
}) : o ===
|
|
802
|
+
}) : o === N.Fluent && lt({
|
|
803
803
|
statsSignal: e,
|
|
804
804
|
dataChannelSignal: t,
|
|
805
805
|
onVideoStateChange: n,
|
|
@@ -807,124 +807,129 @@ function ne({
|
|
|
807
807
|
report: s
|
|
808
808
|
});
|
|
809
809
|
}
|
|
810
|
-
async function
|
|
810
|
+
async function ut(e, t, {
|
|
811
811
|
debug: n = !1,
|
|
812
812
|
callbacks: a,
|
|
813
813
|
auth: o,
|
|
814
|
-
baseURL: s =
|
|
814
|
+
baseURL: s = q,
|
|
815
|
+
analytics: r
|
|
815
816
|
}) {
|
|
816
817
|
me = n;
|
|
817
|
-
let
|
|
818
|
+
let i = !1, c = !1, l = v.Stop, u = v.Stop, f = W.Unknown;
|
|
818
819
|
const {
|
|
819
|
-
startConnection:
|
|
820
|
-
sendStreamRequest:
|
|
821
|
-
close:
|
|
822
|
-
createStream:
|
|
823
|
-
addIceCandidate:
|
|
824
|
-
} = t.videoType === ie.Clip ?
|
|
825
|
-
id:
|
|
826
|
-
offer:
|
|
827
|
-
ice_servers:
|
|
828
|
-
session_id:
|
|
829
|
-
fluent:
|
|
830
|
-
} = await
|
|
831
|
-
iceServers:
|
|
832
|
-
}),
|
|
833
|
-
if (!
|
|
820
|
+
startConnection: k,
|
|
821
|
+
sendStreamRequest: y,
|
|
822
|
+
close: C,
|
|
823
|
+
createStream: S,
|
|
824
|
+
addIceCandidate: B
|
|
825
|
+
} = t.videoType === ie.Clip ? Ze(o, s, e, a.onError) : Ge(o, s, e, a.onError), {
|
|
826
|
+
id: M,
|
|
827
|
+
offer: d,
|
|
828
|
+
ice_servers: w,
|
|
829
|
+
session_id: h,
|
|
830
|
+
fluent: b
|
|
831
|
+
} = await S(t), g = new ct({
|
|
832
|
+
iceServers: w
|
|
833
|
+
}), D = g.createDataChannel("JanusDataChannel");
|
|
834
|
+
if (!h)
|
|
834
835
|
throw new Error("Could not create session_id");
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
|
|
836
|
+
const _ = b ? N.Fluent : N.Legacy;
|
|
837
|
+
r.enrich({
|
|
838
|
+
"stream-type": _
|
|
839
|
+
});
|
|
840
|
+
const P = t.stream_warmup && !b, L = () => i, R = () => {
|
|
841
|
+
var m;
|
|
842
|
+
i = !0, c && ((m = a.onConnectionStateChange) == null || m.call(a, I.Connected));
|
|
843
|
+
}, T = ot(g, L, R, (m, p) => ne({
|
|
844
|
+
statsSignal: u = m,
|
|
845
|
+
dataChannelSignal: _ === N.Legacy ? l : void 0,
|
|
841
846
|
onVideoStateChange: a.onVideoStateChange,
|
|
842
847
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
843
848
|
report: p,
|
|
844
|
-
streamType:
|
|
845
|
-
}), (
|
|
849
|
+
streamType: _
|
|
850
|
+
}), (m) => {
|
|
846
851
|
var p;
|
|
847
852
|
return (p = a.onConnectivityStateChange) == null ? void 0 : p.call(a, f);
|
|
848
|
-
},
|
|
849
|
-
|
|
853
|
+
}, P);
|
|
854
|
+
g.onicecandidate = (m) => {
|
|
850
855
|
var p;
|
|
851
|
-
z("peerConnection.onicecandidate",
|
|
856
|
+
z("peerConnection.onicecandidate", m);
|
|
852
857
|
try {
|
|
853
|
-
|
|
854
|
-
candidate:
|
|
855
|
-
sdpMid:
|
|
856
|
-
sdpMLineIndex:
|
|
857
|
-
},
|
|
858
|
+
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? B(M, {
|
|
859
|
+
candidate: m.candidate.candidate,
|
|
860
|
+
sdpMid: m.candidate.sdpMid,
|
|
861
|
+
sdpMLineIndex: m.candidate.sdpMLineIndex
|
|
862
|
+
}, h) : B(M, {
|
|
858
863
|
candidate: null
|
|
859
|
-
},
|
|
860
|
-
} catch (
|
|
861
|
-
(p = a.onError) == null || p.call(a,
|
|
862
|
-
streamId:
|
|
864
|
+
}, h);
|
|
865
|
+
} catch ($) {
|
|
866
|
+
(p = a.onError) == null || p.call(a, $, {
|
|
867
|
+
streamId: M
|
|
863
868
|
});
|
|
864
869
|
}
|
|
865
|
-
},
|
|
866
|
-
|
|
867
|
-
},
|
|
868
|
-
|
|
869
|
-
statsSignal:
|
|
870
|
-
dataChannelSignal:
|
|
870
|
+
}, D.onopen = () => {
|
|
871
|
+
c = !0, (!P || i) && R();
|
|
872
|
+
}, D.onmessage = (m) => {
|
|
873
|
+
m.data in te && (l = te[m.data], ne({
|
|
874
|
+
statsSignal: _ === N.Legacy ? u : void 0,
|
|
875
|
+
dataChannelSignal: l,
|
|
871
876
|
onVideoStateChange: a.onVideoStateChange,
|
|
872
877
|
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
873
|
-
streamType:
|
|
878
|
+
streamType: _
|
|
874
879
|
}));
|
|
875
|
-
},
|
|
880
|
+
}, g.oniceconnectionstatechange = () => {
|
|
876
881
|
var p;
|
|
877
|
-
z("peerConnection.oniceconnectionstatechange => " +
|
|
878
|
-
const
|
|
879
|
-
|
|
880
|
-
},
|
|
882
|
+
z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
883
|
+
const m = re(g.iceConnectionState);
|
|
884
|
+
m !== I.Connected && ((p = a.onConnectionStateChange) == null || p.call(a, m));
|
|
885
|
+
}, g.ontrack = (m) => {
|
|
881
886
|
var p;
|
|
882
|
-
z("peerConnection.ontrack",
|
|
883
|
-
}, await
|
|
884
|
-
const
|
|
885
|
-
return z("create answer OK"), await
|
|
887
|
+
z("peerConnection.ontrack", m), (p = a.onSrcObjectReady) == null || p.call(a, m.streams[0]);
|
|
888
|
+
}, await g.setRemoteDescription(d), z("set remote description OK");
|
|
889
|
+
const E = await g.createAnswer();
|
|
890
|
+
return z("create answer OK"), await g.setLocalDescription(E), z("set local description OK"), await k(M, E, h), z("start connection OK"), {
|
|
886
891
|
/**
|
|
887
892
|
* Method to send request to server to get clip or talk depend on you payload
|
|
888
893
|
* @param payload
|
|
889
894
|
*/
|
|
890
|
-
speak(
|
|
891
|
-
return
|
|
895
|
+
speak(m) {
|
|
896
|
+
return y(M, h, m);
|
|
892
897
|
},
|
|
893
898
|
/**
|
|
894
899
|
* Method to close RTC connection
|
|
895
900
|
*/
|
|
896
901
|
async disconnect() {
|
|
897
|
-
var
|
|
898
|
-
if (
|
|
899
|
-
const
|
|
900
|
-
if (
|
|
901
|
-
if (
|
|
902
|
-
(
|
|
902
|
+
var m, p, $;
|
|
903
|
+
if (M) {
|
|
904
|
+
const A = re(g.iceConnectionState);
|
|
905
|
+
if (g) {
|
|
906
|
+
if (A === I.New) {
|
|
907
|
+
(m = a.onVideoStateChange) == null || m.call(a, v.Stop), clearInterval(T);
|
|
903
908
|
return;
|
|
904
909
|
}
|
|
905
|
-
|
|
910
|
+
g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
|
|
906
911
|
}
|
|
907
912
|
try {
|
|
908
|
-
|
|
913
|
+
A === I.Connected && await C(M, h).catch((U) => {
|
|
909
914
|
});
|
|
910
|
-
} catch (
|
|
911
|
-
z("Error on close stream connection",
|
|
915
|
+
} catch (U) {
|
|
916
|
+
z("Error on close stream connection", U);
|
|
912
917
|
}
|
|
913
|
-
(p = a.onVideoStateChange) == null || p.call(a, v.Stop), (
|
|
918
|
+
(p = a.onVideoStateChange) == null || p.call(a, v.Stop), ($ = a.onAgentActivityStateChange) == null || $.call(a, K.Idle), clearInterval(T);
|
|
914
919
|
}
|
|
915
920
|
},
|
|
916
921
|
/**
|
|
917
922
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
918
923
|
*/
|
|
919
|
-
sessionId:
|
|
924
|
+
sessionId: h,
|
|
920
925
|
/**
|
|
921
926
|
* Id of current RTC stream
|
|
922
927
|
*/
|
|
923
|
-
streamId:
|
|
924
|
-
streamType:
|
|
928
|
+
streamId: M,
|
|
929
|
+
streamType: _
|
|
925
930
|
};
|
|
926
931
|
}
|
|
927
|
-
function
|
|
932
|
+
function ft(e, t) {
|
|
928
933
|
const {
|
|
929
934
|
streamOptions: n
|
|
930
935
|
} = t ?? {};
|
|
@@ -938,29 +943,29 @@ function ut(e, t) {
|
|
|
938
943
|
};
|
|
939
944
|
}
|
|
940
945
|
function ae(e, t, n, a, o) {
|
|
941
|
-
|
|
946
|
+
x.get() > 0 && (e === v.Start ? a.linkTrack("agent-video", {
|
|
942
947
|
event: "start",
|
|
943
|
-
latency:
|
|
948
|
+
latency: x.get(!0),
|
|
944
949
|
"stream-type": o
|
|
945
|
-
}, "start", [
|
|
950
|
+
}, "start", [Y.StreamVideoCreated]) : e === v.Stop && a.linkTrack("agent-video", {
|
|
946
951
|
event: "stop",
|
|
947
952
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
948
953
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
949
954
|
"stream-type": o,
|
|
950
955
|
...n
|
|
951
|
-
}, "done", [
|
|
956
|
+
}, "done", [Y.StreamVideoDone]));
|
|
952
957
|
}
|
|
953
|
-
function
|
|
954
|
-
return
|
|
958
|
+
function mt(e, t, n) {
|
|
959
|
+
return x.reset(), new Promise(async (a, o) => {
|
|
955
960
|
try {
|
|
956
|
-
const s = await
|
|
961
|
+
const s = await ut(e.id, ft(e, t), {
|
|
957
962
|
...t,
|
|
958
963
|
analytics: n,
|
|
959
964
|
callbacks: {
|
|
960
965
|
...t.callbacks,
|
|
961
966
|
onConnectionStateChange: (r) => {
|
|
962
967
|
var i, c;
|
|
963
|
-
(c = (i = t.callbacks).onConnectionStateChange) == null || c.call(i, r), r ===
|
|
968
|
+
(c = (i = t.callbacks).onConnectionStateChange) == null || c.call(i, r), r === I.Connected && a(s);
|
|
964
969
|
},
|
|
965
970
|
onVideoStateChange: (r, i) => {
|
|
966
971
|
var c, l;
|
|
@@ -968,7 +973,7 @@ function ft(e, t, n) {
|
|
|
968
973
|
},
|
|
969
974
|
onAgentActivityStateChange: (r) => {
|
|
970
975
|
var i, c;
|
|
971
|
-
(c = (i = t.callbacks).onAgentActivityStateChange) == null || c.call(i, r), ae(r ===
|
|
976
|
+
(c = (i = t.callbacks).onAgentActivityStateChange) == null || c.call(i, r), ae(r === K.Talking ? v.Start : v.Stop, e, void 0, n, s.streamType);
|
|
972
977
|
}
|
|
973
978
|
}
|
|
974
979
|
});
|
|
@@ -977,75 +982,75 @@ function ft(e, t, n) {
|
|
|
977
982
|
}
|
|
978
983
|
});
|
|
979
984
|
}
|
|
980
|
-
async function
|
|
981
|
-
var c, l,
|
|
985
|
+
async function gt(e, t, n, a, o) {
|
|
986
|
+
var c, l, u, f;
|
|
982
987
|
const {
|
|
983
988
|
chat: s,
|
|
984
989
|
chatMode: r
|
|
985
990
|
} = await fe(e, n, a, t.mode, t.persistentChat, o);
|
|
986
|
-
if (r && r !== t.mode && (t.mode = r, (l = (c = t.callbacks).onModeChange) == null || l.call(c, r), r ===
|
|
987
|
-
return (
|
|
991
|
+
if (r && r !== t.mode && (t.mode = r, (l = (c = t.callbacks).onModeChange) == null || l.call(c, r), r === j.TextOnly))
|
|
992
|
+
return (f = (u = t.callbacks).onError) == null || f.call(u, new pe(r)), {
|
|
988
993
|
chat: s
|
|
989
994
|
};
|
|
990
|
-
const i = await
|
|
995
|
+
const i = await mt(e, t, a);
|
|
991
996
|
return {
|
|
992
997
|
chat: s,
|
|
993
998
|
streamingManager: i
|
|
994
999
|
};
|
|
995
1000
|
}
|
|
996
|
-
async function
|
|
997
|
-
var
|
|
1001
|
+
async function wt(e, t) {
|
|
1002
|
+
var S, B, M;
|
|
998
1003
|
let n = !0;
|
|
999
|
-
const a = t.mixpanelKey || Pe, o = t.wsURL || be, s = t.baseURL ||
|
|
1004
|
+
const a = t.mixpanelKey || Pe, o = t.wsURL || be, s = t.baseURL || q, r = {
|
|
1000
1005
|
messages: [],
|
|
1001
|
-
chatMode: t.mode ||
|
|
1002
|
-
}, i = de(t.auth, s, t.callbacks.onError), c = await i.getById(e), l =
|
|
1006
|
+
chatMode: t.mode || j.Functional
|
|
1007
|
+
}, i = de(t.auth, s, t.callbacks.onError), c = await i.getById(e), l = We({
|
|
1003
1008
|
token: a,
|
|
1004
1009
|
agent: c,
|
|
1005
1010
|
isEnabled: t.enableAnalitics,
|
|
1006
1011
|
distinctId: t.distinctId
|
|
1007
1012
|
}), {
|
|
1008
|
-
onMessage:
|
|
1009
|
-
clearQueue:
|
|
1010
|
-
} =
|
|
1013
|
+
onMessage: u,
|
|
1014
|
+
clearQueue: f
|
|
1015
|
+
} = Ve(l, r, t, c, () => {
|
|
1011
1016
|
var d;
|
|
1012
1017
|
return (d = r.socketManager) == null ? void 0 : d.disconnect();
|
|
1013
1018
|
});
|
|
1014
|
-
r.messages =
|
|
1019
|
+
r.messages = He(t.initialMessages), (B = (S = t.callbacks).onNewMessage) == null || B.call(S, [...r.messages], "answer"), l.track("agent-sdk", {
|
|
1015
1020
|
event: "loaded",
|
|
1016
|
-
...
|
|
1021
|
+
...ze(c)
|
|
1017
1022
|
});
|
|
1018
|
-
async function
|
|
1019
|
-
var
|
|
1020
|
-
(
|
|
1021
|
-
const
|
|
1022
|
-
onMessage:
|
|
1023
|
+
async function k(d) {
|
|
1024
|
+
var _, P, L, R, T, E, m;
|
|
1025
|
+
(P = (_ = t.callbacks).onConnectionStateChange) == null || P.call(_, I.Connecting), x.reset(), d && !n && (delete r.chat, (R = (L = t.callbacks).onNewMessage) == null || R.call(L, [...r.messages], "answer"));
|
|
1026
|
+
const w = t.mode === j.DirectPlayback ? Promise.resolve(void 0) : Xe(t.auth, o, {
|
|
1027
|
+
onMessage: u,
|
|
1023
1028
|
onError: t.callbacks.onError
|
|
1024
|
-
}),
|
|
1029
|
+
}), h = Z(() => gt(c, t, i, l, r.chat), {
|
|
1025
1030
|
limit: 3,
|
|
1026
1031
|
timeout: Te,
|
|
1027
1032
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1028
1033
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1029
|
-
shouldRetryFn: (
|
|
1034
|
+
shouldRetryFn: (p) => (p == null ? void 0 : p.message) !== "Could not connect" && p.status !== 429,
|
|
1030
1035
|
delayMs: 1e3
|
|
1031
|
-
}).catch((
|
|
1032
|
-
var
|
|
1033
|
-
throw C(
|
|
1034
|
-
}), [
|
|
1035
|
-
streamingManager:
|
|
1036
|
-
chat:
|
|
1037
|
-
}] = await Promise.all([
|
|
1038
|
-
|
|
1036
|
+
}).catch((p) => {
|
|
1037
|
+
var $, A;
|
|
1038
|
+
throw C(j.Maintenance), (A = ($ = t.callbacks).onConnectionStateChange) == null || A.call($, I.Fail), p;
|
|
1039
|
+
}), [b, {
|
|
1040
|
+
streamingManager: g,
|
|
1041
|
+
chat: D
|
|
1042
|
+
}] = await Promise.all([w, h]);
|
|
1043
|
+
D && D.id !== ((T = r.chat) == null ? void 0 : T.id) && ((m = (E = t.callbacks).onNewChat) == null || m.call(E, D.id)), r.streamingManager = g, r.socketManager = b, r.chat = D, n = !1, C((D == null ? void 0 : D.chat_mode) ?? t.mode ?? j.Functional);
|
|
1039
1044
|
}
|
|
1040
|
-
async function
|
|
1041
|
-
var d,
|
|
1042
|
-
(d = r.socketManager) == null || d.disconnect(), await ((
|
|
1045
|
+
async function y() {
|
|
1046
|
+
var d, w, h, b;
|
|
1047
|
+
(d = r.socketManager) == null || d.disconnect(), await ((w = r.streamingManager) == null ? void 0 : w.disconnect()), delete r.streamingManager, delete r.socketManager, (b = (h = t.callbacks).onConnectionStateChange) == null || b.call(h, I.Disconnected);
|
|
1043
1048
|
}
|
|
1044
1049
|
async function C(d) {
|
|
1045
|
-
var
|
|
1050
|
+
var w, h;
|
|
1046
1051
|
d !== r.chatMode && (l.track("agent-mode-change", {
|
|
1047
1052
|
mode: d
|
|
1048
|
-
}), r.chatMode = d, r.chatMode !==
|
|
1053
|
+
}), r.chatMode = d, r.chatMode !== j.Functional && await y(), (h = (w = t.callbacks).onModeChange) == null || h.call(w, d));
|
|
1049
1054
|
}
|
|
1050
1055
|
return {
|
|
1051
1056
|
agent: c,
|
|
@@ -1053,13 +1058,13 @@ async function ht(e, t) {
|
|
|
1053
1058
|
var d;
|
|
1054
1059
|
return (d = r.streamingManager) == null ? void 0 : d.streamType;
|
|
1055
1060
|
},
|
|
1056
|
-
starterMessages: ((
|
|
1061
|
+
starterMessages: ((M = c.knowledge) == null ? void 0 : M.starter_message) || [],
|
|
1057
1062
|
getSTTToken: () => i.getSTTToken(c.id),
|
|
1058
1063
|
changeMode: C,
|
|
1059
1064
|
enrichAnalytics: l.enrich,
|
|
1060
1065
|
async connect() {
|
|
1061
1066
|
var d;
|
|
1062
|
-
await
|
|
1067
|
+
await k(!0), l.track("agent-chat", {
|
|
1063
1068
|
event: "connect",
|
|
1064
1069
|
chatId: (d = r.chat) == null ? void 0 : d.id,
|
|
1065
1070
|
agentId: c.id,
|
|
@@ -1068,7 +1073,7 @@ async function ht(e, t) {
|
|
|
1068
1073
|
},
|
|
1069
1074
|
async reconnect() {
|
|
1070
1075
|
var d;
|
|
1071
|
-
await
|
|
1076
|
+
await y(), await k(!1), l.track("agent-chat", {
|
|
1072
1077
|
event: "reconnect",
|
|
1073
1078
|
chatId: (d = r.chat) == null ? void 0 : d.id,
|
|
1074
1079
|
agentId: c.id,
|
|
@@ -1077,7 +1082,7 @@ async function ht(e, t) {
|
|
|
1077
1082
|
},
|
|
1078
1083
|
async disconnect() {
|
|
1079
1084
|
var d;
|
|
1080
|
-
await
|
|
1085
|
+
await y(), l.track("agent-chat", {
|
|
1081
1086
|
event: "disconnect",
|
|
1082
1087
|
chatId: (d = r.chat) == null ? void 0 : d.id,
|
|
1083
1088
|
agentId: c.id,
|
|
@@ -1085,132 +1090,132 @@ async function ht(e, t) {
|
|
|
1085
1090
|
});
|
|
1086
1091
|
},
|
|
1087
1092
|
async chat(d) {
|
|
1088
|
-
var
|
|
1089
|
-
const
|
|
1090
|
-
if (t.mode ===
|
|
1091
|
-
throw new
|
|
1093
|
+
var g, D, _, P, L;
|
|
1094
|
+
const w = () => {
|
|
1095
|
+
if (t.mode === j.DirectPlayback)
|
|
1096
|
+
throw new F("Direct playback is enabled, chat is disabled");
|
|
1092
1097
|
if (d.length >= 800)
|
|
1093
|
-
throw new
|
|
1098
|
+
throw new F("Message cannot be more than 800 characters");
|
|
1094
1099
|
if (d.length === 0)
|
|
1095
|
-
throw new
|
|
1096
|
-
if (r.chatMode ===
|
|
1097
|
-
throw new
|
|
1098
|
-
if (![
|
|
1100
|
+
throw new F("Message cannot be empty");
|
|
1101
|
+
if (r.chatMode === j.Maintenance)
|
|
1102
|
+
throw new F("Chat is in maintenance mode");
|
|
1103
|
+
if (![j.TextOnly, j.Playground].includes(r.chatMode)) {
|
|
1099
1104
|
if (!r.streamingManager)
|
|
1100
|
-
throw new
|
|
1105
|
+
throw new F("Streaming manager is not initialized");
|
|
1101
1106
|
if (!r.chat)
|
|
1102
|
-
throw new
|
|
1107
|
+
throw new F("Chat is not initialized");
|
|
1103
1108
|
}
|
|
1104
|
-
},
|
|
1105
|
-
var
|
|
1109
|
+
}, h = async () => {
|
|
1110
|
+
var R, T;
|
|
1106
1111
|
if (!r.chat) {
|
|
1107
|
-
const
|
|
1108
|
-
if (!
|
|
1112
|
+
const E = await fe(c, i, l, r.chatMode, t.persistentChat);
|
|
1113
|
+
if (!E.chat)
|
|
1109
1114
|
throw new we(r.chatMode, !!t.persistentChat);
|
|
1110
|
-
r.chat =
|
|
1115
|
+
r.chat = E.chat, (T = (R = t.callbacks).onNewChat) == null || T.call(R, r.chat.id);
|
|
1111
1116
|
}
|
|
1112
1117
|
return r.chat.id;
|
|
1113
|
-
},
|
|
1114
|
-
var
|
|
1115
|
-
return i.chat(c.id,
|
|
1118
|
+
}, b = async (R, T) => Z(() => {
|
|
1119
|
+
var E, m;
|
|
1120
|
+
return i.chat(c.id, T, {
|
|
1116
1121
|
chatMode: r.chatMode,
|
|
1117
|
-
streamId: (
|
|
1118
|
-
sessionId: (
|
|
1119
|
-
messages:
|
|
1120
|
-
matches:
|
|
1121
|
-
|
|
1122
|
-
}) =>
|
|
1122
|
+
streamId: (E = r.streamingManager) == null ? void 0 : E.streamId,
|
|
1123
|
+
sessionId: (m = r.streamingManager) == null ? void 0 : m.sessionId,
|
|
1124
|
+
messages: R.map(({
|
|
1125
|
+
matches: p,
|
|
1126
|
+
...$
|
|
1127
|
+
}) => $)
|
|
1123
1128
|
}, {
|
|
1124
1129
|
...ue(r.chatMode),
|
|
1125
1130
|
skipErrorHandler: !0
|
|
1126
1131
|
});
|
|
1127
1132
|
}, {
|
|
1128
1133
|
limit: 2,
|
|
1129
|
-
shouldRetryFn: (
|
|
1130
|
-
var
|
|
1131
|
-
const
|
|
1132
|
-
return !((A =
|
|
1134
|
+
shouldRetryFn: (E) => {
|
|
1135
|
+
var $, A, U, ee;
|
|
1136
|
+
const m = ($ = E == null ? void 0 : E.message) == null ? void 0 : $.includes("missing or invalid session_id");
|
|
1137
|
+
return !((A = E == null ? void 0 : E.message) == null ? void 0 : A.includes("Stream Error")) && !m ? ((ee = (U = t.callbacks).onError) == null || ee.call(U, E), !1) : !0;
|
|
1133
1138
|
},
|
|
1134
1139
|
onRetry: async () => {
|
|
1135
|
-
await
|
|
1140
|
+
await y(), await k(!1);
|
|
1136
1141
|
}
|
|
1137
1142
|
});
|
|
1138
1143
|
try {
|
|
1139
|
-
|
|
1140
|
-
id:
|
|
1144
|
+
f(), w(), r.messages.push({
|
|
1145
|
+
id: X(),
|
|
1141
1146
|
role: "user",
|
|
1142
1147
|
content: d,
|
|
1143
|
-
created_at: new Date(
|
|
1144
|
-
}), (
|
|
1145
|
-
const
|
|
1148
|
+
created_at: new Date(x.update()).toISOString()
|
|
1149
|
+
}), (D = (g = t.callbacks).onNewMessage) == null || D.call(g, [...r.messages], "user");
|
|
1150
|
+
const R = await h(), T = await b([...r.messages], R);
|
|
1146
1151
|
return r.messages.push({
|
|
1147
|
-
id:
|
|
1152
|
+
id: X(),
|
|
1148
1153
|
role: "assistant",
|
|
1149
|
-
content:
|
|
1154
|
+
content: T.result || "",
|
|
1150
1155
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1151
|
-
context:
|
|
1152
|
-
matches:
|
|
1156
|
+
context: T.context,
|
|
1157
|
+
matches: T.matches
|
|
1153
1158
|
}), l.track("agent-message-send", {
|
|
1154
1159
|
event: "success",
|
|
1155
1160
|
mode: r.chatMode,
|
|
1156
1161
|
messages: r.messages.length + 1
|
|
1157
|
-
}),
|
|
1158
|
-
latency:
|
|
1162
|
+
}), T.result && ((P = (_ = t.callbacks).onNewMessage) == null || P.call(_, [...r.messages], "answer"), l.track("agent-message-received", {
|
|
1163
|
+
latency: x.get(!0),
|
|
1159
1164
|
mode: r.chatMode,
|
|
1160
1165
|
messages: r.messages.length
|
|
1161
|
-
})),
|
|
1162
|
-
} catch (
|
|
1163
|
-
throw ((
|
|
1166
|
+
})), T;
|
|
1167
|
+
} catch (R) {
|
|
1168
|
+
throw ((L = r.messages[r.messages.length - 1]) == null ? void 0 : L.role) === "assistant" && r.messages.pop(), l.track("agent-message-send", {
|
|
1164
1169
|
event: "error",
|
|
1165
1170
|
mode: r.chatMode,
|
|
1166
1171
|
messages: r.messages.length
|
|
1167
|
-
}),
|
|
1172
|
+
}), R;
|
|
1168
1173
|
}
|
|
1169
1174
|
},
|
|
1170
|
-
rate(d,
|
|
1171
|
-
var
|
|
1172
|
-
const
|
|
1175
|
+
rate(d, w, h) {
|
|
1176
|
+
var D, _, P, L;
|
|
1177
|
+
const b = r.messages.find((R) => R.id === d);
|
|
1173
1178
|
if (r.chat) {
|
|
1174
|
-
if (!
|
|
1179
|
+
if (!b)
|
|
1175
1180
|
throw new Error("Message not found");
|
|
1176
1181
|
} else
|
|
1177
1182
|
throw new Error("Chat is not initialized");
|
|
1178
|
-
const
|
|
1183
|
+
const g = ((D = b.matches) == null ? void 0 : D.map((R) => [R.document_id, R.id])) ?? [];
|
|
1179
1184
|
return l.track("agent-rate", {
|
|
1180
|
-
event:
|
|
1181
|
-
thumb:
|
|
1182
|
-
knowledge_id: ((
|
|
1185
|
+
event: h ? "update" : "create",
|
|
1186
|
+
thumb: w === 1 ? "up" : "down",
|
|
1187
|
+
knowledge_id: ((_ = c.knowledge) == null ? void 0 : _.id) ?? "",
|
|
1183
1188
|
mode: r.chatMode,
|
|
1184
|
-
matches:
|
|
1185
|
-
score:
|
|
1186
|
-
}),
|
|
1187
|
-
knowledge_id: ((
|
|
1189
|
+
matches: g,
|
|
1190
|
+
score: w
|
|
1191
|
+
}), h ? i.updateRating(c.id, r.chat.id, h, {
|
|
1192
|
+
knowledge_id: ((P = c.knowledge) == null ? void 0 : P.id) ?? "",
|
|
1188
1193
|
message_id: d,
|
|
1189
|
-
matches:
|
|
1190
|
-
score:
|
|
1194
|
+
matches: g,
|
|
1195
|
+
score: w
|
|
1191
1196
|
}) : i.createRating(c.id, r.chat.id, {
|
|
1192
|
-
knowledge_id: ((
|
|
1197
|
+
knowledge_id: ((L = c.knowledge) == null ? void 0 : L.id) ?? "",
|
|
1193
1198
|
message_id: d,
|
|
1194
|
-
matches:
|
|
1195
|
-
score:
|
|
1199
|
+
matches: g,
|
|
1200
|
+
score: w
|
|
1196
1201
|
});
|
|
1197
1202
|
},
|
|
1198
1203
|
deleteRate(d) {
|
|
1199
|
-
var
|
|
1204
|
+
var w;
|
|
1200
1205
|
if (!r.chat)
|
|
1201
1206
|
throw new Error("Chat is not initialized");
|
|
1202
1207
|
return l.track("agent-rate-delete", {
|
|
1203
1208
|
type: "text",
|
|
1204
|
-
chat_id: (
|
|
1209
|
+
chat_id: (w = r.chat) == null ? void 0 : w.id,
|
|
1205
1210
|
id: d,
|
|
1206
1211
|
mode: r.chatMode
|
|
1207
1212
|
}), i.deleteRating(c.id, r.chat.id, d);
|
|
1208
1213
|
},
|
|
1209
|
-
speak(d) {
|
|
1210
|
-
var
|
|
1214
|
+
async speak(d) {
|
|
1215
|
+
var g, D, _, P;
|
|
1211
1216
|
if (!r.streamingManager)
|
|
1212
1217
|
throw new Error("Please connect to the agent first");
|
|
1213
|
-
function
|
|
1218
|
+
function w() {
|
|
1214
1219
|
if (typeof d == "string") {
|
|
1215
1220
|
if (!c.presenter.voice)
|
|
1216
1221
|
throw new Error("Presenter voice is not initialized");
|
|
@@ -1233,53 +1238,58 @@ async function ht(e, t) {
|
|
|
1233
1238
|
}
|
|
1234
1239
|
return d;
|
|
1235
1240
|
}
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
id:
|
|
1241
|
+
const h = w();
|
|
1242
|
+
l.track("agent-speak", h), x.update(), (g = r.chat) != null && g.id && h.type === "text" && (r.messages.push({
|
|
1243
|
+
id: X(),
|
|
1239
1244
|
role: "assistant",
|
|
1240
|
-
content:
|
|
1241
|
-
created_at: new Date(
|
|
1242
|
-
}), (
|
|
1243
|
-
|
|
1245
|
+
content: h.input,
|
|
1246
|
+
created_at: new Date(x.get(!0)).toISOString()
|
|
1247
|
+
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "answer"));
|
|
1248
|
+
const b = Be(r.chatMode);
|
|
1249
|
+
return r.chat && b ? {
|
|
1250
|
+
duration: 0,
|
|
1251
|
+
status: "success"
|
|
1252
|
+
} : r.streamingManager.speak({
|
|
1253
|
+
script: h,
|
|
1244
1254
|
metadata: {
|
|
1245
|
-
chat_id: (
|
|
1255
|
+
chat_id: (P = r.chat) == null ? void 0 : P.id,
|
|
1246
1256
|
agent_id: c.id
|
|
1247
1257
|
}
|
|
1248
1258
|
});
|
|
1249
1259
|
}
|
|
1250
1260
|
};
|
|
1251
1261
|
}
|
|
1252
|
-
function
|
|
1262
|
+
function pt(e, t, n) {
|
|
1253
1263
|
const {
|
|
1254
1264
|
getById: a
|
|
1255
|
-
} = de(t, n ||
|
|
1265
|
+
} = de(t, n || q);
|
|
1256
1266
|
return a(e);
|
|
1257
1267
|
}
|
|
1258
1268
|
export {
|
|
1259
|
-
|
|
1260
|
-
|
|
1269
|
+
K as AgentActivityState,
|
|
1270
|
+
Ce as AgentStatus,
|
|
1261
1271
|
we as ChatCreationFailed,
|
|
1262
|
-
|
|
1272
|
+
j as ChatMode,
|
|
1263
1273
|
pe as ChatModeDowngraded,
|
|
1264
1274
|
J as ChatProgress,
|
|
1265
|
-
|
|
1275
|
+
I as ConnectionState,
|
|
1266
1276
|
W as ConnectivityState,
|
|
1267
1277
|
te as DataChannelSignalMap,
|
|
1268
1278
|
Se as DocumentType,
|
|
1269
1279
|
Ee as KnowledgeType,
|
|
1270
1280
|
ke as PlanGroup,
|
|
1271
1281
|
_e as Providers,
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1282
|
+
De as RateState,
|
|
1283
|
+
Y as StreamEvents,
|
|
1284
|
+
N as StreamType,
|
|
1275
1285
|
v as StreamingState,
|
|
1276
1286
|
Re as Subject,
|
|
1277
1287
|
ve as UserPlan,
|
|
1278
|
-
|
|
1288
|
+
F as ValidationError,
|
|
1279
1289
|
ie as VideoType,
|
|
1280
1290
|
Ie as VoiceAccess,
|
|
1281
1291
|
ye as WsError,
|
|
1282
|
-
|
|
1283
|
-
|
|
1292
|
+
wt as createAgentManager,
|
|
1293
|
+
pt as getAgent,
|
|
1284
1294
|
Me as mapVideoType
|
|
1285
1295
|
};
|