tuxevil-rotator 4.2.2 → 4.3.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 (39) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +9 -4
  3. package/package.json +1 -1
  4. package/plugins/opencode-discovery/capabilities.d.mts +7 -0
  5. package/plugins/opencode-discovery/capabilities.mjs +54 -0
  6. package/plugins/opencode-discovery/index.d.mts +2 -1
  7. package/plugins/opencode-discovery/index.mjs +6 -1
  8. package/plugins/opencode-discovery/package.json +3 -1
  9. package/src/audio-transcription.ts +32 -6
  10. package/src/cli.ts +3 -3
  11. package/src/compat/model-specs.ts +4 -0
  12. package/src/compat.ts +30 -1
  13. package/src/dashboard-app.ts +1 -0
  14. package/src/install-agent.ts +211 -129
  15. package/src/install-opencode.ts +80 -18
  16. package/src/providers/google-antigravity/catalog.ts +14 -6
  17. package/src/providers/google-antigravity/dynamic-catalog.ts +79 -3
  18. package/src/providers/google-antigravity/forward.ts +4 -2
  19. package/src/providers/google-antigravity/quota.ts +4 -0
  20. package/src/providers/ollama/forward.ts +10 -0
  21. package/src/providers/openai-codex/catalog.ts +157 -18
  22. package/src/proxy.ts +35 -2
  23. package/src/rotator.ts +16 -2
  24. package/src/types.ts +78 -29
  25. package/src/web/app.tsx +4 -0
  26. package/src/web/lib/audio-recorder.ts +159 -0
  27. package/src/web/lib/colors.ts +4 -0
  28. package/src/web/lib/playground-storage.ts +261 -0
  29. package/src/web/lib/playground.ts +448 -0
  30. package/src/web/nav.ts +1 -0
  31. package/src/web/pages/Playground.tsx +1111 -0
  32. package/src/web/pages/Transcription.tsx +428 -0
  33. package/src/web/state/api.ts +3 -0
  34. package/src/web/state/playground-client.ts +136 -0
  35. package/src/web/state/playground.ts +69 -0
  36. package/src/web/state/router.ts +2 -2
  37. package/src/web/state/transcription-client.ts +93 -0
  38. package/src/web/styles/app.css +45 -0
  39. package/tools/telemetry-receiver/receiver.js +59 -46
