tz-voice-chat 1.0.2 → 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 x, useRef as L, useEffect as Q, useMemo as Se } from "react";
2
- import { jsx as w, jsxs as q } from "react/jsx-runtime";
3
- function me() {
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 me() {
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 me() {
42
52
  }
43
53
  };
44
54
  }
45
- async function ke(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 h = 0;
63
- const p = (d) => {
64
- typeof (d == null ? void 0 : d.progress) == "number" && (h = Math.max(h, d.progress / 100), e == null || e("kokoro", Math.min(0.99, h)));
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 c(d, D) {
67
- return i.from_pretrained("onnx-community/Kokoro-82M-ONNX", {
68
- dtype: D,
69
- device: d,
70
- progress_callback: p
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 a;
83
+ let v;
74
84
  try {
75
- a = await c(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.`), h = 0, a = await c("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;
91
+ }
92
+ return e == null || e("kokoro", 1), { kokoro: v };
93
+ }
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
+ }
81
109
  }
82
- return e == null || e("kokoro", 1), { kokoro: a };
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;
83
117
  }
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 h(a) {
88
- if (a instanceof AudioBuffer) return a;
89
- const l = (a == null ? void 0 : a.audio) ?? a;
90
- if (l instanceof ArrayBuffer) return await r.decodeAudioData(l.slice(0));
91
- if (l instanceof Float32Array) {
92
- const b = (a == null ? void 0 : a.samplingRate) ?? 24e3, d = r.createBuffer(1, l.length, b);
93
- return d.copyToChannel(l, 0), d;
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 p(a) {
98
- await r.resume();
99
- const l = r.createBufferSource();
100
- return l.buffer = a, 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 c() {
107
- if (!o) {
108
- for (o = !0; n.length > 0; ) {
109
- const a = 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 a;
112
- l && await p(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(a) {
122
- n.push(e.generate(a, { voice: s }).then(h)), c();
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((a) => setTimeout(a, 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 h(a) {
142
- const l = { text: a };
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 p(a) {
153
- await r.resume();
154
- const l = r.createBufferSource();
155
- return l.buffer = a, 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 c() {
162
- if (!o) {
163
- for (o = !0; n.length > 0; ) {
164
- const a = 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 p(await a);
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(a) {
176
- a != null && a.trim() && (n.push(h(a)), c());
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((a) => setTimeout(a, 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() {
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() {
197
231
  return e ? speechSynthesis.getVoices().find((c) => c.name === e || c.voiceURI === e) ?? null : null;
198
232
  }
199
- function h() {
200
- if (o || n.length === 0) return;
201
- o = !0;
202
- const p = n.shift(), c = new SpeechSynthesisUtterance(p), a = g();
203
- a && (c.voice = a), c.rate = s, c.pitch = t, c.onstart = () => {
204
- i || (i = !0, r == null || r());
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());
205
239
  }, c.onend = () => {
206
- o = !1, h();
207
- }, c.onerror = (l) => {
208
- console.error("[WebSpeech TTS] error", l.error), o = !1, h();
240
+ i = !1, o();
241
+ }, c.onerror = (d) => {
242
+ console.error("[WebSpeech TTS] error", d.error), i = !1, o();
209
243
  }, speechSynthesis.speak(c);
210
244
  }
211
245
  return {
212
- enqueue(p) {
213
- p != null && p.trim() && (n.push(p), h());
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((p) => setTimeout(p, 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,451 +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
- }, Le = "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 = Le,
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: h = "q8",
269
- whisperDevice: p = "cpu",
270
- kokoroDtype: c = "q8",
271
- kokoroBrowserDevice: a = "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] = x(y.IDLE), [D, M] = x(!0), [K, A] = x({ whisper: 0, kokoro: 0 }), [G, T] = x(null), [Y, re] = x([]), [ae, _] = x(null), [O, E] = x(!1), [W, v] = x(""), [R, P] = x([]), [se, X] = x(null), U = L(y.IDLE), Z = L(!1), N = L(null), V = L(null), B = L(null), $ = L(null), H = L(null), ie = L(null), ee = L([{ role: "system", content: s }]), ce = L(e);
275
- Q(() => {
276
- U.current = b;
277
- }, [b]), Q(() => {
278
- Z.current = O;
279
- }, [O]), Q(() => {
280
- ce.current = e;
281
- }, [e]), Q(() => {
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 S = await navigator.mediaDevices.enumerateDevices();
285
- P(S.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
- }, [O]), Q(() => {
291
- let m = !1;
292
- async function S() {
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 = V.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
- N.current = Ne({
300
- voice: r,
301
- rate: o,
302
- pitch: i,
303
- onPlayStart: u
304
- }), A((f) => ({ ...f, kokoro: 1 }));
305
- else if (t === "kokoro") {
306
- const { kokoro: f } = await ke(
307
- (k, F) => A((j) => ({ ...j, [k]: F })),
308
- { dtype: c, device: a, 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
- N.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
- N.current = Ie({ voice: r, onPlayStart: u, url: n }), A((f) => ({ ...f, kokoro: 1 }));
314
- if (m) return;
315
- $.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
- ), $.current.onmessage = (f) => {
323
- f.data.type === "transcript" ? ue(f.data.text) : f.data.type === "progress" ? A((k) => ({ ...k, whisper: f.data.progress })) : f.data.type === "ready" ? (A((k) => ({ ...k, whisper: 1 })), M(!1)) : f.data.type === "error" && (T(`Whisper: ${f.data.message}`), M(!1));
324
- }, $.current.onerror = () => {
325
- T("Model load failed. Check WebGPU/WASM browser support."), M(!1);
326
- }, $.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: h,
330
- device: p,
331
- modelProxyUrl: l
366
+ model: o,
367
+ dtype: f,
368
+ device: c,
369
+ modelProxyUrl: u
332
370
  });
333
- } catch (u) {
334
- m || (T("Initialisation failed: " + ((u == null ? void 0 : u.message) ?? String(u))), M(!1));
371
+ } catch (g) {
372
+ _ || (A("Initialisation failed: " + ((g == null ? void 0 : g.message) ?? String(g))), x(!1));
335
373
  }
336
374
  }
337
- return S(), () => {
338
- var u;
339
- m = !0, (u = $.current) == null || u.terminate();
375
+ return T(), () => {
376
+ var g;
377
+ _ = !0, (g = H.current) == null || g.terminate();
340
378
  };
341
- }, [t, g, h, p, c, a]);
342
- function le(m, S) {
343
- re((u) => [...u, { role: m, content: S, 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;
383
+ }
384
+ function ze(_, { timings: T }) {
385
+ D((g) => g.map((h) => h.id === _ ? { ...h, timings: { ...h.timings, ...T } } : h));
344
386
  }
345
- async function ue(m) {
346
- if (!(m != null && m.trim())) {
347
- d(Z.current ? y.LISTENING : y.IDLE);
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 S = [...ee.current, { role: "user", content: m }];
352
- ee.current = S, await ge(m, S);
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, S) {
355
- var u, f, k, F, j;
356
- (u = B.current) == null || u.abort(), B.current = new AbortController(), (f = N.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 C = me();
360
- let ne = "", oe = !1;
361
- _("");
362
- for await (const de of ce.current(m, S, B.current.signal))
363
- ne += de, _(ne), C.write(de).forEach((ve) => {
364
- var he;
365
- oe || (oe = !0, d(y.SPEAKING)), (he = N.current) == null || he.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 fe = C.flush();
368
- fe && (oe || d(y.SPEAKING), (k = N.current) == null || k.enqueue(fe)), le("assistant", ne), _(null), ee.current = [...ee.current, { role: "assistant", content: ne }], await ((F = N.current) == null ? void 0 : F.finished()), t === "webspeech" && ((j = V.current) == null || j.start());
369
- } catch (C) {
370
- _(null), C.name !== "AbortError" && T(C.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(Z.current ? y.LISTENING : y.IDLE);
422
+ w(Z.current ? z.LISTENING : z.IDLE);
373
423
  }
374
424
  }
375
- async function we() {
376
- var m, S;
377
- T(null), U.current === y.SPEAKING && ((m = N.current) == null || m.cancel(), (S = B.current) == null || S.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), E(!0);
429
+ w(z.LISTENING), C(!0);
380
430
  try {
381
- const u = await navigator.mediaDevices.getUserMedia({
382
- audio: W ? { deviceId: { exact: W } } : !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
- H.current = f;
388
- const k = f.createAnalyser();
389
- k.fftSize = 256, f.createMediaStreamSource(u).connect(k), X(k);
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
- V.current = await Te({
443
+ U.current = await Ke({
394
444
  onSpeechStart: () => {
395
- var u, f;
396
- t === "webspeech" && U.current === y.SPEAKING || (U.current === y.SPEAKING && ((u = N.current) == null || u.cancel(), (f = B.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" && U.current === y.SPEAKING || (d(y.TRANSCRIBING), (f = $.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
- T(u), d(y.IDLE);
452
+ onError: (g) => {
453
+ A(g), w(z.IDLE);
404
454
  },
405
- deviceId: W || void 0
455
+ deviceId: M || void 0
406
456
  });
407
- } catch (u) {
408
- console.error("[TZVoiceChat] startListening failed:", u), T("Microphone access failed. Allow audio permissions and refresh."), d(y.IDLE), E(!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, S, u, f, k;
413
- E(!1), (m = V.current) == null || m.destroy(), V.current = null, (S = ie.current) == null || S.getTracks().forEach((F) => F.stop()), ie.current = null, (u = H.current) == null || u.close(), H.current = null, X(null), (f = N.current) == null || f.cancel(), (k = B.current) == null || k.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 k;
417
- if (!(m != null && m.trim())) return;
418
- d(y.SPEAKING);
419
- const S = me(), u = S.write(m), f = S.flush();
420
- [...u, ...f ? [f] : []].forEach((F) => {
421
- var j;
422
- return (j = N.current) == null ? void 0 : j.enqueue(F);
423
- }), (k = N.current) == null || k.finished().then(() => {
424
- d(Z.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: D,
481
+ loading: I,
432
482
  /** Per-model load progress: { whisper: 0–1, kokoro: 0–1 } */
433
- progress: K,
483
+ progress: L,
434
484
  /** Last error string, or null. Cleared on startListening(). */
435
- error: G,
436
- /** Completed conversation turns: [{ role, content, time }] */
437
- transcript: Y,
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: ae,
489
+ streamingMessage: k,
440
490
  /** Whether the microphone is currently open. */
441
- micEnabled: O,
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,
448
498
  /** Submit text as a user message, triggering the full AI → TTS pipeline (same as voice transcription). */
449
- submitText: ue,
499
+ submitText: be,
450
500
  /** AnalyserNode for real-time waveform rendering, or null when mic is off. */
451
- liveAnalyser: se,
501
+ liveAnalyser: ce,
452
502
  /** Available audio input devices (updated on permission grant). */
453
- devices: R,
503
+ devices: W,
454
504
  /** Currently selected device ID ('': system default). */
455
- selectedMicId: W,
505
+ selectedMicId: M,
456
506
  /** Select an audio input device by its deviceId. */
457
- setSelectedMicId: v
507
+ setSelectedMicId: y
458
508
  };
459
509
  }
460
- function pe(e) {
461
- 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;
462
512
  return [
463
- parseInt(t.slice(0, 2), 16),
464
- parseInt(t.slice(2, 4), 16),
465
- 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)
466
516
  ];
467
517
  }
468
- function ze(e, s, t) {
469
- e /= 255, s /= 255, t /= 255;
470
- const r = Math.max(e, s, t), n = Math.min(e, s, t), o = (r + n) / 2;
471
- if (r === n) return [0, 0, o * 100];
472
- const i = r - n, g = o > 0.5 ? i / (2 - r - n) : i / (r + n);
473
- let h;
474
- 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) {
475
525
  case e:
476
- h = ((s - t) / i + (s < t ? 6 : 0)) / 6;
526
+ o = ((r - s) / n + (r < s ? 6 : 0)) / 6;
477
527
  break;
478
- case s:
479
- h = ((t - e) / i + 2) / 6;
528
+ case r:
529
+ o = ((s - e) / n + 2) / 6;
480
530
  break;
481
531
  default:
482
- h = ((e - s) / i + 4) / 6;
532
+ o = ((e - r) / n + 4) / 6;
483
533
  }
484
- return [h * 360, g * 100, o * 100];
534
+ return [o * 360, l * 100, i * 100];
485
535
  }
486
- function Me(e, s, t) {
487
- s /= 100, t /= 100;
488
- 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)));
489
- 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)];
490
540
  }
491
- function z(e, s) {
492
- const [t, r, n] = pe(e), [o, i, g] = ze(t, r, n), [h, p, c] = Me(o, i, Math.max(0, Math.min(100, g + s)));
493
- return `rgb(${h}, ${p}, ${c})`;
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})`;
494
544
  }
495
- function I(e, s) {
496
- const [t, r, n] = pe(e);
497
- 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})`;
498
548
  }
499
- function J(e, s) {
500
- return e.replace("rgb(", "rgba(").replace(")", `, ${s})`);
549
+ function X(e, r) {
550
+ return e.replace("rgb(", "rgba(").replace(")", `, ${r})`);
501
551
  }
502
- const te = 10;
503
- function _e({ analyser: e }) {
504
- const s = L(null), t = L(null);
505
- return Q(() => {
506
- if (cancelAnimationFrame(t.current), !e) return;
507
- const r = s.current;
508
- if (!r) return;
509
- const n = r.getContext("2d"), o = e.frequencyBinCount, i = new Uint8Array(o), g = Math.max(1, Math.floor(o / te)), h = getComputedStyle(r), p = +h.getPropertyValue("--bar-hue"), c = +h.getPropertyValue("--bar-hue-range"), a = +h.getPropertyValue("--bar-sat"), l = +h.getPropertyValue("--bar-lit"), b = +h.getPropertyValue("--bar-lit-range"), d = () => {
510
- t.current = requestAnimationFrame(d), e.getByteFrequencyData(i);
511
- const D = r.width, M = r.height;
512
- n.clearRect(0, 0, D, M);
513
- const K = (D - (te - 1) * 2) / te;
514
- for (let A = 0; A < te; A++) {
515
- const G = i[A * g] / 255, T = Math.max(3, G * M * 0.88);
516
- n.fillStyle = `hsl(${p + G * c}, ${a}%, ${l + G * b}%)`, n.beginPath(), n.roundRect(A * (K + 2), (M - T) / 2, K, T, [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();
517
567
  }
518
568
  };
519
- return d(), () => cancelAnimationFrame(t.current);
520
- }, [e]), /* @__PURE__ */ w("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" });
521
571
  }
522
- function De({
572
+ function We({
523
573
  status: e = "idle",
524
- active: s = !1,
525
- loading: t = !1,
526
- analyser: r = null,
527
- onToggle: n,
528
- devices: o = [],
529
- selectedMicId: i = "",
530
- 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,
531
581
  // ── Manual input ───────────────────────────────────────────
532
- inputData: h = "",
533
- sendData: p,
582
+ inputData: o = "",
583
+ sendData: f,
534
584
  // ── Theming ────────────────────────────────────────────────
535
585
  accentColor: c = "#f97316",
536
- uiColor: a = "#64748b",
537
- size: l = 70,
538
- barHue: b = 25,
539
- barHueRange: d = 20,
540
- barSat: D = 88,
541
- barLit: M = 65,
542
- barLitRange: K = 20
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
543
593
  }) {
544
- var W;
545
- const [A, G] = x(!1), T = L(null);
546
- Q(() => {
547
- if (!A) return;
548
- function v(R) {
549
- var P;
550
- (P = T.current) != null && P.contains(R.target) || G(!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);
551
601
  }
552
- return document.addEventListener("pointerdown", v), () => document.removeEventListener("pointerdown", v);
553
- }, [A]);
554
- function Y(v) {
555
- g == null || g(v), G(!1);
602
+ return document.addEventListener("pointerdown", M), () => document.removeEventListener("pointerdown", M);
603
+ }, [L]);
604
+ function A(M) {
605
+ l == null || l(M), b(!1);
556
606
  }
557
- const re = Se(() => {
558
- const v = z(c, -8), R = z(c, -15), P = z(c, -22), se = z(c, -30), X = z(c, -42), U = z(c, 8), Z = z(c, 20), N = z(c, 30), V = z(a, -22), B = z(a, -30), $ = z(a, 18), H = z(a, 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);
559
609
  return {
560
- "--tz-size": `${l}px`,
610
+ "--tz-size": `${d}px`,
561
611
  // Accent shades
562
612
  "--tz-a": c,
563
- "--tz-a-d8": v,
564
- "--tz-a-d15": R,
565
- "--tz-a-d22": P,
566
- "--tz-a-d30": se,
567
- "--tz-a-d42": X,
568
- "--tz-a-l8": U,
569
- "--tz-a-l20": Z,
570
- "--tz-a-l30": N,
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,
571
621
  // Accent + alpha
572
- "--tz-a-25": I(c, 0.25),
573
- "--tz-a-28": I(c, 0.28),
574
- "--tz-a-30": I(c, 0.3),
575
- "--tz-a-32": I(c, 0.32),
576
- "--tz-a-34": I(c, 0.34),
577
- "--tz-a-35": I(c, 0.35),
578
- "--tz-a-38": I(c, 0.38),
579
- "--tz-a-45": I(c, 0.45),
580
- "--tz-a-50": I(c, 0.5),
581
- "--tz-a-55": I(c, 0.55),
582
- "--tz-a-60": I(c, 0.6),
583
- "--tz-a-65": I(c, 0.65),
584
- "--tz-a-68": I(c, 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),
585
635
  // UI shades
586
- "--tz-u": a,
587
- "--tz-u-d22": V,
588
- "--tz-u-d30": B,
589
- "--tz-u-l18": $,
636
+ "--tz-u": v,
637
+ "--tz-u-d22": K,
638
+ "--tz-u-d30": U,
639
+ "--tz-u-l18": B,
590
640
  "--tz-u-l37": H,
591
641
  // UI + alpha
592
- "--tz-u-30": I(a, 0.3),
593
- "--tz-u-55": I(a, 0.55),
594
- "--tz-u-d30-a85": J(B, 0.85),
595
- "--tz-u-l18-a18": J($, 0.18),
596
- "--tz-u-l18-a20": J($, 0.2),
597
- "--tz-u-l18-a32": J($, 0.32),
598
- "--tz-u-d22-a90": J(V, 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),
599
649
  // Waveform bar colors (cascade to canvas via getComputedStyle)
600
- "--bar-hue": b,
601
- "--bar-hue-range": d,
602
- "--bar-sat": D,
603
- "--bar-lit": M,
604
- "--bar-lit-range": K
650
+ "--bar-hue": u,
651
+ "--bar-hue-range": m,
652
+ "--bar-sat": w,
653
+ "--bar-lit": I,
654
+ "--bar-lit-range": x
605
655
  };
606
- }, [c, a, l, b, d, D, M, K]), ae = ((W = o.find((v) => v.deviceId === i)) == null ? void 0 : W.label) || (i ? `Mic ${i.slice(0, 6)}…` : "Default mic"), _ = h.trim().length > 0, O = _ ? "ready" : s ? e : "off";
607
- let E;
608
- return _ ? E = /* @__PURE__ */ w("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ w("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) }) : !s || e === "idle" ? E = /* @__PURE__ */ q("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
609
- /* @__PURE__ */ w("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" }),
610
- /* @__PURE__ */ w("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" }),
611
- /* @__PURE__ */ w("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" })
612
- ] }) : e === "listening" ? E = /* @__PURE__ */ w(_e, { analyser: r }) : e === "transcribing" ? E = /* @__PURE__ */ w("div", { className: "ai-btn__bars ai-btn__bars--transcribing", children: Array.from({ length: 7 }, (v, R) => /* @__PURE__ */ w("span", { style: { animationDelay: `${R * 0.1}s` } }, R)) }) : e === "thinking" ? E = /* @__PURE__ */ q("div", { className: "ai-btn__dots", children: [
613
- /* @__PURE__ */ w("span", {}),
614
- /* @__PURE__ */ w("span", { style: { animationDelay: "0.18s" } }),
615
- /* @__PURE__ */ w("span", { style: { animationDelay: "0.36s" } })
616
- ] }) : e === "speaking" && (E = /* @__PURE__ */ w("div", { className: "ai-btn__bars ai-btn__bars--speaking", children: Array.from({ length: 7 }, (v, R) => /* @__PURE__ */ w("span", { style: { animationDelay: `${R * 0.11}s` } }, R)) })), /* @__PURE__ */ q("div", { className: "ai-btn-root", style: re, children: [
617
- /* @__PURE__ */ q("div", { className: `ai-btn-rings ai-btn-rings--${O}`, "aria-hidden": "true", children: [
618
- /* @__PURE__ */ w("span", { className: "ai-ring ai-ring--1" }),
619
- /* @__PURE__ */ w("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" })
620
670
  ] }),
621
- /* @__PURE__ */ q(
671
+ /* @__PURE__ */ S(
622
672
  "button",
623
673
  {
624
- className: `ai-btn ai-btn--${O}`,
625
- disabled: t,
626
- onClick: _ ? () => p == null ? void 0 : p(h) : n,
627
- "aria-label": _ ? "Send message" : s ? "Stop assistant" : "Start assistant",
628
- "aria-pressed": _ ? void 0 : 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,
629
679
  children: [
630
- E,
631
- s && !_ && /* @__PURE__ */ w("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: "■" })
632
682
  ]
633
683
  }
634
684
  ),
635
- /* @__PURE__ */ q("div", { className: `ai-mic-sel${A ? " open" : ""}`, ref: T, children: [
636
- /* @__PURE__ */ q(
685
+ /* @__PURE__ */ S("div", { className: `ai-mic-sel${L ? " open" : ""}`, ref: E, children: [
686
+ /* @__PURE__ */ S(
637
687
  "button",
638
688
  {
639
689
  className: "ai-mic-sel__trigger",
640
- onClick: () => G((v) => !v),
690
+ onClick: () => b((M) => !M),
641
691
  title: "Change microphone",
642
692
  "aria-label": "Change microphone",
643
- "aria-expanded": A,
693
+ "aria-expanded": L,
644
694
  children: [
645
- /* @__PURE__ */ q("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
646
- /* @__PURE__ */ w("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z" }),
647
- /* @__PURE__ */ w("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" })
648
698
  ] }),
649
- /* @__PURE__ */ w("span", { className: "ai-mic-sel__label", children: ae }),
650
- /* @__PURE__ */ w(
699
+ /* @__PURE__ */ p("span", { className: "ai-mic-sel__label", children: D }),
700
+ /* @__PURE__ */ p(
651
701
  "svg",
652
702
  {
653
- className: `ai-mic-sel__caret${A ? " open" : ""}`,
703
+ className: `ai-mic-sel__caret${L ? " open" : ""}`,
654
704
  width: "9",
655
705
  height: "9",
656
706
  viewBox: "0 0 24 24",
657
707
  fill: "currentColor",
658
708
  "aria-hidden": "true",
659
- children: /* @__PURE__ */ w("path", { d: "M12 16L4 8h16l-8 8z" })
709
+ children: /* @__PURE__ */ p("path", { d: "M12 16L4 8h16l-8 8z" })
660
710
  }
661
711
  )
662
712
  ]
663
713
  }
664
714
  ),
665
- A && /* @__PURE__ */ q("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
666
- /* @__PURE__ */ w(
715
+ L && /* @__PURE__ */ S("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
716
+ /* @__PURE__ */ p(
667
717
  "li",
668
718
  {
669
719
  role: "option",
670
- className: `ai-mic-sel__option${i === "" ? " selected" : ""}`,
671
- onClick: () => Y(""),
672
- "aria-selected": i === "",
720
+ className: `ai-mic-sel__option${n === "" ? " selected" : ""}`,
721
+ onClick: () => A(""),
722
+ "aria-selected": n === "",
673
723
  children: "Default microphone"
674
724
  }
675
725
  ),
676
- o.map((v) => /* @__PURE__ */ w(
726
+ i.map((M) => /* @__PURE__ */ p(
677
727
  "li",
678
728
  {
679
729
  role: "option",
680
- className: `ai-mic-sel__option${i === v.deviceId ? " selected" : ""}`,
681
- onClick: () => Y(v.deviceId),
682
- "aria-selected": i === v.deviceId,
683
- children: v.label || `Microphone ${v.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)}`
684
734
  },
685
- v.deviceId
735
+ M.deviceId
686
736
  ))
687
737
  ] })
688
738
  ] })
689
739
  ] });
690
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
+ }
691
1050
  export {
692
- De as AIAssistantButton,
693
- y as STATES,
694
- 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
695
1058
  };