tuxevil-rotator 4.0.0 → 4.1.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 +6 -1
- package/package.json +1 -1
- package/src/audio-transcription.ts +44 -4
- package/src/compat.ts +196 -222
- package/src/config-defaults.ts +5 -0
- package/src/dashboard-live.ts +10 -8
- package/src/dashboard-types.ts +39 -1
- package/src/dashboard.ts +156 -1
- package/src/model-catalog-revision.ts +17 -0
- package/src/model-catalog.ts +302 -0
- package/src/providers/adapter.ts +18 -0
- package/src/providers/google-antigravity/catalog.ts +190 -1
- package/src/providers/google-antigravity/forward.ts +2 -0
- package/src/providers/google-antigravity/index.ts +11 -0
- package/src/providers/google-antigravity/translators.ts +4 -0
- package/src/providers/ollama/index.ts +11 -1
- package/src/providers/ollama/quota-poll-store.ts +22 -1
- package/src/providers/ollama/quota.ts +95 -23
- package/src/providers/openai-codex/index.ts +18 -2
- package/src/providers/opencode-zen/index.ts +11 -2
- package/src/proxy.ts +143 -28
- package/src/rotator.ts +219 -10
- package/src/settings-repository.ts +36 -5
- package/src/types.ts +68 -26
- package/src/validators.ts +35 -0
- package/src/web/app.tsx +4 -0
- package/src/web/components/icons.tsx +29 -0
- package/src/web/components/ui.tsx +6 -1
- package/src/web/lib/accounts.ts +1 -0
- package/src/web/lib/attention.ts +12 -0
- package/src/web/lib/models.ts +279 -0
- package/src/web/lib/pools.ts +53 -9
- package/src/web/lib/status.ts +13 -3
- package/src/web/nav.ts +1 -0
- package/src/web/pages/AccountDetail.tsx +16 -2
- package/src/web/pages/Models.tsx +852 -0
- package/src/web/pages/Overview.tsx +31 -15
- package/src/web/pages/Usage.tsx +3 -3
- package/src/web/state/api.ts +18 -0
- package/src/web/state/model-catalog.ts +103 -0
- package/src/web/state/router.ts +24 -16
- package/src/web/state/store.ts +6 -6
- package/src/web/styles/app.css +294 -0
package/src/compat.ts
CHANGED
|
@@ -37,14 +37,16 @@ import {
|
|
|
37
37
|
sanitizeGeminiSchema,
|
|
38
38
|
sanitizeClaudeViaGeminiSchema,
|
|
39
39
|
} from "./compat/schema-sanitizer.js";
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
getEffectiveAntigravityModels,
|
|
42
|
+
type CompatModelEntry,
|
|
43
|
+
} from "./providers/google-antigravity/catalog.js";
|
|
41
44
|
import {
|
|
42
45
|
DEFAULT_MODEL_SPECS,
|
|
43
46
|
setModelSpecsOverride,
|
|
44
47
|
getActiveModelSpecs,
|
|
45
48
|
getModelFamily,
|
|
46
49
|
getModelSpec,
|
|
47
|
-
getModelSpecOverride,
|
|
48
50
|
isThinkingModel,
|
|
49
51
|
} from "./compat/model-specs.js";
|
|
50
52
|
import type { ModelSpec } from "./compat/model-specs.js";
|
|
@@ -109,6 +111,14 @@ import {
|
|
|
109
111
|
type AutoRoutingCatalogEntry,
|
|
110
112
|
type AutoRoutingRoute,
|
|
111
113
|
} from "./auto-routing.js";
|
|
114
|
+
import {
|
|
115
|
+
isModelServed,
|
|
116
|
+
isProviderTurnedOff,
|
|
117
|
+
isRequestOff,
|
|
118
|
+
modelOffMessage,
|
|
119
|
+
resolveModelRoute,
|
|
120
|
+
type ModelCatalogSource,
|
|
121
|
+
} from "./model-catalog.js";
|
|
112
122
|
|
|
113
123
|
function isCodexModelForRotator(rotator: AccountRotator, model: string): boolean {
|
|
114
124
|
if (isCodexRequestModel(model)) return true;
|
|
@@ -124,6 +134,50 @@ function isAutoModel(model: string): boolean {
|
|
|
124
134
|
return model.trim().toLowerCase() === "auto";
|
|
125
135
|
}
|
|
126
136
|
|
|
137
|
+
type CompatRoute =
|
|
138
|
+
| { off: true }
|
|
139
|
+
| { off: false; providerId: string; pinned: boolean; modelId?: string };
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Provider for a request that names a model. Ids a provider lists follow the
|
|
143
|
+
* Models page (provider order, switches) and are pinned to that provider; other
|
|
144
|
+
* ids keep the long-standing checks: Codex, Zen, Ollama, then Antigravity.
|
|
145
|
+
*/
|
|
146
|
+
function compatRoute(rotator: AccountRotator, model: string): CompatRoute {
|
|
147
|
+
const route = resolveModelRoute(rotator, model);
|
|
148
|
+
if (route.kind === "off") return { off: true };
|
|
149
|
+
if (route.kind === "provider") {
|
|
150
|
+
// Ids match case-insensitively; send the provider's own casing upstream.
|
|
151
|
+
const sameId = route.modelId.toLowerCase() === model.toLowerCase();
|
|
152
|
+
return { off: false, providerId: route.providerId, pinned: true, ...(sameId ? { modelId: route.modelId } : {}) };
|
|
153
|
+
}
|
|
154
|
+
if (isCodexModelForRotator(rotator, model)) return { off: false, providerId: "openai-codex", pinned: false };
|
|
155
|
+
if (isOpenCodeZenModel(model)) return { off: false, providerId: OPENCODE_ZEN_PROVIDER_ID, pinned: false };
|
|
156
|
+
if (rotator?.getOllamaModels?.().includes(model)) return { off: false, providerId: "ollama", pinned: false };
|
|
157
|
+
return { off: false, providerId: "google-antigravity", pinned: false };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Wire format of an upstream response, from the provider that actually served
|
|
162
|
+
* it. Zen output is normalized to Chat Completions by its forwarder.
|
|
163
|
+
*/
|
|
164
|
+
function upstreamFormat(context: RotationAttemptContext): "google" | "ollama" | "opencode-zen" {
|
|
165
|
+
if (context.providerId === OPENCODE_ZEN_PROVIDER_ID) return "opencode-zen";
|
|
166
|
+
if (context.providerId === "ollama") return "ollama";
|
|
167
|
+
return "google";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function openAIModelOff(res: ServerResponse, model: string): void {
|
|
171
|
+
writeJson(res, 404, {
|
|
172
|
+
error: {
|
|
173
|
+
message: modelOffMessage(model),
|
|
174
|
+
type: "invalid_request_error",
|
|
175
|
+
param: "model",
|
|
176
|
+
code: "model_not_found",
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
127
181
|
function authorizeResolvedAutoModel(
|
|
128
182
|
res: ServerResponse,
|
|
129
183
|
auth: Awaited<ReturnType<typeof authenticateVirtualKey>>,
|
|
@@ -143,6 +197,15 @@ function authorizeResolvedAutoModel(
|
|
|
143
197
|
function buildAutoRoutingCatalog(
|
|
144
198
|
rotator: AccountRotator,
|
|
145
199
|
route: AutoRoutingRoute,
|
|
200
|
+
): AutoRoutingCatalogEntry[] {
|
|
201
|
+
return buildAllAutoRoutingCandidates(rotator, route).filter((entry) =>
|
|
202
|
+
isModelServed(rotator, entry.providerId, entry.modelId),
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function buildAllAutoRoutingCandidates(
|
|
207
|
+
rotator: AccountRotator,
|
|
208
|
+
route: AutoRoutingRoute,
|
|
146
209
|
): AutoRoutingCatalogEntry[] {
|
|
147
210
|
const catalog: AutoRoutingCatalogEntry[] = getEffectiveAntigravityModels()
|
|
148
211
|
.filter((model) => !["whisper-1", "proactive-observer", "proactive-observer-v10", "models/proactive-observer-v10"].includes(model.id.toLowerCase()))
|
|
@@ -2235,11 +2298,7 @@ async function completeResponsesViaRotator(
|
|
|
2235
2298
|
context,
|
|
2236
2299
|
rotator,
|
|
2237
2300
|
options?.compressionStats,
|
|
2238
|
-
|
|
2239
|
-
? "opencode-zen"
|
|
2240
|
-
: body.providerId === "ollama" || (rotator?.getOllamaModels?.() ?? []).includes(body.model)
|
|
2241
|
-
? "ollama"
|
|
2242
|
-
: "google",
|
|
2301
|
+
upstreamFormat(context),
|
|
2243
2302
|
);
|
|
2244
2303
|
if (completion.inputTokens > 0 || completion.outputTokens > 0) {
|
|
2245
2304
|
rotator.recordTokenUsage(
|
|
@@ -2311,8 +2370,6 @@ async function completeViaRotator(
|
|
|
2311
2370
|
isDeduplicated?: boolean;
|
|
2312
2371
|
compressionStats?: CompressionStats | null;
|
|
2313
2372
|
}> {
|
|
2314
|
-
const ollamaModels = rotator?.getOllamaModels?.() ?? [];
|
|
2315
|
-
const isOllamaUpstream = (model: string): boolean => body.providerId === "ollama" || ollamaModels.includes(model);
|
|
2316
2373
|
const cfg = typeof rotator?.getConfig === "function" ? rotator.getConfig() : undefined;
|
|
2317
2374
|
const enabled = cfg?.idempotencyEnabled === true;
|
|
2318
2375
|
const windowMs = cfg?.idempotencyWindowMs ?? 2000;
|
|
@@ -2332,9 +2389,10 @@ async function completeViaRotator(
|
|
|
2332
2389
|
async (response, context) => {
|
|
2333
2390
|
if (streamMode === "none") {
|
|
2334
2391
|
const raw = await response.text();
|
|
2335
|
-
const
|
|
2392
|
+
const format = upstreamFormat(context);
|
|
2393
|
+
const completion = format === "opencode-zen"
|
|
2336
2394
|
? parseOpenAiJson(raw)
|
|
2337
|
-
:
|
|
2395
|
+
: format === "ollama"
|
|
2338
2396
|
? parseOllamaNdjson(raw)
|
|
2339
2397
|
: parseAntigravitySse(raw);
|
|
2340
2398
|
if (completion.inputTokens > 0 || completion.outputTokens > 0) {
|
|
@@ -2366,11 +2424,7 @@ async function completeViaRotator(
|
|
|
2366
2424
|
context,
|
|
2367
2425
|
rotator,
|
|
2368
2426
|
options?.compressionStats,
|
|
2369
|
-
|
|
2370
|
-
? "opencode-zen"
|
|
2371
|
-
: isOllamaUpstream(body.model)
|
|
2372
|
-
? "ollama"
|
|
2373
|
-
: "google",
|
|
2427
|
+
upstreamFormat(context),
|
|
2374
2428
|
);
|
|
2375
2429
|
if (completion.inputTokens > 0 || completion.outputTokens > 0) {
|
|
2376
2430
|
rotator.recordTokenUsage(
|
|
@@ -2453,136 +2507,8 @@ async function completeViaRotator(
|
|
|
2453
2507
|
};
|
|
2454
2508
|
}
|
|
2455
2509
|
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
id: "gemini-3-flash",
|
|
2459
|
-
family: "gemini-3-flash",
|
|
2460
|
-
ctx: 1048576,
|
|
2461
|
-
quotaPool: "gemini",
|
|
2462
|
-
multimodal: true,
|
|
2463
|
-
tools: true,
|
|
2464
|
-
},
|
|
2465
|
-
{
|
|
2466
|
-
id: "gemini-3.6-flash-high",
|
|
2467
|
-
family: "gemini-3.6-flash",
|
|
2468
|
-
ctx: 1048576,
|
|
2469
|
-
quotaPool: "gemini",
|
|
2470
|
-
multimodal: true,
|
|
2471
|
-
tools: true,
|
|
2472
|
-
},
|
|
2473
|
-
{
|
|
2474
|
-
id: "gemini-3.6-flash-medium",
|
|
2475
|
-
family: "gemini-3.6-flash",
|
|
2476
|
-
ctx: 1048576,
|
|
2477
|
-
quotaPool: "gemini",
|
|
2478
|
-
multimodal: true,
|
|
2479
|
-
tools: true,
|
|
2480
|
-
},
|
|
2481
|
-
{
|
|
2482
|
-
id: "gemini-3.6-flash-low",
|
|
2483
|
-
family: "gemini-3.6-flash",
|
|
2484
|
-
ctx: 1048576,
|
|
2485
|
-
quotaPool: "gemini",
|
|
2486
|
-
multimodal: true,
|
|
2487
|
-
tools: true,
|
|
2488
|
-
},
|
|
2489
|
-
{
|
|
2490
|
-
id: "gemini-3.6-flash-tiered",
|
|
2491
|
-
family: "gemini-3.6-flash",
|
|
2492
|
-
ctx: 1048576,
|
|
2493
|
-
quotaPool: "gemini",
|
|
2494
|
-
multimodal: true,
|
|
2495
|
-
tools: true,
|
|
2496
|
-
},
|
|
2497
|
-
{
|
|
2498
|
-
id: "gemini-3.7-flash-tiered",
|
|
2499
|
-
family: "gemini-3.7-flash",
|
|
2500
|
-
ctx: 1048576,
|
|
2501
|
-
quotaPool: "gemini",
|
|
2502
|
-
multimodal: true,
|
|
2503
|
-
tools: true,
|
|
2504
|
-
},
|
|
2505
|
-
{
|
|
2506
|
-
id: "gemini-3.8-flash-high",
|
|
2507
|
-
family: "gemini-3.8-flash",
|
|
2508
|
-
ctx: 1048576,
|
|
2509
|
-
quotaPool: "gemini",
|
|
2510
|
-
multimodal: true,
|
|
2511
|
-
tools: true,
|
|
2512
|
-
},
|
|
2513
|
-
{
|
|
2514
|
-
id: "gemini-3.8-flash-medium",
|
|
2515
|
-
family: "gemini-3.8-flash",
|
|
2516
|
-
ctx: 1048576,
|
|
2517
|
-
quotaPool: "gemini",
|
|
2518
|
-
multimodal: true,
|
|
2519
|
-
tools: true,
|
|
2520
|
-
},
|
|
2521
|
-
{
|
|
2522
|
-
id: "gemini-3.8-flash-low",
|
|
2523
|
-
family: "gemini-3.8-flash",
|
|
2524
|
-
ctx: 1048576,
|
|
2525
|
-
quotaPool: "gemini",
|
|
2526
|
-
multimodal: true,
|
|
2527
|
-
tools: true,
|
|
2528
|
-
},
|
|
2529
|
-
{
|
|
2530
|
-
id: "gemini-3.1-pro-low",
|
|
2531
|
-
family: "gemini-3.1-pro",
|
|
2532
|
-
ctx: 1048576,
|
|
2533
|
-
quotaPool: "gemini",
|
|
2534
|
-
multimodal: true,
|
|
2535
|
-
tools: true,
|
|
2536
|
-
},
|
|
2537
|
-
{
|
|
2538
|
-
id: "gemini-3.1-pro-high",
|
|
2539
|
-
family: "gemini-3.1-pro",
|
|
2540
|
-
ctx: 1048576,
|
|
2541
|
-
quotaPool: "gemini",
|
|
2542
|
-
multimodal: true,
|
|
2543
|
-
tools: true,
|
|
2544
|
-
},
|
|
2545
|
-
{
|
|
2546
|
-
id: "claude-sonnet-4-6",
|
|
2547
|
-
family: "claude",
|
|
2548
|
-
ctx: 1000000,
|
|
2549
|
-
quotaPool: "claude",
|
|
2550
|
-
multimodal: true,
|
|
2551
|
-
tools: true,
|
|
2552
|
-
},
|
|
2553
|
-
{
|
|
2554
|
-
id: "claude-opus-4-6-thinking",
|
|
2555
|
-
family: "claude",
|
|
2556
|
-
ctx: 1000000,
|
|
2557
|
-
quotaPool: "claude",
|
|
2558
|
-
multimodal: true,
|
|
2559
|
-
tools: true,
|
|
2560
|
-
},
|
|
2561
|
-
{
|
|
2562
|
-
id: "gpt-oss-120b-medium",
|
|
2563
|
-
family: "gpt-oss",
|
|
2564
|
-
ctx: 131072,
|
|
2565
|
-
quotaPool: "claude",
|
|
2566
|
-
multimodal: false,
|
|
2567
|
-
tools: true,
|
|
2568
|
-
},
|
|
2569
|
-
{
|
|
2570
|
-
id: "gemini-3.5-flash-lite",
|
|
2571
|
-
family: "gemini-3.5-flash",
|
|
2572
|
-
ctx: 1048576,
|
|
2573
|
-
quotaPool: "gemini",
|
|
2574
|
-
multimodal: true,
|
|
2575
|
-
tools: true,
|
|
2576
|
-
},
|
|
2577
|
-
{
|
|
2578
|
-
id: "whisper-1",
|
|
2579
|
-
family: "gemini-3.8-flash",
|
|
2580
|
-
ctx: 1048576,
|
|
2581
|
-
quotaPool: "gemini",
|
|
2582
|
-
multimodal: true,
|
|
2583
|
-
tools: false,
|
|
2584
|
-
},
|
|
2585
|
-
] as const;
|
|
2510
|
+
export { getEffectiveAntigravityModels };
|
|
2511
|
+
export type { CompatModelEntry };
|
|
2586
2512
|
|
|
2587
2513
|
export interface OpenAIModelCatalogEntry {
|
|
2588
2514
|
id: string;
|
|
@@ -2594,58 +2520,12 @@ export interface OpenAIModelCatalogEntry {
|
|
|
2594
2520
|
meta: Record<string, unknown>;
|
|
2595
2521
|
}
|
|
2596
2522
|
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
tools: boolean;
|
|
2604
|
-
maxOutputTokens: number;
|
|
2605
|
-
thinkingBudget: number;
|
|
2606
|
-
minThinkingBudget?: number;
|
|
2607
|
-
isThinking: boolean;
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
|
-
export function getEffectiveAntigravityModels(): CompatModelEntry[] {
|
|
2611
|
-
const dynamic = dynamicCatalog.getAllModels();
|
|
2612
|
-
const seen = new Set(MODEL_CATALOG.map((model) => model.id.toLowerCase()));
|
|
2613
|
-
const result: CompatModelEntry[] = MODEL_CATALOG.map((model) => {
|
|
2614
|
-
const spec = getModelSpec(model.id);
|
|
2615
|
-
const contextWindow = getModelSpecOverride(model.id)?.contextWindow ??
|
|
2616
|
-
dynamicCatalog.getModelSpec(model.id)?.contextWindow;
|
|
2617
|
-
return {
|
|
2618
|
-
...model,
|
|
2619
|
-
ctx: contextWindow ?? model.ctx,
|
|
2620
|
-
maxOutputTokens: spec.maxOutputTokens,
|
|
2621
|
-
thinkingBudget: spec.thinkingBudget,
|
|
2622
|
-
minThinkingBudget: spec.minThinkingBudget,
|
|
2623
|
-
isThinking: spec.isThinking,
|
|
2624
|
-
};
|
|
2625
|
-
});
|
|
2626
|
-
for (const m of dynamic) {
|
|
2627
|
-
if (seen.has(m.id.toLowerCase())) continue;
|
|
2628
|
-
seen.add(m.id.toLowerCase());
|
|
2629
|
-
const spec = getModelSpec(m.id);
|
|
2630
|
-
result.push({
|
|
2631
|
-
id: m.id,
|
|
2632
|
-
family: m.family,
|
|
2633
|
-
ctx: spec.contextWindow ?? m.ctx,
|
|
2634
|
-
quotaPool: m.quotaPool,
|
|
2635
|
-
multimodal: m.multimodal,
|
|
2636
|
-
tools: m.tools,
|
|
2637
|
-
maxOutputTokens: spec.maxOutputTokens,
|
|
2638
|
-
thinkingBudget: spec.thinkingBudget,
|
|
2639
|
-
minThinkingBudget: spec.minThinkingBudget,
|
|
2640
|
-
isThinking: spec.isThinking,
|
|
2641
|
-
});
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
return result;
|
|
2645
|
-
}
|
|
2646
|
-
|
|
2647
|
-
function getOpenAIAntigravityModels(): CompatModelEntry[] {
|
|
2648
|
-
const result = getEffectiveAntigravityModels();
|
|
2523
|
+
function getOpenAIAntigravityModels(
|
|
2524
|
+
source: ModelCatalogSource,
|
|
2525
|
+
): CompatModelEntry[] {
|
|
2526
|
+
// Effort aliases stand in for their targets, so filter before swapping them.
|
|
2527
|
+
const all = getEffectiveAntigravityModels();
|
|
2528
|
+
const result = all.filter((model) => isModelServed(source, "google-antigravity", model.id));
|
|
2649
2529
|
const rules = getEffortRouting();
|
|
2650
2530
|
if (!rules || Object.keys(rules).length === 0) {
|
|
2651
2531
|
return result;
|
|
@@ -2657,6 +2537,7 @@ function getOpenAIAntigravityModels(): CompatModelEntry[] {
|
|
|
2657
2537
|
}> = [];
|
|
2658
2538
|
const hiddenTargetIds = new Set<string>();
|
|
2659
2539
|
const successfulAliasNames = new Set<string>();
|
|
2540
|
+
const unavailableAliasNames = new Set<string>();
|
|
2660
2541
|
|
|
2661
2542
|
for (const [alias, rule] of Object.entries(rules)) {
|
|
2662
2543
|
const defaultEffortKey = rule.defaultEffort;
|
|
@@ -2667,13 +2548,31 @@ function getOpenAIAntigravityModels(): CompatModelEntry[] {
|
|
|
2667
2548
|
);
|
|
2668
2549
|
continue;
|
|
2669
2550
|
}
|
|
2551
|
+
const route = resolveModelRoute(source, alias);
|
|
2552
|
+
// A live provider's exact id wins over an effort alias. Leave its catalog
|
|
2553
|
+
// entry and the unused Antigravity targets to the normal route deduplication.
|
|
2554
|
+
if (route.kind === "provider" && route.providerId !== "google-antigravity") continue;
|
|
2555
|
+
// Review applies to listed ids; an operator's unlisted alias may still
|
|
2556
|
+
// use a reviewed target. Check it like a request, including upstream aliases.
|
|
2557
|
+
if (route.kind === "off" || isRequestOff(source, {
|
|
2558
|
+
catalogModel: alias,
|
|
2559
|
+
model: defaultTargetId,
|
|
2560
|
+
providerId: "google-antigravity",
|
|
2561
|
+
})) {
|
|
2562
|
+
unavailableAliasNames.add(alias.toLowerCase());
|
|
2563
|
+
continue;
|
|
2564
|
+
}
|
|
2670
2565
|
const representative = result.find(
|
|
2671
2566
|
(m) => m.id.toLowerCase() === defaultTargetId.toLowerCase(),
|
|
2672
2567
|
);
|
|
2673
2568
|
if (!representative) {
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
)
|
|
2569
|
+
// A default target turned off on the Models page hides the alias; only
|
|
2570
|
+
// a target missing from the catalog is a configuration problem.
|
|
2571
|
+
if (!all.some((m) => m.id.toLowerCase() === defaultTargetId.toLowerCase())) {
|
|
2572
|
+
compatLogger.warn(
|
|
2573
|
+
`Effort routing alias "${alias}" default target "${defaultTargetId}" absent from catalog; skipping catalog swap`,
|
|
2574
|
+
);
|
|
2575
|
+
}
|
|
2677
2576
|
continue;
|
|
2678
2577
|
}
|
|
2679
2578
|
successfulAliases.push({ alias, representative });
|
|
@@ -2683,12 +2582,9 @@ function getOpenAIAntigravityModels(): CompatModelEntry[] {
|
|
|
2683
2582
|
}
|
|
2684
2583
|
}
|
|
2685
2584
|
|
|
2686
|
-
if (successfulAliases.length === 0) {
|
|
2687
|
-
return result;
|
|
2688
|
-
}
|
|
2689
|
-
|
|
2690
2585
|
const filtered = result.filter(
|
|
2691
2586
|
(m) =>
|
|
2587
|
+
!unavailableAliasNames.has(m.id.toLowerCase()) &&
|
|
2692
2588
|
!hiddenTargetIds.has(m.id.toLowerCase()) &&
|
|
2693
2589
|
!successfulAliasNames.has(m.id.toLowerCase()),
|
|
2694
2590
|
);
|
|
@@ -2707,12 +2603,20 @@ function getOpenAIAntigravityModels(): CompatModelEntry[] {
|
|
|
2707
2603
|
* Build the OpenAI-compatible `/v1/models` catalog for the proxy.
|
|
2708
2604
|
*
|
|
2709
2605
|
* The static Antigravity baseline and dynamically-discovered Antigravity models
|
|
2710
|
-
* are
|
|
2606
|
+
* are included unless Antigravity is turned off. An active rotator also
|
|
2607
|
+
* contributes its other providers. Models turned off on the dashboard's Models
|
|
2608
|
+
* page are left out, and an id more than one provider lists appears once, owned
|
|
2609
|
+
* by the provider its requests go to.
|
|
2711
2610
|
*/
|
|
2712
2611
|
export function buildOpenAIModelCatalog(
|
|
2713
2612
|
rotator?: AccountRotator,
|
|
2714
2613
|
): OpenAIModelCatalogEntry[] {
|
|
2715
|
-
const
|
|
2614
|
+
const source: ModelCatalogSource = rotator ?? {};
|
|
2615
|
+
const served = (providerId: string) => (id: string) => isModelServed(source, providerId, id);
|
|
2616
|
+
const antigravityModels = isProviderTurnedOff(rotator?.getConfig?.(), "google-antigravity")
|
|
2617
|
+
? []
|
|
2618
|
+
: getOpenAIAntigravityModels(source);
|
|
2619
|
+
const catalog: OpenAIModelCatalogEntry[] = antigravityModels.map(
|
|
2716
2620
|
({
|
|
2717
2621
|
id,
|
|
2718
2622
|
ctx,
|
|
@@ -2749,10 +2653,11 @@ export function buildOpenAIModelCatalog(
|
|
|
2749
2653
|
const hasActiveProvider = (providerId: string): boolean =>
|
|
2750
2654
|
rotator?.hasActiveProvider(providerId) ?? false;
|
|
2751
2655
|
const ollamaModels = hasActiveProvider("ollama")
|
|
2752
|
-
? rotator?.getOllamaModels?.() ?? []
|
|
2656
|
+
? (rotator?.getOllamaModels?.() ?? []).filter(served("ollama"))
|
|
2753
2657
|
: [];
|
|
2754
2658
|
if (hasActiveProvider("openai-codex")) {
|
|
2755
2659
|
for (const model of getCodexModels()) {
|
|
2660
|
+
if (!served("openai-codex")(model.id)) continue;
|
|
2756
2661
|
catalog.push({
|
|
2757
2662
|
id: model.id,
|
|
2758
2663
|
object: "model",
|
|
@@ -2790,6 +2695,7 @@ export function buildOpenAIModelCatalog(
|
|
|
2790
2695
|
}
|
|
2791
2696
|
if (hasActiveProvider(OPENCODE_ZEN_PROVIDER_ID)) {
|
|
2792
2697
|
for (const spec of OPENCODE_ZEN_CATALOG) {
|
|
2698
|
+
if (!served(OPENCODE_ZEN_PROVIDER_ID)(spec.id)) continue;
|
|
2793
2699
|
catalog.push({
|
|
2794
2700
|
id: spec.id,
|
|
2795
2701
|
object: "model",
|
|
@@ -2807,7 +2713,32 @@ export function buildOpenAIModelCatalog(
|
|
|
2807
2713
|
});
|
|
2808
2714
|
}
|
|
2809
2715
|
}
|
|
2810
|
-
return catalog;
|
|
2716
|
+
return dedupeByRoute(catalog, source);
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
/** Keep one entry per id: the one owned by the provider its requests go to. */
|
|
2720
|
+
function dedupeByRoute(
|
|
2721
|
+
catalog: OpenAIModelCatalogEntry[],
|
|
2722
|
+
source: ModelCatalogSource,
|
|
2723
|
+
): OpenAIModelCatalogEntry[] {
|
|
2724
|
+
const counts = new Map<string, number>();
|
|
2725
|
+
for (const entry of catalog) {
|
|
2726
|
+
const id = entry.id.toLowerCase();
|
|
2727
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
2728
|
+
}
|
|
2729
|
+
if ([...counts.values()].every((count) => count === 1)) return catalog;
|
|
2730
|
+
const ownerOf = (providerId: string) =>
|
|
2731
|
+
providerId === "google-antigravity" ? "tuxevil-rotator" : providerId;
|
|
2732
|
+
const kept = new Set<string>();
|
|
2733
|
+
return catalog.filter((entry) => {
|
|
2734
|
+
const id = entry.id.toLowerCase();
|
|
2735
|
+
if (counts.get(id) === 1) return true;
|
|
2736
|
+
if (kept.has(id)) return false;
|
|
2737
|
+
const route = resolveModelRoute(source, entry.id);
|
|
2738
|
+
if (route.kind === "provider" && ownerOf(route.providerId) !== entry.owned_by) return false;
|
|
2739
|
+
kept.add(id);
|
|
2740
|
+
return true;
|
|
2741
|
+
});
|
|
2811
2742
|
}
|
|
2812
2743
|
|
|
2813
2744
|
export function serveOpenAIModels(
|
|
@@ -2817,9 +2748,15 @@ export function serveOpenAIModels(
|
|
|
2817
2748
|
writeJson(res, 200, { object: "list", data: buildOpenAIModelCatalog(rotator) });
|
|
2818
2749
|
}
|
|
2819
2750
|
|
|
2820
|
-
export function serveGeminiModels(res: ServerResponse): void {
|
|
2751
|
+
export function serveGeminiModels(res: ServerResponse, rotator?: AccountRotator): void {
|
|
2752
|
+
const source: ModelCatalogSource = rotator ?? {};
|
|
2753
|
+
const models = isProviderTurnedOff(rotator?.getConfig?.(), "google-antigravity")
|
|
2754
|
+
? []
|
|
2755
|
+
: getEffectiveAntigravityModels().filter((model) =>
|
|
2756
|
+
isModelServed(source, "google-antigravity", model.id),
|
|
2757
|
+
);
|
|
2821
2758
|
writeJson(res, 200, {
|
|
2822
|
-
models:
|
|
2759
|
+
models: models.map(
|
|
2823
2760
|
({
|
|
2824
2761
|
id,
|
|
2825
2762
|
ctx,
|
|
@@ -2910,6 +2847,11 @@ export async function handleGeminiGenerateContent(
|
|
|
2910
2847
|
}
|
|
2911
2848
|
if (autoSelection && !authorizeResolvedAutoModel(res, auth, autoSelection.model)) return;
|
|
2912
2849
|
const selectedModel = autoSelection?.model ?? model;
|
|
2850
|
+
if (isRequestOff(rotator, { model: selectedModel, providerId: autoSelection?.providerId })) {
|
|
2851
|
+
return writeJson(res, 404, {
|
|
2852
|
+
error: { code: 404, message: modelOffMessage(model), status: "NOT_FOUND" },
|
|
2853
|
+
});
|
|
2854
|
+
}
|
|
2913
2855
|
|
|
2914
2856
|
const body: RequestBody = {
|
|
2915
2857
|
model: selectedModel,
|
|
@@ -3040,11 +2982,15 @@ export async function handleOpenAIChatCompletions(
|
|
|
3040
2982
|
});
|
|
3041
2983
|
}
|
|
3042
2984
|
if (autoSelection && !authorizeResolvedAutoModel(res, auth, autoSelection.model)) return;
|
|
2985
|
+
const route: CompatRoute = autoSelection
|
|
2986
|
+
? { off: false, providerId: autoSelection.providerId, pinned: true }
|
|
2987
|
+
: compatRoute(rotator, requestedModel);
|
|
2988
|
+
if (route.off) return openAIModelOff(res, requestedModel);
|
|
3043
2989
|
const routedRequest = autoSelection
|
|
3044
2990
|
? { ...validation.value, model: autoSelection.model }
|
|
3045
|
-
: validation.value;
|
|
2991
|
+
: { ...validation.value, model: route.modelId ?? requestedModel };
|
|
3046
2992
|
|
|
3047
|
-
if (
|
|
2993
|
+
if (route.providerId === "openai-codex") {
|
|
3048
2994
|
await serveCodexChat(req, res, rotator, routedRequest, {
|
|
3049
2995
|
callType: "chat_completion",
|
|
3050
2996
|
apiKeyHash,
|
|
@@ -3074,11 +3020,13 @@ export async function handleOpenAIChatCompletions(
|
|
|
3074
3020
|
|
|
3075
3021
|
const started = Date.now();
|
|
3076
3022
|
const streamMode = routedRequest.stream ? "openai" : "none";
|
|
3077
|
-
const bodyToForward: RequestBody =
|
|
3023
|
+
const bodyToForward: RequestBody = route.providerId === OPENCODE_ZEN_PROVIDER_ID
|
|
3078
3024
|
? { project: "", model: chatReq.model, request: chatReq, requestType: "openai-chat" }
|
|
3079
|
-
: (
|
|
3025
|
+
: (route.providerId === "ollama"
|
|
3080
3026
|
? openAIToOllamaBody(chatReq)
|
|
3081
3027
|
: openAIToAntigravityBody(chatReq));
|
|
3028
|
+
if (route.pinned) bodyToForward.providerId = route.providerId;
|
|
3029
|
+
if (isRequestOff(rotator, bodyToForward)) return openAIModelOff(res, requestedModel);
|
|
3082
3030
|
if (autoSelection) {
|
|
3083
3031
|
bodyToForward.displayModel = requestedModel;
|
|
3084
3032
|
bodyToForward.providerId = autoSelection.providerId;
|
|
@@ -3230,11 +3178,15 @@ export async function handleOpenAIResponsesCreate(
|
|
|
3230
3178
|
});
|
|
3231
3179
|
}
|
|
3232
3180
|
if (autoSelection && !authorizeResolvedAutoModel(res, auth, autoSelection.model)) return;
|
|
3181
|
+
const route: CompatRoute = autoSelection
|
|
3182
|
+
? { off: false, providerId: autoSelection.providerId, pinned: true }
|
|
3183
|
+
: compatRoute(rotator, requestedModel);
|
|
3184
|
+
if (route.off) return openAIModelOff(res, requestedModel);
|
|
3233
3185
|
const routedValidation = autoSelection
|
|
3234
3186
|
? { ...validation.value, model: autoSelection.model }
|
|
3235
|
-
: validation.value;
|
|
3187
|
+
: { ...validation.value, model: route.modelId ?? requestedModel };
|
|
3236
3188
|
|
|
3237
|
-
if (
|
|
3189
|
+
if (route.providerId === "openai-codex") {
|
|
3238
3190
|
await serveCodexResponses(req, res, rotator, routedValidation, {
|
|
3239
3191
|
callType: "responses",
|
|
3240
3192
|
apiKeyHash,
|
|
@@ -3276,11 +3228,13 @@ export async function handleOpenAIResponsesCreate(
|
|
|
3276
3228
|
? { ...converted.chatRequest, messages: compRes.messages }
|
|
3277
3229
|
: converted.chatRequest;
|
|
3278
3230
|
|
|
3279
|
-
const requestBody: RequestBody =
|
|
3231
|
+
const requestBody: RequestBody = route.providerId === OPENCODE_ZEN_PROVIDER_ID
|
|
3280
3232
|
? { project: "", model: chatRequest.model, request: chatRequest, requestType: "openai-responses" }
|
|
3281
|
-
: (
|
|
3233
|
+
: (route.providerId === "ollama"
|
|
3282
3234
|
? openAIToOllamaBody(chatRequest)
|
|
3283
3235
|
: openAIToAntigravityBody(chatRequest));
|
|
3236
|
+
if (route.pinned) requestBody.providerId = route.providerId;
|
|
3237
|
+
if (isRequestOff(rotator, requestBody)) return openAIModelOff(res, requestedModel);
|
|
3284
3238
|
if (autoSelection) {
|
|
3285
3239
|
requestBody.displayModel = requestedModel;
|
|
3286
3240
|
requestBody.providerId = autoSelection.providerId;
|
|
@@ -3538,9 +3492,27 @@ export async function handleAnthropicMessages(
|
|
|
3538
3492
|
});
|
|
3539
3493
|
}
|
|
3540
3494
|
if (autoSelection && !authorizeResolvedAutoModel(res, auth, autoSelection.model)) return;
|
|
3495
|
+
const route: CompatRoute = autoSelection
|
|
3496
|
+
? { off: false, providerId: autoSelection.providerId, pinned: true }
|
|
3497
|
+
: compatRoute(rotator, requestedModel);
|
|
3498
|
+
const anthropicModelOff = () =>
|
|
3499
|
+
writeJson(res, 404, {
|
|
3500
|
+
type: "error",
|
|
3501
|
+
error: { type: "not_found_error", message: modelOffMessage(requestedModel) },
|
|
3502
|
+
});
|
|
3503
|
+
if (route.off) return anthropicModelOff();
|
|
3541
3504
|
const routedValidation = autoSelection
|
|
3542
3505
|
? { ...validation.value, model: autoSelection.model }
|
|
3543
|
-
: validation.value;
|
|
3506
|
+
: { ...validation.value, model: route.modelId ?? requestedModel };
|
|
3507
|
+
if (route.providerId === "openai-codex") {
|
|
3508
|
+
return writeJson(res, 400, {
|
|
3509
|
+
type: "error",
|
|
3510
|
+
error: {
|
|
3511
|
+
type: "invalid_request_error",
|
|
3512
|
+
message: `The model '${requestedModel}' is served by OpenAI Codex, which this rotator offers only through /v1/chat/completions and /v1/responses.`,
|
|
3513
|
+
},
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3544
3516
|
|
|
3545
3517
|
const compMode = parseCompressionMode(
|
|
3546
3518
|
req.headers["x-rotator-compression"],
|
|
@@ -3560,11 +3532,13 @@ export async function handleAnthropicMessages(
|
|
|
3560
3532
|
|
|
3561
3533
|
const started = Date.now();
|
|
3562
3534
|
const streamMode = routedValidation.stream ? "anthropic" : "none";
|
|
3563
|
-
const bodyToForward: RequestBody =
|
|
3535
|
+
const bodyToForward: RequestBody = route.providerId === OPENCODE_ZEN_PROVIDER_ID
|
|
3564
3536
|
? { project: "", model: anthropicReq.model, request: anthropicToOpenAIChatRequest(anthropicReq), requestType: "anthropic" }
|
|
3565
|
-
: (
|
|
3537
|
+
: (route.providerId === "ollama"
|
|
3566
3538
|
? anthropicToOllamaBody(anthropicReq)
|
|
3567
3539
|
: anthropicToAntigravityBody(anthropicReq));
|
|
3540
|
+
if (route.pinned) bodyToForward.providerId = route.providerId;
|
|
3541
|
+
if (isRequestOff(rotator, bodyToForward)) return anthropicModelOff();
|
|
3568
3542
|
if (autoSelection) {
|
|
3569
3543
|
bodyToForward.displayModel = requestedModel;
|
|
3570
3544
|
bodyToForward.providerId = autoSelection.providerId;
|
package/src/config-defaults.ts
CHANGED
|
@@ -72,6 +72,11 @@ export function applyConfigDefaults(config: Config): Config {
|
|
|
72
72
|
maxExcerptChars: config.typesafeRouting.maxExcerptChars ?? 12_000,
|
|
73
73
|
}
|
|
74
74
|
: undefined,
|
|
75
|
+
providerOrder: config.providerOrder,
|
|
76
|
+
disabledProviders: config.disabledProviders,
|
|
77
|
+
disabledModels: config.disabledModels,
|
|
78
|
+
autoEnableNewModels: config.autoEnableNewModels,
|
|
79
|
+
reviewedModels: config.reviewedModels,
|
|
75
80
|
accounts: config.accounts ? config.accounts.map((account) => ({
|
|
76
81
|
...normalizeAccountConfig(account),
|
|
77
82
|
tier: account.tier || "unknown",
|
package/src/dashboard-live.ts
CHANGED
|
@@ -160,6 +160,7 @@ export function buildOverview(
|
|
|
160
160
|
return {
|
|
161
161
|
generatedAt: now,
|
|
162
162
|
version: status.version,
|
|
163
|
+
modelCatalogRevision: status.modelCatalogRevision,
|
|
163
164
|
proxyPort: status.proxyPort,
|
|
164
165
|
startedAt: Math.round((now - (status.uptime || 0)) / 1000) * 1000,
|
|
165
166
|
requestsPerRotation: status.requestsPerRotation,
|
|
@@ -312,20 +313,21 @@ export class DashboardLiveHub {
|
|
|
312
313
|
const patch: AccountsPatch = { upsert: [], remove: [] };
|
|
313
314
|
const seen = new Set<string>();
|
|
314
315
|
for (const account of next.accounts) {
|
|
315
|
-
|
|
316
|
+
const id = account.id ?? account.email;
|
|
317
|
+
seen.add(id);
|
|
316
318
|
const json = JSON.stringify(account);
|
|
317
|
-
if (this.accountJson.get(
|
|
318
|
-
this.accountJson.set(
|
|
319
|
+
if (this.accountJson.get(id) !== json) {
|
|
320
|
+
this.accountJson.set(id, json);
|
|
319
321
|
patch.upsert.push(account);
|
|
320
322
|
}
|
|
321
323
|
}
|
|
322
|
-
for (const
|
|
323
|
-
if (!seen.has(
|
|
324
|
-
this.accountJson.delete(
|
|
325
|
-
patch.remove.push(
|
|
324
|
+
for (const id of this.accountJson.keys()) {
|
|
325
|
+
if (!seen.has(id)) {
|
|
326
|
+
this.accountJson.delete(id);
|
|
327
|
+
patch.remove.push(id);
|
|
326
328
|
}
|
|
327
329
|
}
|
|
328
|
-
const order = next.accounts.map((a) => a.email);
|
|
330
|
+
const order = next.accounts.map((a) => a.id ?? a.email);
|
|
329
331
|
if (order.join("\n") !== this.accountOrder.join("\n")) {
|
|
330
332
|
this.accountOrder = order;
|
|
331
333
|
patch.order = order;
|