tuxevil-rotator 4.2.2 → 4.4.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/CHANGELOG.md +48 -1
- package/README.md +11 -4
- package/package.json +2 -1
- package/plugins/opencode-discovery/capabilities.d.mts +7 -0
- package/plugins/opencode-discovery/capabilities.mjs +54 -0
- package/plugins/opencode-discovery/index.d.mts +2 -1
- package/plugins/opencode-discovery/index.mjs +6 -1
- package/plugins/opencode-discovery/package.json +3 -1
- package/src/access-evidence.ts +153 -0
- package/src/access-probe.ts +85 -0
- package/src/admin-auth.ts +4 -1
- package/src/audio-transcription.ts +32 -6
- package/src/auto-access-shadow.ts +11 -0
- package/src/auto-model-access.ts +185 -0
- package/src/auto-output-health.ts +12 -0
- package/src/auto-routing-evaluation.ts +80 -0
- package/src/auto-routing-quality.ts +308 -0
- package/src/auto-routing.ts +403 -26
- package/src/cli.ts +3 -3
- package/src/compat/model-specs.ts +4 -0
- package/src/compat.ts +253 -37
- package/src/compression/index.ts +6 -6
- package/src/compression/lite.ts +3 -9
- package/src/compression/rtk/index.ts +0 -3
- package/src/config-defaults.ts +7 -0
- package/src/dashboard-app.ts +1 -0
- package/src/dashboard.ts +5 -0
- package/src/db-store.ts +10 -0
- package/src/index.ts +2 -0
- package/src/install-agent.ts +211 -129
- package/src/install-opencode.ts +80 -18
- package/src/model-access-api.ts +74 -0
- package/src/model-access.ts +56 -0
- package/src/ollama-output-gate.ts +18 -0
- package/src/onboarding.ts +1 -1
- package/src/provider-catalog-evidence.ts +26 -0
- package/src/providers/google-antigravity/catalog.ts +14 -6
- package/src/providers/google-antigravity/dynamic-catalog.ts +87 -3
- package/src/providers/google-antigravity/forward.ts +4 -2
- package/src/providers/google-antigravity/quota.ts +7 -0
- package/src/providers/ollama/context-window.ts +13 -0
- package/src/providers/ollama/forward.ts +10 -0
- package/src/providers/ollama/quota.ts +4 -0
- package/src/providers/ollama/translators.ts +19 -2
- package/src/providers/openai-codex/catalog.ts +157 -18
- package/src/providers/openai-codex/compat.ts +5 -1
- package/src/providers/openai-codex/credentials.ts +22 -6
- package/src/providers/openai-codex/index.ts +9 -1
- package/src/providers/openai-codex/quota.ts +19 -6
- package/src/providers/opencode-zen/forward.ts +1 -1
- package/src/providers/opencode-zen/quota.ts +2 -0
- package/src/proxy.ts +113 -5
- package/src/quota-observation.ts +26 -0
- package/src/quota-pools.ts +322 -0
- package/src/rotator.ts +167 -40
- package/src/settings-repository.ts +1 -0
- package/src/types.ts +106 -29
- package/src/usage-limits-auth.ts +24 -0
- package/src/usage-limits.ts +148 -0
- package/src/validators.ts +26 -0
- package/src/web/app.tsx +4 -0
- package/src/web/components/icons.tsx +15 -0
- package/src/web/components/overlays.tsx +4 -0
- package/src/web/components/ui.tsx +9 -9
- package/src/web/lib/audio-recorder.ts +159 -0
- package/src/web/lib/colors.ts +4 -0
- package/src/web/lib/playground-storage.ts +261 -0
- package/src/web/lib/playground.ts +483 -0
- package/src/web/lib/pool-navigation.ts +4 -0
- package/src/web/lib/pools.ts +2 -243
- package/src/web/nav.ts +1 -0
- package/src/web/pages/AccountDetail.tsx +2 -1
- package/src/web/pages/ModelAccess.tsx +88 -0
- package/src/web/pages/Models.tsx +2 -0
- package/src/web/pages/Overview.tsx +26 -9
- package/src/web/pages/Playground.tsx +1692 -0
- package/src/web/pages/Transcription.tsx +562 -0
- package/src/web/state/api.ts +6 -0
- package/src/web/state/playground-client.ts +136 -0
- package/src/web/state/playground.ts +69 -0
- package/src/web/state/router.ts +2 -2
- package/src/web/state/transcription-client.ts +93 -0
- package/src/web/styles/app.css +501 -0
- package/tools/telemetry-receiver/receiver.js +59 -46
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import type { JSX } from "preact";
|
|
2
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
3
|
+
import { Button, EmptyState, Panel, Pill } from "../components/ui.js";
|
|
4
|
+
import { Icon } from "../components/icons.js";
|
|
5
|
+
import { copyText, downloadText } from "./shared.js";
|
|
6
|
+
import { toast } from "../state/actions.js";
|
|
7
|
+
import { masked, masker } from "../state/store.js";
|
|
8
|
+
import { transcribeAudio } from "../state/transcription-client.js";
|
|
9
|
+
import { newId, type TranscriptionState } from "../lib/playground.js";
|
|
10
|
+
import {
|
|
11
|
+
AUDIO_ACCEPT,
|
|
12
|
+
AudioRecorder,
|
|
13
|
+
audioFileLimit,
|
|
14
|
+
MAX_RECORDING_MS,
|
|
15
|
+
validateAudioFile,
|
|
16
|
+
type RecordingState,
|
|
17
|
+
} from "../lib/audio-recorder.js";
|
|
18
|
+
import { formatDateTime, formatMs, pluralize } from "../lib/format.js";
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
state: TranscriptionState;
|
|
22
|
+
models: string[];
|
|
23
|
+
maxBodyBytes: number;
|
|
24
|
+
disabled: boolean;
|
|
25
|
+
onChange: (update: (state: TranscriptionState) => TranscriptionState) => void;
|
|
26
|
+
onBusyChange: (busy: boolean) => void;
|
|
27
|
+
controllers: Map<string, AbortController>;
|
|
28
|
+
}
|
|
29
|
+
interface Problem {
|
|
30
|
+
title: string;
|
|
31
|
+
message: string;
|
|
32
|
+
}
|
|
33
|
+
const message = (err: unknown): string =>
|
|
34
|
+
err instanceof Error ? err.message : String(err);
|
|
35
|
+
function clock(ms: number): string {
|
|
36
|
+
const seconds = Math.floor(ms / 1000);
|
|
37
|
+
return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function TranscriptionPage({
|
|
41
|
+
state,
|
|
42
|
+
models,
|
|
43
|
+
maxBodyBytes,
|
|
44
|
+
disabled,
|
|
45
|
+
onChange,
|
|
46
|
+
onBusyChange,
|
|
47
|
+
controllers,
|
|
48
|
+
}: Props): JSX.Element {
|
|
49
|
+
const [file, setFile] = useState<File | null>(null);
|
|
50
|
+
const [url, setUrl] = useState("");
|
|
51
|
+
const [recording, setRecording] = useState<RecordingState>("idle");
|
|
52
|
+
const [elapsed, setElapsed] = useState(0);
|
|
53
|
+
const [sending, setSending] = useState(false);
|
|
54
|
+
const [error, setError] = useState<Problem | null>(null);
|
|
55
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
56
|
+
const formRef = useRef<HTMLDivElement>(null);
|
|
57
|
+
const capture = useRef<AudioRecorder | null>(null);
|
|
58
|
+
const request = useRef<AbortController | null>(null);
|
|
59
|
+
const mounted = useRef(true);
|
|
60
|
+
const refocus = useRef(false);
|
|
61
|
+
const maxBytes = audioFileLimit(maxBodyBytes);
|
|
62
|
+
const available = models.filter(
|
|
63
|
+
(id) =>
|
|
64
|
+
id === "whisper-1" || (/^gemini-/i.test(id) && !/image|tts/i.test(id)),
|
|
65
|
+
);
|
|
66
|
+
const selected =
|
|
67
|
+
state.model ||
|
|
68
|
+
(available.includes("whisper-1") ? "whisper-1" : available[0] || "");
|
|
69
|
+
const active = sending || recording !== "idle";
|
|
70
|
+
const locked = disabled || active;
|
|
71
|
+
const canRecord =
|
|
72
|
+
typeof MediaRecorder !== "undefined" &&
|
|
73
|
+
!!navigator.mediaDevices?.getUserMedia &&
|
|
74
|
+
window.isSecureContext;
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
onBusyChange(active);
|
|
78
|
+
}, [active]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
mounted.current = true;
|
|
81
|
+
const recorder = new AudioRecorder({
|
|
82
|
+
maxBytes,
|
|
83
|
+
onState: (value) => {
|
|
84
|
+
if (mounted.current) setRecording(value);
|
|
85
|
+
if (value === "idle") controllers.delete("microphone");
|
|
86
|
+
},
|
|
87
|
+
onFile: (audio) => {
|
|
88
|
+
if (mounted.current) {
|
|
89
|
+
setFile(audio);
|
|
90
|
+
setError(null);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
onError: (text) => {
|
|
94
|
+
if (mounted.current)
|
|
95
|
+
setError({ title: "Couldn't record audio", message: text });
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
capture.current = recorder;
|
|
99
|
+
return () => {
|
|
100
|
+
mounted.current = false;
|
|
101
|
+
recorder.cancel();
|
|
102
|
+
request.current?.abort();
|
|
103
|
+
controllers.delete("microphone");
|
|
104
|
+
controllers.delete("transcription");
|
|
105
|
+
onBusyChange(false);
|
|
106
|
+
};
|
|
107
|
+
}, [maxBytes]);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!file) {
|
|
110
|
+
setUrl("");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const next = URL.createObjectURL(file);
|
|
114
|
+
setUrl(next);
|
|
115
|
+
return () => URL.revokeObjectURL(next);
|
|
116
|
+
}, [file]);
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (recording !== "recording") return;
|
|
119
|
+
const started = Date.now();
|
|
120
|
+
setElapsed(0);
|
|
121
|
+
const timer = setInterval(() => setElapsed(Date.now() - started), 1000);
|
|
122
|
+
return () => clearInterval(timer);
|
|
123
|
+
}, [recording]);
|
|
124
|
+
// Record, Stop, Cancel, Remove and Transcribe hide or disable themselves.
|
|
125
|
+
// When that drops keyboard focus, move it to the next useful control.
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
const root = formRef.current;
|
|
128
|
+
const focused = document.activeElement;
|
|
129
|
+
if (!refocus.current || !root) return;
|
|
130
|
+
// Cancel holds focus only while permission is pending; once recording
|
|
131
|
+
// starts, Enter should stop (and keep) the clip rather than discard it.
|
|
132
|
+
if (recording === "recording" && focused && root.contains(focused)) {
|
|
133
|
+
root
|
|
134
|
+
.querySelector<HTMLElement>(".pg-audio-actions button:not(:disabled)")
|
|
135
|
+
?.focus();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (
|
|
139
|
+
focused &&
|
|
140
|
+
focused !== document.body &&
|
|
141
|
+
!(focused instanceof HTMLButtonElement && focused.disabled)
|
|
142
|
+
)
|
|
143
|
+
return;
|
|
144
|
+
const next =
|
|
145
|
+
sending || (recording === "idle" && file)
|
|
146
|
+
? ".config-actions button:not(:disabled)"
|
|
147
|
+
: ".pg-audio-actions button:not(:disabled)";
|
|
148
|
+
root.querySelector<HTMLElement>(next)?.focus();
|
|
149
|
+
}, [recording, sending, file]);
|
|
150
|
+
// Once the user moves on (clicks or tabs elsewhere), stop pulling focus back.
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const release = (event: Event): void => {
|
|
153
|
+
if (!formRef.current?.contains(event.target as Node))
|
|
154
|
+
refocus.current = false;
|
|
155
|
+
};
|
|
156
|
+
document.addEventListener("pointerdown", release, true);
|
|
157
|
+
document.addEventListener("focusin", release, true);
|
|
158
|
+
return () => {
|
|
159
|
+
document.removeEventListener("pointerdown", release, true);
|
|
160
|
+
document.removeEventListener("focusin", release, true);
|
|
161
|
+
};
|
|
162
|
+
}, []);
|
|
163
|
+
|
|
164
|
+
function selectFile(next: File): void {
|
|
165
|
+
try {
|
|
166
|
+
validateAudioFile(next, maxBytes);
|
|
167
|
+
setFile(next);
|
|
168
|
+
setError(null);
|
|
169
|
+
} catch (err) {
|
|
170
|
+
setError({ title: "Couldn't use this file", message: message(err) });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function startRecording(): void {
|
|
174
|
+
if (!canRecord || locked) return;
|
|
175
|
+
setError(null);
|
|
176
|
+
setFile(null);
|
|
177
|
+
const controller = new AbortController();
|
|
178
|
+
controller.signal.addEventListener(
|
|
179
|
+
"abort",
|
|
180
|
+
() => capture.current?.cancel(),
|
|
181
|
+
{ once: true },
|
|
182
|
+
);
|
|
183
|
+
controllers.set("microphone", controller);
|
|
184
|
+
void capture.current?.start();
|
|
185
|
+
}
|
|
186
|
+
async function transcribe(): Promise<void> {
|
|
187
|
+
if (!file || locked) return;
|
|
188
|
+
if (!available.includes(selected)) {
|
|
189
|
+
setError({
|
|
190
|
+
title: "Transcription failed",
|
|
191
|
+
message: "Choose an enabled audio model.",
|
|
192
|
+
});
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const controller = new AbortController();
|
|
196
|
+
request.current = controller;
|
|
197
|
+
controllers.set("transcription", controller);
|
|
198
|
+
setSending(true);
|
|
199
|
+
setError(null);
|
|
200
|
+
try {
|
|
201
|
+
const result = await transcribeAudio(
|
|
202
|
+
{
|
|
203
|
+
file,
|
|
204
|
+
model: selected,
|
|
205
|
+
language: state.language.trim(),
|
|
206
|
+
prompt: state.prompt,
|
|
207
|
+
maxBodyBytes,
|
|
208
|
+
},
|
|
209
|
+
controller.signal,
|
|
210
|
+
);
|
|
211
|
+
if (mounted.current)
|
|
212
|
+
onChange((current) => ({
|
|
213
|
+
...current,
|
|
214
|
+
model: selected,
|
|
215
|
+
results: [
|
|
216
|
+
{ ...result, id: newId(), createdAt: Date.now() },
|
|
217
|
+
...current.results,
|
|
218
|
+
],
|
|
219
|
+
}));
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (mounted.current)
|
|
222
|
+
setError(
|
|
223
|
+
controller.signal.aborted
|
|
224
|
+
? {
|
|
225
|
+
title: "Transcription cancelled",
|
|
226
|
+
message: "No transcript was saved.",
|
|
227
|
+
}
|
|
228
|
+
: { title: "Transcription failed", message: message(err) },
|
|
229
|
+
);
|
|
230
|
+
} finally {
|
|
231
|
+
controllers.delete("transcription");
|
|
232
|
+
request.current = null;
|
|
233
|
+
if (mounted.current) setSending(false);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const fileName = file && (masked.value ? "Audio file" : file.name);
|
|
238
|
+
const hint = `WAV, MP3, M4A/MP4, WebM, OGG/OGA, FLAC or PCM up to ${(
|
|
239
|
+
maxBytes /
|
|
240
|
+
1024 /
|
|
241
|
+
1024
|
|
242
|
+
).toFixed(1)} MiB. ${
|
|
243
|
+
canRecord
|
|
244
|
+
? `Recording stops after ${pluralize(MAX_RECORDING_MS / 60_000, "minute")}.`
|
|
245
|
+
: "Recording needs HTTPS or localhost and a browser with MediaRecorder support."
|
|
246
|
+
}`;
|
|
247
|
+
const announcement =
|
|
248
|
+
recording === "requesting"
|
|
249
|
+
? "Waiting for microphone permission…"
|
|
250
|
+
: recording === "recording"
|
|
251
|
+
? "Recording"
|
|
252
|
+
: recording === "finalizing"
|
|
253
|
+
? "Preparing recording…"
|
|
254
|
+
: sending
|
|
255
|
+
? "Transcribing…"
|
|
256
|
+
: "";
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
<>
|
|
260
|
+
<Panel
|
|
261
|
+
title="Transcription"
|
|
262
|
+
subtitle="Upload or record audio to transcribe it. Audio isn't saved; only transcripts are."
|
|
263
|
+
>
|
|
264
|
+
<div class="form" ref={formRef}>
|
|
265
|
+
<div class="form-row">
|
|
266
|
+
<label class="field">
|
|
267
|
+
<span class="field-label">Audio model</span>
|
|
268
|
+
<select
|
|
269
|
+
class="select"
|
|
270
|
+
aria-label="Audio model"
|
|
271
|
+
value={selected}
|
|
272
|
+
disabled={locked}
|
|
273
|
+
onChange={(e) =>
|
|
274
|
+
onChange((current) => ({
|
|
275
|
+
...current,
|
|
276
|
+
model: e.currentTarget.value,
|
|
277
|
+
}))
|
|
278
|
+
}
|
|
279
|
+
>
|
|
280
|
+
{!available.length && (
|
|
281
|
+
<option value="">No audio models enabled</option>
|
|
282
|
+
)}
|
|
283
|
+
{state.model && !available.includes(state.model) && (
|
|
284
|
+
<option value={state.model}>
|
|
285
|
+
{state.model} (unavailable)
|
|
286
|
+
</option>
|
|
287
|
+
)}
|
|
288
|
+
{available.map((model) => (
|
|
289
|
+
<option key={model} value={model}>
|
|
290
|
+
{model}
|
|
291
|
+
</option>
|
|
292
|
+
))}
|
|
293
|
+
</select>
|
|
294
|
+
<span class="field-hint">
|
|
295
|
+
Transcription uses Gemini. whisper-1 is a compatibility alias;
|
|
296
|
+
audio support depends on the selected model.
|
|
297
|
+
</span>
|
|
298
|
+
</label>
|
|
299
|
+
<label class="field">
|
|
300
|
+
<span class="field-label">Language (optional)</span>
|
|
301
|
+
<input
|
|
302
|
+
class="input"
|
|
303
|
+
value={state.language}
|
|
304
|
+
maxLength={12}
|
|
305
|
+
placeholder="Auto detect (e.g. es, en)"
|
|
306
|
+
disabled={locked}
|
|
307
|
+
onInput={(e) =>
|
|
308
|
+
onChange((current) => ({
|
|
309
|
+
...current,
|
|
310
|
+
language: e.currentTarget.value,
|
|
311
|
+
}))
|
|
312
|
+
}
|
|
313
|
+
/>
|
|
314
|
+
</label>
|
|
315
|
+
</div>
|
|
316
|
+
<label class="field">
|
|
317
|
+
<span class="field-label">Vocabulary context (optional)</span>
|
|
318
|
+
<textarea
|
|
319
|
+
class="input"
|
|
320
|
+
rows={3}
|
|
321
|
+
maxLength={1000}
|
|
322
|
+
value={state.prompt}
|
|
323
|
+
disabled={locked}
|
|
324
|
+
placeholder="Names, technical terms or other vocabulary to help recognition."
|
|
325
|
+
onInput={(e) =>
|
|
326
|
+
onChange((current) => ({
|
|
327
|
+
...current,
|
|
328
|
+
prompt: e.currentTarget.value,
|
|
329
|
+
}))
|
|
330
|
+
}
|
|
331
|
+
/>
|
|
332
|
+
</label>
|
|
333
|
+
<div class="field">
|
|
334
|
+
<div class="pg-audio-actions">
|
|
335
|
+
{recording === "idle" ? (
|
|
336
|
+
<>
|
|
337
|
+
<Button
|
|
338
|
+
key="upload"
|
|
339
|
+
icon="upload"
|
|
340
|
+
disabled={locked}
|
|
341
|
+
onClick={() => inputRef.current?.click()}
|
|
342
|
+
>
|
|
343
|
+
Upload audio
|
|
344
|
+
</Button>
|
|
345
|
+
<Button
|
|
346
|
+
key="record"
|
|
347
|
+
icon="mic"
|
|
348
|
+
disabled={locked || !canRecord}
|
|
349
|
+
onClick={() => {
|
|
350
|
+
refocus.current = true;
|
|
351
|
+
startRecording();
|
|
352
|
+
}}
|
|
353
|
+
>
|
|
354
|
+
Record
|
|
355
|
+
</Button>
|
|
356
|
+
</>
|
|
357
|
+
) : (
|
|
358
|
+
<>
|
|
359
|
+
{recording === "recording" ? (
|
|
360
|
+
<Pill tone="bad">Recording {clock(elapsed)}</Pill>
|
|
361
|
+
) : (
|
|
362
|
+
<Pill tone="muted">
|
|
363
|
+
{recording === "requesting"
|
|
364
|
+
? "Waiting for microphone permission…"
|
|
365
|
+
: "Preparing recording…"}
|
|
366
|
+
</Pill>
|
|
367
|
+
)}
|
|
368
|
+
{recording === "recording" && (
|
|
369
|
+
<Button
|
|
370
|
+
key="stop"
|
|
371
|
+
onClick={() => {
|
|
372
|
+
refocus.current = true;
|
|
373
|
+
capture.current?.stop();
|
|
374
|
+
}}
|
|
375
|
+
>
|
|
376
|
+
Stop recording
|
|
377
|
+
</Button>
|
|
378
|
+
)}
|
|
379
|
+
<Button
|
|
380
|
+
key="cancel"
|
|
381
|
+
variant="ghost"
|
|
382
|
+
aria-label="Cancel recording"
|
|
383
|
+
onClick={() => {
|
|
384
|
+
refocus.current = true;
|
|
385
|
+
capture.current?.cancel();
|
|
386
|
+
}}
|
|
387
|
+
>
|
|
388
|
+
Cancel
|
|
389
|
+
</Button>
|
|
390
|
+
</>
|
|
391
|
+
)}
|
|
392
|
+
<input
|
|
393
|
+
ref={inputRef}
|
|
394
|
+
class="sr-only"
|
|
395
|
+
type="file"
|
|
396
|
+
accept={AUDIO_ACCEPT}
|
|
397
|
+
aria-label="Audio file"
|
|
398
|
+
disabled={locked}
|
|
399
|
+
onChange={(e) => {
|
|
400
|
+
const next = e.currentTarget.files?.[0];
|
|
401
|
+
e.currentTarget.value = "";
|
|
402
|
+
if (next) selectFile(next);
|
|
403
|
+
}}
|
|
404
|
+
/>
|
|
405
|
+
<span class="sr-only" role="status">
|
|
406
|
+
{announcement}
|
|
407
|
+
</span>
|
|
408
|
+
</div>
|
|
409
|
+
<span class="field-hint">{hint}</span>
|
|
410
|
+
</div>
|
|
411
|
+
{file && (
|
|
412
|
+
<div class="pg-audio-file">
|
|
413
|
+
<div class="pg-audio-file-head">
|
|
414
|
+
<div class="pg-audio-file-name">
|
|
415
|
+
<strong class="truncate" title={fileName ?? undefined}>
|
|
416
|
+
{fileName}
|
|
417
|
+
</strong>
|
|
418
|
+
<div class="cell-sub">
|
|
419
|
+
{(file.size / 1024).toFixed(1)} KiB
|
|
420
|
+
</div>
|
|
421
|
+
</div>
|
|
422
|
+
<Button
|
|
423
|
+
variant="ghost"
|
|
424
|
+
size="sm"
|
|
425
|
+
icon="x"
|
|
426
|
+
iconOnly
|
|
427
|
+
title={`Remove ${fileName}`}
|
|
428
|
+
disabled={locked}
|
|
429
|
+
onClick={() => {
|
|
430
|
+
refocus.current = true;
|
|
431
|
+
setFile(null);
|
|
432
|
+
}}
|
|
433
|
+
>
|
|
434
|
+
{`Remove ${fileName}`}
|
|
435
|
+
</Button>
|
|
436
|
+
</div>
|
|
437
|
+
{url && (
|
|
438
|
+
<audio
|
|
439
|
+
controls
|
|
440
|
+
preload="metadata"
|
|
441
|
+
src={url}
|
|
442
|
+
aria-label="Audio preview"
|
|
443
|
+
/>
|
|
444
|
+
)}
|
|
445
|
+
</div>
|
|
446
|
+
)}
|
|
447
|
+
{error && (
|
|
448
|
+
<div class="callout tone-bad" role="alert">
|
|
449
|
+
<Icon name="critical" size={16} />
|
|
450
|
+
<div>
|
|
451
|
+
<strong>{error.title}</strong>
|
|
452
|
+
<p>{masker.value.text(error.message)}</p>
|
|
453
|
+
</div>
|
|
454
|
+
</div>
|
|
455
|
+
)}
|
|
456
|
+
<div class="config-actions">
|
|
457
|
+
<span class="spacer" />
|
|
458
|
+
{sending && (
|
|
459
|
+
<Button
|
|
460
|
+
variant="ghost"
|
|
461
|
+
onClick={() => {
|
|
462
|
+
refocus.current = true;
|
|
463
|
+
request.current?.abort();
|
|
464
|
+
}}
|
|
465
|
+
>
|
|
466
|
+
Cancel transcription
|
|
467
|
+
</Button>
|
|
468
|
+
)}
|
|
469
|
+
<Button
|
|
470
|
+
variant="primary"
|
|
471
|
+
loading={sending}
|
|
472
|
+
disabled={locked || !file || !available.includes(selected)}
|
|
473
|
+
onClick={() => {
|
|
474
|
+
refocus.current = true;
|
|
475
|
+
void transcribe();
|
|
476
|
+
}}
|
|
477
|
+
>
|
|
478
|
+
{sending ? "Transcribing…" : "Transcribe"}
|
|
479
|
+
</Button>
|
|
480
|
+
</div>
|
|
481
|
+
</div>
|
|
482
|
+
</Panel>
|
|
483
|
+
<Panel title="Transcripts" flush>
|
|
484
|
+
{state.results.length ? (
|
|
485
|
+
<ul class="pg-transcripts">
|
|
486
|
+
{state.results.map((result) => (
|
|
487
|
+
<li key={result.id} class="pg-transcript">
|
|
488
|
+
<div class="pg-transcript-main">
|
|
489
|
+
<strong class="pg-transcript-name">
|
|
490
|
+
{masked.value ? "Transcript" : result.filename}
|
|
491
|
+
</strong>
|
|
492
|
+
<div class="cell-sub">
|
|
493
|
+
{result.model} · {formatDateTime(result.createdAt)} ·{" "}
|
|
494
|
+
{formatMs(result.elapsedMs)}
|
|
495
|
+
</div>
|
|
496
|
+
<p
|
|
497
|
+
class={`pg-transcript-text${result.text ? "" : " muted"}`}
|
|
498
|
+
>
|
|
499
|
+
{result.text
|
|
500
|
+
? masker.value.text(result.text)
|
|
501
|
+
: "No clear speech detected."}
|
|
502
|
+
</p>
|
|
503
|
+
</div>
|
|
504
|
+
<div class="pg-transcript-actions">
|
|
505
|
+
<Button
|
|
506
|
+
variant="ghost"
|
|
507
|
+
size="sm"
|
|
508
|
+
icon="copy"
|
|
509
|
+
onClick={() =>
|
|
510
|
+
void copyText(result.text).then((ok) =>
|
|
511
|
+
toast(
|
|
512
|
+
ok ? "Transcript copied" : "Could not copy transcript",
|
|
513
|
+
ok ? "success" : "error",
|
|
514
|
+
),
|
|
515
|
+
)
|
|
516
|
+
}
|
|
517
|
+
>
|
|
518
|
+
Copy
|
|
519
|
+
</Button>
|
|
520
|
+
<Button
|
|
521
|
+
variant="ghost"
|
|
522
|
+
size="sm"
|
|
523
|
+
icon="download"
|
|
524
|
+
onClick={() =>
|
|
525
|
+
downloadText(
|
|
526
|
+
`transcript-${result.id}.txt`,
|
|
527
|
+
result.text,
|
|
528
|
+
"text/plain;charset=utf-8",
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
>
|
|
532
|
+
Download
|
|
533
|
+
</Button>
|
|
534
|
+
<Button
|
|
535
|
+
variant="ghost"
|
|
536
|
+
size="sm"
|
|
537
|
+
icon="trash"
|
|
538
|
+
iconOnly
|
|
539
|
+
title="Delete transcript"
|
|
540
|
+
disabled={locked}
|
|
541
|
+
onClick={() =>
|
|
542
|
+
onChange((current) => ({
|
|
543
|
+
...current,
|
|
544
|
+
results: current.results.filter(
|
|
545
|
+
(r) => r.id !== result.id,
|
|
546
|
+
),
|
|
547
|
+
}))
|
|
548
|
+
}
|
|
549
|
+
>
|
|
550
|
+
Delete transcript
|
|
551
|
+
</Button>
|
|
552
|
+
</div>
|
|
553
|
+
</li>
|
|
554
|
+
))}
|
|
555
|
+
</ul>
|
|
556
|
+
) : (
|
|
557
|
+
<EmptyState icon="mic" title="No transcripts yet" />
|
|
558
|
+
)}
|
|
559
|
+
</Panel>
|
|
560
|
+
</>
|
|
561
|
+
);
|
|
562
|
+
}
|
package/src/web/state/api.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AccessReport } from "../../model-access-api.js";
|
|
1
2
|
// Typed client for the admin API. Auth rides on the HttpOnly session cookie,
|
|
2
3
|
// so no token is ever handled in page JavaScript.
|
|
3
4
|
|
|
@@ -33,6 +34,8 @@ export function setUnauthorizedHandler(handler: () => void): void {
|
|
|
33
34
|
onUnauthorized = handler;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
export function notifyUnauthorized(): void { onUnauthorized(); }
|
|
38
|
+
|
|
36
39
|
function messageFrom(body: unknown): string | null {
|
|
37
40
|
if (!body || typeof body !== "object") return null;
|
|
38
41
|
const record = body as Record<string, unknown>;
|
|
@@ -136,6 +139,7 @@ function query(params: Record<string, string | number | undefined>): string {
|
|
|
136
139
|
}
|
|
137
140
|
|
|
138
141
|
export const api = {
|
|
142
|
+
playgroundConfig: () => request<{ maxBodyBytes: number }>("GET", "/api/playground/config"),
|
|
139
143
|
session: () => request<SessionInfo>("GET", "/api/session", undefined, { ignoreUnauthorized: true }),
|
|
140
144
|
signIn: (token: string) =>
|
|
141
145
|
request<{ ok: true }>("POST", "/api/session", { token }, { ignoreUnauthorized: true }),
|
|
@@ -186,6 +190,8 @@ export const api = {
|
|
|
186
190
|
deleteKey: (hash: string) => request("DELETE", `/api/keys/${enc(hash)}`),
|
|
187
191
|
models: () => request<{ ok: true; data: ModelCatalogEntry[] }>("GET", "/api/models"),
|
|
188
192
|
|
|
193
|
+
declareProviderPlan: (accountId: string, provider: string, plan: string) => request<AccessReport>("PUT", "/api/model-access/plan", { accountId, provider, plan }),
|
|
194
|
+
modelAccess: (params = new URLSearchParams()) => request<AccessReport>("GET", `/api/model-access?${params}`),
|
|
189
195
|
catalog: () => request<ModelCatalogResponse>("GET", "/api/catalog"),
|
|
190
196
|
refreshCatalog: () => request<ModelCatalogResponse>("POST", "/api/catalog/refresh"),
|
|
191
197
|
setProviderEnabled: (id: string, on: boolean) =>
|