@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.
@@ -1,4 +1,4 @@
1
- import { c as Ne, C as B, S as p, a as ze, b as Be, A as m, d as Je, l as pe, e as Qe, t as We, f as w, g as U, h as qe, i as He, j as P, n as Xe } from "./index-BLnfl1xQ.js";
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
- [p.ChatAnswer]: B.Answer,
34
- [p.ChatPartial]: B.Partial
35
- }, he = 2e4;
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-BLnfl1xQ.js").then((l) => l.y);
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 on = {
46
- excellent: U.Strong,
47
- good: U.Strong,
48
- poor: U.Weak,
49
- lost: U.Unknown,
50
- unknown: U.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 = ze(u.debug || !1, "LiveKitStreamingManager"), { Room: M, RoomEvent: f, ConnectionState: k, Track: Z } = await tn(), { callbacks: n, auth: ge, baseURL: me, analytics: G } = u;
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 = Be.Fluent;
61
- let R = null;
62
- const L = { isPublishing: !1, publication: null }, J = { isPublishing: !1, publication: null };
63
- let g = null, S = null, j = null, D = !1;
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 O = /* @__PURE__ */ new Set();
70
+ const j = /* @__PURE__ */ new Set();
71
71
  let N = null;
72
- const Ce = en(ge, me || Je, l, n.onError);
73
- let T, I, $, ee = !0;
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: o, session_url: r, interrupt_enabled: s } = e;
80
- (ce = n.onStreamCreated) == null || ce.call(n, { session_id: t, stream_id: t, agent_id: l }), T = t, I = o, $ = r, ee = s ?? !0, await a.prepareConnection($, I);
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 || !T)
84
+ if (!$ || !I || !y)
85
85
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
86
- a.on(f.ConnectionStateChanged, ye).on(f.ConnectionQualityChanged, ve).on(f.ParticipantConnected, we).on(f.ParticipantDisconnected, Ae).on(f.TrackSubscribed, Pe).on(f.TrackUnsubscribed, Re).on(f.DataReceived, $e).on(f.MediaDevicesError, _e).on(f.TranscriptionReceived, Se).on(f.EncryptionError, Ke).on(f.TrackSubscriptionFailed, De);
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 && pe.update();
88
+ t != null && t.isLocal && ge.update();
89
89
  }
