tuxevil-rotator 3.5.0 → 3.6.1

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.
@@ -12,13 +12,84 @@ import {
12
12
  QUOTA_MODEL_KEYS,
13
13
  } from "../../types.js";
14
14
  import { fetchWithRetry } from "../../fetch-with-retry.js";
15
- import { getAccountIdentity } from "../../account-identity.js";
15
+ import {
16
+ getAccountIdentity,
17
+ getCredentialGeneration,
18
+ } from "../../account-identity.js";
16
19
  import type { QuotaFetchContext } from "../adapter.js";
17
20
  import { DEFAULT_PROVIDER, getProviderProjectId } from "../credential-helpers.js";
18
21
  import { getAccountProxyDispatcher } from "../proxy-dispatcher.js";
19
22
  import { sortQuotaPools } from "../registry.js";
20
23
 
21
- import { dynamicCatalog, DynamicModelRegistry } from "./dynamic-catalog.js";
24
+ import {
25
+ dynamicCatalog,
26
+ DynamicModelRegistry,
27
+ parseGoogleQuotaResponse,
28
+ } from "./dynamic-catalog.js";
29
+
30
+ type GoogleModelInfo = GoogleQuotaResponse["models"][string];
31
+ type GoogleModelInfoWithQuota = GoogleModelInfo & {
32
+ quotaInfo: NonNullable<GoogleModelInfo["quotaInfo"]>;
33
+ };
34
+
35
+ function hasUsableQuotaInfo(
36
+ info: GoogleModelInfo | undefined,
37
+ ): info is GoogleModelInfoWithQuota {
38
+ if (!info?.quotaInfo) return false;
39
+ const remaining = info.quotaInfo.remainingFraction;
40
+ if (remaining === undefined) {
41
+ // Google omits remainingFraction for active quota windows. A resetTime
42
+ // without a fraction is the partial shape used by the legacy parser.
43
+ return typeof info.quotaInfo.resetTime === "string" &&
44
+ info.quotaInfo.resetTime.trim().length > 0;
45
+ }
46
+ return typeof remaining === "number" && Number.isFinite(remaining) &&
47
+ remaining >= 0 && remaining <= 1;
48
+ }
49
+
50
+ function getRemainingFraction(info: GoogleModelInfoWithQuota): number {
51
+ const remaining = info.quotaInfo.remainingFraction;
52
+ return typeof remaining === "number" && Number.isFinite(remaining) &&
53
+ remaining >= 0 && remaining <= 1
54
+ ? remaining
55
+ : 0;
56
+ }
57
+
58
+ function applyActiveCooldown(
59
+ quota: ModelQuota,
60
+ cooldownUntil: number | undefined,
61
+ now: number,
62
+ ): void {
63
+ if (!cooldownUntil || !Number.isFinite(cooldownUntil) || cooldownUntil <= now) {
64
+ return;
65
+ }
66
+ const advertisedReset = quota.resetTime
67
+ ? new Date(quota.resetTime).getTime()
68
+ : 0;
69
+ const resetAt = Math.max(
70
+ cooldownUntil,
71
+ Number.isFinite(advertisedReset) && advertisedReset > now ? advertisedReset : 0,
72
+ );
73
+ quota.percentRemaining = 0;
74
+ quota.resetTime = new Date(resetAt).toISOString();
75
+ quota.timerType = resetAt - now < 6 * 60 * 60 * 1000 ? "5h" : "7d";
76
+ }
77
+
78
+ function getActiveCooldownForPool(
79
+ account: AccountRuntime,
80
+ poolKey: string,
81
+ ): number | undefined {
82
+ let cooldownUntil = account.cooldownsByModel[poolKey] ?? 0;
83
+ for (const [modelKey, deadline] of Object.entries(account.cooldownsByModel)) {
84
+ if (
85
+ modelKey !== poolKey &&
86
+ dynamicCatalog.resolveQuotaPool(modelKey) === poolKey
87
+ ) {
88
+ cooldownUntil = Math.max(cooldownUntil, deadline);
89
+ }
90
+ }
91
+ return cooldownUntil || undefined;
92
+ }
22
93
 
