tuxevil-rotator 3.5.0 → 3.6.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 +12 -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 +111 -10
- package/src/config-defaults.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 +68 -14
- package/src/providers/google-antigravity/translators.ts +65 -23
- package/src/proxy.ts +9 -2
- package/src/rotator.ts +155 -31
- package/src/static/dashboard.js +9 -7
- package/src/types.ts +44 -10
- package/src/validators.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [3.6.0] - 2026-09-04
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **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))
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **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))
|
|
14
|
+
- **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))
|
|
15
|
+
- **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))
|
|
16
|
+
|
|
5
17
|
## [3.5.0] - 2026-09-03
|
|
6
18
|
|
|
7
19
|
### 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.0",
|
|
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
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
getActiveModelSpecs,
|
|
36
36
|
getModelFamily,
|
|
37
37
|
getModelSpec,
|
|
38
|
+
getModelSpecOverride,
|
|
38
39
|
isThinkingModel,
|
|
39
40
|
} from "./compat/model-specs.js";
|
|
40
41
|
import type { ModelSpec } from "./compat/model-specs.js";
|
|
@@ -319,6 +320,7 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
319
320
|
let inputTokens = 0;
|
|
320
321
|
let outputTokens = 0;
|
|
321
322
|
let responseId: string | undefined;
|
|
323
|
+
let upstreamFinishReason: string | undefined;
|
|
322
324
|
const toolCallsMap = new Map<string, OpenAIToolCall>();
|
|
323
325
|
let toolCallIndex = 0;
|
|
324
326
|
|
|
@@ -335,6 +337,13 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
335
337
|
? response.candidates
|
|
336
338
|
: [];
|
|
337
339
|
for (const candidate of candidates) {
|
|
340
|
+
if (
|
|
341
|
+
isRecord(candidate) &&
|
|
342
|
+
typeof candidate.finishReason === "string" &&
|
|
343
|
+
candidate.finishReason
|
|
344
|
+
) {
|
|
345
|
+
upstreamFinishReason = candidate.finishReason;
|
|
346
|
+
}
|
|
338
347
|
if (
|
|
339
348
|
!isRecord(candidate) ||
|
|
340
349
|
!isRecord(candidate.content) ||
|
|
@@ -433,6 +442,7 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
433
442
|
outputTokens,
|
|
434
443
|
responseId,
|
|
435
444
|
toolCalls,
|
|
445
|
+
finishReason: upstreamFinishReason,
|
|
436
446
|
};
|
|
437
447
|
}
|
|
438
448
|
|
|
@@ -642,6 +652,7 @@ async function streamCompatSse(
|
|
|
642
652
|
let tailBuffer = "";
|
|
643
653
|
let reqClosed = false;
|
|
644
654
|
let streamError: string | undefined;
|
|
655
|
+
let upstreamFinishReason: string | undefined;
|
|
645
656
|
interface OpenAiStreamingToolState {
|
|
646
657
|
id: string;
|
|
647
658
|
name: string;
|
|
@@ -958,6 +969,13 @@ async function streamCompatSse(
|
|
|
958
969
|
? response.candidates
|
|
959
970
|
: [];
|
|
960
971
|
for (const candidate of candidates) {
|
|
972
|
+
if (
|
|
973
|
+
isRecord(candidate) &&
|
|
974
|
+
typeof candidate.finishReason === "string" &&
|
|
975
|
+
candidate.finishReason
|
|
976
|
+
) {
|
|
977
|
+
upstreamFinishReason = candidate.finishReason;
|
|
978
|
+
}
|
|
961
979
|
if (
|
|
962
980
|
!isRecord(candidate) ||
|
|
963
981
|
!isRecord(candidate.content) ||
|
|
@@ -1108,7 +1126,14 @@ async function streamCompatSse(
|
|
|
1108
1126
|
if (streamError) {
|
|
1109
1127
|
writeCompatStreamError(res, format, streamError);
|
|
1110
1128
|
} else if (format === "openai") {
|
|
1111
|
-
const openaiFinishReason =
|
|
1129
|
+
const openaiFinishReason =
|
|
1130
|
+
toolCallIndex > 0
|
|
1131
|
+
? "tool_calls"
|
|
1132
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1133
|
+
? "length"
|
|
1134
|
+
: upstreamFinishReason === "SAFETY"
|
|
1135
|
+
? "content_filter"
|
|
1136
|
+
: "stop";
|
|
1112
1137
|
res.write(
|
|
1113
1138
|
`data: ${JSON.stringify({ id, object: "chat.completion.chunk", created, model, choices: [{ index: 0, delta: {}, finish_reason: openaiFinishReason }] })}\n\n`,
|
|
1114
1139
|
);
|
|
@@ -1132,7 +1157,12 @@ async function streamCompatSse(
|
|
|
1132
1157
|
);
|
|
1133
1158
|
}
|
|
1134
1159
|
}
|
|
1135
|
-
const anthropicStopReason =
|
|
1160
|
+
const anthropicStopReason =
|
|
1161
|
+
anthropicHasToolUse
|
|
1162
|
+
? "tool_use"
|
|
1163
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1164
|
+
? "max_tokens"
|
|
1165
|
+
: "end_turn";
|
|
1136
1166
|
// message_delta carries output_tokens; also include input_tokens so Hermes shows full context count
|
|
1137
1167
|
res.write(
|
|
1138
1168
|
`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 +1196,13 @@ async function streamCompatSse(
|
|
|
1166
1196
|
content: text || null,
|
|
1167
1197
|
...(collectedToolCalls ? { tool_calls: collectedToolCalls } : {}),
|
|
1168
1198
|
},
|
|
1169
|
-
finish_reason: collectedToolCalls
|
|
1199
|
+
finish_reason: collectedToolCalls
|
|
1200
|
+
? "tool_calls"
|
|
1201
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1202
|
+
? "length"
|
|
1203
|
+
: upstreamFinishReason === "SAFETY"
|
|
1204
|
+
? "content_filter"
|
|
1205
|
+
: "stop",
|
|
1170
1206
|
},
|
|
1171
1207
|
],
|
|
1172
1208
|
usage: {
|
|
@@ -1191,7 +1227,11 @@ async function streamCompatSse(
|
|
|
1191
1227
|
}))
|
|
1192
1228
|
: []),
|
|
1193
1229
|
],
|
|
1194
|
-
stop_reason: anthropicHasToolUse
|
|
1230
|
+
stop_reason: anthropicHasToolUse
|
|
1231
|
+
? "tool_use"
|
|
1232
|
+
: upstreamFinishReason === "MAX_TOKENS"
|
|
1233
|
+
? "max_tokens"
|
|
1234
|
+
: "end_turn",
|
|
1195
1235
|
usage: { input_tokens: inputTokens, output_tokens: outputTokens },
|
|
1196
1236
|
};
|
|
1197
1237
|
|
|
@@ -1204,6 +1244,7 @@ async function streamCompatSse(
|
|
|
1204
1244
|
toolCalls: collectedToolCalls,
|
|
1205
1245
|
rawResponse,
|
|
1206
1246
|
streamError,
|
|
1247
|
+
finishReason: upstreamFinishReason,
|
|
1207
1248
|
};
|
|
1208
1249
|
}
|
|
1209
1250
|
|
|
@@ -2101,22 +2142,43 @@ export interface CompatModelEntry {
|
|
|
2101
2142
|
quotaPool: string;
|
|
2102
2143
|
multimodal: boolean;
|
|
2103
2144
|
tools: boolean;
|
|
2145
|
+
maxOutputTokens: number;
|
|
2146
|
+
thinkingBudget: number;
|
|
2147
|
+
minThinkingBudget?: number;
|
|
2148
|
+
isThinking: boolean;
|
|
2104
2149
|
}
|
|
2105
2150
|
|
|
2106
2151
|
export function getEffectiveAntigravityModels(): CompatModelEntry[] {
|
|
2107
2152
|
const dynamic = dynamicCatalog.getAllModels();
|
|
2108
2153
|
const seen = new Set(MODEL_CATALOG.map((model) => model.id.toLowerCase()));
|
|
2109
|
-
const result: CompatModelEntry[] = MODEL_CATALOG.map((model) =>
|
|
2154
|
+
const result: CompatModelEntry[] = MODEL_CATALOG.map((model) => {
|
|
2155
|
+
const spec = getModelSpec(model.id);
|
|
2156
|
+
const contextWindow = getModelSpecOverride(model.id)?.contextWindow ??
|
|
2157
|
+
dynamicCatalog.getModelSpec(model.id)?.contextWindow;
|
|
2158
|
+
return {
|
|
2159
|
+
...model,
|
|
2160
|
+
ctx: contextWindow ?? model.ctx,
|
|
2161
|
+
maxOutputTokens: spec.maxOutputTokens,
|
|
2162
|
+
thinkingBudget: spec.thinkingBudget,
|
|
2163
|
+
minThinkingBudget: spec.minThinkingBudget,
|
|
2164
|
+
isThinking: spec.isThinking,
|
|
2165
|
+
};
|
|
2166
|
+
});
|
|
2110
2167
|
for (const m of dynamic) {
|
|
2111
2168
|
if (seen.has(m.id.toLowerCase())) continue;
|
|
2112
2169
|
seen.add(m.id.toLowerCase());
|
|
2170
|
+
const spec = getModelSpec(m.id);
|
|
2113
2171
|
result.push({
|
|
2114
2172
|
id: m.id,
|
|
2115
2173
|
family: m.family,
|
|
2116
|
-
ctx: m.ctx,
|
|
2174
|
+
ctx: spec.contextWindow ?? m.ctx,
|
|
2117
2175
|
quotaPool: m.quotaPool,
|
|
2118
2176
|
multimodal: m.multimodal,
|
|
2119
2177
|
tools: m.tools,
|
|
2178
|
+
maxOutputTokens: spec.maxOutputTokens,
|
|
2179
|
+
thinkingBudget: spec.thinkingBudget,
|
|
2180
|
+
minThinkingBudget: spec.minThinkingBudget,
|
|
2181
|
+
isThinking: spec.isThinking,
|
|
2120
2182
|
});
|
|
2121
2183
|
}
|
|
2122
2184
|
return result;
|
|
@@ -2132,7 +2194,18 @@ export function buildOpenAIModelCatalog(
|
|
|
2132
2194
|
rotator?: AccountRotator,
|
|
2133
2195
|
): OpenAIModelCatalogEntry[] {
|
|
2134
2196
|
const catalog: OpenAIModelCatalogEntry[] = getEffectiveAntigravityModels().map(
|
|
2135
|
-
({
|
|
2197
|
+
({
|
|
2198
|
+
id,
|
|
2199
|
+
ctx,
|
|
2200
|
+
family,
|
|
2201
|
+
quotaPool,
|
|
2202
|
+
multimodal,
|
|
2203
|
+
tools,
|
|
2204
|
+
maxOutputTokens,
|
|
2205
|
+
thinkingBudget,
|
|
2206
|
+
minThinkingBudget,
|
|
2207
|
+
isThinking,
|
|
2208
|
+
}) => ({
|
|
2136
2209
|
id,
|
|
2137
2210
|
object: "model",
|
|
2138
2211
|
created: 0,
|
|
@@ -2145,6 +2218,12 @@ export function buildOpenAIModelCatalog(
|
|
|
2145
2218
|
quota_pool: quotaPool,
|
|
2146
2219
|
multimodal,
|
|
2147
2220
|
tool_calling: tools,
|
|
2221
|
+
max_output_tokens: maxOutputTokens,
|
|
2222
|
+
thinking: isThinking,
|
|
2223
|
+
thinking_budget: thinkingBudget,
|
|
2224
|
+
...(minThinkingBudget !== undefined
|
|
2225
|
+
? { min_thinking_budget: minThinkingBudget }
|
|
2226
|
+
: {}),
|
|
2148
2227
|
},
|
|
2149
2228
|
}),
|
|
2150
2229
|
);
|
|
@@ -2222,14 +2301,25 @@ export function serveOpenAIModels(
|
|
|
2222
2301
|
export function serveGeminiModels(res: ServerResponse): void {
|
|
2223
2302
|
writeJson(res, 200, {
|
|
2224
2303
|
models: getEffectiveAntigravityModels().map(
|
|
2225
|
-
({
|
|
2304
|
+
({
|
|
2305
|
+
id,
|
|
2306
|
+
ctx,
|
|
2307
|
+
family,
|
|
2308
|
+
quotaPool,
|
|
2309
|
+
multimodal,
|
|
2310
|
+
tools,
|
|
2311
|
+
maxOutputTokens,
|
|
2312
|
+
thinkingBudget,
|
|
2313
|
+
minThinkingBudget,
|
|
2314
|
+
isThinking,
|
|
2315
|
+
}) => ({
|
|
2226
2316
|
name: `models/${id}`,
|
|
2227
2317
|
baseModelId: family,
|
|
2228
2318
|
version: "v2.0",
|
|
2229
2319
|
displayName: id,
|
|
2230
2320
|
description: `Tuxevil Rotator Gemini-compatible model entry for ${id}`,
|
|
2231
2321
|
inputTokenLimit: ctx,
|
|
2232
|
-
outputTokenLimit:
|
|
2322
|
+
outputTokenLimit: maxOutputTokens,
|
|
2233
2323
|
supportedGenerationMethods: [
|
|
2234
2324
|
"generateContent",
|
|
2235
2325
|
"streamGenerateContent",
|
|
@@ -2238,6 +2328,11 @@ export function serveGeminiModels(res: ServerResponse): void {
|
|
|
2238
2328
|
tools,
|
|
2239
2329
|
multimodal,
|
|
2240
2330
|
quotaPool,
|
|
2331
|
+
thinking: isThinking,
|
|
2332
|
+
thinkingBudget,
|
|
2333
|
+
...(minThinkingBudget !== undefined
|
|
2334
|
+
? { minThinkingBudget }
|
|
2335
|
+
: {}),
|
|
2241
2336
|
},
|
|
2242
2337
|
}),
|
|
2243
2338
|
),
|
|
@@ -2486,7 +2581,13 @@ export async function handleOpenAIChatCompletions(
|
|
|
2486
2581
|
? { reasoning_content: result.completion.thinkingText }
|
|
2487
2582
|
: {}),
|
|
2488
2583
|
},
|
|
2489
|
-
finish_reason: hasToolCalls
|
|
2584
|
+
finish_reason: hasToolCalls
|
|
2585
|
+
? "tool_calls"
|
|
2586
|
+
: result.completion.finishReason === "MAX_TOKENS"
|
|
2587
|
+
? "length"
|
|
2588
|
+
: result.completion.finishReason === "SAFETY"
|
|
2589
|
+
? "content_filter"
|
|
2590
|
+
: "stop",
|
|
2490
2591
|
},
|
|
2491
2592
|
],
|
|
2492
2593
|
usage: {
|
package/src/config-defaults.ts
CHANGED
|
@@ -55,7 +55,8 @@ 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
|
+
accounts: config.accounts ? config.accounts.map((account) => ({
|
|
59
60
|
...normalizeAccountConfig(account),
|
|
60
61
|
tier: account.tier || "unknown",
|
|
61
62
|
})) : [],
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// separately in `src/compat/model-specs.ts` via `maxOutputTokens`.
|
|
11
11
|
|
|
12
12
|
import { dynamicCatalog } from "./dynamic-catalog.js";
|
|
13
|
+
import { getModelSpecOverride } from "../../compat/model-specs.js";
|
|
13
14
|
|
|
14
15
|
export interface AntigravityModelSpec {
|
|
15
16
|
id: string;
|
|
@@ -73,16 +74,21 @@ const FALLBACK_CONTEXT_WINDOW = 128_000;
|
|
|
73
74
|
* Resolve the upstream-published context window for an Antigravity model id.
|
|
74
75
|
*
|
|
75
76
|
* Lookup order:
|
|
76
|
-
* 1.
|
|
77
|
-
* 2.
|
|
78
|
-
* 3.
|
|
79
|
-
* 4.
|
|
80
|
-
* 5.
|
|
77
|
+
* 1. Operator exact/substring override.
|
|
78
|
+
* 2. Exact id match in static table (lowercased).
|
|
79
|
+
* 3. Dynamic catalog entry from live Antigravity endpoint.
|
|
80
|
+
* 4. Substring match across the table (longest key wins via the order here).
|
|
81
|
+
* 5. Family defaults: claude -> 1M, gemini -> 1M, gpt-oss -> 131_072.
|
|
82
|
+
* 6. Defensive fallback: 128_000.
|
|
81
83
|
*/
|
|
82
84
|
export function getAntigravityContextWindow(model: string): number {
|
|
83
85
|
if (!model) return FALLBACK_CONTEXT_WINDOW;
|
|
84
86
|
const lower = model.toLowerCase().trim();
|
|
85
87
|
if (!lower) return FALLBACK_CONTEXT_WINDOW;
|
|
88
|
+
const overrideCtx = getModelSpecOverride(lower)?.contextWindow;
|
|
89
|
+
if (typeof overrideCtx === "number" && Number.isFinite(overrideCtx) && overrideCtx > 0) {
|
|
90
|
+
return overrideCtx;
|
|
91
|
+
}
|
|
86
92
|
const exact = ANTIGRAVITY_CONTEXT_WINDOWS[lower];
|
|
87
93
|
if (typeof exact === "number") return exact;
|
|
88
94
|
const dynamicCtx = dynamicCatalog.getContextWindow(lower);
|