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