tuxevil-rotator 3.0.0 → 3.1.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 +14 -0
- package/README.md +7 -3
- package/package.json +1 -1
- package/src/account-store.ts +35 -3
- package/src/cli.ts +24 -3
- package/src/compat.ts +83 -1
- package/src/config-normalize.ts +67 -30
- package/src/index.ts +1 -0
- package/src/onboarding.ts +232 -21
- package/src/providers/adapter.ts +11 -0
- package/src/providers/credential-helpers.ts +7 -0
- package/src/providers/google-antigravity/translators.ts +30 -21
- 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 +142 -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 +219 -0
- package/src/providers/opencode-zen/catalog.ts +39 -0
- package/src/providers/opencode-zen/credentials.ts +31 -0
- package/src/providers/opencode-zen/forward.ts +199 -0
- package/src/providers/opencode-zen/index.ts +64 -0
- package/src/providers/opencode-zen/login.ts +81 -0
- package/src/providers/opencode-zen/quota.ts +66 -0
- package/src/providers/registry.ts +2 -1
- package/src/proxy.ts +73 -10
- package/src/rotator.ts +238 -38
- package/src/static/dashboard.js +125 -21
- package/src/types.ts +62 -1
- package/src/validators.ts +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.1.0] - 2026-08-12
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **OpenAI Codex OAuth provider**: Support for OpenAI Codex authentication and accounts (`gpt-5.6-codex`, `gpt-5.6-codex-mini`, `gpt-5.6-codex-max`, `codex-sol-4-6`).
|
|
7
|
+
- **Web & CLI OAuth login**: Integrated Codex provider tab in `/login` and `/login-cli` for PKCE OAuth authentication.
|
|
8
|
+
- **Codex pricing & dashboard visualizer**: Added cost tracking and yellow color spectrum mapping for Codex GPT-5.6 models in token usage charts.
|
|
9
|
+
- **Tool calling translation & compat**: Tool calls and chat completions automatically translate between OpenAI Codex and proxy formats.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **Provider catalog isolation**: Prevented non-Codex and Google models from polluting Codex discovery routing.
|
|
13
|
+
- **Isolated provider kickstarts**: Provider kickstart pools operate independently without triggering unneeded OAuth refresh flows.
|
|
14
|
+
- **Codex usage & spend tracking**: Fixed recording of usage and spend for Codex compat requests.
|
|
15
|
+
- **Gemini turn bug fix**: Prevented model-ending compat requests for Gemini models.
|
|
16
|
+
|
|
3
17
|
## [3.0.0] - 2026-08-11
|
|
4
18
|
|
|
5
19
|
### Changed
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://github.com/tuxevil/tuxevil-rotator/actions)
|
|
7
7
|
[](https://www.typescriptlang.org)
|
|
8
|
-
[](https://github.com/tuxevil/tuxevil-rotator/pkgs/container/tuxevil-rotator)
|
|
9
9
|
[](https://github.com/tuxevil/tuxevil-rotator/stargazers)
|
|
10
10
|
|
|
11
11
|
[](https://telemetry.tuxevil.com/v1/public-stats)
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
|
|
25
25
|
**Production-ready OpenAI-compatible gateway for multiple free-tier LLM providers.**
|
|
26
26
|
|
|
27
|
+
> **Container migration notice:** `ghcr.io/tuxevil/pi-antigravity-rotator` is deprecated. Use [`ghcr.io/tuxevil/tuxevil-rotator:latest`](https://github.com/tuxevil/tuxevil-rotator/pkgs/container/tuxevil-rotator) for new deployments. The legacy image remains available as a frozen compatibility reference; see the [migration guide](docs/migrating-from-pi-antigravity-rotator.md).
|
|
28
|
+
|
|
27
29
|
Multi-account load balancing, per-model quota routing, account health scoring, access control with Virtual Keys, and cost auditing — via a single local endpoint that any agent can use. Even with a single account.
|
|
28
30
|
|
|
29
31
|
Originally built as a multi-account rotator for Google Antigravity. It now generalizes that rotation layer across any free-tier LLM provider with per-account credentials: today Google Antigravity and Ollama Cloud, designed so the next free-tier provider slots in without forking the engine.
|
|
@@ -58,8 +60,8 @@ Originally built as a multi-account rotator for Google Antigravity. It now gener
|
|
|
58
60
|
|
|
59
61
|
## v2.7 Highlights
|
|
60
62
|
|
|
61
|
-
- **Multi-Provider Support**: The rotator
|
|
62
|
-
- **
|
|
63
|
+
- **Multi-Provider Support**: The rotator routes through Google Antigravity, Ollama Cloud, and an isolated OpenAI Codex OAuth pool, with per-provider model catalog resolution and no automatic cross-provider fallback.
|
|
64
|
+
- **Provider Compatibility**: Ollama models use native `api/chat` NDJSON, while Codex models use native Responses HTTP/SSE with explicit Chat Completions conversion. `GET /v1/models` marks provider ownership for both catalogs.
|
|
63
65
|
- **Legacy Account Migration**: On startup, Ollama Cloud accounts from `~/.ollama-rotator/accounts.json` (the predecessor product, overridable via `OLLAMA_ROTATOR_DIR`) are imported automatically and merged onto the matching email — `provider: "ollama"`, preserving `label`/`tier`/`type`. Re-import is idempotent.
|
|
64
66
|
- **Flat-shape compatibility**: Existing configs with the legacy flat field layout (`apiKey`/`refreshToken` at the top level) are still accepted and normalized on load to the parent-account credential model.
|
|
65
67
|
|
|
@@ -142,6 +144,7 @@ Existing `enc:v1` records remain decryptable during migration; newly written rec
|
|
|
142
144
|
npm install -g tuxevil-rotator
|
|
143
145
|
tuxevil-rotator login # Google Antigravity (default)
|
|
144
146
|
tuxevil-rotator login --provider ollama # Ollama Cloud (static API key)
|
|
147
|
+
tuxevil-rotator login --provider openai-codex # ChatGPT OAuth (isolated Codex pool)
|
|
145
148
|
tuxevil-rotator start
|
|
146
149
|
```
|
|
147
150
|
|
|
@@ -172,6 +175,7 @@ cd tuxevil-rotator
|
|
|
172
175
|
npm install
|
|
173
176
|
npm run login # Google Antigravity
|
|
174
177
|
npm run login -- --provider ollama # Ollama Cloud
|
|
178
|
+
npm run login -- --provider openai-codex # OpenAI Codex OAuth
|
|
175
179
|
npm start
|
|
176
180
|
```
|
|
177
181
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuxevil-rotator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Multi-provider, multi-account AI proxy rotator with per-model routing, real-time quota tracking, and infringement detection (Google Antigravity, Ollama Cloud)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/account-store.ts
CHANGED
|
@@ -43,6 +43,7 @@ export const MAX_LABEL_LENGTH = 100;
|
|
|
43
43
|
export const MAX_PROJECT_ID_LENGTH = 100;
|
|
44
44
|
export const MAX_REFRESH_TOKEN_LENGTH = 4096;
|
|
45
45
|
export const MAX_PROXY_URL_LENGTH = 2048;
|
|
46
|
+
export const MAX_PROVIDER_ACCOUNT_ID_LENGTH = 256;
|
|
46
47
|
|
|
47
48
|
function validateAccountConfigLengths(entry: AccountConfig): void {
|
|
48
49
|
const checks: Array<[string, number]> = [
|
|
@@ -50,6 +51,8 @@ function validateAccountConfigLengths(entry: AccountConfig): void {
|
|
|
50
51
|
["label", MAX_LABEL_LENGTH],
|
|
51
52
|
["projectId", MAX_PROJECT_ID_LENGTH],
|
|
52
53
|
["refreshToken", MAX_REFRESH_TOKEN_LENGTH],
|
|
54
|
+
["codexRefreshToken", MAX_REFRESH_TOKEN_LENGTH],
|
|
55
|
+
["codexAccountId", MAX_PROVIDER_ACCOUNT_ID_LENGTH],
|
|
53
56
|
["proxyUrl", MAX_PROXY_URL_LENGTH],
|
|
54
57
|
];
|
|
55
58
|
for (const [field, max] of checks) {
|
|
@@ -81,6 +84,9 @@ function validateCredentialLengths(
|
|
|
81
84
|
if (typeof cred.proxyUrl === "string" && cred.proxyUrl.length > MAX_PROXY_URL_LENGTH) {
|
|
82
85
|
throw new Error(`Credential proxyUrl for ${cred.provider} exceeds maximum length`);
|
|
83
86
|
}
|
|
87
|
+
if (typeof cred.providerAccountId === "string" && cred.providerAccountId.length > MAX_PROVIDER_ACCOUNT_ID_LENGTH) {
|
|
88
|
+
throw new Error(`Credential providerAccountId for ${cred.provider} exceeds maximum length`);
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
|
|
@@ -91,23 +97,49 @@ function mergeCredentials(
|
|
|
91
97
|
incoming: AccountConfig["credentials"] | undefined,
|
|
92
98
|
): AccountConfig["credentials"] {
|
|
93
99
|
const out: NonNullable<AccountConfig["credentials"]> = [];
|
|
100
|
+
const incomingByProvider = new Map((incoming ?? []).map((cred) => [cred.provider, cred]));
|
|
94
101
|
const seen = new Set<string>();
|
|
95
|
-
for (const cred of
|
|
102
|
+
for (const cred of existing ?? []) {
|
|
96
103
|
if (seen.has(cred.provider)) continue;
|
|
97
104
|
seen.add(cred.provider);
|
|
98
|
-
|
|
105
|
+
const incomingCredential = incomingByProvider.get(cred.provider);
|
|
106
|
+
out.push(incomingCredential ? { ...cred, ...incomingCredential } : cred);
|
|
107
|
+
incomingByProvider.delete(cred.provider);
|
|
99
108
|
}
|
|
109
|
+
for (const cred of incomingByProvider.values()) out.push(cred);
|
|
100
110
|
return out;
|
|
101
111
|
}
|
|
102
112
|
|
|
113
|
+
function assertCodexIdentityCompatible(
|
|
114
|
+
existing: AccountConfig,
|
|
115
|
+
incoming: AccountConfig,
|
|
116
|
+
): void {
|
|
117
|
+
const existingCredential = normalizeAccountConfig(existing).credentials?.find(
|
|
118
|
+
(credential) => credential.provider === "openai-codex",
|
|
119
|
+
);
|
|
120
|
+
const incomingCredential = incoming.credentials?.find(
|
|
121
|
+
(credential) => credential.provider === "openai-codex",
|
|
122
|
+
);
|
|
123
|
+
const oldId = existingCredential?.providerAccountId;
|
|
124
|
+
const newId = incomingCredential?.providerAccountId;
|
|
125
|
+
if (oldId && newId && oldId !== newId) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Codex credential conflict for ${incoming.email}: the email is already bound to a different providerAccountId; refusing to overwrite it`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
103
132
|
export async function addAccountToConfig(
|
|
104
133
|
entry: AccountConfig,
|
|
105
134
|
): Promise<{ isNew: boolean }> {
|
|
106
135
|
validateAccountConfigLengths(entry);
|
|
107
136
|
const entryNorm = normalizeAccountConfig(entry);
|
|
108
137
|
const config = loadOrCreateAccountsConfig();
|
|
109
|
-
const existing = config.accounts.find(
|
|
138
|
+
const existing = config.accounts.find(
|
|
139
|
+
(a) => a.email === entryNorm.email || a.email.toLowerCase() === entryNorm.email.toLowerCase(),
|
|
140
|
+
);
|
|
110
141
|
if (existing) {
|
|
142
|
+
assertCodexIdentityCompatible(existing, entryNorm);
|
|
111
143
|
validateCredentialLengths(entryNorm.credentials);
|
|
112
144
|
config.accounts[config.accounts.indexOf(existing)] = {
|
|
113
145
|
...normalizeAccountConfig(existing),
|
package/src/cli.ts
CHANGED
|
@@ -46,8 +46,28 @@ switch (command) {
|
|
|
46
46
|
providerFlag >= 0 && process.argv[providerFlag + 1]
|
|
47
47
|
? process.argv[providerFlag + 1]
|
|
48
48
|
: undefined;
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
const importFlag = process.argv.indexOf("--import");
|
|
50
|
+
if (providerId === "openai-codex" && importFlag >= 0) {
|
|
51
|
+
const importPath = process.argv[importFlag + 1];
|
|
52
|
+
if (!importPath || importPath.startsWith("--")) {
|
|
53
|
+
console.error("Usage: tuxevil-rotator login --provider openai-codex --import <auth.json>");
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
const { addAccountToConfig } = await import("./account-store.js");
|
|
58
|
+
const { importCodexAuthFile } = await import("./providers/openai-codex/login.js");
|
|
59
|
+
try {
|
|
60
|
+
const imported = await importCodexAuthFile(importPath);
|
|
61
|
+
const { isNew } = await addAccountToConfig(imported.account);
|
|
62
|
+
console.log(` ${isNew ? "Added" : "Updated"} ${imported.account.email} in Codex provider credentials`);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error(`Codex import failed: ${err instanceof Error ? err.message : "invalid auth.json"}`);
|
|
65
|
+
process.exitCode = 1;
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
const { runLogin } = await import("./login.js");
|
|
69
|
+
await runLogin(providerId);
|
|
70
|
+
}
|
|
51
71
|
break;
|
|
52
72
|
}
|
|
53
73
|
case "import": {
|
|
@@ -255,7 +275,8 @@ switch (command) {
|
|
|
255
275
|
console.log();
|
|
256
276
|
console.log("Usage:");
|
|
257
277
|
console.log(" tuxevil-rotator start Start the proxy (default)");
|
|
258
|
-
console.log(" tuxevil-rotator login Add
|
|
278
|
+
console.log(" tuxevil-rotator login Add an account (use --provider openai-codex for Codex OAuth)");
|
|
279
|
+
console.log(" tuxevil-rotator login --provider openai-codex --import <auth.json>");
|
|
259
280
|
console.log(
|
|
260
281
|
" tuxevil-rotator import Import Google/Pi accounts from JSON (default: ~/.config/antigravity/accounts.json)",
|
|
261
282
|
);
|
package/src/compat.ts
CHANGED
|
@@ -67,6 +67,8 @@ import {
|
|
|
67
67
|
anthropicToOllamaBody,
|
|
68
68
|
parseOllamaNdjson,
|
|
69
69
|
} from "./providers/ollama/translators.js";
|
|
70
|
+
import { OPENCODE_ZEN_CATALOG } from "./providers/opencode-zen/catalog.js";
|
|
71
|
+
import { OPENCODE_ZEN_PROVIDER_ID } from "./providers/opencode-zen/index.js";
|
|
70
72
|
import type {
|
|
71
73
|
ChatMessage,
|
|
72
74
|
OpenAITool,
|
|
@@ -78,6 +80,22 @@ import type {
|
|
|
78
80
|
CompatCompletion,
|
|
79
81
|
ResponsesConversionResult,
|
|
80
82
|
} from "./providers/google-antigravity/translators.js";
|
|
83
|
+
import {
|
|
84
|
+
isCodexRequestModel,
|
|
85
|
+
isCodexProviderModelId,
|
|
86
|
+
getCodexModels,
|
|
87
|
+
} from "./providers/openai-codex/catalog.js";
|
|
88
|
+
import { serveCodexChat, serveCodexResponses } from "./providers/openai-codex/compat.js";
|
|
89
|
+
|
|
90
|
+
function isCodexModelForRotator(rotator: AccountRotator, model: string): boolean {
|
|
91
|
+
if (isCodexRequestModel(model)) return true;
|
|
92
|
+
if (!isCodexProviderModelId(model)) return false;
|
|
93
|
+
try {
|
|
94
|
+
return rotator.getCodexModels?.().includes(model) ?? false;
|
|
95
|
+
} catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
81
99
|
|
|
82
100
|
export {
|
|
83
101
|
isRecord,
|
|
@@ -100,6 +118,7 @@ export {
|
|
|
100
118
|
validateOpenAIChatCompletionRequest,
|
|
101
119
|
validateOpenAIResponsesRequest,
|
|
102
120
|
validateAnthropicMessagesRequest,
|
|
121
|
+
isCodexModelForRotator,
|
|
103
122
|
};
|
|
104
123
|
export type {
|
|
105
124
|
ModelSpec,
|
|
@@ -1683,7 +1702,31 @@ export function serveOpenAIModels(
|
|
|
1683
1702
|
},
|
|
1684
1703
|
}),
|
|
1685
1704
|
);
|
|
1686
|
-
const
|
|
1705
|
+
const hasActiveProvider = (providerId: string): boolean =>
|
|
1706
|
+
rotator?.hasActiveProvider(providerId) ?? false;
|
|
1707
|
+
const ollamaModels = hasActiveProvider("ollama")
|
|
1708
|
+
? rotator?.getOllamaModels?.() ?? []
|
|
1709
|
+
: [];
|
|
1710
|
+
if (hasActiveProvider("openai-codex")) {
|
|
1711
|
+
for (const model of getCodexModels()) {
|
|
1712
|
+
catalog.push({
|
|
1713
|
+
id: model.id,
|
|
1714
|
+
object: "model",
|
|
1715
|
+
created: 0,
|
|
1716
|
+
owned_by: "openai-codex",
|
|
1717
|
+
context_window: model.contextWindow,
|
|
1718
|
+
max_model_len: model.contextWindow,
|
|
1719
|
+
meta: {
|
|
1720
|
+
context_length: model.contextWindow,
|
|
1721
|
+
family: "openai-codex",
|
|
1722
|
+
provider: "openai-codex",
|
|
1723
|
+
reasoning: model.reasoning,
|
|
1724
|
+
multimodal: model.multimodal,
|
|
1725
|
+
tool_calling: model.tools,
|
|
1726
|
+
},
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1687
1730
|
for (const id of ollamaModels) {
|
|
1688
1731
|
catalog.push({
|
|
1689
1732
|
id,
|
|
@@ -1701,6 +1744,25 @@ export function serveOpenAIModels(
|
|
|
1701
1744
|
},
|
|
1702
1745
|
});
|
|
1703
1746
|
}
|
|
1747
|
+
if (hasActiveProvider(OPENCODE_ZEN_PROVIDER_ID)) {
|
|
1748
|
+
for (const spec of OPENCODE_ZEN_CATALOG) {
|
|
1749
|
+
catalog.push({
|
|
1750
|
+
id: spec.id,
|
|
1751
|
+
object: "model",
|
|
1752
|
+
created: 0,
|
|
1753
|
+
owned_by: OPENCODE_ZEN_PROVIDER_ID,
|
|
1754
|
+
context_window: spec.contextWindow,
|
|
1755
|
+
max_model_len: spec.contextWindow,
|
|
1756
|
+
meta: {
|
|
1757
|
+
context_length: spec.contextWindow,
|
|
1758
|
+
family: "opencode-zen",
|
|
1759
|
+
provider: OPENCODE_ZEN_PROVIDER_ID,
|
|
1760
|
+
multimodal: false,
|
|
1761
|
+
tool_calling: true,
|
|
1762
|
+
},
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1704
1766
|
writeJson(res, 200, { object: "list", data: catalog });
|
|
1705
1767
|
}
|
|
1706
1768
|
|
|
@@ -1865,6 +1927,16 @@ export async function handleOpenAIChatCompletions(
|
|
|
1865
1927
|
}
|
|
1866
1928
|
const apiKeyHash = auth.key?.tokenHash || (auth.rawKey ? hashKey(auth.rawKey) : null);
|
|
1867
1929
|
|
|
1930
|
+
if (isCodexModelForRotator(rotator, validation.value.model)) {
|
|
1931
|
+
await serveCodexChat(req, res, rotator, validation.value, {
|
|
1932
|
+
callType: "chat_completion",
|
|
1933
|
+
apiKeyHash,
|
|
1934
|
+
requesterIp: req.socket?.remoteAddress || null,
|
|
1935
|
+
rawRequest: validation.value,
|
|
1936
|
+
});
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1868
1940
|
const compMode = parseCompressionMode(
|
|
1869
1941
|
req.headers["x-rotator-compression"],
|
|
1870
1942
|
rotator?.getConfig?.()?.compressionMode,
|
|
@@ -1991,6 +2063,16 @@ export async function handleOpenAIResponsesCreate(
|
|
|
1991
2063
|
}
|
|
1992
2064
|
const apiKeyHash = auth.key?.tokenHash || (auth.rawKey ? hashKey(auth.rawKey) : null);
|
|
1993
2065
|
|
|
2066
|
+
if (isCodexModelForRotator(rotator, validation.value.model)) {
|
|
2067
|
+
await serveCodexResponses(req, res, rotator, validation.value, {
|
|
2068
|
+
callType: "responses",
|
|
2069
|
+
apiKeyHash,
|
|
2070
|
+
requesterIp: req.socket?.remoteAddress || null,
|
|
2071
|
+
rawRequest: validation.value,
|
|
2072
|
+
});
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
|
|
1994
2076
|
let converted: ResponsesConversionResult;
|
|
1995
2077
|
try {
|
|
1996
2078
|
converted = convertResponsesToChatRequest(validation.value);
|
package/src/config-normalize.ts
CHANGED
|
@@ -8,41 +8,78 @@ import { DEFAULT_PROVIDER } from "./providers/credential-helpers.js";
|
|
|
8
8
|
/**
|
|
9
9
|
* Migrate a flat legacy account shape (provider/apiKey/refreshToken at the
|
|
10
10
|
* top level) into the parent-account model where `email` owns a list of
|
|
11
|
-
* per-provider credentials.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* per-provider credentials. Existing credential arrays are also repaired when
|
|
12
|
+
* they coexist with legacy fields: adding a provider must not strand a
|
|
13
|
+
* pre-existing Google or Ollama credential in the deprecated top-level shape.
|
|
14
|
+
* Runs on every config load (applyConfigDefaults), so both the persisted DB
|
|
15
|
+
* config and legacy files normalize transparently.
|
|
14
16
|
*/
|
|
15
17
|
export function normalizeAccountConfig(account: AccountConfig): AccountConfig {
|
|
16
|
-
if (Array.isArray(account.credentials) && account.credentials.length > 0) {
|
|
17
|
-
return account;
|
|
18
|
-
}
|
|
19
18
|
const provider = account.provider ?? DEFAULT_PROVIDER;
|
|
19
|
+
const credentials = Array.isArray(account.credentials)
|
|
20
|
+
? [...account.credentials]
|
|
21
|
+
: [];
|
|
22
|
+
const providers = new Set(credentials.map((credential) => credential.provider));
|
|
23
|
+
|
|
24
|
+
const addCredential = (credential: NonNullable<AccountConfig["credentials"]>[number]): void => {
|
|
25
|
+
if (providers.has(credential.provider)) return;
|
|
26
|
+
credentials.push(credential);
|
|
27
|
+
providers.add(credential.provider);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
!providers.has("ollama") &&
|
|
32
|
+
typeof account.apiKey === "string" &&
|
|
33
|
+
account.apiKey.trim() !== ""
|
|
34
|
+
) {
|
|
35
|
+
addCredential({
|
|
36
|
+
provider: "ollama",
|
|
37
|
+
apiKey: account.apiKey,
|
|
38
|
+
proxyUrl: account.proxyUrl,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
!providers.has("openai-codex") &&
|
|
44
|
+
(provider === "openai-codex" ||
|
|
45
|
+
typeof account.codexRefreshToken === "string" ||
|
|
46
|
+
typeof account.codexAccountId === "string")
|
|
47
|
+
) {
|
|
48
|
+
addCredential({
|
|
49
|
+
provider: "openai-codex",
|
|
50
|
+
refreshToken: account.codexRefreshToken ?? account.refreshToken,
|
|
51
|
+
providerAccountId: account.codexAccountId,
|
|
52
|
+
proxyUrl: account.proxyUrl,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// A projectId/projectSource is unambiguously an Antigravity legacy field.
|
|
57
|
+
// When the legacy provider was not Codex, refreshToken is sufficient too.
|
|
58
|
+
// Codex also used a top-level refreshToken historically, so do not reinterpret
|
|
59
|
+
// that field as Google unless there is a Google-specific marker.
|
|
60
|
+
const hasLegacyGoogleFields =
|
|
61
|
+
account.projectId !== undefined ||
|
|
62
|
+
account.projectSource !== undefined ||
|
|
63
|
+
(provider !== "openai-codex" && account.refreshToken !== undefined);
|
|
64
|
+
if (!providers.has(DEFAULT_PROVIDER) && hasLegacyGoogleFields) {
|
|
65
|
+
addCredential({
|
|
66
|
+
provider: DEFAULT_PROVIDER,
|
|
67
|
+
refreshToken: account.refreshToken,
|
|
68
|
+
projectId: account.projectId,
|
|
69
|
+
projectSource: account.projectSource,
|
|
70
|
+
proxyUrl: account.proxyUrl,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (credentials.length > 0) {
|
|
75
|
+
if (Array.isArray(account.credentials) && credentials.length === account.credentials.length) {
|
|
76
|
+
return account;
|
|
77
|
+
}
|
|
78
|
+
return { ...account, credentials };
|
|
79
|
+
}
|
|
80
|
+
|
|
20
81
|
// Mirror the flat legacy fields onto the parent-account credentials and
|
|
21
82
|
// KEEP the top-level fields: Google reads (forward/quota/index) still
|
|
22
83
|
// consult them, so both shapes coexist until the runtime migrates.
|
|
23
|
-
if (provider === "ollama" && typeof account.apiKey === "string" && account.apiKey.trim() !== "") {
|
|
24
|
-
return {
|
|
25
|
-
...account,
|
|
26
|
-
credentials: [{
|
|
27
|
-
provider: "ollama",
|
|
28
|
-
apiKey: account.apiKey,
|
|
29
|
-
proxyUrl: account.proxyUrl,
|
|
30
|
-
}],
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
if (provider !== "ollama" && (account.refreshToken !== undefined || account.projectId !== undefined)) {
|
|
34
|
-
return {
|
|
35
|
-
...account,
|
|
36
|
-
credentials: [
|
|
37
|
-
{
|
|
38
|
-
provider: DEFAULT_PROVIDER,
|
|
39
|
-
refreshToken: account.refreshToken,
|
|
40
|
-
projectId: account.projectId,
|
|
41
|
-
projectSource: account.projectSource,
|
|
42
|
-
proxyUrl: account.proxyUrl,
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
84
|
return account;
|
|
48
85
|
}
|
package/src/index.ts
CHANGED
|
@@ -211,6 +211,7 @@ export async function main(): Promise<void> {
|
|
|
211
211
|
|
|
212
212
|
const rotator = new AccountRotator(config);
|
|
213
213
|
await rotator.primeOllamaCatalog();
|
|
214
|
+
await rotator.primeCodexCatalog();
|
|
214
215
|
|
|
215
216
|
// ── Telemetry (anonymous, opt-out via TUXEVIL_ROTATOR_TELEMETRY=off) ──
|
|
216
217
|
const telemetry = new TelemetryReporter(() => {
|