@d-id/client-sdk 1.1.26-staging.117 → 1.1.26-staging.119
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 +388 -385
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
1
|
+
var Ve = Object.defineProperty;
|
|
2
|
+
var Oe = (e, t, i) => t in e ? Ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var fe = (e, t, i) => Oe(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
+
class pe extends Error {
|
|
5
5
|
constructor({ kind: i, description: n, error: c }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: n }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
fe(this, "kind");
|
|
8
|
+
fe(this, "description");
|
|
9
|
+
fe(this, "error");
|
|
10
10
|
this.kind = i, this.description = n, this.error = c;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class He extends
|
|
13
|
+
class He extends pe {
|
|
14
14
|
constructor(t, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,24 +18,24 @@ class He extends ge {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class qe extends
|
|
21
|
+
class qe extends pe {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class ce extends pe {
|
|
27
27
|
constructor(i, n) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
fe(this, "key");
|
|
30
30
|
this.key = n;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class Qe extends
|
|
33
|
+
class Qe extends pe {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ze = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ze || {}), Ge = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ge || {}),
|
|
38
|
+
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ze = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ze || {}), Ge = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ge || {}), J = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(J || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(tt || {}), nt = /* @__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))(nt || {}), Be = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Be || {});
|
|
39
39
|
const dn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -48,11 +48,11 @@ const dn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}),
|
|
52
|
-
const at = 45 * 1e3, ot = "X-Playground-Chat",
|
|
51
|
+
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), G = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(G || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(ae || {}), z = /* @__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))(z || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), te = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(te || {}), we = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(we || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), it = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(it || {});
|
|
52
|
+
const at = 45 * 1e3, ot = "X-Playground-Chat", ge = "https://api.d-id.com", st = "wss://notifications.d-id.com", ct = "79f81a83a67430be2bc0fd61042b8faa", Fe = (e) => new Promise((t) => setTimeout(t, e)), de = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
54
|
return window.crypto.getRandomValues(t), Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
-
}, ze = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ee = (e) => e === Be.Expressive, dt = (e) => [
|
|
55
|
+
}, ze = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ee = (e) => e === Be.Expressive, dt = (e) => [J.TextOnly, J.Playground, J.Maintenance].includes(e), Ne = (e) => e && [J.DirectPlayback, J.Off].includes(e);
|
|
56
56
|
function ut(e, t) {
|
|
57
57
|
let i;
|
|
58
58
|
return {
|
|
@@ -62,7 +62,7 @@ function ut(e, t) {
|
|
|
62
62
|
clear: () => clearTimeout(i)
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
async function
|
|
65
|
+
async function Se(e, t) {
|
|
66
66
|
const i = {
|
|
67
67
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
68
68
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
@@ -86,33 +86,33 @@ async function ve(e, t) {
|
|
|
86
86
|
}
|
|
87
87
|
throw n;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function Ce(e) {
|
|
90
90
|
if (e !== void 0)
|
|
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 i =
|
|
94
|
+
let i = de();
|
|
95
95
|
window.localStorage.setItem("did_external_key_id", i), t = i;
|
|
96
96
|
}
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
|
-
let lt =
|
|
99
|
+
let lt = de();
|
|
100
100
|
function Ke(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}.${
|
|
106
|
+
return `Client-Key ${e.clientKey}.${Ce(t)}_${lt}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const ft = (e) =>
|
|
109
|
+
const ft = (e) => Se(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 Ie(e, t = ge, i, n) {
|
|
116
116
|
const c = async (o, s) => {
|
|
117
117
|
const { skipErrorHandler: a, ...r } = s || {}, d = await ft(
|
|
118
118
|
() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
@@ -146,8 +146,8 @@ function Me(e, t = fe, i, n) {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function mt(e, t =
|
|
150
|
-
const c =
|
|
149
|
+
function mt(e, t = ge, i, n) {
|
|
150
|
+
const c = Ie(e, `${t}/agents`, i, n);
|
|
151
151
|
return {
|
|
152
152
|
create(o, s) {
|
|
153
153
|
return c.post("/", o, s);
|
|
@@ -240,20 +240,20 @@ function wt(e, t, i) {
|
|
|
240
240
|
function be(e) {
|
|
241
241
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
242
|
}
|
|
243
|
-
let
|
|
243
|
+
let ye = {};
|
|
244
244
|
const yt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
245
245
|
function vt(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",
|
|
249
|
-
distinct_id:
|
|
249
|
+
distinct_id: Ce(e.externalId),
|
|
250
250
|
agentId: e.agentId,
|
|
251
251
|
additionalProperties: {
|
|
252
|
-
id:
|
|
252
|
+
id: Ce(e.externalId),
|
|
253
253
|
...e.mixpanelAdditionalProperties || {}
|
|
254
254
|
},
|
|
255
255
|
isEnabled: e.isEnabled ?? !0,
|
|
256
|
-
getRandom:
|
|
256
|
+
getRandom: de,
|
|
257
257
|
enrich(i) {
|
|
258
258
|
this.additionalProperties = { ...this.additionalProperties, ...i };
|
|
259
259
|
},
|
|
@@ -292,8 +292,8 @@ function vt(e) {
|
|
|
292
292
|
}).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
|
|
293
293
|
},
|
|
294
294
|
linkTrack(i, n, c, o) {
|
|
295
|
-
|
|
296
|
-
const s =
|
|
295
|
+
ye[i] || (ye[i] = { events: {}, resolvedDependencies: [] }), o.includes(c) || o.push(c);
|
|
296
|
+
const s = ye[i];
|
|
297
297
|
if (s.events[c] = { props: n }, s.resolvedDependencies.push(c), o.every(
|
|
298
298
|
(r) => s.resolvedDependencies.includes(r)
|
|
299
299
|
)) {
|
|
@@ -307,7 +307,7 @@ function vt(e) {
|
|
|
307
307
|
}
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
function
|
|
310
|
+
function Te() {
|
|
311
311
|
let e = 0;
|
|
312
312
|
return {
|
|
313
313
|
reset: () => e = 0,
|
|
@@ -315,9 +315,9 @@ function Ie() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const
|
|
318
|
+
const ee = Te(), ke = Te(), je = Te();
|
|
319
319
|
function Je(e) {
|
|
320
|
-
return e ===
|
|
320
|
+
return e === J.Playground ? { headers: { [ot]: "true" } } : {};
|
|
321
321
|
}
|
|
322
322
|
async function Ue(e, t, i, n, c = !1, o) {
|
|
323
323
|
try {
|
|
@@ -342,7 +342,7 @@ function Ct(e) {
|
|
|
342
342
|
return e && e.length > 0 ? e : [];
|
|
343
343
|
}
|
|
344
344
|
function kt(e, t, i, n) {
|
|
345
|
-
const c =
|
|
345
|
+
const c = Ie(e, `${t}/v2/agents/${i}`, n);
|
|
346
346
|
return {
|
|
347
347
|
async createStream(o) {
|
|
348
348
|
return c.post("/sessions", o);
|
|
@@ -350,7 +350,7 @@ function kt(e, t, i, n) {
|
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
352
|
const We = (e, t) => (i, n) => e && console.log(`[${t}] ${i}`, n ?? "");
|
|
353
|
-
async function
|
|
353
|
+
async function ve() {
|
|
354
354
|
try {
|
|
355
355
|
return await import("./livekit-client.esm-C1GRQdZY.js");
|
|
356
356
|
} catch {
|
|
@@ -360,92 +360,92 @@ async function ye() {
|
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
const Rt = {
|
|
363
|
-
excellent:
|
|
364
|
-
good:
|
|
365
|
-
poor:
|
|
366
|
-
lost:
|
|
367
|
-
unknown:
|
|
368
|
-
},
|
|
363
|
+
excellent: G.Strong,
|
|
364
|
+
good: G.Strong,
|
|
365
|
+
poor: G.Weak,
|
|
366
|
+
lost: G.Unknown,
|
|
367
|
+
unknown: G.Unknown
|
|
368
|
+
}, me = JSON.stringify({
|
|
369
369
|
kind: "InternalServerError",
|
|
370
370
|
description: "Stream Error"
|
|
371
371
|
});
|
|
372
|
-
var
|
|
373
|
-
function
|
|
372
|
+
var _e = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(_e || {});
|
|
373
|
+
function Re(e, t, i, n) {
|
|
374
374
|
var c, o;
|
|
375
375
|
throw t("Failed to connect to LiveKit room:", e), n(), (c = i.onConnectionStateChange) == null || c.call(i, S.Fail), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
|
|
376
376
|
}
|
|
377
377
|
async function Dt(e, t, i) {
|
|
378
|
-
var
|
|
379
|
-
const n = We(i.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await
|
|
380
|
-
let u = null,
|
|
381
|
-
const x =
|
|
382
|
-
let
|
|
378
|
+
var ue, Ae;
|
|
379
|
+
const n = We(i.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await ve(), { callbacks: a, auth: r, baseURL: d, analytics: m, microphoneStream: p } = i;
|
|
380
|
+
let u = null, E = !1;
|
|
381
|
+
const x = te.Fluent;
|
|
382
|
+
let V = !0, I = null, A = null;
|
|
383
383
|
u = new c({
|
|
384
384
|
adaptiveStream: !1,
|
|
385
385
|
// Must be false to use mediaStreamTrack directly
|
|
386
386
|
dynacast: !0
|
|
387
387
|
});
|
|
388
388
|
let L = null;
|
|
389
|
-
const T = 2e4,
|
|
390
|
-
let B,
|
|
389
|
+
const T = 2e4, ne = kt(r, d || ge, e, a.onError);
|
|
390
|
+
let B, N, X;
|
|
391
391
|
try {
|
|
392
|
-
const l = await
|
|
393
|
-
transport_provider:
|
|
392
|
+
const l = await ne.createStream({
|
|
393
|
+
transport_provider: we.Livekit,
|
|
394
394
|
chat_persist: t.chat_persist ?? !0
|
|
395
|
-
}), { id:
|
|
396
|
-
(
|
|
395
|
+
}), { id: h, session_token: v, session_url: k } = l;
|
|
396
|
+
(ue = a.onStreamCreated) == null || ue.call(a, { session_id: h, stream_id: h, agent_id: e }), B = h, N = v, X = k, await u.prepareConnection(X, N);
|
|
397
397
|
} catch (l) {
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
Re(l, n, a, () => {
|
|
399
|
+
V = !1;
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
|
-
if (!X || !
|
|
402
|
+
if (!X || !N || !B)
|
|
403
403
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
404
|
-
u.on(o.ConnectionStateChanged, f).on(o.ConnectionQualityChanged, R).on(o.ActiveSpeakersChanged,
|
|
404
|
+
u.on(o.ConnectionStateChanged, f).on(o.ConnectionQualityChanged, R).on(o.ActiveSpeakersChanged, w).on(o.ParticipantConnected, $).on(o.ParticipantDisconnected, D).on(o.TrackSubscribed, _).on(o.TrackUnsubscribed, U).on(o.DataReceived, H).on(o.MediaDevicesError, q).on(o.EncryptionError, b).on(o.TrackSubscriptionFailed, K), (Ae = a.onConnectionStateChange) == null || Ae.call(a, S.New);
|
|
405
405
|
try {
|
|
406
|
-
await u.connect(X,
|
|
406
|
+
await u.connect(X, N), n("LiveKit room joined successfully"), L = setTimeout(() => {
|
|
407
407
|
var l;
|
|
408
408
|
n("Track subscription timeout - no track subscribed within 30 seconds after connect"), L = null, m.track("connectivity-error", {
|
|
409
409
|
error: "Track subscription timeout",
|
|
410
410
|
sessionId: B
|
|
411
|
-
}), (l = a.onError) == null || l.call(a, new Error("Track subscription timeout"), { sessionId: B }),
|
|
412
|
-
}, T),
|
|
411
|
+
}), (l = a.onError) == null || l.call(a, new Error("Track subscription timeout"), { sessionId: B }), se();
|
|
412
|
+
}, T), V = !1;
|
|
413
413
|
} catch (l) {
|
|
414
|
-
|
|
415
|
-
|
|
414
|
+
Re(l, n, a, () => {
|
|
415
|
+
V = !1;
|
|
416
416
|
});
|
|
417
417
|
}
|
|
418
418
|
m.enrich({
|
|
419
419
|
"stream-type": x
|
|
420
420
|
});
|
|
421
421
|
function f(l) {
|
|
422
|
-
var
|
|
422
|
+
var h, v, k, P, O;
|
|
423
423
|
switch (n("Connection state changed:", l), l) {
|
|
424
424
|
case s.Connecting:
|
|
425
|
-
(
|
|
425
|
+
(h = a.onConnectionStateChange) == null || h.call(a, S.Connecting);
|
|
426
426
|
break;
|
|
427
427
|
case s.Connected:
|
|
428
|
-
n("LiveKit room connected successfully"),
|
|
429
|
-
var
|
|
430
|
-
(
|
|
428
|
+
n("LiveKit room connected successfully"), E = !0, V ? queueMicrotask(() => {
|
|
429
|
+
var F;
|
|
430
|
+
(F = a.onConnectionStateChange) == null || F.call(a, S.Connected);
|
|
431
431
|
}) : (v = a.onConnectionStateChange) == null || v.call(a, S.Connected);
|
|
432
432
|
break;
|
|
433
433
|
case s.Disconnected:
|
|
434
|
-
n("LiveKit room disconnected"),
|
|
434
|
+
n("LiveKit room disconnected"), E = !1, (k = a.onConnectionStateChange) == null || k.call(a, S.Disconnected);
|
|
435
435
|
break;
|
|
436
436
|
case s.Reconnecting:
|
|
437
|
-
n("LiveKit room reconnecting..."), (
|
|
437
|
+
n("LiveKit room reconnecting..."), (P = a.onConnectionStateChange) == null || P.call(a, S.Connecting);
|
|
438
438
|
break;
|
|
439
439
|
case s.SignalReconnecting:
|
|
440
|
-
n("LiveKit room signal reconnecting..."), (
|
|
440
|
+
n("LiveKit room signal reconnecting..."), (O = a.onConnectionStateChange) == null || O.call(a, S.Connecting);
|
|
441
441
|
break;
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
-
function R(l,
|
|
444
|
+
function R(l, h) {
|
|
445
445
|
var v;
|
|
446
|
-
n("Connection quality:", l),
|
|
446
|
+
n("Connection quality:", l), h != null && h.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a, Rt[l]));
|
|
447
447
|
}
|
|
448
|
-
function
|
|
448
|
+
function w(l) {
|
|
449
449
|
var v, k;
|
|
450
450
|
n("Active speakers changed:", l), l[0] ? (v = a.onAgentActivityStateChange) == null || v.call(a, ae.Talking) : (k = a.onAgentActivityStateChange) == null || k.call(a, ae.Idle);
|
|
451
451
|
}
|
|
@@ -453,42 +453,42 @@ async function Dt(e, t, i) {
|
|
|
453
453
|
n("Participant connected:", l.identity);
|
|
454
454
|
}
|
|
455
455
|
function D(l) {
|
|
456
|
-
n("Participant disconnected:", l.identity),
|
|
456
|
+
n("Participant disconnected:", l.identity), se();
|
|
457
457
|
}
|
|
458
|
-
function _(l,
|
|
459
|
-
var
|
|
458
|
+
function _(l, h, v) {
|
|
459
|
+
var P, O, F;
|
|
460
460
|
n(`Track subscribed: ${l.kind} from ${v.identity}`), L && (clearTimeout(L), L = null, n("Track subscription timeout cleared"));
|
|
461
461
|
const k = l.mediaStreamTrack;
|
|
462
462
|
if (!k) {
|
|
463
463
|
n(`No mediaStreamTrack available for ${l.kind}`);
|
|
464
464
|
return;
|
|
465
465
|
}
|
|
466
|
-
I ? (I.addTrack(k), n(`Added ${l.kind} track to shared MediaStream`)) : (I = new MediaStream([k]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((
|
|
466
|
+
I ? (I.addTrack(k), n(`Added ${l.kind} track to shared MediaStream`)) : (I = new MediaStream([k]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((P = a.onStreamReady) == null || P.call(a), (O = a.onSrcObjectReady) == null || O.call(a, I), (F = a.onVideoStateChange) == null || F.call(a, C.Start));
|
|
467
467
|
}
|
|
468
|
-
function
|
|
468
|
+
function U(l, h, v) {
|
|
469
469
|
var k;
|
|
470
470
|
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((k = a.onVideoStateChange) == null || k.call(a, C.Stop));
|
|
471
471
|
}
|
|
472
|
-
function H(l,
|
|
473
|
-
var
|
|
474
|
-
const
|
|
475
|
-
n("Data received:",
|
|
472
|
+
function H(l, h, v, k) {
|
|
473
|
+
var O, F, le;
|
|
474
|
+
const P = new TextDecoder().decode(l);
|
|
475
|
+
n("Data received:", P);
|
|
476
476
|
try {
|
|
477
|
-
const ie = JSON.parse(
|
|
478
|
-
if (
|
|
477
|
+
const ie = JSON.parse(P), he = k || ie.subject;
|
|
478
|
+
if (he === z.ChatAnswer) {
|
|
479
479
|
const oe = Y.Answer;
|
|
480
|
-
(
|
|
480
|
+
(O = a.onMessage) == null || O.call(a, oe, {
|
|
481
481
|
event: oe,
|
|
482
482
|
...ie
|
|
483
483
|
});
|
|
484
|
-
} else if ([
|
|
485
|
-
const oe = (ie == null ? void 0 : ie.role) || (
|
|
486
|
-
(
|
|
484
|
+
} else if ([z.StreamVideoCreated, z.StreamVideoDone].includes(he)) {
|
|
485
|
+
const oe = (ie == null ? void 0 : ie.role) || (h == null ? void 0 : h.identity) || "datachannel";
|
|
486
|
+
(F = a.onMessage) == null || F.call(a, he, {
|
|
487
487
|
[oe]: ie
|
|
488
488
|
});
|
|
489
|
-
} else if (
|
|
489
|
+
} else if (he === z.ChatAudioTranscribed) {
|
|
490
490
|
const oe = Y.Transcribe;
|
|
491
|
-
(
|
|
491
|
+
(le = a.onMessage) == null || le.call(a, oe, {
|
|
492
492
|
event: oe,
|
|
493
493
|
...ie
|
|
494
494
|
});
|
|
@@ -498,62 +498,62 @@ async function Dt(e, t, i) {
|
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
function q(l) {
|
|
501
|
-
var
|
|
502
|
-
n("Media devices error:", l), (
|
|
501
|
+
var h;
|
|
502
|
+
n("Media devices error:", l), (h = a.onError) == null || h.call(a, new Error(me), { sessionId: B });
|
|
503
503
|
}
|
|
504
|
-
function
|
|
505
|
-
var
|
|
506
|
-
n("Encryption error:", l), (
|
|
504
|
+
function b(l) {
|
|
505
|
+
var h;
|
|
506
|
+
n("Encryption error:", l), (h = a.onError) == null || h.call(a, new Error(me), { sessionId: B });
|
|
507
507
|
}
|
|
508
|
-
function
|
|
509
|
-
n("Track subscription failed:", { trackSid: l, participant:
|
|
508
|
+
function K(l, h, v) {
|
|
509
|
+
n("Track subscription failed:", { trackSid: l, participant: h, reason: v });
|
|
510
510
|
}
|
|
511
|
-
async function
|
|
511
|
+
async function Z(l) {
|
|
512
512
|
if (!u) return null;
|
|
513
|
-
const { Track:
|
|
513
|
+
const { Track: h } = await ve(), v = u.localParticipant.audioTrackPublications;
|
|
514
514
|
if (v) {
|
|
515
|
-
for (const [k,
|
|
516
|
-
if (
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
519
|
-
return
|
|
515
|
+
for (const [k, P] of v)
|
|
516
|
+
if (P.source === h.Source.Microphone && P.track) {
|
|
517
|
+
const F = P.track.mediaStreamTrack;
|
|
518
|
+
if (F === l || F && F.id === l.id)
|
|
519
|
+
return P;
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
522
|
return null;
|
|
523
523
|
}
|
|
524
|
-
function
|
|
524
|
+
function re(l) {
|
|
525
525
|
if (!A || !A.track)
|
|
526
526
|
return !1;
|
|
527
|
-
const
|
|
528
|
-
return
|
|
527
|
+
const h = A.track.mediaStreamTrack;
|
|
528
|
+
return h !== l && (h == null ? void 0 : h.id) !== l.id;
|
|
529
529
|
}
|
|
530
|
-
async function
|
|
531
|
-
var
|
|
532
|
-
if (!
|
|
530
|
+
async function W(l) {
|
|
531
|
+
var O, F;
|
|
532
|
+
if (!E || !u)
|
|
533
533
|
throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
|
|
534
|
-
const
|
|
535
|
-
if (
|
|
534
|
+
const h = l.getAudioTracks();
|
|
535
|
+
if (h.length === 0) {
|
|
536
536
|
n("No audio track found in the provided MediaStream");
|
|
537
537
|
return;
|
|
538
538
|
}
|
|
539
|
-
const v =
|
|
540
|
-
if (
|
|
539
|
+
const v = h[0], { Track: k } = await ve(), P = await Z(v);
|
|
540
|
+
if (P) {
|
|
541
541
|
n("Microphone track is already published, skipping", {
|
|
542
542
|
trackId: v.id,
|
|
543
|
-
publishedTrackId: (
|
|
544
|
-
}), A =
|
|
543
|
+
publishedTrackId: (F = (O = P.track) == null ? void 0 : O.mediaStreamTrack) == null ? void 0 : F.id
|
|
544
|
+
}), A = P;
|
|
545
545
|
return;
|
|
546
546
|
}
|
|
547
|
-
|
|
547
|
+
re(v) && (n("Unpublishing existing microphone track before publishing new one"), await M()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
|
|
548
548
|
try {
|
|
549
549
|
A = await u.localParticipant.publishTrack(v, {
|
|
550
550
|
source: k.Source.Microphone
|
|
551
551
|
}), n("Microphone track published successfully", { trackSid: A.trackSid });
|
|
552
|
-
} catch (
|
|
553
|
-
throw n("Failed to publish microphone track:",
|
|
552
|
+
} catch (le) {
|
|
553
|
+
throw n("Failed to publish microphone track:", le), le;
|
|
554
554
|
}
|
|
555
555
|
}
|
|
556
|
-
async function
|
|
556
|
+
async function M() {
|
|
557
557
|
if (!(!A || !A.track))
|
|
558
558
|
try {
|
|
559
559
|
u && (await u.localParticipant.unpublishTrack(A.track), n("Microphone track unpublished"));
|
|
@@ -563,84 +563,84 @@ async function Dt(e, t, i) {
|
|
|
563
563
|
A = null;
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
function
|
|
566
|
+
function g() {
|
|
567
567
|
I && (I.getTracks().forEach((l) => l.stop()), I = null);
|
|
568
568
|
}
|
|
569
|
-
async function
|
|
569
|
+
async function y(l, h) {
|
|
570
570
|
var v, k;
|
|
571
|
-
if (!
|
|
572
|
-
n("Room is not connected for sending messages"), (v = a.onError) == null || v.call(a, new Error(
|
|
571
|
+
if (!E || !u) {
|
|
572
|
+
n("Room is not connected for sending messages"), (v = a.onError) == null || v.call(a, new Error(me), {
|
|
573
573
|
sessionId: B
|
|
574
574
|
});
|
|
575
575
|
return;
|
|
576
576
|
}
|
|
577
577
|
try {
|
|
578
|
-
await u.localParticipant.sendText(l, { topic:
|
|
579
|
-
} catch (
|
|
580
|
-
n("Failed to send message:",
|
|
578
|
+
await u.localParticipant.sendText(l, { topic: h }), n("Message sent successfully:", l);
|
|
579
|
+
} catch (P) {
|
|
580
|
+
n("Failed to send message:", P), (k = a.onError) == null || k.call(a, new Error(me), { sessionId: B });
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
|
-
async function
|
|
584
|
-
var
|
|
583
|
+
async function j(l) {
|
|
584
|
+
var h;
|
|
585
585
|
try {
|
|
586
586
|
const k = JSON.parse(l).topic;
|
|
587
|
-
return
|
|
587
|
+
return y("", k);
|
|
588
588
|
} catch (v) {
|
|
589
|
-
n("Failed to send data channel message:", v), (
|
|
589
|
+
n("Failed to send data channel message:", v), (h = a.onError) == null || h.call(a, new Error(me), { sessionId: B });
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
592
|
function Q(l) {
|
|
593
|
-
return
|
|
593
|
+
return y(
|
|
594
594
|
l,
|
|
595
595
|
"lk.chat"
|
|
596
596
|
/* Chat */
|
|
597
597
|
);
|
|
598
598
|
}
|
|
599
|
-
async function
|
|
600
|
-
var l,
|
|
601
|
-
L && (clearTimeout(L), L = null), u && (await
|
|
599
|
+
async function se() {
|
|
600
|
+
var l, h;
|
|
601
|
+
L && (clearTimeout(L), L = null), u && (await M(), await u.disconnect()), g(), E = !1, (l = a.onConnectionStateChange) == null || l.call(a, S.Disconnected), (h = a.onAgentActivityStateChange) == null || h.call(a, ae.Idle);
|
|
602
602
|
}
|
|
603
603
|
return {
|
|
604
604
|
speak(l) {
|
|
605
|
-
const
|
|
606
|
-
return
|
|
607
|
-
|
|
605
|
+
const h = typeof l == "string" ? l : JSON.stringify(l);
|
|
606
|
+
return y(
|
|
607
|
+
h,
|
|
608
608
|
"did.speak"
|
|
609
609
|
/* Speak */
|
|
610
610
|
);
|
|
611
611
|
},
|
|
612
|
-
disconnect:
|
|
612
|
+
disconnect: se,
|
|
613
613
|
async reconnect() {
|
|
614
|
-
var l,
|
|
614
|
+
var l, h, v;
|
|
615
615
|
if ((u == null ? void 0 : u.state) === s.Connected) {
|
|
616
616
|
n("Room is already connected");
|
|
617
617
|
return;
|
|
618
618
|
}
|
|
619
|
-
if (!u || !X || !
|
|
619
|
+
if (!u || !X || !N)
|
|
620
620
|
throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
621
621
|
n("Reconnecting to LiveKit room, state:", u.state), (l = a.onConnectionStateChange) == null || l.call(a, S.Connecting);
|
|
622
622
|
try {
|
|
623
|
-
if (await u.connect(X,
|
|
624
|
-
if (n("Waiting for agent to join..."), !await new Promise((
|
|
625
|
-
const
|
|
626
|
-
u == null || u.off(o.ParticipantConnected,
|
|
627
|
-
}, 5e3),
|
|
628
|
-
clearTimeout(
|
|
623
|
+
if (await u.connect(X, N), n("Room reconnected"), E = !0, u.remoteParticipants.size === 0) {
|
|
624
|
+
if (n("Waiting for agent to join..."), !await new Promise((P) => {
|
|
625
|
+
const O = setTimeout(() => {
|
|
626
|
+
u == null || u.off(o.ParticipantConnected, F), P(!1);
|
|
627
|
+
}, 5e3), F = () => {
|
|
628
|
+
clearTimeout(O), u == null || u.off(o.ParticipantConnected, F), P(!0);
|
|
629
629
|
};
|
|
630
|
-
u == null || u.on(o.ParticipantConnected,
|
|
630
|
+
u == null || u.on(o.ParticipantConnected, F);
|
|
631
631
|
}))
|
|
632
632
|
throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
|
|
633
633
|
n("Agent joined");
|
|
634
634
|
}
|
|
635
|
-
(
|
|
635
|
+
(h = a.onConnectionStateChange) == null || h.call(a, S.Connected);
|
|
636
636
|
} catch (k) {
|
|
637
637
|
throw n("Failed to reconnect:", k), (v = a.onConnectionStateChange) == null || v.call(a, S.Fail), k;
|
|
638
638
|
}
|
|
639
639
|
},
|
|
640
|
-
sendDataChannelMessage:
|
|
640
|
+
sendDataChannelMessage: j,
|
|
641
641
|
sendTextMessage: Q,
|
|
642
|
-
publishMicrophoneStream:
|
|
643
|
-
unpublishMicrophoneStream:
|
|
642
|
+
publishMicrophoneStream: W,
|
|
643
|
+
unpublishMicrophoneStream: M,
|
|
644
644
|
sessionId: B,
|
|
645
645
|
streamId: B,
|
|
646
646
|
streamType: x,
|
|
@@ -648,25 +648,25 @@ async function Dt(e, t, i) {
|
|
|
648
648
|
triggersAvailable: !1
|
|
649
649
|
};
|
|
650
650
|
}
|
|
651
|
-
const
|
|
651
|
+
const Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
652
652
|
__proto__: null,
|
|
653
|
-
DataChannelTopic:
|
|
653
|
+
DataChannelTopic: _e,
|
|
654
654
|
createLiveKitStreamingManager: Dt,
|
|
655
|
-
handleInitError:
|
|
655
|
+
handleInitError: Re
|
|
656
656
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
657
|
-
function
|
|
657
|
+
function Et(e, t, i) {
|
|
658
658
|
if (!e)
|
|
659
659
|
throw new Error("Please connect to the agent first");
|
|
660
660
|
if (!e.interruptAvailable)
|
|
661
661
|
throw new Error("Interrupt is not enabled for this stream");
|
|
662
|
-
if (t !==
|
|
662
|
+
if (t !== te.Fluent)
|
|
663
663
|
throw new Error("Interrupt only available for Fluent streams");
|
|
664
664
|
if (!i)
|
|
665
665
|
throw new Error("No active video to interrupt");
|
|
666
666
|
}
|
|
667
667
|
async function It(e, t) {
|
|
668
668
|
const i = {
|
|
669
|
-
type:
|
|
669
|
+
type: z.StreamInterrupt,
|
|
670
670
|
videoId: t,
|
|
671
671
|
timestamp: Date.now()
|
|
672
672
|
};
|
|
@@ -674,7 +674,7 @@ async function It(e, t) {
|
|
|
674
674
|
}
|
|
675
675
|
async function Tt(e) {
|
|
676
676
|
const t = {
|
|
677
|
-
topic:
|
|
677
|
+
topic: _e.Interrupt
|
|
678
678
|
};
|
|
679
679
|
e.sendDataChannelMessage(JSON.stringify(t));
|
|
680
680
|
}
|
|
@@ -777,18 +777,18 @@ function $t(e, t, i, n, c) {
|
|
|
777
777
|
onMessage: (s, a) => {
|
|
778
778
|
var r, d;
|
|
779
779
|
if ("content" in a) {
|
|
780
|
-
const m = s ===
|
|
780
|
+
const m = s === z.ChatAnswer ? Y.Answer : s === z.ChatAudioTranscribed ? Y.Transcribe : s;
|
|
781
781
|
Lt(m, a, o, t, i.callbacks.onNewMessage), m === Y.Answer && e.track("agent-message-received", {
|
|
782
782
|
messages: t.messages.length,
|
|
783
783
|
mode: t.chatMode
|
|
784
784
|
});
|
|
785
785
|
} else {
|
|
786
|
-
const m =
|
|
786
|
+
const m = z, p = [m.StreamVideoDone, m.StreamVideoError, m.StreamVideoRejected], u = [m.StreamFailed, m.StreamVideoError, m.StreamVideoRejected], E = wt(a, n, { mode: t.chatMode });
|
|
787
787
|
if (s = s, s === m.StreamVideoCreated)
|
|
788
|
-
e.linkTrack("agent-video",
|
|
788
|
+
e.linkTrack("agent-video", E, m.StreamVideoCreated, ["start"]);
|
|
789
789
|
else if (p.includes(s)) {
|
|
790
790
|
const x = s.split("/")[1];
|
|
791
|
-
u.includes(s) ? e.track("agent-video", { ...
|
|
791
|
+
u.includes(s) ? e.track("agent-video", { ...E, event: x }) : e.linkTrack("agent-video", { ...E, event: x }, s, ["done"]);
|
|
792
792
|
}
|
|
793
793
|
u.includes(s) && ((d = (r = i.callbacks).onError) == null || d.call(r, new Error(`Stream failed with event ${s}`), { data: a })), a.event === m.StreamDone && c();
|
|
794
794
|
}
|
|
@@ -796,7 +796,7 @@ function $t(e, t, i, n, c) {
|
|
|
796
796
|
};
|
|
797
797
|
}
|
|
798
798
|
function xt(e, t, i, n) {
|
|
799
|
-
const c =
|
|
799
|
+
const c = Ie(e, `${t}/agents/${i}`, n);
|
|
800
800
|
return {
|
|
801
801
|
createStream(o, s) {
|
|
802
802
|
return c.post("/streams", o, { signal: s });
|
|
@@ -961,7 +961,7 @@ function Nt(e, t, i) {
|
|
|
961
961
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
962
962
|
};
|
|
963
963
|
}
|
|
964
|
-
const
|
|
964
|
+
const De = 100, Kt = Math.max(Math.ceil(400 / De), 1), Jt = 0.25, Ut = 0.28;
|
|
965
965
|
function Wt() {
|
|
966
966
|
let e = 0, t, i, n = 0;
|
|
967
967
|
return (c) => {
|
|
@@ -979,20 +979,20 @@ function Wt() {
|
|
|
979
979
|
return { isReceiving: !1, avgJitterDelayInInterval: n };
|
|
980
980
|
};
|
|
981
981
|
}
|
|
982
|
-
function
|
|
983
|
-
let o = [], s, a = 0, r = !1, d =
|
|
984
|
-
const
|
|
982
|
+
function Vt(e, t, i, n, c) {
|
|
983
|
+
let o = [], s, a = 0, r = !1, d = G.Unknown, m = G.Unknown, p = 0, u = 0;
|
|
984
|
+
const E = Wt();
|
|
985
985
|
return setInterval(async () => {
|
|
986
|
-
const x = await e.getStats(), { isReceiving:
|
|
987
|
-
if (
|
|
988
|
-
a = 0, p = A - u, m = I < Jt ?
|
|
986
|
+
const x = await e.getStats(), { isReceiving: V, avgJitterDelayInInterval: I, freezeCount: A } = E(x), L = zt(x);
|
|
987
|
+
if (V)
|
|
988
|
+
a = 0, p = A - u, m = I < Jt ? G.Strong : I > Ut && p > 1 ? G.Weak : d, m !== d && (c == null || c(m), d = m, u += p, p = 0), r || (n == null || n(C.Start), s = o[o.length - 1], o = [], r = !0), o.push(L);
|
|
989
989
|
else if (r && (a++, a >= Kt)) {
|
|
990
|
-
const T = Nt(o,
|
|
990
|
+
const T = Nt(o, De, s);
|
|
991
991
|
n == null || n(C.Stop, T), t() || i(), u = A, r = !1;
|
|
992
992
|
}
|
|
993
|
-
},
|
|
993
|
+
}, De);
|
|
994
994
|
}
|
|
995
|
-
const
|
|
995
|
+
const Ot = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
996
996
|
function Le(e) {
|
|
997
997
|
switch (e) {
|
|
998
998
|
case "connected":
|
|
@@ -1047,7 +1047,7 @@ function $e({
|
|
|
1047
1047
|
streamType: c,
|
|
1048
1048
|
report: o
|
|
1049
1049
|
}) {
|
|
1050
|
-
c ===
|
|
1050
|
+
c === te.Legacy ? qt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o }) : c === te.Fluent && Qt({
|
|
1051
1051
|
statsSignal: e,
|
|
1052
1052
|
dataChannelSignal: t,
|
|
1053
1053
|
onVideoStateChange: i,
|
|
@@ -1055,165 +1055,165 @@ function $e({
|
|
|
1055
1055
|
report: o
|
|
1056
1056
|
});
|
|
1057
1057
|
}
|
|
1058
|
-
async function Xt(e, t, { debug: i = !1, callbacks: n, auth: c, baseURL: o =
|
|
1059
|
-
var
|
|
1058
|
+
async function Xt(e, t, { debug: i = !1, callbacks: n, auth: c, baseURL: o = ge, analytics: s }, a) {
|
|
1059
|
+
var M;
|
|
1060
1060
|
const r = We(i, "WebRTCStreamingManager"), d = Ht(r);
|
|
1061
|
-
let m = !1, p = !1, u = C.Stop,
|
|
1062
|
-
const { startConnection: x, sendStreamRequest:
|
|
1061
|
+
let m = !1, p = !1, u = C.Stop, E = C.Stop;
|
|
1062
|
+
const { startConnection: x, sendStreamRequest: V, close: I, createStream: A, addIceCandidate: L } = xt(
|
|
1063
1063
|
c,
|
|
1064
1064
|
o,
|
|
1065
1065
|
e,
|
|
1066
1066
|
n.onError
|
|
1067
1067
|
), {
|
|
1068
1068
|
id: T,
|
|
1069
|
-
offer:
|
|
1069
|
+
offer: ne,
|
|
1070
1070
|
ice_servers: B,
|
|
1071
|
-
session_id:
|
|
1071
|
+
session_id: N,
|
|
1072
1072
|
fluent: X,
|
|
1073
1073
|
interrupt_enabled: f,
|
|
1074
1074
|
triggers_enabled: R
|
|
1075
1075
|
} = await A(t, a);
|
|
1076
|
-
(
|
|
1077
|
-
const
|
|
1078
|
-
if (!
|
|
1076
|
+
(M = n.onStreamCreated) == null || M.call(n, { stream_id: T, session_id: N, agent_id: e });
|
|
1077
|
+
const w = new Ot({ iceServers: B }), $ = w.createDataChannel("JanusDataChannel");
|
|
1078
|
+
if (!N)
|
|
1079
1079
|
throw new Error("Could not create session_id");
|
|
1080
|
-
const D = X ?
|
|
1080
|
+
const D = X ? te.Fluent : te.Legacy;
|
|
1081
1081
|
s.enrich({
|
|
1082
1082
|
"stream-type": D
|
|
1083
1083
|
});
|
|
1084
|
-
const _ = t.stream_warmup && !X,
|
|
1085
|
-
var
|
|
1086
|
-
m = !0, p && ((
|
|
1087
|
-
}, q =
|
|
1088
|
-
|
|
1089
|
-
|
|
1084
|
+
const _ = t.stream_warmup && !X, U = () => m, H = () => {
|
|
1085
|
+
var g;
|
|
1086
|
+
m = !0, p && ((g = n.onConnectionStateChange) == null || g.call(n, S.Connected));
|
|
1087
|
+
}, q = Vt(
|
|
1088
|
+
w,
|
|
1089
|
+
U,
|
|
1090
1090
|
H,
|
|
1091
|
-
(
|
|
1092
|
-
statsSignal:
|
|
1093
|
-
dataChannelSignal: D ===
|
|
1091
|
+
(g, y) => $e({
|
|
1092
|
+
statsSignal: E = g,
|
|
1093
|
+
dataChannelSignal: D === te.Legacy ? u : void 0,
|
|
1094
1094
|
onVideoStateChange: n.onVideoStateChange,
|
|
1095
1095
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1096
|
-
report:
|
|
1096
|
+
report: y,
|
|
1097
1097
|
streamType: D
|
|
1098
1098
|
}),
|
|
1099
|
-
(
|
|
1100
|
-
var
|
|
1101
|
-
return (
|
|
1099
|
+
(g) => {
|
|
1100
|
+
var y;
|
|
1101
|
+
return (y = n.onConnectivityStateChange) == null ? void 0 : y.call(n, g);
|
|
1102
1102
|
}
|
|
1103
1103
|
);
|
|
1104
|
-
|
|
1105
|
-
var
|
|
1106
|
-
r("peerConnection.onicecandidate",
|
|
1104
|
+
w.onicecandidate = (g) => {
|
|
1105
|
+
var y;
|
|
1106
|
+
r("peerConnection.onicecandidate", g);
|
|
1107
1107
|
try {
|
|
1108
|
-
|
|
1108
|
+
g.candidate && g.candidate.sdpMid && g.candidate.sdpMLineIndex !== null ? L(
|
|
1109
1109
|
T,
|
|
1110
1110
|
{
|
|
1111
|
-
candidate:
|
|
1112
|
-
sdpMid:
|
|
1113
|
-
sdpMLineIndex:
|
|
1111
|
+
candidate: g.candidate.candidate,
|
|
1112
|
+
sdpMid: g.candidate.sdpMid,
|
|
1113
|
+
sdpMLineIndex: g.candidate.sdpMLineIndex
|
|
1114
1114
|
},
|
|
1115
|
-
|
|
1115
|
+
N,
|
|
1116
1116
|
a
|
|
1117
|
-
) : L(T, { candidate: null },
|
|
1118
|
-
} catch (
|
|
1119
|
-
(
|
|
1117
|
+
) : L(T, { candidate: null }, N, a);
|
|
1118
|
+
} catch (j) {
|
|
1119
|
+
(y = n.onError) == null || y.call(n, j, { streamId: T });
|
|
1120
1120
|
}
|
|
1121
1121
|
}, $.onopen = () => {
|
|
1122
1122
|
p = !0, (!_ || m) && H();
|
|
1123
1123
|
};
|
|
1124
|
-
const
|
|
1125
|
-
var
|
|
1126
|
-
(
|
|
1124
|
+
const b = (g) => {
|
|
1125
|
+
var y;
|
|
1126
|
+
(y = n.onVideoIdChange) == null || y.call(n, g);
|
|
1127
1127
|
};
|
|
1128
|
-
function
|
|
1129
|
-
if (
|
|
1130
|
-
const
|
|
1131
|
-
j
|
|
1128
|
+
function K(g, y) {
|
|
1129
|
+
if (g === z.StreamStarted && typeof y == "object" && "metadata" in y) {
|
|
1130
|
+
const j = y.metadata;
|
|
1131
|
+
b(j.videoId);
|
|
1132
1132
|
}
|
|
1133
|
-
|
|
1134
|
-
statsSignal: D ===
|
|
1133
|
+
g === z.StreamDone && b(null), u = g === z.StreamStarted ? C.Start : C.Stop, $e({
|
|
1134
|
+
statsSignal: D === te.Legacy ? E : void 0,
|
|
1135
1135
|
dataChannelSignal: u,
|
|
1136
1136
|
onVideoStateChange: n.onVideoStateChange,
|
|
1137
1137
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1138
1138
|
streamType: D
|
|
1139
1139
|
});
|
|
1140
1140
|
}
|
|
1141
|
-
function
|
|
1141
|
+
function Z(g, y) {
|
|
1142
1142
|
var Q;
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1143
|
+
const j = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
|
|
1144
|
+
j && s.enrich({ streamMetadata: j }), (Q = n.onStreamReady) == null || Q.call(n);
|
|
1145
1145
|
}
|
|
1146
|
-
const
|
|
1147
|
-
[
|
|
1148
|
-
[
|
|
1149
|
-
[
|
|
1146
|
+
const re = {
|
|
1147
|
+
[z.StreamStarted]: K,
|
|
1148
|
+
[z.StreamDone]: K,
|
|
1149
|
+
[z.StreamReady]: Z
|
|
1150
1150
|
};
|
|
1151
|
-
$.onmessage = (
|
|
1151
|
+
$.onmessage = (g) => {
|
|
1152
1152
|
var Q;
|
|
1153
|
-
const { subject:
|
|
1154
|
-
(Q =
|
|
1155
|
-
},
|
|
1156
|
-
var
|
|
1157
|
-
r("peerConnection.oniceconnectionstatechange => " +
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1160
|
-
},
|
|
1161
|
-
var
|
|
1162
|
-
r("peerConnection.ontrack",
|
|
1163
|
-
}, await
|
|
1164
|
-
const
|
|
1165
|
-
return r("create answer OK"), await
|
|
1153
|
+
const { subject: y, data: j } = d(g.data);
|
|
1154
|
+
(Q = re[y]) == null || Q.call(re, y, j);
|
|
1155
|
+
}, w.oniceconnectionstatechange = () => {
|
|
1156
|
+
var y;
|
|
1157
|
+
r("peerConnection.oniceconnectionstatechange => " + w.iceConnectionState);
|
|
1158
|
+
const g = Le(w.iceConnectionState);
|
|
1159
|
+
g !== S.Connected && ((y = n.onConnectionStateChange) == null || y.call(n, g));
|
|
1160
|
+
}, w.ontrack = (g) => {
|
|
1161
|
+
var y;
|
|
1162
|
+
r("peerConnection.ontrack", g), (y = n.onSrcObjectReady) == null || y.call(n, g.streams[0]);
|
|
1163
|
+
}, await w.setRemoteDescription(ne), r("set remote description OK");
|
|
1164
|
+
const W = await w.createAnswer();
|
|
1165
|
+
return r("create answer OK"), await w.setLocalDescription(W), r("set local description OK"), await x(T, W, N, a), r("start connection OK"), {
|
|
1166
1166
|
/**
|
|
1167
1167
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1168
1168
|
* @param payload
|
|
1169
1169
|
*/
|
|
1170
|
-
speak(
|
|
1171
|
-
return
|
|
1170
|
+
speak(g) {
|
|
1171
|
+
return V(T, N, g);
|
|
1172
1172
|
},
|
|
1173
1173
|
/**
|
|
1174
1174
|
* Method to close RTC connection
|
|
1175
1175
|
*/
|
|
1176
1176
|
async disconnect() {
|
|
1177
|
-
var
|
|
1177
|
+
var g;
|
|
1178
1178
|
if (T) {
|
|
1179
|
-
const
|
|
1180
|
-
if (
|
|
1181
|
-
if (
|
|
1179
|
+
const y = Le(w.iceConnectionState);
|
|
1180
|
+
if (w) {
|
|
1181
|
+
if (y === S.New) {
|
|
1182
1182
|
clearInterval(q);
|
|
1183
1183
|
return;
|
|
1184
1184
|
}
|
|
1185
|
-
|
|
1185
|
+
w.close(), w.oniceconnectionstatechange = null, w.onnegotiationneeded = null, w.onicecandidate = null, w.ontrack = null;
|
|
1186
1186
|
}
|
|
1187
1187
|
try {
|
|
1188
|
-
|
|
1188
|
+
y === S.Connected && await I(T, N).catch((j) => {
|
|
1189
1189
|
});
|
|
1190
|
-
} catch (
|
|
1191
|
-
r("Error on close stream connection",
|
|
1190
|
+
} catch (j) {
|
|
1191
|
+
r("Error on close stream connection", j);
|
|
1192
1192
|
}
|
|
1193
|
-
(
|
|
1193
|
+
(g = n.onAgentActivityStateChange) == null || g.call(n, ae.Idle), clearInterval(q);
|
|
1194
1194
|
}
|
|
1195
1195
|
},
|
|
1196
1196
|
/**
|
|
1197
1197
|
* Method to send data channel messages to the server
|
|
1198
1198
|
*/
|
|
1199
|
-
sendDataChannelMessage(
|
|
1200
|
-
var
|
|
1199
|
+
sendDataChannelMessage(g) {
|
|
1200
|
+
var y, j;
|
|
1201
1201
|
if (!m || $.readyState !== "open") {
|
|
1202
|
-
r("Data channel is not ready for sending messages"), (
|
|
1202
|
+
r("Data channel is not ready for sending messages"), (y = n.onError) == null || y.call(n, new Error("Data channel is not ready for sending messages"), {
|
|
1203
1203
|
streamId: T
|
|
1204
1204
|
});
|
|
1205
1205
|
return;
|
|
1206
1206
|
}
|
|
1207
1207
|
try {
|
|
1208
|
-
$.send(
|
|
1208
|
+
$.send(g);
|
|
1209
1209
|
} catch (Q) {
|
|
1210
|
-
r("Error sending data channel message", Q), (
|
|
1210
|
+
r("Error sending data channel message", Q), (j = n.onError) == null || j.call(n, Q, { streamId: T });
|
|
1211
1211
|
}
|
|
1212
1212
|
},
|
|
1213
1213
|
/**
|
|
1214
1214
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1215
1215
|
*/
|
|
1216
|
-
sessionId:
|
|
1216
|
+
sessionId: N,
|
|
1217
1217
|
/**
|
|
1218
1218
|
* Id of current RTC stream
|
|
1219
1219
|
*/
|
|
@@ -1223,7 +1223,7 @@ async function Xt(e, t, { debug: i = !1, callbacks: n, auth: c, baseURL: o = fe,
|
|
|
1223
1223
|
triggersAvailable: R ?? !1
|
|
1224
1224
|
};
|
|
1225
1225
|
}
|
|
1226
|
-
var
|
|
1226
|
+
var Me = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Me || {});
|
|
1227
1227
|
async function Yt(e, t, i, n) {
|
|
1228
1228
|
const c = e.id;
|
|
1229
1229
|
switch (t.version) {
|
|
@@ -1234,8 +1234,8 @@ async function Yt(e, t, i, n) {
|
|
|
1234
1234
|
case "v2": {
|
|
1235
1235
|
const { version: o, ...s } = t;
|
|
1236
1236
|
switch (s.transport_provider) {
|
|
1237
|
-
case
|
|
1238
|
-
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() =>
|
|
1237
|
+
case we.Livekit:
|
|
1238
|
+
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Mt);
|
|
1239
1239
|
return a(c, s, i);
|
|
1240
1240
|
default:
|
|
1241
1241
|
throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
|
|
@@ -1248,7 +1248,7 @@ async function Yt(e, t, i, n) {
|
|
|
1248
1248
|
const Zt = "cht";
|
|
1249
1249
|
function Gt() {
|
|
1250
1250
|
return {
|
|
1251
|
-
transport_provider:
|
|
1251
|
+
transport_provider: we.Livekit
|
|
1252
1252
|
};
|
|
1253
1253
|
}
|
|
1254
1254
|
function en(e) {
|
|
@@ -1265,10 +1265,10 @@ function en(e) {
|
|
|
1265
1265
|
}, ...i && { end_user_data: i } };
|
|
1266
1266
|
}
|
|
1267
1267
|
function tn(e, t) {
|
|
1268
|
-
return Ee(e.presenter.type) ? { version:
|
|
1268
|
+
return Ee(e.presenter.type) ? { version: Me.V2, ...Gt() } : { version: Me.V1, ...en(t) };
|
|
1269
1269
|
}
|
|
1270
1270
|
function nn(e, t, i, n, c) {
|
|
1271
|
-
c ===
|
|
1271
|
+
c === te.Fluent ? rn(e, t, i, n, c) : on(e, t, i, n, c);
|
|
1272
1272
|
}
|
|
1273
1273
|
function rn(e, t, i, n, c) {
|
|
1274
1274
|
e === C.Start ? n.track("stream-session", { event: "start", "stream-type": c }) : e === C.Stop && n.track("stream-session", {
|
|
@@ -1280,11 +1280,11 @@ function rn(e, t, i, n, c) {
|
|
|
1280
1280
|
});
|
|
1281
1281
|
}
|
|
1282
1282
|
function an(e, t, i, n) {
|
|
1283
|
-
|
|
1283
|
+
ee.get() <= 0 || (e === C.Start ? i.linkTrack(
|
|
1284
1284
|
"agent-video",
|
|
1285
|
-
{ event: "start", latency:
|
|
1285
|
+
{ event: "start", latency: ee.get(!0), "stream-type": n },
|
|
1286
1286
|
"start",
|
|
1287
|
-
[
|
|
1287
|
+
[z.StreamVideoCreated]
|
|
1288
1288
|
) : e === C.Stop && i.linkTrack(
|
|
1289
1289
|
"agent-video",
|
|
1290
1290
|
{
|
|
@@ -1294,15 +1294,15 @@ function an(e, t, i, n) {
|
|
|
1294
1294
|
"stream-type": n
|
|
1295
1295
|
},
|
|
1296
1296
|
"done",
|
|
1297
|
-
[
|
|
1297
|
+
[z.StreamVideoDone]
|
|
1298
1298
|
));
|
|
1299
1299
|
}
|
|
1300
1300
|
function on(e, t, i, n, c) {
|
|
1301
|
-
|
|
1301
|
+
ee.get() <= 0 || (e === C.Start ? n.linkTrack(
|
|
1302
1302
|
"agent-video",
|
|
1303
|
-
{ event: "start", latency:
|
|
1303
|
+
{ event: "start", latency: ee.get(!0), "stream-type": c },
|
|
1304
1304
|
"start",
|
|
1305
|
-
[
|
|
1305
|
+
[z.StreamVideoCreated]
|
|
1306
1306
|
) : e === C.Stop && n.linkTrack(
|
|
1307
1307
|
"agent-video",
|
|
1308
1308
|
{
|
|
@@ -1313,11 +1313,11 @@ function on(e, t, i, n, c) {
|
|
|
1313
1313
|
...i
|
|
1314
1314
|
},
|
|
1315
1315
|
"done",
|
|
1316
|
-
[
|
|
1316
|
+
[z.StreamVideoDone]
|
|
1317
1317
|
));
|
|
1318
1318
|
}
|
|
1319
1319
|
function xe(e, t, i, n) {
|
|
1320
|
-
return
|
|
1320
|
+
return ee.reset(), je.update(), new Promise(async (c, o) => {
|
|
1321
1321
|
try {
|
|
1322
1322
|
let s, a = !1;
|
|
1323
1323
|
const r = tn(e, t);
|
|
@@ -1347,7 +1347,7 @@ function xe(e, t, i, n) {
|
|
|
1347
1347
|
},
|
|
1348
1348
|
onAgentActivityStateChange: (d) => {
|
|
1349
1349
|
var m, p;
|
|
1350
|
-
(p = (m = t.callbacks).onAgentActivityStateChange) == null || p.call(m, d), d === ae.Talking ?
|
|
1350
|
+
(p = (m = t.callbacks).onAgentActivityStateChange) == null || p.call(m, d), d === ae.Talking ? ke.update() : ke.reset(), an(
|
|
1351
1351
|
d === ae.Talking ? C.Start : C.Stop,
|
|
1352
1352
|
e,
|
|
1353
1353
|
i,
|
|
@@ -1368,26 +1368,26 @@ function xe(e, t, i, n) {
|
|
|
1368
1368
|
});
|
|
1369
1369
|
}
|
|
1370
1370
|
async function sn(e, t, i, n, c) {
|
|
1371
|
-
var m, p, u,
|
|
1371
|
+
var m, p, u, E;
|
|
1372
1372
|
const o = async () => {
|
|
1373
1373
|
if (Ee(e.presenter.type)) {
|
|
1374
|
-
const x = await xe(e, t, n),
|
|
1374
|
+
const x = await xe(e, t, n), V = `${Zt}_${x.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
|
|
1375
1375
|
return { chatResult: {
|
|
1376
|
-
chatMode:
|
|
1376
|
+
chatMode: J.Functional,
|
|
1377
1377
|
chat: {
|
|
1378
|
-
id:
|
|
1378
|
+
id: V,
|
|
1379
1379
|
agent_id: e.id,
|
|
1380
1380
|
owner_id: e.owner_id ?? "",
|
|
1381
1381
|
created: I,
|
|
1382
1382
|
modified: I,
|
|
1383
1383
|
agent_id__created_at: I,
|
|
1384
1384
|
agent_id__modified_at: I,
|
|
1385
|
-
chat_mode:
|
|
1385
|
+
chat_mode: J.Functional,
|
|
1386
1386
|
messages: []
|
|
1387
1387
|
}
|
|
1388
1388
|
}, streamingManager: x };
|
|
1389
1389
|
} else {
|
|
1390
|
-
const x = new AbortController(),
|
|
1390
|
+
const x = new AbortController(), V = x.signal;
|
|
1391
1391
|
let I;
|
|
1392
1392
|
try {
|
|
1393
1393
|
const A = Ue(
|
|
@@ -1397,20 +1397,20 @@ async function sn(e, t, i, n, c) {
|
|
|
1397
1397
|
t.mode,
|
|
1398
1398
|
t.persistentChat,
|
|
1399
1399
|
c
|
|
1400
|
-
), L = xe(e, t, n,
|
|
1401
|
-
return { chatResult: T, streamingManager:
|
|
1400
|
+
), L = xe(e, t, n, V).then((B) => (I = B, B)), [T, ne] = await Promise.all([A, L]);
|
|
1401
|
+
return { chatResult: T, streamingManager: ne };
|
|
1402
1402
|
} catch (A) {
|
|
1403
1403
|
throw x.abort(), I && await I.disconnect().catch(() => {
|
|
1404
1404
|
}), A;
|
|
1405
1405
|
}
|
|
1406
1406
|
}
|
|
1407
1407
|
}, { chatResult: s, streamingManager: a } = await o(), { chat: r, chatMode: d } = s;
|
|
1408
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (m = t.callbacks).onModeChange) == null || p.call(m, d), d !==
|
|
1408
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (m = t.callbacks).onModeChange) == null || p.call(m, d), d !== J.Functional) ? ((E = (u = t.callbacks).onError) == null || E.call(u, new qe(d)), a == null || a.disconnect(), { chat: r }) : { chat: r, streamingManager: a };
|
|
1409
1409
|
}
|
|
1410
1410
|
async function un(e, t) {
|
|
1411
|
-
var B,
|
|
1411
|
+
var B, N, X;
|
|
1412
1412
|
let i = !0, n = null;
|
|
1413
|
-
const c = t.mixpanelKey || ct, o = t.wsURL || st, s = t.baseURL ||
|
|
1413
|
+
const c = t.mixpanelKey || ct, o = t.wsURL || st, s = t.baseURL || ge, a = t.mode || J.Functional, r = {
|
|
1414
1414
|
messages: [],
|
|
1415
1415
|
chatMode: a
|
|
1416
1416
|
}, d = vt({
|
|
@@ -1423,9 +1423,9 @@ async function un(e, t) {
|
|
|
1423
1423
|
be(() => {
|
|
1424
1424
|
d.track("agent-sdk", { event: "init" }, m);
|
|
1425
1425
|
});
|
|
1426
|
-
const p = mt(t.auth, s, t.callbacks.onError, t.externalId), u = await p.getById(e),
|
|
1426
|
+
const p = mt(t.auth, s, t.callbacks.onError, t.externalId), u = await p.getById(e), E = Ee(u.presenter.type);
|
|
1427
1427
|
d.enrich(ht(u));
|
|
1428
|
-
const { onMessage: x, clearQueue:
|
|
1428
|
+
const { onMessage: x, clearQueue: V } = $t(
|
|
1429
1429
|
d,
|
|
1430
1430
|
r,
|
|
1431
1431
|
t,
|
|
@@ -1435,7 +1435,7 @@ async function un(e, t) {
|
|
|
1435
1435
|
return (f = r.socketManager) == null ? void 0 : f.disconnect();
|
|
1436
1436
|
}
|
|
1437
1437
|
);
|
|
1438
|
-
r.messages = Ct(t.initialMessages), (
|
|
1438
|
+
r.messages = Ct(t.initialMessages), (N = (B = t.callbacks).onNewMessage) == null || N.call(B, [...r.messages], "answer");
|
|
1439
1439
|
const I = (f) => {
|
|
1440
1440
|
n = f;
|
|
1441
1441
|
}, A = Date.now();
|
|
@@ -1443,14 +1443,14 @@ async function un(e, t) {
|
|
|
1443
1443
|
d.track("agent-sdk", { event: "loaded", ...gt(u) }, A);
|
|
1444
1444
|
});
|
|
1445
1445
|
async function L(f) {
|
|
1446
|
-
var
|
|
1447
|
-
(H = (
|
|
1448
|
-
const R = a ===
|
|
1446
|
+
var U, H, q, b, K, Z, re;
|
|
1447
|
+
(H = (U = t.callbacks).onConnectionStateChange) == null || H.call(U, S.Connecting), ee.reset(), f && !i && (delete r.chat, (b = (q = t.callbacks).onNewMessage) == null || b.call(q, [...r.messages], "answer"));
|
|
1448
|
+
const R = a === J.DirectPlayback || E ? Promise.resolve(void 0) : Pt(
|
|
1449
1449
|
t.auth,
|
|
1450
1450
|
o,
|
|
1451
1451
|
{ onMessage: x, onError: t.callbacks.onError },
|
|
1452
1452
|
t.externalId
|
|
1453
|
-
),
|
|
1453
|
+
), w = Se(
|
|
1454
1454
|
() => sn(
|
|
1455
1455
|
u,
|
|
1456
1456
|
{
|
|
@@ -1466,26 +1466,26 @@ async function un(e, t) {
|
|
|
1466
1466
|
limit: 3,
|
|
1467
1467
|
timeout: at,
|
|
1468
1468
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1469
|
-
shouldRetryFn: (
|
|
1469
|
+
shouldRetryFn: (W) => (W == null ? void 0 : W.message) !== "Could not connect" && W.status !== 429 && (W == null ? void 0 : W.message) !== "InsufficientCreditsError",
|
|
1470
1470
|
delayMs: 1e3
|
|
1471
1471
|
}
|
|
1472
|
-
).catch((
|
|
1473
|
-
var
|
|
1474
|
-
throw
|
|
1475
|
-
}), [$, { streamingManager: D, chat: _ }] = await Promise.all([R,
|
|
1476
|
-
_ && _.id !== ((
|
|
1472
|
+
).catch((W) => {
|
|
1473
|
+
var M, g;
|
|
1474
|
+
throw ne(J.Maintenance), (g = (M = t.callbacks).onConnectionStateChange) == null || g.call(M, S.Fail), W;
|
|
1475
|
+
}), [$, { streamingManager: D, chat: _ }] = await Promise.all([R, w]);
|
|
1476
|
+
_ && _.id !== ((K = r.chat) == null ? void 0 : K.id) && ((re = (Z = t.callbacks).onNewChat) == null || re.call(Z, _.id)), r.streamingManager = D, r.socketManager = $, r.chat = _, i = !1, d.enrich({
|
|
1477
1477
|
chatId: _ == null ? void 0 : _.id,
|
|
1478
1478
|
streamId: D == null ? void 0 : D.streamId,
|
|
1479
1479
|
mode: r.chatMode
|
|
1480
|
-
}),
|
|
1480
|
+
}), ne((_ == null ? void 0 : _.chat_mode) ?? a);
|
|
1481
1481
|
}
|
|
1482
1482
|
async function T() {
|
|
1483
|
-
var f, R,
|
|
1484
|
-
(f = r.socketManager) == null || f.disconnect(), await ((R = r.streamingManager) == null ? void 0 : R.disconnect()), delete r.streamingManager, delete r.socketManager, ($ = (
|
|
1483
|
+
var f, R, w, $;
|
|
1484
|
+
(f = r.socketManager) == null || f.disconnect(), await ((R = r.streamingManager) == null ? void 0 : R.disconnect()), delete r.streamingManager, delete r.socketManager, ($ = (w = t.callbacks).onConnectionStateChange) == null || $.call(w, S.Disconnected);
|
|
1485
1485
|
}
|
|
1486
|
-
async function
|
|
1487
|
-
var R,
|
|
1488
|
-
f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !==
|
|
1486
|
+
async function ne(f) {
|
|
1487
|
+
var R, w;
|
|
1488
|
+
f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== J.Functional && await T(), (w = (R = t.callbacks).onModeChange) == null || w.call(R, f));
|
|
1489
1489
|
}
|
|
1490
1490
|
return {
|
|
1491
1491
|
agent: u,
|
|
@@ -1503,7 +1503,7 @@ async function un(e, t) {
|
|
|
1503
1503
|
},
|
|
1504
1504
|
starterMessages: ((X = u.knowledge) == null ? void 0 : X.starter_message) || [],
|
|
1505
1505
|
getSTTToken: () => p.getSTTToken(u.id),
|
|
1506
|
-
changeMode:
|
|
1506
|
+
changeMode: ne,
|
|
1507
1507
|
enrichAnalytics: d.enrich,
|
|
1508
1508
|
async connect() {
|
|
1509
1509
|
await L(!0), d.track("agent-chat", {
|
|
@@ -1513,7 +1513,7 @@ async function un(e, t) {
|
|
|
1513
1513
|
},
|
|
1514
1514
|
async reconnect() {
|
|
1515
1515
|
const f = r.streamingManager;
|
|
1516
|
-
if (
|
|
1516
|
+
if (E && (f != null && f.reconnect)) {
|
|
1517
1517
|
try {
|
|
1518
1518
|
await f.reconnect(), d.track("agent-chat", {
|
|
1519
1519
|
event: "reconnect",
|
|
@@ -1548,111 +1548,114 @@ async function un(e, t) {
|
|
|
1548
1548
|
return r.streamingManager.unpublishMicrophoneStream();
|
|
1549
1549
|
},
|
|
1550
1550
|
async chat(f) {
|
|
1551
|
-
var D, _,
|
|
1551
|
+
var D, _, U, H, q;
|
|
1552
1552
|
const R = () => {
|
|
1553
1553
|
if (Ne(a))
|
|
1554
|
-
throw new
|
|
1554
|
+
throw new ce(`${a} is enabled, chat is disabled`);
|
|
1555
1555
|
if (f.length >= 800)
|
|
1556
|
-
throw new
|
|
1556
|
+
throw new ce("Message cannot be more than 800 characters");
|
|
1557
1557
|
if (f.length === 0)
|
|
1558
|
-
throw new
|
|
1559
|
-
if (r.chatMode ===
|
|
1560
|
-
throw new
|
|
1561
|
-
if (![
|
|
1558
|
+
throw new ce("Message cannot be empty");
|
|
1559
|
+
if (r.chatMode === J.Maintenance)
|
|
1560
|
+
throw new ce("Chat is in maintenance mode");
|
|
1561
|
+
if (![J.TextOnly, J.Playground].includes(r.chatMode)) {
|
|
1562
1562
|
if (!r.streamingManager)
|
|
1563
|
-
throw new
|
|
1563
|
+
throw new ce("Streaming manager is not initialized");
|
|
1564
1564
|
if (!r.chat)
|
|
1565
|
-
throw new
|
|
1565
|
+
throw new ce("Chat is not initialized");
|
|
1566
1566
|
}
|
|
1567
|
-
},
|
|
1568
|
-
var
|
|
1567
|
+
}, w = async () => {
|
|
1568
|
+
var b, K;
|
|
1569
1569
|
if (!r.chat) {
|
|
1570
|
-
const
|
|
1570
|
+
const Z = await Ue(
|
|
1571
1571
|
u,
|
|
1572
1572
|
p,
|
|
1573
1573
|
d,
|
|
1574
1574
|
r.chatMode,
|
|
1575
1575
|
t.persistentChat
|
|
1576
1576
|
);
|
|
1577
|
-
if (!
|
|
1577
|
+
if (!Z.chat)
|
|
1578
1578
|
throw new He(r.chatMode, !!t.persistentChat);
|
|
1579
|
-
r.chat =
|
|
1579
|
+
r.chat = Z.chat, (K = (b = t.callbacks).onNewChat) == null || K.call(b, r.chat.id);
|
|
1580
1580
|
}
|
|
1581
1581
|
return r.chat.id;
|
|
1582
|
-
}, $ = async (
|
|
1583
|
-
|
|
1584
|
-
return
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1582
|
+
}, $ = async (b, K) => {
|
|
1583
|
+
const Z = r.chatMode === J.Playground;
|
|
1584
|
+
return Se(E && !Z ? async () => {
|
|
1585
|
+
var M, g;
|
|
1586
|
+
return await ((g = (M = r.streamingManager) == null ? void 0 : M.sendTextMessage) == null ? void 0 : g.call(M, f)), Promise.resolve({});
|
|
1587
|
+
} : async () => {
|
|
1588
|
+
var M, g;
|
|
1589
|
+
return p.chat(
|
|
1590
|
+
u.id,
|
|
1591
|
+
K,
|
|
1592
|
+
{
|
|
1593
|
+
chatMode: r.chatMode,
|
|
1594
|
+
streamId: (M = r.streamingManager) == null ? void 0 : M.streamId,
|
|
1595
|
+
sessionId: (g = r.streamingManager) == null ? void 0 : g.sessionId,
|
|
1596
|
+
messages: b.map(({ matches: y, ...j }) => j)
|
|
1597
|
+
},
|
|
1598
|
+
{
|
|
1599
|
+
...Je(r.chatMode),
|
|
1600
|
+
skipErrorHandler: !0
|
|
1601
|
+
}
|
|
1602
|
+
);
|
|
1603
|
+
}, {
|
|
1604
|
+
limit: 2,
|
|
1605
|
+
shouldRetryFn: (M) => {
|
|
1606
|
+
var j, Q, se, ue;
|
|
1607
|
+
const g = (j = M == null ? void 0 : M.message) == null ? void 0 : j.includes("missing or invalid session_id");
|
|
1608
|
+
return !((Q = M == null ? void 0 : M.message) == null ? void 0 : Q.includes("Stream Error")) && !g ? ((ue = (se = t.callbacks).onError) == null || ue.call(se, M), !1) : !0;
|
|
1595
1609
|
},
|
|
1596
|
-
{
|
|
1597
|
-
|
|
1598
|
-
skipErrorHandler: !0
|
|
1610
|
+
onRetry: async () => {
|
|
1611
|
+
await T(), await L(!1);
|
|
1599
1612
|
}
|
|
1600
|
-
);
|
|
1601
|
-
}
|
|
1602
|
-
limit: 2,
|
|
1603
|
-
shouldRetryFn: (E) => {
|
|
1604
|
-
var h, w, F, Q;
|
|
1605
|
-
const P = (h = E == null ? void 0 : E.message) == null ? void 0 : h.includes("missing or invalid session_id");
|
|
1606
|
-
return !((w = E == null ? void 0 : E.message) == null ? void 0 : w.includes("Stream Error")) && !P ? ((Q = (F = t.callbacks).onError) == null || Q.call(F, E), !1) : !0;
|
|
1607
|
-
},
|
|
1608
|
-
onRetry: async () => {
|
|
1609
|
-
await T(), await L(!1);
|
|
1610
|
-
}
|
|
1611
|
-
});
|
|
1613
|
+
});
|
|
1614
|
+
};
|
|
1612
1615
|
try {
|
|
1613
|
-
|
|
1614
|
-
id:
|
|
1616
|
+
V(), R(), r.messages.push({
|
|
1617
|
+
id: de(),
|
|
1615
1618
|
role: "user",
|
|
1616
1619
|
content: f,
|
|
1617
|
-
created_at: new Date(
|
|
1620
|
+
created_at: new Date(ee.update()).toISOString()
|
|
1618
1621
|
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "user");
|
|
1619
|
-
const
|
|
1622
|
+
const b = await w(), K = await $([...r.messages], b);
|
|
1620
1623
|
return r.messages.push({
|
|
1621
|
-
id:
|
|
1624
|
+
id: de(),
|
|
1622
1625
|
role: "assistant",
|
|
1623
|
-
content:
|
|
1626
|
+
content: K.result || "",
|
|
1624
1627
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1625
|
-
context:
|
|
1626
|
-
matches:
|
|
1628
|
+
context: K.context,
|
|
1629
|
+
matches: K.matches
|
|
1627
1630
|
}), d.track("agent-message-send", {
|
|
1628
1631
|
event: "success",
|
|
1629
1632
|
messages: r.messages.length + 1
|
|
1630
|
-
}),
|
|
1631
|
-
latency:
|
|
1633
|
+
}), K.result && ((H = (U = t.callbacks).onNewMessage) == null || H.call(U, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1634
|
+
latency: ee.get(!0),
|
|
1632
1635
|
messages: r.messages.length
|
|
1633
|
-
})),
|
|
1634
|
-
} catch (
|
|
1636
|
+
})), K;
|
|
1637
|
+
} catch (b) {
|
|
1635
1638
|
throw ((q = r.messages[r.messages.length - 1]) == null ? void 0 : q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1636
1639
|
event: "error",
|
|
1637
1640
|
messages: r.messages.length
|
|
1638
|
-
}),
|
|
1641
|
+
}), b;
|
|
1639
1642
|
}
|
|
1640
1643
|
},
|
|
1641
|
-
rate(f, R,
|
|
1642
|
-
var _,
|
|
1643
|
-
const $ = r.messages.find((
|
|
1644
|
+
rate(f, R, w) {
|
|
1645
|
+
var _, U, H, q;
|
|
1646
|
+
const $ = r.messages.find((b) => b.id === f);
|
|
1644
1647
|
if (r.chat) {
|
|
1645
1648
|
if (!$)
|
|
1646
1649
|
throw new Error("Message not found");
|
|
1647
1650
|
} else throw new Error("Chat is not initialized");
|
|
1648
|
-
const D = ((_ = $.matches) == null ? void 0 : _.map((
|
|
1651
|
+
const D = ((_ = $.matches) == null ? void 0 : _.map((b) => [b.document_id, b.id])) ?? [];
|
|
1649
1652
|
return d.track("agent-rate", {
|
|
1650
|
-
event:
|
|
1653
|
+
event: w ? "update" : "create",
|
|
1651
1654
|
thumb: R === 1 ? "up" : "down",
|
|
1652
|
-
knowledge_id: ((
|
|
1655
|
+
knowledge_id: ((U = u.knowledge) == null ? void 0 : U.id) ?? "",
|
|
1653
1656
|
matches: D,
|
|
1654
1657
|
score: R
|
|
1655
|
-
}),
|
|
1658
|
+
}), w ? p.updateRating(u.id, r.chat.id, w, {
|
|
1656
1659
|
knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
|
|
1657
1660
|
message_id: f,
|
|
1658
1661
|
matches: D,
|
|
@@ -1670,7 +1673,7 @@ async function un(e, t) {
|
|
|
1670
1673
|
return d.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, r.chat.id, f);
|
|
1671
1674
|
},
|
|
1672
1675
|
async speak(f) {
|
|
1673
|
-
var D, _,
|
|
1676
|
+
var D, _, U;
|
|
1674
1677
|
function R() {
|
|
1675
1678
|
if (typeof f == "string") {
|
|
1676
1679
|
if (!u.presenter.voice)
|
|
@@ -1694,11 +1697,11 @@ async function un(e, t) {
|
|
|
1694
1697
|
}
|
|
1695
1698
|
return f;
|
|
1696
1699
|
}
|
|
1697
|
-
const
|
|
1698
|
-
if (d.track("agent-speak",
|
|
1699
|
-
id:
|
|
1700
|
+
const w = R();
|
|
1701
|
+
if (d.track("agent-speak", w), ee.update(), r.messages && w.type === "text" && (r.messages.push({
|
|
1702
|
+
id: de(),
|
|
1700
1703
|
role: "assistant",
|
|
1701
|
-
content:
|
|
1704
|
+
content: w.input,
|
|
1702
1705
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1703
1706
|
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "answer")), dt(r.chatMode))
|
|
1704
1707
|
return {
|
|
@@ -1709,18 +1712,18 @@ async function un(e, t) {
|
|
|
1709
1712
|
if (!r.streamingManager)
|
|
1710
1713
|
throw new Error("Please connect to the agent first");
|
|
1711
1714
|
return r.streamingManager.speak({
|
|
1712
|
-
script:
|
|
1713
|
-
metadata: { chat_id: (
|
|
1715
|
+
script: w,
|
|
1716
|
+
metadata: { chat_id: (U = r.chat) == null ? void 0 : U.id, agent_id: u.id }
|
|
1714
1717
|
});
|
|
1715
1718
|
},
|
|
1716
1719
|
async interrupt({ type: f }) {
|
|
1717
|
-
var
|
|
1720
|
+
var w, $, D;
|
|
1718
1721
|
const R = r.messages[r.messages.length - 1];
|
|
1719
1722
|
d.track("agent-video-interrupt", {
|
|
1720
1723
|
type: f || "click",
|
|
1721
|
-
video_duration_to_interrupt:
|
|
1722
|
-
message_duration_to_interrupt:
|
|
1723
|
-
}), R.interrupted = !0, ($ = (
|
|
1724
|
+
video_duration_to_interrupt: ke.get(!0),
|
|
1725
|
+
message_duration_to_interrupt: ee.get(!0)
|
|
1726
|
+
}), R.interrupted = !0, ($ = (w = t.callbacks).onNewMessage) == null || $.call(w, [...r.messages], "answer"), E ? Tt(r.streamingManager) : (Et(r.streamingManager, (D = r.streamingManager) == null ? void 0 : D.streamType, n), It(r.streamingManager, n));
|
|
1724
1727
|
}
|
|
1725
1728
|
};
|
|
1726
1729
|
}
|
|
@@ -1728,23 +1731,23 @@ export {
|
|
|
1728
1731
|
ae as AgentActivityState,
|
|
1729
1732
|
Ze as AgentStatus,
|
|
1730
1733
|
He as ChatCreationFailed,
|
|
1731
|
-
|
|
1734
|
+
J as ChatMode,
|
|
1732
1735
|
qe as ChatModeDowngraded,
|
|
1733
1736
|
Y as ChatProgress,
|
|
1734
1737
|
S as ConnectionState,
|
|
1735
|
-
|
|
1738
|
+
G as ConnectivityState,
|
|
1736
1739
|
nt as DocumentType,
|
|
1737
1740
|
tt as KnowledgeType,
|
|
1738
1741
|
Ye as PlanGroup,
|
|
1739
1742
|
rt as Providers,
|
|
1740
1743
|
Ge as RateState,
|
|
1741
|
-
|
|
1742
|
-
|
|
1744
|
+
z as StreamEvents,
|
|
1745
|
+
te as StreamType,
|
|
1743
1746
|
C as StreamingState,
|
|
1744
1747
|
et as Subject,
|
|
1745
|
-
|
|
1748
|
+
we as TransportProvider,
|
|
1746
1749
|
Xe as UserPlan,
|
|
1747
|
-
|
|
1750
|
+
ce as ValidationError,
|
|
1748
1751
|
Be as VideoType,
|
|
1749
1752
|
it as VoiceAccess,
|
|
1750
1753
|
Qe as WsError,
|