90
- async function Te() {
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"), Te(), E = setTimeout(() => {
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 ${he / 1e3} seconds after connect`
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: T
109
- }), (t = n.onError) == null || t.call(n, e, { sessionId: T }), X("internal:track-subscription-timeout");
110
- }, he);
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 ye(e) {
118
- var t, o, r, s;
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, L.publication = null, J.publication = null, (o = n.onConnectionStateChange) == null || o.call(n, w.Disconnected, "livekit:disconnected");
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..."), (r = n.onConnectionStateChange) == null || r.call(n, w.Connecting, "livekit: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 o;
139
- i("Connection quality:", e), t != null && t.isLocal && ((o = n.onConnectivityStateChange) == null || o.call(n, on[e]));
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
- j !== P.Start && (i("CALLBACK: onVideoStateChange(Start)"), j = P.Start, (e = n.onVideoStateChange) == null || e.call(n, P.Start));
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
- j !== P.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), j = P.Stop, (t = n.onVideoStateChange) == null || t.call(n, P.Stop, e));
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, o) {
156
- var s, d, h;
157
- i(`Track subscribed: ${e.kind} from ${o.identity}`);
158
- const r = e.mediaStreamTrack;
159
- if (!r) {
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
- R ? (R.addTrack(r), i(`Added ${e.kind} track to shared MediaStream`)) : (R = new MediaStream([r]), i(`Created shared MediaStream with ${e.kind} track`)), e.kind === "audio" && (S = He(
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: y }) => {
165
+ ({ sttLatency: c, serviceLatency: T }) => {
166
166
  var se, de, ue;
167
- const F = pe.get(!0);
167
+ const F = ge.get(!0);
168
168
  let x = 0;
169
169
  if (c) {
170
- const le = ((de = (se = g == null ? void 0 : g.getReport()) == null ? void 0 : se.webRTCStats) == null ? void 0 : de.avgRtt) ?? 0;
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 && y !== void 0 ? _ - y : 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, R), D || (D = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (h = n.onConnectionStateChange) == null || h.call(n, w.Connected, "livekit:track-subscribed")), g = qe(
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, y) => {
181
- i(`Video state change: ${c}`), c === P.Start ? (E && (clearTimeout(E), E = null, i("Track subscription timeout cleared")), Ee()) : c === P.Stop && ne(y);
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
- ), g.start());
183
+ ), h.start());
184
184
  }
185
- function Re(e, t, o) {
186
- i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (S == null || S.destroy(), S = null), e.kind === "video" && (ne(g == null ? void 0 : g.getReport()), g == null || g.stop(), g = null);
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 r;
190
- const o = nn[e];
191
- o && ((r = n.onMessage) == null || r.call(n, o, { event: o, ...t }));
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 Q(e, t) {
194
- var o, r, s, d, h;
195
- if (e === p.ToolCallStarted) {
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, (o = n.onInterruptibleChange) == null || o.call(n, V), O.add(c.call_id), b = m.ToolActive, (r = n.onAgentActivityStateChange) == null || r.call(n, m.ToolActive), (s = n.onToolEvent) == null || s.call(n, p.ToolCallStarted, c);
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 === p.ToolCallDone) {
200
+ if (e === g.ToolCallDone) {
201
201
  const c = t;
202
- ie(c.call_id), (d = n.onToolEvent) == null || d.call(n, p.ToolCallDone, c);
202
+ ie(c.call_id), (d = n.onToolEvent) == null || d.call(n, g.ToolCallDone, c);
203
203
  return;
204
204
  }
205
- if (e === p.ToolCallError) {
205
+ if (e === g.ToolCallError) {
206
206
  const c = t;
207
- ie(c.call_id), (h = n.onToolEvent) == null || h.call(n, p.ToolCallError, c);
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
- O.delete(e);
211
+ j.delete(e);
212
212
  }
213
- function Le(e, t) {
214
- var o, r, s, d, h;
215
- if (V = ((o = t.metadata) == null ? void 0 : o.interruptible) !== !1, (r = n.onInterruptibleChange) == null || r.call(n, V), e === p.StreamVideoCreated) {
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 (O.size > 0) {
223
- b !== m.ToolActive && (b = m.ToolActive, (h = n.onAgentActivityStateChange) == null || h.call(n, 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 z(e, t) {
228
- var d, h, c, y;
229
- const o = ((h = (d = g == null ? void 0 : g.getReport()) == null ? void 0 : d.webRTCStats) == null ? void 0 : h.avgRtt) ?? 0, r = o > 0 ? Math.round(o / 2 * 1e3) : 0, s = { ...t, downstreamNetworkLatency: r };
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
- }), (y = n.onMessage) == null || y.call(n, e, s), Le(e, t);
233
+ }), (T = n.onMessage) == null || T.call(n, e, s), Re(e, t);
234
234
  }
235
235
  function be(e, t) {
236
- var o;
237
- (o = n.onMessage) == null || o.call(n, B.Transcribe, { event: B.Transcribe, ...t }), queueMicrotask(() => {
238
- var r;
239
- (r = n.onAgentActivityStateChange) == null || r.call(n, m.Loading);
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 o;
244
- N = (t == null ? void 0 : t.turn_id) ?? null, b = m.Loading, (o = n.onAgentActivityStateChange) == null || o.call(n, 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 r;
248
- const o = (t == null ? void 0 : t.turn_id) ?? null;
249
- N !== null && o !== null && o < N || (b = m.Idle, (r = n.onAgentActivityStateChange) == null || r.call(n, m.Idle));
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
- [p.ChatAnswer]: te,
253
- [p.ChatPartial]: te,
254
- [p.ToolCallStarted]: Q,
255
- [p.ToolCallDone]: Q,
256
- [p.ToolCallError]: Q,
257
- [p.StreamVideoCreated]: z,
258
- [p.StreamVideoDone]: z,
259
- [p.StreamVideoError]: z,
260
- [p.StreamVideoRejected]: z,
261
- [p.ChatAudioTranscribed]: be,
262
- [p.TurnStarted]: Me,
263
- [p.TurnEnded]: ke
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, o, r) {
265
+ function $e(e, t, r, o) {
266
266
  const s = new TextDecoder().decode(e);
267
267
  try {
268
- const d = JSON.parse(s), h = r || d.subject;
269
- if (i("Data received:", { subject: h, data: d }), !h) return;
270
- const c = Ie[h];
271
- c == null || c(h, d);
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: T });
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: T });
282
+ i("Encryption error:", e), (t = n.onError) == null || t.call(n, K(), { sessionId: y });
283
283
  }
284
- function De(e, t, o) {
285
- i("Track subscription failed:", { trackSid: e, participant: t, reason: o });
284
+ function De(e, t, r) {
285
+ i("Track subscription failed:", { trackSid: e, participant: t, reason: r });
286
286
  }
287
- function Ve(e, t, o) {
288
- for (const [r, s] of o)
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 oe(e, t, o, r, s, d) {
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 ${r} stream`), new Error("Room is not connected");
299
+ throw i(`Room is not connected, cannot publish ${o} stream`), new Error("Room is not connected");
300
300
  if (e.isPublishing) {
301
- i(`${r} publish already in progress, skipping`);
301
+ i(`${o} publish already in progress, skipping`);
302
302
  return;
303
303
  }
