@d-id/client-sdk 1.1.22-staging.102 → 1.1.22-staging.104
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-DRoGHx1v.js → index-sABN87aB.js} +427 -378
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/livekit-manager-Cv9nty3S.js +256 -0
- package/dist/src/services/analytics/timestamp-tracker.d.ts +5 -0
- package/dist/src/services/streaming-manager/common.d.ts +13 -0
- package/dist/src/services/streaming-manager/livekit-manager.test.d.ts +1 -0
- package/dist/src/types/entities/agents/chat.d.ts +1 -0
- package/dist/src/types/entities/agents/manager.d.ts +18 -0
- package/dist/src/types/stream/stream.d.ts +8 -0
- package/package.json +1 -1
- package/dist/livekit-manager-t6ipl1oJ.js +0 -193
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var G = (e, t, n) =>
|
|
1
|
+
var Ee = Object.defineProperty;
|
|
2
|
+
var Me = (e, t, n) => t in e ? Ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var G = (e, t, n) => Me(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
class te extends Error {
|
|
5
5
|
constructor({ kind: n, description: r, error: c }) {
|
|
6
6
|
super(JSON.stringify({ kind: n, description: r }));
|
|
@@ -10,7 +10,7 @@ class te extends Error {
|
|
|
10
10
|
this.kind = n, this.description = r, this.error = c;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class _e extends te {
|
|
14
14
|
constructor(t, n) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,25 +18,25 @@ class Me extends te {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Te extends te {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class Y extends te {
|
|
27
27
|
constructor(n, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: n });
|
|
29
29
|
G(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class be extends te {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var Ae = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ae || {}),
|
|
39
|
-
const
|
|
38
|
+
var Ae = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ae || {}), Pe = /* @__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))(Pe || {}), je = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(je || {}), Le = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Le || {}), E = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(E || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(J || {}), $e = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))($e || {}), xe = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xe || {}), Be = /* @__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))(Be || {}), ye = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(ye || {});
|
|
39
|
+
const Ft = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,12 +48,12 @@ const Bt = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
52
|
-
const
|
|
51
|
+
var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), Z = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(Z || {}), P = /* @__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))(P || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(_ || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), de = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(de || {}), ze = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ze || {}), Fe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Fe || {});
|
|
52
|
+
const Ne = 45 * 1e3, Je = "X-Playground-Chat", re = "https://api.d-id.com", We = "wss://notifications.d-id.com", Ue = "79f81a83a67430be2bc0fd61042b8faa", ve = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
54
|
return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
-
},
|
|
56
|
-
function
|
|
55
|
+
}, ke = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, le = (e) => e === ye.Expressive, Ke = (e) => [E.TextOnly, E.Playground, E.Maintenance].includes(e), Se = (e) => e && [E.DirectPlayback, E.Off].includes(e);
|
|
56
|
+
function He(e, t) {
|
|
57
57
|
let n;
|
|
58
58
|
return {
|
|
59
59
|
promise: new Promise((c, s) => {
|
|
@@ -77,12 +77,12 @@ async function ae(e, t) {
|
|
|
77
77
|
try {
|
|
78
78
|
if (!n.timeout)
|
|
79
79
|
return await e();
|
|
80
|
-
const { promise: s, clear: o } =
|
|
80
|
+
const { promise: s, clear: o } = He(n.timeout, n.timeoutErrorMessage), a = e().finally(o);
|
|
81
81
|
return await Promise.race([a, s]);
|
|
82
82
|
} catch (s) {
|
|
83
83
|
if (r = s, !n.shouldRetryFn(s) || c >= n.limit)
|
|
84
84
|
throw s;
|
|
85
|
-
await
|
|
85
|
+
await ve(n.delayMs), n.onRetry(s);
|
|
86
86
|
}
|
|
87
87
|
throw r;
|
|
88
88
|
}
|
|
@@ -91,35 +91,35 @@ function ie(e) {
|
|
|
91
91
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
92
92
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
93
93
|
if (!t) {
|
|
94
|
-
let n =
|
|
94
|
+
let n = Q();
|
|
95
95
|
window.localStorage.setItem("did_external_key_id", n), t = n;
|
|
96
96
|
}
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
|
-
let
|
|
100
|
-
function
|
|
99
|
+
let Ve = Q();
|
|
100
|
+
function Ce(e, t) {
|
|
101
101
|
if (e.type === "bearer")
|
|
102
102
|
return `Bearer ${e.token}`;
|
|
103
103
|
if (e.type === "basic")
|
|
104
104
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
105
105
|
if (e.type === "key")
|
|
106
|
-
return `Client-Key ${e.clientKey}.${ie(t)}_${
|
|
106
|
+
return `Client-Key ${e.clientKey}.${ie(t)}_${Ve}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const qe = (e) => ae(e, {
|
|
110
110
|
limit: 3,
|
|
111
111
|
delayMs: 1e3,
|
|
112
112
|
timeout: 0,
|
|
113
113
|
shouldRetryFn: (t) => t.status === 429
|
|
114
114
|
});
|
|
115
|
-
function
|
|
115
|
+
function De(e, t = re, n, r) {
|
|
116
116
|
const c = async (s, o) => {
|
|
117
|
-
const { skipErrorHandler: a, ...i } = o || {}, d = await
|
|
117
|
+
const { skipErrorHandler: a, ...i } = o || {}, d = await qe(
|
|
118
118
|
() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
119
119
|
...i,
|
|
120
120
|
headers: {
|
|
121
121
|
...i.headers,
|
|
122
|
-
Authorization:
|
|
122
|
+
Authorization: Ce(e, r),
|
|
123
123
|
"Content-Type": "application/json"
|
|
124
124
|
}
|
|
125
125
|
})
|
|
@@ -146,8 +146,8 @@ function Ce(e, t = re, n, r) {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const c =
|
|
149
|
+
function Oe(e, t = re, n, r) {
|
|
150
|
+
const c = De(e, `${t}/agents`, n, r);
|
|
151
151
|
return {
|
|
152
152
|
create(s, o) {
|
|
153
153
|
return c.post("/", s, o);
|
|
@@ -184,7 +184,7 @@ function qe(e, t = re, n, r) {
|
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function Xe(e) {
|
|
188
188
|
var c, s, o, a;
|
|
189
189
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
|
|
190
190
|
const i = navigator.platform;
|
|
@@ -195,18 +195,18 @@ function Oe(e) {
|
|
|
195
195
|
isMobile: `${t() == "Mobile"}`,
|
|
196
196
|
browser: navigator.userAgent,
|
|
197
197
|
origin: window.location.origin,
|
|
198
|
-
agentType:
|
|
198
|
+
agentType: ke(r),
|
|
199
199
|
agentVoice: {
|
|
200
200
|
voiceId: (s = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : s.voice_id,
|
|
201
201
|
provider: (a = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : a.type
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function Ye(e) {
|
|
206
206
|
var n, r, c, s, o, a;
|
|
207
207
|
const t = (n = e.llm) == null ? void 0 : n.prompt_customization;
|
|
208
208
|
return {
|
|
209
|
-
agentType:
|
|
209
|
+
agentType: ke(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
211
211
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
212
212
|
behavior: {
|
|
@@ -225,8 +225,8 @@ function Xe(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
228
|
+
const Qe = (e) => e.reduce((t, n) => t + n, 0), me = (e) => Qe(e) / e.length;
|
|
229
|
+
function Ze(e, t, n) {
|
|
230
230
|
var i, d, l;
|
|
231
231
|
const { event: r, ...c } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
|
|
232
232
|
return {
|
|
@@ -241,8 +241,8 @@ function fe(e) {
|
|
|
241
241
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
242
|
}
|
|
243
243
|
let ne = {};
|
|
244
|
-
const
|
|
245
|
-
function
|
|
244
|
+
const Ge = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
245
|
+
function et(e) {
|
|
246
246
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
247
247
|
return {
|
|
248
248
|
token: e.token || "testKey",
|
|
@@ -253,7 +253,7 @@ function Ge(e) {
|
|
|
253
253
|
...e.mixpanelAdditionalProperties || {}
|
|
254
254
|
},
|
|
255
255
|
isEnabled: e.isEnabled ?? !0,
|
|
256
|
-
getRandom:
|
|
256
|
+
getRandom: Q,
|
|
257
257
|
enrich(n) {
|
|
258
258
|
this.additionalProperties = { ...this.additionalProperties, ...n };
|
|
259
259
|
},
|
|
@@ -286,7 +286,7 @@ function Ge(e) {
|
|
|
286
286
|
])
|
|
287
287
|
})
|
|
288
288
|
};
|
|
289
|
-
return fetch(
|
|
289
|
+
return fetch(Ge, {
|
|
290
290
|
...i,
|
|
291
291
|
keepalive: !0
|
|
292
292
|
}).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
|
|
@@ -307,7 +307,7 @@ function Ge(e) {
|
|
|
307
307
|
}
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
function
|
|
310
|
+
function ue() {
|
|
311
311
|
let e = 0;
|
|
312
312
|
return {
|
|
313
313
|
reset: () => e = 0,
|
|
@@ -315,22 +315,22 @@ function De() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const
|
|
318
|
+
const W = ue(), se = ue(), ge = ue();
|
|
319
319
|
function Re(e) {
|
|
320
|
-
return e === E.Playground ? { headers: { [
|
|
320
|
+
return e === E.Playground ? { headers: { [Je]: "true" } } : {};
|
|
321
321
|
}
|
|
322
|
-
async function
|
|
322
|
+
async function Ie(e, t, n, r, c = !1, s) {
|
|
323
323
|
try {
|
|
324
|
-
return !s && !
|
|
324
|
+
return !s && !Se(r) && (s = await t.newChat(e.id, { persist: c }, Re(r)), n.track("agent-chat", {
|
|
325
325
|
event: "created",
|
|
326
326
|
chatId: s.id,
|
|
327
327
|
mode: r
|
|
328
328
|
})), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? r };
|
|
329
329
|
} catch (o) {
|
|
330
|
-
throw
|
|
330
|
+
throw tt(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
const
|
|
333
|
+
const tt = (e) => {
|
|
334
334
|
try {
|
|
335
335
|
const t = JSON.parse(e.message);
|
|
336
336
|
return t == null ? void 0 : t.kind;
|
|
@@ -338,30 +338,30 @@ const et = (e) => {
|
|
|
338
338
|
return "UnknownError";
|
|
339
339
|
}
|
|
340
340
|
};
|
|
341
|
-
function
|
|
341
|
+
function rt(e) {
|
|
342
342
|
return e && e.length > 0 ? e : [];
|
|
343
343
|
}
|
|
344
|
-
function
|
|
344
|
+
function nt(e, t, n) {
|
|
345
345
|
if (!e)
|
|
346
346
|
throw new Error("Please connect to the agent first");
|
|
347
347
|
if (!e.interruptAvailable)
|
|
348
348
|
throw new Error("Interrupt is not enabled for this stream");
|
|
349
|
-
if (t !==
|
|
349
|
+
if (t !== H.Fluent)
|
|
350
350
|
throw new Error("Interrupt only available for Fluent streams");
|
|
351
351
|
if (!n)
|
|
352
352
|
throw new Error("No active video to interrupt");
|
|
353
353
|
}
|
|
354
|
-
async function
|
|
354
|
+
async function at(e, t) {
|
|
355
355
|
const n = {
|
|
356
|
-
type:
|
|
356
|
+
type: P.StreamInterrupt,
|
|
357
357
|
videoId: t,
|
|
358
358
|
timestamp: Date.now()
|
|
359
359
|
};
|
|
360
360
|
e.sendDataChannelMessage(JSON.stringify(n));
|
|
361
361
|
}
|
|
362
|
-
function
|
|
362
|
+
function it(e) {
|
|
363
363
|
return new Promise((t, n) => {
|
|
364
|
-
const { callbacks: r, host: c, auth: s, externalId: o } = e, { onMessage: a = null, onOpen: i = null, onClose: d = null, onError: l = null } = r || {}, u = new WebSocket(`${c}?authorization=${encodeURIComponent(
|
|
364
|
+
const { callbacks: r, host: c, auth: s, externalId: o } = e, { onMessage: a = null, onOpen: i = null, onClose: d = null, onError: l = null } = r || {}, u = new WebSocket(`${c}?authorization=${encodeURIComponent(Ce(s, o))}`);
|
|
365
365
|
u.onmessage = a, u.onclose = d, u.onerror = (y) => {
|
|
366
366
|
console.error(y), l == null || l("Websocket failed to connect", y), n(y);
|
|
367
367
|
}, u.onopen = (y) => {
|
|
@@ -369,28 +369,28 @@ function at(e) {
|
|
|
369
369
|
};
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
|
-
async function
|
|
372
|
+
async function st(e) {
|
|
373
373
|
const { retries: t = 1 } = e;
|
|
374
374
|
let n = null;
|
|
375
375
|
for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
|
|
376
376
|
try {
|
|
377
|
-
n = await
|
|
377
|
+
n = await it(e);
|
|
378
378
|
} catch (c) {
|
|
379
379
|
if (r === t)
|
|
380
380
|
throw c;
|
|
381
|
-
await
|
|
381
|
+
await ve(r * 500);
|
|
382
382
|
}
|
|
383
383
|
return n;
|
|
384
384
|
}
|
|
385
|
-
async function
|
|
386
|
-
const c = n != null && n.onMessage ? [n.onMessage] : [], s = await
|
|
385
|
+
async function ot(e, t, n, r) {
|
|
386
|
+
const c = n != null && n.onMessage ? [n.onMessage] : [], s = await st({
|
|
387
387
|
auth: e,
|
|
388
388
|
host: t,
|
|
389
389
|
externalId: r,
|
|
390
390
|
callbacks: {
|
|
391
391
|
onError: (o) => {
|
|
392
392
|
var a;
|
|
393
|
-
return (a = n.onError) == null ? void 0 : a.call(n, new
|
|
393
|
+
return (a = n.onError) == null ? void 0 : a.call(n, new be(o));
|
|
394
394
|
},
|
|
395
395
|
onMessage(o) {
|
|
396
396
|
const a = JSON.parse(o.data);
|
|
@@ -404,7 +404,7 @@ async function st(e, t, n, r) {
|
|
|
404
404
|
subscribeToEvents: (o) => c.push(o)
|
|
405
405
|
};
|
|
406
406
|
}
|
|
407
|
-
function
|
|
407
|
+
function ct(e) {
|
|
408
408
|
if (e.answer !== void 0)
|
|
409
409
|
return e.answer;
|
|
410
410
|
let t = 0, n = "";
|
|
@@ -412,41 +412,70 @@ function ot(e) {
|
|
|
412
412
|
n += e[t++];
|
|
413
413
|
return n;
|
|
414
414
|
}
|
|
415
|
-
function
|
|
415
|
+
function dt(e, t, n) {
|
|
416
|
+
if (!e.content)
|
|
417
|
+
return;
|
|
418
|
+
const r = {
|
|
419
|
+
id: e.id || `user-${Date.now()}`,
|
|
420
|
+
role: e.role,
|
|
421
|
+
content: e.content,
|
|
422
|
+
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
423
|
+
transcribed: !0
|
|
424
|
+
};
|
|
425
|
+
t.messages.push(r), n == null || n([...t.messages], "user");
|
|
426
|
+
}
|
|
427
|
+
function lt(e, t, n, r, c) {
|
|
428
|
+
if (e === J.Transcribe && t.content) {
|
|
429
|
+
dt(t, r, c);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (!(e === J.Partial || e === J.Answer))
|
|
433
|
+
return;
|
|
416
434
|
const s = r.messages[r.messages.length - 1];
|
|
417
|
-
|
|
435
|
+
let o;
|
|
436
|
+
if (s != null && s.transcribed && s.role === "user")
|
|
437
|
+
e === J.Answer && t.content, o = {
|
|
438
|
+
id: t.id || `assistant-${Date.now()}`,
|
|
439
|
+
role: t.role || "assistant",
|
|
440
|
+
content: t.content || "",
|
|
441
|
+
created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
442
|
+
}, r.messages.push(o);
|
|
443
|
+
else if ((s == null ? void 0 : s.role) === "assistant")
|
|
444
|
+
o = s;
|
|
445
|
+
else
|
|
418
446
|
return;
|
|
419
|
-
const { content:
|
|
420
|
-
e ===
|
|
421
|
-
const
|
|
422
|
-
(
|
|
447
|
+
const { content: a, sequence: i } = t;
|
|
448
|
+
e === J.Partial ? n[i] = a : n.answer = a;
|
|
449
|
+
const d = ct(n);
|
|
450
|
+
(o.content !== d || e === J.Answer) && (o.content = d, c == null || c([...r.messages], e));
|
|
423
451
|
}
|
|
424
|
-
function
|
|
452
|
+
function ut(e, t, n, r, c) {
|
|
425
453
|
let s = {};
|
|
426
454
|
return {
|
|
427
455
|
clearQueue: () => s = {},
|
|
428
456
|
onMessage: (o, a) => {
|
|
429
457
|
var i, d;
|
|
430
|
-
if ("content" in a)
|
|
431
|
-
|
|
458
|
+
if ("content" in a) {
|
|
459
|
+
const l = o === P.ChatAnswer ? J.Answer : o === P.ChatAudioTranscribed ? J.Transcribe : o;
|
|
460
|
+
lt(l, a, s, t, n.callbacks.onNewMessage), l === J.Answer && e.track("agent-message-received", {
|
|
432
461
|
messages: t.messages.length,
|
|
433
462
|
mode: t.chatMode
|
|
434
463
|
});
|
|
435
|
-
else {
|
|
436
|
-
const l =
|
|
464
|
+
} else {
|
|
465
|
+
const l = P, u = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], y = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], j = Ze(a, r, { mode: t.chatMode });
|
|
437
466
|
if (o = o, o === l.StreamVideoCreated)
|
|
438
|
-
e.linkTrack("agent-video",
|
|
467
|
+
e.linkTrack("agent-video", j, l.StreamVideoCreated, ["start"]);
|
|
439
468
|
else if (u.includes(o)) {
|
|
440
|
-
const
|
|
441
|
-
y.includes(o) ? e.track("agent-video", { ...
|
|
469
|
+
const b = o.split("/")[1];
|
|
470
|
+
y.includes(o) ? e.track("agent-video", { ...j, event: b }) : e.linkTrack("agent-video", { ...j, event: b }, o, ["done"]);
|
|
442
471
|
}
|
|
443
472
|
y.includes(o) && ((d = (i = n.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${o}`), { data: a })), a.event === l.StreamDone && c();
|
|
444
473
|
}
|
|
445
474
|
}
|
|
446
475
|
};
|
|
447
476
|
}
|
|
448
|
-
function
|
|
449
|
-
const c =
|
|
477
|
+
function mt(e, t, n, r) {
|
|
478
|
+
const c = De(e, `${t}/agents/${n}`, r);
|
|
450
479
|
return {
|
|
451
480
|
createStream(s, o) {
|
|
452
481
|
return c.post("/streams", s, { signal: o });
|
|
@@ -482,8 +511,8 @@ function lt(e, t, n, r) {
|
|
|
482
511
|
}
|
|
483
512
|
};
|
|
484
513
|
}
|
|
485
|
-
const
|
|
486
|
-
function
|
|
514
|
+
const ft = (e, t) => (n, r) => e && console.log(`[${t}] ${n}`, r ?? "");
|
|
515
|
+
function gt(e, t, n) {
|
|
487
516
|
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
488
517
|
return {
|
|
489
518
|
duration: r,
|
|
@@ -503,7 +532,7 @@ function ft(e, t, n) {
|
|
|
503
532
|
lowFpsCount: n
|
|
504
533
|
};
|
|
505
534
|
}
|
|
506
|
-
function
|
|
535
|
+
function ht(e) {
|
|
507
536
|
return e.filter(
|
|
508
537
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
509
538
|
).map((t) => {
|
|
@@ -514,7 +543,7 @@ function mt(e) {
|
|
|
514
543
|
};
|
|
515
544
|
});
|
|
516
545
|
}
|
|
517
|
-
function
|
|
546
|
+
function pt(e) {
|
|
518
547
|
let t = "", n = 0;
|
|
519
548
|
for (const r of e.values()) {
|
|
520
549
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -544,7 +573,7 @@ function gt(e) {
|
|
|
544
573
|
}
|
|
545
574
|
return {};
|
|
546
575
|
}
|
|
547
|
-
function
|
|
576
|
+
function wt(e, t, n) {
|
|
548
577
|
const r = e.map((i, d) => d === 0 ? n ? {
|
|
549
578
|
timestamp: i.timestamp,
|
|
550
579
|
duration: 0,
|
|
@@ -596,24 +625,24 @@ function ht(e, t, n) {
|
|
|
596
625
|
framesPerSecond: i.framesPerSecond,
|
|
597
626
|
freezeCount: i.freezeCount - e[d - 1].freezeCount,
|
|
598
627
|
freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
|
|
599
|
-
}), c =
|
|
628
|
+
}), c = ht(r), s = c.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), a = r.filter((i) => !!i.rtt).map((i) => i.rtt);
|
|
600
629
|
return {
|
|
601
630
|
webRTCStats: {
|
|
602
631
|
anomalies: c,
|
|
603
632
|
minRtt: Math.min(...a),
|
|
604
|
-
avgRtt:
|
|
633
|
+
avgRtt: me(a),
|
|
605
634
|
maxRtt: Math.max(...a),
|
|
606
|
-
aggregateReport:
|
|
635
|
+
aggregateReport: gt(e[0], e[e.length - 1], s),
|
|
607
636
|
minJitterDelayInInterval: Math.min(...o),
|
|
608
637
|
maxJitterDelayInInterval: Math.max(...o),
|
|
609
|
-
avgJitterDelayInInterval:
|
|
638
|
+
avgJitterDelayInInterval: me(o)
|
|
610
639
|
},
|
|
611
640
|
codec: e[0].codec,
|
|
612
641
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
613
642
|
};
|
|
614
643
|
}
|
|
615
|
-
const oe = 100,
|
|
616
|
-
function
|
|
644
|
+
const oe = 100, yt = Math.max(Math.ceil(400 / oe), 1), vt = 0.25, kt = 0.28;
|
|
645
|
+
function St() {
|
|
617
646
|
let e = 0, t, n, r = 0;
|
|
618
647
|
return (c) => {
|
|
619
648
|
for (const s of c.values())
|
|
@@ -630,21 +659,21 @@ function yt() {
|
|
|
630
659
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
631
660
|
};
|
|
632
661
|
}
|
|
633
|
-
function
|
|
662
|
+
function Ct(e, t, n, r, c) {
|
|
634
663
|
let s = [], o, a = 0, i = !1, d = ee.Unknown, l = ee.Unknown, u = 0, y = 0;
|
|
635
|
-
const
|
|
664
|
+
const j = St();
|
|
636
665
|
return setInterval(async () => {
|
|
637
|
-
const
|
|
638
|
-
if (
|
|
639
|
-
a = 0, u =
|
|
640
|
-
else if (i && (a++, a >=
|
|
641
|
-
const
|
|
642
|
-
r == null || r(
|
|
666
|
+
const b = await e.getStats(), { isReceiving: U, avgJitterDelayInInterval: A, freezeCount: L } = j(b), x = pt(b);
|
|
667
|
+
if (U)
|
|
668
|
+
a = 0, u = L - y, l = A < vt ? ee.Strong : A > kt && u > 1 ? ee.Weak : d, l !== d && (c == null || c(l), d = l, y += u, u = 0), i || (r == null || r(p.Start), o = s[s.length - 1], s = [], i = !0), s.push(x);
|
|
669
|
+
else if (i && (a++, a >= yt)) {
|
|
670
|
+
const R = wt(s, oe, o);
|
|
671
|
+
r == null || r(p.Stop, R), t() || n(), y = L, i = !1;
|
|
643
672
|
}
|
|
644
673
|
}, oe);
|
|
645
674
|
}
|
|
646
|
-
const
|
|
647
|
-
function
|
|
675
|
+
const Dt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
676
|
+
function he(e) {
|
|
648
677
|
switch (e) {
|
|
649
678
|
case "connected":
|
|
650
679
|
return _.Connected;
|
|
@@ -664,7 +693,7 @@ function me(e) {
|
|
|
664
693
|
return _.New;
|
|
665
694
|
}
|
|
666
695
|
}
|
|
667
|
-
const
|
|
696
|
+
const Rt = (e) => (t) => {
|
|
668
697
|
const [n, r = ""] = t.split(/:(.+)/);
|
|
669
698
|
try {
|
|
670
699
|
const c = JSON.parse(r);
|
|
@@ -673,24 +702,24 @@ const Dt = (e) => (t) => {
|
|
|
673
702
|
return e("Failed to parse data channel message, returning data as string", { subject: n, rawData: r, error: c }), { subject: n, data: r };
|
|
674
703
|
}
|
|
675
704
|
};
|
|
676
|
-
function
|
|
705
|
+
function It({
|
|
677
706
|
statsSignal: e,
|
|
678
707
|
dataChannelSignal: t,
|
|
679
708
|
onVideoStateChange: n,
|
|
680
709
|
report: r
|
|
681
710
|
}) {
|
|
682
|
-
e ===
|
|
711
|
+
e === p.Start && t === p.Start ? n == null || n(p.Start) : e === p.Stop && t === p.Stop && (n == null || n(p.Stop, r));
|
|
683
712
|
}
|
|
684
|
-
function
|
|
713
|
+
function Et({
|
|
685
714
|
statsSignal: e,
|
|
686
715
|
dataChannelSignal: t,
|
|
687
716
|
onVideoStateChange: n,
|
|
688
717
|
onAgentActivityStateChange: r,
|
|
689
718
|
report: c
|
|
690
719
|
}) {
|
|
691
|
-
e ===
|
|
720
|
+
e === p.Start ? n == null || n(p.Start) : e === p.Stop && (n == null || n(p.Stop, c)), t === p.Start ? r == null || r(Z.Talking) : t === p.Stop && (r == null || r(Z.Idle));
|
|
692
721
|
}
|
|
693
|
-
function
|
|
722
|
+
function pe({
|
|
694
723
|
statsSignal: e,
|
|
695
724
|
dataChannelSignal: t,
|
|
696
725
|
onVideoStateChange: n,
|
|
@@ -698,7 +727,7 @@ function ge({
|
|
|
698
727
|
streamType: c,
|
|
699
728
|
report: s
|
|
700
729
|
}) {
|
|
701
|
-
c ===
|
|
730
|
+
c === H.Legacy ? It({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: s }) : c === H.Fluent && Et({
|
|
702
731
|
statsSignal: e,
|
|
703
732
|
dataChannelSignal: t,
|
|
704
733
|
onVideoStateChange: n,
|
|
@@ -706,127 +735,128 @@ function ge({
|
|
|
706
735
|
report: s
|
|
707
736
|
});
|
|
708
737
|
}
|
|
709
|
-
async function
|
|
738
|
+
async function Mt(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re, analytics: o }, a) {
|
|
710
739
|
var N;
|
|
711
|
-
const i =
|
|
712
|
-
let l = !1, u = !1, y =
|
|
713
|
-
const { startConnection:
|
|
740
|
+
const i = ft(n, "WebRTCStreamingManager"), d = Rt(i);
|
|
741
|
+
let l = !1, u = !1, y = p.Stop, j = p.Stop;
|
|
742
|
+
const { startConnection: b, sendStreamRequest: U, close: A, createStream: L, addIceCandidate: x } = mt(
|
|
714
743
|
c,
|
|
715
744
|
s,
|
|
716
745
|
e,
|
|
717
746
|
r.onError
|
|
718
747
|
), {
|
|
719
|
-
id:
|
|
720
|
-
offer:
|
|
721
|
-
ice_servers:
|
|
748
|
+
id: R,
|
|
749
|
+
offer: X,
|
|
750
|
+
ice_servers: q,
|
|
722
751
|
session_id: B,
|
|
723
|
-
fluent:
|
|
724
|
-
interrupt_enabled:
|
|
725
|
-
triggers_enabled:
|
|
726
|
-
} = await
|
|
727
|
-
(N = r.onStreamCreated) == null || N.call(r, { stream_id:
|
|
728
|
-
const h = new
|
|
752
|
+
fluent: m,
|
|
753
|
+
interrupt_enabled: v,
|
|
754
|
+
triggers_enabled: k
|
|
755
|
+
} = await L(t, a);
|
|
756
|
+
(N = r.onStreamCreated) == null || N.call(r, { stream_id: R, session_id: B, agent_id: e });
|
|
757
|
+
const h = new Dt({ iceServers: q }), S = h.createDataChannel("JanusDataChannel");
|
|
729
758
|
if (!B)
|
|
730
759
|
throw new Error("Could not create session_id");
|
|
731
|
-
const
|
|
760
|
+
const w = m ? H.Fluent : H.Legacy;
|
|
732
761
|
o.enrich({
|
|
733
|
-
"stream-type":
|
|
762
|
+
"stream-type": w
|
|
734
763
|
});
|
|
735
|
-
const
|
|
736
|
-
var
|
|
737
|
-
l = !0, u && ((
|
|
738
|
-
}, I =
|
|
764
|
+
const $ = t.stream_warmup && !m, F = () => l, z = () => {
|
|
765
|
+
var f;
|
|
766
|
+
l = !0, u && ((f = r.onConnectionStateChange) == null || f.call(r, _.Connected));
|
|
767
|
+
}, I = Ct(
|
|
739
768
|
h,
|
|
740
769
|
F,
|
|
741
770
|
z,
|
|
742
|
-
(
|
|
743
|
-
statsSignal:
|
|
744
|
-
dataChannelSignal:
|
|
771
|
+
(f, g) => pe({
|
|
772
|
+
statsSignal: j = f,
|
|
773
|
+
dataChannelSignal: w === H.Legacy ? y : void 0,
|
|
745
774
|
onVideoStateChange: r.onVideoStateChange,
|
|
746
775
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
747
776
|
report: g,
|
|
748
|
-
streamType:
|
|
777
|
+
streamType: w
|
|
749
778
|
}),
|
|
750
|
-
(
|
|
779
|
+
(f) => {
|
|
751
780
|
var g;
|
|
752
|
-
return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r,
|
|
781
|
+
return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
|
|
753
782
|
}
|
|
754
783
|
);
|
|
755
|
-
h.onicecandidate = (
|
|
784
|
+
h.onicecandidate = (f) => {
|
|
756
785
|
var g;
|
|
757
|
-
i("peerConnection.onicecandidate",
|
|
786
|
+
i("peerConnection.onicecandidate", f);
|
|
758
787
|
try {
|
|
759
|
-
|
|
760
|
-
|
|
788
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? x(
|
|
789
|
+
R,
|
|
761
790
|
{
|
|
762
|
-
candidate:
|
|
763
|
-
sdpMid:
|
|
764
|
-
sdpMLineIndex:
|
|
791
|
+
candidate: f.candidate.candidate,
|
|
792
|
+
sdpMid: f.candidate.sdpMid,
|
|
793
|
+
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
765
794
|
},
|
|
766
795
|
B,
|
|
767
796
|
a
|
|
768
|
-
) :
|
|
797
|
+
) : x(R, { candidate: null }, B, a);
|
|
769
798
|
} catch (M) {
|
|
770
|
-
(g = r.onError) == null || g.call(r, M, { streamId:
|
|
799
|
+
(g = r.onError) == null || g.call(r, M, { streamId: R });
|
|
771
800
|
}
|
|
772
|
-
},
|
|
773
|
-
u = !0, (
|
|
801
|
+
}, S.onopen = () => {
|
|
802
|
+
u = !0, (!$ || l) && z();
|
|
774
803
|
};
|
|
775
|
-
const T = (
|
|
804
|
+
const T = (f) => {
|
|
776
805
|
var g;
|
|
777
|
-
(g = r.onVideoIdChange) == null || g.call(r,
|
|
806
|
+
(g = r.onVideoIdChange) == null || g.call(r, f);
|
|
778
807
|
};
|
|
779
|
-
function
|
|
780
|
-
if (
|
|
808
|
+
function K(f, g) {
|
|
809
|
+
if (f === P.StreamStarted && typeof g == "object" && "metadata" in g) {
|
|
781
810
|
const M = g.metadata;
|
|
782
811
|
T(M.videoId);
|
|
783
812
|
}
|
|
784
|
-
|
|
785
|
-
statsSignal:
|
|
813
|
+
f === P.StreamDone && T(null), y = f === P.StreamStarted ? p.Start : p.Stop, pe({
|
|
814
|
+
statsSignal: w === H.Legacy ? j : void 0,
|
|
786
815
|
dataChannelSignal: y,
|
|
787
816
|
onVideoStateChange: r.onVideoStateChange,
|
|
788
817
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
789
|
-
streamType:
|
|
818
|
+
streamType: w
|
|
790
819
|
});
|
|
791
820
|
}
|
|
792
|
-
function
|
|
821
|
+
function D(f, g) {
|
|
822
|
+
var V;
|
|
793
823
|
const M = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
|
|
794
|
-
M && o.enrich({ streamMetadata: M }),
|
|
824
|
+
M && o.enrich({ streamMetadata: M }), (V = r.onStreamReady) == null || V.call(r);
|
|
795
825
|
}
|
|
796
826
|
const C = {
|
|
797
|
-
[
|
|
798
|
-
[
|
|
799
|
-
[
|
|
827
|
+
[P.StreamStarted]: K,
|
|
828
|
+
[P.StreamDone]: K,
|
|
829
|
+
[P.StreamReady]: D
|
|
800
830
|
};
|
|
801
|
-
|
|
802
|
-
var
|
|
803
|
-
const { subject: g, data: M } = d(
|
|
804
|
-
(
|
|
831
|
+
S.onmessage = (f) => {
|
|
832
|
+
var V;
|
|
833
|
+
const { subject: g, data: M } = d(f.data);
|
|
834
|
+
(V = C[g]) == null || V.call(C, g, M);
|
|
805
835
|
}, h.oniceconnectionstatechange = () => {
|
|
806
836
|
var g;
|
|
807
837
|
i("peerConnection.oniceconnectionstatechange => " + h.iceConnectionState);
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
}, h.ontrack = (
|
|
838
|
+
const f = he(h.iceConnectionState);
|
|
839
|
+
f !== _.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
|
|
840
|
+
}, h.ontrack = (f) => {
|
|
811
841
|
var g;
|
|
812
|
-
i("peerConnection.ontrack",
|
|
813
|
-
}, await h.setRemoteDescription(
|
|
814
|
-
const
|
|
815
|
-
return i("create answer OK"), await h.setLocalDescription(
|
|
842
|
+
i("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
|
|
843
|
+
}, await h.setRemoteDescription(X), i("set remote description OK");
|
|
844
|
+
const O = await h.createAnswer();
|
|
845
|
+
return i("create answer OK"), await h.setLocalDescription(O), i("set local description OK"), await b(R, O, B, a), i("start connection OK"), {
|
|
816
846
|
/**
|
|
817
847
|
* Method to send request to server to get clip or talk depend on you payload
|
|
818
848
|
* @param payload
|
|
819
849
|
*/
|
|
820
|
-
speak(
|
|
821
|
-
return
|
|
850
|
+
speak(f) {
|
|
851
|
+
return U(R, B, f);
|
|
822
852
|
},
|
|
823
853
|
/**
|
|
824
854
|
* Method to close RTC connection
|
|
825
855
|
*/
|
|
826
856
|
async disconnect() {
|
|
827
|
-
var
|
|
828
|
-
if (
|
|
829
|
-
const g =
|
|
857
|
+
var f;
|
|
858
|
+
if (R) {
|
|
859
|
+
const g = he(h.iceConnectionState);
|
|
830
860
|
if (h) {
|
|
831
861
|
if (g === _.New) {
|
|
832
862
|
clearInterval(I);
|
|
@@ -835,29 +865,29 @@ async function It(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
|
|
|
835
865
|
h.close(), h.oniceconnectionstatechange = null, h.onnegotiationneeded = null, h.onicecandidate = null, h.ontrack = null;
|
|
836
866
|
}
|
|
837
867
|
try {
|
|
838
|
-
g === _.Connected && await
|
|
868
|
+
g === _.Connected && await A(R, B).catch((M) => {
|
|
839
869
|
});
|
|
840
870
|
} catch (M) {
|
|
841
871
|
i("Error on close stream connection", M);
|
|
842
872
|
}
|
|
843
|
-
(
|
|
873
|
+
(f = r.onAgentActivityStateChange) == null || f.call(r, Z.Idle), clearInterval(I);
|
|
844
874
|
}
|
|
845
875
|
},
|
|
846
876
|
/**
|
|
847
877
|
* Method to send data channel messages to the server
|
|
848
878
|
*/
|
|
849
|
-
sendDataChannelMessage(
|
|
879
|
+
sendDataChannelMessage(f) {
|
|
850
880
|
var g, M;
|
|
851
|
-
if (!l ||
|
|
881
|
+
if (!l || S.readyState !== "open") {
|
|
852
882
|
i("Data channel is not ready for sending messages"), (g = r.onError) == null || g.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
853
|
-
streamId:
|
|
883
|
+
streamId: R
|
|
854
884
|
});
|
|
855
885
|
return;
|
|
856
886
|
}
|
|
857
887
|
try {
|
|
858
|
-
|
|
859
|
-
} catch (
|
|
860
|
-
i("Error sending data channel message",
|
|
888
|
+
S.send(f);
|
|
889
|
+
} catch (V) {
|
|
890
|
+
i("Error sending data channel message", V), (M = r.onError) == null || M.call(r, V, { streamId: R });
|
|
861
891
|
}
|
|
862
892
|
},
|
|
863
893
|
/**
|
|
@@ -867,25 +897,25 @@ async function It(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
|
|
|
867
897
|
/**
|
|
868
898
|
* Id of current RTC stream
|
|
869
899
|
*/
|
|
870
|
-
streamId:
|
|
871
|
-
streamType:
|
|
872
|
-
interruptAvailable:
|
|
873
|
-
triggersAvailable:
|
|
900
|
+
streamId: R,
|
|
901
|
+
streamType: w,
|
|
902
|
+
interruptAvailable: v ?? !1,
|
|
903
|
+
triggersAvailable: k ?? !1
|
|
874
904
|
};
|
|
875
905
|
}
|
|
876
906
|
var ce = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ce || {});
|
|
877
|
-
async function
|
|
907
|
+
async function _t(e, t, n, r) {
|
|
878
908
|
const c = e.id;
|
|
879
909
|
switch (t.version) {
|
|
880
910
|
case "v1": {
|
|
881
911
|
const { version: s, ...o } = t;
|
|
882
|
-
return
|
|
912
|
+
return Mt(c, o, n, r);
|
|
883
913
|
}
|
|
884
914
|
case "v2": {
|
|
885
915
|
const { version: s, ...o } = t;
|
|
886
916
|
switch (o.transport_provider) {
|
|
887
917
|
case de.Livekit:
|
|
888
|
-
const { createLiveKitStreamingManager: a } = await import("./livekit-manager-
|
|
918
|
+
const { createLiveKitStreamingManager: a } = await import("./livekit-manager-Cv9nty3S.js");
|
|
889
919
|
return a(c, o, n);
|
|
890
920
|
default:
|
|
891
921
|
throw new Error(`Unsupported transport provider: ${o.transport_provider}`);
|
|
@@ -895,13 +925,13 @@ async function Et(e, t, n, r) {
|
|
|
895
925
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
896
926
|
}
|
|
897
927
|
}
|
|
898
|
-
const
|
|
899
|
-
function
|
|
928
|
+
const Tt = "cht";
|
|
929
|
+
function bt() {
|
|
900
930
|
return {
|
|
901
931
|
transport_provider: de.Livekit
|
|
902
932
|
};
|
|
903
933
|
}
|
|
904
|
-
function
|
|
934
|
+
function At(e) {
|
|
905
935
|
var c, s;
|
|
906
936
|
const { streamOptions: t } = e ?? {}, n = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
907
937
|
plan: (s = e.mixpanelAdditionalProperties) == null ? void 0 : s.plan
|
|
@@ -914,14 +944,14 @@ function Tt(e) {
|
|
|
914
944
|
fluent: t == null ? void 0 : t.fluent
|
|
915
945
|
}, ...n && { end_user_data: n } };
|
|
916
946
|
}
|
|
917
|
-
function
|
|
918
|
-
return le(e.presenter.type) ? { version: ce.V2, ...
|
|
947
|
+
function Pt(e, t) {
|
|
948
|
+
return le(e.presenter.type) ? { version: ce.V2, ...bt() } : { version: ce.V1, ...At(t) };
|
|
919
949
|
}
|
|
920
|
-
function
|
|
921
|
-
c ===
|
|
950
|
+
function jt(e, t, n, r, c) {
|
|
951
|
+
c === H.Fluent ? Lt(e, t, n, r, c) : xt(e, t, n, r, c);
|
|
922
952
|
}
|
|
923
|
-
function
|
|
924
|
-
e ===
|
|
953
|
+
function Lt(e, t, n, r, c) {
|
|
954
|
+
e === p.Start ? r.track("stream-session", { event: "start", "stream-type": c }) : e === p.Stop && r.track("stream-session", {
|
|
925
955
|
event: "stop",
|
|
926
956
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
927
957
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
@@ -929,13 +959,13 @@ function Pt(e, t, n, r, c) {
|
|
|
929
959
|
...n
|
|
930
960
|
});
|
|
931
961
|
}
|
|
932
|
-
function
|
|
933
|
-
|
|
962
|
+
function $t(e, t, n, r) {
|
|
963
|
+
W.get() <= 0 || (e === p.Start ? n.linkTrack(
|
|
934
964
|
"agent-video",
|
|
935
|
-
{ event: "start", latency:
|
|
965
|
+
{ event: "start", latency: W.get(!0), "stream-type": r },
|
|
936
966
|
"start",
|
|
937
|
-
[
|
|
938
|
-
) : e ===
|
|
967
|
+
[P.StreamVideoCreated]
|
|
968
|
+
) : e === p.Stop && n.linkTrack(
|
|
939
969
|
"agent-video",
|
|
940
970
|
{
|
|
941
971
|
event: "stop",
|
|
@@ -944,16 +974,16 @@ function jt(e, t, n, r) {
|
|
|
944
974
|
"stream-type": r
|
|
945
975
|
},
|
|
946
976
|
"done",
|
|
947
|
-
[
|
|
977
|
+
[P.StreamVideoDone]
|
|
948
978
|
));
|
|
949
979
|
}
|
|
950
|
-
function
|
|
951
|
-
|
|
980
|
+
function xt(e, t, n, r, c) {
|
|
981
|
+
W.get() <= 0 || (e === p.Start ? r.linkTrack(
|
|
952
982
|
"agent-video",
|
|
953
|
-
{ event: "start", latency:
|
|
983
|
+
{ event: "start", latency: W.get(!0), "stream-type": c },
|
|
954
984
|
"start",
|
|
955
|
-
[
|
|
956
|
-
) : e ===
|
|
985
|
+
[P.StreamVideoCreated]
|
|
986
|
+
) : e === p.Stop && r.linkTrack(
|
|
957
987
|
"agent-video",
|
|
958
988
|
{
|
|
959
989
|
event: "stop",
|
|
@@ -963,43 +993,50 @@ function Lt(e, t, n, r, c) {
|
|
|
963
993
|
...n
|
|
964
994
|
},
|
|
965
995
|
"done",
|
|
966
|
-
[
|
|
996
|
+
[P.StreamVideoDone]
|
|
967
997
|
));
|
|
968
998
|
}
|
|
969
|
-
function
|
|
970
|
-
return
|
|
999
|
+
function we(e, t, n, r) {
|
|
1000
|
+
return W.reset(), ge.update(), new Promise(async (c, s) => {
|
|
971
1001
|
try {
|
|
972
1002
|
let o, a = !1;
|
|
973
|
-
|
|
1003
|
+
const i = Pt(e, t);
|
|
1004
|
+
n.enrich({
|
|
1005
|
+
"stream-version": i.version.toString()
|
|
1006
|
+
}), o = await _t(
|
|
974
1007
|
e,
|
|
975
|
-
|
|
1008
|
+
i,
|
|
976
1009
|
{
|
|
977
1010
|
...t,
|
|
978
1011
|
analytics: n,
|
|
979
1012
|
callbacks: {
|
|
980
1013
|
...t.callbacks,
|
|
981
|
-
onConnectionStateChange: (
|
|
982
|
-
var d, l;
|
|
983
|
-
(l = (d = t.callbacks).onConnectionStateChange) == null || l.call(d, i), i === _.Connected && (o ? c(o) : a = !0);
|
|
984
|
-
},
|
|
985
|
-
onVideoStateChange: (i, d) => {
|
|
1014
|
+
onConnectionStateChange: (d) => {
|
|
986
1015
|
var l, u;
|
|
987
|
-
(u = (l = t.callbacks).
|
|
988
|
-
|
|
989
|
-
|
|
1016
|
+
(u = (l = t.callbacks).onConnectionStateChange) == null || u.call(l, d), d === _.Connected && (o ? c(o) : a = !0);
|
|
1017
|
+
},
|
|
1018
|
+
onVideoStateChange: (d, l) => {
|
|
1019
|
+
var u, y;
|
|
1020
|
+
(y = (u = t.callbacks).onVideoStateChange) == null || y.call(u, d), jt(
|
|
990
1021
|
d,
|
|
1022
|
+
e,
|
|
1023
|
+
l,
|
|
991
1024
|
n,
|
|
992
1025
|
o.streamType
|
|
993
1026
|
);
|
|
994
1027
|
},
|
|
995
|
-
onAgentActivityStateChange: (
|
|
996
|
-
var
|
|
997
|
-
(
|
|
998
|
-
|
|
1028
|
+
onAgentActivityStateChange: (d) => {
|
|
1029
|
+
var l, u;
|
|
1030
|
+
(u = (l = t.callbacks).onAgentActivityStateChange) == null || u.call(l, d), d === Z.Talking ? se.update() : se.reset(), $t(
|
|
1031
|
+
d === Z.Talking ? p.Start : p.Stop,
|
|
999
1032
|
e,
|
|
1000
1033
|
n,
|
|
1001
1034
|
o.streamType
|
|
1002
1035
|
);
|
|
1036
|
+
},
|
|
1037
|
+
onStreamReady: () => {
|
|
1038
|
+
const d = ge.get(!0);
|
|
1039
|
+
n.track("agent-chat", { event: "ready", latency: d });
|
|
1003
1040
|
}
|
|
1004
1041
|
}
|
|
1005
1042
|
},
|
|
@@ -1010,53 +1047,53 @@ function he(e, t, n, r) {
|
|
|
1010
1047
|
}
|
|
1011
1048
|
});
|
|
1012
1049
|
}
|
|
1013
|
-
async function
|
|
1014
|
-
var l, u, y,
|
|
1050
|
+
async function Bt(e, t, n, r, c) {
|
|
1051
|
+
var l, u, y, j;
|
|
1015
1052
|
const s = async () => {
|
|
1016
1053
|
if (le(e.presenter.type)) {
|
|
1017
|
-
const
|
|
1054
|
+
const b = await we(e, t, r), U = `${Tt}_${b.sessionId}`, A = (/* @__PURE__ */ new Date()).toISOString();
|
|
1018
1055
|
return { chatResult: {
|
|
1019
1056
|
chatMode: E.Functional,
|
|
1020
1057
|
chat: {
|
|
1021
|
-
id:
|
|
1058
|
+
id: U,
|
|
1022
1059
|
agent_id: e.id,
|
|
1023
1060
|
owner_id: e.owner_id ?? "",
|
|
1024
|
-
created:
|
|
1025
|
-
modified:
|
|
1026
|
-
agent_id__created_at:
|
|
1027
|
-
agent_id__modified_at:
|
|
1061
|
+
created: A,
|
|
1062
|
+
modified: A,
|
|
1063
|
+
agent_id__created_at: A,
|
|
1064
|
+
agent_id__modified_at: A,
|
|
1028
1065
|
chat_mode: E.Functional,
|
|
1029
1066
|
messages: []
|
|
1030
1067
|
}
|
|
1031
|
-
}, streamingManager:
|
|
1068
|
+
}, streamingManager: b };
|
|
1032
1069
|
} else {
|
|
1033
|
-
const
|
|
1034
|
-
let
|
|
1070
|
+
const b = new AbortController(), U = b.signal;
|
|
1071
|
+
let A;
|
|
1035
1072
|
try {
|
|
1036
|
-
const
|
|
1073
|
+
const L = Ie(
|
|
1037
1074
|
e,
|
|
1038
1075
|
n,
|
|
1039
1076
|
r,
|
|
1040
1077
|
t.mode,
|
|
1041
1078
|
t.persistentChat,
|
|
1042
1079
|
c
|
|
1043
|
-
),
|
|
1044
|
-
return { chatResult:
|
|
1045
|
-
} catch (
|
|
1046
|
-
throw
|
|
1047
|
-
}),
|
|
1080
|
+
), x = we(e, t, r, U).then((q) => (A = q, q)), [R, X] = await Promise.all([L, x]);
|
|
1081
|
+
return { chatResult: R, streamingManager: X };
|
|
1082
|
+
} catch (L) {
|
|
1083
|
+
throw b.abort(), A && await A.disconnect().catch(() => {
|
|
1084
|
+
}), L;
|
|
1048
1085
|
}
|
|
1049
1086
|
}
|
|
1050
1087
|
}, { chatResult: o, streamingManager: a } = await s(), { chat: i, chatMode: d } = o;
|
|
1051
|
-
return d && d !== t.mode && (t.mode = d, (u = (l = t.callbacks).onModeChange) == null || u.call(l, d), d !== E.Functional) ? ((
|
|
1088
|
+
return d && d !== t.mode && (t.mode = d, (u = (l = t.callbacks).onModeChange) == null || u.call(l, d), d !== E.Functional) ? ((j = (y = t.callbacks).onError) == null || j.call(y, new Te(d)), a == null || a.disconnect(), { chat: i }) : { chat: i, streamingManager: a };
|
|
1052
1089
|
}
|
|
1053
|
-
async function
|
|
1054
|
-
var
|
|
1090
|
+
async function Nt(e, t) {
|
|
1091
|
+
var X, q, B;
|
|
1055
1092
|
let n = !0, r = null;
|
|
1056
|
-
const c = t.mixpanelKey ||
|
|
1093
|
+
const c = t.mixpanelKey || Ue, s = t.wsURL || We, o = t.baseURL || re, a = {
|
|
1057
1094
|
messages: [],
|
|
1058
1095
|
chatMode: t.mode || E.Functional
|
|
1059
|
-
}, i =
|
|
1096
|
+
}, i = et({
|
|
1060
1097
|
token: c,
|
|
1061
1098
|
agentId: e,
|
|
1062
1099
|
isEnabled: t.enableAnalitics,
|
|
@@ -1066,39 +1103,39 @@ async function zt(e, t) {
|
|
|
1066
1103
|
fe(() => {
|
|
1067
1104
|
i.track("agent-sdk", { event: "init" }, d);
|
|
1068
1105
|
});
|
|
1069
|
-
const l =
|
|
1070
|
-
i.enrich(
|
|
1071
|
-
const { onMessage:
|
|
1106
|
+
const l = Oe(t.auth, o, t.callbacks.onError, t.externalId), u = await l.getById(e), y = le(u.presenter.type);
|
|
1107
|
+
i.enrich(Ye(u));
|
|
1108
|
+
const { onMessage: j, clearQueue: b } = ut(
|
|
1072
1109
|
i,
|
|
1073
1110
|
a,
|
|
1074
1111
|
t,
|
|
1075
1112
|
u,
|
|
1076
1113
|
() => {
|
|
1077
|
-
var
|
|
1078
|
-
return (
|
|
1114
|
+
var m;
|
|
1115
|
+
return (m = a.socketManager) == null ? void 0 : m.disconnect();
|
|
1079
1116
|
}
|
|
1080
1117
|
);
|
|
1081
|
-
a.messages =
|
|
1082
|
-
const
|
|
1083
|
-
r =
|
|
1084
|
-
},
|
|
1118
|
+
a.messages = rt(t.initialMessages), (q = (X = t.callbacks).onNewMessage) == null || q.call(X, [...a.messages], "answer");
|
|
1119
|
+
const U = (m) => {
|
|
1120
|
+
r = m;
|
|
1121
|
+
}, A = Date.now();
|
|
1085
1122
|
fe(() => {
|
|
1086
|
-
i.track("agent-sdk", { event: "loaded", ...
|
|
1123
|
+
i.track("agent-sdk", { event: "loaded", ...Xe(u) }, A);
|
|
1087
1124
|
});
|
|
1088
|
-
async function
|
|
1089
|
-
var
|
|
1090
|
-
(F = (
|
|
1091
|
-
const
|
|
1125
|
+
async function L(m) {
|
|
1126
|
+
var $, F, z, I, T, K, D;
|
|
1127
|
+
(F = ($ = t.callbacks).onConnectionStateChange) == null || F.call($, _.Connecting), W.reset(), m && !n && (delete a.chat, (I = (z = t.callbacks).onNewMessage) == null || I.call(z, [...a.messages], "answer"));
|
|
1128
|
+
const v = t.mode === E.DirectPlayback || y ? Promise.resolve(void 0) : ot(
|
|
1092
1129
|
t.auth,
|
|
1093
1130
|
s,
|
|
1094
|
-
{ onMessage:
|
|
1131
|
+
{ onMessage: j, onError: t.callbacks.onError },
|
|
1095
1132
|
t.externalId
|
|
1096
|
-
),
|
|
1097
|
-
() =>
|
|
1133
|
+
), k = ae(
|
|
1134
|
+
() => Bt(
|
|
1098
1135
|
u,
|
|
1099
1136
|
{
|
|
1100
1137
|
...t,
|
|
1101
|
-
callbacks: { ...t.callbacks, onVideoIdChange:
|
|
1138
|
+
callbacks: { ...t.callbacks, onVideoIdChange: U, onMessage: j }
|
|
1102
1139
|
},
|
|
1103
1140
|
l,
|
|
1104
1141
|
i,
|
|
@@ -1106,110 +1143,122 @@ async function zt(e, t) {
|
|
|
1106
1143
|
),
|
|
1107
1144
|
{
|
|
1108
1145
|
limit: 3,
|
|
1109
|
-
timeout:
|
|
1146
|
+
timeout: Ne,
|
|
1110
1147
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1111
1148
|
shouldRetryFn: (C) => (C == null ? void 0 : C.message) !== "Could not connect" && C.status !== 429 && (C == null ? void 0 : C.message) !== "InsufficientCreditsError",
|
|
1112
1149
|
delayMs: 1e3
|
|
1113
1150
|
}
|
|
1114
1151
|
).catch((C) => {
|
|
1115
|
-
var
|
|
1116
|
-
throw
|
|
1117
|
-
}), [h, { streamingManager:
|
|
1118
|
-
|
|
1119
|
-
chatId:
|
|
1120
|
-
streamId:
|
|
1152
|
+
var O, N;
|
|
1153
|
+
throw R(E.Maintenance), (N = (O = t.callbacks).onConnectionStateChange) == null || N.call(O, _.Fail), C;
|
|
1154
|
+
}), [h, { streamingManager: S, chat: w }] = await Promise.all([v, k]);
|
|
1155
|
+
w && w.id !== ((T = a.chat) == null ? void 0 : T.id) && ((D = (K = t.callbacks).onNewChat) == null || D.call(K, w.id)), a.streamingManager = S, a.socketManager = h, a.chat = w, n = !1, i.enrich({
|
|
1156
|
+
chatId: w == null ? void 0 : w.id,
|
|
1157
|
+
streamId: S == null ? void 0 : S.streamId,
|
|
1121
1158
|
mode: a.chatMode
|
|
1122
|
-
}),
|
|
1159
|
+
}), R((w == null ? void 0 : w.chat_mode) ?? t.mode ?? E.Functional);
|
|
1123
1160
|
}
|
|
1124
|
-
async function
|
|
1125
|
-
var
|
|
1126
|
-
(
|
|
1161
|
+
async function x() {
|
|
1162
|
+
var m, v, k, h;
|
|
1163
|
+
(m = a.socketManager) == null || m.disconnect(), await ((v = a.streamingManager) == null ? void 0 : v.disconnect()), delete a.streamingManager, delete a.socketManager, (h = (k = t.callbacks).onConnectionStateChange) == null || h.call(k, _.Disconnected);
|
|
1127
1164
|
}
|
|
1128
|
-
async function
|
|
1129
|
-
var
|
|
1130
|
-
|
|
1165
|
+
async function R(m) {
|
|
1166
|
+
var v, k;
|
|
1167
|
+
m !== a.chatMode && (i.track("agent-mode-change", { mode: m }), a.chatMode = m, a.chatMode !== E.Functional && await x(), (k = (v = t.callbacks).onModeChange) == null || k.call(v, m));
|
|
1131
1168
|
}
|
|
1132
1169
|
return {
|
|
1133
1170
|
agent: u,
|
|
1134
1171
|
getStreamType: () => {
|
|
1135
|
-
var
|
|
1136
|
-
return (
|
|
1172
|
+
var m;
|
|
1173
|
+
return (m = a.streamingManager) == null ? void 0 : m.streamType;
|
|
1137
1174
|
},
|
|
1138
1175
|
getIsInterruptAvailable: () => {
|
|
1139
|
-
var
|
|
1140
|
-
return ((
|
|
1176
|
+
var m;
|
|
1177
|
+
return ((m = a.streamingManager) == null ? void 0 : m.interruptAvailable) ?? !1;
|
|
1141
1178
|
},
|
|
1142
1179
|
getIsTriggersAvailable: () => {
|
|
1143
|
-
var
|
|
1144
|
-
return ((
|
|
1180
|
+
var m;
|
|
1181
|
+
return ((m = a.streamingManager) == null ? void 0 : m.triggersAvailable) ?? !1;
|
|
1145
1182
|
},
|
|
1146
1183
|
starterMessages: ((B = u.knowledge) == null ? void 0 : B.starter_message) || [],
|
|
1147
1184
|
getSTTToken: () => l.getSTTToken(u.id),
|
|
1148
|
-
changeMode:
|
|
1185
|
+
changeMode: R,
|
|
1149
1186
|
enrichAnalytics: i.enrich,
|
|
1150
1187
|
async connect() {
|
|
1151
|
-
await
|
|
1188
|
+
await L(!0), i.track("agent-chat", {
|
|
1152
1189
|
event: "connect",
|
|
1153
1190
|
mode: a.chatMode
|
|
1154
1191
|
});
|
|
1155
1192
|
},
|
|
1156
1193
|
async reconnect() {
|
|
1157
|
-
await
|
|
1194
|
+
await x(), await L(!1), i.track("agent-chat", {
|
|
1158
1195
|
event: "reconnect",
|
|
1159
1196
|
mode: a.chatMode
|
|
1160
1197
|
});
|
|
1161
1198
|
},
|
|
1162
1199
|
async disconnect() {
|
|
1163
|
-
await
|
|
1200
|
+
await x(), i.track("agent-chat", {
|
|
1164
1201
|
event: "disconnect",
|
|
1165
1202
|
mode: a.chatMode
|
|
1166
1203
|
});
|
|
1167
1204
|
},
|
|
1168
|
-
async
|
|
1169
|
-
var
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1205
|
+
async publishMicrophoneStream(m) {
|
|
1206
|
+
var v;
|
|
1207
|
+
if (!((v = a.streamingManager) != null && v.publishMicrophoneStream))
|
|
1208
|
+
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1209
|
+
return a.streamingManager.publishMicrophoneStream(m);
|
|
1210
|
+
},
|
|
1211
|
+
async unpublishMicrophoneStream() {
|
|
1212
|
+
var m;
|
|
1213
|
+
if (!((m = a.streamingManager) != null && m.unpublishMicrophoneStream))
|
|
1214
|
+
throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
|
|
1215
|
+
return a.streamingManager.unpublishMicrophoneStream();
|
|
1216
|
+
},
|
|
1217
|
+
async chat(m) {
|
|
1218
|
+
var S, w, $, F, z;
|
|
1219
|
+
const v = () => {
|
|
1220
|
+
if (Se(t.mode))
|
|
1221
|
+
throw new Y(`${t.mode} is enabled, chat is disabled`);
|
|
1222
|
+
if (m.length >= 800)
|
|
1223
|
+
throw new Y("Message cannot be more than 800 characters");
|
|
1224
|
+
if (m.length === 0)
|
|
1225
|
+
throw new Y("Message cannot be empty");
|
|
1177
1226
|
if (a.chatMode === E.Maintenance)
|
|
1178
|
-
throw new
|
|
1227
|
+
throw new Y("Chat is in maintenance mode");
|
|
1179
1228
|
if (![E.TextOnly, E.Playground].includes(a.chatMode)) {
|
|
1180
1229
|
if (!a.streamingManager)
|
|
1181
|
-
throw new
|
|
1230
|
+
throw new Y("Streaming manager is not initialized");
|
|
1182
1231
|
if (!a.chat)
|
|
1183
|
-
throw new
|
|
1232
|
+
throw new Y("Chat is not initialized");
|
|
1184
1233
|
}
|
|
1185
|
-
},
|
|
1234
|
+
}, k = async () => {
|
|
1186
1235
|
var I, T;
|
|
1187
1236
|
if (!a.chat) {
|
|
1188
|
-
const
|
|
1237
|
+
const K = await Ie(
|
|
1189
1238
|
u,
|
|
1190
1239
|
l,
|
|
1191
1240
|
i,
|
|
1192
1241
|
a.chatMode,
|
|
1193
1242
|
t.persistentChat
|
|
1194
1243
|
);
|
|
1195
|
-
if (!
|
|
1196
|
-
throw new
|
|
1197
|
-
a.chat =
|
|
1244
|
+
if (!K.chat)
|
|
1245
|
+
throw new _e(a.chatMode, !!t.persistentChat);
|
|
1246
|
+
a.chat = K.chat, (T = (I = t.callbacks).onNewChat) == null || T.call(I, a.chat.id);
|
|
1198
1247
|
}
|
|
1199
1248
|
return a.chat.id;
|
|
1200
1249
|
}, h = async (I, T) => ae(y ? async () => {
|
|
1201
|
-
var
|
|
1202
|
-
return await ((C = (
|
|
1250
|
+
var D, C;
|
|
1251
|
+
return await ((C = (D = a.streamingManager) == null ? void 0 : D.sendTextMessage) == null ? void 0 : C.call(D, m)), Promise.resolve({});
|
|
1203
1252
|
} : async () => {
|
|
1204
|
-
var
|
|
1253
|
+
var D, C;
|
|
1205
1254
|
return l.chat(
|
|
1206
1255
|
u.id,
|
|
1207
1256
|
T,
|
|
1208
1257
|
{
|
|
1209
1258
|
chatMode: a.chatMode,
|
|
1210
|
-
streamId: (
|
|
1259
|
+
streamId: (D = a.streamingManager) == null ? void 0 : D.streamId,
|
|
1211
1260
|
sessionId: (C = a.streamingManager) == null ? void 0 : C.sessionId,
|
|
1212
|
-
messages: I.map(({ matches:
|
|
1261
|
+
messages: I.map(({ matches: O, ...N }) => N)
|
|
1213
1262
|
},
|
|
1214
1263
|
{
|
|
1215
1264
|
...Re(a.chatMode),
|
|
@@ -1218,25 +1267,25 @@ async function zt(e, t) {
|
|
|
1218
1267
|
);
|
|
1219
1268
|
}, {
|
|
1220
1269
|
limit: 2,
|
|
1221
|
-
shouldRetryFn: (
|
|
1222
|
-
var N,
|
|
1223
|
-
const C = (N =
|
|
1224
|
-
return !((
|
|
1270
|
+
shouldRetryFn: (D) => {
|
|
1271
|
+
var N, f, g, M;
|
|
1272
|
+
const C = (N = D == null ? void 0 : D.message) == null ? void 0 : N.includes("missing or invalid session_id");
|
|
1273
|
+
return !((f = D == null ? void 0 : D.message) == null ? void 0 : f.includes("Stream Error")) && !C ? ((M = (g = t.callbacks).onError) == null || M.call(g, D), !1) : !0;
|
|
1225
1274
|
},
|
|
1226
1275
|
onRetry: async () => {
|
|
1227
|
-
await
|
|
1276
|
+
await x(), await L(!1);
|
|
1228
1277
|
}
|
|
1229
1278
|
});
|
|
1230
1279
|
try {
|
|
1231
|
-
|
|
1232
|
-
id:
|
|
1280
|
+
b(), v(), a.messages.push({
|
|
1281
|
+
id: Q(),
|
|
1233
1282
|
role: "user",
|
|
1234
|
-
content:
|
|
1235
|
-
created_at: new Date(
|
|
1236
|
-
}), (
|
|
1237
|
-
const I = await
|
|
1283
|
+
content: m,
|
|
1284
|
+
created_at: new Date(W.update()).toISOString()
|
|
1285
|
+
}), (w = (S = t.callbacks).onNewMessage) == null || w.call(S, [...a.messages], "user");
|
|
1286
|
+
const I = await k(), T = await h([...a.messages], I);
|
|
1238
1287
|
return a.messages.push({
|
|
1239
|
-
id:
|
|
1288
|
+
id: Q(),
|
|
1240
1289
|
role: "assistant",
|
|
1241
1290
|
content: T.result || "",
|
|
1242
1291
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1245,8 +1294,8 @@ async function zt(e, t) {
|
|
|
1245
1294
|
}), i.track("agent-message-send", {
|
|
1246
1295
|
event: "success",
|
|
1247
1296
|
messages: a.messages.length + 1
|
|
1248
|
-
}), T.result && ((F = (
|
|
1249
|
-
latency:
|
|
1297
|
+
}), T.result && ((F = ($ = t.callbacks).onNewMessage) == null || F.call($, [...a.messages], "answer"), i.track("agent-message-received", {
|
|
1298
|
+
latency: W.get(!0),
|
|
1250
1299
|
messages: a.messages.length
|
|
1251
1300
|
})), T;
|
|
1252
1301
|
} catch (I) {
|
|
@@ -1256,69 +1305,69 @@ async function zt(e, t) {
|
|
|
1256
1305
|
}), I;
|
|
1257
1306
|
}
|
|
1258
1307
|
},
|
|
1259
|
-
rate(
|
|
1260
|
-
var
|
|
1261
|
-
const h = a.messages.find((I) => I.id ===
|
|
1308
|
+
rate(m, v, k) {
|
|
1309
|
+
var w, $, F, z;
|
|
1310
|
+
const h = a.messages.find((I) => I.id === m);
|
|
1262
1311
|
if (a.chat) {
|
|
1263
1312
|
if (!h)
|
|
1264
1313
|
throw new Error("Message not found");
|
|
1265
1314
|
} else throw new Error("Chat is not initialized");
|
|
1266
|
-
const
|
|
1315
|
+
const S = ((w = h.matches) == null ? void 0 : w.map((I) => [I.document_id, I.id])) ?? [];
|
|
1267
1316
|
return i.track("agent-rate", {
|
|
1268
|
-
event:
|
|
1269
|
-
thumb:
|
|
1270
|
-
knowledge_id: ((
|
|
1271
|
-
matches:
|
|
1272
|
-
score:
|
|
1273
|
-
}),
|
|
1317
|
+
event: k ? "update" : "create",
|
|
1318
|
+
thumb: v === 1 ? "up" : "down",
|
|
1319
|
+
knowledge_id: (($ = u.knowledge) == null ? void 0 : $.id) ?? "",
|
|
1320
|
+
matches: S,
|
|
1321
|
+
score: v
|
|
1322
|
+
}), k ? l.updateRating(u.id, a.chat.id, k, {
|
|
1274
1323
|
knowledge_id: ((F = u.knowledge) == null ? void 0 : F.id) ?? "",
|
|
1275
|
-
message_id:
|
|
1276
|
-
matches:
|
|
1277
|
-
score:
|
|
1324
|
+
message_id: m,
|
|
1325
|
+
matches: S,
|
|
1326
|
+
score: v
|
|
1278
1327
|
}) : l.createRating(u.id, a.chat.id, {
|
|
1279
1328
|
knowledge_id: ((z = u.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1280
|
-
message_id:
|
|
1281
|
-
matches:
|
|
1282
|
-
score:
|
|
1329
|
+
message_id: m,
|
|
1330
|
+
matches: S,
|
|
1331
|
+
score: v
|
|
1283
1332
|
});
|
|
1284
1333
|
},
|
|
1285
|
-
deleteRate(
|
|
1334
|
+
deleteRate(m) {
|
|
1286
1335
|
if (!a.chat)
|
|
1287
1336
|
throw new Error("Chat is not initialized");
|
|
1288
|
-
return i.track("agent-rate-delete", { type: "text" }), l.deleteRating(u.id, a.chat.id,
|
|
1337
|
+
return i.track("agent-rate-delete", { type: "text" }), l.deleteRating(u.id, a.chat.id, m);
|
|
1289
1338
|
},
|
|
1290
|
-
async speak(
|
|
1291
|
-
var
|
|
1292
|
-
function
|
|
1293
|
-
if (typeof
|
|
1339
|
+
async speak(m) {
|
|
1340
|
+
var S, w, $;
|
|
1341
|
+
function v() {
|
|
1342
|
+
if (typeof m == "string") {
|
|
1294
1343
|
if (!u.presenter.voice)
|
|
1295
1344
|
throw new Error("Presenter voice is not initialized");
|
|
1296
1345
|
return {
|
|
1297
1346
|
type: "text",
|
|
1298
1347
|
provider: u.presenter.voice,
|
|
1299
|
-
input:
|
|
1348
|
+
input: m,
|
|
1300
1349
|
ssml: !1
|
|
1301
1350
|
};
|
|
1302
1351
|
}
|
|
1303
|
-
if (
|
|
1352
|
+
if (m.type === "text" && !m.provider) {
|
|
1304
1353
|
if (!u.presenter.voice)
|
|
1305
1354
|
throw new Error("Presenter voice is not initialized");
|
|
1306
1355
|
return {
|
|
1307
1356
|
type: "text",
|
|
1308
1357
|
provider: u.presenter.voice,
|
|
1309
|
-
input:
|
|
1310
|
-
ssml:
|
|
1358
|
+
input: m.input,
|
|
1359
|
+
ssml: m.ssml
|
|
1311
1360
|
};
|
|
1312
1361
|
}
|
|
1313
|
-
return
|
|
1362
|
+
return m;
|
|
1314
1363
|
}
|
|
1315
|
-
const
|
|
1316
|
-
if (i.track("agent-speak",
|
|
1317
|
-
id:
|
|
1364
|
+
const k = v();
|
|
1365
|
+
if (i.track("agent-speak", k), W.update(), a.messages && k.type === "text" && (a.messages.push({
|
|
1366
|
+
id: Q(),
|
|
1318
1367
|
role: "assistant",
|
|
1319
|
-
content:
|
|
1368
|
+
content: k.input,
|
|
1320
1369
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1321
|
-
}), (
|
|
1370
|
+
}), (w = (S = t.callbacks).onNewMessage) == null || w.call(S, [...a.messages], "answer")), Ke(a.chatMode))
|
|
1322
1371
|
return {
|
|
1323
1372
|
duration: 0,
|
|
1324
1373
|
video_id: "",
|
|
@@ -1327,49 +1376,49 @@ async function zt(e, t) {
|
|
|
1327
1376
|
if (!a.streamingManager)
|
|
1328
1377
|
throw new Error("Please connect to the agent first");
|
|
1329
1378
|
return a.streamingManager.speak({
|
|
1330
|
-
script:
|
|
1331
|
-
metadata: { chat_id: (
|
|
1379
|
+
script: k,
|
|
1380
|
+
metadata: { chat_id: ($ = a.chat) == null ? void 0 : $.id, agent_id: u.id }
|
|
1332
1381
|
});
|
|
1333
1382
|
},
|
|
1334
|
-
async interrupt({ type:
|
|
1335
|
-
var
|
|
1336
|
-
|
|
1337
|
-
const
|
|
1383
|
+
async interrupt({ type: m }) {
|
|
1384
|
+
var k, h, S;
|
|
1385
|
+
nt(a.streamingManager, (k = a.streamingManager) == null ? void 0 : k.streamType, r);
|
|
1386
|
+
const v = a.messages[a.messages.length - 1];
|
|
1338
1387
|
i.track("agent-video-interrupt", {
|
|
1339
|
-
type:
|
|
1388
|
+
type: m || "click",
|
|
1340
1389
|
video_duration_to_interrupt: se.get(!0),
|
|
1341
|
-
message_duration_to_interrupt:
|
|
1342
|
-
}),
|
|
1390
|
+
message_duration_to_interrupt: W.get(!0)
|
|
1391
|
+
}), v.interrupted = !0, (S = (h = t.callbacks).onNewMessage) == null || S.call(h, [...a.messages], "answer"), at(a.streamingManager, r);
|
|
1343
1392
|
}
|
|
1344
1393
|
};
|
|
1345
1394
|
}
|
|
1346
1395
|
export {
|
|
1347
|
-
|
|
1396
|
+
Z as A,
|
|
1348
1397
|
_ as C,
|
|
1349
|
-
|
|
1398
|
+
Be as D,
|
|
1350
1399
|
xe as K,
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1400
|
+
Pe as P,
|
|
1401
|
+
Le as R,
|
|
1402
|
+
H as S,
|
|
1354
1403
|
de as T,
|
|
1355
1404
|
Ae as U,
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1405
|
+
Y as V,
|
|
1406
|
+
be as W,
|
|
1407
|
+
ft as a,
|
|
1359
1408
|
ee as b,
|
|
1360
|
-
|
|
1409
|
+
De as c,
|
|
1361
1410
|
re as d,
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1411
|
+
p as e,
|
|
1412
|
+
P as f,
|
|
1413
|
+
J as g,
|
|
1414
|
+
_e as h,
|
|
1415
|
+
Te as i,
|
|
1416
|
+
Nt as j,
|
|
1417
|
+
je as k,
|
|
1369
1418
|
E as l,
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1419
|
+
$e as m,
|
|
1420
|
+
ye as n,
|
|
1421
|
+
Ft as o,
|
|
1422
|
+
ze as p,
|
|
1423
|
+
Fe as q
|
|
1375
1424
|
};
|