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