@d-id/client-sdk 1.1.46-staging.189 → 1.1.46
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 +407 -411
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var 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
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,7 +18,7 @@ class it extends Se {
|
|
|
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
|
}
|
|
@@ -26,17 +26,17 @@ class at extends Se {
|
|
|
26
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
|
|
39
|
-
const
|
|
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
|
+
const pn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,13 +48,13 @@ const Cn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var M = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(M || {}),
|
|
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) => {
|
|
@@ -78,12 +78,12 @@ async function Ee(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 = pe, 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 Mt(e, t = pe, 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 Et(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,8 +226,8 @@ function It(e) {
|
|
|
226
226
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
227
227
|
};
|
|
228
228
|
}
|
|
229
|
-
const
|
|
230
|
-
function
|
|
229
|
+
const Dt = (e) => e.reduce((t, i) => t + i, 0), Be = (e) => Dt(e) / e.length;
|
|
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) || {};
|
|
233
233
|
return {
|
|
@@ -238,12 +238,12 @@ function _t(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 Pt(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 Pt(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 Lt = (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 jt(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 $t(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 xt(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 Ce = 100,
|
|
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,19 +498,19 @@ function Nt() {
|
|
|
498
498
|
return { isReceiving: !1, avgJitterDelayInInterval: n };
|
|
499
499
|
};
|
|
500
500
|
}
|
|
501
|
-
function
|
|
502
|
-
let o = null, c = [], a, r = 0, d = !1, h =
|
|
503
|
-
const x =
|
|
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
504
|
async function b() {
|
|
505
505
|
const C = await e();
|
|
506
506
|
if (!C)
|
|
507
507
|
return;
|
|
508
|
-
const { isReceiving: R, avgJitterDelayInInterval: F, freezeCount: S } = x(C),
|
|
508
|
+
const { isReceiving: R, avgJitterDelayInInterval: F, freezeCount: S } = x(C), O = bt(C);
|
|
509
509
|
if (R)
|
|
510
|
-
r = 0, u = S - v, w = F <
|
|
511
|
-
else if (d && (r++, r >=
|
|
512
|
-
const
|
|
513
|
-
n == null || n(M.Stop,
|
|
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 {
|
|
@@ -520,7 +520,7 @@ function Ge(e, t, i, n, s) {
|
|
|
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
526
|
async function Me() {
|
|
@@ -532,13 +532,13 @@ async function Me() {
|
|
|
532
532
|
);
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
|
-
const
|
|
536
|
-
excellent:
|
|
537
|
-
good:
|
|
538
|
-
poor:
|
|
539
|
-
lost:
|
|
540
|
-
unknown:
|
|
541
|
-
},
|
|
535
|
+
const Ft = {
|
|
536
|
+
excellent: re.Strong,
|
|
537
|
+
good: re.Strong,
|
|
538
|
+
poor: re.Weak,
|
|
539
|
+
lost: re.Unknown,
|
|
540
|
+
unknown: re.Unknown
|
|
541
|
+
}, pe = JSON.stringify({
|
|
542
542
|
kind: "InternalServerError",
|
|
543
543
|
description: "Stream Error"
|
|
544
544
|
});
|
|
@@ -547,11 +547,11 @@ function _e(e, t, i) {
|
|
|
547
547
|
var n, s;
|
|
548
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 =
|
|
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
553
|
let u = null, v = !1;
|
|
554
|
-
const x =
|
|
554
|
+
const x = ie.Fluent;
|
|
555
555
|
let b = null, C = null, R = null, F = !1;
|
|
556
556
|
u = new s({
|
|
557
557
|
adaptiveStream: !1,
|
|
@@ -559,43 +559,43 @@ async function Jt(e, t, i) {
|
|
|
559
559
|
dynacast: !0
|
|
560
560
|
});
|
|
561
561
|
let S = null;
|
|
562
|
-
const
|
|
563
|
-
let
|
|
564
|
-
const
|
|
562
|
+
const O = 2e4;
|
|
563
|
+
let J = W.Idle;
|
|
564
|
+
const H = At(r, d || we, e, a.onError);
|
|
565
565
|
let z, ee, te;
|
|
566
566
|
try {
|
|
567
|
-
const
|
|
567
|
+
const f = await H.createStream({
|
|
568
568
|
transport_provider: ke.Livekit,
|
|
569
569
|
chat_persist: t.chat_persist ?? !0
|
|
570
|
-
}), { id: g, session_token: y, session_url: _ } =
|
|
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
575
|
if (!te || !ee || !z)
|
|
576
576
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
577
|
-
u.on(o.ConnectionStateChanged, D).on(o.ConnectionQualityChanged, k).on(o.ParticipantConnected, K).on(o.ParticipantDisconnected,
|
|
578
|
-
function l(
|
|
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
579
|
var y;
|
|
580
|
-
g != null && g.isLocal && (ne.update(),
|
|
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
583
|
await u.connect(te, ee), n("LiveKit room joined successfully"), S = setTimeout(() => {
|
|
584
|
-
var
|
|
584
|
+
var f;
|
|
585
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 D(
|
|
597
|
-
var g, y, _,
|
|
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
600
|
n("CALLBACK: onConnectionStateChange(Connecting)"), (g = a.onConnectionStateChange) == null || g.call(a, I.Connecting, "livekit:connecting");
|
|
601
601
|
break;
|
|
@@ -609,135 +609,131 @@ async function Jt(e, t, i) {
|
|
|
609
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 k(
|
|
616
|
+
function k(f, g) {
|
|
617
617
|
var y;
|
|
618
|
-
n("Connection quality:",
|
|
618
|
+
n("Connection quality:", f), g != null && g.isLocal && ((y = a.onConnectivityStateChange) == null || y.call(a, Ft[f]));
|
|
619
619
|
}
|
|
620
|
-
function K(
|
|
621
|
-
n("Participant connected:",
|
|
620
|
+
function K(f) {
|
|
621
|
+
n("Participant connected:", f.identity);
|
|
622
622
|
}
|
|
623
|
-
function
|
|
624
|
-
n("Participant disconnected:",
|
|
623
|
+
function P(f) {
|
|
624
|
+
n("Participant disconnected:", f.identity), de("livekit:participant-disconnected");
|
|
625
625
|
}
|
|
626
|
-
function T(
|
|
627
|
-
var
|
|
628
|
-
n(`Track subscribed: ${
|
|
629
|
-
const _ =
|
|
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
630
|
if (!_) {
|
|
631
|
-
n(`No mediaStreamTrack available for ${
|
|
631
|
+
n(`No mediaStreamTrack available for ${f.kind}`);
|
|
632
632
|
return;
|
|
633
633
|
}
|
|
634
|
-
b ? (b.addTrack(_), n(`Added ${
|
|
635
|
-
() =>
|
|
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
636
|
() => v,
|
|
637
|
-
|
|
638
|
-
(
|
|
639
|
-
n(`Video state change: ${
|
|
637
|
+
pt,
|
|
638
|
+
(ve, Re) => {
|
|
639
|
+
n(`Video state change: ${ve}`);
|
|
640
640
|
}
|
|
641
641
|
), R.start());
|
|
642
642
|
}
|
|
643
|
-
function N(
|
|
643
|
+
function N(f, g, y) {
|
|
644
644
|
var _;
|
|
645
|
-
if (n(`Track unsubscribed: ${
|
|
646
|
-
const
|
|
647
|
-
R == null || R.stop(), R = null, (_ = a.onVideoStateChange) == null || _.call(a, M.Stop,
|
|
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);
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
|
-
function
|
|
651
|
-
var
|
|
652
|
-
const
|
|
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);
|
|
653
654
|
try {
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
const
|
|
657
|
-
(
|
|
658
|
-
event:
|
|
659
|
-
...
|
|
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, {
|
|
659
|
+
event: ae,
|
|
660
|
+
...U
|
|
660
661
|
});
|
|
661
|
-
} else if (
|
|
662
|
-
const
|
|
663
|
-
(Z = a.onMessage) == null || Z.call(a,
|
|
664
|
-
event:
|
|
665
|
-
...
|
|
662
|
+
} else if (ue === L.ChatPartial) {
|
|
663
|
+
const ae = Y.Partial;
|
|
664
|
+
(Z = a.onMessage) == null || Z.call(a, ae, {
|
|
665
|
+
event: ae,
|
|
666
|
+
...U
|
|
666
667
|
});
|
|
667
|
-
} else if ([
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
} else if (ce === A.ChatAudioTranscribed) {
|
|
680
|
-
const re = Y.Transcribe;
|
|
681
|
-
($e = a.onMessage) == null || $e.call(a, re, {
|
|
682
|
-
event: re,
|
|
683
|
-
...X
|
|
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, {
|
|
678
|
+
event: ae,
|
|
679
|
+
...U
|
|
684
680
|
}), queueMicrotask(() => {
|
|
685
|
-
var
|
|
686
|
-
(
|
|
681
|
+
var ge;
|
|
682
|
+
(ge = a.onAgentActivityStateChange) == null || ge.call(a, W.Loading);
|
|
687
683
|
});
|
|
688
684
|
}
|
|
689
|
-
} catch (
|
|
690
|
-
n("Failed to parse data channel message:",
|
|
685
|
+
} catch (U) {
|
|
686
|
+
n("Failed to parse data channel message:", U);
|
|
691
687
|
}
|
|
692
688
|
}
|
|
693
|
-
function
|
|
689
|
+
function Q(f) {
|
|
694
690
|
var g;
|
|
695
|
-
n("Media devices error:",
|
|
691
|
+
n("Media devices error:", f), (g = a.onError) == null || g.call(a, new Error(pe), { sessionId: z });
|
|
696
692
|
}
|
|
697
|
-
function j(
|
|
693
|
+
function j(f) {
|
|
698
694
|
var g;
|
|
699
|
-
n("Encryption error:",
|
|
695
|
+
n("Encryption error:", f), (g = a.onError) == null || g.call(a, new Error(pe), { sessionId: z });
|
|
700
696
|
}
|
|
701
|
-
function $(
|
|
702
|
-
n("Track subscription failed:", { trackSid:
|
|
697
|
+
function $(f, g, y) {
|
|
698
|
+
n("Track subscription failed:", { trackSid: f, participant: g, reason: y });
|
|
703
699
|
}
|
|
704
|
-
async function G(
|
|
700
|
+
async function G(f) {
|
|
705
701
|
if (!u) return null;
|
|
706
702
|
const { Track: g } = await Me(), y = u.localParticipant.audioTrackPublications;
|
|
707
703
|
if (y) {
|
|
708
|
-
for (const [_,
|
|
709
|
-
if (
|
|
710
|
-
const Z =
|
|
711
|
-
if (Z ===
|
|
712
|
-
return
|
|
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;
|
|
713
709
|
}
|
|
714
710
|
}
|
|
715
711
|
return null;
|
|
716
712
|
}
|
|
717
|
-
function oe(
|
|
713
|
+
function oe(f) {
|
|
718
714
|
if (!C || !C.track)
|
|
719
715
|
return !1;
|
|
720
716
|
const g = C.track.mediaStreamTrack;
|
|
721
|
-
return g !==
|
|
717
|
+
return g !== f && (g == null ? void 0 : g.id) !== f.id;
|
|
722
718
|
}
|
|
723
|
-
async function p(
|
|
724
|
-
var
|
|
719
|
+
async function p(f) {
|
|
720
|
+
var X, Z;
|
|
725
721
|
if (!v || !u)
|
|
726
722
|
throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
|
|
727
|
-
const g =
|
|
723
|
+
const g = f.getAudioTracks();
|
|
728
724
|
if (g.length === 0) {
|
|
729
725
|
n("No audio track found in the provided MediaStream");
|
|
730
726
|
return;
|
|
731
727
|
}
|
|
732
|
-
const y = g[0], { Track: _ } = await Me(),
|
|
733
|
-
if (
|
|
728
|
+
const y = g[0], { Track: _ } = await Me(), A = await G(y);
|
|
729
|
+
if (A) {
|
|
734
730
|
n("Microphone track is already published, skipping", {
|
|
735
731
|
trackId: y.id,
|
|
736
|
-
publishedTrackId: (Z = (
|
|
737
|
-
}), C =
|
|
732
|
+
publishedTrackId: (Z = (X = A.track) == null ? void 0 : X.mediaStreamTrack) == null ? void 0 : Z.id
|
|
733
|
+
}), C = A;
|
|
738
734
|
return;
|
|
739
735
|
}
|
|
740
|
-
oe(y) && (n("Unpublishing existing microphone track before publishing new one"), await
|
|
736
|
+
oe(y) && (n("Unpublishing existing microphone track before publishing new one"), await m()), n("Publishing microphone track from provided MediaStream", { trackId: y.id });
|
|
741
737
|
try {
|
|
742
738
|
C = await u.localParticipant.publishTrack(y, {
|
|
743
739
|
source: _.Source.Microphone
|
|
@@ -746,81 +742,81 @@ async function Jt(e, t, i) {
|
|
|
746
742
|
throw n("Failed to publish microphone track:", se), se;
|
|
747
743
|
}
|
|
748
744
|
}
|
|
749
|
-
async function
|
|
745
|
+
async function m() {
|
|
750
746
|
if (!(!C || !C.track))
|
|
751
747
|
try {
|
|
752
748
|
u && (await u.localParticipant.unpublishTrack(C.track), n("Microphone track unpublished"));
|
|
753
|
-
} catch (
|
|
754
|
-
n("Error unpublishing microphone track:",
|
|
749
|
+
} catch (f) {
|
|
750
|
+
n("Error unpublishing microphone track:", f);
|
|
755
751
|
} finally {
|
|
756
752
|
C = null;
|
|
757
753
|
}
|
|
758
754
|
}
|
|
759
755
|
function E() {
|
|
760
|
-
b && (b.getTracks().forEach((
|
|
756
|
+
b && (b.getTracks().forEach((f) => f.stop()), b = null);
|
|
761
757
|
}
|
|
762
|
-
async function
|
|
758
|
+
async function V(f, g) {
|
|
763
759
|
var y, _;
|
|
764
760
|
if (!v || !u) {
|
|
765
|
-
n("Room is not connected for sending messages"), (y = a.onError) == null || y.call(a, new Error(
|
|
761
|
+
n("Room is not connected for sending messages"), (y = a.onError) == null || y.call(a, new Error(pe), {
|
|
766
762
|
sessionId: z
|
|
767
763
|
});
|
|
768
764
|
return;
|
|
769
765
|
}
|
|
770
766
|
try {
|
|
771
|
-
await u.localParticipant.sendText(
|
|
772
|
-
} catch (
|
|
773
|
-
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 });
|
|
774
770
|
}
|
|
775
771
|
}
|
|
776
|
-
async function
|
|
772
|
+
async function ce(f) {
|
|
777
773
|
var g;
|
|
778
774
|
try {
|
|
779
|
-
const _ = JSON.parse(
|
|
780
|
-
return
|
|
775
|
+
const _ = JSON.parse(f).topic;
|
|
776
|
+
return V("", _);
|
|
781
777
|
} catch (y) {
|
|
782
|
-
n("Failed to send data channel message:", y), (g = a.onError) == null || g.call(a, new Error(
|
|
778
|
+
n("Failed to send data channel message:", y), (g = a.onError) == null || g.call(a, new Error(pe), { sessionId: z });
|
|
783
779
|
}
|
|
784
780
|
}
|
|
785
|
-
function
|
|
786
|
-
return
|
|
787
|
-
|
|
781
|
+
function ye(f) {
|
|
782
|
+
return V(
|
|
783
|
+
f,
|
|
788
784
|
"lk.chat"
|
|
789
785
|
/* Chat */
|
|
790
786
|
);
|
|
791
787
|
}
|
|
792
|
-
async function
|
|
788
|
+
async function de(f) {
|
|
793
789
|
var g, y;
|
|
794
|
-
S && (clearTimeout(S), S = null), u && (await
|
|
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;
|
|
795
791
|
}
|
|
796
792
|
return {
|
|
797
|
-
speak(
|
|
798
|
-
const g = typeof
|
|
799
|
-
return
|
|
793
|
+
speak(f) {
|
|
794
|
+
const g = typeof f == "string" ? f : JSON.stringify(f);
|
|
795
|
+
return V(
|
|
800
796
|
g,
|
|
801
797
|
"did.speak"
|
|
802
798
|
/* Speak */
|
|
803
799
|
);
|
|
804
800
|
},
|
|
805
|
-
disconnect: () =>
|
|
801
|
+
disconnect: () => de("user:disconnect"),
|
|
806
802
|
async reconnect() {
|
|
807
|
-
var
|
|
803
|
+
var f, g;
|
|
808
804
|
if ((u == null ? void 0 : u.state) === c.Connected) {
|
|
809
805
|
n("Room is already connected");
|
|
810
806
|
return;
|
|
811
807
|
}
|
|
812
808
|
if (!u || !te || !ee)
|
|
813
809
|
throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
814
|
-
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");
|
|
815
811
|
try {
|
|
816
812
|
if (await u.connect(te, ee), n("Room reconnected"), v = !0, u.remoteParticipants.size === 0) {
|
|
817
813
|
if (n("Waiting for agent to join..."), !await new Promise((_) => {
|
|
818
|
-
const
|
|
819
|
-
u == null || u.off(o.ParticipantConnected,
|
|
820
|
-
}, 5e3),
|
|
821
|
-
clearTimeout(
|
|
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);
|
|
822
818
|
};
|
|
823
|
-
u == null || u.on(o.ParticipantConnected,
|
|
819
|
+
u == null || u.on(o.ParticipantConnected, X);
|
|
824
820
|
}))
|
|
825
821
|
throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
|
|
826
822
|
n("Agent joined, reconnection successful");
|
|
@@ -829,10 +825,10 @@ async function Jt(e, t, i) {
|
|
|
829
825
|
throw n("Failed to reconnect:", y), (g = a.onConnectionStateChange) == null || g.call(a, I.Fail, "user:reconnect-failed"), y;
|
|
830
826
|
}
|
|
831
827
|
},
|
|
832
|
-
sendDataChannelMessage:
|
|
833
|
-
sendTextMessage:
|
|
828
|
+
sendDataChannelMessage: ce,
|
|
829
|
+
sendTextMessage: ye,
|
|
834
830
|
publishMicrophoneStream: p,
|
|
835
|
-
unpublishMicrophoneStream:
|
|
831
|
+
unpublishMicrophoneStream: m,
|
|
836
832
|
sessionId: z,
|
|
837
833
|
streamId: z,
|
|
838
834
|
streamType: x,
|
|
@@ -840,39 +836,39 @@ async function Jt(e, t, i) {
|
|
|
840
836
|
triggersAvailable: !1
|
|
841
837
|
};
|
|
842
838
|
}
|
|
843
|
-
const
|
|
839
|
+
const Kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
844
840
|
__proto__: null,
|
|
845
841
|
DataChannelTopic: je,
|
|
846
|
-
createLiveKitStreamingManager:
|
|
842
|
+
createLiveKitStreamingManager: zt,
|
|
847
843
|
handleInitError: _e
|
|
848
844
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
849
|
-
function
|
|
845
|
+
function Nt(e, t, i) {
|
|
850
846
|
if (!e)
|
|
851
847
|
throw new Error("Please connect to the agent first");
|
|
852
848
|
if (!e.interruptAvailable)
|
|
853
849
|
throw new Error("Interrupt is not enabled for this stream");
|
|
854
|
-
if (t !==
|
|
850
|
+
if (t !== ie.Fluent)
|
|
855
851
|
throw new Error("Interrupt only available for Fluent streams");
|
|
856
852
|
if (!i)
|
|
857
853
|
throw new Error("No active video to interrupt");
|
|
858
854
|
}
|
|
859
|
-
async function
|
|
855
|
+
async function Jt(e, t) {
|
|
860
856
|
const i = {
|
|
861
|
-
type:
|
|
857
|
+
type: L.StreamInterrupt,
|
|
862
858
|
videoId: t,
|
|
863
859
|
timestamp: Date.now()
|
|
864
860
|
};
|
|
865
861
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
866
862
|
}
|
|
867
|
-
async function
|
|
863
|
+
async function Ut(e) {
|
|
868
864
|
const t = {
|
|
869
865
|
topic: je.Interrupt
|
|
870
866
|
};
|
|
871
867
|
e.sendDataChannelMessage(JSON.stringify(t));
|
|
872
868
|
}
|
|
873
|
-
function
|
|
869
|
+
function Vt(e) {
|
|
874
870
|
return new Promise((t, i) => {
|
|
875
|
-
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))}`);
|
|
876
872
|
w.onmessage = a, w.onclose = d, w.onerror = (u) => {
|
|
877
873
|
console.error(u), h == null || h("Websocket failed to connect", u), i(u);
|
|
878
874
|
}, w.onopen = (u) => {
|
|
@@ -880,28 +876,28 @@ function qt(e) {
|
|
|
880
876
|
};
|
|
881
877
|
});
|
|
882
878
|
}
|
|
883
|
-
async function
|
|
879
|
+
async function Wt(e) {
|
|
884
880
|
const { retries: t = 1 } = e;
|
|
885
881
|
let i = null;
|
|
886
882
|
for (let n = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; n++)
|
|
887
883
|
try {
|
|
888
|
-
i = await
|
|
884
|
+
i = await Vt(e);
|
|
889
885
|
} catch (s) {
|
|
890
886
|
if (n === t)
|
|
891
887
|
throw s;
|
|
892
|
-
await
|
|
888
|
+
await Ve(n * 500);
|
|
893
889
|
}
|
|
894
890
|
return i;
|
|
895
891
|
}
|
|
896
|
-
async function
|
|
897
|
-
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({
|
|
898
894
|
auth: e,
|
|
899
895
|
host: t,
|
|
900
896
|
externalId: n,
|
|
901
897
|
callbacks: {
|
|
902
898
|
onError: (c) => {
|
|
903
899
|
var a;
|
|
904
|
-
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));
|
|
905
901
|
},
|
|
906
902
|
onMessage(c) {
|
|
907
903
|
const a = JSON.parse(c.data);
|
|
@@ -915,7 +911,7 @@ async function Xt(e, t, i, n) {
|
|
|
915
911
|
subscribeToEvents: (c) => s.push(c)
|
|
916
912
|
};
|
|
917
913
|
}
|
|
918
|
-
function
|
|
914
|
+
function Ht(e) {
|
|
919
915
|
if (e.answer !== void 0)
|
|
920
916
|
return e.answer;
|
|
921
917
|
let t = 0, i = "";
|
|
@@ -923,7 +919,7 @@ function Yt(e) {
|
|
|
923
919
|
i += e[t++];
|
|
924
920
|
return i;
|
|
925
921
|
}
|
|
926
|
-
function
|
|
922
|
+
function qt(e, t, i) {
|
|
927
923
|
if (!e.content)
|
|
928
924
|
return;
|
|
929
925
|
const n = t.messages[t.messages.length - 1];
|
|
@@ -937,9 +933,9 @@ function Gt(e, t, i) {
|
|
|
937
933
|
};
|
|
938
934
|
t.messages.push(s), i == null || i([...t.messages], "user");
|
|
939
935
|
}
|
|
940
|
-
function
|
|
936
|
+
function Qt(e, t, i, n, s) {
|
|
941
937
|
if (e === Y.Transcribe && t.content) {
|
|
942
|
-
|
|
938
|
+
qt(t, n, s);
|
|
943
939
|
return;
|
|
944
940
|
}
|
|
945
941
|
if (!(e === Y.Partial || e === Y.Answer))
|
|
@@ -959,10 +955,10 @@ function Zt(e, t, i, n, s) {
|
|
|
959
955
|
return;
|
|
960
956
|
const { content: a, sequence: r } = t;
|
|
961
957
|
e === Y.Partial ? i[r] = a : i.answer = a;
|
|
962
|
-
const d =
|
|
958
|
+
const d = Ht(i);
|
|
963
959
|
(c.content !== d || e === Y.Answer) && (c.content = d, s == null || s([...n.messages], e));
|
|
964
960
|
}
|
|
965
|
-
function
|
|
961
|
+
function Xt(e, t, i, n, s) {
|
|
966
962
|
let o = {};
|
|
967
963
|
const c = () => o = {};
|
|
968
964
|
let a = "answer";
|
|
@@ -975,13 +971,13 @@ function en(e, t, i, n, s) {
|
|
|
975
971
|
onMessage: (d, h) => {
|
|
976
972
|
var w, u;
|
|
977
973
|
if ("content" in h) {
|
|
978
|
-
const v = d ===
|
|
979
|
-
|
|
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", {
|
|
980
976
|
messages: t.messages.length,
|
|
981
977
|
mode: t.chatMode
|
|
982
978
|
});
|
|
983
979
|
} else {
|
|
984
|
-
const v =
|
|
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 });
|
|
985
981
|
if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", C, v.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
986
982
|
const R = t.messages[t.messages.length - 1];
|
|
987
983
|
if ((R == null ? void 0 : R.role) === "assistant") {
|
|
@@ -998,7 +994,7 @@ function en(e, t, i, n, s) {
|
|
|
998
994
|
}
|
|
999
995
|
};
|
|
1000
996
|
}
|
|
1001
|
-
function
|
|
997
|
+
function Yt(e, t, i, n) {
|
|
1002
998
|
const s = Le(e, `${t}/agents/${i}`, n);
|
|
1003
999
|
return {
|
|
1004
1000
|
createStream(o, c) {
|
|
@@ -1035,8 +1031,8 @@ function tn(e, t, i, n) {
|
|
|
1035
1031
|
}
|
|
1036
1032
|
};
|
|
1037
1033
|
}
|
|
1038
|
-
const
|
|
1039
|
-
function
|
|
1034
|
+
const Gt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1035
|
+
function Ke(e) {
|
|
1040
1036
|
switch (e) {
|
|
1041
1037
|
case "connected":
|
|
1042
1038
|
return I.Connected;
|
|
@@ -1056,7 +1052,7 @@ function Ne(e) {
|
|
|
1056
1052
|
return I.New;
|
|
1057
1053
|
}
|
|
1058
1054
|
}
|
|
1059
|
-
const
|
|
1055
|
+
const Zt = (e) => (t) => {
|
|
1060
1056
|
const [i, n = ""] = t.split(/:(.+)/);
|
|
1061
1057
|
try {
|
|
1062
1058
|
const s = JSON.parse(n);
|
|
@@ -1065,7 +1061,7 @@ const rn = (e) => (t) => {
|
|
|
1065
1061
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: n, error: s }), { subject: i, data: n };
|
|
1066
1062
|
}
|
|
1067
1063
|
};
|
|
1068
|
-
function
|
|
1064
|
+
function en({
|
|
1069
1065
|
statsSignal: e,
|
|
1070
1066
|
dataChannelSignal: t,
|
|
1071
1067
|
onVideoStateChange: i,
|
|
@@ -1074,7 +1070,7 @@ function an({
|
|
|
1074
1070
|
}) {
|
|
1075
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));
|
|
1076
1072
|
}
|
|
1077
|
-
function
|
|
1073
|
+
function tn({
|
|
1078
1074
|
statsSignal: e,
|
|
1079
1075
|
dataChannelSignal: t,
|
|
1080
1076
|
onVideoStateChange: i,
|
|
@@ -1082,9 +1078,9 @@ function on({
|
|
|
1082
1078
|
report: s,
|
|
1083
1079
|
log: o
|
|
1084
1080
|
}) {
|
|
1085
|
-
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(
|
|
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));
|
|
1086
1082
|
}
|
|
1087
|
-
function
|
|
1083
|
+
function Ne({
|
|
1088
1084
|
statsSignal: e,
|
|
1089
1085
|
dataChannelSignal: t,
|
|
1090
1086
|
onVideoStateChange: i,
|
|
@@ -1093,7 +1089,7 @@ function Ve({
|
|
|
1093
1089
|
report: o,
|
|
1094
1090
|
log: c
|
|
1095
1091
|
}) {
|
|
1096
|
-
s ===
|
|
1092
|
+
s === ie.Legacy ? en({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o, log: c }) : s === ie.Fluent && tn({
|
|
1097
1093
|
statsSignal: e,
|
|
1098
1094
|
dataChannelSignal: t,
|
|
1099
1095
|
onVideoStateChange: i,
|
|
@@ -1102,55 +1098,55 @@ function Ve({
|
|
|
1102
1098
|
log: c
|
|
1103
1099
|
});
|
|
1104
1100
|
}
|
|
1105
|
-
async function
|
|
1101
|
+
async function nn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = we, analytics: c }, a) {
|
|
1106
1102
|
var oe;
|
|
1107
|
-
const r =
|
|
1103
|
+
const r = Xe(i, "WebRTCStreamingManager"), d = Zt(r);
|
|
1108
1104
|
let h = !1, w = !1, u = M.Stop, v = M.Stop;
|
|
1109
|
-
const { startConnection: x, sendStreamRequest: b, close: C, createStream: R, addIceCandidate: F } =
|
|
1105
|
+
const { startConnection: x, sendStreamRequest: b, close: C, createStream: R, addIceCandidate: F } = Yt(
|
|
1110
1106
|
s,
|
|
1111
1107
|
o,
|
|
1112
1108
|
e,
|
|
1113
1109
|
n.onError
|
|
1114
1110
|
), {
|
|
1115
1111
|
id: S,
|
|
1116
|
-
offer:
|
|
1117
|
-
ice_servers:
|
|
1118
|
-
session_id:
|
|
1112
|
+
offer: O,
|
|
1113
|
+
ice_servers: J,
|
|
1114
|
+
session_id: H,
|
|
1119
1115
|
fluent: z,
|
|
1120
1116
|
interrupt_enabled: ee,
|
|
1121
1117
|
triggers_enabled: te
|
|
1122
1118
|
} = await R(t, a);
|
|
1123
|
-
(oe = n.onStreamCreated) == null || oe.call(n, { stream_id: S, session_id:
|
|
1124
|
-
const l = new
|
|
1125
|
-
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)
|
|
1126
1122
|
throw new Error("Could not create session_id");
|
|
1127
|
-
const k = z ?
|
|
1123
|
+
const k = z ? ie.Fluent : ie.Legacy;
|
|
1128
1124
|
c.enrich({
|
|
1129
1125
|
"stream-type": k
|
|
1130
1126
|
});
|
|
1131
|
-
const K = t.stream_warmup && !z,
|
|
1127
|
+
const K = t.stream_warmup && !z, P = () => h, T = () => {
|
|
1132
1128
|
var p;
|
|
1133
1129
|
h = !0, w && (r("CALLBACK: onConnectionStateChange(Connected)"), (p = n.onConnectionStateChange) == null || p.call(n, I.Connected));
|
|
1134
|
-
}, N =
|
|
1130
|
+
}, N = Ye(
|
|
1135
1131
|
() => l.getStats(),
|
|
1136
|
-
|
|
1132
|
+
P,
|
|
1137
1133
|
T,
|
|
1138
|
-
(p,
|
|
1134
|
+
(p, m) => Ne({
|
|
1139
1135
|
statsSignal: v = p,
|
|
1140
|
-
dataChannelSignal: k ===
|
|
1136
|
+
dataChannelSignal: k === ie.Legacy ? u : void 0,
|
|
1141
1137
|
onVideoStateChange: n.onVideoStateChange,
|
|
1142
1138
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1143
|
-
report:
|
|
1139
|
+
report: m,
|
|
1144
1140
|
streamType: k,
|
|
1145
1141
|
log: r
|
|
1146
1142
|
}),
|
|
1147
1143
|
(p) => {
|
|
1148
|
-
var
|
|
1149
|
-
return (
|
|
1144
|
+
var m;
|
|
1145
|
+
return (m = n.onConnectivityStateChange) == null ? void 0 : m.call(n, p);
|
|
1150
1146
|
}
|
|
1151
1147
|
);
|
|
1152
1148
|
N.start(), l.onicecandidate = (p) => {
|
|
1153
|
-
var
|
|
1149
|
+
var m;
|
|
1154
1150
|
r("peerConnection.onicecandidate", p);
|
|
1155
1151
|
try {
|
|
1156
1152
|
p.candidate && p.candidate.sdpMid && p.candidate.sdpMLineIndex !== null ? F(
|
|
@@ -1160,26 +1156,26 @@ async function sn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = pe,
|
|
|
1160
1156
|
sdpMid: p.candidate.sdpMid,
|
|
1161
1157
|
sdpMLineIndex: p.candidate.sdpMLineIndex
|
|
1162
1158
|
},
|
|
1163
|
-
|
|
1159
|
+
H,
|
|
1164
1160
|
a
|
|
1165
|
-
) : F(S, { candidate: null },
|
|
1161
|
+
) : F(S, { candidate: null }, H, a);
|
|
1166
1162
|
} catch (E) {
|
|
1167
|
-
(
|
|
1163
|
+
(m = n.onError) == null || m.call(n, E, { streamId: S });
|
|
1168
1164
|
}
|
|
1169
1165
|
}, D.onopen = () => {
|
|
1170
1166
|
w = !0, (!K || h) && T();
|
|
1171
1167
|
};
|
|
1172
|
-
const
|
|
1173
|
-
var
|
|
1174
|
-
(
|
|
1168
|
+
const q = (p) => {
|
|
1169
|
+
var m;
|
|
1170
|
+
(m = n.onVideoIdChange) == null || m.call(n, p);
|
|
1175
1171
|
};
|
|
1176
|
-
function
|
|
1177
|
-
if (p ===
|
|
1178
|
-
const E =
|
|
1179
|
-
|
|
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);
|
|
1180
1176
|
}
|
|
1181
|
-
p ===
|
|
1182
|
-
statsSignal: k ===
|
|
1177
|
+
p === L.StreamDone && q(null), u = p === L.StreamStarted ? M.Start : M.Stop, Ne({
|
|
1178
|
+
statsSignal: k === ie.Legacy ? v : void 0,
|
|
1183
1179
|
dataChannelSignal: u,
|
|
1184
1180
|
onVideoStateChange: n.onVideoStateChange,
|
|
1185
1181
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
@@ -1187,37 +1183,37 @@ async function sn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = pe,
|
|
|
1187
1183
|
log: r
|
|
1188
1184
|
});
|
|
1189
1185
|
}
|
|
1190
|
-
function j(p,
|
|
1191
|
-
var
|
|
1192
|
-
const E = typeof
|
|
1193
|
-
E && c.enrich({ streamMetadata: E }), (
|
|
1186
|
+
function j(p, m) {
|
|
1187
|
+
var V;
|
|
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);
|
|
1194
1190
|
}
|
|
1195
1191
|
const $ = {
|
|
1196
|
-
[
|
|
1197
|
-
[
|
|
1198
|
-
[
|
|
1192
|
+
[L.StreamStarted]: Q,
|
|
1193
|
+
[L.StreamDone]: Q,
|
|
1194
|
+
[L.StreamReady]: j
|
|
1199
1195
|
};
|
|
1200
1196
|
D.onmessage = (p) => {
|
|
1201
|
-
var
|
|
1202
|
-
const { subject:
|
|
1203
|
-
(
|
|
1197
|
+
var V;
|
|
1198
|
+
const { subject: m, data: E } = d(p.data);
|
|
1199
|
+
(V = $[m]) == null || V.call($, m, E);
|
|
1204
1200
|
}, l.oniceconnectionstatechange = () => {
|
|
1205
|
-
var
|
|
1201
|
+
var m;
|
|
1206
1202
|
r("peerConnection.oniceconnectionstatechange => " + l.iceConnectionState);
|
|
1207
|
-
const p =
|
|
1208
|
-
p !== I.Connected && ((
|
|
1203
|
+
const p = Ke(l.iceConnectionState);
|
|
1204
|
+
p !== I.Connected && ((m = n.onConnectionStateChange) == null || m.call(n, p));
|
|
1209
1205
|
}, l.ontrack = (p) => {
|
|
1210
|
-
var
|
|
1211
|
-
r("peerConnection.ontrack", p), r("CALLBACK: onSrcObjectReady"), (
|
|
1212
|
-
}, await l.setRemoteDescription(
|
|
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");
|
|
1213
1209
|
const G = await l.createAnswer();
|
|
1214
|
-
return r("create answer OK"), await l.setLocalDescription(G), r("set local description OK"), await x(S, G,
|
|
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"), {
|
|
1215
1211
|
/**
|
|
1216
1212
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1217
1213
|
* @param payload
|
|
1218
1214
|
*/
|
|
1219
1215
|
speak(p) {
|
|
1220
|
-
return b(S,
|
|
1216
|
+
return b(S, H, p);
|
|
1221
1217
|
},
|
|
1222
1218
|
/**
|
|
1223
1219
|
* Method to close RTC connection
|
|
@@ -1225,44 +1221,44 @@ async function sn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = pe,
|
|
|
1225
1221
|
async disconnect() {
|
|
1226
1222
|
var p;
|
|
1227
1223
|
if (S) {
|
|
1228
|
-
const
|
|
1224
|
+
const m = Ke(l.iceConnectionState);
|
|
1229
1225
|
if (l) {
|
|
1230
|
-
if (
|
|
1226
|
+
if (m === I.New) {
|
|
1231
1227
|
N.stop();
|
|
1232
1228
|
return;
|
|
1233
1229
|
}
|
|
1234
1230
|
l.close(), l.oniceconnectionstatechange = null, l.onnegotiationneeded = null, l.onicecandidate = null, l.ontrack = null;
|
|
1235
1231
|
}
|
|
1236
1232
|
try {
|
|
1237
|
-
|
|
1233
|
+
m === I.Connected && await C(S, H).catch((E) => {
|
|
1238
1234
|
});
|
|
1239
1235
|
} catch (E) {
|
|
1240
1236
|
r("Error on close stream connection", E);
|
|
1241
1237
|
}
|
|
1242
|
-
(p = n.onAgentActivityStateChange) == null || p.call(n,
|
|
1238
|
+
(p = n.onAgentActivityStateChange) == null || p.call(n, W.Idle), N.stop();
|
|
1243
1239
|
}
|
|
1244
1240
|
},
|
|
1245
1241
|
/**
|
|
1246
1242
|
* Method to send data channel messages to the server
|
|
1247
1243
|
*/
|
|
1248
1244
|
sendDataChannelMessage(p) {
|
|
1249
|
-
var
|
|
1245
|
+
var m, E;
|
|
1250
1246
|
if (!h || D.readyState !== "open") {
|
|
1251
|
-
r("Data channel is not ready for sending messages"), (
|
|
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"), {
|
|
1252
1248
|
streamId: S
|
|
1253
1249
|
});
|
|
1254
1250
|
return;
|
|
1255
1251
|
}
|
|
1256
1252
|
try {
|
|
1257
1253
|
D.send(p);
|
|
1258
|
-
} catch (
|
|
1259
|
-
r("Error sending data channel message",
|
|
1254
|
+
} catch (V) {
|
|
1255
|
+
r("Error sending data channel message", V), (E = n.onError) == null || E.call(n, V, { streamId: S });
|
|
1260
1256
|
}
|
|
1261
1257
|
},
|
|
1262
1258
|
/**
|
|
1263
1259
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1264
1260
|
*/
|
|
1265
|
-
sessionId:
|
|
1261
|
+
sessionId: H,
|
|
1266
1262
|
/**
|
|
1267
1263
|
* Id of current RTC stream
|
|
1268
1264
|
*/
|
|
@@ -1273,18 +1269,18 @@ async function sn(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = pe,
|
|
|
1273
1269
|
};
|
|
1274
1270
|
}
|
|
1275
1271
|
var Ae = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ae || {});
|
|
1276
|
-
async function
|
|
1272
|
+
async function rn(e, t, i, n) {
|
|
1277
1273
|
const s = e.id;
|
|
1278
1274
|
switch (t.version) {
|
|
1279
1275
|
case "v1": {
|
|
1280
1276
|
const { version: o, ...c } = t;
|
|
1281
|
-
return
|
|
1277
|
+
return nn(s, c, i, n);
|
|
1282
1278
|
}
|
|
1283
1279
|
case "v2": {
|
|
1284
1280
|
const { version: o, ...c } = t;
|
|
1285
1281
|
switch (c.transport_provider) {
|
|
1286
1282
|
case ke.Livekit:
|
|
1287
|
-
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() =>
|
|
1283
|
+
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Kt);
|
|
1288
1284
|
return a(s, c, i);
|
|
1289
1285
|
default:
|
|
1290
1286
|
throw new Error(`Unsupported transport provider: ${c.transport_provider}`);
|
|
@@ -1294,13 +1290,13 @@ async function cn(e, t, i, n) {
|
|
|
1294
1290
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1295
1291
|
}
|
|
1296
1292
|
}
|
|
1297
|
-
const
|
|
1298
|
-
function
|
|
1293
|
+
const an = "cht";
|
|
1294
|
+
function on() {
|
|
1299
1295
|
return {
|
|
1300
1296
|
transport_provider: ke.Livekit
|
|
1301
1297
|
};
|
|
1302
1298
|
}
|
|
1303
|
-
function
|
|
1299
|
+
function sn(e) {
|
|
1304
1300
|
var s, o;
|
|
1305
1301
|
const { streamOptions: t } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
|
|
1306
1302
|
plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
|
|
@@ -1313,16 +1309,16 @@ function ln(e) {
|
|
|
1313
1309
|
fluent: t == null ? void 0 : t.fluent
|
|
1314
1310
|
}, ...i && { end_user_data: i } };
|
|
1315
1311
|
}
|
|
1316
|
-
function
|
|
1317
|
-
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) };
|
|
1318
1314
|
}
|
|
1319
|
-
function
|
|
1315
|
+
function dn(e, t, i) {
|
|
1320
1316
|
i.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1321
1317
|
}
|
|
1322
|
-
function
|
|
1323
|
-
s ===
|
|
1318
|
+
function un(e, t, i, n, s) {
|
|
1319
|
+
s === ie.Fluent ? ln(e, t, i, n, s) : mn(e, t, i, n, s);
|
|
1324
1320
|
}
|
|
1325
|
-
function
|
|
1321
|
+
function ln(e, t, i, n, s) {
|
|
1326
1322
|
e === M.Start ? n.track("stream-session", { event: "start", "stream-type": s }) : e === M.Stop && n.track("stream-session", {
|
|
1327
1323
|
event: "stop",
|
|
1328
1324
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
@@ -1331,12 +1327,12 @@ function hn(e, t, i, n, s) {
|
|
|
1331
1327
|
...i
|
|
1332
1328
|
});
|
|
1333
1329
|
}
|
|
1334
|
-
function
|
|
1330
|
+
function fn(e, t, i, n) {
|
|
1335
1331
|
ne.get() <= 0 || (e === M.Start ? i.linkTrack(
|
|
1336
1332
|
"agent-video",
|
|
1337
1333
|
{ event: "start", latency: ne.get(!0), "stream-type": n },
|
|
1338
1334
|
"start",
|
|
1339
|
-
[
|
|
1335
|
+
[L.StreamVideoCreated]
|
|
1340
1336
|
) : e === M.Stop && i.linkTrack(
|
|
1341
1337
|
"agent-video",
|
|
1342
1338
|
{
|
|
@@ -1346,15 +1342,15 @@ function pn(e, t, i, n) {
|
|
|
1346
1342
|
"stream-type": n
|
|
1347
1343
|
},
|
|
1348
1344
|
"done",
|
|
1349
|
-
[
|
|
1345
|
+
[L.StreamVideoDone]
|
|
1350
1346
|
));
|
|
1351
1347
|
}
|
|
1352
|
-
function
|
|
1348
|
+
function mn(e, t, i, n, s) {
|
|
1353
1349
|
ne.get() <= 0 || (e === M.Start ? n.linkTrack(
|
|
1354
1350
|
"agent-video",
|
|
1355
1351
|
{ event: "start", latency: ne.get(!0), "stream-type": s },
|
|
1356
1352
|
"start",
|
|
1357
|
-
[
|
|
1353
|
+
[L.StreamVideoCreated]
|
|
1358
1354
|
) : e === M.Stop && n.linkTrack(
|
|
1359
1355
|
"agent-video",
|
|
1360
1356
|
{
|
|
@@ -1365,17 +1361,17 @@ function wn(e, t, i, n, s) {
|
|
|
1365
1361
|
...i
|
|
1366
1362
|
},
|
|
1367
1363
|
"done",
|
|
1368
|
-
[
|
|
1364
|
+
[L.StreamVideoDone]
|
|
1369
1365
|
));
|
|
1370
1366
|
}
|
|
1371
1367
|
function Je(e, t, i, n) {
|
|
1372
|
-
return ne.reset(),
|
|
1368
|
+
return ne.reset(), Fe.update(), new Promise(async (s, o) => {
|
|
1373
1369
|
try {
|
|
1374
1370
|
let c, a = !1;
|
|
1375
|
-
const r =
|
|
1371
|
+
const r = cn(e, t);
|
|
1376
1372
|
i.enrich({
|
|
1377
1373
|
"stream-version": r.version.toString()
|
|
1378
|
-
}), c = await
|
|
1374
|
+
}), c = await rn(
|
|
1379
1375
|
e,
|
|
1380
1376
|
r,
|
|
1381
1377
|
{
|
|
@@ -1385,11 +1381,11 @@ function Je(e, t, i, n) {
|
|
|
1385
1381
|
...t.callbacks,
|
|
1386
1382
|
onConnectionStateChange: (d, h) => {
|
|
1387
1383
|
var w, u;
|
|
1388
|
-
(u = (w = t.callbacks).onConnectionStateChange) == null || u.call(w, d),
|
|
1384
|
+
(u = (w = t.callbacks).onConnectionStateChange) == null || u.call(w, d), dn(d, h, i), d === I.Connected && (c ? s(c) : a = !0);
|
|
1389
1385
|
},
|
|
1390
1386
|
onVideoStateChange: (d, h) => {
|
|
1391
1387
|
var w, u;
|
|
1392
|
-
(u = (w = t.callbacks).onVideoStateChange) == null || u.call(w, d),
|
|
1388
|
+
(u = (w = t.callbacks).onVideoStateChange) == null || u.call(w, d), un(
|
|
1393
1389
|
d,
|
|
1394
1390
|
e,
|
|
1395
1391
|
h,
|
|
@@ -1399,15 +1395,15 @@ function Je(e, t, i, n) {
|
|
|
1399
1395
|
},
|
|
1400
1396
|
onAgentActivityStateChange: (d) => {
|
|
1401
1397
|
var h, w;
|
|
1402
|
-
(w = (h = t.callbacks).onAgentActivityStateChange) == null || w.call(h, d), d ===
|
|
1403
|
-
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,
|
|
1404
1400
|
e,
|
|
1405
1401
|
i,
|
|
1406
1402
|
c.streamType
|
|
1407
1403
|
);
|
|
1408
1404
|
},
|
|
1409
1405
|
onStreamReady: () => {
|
|
1410
|
-
const d =
|
|
1406
|
+
const d = Fe.get(!0);
|
|
1411
1407
|
i.track("agent-chat", { event: "ready", latency: d });
|
|
1412
1408
|
}
|
|
1413
1409
|
}
|
|
@@ -1419,11 +1415,11 @@ function Je(e, t, i, n) {
|
|
|
1419
1415
|
}
|
|
1420
1416
|
});
|
|
1421
1417
|
}
|
|
1422
|
-
async function
|
|
1418
|
+
async function gn(e, t, i, n, s) {
|
|
1423
1419
|
var h, w, u, v;
|
|
1424
1420
|
const o = async () => {
|
|
1425
1421
|
if (Pe(e.presenter.type)) {
|
|
1426
|
-
const x = await Je(e, t, n), b = `${
|
|
1422
|
+
const x = await Je(e, t, n), b = `${an}_${x.sessionId}`, C = (/* @__PURE__ */ new Date()).toISOString();
|
|
1427
1423
|
return { chatResult: {
|
|
1428
1424
|
chatMode: B.Functional,
|
|
1429
1425
|
chat: {
|
|
@@ -1442,44 +1438,44 @@ async function yn(e, t, i, n, s) {
|
|
|
1442
1438
|
const x = new AbortController(), b = x.signal;
|
|
1443
1439
|
let C;
|
|
1444
1440
|
try {
|
|
1445
|
-
const R =
|
|
1441
|
+
const R = Qe(
|
|
1446
1442
|
e,
|
|
1447
1443
|
i,
|
|
1448
1444
|
n,
|
|
1449
1445
|
t.mode,
|
|
1450
1446
|
t.persistentChat,
|
|
1451
1447
|
s
|
|
1452
|
-
), F = Je(e, t, n, b).then((
|
|
1453
|
-
return { chatResult: S, streamingManager:
|
|
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 };
|
|
1454
1450
|
} catch (R) {
|
|
1455
1451
|
throw x.abort(), C && await C.disconnect().catch(() => {
|
|
1456
1452
|
}), R;
|
|
1457
1453
|
}
|
|
1458
1454
|
}
|
|
1459
1455
|
}, { chatResult: c, streamingManager: a } = await o(), { chat: r, chatMode: d } = c;
|
|
1460
|
-
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
|
|
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 };
|
|
1461
1457
|
}
|
|
1462
|
-
async function
|
|
1463
|
-
var
|
|
1458
|
+
async function wn(e, t) {
|
|
1459
|
+
var H, z, ee, te;
|
|
1464
1460
|
let i = !0, n = null;
|
|
1465
|
-
const s = t.mixpanelKey ||
|
|
1461
|
+
const s = t.mixpanelKey || ht, o = t.wsURL || gt, c = t.baseURL || we, a = t.mode || B.Functional, r = {
|
|
1466
1462
|
messages: [],
|
|
1467
1463
|
chatMode: a
|
|
1468
|
-
}, d =
|
|
1464
|
+
}, d = It({
|
|
1469
1465
|
token: s,
|
|
1470
1466
|
agentId: e,
|
|
1471
1467
|
isEnabled: t.enableAnalitics,
|
|
1472
1468
|
externalId: t.externalId,
|
|
1473
1469
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1474
1470
|
}), h = Date.now();
|
|
1475
|
-
|
|
1471
|
+
xe(() => {
|
|
1476
1472
|
d.track("agent-sdk", { event: "init" }, h);
|
|
1477
1473
|
});
|
|
1478
|
-
const w =
|
|
1479
|
-
t.debug = t.debug || ((
|
|
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);
|
|
1480
1476
|
const v = Pe(u.presenter.type);
|
|
1481
|
-
d.enrich(
|
|
1482
|
-
const { onMessage: x, clearQueue: b } =
|
|
1477
|
+
d.enrich(Rt(u));
|
|
1478
|
+
const { onMessage: x, clearQueue: b } = Xt(
|
|
1483
1479
|
d,
|
|
1484
1480
|
r,
|
|
1485
1481
|
t,
|
|
@@ -1489,31 +1485,31 @@ async function Sn(e, t) {
|
|
|
1489
1485
|
return (l = r.socketManager) == null ? void 0 : l.disconnect();
|
|
1490
1486
|
}
|
|
1491
1487
|
);
|
|
1492
|
-
r.messages =
|
|
1488
|
+
r.messages = _t(t.initialMessages), (ee = (z = t.callbacks).onNewMessage) == null || ee.call(z, [...r.messages], "answer");
|
|
1493
1489
|
const C = (l) => {
|
|
1494
1490
|
n = l;
|
|
1495
1491
|
}, R = ({ type: l }) => {
|
|
1496
|
-
var k, K,
|
|
1492
|
+
var k, K, P;
|
|
1497
1493
|
const D = r.messages[r.messages.length - 1];
|
|
1498
1494
|
d.track("agent-video-interrupt", {
|
|
1499
1495
|
type: l || "click",
|
|
1500
1496
|
video_duration_to_interrupt: Te.get(!0),
|
|
1501
1497
|
message_duration_to_interrupt: ne.get(!0)
|
|
1502
|
-
}), D.interrupted = !0, (K = (k = t.callbacks).onNewMessage) == null || K.call(k, [...r.messages], "answer"), v ?
|
|
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));
|
|
1503
1499
|
}, F = Date.now();
|
|
1504
|
-
|
|
1505
|
-
d.track("agent-sdk", { event: "loaded", ...
|
|
1500
|
+
xe(() => {
|
|
1501
|
+
d.track("agent-sdk", { event: "loaded", ...kt(u) }, F);
|
|
1506
1502
|
});
|
|
1507
1503
|
async function S(l) {
|
|
1508
|
-
var N,
|
|
1509
|
-
(
|
|
1510
|
-
const D = a === B.DirectPlayback || v ? Promise.resolve(void 0) :
|
|
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(
|
|
1511
1507
|
t.auth,
|
|
1512
1508
|
o,
|
|
1513
1509
|
{ onMessage: x, onError: t.callbacks.onError },
|
|
1514
1510
|
t.externalId
|
|
1515
1511
|
), k = Ee(
|
|
1516
|
-
() =>
|
|
1512
|
+
() => gn(
|
|
1517
1513
|
u,
|
|
1518
1514
|
{
|
|
1519
1515
|
...t,
|
|
@@ -1531,28 +1527,28 @@ async function Sn(e, t) {
|
|
|
1531
1527
|
),
|
|
1532
1528
|
{
|
|
1533
1529
|
limit: 3,
|
|
1534
|
-
timeout:
|
|
1530
|
+
timeout: ft,
|
|
1535
1531
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1536
1532
|
shouldRetryFn: (p) => (p == null ? void 0 : p.message) !== "Could not connect" && p.status !== 429 && (p == null ? void 0 : p.message) !== "InsufficientCreditsError",
|
|
1537
1533
|
delayMs: 1e3
|
|
1538
1534
|
}
|
|
1539
1535
|
).catch((p) => {
|
|
1540
|
-
var
|
|
1541
|
-
throw
|
|
1542
|
-
}), [K, { streamingManager:
|
|
1543
|
-
T && T.id !== (($ = r.chat) == null ? void 0 : $.id) && ((oe = (G = t.callbacks).onNewChat) == null || oe.call(G, T.id)), r.streamingManager =
|
|
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({
|
|
1544
1540
|
chatId: T == null ? void 0 : T.id,
|
|
1545
|
-
streamId:
|
|
1541
|
+
streamId: P == null ? void 0 : P.streamId,
|
|
1546
1542
|
mode: r.chatMode
|
|
1547
|
-
}),
|
|
1543
|
+
}), J((T == null ? void 0 : T.chat_mode) ?? a);
|
|
1548
1544
|
}
|
|
1549
|
-
async function
|
|
1545
|
+
async function O() {
|
|
1550
1546
|
var l, D, k, K;
|
|
1551
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);
|
|
1552
1548
|
}
|
|
1553
|
-
async function
|
|
1549
|
+
async function J(l) {
|
|
1554
1550
|
var D, k;
|
|
1555
|
-
l !== r.chatMode && (d.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== B.Functional && await
|
|
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));
|
|
1556
1552
|
}
|
|
1557
1553
|
return {
|
|
1558
1554
|
agent: u,
|
|
@@ -1570,7 +1566,7 @@ async function Sn(e, t) {
|
|
|
1570
1566
|
},
|
|
1571
1567
|
starterMessages: ((te = u.knowledge) == null ? void 0 : te.starter_message) || [],
|
|
1572
1568
|
getSTTToken: () => w.getSTTToken(u.id),
|
|
1573
|
-
changeMode:
|
|
1569
|
+
changeMode: J,
|
|
1574
1570
|
enrichAnalytics: d.enrich,
|
|
1575
1571
|
async connect() {
|
|
1576
1572
|
await S(!0), d.track("agent-chat", {
|
|
@@ -1587,17 +1583,17 @@ async function Sn(e, t) {
|
|
|
1587
1583
|
mode: r.chatMode
|
|
1588
1584
|
});
|
|
1589
1585
|
} catch {
|
|
1590
|
-
await
|
|
1586
|
+
await O(), await S(!1);
|
|
1591
1587
|
}
|
|
1592
1588
|
return;
|
|
1593
1589
|
}
|
|
1594
|
-
await
|
|
1590
|
+
await O(), await S(!1), d.track("agent-chat", {
|
|
1595
1591
|
event: "reconnect",
|
|
1596
1592
|
mode: r.chatMode
|
|
1597
1593
|
});
|
|
1598
1594
|
},
|
|
1599
1595
|
async disconnect() {
|
|
1600
|
-
await
|
|
1596
|
+
await O(), d.track("agent-chat", {
|
|
1601
1597
|
event: "disconnect",
|
|
1602
1598
|
mode: r.chatMode
|
|
1603
1599
|
});
|
|
@@ -1615,9 +1611,9 @@ async function Sn(e, t) {
|
|
|
1615
1611
|
return r.streamingManager.unpublishMicrophoneStream();
|
|
1616
1612
|
},
|
|
1617
1613
|
async chat(l) {
|
|
1618
|
-
var
|
|
1614
|
+
var P, T, N, q, Q;
|
|
1619
1615
|
const D = () => {
|
|
1620
|
-
if (
|
|
1616
|
+
if (Oe(a))
|
|
1621
1617
|
throw new le(`${a} is enabled, chat is disabled`);
|
|
1622
1618
|
if (l.length >= 800)
|
|
1623
1619
|
throw new le("Message cannot be more than 800 characters");
|
|
@@ -1634,7 +1630,7 @@ async function Sn(e, t) {
|
|
|
1634
1630
|
}, k = async () => {
|
|
1635
1631
|
var j, $;
|
|
1636
1632
|
if (!r.chat) {
|
|
1637
|
-
const G = await
|
|
1633
|
+
const G = await Qe(
|
|
1638
1634
|
u,
|
|
1639
1635
|
w,
|
|
1640
1636
|
d,
|
|
@@ -1642,53 +1638,53 @@ async function Sn(e, t) {
|
|
|
1642
1638
|
t.persistentChat
|
|
1643
1639
|
);
|
|
1644
1640
|
if (!G.chat)
|
|
1645
|
-
throw new
|
|
1641
|
+
throw new et(r.chatMode, !!t.persistentChat);
|
|
1646
1642
|
r.chat = G.chat, ($ = (j = t.callbacks).onNewChat) == null || $.call(j, r.chat.id);
|
|
1647
1643
|
}
|
|
1648
1644
|
return r.chat.id;
|
|
1649
1645
|
}, K = async (j, $) => {
|
|
1650
1646
|
const G = r.chatMode === B.Playground;
|
|
1651
1647
|
return Ee(v && !G ? async () => {
|
|
1652
|
-
var
|
|
1653
|
-
return await ((E = (
|
|
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({});
|
|
1654
1650
|
} : async () => {
|
|
1655
|
-
var
|
|
1651
|
+
var m, E;
|
|
1656
1652
|
return w.chat(
|
|
1657
1653
|
u.id,
|
|
1658
1654
|
$,
|
|
1659
1655
|
{
|
|
1660
1656
|
chatMode: r.chatMode,
|
|
1661
|
-
streamId: (
|
|
1657
|
+
streamId: (m = r.streamingManager) == null ? void 0 : m.streamId,
|
|
1662
1658
|
sessionId: (E = r.streamingManager) == null ? void 0 : E.sessionId,
|
|
1663
|
-
messages: j.map(({ matches:
|
|
1659
|
+
messages: j.map(({ matches: V, ...ce }) => ce)
|
|
1664
1660
|
},
|
|
1665
1661
|
{
|
|
1666
|
-
...
|
|
1662
|
+
...qe(r.chatMode),
|
|
1667
1663
|
skipErrorHandler: !0
|
|
1668
1664
|
}
|
|
1669
1665
|
);
|
|
1670
1666
|
}, {
|
|
1671
1667
|
limit: 2,
|
|
1672
|
-
shouldRetryFn: (
|
|
1673
|
-
var
|
|
1674
|
-
const E = (
|
|
1675
|
-
return !((
|
|
1668
|
+
shouldRetryFn: (m) => {
|
|
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;
|
|
1676
1672
|
},
|
|
1677
1673
|
onRetry: async () => {
|
|
1678
|
-
await
|
|
1674
|
+
await O(), await S(!1);
|
|
1679
1675
|
}
|
|
1680
1676
|
});
|
|
1681
1677
|
};
|
|
1682
1678
|
try {
|
|
1683
1679
|
b(), D(), r.messages.push({
|
|
1684
|
-
id:
|
|
1680
|
+
id: fe(),
|
|
1685
1681
|
role: "user",
|
|
1686
1682
|
content: l,
|
|
1687
1683
|
created_at: new Date(ne.update()).toISOString()
|
|
1688
|
-
}), (T = (
|
|
1684
|
+
}), (T = (P = t.callbacks).onNewMessage) == null || T.call(P, [...r.messages], "user");
|
|
1689
1685
|
const j = await k(), $ = await K([...r.messages], j);
|
|
1690
1686
|
return r.messages.push({
|
|
1691
|
-
id:
|
|
1687
|
+
id: fe(),
|
|
1692
1688
|
role: "assistant",
|
|
1693
1689
|
content: $.result || "",
|
|
1694
1690
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1697,40 +1693,40 @@ async function Sn(e, t) {
|
|
|
1697
1693
|
}), d.track("agent-message-send", {
|
|
1698
1694
|
event: "success",
|
|
1699
1695
|
messages: r.messages.length + 1
|
|
1700
|
-
}), $.result && ((
|
|
1696
|
+
}), $.result && ((q = (N = t.callbacks).onNewMessage) == null || q.call(N, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1701
1697
|
latency: ne.get(!0),
|
|
1702
1698
|
messages: r.messages.length
|
|
1703
1699
|
})), $;
|
|
1704
1700
|
} catch (j) {
|
|
1705
|
-
throw ((
|
|
1701
|
+
throw ((Q = r.messages[r.messages.length - 1]) == null ? void 0 : Q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1706
1702
|
event: "error",
|
|
1707
1703
|
messages: r.messages.length
|
|
1708
1704
|
}), j;
|
|
1709
1705
|
}
|
|
1710
1706
|
},
|
|
1711
1707
|
rate(l, D, k) {
|
|
1712
|
-
var T, N,
|
|
1708
|
+
var T, N, q, Q;
|
|
1713
1709
|
const K = r.messages.find((j) => j.id === l);
|
|
1714
1710
|
if (r.chat) {
|
|
1715
1711
|
if (!K)
|
|
1716
1712
|
throw new Error("Message not found");
|
|
1717
1713
|
} else throw new Error("Chat is not initialized");
|
|
1718
|
-
const
|
|
1714
|
+
const P = ((T = K.matches) == null ? void 0 : T.map((j) => [j.document_id, j.id])) ?? [];
|
|
1719
1715
|
return d.track("agent-rate", {
|
|
1720
1716
|
event: k ? "update" : "create",
|
|
1721
1717
|
thumb: D === 1 ? "up" : "down",
|
|
1722
1718
|
knowledge_id: ((N = u.knowledge) == null ? void 0 : N.id) ?? "",
|
|
1723
|
-
matches:
|
|
1719
|
+
matches: P,
|
|
1724
1720
|
score: D
|
|
1725
1721
|
}), k ? w.updateRating(u.id, r.chat.id, k, {
|
|
1726
|
-
knowledge_id: ((
|
|
1722
|
+
knowledge_id: ((q = u.knowledge) == null ? void 0 : q.id) ?? "",
|
|
1727
1723
|
message_id: l,
|
|
1728
|
-
matches:
|
|
1724
|
+
matches: P,
|
|
1729
1725
|
score: D
|
|
1730
1726
|
}) : w.createRating(u.id, r.chat.id, {
|
|
1731
|
-
knowledge_id: ((
|
|
1727
|
+
knowledge_id: ((Q = u.knowledge) == null ? void 0 : Q.id) ?? "",
|
|
1732
1728
|
message_id: l,
|
|
1733
|
-
matches:
|
|
1729
|
+
matches: P,
|
|
1734
1730
|
score: D
|
|
1735
1731
|
});
|
|
1736
1732
|
},
|
|
@@ -1740,7 +1736,7 @@ async function Sn(e, t) {
|
|
|
1740
1736
|
return d.track("agent-rate-delete", { type: "text" }), w.deleteRating(u.id, r.chat.id, l);
|
|
1741
1737
|
},
|
|
1742
1738
|
async speak(l) {
|
|
1743
|
-
var
|
|
1739
|
+
var P, T, N;
|
|
1744
1740
|
function D() {
|
|
1745
1741
|
if (typeof l == "string") {
|
|
1746
1742
|
if (!u.presenter.voice)
|
|
@@ -1766,11 +1762,11 @@ async function Sn(e, t) {
|
|
|
1766
1762
|
}
|
|
1767
1763
|
const k = D();
|
|
1768
1764
|
if (d.track("agent-speak", k), ne.update(), r.messages && k.type === "text" && (r.messages.push({
|
|
1769
|
-
id:
|
|
1765
|
+
id: fe(),
|
|
1770
1766
|
role: "assistant",
|
|
1771
1767
|
content: k.input,
|
|
1772
1768
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1773
|
-
}), (T = (
|
|
1769
|
+
}), (T = (P = t.callbacks).onNewMessage) == null || T.call(P, [...r.messages], "answer")), wt(r.chatMode))
|
|
1774
1770
|
return {
|
|
1775
1771
|
duration: 0,
|
|
1776
1772
|
video_id: "",
|
|
@@ -1787,29 +1783,29 @@ async function Sn(e, t) {
|
|
|
1787
1783
|
};
|
|
1788
1784
|
}
|
|
1789
1785
|
export {
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1786
|
+
W as AgentActivityState,
|
|
1787
|
+
at as AgentStatus,
|
|
1788
|
+
et as ChatCreationFailed,
|
|
1793
1789
|
B as ChatMode,
|
|
1794
|
-
|
|
1790
|
+
tt as ChatModeDowngraded,
|
|
1795
1791
|
Y as ChatProgress,
|
|
1796
1792
|
I as ConnectionState,
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1793
|
+
re as ConnectivityState,
|
|
1794
|
+
dt as DocumentType,
|
|
1795
|
+
ct as KnowledgeType,
|
|
1796
|
+
it as PlanGroup,
|
|
1797
|
+
ut as Providers,
|
|
1798
|
+
ot as RateState,
|
|
1799
|
+
L as StreamEvents,
|
|
1800
|
+
ie as StreamType,
|
|
1805
1801
|
M as StreamingState,
|
|
1806
|
-
|
|
1802
|
+
st as Subject,
|
|
1807
1803
|
ke as TransportProvider,
|
|
1808
|
-
|
|
1804
|
+
rt as UserPlan,
|
|
1809
1805
|
le as ValidationError,
|
|
1810
1806
|
Ue as VideoType,
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1807
|
+
lt as VoiceAccess,
|
|
1808
|
+
nt as WsError,
|
|
1809
|
+
wn as createAgentManager,
|
|
1810
|
+
pn as mapVideoType
|
|
1815
1811
|
};
|