tuxevil-rotator 3.0.0 → 3.2.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/CHANGELOG.md +37 -0
- package/README.md +20 -6
- package/package.json +1 -1
- package/src/account-store.ts +37 -5
- package/src/cli.ts +24 -3
- package/src/compat/model-specs.ts +1 -0
- package/src/compat.ts +540 -24
- package/src/config-normalize.ts +73 -30
- package/src/dashboard.ts +43 -42
- package/src/index.ts +1 -0
- package/src/onboarding.ts +349 -21
- package/src/providers/adapter.ts +18 -0
- package/src/providers/credential-helpers.ts +64 -0
- package/src/providers/google-antigravity/index.ts +9 -0
- package/src/providers/google-antigravity/quota.ts +2 -1
- package/src/providers/google-antigravity/translators.ts +83 -24
- package/src/providers/ollama/index.ts +8 -0
- package/src/providers/ollama/quota.ts +2 -1
- package/src/providers/openai-codex/catalog.ts +117 -0
- package/src/providers/openai-codex/compat.ts +556 -0
- package/src/providers/openai-codex/credentials.ts +82 -0
- package/src/providers/openai-codex/forward.ts +240 -0
- package/src/providers/openai-codex/index.ts +153 -0
- package/src/providers/openai-codex/login.ts +172 -0
- package/src/providers/openai-codex/oauth.ts +359 -0
- package/src/providers/openai-codex/quota.ts +231 -0
- package/src/providers/opencode-zen/catalog.ts +37 -0
- package/src/providers/opencode-zen/credentials.ts +31 -0
- package/src/providers/opencode-zen/forward.ts +214 -0
- package/src/providers/opencode-zen/index.ts +73 -0
- package/src/providers/opencode-zen/login.ts +81 -0
- package/src/providers/opencode-zen/quota.ts +67 -0
- package/src/providers/registry.ts +24 -5
- package/src/proxy.ts +75 -27
- package/src/rate-limit-parser.ts +2 -1
- package/src/rotator.ts +259 -48
- package/src/spend-logger.ts +2 -0
- package/src/static/dashboard-keys.js +152 -2
- package/src/static/dashboard.js +161 -37
- package/src/types.ts +83 -1
- package/src/validators.ts +11 -2
- package/tools/telemetry-receiver/receiver.js +14 -0
|
@@ -353,6 +353,14 @@ export function convertToolChoiceToGemini(
|
|
|
353
353
|
return { functionCallingConfig: { mode: "AUTO" } };
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
+
function forcesToolUse(toolChoice: unknown): boolean {
|
|
357
|
+
if (toolChoice === "required") return true;
|
|
358
|
+
return isRecord(toolChoice) &&
|
|
359
|
+
toolChoice.type === "function" &&
|
|
360
|
+
((isRecord(toolChoice.function) && isNonEmptyString(toolChoice.function.name)) ||
|
|
361
|
+
isNonEmptyString(toolChoice.name));
|
|
362
|
+
}
|
|
363
|
+
|
|
356
364
|
export function validateMessages(value: unknown): value is ChatMessage[] {
|
|
357
365
|
return (
|
|
358
366
|
Array.isArray(value) &&
|
|
@@ -828,6 +836,38 @@ export function convertResponsesToChatRequest(
|
|
|
828
836
|
};
|
|
829
837
|
}
|
|
830
838
|
|
|
839
|
+
/**
|
|
840
|
+
* Canonical model ID whose thinking level follows an OpenAI-style
|
|
841
|
+
* reasoning_effort. Matched case-insensitively against the exact ID only;
|
|
842
|
+
* virtual siblings (e.g. `gemini-3.7-flash-tiered-high`) are excluded.
|
|
843
|
+
*/
|
|
844
|
+
export const TIERED_EFFORT_MODEL_ID = "gemini-3.7-flash-tiered";
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Map an OpenAI Chat `reasoning_effort` to a Gemini `thinkingLevel` for
|
|
848
|
+
* `gemini-3.7-flash-tiered` only. Accepts exactly low/medium/high
|
|
849
|
+
* (case-insensitive); anything else returns undefined so the caller falls
|
|
850
|
+
* back to the existing adaptive/fixed-budget semantics and never emits an
|
|
851
|
+
* invalid upstream enum.
|
|
852
|
+
*/
|
|
853
|
+
export function mapTieredReasoningEffortToThinkingLevel(
|
|
854
|
+
effort: string | undefined,
|
|
855
|
+
modelId: string,
|
|
856
|
+
): "LOW" | "MEDIUM" | "HIGH" | undefined {
|
|
857
|
+
if (modelId.toLowerCase() !== TIERED_EFFORT_MODEL_ID) return undefined;
|
|
858
|
+
if (!isNonEmptyString(effort)) return undefined;
|
|
859
|
+
switch (effort.toLowerCase()) {
|
|
860
|
+
case "low":
|
|
861
|
+
return "LOW";
|
|
862
|
+
case "medium":
|
|
863
|
+
return "MEDIUM";
|
|
864
|
+
case "high":
|
|
865
|
+
return "HIGH";
|
|
866
|
+
default:
|
|
867
|
+
return undefined;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
831
871
|
export function openAIToAntigravityBody(
|
|
832
872
|
input: OpenAIChatCompletionRequest,
|
|
833
873
|
): RequestBody {
|
|
@@ -1089,26 +1129,27 @@ export function openAIToAntigravityBody(
|
|
|
1089
1129
|
}
|
|
1090
1130
|
}
|
|
1091
1131
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
role: "user",
|
|
1104
|
-
parts: [
|
|
1105
|
-
{
|
|
1106
|
-
text: "Continue from the previous assistant message. Do not repeat completed tool calls unless new user input asks for them.",
|
|
1107
|
-
},
|
|
1108
|
-
],
|
|
1109
|
-
});
|
|
1110
|
-
break;
|
|
1132
|
+
// Google rejects compatibility requests whose final contents turn is a
|
|
1133
|
+
// model turn. Claude additionally needs dangling tool-call turns removed;
|
|
1134
|
+
// other models keep the call history but still need a user turn to resume.
|
|
1135
|
+
while (contents.at(-1)?.role === "model") {
|
|
1136
|
+
const lastContent = contents.at(-1);
|
|
1137
|
+
const hasFunctionCall =
|
|
1138
|
+
lastContent?.parts.some((p: any) => isRecord(p) && p.functionCall) ??
|
|
1139
|
+
false;
|
|
1140
|
+
if (isClaude && hasFunctionCall) {
|
|
1141
|
+
contents.pop();
|
|
1142
|
+
continue;
|
|
1111
1143
|
}
|
|
1144
|
+
contents.push({
|
|
1145
|
+
role: "user",
|
|
1146
|
+
parts: [
|
|
1147
|
+
{
|
|
1148
|
+
text: "Continue from the previous assistant message. Do not repeat completed tool calls unless new user input asks for them.",
|
|
1149
|
+
},
|
|
1150
|
+
],
|
|
1151
|
+
});
|
|
1152
|
+
break;
|
|
1112
1153
|
}
|
|
1113
1154
|
|
|
1114
1155
|
if (contents.length === 0)
|
|
@@ -1135,7 +1176,7 @@ export function openAIToAntigravityBody(
|
|
|
1135
1176
|
}
|
|
1136
1177
|
|
|
1137
1178
|
let thinkingConfigObj: Record<string, unknown> | undefined;
|
|
1138
|
-
if (modelFamily === "claude" && isThinking) {
|
|
1179
|
+
if (modelFamily === "claude" && isThinking && !forcesToolUse(input.tool_choice)) {
|
|
1139
1180
|
const tb = modelSpec.thinkingBudget;
|
|
1140
1181
|
thinkingConfigObj = { include_thoughts: true, thinking_budget: tb };
|
|
1141
1182
|
if (!maxOutputTokens || maxOutputTokens <= tb) {
|
|
@@ -1144,12 +1185,30 @@ export function openAIToAntigravityBody(
|
|
|
1144
1185
|
`Adjusted Claude maxOutputTokens → ${maxOutputTokens}`,
|
|
1145
1186
|
);
|
|
1146
1187
|
}
|
|
1147
|
-
} else if (isThinking) {
|
|
1188
|
+
} else if (isThinking && modelFamily !== "claude") {
|
|
1148
1189
|
const tb = modelSpec.thinkingBudget;
|
|
1149
|
-
|
|
1190
|
+
// Only the exact tiered model selects its thinking level from an
|
|
1191
|
+
// OpenAI-style reasoning_effort, and only while its spec stays adaptive
|
|
1192
|
+
// (thinkingBudget === -1). A fixed budget — bundled or set by an operator
|
|
1193
|
+
// modelSpecs override — deterministically wins and is never combined
|
|
1194
|
+
// with thinkingLevel.
|
|
1195
|
+
const tieredThinkingLevel =
|
|
1150
1196
|
tb === -1
|
|
1151
|
-
?
|
|
1152
|
-
|
|
1197
|
+
? mapTieredReasoningEffortToThinkingLevel(
|
|
1198
|
+
input.reasoning_effort,
|
|
1199
|
+
input.model,
|
|
1200
|
+
)
|
|
1201
|
+
: undefined;
|
|
1202
|
+
if (tieredThinkingLevel) {
|
|
1203
|
+
thinkingConfigObj = {
|
|
1204
|
+
includeThoughts: true,
|
|
1205
|
+
thinkingLevel: tieredThinkingLevel,
|
|
1206
|
+
};
|
|
1207
|
+
} else if (tb === -1) {
|
|
1208
|
+
thinkingConfigObj = { includeThoughts: true };
|
|
1209
|
+
} else {
|
|
1210
|
+
thinkingConfigObj = { includeThoughts: true, thinkingBudget: tb };
|
|
1211
|
+
}
|
|
1153
1212
|
if (tb !== -1 && (!maxOutputTokens || maxOutputTokens <= tb)) {
|
|
1154
1213
|
maxOutputTokens = Math.min(tb + 8192, modelSpec.maxOutputTokens);
|
|
1155
1214
|
compatLogger.debug(
|
|
@@ -77,6 +77,14 @@ export const ollamaAdapter: ProviderAdapter = {
|
|
|
77
77
|
return quotaModelKey === "session" ? "gpt-oss:20b" : undefined;
|
|
78
78
|
},
|
|
79
79
|
|
|
80
|
+
ownsModel(model: string, context?: { ollamaModels?: Set<string> }): boolean {
|
|
81
|
+
return context?.ollamaModels?.has(model) ?? false;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
getPoolKey(): string {
|
|
85
|
+
return "session";
|
|
86
|
+
},
|
|
87
|
+
|
|
80
88
|
getBenchmark() {
|
|
81
89
|
return getBenchmarkSpec();
|
|
82
90
|
},
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
SESSION_WINDOW_MS,
|
|
16
16
|
} from "./usage-windows.js";
|
|
17
17
|
import { getAccountProxyDispatcher } from "../proxy-dispatcher.js";
|
|
18
|
+
import { sortQuotaPools } from "../registry.js";
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Poll `GET /api/usage` for one account and store the parsed pool quotas.
|
|
@@ -66,7 +67,7 @@ export async function fetchProviderUsage(
|
|
|
66
67
|
fresh.forEach(
|
|
67
68
|
(q) => ((q as { providerId?: string }).providerId = "ollama"),
|
|
68
69
|
);
|
|
69
|
-
account.quota = [...otherProviders, ...fresh];
|
|
70
|
+
account.quota = sortQuotaPools([...otherProviders, ...fresh]);
|
|
70
71
|
account.lastQuotaPoll = Date.now();
|
|
71
72
|
void recordUsagePoll(account.config.email, new Date().toISOString(), data);
|
|
72
73
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { AccountRuntime } from "../../types.js";
|
|
2
|
+
import { getAccountProxyDispatcher } from "../proxy-dispatcher.js";
|
|
3
|
+
import { getCodexAccountId, getCodexTokenState } from "./credentials.js";
|
|
4
|
+
import { codexBaseUrl } from "./forward.js";
|
|
5
|
+
import { CODEX_PROVIDER_ID } from "./oauth.js";
|
|
6
|
+
|
|
7
|
+
export interface CodexModel {
|
|
8
|
+
id: string;
|
|
9
|
+
contextWindow: number;
|
|
10
|
+
reasoning: boolean;
|
|
11
|
+
multimodal: boolean;
|
|
12
|
+
tools: boolean;
|
|
13
|
+
source: "allowlist" | "discovered";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Only models validated by the initial unauthenticated/public spike are in the
|
|
17
|
+
// safe base list. Authenticated discovery can add provider-owned GPT-5 IDs.
|
|
18
|
+
// The Codex /models endpoint can expose models from other ChatGPT-backed
|
|
19
|
+
// providers (for example Claude), so model IDs alone must be filtered before
|
|
20
|
+
// they influence routing.
|
|
21
|
+
const CODEX_CONTEXT_WINDOW = 272_000;
|
|
22
|
+
const CODEX_DISCOVERED_ID_PATTERN = /^gpt-5(?:\.\d+)?(?:-[a-z0-9]+)+$/i;
|
|
23
|
+
export const CODEX_BASE_MODELS: readonly CodexModel[] = [
|
|
24
|
+
{ id: "gpt-5.6-sol", contextWindow: CODEX_CONTEXT_WINDOW, reasoning: true, multimodal: true, tools: true, source: "allowlist" },
|
|
25
|
+
{ id: "gpt-5.6-terra", contextWindow: CODEX_CONTEXT_WINDOW, reasoning: true, multimodal: true, tools: true, source: "allowlist" },
|
|
26
|
+
{ id: "gpt-5.6-luna", contextWindow: CODEX_CONTEXT_WINDOW, reasoning: true, multimodal: true, tools: true, source: "allowlist" },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
let discoveredModels: CodexModel[] = [];
|
|
30
|
+
|
|
31
|
+
export function isCodexModel(model: string): boolean {
|
|
32
|
+
return getCodexModel(model) !== undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isCodexRequestModel(model: string): boolean {
|
|
36
|
+
return isCodexModel(model);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getCodexModel(model: string): CodexModel | undefined {
|
|
40
|
+
const normalized = model.trim().toLowerCase();
|
|
41
|
+
return [...discoveredModels, ...CODEX_BASE_MODELS].find(
|
|
42
|
+
(entry) => entry.id.toLowerCase() === normalized,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getCodexModels(): CodexModel[] {
|
|
47
|
+
const merged = new Map<string, CodexModel>();
|
|
48
|
+
for (const entry of [...CODEX_BASE_MODELS, ...discoveredModels]) merged.set(entry.id, entry);
|
|
49
|
+
return [...merged.values()];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isCodexProviderModelId(value: unknown): value is string {
|
|
53
|
+
return typeof value === "string" &&
|
|
54
|
+
isSafeModelId(value) &&
|
|
55
|
+
CODEX_DISCOVERED_ID_PATTERN.test(value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function setDiscoveredCodexModels(models: CodexModel[]): void {
|
|
59
|
+
discoveredModels = models.filter((model) => isCodexProviderModelId(model.id));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isSafeModelId(value: unknown): value is string {
|
|
63
|
+
return typeof value === "string" && /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(value);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseModel(value: unknown): CodexModel | null {
|
|
67
|
+
if (typeof value === "string") {
|
|
68
|
+
return isCodexProviderModelId(value)
|
|
69
|
+
? { id: value, contextWindow: CODEX_CONTEXT_WINDOW, reasoning: true, multimodal: true, tools: true, source: "discovered" }
|
|
70
|
+
: null;
|
|
71
|
+
}
|
|
72
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
73
|
+
const record = value as Record<string, unknown>;
|
|
74
|
+
const id = record.id ?? record.model ?? record.name;
|
|
75
|
+
if (!isCodexProviderModelId(id)) return null;
|
|
76
|
+
const contextWindow = [record.context_window, record.contextWindow, record.context_length]
|
|
77
|
+
.find((candidate) => typeof candidate === "number" && Number.isFinite(candidate) && candidate > 0);
|
|
78
|
+
return {
|
|
79
|
+
id,
|
|
80
|
+
contextWindow: typeof contextWindow === "number" ? Math.min(contextWindow, 2_000_000) : CODEX_CONTEXT_WINDOW,
|
|
81
|
+
reasoning: record.reasoning !== false,
|
|
82
|
+
multimodal: record.multimodal !== false && record.vision !== false,
|
|
83
|
+
tools: record.tools !== false && record.tool_calling !== false,
|
|
84
|
+
source: "discovered",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function fetchCodexCatalog(
|
|
89
|
+
account: AccountRuntime,
|
|
90
|
+
signal?: AbortSignal,
|
|
91
|
+
): Promise<CodexModel[]> {
|
|
92
|
+
const token = getCodexTokenState(account).accessToken;
|
|
93
|
+
if (!token) return getCodexModels();
|
|
94
|
+
const base = codexBaseUrl();
|
|
95
|
+
const endpoint = base.endsWith("/models") ? base : `${base}/models`;
|
|
96
|
+
try {
|
|
97
|
+
const headers: Record<string, string> = {
|
|
98
|
+
Authorization: `Bearer ${token}`,
|
|
99
|
+
Accept: "application/json",
|
|
100
|
+
};
|
|
101
|
+
const accountId = getCodexAccountId(account.config);
|
|
102
|
+
if (accountId) headers["chatgpt-account-id"] = accountId;
|
|
103
|
+
const response = await fetch(endpoint, {
|
|
104
|
+
headers,
|
|
105
|
+
signal: signal ?? AbortSignal.timeout(8_000),
|
|
106
|
+
dispatcher: getAccountProxyDispatcher(account, CODEX_PROVIDER_ID),
|
|
107
|
+
} as RequestInit & { dispatcher?: unknown });
|
|
108
|
+
if (!response.ok) return getCodexModels();
|
|
109
|
+
const data = await response.json() as Record<string, unknown>;
|
|
110
|
+
const raw = Array.isArray(data.data) ? data.data : Array.isArray(data.models) ? data.models : [];
|
|
111
|
+
const parsed = raw.map(parseModel).filter((model): model is CodexModel => model !== null);
|
|
112
|
+
if (parsed.length > 0) setDiscoveredCodexModels(parsed);
|
|
113
|
+
} catch {
|
|
114
|
+
// Discovery is optional; the safe allowlist remains available.
|
|
115
|
+
}
|
|
116
|
+
return getCodexModels();
|
|
117
|
+
}
|