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/src/types.ts
CHANGED
|
@@ -142,13 +142,22 @@ export interface Config {
|
|
|
142
142
|
streamRecoveryMaxRetries?: number;
|
|
143
143
|
// Prompt compression mode ("off" | "lite" | "rtk" | "rtk+lite").
|
|
144
144
|
compressionMode?: "off" | "lite" | "rtk" | "rtk+lite";
|
|
145
|
-
//
|
|
146
|
-
// matched case-insensitively
|
|
145
|
+
// Partially override per-model specs used by the compat layer. Keys are model id
|
|
146
|
+
// substrings matched case-insensitively; omitted fields inherit effective defaults.
|
|
147
147
|
modelSpecs?: Record<string, ModelSpecConfig>;
|
|
148
148
|
// Override model-id aliases used to translate the operator-facing name
|
|
149
149
|
// (e.g. "gemini-3.1-pro-high") to the upstream Antigravity name
|
|
150
150
|
// (e.g. "gemini-pro-agent"). When set, replaces the bundled defaults.
|
|
151
151
|
modelAliases?: Record<string, string>;
|
|
152
|
+
// Config-driven alias routing based on reasoning_effort.
|
|
153
|
+
// Absent, null, or empty object = disabled.
|
|
154
|
+
effortRouting?: Record<string, EffortRoutingRule> | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface EffortRoutingRule {
|
|
158
|
+
/** Effort key used when the request carries no recognizable effort. Defaults to "medium". */
|
|
159
|
+
defaultEffort?: string;
|
|
160
|
+
targets: Record<string, string>;
|
|
152
161
|
}
|
|
153
162
|
|
|
154
163
|
export const DEFAULT_QUOTA_POLL_INTERVAL_MS = 300_000;
|
|
@@ -164,6 +173,13 @@ const DEFAULT_MODEL_ALIASES: Record<string, string> = {
|
|
|
164
173
|
"gpt-oss-120b": "gpt-oss-120b-medium",
|
|
165
174
|
};
|
|
166
175
|
let modelAliasesOverride: Record<string, string> | null = null;
|
|
176
|
+
type StoredEffortRoutingRule = {
|
|
177
|
+
defaultEffort: string;
|
|
178
|
+
targets: Record<string, string>;
|
|
179
|
+
};
|
|
180
|
+
type EffortRoutingModelKind = "alias" | "target";
|
|
181
|
+
|
|
182
|
+
let effortRoutingOverride: Record<string, StoredEffortRoutingRule> | null = null;
|
|
167
183
|
|
|
168
184
|
/**
|
|
169
185
|
* Replace the bundled model-alias table with operator-provided overrides.
|
|
@@ -180,6 +196,65 @@ export function setModelAliasesOverride(
|
|
|
180
196
|
aliases && Object.keys(aliases).length > 0 ? aliases : null;
|
|
181
197
|
}
|
|
182
198
|
|
|
199
|
+
export function setEffortRoutingOverride(
|
|
200
|
+
rules: Record<string, EffortRoutingRule> | null | undefined,
|
|
201
|
+
): void {
|
|
202
|
+
if (!rules || Object.keys(rules).length === 0) {
|
|
203
|
+
effortRoutingOverride = null;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const normalized = Object.create(null) as Record<
|
|
207
|
+
string,
|
|
208
|
+
StoredEffortRoutingRule
|
|
209
|
+
>;
|
|
210
|
+
for (const [rawAlias, rule] of Object.entries(rules)) {
|
|
211
|
+
const alias = rawAlias.trim().toLowerCase();
|
|
212
|
+
const defaultEffort = rule.defaultEffort?.trim().toLowerCase() || "medium";
|
|
213
|
+
const targets = Object.create(null) as Record<string, string>;
|
|
214
|
+
for (const [effortKey, targetValue] of Object.entries(rule.targets ?? {})) {
|
|
215
|
+
targets[effortKey.trim().toLowerCase()] =
|
|
216
|
+
typeof targetValue === "string" ? targetValue.trim() : targetValue;
|
|
217
|
+
}
|
|
218
|
+
normalized[alias] = {
|
|
219
|
+
defaultEffort,
|
|
220
|
+
targets,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
effortRoutingOverride = normalized;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function getEffortRouting(): Record<string, StoredEffortRoutingRule> | null {
|
|
227
|
+
return effortRoutingOverride;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function getEffortRoutingRule(
|
|
231
|
+
requestedModel: string,
|
|
232
|
+
): StoredEffortRoutingRule | undefined {
|
|
233
|
+
const rules = effortRoutingOverride;
|
|
234
|
+
if (!rules) return undefined;
|
|
235
|
+
const alias = requestedModel.trim().toLowerCase();
|
|
236
|
+
return Object.hasOwn(rules, alias) ? rules[alias] : undefined;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function classifyEffortRoutingModel(
|
|
240
|
+
model: string,
|
|
241
|
+
): EffortRoutingModelKind | null {
|
|
242
|
+
const rules = effortRoutingOverride;
|
|
243
|
+
if (!rules) return null;
|
|
244
|
+
const normalizedModel = model.trim().toLowerCase();
|
|
245
|
+
if (Object.hasOwn(rules, normalizedModel)) return "alias";
|
|
246
|
+
for (const rule of Object.values(rules)) {
|
|
247
|
+
if (
|
|
248
|
+
Object.values(rule.targets).some(
|
|
249
|
+
(target) => target.toLowerCase() === normalizedModel,
|
|
250
|
+
)
|
|
251
|
+
) {
|
|
252
|
+
return "target";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
|
|
183
258
|
function getActiveModelAliases(): Record<string, string> {
|
|
184
259
|
return modelAliasesOverride ?? DEFAULT_MODEL_ALIASES;
|
|
185
260
|
}
|
|
@@ -190,7 +265,7 @@ function getActiveModelAliases(): Record<string, string> {
|
|
|
190
265
|
*/
|
|
191
266
|
export function applyModelAlias(model: string): string {
|
|
192
267
|
const aliases = getActiveModelAliases();
|
|
193
|
-
if (model
|
|
268
|
+
if (Object.hasOwn(aliases, model)) return aliases[model];
|
|
194
269
|
const lower = model.toLowerCase();
|
|
195
270
|
for (const [from, to] of Object.entries(aliases)) {
|
|
196
271
|
if (from.toLowerCase() === lower) return to;
|
|
@@ -224,9 +299,11 @@ export interface GoogleQuotaResponse {
|
|
|
224
299
|
// Per-model thinking/output spec used by the compat layer.
|
|
225
300
|
// Operators can override defaults via the `modelSpecs` field in accounts.json.
|
|
226
301
|
export interface ModelSpecConfig {
|
|
227
|
-
maxOutputTokens
|
|
228
|
-
thinkingBudget
|
|
229
|
-
|
|
302
|
+
maxOutputTokens?: number;
|
|
303
|
+
thinkingBudget?: number; // -1 = adaptive (model decides), >=0 = fixed
|
|
304
|
+
minThinkingBudget?: number;
|
|
305
|
+
isThinking?: boolean;
|
|
306
|
+
contextWindow?: number;
|
|
230
307
|
}
|
|
231
308
|
|
|
232
309
|
// Per-model quota info for an account
|
|
@@ -330,7 +407,17 @@ export function resolveQuotaModelKey(requestModel: string): string | null {
|
|
|
330
407
|
* - gemini-3.1-pro-low vs gemini-3.1-pro-high (same quota pool, different display)
|
|
331
408
|
* - claude-sonnet-4-6 vs claude-opus-4-6-thinking (different pricing)
|
|
332
409
|
*/
|
|
333
|
-
export function resolveDisplayModelKey(
|
|
410
|
+
export function resolveDisplayModelKey(
|
|
411
|
+
requestModel: string,
|
|
412
|
+
effectiveModel?: string,
|
|
413
|
+
): string {
|
|
414
|
+
if (
|
|
415
|
+
effectiveModel &&
|
|
416
|
+
effectiveModel !== requestModel &&
|
|
417
|
+
getEffortRoutingRule(requestModel)
|
|
418
|
+
) {
|
|
419
|
+
return resolveDisplayModelKey(effectiveModel);
|
|
420
|
+
}
|
|
334
421
|
const lower = requestModel.toLowerCase();
|
|
335
422
|
// Explicit agent and gpt-oss overrides
|
|
336
423
|
if (lower.includes("gemini-3-flash-agent")) return "gemini-3-flash";
|
|
@@ -454,7 +541,22 @@ export interface PersistedSafetyState {
|
|
|
454
541
|
}>;
|
|
455
542
|
}
|
|
456
543
|
|
|
544
|
+
export interface PersistedDynamicModelOwnership {
|
|
545
|
+
scopedModels: string[];
|
|
546
|
+
accounts: Record<
|
|
547
|
+
string,
|
|
548
|
+
{
|
|
549
|
+
credentialGenerationFingerprint: string;
|
|
550
|
+
models: string[];
|
|
551
|
+
}
|
|
552
|
+
>;
|
|
553
|
+
}
|
|
554
|
+
|
|
457
555
|
export interface PersistedState {
|
|
556
|
+
// Historical dynamic model IDs mapped to their shared quota pools.
|
|
557
|
+
dynamicModelQuotaPools?: Record<string, string>;
|
|
558
|
+
// Exact account ownership for dynamically discovered model IDs.
|
|
559
|
+
dynamicModelOwnership?: PersistedDynamicModelOwnership;
|
|
458
560
|
// Per-model active account index
|
|
459
561
|
modelAccounts: Record<string, number>;
|
|
460
562
|
// Per-model request count on the active account
|
|
@@ -849,11 +951,28 @@ export function getModelPricing(model: string): ModelPricing | undefined {
|
|
|
849
951
|
if (MODEL_PRICING[model]) return MODEL_PRICING[model];
|
|
850
952
|
const lower = model.toLowerCase();
|
|
851
953
|
if (MODEL_PRICING[lower]) return MODEL_PRICING[lower];
|
|
852
|
-
// Dynamic family fallbacks for unseen future models
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
if (lower.includes("
|
|
856
|
-
|
|
954
|
+
// Dynamic family fallbacks for unseen future models. Keep provider and
|
|
955
|
+
// version checks explicit so an unrelated model containing "flash" cannot
|
|
956
|
+
// inherit Gemini pricing.
|
|
957
|
+
if (lower.includes("claude") && lower.includes("opus")) {
|
|
958
|
+
return MODEL_PRICING["claude-opus-4-6-thinking"];
|
|
959
|
+
}
|
|
960
|
+
if (lower.includes("claude") && lower.includes("sonnet")) {
|
|
961
|
+
return MODEL_PRICING["claude-sonnet-4-6"];
|
|
962
|
+
}
|
|
963
|
+
if (lower.includes("gemini")) {
|
|
964
|
+
if (lower.includes("3.8") && lower.includes("flash")) {
|
|
965
|
+
return MODEL_PRICING["gemini-3.8-flash-high"];
|
|
966
|
+
}
|
|
967
|
+
if (lower.includes("3.7") && lower.includes("flash")) {
|
|
968
|
+
return MODEL_PRICING["gemini-3.7-flash-tiered"];
|
|
969
|
+
}
|
|
970
|
+
if (lower.includes("3.6") && lower.includes("flash")) {
|
|
971
|
+
return MODEL_PRICING["gemini-3.6-flash-high"];
|
|
972
|
+
}
|
|
973
|
+
if (lower.includes("flash")) return MODEL_PRICING["gemini-3-flash"];
|
|
974
|
+
if (lower.includes("pro")) return MODEL_PRICING["gemini-3.1-pro"];
|
|
975
|
+
}
|
|
857
976
|
if (lower.includes("gpt-oss")) return MODEL_PRICING["gpt-oss-120b-medium"];
|
|
858
977
|
return undefined;
|
|
859
978
|
}
|
package/src/validators.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MAX_QUOTA_POLL_INTERVAL_MS,
|
|
3
3
|
MIN_QUOTA_POLL_INTERVAL_MS,
|
|
4
|
+
MODEL_TIER_ACCESS,
|
|
4
5
|
type AccountConfig,
|
|
5
6
|
type Config,
|
|
6
7
|
} from "./types.js";
|
|
7
8
|
import { getProxyConfigurationError } from "./providers/proxy-dispatcher.js";
|
|
9
|
+
import { isCodexRequestModel } from "./providers/openai-codex/catalog.js";
|
|
10
|
+
import { isOpenCodeZenModel } from "./providers/opencode-zen/catalog.js";
|
|
8
11
|
|
|
9
12
|
export interface ValidationResult<T> {
|
|
10
13
|
ok: boolean;
|
|
@@ -40,6 +43,15 @@ function isNonNegativeInteger(value: unknown): value is number {
|
|
|
40
43
|
return isNonNegativeNumber(value) && Number.isInteger(value);
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
function isKnownNonGoogleModel(model: string): boolean {
|
|
47
|
+
const trimmed = model.trim();
|
|
48
|
+
if (!trimmed) return false;
|
|
49
|
+
const lower = trimmed.toLowerCase();
|
|
50
|
+
if (isCodexRequestModel(trimmed)) return true;
|
|
51
|
+
if (isOpenCodeZenModel(trimmed) || isOpenCodeZenModel(lower)) return true;
|
|
52
|
+
return Object.keys(MODEL_TIER_ACCESS).some((k) => k.toLowerCase() === lower);
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
export function validateAccountConfig(value: unknown, path = "account"): ValidationResult<AccountConfig> {
|
|
44
56
|
if (!isRecord(value)) return fail([`${path} must be an object`]);
|
|
45
57
|
const errors: string[] = [];
|
|
@@ -173,9 +185,15 @@ export function validateConfig(value: unknown): ValidationResult<Config> {
|
|
|
173
185
|
if (spec.thinkingBudget !== undefined && (typeof spec.thinkingBudget !== "number" || !Number.isFinite(spec.thinkingBudget))) {
|
|
174
186
|
errors.push(`config.modelSpecs.${key}.thinkingBudget must be a number`);
|
|
175
187
|
}
|
|
188
|
+
if (spec.minThinkingBudget !== undefined && !isNonNegativeNumber(spec.minThinkingBudget)) {
|
|
189
|
+
errors.push(`config.modelSpecs.${key}.minThinkingBudget must be a non-negative number`);
|
|
190
|
+
}
|
|
176
191
|
if (spec.isThinking !== undefined && typeof spec.isThinking !== "boolean") {
|
|
177
192
|
errors.push(`config.modelSpecs.${key}.isThinking must be a boolean`);
|
|
178
193
|
}
|
|
194
|
+
if (spec.contextWindow !== undefined && !isPositiveNumber(spec.contextWindow)) {
|
|
195
|
+
errors.push(`config.modelSpecs.${key}.contextWindow must be a positive number`);
|
|
196
|
+
}
|
|
179
197
|
}
|
|
180
198
|
}
|
|
181
199
|
}
|
|
@@ -194,6 +212,98 @@ export function validateConfig(value: unknown): ValidationResult<Config> {
|
|
|
194
212
|
}
|
|
195
213
|
}
|
|
196
214
|
}
|
|
215
|
+
if (value.effortRouting !== undefined && value.effortRouting !== null) {
|
|
216
|
+
if (!isRecord(value.effortRouting)) {
|
|
217
|
+
errors.push("config.effortRouting must be an object or null when provided");
|
|
218
|
+
} else {
|
|
219
|
+
const seenAliasKeys = new Map<string, string>();
|
|
220
|
+
for (const rawAlias of Object.keys(value.effortRouting)) {
|
|
221
|
+
if (typeof rawAlias !== "string" || rawAlias.trim().length === 0) {
|
|
222
|
+
errors.push("config.effortRouting keys must be non-empty strings");
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const lowerAlias = rawAlias.trim().toLowerCase();
|
|
226
|
+
const prev = seenAliasKeys.get(lowerAlias);
|
|
227
|
+
if (prev !== undefined) {
|
|
228
|
+
errors.push(`config.effortRouting keys collide case-insensitively: "${prev}" / "${rawAlias}"`);
|
|
229
|
+
} else {
|
|
230
|
+
seenAliasKeys.set(lowerAlias, rawAlias);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const modelAliasesRecord = isRecord(value.modelAliases) ? value.modelAliases : null;
|
|
235
|
+
|
|
236
|
+
for (const [rawAlias, rule] of Object.entries(value.effortRouting)) {
|
|
237
|
+
if (typeof rawAlias !== "string" || rawAlias.trim().length === 0) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const lowerAlias = rawAlias.trim().toLowerCase();
|
|
241
|
+
|
|
242
|
+
if (isKnownNonGoogleModel(rawAlias)) {
|
|
243
|
+
errors.push(`config.effortRouting.${rawAlias} collides with non-Antigravity model "${rawAlias}"`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (modelAliasesRecord) {
|
|
247
|
+
for (const maKey of Object.keys(modelAliasesRecord)) {
|
|
248
|
+
if (maKey.trim().toLowerCase() === lowerAlias) {
|
|
249
|
+
errors.push(`config.effortRouting.${rawAlias} conflicts with config.modelAliases entry of the same name`);
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!isRecord(rule)) {
|
|
256
|
+
errors.push(`config.effortRouting.${rawAlias} must be an object`);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (rule.defaultEffort !== undefined && typeof rule.defaultEffort !== "string") {
|
|
261
|
+
errors.push(`config.effortRouting.${rawAlias}.defaultEffort must be a string when provided`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (!("targets" in rule) || !isRecord(rule.targets)) {
|
|
265
|
+
errors.push(`config.effortRouting.${rawAlias}.targets must be an object`);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const seenEffortKeys = new Map<string, string>();
|
|
270
|
+
for (const [rawEffort, targetValue] of Object.entries(rule.targets)) {
|
|
271
|
+
if (typeof rawEffort !== "string" || rawEffort.trim().length === 0) {
|
|
272
|
+
errors.push(`config.effortRouting.${rawAlias}.targets keys must be non-empty strings`);
|
|
273
|
+
} else {
|
|
274
|
+
const lowerEffort = rawEffort.trim().toLowerCase();
|
|
275
|
+
const prevEffort = seenEffortKeys.get(lowerEffort);
|
|
276
|
+
if (prevEffort !== undefined) {
|
|
277
|
+
errors.push(`config.effortRouting.${rawAlias}.targets keys collide case-insensitively: "${prevEffort}" / "${rawEffort}"`);
|
|
278
|
+
} else {
|
|
279
|
+
seenEffortKeys.set(lowerEffort, rawEffort);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (typeof targetValue !== "string" || targetValue.trim().length === 0) {
|
|
284
|
+
errors.push(`config.effortRouting.${rawAlias}.targets.${rawEffort} must be a non-empty string`);
|
|
285
|
+
} else {
|
|
286
|
+
if (seenAliasKeys.has(targetValue.trim().toLowerCase())) {
|
|
287
|
+
errors.push(`config.effortRouting.${rawAlias}.targets.${rawEffort} chains into effort-routing alias "${targetValue}" (not supported)`);
|
|
288
|
+
}
|
|
289
|
+
if (isKnownNonGoogleModel(targetValue)) {
|
|
290
|
+
errors.push(`config.effortRouting.${rawAlias} collides with non-Antigravity model "${targetValue}"`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (rule.defaultEffort === undefined || typeof rule.defaultEffort === "string") {
|
|
296
|
+
const effectiveDefault = rule.defaultEffort !== undefined ? rule.defaultEffort : "medium";
|
|
297
|
+
const hasEffectiveDefault = Object.keys(rule.targets).some(
|
|
298
|
+
(k) => k.trim().toLowerCase() === effectiveDefault.trim().toLowerCase(),
|
|
299
|
+
);
|
|
300
|
+
if (!hasEffectiveDefault) {
|
|
301
|
+
errors.push(`config.effortRouting.${rawAlias} default effort "${effectiveDefault}" has no matching target`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
197
307
|
|
|
198
308
|
return errors.length > 0 ? fail(errors) : ok(value as unknown as Config);
|
|
199
309
|
}
|