@d-id/client-sdk 2.0.6 → 2.0.7-staging.404

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