tuxevil-rotator 4.2.2 → 4.3.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 (39) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +9 -4
  3. package/package.json +1 -1
  4. package/plugins/opencode-discovery/capabilities.d.mts +7 -0
  5. package/plugins/opencode-discovery/capabilities.mjs +54 -0
  6. package/plugins/opencode-discovery/index.d.mts +2 -1
  7. package/plugins/opencode-discovery/index.mjs +6 -1
  8. package/plugins/opencode-discovery/package.json +3 -1
  9. package/src/audio-transcription.ts +32 -6
  10. package/src/cli.ts +3 -3
  11. package/src/compat/model-specs.ts +4 -0
  12. package/src/compat.ts +30 -1
  13. package/src/dashboard-app.ts +1 -0
  14. package/src/install-agent.ts +211 -129
  15. package/src/install-opencode.ts +80 -18
  16. package/src/providers/google-antigravity/catalog.ts +14 -6
  17. package/src/providers/google-antigravity/dynamic-catalog.ts +79 -3
  18. package/src/providers/google-antigravity/forward.ts +4 -2
  19. package/src/providers/google-antigravity/quota.ts +4 -0
  20. package/src/providers/ollama/forward.ts +10 -0
  21. package/src/providers/openai-codex/catalog.ts +157 -18
  22. package/src/proxy.ts +35 -2
  23. package/src/rotator.ts +16 -2
  24. package/src/types.ts +78 -29
  25. package/src/web/app.tsx +4 -0
  26. package/src/web/lib/audio-recorder.ts +159 -0
  27. package/src/web/lib/colors.ts +4 -0
  28. package/src/web/lib/playground-storage.ts +261 -0
  29. package/src/web/lib/playground.ts +448 -0
  30. package/src/web/nav.ts +1 -0
  31. package/src/web/pages/Playground.tsx +1111 -0
  32. package/src/web/pages/Transcription.tsx +428 -0
  33. package/src/web/state/api.ts +3 -0
  34. package/src/web/state/playground-client.ts +136 -0
  35. package/src/web/state/playground.ts +69 -0
  36. package/src/web/state/router.ts +2 -2
  37. package/src/web/state/transcription-client.ts +93 -0
  38. package/src/web/styles/app.css +45 -0
  39. package/tools/telemetry-receiver/receiver.js +59 -46
@@ -1,3 +1,5 @@
1
+ import { mergeOpenCodeModels } from "../plugins/opencode-discovery/capabilities.mjs";
2
+ import type { RawRotatorModel } from "../plugins/opencode-discovery/index.mjs";
1
3
  import { execSync } from "node:child_process";
2
4
  import { readFileSync, existsSync } from "node:fs";
3
5
  import { resolve, dirname } from "node:path";
@@ -10,7 +12,11 @@ const PLUGIN_SOURCE_DIR = resolve(__dirname, "../plugins/opencode-discovery");
10
12
  * Files shipped from the repo plugin directory to the target machine.
11
13
  * Keep in sync with plugins/opencode-discovery/.
12
14
  */
13
- const PLUGIN_RUNTIME_SOURCE_FILES = ["index.mjs", "package.json"];
15
+ const PLUGIN_RUNTIME_SOURCE_FILES = [
16
+ "index.mjs",
17
+ "package.json",
18
+ "capabilities.mjs",
19
+ ];
14
20
 
