jeopi-ai 16.6.24 → 16.6.26
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 +9 -0
- package/package.json +4 -4
- package/src/auth-retry.ts +27 -7
- package/src/auth-storage.ts +61 -24
- package/src/providers/google-interactions.ts +3 -0
- package/src/providers/openai-codex-responses.ts +3 -0
- package/src/stream.ts +16 -12
- package/src/usage/google-antigravity.ts +39 -3
- package/src/utils/openai-http.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [16.6.25] - 2026-11-14
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Scoped Antigravity quota limits and `blockScope` per model/bucket (`gemini-4-argon-*` weekly vs other `gemini-*` daily) and ran window inference across all models so exhausting one model family no longer blocks healthy sibling accounts or other model families.
|
|
10
|
+
- Enabled default usage-based credential ranking and availability checking for all usage-capable providers (`google-gemini-cli`, `github-copilot`, `cursor`, `kimi-code`, `zai`, `ollama`, `ollama-cloud`, `opencode-go`) in addition to `openai-codex`, `anthropic`, and `google-antigravity`.
|
|
11
|
+
- Skipped `forceRefresh` on usage-limit errors in `streamSimple`, `withAuth`, and `withOAuthAccess`, added multi-sibling rotation across up to 8 untried credentials, and stopped `fetchWithRetry` from sleeping on 429 usage-limit responses so failover happens immediately.
|
|
12
|
+
- Preserved `blockScope` and session stickiness in `rotateSessionCredential` and `#selectCredentialByType`, and returned `undefined` from `AuthStorage.resolver` when no unblocked sibling remains.
|
|
13
|
+
|
|
5
14
|
## [16.6.23] - 2026-11-13
|
|
6
15
|
|
|
7
16
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "jeopi-ai",
|
|
4
|
-
"version": "16.6.
|
|
4
|
+
"version": "16.6.26",
|
|
5
5
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
6
6
|
"homepage": "https://github.com/akillness/jeopi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@bufbuild/protobuf": "^2.12.0",
|
|
41
|
-
"jeopi-catalog": "16.6.
|
|
42
|
-
"jeopi-utils": "16.6.
|
|
43
|
-
"jeopi-wire": "16.6.
|
|
41
|
+
"jeopi-catalog": "16.6.26",
|
|
42
|
+
"jeopi-utils": "16.6.26",
|
|
43
|
+
"jeopi-wire": "16.6.26",
|
|
44
44
|
"arktype": "2.2.3",
|
|
45
45
|
"zod": "^4"
|
|
46
46
|
},
|
package/src/auth-retry.ts
CHANGED
|
@@ -135,15 +135,25 @@ export async function withAuth<T>(
|
|
|
135
135
|
lastError = error;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const triedKeys = new Set<string>([lastKey]);
|
|
139
|
+
const maxRotations = 8;
|
|
140
|
+
let refreshedSame = false;
|
|
141
|
+
for (let i = 0; i < maxRotations; i++) {
|
|
142
|
+
const lastChance = refreshedSame;
|
|
143
|
+
if (!lastChance) refreshedSame = true;
|
|
144
|
+
const nextKey = await resolveRetryKey(resolver, lastChance, lastError, signal);
|
|
145
|
+
if (nextKey === undefined || triedKeys.has(nextKey)) {
|
|
146
|
+
if (!lastChance) continue;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
triedKeys.add(nextKey);
|
|
141
150
|
lastKey = nextKey;
|
|
142
151
|
try {
|
|
143
152
|
return await attempt(nextKey);
|
|
144
153
|
} catch (error) {
|
|
145
154
|
if (!isAuthError(error)) throw error;
|
|
146
155
|
lastError = error;
|
|
156
|
+
if (lastChance) refreshedSame = false;
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
159
|
|
|
@@ -219,7 +229,8 @@ export async function withOAuthAccess<T>(
|
|
|
219
229
|
const resolveStep = async (lastChance: boolean, error: unknown): Promise<OAuthAccess | undefined> => {
|
|
220
230
|
try {
|
|
221
231
|
if (!lastChance) return await storage.getOAuthAccess(provider, sessionId, { forceRefresh: true, signal });
|
|
222
|
-
await storage.rotateSessionCredential(provider, sessionId, { error, signal });
|
|
232
|
+
const switched = await storage.rotateSessionCredential(provider, sessionId, { error, signal });
|
|
233
|
+
if (!switched) return undefined;
|
|
223
234
|
return await storage.getOAuthAccess(provider, sessionId, { signal });
|
|
224
235
|
} catch {
|
|
225
236
|
return undefined;
|
|
@@ -233,16 +244,25 @@ export async function withOAuthAccess<T>(
|
|
|
233
244
|
if (!isAuthError(error)) throw error;
|
|
234
245
|
lastError = error;
|
|
235
246
|
}
|
|
236
|
-
|
|
237
|
-
|
|
247
|
+
const triedTokens = new Set<string>([lastAccess.accessToken]);
|
|
248
|
+
const maxRotations = 8;
|
|
249
|
+
let refreshedSame = false;
|
|
250
|
+
for (let i = 0; i < maxRotations; i++) {
|
|
251
|
+
const lastChance = refreshedSame;
|
|
252
|
+
if (!lastChance) refreshedSame = true;
|
|
238
253
|
const next = await resolveStep(lastChance, lastError);
|
|
239
|
-
if (!next || next.accessToken
|
|
254
|
+
if (!next || triedTokens.has(next.accessToken)) {
|
|
255
|
+
if (!lastChance) continue;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
triedTokens.add(next.accessToken);
|
|
240
259
|
lastAccess = next;
|
|
241
260
|
try {
|
|
242
261
|
return await attempt(next);
|
|
243
262
|
} catch (error) {
|
|
244
263
|
if (!isAuthError(error)) throw error;
|
|
245
264
|
lastError = error;
|
|
265
|
+
if (lastChance) refreshedSame = false;
|
|
246
266
|
}
|
|
247
267
|
}
|
|
248
268
|
|
package/src/auth-storage.ts
CHANGED
|
@@ -769,8 +769,32 @@ const DEFAULT_RANKING_STRATEGIES = new Map<Provider, CredentialRankingStrategy>(
|
|
|
769
769
|
["google-antigravity", antigravityRankingStrategy],
|
|
770
770
|
]);
|
|
771
771
|
|
|
772
|
+
const defaultUsageRankingStrategy: CredentialRankingStrategy = {
|
|
773
|
+
findWindowLimits(report) {
|
|
774
|
+
if (report.limits.length === 0) return {};
|
|
775
|
+
const sorted = [...report.limits].sort((a, b) => {
|
|
776
|
+
const aUsed = a.amount.usedFraction ?? 0;
|
|
777
|
+
const bUsed = b.amount.usedFraction ?? 0;
|
|
778
|
+
return bUsed - aUsed;
|
|
779
|
+
});
|
|
780
|
+
return { primary: sorted[0] };
|
|
781
|
+
},
|
|
782
|
+
windowDefaults: { primaryMs: 24 * 60 * 60 * 1000, secondaryMs: 7 * 24 * 60 * 60 * 1000 },
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
const DEFAULT_USAGE_RANKED_PROVIDERS: ReadonlySet<Provider> = new Set([
|
|
786
|
+
"google-gemini-cli",
|
|
787
|
+
"kimi-code",
|
|
788
|
+
"cursor",
|
|
789
|
+
"zai",
|
|
790
|
+
"ollama-cloud",
|
|
791
|
+
]);
|
|
792
|
+
|
|
772
793
|
function resolveDefaultRankingStrategy(provider: Provider): CredentialRankingStrategy | undefined {
|
|
773
|
-
return
|
|
794
|
+
return (
|
|
795
|
+
DEFAULT_RANKING_STRATEGIES.get(provider) ??
|
|
796
|
+
(DEFAULT_USAGE_RANKED_PROVIDERS.has(provider) ? defaultUsageRankingStrategy : undefined)
|
|
797
|
+
);
|
|
774
798
|
}
|
|
775
799
|
|
|
776
800
|
function parseUsageCacheEntry<T>(raw: string): UsageCacheEntry<T> | undefined {
|
|
@@ -1444,6 +1468,7 @@ export class AuthStorage {
|
|
|
1444
1468
|
provider: string,
|
|
1445
1469
|
type: T,
|
|
1446
1470
|
sessionId?: string,
|
|
1471
|
+
blockScope?: string,
|
|
1447
1472
|
): { credential: Extract<AuthCredential, { type: T }>; index: number } | undefined {
|
|
1448
1473
|
const credentials = this.#getCredentialsForProvider(provider)
|
|
1449
1474
|
.map((credential, index) => ({ credential, index }))
|
|
@@ -1456,12 +1481,19 @@ export class AuthStorage {
|
|
|
1456
1481
|
if (credentials.length === 1) return credentials[0];
|
|
1457
1482
|
|
|
1458
1483
|
const providerKey = this.#getProviderTypeKey(provider, type);
|
|
1484
|
+
const sessionCredential = this.#getSessionCredential(provider, sessionId);
|
|
1485
|
+
if (sessionCredential?.type === type) {
|
|
1486
|
+
const sticky = credentials.find(entry => entry.index === sessionCredential.index);
|
|
1487
|
+
if (sticky && !this.#isCredentialBlocked(providerKey, sticky.index, blockScope)) {
|
|
1488
|
+
return sticky;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1459
1491
|
const order = this.#getCredentialOrder(providerKey, sessionId, credentials.length);
|
|
1460
1492
|
const fallback = credentials[order[0]];
|
|
1461
1493
|
|
|
1462
1494
|
for (const idx of order) {
|
|
1463
1495
|
const candidate = credentials[idx];
|
|
1464
|
-
if (!this.#isCredentialBlocked(providerKey, candidate.index)) {
|
|
1496
|
+
if (!this.#isCredentialBlocked(providerKey, candidate.index, blockScope)) {
|
|
1465
1497
|
return candidate;
|
|
1466
1498
|
}
|
|
1467
1499
|
}
|
|
@@ -2070,33 +2102,33 @@ export class AuthStorage {
|
|
|
2070
2102
|
* refresh override can address the row. Mirrors the matching logic in
|
|
2071
2103
|
* {@link AuthStorage.#persistRefreshedUsageCredential}.
|
|
2072
2104
|
*/
|
|
2105
|
+
#matchesUsageCredentialRow(entryCredential: AuthCredential, previous: UsageCredential): boolean {
|
|
2106
|
+
if (entryCredential.type !== "oauth") return false;
|
|
2107
|
+
if (previous.refreshToken && entryCredential.refresh === previous.refreshToken) return true;
|
|
2108
|
+
if (previous.accessToken && entryCredential.access === previous.accessToken) return true;
|
|
2109
|
+
const hasIdentity = Boolean(
|
|
2110
|
+
(previous.accountId && entryCredential.accountId) ||
|
|
2111
|
+
(previous.email && entryCredential.email) ||
|
|
2112
|
+
(previous.projectId && entryCredential.projectId),
|
|
2113
|
+
);
|
|
2114
|
+
if (!hasIdentity) return false;
|
|
2115
|
+
return (
|
|
2116
|
+
entryCredential.accountId === previous.accountId &&
|
|
2117
|
+
entryCredential.email === previous.email &&
|
|
2118
|
+
entryCredential.projectId === previous.projectId &&
|
|
2119
|
+
entryCredential.enterpriseUrl === previous.enterpriseUrl
|
|
2120
|
+
);
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2073
2123
|
#findStoredCredentialIdForUsageCredential(provider: Provider, previous: UsageCredential): number | undefined {
|
|
2074
2124
|
const entries = this.#getStoredCredentials(provider);
|
|
2075
|
-
const match = entries.find(entry =>
|
|
2076
|
-
if (entry.credential.type !== "oauth") return false;
|
|
2077
|
-
if (previous.refreshToken && entry.credential.refresh === previous.refreshToken) return true;
|
|
2078
|
-
if (previous.accessToken && entry.credential.access === previous.accessToken) return true;
|
|
2079
|
-
return (
|
|
2080
|
-
entry.credential.accountId === previous.accountId &&
|
|
2081
|
-
entry.credential.email === previous.email &&
|
|
2082
|
-
entry.credential.projectId === previous.projectId
|
|
2083
|
-
);
|
|
2084
|
-
});
|
|
2125
|
+
const match = entries.find(entry => this.#matchesUsageCredentialRow(entry.credential, previous));
|
|
2085
2126
|
return match?.id;
|
|
2086
2127
|
}
|
|
2087
2128
|
|
|
2088
2129
|
#persistRefreshedUsageCredential(provider: Provider, previous: UsageCredential, next: UsageCredential): void {
|
|
2089
2130
|
const entries = this.#getStoredCredentials(provider);
|
|
2090
|
-
const index = entries.findIndex(entry =>
|
|
2091
|
-
if (entry.credential.type !== "oauth") return false;
|
|
2092
|
-
if (previous.refreshToken && entry.credential.refresh === previous.refreshToken) return true;
|
|
2093
|
-
if (previous.accessToken && entry.credential.access === previous.accessToken) return true;
|
|
2094
|
-
return (
|
|
2095
|
-
entry.credential.accountId === previous.accountId &&
|
|
2096
|
-
entry.credential.email === previous.email &&
|
|
2097
|
-
entry.credential.projectId === previous.projectId
|
|
2098
|
-
);
|
|
2099
|
-
});
|
|
2131
|
+
const index = entries.findIndex(entry => this.#matchesUsageCredentialRow(entry.credential, previous));
|
|
2100
2132
|
if (index === -1) return;
|
|
2101
2133
|
const existing = entries[index]!.credential;
|
|
2102
2134
|
if (existing.type !== "oauth") return;
|
|
@@ -4288,13 +4320,15 @@ export class AuthStorage {
|
|
|
4288
4320
|
}
|
|
4289
4321
|
|
|
4290
4322
|
const providerKey = this.#getProviderTypeKey(provider, sessionCredential.type);
|
|
4323
|
+
const strategy = this.#rankingStrategyResolver?.(provider);
|
|
4324
|
+
const blockScope = strategy?.blockScope?.({ modelId: options?.modelId });
|
|
4291
4325
|
// Snapshot sibling availability before mutating so a soft-deleting
|
|
4292
4326
|
// suspect hook can't reindex the answer out from under us.
|
|
4293
4327
|
const hasSibling = this.#getCredentialsForProvider(provider).some(
|
|
4294
4328
|
(credential, index) =>
|
|
4295
4329
|
credential.type === sessionCredential.type &&
|
|
4296
4330
|
index !== sessionCredential.index &&
|
|
4297
|
-
!this.#isCredentialBlocked(providerKey, index),
|
|
4331
|
+
!this.#isCredentialBlocked(providerKey, index, blockScope),
|
|
4298
4332
|
);
|
|
4299
4333
|
const target = this.#getStoredCredentials(provider)[sessionCredential.index];
|
|
4300
4334
|
this.#clearSessionCredential(provider, sessionId);
|
|
@@ -4335,9 +4369,12 @@ export class AuthStorage {
|
|
|
4335
4369
|
return this.getApiKey(provider, sessionId, { baseUrl, modelId, signal });
|
|
4336
4370
|
}
|
|
4337
4371
|
if (lastChance) {
|
|
4338
|
-
await this.rotateSessionCredential(provider, sessionId, { error, modelId, signal });
|
|
4372
|
+
const switched = await this.rotateSessionCredential(provider, sessionId, { error, modelId, signal });
|
|
4373
|
+
if (!switched) return undefined;
|
|
4339
4374
|
return this.getApiKey(provider, sessionId, { baseUrl, modelId, signal });
|
|
4340
4375
|
}
|
|
4376
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : undefined;
|
|
4377
|
+
if (isUsageLimitOutcome(AIError.status(error), message)) return undefined;
|
|
4341
4378
|
return this.getApiKey(provider, sessionId, { baseUrl, modelId, forceRefresh: true, signal });
|
|
4342
4379
|
};
|
|
4343
4380
|
}
|
|
@@ -2,6 +2,7 @@ import { parseGeminiModel } from "jeopi-catalog/identity";
|
|
|
2
2
|
import { calculateCost } from "jeopi-catalog/models";
|
|
3
3
|
import { fetchWithRetry, readSseJson } from "jeopi-utils";
|
|
4
4
|
import * as AIError from "../error";
|
|
5
|
+
import { isUsageLimitOutcome } from "../error/rate-limit";
|
|
5
6
|
import type {
|
|
6
7
|
AssistantMessage,
|
|
7
8
|
Context,
|
|
@@ -542,6 +543,8 @@ export function streamGoogleInteractions<T extends GoogleInteractionsApi>(args:
|
|
|
542
543
|
body: JSON.stringify(requestBody),
|
|
543
544
|
signal: options?.signal,
|
|
544
545
|
fetch: plan.fetch,
|
|
546
|
+
shouldRetryResponse: (response, body) =>
|
|
547
|
+
response.status !== 429 || !isUsageLimitOutcome(response.status, body),
|
|
545
548
|
});
|
|
546
549
|
if (!response.ok) {
|
|
547
550
|
const errorText = await response.text().catch(() => "");
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "jeopi-utils";
|
|
16
16
|
import packageJson from "../../package.json" with { type: "json" };
|
|
17
17
|
import * as AIError from "../error";
|
|
18
|
+
import { isUsageLimitOutcome } from "../error/rate-limit";
|
|
18
19
|
import { getEnvApiKey } from "../stream";
|
|
19
20
|
import type {
|
|
20
21
|
Api,
|
|
@@ -3010,6 +3011,8 @@ async function openCodexSseEventStream(
|
|
|
3010
3011
|
maxAttempts: CODEX_MAX_RETRIES + 1,
|
|
3011
3012
|
defaultDelayMs: attempt => CODEX_RETRY_DELAY_MS * (attempt + 1),
|
|
3012
3013
|
maxDelayMs: CODEX_RATE_LIMIT_BUDGET_MS,
|
|
3014
|
+
shouldRetryResponse: (response, body) =>
|
|
3015
|
+
response.status !== 429 || !isUsageLimitOutcome(response.status, body),
|
|
3013
3016
|
fetch: fetchOverride,
|
|
3014
3017
|
timeout: false,
|
|
3015
3018
|
});
|
package/src/stream.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { CATALOG_PROVIDERS, type ProviderCatalogEntry } from "jeopi-catalog/provider-models";
|
|
16
16
|
import { $env, $pickenv, getConfigRootDir, isEnoent, logger, withExtraCaFetch } from "jeopi-utils";
|
|
17
17
|
import { getCustomApi } from "./api-registry";
|
|
18
|
-
import {
|
|
18
|
+
import { isApiKeyResolver, resolveRetryKey } from "./auth-retry";
|
|
19
19
|
import * as AIError from "./error";
|
|
20
20
|
import { ProviderHttpError } from "./error";
|
|
21
21
|
import { isUsageLimitOutcome } from "./error/rate-limit";
|
|
@@ -1036,23 +1036,27 @@ export function streamSimple<TApi extends Api>(
|
|
|
1036
1036
|
outer.fail(new AIError.MissingApiKeyError(model.provider));
|
|
1037
1037
|
return;
|
|
1038
1038
|
}
|
|
1039
|
+
const triedKeys = new Set<string>([lastKey]);
|
|
1039
1040
|
let failure = await runAttempt(lastKey, true);
|
|
1040
1041
|
if (!failure) return;
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
// final step's attempt clears the capture flag so it emits directly.
|
|
1045
|
-
for (let step = 0; step < AUTH_RETRY_STEPS.length; step++) {
|
|
1046
|
-
// Caller aborted between attempts: don't mint a fresh token or fire
|
|
1047
|
-
// another doomed request — emit the captured failure instead.
|
|
1042
|
+
const maxRotations = 8;
|
|
1043
|
+
let refreshedSame = false;
|
|
1044
|
+
for (let rotation = 0; rotation < maxRotations; rotation++) {
|
|
1048
1045
|
if (signal?.aborted) break;
|
|
1049
|
-
const
|
|
1050
|
-
if (
|
|
1046
|
+
const lastChance = refreshedSame;
|
|
1047
|
+
if (!lastChance) refreshedSame = true;
|
|
1048
|
+
const nextKey = await resolveRetryKey(apiKeyResolver, lastChance, failure.error, signal);
|
|
1049
|
+
if (nextKey === undefined || triedKeys.has(nextKey)) {
|
|
1050
|
+
if (!lastChance) continue;
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
triedKeys.add(nextKey);
|
|
1051
1054
|
lastKey = nextKey;
|
|
1052
|
-
const
|
|
1053
|
-
const next = await runAttempt(nextKey, !
|
|
1055
|
+
const isLastAttempt = rotation === maxRotations - 1;
|
|
1056
|
+
const next = await runAttempt(nextKey, !isLastAttempt);
|
|
1054
1057
|
if (!next) return;
|
|
1055
1058
|
failure = next;
|
|
1059
|
+
if (lastChance) refreshedSame = false;
|
|
1056
1060
|
}
|
|
1057
1061
|
emitFailure(failure);
|
|
1058
1062
|
})();
|
|
@@ -327,9 +327,19 @@ async function fetchAntigravityUsage(params: UsageFetchParams, ctx: UsageFetchCo
|
|
|
327
327
|
>();
|
|
328
328
|
let earliestReset: number | undefined;
|
|
329
329
|
|
|
330
|
-
|
|
330
|
+
const modelEntries = Object.entries(data.models ?? {});
|
|
331
|
+
const allQuotaInfos: AntigravityQuotaInfo[] = [];
|
|
332
|
+
const perModelQuotaInfos: Array<{ modelId: string; quotaInfos: AntigravityQuotaInfo[] }> = [];
|
|
333
|
+
for (const [modelId, modelInfo] of modelEntries) {
|
|
331
334
|
const quotaInfos = normalizeQuotaInfos(modelInfo);
|
|
332
|
-
|
|
335
|
+
allQuotaInfos.push(...quotaInfos);
|
|
336
|
+
perModelQuotaInfos.push({ modelId, quotaInfos });
|
|
337
|
+
}
|
|
338
|
+
const inferredDescriptors = inferWindowDescriptors(allQuotaInfos, nowMs);
|
|
339
|
+
const modelLimits: Record<string, string[]> = {};
|
|
340
|
+
|
|
341
|
+
for (const { modelId, quotaInfos } of perModelQuotaInfos) {
|
|
342
|
+
const modelLimitIds = new Set<string>();
|
|
333
343
|
for (const quotaInfo of quotaInfos) {
|
|
334
344
|
const amount = buildAmount(quotaInfo);
|
|
335
345
|
const window = parseWindow(quotaInfo, inferredDescriptors.get(quotaInfo));
|
|
@@ -344,6 +354,7 @@ async function fetchAntigravityUsage(params: UsageFetchParams, ctx: UsageFetchCo
|
|
|
344
354
|
// weeklyQuotaInfo entries.
|
|
345
355
|
const windowId = window?.id ?? quotaInfo.windowId ?? "default";
|
|
346
356
|
const key = `${counterKey}|${tierKey}|${windowId}`;
|
|
357
|
+
modelLimitIds.add(`${params.provider}:${counterKey}:${tierKey}:${windowId}`);
|
|
347
358
|
const existing = deduped.get(key);
|
|
348
359
|
if (!existing) {
|
|
349
360
|
deduped.set(key, { amount, window, tier: quotaInfo.tier, tierKey, windowId, counterName, counterKey });
|
|
@@ -382,6 +393,9 @@ async function fetchAntigravityUsage(params: UsageFetchParams, ctx: UsageFetchCo
|
|
|
382
393
|
counterKey: existing.counterKey,
|
|
383
394
|
});
|
|
384
395
|
}
|
|
396
|
+
if (modelLimitIds.size > 0) {
|
|
397
|
+
modelLimits[modelId.toLowerCase()] = [...modelLimitIds];
|
|
398
|
+
}
|
|
385
399
|
}
|
|
386
400
|
|
|
387
401
|
const limits: UsageLimit[] = [];
|
|
@@ -412,6 +426,7 @@ async function fetchAntigravityUsage(params: UsageFetchParams, ctx: UsageFetchCo
|
|
|
412
426
|
const metadata: UsageReport["metadata"] = {
|
|
413
427
|
endpoint: successfulEndpoint,
|
|
414
428
|
projectId: credential.projectId,
|
|
429
|
+
...(Object.keys(modelLimits).length > 0 ? { modelLimits } : {}),
|
|
415
430
|
};
|
|
416
431
|
if (credential.email) metadata.email = credential.email;
|
|
417
432
|
if (credential.accountId) metadata.accountId = credential.accountId;
|
|
@@ -454,10 +469,28 @@ function scopeAntigravityLimitsForModel(
|
|
|
454
469
|
report: UsageReport,
|
|
455
470
|
context: CredentialRankingContext | undefined,
|
|
456
471
|
): UsageLimit[] {
|
|
472
|
+
const modelId = context?.modelId?.toLowerCase();
|
|
473
|
+
const rawModelLimits = report.metadata?.modelLimits;
|
|
474
|
+
if (modelId && rawModelLimits && typeof rawModelLimits === "object" && !Array.isArray(rawModelLimits)) {
|
|
475
|
+
const mappedIds = (rawModelLimits as Record<string, unknown>)[modelId];
|
|
476
|
+
if (Array.isArray(mappedIds) && mappedIds.length > 0) {
|
|
477
|
+
const idSet = new Set(mappedIds.filter((id): id is string => typeof id === "string"));
|
|
478
|
+
const exact = report.limits.filter(limit => idSet.has(limit.id));
|
|
479
|
+
if (exact.length > 0) return exact;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
457
482
|
const counterKey = getAntigravityCounterKeyForModel(context);
|
|
458
483
|
if (!counterKey) return [];
|
|
459
484
|
const backendLimits = getAntigravityCounterLimits(report, counterKey);
|
|
460
|
-
if (backendLimits.length > 0)
|
|
485
|
+
if (backendLimits.length > 0) {
|
|
486
|
+
if (counterKey === "google" && modelId) {
|
|
487
|
+
const isArgon = modelId.startsWith("gemini-4-argon");
|
|
488
|
+
const windowSuffix = isArgon ? ":weekly" : ":daily";
|
|
489
|
+
const windowMatched = backendLimits.filter(limit => limit.id.toLowerCase().endsWith(windowSuffix));
|
|
490
|
+
if (windowMatched.length > 0) return windowMatched;
|
|
491
|
+
}
|
|
492
|
+
return backendLimits;
|
|
493
|
+
}
|
|
461
494
|
return getAntigravityCounterLimits(report, "default");
|
|
462
495
|
}
|
|
463
496
|
|
|
@@ -488,6 +521,9 @@ export const antigravityRankingStrategy: CredentialRankingStrategy = {
|
|
|
488
521
|
// cannot fall through to AuthStorage's provider-wide block bucket.
|
|
489
522
|
blockScope(context) {
|
|
490
523
|
const counterKey = getAntigravityCounterKeyForModel(context);
|
|
524
|
+
if (counterKey === "google" && context?.modelId?.toLowerCase().startsWith("gemini-4-argon")) {
|
|
525
|
+
return "counter:google:argon";
|
|
526
|
+
}
|
|
491
527
|
return `counter:${counterKey ?? "unknown"}`;
|
|
492
528
|
},
|
|
493
529
|
// Antigravity windows carry `durationMs` when the response identifies them
|
package/src/utils/openai-http.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { fetchWithRetry, readSseJson, type SseEventObserver } from "jeopi-utils";
|
|
18
18
|
import * as AIError from "../error";
|
|
19
19
|
import { OpenAIHttpError } from "../error";
|
|
20
|
+
import { isUsageLimitOutcome } from "../error/rate-limit";
|
|
20
21
|
|
|
21
22
|
export { OpenAIHttpError };
|
|
22
23
|
|
|
@@ -72,6 +73,7 @@ export async function postOpenAIStream<TEvent>(init: OpenAIStreamRequestInit): P
|
|
|
72
73
|
signal: init.signal,
|
|
73
74
|
fetch: init.fetch,
|
|
74
75
|
maxAttempts: init.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
|
|
76
|
+
shouldRetryResponse: (response, body) => response.status !== 429 || !isUsageLimitOutcome(response.status, body),
|
|
75
77
|
// Bun's native fetch enforces a hard ~300s pre-response timeout (issue #2422).
|
|
76
78
|
// Cold large-context streams legitimately exceed it; the caller's
|
|
77
79
|
// `firstEventTimeoutMs`/`AbortSignal` already govern stuck requests.
|