tuxevil-rotator 4.4.9 → 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.
Files changed (57) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +2 -1
  3. package/package.json +1 -1
  4. package/src/access-probe.ts +1 -1
  5. package/src/account-store.ts +14 -2
  6. package/src/audio-transcription.ts +1 -0
  7. package/src/auto-model-access.ts +22 -0
  8. package/src/compat/model-specs.ts +7 -0
  9. package/src/compat/schema-sanitizer.ts +420 -287
  10. package/src/compat.ts +110 -66
  11. package/src/config-defaults.ts +7 -0
  12. package/src/fetch-with-retry.ts +294 -16
  13. package/src/idempotency.ts +3 -1
  14. package/src/model-access-api.ts +9 -1
  15. package/src/model-access.ts +2 -2
  16. package/src/notification-poller.ts +9 -1
  17. package/src/provider-catalog-evidence.ts +18 -1
  18. package/src/providers/adapter.ts +5 -0
  19. package/src/providers/credential-helpers.ts +34 -0
  20. package/src/providers/google-antigravity/aicode-eligibility.ts +256 -0
  21. package/src/providers/google-antigravity/aicode-forward.ts +381 -0
  22. package/src/providers/google-antigravity/aicode.ts +478 -0
  23. package/src/providers/google-antigravity/catalog.ts +6 -0
  24. package/src/providers/google-antigravity/code-assist.ts +53 -41
  25. package/src/providers/google-antigravity/dynamic-catalog.ts +72 -7
  26. package/src/providers/google-antigravity/forward.ts +309 -86
  27. package/src/providers/google-antigravity/index.ts +67 -6
  28. package/src/providers/google-antigravity/oauth.ts +22 -12
  29. package/src/providers/google-antigravity/quota.ts +781 -34
  30. package/src/providers/google-antigravity/translators.ts +55 -46
  31. package/src/providers/google-antigravity/twin-payload.ts +231 -0
  32. package/src/providers/ollama/quota.ts +6 -4
  33. package/src/providers/openai-codex/compat.ts +11 -2
  34. package/src/providers/openai-codex/quota.ts +2 -1
  35. package/src/providers/opencode-zen/catalog.ts +159 -13
  36. package/src/providers/opencode-zen/discovery.ts +50 -0
  37. package/src/providers/opencode-zen/index.ts +7 -2
  38. package/src/providers/opencode-zen/quota.ts +14 -1
  39. package/src/proxy.ts +570 -87
  40. package/src/quota-pools.ts +76 -1
  41. package/src/rate-limit-parser.ts +239 -19
  42. package/src/rotator.ts +602 -138
  43. package/src/stream-guards.ts +87 -1
  44. package/src/telemetry.ts +17 -3
  45. package/src/types.ts +168 -9
  46. package/src/validators.ts +3 -0
  47. package/src/web/lib/accounts.ts +2 -0
  48. package/src/web/lib/attention.ts +19 -0
  49. package/src/web/lib/models.ts +6 -1
  50. package/src/web/lib/status.ts +22 -4
  51. package/src/web/pages/AccountDetail.tsx +49 -2
  52. package/src/web/pages/Accounts.tsx +38 -3
  53. package/src/web/pages/ModelAccess.tsx +4 -0
  54. package/src/web/pages/Models.tsx +2 -1
  55. package/src/web/pages/Overview.tsx +15 -1
  56. package/src/web/styles/app.css +73 -3
  57. package/tools/telemetry-receiver/receiver.js +444 -243
@@ -36,6 +36,7 @@ import {
36
36
  KICKSTART_MODEL_FOR_QUOTA_POOL,
37
37
  KICKSTART_FALLBACK_MODELS_FOR_QUOTA_POOL,
38
38
  KICKSTART_PRO_MODELS_FOR_QUOTA_POOL,
39
+ REQUEST_USER_AGENT,
39
40
  applyModelAlias,
40
41
  resolveQuotaModelKey,
41
42
  } from "../../types.js";
@@ -46,6 +47,7 @@ import {
46
47
  } from "../../account-identity.js";
47
48
  import { fetchWithRetry } from "../../fetch-with-retry.js";
48
49
  import { logger } from "../../logger.js";
50
+ import { DEFAULT_PROVIDER, getProviderProjectId } from "../credential-helpers.js";
49
51
  import { getAccountProxyDispatcher } from "../proxy-dispatcher.js";
50
52
 
51
53
  const providerLog = logger.child("provider/google");
@@ -72,7 +74,10 @@ async function ensureGoogleToken(account: AccountRuntime): Promise<void> {
72
74
  const oauth = getOAuthClientConfig();
73
75
  const response = await fetchWithRetry(TOKEN_URL, {
74
76
  method: "POST",
75
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
77
+ headers: {
78
+ "Content-Type": "application/x-www-form-urlencoded",
79
+ "User-Agent": REQUEST_USER_AGENT,
80
+ },
76
81
  body: new URLSearchParams({
77
82
  client_id: oauth.clientId,
78
83
  client_secret: oauth.clientSecret,
@@ -88,9 +93,13 @@ async function ensureGoogleToken(account: AccountRuntime): Promise<void> {
88
93
  const data = (await response.json()) as {
89
94
  access_token: string;
90
95
  expires_in: number;
96
+ scope?: string;
91
97
  };
92
98
  account.accessToken = data.access_token;
93
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
+ }
94
103
  account.consecutiveErrors = 0;
95
104
  }
96
105
 
@@ -174,18 +183,70 @@ export const googleAntigravityAdapter: ProviderAdapter = {
174
183
  },
175
184
  createStreamAccumulator: createGoogleStreamAccumulator,
176
185
 
177
- getKickstartModelForPool(quotaModelKey: string): string | undefined {
178
- return (
179
- KICKSTART_MODEL_FOR_QUOTA_POOL[quotaModelKey] ??
180
- KICKSTART_MODEL_FOR_QUOTA_POOL[resolveQuotaModelKey(quotaModelKey) ?? ""]
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 },
181
204
  );
182
205
  },
183
206
 
207
+ getKickstartModelForPool(quotaModelKey: string): string | undefined {
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
+
184
223
  getKickstartModelsForPool(
185
224
  quotaModelKey: string,
186
225
  account?: AccountRuntime,
187
226
  ): string[] {
188
- const pool = KICKSTART_MODEL_FOR_QUOTA_POOL[quotaModelKey]
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
189
250
  ? quotaModelKey
190
251
  : resolveQuotaModelKey(quotaModelKey) ?? "";
191
252
  const primary = KICKSTART_MODEL_FOR_QUOTA_POOL[pool];
@@ -1,5 +1,11 @@
1
1
  import { createHash, randomBytes } from "node:crypto";
2
- import { ANTIGRAVITY_VERSION, CLIENT_ID, CLIENT_SECRET, REQUEST_USER_AGENT, TOKEN_URL } from "../../types.js";
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: { "Content-Type": "application/x-www-form-urlencoded" },
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": `${REQUEST_USER_AGENT} google-api-nodejs-client/10.3.0`,
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
- tier_id: tierId,
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: { ideType: "ANTIGRAVITY" },
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: { Authorization: `Bearer ${accessToken}` },
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 };