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