tuxevil-rotator 4.3.0 → 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.
Files changed (59) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +4 -2
  3. package/package.json +2 -1
  4. package/src/access-evidence.ts +153 -0
  5. package/src/access-probe.ts +85 -0
  6. package/src/admin-auth.ts +4 -1
  7. package/src/auto-access-shadow.ts +11 -0
  8. package/src/auto-model-access.ts +185 -0
  9. package/src/auto-output-health.ts +12 -0
  10. package/src/auto-routing-evaluation.ts +80 -0
  11. package/src/auto-routing-quality.ts +308 -0
  12. package/src/auto-routing.ts +403 -26
  13. package/src/compat.ts +223 -36
  14. package/src/compression/index.ts +6 -6
  15. package/src/compression/lite.ts +3 -9
  16. package/src/compression/rtk/index.ts +0 -3
  17. package/src/config-defaults.ts +7 -0
  18. package/src/dashboard.ts +5 -0
  19. package/src/db-store.ts +10 -0
  20. package/src/index.ts +2 -0
  21. package/src/model-access-api.ts +74 -0
  22. package/src/model-access.ts +56 -0
  23. package/src/ollama-output-gate.ts +18 -0
  24. package/src/onboarding.ts +1 -1
  25. package/src/provider-catalog-evidence.ts +26 -0
  26. package/src/providers/google-antigravity/dynamic-catalog.ts +8 -0
  27. package/src/providers/google-antigravity/quota.ts +3 -0
  28. package/src/providers/ollama/context-window.ts +13 -0
  29. package/src/providers/ollama/quota.ts +4 -0
  30. package/src/providers/ollama/translators.ts +19 -2
  31. package/src/providers/openai-codex/compat.ts +5 -1
  32. package/src/providers/openai-codex/credentials.ts +22 -6
  33. package/src/providers/openai-codex/index.ts +9 -1
  34. package/src/providers/openai-codex/quota.ts +19 -6
  35. package/src/providers/opencode-zen/forward.ts +1 -1
  36. package/src/providers/opencode-zen/quota.ts +2 -0
  37. package/src/proxy.ts +78 -3
  38. package/src/quota-observation.ts +26 -0
  39. package/src/quota-pools.ts +322 -0
  40. package/src/rotator.ts +151 -38
  41. package/src/settings-repository.ts +1 -0
  42. package/src/types.ts +28 -0
  43. package/src/usage-limits-auth.ts +24 -0
  44. package/src/usage-limits.ts +148 -0
  45. package/src/validators.ts +26 -0
  46. package/src/web/components/icons.tsx +15 -0
  47. package/src/web/components/overlays.tsx +4 -0
  48. package/src/web/components/ui.tsx +9 -9
  49. package/src/web/lib/playground.ts +35 -0
  50. package/src/web/lib/pool-navigation.ts +4 -0
  51. package/src/web/lib/pools.ts +2 -243
  52. package/src/web/pages/AccountDetail.tsx +2 -1
  53. package/src/web/pages/ModelAccess.tsx +88 -0
  54. package/src/web/pages/Models.tsx +2 -0
  55. package/src/web/pages/Overview.tsx +26 -9
  56. package/src/web/pages/Playground.tsx +1132 -551
  57. package/src/web/pages/Transcription.tsx +304 -170
  58. package/src/web/state/api.ts +3 -0
  59. package/src/web/styles/app.css +501 -45
@@ -1,6 +1,7 @@
1
1
  import type { JSX } from "preact";
2
2
  import { useEffect, useRef, useState } from "preact/hooks";
3
- import { Button, Panel, Pill } from "../components/ui.js";
3
+ import { Button, EmptyState, Panel, Pill } from "../components/ui.js";
4
+ import { Icon } from "../components/icons.js";
4
5
  import { copyText, downloadText } from "./shared.js";
5
6
  import { toast } from "../state/actions.js";
6
7
  import { masked, masker } from "../state/store.js";
