tuxevil-rotator 4.2.1 → 4.2.2

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.
@@ -4,7 +4,13 @@ import { resolve, dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
6
6
  const __dirname = dirname(fileURLToPath(import.meta.url));
7
- const PLUGIN_SOURCE_PATH = resolve(__dirname, "../plugins/opencode-discovery.js");
7
+ const PLUGIN_SOURCE_DIR = resolve(__dirname, "../plugins/opencode-discovery");
8
+
9
+ /**
10
+ * Files shipped from the repo plugin directory to the target machine.
11
+ * Keep in sync with plugins/opencode-discovery/.
12
+ */
13
+ const PLUGIN_RUNTIME_SOURCE_FILES = ["index.mjs", "package.json"];
8
14
 
9
15
  export interface InstallOptions {
10
16
  host?: string;
@@ -19,11 +25,93 @@ export interface InstallOptions {
19
25
  dryRun?: boolean;
20
26
  }
21
27
 
28
+ export interface DiscoveryConfigInput {
29
+ pluginDir: string;
30
+ providerID: string;
31
+ providerName: string;
32
+ baseURL: string;
33
+ apiKey?: string;
34
+ }
35
+
36
+ /**
37
+ * Pure config mutation shared in spirit with the self-contained node script
38
+ * embedded in buildRemoteInstallerScript (which runs on hosts without this TS
39
+ * module, so it carries its own copy — keep both in sync).
40
+ *
41
+ * Config form written for OpenCode 2.x:
42
+ * "plugins": [{ "package": pluginDir, "options": {...} }]
43
+ *
44
+ * Legacy cleanup: discovery entries are scrubbed from both the V2 "plugins"
45
+ * list and the legacy "plugin" key; other legacy entries are left untouched
46
+ * (OpenCode migrates them on its own).
47
+ */
48
+ export function applyDiscoveryPluginConfig(
49
+ config: Record<string, unknown>,
50
+ { pluginDir, providerID, providerName, baseURL, apiKey }: DiscoveryConfigInput
51
+ ): Record<string, unknown> {
52
+ const isDiscoveryEntry = (entry: unknown): boolean => {
53
+ if (typeof entry === "string") return entry.includes("opencode-discovery");
54
+ if (Array.isArray(entry)) {
55
+ return typeof entry[0] === "string" && entry[0].includes("opencode-discovery");
56
+ }
57
+ if (entry && typeof entry === "object") {
58
+ const pkg = (entry as { package?: unknown }).package;
59
+ return typeof pkg === "string" && pkg.includes("opencode-discovery");
60
+ }
61
+ return false;
62
+ };
63
+
64
+ config.plugins = Array.isArray(config.plugins)
65
+ ? (config.plugins as unknown[]).filter((entry) => !isDiscoveryEntry(entry))
66
+ : [];
67
+
68
+ if (Array.isArray(config.plugin)) {
69
+ const kept = (config.plugin as unknown[]).filter((entry) => !isDiscoveryEntry(entry));
70
+ if (kept.length > 0) {
71
+ config.plugin = kept;
72
+ } else {
73
+ delete config.plugin;
74
+ }
75
+ }
76
+
77
+ (config.plugins as unknown[]).push({
78
+ package: pluginDir,
79
+ options: { baseURL, providerID, providerName },
80
+ });
81
+
82
+ if (!config.$schema) {
83
+ config.$schema = "https://opencode.ai/config.json";
84
+ }
85
+
86
+ if (!config.provider) {
87
+ config.provider = {};
88
+ }
89
+ const provider = config.provider as Record<string, Record<string, unknown>>;
90
+ const existing = provider[providerID] ?? {};
91
+
92
+ provider[providerID] = {
93
+ ...(existing as object),
94
+ npm: "@ai-sdk/openai-compatible",
95
+ name: providerName,
96
+ options: {
97
+ ...((existing.options as object) ?? {}),
98
+ baseURL,
99
+ ...(apiKey && apiKey !== "no-key" ? { apiKey } : {}),
100
+ },
101
+ };
102
+
103
+ if (!config.model) {
104
+ config.model = `${providerID}/gemini-3.8-flash-high`;
105
+ }
106
+
107
+ return config;
108
+ }
109
+
22
110
  /**
23
111
  * Builds the remote installation script that will execute on the target machine.
24
112
  */
25
113
  export function buildRemoteInstallerScript(
26
- pluginContent: string,
114
+ pluginFiles: Record<string, string>,
27
115
  options: {
28
116
  rotatorUrl: string;
29
117
  providerId: string;
@@ -32,32 +120,40 @@ export function buildRemoteInstallerScript(
32
120
  targetDir?: string;
33
121
  }
34
122
  ): string {
35
- const pluginContentBase64 = Buffer.from(pluginContent, "utf8").toString("base64");
123
+ if (!(PLUGIN_RUNTIME_SOURCE_FILES.every((name) => name in pluginFiles))) {
124
+ throw new Error(`pluginFiles must include all of: ${PLUGIN_RUNTIME_SOURCE_FILES.join(", ")}`);
125
+ }
126
+
36
127
  const targetDir = options.targetDir || "~/.config/opencode";
37
128
  const providerId = options.providerId || "antigravity";
38
129
  const providerName = options.providerName || "Antigravity (rotator)";
39
130
  const rotatorUrl = options.rotatorUrl;
40
131
  const apiKey = options.apiKey;
41
132
 
133
+ const fileWriteLines = PLUGIN_RUNTIME_SOURCE_FILES.map((name) => {
134
+ const base64 = Buffer.from(pluginFiles[name], "utf8").toString("base64");
135
+ return `echo "${base64}" | base64 -d > "$PLUGIN_DIR/${name}"`;
136
+ }).join("\n");
137
+
42
138
  return `
43
139
  set -e
44
140
  TARGET_DIR="${targetDir}"
45
141
  eval TARGET_DIR="$TARGET_DIR"
46
142
 
47
- mkdir -p "$TARGET_DIR/plugins"
48
- PLUGIN_FILE="$TARGET_DIR/plugins/opencode-discovery.js"
143
+ mkdir -p "$TARGET_DIR/plugins/opencode-discovery"
144
+ PLUGIN_DIR="$TARGET_DIR/plugins/opencode-discovery"
49
145
  CONFIG_FILE="$TARGET_DIR/opencode.json"
50
146
 
51
- echo "==> Writing plugin to $PLUGIN_FILE..."
52
- echo "${pluginContentBase64}" | base64 -d > "$PLUGIN_FILE"
147
+ echo "==> Writing plugin to $PLUGIN_DIR/index.mjs..."
148
+ ${fileWriteLines}
53
149
 
54
- # Prepare node script to cleanly mutate or create opencode.json
150
+ # Prepare node script to cleanly mutate or create opencode.json (OpenCode 2.x form)
55
151
  node -e '
56
152
  const fs = require("fs");
57
153
  const path = require("path");
58
154
 
59
155
  const configFile = process.argv[1];
60
- const pluginPath = process.argv[2];
156
+ const pluginDir = process.argv[2];
61
157
  const providerID = process.argv[3];
62
158
  const providerName = process.argv[4];
63
159
  const baseURL = process.argv[5];
@@ -66,8 +162,7 @@ const apiKey = process.argv[6];
66
162
  let config = {};
67
163
  if (fs.existsSync(configFile)) {
68
164
  try {
69
- const raw = fs.readFileSync(configFile, "utf8");
70
- config = JSON.parse(raw);
165
+ config = JSON.parse(fs.readFileSync(configFile, "utf8"));
71
166
  } catch (err) {
72
167
  console.error("Warning: parsing existing " + configFile + " failed, backing up to .bak");
73
168
  fs.copyFileSync(configFile, configFile + ".bak." + Date.now());
@@ -78,26 +173,33 @@ if (!config.$schema) {
78
173
  config.$schema = "https://opencode.ai/config.json";
79
174
  }
80
175
 
81
- if (!Array.isArray(config.plugin)) {
82
- config.plugin = [];
83
- }
176
+ const isDiscoveryEntry = (entry) => {
177
+ if (typeof entry === "string") return entry.includes("opencode-discovery");
178
+ if (Array.isArray(entry)) {
179
+ return typeof entry[0] === "string" && entry[0].includes("opencode-discovery");
180
+ }
181
+ if (entry && typeof entry === "object") {
182
+ return typeof entry.package === "string" && entry.package.includes("opencode-discovery");
183
+ }
184
+ return false;
185
+ };
84
186
 
85
- // Remove any prior entry of opencode-discovery
86
- config.plugin = config.plugin.filter(p => {
87
- if (typeof p === "string") return !p.includes("opencode-discovery.js");
88
- if (Array.isArray(p)) return !p[0].includes("opencode-discovery.js");
89
- return true;
187
+ // V2 plugin list: scrub prior discovery entries, then register the directory
188
+ config.plugins = Array.isArray(config.plugins) ? config.plugins.filter(p => !isDiscoveryEntry(p)) : [];
189
+ config.plugins.push({
190
+ package: pluginDir,
191
+ options: { baseURL, providerID, providerName }
90
192
  });
91
193
 
92
- // Add plugin tuple with options
93
- config.plugin.push([
94
- pluginPath,
95
- {
96
- baseURL: baseURL,
97
- providerID: providerID,
98
- providerName: providerName
194
+ // Legacy V1 key: scrub discovery entries, keep everything else untouched
195
+ if (Array.isArray(config.plugin)) {
196
+ const kept = config.plugin.filter(p => !isDiscoveryEntry(p));
197
+ if (kept.length > 0) {
198
+ config.plugin = kept;
199
+ } else {
200
+ delete config.plugin;
99
201
  }
100
- ]);
202
+ }
101
203
 
102
204
  if (!config.provider) {
103
205
  config.provider = {};
@@ -128,7 +230,7 @@ if (!config.model) {
128
230
 
129
231
  fs.writeFileSync(configFile, JSON.stringify(config, null, 2) + "\\n", "utf8");
130
232
  console.log("==> Successfully updated " + configFile);
131
- ' "$CONFIG_FILE" "$PLUGIN_FILE" "${providerId}" "${providerName}" "${rotatorUrl}" "${apiKey || ""}"
233
+ ' "$CONFIG_FILE" "$PLUGIN_DIR" "${providerId}" "${providerName}" "${rotatorUrl}" "${apiKey || ""}"
132
234
 
133
235
  echo "==> Installation complete! OpenCode is now configured to discover models from ${rotatorUrl}"
134
236
  `;
@@ -138,16 +240,20 @@ echo "==> Installation complete! OpenCode is now configured to discover models f
138
240
  * Installs the discovery plugin either locally or remotely via SSH.
139
241
  */
140
242
  export async function installOpenCodePlugin(options: InstallOptions): Promise<void> {
141
- if (!existsSync(PLUGIN_SOURCE_PATH)) {
142
- throw new Error(`Plugin file not found at ${PLUGIN_SOURCE_PATH}`);
243
+ const pluginFiles: Record<string, string> = {};
244
+ for (const name of PLUGIN_RUNTIME_SOURCE_FILES) {
245
+ const filePath = resolve(PLUGIN_SOURCE_DIR, name);
246
+ if (!existsSync(filePath)) {
247
+ throw new Error(`Plugin directory ${PLUGIN_SOURCE_DIR} does not contain ${name}`);
248
+ }
249
+ pluginFiles[name] = readFileSync(filePath, "utf8");
143
250
  }
144
251
 
145
- const pluginContent = readFileSync(PLUGIN_SOURCE_PATH, "utf8");
146
252
  const rotatorUrl = (options.rotatorUrl || process.env.TUXEVIL_ROTATOR_BASE_URL || "http://127.0.0.1:51200/v1").replace(/\/+$/, "");
147
253
  const providerId = options.providerId || "antigravity";
148
254
  const providerName = options.providerName || "Antigravity (rotator)";
149
255
 
150
- const script = buildRemoteInstallerScript(pluginContent, {
256
+ const script = buildRemoteInstallerScript(pluginFiles, {
151
257
  rotatorUrl,
152
258
  providerId,
153
259
  providerName,
@@ -11,6 +11,7 @@
11
11
 
12
12
  import { dynamicCatalog } from "./dynamic-catalog.js";
13
13
  import { getModelSpec, getModelSpecOverride } from "../../compat/model-specs.js";
14
+ import { applyModelAlias } from "../../types.js";
14
15
 
15
16
  export interface AntigravityModelSpec {
16
17
  id: string;
@@ -107,145 +108,6 @@ export function getAntigravityContextWindow(model: string): number {
107
108
  return FALLBACK_CONTEXT_WINDOW;
108
109
  }
109
110
 
110
- // Static Antigravity models every install lists, before dynamic discovery adds
111
- // the models each account reports.
112
- const MODEL_CATALOG = [
113
- {
114
- id: "gemini-3-flash",
115
- family: "gemini-3-flash",
116
- ctx: 1048576,
117
- quotaPool: "gemini",
118
- multimodal: true,
119
- tools: true,
120
- },
121
- {
122
- id: "gemini-3.6-flash-high",
123
- family: "gemini-3.6-flash",
124
- ctx: 1048576,
125
- quotaPool: "gemini",
126
- multimodal: true,
127
- tools: true,
128
- },
129
- {
130
- id: "gemini-3.6-flash-medium",
131
- family: "gemini-3.6-flash",
132
- ctx: 1048576,
133
- quotaPool: "gemini",
134
- multimodal: true,
135
- tools: true,
136
- },
137
- {
138
- id: "gemini-3.6-flash-low",
139
- family: "gemini-3.6-flash",
140
- ctx: 1048576,
141
- quotaPool: "gemini",
142
- multimodal: true,
143
- tools: true,
144
- },
145
- {
146
- id: "gemini-3.6-flash-tiered",
147
- family: "gemini-3.6-flash",
148
- ctx: 1048576,
149
- quotaPool: "gemini",
150
- multimodal: true,
151
- tools: true,
152
- },
153
- {
154
- id: "gemini-3.7-flash-tiered",
155
- family: "gemini-3.7-flash",
156
- ctx: 1048576,
157
- quotaPool: "gemini",
158
- multimodal: true,
159
- tools: true,
160
- },
161
- {
162
- id: "gemini-3.8-flash-high",
163
- family: "gemini-3.8-flash",
164
- ctx: 1048576,
165
- quotaPool: "gemini",
166
- multimodal: true,
167
- tools: true,
168
- },
169
- {
170
- id: "gemini-3.8-flash-medium",
171
- family: "gemini-3.8-flash",
172
- ctx: 1048576,
173
- quotaPool: "gemini",
174
- multimodal: true,
175
- tools: true,
176
- },
177
- {
178
- id: "gemini-3.8-flash-low",
179
- family: "gemini-3.8-flash",
180
- ctx: 1048576,
181
- quotaPool: "gemini",
182
- multimodal: true,
183
- tools: true,
184
- },
185
- {
186
- id: "gemini-3.1-pro-low",
187
- family: "gemini-3.1-pro",
188
- ctx: 1048576,
189
- quotaPool: "gemini",
190
- multimodal: true,
191
- tools: true,
192
- },
193
- {
194
- id: "gemini-3.1-pro-high",
195
- family: "gemini-3.1-pro",
196
- ctx: 1048576,
197
- quotaPool: "gemini",
198
- multimodal: true,
199
- tools: true,
200
- },
201
- {
202
- id: "claude-sonnet-4-6",
203
- family: "claude",
204
- ctx: 1000000,
205
- quotaPool: "claude",
206
- multimodal: true,
207
- tools: true,
208
- },
209
- {
210
- id: "claude-opus-4-6-thinking",
211
- family: "claude",
212
- ctx: 1000000,
213
- quotaPool: "claude",
214
- multimodal: true,
215
- tools: true,
216
- },
217
- {
218
- id: "gpt-oss-120b-medium",
219
- family: "gpt-oss",
220
- ctx: 131072,
221
- quotaPool: "claude",
222
- multimodal: false,
223
- tools: true,
224
- },
225
- {
226
- id: "gemini-3.5-flash-lite",
227
- family: "gemini-3.5-flash",
228
- ctx: 1048576,
229
- quotaPool: "gemini",
230
- multimodal: true,
231
- tools: true,
232
- },
233
- {
234
- id: "whisper-1",
235
- family: "gemini-3.8-flash",
236
- ctx: 1048576,
237
- quotaPool: "gemini",
238
- multimodal: true,
239
- tools: false,
240
- },
241
- ] as const;
242
-
243
- /** Whether the rotator ships this id, as opposed to an account reporting it. */
244
- export function isBuiltInAntigravityModel(model: string): boolean {
245
- const wanted = model.trim().toLowerCase();
246
- return MODEL_CATALOG.some((entry) => entry.id.toLowerCase() === wanted);
247
- }
248
-
249
111
  export interface CompatModelEntry {
250
112
  id: string;
251
113
  family: string;
@@ -261,37 +123,46 @@ export interface CompatModelEntry {
261
123
 
262
124
  export function getEffectiveAntigravityModels(): CompatModelEntry[] {
263
125
  const dynamic = dynamicCatalog.getAllModels();
264
- const seen = new Set(MODEL_CATALOG.map((model) => model.id.toLowerCase()));
265
- const result: CompatModelEntry[] = MODEL_CATALOG.map((model) => {
126
+ const byId = new Map(dynamic.map((model) => [model.id.toLowerCase(), model]));
127
+ const toCompatModel = (
128
+ model: (typeof dynamic)[number],
129
+ id = model.id,
130
+ tools = model.tools,
131
+ ): CompatModelEntry => {
266
132
  const spec = getModelSpec(model.id);
267
- const contextWindow = getModelSpecOverride(model.id)?.contextWindow ??
268
- dynamicCatalog.getModelSpec(model.id)?.contextWindow;
269
133
  return {
270
- ...model,
271
- ctx: contextWindow ?? model.ctx,
134
+ id,
135
+ family: model.family,
136
+ ctx: spec.contextWindow ?? model.ctx,
137
+ quotaPool: model.quotaPool,
138
+ multimodal: model.multimodal,
139
+ tools,
272
140
  maxOutputTokens: spec.maxOutputTokens,
273
141
  thinkingBudget: spec.thinkingBudget,
274
142
  minThinkingBudget: spec.minThinkingBudget,
275
143
  isThinking: spec.isThinking,
276
144
  };
277
- });
278
- for (const m of dynamic) {
279
- if (seen.has(m.id.toLowerCase())) continue;
280
- seen.add(m.id.toLowerCase());
281
- const spec = getModelSpec(m.id);
282
- result.push({
283
- id: m.id,
284
- family: m.family,
285
- ctx: spec.contextWindow ?? m.ctx,
286
- quotaPool: m.quotaPool,
287
- multimodal: m.multimodal,
288
- tools: m.tools,
289
- maxOutputTokens: spec.maxOutputTokens,
290
- thinkingBudget: spec.thinkingBudget,
291
- minThinkingBudget: spec.minThinkingBudget,
292
- isThinking: spec.isThinking,
293
- });
294
- }
145
+ };
146
+ const result = dynamic.map((model) => toCompatModel(model));
295
147
 
148
+ // Keep the OpenAI audio compatibility name only while its configured target
149
+ // appears in a current Antigravity account snapshot.
150
+ if (!byId.has("whisper-1")) {
151
+ const target = applyModelAlias("whisper-1")
152
+ .trim()
153
+ .replace(/^models\//i, "")
154
+ .toLowerCase();
155
+ const backingModel = byId.get(target);
156
+ if (backingModel) result.push(toCompatModel(backingModel, "whisper-1", false));
157
+ }
296
158
  return result;
297
159
  }
160
+
161
+ /** Whether an id or configured operator alias resolves to a current snapshot model. */
162
+ export function isDynamicallyAvailableAntigravityModel(model: string): boolean {
163
+ const normalize = (value: string) => value.trim().replace(/^models\//i, "").toLowerCase();
164
+ return Boolean(
165
+ dynamicCatalog.getModel(normalize(model)) ??
166
+ dynamicCatalog.getModel(normalize(applyModelAlias(model))),
167
+ );
168
+ }
@@ -285,13 +285,6 @@ export class DynamicModelRegistry {
285
285
  );
286
286
  let newModelsCount = 0;
287
287
 
288
- if (data.defaultAgentModelId) {
289
- this.defaultAgentModelIds.delete(key);
290
- this.defaultAgentModelIds.set(key, data.defaultAgentModelId);
291
- } else {
292
- this.defaultAgentModelIds.delete(key);
293
- }
294
-
295
288
  for (const [rawId, info] of Object.entries(data.models)) {
296
289
  const normalizedId = rawId.trim();
297
290
  const lowerId = normalizedId.toLowerCase();
@@ -356,6 +349,34 @@ export class DynamicModelRegistry {
356
349
  if (!knownBefore.has(lowerId)) newModelsCount++;
357
350
  }
358
351
 
352
+ const reportedIds = Object.keys(data.models);
353
+ const hasUsableQuotaData = reportedIds.some((id) =>
354
+ Object.keys(data.models[id]?.quotaInfo ?? {}).length > 0,
355
+ );
356
+ if (
357
+ reportedIds.length > 0 &&
358
+ next.size === 0 &&
359
+ !hasUsableQuotaData &&
360
+ reportedIds.every((id) => {
361
+ const lower = id.toLowerCase();
362
+ return RESERVED_QUOTA_MODEL_IDS.has(lower) ||
363
+ lower.startsWith("chat_") ||
364
+ lower.startsWith("tab_");
365
+ })
366
+ ) {
367
+ // Quota-family rows without usable quota values are not a fresh model
368
+ // snapshot. Keep the last model list instead of clearing it on a
369
+ // response whose only model-like key was malformed quota data.
370
+ return 0;
371
+ }
372
+
373
+ if (data.defaultAgentModelId) {
374
+ this.defaultAgentModelIds.delete(key);
375
+ this.defaultAgentModelIds.set(key, data.defaultAgentModelId);
376
+ } else {
377
+ this.defaultAgentModelIds.delete(key);
378
+ }
379
+
359
380
  this.accountModels.set(key, next);
360
381
  this.accountModelOwnership.set(key, new Set(next.keys()));
361
382
  return newModelsCount;
@@ -10,7 +10,11 @@ import type {
10
10
  ProviderModel,
11
11
  QuotaFetchContext,
12
12
  } from "../adapter.js";
13
- import { getEffectiveAntigravityModels, isBuiltInAntigravityModel } from "./catalog.js";
13
+ import {
14
+ getEffectiveAntigravityModels,
15
+ isDynamicallyAvailableAntigravityModel,
16
+ } from "./catalog.js";
17
+ import { dynamicCatalog } from "./dynamic-catalog.js";
14
18
  import { fetchProviderQuota } from "./quota.js";
15
19
  import {
16
20
  forwardRequest,
@@ -30,6 +34,7 @@ import {
30
34
  import {
31
35
  TOKEN_URL,
32
36
  KICKSTART_MODEL_FOR_QUOTA_POOL,
37
+ applyModelAlias,
33
38
  resolveQuotaModelKey,
34
39
  } from "../../types.js";
35
40
  import type { AccountRuntime } from "../../types.js";
@@ -175,16 +180,19 @@ export const googleAntigravityAdapter: ProviderAdapter = {
175
180
  id: model.id,
176
181
  contextWindow: model.ctx,
177
182
  quotaPool: model.quotaPool,
178
- source: isBuiltInAntigravityModel(model.id) ? "catalog" : "discovered",
183
+ source: "discovered",
179
184
  }));
180
185
  },
181
186
 
182
187
  ownsModel(model: string): boolean {
183
- return resolveQuotaModelKey(model) !== null || model.includes("gemini") || model.includes("claude");
188
+ return isDynamicallyAvailableAntigravityModel(model);
184
189
  },
185
190
 
186
191
  getPoolKey(model: string): string {
187
- return resolveQuotaModelKey(model) ?? model;
192
+ const normalize = (value: string) => value.trim().replace(/^models\//i, "");
193
+ const observed = dynamicCatalog.getModel(normalize(model)) ??
194
+ dynamicCatalog.getModel(normalize(applyModelAlias(model)));
195
+ return observed?.id ?? resolveQuotaModelKey(model) ?? model;
188
196
  },
189
197
 
190
198
  getBenchmark(account: AccountRuntime) {
@@ -104,16 +104,14 @@ export function extractQuotas(
104
104
 
105
105
  for (const [, config] of Object.entries(QUOTA_MODEL_KEYS)) {
106
106
  const candidates: GoogleModelInfoWithQuota[] = [];
107
- for (const candidate of [config.key, ...config.altKeys]) {
108
- const info = data.models[candidate];
109
- if (hasUsableQuotaInfo(info)) {
110
- candidates.push(info);
111
- }
107
+ const sharedPoolInfo = data.models[config.key];
108
+ if (hasUsableQuotaInfo(sharedPoolInfo)) {
109
+ candidates.push(sharedPoolInfo);
112
110
  }
113
111
 
114
112
  for (const [modelKey, info] of Object.entries(data.models)) {
115
113
  if (
116
- ![config.key, ...config.altKeys].includes(modelKey) &&
114
+ modelKey !== config.key &&
117
115
  DynamicModelRegistry.inferFamilyAndPool(modelKey).quotaPool === config.key &&
118
116
  hasUsableQuotaInfo(info)
119
117
  ) {
@@ -236,7 +234,6 @@ export async function fetchProviderQuota(
236
234
  if (!data) return;
237
235
  const oldQuota = account.quota || [];
238
236
  const fresh = extractQuotas(data, oldQuota);
239
- if (fresh.length === 0) return;
240
237
  const newModels = dynamicCatalog.updateFromEndpointResponse(
241
238
  data,
242
239
  accountId,
@@ -248,6 +245,7 @@ export async function fetchProviderQuota(
248
245
  `${account.config.email}: discovered ${newModels} Antigravity model(s) from quota response`,
249
246
  );
250
247
  }
248
+ if (fresh.length === 0) return;
251
249
  // Drop the previous Antigravity entries so the new ones fully replace
252
250
  // them; keep entries from OTHER providers (Ollama) so multi-provider
253
251
  // accounts accumulate quotas across credentials without overwriting
package/src/proxy.ts CHANGED
@@ -14,6 +14,7 @@ import { Readable, type Duplex } from "node:stream";
14
14
  import {
15
15
  classifyEffortRoutingModel,
16
16
  getEffortRoutingRule,
17
+ applyModelAlias,
17
18
  resolveQuotaModelKey,
18
19
  resolveDisplayModelKey,
19
20
  } from "./types.js";
@@ -40,6 +41,7 @@ import {
40
41
  extractUsageFromSseEvent,
41
42
  GOOGLE_BENCHMARK_CONSTANTS,
42
43
  } from "./providers/google-antigravity/forward.js";
44
+ import { isDynamicallyAvailableAntigravityModel } from "./providers/google-antigravity/catalog.js";
43
45
  export { forwardRequest, SseEventAccumulator, extractUsageFromSseEvent };
44
46
  import {
45
47
  serveStatusApi,
@@ -1084,7 +1086,7 @@ export async function benchmarkAccount(
1084
1086
  error: `${benchmarkProvider.displayName} is turned off on the Models page`,
1085
1087
  };
1086
1088
  if (turnedOff()) return turnedOffResult;
1087
- rotator.startRequest(account, benchmarkSpec.body.model);
1089
+ rotator.startRequest(account, benchmarkSpec.body.model, benchmarkProvider.id);
1088
1090
  const timeoutController = new AbortController();
1089
1091
  const timeout = setTimeout(
1090
1092
  () => timeoutController.abort(new Error("Benchmark timeout")),
@@ -1129,7 +1131,7 @@ export async function benchmarkAccount(
1129
1131
  return benchmarkFailure(account, startedAt, formatError(err), ttfbMs);
1130
1132
  } finally {
1131
1133
  clearTimeout(timeout);
1132
- rotator.finishRequest(account, benchmarkSpec.body.model);
1134
+ rotator.finishRequest(account, benchmarkSpec.body.model, benchmarkProvider.id);
1133
1135
  }
1134
1136
  }
1135
1137
 
@@ -1267,6 +1269,19 @@ export async function withRotation<T>(
1267
1269
  ollamaModels: new Set(rotator.getOllamaModels?.() ?? []),
1268
1270
  codexModels: new Set(rotator.getCodexModels?.() ?? []),
1269
1271
  })?.id;
1272
+ const modelQuotaFamily = resolveQuotaModelKey(model) ??
1273
+ resolveQuotaModelKey(applyModelAlias(model));
1274
+ if (
1275
+ (providerId === DEFAULT_PROVIDER ||
1276
+ (!providerId && (modelQuotaFamily === "claude" || modelQuotaFamily === "gemini"))) &&
1277
+ !isDynamicallyAvailableAntigravityModel(model)
1278
+ ) {
1279
+ return {
1280
+ ok: false,
1281
+ status: 404,
1282
+ errorText: `Model '${body.displayModel || model}' is not available in the active Antigravity model catalog`,
1283
+ };
1284
+ }
1270
1285
  const requestIsOff = (selectedProviderId = providerId): boolean => isRequestOff(rotator, {
1271
1286
  model,
1272
1287
  requestedModel: body.requestedModel,
@@ -1335,7 +1350,7 @@ export async function withRotation<T>(
1335
1350
  const releaseCurrentAccount = (): void => {
1336
1351
  if (accountReleased) return;
1337
1352
  accountReleased = true;
1338
- rotator.finishRequest(account, modelKey);
1353
+ rotator.finishRequest(account, modelKey, providerId);
1339
1354
  };
1340
1355
  const rotateAndRelease = async (): Promise<AccountRuntime | null> => {
1341
1356
  releaseCurrentAccount();
@@ -1855,7 +1870,7 @@ async function handleProxyRequest(
1855
1870
  const releaseCurrentAccount = (): void => {
1856
1871
  if (accountReleased) return;
1857
1872
  accountReleased = true;
1858
- rotator.finishRequest(account, modelKey);
1873
+ rotator.finishRequest(account, modelKey, providerId);
1859
1874
  };
1860
1875
  const rotateAndRelease = async (): Promise<AccountRuntime | null> => {
1861
1876
  releaseCurrentAccount();
@@ -2209,6 +2224,7 @@ async function handleCodeAssistPassthrough(
2209
2224
  rotator.finishRequest(
2210
2225
  account,
2211
2226
  resolveQuotaModelKey(CODE_ASSIST_ROUTING_MODEL) ?? undefined,
2227
+ DEFAULT_PROVIDER,
2212
2228
  );
2213
2229
  };
2214
2230