tz-voice-chat 1.1.2 → 1.2.0

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.
Files changed (36) hide show
  1. package/README.md +607 -149
  2. package/bin/tz-voice-chat.js +46 -0
  3. package/dist/assets/whisperWorker-D69IwlqW.js +1 -0
  4. package/dist/index.cjs +2 -2
  5. package/dist/index.js +1327 -698
  6. package/dist/style.css +1 -1
  7. package/dist-app/assets/index-BDMCgrF_.css +1 -0
  8. package/dist-app/assets/index-CFWv17S2.js +41 -0
  9. package/dist-app/assets/llmWorker-CVEGn6yI.js +1 -0
  10. package/dist-app/assets/whisperWorker-D69IwlqW.js +1 -0
  11. package/dist-app/index.html +27 -0
  12. package/package.json +45 -11
  13. package/server/chat.js +91 -0
  14. package/server/elevenlabs.js +40 -0
  15. package/server/index.js +173 -92
  16. package/server/openai-stt.js +21 -0
  17. package/server/run.js +42 -0
  18. package/server/settings.js +102 -0
  19. package/server/tts.js +26 -3
  20. package/server/vendor.js +57 -0
  21. package/shared/settingsSchema.js +212 -0
  22. package/vendor/kokoro/kokoro.web.js +1 -0
  23. package/vendor/ort/ort-wasm-simd-threaded.jsep.mjs +125 -0
  24. package/vendor/ort/ort-wasm-simd-threaded.jsep.wasm +0 -0
  25. package/vendor/ort/ort-wasm-simd-threaded.mjs +70 -0
  26. package/vendor/ort/ort-wasm-simd-threaded.wasm +0 -0
  27. package/vendor/ort/ort.wasm.min.js +8 -0
  28. package/vendor/transformers/ort-wasm-simd-threaded.jsep.mjs +125 -0
  29. package/vendor/transformers/ort-wasm-simd-threaded.jsep.wasm +0 -0
  30. package/vendor/transformers/transformers.min.js +2 -0
  31. package/vendor/transformers/transformers.node.min.mjs +2 -0
  32. package/vendor/transformers/transformers.node.mjs +36472 -0
  33. package/vendor/vad/bundle.min.js +2 -0
  34. package/vendor/vad/silero_vad_legacy.onnx +0 -0
  35. package/vendor/vad/vad.worklet.bundle.min.js +1 -0
  36. package/dist/assets/whisperWorker-BJuP9cl9.js +0 -1
