@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.
@@ -1,12 +1,12 @@
1
- import { c as Je, C as Q, S as g, a as Qe, b as We, A as m, d as qe, l as fe, e as Ge, t as He, f as A, g as N, h as Xe, i as Ze, j as R, n as Ye } from "./index-BLArKcFJ.js";
2
- function en() {
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 nn() {
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 tn() {
19
- const l = {}, C = en();
18
+ function nn() {
19
+ const l = {}, C = Ye();
20
20
  C && (l.timezone = C);
21
- const u = nn();
21
+ const u = en();
22
22
  return u && (l.device = u), l;
23
23
  }
24
- function on(l, C, u, i) {
25
- const k = Je(l, `${C}/v2/agents/${u}`, i);
24
+ function tn(l, C, u, i) {
25
+ const k = Be(l, `${C}/v2/agents/${u}`, i);
26
26
  return {
27
- async createStream(f) {
28
- return k.post("/sessions", f);
27
+ async createStream(g) {
28
+ return k.post("/sessions", g);
29
29
  }
30
30
  };
31
31
  }
32
- const rn = {
33
- [g.ChatAnswer]: Q.Answer,
34
- [g.ChatPartial]: Q.Partial
35
- }, he = 2e4, an = [];
36
- async function cn() {
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-BLArKcFJ.js").then((l) => l.z);
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 sn = {
46
- excellent: N.Strong,
47
- good: N.Strong,
48
- poor: N.Weak,
49
- lost: N.Unknown,
50
- unknown: N.Unknown
51
- }, x = (l = "Stream Error") => new Ge(l);
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 dn(l, C, u) {
57
- var ue;
58
- const i = Qe(u.debug || !1, "LiveKitStreamingManager"), { Room: k, RoomEvent: f, ConnectionState: I, Track: Y } = await cn(), { callbacks: n, auth: Ce, baseURL: Se, analytics: ee } = u;
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 = We.Fluent;
61
- let P = null;
62
- const b = { isPublishing: !1, publication: null }, W = { isPublishing: !1, publication: null };
63
- let h = null, S = null, U = null, D = !1;
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 L = null, M = m.Idle, q = !0;
70
- const v = /* @__PURE__ */ new Map();
71
- let V = null;
72
- const Te = on(Ce, Se || qe, l, n.onError);
73
- let T, _, $, te = !0;
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
- (ue = n.onStreamCreated) == null || ue.call(n, { session_id: t, stream_id: t, agent_id: l }), T = t, _ = o, $ = r, te = c ?? !0, await a.prepareConnection($, _);
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 (!$ || !_ || !T)
84
+ if (!$ || !_ || !v)
85
85
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
86
- a.on(f.ConnectionStateChanged, we).on(f.ConnectionQualityChanged, Ae).on(f.ParticipantConnected, Ee).on(f.ParticipantDisconnected, Le).on(f.TrackSubscribed, Pe).on(f.TrackUnsubscribed, be).on(f.DataReceived, xe).on(f.MediaDevicesError, De).on(f.TranscriptionReceived, ye).on(f.EncryptionError, Ve).on(f.TrackSubscriptionFailed, Fe);
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 && fe.update();
88
+ t != null && t.isLocal && pe.update();
89
89
  }
90
90
  async function ve() {
91
- const e = tn();
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(), L = setTimeout(() => {
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
- ), L = null;
105
- const e = x("Track subscription timeout");
104
+ ), R = null;
105
+ const e = O("Track subscription timeout");
106
106
  ee.track("connectivity-error", {
107
- error: He(e),
108
- sessionId: T
109
- }), (t = n.onError) == null || t.call(n, e, { sessionId: T }), Z("internal:track-subscription-timeout");
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, D = !1, b.publication = null, W.publication = null, (o = n.onConnectionStateChange) == null || o.call(n, A.Disconnected, "livekit:disconnected");
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, sn[e]));
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 Le(e) {
144
+ function Re(e) {
145
145
  i("Participant disconnected:", e.identity), Z("livekit:participant-disconnected");
146
146
  }
147
- function Re() {
147
+ function be() {
148
148
  var e;
149
- U !== R.Start && (i("CALLBACK: onVideoStateChange(Start)"), U = R.Start, (e = n.onVideoStateChange) == null || e.call(n, R.Start));
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
- U !== R.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), U = R.Stop, (t = n.onVideoStateChange) == null || t.call(n, R.Stop, e));
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 Pe(e, t, o) {
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
- P ? (P.addTrack(r), i(`Added ${e.kind} track to shared MediaStream`)) : (P = new MediaStream([r]), i(`Created shared MediaStream with ${e.kind} track`)), e.kind === "audio" && (S = Ze(
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: y }) => {
166
- var de, le, ge;
167
- const F = fe.get(!0);
168
- let O = 0;
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 pe = ((le = (de = h == null ? void 0 : h.getReport()) == null ? void 0 : de.webRTCStats) == null ? void 0 : le.avgRtt) ?? 0;
171
- O = pe > 0 ? Math.round(pe * 1e3) : 0;
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 K = F > 0 ? F + (p ?? 0) + O : void 0, w = K !== void 0 && y !== void 0 ? K - y : void 0;
174
- (ge = n.onFirstAudioDetected) == null || ge.call(n, { latency: K, networkLatency: w });
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, P), D || (D = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (s = n.onConnectionStateChange) == null || s.call(n, A.Connected, "livekit:track-subscribed")), h = Xe(
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
- Ye,
180
- (p, y) => {
181
- i(`Video state change: ${p}`), p === R.Start ? (L && (clearTimeout(L), L = null, i("Track subscription timeout cleared")), Re()) : p === R.Stop && ie(y);
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 be(e, t, o) {
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 = rn[e];
190
+ const o = on[e];
191
191
  o && ((r = n.onMessage) == null || r.call(n, o, { event: o, ...t }));
192
192
  }
193
- function G(e, t) {
193
+ function q(e, t) {
194
194
  var o, r, c, d;
195
- if (e === g.ToolCallStarted) {
195
+ if (e === f.ToolCallStarted) {
196
196
  const s = t;
197
- v.set(s.call_id, {
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 ?? V
205
- }), j(), z(), M = m.ToolActive, (o = n.onAgentActivityStateChange) == null || o.call(n, m.ToolActive), (r = n.onToolEvent) == null || r.call(n, g.ToolCallStarted, s);
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 === g.ToolCallDone) {
208
+ if (e === f.ToolCallDone) {
209
209
  const s = t;
210
- re(s.call_id), (c = n.onToolEvent) == null || c.call(n, g.ToolCallDone, s);
210
+ re(s.call_id), (c = n.onToolEvent) == null || c.call(n, f.ToolCallDone, s);
211
211
  return;
212
212
  }
213
- if (e === g.ToolCallError) {
213
+ if (e === f.ToolCallError) {
214
214
  const s = t;
215
- re(s.call_id), (d = n.onToolEvent) == null || d.call(n, g.ToolCallError, s);
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
- v.delete(e) && (j(), z());
219
+ y.delete(e) && (N(), z());
220
220
  }
221
221
  function Me(e) {
222
222
  let t = !1;
223
- for (const [o, r] of v)
224
- r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (v.delete(o), t = !0));
225
- t && (j(), z());
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 j() {
227
+ function N() {
228
228
  var t;
229
- const e = ![...v.values()].some(({ call: o }) => o.executionMode === "blocking");
230
- e !== q && (q = e, (t = n.onInterruptibleChange) == null || t.call(n, 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
- v.size === 0 ? an : [...v.values()].map(({ call: t }) => t)
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 === g.StreamVideoCreated) {
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 (v.size > 0) {
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, y;
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
- }), (y = n.onMessage) == null || y.call(n, e, c), ke(e, t);
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, Q.Transcribe, { event: Q.Transcribe, ...t }), queueMicrotask(() => {
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
- V = (t == null ? void 0 : t.turn_id) ?? null, M = m.Loading, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Loading);
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
- V !== null && o !== null && o < V || (Me(o), M = m.Idle, (r = n.onAgentActivityStateChange) == null || r.call(n, m.Idle));
276
- }
277
- const Ke = {
278
- [g.ChatAnswer]: oe,
279
- [g.ChatPartial]: oe,
280
- [g.ToolCallStarted]: G,
281
- [g.ToolCallDone]: G,
282
- [g.ToolCallError]: G,
283
- [g.StreamVideoCreated]: B,
284
- [g.StreamVideoDone]: B,
285
- [g.StreamVideoError]: B,
286
- [g.StreamVideoRejected]: B,
287
- [g.ChatAudioTranscribed]: Ie,
288
- [g.TurnStarted]: _e,
289
- [g.TurnEnded]: $e
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 xe(e, t, o, r) {
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 = Ke[s];
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 De(e) {
302
+ function xe(e) {
303
303
  var t;
304
- i("Media devices error:", e), (t = n.onError) == null || t.call(n, x(), { sessionId: T });
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, x(), { sessionId: T });
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 Oe(e, t, o) {
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 F, O, K;
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], y = Oe(p, r, c());
334
- if (y) {
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: (O = (F = y.track) == null ? void 0 : F.mediaStreamTrack) == null ? void 0 : O.id
338
- }), e.publication = y;
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 ((K = e.publication) != null && K.track) {
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 Ne(e) {
364
+ async function Oe(e) {
365
365
  return ae(
366
- b,
366
+ P,
367
367
  e,
368
368
  (t) => t.getAudioTracks(),
369
369
  Y.Source.Microphone,
370
370
  () => a.localParticipant.audioTrackPublications,
371
- H
371
+ G
372
372
  );
373
373
  }
374
- async function H() {
375
- return ce(b, "Microphone");
374
+ async function G() {
375
+ return ce(P, "Microphone");
376
376
  }
377
- async function Ue(e) {
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 (b.isPublishing)
382
+ if (P.isPublishing)
383
383
  throw i("Cannot replace microphone track: publish in progress"), new Error("Microphone publish in progress");
384
- const t = b.publication;
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
- b.isPublishing = !0, await t.track.replaceTrack(e), i("Microphone track replaced", { trackId: e.id, trackSid: t.trackSid });
388
+ P.isPublishing = !0, await t.track.replaceTrack(e), i("Microphone track replaced", { trackId: e.id, trackSid: t.trackSid });
389
389
  } finally {
390
- b.isPublishing = !1;
390
+ P.isPublishing = !1;
391
391
  }
392
392
  }
393
- async function je(e) {
393
+ async function Ne(e) {
394
394
  return ae(
395
- W,
395
+ Q,
396
396
  e,
397
397
  (t) => t.getVideoTracks(),
398
398
  Y.Source.Camera,
399
399
  () => a.localParticipant.videoTrackPublications,
400
- X
400
+ H
401
401
  );
402
402
  }
403
- async function X() {
404
- return ce(W, "Camera");
403
+ async function H() {
404
+ return ce(Q, "Camera");
405
405
  }
406
406
  function ze() {
407
- P && (P.getTracks().forEach((e) => e.stop()), P = null);
407
+ L && (L.getTracks().forEach((e) => e.stop()), L = null);
408
408
  }
409
- async function J(e, t) {
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, x(), {
413
- sessionId: T
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(e, { topic: t }), i("Message sent successfully:", e);
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, x(), { sessionId: T });
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
- L && (clearTimeout(L), L = null), S == null || S.destroy(), S = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, A.Disconnecting, e), await Promise.all([H(), X()]), await a.disconnect()), ze(), E = !1, D = !1, v.size > 0 && (v.clear(), j(), z()), V = null, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Idle), M = m.Idle;
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 J(
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), D = !1, (e = n.onConnectionStateChange) == null || e.call(n, A.Connecting, "user:reconnect");
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(f.ParticipantConnected, d), r(!1);
446
+ a == null || a.off(g.ParticipantConnected, d), r(!1);
467
447
  }, 5e3), d = () => {
468
- clearTimeout(c), a == null || a.off(f.ParticipantConnected, d), r(!0);
448
+ clearTimeout(c), a == null || a.off(g.ParticipantConnected, d), r(!0);
469
449
  };
470
- a == null || a.on(f.ParticipantConnected, d);
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: se,
480
- sendTextMessage: Be,
481
- publishMicrophoneStream: Ne,
482
- unpublishMicrophoneStream: H,
483
- replaceMicrophoneTrack: Ue,
484
- publishCameraStream: je,
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" && se(JSON.stringify({
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: T,
512
- streamId: T,
474
+ sessionId: v,
475
+ streamId: v,
513
476
  streamType: ne,
514
477
  interruptAvailable: te,
515
- isInterruptible: q
478
+ isInterruptible: W
516
479
  };
517
480
  }
518
481
  export {
519
- dn as createLiveKitStreamingManager,
482
+ un as createLiveKitStreamingManager,
520
483
  me as handleInitError
521
484
  };
@@ -1,5 +1 @@
1
- /**
2
- * Advanced functionality tests for streaming manager
3
- * Tests complex scenarios, edge cases, and advanced features
4
- */
5
1
  export {};