@d-id/client-sdk 1.1.24-staging.111 → 1.1.24-staging.114
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 +503 -496
- package/dist/index.umd.cjs +13 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var ue = (e, t, i) =>
|
|
1
|
+
var Oe = Object.defineProperty;
|
|
2
|
+
var Ve = (e, t, i) => t in e ? Oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var ue = (e, t, i) => Ve(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
4
|
class ge extends Error {
|
|
5
5
|
constructor({ kind: i, description: n, error: c }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: n }));
|
|
@@ -10,7 +10,7 @@ class ge extends Error {
|
|
|
10
10
|
this.kind = i, this.description = n, this.error = c;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class He extends ge {
|
|
14
14
|
constructor(t, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,7 +18,7 @@ class Ve extends ge {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class qe extends ge {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
@@ -30,13 +30,13 @@ class se extends ge {
|
|
|
30
30
|
this.key = n;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class Qe extends ge {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ye || {}), Ze = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ze || {}), Ge = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ge || {}), U = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(U || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(tt || {}), nt = /* @__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))(nt || {}), Be = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Be || {});
|
|
39
|
+
const dn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,12 +48,12 @@ const sn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
52
|
-
const
|
|
51
|
+
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(ae || {}), N = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(N || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ne = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ne || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), it = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(it || {});
|
|
52
|
+
const at = 45 * 1e3, ot = "X-Playground-Chat", fe = "https://api.d-id.com", st = "wss://notifications.d-id.com", ct = "79f81a83a67430be2bc0fd61042b8faa", Fe = (e) => new Promise((t) => setTimeout(t, e)), ce = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
54
|
return window.crypto.getRandomValues(t), Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
-
},
|
|
56
|
-
function
|
|
55
|
+
}, ze = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Me = (e) => e === Be.Expressive, dt = (e) => [U.TextOnly, U.Playground, U.Maintenance].includes(e), Ne = (e) => e && [U.DirectPlayback, U.Off].includes(e);
|
|
56
|
+
function ut(e, t) {
|
|
57
57
|
let i;
|
|
58
58
|
return {
|
|
59
59
|
promise: new Promise((c, o) => {
|
|
@@ -62,7 +62,7 @@ function ct(e, t) {
|
|
|
62
62
|
clear: () => clearTimeout(i)
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
async function
|
|
65
|
+
async function ve(e, t) {
|
|
66
66
|
const i = {
|
|
67
67
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
68
68
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -77,16 +77,16 @@ async function ye(e, t) {
|
|
|
77
77
|
try {
|
|
78
78
|
if (!i.timeout)
|
|
79
79
|
return await e();
|
|
80
|
-
const { promise: o, clear: s } =
|
|
80
|
+
const { promise: o, clear: s } = ut(i.timeout, i.timeoutErrorMessage), a = e().finally(s);
|
|
81
81
|
return await Promise.race([a, o]);
|
|
82
82
|
} catch (o) {
|
|
83
83
|
if (n = o, !i.shouldRetryFn(o) || c >= i.limit)
|
|
84
84
|
throw o;
|
|
85
|
-
await
|
|
85
|
+
await Fe(i.delayMs), i.onRetry(o);
|
|
86
86
|
}
|
|
87
87
|
throw n;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function Se(e) {
|
|
90
90
|
if (e !== void 0)
|
|
91
91
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
92
92
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
@@ -96,30 +96,30 @@ function ve(e) {
|
|
|
96
96
|
}
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
|
-
let
|
|
100
|
-
function
|
|
99
|
+
let lt = ce();
|
|
100
|
+
function Ke(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}.${
|
|
106
|
+
return `Client-Key ${e.clientKey}.${Se(t)}_${lt}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const ft = (e) => ve(e, {
|
|
110
110
|
limit: 3,
|
|
111
111
|
delayMs: 1e3,
|
|
112
112
|
timeout: 0,
|
|
113
113
|
shouldRetryFn: (t) => t.status === 429
|
|
114
114
|
});
|
|
115
|
-
function
|
|
115
|
+
function Ee(e, t = fe, i, n) {
|
|
116
116
|
const c = async (o, s) => {
|
|
117
|
-
const { skipErrorHandler: a, ...r } = s || {}, d = await
|
|
117
|
+
const { skipErrorHandler: a, ...r } = s || {}, d = await ft(
|
|
118
118
|
() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
119
119
|
...r,
|
|
120
120
|
headers: {
|
|
121
121
|
...r.headers,
|
|
122
|
-
Authorization:
|
|
122
|
+
Authorization: Ke(e, n),
|
|
123
123
|
"Content-Type": "application/json"
|
|
124
124
|
}
|
|
125
125
|
})
|
|
@@ -146,8 +146,8 @@ function Me(e, t = fe, i, n) {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const c =
|
|
149
|
+
function mt(e, t = fe, i, n) {
|
|
150
|
+
const c = Ee(e, `${t}/agents`, i, n);
|
|
151
151
|
return {
|
|
152
152
|
create(o, s) {
|
|
153
153
|
return c.post("/", o, s);
|
|
@@ -184,7 +184,7 @@ function lt(e, t = fe, i, n) {
|
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function gt(e) {
|
|
188
188
|
var c, o, s, a;
|
|
189
189
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
190
190
|
const r = navigator.platform;
|
|
@@ -195,18 +195,18 @@ function ft(e) {
|
|
|
195
195
|
isMobile: `${t() == "Mobile"}`,
|
|
196
196
|
browser: navigator.userAgent,
|
|
197
197
|
origin: window.location.origin,
|
|
198
|
-
agentType:
|
|
198
|
+
agentType: ze(n),
|
|
199
199
|
agentVoice: {
|
|
200
200
|
voiceId: (o = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : o.voice_id,
|
|
201
201
|
provider: (a = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : a.type
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function ht(e) {
|
|
206
206
|
var i, n, c, o, s, a;
|
|
207
207
|
const t = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
208
208
|
return {
|
|
209
|
-
agentType:
|
|
209
|
+
agentType: ze(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
211
211
|
promptVersion: (n = e.llm) == null ? void 0 : n.prompt_version,
|
|
212
212
|
behavior: {
|
|
@@ -225,8 +225,8 @@ function mt(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
228
|
+
const pt = (e) => e.reduce((t, i) => t + i, 0), Pe = (e) => pt(e) / e.length;
|
|
229
|
+
function wt(e, t, i) {
|
|
230
230
|
var r, d, m;
|
|
231
231
|
const { event: n, ...c } = e, { template: o } = (t == null ? void 0 : t.llm) || {}, { language: s } = ((r = t == null ? void 0 : t.presenter) == null ? void 0 : r.voice) || {};
|
|
232
232
|
return {
|
|
@@ -237,19 +237,19 @@ function ht(e, t, i) {
|
|
|
237
237
|
...i
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function be(e) {
|
|
241
241
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
242
|
}
|
|
243
|
-
let
|
|
244
|
-
const
|
|
245
|
-
function
|
|
243
|
+
let we = {};
|
|
244
|
+
const yt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
245
|
+
function vt(e) {
|
|
246
246
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
247
247
|
return {
|
|
248
248
|
token: e.token || "testKey",
|
|
249
|
-
distinct_id:
|
|
249
|
+
distinct_id: Se(e.externalId),
|
|
250
250
|
agentId: e.agentId,
|
|
251
251
|
additionalProperties: {
|
|
252
|
-
id:
|
|
252
|
+
id: Se(e.externalId),
|
|
253
253
|
...e.mixpanelAdditionalProperties || {}
|
|
254
254
|
},
|
|
255
255
|
isEnabled: e.isEnabled ?? !0,
|
|
@@ -286,14 +286,14 @@ function wt(e) {
|
|
|
286
286
|
])
|
|
287
287
|
})
|
|
288
288
|
};
|
|
289
|
-
return fetch(
|
|
289
|
+
return fetch(yt, {
|
|
290
290
|
...r,
|
|
291
291
|
keepalive: !0
|
|
292
292
|
}).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
|
|
293
293
|
},
|
|
294
294
|
linkTrack(i, n, c, o) {
|
|
295
|
-
|
|
296
|
-
const s =
|
|
295
|
+
we[i] || (we[i] = { events: {}, resolvedDependencies: [] }), o.includes(c) || o.push(c);
|
|
296
|
+
const s = we[i];
|
|
297
297
|
if (s.events[c] = { props: n }, s.resolvedDependencies.push(c), o.every(
|
|
298
298
|
(r) => s.resolvedDependencies.includes(r)
|
|
299
299
|
)) {
|
|
@@ -307,7 +307,7 @@ function wt(e) {
|
|
|
307
307
|
}
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
function
|
|
310
|
+
function Ie() {
|
|
311
311
|
let e = 0;
|
|
312
312
|
return {
|
|
313
313
|
reset: () => e = 0,
|
|
@@ -315,22 +315,22 @@ function Ee() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const te =
|
|
319
|
-
function
|
|
320
|
-
return e ===
|
|
318
|
+
const te = Ie(), Ce = Ie(), je = Ie();
|
|
319
|
+
function Je(e) {
|
|
320
|
+
return e === U.Playground ? { headers: { [ot]: "true" } } : {};
|
|
321
321
|
}
|
|
322
|
-
async function
|
|
322
|
+
async function Ue(e, t, i, n, c = !1, o) {
|
|
323
323
|
try {
|
|
324
|
-
return !o && !
|
|
324
|
+
return !o && !Ne(n) && (o = await t.newChat(e.id, { persist: c }, Je(n)), i.track("agent-chat", {
|
|
325
325
|
event: "created",
|
|
326
326
|
chatId: o.id,
|
|
327
327
|
mode: n
|
|
328
328
|
})), { chat: o, chatMode: (o == null ? void 0 : o.chat_mode) ?? n };
|
|
329
329
|
} catch (s) {
|
|
330
|
-
throw
|
|
330
|
+
throw St(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
const
|
|
333
|
+
const St = (e) => {
|
|
334
334
|
try {
|
|
335
335
|
const t = JSON.parse(e.message);
|
|
336
336
|
return t == null ? void 0 : t.kind;
|
|
@@ -338,19 +338,19 @@ const yt = (e) => {
|
|
|
338
338
|
return "UnknownError";
|
|
339
339
|
}
|
|
340
340
|
};
|
|
341
|
-
function
|
|
341
|
+
function Ct(e) {
|
|
342
342
|
return e && e.length > 0 ? e : [];
|
|
343
343
|
}
|
|
344
|
-
function
|
|
345
|
-
const c =
|
|
344
|
+
function kt(e, t, i, n) {
|
|
345
|
+
const c = Ee(e, `${t}/v2/agents/${i}`, n);
|
|
346
346
|
return {
|
|
347
347
|
async createStream(o) {
|
|
348
348
|
return c.post("/sessions", o);
|
|
349
349
|
}
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
const
|
|
353
|
-
async function
|
|
352
|
+
const We = (e, t) => (i, n) => e && console.log(`[${t}] ${i}`, n ?? "");
|
|
353
|
+
async function ye() {
|
|
354
354
|
try {
|
|
355
355
|
return await import("./livekit-client.esm-C1GRQdZY.js");
|
|
356
356
|
} catch {
|
|
@@ -359,7 +359,7 @@ async function we() {
|
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
|
-
const
|
|
362
|
+
const Rt = {
|
|
363
363
|
excellent: ee.Strong,
|
|
364
364
|
good: ee.Strong,
|
|
365
365
|
poor: ee.Weak,
|
|
@@ -369,184 +369,191 @@ const Ct = {
|
|
|
369
369
|
kind: "InternalServerError",
|
|
370
370
|
description: "Stream Error"
|
|
371
371
|
});
|
|
372
|
-
var
|
|
373
|
-
function
|
|
372
|
+
var Te = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Te || {});
|
|
373
|
+
function ke(e, t, i, n) {
|
|
374
374
|
var c, o;
|
|
375
|
-
throw t("Failed to connect to LiveKit room:", e), n(), (c = i.onConnectionStateChange) == null || c.call(i,
|
|
375
|
+
throw t("Failed to connect to LiveKit room:", e), n(), (c = i.onConnectionStateChange) == null || c.call(i, S.Fail), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
|
|
376
376
|
}
|
|
377
|
-
async function
|
|
378
|
-
var
|
|
379
|
-
const n =
|
|
380
|
-
let u = null,
|
|
377
|
+
async function Dt(e, t, i) {
|
|
378
|
+
var _e, Ae;
|
|
379
|
+
const n = We(i.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await ye(), { callbacks: a, auth: r, baseURL: d, analytics: m, microphoneStream: p } = i;
|
|
380
|
+
let u = null, E = !1;
|
|
381
381
|
const x = ne.Fluent;
|
|
382
|
-
let
|
|
382
|
+
let O = !0, I = null, A = null;
|
|
383
383
|
u = new c({
|
|
384
384
|
adaptiveStream: !1,
|
|
385
385
|
// Must be false to use mediaStreamTrack directly
|
|
386
386
|
dynacast: !0
|
|
387
387
|
});
|
|
388
|
-
|
|
389
|
-
|
|
388
|
+
let L = null;
|
|
389
|
+
const T = 2e4, re = kt(r, d || fe, e, a.onError);
|
|
390
|
+
let B, K, X;
|
|
390
391
|
try {
|
|
391
|
-
const l = await
|
|
392
|
+
const l = await re.createStream({
|
|
392
393
|
transport_provider: he.Livekit,
|
|
393
394
|
chat_persist: t.chat_persist ?? !0
|
|
394
|
-
}), { id: g, session_token: v, session_url:
|
|
395
|
-
(
|
|
395
|
+
}), { id: g, session_token: v, session_url: k } = l;
|
|
396
|
+
(_e = a.onStreamCreated) == null || _e.call(a, { session_id: g, stream_id: g, agent_id: e }), B = g, K = v, X = k, await u.prepareConnection(X, K);
|
|
396
397
|
} catch (l) {
|
|
397
|
-
|
|
398
|
-
|
|
398
|
+
ke(l, n, a, () => {
|
|
399
|
+
O = !1;
|
|
399
400
|
});
|
|
400
401
|
}
|
|
401
|
-
if (!
|
|
402
|
+
if (!X || !K || !B)
|
|
402
403
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
403
|
-
u.on(o.ConnectionStateChanged,
|
|
404
|
+
u.on(o.ConnectionStateChanged, f).on(o.ConnectionQualityChanged, R).on(o.ActiveSpeakersChanged, y).on(o.ParticipantConnected, $).on(o.ParticipantDisconnected, D).on(o.TrackSubscribed, _).on(o.TrackUnsubscribed, W).on(o.DataReceived, H).on(o.MediaDevicesError, q).on(o.EncryptionError, j).on(o.TrackSubscriptionFailed, J), (Ae = a.onConnectionStateChange) == null || Ae.call(a, S.New);
|
|
404
405
|
try {
|
|
405
|
-
await u.connect(
|
|
406
|
+
await u.connect(X, K), n("LiveKit room joined successfully"), L = setTimeout(() => {
|
|
407
|
+
var l;
|
|
408
|
+
n("Track subscription timeout - no track subscribed within 30 seconds after connect"), L = null, m.track("connectivity-error", {
|
|
409
|
+
error: "Track subscription timeout",
|
|
410
|
+
sessionId: B
|
|
411
|
+
}), (l = a.onError) == null || l.call(a, new Error("Track subscription timeout"), { sessionId: B }), pe();
|
|
412
|
+
}, T), O = !1;
|
|
406
413
|
} catch (l) {
|
|
407
|
-
|
|
408
|
-
|
|
414
|
+
ke(l, n, a, () => {
|
|
415
|
+
O = !1;
|
|
409
416
|
});
|
|
410
417
|
}
|
|
411
418
|
m.enrich({
|
|
412
419
|
"stream-type": x
|
|
413
420
|
});
|
|
414
|
-
function
|
|
415
|
-
var g, v,
|
|
421
|
+
function f(l) {
|
|
422
|
+
var g, v, k, b, V;
|
|
416
423
|
switch (n("Connection state changed:", l), l) {
|
|
417
424
|
case s.Connecting:
|
|
418
|
-
(g = a.onConnectionStateChange) == null || g.call(a,
|
|
425
|
+
(g = a.onConnectionStateChange) == null || g.call(a, S.Connecting);
|
|
419
426
|
break;
|
|
420
427
|
case s.Connected:
|
|
421
|
-
n("LiveKit room connected successfully"),
|
|
422
|
-
var
|
|
423
|
-
(
|
|
424
|
-
}) : (v = a.onConnectionStateChange) == null || v.call(a,
|
|
428
|
+
n("LiveKit room connected successfully"), E = !0, O ? queueMicrotask(() => {
|
|
429
|
+
var z;
|
|
430
|
+
(z = a.onConnectionStateChange) == null || z.call(a, S.Connected);
|
|
431
|
+
}) : (v = a.onConnectionStateChange) == null || v.call(a, S.Connected);
|
|
425
432
|
break;
|
|
426
433
|
case s.Disconnected:
|
|
427
|
-
n("LiveKit room disconnected"),
|
|
434
|
+
n("LiveKit room disconnected"), E = !1, (k = a.onConnectionStateChange) == null || k.call(a, S.Disconnected);
|
|
428
435
|
break;
|
|
429
436
|
case s.Reconnecting:
|
|
430
|
-
n("LiveKit room reconnecting..."), (b = a.onConnectionStateChange) == null || b.call(a,
|
|
437
|
+
n("LiveKit room reconnecting..."), (b = a.onConnectionStateChange) == null || b.call(a, S.Connecting);
|
|
431
438
|
break;
|
|
432
439
|
case s.SignalReconnecting:
|
|
433
|
-
n("LiveKit room signal reconnecting..."), (
|
|
440
|
+
n("LiveKit room signal reconnecting..."), (V = a.onConnectionStateChange) == null || V.call(a, S.Connecting);
|
|
434
441
|
break;
|
|
435
442
|
}
|
|
436
443
|
}
|
|
437
|
-
function
|
|
444
|
+
function R(l, g) {
|
|
438
445
|
var v;
|
|
439
|
-
n("Connection quality:", l), g != null && g.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a,
|
|
446
|
+
n("Connection quality:", l), g != null && g.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a, Rt[l]));
|
|
440
447
|
}
|
|
441
|
-
function
|
|
442
|
-
var v,
|
|
443
|
-
n("Active speakers changed:", l), l[0] ? (v = a.onAgentActivityStateChange) == null || v.call(a,
|
|
448
|
+
function y(l) {
|
|
449
|
+
var v, k;
|
|
450
|
+
n("Active speakers changed:", l), l[0] ? (v = a.onAgentActivityStateChange) == null || v.call(a, ae.Talking) : (k = a.onAgentActivityStateChange) == null || k.call(a, ae.Idle);
|
|
444
451
|
}
|
|
445
|
-
function
|
|
452
|
+
function $(l) {
|
|
446
453
|
n("Participant connected:", l.identity);
|
|
447
454
|
}
|
|
448
|
-
function
|
|
449
|
-
n("Participant disconnected:", l.identity),
|
|
455
|
+
function D(l) {
|
|
456
|
+
n("Participant disconnected:", l.identity), pe();
|
|
450
457
|
}
|
|
451
|
-
function
|
|
452
|
-
var b,
|
|
453
|
-
n(`Track subscribed: ${l.kind} from ${v.identity}`);
|
|
454
|
-
const
|
|
455
|
-
if (!
|
|
458
|
+
function _(l, g, v) {
|
|
459
|
+
var b, V, z;
|
|
460
|
+
n(`Track subscribed: ${l.kind} from ${v.identity}`), L && (clearTimeout(L), L = null, n("Track subscription timeout cleared"));
|
|
461
|
+
const k = l.mediaStreamTrack;
|
|
462
|
+
if (!k) {
|
|
456
463
|
n(`No mediaStreamTrack available for ${l.kind}`);
|
|
457
464
|
return;
|
|
458
465
|
}
|
|
459
|
-
|
|
466
|
+
I ? (I.addTrack(k), n(`Added ${l.kind} track to shared MediaStream`)) : (I = new MediaStream([k]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((b = a.onStreamReady) == null || b.call(a), (V = a.onSrcObjectReady) == null || V.call(a, I), (z = a.onVideoStateChange) == null || z.call(a, C.Start));
|
|
460
467
|
}
|
|
461
|
-
function
|
|
462
|
-
var
|
|
463
|
-
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((
|
|
468
|
+
function W(l, g, v) {
|
|
469
|
+
var k;
|
|
470
|
+
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((k = a.onVideoStateChange) == null || k.call(a, C.Stop));
|
|
464
471
|
}
|
|
465
|
-
function
|
|
466
|
-
var
|
|
472
|
+
function H(l, g, v, k) {
|
|
473
|
+
var V, z, de;
|
|
467
474
|
const b = new TextDecoder().decode(l);
|
|
468
475
|
n("Data received:", b);
|
|
469
476
|
try {
|
|
470
|
-
const
|
|
471
|
-
if (me ===
|
|
477
|
+
const ie = JSON.parse(b), me = k || ie.subject;
|
|
478
|
+
if (me === N.ChatAnswer) {
|
|
472
479
|
const oe = Y.Answer;
|
|
473
|
-
(
|
|
480
|
+
(V = a.onMessage) == null || V.call(a, oe, {
|
|
474
481
|
event: oe,
|
|
475
|
-
...
|
|
482
|
+
...ie
|
|
476
483
|
});
|
|
477
|
-
} else if ([
|
|
478
|
-
const oe = (
|
|
479
|
-
(
|
|
480
|
-
[oe]:
|
|
484
|
+
} else if ([N.StreamVideoCreated, N.StreamVideoDone].includes(me)) {
|
|
485
|
+
const oe = (ie == null ? void 0 : ie.role) || (g == null ? void 0 : g.identity) || "datachannel";
|
|
486
|
+
(z = a.onMessage) == null || z.call(a, me, {
|
|
487
|
+
[oe]: ie
|
|
481
488
|
});
|
|
482
|
-
} else if (me ===
|
|
489
|
+
} else if (me === N.ChatAudioTranscribed) {
|
|
483
490
|
const oe = Y.Transcribe;
|
|
484
491
|
(de = a.onMessage) == null || de.call(a, oe, {
|
|
485
492
|
event: oe,
|
|
486
|
-
...
|
|
493
|
+
...ie
|
|
487
494
|
});
|
|
488
495
|
}
|
|
489
|
-
} catch (
|
|
490
|
-
n("Failed to parse data channel message:",
|
|
496
|
+
} catch (ie) {
|
|
497
|
+
n("Failed to parse data channel message:", ie);
|
|
491
498
|
}
|
|
492
499
|
}
|
|
493
|
-
function
|
|
500
|
+
function q(l) {
|
|
494
501
|
var g;
|
|
495
|
-
n("Media devices error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId:
|
|
502
|
+
n("Media devices error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
|
|
496
503
|
}
|
|
497
|
-
function
|
|
504
|
+
function j(l) {
|
|
498
505
|
var g;
|
|
499
|
-
n("Encryption error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId:
|
|
506
|
+
n("Encryption error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
|
|
500
507
|
}
|
|
501
|
-
function
|
|
508
|
+
function J(l, g, v) {
|
|
502
509
|
n("Track subscription failed:", { trackSid: l, participant: g, reason: v });
|
|
503
510
|
}
|
|
504
|
-
async function
|
|
511
|
+
async function G(l) {
|
|
505
512
|
if (!u) return null;
|
|
506
|
-
const { Track: g } = await
|
|
513
|
+
const { Track: g } = await ye(), v = u.localParticipant.audioTrackPublications;
|
|
507
514
|
if (v) {
|
|
508
|
-
for (const [
|
|
515
|
+
for (const [k, b] of v)
|
|
509
516
|
if (b.source === g.Source.Microphone && b.track) {
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
517
|
+
const z = b.track.mediaStreamTrack;
|
|
518
|
+
if (z === l || z && z.id === l.id)
|
|
512
519
|
return b;
|
|
513
520
|
}
|
|
514
521
|
}
|
|
515
522
|
return null;
|
|
516
523
|
}
|
|
517
|
-
function
|
|
524
|
+
function M(l) {
|
|
518
525
|
if (!A || !A.track)
|
|
519
526
|
return !1;
|
|
520
527
|
const g = A.track.mediaStreamTrack;
|
|
521
528
|
return g !== l && (g == null ? void 0 : g.id) !== l.id;
|
|
522
529
|
}
|
|
523
|
-
async function
|
|
524
|
-
var
|
|
525
|
-
if (!
|
|
530
|
+
async function P(l) {
|
|
531
|
+
var V, z;
|
|
532
|
+
if (!E || !u)
|
|
526
533
|
throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
|
|
527
534
|
const g = l.getAudioTracks();
|
|
528
535
|
if (g.length === 0) {
|
|
529
536
|
n("No audio track found in the provided MediaStream");
|
|
530
537
|
return;
|
|
531
538
|
}
|
|
532
|
-
const v = g[0], { Track:
|
|
539
|
+
const v = g[0], { Track: k } = await ye(), b = await G(v);
|
|
533
540
|
if (b) {
|
|
534
541
|
n("Microphone track is already published, skipping", {
|
|
535
542
|
trackId: v.id,
|
|
536
|
-
publishedTrackId: (
|
|
543
|
+
publishedTrackId: (z = (V = b.track) == null ? void 0 : V.mediaStreamTrack) == null ? void 0 : z.id
|
|
537
544
|
}), A = b;
|
|
538
545
|
return;
|
|
539
546
|
}
|
|
540
|
-
|
|
547
|
+
M(v) && (n("Unpublishing existing microphone track before publishing new one"), await Z()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
|
|
541
548
|
try {
|
|
542
549
|
A = await u.localParticipant.publishTrack(v, {
|
|
543
|
-
source:
|
|
550
|
+
source: k.Source.Microphone
|
|
544
551
|
}), n("Microphone track published successfully", { trackSid: A.trackSid });
|
|
545
552
|
} catch (de) {
|
|
546
553
|
throw n("Failed to publish microphone track:", de), de;
|
|
547
554
|
}
|
|
548
555
|
}
|
|
549
|
-
async function
|
|
556
|
+
async function Z() {
|
|
550
557
|
if (!(!A || !A.track))
|
|
551
558
|
try {
|
|
552
559
|
u && (await u.localParticipant.unpublishTrack(A.track), n("Microphone track unpublished"));
|
|
@@ -556,98 +563,98 @@ async function kt(e, t, i) {
|
|
|
556
563
|
A = null;
|
|
557
564
|
}
|
|
558
565
|
}
|
|
559
|
-
function
|
|
560
|
-
|
|
566
|
+
function h() {
|
|
567
|
+
I && (I.getTracks().forEach((l) => l.stop()), I = null);
|
|
561
568
|
}
|
|
562
|
-
async function
|
|
563
|
-
var v,
|
|
564
|
-
if (!
|
|
569
|
+
async function w(l, g) {
|
|
570
|
+
var v, k;
|
|
571
|
+
if (!E || !u) {
|
|
565
572
|
n("Room is not connected for sending messages"), (v = a.onError) == null || v.call(a, new Error(le), {
|
|
566
|
-
sessionId:
|
|
573
|
+
sessionId: B
|
|
567
574
|
});
|
|
568
575
|
return;
|
|
569
576
|
}
|
|
570
577
|
try {
|
|
571
578
|
await u.localParticipant.sendText(l, { topic: g }), n("Message sent successfully:", l);
|
|
572
579
|
} catch (b) {
|
|
573
|
-
n("Failed to send message:", b), (
|
|
580
|
+
n("Failed to send message:", b), (k = a.onError) == null || k.call(a, new Error(le), { sessionId: B });
|
|
574
581
|
}
|
|
575
582
|
}
|
|
576
|
-
async function
|
|
583
|
+
async function F(l) {
|
|
577
584
|
var g;
|
|
578
585
|
try {
|
|
579
|
-
const
|
|
580
|
-
return
|
|
586
|
+
const k = JSON.parse(l).topic;
|
|
587
|
+
return w("", k);
|
|
581
588
|
} catch (v) {
|
|
582
|
-
n("Failed to send data channel message:", v), (g = a.onError) == null || g.call(a, new Error(le), { sessionId:
|
|
589
|
+
n("Failed to send data channel message:", v), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
|
|
583
590
|
}
|
|
584
591
|
}
|
|
585
|
-
function
|
|
586
|
-
return
|
|
592
|
+
function Q(l) {
|
|
593
|
+
return w(
|
|
587
594
|
l,
|
|
588
595
|
"lk.chat"
|
|
589
596
|
/* Chat */
|
|
590
597
|
);
|
|
591
598
|
}
|
|
592
|
-
async function
|
|
599
|
+
async function pe() {
|
|
593
600
|
var l, g;
|
|
594
|
-
u && (await
|
|
601
|
+
L && (clearTimeout(L), L = null), u && (await Z(), await u.disconnect()), h(), E = !1, (l = a.onConnectionStateChange) == null || l.call(a, S.Disconnected), (g = a.onAgentActivityStateChange) == null || g.call(a, ae.Idle);
|
|
595
602
|
}
|
|
596
603
|
return {
|
|
597
604
|
speak(l) {
|
|
598
605
|
const g = typeof l == "string" ? l : JSON.stringify(l);
|
|
599
|
-
return
|
|
606
|
+
return w(
|
|
600
607
|
g,
|
|
601
608
|
"did.speak"
|
|
602
609
|
/* Speak */
|
|
603
610
|
);
|
|
604
611
|
},
|
|
605
|
-
disconnect:
|
|
612
|
+
disconnect: pe,
|
|
606
613
|
async reconnect() {
|
|
607
614
|
var l, g, v;
|
|
608
615
|
if ((u == null ? void 0 : u.state) === s.Connected) {
|
|
609
616
|
n("Room is already connected");
|
|
610
617
|
return;
|
|
611
618
|
}
|
|
612
|
-
if (!u || !
|
|
619
|
+
if (!u || !X || !K)
|
|
613
620
|
throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
614
|
-
n("Reconnecting to LiveKit room, state:", u.state), (l = a.onConnectionStateChange) == null || l.call(a,
|
|
621
|
+
n("Reconnecting to LiveKit room, state:", u.state), (l = a.onConnectionStateChange) == null || l.call(a, S.Connecting);
|
|
615
622
|
try {
|
|
616
|
-
if (await u.connect(
|
|
623
|
+
if (await u.connect(X, K), n("Room reconnected"), E = !0, u.remoteParticipants.size === 0) {
|
|
617
624
|
if (n("Waiting for agent to join..."), !await new Promise((b) => {
|
|
618
|
-
const
|
|
619
|
-
u == null || u.off(o.ParticipantConnected,
|
|
620
|
-
}, 5e3),
|
|
621
|
-
clearTimeout(
|
|
625
|
+
const V = setTimeout(() => {
|
|
626
|
+
u == null || u.off(o.ParticipantConnected, z), b(!1);
|
|
627
|
+
}, 5e3), z = () => {
|
|
628
|
+
clearTimeout(V), u == null || u.off(o.ParticipantConnected, z), b(!0);
|
|
622
629
|
};
|
|
623
|
-
u == null || u.on(o.ParticipantConnected,
|
|
630
|
+
u == null || u.on(o.ParticipantConnected, z);
|
|
624
631
|
}))
|
|
625
632
|
throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
|
|
626
633
|
n("Agent joined");
|
|
627
634
|
}
|
|
628
|
-
(g = a.onConnectionStateChange) == null || g.call(a,
|
|
629
|
-
} catch (
|
|
630
|
-
throw n("Failed to reconnect:",
|
|
635
|
+
(g = a.onConnectionStateChange) == null || g.call(a, S.Connected);
|
|
636
|
+
} catch (k) {
|
|
637
|
+
throw n("Failed to reconnect:", k), (v = a.onConnectionStateChange) == null || v.call(a, S.Fail), k;
|
|
631
638
|
}
|
|
632
639
|
},
|
|
633
|
-
sendDataChannelMessage:
|
|
634
|
-
sendTextMessage:
|
|
635
|
-
publishMicrophoneStream:
|
|
636
|
-
unpublishMicrophoneStream:
|
|
637
|
-
sessionId:
|
|
638
|
-
streamId:
|
|
640
|
+
sendDataChannelMessage: F,
|
|
641
|
+
sendTextMessage: Q,
|
|
642
|
+
publishMicrophoneStream: P,
|
|
643
|
+
unpublishMicrophoneStream: Z,
|
|
644
|
+
sessionId: B,
|
|
645
|
+
streamId: B,
|
|
639
646
|
streamType: x,
|
|
640
647
|
interruptAvailable: !0,
|
|
641
648
|
triggersAvailable: !1
|
|
642
649
|
};
|
|
643
650
|
}
|
|
644
|
-
const
|
|
651
|
+
const Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
645
652
|
__proto__: null,
|
|
646
|
-
DataChannelTopic:
|
|
647
|
-
createLiveKitStreamingManager:
|
|
648
|
-
handleInitError:
|
|
653
|
+
DataChannelTopic: Te,
|
|
654
|
+
createLiveKitStreamingManager: Dt,
|
|
655
|
+
handleInitError: ke
|
|
649
656
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
650
|
-
function
|
|
657
|
+
function Et(e, t, i) {
|
|
651
658
|
if (!e)
|
|
652
659
|
throw new Error("Please connect to the agent first");
|
|
653
660
|
if (!e.interruptAvailable)
|
|
@@ -657,23 +664,23 @@ function Dt(e, t, i) {
|
|
|
657
664
|
if (!i)
|
|
658
665
|
throw new Error("No active video to interrupt");
|
|
659
666
|
}
|
|
660
|
-
async function
|
|
667
|
+
async function It(e, t) {
|
|
661
668
|
const i = {
|
|
662
|
-
type:
|
|
669
|
+
type: N.StreamInterrupt,
|
|
663
670
|
videoId: t,
|
|
664
671
|
timestamp: Date.now()
|
|
665
672
|
};
|
|
666
673
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
667
674
|
}
|
|
668
|
-
async function
|
|
675
|
+
async function Tt(e) {
|
|
669
676
|
const t = {
|
|
670
|
-
topic:
|
|
677
|
+
topic: Te.Interrupt
|
|
671
678
|
};
|
|
672
679
|
e.sendDataChannelMessage(JSON.stringify(t));
|
|
673
680
|
}
|
|
674
|
-
function
|
|
681
|
+
function _t(e) {
|
|
675
682
|
return new Promise((t, i) => {
|
|
676
|
-
const { callbacks: n, host: c, auth: o, externalId: s } = e, { onMessage: a = null, onOpen: r = null, onClose: d = null, onError: m = null } = n || {}, p = new WebSocket(`${c}?authorization=${encodeURIComponent(
|
|
683
|
+
const { callbacks: n, host: c, auth: o, externalId: s } = e, { onMessage: a = null, onOpen: r = null, onClose: d = null, onError: m = null } = n || {}, p = new WebSocket(`${c}?authorization=${encodeURIComponent(Ke(o, s))}`);
|
|
677
684
|
p.onmessage = a, p.onclose = d, p.onerror = (u) => {
|
|
678
685
|
console.error(u), m == null || m("Websocket failed to connect", u), i(u);
|
|
679
686
|
}, p.onopen = (u) => {
|
|
@@ -681,28 +688,28 @@ function It(e) {
|
|
|
681
688
|
};
|
|
682
689
|
});
|
|
683
690
|
}
|
|
684
|
-
async function
|
|
691
|
+
async function At(e) {
|
|
685
692
|
const { retries: t = 1 } = e;
|
|
686
693
|
let i = null;
|
|
687
694
|
for (let n = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; n++)
|
|
688
695
|
try {
|
|
689
|
-
i = await
|
|
696
|
+
i = await _t(e);
|
|
690
697
|
} catch (c) {
|
|
691
698
|
if (n === t)
|
|
692
699
|
throw c;
|
|
693
|
-
await
|
|
700
|
+
await Fe(n * 500);
|
|
694
701
|
}
|
|
695
702
|
return i;
|
|
696
703
|
}
|
|
697
|
-
async function
|
|
698
|
-
const c = i != null && i.onMessage ? [i.onMessage] : [], o = await
|
|
704
|
+
async function Pt(e, t, i, n) {
|
|
705
|
+
const c = i != null && i.onMessage ? [i.onMessage] : [], o = await At({
|
|
699
706
|
auth: e,
|
|
700
707
|
host: t,
|
|
701
708
|
externalId: n,
|
|
702
709
|
callbacks: {
|
|
703
710
|
onError: (s) => {
|
|
704
711
|
var a;
|
|
705
|
-
return (a = i.onError) == null ? void 0 : a.call(i, new
|
|
712
|
+
return (a = i.onError) == null ? void 0 : a.call(i, new Qe(s));
|
|
706
713
|
},
|
|
707
714
|
onMessage(s) {
|
|
708
715
|
const a = JSON.parse(s.data);
|
|
@@ -716,7 +723,7 @@ async function _t(e, t, i, n) {
|
|
|
716
723
|
subscribeToEvents: (s) => c.push(s)
|
|
717
724
|
};
|
|
718
725
|
}
|
|
719
|
-
function
|
|
726
|
+
function bt(e) {
|
|
720
727
|
if (e.answer !== void 0)
|
|
721
728
|
return e.answer;
|
|
722
729
|
let t = 0, i = "";
|
|
@@ -724,7 +731,7 @@ function At(e) {
|
|
|
724
731
|
i += e[t++];
|
|
725
732
|
return i;
|
|
726
733
|
}
|
|
727
|
-
function
|
|
734
|
+
function jt(e, t, i) {
|
|
728
735
|
if (!e.content)
|
|
729
736
|
return;
|
|
730
737
|
const n = {
|
|
@@ -736,9 +743,9 @@ function Pt(e, t, i) {
|
|
|
736
743
|
};
|
|
737
744
|
t.messages.push(n), i == null || i([...t.messages], "user");
|
|
738
745
|
}
|
|
739
|
-
function
|
|
746
|
+
function Lt(e, t, i, n, c) {
|
|
740
747
|
if (e === Y.Transcribe && t.content) {
|
|
741
|
-
|
|
748
|
+
jt(t, n, c);
|
|
742
749
|
return;
|
|
743
750
|
}
|
|
744
751
|
if (!(e === Y.Partial || e === Y.Answer))
|
|
@@ -758,36 +765,36 @@ function bt(e, t, i, n, c) {
|
|
|
758
765
|
return;
|
|
759
766
|
const { content: a, sequence: r } = t;
|
|
760
767
|
e === Y.Partial ? i[r] = a : i.answer = a;
|
|
761
|
-
const d =
|
|
768
|
+
const d = bt(i);
|
|
762
769
|
(s.content !== d || e === Y.Answer) && (s.content = d, c == null || c([...n.messages], e));
|
|
763
770
|
}
|
|
764
|
-
function
|
|
771
|
+
function $t(e, t, i, n, c) {
|
|
765
772
|
let o = {};
|
|
766
773
|
return {
|
|
767
774
|
clearQueue: () => o = {},
|
|
768
775
|
onMessage: (s, a) => {
|
|
769
776
|
var r, d;
|
|
770
777
|
if ("content" in a) {
|
|
771
|
-
const m = s ===
|
|
772
|
-
|
|
778
|
+
const m = s === N.ChatAnswer ? Y.Answer : s === N.ChatAudioTranscribed ? Y.Transcribe : s;
|
|
779
|
+
Lt(m, a, o, t, i.callbacks.onNewMessage), m === Y.Answer && e.track("agent-message-received", {
|
|
773
780
|
messages: t.messages.length,
|
|
774
781
|
mode: t.chatMode
|
|
775
782
|
});
|
|
776
783
|
} else {
|
|
777
|
-
const m =
|
|
784
|
+
const m = N, p = [m.StreamVideoDone, m.StreamVideoError, m.StreamVideoRejected], u = [m.StreamFailed, m.StreamVideoError, m.StreamVideoRejected], E = wt(a, n, { mode: t.chatMode });
|
|
778
785
|
if (s = s, s === m.StreamVideoCreated)
|
|
779
|
-
e.linkTrack("agent-video",
|
|
786
|
+
e.linkTrack("agent-video", E, m.StreamVideoCreated, ["start"]);
|
|
780
787
|
else if (p.includes(s)) {
|
|
781
788
|
const x = s.split("/")[1];
|
|
782
|
-
u.includes(s) ? e.track("agent-video", { ...
|
|
789
|
+
u.includes(s) ? e.track("agent-video", { ...E, event: x }) : e.linkTrack("agent-video", { ...E, event: x }, s, ["done"]);
|
|
783
790
|
}
|
|
784
791
|
u.includes(s) && ((d = (r = i.callbacks).onError) == null || d.call(r, new Error(`Stream failed with event ${s}`), { data: a })), a.event === m.StreamDone && c();
|
|
785
792
|
}
|
|
786
793
|
}
|
|
787
794
|
};
|
|
788
795
|
}
|
|
789
|
-
function
|
|
790
|
-
const c =
|
|
796
|
+
function xt(e, t, i, n) {
|
|
797
|
+
const c = Ee(e, `${t}/agents/${i}`, n);
|
|
791
798
|
return {
|
|
792
799
|
createStream(o, s) {
|
|
793
800
|
return c.post("/streams", o, { signal: s });
|
|
@@ -823,7 +830,7 @@ function Lt(e, t, i, n) {
|
|
|
823
830
|
}
|
|
824
831
|
};
|
|
825
832
|
}
|
|
826
|
-
function
|
|
833
|
+
function Bt(e, t, i) {
|
|
827
834
|
const n = (t.timestamp - e.timestamp) / 1e3;
|
|
828
835
|
return {
|
|
829
836
|
duration: n,
|
|
@@ -843,7 +850,7 @@ function $t(e, t, i) {
|
|
|
843
850
|
lowFpsCount: i
|
|
844
851
|
};
|
|
845
852
|
}
|
|
846
|
-
function
|
|
853
|
+
function Ft(e) {
|
|
847
854
|
return e.filter(
|
|
848
855
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
849
856
|
).map((t) => {
|
|
@@ -854,7 +861,7 @@ function xt(e) {
|
|
|
854
861
|
};
|
|
855
862
|
});
|
|
856
863
|
}
|
|
857
|
-
function
|
|
864
|
+
function zt(e) {
|
|
858
865
|
let t = "", i = 0;
|
|
859
866
|
for (const n of e.values()) {
|
|
860
867
|
if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair") {
|
|
@@ -884,7 +891,7 @@ function Ft(e) {
|
|
|
884
891
|
}
|
|
885
892
|
return {};
|
|
886
893
|
}
|
|
887
|
-
function
|
|
894
|
+
function Nt(e, t, i) {
|
|
888
895
|
const n = e.map((r, d) => d === 0 ? i ? {
|
|
889
896
|
timestamp: r.timestamp,
|
|
890
897
|
duration: 0,
|
|
@@ -936,24 +943,24 @@ function Bt(e, t, i) {
|
|
|
936
943
|
framesPerSecond: r.framesPerSecond,
|
|
937
944
|
freezeCount: r.freezeCount - e[d - 1].freezeCount,
|
|
938
945
|
freezeDuration: r.freezeDuration - e[d - 1].freezeDuration
|
|
939
|
-
}), c =
|
|
946
|
+
}), c = Ft(n), o = c.reduce((r, d) => r + (d.causes.includes("low fps") ? 1 : 0), 0), s = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), a = n.filter((r) => !!r.rtt).map((r) => r.rtt);
|
|
940
947
|
return {
|
|
941
948
|
webRTCStats: {
|
|
942
949
|
anomalies: c,
|
|
943
950
|
minRtt: Math.min(...a),
|
|
944
|
-
avgRtt:
|
|
951
|
+
avgRtt: Pe(a),
|
|
945
952
|
maxRtt: Math.max(...a),
|
|
946
|
-
aggregateReport:
|
|
953
|
+
aggregateReport: Bt(e[0], e[e.length - 1], o),
|
|
947
954
|
minJitterDelayInInterval: Math.min(...s),
|
|
948
955
|
maxJitterDelayInInterval: Math.max(...s),
|
|
949
|
-
avgJitterDelayInInterval:
|
|
956
|
+
avgJitterDelayInInterval: Pe(s)
|
|
950
957
|
},
|
|
951
958
|
codec: e[0].codec,
|
|
952
959
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
953
960
|
};
|
|
954
961
|
}
|
|
955
|
-
const
|
|
956
|
-
function
|
|
962
|
+
const Re = 100, Kt = Math.max(Math.ceil(400 / Re), 1), Jt = 0.25, Ut = 0.28;
|
|
963
|
+
function Wt() {
|
|
957
964
|
let e = 0, t, i, n = 0;
|
|
958
965
|
return (c) => {
|
|
959
966
|
for (const o of c.values())
|
|
@@ -970,41 +977,41 @@ function Jt() {
|
|
|
970
977
|
return { isReceiving: !1, avgJitterDelayInInterval: n };
|
|
971
978
|
};
|
|
972
979
|
}
|
|
973
|
-
function
|
|
980
|
+
function Ot(e, t, i, n, c) {
|
|
974
981
|
let o = [], s, a = 0, r = !1, d = ee.Unknown, m = ee.Unknown, p = 0, u = 0;
|
|
975
|
-
const
|
|
982
|
+
const E = Wt();
|
|
976
983
|
return setInterval(async () => {
|
|
977
|
-
const x = await e.getStats(), { isReceiving:
|
|
978
|
-
if (
|
|
979
|
-
a = 0, p = A - u, m =
|
|
980
|
-
else if (r && (a++, a >=
|
|
981
|
-
const
|
|
982
|
-
n == null || n(
|
|
984
|
+
const x = await e.getStats(), { isReceiving: O, avgJitterDelayInInterval: I, freezeCount: A } = E(x), L = zt(x);
|
|
985
|
+
if (O)
|
|
986
|
+
a = 0, p = A - u, m = I < Jt ? ee.Strong : I > Ut && p > 1 ? ee.Weak : d, m !== d && (c == null || c(m), d = m, u += p, p = 0), r || (n == null || n(C.Start), s = o[o.length - 1], o = [], r = !0), o.push(L);
|
|
987
|
+
else if (r && (a++, a >= Kt)) {
|
|
988
|
+
const T = Nt(o, Re, s);
|
|
989
|
+
n == null || n(C.Stop, T), t() || i(), u = A, r = !1;
|
|
983
990
|
}
|
|
984
|
-
},
|
|
991
|
+
}, Re);
|
|
985
992
|
}
|
|
986
|
-
const
|
|
987
|
-
function
|
|
993
|
+
const Vt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
994
|
+
function Le(e) {
|
|
988
995
|
switch (e) {
|
|
989
996
|
case "connected":
|
|
990
|
-
return
|
|
997
|
+
return S.Connected;
|
|
991
998
|
case "checking":
|
|
992
|
-
return
|
|
999
|
+
return S.Connecting;
|
|
993
1000
|
case "failed":
|
|
994
|
-
return
|
|
1001
|
+
return S.Fail;
|
|
995
1002
|
case "new":
|
|
996
|
-
return
|
|
1003
|
+
return S.New;
|
|
997
1004
|
case "closed":
|
|
998
|
-
return
|
|
1005
|
+
return S.Closed;
|
|
999
1006
|
case "disconnected":
|
|
1000
|
-
return
|
|
1007
|
+
return S.Disconnected;
|
|
1001
1008
|
case "completed":
|
|
1002
|
-
return
|
|
1009
|
+
return S.Completed;
|
|
1003
1010
|
default:
|
|
1004
|
-
return
|
|
1011
|
+
return S.New;
|
|
1005
1012
|
}
|
|
1006
1013
|
}
|
|
1007
|
-
const
|
|
1014
|
+
const Ht = (e) => (t) => {
|
|
1008
1015
|
const [i, n = ""] = t.split(/:(.+)/);
|
|
1009
1016
|
try {
|
|
1010
1017
|
const c = JSON.parse(n);
|
|
@@ -1013,24 +1020,24 @@ const Vt = (e) => (t) => {
|
|
|
1013
1020
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: n, error: c }), { subject: i, data: n };
|
|
1014
1021
|
}
|
|
1015
1022
|
};
|
|
1016
|
-
function
|
|
1023
|
+
function qt({
|
|
1017
1024
|
statsSignal: e,
|
|
1018
1025
|
dataChannelSignal: t,
|
|
1019
1026
|
onVideoStateChange: i,
|
|
1020
1027
|
report: n
|
|
1021
1028
|
}) {
|
|
1022
|
-
e ===
|
|
1029
|
+
e === C.Start && t === C.Start ? i == null || i(C.Start) : e === C.Stop && t === C.Stop && (i == null || i(C.Stop, n));
|
|
1023
1030
|
}
|
|
1024
|
-
function
|
|
1031
|
+
function Qt({
|
|
1025
1032
|
statsSignal: e,
|
|
1026
1033
|
dataChannelSignal: t,
|
|
1027
1034
|
onVideoStateChange: i,
|
|
1028
1035
|
onAgentActivityStateChange: n,
|
|
1029
1036
|
report: c
|
|
1030
1037
|
}) {
|
|
1031
|
-
e ===
|
|
1038
|
+
e === C.Start ? i == null || i(C.Start) : e === C.Stop && (i == null || i(C.Stop, c)), t === C.Start ? n == null || n(ae.Talking) : t === C.Stop && (n == null || n(ae.Idle));
|
|
1032
1039
|
}
|
|
1033
|
-
function
|
|
1040
|
+
function $e({
|
|
1034
1041
|
statsSignal: e,
|
|
1035
1042
|
dataChannelSignal: t,
|
|
1036
1043
|
onVideoStateChange: i,
|
|
@@ -1038,7 +1045,7 @@ function je({
|
|
|
1038
1045
|
streamType: c,
|
|
1039
1046
|
report: o
|
|
1040
1047
|
}) {
|
|
1041
|
-
c === ne.Legacy ?
|
|
1048
|
+
c === ne.Legacy ? qt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o }) : c === ne.Fluent && Qt({
|
|
1042
1049
|
statsSignal: e,
|
|
1043
1050
|
dataChannelSignal: t,
|
|
1044
1051
|
onVideoStateChange: i,
|
|
@@ -1046,187 +1053,187 @@ function je({
|
|
|
1046
1053
|
report: o
|
|
1047
1054
|
});
|
|
1048
1055
|
}
|
|
1049
|
-
async function
|
|
1056
|
+
async function Xt(e, t, { debug: i = !1, callbacks: n, auth: c, baseURL: o = fe, analytics: s }, a) {
|
|
1050
1057
|
var Z;
|
|
1051
|
-
const r =
|
|
1052
|
-
let m = !1, p = !1, u =
|
|
1053
|
-
const { startConnection: x, sendStreamRequest:
|
|
1058
|
+
const r = We(i, "WebRTCStreamingManager"), d = Ht(r);
|
|
1059
|
+
let m = !1, p = !1, u = C.Stop, E = C.Stop;
|
|
1060
|
+
const { startConnection: x, sendStreamRequest: O, close: I, createStream: A, addIceCandidate: L } = xt(
|
|
1054
1061
|
c,
|
|
1055
1062
|
o,
|
|
1056
1063
|
e,
|
|
1057
1064
|
n.onError
|
|
1058
1065
|
), {
|
|
1059
|
-
id:
|
|
1060
|
-
offer:
|
|
1061
|
-
ice_servers:
|
|
1062
|
-
session_id:
|
|
1063
|
-
fluent:
|
|
1066
|
+
id: T,
|
|
1067
|
+
offer: re,
|
|
1068
|
+
ice_servers: B,
|
|
1069
|
+
session_id: K,
|
|
1070
|
+
fluent: X,
|
|
1064
1071
|
interrupt_enabled: f,
|
|
1065
|
-
triggers_enabled:
|
|
1072
|
+
triggers_enabled: R
|
|
1066
1073
|
} = await A(t, a);
|
|
1067
|
-
(Z = n.onStreamCreated) == null || Z.call(n, { stream_id:
|
|
1068
|
-
const
|
|
1069
|
-
if (!
|
|
1074
|
+
(Z = n.onStreamCreated) == null || Z.call(n, { stream_id: T, session_id: K, agent_id: e });
|
|
1075
|
+
const y = new Vt({ iceServers: B }), $ = y.createDataChannel("JanusDataChannel");
|
|
1076
|
+
if (!K)
|
|
1070
1077
|
throw new Error("Could not create session_id");
|
|
1071
|
-
const
|
|
1078
|
+
const D = X ? ne.Fluent : ne.Legacy;
|
|
1072
1079
|
s.enrich({
|
|
1073
|
-
"stream-type":
|
|
1080
|
+
"stream-type": D
|
|
1074
1081
|
});
|
|
1075
|
-
const _ = t.stream_warmup && !
|
|
1082
|
+
const _ = t.stream_warmup && !X, W = () => m, H = () => {
|
|
1076
1083
|
var h;
|
|
1077
|
-
m = !0, p && ((h = n.onConnectionStateChange) == null || h.call(n,
|
|
1078
|
-
},
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
(h,
|
|
1083
|
-
statsSignal:
|
|
1084
|
-
dataChannelSignal:
|
|
1084
|
+
m = !0, p && ((h = n.onConnectionStateChange) == null || h.call(n, S.Connected));
|
|
1085
|
+
}, q = Ot(
|
|
1086
|
+
y,
|
|
1087
|
+
W,
|
|
1088
|
+
H,
|
|
1089
|
+
(h, w) => $e({
|
|
1090
|
+
statsSignal: E = h,
|
|
1091
|
+
dataChannelSignal: D === ne.Legacy ? u : void 0,
|
|
1085
1092
|
onVideoStateChange: n.onVideoStateChange,
|
|
1086
1093
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1087
|
-
report:
|
|
1088
|
-
streamType:
|
|
1094
|
+
report: w,
|
|
1095
|
+
streamType: D
|
|
1089
1096
|
}),
|
|
1090
1097
|
(h) => {
|
|
1091
|
-
var
|
|
1092
|
-
return (
|
|
1098
|
+
var w;
|
|
1099
|
+
return (w = n.onConnectivityStateChange) == null ? void 0 : w.call(n, h);
|
|
1093
1100
|
}
|
|
1094
1101
|
);
|
|
1095
|
-
|
|
1096
|
-
var
|
|
1102
|
+
y.onicecandidate = (h) => {
|
|
1103
|
+
var w;
|
|
1097
1104
|
r("peerConnection.onicecandidate", h);
|
|
1098
1105
|
try {
|
|
1099
|
-
h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ?
|
|
1100
|
-
|
|
1106
|
+
h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? L(
|
|
1107
|
+
T,
|
|
1101
1108
|
{
|
|
1102
1109
|
candidate: h.candidate.candidate,
|
|
1103
1110
|
sdpMid: h.candidate.sdpMid,
|
|
1104
1111
|
sdpMLineIndex: h.candidate.sdpMLineIndex
|
|
1105
1112
|
},
|
|
1106
|
-
|
|
1113
|
+
K,
|
|
1107
1114
|
a
|
|
1108
|
-
) :
|
|
1109
|
-
} catch (
|
|
1110
|
-
(
|
|
1115
|
+
) : L(T, { candidate: null }, K, a);
|
|
1116
|
+
} catch (F) {
|
|
1117
|
+
(w = n.onError) == null || w.call(n, F, { streamId: T });
|
|
1111
1118
|
}
|
|
1112
|
-
},
|
|
1113
|
-
p = !0, (!_ || m) &&
|
|
1119
|
+
}, $.onopen = () => {
|
|
1120
|
+
p = !0, (!_ || m) && H();
|
|
1114
1121
|
};
|
|
1115
1122
|
const j = (h) => {
|
|
1116
|
-
var
|
|
1117
|
-
(
|
|
1123
|
+
var w;
|
|
1124
|
+
(w = n.onVideoIdChange) == null || w.call(n, h);
|
|
1118
1125
|
};
|
|
1119
|
-
function
|
|
1120
|
-
if (h ===
|
|
1121
|
-
const
|
|
1122
|
-
j(
|
|
1126
|
+
function J(h, w) {
|
|
1127
|
+
if (h === N.StreamStarted && typeof w == "object" && "metadata" in w) {
|
|
1128
|
+
const F = w.metadata;
|
|
1129
|
+
j(F.videoId);
|
|
1123
1130
|
}
|
|
1124
|
-
h ===
|
|
1125
|
-
statsSignal:
|
|
1131
|
+
h === N.StreamDone && j(null), u = h === N.StreamStarted ? C.Start : C.Stop, $e({
|
|
1132
|
+
statsSignal: D === ne.Legacy ? E : void 0,
|
|
1126
1133
|
dataChannelSignal: u,
|
|
1127
1134
|
onVideoStateChange: n.onVideoStateChange,
|
|
1128
1135
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1129
|
-
streamType:
|
|
1136
|
+
streamType: D
|
|
1130
1137
|
});
|
|
1131
1138
|
}
|
|
1132
|
-
function G(h,
|
|
1133
|
-
var
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1139
|
+
function G(h, w) {
|
|
1140
|
+
var Q;
|
|
1141
|
+
const F = typeof w == "string" ? w : w == null ? void 0 : w.metadata;
|
|
1142
|
+
F && s.enrich({ streamMetadata: F }), (Q = n.onStreamReady) == null || Q.call(n);
|
|
1136
1143
|
}
|
|
1137
|
-
const
|
|
1138
|
-
[
|
|
1139
|
-
[
|
|
1140
|
-
[
|
|
1144
|
+
const M = {
|
|
1145
|
+
[N.StreamStarted]: J,
|
|
1146
|
+
[N.StreamDone]: J,
|
|
1147
|
+
[N.StreamReady]: G
|
|
1141
1148
|
};
|
|
1142
|
-
|
|
1143
|
-
var
|
|
1144
|
-
const { subject:
|
|
1145
|
-
(
|
|
1146
|
-
},
|
|
1147
|
-
var
|
|
1148
|
-
r("peerConnection.oniceconnectionstatechange => " +
|
|
1149
|
-
const h =
|
|
1150
|
-
h !==
|
|
1151
|
-
},
|
|
1152
|
-
var
|
|
1153
|
-
r("peerConnection.ontrack", h), (
|
|
1154
|
-
}, await
|
|
1155
|
-
const P = await
|
|
1156
|
-
return r("create answer OK"), await
|
|
1149
|
+
$.onmessage = (h) => {
|
|
1150
|
+
var Q;
|
|
1151
|
+
const { subject: w, data: F } = d(h.data);
|
|
1152
|
+
(Q = M[w]) == null || Q.call(M, w, F);
|
|
1153
|
+
}, y.oniceconnectionstatechange = () => {
|
|
1154
|
+
var w;
|
|
1155
|
+
r("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
|
|
1156
|
+
const h = Le(y.iceConnectionState);
|
|
1157
|
+
h !== S.Connected && ((w = n.onConnectionStateChange) == null || w.call(n, h));
|
|
1158
|
+
}, y.ontrack = (h) => {
|
|
1159
|
+
var w;
|
|
1160
|
+
r("peerConnection.ontrack", h), (w = n.onSrcObjectReady) == null || w.call(n, h.streams[0]);
|
|
1161
|
+
}, await y.setRemoteDescription(re), r("set remote description OK");
|
|
1162
|
+
const P = await y.createAnswer();
|
|
1163
|
+
return r("create answer OK"), await y.setLocalDescription(P), r("set local description OK"), await x(T, P, K, a), r("start connection OK"), {
|
|
1157
1164
|
/**
|
|
1158
1165
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1159
1166
|
* @param payload
|
|
1160
1167
|
*/
|
|
1161
1168
|
speak(h) {
|
|
1162
|
-
return
|
|
1169
|
+
return O(T, K, h);
|
|
1163
1170
|
},
|
|
1164
1171
|
/**
|
|
1165
1172
|
* Method to close RTC connection
|
|
1166
1173
|
*/
|
|
1167
1174
|
async disconnect() {
|
|
1168
1175
|
var h;
|
|
1169
|
-
if (
|
|
1170
|
-
const
|
|
1171
|
-
if (
|
|
1172
|
-
if (
|
|
1173
|
-
clearInterval(
|
|
1176
|
+
if (T) {
|
|
1177
|
+
const w = Le(y.iceConnectionState);
|
|
1178
|
+
if (y) {
|
|
1179
|
+
if (w === S.New) {
|
|
1180
|
+
clearInterval(q);
|
|
1174
1181
|
return;
|
|
1175
1182
|
}
|
|
1176
|
-
|
|
1183
|
+
y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
|
|
1177
1184
|
}
|
|
1178
1185
|
try {
|
|
1179
|
-
|
|
1186
|
+
w === S.Connected && await I(T, K).catch((F) => {
|
|
1180
1187
|
});
|
|
1181
|
-
} catch (
|
|
1182
|
-
r("Error on close stream connection",
|
|
1188
|
+
} catch (F) {
|
|
1189
|
+
r("Error on close stream connection", F);
|
|
1183
1190
|
}
|
|
1184
|
-
(h = n.onAgentActivityStateChange) == null || h.call(n,
|
|
1191
|
+
(h = n.onAgentActivityStateChange) == null || h.call(n, ae.Idle), clearInterval(q);
|
|
1185
1192
|
}
|
|
1186
1193
|
},
|
|
1187
1194
|
/**
|
|
1188
1195
|
* Method to send data channel messages to the server
|
|
1189
1196
|
*/
|
|
1190
1197
|
sendDataChannelMessage(h) {
|
|
1191
|
-
var
|
|
1192
|
-
if (!m ||
|
|
1193
|
-
r("Data channel is not ready for sending messages"), (
|
|
1194
|
-
streamId:
|
|
1198
|
+
var w, F;
|
|
1199
|
+
if (!m || $.readyState !== "open") {
|
|
1200
|
+
r("Data channel is not ready for sending messages"), (w = n.onError) == null || w.call(n, new Error("Data channel is not ready for sending messages"), {
|
|
1201
|
+
streamId: T
|
|
1195
1202
|
});
|
|
1196
1203
|
return;
|
|
1197
1204
|
}
|
|
1198
1205
|
try {
|
|
1199
|
-
|
|
1200
|
-
} catch (
|
|
1201
|
-
r("Error sending data channel message",
|
|
1206
|
+
$.send(h);
|
|
1207
|
+
} catch (Q) {
|
|
1208
|
+
r("Error sending data channel message", Q), (F = n.onError) == null || F.call(n, Q, { streamId: T });
|
|
1202
1209
|
}
|
|
1203
1210
|
},
|
|
1204
1211
|
/**
|
|
1205
1212
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1206
1213
|
*/
|
|
1207
|
-
sessionId:
|
|
1214
|
+
sessionId: K,
|
|
1208
1215
|
/**
|
|
1209
1216
|
* Id of current RTC stream
|
|
1210
1217
|
*/
|
|
1211
|
-
streamId:
|
|
1212
|
-
streamType:
|
|
1218
|
+
streamId: T,
|
|
1219
|
+
streamType: D,
|
|
1213
1220
|
interruptAvailable: f ?? !1,
|
|
1214
|
-
triggersAvailable:
|
|
1221
|
+
triggersAvailable: R ?? !1
|
|
1215
1222
|
};
|
|
1216
1223
|
}
|
|
1217
|
-
var
|
|
1218
|
-
async function
|
|
1224
|
+
var De = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(De || {});
|
|
1225
|
+
async function Yt(e, t, i, n) {
|
|
1219
1226
|
const c = e.id;
|
|
1220
1227
|
switch (t.version) {
|
|
1221
1228
|
case "v1": {
|
|
1222
1229
|
const { version: o, ...s } = t;
|
|
1223
|
-
return
|
|
1230
|
+
return Xt(c, s, i, n);
|
|
1224
1231
|
}
|
|
1225
1232
|
case "v2": {
|
|
1226
1233
|
const { version: o, ...s } = t;
|
|
1227
1234
|
switch (s.transport_provider) {
|
|
1228
1235
|
case he.Livekit:
|
|
1229
|
-
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() =>
|
|
1236
|
+
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Mt);
|
|
1230
1237
|
return a(c, s, i);
|
|
1231
1238
|
default:
|
|
1232
1239
|
throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
|
|
@@ -1236,13 +1243,13 @@ async function Qt(e, t, i, n) {
|
|
|
1236
1243
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1237
1244
|
}
|
|
1238
1245
|
}
|
|
1239
|
-
const
|
|
1240
|
-
function
|
|
1246
|
+
const Zt = "cht";
|
|
1247
|
+
function Gt() {
|
|
1241
1248
|
return {
|
|
1242
1249
|
transport_provider: he.Livekit
|
|
1243
1250
|
};
|
|
1244
1251
|
}
|
|
1245
|
-
function
|
|
1252
|
+
function en(e) {
|
|
1246
1253
|
var c, o;
|
|
1247
1254
|
const { streamOptions: t } = e ?? {}, i = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
1248
1255
|
plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
|
|
@@ -1255,14 +1262,14 @@ function Zt(e) {
|
|
|
1255
1262
|
fluent: t == null ? void 0 : t.fluent
|
|
1256
1263
|
}, ...i && { end_user_data: i } };
|
|
1257
1264
|
}
|
|
1258
|
-
function
|
|
1259
|
-
return
|
|
1265
|
+
function tn(e, t) {
|
|
1266
|
+
return Me(e.presenter.type) ? { version: De.V2, ...Gt() } : { version: De.V1, ...en(t) };
|
|
1260
1267
|
}
|
|
1261
|
-
function
|
|
1262
|
-
c === ne.Fluent ?
|
|
1268
|
+
function nn(e, t, i, n, c) {
|
|
1269
|
+
c === ne.Fluent ? rn(e, t, i, n, c) : on(e, t, i, n, c);
|
|
1263
1270
|
}
|
|
1264
|
-
function
|
|
1265
|
-
e ===
|
|
1271
|
+
function rn(e, t, i, n, c) {
|
|
1272
|
+
e === C.Start ? n.track("stream-session", { event: "start", "stream-type": c }) : e === C.Stop && n.track("stream-session", {
|
|
1266
1273
|
event: "stop",
|
|
1267
1274
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1268
1275
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -1270,13 +1277,13 @@ function tn(e, t, i, n, c) {
|
|
|
1270
1277
|
...i
|
|
1271
1278
|
});
|
|
1272
1279
|
}
|
|
1273
|
-
function
|
|
1274
|
-
te.get() <= 0 || (e ===
|
|
1280
|
+
function an(e, t, i, n) {
|
|
1281
|
+
te.get() <= 0 || (e === C.Start ? i.linkTrack(
|
|
1275
1282
|
"agent-video",
|
|
1276
1283
|
{ event: "start", latency: te.get(!0), "stream-type": n },
|
|
1277
1284
|
"start",
|
|
1278
|
-
[
|
|
1279
|
-
) : e ===
|
|
1285
|
+
[N.StreamVideoCreated]
|
|
1286
|
+
) : e === C.Stop && i.linkTrack(
|
|
1280
1287
|
"agent-video",
|
|
1281
1288
|
{
|
|
1282
1289
|
event: "stop",
|
|
@@ -1285,16 +1292,16 @@ function nn(e, t, i, n) {
|
|
|
1285
1292
|
"stream-type": n
|
|
1286
1293
|
},
|
|
1287
1294
|
"done",
|
|
1288
|
-
[
|
|
1295
|
+
[N.StreamVideoDone]
|
|
1289
1296
|
));
|
|
1290
1297
|
}
|
|
1291
|
-
function
|
|
1292
|
-
te.get() <= 0 || (e ===
|
|
1298
|
+
function on(e, t, i, n, c) {
|
|
1299
|
+
te.get() <= 0 || (e === C.Start ? n.linkTrack(
|
|
1293
1300
|
"agent-video",
|
|
1294
1301
|
{ event: "start", latency: te.get(!0), "stream-type": c },
|
|
1295
1302
|
"start",
|
|
1296
|
-
[
|
|
1297
|
-
) : e ===
|
|
1303
|
+
[N.StreamVideoCreated]
|
|
1304
|
+
) : e === C.Stop && n.linkTrack(
|
|
1298
1305
|
"agent-video",
|
|
1299
1306
|
{
|
|
1300
1307
|
event: "stop",
|
|
@@ -1304,17 +1311,17 @@ function rn(e, t, i, n, c) {
|
|
|
1304
1311
|
...i
|
|
1305
1312
|
},
|
|
1306
1313
|
"done",
|
|
1307
|
-
[
|
|
1314
|
+
[N.StreamVideoDone]
|
|
1308
1315
|
));
|
|
1309
1316
|
}
|
|
1310
|
-
function
|
|
1311
|
-
return te.reset(),
|
|
1317
|
+
function xe(e, t, i, n) {
|
|
1318
|
+
return te.reset(), je.update(), new Promise(async (c, o) => {
|
|
1312
1319
|
try {
|
|
1313
1320
|
let s, a = !1;
|
|
1314
|
-
const r =
|
|
1321
|
+
const r = tn(e, t);
|
|
1315
1322
|
i.enrich({
|
|
1316
1323
|
"stream-version": r.version.toString()
|
|
1317
|
-
}), s = await
|
|
1324
|
+
}), s = await Yt(
|
|
1318
1325
|
e,
|
|
1319
1326
|
r,
|
|
1320
1327
|
{
|
|
@@ -1324,11 +1331,11 @@ function Le(e, t, i, n) {
|
|
|
1324
1331
|
...t.callbacks,
|
|
1325
1332
|
onConnectionStateChange: (d) => {
|
|
1326
1333
|
var m, p;
|
|
1327
|
-
(p = (m = t.callbacks).onConnectionStateChange) == null || p.call(m, d), d ===
|
|
1334
|
+
(p = (m = t.callbacks).onConnectionStateChange) == null || p.call(m, d), d === S.Connected && (s ? c(s) : a = !0);
|
|
1328
1335
|
},
|
|
1329
1336
|
onVideoStateChange: (d, m) => {
|
|
1330
1337
|
var p, u;
|
|
1331
|
-
(u = (p = t.callbacks).onVideoStateChange) == null || u.call(p, d),
|
|
1338
|
+
(u = (p = t.callbacks).onVideoStateChange) == null || u.call(p, d), nn(
|
|
1332
1339
|
d,
|
|
1333
1340
|
e,
|
|
1334
1341
|
m,
|
|
@@ -1338,15 +1345,15 @@ function Le(e, t, i, n) {
|
|
|
1338
1345
|
},
|
|
1339
1346
|
onAgentActivityStateChange: (d) => {
|
|
1340
1347
|
var m, p;
|
|
1341
|
-
(p = (m = t.callbacks).onAgentActivityStateChange) == null || p.call(m, d), d ===
|
|
1342
|
-
d ===
|
|
1348
|
+
(p = (m = t.callbacks).onAgentActivityStateChange) == null || p.call(m, d), d === ae.Talking ? Ce.update() : Ce.reset(), an(
|
|
1349
|
+
d === ae.Talking ? C.Start : C.Stop,
|
|
1343
1350
|
e,
|
|
1344
1351
|
i,
|
|
1345
1352
|
s.streamType
|
|
1346
1353
|
);
|
|
1347
1354
|
},
|
|
1348
1355
|
onStreamReady: () => {
|
|
1349
|
-
const d =
|
|
1356
|
+
const d = je.get(!0);
|
|
1350
1357
|
i.track("agent-chat", { event: "ready", latency: d });
|
|
1351
1358
|
}
|
|
1352
1359
|
}
|
|
@@ -1358,65 +1365,65 @@ function Le(e, t, i, n) {
|
|
|
1358
1365
|
}
|
|
1359
1366
|
});
|
|
1360
1367
|
}
|
|
1361
|
-
async function
|
|
1362
|
-
var m, p, u,
|
|
1368
|
+
async function sn(e, t, i, n, c) {
|
|
1369
|
+
var m, p, u, E;
|
|
1363
1370
|
const o = async () => {
|
|
1364
|
-
if (
|
|
1365
|
-
const x = await
|
|
1371
|
+
if (Me(e.presenter.type)) {
|
|
1372
|
+
const x = await xe(e, t, n), O = `${Zt}_${x.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
|
|
1366
1373
|
return { chatResult: {
|
|
1367
|
-
chatMode:
|
|
1374
|
+
chatMode: U.Functional,
|
|
1368
1375
|
chat: {
|
|
1369
|
-
id:
|
|
1376
|
+
id: O,
|
|
1370
1377
|
agent_id: e.id,
|
|
1371
1378
|
owner_id: e.owner_id ?? "",
|
|
1372
|
-
created:
|
|
1373
|
-
modified:
|
|
1374
|
-
agent_id__created_at:
|
|
1375
|
-
agent_id__modified_at:
|
|
1376
|
-
chat_mode:
|
|
1379
|
+
created: I,
|
|
1380
|
+
modified: I,
|
|
1381
|
+
agent_id__created_at: I,
|
|
1382
|
+
agent_id__modified_at: I,
|
|
1383
|
+
chat_mode: U.Functional,
|
|
1377
1384
|
messages: []
|
|
1378
1385
|
}
|
|
1379
1386
|
}, streamingManager: x };
|
|
1380
1387
|
} else {
|
|
1381
|
-
const x = new AbortController(),
|
|
1382
|
-
let
|
|
1388
|
+
const x = new AbortController(), O = x.signal;
|
|
1389
|
+
let I;
|
|
1383
1390
|
try {
|
|
1384
|
-
const A =
|
|
1391
|
+
const A = Ue(
|
|
1385
1392
|
e,
|
|
1386
1393
|
i,
|
|
1387
1394
|
n,
|
|
1388
1395
|
t.mode,
|
|
1389
1396
|
t.persistentChat,
|
|
1390
1397
|
c
|
|
1391
|
-
),
|
|
1392
|
-
return { chatResult:
|
|
1398
|
+
), L = xe(e, t, n, O).then((B) => (I = B, B)), [T, re] = await Promise.all([A, L]);
|
|
1399
|
+
return { chatResult: T, streamingManager: re };
|
|
1393
1400
|
} catch (A) {
|
|
1394
|
-
throw x.abort(),
|
|
1401
|
+
throw x.abort(), I && await I.disconnect().catch(() => {
|
|
1395
1402
|
}), A;
|
|
1396
1403
|
}
|
|
1397
1404
|
}
|
|
1398
1405
|
}, { chatResult: s, streamingManager: a } = await o(), { chat: r, chatMode: d } = s;
|
|
1399
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (m = t.callbacks).onModeChange) == null || p.call(m, d), d !==
|
|
1406
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (m = t.callbacks).onModeChange) == null || p.call(m, d), d !== U.Functional) ? ((E = (u = t.callbacks).onError) == null || E.call(u, new qe(d)), a == null || a.disconnect(), { chat: r }) : { chat: r, streamingManager: a };
|
|
1400
1407
|
}
|
|
1401
|
-
async function
|
|
1402
|
-
var
|
|
1408
|
+
async function un(e, t) {
|
|
1409
|
+
var B, K, X;
|
|
1403
1410
|
let i = !0, n = null;
|
|
1404
|
-
const c = t.mixpanelKey ||
|
|
1411
|
+
const c = t.mixpanelKey || ct, o = t.wsURL || st, s = t.baseURL || fe, a = t.mode || U.Functional, r = {
|
|
1405
1412
|
messages: [],
|
|
1406
1413
|
chatMode: a
|
|
1407
|
-
}, d =
|
|
1414
|
+
}, d = vt({
|
|
1408
1415
|
token: c,
|
|
1409
1416
|
agentId: e,
|
|
1410
1417
|
isEnabled: t.enableAnalitics,
|
|
1411
1418
|
externalId: t.externalId,
|
|
1412
1419
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1413
1420
|
}), m = Date.now();
|
|
1414
|
-
|
|
1421
|
+
be(() => {
|
|
1415
1422
|
d.track("agent-sdk", { event: "init" }, m);
|
|
1416
1423
|
});
|
|
1417
|
-
const p =
|
|
1418
|
-
d.enrich(
|
|
1419
|
-
const { onMessage: x, clearQueue:
|
|
1424
|
+
const p = mt(t.auth, s, t.callbacks.onError, t.externalId), u = await p.getById(e), E = Me(u.presenter.type);
|
|
1425
|
+
d.enrich(ht(u));
|
|
1426
|
+
const { onMessage: x, clearQueue: O } = $t(
|
|
1420
1427
|
d,
|
|
1421
1428
|
r,
|
|
1422
1429
|
t,
|
|
@@ -1426,28 +1433,28 @@ async function cn(e, t) {
|
|
|
1426
1433
|
return (f = r.socketManager) == null ? void 0 : f.disconnect();
|
|
1427
1434
|
}
|
|
1428
1435
|
);
|
|
1429
|
-
r.messages =
|
|
1430
|
-
const
|
|
1436
|
+
r.messages = Ct(t.initialMessages), (K = (B = t.callbacks).onNewMessage) == null || K.call(B, [...r.messages], "answer");
|
|
1437
|
+
const I = (f) => {
|
|
1431
1438
|
n = f;
|
|
1432
1439
|
}, A = Date.now();
|
|
1433
|
-
|
|
1434
|
-
d.track("agent-sdk", { event: "loaded", ...
|
|
1440
|
+
be(() => {
|
|
1441
|
+
d.track("agent-sdk", { event: "loaded", ...gt(u) }, A);
|
|
1435
1442
|
});
|
|
1436
|
-
async function
|
|
1437
|
-
var
|
|
1438
|
-
(
|
|
1439
|
-
const
|
|
1443
|
+
async function L(f) {
|
|
1444
|
+
var W, H, q, j, J, G, M;
|
|
1445
|
+
(H = (W = t.callbacks).onConnectionStateChange) == null || H.call(W, S.Connecting), te.reset(), f && !i && (delete r.chat, (j = (q = t.callbacks).onNewMessage) == null || j.call(q, [...r.messages], "answer"));
|
|
1446
|
+
const R = a === U.DirectPlayback || E ? Promise.resolve(void 0) : Pt(
|
|
1440
1447
|
t.auth,
|
|
1441
1448
|
o,
|
|
1442
1449
|
{ onMessage: x, onError: t.callbacks.onError },
|
|
1443
1450
|
t.externalId
|
|
1444
|
-
),
|
|
1445
|
-
() =>
|
|
1451
|
+
), y = ve(
|
|
1452
|
+
() => sn(
|
|
1446
1453
|
u,
|
|
1447
1454
|
{
|
|
1448
1455
|
...t,
|
|
1449
1456
|
mode: a,
|
|
1450
|
-
callbacks: { ...t.callbacks, onVideoIdChange:
|
|
1457
|
+
callbacks: { ...t.callbacks, onVideoIdChange: I, onMessage: x }
|
|
1451
1458
|
},
|
|
1452
1459
|
p,
|
|
1453
1460
|
d,
|
|
@@ -1455,28 +1462,28 @@ async function cn(e, t) {
|
|
|
1455
1462
|
),
|
|
1456
1463
|
{
|
|
1457
1464
|
limit: 3,
|
|
1458
|
-
timeout:
|
|
1465
|
+
timeout: at,
|
|
1459
1466
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1460
1467
|
shouldRetryFn: (P) => (P == null ? void 0 : P.message) !== "Could not connect" && P.status !== 429 && (P == null ? void 0 : P.message) !== "InsufficientCreditsError",
|
|
1461
1468
|
delayMs: 1e3
|
|
1462
1469
|
}
|
|
1463
1470
|
).catch((P) => {
|
|
1464
1471
|
var Z, h;
|
|
1465
|
-
throw U
|
|
1466
|
-
}), [
|
|
1467
|
-
_ && _.id !== ((
|
|
1472
|
+
throw re(U.Maintenance), (h = (Z = t.callbacks).onConnectionStateChange) == null || h.call(Z, S.Fail), P;
|
|
1473
|
+
}), [$, { streamingManager: D, chat: _ }] = await Promise.all([R, y]);
|
|
1474
|
+
_ && _.id !== ((J = r.chat) == null ? void 0 : J.id) && ((M = (G = t.callbacks).onNewChat) == null || M.call(G, _.id)), r.streamingManager = D, r.socketManager = $, r.chat = _, i = !1, d.enrich({
|
|
1468
1475
|
chatId: _ == null ? void 0 : _.id,
|
|
1469
|
-
streamId:
|
|
1476
|
+
streamId: D == null ? void 0 : D.streamId,
|
|
1470
1477
|
mode: r.chatMode
|
|
1471
|
-
}),
|
|
1478
|
+
}), re((_ == null ? void 0 : _.chat_mode) ?? a);
|
|
1472
1479
|
}
|
|
1473
|
-
async function
|
|
1474
|
-
var f,
|
|
1475
|
-
(f = r.socketManager) == null || f.disconnect(), await ((
|
|
1480
|
+
async function T() {
|
|
1481
|
+
var f, R, y, $;
|
|
1482
|
+
(f = r.socketManager) == null || f.disconnect(), await ((R = r.streamingManager) == null ? void 0 : R.disconnect()), delete r.streamingManager, delete r.socketManager, ($ = (y = t.callbacks).onConnectionStateChange) == null || $.call(y, S.Disconnected);
|
|
1476
1483
|
}
|
|
1477
|
-
async function
|
|
1478
|
-
var
|
|
1479
|
-
f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !==
|
|
1484
|
+
async function re(f) {
|
|
1485
|
+
var R, y;
|
|
1486
|
+
f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== U.Functional && await T(), (y = (R = t.callbacks).onModeChange) == null || y.call(R, f));
|
|
1480
1487
|
}
|
|
1481
1488
|
return {
|
|
1482
1489
|
agent: u,
|
|
@@ -1492,43 +1499,43 @@ async function cn(e, t) {
|
|
|
1492
1499
|
var f;
|
|
1493
1500
|
return ((f = r.streamingManager) == null ? void 0 : f.triggersAvailable) ?? !1;
|
|
1494
1501
|
},
|
|
1495
|
-
starterMessages: ((
|
|
1502
|
+
starterMessages: ((X = u.knowledge) == null ? void 0 : X.starter_message) || [],
|
|
1496
1503
|
getSTTToken: () => p.getSTTToken(u.id),
|
|
1497
|
-
changeMode:
|
|
1504
|
+
changeMode: re,
|
|
1498
1505
|
enrichAnalytics: d.enrich,
|
|
1499
1506
|
async connect() {
|
|
1500
|
-
await
|
|
1507
|
+
await L(!0), d.track("agent-chat", {
|
|
1501
1508
|
event: "connect",
|
|
1502
1509
|
mode: r.chatMode
|
|
1503
1510
|
});
|
|
1504
1511
|
},
|
|
1505
1512
|
async reconnect() {
|
|
1506
1513
|
const f = r.streamingManager;
|
|
1507
|
-
if (
|
|
1514
|
+
if (E && (f != null && f.reconnect)) {
|
|
1508
1515
|
try {
|
|
1509
1516
|
await f.reconnect(), d.track("agent-chat", {
|
|
1510
1517
|
event: "reconnect",
|
|
1511
1518
|
mode: r.chatMode
|
|
1512
1519
|
});
|
|
1513
1520
|
} catch {
|
|
1514
|
-
await
|
|
1521
|
+
await T(), await L(!1);
|
|
1515
1522
|
}
|
|
1516
1523
|
return;
|
|
1517
1524
|
}
|
|
1518
|
-
await
|
|
1525
|
+
await T(), await L(!1), d.track("agent-chat", {
|
|
1519
1526
|
event: "reconnect",
|
|
1520
1527
|
mode: r.chatMode
|
|
1521
1528
|
});
|
|
1522
1529
|
},
|
|
1523
1530
|
async disconnect() {
|
|
1524
|
-
await
|
|
1531
|
+
await T(), d.track("agent-chat", {
|
|
1525
1532
|
event: "disconnect",
|
|
1526
1533
|
mode: r.chatMode
|
|
1527
1534
|
});
|
|
1528
1535
|
},
|
|
1529
1536
|
async publishMicrophoneStream(f) {
|
|
1530
|
-
var
|
|
1531
|
-
if (!((
|
|
1537
|
+
var R;
|
|
1538
|
+
if (!((R = r.streamingManager) != null && R.publishMicrophoneStream))
|
|
1532
1539
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1533
1540
|
return r.streamingManager.publishMicrophoneStream(f);
|
|
1534
1541
|
},
|
|
@@ -1539,26 +1546,26 @@ async function cn(e, t) {
|
|
|
1539
1546
|
return r.streamingManager.unpublishMicrophoneStream();
|
|
1540
1547
|
},
|
|
1541
1548
|
async chat(f) {
|
|
1542
|
-
var
|
|
1543
|
-
const
|
|
1544
|
-
if (
|
|
1549
|
+
var D, _, W, H, q;
|
|
1550
|
+
const R = () => {
|
|
1551
|
+
if (Ne(a))
|
|
1545
1552
|
throw new se(`${a} is enabled, chat is disabled`);
|
|
1546
1553
|
if (f.length >= 800)
|
|
1547
1554
|
throw new se("Message cannot be more than 800 characters");
|
|
1548
1555
|
if (f.length === 0)
|
|
1549
1556
|
throw new se("Message cannot be empty");
|
|
1550
|
-
if (r.chatMode ===
|
|
1557
|
+
if (r.chatMode === U.Maintenance)
|
|
1551
1558
|
throw new se("Chat is in maintenance mode");
|
|
1552
|
-
if (![
|
|
1559
|
+
if (![U.TextOnly, U.Playground].includes(r.chatMode)) {
|
|
1553
1560
|
if (!r.streamingManager)
|
|
1554
1561
|
throw new se("Streaming manager is not initialized");
|
|
1555
1562
|
if (!r.chat)
|
|
1556
1563
|
throw new se("Chat is not initialized");
|
|
1557
1564
|
}
|
|
1558
|
-
},
|
|
1559
|
-
var j,
|
|
1565
|
+
}, y = async () => {
|
|
1566
|
+
var j, J;
|
|
1560
1567
|
if (!r.chat) {
|
|
1561
|
-
const G = await
|
|
1568
|
+
const G = await Ue(
|
|
1562
1569
|
u,
|
|
1563
1570
|
p,
|
|
1564
1571
|
d,
|
|
@@ -1566,93 +1573,93 @@ async function cn(e, t) {
|
|
|
1566
1573
|
t.persistentChat
|
|
1567
1574
|
);
|
|
1568
1575
|
if (!G.chat)
|
|
1569
|
-
throw new
|
|
1570
|
-
r.chat = G.chat, (
|
|
1576
|
+
throw new He(r.chatMode, !!t.persistentChat);
|
|
1577
|
+
r.chat = G.chat, (J = (j = t.callbacks).onNewChat) == null || J.call(j, r.chat.id);
|
|
1571
1578
|
}
|
|
1572
1579
|
return r.chat.id;
|
|
1573
|
-
},
|
|
1574
|
-
var
|
|
1575
|
-
return await ((P = (
|
|
1580
|
+
}, $ = async (j, J) => ve(E ? async () => {
|
|
1581
|
+
var M, P;
|
|
1582
|
+
return await ((P = (M = r.streamingManager) == null ? void 0 : M.sendTextMessage) == null ? void 0 : P.call(M, f)), Promise.resolve({});
|
|
1576
1583
|
} : async () => {
|
|
1577
|
-
var
|
|
1584
|
+
var M, P;
|
|
1578
1585
|
return p.chat(
|
|
1579
1586
|
u.id,
|
|
1580
|
-
|
|
1587
|
+
J,
|
|
1581
1588
|
{
|
|
1582
1589
|
chatMode: r.chatMode,
|
|
1583
|
-
streamId: (
|
|
1590
|
+
streamId: (M = r.streamingManager) == null ? void 0 : M.streamId,
|
|
1584
1591
|
sessionId: (P = r.streamingManager) == null ? void 0 : P.sessionId,
|
|
1585
1592
|
messages: j.map(({ matches: Z, ...h }) => h)
|
|
1586
1593
|
},
|
|
1587
1594
|
{
|
|
1588
|
-
...
|
|
1595
|
+
...Je(r.chatMode),
|
|
1589
1596
|
skipErrorHandler: !0
|
|
1590
1597
|
}
|
|
1591
1598
|
);
|
|
1592
1599
|
}, {
|
|
1593
1600
|
limit: 2,
|
|
1594
|
-
shouldRetryFn: (
|
|
1595
|
-
var h,
|
|
1596
|
-
const P = (h =
|
|
1597
|
-
return !((
|
|
1601
|
+
shouldRetryFn: (M) => {
|
|
1602
|
+
var h, w, F, Q;
|
|
1603
|
+
const P = (h = M == null ? void 0 : M.message) == null ? void 0 : h.includes("missing or invalid session_id");
|
|
1604
|
+
return !((w = M == null ? void 0 : M.message) == null ? void 0 : w.includes("Stream Error")) && !P ? ((Q = (F = t.callbacks).onError) == null || Q.call(F, M), !1) : !0;
|
|
1598
1605
|
},
|
|
1599
1606
|
onRetry: async () => {
|
|
1600
|
-
await
|
|
1607
|
+
await T(), await L(!1);
|
|
1601
1608
|
}
|
|
1602
1609
|
});
|
|
1603
1610
|
try {
|
|
1604
|
-
|
|
1611
|
+
O(), R(), r.messages.push({
|
|
1605
1612
|
id: ce(),
|
|
1606
1613
|
role: "user",
|
|
1607
1614
|
content: f,
|
|
1608
1615
|
created_at: new Date(te.update()).toISOString()
|
|
1609
|
-
}), (_ = (
|
|
1610
|
-
const j = await
|
|
1616
|
+
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "user");
|
|
1617
|
+
const j = await y(), J = await $([...r.messages], j);
|
|
1611
1618
|
return r.messages.push({
|
|
1612
1619
|
id: ce(),
|
|
1613
1620
|
role: "assistant",
|
|
1614
|
-
content:
|
|
1621
|
+
content: J.result || "",
|
|
1615
1622
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1616
|
-
context:
|
|
1617
|
-
matches:
|
|
1623
|
+
context: J.context,
|
|
1624
|
+
matches: J.matches
|
|
1618
1625
|
}), d.track("agent-message-send", {
|
|
1619
1626
|
event: "success",
|
|
1620
1627
|
messages: r.messages.length + 1
|
|
1621
|
-
}),
|
|
1628
|
+
}), J.result && ((H = (W = t.callbacks).onNewMessage) == null || H.call(W, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1622
1629
|
latency: te.get(!0),
|
|
1623
1630
|
messages: r.messages.length
|
|
1624
|
-
})),
|
|
1631
|
+
})), J;
|
|
1625
1632
|
} catch (j) {
|
|
1626
|
-
throw ((
|
|
1633
|
+
throw ((q = r.messages[r.messages.length - 1]) == null ? void 0 : q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1627
1634
|
event: "error",
|
|
1628
1635
|
messages: r.messages.length
|
|
1629
1636
|
}), j;
|
|
1630
1637
|
}
|
|
1631
1638
|
},
|
|
1632
|
-
rate(f,
|
|
1633
|
-
var _,
|
|
1634
|
-
const
|
|
1639
|
+
rate(f, R, y) {
|
|
1640
|
+
var _, W, H, q;
|
|
1641
|
+
const $ = r.messages.find((j) => j.id === f);
|
|
1635
1642
|
if (r.chat) {
|
|
1636
|
-
if (
|
|
1643
|
+
if (!$)
|
|
1637
1644
|
throw new Error("Message not found");
|
|
1638
1645
|
} else throw new Error("Chat is not initialized");
|
|
1639
|
-
const
|
|
1646
|
+
const D = ((_ = $.matches) == null ? void 0 : _.map((j) => [j.document_id, j.id])) ?? [];
|
|
1640
1647
|
return d.track("agent-rate", {
|
|
1641
|
-
event:
|
|
1642
|
-
thumb:
|
|
1643
|
-
knowledge_id: ((
|
|
1644
|
-
matches:
|
|
1645
|
-
score:
|
|
1646
|
-
}),
|
|
1647
|
-
knowledge_id: ((
|
|
1648
|
+
event: y ? "update" : "create",
|
|
1649
|
+
thumb: R === 1 ? "up" : "down",
|
|
1650
|
+
knowledge_id: ((W = u.knowledge) == null ? void 0 : W.id) ?? "",
|
|
1651
|
+
matches: D,
|
|
1652
|
+
score: R
|
|
1653
|
+
}), y ? p.updateRating(u.id, r.chat.id, y, {
|
|
1654
|
+
knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
|
|
1648
1655
|
message_id: f,
|
|
1649
|
-
matches:
|
|
1650
|
-
score:
|
|
1656
|
+
matches: D,
|
|
1657
|
+
score: R
|
|
1651
1658
|
}) : p.createRating(u.id, r.chat.id, {
|
|
1652
|
-
knowledge_id: ((
|
|
1659
|
+
knowledge_id: ((q = u.knowledge) == null ? void 0 : q.id) ?? "",
|
|
1653
1660
|
message_id: f,
|
|
1654
|
-
matches:
|
|
1655
|
-
score:
|
|
1661
|
+
matches: D,
|
|
1662
|
+
score: R
|
|
1656
1663
|
});
|
|
1657
1664
|
},
|
|
1658
1665
|
deleteRate(f) {
|
|
@@ -1661,8 +1668,8 @@ async function cn(e, t) {
|
|
|
1661
1668
|
return d.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, r.chat.id, f);
|
|
1662
1669
|
},
|
|
1663
1670
|
async speak(f) {
|
|
1664
|
-
var
|
|
1665
|
-
function
|
|
1671
|
+
var D, _, W;
|
|
1672
|
+
function R() {
|
|
1666
1673
|
if (typeof f == "string") {
|
|
1667
1674
|
if (!u.presenter.voice)
|
|
1668
1675
|
throw new Error("Presenter voice is not initialized");
|
|
@@ -1685,13 +1692,13 @@ async function cn(e, t) {
|
|
|
1685
1692
|
}
|
|
1686
1693
|
return f;
|
|
1687
1694
|
}
|
|
1688
|
-
const
|
|
1689
|
-
if (d.track("agent-speak",
|
|
1695
|
+
const y = R();
|
|
1696
|
+
if (d.track("agent-speak", y), te.update(), r.messages && y.type === "text" && (r.messages.push({
|
|
1690
1697
|
id: ce(),
|
|
1691
1698
|
role: "assistant",
|
|
1692
|
-
content:
|
|
1699
|
+
content: y.input,
|
|
1693
1700
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1694
|
-
}), (_ = (
|
|
1701
|
+
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "answer")), dt(r.chatMode))
|
|
1695
1702
|
return {
|
|
1696
1703
|
duration: 0,
|
|
1697
1704
|
video_id: "",
|
|
@@ -1700,45 +1707,45 @@ async function cn(e, t) {
|
|
|
1700
1707
|
if (!r.streamingManager)
|
|
1701
1708
|
throw new Error("Please connect to the agent first");
|
|
1702
1709
|
return r.streamingManager.speak({
|
|
1703
|
-
script:
|
|
1704
|
-
metadata: { chat_id: (
|
|
1710
|
+
script: y,
|
|
1711
|
+
metadata: { chat_id: (W = r.chat) == null ? void 0 : W.id, agent_id: u.id }
|
|
1705
1712
|
});
|
|
1706
1713
|
},
|
|
1707
1714
|
async interrupt({ type: f }) {
|
|
1708
|
-
var
|
|
1709
|
-
const
|
|
1715
|
+
var y, $, D;
|
|
1716
|
+
const R = r.messages[r.messages.length - 1];
|
|
1710
1717
|
d.track("agent-video-interrupt", {
|
|
1711
1718
|
type: f || "click",
|
|
1712
|
-
video_duration_to_interrupt:
|
|
1719
|
+
video_duration_to_interrupt: Ce.get(!0),
|
|
1713
1720
|
message_duration_to_interrupt: te.get(!0)
|
|
1714
|
-
}),
|
|
1721
|
+
}), R.interrupted = !0, ($ = (y = t.callbacks).onNewMessage) == null || $.call(y, [...r.messages], "answer"), E ? Tt(r.streamingManager) : (Et(r.streamingManager, (D = r.streamingManager) == null ? void 0 : D.streamType, n), It(r.streamingManager, n));
|
|
1715
1722
|
}
|
|
1716
1723
|
};
|
|
1717
1724
|
}
|
|
1718
1725
|
export {
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1726
|
+
ae as AgentActivityState,
|
|
1727
|
+
Ze as AgentStatus,
|
|
1728
|
+
He as ChatCreationFailed,
|
|
1729
|
+
U as ChatMode,
|
|
1730
|
+
qe as ChatModeDowngraded,
|
|
1724
1731
|
Y as ChatProgress,
|
|
1725
|
-
|
|
1732
|
+
S as ConnectionState,
|
|
1726
1733
|
ee as ConnectivityState,
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1734
|
+
nt as DocumentType,
|
|
1735
|
+
tt as KnowledgeType,
|
|
1736
|
+
Ye as PlanGroup,
|
|
1737
|
+
rt as Providers,
|
|
1738
|
+
Ge as RateState,
|
|
1739
|
+
N as StreamEvents,
|
|
1733
1740
|
ne as StreamType,
|
|
1734
|
-
|
|
1735
|
-
|
|
1741
|
+
C as StreamingState,
|
|
1742
|
+
et as Subject,
|
|
1736
1743
|
he as TransportProvider,
|
|
1737
|
-
|
|
1744
|
+
Xe as UserPlan,
|
|
1738
1745
|
se as ValidationError,
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1746
|
+
Be as VideoType,
|
|
1747
|
+
it as VoiceAccess,
|
|
1748
|
+
Qe as WsError,
|
|
1749
|
+
un as createAgentManager,
|
|
1750
|
+
dn as mapVideoType
|
|
1744
1751
|
};
|