23
94
  /**
24
95
  * Extract per-model quotas from a Google quota response, preserving the
@@ -32,26 +103,33 @@ export function extractQuotas(
32
103
  const now = Date.now();
33
104
 
34
105
  for (const [, config] of Object.entries(QUOTA_MODEL_KEYS)) {
35
- let modelInfo = data.models[config.key];
36
-
37
- if (!modelInfo) {
38
- for (const altKey of config.altKeys) {
39
- modelInfo = data.models[altKey];
40
- if (modelInfo) break;
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);
41
111
  }
42
112
  }
43
113
 
44
- if (!modelInfo) {
45
- for (const [modelKey, info] of Object.entries(data.models)) {
46
- if (DynamicModelRegistry.inferFamilyAndPool(modelKey).quotaPool === config.key) {
47
- modelInfo = info;
48
- break;
49
- }
114
+ for (const [modelKey, info] of Object.entries(data.models)) {
115
+ if (
116
+ ![config.key, ...config.altKeys].includes(modelKey) &&
117
+ DynamicModelRegistry.inferFamilyAndPool(modelKey).quotaPool === config.key &&
118
+ hasUsableQuotaInfo(info)
119
+ ) {
120
+ candidates.push(info);
50
121
  }
51
122
  }
52
123
 
124
+ // A shared pool is usable only as far as its most exhausted model. Google
125
+ // may report one sibling at 100% while the model we route to is exhausted.
126
+ const modelInfo = candidates.sort(
127
+ (a, b) => getRemainingFraction(a) - getRemainingFraction(b) ||
128
+ Number(Boolean(b.quotaInfo.resetTime)) -
129
+ Number(Boolean(a.quotaInfo.resetTime)),
130
+ )[0];
53
131
  if (modelInfo?.quotaInfo) {
54
- const remainingFraction = modelInfo.quotaInfo.remainingFraction ?? 0;
132
+ const remainingFraction = getRemainingFraction(modelInfo);
55
133
  // Google can publish a nominal reset for an untouched pool; no usage means
56
134
  // there is no active quota window yet.
57
135
  const resetTime =
@@ -98,6 +176,24 @@ export async function fetchProviderQuota(
98
176
  ctx: QuotaFetchContext,
99
177
  ): Promise<void> {
100
178
  if (!account.accessToken) return;
179
+ const accountId = getAccountIdentity(account);
180
+ const credentialGeneration = getCredentialGeneration(
181
+ account,
182
+ DEFAULT_PROVIDER,
183
+ );
184
+ const accountEpoch = dynamicCatalog.captureAccountEpoch(
185
+ accountId,
186
+ credentialGeneration,
187
+ );
188
+ if (accountEpoch === null) return;
189
+ const isCurrentGeneration = (): boolean =>
190
+ accountId === getAccountIdentity(account) &&
191
+ credentialGeneration === getCredentialGeneration(account, DEFAULT_PROVIDER) &&
192
+ dynamicCatalog.isAccountGenerationActive(
193
+ accountId,
194
+ credentialGeneration,
195
+ accountEpoch,
196
+ );
101
197
 
102
198
  try {
103
199
  const response = await fetchWithRetry(QUOTA_API_URL, {
@@ -113,10 +209,12 @@ export async function fetchProviderQuota(
113
209
  timeoutMs: 8000,
114
210
  dispatcher: getAccountProxyDispatcher(account, "google-antigravity"),
115
211
  });
212
+ if (!isCurrentGeneration()) return;
116
213
 
117
214
  if (!response.ok) {
118
215
  if (response.status === 401 || response.status === 403) {
119
216
  const errorText = await response.text();
217
+ if (!isCurrentGeneration()) return;
120
218
  ctx.log(
121
219
  `${account.config.email}: quota API returned ${response.status}, flagging account`,
122
220
  );
@@ -130,18 +228,24 @@ export async function fetchProviderQuota(
130
228
  return;
131
229
  }
132
230
 
133
- const data = (await response.json()) as GoogleQuotaResponse;
231
+ const rawData = await response.json();
232
+ if (!isCurrentGeneration()) return;
233
+ const data = parseGoogleQuotaResponse(rawData);
234
+ if (!data) return;
235
+ const oldQuota = account.quota || [];
236
+ const fresh = extractQuotas(data, oldQuota);
237
+ if (fresh.length === 0) return;
134
238
  const newModels = dynamicCatalog.updateFromEndpointResponse(
135
239
  data,
136
- getAccountIdentity(account),
240
+ accountId,
241
+ credentialGeneration,
242
+ accountEpoch,
137
243
  );
138
244
  if (newModels > 0) {
139
245
  ctx.log(
140
246
  `${account.config.email}: discovered ${newModels} Antigravity model(s) from quota response`,
141
247
  );
142
248
  }
143
- const oldQuota = account.quota || [];
144
- const fresh = extractQuotas(data, oldQuota);
145
249
  // Drop the previous Antigravity entries so the new ones fully replace
146
250
  // them; keep entries from OTHER providers (Ollama) so multi-provider
147
251
  // accounts accumulate quotas across credentials without overwriting
@@ -153,7 +257,32 @@ export async function fetchProviderQuota(
153
257
  fresh.forEach(
154
258
  (q) => ((q as { providerId?: string }).providerId = "google-antigravity"),
155
259
  );
156
- account.quota = sortQuotaPools([...otherProviders, ...fresh]);
260
+ const freshKeys = new Set(fresh.map((quota) => quota.modelKey));
261
+ const previousGooglePools = oldQuota.filter(
262
+ (q) => (q as { providerId?: string }).providerId === DEFAULT_PROVIDER &&
263
+ !freshKeys.has(q.modelKey),
264
+ );
265
+ for (const quota of [...previousGooglePools, ...fresh]) {
266
+ if (
267
+ freshKeys.has(quota.modelKey) &&
268
+ quota.percentRemaining === 0 &&
269
+ quota.resetTime
270
+ ) {
271
+ // A newly reported exhausted window is authoritative; the poll
272
+ // reconciler will persist its reset time instead of stale local state.
273
+ continue;
274
+ }
275
+ applyActiveCooldown(
276
+ quota,
277
+ getActiveCooldownForPool(account, quota.modelKey),
278
+ Date.now(),
279
+ );
280
+ }
281
+ account.quota = sortQuotaPools([
282
+ ...otherProviders,
283
+ ...previousGooglePools,
284
+ ...fresh,
285
+ ]);
157
286
  account.lastQuotaPoll = Date.now();
158
287
 
159
288
  // Stash the provider-local poll log for the rotator to emit as a
@@ -1,5 +1,5 @@
1
1
  import { logger, redactSensitive } from "../../logger.js";
2
- import { applyModelAlias } from "../../types.js";
2
+ import { applyModelAlias, getEffortRoutingRule } from "../../types.js";
3
3
  import type { RequestBody } from "../../proxy.js";
4
4
  import {
5
5
  isRecord,
@@ -11,6 +11,7 @@ import {
11
11
  getModelSpec,
12
12
  isThinkingModel,
13
13
  } from "../../compat/model-specs.js";
14
+ import { dynamicCatalog } from "./dynamic-catalog.js";
14
15
  import {
15
16
  thoughtSignatureCache,
16
17
  getStoredResponse,
@@ -22,6 +23,32 @@ const compatLogger = logger.child("compat");
22
23
 
23
24
  const VALIDATION_LOG_MAX_CHARS = 200;
24
25
 
26
+ function normalizeFixedThinking(
27
+ modelSpec: ReturnType<typeof getModelSpec>,
28
+ requestedMaxOutputTokens: number | undefined,
29
+ ): { budget?: number; maxOutputTokens: number | undefined } {
30
+ const outputLimit = Math.max(1, Math.floor(modelSpec.maxOutputTokens));
31
+ const minimum = typeof modelSpec.minThinkingBudget === "number" &&
32
+ Number.isFinite(modelSpec.minThinkingBudget)
33
+ ? Math.max(0, Math.floor(modelSpec.minThinkingBudget))
34
+ : 0;
35
+ let budget = Math.max(
36
+ minimum,
37
+ Math.max(0, Math.floor(modelSpec.thinkingBudget)),
38
+ );
39
+ budget = Math.min(budget, outputLimit - 1);
40
+ if (budget < minimum) {
41
+ return { maxOutputTokens: requestedMaxOutputTokens };
42
+ }
43
+
44
+ let maxOutputTokens = requestedMaxOutputTokens;
45
+ if (!maxOutputTokens || maxOutputTokens <= budget) {
46
+ maxOutputTokens = Math.min(budget + 8192, outputLimit);
47
+ if (maxOutputTokens <= budget) maxOutputTokens = budget + 1;
48
+ }
49
+ return { budget, maxOutputTokens };
50
+ }
51
+
25
52
  export function logValidationFailure(scope: string, payload: unknown): void {
26
53
  const truncated = redactSensitive(JSON.stringify(payload));
27
54
  const clipped =
@@ -109,7 +136,7 @@ export interface OpenAIChatCompletionRequest {
109
136
  tools?: OpenAITool[];
110
137
  tool_choice?: unknown;
111
138
  /** OpenAI-style reasoning effort. Mapped to Gemini thinkingLevel. */