304
- const h = o(t);
305
- if (h.length === 0)
306
- throw new Error(`No ${r} track found in the provided MediaStream`);
307
- const c = h[0], y = Ve(c, r, s());
308
- if (y) {
309
- i(`${r} track is already published, skipping`, {
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 = y.track) == null ? void 0 : F.mediaStreamTrack) == null ? void 0 : x.id
312
- }), e.publication = y;
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 ${r} track before publishing new one`), await d());
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 ${r} track from provided MediaStream`, { trackId: c.id }), e.isPublishing = !0;
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: r }), i(`${r} track published successfully`, { trackSid: e.publication.trackSid });
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 ${r} track:`, v), v;
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 re(e, t) {
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 (o) {
333
- i(`Error unpublishing ${t} track:`, o);
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 oe(
340
- L,
339
+ return re(
340
+ R,
341
341
  e,
342
342
  (t) => t.getAudioTracks(),
343
343
  Z.Source.Microphone,
344
344
  () => a.localParticipant.audioTrackPublications,
345
- W
345
+ q
346
346
  );
347
347
  }
348
- async function W() {
349
- return re(L, "Microphone");
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 (L.isPublishing)
356
+ if (R.isPublishing)
357
357
  throw i("Cannot replace microphone track: publish in progress"), new Error("Microphone publish in progress");
358
- const t = L.publication;
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
- L.isPublishing = !0, await t.track.replaceTrack(e), i("Microphone track replaced", { trackId: e.id, trackSid: t.trackSid });
362
+ R.isPublishing = !0, await t.track.replaceTrack(e), i("Microphone track replaced", { trackId: e.id, trackSid: t.trackSid });
363
363
  } finally {
364
- L.isPublishing = !1;
364
+ R.isPublishing = !1;
365
365
  }
366
366
  }
367
- async function Ue(e) {
368
- return oe(
369
- J,
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
- q
374
+ H
375
375
  );
376
376
  }
377
- async function q() {
378
- return re(J, "Camera");
377
+ async function H() {
378
+ return oe(Q, "Camera");
379
379
  }
380
- function je() {
381
- R && (R.getTracks().forEach((e) => e.stop()), R = null);
380
+ function Ue() {
381
+ L && (L.getTracks().forEach((e) => e.stop()), L = null);
382
382
  }
383
- async function H(e, t) {
384
- var o, r;
383
+ async function z(e, t) {
384
+ var r, o;
385
385
  if (!A || !a) {
386
- i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n, K(), {
387
- sessionId: T
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), (r = n.onError) == null || r.call(n, K(), { sessionId: T });
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 r = JSON.parse(e).topic;
401
- return H("", r);
402
- } catch (o) {
403
- i("Failed to send data channel message:", o), (t = n.onError) == null || t.call(n, K(), { sessionId: T });
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 Oe(e) {
407
- return H(
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, o;
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([W(), q()]), await a.disconnect()), je(), A = !1, D = !1, O.clear(), N = null, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Idle), b = m.Idle;
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 H(
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((r) => {
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), r(!1);
440
+ a == null || a.off(f.ParticipantConnected, d), o(!1);
441
441
  }, 5e3), d = () => {
442
- clearTimeout(s), a == null || a.off(f.ParticipantConnected, d), r(!0);
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 (o) {
450
- throw i("Failed to reconnect:", o), (t = n.onConnectionStateChange) == null || t.call(n, w.Fail, "user:reconnect-failed"), o;
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: Oe,
454
+ sendTextMessage: je,
455
455
  publishMicrophoneStream: Fe,
456
- unpublishMicrophoneStream: W,
456
+ unpublishMicrophoneStream: q,
457
457
  replaceMicrophoneTrack: xe,
458
- publishCameraStream: Ue,
459
- unpublishCameraStream: q,
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: T,
473
- streamId: T,
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> & {
@@ -39,6 +39,7 @@ export interface Agent {
39
39
  advanced_settings?: {
40
40
  ui_debug_mode?: boolean;
41
41
  vm_account_id?: string;
42
+ closed_captions_enabled?: boolean;
42
43
  };
43
44
  }
44
45
  export interface AgentsAPI {