tuxevil-rotator 3.5.0 → 3.6.1
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 +23 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/account-identity.ts +26 -0
- package/src/compat/model-specs.ts +82 -32
- package/src/compat.ts +177 -15
- package/src/config-defaults.ts +4 -1
- package/src/index.ts +2 -1
- package/src/providers/google-antigravity/catalog.ts +11 -5
- package/src/providers/google-antigravity/dynamic-catalog.ts +371 -21
- package/src/providers/google-antigravity/quota.ts +149 -20
- package/src/providers/google-antigravity/translators.ts +102 -34
- package/src/proxy.ts +30 -2
- package/src/rotator.ts +186 -45
- package/src/static/dashboard.js +9 -7
- package/src/types.ts +131 -12
- package/src/validators.ts +110 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [3.6.1] - 2026-09-05
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Effort-based model routing**: Optional aliases can dispatch requests to concrete model variants based on `reasoning_effort`, while preserving the alias in client-facing responses and tracking quotas against the concrete target ([#32](https://github.com/tuxevil/tuxevil-rotator/pull/32) by [@CyR1en](https://github.com/CyR1en)).
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **Partial Google quota snapshots**: Reset-only quota entries are now treated as exhausted instead of being discarded, while omitted pools remain available from the last known-good snapshot.
|
|
14
|
+
- **Model-scoped cooldown reconciliation**: Shared Claude and Gemini pools now reconcile cooldowns independently, preventing one exhausted pool from blocking its sibling and honoring fresh provider reset deadlines.
|
|
15
|
+
|
|
16
|
+
## [3.6.0] - 2026-09-04
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- **Persistent dynamic model ownership**: Dynamic Antigravity model ownership is persisted by complete account identity and credential-generation fingerprint, so cold restarts cannot route a model through an account or project that never advertised it. ([#30](https://github.com/tuxevil/tuxevil-rotator/pull/30) by [@javargasm](https://github.com/javargasm))
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **Dynamic catalog and quota safety**: Malformed quota entries are ignored without replacing the last known-good snapshot; exhausted sibling pools, stale in-flight responses, retired/reserved model IDs, and account removal or credential changes are handled safely. Persisted cooldown, circuit-breaker, and 429 state is migrated without shortening valid deadlines or losing history. ([#30](https://github.com/tuxevil/tuxevil-rotator/pull/30) by [@javargasm](https://github.com/javargasm))
|
|
25
|
+
- **Dynamic model compatibility metadata**: Effective output-token and thinking metadata now honor runtime constraints and operator overrides across Chat, Responses, and Anthropic compatibility paths, with provider- and version-aware Gemini pricing fallbacks. ([#30](https://github.com/tuxevil/tuxevil-rotator/pull/30) by [@javargasm](https://github.com/javargasm))
|
|
26
|
+
- **Partial model specification overrides**: Operators can now override only selected `modelSpecs` fields while inheriting the effective runtime, static, or family defaults for omitted metadata. Overrides are retained through configuration normalization and persistence, including context-window lookups. ([#31](https://github.com/tuxevil/tuxevil-rotator/pull/31) by [@javargasm](https://github.com/javargasm))
|
|
27
|
+
|
|
5
28
|
## [3.5.0] - 2026-09-03
|
|
6
29
|
|
|
7
30
|
### Added
|
package/README.md
CHANGED
|
@@ -55,6 +55,8 @@ Originally built as a multi-account rotator for Google Antigravity. It now gener
|
|
|
55
55
|
|
|
56
56
|
- **Gemini 3.8 Flash Support**: Native Antigravity model IDs `gemini-3.8-flash-high`, `gemini-3.8-flash-medium`, and `gemini-3.8-flash-low`, with 1M-token context, 65,536-token output, pricing, quota routing, dashboard visualization, and telemetry support. Gemini 3.5 Flash has been removed from the user-facing catalog to match Antigravity 2.11. ([PR #28](https://github.com/tuxevil/tuxevil-rotator/pull/28) by [@CyR1en](https://github.com/CyR1en))
|
|
57
57
|
- **Dynamic Antigravity Discovery**: Successful quota polls reconcile live model IDs and metadata per full account identity. Newly advertised models appear in `/v1/models` and route only to accounts that advertised them; removed models disappear without falling back to the generic Gemini pool. Legacy `gemini-3.5-*` IDs stay hidden, and configured `modelSpecs` substring overrides retain precedence. ([PR #29](https://github.com/tuxevil/tuxevil-rotator/pull/29) by [@javargasm](https://github.com/javargasm))
|
|
58
|
+
- **Dynamic Catalog Hardening**: Quota snapshots reject malformed data while preserving the last known-good state, stale account responses are ignored, and dynamic model ownership and quota-safety state survive restarts without routing a model through an account that did not advertise it. ([PR #30](https://github.com/tuxevil/tuxevil-rotator/pull/30) by [@javargasm](https://github.com/javargasm))
|
|
59
|
+
- **Partial Model Specification Overrides**: `modelSpecs` entries can override selected output, thinking, and context fields while inheriting the remaining effective runtime, static, or family metadata. Overrides are preserved through configuration normalization and persistence. ([PR #31](https://github.com/tuxevil/tuxevil-rotator/pull/31) by [@javargasm](https://github.com/javargasm))
|
|
58
60
|
|
|
59
61
|
## v3.2 Highlights
|
|
60
62
|
|
|
@@ -349,7 +351,7 @@ Thanks to these amazing people who have contributed to the project:
|
|
|
349
351
|
- **[@CyR1en](https://github.com/CyR1en)** (Ethan Bacurio) — Added Gemini 3.6, Gemini 3.7, and Gemini 3.8 Flash model families, shared quota-pool routing, pricing, dashboard support, integration documentation, and regression coverage. ([PR #18](https://github.com/tuxevil/tuxevil-rotator/pull/18), [PR #21](https://github.com/tuxevil/tuxevil-rotator/pull/21), [PR #28](https://github.com/tuxevil/tuxevil-rotator/pull/28))
|
|
350
352
|
- **[@josenicomaia](https://github.com/josenicomaia)** (José Nicodemos Maia Neto) — Modularized the compatibility layer architecture, added multimodal tool response support, fixed streaming pass-through for tool executions, and added PostgreSQL storage and weighted pool quota forecasting. ([PR #8](https://github.com/tuxevil/tuxevil-rotator/pull/8), [PR #9](https://github.com/tuxevil/tuxevil-rotator/pull/9), [PR #11](https://github.com/tuxevil/tuxevil-rotator/pull/11), [PR #13](https://github.com/tuxevil/tuxevil-rotator/pull/13), [PR #14](https://github.com/tuxevil/tuxevil-rotator/pull/14))
|
|
351
353
|
- **[@yashyadav711](https://github.com/yashyadav711)** (Yash) — Fixed Draft-2020-12 inline JSON-Schema union type mapping for Gemini tools support. ([PR #10](https://github.com/tuxevil/tuxevil-rotator/pull/10))
|
|
352
|
-
- **[@javargasm](https://github.com/javargasm)** (Jeisson Alexander Vargas Marroquin) — Queued multi-request Antigravity account pooling (5×5 concurrent streams), strict FIFO overflow queue, dashboard concurrency metrics, canonical project ID resolution, account-scoped dynamic Antigravity discovery and routing, 429 quota resilience with account-scoped retry, synchronous leasing, snapshot-based token refresh with generation validation, provider-scoped token publication, spend-logger memory leak fix, atomic PostgreSQL CTE daily spend aggregation with idempotent retries, virtual-key cache bounding, Anthropic tool-use compatibility layer (`tool_use`/`tool_result` content block conversion), JSON schema round-trip fixes, compat test suite expansion, model-scoped cooldowns, explicit Antigravity reset-duration parsing, idle pool normalization, RAW POLL deadline reconciliation, serialized per-account quota polling, and Ollama kickstart routing for multi-provider accounts. ([PR #3](https://github.com/tuxevil/tuxevil-rotator/pull/3), [PR #7](https://github.com/tuxevil/tuxevil-rotator/pull/7), [PR #22](https://github.com/tuxevil/tuxevil-rotator/pull/22), [PR #23](https://github.com/tuxevil/tuxevil-rotator/pull/23), [PR #24](https://github.com/tuxevil/tuxevil-rotator/pull/24), [PR #26](https://github.com/tuxevil/tuxevil-rotator/pull/26), [PR #29](https://github.com/tuxevil/tuxevil-rotator/pull/29))
|
|
354
|
+
- **[@javargasm](https://github.com/javargasm)** (Jeisson Alexander Vargas Marroquin) — Queued multi-request Antigravity account pooling (5×5 concurrent streams), strict FIFO overflow queue, dashboard concurrency metrics, canonical project ID resolution, account-scoped dynamic Antigravity discovery and routing, dynamic catalog and quota-safety hardening, persistent dynamic model ownership across restarts, 429 quota resilience with account-scoped retry, synchronous leasing, snapshot-based token refresh with generation validation, provider-scoped token publication, spend-logger memory leak fix, atomic PostgreSQL CTE daily spend aggregation with idempotent retries, virtual-key cache bounding, Anthropic tool-use compatibility layer (`tool_use`/`tool_result` content block conversion), JSON schema round-trip fixes, compat test suite expansion, model-scoped cooldowns, explicit Antigravity reset-duration parsing, idle pool normalization, RAW POLL deadline reconciliation, serialized per-account quota polling, and Ollama kickstart routing for multi-provider accounts. ([PR #3](https://github.com/tuxevil/tuxevil-rotator/pull/3), [PR #7](https://github.com/tuxevil/tuxevil-rotator/pull/7), [PR #22](https://github.com/tuxevil/tuxevil-rotator/pull/22), [PR #23](https://github.com/tuxevil/tuxevil-rotator/pull/23), [PR #24](https://github.com/tuxevil/tuxevil-rotator/pull/24), [PR #26](https://github.com/tuxevil/tuxevil-rotator/pull/26), [PR #29](https://github.com/tuxevil/tuxevil-rotator/pull/29), [PR #30](https://github.com/tuxevil/tuxevil-rotator/pull/30))
|
|
353
355
|
|
|
354
356
|
## Development
|
|
355
357
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuxevil-rotator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "Multi-provider, multi-account AI proxy rotator with per-model routing, real-time quota tracking, and infringement detection (Google Antigravity, Ollama Cloud)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/account-identity.ts
CHANGED
|
@@ -68,3 +68,29 @@ export function getAccountIdentity(
|
|
|
68
68
|
}
|
|
69
69
|
return `${email}#${creds}`;
|
|
70
70
|
}
|
|
71
|
+
|
|
72
|
+
/** Identify the exact provider credential revision used by an async operation. */
|
|
73
|
+
export function getCredentialGeneration(
|
|
74
|
+
account: AccountRuntime | AccountConfig,
|
|
75
|
+
providerId: string,
|
|
76
|
+
): string {
|
|
77
|
+
const config = "config" in account ? account.config : account;
|
|
78
|
+
const norm = normalizeAccountConfig(config);
|
|
79
|
+
const cred = norm.credentials?.find((candidate) => candidate.provider === providerId);
|
|
80
|
+
const details = getProviderCredentialDetails(
|
|
81
|
+
norm,
|
|
82
|
+
cred ?? { provider: providerId },
|
|
83
|
+
);
|
|
84
|
+
if (!cred && !details.secret) return "none";
|
|
85
|
+
return `${providerId}:${details.projectId}:${details.providerAccountId}:${details.secret}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Persist a credential revision without exposing its raw secret. */
|
|
89
|
+
export function getCredentialGenerationFingerprint(
|
|
90
|
+
account: AccountRuntime | AccountConfig,
|
|
91
|
+
providerId: string,
|
|
92
|
+
): string {
|
|
93
|
+
return createHash("sha256")
|
|
94
|
+
.update(getCredentialGeneration(account, providerId))
|
|
95
|
+
.digest("hex");
|
|
96
|
+
}
|
|
@@ -3,11 +3,14 @@ import { dynamicCatalog } from "../providers/google-antigravity/dynamic-catalog.
|
|
|
3
3
|
export interface ModelSpec {
|
|
4
4
|
maxOutputTokens: number;
|
|
5
5
|
thinkingBudget: number; // -1 = adaptive (model decides), >=0 = fixed
|
|
6
|
+
minThinkingBudget?: number;
|
|
6
7
|
isThinking: boolean;
|
|
7
8
|
/** Upstream-published context window (input tokens). Optional. */
|
|
8
9
|
contextWindow?: number;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
export type ModelSpecOverride = Partial<ModelSpec>;
|
|
13
|
+
|
|
11
14
|
export const DEFAULT_MODEL_SPECS: Record<string, ModelSpec> = {
|
|
12
15
|
"gemini-pro-agent": { maxOutputTokens: 65535, thinkingBudget: 10001, isThinking: true, contextWindow: 1_000_000 },
|
|
13
16
|
"gemini-3-flash-agent": { maxOutputTokens: 65536, thinkingBudget: 10000, isThinking: true, contextWindow: 1_000_000 },
|
|
@@ -32,17 +35,21 @@ export const DEFAULT_MODEL_SPECS: Record<string, ModelSpec> = {
|
|
|
32
35
|
"claude-sonnet-4-6-thinking":{ maxOutputTokens: 64000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
|
|
33
36
|
"claude-opus-4-6-thinking": { maxOutputTokens: 64000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
|
|
34
37
|
"claude-opus-4-6": { maxOutputTokens: 64000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
|
|
38
|
+
"claude-sonnet-4-5": { maxOutputTokens: 64000, thinkingBudget: 32768, isThinking: true, contextWindow: 200_000 },
|
|
39
|
+
"claude-sonnet-4-5-thinking":{ maxOutputTokens: 64000, thinkingBudget: 32768, isThinking: true, contextWindow: 200_000 },
|
|
40
|
+
"claude-opus-4-5": { maxOutputTokens: 64000, thinkingBudget: 32768, isThinking: true, contextWindow: 200_000 },
|
|
41
|
+
"claude-opus-4-5-thinking": { maxOutputTokens: 64000, thinkingBudget: 32768, isThinking: true, contextWindow: 200_000 },
|
|
35
42
|
"gpt-oss-120b-medium": { maxOutputTokens: 32768, thinkingBudget: 8192, isThinking: true, contextWindow: 131_072 },
|
|
36
43
|
"gpt-oss-120b": { maxOutputTokens: 32768, thinkingBudget: 8192, isThinking: true, contextWindow: 131_072 },
|
|
37
44
|
};
|
|
38
45
|
|
|
39
|
-
let modelSpecsOverride: Record<string,
|
|
46
|
+
let modelSpecsOverride: Record<string, ModelSpecOverride> | null = null;
|
|
40
47
|
|
|
41
48
|
/**
|
|
42
|
-
*
|
|
49
|
+
* Apply operator-provided partial overrides over effective model specs.
|
|
43
50
|
* Pass `null` to restore defaults. Called once at startup from index.ts.
|
|
44
51
|
*/
|
|
45
|
-
export function setModelSpecsOverride(specs: Record<string,
|
|
52
|
+
export function setModelSpecsOverride(specs: Record<string, ModelSpecOverride> | null): void {
|
|
46
53
|
modelSpecsOverride = specs && Object.keys(specs).length > 0
|
|
47
54
|
? Object.fromEntries(
|
|
48
55
|
Object.entries(specs).map(([key, spec]) => [key.toLowerCase(), spec]),
|
|
@@ -51,7 +58,10 @@ export function setModelSpecsOverride(specs: Record<string, ModelSpec> | null):
|
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
export function getActiveModelSpecs(): Record<string, ModelSpec> {
|
|
54
|
-
|
|
61
|
+
if (!modelSpecsOverride) return DEFAULT_MODEL_SPECS;
|
|
62
|
+
return Object.fromEntries(
|
|
63
|
+
Object.keys(modelSpecsOverride).map((model) => [model, getModelSpec(model)]),
|
|
64
|
+
);
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
const GEMINI_MAX_OUTPUT_TOKENS = 65536;
|
|
@@ -66,36 +76,76 @@ export function getModelFamily(model: string): "claude" | "gemini" | "unknown" {
|
|
|
66
76
|
return "unknown";
|
|
67
77
|
}
|
|
68
78
|
|
|
69
|
-
|
|
79
|
+
/** Resolve bundled static metadata without consulting the dynamic registry. */
|
|
80
|
+
export function getStaticModelSpec(model: string): ModelSpec | undefined {
|
|
70
81
|
const lower = model.toLowerCase();
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
if (DEFAULT_MODEL_SPECS[lower]) return DEFAULT_MODEL_SPECS[lower];
|
|
83
|
+
let best: { key: string; spec: ModelSpec } | undefined;
|
|
84
|
+
for (const [key, spec] of Object.entries(DEFAULT_MODEL_SPECS)) {
|
|
85
|
+
if (lower.includes(key) && (!best || key.length > best.key.length)) {
|
|
86
|
+
best = { key, spec };
|
|
75
87
|
}
|
|
76
|
-
} else if (DEFAULT_MODEL_SPECS[lower]) {
|
|
77
|
-
return DEFAULT_MODEL_SPECS[lower];
|
|
78
88
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
return best?.spec;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function getModelSpecOverride(model: string): ModelSpecOverride | undefined {
|
|
93
|
+
if (!modelSpecsOverride) return undefined;
|
|
94
|
+
const lower = model.toLowerCase();
|
|
95
|
+
if (modelSpecsOverride[lower]) return modelSpecsOverride[lower];
|
|
96
|
+
for (const [key, spec] of Object.entries(modelSpecsOverride)) {
|
|
97
|
+
if (lower.includes(key)) return spec;
|
|
85
98
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function mergeModelSpec(
|
|
103
|
+
defaults: ModelSpec,
|
|
104
|
+
override: ModelSpecOverride,
|
|
105
|
+
): ModelSpec {
|
|
106
|
+
const minThinkingBudget = typeof override.minThinkingBudget === "number" &&
|
|
107
|
+
Number.isFinite(override.minThinkingBudget) &&
|
|
108
|
+
override.minThinkingBudget >= 0
|
|
109
|
+
? override.minThinkingBudget
|
|
110
|
+
: defaults.minThinkingBudget;
|
|
111
|
+
const contextWindow = typeof override.contextWindow === "number" &&
|
|
112
|
+
Number.isFinite(override.contextWindow) &&
|
|
113
|
+
override.contextWindow > 0
|
|
114
|
+
? override.contextWindow
|
|
115
|
+
: defaults.contextWindow;
|
|
116
|
+
return {
|
|
117
|
+
maxOutputTokens: typeof override.maxOutputTokens === "number" &&
|
|
118
|
+
Number.isFinite(override.maxOutputTokens) &&
|
|
119
|
+
override.maxOutputTokens > 0
|
|
120
|
+
? override.maxOutputTokens
|
|
121
|
+
: defaults.maxOutputTokens,
|
|
122
|
+
thinkingBudget: typeof override.thinkingBudget === "number" &&
|
|
123
|
+
Number.isFinite(override.thinkingBudget)
|
|
124
|
+
? override.thinkingBudget
|
|
125
|
+
: defaults.thinkingBudget,
|
|
126
|
+
...(minThinkingBudget !== undefined ? { minThinkingBudget } : {}),
|
|
127
|
+
isThinking: typeof override.isThinking === "boolean"
|
|
128
|
+
? override.isThinking
|
|
129
|
+
: defaults.isThinking,
|
|
130
|
+
...(contextWindow !== undefined ? { contextWindow } : {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function getModelSpec(model: string): ModelSpec {
|
|
135
|
+
const lower = model.toLowerCase();
|
|
136
|
+
const dynamicSpec = dynamicCatalog.getModelSpec(lower);
|
|
137
|
+
const staticSpec = getStaticModelSpec(lower);
|
|
138
|
+
const family = getModelFamily(model);
|
|
139
|
+
const defaults = dynamicSpec ?? staticSpec ??
|
|
140
|
+
(family === "claude"
|
|
141
|
+
? { maxOutputTokens: CLAUDE_MAX_OUTPUT_TOKENS, thinkingBudget: CLAUDE_DEFAULT_THINKING_BUDGET, isThinking: true, contextWindow: 1_000_000 }
|
|
142
|
+
: family === "gemini"
|
|
143
|
+
? { maxOutputTokens: GEMINI_MAX_OUTPUT_TOKENS, thinkingBudget: FALLBACK_THINKING_BUDGET, isThinking: true, contextWindow: 1_000_000 }
|
|
144
|
+
: { maxOutputTokens: 65536, thinkingBudget: FALLBACK_THINKING_BUDGET, isThinking: false, contextWindow: 128_000 });
|
|
145
|
+
const override = getModelSpecOverride(lower);
|
|
146
|
+
return override ? mergeModelSpec(defaults, override) : defaults;
|
|
147
|
+
}
|
|
91
148
|
|
|
92
|
-
export function isThinkingModel(model: string): boolean {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const l = model.toLowerCase();
|
|
96
|
-
if (l.includes("gemini")) {
|
|
97
|
-
const m = l.match(/gemini-(\d+)/);
|
|
98
|
-
if (m && parseInt(m[1], 10) >= 3) return true;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
149
|
+
export function isThinkingModel(model: string): boolean {
|
|
150
|
+
return getModelSpec(model).isThinking;
|
|
151
|
+
}
|
package/src/compat.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type RotationAttemptContext,
|
|
24
24
|
type RotationOutcome,
|
|
25
25
|
} from "./proxy.js";
|
|
26
|
+
import { getEffortRouting } from "./types.js";
|
|
26
27
|
import {
|
|
27
28
|
isRecord,
|
|
28
29
|
sanitizeGeminiSchema,
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
getActiveModelSpecs,
|
|
36
37
|
getModelFamily,
|
|
37
38
|
getModelSpec,
|
|
39
|
+
getModelSpecOverride,
|
|
38
40
|
isThinkingModel,
|
|
39
41
|
} from "./compat/model-specs.js";
|
|
40
42
|
import type { ModelSpec } from "./compat/model-specs.js";
|
|
@@ -319,6 +321,7 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
319
321
|
let inputTokens = 0;
|
|
320
322
|
let outputTokens = 0;
|
|
321
323
|
let responseId: string | undefined;
|
|
324
|
+
let upstreamFinishReason: string | undefined;
|
|
322
325
|
const toolCallsMap = new Map<string, OpenAIToolCall>();
|
|
323
326
|
let toolCallIndex = 0;
|
|
324
327
|
|
|
@@ -335,6 +338,13 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
335
338
|
? response.candidates
|
|
336
339
|
: [];
|
|
337
340
|
for (const candidate of candidates) {
|
|
341
|
+
if (
|
|
342
|
+
isRecord(candidate) &&
|
|
343
|
+
typeof candidate.finishReason === "string" &&
|
|
344
|
+
candidate.finishReason
|
|
345
|
+
) {
|
|
346
|
+
upstreamFinishReason = candidate.finishReason;
|
|
347
|
+
}
|
|
338
348
|
if (
|
|
339
349
|
!isRecord(candidate) ||
|
|
340
350
|
!isRecord(candidate.content) ||
|
|
@@ -433,6 +443,7 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
433
443
|
outputTokens,
|
|
434
444
|
responseId,
|
|
435
445
|
toolCalls,
|
|
446
|
+
finishReason: upstreamFinishReason,
|
|
436
447
|
};
|
|
437
448
|
}
|
|
438
449
|
|
|
@@ -506,7 +517,7 @@ function recordCompatOutcome(
|
|
|
506
517
|
},
|
|
507
518
|
): void {
|
|
508
519
|
const ttfbMs = completion?.firstByteMs ?? totalMs;
|
|
509
|
-
rotator.recordLatency(
|
|
520
|
+
rotator.recordLatency(context.displayModelKey, ttfbMs, totalMs);
|
|
510
521
|
rotator.recordRequestLog({
|
|
511
522
|
model: context.displayModelKey,
|
|
512
523
|
account: context.label,
|
|
@@ -642,6 +653,7 @@ async function streamCompatSse(
|
|
|
642
653
|
let tailBuffer = "";
|
|
643
654
|
let reqClosed = false;
|
|
644
655
|
let streamError: string | undefined;
|
|
656
|
+
let upstreamFinishReason: string | undefined;
|
|
645
657
|
interface OpenAiStreamingToolState {
|
|
646
658
|
id: string;
|
|
647
659
|
name: string;
|
|
@@ -958,6 +970,13 @@ async function streamCompatSse(
|
|
|
958
970
|
? response.candidates
|
|
959
971
|
: [];
|
|
960
972
|
for (const candidate of candidates) {
|
|
973
|
+
if (
|
|
974
|
+
isRecord(candidate) &&
|
|
975
|
+
typeof candidate.finishReason === "string" &&
|
|
976
|
+
candidate.finishReason
|
|
977
|
+
) {
|
|
978
|
+
upstreamFinishReason = candidate.finishReason;
|
|
979
|
+
}
|
|
961
980
|
if (
|
|
962
981
|
!isRecord(candidate) ||
|
|
963
982
|
!isRecord(candidate.content) ||
|
|
@@ -1108,7 +1127,14 @@ async function streamCompatSse(
|
|
|
1108
1127
|
if (streamError) {
|
|
1109
1128
|
writeCompatStreamError(res, format, streamError);
|
|
1110
1129
|
} else if (format === "openai") {
|
|
1111
|
-
const openaiFinishReason =
|
|
1130
|
+
const openaiFinishReason =
|
|
1131
|
+
toolCallIndex > 0
|
|
1132
|
+
? "tool_calls"
|
|
1133
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1134
|
+
? "length"
|
|
1135
|
+
: upstreamFinishReason === "SAFETY"
|
|
1136
|
+
? "content_filter"
|
|
1137
|
+
: "stop";
|
|
1112
1138
|
res.write(
|
|
1113
1139
|
`data: ${JSON.stringify({ id, object: "chat.completion.chunk", created, model, choices: [{ index: 0, delta: {}, finish_reason: openaiFinishReason }] })}\n\n`,
|
|
1114
1140
|
);
|
|
@@ -1132,7 +1158,12 @@ async function streamCompatSse(
|
|
|
1132
1158
|
);
|
|
1133
1159
|
}
|
|
1134
1160
|
}
|
|
1135
|
-
const anthropicStopReason =
|
|
1161
|
+
const anthropicStopReason =
|
|
1162
|
+
anthropicHasToolUse
|
|
1163
|
+
? "tool_use"
|
|
1164
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1165
|
+
? "max_tokens"
|
|
1166
|
+
: "end_turn";
|
|
1136
1167
|
// message_delta carries output_tokens; also include input_tokens so Hermes shows full context count
|
|
1137
1168
|
res.write(
|
|
1138
1169
|
`event: message_delta\ndata: ${JSON.stringify({ type: "message_delta", delta: { stop_reason: anthropicStopReason, stop_sequence: null }, usage: { input_tokens: inputTokens, output_tokens: outputTokens } })}\n\n`,
|
|
@@ -1166,7 +1197,13 @@ async function streamCompatSse(
|
|
|
1166
1197
|
content: text || null,
|
|
1167
1198
|
...(collectedToolCalls ? { tool_calls: collectedToolCalls } : {}),
|
|
1168
1199
|
},
|
|
1169
|
-
finish_reason: collectedToolCalls
|
|
1200
|
+
finish_reason: collectedToolCalls
|
|
1201
|
+
? "tool_calls"
|
|
1202
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1203
|
+
? "length"
|
|
1204
|
+
: upstreamFinishReason === "SAFETY"
|
|
1205
|
+
? "content_filter"
|
|
1206
|
+
: "stop",
|
|
1170
1207
|
},
|
|
1171
1208
|
],
|
|
1172
1209
|
usage: {
|
|
@@ -1191,7 +1228,11 @@ async function streamCompatSse(
|
|
|
1191
1228
|
}))
|
|
1192
1229
|
: []),
|
|
1193
1230
|
],
|
|
1194
|
-
stop_reason: anthropicHasToolUse
|
|
1231
|
+
stop_reason: anthropicHasToolUse
|
|
1232
|
+
? "tool_use"
|
|
1233
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1234
|
+
? "max_tokens"
|
|
1235
|
+
: "end_turn",
|
|
1195
1236
|
usage: { input_tokens: inputTokens, output_tokens: outputTokens },
|
|
1196
1237
|
};
|
|
1197
1238
|
|
|
@@ -1204,6 +1245,7 @@ async function streamCompatSse(
|
|
|
1204
1245
|
toolCalls: collectedToolCalls,
|
|
1205
1246
|
rawResponse,
|
|
1206
1247
|
streamError,
|
|
1248
|
+
finishReason: upstreamFinishReason,
|
|
1207
1249
|
};
|
|
1208
1250
|
}
|
|
1209
1251
|
|
|
@@ -1761,7 +1803,7 @@ async function completeResponsesViaRotator(
|
|
|
1761
1803
|
);
|
|
1762
1804
|
if (completion.inputTokens > 0 || completion.outputTokens > 0) {
|
|
1763
1805
|
rotator.recordTokenUsage(
|
|
1764
|
-
|
|
1806
|
+
context.displayModelKey,
|
|
1765
1807
|
completion.inputTokens,
|
|
1766
1808
|
completion.outputTokens,
|
|
1767
1809
|
);
|
|
@@ -1857,7 +1899,7 @@ async function completeViaRotator(
|
|
|
1857
1899
|
: parseAntigravitySse(raw);
|
|
1858
1900
|
if (completion.inputTokens > 0 || completion.outputTokens > 0) {
|
|
1859
1901
|
rotator.recordTokenUsage(
|
|
1860
|
-
|
|
1902
|
+
context.displayModelKey,
|
|
1861
1903
|
completion.inputTokens,
|
|
1862
1904
|
completion.outputTokens,
|
|
1863
1905
|
);
|
|
@@ -1890,7 +1932,7 @@ async function completeViaRotator(
|
|
|
1890
1932
|
);
|
|
1891
1933
|
if (completion.inputTokens > 0 || completion.outputTokens > 0) {
|
|
1892
1934
|
rotator.recordTokenUsage(
|
|
1893
|
-
|
|
1935
|
+
context.displayModelKey,
|
|
1894
1936
|
completion.inputTokens,
|
|
1895
1937
|
completion.outputTokens,
|
|
1896
1938
|
);
|
|
@@ -2101,27 +2143,108 @@ export interface CompatModelEntry {
|
|
|
2101
2143
|
quotaPool: string;
|
|
2102
2144
|
multimodal: boolean;
|
|
2103
2145
|
tools: boolean;
|
|
2146
|
+
maxOutputTokens: number;
|
|
2147
|
+
thinkingBudget: number;
|
|
2148
|
+
minThinkingBudget?: number;
|
|
2149
|
+
isThinking: boolean;
|
|
2104
2150
|
}
|
|
2105
2151
|
|
|
2106
2152
|
export function getEffectiveAntigravityModels(): CompatModelEntry[] {
|
|
2107
2153
|
const dynamic = dynamicCatalog.getAllModels();
|
|
2108
2154
|
const seen = new Set(MODEL_CATALOG.map((model) => model.id.toLowerCase()));
|
|
2109
|
-
const result: CompatModelEntry[] = MODEL_CATALOG.map((model) =>
|
|
2155
|
+
const result: CompatModelEntry[] = MODEL_CATALOG.map((model) => {
|
|
2156
|
+
const spec = getModelSpec(model.id);
|
|
2157
|
+
const contextWindow = getModelSpecOverride(model.id)?.contextWindow ??
|
|
2158
|
+
dynamicCatalog.getModelSpec(model.id)?.contextWindow;
|
|
2159
|
+
return {
|
|
2160
|
+
...model,
|
|
2161
|
+
ctx: contextWindow ?? model.ctx,
|
|
2162
|
+
maxOutputTokens: spec.maxOutputTokens,
|
|
2163
|
+
thinkingBudget: spec.thinkingBudget,
|
|
2164
|
+
minThinkingBudget: spec.minThinkingBudget,
|
|
2165
|
+
isThinking: spec.isThinking,
|
|
2166
|
+
};
|
|
2167
|
+
});
|
|
2110
2168
|
for (const m of dynamic) {
|
|
2111
2169
|
if (seen.has(m.id.toLowerCase())) continue;
|
|
2112
2170
|
seen.add(m.id.toLowerCase());
|
|
2171
|
+
const spec = getModelSpec(m.id);
|
|
2113
2172
|
result.push({
|
|
2114
2173
|
id: m.id,
|
|
2115
2174
|
family: m.family,
|
|
2116
|
-
ctx: m.ctx,
|
|
2175
|
+
ctx: spec.contextWindow ?? m.ctx,
|
|
2117
2176
|
quotaPool: m.quotaPool,
|
|
2118
2177
|
multimodal: m.multimodal,
|
|
2119
2178
|
tools: m.tools,
|
|
2179
|
+
maxOutputTokens: spec.maxOutputTokens,
|
|
2180
|
+
thinkingBudget: spec.thinkingBudget,
|
|
2181
|
+
minThinkingBudget: spec.minThinkingBudget,
|
|
2182
|
+
isThinking: spec.isThinking,
|
|
2120
2183
|
});
|
|
2121
2184
|
}
|
|
2185
|
+
|
|
2122
2186
|
return result;
|
|
2123
2187
|
}
|
|
2124
2188
|
|
|
2189
|
+
function getOpenAIAntigravityModels(): CompatModelEntry[] {
|
|
2190
|
+
const result = getEffectiveAntigravityModels();
|
|
2191
|
+
const rules = getEffortRouting();
|
|
2192
|
+
if (!rules || Object.keys(rules).length === 0) {
|
|
2193
|
+
return result;
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
const successfulAliases: Array<{
|
|
2197
|
+
alias: string;
|
|
2198
|
+
representative: CompatModelEntry;
|
|
2199
|
+
}> = [];
|
|
2200
|
+
const hiddenTargetIds = new Set<string>();
|
|
2201
|
+
const successfulAliasNames = new Set<string>();
|
|
2202
|
+
|
|
2203
|
+
for (const [alias, rule] of Object.entries(rules)) {
|
|
2204
|
+
const defaultEffortKey = rule.defaultEffort;
|
|
2205
|
+
const defaultTargetId = rule.targets[defaultEffortKey];
|
|
2206
|
+
if (!defaultTargetId) {
|
|
2207
|
+
compatLogger.warn(
|
|
2208
|
+
`Effort routing alias "${alias}" default effort "${defaultEffortKey}" target not found; skipping catalog swap`,
|
|
2209
|
+
);
|
|
2210
|
+
continue;
|
|
2211
|
+
}
|
|
2212
|
+
const representative = result.find(
|
|
2213
|
+
(m) => m.id.toLowerCase() === defaultTargetId.toLowerCase(),
|
|
2214
|
+
);
|
|
2215
|
+
if (!representative) {
|
|
2216
|
+
compatLogger.warn(
|
|
2217
|
+
`Effort routing alias "${alias}" default target "${defaultTargetId}" absent from catalog; skipping catalog swap`,
|
|
2218
|
+
);
|
|
2219
|
+
continue;
|
|
2220
|
+
}
|
|
2221
|
+
successfulAliases.push({ alias, representative });
|
|
2222
|
+
successfulAliasNames.add(alias.toLowerCase());
|
|
2223
|
+
for (const targetId of Object.values(rule.targets)) {
|
|
2224
|
+
hiddenTargetIds.add(targetId.toLowerCase());
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
if (successfulAliases.length === 0) {
|
|
2229
|
+
return result;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
const filtered = result.filter(
|
|
2233
|
+
(m) =>
|
|
2234
|
+
!hiddenTargetIds.has(m.id.toLowerCase()) &&
|
|
2235
|
+
!successfulAliasNames.has(m.id.toLowerCase()),
|
|
2236
|
+
);
|
|
2237
|
+
|
|
2238
|
+
for (const { alias, representative } of successfulAliases) {
|
|
2239
|
+
filtered.push({
|
|
2240
|
+
...representative,
|
|
2241
|
+
id: alias,
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
return filtered;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2125
2248
|
/**
|
|
2126
2249
|
* Build the OpenAI-compatible `/v1/models` catalog for the proxy.
|
|
2127
2250
|
*
|
|
@@ -2131,8 +2254,19 @@ export function getEffectiveAntigravityModels(): CompatModelEntry[] {
|
|
|
2131
2254
|
export function buildOpenAIModelCatalog(
|
|
2132
2255
|
rotator?: AccountRotator,
|
|
2133
2256
|
): OpenAIModelCatalogEntry[] {
|
|
2134
|
-
const catalog: OpenAIModelCatalogEntry[] =
|
|
2135
|
-
({
|
|
2257
|
+
const catalog: OpenAIModelCatalogEntry[] = getOpenAIAntigravityModels().map(
|
|
2258
|
+
({
|
|
2259
|
+
id,
|
|
2260
|
+
ctx,
|
|
2261
|
+
family,
|
|
2262
|
+
quotaPool,
|
|
2263
|
+
multimodal,
|
|
2264
|
+
tools,
|
|
2265
|
+
maxOutputTokens,
|
|
2266
|
+
thinkingBudget,
|
|
2267
|
+
minThinkingBudget,
|
|
2268
|
+
isThinking,
|
|
2269
|
+
}) => ({
|
|
2136
2270
|
id,
|
|
2137
2271
|
object: "model",
|
|
2138
2272
|
created: 0,
|
|
@@ -2145,6 +2279,12 @@ export function buildOpenAIModelCatalog(
|
|
|
2145
2279
|
quota_pool: quotaPool,
|
|
2146
2280
|
multimodal,
|
|
2147
2281
|
tool_calling: tools,
|
|
2282
|
+
max_output_tokens: maxOutputTokens,
|
|
2283
|
+
thinking: isThinking,
|
|
2284
|
+
thinking_budget: thinkingBudget,
|
|
2285
|
+
...(minThinkingBudget !== undefined
|
|
2286
|
+
? { min_thinking_budget: minThinkingBudget }
|
|
2287
|
+
: {}),
|
|
2148
2288
|
},
|
|
2149
2289
|
}),
|
|
2150
2290
|
);
|
|
@@ -2222,14 +2362,25 @@ export function serveOpenAIModels(
|
|
|
2222
2362
|
export function serveGeminiModels(res: ServerResponse): void {
|
|
2223
2363
|
writeJson(res, 200, {
|
|
2224
2364
|
models: getEffectiveAntigravityModels().map(
|
|
2225
|
-
({
|
|
2365
|
+
({
|
|
2366
|
+
id,
|
|
2367
|
+
ctx,
|
|
2368
|
+
family,
|
|
2369
|
+
quotaPool,
|
|
2370
|
+
multimodal,
|
|
2371
|
+
tools,
|
|
2372
|
+
maxOutputTokens,
|
|
2373
|
+
thinkingBudget,
|
|
2374
|
+
minThinkingBudget,
|
|
2375
|
+
isThinking,
|
|
2376
|
+
}) => ({
|
|
2226
2377
|
name: `models/${id}`,
|
|
2227
2378
|
baseModelId: family,
|
|
2228
2379
|
version: "v2.0",
|
|
2229
2380
|
displayName: id,
|
|
2230
2381
|
description: `Tuxevil Rotator Gemini-compatible model entry for ${id}`,
|
|
2231
2382
|
inputTokenLimit: ctx,
|
|
2232
|
-
outputTokenLimit:
|
|
2383
|
+
outputTokenLimit: maxOutputTokens,
|
|
2233
2384
|
supportedGenerationMethods: [
|
|
2234
2385
|
"generateContent",
|
|
2235
2386
|
"streamGenerateContent",
|
|
@@ -2238,6 +2389,11 @@ export function serveGeminiModels(res: ServerResponse): void {
|
|
|
2238
2389
|
tools,
|
|
2239
2390
|
multimodal,
|
|
2240
2391
|
quotaPool,
|
|
2392
|
+
thinking: isThinking,
|
|
2393
|
+
thinkingBudget,
|
|
2394
|
+
...(minThinkingBudget !== undefined
|
|
2395
|
+
? { minThinkingBudget }
|
|
2396
|
+
: {}),
|
|
2241
2397
|
},
|
|
2242
2398
|
}),
|
|
2243
2399
|
),
|
|
@@ -2486,7 +2642,13 @@ export async function handleOpenAIChatCompletions(
|
|
|
2486
2642
|
? { reasoning_content: result.completion.thinkingText }
|
|
2487
2643
|
: {}),
|
|
2488
2644
|
},
|
|
2489
|
-
finish_reason: hasToolCalls
|
|
2645
|
+
finish_reason: hasToolCalls
|
|
2646
|
+
? "tool_calls"
|
|
2647
|
+
: result.completion.finishReason === "MAX_TOKENS"
|
|
2648
|
+
? "length"
|
|
2649
|
+
: result.completion.finishReason === "SAFETY"
|
|
2650
|
+
? "content_filter"
|
|
2651
|
+
: "stop",
|
|
2490
2652
|
},
|
|
2491
2653
|
],
|
|
2492
2654
|
usage: {
|
package/src/config-defaults.ts
CHANGED
|
@@ -55,7 +55,10 @@ export function applyConfigDefaults(config: Config): Config {
|
|
|
55
55
|
idempotencyWindowMs: config.idempotencyWindowMs ?? 2000,
|
|
56
56
|
streamRecoveryMaxRetries: safeStreamRecoveryMaxRetries(config.streamRecoveryMaxRetries),
|
|
57
57
|
compressionMode: config.compressionMode ?? "off",
|
|
58
|
-
|
|
58
|
+
modelSpecs: config.modelSpecs,
|
|
59
|
+
modelAliases: config.modelAliases,
|
|
60
|
+
effortRouting: config.effortRouting,
|
|
61
|
+
accounts: config.accounts ? config.accounts.map((account) => ({
|
|
59
62
|
...normalizeAccountConfig(account),
|
|
60
63
|
tier: account.tier || "unknown",
|
|
61
64
|
})) : [],
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
loadResponsesStore,
|
|
20
20
|
flushResponsesStore,
|
|
21
21
|
} from "./compat.js";
|
|
22
|
-
import { setModelAliasesOverride } from "./types.js";
|
|
22
|
+
import { setModelAliasesOverride, setEffortRoutingOverride } from "./types.js";
|
|
23
23
|
import { readTextFile, writeTextFileAtomic } from "./storage.js";
|
|
24
24
|
import { initDb, isDbConfigured } from "./db-store.js";
|
|
25
25
|
import { runKeyMigrations } from "./key-migrations.js";
|
|
@@ -211,6 +211,7 @@ export async function main(): Promise<void> {
|
|
|
211
211
|
warnIfInsecureTelemetryEndpoint();
|
|
212
212
|
setModelSpecsOverride(config.modelSpecs ?? null);
|
|
213
213
|
setModelAliasesOverride(config.modelAliases ?? null);
|
|
214
|
+
setEffortRoutingOverride(config.effortRouting ?? null);
|
|
214
215
|
void loadResponsesStore();
|
|
215
216
|
|
|
216
217
|
const rotator = new AccountRotator(config);
|