package/dist/index.js CHANGED
@@ -1,162 +1,162 @@
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;
1
+ import { useState as z, useRef as W, useEffect as j, useMemo as Be, useCallback as Ne } from "react";
2
+ import { jsx as u, jsxs as _, Fragment as Ee } from "react/jsx-runtime";
3
+ const _e = 60, ue = 200;
4
+ function Pe() {
5
+ let e = "", a = !0;
6
+ function r(n, o, s) {
7
+ n.push(o), e = s, a = !1;
8
8
  }
9
- function a() {
10
- const t = [];
9
+ function c() {
10
+ const n = [];
11
11
  for (; ; ) {
12
- const i = /([.!?]{1,3})(\s|$)/.exec(e);
13
- if (i) {
14
- const n = e.slice(0, i.index + i[0].length).trim();
15
- if (n.length >= 10) {
16
- s(t, n, e.slice(i.index + i[0].length));
12
+ const o = /([.!?]{1,3})(\s|$)/.exec(e);
13
+ if (o) {
14
+ const s = e.slice(0, o.index + o[0].length).trim();
15
+ if (s.length >= 10) {
16
+ r(n, s, e.slice(o.index + o[0].length));
17
17
  continue;
18
18
  }
19
19
  }
20
- if (r) {
20
+ if (a) {
21
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();
22
+ const s = /[,;:—–](\s|$)/.exec(e);
23
+ if (s) {
24
+ const l = e.slice(0, s.index + s[0].length).trim();
25
25
  if (l.length >= 20) {
26
- s(t, l, e.slice(n.index + n[0].length));
26
+ r(n, l, e.slice(s.index + s[0].length));
27
27
  continue;
28
28
  }
29
29
  }
30
30
  }
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());
31
+ if (e.length >= _e) {
32
+ const s = e.lastIndexOf(" ", _e - 1), l = s > 10 ? s : _e;
33
+ r(n, e.slice(0, l).trim(), e.slice(l).trimStart());
34
34
  continue;
35
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());
36
+ } else if (e.length >= ue) {
37
+ const s = e.slice(0, ue), l = Math.max(s.lastIndexOf(", "), s.lastIndexOf("; "), s.lastIndexOf(": ")), i = l > ue / 2 ? l + 1 : s.lastIndexOf(" ") > 10 ? s.lastIndexOf(" ") : ue;
38
+ r(n, e.slice(0, i).trim(), e.slice(i).trimStart());
39
39
  continue;
40
40
  }
41
41
  break;
42
42
  }
43
- return t;
43
+ return n;
44
44
  }
45
45
  return {
46
- write(t) {
47
- return e += t, a();
46
+ write(n) {
47
+ return e += n, c();
48
48
  },
49
49
  flush() {
50
- const t = e.trim();
51
- return e = "", t;
50
+ const n = e.trim();
51
+ return e = "", n;
52
52
  }
53
53
  };
54
54
  }
55
- async function qe(e, {
56
- dtype: r = "q8",
57
- device: s = "cpu",
58
- modelProxyUrl: a = "/api/models/"
55
+ async function Ge(e, {
56
+ dtype: a = "q8",
57
+ device: r = "cpu",
58
+ modelProxyUrl: c = "/api/models/"
59
59
  } = {}) {
60
- var d, u;
61
- const { env: t } = await import(
60
+ var f, h;
61
+ const { env: n } = await import(
62
62
  /* @vite-ignore */
63
63
  "/vendor/transformers/transformers.min.js"
64
64
  );
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(
65
+ n.remoteHost = c, (h = (f = n == null ? void 0 : n.backends) == null ? void 0 : f.onnx) != null && h.wasm && (n.backends.onnx.wasm.wasmPaths = "/vendor/transformers/"), n != null && n.onnx && (n.onnx.logSeverityLevel = 3);
66
+ const o = await import(
67
67
  /* @vite-ignore */
68
68
  "/vendor/kokoro/kokoro.web.js"
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)));
69
+ ), { KokoroTTS: s } = o;
70
+ let l = a;
71
+ r === "webgpu" && (a === "q4" || a === "q8") && (console.warn(`[modelLoader] dtype "${a}" not supported on WebGPU — using "fp32".`), l = "fp32");
72
+ let i = 0;
73
+ const p = (w) => {
74
+ typeof (w == null ? void 0 : w.progress) == "number" && (i = Math.max(i, w.progress / 100), e == null || e("kokoro", Math.min(0.99, i)));
75
75
  };
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
76
+ async function d(w, A) {
77
+ return s.from_pretrained("onnx-community/Kokoro-82M-ONNX", {
78
+ dtype: A,
79
+ device: w,
80
+ progress_callback: p
81
81
  });
82
82
  }
83
- let v;
83
+ let k;
84
84
  try {
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);
85
+ k = await d(r, l);
86
+ } catch (w) {
87
+ if (r !== "wasm")
88
+ console.warn(`[modelLoader] Kokoro on "${r}" failed (${w == null ? void 0 : w.message}) — falling back to WASM.`), i = 0, k = await d("wasm", a);
89
89
  else
90
- throw m;
90
+ throw w;
91
91
  }
92
- return e == null || e("kokoro", 1), { kokoro: v };
92
+ return e == null || e("kokoro", 1), { kokoro: k };
93
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);
94
+ function he(e, a, { threshold: r = 0.01, padMs: c = 25 } = {}) {
95
+ const { numberOfChannels: n, length: o, sampleRate: s } = a;
96
+ let l = o, i = -1;
97
+ for (let h = 0; h < n; h++) {
98
+ const w = a.getChannelData(h);
99
+ for (let A = 0; A < o; A++)
100
+ if (Math.abs(w[A]) > r) {
101
+ A < l && (l = A);
102
102
  break;
103
103
  }
104
- for (let w = i - 1; w >= 0; w--)
105
- if (Math.abs(m[w]) > s) {
106
- w > o && (o = w);
104
+ for (let A = o - 1; A >= 0; A--)
105
+ if (Math.abs(w[A]) > r) {
106
+ A > i && (i = A);
107
107
  break;
108
108
  }
109
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;
110
+ if (i < l) return a;
111
+ const p = Math.round(c / 1e3 * s), d = Math.max(0, l - p), k = Math.min(o, i + 1 + p);
112
+ if (d === 0 && k === o) return a;
113
+ const f = e.createBuffer(n, k - d, s);
114
+ for (let h = 0; h < n; h++)
115
+ f.copyToChannel(a.getChannelData(h).subarray(d, k), h);
116
+ return f;
117
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);
118
+ function Fe(e, { voice: a = "af_bella", speed: r = 1, onPlayStart: c } = {}) {
119
+ const n = new AudioContext(), o = [];
120
+ let s = !1, l = null, i = !1;
121
+ async function p(f) {
122
+ if (f instanceof AudioBuffer) return he(n, f);
123
+ const h = (f == null ? void 0 : f.audio) ?? f;
124
+ if (h instanceof ArrayBuffer) return he(n, await n.decodeAudioData(h.slice(0)));
125
+ if (h instanceof Float32Array) {
126
+ const w = (f == null ? void 0 : f.samplingRate) ?? 24e3, A = n.createBuffer(1, h.length, w);
127
+ return A.copyToChannel(h, 0), he(n, A);
128
128
  }
129
129
  throw new Error("Unsupported TTS payload");
130
130
  }
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());
131
+ async function d(f) {
132
+ await n.resume();
133
+ const h = n.createBufferSource();
134
+ return h.buffer = f, h.connect(n.destination), new Promise((w) => {
135
+ h.onended = () => {
136
+ l === h && (l = null), w();
137
+ }, l = h, h.start(), i || (i = !0, c == null || c());
138
138
  });
139
139
  }
140
- async function v() {
141
- if (!n) {
142
- for (n = !0; i.length > 0; ) {
143
- const d = i.shift();
140
+ async function k() {
141
+ if (!s) {
142
+ for (s = !0; o.length > 0; ) {
143
+ const f = o.shift();
144
144
  try {
145
- const u = await d;
146
- u && await c(u);
147
- } catch (u) {
148
- console.error("[TtsQueue]", u);
145
+ const h = await f;
146
+ h && await d(h);
147
+ } catch (h) {
148
+ console.error("[TtsQueue]", h);
149
149
  }
150
150
  }
151
- n = !1;
151
+ s = !1;
152
152
  }
153
153
  }
154
154
  return {
155
- enqueue(d) {
156
- i.push(e.generate(d, { voice: r, speed: s }).then(f)), v();
155
+ enqueue(f) {
156
+ o.push(e.generate(f, { voice: a, speed: r }).then(p)), k();
157
157
  },
158
158
  cancel() {
159
- if (i.length = 0, o = !1, l) {
159
+ if (o.length = 0, i = !1, l) {
160
160
  try {
161
161
  l.stop();
162
162
  } catch {
@@ -165,99 +165,99 @@ function Ve(e, { voice: r = "af_bella", speed: s = 1, onPlayStart: a } = {}) {
165
165
  }
166
166
  },
167
167
  async finished() {
168
- for (; n || i.length > 0; ) await new Promise((d) => setTimeout(d, 200));
168
+ for (; s || o.length > 0; ) await new Promise((f) => setTimeout(f, 200));
169
169
  }
170
170
  };
171
171
  }
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, {
172
+ function He({ voice: e = "", speed: a = 1, onPlayStart: r, url: c = "/api/tts" } = {}) {
173
+ const n = new AudioContext(), o = [];
174
+ let s = !1, l = null, i = !1;
175
+ async function p(f) {
176
+ const h = { text: f };
177
+ e && (h.voice = e), a !== 1 && (h.speed = a);
178
+ const w = await fetch(c, {
179
179
  method: "POST",
180
180
  headers: { "Content-Type": "application/json" },
181
- body: JSON.stringify(u)
181
+ body: JSON.stringify(h)
182
182
  });
183
- if (!m.ok) throw new Error(`TTS ${m.status}: ${await m.text()}`);
184
- return ie(t, await t.decodeAudioData(await m.arrayBuffer()));
183
+ if (!w.ok) throw new Error(`TTS ${w.status}: ${await w.text()}`);
184
+ return he(n, await n.decodeAudioData(await w.arrayBuffer()));
185
185
  }
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());
186
+ async function d(f) {
187
+ await n.resume();
188
+ const h = n.createBufferSource();
189
+ return h.buffer = f, h.connect(n.destination), new Promise((w) => {
190
+ h.onended = () => {
191
+ l === h && (l = null), w();
192
+ }, l = h, h.start(), i || (i = !0, r == null || r());
193
193
  });
194
194
  }
195
- async function v() {
196
- if (!n) {
197
- for (n = !0; i.length > 0; ) {
198
- const d = i.shift();
195
+ async function k() {
196
+ if (!s) {
197
+ for (s = !0; o.length > 0; ) {
198
+ const f = o.shift();
199
199
  try {
200
- await c(await d);
201
- } catch (u) {
202
- console.error("[ServerTTS]", u);
200
+ await d(await f);
201
+ } catch (h) {
202
+ console.error("[ServerTTS]", h);
203
203
  }
204
204
  }
205
- n = !1;
205
+ s = !1;
206
206
  }
207
207
  }
208
208
  return {
209
- enqueue(d) {
210
- d != null && d.trim() && (i.push(f(d)), v());
209
+ enqueue(f) {
210
+ f != null && f.trim() && (o.push(p(f)), k());
211
211
  },
212
212
  cancel() {
213
- if (i.length = 0, l) {
213
+ if (o.length = 0, l) {
214
214
  try {
215
215
  l.stop();
216
216
  } catch {
217
217
  }
218
218
  l = null;
219
219
  }
220
- o = !1;
220
+ i = !1;
221
221
  },
222
222
  async finished() {
223
- for (; n || i.length > 0; ) await new Promise((d) => setTimeout(d, 100));
223
+ for (; s || o.length > 0; ) await new Promise((f) => setTimeout(f, 100));
224
224
  }
225
225
  };
226
226
  }
227
- function Pe({ voice: e = "", rate: r = 1, pitch: s = 1, onPlayStart: a } = {}) {
228
- const t = [];
229
- let i = !1, n = !1;
227
+ function Ye({ voice: e = "", rate: a = 1, pitch: r = 1, onPlayStart: c } = {}) {
228
+ const n = [];
229
+ let o = !1, s = !1;
230
230
  function l() {
231
- return e ? speechSynthesis.getVoices().find((c) => c.name === e || c.voiceURI === e) ?? null : null;
231
+ return e ? speechSynthesis.getVoices().find((d) => d.name === e || d.voiceURI === e) ?? null : null;
232
232
  }
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);
233
+ function i() {
234
+ if (o || n.length === 0) return;
235
+ o = !0;
236
+ const p = n.shift(), d = new SpeechSynthesisUtterance(p), k = l();
237
+ k && (d.voice = k), d.rate = a, d.pitch = r, d.onstart = () => {
238
+ s || (s = !0, c == null || c());
239
+ }, d.onend = () => {
240
+ o = !1, i();
241
+ }, d.onerror = (f) => {
242
+ console.error("[WebSpeech TTS] error", f.error), o = !1, i();
243
+ }, speechSynthesis.speak(d);
244
244
  }
245
245
  return {
246
- enqueue(f) {
247
- f != null && f.trim() && (t.push(f), o());
246
+ enqueue(p) {
247
+ p != null && p.trim() && (n.push(p), i());
248
248
  },
249
249
  cancel() {
250
- t.length = 0, speechSynthesis.cancel(), i = !1, n = !1;
250
+ n.length = 0, speechSynthesis.cancel(), o = !1, s = !1;
251
251
  },
252
252
  async finished() {
253
- for (; i || t.length > 0; ) await new Promise((f) => setTimeout(f, 100));
253
+ for (; o || n.length > 0; ) await new Promise((p) => setTimeout(p, 100));
254
254
  }
255
255
  };
256
256
  }
257
- async function Ke({ onSpeechStart: e, onSpeechEnd: r, onError: s, deviceId: a }) {
257
+ async function Je({ onSpeechStart: e, onSpeechEnd: a, onError: r, deviceId: c }) {
258
258
  try {
259
- const { MicVAD: t } = window.vad;
260
- return await t.new({
259
+ const { MicVAD: n } = window.vad;
260
+ return await n.new({
261
261
  model: "legacy",
262
262
  baseAssetPath: "/vendor/vad/",
263
263
  onnxWASMBasePath: "/vendor/ort/",
@@ -265,11 +265,11 @@ async function Ke({ onSpeechStart: e, onSpeechEnd: r, onError: s, deviceId: a })
265
265
  echoCancellation: !0,
266
266
  noiseSuppression: !0,
267
267
  autoGainControl: !1,
268
- ...a ? { deviceId: { exact: a } } : {}
268
+ ...c ? { deviceId: { exact: c } } : {}
269
269
  },
270
270
  onSpeechStart: () => e == null ? void 0 : e(),
271
- onSpeechEnd: (n) => {
272
- console.log("[VAD] onSpeechEnd — samples:", n == null ? void 0 : n.length), r == null || r(n);
271
+ onSpeechEnd: (s) => {
272
+ console.log("[VAD] onSpeechEnd — samples:", s == null ? void 0 : s.length), a == null || a(s);
273
273
  },
274
274
  onVADMisfire: () => {
275
275
  },
@@ -279,507 +279,556 @@ async function Ke({ onSpeechStart: e, onSpeechEnd: r, onError: s, deviceId: a })
279
279
  minSpeechFrames: 3,
280
280
  preSpeechPadFrames: 1
281
281
  });
282
- } catch (t) {
283
- throw s == null || s("VAD initialization failed. Falling back to manual microphone capture."), t;
282
+ } catch (n) {
283
+ throw r == null || r("VAD initialization failed. Falling back to manual microphone capture."), n;
284
+ }
285
+ }
286
+ function Qe(e, a = 16e3) {
287
+ const r = e.length * 2, c = new ArrayBuffer(44 + r), n = new DataView(c), o = (s, l) => {
288
+ for (let i = 0; i < l.length; i++) n.setUint8(s + i, l.charCodeAt(i));
289
+ };
290
+ o(0, "RIFF"), n.setUint32(4, 36 + r, !0), o(8, "WAVE"), o(12, "fmt "), n.setUint32(16, 16, !0), n.setUint16(20, 1, !0), n.setUint16(22, 1, !0), n.setUint32(24, a, !0), n.setUint32(28, a * 2, !0), n.setUint16(32, 2, !0), n.setUint16(34, 16, !0), o(36, "data"), n.setUint32(40, r, !0);
291
+ for (let s = 0, l = 44; s < e.length; s++, l += 2) {
292
+ const i = Math.max(-1, Math.min(1, e[s]));
293
+ n.setInt16(l, i < 0 ? i * 32768 : i * 32767, !0);
284
294
  }
295
+ return new Blob([c], { type: "audio/wav" });
285
296
  }
286
- const z = {
297
+ const x = {
287
298
  IDLE: "idle",
288
299
  LISTENING: "listening",
289
300
  TRANSCRIBING: "transcribing",
290
301
  THINKING: "thinking",
291
302
  SPEAKING: "speaking"
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({
303
+ }, 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.";
304
+ function Xe({
294
305
  processInput: e,
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,
306
+ systemPrompt: a = Ze,
307
+ ttsProvider: r = "server-kokoro",
308
+ ttsVoice: c = "af_bella",
309
+ ttsSpeed: n = 1,
310
+ ttsServerUrl: o = "/api/tts",
311
+ ttsSpeechRate: s = 1,
301
312
  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/"
313
+ sttProvider: i = "whisper",
314
+ sttServerUrl: p = "/api/stt",
315
+ whisperModel: d = "onnx-community/whisper-tiny.en",
316
+ whisperDtype: k = "q8",
317
+ whisperDevice: f = "wasm",
318
+ kokoroDtype: h = "q8",
319
+ kokoroBrowserDevice: w = "wasm",
320
+ modelProxyUrl: A = "/api/models/"
308
321
  } = {}) {
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;
322
+ const [N, S] = z(x.IDLE), [T, L] = z(!0), [K, V] = z({ whisper: 0, kokoro: 0 }), [C, $] = z(null), [t, b] = z([]), [g, E] = z(null), [m, P] = z(!1), [D, G] = z(""), [ee, M] = z([]), [ae, ie] = z(null), H = W(x.IDLE), Y = W(!1), U = W(null), Z = W(null), te = W(null), X = W(null), pe = W(null), fe = W(null), ne = W([{ role: "system", content: a }]), me = W(e), ve = W(0), Se = W({ id: null, enqueuedAt: null, ttsMs: null }), De = W(1), ye = W({ provider: i, url: p });
323
+ ye.current = { provider: i, url: p }, j(() => {
324
+ ne.current = [{ role: "system", content: a }, ...ne.current.slice(1)];
325
+ }, [a]), j(() => {
326
+ H.current = N;
327
+ }, [N]), j(() => {
328
+ Y.current = m;
312
329
  }, [m]), j(() => {
313
- Z.current = $;
314
- }, [$]), j(() => {
315
- de.current = e;
330
+ me.current = e;
316
331
  }, [e]), j(() => {
317
- async function _() {
332
+ async function I() {
318
333
  try {
319
- const T = await navigator.mediaDevices.enumerateDevices();
320
- oe(T.filter((g) => g.kind === "audioinput"));
334
+ const O = await navigator.mediaDevices.enumerateDevices();
335
+ M(O.filter((y) => y.kind === "audioinput"));
321
336
  } catch {
322
337
  }
323
338
  }
324
- return _(), navigator.mediaDevices.addEventListener("devicechange", _), () => navigator.mediaDevices.removeEventListener("devicechange", _);
325
- }, [$]), j(() => {
326
- let _ = !1;
327
- async function T() {
339
+ return I(), navigator.mediaDevices.addEventListener("devicechange", I), () => navigator.mediaDevices.removeEventListener("devicechange", I);
340
+ }, [m]), j(() => {
341
+ let I = !1;
342
+ L(!0), V({ whisper: 0, kokoro: 0 });
343
+ async function O() {
328
344
  try {
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());
345
+ const y = () => {
346
+ var R;
347
+ const v = Se.current;
348
+ v.enqueuedAt != null && v.ttsMs == null && (v.ttsMs = Math.round(performance.now() - v.enqueuedAt), v.id != null && Re(v.id, { timings: { ttsMs: v.ttsMs } })), r === "webspeech" && ((R = Z.current) == null || R.pause());
333
349
  };
334
- if (s === "webspeech")
335
- K.current = Pe({
336
- voice: a,
337
- rate: n,
350
+ if (r === "webspeech")
351
+ U.current = Ye({
352
+ voice: c,
353
+ rate: s,
338
354
  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 }
355
+ onPlayStart: y
356
+ }), V((v) => ({ ...v, kokoro: 1 }));
357
+ else if (r === "kokoro") {
358
+ const { kokoro: v } = await Ge(
359
+ (R, J) => V((F) => ({ ...F, [R]: J })),
360
+ { dtype: h, device: w, modelProxyUrl: A }
345
361
  );
346
- if (_) return;
347
- K.current = Ve(h, { voice: a, speed: t, onPlayStart: g });
362
+ if (I) return;
363
+ U.current = Fe(v, { voice: c, speed: n, onPlayStart: y });
348
364
  } else
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(
365
+ U.current = He({ voice: c, speed: n, onPlayStart: y, url: o }), V((v) => ({ ...v, kokoro: 1 }));
366
+ if (I) return;
367
+ if (i === "server") {
368
+ X.current = null, V((v) => ({ ...v, whisper: 1 })), L(!1);
369
+ return;
370
+ }
371
+ X.current = new Worker(
352
372
  new URL(
353
373
  /* @vite-ignore */
354
- "./assets/whisperWorker-BJuP9cl9.js",
374
+ "./assets/whisperWorker-D69IwlqW.js",
355
375
  import.meta.url
356
376
  ),
357
377
  { type: "module" }
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({
378
+ ), X.current.onmessage = (v) => {
379
+ v.data.type === "transcript" ? ge(v.data.text, {
380
+ transcribeMs: Math.round(performance.now() - ve.current)
381
+ }) : v.data.type === "progress" ? V((R) => ({ ...R, whisper: v.data.progress })) : v.data.type === "ready" ? (V((R) => ({ ...R, whisper: 1 })), L(!1)) : v.data.type === "error" && ($(`Whisper: ${v.data.message}`), L(!1));
382
+ }, X.current.onerror = () => {
383
+ $("Model load failed. Check WebGPU/WASM browser support."), L(!1);
384
+ }, X.current.postMessage({
365
385
  type: "init",
366
- model: o,
367
- dtype: f,
368
- device: c,
369
- modelProxyUrl: u
386
+ model: d,
387
+ dtype: k,
388
+ device: f,
389
+ modelProxyUrl: A
370
390
  });
371
- } catch (g) {
372
- _ || (A("Initialisation failed: " + ((g == null ? void 0 : g.message) ?? String(g))), x(!1));
391
+ } catch (y) {
392
+ I || ($("Initialisation failed: " + ((y == null ? void 0 : y.message) ?? String(y))), L(!1));
373
393
  }
374
394
  }
375
- return T(), () => {
376
- var g;
377
- _ = !0, (g = H.current) == null || g.terminate();
395
+ return O(), () => {
396
+ var y, v;
397
+ I = !0, (y = X.current) == null || y.terminate(), (v = U.current) == null || v.cancel();
378
398
  };
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;
399
+ }, [
400
+ r,
401
+ c,
402
+ n,
403
+ s,
404
+ l,
405
+ o,
406
+ i,
407
+ p,
408
+ d,
409
+ k,
410
+ f,
411
+ h,
412
+ w
413
+ ]);
414
+ function Ie(I, O, y) {
415
+ const v = De.current++;
416
+ return b((R) => [...R, { id: v, role: I, content: O, timings: y, time: (/* @__PURE__ */ new Date()).toISOString() }]), v;
417
+ }
418
+ function Re(I, { timings: O }) {
419
+ b((y) => y.map((v) => v.id === I ? { ...v, timings: { ...v.timings, ...O } } : v));
383
420
  }
384
- function ze(_, { timings: T }) {
385
- D((g) => g.map((h) => h.id === _ ? { ...h, timings: { ...h.timings, ...T } } : h));
421
+ async function We(I) {
422
+ const O = ve.current;
423
+ try {
424
+ const y = await fetch(ye.current.url, {
425
+ method: "POST",
426
+ headers: { "Content-Type": "audio/wav" },
427
+ body: Qe(I, 16e3)
428
+ });
429
+ if (!y.ok) throw new Error(`Speech-to-text failed: ${y.status} ${await y.text()}`);
430
+ const { text: v } = await y.json();
431
+ await ge(v, { transcribeMs: Math.round(performance.now() - O) });
432
+ } catch (y) {
433
+ $(y.message || "Speech-to-text failed."), S(Y.current ? x.LISTENING : x.IDLE);
434
+ }
386
435
  }
387
- async function be(_, { transcribeMs: T } = {}) {
388
- if (!(_ != null && _.trim())) {
389
- w(Z.current ? z.LISTENING : z.IDLE);
436
+ async function ge(I, { transcribeMs: O } = {}) {
437
+ if (!(I != null && I.trim())) {
438
+ S(Y.current ? x.LISTENING : x.IDLE);
390
439
  return;
391
440
  }
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);
441
+ S(x.THINKING), Ie("user", I, O != null ? { transcribeMs: O } : void 0);
442
+ const y = [...ne.current, { role: "user", content: I }];
443
+ ne.current = y, await Ce(I, y);
395
444
  }
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();
445
+ async function Ce(I, O) {
446
+ var y, v, R, J;
447
+ (y = te.current) == null || y.abort(), te.current = new AbortController(), (v = U.current) == null || v.cancel();
399
448
  try {
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);
449
+ if (!me.current) throw new Error("processInput is not provided");
450
+ const F = Pe();
451
+ let ce = "", we = !1, be = null;
452
+ const qe = performance.now(), se = { id: null, enqueuedAt: null, ttsMs: null };
453
+ Se.current = se;
454
+ const Me = (le) => {
455
+ var ke;
456
+ se.enqueuedAt == null && (se.enqueuedAt = performance.now()), (ke = U.current) == null || ke.enqueue(le);
408
457
  };
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);
458
+ E("");
459
+ for await (const le of me.current(I, O, te.current.signal))
460
+ be == null && (be = Math.round(performance.now() - qe)), ce += le, E(ce), F.write(le).forEach((je) => {
461
+ we || (we = !0, S(x.SPEAKING)), Me(je);
413
462
  });
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());
463
+ const Le = F.flush();
464
+ Le && (we || S(x.SPEAKING), Me(Le)), se.id = Ie("assistant", ce, {
465
+ thinkMs: be,
466
+ ...se.ttsMs != null ? { ttsMs: se.ttsMs } : {}
467
+ }), E(null), ne.current = [...ne.current, { role: "assistant", content: ce }], await ((R = U.current) == null ? void 0 : R.finished()), r === "webspeech" && ((J = Z.current) == null || J.start());
419
468
  } catch (F) {
420
- V(null), F.name !== "AbortError" && A(F.message || "Processing failed.");
469
+ E(null), F.name !== "AbortError" && $(F.message || "Processing failed.");
421
470
  } finally {
422
- w(Z.current ? z.LISTENING : z.IDLE);
471
+ S(Y.current ? x.LISTENING : x.IDLE);
423
472
  }
424
473
  }
425
- async function Le() {
426
- var _, T;
427
- A(null), J.current === z.SPEAKING && ((_ = K.current) == null || _.cancel(), (T = B.current) == null || T.abort());
474
+ async function Ve() {
475
+ var I, O;
476
+ $(null), H.current === x.SPEAKING && ((I = U.current) == null || I.cancel(), (O = te.current) == null || O.abort());
428
477
  try {
429
- w(z.LISTENING), C(!0);
478
+ S(x.LISTENING), P(!0);
430
479
  try {
431
- const g = await navigator.mediaDevices.getUserMedia({
432
- audio: M ? { deviceId: { exact: M } } : !0,
480
+ const y = await navigator.mediaDevices.getUserMedia({
481
+ audio: D ? { deviceId: { exact: D } } : !0,
433
482
  video: !1
434
483
  });
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);
484
+ fe.current = y;
485
+ const v = new AudioContext();
486
+ pe.current = v;
487
+ const R = v.createAnalyser();
488
+ R.fftSize = 256, v.createMediaStreamSource(y).connect(R), ie(R);
489
+ } catch (y) {
490
+ console.warn("[TZVoiceChat] waveform analyser unavailable:", y);
442
491
  }
443
- U.current = await Ke({
492
+ Z.current = await Je({
444
493
  onSpeechStart: () => {
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));
494
+ var y, v;
495
+ r === "webspeech" && H.current === x.SPEAKING || (H.current === x.SPEAKING && ((y = U.current) == null || y.cancel(), (v = te.current) == null || v.abort()), S(x.LISTENING));
447
496
  },
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]));
497
+ onSpeechEnd: (y) => {
498
+ var v;
499
+ r === "webspeech" && H.current === x.SPEAKING || (S(x.TRANSCRIBING), ve.current = performance.now(), ye.current.provider === "server" ? We(y) : (v = X.current) == null || v.postMessage({ type: "transcribe", audio: y }, [y.buffer]));
451
500
  },
452
- onError: (g) => {
453
- A(g), w(z.IDLE);
501
+ onError: (y) => {
502
+ $(y), S(x.IDLE);
454
503
  },
455
- deviceId: M || void 0
504
+ deviceId: D || void 0
456
505
  });
457
- } catch (g) {
458
- console.error("[TZVoiceChat] startListening failed:", g), A("Microphone access failed. Allow audio permissions and refresh."), w(z.IDLE), C(!1);
506
+ } catch (y) {
507
+ console.error("[TZVoiceChat] startListening failed:", y), $("Microphone access failed. Allow audio permissions and refresh."), S(x.IDLE), P(!1);
459
508
  }
460
509
  }
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);
510
+ function Ke() {
511
+ var I, O, y, v, R;
512
+ P(!1), (I = Z.current) == null || I.destroy(), Z.current = null, (O = fe.current) == null || O.getTracks().forEach((J) => J.stop()), fe.current = null, (y = pe.current) == null || y.close(), pe.current = null, ie(null), (v = U.current) == null || v.cancel(), (R = te.current) == null || R.abort(), S(x.IDLE);
464
513
  }
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) => {
514
+ function Ue(I) {
515
+ var R;
516
+ if (!(I != null && I.trim())) return;
517
+ S(x.SPEAKING);
518
+ const O = Pe(), y = O.write(I), v = O.flush();
519
+ [...y, ...v ? [v] : []].forEach((J) => {
471
520
  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);
521
+ return (F = U.current) == null ? void 0 : F.enqueue(J);
522
+ }), (R = U.current) == null || R.finished().then(() => {
523
+ S(Y.current ? x.LISTENING : x.IDLE);
475
524
  });
476
525
  }
477
526
  return {
478
527
  /** Current pipeline state: 'idle' | 'listening' | 'transcribing' | 'thinking' | 'speaking' */
479
- status: m,
528
+ status: N,
480
529
  /** True while models (Whisper + TTS) are still loading. */
481
- loading: I,
530
+ loading: T,
482
531
  /** Per-model load progress: { whisper: 0–1, kokoro: 0–1 } */
483
- progress: L,
532
+ progress: K,
484
533
  /** Last error string, or null. Cleared on startListening(). */
485
- error: E,
534
+ error: C,
486
535
  /** 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,
536
+ transcript: t,
488
537
  /** Partial assistant response being streamed, or null. */
489
- streamingMessage: k,
538
+ streamingMessage: g,
490
539
  /** Whether the microphone is currently open. */
491
- micEnabled: $,
540
+ micEnabled: m,
492
541
  /** Open the microphone and start the VAD → STT → AI → TTS pipeline. */
493
- startListening: Le,
542
+ startListening: Ve,
494
543
  /** Close the microphone and cancel any in-progress pipeline. */
495
- stopListening: $e,
544
+ stopListening: Ke,
496
545
  /** Directly synthesise and play text via the configured TTS provider. */
497
- speak: xe,
546
+ speak: Ue,
498
547
  /** Submit text as a user message, triggering the full AI → TTS pipeline (same as voice transcription). */
499
- submitText: be,
548
+ submitText: ge,
500
549
  /** AnalyserNode for real-time waveform rendering, or null when mic is off. */
501
- liveAnalyser: ce,
550
+ liveAnalyser: ae,
502
551
  /** Available audio input devices (updated on permission grant). */
503
- devices: W,
552
+ devices: ee,
504
553
  /** Currently selected device ID ('': system default). */
505
- selectedMicId: M,
554
+ selectedMicId: D,
506
555
  /** Select an audio input device by its deviceId. */
507
- setSelectedMicId: y
556
+ setSelectedMicId: G
508
557
  };
509
558
  }
510
- function Ne(e) {
511
- const r = e.replace("#", ""), s = r.length === 3 ? r.split("").map((a) => a + a).join("") : r;
559
+ function Oe(e) {
560
+ const a = e.replace("#", ""), r = a.length === 3 ? a.split("").map((c) => c + c).join("") : a;
512
561
  return [
513
- parseInt(s.slice(0, 2), 16),
514
- parseInt(s.slice(2, 4), 16),
515
- parseInt(s.slice(4, 6), 16)
562
+ parseInt(r.slice(0, 2), 16),
563
+ parseInt(r.slice(2, 4), 16),
564
+ parseInt(r.slice(4, 6), 16)
516
565
  ];
517
566
  }
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) {
567
+ function et(e, a, r) {
568
+ e /= 255, a /= 255, r /= 255;
569
+ const c = Math.max(e, a, r), n = Math.min(e, a, r), o = (c + n) / 2;
570
+ if (c === n) return [0, 0, o * 100];
571
+ const s = c - n, l = o > 0.5 ? s / (2 - c - n) : s / (c + n);
572
+ let i;
573
+ switch (c) {
525
574
  case e:
526
- o = ((r - s) / n + (r < s ? 6 : 0)) / 6;
575
+ i = ((a - r) / s + (a < r ? 6 : 0)) / 6;
527
576
  break;
528
- case r:
529
- o = ((s - e) / n + 2) / 6;
577
+ case a:
578
+ i = ((r - e) / s + 2) / 6;
530
579
  break;
531
580
  default:
532
- o = ((e - r) / n + 4) / 6;
581
+ i = ((e - a) / s + 4) / 6;
533
582
  }
534
- return [o * 360, l * 100, i * 100];
583
+ return [i * 360, l * 100, o * 100];
535
584
  }
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)];
585
+ function tt(e, a, r) {
586
+ a /= 100, r /= 100;
587
+ const c = (s) => (s + e / 30) % 12, n = a * Math.min(r, 1 - r), o = (s) => r - n * Math.max(-1, Math.min(c(s) - 3, Math.min(9 - c(s), 1)));
588
+ return [Math.round(o(0) * 255), Math.round(o(8) * 255), Math.round(o(4) * 255)];
540
589
  }
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})`;
590
+ function B(e, a) {
591
+ const [r, c, n] = Oe(e), [o, s, l] = et(r, c, n), [i, p, d] = tt(o, s, Math.max(0, Math.min(100, l + a)));
592
+ return `rgb(${i}, ${p}, ${d})`;
544
593
  }
545
- function O(e, r) {
546
- const [s, a, t] = Ne(e);
547
- return `rgba(${s}, ${a}, ${t}, ${r})`;
594
+ function q(e, a) {
595
+ const [r, c, n] = Oe(e);
596
+ return `rgba(${r}, ${c}, ${n}, ${a})`;
548
597
  }
549
- function X(e, r) {
550
- return e.replace("rgb(", "rgba(").replace(")", `, ${r})`);
598
+ function oe(e, a) {
599
+ return e.replace("rgb(", "rgba(").replace(")", `, ${a})`);
551
600
  }
552
- const ae = 10;
553
- function Fe({ analyser: e }) {
554
- const r = R(null), s = R(null);
601
+ const de = 10;
602
+ function nt({ analyser: e }) {
603
+ const a = W(null), r = W(null);
555
604
  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();
605
+ if (cancelAnimationFrame(r.current), !e) return;
606
+ const c = a.current;
607
+ if (!c) return;
608
+ const n = c.getContext("2d"), o = e.frequencyBinCount, s = new Uint8Array(o), l = Math.max(1, Math.floor(o / de)), i = getComputedStyle(c), p = +i.getPropertyValue("--bar-hue"), d = +i.getPropertyValue("--bar-hue-range"), k = +i.getPropertyValue("--bar-sat"), f = +i.getPropertyValue("--bar-lit"), h = +i.getPropertyValue("--bar-lit-range"), w = () => {
609
+ r.current = requestAnimationFrame(w), e.getByteFrequencyData(s);
610
+ const A = c.width, N = c.height;
611
+ n.clearRect(0, 0, A, N);
612
+ const S = (A - (de - 1) * 2) / de;
613
+ for (let T = 0; T < de; T++) {
614
+ const L = s[T * l] / 255, K = Math.max(3, L * N * 0.88);
615
+ n.fillStyle = `hsl(${p + L * d}, ${k}%, ${f + L * h}%)`, n.beginPath(), n.roundRect(T * (S + 2), (N - K) / 2, S, K, [2]), n.fill();
567
616
  }
568
617
  };
569
- return m(), () => cancelAnimationFrame(s.current);
570
- }, [e]), /* @__PURE__ */ p("canvas", { ref: r, width: 55, height: 35, className: "ai-btn__canvas" });
618
+ return w(), () => cancelAnimationFrame(r.current);
619
+ }, [e]), /* @__PURE__ */ u("canvas", { ref: a, width: 55, height: 35, className: "ai-btn__canvas" });
571
620
  }
572
- function We({
621
+ function st({
573
622
  status: e = "idle",
574
- active: r = !1,
575
- loading: s = !1,
576
- analyser: a = null,
577
- onToggle: t,
578
- devices: i = [],
579
- selectedMicId: n = "",
623
+ active: a = !1,
624
+ loading: r = !1,
625
+ analyser: c = null,
626
+ onToggle: n,
627
+ devices: o = [],
628
+ selectedMicId: s = "",
580
629
  onDeviceChange: l,
581
630
  // ── Manual input ───────────────────────────────────────────
582
- inputData: o = "",
583
- sendData: f,
631
+ inputData: i = "",
632
+ sendData: p,
584
633
  // ── Theming ────────────────────────────────────────────────
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
634
+ accentColor: d = "#f97316",
635
+ uiColor: k = "#64748b",
636
+ size: f = 70,
637
+ barHue: h = 25,
638
+ barHueRange: w = 20,
639
+ barSat: A = 88,
640
+ barLit: N = 65,
641
+ barLitRange: S = 20
593
642
  }) {
594
- var C;
595
- const [L, b] = q(!1), E = R(null);
643
+ var E;
644
+ const [T, L] = z(!1), K = W(null);
596
645
  j(() => {
597
- if (!L) return;
598
- function M(y) {
599
- var W;
600
- (W = E.current) != null && W.contains(y.target) || b(!1);
646
+ if (!T) return;
647
+ function m(P) {
648
+ var D;
649
+ (D = K.current) != null && D.contains(P.target) || L(!1);
601
650
  }
602
- return document.addEventListener("pointerdown", M), () => document.removeEventListener("pointerdown", M);
603
- }, [L]);
604
- function A(M) {
605
- l == null || l(M), b(!1);
651
+ return document.addEventListener("pointerdown", m), () => document.removeEventListener("pointerdown", m);
652
+ }, [T]);
653
+ function V(m) {
654
+ l == null || l(m), L(!1);
606
655
  }
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);
656
+ const C = Be(() => {
657
+ const m = B(d, -8), P = B(d, -15), D = B(d, -22), G = B(d, -30), ee = B(d, -42), M = B(d, 8), ae = B(d, 20), ie = B(d, 30), H = B(k, -22), Y = B(k, -30), U = B(k, 18), Z = B(k, 37);
609
658
  return {
610
- "--tz-size": `${d}px`,
659
+ "--tz-size": `${f}px`,
611
660
  // Accent shades
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,
661
+ "--tz-a": d,
662
+ "--tz-a-d8": m,
663
+ "--tz-a-d15": P,
664
+ "--tz-a-d22": D,
665
+ "--tz-a-d30": G,
666
+ "--tz-a-d42": ee,
667
+ "--tz-a-l8": M,
668
+ "--tz-a-l20": ae,
669
+ "--tz-a-l30": ie,
621
670
  // Accent + alpha
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),
671
+ "--tz-a-25": q(d, 0.25),
672
+ "--tz-a-28": q(d, 0.28),
673
+ "--tz-a-30": q(d, 0.3),
674
+ "--tz-a-32": q(d, 0.32),
675
+ "--tz-a-34": q(d, 0.34),
676
+ "--tz-a-35": q(d, 0.35),
677
+ "--tz-a-38": q(d, 0.38),
678
+ "--tz-a-45": q(d, 0.45),
679
+ "--tz-a-50": q(d, 0.5),
680
+ "--tz-a-55": q(d, 0.55),
681
+ "--tz-a-60": q(d, 0.6),
682
+ "--tz-a-65": q(d, 0.65),
683
+ "--tz-a-68": q(d, 0.68),
635
684
  // UI shades
636
- "--tz-u": v,
637
- "--tz-u-d22": K,
638
- "--tz-u-d30": U,
639
- "--tz-u-l18": B,
640
- "--tz-u-l37": H,
685
+ "--tz-u": k,
686
+ "--tz-u-d22": H,
687
+ "--tz-u-d30": Y,
688
+ "--tz-u-l18": U,
689
+ "--tz-u-l37": Z,
641
690
  // UI + alpha
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),
691
+ "--tz-u-30": q(k, 0.3),
692
+ "--tz-u-55": q(k, 0.55),
693
+ "--tz-u-d30-a85": oe(Y, 0.85),
694
+ "--tz-u-l18-a18": oe(U, 0.18),
695
+ "--tz-u-l18-a20": oe(U, 0.2),
696
+ "--tz-u-l18-a32": oe(U, 0.32),
697
+ "--tz-u-d22-a90": oe(H, 0.9),
649
698
  // Waveform bar colors (cascade to canvas via getComputedStyle)
650
- "--bar-hue": u,
651
- "--bar-hue-range": m,
652
- "--bar-sat": w,
653
- "--bar-lit": I,
654
- "--bar-lit-range": x
699
+ "--bar-hue": h,
700
+ "--bar-hue-range": w,
701
+ "--bar-sat": A,
702
+ "--bar-lit": N,
703
+ "--bar-lit-range": S
655
704
  };
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" })
705
+ }, [d, k, f, h, w, A, N, S]), $ = ((E = o.find((m) => m.deviceId === s)) == null ? void 0 : E.label) || (s ? `Mic ${s.slice(0, 6)}…` : "Default mic"), t = i.trim().length > 0, b = t ? "ready" : a ? e : "off";
706
+ let g;
707
+ return t ? g = /* @__PURE__ */ u("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ u("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) }) : !a || e === "idle" ? g = /* @__PURE__ */ _("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
708
+ /* @__PURE__ */ u("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" }),
709
+ /* @__PURE__ */ u("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" }),
710
+ /* @__PURE__ */ u("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" })
711
+ ] }) : e === "listening" ? g = /* @__PURE__ */ u(nt, { analyser: c }) : e === "transcribing" ? g = /* @__PURE__ */ u("div", { className: "ai-btn__bars ai-btn__bars--transcribing", children: Array.from({ length: 7 }, (m, P) => /* @__PURE__ */ u("span", { style: { animationDelay: `${P * 0.1}s` } }, P)) }) : e === "thinking" ? g = /* @__PURE__ */ _("div", { className: "ai-btn__dots", children: [
712
+ /* @__PURE__ */ u("span", {}),
713
+ /* @__PURE__ */ u("span", { style: { animationDelay: "0.18s" } }),
714
+ /* @__PURE__ */ u("span", { style: { animationDelay: "0.36s" } })
715
+ ] }) : e === "speaking" && (g = /* @__PURE__ */ u("div", { className: "ai-btn__bars ai-btn__bars--speaking", children: Array.from({ length: 7 }, (m, P) => /* @__PURE__ */ u("span", { style: { animationDelay: `${P * 0.11}s` } }, P)) })), /* @__PURE__ */ _("div", { className: "ai-btn-root", style: C, children: [
716
+ /* @__PURE__ */ _("div", { className: `ai-btn-rings ai-btn-rings--${b}`, "aria-hidden": "true", children: [
717
+ /* @__PURE__ */ u("span", { className: "ai-ring ai-ring--1" }),
718
+ /* @__PURE__ */ u("span", { className: "ai-ring ai-ring--2" })
670
719
  ] }),
671
- /* @__PURE__ */ S(
720
+ /* @__PURE__ */ _(
672
721
  "button",
673
722
  {
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,
723
+ className: `ai-btn ai-btn--${b}`,
724
+ disabled: r,
725
+ onClick: t ? () => p == null ? void 0 : p(i) : n,
726
+ "aria-label": t ? "Send message" : a ? "Stop assistant" : "Start assistant",
727
+ "aria-pressed": t ? void 0 : a,
679
728
  children: [
680
- $,
681
- r && !k && /* @__PURE__ */ p("span", { className: "ai-btn__hover-stop", "aria-hidden": "true", children: "■" })
729
+ g,
730
+ a && !t && /* @__PURE__ */ u("span", { className: "ai-btn__hover-stop", "aria-hidden": "true", children: "■" })
682
731
  ]
683
732
  }
684
733
  ),
685
- /* @__PURE__ */ S("div", { className: `ai-mic-sel${L ? " open" : ""}`, ref: E, children: [
686
- /* @__PURE__ */ S(
734
+ /* @__PURE__ */ _("div", { className: `ai-mic-sel${T ? " open" : ""}`, ref: K, children: [
735
+ /* @__PURE__ */ _(
687
736
  "button",
688
737
  {
689
738
  className: "ai-mic-sel__trigger",
690
- onClick: () => b((M) => !M),
739
+ onClick: () => L((m) => !m),
691
740
  title: "Change microphone",
692
741
  "aria-label": "Change microphone",
693
- "aria-expanded": L,
742
+ "aria-expanded": T,
694
743
  children: [
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" })
744
+ /* @__PURE__ */ _("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
745
+ /* @__PURE__ */ u("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z" }),
746
+ /* @__PURE__ */ u("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" })
698
747
  ] }),
699
- /* @__PURE__ */ p("span", { className: "ai-mic-sel__label", children: D }),
700
- /* @__PURE__ */ p(
748
+ /* @__PURE__ */ u("span", { className: "ai-mic-sel__label", children: $ }),
749
+ /* @__PURE__ */ u(
701
750
  "svg",
702
751
  {
703
- className: `ai-mic-sel__caret${L ? " open" : ""}`,
752
+ className: `ai-mic-sel__caret${T ? " open" : ""}`,
704
753
  width: "9",
705
754
  height: "9",
706
755
  viewBox: "0 0 24 24",
707
756
  fill: "currentColor",
708
757
  "aria-hidden": "true",
709
- children: /* @__PURE__ */ p("path", { d: "M12 16L4 8h16l-8 8z" })
758
+ children: /* @__PURE__ */ u("path", { d: "M12 16L4 8h16l-8 8z" })
710
759
  }
711
760
  )
712
761
  ]
713
762
  }
714
763
  ),
715
- L && /* @__PURE__ */ S("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
716
- /* @__PURE__ */ p(
764
+ T && /* @__PURE__ */ _("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
765
+ /* @__PURE__ */ u(
717
766
  "li",
718
767
  {
719
768
  role: "option",
720
- className: `ai-mic-sel__option${n === "" ? " selected" : ""}`,
721
- onClick: () => A(""),
722
- "aria-selected": n === "",
769
+ className: `ai-mic-sel__option${s === "" ? " selected" : ""}`,
770
+ onClick: () => V(""),
771
+ "aria-selected": s === "",
723
772
  children: "Default microphone"
724
773
  }
725
774
  ),
726
- i.map((M) => /* @__PURE__ */ p(
775
+ o.map((m) => /* @__PURE__ */ u(
727
776
  "li",
728
777
  {
729
778
  role: "option",
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)}`
779
+ className: `ai-mic-sel__option${s === m.deviceId ? " selected" : ""}`,
780
+ onClick: () => V(m.deviceId),
781
+ "aria-selected": s === m.deviceId,
782
+ children: m.label || `Microphone ${m.deviceId.slice(0, 8)}`
734
783
  },
735
- M.deviceId
784
+ m.deviceId
736
785
  ))
737
786
  ] })
738
787
  ] })
739
788
  ] });
740
789
  }
741
- async function Ue(e, r, s = "/api/chat") {
790
+ async function rt(e, a, r = "/api/chat") {
742
791
  var l;
743
- const a = await fetch(s, {
792
+ const c = await fetch(r, {
744
793
  method: "POST",
745
794
  headers: {
746
795
  "Content-Type": "application/json"
747
796
  },
748
- signal: r,
797
+ signal: a,
749
798
  body: JSON.stringify({ messages: e })
750
799
  });
751
- if (!a.ok) {
752
- const o = await a.text();
753
- throw new Error(`Server error: ${a.status} ${o}`);
800
+ if (!c.ok) {
801
+ const i = await c.text();
802
+ throw new Error(`Server error: ${c.status} ${i}`);
754
803
  }
755
- const t = (l = a.body) == null ? void 0 : l.getReader();
756
- if (!t) {
757
- const o = await a.json();
804
+ const n = (l = c.body) == null ? void 0 : l.getReader();
805
+ if (!n) {
806
+ const i = await c.json();
758
807
  return { stream: async function* () {
759
- yield o.text;
808
+ yield i.text;
760
809
  } };
761
810
  }
762
- const i = new TextDecoder();
763
- let n = "";
811
+ const o = new TextDecoder();
812
+ let s = "";
764
813
  return {
765
814
  stream: async function* () {
766
- var f, c, v;
767
- let o = "";
815
+ var p, d, k;
816
+ let i = "";
768
817
  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(`
818
+ const { value: f, done: h } = await n.read();
819
+ if (h) break;
820
+ s += o.decode(f, { stream: !0 });
821
+ const w = s.split(`
773
822
  `);
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;
823
+ s = w.pop();
824
+ for (const A of w) {
825
+ const N = A.trim();
826
+ if (!N.startsWith("data:")) continue;
827
+ const S = N.slice(5).trimStart();
828
+ if (S === "[DONE]") return;
780
829
  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);
830
+ const L = (k = (d = (p = JSON.parse(S).choices) == null ? void 0 : p[0]) == null ? void 0 : d.delta) == null ? void 0 : k.content;
831
+ L && (i && /\w/.test(i) && /\w/.test(L[0]) && (yield " "), i = L[L.length - 1], yield L);
783
832
  } catch {
784
833
  }
785
834
  }
@@ -787,272 +836,852 @@ async function Ue(e, r, s = "/api/chat") {
787
836
  }
788
837
  };
789
838
  }
790
- function He(e, r, s) {
839
+ function at(e, a, r) {
791
840
  return {
792
841
  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;
842
+ const c = [];
843
+ let n = null, o = !1, s = "";
844
+ const l = ({ data: p }) => {
845
+ p.type === "token" ? (c.push(p.text), n == null || n(), n = null) : p.type === "done" && (o = !0, n == null || n(), n = null);
846
+ }, i = () => {
847
+ o = !0, n == null || n(), n = null;
799
848
  };
800
- e.addEventListener("message", l), s == null || s.addEventListener("abort", o), e.postMessage({ type: "generate", messages: r });
849
+ e.addEventListener("message", l), r == null || r.addEventListener("abort", i), e.postMessage({ type: "generate", messages: a });
801
850
  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;
851
+ for (; !o || c.length > 0; )
852
+ if (c.length > 0) {
853
+ const p = c.shift();
854
+ s && /\w/.test(s) && /\w/.test(p[0]) && (yield " "), s = p[p.length - 1], yield p;
806
855
  } else
807
- await new Promise((f) => {
808
- t = f;
856
+ await new Promise((p) => {
857
+ n = p;
809
858
  });
810
859
  } finally {
811
- e.removeEventListener("message", l), s == null || s.removeEventListener("abort", o);
860
+ e.removeEventListener("message", l), r == null || r.removeEventListener("abort", i);
812
861
  }
813
862
  }
814
863
  };
815
864
  }
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);
865
+ function ot({ apiBase: e = "/api", systemPrompt: a } = {}) {
866
+ const [r, c] = z(!0), [n, o] = z(0), [s, l] = z(""), [i, p] = z({}), [d, k] = z(null), [f, h] = z({}), [w, A] = z(0), N = W(null), S = W(null), T = Ne(() => A((C) => C + 1), []);
818
867
  j(() => {
819
- let b = !1;
820
- async function E() {
821
- let A = !0, P = {};
868
+ let C = !1;
869
+ l(""), o(0);
870
+ async function $() {
871
+ let t = null, b = {};
822
872
  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",
873
+ t = await (await fetch(`${e}/config`)).json(), k(t), b = {
874
+ ttsProvider: t.ttsProvider || "kokoro",
875
+ ttsVoice: t.ttsProvider === "openai" ? t.openaiTtsVoice || "alloy" : t.ttsProvider === "elevenlabs" ? t.elevenlabsVoiceId : t.ttsProvider === "webspeech" ? t.webSpeechVoice || "" : t.kokoroVoice || "af_bella",
876
+ ttsSpeed: t.kokoroSpeed ?? 1,
827
877
  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/`
878
+ ttsSpeechRate: t.webSpeechRate ?? 1,
879
+ ttsSpeechPitch: t.webSpeechPitch ?? 1,
880
+ sttProvider: t.sttProvider === "elevenlabs" || t.sttProvider === "openai" ? "server" : "whisper",
881
+ sttServerUrl: `${e}/stt`,
882
+ whisperModel: t.whisperModel || "onnx-community/whisper-tiny.en",
883
+ whisperDtype: t.whisperDtype || "q8",
884
+ whisperDevice: t.whisperDevice || "wasm",
885
+ kokoroDtype: t.kokoroDtype || "q8",
886
+ kokoroBrowserDevice: t.kokoroBrowserDevice || "wasm",
887
+ modelProxyUrl: `${e}/models/`,
888
+ ...t.systemPrompt ? { systemPrompt: t.systemPrompt } : {}
837
889
  };
838
890
  } catch {
839
- P = { ttsProvider: "server-kokoro", ttsServerUrl: `${e}/tts`, modelProxyUrl: `${e}/models/` };
891
+ b = { ttsProvider: "kokoro", ttsServerUrl: `${e}/tts`, modelProxyUrl: `${e}/models/` };
840
892
  }
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(
893
+ if (!C) {
894
+ if ((t == null ? void 0 : t.chatProvider) === "local") {
895
+ c(!0), l("Using SmolLM2-360M-Instruct locally in your browser — slow and simple; pick a cloud model in Settings for better answers.");
896
+ const g = new Worker(new URL(
850
897
  /* @vite-ignore */
851
898
  "./assets/llmWorker-CVEGn6yI.js",
852
899
  import.meta.url
853
900
  ), { 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/` });
901
+ S.current = g, g.onmessage = (E) => {
902
+ E.data.type === "progress" ? o(E.data.progress ?? 0) : E.data.type === "ready" ? (o(1), N.current = async function* (m, P, D) {
903
+ const { stream: G } = at(g, P, D);
904
+ yield* G();
905
+ }, p(b), c(!1)) : E.data.type === "error" && c(!1);
906
+ }, g.onerror = () => c(!1), p(b), g.postMessage({ type: "init", modelProxyUrl: `${e}/models/` });
907
+ return;
860
908
  }
909
+ t != null && t.hasApiKey ? N.current = async function* (g, E, m) {
910
+ const { stream: P } = await rt(E, m, `${e}/chat`);
911
+ yield* P();
912
+ } : N.current = async function* () {
913
+ throw new Error("The chat model is not configured yet — open Settings and choose a provider.");
914
+ }, p(b), c(!1);
915
+ }
861
916
  }
862
- return E(), () => {
863
- var A;
864
- b = !0, (A = w.current) == null || A.terminate();
917
+ return $(), () => {
918
+ var t;
919
+ C = !0, (t = S.current) == null || t.terminate(), S.current = null;
865
920
  };
866
- }, [e]);
867
- const I = Ce({
868
- processInput: async function* (b, E, A) {
869
- m.current && (yield* m.current(b, E, A));
921
+ }, [e, w]);
922
+ const L = Xe({
923
+ processInput: async function* (C, $, t) {
924
+ N.current && (yield* N.current(C, $, t));
870
925
  },
871
- ...r ? { systemPrompt: r } : {},
872
- ...o
926
+ ...a ? { systemPrompt: a } : {},
927
+ ...i
873
928
  });
874
929
  j(() => {
875
- let b = !1;
876
- async function E() {
877
- const P = {};
878
- typeof performance < "u" && performance.memory && (P.browser = performance.memory.usedJSHeapSize);
930
+ let C = !1;
931
+ async function $() {
932
+ const b = {};
933
+ typeof performance < "u" && performance.memory && (b.browser = performance.memory.usedJSHeapSize);
879
934
  try {
880
- const D = await fetch(`${e}/stats`);
881
- D.ok && (P.server = (await D.json()).rss);
935
+ const g = await fetch(`${e}/stats`);
936
+ g.ok && (b.server = (await g.json()).rss);
882
937
  } catch {
883
938
  }
884
- b || u(P);
939
+ C || h(b);
885
940
  }
886
- E();
887
- const A = setInterval(E, 3e3);
941
+ $();
942
+ const t = setInterval($, 3e3);
888
943
  return () => {
889
- b = !0, clearInterval(A);
944
+ C = !0, clearInterval(t);
890
945
  };
891
946
  }, [e]);
892
- const { micEnabled: x, stopListening: L } = I;
947
+ const { micEnabled: K, stopListening: V } = L;
893
948
  return j(() => {
894
- if (!x) return;
895
- const b = (E) => {
896
- E.key === "Escape" && L();
949
+ if (!K) return;
950
+ const C = ($) => {
951
+ $.key === "Escape" && V();
897
952
  };
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
953
+ return window.addEventListener("keydown", C), () => window.removeEventListener("keydown", C);
954
+ }, [K, V]), {
955
+ chat: L,
956
+ info: d,
957
+ config: i,
958
+ memory: f,
959
+ llmProgress: n,
960
+ note: s,
961
+ loading: L.loading || r,
962
+ missing: (d == null ? void 0 : d.missing) ?? [],
963
+ reload: T
907
964
  };
908
965
  }
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) {
966
+ const it = ["q8", "q4", "q4f16", "fp16", "fp32"], re = "Local · free", Q = "Cloud", xe = [
967
+ {
968
+ group: "Chat model",
969
+ fields: [
970
+ {
971
+ key: "chatProvider",
972
+ label: "Provider",
973
+ type: "select",
974
+ env: "OPENAI_PROVIDER",
975
+ default: "local",
976
+ options: [
977
+ ["", "Not configured"],
978
+ ["local", "In-browser model (SmolLM2, no key, ~200 MB) — slow and simple", re],
979
+ ["openai-compatible", "OpenAI-compatible server (Ollama, LM Studio, vLLM, on-premise…)", re],
980
+ ["openrouter", "OpenRouter", Q],
981
+ ["openai", "OpenAI", Q],
982
+ ["anthropic", "Anthropic (Claude)", Q],
983
+ ["huggingface", "Hugging Face", Q]
984
+ ]
985
+ },
986
+ {
987
+ key: "openrouterApiKey",
988
+ label: "OpenRouter API key",
989
+ type: "password",
990
+ secret: !0,
991
+ env: "OPENROUTER_API_KEY",
992
+ showWhen: { chatProvider: "openrouter" },
993
+ hint: "Get one at https://openrouter.ai/keys"
994
+ },
995
+ {
996
+ key: "openrouterModel",
997
+ label: "OpenRouter model",
998
+ type: "text",
999
+ env: "OPENROUTER_MODEL",
1000
+ default: "gpt-4o-mini",
1001
+ showWhen: { chatProvider: "openrouter" },
1002
+ hint: 'e.g. openai/gpt-4o-mini, or a ":free" model'
1003
+ },
1004
+ {
1005
+ key: "openaiApiKey",
1006
+ label: "OpenAI API key",
1007
+ type: "password",
1008
+ secret: !0,
1009
+ env: "OPENAI_API_KEY",
1010
+ showWhenAny: [{ chatProvider: "openai" }, { sttProvider: "openai" }, { ttsProvider: "openai" }],
1011
+ hint: "Used for OpenAI chat, transcription and/or TTS. Get one at https://platform.openai.com/api-keys"
1012
+ },
1013
+ {
1014
+ key: "openaiChatModel",
1015
+ label: "OpenAI model",
1016
+ type: "text",
1017
+ env: "OPENAI_CHAT_MODEL",
1018
+ default: "gpt-4o-mini",
1019
+ showWhen: { chatProvider: "openai" },
1020
+ suggestions: ["gpt-4o-mini", "gpt-4o", "gpt-4.1-mini", "gpt-4.1"]
1021
+ },
1022
+ {
1023
+ key: "anthropicApiKey",
1024
+ label: "Anthropic API key",
1025
+ type: "password",
1026
+ secret: !0,
1027
+ env: "ANTHROPIC_API_KEY",
1028
+ showWhen: { chatProvider: "anthropic" },
1029
+ hint: "Get one at https://console.anthropic.com/settings/keys"
1030
+ },
1031
+ {
1032
+ key: "anthropicModel",
1033
+ label: "Anthropic model",
1034
+ type: "text",
1035
+ env: "ANTHROPIC_MODEL",
1036
+ default: "claude-haiku-5-5",
1037
+ showWhen: { chatProvider: "anthropic" },
1038
+ suggestions: ["claude-haiku-5-5", "claude-sonnet-5-5", "claude-opus-5-5", "claude-fable-5-2"],
1039
+ hint: "Haiku is the fastest — best for voice"
1040
+ },
1041
+ {
1042
+ key: "huggingfaceApiKey",
1043
+ label: "Hugging Face token",
1044
+ type: "password",
1045
+ secret: !0,
1046
+ env: "HUGGINGFACE_API_KEY",
1047
+ showWhen: { chatProvider: "huggingface" },
1048
+ hint: "A token with read scope"
1049
+ },
1050
+ {
1051
+ key: "compatBaseUrl",
1052
+ label: "Server base URL",
1053
+ type: "text",
1054
+ env: "OPENAI_COMPAT_BASE_URL",
1055
+ default: "http://localhost:11434/v1",
1056
+ showWhen: { chatProvider: "openai-compatible" },
1057
+ suggestions: ["http://localhost:11434/v1", "http://localhost:1234/v1", "http://localhost:8000/v1"],
1058
+ hint: "Must serve /chat/completions. Ollama :11434, LM Studio :1234, vLLM :8000. From inside Docker use host.docker.internal instead of localhost."
1059
+ },
1060
+ {
1061
+ key: "compatModel",
1062
+ label: "Model name",
1063
+ type: "text",
1064
+ env: "OPENAI_COMPAT_MODEL",
1065
+ default: "",
1066
+ showWhen: { chatProvider: "openai-compatible" },
1067
+ hint: "Exactly as the server names it, e.g. llama3.2 or qwen2.5:7b-instruct"
1068
+ },
1069
+ {
1070
+ key: "compatApiKey",
1071
+ label: "API key (optional)",
1072
+ type: "password",
1073
+ secret: !0,
1074
+ env: "OPENAI_COMPAT_API_KEY",
1075
+ showWhen: { chatProvider: "openai-compatible" },
1076
+ hint: "Leave empty if the server needs no key (most local servers)."
1077
+ },
1078
+ {
1079
+ key: "systemPrompt",
1080
+ label: "System prompt",
1081
+ type: "textarea",
1082
+ default: "",
1083
+ hint: "Leave blank for the built-in short, spoken-style prompt."
1084
+ }
1085
+ ]
1086
+ },
1087
+ {
1088
+ group: "Speech-to-text",
1089
+ fields: [
1090
+ {
1091
+ key: "sttProvider",
1092
+ label: "Provider",
1093
+ type: "select",
1094
+ env: "STT_PROVIDER",
1095
+ default: "whisper",
1096
+ options: [
1097
+ ["whisper", "Whisper in the browser", re],
1098
+ ["openai", "OpenAI transcription", Q],
1099
+ ["elevenlabs", "ElevenLabs Scribe", Q]
1100
+ ]
1101
+ },
1102
+ {
1103
+ key: "openaiSttModel",
1104
+ label: "OpenAI model",
1105
+ type: "text",
1106
+ env: "OPENAI_STT_MODEL",
1107
+ default: "whisper-1",
1108
+ showWhen: { sttProvider: "openai" },
1109
+ suggestions: ["whisper-1", "gpt-4o-mini-transcribe", "gpt-4o-transcribe"],
1110
+ hint: "Uses the OpenAI API key below"
1111
+ },
1112
+ {
1113
+ key: "openaiSttLanguage",
1114
+ label: "OpenAI language",
1115
+ type: "text",
1116
+ env: "OPENAI_STT_LANGUAGE",
1117
+ default: "",
1118
+ showWhen: { sttProvider: "openai" },
1119
+ hint: "ISO-639-1 code such as en; blank = detect automatically"
1120
+ },
1121
+ {
1122
+ key: "elevenlabsApiKey",
1123
+ label: "ElevenLabs API key",
1124
+ type: "password",
1125
+ secret: !0,
1126
+ env: "ELEVENLABS_API_KEY",
1127
+ showWhenAny: [{ sttProvider: "elevenlabs" }, { ttsProvider: "elevenlabs" }],
1128
+ hint: "Used for ElevenLabs speech-to-text and/or text-to-speech. Get one at https://elevenlabs.io/app/settings/api-keys"
1129
+ },
1130
+ {
1131
+ key: "elevenlabsSttModel",
1132
+ label: "ElevenLabs model",
1133
+ type: "text",
1134
+ env: "ELEVENLABS_STT_MODEL",
1135
+ default: "scribe_v2",
1136
+ showWhen: { sttProvider: "elevenlabs" },
1137
+ suggestions: ["scribe_v2", "scribe_v3", "scribe_v2_medical"]
1138
+ },
1139
+ {
1140
+ key: "elevenlabsLanguage",
1141
+ label: "ElevenLabs language",
1142
+ type: "text",
1143
+ env: "ELEVENLABS_STT_LANGUAGE",
1144
+ default: "",
1145
+ showWhen: { sttProvider: "elevenlabs" },
1146
+ hint: "ISO code such as en or de; blank = detect automatically"
1147
+ },
1148
+ {
1149
+ key: "whisperModel",
1150
+ label: "Model",
1151
+ type: "select",
1152
+ env: "WHISPER_MODEL",
1153
+ default: "onnx-community/whisper-small.en",
1154
+ showWhen: { sttProvider: "whisper" },
1155
+ allowCustom: !0,
1156
+ // any other Hugging Face model id from an env var / imported file is kept
1157
+ options: [
1158
+ ["onnx-community/whisper-tiny.en", "whisper-tiny.en — fastest, ~40 MB, more errors"],
1159
+ ["onnx-community/whisper-base.en", "whisper-base.en — better, ~74 MB, recommended"],
1160
+ ["onnx-community/whisper-small.en", "whisper-small.en — good, ~244 MB, significantly more accurate"]
1161
+ ]
1162
+ },
1163
+ {
1164
+ key: "whisperDtype",
1165
+ label: "Precision",
1166
+ type: "select",
1167
+ env: "WHISPER_DTYPE",
1168
+ default: "fp32",
1169
+ showWhen: { sttProvider: "whisper" },
1170
+ options: [["q8", "q8"], ["q4", "q4"], ["fp16", "fp16 (WebGPU)"], ["fp32", "fp32"]]
1171
+ },
1172
+ {
1173
+ key: "whisperDevice",
1174
+ label: "Device",
1175
+ type: "select",
1176
+ env: "WHISPER_DEVICE",
1177
+ default: "webgpu",
1178
+ showWhen: { sttProvider: "whisper" },
1179
+ aliases: { cpu: "wasm" },
1180
+ options: [["wasm", "wasm (CPU)"], ["webgpu", "webgpu"]]
1181
+ }
1182
+ ]
1183
+ },
1184
+ {
1185
+ group: "Text-to-speech",
1186
+ fields: [
1187
+ {
1188
+ key: "ttsProvider",
1189
+ label: "Provider",
1190
+ type: "select",
1191
+ env: "TTS_PROVIDER",
1192
+ default: "kokoro",
1193
+ options: [
1194
+ ["kokoro", "Kokoro in the browser", re],
1195
+ ["server-kokoro", "Kokoro on the server (needs: npm install kokoro-js)", re],
1196
+ ["webspeech", "Browser Web Speech API (built-in voices)", re],
1197
+ ["openai", "OpenAI TTS", Q],
1198
+ ["elevenlabs", "ElevenLabs", Q]
1199
+ ]
1200
+ },
1201
+ {
1202
+ key: "kokoroVoice",
1203
+ label: "Kokoro voice",
1204
+ type: "text",
1205
+ env: "KOKORO_VOICE",
1206
+ default: "af_bella",
1207
+ showWhen: { ttsProvider: ["kokoro", "server-kokoro"] },
1208
+ hint: "e.g. af_bella, af_sarah, am_adam"
1209
+ },
1210
+ {
1211
+ key: "kokoroSpeed",
1212
+ label: "Kokoro speed",
1213
+ type: "number",
1214
+ env: "KOKORO_SPEED",
1215
+ default: 1,
1216
+ showWhen: { ttsProvider: ["kokoro", "server-kokoro"] },
1217
+ hint: "1 = normal; 1.1–1.2 often sounds more natural"
1218
+ },
1219
+ {
1220
+ key: "kokoroDtype",
1221
+ label: "Kokoro precision",
1222
+ type: "select",
1223
+ env: "KOKORO_DTYPE",
1224
+ default: "fp32",
1225
+ showWhen: { ttsProvider: ["kokoro", "server-kokoro"] },
1226
+ options: it.map((e) => [e, e]),
1227
+ hint: "q4/q8 are promoted to fp32 on WebGPU"
1228
+ },
1229
+ {
1230
+ key: "kokoroBrowserDevice",
1231
+ label: "Kokoro device (browser)",
1232
+ type: "select",
1233
+ env: "KOKORO_BROWSER_DEVICE",
1234
+ default: "webgpu",
1235
+ showWhen: { ttsProvider: "kokoro" },
1236
+ options: [["wasm", "wasm"], ["webgpu", "webgpu"]]
1237
+ },
1238
+ {
1239
+ key: "kokoroDevice",
1240
+ label: "Kokoro device (server)",
1241
+ type: "select",
1242
+ env: "KOKORO_DEVICE",
1243
+ default: "cpu",
1244
+ showWhen: { ttsProvider: "server-kokoro" },
1245
+ options: [["cpu", "cpu"]]
1246
+ },
1247
+ {
1248
+ key: "openaiTtsModel",
1249
+ label: "OpenAI TTS model",
1250
+ type: "text",
1251
+ env: "OPENAI_TTS_MODEL",
1252
+ default: "tts-1",
1253
+ showWhen: { ttsProvider: "openai" },
1254
+ suggestions: ["tts-1", "tts-1-hd", "gpt-4o-mini-tts"]
1255
+ },
1256
+ {
1257
+ key: "openaiTtsVoice",
1258
+ label: "OpenAI voice",
1259
+ type: "text",
1260
+ env: "OPENAI_TTS_VOICE",
1261
+ default: "alloy",
1262
+ showWhen: { ttsProvider: "openai" },
1263
+ suggestions: ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
1264
+ },
1265
+ {
1266
+ key: "elevenlabsVoiceId",
1267
+ label: "ElevenLabs voice ID",
1268
+ type: "text",
1269
+ env: "ELEVENLABS_VOICE_ID",
1270
+ default: "21m00Tcm4TlvDq8ikWAM",
1271
+ showWhen: { ttsProvider: "elevenlabs" },
1272
+ hint: `Default is the premade "Rachel" voice. Copy another voice's ID from your ElevenLabs voice library.`
1273
+ },
1274
+ {
1275
+ key: "elevenlabsTtsModel",
1276
+ label: "ElevenLabs model",
1277
+ type: "text",
1278
+ env: "ELEVENLABS_TTS_MODEL",
1279
+ default: "eleven_flash_v2_5",
1280
+ showWhen: { ttsProvider: "elevenlabs" },
1281
+ suggestions: ["eleven_flash_v2_5", "eleven_turbo_v2_5", "eleven_multilingual_v2"],
1282
+ hint: "Flash is the lowest latency — best for voice chat"
1283
+ },
1284
+ {
1285
+ key: "webSpeechVoice",
1286
+ label: "Web Speech voice",
1287
+ type: "text",
1288
+ env: "WEBSPEECH_VOICE",
1289
+ default: "",
1290
+ showWhen: { ttsProvider: "webspeech" },
1291
+ hint: "Exact voice name; blank = browser default"
1292
+ },
1293
+ {
1294
+ key: "webSpeechRate",
1295
+ label: "Web Speech rate",
1296
+ type: "number",
1297
+ env: "WEBSPEECH_RATE",
1298
+ default: 1,
1299
+ showWhen: { ttsProvider: "webspeech" },
1300
+ hint: "0.1 – 10"
1301
+ },
1302
+ {
1303
+ key: "webSpeechPitch",
1304
+ label: "Web Speech pitch",
1305
+ type: "number",
1306
+ env: "WEBSPEECH_PITCH",
1307
+ default: 1,
1308
+ showWhen: { ttsProvider: "webspeech" },
1309
+ hint: "0 – 2"
1310
+ }
1311
+ ]
1312
+ }
1313
+ ], ze = xe.flatMap((e) => e.fields);
1314
+ Object.fromEntries(ze.map((e) => [e.key, e]));
1315
+ ze.filter((e) => e.secret).map((e) => e.key);
1316
+ function ct(e, a) {
1317
+ const r = (c) => Object.entries(c).every(([n, o]) => (Array.isArray(o) ? o : [o]).includes(a[n]));
1318
+ return e.showWhenAny ? e.showWhenAny.some(r) : e.showWhen ? r(e.showWhen) : !0;
1319
+ }
1320
+ function lt(e, a = {}) {
1321
+ const r = [], c = (s) => !!a[s], n = e.chatProvider;
1322
+ n || r.push({ key: "chatProvider", message: "No chat model provider is configured.", scope: "chat" }), n === "openai-compatible" && (e.compatBaseUrl || r.push({ key: "compatBaseUrl", message: "The OpenAI-compatible server URL is missing.", scope: "chat" }), e.compatModel || r.push({ key: "compatModel", message: "The model name for the OpenAI-compatible server is missing.", scope: "chat" }));
1323
+ const o = [
1324
+ { key: "openrouterApiKey", name: "OpenRouter API key", uses: [n === "openrouter" && ["chat", "chat"]] },
1325
+ { key: "anthropicApiKey", name: "Anthropic API key", uses: [n === "anthropic" && ["chat", "chat"]] },
1326
+ { key: "huggingfaceApiKey", name: "Hugging Face token", uses: [n === "huggingface" && ["chat", "chat"]] },
1327
+ { key: "openaiApiKey", name: "OpenAI API key", uses: [
1328
+ n === "openai" && ["chat", "chat"],
1329
+ e.sttProvider === "openai" && ["speech-to-text", "stt"],
1330
+ e.ttsProvider === "openai" && ["text-to-speech", "tts"]
1331
+ ] },
1332
+ { key: "elevenlabsApiKey", name: "ElevenLabs API key", uses: [
1333
+ e.sttProvider === "elevenlabs" && ["speech-to-text", "stt"],
1334
+ e.ttsProvider === "elevenlabs" && ["text-to-speech", "tts"]
1335
+ ] }
1336
+ ];
1337
+ for (const { key: s, name: l, uses: i } of o) {
1338
+ const p = i.filter(Boolean);
1339
+ if (!p.length || c(s)) continue;
1340
+ const d = p.some((f) => f[1] === "chat") ? "chat" : p[0][1], k = p.length === 1 && p[0][0] === "chat" ? `${l} is missing.` : `${l} (for ${p.map((f) => f[0]).join(", ").replace(/, ([^,]*)$/, " and $1")}) is missing.`;
1341
+ r.push({ key: s, message: k, scope: d });
1342
+ }
1343
+ return r;
1344
+ }
1345
+ function ut({ apiBase: e = "/api", onSaved: a, onClose: r }) {
1346
+ const [c, n] = z(null), [o, s] = z({}), [l, i] = z(null), [p, d] = z(!1), k = W(null), f = Ne(async () => {
1347
+ try {
1348
+ const t = await fetch(`${e}/settings`);
1349
+ if (!t.ok) throw new Error(await t.text());
1350
+ n(await t.json());
1351
+ } catch (t) {
1352
+ i({ kind: "error", text: `Could not load settings: ${t.message}` });
1353
+ }
1354
+ }, [e]);
1355
+ if (j(() => {
1356
+ f();
1357
+ }, [f]), !c) return /* @__PURE__ */ u("section", { className: "tz-va__card", children: l ? l.text : "Loading settings…" });
1358
+ const h = { ...c.values, ...Object.fromEntries(Object.entries(o).filter(([, t]) => t !== null)) }, w = { ...c.secretsSet };
1359
+ for (const [t, b] of Object.entries(o)) t in w && (w[t] = b === null ? !1 : b ? !0 : w[t]);
1360
+ const A = lt(h, w), N = new Set(A.map((t) => t.key)), S = Object.keys(o).length > 0, T = (t, b) => s((g) => ({ ...g, [t]: b }));
1361
+ async function L(t, b) {
1362
+ var g;
1363
+ d(!0);
1364
+ try {
1365
+ const E = await fetch(`${e}/settings`, {
1366
+ method: "PUT",
1367
+ headers: { "Content-Type": "application/json" },
1368
+ body: JSON.stringify(t)
1369
+ });
1370
+ if (!E.ok) throw new Error(await E.text());
1371
+ const m = await E.json();
1372
+ n(m), s({});
1373
+ const P = (g = m.ignored) != null && g.length ? ` Ignored unknown/invalid keys: ${m.ignored.join(", ")}.` : "";
1374
+ i({ kind: "ok", text: b + P }), a == null || a(m);
1375
+ } catch (E) {
1376
+ i({ kind: "error", text: E.message });
1377
+ } finally {
1378
+ d(!1);
1379
+ }
1380
+ }
1381
+ async function K() {
1382
+ try {
1383
+ const t = await fetch(`${e}/settings/export`);
1384
+ if (!t.ok) throw new Error(await t.text());
1385
+ const b = new Blob([JSON.stringify(await t.json(), null, 2)], { type: "application/json" }), g = document.createElement("a");
1386
+ g.href = URL.createObjectURL(b), g.download = "tz-voice-chat-settings.json", g.click(), URL.revokeObjectURL(g.href), i({ kind: "ok", text: "Exported. The file contains your API keys — keep it private." });
1387
+ } catch (t) {
1388
+ i({ kind: "error", text: `Export failed: ${t.message}` });
1389
+ }
1390
+ }
1391
+ async function V(t) {
1392
+ var g;
1393
+ const b = (g = t.target.files) == null ? void 0 : g[0];
1394
+ if (t.target.value = "", !!b)
1395
+ try {
1396
+ const E = JSON.parse(await b.text()), m = E && typeof E.settings == "object" ? E.settings : E;
1397
+ if (!m || typeof m != "object" || Array.isArray(m)) throw new Error("not a settings object");
1398
+ await L({ settings: m }, `Imported ${b.name} and applied it.`);
1399
+ } catch (E) {
1400
+ i({ kind: "error", text: `Import failed: ${E.message}` });
1401
+ }
1402
+ }
1403
+ function C(t) {
1404
+ const b = [];
1405
+ for (const [g, E, m] of t) {
1406
+ const P = b[b.length - 1], D = /* @__PURE__ */ u("option", { value: g, children: E }, g);
1407
+ m ? P && P.group === m ? P.items.push(D) : b.push({ group: m, items: [D] }) : b.push(D);
1408
+ }
1409
+ return b.map((g) => g.group ? /* @__PURE__ */ u("optgroup", { label: g.group, children: g.items }, g.group) : g);
1410
+ }
1411
+ function $(t) {
1412
+ const b = `tz-va-set-${t.key}`, g = N.has(t.key);
1413
+ let E;
1414
+ if (t.type === "select")
1415
+ E = /* @__PURE__ */ _("select", { id: b, value: h[t.key] ?? "", onChange: (m) => T(t.key, m.target.value), children: [
1416
+ C(t.options),
1417
+ t.allowCustom && h[t.key] && !t.options.some(([m]) => m === h[t.key]) && /* @__PURE__ */ _("option", { value: h[t.key], children: [
1418
+ h[t.key],
1419
+ " (custom)"
1420
+ ] })
1421
+ ] });
1422
+ else if (t.type === "textarea")
1423
+ E = /* @__PURE__ */ u("textarea", { id: b, rows: 4, value: h[t.key] ?? "", onChange: (m) => T(t.key, m.target.value) });
1424
+ else if (t.type === "password") {
1425
+ const m = t.key in o, P = o[t.key] === null ? "Will be cleared on save" : c.secretsSet[t.key] ? "Saved — type to replace" : "Not set";
1426
+ E = /* @__PURE__ */ _("span", { className: "tz-va__secret", children: [
1427
+ /* @__PURE__ */ u(
1428
+ "input",
1429
+ {
1430
+ id: b,
1431
+ type: "password",
1432
+ autoComplete: "off",
1433
+ value: o[t.key] ?? "",
1434
+ placeholder: P,
1435
+ onChange: (D) => T(t.key, D.target.value)
1436
+ }
1437
+ ),
1438
+ (c.secretsSet[t.key] || m) && /* @__PURE__ */ u(
1439
+ "button",
1440
+ {
1441
+ type: "button",
1442
+ className: "tz-va__link",
1443
+ onClick: () => m ? s((D) => {
1444
+ const G = { ...D };
1445
+ return delete G[t.key], G;
1446
+ }) : T(t.key, null),
1447
+ children: m ? "Undo" : "Clear"
1448
+ }
1449
+ )
1450
+ ] });
1451
+ } else
1452
+ E = /* @__PURE__ */ _(Ee, { children: [
1453
+ /* @__PURE__ */ u(
1454
+ "input",
1455
+ {
1456
+ id: b,
1457
+ type: t.type === "number" ? "number" : "text",
1458
+ step: t.type === "number" ? "any" : void 0,
1459
+ list: t.suggestions ? `${b}-list` : void 0,
1460
+ value: h[t.key] ?? "",
1461
+ onChange: (m) => T(t.key, m.target.value)
1462
+ }
1463
+ ),
1464
+ t.suggestions && /* @__PURE__ */ u("datalist", { id: `${b}-list`, children: t.suggestions.map((m) => /* @__PURE__ */ u("option", { value: m }, m)) })
1465
+ ] });
1466
+ return /* @__PURE__ */ _("div", { className: `tz-va__field${g ? " tz-va__field--missing" : ""}`, children: [
1467
+ /* @__PURE__ */ _("label", { htmlFor: b, children: [
1468
+ t.label,
1469
+ g && /* @__PURE__ */ u("em", { children: " — required" })
1470
+ ] }),
1471
+ E,
1472
+ t.hint && /* @__PURE__ */ u("small", { children: t.hint })
1473
+ ] }, t.key);
1474
+ }
1475
+ return /* @__PURE__ */ _(Ee, { children: [
1476
+ /* @__PURE__ */ _("section", { className: "tz-va__card tz-va__settings", children: [
1477
+ A.length > 0 && /* @__PURE__ */ _("div", { className: "tz-va__notice", role: "alert", children: [
1478
+ /* @__PURE__ */ u("strong", { children: "Setup incomplete:" }),
1479
+ " ",
1480
+ A.map((t) => t.message).join(" ")
1481
+ ] }),
1482
+ xe.map((t) => /* @__PURE__ */ _("fieldset", { children: [
1483
+ /* @__PURE__ */ u("legend", { children: t.group }),
1484
+ t.fields.filter((b) => ct(b, h)).map($)
1485
+ ] }, t.group)),
1486
+ /* @__PURE__ */ _("p", { className: "tz-va__note", children: [
1487
+ "Saved to ",
1488
+ /* @__PURE__ */ u("code", { children: c.file }),
1489
+ " and applied immediately. Environment variables provide the initial values."
1490
+ ] }),
1491
+ /* @__PURE__ */ _("div", { className: "tz-va__actions", children: [
1492
+ /* @__PURE__ */ u("button", { type: "button", disabled: p || !S, onClick: () => L(o, "Settings saved and applied."), children: "Save" }),
1493
+ /* @__PURE__ */ u("button", { type: "button", className: "tz-va__secondary", disabled: !S, onClick: () => s({}), children: "Discard" }),
1494
+ /* @__PURE__ */ u("span", { className: "tz-va__spacer" }),
1495
+ /* @__PURE__ */ u("button", { type: "button", className: "tz-va__secondary", onClick: () => {
1496
+ var t;
1497
+ return (t = k.current) == null ? void 0 : t.click();
1498
+ }, children: "Import…" }),
1499
+ /* @__PURE__ */ u("button", { type: "button", className: "tz-va__secondary", onClick: K, children: "Export" }),
1500
+ /* @__PURE__ */ u("input", { ref: k, type: "file", accept: "application/json,.json", hidden: !0, onChange: V })
1501
+ ] }),
1502
+ l && /* @__PURE__ */ u("p", { className: `tz-va__status tz-va__status--${l.kind}`, children: l.text })
1503
+ ] }),
1504
+ r && /* @__PURE__ */ u("div", { className: "tz-va__actions", children: /* @__PURE__ */ u("button", { type: "button", className: "tz-va__secondary", onClick: r, children: "← Back to chat" }) })
1505
+ ] });
1506
+ }
1507
+ const $e = (e, a) => e === "webgpu" && (a === "q4" || a === "q8") ? "fp32" : a, Ae = (e) => e >= 1e3 ? `${(e / 1e3).toFixed(1)} s` : `${e} ms`, Te = (e) => `${(e / 1048576).toFixed(0)} MB`;
1508
+ function dt(e) {
911
1509
  switch (e.ttsProvider) {
912
1510
  case "openai":
913
1511
  return `OpenAI · ${e.openaiTtsModel} · ${e.ttsVoice}`;
1512
+ case "elevenlabs":
1513
+ return `ElevenLabs · ${e.elevenlabsTtsModel} · ${e.ttsVoice}`;
914
1514
  case "webspeech":
915
1515
  return `Web Speech API · rate ${e.ttsSpeechRate} · pitch ${e.ttsSpeechPitch}`;
916
1516
  case "server-kokoro":
917
1517
  return `Kokoro (server) · ${e.ttsVoice} · ${e.kokoroDtype}/${e.kokoroDevice}`;
918
1518
  default:
919
- return `Kokoro (browser) · ${e.ttsVoice} · ${Ae(e.kokoroBrowserDevice, e.kokoroDtype)}/${e.kokoroBrowserDevice}`;
1519
+ return `Kokoro (browser) · ${e.ttsVoice} · ${$e(e.kokoroBrowserDevice, e.kokoroDtype)}/${e.kokoroBrowserDevice}`;
920
1520
  }
921
1521
  }
922
- const Ze = (e) => e.replace(/\b\w/g, (r) => r.toUpperCase());
923
- function et({
1522
+ const ht = (e) => e.replace(/\b\w/g, (a) => a.toUpperCase());
1523
+ function mt({
924
1524
  apiBase: e = "/api",
925
- title: r = "Voice Assistant",
926
- showInfo: s = !0,
927
- systemPrompt: a,
928
- className: t = ""
1525
+ title: a = "Voice Assistant",
1526
+ showInfo: r = !0,
1527
+ systemPrompt: c,
1528
+ className: n = ""
929
1529
  } = {}) {
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);
1530
+ const { chat: o, info: s, config: l, memory: i, llmProgress: p, note: d, loading: k, missing: f, reload: h } = ot({ apiBase: e, systemPrompt: c }), [w, A] = z("chat"), {
1531
+ status: N,
1532
+ progress: S,
1533
+ error: T,
1534
+ transcript: L,
1535
+ streamingMessage: K,
1536
+ micEnabled: V,
1537
+ startListening: C,
1538
+ stopListening: $,
1539
+ submitText: t,
1540
+ liveAnalyser: b,
1541
+ devices: g,
1542
+ selectedMicId: E,
1543
+ setSelectedMicId: m
1544
+ } = o, [P, D] = z(""), G = W(null);
945
1545
  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)"],
1546
+ var M;
1547
+ (M = G.current) == null || M.scrollIntoView({ behavior: K !== null ? "auto" : "smooth" });
1548
+ }, [L, K]);
1549
+ const ee = s && l.whisperDevice && [
1550
+ ["STT", s.sttProvider === "elevenlabs" ? `ElevenLabs · ${s.elevenlabsSttModel}` : s.sttProvider === "openai" ? `OpenAI · ${s.openaiSttModel}` : `Whisper · ${(l.whisperModel || s.whisperModel).split("/").pop()} · ${$e(l.whisperDevice, l.whisperDtype)}/${l.whisperDevice}`],
1551
+ ["TTS", dt({ ...s, ...l })],
1552
+ ["Chat", s.chatProvider === "local" ? "SmolLM2-360M-Instruct (in-browser) — slow and simple" : s.chatReady ? `${s.chatProvider} · ${s.chatModel}` : "not configured"],
953
1553
  ["Memory", [
954
- o.browser != null ? `browser heap ${Se(o.browser)}` : "browser heap n/a",
955
- o.server != null ? `server ${Se(o.server)}` : null
1554
+ i.browser != null ? `browser heap ${Te(i.browser)}` : "browser heap n/a",
1555
+ i.server != null ? `server ${Te(i.server)}` : null
956
1556
  ].filter(Boolean).join(" · ")]
957
1557
  ];
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) })
1558
+ return /* @__PURE__ */ _("div", { className: `tz-va ${n}`.trim(), children: [
1559
+ /* @__PURE__ */ _("section", { className: "tz-va__card tz-va__header", children: [
1560
+ /* @__PURE__ */ u("h1", { children: a }),
1561
+ /* @__PURE__ */ _("span", { className: "tz-va__header-right", children: [
1562
+ /* @__PURE__ */ u("span", { className: `tz-va__chip tz-va__chip--${N}`, children: ht(N) }),
1563
+ /* @__PURE__ */ u(
1564
+ "button",
1565
+ {
1566
+ type: "button",
1567
+ className: `tz-va__gear${w === "settings" ? " tz-va__gear--on" : ""}`,
1568
+ "aria-label": "Settings",
1569
+ title: "Settings",
1570
+ onClick: () => A((M) => M === "settings" ? "chat" : "settings"),
1571
+ children: /* @__PURE__ */ _("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
1572
+ /* @__PURE__ */ u("circle", { cx: "12", cy: "12", r: "3" }),
1573
+ /* @__PURE__ */ u("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33h0a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51h0a1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82v0a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" })
1574
+ ] })
1575
+ }
1576
+ )
1577
+ ] })
962
1578
  ] }),
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
- ] })
1579
+ f.length > 0 && w !== "settings" && /* @__PURE__ */ _("section", { className: "tz-va__card tz-va__notice", role: "alert", children: [
1580
+ /* @__PURE__ */ _("div", { children: [
1581
+ /* @__PURE__ */ u("strong", { children: "Setup incomplete." }),
1582
+ " ",
1583
+ f.map((M) => M.message).join(" ")
981
1584
  ] }),
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 })
1585
+ /* @__PURE__ */ u("button", { type: "button", onClick: () => A("settings"), children: "Open Settings" })
1015
1586
  ] }),
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)
1587
+ w === "settings" ? /* @__PURE__ */ u(ut, { apiBase: e, onSaved: h, onClose: () => A("chat") }) : /* @__PURE__ */ _(Ee, { children: [
1588
+ r && ee && /* @__PURE__ */ u("section", { className: "tz-va__card tz-va__info", children: ee.map(([M, ae]) => /* @__PURE__ */ _("div", { className: "tz-va__info-row", children: [
1589
+ /* @__PURE__ */ u("span", { className: "tz-va__info-label", children: M }),
1590
+ /* @__PURE__ */ u("span", { className: "tz-va__info-value", children: ae })
1591
+ ] }, M)) }),
1592
+ /* @__PURE__ */ _("section", { className: "tz-va__card", children: [
1593
+ k && /* @__PURE__ */ _("div", { className: "tz-va__progress", children: [
1594
+ l.sttProvider !== "server" && /* @__PURE__ */ _("label", { children: [
1595
+ "Whisper STT",
1596
+ /* @__PURE__ */ u("div", { className: "tz-va__bar", children: /* @__PURE__ */ u("span", { style: { width: `${S.whisper * 100}%` } }) })
1024
1597
  ] }),
1025
- y.timings.thinkMs != null && /* @__PURE__ */ S("span", { children: [
1026
- "think ",
1027
- we(y.timings.thinkMs)
1598
+ /* @__PURE__ */ _("label", { children: [
1599
+ "Kokoro TTS",
1600
+ /* @__PURE__ */ u("div", { className: "tz-va__bar", children: /* @__PURE__ */ u("span", { style: { width: `${S.kokoro * 100}%` } }) })
1028
1601
  ] }),
1029
- y.timings.ttsMs != null && /* @__PURE__ */ S("span", { children: [
1030
- "tts ",
1031
- we(y.timings.ttsMs)
1602
+ p > 0 && /* @__PURE__ */ _("label", { children: [
1603
+ "Local LLM",
1604
+ /* @__PURE__ */ u("div", { className: "tz-va__bar", children: /* @__PURE__ */ u("span", { style: { width: `${p * 100}%` } }) })
1032
1605
  ] })
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
- ] })
1606
+ ] }),
1607
+ /* @__PURE__ */ u("div", { className: "tz-va__button", children: /* @__PURE__ */ u(
1608
+ st,
1609
+ {
1610
+ status: N,
1611
+ active: V,
1612
+ loading: k,
1613
+ analyser: b,
1614
+ onToggle: V ? $ : C,
1615
+ devices: g,
1616
+ selectedMicId: E,
1617
+ onDeviceChange: m,
1618
+ inputData: P,
1619
+ sendData: (M) => {
1620
+ D(""), t(M);
1621
+ }
1622
+ }
1623
+ ) }),
1624
+ /* @__PURE__ */ u("div", { className: "tz-va__input-row", children: /* @__PURE__ */ u(
1625
+ "input",
1626
+ {
1627
+ type: "text",
1628
+ className: "tz-va__input",
1629
+ value: P,
1630
+ onChange: (M) => D(M.target.value),
1631
+ onKeyDown: (M) => {
1632
+ M.key === "Enter" && P.trim() && (D(""), t(P));
1633
+ },
1634
+ placeholder: "Type a message…",
1635
+ disabled: k
1636
+ }
1637
+ ) }),
1638
+ /* @__PURE__ */ u("p", { className: "tz-va__note", children: k ? S.kokoro < 1 ? "Loading Kokoro TTS…" : S.whisper < 1 ? "Loading Whisper STT…" : p > 0 && p < 1 ? "Loading local LLM (SmolLM2-360M, ~200 MB)…" : "Finishing up…" : "Ready." }),
1639
+ d && /* @__PURE__ */ u("p", { className: "tz-va__note", children: d })
1041
1640
  ] }),
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
1641
+ /* @__PURE__ */ _("section", { className: "tz-va__card tz-va__transcript", children: [
1642
+ L.map((M) => /* @__PURE__ */ _("div", { className: `tz-va__message tz-va__message--${M.role}`, children: [
1643
+ /* @__PURE__ */ u("small", { children: M.role === "user" ? "You" : "Assistant" }),
1644
+ /* @__PURE__ */ u("p", { children: M.content }),
1645
+ M.timings && /* @__PURE__ */ _("div", { className: "tz-va__timings", children: [
1646
+ M.timings.transcribeMs != null && /* @__PURE__ */ _("span", { children: [
1647
+ "transcribe ",
1648
+ Ae(M.timings.transcribeMs)
1649
+ ] }),
1650
+ M.timings.thinkMs != null && /* @__PURE__ */ _("span", { children: [
1651
+ "think ",
1652
+ Ae(M.timings.thinkMs)
1653
+ ] }),
1654
+ M.timings.ttsMs != null && /* @__PURE__ */ _("span", { children: [
1655
+ "tts ",
1656
+ Ae(M.timings.ttsMs)
1657
+ ] })
1658
+ ] })
1659
+ ] }, M.id)),
1660
+ K !== null && /* @__PURE__ */ _("div", { className: "tz-va__message tz-va__message--assistant tz-va__message--streaming", children: [
1661
+ /* @__PURE__ */ u("small", { children: "Assistant" }),
1662
+ /* @__PURE__ */ _("p", { children: [
1663
+ K,
1664
+ /* @__PURE__ */ u("span", { className: "tz-va__cursor" })
1665
+ ] })
1666
+ ] }),
1667
+ /* @__PURE__ */ u("div", { ref: G })
1668
+ ] }),
1669
+ T ? /* @__PURE__ */ _("section", { className: "tz-va__card", children: [
1670
+ /* @__PURE__ */ u("strong", { children: "Error:" }),
1671
+ /* @__PURE__ */ u("p", { children: T })
1672
+ ] }) : null
1673
+ ] })
1048
1674
  ] });
1049
1675
  }
1050
1676
  export {
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
1677
+ st as AIAssistantButton,
1678
+ xe as SETTINGS_SCHEMA,
1679
+ x as STATES,
1680
+ ut as SettingsPanel,
1681
+ Xe as TZVoiceChat,
1682
+ mt as VoiceAssistant,
1683
+ lt as computeMissing,
1684
+ at as createLocalChatStream,
1685
+ rt as sendChatRequest,
1686
+ ot as useVoiceAssistant
1058
1687
  };