@d-id/client-sdk 1.1.56-staging.254 → 1.1.56-staging.255
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 +438 -438
- package/dist/index.umd.cjs +5 -5
- package/dist/src/types/stream/streams-v2.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
1
|
+
var wt = Object.defineProperty;
|
|
2
|
+
var yt = (e, n, i) => n in e ? wt(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
|
+
var ge = (e, n, i) => yt(e, typeof n != "symbol" ? n + "" : n, i);
|
|
4
|
+
class Re extends Error {
|
|
5
5
|
constructor({ kind: i, description: r, error: o }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: r }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
ge(this, "kind");
|
|
8
|
+
ge(this, "description");
|
|
9
|
+
ge(this, "error");
|
|
10
10
|
this.kind = i, this.description = r, this.error = o;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class vt extends Re {
|
|
14
14
|
constructor(n, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,25 +18,25 @@ class yt extends Se {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Ct extends Re {
|
|
22
22
|
constructor(n) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${n}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class ue extends Re {
|
|
27
27
|
constructor(i, r) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
ge(this, "key");
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class St extends Re {
|
|
34
34
|
constructor(n) {
|
|
35
35
|
super({ kind: "WSError", description: n });
|
|
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 || {}), Tt = /* @__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))(Tt || {}), kt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(kt || {}), Et = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Et || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Dt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Dt || {}), It = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(It || {}), Mt = /* @__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))(Mt || {}), Ze = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ze || {});
|
|
39
|
+
const zn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,12 +48,12 @@ const Fn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ne = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ne || {}),
|
|
52
|
-
const
|
|
53
|
-
}, et = (e) => new Promise((n) => setTimeout(n, e)),
|
|
51
|
+
var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ne = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ne || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), D = /* @__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.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(D || {}), b = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(b || {}), ie = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ie || {}), Pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Pe || {}), At = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(At || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(_t || {});
|
|
52
|
+
const bt = 45 * 1e3, Pt = "X-Playground-Chat", we = "https://api.d-id.com", Lt = "wss://notifications.d-id.com", jt = "79f81a83a67430be2bc0fd61042b8faa", $t = (...e) => {
|
|
53
|
+
}, et = (e) => new Promise((n) => setTimeout(n, e)), le = (e = 16) => {
|
|
54
54
|
const n = new Uint8Array(e);
|
|
55
55
|
return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
56
|
-
}, tt = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type,
|
|
56
|
+
}, tt = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, xt = (e) => {
|
|
57
57
|
switch (e.type) {
|
|
58
58
|
case "expressive":
|
|
59
59
|
return "v4";
|
|
@@ -62,8 +62,8 @@ const _t = 45 * 1e3, bt = "X-Playground-Chat", pe = "https://api.d-id.com", Pt =
|
|
|
62
62
|
case "talk":
|
|
63
63
|
return "v2";
|
|
64
64
|
}
|
|
65
|
-
},
|
|
66
|
-
function
|
|
65
|
+
}, Bt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Le = (e) => e === Ze.Expressive, Ft = (e) => [O.TextOnly, O.Playground, O.Maintenance].includes(e), nt = (e) => e && [O.DirectPlayback, O.Off].includes(e);
|
|
66
|
+
function zt(e, n) {
|
|
67
67
|
let i;
|
|
68
68
|
return {
|
|
69
69
|
promise: new Promise((o, a) => {
|
|
@@ -87,7 +87,7 @@ async function Ie(e, n) {
|
|
|
87
87
|
try {
|
|
88
88
|
if (!i.timeout)
|
|
89
89
|
return await e();
|
|
90
|
-
const { promise: a, clear: s } =
|
|
90
|
+
const { promise: a, clear: s } = zt(i.timeout, i.timeoutErrorMessage), d = e().finally(s);
|
|
91
91
|
return await Promise.race([d, a]);
|
|
92
92
|
} catch (a) {
|
|
93
93
|
if (r = a, !i.shouldRetryFn(a) || o >= i.limit)
|
|
@@ -101,30 +101,30 @@ function Me(e) {
|
|
|
101
101
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
102
102
|
let n = window.localStorage.getItem("did_external_key_id");
|
|
103
103
|
if (!n) {
|
|
104
|
-
let i =
|
|
104
|
+
let i = le();
|
|
105
105
|
window.localStorage.setItem("did_external_key_id", i), n = i;
|
|
106
106
|
}
|
|
107
107
|
return n;
|
|
108
108
|
}
|
|
109
|
-
let
|
|
109
|
+
let Kt = le();
|
|
110
110
|
function rt(e, n) {
|
|
111
111
|
if (e.type === "bearer")
|
|
112
112
|
return `Bearer ${e.token}`;
|
|
113
113
|
if (e.type === "basic")
|
|
114
114
|
return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
|
|
115
115
|
if (e.type === "key")
|
|
116
|
-
return `Client-Key ${e.clientKey}.${Me(n)}_${
|
|
116
|
+
return `Client-Key ${e.clientKey}.${Me(n)}_${Kt}`;
|
|
117
117
|
throw new Error(`Unknown auth type: ${e}`);
|
|
118
118
|
}
|
|
119
|
-
const
|
|
119
|
+
const Nt = (e) => Ie(e, {
|
|
120
120
|
limit: 3,
|
|
121
121
|
delayMs: 1e3,
|
|
122
122
|
timeout: 0,
|
|
123
123
|
shouldRetryFn: (n) => n.status === 429
|
|
124
124
|
});
|
|
125
|
-
function je(e, n =
|
|
125
|
+
function je(e, n = we, i, r) {
|
|
126
126
|
const o = async (a, s) => {
|
|
127
|
-
const { skipErrorHandler: d, ...t } = s || {}, c = await
|
|
127
|
+
const { skipErrorHandler: d, ...t } = s || {}, c = await Nt(
|
|
128
128
|
() => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
|
|
129
129
|
...t,
|
|
130
130
|
headers: {
|
|
@@ -156,7 +156,7 @@ function je(e, n = pe, i, r) {
|
|
|
156
156
|
}
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function Vt(e, n = we, i, r) {
|
|
160
160
|
const o = je(e, `${n}/agents`, i, r);
|
|
161
161
|
return {
|
|
162
162
|
create(a, s) {
|
|
@@ -194,7 +194,7 @@ function Nt(e, n = pe, i, r) {
|
|
|
194
194
|
}
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function Ut(e) {
|
|
198
198
|
var o, a, s, d;
|
|
199
199
|
const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
|
|
200
200
|
const t = navigator.platform;
|
|
@@ -212,13 +212,13 @@ function Vt(e) {
|
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function Jt(e) {
|
|
216
216
|
var i, r, o, a, s, d;
|
|
217
217
|
const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
218
218
|
return {
|
|
219
219
|
agentType: tt(e.presenter),
|
|
220
|
-
presenterType:
|
|
221
|
-
presenter:
|
|
220
|
+
presenterType: xt(e.presenter),
|
|
221
|
+
presenter: Bt(e.presenter),
|
|
222
222
|
owner_id: e.owner_id ?? "",
|
|
223
223
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
224
224
|
behavior: {
|
|
@@ -237,8 +237,8 @@ function Ut(e) {
|
|
|
237
237
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
const
|
|
241
|
-
function
|
|
240
|
+
const Ot = (e) => e.reduce((n, i) => n + i, 0), Je = (e) => Ot(e) / e.length;
|
|
241
|
+
function Wt(e, n, i) {
|
|
242
242
|
var t, c, h;
|
|
243
243
|
const { event: r, ...o } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: s } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
|
|
244
244
|
return {
|
|
@@ -252,8 +252,8 @@ function Ot(e, n, i) {
|
|
|
252
252
|
function Oe(e) {
|
|
253
253
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
254
254
|
}
|
|
255
|
-
const
|
|
256
|
-
function
|
|
255
|
+
const Ht = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
256
|
+
function qt(e) {
|
|
257
257
|
const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
|
|
258
258
|
return {
|
|
259
259
|
token: e.token || "testKey",
|
|
@@ -264,7 +264,7 @@ function Ht(e) {
|
|
|
264
264
|
...e.mixpanelAdditionalProperties || {}
|
|
265
265
|
},
|
|
266
266
|
isEnabled: e.isEnabled ?? !0,
|
|
267
|
-
getRandom:
|
|
267
|
+
getRandom: le,
|
|
268
268
|
enrich(r) {
|
|
269
269
|
this.additionalProperties = { ...this.additionalProperties, ...r };
|
|
270
270
|
},
|
|
@@ -297,7 +297,7 @@ function Ht(e) {
|
|
|
297
297
|
])
|
|
298
298
|
})
|
|
299
299
|
};
|
|
300
|
-
return fetch(
|
|
300
|
+
return fetch(Ht, c).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
|
|
301
301
|
},
|
|
302
302
|
linkTrack(r, o, a, s) {
|
|
303
303
|
i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), s.includes(a) || s.push(a);
|
|
@@ -325,7 +325,7 @@ function $e() {
|
|
|
325
325
|
}
|
|
326
326
|
const re = $e(), Ae = $e(), We = $e();
|
|
327
327
|
function it(e) {
|
|
328
|
-
return e ===
|
|
328
|
+
return e === O.Playground ? { headers: { [Pt]: "true" } } : {};
|
|
329
329
|
}
|
|
330
330
|
async function at(e, n, i, r, o = !1, a) {
|
|
331
331
|
try {
|
|
@@ -335,10 +335,10 @@ async function at(e, n, i, r, o = !1, a) {
|
|
|
335
335
|
mode: r
|
|
336
336
|
})), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
|
|
337
337
|
} catch (s) {
|
|
338
|
-
throw
|
|
338
|
+
throw Qt(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
|
-
const
|
|
341
|
+
const Qt = (e) => {
|
|
342
342
|
try {
|
|
343
343
|
const n = JSON.parse(e.message);
|
|
344
344
|
return n == null ? void 0 : n.kind;
|
|
@@ -346,10 +346,10 @@ const qt = (e) => {
|
|
|
346
346
|
return "UnknownError";
|
|
347
347
|
}
|
|
348
348
|
};
|
|
349
|
-
function
|
|
349
|
+
function Xt(e) {
|
|
350
350
|
return e && e.length > 0 ? e : [];
|
|
351
351
|
}
|
|
352
|
-
function
|
|
352
|
+
function Yt(e, n, i, r) {
|
|
353
353
|
const o = je(e, `${n}/v2/agents/${i}`, r);
|
|
354
354
|
return {
|
|
355
355
|
async createStream(a) {
|
|
@@ -357,11 +357,11 @@ function Xt(e, n, i, r) {
|
|
|
357
357
|
}
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
|
-
const ot = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""),
|
|
360
|
+
const ot = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), Gt = {
|
|
361
361
|
[D.ChatAnswer]: X.Answer,
|
|
362
362
|
[D.ChatPartial]: X.Partial
|
|
363
363
|
};
|
|
364
|
-
function
|
|
364
|
+
function Zt(e, n, i) {
|
|
365
365
|
const r = (n.timestamp - e.timestamp) / 1e3;
|
|
366
366
|
return {
|
|
367
367
|
duration: r,
|
|
@@ -381,7 +381,7 @@ function Gt(e, n, i) {
|
|
|
381
381
|
lowFpsCount: i
|
|
382
382
|
};
|
|
383
383
|
}
|
|
384
|
-
function
|
|
384
|
+
function en(e) {
|
|
385
385
|
return e.filter(
|
|
386
386
|
(n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0
|
|
387
387
|
).map((n) => {
|
|
@@ -392,7 +392,7 @@ function Zt(e) {
|
|
|
392
392
|
};
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function tn(e) {
|
|
396
396
|
let n = "", i = 0;
|
|
397
397
|
for (const r of e.values()) {
|
|
398
398
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (n = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
|
|
@@ -474,14 +474,14 @@ function He(e, n, i) {
|
|
|
474
474
|
framesPerSecond: t.framesPerSecond,
|
|
475
475
|
freezeCount: t.freezeCount - e[c - 1].freezeCount,
|
|
476
476
|
freezeDuration: t.freezeDuration - e[c - 1].freezeDuration
|
|
477
|
-
}), o =
|
|
477
|
+
}), o = en(r), a = o.reduce((t, c) => t + (c.causes.includes("low fps") ? 1 : 0), 0), s = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), d = r.filter((t) => !!t.rtt).map((t) => t.rtt);
|
|
478
478
|
return {
|
|
479
479
|
webRTCStats: {
|
|
480
480
|
anomalies: o,
|
|
481
481
|
minRtt: Math.min(...d),
|
|
482
482
|
avgRtt: Je(d),
|
|
483
483
|
maxRtt: Math.max(...d),
|
|
484
|
-
aggregateReport:
|
|
484
|
+
aggregateReport: Zt(e[0], e[e.length - 1], a),
|
|
485
485
|
minJitterDelayInInterval: Math.min(...s),
|
|
486
486
|
maxJitterDelayInInterval: Math.max(...s),
|
|
487
487
|
avgJitterDelayInInterval: Je(s)
|
|
@@ -496,48 +496,48 @@ function st(e, n) {
|
|
|
496
496
|
return i;
|
|
497
497
|
return null;
|
|
498
498
|
}
|
|
499
|
-
const
|
|
500
|
-
function
|
|
499
|
+
const he = 10;
|
|
500
|
+
function nn(e, n) {
|
|
501
501
|
let i = !1, r = !1, o = null, a = 0, s = 0, d = {};
|
|
502
502
|
async function t() {
|
|
503
503
|
if (i) {
|
|
504
504
|
try {
|
|
505
505
|
const c = await e();
|
|
506
506
|
if (!c) {
|
|
507
|
-
o = setTimeout(t,
|
|
507
|
+
o = setTimeout(t, he);
|
|
508
508
|
return;
|
|
509
509
|
}
|
|
510
510
|
const h = st(c, "audio");
|
|
511
511
|
if (!h) {
|
|
512
|
-
o = setTimeout(t,
|
|
512
|
+
o = setTimeout(t, he);
|
|
513
513
|
return;
|
|
514
514
|
}
|
|
515
515
|
const g = h.totalAudioEnergy ?? 0, l = h.totalSamplesReceived ?? 0;
|
|
516
516
|
if (!r) {
|
|
517
|
-
a = g, s = l, r = !0, o = setTimeout(t,
|
|
517
|
+
a = g, s = l, r = !0, o = setTimeout(t, he);
|
|
518
518
|
return;
|
|
519
519
|
}
|
|
520
|
-
const y = g - a,
|
|
521
|
-
if (a = g, s = l,
|
|
520
|
+
const y = g - a, A = l - s;
|
|
521
|
+
if (a = g, s = l, A > 0 && y > 0) {
|
|
522
522
|
i = !1, n(d);
|
|
523
523
|
return;
|
|
524
524
|
}
|
|
525
525
|
} catch {
|
|
526
526
|
}
|
|
527
|
-
i && (o = setTimeout(t,
|
|
527
|
+
i && (o = setTimeout(t, he));
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
return {
|
|
531
531
|
arm(c = {}) {
|
|
532
|
-
d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t,
|
|
532
|
+
d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t, he);
|
|
533
533
|
},
|
|
534
534
|
destroy() {
|
|
535
535
|
i = !1, o !== null && (clearTimeout(o), o = null);
|
|
536
536
|
}
|
|
537
537
|
};
|
|
538
538
|
}
|
|
539
|
-
const
|
|
540
|
-
function
|
|
539
|
+
const Se = 100, rn = Math.max(Math.ceil(400 / Se), 1), an = 0.25, on = 0.28;
|
|
540
|
+
function sn() {
|
|
541
541
|
let e = 0, n, i, r = 0;
|
|
542
542
|
return (o) => {
|
|
543
543
|
const a = st(o, "video");
|
|
@@ -555,31 +555,31 @@ function on() {
|
|
|
555
555
|
}
|
|
556
556
|
function ct(e, n, i, r, o) {
|
|
557
557
|
let a = null, s = [], d, t = 0, c = !1, h = ne.Unknown, g = ne.Unknown, l = 0, y = 0;
|
|
558
|
-
const
|
|
558
|
+
const A = sn();
|
|
559
559
|
async function z() {
|
|
560
560
|
const L = await e();
|
|
561
561
|
if (!L)
|
|
562
562
|
return;
|
|
563
|
-
const { isReceiving:
|
|
564
|
-
if (
|
|
565
|
-
t = 0, l = k - y, g =
|
|
566
|
-
else if (c && (t++, t >=
|
|
567
|
-
const
|
|
568
|
-
r == null || r(T.Stop,
|
|
563
|
+
const { isReceiving: j, avgJitterDelayInInterval: _, freezeCount: k } = A(L), H = tn(L);
|
|
564
|
+
if (j)
|
|
565
|
+
t = 0, l = k - y, g = _ < an ? ne.Strong : _ > on && l > 1 ? ne.Weak : h, g !== h && (o == null || o(g), h = g, y += l, l = 0), c || (r == null || r(T.Start), d = s[s.length - 1], s = [], c = !0), s.push(H);
|
|
566
|
+
else if (c && (t++, t >= rn)) {
|
|
567
|
+
const q = He(s, Se, d);
|
|
568
|
+
r == null || r(T.Stop, q), n() || i(), y = k, c = !1;
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
return {
|
|
572
572
|
start: () => {
|
|
573
|
-
a || (a = setInterval(z,
|
|
573
|
+
a || (a = setInterval(z, Se));
|
|
574
574
|
},
|
|
575
575
|
stop: () => {
|
|
576
576
|
a && (clearInterval(a), a = null);
|
|
577
577
|
},
|
|
578
|
-
getReport: () => He(s,
|
|
578
|
+
getReport: () => He(s, Se, d)
|
|
579
579
|
};
|
|
580
580
|
}
|
|
581
581
|
const qe = 2e4;
|
|
582
|
-
async function
|
|
582
|
+
async function cn() {
|
|
583
583
|
try {
|
|
584
584
|
return await import("./livekit-client.esm-RGXA_gNu.js");
|
|
585
585
|
} catch {
|
|
@@ -588,13 +588,13 @@ async function sn() {
|
|
|
588
588
|
);
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
|
-
const
|
|
591
|
+
const dn = {
|
|
592
592
|
excellent: ne.Strong,
|
|
593
593
|
good: ne.Strong,
|
|
594
594
|
poor: ne.Weak,
|
|
595
595
|
lost: ne.Unknown,
|
|
596
596
|
unknown: ne.Unknown
|
|
597
|
-
},
|
|
597
|
+
}, pe = JSON.stringify({
|
|
598
598
|
kind: "InternalServerError",
|
|
599
599
|
description: "Stream Error"
|
|
600
600
|
});
|
|
@@ -603,40 +603,40 @@ function _e(e, n, i) {
|
|
|
603
603
|
var r, o;
|
|
604
604
|
throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, b.Fail, "internal:init-error"), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
|
|
605
605
|
}
|
|
606
|
-
async function
|
|
606
|
+
async function un(e, n, i) {
|
|
607
607
|
var ze;
|
|
608
|
-
const r = ot(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await
|
|
608
|
+
const r = ot(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await cn(), { callbacks: t, auth: c, baseURL: h, analytics: g } = i;
|
|
609
609
|
let l = null, y = !1;
|
|
610
|
-
const
|
|
610
|
+
const A = ie.Fluent;
|
|
611
611
|
let z = null;
|
|
612
|
-
const L = { isPublishing: !1, publication: null },
|
|
613
|
-
let
|
|
612
|
+
const L = { isPublishing: !1, publication: null }, j = { isPublishing: !1, publication: null };
|
|
613
|
+
let _ = null, k = null, H = null, q = !1;
|
|
614
614
|
l = new o({
|
|
615
615
|
adaptiveStream: !1,
|
|
616
616
|
// Must be false to use mediaStreamTrack directly
|
|
617
617
|
dynacast: !0
|
|
618
618
|
});
|
|
619
|
-
let K = null, G =
|
|
620
|
-
const
|
|
621
|
-
let f,
|
|
619
|
+
let K = null, G = W.Idle, ae = !0;
|
|
620
|
+
const $ = Yt(c, h || we, e, t.onError);
|
|
621
|
+
let f, C, E, J = !0;
|
|
622
622
|
try {
|
|
623
|
-
const u = await
|
|
623
|
+
const u = await $.createStream({
|
|
624
624
|
transport: n.transport,
|
|
625
625
|
chat_persist: n.chat_persist ?? !0
|
|
626
|
-
}), { id: m, session_token: p, session_url: v } = u;
|
|
627
|
-
(ze = t.onStreamCreated) == null || ze.call(t, { session_id: m, stream_id: m, agent_id: e }), f = m,
|
|
626
|
+
}), { id: m, session_token: p, session_url: v, interrupt_enabled: I } = u;
|
|
627
|
+
(ze = t.onStreamCreated) == null || ze.call(t, { session_id: m, stream_id: m, agent_id: e }), f = m, C = p, E = v, J = I ?? !0, await l.prepareConnection(E, C);
|
|
628
628
|
} catch (u) {
|
|
629
629
|
_e(u, r, t);
|
|
630
630
|
}
|
|
631
|
-
if (!E || !
|
|
631
|
+
if (!E || !C || !f)
|
|
632
632
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
633
|
-
l.on(a.ConnectionStateChanged,
|
|
634
|
-
function
|
|
633
|
+
l.on(a.ConnectionStateChanged, M).on(a.ConnectionQualityChanged, V).on(a.ParticipantConnected, Y).on(a.ParticipantDisconnected, Z).on(a.TrackSubscribed, ee).on(a.TrackUnsubscribed, S).on(a.DataReceived, ve).on(a.MediaDevicesError, Ce).on(a.TranscriptionReceived, x).on(a.EncryptionError, dt).on(a.TrackSubscriptionFailed, ut);
|
|
634
|
+
function x(u, m) {
|
|
635
635
|
var p;
|
|
636
|
-
m != null && m.isLocal && (re.update(), G ===
|
|
636
|
+
m != null && m.isLocal && (re.update(), G === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), G = W.Idle));
|
|
637
637
|
}
|
|
638
638
|
try {
|
|
639
|
-
await l.connect(E,
|
|
639
|
+
await l.connect(E, C), r("LiveKit room joined successfully"), K = setTimeout(() => {
|
|
640
640
|
var u;
|
|
641
641
|
r(
|
|
642
642
|
`Track subscription timeout - no track subscribed within ${qe / 1e3} seconds after connect`
|
|
@@ -649,10 +649,10 @@ async function dn(e, n, i) {
|
|
|
649
649
|
_e(u, r, t);
|
|
650
650
|
}
|
|
651
651
|
g.enrich({
|
|
652
|
-
"stream-type":
|
|
652
|
+
"stream-type": A
|
|
653
653
|
});
|
|
654
|
-
function
|
|
655
|
-
var m, p, v,
|
|
654
|
+
function M(u) {
|
|
655
|
+
var m, p, v, I;
|
|
656
656
|
switch (r("Connection state changed:", u), u) {
|
|
657
657
|
case s.Connecting:
|
|
658
658
|
r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, b.Connecting, "livekit:connecting");
|
|
@@ -661,150 +661,150 @@ async function dn(e, n, i) {
|
|
|
661
661
|
r("LiveKit room connected successfully"), y = !0;
|
|
662
662
|
break;
|
|
663
663
|
case s.Disconnected:
|
|
664
|
-
r("LiveKit room disconnected"), y = !1,
|
|
664
|
+
r("LiveKit room disconnected"), y = !1, q = !1, L.publication = null, j.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, b.Disconnected, "livekit:disconnected");
|
|
665
665
|
break;
|
|
666
666
|
case s.Reconnecting:
|
|
667
667
|
r("LiveKit room reconnecting..."), (v = t.onConnectionStateChange) == null || v.call(t, b.Connecting, "livekit:reconnecting");
|
|
668
668
|
break;
|
|
669
669
|
case s.SignalReconnecting:
|
|
670
|
-
r("LiveKit room signal reconnecting..."), (
|
|
670
|
+
r("LiveKit room signal reconnecting..."), (I = t.onConnectionStateChange) == null || I.call(t, b.Connecting, "livekit:signal-reconnecting");
|
|
671
671
|
break;
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
|
-
function
|
|
674
|
+
function V(u, m) {
|
|
675
675
|
var p;
|
|
676
|
-
r("Connection quality:", u), m != null && m.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t,
|
|
676
|
+
r("Connection quality:", u), m != null && m.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, dn[u]));
|
|
677
677
|
}
|
|
678
|
-
function
|
|
678
|
+
function Y(u) {
|
|
679
679
|
r("Participant connected:", u.identity);
|
|
680
680
|
}
|
|
681
|
-
function
|
|
681
|
+
function Z(u) {
|
|
682
682
|
r("Participant disconnected:", u.identity), De("livekit:participant-disconnected");
|
|
683
683
|
}
|
|
684
|
-
function
|
|
684
|
+
function B() {
|
|
685
685
|
var u;
|
|
686
|
-
|
|
686
|
+
H !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), H = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
|
|
687
687
|
}
|
|
688
|
-
function
|
|
688
|
+
function U(u) {
|
|
689
689
|
var m;
|
|
690
|
-
|
|
690
|
+
H !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), H = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
|
|
691
691
|
}
|
|
692
|
-
function
|
|
693
|
-
var
|
|
692
|
+
function ee(u, m, p) {
|
|
693
|
+
var I, P, Q;
|
|
694
694
|
r(`Track subscribed: ${u.kind} from ${p.identity}`);
|
|
695
695
|
const v = u.mediaStreamTrack;
|
|
696
696
|
if (!v) {
|
|
697
697
|
r(`No mediaStreamTrack available for ${u.kind}`);
|
|
698
698
|
return;
|
|
699
699
|
}
|
|
700
|
-
z ? (z.addTrack(v), r(`Added ${u.kind} track to shared MediaStream`)) : (z = new MediaStream([v]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k =
|
|
700
|
+
z ? (z.addTrack(v), r(`Added ${u.kind} track to shared MediaStream`)) : (z = new MediaStream([v]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = nn(
|
|
701
701
|
() => u.getRTCStatsReport(),
|
|
702
702
|
({ sttLatency: N, serviceLatency: te }) => {
|
|
703
703
|
var Ke, Ne, Ve;
|
|
704
|
-
const
|
|
705
|
-
let
|
|
704
|
+
const me = re.get(!0);
|
|
705
|
+
let fe = 0;
|
|
706
706
|
if (N) {
|
|
707
|
-
const Ue = ((Ne = (Ke =
|
|
708
|
-
|
|
707
|
+
const Ue = ((Ne = (Ke = _ == null ? void 0 : _.getReport()) == null ? void 0 : Ke.webRTCStats) == null ? void 0 : Ne.avgRtt) ?? 0;
|
|
708
|
+
fe = Ue > 0 ? Math.round(Ue * 1e3) : 0;
|
|
709
709
|
}
|
|
710
|
-
const
|
|
711
|
-
(Ve = t.onFirstAudioDetected) == null || Ve.call(t, { latency:
|
|
710
|
+
const de = me > 0 ? me + (N ?? 0) + fe : void 0, oe = de !== void 0 && te !== void 0 ? de - te : void 0;
|
|
711
|
+
(Ve = t.onFirstAudioDetected) == null || Ve.call(t, { latency: de, networkLatency: oe });
|
|
712
712
|
}
|
|
713
|
-
)), u.kind === "video" && ((
|
|
713
|
+
)), u.kind === "video" && ((I = t.onStreamReady) == null || I.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, z), q || (q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (Q = t.onConnectionStateChange) == null || Q.call(t, b.Connected, "livekit:track-subscribed")), _ = ct(
|
|
714
714
|
() => u.getRTCStatsReport(),
|
|
715
715
|
() => y,
|
|
716
|
-
|
|
716
|
+
$t,
|
|
717
717
|
(N, te) => {
|
|
718
|
-
r(`Video state change: ${N}`), N === T.Start ? (K && (clearTimeout(K), K = null, r("Track subscription timeout cleared")),
|
|
718
|
+
r(`Video state change: ${N}`), N === T.Start ? (K && (clearTimeout(K), K = null, r("Track subscription timeout cleared")), B()) : N === T.Stop && U(te);
|
|
719
719
|
}
|
|
720
|
-
),
|
|
720
|
+
), _.start());
|
|
721
721
|
}
|
|
722
|
-
function
|
|
723
|
-
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (
|
|
722
|
+
function S(u, m, p) {
|
|
723
|
+
r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (U(_ == null ? void 0 : _.getReport()), _ == null || _.stop(), _ = null);
|
|
724
724
|
}
|
|
725
|
-
function
|
|
725
|
+
function w(u, m) {
|
|
726
726
|
var v;
|
|
727
|
-
const p =
|
|
727
|
+
const p = Gt[u];
|
|
728
728
|
p && ((v = t.onMessage) == null || v.call(t, p, { event: p, ...m }));
|
|
729
729
|
}
|
|
730
|
-
function
|
|
731
|
-
var p, v,
|
|
730
|
+
function R(u, m) {
|
|
731
|
+
var p, v, I;
|
|
732
732
|
if (u === D.ToolCalling) {
|
|
733
|
-
G =
|
|
733
|
+
G = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (v = t.onToolEvent) == null || v.call(t, D.ToolCalling, m);
|
|
734
734
|
return;
|
|
735
735
|
}
|
|
736
|
-
u === D.ToolResult && ((
|
|
736
|
+
u === D.ToolResult && ((I = t.onToolEvent) == null || I.call(t, D.ToolResult, m));
|
|
737
737
|
}
|
|
738
|
-
function
|
|
739
|
-
var p, v,
|
|
738
|
+
function F(u, m) {
|
|
739
|
+
var p, v, I, P, Q;
|
|
740
740
|
if (ae = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (v = t.onInterruptibleChange) == null || v.call(t, ae), u === D.StreamVideoCreated) {
|
|
741
|
-
G =
|
|
741
|
+
G = W.Talking, (I = t.onAgentActivityStateChange) == null || I.call(t, W.Talking), k == null || k.arm({
|
|
742
742
|
sttLatency: (P = m == null ? void 0 : m.stt) == null ? void 0 : P.latency,
|
|
743
743
|
serviceLatency: m == null ? void 0 : m.serviceLatency
|
|
744
744
|
});
|
|
745
745
|
return;
|
|
746
746
|
}
|
|
747
|
-
ae && (G =
|
|
747
|
+
ae && (G = W.Idle, (Q = t.onAgentActivityStateChange) == null || Q.call(t, W.Idle));
|
|
748
748
|
}
|
|
749
|
-
function
|
|
749
|
+
function se(u, m) {
|
|
750
750
|
var P, Q, N, te;
|
|
751
|
-
const p = ((Q = (P =
|
|
752
|
-
i.debug && ((N = m == null ? void 0 : m.metadata) != null && N.sentiment) && (
|
|
751
|
+
const p = ((Q = (P = _ == null ? void 0 : _.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : Q.avgRtt) ?? 0, v = p > 0 ? Math.round(p / 2 * 1e3) : 0, I = { ...m, downstreamNetworkLatency: v };
|
|
752
|
+
i.debug && ((N = m == null ? void 0 : m.metadata) != null && N.sentiment) && (I.sentiment = {
|
|
753
753
|
id: m.metadata.sentiment.id,
|
|
754
754
|
name: m.metadata.sentiment.sentiment
|
|
755
|
-
}), (te = t.onMessage) == null || te.call(t, u,
|
|
755
|
+
}), (te = t.onMessage) == null || te.call(t, u, I), F(u, m);
|
|
756
756
|
}
|
|
757
|
-
function
|
|
757
|
+
function ce(u, m) {
|
|
758
758
|
var p;
|
|
759
759
|
(p = t.onMessage) == null || p.call(t, X.Transcribe, { event: X.Transcribe, ...m }), queueMicrotask(() => {
|
|
760
760
|
var v;
|
|
761
|
-
(v = t.onAgentActivityStateChange) == null || v.call(t,
|
|
761
|
+
(v = t.onAgentActivityStateChange) == null || v.call(t, W.Loading);
|
|
762
762
|
});
|
|
763
763
|
}
|
|
764
|
-
const
|
|
765
|
-
[D.ChatAnswer]:
|
|
766
|
-
[D.ChatPartial]:
|
|
767
|
-
[D.ToolCalling]:
|
|
768
|
-
[D.ToolResult]:
|
|
769
|
-
[D.StreamVideoCreated]:
|
|
770
|
-
[D.StreamVideoDone]:
|
|
771
|
-
[D.StreamVideoError]:
|
|
772
|
-
[D.StreamVideoRejected]:
|
|
773
|
-
[D.ChatAudioTranscribed]:
|
|
764
|
+
const ye = {
|
|
765
|
+
[D.ChatAnswer]: w,
|
|
766
|
+
[D.ChatPartial]: w,
|
|
767
|
+
[D.ToolCalling]: R,
|
|
768
|
+
[D.ToolResult]: R,
|
|
769
|
+
[D.StreamVideoCreated]: se,
|
|
770
|
+
[D.StreamVideoDone]: se,
|
|
771
|
+
[D.StreamVideoError]: se,
|
|
772
|
+
[D.StreamVideoRejected]: se,
|
|
773
|
+
[D.ChatAudioTranscribed]: ce
|
|
774
774
|
};
|
|
775
|
-
function
|
|
776
|
-
const
|
|
775
|
+
function ve(u, m, p, v) {
|
|
776
|
+
const I = new TextDecoder().decode(u);
|
|
777
777
|
try {
|
|
778
|
-
const P = JSON.parse(
|
|
778
|
+
const P = JSON.parse(I), Q = v || P.subject;
|
|
779
779
|
if (r("Data received:", { subject: Q, data: P }), !Q) return;
|
|
780
|
-
const N =
|
|
780
|
+
const N = ye[Q];
|
|
781
781
|
N == null || N(Q, P);
|
|
782
782
|
} catch (P) {
|
|
783
783
|
r("Failed to parse data channel message:", P);
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
|
-
function
|
|
786
|
+
function Ce(u) {
|
|
787
787
|
var m;
|
|
788
|
-
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
788
|
+
r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(pe), { sessionId: f });
|
|
789
789
|
}
|
|
790
|
-
function
|
|
790
|
+
function dt(u) {
|
|
791
791
|
var m;
|
|
792
|
-
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(
|
|
792
|
+
r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(pe), { sessionId: f });
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function ut(u, m, p) {
|
|
795
795
|
r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
|
|
796
796
|
}
|
|
797
|
-
function
|
|
798
|
-
for (const [v,
|
|
799
|
-
if (
|
|
800
|
-
const P =
|
|
797
|
+
function lt(u, m, p) {
|
|
798
|
+
for (const [v, I] of p)
|
|
799
|
+
if (I.source === m && I.track) {
|
|
800
|
+
const P = I.track.mediaStreamTrack;
|
|
801
801
|
if (P === u || (P == null ? void 0 : P.id) === u.id)
|
|
802
|
-
return
|
|
802
|
+
return I;
|
|
803
803
|
}
|
|
804
804
|
return null;
|
|
805
805
|
}
|
|
806
|
-
async function Be(u, m, p, v,
|
|
807
|
-
var
|
|
806
|
+
async function Be(u, m, p, v, I, P) {
|
|
807
|
+
var me, fe, de;
|
|
808
808
|
if (!y || !l)
|
|
809
809
|
throw r(`Room is not connected, cannot publish ${v} stream`), new Error("Room is not connected");
|
|
810
810
|
if (u.isPublishing) {
|
|
@@ -814,15 +814,15 @@ async function dn(e, n, i) {
|
|
|
814
814
|
const Q = p(m);
|
|
815
815
|
if (Q.length === 0)
|
|
816
816
|
throw new Error(`No ${v} track found in the provided MediaStream`);
|
|
817
|
-
const N = Q[0], te =
|
|
817
|
+
const N = Q[0], te = lt(N, v, I());
|
|
818
818
|
if (te) {
|
|
819
819
|
r(`${v} track is already published, skipping`, {
|
|
820
820
|
trackId: N.id,
|
|
821
|
-
publishedTrackId: (
|
|
821
|
+
publishedTrackId: (fe = (me = te.track) == null ? void 0 : me.mediaStreamTrack) == null ? void 0 : fe.id
|
|
822
822
|
}), u.publication = te;
|
|
823
823
|
return;
|
|
824
824
|
}
|
|
825
|
-
if ((
|
|
825
|
+
if ((de = u.publication) != null && de.track) {
|
|
826
826
|
const oe = u.publication.track.mediaStreamTrack;
|
|
827
827
|
oe !== N && (oe == null ? void 0 : oe.id) !== N.id && (r(`Unpublishing existing ${v} track before publishing new one`), await P());
|
|
828
828
|
}
|
|
@@ -845,7 +845,7 @@ async function dn(e, n, i) {
|
|
|
845
845
|
u.publication = null;
|
|
846
846
|
}
|
|
847
847
|
}
|
|
848
|
-
async function
|
|
848
|
+
async function mt(u) {
|
|
849
849
|
return Be(
|
|
850
850
|
L,
|
|
851
851
|
u,
|
|
@@ -858,9 +858,9 @@ async function dn(e, n, i) {
|
|
|
858
858
|
async function Te() {
|
|
859
859
|
return Fe(L, "Microphone");
|
|
860
860
|
}
|
|
861
|
-
async function
|
|
861
|
+
async function ft(u) {
|
|
862
862
|
return Be(
|
|
863
|
-
|
|
863
|
+
j,
|
|
864
864
|
u,
|
|
865
865
|
(m) => m.getVideoTracks(),
|
|
866
866
|
d.Source.Camera,
|
|
@@ -869,35 +869,35 @@ async function dn(e, n, i) {
|
|
|
869
869
|
);
|
|
870
870
|
}
|
|
871
871
|
async function ke() {
|
|
872
|
-
return Fe(
|
|
872
|
+
return Fe(j, "Camera");
|
|
873
873
|
}
|
|
874
|
-
function
|
|
874
|
+
function gt() {
|
|
875
875
|
z && (z.getTracks().forEach((u) => u.stop()), z = null);
|
|
876
876
|
}
|
|
877
877
|
async function Ee(u, m) {
|
|
878
878
|
var p, v;
|
|
879
879
|
if (!y || !l) {
|
|
880
|
-
r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(
|
|
880
|
+
r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(pe), {
|
|
881
881
|
sessionId: f
|
|
882
882
|
});
|
|
883
883
|
return;
|
|
884
884
|
}
|
|
885
885
|
try {
|
|
886
886
|
await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
|
|
887
|
-
} catch (
|
|
888
|
-
r("Failed to send message:",
|
|
887
|
+
} catch (I) {
|
|
888
|
+
r("Failed to send message:", I), (v = t.onError) == null || v.call(t, new Error(pe), { sessionId: f });
|
|
889
889
|
}
|
|
890
890
|
}
|
|
891
|
-
async function
|
|
891
|
+
async function ht(u) {
|
|
892
892
|
var m;
|
|
893
893
|
try {
|
|
894
894
|
const v = JSON.parse(u).topic;
|
|
895
895
|
return Ee("", v);
|
|
896
896
|
} catch (p) {
|
|
897
|
-
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(
|
|
897
|
+
r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(pe), { sessionId: f });
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
|
-
function
|
|
900
|
+
function pt(u) {
|
|
901
901
|
return Ee(
|
|
902
902
|
u,
|
|
903
903
|
"lk.chat"
|
|
@@ -906,7 +906,7 @@ async function dn(e, n, i) {
|
|
|
906
906
|
}
|
|
907
907
|
async function De(u) {
|
|
908
908
|
var m, p;
|
|
909
|
-
K && (clearTimeout(K), K = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, b.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()),
|
|
909
|
+
K && (clearTimeout(K), K = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, b.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()), gt(), y = !1, q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), G = W.Idle;
|
|
910
910
|
}
|
|
911
911
|
return {
|
|
912
912
|
speak(u) {
|
|
@@ -924,16 +924,16 @@ async function dn(e, n, i) {
|
|
|
924
924
|
r("Room is already connected");
|
|
925
925
|
return;
|
|
926
926
|
}
|
|
927
|
-
if (!l || !E || !
|
|
927
|
+
if (!l || !E || !C)
|
|
928
928
|
throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
929
|
-
r("Reconnecting to LiveKit room, state:", l.state),
|
|
929
|
+
r("Reconnecting to LiveKit room, state:", l.state), q = !1, (u = t.onConnectionStateChange) == null || u.call(t, b.Connecting, "user:reconnect");
|
|
930
930
|
try {
|
|
931
|
-
if (await l.connect(E,
|
|
931
|
+
if (await l.connect(E, C), r("Room reconnected"), y = !0, l.remoteParticipants.size === 0) {
|
|
932
932
|
if (r("Waiting for agent to join..."), !await new Promise((v) => {
|
|
933
|
-
const
|
|
933
|
+
const I = setTimeout(() => {
|
|
934
934
|
l == null || l.off(a.ParticipantConnected, P), v(!1);
|
|
935
935
|
}, 5e3), P = () => {
|
|
936
|
-
clearTimeout(
|
|
936
|
+
clearTimeout(I), l == null || l.off(a.ParticipantConnected, P), v(!0);
|
|
937
937
|
};
|
|
938
938
|
l == null || l.on(a.ParticipantConnected, P);
|
|
939
939
|
}))
|
|
@@ -944,26 +944,26 @@ async function dn(e, n, i) {
|
|
|
944
944
|
throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, b.Fail, "user:reconnect-failed"), p;
|
|
945
945
|
}
|
|
946
946
|
},
|
|
947
|
-
sendDataChannelMessage:
|
|
948
|
-
sendTextMessage:
|
|
949
|
-
publishMicrophoneStream:
|
|
947
|
+
sendDataChannelMessage: ht,
|
|
948
|
+
sendTextMessage: pt,
|
|
949
|
+
publishMicrophoneStream: mt,
|
|
950
950
|
unpublishMicrophoneStream: Te,
|
|
951
|
-
publishCameraStream:
|
|
951
|
+
publishCameraStream: ft,
|
|
952
952
|
unpublishCameraStream: ke,
|
|
953
953
|
sessionId: f,
|
|
954
954
|
streamId: f,
|
|
955
|
-
streamType:
|
|
956
|
-
interruptAvailable:
|
|
955
|
+
streamType: A,
|
|
956
|
+
interruptAvailable: J,
|
|
957
957
|
isInterruptible: ae
|
|
958
958
|
};
|
|
959
959
|
}
|
|
960
|
-
const
|
|
960
|
+
const ln = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
961
961
|
__proto__: null,
|
|
962
962
|
DataChannelTopic: xe,
|
|
963
|
-
createLiveKitStreamingManager:
|
|
963
|
+
createLiveKitStreamingManager: un,
|
|
964
964
|
handleInitError: _e
|
|
965
965
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
966
|
-
function
|
|
966
|
+
function mn(e, n, i) {
|
|
967
967
|
if (!e)
|
|
968
968
|
throw new Error("Please connect to the agent first");
|
|
969
969
|
if (!e.interruptAvailable)
|
|
@@ -973,7 +973,7 @@ function ln(e, n, i) {
|
|
|
973
973
|
if (!i)
|
|
974
974
|
throw new Error("No active video to interrupt");
|
|
975
975
|
}
|
|
976
|
-
async function
|
|
976
|
+
async function fn(e, n) {
|
|
977
977
|
const i = {
|
|
978
978
|
type: D.StreamInterrupt,
|
|
979
979
|
videoId: n,
|
|
@@ -981,13 +981,13 @@ async function mn(e, n) {
|
|
|
981
981
|
};
|
|
982
982
|
e.sendDataChannelMessage(JSON.stringify(i));
|
|
983
983
|
}
|
|
984
|
-
async function
|
|
984
|
+
async function gn(e) {
|
|
985
985
|
const n = {
|
|
986
986
|
topic: xe.Interrupt
|
|
987
987
|
};
|
|
988
988
|
e.sendDataChannelMessage(JSON.stringify(n));
|
|
989
989
|
}
|
|
990
|
-
function
|
|
990
|
+
function hn(e) {
|
|
991
991
|
return new Promise((n, i) => {
|
|
992
992
|
const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: h = null } = r || {}, g = new WebSocket(`${o}?authorization=${encodeURIComponent(rt(a, s))}`);
|
|
993
993
|
g.onmessage = d, g.onclose = c, g.onerror = (l) => {
|
|
@@ -997,12 +997,12 @@ function gn(e) {
|
|
|
997
997
|
};
|
|
998
998
|
});
|
|
999
999
|
}
|
|
1000
|
-
async function
|
|
1000
|
+
async function pn(e) {
|
|
1001
1001
|
const { retries: n = 1 } = e;
|
|
1002
1002
|
let i = null;
|
|
1003
1003
|
for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
|
|
1004
1004
|
try {
|
|
1005
|
-
i = await
|
|
1005
|
+
i = await hn(e);
|
|
1006
1006
|
} catch (o) {
|
|
1007
1007
|
if (r === n)
|
|
1008
1008
|
throw o;
|
|
@@ -1010,15 +1010,15 @@ async function hn(e) {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
return i;
|
|
1012
1012
|
}
|
|
1013
|
-
async function
|
|
1014
|
-
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await
|
|
1013
|
+
async function wn(e, n, i, r) {
|
|
1014
|
+
const o = i != null && i.onMessage ? [i.onMessage] : [], a = await pn({
|
|
1015
1015
|
auth: e,
|
|
1016
1016
|
host: n,
|
|
1017
1017
|
externalId: r,
|
|
1018
1018
|
callbacks: {
|
|
1019
1019
|
onError: (s) => {
|
|
1020
1020
|
var d;
|
|
1021
|
-
return (d = i.onError) == null ? void 0 : d.call(i, new
|
|
1021
|
+
return (d = i.onError) == null ? void 0 : d.call(i, new St(s));
|
|
1022
1022
|
},
|
|
1023
1023
|
onMessage(s) {
|
|
1024
1024
|
const d = JSON.parse(s.data);
|
|
@@ -1032,7 +1032,7 @@ async function pn(e, n, i, r) {
|
|
|
1032
1032
|
subscribeToEvents: (s) => o.push(s)
|
|
1033
1033
|
};
|
|
1034
1034
|
}
|
|
1035
|
-
function
|
|
1035
|
+
function yn(e) {
|
|
1036
1036
|
if (e.answer !== void 0)
|
|
1037
1037
|
return e.answer;
|
|
1038
1038
|
let n = 0, i = "";
|
|
@@ -1040,7 +1040,7 @@ function wn(e) {
|
|
|
1040
1040
|
i += e[n++];
|
|
1041
1041
|
return i;
|
|
1042
1042
|
}
|
|
1043
|
-
function
|
|
1043
|
+
function vn(e, n, i) {
|
|
1044
1044
|
if (!e.content)
|
|
1045
1045
|
return;
|
|
1046
1046
|
const r = n.messages[n.messages.length - 1];
|
|
@@ -1054,9 +1054,9 @@ function yn(e, n, i) {
|
|
|
1054
1054
|
};
|
|
1055
1055
|
n.messages.push(o), i == null || i([...n.messages], "user");
|
|
1056
1056
|
}
|
|
1057
|
-
function
|
|
1057
|
+
function Cn(e, n, i, r, o) {
|
|
1058
1058
|
if (e === X.Transcribe && n.content) {
|
|
1059
|
-
|
|
1059
|
+
vn(n, r, o);
|
|
1060
1060
|
return;
|
|
1061
1061
|
}
|
|
1062
1062
|
if (!(e === X.Partial || e === X.Answer))
|
|
@@ -1076,10 +1076,10 @@ function vn(e, n, i, r, o) {
|
|
|
1076
1076
|
return;
|
|
1077
1077
|
const { content: d, sequence: t } = n;
|
|
1078
1078
|
e === X.Partial ? i[t] = d : i.answer = d;
|
|
1079
|
-
const c =
|
|
1079
|
+
const c = yn(i);
|
|
1080
1080
|
(s.content !== c || e === X.Answer) && (s.content = c, o == null || o([...r.messages], e));
|
|
1081
1081
|
}
|
|
1082
|
-
function
|
|
1082
|
+
function Sn(e, n, i, r, o) {
|
|
1083
1083
|
let a = {};
|
|
1084
1084
|
const s = () => a = {};
|
|
1085
1085
|
let d = "answer";
|
|
@@ -1093,30 +1093,30 @@ function Cn(e, n, i, r, o) {
|
|
|
1093
1093
|
var g, l;
|
|
1094
1094
|
if ("content" in h) {
|
|
1095
1095
|
const y = c === D.ChatAnswer ? X.Answer : c === D.ChatAudioTranscribed ? X.Transcribe : c;
|
|
1096
|
-
|
|
1096
|
+
Cn(y, h, a, n, t), y === X.Answer && e.track("agent-message-received", {
|
|
1097
1097
|
content: h.content,
|
|
1098
1098
|
messages: n.messages.length,
|
|
1099
1099
|
mode: n.chatMode
|
|
1100
1100
|
});
|
|
1101
1101
|
} else {
|
|
1102
|
-
const y = D,
|
|
1102
|
+
const y = D, A = [y.StreamVideoDone, y.StreamVideoError, y.StreamVideoRejected], z = [y.StreamFailed, y.StreamVideoError, y.StreamVideoRejected], L = Wt(h, r, { mode: n.chatMode });
|
|
1103
1103
|
if (c = c, c === y.StreamVideoCreated && (e.linkTrack("agent-video", L, y.StreamVideoCreated, ["start"]), h.sentiment)) {
|
|
1104
|
-
const
|
|
1105
|
-
if ((
|
|
1106
|
-
const
|
|
1107
|
-
n.messages[n.messages.length - 1] =
|
|
1104
|
+
const j = n.messages[n.messages.length - 1];
|
|
1105
|
+
if ((j == null ? void 0 : j.role) === "assistant") {
|
|
1106
|
+
const _ = { ...j, sentiment: h.sentiment };
|
|
1107
|
+
n.messages[n.messages.length - 1] = _, t == null || t([...n.messages], d);
|
|
1108
1108
|
}
|
|
1109
1109
|
}
|
|
1110
|
-
if (
|
|
1111
|
-
const
|
|
1112
|
-
z.includes(c) ? e.track("agent-video", { ...L, event:
|
|
1110
|
+
if (A.includes(c)) {
|
|
1111
|
+
const j = c.split("/")[1];
|
|
1112
|
+
z.includes(c) ? e.track("agent-video", { ...L, event: j }) : e.linkTrack("agent-video", { ...L, event: j }, c, ["done"]);
|
|
1113
1113
|
}
|
|
1114
1114
|
z.includes(c) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${c}`), { data: h })), h.event === y.StreamDone && o();
|
|
1115
1115
|
}
|
|
1116
1116
|
}
|
|
1117
1117
|
};
|
|
1118
1118
|
}
|
|
1119
|
-
function
|
|
1119
|
+
function Rn(e, n, i, r) {
|
|
1120
1120
|
const o = je(e, `${n}/agents/${i}`, r);
|
|
1121
1121
|
return {
|
|
1122
1122
|
createStream(a, s) {
|
|
@@ -1153,7 +1153,7 @@ function Sn(e, n, i, r) {
|
|
|
1153
1153
|
}
|
|
1154
1154
|
};
|
|
1155
1155
|
}
|
|
1156
|
-
const
|
|
1156
|
+
const Tn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1157
1157
|
function Qe(e) {
|
|
1158
1158
|
switch (e) {
|
|
1159
1159
|
case "connected":
|
|
@@ -1174,7 +1174,7 @@ function Qe(e) {
|
|
|
1174
1174
|
return b.New;
|
|
1175
1175
|
}
|
|
1176
1176
|
}
|
|
1177
|
-
const
|
|
1177
|
+
const kn = (e) => (n) => {
|
|
1178
1178
|
const [i, r = ""] = n.split(/:(.+)/);
|
|
1179
1179
|
try {
|
|
1180
1180
|
const o = JSON.parse(r);
|
|
@@ -1183,7 +1183,7 @@ const Tn = (e) => (n) => {
|
|
|
1183
1183
|
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: o }), { subject: i, data: r };
|
|
1184
1184
|
}
|
|
1185
1185
|
};
|
|
1186
|
-
function
|
|
1186
|
+
function En({
|
|
1187
1187
|
statsSignal: e,
|
|
1188
1188
|
dataChannelSignal: n,
|
|
1189
1189
|
onVideoStateChange: i,
|
|
@@ -1192,7 +1192,7 @@ function kn({
|
|
|
1192
1192
|
}) {
|
|
1193
1193
|
e === T.Start && n === T.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && n === T.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, r));
|
|
1194
1194
|
}
|
|
1195
|
-
function
|
|
1195
|
+
function Dn({
|
|
1196
1196
|
statsSignal: e,
|
|
1197
1197
|
dataChannelSignal: n,
|
|
1198
1198
|
onVideoStateChange: i,
|
|
@@ -1200,7 +1200,7 @@ function En({
|
|
|
1200
1200
|
report: o,
|
|
1201
1201
|
log: a
|
|
1202
1202
|
}) {
|
|
1203
|
-
e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(
|
|
1203
|
+
e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(W.Talking) : n === T.Stop && (r == null || r(W.Idle));
|
|
1204
1204
|
}
|
|
1205
1205
|
function Xe({
|
|
1206
1206
|
statsSignal: e,
|
|
@@ -1211,7 +1211,7 @@ function Xe({
|
|
|
1211
1211
|
report: a,
|
|
1212
1212
|
log: s
|
|
1213
1213
|
}) {
|
|
1214
|
-
o === ie.Legacy ?
|
|
1214
|
+
o === ie.Legacy ? En({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === ie.Fluent && Dn({
|
|
1215
1215
|
statsSignal: e,
|
|
1216
1216
|
dataChannelSignal: n,
|
|
1217
1217
|
onVideoStateChange: i,
|
|
@@ -1220,135 +1220,135 @@ function Xe({
|
|
|
1220
1220
|
log: s
|
|
1221
1221
|
});
|
|
1222
1222
|
}
|
|
1223
|
-
async function
|
|
1223
|
+
async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we, analytics: s }, d) {
|
|
1224
1224
|
var ee;
|
|
1225
|
-
const t = ot(i, "WebRTCStreamingManager"), c =
|
|
1225
|
+
const t = ot(i, "WebRTCStreamingManager"), c = kn(t);
|
|
1226
1226
|
let h = !1, g = !1, l = T.Stop, y = T.Stop;
|
|
1227
|
-
const { startConnection:
|
|
1227
|
+
const { startConnection: A, sendStreamRequest: z, close: L, createStream: j, addIceCandidate: _ } = Rn(
|
|
1228
1228
|
o,
|
|
1229
1229
|
a,
|
|
1230
1230
|
e,
|
|
1231
1231
|
r.onError
|
|
1232
1232
|
), {
|
|
1233
1233
|
id: k,
|
|
1234
|
-
offer:
|
|
1235
|
-
ice_servers:
|
|
1234
|
+
offer: H,
|
|
1235
|
+
ice_servers: q,
|
|
1236
1236
|
session_id: K,
|
|
1237
1237
|
fluent: G,
|
|
1238
1238
|
interrupt_enabled: ae
|
|
1239
|
-
} = await
|
|
1239
|
+
} = await j(n, d);
|
|
1240
1240
|
(ee = r.onStreamCreated) == null || ee.call(r, { stream_id: k, session_id: K, agent_id: e });
|
|
1241
|
-
const
|
|
1241
|
+
const $ = new Tn({ iceServers: q }), f = $.createDataChannel("JanusDataChannel");
|
|
1242
1242
|
if (!K)
|
|
1243
1243
|
throw new Error("Could not create session_id");
|
|
1244
|
-
const
|
|
1244
|
+
const C = G ? ie.Fluent : ie.Legacy;
|
|
1245
1245
|
s.enrich({
|
|
1246
|
-
"stream-type":
|
|
1246
|
+
"stream-type": C
|
|
1247
1247
|
});
|
|
1248
|
-
const E = n.stream_warmup && !G, J = () => h,
|
|
1249
|
-
var
|
|
1250
|
-
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (
|
|
1251
|
-
},
|
|
1252
|
-
() =>
|
|
1248
|
+
const E = n.stream_warmup && !G, J = () => h, x = () => {
|
|
1249
|
+
var S;
|
|
1250
|
+
h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (S = r.onConnectionStateChange) == null || S.call(r, b.Connected));
|
|
1251
|
+
}, M = ct(
|
|
1252
|
+
() => $.getStats(),
|
|
1253
1253
|
J,
|
|
1254
|
-
|
|
1255
|
-
(
|
|
1256
|
-
statsSignal: y =
|
|
1257
|
-
dataChannelSignal:
|
|
1254
|
+
x,
|
|
1255
|
+
(S, w) => Xe({
|
|
1256
|
+
statsSignal: y = S,
|
|
1257
|
+
dataChannelSignal: C === ie.Legacy ? l : void 0,
|
|
1258
1258
|
onVideoStateChange: r.onVideoStateChange,
|
|
1259
1259
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1260
1260
|
report: w,
|
|
1261
|
-
streamType:
|
|
1261
|
+
streamType: C,
|
|
1262
1262
|
log: t
|
|
1263
1263
|
}),
|
|
1264
|
-
(
|
|
1264
|
+
(S) => {
|
|
1265
1265
|
var w;
|
|
1266
|
-
return (w = r.onConnectivityStateChange) == null ? void 0 : w.call(r,
|
|
1266
|
+
return (w = r.onConnectivityStateChange) == null ? void 0 : w.call(r, S);
|
|
1267
1267
|
}
|
|
1268
1268
|
);
|
|
1269
|
-
|
|
1269
|
+
M.start(), $.onicecandidate = (S) => {
|
|
1270
1270
|
var w;
|
|
1271
|
-
t("peerConnection.onicecandidate",
|
|
1271
|
+
t("peerConnection.onicecandidate", S);
|
|
1272
1272
|
try {
|
|
1273
|
-
|
|
1273
|
+
S.candidate && S.candidate.sdpMid && S.candidate.sdpMLineIndex !== null ? _(
|
|
1274
1274
|
k,
|
|
1275
1275
|
{
|
|
1276
|
-
candidate:
|
|
1277
|
-
sdpMid:
|
|
1278
|
-
sdpMLineIndex:
|
|
1276
|
+
candidate: S.candidate.candidate,
|
|
1277
|
+
sdpMid: S.candidate.sdpMid,
|
|
1278
|
+
sdpMLineIndex: S.candidate.sdpMLineIndex
|
|
1279
1279
|
},
|
|
1280
1280
|
K,
|
|
1281
1281
|
d
|
|
1282
|
-
) :
|
|
1282
|
+
) : _(k, { candidate: null }, K, d);
|
|
1283
1283
|
} catch (R) {
|
|
1284
1284
|
(w = r.onError) == null || w.call(r, R, { streamId: k });
|
|
1285
1285
|
}
|
|
1286
1286
|
}, f.onopen = () => {
|
|
1287
|
-
g = !0, (!E || h) &&
|
|
1287
|
+
g = !0, (!E || h) && x();
|
|
1288
1288
|
};
|
|
1289
|
-
const
|
|
1289
|
+
const V = (S) => {
|
|
1290
1290
|
var w;
|
|
1291
|
-
(w = r.onVideoIdChange) == null || w.call(r,
|
|
1291
|
+
(w = r.onVideoIdChange) == null || w.call(r, S);
|
|
1292
1292
|
};
|
|
1293
|
-
function Y(
|
|
1294
|
-
if (
|
|
1293
|
+
function Y(S, w) {
|
|
1294
|
+
if (S === D.StreamStarted && typeof w == "object" && "metadata" in w) {
|
|
1295
1295
|
const R = w.metadata;
|
|
1296
|
-
|
|
1296
|
+
V(R.videoId);
|
|
1297
1297
|
}
|
|
1298
|
-
|
|
1299
|
-
statsSignal:
|
|
1298
|
+
S === D.StreamDone && V(null), l = S === D.StreamStarted ? T.Start : T.Stop, Xe({
|
|
1299
|
+
statsSignal: C === ie.Legacy ? y : void 0,
|
|
1300
1300
|
dataChannelSignal: l,
|
|
1301
1301
|
onVideoStateChange: r.onVideoStateChange,
|
|
1302
1302
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
1303
|
-
streamType:
|
|
1303
|
+
streamType: C,
|
|
1304
1304
|
log: t
|
|
1305
1305
|
});
|
|
1306
1306
|
}
|
|
1307
|
-
function Z(
|
|
1308
|
-
var
|
|
1307
|
+
function Z(S, w) {
|
|
1308
|
+
var F;
|
|
1309
1309
|
const R = typeof w == "string" ? w : w == null ? void 0 : w.metadata;
|
|
1310
|
-
R && s.enrich({ streamMetadata: R }), (
|
|
1310
|
+
R && s.enrich({ streamMetadata: R }), (F = r.onStreamReady) == null || F.call(r);
|
|
1311
1311
|
}
|
|
1312
|
-
const
|
|
1312
|
+
const B = {
|
|
1313
1313
|
[D.StreamStarted]: Y,
|
|
1314
1314
|
[D.StreamDone]: Y,
|
|
1315
1315
|
[D.StreamReady]: Z
|
|
1316
1316
|
};
|
|
1317
|
-
f.onmessage = (
|
|
1318
|
-
var
|
|
1319
|
-
const { subject: w, data: R } = c(
|
|
1320
|
-
(
|
|
1321
|
-
},
|
|
1317
|
+
f.onmessage = (S) => {
|
|
1318
|
+
var F;
|
|
1319
|
+
const { subject: w, data: R } = c(S.data);
|
|
1320
|
+
(F = B[w]) == null || F.call(B, w, R);
|
|
1321
|
+
}, $.oniceconnectionstatechange = () => {
|
|
1322
1322
|
var w;
|
|
1323
|
-
t("peerConnection.oniceconnectionstatechange => " +
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1326
|
-
},
|
|
1323
|
+
t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
|
|
1324
|
+
const S = Qe($.iceConnectionState);
|
|
1325
|
+
S !== b.Connected && ((w = r.onConnectionStateChange) == null || w.call(r, S));
|
|
1326
|
+
}, $.ontrack = (S) => {
|
|
1327
1327
|
var w;
|
|
1328
|
-
t("peerConnection.ontrack",
|
|
1329
|
-
}, await
|
|
1330
|
-
const
|
|
1331
|
-
return t("create answer OK"), await
|
|
1328
|
+
t("peerConnection.ontrack", S), t("CALLBACK: onSrcObjectReady"), (w = r.onSrcObjectReady) == null || w.call(r, S.streams[0]);
|
|
1329
|
+
}, await $.setRemoteDescription(H), t("set remote description OK");
|
|
1330
|
+
const U = await $.createAnswer();
|
|
1331
|
+
return t("create answer OK"), await $.setLocalDescription(U), t("set local description OK"), await A(k, U, K, d), t("start connection OK"), {
|
|
1332
1332
|
/**
|
|
1333
1333
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1334
1334
|
* @param payload
|
|
1335
1335
|
*/
|
|
1336
|
-
speak(
|
|
1337
|
-
return z(k, K,
|
|
1336
|
+
speak(S) {
|
|
1337
|
+
return z(k, K, S);
|
|
1338
1338
|
},
|
|
1339
1339
|
/**
|
|
1340
1340
|
* Method to close RTC connection
|
|
1341
1341
|
*/
|
|
1342
1342
|
async disconnect() {
|
|
1343
|
-
var
|
|
1343
|
+
var S;
|
|
1344
1344
|
if (k) {
|
|
1345
|
-
const w = Qe(
|
|
1346
|
-
if (
|
|
1345
|
+
const w = Qe($.iceConnectionState);
|
|
1346
|
+
if ($) {
|
|
1347
1347
|
if (w === b.New) {
|
|
1348
|
-
|
|
1348
|
+
M.stop();
|
|
1349
1349
|
return;
|
|
1350
1350
|
}
|
|
1351
|
-
|
|
1351
|
+
$.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
|
|
1352
1352
|
}
|
|
1353
1353
|
try {
|
|
1354
1354
|
w === b.Connected && await L(k, K).catch((R) => {
|
|
@@ -1356,13 +1356,13 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
|
|
|
1356
1356
|
} catch (R) {
|
|
1357
1357
|
t("Error on close stream connection", R);
|
|
1358
1358
|
}
|
|
1359
|
-
(
|
|
1359
|
+
(S = r.onAgentActivityStateChange) == null || S.call(r, W.Idle), M.stop();
|
|
1360
1360
|
}
|
|
1361
1361
|
},
|
|
1362
1362
|
/**
|
|
1363
1363
|
* Method to send data channel messages to the server
|
|
1364
1364
|
*/
|
|
1365
|
-
sendDataChannelMessage(
|
|
1365
|
+
sendDataChannelMessage(S) {
|
|
1366
1366
|
var w, R;
|
|
1367
1367
|
if (!h || f.readyState !== "open") {
|
|
1368
1368
|
t("Data channel is not ready for sending messages"), (w = r.onError) == null || w.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
@@ -1371,9 +1371,9 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
|
|
|
1371
1371
|
return;
|
|
1372
1372
|
}
|
|
1373
1373
|
try {
|
|
1374
|
-
f.send(
|
|
1375
|
-
} catch (
|
|
1376
|
-
t("Error sending data channel message",
|
|
1374
|
+
f.send(S);
|
|
1375
|
+
} catch (F) {
|
|
1376
|
+
t("Error sending data channel message", F), (R = r.onError) == null || R.call(r, F, { streamId: k });
|
|
1377
1377
|
}
|
|
1378
1378
|
},
|
|
1379
1379
|
/**
|
|
@@ -1384,24 +1384,24 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
|
|
|
1384
1384
|
* Id of current RTC stream
|
|
1385
1385
|
*/
|
|
1386
1386
|
streamId: k,
|
|
1387
|
-
streamType:
|
|
1387
|
+
streamType: C,
|
|
1388
1388
|
interruptAvailable: ae ?? !1,
|
|
1389
1389
|
isInterruptible: !0
|
|
1390
1390
|
};
|
|
1391
1391
|
}
|
|
1392
1392
|
var be = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(be || {});
|
|
1393
|
-
async function
|
|
1393
|
+
async function Mn(e, n, i, r) {
|
|
1394
1394
|
const o = e.id;
|
|
1395
1395
|
switch (n.version) {
|
|
1396
1396
|
case "v1": {
|
|
1397
1397
|
const { version: a, ...s } = n;
|
|
1398
|
-
return
|
|
1398
|
+
return In(o, s, i, r);
|
|
1399
1399
|
}
|
|
1400
1400
|
case "v2": {
|
|
1401
1401
|
const { version: a, ...s } = n;
|
|
1402
1402
|
switch (s.transport.provider) {
|
|
1403
1403
|
case Pe.Livekit:
|
|
1404
|
-
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() =>
|
|
1404
|
+
const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => ln);
|
|
1405
1405
|
return d(o, s, i);
|
|
1406
1406
|
default:
|
|
1407
1407
|
throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
|
|
@@ -1411,15 +1411,15 @@ async function In(e, n, i, r) {
|
|
|
1411
1411
|
throw new Error(`Invalid stream version: ${n.version}`);
|
|
1412
1412
|
}
|
|
1413
1413
|
}
|
|
1414
|
-
const
|
|
1415
|
-
function
|
|
1414
|
+
const An = "cht";
|
|
1415
|
+
function _n() {
|
|
1416
1416
|
return {
|
|
1417
1417
|
transport: {
|
|
1418
1418
|
provider: Pe.Livekit
|
|
1419
1419
|
}
|
|
1420
1420
|
};
|
|
1421
1421
|
}
|
|
1422
|
-
function
|
|
1422
|
+
function bn(e) {
|
|
1423
1423
|
var o, a;
|
|
1424
1424
|
const { streamOptions: n } = e ?? {}, i = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
|
|
1425
1425
|
plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
|
|
@@ -1432,16 +1432,16 @@ function _n(e) {
|
|
|
1432
1432
|
fluent: n == null ? void 0 : n.fluent
|
|
1433
1433
|
}, ...i && { end_user_data: i } };
|
|
1434
1434
|
}
|
|
1435
|
-
function
|
|
1436
|
-
return Le(e.presenter.type) ? { version: be.V2, ...
|
|
1435
|
+
function Pn(e, n) {
|
|
1436
|
+
return Le(e.presenter.type) ? { version: be.V2, ..._n() } : { version: be.V1, ...bn(n) };
|
|
1437
1437
|
}
|
|
1438
|
-
function
|
|
1438
|
+
function Ln(e, n, i) {
|
|
1439
1439
|
i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
|
|
1440
1440
|
}
|
|
1441
|
-
function Ln(e, n, i, r, o) {
|
|
1442
|
-
o === ie.Fluent ? jn(e, n, i, r, o) : $n(e, n, i, r, o);
|
|
1443
|
-
}
|
|
1444
1441
|
function jn(e, n, i, r, o) {
|
|
1442
|
+
o === ie.Fluent ? $n(e, n, i, r, o) : xn(e, n, i, r, o);
|
|
1443
|
+
}
|
|
1444
|
+
function $n(e, n, i, r, o) {
|
|
1445
1445
|
e === T.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === T.Stop && r.track("stream-session", {
|
|
1446
1446
|
event: "stop",
|
|
1447
1447
|
is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
|
|
@@ -1465,7 +1465,7 @@ function Ye(e, n, i, r, o) {
|
|
|
1465
1465
|
[D.StreamVideoDone]
|
|
1466
1466
|
);
|
|
1467
1467
|
}
|
|
1468
|
-
function
|
|
1468
|
+
function xn(e, n, i, r, o) {
|
|
1469
1469
|
e === T.Start ? r.linkTrack(
|
|
1470
1470
|
"agent-video",
|
|
1471
1471
|
{ event: "start", latency: re.get(!0), "stream-type": o },
|
|
@@ -1488,13 +1488,13 @@ function Ge(e, n, i, r) {
|
|
|
1488
1488
|
return re.reset(), We.update(), new Promise(async (o, a) => {
|
|
1489
1489
|
try {
|
|
1490
1490
|
let s, d = !1;
|
|
1491
|
-
const t =
|
|
1491
|
+
const t = Pn(e, n);
|
|
1492
1492
|
i.enrich({
|
|
1493
1493
|
"stream-version": t.version.toString()
|
|
1494
1494
|
});
|
|
1495
1495
|
let c = null;
|
|
1496
1496
|
const h = e.presenter.type === "expressive";
|
|
1497
|
-
s = await
|
|
1497
|
+
s = await Mn(
|
|
1498
1498
|
e,
|
|
1499
1499
|
t,
|
|
1500
1500
|
{
|
|
@@ -1503,12 +1503,12 @@ function Ge(e, n, i, r) {
|
|
|
1503
1503
|
callbacks: {
|
|
1504
1504
|
...n.callbacks,
|
|
1505
1505
|
onConnectionStateChange: (g, l) => {
|
|
1506
|
-
var y,
|
|
1507
|
-
(
|
|
1506
|
+
var y, A;
|
|
1507
|
+
(A = (y = n.callbacks).onConnectionStateChange) == null || A.call(y, g), Ln(g, l, i), g === b.Connected && (s ? o(s) : d = !0);
|
|
1508
1508
|
},
|
|
1509
1509
|
onVideoStateChange: (g, l) => {
|
|
1510
|
-
var y,
|
|
1511
|
-
(
|
|
1510
|
+
var y, A;
|
|
1511
|
+
(A = (y = n.callbacks).onVideoStateChange) == null || A.call(y, g), jn(
|
|
1512
1512
|
g,
|
|
1513
1513
|
e,
|
|
1514
1514
|
l,
|
|
@@ -1518,13 +1518,13 @@ function Ge(e, n, i, r) {
|
|
|
1518
1518
|
},
|
|
1519
1519
|
onAgentActivityStateChange: (g) => {
|
|
1520
1520
|
var l, y;
|
|
1521
|
-
(y = (l = n.callbacks).onAgentActivityStateChange) == null || y.call(l, g), g ===
|
|
1521
|
+
(y = (l = n.callbacks).onAgentActivityStateChange) == null || y.call(l, g), g === W.Talking ? (Ae.update(), c = (A) => {
|
|
1522
1522
|
Ye(
|
|
1523
1523
|
T.Start,
|
|
1524
1524
|
e,
|
|
1525
1525
|
i,
|
|
1526
1526
|
s.streamType,
|
|
1527
|
-
|
|
1527
|
+
A
|
|
1528
1528
|
), c = null;
|
|
1529
1529
|
}, h || c({ latency: re.get(!0) })) : (Ae.reset(), c = null, Ye(
|
|
1530
1530
|
T.Stop,
|
|
@@ -1549,13 +1549,13 @@ function Ge(e, n, i, r) {
|
|
|
1549
1549
|
}
|
|
1550
1550
|
});
|
|
1551
1551
|
}
|
|
1552
|
-
async function
|
|
1552
|
+
async function Bn(e, n, i, r, o) {
|
|
1553
1553
|
var h, g, l, y;
|
|
1554
1554
|
const a = async () => {
|
|
1555
1555
|
if (Le(e.presenter.type)) {
|
|
1556
|
-
const
|
|
1556
|
+
const A = await Ge(e, n, r), z = `${An}_${A.sessionId}`, L = (/* @__PURE__ */ new Date()).toISOString();
|
|
1557
1557
|
return { chatResult: {
|
|
1558
|
-
chatMode:
|
|
1558
|
+
chatMode: O.Functional,
|
|
1559
1559
|
chat: {
|
|
1560
1560
|
id: z,
|
|
1561
1561
|
agent_id: e.id,
|
|
@@ -1564,38 +1564,38 @@ async function xn(e, n, i, r, o) {
|
|
|
1564
1564
|
modified: L,
|
|
1565
1565
|
agent_id__created_at: L,
|
|
1566
1566
|
agent_id__modified_at: L,
|
|
1567
|
-
chat_mode:
|
|
1567
|
+
chat_mode: O.Functional,
|
|
1568
1568
|
messages: []
|
|
1569
1569
|
}
|
|
1570
|
-
}, streamingManager:
|
|
1570
|
+
}, streamingManager: A };
|
|
1571
1571
|
} else {
|
|
1572
|
-
const
|
|
1572
|
+
const A = new AbortController(), z = A.signal;
|
|
1573
1573
|
let L;
|
|
1574
1574
|
try {
|
|
1575
|
-
const
|
|
1575
|
+
const j = at(
|
|
1576
1576
|
e,
|
|
1577
1577
|
i,
|
|
1578
1578
|
r,
|
|
1579
1579
|
n.mode,
|
|
1580
1580
|
n.persistentChat,
|
|
1581
1581
|
o
|
|
1582
|
-
),
|
|
1583
|
-
return { chatResult: k, streamingManager:
|
|
1584
|
-
} catch (
|
|
1585
|
-
throw
|
|
1586
|
-
}),
|
|
1582
|
+
), _ = Ge(e, n, r, z).then((q) => (L = q, q)), [k, H] = await Promise.all([j, _]);
|
|
1583
|
+
return { chatResult: k, streamingManager: H };
|
|
1584
|
+
} catch (j) {
|
|
1585
|
+
throw A.abort(), L && await L.disconnect().catch(() => {
|
|
1586
|
+
}), j;
|
|
1587
1587
|
}
|
|
1588
1588
|
}
|
|
1589
1589
|
}, { chatResult: s, streamingManager: d } = await a(), { chat: t, chatMode: c } = s;
|
|
1590
|
-
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (h = n.callbacks).onModeChange) == null || g.call(h, c), c !==
|
|
1590
|
+
return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (h = n.callbacks).onModeChange) == null || g.call(h, c), c !== O.Functional) ? ((y = (l = n.callbacks).onError) == null || y.call(l, new Ct(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
|
|
1591
1591
|
}
|
|
1592
|
-
async function
|
|
1593
|
-
var K, G, ae,
|
|
1592
|
+
async function Kn(e, n) {
|
|
1593
|
+
var K, G, ae, $;
|
|
1594
1594
|
let i = !0, r = null;
|
|
1595
|
-
const o = n.mixpanelKey ||
|
|
1595
|
+
const o = n.mixpanelKey || jt, a = n.wsURL || Lt, s = n.baseURL || we, d = n.mode || O.Functional, t = {
|
|
1596
1596
|
messages: [],
|
|
1597
1597
|
chatMode: d
|
|
1598
|
-
}, c =
|
|
1598
|
+
}, c = qt({
|
|
1599
1599
|
token: o,
|
|
1600
1600
|
agentId: e,
|
|
1601
1601
|
isEnabled: n.enableAnalitics,
|
|
@@ -1605,40 +1605,40 @@ async function zn(e, n) {
|
|
|
1605
1605
|
Oe(() => {
|
|
1606
1606
|
c.track("agent-sdk", { event: "init" }, h);
|
|
1607
1607
|
});
|
|
1608
|
-
const g =
|
|
1608
|
+
const g = Vt(n.auth, s, n.callbacks.onError, n.externalId), l = await g.getById(e);
|
|
1609
1609
|
n.debug = n.debug || ((K = l == null ? void 0 : l.advanced_settings) == null ? void 0 : K.ui_debug_mode);
|
|
1610
1610
|
const y = Le(l.presenter.type);
|
|
1611
|
-
c.enrich(
|
|
1612
|
-
const { onMessage:
|
|
1613
|
-
var f,
|
|
1614
|
-
(f = t.socketManager) == null || f.disconnect(), (E = (
|
|
1611
|
+
c.enrich(Jt(l));
|
|
1612
|
+
const { onMessage: A, clearQueue: z } = Sn(c, t, n, l, () => {
|
|
1613
|
+
var f, C, E;
|
|
1614
|
+
(f = t.socketManager) == null || f.disconnect(), (E = (C = n.callbacks).onConnectionStateChange) == null || E.call(C, b.Disconnected);
|
|
1615
1615
|
});
|
|
1616
|
-
t.messages =
|
|
1616
|
+
t.messages = Xt(n.initialMessages), (ae = (G = n.callbacks).onNewMessage) == null || ae.call(G, [...t.messages], "answer");
|
|
1617
1617
|
const L = (f) => {
|
|
1618
1618
|
r = f;
|
|
1619
|
-
},
|
|
1620
|
-
var E, J,
|
|
1621
|
-
if (!((E = t.streamingManager) != null && E.isInterruptible)) return;
|
|
1622
|
-
const
|
|
1619
|
+
}, j = ({ type: f }) => {
|
|
1620
|
+
var E, J, x, M, V;
|
|
1621
|
+
if (!((E = t.streamingManager) != null && E.interruptAvailable) || !((J = t.streamingManager) != null && J.isInterruptible)) return;
|
|
1622
|
+
const C = t.messages[t.messages.length - 1];
|
|
1623
1623
|
c.track("agent-video-interrupt", {
|
|
1624
1624
|
type: f || "click",
|
|
1625
1625
|
video_duration_to_interrupt: Ae.get(!0),
|
|
1626
1626
|
message_duration_to_interrupt: re.get(!0)
|
|
1627
|
-
}),
|
|
1628
|
-
},
|
|
1627
|
+
}), C.interrupted = !0, (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "answer"), y ? gn(t.streamingManager) : (mn(t.streamingManager, (V = t.streamingManager) == null ? void 0 : V.streamType, r), fn(t.streamingManager, r));
|
|
1628
|
+
}, _ = Date.now();
|
|
1629
1629
|
Oe(() => {
|
|
1630
|
-
c.track("agent-sdk", { event: "loaded", ...
|
|
1630
|
+
c.track("agent-sdk", { event: "loaded", ...Ut(l) }, _);
|
|
1631
1631
|
});
|
|
1632
1632
|
async function k(f) {
|
|
1633
|
-
var
|
|
1634
|
-
(Y = (
|
|
1635
|
-
const
|
|
1633
|
+
var V, Y, Z, B, U, ee, S;
|
|
1634
|
+
(Y = (V = n.callbacks).onConnectionStateChange) == null || Y.call(V, b.Connecting), re.reset(), f && !i && (delete t.chat, (B = (Z = n.callbacks).onNewMessage) == null || B.call(Z, [...t.messages], "answer"));
|
|
1635
|
+
const C = d === O.DirectPlayback || y ? Promise.resolve(void 0) : wn(
|
|
1636
1636
|
n.auth,
|
|
1637
1637
|
a,
|
|
1638
|
-
{ onMessage:
|
|
1638
|
+
{ onMessage: A, onError: n.callbacks.onError },
|
|
1639
1639
|
n.externalId
|
|
1640
1640
|
), E = Ie(
|
|
1641
|
-
() =>
|
|
1641
|
+
() => Bn(
|
|
1642
1642
|
l,
|
|
1643
1643
|
{
|
|
1644
1644
|
...n,
|
|
@@ -1646,8 +1646,8 @@ async function zn(e, n) {
|
|
|
1646
1646
|
callbacks: {
|
|
1647
1647
|
...n.callbacks,
|
|
1648
1648
|
onVideoIdChange: L,
|
|
1649
|
-
onMessage:
|
|
1650
|
-
onInterruptDetected:
|
|
1649
|
+
onMessage: A,
|
|
1650
|
+
onInterruptDetected: j
|
|
1651
1651
|
}
|
|
1652
1652
|
},
|
|
1653
1653
|
g,
|
|
@@ -1656,28 +1656,28 @@ async function zn(e, n) {
|
|
|
1656
1656
|
),
|
|
1657
1657
|
{
|
|
1658
1658
|
limit: 3,
|
|
1659
|
-
timeout:
|
|
1659
|
+
timeout: bt,
|
|
1660
1660
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1661
1661
|
shouldRetryFn: (w) => (w == null ? void 0 : w.message) !== "Could not connect" && w.status !== 429 && (w == null ? void 0 : w.message) !== "InsufficientCreditsError",
|
|
1662
1662
|
delayMs: 1e3
|
|
1663
1663
|
}
|
|
1664
1664
|
).catch((w) => {
|
|
1665
|
-
var R,
|
|
1666
|
-
throw
|
|
1667
|
-
}), [J, { streamingManager:
|
|
1668
|
-
|
|
1669
|
-
chatId:
|
|
1670
|
-
streamId:
|
|
1665
|
+
var R, F;
|
|
1666
|
+
throw q(O.Maintenance), (F = (R = n.callbacks).onConnectionStateChange) == null || F.call(R, b.Fail), w;
|
|
1667
|
+
}), [J, { streamingManager: x, chat: M }] = await Promise.all([C, E]);
|
|
1668
|
+
M && M.id !== ((U = t.chat) == null ? void 0 : U.id) && ((S = (ee = n.callbacks).onNewChat) == null || S.call(ee, M.id)), t.streamingManager = x, t.socketManager = J, t.chat = M, i = !1, c.enrich({
|
|
1669
|
+
chatId: M == null ? void 0 : M.id,
|
|
1670
|
+
streamId: x == null ? void 0 : x.streamId,
|
|
1671
1671
|
mode: t.chatMode
|
|
1672
|
-
}),
|
|
1672
|
+
}), q((M == null ? void 0 : M.chat_mode) ?? d);
|
|
1673
1673
|
}
|
|
1674
|
-
async function
|
|
1675
|
-
var f,
|
|
1676
|
-
(f = t.socketManager) == null || f.disconnect(), await ((
|
|
1674
|
+
async function H() {
|
|
1675
|
+
var f, C, E, J;
|
|
1676
|
+
(f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (J = (E = n.callbacks).onConnectionStateChange) == null || J.call(E, b.Disconnected);
|
|
1677
1677
|
}
|
|
1678
|
-
async function
|
|
1679
|
-
var
|
|
1680
|
-
f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !==
|
|
1678
|
+
async function q(f) {
|
|
1679
|
+
var C, E;
|
|
1680
|
+
f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await H(), (E = (C = n.callbacks).onModeChange) == null || E.call(C, f));
|
|
1681
1681
|
}
|
|
1682
1682
|
return {
|
|
1683
1683
|
agent: l,
|
|
@@ -1689,9 +1689,9 @@ async function zn(e, n) {
|
|
|
1689
1689
|
var f;
|
|
1690
1690
|
return ((f = t.streamingManager) == null ? void 0 : f.interruptAvailable) ?? !1;
|
|
1691
1691
|
},
|
|
1692
|
-
starterMessages: ((
|
|
1692
|
+
starterMessages: (($ = l.knowledge) == null ? void 0 : $.starter_message) || [],
|
|
1693
1693
|
getSTTToken: () => g.getSTTToken(l.id),
|
|
1694
|
-
changeMode:
|
|
1694
|
+
changeMode: q,
|
|
1695
1695
|
enrichAnalytics: c.enrich,
|
|
1696
1696
|
async connect() {
|
|
1697
1697
|
await k(!0), c.track("agent-chat", {
|
|
@@ -1708,24 +1708,24 @@ async function zn(e, n) {
|
|
|
1708
1708
|
mode: t.chatMode
|
|
1709
1709
|
});
|
|
1710
1710
|
} catch {
|
|
1711
|
-
await
|
|
1711
|
+
await H(), await k(!1);
|
|
1712
1712
|
}
|
|
1713
1713
|
return;
|
|
1714
1714
|
}
|
|
1715
|
-
await
|
|
1715
|
+
await H(), await k(!1), c.track("agent-chat", {
|
|
1716
1716
|
event: "reconnect",
|
|
1717
1717
|
mode: t.chatMode
|
|
1718
1718
|
});
|
|
1719
1719
|
},
|
|
1720
1720
|
async disconnect() {
|
|
1721
|
-
await
|
|
1721
|
+
await H(), c.track("agent-chat", {
|
|
1722
1722
|
event: "disconnect",
|
|
1723
1723
|
mode: t.chatMode
|
|
1724
1724
|
});
|
|
1725
1725
|
},
|
|
1726
1726
|
async publishMicrophoneStream(f) {
|
|
1727
|
-
var
|
|
1728
|
-
if (!((
|
|
1727
|
+
var C;
|
|
1728
|
+
if (!((C = t.streamingManager) != null && C.publishMicrophoneStream))
|
|
1729
1729
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1730
1730
|
return t.streamingManager.publishMicrophoneStream(f);
|
|
1731
1731
|
},
|
|
@@ -1736,8 +1736,8 @@ async function zn(e, n) {
|
|
|
1736
1736
|
return t.streamingManager.unpublishMicrophoneStream();
|
|
1737
1737
|
},
|
|
1738
1738
|
async publishCameraStream(f) {
|
|
1739
|
-
var
|
|
1740
|
-
if (!((
|
|
1739
|
+
var C;
|
|
1740
|
+
if (!((C = t.streamingManager) != null && C.publishCameraStream))
|
|
1741
1741
|
throw new Error("publishCameraStream is not available for this streaming manager");
|
|
1742
1742
|
return t.streamingManager.publishCameraStream(f);
|
|
1743
1743
|
},
|
|
@@ -1748,24 +1748,24 @@ async function zn(e, n) {
|
|
|
1748
1748
|
return t.streamingManager.unpublishCameraStream();
|
|
1749
1749
|
},
|
|
1750
1750
|
async chat(f) {
|
|
1751
|
-
var
|
|
1752
|
-
const
|
|
1751
|
+
var x, M, V, Y, Z;
|
|
1752
|
+
const C = () => {
|
|
1753
1753
|
if (nt(d))
|
|
1754
|
-
throw new
|
|
1754
|
+
throw new ue(`${d} is enabled, chat is disabled`);
|
|
1755
1755
|
if (f.length >= 800)
|
|
1756
|
-
throw new
|
|
1756
|
+
throw new ue("Message cannot be more than 800 characters");
|
|
1757
1757
|
if (f.length === 0)
|
|
1758
|
-
throw new
|
|
1759
|
-
if (t.chatMode ===
|
|
1760
|
-
throw new
|
|
1761
|
-
if (![
|
|
1758
|
+
throw new ue("Message cannot be empty");
|
|
1759
|
+
if (t.chatMode === O.Maintenance)
|
|
1760
|
+
throw new ue("Chat is in maintenance mode");
|
|
1761
|
+
if (![O.TextOnly, O.Playground].includes(t.chatMode)) {
|
|
1762
1762
|
if (!t.streamingManager)
|
|
1763
|
-
throw new
|
|
1763
|
+
throw new ue("Streaming manager is not initialized");
|
|
1764
1764
|
if (!t.chat)
|
|
1765
|
-
throw new
|
|
1765
|
+
throw new ue("Chat is not initialized");
|
|
1766
1766
|
}
|
|
1767
1767
|
}, E = async () => {
|
|
1768
|
-
var
|
|
1768
|
+
var B, U;
|
|
1769
1769
|
if (!t.chat) {
|
|
1770
1770
|
const ee = await at(
|
|
1771
1771
|
l,
|
|
@@ -1775,25 +1775,25 @@ async function zn(e, n) {
|
|
|
1775
1775
|
n.persistentChat
|
|
1776
1776
|
);
|
|
1777
1777
|
if (!ee.chat)
|
|
1778
|
-
throw new
|
|
1779
|
-
t.chat = ee.chat, (
|
|
1778
|
+
throw new vt(t.chatMode, !!n.persistentChat);
|
|
1779
|
+
t.chat = ee.chat, (U = (B = n.callbacks).onNewChat) == null || U.call(B, t.chat.id);
|
|
1780
1780
|
}
|
|
1781
1781
|
return t.chat.id;
|
|
1782
|
-
}, J = async (
|
|
1783
|
-
const ee = t.chatMode ===
|
|
1782
|
+
}, J = async (B, U) => {
|
|
1783
|
+
const ee = t.chatMode === O.Playground;
|
|
1784
1784
|
return Ie(y && !ee ? async () => {
|
|
1785
|
-
var R,
|
|
1786
|
-
return await ((
|
|
1785
|
+
var R, F;
|
|
1786
|
+
return await ((F = (R = t.streamingManager) == null ? void 0 : R.sendTextMessage) == null ? void 0 : F.call(R, f)), Promise.resolve({});
|
|
1787
1787
|
} : async () => {
|
|
1788
|
-
var R,
|
|
1788
|
+
var R, F;
|
|
1789
1789
|
return g.chat(
|
|
1790
1790
|
l.id,
|
|
1791
|
-
|
|
1791
|
+
U,
|
|
1792
1792
|
{
|
|
1793
1793
|
chatMode: t.chatMode,
|
|
1794
1794
|
streamId: (R = t.streamingManager) == null ? void 0 : R.streamId,
|
|
1795
|
-
sessionId: (
|
|
1796
|
-
messages:
|
|
1795
|
+
sessionId: (F = t.streamingManager) == null ? void 0 : F.sessionId,
|
|
1796
|
+
messages: B.map(({ matches: se, ...ce }) => ce)
|
|
1797
1797
|
},
|
|
1798
1798
|
{
|
|
1799
1799
|
...it(t.chatMode),
|
|
@@ -1803,68 +1803,68 @@ async function zn(e, n) {
|
|
|
1803
1803
|
}, {
|
|
1804
1804
|
limit: 2,
|
|
1805
1805
|
shouldRetryFn: (R) => {
|
|
1806
|
-
var
|
|
1807
|
-
const
|
|
1808
|
-
return !((
|
|
1806
|
+
var ce, ye, ve, Ce;
|
|
1807
|
+
const F = (ce = R == null ? void 0 : R.message) == null ? void 0 : ce.includes("missing or invalid session_id");
|
|
1808
|
+
return !((ye = R == null ? void 0 : R.message) == null ? void 0 : ye.includes("Stream Error")) && !F ? ((Ce = (ve = n.callbacks).onError) == null || Ce.call(ve, R), !1) : !0;
|
|
1809
1809
|
},
|
|
1810
1810
|
onRetry: async () => {
|
|
1811
|
-
await
|
|
1811
|
+
await H(), await k(!1);
|
|
1812
1812
|
}
|
|
1813
1813
|
});
|
|
1814
1814
|
};
|
|
1815
1815
|
try {
|
|
1816
|
-
z(),
|
|
1817
|
-
id:
|
|
1816
|
+
z(), C(), t.messages.push({
|
|
1817
|
+
id: le(),
|
|
1818
1818
|
role: "user",
|
|
1819
1819
|
content: f,
|
|
1820
1820
|
created_at: new Date(re.update()).toISOString()
|
|
1821
|
-
}), (
|
|
1822
|
-
const
|
|
1821
|
+
}), (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "user");
|
|
1822
|
+
const B = await E(), U = await J([...t.messages], B);
|
|
1823
1823
|
return t.messages.push({
|
|
1824
|
-
id:
|
|
1824
|
+
id: le(),
|
|
1825
1825
|
role: "assistant",
|
|
1826
|
-
content:
|
|
1826
|
+
content: U.result || "",
|
|
1827
1827
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1828
|
-
context:
|
|
1829
|
-
matches:
|
|
1828
|
+
context: U.context,
|
|
1829
|
+
matches: U.matches
|
|
1830
1830
|
}), c.track("agent-message-send", {
|
|
1831
1831
|
event: "success",
|
|
1832
1832
|
messages: t.messages.length + 1
|
|
1833
|
-
}),
|
|
1833
|
+
}), U.result && ((Y = (V = n.callbacks).onNewMessage) == null || Y.call(V, [...t.messages], "answer"), c.track("agent-message-received", {
|
|
1834
1834
|
latency: re.get(!0),
|
|
1835
1835
|
messages: t.messages.length
|
|
1836
|
-
})),
|
|
1837
|
-
} catch (
|
|
1836
|
+
})), U;
|
|
1837
|
+
} catch (B) {
|
|
1838
1838
|
throw ((Z = t.messages[t.messages.length - 1]) == null ? void 0 : Z.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
|
|
1839
1839
|
event: "error",
|
|
1840
1840
|
messages: t.messages.length
|
|
1841
|
-
}),
|
|
1841
|
+
}), B;
|
|
1842
1842
|
}
|
|
1843
1843
|
},
|
|
1844
|
-
rate(f,
|
|
1845
|
-
var
|
|
1846
|
-
const J = t.messages.find((
|
|
1844
|
+
rate(f, C, E) {
|
|
1845
|
+
var M, V, Y, Z;
|
|
1846
|
+
const J = t.messages.find((B) => B.id === f);
|
|
1847
1847
|
if (t.chat) {
|
|
1848
1848
|
if (!J)
|
|
1849
1849
|
throw new Error("Message not found");
|
|
1850
1850
|
} else throw new Error("Chat is not initialized");
|
|
1851
|
-
const
|
|
1851
|
+
const x = ((M = J.matches) == null ? void 0 : M.map((B) => [B.document_id, B.id])) ?? [];
|
|
1852
1852
|
return c.track("agent-rate", {
|
|
1853
1853
|
event: E ? "update" : "create",
|
|
1854
|
-
thumb:
|
|
1855
|
-
knowledge_id: ((
|
|
1856
|
-
matches:
|
|
1857
|
-
score:
|
|
1854
|
+
thumb: C === 1 ? "up" : "down",
|
|
1855
|
+
knowledge_id: ((V = l.knowledge) == null ? void 0 : V.id) ?? "",
|
|
1856
|
+
matches: x,
|
|
1857
|
+
score: C
|
|
1858
1858
|
}), E ? g.updateRating(l.id, t.chat.id, E, {
|
|
1859
1859
|
knowledge_id: ((Y = l.knowledge) == null ? void 0 : Y.id) ?? "",
|
|
1860
1860
|
message_id: f,
|
|
1861
|
-
matches:
|
|
1862
|
-
score:
|
|
1861
|
+
matches: x,
|
|
1862
|
+
score: C
|
|
1863
1863
|
}) : g.createRating(l.id, t.chat.id, {
|
|
1864
1864
|
knowledge_id: ((Z = l.knowledge) == null ? void 0 : Z.id) ?? "",
|
|
1865
1865
|
message_id: f,
|
|
1866
|
-
matches:
|
|
1867
|
-
score:
|
|
1866
|
+
matches: x,
|
|
1867
|
+
score: C
|
|
1868
1868
|
});
|
|
1869
1869
|
},
|
|
1870
1870
|
deleteRate(f) {
|
|
@@ -1873,8 +1873,8 @@ async function zn(e, n) {
|
|
|
1873
1873
|
return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
|
|
1874
1874
|
},
|
|
1875
1875
|
async speak(f) {
|
|
1876
|
-
var
|
|
1877
|
-
function
|
|
1876
|
+
var x, M, V;
|
|
1877
|
+
function C() {
|
|
1878
1878
|
if (typeof f == "string") {
|
|
1879
1879
|
if (!l.presenter.voice)
|
|
1880
1880
|
throw new Error("Presenter voice is not initialized");
|
|
@@ -1897,13 +1897,13 @@ async function zn(e, n) {
|
|
|
1897
1897
|
}
|
|
1898
1898
|
return f;
|
|
1899
1899
|
}
|
|
1900
|
-
const E =
|
|
1900
|
+
const E = C();
|
|
1901
1901
|
if (c.track("agent-speak", E), re.update(), t.messages && E.type === "text" && (t.messages.push({
|
|
1902
|
-
id:
|
|
1902
|
+
id: le(),
|
|
1903
1903
|
role: "assistant",
|
|
1904
1904
|
content: E.input,
|
|
1905
1905
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1906
|
-
}), (
|
|
1906
|
+
}), (M = (x = n.callbacks).onNewMessage) == null || M.call(x, [...t.messages], "answer")), Ft(t.chatMode))
|
|
1907
1907
|
return {
|
|
1908
1908
|
duration: 0,
|
|
1909
1909
|
video_id: "",
|
|
@@ -1913,36 +1913,36 @@ async function zn(e, n) {
|
|
|
1913
1913
|
throw new Error("Please connect to the agent first");
|
|
1914
1914
|
return t.streamingManager.speak({
|
|
1915
1915
|
script: E,
|
|
1916
|
-
metadata: { chat_id: (
|
|
1916
|
+
metadata: { chat_id: (V = t.chat) == null ? void 0 : V.id, agent_id: l.id }
|
|
1917
1917
|
});
|
|
1918
1918
|
},
|
|
1919
|
-
interrupt:
|
|
1919
|
+
interrupt: j
|
|
1920
1920
|
};
|
|
1921
1921
|
}
|
|
1922
1922
|
export {
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1923
|
+
W as AgentActivityState,
|
|
1924
|
+
kt as AgentStatus,
|
|
1925
|
+
vt as ChatCreationFailed,
|
|
1926
|
+
O as ChatMode,
|
|
1927
|
+
Ct as ChatModeDowngraded,
|
|
1928
1928
|
X as ChatProgress,
|
|
1929
1929
|
b as ConnectionState,
|
|
1930
1930
|
ne as ConnectivityState,
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1931
|
+
Mt as DocumentType,
|
|
1932
|
+
It as KnowledgeType,
|
|
1933
|
+
Tt as PlanGroup,
|
|
1934
|
+
At as Providers,
|
|
1935
|
+
Et as RateState,
|
|
1936
1936
|
D as StreamEvents,
|
|
1937
1937
|
ie as StreamType,
|
|
1938
1938
|
T as StreamingState,
|
|
1939
|
-
|
|
1939
|
+
Dt as Subject,
|
|
1940
1940
|
Pe as TransportProvider,
|
|
1941
|
-
|
|
1942
|
-
|
|
1941
|
+
Rt as UserPlan,
|
|
1942
|
+
ue as ValidationError,
|
|
1943
1943
|
Ze as VideoType,
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1944
|
+
_t as VoiceAccess,
|
|
1945
|
+
St as WsError,
|
|
1946
|
+
Kn as createAgentManager,
|
|
1947
|
+
zn as mapVideoType
|
|
1948
1948
|
};
|