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.
Files changed (84) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +11 -4
  3. package/package.json +2 -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/access-evidence.ts +153 -0
  10. package/src/access-probe.ts +85 -0
  11. package/src/admin-auth.ts +4 -1
  12. package/src/audio-transcription.ts +32 -6
  13. package/src/auto-access-shadow.ts +11 -0
  14. package/src/auto-model-access.ts +185 -0
  15. package/src/auto-output-health.ts +12 -0
  16. package/src/auto-routing-evaluation.ts +80 -0
  17. package/src/auto-routing-quality.ts +308 -0
  18. package/src/auto-routing.ts +403 -26
  19. package/src/cli.ts +3 -3
  20. package/src/compat/model-specs.ts +4 -0
  21. package/src/compat.ts +253 -37
  22. package/src/compression/index.ts +6 -6
  23. package/src/compression/lite.ts +3 -9
  24. package/src/compression/rtk/index.ts +0 -3
  25. package/src/config-defaults.ts +7 -0
  26. package/src/dashboard-app.ts +1 -0
  27. package/src/dashboard.ts +5 -0
  28. package/src/db-store.ts +10 -0
  29. package/src/index.ts +2 -0
  30. package/src/install-agent.ts +211 -129
  31. package/src/install-opencode.ts +80 -18
  32. package/src/model-access-api.ts +74 -0
  33. package/src/model-access.ts +56 -0
  34. package/src/ollama-output-gate.ts +18 -0
  35. package/src/onboarding.ts +1 -1
  36. package/src/provider-catalog-evidence.ts +26 -0
  37. package/src/providers/google-antigravity/catalog.ts +14 -6
  38. package/src/providers/google-antigravity/dynamic-catalog.ts +87 -3
  39. package/src/providers/google-antigravity/forward.ts +4 -2
  40. package/src/providers/google-antigravity/quota.ts +7 -0
  41. package/src/providers/ollama/context-window.ts +13 -0
  42. package/src/providers/ollama/forward.ts +10 -0
  43. package/src/providers/ollama/quota.ts +4 -0
  44. package/src/providers/ollama/translators.ts +19 -2
  45. package/src/providers/openai-codex/catalog.ts +157 -18
  46. package/src/providers/openai-codex/compat.ts +5 -1
  47. package/src/providers/openai-codex/credentials.ts +22 -6
  48. package/src/providers/openai-codex/index.ts +9 -1
  49. package/src/providers/openai-codex/quota.ts +19 -6
  50. package/src/providers/opencode-zen/forward.ts +1 -1
  51. package/src/providers/opencode-zen/quota.ts +2 -0
  52. package/src/proxy.ts +113 -5
  53. package/src/quota-observation.ts +26 -0
  54. package/src/quota-pools.ts +322 -0
  55. package/src/rotator.ts +167 -40
  56. package/src/settings-repository.ts +1 -0
  57. package/src/types.ts +106 -29
  58. package/src/usage-limits-auth.ts +24 -0
  59. package/src/usage-limits.ts +148 -0
  60. package/src/validators.ts +26 -0
  61. package/src/web/app.tsx +4 -0
  62. package/src/web/components/icons.tsx +15 -0
  63. package/src/web/components/overlays.tsx +4 -0
  64. package/src/web/components/ui.tsx +9 -9
  65. package/src/web/lib/audio-recorder.ts +159 -0
  66. package/src/web/lib/colors.ts +4 -0
  67. package/src/web/lib/playground-storage.ts +261 -0
  68. package/src/web/lib/playground.ts +483 -0
  69. package/src/web/lib/pool-navigation.ts +4 -0
  70. package/src/web/lib/pools.ts +2 -243
  71. package/src/web/nav.ts +1 -0
  72. package/src/web/pages/AccountDetail.tsx +2 -1
  73. package/src/web/pages/ModelAccess.tsx +88 -0
  74. package/src/web/pages/Models.tsx +2 -0
  75. package/src/web/pages/Overview.tsx +26 -9
  76. package/src/web/pages/Playground.tsx +1692 -0
  77. package/src/web/pages/Transcription.tsx +562 -0
  78. package/src/web/state/api.ts +6 -0
  79. package/src/web/state/playground-client.ts +136 -0
  80. package/src/web/state/playground.ts +69 -0
  81. package/src/web/state/router.ts +2 -2
  82. package/src/web/state/transcription-client.ts +93 -0
  83. package/src/web/styles/app.css +501 -0
  84. package/tools/telemetry-receiver/receiver.js +59 -46
