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