112
- reasoning_effort?: string;
139
+ reasoning_effort?: unknown;
113
140
  [key: string]: unknown;
114
141
  }
115
142
 
@@ -156,6 +183,7 @@ export interface CompatCompletion {
156
183
  toolCalls?: OpenAIToolCall[];
157
184
  rawResponse?: unknown;
158
185
  streamError?: string;
186
+ finishReason?: string;
159
187
  }
160
188
 
161
189
  export type AntigravityPart =
@@ -841,7 +869,6 @@ export function convertResponsesToChatRequest(
841
869
  * reasoning_effort. Matched case-insensitively against the exact ID only;
842
870
  * virtual siblings (e.g. `gemini-3.7-flash-tiered-high`) are excluded.
843
871
  */
844
- import { dynamicCatalog } from "./dynamic-catalog.js";
845
872
 
846
873
  export const TIERED_EFFORT_MODEL_ID = "gemini-3.7-flash-tiered";
847
874
  export const TIERED_EFFORT_MODEL_IDS = new Set([
@@ -866,7 +893,7 @@ export function isTieredEffortModel(modelId: string): boolean {
866
893
  * semantics and never emits an invalid upstream enum.
867
894
  */
868
895
  export function mapTieredReasoningEffortToThinkingLevel(
869
- effort: string | undefined,
896
+ effort: unknown,
870
897
  modelId: string,
871
898
  ): "LOW" | "MEDIUM" | "HIGH" | undefined {
872
899
  if (!isTieredEffortModel(modelId)) return undefined;
@@ -883,9 +910,35 @@ export function mapTieredReasoningEffortToThinkingLevel(
883
910
  }
884
911
  }
885
912
 
913
+ export function resolveEffortAliasModel(
914
+ requestedModel: string,
915
+ effort: unknown,
916
+ ): string | null {
917
+ const rule = getEffortRoutingRule(requestedModel);
918
+ if (!rule) return null;
919
+ const key = typeof effort === "string" ? effort.trim().toLowerCase() : "";
920
+ if (key && Object.hasOwn(rule.targets, key)) return rule.targets[key];
921
+ if (effort !== undefined) {
922
+ const supplied = typeof effort === "string"
923
+ ? JSON.stringify(effort.length > 40 ? `${effort.slice(0, 40)}…` : effort)
924
+ : `<${effort === null ? "null" : typeof effort}>`;
925
+ compatLogger.debug(
926
+ `Unrecognized effort ${supplied} for alias "${requestedModel.trim().toLowerCase()}", falling back to default`,
927
+ );
928
+ }
929
+ return Object.hasOwn(rule.targets, rule.defaultEffort)
930
+ ? rule.targets[rule.defaultEffort]
931
+ : null;
932
+ }
933
+
886
934
  export function openAIToAntigravityBody(
887
935
  input: OpenAIChatCompletionRequest,
888
936
  ): RequestBody {
937
+ const requestedModel = input.model;
938
+ const effortTarget =
939
+ resolveEffortAliasModel(requestedModel, input.reasoning_effort) ??
940
+ requestedModel;
941
+
889
942
  const systemParts: string[] = [];
890
943
  const conversationMessages = input.messages.filter((msg) => {
891
944
  if (msg.role === "system" || msg.role === "developer") {
@@ -899,8 +952,8 @@ export function openAIToAntigravityBody(
899
952
  return true;
900
953
  });
901
954
 
902
- const isClaude = /^claude-/i.test(input.model);
903
- const isThinking = isThinkingModel(input.model);
955
+ const isClaude = /^claude-/i.test(effortTarget);
956
+ const isThinking = isThinkingModel(effortTarget);
904
957
  const isGeminiThinking = !isClaude && isThinking;
905
958
 
906
959
  const contents: GeminiContent[] = [];
@@ -1179,26 +1232,35 @@ export function openAIToAntigravityBody(
1179
1232
  ? convertToolChoiceToGemini(input.tool_choice)
1180
1233
  : undefined;
1181
1234
 
1182
- const modelSpec = getModelSpec(input.model);
1183
- const modelFamily = getModelFamily(input.model);
1235
+ const modelSpec = getModelSpec(effortTarget);
1236
+ const modelFamily = getModelFamily(effortTarget);
1184
1237
  let maxOutputTokens =
1185
1238
  typeof input.max_tokens === "number" ? input.max_tokens : undefined;
1186
1239
  if (maxOutputTokens && maxOutputTokens > modelSpec.maxOutputTokens) {
1187
1240
  compatLogger.debug(
1188
- `Capping ${input.model} maxOutputTokens ${maxOutputTokens} → ${modelSpec.maxOutputTokens}`,
1241
+ `Capping ${effortTarget} maxOutputTokens ${maxOutputTokens} → ${modelSpec.maxOutputTokens}`,
1189
1242
  );
1190
1243
  maxOutputTokens = modelSpec.maxOutputTokens;
1191
1244
  }
1192
1245
 
1193
1246
  let thinkingConfigObj: Record<string, unknown> | undefined;
1194
1247
  if (modelFamily === "claude" && isThinking && !forcesToolUse(input.tool_choice)) {
1195
- const tb = modelSpec.thinkingBudget;
1196
- thinkingConfigObj = { include_thoughts: true, thinking_budget: tb };
1197
- if (!maxOutputTokens || maxOutputTokens <= tb) {
1198
- maxOutputTokens = Math.min(tb + 8192, modelSpec.maxOutputTokens);
1199
- compatLogger.debug(
1200
- `Adjusted Claude maxOutputTokens → ${maxOutputTokens}`,
1201
- );
1248
+ if (modelSpec.thinkingBudget === -1) {
1249
+ thinkingConfigObj = { include_thoughts: true };
1250
+ } else {
1251
+ const normalized = normalizeFixedThinking(modelSpec, maxOutputTokens);
1252
+ if (normalized.budget !== undefined) {
1253
+ thinkingConfigObj = {
1254
+ include_thoughts: true,
1255
+ thinking_budget: normalized.budget,
1256
+ };
1257
+ }
1258
+ if (maxOutputTokens !== normalized.maxOutputTokens) {
1259
+ maxOutputTokens = normalized.maxOutputTokens;
1260
+ compatLogger.debug(
1261
+ `Adjusted Claude maxOutputTokens → ${maxOutputTokens}`,
1262
+ );
1263
+ }
1202
1264
  }
1203
1265
  } else if (isThinking && modelFamily !== "claude") {
1204
1266
  const tb = modelSpec.thinkingBudget;
@@ -1211,7 +1273,7 @@ export function openAIToAntigravityBody(
1211
1273
  tb === -1
1212
1274
  ? mapTieredReasoningEffortToThinkingLevel(
1213
1275
  input.reasoning_effort,
1214
- input.model,
1276
+ effortTarget,
1215
1277
  )
1216
1278
  : undefined;
1217
1279
  if (tieredThinkingLevel) {
@@ -1221,23 +1283,29 @@ export function openAIToAntigravityBody(
1221
1283
  };
1222
1284
  } else if (tb === -1) {
1223
1285
  thinkingConfigObj = { includeThoughts: true };
1286
+ if (maxOutputTokens !== undefined) {
1287
+ // Adaptive models spend from the output budget before emitting visible text.
1288
+ const targetTokens = Math.max(maxOutputTokens + 8192, 8192);
1289
+ maxOutputTokens = Math.min(targetTokens, modelSpec.maxOutputTokens);
1290
+ compatLogger.debug(
1291
+ `Adjusted adaptive Gemini maxOutputTokens → ${maxOutputTokens}`,
1292
+ );
1293
+ }
1224
1294
  } else {
1225
- thinkingConfigObj = { includeThoughts: true, thinkingBudget: tb };
1226
- }
1227
- if (tb !== -1 && (!maxOutputTokens || maxOutputTokens <= tb)) {
1228
- maxOutputTokens = Math.min(tb + 8192, modelSpec.maxOutputTokens);
1229
- compatLogger.debug(
1230
- `Adjusted Gemini maxOutputTokens → ${maxOutputTokens}`,
1231
- );
1295
+ const normalized = normalizeFixedThinking(modelSpec, maxOutputTokens);
1296
+ if (normalized.budget !== undefined) {
1297
+ thinkingConfigObj = {
1298
+ includeThoughts: true,
1299
+ thinkingBudget: normalized.budget,
1300
+ };
1301
+ }
1302
+ if (maxOutputTokens !== normalized.maxOutputTokens) {
1303
+ maxOutputTokens = normalized.maxOutputTokens;
1304
+ compatLogger.debug(
1305
+ `Adjusted Gemini maxOutputTokens → ${maxOutputTokens}`,
1306
+ );
1307
+ }
1232
1308
  }
1233
- } else if (input.reasoning_effort) {
1234
- const budgets: Record<string, number> = {
1235
- low: Math.round(modelSpec.thinkingBudget / 4),
1236
- medium: Math.round(modelSpec.thinkingBudget / 2),
1237
- high: modelSpec.thinkingBudget,
1238
- };
1239
- const b = budgets[input.reasoning_effort.toLowerCase()];
1240
- if (b) thinkingConfigObj = { includeThoughts: true, thinkingBudget: b };
1241
1309
  }
1242
1310
 
1243
1311
  const generationConfig: Record<string, unknown> = {
@@ -1282,12 +1350,12 @@ export function openAIToAntigravityBody(
1282
1350
  if (geminiTools.length > 0) request.tools = geminiTools;
1283
1351
  if (geminiToolConfig) request.toolConfig = geminiToolConfig;
1284
1352
 
1285
- const mappedModel = applyModelAlias(input.model);
1353
+ const mappedModel = applyModelAlias(effortTarget);
1286
1354
 
1287
1355
  return {
1288
1356
  project: "compat-placeholder",
1289
1357
  model: mappedModel,
1290
- displayModel: input.model,
1358
+ displayModel: requestedModel,
1291
1359
  userAgent: "antigravity",
1292
1360
  requestType: "agent",
1293
1361
  request,
package/src/proxy.ts CHANGED
@@ -12,6 +12,8 @@ import {
12
12
  } from "node:http";
13
13
  import { Readable } from "node:stream";
14
14
  import {
15
+ classifyEffortRoutingModel,
16
+ getEffortRoutingRule,
15
17
  resolveQuotaModelKey,
16
18
  resolveDisplayModelKey,
17
19
  } from "./types.js";
@@ -108,6 +110,12 @@ export function providerAdapterForModel(
108
110
  ollamaModels: new Set(rotator?.getOllamaModels?.() ?? []),
109
111
  codexModels: new Set(rotator?.getCodexModels?.() ?? []),
110
112
  };
113
+ const effortRoutingKind = classifyEffortRoutingModel(model);
114
+ if (effortRoutingKind && context.ollamaModels.has(model)) {
115
+ proxyLogger.warn(
116
+ `Effort routing ${effortRoutingKind} "${model}" matches a live Ollama model; live provider dispatch wins`,
117
+ );
118
+ }
111
119
  const matched = findProviderForModel(model, context);
112
120
  if (matched) return matched;
113
121
  }
@@ -132,6 +140,22 @@ function routingModelKey(rotator: AccountRotator, model: string): string {
132
140
  }).resolveQuotaModelKeyForDisplay;
133
141
  return resolver?.call(rotator, model) ?? resolveQuotaModelKey(model) ?? model;
134
142
  }
143
+
144
+ function observedModelKey(
145
+ rotator: AccountRotator,
146
+ displayModel: string,
147
+ effectiveModel?: string,
148
+ ): string {
149
+ const rule = getEffortRoutingRule(displayModel);
150
+ const observedModel = effectiveModel && rule ? effectiveModel : displayModel;
151
+ const resolver = (rotator as unknown as {
152
+ resolveObservedModelKey?: (value: string) => string;
153
+ }).resolveObservedModelKey;
154
+ return (
155
+ resolver?.call(rotator, observedModel) ??
156
+ resolveDisplayModelKey(displayModel, effectiveModel)
157
+ );
158
+ }
135
159
  import { startVersionChecker, performSelfUpdate } from "./version-check.js";
136
160
  import { startNotificationPoller } from "./notification-poller.js";
137
161
  import {
@@ -1173,7 +1197,11 @@ export async function withRotation<T>(
1173
1197
 
1174
1198
  const label = account.config.label || account.config.email;
1175
1199
  const modelKey = routingModelKey(rotator, model);
1176
- const displayModelKey = resolveDisplayModelKey(body.displayModel || model);
1200
+ const displayModelKey = observedModelKey(
1201
+ rotator,
1202
+ body.displayModel || model,
1203
+ body.model,
1204
+ );
1177
1205
  const requestId = `${modelKey}-${Date.now().toString(36)}-${attempt + 1}`;
1178
1206
  const requestStartMs = Date.now();
1179
1207
  let accountReleased = false;
@@ -1609,7 +1637,7 @@ async function handleProxyRequest(
1609
1637
 
1610
1638
  const label = account.config.label || account.config.email;
1611
1639
  const modelKey = rotator.resolveQuotaModelKeyForDisplay(body.model) ?? body.model; // quota routing
1612
- const displayModelKey = resolveDisplayModelKey(body.model); // metrics/logs
1640
+ const displayModelKey = observedModelKey(rotator, body.model); // metrics/logs
1613
1641
  const requestId = `${modelKey}-${Date.now().toString(36)}-${attempt + 1}`;
1614
1642
  let accountReleased = false;
1615
1643
  const releaseCurrentAccount = (): void => {