@zeroweight/react 0.2.22 → 0.2.23

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