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