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