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