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