@@ -14,7 +15,7 @@ import {
14
15
  validateAudioFile,
15
16
  type RecordingState,
16
17
  } from "../lib/audio-recorder.js";
17
- import { formatMs } from "../lib/format.js";
18
+ import { formatDateTime, formatMs, pluralize } from "../lib/format.js";
18
19
 
19
20
  interface Props {
20
21
  state: TranscriptionState;
@@ -25,6 +26,17 @@ interface Props {
25
26
  onBusyChange: (busy: boolean) => void;
26
27
  controllers: Map<string, AbortController>;
27
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
+
28
40
  export function TranscriptionPage({
29
41
  state,
30
42
  models,
@@ -39,11 +51,13 @@ export function TranscriptionPage({
39
51
  const [recording, setRecording] = useState<RecordingState>("idle");
40
52
  const [elapsed, setElapsed] = useState(0);
41
53
  const [sending, setSending] = useState(false);
42
- const [error, setError] = useState("");
54
+ const [error, setError] = useState<Problem | null>(null);
43
55
  const inputRef = useRef<HTMLInputElement>(null);
56
+ const formRef = useRef<HTMLDivElement>(null);
44
57
  const capture = useRef<AudioRecorder | null>(null);
45
58
  const request = useRef<AbortController | null>(null);
46
59
  const mounted = useRef(true);
60
+ const refocus = useRef(false);
47
61
  const maxBytes = audioFileLimit(maxBodyBytes);
48
62
  const available = models.filter(
49
63
  (id) =>
@@ -73,11 +87,12 @@ export function TranscriptionPage({
73
87
  onFile: (audio) => {
74
88
  if (mounted.current) {
75
89
  setFile(audio);
76
- setError("");
90
+ setError(null);
77
91
  }
78
92
  },
79
- onError: (message) => {
80
- if (mounted.current) setError(message);
93
+ onError: (text) => {
94
+ if (mounted.current)
95
+ setError({ title: "Couldn't record audio", message: text });
81
96
  },
82
97
  });
83
98
  capture.current = recorder;
@@ -106,19 +121,58 @@ export function TranscriptionPage({
106
121
  const timer = setInterval(() => setElapsed(Date.now() - started), 1000);
107
122
  return () => clearInterval(timer);
108
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
+ }, []);
109
163
 
110
164
  function selectFile(next: File): void {
111
165
  try {
112
166
  validateAudioFile(next, maxBytes);
113
167
  setFile(next);
114
- setError("");
168
+ setError(null);
115
169
  } catch (err) {
116
- setError(err instanceof Error ? err.message : String(err));
170
+ setError({ title: "Couldn't use this file", message: message(err) });
117
171
  }
118
172
  }
119
173
  function startRecording(): void {
120
174
  if (!canRecord || locked) return;
121
- setError("");
175
+ setError(null);
122
176
  setFile(null);
123
177
  const controller = new AbortController();
124
178
  controller.signal.addEventListener(
@@ -132,14 +186,17 @@ export function TranscriptionPage({
132
186
  async function transcribe(): Promise<void> {
133
187
  if (!file || locked) return;
134
188
  if (!available.includes(selected)) {
135
- setError("Choose an enabled audio model.");
189
+ setError({
190
+ title: "Transcription failed",
191
+ message: "Choose an enabled audio model.",
192
+ });
136
193
  return;
137
194
  }
138
195
  const controller = new AbortController();
139
196
  request.current = controller;
140
197
  controllers.set("transcription", controller);
141
198
  setSending(true);
142
- setError("");
199
+ setError(null);
143
200
  try {
144
201
  const result = await transcribeAudio(
145
202
  {
@@ -162,7 +219,14 @@ export function TranscriptionPage({
162
219
  }));
163
220
  } catch (err) {
164
221
  if (mounted.current)
165
- setError(err instanceof Error ? err.message : String(err));
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
+ );
166
230
  } finally {
167
231
  controllers.delete("transcription");
168
232
  request.current = null;
@@ -170,18 +234,39 @@ export function TranscriptionPage({
170
234
  }
171
235
  }
172
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
+
173
258
  return (
174
- <div class="pg-transcription">
259
+ <>
175
260
  <Panel
176
261
  title="Transcription"
177
- subtitle="Upload an audio file or record with this device's microphone, then preview and send it to the rotator."
262
+ subtitle="Upload or record audio to transcribe it. Audio isn't saved; only transcripts are."
178
263
  >
179
- <div class="form">
180
- <div class="form-grid">
264
+ <div class="form" ref={formRef}>
265
+ <div class="form-row">
181
266
  <label class="field">
182
267
  <span class="field-label">Audio model</span>
183
268
  <select
184
- class="input"
269
+ class="select"
185
270
  aria-label="Audio model"
186
271
  value={selected}
187
272
  disabled={locked}
@@ -231,8 +316,8 @@ export function TranscriptionPage({
231
316
  <label class="field">
232
317
  <span class="field-label">Vocabulary context (optional)</span>
233
318
  <textarea
234
- class="input pg-audio-context"
235
- rows={2}
319
+ class="input"
320
+ rows={3}
236
321
  maxLength={1000}
237
322
  value={state.prompt}
238
323
  disabled={locked}
@@ -245,85 +330,108 @@ export function TranscriptionPage({
245
330
  }
246
331
  />
247
332
  </label>
248
- <div class="pg-toolbar">
249
- <Button
250
- icon="upload"
251
- disabled={locked}
252
- onClick={() => inputRef.current?.click()}
253
- >
254
- Upload audio
255
- </Button>
256
- <input
257
- ref={inputRef}
258
- class="sr-only"
259
- type="file"
260
- accept={AUDIO_ACCEPT}
261
- aria-label="Audio file"
262
- disabled={locked}
263
- onChange={(e) => {
264
- const next = e.currentTarget.files?.[0];
265
- e.currentTarget.value = "";
266
- if (next) selectFile(next);
267
- }}
268
- />
269
- <Button
270
- icon="play"
271
- disabled={locked || !canRecord}
272
- onClick={startRecording}
273
- >
274
- Record microphone
275
- </Button>
276
- {recording === "recording" && (
277
- <>
278
- <Pill tone="bad">
279
- Recording · {Math.floor(elapsed / 60_000)}:
280
- {String(Math.floor(elapsed / 1000) % 60).padStart(2, "0")}
281
- </Pill>
282
- <Button
283
- variant="primary"
284
- onClick={() => capture.current?.stop()}
285
- >
286
- Stop recording
287
- </Button>
288
- </>
289
- )}
290
- {recording === "requesting" && (
291
- <span role="status">Waiting for microphone permission…</span>
292
- )}
293
- {recording === "finalizing" && (
294
- <span role="status">Preparing recording…</span>
295
- )}
296
- {recording !== "idle" && (
297
- <Button
298
- variant="danger"
299
- onClick={() => capture.current?.cancel()}
300
- >
301
- Cancel recording
302
- </Button>
303
- )}
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>
304
410
  </div>
305
- {!canRecord && (
306
- <p class="field-hint">
307
- Microphone recording requires HTTPS or localhost and a browser
308
- with MediaRecorder support. You can still upload an audio file.
309
- </p>
310
- )}
311
- <p class="field-hint">
312
- WAV, MP3, M4A/MP4, WebM, OGG/OGA, FLAC or PCM. Up to{" "}
313
- {(maxBytes / 1024 / 1024).toFixed(1)} MiB per file. Recording stops
314
- automatically after {MAX_RECORDING_MS / 60_000} minutes.
315
- </p>
316
411
  {file && (
317
- <div class="pg-audio-preview">
318
- <div class="pg-toolbar">
319
- <strong>{masked.value ? "Audio file" : file.name}</strong>
320
- <span class="muted">{(file.size / 1024).toFixed(1)} KiB</span>
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>
321
422
  <Button
423
+ variant="ghost"
322
424
  size="sm"
425
+ icon="x"
426
+ iconOnly
427
+ title={`Remove ${fileName}`}
323
428
  disabled={locked}
324
- onClick={() => setFile(null)}
429
+ onClick={() => {
430
+ refocus.current = true;
431
+ setFile(null);
432
+ }}
325
433
  >
326
- Remove audio
434
+ {`Remove ${fileName}`}
327
435
  </Button>
328
436
  </div>
329
437
  {url && (
@@ -337,92 +445,118 @@ export function TranscriptionPage({
337
445
  </div>
338
446
  )}
339
447
  {error && (
340
- <p class="form-error" role="alert">
341
- {masker.value.text(error)}
342
- </p>
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>
343
455
  )}
344
- <div class="pg-toolbar">
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
+ )}
345
469
  <Button
346
470
  variant="primary"
471
+ loading={sending}
347
472
  disabled={locked || !file || !available.includes(selected)}
348
- onClick={() => void transcribe()}
473
+ onClick={() => {
474
+ refocus.current = true;
475
+ void transcribe();
476
+ }}
349
477
  >
350
- Transcribe
478
+ {sending ? "Transcribing…" : "Transcribe"}
351
479
  </Button>
352
- {sending && (
353
- <>
354
- <span role="status">Transcribing…</span>
355
- <Button
356
- variant="danger"
357
- onClick={() => request.current?.abort()}
358
- >
359
- Cancel transcription
360
- </Button>
361
- </>
362
- )}
363
480
  </div>
364
- <p class="field-hint">
365
- Audio is sent only when you press Transcribe. Only results and
366
- settings are saved in local history; audio files and recordings stay
367
- in this tab.
368
- </p>
369
481
  </div>
370
482
  </Panel>
371
- {state.results.map((result) => (
372
- <Panel
373
- key={result.id}
374
- title={masked.value ? "Transcript" : result.filename}
375
- subtitle={`${result.model} · ${new Date(result.createdAt).toLocaleString()} · ${formatMs(result.elapsedMs)}`}
376
- actions={
377
- <>
378
- <Button
379
- size="sm"
380
- onClick={() =>
381
- void copyText(result.text).then((ok) =>
382
- toast(
383
- ok ? "Transcript copied" : "Could not copy transcript",
384
- ok ? "success" : "error",
385
- ),
386
- )
387
- }
388
- >
389
- Copy text
390
- </Button>
391
- <Button
392
- size="sm"
393
- icon="download"
394
- onClick={() =>
395
- downloadText(
396
- `transcript-${result.id}.txt`,
397
- result.text,
398
- "text/plain;charset=utf-8",
399
- )
400
- }
401
- >
402
- Download text
403
- </Button>
404
- <Button
405
- size="sm"
406
- disabled={locked}
407
- onClick={() =>
408
- onChange((current) => ({
409
- ...current,
410
- results: current.results.filter((r) => r.id !== result.id),
411
- }))
412
- }
413
- >
414
- Delete result
415
- </Button>
416
- </>
417
- }
418
- >
419
- <pre class="pg-answer">
420
- {result.text
421
- ? masker.value.text(result.text)
422
- : "No clear speech detected."}
423
- </pre>
424
- </Panel>
425
- ))}
426
- </div>
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
+ </>
427
561
  );
428
562
  }
@@ -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
 
@@ -189,6 +190,8 @@ export const api = {
189
190
  deleteKey: (hash: string) => request("DELETE", `/api/keys/${enc(hash)}`),
190
191
  models: () => request<{ ok: true; data: ModelCatalogEntry[] }>("GET", "/api/models"),
191
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}`),
192
195
  catalog: () => request<ModelCatalogResponse>("GET", "/api/catalog"),
193
196
  refreshCatalog: () => request<ModelCatalogResponse>("POST", "/api/catalog/refresh"),
194
197
  setProviderEnabled: (id: string, on: boolean) =>