@@ -0,0 +1,159 @@
1
+ // Browser capture with explicit ownership: every exit releases the microphone.
2
+ export type RecordingState = "idle" | "requesting" | "recording" | "finalizing";
3
+ export const MAX_RECORDING_MS = 5 * 60_000;
4
+ export const AUDIO_ACCEPT = "audio/*,.wav,.mp3,.m4a,.mp4,.webm,.ogg,.oga,.flac,.pcm";
5
+ export function audioFileLimit(maxBodyBytes: number): number {
6
+ return Math.max(0, maxBodyBytes - 64 * 1024);
7
+ }
8
+ export function validateAudioFile(file: File, maxBytes: number): void {
9
+ if (!file.size) throw new Error("The audio file is empty.");
10
+ if (file.size > maxBytes)
11
+ throw new Error(
12
+ `Audio exceeds the ${(maxBytes / 1024 / 1024).toFixed(1)} MiB upload limit.`,
13
+ );
14
+ if (!/\.(wav|mp3|m4a|mp4|webm|ogg|oga|flac|pcm)$/i.test(file.name))
15
+ throw new Error("Choose WAV, MP3, M4A/MP4, WebM, OGG/OGA, FLAC or PCM audio.");
16
+ }
17
+ export function microphoneError(error: unknown): string {
18
+ const name = error instanceof Error ? error.name : "";
19
+ if (name === "NotAllowedError" || name === "SecurityError")
20
+ return "Microphone permission was denied. Allow microphone access in your browser settings, or upload an audio file.";
21
+ if (name === "NotFoundError")
22
+ return "No microphone was found on this device. You can upload an audio file instead.";
23
+ if (name === "NotReadableError")
24
+ return "The microphone is unavailable or in use by another application.";
25
+ return error instanceof Error ? error.message : String(error);
26
+ }
27
+ export interface RecorderOptions {
28
+ maxBytes: number;
29
+ maxDurationMs?: number;
30
+ onState: (state: RecordingState) => void;
31
+ onFile: (file: File) => void;
32
+ onError: (message: string) => void;
33
+ openMicrophone?: () => Promise<MediaStream>;
34
+ makeRecorder?: (stream: MediaStream) => MediaRecorder;
35
+ }
36
+ export function browserRecorder(stream: MediaStream): MediaRecorder {
37
+ const mimeType = [
38
+ "audio/webm;codecs=opus",
39
+ "audio/mp4",
40
+ "audio/ogg;codecs=opus",
41
+ ].find((type) => MediaRecorder.isTypeSupported(type));
42
+ return new MediaRecorder(stream, mimeType ? { mimeType } : undefined);
43
+ }
44
+ export class AudioRecorder {
45
+ private generation = 0;
46
+ private recorder: MediaRecorder | null = null;
47
+ private stream: MediaStream | null = null;
48
+ private timer: ReturnType<typeof setTimeout> | undefined;
49
+ private state: RecordingState = "idle";
50
+ constructor(private readonly options: RecorderOptions) {}
51
+ private change(state: RecordingState): void {
52
+ this.state = state;
53
+ this.options.onState(state);
54
+ }
55
+ private release(): void {
56
+ clearTimeout(this.timer);
57
+ this.stream?.getTracks().forEach((track) => track.stop());
58
+ this.stream = null;
59
+ }
60
+ async start(): Promise<void> {
61
+ if (this.state !== "idle") return;
62
+ const generation = ++this.generation;
63
+ this.change("requesting");
64
+ try {
65
+ const stream = await (
66
+ this.options.openMicrophone ??
67
+ (() => navigator.mediaDevices.getUserMedia({ audio: true }))
68
+ )();
69
+ // Permission can resolve after a tab switch or Cancel. Never retain that stream.
70
+ if (generation !== this.generation) {
71
+ stream.getTracks().forEach((track) => track.stop());
72
+ return;
73
+ }
74
+ this.stream = stream;
75
+ const recorder = (this.options.makeRecorder ?? browserRecorder)(stream);
76
+ this.recorder = recorder;
77
+ const chunks: Blob[] = [];
78
+ let bytes = 0;
79
+ recorder.ondataavailable = (event) => {
80
+ if (generation !== this.generation || !event.data.size) return;
81
+ bytes += event.data.size;
82
+ if (bytes > this.options.maxBytes) {
83
+ this.cancel();
84
+ this.options.onError(
85
+ "Recording exceeded the upload limit. Record a shorter clip.",
86
+ );
87
+ return;
88
+ }
89
+ chunks.push(event.data);
90
+ };
91
+ recorder.onerror = () => {
92
+ if (generation === this.generation) {
93
+ this.cancel();
94
+ this.options.onError(
95
+ "Recording failed. Check your microphone or upload an audio file.",
96
+ );
97
+ }
98
+ };
99
+ recorder.onstop = () => {
100
+ if (generation !== this.generation) return;
101
+ this.recorder = null;
102
+ this.release();
103
+ this.change("idle");
104
+ const type = chunks[0]?.type || recorder.mimeType || "audio/webm";
105
+ const blob = new Blob(chunks, { type });
106
+ if (!blob.size) {
107
+ this.options.onError("The recording is empty. Try recording again.");
108
+ return;
109
+ }
110
+ const extension = /mp4|aac/i.test(type)
111
+ ? "m4a"
112
+ : /ogg/i.test(type)
113
+ ? "ogg"
114
+ : "webm";
115
+ this.options.onFile(
116
+ new File([blob], `recording-${Date.now()}.${extension}`, { type }),
117
+ );
118
+ };
119
+ recorder.start(1000);
120
+ this.change("recording");
121
+ this.timer = setTimeout(
122
+ () => this.stop(),
123
+ this.options.maxDurationMs ?? MAX_RECORDING_MS,
124
+ );
125
+ } catch (err) {
126
+ if (generation !== this.generation) return;
127
+ this.cancel();
128
+ this.options.onError(microphoneError(err));
129
+ }
130
+ }
131
+ stop(): void {
132
+ if (!this.recorder || this.state !== "recording") return;
133
+ this.change("finalizing");
134
+ try {
135
+ this.recorder.stop();
136
+ } catch (err) {
137
+ this.cancel();
138
+ this.options.onError(microphoneError(err));
139
+ }
140
+ this.release();
141
+ }
142
+ cancel(): void {
143
+ ++this.generation;
144
+ const recorder = this.recorder;
145
+ this.recorder = null;
146
+ if (recorder) {
147
+ recorder.ondataavailable = null;
148
+ recorder.onstop = null;
149
+ recorder.onerror = null;
150
+ try {
151
+ if (recorder.state !== "inactive") recorder.stop();
152
+ } catch {
153
+ /* release tracks even if the browser recorder failed */
154
+ }
155
+ }
156
+ this.release();
157
+ this.change("idle");
158
+ }
159
+ }
@@ -24,6 +24,10 @@ const MODEL_COLORS: Record<string, string> = {
24
24
  "gemini-3.6-flash-medium": "#38bdf8",
25
25
  "gemini-3.6-flash-low": "#38bdf8",
26
26
  "gemini-3.6-flash-tiered": "#38bdf8",
27
+ "gemini-4-argon": "#2563eb",
28
+ "gemini-4-argon-high": "#2563eb",
29
+ "gemini-4-argon-medium": "#3b82f6",
30
+ "gemini-4-argon-low": "#60a5fa",
27
31
  "gemini-3.8-flash-high": "#0284c7",
28
32
  "gemini-3.8-flash-medium": "#0284c7",
29
33
  "gemini-3.8-flash-low": "#0284c7",
@@ -0,0 +1,261 @@
1
+ import {
2
+ CASES,
3
+ record,
4
+ newTranscription,
5
+ type PlaygroundDocument,
6
+ } from "./playground.js";
7
+
8
+ export interface PlaygroundWorkspace {
9
+ version: 1;
10
+ currentId: string;
11
+ documents: PlaygroundDocument[];
12
+ }
13
+ const CASE_IDS = new Set(CASES.map((c) => c.id));
14
+ const imageUrl = (value: unknown): boolean =>
15
+ typeof value === "string" &&
16
+ /^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(value);
17
+ const finite = (v: unknown): boolean =>
18
+ typeof v === "number" && Number.isFinite(v) && v >= 0;
19
+ const nullableNumber = (v: unknown): boolean => v === null || finite(v);
20
+ const text = (v: unknown): v is string => typeof v === "string";
21
+ function content(v: unknown): boolean {
22
+ return (
23
+ v === null ||
24
+ text(v) ||
25
+ (Array.isArray(v) &&
26
+ v.every(
27
+ (p) =>
28
+ record(p) &&
29
+ ((p.type === "text" && text(p.text)) ||
30
+ (p.type === "image_url" &&
31
+ record(p.image_url) &&
32
+ imageUrl(p.image_url.url))),
33
+ ))
34
+ );
35
+ }
36
+ function tools(v: unknown): boolean {
37
+ return (
38
+ Array.isArray(v) &&
39
+ v.every(
40
+ (t) =>
41
+ record(t) &&
42
+ text(t.id) &&
43
+ t.type === "function" &&
44
+ record(t.function) &&
45
+ text(t.function.name) &&
46
+ text(t.function.arguments),
47
+ )
48
+ );
49
+ }
50
+ function request(v: unknown): boolean {
51
+ return (
52
+ record(v) &&
53
+ text(v.model) &&
54
+ typeof v.stream === "boolean" &&
55
+ Array.isArray(v.messages) &&
56
+ v.messages.length > 0 &&
57
+ v.messages.every(
58
+ (m) =>
59
+ record(m) &&
60
+ ["user", "system", "assistant"].includes(String(m.role)) &&
61
+ content(m.content) &&
62
+ (m.tool_calls === undefined || tools(m.tool_calls)),
63
+ )
64
+ );
65
+ }
66
+ function result(v: unknown): boolean {
67
+ return (
68
+ v === null ||
69
+ (record(v) &&
70
+ text(v.content) &&
71
+ text(v.reasoning) &&
72
+ tools(v.tools) &&
73
+ finite(v.durationMs) &&
74
+ nullableNumber(v.firstContentMs) &&
75
+ nullableNumber(v.inputTokens) &&
76
+ nullableNumber(v.outputTokens) &&
77
+ (v.finishReason === null || text(v.finishReason)) &&
78
+ record(v.metadata) &&
79
+ Object.values(v.metadata).every(text) &&
80
+ Array.isArray(v.raw) &&
81
+ typeof v.done === "boolean" &&
82
+ finite(v.status))
83
+ );
84
+ }
85
+ function turn(v: unknown): boolean {
86
+ return (
87
+ record(v) &&
88
+ request(v.request) &&
89
+ result(v.result) &&
90
+ (v.error === undefined || text(v.error))
91
+ );
92
+ }
93
+ function panel(v: unknown): boolean {
94
+ return (
95
+ record(v) &&
96
+ text(v.id) &&
97
+ text(v.model) &&
98
+ record(v.params) &&
99
+ ["system", "temperature", "maxTokens", "effort", "tools"].every((k) =>
100
+ text(v.params && (v.params as Record<string, unknown>)[k]),
101
+ ) &&
102
+ typeof v.params.stream === "boolean" &&
103
+ Array.isArray(v.turns) &&
104
+ v.turns.every(turn)
105
+ );
106
+ }
107
+ function transcription(value: unknown): boolean {
108
+ return (
109
+ value === undefined ||
110
+ (record(value) &&
111
+ text(value.model) &&
112
+ text(value.language) &&
113
+ text(value.prompt) &&
114
+ Array.isArray(value.results) &&
115
+ value.results.every(
116
+ (r) =>
117
+ record(r) &&
118
+ text(r.id) &&
119
+ text(r.filename) &&
120
+ text(r.model) &&
121
+ text(r.language) &&
122
+ text(r.prompt) &&
123
+ text(r.text) &&
124
+ finite(r.elapsedMs) &&
125
+ finite(r.createdAt),
126
+ ))
127
+ );
128
+ }
129
+ /** Validate imports before any UI or request-building code sees them. Never run imports. */
130
+ export function parsePlaygroundDocument(input: unknown): PlaygroundDocument {
131
+ if (
132
+ !record(input) ||
133
+ input.version !== 1 ||
134
+ !text(input.id) ||
135
+ !input.id ||
136
+ !text(input.title) ||
137
+ !finite(input.updatedAt) ||
138
+ !panel(input.chat) ||
139
+ !transcription(input.transcription) ||
140
+ !Array.isArray(input.compare) ||
141
+ input.compare.length < 2 ||
142
+ input.compare.length > 3 ||
143
+ !input.compare.every(panel) ||
144
+ new Set(input.compare.map((p) => (p as { id: string }).id)).size !==
145
+ input.compare.length ||
146
+ typeof input.sync !== "boolean" ||
147
+ !text(input.draft) ||
148
+ !Array.isArray(input.images) ||
149
+ !input.images.every((i) => record(i) && text(i.name) && imageUrl(i.url)) ||
150
+ !Array.isArray(input.complianceModels) ||
151
+ input.complianceModels.length > 3 ||
152
+ !input.complianceModels.every(text) ||
153
+ !Array.isArray(input.cases) ||
154
+ !input.cases.every((c) => CASE_IDS.has(c)) ||
155
+ !Array.isArray(input.results) ||
156
+ !input.results.every(
157
+ (r) =>
158
+ record(r) &&
159
+ text(r.model) &&
160
+ CASE_IDS.has(r.caseId as never) &&
161
+ ["passed", "failed", "unsupported", "error", "cancelled"].includes(
162
+ String(r.verdict),
163
+ ) &&
164
+ text(r.explanation) &&
165
+ turn(r.turn),
166
+ )
167
+ ) {
168
+ throw new Error(
169
+ "Invalid playground file or unsupported version. Expected a version 1 playground export.",
170
+ );
171
+ }
172
+ const doc = input as unknown as PlaygroundDocument;
173
+ const restorePanel = (p: typeof doc.chat) => ({
174
+ ...p,
175
+ turns: p.turns.map((t) =>
176
+ !t.error && !t.result?.done
177
+ ? {
178
+ ...t,
179
+ error:
180
+ "Interrupted before completion. Retry this turn to send it again.",
181
+ }
182
+ : t,
183
+ ),
184
+ });
185
+ return {
186
+ ...doc,
187
+ transcription: doc.transcription ?? newTranscription(),
188
+ chat: restorePanel(doc.chat),
189
+ compare: doc.compare.map(restorePanel),
190
+ };
191
+ }
192
+
193
+ let database: Promise<IDBDatabase> | undefined;
194
+ function openDatabase(): Promise<IDBDatabase> {
195
+ database ??= new Promise((resolve, reject) => {
196
+ if (typeof indexedDB === "undefined") {
197
+ reject(new Error("Local storage is unavailable."));
198
+ return;
199
+ }
200
+ const req = indexedDB.open("tuxevil-playground", 1);
201
+ req.onupgradeneeded = () => {
202
+ req.result.createObjectStore("workspace");
203
+ };
204
+ req.onerror = () => reject(req.error);
205
+ req.onblocked = () =>
206
+ reject(new Error("Close other dashboard tabs to open local history."));
207
+ req.onsuccess = () => {
208
+ req.result.onversionchange = () => req.result.close();
209
+ resolve(req.result);
210
+ };
211
+ });
212
+ return database;
213
+ }
214
+ export async function readWorkspace(): Promise<PlaygroundWorkspace | null> {
215
+ const db = await openDatabase();
216
+ return new Promise((resolve, reject) => {
217
+ const tx = db.transaction("workspace", "readonly");
218
+ const req = tx.objectStore("workspace").get("current");
219
+ req.onsuccess = () => {
220
+ try {
221
+ const value: unknown = req.result;
222
+ if (value === undefined) {
223
+ resolve(null);
224
+ return;
225
+ }
226
+ if (
227
+ !record(value) ||
228
+ value.version !== 1 ||
229
+ !text(value.currentId) ||
230
+ !Array.isArray(value.documents)
231
+ )
232
+ throw new Error("Invalid local playground history.");
233
+ const documents = value.documents.map(parsePlaygroundDocument);
234
+ resolve({ version: 1, currentId: value.currentId, documents });
235
+ } catch (err) {
236
+ reject(err);
237
+ }
238
+ };
239
+ req.onerror = () => reject(req.error);
240
+ });
241
+ }
242
+ // Serialize snapshots so an older, slower write cannot replace newer work.
243
+ let writeTail = Promise.resolve();
244
+ export function writeWorkspace(workspace: PlaygroundWorkspace): Promise<void> {
245
+ const snapshot = structuredClone(workspace);
246
+ const operation = writeTail
247
+ .catch(() => {})
248
+ .then(async () => {
249
+ const db = await openDatabase();
250
+ return new Promise<void>((resolve, reject) => {
251
+ const tx = db.transaction("workspace", "readwrite");
252
+ tx.objectStore("workspace").put(snapshot, "current");
253
+ tx.oncomplete = () => resolve();
254
+ tx.onerror = () => reject(tx.error);
255
+ tx.onabort = () =>
256
+ reject(tx.error || new Error("Local history write aborted."));
257
+ });
258
+ });
259
+ writeTail = operation;
260
+ return operation;
261
+ }