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