tuxevil-rotator 4.2.1 → 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 (41) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +20 -6
  3. package/package.json +3 -3
  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 +60 -0
  7. package/plugins/opencode-discovery/index.mjs +333 -0
  8. package/plugins/opencode-discovery/package.json +24 -0
  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 +34 -6
  13. package/src/dashboard-app.ts +1 -0
  14. package/src/install-agent.ts +252 -143
  15. package/src/install-opencode.ts +211 -43
  16. package/src/providers/google-antigravity/catalog.ts +45 -166
  17. package/src/providers/google-antigravity/dynamic-catalog.ts +107 -10
  18. package/src/providers/google-antigravity/forward.ts +4 -2
  19. package/src/providers/google-antigravity/index.ts +12 -4
  20. package/src/providers/google-antigravity/quota.ts +9 -7
  21. package/src/providers/ollama/forward.ts +10 -0
  22. package/src/providers/openai-codex/catalog.ts +157 -18
  23. package/src/proxy.ts +54 -5
  24. package/src/rotator.ts +32 -22
  25. package/src/types.ts +79 -67
  26. package/src/web/app.tsx +4 -0
  27. package/src/web/lib/audio-recorder.ts +159 -0
  28. package/src/web/lib/colors.ts +4 -0
  29. package/src/web/lib/playground-storage.ts +261 -0
  30. package/src/web/lib/playground.ts +448 -0
  31. package/src/web/nav.ts +1 -0
  32. package/src/web/pages/Playground.tsx +1111 -0
  33. package/src/web/pages/Transcription.tsx +428 -0
  34. package/src/web/state/api.ts +3 -0
  35. package/src/web/state/playground-client.ts +136 -0
  36. package/src/web/state/playground.ts +69 -0
  37. package/src/web/state/router.ts +2 -2
  38. package/src/web/state/transcription-client.ts +93 -0
  39. package/src/web/styles/app.css +45 -0
  40. package/tools/telemetry-receiver/receiver.js +59 -46
  41. package/plugins/opencode-discovery.js +0 -174
