@d-id/client-sdk 2.0.6 → 2.0.7
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/README.md +10 -0
- package/dist/{index-BLArKcFJ.js → index-DeKPoqBL.js} +2391 -2381
- package/dist/index.js +17 -16
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-BPAUUVXy.js → livekit-manager-D7YZEQiJ.js} +156 -193
- package/dist/src/services/streaming-manager/advanced.test.d.ts +0 -4
- package/dist/src/services/streaming-manager/common.d.ts +8 -20
- package/dist/src/services/streaming-manager/edge-cases.test.d.ts +0 -4
- package/dist/src/services/streaming-manager/livekit-manager.d.ts +0 -6
- package/dist/src/services/streaming-manager/webrtc-core.test.d.ts +0 -4
- package/dist/src/types/entities/agents/agent.d.ts +5 -0
- package/dist/src/types/entities/agents/manager.d.ts +8 -1
- package/dist/src/types/entities/knowledge/document.d.ts +13 -3
- package/dist/src/types/stream/data-channel.d.ts +16 -0
- package/dist/src/types/stream/stream.d.ts +15 -0
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
function
|
|
1
|
+
import { c as Be, C as J, S as f, a as Je, b as Qe, A as m, d as We, l as pe, e as qe, t as Ge, f as A, g as U, h as He, D as ge, i as Xe, j as b, n as Ze } from "./index-DeKPoqBL.js";
|
|
2
|
+
function Ye() {
|
|
3
3
|
try {
|
|
4
4
|
return Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
|
|
5
5
|
} catch {
|
|
6
6
|
return "";
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function en() {
|
|
10
10
|
if (typeof navigator > "u")
|
|
11
11
|
return "";
|
|
12
12
|
const l = navigator.userAgent ?? "", C = (navigator.platform ?? "").toLowerCase();
|
|
@@ -15,80 +15,80 @@ function nn() {
|
|
|
15
15
|
const i = u === "Android" || u === "iOS" || /Mobi/i.test(l);
|
|
16
16
|
return `${u}, ${i ? "Mobile" : "Desktop"}`;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const l = {}, C =
|
|
18
|
+
function nn() {
|
|
19
|
+
const l = {}, C = Ye();
|
|
20
20
|
C && (l.timezone = C);
|
|
21
|
-
const u =
|
|
21
|
+
const u = en();
|
|
22
22
|
return u && (l.device = u), l;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const k =
|
|
24
|
+
function tn(l, C, u, i) {
|
|
25
|
+
const k = Be(l, `${C}/v2/agents/${u}`, i);
|
|
26
26
|
return {
|
|
27
|
-
async createStream(
|
|
28
|
-
return k.post("/sessions",
|
|
27
|
+
async createStream(g) {
|
|
28
|
+
return k.post("/sessions", g);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
}, he = 2e4,
|
|
36
|
-
async function
|
|
32
|
+
const on = {
|
|
33
|
+
[f.ChatAnswer]: J.Answer,
|
|
34
|
+
[f.ChatPartial]: J.Partial
|
|
35
|
+
}, he = 2e4, rn = [];
|
|
36
|
+
async function an() {
|
|
37
37
|
try {
|
|
38
|
-
return await import("./index-
|
|
38
|
+
return await import("./index-DeKPoqBL.js").then((l) => l.F);
|
|
39
39
|
} catch {
|
|
40
40
|
throw new Error(
|
|
41
41
|
"LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
const
|
|
46
|
-
excellent:
|
|
47
|
-
good:
|
|
48
|
-
poor:
|
|
49
|
-
lost:
|
|
50
|
-
unknown:
|
|
51
|
-
},
|
|
45
|
+
const cn = {
|
|
46
|
+
excellent: U.Strong,
|
|
47
|
+
good: U.Strong,
|
|
48
|
+
poor: U.Weak,
|
|
49
|
+
lost: U.Unknown,
|
|
50
|
+
unknown: U.Unknown
|
|
51
|
+
}, O = (l = "Stream Error") => new qe(l);
|
|
52
52
|
function me(l, C, u) {
|
|
53
53
|
var i, k;
|
|
54
54
|
throw C("Failed to connect to LiveKit room:", l), (i = u.onConnectionStateChange) == null || i.call(u, A.Fail, "internal:init-error"), (k = u.onError) == null || k.call(u, l, { sessionId: "" }), l;
|
|
55
55
|
}
|
|
56
|
-
async function
|
|
57
|
-
var
|
|
58
|
-
const i =
|
|
56
|
+
async function un(l, C, u) {
|
|
57
|
+
var se;
|
|
58
|
+
const i = Je(u.debug || !1, "LiveKitStreamingManager"), { Room: k, RoomEvent: g, ConnectionState: I, Track: Y } = await an(), { callbacks: n, auth: Ce, baseURL: Se, analytics: ee } = u;
|
|
59
59
|
let a = null, E = !1;
|
|
60
|
-
const ne =
|
|
61
|
-
let
|
|
62
|
-
const
|
|
63
|
-
let h = null, S = null,
|
|
60
|
+
const ne = Qe.Fluent;
|
|
61
|
+
let L = null;
|
|
62
|
+
const P = { isPublishing: !1, publication: null }, Q = { isPublishing: !1, publication: null };
|
|
63
|
+
let h = null, S = null, j = null, K = !1;
|
|
64
64
|
a = new k({
|
|
65
65
|
adaptiveStream: !1,
|
|
66
66
|
// Must be false to use mediaStreamTrack directly
|
|
67
67
|
dynacast: !0
|
|
68
68
|
});
|
|
69
|
-
let
|
|
70
|
-
const
|
|
71
|
-
let
|
|
72
|
-
const Te =
|
|
73
|
-
let
|
|
69
|
+
let R = null, M = m.Idle, W = !0;
|
|
70
|
+
const y = /* @__PURE__ */ new Map();
|
|
71
|
+
let x = null;
|
|
72
|
+
const Te = tn(Ce, Se || We, l, n.onError);
|
|
73
|
+
let v, _, $, te = !0;
|
|
74
74
|
try {
|
|
75
75
|
const e = await Te.createStream({
|
|
76
76
|
transport: C.transport,
|
|
77
77
|
chat_persist: C.chat_persist ?? !0,
|
|
78
78
|
verbose: u.verbose ?? !1
|
|
79
79
|
}), { id: t, session_token: o, session_url: r, interrupt_enabled: c } = e;
|
|
80
|
-
(
|
|
80
|
+
(se = n.onStreamCreated) == null || se.call(n, { session_id: t, stream_id: t, agent_id: l }), v = t, _ = o, $ = r, te = c ?? !0, await a.prepareConnection($, _);
|
|
81
81
|
} catch (e) {
|
|
82
82
|
me(e, i, n);
|
|
83
83
|
}
|
|
84
|
-
if (!$ || !_ || !
|
|
84
|
+
if (!$ || !_ || !v)
|
|
85
85
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
86
|
-
a.on(
|
|
86
|
+
a.on(g.ConnectionStateChanged, we).on(g.ConnectionQualityChanged, Ae).on(g.ParticipantConnected, Ee).on(g.ParticipantDisconnected, Re).on(g.TrackSubscribed, Le).on(g.TrackUnsubscribed, Pe).on(g.DataReceived, Ke).on(g.MediaDevicesError, xe).on(g.TranscriptionReceived, ye).on(g.EncryptionError, Ve).on(g.TrackSubscriptionFailed, Fe);
|
|
87
87
|
function ye(e, t) {
|
|
88
|
-
t != null && t.isLocal &&
|
|
88
|
+
t != null && t.isLocal && pe.update();
|
|
89
89
|
}
|
|
90
90
|
async function ve() {
|
|
91
|
-
const e =
|
|
91
|
+
const e = nn();
|
|
92
92
|
if (!(!a || Object.keys(e).length === 0))
|
|
93
93
|
try {
|
|
94
94
|
await a.localParticipant.setAttributes(e);
|
|
@@ -97,16 +97,16 @@ async function dn(l, C, u) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
100
|
-
await a.connect($, _), i("LiveKit room joined successfully"), ve(),
|
|
100
|
+
await a.connect($, _), i("LiveKit room joined successfully"), ve(), R = setTimeout(() => {
|
|
101
101
|
var t;
|
|
102
102
|
i(
|
|
103
103
|
`Track subscription timeout - no track subscribed within ${he / 1e3} seconds after connect`
|
|
104
|
-
),
|
|
105
|
-
const e =
|
|
104
|
+
), R = null;
|
|
105
|
+
const e = O("Track subscription timeout");
|
|
106
106
|
ee.track("connectivity-error", {
|
|
107
|
-
error:
|
|
108
|
-
sessionId:
|
|
109
|
-
}), (t = n.onError) == null || t.call(n, e, { sessionId:
|
|
107
|
+
error: Ge(e),
|
|
108
|
+
sessionId: v
|
|
109
|
+
}), (t = n.onError) == null || t.call(n, e, { sessionId: v }), Z("internal:track-subscription-timeout");
|
|
110
110
|
}, he);
|
|
111
111
|
} catch (e) {
|
|
112
112
|
me(e, i, n);
|
|
@@ -124,7 +124,7 @@ async function dn(l, C, u) {
|
|
|
124
124
|
i("LiveKit room connected successfully"), E = !0;
|
|
125
125
|
break;
|
|
126
126
|
case I.Disconnected:
|
|
127
|
-
i("LiveKit room disconnected"), E = !1,
|
|
127
|
+
i("LiveKit room disconnected"), E = !1, K = !1, P.publication = null, Q.publication = null, (o = n.onConnectionStateChange) == null || o.call(n, A.Disconnected, "livekit:disconnected");
|
|
128
128
|
break;
|
|
129
129
|
case I.Reconnecting:
|
|
130
130
|
i("LiveKit room reconnecting..."), (r = n.onConnectionStateChange) == null || r.call(n, A.Connecting, "livekit:reconnecting");
|
|
@@ -136,23 +136,23 @@ async function dn(l, C, u) {
|
|
|
136
136
|
}
|
|
137
137
|
function Ae(e, t) {
|
|
138
138
|
var o;
|
|
139
|
-
i("Connection quality:", e), t != null && t.isLocal && ((o = n.onConnectivityStateChange) == null || o.call(n,
|
|
139
|
+
i("Connection quality:", e), t != null && t.isLocal && ((o = n.onConnectivityStateChange) == null || o.call(n, cn[e]));
|
|
140
140
|
}
|
|
141
141
|
function Ee(e) {
|
|
142
142
|
i("Participant connected:", e.identity);
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function Re(e) {
|
|
145
145
|
i("Participant disconnected:", e.identity), Z("livekit:participant-disconnected");
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function be() {
|
|
148
148
|
var e;
|
|
149
|
-
|
|
149
|
+
j !== b.Start && (i("CALLBACK: onVideoStateChange(Start)"), j = b.Start, (e = n.onVideoStateChange) == null || e.call(n, b.Start));
|
|
150
150
|
}
|
|
151
151
|
function ie(e) {
|
|
152
152
|
var t;
|
|
153
|
-
|
|
153
|
+
j !== b.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), j = b.Stop, (t = n.onVideoStateChange) == null || t.call(n, b.Stop, e));
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function Le(e, t, o) {
|
|
156
156
|
var c, d, s;
|
|
157
157
|
i(`Track subscribed: ${e.kind} from ${o.identity}`);
|
|
158
158
|
const r = e.mediaStreamTrack;
|
|
@@ -160,157 +160,157 @@ async function dn(l, C, u) {
|
|
|
160
160
|
i(`No mediaStreamTrack available for ${e.kind}`);
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
L ? (L.addTrack(r), i(`Added ${e.kind} track to shared MediaStream`)) : (L = new MediaStream([r]), i(`Created shared MediaStream with ${e.kind} track`)), e.kind === "audio" && (S = Xe(
|
|
164
164
|
() => e.getRTCStatsReport(),
|
|
165
|
-
({ sttLatency: p, serviceLatency:
|
|
166
|
-
var de, le
|
|
167
|
-
const
|
|
168
|
-
let
|
|
165
|
+
({ sttLatency: p, serviceLatency: T }) => {
|
|
166
|
+
var ue, de, le;
|
|
167
|
+
const V = pe.get(!0);
|
|
168
|
+
let F = 0;
|
|
169
169
|
if (p) {
|
|
170
|
-
const
|
|
171
|
-
|
|
170
|
+
const fe = ((de = (ue = h == null ? void 0 : h.getReport()) == null ? void 0 : ue.webRTCStats) == null ? void 0 : de.avgRtt) ?? 0;
|
|
171
|
+
F = fe > 0 ? Math.round(fe * 1e3) : 0;
|
|
172
172
|
}
|
|
173
|
-
const
|
|
174
|
-
(
|
|
173
|
+
const D = V > 0 ? V + (p ?? 0) + F : void 0, w = D !== void 0 && T !== void 0 ? D - T : void 0;
|
|
174
|
+
(le = n.onFirstAudioDetected) == null || le.call(n, { latency: D, networkLatency: w });
|
|
175
175
|
}
|
|
176
|
-
)), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n,
|
|
176
|
+
)), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, L), K || (K = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (s = n.onConnectionStateChange) == null || s.call(n, A.Connected, "livekit:track-subscribed")), h = He(
|
|
177
177
|
() => e.getRTCStatsReport(),
|
|
178
178
|
() => E,
|
|
179
|
-
|
|
180
|
-
(p,
|
|
181
|
-
i(`Video state change: ${p}`), p ===
|
|
179
|
+
Ze,
|
|
180
|
+
(p, T) => {
|
|
181
|
+
i(`Video state change: ${p}`), p === b.Start ? (R && (clearTimeout(R), R = null, i("Track subscription timeout cleared")), be()) : p === b.Stop && ie(T);
|
|
182
182
|
}
|
|
183
183
|
), h.start());
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function Pe(e, t, o) {
|
|
186
186
|
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (S == null || S.destroy(), S = null), e.kind === "video" && (ie(h == null ? void 0 : h.getReport()), h == null || h.stop(), h = null);
|
|
187
187
|
}
|
|
188
188
|
function oe(e, t) {
|
|
189
189
|
var r;
|
|
190
|
-
const o =
|
|
190
|
+
const o = on[e];
|
|
191
191
|
o && ((r = n.onMessage) == null || r.call(n, o, { event: o, ...t }));
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function q(e, t) {
|
|
194
194
|
var o, r, c, d;
|
|
195
|
-
if (e ===
|
|
195
|
+
if (e === f.ToolCallStarted) {
|
|
196
196
|
const s = t;
|
|
197
|
-
|
|
197
|
+
y.set(s.call_id, {
|
|
198
198
|
call: {
|
|
199
199
|
callId: s.call_id,
|
|
200
200
|
name: s.name,
|
|
201
201
|
executionMode: s.execution_mode === "async" ? "async" : "blocking"
|
|
202
202
|
},
|
|
203
203
|
interruptible: s.interruptible === !0,
|
|
204
|
-
turnId: s.turn_id ??
|
|
205
|
-
}),
|
|
204
|
+
turnId: s.turn_id ?? x
|
|
205
|
+
}), N(), z(), M = m.ToolActive, (o = n.onAgentActivityStateChange) == null || o.call(n, m.ToolActive), (r = n.onToolEvent) == null || r.call(n, f.ToolCallStarted, s);
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
-
if (e ===
|
|
208
|
+
if (e === f.ToolCallDone) {
|
|
209
209
|
const s = t;
|
|
210
|
-
re(s.call_id), (c = n.onToolEvent) == null || c.call(n,
|
|
210
|
+
re(s.call_id), (c = n.onToolEvent) == null || c.call(n, f.ToolCallDone, s);
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
|
-
if (e ===
|
|
213
|
+
if (e === f.ToolCallError) {
|
|
214
214
|
const s = t;
|
|
215
|
-
re(s.call_id), (d = n.onToolEvent) == null || d.call(n,
|
|
215
|
+
re(s.call_id), (d = n.onToolEvent) == null || d.call(n, f.ToolCallError, s);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
function re(e) {
|
|
219
|
-
|
|
219
|
+
y.delete(e) && (N(), z());
|
|
220
220
|
}
|
|
221
221
|
function Me(e) {
|
|
222
222
|
let t = !1;
|
|
223
|
-
for (const [o, r] of
|
|
224
|
-
r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (
|
|
225
|
-
t && (
|
|
223
|
+
for (const [o, r] of y)
|
|
224
|
+
r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (y.delete(o), t = !0));
|
|
225
|
+
t && (N(), z());
|
|
226
226
|
}
|
|
227
|
-
function
|
|
227
|
+
function N() {
|
|
228
228
|
var t;
|
|
229
|
-
const e = ![...
|
|
230
|
-
e !==
|
|
229
|
+
const e = ![...y.values()].some(({ call: o }) => o.executionMode === "blocking");
|
|
230
|
+
e !== W && (W = e, (t = n.onInterruptibleChange) == null || t.call(n, e));
|
|
231
231
|
}
|
|
232
232
|
function z() {
|
|
233
233
|
var e;
|
|
234
234
|
(e = n.onRunningToolCallsChange) == null || e.call(
|
|
235
235
|
n,
|
|
236
|
-
|
|
236
|
+
y.size === 0 ? rn : [...y.values()].map(({ call: t }) => t)
|
|
237
237
|
);
|
|
238
238
|
}
|
|
239
239
|
function ke(e, t) {
|
|
240
240
|
var o, r, c;
|
|
241
|
-
if (e ===
|
|
241
|
+
if (e === f.StreamVideoCreated) {
|
|
242
242
|
M = m.Talking, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Talking), S == null || S.arm({
|
|
243
243
|
sttLatency: (r = t == null ? void 0 : t.stt) == null ? void 0 : r.latency,
|
|
244
244
|
serviceLatency: t == null ? void 0 : t.serviceLatency
|
|
245
245
|
});
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
|
-
if (
|
|
248
|
+
if (y.size > 0) {
|
|
249
249
|
M !== m.ToolActive && (M = m.ToolActive, (c = n.onAgentActivityStateChange) == null || c.call(n, m.ToolActive));
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
function B(e, t) {
|
|
254
|
-
var d, s, p,
|
|
254
|
+
var d, s, p, T;
|
|
255
255
|
const o = ((s = (d = h == null ? void 0 : h.getReport()) == null ? void 0 : d.webRTCStats) == null ? void 0 : s.avgRtt) ?? 0, r = o > 0 ? Math.round(o / 2 * 1e3) : 0, c = { ...t, downstreamNetworkLatency: r };
|
|
256
256
|
u.debug && ((p = t == null ? void 0 : t.metadata) != null && p.sentiment) && (c.sentiment = {
|
|
257
257
|
id: t.metadata.sentiment.id,
|
|
258
258
|
name: t.metadata.sentiment.sentiment
|
|
259
|
-
}), (
|
|
259
|
+
}), (T = n.onMessage) == null || T.call(n, e, c), ke(e, t);
|
|
260
260
|
}
|
|
261
261
|
function Ie(e, t) {
|
|
262
262
|
var o;
|
|
263
|
-
(o = n.onMessage) == null || o.call(n,
|
|
263
|
+
(o = n.onMessage) == null || o.call(n, J.Transcribe, { event: J.Transcribe, ...t }), queueMicrotask(() => {
|
|
264
264
|
var r;
|
|
265
265
|
(r = n.onAgentActivityStateChange) == null || r.call(n, m.Loading);
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
268
|
function _e(e, t) {
|
|
269
269
|
var o;
|
|
270
|
-
|
|
270
|
+
x = (t == null ? void 0 : t.turn_id) ?? null, M = m.Loading, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Loading);
|
|
271
271
|
}
|
|
272
272
|
function $e(e, t) {
|
|
273
273
|
var r;
|
|
274
274
|
const o = (t == null ? void 0 : t.turn_id) ?? null;
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
const
|
|
278
|
-
[
|
|
279
|
-
[
|
|
280
|
-
[
|
|
281
|
-
[
|
|
282
|
-
[
|
|
283
|
-
[
|
|
284
|
-
[
|
|
285
|
-
[
|
|
286
|
-
[
|
|
287
|
-
[
|
|
288
|
-
[
|
|
289
|
-
[
|
|
275
|
+
x !== null && o !== null && o < x || (Me(o), M = m.Idle, (r = n.onAgentActivityStateChange) == null || r.call(n, m.Idle));
|
|
276
|
+
}
|
|
277
|
+
const De = {
|
|
278
|
+
[f.ChatAnswer]: oe,
|
|
279
|
+
[f.ChatPartial]: oe,
|
|
280
|
+
[f.ToolCallStarted]: q,
|
|
281
|
+
[f.ToolCallDone]: q,
|
|
282
|
+
[f.ToolCallError]: q,
|
|
283
|
+
[f.StreamVideoCreated]: B,
|
|
284
|
+
[f.StreamVideoDone]: B,
|
|
285
|
+
[f.StreamVideoError]: B,
|
|
286
|
+
[f.StreamVideoRejected]: B,
|
|
287
|
+
[f.ChatAudioTranscribed]: Ie,
|
|
288
|
+
[f.TurnStarted]: _e,
|
|
289
|
+
[f.TurnEnded]: $e
|
|
290
290
|
};
|
|
291
|
-
function
|
|
291
|
+
function Ke(e, t, o, r) {
|
|
292
292
|
const c = new TextDecoder().decode(e);
|
|
293
293
|
try {
|
|
294
294
|
const d = JSON.parse(c), s = r || d.subject;
|
|
295
295
|
if (i("Data received:", { subject: s, data: d }), !s) return;
|
|
296
|
-
const p =
|
|
296
|
+
const p = De[s];
|
|
297
297
|
p == null || p(s, d);
|
|
298
298
|
} catch (d) {
|
|
299
299
|
i("Failed to parse data channel message:", d);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
|
-
function
|
|
302
|
+
function xe(e) {
|
|
303
303
|
var t;
|
|
304
|
-
i("Media devices error:", e), (t = n.onError) == null || t.call(n,
|
|
304
|
+
i("Media devices error:", e), (t = n.onError) == null || t.call(n, O(), { sessionId: v });
|
|
305
305
|
}
|
|
306
306
|
function Ve(e) {
|
|
307
307
|
var t;
|
|
308
|
-
i("Encryption error:", e), (t = n.onError) == null || t.call(n,
|
|
308
|
+
i("Encryption error:", e), (t = n.onError) == null || t.call(n, O(), { sessionId: v });
|
|
309
309
|
}
|
|
310
310
|
function Fe(e, t, o) {
|
|
311
311
|
i("Track subscription failed:", { trackSid: e, participant: t, reason: o });
|
|
312
312
|
}
|
|
313
|
-
function
|
|
313
|
+
function Ue(e, t, o) {
|
|
314
314
|
for (const [r, c] of o)
|
|
315
315
|
if (c.source === t && c.track) {
|
|
316
316
|
const d = c.track.mediaStreamTrack;
|
|
@@ -320,7 +320,7 @@ async function dn(l, C, u) {
|
|
|
320
320
|
return null;
|
|
321
321
|
}
|
|
322
322
|
async function ae(e, t, o, r, c, d) {
|
|
323
|
-
var
|
|
323
|
+
var V, F, D;
|
|
324
324
|
if (!E || !a)
|
|
325
325
|
throw i(`Room is not connected, cannot publish ${r} stream`), new Error("Room is not connected");
|
|
326
326
|
if (e.isPublishing) {
|
|
@@ -330,15 +330,15 @@ async function dn(l, C, u) {
|
|
|
330
330
|
const s = o(t);
|
|
331
331
|
if (s.length === 0)
|
|
332
332
|
throw new Error(`No ${r} track found in the provided MediaStream`);
|
|
333
|
-
const p = s[0],
|
|
334
|
-
if (
|
|
333
|
+
const p = s[0], T = Ue(p, r, c());
|
|
334
|
+
if (T) {
|
|
335
335
|
i(`${r} track is already published, skipping`, {
|
|
336
336
|
trackId: p.id,
|
|
337
|
-
publishedTrackId: (
|
|
338
|
-
}), e.publication =
|
|
337
|
+
publishedTrackId: (F = (V = T.track) == null ? void 0 : V.mediaStreamTrack) == null ? void 0 : F.id
|
|
338
|
+
}), e.publication = T;
|
|
339
339
|
return;
|
|
340
340
|
}
|
|
341
|
-
if ((
|
|
341
|
+
if ((D = e.publication) != null && D.track) {
|
|
342
342
|
const w = e.publication.track.mediaStreamTrack;
|
|
343
343
|
w !== p && (w == null ? void 0 : w.id) !== p.id && (i(`Unpublishing existing ${r} track before publishing new one`), await d());
|
|
344
344
|
}
|
|
@@ -361,93 +361,73 @@ async function dn(l, C, u) {
|
|
|
361
361
|
e.publication = null;
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
|
-
async function
|
|
364
|
+
async function Oe(e) {
|
|
365
365
|
return ae(
|
|
366
|
-
|
|
366
|
+
P,
|
|
367
367
|
e,
|
|
368
368
|
(t) => t.getAudioTracks(),
|
|
369
369
|
Y.Source.Microphone,
|
|
370
370
|
() => a.localParticipant.audioTrackPublications,
|
|
371
|
-
|
|
371
|
+
G
|
|
372
372
|
);
|
|
373
373
|
}
|
|
374
|
-
async function
|
|
375
|
-
return ce(
|
|
374
|
+
async function G() {
|
|
375
|
+
return ce(P, "Microphone");
|
|
376
376
|
}
|
|
377
|
-
async function
|
|
377
|
+
async function je(e) {
|
|
378
378
|
if (!E || !a)
|
|
379
379
|
throw i("Cannot replace microphone track: room is not connected"), new Error("Room is not connected");
|
|
380
380
|
if (e.kind !== "audio")
|
|
381
381
|
throw i("Cannot replace microphone track: not an audio track", { kind: e.kind }), new Error("Microphone track must be an audio track");
|
|
382
|
-
if (
|
|
382
|
+
if (P.isPublishing)
|
|
383
383
|
throw i("Cannot replace microphone track: publish in progress"), new Error("Microphone publish in progress");
|
|
384
|
-
const t =
|
|
384
|
+
const t = P.publication;
|
|
385
385
|
if (!t || !t.track)
|
|
386
386
|
throw i("Cannot replace microphone track: no publication to replace"), new Error("No microphone publication to replace");
|
|
387
387
|
try {
|
|
388
|
-
|
|
388
|
+
P.isPublishing = !0, await t.track.replaceTrack(e), i("Microphone track replaced", { trackId: e.id, trackSid: t.trackSid });
|
|
389
389
|
} finally {
|
|
390
|
-
|
|
390
|
+
P.isPublishing = !1;
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
async function
|
|
393
|
+
async function Ne(e) {
|
|
394
394
|
return ae(
|
|
395
|
-
|
|
395
|
+
Q,
|
|
396
396
|
e,
|
|
397
397
|
(t) => t.getVideoTracks(),
|
|
398
398
|
Y.Source.Camera,
|
|
399
399
|
() => a.localParticipant.videoTrackPublications,
|
|
400
|
-
|
|
400
|
+
H
|
|
401
401
|
);
|
|
402
402
|
}
|
|
403
|
-
async function
|
|
404
|
-
return ce(
|
|
403
|
+
async function H() {
|
|
404
|
+
return ce(Q, "Camera");
|
|
405
405
|
}
|
|
406
406
|
function ze() {
|
|
407
|
-
|
|
407
|
+
L && (L.getTracks().forEach((e) => e.stop()), L = null);
|
|
408
408
|
}
|
|
409
|
-
async function
|
|
409
|
+
async function X(e, t) {
|
|
410
410
|
var o, r;
|
|
411
411
|
if (!E || !a) {
|
|
412
|
-
i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n,
|
|
413
|
-
sessionId:
|
|
412
|
+
i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n, O(), {
|
|
413
|
+
sessionId: v
|
|
414
414
|
});
|
|
415
415
|
return;
|
|
416
416
|
}
|
|
417
417
|
try {
|
|
418
|
-
await a.localParticipant.sendText(
|
|
418
|
+
await a.localParticipant.sendText(t, { topic: e }), i("Message sent successfully:", t);
|
|
419
419
|
} catch (c) {
|
|
420
|
-
i("Failed to send message:", c), (r = n.onError) == null || r.call(n,
|
|
420
|
+
i("Failed to send message:", c), (r = n.onError) == null || r.call(n, O(), { sessionId: v });
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
async function se(e) {
|
|
424
|
-
var t;
|
|
425
|
-
try {
|
|
426
|
-
const r = JSON.parse(e).topic;
|
|
427
|
-
return J("", r);
|
|
428
|
-
} catch (o) {
|
|
429
|
-
i("Failed to send data channel message:", o), (t = n.onError) == null || t.call(n, x(), { sessionId: T });
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
function Be(e) {
|
|
433
|
-
return J(
|
|
434
|
-
e,
|
|
435
|
-
"lk.chat"
|
|
436
|
-
/* Chat */
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
423
|
async function Z(e) {
|
|
440
424
|
var t, o;
|
|
441
|
-
|
|
425
|
+
R && (clearTimeout(R), R = null), S == null || S.destroy(), S = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, A.Disconnecting, e), await Promise.all([G(), H()]), await a.disconnect()), ze(), E = !1, K = !1, y.size > 0 && (y.clear(), N(), z()), x = null, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Idle), M = m.Idle;
|
|
442
426
|
}
|
|
443
427
|
return {
|
|
444
428
|
speak(e) {
|
|
445
429
|
const t = typeof e == "string" ? e : JSON.stringify(e);
|
|
446
|
-
return
|
|
447
|
-
t,
|
|
448
|
-
"did.speak"
|
|
449
|
-
/* Speak */
|
|
450
|
-
);
|
|
430
|
+
return X(ge.Speak, t);
|
|
451
431
|
},
|
|
452
432
|
disconnect: () => Z("user:disconnect"),
|
|
453
433
|
async reconnect() {
|
|
@@ -458,16 +438,16 @@ async function dn(l, C, u) {
|
|
|
458
438
|
}
|
|
459
439
|
if (!a || !$ || !_)
|
|
460
440
|
throw i("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
461
|
-
i("Reconnecting to LiveKit room, state:", a.state),
|
|
441
|
+
i("Reconnecting to LiveKit room, state:", a.state), K = !1, (e = n.onConnectionStateChange) == null || e.call(n, A.Connecting, "user:reconnect");
|
|
462
442
|
try {
|
|
463
443
|
if (await a.connect($, _), i("Room reconnected"), E = !0, a.remoteParticipants.size === 0) {
|
|
464
444
|
if (i("Waiting for agent to join..."), !await new Promise((r) => {
|
|
465
445
|
const c = setTimeout(() => {
|
|
466
|
-
a == null || a.off(
|
|
446
|
+
a == null || a.off(g.ParticipantConnected, d), r(!1);
|
|
467
447
|
}, 5e3), d = () => {
|
|
468
|
-
clearTimeout(c), a == null || a.off(
|
|
448
|
+
clearTimeout(c), a == null || a.off(g.ParticipantConnected, d), r(!0);
|
|
469
449
|
};
|
|
470
|
-
a == null || a.on(
|
|
450
|
+
a == null || a.on(g.ParticipantConnected, d);
|
|
471
451
|
}))
|
|
472
452
|
throw i("Agent did not join within timeout"), await a.disconnect(), new Error("Agent did not rejoin the room");
|
|
473
453
|
i("Agent joined, reconnection successful");
|
|
@@ -476,31 +456,14 @@ async function dn(l, C, u) {
|
|
|
476
456
|
throw i("Failed to reconnect:", o), (t = n.onConnectionStateChange) == null || t.call(n, A.Fail, "user:reconnect-failed"), o;
|
|
477
457
|
}
|
|
478
458
|
},
|
|
479
|
-
sendDataChannelMessage:
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
unpublishCameraStream: X,
|
|
459
|
+
sendDataChannelMessage: X,
|
|
460
|
+
publishMicrophoneStream: Oe,
|
|
461
|
+
unpublishMicrophoneStream: G,
|
|
462
|
+
replaceMicrophoneTrack: je,
|
|
463
|
+
publishCameraStream: Ne,
|
|
464
|
+
unpublishCameraStream: H,
|
|
486
465
|
interrupt(e) {
|
|
487
|
-
e !== "text" &&
|
|
488
|
-
topic: "did.interrupt"
|
|
489
|
-
/* Interrupt */
|
|
490
|
-
}));
|
|
491
|
-
},
|
|
492
|
-
/**
|
|
493
|
-
* Switch the STT language mid-session.
|
|
494
|
-
* Only available for Expressive (V4) agents.
|
|
495
|
-
* @param language - Language name or BCP-47 code (e.g. "English" or "en-US").
|
|
496
|
-
* @returns Promise that resolves after the send attempt completes; failures are reported via onError.
|
|
497
|
-
*/
|
|
498
|
-
setSttLanguage(e) {
|
|
499
|
-
return J(
|
|
500
|
-
JSON.stringify({ language: e }),
|
|
501
|
-
"did.stt-language"
|
|
502
|
-
/* SttLanguage */
|
|
503
|
-
);
|
|
466
|
+
e !== "text" && X(ge.Interrupt, "");
|
|
504
467
|
},
|
|
505
468
|
registerRpcMethod(e, t) {
|
|
506
469
|
a == null || a.registerRpcMethod(e, t);
|
|
@@ -508,14 +471,14 @@ async function dn(l, C, u) {
|
|
|
508
471
|
unregisterRpcMethod(e) {
|
|
509
472
|
a == null || a.unregisterRpcMethod(e);
|
|
510
473
|
},
|
|
511
|
-
sessionId:
|
|
512
|
-
streamId:
|
|
474
|
+
sessionId: v,
|
|
475
|
+
streamId: v,
|
|
513
476
|
streamType: ne,
|
|
514
477
|
interruptAvailable: te,
|
|
515
|
-
isInterruptible:
|
|
478
|
+
isInterruptible: W
|
|
516
479
|
};
|
|
517
480
|
}
|
|
518
481
|
export {
|
|
519
|
-
|
|
482
|
+
un as createLiveKitStreamingManager,
|
|
520
483
|
me as handleInitError
|
|
521
484
|
};
|