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