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