@d-id/client-sdk 1.1.58-staging.273 → 1.1.59
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 +269 -269
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ class Dt extends Ie {
|
|
|
35
35
|
super({ kind: "WSError", description: n });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var _t = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_t || {}), At = /* @__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))(At || {}), 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 T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), I = /* @__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))(I || {}), P = /* @__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))(P || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}),
|
|
52
|
-
const Ft = 45 * 1e3,
|
|
51
|
+
var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), I = /* @__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))(I || {}), P = /* @__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))(P || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ke = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ke || {}), 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, Kt = "X-Playground-Chat", Ee = "https://api.d-id.com", Nt = "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, Nt = "X-Playground-Chat", Ee = "https://api.d-id.com", Kt =
|
|
|
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, Ne = (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], d = { type: "image", src: o, alt: i[1] };
|
|
80
|
+
o.toLowerCase().endsWith(".gif") && (d.mimeType = "image/gif"), n.push({ index: i.index, length: i[0].length, part: d });
|
|
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), d = e().finally(o);
|
|
132
|
+
return await Promise.race([d, 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: d, ...t } = o || {}, c = 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 (!c.ok) {
|
|
179
|
+
let h = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
|
|
180
180
|
const g = new Error(h);
|
|
181
|
-
throw i && !
|
|
181
|
+
throw i && !d && i(g, { url: a, options: t, headers: c.headers }), g;
|
|
182
182
|
}
|
|
183
|
-
return
|
|
183
|
+
return c.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, d) {
|
|
190
|
+
return s(a, { ...d, body: JSON.stringify(o), method: "POST" });
|
|
191
191
|
},
|
|
192
|
-
delete(a, o,
|
|
193
|
-
return s(a, { ...
|
|
192
|
+
delete(a, o, d) {
|
|
193
|
+
return s(a, { ...d, body: JSON.stringify(o), method: "DELETE" });
|
|
194
194
|
},
|
|
195
|
-
patch(a, o,
|
|
196
|
-
return s(a, { ...
|
|
195
|
+
patch(a, o, d) {
|
|
196
|
+
return s(a, { ...d, 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((d) => d ?? []);
|
|
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, d) {
|
|
216
|
+
return s.patch(`/${a}`, o, d);
|
|
217
217
|
},
|
|
218
|
-
newChat(a, o,
|
|
219
|
-
return s.post(`/${a}/chat`, o,
|
|
218
|
+
newChat(a, o, d) {
|
|
219
|
+
return s.post(`/${a}/chat`, o, d);
|
|
220
220
|
},
|
|
221
|
-
chat(a, o,
|
|
222
|
-
return s.post(`/${a}/chat/${o}`,
|
|
221
|
+
chat(a, o, d, t) {
|
|
222
|
+
return s.post(`/${a}/chat/${o}`, d, t);
|
|
223
223
|
},
|
|
224
|
-
createRating(a, o,
|
|
225
|
-
return s.post(`/${a}/chat/${o}/ratings`,
|
|
224
|
+
createRating(a, o, d, t) {
|
|
225
|
+
return s.post(`/${a}/chat/${o}/ratings`, d, t);
|
|
226
226
|
},
|
|
227
|
-
updateRating(a, o,
|
|
228
|
-
return s.patch(`/${a}/chat/${o}/ratings/${
|
|
227
|
+
updateRating(a, o, d, t, c) {
|
|
228
|
+
return s.patch(`/${a}/chat/${o}/ratings/${d}`, t, c);
|
|
229
229
|
},
|
|
230
|
-
deleteRating(a, o,
|
|
231
|
-
return s.delete(`/${a}/chat/${o}/ratings/${
|
|
230
|
+
deleteRating(a, o, d, t) {
|
|
231
|
+
return s.delete(`/${a}/chat/${o}/ratings/${d}`, 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, d;
|
|
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: (d = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : d.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, d;
|
|
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: (d = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : d.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, c, 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: { ...(c = s == null ? void 0 : s.script) == null ? void 0 : c.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, ...d } = s || {}, t = a || Date.now(), c = {
|
|
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
|
+
...d,
|
|
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, c).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 d = i[r];
|
|
346
|
+
if (d.events[a] = { props: s }, d.resolvedDependencies.push(a), o.every(
|
|
347
|
+
(c) => d.resolvedDependencies.includes(c)
|
|
348
348
|
)) {
|
|
349
|
-
const
|
|
350
|
-
this.track(r,
|
|
349
|
+
const c = o.reduce((h, g) => d.events[g] ? { ...h, ...d.events[g].props } : h, {});
|
|
350
|
+
this.track(r, c), d.resolvedDependencies = d.resolvedDependencies.filter(
|
|
351
351
|
(h) => !o.includes(h)
|
|
352
352
|
), o.forEach((h) => {
|
|
353
|
-
delete
|
|
353
|
+
delete d.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: { [Kt]: "true" } } : {};
|
|
370
370
|
}
|
|
371
371
|
async function ht(e, n, i, r, s = !1, a) {
|
|
372
372
|
try {
|
|
@@ -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, c) => c === 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 * c / 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[c - 1].bytesReceived,
|
|
506
|
+
bitrate: (t.bytesReceived - e[c - 1].bytesReceived) * 8 / (n / 1e3),
|
|
507
|
+
packetsReceived: t.packetsReceived - e[c - 1].packetsReceived,
|
|
508
|
+
packetsLost: t.packetsLost - e[c - 1].packetsLost,
|
|
509
|
+
framesDropped: t.framesDropped - e[c - 1].framesDropped,
|
|
510
|
+
framesDecoded: t.framesDecoded - e[c - 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[c - 1].jitterBufferDelay,
|
|
513
|
+
jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[c - 1].jitterBufferEmittedCount,
|
|
514
|
+
avgJitterDelayInInterval: (t.jitterBufferDelay - e[c - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[c - 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[c - 1].freezeCount,
|
|
517
|
+
freezeDuration: t.freezeDuration - e[c - 1].freezeDuration
|
|
518
|
+
}), s = dn(r), a = s.reduce((t, c) => t + (c.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), d = 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(...d),
|
|
523
|
+
avgRtt: et(d),
|
|
524
|
+
maxRtt: Math.max(...d),
|
|
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, d = {};
|
|
543
543
|
async function t() {
|
|
544
544
|
if (i) {
|
|
545
545
|
try {
|
|
546
|
-
const
|
|
547
|
-
if (!
|
|
546
|
+
const c = await e();
|
|
547
|
+
if (!c) {
|
|
548
548
|
s = setTimeout(t, Se);
|
|
549
549
|
return;
|
|
550
550
|
}
|
|
551
|
-
const h = wt(
|
|
551
|
+
const h = wt(c, "audio");
|
|
552
552
|
if (!h) {
|
|
553
553
|
s = setTimeout(t, Se);
|
|
554
554
|
return;
|
|
@@ -560,7 +560,7 @@ function ln(e, n) {
|
|
|
560
560
|
}
|
|
561
561
|
const v = g - a, L = l - o;
|
|
562
562
|
if (a = g, o = l, L > 0 && v > 0) {
|
|
563
|
-
i = !1, n(
|
|
563
|
+
i = !1, n(d);
|
|
564
564
|
return;
|
|
565
565
|
}
|
|
566
566
|
} catch {
|
|
@@ -569,8 +569,8 @@ function ln(e, n) {
|
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
return {
|
|
572
|
-
arm(
|
|
573
|
-
|
|
572
|
+
arm(c = {}) {
|
|
573
|
+
d = c, 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);
|
|
@@ -584,39 +584,39 @@ function hn() {
|
|
|
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, d = a.jitterBufferEmittedCount;
|
|
588
|
+
if (i && d > i) {
|
|
589
|
+
const h = o - n, g = d - 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 = d;
|
|
593
|
+
const t = a.framesDecoded, c = t - e > 0;
|
|
594
|
+
return e = t, { isReceiving: c, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
597
|
function yt(e, n, i, r, s) {
|
|
598
|
-
let a = null, o = [],
|
|
598
|
+
let a = null, o = [], d, t = 0, c = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
|
|
599
599
|
const L = hn();
|
|
600
|
-
async function
|
|
600
|
+
async function K() {
|
|
601
601
|
const B = await e();
|
|
602
602
|
if (!B)
|
|
603
603
|
return;
|
|
604
604
|
const { isReceiving: F, avgJitterDelayInInterval: M, freezeCount: k } = L(B), Y = un(B);
|
|
605
605
|
if (F)
|
|
606
|
-
t = 0, l = k - v, g = M < mn ? ae.Strong : M > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0),
|
|
607
|
-
else if (
|
|
608
|
-
const Q = rt(o, Me,
|
|
609
|
-
r == null || r(T.Stop, Q), n() || i(), v = k,
|
|
606
|
+
t = 0, l = k - v, g = M < mn ? ae.Strong : M > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0), c || (r == null || r(T.Start), d = o[o.length - 1], o = [], c = !0), o.push(Y);
|
|
607
|
+
else if (c && (t++, t >= fn)) {
|
|
608
|
+
const Q = rt(o, Me, d);
|
|
609
|
+
r == null || r(T.Stop, Q), n() || i(), v = k, c = !1;
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
return {
|
|
613
613
|
start: () => {
|
|
614
|
-
a || (a = setInterval(
|
|
614
|
+
a || (a = setInterval(K, Me));
|
|
615
615
|
},
|
|
616
616
|
stop: () => {
|
|
617
617
|
a && (clearInterval(a), a = null);
|
|
618
618
|
},
|
|
619
|
-
getReport: () => rt(o, Me,
|
|
619
|
+
getReport: () => rt(o, Me, d)
|
|
620
620
|
};
|
|
621
621
|
}
|
|
622
622
|
const it = 2e4;
|
|
@@ -646,10 +646,10 @@ function Be(e, n, i) {
|
|
|
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: d } = await pn(), { callbacks: t, auth: c, baseURL: h, analytics: g } = i;
|
|
650
650
|
let l = null, v = !1;
|
|
651
651
|
const L = se.Fluent;
|
|
652
|
-
let
|
|
652
|
+
let K = null;
|
|
653
653
|
const B = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
|
|
654
654
|
let M = null, k = null, Y = null, Q = !1;
|
|
655
655
|
l = new s({
|
|
@@ -658,20 +658,20 @@ async function yn(e, n, i) {
|
|
|
658
658
|
dynacast: !0
|
|
659
659
|
});
|
|
660
660
|
let U = null, te = W.Idle, ne = !0;
|
|
661
|
-
const x = on(
|
|
662
|
-
let
|
|
661
|
+
const x = on(c, h || Ee, e, t.onError);
|
|
662
|
+
let N, H, re, de = !0;
|
|
663
663
|
try {
|
|
664
664
|
const u = await x.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: A } = u;
|
|
668
|
+
(Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), N = m, H = p, re = S, de = A ?? !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 || !N)
|
|
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, _).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,8 +683,8 @@ 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: N
|
|
687
|
+
}), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: N }), Le("internal:track-subscription-timeout");
|
|
688
688
|
}, it);
|
|
689
689
|
} catch (u) {
|
|
690
690
|
Be(u, r, t);
|
|
@@ -693,7 +693,7 @@ async function yn(e, n, i) {
|
|
|
693
693
|
"stream-type": L
|
|
694
694
|
});
|
|
695
695
|
function f(u) {
|
|
696
|
-
var m, p, S,
|
|
696
|
+
var m, p, S, A;
|
|
697
697
|
switch (r("Connection state changed:", u), u) {
|
|
698
698
|
case o.Connecting:
|
|
699
699
|
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, P.Connecting, "livekit:connecting");
|
|
@@ -708,7 +708,7 @@ async function yn(e, n, i) {
|
|
|
708
708
|
r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, P.Connecting, "livekit:reconnecting");
|
|
709
709
|
break;
|
|
710
710
|
case o.SignalReconnecting:
|
|
711
|
-
r("LiveKit room signal reconnecting..."), (
|
|
711
|
+
r("LiveKit room signal reconnecting..."), (A = t.onConnectionStateChange) == null || A.call(t, P.Connecting, "livekit:signal-reconnecting");
|
|
712
712
|
break;
|
|
713
713
|
}
|
|
714
714
|
}
|
|
@@ -719,7 +719,7 @@ async function yn(e, n, i) {
|
|
|
719
719
|
function R(u) {
|
|
720
720
|
r("Participant connected:", u.identity);
|
|
721
721
|
}
|
|
722
|
-
function
|
|
722
|
+
function _(u) {
|
|
723
723
|
r("Participant disconnected:", u.identity), Le("livekit:participant-disconnected");
|
|
724
724
|
}
|
|
725
725
|
function D() {
|
|
@@ -731,14 +731,14 @@ async function yn(e, n, i) {
|
|
|
731
731
|
Y !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
|
|
732
732
|
}
|
|
733
733
|
function J(u, m, p) {
|
|
734
|
-
var
|
|
734
|
+
var A, j, 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
|
+
K ? (K.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (K = 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;
|
|
@@ -751,7 +751,7 @@ async function yn(e, n, i) {
|
|
|
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" && ((A = t.onStreamReady) == null || A.call(t), r("CALLBACK: onSrcObjectReady"), (j = t.onSrcObjectReady) == null || j.call(t, K), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, P.Connected, "livekit:track-subscribed")), M = yt(
|
|
755
755
|
() => u.getRTCStatsReport(),
|
|
756
756
|
() => v,
|
|
757
757
|
Vt,
|
|
@@ -769,17 +769,17 @@ async function yn(e, n, i) {
|
|
|
769
769
|
p && ((S = t.onMessage) == null || S.call(t, p, { event: p, ...m }));
|
|
770
770
|
}
|
|
771
771
|
function E(u, m) {
|
|
772
|
-
var p, S,
|
|
772
|
+
var p, S, A;
|
|
773
773
|
if (u === I.ToolCalling) {
|
|
774
774
|
te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, I.ToolCalling, m);
|
|
775
775
|
return;
|
|
776
776
|
}
|
|
777
|
-
u === I.ToolResult && ((
|
|
777
|
+
u === I.ToolResult && ((A = t.onToolEvent) == null || A.call(t, I.ToolResult, m));
|
|
778
778
|
}
|
|
779
779
|
function $(u, m) {
|
|
780
|
-
var p, S,
|
|
780
|
+
var p, S, A, j, q;
|
|
781
781
|
if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === I.StreamVideoCreated) {
|
|
782
|
-
te = W.Talking, (
|
|
782
|
+
te = W.Talking, (A = t.onAgentActivityStateChange) == null || A.call(t, W.Talking), k == null || k.arm({
|
|
783
783
|
sttLatency: (j = m == null ? void 0 : m.stt) == null ? void 0 : j.latency,
|
|
784
784
|
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
785
785
|
});
|
|
@@ -789,11 +789,11 @@ async function yn(e, n, i) {
|
|
|
789
789
|
}
|
|
790
790
|
function G(u, m) {
|
|
791
791
|
var j, q, V, ie;
|
|
792
|
-
const p = ((q = (j = M == null ? void 0 : M.getReport()) == null ? void 0 : j.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0,
|
|
793
|
-
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (
|
|
792
|
+
const p = ((q = (j = M == null ? void 0 : M.getReport()) == null ? void 0 : j.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, A = { ...m, downstreamNetworkLatency: S };
|
|
793
|
+
i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (A.sentiment = {
|
|
794
794
|
id: m.metadata.sentiment.id,
|
|
795
795
|
name: m.metadata.sentiment.sentiment
|
|
796
|
-
}), (ie = t.onMessage) == null || ie.call(t, u,
|
|
796
|
+
}), (ie = t.onMessage) == null || ie.call(t, u, A), $(u, m);
|
|
797
797
|
}
|
|
798
798
|
function he(u, m) {
|
|
799
799
|
var p;
|
|
@@ -814,9 +814,9 @@ async function yn(e, n, i) {
|
|
|
814
814
|
[I.ChatAudioTranscribed]: he
|
|
815
815
|
};
|
|
816
816
|
function z(u, m, p, S) {
|
|
817
|
-
const
|
|
817
|
+
const A = new TextDecoder().decode(u);
|
|
818
818
|
try {
|
|
819
|
-
const j = JSON.parse(
|
|
819
|
+
const j = JSON.parse(A), q = S || j.subject;
|
|
820
820
|
if (r("Data received:", { subject: q, data: j }), !q) return;
|
|
821
821
|
const V = Z[q];
|
|
822
822
|
V == null || V(q, j);
|
|
@@ -826,25 +826,25 @@ async function yn(e, n, i) {
|
|
|
826
826
|
}
|
|
827
827
|
function ee(u) {
|
|
828
828
|
var m;
|
|
829
|
-
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId:
|
|
829
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: N });
|
|
830
830
|
}
|
|
831
831
|
function De(u) {
|
|
832
832
|
var m;
|
|
833
|
-
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId:
|
|
833
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: N });
|
|
834
834
|
}
|
|
835
835
|
function le(u, m, p) {
|
|
836
836
|
r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
|
|
837
837
|
}
|
|
838
838
|
function ke(u, m, p) {
|
|
839
|
-
for (const [S,
|
|
840
|
-
if (
|
|
841
|
-
const j =
|
|
839
|
+
for (const [S, A] of p)
|
|
840
|
+
if (A.source === m && A.track) {
|
|
841
|
+
const j = A.track.mediaStreamTrack;
|
|
842
842
|
if (j === u || (j == null ? void 0 : j.id) === u.id)
|
|
843
|
-
return
|
|
843
|
+
return A;
|
|
844
844
|
}
|
|
845
845
|
return null;
|
|
846
846
|
}
|
|
847
|
-
async function pe(u, m, p, S,
|
|
847
|
+
async function pe(u, m, p, S, A, j) {
|
|
848
848
|
var ye, ve, fe;
|
|
849
849
|
if (!v || !l)
|
|
850
850
|
throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
|
|
@@ -855,7 +855,7 @@ async function yn(e, n, i) {
|
|
|
855
855
|
const q = p(m);
|
|
856
856
|
if (q.length === 0)
|
|
857
857
|
throw new Error(`No ${S} track found in the provided MediaStream`);
|
|
858
|
-
const V = q[0], ie = ke(V, S,
|
|
858
|
+
const V = q[0], ie = ke(V, S, A());
|
|
859
859
|
if (ie) {
|
|
860
860
|
r(`${S} track is already published, skipping`, {
|
|
861
861
|
trackId: V.id,
|
|
@@ -891,12 +891,12 @@ async function yn(e, n, i) {
|
|
|
891
891
|
B,
|
|
892
892
|
u,
|
|
893
893
|
(m) => m.getAudioTracks(),
|
|
894
|
-
|
|
894
|
+
d.Source.Microphone,
|
|
895
895
|
() => l.localParticipant.audioTrackPublications,
|
|
896
|
-
|
|
896
|
+
_e
|
|
897
897
|
);
|
|
898
898
|
}
|
|
899
|
-
async function
|
|
899
|
+
async function _e() {
|
|
900
900
|
return we(B, "Microphone");
|
|
901
901
|
}
|
|
902
902
|
async function Ct(u) {
|
|
@@ -904,29 +904,29 @@ async function yn(e, n, i) {
|
|
|
904
904
|
F,
|
|
905
905
|
u,
|
|
906
906
|
(m) => m.getVideoTracks(),
|
|
907
|
-
|
|
907
|
+
d.Source.Camera,
|
|
908
908
|
() => l.localParticipant.videoTrackPublications,
|
|
909
|
-
|
|
909
|
+
Ae
|
|
910
910
|
);
|
|
911
911
|
}
|
|
912
|
-
async function
|
|
912
|
+
async function Ae() {
|
|
913
913
|
return we(F, "Camera");
|
|
914
914
|
}
|
|
915
915
|
function St() {
|
|
916
|
-
|
|
916
|
+
K && (K.getTracks().forEach((u) => u.stop()), K = null);
|
|
917
917
|
}
|
|
918
918
|
async function be(u, m) {
|
|
919
919
|
var p, S;
|
|
920
920
|
if (!v || !l) {
|
|
921
921
|
r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(Re), {
|
|
922
|
-
sessionId:
|
|
922
|
+
sessionId: N
|
|
923
923
|
});
|
|
924
924
|
return;
|
|
925
925
|
}
|
|
926
926
|
try {
|
|
927
927
|
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
928
|
-
} catch (
|
|
929
|
-
r("Failed to send message:",
|
|
928
|
+
} catch (A) {
|
|
929
|
+
r("Failed to send message:", A), (S = t.onError) == null || S.call(t, new Error(Re), { sessionId: N });
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
async function Rt(u) {
|
|
@@ -935,7 +935,7 @@ async function yn(e, n, i) {
|
|
|
935
935
|
const S = JSON.parse(u).topic;
|
|
936
936
|
return be("", S);
|
|
937
937
|
} catch (p) {
|
|
938
|
-
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId:
|
|
938
|
+
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: N });
|
|
939
939
|
}
|
|
940
940
|
}
|
|
941
941
|
function Tt(u) {
|
|
@@ -947,7 +947,7 @@ async function yn(e, n, i) {
|
|
|
947
947
|
}
|
|
948
948
|
async function Le(u) {
|
|
949
949
|
var m, p;
|
|
950
|
-
U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, P.Disconnecting, u), await Promise.all([
|
|
950
|
+
U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, P.Disconnecting, u), await Promise.all([_e(), Ae()]), await l.disconnect()), St(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
|
|
951
951
|
}
|
|
952
952
|
return {
|
|
953
953
|
speak(u) {
|
|
@@ -971,10 +971,10 @@ async function yn(e, n, i) {
|
|
|
971
971
|
try {
|
|
972
972
|
if (await l.connect(re, H), r("Room reconnected"), v = !0, l.remoteParticipants.size === 0) {
|
|
973
973
|
if (r("Waiting for agent to join..."), !await new Promise((S) => {
|
|
974
|
-
const
|
|
974
|
+
const A = setTimeout(() => {
|
|
975
975
|
l == null || l.off(a.ParticipantConnected, j), S(!1);
|
|
976
976
|
}, 5e3), j = () => {
|
|
977
|
-
clearTimeout(
|
|
977
|
+
clearTimeout(A), l == null || l.off(a.ParticipantConnected, j), S(!0);
|
|
978
978
|
};
|
|
979
979
|
l == null || l.on(a.ParticipantConnected, j);
|
|
980
980
|
}))
|
|
@@ -988,17 +988,17 @@ async function yn(e, n, i) {
|
|
|
988
988
|
sendDataChannelMessage: Rt,
|
|
989
989
|
sendTextMessage: Tt,
|
|
990
990
|
publishMicrophoneStream: vt,
|
|
991
|
-
unpublishMicrophoneStream:
|
|
991
|
+
unpublishMicrophoneStream: _e,
|
|
992
992
|
publishCameraStream: Ct,
|
|
993
|
-
unpublishCameraStream:
|
|
993
|
+
unpublishCameraStream: Ae,
|
|
994
994
|
registerRpcMethod(u, m) {
|
|
995
995
|
l == null || l.registerRpcMethod(u, m);
|
|
996
996
|
},
|
|
997
997
|
unregisterRpcMethod(u) {
|
|
998
998
|
l == null || l.unregisterRpcMethod(u);
|
|
999
999
|
},
|
|
1000
|
-
sessionId:
|
|
1001
|
-
streamId:
|
|
1000
|
+
sessionId: N,
|
|
1001
|
+
streamId: N,
|
|
1002
1002
|
streamType: L,
|
|
1003
1003
|
interruptAvailable: de,
|
|
1004
1004
|
isInterruptible: ne
|
|
@@ -1036,8 +1036,8 @@ async function Rn(e) {
|
|
|
1036
1036
|
}
|
|
1037
1037
|
function Tn(e) {
|
|
1038
1038
|
return new Promise((n, i) => {
|
|
1039
|
-
const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage:
|
|
1040
|
-
g.onmessage =
|
|
1039
|
+
const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: h = null } = r || {}, g = new WebSocket(`${s}?authorization=${encodeURIComponent(mt(a, o))}`);
|
|
1040
|
+
g.onmessage = d, g.onclose = c, g.onerror = (l) => {
|
|
1041
1041
|
console.error(l), h == null || h("Websocket failed to connect", l), i(l);
|
|
1042
1042
|
}, g.onopen = (l) => {
|
|
1043
1043
|
t == null || t(l), n(g);
|
|
@@ -1064,12 +1064,12 @@ async function kn(e, n, i, r) {
|
|
|
1064
1064
|
externalId: r,
|
|
1065
1065
|
callbacks: {
|
|
1066
1066
|
onError: (o) => {
|
|
1067
|
-
var
|
|
1068
|
-
return (
|
|
1067
|
+
var d;
|
|
1068
|
+
return (d = i.onError) == null ? void 0 : d.call(i, new Dt(o));
|
|
1069
1069
|
},
|
|
1070
1070
|
onMessage(o) {
|
|
1071
|
-
const
|
|
1072
|
-
s.forEach((t) => t(
|
|
1071
|
+
const d = JSON.parse(o.data);
|
|
1072
|
+
s.forEach((t) => t(d.event, d));
|
|
1073
1073
|
}
|
|
1074
1074
|
}
|
|
1075
1075
|
});
|
|
@@ -1102,99 +1102,99 @@ function In(e, n, i) {
|
|
|
1102
1102
|
};
|
|
1103
1103
|
n.messages.push(s), i == null || i([...n.messages], "user");
|
|
1104
1104
|
}
|
|
1105
|
-
function Dn(e, n, i, r, s
|
|
1105
|
+
function Dn(e, n, i, r, s) {
|
|
1106
1106
|
if (e === X.Transcribe && n.content) {
|
|
1107
1107
|
In(n, r, s);
|
|
1108
1108
|
return;
|
|
1109
1109
|
}
|
|
1110
1110
|
if (!(e === X.Partial || e === X.Answer))
|
|
1111
1111
|
return;
|
|
1112
|
-
const
|
|
1113
|
-
let
|
|
1114
|
-
if ((
|
|
1115
|
-
|
|
1116
|
-
else if (!
|
|
1117
|
-
|
|
1112
|
+
const a = r.messages[r.messages.length - 1];
|
|
1113
|
+
let o;
|
|
1114
|
+
if ((a == null ? void 0 : a.role) === "assistant")
|
|
1115
|
+
o = a;
|
|
1116
|
+
else if (!a || a.transcribed && a.role === "user")
|
|
1117
|
+
o = {
|
|
1118
1118
|
id: n.id || `assistant-${Date.now()}`,
|
|
1119
1119
|
role: n.role || "assistant",
|
|
1120
1120
|
content: n.content || "",
|
|
1121
1121
|
parts: [],
|
|
1122
1122
|
created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
1123
|
-
}, r.messages.push(
|
|
1123
|
+
}, r.messages.push(o);
|
|
1124
1124
|
else
|
|
1125
1125
|
return;
|
|
1126
|
-
const { content: d, sequence:
|
|
1127
|
-
e === X.Partial ? i[
|
|
1128
|
-
const
|
|
1129
|
-
(
|
|
1126
|
+
const { content: d, sequence: t } = n;
|
|
1127
|
+
e === X.Partial ? i[t] = d : i.answer = d;
|
|
1128
|
+
const c = Mn(i);
|
|
1129
|
+
(o.content !== c || e === X.Answer) && (o.content = c, o.parts = Te(c), s == null || s([...r.messages], e));
|
|
1130
1130
|
}
|
|
1131
|
-
function
|
|
1131
|
+
function _n(e, n, i, r, s) {
|
|
1132
1132
|
let a = {};
|
|
1133
1133
|
const o = () => a = {};
|
|
1134
|
-
let
|
|
1135
|
-
const t = (
|
|
1134
|
+
let d = "answer";
|
|
1135
|
+
const t = (c, h) => {
|
|
1136
1136
|
var g, l;
|
|
1137
|
-
h === "user" && o(),
|
|
1137
|
+
h === "user" && o(), d = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, h);
|
|
1138
1138
|
};
|
|
1139
1139
|
return {
|
|
1140
1140
|
clearQueue: o,
|
|
1141
|
-
onMessage: (
|
|
1141
|
+
onMessage: (c, h) => {
|
|
1142
1142
|
var g, l;
|
|
1143
1143
|
if ("content" in h) {
|
|
1144
|
-
const v =
|
|
1145
|
-
Dn(v, h, a, n, t
|
|
1144
|
+
const v = c === I.ChatAnswer ? X.Answer : c === I.ChatAudioTranscribed ? X.Transcribe : c;
|
|
1145
|
+
Dn(v, h, a, n, t), v === X.Answer && e.track("agent-message-received", {
|
|
1146
1146
|
content: h.content,
|
|
1147
1147
|
messages: n.messages.length,
|
|
1148
1148
|
mode: n.chatMode
|
|
1149
1149
|
});
|
|
1150
1150
|
} else {
|
|
1151
|
-
const v = I, L = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected],
|
|
1152
|
-
if (
|
|
1151
|
+
const v = I, L = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], K = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
|
|
1152
|
+
if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1153
1153
|
const F = n.messages[n.messages.length - 1];
|
|
1154
1154
|
if ((F == null ? void 0 : F.role) === "assistant") {
|
|
1155
1155
|
const M = { ...F, sentiment: h.sentiment };
|
|
1156
|
-
n.messages[n.messages.length - 1] = M, t == null || t([...n.messages],
|
|
1156
|
+
n.messages[n.messages.length - 1] = M, t == null || t([...n.messages], d);
|
|
1157
1157
|
}
|
|
1158
1158
|
}
|
|
1159
|
-
if (L.includes(
|
|
1160
|
-
const F =
|
|
1161
|
-
|
|
1159
|
+
if (L.includes(c)) {
|
|
1160
|
+
const F = c.split("/")[1];
|
|
1161
|
+
K.includes(c) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, c, ["done"]);
|
|
1162
1162
|
}
|
|
1163
|
-
|
|
1163
|
+
K.includes(c) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${c}`), { data: h })), h.event === v.StreamDone && s();
|
|
1164
1164
|
}
|
|
1165
1165
|
}
|
|
1166
1166
|
};
|
|
1167
1167
|
}
|
|
1168
|
-
function
|
|
1168
|
+
function An(e, n, i, r) {
|
|
1169
1169
|
const s = ze(e, `${n}/agents/${i}`, r);
|
|
1170
1170
|
return {
|
|
1171
1171
|
createStream(a, o) {
|
|
1172
1172
|
return s.post("/streams", a, { signal: o });
|
|
1173
1173
|
},
|
|
1174
|
-
startConnection(a, o,
|
|
1174
|
+
startConnection(a, o, d, t) {
|
|
1175
1175
|
return s.post(
|
|
1176
1176
|
`/streams/${a}/sdp`,
|
|
1177
1177
|
{
|
|
1178
|
-
session_id:
|
|
1178
|
+
session_id: d,
|
|
1179
1179
|
answer: o
|
|
1180
1180
|
},
|
|
1181
1181
|
{ signal: t }
|
|
1182
1182
|
);
|
|
1183
1183
|
},
|
|
1184
|
-
addIceCandidate(a, o,
|
|
1184
|
+
addIceCandidate(a, o, d, t) {
|
|
1185
1185
|
return s.post(
|
|
1186
1186
|
`/streams/${a}/ice`,
|
|
1187
1187
|
{
|
|
1188
|
-
session_id:
|
|
1188
|
+
session_id: d,
|
|
1189
1189
|
...o
|
|
1190
1190
|
},
|
|
1191
1191
|
{ signal: t }
|
|
1192
1192
|
);
|
|
1193
1193
|
},
|
|
1194
|
-
sendStreamRequest(a, o,
|
|
1194
|
+
sendStreamRequest(a, o, d) {
|
|
1195
1195
|
return s.post(`/streams/${a}`, {
|
|
1196
1196
|
session_id: o,
|
|
1197
|
-
...
|
|
1197
|
+
...d
|
|
1198
1198
|
});
|
|
1199
1199
|
},
|
|
1200
1200
|
close(a, o) {
|
|
@@ -1269,11 +1269,11 @@ function ot({
|
|
|
1269
1269
|
log: o
|
|
1270
1270
|
});
|
|
1271
1271
|
}
|
|
1272
|
-
async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o },
|
|
1272
|
+
async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, d) {
|
|
1273
1273
|
var J;
|
|
1274
|
-
const t = pt(i, "WebRTCStreamingManager"),
|
|
1274
|
+
const t = pt(i, "WebRTCStreamingManager"), c = Ln(t);
|
|
1275
1275
|
let h = !1, g = !1, l = T.Stop, v = T.Stop;
|
|
1276
|
-
const { startConnection: L, sendStreamRequest:
|
|
1276
|
+
const { startConnection: L, sendStreamRequest: K, close: B, createStream: F, addIceCandidate: M } = An(
|
|
1277
1277
|
s,
|
|
1278
1278
|
a,
|
|
1279
1279
|
e,
|
|
@@ -1285,9 +1285,9 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1285
1285
|
session_id: U,
|
|
1286
1286
|
fluent: te,
|
|
1287
1287
|
interrupt_enabled: ne
|
|
1288
|
-
} = await F(n,
|
|
1288
|
+
} = await F(n, d);
|
|
1289
1289
|
(J = r.onStreamCreated) == null || J.call(r, { stream_id: k, session_id: U, agent_id: e });
|
|
1290
|
-
const x = new bn({ iceServers: Q }),
|
|
1290
|
+
const x = new bn({ iceServers: Q }), N = x.createDataChannel("JanusDataChannel");
|
|
1291
1291
|
if (!U)
|
|
1292
1292
|
throw new Error("Could not create session_id");
|
|
1293
1293
|
const H = te ? se.Fluent : se.Legacy;
|
|
@@ -1327,12 +1327,12 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1327
1327
|
sdpMLineIndex: w.candidate.sdpMLineIndex
|
|
1328
1328
|
},
|
|
1329
1329
|
U,
|
|
1330
|
-
|
|
1331
|
-
) : M(k, { candidate: null }, U,
|
|
1330
|
+
d
|
|
1331
|
+
) : M(k, { candidate: null }, U, d);
|
|
1332
1332
|
} catch (E) {
|
|
1333
1333
|
(y = r.onError) == null || y.call(r, E, { streamId: k });
|
|
1334
1334
|
}
|
|
1335
|
-
},
|
|
1335
|
+
}, N.onopen = () => {
|
|
1336
1336
|
g = !0, (!re || h) && ue();
|
|
1337
1337
|
};
|
|
1338
1338
|
const C = (w) => {
|
|
@@ -1353,7 +1353,7 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1353
1353
|
log: t
|
|
1354
1354
|
});
|
|
1355
1355
|
}
|
|
1356
|
-
function
|
|
1356
|
+
function _(w, y) {
|
|
1357
1357
|
var $;
|
|
1358
1358
|
const E = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
|
|
1359
1359
|
E && o.enrich({ streamMetadata: E }), ($ = r.onStreamReady) == null || $.call(r);
|
|
@@ -1361,11 +1361,11 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1361
1361
|
const D = {
|
|
1362
1362
|
[I.StreamStarted]: R,
|
|
1363
1363
|
[I.StreamDone]: R,
|
|
1364
|
-
[I.StreamReady]:
|
|
1364
|
+
[I.StreamReady]: _
|
|
1365
1365
|
};
|
|
1366
|
-
|
|
1366
|
+
N.onmessage = (w) => {
|
|
1367
1367
|
var $;
|
|
1368
|
-
const { subject: y, data: E } =
|
|
1368
|
+
const { subject: y, data: E } = c(w.data);
|
|
1369
1369
|
($ = D[y]) == null || $.call(D, y, E);
|
|
1370
1370
|
}, x.oniceconnectionstatechange = () => {
|
|
1371
1371
|
var y;
|
|
@@ -1377,13 +1377,13 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1377
1377
|
t("peerConnection.ontrack", w), t("CALLBACK: onSrcObjectReady"), (y = r.onSrcObjectReady) == null || y.call(r, w.streams[0]);
|
|
1378
1378
|
}, await x.setRemoteDescription(Y), t("set remote description OK");
|
|
1379
1379
|
const b = await x.createAnswer();
|
|
1380
|
-
return t("create answer OK"), await x.setLocalDescription(b), t("set local description OK"), await L(k, b, U,
|
|
1380
|
+
return t("create answer OK"), await x.setLocalDescription(b), t("set local description OK"), await L(k, b, U, d), t("start connection OK"), {
|
|
1381
1381
|
/**
|
|
1382
1382
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1383
1383
|
* @param payload
|
|
1384
1384
|
*/
|
|
1385
1385
|
speak(w) {
|
|
1386
|
-
return
|
|
1386
|
+
return K(k, U, w);
|
|
1387
1387
|
},
|
|
1388
1388
|
/**
|
|
1389
1389
|
* Method to close RTC connection
|
|
@@ -1413,14 +1413,14 @@ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee,
|
|
|
1413
1413
|
*/
|
|
1414
1414
|
sendDataChannelMessage(w) {
|
|
1415
1415
|
var y, E;
|
|
1416
|
-
if (!h ||
|
|
1416
|
+
if (!h || N.readyState !== "open") {
|
|
1417
1417
|
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
1418
|
streamId: k
|
|
1419
1419
|
});
|
|
1420
1420
|
return;
|
|
1421
1421
|
}
|
|
1422
1422
|
try {
|
|
1423
|
-
|
|
1423
|
+
N.send(w);
|
|
1424
1424
|
} catch ($) {
|
|
1425
1425
|
t("Error sending data channel message", $), (E = r.onError) == null || E.call(r, $, { streamId: k });
|
|
1426
1426
|
}
|
|
@@ -1449,9 +1449,9 @@ async function jn(e, n, i, r) {
|
|
|
1449
1449
|
case "v2": {
|
|
1450
1450
|
const { version: a, ...o } = n;
|
|
1451
1451
|
switch (o.transport.provider) {
|
|
1452
|
-
case
|
|
1453
|
-
const { createLiveKitStreamingManager:
|
|
1454
|
-
return
|
|
1452
|
+
case Ke.Livekit:
|
|
1453
|
+
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => vn);
|
|
1454
|
+
return d(s, o, i);
|
|
1455
1455
|
default:
|
|
1456
1456
|
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
1457
1457
|
}
|
|
@@ -1464,11 +1464,11 @@ const Bn = "cht";
|
|
|
1464
1464
|
function Fn() {
|
|
1465
1465
|
return {
|
|
1466
1466
|
transport: {
|
|
1467
|
-
provider:
|
|
1467
|
+
provider: Ke.Livekit
|
|
1468
1468
|
}
|
|
1469
1469
|
};
|
|
1470
1470
|
}
|
|
1471
|
-
function
|
|
1471
|
+
function Kn(e) {
|
|
1472
1472
|
var s, a;
|
|
1473
1473
|
const { streamOptions: n } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
|
|
1474
1474
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1481,8 +1481,8 @@ function Nn(e) {
|
|
|
1481
1481
|
fluent: n == null ? void 0 : n.fluent
|
|
1482
1482
|
}, ...i && { end_user_data: i } };
|
|
1483
1483
|
}
|
|
1484
|
-
function
|
|
1485
|
-
return
|
|
1484
|
+
function Nn(e, n) {
|
|
1485
|
+
return Ne(e.presenter.type) ? { version: Fe.V2, ...Fn() } : { version: Fe.V1, ...Kn(n) };
|
|
1486
1486
|
}
|
|
1487
1487
|
function zn(e, n, i) {
|
|
1488
1488
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
@@ -1536,12 +1536,12 @@ function Jn(e, n, i, r, s) {
|
|
|
1536
1536
|
function ct(e, n, i, r) {
|
|
1537
1537
|
return oe.reset(), nt.update(), new Promise(async (s, a) => {
|
|
1538
1538
|
try {
|
|
1539
|
-
let o,
|
|
1540
|
-
const t =
|
|
1539
|
+
let o, d = !1;
|
|
1540
|
+
const t = Nn(e, n);
|
|
1541
1541
|
i.enrich({
|
|
1542
1542
|
"stream-version": t.version.toString()
|
|
1543
1543
|
});
|
|
1544
|
-
let
|
|
1544
|
+
let c = null;
|
|
1545
1545
|
const h = e.presenter.type === "expressive";
|
|
1546
1546
|
o = await jn(
|
|
1547
1547
|
e,
|
|
@@ -1553,7 +1553,7 @@ function ct(e, n, i, r) {
|
|
|
1553
1553
|
...n.callbacks,
|
|
1554
1554
|
onConnectionStateChange: (g, l) => {
|
|
1555
1555
|
var v, L;
|
|
1556
|
-
(L = (v = n.callbacks).onConnectionStateChange) == null || L.call(v, g), zn(g, l, i), g === P.Connected && (o ? s(o) :
|
|
1556
|
+
(L = (v = n.callbacks).onConnectionStateChange) == null || L.call(v, g), zn(g, l, i), g === P.Connected && (o ? s(o) : d = !0);
|
|
1557
1557
|
},
|
|
1558
1558
|
onVideoStateChange: (g, l) => {
|
|
1559
1559
|
var v, L;
|
|
@@ -1567,15 +1567,15 @@ function ct(e, n, i, r) {
|
|
|
1567
1567
|
},
|
|
1568
1568
|
onAgentActivityStateChange: (g) => {
|
|
1569
1569
|
var l, v;
|
|
1570
|
-
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(),
|
|
1570
|
+
(v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), c = (L) => {
|
|
1571
1571
|
st(
|
|
1572
1572
|
T.Start,
|
|
1573
1573
|
e,
|
|
1574
1574
|
i,
|
|
1575
1575
|
o.streamType,
|
|
1576
1576
|
L
|
|
1577
|
-
),
|
|
1578
|
-
}, h ||
|
|
1577
|
+
), c = null;
|
|
1578
|
+
}, h || c({ latency: oe.get(!0) })) : (je.reset(), c = null, st(
|
|
1579
1579
|
T.Stop,
|
|
1580
1580
|
e,
|
|
1581
1581
|
i,
|
|
@@ -1583,7 +1583,7 @@ function ct(e, n, i, r) {
|
|
|
1583
1583
|
));
|
|
1584
1584
|
},
|
|
1585
1585
|
onFirstAudioDetected: (g) => {
|
|
1586
|
-
|
|
1586
|
+
c == null || c(g);
|
|
1587
1587
|
},
|
|
1588
1588
|
onStreamReady: () => {
|
|
1589
1589
|
const g = nt.get(!0);
|
|
@@ -1592,7 +1592,7 @@ function ct(e, n, i, r) {
|
|
|
1592
1592
|
}
|
|
1593
1593
|
},
|
|
1594
1594
|
r
|
|
1595
|
-
),
|
|
1595
|
+
), d && s(o);
|
|
1596
1596
|
} catch (o) {
|
|
1597
1597
|
a(o);
|
|
1598
1598
|
}
|
|
@@ -1601,12 +1601,12 @@ function ct(e, n, i, r) {
|
|
|
1601
1601
|
async function On(e, n, i, r, s) {
|
|
1602
1602
|
var h, g, l, v;
|
|
1603
1603
|
const a = async () => {
|
|
1604
|
-
if (
|
|
1605
|
-
const L = await ct(e, n, r),
|
|
1604
|
+
if (Ne(e.presenter.type)) {
|
|
1605
|
+
const L = await ct(e, n, r), K = `${Bn}_${L.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
|
|
1606
1606
|
return { chatResult: {
|
|
1607
1607
|
chatMode: O.Functional,
|
|
1608
1608
|
chat: {
|
|
1609
|
-
id:
|
|
1609
|
+
id: K,
|
|
1610
1610
|
agent_id: e.id,
|
|
1611
1611
|
owner_id: e.owner_id ?? "",
|
|
1612
1612
|
created: B,
|
|
@@ -1618,7 +1618,7 @@ async function On(e, n, i, r, s) {
|
|
|
1618
1618
|
}
|
|
1619
1619
|
}, streamingManager: L };
|
|
1620
1620
|
} else {
|
|
1621
|
-
const L = new AbortController(),
|
|
1621
|
+
const L = new AbortController(), K = L.signal;
|
|
1622
1622
|
let B;
|
|
1623
1623
|
try {
|
|
1624
1624
|
const F = ht(
|
|
@@ -1628,23 +1628,23 @@ async function On(e, n, i, r, s) {
|
|
|
1628
1628
|
n.mode,
|
|
1629
1629
|
n.persistentChat,
|
|
1630
1630
|
s
|
|
1631
|
-
), M = ct(e, n, r,
|
|
1631
|
+
), M = ct(e, n, r, K).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, M]);
|
|
1632
1632
|
return { chatResult: k, streamingManager: Y };
|
|
1633
1633
|
} catch (F) {
|
|
1634
1634
|
throw L.abort(), B && await B.disconnect().catch(() => {
|
|
1635
1635
|
}), F;
|
|
1636
1636
|
}
|
|
1637
1637
|
}
|
|
1638
|
-
}, { chatResult: o, streamingManager:
|
|
1639
|
-
return
|
|
1638
|
+
}, { chatResult: o, streamingManager: d } = await a(), { chat: t, chatMode: c } = o;
|
|
1639
|
+
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (h = n.callbacks).onModeChange) == null || g.call(h, c), c !== O.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new It(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
|
|
1640
1640
|
}
|
|
1641
1641
|
async function qn(e, n) {
|
|
1642
1642
|
var H, re, de, ue;
|
|
1643
1643
|
let i = !0, r = null;
|
|
1644
|
-
const s = n.mixpanelKey || zt, a = n.wsURL ||
|
|
1644
|
+
const s = n.mixpanelKey || zt, a = n.wsURL || Nt, o = n.baseURL || Ee, d = n.mode || O.Functional, t = {
|
|
1645
1645
|
messages: [],
|
|
1646
|
-
chatMode:
|
|
1647
|
-
},
|
|
1646
|
+
chatMode: d
|
|
1647
|
+
}, c = nn({
|
|
1648
1648
|
token: s,
|
|
1649
1649
|
agentId: e,
|
|
1650
1650
|
isEnabled: n.enableAnalitics,
|
|
@@ -1652,13 +1652,13 @@ async function qn(e, n) {
|
|
|
1652
1652
|
mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
|
|
1653
1653
|
}), h = Date.now();
|
|
1654
1654
|
tt(() => {
|
|
1655
|
-
|
|
1655
|
+
c.track("agent-sdk", { event: "init" }, h);
|
|
1656
1656
|
});
|
|
1657
1657
|
const g = Xt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1658
1658
|
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: L, clearQueue:
|
|
1659
|
+
const v = Ne(l.presenter.type);
|
|
1660
|
+
c.enrich(Gt(l));
|
|
1661
|
+
const { onMessage: L, clearQueue: K } = _n(c, t, n, l, () => {
|
|
1662
1662
|
var f, C, R;
|
|
1663
1663
|
(f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, P.Disconnected);
|
|
1664
1664
|
});
|
|
@@ -1666,10 +1666,10 @@ async function qn(e, n) {
|
|
|
1666
1666
|
const B = (f) => {
|
|
1667
1667
|
r = f;
|
|
1668
1668
|
}, F = ({ type: f }) => {
|
|
1669
|
-
var R,
|
|
1670
|
-
if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((
|
|
1669
|
+
var R, _, D, b, J;
|
|
1670
|
+
if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((_ = t.streamingManager) != null && _.isInterruptible)) return;
|
|
1671
1671
|
const C = t.messages[t.messages.length - 1];
|
|
1672
|
-
|
|
1672
|
+
c.track("agent-video-interrupt", {
|
|
1673
1673
|
type: f || "click",
|
|
1674
1674
|
video_duration_to_interrupt: je.get(!0),
|
|
1675
1675
|
message_duration_to_interrupt: oe.get(!0)
|
|
@@ -1681,22 +1681,22 @@ async function qn(e, n) {
|
|
|
1681
1681
|
if (!R)
|
|
1682
1682
|
throw new Error(`No handler registered for client tool: ${f}`);
|
|
1683
1683
|
try {
|
|
1684
|
-
const
|
|
1685
|
-
return await R(
|
|
1686
|
-
} catch (
|
|
1687
|
-
throw new Error(`Client tool "${f}" failed: ${
|
|
1684
|
+
const _ = JSON.parse(C.payload);
|
|
1685
|
+
return await R(_);
|
|
1686
|
+
} catch (_) {
|
|
1687
|
+
throw new Error(`Client tool "${f}" failed: ${_.message}`);
|
|
1688
1688
|
}
|
|
1689
1689
|
};
|
|
1690
1690
|
}
|
|
1691
1691
|
function Y() {
|
|
1692
|
-
var f, C, R,
|
|
1692
|
+
var f, C, R, _;
|
|
1693
1693
|
for (const [D] of M)
|
|
1694
|
-
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (
|
|
1694
|
+
(C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (_ = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || _.call(R, D, k(D));
|
|
1695
1695
|
}
|
|
1696
1696
|
function Q(f, C) {
|
|
1697
|
-
var
|
|
1697
|
+
var _, D;
|
|
1698
1698
|
const R = !M.has(f);
|
|
1699
|
-
M.set(f, C), R && ((D = (
|
|
1699
|
+
M.set(f, C), R && ((D = (_ = t.streamingManager) == null ? void 0 : _.registerRpcMethod) == null || D.call(_, f, k(f)));
|
|
1700
1700
|
}
|
|
1701
1701
|
function U(f) {
|
|
1702
1702
|
var C, R;
|
|
@@ -1704,12 +1704,12 @@ async function qn(e, n) {
|
|
|
1704
1704
|
}
|
|
1705
1705
|
const te = Date.now();
|
|
1706
1706
|
tt(() => {
|
|
1707
|
-
|
|
1707
|
+
c.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
|
|
1708
1708
|
});
|
|
1709
1709
|
async function ne(f) {
|
|
1710
1710
|
var J, w, y, E, $, G, he;
|
|
1711
1711
|
(w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J, P.Connecting), oe.reset(), f && !i && (delete t.chat, (E = (y = n.callbacks).onNewMessage) == null || E.call(y, [...t.messages], "answer"));
|
|
1712
|
-
const C =
|
|
1712
|
+
const C = d === O.DirectPlayback || v ? Promise.resolve(void 0) : kn(
|
|
1713
1713
|
n.auth,
|
|
1714
1714
|
a,
|
|
1715
1715
|
{ onMessage: L, onError: n.callbacks.onError },
|
|
@@ -1719,7 +1719,7 @@ async function qn(e, n) {
|
|
|
1719
1719
|
l,
|
|
1720
1720
|
{
|
|
1721
1721
|
...n,
|
|
1722
|
-
mode:
|
|
1722
|
+
mode: d,
|
|
1723
1723
|
callbacks: {
|
|
1724
1724
|
...n.callbacks,
|
|
1725
1725
|
onVideoIdChange: B,
|
|
@@ -1728,7 +1728,7 @@ async function qn(e, n) {
|
|
|
1728
1728
|
}
|
|
1729
1729
|
},
|
|
1730
1730
|
g,
|
|
1731
|
-
|
|
1731
|
+
c,
|
|
1732
1732
|
t.chat
|
|
1733
1733
|
),
|
|
1734
1734
|
{
|
|
@@ -1740,21 +1740,21 @@ async function qn(e, n) {
|
|
|
1740
1740
|
}
|
|
1741
1741
|
).catch((Z) => {
|
|
1742
1742
|
var z, ee;
|
|
1743
|
-
throw
|
|
1744
|
-
}), [
|
|
1745
|
-
b && b.id !== (($ = t.chat) == null ? void 0 : $.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = D, t.socketManager =
|
|
1743
|
+
throw N(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, P.Fail), Z;
|
|
1744
|
+
}), [_, { streamingManager: D, chat: b }] = await Promise.all([C, R]);
|
|
1745
|
+
b && b.id !== (($ = t.chat) == null ? void 0 : $.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = D, t.socketManager = _, t.chat = b, Y(), i = !1, c.enrich({
|
|
1746
1746
|
chatId: b == null ? void 0 : b.id,
|
|
1747
1747
|
streamId: D == null ? void 0 : D.streamId,
|
|
1748
1748
|
mode: t.chatMode
|
|
1749
|
-
}),
|
|
1749
|
+
}), N((b == null ? void 0 : b.chat_mode) ?? d);
|
|
1750
1750
|
}
|
|
1751
1751
|
async function x() {
|
|
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, (
|
|
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, (_ = (R = n.callbacks).onConnectionStateChange) == null || _.call(R, P.Disconnected);
|
|
1754
1754
|
}
|
|
1755
|
-
async function
|
|
1755
|
+
async function N(f) {
|
|
1756
1756
|
var C, R;
|
|
1757
|
-
f !== t.chatMode && (
|
|
1757
|
+
f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await x(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
|
|
1758
1758
|
}
|
|
1759
1759
|
return {
|
|
1760
1760
|
agent: l,
|
|
@@ -1768,10 +1768,10 @@ async function qn(e, n) {
|
|
|
1768
1768
|
},
|
|
1769
1769
|
starterMessages: ((ue = l.knowledge) == null ? void 0 : ue.starter_message) || [],
|
|
1770
1770
|
getSTTToken: () => g.getSTTToken(l.id),
|
|
1771
|
-
changeMode:
|
|
1772
|
-
enrichAnalytics:
|
|
1771
|
+
changeMode: N,
|
|
1772
|
+
enrichAnalytics: c.enrich,
|
|
1773
1773
|
async connect() {
|
|
1774
|
-
await ne(!0),
|
|
1774
|
+
await ne(!0), c.track("agent-chat", {
|
|
1775
1775
|
event: "connect",
|
|
1776
1776
|
mode: t.chatMode
|
|
1777
1777
|
});
|
|
@@ -1780,7 +1780,7 @@ async function qn(e, n) {
|
|
|
1780
1780
|
const f = t.streamingManager;
|
|
1781
1781
|
if (v && (f != null && f.reconnect)) {
|
|
1782
1782
|
try {
|
|
1783
|
-
await f.reconnect(),
|
|
1783
|
+
await f.reconnect(), c.track("agent-chat", {
|
|
1784
1784
|
event: "reconnect",
|
|
1785
1785
|
mode: t.chatMode
|
|
1786
1786
|
});
|
|
@@ -1789,13 +1789,13 @@ async function qn(e, n) {
|
|
|
1789
1789
|
}
|
|
1790
1790
|
return;
|
|
1791
1791
|
}
|
|
1792
|
-
await x(), await ne(!1),
|
|
1792
|
+
await x(), await ne(!1), c.track("agent-chat", {
|
|
1793
1793
|
event: "reconnect",
|
|
1794
1794
|
mode: t.chatMode
|
|
1795
1795
|
});
|
|
1796
1796
|
},
|
|
1797
1797
|
async disconnect() {
|
|
1798
|
-
await x(),
|
|
1798
|
+
await x(), c.track("agent-chat", {
|
|
1799
1799
|
event: "disconnect",
|
|
1800
1800
|
mode: t.chatMode
|
|
1801
1801
|
});
|
|
@@ -1825,8 +1825,8 @@ async function qn(e, n) {
|
|
|
1825
1825
|
async chat(f) {
|
|
1826
1826
|
var D, b, J, w, y;
|
|
1827
1827
|
const C = () => {
|
|
1828
|
-
if (ft(
|
|
1829
|
-
throw new me(`${
|
|
1828
|
+
if (ft(d))
|
|
1829
|
+
throw new me(`${d} is enabled, chat is disabled`);
|
|
1830
1830
|
if (f.length >= 800)
|
|
1831
1831
|
throw new me("Message cannot be more than 800 characters");
|
|
1832
1832
|
if (f.length === 0)
|
|
@@ -1845,7 +1845,7 @@ async function qn(e, n) {
|
|
|
1845
1845
|
const G = await ht(
|
|
1846
1846
|
l,
|
|
1847
1847
|
g,
|
|
1848
|
-
|
|
1848
|
+
c,
|
|
1849
1849
|
t.chatMode,
|
|
1850
1850
|
n.persistentChat
|
|
1851
1851
|
);
|
|
@@ -1854,7 +1854,7 @@ async function qn(e, n) {
|
|
|
1854
1854
|
t.chat = G.chat, ($ = (E = n.callbacks).onNewChat) == null || $.call(E, t.chat.id);
|
|
1855
1855
|
}
|
|
1856
1856
|
return t.chat.id;
|
|
1857
|
-
},
|
|
1857
|
+
}, _ = async (E, $) => {
|
|
1858
1858
|
const G = t.chatMode === O.Playground;
|
|
1859
1859
|
return xe(v && !G ? async () => {
|
|
1860
1860
|
var z, ee;
|
|
@@ -1888,14 +1888,14 @@ async function qn(e, n) {
|
|
|
1888
1888
|
});
|
|
1889
1889
|
};
|
|
1890
1890
|
try {
|
|
1891
|
-
|
|
1891
|
+
K(), C(), t.messages.push({
|
|
1892
1892
|
id: ge(),
|
|
1893
1893
|
role: "user",
|
|
1894
1894
|
content: f,
|
|
1895
1895
|
parts: Te(f),
|
|
1896
1896
|
created_at: new Date(oe.update()).toISOString()
|
|
1897
1897
|
}), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "user");
|
|
1898
|
-
const E = await R(), $ = await
|
|
1898
|
+
const E = await R(), $ = await _([...t.messages], E);
|
|
1899
1899
|
return t.messages.push({
|
|
1900
1900
|
id: ge(),
|
|
1901
1901
|
role: "assistant",
|
|
@@ -1904,15 +1904,15 @@ async function qn(e, n) {
|
|
|
1904
1904
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1905
1905
|
context: $.context,
|
|
1906
1906
|
matches: $.matches
|
|
1907
|
-
}),
|
|
1907
|
+
}), c.track("agent-message-send", {
|
|
1908
1908
|
event: "success",
|
|
1909
1909
|
messages: t.messages.length + 1
|
|
1910
|
-
}), $.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"),
|
|
1910
|
+
}), $.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), c.track("agent-message-received", {
|
|
1911
1911
|
latency: oe.get(!0),
|
|
1912
1912
|
messages: t.messages.length
|
|
1913
1913
|
})), $;
|
|
1914
1914
|
} catch (E) {
|
|
1915
|
-
throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(),
|
|
1915
|
+
throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
|
|
1916
1916
|
event: "error",
|
|
1917
1917
|
messages: t.messages.length
|
|
1918
1918
|
}), E;
|
|
@@ -1920,13 +1920,13 @@ async function qn(e, n) {
|
|
|
1920
1920
|
},
|
|
1921
1921
|
rate(f, C, R) {
|
|
1922
1922
|
var b, J, w, y;
|
|
1923
|
-
const
|
|
1923
|
+
const _ = t.messages.find((E) => E.id === f);
|
|
1924
1924
|
if (t.chat) {
|
|
1925
|
-
if (!
|
|
1925
|
+
if (!_)
|
|
1926
1926
|
throw new Error("Message not found");
|
|
1927
1927
|
} else throw new Error("Chat is not initialized");
|
|
1928
|
-
const D = ((b =
|
|
1929
|
-
return
|
|
1928
|
+
const D = ((b = _.matches) == null ? void 0 : b.map((E) => [E.document_id, E.id])) ?? [];
|
|
1929
|
+
return c.track("agent-rate", {
|
|
1930
1930
|
event: R ? "update" : "create",
|
|
1931
1931
|
thumb: C === 1 ? "up" : "down",
|
|
1932
1932
|
knowledge_id: ((J = l.knowledge) == null ? void 0 : J.id) ?? "",
|
|
@@ -1947,7 +1947,7 @@ async function qn(e, n) {
|
|
|
1947
1947
|
deleteRate(f) {
|
|
1948
1948
|
if (!t.chat)
|
|
1949
1949
|
throw new Error("Chat is not initialized");
|
|
1950
|
-
return
|
|
1950
|
+
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
|
|
1951
1951
|
},
|
|
1952
1952
|
async speak(f) {
|
|
1953
1953
|
var D, b, J;
|
|
@@ -1975,7 +1975,7 @@ async function qn(e, n) {
|
|
|
1975
1975
|
return f;
|
|
1976
1976
|
}
|
|
1977
1977
|
const R = C();
|
|
1978
|
-
if (
|
|
1978
|
+
if (c.track("agent-speak", R), oe.update(), t.messages && R.type === "text" && (t.messages.push({
|
|
1979
1979
|
id: ge(),
|
|
1980
1980
|
role: "assistant",
|
|
1981
1981
|
content: R.input,
|
|
@@ -2010,15 +2010,15 @@ export {
|
|
|
2010
2010
|
ae as ConnectivityState,
|
|
2011
2011
|
$t as DocumentType,
|
|
2012
2012
|
xt as KnowledgeType,
|
|
2013
|
-
|
|
2013
|
+
At as PlanGroup,
|
|
2014
2014
|
jt as Providers,
|
|
2015
2015
|
Lt as RateState,
|
|
2016
2016
|
I as StreamEvents,
|
|
2017
2017
|
se as StreamType,
|
|
2018
2018
|
T as StreamingState,
|
|
2019
2019
|
Pt as Subject,
|
|
2020
|
-
|
|
2021
|
-
|
|
2020
|
+
Ke as TransportProvider,
|
|
2021
|
+
_t as UserPlan,
|
|
2022
2022
|
me as ValidationError,
|
|
2023
2023
|
dt as VideoType,
|
|
2024
2024
|
Bt as VoiceAccess,
|