tuxevil-rotator 4.4.8 → 4.5.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 +40 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/plugins/opencode-discovery/index.mjs +50 -21
- package/src/access-probe.ts +1 -1
- package/src/account-store.ts +14 -2
- package/src/audio-transcription.ts +1 -0
- package/src/auto-model-access.ts +22 -0
- package/src/compat/model-specs.ts +7 -0
- package/src/compat/schema-sanitizer.ts +420 -287
- package/src/compat.ts +110 -66
- package/src/config-defaults.ts +7 -0
- package/src/fetch-with-retry.ts +294 -16
- package/src/idempotency.ts +3 -1
- package/src/model-access-api.ts +9 -1
- package/src/model-access.ts +2 -2
- package/src/notification-poller.ts +9 -1
- package/src/provider-catalog-evidence.ts +18 -1
- package/src/providers/adapter.ts +10 -0
- package/src/providers/credential-helpers.ts +34 -0
- package/src/providers/google-antigravity/aicode-eligibility.ts +256 -0
- package/src/providers/google-antigravity/aicode-forward.ts +381 -0
- package/src/providers/google-antigravity/aicode.ts +478 -0
- package/src/providers/google-antigravity/catalog.ts +6 -0
- package/src/providers/google-antigravity/code-assist.ts +53 -41
- package/src/providers/google-antigravity/dynamic-catalog.ts +72 -7
- package/src/providers/google-antigravity/forward.ts +309 -86
- package/src/providers/google-antigravity/index.ts +122 -4
- package/src/providers/google-antigravity/oauth.ts +22 -12
- package/src/providers/google-antigravity/quota.ts +781 -34
- package/src/providers/google-antigravity/translators.ts +55 -46
- package/src/providers/google-antigravity/twin-payload.ts +231 -0
- package/src/providers/ollama/quota.ts +6 -4
- package/src/providers/openai-codex/compat.ts +11 -2
- package/src/providers/openai-codex/quota.ts +2 -1
- package/src/providers/opencode-zen/catalog.ts +159 -13
- package/src/providers/opencode-zen/discovery.ts +50 -0
- package/src/providers/opencode-zen/index.ts +7 -2
- package/src/providers/opencode-zen/quota.ts +14 -1
- package/src/proxy.ts +570 -87
- package/src/quota-pools.ts +76 -1
- package/src/rate-limit-parser.ts +239 -19
- package/src/rotator.ts +848 -297
- package/src/stream-guards.ts +87 -1
- package/src/telemetry.ts +17 -3
- package/src/types.ts +184 -9
- package/src/validators.ts +3 -0
- package/src/web/lib/accounts.ts +2 -0
- package/src/web/lib/attention.ts +19 -0
- package/src/web/lib/models.ts +6 -1
- package/src/web/lib/status.ts +22 -4
- package/src/web/pages/AccountDetail.tsx +49 -2
- package/src/web/pages/Accounts.tsx +38 -3
- package/src/web/pages/ModelAccess.tsx +4 -0
- package/src/web/pages/Models.tsx +2 -1
- package/src/web/pages/Overview.tsx +15 -1
- package/src/web/styles/app.css +73 -3
- package/tools/telemetry-receiver/receiver.js +523 -266
|
@@ -34,12 +34,20 @@ import {
|
|
|
34
34
|
import {
|
|
35
35
|
TOKEN_URL,
|
|
36
36
|
KICKSTART_MODEL_FOR_QUOTA_POOL,
|
|
37
|
+
KICKSTART_FALLBACK_MODELS_FOR_QUOTA_POOL,
|
|
38
|
+
KICKSTART_PRO_MODELS_FOR_QUOTA_POOL,
|
|
39
|
+
REQUEST_USER_AGENT,
|
|
37
40
|
applyModelAlias,
|
|
38
41
|
resolveQuotaModelKey,
|
|
39
42
|
} from "../../types.js";
|
|
40
43
|
import type { AccountRuntime } from "../../types.js";
|
|
44
|
+
import {
|
|
45
|
+
getAccountIdentity,
|
|
46
|
+
getCredentialGeneration,
|
|
47
|
+
} from "../../account-identity.js";
|
|
41
48
|
import { fetchWithRetry } from "../../fetch-with-retry.js";
|
|
42
49
|
import { logger } from "../../logger.js";
|
|
50
|
+
import { DEFAULT_PROVIDER, getProviderProjectId } from "../credential-helpers.js";
|
|
43
51
|
import { getAccountProxyDispatcher } from "../proxy-dispatcher.js";
|
|
44
52
|
|
|
45
53
|
const providerLog = logger.child("provider/google");
|
|
@@ -66,7 +74,10 @@ async function ensureGoogleToken(account: AccountRuntime): Promise<void> {
|
|
|
66
74
|
const oauth = getOAuthClientConfig();
|
|
67
75
|
const response = await fetchWithRetry(TOKEN_URL, {
|
|
68
76
|
method: "POST",
|
|
69
|
-
headers: {
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
79
|
+
"User-Agent": REQUEST_USER_AGENT,
|
|
80
|
+
},
|
|
70
81
|
body: new URLSearchParams({
|
|
71
82
|
client_id: oauth.clientId,
|
|
72
83
|
client_secret: oauth.clientSecret,
|
|
@@ -82,9 +93,13 @@ async function ensureGoogleToken(account: AccountRuntime): Promise<void> {
|
|
|
82
93
|
const data = (await response.json()) as {
|
|
83
94
|
access_token: string;
|
|
84
95
|
expires_in: number;
|
|
96
|
+
scope?: string;
|
|
85
97
|
};
|
|
86
98
|
account.accessToken = data.access_token;
|
|
87
99
|
account.tokenExpires = now + data.expires_in * 1000 - 5 * 60 * 1000;
|
|
100
|
+
if (typeof data.scope === "string" && data.scope.trim()) {
|
|
101
|
+
account.tokenScopes = data.scope.trim().split(/\s+/).filter(Boolean);
|
|
102
|
+
}
|
|
88
103
|
account.consecutiveErrors = 0;
|
|
89
104
|
}
|
|
90
105
|
|
|
@@ -168,11 +183,114 @@ export const googleAntigravityAdapter: ProviderAdapter = {
|
|
|
168
183
|
},
|
|
169
184
|
createStreamAccumulator: createGoogleStreamAccumulator,
|
|
170
185
|
|
|
186
|
+
async forwardKickstartRequest(
|
|
187
|
+
account: AccountRuntime,
|
|
188
|
+
model: string,
|
|
189
|
+
signal?: AbortSignal,
|
|
190
|
+
) {
|
|
191
|
+
return forwardRequest(
|
|
192
|
+
account,
|
|
193
|
+
{
|
|
194
|
+
project: getProviderProjectId(account.config, DEFAULT_PROVIDER),
|
|
195
|
+
model,
|
|
196
|
+
request: {
|
|
197
|
+
contents: [{ role: "user", parts: [{ text: "." }] }],
|
|
198
|
+
generationConfig: { maxOutputTokens: 1 },
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
{},
|
|
202
|
+
signal,
|
|
203
|
+
{ apiRetry: false },
|
|
204
|
+
);
|
|
205
|
+
},
|
|
206
|
+
|
|
171
207
|
getKickstartModelForPool(quotaModelKey: string): string | undefined {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
208
|
+
const known = KICKSTART_MODEL_FOR_QUOTA_POOL[quotaModelKey];
|
|
209
|
+
if (known) return known;
|
|
210
|
+
const dynamicCandidates = dynamicCatalog
|
|
211
|
+
.getModelsForQuotaPool(quotaModelKey)
|
|
212
|
+
.filter((entry) => !entry.id.toLowerCase().endsWith("-disabled"));
|
|
213
|
+
if (dynamicCandidates.length > 0) {
|
|
214
|
+
const preferred = dynamicCandidates.find((entry) =>
|
|
215
|
+
/(?:^|-)(?:low|lite|flash|medium)$/i.test(entry.id),
|
|
216
|
+
);
|
|
217
|
+
return (preferred ?? dynamicCandidates[0]).id;
|
|
218
|
+
}
|
|
219
|
+
if (dynamicCatalog.hasQuotaPool(quotaModelKey)) return undefined;
|
|
220
|
+
return KICKSTART_MODEL_FOR_QUOTA_POOL[resolveQuotaModelKey(quotaModelKey) ?? ""];
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
getKickstartModelsForPool(
|
|
224
|
+
quotaModelKey: string,
|
|
225
|
+
account?: AccountRuntime,
|
|
226
|
+
): string[] {
|
|
227
|
+
const directPrimary = KICKSTART_MODEL_FOR_QUOTA_POOL[quotaModelKey];
|
|
228
|
+
const accountId = account ? getAccountIdentity(account) : undefined;
|
|
229
|
+
if (!directPrimary) {
|
|
230
|
+
const dynamicCandidates = dynamicCatalog
|
|
231
|
+
.getModelsForQuotaPool(quotaModelKey, accountId)
|
|
232
|
+
.filter((entry) => !entry.id.toLowerCase().endsWith("-disabled"));
|
|
233
|
+
if (dynamicCandidates.length > 0) {
|
|
234
|
+
const preferred = dynamicCandidates.filter((entry) =>
|
|
235
|
+
/(?:^|-)(?:low|lite|flash|medium)$/i.test(entry.id),
|
|
236
|
+
);
|
|
237
|
+
const rest = dynamicCandidates.filter(
|
|
238
|
+
(entry) => !/(?:^|-)(?:low|lite|flash|medium)$/i.test(entry.id),
|
|
239
|
+
);
|
|
240
|
+
return [...preferred, ...rest].map((entry) => entry.id);
|
|
241
|
+
}
|
|
242
|
+
if (
|
|
243
|
+
dynamicCatalog.hasQuotaPool(quotaModelKey, accountId) ||
|
|
244
|
+
account?.quota.some((q) => q.modelKey === quotaModelKey)
|
|
245
|
+
) {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const pool = directPrimary
|
|
250
|
+
? quotaModelKey
|
|
251
|
+
: resolveQuotaModelKey(quotaModelKey) ?? "";
|
|
252
|
+
const primary = KICKSTART_MODEL_FOR_QUOTA_POOL[pool];
|
|
253
|
+
if (!pool || !primary) return [];
|
|
254
|
+
|
|
255
|
+
const snapshot = account
|
|
256
|
+
? dynamicCatalog.getAccountSnapshot(
|
|
257
|
+
getAccountIdentity(account),
|
|
258
|
+
getCredentialGeneration(account.config, "google-antigravity"),
|
|
259
|
+
)
|
|
260
|
+
: undefined;
|
|
261
|
+
const snapshotSet = snapshot
|
|
262
|
+
? new Set(snapshot.models.map((model) => model.toLowerCase()))
|
|
263
|
+
: null;
|
|
264
|
+
|
|
265
|
+
const tier = account?.config.tier;
|
|
266
|
+
const isExplicitlyFree = tier === "free";
|
|
267
|
+
const isProOrHigher = isExplicitlyFree
|
|
268
|
+
? false
|
|
269
|
+
: tier === "pro" || tier === "ultra" || tier === "plus" ||
|
|
270
|
+
tier === "max" || tier === "team" || account?.config.type === "pro";
|
|
271
|
+
const snapshotHasSonnet55 = Boolean(
|
|
272
|
+
snapshotSet &&
|
|
273
|
+
(snapshotSet.has("claude-sonnet-5-5-low") ||
|
|
274
|
+
snapshotSet.has("claude-sonnet-5-5-medium")),
|
|
175
275
|
);
|
|
276
|
+
const useProOrder = pool === "claude" && !isExplicitlyFree &&
|
|
277
|
+
(isProOrHigher || snapshotHasSonnet55);
|
|
278
|
+
const preferred =
|
|
279
|
+
(useProOrder
|
|
280
|
+
? KICKSTART_PRO_MODELS_FOR_QUOTA_POOL[pool]
|
|
281
|
+
: KICKSTART_FALLBACK_MODELS_FOR_QUOTA_POOL[pool]) ?? [primary];
|
|
282
|
+
|
|
283
|
+
if (snapshotSet) {
|
|
284
|
+
const inSnapshot = preferred.filter((model) =>
|
|
285
|
+
snapshotSet.has(model.toLowerCase()),
|
|
286
|
+
);
|
|
287
|
+
if (inSnapshot.length > 0) return inSnapshot;
|
|
288
|
+
return [primary];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Without a per-account catalog, preserve only the existing primary.
|
|
292
|
+
if (pool === "gemini") return [primary];
|
|
293
|
+
return [...preferred];
|
|
176
294
|
},
|
|
177
295
|
|
|
178
296
|
listModels(): ProviderModel[] {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ANTIGRAVITY_CLIENT_METADATA,
|
|
4
|
+
CLIENT_ID,
|
|
5
|
+
CLIENT_SECRET,
|
|
6
|
+
REQUEST_USER_AGENT,
|
|
7
|
+
TOKEN_URL,
|
|
8
|
+
} from "../../types.js";
|
|
3
9
|
import { fetchWithRetry } from "../../fetch-with-retry.js";
|
|
4
10
|
|
|
5
11
|
export const DEFAULT_REDIRECT_URI = "http://localhost:51121/oauth-callback";
|
|
@@ -9,6 +15,7 @@ export const SCOPES = [
|
|
|
9
15
|
"https://www.googleapis.com/auth/userinfo.profile",
|
|
10
16
|
"https://www.googleapis.com/auth/cclog",
|
|
11
17
|
"https://www.googleapis.com/auth/experimentsandconfigs",
|
|
18
|
+
"https://www.googleapis.com/auth/aicode",
|
|
12
19
|
];
|
|
13
20
|
export const AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
14
21
|
|
|
@@ -112,7 +119,10 @@ export async function exchangeAuthorizationCode(code: string, verifier: string):
|
|
|
112
119
|
const oauth = getOAuthClientConfig();
|
|
113
120
|
const tokenResponse = await fetchWithRetry(TOKEN_URL, {
|
|
114
121
|
method: "POST",
|
|
115
|
-
headers: {
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
124
|
+
"User-Agent": REQUEST_USER_AGENT,
|
|
125
|
+
},
|
|
116
126
|
body: new URLSearchParams({
|
|
117
127
|
client_id: oauth.clientId,
|
|
118
128
|
client_secret: oauth.clientSecret,
|
|
@@ -217,17 +227,12 @@ async function onboardUser(accessToken: string, tierId: string): Promise<string
|
|
|
217
227
|
const headers: Record<string, string> = {
|
|
218
228
|
Authorization: `Bearer ${accessToken}`,
|
|
219
229
|
"Content-Type": "application/json",
|
|
220
|
-
"User-Agent":
|
|
221
|
-
"X-Goog-Api-Client": "gl-node/22.21.1",
|
|
230
|
+
"User-Agent": REQUEST_USER_AGENT,
|
|
222
231
|
};
|
|
223
232
|
|
|
224
233
|
const body = JSON.stringify({
|
|
225
|
-
|
|
226
|
-
metadata:
|
|
227
|
-
ide_type: "ANTIGRAVITY",
|
|
228
|
-
ide_version: ANTIGRAVITY_VERSION,
|
|
229
|
-
ide_name: "antigravity",
|
|
230
|
-
},
|
|
234
|
+
tierId,
|
|
235
|
+
metadata: ANTIGRAVITY_CLIENT_METADATA,
|
|
231
236
|
});
|
|
232
237
|
|
|
233
238
|
for (let attempt = 0; attempt < ONBOARD_MAX_POLLS; attempt++) {
|
|
@@ -237,6 +242,7 @@ async function onboardUser(accessToken: string, tierId: string): Promise<string
|
|
|
237
242
|
method: "POST",
|
|
238
243
|
headers,
|
|
239
244
|
body,
|
|
245
|
+
retryPolicy: "antigravity",
|
|
240
246
|
});
|
|
241
247
|
if (!response.ok) return null;
|
|
242
248
|
const data = (await response.json()) as Record<string, unknown> | null;
|
|
@@ -270,8 +276,9 @@ export async function discoverProject(accessToken: string): Promise<ProjectDisco
|
|
|
270
276
|
method: "POST",
|
|
271
277
|
headers,
|
|
272
278
|
body: JSON.stringify({
|
|
273
|
-
metadata:
|
|
279
|
+
metadata: ANTIGRAVITY_CLIENT_METADATA,
|
|
274
280
|
}),
|
|
281
|
+
retryPolicy: "antigravity",
|
|
275
282
|
});
|
|
276
283
|
|
|
277
284
|
if (response.ok) {
|
|
@@ -301,7 +308,10 @@ export async function discoverProject(accessToken: string): Promise<ProjectDisco
|
|
|
301
308
|
export async function getUserEmail(accessToken: string): Promise<string | undefined> {
|
|
302
309
|
try {
|
|
303
310
|
const response = await fetchWithRetry("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", {
|
|
304
|
-
headers: {
|
|
311
|
+
headers: {
|
|
312
|
+
Authorization: `Bearer ${accessToken}`,
|
|
313
|
+
"User-Agent": REQUEST_USER_AGENT,
|
|
314
|
+
},
|
|
305
315
|
});
|
|
306
316
|
if (response.ok) {
|
|
307
317
|
const data = (await response.json()) as { email?: string };
|