@zeroweight/react 0.2.35 → 0.2.36

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,147 +1,147 @@
1
- import { useMemo as be, useRef as x, useState as k, useCallback as S, useEffect as h } from "react";
1
+ import { useMemo as be, useRef as x, useState as k, useCallback as S, useEffect as m } from "react";
2
2
  import { ZeroWeightRenderer as Se, ActionQueue as ke, VoiceActivityDetector as xe } from "@zeroweight/renderer";
3
- import { jsxs as w, jsx as i, Fragment as j } from "react/jsx-runtime";
4
- import { useVoiceAssistant as we, useLocalParticipant as Ae, useIsSpeaking as Te, useDataChannel as Ie, RoomAudioRenderer as Me, LiveKitRoom as Ce } from "@livekit/components-react";
3
+ import { jsxs as A, jsx as r, Fragment as j } from "react/jsx-runtime";
4
+ import { useVoiceAssistant as Ae, useLocalParticipant as we, useIsSpeaking as Te, useDataChannel as Ie, RoomAudioRenderer as Me, LiveKitRoom as Ce } from "@livekit/components-react";
5
5
  import "@livekit/components-styles";
6
6
  import { Loader2 as J, MicOff as Re, Mic as Ee, Power as Le, Activity as De } from "lucide-react";
7
7
  const ze = 3e4, Ue = 120, Pe = "wss://prod-project-pazuyq69.livekit.cloud", ne = "https://api.zeroweight.ai/api/v1", $e = () => {
8
- const l = ["Happy", "Swift", "Bright", "Cool", "Smart"], a = ["User", "Guest", "Visitor", "Agent", "Caller"], e = Math.floor(Math.random() * 1e3);
9
- return `${l[Math.floor(Math.random() * l.length)]}${a[Math.floor(Math.random() * a.length)]}${e}`;
8
+ const d = ["Happy", "Swift", "Bright", "Cool", "Smart"], o = ["User", "Guest", "Visitor", "Agent", "Caller"], e = Math.floor(Math.random() * 1e3);
9
+ return `${d[Math.floor(Math.random() * d.length)]}${o[Math.floor(Math.random() * o.length)]}${e}`;
10
10
  };
