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