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