@@ -0,0 +1,136 @@
1
+ import { ApiError, notifyUnauthorized } from "./api.js";
2
+ import {
3
+ apiErrorMessage,
4
+ applyCompletion,
5
+ emptyResult,
6
+ SseDecoder,
7
+ type ChatRequest,
8
+ type ChatResult,
9
+ } from "../lib/playground.js";
10
+
11
+ export class PlaygroundError extends Error {
12
+ constructor(
13
+ message: string,
14
+ readonly result: ChatResult,
15
+ readonly cancelled = false,
16
+ ) {
17
+ super(message);
18
+ }
19
+ }
20
+
21
+ /** One cancellable request, shared by Chat, Compare and Compliance. */
22
+ export async function runChat(
23
+ request: ChatRequest,
24
+ signal: AbortSignal,
25
+ onProgress: (result: ChatResult) => void = () => {},
26
+ fetcher: typeof fetch = fetch,
27
+ timeoutMs = 120_000,
28
+ ): Promise<ChatResult> {
29
+ const started = performance.now();
30
+ const controller = new AbortController();
31
+ const abort = () => controller.abort();
32
+ signal.addEventListener("abort", abort, { once: true });
33
+ if (signal.aborted) abort();
34
+ let timedOut = false;
35
+ const timer = setTimeout(() => {
36
+ timedOut = true;
37
+ controller.abort();
38
+ }, timeoutMs);
39
+ const result = emptyResult();
40
+ let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
41
+ try {
42
+ const response = await fetcher("/api/playground/chat/completions", {
43
+ method: "POST",
44
+ credentials: "same-origin",
45
+ signal: controller.signal,
46
+ headers: { "Content-Type": "application/json" },
47
+ body: JSON.stringify(request),
48
+ });
49
+ result.status = response.status;
50
+ response.headers.forEach((value, key) => {
51
+ if (key.startsWith("x-rotator-")) result.metadata[key] = value;
52
+ });
53
+ if (response.status === 401) {
54
+ notifyUnauthorized();
55
+ throw new ApiError(401, "Your session ended. Sign in again.");
56
+ }
57
+ if (!response.ok) {
58
+ let data: unknown;
59
+ try {
60
+ data = await response.json();
61
+ } catch {
62
+ data = null;
63
+ }
64
+ if (data) result.raw.push(data);
65
+ throw new Error(
66
+ apiErrorMessage(data) || `Request failed (HTTP ${response.status}).`,
67
+ );
68
+ }
69
+ if (request.stream) {
70
+ if (
71
+ !response.headers.get("content-type")?.includes("text/event-stream") ||
72
+ !response.body
73
+ )
74
+ throw new Error("Expected an SSE response.");
75
+ let terminated = false;
76
+ const parser = new SseDecoder((data) => {
77
+ if (terminated) throw new Error("Received data after [DONE].");
78
+ if (data === "[DONE]") {
79
+ terminated = true;
80
+ return;
81
+ }
82
+ applyCompletion(
83
+ result,
84
+ JSON.parse(data) as unknown,
85
+ true,
86
+ performance.now() - started,
87
+ );
88
+ result.durationMs = performance.now() - started;
89
+ onProgress(structuredClone(result));
90
+ });
91
+ reader = response.body.getReader();
92
+ const decoder = new TextDecoder();
93
+ for (;;) {
94
+ const { done, value } = await reader.read();
95
+ if (done) break;
96
+ parser.push(decoder.decode(value, { stream: true }));
97
+ }
98
+ parser.push(decoder.decode());
99
+ parser.finish();
100
+ if (!terminated || !result.finishReason)
101
+ throw new Error("Stream ended without a finish reason and [DONE].");
102
+ } else {
103
+ applyCompletion(
104
+ result,
105
+ await response.json(),
106
+ false,
107
+ performance.now() - started,
108
+ );
109
+ if (!result.finishReason)
110
+ throw new Error("Response is missing finish_reason.");
111
+ }
112
+ if (controller.signal.aborted) throw new Error("Request aborted.");
113
+ result.done = true;
114
+ return result;
115
+ } catch (err) {
116
+ const message = timedOut
117
+ ? "Request timed out after 120 seconds."
118
+ : signal.aborted
119
+ ? "Request cancelled."
120
+ : err instanceof Error
121
+ ? err.message
122
+ : String(err);
123
+ throw new PlaygroundError(message, result, signal.aborted && !timedOut);
124
+ } finally {
125
+ result.durationMs = performance.now() - started;
126
+ clearTimeout(timer);
127
+ signal.removeEventListener("abort", abort);
128
+ // Cancel a malformed or interrupted response so server capacity is released.
129
+ try {
130
+ await reader?.cancel();
131
+ } catch {
132
+ /* the transport may already be closed */
133
+ }
134
+ reader?.releaseLock();
135
+ }
136
+ }
@@ -0,0 +1,69 @@
1
+ import { signal } from "@preact/signals";
2
+ import { newDocument, type PlaygroundDocument } from "../lib/playground.js";
3
+ import {
4
+ readWorkspace,
5
+ writeWorkspace,
6
+ type PlaygroundWorkspace,
7
+ } from "../lib/playground-storage.js";
8
+
9
+ export const workspace = signal<PlaygroundWorkspace | null>(null);
10
+ export const storageError = signal("");
11
+ let initialization: Promise<void> | undefined;
12
+ let saveTimer: ReturnType<typeof setTimeout> | undefined;
13
+ export function initializePlayground(): Promise<void> {
14
+ initialization ??= (async () => {
15
+ try {
16
+ workspace.value = await readWorkspace();
17
+ } catch (err) {
18
+ storageError.value = String(err);
19
+ }
20
+ if (!workspace.value || !workspace.value.documents.length) {
21
+ const doc = newDocument();
22
+ workspace.value = { version: 1, currentId: doc.id, documents: [doc] };
23
+ }
24
+ })();
25
+ return initialization;
26
+ }
27
+ export function currentDocument(): PlaygroundDocument | null {
28
+ const state = workspace.value;
29
+ return (
30
+ state?.documents.find((doc) => doc.id === state.currentId) ??
31
+ state?.documents[0] ??
32
+ null
33
+ );
34
+ }
35
+ export function saveWorkspace(
36
+ next: PlaygroundWorkspace,
37
+ immediate = false,
38
+ ): void {
39
+ workspace.value = next;
40
+ clearTimeout(saveTimer);
41
+ const save = () => {
42
+ void writeWorkspace(workspace.value!)
43
+ .then(() => {
44
+ storageError.value = "";
45
+ })
46
+ .catch((err) => {
47
+ storageError.value = String(err);
48
+ });
49
+ };
50
+ if (immediate) save();
51
+ else saveTimer = setTimeout(save, 300);
52
+ }
53
+ export function updateDocument(
54
+ update: (doc: PlaygroundDocument) => PlaygroundDocument,
55
+ immediate = false,
56
+ ): void {
57
+ const doc = currentDocument();
58
+ if (!doc || !workspace.value) return;
59
+ const next = { ...update(doc), updatedAt: Date.now() };
60
+ saveWorkspace(
61
+ {
62
+ ...workspace.value,
63
+ documents: workspace.value.documents.map((d) =>
64
+ d.id === doc.id ? next : d,
65
+ ),
66
+ },
67
+ immediate,
68
+ );
69
+ }
@@ -5,7 +5,7 @@ import { computed, signal } from "@preact/signals";
5
5
 