@@ -0,0 +1,448 @@
1
+ // Shared, browser-independent playground contracts and compatibility evaluators.
2
+ export type PlaygroundTab = "chat" | "compare" | "compliance" | "transcription";
3
+ export interface ImageAttachment {
4
+ name: string;
5
+ url: string;
6
+ }
7
+ export type MessageContent =
8
+ | string
9
+ | Array<
10
+ | { type: "text"; text: string }
11
+ | { type: "image_url"; image_url: { url: string } }
12
+ >;
13
+ export interface ToolCall {
14
+ id: string;
15
+ type: "function";
16
+ function: { name: string; arguments: string };
17
+ }
18
+ export interface PlaygroundMessage {
19
+ role: "system" | "user" | "assistant";
20
+ content: MessageContent | null;
21
+ tool_calls?: ToolCall[];
22
+ }
23
+ export interface Parameters {
24
+ system: string;
25
+ temperature: string;
26
+ maxTokens: string;
27
+ effort: string;
28
+ stream: boolean;
29
+ tools: string;
30
+ }
31
+ export const DEFAULT_PARAMETERS: Parameters = {
32
+ system: "",
33
+ temperature: "",
34
+ maxTokens: "512",
35
+ effort: "",
36
+ stream: true,
37
+ tools: "",
38
+ };
39
+ export interface ChatRequest {
40
+ model: string;
41
+ messages: PlaygroundMessage[];
42
+ stream: boolean;
43
+ temperature?: number;
44
+ max_tokens?: number;
45
+ reasoning_effort?: string;
46
+ tools?: unknown[];
47
+ tool_choice?: unknown;
48
+ response_format?: { type: "json_object" };
49
+ }
50
+ export interface ChatResult {
51
+ content: string;
52
+ reasoning: string;
53
+ tools: ToolCall[];
54
+ durationMs: number;
55
+ firstContentMs: number | null;
56
+ inputTokens: number | null;
57
+ outputTokens: number | null;
58
+ finishReason: string | null;
59
+ metadata: Record<string, string>;
60
+ raw: unknown[];
61
+ done: boolean;
62
+ status: number;
63
+ }
64
+ export interface Turn {
65
+ request: ChatRequest;
66
+ result: ChatResult | null;
67
+ error?: string;
68
+ }
69
+ export interface PlaygroundPanel {
70
+ id: string;
71
+ model: string;
72
+ params: Parameters;
73
+ turns: Turn[];
74
+ }
75
+ export type CaseId = "basic" | "stream" | "system" | "json" | "tools";
76
+ export type Verdict =
77
+ "passed" | "failed" | "unsupported" | "error" | "cancelled";
78
+ export interface ComplianceResult {
79
+ model: string;
80
+ caseId: CaseId;
81
+ verdict: Verdict;
82
+ explanation: string;
83
+ turn: Turn;
84
+ }
85
+ export interface TranscriptionResult {
86
+ id: string;
87
+ filename: string;
88
+ model: string;
89
+ language: string;
90
+ prompt: string;
91
+ text: string;
92
+ elapsedMs: number;
93
+ createdAt: number;
94
+ }
95
+ export interface TranscriptionState {
96
+ model: string;
97
+ language: string;
98
+ prompt: string;
99
+ results: TranscriptionResult[];
100
+ }
101
+ export function newTranscription(): TranscriptionState {
102
+ return { model: "", language: "", prompt: "", results: [] };
103
+ }
104
+ export interface PlaygroundDocument {
105
+ version: 1;
106
+ id: string;
107
+ title: string;
108
+ updatedAt: number;
109
+ chat: PlaygroundPanel;
110
+ compare: PlaygroundPanel[];
111
+ sync: boolean;
112
+ draft: string;
113
+ images: ImageAttachment[];
114
+ complianceModels: string[];
115
+ cases: CaseId[];
116
+ results: ComplianceResult[];
117
+ transcription?: TranscriptionState;
118
+ }
119
+ export const CASES: Array<{ id: CaseId; label: string }> = [
120
+ { id: "basic", label: "Basic chat" },
121
+ { id: "stream", label: "Streaming" },
122
+ { id: "system", label: "System prompt" },
123
+ { id: "json", label: "JSON mode" },
124
+ { id: "tools", label: "Tool calling" },
125
+ ];
126
+ export const VERDICT_LABELS: Record<Verdict, string> = {
127
+ passed: "Passed",
128
+ failed: "Failed",
129
+ unsupported: "Not supported",
130
+ error: "Error",
131
+ cancelled: "Cancelled",
132
+ };
133
+ // randomUUID requires a secure context; getRandomValues also works on LAN HTTP dashboards.
134
+ export const newId = (): string =>
135
+ typeof crypto.randomUUID === "function"
136
+ ? crypto.randomUUID()
137
+ : Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) =>
138
+ byte.toString(16).padStart(2, "0"),
139
+ ).join("");
140
+ export function newPanel(): PlaygroundPanel {
141
+ return {
142
+ id: newId(),
143
+ model: "",
144
+ params: { ...DEFAULT_PARAMETERS },
145
+ turns: [],
146
+ };
147
+ }
148
+ export function newDocument(): PlaygroundDocument {
149
+ return {
150
+ version: 1,
151
+ id: newId(),
152
+ title: "Untitled playground",
153
+ updatedAt: Date.now(),
154
+ chat: newPanel(),
155
+ compare: [newPanel(), newPanel()],
156
+ sync: true,
157
+ draft: "",
158
+ images: [],
159
+ complianceModels: [],
160
+ cases: CASES.map((c) => c.id),
161
+ results: [],
162
+ transcription: newTranscription(),
163
+ };
164
+ }
165
+ export function userMessage(
166
+ text: string,
167
+ images: ImageAttachment[],
168
+ ): PlaygroundMessage {
169
+ return {
170
+ role: "user",
171
+ content: images.length
172
+ ? [
173
+ ...(text ? [{ type: "text" as const, text }] : []),
174
+ ...images.map((image) => ({
175
+ type: "image_url" as const,
176
+ image_url: { url: image.url },
177
+ })),
178
+ ]
179
+ : text,
180
+ };
181
+ }
182
+ export function buildChatRequest(
183
+ panel: PlaygroundPanel,
184
+ next: PlaygroundMessage,
185
+ retry = false,
186
+ ): ChatRequest {
187
+ if (!panel.model) throw new Error("Choose a model first.");
188
+ const params = panel.params;
189
+ const messages: PlaygroundMessage[] = params.system
190
+ ? [{ role: "system", content: params.system }]
191
+ : [];
192
+ // Tool calls are inspected only; without tool results they cannot be replayed.
193
+ const turns = retry ? panel.turns.slice(0, -1) : panel.turns;
194
+ for (const turn of turns) {
195
+ if (
196
+ turn.error ||
197
+ !turn.result?.done ||
198
+ !turn.result.content ||
199
+ turn.result.tools.length
200
+ )
201
+ continue;
202
+ messages.push(turn.request.messages[turn.request.messages.length - 1], {
203
+ role: "assistant",
204
+ content: turn.result.content,
205
+ });
206
+ }
207
+ messages.push(next);
208
+ const request: ChatRequest = {
209
+ model: panel.model,
210
+ messages,
211
+ stream: params.stream,
212
+ };
213
+ if (params.temperature !== "") {
214
+ const value = Number(params.temperature);
215
+ if (!Number.isFinite(value) || value < 0 || value > 2)
216
+ throw new Error("Temperature must be between 0 and 2.");
217
+ request.temperature = value;
218
+ }
219
+ if (params.maxTokens !== "") {
220
+ const value = Number(params.maxTokens);
221
+ if (!Number.isSafeInteger(value) || value < 1)
222
+ throw new Error("Max tokens must be a positive integer.");
223
+ request.max_tokens = value;
224
+ }
225
+ if (params.effort) request.reasoning_effort = params.effort;
226
+ if (params.tools.trim()) {
227
+ const tools: unknown = JSON.parse(params.tools);
228
+ if (
229
+ !Array.isArray(tools) ||
230
+ tools.some(
231
+ (t) =>
232
+ !record(t) ||
233
+ t.type !== "function" ||
234
+ !record(t.function) ||
235
+ typeof t.function.name !== "string" ||
236
+ !record(t.function.parameters),
237
+ )
238
+ ) {
239
+ throw new Error(
240
+ "Tools must be a JSON array of function definitions with name and parameters.",
241
+ );
242
+ }
243
+ request.tools = tools;
244
+ }
245
+ return request;
246
+ }
247
+ export function record(value: unknown): value is Record<string, unknown> {
248
+ return !!value && typeof value === "object" && !Array.isArray(value);
249
+ }
250
+ export function emptyResult(): ChatResult {
251
+ return {
252
+ content: "",
253
+ reasoning: "",
254
+ tools: [],
255
+ durationMs: 0,
256
+ firstContentMs: null,
257
+ inputTokens: null,
258
+ outputTokens: null,
259
+ finishReason: null,
260
+ metadata: {},
261
+ raw: [],
262
+ done: false,
263
+ status: 0,
264
+ };
265
+ }
266
+ export function apiErrorMessage(value: unknown): string | null {
267
+ if (!record(value)) return null;
268
+ if (typeof value.error === "string") return value.error;
269
+ if (record(value.error) && typeof value.error.message === "string")
270
+ return value.error.message;
271
+ return null;
272
+ }
273
+ /** Parses SSE across arbitrary UTF-8/text boundaries, including CRLF and comments. */
274
+ export class SseDecoder {
275
+ private buffer = "";
276
+ constructor(private readonly onData: (data: string) => void) {}
277
+ push(text: string): void {
278
+ this.buffer += text;
279
+ for (;;) {
280
+ const separator = /\r?\n\r?\n/.exec(this.buffer);
281
+ if (!separator) return;
282
+ const frame = this.buffer.slice(0, separator.index);
283
+ this.buffer = this.buffer.slice(separator.index + separator[0].length);
284
+ const data = frame
285
+ .split(/\r?\n/)
286
+ .filter((line) => line.startsWith("data:"))
287
+ .map((line) => line.slice(5).replace(/^ /, ""))
288
+ .join("\n");
289
+ if (data) this.onData(data);
290
+ }
291
+ }
292
+ finish(): void {
293
+ if (this.buffer.trim()) throw new Error("Incomplete SSE frame.");
294
+ }
295
+ }
296
+ export function applyCompletion(
297
+ result: ChatResult,
298
+ value: unknown,
299
+ streaming: boolean,
300
+ elapsedMs: number,
301
+ ): void {
302
+ const error = apiErrorMessage(value);
303
+ if (error) throw new Error(error);
304
+ if (!record(value)) throw new Error("Invalid completion response.");
305
+ result.raw.push(value);
306
+ if (record(value.usage)) {
307
+ if (typeof value.usage.prompt_tokens === "number")
308
+ result.inputTokens = value.usage.prompt_tokens;
309
+ if (typeof value.usage.completion_tokens === "number")
310
+ result.outputTokens = value.usage.completion_tokens;
311
+ }
312
+ if (!Array.isArray(value.choices))
313
+ throw new Error("Response is missing choices.");
314
+ const choice = value.choices[0];
315
+ if (!record(choice)) return; // usage-only streaming chunk
316
+ if (typeof choice.finish_reason === "string")
317
+ result.finishReason = choice.finish_reason;
318
+ const message = streaming ? choice.delta : choice.message;
319
+ if (!record(message))
320
+ throw new Error("Response is missing its message or delta.");
321
+ if (typeof message.content === "string") result.content += message.content;
322
+ if (typeof message.reasoning_content === "string")
323
+ result.reasoning += message.reasoning_content;
324
+ if (Array.isArray(message.tool_calls)) {
325
+ for (const [position, tool] of message.tool_calls.entries()) {
326
+ if (!record(tool)) throw new Error("Invalid tool call.");
327
+ const index = streaming ? tool.index : position;
328
+ if (!Number.isInteger(index) || Number(index) < 0 || Number(index) > 100)
329
+ throw new Error("Invalid tool call index.");
330
+ const current = result.tools[Number(index)] ?? {
331
+ id: "",
332
+ type: "function",
333
+ function: { name: "", arguments: "" },
334
+ };
335
+ if (typeof tool.id === "string") current.id = tool.id;
336
+ if (record(tool.function)) {
337
+ if (typeof tool.function.name === "string")
338
+ current.function.name += tool.function.name;
339
+ if (typeof tool.function.arguments === "string")
340
+ current.function.arguments += tool.function.arguments;
341
+ }
342
+ result.tools[Number(index)] = current;
343
+ }
344
+ }
345
+ if (
346
+ result.firstContentMs === null &&
347
+ (result.content || result.reasoning || result.tools.length)
348
+ )
349
+ result.firstContentMs = elapsedMs;
350
+ }
351
+ export function complianceRequest(model: string, caseId: CaseId): ChatRequest {
352
+ const request: ChatRequest = {
353
+ model,
354
+ messages: [{ role: "user", content: "Reply with the single word hello." }],
355
+ stream: caseId === "stream",
356
+ max_tokens: 256,
357
+ };
358
+ if (caseId === "system")
359
+ request.messages = [
360
+ {
361
+ role: "system",
362
+ content:
363
+ "For every user message respond with exactly ROTATOR_OK and nothing else.",
364
+ },
365
+ { role: "user", content: "What is two plus two?" },
366
+ ];
367
+ if (caseId === "json") {
368
+ request.response_format = { type: "json_object" };
369
+ request.messages = [
370
+ {
371
+ role: "user",
372
+ content:
373
+ 'Return a JSON object with exactly this property: "rotator_ok": true. No markdown.',
374
+ },
375
+ ];
376
+ }
377
+ if (caseId === "tools") {
378
+ request.tools = [
379
+ {
380
+ type: "function",
381
+ function: {
382
+ name: "rotator_echo",
383
+ description: "Echo the provided text.",
384
+ parameters: {
385
+ type: "object",
386
+ properties: { text: { type: "string" } },
387
+ required: ["text"],
388
+ additionalProperties: false,
389
+ },
390
+ },
391
+ },
392
+ ];
393
+ request.tool_choice = {
394
+ type: "function",
395
+ function: { name: "rotator_echo" },
396
+ };
397
+ request.messages = [
398
+ { role: "user", content: 'Call rotator_echo with text "ROTATOR_OK".' },
399
+ ];
400
+ }
401
+ return request;
402
+ }
403
+ export function evaluateCompliance(
404
+ caseId: CaseId,
405
+ result: ChatResult,
406
+ ): { verdict: Verdict; explanation: string } {
407
+ let passed =
408
+ result.done &&
409
+ result.raw.length > 0 &&
410
+ result.finishReason !== null &&
411
+ Boolean(result.content || result.tools.length);
412
+ if (caseId === "system") passed &&= result.content.trim() === "ROTATOR_OK";
413
+ if (caseId === "json") {
414
+ try {
415
+ const value: unknown = JSON.parse(result.content);
416
+ passed &&=
417
+ record(value) &&
418
+ value.rotator_ok === true &&
419
+ Object.keys(value).length === 1;
420
+ } catch {
421
+ passed = false;
422
+ }
423
+ }
424
+ if (caseId === "tools") {
425
+ try {
426
+ passed &&=
427
+ result.tools.length === 1 &&
428
+ result.tools[0].function.name === "rotator_echo" &&
429
+ JSON.parse(result.tools[0].function.arguments).text === "ROTATOR_OK";
430
+ } catch {
431
+ passed = false;
432
+ }
433
+ }
434
+ return {
435
+ verdict: passed ? "passed" : "failed",
436
+ explanation: passed
437
+ ? "Observed response meets this case's checks through the rotator."
438
+ : "Response did not meet this case's checks. Inspect the request and response.",
439
+ };
440
+ }
441
+ export function errorVerdict(status: number, message: string): Verdict {
442
+ return [400, 422, 501].includes(status) &&
443
+ /(?:not supported|unsupported|does not support|not implemented)/i.test(
444
+ message,
445
+ )
446
+ ? "unsupported"
447
+ : "error";
448
+ }
package/src/web/nav.ts CHANGED
@@ -17,6 +17,7 @@ export const NAV: NavItem[] = [
17
17
  { id: "overview", label: "Overview", icon: "overview", href: BASE, keywords: "home status health models pools" },
18
18
  { id: "accounts", label: "Accounts", icon: "accounts", href: `${BASE}/accounts`, keywords: "providers quota" },
19
19
  { id: "models", label: "Models", icon: "models", href: `${BASE}/models`, keywords: "providers order enable disable catalog" },
20
+ { id: "playground", label: "Playground", icon: "play", href: `${BASE}/playground`, keywords: "chat compare compliance transcription microphone audio test models images" },
20
21
  { id: "requests", label: "Requests", icon: "requests", href: `${BASE}/requests`, keywords: "traffic logs history live" },
21
22
  { id: "usage", label: "Usage", icon: "usage", href: `${BASE}/usage`, keywords: "tokens savings latency heatmap" },
22
23
  { id: "keys", label: "Virtual keys", icon: "keys", href: `${BASE}/keys`, keywords: "api clients" },