11
- function Fe(l) {
11
+ function Fe(d) {
12
12
  const {
13
- avatarId: a,
13
+ avatarId: o,
14
14
  apiKey: e = null,
15
- api: d,
15
+ api: f,
16
16
  turnOffMicWhenAISpeaking: v = !0,
17
- livekitUrl: A = Pe,
18
- sessionDuration: f = Ue,
19
- inactivityTimeout: M = ze
20
- } = l, D = A, y = be(() => {
21
- if (d) return d;
17
+ livekitUrl: w = Pe,
18
+ sessionDuration: p = Ue,
19
+ inactivityTimeout: T = ze
20
+ } = d, L = w, y = be(() => {
21
+ if (f) return f;
22
22
  const t = e ? { "X-ZW-Api-Key": e } : void 0;
23
23
  return {
24
- getBundle: async (g) => {
25
- const T = await fetch(
24
+ getBundle: async (h) => {
25
+ const I = await fetch(
26
26
  `${ne}/avatars/bundle/${encodeURIComponent(
27
- g
27
+ h
28
28
  )}`,
29
29
  { headers: t }
30
30
  );
31
- if (!T.ok)
31
+ if (!I.ok)
32
32
  throw new Error(
33
- `Failed to fetch avatar bundle (${T.status} ${T.statusText})`
33
+ `Failed to fetch avatar bundle (${I.status} ${I.statusText})`
34
34
  );
35
- return T.json();
35
+ return I.json();
36
36
  },
37
- getLiveKitToken: async (g) => {
38
- const T = new URLSearchParams({
39
- avatar_id: g,
37
+ getLiveKitToken: async (h) => {
38
+ const I = new URLSearchParams({
39
+ avatar_id: h,
40
40
  name: $e()
41
- }), c = await fetch(
42
- `${ne}/livekit/getToken?${T.toString()}`,
41
+ }), u = await fetch(
42
+ `${ne}/livekit/getToken?${I.toString()}`,
43
43
  { headers: t }
44
44
  );
45
- if (!c.ok)
45
+ if (!u.ok)
46
46
  throw new Error(
47
- `Failed to fetch LiveKit token (${c.status} ${c.statusText})`
47
+ `Failed to fetch LiveKit token (${u.status} ${u.statusText})`
48
48
  );
49
- return c.json();
49
+ return u.json();
50
50
  }
51
51
  };
52
- }, [d, e]), m = x(null), E = x(null), r = x(null), u = x(null), [b, C] = k("idle"), [p, U] = k(null), [s, $] = k(
52
+ }, [f, e]), b = x(null), R = x(null), a = x(null), i = x(null), [g, D] = k("idle"), [l, U] = k(null), [s, $] = k(
53
53
  /* @__PURE__ */ new Set(["listening"])
54
- ), [n, o] = k({
54
+ ), [n, c] = k({
55
55
  listening: { kind: "looped" },
56
56
  speaking: { kind: "looped" }
57
- }), [_, z] = k(!1), [P, O] = k(null), [N, K] = k(!1), [W, Z] = k(!1), [ae, V] = k(f), R = x(null), B = x(() => {
58
- }), [oe, G] = k(!1), [se, X] = k(0.8), L = x(null), H = b === "ready", Y = S(() => {
59
- const t = m.current;
57
+ }), [_, z] = k(!1), [P, O] = k(null), [N, K] = k(!1), [W, Z] = k(!1), [ae, V] = k(p), C = x(null), B = x(() => {
58
+ }), [oe, G] = k(!1), [se, X] = k(0.8), E = x(null), H = g === "ready", Y = S(() => {
59
+ const t = b.current;
60
60
  if (!t) return null;
61
- let g = t.querySelector("canvas");
62
- return g || (g = document.createElement("canvas"), g.style.width = "100%", g.style.height = "100%", g.style.display = "block", t.appendChild(g)), E.current = g, g;
61
+ let h = t.querySelector("canvas");
62
+ return h || (h = document.createElement("canvas"), h.style.width = "100%", h.style.height = "100%", h.style.display = "block", t.appendChild(h)), R.current = h, h;
63
63
  }, []);
64
- h(() => {
64
+ m(() => {
65
65
  let t = !1;
66
66
  return (async () => {
67
- const T = Y();
68
- if (!T) return;
69
- const c = new Se();
70
- r.current = c;
71
- const q = new ke((I, F) => {
72
- c.play(I, F);
67
+ const I = Y();
68
+ if (!I) return;
69
+ const u = new Se();
70
+ a.current = u;
71
+ const q = new ke((M, F) => {
72
+ u.play(M, F);
73
73
  });
74
- u.current = q, c.on("stateChanged", (I) => {
75
- t || C(I);
76
- }), c.on("dimensions", (I, F) => {
77
- t || U({ width: I, height: F });
78
- }), c.on("actionLoaded", (I) => {
74
+ i.current = q, u.on("stateChanged", (M) => {
75
+ t || D(M);
76
+ }), u.on("dimensions", (M, F) => {
77
+ t || U({ width: M, height: F });
78
+ }), u.on("actionLoaded", (M) => {
79
79
  t || $((F) => {
80
80
  const te = new Set(F);
81
- return te.add(I), te;
81
+ return te.add(M), te;
82
82
  });
83
- }), c.on("allActionsLoaded", () => {
83
+ }), u.on("allActionsLoaded", () => {
84
84
  t || z(!1);
85
- }), c.on("ready", () => {
86
- t || (o(c.getActionMetadata()), q.setActionMetadata(c.getActionMetadata()));
85
+ }), u.on("ready", () => {
86
+ t || (c(u.getActionMetadata()), q.setActionMetadata(u.getActionMetadata()));
87
87
  });
88
88
  try {
89
89
  z(!0);
90
- const I = await y.getBundle(a);
91
- if (t || (await c.init(T, { payload: I.payload }), t)) return;
92
- o(c.getActionMetadata()), q.setActionMetadata(c.getActionMetadata());
93
- } catch (I) {
94
- console.error("[useAvatarSession] Init failed:", I);
90
+ const M = await y.getBundle(o);
91
+ if (t || (await u.init(I, { payload: M.payload }), t)) return;
92
+ c(u.getActionMetadata()), q.setActionMetadata(u.getActionMetadata());
93
+ } catch (M) {
94
+ console.error("[useAvatarSession] Init failed:", M);
95
95
  }
96
96
  })(), () => {
97
- t = !0, r.current?.destroy(), r.current = null, u.current = null;
97
+ t = !0, a.current?.destroy(), a.current = null, i.current = null;
98
98
  };
99
- }, [a, Y, y]);
99
+ }, [o, Y, y]);
100
100
  const ee = x(!1);
101
- h(() => {
102
- H && r.current && s.has("wave_hand") && !ee.current && (r.current.play("wave_hand", "listening"), ee.current = !0);
101
+ m(() => {
102
+ H && a.current && s.has("wave_hand") && !ee.current && (a.current.play("wave_hand", "listening"), ee.current = !0);
103
103
  }, [H, s]);
104
104
  const ce = S(async () => {
105
105
  if (!(N || W)) {
106
106
  K(!0);
107
107
  try {
108
108
  await navigator.mediaDevices.getUserMedia({ audio: !0 });
109
- const t = await y.getLiveKitToken(a);
109
+ const t = await y.getLiveKitToken(o);
110
110
  O(t.token);
111
111
  } catch (t) {
112
112
  console.error("[useAvatarSession] Failed to connect:", t), K(!1);
113
113
  }
114
114
  }
115
- }, [N, W, a, y]), Q = S(() => {
116
- R.current && (clearInterval(R.current), R.current = null), V(f), L.current && (clearTimeout(L.current), L.current = null), O(null), Z(!1), K(!1), u.current?.forceListening();
117
- }, [f]);
118
- h(() => {
115
+ }, [N, W, o, y]), Q = S(() => {
116
+ C.current && (clearInterval(C.current), C.current = null), V(p), E.current && (clearTimeout(E.current), E.current = null), O(null), Z(!1), K(!1), i.current?.forceListening();
117
+ }, [p]);
118
+ m(() => {
119
119
  B.current = Q;
120
120
  }, [Q]);
121
121
  const le = S(() => {
122
122
  Z(!0), K(!1);
123
123
  }, []), ue = S(() => {
124
- R.current && clearInterval(R.current), V(f), R.current = setInterval(() => {
125
- V((t) => t <= 1 ? (clearInterval(R.current), R.current = null, setTimeout(() => B.current(), 0), 0) : t - 1);
124
+ C.current && clearInterval(C.current), V(p), C.current = setInterval(() => {
125
+ V((t) => t <= 1 ? (clearInterval(C.current), C.current = null, setTimeout(() => B.current(), 0), 0) : t - 1);
126
126
  }, 1e3);
127
- }, [f]), de = S((t) => {
128
- const g = Math.floor(t / 60).toString().padStart(2, "0"), T = (t % 60).toString().padStart(2, "0");
129
- return `${g}:${T}`;
127
+ }, [p]), de = S((t) => {
128
+ const h = Math.floor(t / 60).toString().padStart(2, "0"), I = (t % 60).toString().padStart(2, "0");
129
+ return `${h}:${I}`;
130
130
  }, []);
131
- h(() => () => {
132
- R.current && clearInterval(R.current);
131
+ m(() => () => {
132
+ C.current && clearInterval(C.current);
133
133
  }, []);
134
134
  const fe = S(
135
135
  (t) => {
136
136
  if (!t) {
137
- L.current && (clearTimeout(L.current), L.current = null);
137
+ E.current && (clearTimeout(E.current), E.current = null);
138
138
  return;
139
139
  }
140
- L.current || (L.current = setTimeout(() => {
141
- L.current = null, B.current();
142
- }, M));
140
+ E.current || (E.current = setTimeout(() => {
141
+ E.current = null, B.current();
142
+ }, T));
143
143
  },
144
- [M]
144
+ [T]
145
145
  ), pe = S(() => {
146
146
  G((t) => !t);
147
147
  }, []), ge = S((t) => {
@@ -151,16 +151,16 @@ function Fe(l) {
151
151
  }, []), me = S(() => {
152
152
  X((t) => t > 0 ? 0 : 1);
153
153
  }, []), ve = S(() => {
154
- r.current?.interrupt();
154
+ a.current?.interrupt();
155
155
  }, []), ye = S((t) => {
156
- r.current?.play(t, "listening");
156
+ a.current?.play(t, "listening");
157
157
  }, []);
158
158
  return {
159
- containerRef: m,
160
- renderer: r.current,
161
- actionQueue: u.current,
162
- rendererState: b,
163
- avatarDimensions: p,
159
+ containerRef: b,
160
+ renderer: a.current,
161
+ actionQueue: i.current,
162
+ rendererState: g,
163
+ avatarDimensions: l,
164
164
  loadedActions: s,
165
165
  actionMetadata: n,
166
166
  isLoadingActions: _,
@@ -168,7 +168,7 @@ function Fe(l) {
168
168
  token: P,
169
169
  isConnecting: N,
170
170
  isConnected: W,
171
- livekitUrl: D,
171
+ livekitUrl: L,
172
172
  timeRemaining: ae,
173
173
  formatTime: de,
174
174
  micMuted: oe,
@@ -188,10 +188,10 @@ function Fe(l) {
188
188
  };
189
189
  }
190
190
  const je = ({
191
- session: l,
192
- style: a,
191
+ session: d,
192
+ style: o,
193
193
  loadingContent: e
194
- }) => /* @__PURE__ */ w(
194
+ }) => /* @__PURE__ */ A(
195
195
  "div",
196
196
  {
197
197
  style: {
@@ -205,10 +205,10 @@ const je = ({
205
205
  justifyContent: "center",
206
206
  alignItems: "center",
207
207
  overflow: "hidden",
208
- ...a
208
+ ...o
209
209
  },
210
210
  children: [
211
- /* @__PURE__ */ i("style", { children: `
211
+ /* @__PURE__ */ r("style", { children: `
212
212
  @keyframes zwr-spin {
213
213
  from { transform: rotate(0deg); }
214
214
  to { transform: rotate(360deg); }
@@ -218,17 +218,17 @@ const je = ({
218
218
  50% { opacity: 0.5; }
219
219
  }
220
220
  ` }),
221
- /* @__PURE__ */ i(
221
+ /* @__PURE__ */ r(
222
222
  "div",
223
223
  {
224
- ref: l.containerRef,
224
+ ref: d.containerRef,
225
225
  style: {
226
226
  position: "relative",
227
227
  width: "100%",
228
228
  height: "100%",
229
229
  transition: "all 0.5s ease-in-out"
230
230
  },
231
- children: !l.isEngineReady && /* @__PURE__ */ i(
231
+ children: !d.isEngineReady && /* @__PURE__ */ r(
232
232
  "div",
233
233
  {
234
234
  style: {
@@ -241,7 +241,7 @@ const je = ({
241
241
  backdropFilter: "blur(4px)",
242
242
  zIndex: 10
243
243
  },
244
- children: e || /* @__PURE__ */ w(
244
+ children: e || /* @__PURE__ */ A(
245
245
  "div",
246
246
  {
247
247
  style: {
@@ -251,7 +251,7 @@ const je = ({
251
251
  gap: 16
252
252
  },
253
253
  children: [
254
- /* @__PURE__ */ i(
254
+ /* @__PURE__ */ r(
255
255
  J,
256
256
  {
257
257
  style: {
@@ -262,7 +262,7 @@ const je = ({
262
262
  }
263
263
  }
264
264
  ),
265
- /* @__PURE__ */ i(
265
+ /* @__PURE__ */ r(
266
266
  "div",
267
267
  {
268
268
  style: {
@@ -311,40 +311,40 @@ const je = ({
311
311
  border: "none",
312
312
  cursor: "pointer"
313
313
  }, _e = ({
314
- session: l,
315
- style: a
314
+ session: d,
315
+ style: o
316
316
  }) => {
317
317
  const {
318
318
  micMuted: e,
319
- toggleMic: d,
319
+ toggleMic: f,
320
320
  isConnected: v,
321
- isConnecting: A,
322
- isEngineReady: f,
323
- loadedActions: M,
324
- connect: D,
321
+ isConnecting: w,
322
+ isEngineReady: p,
323
+ loadedActions: T,
324
+ connect: L,
325
325
  disconnect: y
326
- } = l, [m, E] = k(!1), [r, u] = k(!1), b = f && M.has("listening") && M.has("speaking"), C = e ? {
326
+ } = d, [b, R] = k(!1), [a, i] = k(!1), g = p && T.has("listening") && T.has("speaking"), D = e ? {
327
327
  ...re,
328
328
  background: "rgba(239,68,68,0.1)",
329
329
  color: "#f87171",
330
330
  boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.3)",
331
- ...m ? { background: "rgba(239,68,68,0.2)" } : {}
331
+ ...b ? { background: "rgba(239,68,68,0.2)" } : {}
332
332
  } : {
333
333
  ...re,
334
- background: m ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
334
+ background: b ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
335
335
  color: "#fff",
336
336
  boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)"
337
- }, p = v ? {
337
+ }, l = v ? {
338
338
  ...ie,
339
- background: r ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
339
+ background: a ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
340
340
  boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.5), 0 0 20px rgba(239,68,68,0.2)"
341
341
  } : {
342
342
  ...ie,
343
343
  background: "linear-gradient(to right, #7c3aed, #db2777, #f97316)",
344
344
  boxShadow: "0 0 30px rgba(236,72,153,0.3)",
345
- opacity: r ? 0.9 : 1
345
+ opacity: a ? 0.9 : 1
346
346
  };
347
- return (A || !b) && (p.opacity = 0.5, p.cursor = "not-allowed"), /* @__PURE__ */ w(
347
+ return (w || !g) && (l.opacity = 0.5, l.cursor = "not-allowed"), /* @__PURE__ */ A(
348
348
  "div",
349
349
  {
350
350
  style: {
@@ -355,16 +355,16 @@ const je = ({
355
355
  alignItems: "center",
356
356
  gap: 16,
357
357
  paddingBottom: 16,
358
- ...a
358
+ ...o
359
359
  },
360
360
  children: [
361
- /* @__PURE__ */ i("style", { children: `
361
+ /* @__PURE__ */ r("style", { children: `
362
362
  @keyframes zwr-spin {
363
363
  from { transform: rotate(0deg); }
364
364
  to { transform: rotate(360deg); }
365
365
  }
366
366
  ` }),
367
- /* @__PURE__ */ w(
367
+ /* @__PURE__ */ A(
368
368
  "div",
369
369
  {
370
370
  style: {
@@ -377,39 +377,39 @@ const je = ({
377
377
  pointerEvents: "auto"
378
378
  },
379
379
  children: [
380
- /* @__PURE__ */ i(
380
+ /* @__PURE__ */ r(
381
381
  "button",
382
382
  {
383
383
  type: "button",
384
- onClick: d,
385
- onMouseEnter: () => E(!0),
386
- onMouseLeave: () => E(!1),
387
- style: C,
384
+ onClick: f,
385
+ onMouseEnter: () => R(!0),
386
+ onMouseLeave: () => R(!1),
387
+ style: D,
388
388
  title: e ? "Unmute mic" : "Mute mic",
389
- children: e ? /* @__PURE__ */ i(Re, { size: 24 }) : /* @__PURE__ */ i(Ee, { size: 24 })
389
+ children: e ? /* @__PURE__ */ r(Re, { size: 24 }) : /* @__PURE__ */ r(Ee, { size: 24 })
390
390
  }
391
391
  ),
392
- /* @__PURE__ */ i(
392
+ /* @__PURE__ */ r(
393
393
  "button",
394
394
  {
395
395
  type: "button",
396
- onClick: v ? y : D,
397
- onMouseEnter: () => u(!0),
398
- onMouseLeave: () => u(!1),
399
- disabled: !v && (A || !b),
400
- style: p,
401
- children: A ? /* @__PURE__ */ w(j, { children: [
402
- /* @__PURE__ */ i(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
403
- /* @__PURE__ */ i("span", { children: "Connecting..." })
404
- ] }) : !v && !b ? /* @__PURE__ */ w(j, { children: [
405
- /* @__PURE__ */ i(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
406
- /* @__PURE__ */ i("span", { children: "Loading Avatar..." })
407
- ] }) : v ? /* @__PURE__ */ w(j, { children: [
408
- /* @__PURE__ */ i(Le, { size: 20 }),
409
- /* @__PURE__ */ i("span", { children: "End Session" })
410
- ] }) : /* @__PURE__ */ w(j, { children: [
411
- /* @__PURE__ */ i(De, { size: 20 }),
412
- /* @__PURE__ */ i("span", { children: "Start Session" })
396
+ onClick: v ? y : L,
397
+ onMouseEnter: () => i(!0),
398
+ onMouseLeave: () => i(!1),
399
+ disabled: !v && (w || !g),
400
+ style: l,
401
+ children: w ? /* @__PURE__ */ A(j, { children: [
402
+ /* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
403
+ /* @__PURE__ */ r("span", { children: "Connecting..." })
404
+ ] }) : !v && !g ? /* @__PURE__ */ A(j, { children: [
405
+ /* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
406
+ /* @__PURE__ */ r("span", { children: "Loading Avatar..." })
407
+ ] }) : v ? /* @__PURE__ */ A(j, { children: [
408
+ /* @__PURE__ */ r(Le, { size: 20 }),
409
+ /* @__PURE__ */ r("span", { children: "End Session" })
410
+ ] }) : /* @__PURE__ */ A(j, { children: [
411
+ /* @__PURE__ */ r(De, { size: 20 }),
412
+ /* @__PURE__ */ r("span", { children: "Start Session" })
413
413
  ] })
414
414
  }
415
415
  )
@@ -420,9 +420,9 @@ const je = ({
420
420
  }
421
421
  );
422
422
  }, Oe = ({
423
- session: l
423
+ session: d
424
424
  }) => {
425
- const { isConnected: a, timeRemaining: e, formatTime: d } = l, v = a && e <= 30, A = a && e > 30 && e <= 60, f = {
425
+ const { isConnected: o, timeRemaining: e, formatTime: f } = d, v = o && e <= 30, w = o && e > 30 && e <= 60, p = {
426
426
  display: "flex",
427
427
  alignItems: "center",
428
428
  gap: 8,
@@ -437,7 +437,7 @@ const je = ({
437
437
  borderColor: "rgba(239,68,68,0.4)",
438
438
  boxShadow: "0 0 15px rgba(239,68,68,0.3)",
439
439
  animation: "zwr-pulse 2s ease-in-out infinite"
440
- } : A ? {
440
+ } : w ? {
441
441
  background: "rgba(249,115,22,0.2)",
442
442
  borderColor: "rgba(249,115,22,0.3)",
443
443
  boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
@@ -447,22 +447,22 @@ const je = ({
447
447
  boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
448
448
  }
449
449
  };
450
- return /* @__PURE__ */ w(j, { children: [
451
- /* @__PURE__ */ i("style", { children: `
450
+ return /* @__PURE__ */ A(j, { children: [
451
+ /* @__PURE__ */ r("style", { children: `
452
452
  @keyframes zwr-pulse {
453
453
  0%, 100% { opacity: 1; }
454
454
  50% { opacity: 0.5; }
455
455
  }
456
456
  ` }),
457
- /* @__PURE__ */ w("div", { style: f, children: [
458
- /* @__PURE__ */ i(
457
+ /* @__PURE__ */ A("div", { style: p, children: [
458
+ /* @__PURE__ */ r(
459
459
  "div",
460
460
  {
461
461
  style: {
462
462
  height: 8,
463
463
  width: 8,
464
464
  borderRadius: "50%",
465
- ...a ? {
465
+ ...o ? {
466
466
  background: "#22c55e",
467
467
  boxShadow: "0 0 10px rgba(34,197,94,0.5)"
468
468
  } : {
@@ -471,7 +471,7 @@ const je = ({
471
471
  }
472
472
  }
473
473
  ),
474
- /* @__PURE__ */ i(
474
+ /* @__PURE__ */ r(
475
475
  "span",
476
476
  {
477
477
  style: {
@@ -481,32 +481,32 @@ const je = ({
481
481
  color: "rgba(255,255,255,0.7)",
482
482
  textTransform: "uppercase"
483
483
  },
484
- children: a ? `Online ${d(e)}` : "Offline"
484
+ children: o ? `Online ${f(e)}` : "Offline"
485
485
  }
486
486
  )
487
487
  ] })
488
488
  ] });
489
489
  }, Ke = ({
490
- session: l
490
+ session: d
491
491
  }) => {
492
492
  const {
493
- renderer: a,
493
+ renderer: o,
494
494
  actionQueue: e,
495
- micMuted: d,
495
+ micMuted: f,
496
496
  volume: v,
497
- setInactivityActive: A,
498
- loadedActions: f,
499
- token: M,
500
- isConnected: D
501
- } = l, { turnOffMicWhenAISpeaking: y, setMicMuted: m } = l, E = x(!1), { state: r, audioTrack: u } = we(), b = Ae(), C = Te(b.localParticipant), p = x(null), U = x(f);
502
- h(() => {
503
- U.current = f;
504
- }, [f]), h(() => {
505
- const n = b.localParticipant;
506
- if (!a || !n) return;
507
- const o = new TextEncoder();
508
- return a.onOneshotComplete((z) => {
509
- const P = o.encode(
497
+ setInactivityActive: w,
498
+ loadedActions: p,
499
+ token: T,
500
+ isConnected: L
501
+ } = d, { turnOffMicWhenAISpeaking: y, setMicMuted: b } = d, R = x(!1), { state: a, audioTrack: i } = Ae(), g = we(), D = Te(g.localParticipant), l = x(null), U = x(p);
502
+ m(() => {
503
+ U.current = p;
504
+ }, [p]), m(() => {
505
+ const n = g.localParticipant;
506
+ if (!o || !n) return;
507
+ const c = new TextEncoder();
508
+ return o.onOneshotComplete((z) => {
509
+ const P = c.encode(
510
510
  JSON.stringify({
511
511
  type: "ACTION_FINISHED",
512
512
  action: z
@@ -518,7 +518,7 @@ const je = ({
518
518
  console.error("[LiveKitAvatarProvider] Failed to publish action completion:", O);
519
519
  });
520
520
  });
521
- }, [a, b.localParticipant]), h(() => {
521
+ }, [o, g.localParticipant]), m(() => {
522
522
  if (!e) return;
523
523
  const n = new xe({
524
524
  threshold: 8e-3,
@@ -527,50 +527,50 @@ const je = ({
527
527
  speechPauseFrames: 30,
528
528
  turnEndFrames: 50
529
529
  });
530
- return p.current = n, n.on("speechStart", () => {
530
+ return l.current = n, n.on("speechStart", () => {
531
531
  e.setTurnActive(!0), e.setSpeechState("speaking");
532
532
  }), n.on("turnEnd", () => {
533
533
  e.setTurnActive(!1);
534
534
  }), () => {
535
- n.stop(), p.current = null;
535
+ n.stop(), l.current = null;
536
536
  };
537
- }, [e]), h(() => {
538
- const n = p.current;
537
+ }, [e]), m(() => {
538
+ const n = l.current;
539
539
  if (n)
540
- if (u?.publication?.track) {
541
- const o = u.publication.track.mediaStreamTrack;
542
- o && n.start(o);
540
+ if (i?.publication?.track) {
541
+ const c = i.publication.track.mediaStreamTrack;
542
+ c && n.start(c);
543
543
  } else
544
544
  n.stop();
545
- }, [u?.publication?.track]);
545
+ }, [i?.publication?.track]);
546
546
  const s = x(null), $ = x(!1);
547
- return h(() => {
547
+ return m(() => {
548
548
  if (!e) return;
549
- const n = r;
550
- if (!M || !D || n === "disconnected") {
551
- s.current && (clearTimeout(s.current), s.current = null), p.current?.endTurn(), e.forceListening();
549
+ const n = a;
550
+ if (!T || !L || n === "disconnected") {
551
+ s.current && (clearTimeout(s.current), s.current = null), l.current?.endTurn(), e.forceListening();
552
552
  return;
553
553
  }
554
- n === "speaking" ? (s.current && (clearTimeout(s.current), s.current = null), e.setTurnActive(!0), e.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (s.current && (clearTimeout(s.current), s.current = null), p.current?.endTurn(), e.setTurnActive(!1)) : n === "thinking" && (s.current || (s.current = setTimeout(() => {
555
- s.current = null, p.current?.endTurn(), e.setTurnActive(!1);
554
+ n === "speaking" ? (s.current && (clearTimeout(s.current), s.current = null), e.setTurnActive(!0), e.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (s.current && (clearTimeout(s.current), s.current = null), l.current?.endTurn(), e.setTurnActive(!1)) : n === "thinking" && (s.current || (s.current = setTimeout(() => {
555
+ s.current = null, l.current?.endTurn(), e.setTurnActive(!1);
556
556
  }, 500)));
557
- }, [e, D, r, M]), h(() => {
558
- const n = r === "speaking";
557
+ }, [e, L, a, T]), m(() => {
558
+ const n = a === "speaking";
559
559
  if (!y) {
560
560
  $.current = n;
561
561
  return;
562
562
  }
563
- const o = $.current;
564
- !o && n ? d || m(!0) : o && !n && d && m(!1), $.current = n;
565
- }, [d, m, r, y]), h(() => {
563
+ const c = $.current;
564
+ !c && n ? f || b(!0) : c && !n && f && b(!1), $.current = n;
565
+ }, [f, b, a, y]), m(() => {
566
566
  if (!y || !e) return;
567
- const n = (o) => {
568
- o || m(!1);
567
+ const n = (c) => {
568
+ c || b(!1);
569
569
  };
570
570
  return e.on("turnChanged", n), () => {
571
571
  e.off("turnChanged", n);
572
572
  };
573
- }, [e, m, y]), h(() => () => {
573
+ }, [e, b, y]), m(() => () => {
574
574
  s.current && clearTimeout(s.current);
575
575
  }, []), Ie((n) => {
576
576
  try {
@@ -581,54 +581,55 @@ const je = ({
581
581
  return;
582
582
  e?.dispatch(P);
583
583
  }
584
- } catch (o) {
585
- console.error("[LiveKitAvatarProvider] Failed to parse data message:", o);
584
+ } catch (c) {
585
+ console.error("[LiveKitAvatarProvider] Failed to parse data message:", c);
586
586
  }
587
- }), h(() => {
588
- A(!(r === "speaking") && !C);
589
- }, [C, A, r]), h(() => {
587
+ }), m(() => {
588
+ w(!(a === "speaking") && !D);
589
+ }, [D, w, a]), m(() => {
590
590
  if (!e) return;
591
- const n = !!u;
592
- (!n || r === "disconnected") && (p.current?.endTurn(), e.forceListening()), E.current = n;
593
- }, [u, r, e]), h(() => {
594
- const n = b.localParticipant;
595
- n && n.setMicrophoneEnabled(!d).catch((o) => {
596
- console.error("[LiveKitAvatarProvider] Failed to set mic state:", o);
591
+ const n = !!i;
592
+ (!n || a === "disconnected") && (l.current?.endTurn(), e.forceListening()), R.current = n;
593
+ }, [i, a, e]), m(() => {
594
+ const n = g.localParticipant;
595
+ n && n.setMicrophoneEnabled(!f).catch((c) => {
596
+ console.error("[LiveKitAvatarProvider] Failed to set mic state:", c);
597
597
  });
598
- }, [d, b.localParticipant]), /* @__PURE__ */ i("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ i(Me, { volume: v }) });
598
+ }, [f, g.localParticipant]), /* @__PURE__ */ r("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ r(Me, { volume: v }) });
599
599
  }, qe = ({
600
- avatarId: l,
601
- apiKey: a,
600
+ avatarId: d,
601
+ apiKey: o,
602
602
  api: e,
603
- turnOffMicWhenAISpeaking: d,
603
+ turnOffMicWhenAISpeaking: f,
604
604
  livekitUrl: v,
605
- sessionDuration: A,
606
- inactivityTimeout: f,
607
- style: M,
608
- className: D,
609
- loadingContent: y,
610
- customControls: m,
611
- customStatusBadge: E
605
+ sessionDuration: w,
606
+ inactivityTimeout: p,
607
+ showBorder: T = !0,
608
+ style: L,
609
+ className: y,
610
+ loadingContent: b,
611
+ customControls: R,
612
+ customStatusBadge: a
612
613
  }) => {
613
- const r = Fe({
614
- avatarId: l,
615
- apiKey: a,
614
+ const i = Fe({
615
+ avatarId: d,
616
+ apiKey: o,
616
617
  api: e,
617
- turnOffMicWhenAISpeaking: d,
618
+ turnOffMicWhenAISpeaking: f,
618
619
  livekitUrl: v,
619
- sessionDuration: A,
620
- inactivityTimeout: f
620
+ sessionDuration: w,
621
+ inactivityTimeout: p
621
622
  }), {
622
- token: u,
623
- isConnected: b,
624
- avatarDimensions: C,
625
- disconnect: p,
626
- startSessionTimer: U
627
- } = r;
628
- return /* @__PURE__ */ w(
623
+ token: g,
624
+ isConnected: D,
625
+ avatarDimensions: l,
626
+ disconnect: U,
627
+ startSessionTimer: s
628
+ } = i;
629
+ return /* @__PURE__ */ A(
629
630
  "section",
630
631
  {
631
- className: D,
632
+ className: y,
632
633
  style: {
633
634
  position: "relative",
634
635
  display: "flex",
@@ -637,17 +638,17 @@ const je = ({
637
638
  justifyContent: "center",
638
639
  overflow: "hidden",
639
640
  borderRadius: 16,
640
- border: "1px solid rgba(255,255,255,0.1)",
641
- boxShadow: "0 25px 50px -12px rgba(0,0,0,0.5)",
641
+ border: T ? "1px solid rgba(255,255,255,0.1)" : "none",
642
+ boxShadow: T ? "0 25px 50px -12px rgba(0,0,0,0.5)" : "none",
642
643
  height: "80vh",
643
644
  width: "auto",
644
645
  maxWidth: "100%",
645
- aspectRatio: C ? `${C.width} / ${C.height}` : "3 / 4",
646
- ...M
646
+ aspectRatio: l ? `${l.width} / ${l.height}` : "3 / 4",
647
+ ...L
647
648
  },
648
649
  children: [
649
- /* @__PURE__ */ i(je, { session: r, loadingContent: y }),
650
- /* @__PURE__ */ w(
650
+ /* @__PURE__ */ r(je, { session: i, loadingContent: b }),
651
+ /* @__PURE__ */ A(
651
652
  "div",
652
653
  {
653
654
  style: {
@@ -661,7 +662,7 @@ const je = ({
661
662
  padding: 16
662
663
  },
663
664
  children: [
664
- /* @__PURE__ */ w(
665
+ /* @__PURE__ */ A(
665
666
  "div",
666
667
  {
667
668
  style: {
@@ -671,28 +672,28 @@ const je = ({
671
672
  justifyContent: "space-between"
672
673
  },
673
674
  children: [
674
- E ? E(r) : /* @__PURE__ */ i(Oe, { session: r }),
675
- /* @__PURE__ */ i("div", {})
675
+ a ? a(i) : /* @__PURE__ */ r(Oe, { session: i }),
676
+ /* @__PURE__ */ r("div", {})
676
677
  ]
677
678
  }
678
679
  ),
679
- m ? m(r) : /* @__PURE__ */ i(_e, { session: r })
680
+ R ? R(i) : /* @__PURE__ */ r(_e, { session: i })
680
681
  ]
681
682
  }
682
683
  ),
683
- /* @__PURE__ */ i("div", { style: { display: "none" }, children: u && r.livekitUrl && /* @__PURE__ */ i(
684
+ /* @__PURE__ */ r("div", { style: { display: "none" }, children: g && i.livekitUrl && /* @__PURE__ */ r(
684
685
  Ce,
685
686
  {
686
- serverUrl: r.livekitUrl,
687
- token: u,
687
+ serverUrl: i.livekitUrl,
688
+ token: g,
688
689
  connect: !0,
689
690
  video: !1,
690
691
  audio: !0,
691
692
  onConnected: () => {
692
- r.markConnected(), U();
693
+ i.markConnected(), s();
693
694
  },
694
- onDisconnected: p,
695
- children: /* @__PURE__ */ i(Ke, { session: r })
695
+ onDisconnected: U,
696
+ children: /* @__PURE__ */ r(Ke, { session: i })
696
697
  }
697
698
  ) })
698
699
  ]