tuxevil-rotator 3.6.0 → 3.7.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/src/types.ts CHANGED
@@ -149,6 +149,15 @@ export interface Config {
149
149
  // (e.g. "gemini-3.1-pro-high") to the upstream Antigravity name
150
150
  // (e.g. "gemini-pro-agent"). When set, replaces the bundled defaults.
151
151
  modelAliases?: Record<string, string>;
152
+ // Config-driven alias routing based on reasoning_effort.
153
+ // Absent, null, or empty object = disabled.
154
+ effortRouting?: Record<string, EffortRoutingRule> | null;
155
+ }
156
+
157
+ export interface EffortRoutingRule {
158
+ /** Effort key used when the request carries no recognizable effort. Defaults to "medium". */
159
+ defaultEffort?: string;
160
+ targets: Record<string, string>;
152
161
  }
153
162
 
154
163
  export const DEFAULT_QUOTA_POLL_INTERVAL_MS = 300_000;
@@ -162,8 +171,18 @@ export const MAX_QUOTA_POLL_INTERVAL_MS = 24 * 60 * 60 * 1000;
162
171
  const DEFAULT_MODEL_ALIASES: Record<string, string> = {
163
172
  "gemini-3.1-pro-high": "gemini-pro-agent",
164
173
  "gpt-oss-120b": "gpt-oss-120b-medium",
174
+ "whisper-1": "models/proactive-observer-v10",
175
+ "proactive-observer": "models/proactive-observer-v10",
176
+ "proactive-observer-v10": "models/proactive-observer-v10",
165
177
  };
166
178
  let modelAliasesOverride: Record<string, string> | null = null;
179
+ type StoredEffortRoutingRule = {
180
+ defaultEffort: string;
181
+ targets: Record<string, string>;
182
+ };
183
+ type EffortRoutingModelKind = "alias" | "target";
184
+
185
+ let effortRoutingOverride: Record<string, StoredEffortRoutingRule> | null = null;
167
186
 
168
187
  /**
169
188
  * Replace the bundled model-alias table with operator-provided overrides.
@@ -180,6 +199,65 @@ export function setModelAliasesOverride(
180
199
  aliases && Object.keys(aliases).length > 0 ? aliases : null;
181
200
  }
182
201
 
202
+ export function setEffortRoutingOverride(
203
+ rules: Record<string, EffortRoutingRule> | null | undefined,
204
+ ): void {
205
+ if (!rules || Object.keys(rules).length === 0) {
206
+ effortRoutingOverride = null;
207
+ return;
208
+ }
209
+ const normalized = Object.create(null) as Record<
210
+ string,
211
+ StoredEffortRoutingRule
212
+ >;
213
+ for (const [rawAlias, rule] of Object.entries(rules)) {
214
+ const alias = rawAlias.trim().toLowerCase();
215
+ const defaultEffort = rule.defaultEffort?.trim().toLowerCase() || "medium";
216
+ const targets = Object.create(null) as Record<string, string>;
217
+ for (const [effortKey, targetValue] of Object.entries(rule.targets ?? {})) {
218
+ targets[effortKey.trim().toLowerCase()] =
219
+ typeof targetValue === "string" ? targetValue.trim() : targetValue;
220
+ }
221
+ normalized[alias] = {
222
+ defaultEffort,
223
+ targets,
224
+ };
225
+ }
226
+ effortRoutingOverride = normalized;
227
+ }
228
+
229
+ export function getEffortRouting(): Record<string, StoredEffortRoutingRule> | null {
230
+ return effortRoutingOverride;
231
+ }
232
+
233
+ export function getEffortRoutingRule(
234
+ requestedModel: string,
235
+ ): StoredEffortRoutingRule | undefined {
236
+ const rules = effortRoutingOverride;
237
+ if (!rules) return undefined;
238
+ const alias = requestedModel.trim().toLowerCase();
239
+ return Object.hasOwn(rules, alias) ? rules[alias] : undefined;
240
+ }
241
+
242
+ export function classifyEffortRoutingModel(
243
+ model: string,
244
+ ): EffortRoutingModelKind | null {
245
+ const rules = effortRoutingOverride;
246
+ if (!rules) return null;
247
+ const normalizedModel = model.trim().toLowerCase();
248
+ if (Object.hasOwn(rules, normalizedModel)) return "alias";
249
+ for (const rule of Object.values(rules)) {
250
+ if (
251
+ Object.values(rule.targets).some(
252
+ (target) => target.toLowerCase() === normalizedModel,
253
+ )
254
+ ) {
255
+ return "target";
256
+ }
257
+ }
258
+ return null;
259
+ }
260
+
183
261
  function getActiveModelAliases(): Record<string, string> {
184
262
  return modelAliasesOverride ?? DEFAULT_MODEL_ALIASES;
185
263
  }
@@ -190,7 +268,7 @@ function getActiveModelAliases(): Record<string, string> {
190
268
  */
