@d-id/client-sdk 1.1.26-staging.120 → 1.1.27
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 +385 -388
- 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 Oe = Object.defineProperty;
|
|
2
|
+
var Ve = (e, t, i) => t in e ? Oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var ue = (e, t, i) => Ve(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
+
class ge extends Error {
|
|
5
5
|
constructor({ kind: i, description: n, error: c }) {
|
|
6
6
|
super(JSON.stringify({ kind: i, description: n }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
ue(this, "kind");
|
|
8
|
+
ue(this, "description");
|
|
9
|
+
ue(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 ge {
|
|
14
14
|
constructor(t, i) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,24 +18,24 @@ class He extends pe {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class qe extends
|
|
21
|
+
class qe extends ge {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class se extends ge {
|
|
27
27
|
constructor(i, n) {
|
|
28
28
|
super({ kind: "ValidationError", description: i });
|
|
29
|
-
|
|
29
|
+
ue(this, "key");
|
|
30
30
|
this.key = n;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class Qe extends
|
|
33
|
+
class Qe extends ge {
|
|
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 || {}), U = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(U || {}), 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 || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(ae || {}), N = /* @__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))(N || {}), 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 || {}), ne = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ne || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), 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", fe = "https://api.d-id.com", st = "wss://notifications.d-id.com", ct = "79f81a83a67430be2bc0fd61042b8faa", Fe = (e) => new Promise((t) => setTimeout(t, e)), ce = (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) => [U.TextOnly, U.Playground, U.Maintenance].includes(e), Ne = (e) => e && [U.DirectPlayback, U.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 ve(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 Se(e, t) {
|
|
|
86
86
|
}
|
|
87
87
|
throw n;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function Se(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 = ce();
|
|
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 = ce();
|
|
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}.${Se(t)}_${lt}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const ft = (e) =>
|
|
109
|
+
const ft = (e) => ve(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 Me(e, t = fe, 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 Ie(e, t = ge, i, n) {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function mt(e, t =
|
|
150
|
-
const c =
|
|
149
|
+
function mt(e, t = fe, i, n) {
|
|
150
|
+
const c = Me(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 we = {};
|
|
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: Se(e.externalId),
|
|
250
250
|
agentId: e.agentId,
|
|
251
251
|
additionalProperties: {
|
|
252
|
-
id:
|
|
252
|
+
id: Se(e.externalId),
|
|
253
253
|
...e.mixpanelAdditionalProperties || {}
|
|
254
254
|
},
|
|
255
255
|
isEnabled: e.isEnabled ?? !0,
|
|
256
|
-
getRandom:
|
|
256
|
+
getRandom: ce,
|
|
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
|
+
we[i] || (we[i] = { events: {}, resolvedDependencies: [] }), o.includes(c) || o.push(c);
|
|
296
|
+
const s = we[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 Ie() {
|
|
311
311
|
let e = 0;
|
|
312
312
|
return {
|
|
313
313
|
reset: () => e = 0,
|
|
@@ -315,9 +315,9 @@ function Te() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const
|
|
318
|
+
const te = Ie(), Ce = Ie(), je = Ie();
|
|
319
319
|
function Je(e) {
|
|
320
|
-
return e ===
|
|
320
|
+
return e === U.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 = Me(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 ye() {
|
|
354
354
|
try {
|
|
355
355
|
return await import("./livekit-client.esm-C1GRQdZY.js");
|
|
356
356
|
} catch {
|
|
@@ -360,92 +360,92 @@ async function ve() {
|
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
const Rt = {
|
|
363
|
-
excellent:
|
|
364
|
-
good:
|
|
365
|
-
poor:
|
|
366
|
-
lost:
|
|
367
|
-
unknown:
|
|
368
|
-
},
|
|
363
|
+
excellent: ee.Strong,
|
|
364
|
+
good: ee.Strong,
|
|
365
|
+
poor: ee.Weak,
|
|
366
|
+
lost: ee.Unknown,
|
|
367
|
+
unknown: ee.Unknown
|
|
368
|
+
}, le = JSON.stringify({
|
|
369
369
|
kind: "InternalServerError",
|
|
370
370
|
description: "Stream Error"
|
|
371
371
|
});
|
|
372
|
-
var
|
|
373
|
-
function
|
|
372
|
+
var Te = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Te || {});
|
|
373
|
+
function ke(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 _e, Ae;
|
|
379
|
+
const n = We(i.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await ye(), { callbacks: a, auth: r, baseURL: d, analytics: m, microphoneStream: p } = i;
|
|
380
|
+
let u = null, M = !1;
|
|
381
|
+
const x = ne.Fluent;
|
|
382
|
+
let O = !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, re = kt(r, d || fe, e, a.onError);
|
|
390
|
+
let B, K, X;
|
|
391
391
|
try {
|
|
392
|
-
const l = await
|
|
393
|
-
transport_provider:
|
|
392
|
+
const l = await re.createStream({
|
|
393
|
+
transport_provider: he.Livekit,
|
|
394
394
|
chat_persist: t.chat_persist ?? !0
|
|
395
|
-
}), { id:
|
|
396
|
-
(
|
|
395
|
+
}), { id: g, session_token: v, session_url: k } = l;
|
|
396
|
+
(_e = a.onStreamCreated) == null || _e.call(a, { session_id: g, stream_id: g, agent_id: e }), B = g, K = v, X = k, await u.prepareConnection(X, K);
|
|
397
397
|
} catch (l) {
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
ke(l, n, a, () => {
|
|
399
|
+
O = !1;
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
|
-
if (!X || !
|
|
402
|
+
if (!X || !K || !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, y).on(o.ParticipantConnected, $).on(o.ParticipantDisconnected, D).on(o.TrackSubscribed, _).on(o.TrackUnsubscribed, W).on(o.DataReceived, H).on(o.MediaDevicesError, q).on(o.EncryptionError, j).on(o.TrackSubscriptionFailed, J), (Ae = a.onConnectionStateChange) == null || Ae.call(a, S.New);
|
|
405
405
|
try {
|
|
406
|
-
await u.connect(X,
|
|
406
|
+
await u.connect(X, K), 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 }), pe();
|
|
412
|
+
}, T), O = !1;
|
|
413
413
|
} catch (l) {
|
|
414
|
-
|
|
415
|
-
|
|
414
|
+
ke(l, n, a, () => {
|
|
415
|
+
O = !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 g, v, k, b, V;
|
|
423
423
|
switch (n("Connection state changed:", l), l) {
|
|
424
424
|
case s.Connecting:
|
|
425
|
-
(
|
|
425
|
+
(g = a.onConnectionStateChange) == null || g.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"), M = !0, O ? queueMicrotask(() => {
|
|
429
|
+
var z;
|
|
430
|
+
(z = a.onConnectionStateChange) == null || z.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"), M = !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..."), (b = a.onConnectionStateChange) == null || b.call(a, S.Connecting);
|
|
438
438
|
break;
|
|
439
439
|
case s.SignalReconnecting:
|
|
440
|
-
n("LiveKit room signal reconnecting..."), (
|
|
440
|
+
n("LiveKit room signal reconnecting..."), (V = a.onConnectionStateChange) == null || V.call(a, S.Connecting);
|
|
441
441
|
break;
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
-
function R(l,
|
|
444
|
+
function R(l, g) {
|
|
445
445
|
var v;
|
|
446
|
-
n("Connection quality:", l),
|
|
446
|
+
n("Connection quality:", l), g != null && g.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a, Rt[l]));
|
|
447
447
|
}
|
|
448
|
-
function
|
|
448
|
+
function y(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), pe();
|
|
457
457
|
}
|
|
458
|
-
function _(l,
|
|
459
|
-
var
|
|
458
|
+
function _(l, g, v) {
|
|
459
|
+
var b, V, z;
|
|
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" && ((b = a.onStreamReady) == null || b.call(a), (V = a.onSrcObjectReady) == null || V.call(a, I), (z = a.onVideoStateChange) == null || z.call(a, C.Start));
|
|
467
467
|
}
|
|
468
|
-
function
|
|
468
|
+
function W(l, g, 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, g, v, k) {
|
|
473
|
+
var V, z, de;
|
|
474
|
+
const b = new TextDecoder().decode(l);
|
|
475
|
+
n("Data received:", b);
|
|
476
476
|
try {
|
|
477
|
-
const ie = JSON.parse(
|
|
478
|
-
if (
|
|
477
|
+
const ie = JSON.parse(b), me = k || ie.subject;
|
|
478
|
+
if (me === N.ChatAnswer) {
|
|
479
479
|
const oe = Y.Answer;
|
|
480
|
-
(
|
|
480
|
+
(V = a.onMessage) == null || V.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 ([N.StreamVideoCreated, N.StreamVideoDone].includes(me)) {
|
|
485
|
+
const oe = (ie == null ? void 0 : ie.role) || (g == null ? void 0 : g.identity) || "datachannel";
|
|
486
|
+
(z = a.onMessage) == null || z.call(a, me, {
|
|
487
487
|
[oe]: ie
|
|
488
488
|
});
|
|
489
|
-
} else if (
|
|
489
|
+
} else if (me === N.ChatAudioTranscribed) {
|
|
490
490
|
const oe = Y.Transcribe;
|
|
491
|
-
(
|
|
491
|
+
(de = a.onMessage) == null || de.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 g;
|
|
502
|
+
n("Media devices error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
|
|
503
503
|
}
|
|
504
|
-
function
|
|
505
|
-
var
|
|
506
|
-
n("Encryption error:", l), (
|
|
504
|
+
function j(l) {
|
|
505
|
+
var g;
|
|
506
|
+
n("Encryption error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
|
|
507
507
|
}
|
|
508
|
-
function
|
|
509
|
-
n("Track subscription failed:", { trackSid: l, participant:
|
|
508
|
+
function J(l, g, v) {
|
|
509
|
+
n("Track subscription failed:", { trackSid: l, participant: g, reason: v });
|
|
510
510
|
}
|
|
511
|
-
async function
|
|
511
|
+
async function G(l) {
|
|
512
512
|
if (!u) return null;
|
|
513
|
-
const { Track:
|
|
513
|
+
const { Track: g } = await ye(), v = u.localParticipant.audioTrackPublications;
|
|
514
514
|
if (v) {
|
|
515
|
-
for (const [k,
|
|
516
|
-
if (
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
519
|
-
return
|
|
515
|
+
for (const [k, b] of v)
|
|
516
|
+
if (b.source === g.Source.Microphone && b.track) {
|
|
517
|
+
const z = b.track.mediaStreamTrack;
|
|
518
|
+
if (z === l || z && z.id === l.id)
|
|
519
|
+
return b;
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
522
|
return null;
|
|
523
523
|
}
|
|
524
|
-
function
|
|
524
|
+
function E(l) {
|
|
525
525
|
if (!A || !A.track)
|
|
526
526
|
return !1;
|
|
527
|
-
const
|
|
528
|
-
return
|
|
527
|
+
const g = A.track.mediaStreamTrack;
|
|
528
|
+
return g !== l && (g == null ? void 0 : g.id) !== l.id;
|
|
529
529
|
}
|
|
530
|
-
async function
|
|
531
|
-
var
|
|
532
|
-
if (!
|
|
530
|
+
async function P(l) {
|
|
531
|
+
var V, z;
|
|
532
|
+
if (!M || !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 g = l.getAudioTracks();
|
|
535
|
+
if (g.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 = g[0], { Track: k } = await ye(), b = await G(v);
|
|
540
|
+
if (b) {
|
|
541
541
|
n("Microphone track is already published, skipping", {
|
|
542
542
|
trackId: v.id,
|
|
543
|
-
publishedTrackId: (
|
|
544
|
-
}), A =
|
|
543
|
+
publishedTrackId: (z = (V = b.track) == null ? void 0 : V.mediaStreamTrack) == null ? void 0 : z.id
|
|
544
|
+
}), A = b;
|
|
545
545
|
return;
|
|
546
546
|
}
|
|
547
|
-
|
|
547
|
+
E(v) && (n("Unpublishing existing microphone track before publishing new one"), await Z()), 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 (de) {
|
|
553
|
+
throw n("Failed to publish microphone track:", de), de;
|
|
554
554
|
}
|
|
555
555
|
}
|
|
556
|
-
async function
|
|
556
|
+
async function Z() {
|
|
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 h() {
|
|
567
567
|
I && (I.getTracks().forEach((l) => l.stop()), I = null);
|
|
568
568
|
}
|
|
569
|
-
async function
|
|
569
|
+
async function w(l, g) {
|
|
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 (!M || !u) {
|
|
572
|
+
n("Room is not connected for sending messages"), (v = a.onError) == null || v.call(a, new Error(le), {
|
|
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: g }), n("Message sent successfully:", l);
|
|
579
|
+
} catch (b) {
|
|
580
|
+
n("Failed to send message:", b), (k = a.onError) == null || k.call(a, new Error(le), { sessionId: B });
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
|
-
async function
|
|
584
|
-
var
|
|
583
|
+
async function F(l) {
|
|
584
|
+
var g;
|
|
585
585
|
try {
|
|
586
586
|
const k = JSON.parse(l).topic;
|
|
587
|
-
return
|
|
587
|
+
return w("", k);
|
|
588
588
|
} catch (v) {
|
|
589
|
-
n("Failed to send data channel message:", v), (
|
|
589
|
+
n("Failed to send data channel message:", v), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
592
|
function Q(l) {
|
|
593
|
-
return
|
|
593
|
+
return w(
|
|
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 pe() {
|
|
600
|
+
var l, g;
|
|
601
|
+
L && (clearTimeout(L), L = null), u && (await Z(), await u.disconnect()), h(), M = !1, (l = a.onConnectionStateChange) == null || l.call(a, S.Disconnected), (g = a.onAgentActivityStateChange) == null || g.call(a, ae.Idle);
|
|
602
602
|
}
|
|
603
603
|
return {
|
|
604
604
|
speak(l) {
|
|
605
|
-
const
|
|
606
|
-
return
|
|
607
|
-
|
|
605
|
+
const g = typeof l == "string" ? l : JSON.stringify(l);
|
|
606
|
+
return w(
|
|
607
|
+
g,
|
|
608
608
|
"did.speak"
|
|
609
609
|
/* Speak */
|
|
610
610
|
);
|
|
611
611
|
},
|
|
612
|
-
disconnect:
|
|
612
|
+
disconnect: pe,
|
|
613
613
|
async reconnect() {
|
|
614
|
-
var l,
|
|
614
|
+
var l, g, 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 || !K)
|
|
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, K), n("Room reconnected"), M = !0, u.remoteParticipants.size === 0) {
|
|
624
|
+
if (n("Waiting for agent to join..."), !await new Promise((b) => {
|
|
625
|
+
const V = setTimeout(() => {
|
|
626
|
+
u == null || u.off(o.ParticipantConnected, z), b(!1);
|
|
627
|
+
}, 5e3), z = () => {
|
|
628
|
+
clearTimeout(V), u == null || u.off(o.ParticipantConnected, z), b(!0);
|
|
629
629
|
};
|
|
630
|
-
u == null || u.on(o.ParticipantConnected,
|
|
630
|
+
u == null || u.on(o.ParticipantConnected, z);
|
|
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
|
+
(g = a.onConnectionStateChange) == null || g.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: F,
|
|
641
641
|
sendTextMessage: Q,
|
|
642
|
-
publishMicrophoneStream:
|
|
643
|
-
unpublishMicrophoneStream:
|
|
642
|
+
publishMicrophoneStream: P,
|
|
643
|
+
unpublishMicrophoneStream: Z,
|
|
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 Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
652
652
|
__proto__: null,
|
|
653
|
-
DataChannelTopic:
|
|
653
|
+
DataChannelTopic: Te,
|
|
654
654
|
createLiveKitStreamingManager: Dt,
|
|
655
|
-
handleInitError:
|
|
655
|
+
handleInitError: ke
|
|
656
656
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
657
|
-
function
|
|
657
|
+
function Mt(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 !== ne.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: N.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: Te.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 === N.ChatAnswer ? Y.Answer : s === N.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 = N, p = [m.StreamVideoDone, m.StreamVideoError, m.StreamVideoRejected], u = [m.StreamFailed, m.StreamVideoError, m.StreamVideoRejected], M = wt(a, n, { mode: t.chatMode });
|
|
787
787
|
if (s = s, s === m.StreamVideoCreated)
|
|
788
|
-
e.linkTrack("agent-video",
|
|
788
|
+
e.linkTrack("agent-video", M, 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", { ...M, event: x }) : e.linkTrack("agent-video", { ...M, 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 = Me(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 Re = 100, Kt = Math.max(Math.ceil(400 / Re), 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 Ot(e, t, i, n, c) {
|
|
983
|
+
let o = [], s, a = 0, r = !1, d = ee.Unknown, m = ee.Unknown, p = 0, u = 0;
|
|
984
|
+
const M = 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: O, avgJitterDelayInInterval: I, freezeCount: A } = M(x), L = zt(x);
|
|
987
|
+
if (O)
|
|
988
|
+
a = 0, p = A - u, m = I < Jt ? ee.Strong : I > Ut && p > 1 ? ee.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, Re, s);
|
|
991
991
|
n == null || n(C.Stop, T), t() || i(), u = A, r = !1;
|
|
992
992
|
}
|
|
993
|
-
},
|
|
993
|
+
}, Re);
|
|
994
994
|
}
|
|
995
|
-
const
|
|
995
|
+
const Vt = (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 === ne.Legacy ? qt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o }) : c === ne.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 = fe, analytics: s }, a) {
|
|
1059
|
+
var Z;
|
|
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, M = C.Stop;
|
|
1062
|
+
const { startConnection: x, sendStreamRequest: O, 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: re,
|
|
1070
1070
|
ice_servers: B,
|
|
1071
|
-
session_id:
|
|
1071
|
+
session_id: K,
|
|
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
|
+
(Z = n.onStreamCreated) == null || Z.call(n, { stream_id: T, session_id: K, agent_id: e });
|
|
1077
|
+
const y = new Vt({ iceServers: B }), $ = y.createDataChannel("JanusDataChannel");
|
|
1078
|
+
if (!K)
|
|
1079
1079
|
throw new Error("Could not create session_id");
|
|
1080
|
-
const D = X ?
|
|
1080
|
+
const D = X ? ne.Fluent : ne.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, W = () => m, H = () => {
|
|
1085
|
+
var h;
|
|
1086
|
+
m = !0, p && ((h = n.onConnectionStateChange) == null || h.call(n, S.Connected));
|
|
1087
|
+
}, q = Ot(
|
|
1088
|
+
y,
|
|
1089
|
+
W,
|
|
1090
1090
|
H,
|
|
1091
|
-
(
|
|
1092
|
-
statsSignal:
|
|
1093
|
-
dataChannelSignal: D ===
|
|
1091
|
+
(h, w) => $e({
|
|
1092
|
+
statsSignal: M = h,
|
|
1093
|
+
dataChannelSignal: D === ne.Legacy ? u : void 0,
|
|
1094
1094
|
onVideoStateChange: n.onVideoStateChange,
|
|
1095
1095
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1096
|
-
report:
|
|
1096
|
+
report: w,
|
|
1097
1097
|
streamType: D
|
|
1098
1098
|
}),
|
|
1099
|
-
(
|
|
1100
|
-
var
|
|
1101
|
-
return (
|
|
1099
|
+
(h) => {
|
|
1100
|
+
var w;
|
|
1101
|
+
return (w = n.onConnectivityStateChange) == null ? void 0 : w.call(n, h);
|
|
1102
1102
|
}
|
|
1103
1103
|
);
|
|
1104
|
-
|
|
1105
|
-
var
|
|
1106
|
-
r("peerConnection.onicecandidate",
|
|
1104
|
+
y.onicecandidate = (h) => {
|
|
1105
|
+
var w;
|
|
1106
|
+
r("peerConnection.onicecandidate", h);
|
|
1107
1107
|
try {
|
|
1108
|
-
|
|
1108
|
+
h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? L(
|
|
1109
1109
|
T,
|
|
1110
1110
|
{
|
|
1111
|
-
candidate:
|
|
1112
|
-
sdpMid:
|
|
1113
|
-
sdpMLineIndex:
|
|
1111
|
+
candidate: h.candidate.candidate,
|
|
1112
|
+
sdpMid: h.candidate.sdpMid,
|
|
1113
|
+
sdpMLineIndex: h.candidate.sdpMLineIndex
|
|
1114
1114
|
},
|
|
1115
|
-
|
|
1115
|
+
K,
|
|
1116
1116
|
a
|
|
1117
|
-
) : L(T, { candidate: null },
|
|
1118
|
-
} catch (
|
|
1119
|
-
(
|
|
1117
|
+
) : L(T, { candidate: null }, K, a);
|
|
1118
|
+
} catch (F) {
|
|
1119
|
+
(w = n.onError) == null || w.call(n, F, { streamId: T });
|
|
1120
1120
|
}
|
|
1121
1121
|
}, $.onopen = () => {
|
|
1122
1122
|
p = !0, (!_ || m) && H();
|
|
1123
1123
|
};
|
|
1124
|
-
const
|
|
1125
|
-
var
|
|
1126
|
-
(
|
|
1124
|
+
const j = (h) => {
|
|
1125
|
+
var w;
|
|
1126
|
+
(w = n.onVideoIdChange) == null || w.call(n, h);
|
|
1127
1127
|
};
|
|
1128
|
-
function
|
|
1129
|
-
if (
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1128
|
+
function J(h, w) {
|
|
1129
|
+
if (h === N.StreamStarted && typeof w == "object" && "metadata" in w) {
|
|
1130
|
+
const F = w.metadata;
|
|
1131
|
+
j(F.videoId);
|
|
1132
1132
|
}
|
|
1133
|
-
|
|
1134
|
-
statsSignal: D ===
|
|
1133
|
+
h === N.StreamDone && j(null), u = h === N.StreamStarted ? C.Start : C.Stop, $e({
|
|
1134
|
+
statsSignal: D === ne.Legacy ? M : 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 G(h, w) {
|
|
1142
1142
|
var Q;
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1143
|
+
const F = typeof w == "string" ? w : w == null ? void 0 : w.metadata;
|
|
1144
|
+
F && s.enrich({ streamMetadata: F }), (Q = n.onStreamReady) == null || Q.call(n);
|
|
1145
1145
|
}
|
|
1146
|
-
const
|
|
1147
|
-
[
|
|
1148
|
-
[
|
|
1149
|
-
[
|
|
1146
|
+
const E = {
|
|
1147
|
+
[N.StreamStarted]: J,
|
|
1148
|
+
[N.StreamDone]: J,
|
|
1149
|
+
[N.StreamReady]: G
|
|
1150
1150
|
};
|
|
1151
|
-
$.onmessage = (
|
|
1151
|
+
$.onmessage = (h) => {
|
|
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: w, data: F } = d(h.data);
|
|
1154
|
+
(Q = E[w]) == null || Q.call(E, w, F);
|
|
1155
|
+
}, y.oniceconnectionstatechange = () => {
|
|
1156
|
+
var w;
|
|
1157
|
+
r("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
|
|
1158
|
+
const h = Le(y.iceConnectionState);
|
|
1159
|
+
h !== S.Connected && ((w = n.onConnectionStateChange) == null || w.call(n, h));
|
|
1160
|
+
}, y.ontrack = (h) => {
|
|
1161
|
+
var w;
|
|
1162
|
+
r("peerConnection.ontrack", h), (w = n.onSrcObjectReady) == null || w.call(n, h.streams[0]);
|
|
1163
|
+
}, await y.setRemoteDescription(re), r("set remote description OK");
|
|
1164
|
+
const P = await y.createAnswer();
|
|
1165
|
+
return r("create answer OK"), await y.setLocalDescription(P), r("set local description OK"), await x(T, P, K, 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(h) {
|
|
1171
|
+
return O(T, K, h);
|
|
1172
1172
|
},
|
|
1173
1173
|
/**
|
|
1174
1174
|
* Method to close RTC connection
|
|
1175
1175
|
*/
|
|
1176
1176
|
async disconnect() {
|
|
1177
|
-
var
|
|
1177
|
+
var h;
|
|
1178
1178
|
if (T) {
|
|
1179
|
-
const
|
|
1180
|
-
if (
|
|
1181
|
-
if (
|
|
1179
|
+
const w = Le(y.iceConnectionState);
|
|
1180
|
+
if (y) {
|
|
1181
|
+
if (w === S.New) {
|
|
1182
1182
|
clearInterval(q);
|
|
1183
1183
|
return;
|
|
1184
1184
|
}
|
|
1185
|
-
|
|
1185
|
+
y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
|
|
1186
1186
|
}
|
|
1187
1187
|
try {
|
|
1188
|
-
|
|
1188
|
+
w === S.Connected && await I(T, K).catch((F) => {
|
|
1189
1189
|
});
|
|
1190
|
-
} catch (
|
|
1191
|
-
r("Error on close stream connection",
|
|
1190
|
+
} catch (F) {
|
|
1191
|
+
r("Error on close stream connection", F);
|
|
1192
1192
|
}
|
|
1193
|
-
(
|
|
1193
|
+
(h = n.onAgentActivityStateChange) == null || h.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(h) {
|
|
1200
|
+
var w, F;
|
|
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"), (w = n.onError) == null || w.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(h);
|
|
1209
1209
|
} catch (Q) {
|
|
1210
|
-
r("Error sending data channel message", Q), (
|
|
1210
|
+
r("Error sending data channel message", Q), (F = n.onError) == null || F.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: K,
|
|
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 = ge,
|
|
|
1223
1223
|
triggersAvailable: R ?? !1
|
|
1224
1224
|
};
|
|
1225
1225
|
}
|
|
1226
|
-
var
|
|
1226
|
+
var De = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(De || {});
|
|
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 he.Livekit:
|
|
1238
|
+
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Et);
|
|
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: he.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: De.V2, ...Gt() } : { version: De.V1, ...en(t) };
|
|
1269
1269
|
}
|
|
1270
1270
|
function nn(e, t, i, n, c) {
|
|
1271
|
-
c ===
|
|
1271
|
+
c === ne.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
|
+
te.get() <= 0 || (e === C.Start ? i.linkTrack(
|
|
1284
1284
|
"agent-video",
|
|
1285
|
-
{ event: "start", latency:
|
|
1285
|
+
{ event: "start", latency: te.get(!0), "stream-type": n },
|
|
1286
1286
|
"start",
|
|
1287
|
-
[
|
|
1287
|
+
[N.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
|
+
[N.StreamVideoDone]
|
|
1298
1298
|
));
|
|
1299
1299
|
}
|
|
1300
1300
|
function on(e, t, i, n, c) {
|
|
1301
|
-
|
|
1301
|
+
te.get() <= 0 || (e === C.Start ? n.linkTrack(
|
|
1302
1302
|
"agent-video",
|
|
1303
|
-
{ event: "start", latency:
|
|
1303
|
+
{ event: "start", latency: te.get(!0), "stream-type": c },
|
|
1304
1304
|
"start",
|
|
1305
|
-
[
|
|
1305
|
+
[N.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
|
+
[N.StreamVideoDone]
|
|
1317
1317
|
));
|
|
1318
1318
|
}
|
|
1319
1319
|
function xe(e, t, i, n) {
|
|
1320
|
-
return
|
|
1320
|
+
return te.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 ? Ce.update() : Ce.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, M;
|
|
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), O = `${Zt}_${x.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
|
|
1375
1375
|
return { chatResult: {
|
|
1376
|
-
chatMode:
|
|
1376
|
+
chatMode: U.Functional,
|
|
1377
1377
|
chat: {
|
|
1378
|
-
id:
|
|
1378
|
+
id: O,
|
|
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: U.Functional,
|
|
1386
1386
|
messages: []
|
|
1387
1387
|
}
|
|
1388
1388
|
}, streamingManager: x };
|
|
1389
1389
|
} else {
|
|
1390
|
-
const x = new AbortController(),
|
|
1390
|
+
const x = new AbortController(), O = 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, O).then((B) => (I = B, B)), [T, re] = await Promise.all([A, L]);
|
|
1401
|
+
return { chatResult: T, streamingManager: re };
|
|
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 !== U.Functional) ? ((M = (u = t.callbacks).onError) == null || M.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, K, 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 || fe, a = t.mode || U.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), M = Ee(u.presenter.type);
|
|
1427
1427
|
d.enrich(ht(u));
|
|
1428
|
-
const { onMessage: x, clearQueue:
|
|
1428
|
+
const { onMessage: x, clearQueue: O } = $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), (K = (B = t.callbacks).onNewMessage) == null || K.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 W, H, q, j, J, G, E;
|
|
1447
|
+
(H = (W = t.callbacks).onConnectionStateChange) == null || H.call(W, S.Connecting), te.reset(), f && !i && (delete r.chat, (j = (q = t.callbacks).onNewMessage) == null || j.call(q, [...r.messages], "answer"));
|
|
1448
|
+
const R = a === U.DirectPlayback || M ? 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
|
+
), y = ve(
|
|
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: (P) => (P == null ? void 0 : P.message) !== "Could not connect" && P.status !== 429 && (P == null ? void 0 : P.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((P) => {
|
|
1473
|
+
var Z, h;
|
|
1474
|
+
throw re(U.Maintenance), (h = (Z = t.callbacks).onConnectionStateChange) == null || h.call(Z, S.Fail), P;
|
|
1475
|
+
}), [$, { streamingManager: D, chat: _ }] = await Promise.all([R, y]);
|
|
1476
|
+
_ && _.id !== ((J = r.chat) == null ? void 0 : J.id) && ((E = (G = t.callbacks).onNewChat) == null || E.call(G, _.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
|
+
}), re((_ == 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, y, $;
|
|
1484
|
+
(f = r.socketManager) == null || f.disconnect(), await ((R = r.streamingManager) == null ? void 0 : R.disconnect()), delete r.streamingManager, delete r.socketManager, ($ = (y = t.callbacks).onConnectionStateChange) == null || $.call(y, 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 re(f) {
|
|
1487
|
+
var R, y;
|
|
1488
|
+
f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== U.Functional && await T(), (y = (R = t.callbacks).onModeChange) == null || y.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: re,
|
|
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 (M && (f != null && f.reconnect)) {
|
|
1517
1517
|
try {
|
|
1518
1518
|
await f.reconnect(), d.track("agent-chat", {
|
|
1519
1519
|
event: "reconnect",
|
|
@@ -1548,114 +1548,111 @@ async function un(e, t) {
|
|
|
1548
1548
|
return r.streamingManager.unpublishMicrophoneStream();
|
|
1549
1549
|
},
|
|
1550
1550
|
async chat(f) {
|
|
1551
|
-
var D, _,
|
|
1551
|
+
var D, _, W, H, q;
|
|
1552
1552
|
const R = () => {
|
|
1553
1553
|
if (Ne(a))
|
|
1554
|
-
throw new
|
|
1554
|
+
throw new se(`${a} is enabled, chat is disabled`);
|
|
1555
1555
|
if (f.length >= 800)
|
|
1556
|
-
throw new
|
|
1556
|
+
throw new se("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 se("Message cannot be empty");
|
|
1559
|
+
if (r.chatMode === U.Maintenance)
|
|
1560
|
+
throw new se("Chat is in maintenance mode");
|
|
1561
|
+
if (![U.TextOnly, U.Playground].includes(r.chatMode)) {
|
|
1562
1562
|
if (!r.streamingManager)
|
|
1563
|
-
throw new
|
|
1563
|
+
throw new se("Streaming manager is not initialized");
|
|
1564
1564
|
if (!r.chat)
|
|
1565
|
-
throw new
|
|
1565
|
+
throw new se("Chat is not initialized");
|
|
1566
1566
|
}
|
|
1567
|
-
},
|
|
1568
|
-
var
|
|
1567
|
+
}, y = async () => {
|
|
1568
|
+
var j, J;
|
|
1569
1569
|
if (!r.chat) {
|
|
1570
|
-
const
|
|
1570
|
+
const G = 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 (!G.chat)
|
|
1578
1578
|
throw new He(r.chatMode, !!t.persistentChat);
|
|
1579
|
-
r.chat =
|
|
1579
|
+
r.chat = G.chat, (J = (j = t.callbacks).onNewChat) == null || J.call(j, 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
|
-
|
|
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;
|
|
1582
|
+
}, $ = async (j, J) => ve(M ? async () => {
|
|
1583
|
+
var E, P;
|
|
1584
|
+
return await ((P = (E = r.streamingManager) == null ? void 0 : E.sendTextMessage) == null ? void 0 : P.call(E, f)), Promise.resolve({});
|
|
1585
|
+
} : async () => {
|
|
1586
|
+
var E, P;
|
|
1587
|
+
return p.chat(
|
|
1588
|
+
u.id,
|
|
1589
|
+
J,
|
|
1590
|
+
{
|
|
1591
|
+
chatMode: r.chatMode,
|
|
1592
|
+
streamId: (E = r.streamingManager) == null ? void 0 : E.streamId,
|
|
1593
|
+
sessionId: (P = r.streamingManager) == null ? void 0 : P.sessionId,
|
|
1594
|
+
messages: j.map(({ matches: Z, ...h }) => h)
|
|
1609
1595
|
},
|
|
1610
|
-
|
|
1611
|
-
|
|
1596
|
+
{
|
|
1597
|
+
...Je(r.chatMode),
|
|
1598
|
+
skipErrorHandler: !0
|
|
1612
1599
|
}
|
|
1613
|
-
|
|
1614
|
-
}
|
|
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
|
+
});
|
|
1615
1612
|
try {
|
|
1616
|
-
|
|
1617
|
-
id:
|
|
1613
|
+
O(), R(), r.messages.push({
|
|
1614
|
+
id: ce(),
|
|
1618
1615
|
role: "user",
|
|
1619
1616
|
content: f,
|
|
1620
|
-
created_at: new Date(
|
|
1617
|
+
created_at: new Date(te.update()).toISOString()
|
|
1621
1618
|
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "user");
|
|
1622
|
-
const
|
|
1619
|
+
const j = await y(), J = await $([...r.messages], j);
|
|
1623
1620
|
return r.messages.push({
|
|
1624
|
-
id:
|
|
1621
|
+
id: ce(),
|
|
1625
1622
|
role: "assistant",
|
|
1626
|
-
content:
|
|
1623
|
+
content: J.result || "",
|
|
1627
1624
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1628
|
-
context:
|
|
1629
|
-
matches:
|
|
1625
|
+
context: J.context,
|
|
1626
|
+
matches: J.matches
|
|
1630
1627
|
}), d.track("agent-message-send", {
|
|
1631
1628
|
event: "success",
|
|
1632
1629
|
messages: r.messages.length + 1
|
|
1633
|
-
}),
|
|
1634
|
-
latency:
|
|
1630
|
+
}), J.result && ((H = (W = t.callbacks).onNewMessage) == null || H.call(W, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1631
|
+
latency: te.get(!0),
|
|
1635
1632
|
messages: r.messages.length
|
|
1636
|
-
})),
|
|
1637
|
-
} catch (
|
|
1633
|
+
})), J;
|
|
1634
|
+
} catch (j) {
|
|
1638
1635
|
throw ((q = r.messages[r.messages.length - 1]) == null ? void 0 : q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1639
1636
|
event: "error",
|
|
1640
1637
|
messages: r.messages.length
|
|
1641
|
-
}),
|
|
1638
|
+
}), j;
|
|
1642
1639
|
}
|
|
1643
1640
|
},
|
|
1644
|
-
rate(f, R,
|
|
1645
|
-
var _,
|
|
1646
|
-
const $ = r.messages.find((
|
|
1641
|
+
rate(f, R, y) {
|
|
1642
|
+
var _, W, H, q;
|
|
1643
|
+
const $ = r.messages.find((j) => j.id === f);
|
|
1647
1644
|
if (r.chat) {
|
|
1648
1645
|
if (!$)
|
|
1649
1646
|
throw new Error("Message not found");
|
|
1650
1647
|
} else throw new Error("Chat is not initialized");
|
|
1651
|
-
const D = ((_ = $.matches) == null ? void 0 : _.map((
|
|
1648
|
+
const D = ((_ = $.matches) == null ? void 0 : _.map((j) => [j.document_id, j.id])) ?? [];
|
|
1652
1649
|
return d.track("agent-rate", {
|
|
1653
|
-
event:
|
|
1650
|
+
event: y ? "update" : "create",
|
|
1654
1651
|
thumb: R === 1 ? "up" : "down",
|
|
1655
|
-
knowledge_id: ((
|
|
1652
|
+
knowledge_id: ((W = u.knowledge) == null ? void 0 : W.id) ?? "",
|
|
1656
1653
|
matches: D,
|
|
1657
1654
|
score: R
|
|
1658
|
-
}),
|
|
1655
|
+
}), y ? p.updateRating(u.id, r.chat.id, y, {
|
|
1659
1656
|
knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
|
|
1660
1657
|
message_id: f,
|
|
1661
1658
|
matches: D,
|
|
@@ -1673,7 +1670,7 @@ async function un(e, t) {
|
|
|
1673
1670
|
return d.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, r.chat.id, f);
|
|
1674
1671
|
},
|
|
1675
1672
|
async speak(f) {
|
|
1676
|
-
var D, _,
|
|
1673
|
+
var D, _, W;
|
|
1677
1674
|
function R() {
|
|
1678
1675
|
if (typeof f == "string") {
|
|
1679
1676
|
if (!u.presenter.voice)
|
|
@@ -1697,11 +1694,11 @@ async function un(e, t) {
|
|
|
1697
1694
|
}
|
|
1698
1695
|
return f;
|
|
1699
1696
|
}
|
|
1700
|
-
const
|
|
1701
|
-
if (d.track("agent-speak",
|
|
1702
|
-
id:
|
|
1697
|
+
const y = R();
|
|
1698
|
+
if (d.track("agent-speak", y), te.update(), r.messages && y.type === "text" && (r.messages.push({
|
|
1699
|
+
id: ce(),
|
|
1703
1700
|
role: "assistant",
|
|
1704
|
-
content:
|
|
1701
|
+
content: y.input,
|
|
1705
1702
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1706
1703
|
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "answer")), dt(r.chatMode))
|
|
1707
1704
|
return {
|
|
@@ -1712,18 +1709,18 @@ async function un(e, t) {
|
|
|
1712
1709
|
if (!r.streamingManager)
|
|
1713
1710
|
throw new Error("Please connect to the agent first");
|
|
1714
1711
|
return r.streamingManager.speak({
|
|
1715
|
-
script:
|
|
1716
|
-
metadata: { chat_id: (
|
|
1712
|
+
script: y,
|
|
1713
|
+
metadata: { chat_id: (W = r.chat) == null ? void 0 : W.id, agent_id: u.id }
|
|
1717
1714
|
});
|
|
1718
1715
|
},
|
|
1719
1716
|
async interrupt({ type: f }) {
|
|
1720
|
-
var
|
|
1717
|
+
var y, $, D;
|
|
1721
1718
|
const R = r.messages[r.messages.length - 1];
|
|
1722
1719
|
d.track("agent-video-interrupt", {
|
|
1723
1720
|
type: f || "click",
|
|
1724
|
-
video_duration_to_interrupt:
|
|
1725
|
-
message_duration_to_interrupt:
|
|
1726
|
-
}), R.interrupted = !0, ($ = (
|
|
1721
|
+
video_duration_to_interrupt: Ce.get(!0),
|
|
1722
|
+
message_duration_to_interrupt: te.get(!0)
|
|
1723
|
+
}), R.interrupted = !0, ($ = (y = t.callbacks).onNewMessage) == null || $.call(y, [...r.messages], "answer"), M ? Tt(r.streamingManager) : (Mt(r.streamingManager, (D = r.streamingManager) == null ? void 0 : D.streamType, n), It(r.streamingManager, n));
|
|
1727
1724
|
}
|
|
1728
1725
|
};
|
|
1729
1726
|
}
|
|
@@ -1731,23 +1728,23 @@ export {
|
|
|
1731
1728
|
ae as AgentActivityState,
|
|
1732
1729
|
Ze as AgentStatus,
|
|
1733
1730
|
He as ChatCreationFailed,
|
|
1734
|
-
|
|
1731
|
+
U as ChatMode,
|
|
1735
1732
|
qe as ChatModeDowngraded,
|
|
1736
1733
|
Y as ChatProgress,
|
|
1737
1734
|
S as ConnectionState,
|
|
1738
|
-
|
|
1735
|
+
ee as ConnectivityState,
|
|
1739
1736
|
nt as DocumentType,
|
|
1740
1737
|
tt as KnowledgeType,
|
|
1741
1738
|
Ye as PlanGroup,
|
|
1742
1739
|
rt as Providers,
|
|
1743
1740
|
Ge as RateState,
|
|
1744
|
-
|
|
1745
|
-
|
|
1741
|
+
N as StreamEvents,
|
|
1742
|
+
ne as StreamType,
|
|
1746
1743
|
C as StreamingState,
|
|
1747
1744
|
et as Subject,
|
|
1748
|
-
|
|
1745
|
+
he as TransportProvider,
|
|
1749
1746
|
Xe as UserPlan,
|
|
1750
|
-
|
|
1747
|
+
se as ValidationError,
|
|
1751
1748
|
Be as VideoType,
|
|
1752
1749
|
it as VoiceAccess,
|
|
1753
1750
|
Qe as WsError,
|