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