@d-id/client-sdk 1.1.59 → 1.1.60-staging.278
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 +424 -419
- package/dist/index.umd.cjs +3 -3
- package/dist/src/types/entities/agents/manager.d.ts +5 -5
- package/dist/src/types/stream/stream.d.ts +34 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var Et = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var Ce = (e, n, i) =>
|
|
2
|
+
var Mt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
|
+
var Ce = (e, n, i) => Mt(e, typeof n != "symbol" ? n + "" : n, i);
|
|
4
4
|
class Ie extends Error {
|
|
5
5
|
constructor({ kind: i, description: r, error: s }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: r }));
|
|
@@ -10,7 +10,7 @@ class Ie extends Error {
|
|
|
10
10
|
this.kind = i, this.description = r, this.error = s;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class kt extends Ie {
|
|
14
14
|
constructor(n, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -35,7 +35,7 @@ class Dt extends Ie {
|
|
|
35
35
|
super({ kind: "WSError", description: n });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var At = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(At || {}), _t = /* @__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))(_t || {}), bt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(bt || {}), Lt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Lt || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pt || {}), xt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xt || {}), $t = /* @__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))($t || {}), dt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(dt || {});
|
|
39
39
|
const Hn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -48,8 +48,8 @@ const Hn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
52
|
-
const Ft = 45 * 1e3,
|
|
51
|
+
var E = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(E || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), M = /* @__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.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(M || {}), x = /* @__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))(x || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ne = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ne || {}), jt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(jt || {}), Bt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Bt || {});
|
|
52
|
+
const Ft = 45 * 1e3, Nt = "X-Playground-Chat", Ee = "https://api.d-id.com", Kt = "wss://notifications.d-id.com", zt = "79f81a83a67430be2bc0fd61042b8faa", Vt = (...e) => {
|
|
53
53
|
}, ut = (e) => new Promise((n) => setTimeout(n, e)), ge = (e = 16) => {
|
|
54
54
|
const n = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
@@ -62,7 +62,7 @@ const Ft = 45 * 1e3, Kt = "X-Playground-Chat", Ee = "https://api.d-id.com", Nt =
|
|
|
62
62
|
case "talk":
|
|
63
63
|
return "v2";
|
|
64
64
|
}
|
|
65
|
-
}, Jt = (e) => e.type === "talk" ? e.source_url : e.presenter_id,
|
|
65
|
+
}, Jt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Ke = (e) => e === dt.Expressive, Ot = (e) => [O.TextOnly, O.Playground, O.Maintenance].includes(e), ft = (e) => e && [O.DirectPlayback, O.Off].includes(e), Qe = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Xe = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ye = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ge = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
66
66
|
function Wt(e) {
|
|
67
67
|
if (e.length === 0)
|
|
68
68
|
return [];
|
|
@@ -76,8 +76,8 @@ function Wt(e) {
|
|
|
76
76
|
});
|
|
77
77
|
for (Xe.lastIndex = 0; (i = Xe.exec(e)) !== null; )
|
|
78
78
|
if (!n.some((o) => i.index >= o.index && i.index < o.index + o.length)) {
|
|
79
|
-
const o = i[2],
|
|
80
|
-
o.toLowerCase().endsWith(".gif") && (
|
|
79
|
+
const o = i[2], c = { type: "image", src: o, alt: i[1] };
|
|
80
|
+
o.toLowerCase().endsWith(".gif") && (c.mimeType = "image/gif"), n.push({ index: i.index, length: i[0].length, part: c });
|
|
81
81
|
}
|
|
82
82
|
for (Ye.lastIndex = 0; (i = Ye.exec(e)) !== null; )
|
|
83
83
|
n.some((o) => i.index >= o.index && i.index < o.index + o.length) || n.push({
|
|
@@ -128,8 +128,8 @@ async function xe(e, n) {
|
|
|
128
128
|
try {
|
|
129
129
|
if (!i.timeout)
|
|
130
130
|
return await e();
|
|
131
|
-
const { promise: a, clear: o } = Ht(i.timeout, i.timeoutErrorMessage),
|
|
132
|
-
return await Promise.race([
|
|
131
|
+
const { promise: a, clear: o } = Ht(i.timeout, i.timeoutErrorMessage), c = e().finally(o);
|
|
132
|
+
return await Promise.race([c, a]);
|
|
133
133
|
} catch (a) {
|
|
134
134
|
if (r = a, !i.shouldRetryFn(a) || s >= i.limit)
|
|
135
135
|
throw a;
|
|
@@ -165,7 +165,7 @@ const Qt = (e) => xe(e, {
|
|
|
165
165
|
});
|
|
166
166
|
function ze(e, n = Ee, i, r) {
|
|
167
167
|
const s = async (a, o) => {
|
|
168
|
-
const { skipErrorHandler:
|
|
168
|
+
const { skipErrorHandler: c, ...t } = o || {}, d = await Qt(
|
|
169
169
|
() => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
170
170
|
...t,
|
|
171
171
|
headers: {
|
|
@@ -175,25 +175,25 @@ function ze(e, n = Ee, i, r) {
|
|
|
175
175
|
}
|
|
176
176
|
})
|
|
177
177
|
);
|
|
178
|
-
if (!
|
|
179
|
-
let h = await
|
|
178
|
+
if (!d.ok) {
|
|
179
|
+
let h = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
180
180
|
const g = new Error(h);
|
|
181
|
-
throw i && !
|
|
181
|
+
throw i && !c && i(g, { url: a, options: t, headers: d.headers }), g;
|
|
182
182
|
}
|
|
183
|
-
return
|
|
183
|
+
return d.json();
|
|
184
184
|
};
|
|
185
185
|
return {
|
|
186
186
|
get(a, o) {
|
|
187
187
|
return s(a, { ...o, method: "GET" });
|
|
188
188
|
},
|
|
189
|
-
post(a, o,
|
|
190
|
-
return s(a, { ...
|
|
189
|
+
post(a, o, c) {
|
|
190
|
+
return s(a, { ...c, body: JSON.stringify(o), method: "POST" });
|
|
191
191
|
},
|
|
192
|
-
delete(a, o,
|
|
193
|
-
return s(a, { ...
|
|
192
|
+
delete(a, o, c) {
|
|
193
|
+
return s(a, { ...c, body: JSON.stringify(o), method: "DELETE" });
|
|
194
194
|
},
|
|
195
|
-
patch(a, o,
|
|
196
|
-
return s(a, { ...
|
|
195
|
+
patch(a, o, c) {
|
|
196
|
+
return s(a, { ...c, body: JSON.stringify(o), method: "PATCH" });
|
|
197
197
|
}
|
|
198
198
|
};
|
|
199
199
|
}
|
|
@@ -204,7 +204,7 @@ function Xt(e, n = Ee, i, r) {
|
|
|
204
204
|
return s.post("/", a, o);
|
|
205
205
|
},
|
|
206
206
|
getAgents(a, o) {
|
|
207
|
-
return s.get(`/${a ? `?tag=${a}` : ""}`, o).then((
|
|
207
|
+
return s.get(`/${a ? `?tag=${a}` : ""}`, o).then((c) => c ?? []);
|
|
208
208
|
},
|
|
209
209
|
getById(a, o) {
|
|
210
210
|
return s.get(`/${a}`, o);
|
|
@@ -212,23 +212,23 @@ function Xt(e, n = Ee, i, r) {
|
|
|
212
212
|
delete(a, o) {
|
|
213
213
|
return s.delete(`/${a}`, void 0, o);
|
|
214
214
|
},
|
|
215
|
-
update(a, o,
|
|
216
|
-
return s.patch(`/${a}`, o,
|
|
215
|
+
update(a, o, c) {
|
|
216
|
+
return s.patch(`/${a}`, o, c);
|
|
217
217
|
},
|
|
218
|
-
newChat(a, o,
|
|
219
|
-
return s.post(`/${a}/chat`, o,
|
|
218
|
+
newChat(a, o, c) {
|
|
219
|
+
return s.post(`/${a}/chat`, o, c);
|
|
220
220
|
},
|
|
221
|
-
chat(a, o,
|
|
222
|
-
return s.post(`/${a}/chat/${o}`,
|
|
221
|
+
chat(a, o, c, t) {
|
|
222
|
+
return s.post(`/${a}/chat/${o}`, c, t);
|
|
223
223
|
},
|
|
224
|
-
createRating(a, o,
|
|
225
|
-
return s.post(`/${a}/chat/${o}/ratings`,
|
|
224
|
+
createRating(a, o, c, t) {
|
|
225
|
+
return s.post(`/${a}/chat/${o}/ratings`, c, t);
|
|
226
226
|
},
|
|
227
|
-
updateRating(a, o,
|
|
228
|
-
return s.patch(`/${a}/chat/${o}/ratings/${
|
|
227
|
+
updateRating(a, o, c, t, d) {
|
|
228
|
+
return s.patch(`/${a}/chat/${o}/ratings/${c}`, t, d);
|
|
229
229
|
},
|
|
230
|
-
deleteRating(a, o,
|
|
231
|
-
return s.delete(`/${a}/chat/${o}/ratings/${
|
|
230
|
+
deleteRating(a, o, c, t) {
|
|
231
|
+
return s.delete(`/${a}/chat/${o}/ratings/${c}`, t);
|
|
232
232
|
},
|
|
233
233
|
getSTTToken(a, o) {
|
|
234
234
|
return s.get(`/${a}/stt-token`, o);
|
|
@@ -236,7 +236,7 @@ function Xt(e, n = Ee, i, r) {
|
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
238
|
function Yt(e) {
|
|
239
|
-
var s, a, o,
|
|
239
|
+
var s, a, o, c;
|
|
240
240
|
const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
241
241
|
const t = navigator.platform;
|
|
242
242
|
return t.toLowerCase().includes("win") ? "Windows" : t.toLowerCase().includes("mac") ? "Mac OS X" : t.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
@@ -249,12 +249,12 @@ function Yt(e) {
|
|
|
249
249
|
agentType: lt(r),
|
|
250
250
|
agentVoice: {
|
|
251
251
|
voiceId: (a = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : a.voice_id,
|
|
252
|
-
provider: (
|
|
252
|
+
provider: (c = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : c.type
|
|
253
253
|
}
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
256
|
function Gt(e) {
|
|
257
|
-
var i, r, s, a, o,
|
|
257
|
+
var i, r, s, a, o, c;
|
|
258
258
|
const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
259
259
|
return {
|
|
260
260
|
agentType: lt(e.presenter),
|
|
@@ -269,7 +269,7 @@ function Gt(e) {
|
|
|
269
269
|
},
|
|
270
270
|
temperature: (a = e.llm) == null ? void 0 : a.temperature,
|
|
271
271
|
knowledgeSource: n == null ? void 0 : n.knowledge_source,
|
|
272
|
-
starterQuestionsCount: (
|
|
272
|
+
starterQuestionsCount: (c = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : c.length,
|
|
273
273
|
topicsToAvoid: n == null ? void 0 : n.topics_to_avoid,
|
|
274
274
|
maxResponseLength: n == null ? void 0 : n.max_response_length,
|
|
275
275
|
agentId: e.id,
|
|
@@ -280,12 +280,12 @@ function Gt(e) {
|
|
|
280
280
|
}
|
|
281
281
|
const Zt = (e) => e.reduce((n, i) => n + i, 0), et = (e) => Zt(e) / e.length;
|
|
282
282
|
function en(e, n, i) {
|
|
283
|
-
var t,
|
|
283
|
+
var t, d, h;
|
|
284
284
|
const { event: r, ...s } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: o } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
|
|
285
285
|
return {
|
|
286
286
|
...s,
|
|
287
287
|
llm: { ...s.llm, template: a },
|
|
288
|
-
script: { ...s.script, provider: { ...(
|
|
288
|
+
script: { ...s.script, provider: { ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider, language: o } },
|
|
289
289
|
stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (h = n == null ? void 0 : n.presenter) == null ? void 0 : h.stitch : void 0,
|
|
290
290
|
...i
|
|
291
291
|
};
|
|
@@ -312,7 +312,7 @@ function nn(e) {
|
|
|
312
312
|
async track(r, s, a) {
|
|
313
313
|
if (!this.isEnabled)
|
|
314
314
|
return Promise.resolve();
|
|
315
|
-
const { audioPath: o, ...
|
|
315
|
+
const { audioPath: o, ...c } = s || {}, t = a || Date.now(), d = {
|
|
316
316
|
method: "POST",
|
|
317
317
|
headers: {
|
|
318
318
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -323,7 +323,7 @@ function nn(e) {
|
|
|
323
323
|
event: r,
|
|
324
324
|
properties: {
|
|
325
325
|
...this.additionalProperties,
|
|
326
|
-
...
|
|
326
|
+
...c,
|
|
327
327
|
agentId: this.agentId,
|
|
328
328
|
source: n,
|
|
329
329
|
token: this.token,
|
|
@@ -338,19 +338,19 @@ function nn(e) {
|
|
|
338
338
|
])
|
|
339
339
|
})
|
|
340
340
|
};
|
|
341
|
-
return fetch(tn,
|
|
341
|
+
return fetch(tn, d).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
|
|
342
342
|
},
|
|
343
343
|
linkTrack(r, s, a, o) {
|
|
344
344
|
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), o.includes(a) || o.push(a);
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
347
|
-
(
|
|
345
|
+
const c = i[r];
|
|
346
|
+
if (c.events[a] = { props: s }, c.resolvedDependencies.push(a), o.every(
|
|
347
|
+
(d) => c.resolvedDependencies.includes(d)
|
|
348
348
|
)) {
|
|
349
|
-
const
|
|
350
|
-
this.track(r,
|
|
349
|
+
const d = o.reduce((h, g) => c.events[g] ? { ...h, ...c.events[g].props } : h, {});
|
|
350
|
+
this.track(r, d), c.resolvedDependencies = c.resolvedDependencies.filter(
|
|
351
351
|
(h) => !o.includes(h)
|
|
352
352
|
), o.forEach((h) => {
|
|
353
|
-
delete
|
|
353
|
+
delete c.events[h];
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
}
|
|
@@ -366,7 +366,7 @@ function Ve() {
|
|
|
366
366
|
}
|
|
367
367
|
const oe = Ve(), je = Ve(), nt = Ve();
|
|
368
368
|
function gt(e) {
|
|
369
|
-
return e === O.Playground ? { headers: { [
|
|
369
|
+
return e === O.Playground ? { headers: { [Nt]: "true" } } : {};
|
|
370
370
|
}
|
|
371
371
|
async function ht(e, n, i, r, s = !1, a) {
|
|
372
372
|
try {
|
|
@@ -399,8 +399,8 @@ function on(e, n, i, r) {
|
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
401
|
const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), sn = {
|
|
402
|
-
[
|
|
403
|
-
[
|
|
402
|
+
[M.ChatAnswer]: X.Answer,
|
|
403
|
+
[M.ChatPartial]: X.Partial
|
|
404
404
|
};
|
|
405
405
|
function cn(e, n, i) {
|
|
406
406
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
@@ -464,7 +464,7 @@ function un(e) {
|
|
|
464
464
|
return {};
|
|
465
465
|
}
|
|
466
466
|
function rt(e, n, i) {
|
|
467
|
-
const r = e.map((t,
|
|
467
|
+
const r = e.map((t, d) => d === 0 ? i ? {
|
|
468
468
|
timestamp: t.timestamp,
|
|
469
469
|
duration: 0,
|
|
470
470
|
rtt: t.rtt,
|
|
@@ -500,28 +500,28 @@ function rt(e, n, i) {
|
|
|
500
500
|
freezeDuration: t.freezeDuration
|
|
501
501
|
} : {
|
|
502
502
|
timestamp: t.timestamp,
|
|
503
|
-
duration: n *
|
|
503
|
+
duration: n * d / 1e3,
|
|
504
504
|
rtt: t.rtt,
|
|
505
|
-
bytesReceived: t.bytesReceived - e[
|
|
506
|
-
bitrate: (t.bytesReceived - e[
|
|
507
|
-
packetsReceived: t.packetsReceived - e[
|
|
508
|
-
packetsLost: t.packetsLost - e[
|
|
509
|
-
framesDropped: t.framesDropped - e[
|
|
510
|
-
framesDecoded: t.framesDecoded - e[
|
|
505
|
+
bytesReceived: t.bytesReceived - e[d - 1].bytesReceived,
|
|
506
|
+
bitrate: (t.bytesReceived - e[d - 1].bytesReceived) * 8 / (n / 1e3),
|
|
507
|
+
packetsReceived: t.packetsReceived - e[d - 1].packetsReceived,
|
|
508
|
+
packetsLost: t.packetsLost - e[d - 1].packetsLost,
|
|
509
|
+
framesDropped: t.framesDropped - e[d - 1].framesDropped,
|
|
510
|
+
framesDecoded: t.framesDecoded - e[d - 1].framesDecoded,
|
|
511
511
|
jitter: t.jitter,
|
|
512
|
-
jitterBufferDelay: t.jitterBufferDelay - e[
|
|
513
|
-
jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[
|
|
514
|
-
avgJitterDelayInInterval: (t.jitterBufferDelay - e[
|
|
512
|
+
jitterBufferDelay: t.jitterBufferDelay - e[d - 1].jitterBufferDelay,
|
|
513
|
+
jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
|
|
514
|
+
avgJitterDelayInInterval: (t.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
|
|
515
515
|
framesPerSecond: t.framesPerSecond,
|
|
516
|
-
freezeCount: t.freezeCount - e[
|
|
517
|
-
freezeDuration: t.freezeDuration - e[
|
|
518
|
-
}), s = dn(r), a = s.reduce((t,
|
|
516
|
+
freezeCount: t.freezeCount - e[d - 1].freezeCount,
|
|
517
|
+
freezeDuration: t.freezeDuration - e[d - 1].freezeDuration
|
|
518
|
+
}), s = dn(r), a = s.reduce((t, d) => t + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), c = r.filter((t) => !!t.rtt).map((t) => t.rtt);
|
|
519
519
|
return {
|
|
520
520
|
webRTCStats: {
|
|
521
521
|
anomalies: s,
|
|
522
|
-
minRtt: Math.min(...
|
|
523
|
-
avgRtt: et(
|
|
524
|
-
maxRtt: Math.max(...
|
|
522
|
+
minRtt: Math.min(...c),
|
|
523
|
+
avgRtt: et(c),
|
|
524
|
+
maxRtt: Math.max(...c),
|
|
525
525
|
aggregateReport: cn(e[0], e[e.length - 1], a),
|
|
526
526
|
minJitterDelayInInterval: Math.min(...o),
|
|
527
527
|
maxJitterDelayInInterval: Math.max(...o),
|
|
@@ -539,16 +539,16 @@ function wt(e, n) {
|
|
|
539
539
|
}
|
|
540
540
|
const Se = 10;
|
|
541
541
|
function ln(e, n) {
|
|
542
|
-
let i = !1, r = !1, s = null, a = 0, o = 0,
|
|
542
|
+
let i = !1, r = !1, s = null, a = 0, o = 0, c = {};
|
|
543
543
|
async function t() {
|
|
544
544
|
if (i) {
|
|
545
545
|
try {
|
|
546
|
-
const
|
|
547
|
-
if (!
|
|
546
|
+
const d = await e();
|
|
547
|
+
if (!d) {
|
|
548
548
|
s = setTimeout(t, Se);
|
|
549
549
|
return;
|
|
550
550
|
}
|
|
551
|
-
const h = wt(
|
|
551
|
+
const h = wt(d, "audio");
|
|
552
552
|
if (!h) {
|
|
553
553
|
s = setTimeout(t, Se);
|
|
554
554
|
return;
|
|
@@ -558,9 +558,9 @@ function ln(e, n) {
|
|
|
558
558
|
a = g, o = l, r = !0, s = setTimeout(t, Se);
|
|
559
559
|
return;
|
|
560
560
|
}
|
|
561
|
-
const v = g - a,
|
|
562
|
-
if (a = g, o = l,
|
|
563
|
-
i = !1, n(
|
|
561
|
+
const v = g - a, P = l - o;
|
|
562
|
+
if (a = g, o = l, P > 0 && v > 0) {
|
|
563
|
+
i = !1, n(c);
|
|
564
564
|
return;
|
|
565
565
|
}
|
|
566
566
|
} catch {
|
|
@@ -569,54 +569,54 @@ function ln(e, n) {
|
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
return {
|
|
572
|
-
arm(
|
|
573
|
-
|
|
572
|
+
arm(d = {}) {
|
|
573
|
+
c = d, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t, Se);
|
|
574
574
|
},
|
|
575
575
|
destroy() {
|
|
576
576
|
i = !1, s !== null && (clearTimeout(s), s = null);
|
|
577
577
|
}
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
|
-
const
|
|
580
|
+
const ke = 100, fn = Math.max(Math.ceil(400 / ke), 1), mn = 0.25, gn = 0.28;
|
|
581
581
|
function hn() {
|
|
582
582
|
let e = 0, n, i, r = 0;
|
|
583
583
|
return (s) => {
|
|
584
584
|
const a = wt(s, "video");
|
|
585
585
|
if (!a)
|
|
586
586
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
587
|
-
const o = a.jitterBufferDelay,
|
|
588
|
-
if (i &&
|
|
589
|
-
const h = o - n, g =
|
|
587
|
+
const o = a.jitterBufferDelay, c = a.jitterBufferEmittedCount;
|
|
588
|
+
if (i && c > i) {
|
|
589
|
+
const h = o - n, g = c - i;
|
|
590
590
|
r = h / g;
|
|
591
591
|
}
|
|
592
|
-
n = o, i =
|
|
593
|
-
const t = a.framesDecoded,
|
|
594
|
-
return e = t, { isReceiving:
|
|
592
|
+
n = o, i = c;
|
|
593
|
+
const t = a.framesDecoded, d = t - e > 0;
|
|
594
|
+
return e = t, { isReceiving: d, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
597
|
function yt(e, n, i, r, s) {
|
|
598
|
-
let a = null, o = [],
|
|
599
|
-
const
|
|
600
|
-
async function
|
|
598
|
+
let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
|
|
599
|
+
const P = hn();
|
|
600
|
+
async function N() {
|
|
601
601
|
const B = await e();
|
|
602
602
|
if (!B)
|
|
603
603
|
return;
|
|
604
|
-
const { isReceiving: F, avgJitterDelayInInterval:
|
|
604
|
+
const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: k } = P(B), Y = un(B);
|
|
605
605
|
if (F)
|
|
606
|
-
t = 0, l = k - v, g =
|
|
607
|
-
else if (
|
|
608
|
-
const Q = rt(o,
|
|
609
|
-
r == null || r(
|
|
606
|
+
t = 0, l = k - v, g = I < mn ? ae.Strong : I > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0), d || (r == null || r(E.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
|
|
607
|
+
else if (d && (t++, t >= fn)) {
|
|
608
|
+
const Q = rt(o, ke, c);
|
|
609
|
+
r == null || r(E.Stop, Q), n() || i(), v = k, d = !1;
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
return {
|
|
613
613
|
start: () => {
|
|
614
|
-
a || (a = setInterval(
|
|
614
|
+
a || (a = setInterval(N, ke));
|
|
615
615
|
},
|
|
616
616
|
stop: () => {
|
|
617
617
|
a && (clearInterval(a), a = null);
|
|
618
618
|
},
|
|
619
|
-
getReport: () => rt(o,
|
|
619
|
+
getReport: () => rt(o, ke, c)
|
|
620
620
|
};
|
|
621
621
|
}
|
|
622
622
|
const it = 2e4;
|
|
@@ -642,36 +642,36 @@ const wn = {
|
|
|
642
642
|
var Ue = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ue || {});
|
|
643
643
|
function Be(e, n, i) {
|
|
644
644
|
var r, s;
|
|
645
|
-
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i,
|
|
645
|
+
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, x.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
|
|
646
646
|
}
|
|
647
647
|
async function yn(e, n, i) {
|
|
648
648
|
var Je;
|
|
649
|
-
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track:
|
|
649
|
+
const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await pn(), { callbacks: t, auth: d, baseURL: h, analytics: g } = i;
|
|
650
650
|
let l = null, v = !1;
|
|
651
|
-
const
|
|
652
|
-
let
|
|
651
|
+
const P = se.Fluent;
|
|
652
|
+
let N = null;
|
|
653
653
|
const B = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
|
|
654
|
-
let
|
|
654
|
+
let I = null, k = null, Y = null, Q = !1;
|
|
655
655
|
l = new s({
|
|
656
656
|
adaptiveStream: !1,
|
|
657
657
|
// Must be false to use mediaStreamTrack directly
|
|
658
658
|
dynacast: !0
|
|
659
659
|
});
|
|
660
660
|
let U = null, te = W.Idle, ne = !0;
|
|
661
|
-
const
|
|
662
|
-
let
|
|
661
|
+
const $ = on(d, h || Ee, e, t.onError);
|
|
662
|
+
let K, H, re, de = !0;
|
|
663
663
|
try {
|
|
664
|
-
const u = await
|
|
664
|
+
const u = await $.createStream({
|
|
665
665
|
transport: n.transport,
|
|
666
666
|
chat_persist: n.chat_persist ?? !0
|
|
667
|
-
}), { id: m, session_token: p, session_url: S, interrupt_enabled:
|
|
668
|
-
(Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }),
|
|
667
|
+
}), { id: m, session_token: p, session_url: S, interrupt_enabled: _ } = u;
|
|
668
|
+
(Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H = p, re = S, de = _ ?? !0, await l.prepareConnection(re, H);
|
|
669
669
|
} catch (u) {
|
|
670
670
|
Be(u, r, t);
|
|
671
671
|
}
|
|
672
|
-
if (!re || !H || !
|
|
672
|
+
if (!re || !H || !K)
|
|
673
673
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
674
|
-
l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected,
|
|
674
|
+
l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, J).on(a.TrackUnsubscribed, w).on(a.DataReceived, z).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
|
|
675
675
|
function ue(u, m) {
|
|
676
676
|
var p;
|
|
677
677
|
m != null && m.isLocal && (oe.update(), te === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), te = W.Idle));
|
|
@@ -683,32 +683,32 @@ async function yn(e, n, i) {
|
|
|
683
683
|
`Track subscription timeout - no track subscribed within ${it / 1e3} seconds after connect`
|
|
684
684
|
), U = null, g.track("connectivity-error", {
|
|
685
685
|
error: "Track subscription timeout",
|
|
686
|
-
sessionId:
|
|
687
|
-
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId:
|
|
686
|
+
sessionId: K
|
|
687
|
+
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: K }), Le("internal:track-subscription-timeout");
|
|
688
688
|
}, it);
|
|
689
689
|
} catch (u) {
|
|
690
690
|
Be(u, r, t);
|
|
691
691
|
}
|
|
692
692
|
g.enrich({
|
|
693
|
-
"stream-type":
|
|
693
|
+
"stream-type": P
|
|
694
694
|
});
|
|
695
695
|
function f(u) {
|
|
696
|
-
var m, p, S,
|
|
696
|
+
var m, p, S, _;
|
|
697
697
|
switch (r("Connection state changed:", u), u) {
|
|
698
698
|
case o.Connecting:
|
|
699
|
-
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t,
|
|
699
|
+
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, x.Connecting, "livekit:connecting");
|
|
700
700
|
break;
|
|
701
701
|
case o.Connected:
|
|
702
702
|
r("LiveKit room connected successfully"), v = !0;
|
|
703
703
|
break;
|
|
704
704
|
case o.Disconnected:
|
|
705
|
-
r("LiveKit room disconnected"), v = !1, Q = !1, B.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t,
|
|
705
|
+
r("LiveKit room disconnected"), v = !1, Q = !1, B.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, x.Disconnected, "livekit:disconnected");
|
|
706
706
|
break;
|
|
707
707
|
case o.Reconnecting:
|
|
708
|
-
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t,
|
|
708
|
+
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, x.Connecting, "livekit:reconnecting");
|
|
709
709
|
break;
|
|
710
710
|
case o.SignalReconnecting:
|
|
711
|
-
r("LiveKit room signal reconnecting..."), (
|
|
711
|
+
r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, x.Connecting, "livekit:signal-reconnecting");
|
|
712
712
|
break;
|
|
713
713
|
}
|
|
714
714
|
}
|
|
@@ -719,68 +719,72 @@ async function yn(e, n, i) {
|
|
|
719
719
|
function R(u) {
|
|
720
720
|
r("Participant connected:", u.identity);
|
|
721
721
|
}
|
|
722
|
-
function
|
|
722
|
+
function A(u) {
|
|
723
723
|
r("Participant disconnected:", u.identity), Le("livekit:participant-disconnected");
|
|
724
724
|
}
|
|
725
725
|
function D() {
|
|
726
726
|
var u;
|
|
727
|
-
Y !==
|
|
727
|
+
Y !== E.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = E.Start, (u = t.onVideoStateChange) == null || u.call(t, E.Start));
|
|
728
728
|
}
|
|
729
729
|
function b(u) {
|
|
730
730
|
var m;
|
|
731
|
-
Y !==
|
|
731
|
+
Y !== E.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = E.Stop, (m = t.onVideoStateChange) == null || m.call(t, E.Stop, u));
|
|
732
732
|
}
|
|
733
733
|
function J(u, m, p) {
|
|
734
|
-
var
|
|
734
|
+
var _, L, q;
|
|
735
735
|
r(`Track subscribed: ${u.kind} from ${p.identity}`);
|
|
736
736
|
const S = u.mediaStreamTrack;
|
|
737
737
|
if (!S) {
|
|
738
738
|
r(`No mediaStreamTrack available for ${u.kind}`);
|
|
739
739
|
return;
|
|
740
740
|
}
|
|
741
|
-
|
|
741
|
+
N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = ln(
|
|
742
742
|
() => u.getRTCStatsReport(),
|
|
743
743
|
({ sttLatency: V, serviceLatency: ie }) => {
|
|
744
744
|
var Oe, We, He;
|
|
745
745
|
const ye = oe.get(!0);
|
|
746
746
|
let ve = 0;
|
|
747
747
|
if (V) {
|
|
748
|
-
const qe = ((We = (Oe =
|
|
748
|
+
const qe = ((We = (Oe = I == null ? void 0 : I.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
|
|
749
749
|
ve = qe > 0 ? Math.round(qe * 1e3) : 0;
|
|
750
750
|
}
|
|
751
751
|
const fe = ye > 0 ? ye + (V ?? 0) + ve : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
|
|
752
752
|
(He = t.onFirstAudioDetected) == null || He.call(t, { latency: fe, networkLatency: ce });
|
|
753
753
|
}
|
|
754
|
-
)), u.kind === "video" && ((
|
|
754
|
+
)), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (L = t.onSrcObjectReady) == null || L.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, x.Connected, "livekit:track-subscribed")), I = yt(
|
|
755
755
|
() => u.getRTCStatsReport(),
|
|
756
756
|
() => v,
|
|
757
757
|
Vt,
|
|
758
758
|
(V, ie) => {
|
|
759
|
-
r(`Video state change: ${V}`), V ===
|
|
759
|
+
r(`Video state change: ${V}`), V === E.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), D()) : V === E.Stop && b(ie);
|
|
760
760
|
}
|
|
761
|
-
),
|
|
761
|
+
), I.start());
|
|
762
762
|
}
|
|
763
763
|
function w(u, m, p) {
|
|
764
|
-
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (b(
|
|
764
|
+
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (b(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
|
|
765
765
|
}
|
|
766
766
|
function y(u, m) {
|
|
767
767
|
var S;
|
|
768
768
|
const p = sn[u];
|
|
769
769
|
p && ((S = t.onMessage) == null || S.call(t, p, { event: p, ...m }));
|
|
770
770
|
}
|
|
771
|
-
function
|
|
772
|
-
var p, S,
|
|
773
|
-
if (u ===
|
|
774
|
-
te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t,
|
|
771
|
+
function T(u, m) {
|
|
772
|
+
var p, S, _, L;
|
|
773
|
+
if (u === M.ToolCallStarted) {
|
|
774
|
+
te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, M.ToolCallStarted, m);
|
|
775
775
|
return;
|
|
776
776
|
}
|
|
777
|
-
u ===
|
|
777
|
+
if (u === M.ToolCallDone) {
|
|
778
|
+
(_ = t.onToolEvent) == null || _.call(t, M.ToolCallDone, m);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
u === M.ToolCallError && ((L = t.onToolEvent) == null || L.call(t, M.ToolCallError, m));
|
|
778
782
|
}
|
|
779
|
-
function
|
|
780
|
-
var p, S,
|
|
781
|
-
if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u ===
|
|
782
|
-
te = W.Talking, (
|
|
783
|
-
sttLatency: (
|
|
783
|
+
function j(u, m) {
|
|
784
|
+
var p, S, _, L, q;
|
|
785
|
+
if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === M.StreamVideoCreated) {
|
|
786
|
+
te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), k == null || k.arm({
|
|
787
|
+
sttLatency: (L = m == null ? void 0 : m.stt) == null ? void 0 : L.latency,
|
|
784
788
|
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
785
789
|
});
|
|
786
790
|
return;
|
|
@@ -788,12 +792,12 @@ async function yn(e, n, i) {
|
|
|
788
792
|
ne && (te = W.Idle, (q = t.onAgentActivityStateChange) == null || q.call(t, W.Idle));
|
|
789
793
|
}
|
|
790
794
|
function G(u, m) {
|
|
791
|
-
var
|
|
792
|
-
const p = ((q = (
|
|
793
|
-
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (
|
|
795
|
+
var L, q, V, ie;
|
|
796
|
+
const p = ((q = (L = I == null ? void 0 : I.getReport()) == null ? void 0 : L.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: S };
|
|
797
|
+
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (_.sentiment = {
|
|
794
798
|
id: m.metadata.sentiment.id,
|
|
795
799
|
name: m.metadata.sentiment.sentiment
|
|
796
|
-
}), (ie = t.onMessage) == null || ie.call(t, u,
|
|
800
|
+
}), (ie = t.onMessage) == null || ie.call(t, u, _), j(u, m);
|
|
797
801
|
}
|
|
798
802
|
function he(u, m) {
|
|
799
803
|
var p;
|
|
@@ -803,48 +807,49 @@ async function yn(e, n, i) {
|
|
|
803
807
|
});
|
|
804
808
|
}
|
|
805
809
|
const Z = {
|
|
806
|
-
[
|
|
807
|
-
[
|
|
808
|
-
[
|
|
809
|
-
[
|
|
810
|
-
[
|
|
811
|
-
[
|
|
812
|
-
[
|
|
813
|
-
[
|
|
814
|
-
[
|
|
810
|
+
[M.ChatAnswer]: y,
|
|
811
|
+
[M.ChatPartial]: y,
|
|
812
|
+
[M.ToolCallStarted]: T,
|
|
813
|
+
[M.ToolCallDone]: T,
|
|
814
|
+
[M.ToolCallError]: T,
|
|
815
|
+
[M.StreamVideoCreated]: G,
|
|
816
|
+
[M.StreamVideoDone]: G,
|
|
817
|
+
[M.StreamVideoError]: G,
|
|
818
|
+
[M.StreamVideoRejected]: G,
|
|
819
|
+
[M.ChatAudioTranscribed]: he
|
|
815
820
|
};
|
|
816
821
|
function z(u, m, p, S) {
|
|
817
|
-
const
|
|
822
|
+
const _ = new TextDecoder().decode(u);
|
|
818
823
|
try {
|
|
819
|
-
const
|
|
820
|
-
if (r("Data received:", { subject: q, data:
|
|
824
|
+
const L = JSON.parse(_), q = S || L.subject;
|
|
825
|
+
if (r("Data received:", { subject: q, data: L }), !q) return;
|
|
821
826
|
const V = Z[q];
|
|
822
|
-
V == null || V(q,
|
|
823
|
-
} catch (
|
|
824
|
-
r("Failed to parse data channel message:",
|
|
827
|
+
V == null || V(q, L);
|
|
828
|
+
} catch (L) {
|
|
829
|
+
r("Failed to parse data channel message:", L);
|
|
825
830
|
}
|
|
826
831
|
}
|
|
827
832
|
function ee(u) {
|
|
828
833
|
var m;
|
|
829
|
-
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId:
|
|
834
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
|
|
830
835
|
}
|
|
831
836
|
function De(u) {
|
|
832
837
|
var m;
|
|
833
|
-
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId:
|
|
838
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
|
|
834
839
|
}
|
|
835
840
|
function le(u, m, p) {
|
|
836
841
|
r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
|
|
837
842
|
}
|
|
838
|
-
function
|
|
839
|
-
for (const [S,
|
|
840
|
-
if (
|
|
841
|
-
const
|
|
842
|
-
if (
|
|
843
|
-
return
|
|
843
|
+
function Me(u, m, p) {
|
|
844
|
+
for (const [S, _] of p)
|
|
845
|
+
if (_.source === m && _.track) {
|
|
846
|
+
const L = _.track.mediaStreamTrack;
|
|
847
|
+
if (L === u || (L == null ? void 0 : L.id) === u.id)
|
|
848
|
+
return _;
|
|
844
849
|
}
|
|
845
850
|
return null;
|
|
846
851
|
}
|
|
847
|
-
async function pe(u, m, p, S,
|
|
852
|
+
async function pe(u, m, p, S, _, L) {
|
|
848
853
|
var ye, ve, fe;
|
|
849
854
|
if (!v || !l)
|
|
850
855
|
throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
|
|
@@ -855,7 +860,7 @@ async function yn(e, n, i) {
|
|
|
855
860
|
const q = p(m);
|
|
856
861
|
if (q.length === 0)
|
|
857
862
|
throw new Error(`No ${S} track found in the provided MediaStream`);
|
|
858
|
-
const V = q[0], ie =
|
|
863
|
+
const V = q[0], ie = Me(V, S, _());
|
|
859
864
|
if (ie) {
|
|
860
865
|
r(`${S} track is already published, skipping`, {
|
|
861
866
|
trackId: V.id,
|
|
@@ -865,7 +870,7 @@ async function yn(e, n, i) {
|
|
|
865
870
|
}
|
|
866
871
|
if ((fe = u.publication) != null && fe.track) {
|
|
867
872
|
const ce = u.publication.track.mediaStreamTrack;
|
|
868
|
-
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await
|
|
873
|
+
ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await L());
|
|
869
874
|
}
|
|
870
875
|
r(`Publishing ${S} track from provided MediaStream`, { trackId: V.id }), u.isPublishing = !0;
|
|
871
876
|
try {
|
|
@@ -891,12 +896,12 @@ async function yn(e, n, i) {
|
|
|
891
896
|
B,
|
|
892
897
|
u,
|
|
893
898
|
(m) => m.getAudioTracks(),
|
|
894
|
-
|
|
899
|
+
c.Source.Microphone,
|
|
895
900
|
() => l.localParticipant.audioTrackPublications,
|
|
896
|
-
|
|
901
|
+
Ae
|
|
897
902
|
);
|
|
898
903
|
}
|
|
899
|
-
async function
|
|
904
|
+
async function Ae() {
|
|
900
905
|
return we(B, "Microphone");
|
|
901
906
|
}
|
|
902
907
|
async function Ct(u) {
|
|
@@ -904,29 +909,29 @@ async function yn(e, n, i) {
|
|
|
904
909
|
F,
|
|
905
910
|
u,
|
|
906
911
|
(m) => m.getVideoTracks(),
|
|
907
|
-
|
|
912
|
+
c.Source.Camera,
|
|
908
913
|
() => l.localParticipant.videoTrackPublications,
|
|
909
|
-
|
|
914
|
+
_e
|
|
910
915
|
);
|
|
911
916
|
}
|
|
912
|
-
async function
|
|
917
|
+
async function _e() {
|
|
913
918
|
return we(F, "Camera");
|
|
914
919
|
}
|
|
915
920
|
function St() {
|
|
916
|
-
|
|
921
|
+
N && (N.getTracks().forEach((u) => u.stop()), N = null);
|
|
917
922
|
}
|
|
918
923
|
async function be(u, m) {
|
|
919
924
|
var p, S;
|
|
920
925
|
if (!v || !l) {
|
|
921
926
|
r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(Re), {
|
|
922
|
-
sessionId:
|
|
927
|
+
sessionId: K
|
|
923
928
|
});
|
|
924
929
|
return;
|
|
925
930
|
}
|
|
926
931
|
try {
|
|
927
932
|
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
928
|
-
} catch (
|
|
929
|
-
r("Failed to send message:",
|
|
933
|
+
} catch (_) {
|
|
934
|
+
r("Failed to send message:", _), (S = t.onError) == null || S.call(t, new Error(Re), { sessionId: K });
|
|
930
935
|
}
|
|
931
936
|
}
|
|
932
937
|
async function Rt(u) {
|
|
@@ -935,7 +940,7 @@ async function yn(e, n, i) {
|
|
|
935
940
|
const S = JSON.parse(u).topic;
|
|
936
941
|
return be("", S);
|
|
937
942
|
} catch (p) {
|
|
938
|
-
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId:
|
|
943
|
+
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
|
|
939
944
|
}
|
|
940
945
|
}
|
|
941
946
|
function Tt(u) {
|
|
@@ -947,7 +952,7 @@ async function yn(e, n, i) {
|
|
|
947
952
|
}
|
|
948
953
|
async function Le(u) {
|
|
949
954
|
var m, p;
|
|
950
|
-
U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t,
|
|
955
|
+
U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([Ae(), _e()]), await l.disconnect()), St(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
|
|
951
956
|
}
|
|
952
957
|
return {
|
|
953
958
|
speak(u) {
|
|
@@ -967,39 +972,39 @@ async function yn(e, n, i) {
|
|
|
967
972
|
}
|
|
968
973
|
if (!l || !re || !H)
|
|
969
974
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
970
|
-
r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t,
|
|
975
|
+
r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, x.Connecting, "user:reconnect");
|
|
971
976
|
try {
|
|
972
977
|
if (await l.connect(re, H), r("Room reconnected"), v = !0, l.remoteParticipants.size === 0) {
|
|
973
978
|
if (r("Waiting for agent to join..."), !await new Promise((S) => {
|
|
974
|
-
const
|
|
975
|
-
l == null || l.off(a.ParticipantConnected,
|
|
976
|
-
}, 5e3),
|
|
977
|
-
clearTimeout(
|
|
979
|
+
const _ = setTimeout(() => {
|
|
980
|
+
l == null || l.off(a.ParticipantConnected, L), S(!1);
|
|
981
|
+
}, 5e3), L = () => {
|
|
982
|
+
clearTimeout(_), l == null || l.off(a.ParticipantConnected, L), S(!0);
|
|
978
983
|
};
|
|
979
|
-
l == null || l.on(a.ParticipantConnected,
|
|
984
|
+
l == null || l.on(a.ParticipantConnected, L);
|
|
980
985
|
}))
|
|
981
986
|
throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
|
|
982
987
|
r("Agent joined, reconnection successful");
|
|
983
988
|
}
|
|
984
989
|
} catch (p) {
|
|
985
|
-
throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t,
|
|
990
|
+
throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, x.Fail, "user:reconnect-failed"), p;
|
|
986
991
|
}
|
|
987
992
|
},
|
|
988
993
|
sendDataChannelMessage: Rt,
|
|
989
994
|
sendTextMessage: Tt,
|
|
990
995
|
publishMicrophoneStream: vt,
|
|
991
|
-
unpublishMicrophoneStream:
|
|
996
|
+
unpublishMicrophoneStream: Ae,
|
|
992
997
|
publishCameraStream: Ct,
|
|
993
|
-
unpublishCameraStream:
|
|
998
|
+
unpublishCameraStream: _e,
|
|
994
999
|
registerRpcMethod(u, m) {
|
|
995
1000
|
l == null || l.registerRpcMethod(u, m);
|
|
996
1001
|
},
|
|
997
1002
|
unregisterRpcMethod(u) {
|
|
998
1003
|
l == null || l.unregisterRpcMethod(u);
|
|
999
1004
|
},
|
|
1000
|
-
sessionId:
|
|
1001
|
-
streamId:
|
|
1002
|
-
streamType:
|
|
1005
|
+
sessionId: K,
|
|
1006
|
+
streamId: K,
|
|
1007
|
+
streamType: P,
|
|
1003
1008
|
interruptAvailable: de,
|
|
1004
1009
|
isInterruptible: ne
|
|
1005
1010
|
};
|
|
@@ -1022,7 +1027,7 @@ function Cn(e, n, i) {
|
|
|
1022
1027
|
}
|
|
1023
1028
|
async function Sn(e, n) {
|
|
1024
1029
|
const i = {
|
|
1025
|
-
type:
|
|
1030
|
+
type: M.StreamInterrupt,
|
|
1026
1031
|
videoId: n,
|
|
1027
1032
|
timestamp: Date.now()
|
|
1028
1033
|
};
|
|
@@ -1036,8 +1041,8 @@ async function Rn(e) {
|
|
|
1036
1041
|
}
|
|
1037
1042
|
function Tn(e) {
|
|
1038
1043
|
return new Promise((n, i) => {
|
|
1039
|
-
const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage:
|
|
1040
|
-
g.onmessage =
|
|
1044
|
+
const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage: c = null, onOpen: t = null, onClose: d = null, onError: h = null } = r || {}, g = new WebSocket(`${s}?authorization=${encodeURIComponent(mt(a, o))}`);
|
|
1045
|
+
g.onmessage = c, g.onclose = d, g.onerror = (l) => {
|
|
1041
1046
|
console.error(l), h == null || h("Websocket failed to connect", l), i(l);
|
|
1042
1047
|
}, g.onopen = (l) => {
|
|
1043
1048
|
t == null || t(l), n(g);
|
|
@@ -1057,19 +1062,19 @@ async function En(e) {
|
|
|
1057
1062
|
}
|
|
1058
1063
|
return i;
|
|
1059
1064
|
}
|
|
1060
|
-
async function
|
|
1065
|
+
async function Mn(e, n, i, r) {
|
|
1061
1066
|
const s = i != null && i.onMessage ? [i.onMessage] : [], a = await En({
|
|
1062
1067
|
auth: e,
|
|
1063
1068
|
host: n,
|
|
1064
1069
|
externalId: r,
|
|
1065
1070
|
callbacks: {
|
|
1066
1071
|
onError: (o) => {
|
|
1067
|
-
var
|
|
1068
|
-
return (
|
|
1072
|
+
var c;
|
|
1073
|
+
return (c = i.onError) == null ? void 0 : c.call(i, new Dt(o));
|
|
1069
1074
|
},
|
|
1070
1075
|
onMessage(o) {
|
|
1071
|
-
const
|
|
1072
|
-
s.forEach((t) => t(
|
|
1076
|
+
const c = JSON.parse(o.data);
|
|
1077
|
+
s.forEach((t) => t(c.event, c));
|
|
1073
1078
|
}
|
|
1074
1079
|
}
|
|
1075
1080
|
});
|
|
@@ -1079,7 +1084,7 @@ async function kn(e, n, i, r) {
|
|
|
1079
1084
|
subscribeToEvents: (o) => s.push(o)
|
|
1080
1085
|
};
|
|
1081
1086
|
}
|
|
1082
|
-
function
|
|
1087
|
+
function kn(e) {
|
|
1083
1088
|
if (e.answer !== void 0)
|
|
1084
1089
|
return e.answer;
|
|
1085
1090
|
let n = 0, i = "";
|
|
@@ -1102,99 +1107,99 @@ function In(e, n, i) {
|
|
|
1102
1107
|
};
|
|
1103
1108
|
n.messages.push(s), i == null || i([...n.messages], "user");
|
|
1104
1109
|
}
|
|
1105
|
-
function Dn(e, n, i, r, s) {
|
|
1110
|
+
function Dn(e, n, i, r, s, a) {
|
|
1106
1111
|
if (e === X.Transcribe && n.content) {
|
|
1107
1112
|
In(n, r, s);
|
|
1108
1113
|
return;
|
|
1109
1114
|
}
|
|
1110
1115
|
if (!(e === X.Partial || e === X.Answer))
|
|
1111
1116
|
return;
|
|
1112
|
-
const
|
|
1113
|
-
let
|
|
1114
|
-
if ((
|
|
1115
|
-
|
|
1116
|
-
else if (!
|
|
1117
|
-
|
|
1117
|
+
const o = r.messages[r.messages.length - 1], c = n.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== n.id;
|
|
1118
|
+
let t;
|
|
1119
|
+
if ((o == null ? void 0 : o.role) === "assistant" && !c)
|
|
1120
|
+
t = o;
|
|
1121
|
+
else if (!o || o.transcribed && o.role === "user" || c)
|
|
1122
|
+
c && a(), t = {
|
|
1118
1123
|
id: n.id || `assistant-${Date.now()}`,
|
|
1119
1124
|
role: n.role || "assistant",
|
|
1120
1125
|
content: n.content || "",
|
|
1121
1126
|
parts: [],
|
|
1122
1127
|
created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
1123
|
-
}, r.messages.push(
|
|
1128
|
+
}, r.messages.push(t);
|
|
1124
1129
|
else
|
|
1125
1130
|
return;
|
|
1126
|
-
const { content: d, sequence:
|
|
1127
|
-
e === X.Partial ? i[
|
|
1128
|
-
const
|
|
1129
|
-
(
|
|
1131
|
+
const { content: d, sequence: h } = n;
|
|
1132
|
+
e === X.Partial ? i[h] = d : i.answer = d;
|
|
1133
|
+
const g = kn(i);
|
|
1134
|
+
(t.content !== g || e === X.Answer) && (t.content = g, t.parts = Te(g), s == null || s([...r.messages], e));
|
|
1130
1135
|
}
|
|
1131
|
-
function
|
|
1136
|
+
function An(e, n, i, r, s) {
|
|
1132
1137
|
let a = {};
|
|
1133
1138
|
const o = () => a = {};
|
|
1134
|
-
let
|
|
1135
|
-
const t = (
|
|
1139
|
+
let c = "answer";
|
|
1140
|
+
const t = (d, h) => {
|
|
1136
1141
|
var g, l;
|
|
1137
|
-
h === "user" && o(),
|
|
1142
|
+
h === "user" && o(), c = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, d, h);
|
|
1138
1143
|
};
|
|
1139
1144
|
return {
|
|
1140
1145
|
clearQueue: o,
|
|
1141
|
-
onMessage: (
|
|
1146
|
+
onMessage: (d, h) => {
|
|
1142
1147
|
var g, l;
|
|
1143
1148
|
if ("content" in h) {
|
|
1144
|
-
const v =
|
|
1145
|
-
Dn(v, h, a, n, t), v === X.Answer && e.track("agent-message-received", {
|
|
1149
|
+
const v = d === M.ChatAnswer ? X.Answer : d === M.ChatAudioTranscribed ? X.Transcribe : d;
|
|
1150
|
+
Dn(v, h, a, n, t, o), v === X.Answer && e.track("agent-message-received", {
|
|
1146
1151
|
content: h.content,
|
|
1147
1152
|
messages: n.messages.length,
|
|
1148
1153
|
mode: n.chatMode
|
|
1149
1154
|
});
|
|
1150
1155
|
} else {
|
|
1151
|
-
const v =
|
|
1152
|
-
if (
|
|
1156
|
+
const v = M, P = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], N = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
|
|
1157
|
+
if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1153
1158
|
const F = n.messages[n.messages.length - 1];
|
|
1154
1159
|
if ((F == null ? void 0 : F.role) === "assistant") {
|
|
1155
|
-
const
|
|
1156
|
-
n.messages[n.messages.length - 1] =
|
|
1160
|
+
const I = { ...F, sentiment: h.sentiment };
|
|
1161
|
+
n.messages[n.messages.length - 1] = I, t == null || t([...n.messages], c);
|
|
1157
1162
|
}
|
|
1158
1163
|
}
|
|
1159
|
-
if (
|
|
1160
|
-
const F =
|
|
1161
|
-
|
|
1164
|
+
if (P.includes(d)) {
|
|
1165
|
+
const F = d.split("/")[1];
|
|
1166
|
+
N.includes(d) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, d, ["done"]);
|
|
1162
1167
|
}
|
|
1163
|
-
|
|
1168
|
+
N.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: h })), h.event === v.StreamDone && s();
|
|
1164
1169
|
}
|
|
1165
1170
|
}
|
|
1166
1171
|
};
|
|
1167
1172
|
}
|
|
1168
|
-
function
|
|
1173
|
+
function _n(e, n, i, r) {
|
|
1169
1174
|
const s = ze(e, `${n}/agents/${i}`, r);
|
|
1170
1175
|
return {
|
|
1171
1176
|
createStream(a, o) {
|
|
1172
1177
|
return s.post("/streams", a, { signal: o });
|
|
1173
1178
|
},
|
|
1174
|
-
startConnection(a, o,
|
|
1179
|
+
startConnection(a, o, c, t) {
|
|
1175
1180
|
return s.post(
|
|
1176
1181
|
`/streams/${a}/sdp`,
|
|
1177
1182
|
{
|
|
1178
|
-
session_id:
|
|
1183
|
+
session_id: c,
|
|
1179
1184
|
answer: o
|
|
1180
1185
|
},
|
|
1181
1186
|
{ signal: t }
|
|
1182
1187
|
);
|
|
1183
1188
|
},
|
|
1184
|
-
addIceCandidate(a, o,
|
|
1189
|
+
addIceCandidate(a, o, c, t) {
|
|
1185
1190
|
return s.post(
|
|
1186
1191
|
`/streams/${a}/ice`,
|
|
1187
1192
|
{
|
|
1188
|
-
session_id:
|
|
1193
|
+
session_id: c,
|
|
1189
1194
|
...o
|
|
1190
1195
|
},
|
|
1191
1196
|
{ signal: t }
|
|
1192
1197
|
);
|
|
1193
1198
|
},
|
|
1194
|
-
sendStreamRequest(a, o,
|
|
1199
|
+
sendStreamRequest(a, o, c) {
|
|
1195
1200
|
return s.post(`/streams/${a}`, {
|
|
1196
1201
|
session_id: o,
|
|
1197
|
-
...
|
|
1202
|
+
...c
|
|
1198
1203
|
});
|
|
1199
1204
|
},
|
|
1200
1205
|
close(a, o) {
|
|
@@ -1206,21 +1211,21 @@ const bn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window
|
|
|
1206
1211
|
function at(e) {
|
|
1207
1212
|
switch (e) {
|
|
1208
1213
|
case "connected":
|
|
1209
|
-
return
|
|
1214
|
+
return x.Connected;
|
|
1210
1215
|
case "checking":
|
|
1211
|
-
return
|
|
1216
|
+
return x.Connecting;
|
|
1212
1217
|
case "failed":
|
|
1213
|
-
return
|
|
1218
|
+
return x.Fail;
|
|
1214
1219
|
case "new":
|
|
1215
|
-
return
|
|
1220
|
+
return x.New;
|
|
1216
1221
|
case "closed":
|
|
1217
|
-
return
|
|
1222
|
+
return x.Closed;
|
|
1218
1223
|
case "disconnected":
|
|
1219
|
-
return
|
|
1224
|
+
return x.Disconnected;
|
|
1220
1225
|
case "completed":
|
|
1221
|
-
return
|
|
1226
|
+
return x.Completed;
|
|
1222
1227
|
default:
|
|
1223
|
-
return
|
|
1228
|
+
return x.New;
|
|
1224
1229
|
}
|
|
1225
1230
|
}
|
|
1226
1231
|
const Ln = (e) => (n) => {
|
|
@@ -1239,7 +1244,7 @@ function Pn({
|
|
|
1239
1244
|
report: r,
|
|
1240
1245
|
log: s
|
|
1241
1246
|
}) {
|
|
1242
|
-
e ===
|
|
1247
|
+
e === E.Start && n === E.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && n === E.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, r));
|
|
1243
1248
|
}
|
|
1244
1249
|
function xn({
|
|
1245
1250
|
statsSignal: e,
|
|
@@ -1249,7 +1254,7 @@ function xn({
|
|
|
1249
1254
|
report: s,
|
|
1250
1255
|
log: a
|
|
1251
1256
|
}) {
|
|
1252
|
-
e ===
|
|
1257
|
+
e === E.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, s)), n === E.Start ? r == null || r(W.Talking) : n === E.Stop && (r == null || r(W.Idle));
|
|
1253
1258
|
}
|
|
1254
1259
|
function ot({
|
|
1255
1260
|
statsSignal: e,
|
|
@@ -1269,11 +1274,11 @@ function ot({
|
|
|
1269
1274
|
log: o
|
|
1270
1275
|
});
|
|
1271
1276
|
}
|
|
1272
|
-
async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o },
|
|
1277
|
+
async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, c) {
|
|
1273
1278
|
var J;
|
|
1274
|
-
const t = pt(i, "WebRTCStreamingManager"),
|
|
1275
|
-
let h = !1, g = !1, l =
|
|
1276
|
-
const { startConnection:
|
|
1279
|
+
const t = pt(i, "WebRTCStreamingManager"), d = Ln(t);
|
|
1280
|
+
let h = !1, g = !1, l = E.Stop, v = E.Stop;
|
|
1281
|
+
const { startConnection: P, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } = _n(
|
|
1277
1282
|
s,
|
|
1278
1283
|
a,
|
|
1279
1284
|
e,
|
|
@@ -1285,9 +1290,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1285
1290
|
session_id: U,
|
|
1286
1291
|
fluent: te,
|
|
1287
1292
|
interrupt_enabled: ne
|
|
1288
|
-
} = await F(n,
|
|
1293
|
+
} = await F(n, c);
|
|
1289
1294
|
(J = r.onStreamCreated) == null || J.call(r, { stream_id: k, session_id: U, agent_id: e });
|
|
1290
|
-
const
|
|
1295
|
+
const $ = new bn({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
|
|
1291
1296
|
if (!U)
|
|
1292
1297
|
throw new Error("Could not create session_id");
|
|
1293
1298
|
const H = te ? se.Fluent : se.Legacy;
|
|
@@ -1296,9 +1301,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1296
1301
|
});
|
|
1297
1302
|
const re = n.stream_warmup && !te, de = () => h, ue = () => {
|
|
1298
1303
|
var w;
|
|
1299
|
-
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r,
|
|
1304
|
+
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, x.Connected));
|
|
1300
1305
|
}, f = yt(
|
|
1301
|
-
() =>
|
|
1306
|
+
() => $.getStats(),
|
|
1302
1307
|
de,
|
|
1303
1308
|
ue,
|
|
1304
1309
|
(w, y) => ot({
|
|
@@ -1315,11 +1320,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1315
1320
|
return (y = r.onConnectivityStateChange) == null ? void 0 : y.call(r, w);
|
|
1316
1321
|
}
|
|
1317
1322
|
);
|
|
1318
|
-
f.start(),
|
|
1323
|
+
f.start(), $.onicecandidate = (w) => {
|
|
1319
1324
|
var y;
|
|
1320
1325
|
t("peerConnection.onicecandidate", w);
|
|
1321
1326
|
try {
|
|
1322
|
-
w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ?
|
|
1327
|
+
w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? I(
|
|
1323
1328
|
k,
|
|
1324
1329
|
{
|
|
1325
1330
|
candidate: w.candidate.candidate,
|
|
@@ -1327,12 +1332,12 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1327
1332
|
sdpMLineIndex: w.candidate.sdpMLineIndex
|
|
1328
1333
|
},
|
|
1329
1334
|
U,
|
|
1330
|
-
|
|
1331
|
-
) :
|
|
1332
|
-
} catch (
|
|
1333
|
-
(y = r.onError) == null || y.call(r,
|
|
1335
|
+
c
|
|
1336
|
+
) : I(k, { candidate: null }, U, c);
|
|
1337
|
+
} catch (T) {
|
|
1338
|
+
(y = r.onError) == null || y.call(r, T, { streamId: k });
|
|
1334
1339
|
}
|
|
1335
|
-
},
|
|
1340
|
+
}, K.onopen = () => {
|
|
1336
1341
|
g = !0, (!re || h) && ue();
|
|
1337
1342
|
};
|
|
1338
1343
|
const C = (w) => {
|
|
@@ -1340,11 +1345,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1340
1345
|
(y = r.onVideoIdChange) == null || y.call(r, w);
|
|
1341
1346
|
};
|
|
1342
1347
|
function R(w, y) {
|
|
1343
|
-
if (w ===
|
|
1344
|
-
const
|
|
1345
|
-
C(
|
|
1348
|
+
if (w === M.StreamStarted && typeof y == "object" && "metadata" in y) {
|
|
1349
|
+
const T = y.metadata;
|
|
1350
|
+
C(T.videoId);
|
|
1346
1351
|
}
|
|
1347
|
-
w ===
|
|
1352
|
+
w === M.StreamDone && C(null), l = w === M.StreamStarted ? E.Start : E.Stop, ot({
|
|
1348
1353
|
statsSignal: H === se.Legacy ? v : void 0,
|
|
1349
1354
|
dataChannelSignal: l,
|
|
1350
1355
|
onVideoStateChange: r.onVideoStateChange,
|
|
@@ -1353,37 +1358,37 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1353
1358
|
log: t
|
|
1354
1359
|
});
|
|
1355
1360
|
}
|
|
1356
|
-
function
|
|
1357
|
-
var
|
|
1358
|
-
const
|
|
1359
|
-
|
|
1361
|
+
function A(w, y) {
|
|
1362
|
+
var j;
|
|
1363
|
+
const T = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
|
|
1364
|
+
T && o.enrich({ streamMetadata: T }), (j = r.onStreamReady) == null || j.call(r);
|
|
1360
1365
|
}
|
|
1361
1366
|
const D = {
|
|
1362
|
-
[
|
|
1363
|
-
[
|
|
1364
|
-
[
|
|
1367
|
+
[M.StreamStarted]: R,
|
|
1368
|
+
[M.StreamDone]: R,
|
|
1369
|
+
[M.StreamReady]: A
|
|
1365
1370
|
};
|
|
1366
|
-
|
|
1367
|
-
var
|
|
1368
|
-
const { subject: y, data:
|
|
1369
|
-
(
|
|
1370
|
-
},
|
|
1371
|
+
K.onmessage = (w) => {
|
|
1372
|
+
var j;
|
|
1373
|
+
const { subject: y, data: T } = d(w.data);
|
|
1374
|
+
(j = D[y]) == null || j.call(D, y, T);
|
|
1375
|
+
}, $.oniceconnectionstatechange = () => {
|
|
1371
1376
|
var y;
|
|
1372
|
-
t("peerConnection.oniceconnectionstatechange => " +
|
|
1373
|
-
const w = at(
|
|
1374
|
-
w !==
|
|
1375
|
-
},
|
|
1377
|
+
t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
|
|
1378
|
+
const w = at($.iceConnectionState);
|
|
1379
|
+
w !== x.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
|
|
1380
|
+
}, $.ontrack = (w) => {
|
|
1376
1381
|
var y;
|
|
1377
1382
|
t("peerConnection.ontrack", w), t("CALLBACK: onSrcObjectReady"), (y = r.onSrcObjectReady) == null || y.call(r, w.streams[0]);
|
|
1378
|
-
}, await
|
|
1379
|
-
const b = await
|
|
1380
|
-
return t("create answer OK"), await
|
|
1383
|
+
}, await $.setRemoteDescription(Y), t("set remote description OK");
|
|
1384
|
+
const b = await $.createAnswer();
|
|
1385
|
+
return t("create answer OK"), await $.setLocalDescription(b), t("set local description OK"), await P(k, b, U, c), t("start connection OK"), {
|
|
1381
1386
|
/**
|
|
1382
1387
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1383
1388
|
* @param payload
|
|
1384
1389
|
*/
|
|
1385
1390
|
speak(w) {
|
|
1386
|
-
return
|
|
1391
|
+
return N(k, U, w);
|
|
1387
1392
|
},
|
|
1388
1393
|
/**
|
|
1389
1394
|
* Method to close RTC connection
|
|
@@ -1391,19 +1396,19 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1391
1396
|
async disconnect() {
|
|
1392
1397
|
var w;
|
|
1393
1398
|
if (k) {
|
|
1394
|
-
const y = at(
|
|
1395
|
-
if (
|
|
1396
|
-
if (y ===
|
|
1399
|
+
const y = at($.iceConnectionState);
|
|
1400
|
+
if ($) {
|
|
1401
|
+
if (y === x.New) {
|
|
1397
1402
|
f.stop();
|
|
1398
1403
|
return;
|
|
1399
1404
|
}
|
|
1400
|
-
|
|
1405
|
+
$.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
|
|
1401
1406
|
}
|
|
1402
1407
|
try {
|
|
1403
|
-
y ===
|
|
1408
|
+
y === x.Connected && await B(k, U).catch((T) => {
|
|
1404
1409
|
});
|
|
1405
|
-
} catch (
|
|
1406
|
-
t("Error on close stream connection",
|
|
1410
|
+
} catch (T) {
|
|
1411
|
+
t("Error on close stream connection", T);
|
|
1407
1412
|
}
|
|
1408
1413
|
(w = r.onAgentActivityStateChange) == null || w.call(r, W.Idle), f.stop();
|
|
1409
1414
|
}
|
|
@@ -1412,17 +1417,17 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1412
1417
|
* Method to send data channel messages to the server
|
|
1413
1418
|
*/
|
|
1414
1419
|
sendDataChannelMessage(w) {
|
|
1415
|
-
var y,
|
|
1416
|
-
if (!h ||
|
|
1420
|
+
var y, T;
|
|
1421
|
+
if (!h || K.readyState !== "open") {
|
|
1417
1422
|
t("Data channel is not ready for sending messages"), (y = r.onError) == null || y.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
1418
1423
|
streamId: k
|
|
1419
1424
|
});
|
|
1420
1425
|
return;
|
|
1421
1426
|
}
|
|
1422
1427
|
try {
|
|
1423
|
-
|
|
1424
|
-
} catch (
|
|
1425
|
-
t("Error sending data channel message",
|
|
1428
|
+
K.send(w);
|
|
1429
|
+
} catch (j) {
|
|
1430
|
+
t("Error sending data channel message", j), (T = r.onError) == null || T.call(r, j, { streamId: k });
|
|
1426
1431
|
}
|
|
1427
1432
|
},
|
|
1428
1433
|
/**
|
|
@@ -1449,9 +1454,9 @@ async function jn(e, n, i, r) {
|
|
|
1449
1454
|
case "v2": {
|
|
1450
1455
|
const { version: a, ...o } = n;
|
|
1451
1456
|
switch (o.transport.provider) {
|
|
1452
|
-
case
|
|
1453
|
-
const { createLiveKitStreamingManager:
|
|
1454
|
-
return
|
|
1457
|
+
case Ne.Livekit:
|
|
1458
|
+
const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() => vn);
|
|
1459
|
+
return c(s, o, i);
|
|
1455
1460
|
default:
|
|
1456
1461
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
1457
1462
|
}
|
|
@@ -1464,11 +1469,11 @@ const Bn = "cht";
|
|
|
1464
1469
|
function Fn() {
|
|
1465
1470
|
return {
|
|
1466
1471
|
transport: {
|
|
1467
|
-
provider:
|
|
1472
|
+
provider: Ne.Livekit
|
|
1468
1473
|
}
|
|
1469
1474
|
};
|
|
1470
1475
|
}
|
|
1471
|
-
function
|
|
1476
|
+
function Nn(e) {
|
|
1472
1477
|
var s, a;
|
|
1473
1478
|
const { streamOptions: n } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
|
|
1474
1479
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1481,8 +1486,8 @@ function Kn(e) {
|
|
|
1481
1486
|
fluent: n == null ? void 0 : n.fluent
|
|
1482
1487
|
}, ...i && { end_user_data: i } };
|
|
1483
1488
|
}
|
|
1484
|
-
function
|
|
1485
|
-
return
|
|
1489
|
+
function Kn(e, n) {
|
|
1490
|
+
return Ke(e.presenter.type) ? { version: Fe.V2, ...Fn() } : { version: Fe.V1, ...Nn(n) };
|
|
1486
1491
|
}
|
|
1487
1492
|
function zn(e, n, i) {
|
|
1488
1493
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
@@ -1491,7 +1496,7 @@ function Vn(e, n, i, r, s) {
|
|
|
1491
1496
|
s === se.Fluent ? Un(e, n, i, r, s) : Jn(e, n, i, r, s);
|
|
1492
1497
|
}
|
|
1493
1498
|
function Un(e, n, i, r, s) {
|
|
1494
|
-
e ===
|
|
1499
|
+
e === E.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === E.Stop && r.track("stream-session", {
|
|
1495
1500
|
event: "stop",
|
|
1496
1501
|
is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
|
|
1497
1502
|
background: n.presenter.type === "clip" && n.presenter.background,
|
|
@@ -1500,9 +1505,9 @@ function Un(e, n, i, r, s) {
|
|
|
1500
1505
|
});
|
|
1501
1506
|
}
|
|
1502
1507
|
function st(e, n, i, r, s) {
|
|
1503
|
-
e ===
|
|
1504
|
-
|
|
1505
|
-
]) : e ===
|
|
1508
|
+
e === E.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
|
|
1509
|
+
M.StreamVideoCreated
|
|
1510
|
+
]) : e === E.Stop && i.linkTrack(
|
|
1506
1511
|
"agent-video",
|
|
1507
1512
|
{
|
|
1508
1513
|
event: "stop",
|
|
@@ -1511,16 +1516,16 @@ function st(e, n, i, r, s) {
|
|
|
1511
1516
|
"stream-type": r
|
|
1512
1517
|
},
|
|
1513
1518
|
"done",
|
|
1514
|
-
[
|
|
1519
|
+
[M.StreamVideoDone]
|
|
1515
1520
|
);
|
|
1516
1521
|
}
|
|
1517
1522
|
function Jn(e, n, i, r, s) {
|
|
1518
|
-
e ===
|
|
1523
|
+
e === E.Start ? r.linkTrack(
|
|
1519
1524
|
"agent-video",
|
|
1520
1525
|
{ event: "start", latency: oe.get(!0), "stream-type": s },
|
|
1521
1526
|
"start",
|
|
1522
|
-
[
|
|
1523
|
-
) : e ===
|
|
1527
|
+
[M.StreamVideoCreated]
|
|
1528
|
+
) : e === E.Stop && r.linkTrack(
|
|
1524
1529
|
"agent-video",
|
|
1525
1530
|
{
|
|
1526
1531
|
event: "stop",
|
|
@@ -1530,18 +1535,18 @@ function Jn(e, n, i, r, s) {
|
|
|
1530
1535
|
...i
|
|
1531
1536
|
},
|
|
1532
1537
|
"done",
|
|
1533
|
-
[
|
|
1538
|
+
[M.StreamVideoDone]
|
|
1534
1539
|
);
|
|
1535
1540
|
}
|
|
1536
1541
|
function ct(e, n, i, r) {
|
|
1537
1542
|
return oe.reset(), nt.update(), new Promise(async (s, a) => {
|
|
1538
1543
|
try {
|
|
1539
|
-
let o,
|
|
1540
|
-
const t =
|
|
1544
|
+
let o, c = !1;
|
|
1545
|
+
const t = Kn(e, n);
|
|
1541
1546
|
i.enrich({
|
|
1542
1547
|
"stream-version": t.version.toString()
|
|
1543
1548
|
});
|
|
1544
|
-
let
|
|
1549
|
+
let d = null;
|
|
1545
1550
|
const h = e.presenter.type === "expressive";
|
|
1546
1551
|
o = await jn(
|
|
1547
1552
|
e,
|
|
@@ -1552,12 +1557,12 @@ function ct(e, n, i, r) {
|
|
|
1552
1557
|
callbacks: {
|
|
1553
1558
|
...n.callbacks,
|
|
1554
1559
|
onConnectionStateChange: (g, l) => {
|
|
1555
|
-
var v,
|
|
1556
|
-
(
|
|
1560
|
+
var v, P;
|
|
1561
|
+
(P = (v = n.callbacks).onConnectionStateChange) == null || P.call(v, g), zn(g, l, i), g === x.Connected && (o ? s(o) : c = !0);
|
|
1557
1562
|
},
|
|
1558
1563
|
onVideoStateChange: (g, l) => {
|
|
1559
|
-
var v,
|
|
1560
|
-
(
|
|
1564
|
+
var v, P;
|
|
1565
|
+
(P = (v = n.callbacks).onVideoStateChange) == null || P.call(v, g), Vn(
|
|
1561
1566
|
g,
|
|
1562
1567
|
e,
|
|
1563
1568
|
l,
|
|
@@ -1567,23 +1572,23 @@ function ct(e, n, i, r) {
|
|
|
1567
1572
|
},
|
|
1568
1573
|
onAgentActivityStateChange: (g) => {
|
|
1569
1574
|
var l, v;
|
|
1570
|
-
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(),
|
|
1575
|
+
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), d = (P) => {
|
|
1571
1576
|
st(
|
|
1572
|
-
|
|
1577
|
+
E.Start,
|
|
1573
1578
|
e,
|
|
1574
1579
|
i,
|
|
1575
1580
|
o.streamType,
|
|
1576
|
-
|
|
1577
|
-
),
|
|
1578
|
-
}, h ||
|
|
1579
|
-
|
|
1581
|
+
P
|
|
1582
|
+
), d = null;
|
|
1583
|
+
}, h || d({ latency: oe.get(!0) })) : (je.reset(), d = null, st(
|
|
1584
|
+
E.Stop,
|
|
1580
1585
|
e,
|
|
1581
1586
|
i,
|
|
1582
1587
|
o.streamType
|
|
1583
1588
|
));
|
|
1584
1589
|
},
|
|
1585
1590
|
onFirstAudioDetected: (g) => {
|
|
1586
|
-
|
|
1591
|
+
d == null || d(g);
|
|
1587
1592
|
},
|
|
1588
1593
|
onStreamReady: () => {
|
|
1589
1594
|
const g = nt.get(!0);
|
|
@@ -1592,7 +1597,7 @@ function ct(e, n, i, r) {
|
|
|
1592
1597
|
}
|
|
1593
1598
|
},
|
|
1594
1599
|
r
|
|
1595
|
-
),
|
|
1600
|
+
), c && s(o);
|
|
1596
1601
|
} catch (o) {
|
|
1597
1602
|
a(o);
|
|
1598
1603
|
}
|
|
@@ -1601,12 +1606,12 @@ function ct(e, n, i, r) {
|
|
|
1601
1606
|
async function On(e, n, i, r, s) {
|
|
1602
1607
|
var h, g, l, v;
|
|
1603
1608
|
const a = async () => {
|
|
1604
|
-
if (
|
|
1605
|
-
const
|
|
1609
|
+
if (Ke(e.presenter.type)) {
|
|
1610
|
+
const P = await ct(e, n, r), N = `${Bn}_${P.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
|
|
1606
1611
|
return { chatResult: {
|
|
1607
1612
|
chatMode: O.Functional,
|
|
1608
1613
|
chat: {
|
|
1609
|
-
id:
|
|
1614
|
+
id: N,
|
|
1610
1615
|
agent_id: e.id,
|
|
1611
1616
|
owner_id: e.owner_id ?? "",
|
|
1612
1617
|
created: B,
|
|
@@ -1616,9 +1621,9 @@ async function On(e, n, i, r, s) {
|
|
|
1616
1621
|
chat_mode: O.Functional,
|
|
1617
1622
|
messages: []
|
|
1618
1623
|
}
|
|
1619
|
-
}, streamingManager:
|
|
1624
|
+
}, streamingManager: P };
|
|
1620
1625
|
} else {
|
|
1621
|
-
const
|
|
1626
|
+
const P = new AbortController(), N = P.signal;
|
|
1622
1627
|
let B;
|
|
1623
1628
|
try {
|
|
1624
1629
|
const F = ht(
|
|
@@ -1628,23 +1633,23 @@ async function On(e, n, i, r, s) {
|
|
|
1628
1633
|
n.mode,
|
|
1629
1634
|
n.persistentChat,
|
|
1630
1635
|
s
|
|
1631
|
-
),
|
|
1636
|
+
), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, I]);
|
|
1632
1637
|
return { chatResult: k, streamingManager: Y };
|
|
1633
1638
|
} catch (F) {
|
|
1634
|
-
throw
|
|
1639
|
+
throw P.abort(), B && await B.disconnect().catch(() => {
|
|
1635
1640
|
}), F;
|
|
1636
1641
|
}
|
|
1637
1642
|
}
|
|
1638
|
-
}, { chatResult: o, streamingManager:
|
|
1639
|
-
return
|
|
1643
|
+
}, { chatResult: o, streamingManager: c } = await a(), { chat: t, chatMode: d } = o;
|
|
1644
|
+
return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new It(d)), c == null || c.disconnect(), { chat: t }) : { chat: t, streamingManager: c };
|
|
1640
1645
|
}
|
|
1641
1646
|
async function qn(e, n) {
|
|
1642
1647
|
var H, re, de, ue;
|
|
1643
1648
|
let i = !0, r = null;
|
|
1644
|
-
const s = n.mixpanelKey || zt, a = n.wsURL ||
|
|
1649
|
+
const s = n.mixpanelKey || zt, a = n.wsURL || Kt, o = n.baseURL || Ee, c = n.mode || O.Functional, t = {
|
|
1645
1650
|
messages: [],
|
|
1646
|
-
chatMode:
|
|
1647
|
-
},
|
|
1651
|
+
chatMode: c
|
|
1652
|
+
}, d = nn({
|
|
1648
1653
|
token: s,
|
|
1649
1654
|
agentId: e,
|
|
1650
1655
|
isEnabled: n.enableAnalitics,
|
|
@@ -1652,83 +1657,83 @@ async function qn(e, n) {
|
|
|
1652
1657
|
mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
|
|
1653
1658
|
}), h = Date.now();
|
|
1654
1659
|
tt(() => {
|
|
1655
|
-
|
|
1660
|
+
d.track("agent-sdk", { event: "init" }, h);
|
|
1656
1661
|
});
|
|
1657
1662
|
const g = Xt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1658
1663
|
n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
|
|
1659
|
-
const v =
|
|
1660
|
-
|
|
1661
|
-
const { onMessage:
|
|
1664
|
+
const v = Ke(l.presenter.type);
|
|
1665
|
+
d.enrich(Gt(l));
|
|
1666
|
+
const { onMessage: P, clearQueue: N } = An(d, t, n, l, () => {
|
|
1662
1667
|
var f, C, R;
|
|
1663
|
-
(f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C,
|
|
1668
|
+
(f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, x.Disconnected);
|
|
1664
1669
|
});
|
|
1665
1670
|
t.messages = an(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
|
|
1666
1671
|
const B = (f) => {
|
|
1667
1672
|
r = f;
|
|
1668
1673
|
}, F = ({ type: f }) => {
|
|
1669
|
-
var R,
|
|
1670
|
-
if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((
|
|
1674
|
+
var R, A, D, b, J;
|
|
1675
|
+
if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((A = t.streamingManager) != null && A.isInterruptible)) return;
|
|
1671
1676
|
const C = t.messages[t.messages.length - 1];
|
|
1672
|
-
|
|
1677
|
+
d.track("agent-video-interrupt", {
|
|
1673
1678
|
type: f || "click",
|
|
1674
1679
|
video_duration_to_interrupt: je.get(!0),
|
|
1675
1680
|
message_duration_to_interrupt: oe.get(!0)
|
|
1676
1681
|
}), C.interrupted = !0, (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "answer"), v ? Rn(t.streamingManager) : (Cn(t.streamingManager, (J = t.streamingManager) == null ? void 0 : J.streamType, r), Sn(t.streamingManager, r));
|
|
1677
|
-
},
|
|
1682
|
+
}, I = /* @__PURE__ */ new Map();
|
|
1678
1683
|
function k(f) {
|
|
1679
1684
|
return async (C) => {
|
|
1680
|
-
const R =
|
|
1685
|
+
const R = I.get(f);
|
|
1681
1686
|
if (!R)
|
|
1682
1687
|
throw new Error(`No handler registered for client tool: ${f}`);
|
|
1683
1688
|
try {
|
|
1684
|
-
const
|
|
1685
|
-
return await R(
|
|
1686
|
-
} catch (
|
|
1687
|
-
throw new Error(`Client tool "${f}" failed: ${
|
|
1689
|
+
const A = JSON.parse(C.payload);
|
|
1690
|
+
return await R(A);
|
|
1691
|
+
} catch (A) {
|
|
1692
|
+
throw new Error(`Client tool "${f}" failed: ${A.message}`);
|
|
1688
1693
|
}
|
|
1689
1694
|
};
|
|
1690
1695
|
}
|
|
1691
1696
|
function Y() {
|
|
1692
|
-
var f, C, R,
|
|
1693
|
-
for (const [D] of
|
|
1694
|
-
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (
|
|
1697
|
+
var f, C, R, A;
|
|
1698
|
+
for (const [D] of I)
|
|
1699
|
+
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (A = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || A.call(R, D, k(D));
|
|
1695
1700
|
}
|
|
1696
1701
|
function Q(f, C) {
|
|
1697
|
-
var
|
|
1698
|
-
const R = !
|
|
1699
|
-
|
|
1702
|
+
var A, D;
|
|
1703
|
+
const R = !I.has(f);
|
|
1704
|
+
I.set(f, C), R && ((D = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || D.call(A, f, k(f)));
|
|
1700
1705
|
}
|
|
1701
1706
|
function U(f) {
|
|
1702
1707
|
var C, R;
|
|
1703
|
-
|
|
1708
|
+
I.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
|
|
1704
1709
|
}
|
|
1705
1710
|
const te = Date.now();
|
|
1706
1711
|
tt(() => {
|
|
1707
|
-
|
|
1712
|
+
d.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
|
|
1708
1713
|
});
|
|
1709
1714
|
async function ne(f) {
|
|
1710
|
-
var J, w, y,
|
|
1711
|
-
(w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J,
|
|
1712
|
-
const C =
|
|
1715
|
+
var J, w, y, T, j, G, he;
|
|
1716
|
+
(w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J, x.Connecting), oe.reset(), f && !i && (delete t.chat, (T = (y = n.callbacks).onNewMessage) == null || T.call(y, [...t.messages], "answer"));
|
|
1717
|
+
const C = c === O.DirectPlayback || v ? Promise.resolve(void 0) : Mn(
|
|
1713
1718
|
n.auth,
|
|
1714
1719
|
a,
|
|
1715
|
-
{ onMessage:
|
|
1720
|
+
{ onMessage: P, onError: n.callbacks.onError },
|
|
1716
1721
|
n.externalId
|
|
1717
1722
|
), R = xe(
|
|
1718
1723
|
() => On(
|
|
1719
1724
|
l,
|
|
1720
1725
|
{
|
|
1721
1726
|
...n,
|
|
1722
|
-
mode:
|
|
1727
|
+
mode: c,
|
|
1723
1728
|
callbacks: {
|
|
1724
1729
|
...n.callbacks,
|
|
1725
1730
|
onVideoIdChange: B,
|
|
1726
|
-
onMessage:
|
|
1731
|
+
onMessage: P,
|
|
1727
1732
|
onInterruptDetected: F
|
|
1728
1733
|
}
|
|
1729
1734
|
},
|
|
1730
1735
|
g,
|
|
1731
|
-
|
|
1736
|
+
d,
|
|
1732
1737
|
t.chat
|
|
1733
1738
|
),
|
|
1734
1739
|
{
|
|
@@ -1740,21 +1745,21 @@ async function qn(e, n) {
|
|
|
1740
1745
|
}
|
|
1741
1746
|
).catch((Z) => {
|
|
1742
1747
|
var z, ee;
|
|
1743
|
-
throw
|
|
1744
|
-
}), [
|
|
1745
|
-
b && b.id !== ((
|
|
1748
|
+
throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, x.Fail), Z;
|
|
1749
|
+
}), [A, { streamingManager: D, chat: b }] = await Promise.all([C, R]);
|
|
1750
|
+
b && b.id !== ((j = t.chat) == null ? void 0 : j.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = D, t.socketManager = A, t.chat = b, Y(), i = !1, d.enrich({
|
|
1746
1751
|
chatId: b == null ? void 0 : b.id,
|
|
1747
1752
|
streamId: D == null ? void 0 : D.streamId,
|
|
1748
1753
|
mode: t.chatMode
|
|
1749
|
-
}),
|
|
1754
|
+
}), K((b == null ? void 0 : b.chat_mode) ?? c);
|
|
1750
1755
|
}
|
|
1751
|
-
async function
|
|
1752
|
-
var f, C, R,
|
|
1753
|
-
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (
|
|
1756
|
+
async function $() {
|
|
1757
|
+
var f, C, R, A;
|
|
1758
|
+
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R, x.Disconnected);
|
|
1754
1759
|
}
|
|
1755
|
-
async function
|
|
1760
|
+
async function K(f) {
|
|
1756
1761
|
var C, R;
|
|
1757
|
-
f !== t.chatMode && (
|
|
1762
|
+
f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
|
|
1758
1763
|
}
|
|
1759
1764
|
return {
|
|
1760
1765
|
agent: l,
|
|
@@ -1768,10 +1773,10 @@ async function qn(e, n) {
|
|
|
1768
1773
|
},
|
|
1769
1774
|
starterMessages: ((ue = l.knowledge) == null ? void 0 : ue.starter_message) || [],
|
|
1770
1775
|
getSTTToken: () => g.getSTTToken(l.id),
|
|
1771
|
-
changeMode:
|
|
1772
|
-
enrichAnalytics:
|
|
1776
|
+
changeMode: K,
|
|
1777
|
+
enrichAnalytics: d.enrich,
|
|
1773
1778
|
async connect() {
|
|
1774
|
-
await ne(!0),
|
|
1779
|
+
await ne(!0), d.track("agent-chat", {
|
|
1775
1780
|
event: "connect",
|
|
1776
1781
|
mode: t.chatMode
|
|
1777
1782
|
});
|
|
@@ -1780,22 +1785,22 @@ async function qn(e, n) {
|
|
|
1780
1785
|
const f = t.streamingManager;
|
|
1781
1786
|
if (v && (f != null && f.reconnect)) {
|
|
1782
1787
|
try {
|
|
1783
|
-
await f.reconnect(),
|
|
1788
|
+
await f.reconnect(), d.track("agent-chat", {
|
|
1784
1789
|
event: "reconnect",
|
|
1785
1790
|
mode: t.chatMode
|
|
1786
1791
|
});
|
|
1787
1792
|
} catch {
|
|
1788
|
-
await
|
|
1793
|
+
await $(), await ne(!1);
|
|
1789
1794
|
}
|
|
1790
1795
|
return;
|
|
1791
1796
|
}
|
|
1792
|
-
await
|
|
1797
|
+
await $(), await ne(!1), d.track("agent-chat", {
|
|
1793
1798
|
event: "reconnect",
|
|
1794
1799
|
mode: t.chatMode
|
|
1795
1800
|
});
|
|
1796
1801
|
},
|
|
1797
1802
|
async disconnect() {
|
|
1798
|
-
await
|
|
1803
|
+
await $(), d.track("agent-chat", {
|
|
1799
1804
|
event: "disconnect",
|
|
1800
1805
|
mode: t.chatMode
|
|
1801
1806
|
});
|
|
@@ -1825,8 +1830,8 @@ async function qn(e, n) {
|
|
|
1825
1830
|
async chat(f) {
|
|
1826
1831
|
var D, b, J, w, y;
|
|
1827
1832
|
const C = () => {
|
|
1828
|
-
if (ft(
|
|
1829
|
-
throw new me(`${
|
|
1833
|
+
if (ft(c))
|
|
1834
|
+
throw new me(`${c} is enabled, chat is disabled`);
|
|
1830
1835
|
if (f.length >= 800)
|
|
1831
1836
|
throw new me("Message cannot be more than 800 characters");
|
|
1832
1837
|
if (f.length === 0)
|
|
@@ -1840,21 +1845,21 @@ async function qn(e, n) {
|
|
|
1840
1845
|
throw new me("Chat is not initialized");
|
|
1841
1846
|
}
|
|
1842
1847
|
}, R = async () => {
|
|
1843
|
-
var
|
|
1848
|
+
var T, j;
|
|
1844
1849
|
if (!t.chat) {
|
|
1845
1850
|
const G = await ht(
|
|
1846
1851
|
l,
|
|
1847
1852
|
g,
|
|
1848
|
-
|
|
1853
|
+
d,
|
|
1849
1854
|
t.chatMode,
|
|
1850
1855
|
n.persistentChat
|
|
1851
1856
|
);
|
|
1852
1857
|
if (!G.chat)
|
|
1853
|
-
throw new
|
|
1854
|
-
t.chat = G.chat, (
|
|
1858
|
+
throw new kt(t.chatMode, !!n.persistentChat);
|
|
1859
|
+
t.chat = G.chat, (j = (T = n.callbacks).onNewChat) == null || j.call(T, t.chat.id);
|
|
1855
1860
|
}
|
|
1856
1861
|
return t.chat.id;
|
|
1857
|
-
},
|
|
1862
|
+
}, A = async (T, j) => {
|
|
1858
1863
|
const G = t.chatMode === O.Playground;
|
|
1859
1864
|
return xe(v && !G ? async () => {
|
|
1860
1865
|
var z, ee;
|
|
@@ -1863,12 +1868,12 @@ async function qn(e, n) {
|
|
|
1863
1868
|
var z, ee;
|
|
1864
1869
|
return g.chat(
|
|
1865
1870
|
l.id,
|
|
1866
|
-
|
|
1871
|
+
j,
|
|
1867
1872
|
{
|
|
1868
1873
|
chatMode: t.chatMode,
|
|
1869
1874
|
streamId: (z = t.streamingManager) == null ? void 0 : z.streamId,
|
|
1870
1875
|
sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
|
|
1871
|
-
messages:
|
|
1876
|
+
messages: T.map(({ matches: De, ...le }) => le)
|
|
1872
1877
|
},
|
|
1873
1878
|
{
|
|
1874
1879
|
...gt(t.chatMode),
|
|
@@ -1878,55 +1883,55 @@ async function qn(e, n) {
|
|
|
1878
1883
|
}, {
|
|
1879
1884
|
limit: 2,
|
|
1880
1885
|
shouldRetryFn: (z) => {
|
|
1881
|
-
var le,
|
|
1886
|
+
var le, Me, pe, we;
|
|
1882
1887
|
const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
|
|
1883
|
-
return !((
|
|
1888
|
+
return !((Me = z == null ? void 0 : z.message) == null ? void 0 : Me.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, z), !1) : !0;
|
|
1884
1889
|
},
|
|
1885
1890
|
onRetry: async () => {
|
|
1886
|
-
await
|
|
1891
|
+
await $(), await ne(!1);
|
|
1887
1892
|
}
|
|
1888
1893
|
});
|
|
1889
1894
|
};
|
|
1890
1895
|
try {
|
|
1891
|
-
|
|
1896
|
+
N(), C(), t.messages.push({
|
|
1892
1897
|
id: ge(),
|
|
1893
1898
|
role: "user",
|
|
1894
1899
|
content: f,
|
|
1895
1900
|
parts: Te(f),
|
|
1896
1901
|
created_at: new Date(oe.update()).toISOString()
|
|
1897
1902
|
}), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "user");
|
|
1898
|
-
const
|
|
1903
|
+
const T = await R(), j = await A([...t.messages], T);
|
|
1899
1904
|
return t.messages.push({
|
|
1900
1905
|
id: ge(),
|
|
1901
1906
|
role: "assistant",
|
|
1902
|
-
content:
|
|
1903
|
-
parts: Te(
|
|
1907
|
+
content: j.result || "",
|
|
1908
|
+
parts: Te(j.result || ""),
|
|
1904
1909
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1905
|
-
context:
|
|
1906
|
-
matches:
|
|
1907
|
-
}),
|
|
1910
|
+
context: j.context,
|
|
1911
|
+
matches: j.matches
|
|
1912
|
+
}), d.track("agent-message-send", {
|
|
1908
1913
|
event: "success",
|
|
1909
1914
|
messages: t.messages.length + 1
|
|
1910
|
-
}),
|
|
1915
|
+
}), j.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), d.track("agent-message-received", {
|
|
1911
1916
|
latency: oe.get(!0),
|
|
1912
1917
|
messages: t.messages.length
|
|
1913
|
-
})),
|
|
1914
|
-
} catch (
|
|
1915
|
-
throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(),
|
|
1918
|
+
})), j;
|
|
1919
|
+
} catch (T) {
|
|
1920
|
+
throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), d.track("agent-message-send", {
|
|
1916
1921
|
event: "error",
|
|
1917
1922
|
messages: t.messages.length
|
|
1918
|
-
}),
|
|
1923
|
+
}), T;
|
|
1919
1924
|
}
|
|
1920
1925
|
},
|
|
1921
1926
|
rate(f, C, R) {
|
|
1922
1927
|
var b, J, w, y;
|
|
1923
|
-
const
|
|
1928
|
+
const A = t.messages.find((T) => T.id === f);
|
|
1924
1929
|
if (t.chat) {
|
|
1925
|
-
if (!
|
|
1930
|
+
if (!A)
|
|
1926
1931
|
throw new Error("Message not found");
|
|
1927
1932
|
} else throw new Error("Chat is not initialized");
|
|
1928
|
-
const D = ((b =
|
|
1929
|
-
return
|
|
1933
|
+
const D = ((b = A.matches) == null ? void 0 : b.map((T) => [T.document_id, T.id])) ?? [];
|
|
1934
|
+
return d.track("agent-rate", {
|
|
1930
1935
|
event: R ? "update" : "create",
|
|
1931
1936
|
thumb: C === 1 ? "up" : "down",
|
|
1932
1937
|
knowledge_id: ((J = l.knowledge) == null ? void 0 : J.id) ?? "",
|
|
@@ -1947,7 +1952,7 @@ async function qn(e, n) {
|
|
|
1947
1952
|
deleteRate(f) {
|
|
1948
1953
|
if (!t.chat)
|
|
1949
1954
|
throw new Error("Chat is not initialized");
|
|
1950
|
-
return
|
|
1955
|
+
return d.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
|
|
1951
1956
|
},
|
|
1952
1957
|
async speak(f) {
|
|
1953
1958
|
var D, b, J;
|
|
@@ -1975,7 +1980,7 @@ async function qn(e, n) {
|
|
|
1975
1980
|
return f;
|
|
1976
1981
|
}
|
|
1977
1982
|
const R = C();
|
|
1978
|
-
if (
|
|
1983
|
+
if (d.track("agent-speak", R), oe.update(), t.messages && R.type === "text" && (t.messages.push({
|
|
1979
1984
|
id: ge(),
|
|
1980
1985
|
role: "assistant",
|
|
1981
1986
|
content: R.input,
|
|
@@ -2002,23 +2007,23 @@ async function qn(e, n) {
|
|
|
2002
2007
|
export {
|
|
2003
2008
|
W as AgentActivityState,
|
|
2004
2009
|
bt as AgentStatus,
|
|
2005
|
-
|
|
2010
|
+
kt as ChatCreationFailed,
|
|
2006
2011
|
O as ChatMode,
|
|
2007
2012
|
It as ChatModeDowngraded,
|
|
2008
2013
|
X as ChatProgress,
|
|
2009
|
-
|
|
2014
|
+
x as ConnectionState,
|
|
2010
2015
|
ae as ConnectivityState,
|
|
2011
2016
|
$t as DocumentType,
|
|
2012
2017
|
xt as KnowledgeType,
|
|
2013
|
-
|
|
2018
|
+
_t as PlanGroup,
|
|
2014
2019
|
jt as Providers,
|
|
2015
2020
|
Lt as RateState,
|
|
2016
|
-
|
|
2021
|
+
M as StreamEvents,
|
|
2017
2022
|
se as StreamType,
|
|
2018
|
-
|
|
2023
|
+
E as StreamingState,
|
|
2019
2024
|
Pt as Subject,
|
|
2020
|
-
|
|
2021
|
-
|
|
2025
|
+
Ne as TransportProvider,
|
|
2026
|
+
At as UserPlan,
|
|
2022
2027
|
me as ValidationError,
|
|
2023
2028
|
dt as VideoType,
|
|
2024
2029
|
Bt as VoiceAccess,
|