tuxevil-rotator 4.4.2 → 4.4.3
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 +8 -0
- package/README.md +2 -0
- package/package.json +1 -1
- package/src/auto-model-access.ts +29 -4
- package/src/compat.ts +20 -3
- package/src/model-access.ts +15 -6
- package/src/proxy.ts +16 -6
- package/src/rotator.ts +14 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## [4.4.3] - 2026-11-20
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Enforce provider and model eligibility for direct requests, account selection, and retries across Antigravity and Codex, preventing requests from being sent to accounts without the required plan access.
|
|
10
|
+
- Record compatibility requests rejected before account selection in request history and spend logs, including their HTTP status.
|
|
11
|
+
- Calculate retry estimates from accounts eligible for the requested provider model so unavailable accounts do not distort cooldown responses.
|
|
12
|
+
|
|
5
13
|
## [4.4.2] - 2026-11-14
|
|
6
14
|
|
|
7
15
|
### Changed
|
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
|
## Current Model Update
|
|
57
57
|
|
|
58
|
+
- **v4.4.3: Account model access and routing visibility**: Enforce provider plan eligibility for direct requests, selection, and retries across Antigravity and Codex. Admission rejections now appear in request history, and cooldown estimates use accounts eligible for the requested model. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.3))
|
|
59
|
+
|
|
58
60
|
- **v4.4.2: Model access dashboard**: A redesigned Model access panel with live checks, account evidence, clearer rules and safer plan saving. Thanks to [@CyR1en](https://github.com/CyR1en) for [PR #49](https://github.com/tuxevil/tuxevil-rotator/pull/49). ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.2))
|
|
59
61
|
|
|
60
62
|
- **v4.4.1: Telemetry reliability**: Prevent failed or timed-out flag telemetry requests from terminating the rotator, and update the development-only minimatch override. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.1))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuxevil-rotator",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.3",
|
|
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/auto-model-access.ts
CHANGED
|
@@ -18,6 +18,10 @@ export interface AutoAccountScope {
|
|
|
18
18
|
modelId: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export function requiresAntigravityAccessPolicy(model: string): boolean {
|
|
22
|
+
return /^(?:claude-(?:opus|sonnet)-(?:5-5|4-6)(?:-|$)|gemini-4(?:-|$)|gemini-3\.(?:7-flash|6-flash|1-pro)(?:-|$))/i.test(model);
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
function matchesRule(rule: (typeof MODEL_ACCESS_RULES)[number], model: string): boolean {
|
|
22
26
|
if (rule.modelPrefix === "*-free") return model.endsWith("-free");
|
|
23
27
|
return rule.exact
|
|
@@ -111,6 +115,14 @@ export function evaluateAutoModelAccess(
|
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
if (plan === "unknown") {
|
|
118
|
+
// A verified Free-plan model is also safe to try when the Codex plan is
|
|
119
|
+
// unknown; paid-only and unlisted models still require a known plan.
|
|
120
|
+
if (provider === "openai-codex" && MODEL_ACCESS_RULES.some((rule) =>
|
|
121
|
+
rule.provider === provider && rule.plans.includes("free") && rule.state === "allowed" &&
|
|
122
|
+
matchesRule(rule, model) && evaluateModelAccess({ provider, model, plan: "free", at: new Date(now).toISOString() }).state === "allowed",
|
|
123
|
+
)) {
|
|
124
|
+
return { eligible: true, plan, planSource, reason: "model is documented for Codex Free" };
|
|
125
|
+
}
|
|
114
126
|
const hasPlanSpecificRule = MODEL_ACCESS_RULES.some((rule) =>
|
|
115
127
|
rule.provider === provider && matchesRule(rule, model),
|
|
116
128
|
);
|
|
@@ -143,11 +155,24 @@ export function evaluateAutoModelAccess(
|
|
|
143
155
|
at: new Date(now).toISOString(),
|
|
144
156
|
});
|
|
145
157
|
|
|
146
|
-
//
|
|
147
|
-
|
|
158
|
+
// An overdue review must not turn a documented denial into permission.
|
|
159
|
+
if (provider === "google-antigravity" && matchingRules.some((rule) =>
|
|
160
|
+
(rule.state === "blocked" || rule.state === "conditional" ||
|
|
161
|
+
(rule.validUntil !== undefined && now >= Date.parse(`${rule.validUntil}T00:00:00Z`))) &&
|
|
162
|
+
now >= Date.parse(`${rule.validFrom}T00:00:00Z`),
|
|
163
|
+
)) {
|
|
164
|
+
return { eligible: false, plan, planSource, reason: decision.reason };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (provider === "google-antigravity" && model.startsWith("gemini-4-") && decision.state === "unknown") {
|
|
168
|
+
return { eligible: false, plan, planSource, reason: decision.reason };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Unknown or stale entries must not silently inherit free access.
|
|
148
172
|
if ((provider === "ollama" || provider === "openai-codex") && plan === "free") {
|
|
149
173
|
const confirmedAllow = matchingRules.some((rule) =>
|
|
150
|
-
rule.state === "allowed" && rule.evidence === "operator-confirmed"
|
|
174
|
+
rule.state === "allowed" && (rule.evidence === "operator-confirmed" ||
|
|
175
|
+
(provider === "openai-codex" && rule.evidence === "documented")),
|
|
151
176
|
);
|
|
152
177
|
if (!confirmedAllow || decision.state === "unknown") {
|
|
153
178
|
return {
|
|
@@ -156,7 +181,7 @@ export function evaluateAutoModelAccess(
|
|
|
156
181
|
planSource,
|
|
157
182
|
reason: confirmedAllow
|
|
158
183
|
? "Free-plan model policy needs re-verification"
|
|
159
|
-
: "model is outside the confirmed Free-plan auto-routing list",
|
|
184
|
+
: provider === "ollama" ? "model is outside the confirmed Free-plan auto-routing list" : "model is outside the confirmed Free-plan model list",
|
|
160
185
|
};
|
|
161
186
|
}
|
|
162
187
|
}
|
package/src/compat.ts
CHANGED
|
@@ -777,6 +777,7 @@ function recordCompatFailure(
|
|
|
777
777
|
rotator: AccountRotator,
|
|
778
778
|
body: RequestBody,
|
|
779
779
|
outcome: RotationOutcome<unknown>,
|
|
780
|
+
startedAt: number,
|
|
780
781
|
options?: {
|
|
781
782
|
callType?: string;
|
|
782
783
|
apiKeyHash?: string | null;
|
|
@@ -785,7 +786,21 @@ function recordCompatFailure(
|
|
|
785
786
|
rawResponse?: unknown;
|
|
786
787
|
},
|
|
787
788
|
): void {
|
|
788
|
-
if (outcome.ok
|
|
789
|
+
if (outcome.ok) return;
|
|
790
|
+
if (!outcome.context) {
|
|
791
|
+
const model = body.displayModel || body.model;
|
|
792
|
+
const durationMs = Date.now() - startedAt;
|
|
793
|
+
rotator.recordRequestLog({ model, account: "No account", statusCode: outcome.status, ttfbMs: durationMs, totalMs: durationMs, inputTokens: 0, outputTokens: 0 });
|
|
794
|
+
logSpend({
|
|
795
|
+
apiKeyHash: options?.apiKeyHash || null, model, accountEmail: null,
|
|
796
|
+
callType: options?.callType || "compat", status: "failure", promptTokens: 0, completionTokens: 0,
|
|
797
|
+
startTime: new Date(startedAt).toISOString(), endTime: new Date().toISOString(),
|
|
798
|
+
ttfbMs: durationMs, durationMs, requestMessages: options?.rawRequest || body.request || body,
|
|
799
|
+
responseContent: null, requesterIp: options?.requesterIp || null,
|
|
800
|
+
metadata: { statusCode: outcome.status, stage: "admission" },
|
|
801
|
+
});
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
789
804
|
recordCompatOutcome(
|
|
790
805
|
rotator,
|
|
791
806
|
body,
|
|
@@ -2301,6 +2316,7 @@ async function completeResponsesViaRotator(
|
|
|
2301
2316
|
context?: RotationAttemptContext;
|
|
2302
2317
|
compressionStats?: CompressionStats | null;
|
|
2303
2318
|
}> {
|
|
2319
|
+
const startedAt = Date.now();
|
|
2304
2320
|
const createdAt = Math.floor(Date.now() / 1000);
|
|
2305
2321
|
const controller = new AbortController();
|
|
2306
2322
|
const abort = (): void => controller.abort();
|
|
@@ -2346,7 +2362,7 @@ async function completeResponsesViaRotator(
|
|
|
2346
2362
|
controller.signal,
|
|
2347
2363
|
);
|
|
2348
2364
|
if (!outcome.ok) {
|
|
2349
|
-
recordCompatFailure(rotator, body, outcome, options);
|
|
2365
|
+
recordCompatFailure(rotator, body, outcome, startedAt, options);
|
|
2350
2366
|
return {
|
|
2351
2367
|
completion: { text: "", inputTokens: 0, outputTokens: 0 },
|
|
2352
2368
|
status: outcome.status,
|
|
@@ -2396,6 +2412,7 @@ async function completeViaRotator(
|
|
|
2396
2412
|
isDeduplicated?: boolean;
|
|
2397
2413
|
compressionStats?: CompressionStats | null;
|
|
2398
2414
|
}> {
|
|
2415
|
+
const startedAt = Date.now();
|
|
2399
2416
|
const cfg = typeof rotator?.getConfig === "function" ? rotator.getConfig() : undefined;
|
|
2400
2417
|
const enabled = cfg?.idempotencyEnabled === true;
|
|
2401
2418
|
const windowMs = cfg?.idempotencyWindowMs ?? 2000;
|
|
@@ -2531,7 +2548,7 @@ async function completeViaRotator(
|
|
|
2531
2548
|
}
|
|
2532
2549
|
|
|
2533
2550
|
if (!outcome.ok) {
|
|
2534
|
-
recordCompatFailure(rotator, body, outcome, options);
|
|
2551
|
+
recordCompatFailure(rotator, body, outcome, startedAt, options);
|
|
2535
2552
|
if (outcome.status === 404) {
|
|
2536
2553
|
compatLogger.warn(
|
|
2537
2554
|
`Compat upstream 404 endpoint=${outcome.endpoint || "unknown"} ${summarizeCompatRequest(body)} error=${(outcome.errorText || "").slice(0, 300)}`,
|
package/src/model-access.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Policy data for access explanations and
|
|
1
|
+
/** Policy data for access explanations and account eligibility. */
|
|
2
2
|
export type AccessState = "allowed" | "blocked" | "conditional" | "unknown";
|
|
3
3
|
export interface AccessRule {
|
|
4
4
|
id: string;
|
|
@@ -17,15 +17,24 @@ export interface AccessRule {
|
|
|
17
17
|
note: string;
|
|
18
18
|
}
|
|
19
19
|
const google = "https://antigravity.google/docs/models";
|
|
20
|
-
const rule = (id: string, provider: string, plans: string[], modelPrefix: string, state: AccessState, evidence: AccessRule["evidence"], source: string, note: string, extra: Partial<AccessRule> = {}): AccessRule => ({ id, provider, plans, modelPrefix, state, evidence, source, verifiedAt: "2026-10-30", validFrom: "2026-10-30", reviewAfter: "2026-11-29", note, ...extra });
|
|
20
|
+
const rule = (id: string, provider: string, plans: string[], modelPrefix: string, state: AccessState, evidence: AccessRule["evidence"], source: string, note: string, extra: Partial<AccessRule> = {}): AccessRule => ({ id, provider, plans, modelPrefix, state, evidence, source, verifiedAt: provider === "google-antigravity" ? "2026-11-20" : "2026-10-30", validFrom: "2026-10-30", reviewAfter: provider === "google-antigravity" ? "2026-12-20" : "2026-11-29", note, ...extra });
|
|
21
21
|
export const MODEL_ACCESS_RULES: readonly AccessRule[] = [
|
|
22
22
|
rule("ag-flash-free", "google-antigravity", ["free", "plus", "pro-trial", "pro-paid", "ultra", "enterprise"], "gemini-3.8-flash", "allowed", "documented", google, "Gemini 3.8 Flash is listed for Free/Plus."),
|
|
23
|
-
...["
|
|
24
|
-
|
|
23
|
+
...["gemini-3.7-flash", "gemini-3.6-flash", "gemini-3.1-pro"].flatMap(model => [
|
|
24
|
+
rule(`ag-enterprise-only-${model}`, "google-antigravity", ["free", "plus", "pro-trial", "pro-paid", "ultra"], model, "blocked", "documented", google, "Listed only for Enterprise."),
|
|
25
|
+
rule(`ag-enterprise-${model}`, "google-antigravity", ["enterprise"], model, "allowed", "documented", google, "Listed for Enterprise."),
|
|
26
|
+
]),
|
|
27
|
+
...["claude-sonnet-4-6", "claude-opus-4-6"].map(model => rule(`ag-legacy-${model}`, "google-antigravity", ["free", "plus", "pro-paid", "pro-trial"], model, "allowed", "documented", google, "Removal announced for November 18; exact upstream rollout may differ.", { validUntil: "2026-11-18" })),
|
|
28
|
+
...["claude-sonnet-4-6", "claude-opus-4-6"].map(model => rule(`ag-legacy-unavailable-${model}`, "google-antigravity", ["ultra", "enterprise"], model, "blocked", "documented", google, "Not listed for Ultra or Enterprise.")),
|
|
29
|
+
...["gemini-4", "claude-sonnet-5-5", "claude-opus-5-5"].map(model => rule(`ag-paid-${model}`, "google-antigravity", ["free", "plus"], model, "blocked", "documented", google, "Not included in Free/Plus.")),
|
|
25
30
|
...["claude-sonnet-5-5", "claude-opus-5-5"].map(model => rule(`ag-trial-${model}`, "google-antigravity", ["pro-trial"], model, "blocked", "documented", google, "Claude 5.5 requires a non-trial Pro subscription or higher eligible plan.")),
|
|
26
|
-
...["gemini-4-argon", "claude-sonnet-5-5", "claude-opus-5-5"].map(model => rule(`ag-entitled-${model}`, "google-antigravity", ["pro-paid", "ultra", "enterprise"], model, "allowed", "documented", google, "Listed for paid Pro/Ultra; account entitlement and quota still apply.")),
|
|
31
|
+
...["gemini-4-argon", "gemini-4-neon", "gemini-4-hydrogen", "claude-sonnet-5-5", "claude-opus-5-5"].map(model => rule(`ag-entitled-${model}`, "google-antigravity", ["pro-paid", "ultra", "enterprise"], model, "allowed", "documented", google, "Listed for paid Pro/Ultra; account entitlement and quota still apply.")),
|
|
32
|
+
rule("ag-carbon-paid", "google-antigravity", ["pro-paid", "pro-trial"], "gemini-4-carbon", "blocked", "documented", google, "Gemini 4 Carbon requires Ultra or Enterprise."),
|
|
33
|
+
rule("ag-carbon-ultra", "google-antigravity", ["ultra", "enterprise"], "gemini-4-carbon", "allowed", "documented", google, "Gemini 4 Carbon is listed for Ultra and Enterprise."),
|
|
34
|
+
rule("ag-hydrogen-trial", "google-antigravity", ["pro-trial"], "gemini-4-hydrogen", "blocked", "documented", google, "Gemini 4 Hydrogen requires a non-trial Pro plan or higher."),
|
|
35
|
+
rule("ag-neon-trial", "google-antigravity", ["pro-trial"], "gemini-4-neon", "conditional", "documented", google, "Only eligible premium-device trials."),
|
|
27
36
|
rule("ag-argon-trial", "google-antigravity", ["pro-trial"], "gemini-4-argon", "conditional", "documented", google, "Only eligible premium-device trials; generic trial status is insufficient."),
|
|
28
|
-
...["gpt-6-luna", "gpt-5.6-terra"
|
|
37
|
+
...["gpt-6-luna", "gpt-5.6-terra"].map(model => rule(`codex-free-${model}`, "openai-codex", ["free"], model, "allowed", "documented", "https://help.openai.com/en/articles/20001354-gpt-6-and-other-models-in-chatgpt", "Listed for Free; live account entitlement and quota still apply.", { exact: true, verifiedAt: "2026-11-20", reviewAfter: "2026-12-20" })),
|
|
29
38
|
rule("codex-terra61-free", "openai-codex", ["free"], "gpt-6.1-terra", "blocked", "documented", "https://learn.chatgpt.com/docs/pricing", "Official ChatGPT Work/Codex availability lists paid plans for Terra 6.1. Free is not included; account-specific provider rejections are separate evidence.", { exact: true, verifiedAt: "2026-10-31", validFrom: "2026-10-26", reviewAfter: "2026-11-30" }),
|
|
30
39
|
rule("codex-terra61-plus", "openai-codex", ["plus"], "gpt-6.1-terra", "allowed", "documented", "https://learn.chatgpt.com/docs/pricing", "Terra 6.1 is listed for Plus in Work/Codex; rollout, surface access, quota and account restrictions still apply.", { exact: true, verifiedAt: "2026-10-31", validFrom: "2026-10-26", reviewAfter: "2026-11-30" }),
|
|
31
40
|
...["beam", "gemma4:31b", "gpt-oss:120b", "gpt-oss:20b", "nemotron-3-nano:30b", "nemotron-3-super", "nemotron-3-ultra"].map(model => rule(`ollama-free-${model}`, "ollama", ["free"], model, "allowed", "operator-confirmed", "Operator-provided Ollama free-credit list, 2026-10-30", "Included in the supplied free-credit list; quota and live entitlement are separate.")),
|
package/src/proxy.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { serveAccessProbe } from "./access-probe.js";
|
|
2
|
+
import { requiresAntigravityAccessPolicy } from "./auto-model-access.js";
|
|
2
3
|
import { observeAccessAttempt, logAccessPolicyShadow } from "./access-evidence.js";
|
|
3
4
|
import { serveModelAccessApi, serveProviderPlanApi } from "./model-access-api.js";
|
|
4
5
|
import { createUsageLimitsHandler, USAGE_LIMITS_PATH } from "./usage-limits.js";
|
|
@@ -1278,8 +1279,12 @@ export async function withRotation<T>(
|
|
|
1278
1279
|
ollamaModels: new Set(rotator.getOllamaModels?.() ?? []),
|
|
1279
1280
|
codexModels: new Set(rotator.getCodexModels?.() ?? []),
|
|
1280
1281
|
})?.id;
|
|
1281
|
-
const
|
|
1282
|
-
?
|
|
1282
|
+
const policyModel = requiresAntigravityAccessPolicy(model) || body.displayModel?.toLowerCase() === "auto"
|
|
1283
|
+
? model
|
|
1284
|
+
: body.catalogModel ?? model;
|
|
1285
|
+
const autoScope = providerId && (body.displayModel?.toLowerCase() === "auto" ||
|
|
1286
|
+
(providerId === DEFAULT_PROVIDER && requiresAntigravityAccessPolicy(policyModel)))
|
|
1287
|
+
? { providerId, modelId: policyModel }
|
|
1283
1288
|
: undefined;
|
|
1284
1289
|
const modelQuotaFamily = resolveQuotaModelKey(model) ??
|
|
1285
1290
|
resolveQuotaModelKey(applyModelAlias(model));
|
|
@@ -1311,7 +1316,7 @@ export async function withRotation<T>(
|
|
|
1311
1316
|
context?: RotationAttemptContext,
|
|
1312
1317
|
): RotationOutcome<T> => {
|
|
1313
1318
|
log(`[${model}] No healthy account available: ${reason}`, rotator, "warn");
|
|
1314
|
-
const retryAfterMs = rotator.getRetryAfterMs(model, providerId);
|
|
1319
|
+
const retryAfterMs = rotator.getRetryAfterMs(model, providerId, autoScope);
|
|
1315
1320
|
const contextFields = context
|
|
1316
1321
|
? { context, totalMs: Date.now() - context.requestStartMs }
|
|
1317
1322
|
: {};
|
|
@@ -1784,7 +1789,7 @@ async function handleProxyRequest(
|
|
|
1784
1789
|
const sendNoAccountsAvailable = (reason: string): void => {
|
|
1785
1790
|
if (clientController.signal.aborted || res.destroyed) return;
|
|
1786
1791
|
proxyLog(`[${body.model}] No healthy account available: ${reason}`, "warn");
|
|
1787
|
-
const retryAfterMs = rotator.getRetryAfterMs(body.model, providerId);
|
|
1792
|
+
const retryAfterMs = rotator.getRetryAfterMs(body.model, providerId, accessScope);
|
|
1788
1793
|
if (retryAfterMs > 0) {
|
|
1789
1794
|
const retrySec = Math.ceil(retryAfterMs / 1000);
|
|
1790
1795
|
res.writeHead(429, {
|
|
@@ -1877,6 +1882,10 @@ async function handleProxyRequest(
|
|
|
1877
1882
|
res.end(decision.errorText || JSON.stringify({ error: "Upstream error" }));
|
|
1878
1883
|
};
|
|
1879
1884
|
|
|
1885
|
+
const policyModel = requiresAntigravityAccessPolicy(body.model) ? body.model : body.catalogModel ?? body.model;
|
|
1886
|
+
const accessScope = providerId === DEFAULT_PROVIDER && requiresAntigravityAccessPolicy(policyModel)
|
|
1887
|
+
? { providerId, modelId: policyModel }
|
|
1888
|
+
: undefined;
|
|
1880
1889
|
const maxRetries = getStreamRecoveryMaxRetries(rotator);
|
|
1881
1890
|
const maxAttempts = maxRetries + 1;
|
|
1882
1891
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
@@ -1889,6 +1898,7 @@ async function handleProxyRequest(
|
|
|
1889
1898
|
body.model,
|
|
1890
1899
|
clientController.signal,
|
|
1891
1900
|
providerId,
|
|
1901
|
+
accessScope,
|
|
1892
1902
|
);
|
|
1893
1903
|
if (!account) {
|
|
1894
1904
|
if (clientController.signal.aborted || res.destroyed) return;
|
|
@@ -1913,7 +1923,7 @@ async function handleProxyRequest(
|
|
|
1913
1923
|
};
|
|
1914
1924
|
const rotateAndRelease = async (): Promise<AccountRuntime | null> => {
|
|
1915
1925
|
releaseCurrentAccount();
|
|
1916
|
-
const nextAccount = await rotator.rotateToNext(body.model, account, providerId);
|
|
1926
|
+
const nextAccount = await rotator.rotateToNext(body.model, account, providerId, accessScope);
|
|
1917
1927
|
return nextAccount;
|
|
1918
1928
|
};
|
|
1919
1929
|
proxyLog(
|
|
@@ -2138,7 +2148,7 @@ async function handleProxyRequest(
|
|
|
2138
2148
|
res.end();
|
|
2139
2149
|
|
|
2140
2150
|
if (shouldRotate) {
|
|
2141
|
-
await rotator.rotateToNext(body.model, account, providerId);
|
|
2151
|
+
await rotator.rotateToNext(body.model, account, providerId, accessScope);
|
|
2142
2152
|
}
|
|
2143
2153
|
return;
|
|
2144
2154
|
} catch (err) {
|
package/src/rotator.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { summarizeAutoAccess } from "./auto-access-shadow.js";
|
|
2
|
-
import { evaluateAutoModelAccess, type AutoAccountScope } from "./auto-model-access.js";
|
|
2
|
+
import { evaluateAutoModelAccess, requiresAntigravityAccessPolicy, type AutoAccountScope } from "./auto-model-access.js";
|
|
3
3
|
import { primeOllamaContextWindows } from "./providers/ollama/context-window.js";
|
|
4
4
|
import {
|
|
5
5
|
type AccountConfig,
|
|
@@ -1740,7 +1740,7 @@ export class AccountRotator {
|
|
|
1740
1740
|
if (!access.eligible) {
|
|
1741
1741
|
return {
|
|
1742
1742
|
reason: "provider-ineligible",
|
|
1743
|
-
detail: `
|
|
1743
|
+
detail: `model access policy: ${access.reason}`,
|
|
1744
1744
|
};
|
|
1745
1745
|
}
|
|
1746
1746
|
}
|
|
@@ -2117,6 +2117,7 @@ export class AccountRotator {
|
|
|
2117
2117
|
autoScope?: AutoAccountScope,
|
|
2118
2118
|
): Promise<AccountRuntime | null> {
|
|
2119
2119
|
if (signal?.aborted) return null;
|
|
2120
|
+
autoScope ??= this.getExplicitAccessScope(model, providerId);
|
|
2120
2121
|
const queueKey = this.getRequestQueueKey(model, providerId);
|
|
2121
2122
|
if (
|
|
2122
2123
|
this.hasQueuedRequest(queueKey) ||
|
|
@@ -2793,6 +2794,7 @@ export class AccountRotator {
|
|
|
2793
2794
|
autoScope?: AutoAccountScope,
|
|
2794
2795
|
): Promise<AccountRuntime | null> {
|
|
2795
2796
|
if (this.isProtectivePauseActive(Date.now())) return null;
|
|
2797
|
+
autoScope ??= this.getExplicitAccessScope(model, providerId);
|
|
2796
2798
|
const modelKey = model ? this.resolveRequestPoolKey(model, providerId) : null;
|
|
2797
2799
|
let excludeIdx: number;
|
|
2798
2800
|
if (typeof failedAccount === "number") {
|
|
@@ -2815,6 +2817,13 @@ export class AccountRotator {
|
|
|
2815
2817
|
: this.rotateDefault(Date.now(), false, excludeIdx);
|
|
2816
2818
|
}
|
|
2817
2819
|
|
|
2820
|
+
private getExplicitAccessScope(model?: string, providerId?: string): AutoAccountScope | undefined {
|
|
2821
|
+
if (!model) return undefined;
|
|
2822
|
+
const provider = providerId ?? getProviderIdForPoolKey(this.resolveRequestPoolKey(model, providerId));
|
|
2823
|
+
return provider === "openai-codex" || (provider === DEFAULT_PROVIDER && requiresAntigravityAccessPolicy(model))
|
|
2824
|
+
? { providerId: provider, modelId: model } : undefined;
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2818
2827
|
// Record a successful request. Returns true if rotation is needed.
|
|
2819
2828
|
recordRequest(account: AccountRuntime, model?: string, providerId?: string): boolean {
|
|
2820
2829
|
account.requestsSinceRotation++;
|
|
@@ -4277,6 +4286,7 @@ export class AccountRotator {
|
|
|
4277
4286
|
for (const account of this.accounts) {
|
|
4278
4287
|
if (account.disabled || account.flagged) continue;
|
|
4279
4288
|
const candidateProviderId = providerId ?? getProviderIdForPoolKey(modelKey);
|
|
4289
|
+
if (this.getProviderEligibilityRejection(account, modelKey, now)?.reason === "provider-ineligible") continue;
|
|
4280
4290
|
if (
|
|
4281
4291
|
autoScope &&
|
|
4282
4292
|
!evaluateAutoModelAccess(
|
|
@@ -4333,9 +4343,9 @@ export class AccountRotator {
|
|
|
4333
4343
|
return retryTimes.length > 0 ? Math.min(...retryTimes) : null;
|
|
4334
4344
|
}
|
|
4335
4345
|
|
|
4336
|
-
getRetryAfterMs(model?: string, providerId?: string): number {
|
|
4346
|
+
getRetryAfterMs(model?: string, providerId?: string, autoScope?: AutoAccountScope): number {
|
|
4337
4347
|
const now = Date.now();
|
|
4338
|
-
const retryTimes = this.getRequestAvailabilityTimes(model, now, providerId);
|
|
4348
|
+
const retryTimes = this.getRequestAvailabilityTimes(model, now, providerId, autoScope ?? this.getExplicitAccessScope(model, providerId));
|
|
4339
4349
|
if (retryTimes.length === 0) return 0;
|
|
4340
4350
|
return Math.max(1000, Math.min(...retryTimes) - now);
|
|
4341
4351
|
}
|