6
6
  export const BASE = "/dashboard";
7
7
 
8
- export type PageId = "overview" | "accounts" | "models" | "requests" | "usage" | "keys" | "settings";
8
+ export type PageId = "overview" | "accounts" | "models" | "requests" | "usage" | "keys" | "settings" | "playground";
9
9
 
10
10
  export interface RouteMatch {
11
11
  page: PageId | "not-found";
@@ -133,7 +133,7 @@ export function matchRoute(path: string): RouteMatch {
133
133
  if (head === "accounts") return { ...none, page: "accounts", account: decodeSegment(second) };
134
134
  if (head === "models" && second === "effort") return { ...none, page: "models", effort: { alias: decodeSegment(third) } };
135
135
  if (head === "models") return { ...none, page: "models", provider: decodeSegment(second) };
136
- if (head === "requests" || head === "usage" || head === "keys" || head === "settings") {
136
+ if (head === "playground" || head === "requests" || head === "usage" || head === "keys" || head === "settings") {
137
137
  return { ...none, page: head };
138
138
  }
139
139
  return { ...none, page: "not-found" };
@@ -0,0 +1,93 @@
1
+ import { ApiError, notifyUnauthorized } from "./api.js";
2
+ import {
3
+ apiErrorMessage,
4
+ record,
5
+ type TranscriptionResult,
6
+ } from "../lib/playground.js";
7
+ import { validateAudioFile, audioFileLimit } from "../lib/audio-recorder.js";
8
+
9
+ export interface TranscriptionInput {
10
+ file: File;
11
+ model: string;
12
+ language: string;
13
+ prompt: string;
14
+ maxBodyBytes: number;
15
+ }
16
+ export async function transcribeAudio(
17
+ input: TranscriptionInput,
18
+ signal: AbortSignal,
19
+ fetcher: typeof fetch = fetch,
20
+ ): Promise<Omit<TranscriptionResult, "id" | "createdAt">> {
21
+ validateAudioFile(input.file, audioFileLimit(input.maxBodyBytes));
22
+ if (!input.model) throw new Error("Choose an audio model first.");
23
+ if (input.language && !/^[a-z]{2,3}(?:-[a-zA-Z]{2,4})?$/.test(input.language))
24
+ throw new Error(
25
+ "Use a language code such as es or en, or leave it blank for automatic detection.",
26
+ );
27
+ if (input.prompt.length > 1000)
28
+ throw new Error("Vocabulary context must be 1000 characters or fewer.");
29
+ const form = new FormData();
30
+ form.append("file", input.file);
31
+ form.append("model", input.model);
32
+ form.append("response_format", "json");
33
+ if (input.language) form.append("language", input.language);
34
+ if (input.prompt) form.append("prompt", input.prompt);
35
+ const controller = new AbortController();
36
+ const abort = () => controller.abort();
37
+ signal.addEventListener("abort", abort, { once: true });
38
+ if (signal.aborted) abort();
39
+ const started = performance.now();
40
+ let timedOut = false;
41
+ const timeout = setTimeout(() => {
42
+ timedOut = true;
43
+ controller.abort();
44
+ }, 40_000);
45
+ try {
46
+ const response = await fetcher("/api/playground/audio/transcriptions", {
47
+ method: "POST",
48
+ credentials: "same-origin",
49
+ body: form,
50
+ signal: controller.signal,
51
+ });
52
+ if (response.status === 401) {
53
+ notifyUnauthorized();
54
+ throw new ApiError(401, "Your session ended. Sign in again.");
55
+ }
56
+ let body: unknown;
57
+ try {
58
+ body = await response.json();
59
+ } catch {
60
+ throw new Error(
61
+ `Invalid transcription response (HTTP ${response.status}).`,
62
+ );
63
+ }
64
+ if (!response.ok)
65
+ throw new Error(
66
+ apiErrorMessage(body) ||
67
+ `Transcription failed (HTTP ${response.status}).`,
68
+ );
69
+ if (!record(body) || typeof body.text !== "string")
70
+ throw new Error("Transcription response is missing text.");
71
+ if (controller.signal.aborted) throw new Error("Request cancelled.");
72
+ return {
73
+ filename: input.file.name,
74
+ model: input.model,
75
+ language: input.language,
76
+ prompt: input.prompt,
77
+ text: body.text,
78
+ elapsedMs: performance.now() - started,
79
+ };
80
+ } catch (err) {
81
+ if (timedOut)
82
+ throw new Error(
83
+ "Transcription request timed out. Try a shorter recording.",
84
+ { cause: err },
85
+ );
86
+ if (signal.aborted)
87
+ throw new Error("Transcription cancelled.", { cause: err });
88
+ throw err;
89
+ } finally {
90
+ clearTimeout(timeout);
91
+ signal.removeEventListener("abort", abort);
92
+ }
93
+ }