@zeroweight/react 0.2.34 → 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,176 +1,182 @@
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";
1
+ import { useMemo as be, useRef as x, useState as k, useCallback as S, useEffect as m } from "react";
2
+ import { ZeroWeightRenderer as Se, ActionQueue as ke, VoiceActivityDetector as xe } from "@zeroweight/renderer";
3
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";
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
- 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 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
+ };
11
+ function Fe(d) {
9
12
  const {
10
- avatarId: a,
13
+ avatarId: o,
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: f,
16
+ turnOffMicWhenAISpeaking: v = !0,
17
+ livekitUrl: w = Pe,
18
+ sessionDuration: p = Ue,
19
+ inactivityTimeout: T = ze
20
+ } = d, L = w, y = be(() => {
21
+ if (f) return f;
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 (h) => {
25
+ const I = await fetch(
23
26
  `${ne}/avatars/bundle/${encodeURIComponent(
24
- f
27
+ h
25
28
  )}`,
26
29
  { headers: t }
27
30
  );
28
- if (!m.ok)
31
+ if (!I.ok)
29
32
  throw new Error(
30
- `Failed to fetch avatar bundle (${m.status} ${m.statusText})`
33
+ `Failed to fetch avatar bundle (${I.status} ${I.statusText})`
31
34
  );
32
- return m.json();
35
+ return I.json();
33
36
  },
34
- getLiveKitToken: async (f) => {
35
- const m = await fetch(
36
- `${ne}/livekit/getToken?avatar_id=${f}&name=anonymuous`,
37
+ getLiveKitToken: async (h) => {
38
+ const I = new URLSearchParams({
39
+ avatar_id: h,
40
+ name: $e()
41
+ }), u = await fetch(
42
+ `${ne}/livekit/getToken?${I.toString()}`,
37
43
  { headers: t }
38
44
  );
39
- if (!m.ok)
45
+ if (!u.ok)
40
46
  throw new Error(
41
- `Failed to fetch LiveKit token (${m.status} ${m.statusText})`
47
+ `Failed to fetch LiveKit token (${u.status} ${u.statusText})`
42
48
  );
43
- return m.json();
49
+ return u.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
+ }, [f, e]), b = x(null), R = x(null), a = x(null), i = x(null), [g, D] = k("idle"), [l, U] = k(null), [s, $] = k(
47
53
  /* @__PURE__ */ new Set(["listening"])
48
- ), [n, o] = x({
54
+ ), [n, c] = 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(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;
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 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;
57
63
  }, []);
58
- g(() => {
64
+ m(() => {
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 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);
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(_);
75
- return te.add(I), te;
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
+ t || $((F) => {
80
+ const te = new Set(F);
81
+ return te.add(M), te;
76
82
  });
77
- }), T.on("allActionsLoaded", () => {
83
+ }), u.on("allActionsLoaded", () => {
78
84
  t || z(!1);
79
- }), T.on("ready", () => {
80
- t || (o(T.getActionMetadata()), q.setActionMetadata(T.getActionMetadata()));
85
+ }), u.on("ready", () => {
86
+ t || (c(u.getActionMetadata()), q.setActionMetadata(u.getActionMetadata()));
81
87
  });
82
88
  try {
83
89
  z(!0);
84
- 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());
87
- } catch (I) {
88
- 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);
89
95
  }
90
96
  })(), () => {
91
- t = !0, i.current?.destroy(), i.current = null, c.current = null;
97
+ t = !0, a.current?.destroy(), a.current = null, i.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
+ }, [o, Y, y]);
100
+ const ee = x(!1);
101
+ m(() => {
102
+ H && a.current && s.has("wave_hand") && !ee.current && (a.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
- const t = await y.getLiveKitToken(a);
104
- $(t.token);
109
+ const t = await y.getLiveKitToken(o);
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, 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(() => {
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
+ 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);
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
+ }, [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}`;
124
130
  }, []);
125
- g(() => () => {
126
- M.current && clearInterval(M.current);
131
+ m(() => () => {
132
+ C.current && clearInterval(C.current);
127
133
  }, []);
128
- const pe = S(
134
+ const fe = S(
129
135
  (t) => {
130
136
  if (!t) {
131
- L.current && (clearTimeout(L.current), L.current = null);
137
+ E.current && (clearTimeout(E.current), E.current = null);
132
138
  return;
133
139
  }
134
- L.current || (L.current = setTimeout(() => {
135
- L.current = null, B.current();
136
- }, C));
140
+ E.current || (E.current = setTimeout(() => {
141
+ E.current = null, B.current();
142
+ }, T));
137
143
  },
138
- [C]
139
- ), fe = S(() => {
140
- X((t) => !t);
144
+ [T]
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
+ a.current?.interrupt();
149
155
  }, []), ye = S((t) => {
150
- i.current?.play(t, "listening");
156
+ a.current?.play(t, "listening");
151
157
  }, []);
152
158
  return {
153
- containerRef: h,
154
- renderer: i.current,
155
- actionQueue: c.current,
156
- rendererState: b,
157
- avatarDimensions: p,
159
+ containerRef: b,
160
+ renderer: a.current,
161
+ actionQueue: i.current,
162
+ rendererState: g,
163
+ avatarDimensions: l,
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,
165
- livekitUrl: D,
168
+ token: P,
169
+ isConnecting: N,
170
+ isConnected: W,
171
+ livekitUrl: L,
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,12 +184,12 @@ 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,
186
- style: a,
190
+ const je = ({
191
+ session: d,
192
+ style: o,
187
193
  loadingContent: e
188
194
  }) => /* @__PURE__ */ A(
189
195
  "div",
@@ -199,7 +205,7 @@ const _e = ({
199
205
  justifyContent: "center",
200
206
  alignItems: "center",
201
207
  overflow: "hidden",
202
- ...a
208
+ ...o
203
209
  },
204
210
  children: [
205
211
  /* @__PURE__ */ r("style", { children: `
@@ -215,14 +221,14 @@ const _e = ({
215
221
  /* @__PURE__ */ r(
216
222
  "div",
217
223
  {
218
- ref: v.containerRef,
224
+ ref: d.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: !d.isEngineReady && /* @__PURE__ */ r(
226
232
  "div",
227
233
  {
228
234
  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,
309
- style: a
313
+ }, _e = ({
314
+ session: d,
315
+ style: o
310
316
  }) => {
311
317
  const {
312
318
  micMuted: e,
313
- toggleMic: l,
314
- isConnected: u,
319
+ toggleMic: f,
320
+ isConnected: v,
315
321
  isConnecting: w,
316
- isEngineReady: d,
317
- loadedActions: C,
318
- connect: D,
322
+ isEngineReady: p,
323
+ loadedActions: T,
324
+ connect: L,
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
+ } = d, [b, R] = k(!1), [a, i] = k(!1), g = p && T.has("listening") && T.has("speaking"), D = 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
+ ...b ? { 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: b ? "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
+ }, l = v ? {
332
338
  ...ie,
333
- background: i ? "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)",
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: a ? 0.9 : 1
340
346
  };
341
- return (w || !b) && (p.opacity = 0.5, p.cursor = "not-allowed"), /* @__PURE__ */ A(
347
+ return (w || !g) && (l.opacity = 0.5, l.cursor = "not-allowed"), /* @__PURE__ */ A(
342
348
  "div",
343
349
  {
344
350
  style: {
@@ -349,7 +355,7 @@ const _e = ({
349
355
  alignItems: "center",
350
356
  gap: 16,
351
357
  paddingBottom: 16,
352
- ...a
358
+ ...o
353
359
  },
354
360
  children: [
355
361
  /* @__PURE__ */ r("style", { children: `
@@ -375,30 +381,30 @@ const _e = ({
375
381
  "button",
376
382
  {
377
383
  type: "button",
378
- onClick: l,
379
- onMouseEnter: () => E(!0),
380
- onMouseLeave: () => E(!1),
381
- style: R,
384
+ onClick: f,
385
+ onMouseEnter: () => R(!0),
386
+ onMouseLeave: () => R(!1),
387
+ style: D,
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__ */ r(Re, { size: 24 }) : /* @__PURE__ */ r(Ee, { size: 24 })
384
390
  }
385
391
  ),
386
392
  /* @__PURE__ */ r(
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),
394
- style: p,
396
+ onClick: v ? y : L,
397
+ onMouseEnter: () => i(!0),
398
+ onMouseLeave: () => i(!1),
399
+ disabled: !v && (w || !g),
400
+ style: l,
395
401
  children: w ? /* @__PURE__ */ A(j, { children: [
396
402
  /* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
397
403
  /* @__PURE__ */ r("span", { children: "Connecting..." })
398
- ] }) : !u && !b ? /* @__PURE__ */ A(j, { children: [
404
+ ] }) : !v && !g ? /* @__PURE__ */ A(j, { children: [
399
405
  /* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
400
406
  /* @__PURE__ */ r("span", { children: "Loading Avatar..." })
401
- ] }) : u ? /* @__PURE__ */ A(j, { children: [
407
+ ] }) : v ? /* @__PURE__ */ A(j, { children: [
402
408
  /* @__PURE__ */ r(Le, { size: 20 }),
403
409
  /* @__PURE__ */ r("span", { children: "End Session" })
404
410
  ] }) : /* @__PURE__ */ A(j, { children: [
@@ -414,9 +420,9 @@ const _e = ({
414
420
  }
415
421
  );
416
422
  }, Oe = ({
417
- session: v
423
+ session: d
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: o, timeRemaining: e, formatTime: f } = d, v = o && e <= 30, w = o && e > 30 && e <= 60, p = {
420
426
  display: "flex",
421
427
  alignItems: "center",
422
428
  gap: 8,
@@ -426,7 +432,7 @@ 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)",
@@ -448,7 +454,7 @@ const _e = ({
448
454
  50% { opacity: 0.5; }
449
455
  }
450
456
  ` }),
451
- /* @__PURE__ */ A("div", { style: d, children: [
457
+ /* @__PURE__ */ A("div", { style: p, children: [
452
458
  /* @__PURE__ */ r(
453
459
  "div",
454
460
  {
@@ -456,7 +462,7 @@ const _e = ({
456
462
  height: 8,
457
463
  width: 8,
458
464
  borderRadius: "50%",
459
- ...a ? {
465
+ ...o ? {
460
466
  background: "#22c55e",
461
467
  boxShadow: "0 0 10px rgba(34,197,94,0.5)"
462
468
  } : {
@@ -475,154 +481,155 @@ 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: o ? `Online ${f(e)}` : "Offline"
479
485
  }
480
486
  )
481
487
  ] })
482
488
  ] });
483
- }, $e = ({
484
- session: v
489
+ }, Ke = ({
490
+ session: d
485
491
  }) => {
486
492
  const {
487
- renderer: a,
493
+ renderer: o,
488
494
  actionQueue: e,
489
- micMuted: l,
490
- volume: u,
495
+ micMuted: f,
496
+ volume: v,
491
497
  setInactivityActive: w,
492
- loadedActions: d,
493
- token: C,
494
- 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(() => {
499
- const n = b.localParticipant;
500
- if (!a || !n) return;
501
- const o = new TextEncoder();
502
- return a.onOneshotComplete((z) => {
503
- const F = o.encode(
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(
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
+ }, [o, g.localParticipant]), m(() => {
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,
521
527
  speechPauseFrames: 30,
522
528
  turnEndFrames: 50
523
529
  });
524
- return p.current = n, n.on("speechStart", () => {
530
+ return l.current = n, n.on("speechStart", () => {
525
531
  e.setTurnActive(!0), e.setSpeechState("speaking");
526
532
  }), n.on("turnEnd", () => {
527
533
  e.setTurnActive(!1);
528
534
  }), () => {
529
- n.stop(), p.current = null;
535
+ n.stop(), l.current = null;
530
536
  };
531
- }, [e]), g(() => {
532
- const n = p.current;
537
+ }, [e]), m(() => {
538
+ const n = l.current;
533
539
  if (n)
534
- if (c?.publication?.track) {
535
- const o = c.publication.track.mediaStreamTrack;
536
- o && n.start(o);
540
+ if (i?.publication?.track) {
541
+ const c = i.publication.track.mediaStreamTrack;
542
+ c && n.start(c);
537
543
  } else
538
544
  n.stop();
539
- }, [c?.publication?.track]);
540
- const s = k(null), U = k(!1);
541
- return g(() => {
545
+ }, [i?.publication?.track]);
546
+ const s = x(null), $ = x(!1);
547
+ return m(() => {
542
548
  if (!e) return;
543
- const n = i;
544
- if (!C || !D || n === "disconnected") {
545
- 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();
546
552
  return;
547
553
  }
548
- 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
- 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);
550
556
  }, 500)));
551
- }, [e, D, i, C]), g(() => {
552
- const n = i === "speaking";
557
+ }, [e, L, a, T]), m(() => {
558
+ const n = a === "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 c = $.current;
564
+ !c && n ? f || b(!0) : c && !n && f && b(!1), $.current = n;
565
+ }, [f, b, a, y]), m(() => {
560
566
  if (!y || !e) return;
561
- const n = (o) => {
562
- o || h(!1);
567
+ const n = (c) => {
568
+ c || b(!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, b, y]), m(() => () => {
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
- } catch (o) {
579
- console.error("[LiveKitAvatarProvider] Failed to parse data message:", o);
584
+ } catch (c) {
585
+ console.error("[LiveKitAvatarProvider] Failed to parse data message:", c);
580
586
  }
581
- }), g(() => {
582
- w(!(i === "speaking") && !R);
583
- }, [R, w, i]), g(() => {
587
+ }), m(() => {
588
+ w(!(a === "speaking") && !D);
589
+ }, [D, w, a]), m(() => {
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(() => {
588
- const n = b.localParticipant;
589
- n && n.setMicrophoneEnabled(!l).catch((o) => {
590
- 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);
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,
595
- apiKey: a,
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
+ }, qe = ({
600
+ avatarId: d,
601
+ apiKey: o,
596
602
  api: e,
597
- turnOffMicWhenAISpeaking: l,
598
- livekitUrl: u,
603
+ turnOffMicWhenAISpeaking: f,
604
+ livekitUrl: v,
599
605
  sessionDuration: w,
600
- inactivityTimeout: d,
601
- style: C,
602
- className: D,
603
- loadingContent: y,
604
- customControls: h,
605
- customStatusBadge: E
606
+ inactivityTimeout: p,
607
+ showBorder: T = !0,
608
+ style: L,
609
+ className: y,
610
+ loadingContent: b,
611
+ customControls: R,
612
+ customStatusBadge: a
606
613
  }) => {
607
- const i = Ue({
608
- avatarId: v,
609
- apiKey: a,
614
+ const i = Fe({
615
+ avatarId: d,
616
+ apiKey: o,
610
617
  api: e,
611
- turnOffMicWhenAISpeaking: l,
612
- livekitUrl: u,
618
+ turnOffMicWhenAISpeaking: f,
619
+ livekitUrl: v,
613
620
  sessionDuration: w,
614
- inactivityTimeout: d
621
+ inactivityTimeout: p
615
622
  }), {
616
- token: c,
617
- isConnected: b,
618
- avatarDimensions: R,
619
- disconnect: p,
620
- startSessionTimer: P
623
+ token: g,
624
+ isConnected: D,
625
+ avatarDimensions: l,
626
+ disconnect: U,
627
+ startSessionTimer: s
621
628
  } = i;
622
629
  return /* @__PURE__ */ A(
623
630
  "section",
624
631
  {
625
- className: D,
632
+ className: y,
626
633
  style: {
627
634
  position: "relative",
628
635
  display: "flex",
@@ -631,16 +638,16 @@ const _e = ({
631
638
  justifyContent: "center",
632
639
  overflow: "hidden",
633
640
  borderRadius: 16,
634
- border: "1px solid rgba(255,255,255,0.1)",
635
- 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",
636
643
  height: "80vh",
637
644
  width: "auto",
638
645
  maxWidth: "100%",
639
- aspectRatio: R ? `${R.width} / ${R.height}` : "3 / 4",
640
- ...C
646
+ aspectRatio: l ? `${l.width} / ${l.height}` : "3 / 4",
647
+ ...L
641
648
  },
642
649
  children: [
643
- /* @__PURE__ */ r(_e, { session: i, loadingContent: y }),
650
+ /* @__PURE__ */ r(je, { session: i, loadingContent: b }),
644
651
  /* @__PURE__ */ A(
645
652
  "div",
646
653
  {
@@ -665,28 +672,28 @@ const _e = ({
665
672
  justifyContent: "space-between"
666
673
  },
667
674
  children: [
668
- E ? E(i) : /* @__PURE__ */ r(Oe, { session: i }),
675
+ a ? a(i) : /* @__PURE__ */ r(Oe, { session: i }),
669
676
  /* @__PURE__ */ r("div", {})
670
677
  ]
671
678
  }
672
679
  ),
673
- h ? h(i) : /* @__PURE__ */ r(je, { session: i })
680
+ R ? R(i) : /* @__PURE__ */ r(_e, { session: i })
674
681
  ]
675
682
  }
676
683
  ),
677
- /* @__PURE__ */ r("div", { style: { display: "none" }, children: c && u && /* @__PURE__ */ r(
678
- Re,
684
+ /* @__PURE__ */ r("div", { style: { display: "none" }, children: g && i.livekitUrl && /* @__PURE__ */ r(
685
+ Ce,
679
686
  {
680
- serverUrl: u,
681
- token: c,
687
+ serverUrl: i.livekitUrl,
688
+ token: g,
682
689
  connect: !0,
683
690
  video: !1,
684
691
  audio: !0,
685
692
  onConnected: () => {
686
- i.markConnected(), P();
693
+ i.markConnected(), s();
687
694
  },
688
- onDisconnected: p,
689
- children: /* @__PURE__ */ r($e, { session: i })
695
+ onDisconnected: U,
696
+ children: /* @__PURE__ */ r(Ke, { session: i })
690
697
  }
691
698
  ) })
692
699
  ]
@@ -694,11 +701,11 @@ const _e = ({
694
701
  );
695
702
  };
696
703
  export {
697
- _e as AvatarCanvas,
698
- je as AvatarControls,
704
+ je as AvatarCanvas,
705
+ _e as AvatarControls,
699
706
  Oe as AvatarStatusBadge,
700
- $e as LiveKitAvatarProvider,
701
- Qe as LiveKitAvatarSession,
702
- Ue as useAvatarSession
707
+ Ke as LiveKitAvatarProvider,
708
+ qe as LiveKitAvatarSession,
709
+ Fe as useAvatarSession
703
710
  };
704
711
  //# sourceMappingURL=zeroweight-renderer-react.es.js.map