@zeroweight/react 0.2.34 → 0.2.35

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