@d-id/client-sdk 1.1.57 → 1.1.58
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 +767 -740
- package/dist/index.umd.cjs +7 -7
- package/dist/src/services/streaming-manager/common.d.ts +9 -2
- package/dist/src/types/entities/agents/manager.d.ts +13 -5
- package/dist/src/types/stream/rtc.d.ts +0 -1
- package/dist/src/types/stream/stream.d.ts +1 -0
- package/dist/src/types/stream/streams-v2.d.ts +1 -0
- package/dist/src/utils/analytics.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
1
|
+
var wt = Object.defineProperty;
|
|
2
|
+
var yt = (e, n, i) => n in e ? wt(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
|
+
var Ce = (e, n, i) => yt(e, typeof n != "symbol" ? n + "" : n, i);
|
|
4
|
+
class Me extends Error {
|
|
5
5
|
constructor({ kind: i, description: r, error: o }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: r }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
Ce(this, "kind");
|
|
8
|
+
Ce(this, "description");
|
|
9
|
+
Ce(this, "error");
|
|
10
10
|
this.kind = i, this.description = r, this.error = o;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class vt extends Me {
|
|
14
14
|
constructor(n, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,25 +18,25 @@ class yt extends Re {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Ct extends Me {
|
|
22
22
|
constructor(n) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${n}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class me extends Me {
|
|
27
27
|
constructor(i, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
Ce(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class St extends Me {
|
|
34
34
|
constructor(n) {
|
|
35
35
|
super({ kind: "WSError", description: n });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var Rt = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Rt || {}), 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 || {}), kt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(kt || {}), Et = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Et || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Mt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Mt || {}), Dt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Dt || {}), It = /* @__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))(It || {}), nt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(nt || {});
|
|
39
|
+
const zn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,12 +48,12 @@ const Fn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}),
|
|
52
|
-
const
|
|
53
|
-
},
|
|
51
|
+
var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), D = /* @__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.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(D || {}), L = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(L || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Be = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Be || {}), At = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(At || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(_t || {});
|
|
52
|
+
const bt = 45 * 1e3, Pt = "X-Playground-Chat", Te = "https://api.d-id.com", Lt = "wss://notifications.d-id.com", $t = "79f81a83a67430be2bc0fd61042b8faa", jt = (...e) => {
|
|
53
|
+
}, rt = (e) => new Promise((n) => setTimeout(n, e)), ge = (e = 16) => {
|
|
54
54
|
const n = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
|
-
},
|
|
56
|
+
}, it = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, xt = (e) => {
|
|
57
57
|
switch (e.type) {
|
|
58
58
|
case "expressive":
|
|
59
59
|
return "v4";
|
|
@@ -62,8 +62,8 @@ const _t = 45 * 1e3, bt = "X-Playground-Chat", we = "https://api.d-id.com", Pt =
|
|
|
62
62
|
case "talk":
|
|
63
63
|
return "v2";
|
|
64
64
|
}
|
|
65
|
-
},
|
|
66
|
-
function
|
|
65
|
+
}, Bt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Fe = (e) => e === nt.Expressive, Ft = (e) => [O.TextOnly, O.Playground, O.Maintenance].includes(e), at = (e) => e && [O.DirectPlayback, O.Off].includes(e);
|
|
66
|
+
function zt(e, n) {
|
|
67
67
|
let i;
|
|
68
68
|
return {
|
|
69
69
|
promise: new Promise((o, a) => {
|
|
@@ -72,7 +72,7 @@ function Ft(e, n) {
|
|
|
72
72
|
clear: () => clearTimeout(i)
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
async function
|
|
75
|
+
async function Pe(e, n) {
|
|
76
76
|
const i = {
|
|
77
77
|
limit: (n == null ? void 0 : n.limit) ?? 3,
|
|
78
78
|
delayMs: (n == null ? void 0 : n.delayMs) ?? 0,
|
|
@@ -87,56 +87,56 @@ async function Ie(e, n) {
|
|
|
87
87
|
try {
|
|
88
88
|
if (!i.timeout)
|
|
89
89
|
return await e();
|
|
90
|
-
const { promise: a, clear: s } =
|
|
90
|
+
const { promise: a, clear: s } = zt(i.timeout, i.timeoutErrorMessage), d = e().finally(s);
|
|
91
91
|
return await Promise.race([d, a]);
|
|
92
92
|
} catch (a) {
|
|
93
93
|
if (r = a, !i.shouldRetryFn(a) || o >= i.limit)
|
|
94
94
|
throw a;
|
|
95
|
-
await
|
|
95
|
+
await rt(i.delayMs), i.onRetry(a);
|
|
96
96
|
}
|
|
97
97
|
throw r;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function Le(e) {
|
|
100
100
|
if (e !== void 0)
|
|
101
101
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
102
102
|
let n = window.localStorage.getItem("did_external_key_id");
|
|
103
103
|
if (!n) {
|
|
104
|
-
let i =
|
|
104
|
+
let i = ge();
|
|
105
105
|
window.localStorage.setItem("did_external_key_id", i), n = i;
|
|
106
106
|
}
|
|
107
107
|
return n;
|
|
108
108
|
}
|
|
109
|
-
let
|
|
110
|
-
function
|
|
109
|
+
let Kt = ge();
|
|
110
|
+
function ot(e, n) {
|
|
111
111
|
if (e.type === "bearer")
|
|
112
112
|
return `Bearer ${e.token}`;
|
|
113
113
|
if (e.type === "basic")
|
|
114
114
|
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
115
115
|
if (e.type === "key")
|
|
116
|
-
return `Client-Key ${e.clientKey}.${
|
|
116
|
+
return `Client-Key ${e.clientKey}.${Le(n)}_${Kt}`;
|
|
117
117
|
throw new Error(`Unknown auth type: ${e}`);
|
|
118
118
|
}
|
|
119
|
-
const
|
|
119
|
+
const Nt = (e) => Pe(e, {
|
|
120
120
|
limit: 3,
|
|
121
121
|
delayMs: 1e3,
|
|
122
122
|
timeout: 0,
|
|
123
123
|
shouldRetryFn: (n) => n.status === 429
|
|
124
124
|
});
|
|
125
|
-
function
|
|
125
|
+
function ze(e, n = Te, i, r) {
|
|
126
126
|
const o = async (a, s) => {
|
|
127
|
-
const { skipErrorHandler: d, ...t } = s || {}, c = await
|
|
127
|
+
const { skipErrorHandler: d, ...t } = s || {}, c = await Nt(
|
|
128
128
|
() => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
129
129
|
...t,
|
|
130
130
|
headers: {
|
|
131
131
|
...t.headers,
|
|
132
|
-
Authorization:
|
|
132
|
+
Authorization: ot(e, r),
|
|
133
133
|
"Content-Type": "application/json"
|
|
134
134
|
}
|
|
135
135
|
})
|
|
136
136
|
);
|
|
137
137
|
if (!c.ok) {
|
|
138
|
-
let
|
|
139
|
-
const g = new Error(
|
|
138
|
+
let h = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
|
|
139
|
+
const g = new Error(h);
|
|
140
140
|
throw i && !d && i(g, { url: a, options: t, headers: c.headers }), g;
|
|
141
141
|
}
|
|
142
142
|
return c.json();
|
|
@@ -156,8 +156,8 @@ function je(e, n = we, i, r) {
|
|
|
156
156
|
}
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
function
|
|
160
|
-
const o =
|
|
159
|
+
function Vt(e, n = Te, i, r) {
|
|
160
|
+
const o = ze(e, `${n}/agents`, i, r);
|
|
161
161
|
return {
|
|
162
162
|
create(a, s) {
|
|
163
163
|
return o.post("/", a, s);
|
|
@@ -194,7 +194,7 @@ function Nt(e, n = we, i, r) {
|
|
|
194
194
|
}
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function Jt(e) {
|
|
198
198
|
var o, a, s, d;
|
|
199
199
|
const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
200
200
|
const t = navigator.platform;
|
|
@@ -205,7 +205,7 @@ function Vt(e) {
|
|
|
205
205
|
isMobile: `${n() == "Mobile"}`,
|
|
206
206
|
browser: navigator.userAgent,
|
|
207
207
|
origin: window.location.origin,
|
|
208
|
-
agentType:
|
|
208
|
+
agentType: it(r),
|
|
209
209
|
agentVoice: {
|
|
210
210
|
voiceId: (a = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : a.voice_id,
|
|
211
211
|
provider: (d = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : d.type
|
|
@@ -216,9 +216,9 @@ function Ut(e) {
|
|
|
216
216
|
var i, r, o, a, s, d;
|
|
217
217
|
const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
218
218
|
return {
|
|
219
|
-
agentType:
|
|
220
|
-
presenterType:
|
|
221
|
-
presenter:
|
|
219
|
+
agentType: it(e.presenter),
|
|
220
|
+
presenterType: xt(e.presenter),
|
|
221
|
+
presenter: Bt(e.presenter),
|
|
222
222
|
owner_id: e.owner_id ?? "",
|
|
223
223
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
224
224
|
behavior: {
|
|
@@ -233,38 +233,38 @@ function Ut(e) {
|
|
|
233
233
|
maxResponseLength: n == null ? void 0 : n.max_response_length,
|
|
234
234
|
agentId: e.id,
|
|
235
235
|
access: e.access,
|
|
236
|
-
|
|
236
|
+
agentName: e.preview_name,
|
|
237
237
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
const
|
|
241
|
-
function
|
|
242
|
-
var t, c,
|
|
240
|
+
const Ot = (e) => e.reduce((n, i) => n + i, 0), He = (e) => Ot(e) / e.length;
|
|
241
|
+
function Wt(e, n, i) {
|
|
242
|
+
var t, c, h;
|
|
243
243
|
const { event: r, ...o } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: s } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
|
|
244
244
|
return {
|
|
245
245
|
...o,
|
|
246
246
|
llm: { ...o.llm, template: a },
|
|
247
247
|
script: { ...o.script, provider: { ...(c = o == null ? void 0 : o.script) == null ? void 0 : c.provider, language: s } },
|
|
248
|
-
stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (
|
|
248
|
+
stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (h = n == null ? void 0 : n.presenter) == null ? void 0 : h.stitch : void 0,
|
|
249
249
|
...i
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
-
function
|
|
252
|
+
function qe(e) {
|
|
253
253
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
254
254
|
}
|
|
255
|
-
const
|
|
256
|
-
function
|
|
255
|
+
const Ht = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
256
|
+
function qt(e) {
|
|
257
257
|
const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
|
|
258
258
|
return {
|
|
259
259
|
token: e.token || "testKey",
|
|
260
|
-
distinct_id:
|
|
260
|
+
distinct_id: Le(e.externalId),
|
|
261
261
|
agentId: e.agentId,
|
|
262
262
|
additionalProperties: {
|
|
263
|
-
id:
|
|
263
|
+
id: Le(e.externalId),
|
|
264
264
|
...e.mixpanelAdditionalProperties || {}
|
|
265
265
|
},
|
|
266
266
|
isEnabled: e.isEnabled ?? !0,
|
|
267
|
-
getRandom:
|
|
267
|
+
getRandom: ge,
|
|
268
268
|
enrich(r) {
|
|
269
269
|
this.additionalProperties = { ...this.additionalProperties, ...r };
|
|
270
270
|
},
|
|
@@ -297,7 +297,7 @@ function Ht(e) {
|
|
|
297
297
|
])
|
|
298
298
|
})
|
|
299
299
|
};
|
|
300
|
-
return fetch(
|
|
300
|
+
return fetch(Ht, c).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
|
|
301
301
|
},
|
|
302
302
|
linkTrack(r, o, a, s) {
|
|
303
303
|
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), s.includes(a) || s.push(a);
|
|
@@ -305,17 +305,17 @@ function Ht(e) {
|
|
|
305
305
|
if (d.events[a] = { props: o }, d.resolvedDependencies.push(a), s.every(
|
|
306
306
|
(c) => d.resolvedDependencies.includes(c)
|
|
307
307
|
)) {
|
|
308
|
-
const c = s.reduce((
|
|
308
|
+
const c = s.reduce((h, g) => d.events[g] ? { ...h, ...d.events[g].props } : h, {});
|
|
309
309
|
this.track(r, c), d.resolvedDependencies = d.resolvedDependencies.filter(
|
|
310
|
-
(
|
|
311
|
-
), s.forEach((
|
|
312
|
-
delete d.events[
|
|
310
|
+
(h) => !s.includes(h)
|
|
311
|
+
), s.forEach((h) => {
|
|
312
|
+
delete d.events[h];
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function Ke() {
|
|
319
319
|
let e = 0;
|
|
320
320
|
return {
|
|
321
321
|
reset: () => e = 0,
|
|
@@ -323,22 +323,22 @@ function $e() {
|
|
|
323
323
|
get: (n = !1) => n ? Date.now() - e : e
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
|
-
const
|
|
327
|
-
function
|
|
328
|
-
return e ===
|
|
326
|
+
const oe = Ke(), $e = Ke(), Qe = Ke();
|
|
327
|
+
function st(e) {
|
|
328
|
+
return e === O.Playground ? { headers: { [Pt]: "true" } } : {};
|
|
329
329
|
}
|
|
330
|
-
async function
|
|
330
|
+
async function ct(e, n, i, r, o = !1, a) {
|
|
331
331
|
try {
|
|
332
|
-
return !a && !
|
|
332
|
+
return !a && !at(r) && (a = await n.newChat(e.id, { persist: o }, st(r)), i.track("agent-chat", {
|
|
333
333
|
event: "created",
|
|
334
334
|
chatId: a.id,
|
|
335
335
|
mode: r
|
|
336
336
|
})), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
|
|
337
337
|
} catch (s) {
|
|
338
|
-
throw
|
|
338
|
+
throw Qt(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
|
-
const
|
|
341
|
+
const Qt = (e) => {
|
|
342
342
|
try {
|
|
343
343
|
const n = JSON.parse(e.message);
|
|
344
344
|
return n == null ? void 0 : n.kind;
|
|
@@ -346,22 +346,22 @@ const qt = (e) => {
|
|
|
346
346
|
return "UnknownError";
|
|
347
347
|
}
|
|
348
348
|
};
|
|
349
|
-
function
|
|
349
|
+
function Xt(e) {
|
|
350
350
|
return e && e.length > 0 ? e : [];
|
|
351
351
|
}
|
|
352
|
-
function
|
|
353
|
-
const o =
|
|
352
|
+
function Yt(e, n, i, r) {
|
|
353
|
+
const o = ze(e, `${n}/v2/agents/${i}`, r);
|
|
354
354
|
return {
|
|
355
355
|
async createStream(a) {
|
|
356
356
|
return o.post("/sessions", a);
|
|
357
357
|
}
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
|
-
const
|
|
361
|
-
[
|
|
362
|
-
[
|
|
360
|
+
const dt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), Gt = {
|
|
361
|
+
[D.ChatAnswer]: X.Answer,
|
|
362
|
+
[D.ChatPartial]: X.Partial
|
|
363
363
|
};
|
|
364
|
-
function
|
|
364
|
+
function Zt(e, n, i) {
|
|
365
365
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
366
366
|
return {
|
|
367
367
|
duration: r,
|
|
@@ -381,7 +381,7 @@ function Gt(e, n, i) {
|
|
|
381
381
|
lowFpsCount: i
|
|
382
382
|
};
|
|
383
383
|
}
|
|
384
|
-
function
|
|
384
|
+
function en(e) {
|
|
385
385
|
return e.filter(
|
|
386
386
|
(n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0
|
|
387
387
|
).map((n) => {
|
|
@@ -392,7 +392,7 @@ function Zt(e) {
|
|
|
392
392
|
};
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function tn(e) {
|
|
396
396
|
let n = "", i = 0;
|
|
397
397
|
for (const r of e.values()) {
|
|
398
398
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (n = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -422,7 +422,7 @@ function en(e) {
|
|
|
422
422
|
}
|
|
423
423
|
return {};
|
|
424
424
|
}
|
|
425
|
-
function
|
|
425
|
+
function Xe(e, n, i) {
|
|
426
426
|
const r = e.map((t, c) => c === 0 ? i ? {
|
|
427
427
|
timestamp: t.timestamp,
|
|
428
428
|
duration: 0,
|
|
@@ -474,112 +474,112 @@ function He(e, n, i) {
|
|
|
474
474
|
framesPerSecond: t.framesPerSecond,
|
|
475
475
|
freezeCount: t.freezeCount - e[c - 1].freezeCount,
|
|
476
476
|
freezeDuration: t.freezeDuration - e[c - 1].freezeDuration
|
|
477
|
-
}), o =
|
|
477
|
+
}), o = en(r), a = o.reduce((t, c) => t + (c.causes.includes("low fps") ? 1 : 0), 0), s = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), d = r.filter((t) => !!t.rtt).map((t) => t.rtt);
|
|
478
478
|
return {
|
|
479
479
|
webRTCStats: {
|
|
480
480
|
anomalies: o,
|
|
481
481
|
minRtt: Math.min(...d),
|
|
482
|
-
avgRtt:
|
|
482
|
+
avgRtt: He(d),
|
|
483
483
|
maxRtt: Math.max(...d),
|
|
484
|
-
aggregateReport:
|
|
484
|
+
aggregateReport: Zt(e[0], e[e.length - 1], a),
|
|
485
485
|
minJitterDelayInInterval: Math.min(...s),
|
|
486
486
|
maxJitterDelayInInterval: Math.max(...s),
|
|
487
|
-
avgJitterDelayInInterval:
|
|
487
|
+
avgJitterDelayInInterval: He(s)
|
|
488
488
|
},
|
|
489
489
|
codec: e[0].codec,
|
|
490
490
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
|
-
function
|
|
493
|
+
function ut(e, n) {
|
|
494
494
|
for (const i of e.values())
|
|
495
495
|
if ((i == null ? void 0 : i.type) === "inbound-rtp" && i.kind === n)
|
|
496
496
|
return i;
|
|
497
497
|
return null;
|
|
498
498
|
}
|
|
499
|
-
const
|
|
500
|
-
function
|
|
499
|
+
const Se = 10;
|
|
500
|
+
function nn(e, n) {
|
|
501
501
|
let i = !1, r = !1, o = null, a = 0, s = 0, d = {};
|
|
502
502
|
async function t() {
|
|
503
503
|
if (i) {
|
|
504
504
|
try {
|
|
505
505
|
const c = await e();
|
|
506
506
|
if (!c) {
|
|
507
|
-
o = setTimeout(t,
|
|
507
|
+
o = setTimeout(t, Se);
|
|
508
508
|
return;
|
|
509
509
|
}
|
|
510
|
-
const
|
|
511
|
-
if (!
|
|
512
|
-
o = setTimeout(t,
|
|
510
|
+
const h = ut(c, "audio");
|
|
511
|
+
if (!h) {
|
|
512
|
+
o = setTimeout(t, Se);
|
|
513
513
|
return;
|
|
514
514
|
}
|
|
515
|
-
const g =
|
|
515
|
+
const g = h.totalAudioEnergy ?? 0, l = h.totalSamplesReceived ?? 0;
|
|
516
516
|
if (!r) {
|
|
517
|
-
a = g, s = l, r = !0, o = setTimeout(t,
|
|
517
|
+
a = g, s = l, r = !0, o = setTimeout(t, Se);
|
|
518
518
|
return;
|
|
519
519
|
}
|
|
520
|
-
const v = g - a,
|
|
521
|
-
if (a = g, s = l,
|
|
520
|
+
const v = g - a, P = l - s;
|
|
521
|
+
if (a = g, s = l, P > 0 && v > 0) {
|
|
522
522
|
i = !1, n(d);
|
|
523
523
|
return;
|
|
524
524
|
}
|
|
525
525
|
} catch {
|
|
526
526
|
}
|
|
527
|
-
i && (o = setTimeout(t,
|
|
527
|
+
i && (o = setTimeout(t, Se));
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
return {
|
|
531
531
|
arm(c = {}) {
|
|
532
|
-
d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t,
|
|
532
|
+
d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t, Se);
|
|
533
533
|
},
|
|
534
534
|
destroy() {
|
|
535
535
|
i = !1, o !== null && (clearTimeout(o), o = null);
|
|
536
536
|
}
|
|
537
537
|
};
|
|
538
538
|
}
|
|
539
|
-
const
|
|
540
|
-
function
|
|
539
|
+
const Ee = 100, rn = Math.max(Math.ceil(400 / Ee), 1), an = 0.25, on = 0.28;
|
|
540
|
+
function sn() {
|
|
541
541
|
let e = 0, n, i, r = 0;
|
|
542
542
|
return (o) => {
|
|
543
|
-
const a =
|
|
543
|
+
const a = ut(o, "video");
|
|
544
544
|
if (!a)
|
|
545
545
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
546
546
|
const s = a.jitterBufferDelay, d = a.jitterBufferEmittedCount;
|
|
547
547
|
if (i && d > i) {
|
|
548
|
-
const
|
|
549
|
-
r =
|
|
548
|
+
const h = s - n, g = d - i;
|
|
549
|
+
r = h / g;
|
|
550
550
|
}
|
|
551
551
|
n = s, i = d;
|
|
552
552
|
const t = a.framesDecoded, c = t - e > 0;
|
|
553
553
|
return e = t, { isReceiving: c, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
|
|
554
554
|
};
|
|
555
555
|
}
|
|
556
|
-
function
|
|
557
|
-
let a = null, s = [], d, t = 0, c = !1,
|
|
558
|
-
const
|
|
559
|
-
async function
|
|
560
|
-
const
|
|
561
|
-
if (!
|
|
556
|
+
function lt(e, n, i, r, o) {
|
|
557
|
+
let a = null, s = [], d, t = 0, c = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
|
|
558
|
+
const P = sn();
|
|
559
|
+
async function z() {
|
|
560
|
+
const x = await e();
|
|
561
|
+
if (!x)
|
|
562
562
|
return;
|
|
563
|
-
const { isReceiving:
|
|
564
|
-
if (
|
|
565
|
-
t = 0, l =
|
|
566
|
-
else if (c && (t++, t >=
|
|
567
|
-
const
|
|
568
|
-
r == null || r(T.Stop,
|
|
563
|
+
const { isReceiving: F, avgJitterDelayInInterval: M, freezeCount: E } = P(x), Y = tn(x);
|
|
564
|
+
if (F)
|
|
565
|
+
t = 0, l = E - v, g = M < an ? ae.Strong : M > on && l > 1 ? ae.Weak : h, g !== h && (o == null || o(g), h = g, v += l, l = 0), c || (r == null || r(T.Start), d = s[s.length - 1], s = [], c = !0), s.push(Y);
|
|
566
|
+
else if (c && (t++, t >= rn)) {
|
|
567
|
+
const Q = Xe(s, Ee, d);
|
|
568
|
+
r == null || r(T.Stop, Q), n() || i(), v = E, c = !1;
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
return {
|
|
572
572
|
start: () => {
|
|
573
|
-
a || (a = setInterval(
|
|
573
|
+
a || (a = setInterval(z, Ee));
|
|
574
574
|
},
|
|
575
575
|
stop: () => {
|
|
576
576
|
a && (clearInterval(a), a = null);
|
|
577
577
|
},
|
|
578
|
-
getReport: () =>
|
|
578
|
+
getReport: () => Xe(s, Ee, d)
|
|
579
579
|
};
|
|
580
580
|
}
|
|
581
|
-
const
|
|
582
|
-
async function
|
|
581
|
+
const Ye = 2e4;
|
|
582
|
+
async function cn() {
|
|
583
583
|
try {
|
|
584
584
|
return await import("./livekit-client.esm-RGXA_gNu.js");
|
|
585
585
|
} catch {
|
|
@@ -588,438 +588,443 @@ async function sn() {
|
|
|
588
588
|
);
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
|
-
const
|
|
592
|
-
excellent:
|
|
593
|
-
good:
|
|
594
|
-
poor:
|
|
595
|
-
lost:
|
|
596
|
-
unknown:
|
|
597
|
-
},
|
|
591
|
+
const dn = {
|
|
592
|
+
excellent: ae.Strong,
|
|
593
|
+
good: ae.Strong,
|
|
594
|
+
poor: ae.Weak,
|
|
595
|
+
lost: ae.Unknown,
|
|
596
|
+
unknown: ae.Unknown
|
|
597
|
+
}, Re = JSON.stringify({
|
|
598
598
|
kind: "InternalServerError",
|
|
599
599
|
description: "Stream Error"
|
|
600
600
|
});
|
|
601
|
-
var
|
|
602
|
-
function
|
|
601
|
+
var Ne = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ne || {});
|
|
602
|
+
function je(e, n, i) {
|
|
603
603
|
var r, o;
|
|
604
|
-
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i,
|
|
604
|
+
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, L.Fail, "internal:init-error"), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
|
|
605
605
|
}
|
|
606
|
-
async function
|
|
607
|
-
var
|
|
608
|
-
const r =
|
|
606
|
+
async function un(e, n, i) {
|
|
607
|
+
var Ve;
|
|
608
|
+
const r = dt(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await cn(), { callbacks: t, auth: c, baseURL: h, analytics: g } = i;
|
|
609
609
|
let l = null, v = !1;
|
|
610
|
-
const
|
|
611
|
-
let
|
|
612
|
-
const
|
|
613
|
-
let M = null,
|
|
610
|
+
const P = se.Fluent;
|
|
611
|
+
let z = null;
|
|
612
|
+
const x = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
|
|
613
|
+
let M = null, E = null, Y = null, Q = !1;
|
|
614
614
|
l = new o({
|
|
615
615
|
adaptiveStream: !1,
|
|
616
616
|
// Must be false to use mediaStreamTrack directly
|
|
617
617
|
dynacast: !0
|
|
618
618
|
});
|
|
619
|
-
let
|
|
620
|
-
const
|
|
621
|
-
let
|
|
619
|
+
let J = null, te = W.Idle, ne = !0;
|
|
620
|
+
const $ = Yt(c, h || Te, e, t.onError);
|
|
621
|
+
let K, H, re, de = !0;
|
|
622
622
|
try {
|
|
623
|
-
const u = await
|
|
623
|
+
const u = await $.createStream({
|
|
624
624
|
transport: n.transport,
|
|
625
625
|
chat_persist: n.chat_persist ?? !0
|
|
626
|
-
}), { id:
|
|
627
|
-
(
|
|
626
|
+
}), { id: m, session_token: p, session_url: S, interrupt_enabled: _ } = u;
|
|
627
|
+
(Ve = t.onStreamCreated) == null || Ve.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H = p, re = S, de = _ ?? !0, await l.prepareConnection(re, H);
|
|
628
628
|
} catch (u) {
|
|
629
|
-
|
|
629
|
+
je(u, r, t);
|
|
630
630
|
}
|
|
631
|
-
if (!
|
|
631
|
+
if (!re || !H || !K)
|
|
632
632
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
633
|
-
l.on(a.ConnectionStateChanged,
|
|
634
|
-
function
|
|
635
|
-
var
|
|
636
|
-
|
|
633
|
+
l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, U).on(a.TrackUnsubscribed, w).on(a.DataReceived, N).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
|
|
634
|
+
function ue(u, m) {
|
|
635
|
+
var p;
|
|
636
|
+
m != null && m.isLocal && (oe.update(), te === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), te = W.Idle));
|
|
637
637
|
}
|
|
638
638
|
try {
|
|
639
|
-
await l.connect(
|
|
639
|
+
await l.connect(re, H), r("LiveKit room joined successfully"), J = setTimeout(() => {
|
|
640
640
|
var u;
|
|
641
641
|
r(
|
|
642
|
-
`Track subscription timeout - no track subscribed within ${
|
|
643
|
-
),
|
|
642
|
+
`Track subscription timeout - no track subscribed within ${Ye / 1e3} seconds after connect`
|
|
643
|
+
), J = null, g.track("connectivity-error", {
|
|
644
644
|
error: "Track subscription timeout",
|
|
645
|
-
sessionId:
|
|
646
|
-
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId:
|
|
647
|
-
},
|
|
645
|
+
sessionId: K
|
|
646
|
+
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: K }), be("internal:track-subscription-timeout");
|
|
647
|
+
}, Ye);
|
|
648
648
|
} catch (u) {
|
|
649
|
-
|
|
649
|
+
je(u, r, t);
|
|
650
650
|
}
|
|
651
651
|
g.enrich({
|
|
652
|
-
"stream-type":
|
|
652
|
+
"stream-type": P
|
|
653
653
|
});
|
|
654
|
-
function
|
|
655
|
-
var
|
|
654
|
+
function f(u) {
|
|
655
|
+
var m, p, S, _;
|
|
656
656
|
switch (r("Connection state changed:", u), u) {
|
|
657
657
|
case s.Connecting:
|
|
658
|
-
r("CALLBACK: onConnectionStateChange(Connecting)"), (
|
|
658
|
+
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, L.Connecting, "livekit:connecting");
|
|
659
659
|
break;
|
|
660
660
|
case s.Connected:
|
|
661
661
|
r("LiveKit room connected successfully"), v = !0;
|
|
662
662
|
break;
|
|
663
663
|
case s.Disconnected:
|
|
664
|
-
r("LiveKit room disconnected"), v = !1,
|
|
664
|
+
r("LiveKit room disconnected"), v = !1, Q = !1, x.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, L.Disconnected, "livekit:disconnected");
|
|
665
665
|
break;
|
|
666
666
|
case s.Reconnecting:
|
|
667
|
-
r("LiveKit room reconnecting..."), (
|
|
667
|
+
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, L.Connecting, "livekit:reconnecting");
|
|
668
668
|
break;
|
|
669
669
|
case s.SignalReconnecting:
|
|
670
|
-
r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t,
|
|
670
|
+
r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, L.Connecting, "livekit:signal-reconnecting");
|
|
671
671
|
break;
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
|
-
function
|
|
675
|
-
var
|
|
676
|
-
r("Connection quality:", u),
|
|
674
|
+
function C(u, m) {
|
|
675
|
+
var p;
|
|
676
|
+
r("Connection quality:", u), m != null && m.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, dn[u]));
|
|
677
677
|
}
|
|
678
|
-
function
|
|
678
|
+
function R(u) {
|
|
679
679
|
r("Participant connected:", u.identity);
|
|
680
680
|
}
|
|
681
|
-
function
|
|
682
|
-
r("Participant disconnected:", u.identity),
|
|
681
|
+
function A(u) {
|
|
682
|
+
r("Participant disconnected:", u.identity), be("livekit:participant-disconnected");
|
|
683
683
|
}
|
|
684
|
-
function
|
|
684
|
+
function I() {
|
|
685
685
|
var u;
|
|
686
|
-
|
|
686
|
+
Y !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
|
|
687
687
|
}
|
|
688
|
-
function
|
|
689
|
-
var
|
|
690
|
-
|
|
688
|
+
function b(u) {
|
|
689
|
+
var m;
|
|
690
|
+
Y !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
|
|
691
691
|
}
|
|
692
|
-
function
|
|
693
|
-
var _,
|
|
694
|
-
r(`Track subscribed: ${u.kind} from ${
|
|
695
|
-
const
|
|
696
|
-
if (!
|
|
692
|
+
function U(u, m, p) {
|
|
693
|
+
var _, j, q;
|
|
694
|
+
r(`Track subscribed: ${u.kind} from ${p.identity}`);
|
|
695
|
+
const S = u.mediaStreamTrack;
|
|
696
|
+
if (!S) {
|
|
697
697
|
r(`No mediaStreamTrack available for ${u.kind}`);
|
|
698
698
|
return;
|
|
699
699
|
}
|
|
700
|
-
|
|
700
|
+
z ? (z.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (z = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (E = nn(
|
|
701
701
|
() => u.getRTCStatsReport(),
|
|
702
|
-
({ sttLatency:
|
|
703
|
-
var
|
|
704
|
-
const
|
|
705
|
-
let
|
|
706
|
-
if (
|
|
707
|
-
const
|
|
708
|
-
|
|
702
|
+
({ sttLatency: V, serviceLatency: ie }) => {
|
|
703
|
+
var Je, Ue, Oe;
|
|
704
|
+
const ye = oe.get(!0);
|
|
705
|
+
let ve = 0;
|
|
706
|
+
if (V) {
|
|
707
|
+
const We = ((Ue = (Je = M == null ? void 0 : M.getReport()) == null ? void 0 : Je.webRTCStats) == null ? void 0 : Ue.avgRtt) ?? 0;
|
|
708
|
+
ve = We > 0 ? Math.round(We * 1e3) : 0;
|
|
709
709
|
}
|
|
710
|
-
const
|
|
711
|
-
(
|
|
710
|
+
const fe = ye > 0 ? ye + (V ?? 0) + ve : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
|
|
711
|
+
(Oe = t.onFirstAudioDetected) == null || Oe.call(t, { latency: fe, networkLatency: ce });
|
|
712
712
|
}
|
|
713
|
-
)), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (
|
|
713
|
+
)), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (j = t.onSrcObjectReady) == null || j.call(t, z), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, L.Connected, "livekit:track-subscribed")), M = lt(
|
|
714
714
|
() => u.getRTCStatsReport(),
|
|
715
715
|
() => v,
|
|
716
716
|
jt,
|
|
717
|
-
(
|
|
718
|
-
r(`Video state change: ${
|
|
717
|
+
(V, ie) => {
|
|
718
|
+
r(`Video state change: ${V}`), V === T.Start ? (J && (clearTimeout(J), J = null, r("Track subscription timeout cleared")), I()) : V === T.Stop && b(ie);
|
|
719
719
|
}
|
|
720
720
|
), M.start());
|
|
721
721
|
}
|
|
722
|
-
function
|
|
723
|
-
r(`Track unsubscribed: ${u.kind} from ${
|
|
722
|
+
function w(u, m, p) {
|
|
723
|
+
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (E == null || E.destroy(), E = null), u.kind === "video" && (b(M == null ? void 0 : M.getReport()), M == null || M.stop(), M = null);
|
|
724
724
|
}
|
|
725
|
-
function
|
|
726
|
-
var
|
|
727
|
-
const
|
|
728
|
-
|
|
725
|
+
function y(u, m) {
|
|
726
|
+
var S;
|
|
727
|
+
const p = Gt[u];
|
|
728
|
+
p && ((S = t.onMessage) == null || S.call(t, p, { event: p, ...m }));
|
|
729
729
|
}
|
|
730
|
-
function
|
|
731
|
-
var
|
|
732
|
-
if (u ===
|
|
733
|
-
|
|
730
|
+
function k(u, m) {
|
|
731
|
+
var p, S, _;
|
|
732
|
+
if (u === D.ToolCalling) {
|
|
733
|
+
te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, D.ToolCalling, m);
|
|
734
734
|
return;
|
|
735
735
|
}
|
|
736
|
-
u ===
|
|
736
|
+
u === D.ToolResult && ((_ = t.onToolEvent) == null || _.call(t, D.ToolResult, m));
|
|
737
737
|
}
|
|
738
|
-
function
|
|
739
|
-
var
|
|
740
|
-
if (
|
|
741
|
-
|
|
742
|
-
sttLatency: (
|
|
743
|
-
serviceLatency:
|
|
738
|
+
function B(u, m) {
|
|
739
|
+
var p, S, _, j, q;
|
|
740
|
+
if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === D.StreamVideoCreated) {
|
|
741
|
+
te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), E == null || E.arm({
|
|
742
|
+
sttLatency: (j = m == null ? void 0 : m.stt) == null ? void 0 : j.latency,
|
|
743
|
+
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
744
744
|
});
|
|
745
745
|
return;
|
|
746
746
|
}
|
|
747
|
-
|
|
747
|
+
ne && (te = W.Idle, (q = t.onAgentActivityStateChange) == null || q.call(t, W.Idle));
|
|
748
748
|
}
|
|
749
|
-
function
|
|
750
|
-
var
|
|
751
|
-
const
|
|
752
|
-
i.debug && ((
|
|
753
|
-
id:
|
|
754
|
-
name:
|
|
755
|
-
}), (
|
|
749
|
+
function G(u, m) {
|
|
750
|
+
var j, q, V, ie;
|
|
751
|
+
const p = ((q = (j = M == null ? void 0 : M.getReport()) == null ? void 0 : j.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: S };
|
|
752
|
+
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (_.sentiment = {
|
|
753
|
+
id: m.metadata.sentiment.id,
|
|
754
|
+
name: m.metadata.sentiment.sentiment
|
|
755
|
+
}), (ie = t.onMessage) == null || ie.call(t, u, _), B(u, m);
|
|
756
756
|
}
|
|
757
|
-
function
|
|
758
|
-
var
|
|
759
|
-
(
|
|
760
|
-
var
|
|
761
|
-
(
|
|
757
|
+
function he(u, m) {
|
|
758
|
+
var p;
|
|
759
|
+
(p = t.onMessage) == null || p.call(t, X.Transcribe, { event: X.Transcribe, ...m }), queueMicrotask(() => {
|
|
760
|
+
var S;
|
|
761
|
+
(S = t.onAgentActivityStateChange) == null || S.call(t, W.Loading);
|
|
762
762
|
});
|
|
763
763
|
}
|
|
764
|
-
const
|
|
765
|
-
[
|
|
766
|
-
[
|
|
767
|
-
[
|
|
768
|
-
[
|
|
769
|
-
[
|
|
770
|
-
[
|
|
771
|
-
[
|
|
772
|
-
[
|
|
773
|
-
[
|
|
764
|
+
const Z = {
|
|
765
|
+
[D.ChatAnswer]: y,
|
|
766
|
+
[D.ChatPartial]: y,
|
|
767
|
+
[D.ToolCalling]: k,
|
|
768
|
+
[D.ToolResult]: k,
|
|
769
|
+
[D.StreamVideoCreated]: G,
|
|
770
|
+
[D.StreamVideoDone]: G,
|
|
771
|
+
[D.StreamVideoError]: G,
|
|
772
|
+
[D.StreamVideoRejected]: G,
|
|
773
|
+
[D.ChatAudioTranscribed]: he
|
|
774
774
|
};
|
|
775
|
-
function
|
|
775
|
+
function N(u, m, p, S) {
|
|
776
776
|
const _ = new TextDecoder().decode(u);
|
|
777
777
|
try {
|
|
778
|
-
const
|
|
779
|
-
if (r("Data received:", { subject:
|
|
780
|
-
const
|
|
781
|
-
|
|
782
|
-
} catch (
|
|
783
|
-
r("Failed to parse data channel message:",
|
|
778
|
+
const j = JSON.parse(_), q = S || j.subject;
|
|
779
|
+
if (r("Data received:", { subject: q, data: j }), !q) return;
|
|
780
|
+
const V = Z[q];
|
|
781
|
+
V == null || V(q, j);
|
|
782
|
+
} catch (j) {
|
|
783
|
+
r("Failed to parse data channel message:", j);
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
|
-
function
|
|
787
|
-
var
|
|
788
|
-
r("Media devices error:", u), (
|
|
786
|
+
function ee(u) {
|
|
787
|
+
var m;
|
|
788
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
|
|
789
789
|
}
|
|
790
|
-
function
|
|
791
|
-
var
|
|
792
|
-
r("Encryption error:", u), (
|
|
790
|
+
function De(u) {
|
|
791
|
+
var m;
|
|
792
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
|
|
793
793
|
}
|
|
794
|
-
function
|
|
795
|
-
r("Track subscription failed:", { trackSid: u, participant:
|
|
794
|
+
function le(u, m, p) {
|
|
795
|
+
r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
|
|
796
796
|
}
|
|
797
|
-
function
|
|
798
|
-
for (const [
|
|
799
|
-
if (_.source ===
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
797
|
+
function ke(u, m, p) {
|
|
798
|
+
for (const [S, _] of p)
|
|
799
|
+
if (_.source === m && _.track) {
|
|
800
|
+
const j = _.track.mediaStreamTrack;
|
|
801
|
+
if (j === u || (j == null ? void 0 : j.id) === u.id)
|
|
802
802
|
return _;
|
|
803
803
|
}
|
|
804
804
|
return null;
|
|
805
805
|
}
|
|
806
|
-
async function
|
|
807
|
-
var
|
|
806
|
+
async function pe(u, m, p, S, _, j) {
|
|
807
|
+
var ye, ve, fe;
|
|
808
808
|
if (!v || !l)
|
|
809
|
-
throw r(`Room is not connected, cannot publish ${
|
|
809
|
+
throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
|
|
810
810
|
if (u.isPublishing) {
|
|
811
|
-
r(`${
|
|
811
|
+
r(`${S} publish already in progress, skipping`);
|
|
812
812
|
return;
|
|
813
813
|
}
|
|
814
|
-
const
|
|
815
|
-
if (
|
|
816
|
-
throw new Error(`No ${
|
|
817
|
-
const
|
|
818
|
-
if (
|
|
819
|
-
r(`${
|
|
820
|
-
trackId:
|
|
821
|
-
publishedTrackId: (
|
|
822
|
-
}), u.publication =
|
|
814
|
+
const q = p(m);
|
|
815
|
+
if (q.length === 0)
|
|
816
|
+
throw new Error(`No ${S} track found in the provided MediaStream`);
|
|
817
|
+
const V = q[0], ie = ke(V, S, _());
|
|
818
|
+
if (ie) {
|
|
819
|
+
r(`${S} track is already published, skipping`, {
|
|
820
|
+
trackId: V.id,
|
|
821
|
+
publishedTrackId: (ve = (ye = ie.track) == null ? void 0 : ye.mediaStreamTrack) == null ? void 0 : ve.id
|
|
822
|
+
}), u.publication = ie;
|
|
823
823
|
return;
|
|
824
824
|
}
|
|
825
|
-
if ((
|
|
826
|
-
const
|
|
827
|
-
|
|
825
|
+
if ((fe = u.publication) != null && fe.track) {
|
|
826
|
+
const ce = u.publication.track.mediaStreamTrack;
|
|
827
|
+
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await j());
|
|
828
828
|
}
|
|
829
|
-
r(`Publishing ${
|
|
829
|
+
r(`Publishing ${S} track from provided MediaStream`, { trackId: V.id }), u.isPublishing = !0;
|
|
830
830
|
try {
|
|
831
|
-
u.publication = await l.localParticipant.publishTrack(
|
|
832
|
-
} catch (
|
|
833
|
-
throw r(`Failed to publish ${
|
|
831
|
+
u.publication = await l.localParticipant.publishTrack(V, { source: S }), r(`${S} track published successfully`, { trackSid: u.publication.trackSid });
|
|
832
|
+
} catch (ce) {
|
|
833
|
+
throw r(`Failed to publish ${S} track:`, ce), ce;
|
|
834
834
|
} finally {
|
|
835
835
|
u.isPublishing = !1;
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
|
-
async function
|
|
838
|
+
async function we(u, m) {
|
|
839
839
|
if (!(!u.publication || !u.publication.track))
|
|
840
840
|
try {
|
|
841
|
-
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${
|
|
842
|
-
} catch (
|
|
843
|
-
r(`Error unpublishing ${
|
|
841
|
+
l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${m} track unpublished`));
|
|
842
|
+
} catch (p) {
|
|
843
|
+
r(`Error unpublishing ${m} track:`, p);
|
|
844
844
|
} finally {
|
|
845
845
|
u.publication = null;
|
|
846
846
|
}
|
|
847
847
|
}
|
|
848
|
-
async function
|
|
849
|
-
return
|
|
850
|
-
|
|
848
|
+
async function ft(u) {
|
|
849
|
+
return pe(
|
|
850
|
+
x,
|
|
851
851
|
u,
|
|
852
|
-
(
|
|
852
|
+
(m) => m.getAudioTracks(),
|
|
853
853
|
d.Source.Microphone,
|
|
854
854
|
() => l.localParticipant.audioTrackPublications,
|
|
855
|
-
|
|
855
|
+
Ie
|
|
856
856
|
);
|
|
857
857
|
}
|
|
858
|
-
async function
|
|
859
|
-
return
|
|
858
|
+
async function Ie() {
|
|
859
|
+
return we(x, "Microphone");
|
|
860
860
|
}
|
|
861
861
|
async function mt(u) {
|
|
862
|
-
return
|
|
863
|
-
|
|
862
|
+
return pe(
|
|
863
|
+
F,
|
|
864
864
|
u,
|
|
865
|
-
(
|
|
865
|
+
(m) => m.getVideoTracks(),
|
|
866
866
|
d.Source.Camera,
|
|
867
867
|
() => l.localParticipant.videoTrackPublications,
|
|
868
|
-
|
|
868
|
+
Ae
|
|
869
869
|
);
|
|
870
870
|
}
|
|
871
|
-
async function
|
|
872
|
-
return
|
|
871
|
+
async function Ae() {
|
|
872
|
+
return we(F, "Camera");
|
|
873
873
|
}
|
|
874
|
-
function
|
|
875
|
-
|
|
874
|
+
function gt() {
|
|
875
|
+
z && (z.getTracks().forEach((u) => u.stop()), z = null);
|
|
876
876
|
}
|
|
877
|
-
async function
|
|
878
|
-
var
|
|
877
|
+
async function _e(u, m) {
|
|
878
|
+
var p, S;
|
|
879
879
|
if (!v || !l) {
|
|
880
|
-
r("Room is not connected for sending messages"), (
|
|
881
|
-
sessionId:
|
|
880
|
+
r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(Re), {
|
|
881
|
+
sessionId: K
|
|
882
882
|
});
|
|
883
883
|
return;
|
|
884
884
|
}
|
|
885
885
|
try {
|
|
886
|
-
await l.localParticipant.sendText(u, { topic:
|
|
886
|
+
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
887
887
|
} catch (_) {
|
|
888
|
-
r("Failed to send message:", _), (
|
|
888
|
+
r("Failed to send message:", _), (S = t.onError) == null || S.call(t, new Error(Re), { sessionId: K });
|
|
889
889
|
}
|
|
890
890
|
}
|
|
891
|
-
async function
|
|
892
|
-
var
|
|
891
|
+
async function ht(u) {
|
|
892
|
+
var m;
|
|
893
893
|
try {
|
|
894
|
-
const
|
|
895
|
-
return
|
|
896
|
-
} catch (
|
|
897
|
-
r("Failed to send data channel message:",
|
|
894
|
+
const S = JSON.parse(u).topic;
|
|
895
|
+
return _e("", S);
|
|
896
|
+
} catch (p) {
|
|
897
|
+
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
|
-
function
|
|
901
|
-
return
|
|
900
|
+
function pt(u) {
|
|
901
|
+
return _e(
|
|
902
902
|
u,
|
|
903
903
|
"lk.chat"
|
|
904
904
|
/* Chat */
|
|
905
905
|
);
|
|
906
906
|
}
|
|
907
|
-
async function
|
|
908
|
-
var
|
|
909
|
-
|
|
907
|
+
async function be(u) {
|
|
908
|
+
var m, p;
|
|
909
|
+
J && (clearTimeout(J), J = null), E == null || E.destroy(), E = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, L.Disconnecting, u), await Promise.all([Ie(), Ae()]), await l.disconnect()), gt(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
|
|
910
910
|
}
|
|
911
911
|
return {
|
|
912
912
|
speak(u) {
|
|
913
|
-
const
|
|
914
|
-
return
|
|
915
|
-
|
|
913
|
+
const m = typeof u == "string" ? u : JSON.stringify(u);
|
|
914
|
+
return _e(
|
|
915
|
+
m,
|
|
916
916
|
"did.speak"
|
|
917
917
|
/* Speak */
|
|
918
918
|
);
|
|
919
919
|
},
|
|
920
|
-
disconnect: () =>
|
|
920
|
+
disconnect: () => be("user:disconnect"),
|
|
921
921
|
async reconnect() {
|
|
922
|
-
var u,
|
|
922
|
+
var u, m;
|
|
923
923
|
if ((l == null ? void 0 : l.state) === s.Connected) {
|
|
924
924
|
r("Room is already connected");
|
|
925
925
|
return;
|
|
926
926
|
}
|
|
927
|
-
if (!l || !
|
|
927
|
+
if (!l || !re || !H)
|
|
928
928
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
929
|
-
r("Reconnecting to LiveKit room, state:", l.state),
|
|
929
|
+
r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, L.Connecting, "user:reconnect");
|
|
930
930
|
try {
|
|
931
|
-
if (await l.connect(
|
|
932
|
-
if (r("Waiting for agent to join..."), !await new Promise((
|
|
931
|
+
if (await l.connect(re, H), r("Room reconnected"), v = !0, l.remoteParticipants.size === 0) {
|
|
932
|
+
if (r("Waiting for agent to join..."), !await new Promise((S) => {
|
|
933
933
|
const _ = setTimeout(() => {
|
|
934
|
-
l == null || l.off(a.ParticipantConnected,
|
|
935
|
-
}, 5e3),
|
|
936
|
-
clearTimeout(_), l == null || l.off(a.ParticipantConnected,
|
|
934
|
+
l == null || l.off(a.ParticipantConnected, j), S(!1);
|
|
935
|
+
}, 5e3), j = () => {
|
|
936
|
+
clearTimeout(_), l == null || l.off(a.ParticipantConnected, j), S(!0);
|
|
937
937
|
};
|
|
938
|
-
l == null || l.on(a.ParticipantConnected,
|
|
938
|
+
l == null || l.on(a.ParticipantConnected, j);
|
|
939
939
|
}))
|
|
940
940
|
throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
|
|
941
941
|
r("Agent joined, reconnection successful");
|
|
942
942
|
}
|
|
943
|
-
} catch (
|
|
944
|
-
throw r("Failed to reconnect:",
|
|
943
|
+
} catch (p) {
|
|
944
|
+
throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, L.Fail, "user:reconnect-failed"), p;
|
|
945
945
|
}
|
|
946
946
|
},
|
|
947
|
-
sendDataChannelMessage:
|
|
948
|
-
sendTextMessage:
|
|
949
|
-
publishMicrophoneStream:
|
|
950
|
-
unpublishMicrophoneStream:
|
|
947
|
+
sendDataChannelMessage: ht,
|
|
948
|
+
sendTextMessage: pt,
|
|
949
|
+
publishMicrophoneStream: ft,
|
|
950
|
+
unpublishMicrophoneStream: Ie,
|
|
951
951
|
publishCameraStream: mt,
|
|
952
|
-
unpublishCameraStream:
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
952
|
+
unpublishCameraStream: Ae,
|
|
953
|
+
registerRpcMethod(u, m) {
|
|
954
|
+
l == null || l.registerRpcMethod(u, m);
|
|
955
|
+
},
|
|
956
|
+
unregisterRpcMethod(u) {
|
|
957
|
+
l == null || l.unregisterRpcMethod(u);
|
|
958
|
+
},
|
|
959
|
+
sessionId: K,
|
|
960
|
+
streamId: K,
|
|
961
|
+
streamType: P,
|
|
962
|
+
interruptAvailable: de,
|
|
963
|
+
isInterruptible: ne
|
|
959
964
|
};
|
|
960
965
|
}
|
|
961
|
-
const
|
|
966
|
+
const ln = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
962
967
|
__proto__: null,
|
|
963
|
-
DataChannelTopic:
|
|
964
|
-
createLiveKitStreamingManager:
|
|
965
|
-
handleInitError:
|
|
968
|
+
DataChannelTopic: Ne,
|
|
969
|
+
createLiveKitStreamingManager: un,
|
|
970
|
+
handleInitError: je
|
|
966
971
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
967
|
-
function
|
|
972
|
+
function fn(e, n, i) {
|
|
968
973
|
if (!e)
|
|
969
974
|
throw new Error("Please connect to the agent first");
|
|
970
975
|
if (!e.interruptAvailable)
|
|
971
976
|
throw new Error("Interrupt is not enabled for this stream");
|
|
972
|
-
if (n !==
|
|
977
|
+
if (n !== se.Fluent)
|
|
973
978
|
throw new Error("Interrupt only available for Fluent streams");
|
|
974
979
|
if (!i)
|
|
975
980
|
throw new Error("No active video to interrupt");
|
|
976
981
|
}
|
|
977
982
|
async function mn(e, n) {
|
|
978
983
|
const i = {
|
|
979
|
-
type:
|
|
984
|
+
type: D.StreamInterrupt,
|
|
980
985
|
videoId: n,
|
|
981
986
|
timestamp: Date.now()
|
|
982
987
|
};
|
|
983
988
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
984
989
|
}
|
|
985
|
-
async function
|
|
990
|
+
async function gn(e) {
|
|
986
991
|
const n = {
|
|
987
|
-
topic:
|
|
992
|
+
topic: Ne.Interrupt
|
|
988
993
|
};
|
|
989
994
|
e.sendDataChannelMessage(JSON.stringify(n));
|
|
990
995
|
}
|
|
991
|
-
function
|
|
996
|
+
function hn(e) {
|
|
992
997
|
return new Promise((n, i) => {
|
|
993
|
-
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError:
|
|
998
|
+
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: h = null } = r || {}, g = new WebSocket(`${o}?authorization=${encodeURIComponent(ot(a, s))}`);
|
|
994
999
|
g.onmessage = d, g.onclose = c, g.onerror = (l) => {
|
|
995
|
-
console.error(l),
|
|
1000
|
+
console.error(l), h == null || h("Websocket failed to connect", l), i(l);
|
|
996
1001
|
}, g.onopen = (l) => {
|
|
997
1002
|
t == null || t(l), n(g);
|
|
998
1003
|
};
|
|
999
1004
|
});
|
|
1000
1005
|
}
|
|
1001
|
-
async function
|
|
1006
|
+
async function pn(e) {
|
|
1002
1007
|
const { retries: n = 1 } = e;
|
|
1003
1008
|
let i = null;
|
|
1004
1009
|
for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
|
|
1005
1010
|
try {
|
|
1006
|
-
i = await
|
|
1011
|
+
i = await hn(e);
|
|
1007
1012
|
} catch (o) {
|
|
1008
1013
|
if (r === n)
|
|
1009
1014
|
throw o;
|
|
1010
|
-
await
|
|
1015
|
+
await rt(r * 500);
|
|
1011
1016
|
}
|
|
1012
1017
|
return i;
|
|
1013
1018
|
}
|
|
1014
|
-
async function
|
|
1015
|
-
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await
|
|
1019
|
+
async function wn(e, n, i, r) {
|
|
1020
|
+
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await pn({
|
|
1016
1021
|
auth: e,
|
|
1017
1022
|
host: n,
|
|
1018
1023
|
externalId: r,
|
|
1019
1024
|
callbacks: {
|
|
1020
1025
|
onError: (s) => {
|
|
1021
1026
|
var d;
|
|
1022
|
-
return (d = i.onError) == null ? void 0 : d.call(i, new
|
|
1027
|
+
return (d = i.onError) == null ? void 0 : d.call(i, new St(s));
|
|
1023
1028
|
},
|
|
1024
1029
|
onMessage(s) {
|
|
1025
1030
|
const d = JSON.parse(s.data);
|
|
@@ -1033,7 +1038,7 @@ async function pn(e, n, i, r) {
|
|
|
1033
1038
|
subscribeToEvents: (s) => o.push(s)
|
|
1034
1039
|
};
|
|
1035
1040
|
}
|
|
1036
|
-
function
|
|
1041
|
+
function yn(e) {
|
|
1037
1042
|
if (e.answer !== void 0)
|
|
1038
1043
|
return e.answer;
|
|
1039
1044
|
let n = 0, i = "";
|
|
@@ -1041,7 +1046,7 @@ function wn(e) {
|
|
|
1041
1046
|
i += e[n++];
|
|
1042
1047
|
return i;
|
|
1043
1048
|
}
|
|
1044
|
-
function
|
|
1049
|
+
function vn(e, n, i) {
|
|
1045
1050
|
if (!e.content)
|
|
1046
1051
|
return;
|
|
1047
1052
|
const r = n.messages[n.messages.length - 1];
|
|
@@ -1055,17 +1060,17 @@ function yn(e, n, i) {
|
|
|
1055
1060
|
};
|
|
1056
1061
|
n.messages.push(o), i == null || i([...n.messages], "user");
|
|
1057
1062
|
}
|
|
1058
|
-
function
|
|
1059
|
-
if (e ===
|
|
1060
|
-
|
|
1063
|
+
function Cn(e, n, i, r, o) {
|
|
1064
|
+
if (e === X.Transcribe && n.content) {
|
|
1065
|
+
vn(n, r, o);
|
|
1061
1066
|
return;
|
|
1062
1067
|
}
|
|
1063
|
-
if (!(e ===
|
|
1068
|
+
if (!(e === X.Partial || e === X.Answer))
|
|
1064
1069
|
return;
|
|
1065
1070
|
const a = r.messages[r.messages.length - 1];
|
|
1066
1071
|
let s;
|
|
1067
1072
|
if (a != null && a.transcribed && a.role === "user")
|
|
1068
|
-
e ===
|
|
1073
|
+
e === X.Answer && n.content, s = {
|
|
1069
1074
|
id: n.id || `assistant-${Date.now()}`,
|
|
1070
1075
|
role: n.role || "assistant",
|
|
1071
1076
|
content: n.content || "",
|
|
@@ -1076,49 +1081,49 @@ function vn(e, n, i, r, o) {
|
|
|
1076
1081
|
else
|
|
1077
1082
|
return;
|
|
1078
1083
|
const { content: d, sequence: t } = n;
|
|
1079
|
-
e ===
|
|
1080
|
-
const c =
|
|
1081
|
-
(s.content !== c || e ===
|
|
1084
|
+
e === X.Partial ? i[t] = d : i.answer = d;
|
|
1085
|
+
const c = yn(i);
|
|
1086
|
+
(s.content !== c || e === X.Answer) && (s.content = c, o == null || o([...r.messages], e));
|
|
1082
1087
|
}
|
|
1083
|
-
function
|
|
1088
|
+
function Sn(e, n, i, r, o) {
|
|
1084
1089
|
let a = {};
|
|
1085
1090
|
const s = () => a = {};
|
|
1086
1091
|
let d = "answer";
|
|
1087
|
-
const t = (c,
|
|
1092
|
+
const t = (c, h) => {
|
|
1088
1093
|
var g, l;
|
|
1089
|
-
|
|
1094
|
+
h === "user" && s(), d = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, h);
|
|
1090
1095
|
};
|
|
1091
1096
|
return {
|
|
1092
1097
|
clearQueue: s,
|
|
1093
|
-
onMessage: (c,
|
|
1098
|
+
onMessage: (c, h) => {
|
|
1094
1099
|
var g, l;
|
|
1095
|
-
if ("content" in
|
|
1096
|
-
const v = c ===
|
|
1097
|
-
|
|
1098
|
-
content:
|
|
1100
|
+
if ("content" in h) {
|
|
1101
|
+
const v = c === D.ChatAnswer ? X.Answer : c === D.ChatAudioTranscribed ? X.Transcribe : c;
|
|
1102
|
+
Cn(v, h, a, n, t), v === X.Answer && e.track("agent-message-received", {
|
|
1103
|
+
content: h.content,
|
|
1099
1104
|
messages: n.messages.length,
|
|
1100
1105
|
mode: n.chatMode
|
|
1101
1106
|
});
|
|
1102
1107
|
} else {
|
|
1103
|
-
const v =
|
|
1104
|
-
if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video",
|
|
1105
|
-
const
|
|
1106
|
-
if ((
|
|
1107
|
-
const M = { ...
|
|
1108
|
+
const v = D, P = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], z = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], x = Wt(h, r, { mode: n.chatMode });
|
|
1109
|
+
if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", x, v.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1110
|
+
const F = n.messages[n.messages.length - 1];
|
|
1111
|
+
if ((F == null ? void 0 : F.role) === "assistant") {
|
|
1112
|
+
const M = { ...F, sentiment: h.sentiment };
|
|
1108
1113
|
n.messages[n.messages.length - 1] = M, t == null || t([...n.messages], d);
|
|
1109
1114
|
}
|
|
1110
1115
|
}
|
|
1111
|
-
if (
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1116
|
+
if (P.includes(c)) {
|
|
1117
|
+
const F = c.split("/")[1];
|
|
1118
|
+
z.includes(c) ? e.track("agent-video", { ...x, event: F }) : e.linkTrack("agent-video", { ...x, event: F }, c, ["done"]);
|
|
1114
1119
|
}
|
|
1115
|
-
|
|
1120
|
+
z.includes(c) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${c}`), { data: h })), h.event === v.StreamDone && o();
|
|
1116
1121
|
}
|
|
1117
1122
|
}
|
|
1118
1123
|
};
|
|
1119
1124
|
}
|
|
1120
|
-
function
|
|
1121
|
-
const o =
|
|
1125
|
+
function Rn(e, n, i, r) {
|
|
1126
|
+
const o = ze(e, `${n}/agents/${i}`, r);
|
|
1122
1127
|
return {
|
|
1123
1128
|
createStream(a, s) {
|
|
1124
1129
|
return o.post("/streams", a, { signal: s });
|
|
@@ -1154,28 +1159,28 @@ function Sn(e, n, i, r) {
|
|
|
1154
1159
|
}
|
|
1155
1160
|
};
|
|
1156
1161
|
}
|
|
1157
|
-
const
|
|
1158
|
-
function
|
|
1162
|
+
const Tn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1163
|
+
function Ge(e) {
|
|
1159
1164
|
switch (e) {
|
|
1160
1165
|
case "connected":
|
|
1161
|
-
return
|
|
1166
|
+
return L.Connected;
|
|
1162
1167
|
case "checking":
|
|
1163
|
-
return
|
|
1168
|
+
return L.Connecting;
|
|
1164
1169
|
case "failed":
|
|
1165
|
-
return
|
|
1170
|
+
return L.Fail;
|
|
1166
1171
|
case "new":
|
|
1167
|
-
return
|
|
1172
|
+
return L.New;
|
|
1168
1173
|
case "closed":
|
|
1169
|
-
return
|
|
1174
|
+
return L.Closed;
|
|
1170
1175
|
case "disconnected":
|
|
1171
|
-
return
|
|
1176
|
+
return L.Disconnected;
|
|
1172
1177
|
case "completed":
|
|
1173
|
-
return
|
|
1178
|
+
return L.Completed;
|
|
1174
1179
|
default:
|
|
1175
|
-
return
|
|
1180
|
+
return L.New;
|
|
1176
1181
|
}
|
|
1177
1182
|
}
|
|
1178
|
-
const
|
|
1183
|
+
const kn = (e) => (n) => {
|
|
1179
1184
|
const [i, r = ""] = n.split(/:(.+)/);
|
|
1180
1185
|
try {
|
|
1181
1186
|
const o = JSON.parse(r);
|
|
@@ -1184,7 +1189,7 @@ const Tn = (e) => (n) => {
|
|
|
1184
1189
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: o }), { subject: i, data: r };
|
|
1185
1190
|
}
|
|
1186
1191
|
};
|
|
1187
|
-
function
|
|
1192
|
+
function En({
|
|
1188
1193
|
statsSignal: e,
|
|
1189
1194
|
dataChannelSignal: n,
|
|
1190
1195
|
onVideoStateChange: i,
|
|
@@ -1193,7 +1198,7 @@ function kn({
|
|
|
1193
1198
|
}) {
|
|
1194
1199
|
e === T.Start && n === T.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && n === T.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, r));
|
|
1195
1200
|
}
|
|
1196
|
-
function
|
|
1201
|
+
function Mn({
|
|
1197
1202
|
statsSignal: e,
|
|
1198
1203
|
dataChannelSignal: n,
|
|
1199
1204
|
onVideoStateChange: i,
|
|
@@ -1201,9 +1206,9 @@ function En({
|
|
|
1201
1206
|
report: o,
|
|
1202
1207
|
log: a
|
|
1203
1208
|
}) {
|
|
1204
|
-
e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(
|
|
1209
|
+
e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(W.Talking) : n === T.Stop && (r == null || r(W.Idle));
|
|
1205
1210
|
}
|
|
1206
|
-
function
|
|
1211
|
+
function Ze({
|
|
1207
1212
|
statsSignal: e,
|
|
1208
1213
|
dataChannelSignal: n,
|
|
1209
1214
|
onVideoStateChange: i,
|
|
@@ -1212,7 +1217,7 @@ function Xe({
|
|
|
1212
1217
|
report: a,
|
|
1213
1218
|
log: s
|
|
1214
1219
|
}) {
|
|
1215
|
-
o ===
|
|
1220
|
+
o === se.Legacy ? En({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === se.Fluent && Mn({
|
|
1216
1221
|
statsSignal: e,
|
|
1217
1222
|
dataChannelSignal: n,
|
|
1218
1223
|
onVideoStateChange: i,
|
|
@@ -1221,178 +1226,176 @@ function Xe({
|
|
|
1221
1226
|
log: s
|
|
1222
1227
|
});
|
|
1223
1228
|
}
|
|
1224
|
-
async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a =
|
|
1225
|
-
var
|
|
1226
|
-
const t =
|
|
1227
|
-
let
|
|
1228
|
-
const { startConnection:
|
|
1229
|
+
async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te, analytics: s }, d) {
|
|
1230
|
+
var U;
|
|
1231
|
+
const t = dt(i, "WebRTCStreamingManager"), c = kn(t);
|
|
1232
|
+
let h = !1, g = !1, l = T.Stop, v = T.Stop;
|
|
1233
|
+
const { startConnection: P, sendStreamRequest: z, close: x, createStream: F, addIceCandidate: M } = Rn(
|
|
1229
1234
|
o,
|
|
1230
1235
|
a,
|
|
1231
1236
|
e,
|
|
1232
1237
|
r.onError
|
|
1233
1238
|
), {
|
|
1234
|
-
id:
|
|
1235
|
-
offer:
|
|
1236
|
-
ice_servers:
|
|
1237
|
-
session_id:
|
|
1238
|
-
fluent:
|
|
1239
|
-
interrupt_enabled:
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
if (!F)
|
|
1239
|
+
id: E,
|
|
1240
|
+
offer: Y,
|
|
1241
|
+
ice_servers: Q,
|
|
1242
|
+
session_id: J,
|
|
1243
|
+
fluent: te,
|
|
1244
|
+
interrupt_enabled: ne
|
|
1245
|
+
} = await F(n, d);
|
|
1246
|
+
(U = r.onStreamCreated) == null || U.call(r, { stream_id: E, session_id: J, agent_id: e });
|
|
1247
|
+
const $ = new Tn({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
|
|
1248
|
+
if (!J)
|
|
1245
1249
|
throw new Error("Could not create session_id");
|
|
1246
|
-
const
|
|
1250
|
+
const H = te ? se.Fluent : se.Legacy;
|
|
1247
1251
|
s.enrich({
|
|
1248
|
-
"stream-type":
|
|
1252
|
+
"stream-type": H
|
|
1249
1253
|
});
|
|
1250
|
-
const
|
|
1251
|
-
var
|
|
1252
|
-
|
|
1253
|
-
},
|
|
1254
|
-
() =>
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
(
|
|
1258
|
-
statsSignal: v =
|
|
1259
|
-
dataChannelSignal:
|
|
1254
|
+
const re = n.stream_warmup && !te, de = () => h, ue = () => {
|
|
1255
|
+
var w;
|
|
1256
|
+
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, L.Connected));
|
|
1257
|
+
}, f = lt(
|
|
1258
|
+
() => $.getStats(),
|
|
1259
|
+
de,
|
|
1260
|
+
ue,
|
|
1261
|
+
(w, y) => Ze({
|
|
1262
|
+
statsSignal: v = w,
|
|
1263
|
+
dataChannelSignal: H === se.Legacy ? l : void 0,
|
|
1260
1264
|
onVideoStateChange: r.onVideoStateChange,
|
|
1261
1265
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1262
|
-
report:
|
|
1263
|
-
streamType:
|
|
1266
|
+
report: y,
|
|
1267
|
+
streamType: H,
|
|
1264
1268
|
log: t
|
|
1265
1269
|
}),
|
|
1266
|
-
(
|
|
1267
|
-
var
|
|
1268
|
-
return (
|
|
1270
|
+
(w) => {
|
|
1271
|
+
var y;
|
|
1272
|
+
return (y = r.onConnectivityStateChange) == null ? void 0 : y.call(r, w);
|
|
1269
1273
|
}
|
|
1270
1274
|
);
|
|
1271
|
-
|
|
1272
|
-
var
|
|
1273
|
-
t("peerConnection.onicecandidate",
|
|
1275
|
+
f.start(), $.onicecandidate = (w) => {
|
|
1276
|
+
var y;
|
|
1277
|
+
t("peerConnection.onicecandidate", w);
|
|
1274
1278
|
try {
|
|
1275
|
-
|
|
1276
|
-
|
|
1279
|
+
w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? M(
|
|
1280
|
+
E,
|
|
1277
1281
|
{
|
|
1278
|
-
candidate:
|
|
1279
|
-
sdpMid:
|
|
1280
|
-
sdpMLineIndex:
|
|
1282
|
+
candidate: w.candidate.candidate,
|
|
1283
|
+
sdpMid: w.candidate.sdpMid,
|
|
1284
|
+
sdpMLineIndex: w.candidate.sdpMLineIndex
|
|
1281
1285
|
},
|
|
1282
|
-
|
|
1286
|
+
J,
|
|
1283
1287
|
d
|
|
1284
|
-
) : M(
|
|
1285
|
-
} catch (
|
|
1286
|
-
(
|
|
1288
|
+
) : M(E, { candidate: null }, J, d);
|
|
1289
|
+
} catch (k) {
|
|
1290
|
+
(y = r.onError) == null || y.call(r, k, { streamId: E });
|
|
1287
1291
|
}
|
|
1288
|
-
},
|
|
1289
|
-
g = !0, (!
|
|
1292
|
+
}, K.onopen = () => {
|
|
1293
|
+
g = !0, (!re || h) && ue();
|
|
1290
1294
|
};
|
|
1291
|
-
const
|
|
1292
|
-
var
|
|
1293
|
-
(
|
|
1295
|
+
const C = (w) => {
|
|
1296
|
+
var y;
|
|
1297
|
+
(y = r.onVideoIdChange) == null || y.call(r, w);
|
|
1294
1298
|
};
|
|
1295
|
-
function
|
|
1296
|
-
if (
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
+
function R(w, y) {
|
|
1300
|
+
if (w === D.StreamStarted && typeof y == "object" && "metadata" in y) {
|
|
1301
|
+
const k = y.metadata;
|
|
1302
|
+
C(k.videoId);
|
|
1299
1303
|
}
|
|
1300
|
-
|
|
1301
|
-
statsSignal:
|
|
1304
|
+
w === D.StreamDone && C(null), l = w === D.StreamStarted ? T.Start : T.Stop, Ze({
|
|
1305
|
+
statsSignal: H === se.Legacy ? v : void 0,
|
|
1302
1306
|
dataChannelSignal: l,
|
|
1303
1307
|
onVideoStateChange: r.onVideoStateChange,
|
|
1304
1308
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1305
|
-
streamType:
|
|
1309
|
+
streamType: H,
|
|
1306
1310
|
log: t
|
|
1307
1311
|
});
|
|
1308
1312
|
}
|
|
1309
|
-
function
|
|
1310
|
-
var
|
|
1311
|
-
const
|
|
1312
|
-
|
|
1313
|
+
function A(w, y) {
|
|
1314
|
+
var B;
|
|
1315
|
+
const k = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
|
|
1316
|
+
k && s.enrich({ streamMetadata: k }), (B = r.onStreamReady) == null || B.call(r);
|
|
1313
1317
|
}
|
|
1314
|
-
const
|
|
1315
|
-
[
|
|
1316
|
-
[
|
|
1317
|
-
[
|
|
1318
|
+
const I = {
|
|
1319
|
+
[D.StreamStarted]: R,
|
|
1320
|
+
[D.StreamDone]: R,
|
|
1321
|
+
[D.StreamReady]: A
|
|
1318
1322
|
};
|
|
1319
|
-
|
|
1320
|
-
var
|
|
1321
|
-
const { subject:
|
|
1322
|
-
(
|
|
1323
|
-
},
|
|
1324
|
-
var
|
|
1325
|
-
t("peerConnection.oniceconnectionstatechange => " +
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1328
|
-
},
|
|
1329
|
-
var
|
|
1330
|
-
t("peerConnection.ontrack",
|
|
1331
|
-
}, await
|
|
1332
|
-
const
|
|
1333
|
-
return t("create answer OK"), await
|
|
1323
|
+
K.onmessage = (w) => {
|
|
1324
|
+
var B;
|
|
1325
|
+
const { subject: y, data: k } = c(w.data);
|
|
1326
|
+
(B = I[y]) == null || B.call(I, y, k);
|
|
1327
|
+
}, $.oniceconnectionstatechange = () => {
|
|
1328
|
+
var y;
|
|
1329
|
+
t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
|
|
1330
|
+
const w = Ge($.iceConnectionState);
|
|
1331
|
+
w !== L.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
|
|
1332
|
+
}, $.ontrack = (w) => {
|
|
1333
|
+
var y;
|
|
1334
|
+
t("peerConnection.ontrack", w), t("CALLBACK: onSrcObjectReady"), (y = r.onSrcObjectReady) == null || y.call(r, w.streams[0]);
|
|
1335
|
+
}, await $.setRemoteDescription(Y), t("set remote description OK");
|
|
1336
|
+
const b = await $.createAnswer();
|
|
1337
|
+
return t("create answer OK"), await $.setLocalDescription(b), t("set local description OK"), await P(E, b, J, d), t("start connection OK"), {
|
|
1334
1338
|
/**
|
|
1335
1339
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1336
1340
|
* @param payload
|
|
1337
1341
|
*/
|
|
1338
|
-
speak(
|
|
1339
|
-
return
|
|
1342
|
+
speak(w) {
|
|
1343
|
+
return z(E, J, w);
|
|
1340
1344
|
},
|
|
1341
1345
|
/**
|
|
1342
1346
|
* Method to close RTC connection
|
|
1343
1347
|
*/
|
|
1344
1348
|
async disconnect() {
|
|
1345
|
-
var
|
|
1346
|
-
if (
|
|
1347
|
-
const
|
|
1348
|
-
if (
|
|
1349
|
-
if (
|
|
1350
|
-
|
|
1349
|
+
var w;
|
|
1350
|
+
if (E) {
|
|
1351
|
+
const y = Ge($.iceConnectionState);
|
|
1352
|
+
if ($) {
|
|
1353
|
+
if (y === L.New) {
|
|
1354
|
+
f.stop();
|
|
1351
1355
|
return;
|
|
1352
1356
|
}
|
|
1353
|
-
|
|
1357
|
+
$.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
|
|
1354
1358
|
}
|
|
1355
1359
|
try {
|
|
1356
|
-
|
|
1360
|
+
y === L.Connected && await x(E, J).catch((k) => {
|
|
1357
1361
|
});
|
|
1358
|
-
} catch (
|
|
1359
|
-
t("Error on close stream connection",
|
|
1362
|
+
} catch (k) {
|
|
1363
|
+
t("Error on close stream connection", k);
|
|
1360
1364
|
}
|
|
1361
|
-
(
|
|
1365
|
+
(w = r.onAgentActivityStateChange) == null || w.call(r, W.Idle), f.stop();
|
|
1362
1366
|
}
|
|
1363
1367
|
},
|
|
1364
1368
|
/**
|
|
1365
1369
|
* Method to send data channel messages to the server
|
|
1366
1370
|
*/
|
|
1367
|
-
sendDataChannelMessage(
|
|
1368
|
-
var
|
|
1369
|
-
if (!
|
|
1370
|
-
t("Data channel is not ready for sending messages"), (
|
|
1371
|
-
streamId:
|
|
1371
|
+
sendDataChannelMessage(w) {
|
|
1372
|
+
var y, k;
|
|
1373
|
+
if (!h || K.readyState !== "open") {
|
|
1374
|
+
t("Data channel is not ready for sending messages"), (y = r.onError) == null || y.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1375
|
+
streamId: E
|
|
1372
1376
|
});
|
|
1373
1377
|
return;
|
|
1374
1378
|
}
|
|
1375
1379
|
try {
|
|
1376
|
-
|
|
1377
|
-
} catch (
|
|
1378
|
-
t("Error sending data channel message",
|
|
1380
|
+
K.send(w);
|
|
1381
|
+
} catch (B) {
|
|
1382
|
+
t("Error sending data channel message", B), (k = r.onError) == null || k.call(r, B, { streamId: E });
|
|
1379
1383
|
}
|
|
1380
1384
|
},
|
|
1381
1385
|
/**
|
|
1382
1386
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1383
1387
|
*/
|
|
1384
|
-
sessionId:
|
|
1388
|
+
sessionId: J,
|
|
1385
1389
|
/**
|
|
1386
1390
|
* Id of current RTC stream
|
|
1387
1391
|
*/
|
|
1388
|
-
streamId:
|
|
1389
|
-
streamType:
|
|
1390
|
-
interruptAvailable:
|
|
1391
|
-
isInterruptible: !0
|
|
1392
|
-
triggersAvailable: se ?? !1
|
|
1392
|
+
streamId: E,
|
|
1393
|
+
streamType: H,
|
|
1394
|
+
interruptAvailable: ne ?? !1,
|
|
1395
|
+
isInterruptible: !0
|
|
1393
1396
|
};
|
|
1394
1397
|
}
|
|
1395
|
-
var
|
|
1398
|
+
var xe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(xe || {});
|
|
1396
1399
|
async function In(e, n, i, r) {
|
|
1397
1400
|
const o = e.id;
|
|
1398
1401
|
switch (n.version) {
|
|
@@ -1403,8 +1406,8 @@ async function In(e, n, i, r) {
|
|
|
1403
1406
|
case "v2": {
|
|
1404
1407
|
const { version: a, ...s } = n;
|
|
1405
1408
|
switch (s.transport.provider) {
|
|
1406
|
-
case
|
|
1407
|
-
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() =>
|
|
1409
|
+
case Be.Livekit:
|
|
1410
|
+
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => ln);
|
|
1408
1411
|
return d(o, s, i);
|
|
1409
1412
|
default:
|
|
1410
1413
|
throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
|
|
@@ -1414,15 +1417,15 @@ async function In(e, n, i, r) {
|
|
|
1414
1417
|
throw new Error(`Invalid stream version: ${n.version}`);
|
|
1415
1418
|
}
|
|
1416
1419
|
}
|
|
1417
|
-
const
|
|
1418
|
-
function
|
|
1420
|
+
const An = "cht";
|
|
1421
|
+
function _n() {
|
|
1419
1422
|
return {
|
|
1420
1423
|
transport: {
|
|
1421
|
-
provider:
|
|
1424
|
+
provider: Be.Livekit
|
|
1422
1425
|
}
|
|
1423
1426
|
};
|
|
1424
1427
|
}
|
|
1425
|
-
function
|
|
1428
|
+
function bn(e) {
|
|
1426
1429
|
var o, a;
|
|
1427
1430
|
const { streamOptions: n } = e ?? {}, i = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
|
|
1428
1431
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1435,14 +1438,14 @@ function _n(e) {
|
|
|
1435
1438
|
fluent: n == null ? void 0 : n.fluent
|
|
1436
1439
|
}, ...i && { end_user_data: i } };
|
|
1437
1440
|
}
|
|
1438
|
-
function
|
|
1439
|
-
return
|
|
1441
|
+
function Pn(e, n) {
|
|
1442
|
+
return Fe(e.presenter.type) ? { version: xe.V2, ..._n() } : { version: xe.V1, ...bn(n) };
|
|
1440
1443
|
}
|
|
1441
|
-
function
|
|
1444
|
+
function Ln(e, n, i) {
|
|
1442
1445
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
1443
1446
|
}
|
|
1444
|
-
function
|
|
1445
|
-
o ===
|
|
1447
|
+
function $n(e, n, i, r, o) {
|
|
1448
|
+
o === se.Fluent ? jn(e, n, i, r, o) : xn(e, n, i, r, o);
|
|
1446
1449
|
}
|
|
1447
1450
|
function jn(e, n, i, r, o) {
|
|
1448
1451
|
e === T.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === T.Stop && r.track("stream-session", {
|
|
@@ -1453,9 +1456,9 @@ function jn(e, n, i, r, o) {
|
|
|
1453
1456
|
...i
|
|
1454
1457
|
});
|
|
1455
1458
|
}
|
|
1456
|
-
function
|
|
1459
|
+
function et(e, n, i, r, o) {
|
|
1457
1460
|
e === T.Start ? i.linkTrack("agent-video", { event: "start", ...o, "stream-type": r }, "start", [
|
|
1458
|
-
|
|
1461
|
+
D.StreamVideoCreated
|
|
1459
1462
|
]) : e === T.Stop && i.linkTrack(
|
|
1460
1463
|
"agent-video",
|
|
1461
1464
|
{
|
|
@@ -1465,15 +1468,15 @@ function Ye(e, n, i, r, o) {
|
|
|
1465
1468
|
"stream-type": r
|
|
1466
1469
|
},
|
|
1467
1470
|
"done",
|
|
1468
|
-
[
|
|
1471
|
+
[D.StreamVideoDone]
|
|
1469
1472
|
);
|
|
1470
1473
|
}
|
|
1471
|
-
function
|
|
1474
|
+
function xn(e, n, i, r, o) {
|
|
1472
1475
|
e === T.Start ? r.linkTrack(
|
|
1473
1476
|
"agent-video",
|
|
1474
|
-
{ event: "start", latency:
|
|
1477
|
+
{ event: "start", latency: oe.get(!0), "stream-type": o },
|
|
1475
1478
|
"start",
|
|
1476
|
-
[
|
|
1479
|
+
[D.StreamVideoCreated]
|
|
1477
1480
|
) : e === T.Stop && r.linkTrack(
|
|
1478
1481
|
"agent-video",
|
|
1479
1482
|
{
|
|
@@ -1484,19 +1487,19 @@ function $n(e, n, i, r, o) {
|
|
|
1484
1487
|
...i
|
|
1485
1488
|
},
|
|
1486
1489
|
"done",
|
|
1487
|
-
[
|
|
1490
|
+
[D.StreamVideoDone]
|
|
1488
1491
|
);
|
|
1489
1492
|
}
|
|
1490
|
-
function
|
|
1491
|
-
return
|
|
1493
|
+
function tt(e, n, i, r) {
|
|
1494
|
+
return oe.reset(), Qe.update(), new Promise(async (o, a) => {
|
|
1492
1495
|
try {
|
|
1493
1496
|
let s, d = !1;
|
|
1494
|
-
const t =
|
|
1497
|
+
const t = Pn(e, n);
|
|
1495
1498
|
i.enrich({
|
|
1496
1499
|
"stream-version": t.version.toString()
|
|
1497
1500
|
});
|
|
1498
1501
|
let c = null;
|
|
1499
|
-
const
|
|
1502
|
+
const h = e.presenter.type === "expressive";
|
|
1500
1503
|
s = await In(
|
|
1501
1504
|
e,
|
|
1502
1505
|
t,
|
|
@@ -1506,12 +1509,12 @@ function Ge(e, n, i, r) {
|
|
|
1506
1509
|
callbacks: {
|
|
1507
1510
|
...n.callbacks,
|
|
1508
1511
|
onConnectionStateChange: (g, l) => {
|
|
1509
|
-
var v,
|
|
1510
|
-
(
|
|
1512
|
+
var v, P;
|
|
1513
|
+
(P = (v = n.callbacks).onConnectionStateChange) == null || P.call(v, g), Ln(g, l, i), g === L.Connected && (s ? o(s) : d = !0);
|
|
1511
1514
|
},
|
|
1512
1515
|
onVideoStateChange: (g, l) => {
|
|
1513
|
-
var v,
|
|
1514
|
-
(
|
|
1516
|
+
var v, P;
|
|
1517
|
+
(P = (v = n.callbacks).onVideoStateChange) == null || P.call(v, g), $n(
|
|
1515
1518
|
g,
|
|
1516
1519
|
e,
|
|
1517
1520
|
l,
|
|
@@ -1521,15 +1524,15 @@ function Ge(e, n, i, r) {
|
|
|
1521
1524
|
},
|
|
1522
1525
|
onAgentActivityStateChange: (g) => {
|
|
1523
1526
|
var l, v;
|
|
1524
|
-
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g ===
|
|
1525
|
-
|
|
1527
|
+
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? ($e.update(), c = (P) => {
|
|
1528
|
+
et(
|
|
1526
1529
|
T.Start,
|
|
1527
1530
|
e,
|
|
1528
1531
|
i,
|
|
1529
1532
|
s.streamType,
|
|
1530
|
-
|
|
1533
|
+
P
|
|
1531
1534
|
), c = null;
|
|
1532
|
-
},
|
|
1535
|
+
}, h || c({ latency: oe.get(!0) })) : ($e.reset(), c = null, et(
|
|
1533
1536
|
T.Stop,
|
|
1534
1537
|
e,
|
|
1535
1538
|
i,
|
|
@@ -1540,7 +1543,7 @@ function Ge(e, n, i, r) {
|
|
|
1540
1543
|
c == null || c(g);
|
|
1541
1544
|
},
|
|
1542
1545
|
onStreamReady: () => {
|
|
1543
|
-
const g =
|
|
1546
|
+
const g = Qe.get(!0);
|
|
1544
1547
|
i.track("agent-chat", { event: "ready", latency: g });
|
|
1545
1548
|
}
|
|
1546
1549
|
}
|
|
@@ -1552,105 +1555,133 @@ function Ge(e, n, i, r) {
|
|
|
1552
1555
|
}
|
|
1553
1556
|
});
|
|
1554
1557
|
}
|
|
1555
|
-
async function
|
|
1556
|
-
var
|
|
1558
|
+
async function Bn(e, n, i, r, o) {
|
|
1559
|
+
var h, g, l, v;
|
|
1557
1560
|
const a = async () => {
|
|
1558
|
-
if (
|
|
1559
|
-
const
|
|
1561
|
+
if (Fe(e.presenter.type)) {
|
|
1562
|
+
const P = await tt(e, n, r), z = `${An}_${P.sessionId}`, x = (/* @__PURE__ */ new Date()).toISOString();
|
|
1560
1563
|
return { chatResult: {
|
|
1561
|
-
chatMode:
|
|
1564
|
+
chatMode: O.Functional,
|
|
1562
1565
|
chat: {
|
|
1563
|
-
id:
|
|
1566
|
+
id: z,
|
|
1564
1567
|
agent_id: e.id,
|
|
1565
1568
|
owner_id: e.owner_id ?? "",
|
|
1566
|
-
created:
|
|
1567
|
-
modified:
|
|
1568
|
-
agent_id__created_at:
|
|
1569
|
-
agent_id__modified_at:
|
|
1570
|
-
chat_mode:
|
|
1569
|
+
created: x,
|
|
1570
|
+
modified: x,
|
|
1571
|
+
agent_id__created_at: x,
|
|
1572
|
+
agent_id__modified_at: x,
|
|
1573
|
+
chat_mode: O.Functional,
|
|
1571
1574
|
messages: []
|
|
1572
1575
|
}
|
|
1573
|
-
}, streamingManager:
|
|
1576
|
+
}, streamingManager: P };
|
|
1574
1577
|
} else {
|
|
1575
|
-
const
|
|
1576
|
-
let
|
|
1578
|
+
const P = new AbortController(), z = P.signal;
|
|
1579
|
+
let x;
|
|
1577
1580
|
try {
|
|
1578
|
-
const
|
|
1581
|
+
const F = ct(
|
|
1579
1582
|
e,
|
|
1580
1583
|
i,
|
|
1581
1584
|
r,
|
|
1582
1585
|
n.mode,
|
|
1583
1586
|
n.persistentChat,
|
|
1584
1587
|
o
|
|
1585
|
-
), M =
|
|
1586
|
-
return { chatResult:
|
|
1587
|
-
} catch (
|
|
1588
|
-
throw
|
|
1589
|
-
}),
|
|
1588
|
+
), M = tt(e, n, r, z).then((Q) => (x = Q, Q)), [E, Y] = await Promise.all([F, M]);
|
|
1589
|
+
return { chatResult: E, streamingManager: Y };
|
|
1590
|
+
} catch (F) {
|
|
1591
|
+
throw P.abort(), x && await x.disconnect().catch(() => {
|
|
1592
|
+
}), F;
|
|
1590
1593
|
}
|
|
1591
1594
|
}
|
|
1592
1595
|
}, { chatResult: s, streamingManager: d } = await a(), { chat: t, chatMode: c } = s;
|
|
1593
|
-
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (
|
|
1596
|
+
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (h = n.callbacks).onModeChange) == null || g.call(h, c), c !== O.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new Ct(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
|
|
1594
1597
|
}
|
|
1595
|
-
async function
|
|
1596
|
-
var
|
|
1598
|
+
async function Kn(e, n) {
|
|
1599
|
+
var H, re, de, ue;
|
|
1597
1600
|
let i = !0, r = null;
|
|
1598
|
-
const o = n.mixpanelKey ||
|
|
1601
|
+
const o = n.mixpanelKey || $t, a = n.wsURL || Lt, s = n.baseURL || Te, d = n.mode || O.Functional, t = {
|
|
1599
1602
|
messages: [],
|
|
1600
1603
|
chatMode: d
|
|
1601
|
-
}, c =
|
|
1604
|
+
}, c = qt({
|
|
1602
1605
|
token: o,
|
|
1603
1606
|
agentId: e,
|
|
1604
1607
|
isEnabled: n.enableAnalitics,
|
|
1605
1608
|
externalId: n.externalId,
|
|
1606
1609
|
mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
|
|
1607
|
-
}),
|
|
1608
|
-
|
|
1609
|
-
c.track("agent-sdk", { event: "init" },
|
|
1610
|
+
}), h = Date.now();
|
|
1611
|
+
qe(() => {
|
|
1612
|
+
c.track("agent-sdk", { event: "init" }, h);
|
|
1610
1613
|
});
|
|
1611
|
-
const g =
|
|
1612
|
-
n.debug = n.debug || ((
|
|
1613
|
-
const v =
|
|
1614
|
+
const g = Vt(n.auth, s, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1615
|
+
n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
|
|
1616
|
+
const v = Fe(l.presenter.type);
|
|
1614
1617
|
c.enrich(Ut(l));
|
|
1615
|
-
const { onMessage:
|
|
1616
|
-
var
|
|
1617
|
-
(
|
|
1618
|
+
const { onMessage: P, clearQueue: z } = Sn(c, t, n, l, () => {
|
|
1619
|
+
var f, C, R;
|
|
1620
|
+
(f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, L.Disconnected);
|
|
1618
1621
|
});
|
|
1619
|
-
t.messages =
|
|
1620
|
-
const
|
|
1621
|
-
r =
|
|
1622
|
-
},
|
|
1623
|
-
var R,
|
|
1624
|
-
if (!((R = t.streamingManager) != null && R.isInterruptible)) return;
|
|
1625
|
-
const
|
|
1622
|
+
t.messages = Xt(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
|
|
1623
|
+
const x = (f) => {
|
|
1624
|
+
r = f;
|
|
1625
|
+
}, F = ({ type: f }) => {
|
|
1626
|
+
var R, A, I, b, U;
|
|
1627
|
+
if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((A = t.streamingManager) != null && A.isInterruptible)) return;
|
|
1628
|
+
const C = t.messages[t.messages.length - 1];
|
|
1626
1629
|
c.track("agent-video-interrupt", {
|
|
1627
|
-
type:
|
|
1628
|
-
video_duration_to_interrupt:
|
|
1629
|
-
message_duration_to_interrupt:
|
|
1630
|
-
}),
|
|
1631
|
-
}, M =
|
|
1632
|
-
|
|
1633
|
-
|
|
1630
|
+
type: f || "click",
|
|
1631
|
+
video_duration_to_interrupt: $e.get(!0),
|
|
1632
|
+
message_duration_to_interrupt: oe.get(!0)
|
|
1633
|
+
}), C.interrupted = !0, (b = (I = n.callbacks).onNewMessage) == null || b.call(I, [...t.messages], "answer"), v ? gn(t.streamingManager) : (fn(t.streamingManager, (U = t.streamingManager) == null ? void 0 : U.streamType, r), mn(t.streamingManager, r));
|
|
1634
|
+
}, M = /* @__PURE__ */ new Map();
|
|
1635
|
+
function E(f) {
|
|
1636
|
+
return async (C) => {
|
|
1637
|
+
const R = M.get(f);
|
|
1638
|
+
if (!R)
|
|
1639
|
+
throw new Error(`No handler registered for client tool: ${f}`);
|
|
1640
|
+
try {
|
|
1641
|
+
const A = JSON.parse(C.payload);
|
|
1642
|
+
return await R(A);
|
|
1643
|
+
} catch (A) {
|
|
1644
|
+
throw new Error(`Client tool "${f}" failed: ${A.message}`);
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
function Y() {
|
|
1649
|
+
var f, C, R, A;
|
|
1650
|
+
for (const [I] of M)
|
|
1651
|
+
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, I), (A = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || A.call(R, I, E(I));
|
|
1652
|
+
}
|
|
1653
|
+
function Q(f, C) {
|
|
1654
|
+
var A, I;
|
|
1655
|
+
const R = !M.has(f);
|
|
1656
|
+
M.set(f, C), R && ((I = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || I.call(A, f, E(f)));
|
|
1657
|
+
}
|
|
1658
|
+
function J(f) {
|
|
1659
|
+
var C, R;
|
|
1660
|
+
M.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
|
|
1661
|
+
}
|
|
1662
|
+
const te = Date.now();
|
|
1663
|
+
qe(() => {
|
|
1664
|
+
c.track("agent-sdk", { event: "loaded", ...Jt(l) }, te);
|
|
1634
1665
|
});
|
|
1635
|
-
async function
|
|
1636
|
-
var U,
|
|
1637
|
-
(
|
|
1638
|
-
const
|
|
1666
|
+
async function ne(f) {
|
|
1667
|
+
var U, w, y, k, B, G, he;
|
|
1668
|
+
(w = (U = n.callbacks).onConnectionStateChange) == null || w.call(U, L.Connecting), oe.reset(), f && !i && (delete t.chat, (k = (y = n.callbacks).onNewMessage) == null || k.call(y, [...t.messages], "answer"));
|
|
1669
|
+
const C = d === O.DirectPlayback || v ? Promise.resolve(void 0) : wn(
|
|
1639
1670
|
n.auth,
|
|
1640
1671
|
a,
|
|
1641
|
-
{ onMessage:
|
|
1672
|
+
{ onMessage: P, onError: n.callbacks.onError },
|
|
1642
1673
|
n.externalId
|
|
1643
|
-
), R =
|
|
1644
|
-
() =>
|
|
1674
|
+
), R = Pe(
|
|
1675
|
+
() => Bn(
|
|
1645
1676
|
l,
|
|
1646
1677
|
{
|
|
1647
1678
|
...n,
|
|
1648
1679
|
mode: d,
|
|
1649
1680
|
callbacks: {
|
|
1650
1681
|
...n.callbacks,
|
|
1651
|
-
onVideoIdChange:
|
|
1652
|
-
onMessage:
|
|
1653
|
-
onInterruptDetected:
|
|
1682
|
+
onVideoIdChange: x,
|
|
1683
|
+
onMessage: P,
|
|
1684
|
+
onInterruptDetected: F
|
|
1654
1685
|
}
|
|
1655
1686
|
},
|
|
1656
1687
|
g,
|
|
@@ -1659,122 +1690,116 @@ async function zn(e, n) {
|
|
|
1659
1690
|
),
|
|
1660
1691
|
{
|
|
1661
1692
|
limit: 3,
|
|
1662
|
-
timeout:
|
|
1693
|
+
timeout: bt,
|
|
1663
1694
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1664
|
-
shouldRetryFn: (
|
|
1695
|
+
shouldRetryFn: (Z) => (Z == null ? void 0 : Z.message) !== "Could not connect" && Z.status !== 429 && (Z == null ? void 0 : Z.message) !== "InsufficientCreditsError",
|
|
1665
1696
|
delayMs: 1e3
|
|
1666
1697
|
}
|
|
1667
|
-
).catch((
|
|
1668
|
-
var
|
|
1669
|
-
throw
|
|
1670
|
-
}), [
|
|
1671
|
-
|
|
1672
|
-
chatId:
|
|
1673
|
-
streamId:
|
|
1698
|
+
).catch((Z) => {
|
|
1699
|
+
var N, ee;
|
|
1700
|
+
throw K(O.Maintenance), (ee = (N = n.callbacks).onConnectionStateChange) == null || ee.call(N, L.Fail), Z;
|
|
1701
|
+
}), [A, { streamingManager: I, chat: b }] = await Promise.all([C, R]);
|
|
1702
|
+
b && b.id !== ((B = t.chat) == null ? void 0 : B.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = I, t.socketManager = A, t.chat = b, Y(), i = !1, c.enrich({
|
|
1703
|
+
chatId: b == null ? void 0 : b.id,
|
|
1704
|
+
streamId: I == null ? void 0 : I.streamId,
|
|
1674
1705
|
mode: t.chatMode
|
|
1675
|
-
}),
|
|
1706
|
+
}), K((b == null ? void 0 : b.chat_mode) ?? d);
|
|
1676
1707
|
}
|
|
1677
|
-
async function
|
|
1678
|
-
var
|
|
1679
|
-
(
|
|
1708
|
+
async function $() {
|
|
1709
|
+
var f, C, R, A;
|
|
1710
|
+
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R, L.Disconnected);
|
|
1680
1711
|
}
|
|
1681
|
-
async function
|
|
1682
|
-
var
|
|
1683
|
-
|
|
1712
|
+
async function K(f) {
|
|
1713
|
+
var C, R;
|
|
1714
|
+
f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
|
|
1684
1715
|
}
|
|
1685
1716
|
return {
|
|
1686
1717
|
agent: l,
|
|
1687
1718
|
getStreamType: () => {
|
|
1688
|
-
var
|
|
1689
|
-
return (
|
|
1719
|
+
var f;
|
|
1720
|
+
return (f = t.streamingManager) == null ? void 0 : f.streamType;
|
|
1690
1721
|
},
|
|
1691
1722
|
getIsInterruptAvailable: () => {
|
|
1692
|
-
var
|
|
1693
|
-
return ((
|
|
1694
|
-
},
|
|
1695
|
-
getIsTriggersAvailable: () => {
|
|
1696
|
-
var m;
|
|
1697
|
-
return ((m = t.streamingManager) == null ? void 0 : m.triggersAvailable) ?? !1;
|
|
1723
|
+
var f;
|
|
1724
|
+
return ((f = t.streamingManager) == null ? void 0 : f.interruptAvailable) ?? !1;
|
|
1698
1725
|
},
|
|
1699
|
-
starterMessages: ((
|
|
1726
|
+
starterMessages: ((ue = l.knowledge) == null ? void 0 : ue.starter_message) || [],
|
|
1700
1727
|
getSTTToken: () => g.getSTTToken(l.id),
|
|
1701
|
-
changeMode:
|
|
1728
|
+
changeMode: K,
|
|
1702
1729
|
enrichAnalytics: c.enrich,
|
|
1703
1730
|
async connect() {
|
|
1704
|
-
await
|
|
1731
|
+
await ne(!0), c.track("agent-chat", {
|
|
1705
1732
|
event: "connect",
|
|
1706
1733
|
mode: t.chatMode
|
|
1707
1734
|
});
|
|
1708
1735
|
},
|
|
1709
1736
|
async reconnect() {
|
|
1710
|
-
const
|
|
1711
|
-
if (v && (
|
|
1737
|
+
const f = t.streamingManager;
|
|
1738
|
+
if (v && (f != null && f.reconnect)) {
|
|
1712
1739
|
try {
|
|
1713
|
-
await
|
|
1740
|
+
await f.reconnect(), c.track("agent-chat", {
|
|
1714
1741
|
event: "reconnect",
|
|
1715
1742
|
mode: t.chatMode
|
|
1716
1743
|
});
|
|
1717
1744
|
} catch {
|
|
1718
|
-
await
|
|
1745
|
+
await $(), await ne(!1);
|
|
1719
1746
|
}
|
|
1720
1747
|
return;
|
|
1721
1748
|
}
|
|
1722
|
-
await
|
|
1749
|
+
await $(), await ne(!1), c.track("agent-chat", {
|
|
1723
1750
|
event: "reconnect",
|
|
1724
1751
|
mode: t.chatMode
|
|
1725
1752
|
});
|
|
1726
1753
|
},
|
|
1727
1754
|
async disconnect() {
|
|
1728
|
-
await
|
|
1755
|
+
await $(), c.track("agent-chat", {
|
|
1729
1756
|
event: "disconnect",
|
|
1730
1757
|
mode: t.chatMode
|
|
1731
1758
|
});
|
|
1732
1759
|
},
|
|
1733
|
-
async publishMicrophoneStream(
|
|
1734
|
-
var
|
|
1735
|
-
if (!((
|
|
1760
|
+
async publishMicrophoneStream(f) {
|
|
1761
|
+
var C;
|
|
1762
|
+
if (!((C = t.streamingManager) != null && C.publishMicrophoneStream))
|
|
1736
1763
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1737
|
-
return t.streamingManager.publishMicrophoneStream(
|
|
1764
|
+
return t.streamingManager.publishMicrophoneStream(f);
|
|
1738
1765
|
},
|
|
1739
1766
|
async unpublishMicrophoneStream() {
|
|
1740
|
-
var
|
|
1741
|
-
if (
|
|
1742
|
-
|
|
1743
|
-
return t.streamingManager.unpublishMicrophoneStream();
|
|
1767
|
+
var f;
|
|
1768
|
+
if ((f = t.streamingManager) != null && f.unpublishMicrophoneStream)
|
|
1769
|
+
return t.streamingManager.unpublishMicrophoneStream();
|
|
1744
1770
|
},
|
|
1745
|
-
async publishCameraStream(
|
|
1746
|
-
var
|
|
1747
|
-
if (!((
|
|
1771
|
+
async publishCameraStream(f) {
|
|
1772
|
+
var C;
|
|
1773
|
+
if (!((C = t.streamingManager) != null && C.publishCameraStream))
|
|
1748
1774
|
throw new Error("publishCameraStream is not available for this streaming manager");
|
|
1749
|
-
return t.streamingManager.publishCameraStream(
|
|
1775
|
+
return t.streamingManager.publishCameraStream(f);
|
|
1750
1776
|
},
|
|
1751
1777
|
async unpublishCameraStream() {
|
|
1752
|
-
var
|
|
1753
|
-
if (
|
|
1754
|
-
|
|
1755
|
-
return t.streamingManager.unpublishCameraStream();
|
|
1778
|
+
var f;
|
|
1779
|
+
if ((f = t.streamingManager) != null && f.unpublishCameraStream)
|
|
1780
|
+
return t.streamingManager.unpublishCameraStream();
|
|
1756
1781
|
},
|
|
1757
|
-
async chat(
|
|
1758
|
-
var
|
|
1759
|
-
const
|
|
1760
|
-
if (
|
|
1761
|
-
throw new
|
|
1762
|
-
if (
|
|
1763
|
-
throw new
|
|
1764
|
-
if (
|
|
1765
|
-
throw new
|
|
1766
|
-
if (t.chatMode ===
|
|
1767
|
-
throw new
|
|
1768
|
-
if (![
|
|
1782
|
+
async chat(f) {
|
|
1783
|
+
var I, b, U, w, y;
|
|
1784
|
+
const C = () => {
|
|
1785
|
+
if (at(d))
|
|
1786
|
+
throw new me(`${d} is enabled, chat is disabled`);
|
|
1787
|
+
if (f.length >= 800)
|
|
1788
|
+
throw new me("Message cannot be more than 800 characters");
|
|
1789
|
+
if (f.length === 0)
|
|
1790
|
+
throw new me("Message cannot be empty");
|
|
1791
|
+
if (t.chatMode === O.Maintenance)
|
|
1792
|
+
throw new me("Chat is in maintenance mode");
|
|
1793
|
+
if (![O.TextOnly, O.Playground].includes(t.chatMode)) {
|
|
1769
1794
|
if (!t.streamingManager)
|
|
1770
|
-
throw new
|
|
1795
|
+
throw new me("Streaming manager is not initialized");
|
|
1771
1796
|
if (!t.chat)
|
|
1772
|
-
throw new
|
|
1797
|
+
throw new me("Chat is not initialized");
|
|
1773
1798
|
}
|
|
1774
1799
|
}, R = async () => {
|
|
1775
|
-
var
|
|
1800
|
+
var k, B;
|
|
1776
1801
|
if (!t.chat) {
|
|
1777
|
-
const G = await
|
|
1802
|
+
const G = await ct(
|
|
1778
1803
|
l,
|
|
1779
1804
|
g,
|
|
1780
1805
|
c,
|
|
@@ -1782,135 +1807,135 @@ async function zn(e, n) {
|
|
|
1782
1807
|
n.persistentChat
|
|
1783
1808
|
);
|
|
1784
1809
|
if (!G.chat)
|
|
1785
|
-
throw new
|
|
1786
|
-
t.chat = G.chat, (
|
|
1810
|
+
throw new vt(t.chatMode, !!n.persistentChat);
|
|
1811
|
+
t.chat = G.chat, (B = (k = n.callbacks).onNewChat) == null || B.call(k, t.chat.id);
|
|
1787
1812
|
}
|
|
1788
1813
|
return t.chat.id;
|
|
1789
|
-
},
|
|
1790
|
-
const G = t.chatMode ===
|
|
1791
|
-
return
|
|
1792
|
-
var
|
|
1793
|
-
return await ((
|
|
1814
|
+
}, A = async (k, B) => {
|
|
1815
|
+
const G = t.chatMode === O.Playground;
|
|
1816
|
+
return Pe(v && !G ? async () => {
|
|
1817
|
+
var N, ee;
|
|
1818
|
+
return await ((ee = (N = t.streamingManager) == null ? void 0 : N.sendTextMessage) == null ? void 0 : ee.call(N, f)), Promise.resolve({});
|
|
1794
1819
|
} : async () => {
|
|
1795
|
-
var
|
|
1820
|
+
var N, ee;
|
|
1796
1821
|
return g.chat(
|
|
1797
1822
|
l.id,
|
|
1798
|
-
|
|
1823
|
+
B,
|
|
1799
1824
|
{
|
|
1800
1825
|
chatMode: t.chatMode,
|
|
1801
|
-
streamId: (
|
|
1802
|
-
sessionId: (
|
|
1803
|
-
messages:
|
|
1826
|
+
streamId: (N = t.streamingManager) == null ? void 0 : N.streamId,
|
|
1827
|
+
sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
|
|
1828
|
+
messages: k.map(({ matches: De, ...le }) => le)
|
|
1804
1829
|
},
|
|
1805
1830
|
{
|
|
1806
|
-
...
|
|
1831
|
+
...st(t.chatMode),
|
|
1807
1832
|
skipErrorHandler: !0
|
|
1808
1833
|
}
|
|
1809
1834
|
);
|
|
1810
1835
|
}, {
|
|
1811
1836
|
limit: 2,
|
|
1812
|
-
shouldRetryFn: (
|
|
1813
|
-
var
|
|
1814
|
-
const
|
|
1815
|
-
return !((
|
|
1837
|
+
shouldRetryFn: (N) => {
|
|
1838
|
+
var le, ke, pe, we;
|
|
1839
|
+
const ee = (le = N == null ? void 0 : N.message) == null ? void 0 : le.includes("missing or invalid session_id");
|
|
1840
|
+
return !((ke = N == null ? void 0 : N.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, N), !1) : !0;
|
|
1816
1841
|
},
|
|
1817
1842
|
onRetry: async () => {
|
|
1818
|
-
await
|
|
1843
|
+
await $(), await ne(!1);
|
|
1819
1844
|
}
|
|
1820
1845
|
});
|
|
1821
1846
|
};
|
|
1822
1847
|
try {
|
|
1823
|
-
|
|
1824
|
-
id:
|
|
1848
|
+
z(), C(), t.messages.push({
|
|
1849
|
+
id: ge(),
|
|
1825
1850
|
role: "user",
|
|
1826
|
-
content:
|
|
1827
|
-
created_at: new Date(
|
|
1828
|
-
}), (
|
|
1829
|
-
const
|
|
1851
|
+
content: f,
|
|
1852
|
+
created_at: new Date(oe.update()).toISOString()
|
|
1853
|
+
}), (b = (I = n.callbacks).onNewMessage) == null || b.call(I, [...t.messages], "user");
|
|
1854
|
+
const k = await R(), B = await A([...t.messages], k);
|
|
1830
1855
|
return t.messages.push({
|
|
1831
|
-
id:
|
|
1856
|
+
id: ge(),
|
|
1832
1857
|
role: "assistant",
|
|
1833
|
-
content:
|
|
1858
|
+
content: B.result || "",
|
|
1834
1859
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1835
|
-
context:
|
|
1836
|
-
matches:
|
|
1860
|
+
context: B.context,
|
|
1861
|
+
matches: B.matches
|
|
1837
1862
|
}), c.track("agent-message-send", {
|
|
1838
1863
|
event: "success",
|
|
1839
1864
|
messages: t.messages.length + 1
|
|
1840
|
-
}),
|
|
1841
|
-
latency:
|
|
1865
|
+
}), B.result && ((w = (U = n.callbacks).onNewMessage) == null || w.call(U, [...t.messages], "answer"), c.track("agent-message-received", {
|
|
1866
|
+
latency: oe.get(!0),
|
|
1842
1867
|
messages: t.messages.length
|
|
1843
|
-
})),
|
|
1844
|
-
} catch (
|
|
1845
|
-
throw ((
|
|
1868
|
+
})), B;
|
|
1869
|
+
} catch (k) {
|
|
1870
|
+
throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
|
|
1846
1871
|
event: "error",
|
|
1847
1872
|
messages: t.messages.length
|
|
1848
|
-
}),
|
|
1873
|
+
}), k;
|
|
1849
1874
|
}
|
|
1850
1875
|
},
|
|
1851
|
-
rate(
|
|
1852
|
-
var
|
|
1853
|
-
const
|
|
1876
|
+
rate(f, C, R) {
|
|
1877
|
+
var b, U, w, y;
|
|
1878
|
+
const A = t.messages.find((k) => k.id === f);
|
|
1854
1879
|
if (t.chat) {
|
|
1855
|
-
if (!
|
|
1880
|
+
if (!A)
|
|
1856
1881
|
throw new Error("Message not found");
|
|
1857
1882
|
} else throw new Error("Chat is not initialized");
|
|
1858
|
-
const
|
|
1883
|
+
const I = ((b = A.matches) == null ? void 0 : b.map((k) => [k.document_id, k.id])) ?? [];
|
|
1859
1884
|
return c.track("agent-rate", {
|
|
1860
1885
|
event: R ? "update" : "create",
|
|
1861
|
-
thumb:
|
|
1886
|
+
thumb: C === 1 ? "up" : "down",
|
|
1862
1887
|
knowledge_id: ((U = l.knowledge) == null ? void 0 : U.id) ?? "",
|
|
1863
|
-
matches:
|
|
1864
|
-
score:
|
|
1888
|
+
matches: I,
|
|
1889
|
+
score: C
|
|
1865
1890
|
}), R ? g.updateRating(l.id, t.chat.id, R, {
|
|
1866
|
-
knowledge_id: ((
|
|
1867
|
-
message_id:
|
|
1868
|
-
matches:
|
|
1869
|
-
score:
|
|
1891
|
+
knowledge_id: ((w = l.knowledge) == null ? void 0 : w.id) ?? "",
|
|
1892
|
+
message_id: f,
|
|
1893
|
+
matches: I,
|
|
1894
|
+
score: C
|
|
1870
1895
|
}) : g.createRating(l.id, t.chat.id, {
|
|
1871
|
-
knowledge_id: ((
|
|
1872
|
-
message_id:
|
|
1873
|
-
matches:
|
|
1874
|
-
score:
|
|
1896
|
+
knowledge_id: ((y = l.knowledge) == null ? void 0 : y.id) ?? "",
|
|
1897
|
+
message_id: f,
|
|
1898
|
+
matches: I,
|
|
1899
|
+
score: C
|
|
1875
1900
|
});
|
|
1876
1901
|
},
|
|
1877
|
-
deleteRate(
|
|
1902
|
+
deleteRate(f) {
|
|
1878
1903
|
if (!t.chat)
|
|
1879
1904
|
throw new Error("Chat is not initialized");
|
|
1880
|
-
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id,
|
|
1905
|
+
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
|
|
1881
1906
|
},
|
|
1882
|
-
async speak(
|
|
1883
|
-
var
|
|
1884
|
-
function
|
|
1885
|
-
if (typeof
|
|
1907
|
+
async speak(f) {
|
|
1908
|
+
var I, b, U;
|
|
1909
|
+
function C() {
|
|
1910
|
+
if (typeof f == "string") {
|
|
1886
1911
|
if (!l.presenter.voice)
|
|
1887
1912
|
throw new Error("Presenter voice is not initialized");
|
|
1888
1913
|
return {
|
|
1889
1914
|
type: "text",
|
|
1890
1915
|
provider: l.presenter.voice,
|
|
1891
|
-
input:
|
|
1916
|
+
input: f,
|
|
1892
1917
|
ssml: !1
|
|
1893
1918
|
};
|
|
1894
1919
|
}
|
|
1895
|
-
if (
|
|
1920
|
+
if (f.type === "text" && !f.provider) {
|
|
1896
1921
|
if (!l.presenter.voice)
|
|
1897
1922
|
throw new Error("Presenter voice is not initialized");
|
|
1898
1923
|
return {
|
|
1899
1924
|
type: "text",
|
|
1900
1925
|
provider: l.presenter.voice,
|
|
1901
|
-
input:
|
|
1902
|
-
ssml:
|
|
1926
|
+
input: f.input,
|
|
1927
|
+
ssml: f.ssml
|
|
1903
1928
|
};
|
|
1904
1929
|
}
|
|
1905
|
-
return
|
|
1930
|
+
return f;
|
|
1906
1931
|
}
|
|
1907
|
-
const R =
|
|
1908
|
-
if (c.track("agent-speak", R),
|
|
1909
|
-
id:
|
|
1932
|
+
const R = C();
|
|
1933
|
+
if (c.track("agent-speak", R), oe.update(), t.messages && R.type === "text" && (t.messages.push({
|
|
1934
|
+
id: ge(),
|
|
1910
1935
|
role: "assistant",
|
|
1911
1936
|
content: R.input,
|
|
1912
1937
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1913
|
-
}), (
|
|
1938
|
+
}), (b = (I = n.callbacks).onNewMessage) == null || b.call(I, [...t.messages], "answer")), Ft(t.chatMode))
|
|
1914
1939
|
return {
|
|
1915
1940
|
duration: 0,
|
|
1916
1941
|
video_id: "",
|
|
@@ -1923,33 +1948,35 @@ async function zn(e, n) {
|
|
|
1923
1948
|
metadata: { chat_id: (U = t.chat) == null ? void 0 : U.id, agent_id: l.id }
|
|
1924
1949
|
});
|
|
1925
1950
|
},
|
|
1926
|
-
interrupt:
|
|
1951
|
+
interrupt: F,
|
|
1952
|
+
registerClientTool: Q,
|
|
1953
|
+
unregisterClientTool: J
|
|
1927
1954
|
};
|
|
1928
1955
|
}
|
|
1929
1956
|
export {
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1957
|
+
W as AgentActivityState,
|
|
1958
|
+
kt as AgentStatus,
|
|
1959
|
+
vt as ChatCreationFailed,
|
|
1960
|
+
O as ChatMode,
|
|
1961
|
+
Ct as ChatModeDowngraded,
|
|
1962
|
+
X as ChatProgress,
|
|
1963
|
+
L as ConnectionState,
|
|
1964
|
+
ae as ConnectivityState,
|
|
1938
1965
|
It as DocumentType,
|
|
1939
1966
|
Dt as KnowledgeType,
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1967
|
+
Tt as PlanGroup,
|
|
1968
|
+
At as Providers,
|
|
1969
|
+
Et as RateState,
|
|
1970
|
+
D as StreamEvents,
|
|
1971
|
+
se as StreamType,
|
|
1945
1972
|
T as StreamingState,
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1973
|
+
Mt as Subject,
|
|
1974
|
+
Be as TransportProvider,
|
|
1975
|
+
Rt as UserPlan,
|
|
1976
|
+
me as ValidationError,
|
|
1977
|
+
nt as VideoType,
|
|
1978
|
+
_t as VoiceAccess,
|
|
1979
|
+
St as WsError,
|
|
1980
|
+
Kn as createAgentManager,
|
|
1981
|
+
zn as mapVideoType
|
|
1955
1982
|
};
|