191
269
  export function applyModelAlias(model: string): string {
192
270
  const aliases = getActiveModelAliases();
193
- if (model in aliases) return aliases[model];
271
+ if (Object.hasOwn(aliases, model)) return aliases[model];
194
272
  const lower = model.toLowerCase();
195
273
  for (const [from, to] of Object.entries(aliases)) {
196
274
  if (from.toLowerCase() === lower) return to;
@@ -332,7 +410,17 @@ export function resolveQuotaModelKey(requestModel: string): string | null {
332
410
  * - gemini-3.1-pro-low vs gemini-3.1-pro-high (same quota pool, different display)
333
411
  * - claude-sonnet-4-6 vs claude-opus-4-6-thinking (different pricing)
334
412
  */
335
- export function resolveDisplayModelKey(requestModel: string): string {
413
+ export function resolveDisplayModelKey(
414
+ requestModel: string,
415
+ effectiveModel?: string,
416
+ ): string {
417
+ if (
418
+ effectiveModel &&
419
+ effectiveModel !== requestModel &&
420
+ getEffortRoutingRule(requestModel)
421
+ ) {
422
+ return resolveDisplayModelKey(effectiveModel);
423
+ }
336
424
  const lower = requestModel.toLowerCase();
337
425
  // Explicit agent and gpt-oss overrides
338
426
  if (lower.includes("gemini-3-flash-agent")) return "gemini-3-flash";
package/src/validators.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  MAX_QUOTA_POLL_INTERVAL_MS,
3
3
  MIN_QUOTA_POLL_INTERVAL_MS,
4
+ MODEL_TIER_ACCESS,
4
5
  type AccountConfig,
5
6
  type Config,
6
7
  } from "./types.js";
7
8
  import { getProxyConfigurationError } from "./providers/proxy-dispatcher.js";
9
+ import { isCodexRequestModel } from "./providers/openai-codex/catalog.js";
10
+ import { isOpenCodeZenModel } from "./providers/opencode-zen/catalog.js";
8
11
 
9
12
  export interface ValidationResult<T> {
10
13
  ok: boolean;
@@ -40,6 +43,15 @@ function isNonNegativeInteger(value: unknown): value is number {
40
43
  return isNonNegativeNumber(value) && Number.isInteger(value);
41
44
  }
42
45
 
46
+ function isKnownNonGoogleModel(model: string): boolean {
47
+ const trimmed = model.trim();
48
+ if (!trimmed) return false;
49
+ const lower = trimmed.toLowerCase();
50
+ if (isCodexRequestModel(trimmed)) return true;
51
+ if (isOpenCodeZenModel(trimmed) || isOpenCodeZenModel(lower)) return true;
52
+ return Object.keys(MODEL_TIER_ACCESS).some((k) => k.toLowerCase() === lower);
53
+ }
54
+
43
55
  export function validateAccountConfig(value: unknown, path = "account"): ValidationResult<AccountConfig> {
44
56
  if (!isRecord(value)) return fail([`${path} must be an object`]);
45
57
  const errors: string[] = [];
@@ -200,6 +212,98 @@ export function validateConfig(value: unknown): ValidationResult<Config> {
200
212
  }
201
213
  }
202
214
  }
215
+ if (value.effortRouting !== undefined && value.effortRouting !== null) {
216
+ if (!isRecord(value.effortRouting)) {
217
+ errors.push("config.effortRouting must be an object or null when provided");
218
+ } else {
219
+ const seenAliasKeys = new Map<string, string>();
220
+ for (const rawAlias of Object.keys(value.effortRouting)) {
221
+ if (typeof rawAlias !== "string" || rawAlias.trim().length === 0) {
222
+ errors.push("config.effortRouting keys must be non-empty strings");
223
+ continue;
224
+ }
225
+ const lowerAlias = rawAlias.trim().toLowerCase();
226
+ const prev = seenAliasKeys.get(lowerAlias);
227
+ if (prev !== undefined) {
228
+ errors.push(`config.effortRouting keys collide case-insensitively: "${prev}" / "${rawAlias}"`);
229
+ } else {
230
+ seenAliasKeys.set(lowerAlias, rawAlias);
231
+ }
232
+ }
233
+
234
+ const modelAliasesRecord = isRecord(value.modelAliases) ? value.modelAliases : null;
235
+
236
+ for (const [rawAlias, rule] of Object.entries(value.effortRouting)) {
237
+ if (typeof rawAlias !== "string" || rawAlias.trim().length === 0) {
238
+ continue;
239
+ }
240
+ const lowerAlias = rawAlias.trim().toLowerCase();
241
+
242
+ if (isKnownNonGoogleModel(rawAlias)) {
243
+ errors.push(`config.effortRouting.${rawAlias} collides with non-Antigravity model "${rawAlias}"`);
244
+ }
245
+
246
+ if (modelAliasesRecord) {
247
+ for (const maKey of Object.keys(modelAliasesRecord)) {
248
+ if (maKey.trim().toLowerCase() === lowerAlias) {
249
+ errors.push(`config.effortRouting.${rawAlias} conflicts with config.modelAliases entry of the same name`);
250
+ break;
251
+ }
252
+ }
253
+ }
254
+
255
+ if (!isRecord(rule)) {
256
+ errors.push(`config.effortRouting.${rawAlias} must be an object`);
257
+ continue;
258
+ }
259
+
260
+ if (rule.defaultEffort !== undefined && typeof rule.defaultEffort !== "string") {
261
+ errors.push(`config.effortRouting.${rawAlias}.defaultEffort must be a string when provided`);
262
+ }
263
+
264
+ if (!("targets" in rule) || !isRecord(rule.targets)) {
265
+ errors.push(`config.effortRouting.${rawAlias}.targets must be an object`);
266
+ continue;
267
+ }
268
+
269
+ const seenEffortKeys = new Map<string, string>();
270
+ for (const [rawEffort, targetValue] of Object.entries(rule.targets)) {
271
+ if (typeof rawEffort !== "string" || rawEffort.trim().length === 0) {
272
+ errors.push(`config.effortRouting.${rawAlias}.targets keys must be non-empty strings`);
273
+ } else {
274
+ const lowerEffort = rawEffort.trim().toLowerCase();
275
+ const prevEffort = seenEffortKeys.get(lowerEffort);
276
+ if (prevEffort !== undefined) {
277
+ errors.push(`config.effortRouting.${rawAlias}.targets keys collide case-insensitively: "${prevEffort}" / "${rawEffort}"`);
278
+ } else {
279
+ seenEffortKeys.set(lowerEffort, rawEffort);
280
+ }
281
+ }
282
+
283
+ if (typeof targetValue !== "string" || targetValue.trim().length === 0) {
284
+ errors.push(`config.effortRouting.${rawAlias}.targets.${rawEffort} must be a non-empty string`);
285
+ } else {
286
+ if (seenAliasKeys.has(targetValue.trim().toLowerCase())) {
287
+ errors.push(`config.effortRouting.${rawAlias}.targets.${rawEffort} chains into effort-routing alias "${targetValue}" (not supported)`);
288
+ }
289
+ if (isKnownNonGoogleModel(targetValue)) {
290
+ errors.push(`config.effortRouting.${rawAlias} collides with non-Antigravity model "${targetValue}"`);
291
+ }
292
+ }
293
+ }
294
+
295
+ if (rule.defaultEffort === undefined || typeof rule.defaultEffort === "string") {
296
+ const effectiveDefault = rule.defaultEffort !== undefined ? rule.defaultEffort : "medium";
297
+ const hasEffectiveDefault = Object.keys(rule.targets).some(
298
+ (k) => k.trim().toLowerCase() === effectiveDefault.trim().toLowerCase(),
299
+ );
300
+ if (!hasEffectiveDefault) {
301
+ errors.push(`config.effortRouting.${rawAlias} default effort "${effectiveDefault}" has no matching target`);
302
+ }
303
+ }
304
+ }
305
+ }
306
+ }
203
307
 
204
308
  return errors.length > 0 ? fail(errors) : ok(value as unknown as Config);
205
309
  }