tuxevil-rotator 3.0.0 → 3.2.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 +37 -0
- package/README.md +20 -6
- package/package.json +1 -1
- package/src/account-store.ts +37 -5
- package/src/cli.ts +24 -3
- package/src/compat/model-specs.ts +1 -0
- package/src/compat.ts +540 -24
- package/src/config-normalize.ts +73 -30
- package/src/dashboard.ts +43 -42
- package/src/index.ts +1 -0
- package/src/onboarding.ts +349 -21
- package/src/providers/adapter.ts +18 -0
- package/src/providers/credential-helpers.ts +64 -0
- package/src/providers/google-antigravity/index.ts +9 -0
- package/src/providers/google-antigravity/quota.ts +2 -1
- package/src/providers/google-antigravity/translators.ts +83 -24
- package/src/providers/ollama/index.ts +8 -0
- package/src/providers/ollama/quota.ts +2 -1
- package/src/providers/openai-codex/catalog.ts +117 -0
- package/src/providers/openai-codex/compat.ts +556 -0
- package/src/providers/openai-codex/credentials.ts +82 -0
- package/src/providers/openai-codex/forward.ts +240 -0
- package/src/providers/openai-codex/index.ts +153 -0
- package/src/providers/openai-codex/login.ts +172 -0
- package/src/providers/openai-codex/oauth.ts +359 -0
- package/src/providers/openai-codex/quota.ts +231 -0
- package/src/providers/opencode-zen/catalog.ts +37 -0
- package/src/providers/opencode-zen/credentials.ts +31 -0
- package/src/providers/opencode-zen/forward.ts +214 -0
- package/src/providers/opencode-zen/index.ts +73 -0
- package/src/providers/opencode-zen/login.ts +81 -0
- package/src/providers/opencode-zen/quota.ts +67 -0
- package/src/providers/registry.ts +24 -5
- package/src/proxy.ts +75 -27
- package/src/rate-limit-parser.ts +2 -1
- package/src/rotator.ts +259 -48
- package/src/spend-logger.ts +2 -0
- package/src/static/dashboard-keys.js +152 -2
- package/src/static/dashboard.js +161 -37
- package/src/types.ts +83 -1
- package/src/validators.ts +11 -2
- package/tools/telemetry-receiver/receiver.js +14 -0
package/src/config-normalize.ts
CHANGED
|
@@ -3,46 +3,89 @@
|
|
|
3
3
|
// account-store (write path) can use it without import cycles.
|
|
4
4
|
|
|
5
5
|
import type { AccountConfig } from "./types.js";
|
|
6
|
-
import { DEFAULT_PROVIDER } from "./providers/credential-helpers.js";
|
|
6
|
+
import { DEFAULT_PROVIDER, sortAccountCredentials } from "./providers/credential-helpers.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Migrate a flat legacy account shape (provider/apiKey/refreshToken at the
|
|
10
10
|
* top level) into the parent-account model where `email` owns a list of
|
|
11
|
-
* per-provider credentials.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* per-provider credentials. Existing credential arrays are also repaired when
|
|
12
|
+
* they coexist with legacy fields: adding a provider must not strand a
|
|
13
|
+
* pre-existing Google or Ollama credential in the deprecated top-level shape.
|
|
14
|
+
* Runs on every config load (applyConfigDefaults), so both the persisted DB
|
|
15
|
+
* config and legacy files normalize transparently.
|
|
14
16
|
*/
|
|
15
17
|
export function normalizeAccountConfig(account: AccountConfig): AccountConfig {
|
|
16
|
-
if (Array.isArray(account.credentials) && account.credentials.length > 0) {
|
|
17
|
-
return account;
|
|
18
|
-
}
|
|
19
18
|
const provider = account.provider ?? DEFAULT_PROVIDER;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
const credentials = Array.isArray(account.credentials)
|
|
20
|
+
? [...account.credentials]
|
|
21
|
+
: [];
|
|
22
|
+
const providers = new Set(credentials.map((credential) => credential.provider));
|
|
23
|
+
|
|
24
|
+
const addCredential = (credential: NonNullable<AccountConfig["credentials"]>[number]): void => {
|
|
25
|
+
if (providers.has(credential.provider)) return;
|
|
26
|
+
credentials.push(credential);
|
|
27
|
+
providers.add(credential.provider);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
typeof account.apiKey === "string" &&
|
|
32
|
+
account.apiKey.trim() !== ""
|
|
33
|
+
) {
|
|
34
|
+
if (!providers.has(provider)) {
|
|
35
|
+
addCredential({
|
|
36
|
+
provider,
|
|
28
37
|
apiKey: account.apiKey,
|
|
29
38
|
proxyUrl: account.proxyUrl,
|
|
30
|
-
}
|
|
31
|
-
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
32
41
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
!providers.has("openai-codex") &&
|
|
45
|
+
(provider === "openai-codex" ||
|
|
46
|
+
typeof account.codexRefreshToken === "string" ||
|
|
47
|
+
typeof account.codexAccountId === "string")
|
|
48
|
+
) {
|
|
49
|
+
addCredential({
|
|
50
|
+
provider: "openai-codex",
|
|
51
|
+
refreshToken: account.codexRefreshToken ?? account.refreshToken,
|
|
52
|
+
providerAccountId: account.codexAccountId,
|
|
53
|
+
proxyUrl: account.proxyUrl,
|
|
54
|
+
});
|
|
46
55
|
}
|
|
56
|
+
|
|
57
|
+
// A projectId/projectSource is unambiguously an Antigravity legacy field.
|
|
58
|
+
// When the legacy provider was not Codex, refreshToken is sufficient too.
|
|
59
|
+
// Codex also used a top-level refreshToken historically, so do not reinterpret
|
|
60
|
+
// that field as Google unless there is a Google-specific marker.
|
|
61
|
+
const hasLegacyGoogleFields =
|
|
62
|
+
account.projectId !== undefined ||
|
|
63
|
+
account.projectSource !== undefined ||
|
|
64
|
+
(provider !== "openai-codex" && account.refreshToken !== undefined);
|
|
65
|
+
if (!providers.has(DEFAULT_PROVIDER) && hasLegacyGoogleFields) {
|
|
66
|
+
addCredential({
|
|
67
|
+
provider: DEFAULT_PROVIDER,
|
|
68
|
+
refreshToken: account.refreshToken,
|
|
69
|
+
projectId: account.projectId,
|
|
70
|
+
projectSource: account.projectSource,
|
|
71
|
+
proxyUrl: account.proxyUrl,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (credentials.length > 0) {
|
|
76
|
+
const sorted = sortAccountCredentials(credentials);
|
|
77
|
+
if (
|
|
78
|
+
Array.isArray(account.credentials) &&
|
|
79
|
+
credentials.length === account.credentials.length &&
|
|
80
|
+
JSON.stringify(sorted) === JSON.stringify(account.credentials)
|
|
81
|
+
) {
|
|
82
|
+
return account;
|
|
83
|
+
}
|
|
84
|
+
return { ...account, credentials: sorted };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Mirror the flat legacy fields onto the parent-account credentials and
|
|
88
|
+
// KEEP the top-level fields: Google reads (forward/quota/index) still
|
|
89
|
+
// consult them, so both shapes coexist until the runtime migrates.
|
|
47
90
|
return account;
|
|
48
91
|
}
|
package/src/dashboard.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
deleteVirtualKey,
|
|
16
16
|
} from "./virtual-keys.js";
|
|
17
17
|
import { getSpendLogs, getDailySpendSummary, getSpendByKey } from "./spend-logger.js";
|
|
18
|
+
import { buildOpenAIModelCatalog } from "./compat.js";
|
|
18
19
|
import { logger } from "./logger.js";
|
|
19
20
|
|
|
20
21
|
const dashboardLogger = logger.child("dashboard");
|
|
@@ -47,7 +48,7 @@ export function serveDashboard(res: ServerResponse): void {
|
|
|
47
48
|
export function serveStaticCss(res: ServerResponse): void {
|
|
48
49
|
res.writeHead(200, {
|
|
49
50
|
"Content-Type": "text/css; charset=utf-8",
|
|
50
|
-
"Cache-Control": "
|
|
51
|
+
"Cache-Control": "no-cache, must-revalidate",
|
|
51
52
|
});
|
|
52
53
|
res.end(DASHBOARD_CSS);
|
|
53
54
|
}
|
|
@@ -55,7 +56,7 @@ export function serveStaticCss(res: ServerResponse): void {
|
|
|
55
56
|
export function serveStaticJs(res: ServerResponse): void {
|
|
56
57
|
res.writeHead(200, {
|
|
57
58
|
"Content-Type": "application/javascript; charset=utf-8",
|
|
58
|
-
"Cache-Control": "
|
|
59
|
+
"Cache-Control": "no-cache, must-revalidate",
|
|
59
60
|
});
|
|
60
61
|
res.end(DASHBOARD_JS);
|
|
61
62
|
}
|
|
@@ -63,7 +64,7 @@ export function serveStaticJs(res: ServerResponse): void {
|
|
|
63
64
|
export function serveStaticKeysJs(res: ServerResponse): void {
|
|
64
65
|
res.writeHead(200, {
|
|
65
66
|
"Content-Type": "application/javascript; charset=utf-8",
|
|
66
|
-
"Cache-Control": "
|
|
67
|
+
"Cache-Control": "no-cache, must-revalidate",
|
|
67
68
|
});
|
|
68
69
|
res.end(DASHBOARD_KEYS_JS);
|
|
69
70
|
}
|
|
@@ -71,7 +72,7 @@ export function serveStaticKeysJs(res: ServerResponse): void {
|
|
|
71
72
|
export function serveStaticLogsJs(res: ServerResponse): void {
|
|
72
73
|
res.writeHead(200, {
|
|
73
74
|
"Content-Type": "application/javascript; charset=utf-8",
|
|
74
|
-
"Cache-Control": "
|
|
75
|
+
"Cache-Control": "no-cache, must-revalidate",
|
|
75
76
|
});
|
|
76
77
|
res.end(DASHBOARD_LOGS_JS);
|
|
77
78
|
}
|
|
@@ -108,6 +109,33 @@ export function serveConfigApi(
|
|
|
108
109
|
res.end(JSON.stringify(rotator.getConfig()));
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Admin /api/models — returns the full provider model catalog grouped by
|
|
114
|
+
* provider. Powers the "Allowed Models" checkboxes in the Generate/Edit
|
|
115
|
+
* Virtual Key modal so the dashboard can show models from every active
|
|
116
|
+
* provider (Google Antigravity, Ollama, OpenAI Codex, OpenCode Zen) instead
|
|
117
|
+
* of the legacy hardcoded list.
|
|
118
|
+
*
|
|
119
|
+
* The shape mirrors /v1/models so the client can reuse metadata for tooltips.
|
|
120
|
+
*/
|
|
121
|
+
export function serveModelsApi(
|
|
122
|
+
res: ServerResponse,
|
|
123
|
+
rotator: AccountRotator,
|
|
124
|
+
): void {
|
|
125
|
+
const catalog = buildOpenAIModelCatalog(rotator);
|
|
126
|
+
res.writeHead(200, {
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
"Cache-Control": "no-store",
|
|
129
|
+
});
|
|
130
|
+
res.end(
|
|
131
|
+
JSON.stringify({
|
|
132
|
+
ok: true,
|
|
133
|
+
count: catalog.length,
|
|
134
|
+
data: catalog,
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
111
139
|
export function serveConfigExportApi(
|
|
112
140
|
res: ServerResponse,
|
|
113
141
|
rotator: AccountRotator,
|
|
@@ -897,44 +925,17 @@ const DASHBOARD_KEYS_HTML = renderAppShell({
|
|
|
897
925
|
</div>
|
|
898
926
|
</div>
|
|
899
927
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
<label class="model-card"><input type="checkbox" value="gemini-3.5-flash-medium" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gemini-3.5-flash-medium</span></label>
|
|
912
|
-
<label class="model-card"><input type="checkbox" value="gemini-3.5-flash-high" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gemini-3.5-flash-high</span></label>
|
|
913
|
-
<label class="model-card"><input type="checkbox" value="gemini-3-flash" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gemini-3-flash</span></label>
|
|
914
|
-
</div>
|
|
915
|
-
</div>
|
|
916
|
-
<div class="model-category">
|
|
917
|
-
<div class="cat-title">Gemini 3.6 Flash</div>
|
|
918
|
-
<div class="cat-grid">
|
|
919
|
-
<label class="model-card"><input type="checkbox" value="gemini-3.6-flash-low" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gemini-3.6-flash-low</span></label>
|
|
920
|
-
<label class="model-card"><input type="checkbox" value="gemini-3.6-flash-medium" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gemini-3.6-flash-medium</span></label>
|
|
921
|
-
<label class="model-card"><input type="checkbox" value="gemini-3.6-flash-high" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gemini-3.6-flash-high</span></label>
|
|
922
|
-
<label class="model-card"><input type="checkbox" value="gemini-3.6-flash-tiered" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gemini-3.6-flash-tiered</span></label>
|
|
923
|
-
</div>
|
|
924
|
-
</div>
|
|
925
|
-
<div class="model-category">
|
|
926
|
-
<div class="cat-title">Claude</div>
|
|
927
|
-
<div class="cat-grid">
|
|
928
|
-
<label class="model-card"><input type="checkbox" value="claude-sonnet-4-6" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">claude-sonnet-4-6</span></label>
|
|
929
|
-
<label class="model-card"><input type="checkbox" value="claude-opus-4-6-thinking" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">claude-opus-4-6-thinking</span></label>
|
|
930
|
-
</div>
|
|
931
|
-
</div>
|
|
932
|
-
<div class="model-category">
|
|
933
|
-
<div class="cat-title">GPT-OSS</div>
|
|
934
|
-
<div class="cat-grid">
|
|
935
|
-
<label class="model-card"><input type="checkbox" value="gpt-oss-120b-medium" class="modelCb" onchange="updateModelsCountBadge()"><span class="model-name">gpt-oss-120b-medium</span></label>
|
|
936
|
-
</div>
|
|
937
|
-
</div>
|
|
928
|
+
<!--
|
|
929
|
+
The model grid is populated dynamically by dashboard-keys.js from
|
|
930
|
+
GET /api/models, which returns the live provider catalog (Google
|
|
931
|
+
Antigravity + every active Ollama / OpenAI Codex / OpenCode Zen
|
|
932
|
+
account). Each entry is grouped by its owned_by provider so the
|
|
933
|
+
checkbox UI surfaces every model the rotator can actually route
|
|
934
|
+
today, including those added by future providers.
|
|
935
|
+
-->
|
|
936
|
+
<div class="model-grid" id="modelGrid"></div>
|
|
937
|
+
<div class="model-grid-empty" id="modelGridEmpty" style="display:none;color:var(--text-dim);font-size:0.85rem;padding:8px 0">
|
|
938
|
+
No models available. Configure a provider or refresh.
|
|
938
939
|
</div>
|
|
939
940
|
</div>
|
|
940
941
|
|
package/src/index.ts
CHANGED
|
@@ -211,6 +211,7 @@ export async function main(): Promise<void> {
|
|
|
211
211
|
|
|
212
212
|
const rotator = new AccountRotator(config);
|
|
213
213
|
await rotator.primeOllamaCatalog();
|
|
214
|
+
await rotator.primeCodexCatalog();
|
|
214
215
|
|
|
215
216
|
// ── Telemetry (anonymous, opt-out via TUXEVIL_ROTATOR_TELEMETRY=off) ──
|
|
216
217
|
const telemetry = new TelemetryReporter(() => {
|