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