tz-voice-chat 1.0.1 → 1.1.2

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/dist/index.js CHANGED
@@ -1,31 +1,41 @@
1
- import { useState as L, useRef as _, useEffect as U, useMemo as ke } from "react";
2
- import { jsx as v, jsxs as V } from "react/jsx-runtime";
3
- function he() {
4
- let e = "";
5
- function s() {
1
+ import { useState as q, useRef as R, useEffect as j, useMemo as Re } from "react";
2
+ import { jsx as p, jsxs as S } from "react/jsx-runtime";
3
+ const me = 60, se = 200;
4
+ function Me() {
5
+ let e = "", r = !0;
6
+ function s(t, i, n) {
7
+ t.push(i), e = n, r = !1;
8
+ }
9
+ function a() {
6
10
  const t = [];
7
11
  for (; ; ) {
8
- const r = /([.!?]{1,3})(\s|$)/.exec(e);
9
- if (r) {
10
- const n = e.slice(0, r.index + r[0].length).trim();
12
+ const i = /([.!?]{1,3})(\s|$)/.exec(e);
13
+ if (i) {
14
+ const n = e.slice(0, i.index + i[0].length).trim();
11
15
  if (n.length >= 10) {
12
- t.push(n), e = e.slice(r.index + r[0].length);
16
+ s(t, n, e.slice(i.index + i[0].length));
13
17
  continue;
14
18
  }
15
19
  }
16
- if (e.length >= 25) {
17
- const n = /[,;:—–](\s|$)/.exec(e);
18
- if (n) {
19
- const o = e.slice(0, n.index + n[0].length).trim();
20
- if (o.length >= 20) {
21
- t.push(o), e = e.slice(n.index + n[0].length);
22
- continue;
20
+ if (r) {
21
+ if (e.length >= 25) {
22
+ const n = /[,;:—–](\s|$)/.exec(e);
23
+ if (n) {
24
+ const l = e.slice(0, n.index + n[0].length).trim();
25
+ if (l.length >= 20) {
26
+ s(t, l, e.slice(n.index + n[0].length));
27
+ continue;
28
+ }
23
29
  }
24
30
  }
25
- }
26
- if (e.length >= 45) {
27
- const n = e.lastIndexOf(" ", 44), o = n > 10 ? n : 45;
28
- t.push(e.slice(0, o).trim()), e = e.slice(o).trimStart();
31
+ if (e.length >= me) {
32
+ const n = e.lastIndexOf(" ", me - 1), l = n > 10 ? n : me;
33
+ s(t, e.slice(0, l).trim(), e.slice(l).trimStart());
34
+ continue;
35
+ }
36
+ } else if (e.length >= se) {
37
+ const n = e.slice(0, se), l = Math.max(n.lastIndexOf(", "), n.lastIndexOf("; "), n.lastIndexOf(": ")), o = l > se / 2 ? l + 1 : n.lastIndexOf(" ") > 10 ? n.lastIndexOf(" ") : se;
38
+ s(t, e.slice(0, o).trim(), e.slice(o).trimStart());
29
39
  continue;
30
40
  }
31
41
  break;
@@ -34,7 +44,7 @@ function he() {
34
44
  }
35
45
  return {
36
46
  write(t) {
37
- return e += t, s();
47
+ return e += t, a();
38
48
  },
39
49
  flush() {
40
50
  const t = e.trim();
@@ -42,188 +52,212 @@ function he() {
42
52
  }
43
53
  };
44
54
  }
45
- async function Se(e, {
46
- dtype: s = "q8",
47
- device: t = "cpu",
48
- modelProxyUrl: r = "/api/models/"
55
+ async function qe(e, {
56
+ dtype: r = "q8",
57
+ device: s = "cpu",
58
+ modelProxyUrl: a = "/api/models/"
49
59
  } = {}) {
50
- var l, b;
51
- const { env: n } = await import(
60
+ var d, u;
61
+ const { env: t } = await import(
52
62
  /* @vite-ignore */
53
63
  "/vendor/transformers/transformers.min.js"
54
64
  );
55
- n.remoteHost = r, (b = (l = n == null ? void 0 : n.backends) == null ? void 0 : l.onnx) != null && b.wasm && (n.backends.onnx.wasm.wasmPaths = "/vendor/transformers/"), n != null && n.onnx && (n.onnx.logSeverityLevel = 3);
56
- const o = await import(
65
+ t.remoteHost = a, (u = (d = t == null ? void 0 : t.backends) == null ? void 0 : d.onnx) != null && u.wasm && (t.backends.onnx.wasm.wasmPaths = "/vendor/transformers/"), t != null && t.onnx && (t.onnx.logSeverityLevel = 3);
66
+ const i = await import(
57
67
  /* @vite-ignore */
58
68
  "/vendor/kokoro/kokoro.web.js"
59
- ), { KokoroTTS: i } = o;
60
- let g = s;
61
- t === "webgpu" && (s === "q4" || s === "q8") && (console.warn(`[modelLoader] dtype "${s}" not supported on WebGPU — using "fp32".`), g = "fp32");
62
- let a = 0;
63
- const h = (d) => {
64
- typeof (d == null ? void 0 : d.progress) == "number" && (a = Math.max(a, d.progress / 100), e == null || e("kokoro", Math.min(0.99, a)));
69
+ ), { KokoroTTS: n } = i;
70
+ let l = r;
71
+ s === "webgpu" && (r === "q4" || r === "q8") && (console.warn(`[modelLoader] dtype "${r}" not supported on WebGPU — using "fp32".`), l = "fp32");
72
+ let o = 0;
73
+ const f = (m) => {
74
+ typeof (m == null ? void 0 : m.progress) == "number" && (o = Math.max(o, m.progress / 100), e == null || e("kokoro", Math.min(0.99, o)));
65
75
  };
66
- async function p(d, R) {
67
- return i.from_pretrained("onnx-community/Kokoro-82M-ONNX", {
68
- dtype: R,
69
- device: d,
70
- progress_callback: h
76
+ async function c(m, w) {
77
+ return n.from_pretrained("onnx-community/Kokoro-82M-ONNX", {
78
+ dtype: w,
79
+ device: m,
80
+ progress_callback: f
71
81
  });
72
82
  }
73
- let c;
83
+ let v;
74
84
  try {
75
- c = await p(t, g);
76
- } catch (d) {
77
- if (t !== "wasm")
78
- console.warn(`[modelLoader] Kokoro on "${t}" failed (${d == null ? void 0 : d.message}) — falling back to WASM.`), a = 0, c = await p("wasm", s);
85
+ v = await c(s, l);
86
+ } catch (m) {
87
+ if (s !== "wasm")
88
+ console.warn(`[modelLoader] Kokoro on "${s}" failed (${m == null ? void 0 : m.message}) — falling back to WASM.`), o = 0, v = await c("wasm", r);
79
89
  else
80
- throw d;
90
+ throw m;
81
91
  }
82
- return e == null || e("kokoro", 1), { kokoro: c };
92
+ return e == null || e("kokoro", 1), { kokoro: v };
83
93
  }
84
- function Ae(e, { voice: s = "af_bella", onPlayStart: t } = {}) {
85
- const r = new AudioContext(), n = [];
86
- let o = !1, i = null, g = !1;
87
- async function a(c) {
88
- if (c instanceof AudioBuffer) return c;
89
- const l = (c == null ? void 0 : c.audio) ?? c;
90
- if (l instanceof ArrayBuffer) return await r.decodeAudioData(l.slice(0));
91
- if (l instanceof Float32Array) {
92
- const b = (c == null ? void 0 : c.samplingRate) ?? 24e3, d = r.createBuffer(1, l.length, b);
93
- return d.copyToChannel(l, 0), d;
94
+ function ie(e, r, { threshold: s = 0.01, padMs: a = 25 } = {}) {
95
+ const { numberOfChannels: t, length: i, sampleRate: n } = r;
96
+ let l = i, o = -1;
97
+ for (let u = 0; u < t; u++) {
98
+ const m = r.getChannelData(u);
99
+ for (let w = 0; w < i; w++)
100
+ if (Math.abs(m[w]) > s) {
101
+ w < l && (l = w);
102
+ break;
103
+ }
104
+ for (let w = i - 1; w >= 0; w--)
105
+ if (Math.abs(m[w]) > s) {
106
+ w > o && (o = w);
107
+ break;
108
+ }
109
+ }
110
+ if (o < l) return r;
111
+ const f = Math.round(a / 1e3 * n), c = Math.max(0, l - f), v = Math.min(i, o + 1 + f);
112
+ if (c === 0 && v === i) return r;
113
+ const d = e.createBuffer(t, v - c, n);
114
+ for (let u = 0; u < t; u++)
115
+ d.copyToChannel(r.getChannelData(u).subarray(c, v), u);
116
+ return d;
117
+ }
118
+ function Ve(e, { voice: r = "af_bella", speed: s = 1, onPlayStart: a } = {}) {
119
+ const t = new AudioContext(), i = [];
120
+ let n = !1, l = null, o = !1;
121
+ async function f(d) {
122
+ if (d instanceof AudioBuffer) return ie(t, d);
123
+ const u = (d == null ? void 0 : d.audio) ?? d;
124
+ if (u instanceof ArrayBuffer) return ie(t, await t.decodeAudioData(u.slice(0)));
125
+ if (u instanceof Float32Array) {
126
+ const m = (d == null ? void 0 : d.samplingRate) ?? 24e3, w = t.createBuffer(1, u.length, m);
127
+ return w.copyToChannel(u, 0), ie(t, w);
94
128
  }
95
129
  throw new Error("Unsupported TTS payload");
96
130
  }
97
- async function h(c) {
98
- await r.resume();
99
- const l = r.createBufferSource();
100
- return l.buffer = c, l.connect(r.destination), new Promise((b) => {
101
- l.onended = () => {
102
- i === l && (i = null), b();
103
- }, i = l, l.start(), g || (g = !0, t == null || t());
131
+ async function c(d) {
132
+ await t.resume();
133
+ const u = t.createBufferSource();
134
+ return u.buffer = d, u.connect(t.destination), new Promise((m) => {
135
+ u.onended = () => {
136
+ l === u && (l = null), m();
137
+ }, l = u, u.start(), o || (o = !0, a == null || a());
104
138
  });
105
139
  }
106
- async function p() {
107
- if (!o) {
108
- for (o = !0; n.length > 0; ) {
109
- const c = n.shift();
140
+ async function v() {
141
+ if (!n) {
142
+ for (n = !0; i.length > 0; ) {
143
+ const d = i.shift();
110
144
  try {
111
- const l = await c;
112
- l && await h(l);
113
- } catch (l) {
114
- console.error("[TtsQueue]", l);
145
+ const u = await d;
146
+ u && await c(u);
147
+ } catch (u) {
148
+ console.error("[TtsQueue]", u);
115
149
  }
116
150
  }
117
- o = !1;
151
+ n = !1;
118
152
  }
119
153
  }
120
154
  return {
121
- enqueue(c) {
122
- n.push(e.generate(c, { voice: s }).then(a)), p();
155
+ enqueue(d) {
156
+ i.push(e.generate(d, { voice: r, speed: s }).then(f)), v();
123
157
  },
124
158
  cancel() {
125
- if (n.length = 0, i) {
159
+ if (i.length = 0, o = !1, l) {
126
160
  try {
127
- i.stop();
161
+ l.stop();
128
162
  } catch {
129
163
  }
130
- i = null;
164
+ l = null;
131
165
  }
132
166
  },
133
167
  async finished() {
134
- for (; o || n.length > 0; ) await new Promise((c) => setTimeout(c, 200));
168
+ for (; n || i.length > 0; ) await new Promise((d) => setTimeout(d, 200));
135
169
  }
136
170
  };
137
171
  }
138
- function Ie({ voice: e = "", onPlayStart: s, url: t = "/api/tts" } = {}) {
139
- const r = new AudioContext(), n = [];
140
- let o = !1, i = null, g = !1;
141
- async function a(c) {
142
- const l = { text: c };
143
- e && (l.voice = e);
144
- const b = await fetch(t, {
172
+ function Oe({ voice: e = "", speed: r = 1, onPlayStart: s, url: a = "/api/tts" } = {}) {
173
+ const t = new AudioContext(), i = [];
174
+ let n = !1, l = null, o = !1;
175
+ async function f(d) {
176
+ const u = { text: d };
177
+ e && (u.voice = e), r !== 1 && (u.speed = r);
178
+ const m = await fetch(a, {
145
179
  method: "POST",
146
180
  headers: { "Content-Type": "application/json" },
147
- body: JSON.stringify(l)
181
+ body: JSON.stringify(u)
148
182
  });
149
- if (!b.ok) throw new Error(`TTS ${b.status}: ${await b.text()}`);
150
- return r.decodeAudioData(await b.arrayBuffer());
183
+ if (!m.ok) throw new Error(`TTS ${m.status}: ${await m.text()}`);
184
+ return ie(t, await t.decodeAudioData(await m.arrayBuffer()));
151
185
  }
152
- async function h(c) {
153
- await r.resume();
154
- const l = r.createBufferSource();
155
- return l.buffer = c, l.connect(r.destination), new Promise((b) => {
156
- l.onended = () => {
157
- i === l && (i = null), b();
158
- }, i = l, l.start(), g || (g = !0, s == null || s());
186
+ async function c(d) {
187
+ await t.resume();
188
+ const u = t.createBufferSource();
189
+ return u.buffer = d, u.connect(t.destination), new Promise((m) => {
190
+ u.onended = () => {
191
+ l === u && (l = null), m();
192
+ }, l = u, u.start(), o || (o = !0, s == null || s());
159
193
  });
160
194
  }
161
- async function p() {
162
- if (!o) {
163
- for (o = !0; n.length > 0; ) {
164
- const c = n.shift();
195
+ async function v() {
196
+ if (!n) {
197
+ for (n = !0; i.length > 0; ) {
198
+ const d = i.shift();
165
199
  try {
166
- await h(await c);
167
- } catch (l) {
168
- console.error("[ServerTTS]", l);
200
+ await c(await d);
201
+ } catch (u) {
202
+ console.error("[ServerTTS]", u);
169
203
  }
170
204
  }
171
- o = !1;
205
+ n = !1;
172
206
  }
173
207
  }
174
208
  return {
175
- enqueue(c) {
176
- c != null && c.trim() && (n.push(a(c)), p());
209
+ enqueue(d) {
210
+ d != null && d.trim() && (i.push(f(d)), v());
177
211
  },
178
212
  cancel() {
179
- if (n.length = 0, i) {
213
+ if (i.length = 0, l) {
180
214
  try {
181
- i.stop();
215
+ l.stop();
182
216
  } catch {
183
217
  }
184
- i = null;
218
+ l = null;
185
219
  }
186
- g = !1;
220
+ o = !1;
187
221
  },
188
222
  async finished() {
189
- for (; o || n.length > 0; ) await new Promise((c) => setTimeout(c, 100));
223
+ for (; n || i.length > 0; ) await new Promise((d) => setTimeout(d, 100));
190
224
  }
191
225
  };
192
226
  }
193
- function Ne({ voice: e = "", rate: s = 1, pitch: t = 1, onPlayStart: r } = {}) {
194
- const n = [];
195
- let o = !1, i = !1;
196
- function g() {
197
- return e ? speechSynthesis.getVoices().find((p) => p.name === e || p.voiceURI === e) ?? null : null;
227
+ function Pe({ voice: e = "", rate: r = 1, pitch: s = 1, onPlayStart: a } = {}) {
228
+ const t = [];
229
+ let i = !1, n = !1;
230
+ function l() {
231
+ return e ? speechSynthesis.getVoices().find((c) => c.name === e || c.voiceURI === e) ?? null : null;
198
232
  }
199
- function a() {
200
- if (o || n.length === 0) return;
201
- o = !0;
202
- const h = n.shift(), p = new SpeechSynthesisUtterance(h), c = g();
203
- c && (p.voice = c), p.rate = s, p.pitch = t, p.onstart = () => {
204
- i || (i = !0, r == null || r());
205
- }, p.onend = () => {
206
- o = !1, a();
207
- }, p.onerror = (l) => {
208
- console.error("[WebSpeech TTS] error", l.error), o = !1, a();
209
- }, speechSynthesis.speak(p);
233
+ function o() {
234
+ if (i || t.length === 0) return;
235
+ i = !0;
236
+ const f = t.shift(), c = new SpeechSynthesisUtterance(f), v = l();
237
+ v && (c.voice = v), c.rate = r, c.pitch = s, c.onstart = () => {
238
+ n || (n = !0, a == null || a());
239
+ }, c.onend = () => {
240
+ i = !1, o();
241
+ }, c.onerror = (d) => {
242
+ console.error("[WebSpeech TTS] error", d.error), i = !1, o();
243
+ }, speechSynthesis.speak(c);
210
244
  }
211
245
  return {
212
- enqueue(h) {
213
- h != null && h.trim() && (n.push(h), a());
246
+ enqueue(f) {
247
+ f != null && f.trim() && (t.push(f), o());
214
248
  },
215
249
  cancel() {
216
- n.length = 0, speechSynthesis.cancel(), o = !1, i = !1;
250
+ t.length = 0, speechSynthesis.cancel(), i = !1, n = !1;
217
251
  },
218
252
  async finished() {
219
- for (; o || n.length > 0; ) await new Promise((h) => setTimeout(h, 100));
253
+ for (; i || t.length > 0; ) await new Promise((f) => setTimeout(f, 100));
220
254
  }
221
255
  };
222
256
  }
223
- async function Te({ onSpeechStart: e, onSpeechEnd: s, onError: t, deviceId: r }) {
257
+ async function Ke({ onSpeechStart: e, onSpeechEnd: r, onError: s, deviceId: a }) {
224
258
  try {
225
- const { MicVAD: n } = window.vad;
226
- return await n.new({
259
+ const { MicVAD: t } = window.vad;
260
+ return await t.new({
227
261
  model: "legacy",
228
262
  baseAssetPath: "/vendor/vad/",
229
263
  onnxWASMBasePath: "/vendor/ort/",
@@ -231,11 +265,11 @@ async function Te({ onSpeechStart: e, onSpeechEnd: s, onError: t, deviceId: r })
231
265
  echoCancellation: !0,
232
266
  noiseSuppression: !0,
233
267
  autoGainControl: !1,
234
- ...r ? { deviceId: { exact: r } } : {}
268
+ ...a ? { deviceId: { exact: a } } : {}
235
269
  },
236
270
  onSpeechStart: () => e == null ? void 0 : e(),
237
- onSpeechEnd: (i) => {
238
- console.log("[VAD] onSpeechEnd — samples:", i == null ? void 0 : i.length), s == null || s(i);
271
+ onSpeechEnd: (n) => {
272
+ console.log("[VAD] onSpeechEnd — samples:", n == null ? void 0 : n.length), r == null || r(n);
239
273
  },
240
274
  onVADMisfire: () => {
241
275
  },
@@ -245,442 +279,780 @@ async function Te({ onSpeechStart: e, onSpeechEnd: s, onError: t, deviceId: r })
245
279
  minSpeechFrames: 3,
246
280
  preSpeechPadFrames: 1
247
281
  });
248
- } catch (n) {
249
- throw t == null || t("VAD initialization failed. Falling back to manual microphone capture."), n;
282
+ } catch (t) {
283
+ throw s == null || s("VAD initialization failed. Falling back to manual microphone capture."), t;
250
284
  }
251
285
  }
252
- const y = {
286
+ const z = {
253
287
  IDLE: "idle",
254
288
  LISTENING: "listening",
255
289
  TRANSCRIBING: "transcribing",
256
290
  THINKING: "thinking",
257
291
  SPEAKING: "speaking"
258
- }, ze = "You are a friendly assistant for quick voice interactions. Provide answers only in the form of a single concise sentence, without any introductory phrases. Don't use any formatting, markdown, emoji, or code blocks — just plain text. The answers will be spoken aloud, so keep them short and natural.";
259
- function xe({
292
+ }, Ge = "You are a friendly assistant for quick voice interactions. Provide answers only in the form of a single concise sentence, without any introductory phrases. Don't use any formatting, markdown, emoji, or code blocks — just plain text. The answers will be spoken aloud, so keep them short and natural.";
293
+ function Ce({
260
294
  processInput: e,
261
- systemPrompt: s = ze,
262
- ttsProvider: t = "server-kokoro",
263
- ttsVoice: r = "af_bella",
264
- ttsServerUrl: n = "/api/tts",
265
- ttsSpeechRate: o = 1,
266
- ttsSpeechPitch: i = 1,
267
- whisperModel: g = "onnx-community/whisper-tiny.en",
268
- whisperDtype: a = "q8",
269
- whisperDevice: h = "cpu",
270
- kokoroDtype: p = "q8",
271
- kokoroBrowserDevice: c = "wasm",
272
- modelProxyUrl: l = "/api/models/"
295
+ systemPrompt: r = Ge,
296
+ ttsProvider: s = "server-kokoro",
297
+ ttsVoice: a = "af_bella",
298
+ ttsSpeed: t = 1,
299
+ ttsServerUrl: i = "/api/tts",
300
+ ttsSpeechRate: n = 1,
301
+ ttsSpeechPitch: l = 1,
302
+ whisperModel: o = "onnx-community/whisper-tiny.en",
303
+ whisperDtype: f = "q8",
304
+ whisperDevice: c = "cpu",
305
+ kokoroDtype: v = "q8",
306
+ kokoroBrowserDevice: d = "wasm",
307
+ modelProxyUrl: u = "/api/models/"
273
308
  } = {}) {
274
- const [b, d] = L(y.IDLE), [R, I] = L(!0), [x, T] = L({ whisper: 0, kokoro: 0 }), [D, M] = L(null), [ee, Z] = L([]), [G, F] = L(null), [w, z] = L(!1), [$, ne] = L(""), [te, re] = L([]), [ae, C] = L(null), q = _(y.IDLE), K = _(!1), A = _(null), W = _(null), j = _(null), Q = _(null), se = _(null), ie = _(null), J = _([{ role: "system", content: s }]), ce = _(e);
275
- U(() => {
276
- q.current = b;
277
- }, [b]), U(() => {
278
- K.current = w;
279
- }, [w]), U(() => {
280
- ce.current = e;
281
- }, [e]), U(() => {
282
- async function m() {
309
+ const [m, w] = q(z.IDLE), [I, x] = q(!0), [L, b] = q({ whisper: 0, kokoro: 0 }), [E, A] = q(null), [P, D] = q([]), [k, V] = q(null), [$, C] = q(!1), [M, y] = q(""), [W, oe] = q([]), [ce, ee] = q(null), J = R(z.IDLE), Z = R(!1), K = R(null), U = R(null), B = R(null), H = R(null), le = R(null), ue = R(null), te = R([{ role: "system", content: r }]), de = R(e), ge = R(0), ve = R({ id: null, enqueuedAt: null, ttsMs: null }), Te = R(1);
310
+ j(() => {
311
+ J.current = m;
312
+ }, [m]), j(() => {
313
+ Z.current = $;
314
+ }, [$]), j(() => {
315
+ de.current = e;
316
+ }, [e]), j(() => {
317
+ async function _() {
283
318
  try {
284
- const k = await navigator.mediaDevices.enumerateDevices();
285
- re(k.filter((u) => u.kind === "audioinput"));
319
+ const T = await navigator.mediaDevices.enumerateDevices();
320
+ oe(T.filter((g) => g.kind === "audioinput"));
286
321
  } catch {
287
322
  }
288
323
  }
289
- return m(), navigator.mediaDevices.addEventListener("devicechange", m), () => navigator.mediaDevices.removeEventListener("devicechange", m);
290
- }, [w]), U(() => {
291
- let m = !1;
292
- async function k() {
324
+ return _(), navigator.mediaDevices.addEventListener("devicechange", _), () => navigator.mediaDevices.removeEventListener("devicechange", _);
325
+ }, [$]), j(() => {
326
+ let _ = !1;
327
+ async function T() {
293
328
  try {
294
- const u = () => {
295
- var f;
296
- t === "webspeech" && ((f = W.current) == null || f.pause());
329
+ const g = () => {
330
+ var N;
331
+ const h = ve.current;
332
+ h.enqueuedAt != null && h.ttsMs == null && (h.ttsMs = Math.round(performance.now() - h.enqueuedAt), h.id != null && ze(h.id, { timings: { ttsMs: h.ttsMs } })), s === "webspeech" && ((N = U.current) == null || N.pause());
297
333
  };
298
- if (t === "webspeech")
299
- A.current = Ne({
300
- voice: r,
301
- rate: o,
302
- pitch: i,
303
- onPlayStart: u
304
- }), T((f) => ({ ...f, kokoro: 1 }));
305
- else if (t === "kokoro") {
306
- const { kokoro: f } = await Se(
307
- (S, B) => T((O) => ({ ...O, [S]: B })),
308
- { dtype: p, device: c, modelProxyUrl: l }
334
+ if (s === "webspeech")
335
+ K.current = Pe({
336
+ voice: a,
337
+ rate: n,
338
+ pitch: l,
339
+ onPlayStart: g
340
+ }), b((h) => ({ ...h, kokoro: 1 }));
341
+ else if (s === "kokoro") {
342
+ const { kokoro: h } = await qe(
343
+ (N, Q) => b((F) => ({ ...F, [N]: Q })),
344
+ { dtype: v, device: d, modelProxyUrl: u }
309
345
  );
310
- if (m) return;
311
- A.current = Ae(f, { voice: r, onPlayStart: u });
346
+ if (_) return;
347
+ K.current = Ve(h, { voice: a, speed: t, onPlayStart: g });
312
348
  } else
313
- A.current = Ie({ voice: r, onPlayStart: u, url: n }), T((f) => ({ ...f, kokoro: 1 }));
314
- if (m) return;
315
- Q.current = new Worker(
349
+ K.current = Oe({ voice: a, speed: t, onPlayStart: g, url: i }), b((h) => ({ ...h, kokoro: 1 }));
350
+ if (_) return;
351
+ H.current = new Worker(
316
352
  new URL(
317
353
  /* @vite-ignore */
318
354
  "./assets/whisperWorker-BJuP9cl9.js",
319
355
  import.meta.url
320
356
  ),
321
357
  { type: "module" }
322
- ), Q.current.onmessage = (f) => {
323
- f.data.type === "transcript" ? pe(f.data.text) : f.data.type === "progress" ? T((S) => ({ ...S, whisper: f.data.progress })) : f.data.type === "ready" ? (T((S) => ({ ...S, whisper: 1 })), I(!1)) : f.data.type === "error" && (M(`Whisper: ${f.data.message}`), I(!1));
324
- }, Q.current.onerror = () => {
325
- M("Model load failed. Check WebGPU/WASM browser support."), I(!1);
326
- }, Q.current.postMessage({
358
+ ), H.current.onmessage = (h) => {
359
+ h.data.type === "transcript" ? be(h.data.text, {
360
+ transcribeMs: Math.round(performance.now() - ge.current)
361
+ }) : h.data.type === "progress" ? b((N) => ({ ...N, whisper: h.data.progress })) : h.data.type === "ready" ? (b((N) => ({ ...N, whisper: 1 })), x(!1)) : h.data.type === "error" && (A(`Whisper: ${h.data.message}`), x(!1));
362
+ }, H.current.onerror = () => {
363
+ A("Model load failed. Check WebGPU/WASM browser support."), x(!1);
364
+ }, H.current.postMessage({
327
365
  type: "init",
328
- model: g,
329
- dtype: a,
330
- device: h,
331
- modelProxyUrl: l
366
+ model: o,
367
+ dtype: f,
368
+ device: c,
369
+ modelProxyUrl: u
332
370
  });
333
- } catch (u) {
334
- m || (M("Initialisation failed: " + ((u == null ? void 0 : u.message) ?? String(u))), I(!1));
371
+ } catch (g) {
372
+ _ || (A("Initialisation failed: " + ((g == null ? void 0 : g.message) ?? String(g))), x(!1));
335
373
  }
336
374
  }
337
- return k(), () => {
338
- var u;
339
- m = !0, (u = Q.current) == null || u.terminate();
375
+ return T(), () => {
376
+ var g;
377
+ _ = !0, (g = H.current) == null || g.terminate();
340
378
  };
341
- }, [t, g, a, h, p, c]);
342
- function le(m, k) {
343
- Z((u) => [...u, { role: m, content: k, time: (/* @__PURE__ */ new Date()).toISOString() }]);
379
+ }, [s, o, f, c, v, d]);
380
+ function ye(_, T, g) {
381
+ const h = Te.current++;
382
+ return D((N) => [...N, { id: h, role: _, content: T, timings: g, time: (/* @__PURE__ */ new Date()).toISOString() }]), h;
344
383
  }
345
- async function pe(m) {
346
- if (!(m != null && m.trim())) {
347
- d(K.current ? y.LISTENING : y.IDLE);
384
+ function ze(_, { timings: T }) {
385
+ D((g) => g.map((h) => h.id === _ ? { ...h, timings: { ...h.timings, ...T } } : h));
386
+ }
387
+ async function be(_, { transcribeMs: T } = {}) {
388
+ if (!(_ != null && _.trim())) {
389
+ w(Z.current ? z.LISTENING : z.IDLE);
348
390
  return;
349
391
  }
350
- d(y.THINKING), le("user", m);
351
- const k = [...J.current, { role: "user", content: m }];
352
- J.current = k, await ge(m, k);
392
+ w(z.THINKING), ye("user", _, T != null ? { transcribeMs: T } : void 0);
393
+ const g = [...te.current, { role: "user", content: _ }];
394
+ te.current = g, await Ie(_, g);
353
395
  }
354
- async function ge(m, k) {
355
- var u, f, S, B, O;
356
- (u = j.current) == null || u.abort(), j.current = new AbortController(), (f = A.current) == null || f.cancel();
396
+ async function Ie(_, T) {
397
+ var g, h, N, Q;
398
+ (g = B.current) == null || g.abort(), B.current = new AbortController(), (h = K.current) == null || h.cancel();
357
399
  try {
358
- if (!ce.current) throw new Error("processInput is not provided");
359
- const P = he();
360
- let Y = "", oe = !1;
361
- F("");
362
- for await (const fe of ce.current(m, k, j.current.signal))
363
- Y += fe, F(Y), P.write(fe).forEach((ve) => {
364
- var de;
365
- oe || (oe = !0, d(y.SPEAKING)), (de = A.current) == null || de.enqueue(ve);
400
+ if (!de.current) throw new Error("processInput is not provided");
401
+ const F = Me();
402
+ let ne = "", fe = !1, he = null;
403
+ const Ee = performance.now(), Y = { id: null, enqueuedAt: null, ttsMs: null };
404
+ ve.current = Y;
405
+ const ke = (re) => {
406
+ var pe;
407
+ Y.enqueuedAt == null && (Y.enqueuedAt = performance.now()), (pe = K.current) == null || pe.enqueue(re);
408
+ };
409
+ V("");
410
+ for await (const re of de.current(_, T, B.current.signal))
411
+ he == null && (he = Math.round(performance.now() - Ee)), ne += re, V(ne), F.write(re).forEach((De) => {
412
+ fe || (fe = !0, w(z.SPEAKING)), ke(De);
366
413
  });
367
- const ue = P.flush();
368
- ue && (oe || d(y.SPEAKING), (S = A.current) == null || S.enqueue(ue)), le("assistant", Y), F(null), J.current = [...J.current, { role: "assistant", content: Y }], await ((B = A.current) == null ? void 0 : B.finished()), t === "webspeech" && ((O = W.current) == null || O.start());
369
- } catch (P) {
370
- F(null), P.name !== "AbortError" && M(P.message || "Processing failed.");
414
+ const _e = F.flush();
415
+ _e && (fe || w(z.SPEAKING), ke(_e)), Y.id = ye("assistant", ne, {
416
+ thinkMs: he,
417
+ ...Y.ttsMs != null ? { ttsMs: Y.ttsMs } : {}
418
+ }), V(null), te.current = [...te.current, { role: "assistant", content: ne }], await ((N = K.current) == null ? void 0 : N.finished()), s === "webspeech" && ((Q = U.current) == null || Q.start());
419
+ } catch (F) {
420
+ V(null), F.name !== "AbortError" && A(F.message || "Processing failed.");
371
421
  } finally {
372
- d(K.current ? y.LISTENING : y.IDLE);
422
+ w(Z.current ? z.LISTENING : z.IDLE);
373
423
  }
374
424
  }
375
- async function we() {
376
- var m, k;
377
- M(null), q.current === y.SPEAKING && ((m = A.current) == null || m.cancel(), (k = j.current) == null || k.abort());
425
+ async function Le() {
426
+ var _, T;
427
+ A(null), J.current === z.SPEAKING && ((_ = K.current) == null || _.cancel(), (T = B.current) == null || T.abort());
378
428
  try {
379
- d(y.LISTENING), z(!0);
429
+ w(z.LISTENING), C(!0);
380
430
  try {
381
- const u = await navigator.mediaDevices.getUserMedia({
382
- audio: $ ? { deviceId: { exact: $ } } : !0,
431
+ const g = await navigator.mediaDevices.getUserMedia({
432
+ audio: M ? { deviceId: { exact: M } } : !0,
383
433
  video: !1
384
434
  });
385
- ie.current = u;
386
- const f = new AudioContext();
387
- se.current = f;
388
- const S = f.createAnalyser();
389
- S.fftSize = 256, f.createMediaStreamSource(u).connect(S), C(S);
390
- } catch (u) {
391
- console.warn("[TZVoiceChat] waveform analyser unavailable:", u);
435
+ ue.current = g;
436
+ const h = new AudioContext();
437
+ le.current = h;
438
+ const N = h.createAnalyser();
439
+ N.fftSize = 256, h.createMediaStreamSource(g).connect(N), ee(N);
440
+ } catch (g) {
441
+ console.warn("[TZVoiceChat] waveform analyser unavailable:", g);
392
442
  }
393
- W.current = await Te({
443
+ U.current = await Ke({
394
444
  onSpeechStart: () => {
395
- var u, f;
396
- t === "webspeech" && q.current === y.SPEAKING || (q.current === y.SPEAKING && ((u = A.current) == null || u.cancel(), (f = j.current) == null || f.abort()), d(y.LISTENING));
445
+ var g, h;
446
+ s === "webspeech" && J.current === z.SPEAKING || (J.current === z.SPEAKING && ((g = K.current) == null || g.cancel(), (h = B.current) == null || h.abort()), w(z.LISTENING));
397
447
  },
398
- onSpeechEnd: (u) => {
399
- var f;
400
- t === "webspeech" && q.current === y.SPEAKING || (d(y.TRANSCRIBING), (f = Q.current) == null || f.postMessage({ type: "transcribe", audio: u }, [u.buffer]));
448
+ onSpeechEnd: (g) => {
449
+ var h;
450
+ s === "webspeech" && J.current === z.SPEAKING || (w(z.TRANSCRIBING), ge.current = performance.now(), (h = H.current) == null || h.postMessage({ type: "transcribe", audio: g }, [g.buffer]));
401
451
  },
402
- onError: (u) => {
403
- M(u), d(y.IDLE);
452
+ onError: (g) => {
453
+ A(g), w(z.IDLE);
404
454
  },
405
- deviceId: $ || void 0
455
+ deviceId: M || void 0
406
456
  });
407
- } catch (u) {
408
- console.error("[TZVoiceChat] startListening failed:", u), M("Microphone access failed. Allow audio permissions and refresh."), d(y.IDLE), z(!1);
457
+ } catch (g) {
458
+ console.error("[TZVoiceChat] startListening failed:", g), A("Microphone access failed. Allow audio permissions and refresh."), w(z.IDLE), C(!1);
409
459
  }
410
460
  }
411
- function be() {
412
- var m, k, u, f, S;
413
- z(!1), (m = W.current) == null || m.destroy(), W.current = null, (k = ie.current) == null || k.getTracks().forEach((B) => B.stop()), ie.current = null, (u = se.current) == null || u.close(), se.current = null, C(null), (f = A.current) == null || f.cancel(), (S = j.current) == null || S.abort(), d(y.IDLE);
461
+ function $e() {
462
+ var _, T, g, h, N;
463
+ C(!1), (_ = U.current) == null || _.destroy(), U.current = null, (T = ue.current) == null || T.getTracks().forEach((Q) => Q.stop()), ue.current = null, (g = le.current) == null || g.close(), le.current = null, ee(null), (h = K.current) == null || h.cancel(), (N = B.current) == null || N.abort(), w(z.IDLE);
414
464
  }
415
- function ye(m) {
416
- var S;
417
- if (!(m != null && m.trim())) return;
418
- d(y.SPEAKING);
419
- const k = he(), u = k.write(m), f = k.flush();
420
- [...u, ...f ? [f] : []].forEach((B) => {
421
- var O;
422
- return (O = A.current) == null ? void 0 : O.enqueue(B);
423
- }), (S = A.current) == null || S.finished().then(() => {
424
- d(K.current ? y.LISTENING : y.IDLE);
465
+ function xe(_) {
466
+ var N;
467
+ if (!(_ != null && _.trim())) return;
468
+ w(z.SPEAKING);
469
+ const T = Me(), g = T.write(_), h = T.flush();
470
+ [...g, ...h ? [h] : []].forEach((Q) => {
471
+ var F;
472
+ return (F = K.current) == null ? void 0 : F.enqueue(Q);
473
+ }), (N = K.current) == null || N.finished().then(() => {
474
+ w(Z.current ? z.LISTENING : z.IDLE);
425
475
  });
426
476
  }
427
477
  return {
428
478
  /** Current pipeline state: 'idle' | 'listening' | 'transcribing' | 'thinking' | 'speaking' */
429
- status: b,
479
+ status: m,
430
480
  /** True while models (Whisper + TTS) are still loading. */
431
- loading: R,
481
+ loading: I,
432
482
  /** Per-model load progress: { whisper: 0–1, kokoro: 0–1 } */
433
- progress: x,
483
+ progress: L,
434
484
  /** Last error string, or null. Cleared on startListening(). */
435
- error: D,
436
- /** Completed conversation turns: [{ role, content, time }] */
437
- transcript: ee,
485
+ error: E,
486
+ /** Completed conversation turns: [{ id, role, content, time, timings }]. timings (ms): user → transcribeMs; assistant → thinkMs (time to first token), ttsMs (first sentence queued → audio starts). */
487
+ transcript: P,
438
488
  /** Partial assistant response being streamed, or null. */
439
- streamingMessage: G,
489
+ streamingMessage: k,
440
490
  /** Whether the microphone is currently open. */
441
- micEnabled: w,
491
+ micEnabled: $,
442
492
  /** Open the microphone and start the VAD → STT → AI → TTS pipeline. */
443
- startListening: we,
493
+ startListening: Le,
444
494
  /** Close the microphone and cancel any in-progress pipeline. */
445
- stopListening: be,
495
+ stopListening: $e,
446
496
  /** Directly synthesise and play text via the configured TTS provider. */
447
- speak: ye,
497
+ speak: xe,
498
+ /** Submit text as a user message, triggering the full AI → TTS pipeline (same as voice transcription). */
499
+ submitText: be,
448
500
  /** AnalyserNode for real-time waveform rendering, or null when mic is off. */
449
- liveAnalyser: ae,
501
+ liveAnalyser: ce,
450
502
  /** Available audio input devices (updated on permission grant). */
451
- devices: te,
503
+ devices: W,
452
504
  /** Currently selected device ID ('': system default). */
453
- selectedMicId: $,
505
+ selectedMicId: M,
454
506
  /** Select an audio input device by its deviceId. */
455
- setSelectedMicId: ne
507
+ setSelectedMicId: y
456
508
  };
457
509
  }
458
- function me(e) {
459
- const s = e.replace("#", ""), t = s.length === 3 ? s.split("").map((r) => r + r).join("") : s;
510
+ function Ne(e) {
511
+ const r = e.replace("#", ""), s = r.length === 3 ? r.split("").map((a) => a + a).join("") : r;
460
512
  return [
461
- parseInt(t.slice(0, 2), 16),
462
- parseInt(t.slice(2, 4), 16),
463
- parseInt(t.slice(4, 6), 16)
513
+ parseInt(s.slice(0, 2), 16),
514
+ parseInt(s.slice(2, 4), 16),
515
+ parseInt(s.slice(4, 6), 16)
464
516
  ];
465
517
  }
466
- function _e(e, s, t) {
467
- e /= 255, s /= 255, t /= 255;
468
- const r = Math.max(e, s, t), n = Math.min(e, s, t), o = (r + n) / 2;
469
- if (r === n) return [0, 0, o * 100];
470
- const i = r - n, g = o > 0.5 ? i / (2 - r - n) : i / (r + n);
471
- let a;
472
- switch (r) {
518
+ function Be(e, r, s) {
519
+ e /= 255, r /= 255, s /= 255;
520
+ const a = Math.max(e, r, s), t = Math.min(e, r, s), i = (a + t) / 2;
521
+ if (a === t) return [0, 0, i * 100];
522
+ const n = a - t, l = i > 0.5 ? n / (2 - a - t) : n / (a + t);
523
+ let o;
524
+ switch (a) {
473
525
  case e:
474
- a = ((s - t) / i + (s < t ? 6 : 0)) / 6;
526
+ o = ((r - s) / n + (r < s ? 6 : 0)) / 6;
475
527
  break;
476
- case s:
477
- a = ((t - e) / i + 2) / 6;
528
+ case r:
529
+ o = ((s - e) / n + 2) / 6;
478
530
  break;
479
531
  default:
480
- a = ((e - s) / i + 4) / 6;
532
+ o = ((e - r) / n + 4) / 6;
481
533
  }
482
- return [a * 360, g * 100, o * 100];
534
+ return [o * 360, l * 100, i * 100];
483
535
  }
484
- function Me(e, s, t) {
485
- s /= 100, t /= 100;
486
- const r = (i) => (i + e / 30) % 12, n = s * Math.min(t, 1 - t), o = (i) => t - n * Math.max(-1, Math.min(r(i) - 3, Math.min(9 - r(i), 1)));
487
- return [Math.round(o(0) * 255), Math.round(o(8) * 255), Math.round(o(4) * 255)];
536
+ function je(e, r, s) {
537
+ r /= 100, s /= 100;
538
+ const a = (n) => (n + e / 30) % 12, t = r * Math.min(s, 1 - s), i = (n) => s - t * Math.max(-1, Math.min(a(n) - 3, Math.min(9 - a(n), 1)));
539
+ return [Math.round(i(0) * 255), Math.round(i(8) * 255), Math.round(i(4) * 255)];
488
540
  }
489
- function E(e, s) {
490
- const [t, r, n] = me(e), [o, i, g] = _e(t, r, n), [a, h, p] = Me(o, i, Math.max(0, Math.min(100, g + s)));
491
- return `rgb(${a}, ${h}, ${p})`;
541
+ function G(e, r) {
542
+ const [s, a, t] = Ne(e), [i, n, l] = Be(s, a, t), [o, f, c] = je(i, n, Math.max(0, Math.min(100, l + r)));
543
+ return `rgb(${o}, ${f}, ${c})`;
492
544
  }
493
- function N(e, s) {
494
- const [t, r, n] = me(e);
495
- return `rgba(${t}, ${r}, ${n}, ${s})`;
545
+ function O(e, r) {
546
+ const [s, a, t] = Ne(e);
547
+ return `rgba(${s}, ${a}, ${t}, ${r})`;
496
548
  }
497
- function H(e, s) {
498
- return e.replace("rgb(", "rgba(").replace(")", `, ${s})`);
549
+ function X(e, r) {
550
+ return e.replace("rgb(", "rgba(").replace(")", `, ${r})`);
499
551
  }
500
- const X = 10;
501
- function Ee({ analyser: e }) {
502
- const s = _(null), t = _(null);
503
- return U(() => {
504
- if (cancelAnimationFrame(t.current), !e) return;
505
- const r = s.current;
506
- if (!r) return;
507
- const n = r.getContext("2d"), o = e.frequencyBinCount, i = new Uint8Array(o), g = Math.max(1, Math.floor(o / X)), a = getComputedStyle(r), h = +a.getPropertyValue("--bar-hue"), p = +a.getPropertyValue("--bar-hue-range"), c = +a.getPropertyValue("--bar-sat"), l = +a.getPropertyValue("--bar-lit"), b = +a.getPropertyValue("--bar-lit-range"), d = () => {
508
- t.current = requestAnimationFrame(d), e.getByteFrequencyData(i);
509
- const R = r.width, I = r.height;
510
- n.clearRect(0, 0, R, I);
511
- const x = (R - (X - 1) * 2) / X;
512
- for (let T = 0; T < X; T++) {
513
- const D = i[T * g] / 255, M = Math.max(3, D * I * 0.88);
514
- n.fillStyle = `hsl(${h + D * p}, ${c}%, ${l + D * b}%)`, n.beginPath(), n.roundRect(T * (x + 2), (I - M) / 2, x, M, [2]), n.fill();
552
+ const ae = 10;
553
+ function Fe({ analyser: e }) {
554
+ const r = R(null), s = R(null);
555
+ return j(() => {
556
+ if (cancelAnimationFrame(s.current), !e) return;
557
+ const a = r.current;
558
+ if (!a) return;
559
+ const t = a.getContext("2d"), i = e.frequencyBinCount, n = new Uint8Array(i), l = Math.max(1, Math.floor(i / ae)), o = getComputedStyle(a), f = +o.getPropertyValue("--bar-hue"), c = +o.getPropertyValue("--bar-hue-range"), v = +o.getPropertyValue("--bar-sat"), d = +o.getPropertyValue("--bar-lit"), u = +o.getPropertyValue("--bar-lit-range"), m = () => {
560
+ s.current = requestAnimationFrame(m), e.getByteFrequencyData(n);
561
+ const w = a.width, I = a.height;
562
+ t.clearRect(0, 0, w, I);
563
+ const x = (w - (ae - 1) * 2) / ae;
564
+ for (let L = 0; L < ae; L++) {
565
+ const b = n[L * l] / 255, E = Math.max(3, b * I * 0.88);
566
+ t.fillStyle = `hsl(${f + b * c}, ${v}%, ${d + b * u}%)`, t.beginPath(), t.roundRect(L * (x + 2), (I - E) / 2, x, E, [2]), t.fill();
515
567
  }
516
568
  };
517
- return d(), () => cancelAnimationFrame(t.current);
518
- }, [e]), /* @__PURE__ */ v("canvas", { ref: s, width: 55, height: 35, className: "ai-btn__canvas" });
569
+ return m(), () => cancelAnimationFrame(s.current);
570
+ }, [e]), /* @__PURE__ */ p("canvas", { ref: r, width: 55, height: 35, className: "ai-btn__canvas" });
519
571
  }
520
- function De({
572
+ function We({
521
573
  status: e = "idle",
522
- active: s = !1,
523
- loading: t = !1,
524
- analyser: r = null,
525
- onToggle: n,
526
- devices: o = [],
527
- selectedMicId: i = "",
528
- onDeviceChange: g,
574
+ active: r = !1,
575
+ loading: s = !1,
576
+ analyser: a = null,
577
+ onToggle: t,
578
+ devices: i = [],
579
+ selectedMicId: n = "",
580
+ onDeviceChange: l,
581
+ // ── Manual input ───────────────────────────────────────────
582
+ inputData: o = "",
583
+ sendData: f,
529
584
  // ── Theming ────────────────────────────────────────────────
530
- accentColor: a = "#f97316",
531
- uiColor: h = "#64748b",
532
- size: p = 70,
533
- barHue: c = 25,
534
- barHueRange: l = 20,
535
- barSat: b = 88,
536
- barLit: d = 65,
537
- barLitRange: R = 20
585
+ accentColor: c = "#f97316",
586
+ uiColor: v = "#64748b",
587
+ size: d = 70,
588
+ barHue: u = 25,
589
+ barHueRange: m = 20,
590
+ barSat: w = 88,
591
+ barLit: I = 65,
592
+ barLitRange: x = 20
538
593
  }) {
539
- var F;
540
- const [I, x] = L(!1), T = _(null);
541
- U(() => {
542
- if (!I) return;
543
- function w(z) {
544
- var $;
545
- ($ = T.current) != null && $.contains(z.target) || x(!1);
594
+ var C;
595
+ const [L, b] = q(!1), E = R(null);
596
+ j(() => {
597
+ if (!L) return;
598
+ function M(y) {
599
+ var W;
600
+ (W = E.current) != null && W.contains(y.target) || b(!1);
546
601
  }
547
- return document.addEventListener("pointerdown", w), () => document.removeEventListener("pointerdown", w);
548
- }, [I]);
549
- function D(w) {
550
- g == null || g(w), x(!1);
602
+ return document.addEventListener("pointerdown", M), () => document.removeEventListener("pointerdown", M);
603
+ }, [L]);
604
+ function A(M) {
605
+ l == null || l(M), b(!1);
551
606
  }
552
- const M = ke(() => {
553
- const w = E(a, -8), z = E(a, -15), $ = E(a, -22), ne = E(a, -30), te = E(a, -42), re = E(a, 8), ae = E(a, 20), C = E(a, 30), q = E(h, -22), K = E(h, -30), A = E(h, 18), W = E(h, 37);
607
+ const P = Re(() => {
608
+ const M = G(c, -8), y = G(c, -15), W = G(c, -22), oe = G(c, -30), ce = G(c, -42), ee = G(c, 8), J = G(c, 20), Z = G(c, 30), K = G(v, -22), U = G(v, -30), B = G(v, 18), H = G(v, 37);
554
609
  return {
555
- "--tz-size": `${p}px`,
610
+ "--tz-size": `${d}px`,
556
611
  // Accent shades
557
- "--tz-a": a,
558
- "--tz-a-d8": w,
559
- "--tz-a-d15": z,
560
- "--tz-a-d22": $,
561
- "--tz-a-d30": ne,
562
- "--tz-a-d42": te,
563
- "--tz-a-l8": re,
564
- "--tz-a-l20": ae,
565
- "--tz-a-l30": C,
612
+ "--tz-a": c,
613
+ "--tz-a-d8": M,
614
+ "--tz-a-d15": y,
615
+ "--tz-a-d22": W,
616
+ "--tz-a-d30": oe,
617
+ "--tz-a-d42": ce,
618
+ "--tz-a-l8": ee,
619
+ "--tz-a-l20": J,
620
+ "--tz-a-l30": Z,
566
621
  // Accent + alpha
567
- "--tz-a-25": N(a, 0.25),
568
- "--tz-a-28": N(a, 0.28),
569
- "--tz-a-30": N(a, 0.3),
570
- "--tz-a-32": N(a, 0.32),
571
- "--tz-a-34": N(a, 0.34),
572
- "--tz-a-35": N(a, 0.35),
573
- "--tz-a-38": N(a, 0.38),
574
- "--tz-a-45": N(a, 0.45),
575
- "--tz-a-50": N(a, 0.5),
576
- "--tz-a-55": N(a, 0.55),
577
- "--tz-a-60": N(a, 0.6),
578
- "--tz-a-65": N(a, 0.65),
579
- "--tz-a-68": N(a, 0.68),
622
+ "--tz-a-25": O(c, 0.25),
623
+ "--tz-a-28": O(c, 0.28),
624
+ "--tz-a-30": O(c, 0.3),
625
+ "--tz-a-32": O(c, 0.32),
626
+ "--tz-a-34": O(c, 0.34),
627
+ "--tz-a-35": O(c, 0.35),
628
+ "--tz-a-38": O(c, 0.38),
629
+ "--tz-a-45": O(c, 0.45),
630
+ "--tz-a-50": O(c, 0.5),
631
+ "--tz-a-55": O(c, 0.55),
632
+ "--tz-a-60": O(c, 0.6),
633
+ "--tz-a-65": O(c, 0.65),
634
+ "--tz-a-68": O(c, 0.68),
580
635
  // UI shades
581
- "--tz-u": h,
582
- "--tz-u-d22": q,
583
- "--tz-u-d30": K,
584
- "--tz-u-l18": A,
585
- "--tz-u-l37": W,
636
+ "--tz-u": v,
637
+ "--tz-u-d22": K,
638
+ "--tz-u-d30": U,
639
+ "--tz-u-l18": B,
640
+ "--tz-u-l37": H,
586
641
  // UI + alpha
587
- "--tz-u-30": N(h, 0.3),
588
- "--tz-u-55": N(h, 0.55),
589
- "--tz-u-d30-a85": H(K, 0.85),
590
- "--tz-u-l18-a18": H(A, 0.18),
591
- "--tz-u-l18-a20": H(A, 0.2),
592
- "--tz-u-l18-a32": H(A, 0.32),
593
- "--tz-u-d22-a90": H(q, 0.9),
642
+ "--tz-u-30": O(v, 0.3),
643
+ "--tz-u-55": O(v, 0.55),
644
+ "--tz-u-d30-a85": X(U, 0.85),
645
+ "--tz-u-l18-a18": X(B, 0.18),
646
+ "--tz-u-l18-a20": X(B, 0.2),
647
+ "--tz-u-l18-a32": X(B, 0.32),
648
+ "--tz-u-d22-a90": X(K, 0.9),
594
649
  // Waveform bar colors (cascade to canvas via getComputedStyle)
595
- "--bar-hue": c,
596
- "--bar-hue-range": l,
597
- "--bar-sat": b,
598
- "--bar-lit": d,
599
- "--bar-lit-range": R
650
+ "--bar-hue": u,
651
+ "--bar-hue-range": m,
652
+ "--bar-sat": w,
653
+ "--bar-lit": I,
654
+ "--bar-lit-range": x
600
655
  };
601
- }, [a, h, p, c, l, b, d, R]), ee = ((F = o.find((w) => w.deviceId === i)) == null ? void 0 : F.label) || (i ? `Mic ${i.slice(0, 6)}…` : "Default mic"), Z = s ? e : "off";
602
- let G;
603
- return !s || e === "idle" ? G = /* @__PURE__ */ v("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ v("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4zm6 10a1 1 0 0 1 2 0 8 8 0 0 1-7 7.94V21h2a1 1 0 0 1 0 2H9a1 1 0 0 1 0-2h2v-2.06A8 8 0 0 1 4 11a1 1 0 0 1 2 0 6 6 0 0 0 12 0z" }) }) : e === "listening" ? G = /* @__PURE__ */ v(Ee, { analyser: r }) : e === "transcribing" ? G = /* @__PURE__ */ v("div", { className: "ai-btn__bars ai-btn__bars--transcribing", children: Array.from({ length: 7 }, (w, z) => /* @__PURE__ */ v("span", { style: { animationDelay: `${z * 0.1}s` } }, z)) }) : e === "thinking" ? G = /* @__PURE__ */ V("div", { className: "ai-btn__dots", children: [
604
- /* @__PURE__ */ v("span", {}),
605
- /* @__PURE__ */ v("span", { style: { animationDelay: "0.18s" } }),
606
- /* @__PURE__ */ v("span", { style: { animationDelay: "0.36s" } })
607
- ] }) : e === "speaking" && (G = /* @__PURE__ */ v("div", { className: "ai-btn__bars ai-btn__bars--speaking", children: Array.from({ length: 7 }, (w, z) => /* @__PURE__ */ v("span", { style: { animationDelay: `${z * 0.11}s` } }, z)) })), /* @__PURE__ */ V("div", { className: "ai-btn-root", style: M, children: [
608
- /* @__PURE__ */ V("div", { className: `ai-btn-rings ai-btn-rings--${Z}`, "aria-hidden": "true", children: [
609
- /* @__PURE__ */ v("span", { className: "ai-ring ai-ring--1" }),
610
- /* @__PURE__ */ v("span", { className: "ai-ring ai-ring--2" })
656
+ }, [c, v, d, u, m, w, I, x]), D = ((C = i.find((M) => M.deviceId === n)) == null ? void 0 : C.label) || (n ? `Mic ${n.slice(0, 6)}…` : "Default mic"), k = o.trim().length > 0, V = k ? "ready" : r ? e : "off";
657
+ let $;
658
+ return k ? $ = /* @__PURE__ */ p("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ p("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) }) : !r || e === "idle" ? $ = /* @__PURE__ */ S("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
659
+ /* @__PURE__ */ p("path", { fillOpacity: "0.52", d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4zm6 10a1 1 0 0 1 2 0 8 8 0 0 1-7 7.94V21h2a1 1 0 0 1 0 2H9a1 1 0 0 1 0-2h2v-2.06A8 8 0 0 1 4 11a1 1 0 0 1 2 0 6 6 0 0 0 12 0z" }),
660
+ /* @__PURE__ */ p("path", { fill: "white", fillOpacity: "0.98", d: "M14.5 0L15.65 3.45L19.1 4.6L15.65 5.75L14.5 9.2L13.35 5.75L9.9 4.6L13.35 3.45Z" }),
661
+ /* @__PURE__ */ p("path", { fill: "white", fillOpacity: "0.88", d: "M19 8.62L19.75 10.75L21.88 11.5L19.75 12.25L19 14.38L18.25 12.25L16.12 11.5L18.25 10.75Z" })
662
+ ] }) : e === "listening" ? $ = /* @__PURE__ */ p(Fe, { analyser: a }) : e === "transcribing" ? $ = /* @__PURE__ */ p("div", { className: "ai-btn__bars ai-btn__bars--transcribing", children: Array.from({ length: 7 }, (M, y) => /* @__PURE__ */ p("span", { style: { animationDelay: `${y * 0.1}s` } }, y)) }) : e === "thinking" ? $ = /* @__PURE__ */ S("div", { className: "ai-btn__dots", children: [
663
+ /* @__PURE__ */ p("span", {}),
664
+ /* @__PURE__ */ p("span", { style: { animationDelay: "0.18s" } }),
665
+ /* @__PURE__ */ p("span", { style: { animationDelay: "0.36s" } })
666
+ ] }) : e === "speaking" && ($ = /* @__PURE__ */ p("div", { className: "ai-btn__bars ai-btn__bars--speaking", children: Array.from({ length: 7 }, (M, y) => /* @__PURE__ */ p("span", { style: { animationDelay: `${y * 0.11}s` } }, y)) })), /* @__PURE__ */ S("div", { className: "ai-btn-root", style: P, children: [
667
+ /* @__PURE__ */ S("div", { className: `ai-btn-rings ai-btn-rings--${V}`, "aria-hidden": "true", children: [
668
+ /* @__PURE__ */ p("span", { className: "ai-ring ai-ring--1" }),
669
+ /* @__PURE__ */ p("span", { className: "ai-ring ai-ring--2" })
611
670
  ] }),
612
- /* @__PURE__ */ V(
671
+ /* @__PURE__ */ S(
613
672
  "button",
614
673
  {
615
- className: `ai-btn ai-btn--${Z}`,
616
- disabled: t,
617
- onClick: n,
618
- "aria-label": s ? "Stop assistant" : "Start assistant",
619
- "aria-pressed": s,
674
+ className: `ai-btn ai-btn--${V}`,
675
+ disabled: s,
676
+ onClick: k ? () => f == null ? void 0 : f(o) : t,
677
+ "aria-label": k ? "Send message" : r ? "Stop assistant" : "Start assistant",
678
+ "aria-pressed": k ? void 0 : r,
620
679
  children: [
621
- G,
622
- s && /* @__PURE__ */ v("span", { className: "ai-btn__hover-stop", "aria-hidden": "true", children: "■" })
680
+ $,
681
+ r && !k && /* @__PURE__ */ p("span", { className: "ai-btn__hover-stop", "aria-hidden": "true", children: "■" })
623
682
  ]
624
683
  }
625
684
  ),
626
- /* @__PURE__ */ V("div", { className: `ai-mic-sel${I ? " open" : ""}`, ref: T, children: [
627
- /* @__PURE__ */ V(
685
+ /* @__PURE__ */ S("div", { className: `ai-mic-sel${L ? " open" : ""}`, ref: E, children: [
686
+ /* @__PURE__ */ S(
628
687
  "button",
629
688
  {
630
689
  className: "ai-mic-sel__trigger",
631
- onClick: () => x((w) => !w),
690
+ onClick: () => b((M) => !M),
632
691
  title: "Change microphone",
633
692
  "aria-label": "Change microphone",
634
- "aria-expanded": I,
693
+ "aria-expanded": L,
635
694
  children: [
636
- /* @__PURE__ */ V("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
637
- /* @__PURE__ */ v("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z" }),
638
- /* @__PURE__ */ v("path", { d: "M5 11a1 1 0 0 0-2 0 9 9 0 0 0 8 8.94V22H9a1 1 0 0 0 0 2h6a1 1 0 0 0 0-2h-2v-2.06A9 9 0 0 0 21 11a1 1 0 0 0-2 0 7 7 0 0 1-14 0z" })
695
+ /* @__PURE__ */ S("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
696
+ /* @__PURE__ */ p("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z" }),
697
+ /* @__PURE__ */ p("path", { d: "M5 11a1 1 0 0 0-2 0 9 9 0 0 0 8 8.94V22H9a1 1 0 0 0 0 2h6a1 1 0 0 0 0-2h-2v-2.06A9 9 0 0 0 21 11a1 1 0 0 0-2 0 7 7 0 0 1-14 0z" })
639
698
  ] }),
640
- /* @__PURE__ */ v("span", { className: "ai-mic-sel__label", children: ee }),
641
- /* @__PURE__ */ v(
699
+ /* @__PURE__ */ p("span", { className: "ai-mic-sel__label", children: D }),
700
+ /* @__PURE__ */ p(
642
701
  "svg",
643
702
  {
644
- className: `ai-mic-sel__caret${I ? " open" : ""}`,
703
+ className: `ai-mic-sel__caret${L ? " open" : ""}`,
645
704
  width: "9",
646
705
  height: "9",
647
706
  viewBox: "0 0 24 24",
648
707
  fill: "currentColor",
649
708
  "aria-hidden": "true",
650
- children: /* @__PURE__ */ v("path", { d: "M12 16L4 8h16l-8 8z" })
709
+ children: /* @__PURE__ */ p("path", { d: "M12 16L4 8h16l-8 8z" })
651
710
  }
652
711
  )
653
712
  ]
654
713
  }
655
714
  ),
656
- I && /* @__PURE__ */ V("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
657
- /* @__PURE__ */ v(
715
+ L && /* @__PURE__ */ S("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
716
+ /* @__PURE__ */ p(
658
717
  "li",
659
718
  {
660
719
  role: "option",
661
- className: `ai-mic-sel__option${i === "" ? " selected" : ""}`,
662
- onClick: () => D(""),
663
- "aria-selected": i === "",
720
+ className: `ai-mic-sel__option${n === "" ? " selected" : ""}`,
721
+ onClick: () => A(""),
722
+ "aria-selected": n === "",
664
723
  children: "Default microphone"
665
724
  }
666
725
  ),
667
- o.map((w) => /* @__PURE__ */ v(
726
+ i.map((M) => /* @__PURE__ */ p(
668
727
  "li",
669
728
  {
670
729
  role: "option",
671
- className: `ai-mic-sel__option${i === w.deviceId ? " selected" : ""}`,
672
- onClick: () => D(w.deviceId),
673
- "aria-selected": i === w.deviceId,
674
- children: w.label || `Microphone ${w.deviceId.slice(0, 8)}`
730
+ className: `ai-mic-sel__option${n === M.deviceId ? " selected" : ""}`,
731
+ onClick: () => A(M.deviceId),
732
+ "aria-selected": n === M.deviceId,
733
+ children: M.label || `Microphone ${M.deviceId.slice(0, 8)}`
675
734
  },
676
- w.deviceId
735
+ M.deviceId
677
736
  ))
678
737
  ] })
679
738
  ] })
680
739
  ] });
681
740
  }
741
+ async function Ue(e, r, s = "/api/chat") {
742
+ var l;
743
+ const a = await fetch(s, {
744
+ method: "POST",
745
+ headers: {
746
+ "Content-Type": "application/json"
747
+ },
748
+ signal: r,
749
+ body: JSON.stringify({ messages: e })
750
+ });
751
+ if (!a.ok) {
752
+ const o = await a.text();
753
+ throw new Error(`Server error: ${a.status} ${o}`);
754
+ }
755
+ const t = (l = a.body) == null ? void 0 : l.getReader();
756
+ if (!t) {
757
+ const o = await a.json();
758
+ return { stream: async function* () {
759
+ yield o.text;
760
+ } };
761
+ }
762
+ const i = new TextDecoder();
763
+ let n = "";
764
+ return {
765
+ stream: async function* () {
766
+ var f, c, v;
767
+ let o = "";
768
+ for (; ; ) {
769
+ const { value: d, done: u } = await t.read();
770
+ if (u) break;
771
+ n += i.decode(d, { stream: !0 });
772
+ const m = n.split(`
773
+ `);
774
+ n = m.pop();
775
+ for (const w of m) {
776
+ const I = w.trim();
777
+ if (!I.startsWith("data:")) continue;
778
+ const x = I.slice(5).trimStart();
779
+ if (x === "[DONE]") return;
780
+ try {
781
+ const b = (v = (c = (f = JSON.parse(x).choices) == null ? void 0 : f[0]) == null ? void 0 : c.delta) == null ? void 0 : v.content;
782
+ b && (o && /\w/.test(o) && /\w/.test(b[0]) && (yield " "), o = b[b.length - 1], yield b);
783
+ } catch {
784
+ }
785
+ }
786
+ }
787
+ }
788
+ };
789
+ }
790
+ function He(e, r, s) {
791
+ return {
792
+ stream: async function* () {
793
+ const a = [];
794
+ let t = null, i = !1, n = "";
795
+ const l = ({ data: f }) => {
796
+ f.type === "token" ? (a.push(f.text), t == null || t(), t = null) : f.type === "done" && (i = !0, t == null || t(), t = null);
797
+ }, o = () => {
798
+ i = !0, t == null || t(), t = null;
799
+ };
800
+ e.addEventListener("message", l), s == null || s.addEventListener("abort", o), e.postMessage({ type: "generate", messages: r });
801
+ try {
802
+ for (; !i || a.length > 0; )
803
+ if (a.length > 0) {
804
+ const f = a.shift();
805
+ n && /\w/.test(n) && /\w/.test(f[0]) && (yield " "), n = f[f.length - 1], yield f;
806
+ } else
807
+ await new Promise((f) => {
808
+ t = f;
809
+ });
810
+ } finally {
811
+ e.removeEventListener("message", l), s == null || s.removeEventListener("abort", o);
812
+ }
813
+ }
814
+ };
815
+ }
816
+ function Qe({ apiBase: e = "/api", systemPrompt: r } = {}) {
817
+ const [s, a] = q(!0), [t, i] = q(0), [n, l] = q(""), [o, f] = q({}), [c, v] = q(null), [d, u] = q({}), m = R(null), w = R(null);
818
+ j(() => {
819
+ let b = !1;
820
+ async function E() {
821
+ let A = !0, P = {};
822
+ try {
823
+ const k = await (await fetch(`${e}/config`)).json();
824
+ A = k.hasApiKey, v(k), P = {
825
+ ttsProvider: k.ttsProvider || "server-kokoro",
826
+ ttsVoice: k.ttsProvider === "openai" ? k.openaiTtsVoice || "alloy" : k.kokoroVoice || "af_bella",
827
+ ttsServerUrl: `${e}/tts`,
828
+ ttsSpeed: k.kokoroSpeed ?? 1,
829
+ ttsSpeechRate: k.webSpeechRate ?? 1,
830
+ ttsSpeechPitch: k.webSpeechPitch ?? 1,
831
+ whisperModel: k.whisperModel || "onnx-community/whisper-tiny.en",
832
+ whisperDtype: k.whisperDtype || "q8",
833
+ whisperDevice: k.whisperDevice || "cpu",
834
+ kokoroDtype: k.kokoroDtype || "q8",
835
+ kokoroBrowserDevice: k.kokoroBrowserDevice || "wasm",
836
+ modelProxyUrl: `${e}/models/`
837
+ };
838
+ } catch {
839
+ P = { ttsProvider: "server-kokoro", ttsServerUrl: `${e}/tts`, modelProxyUrl: `${e}/models/` };
840
+ }
841
+ if (!b)
842
+ if (A)
843
+ m.current = async function* (D, k, V) {
844
+ const { stream: $ } = await Ue(k, V, `${e}/chat`);
845
+ yield* $();
846
+ }, f(P), a(!1);
847
+ else {
848
+ l("No API key — using SmolLM2-360M-Instruct locally in your browser.");
849
+ const D = new Worker(new URL(
850
+ /* @vite-ignore */
851
+ "./assets/llmWorker-CVEGn6yI.js",
852
+ import.meta.url
853
+ ), { type: "module" });
854
+ w.current = D, D.onmessage = (k) => {
855
+ k.data.type === "progress" ? i(k.data.progress ?? 0) : k.data.type === "ready" ? (i(1), m.current = async function* (V, $, C) {
856
+ const { stream: M } = He(D, $, C);
857
+ yield* M();
858
+ }, f(P), a(!1)) : k.data.type === "error" && a(!1);
859
+ }, D.onerror = () => a(!1), D.postMessage({ type: "init", modelProxyUrl: `${e}/models/` });
860
+ }
861
+ }
862
+ return E(), () => {
863
+ var A;
864
+ b = !0, (A = w.current) == null || A.terminate();
865
+ };
866
+ }, [e]);
867
+ const I = Ce({
868
+ processInput: async function* (b, E, A) {
869
+ m.current && (yield* m.current(b, E, A));
870
+ },
871
+ ...r ? { systemPrompt: r } : {},
872
+ ...o
873
+ });
874
+ j(() => {
875
+ let b = !1;
876
+ async function E() {
877
+ const P = {};
878
+ typeof performance < "u" && performance.memory && (P.browser = performance.memory.usedJSHeapSize);
879
+ try {
880
+ const D = await fetch(`${e}/stats`);
881
+ D.ok && (P.server = (await D.json()).rss);
882
+ } catch {
883
+ }
884
+ b || u(P);
885
+ }
886
+ E();
887
+ const A = setInterval(E, 3e3);
888
+ return () => {
889
+ b = !0, clearInterval(A);
890
+ };
891
+ }, [e]);
892
+ const { micEnabled: x, stopListening: L } = I;
893
+ return j(() => {
894
+ if (!x) return;
895
+ const b = (E) => {
896
+ E.key === "Escape" && L();
897
+ };
898
+ return window.addEventListener("keydown", b), () => window.removeEventListener("keydown", b);
899
+ }, [x, L]), {
900
+ chat: I,
901
+ info: c,
902
+ config: o,
903
+ memory: d,
904
+ llmProgress: t,
905
+ note: n,
906
+ loading: I.loading || s
907
+ };
908
+ }
909
+ const Ae = (e, r) => e === "webgpu" && (r === "q4" || r === "q8") ? "fp32" : r, we = (e) => e >= 1e3 ? `${(e / 1e3).toFixed(1)} s` : `${e} ms`, Se = (e) => `${(e / 1048576).toFixed(0)} MB`;
910
+ function Je(e) {
911
+ switch (e.ttsProvider) {
912
+ case "openai":
913
+ return `OpenAI · ${e.openaiTtsModel} · ${e.ttsVoice}`;
914
+ case "webspeech":
915
+ return `Web Speech API · rate ${e.ttsSpeechRate} · pitch ${e.ttsSpeechPitch}`;
916
+ case "server-kokoro":
917
+ return `Kokoro (server) · ${e.ttsVoice} · ${e.kokoroDtype}/${e.kokoroDevice}`;
918
+ default:
919
+ return `Kokoro (browser) · ${e.ttsVoice} · ${Ae(e.kokoroBrowserDevice, e.kokoroDtype)}/${e.kokoroBrowserDevice}`;
920
+ }
921
+ }
922
+ const Ze = (e) => e.replace(/\b\w/g, (r) => r.toUpperCase());
923
+ function et({
924
+ apiBase: e = "/api",
925
+ title: r = "Voice Assistant",
926
+ showInfo: s = !0,
927
+ systemPrompt: a,
928
+ className: t = ""
929
+ } = {}) {
930
+ const { chat: i, info: n, config: l, memory: o, llmProgress: f, note: c, loading: v } = Qe({ apiBase: e, systemPrompt: a }), {
931
+ status: d,
932
+ progress: u,
933
+ error: m,
934
+ transcript: w,
935
+ streamingMessage: I,
936
+ micEnabled: x,
937
+ startListening: L,
938
+ stopListening: b,
939
+ submitText: E,
940
+ liveAnalyser: A,
941
+ devices: P,
942
+ selectedMicId: D,
943
+ setSelectedMicId: k
944
+ } = i, [V, $] = q(""), C = R(null);
945
+ j(() => {
946
+ var y;
947
+ (y = C.current) == null || y.scrollIntoView({ behavior: I !== null ? "auto" : "smooth" });
948
+ }, [w, I]);
949
+ const M = n && l.whisperDevice && [
950
+ ["STT", `Whisper · ${(l.whisperModel || n.whisperModel).split("/").pop()} · ${Ae(l.whisperDevice, l.whisperDtype)}/${l.whisperDevice}`],
951
+ ["TTS", Je({ ...n, ...l })],
952
+ ["Chat", n.hasApiKey ? `${n.chatProvider} · ${n.chatModel}` : "SmolLM2-360M-Instruct (in-browser)"],
953
+ ["Memory", [
954
+ o.browser != null ? `browser heap ${Se(o.browser)}` : "browser heap n/a",
955
+ o.server != null ? `server ${Se(o.server)}` : null
956
+ ].filter(Boolean).join(" · ")]
957
+ ];
958
+ return /* @__PURE__ */ S("div", { className: `tz-va ${t}`.trim(), children: [
959
+ /* @__PURE__ */ S("section", { className: "tz-va__card tz-va__header", children: [
960
+ /* @__PURE__ */ p("h1", { children: r }),
961
+ /* @__PURE__ */ p("span", { className: `tz-va__chip tz-va__chip--${d}`, children: Ze(d) })
962
+ ] }),
963
+ s && M && /* @__PURE__ */ p("section", { className: "tz-va__card tz-va__info", children: M.map(([y, W]) => /* @__PURE__ */ S("div", { className: "tz-va__info-row", children: [
964
+ /* @__PURE__ */ p("span", { className: "tz-va__info-label", children: y }),
965
+ /* @__PURE__ */ p("span", { className: "tz-va__info-value", children: W })
966
+ ] }, y)) }),
967
+ /* @__PURE__ */ S("section", { className: "tz-va__card", children: [
968
+ v && /* @__PURE__ */ S("div", { className: "tz-va__progress", children: [
969
+ /* @__PURE__ */ S("label", { children: [
970
+ "Whisper STT",
971
+ /* @__PURE__ */ p("div", { className: "tz-va__bar", children: /* @__PURE__ */ p("span", { style: { width: `${u.whisper * 100}%` } }) })
972
+ ] }),
973
+ /* @__PURE__ */ S("label", { children: [
974
+ "Kokoro TTS",
975
+ /* @__PURE__ */ p("div", { className: "tz-va__bar", children: /* @__PURE__ */ p("span", { style: { width: `${u.kokoro * 100}%` } }) })
976
+ ] }),
977
+ f > 0 && /* @__PURE__ */ S("label", { children: [
978
+ "Local LLM",
979
+ /* @__PURE__ */ p("div", { className: "tz-va__bar", children: /* @__PURE__ */ p("span", { style: { width: `${f * 100}%` } }) })
980
+ ] })
981
+ ] }),
982
+ /* @__PURE__ */ p("div", { className: "tz-va__button", children: /* @__PURE__ */ p(
983
+ We,
984
+ {
985
+ status: d,
986
+ active: x,
987
+ loading: v,
988
+ analyser: A,
989
+ onToggle: x ? b : L,
990
+ devices: P,
991
+ selectedMicId: D,
992
+ onDeviceChange: k,
993
+ inputData: V,
994
+ sendData: (y) => {
995
+ $(""), E(y);
996
+ }
997
+ }
998
+ ) }),
999
+ /* @__PURE__ */ p("div", { className: "tz-va__input-row", children: /* @__PURE__ */ p(
1000
+ "input",
1001
+ {
1002
+ type: "text",
1003
+ className: "tz-va__input",
1004
+ value: V,
1005
+ onChange: (y) => $(y.target.value),
1006
+ onKeyDown: (y) => {
1007
+ y.key === "Enter" && V.trim() && ($(""), E(V));
1008
+ },
1009
+ placeholder: "Type a message…",
1010
+ disabled: v
1011
+ }
1012
+ ) }),
1013
+ /* @__PURE__ */ p("p", { className: "tz-va__note", children: v ? u.kokoro < 1 ? "Loading Kokoro TTS…" : u.whisper < 1 ? "Loading Whisper STT…" : f > 0 && f < 1 ? "Loading local LLM (SmolLM2-360M, ~200 MB)…" : "Finishing up…" : "Ready." }),
1014
+ c && /* @__PURE__ */ p("p", { className: "tz-va__note", children: c })
1015
+ ] }),
1016
+ /* @__PURE__ */ S("section", { className: "tz-va__card tz-va__transcript", children: [
1017
+ w.map((y) => /* @__PURE__ */ S("div", { className: `tz-va__message tz-va__message--${y.role}`, children: [
1018
+ /* @__PURE__ */ p("small", { children: y.role === "user" ? "You" : "Assistant" }),
1019
+ /* @__PURE__ */ p("p", { children: y.content }),
1020
+ y.timings && /* @__PURE__ */ S("div", { className: "tz-va__timings", children: [
1021
+ y.timings.transcribeMs != null && /* @__PURE__ */ S("span", { children: [
1022
+ "transcribe ",
1023
+ we(y.timings.transcribeMs)
1024
+ ] }),
1025
+ y.timings.thinkMs != null && /* @__PURE__ */ S("span", { children: [
1026
+ "think ",
1027
+ we(y.timings.thinkMs)
1028
+ ] }),
1029
+ y.timings.ttsMs != null && /* @__PURE__ */ S("span", { children: [
1030
+ "tts ",
1031
+ we(y.timings.ttsMs)
1032
+ ] })
1033
+ ] })
1034
+ ] }, y.id)),
1035
+ I !== null && /* @__PURE__ */ S("div", { className: "tz-va__message tz-va__message--assistant tz-va__message--streaming", children: [
1036
+ /* @__PURE__ */ p("small", { children: "Assistant" }),
1037
+ /* @__PURE__ */ S("p", { children: [
1038
+ I,
1039
+ /* @__PURE__ */ p("span", { className: "tz-va__cursor" })
1040
+ ] })
1041
+ ] }),
1042
+ /* @__PURE__ */ p("div", { ref: C })
1043
+ ] }),
1044
+ m ? /* @__PURE__ */ S("section", { className: "tz-va__card", children: [
1045
+ /* @__PURE__ */ p("strong", { children: "Error:" }),
1046
+ /* @__PURE__ */ p("p", { children: m })
1047
+ ] }) : null
1048
+ ] });
1049
+ }
682
1050
  export {
683
- De as AIAssistantButton,
684
- y as STATES,
685
- xe as TZVoiceChat
1051
+ We as AIAssistantButton,
1052
+ z as STATES,
1053
+ Ce as TZVoiceChat,
1054
+ et as VoiceAssistant,
1055
+ He as createLocalChatStream,
1056
+ Ue as sendChatRequest,
1057
+ Qe as useVoiceAssistant
686
1058
  };