15
21
  export interface InstallOptions {
16
22
  host?: string;
@@ -31,6 +37,7 @@ export interface DiscoveryConfigInput {
31
37
  providerName: string;
32
38
  baseURL: string;
33
39
  apiKey?: string;
40
+ models?: RawRotatorModel[];
34
41
  }
35
42
 
36
43
  /**
@@ -47,12 +54,21 @@ export interface DiscoveryConfigInput {
47
54
  */
48
55
  export function applyDiscoveryPluginConfig(
49
56
  config: Record<string, unknown>,
50
- { pluginDir, providerID, providerName, baseURL, apiKey }: DiscoveryConfigInput
57
+ {
58
+ pluginDir,
59
+ providerID,
60
+ providerName,
61
+ baseURL,
62
+ apiKey,
63
+ models,
64
+ }: DiscoveryConfigInput,
51
65
  ): Record<string, unknown> {
52
66
  const isDiscoveryEntry = (entry: unknown): boolean => {
53
67
  if (typeof entry === "string") return entry.includes("opencode-discovery");
54
68
  if (Array.isArray(entry)) {
55
- return typeof entry[0] === "string" && entry[0].includes("opencode-discovery");
69
+ return (
70
+ typeof entry[0] === "string" && entry[0].includes("opencode-discovery")
71
+ );
56
72
  }
57
73
  if (entry && typeof entry === "object") {
58
74
  const pkg = (entry as { package?: unknown }).package;
@@ -66,7 +82,9 @@ export function applyDiscoveryPluginConfig(
66
82
  : [];
67
83
 
68
84
  if (Array.isArray(config.plugin)) {
69
- const kept = (config.plugin as unknown[]).filter((entry) => !isDiscoveryEntry(entry));
85
+ const kept = (config.plugin as unknown[]).filter(
86
+ (entry) => !isDiscoveryEntry(entry),
87
+ );
70
88
  if (kept.length > 0) {
71
89
  config.plugin = kept;
72
90
  } else {
@@ -91,6 +109,14 @@ export function applyDiscoveryPluginConfig(
91
109
 
92
110
  provider[providerID] = {
93
111
  ...(existing as object),
112
+ ...(models?.length
113
+ ? {
114
+ models: mergeOpenCodeModels(
115
+ existing.models as Record<string, unknown>,
116
+ models,
117
+ ),
118
+ }
119
+ : {}),
94
120
  npm: "@ai-sdk/openai-compatible",
95
121
  name: providerName,
96
122
  options: {
@@ -118,10 +144,12 @@ export function buildRemoteInstallerScript(
118
144
  providerName: string;
119
145
  apiKey?: string;
120
146
  targetDir?: string;
121
- }
147
+ },
122
148
  ): string {
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(", ")}`);
149
+ if (!PLUGIN_RUNTIME_SOURCE_FILES.every((name) => name in pluginFiles)) {
150
+ throw new Error(
151
+ `pluginFiles must include all of: ${PLUGIN_RUNTIME_SOURCE_FILES.join(", ")}`,
152
+ );
125
153
  }
126
154
 
127
155
  const targetDir = options.targetDir || "~/.config/opencode";
@@ -149,6 +177,7 @@ ${fileWriteLines}
149
177
 
150
178
  # Prepare node script to cleanly mutate or create opencode.json (OpenCode 2.x form)
151
179
  node -e '
180
+ (async () => {
152
181
  const fs = require("fs");
153
182
  const path = require("path");
154
183
 
@@ -224,12 +253,22 @@ if (apiKey && apiKey !== "no-key") {
224
253
  config.provider[providerID].options.apiKey = apiKey;
225
254
  }
226
255
 
256
+ const { fetchModels, mergeOpenCodeModels } = await import(require("url").pathToFileURL(path.join(pluginDir, "capabilities.mjs")).href);
257
+ try {
258
+ const live = await fetchModels(baseURL, apiKey);
259
+ config.provider[providerID].models = mergeOpenCodeModels(config.provider[providerID].models, live);
260
+ } catch {
261
+ console.warn("==> Catalog unavailable; existing models retained. Discovery will retry at startup.");
262
+ }
263
+
227
264
  if (!config.model) {
228
265
  config.model = providerID + "/gemini-3.8-flash-high";
229
266
  }
230
267
 
268
+ if (fs.existsSync(configFile)) fs.copyFileSync(configFile, configFile + ".bak." + Date.now());
231
269
  fs.writeFileSync(configFile, JSON.stringify(config, null, 2) + "\\n", "utf8");
232
270
  console.log("==> Successfully updated " + configFile);
271
+ })().catch(error => { console.error(error.message); process.exitCode = 1; });
233
272
  ' "$CONFIG_FILE" "$PLUGIN_DIR" "${providerId}" "${providerName}" "${rotatorUrl}" "${apiKey || ""}"
234
273
 
235
274
  echo "==> Installation complete! OpenCode is now configured to discover models from ${rotatorUrl}"
@@ -239,17 +278,25 @@ echo "==> Installation complete! OpenCode is now configured to discover models f
239
278
  /**
240
279
  * Installs the discovery plugin either locally or remotely via SSH.
241
280
  */
242
- export async function installOpenCodePlugin(options: InstallOptions): Promise<void> {
281
+ export async function installOpenCodePlugin(
282
+ options: InstallOptions,
283
+ ): Promise<void> {
243
284
  const pluginFiles: Record<string, string> = {};
244
285
  for (const name of PLUGIN_RUNTIME_SOURCE_FILES) {
245
286
  const filePath = resolve(PLUGIN_SOURCE_DIR, name);
246
287
  if (!existsSync(filePath)) {
247
- throw new Error(`Plugin directory ${PLUGIN_SOURCE_DIR} does not contain ${name}`);
288
+ throw new Error(
289
+ `Plugin directory ${PLUGIN_SOURCE_DIR} does not contain ${name}`,
290
+ );
248
291
  }
249
292
  pluginFiles[name] = readFileSync(filePath, "utf8");
250
293
  }
251
294
 
252
- const rotatorUrl = (options.rotatorUrl || process.env.TUXEVIL_ROTATOR_BASE_URL || "http://127.0.0.1:51200/v1").replace(/\/+$/, "");
295
+ const rotatorUrl = (
296
+ options.rotatorUrl ||
297
+ process.env.TUXEVIL_ROTATOR_BASE_URL ||
298
+ "http://127.0.0.1:51200/v1"
299
+ ).replace(/\/+$/, "");
253
300
  const providerId = options.providerId || "antigravity";
254
301
  const providerName = options.providerName || "Antigravity (rotator)";
255
302
 
@@ -268,8 +315,14 @@ export async function installOpenCodePlugin(options: InstallOptions): Promise<vo
268
315
  }
269
316
 
270
317
  // Local installation
271
- if (!options.host || options.host === "localhost" || options.host === "127.0.0.1") {
272
- console.log(`==> Installing OpenCode plugin locally for rotator: ${rotatorUrl}...`);
318
+ if (
319
+ !options.host ||
320
+ options.host === "localhost" ||
321
+ options.host === "127.0.0.1"
322
+ ) {
323
+ console.log(
324
+ `==> Installing OpenCode plugin locally for rotator: ${rotatorUrl}...`,
325
+ );
273
326
  execSync("bash -s", {
274
327
  input: script,
275
328
  stdio: ["pipe", "inherit", "inherit"],
@@ -278,11 +331,16 @@ export async function installOpenCodePlugin(options: InstallOptions): Promise<vo
278
331
  }
279
332
 
280
333
  // Remote installation via SSH
281
- const sshTarget = options.user ? `${options.user}@${options.host}` : options.host;
334
+ const sshTarget = options.user
335
+ ? `${options.user}@${options.host}`
336
+ : options.host;
282
337
  const sshArgs: string[] = [
283
- "-o", "BatchMode=yes",
284
- "-o", "ConnectTimeout=10",
285
- "-o", "StrictHostKeyChecking=accept-new",
338
+ "-o",
339
+ "BatchMode=yes",
340
+ "-o",
341
+ "ConnectTimeout=10",
342
+ "-o",
343
+ "StrictHostKeyChecking=accept-new",
286
344
  ];
287
345
 
288
346
  if (options.port) {
@@ -294,7 +352,9 @@ export async function installOpenCodePlugin(options: InstallOptions): Promise<vo
294
352
 
295
353
  const sshCmd = `ssh ${sshArgs.join(" ")} ${sshTarget} "bash -s"`;
296
354
 
297
- console.log(`==> Installing OpenCode plugin remotely on ${sshTarget} (Rotator: ${rotatorUrl})...`);
355
+ console.log(
356
+ `==> Installing OpenCode plugin remotely on ${sshTarget} (Rotator: ${rotatorUrl})...`,
357
+ );
298
358
  try {
299
359
  execSync(sshCmd, {
300
360
  input: script,
@@ -302,6 +362,8 @@ export async function installOpenCodePlugin(options: InstallOptions): Promise<vo
302
362
  });
303
363
  } catch (err: unknown) {
304
364
  const errorMsg = err instanceof Error ? err.message : String(err);
305
- throw new Error(`SSH installation failed on ${sshTarget}: ${errorMsg}`, { cause: err });
365
+ throw new Error(`SSH installation failed on ${sshTarget}: ${errorMsg}`, {
366
+ cause: err,
367
+ });
306
368
  }
307
369
  }
@@ -39,6 +39,11 @@ export const ANTIGRAVITY_CONTEXT_WINDOWS: Record<string, number> = {
39
39
  // OpenAI gpt-oss-120b — 131,072 per platform.openai.com/docs/models/gpt-oss-120b.
40
40
  "gpt-oss-120b": 131_072,
41
41
  "gpt-oss-120b-medium": 131_072,
42
+ // Google Gemini 4 Argon family — 1M context window.
43
+ "gemini-4-argon": 1_000_000,
44
+ "gemini-4-argon-high": 1_000_000,
45
+ "gemini-4-argon-medium": 1_000_000,
46
+ "gemini-4-argon-low": 1_000_000,
42
47
  // Google Gemini 3.x — 1M context window per deepmind.google/models/gemini/*.
43
48
  "gemini-3.8-flash-high": 1_000_000,
44
49
  "gemini-3.8-flash-medium": 1_000_000,
@@ -76,8 +81,8 @@ const FALLBACK_CONTEXT_WINDOW = 128_000;
76
81
  *
77
82
  * Lookup order:
78
83
  * 1. Operator exact/substring override.
79
- * 2. Exact id match in static table (lowercased).
80
- * 3. Dynamic catalog entry from live Antigravity endpoint.
84
+ * 2. Dynamic catalog entry from an account snapshot.
85
+ * 3. Exact id match in static table (lowercased).
81
86
  * 4. Substring match across the table (longest key wins via the order here).
82
87
  * 5. Family defaults: claude -> 1M, gemini -> 1M, gpt-oss -> 131_072.
83
88
  * 6. Defensive fallback: 128_000.
@@ -90,10 +95,10 @@ export function getAntigravityContextWindow(model: string): number {
90
95
  if (typeof overrideCtx === "number" && Number.isFinite(overrideCtx) && overrideCtx > 0) {
91
96
  return overrideCtx;
92
97
  }
93
- const exact = ANTIGRAVITY_CONTEXT_WINDOWS[lower];
94
- if (typeof exact === "number") return exact;
95
98
  const dynamicCtx = dynamicCatalog.getContextWindow(lower);
96
99
  if (typeof dynamicCtx === "number") return dynamicCtx;
100
+ const exact = ANTIGRAVITY_CONTEXT_WINDOWS[lower];
101
+ if (typeof exact === "number") return exact;
97
102
  // Substring fallback: pick the longest registered key that appears in lower.
98
103
  let best: { key: string; value: number } | null = null;
99
104
  for (const [key, value] of Object.entries(ANTIGRAVITY_CONTEXT_WINDOWS)) {
@@ -155,14 +160,17 @@ export function getEffectiveAntigravityModels(): CompatModelEntry[] {
155
160
  const backingModel = byId.get(target);
156
161
  if (backingModel) result.push(toCompatModel(backingModel, "whisper-1", false));
157
162
  }
163
+
158
164
  return result;
159
165
  }
160
166
 
161
167
  /** Whether an id or configured operator alias resolves to a current snapshot model. */
162
168
  export function isDynamicallyAvailableAntigravityModel(model: string): boolean {
163
169
  const normalize = (value: string) => value.trim().replace(/^models\//i, "").toLowerCase();
170
+ const normalized = normalize(model);
171
+ const aliased = normalize(applyModelAlias(model));
164
172
  return Boolean(
165
- dynamicCatalog.getModel(normalize(model)) ??
166
- dynamicCatalog.getModel(normalize(applyModelAlias(model))),
173
+ dynamicCatalog.getModel(normalized) ??
174
+ dynamicCatalog.getModel(aliased),
167
175
  );
168
176
  }
@@ -8,6 +8,7 @@ import {
8
8
  QUOTA_MODEL_KEYS,
9
9
  type GoogleQuotaResponse,
10
10
  type PersistedDynamicModelOwnership,
11
+ type PersistedDynamicModelSnapshots,
11
12
  } from "../../types.js";
12
13
 
13
14
  export interface DynamicModelEntry {
@@ -60,8 +61,7 @@ function isDiscoverableModelId(value: string): boolean {
60
61
  return isSafeModelId(id) &&
61
62
  !RESERVED_QUOTA_MODEL_IDS.has(lower) &&
62
63
  !lower.startsWith("chat_") &&
63
- !lower.startsWith("tab_") &&
64
- (!lower.startsWith("gemini-3.5-") || lower === "gemini-3.5-flash-lite");
64
+ !lower.startsWith("tab_");
65
65
  }
66
66
 
67
67
  /** Validate and sanitize the untrusted runtime catalog response. */
@@ -213,6 +213,7 @@ function familyDefaults(
213
213
  export class DynamicModelRegistry {
214
214
  private static instance: DynamicModelRegistry | null = null;
215
215
  private accountModels = new Map<string, Map<string, DynamicModelEntry>>();
216
+ private snapshotTimes = new Map<string, number>();
216
217
  private defaultAgentModelIds = new Map<string, string>();
217
218
  private discoveredModels = new Map<
218
219
  string,
@@ -225,6 +226,7 @@ export class DynamicModelRegistry {
225
226
  ActiveAccountGeneration
226
227
  > | null = null;
227
228
  private nextAccountEpoch = 0;
229
+ snapshotRevision = 0;
228
230
 
229
231
  static getInstance(): DynamicModelRegistry {
230
232
  DynamicModelRegistry.instance ??= new DynamicModelRegistry();
@@ -234,6 +236,7 @@ export class DynamicModelRegistry {
234
236
  /** Reset dynamic account state (primarily for tests). */
235
237
  reset(): void {
236
238
  this.accountModels.clear();
239
+ this.snapshotTimes.clear();
237
240
  this.defaultAgentModelIds.clear();
238
241
  this.discoveredModels.clear();
239
242
  this.accountModelOwnership.clear();
@@ -377,6 +380,8 @@ export class DynamicModelRegistry {
377
380
  this.defaultAgentModelIds.delete(key);
378
381
  }
379
382
 
383
+ this.snapshotRevision++;
384
+ this.snapshotTimes.set(key, Date.now());
380
385
  this.accountModels.set(key, next);
381
386
  this.accountModelOwnership.set(key, new Set(next.keys()));
382
387
  return newModelsCount;
@@ -407,6 +412,7 @@ export class DynamicModelRegistry {
407
412
  (previousGeneration !== undefined && previousGeneration !== nextGeneration)
408
413
  ) {
409
414
  this.accountModels.delete(key);
415
+ this.snapshotTimes.delete(key);
410
416
  }
411
417
  }
412
418
  for (const key of this.accountModelOwnership.keys()) {
@@ -484,7 +490,8 @@ export class DynamicModelRegistry {
484
490
  }
485
491
 
486
492
  wasDiscovered(id: string): boolean {
487
- return this.discoveredModels.has(id.trim().toLowerCase());
493
+ const lower = id.trim().toLowerCase();
494
+ return this.discoveredModels.has(lower);
488
495
  }
489
496
 
490
497
  getObservedModelId(id: string): string | undefined {
@@ -500,6 +507,75 @@ export class DynamicModelRegistry {
500
507
  return pools;
501
508
  }
502
509
 
510
+ getPersistedSnapshots(accounts: Iterable<PersistedOwnershipAccount>): PersistedDynamicModelSnapshots {
511
+ const snapshots: PersistedDynamicModelSnapshots = { version: 1, accounts: Object.create(null) };
512
+ for (const account of accounts) {
513
+ const id = accountKey(account.id);
514
+ const models = this.accountModels.get(id);
515
+ if (!models) continue;
516
+ snapshots.accounts[id] = {
517
+ credentialGenerationFingerprint: account.credentialGenerationFingerprint,
518
+ capturedAt: this.snapshotTimes.get(id)!,
519
+ models: Array.from(models.values(), (model) => ({ ...model })),
520
+ defaultAgentModelId: this.defaultAgentModelIds.get(id),
521
+ };
522
+ }
523
+ return snapshots;
524
+ }
525
+
526
+ restorePersistedSnapshots(value: unknown, accounts: Iterable<PersistedOwnershipAccount>): void {
527
+ if (!isRecord(value) || value.version !== 1 || !isRecord(value.accounts)) return;
528
+ for (const account of accounts) {
529
+ const id = accountKey(account.id);
530
+ const snapshot = value.accounts[id];
531
+ if (!isRecord(snapshot) ||
532
+ snapshot.credentialGenerationFingerprint !== account.credentialGenerationFingerprint ||
533
+ typeof snapshot.capturedAt !== "number" || !Number.isFinite(snapshot.capturedAt) ||
534
+ snapshot.capturedAt <= 0 || !Array.isArray(snapshot.models)) continue;
535
+ const models = new Map<string, DynamicModelEntry>();
536
+ let valid = true;
537
+ for (const raw of snapshot.models) {
538
+ if (!isRecord(raw) || typeof raw.id !== "string" || !isDiscoverableModelId(raw.id) ||
539
+ typeof raw.family !== "string" || !isSafeModelId(raw.family) ||
540
+ typeof raw.quotaPool !== "string" || !["gemini", "claude"].includes(raw.quotaPool) ||
541
+ !["ctx", "maxOutputTokens"].every((key) => typeof raw[key] === "number" && Number.isFinite(raw[key]) && raw[key] > 0) ||
542
+ typeof raw.thinkingBudget !== "number" || !Number.isFinite(raw.thinkingBudget) || raw.thinkingBudget < -1 ||
543
+ (raw.thinkingBudget < 0 && raw.thinkingBudget !== -1) ||
544
+ (raw.minThinkingBudget !== undefined && (typeof raw.minThinkingBudget !== "number" || !Number.isFinite(raw.minThinkingBudget) || raw.minThinkingBudget < 0)) ||
545
+ !["multimodal", "tools", "isThinking", "isTiered"].every((key) => typeof raw[key] === "boolean") ||
546
+ (raw.displayName !== undefined && typeof raw.displayName !== "string")) {
547
+ valid = false;
548
+ break;
549
+ }
550
+ models.set(raw.id.trim().toLowerCase(), {
551
+ id: raw.id.trim(),
552
+ family: raw.family as string,
553
+ quotaPool: raw.quotaPool as string,
554
+ ctx: raw.ctx as number,
555
+ maxOutputTokens: raw.maxOutputTokens as number,
556
+ thinkingBudget: raw.thinkingBudget as number,
557
+ ...(raw.minThinkingBudget !== undefined ? { minThinkingBudget: raw.minThinkingBudget as number } : {}),
558
+ multimodal: raw.multimodal as boolean,
559
+ tools: raw.tools as boolean,
560
+ isThinking: raw.isThinking as boolean,
561
+ isTiered: raw.isTiered as boolean,
562
+ ...(raw.displayName !== undefined ? { displayName: raw.displayName as string } : {}),
563
+ });
564
+ }
565
+ const defaultId = snapshot.defaultAgentModelId;
566
+ if (!valid || (defaultId !== undefined && (typeof defaultId !== "string" || !isSafeModelId(defaultId)))) continue;
567
+ this.accountModels.set(id, models);
568
+ this.snapshotTimes.set(id, snapshot.capturedAt);
569
+ this.accountModelOwnership.set(id, new Set(models.keys()));
570
+ this.defaultAgentModelIds.delete(id);
571
+ if (typeof defaultId === "string") this.defaultAgentModelIds.set(id, defaultId);
572
+ for (const [key, model] of models) {
573
+ this.discoveredModels.set(key, { id: model.id, quotaPool: model.quotaPool });
574
+ this.ownershipScopedModels.add(key);
575
+ }
576
+ }
577
+ }
578
+
503
579
  getPersistedModelOwnership(
504
580
  accounts: Iterable<PersistedOwnershipAccount>,
505
581
  ): PersistedDynamicModelOwnership {
@@ -177,7 +177,7 @@ function extractTextFromSseEvent(eventText: string): string | null {
177
177
  try {
178
178
  const parsed = JSON.parse(payload);
179
179
  if (parsed && typeof parsed === "object") {
180
- const p = parsed as Record<string, unknown>;
180
+ const p = isRecord(parsed.response) ? parsed.response : parsed;
181
181
  if (
182
182
  Array.isArray(p.candidates) &&
183
183
  p.candidates[0] &&
@@ -191,6 +191,7 @@ function extractTextFromSseEvent(eventText: string): string | null {
191
191
  .map((part) =>
192
192
  part &&
193
193
  typeof part === "object" &&
194
+ (part as Record<string, unknown>).thought !== true &&
194
195
  typeof (part as Record<string, unknown>).text === "string"
195
196
  ? (part as Record<string, unknown>).text
196
197
  : "",
@@ -282,7 +283,8 @@ function benchmarkUsage(raw: string): { outputTokens: number } | null {
282
283
  for (const event of raw.split(/\r?\n\r?\n/)) {
283
284
  const usage = extractUsageFromSseEvent(event);
284
285
  if (usage) {
285
- outputTokens += usage.outputTokens;
286
+ // Antigravity repeats cumulative usage in content and final events.
287
+ outputTokens = Math.max(outputTokens, usage.outputTokens);
286
288
  }
287
289
  }
288
290
  return { outputTokens };
@@ -10,6 +10,8 @@ import {
10
10
  QUOTA_API_URL,
11
11
  QUOTA_USER_AGENT,
12
12
  QUOTA_MODEL_KEYS,
13
+ REQUEST_CLIENT_METADATA,
14
+ REQUEST_GOOG_API_CLIENT,
13
15
  } from "../../types.js";
14
16
  import { fetchWithRetry } from "../../fetch-with-retry.js";
15
17
  import {
@@ -200,6 +202,8 @@ export async function fetchProviderQuota(
200
202
  "Content-Type": "application/json",
201
203
  Authorization: `Bearer ${account.accessToken}`,
202
204
  "User-Agent": QUOTA_USER_AGENT,
205
+ "X-Goog-Api-Client": REQUEST_GOOG_API_CLIENT,
206
+ "Client-Metadata": REQUEST_CLIENT_METADATA,
203
207
  },
204
208
  body: JSON.stringify({
205
209
  project: getProviderProjectId(account.config, DEFAULT_PROVIDER),
@@ -86,6 +86,16 @@ export function buildOllamaPayload(body: RequestBody): Record<string, unknown> {
86
86
  if (!isRecord(msg)) return msg;
87
87
  const normalized = { ...msg };
88
88
  normalizeOllamaMessageContent(normalized);
89
+ // Ollama decodes images[] directly as base64. OpenAI/Anthropic image
90
+ // blocks use data URLs, whose prefix fails decoding at the ':' byte.
91
+ // Normalize after merging so native images and content blocks both work.
92
+ if (Array.isArray(normalized.images)) {
93
+ normalized.images = normalized.images.map((image: unknown) =>
94
+ typeof image === "string"
95
+ ? image.replace(/^data:[^,]*;base64,/i, "")
96
+ : image,
97
+ );
98
+ }
89
99
  return normalized;
90
100
  });
91
101
  const payload: Record<string, unknown> = {