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