@zeroweight/react 0.2.27 → 0.2.29

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