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