@d-id/client-sdk 1.1.19 → 1.1.20-staging.90
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-DKb-cXkg.js → index-BH8ByqOr.js} +444 -437
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +6 -6
- package/dist/{livekit-manager-D7QkEucf.js → livekit-manager-D9xuX-OS.js} +62 -68
- package/dist/src/api/streams/streamsApiV2.d.ts +2 -2
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +2 -2
- package/dist/src/services/analytics/mixpanel.d.ts +1 -1
- package/dist/src/services/streaming-manager/common.d.ts +2 -2
- package/dist/src/services/streaming-manager/factory.d.ts +3 -3
- package/dist/src/services/streaming-manager/livekit-manager.d.ts +2 -2
- package/dist/src/types/stream/streams-v2.d.ts +6 -7
- package/dist/src/utils/defer.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var Q = (e, t, a) =>
|
|
1
|
+
var Se = Object.defineProperty;
|
|
2
|
+
var Ie = (e, t, a) => t in e ? Se(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var Q = (e, t, a) => Ie(e, typeof t != "symbol" ? t + "" : t, a);
|
|
4
4
|
class ee extends Error {
|
|
5
5
|
constructor({ kind: a, description: r, error: o }) {
|
|
6
6
|
super(JSON.stringify({ kind: a, description: r }));
|
|
@@ -10,7 +10,7 @@ class ee extends Error {
|
|
|
10
10
|
this.kind = a, this.description = r, this.error = o;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class Ee extends ee {
|
|
14
14
|
constructor(t, a) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,25 +18,25 @@ class Ie extends ee {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Me extends ee {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class V extends ee {
|
|
27
27
|
constructor(a, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: a });
|
|
29
29
|
Q(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class _e extends ee {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var Te = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Te || {}), Ae = /* @__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))(Ae || {}), Pe = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Pe || {}), be = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(be || {}), I = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(I || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), je = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(je || {}), Le = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Le || {}), xe = /* @__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))(xe || {}), he = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(he || {});
|
|
39
|
+
const xt = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,12 +48,12 @@ const bt = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
52
|
-
const
|
|
51
|
+
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), Z = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Z || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), L = /* @__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.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(L || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(_ || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), ce = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ce || {}), $e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))($e || {}), Be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Be || {});
|
|
52
|
+
const ze = 45 * 1e3, Fe = "X-Playground-Chat", te = "https://api.d-id.com", Ne = "wss://notifications.d-id.com", Je = "79f81a83a67430be2bc0fd61042b8faa", pe = (e) => new Promise((t) => setTimeout(t, e)), O = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
54
|
return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
-
},
|
|
56
|
-
function
|
|
55
|
+
}, we = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, de = (e) => e === he.Expressive, We = (e) => [I.TextOnly, I.Playground, I.Maintenance].includes(e), ve = (e) => e && [I.DirectPlayback, I.Off].includes(e);
|
|
56
|
+
function Ue(e, t) {
|
|
57
57
|
let a;
|
|
58
58
|
return {
|
|
59
59
|
promise: new Promise((o, i) => {
|
|
@@ -77,12 +77,12 @@ async function ne(e, t) {
|
|
|
77
77
|
try {
|
|
78
78
|
if (!a.timeout)
|
|
79
79
|
return await e();
|
|
80
|
-
const { promise: i, clear: c } =
|
|
80
|
+
const { promise: i, clear: c } = Ue(a.timeout, a.timeoutErrorMessage), n = e().finally(c);
|
|
81
81
|
return await Promise.race([n, i]);
|
|
82
82
|
} catch (i) {
|
|
83
83
|
if (r = i, !a.shouldRetryFn(i) || o >= a.limit)
|
|
84
84
|
throw i;
|
|
85
|
-
await
|
|
85
|
+
await pe(a.delayMs), a.onRetry(i);
|
|
86
86
|
}
|
|
87
87
|
throw r;
|
|
88
88
|
}
|
|
@@ -91,22 +91,22 @@ function ae(e) {
|
|
|
91
91
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
92
92
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
93
93
|
if (!t) {
|
|
94
|
-
let a =
|
|
94
|
+
let a = O();
|
|
95
95
|
window.localStorage.setItem("did_external_key_id", a), t = a;
|
|
96
96
|
}
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
|
-
let
|
|
99
|
+
let Ke = O();
|
|
100
100
|
function ye(e, t) {
|
|
101
101
|
if (e.type === "bearer")
|
|
102
102
|
return `Bearer ${e.token}`;
|
|
103
103
|
if (e.type === "basic")
|
|
104
104
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
105
105
|
if (e.type === "key")
|
|
106
|
-
return `Client-Key ${e.clientKey}.${ae(t)}_${
|
|
106
|
+
return `Client-Key ${e.clientKey}.${ae(t)}_${Ke}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const He = (e) => ne(e, {
|
|
110
110
|
limit: 3,
|
|
111
111
|
delayMs: 1e3,
|
|
112
112
|
timeout: 0,
|
|
@@ -114,7 +114,7 @@ const Ke = (e) => ne(e, {
|
|
|
114
114
|
});
|
|
115
115
|
function ke(e, t = te, a, r) {
|
|
116
116
|
const o = async (i, c) => {
|
|
117
|
-
const { skipErrorHandler: n, ...s } = c || {}, d = await
|
|
117
|
+
const { skipErrorHandler: n, ...s } = c || {}, d = await He(
|
|
118
118
|
() => fetch(t + (i != null && i.startsWith("/") ? i : `/${i}`), {
|
|
119
119
|
...s,
|
|
120
120
|
headers: {
|
|
@@ -126,8 +126,8 @@ function ke(e, t = te, a, r) {
|
|
|
126
126
|
);
|
|
127
127
|
if (!d.ok) {
|
|
128
128
|
let l = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
129
|
-
const
|
|
130
|
-
throw a && !n && a(
|
|
129
|
+
const u = new Error(l);
|
|
130
|
+
throw a && !n && a(u, { url: i, options: s, headers: d.headers }), u;
|
|
131
131
|
}
|
|
132
132
|
return d.json();
|
|
133
133
|
};
|
|
@@ -146,7 +146,7 @@ function ke(e, t = te, a, r) {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function Ve(e, t = te, a, r) {
|
|
150
150
|
const o = ke(e, `${t}/agents`, a, r);
|
|
151
151
|
return {
|
|
152
152
|
create(i, c) {
|
|
@@ -184,7 +184,7 @@ function He(e, t = te, a, r) {
|
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function qe(e) {
|
|
188
188
|
var o, i, c, n;
|
|
189
189
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
|
|
190
190
|
const s = navigator.platform;
|
|
@@ -195,18 +195,18 @@ function Ve(e) {
|
|
|
195
195
|
isMobile: `${t() == "Mobile"}`,
|
|
196
196
|
browser: navigator.userAgent,
|
|
197
197
|
origin: window.location.origin,
|
|
198
|
-
agentType:
|
|
198
|
+
agentType: we(r),
|
|
199
199
|
agentVoice: {
|
|
200
200
|
voiceId: (i = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : i.voice_id,
|
|
201
201
|
provider: (n = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : n.type
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function Oe(e) {
|
|
206
206
|
var a, r, o, i, c, n;
|
|
207
207
|
const t = (a = e.llm) == null ? void 0 : a.prompt_customization;
|
|
208
208
|
return {
|
|
209
|
-
agentType:
|
|
209
|
+
agentType: we(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
211
211
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
212
212
|
behavior: {
|
|
@@ -225,8 +225,8 @@ function qe(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
228
|
+
const Xe = (e) => e.reduce((t, a) => t + a, 0), le = (e) => Xe(e) / e.length;
|
|
229
|
+
function Ye(e, t, a) {
|
|
230
230
|
var s, d, l;
|
|
231
231
|
const { event: r, ...o } = e, { template: i } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((s = t == null ? void 0 : t.presenter) == null ? void 0 : s.voice) || {};
|
|
232
232
|
return {
|
|
@@ -237,9 +237,12 @@ function Xe(e, t, a) {
|
|
|
237
237
|
...a
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
+
function ue(e) {
|
|
241
|
+
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
|
+
}
|
|
240
243
|
let re = {};
|
|
241
|
-
const
|
|
242
|
-
function
|
|
244
|
+
const Qe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
245
|
+
function Ze(e) {
|
|
243
246
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
244
247
|
return {
|
|
245
248
|
token: e.token || "testKey",
|
|
@@ -250,14 +253,14 @@ function Qe(e) {
|
|
|
250
253
|
...e.mixpanelAdditionalProperties || {}
|
|
251
254
|
},
|
|
252
255
|
isEnabled: e.isEnabled ?? !0,
|
|
253
|
-
getRandom:
|
|
256
|
+
getRandom: O,
|
|
254
257
|
enrich(a) {
|
|
255
258
|
this.additionalProperties = { ...this.additionalProperties, ...a };
|
|
256
259
|
},
|
|
257
|
-
async track(a, r) {
|
|
260
|
+
async track(a, r, o) {
|
|
258
261
|
if (!this.isEnabled)
|
|
259
262
|
return Promise.resolve();
|
|
260
|
-
const { audioPath:
|
|
263
|
+
const { audioPath: i, ...c } = r || {}, n = o || Date.now(), s = {
|
|
261
264
|
method: "POST",
|
|
262
265
|
headers: {
|
|
263
266
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -268,11 +271,11 @@ function Qe(e) {
|
|
|
268
271
|
event: a,
|
|
269
272
|
properties: {
|
|
270
273
|
...this.additionalProperties,
|
|
271
|
-
...
|
|
274
|
+
...c,
|
|
272
275
|
agentId: this.agentId,
|
|
273
276
|
source: t,
|
|
274
277
|
token: this.token,
|
|
275
|
-
time:
|
|
278
|
+
time: n,
|
|
276
279
|
$insert_id: this.getRandom(),
|
|
277
280
|
origin: window.location.href,
|
|
278
281
|
"Screen Height": window.screen.height || window.innerWidth,
|
|
@@ -283,11 +286,10 @@ function Qe(e) {
|
|
|
283
286
|
])
|
|
284
287
|
})
|
|
285
288
|
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
289
|
+
return fetch(Qe, {
|
|
290
|
+
...s,
|
|
291
|
+
keepalive: !0
|
|
292
|
+
}).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
|
|
291
293
|
},
|
|
292
294
|
linkTrack(a, r, o, i) {
|
|
293
295
|
re[a] || (re[a] = { events: {}, resolvedDependencies: [] }), i.includes(o) || i.push(o);
|
|
@@ -305,7 +307,7 @@ function Qe(e) {
|
|
|
305
307
|
}
|
|
306
308
|
};
|
|
307
309
|
}
|
|
308
|
-
function
|
|
310
|
+
function De() {
|
|
309
311
|
let e = 0;
|
|
310
312
|
return {
|
|
311
313
|
reset: () => e = 0,
|
|
@@ -313,11 +315,11 @@ function Re() {
|
|
|
313
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
314
316
|
};
|
|
315
317
|
}
|
|
316
|
-
const
|
|
318
|
+
const F = De(), ie = De();
|
|
317
319
|
function Ce(e) {
|
|
318
|
-
return e ===
|
|
320
|
+
return e === I.Playground ? { headers: { [Fe]: "true" } } : {};
|
|
319
321
|
}
|
|
320
|
-
async function
|
|
322
|
+
async function Re(e, t, a, r, o = !1, i) {
|
|
321
323
|
try {
|
|
322
324
|
return !i && !ve(r) && (i = await t.newChat(e.id, { persist: o }, Ce(r)), a.track("agent-chat", {
|
|
323
325
|
event: "created",
|
|
@@ -335,59 +337,59 @@ async function se(e, t, a, r, o = !1, i) {
|
|
|
335
337
|
throw new Error("Cannot create new chat");
|
|
336
338
|
}
|
|
337
339
|
}
|
|
338
|
-
function
|
|
340
|
+
function Ge(e) {
|
|
339
341
|
return e && e.length > 0 ? e : [];
|
|
340
342
|
}
|
|
341
|
-
function
|
|
343
|
+
function et(e, t, a) {
|
|
342
344
|
if (!e)
|
|
343
345
|
throw new Error("Please connect to the agent first");
|
|
344
346
|
if (!e.interruptAvailable)
|
|
345
347
|
throw new Error("Interrupt is not enabled for this stream");
|
|
346
|
-
if (t !==
|
|
348
|
+
if (t !== J.Fluent)
|
|
347
349
|
throw new Error("Interrupt only available for Fluent streams");
|
|
348
350
|
if (!a)
|
|
349
351
|
throw new Error("No active video to interrupt");
|
|
350
352
|
}
|
|
351
|
-
async function
|
|
353
|
+
async function tt(e, t) {
|
|
352
354
|
const a = {
|
|
353
|
-
type:
|
|
355
|
+
type: L.StreamInterrupt,
|
|
354
356
|
videoId: t,
|
|
355
357
|
timestamp: Date.now()
|
|
356
358
|
};
|
|
357
359
|
e.sendDataChannelMessage(JSON.stringify(a));
|
|
358
360
|
}
|
|
359
|
-
function
|
|
361
|
+
function rt(e) {
|
|
360
362
|
return new Promise((t, a) => {
|
|
361
|
-
const { callbacks: r, host: o, auth: i, externalId: c } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: l = null } = r || {},
|
|
362
|
-
|
|
363
|
+
const { callbacks: r, host: o, auth: i, externalId: c } = e, { onMessage: n = null, onOpen: s = null, onClose: d = null, onError: l = null } = r || {}, u = new WebSocket(`${o}?authorization=${encodeURIComponent(ye(i, c))}`);
|
|
364
|
+
u.onmessage = n, u.onclose = d, u.onerror = (y) => {
|
|
363
365
|
console.error(y), l == null || l("Websocket failed to connect", y), a(y);
|
|
364
|
-
},
|
|
365
|
-
s == null || s(y), t(
|
|
366
|
+
}, u.onopen = (y) => {
|
|
367
|
+
s == null || s(y), t(u);
|
|
366
368
|
};
|
|
367
369
|
});
|
|
368
370
|
}
|
|
369
|
-
async function
|
|
371
|
+
async function nt(e) {
|
|
370
372
|
const { retries: t = 1 } = e;
|
|
371
373
|
let a = null;
|
|
372
374
|
for (let r = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; r++)
|
|
373
375
|
try {
|
|
374
|
-
a = await
|
|
376
|
+
a = await rt(e);
|
|
375
377
|
} catch (o) {
|
|
376
378
|
if (r === t)
|
|
377
379
|
throw o;
|
|
378
|
-
await
|
|
380
|
+
await pe(r * 500);
|
|
379
381
|
}
|
|
380
382
|
return a;
|
|
381
383
|
}
|
|
382
|
-
async function
|
|
383
|
-
const o = a != null && a.onMessage ? [a.onMessage] : [], i = await
|
|
384
|
+
async function at(e, t, a, r) {
|
|
385
|
+
const o = a != null && a.onMessage ? [a.onMessage] : [], i = await nt({
|
|
384
386
|
auth: e,
|
|
385
387
|
host: t,
|
|
386
388
|
externalId: r,
|
|
387
389
|
callbacks: {
|
|
388
390
|
onError: (c) => {
|
|
389
391
|
var n;
|
|
390
|
-
return (n = a.onError) == null ? void 0 : n.call(a, new
|
|
392
|
+
return (n = a.onError) == null ? void 0 : n.call(a, new _e(c));
|
|
391
393
|
},
|
|
392
394
|
onMessage(c) {
|
|
393
395
|
const n = JSON.parse(c.data);
|
|
@@ -401,7 +403,7 @@ async function nt(e, t, a, r) {
|
|
|
401
403
|
subscribeToEvents: (c) => o.push(c)
|
|
402
404
|
};
|
|
403
405
|
}
|
|
404
|
-
function
|
|
406
|
+
function it(e) {
|
|
405
407
|
if (e.answer !== void 0)
|
|
406
408
|
return e.answer;
|
|
407
409
|
let t = 0, a = "";
|
|
@@ -409,40 +411,40 @@ function at(e) {
|
|
|
409
411
|
a += e[t++];
|
|
410
412
|
return a;
|
|
411
413
|
}
|
|
412
|
-
function
|
|
414
|
+
function st(e, t, a, r, o) {
|
|
413
415
|
const i = r.messages[r.messages.length - 1];
|
|
414
|
-
if (!(e ===
|
|
416
|
+
if (!(e === q.Partial || e === q.Answer) || (i == null ? void 0 : i.role) !== "assistant")
|
|
415
417
|
return;
|
|
416
418
|
const { content: c, sequence: n } = t;
|
|
417
|
-
e ===
|
|
418
|
-
const s =
|
|
419
|
-
(i.content !== s || e ===
|
|
419
|
+
e === q.Partial ? a[n] = c : a.answer = c;
|
|
420
|
+
const s = it(a);
|
|
421
|
+
(i.content !== s || e === q.Answer) && (i.content = s, o == null || o([...r.messages], e));
|
|
420
422
|
}
|
|
421
|
-
function
|
|
423
|
+
function ot(e, t, a, r, o) {
|
|
422
424
|
let i = {};
|
|
423
425
|
return {
|
|
424
426
|
clearQueue: () => i = {},
|
|
425
427
|
onMessage: (c, n) => {
|
|
426
428
|
var s, d;
|
|
427
429
|
if ("content" in n)
|
|
428
|
-
|
|
430
|
+
st(c, n, i, t, a.callbacks.onNewMessage), c === q.Answer && e.track("agent-message-received", {
|
|
429
431
|
messages: t.messages.length,
|
|
430
432
|
mode: t.chatMode
|
|
431
433
|
});
|
|
432
434
|
else {
|
|
433
|
-
const l =
|
|
435
|
+
const l = L, u = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], y = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], P = Ye(n, r, { mode: t.chatMode });
|
|
434
436
|
if (c = c, c === l.StreamVideoCreated)
|
|
435
|
-
e.linkTrack("agent-video",
|
|
436
|
-
else if (
|
|
437
|
-
const
|
|
438
|
-
y.includes(c) ? e.track("agent-video", { ...
|
|
437
|
+
e.linkTrack("agent-video", P, l.StreamVideoCreated, ["start"]);
|
|
438
|
+
else if (u.includes(c)) {
|
|
439
|
+
const A = c.split("/")[1];
|
|
440
|
+
y.includes(c) ? e.track("agent-video", { ...P, event: A }) : e.linkTrack("agent-video", { ...P, event: A }, c, ["done"]);
|
|
439
441
|
}
|
|
440
442
|
y.includes(c) && ((d = (s = a.callbacks).onError) == null || d.call(s, new Error(`Stream failed with event ${c}`), { data: n })), n.event === l.StreamDone && o();
|
|
441
443
|
}
|
|
442
444
|
}
|
|
443
445
|
};
|
|
444
446
|
}
|
|
445
|
-
function
|
|
447
|
+
function ct(e, t, a, r) {
|
|
446
448
|
const o = ke(e, `${t}/agents/${a}`, r);
|
|
447
449
|
return {
|
|
448
450
|
createStream(i) {
|
|
@@ -471,8 +473,8 @@ function ot(e, t, a, r) {
|
|
|
471
473
|
}
|
|
472
474
|
};
|
|
473
475
|
}
|
|
474
|
-
const
|
|
475
|
-
function
|
|
476
|
+
const dt = (e, t) => (a, r) => e && console.log(`[${t}] ${a}`, r ?? "");
|
|
477
|
+
function lt(e, t, a) {
|
|
476
478
|
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
477
479
|
return {
|
|
478
480
|
duration: r,
|
|
@@ -492,7 +494,7 @@ function dt(e, t, a) {
|
|
|
492
494
|
lowFpsCount: a
|
|
493
495
|
};
|
|
494
496
|
}
|
|
495
|
-
function
|
|
497
|
+
function ut(e) {
|
|
496
498
|
return e.filter(
|
|
497
499
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
498
500
|
).map((t) => {
|
|
@@ -503,7 +505,7 @@ function lt(e) {
|
|
|
503
505
|
};
|
|
504
506
|
});
|
|
505
507
|
}
|
|
506
|
-
function
|
|
508
|
+
function ft(e) {
|
|
507
509
|
let t = "", a = 0;
|
|
508
510
|
for (const r of e.values()) {
|
|
509
511
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -533,7 +535,7 @@ function ut(e) {
|
|
|
533
535
|
}
|
|
534
536
|
return {};
|
|
535
537
|
}
|
|
536
|
-
function
|
|
538
|
+
function mt(e, t, a) {
|
|
537
539
|
const r = e.map((s, d) => d === 0 ? a ? {
|
|
538
540
|
timestamp: s.timestamp,
|
|
539
541
|
duration: 0,
|
|
@@ -585,23 +587,23 @@ function ft(e, t, a) {
|
|
|
585
587
|
framesPerSecond: s.framesPerSecond,
|
|
586
588
|
freezeCount: s.freezeCount - e[d - 1].freezeCount,
|
|
587
589
|
freezeDuration: s.freezeDuration - e[d - 1].freezeDuration
|
|
588
|
-
}), o =
|
|
590
|
+
}), o = ut(r), i = o.reduce((s, d) => s + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((s) => !!s.avgJitterDelayInInterval).map((s) => s.avgJitterDelayInInterval), n = r.filter((s) => !!s.rtt).map((s) => s.rtt);
|
|
589
591
|
return {
|
|
590
592
|
webRTCStats: {
|
|
591
593
|
anomalies: o,
|
|
592
594
|
minRtt: Math.min(...n),
|
|
593
|
-
avgRtt:
|
|
595
|
+
avgRtt: le(n),
|
|
594
596
|
maxRtt: Math.max(...n),
|
|
595
|
-
aggregateReport:
|
|
597
|
+
aggregateReport: lt(e[0], e[e.length - 1], i),
|
|
596
598
|
minJitterDelayInInterval: Math.min(...c),
|
|
597
599
|
maxJitterDelayInInterval: Math.max(...c),
|
|
598
|
-
avgJitterDelayInInterval:
|
|
600
|
+
avgJitterDelayInInterval: le(c)
|
|
599
601
|
},
|
|
600
602
|
codec: e[0].codec,
|
|
601
603
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
602
604
|
};
|
|
603
605
|
}
|
|
604
|
-
const
|
|
606
|
+
const se = 100, gt = Math.max(Math.ceil(400 / se), 1), ht = 0.25, pt = 0.28;
|
|
605
607
|
function wt() {
|
|
606
608
|
let e = 0, t, a, r = 0;
|
|
607
609
|
return (o) => {
|
|
@@ -609,8 +611,8 @@ function wt() {
|
|
|
609
611
|
if (i && i.type === "inbound-rtp" && i.kind === "video") {
|
|
610
612
|
const c = i.jitterBufferDelay, n = i.jitterBufferEmittedCount;
|
|
611
613
|
if (a && n > a) {
|
|
612
|
-
const l = c - t,
|
|
613
|
-
r = l /
|
|
614
|
+
const l = c - t, u = n - a;
|
|
615
|
+
r = l / u;
|
|
614
616
|
}
|
|
615
617
|
t = c, a = n;
|
|
616
618
|
const s = i.framesDecoded, d = s - e > 0;
|
|
@@ -619,41 +621,41 @@ function wt() {
|
|
|
619
621
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
620
622
|
};
|
|
621
623
|
}
|
|
622
|
-
function
|
|
623
|
-
let i = [], c, n = 0, s = !1, d = Z.Unknown, l = Z.Unknown,
|
|
624
|
-
const
|
|
624
|
+
function vt(e, t, a, r, o) {
|
|
625
|
+
let i = [], c, n = 0, s = !1, d = Z.Unknown, l = Z.Unknown, u = 0, y = 0;
|
|
626
|
+
const P = wt();
|
|
625
627
|
return setInterval(async () => {
|
|
626
|
-
const
|
|
627
|
-
if (
|
|
628
|
-
n = 0,
|
|
629
|
-
else if (s && (n++, n >=
|
|
630
|
-
const K =
|
|
631
|
-
r == null || r(
|
|
628
|
+
const A = await e.getStats(), { isReceiving: N, avgJitterDelayInInterval: b, freezeCount: x } = P(A), R = ft(A);
|
|
629
|
+
if (N)
|
|
630
|
+
n = 0, u = x - y, l = b < ht ? Z.Strong : b > pt && u > 1 ? Z.Weak : d, l !== d && (o == null || o(l), d = l, y += u, u = 0), s || (r == null || r(p.Start), c = i[i.length - 1], i = [], s = !0), i.push(R);
|
|
631
|
+
else if (s && (n++, n >= gt)) {
|
|
632
|
+
const K = mt(i, se, c);
|
|
633
|
+
r == null || r(p.Stop, K), t() || a(), y = x, s = !1;
|
|
632
634
|
}
|
|
633
|
-
},
|
|
635
|
+
}, se);
|
|
634
636
|
}
|
|
635
|
-
const
|
|
637
|
+
const yt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
636
638
|
function fe(e) {
|
|
637
639
|
switch (e) {
|
|
638
640
|
case "connected":
|
|
639
|
-
return
|
|
641
|
+
return _.Connected;
|
|
640
642
|
case "checking":
|
|
641
|
-
return
|
|
643
|
+
return _.Connecting;
|
|
642
644
|
case "failed":
|
|
643
|
-
return
|
|
645
|
+
return _.Fail;
|
|
644
646
|
case "new":
|
|
645
|
-
return
|
|
647
|
+
return _.New;
|
|
646
648
|
case "closed":
|
|
647
|
-
return
|
|
649
|
+
return _.Closed;
|
|
648
650
|
case "disconnected":
|
|
649
|
-
return
|
|
651
|
+
return _.Disconnected;
|
|
650
652
|
case "completed":
|
|
651
|
-
return
|
|
653
|
+
return _.Completed;
|
|
652
654
|
default:
|
|
653
|
-
return
|
|
655
|
+
return _.New;
|
|
654
656
|
}
|
|
655
657
|
}
|
|
656
|
-
const
|
|
658
|
+
const kt = (e) => (t) => {
|
|
657
659
|
const [a, r = ""] = t.split(/:(.+)/);
|
|
658
660
|
try {
|
|
659
661
|
const o = JSON.parse(r);
|
|
@@ -662,22 +664,22 @@ const yt = (e) => (t) => {
|
|
|
662
664
|
return e("Failed to parse data channel message, returning data as string", { subject: a, rawData: r, error: o }), { subject: a, data: r };
|
|
663
665
|
}
|
|
664
666
|
};
|
|
665
|
-
function
|
|
667
|
+
function Dt({
|
|
666
668
|
statsSignal: e,
|
|
667
669
|
dataChannelSignal: t,
|
|
668
670
|
onVideoStateChange: a,
|
|
669
671
|
report: r
|
|
670
672
|
}) {
|
|
671
|
-
e ===
|
|
673
|
+
e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop, r));
|
|
672
674
|
}
|
|
673
|
-
function
|
|
675
|
+
function Ct({
|
|
674
676
|
statsSignal: e,
|
|
675
677
|
dataChannelSignal: t,
|
|
676
678
|
onVideoStateChange: a,
|
|
677
679
|
onAgentActivityStateChange: r,
|
|
678
680
|
report: o
|
|
679
681
|
}) {
|
|
680
|
-
e ===
|
|
682
|
+
e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, o)), t === p.Start ? r == null || r(X.Talking) : t === p.Stop && (r == null || r(X.Idle));
|
|
681
683
|
}
|
|
682
684
|
function me({
|
|
683
685
|
statsSignal: e,
|
|
@@ -687,7 +689,7 @@ function me({
|
|
|
687
689
|
streamType: o,
|
|
688
690
|
report: i
|
|
689
691
|
}) {
|
|
690
|
-
o ===
|
|
692
|
+
o === J.Legacy ? Dt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: a, report: i }) : o === J.Fluent && Ct({
|
|
691
693
|
statsSignal: e,
|
|
692
694
|
dataChannelSignal: t,
|
|
693
695
|
onVideoStateChange: a,
|
|
@@ -695,185 +697,185 @@ function me({
|
|
|
695
697
|
report: i
|
|
696
698
|
});
|
|
697
699
|
}
|
|
698
|
-
async function
|
|
699
|
-
var
|
|
700
|
-
const n =
|
|
701
|
-
let d = !1, l = !1,
|
|
702
|
-
const { startConnection:
|
|
700
|
+
async function Rt(e, t, { debug: a = !1, callbacks: r, auth: o, baseURL: i = te, analytics: c }) {
|
|
701
|
+
var H;
|
|
702
|
+
const n = dt(a, "WebRTCStreamingManager"), s = kt(n);
|
|
703
|
+
let d = !1, l = !1, u = p.Stop, y = p.Stop;
|
|
704
|
+
const { startConnection: P, sendStreamRequest: A, close: N, createStream: b, addIceCandidate: x } = ct(
|
|
703
705
|
o,
|
|
704
706
|
i,
|
|
705
707
|
e,
|
|
706
708
|
r.onError
|
|
707
709
|
), {
|
|
708
|
-
id:
|
|
710
|
+
id: R,
|
|
709
711
|
offer: K,
|
|
710
712
|
ice_servers: G,
|
|
711
|
-
session_id:
|
|
712
|
-
fluent:
|
|
713
|
-
interrupt_enabled:
|
|
714
|
-
triggers_enabled:
|
|
715
|
-
} = await
|
|
716
|
-
(
|
|
717
|
-
const g = new
|
|
718
|
-
if (
|
|
713
|
+
session_id: $,
|
|
714
|
+
fluent: Y,
|
|
715
|
+
interrupt_enabled: f,
|
|
716
|
+
triggers_enabled: D
|
|
717
|
+
} = await b(t);
|
|
718
|
+
(H = r.onStreamCreated) == null || H.call(r, { stream_id: R, session_id: $, agent_id: e });
|
|
719
|
+
const g = new yt({ iceServers: G }), S = g.createDataChannel("JanusDataChannel");
|
|
720
|
+
if (!$)
|
|
719
721
|
throw new Error("Could not create session_id");
|
|
720
|
-
const
|
|
722
|
+
const w = Y ? J.Fluent : J.Legacy;
|
|
721
723
|
c.enrich({
|
|
722
|
-
"stream-type":
|
|
724
|
+
"stream-type": w
|
|
723
725
|
});
|
|
724
|
-
const
|
|
725
|
-
var
|
|
726
|
-
d = !0, l && ((
|
|
727
|
-
},
|
|
726
|
+
const k = t.stream_warmup && !Y, j = () => d, B = () => {
|
|
727
|
+
var m;
|
|
728
|
+
d = !0, l && ((m = r.onConnectionStateChange) == null || m.call(r, _.Connected));
|
|
729
|
+
}, z = vt(
|
|
728
730
|
g,
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
(
|
|
732
|
-
statsSignal: y =
|
|
733
|
-
dataChannelSignal:
|
|
731
|
+
j,
|
|
732
|
+
B,
|
|
733
|
+
(m, h) => me({
|
|
734
|
+
statsSignal: y = m,
|
|
735
|
+
dataChannelSignal: w === J.Legacy ? u : void 0,
|
|
734
736
|
onVideoStateChange: r.onVideoStateChange,
|
|
735
737
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
736
|
-
report:
|
|
737
|
-
streamType:
|
|
738
|
+
report: h,
|
|
739
|
+
streamType: w
|
|
738
740
|
}),
|
|
739
|
-
(
|
|
740
|
-
var
|
|
741
|
-
return (
|
|
741
|
+
(m) => {
|
|
742
|
+
var h;
|
|
743
|
+
return (h = r.onConnectivityStateChange) == null ? void 0 : h.call(r, m);
|
|
742
744
|
}
|
|
743
745
|
);
|
|
744
|
-
g.onicecandidate = (
|
|
745
|
-
var
|
|
746
|
-
n("peerConnection.onicecandidate",
|
|
746
|
+
g.onicecandidate = (m) => {
|
|
747
|
+
var h;
|
|
748
|
+
n("peerConnection.onicecandidate", m);
|
|
747
749
|
try {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
+
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? x(
|
|
751
|
+
R,
|
|
750
752
|
{
|
|
751
|
-
candidate:
|
|
752
|
-
sdpMid:
|
|
753
|
-
sdpMLineIndex:
|
|
753
|
+
candidate: m.candidate.candidate,
|
|
754
|
+
sdpMid: m.candidate.sdpMid,
|
|
755
|
+
sdpMLineIndex: m.candidate.sdpMLineIndex
|
|
754
756
|
},
|
|
755
|
-
|
|
756
|
-
) :
|
|
757
|
-
} catch (
|
|
758
|
-
(
|
|
757
|
+
$
|
|
758
|
+
) : x(R, { candidate: null }, $);
|
|
759
|
+
} catch (M) {
|
|
760
|
+
(h = r.onError) == null || h.call(r, M, { streamId: R });
|
|
759
761
|
}
|
|
760
|
-
},
|
|
761
|
-
l = !0, (
|
|
762
|
+
}, S.onopen = () => {
|
|
763
|
+
l = !0, (!k || d) && B();
|
|
762
764
|
};
|
|
763
|
-
const
|
|
764
|
-
var
|
|
765
|
-
(
|
|
765
|
+
const C = (m) => {
|
|
766
|
+
var h;
|
|
767
|
+
(h = r.onVideoIdChange) == null || h.call(r, m);
|
|
766
768
|
};
|
|
767
|
-
function
|
|
768
|
-
if (
|
|
769
|
-
const
|
|
770
|
-
|
|
769
|
+
function T(m, h) {
|
|
770
|
+
if (m === L.StreamStarted && typeof h == "object" && "metadata" in h) {
|
|
771
|
+
const M = h.metadata;
|
|
772
|
+
C(M.videoId);
|
|
771
773
|
}
|
|
772
|
-
|
|
773
|
-
statsSignal:
|
|
774
|
-
dataChannelSignal:
|
|
774
|
+
m === L.StreamDone && C(null), u = m === L.StreamStarted ? p.Start : p.Stop, me({
|
|
775
|
+
statsSignal: w === J.Legacy ? y : void 0,
|
|
776
|
+
dataChannelSignal: u,
|
|
775
777
|
onVideoStateChange: r.onVideoStateChange,
|
|
776
778
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
777
|
-
streamType:
|
|
779
|
+
streamType: w
|
|
778
780
|
});
|
|
779
781
|
}
|
|
780
|
-
function
|
|
781
|
-
const
|
|
782
|
-
|
|
782
|
+
function W(m, h) {
|
|
783
|
+
const M = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
|
|
784
|
+
M && c.enrich({ streamMetadata: M }), c.track("agent-chat", { event: "ready" });
|
|
783
785
|
}
|
|
784
|
-
const
|
|
785
|
-
[
|
|
786
|
-
[
|
|
787
|
-
[
|
|
786
|
+
const v = {
|
|
787
|
+
[L.StreamStarted]: T,
|
|
788
|
+
[L.StreamDone]: T,
|
|
789
|
+
[L.StreamReady]: W
|
|
788
790
|
};
|
|
789
|
-
|
|
790
|
-
var
|
|
791
|
-
const { subject:
|
|
792
|
-
(
|
|
791
|
+
S.onmessage = (m) => {
|
|
792
|
+
var U;
|
|
793
|
+
const { subject: h, data: M } = s(m.data);
|
|
794
|
+
(U = v[h]) == null || U.call(v, h, M);
|
|
793
795
|
}, g.oniceconnectionstatechange = () => {
|
|
794
|
-
var
|
|
796
|
+
var h;
|
|
795
797
|
n("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
796
|
-
const
|
|
797
|
-
|
|
798
|
-
}, g.ontrack = (
|
|
799
|
-
var
|
|
800
|
-
n("peerConnection.ontrack",
|
|
798
|
+
const m = fe(g.iceConnectionState);
|
|
799
|
+
m !== _.Connected && ((h = r.onConnectionStateChange) == null || h.call(r, m));
|
|
800
|
+
}, g.ontrack = (m) => {
|
|
801
|
+
var h;
|
|
802
|
+
n("peerConnection.ontrack", m), (h = r.onSrcObjectReady) == null || h.call(r, m.streams[0]);
|
|
801
803
|
}, await g.setRemoteDescription(K), n("set remote description OK");
|
|
802
|
-
const
|
|
803
|
-
return n("create answer OK"), await g.setLocalDescription(
|
|
804
|
+
const E = await g.createAnswer();
|
|
805
|
+
return n("create answer OK"), await g.setLocalDescription(E), n("set local description OK"), await P(R, E, $), n("start connection OK"), {
|
|
804
806
|
/**
|
|
805
807
|
* Method to send request to server to get clip or talk depend on you payload
|
|
806
808
|
* @param payload
|
|
807
809
|
*/
|
|
808
|
-
speak(
|
|
809
|
-
return
|
|
810
|
+
speak(m) {
|
|
811
|
+
return A(R, $, m);
|
|
810
812
|
},
|
|
811
813
|
/**
|
|
812
814
|
* Method to close RTC connection
|
|
813
815
|
*/
|
|
814
816
|
async disconnect() {
|
|
815
|
-
var
|
|
816
|
-
if (
|
|
817
|
-
const
|
|
817
|
+
var m;
|
|
818
|
+
if (R) {
|
|
819
|
+
const h = fe(g.iceConnectionState);
|
|
818
820
|
if (g) {
|
|
819
|
-
if (
|
|
820
|
-
clearInterval(
|
|
821
|
+
if (h === _.New) {
|
|
822
|
+
clearInterval(z);
|
|
821
823
|
return;
|
|
822
824
|
}
|
|
823
825
|
g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
|
|
824
826
|
}
|
|
825
827
|
try {
|
|
826
|
-
|
|
828
|
+
h === _.Connected && await N(R, $).catch((M) => {
|
|
827
829
|
});
|
|
828
|
-
} catch (
|
|
829
|
-
n("Error on close stream connection",
|
|
830
|
+
} catch (M) {
|
|
831
|
+
n("Error on close stream connection", M);
|
|
830
832
|
}
|
|
831
|
-
(
|
|
833
|
+
(m = r.onAgentActivityStateChange) == null || m.call(r, X.Idle), clearInterval(z);
|
|
832
834
|
}
|
|
833
835
|
},
|
|
834
836
|
/**
|
|
835
837
|
* Method to send data channel messages to the server
|
|
836
838
|
*/
|
|
837
|
-
sendDataChannelMessage(
|
|
838
|
-
var
|
|
839
|
-
if (!d ||
|
|
840
|
-
n("Data channel is not ready for sending messages"), (
|
|
841
|
-
streamId:
|
|
839
|
+
sendDataChannelMessage(m) {
|
|
840
|
+
var h, M;
|
|
841
|
+
if (!d || S.readyState !== "open") {
|
|
842
|
+
n("Data channel is not ready for sending messages"), (h = r.onError) == null || h.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
843
|
+
streamId: R
|
|
842
844
|
});
|
|
843
845
|
return;
|
|
844
846
|
}
|
|
845
847
|
try {
|
|
846
|
-
|
|
847
|
-
} catch (
|
|
848
|
-
n("Error sending data channel message",
|
|
848
|
+
S.send(m);
|
|
849
|
+
} catch (U) {
|
|
850
|
+
n("Error sending data channel message", U), (M = r.onError) == null || M.call(r, U, { streamId: R });
|
|
849
851
|
}
|
|
850
852
|
},
|
|
851
853
|
/**
|
|
852
854
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
853
855
|
*/
|
|
854
|
-
sessionId:
|
|
856
|
+
sessionId: $,
|
|
855
857
|
/**
|
|
856
858
|
* Id of current RTC stream
|
|
857
859
|
*/
|
|
858
|
-
streamId:
|
|
859
|
-
streamType:
|
|
860
|
-
interruptAvailable:
|
|
861
|
-
triggersAvailable:
|
|
860
|
+
streamId: R,
|
|
861
|
+
streamType: w,
|
|
862
|
+
interruptAvailable: f ?? !1,
|
|
863
|
+
triggersAvailable: D ?? !1
|
|
862
864
|
};
|
|
863
865
|
}
|
|
864
|
-
var
|
|
865
|
-
async function
|
|
866
|
+
var oe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(oe || {});
|
|
867
|
+
async function St(e, t, a) {
|
|
866
868
|
const r = e.id;
|
|
867
869
|
switch (t.version) {
|
|
868
870
|
case "v1": {
|
|
869
871
|
const { version: o, ...i } = t;
|
|
870
|
-
return
|
|
872
|
+
return Rt(r, i, a);
|
|
871
873
|
}
|
|
872
874
|
case "v2": {
|
|
873
875
|
const { version: o, ...i } = t;
|
|
874
876
|
switch (i.transport_provider) {
|
|
875
|
-
case
|
|
876
|
-
const { createLiveKitStreamingManager: c } = await import("./livekit-manager-
|
|
877
|
+
case ce.Livekit:
|
|
878
|
+
const { createLiveKitStreamingManager: c } = await import("./livekit-manager-D9xuX-OS.js");
|
|
877
879
|
return c(r, i, a);
|
|
878
880
|
default:
|
|
879
881
|
throw new Error(`Unsupported transport provider: ${i.transport_provider}`);
|
|
@@ -883,13 +885,13 @@ async function Dt(e, t, a) {
|
|
|
883
885
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
884
886
|
}
|
|
885
887
|
}
|
|
886
|
-
|
|
888
|
+
const It = "cht";
|
|
889
|
+
function Et() {
|
|
887
890
|
return {
|
|
888
|
-
transport_provider:
|
|
889
|
-
chat_id: e == null ? void 0 : e.chatId
|
|
891
|
+
transport_provider: ce.Livekit
|
|
890
892
|
};
|
|
891
893
|
}
|
|
892
|
-
function
|
|
894
|
+
function Mt(e) {
|
|
893
895
|
var o, i;
|
|
894
896
|
const { streamOptions: t } = e ?? {}, a = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
|
|
895
897
|
plan: (i = e.mixpanelAdditionalProperties) == null ? void 0 : i.plan
|
|
@@ -902,14 +904,14 @@ function It(e) {
|
|
|
902
904
|
fluent: t == null ? void 0 : t.fluent
|
|
903
905
|
}, ...a && { end_user_data: a } };
|
|
904
906
|
}
|
|
905
|
-
function
|
|
906
|
-
return
|
|
907
|
+
function _t(e, t) {
|
|
908
|
+
return de(e.presenter.type) ? { version: oe.V2, ...Et() } : { version: oe.V1, ...Mt(t) };
|
|
907
909
|
}
|
|
908
|
-
function
|
|
909
|
-
o ===
|
|
910
|
+
function Tt(e, t, a, r, o) {
|
|
911
|
+
o === J.Fluent ? At(e, t, a, r, o) : bt(e, t, a, r, o);
|
|
910
912
|
}
|
|
911
|
-
function
|
|
912
|
-
e ===
|
|
913
|
+
function At(e, t, a, r, o) {
|
|
914
|
+
e === p.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === p.Stop && r.track("stream-session", {
|
|
913
915
|
event: "stop",
|
|
914
916
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
915
917
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -917,13 +919,13 @@ function _t(e, t, a, r, o) {
|
|
|
917
919
|
...a
|
|
918
920
|
});
|
|
919
921
|
}
|
|
920
|
-
function
|
|
921
|
-
|
|
922
|
+
function Pt(e, t, a, r) {
|
|
923
|
+
F.get() <= 0 || (e === p.Start ? a.linkTrack(
|
|
922
924
|
"agent-video",
|
|
923
|
-
{ event: "start", latency:
|
|
925
|
+
{ event: "start", latency: F.get(!0), "stream-type": r },
|
|
924
926
|
"start",
|
|
925
|
-
[
|
|
926
|
-
) : e ===
|
|
927
|
+
[L.StreamVideoCreated]
|
|
928
|
+
) : e === p.Stop && a.linkTrack(
|
|
927
929
|
"agent-video",
|
|
928
930
|
{
|
|
929
931
|
event: "stop",
|
|
@@ -932,16 +934,16 @@ function Tt(e, t, a, r) {
|
|
|
932
934
|
"stream-type": r
|
|
933
935
|
},
|
|
934
936
|
"done",
|
|
935
|
-
[
|
|
937
|
+
[L.StreamVideoDone]
|
|
936
938
|
));
|
|
937
939
|
}
|
|
938
|
-
function
|
|
939
|
-
|
|
940
|
+
function bt(e, t, a, r, o) {
|
|
941
|
+
F.get() <= 0 || (e === p.Start ? r.linkTrack(
|
|
940
942
|
"agent-video",
|
|
941
|
-
{ event: "start", latency:
|
|
943
|
+
{ event: "start", latency: F.get(!0), "stream-type": o },
|
|
942
944
|
"start",
|
|
943
|
-
[
|
|
944
|
-
) : e ===
|
|
945
|
+
[L.StreamVideoCreated]
|
|
946
|
+
) : e === p.Stop && r.linkTrack(
|
|
945
947
|
"agent-video",
|
|
946
948
|
{
|
|
947
949
|
event: "stop",
|
|
@@ -951,25 +953,25 @@ function At(e, t, a, r, o) {
|
|
|
951
953
|
...a
|
|
952
954
|
},
|
|
953
955
|
"done",
|
|
954
|
-
[
|
|
956
|
+
[L.StreamVideoDone]
|
|
955
957
|
));
|
|
956
958
|
}
|
|
957
959
|
function ge(e, t, a) {
|
|
958
|
-
return
|
|
960
|
+
return F.reset(), new Promise(async (r, o) => {
|
|
959
961
|
try {
|
|
960
962
|
let i, c = !1;
|
|
961
|
-
i = await
|
|
963
|
+
i = await St(e, _t(e, t), {
|
|
962
964
|
...t,
|
|
963
965
|
analytics: a,
|
|
964
966
|
callbacks: {
|
|
965
967
|
...t.callbacks,
|
|
966
968
|
onConnectionStateChange: (n) => {
|
|
967
969
|
var s, d;
|
|
968
|
-
(d = (s = t.callbacks).onConnectionStateChange) == null || d.call(s, n), n ===
|
|
970
|
+
(d = (s = t.callbacks).onConnectionStateChange) == null || d.call(s, n), n === _.Connected && (i ? r(i) : c = !0);
|
|
969
971
|
},
|
|
970
972
|
onVideoStateChange: (n, s) => {
|
|
971
973
|
var d, l;
|
|
972
|
-
(l = (d = t.callbacks).onVideoStateChange) == null || l.call(d, n),
|
|
974
|
+
(l = (d = t.callbacks).onVideoStateChange) == null || l.call(d, n), Tt(
|
|
973
975
|
n,
|
|
974
976
|
e,
|
|
975
977
|
s,
|
|
@@ -979,8 +981,8 @@ function ge(e, t, a) {
|
|
|
979
981
|
},
|
|
980
982
|
onAgentActivityStateChange: (n) => {
|
|
981
983
|
var s, d;
|
|
982
|
-
(d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n ===
|
|
983
|
-
n ===
|
|
984
|
+
(d = (s = t.callbacks).onAgentActivityStateChange) == null || d.call(s, n), n === X.Talking ? ie.update() : ie.reset(), Pt(
|
|
985
|
+
n === X.Talking ? p.Start : p.Stop,
|
|
984
986
|
e,
|
|
985
987
|
a,
|
|
986
988
|
i.streamType
|
|
@@ -994,130 +996,135 @@ function ge(e, t, a) {
|
|
|
994
996
|
});
|
|
995
997
|
}
|
|
996
998
|
async function jt(e, t, a, r, o) {
|
|
997
|
-
var l,
|
|
999
|
+
var l, u, y, P;
|
|
998
1000
|
const i = async () => {
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1001
|
+
if (de(e.presenter.type)) {
|
|
1002
|
+
const A = await ge(e, t, r), N = `${It}_${A.sessionId}`, b = (/* @__PURE__ */ new Date()).toISOString();
|
|
1003
|
+
return { chatResult: {
|
|
1004
|
+
chatMode: I.Functional,
|
|
1005
|
+
chat: {
|
|
1006
|
+
id: N,
|
|
1007
|
+
agent_id: e.id,
|
|
1008
|
+
owner_id: e.owner_id ?? "",
|
|
1009
|
+
created: b,
|
|
1010
|
+
modified: b,
|
|
1011
|
+
agent_id__created_at: b,
|
|
1012
|
+
agent_id__modified_at: b,
|
|
1013
|
+
chat_mode: I.Functional,
|
|
1014
|
+
messages: []
|
|
1015
|
+
}
|
|
1016
|
+
}, streamingManager: A };
|
|
1014
1017
|
} else {
|
|
1015
|
-
const
|
|
1018
|
+
const A = Re(
|
|
1016
1019
|
e,
|
|
1017
1020
|
a,
|
|
1018
1021
|
r,
|
|
1019
1022
|
t.mode,
|
|
1020
1023
|
t.persistentChat,
|
|
1021
1024
|
o
|
|
1022
|
-
),
|
|
1023
|
-
return { chatResult:
|
|
1025
|
+
), N = ge(e, t, r), [b, x] = await Promise.all([A, N]);
|
|
1026
|
+
return { chatResult: b, streamingManager: x };
|
|
1024
1027
|
}
|
|
1025
1028
|
}, { chatResult: c, streamingManager: n } = await i(), { chat: s, chatMode: d } = c;
|
|
1026
|
-
return d && d !== t.mode && (t.mode = d, (
|
|
1029
|
+
return d && d !== t.mode && (t.mode = d, (u = (l = t.callbacks).onModeChange) == null || u.call(l, d), d !== I.Functional) ? ((P = (y = t.callbacks).onError) == null || P.call(y, new Me(d)), n == null || n.disconnect(), { chat: s }) : { chat: s, streamingManager: n };
|
|
1027
1030
|
}
|
|
1028
|
-
async function
|
|
1029
|
-
var
|
|
1031
|
+
async function $t(e, t) {
|
|
1032
|
+
var G, $, Y;
|
|
1030
1033
|
let a = !0, r = null;
|
|
1031
|
-
const o = t.mixpanelKey ||
|
|
1034
|
+
const o = t.mixpanelKey || Je, i = t.wsURL || Ne, c = t.baseURL || te, n = {
|
|
1032
1035
|
messages: [],
|
|
1033
|
-
chatMode: t.mode ||
|
|
1034
|
-
}, s =
|
|
1036
|
+
chatMode: t.mode || I.Functional
|
|
1037
|
+
}, s = Ze({
|
|
1035
1038
|
token: o,
|
|
1036
1039
|
agentId: e,
|
|
1037
1040
|
isEnabled: t.enableAnalitics,
|
|
1038
1041
|
externalId: t.externalId,
|
|
1039
1042
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1043
|
+
}), d = Date.now();
|
|
1044
|
+
ue(() => {
|
|
1045
|
+
s.track("agent-sdk", { event: "init" }, d);
|
|
1040
1046
|
});
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
const { onMessage: y, clearQueue: b } = st(
|
|
1047
|
+
const l = Ve(t.auth, c, t.callbacks.onError, t.externalId), u = await l.getById(e), y = de(u.presenter.type);
|
|
1048
|
+
s.enrich(Oe(u));
|
|
1049
|
+
const { onMessage: P, clearQueue: A } = ot(
|
|
1045
1050
|
s,
|
|
1046
1051
|
n,
|
|
1047
1052
|
t,
|
|
1048
|
-
|
|
1053
|
+
u,
|
|
1049
1054
|
() => {
|
|
1050
|
-
var
|
|
1051
|
-
return (
|
|
1055
|
+
var f;
|
|
1056
|
+
return (f = n.socketManager) == null ? void 0 : f.disconnect();
|
|
1052
1057
|
}
|
|
1053
1058
|
);
|
|
1054
|
-
n.messages =
|
|
1055
|
-
const
|
|
1056
|
-
r =
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1059
|
+
n.messages = Ge(t.initialMessages), ($ = (G = t.callbacks).onNewMessage) == null || $.call(G, [...n.messages], "answer");
|
|
1060
|
+
const N = (f) => {
|
|
1061
|
+
r = f;
|
|
1062
|
+
}, b = Date.now();
|
|
1063
|
+
ue(() => {
|
|
1064
|
+
s.track("agent-sdk", { event: "loaded", ...qe(u) }, b);
|
|
1065
|
+
});
|
|
1066
|
+
async function x(f) {
|
|
1067
|
+
var j, B, z, C, T, W, v;
|
|
1068
|
+
(B = (j = t.callbacks).onConnectionStateChange) == null || B.call(j, _.Connecting), F.reset(), f && !a && (delete n.chat, (C = (z = t.callbacks).onNewMessage) == null || C.call(z, [...n.messages], "answer"));
|
|
1069
|
+
const D = t.mode === I.DirectPlayback || y ? Promise.resolve(void 0) : at(
|
|
1063
1070
|
t.auth,
|
|
1064
1071
|
i,
|
|
1065
|
-
{ onMessage:
|
|
1072
|
+
{ onMessage: P, onError: t.callbacks.onError },
|
|
1066
1073
|
t.externalId
|
|
1067
|
-
),
|
|
1074
|
+
), g = ne(
|
|
1068
1075
|
() => jt(
|
|
1069
|
-
|
|
1076
|
+
u,
|
|
1070
1077
|
{
|
|
1071
1078
|
...t,
|
|
1072
|
-
callbacks: { ...t.callbacks, onVideoIdChange:
|
|
1079
|
+
callbacks: { ...t.callbacks, onVideoIdChange: N, onMessage: P }
|
|
1073
1080
|
},
|
|
1074
|
-
|
|
1081
|
+
l,
|
|
1075
1082
|
s,
|
|
1076
1083
|
n.chat
|
|
1077
1084
|
),
|
|
1078
1085
|
{
|
|
1079
1086
|
limit: 3,
|
|
1080
|
-
timeout:
|
|
1087
|
+
timeout: ze,
|
|
1081
1088
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1082
1089
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1083
|
-
shouldRetryFn: (
|
|
1090
|
+
shouldRetryFn: (E) => (E == null ? void 0 : E.message) !== "Could not connect" && E.status !== 429,
|
|
1084
1091
|
delayMs: 1e3
|
|
1085
1092
|
}
|
|
1086
|
-
).catch((
|
|
1087
|
-
var
|
|
1088
|
-
throw
|
|
1089
|
-
}), [
|
|
1090
|
-
|
|
1091
|
-
chatId:
|
|
1092
|
-
streamId:
|
|
1093
|
+
).catch((E) => {
|
|
1094
|
+
var H, m;
|
|
1095
|
+
throw K(I.Maintenance), (m = (H = t.callbacks).onConnectionStateChange) == null || m.call(H, _.Fail), E;
|
|
1096
|
+
}), [S, { streamingManager: w, chat: k }] = await Promise.all([D, g]);
|
|
1097
|
+
k && k.id !== ((T = n.chat) == null ? void 0 : T.id) && ((v = (W = t.callbacks).onNewChat) == null || v.call(W, k.id)), n.streamingManager = w, n.socketManager = S, n.chat = k, a = !1, s.enrich({
|
|
1098
|
+
chatId: k == null ? void 0 : k.id,
|
|
1099
|
+
streamId: w == null ? void 0 : w.streamId,
|
|
1093
1100
|
mode: n.chatMode
|
|
1094
|
-
}),
|
|
1101
|
+
}), K((k == null ? void 0 : k.chat_mode) ?? t.mode ?? I.Functional);
|
|
1095
1102
|
}
|
|
1096
|
-
async function
|
|
1097
|
-
var
|
|
1098
|
-
(
|
|
1103
|
+
async function R() {
|
|
1104
|
+
var f, D, g, S;
|
|
1105
|
+
(f = n.socketManager) == null || f.disconnect(), await ((D = n.streamingManager) == null ? void 0 : D.disconnect()), delete n.streamingManager, delete n.socketManager, (S = (g = t.callbacks).onConnectionStateChange) == null || S.call(g, _.Disconnected);
|
|
1099
1106
|
}
|
|
1100
|
-
async function
|
|
1101
|
-
var
|
|
1102
|
-
|
|
1107
|
+
async function K(f) {
|
|
1108
|
+
var D, g;
|
|
1109
|
+
f !== n.chatMode && (s.track("agent-mode-change", { mode: f }), n.chatMode = f, n.chatMode !== I.Functional && await R(), (g = (D = t.callbacks).onModeChange) == null || g.call(D, f));
|
|
1103
1110
|
}
|
|
1104
1111
|
return {
|
|
1105
|
-
agent:
|
|
1112
|
+
agent: u,
|
|
1106
1113
|
getStreamType: () => {
|
|
1107
|
-
var
|
|
1108
|
-
return (
|
|
1114
|
+
var f;
|
|
1115
|
+
return (f = n.streamingManager) == null ? void 0 : f.streamType;
|
|
1109
1116
|
},
|
|
1110
1117
|
getIsInterruptAvailable: () => {
|
|
1111
|
-
var
|
|
1112
|
-
return ((
|
|
1118
|
+
var f;
|
|
1119
|
+
return ((f = n.streamingManager) == null ? void 0 : f.interruptAvailable) ?? !1;
|
|
1113
1120
|
},
|
|
1114
1121
|
getIsTriggersAvailable: () => {
|
|
1115
|
-
var
|
|
1116
|
-
return ((
|
|
1122
|
+
var f;
|
|
1123
|
+
return ((f = n.streamingManager) == null ? void 0 : f.triggersAvailable) ?? !1;
|
|
1117
1124
|
},
|
|
1118
|
-
starterMessages: ((
|
|
1119
|
-
getSTTToken: () =>
|
|
1120
|
-
changeMode:
|
|
1125
|
+
starterMessages: ((Y = u.knowledge) == null ? void 0 : Y.starter_message) || [],
|
|
1126
|
+
getSTTToken: () => l.getSTTToken(u.id),
|
|
1127
|
+
changeMode: K,
|
|
1121
1128
|
enrichAnalytics: s.enrich,
|
|
1122
1129
|
async connect() {
|
|
1123
1130
|
await x(!0), s.track("agent-chat", {
|
|
@@ -1126,62 +1133,62 @@ async function Lt(e, t) {
|
|
|
1126
1133
|
});
|
|
1127
1134
|
},
|
|
1128
1135
|
async reconnect() {
|
|
1129
|
-
await
|
|
1136
|
+
await R(), await x(!1), s.track("agent-chat", {
|
|
1130
1137
|
event: "reconnect",
|
|
1131
1138
|
mode: n.chatMode
|
|
1132
1139
|
});
|
|
1133
1140
|
},
|
|
1134
1141
|
async disconnect() {
|
|
1135
|
-
await
|
|
1142
|
+
await R(), s.track("agent-chat", {
|
|
1136
1143
|
event: "disconnect",
|
|
1137
1144
|
mode: n.chatMode
|
|
1138
1145
|
});
|
|
1139
1146
|
},
|
|
1140
|
-
async chat(
|
|
1141
|
-
var
|
|
1142
|
-
const
|
|
1147
|
+
async chat(f) {
|
|
1148
|
+
var w, k, j, B, z;
|
|
1149
|
+
const D = () => {
|
|
1143
1150
|
if (ve(t.mode))
|
|
1144
|
-
throw new
|
|
1145
|
-
if (
|
|
1146
|
-
throw new
|
|
1147
|
-
if (
|
|
1148
|
-
throw new
|
|
1149
|
-
if (n.chatMode ===
|
|
1150
|
-
throw new
|
|
1151
|
-
if (![
|
|
1151
|
+
throw new V(`${t.mode} is enabled, chat is disabled`);
|
|
1152
|
+
if (f.length >= 800)
|
|
1153
|
+
throw new V("Message cannot be more than 800 characters");
|
|
1154
|
+
if (f.length === 0)
|
|
1155
|
+
throw new V("Message cannot be empty");
|
|
1156
|
+
if (n.chatMode === I.Maintenance)
|
|
1157
|
+
throw new V("Chat is in maintenance mode");
|
|
1158
|
+
if (![I.TextOnly, I.Playground].includes(n.chatMode)) {
|
|
1152
1159
|
if (!n.streamingManager)
|
|
1153
|
-
throw new
|
|
1160
|
+
throw new V("Streaming manager is not initialized");
|
|
1154
1161
|
if (!n.chat)
|
|
1155
|
-
throw new
|
|
1162
|
+
throw new V("Chat is not initialized");
|
|
1156
1163
|
}
|
|
1157
|
-
},
|
|
1158
|
-
var C,
|
|
1164
|
+
}, g = async () => {
|
|
1165
|
+
var C, T;
|
|
1159
1166
|
if (!n.chat) {
|
|
1160
|
-
const
|
|
1167
|
+
const W = await Re(
|
|
1168
|
+
u,
|
|
1161
1169
|
l,
|
|
1162
|
-
d,
|
|
1163
1170
|
s,
|
|
1164
1171
|
n.chatMode,
|
|
1165
1172
|
t.persistentChat
|
|
1166
1173
|
);
|
|
1167
|
-
if (!
|
|
1168
|
-
throw new
|
|
1169
|
-
n.chat =
|
|
1174
|
+
if (!W.chat)
|
|
1175
|
+
throw new Ee(n.chatMode, !!t.persistentChat);
|
|
1176
|
+
n.chat = W.chat, (T = (C = t.callbacks).onNewChat) == null || T.call(C, n.chat.id);
|
|
1170
1177
|
}
|
|
1171
1178
|
return n.chat.id;
|
|
1172
|
-
},
|
|
1173
|
-
var
|
|
1174
|
-
return await ((
|
|
1179
|
+
}, S = async (C, T) => ne(y ? async () => {
|
|
1180
|
+
var v, E;
|
|
1181
|
+
return await ((E = (v = n.streamingManager) == null ? void 0 : v.sendTextMessage) == null ? void 0 : E.call(v, f)), Promise.resolve({});
|
|
1175
1182
|
} : async () => {
|
|
1176
|
-
var
|
|
1177
|
-
return
|
|
1178
|
-
|
|
1179
|
-
|
|
1183
|
+
var v, E;
|
|
1184
|
+
return l.chat(
|
|
1185
|
+
u.id,
|
|
1186
|
+
T,
|
|
1180
1187
|
{
|
|
1181
1188
|
chatMode: n.chatMode,
|
|
1182
|
-
streamId: (
|
|
1183
|
-
sessionId: (
|
|
1184
|
-
messages: C.map(({ matches:
|
|
1189
|
+
streamId: (v = n.streamingManager) == null ? void 0 : v.streamId,
|
|
1190
|
+
sessionId: (E = n.streamingManager) == null ? void 0 : E.sessionId,
|
|
1191
|
+
messages: C.map(({ matches: H, ...m }) => m)
|
|
1185
1192
|
},
|
|
1186
1193
|
{
|
|
1187
1194
|
...Ce(n.chatMode),
|
|
@@ -1190,37 +1197,37 @@ async function Lt(e, t) {
|
|
|
1190
1197
|
);
|
|
1191
1198
|
}, {
|
|
1192
1199
|
limit: 2,
|
|
1193
|
-
shouldRetryFn: (
|
|
1194
|
-
var
|
|
1195
|
-
const
|
|
1196
|
-
return !((
|
|
1200
|
+
shouldRetryFn: (v) => {
|
|
1201
|
+
var m, h, M, U;
|
|
1202
|
+
const E = (m = v == null ? void 0 : v.message) == null ? void 0 : m.includes("missing or invalid session_id");
|
|
1203
|
+
return !((h = v == null ? void 0 : v.message) == null ? void 0 : h.includes("Stream Error")) && !E ? ((U = (M = t.callbacks).onError) == null || U.call(M, v), !1) : !0;
|
|
1197
1204
|
},
|
|
1198
1205
|
onRetry: async () => {
|
|
1199
|
-
await
|
|
1206
|
+
await R(), await x(!1);
|
|
1200
1207
|
}
|
|
1201
1208
|
});
|
|
1202
1209
|
try {
|
|
1203
|
-
|
|
1204
|
-
id:
|
|
1210
|
+
A(), D(), n.messages.push({
|
|
1211
|
+
id: O(),
|
|
1205
1212
|
role: "user",
|
|
1206
|
-
content:
|
|
1207
|
-
created_at: new Date(
|
|
1208
|
-
}), (
|
|
1209
|
-
const C = await
|
|
1213
|
+
content: f,
|
|
1214
|
+
created_at: new Date(F.update()).toISOString()
|
|
1215
|
+
}), (k = (w = t.callbacks).onNewMessage) == null || k.call(w, [...n.messages], "user");
|
|
1216
|
+
const C = await g(), T = await S([...n.messages], C);
|
|
1210
1217
|
return n.messages.push({
|
|
1211
|
-
id:
|
|
1218
|
+
id: O(),
|
|
1212
1219
|
role: "assistant",
|
|
1213
|
-
content:
|
|
1220
|
+
content: T.result || "",
|
|
1214
1221
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1215
|
-
context:
|
|
1216
|
-
matches:
|
|
1222
|
+
context: T.context,
|
|
1223
|
+
matches: T.matches
|
|
1217
1224
|
}), s.track("agent-message-send", {
|
|
1218
1225
|
event: "success",
|
|
1219
1226
|
messages: n.messages.length + 1
|
|
1220
|
-
}),
|
|
1221
|
-
latency:
|
|
1227
|
+
}), T.result && ((B = (j = t.callbacks).onNewMessage) == null || B.call(j, [...n.messages], "answer"), s.track("agent-message-received", {
|
|
1228
|
+
latency: F.get(!0),
|
|
1222
1229
|
messages: n.messages.length
|
|
1223
|
-
})),
|
|
1230
|
+
})), T;
|
|
1224
1231
|
} catch (C) {
|
|
1225
1232
|
throw ((z = n.messages[n.messages.length - 1]) == null ? void 0 : z.role) === "assistant" && n.messages.pop(), s.track("agent-message-send", {
|
|
1226
1233
|
event: "error",
|
|
@@ -1228,69 +1235,69 @@ async function Lt(e, t) {
|
|
|
1228
1235
|
}), C;
|
|
1229
1236
|
}
|
|
1230
1237
|
},
|
|
1231
|
-
rate(
|
|
1232
|
-
var
|
|
1233
|
-
const
|
|
1238
|
+
rate(f, D, g) {
|
|
1239
|
+
var k, j, B, z;
|
|
1240
|
+
const S = n.messages.find((C) => C.id === f);
|
|
1234
1241
|
if (n.chat) {
|
|
1235
|
-
if (!
|
|
1242
|
+
if (!S)
|
|
1236
1243
|
throw new Error("Message not found");
|
|
1237
1244
|
} else throw new Error("Chat is not initialized");
|
|
1238
|
-
const
|
|
1245
|
+
const w = ((k = S.matches) == null ? void 0 : k.map((C) => [C.document_id, C.id])) ?? [];
|
|
1239
1246
|
return s.track("agent-rate", {
|
|
1240
|
-
event:
|
|
1241
|
-
thumb:
|
|
1242
|
-
knowledge_id: ((
|
|
1243
|
-
matches:
|
|
1244
|
-
score:
|
|
1245
|
-
}),
|
|
1246
|
-
knowledge_id: ((
|
|
1247
|
-
message_id:
|
|
1248
|
-
matches:
|
|
1249
|
-
score:
|
|
1250
|
-
}) :
|
|
1251
|
-
knowledge_id: ((z =
|
|
1252
|
-
message_id:
|
|
1253
|
-
matches:
|
|
1254
|
-
score:
|
|
1247
|
+
event: g ? "update" : "create",
|
|
1248
|
+
thumb: D === 1 ? "up" : "down",
|
|
1249
|
+
knowledge_id: ((j = u.knowledge) == null ? void 0 : j.id) ?? "",
|
|
1250
|
+
matches: w,
|
|
1251
|
+
score: D
|
|
1252
|
+
}), g ? l.updateRating(u.id, n.chat.id, g, {
|
|
1253
|
+
knowledge_id: ((B = u.knowledge) == null ? void 0 : B.id) ?? "",
|
|
1254
|
+
message_id: f,
|
|
1255
|
+
matches: w,
|
|
1256
|
+
score: D
|
|
1257
|
+
}) : l.createRating(u.id, n.chat.id, {
|
|
1258
|
+
knowledge_id: ((z = u.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1259
|
+
message_id: f,
|
|
1260
|
+
matches: w,
|
|
1261
|
+
score: D
|
|
1255
1262
|
});
|
|
1256
1263
|
},
|
|
1257
|
-
deleteRate(
|
|
1264
|
+
deleteRate(f) {
|
|
1258
1265
|
if (!n.chat)
|
|
1259
1266
|
throw new Error("Chat is not initialized");
|
|
1260
|
-
return s.track("agent-rate-delete", { type: "text" }),
|
|
1267
|
+
return s.track("agent-rate-delete", { type: "text" }), l.deleteRating(u.id, n.chat.id, f);
|
|
1261
1268
|
},
|
|
1262
|
-
async speak(
|
|
1263
|
-
var
|
|
1264
|
-
function
|
|
1265
|
-
if (typeof
|
|
1266
|
-
if (!
|
|
1269
|
+
async speak(f) {
|
|
1270
|
+
var w, k, j;
|
|
1271
|
+
function D() {
|
|
1272
|
+
if (typeof f == "string") {
|
|
1273
|
+
if (!u.presenter.voice)
|
|
1267
1274
|
throw new Error("Presenter voice is not initialized");
|
|
1268
1275
|
return {
|
|
1269
1276
|
type: "text",
|
|
1270
|
-
provider:
|
|
1271
|
-
input:
|
|
1277
|
+
provider: u.presenter.voice,
|
|
1278
|
+
input: f,
|
|
1272
1279
|
ssml: !1
|
|
1273
1280
|
};
|
|
1274
1281
|
}
|
|
1275
|
-
if (
|
|
1276
|
-
if (!
|
|
1282
|
+
if (f.type === "text" && !f.provider) {
|
|
1283
|
+
if (!u.presenter.voice)
|
|
1277
1284
|
throw new Error("Presenter voice is not initialized");
|
|
1278
1285
|
return {
|
|
1279
1286
|
type: "text",
|
|
1280
|
-
provider:
|
|
1281
|
-
input:
|
|
1282
|
-
ssml:
|
|
1287
|
+
provider: u.presenter.voice,
|
|
1288
|
+
input: f.input,
|
|
1289
|
+
ssml: f.ssml
|
|
1283
1290
|
};
|
|
1284
1291
|
}
|
|
1285
|
-
return
|
|
1292
|
+
return f;
|
|
1286
1293
|
}
|
|
1287
|
-
const
|
|
1288
|
-
if (s.track("agent-speak",
|
|
1289
|
-
id:
|
|
1294
|
+
const g = D();
|
|
1295
|
+
if (s.track("agent-speak", g), F.update(), n.messages && g.type === "text" && (n.messages.push({
|
|
1296
|
+
id: O(),
|
|
1290
1297
|
role: "assistant",
|
|
1291
|
-
content:
|
|
1298
|
+
content: g.input,
|
|
1292
1299
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1293
|
-
}), (
|
|
1300
|
+
}), (k = (w = t.callbacks).onNewMessage) == null || k.call(w, [...n.messages], "answer")), We(n.chatMode))
|
|
1294
1301
|
return {
|
|
1295
1302
|
duration: 0,
|
|
1296
1303
|
video_id: "",
|
|
@@ -1299,49 +1306,49 @@ async function Lt(e, t) {
|
|
|
1299
1306
|
if (!n.streamingManager)
|
|
1300
1307
|
throw new Error("Please connect to the agent first");
|
|
1301
1308
|
return n.streamingManager.speak({
|
|
1302
|
-
script:
|
|
1303
|
-
metadata: { chat_id: (
|
|
1309
|
+
script: g,
|
|
1310
|
+
metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: u.id }
|
|
1304
1311
|
});
|
|
1305
1312
|
},
|
|
1306
|
-
async interrupt({ type:
|
|
1307
|
-
var
|
|
1308
|
-
|
|
1309
|
-
const
|
|
1313
|
+
async interrupt({ type: f }) {
|
|
1314
|
+
var g, S, w;
|
|
1315
|
+
et(n.streamingManager, (g = n.streamingManager) == null ? void 0 : g.streamType, r);
|
|
1316
|
+
const D = n.messages[n.messages.length - 1];
|
|
1310
1317
|
s.track("agent-video-interrupt", {
|
|
1311
|
-
type:
|
|
1318
|
+
type: f || "click",
|
|
1312
1319
|
video_duration_to_interrupt: ie.get(!0),
|
|
1313
|
-
message_duration_to_interrupt:
|
|
1314
|
-
}),
|
|
1320
|
+
message_duration_to_interrupt: F.get(!0)
|
|
1321
|
+
}), D.interrupted = !0, (w = (S = t.callbacks).onNewMessage) == null || w.call(S, [...n.messages], "answer"), tt(n.streamingManager, r);
|
|
1315
1322
|
}
|
|
1316
1323
|
};
|
|
1317
1324
|
}
|
|
1318
1325
|
export {
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1326
|
+
X as A,
|
|
1327
|
+
_ as C,
|
|
1328
|
+
xe as D,
|
|
1329
|
+
Le as K,
|
|
1330
|
+
Ae as P,
|
|
1331
|
+
be as R,
|
|
1332
|
+
J as S,
|
|
1333
|
+
ce as T,
|
|
1334
|
+
Te as U,
|
|
1335
|
+
V,
|
|
1336
|
+
_e as W,
|
|
1337
|
+
dt as a,
|
|
1331
1338
|
Z as b,
|
|
1332
1339
|
ke as c,
|
|
1333
1340
|
te as d,
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1341
|
+
p as e,
|
|
1342
|
+
L as f,
|
|
1343
|
+
q as g,
|
|
1344
|
+
Ee as h,
|
|
1345
|
+
Me as i,
|
|
1346
|
+
$t as j,
|
|
1347
|
+
Pe as k,
|
|
1348
|
+
I as l,
|
|
1349
|
+
je as m,
|
|
1343
1350
|
he as n,
|
|
1344
|
-
|
|
1345
|
-
|
|
1351
|
+
xt as o,
|
|
1352
|
+
$e as p,
|
|
1346
1353
|
Be as q
|
|
1347
1354
|
};
|