tuxevil-rotator 3.0.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 (142) hide show
  1. package/CHANGELOG.md +773 -0
  2. package/LICENSE +21 -0
  3. package/README.md +341 -0
  4. package/bin/pi-antigravity-rotator.js +27 -0
  5. package/bin/tuxevil-rotator.js +5 -0
  6. package/package.json +63 -0
  7. package/src/account-store.ts +542 -0
  8. package/src/admin-auth.ts +126 -0
  9. package/src/body-limit.ts +52 -0
  10. package/src/cli.ts +293 -0
  11. package/src/compat/cache.ts +38 -0
  12. package/src/compat/model-specs.ts +82 -0
  13. package/src/compat/schema-sanitizer.ts +284 -0
  14. package/src/compat.ts +2357 -0
  15. package/src/compression/index.ts +92 -0
  16. package/src/compression/lite.ts +210 -0
  17. package/src/compression/preservation.ts +183 -0
  18. package/src/compression/rtk/command-detector.ts +170 -0
  19. package/src/compression/rtk/deduplicator.ts +39 -0
  20. package/src/compression/rtk/filter-loader.ts +84 -0
  21. package/src/compression/rtk/filter-types.ts +25 -0
  22. package/src/compression/rtk/filters/aws.json +34 -0
  23. package/src/compression/rtk/filters/biome.json +35 -0
  24. package/src/compression/rtk/filters/build-eslint.json +37 -0
  25. package/src/compression/rtk/filters/build-typescript.json +33 -0
  26. package/src/compression/rtk/filters/build-vite.json +41 -0
  27. package/src/compression/rtk/filters/build-webpack.json +34 -0
  28. package/src/compression/rtk/filters/bundle-install.json +35 -0
  29. package/src/compression/rtk/filters/composer.json +81 -0
  30. package/src/compression/rtk/filters/curl.json +34 -0
  31. package/src/compression/rtk/filters/df.json +34 -0
  32. package/src/compression/rtk/filters/docker-build.json +78 -0
  33. package/src/compression/rtk/filters/docker-logs.json +42 -0
  34. package/src/compression/rtk/filters/docker-ps.json +33 -0
  35. package/src/compression/rtk/filters/dotnet.json +47 -0
  36. package/src/compression/rtk/filters/du.json +33 -0
  37. package/src/compression/rtk/filters/error-stacktrace.json +41 -0
  38. package/src/compression/rtk/filters/gcloud.json +34 -0
  39. package/src/compression/rtk/filters/generic-output.json +32 -0
  40. package/src/compression/rtk/filters/gh.json +98 -0
  41. package/src/compression/rtk/filters/git-branch.json +45 -0
  42. package/src/compression/rtk/filters/git-diff.json +33 -0
  43. package/src/compression/rtk/filters/git-log.json +33 -0
  44. package/src/compression/rtk/filters/git-status.json +40 -0
  45. package/src/compression/rtk/filters/golangci-lint.json +34 -0
  46. package/src/compression/rtk/filters/gradle.json +47 -0
  47. package/src/compression/rtk/filters/json-output.json +40 -0
  48. package/src/compression/rtk/filters/kubectl.json +99 -0
  49. package/src/compression/rtk/filters/make.json +38 -0
  50. package/src/compression/rtk/filters/mypy.json +34 -0
  51. package/src/compression/rtk/filters/npm-audit.json +43 -0
  52. package/src/compression/rtk/filters/npm-install.json +41 -0
  53. package/src/compression/rtk/filters/nx.json +34 -0
  54. package/src/compression/rtk/filters/pip.json +41 -0
  55. package/src/compression/rtk/filters/playwright.json +42 -0
  56. package/src/compression/rtk/filters/poetry-install.json +35 -0
  57. package/src/compression/rtk/filters/prettier.json +40 -0
  58. package/src/compression/rtk/filters/ps.json +34 -0
  59. package/src/compression/rtk/filters/rsync.json +33 -0
  60. package/src/compression/rtk/filters/rubocop.json +34 -0
  61. package/src/compression/rtk/filters/ruff.json +40 -0
  62. package/src/compression/rtk/filters/shell-find.json +33 -0
  63. package/src/compression/rtk/filters/shell-grep.json +37 -0
  64. package/src/compression/rtk/filters/shell-ls.json +33 -0
  65. package/src/compression/rtk/filters/ssh.json +43 -0
  66. package/src/compression/rtk/filters/systemctl-status.json +43 -0
  67. package/src/compression/rtk/filters/terraform-plan.json +34 -0
  68. package/src/compression/rtk/filters/test-cargo.json +42 -0
  69. package/src/compression/rtk/filters/test-go.json +41 -0
  70. package/src/compression/rtk/filters/test-jest.json +43 -0
  71. package/src/compression/rtk/filters/test-pytest.json +41 -0
  72. package/src/compression/rtk/filters/test-vitest.json +43 -0
  73. package/src/compression/rtk/filters/tofu-plan.json +34 -0
  74. package/src/compression/rtk/filters/turbo.json +34 -0
  75. package/src/compression/rtk/filters/uv-sync.json +35 -0
  76. package/src/compression/rtk/filters/wget.json +34 -0
  77. package/src/compression/rtk/index.ts +103 -0
  78. package/src/compression/rtk/line-filter.ts +124 -0
  79. package/src/compression/rtk/smart-truncate.ts +71 -0
  80. package/src/config-defaults.ts +93 -0
  81. package/src/config-normalize.ts +48 -0
  82. package/src/config-storage.ts +21 -0
  83. package/src/dashboard.ts +1169 -0
  84. package/src/db-store.ts +188 -0
  85. package/src/doctor.ts +115 -0
  86. package/src/env.ts +15 -0
  87. package/src/exposure.ts +17 -0
  88. package/src/fetch-with-retry.ts +93 -0
  89. package/src/idempotency.ts +137 -0
  90. package/src/index.ts +267 -0
  91. package/src/key-auth.ts +159 -0
  92. package/src/key-migrations.ts +84 -0
  93. package/src/logger.ts +92 -0
  94. package/src/login.ts +48 -0
  95. package/src/notification-poller.ts +155 -0
  96. package/src/onboarding.ts +754 -0
  97. package/src/paths.ts +153 -0
  98. package/src/providers/adapter.ts +131 -0
  99. package/src/providers/credential-helpers.ts +72 -0
  100. package/src/providers/google-antigravity/code-assist.ts +161 -0
  101. package/src/providers/google-antigravity/credentials.ts +24 -0
  102. package/src/providers/google-antigravity/forward.ts +424 -0
  103. package/src/providers/google-antigravity/index.ts +168 -0
  104. package/src/providers/google-antigravity/login.ts +285 -0
  105. package/src/providers/google-antigravity/oauth.ts +314 -0
  106. package/src/providers/google-antigravity/quota.ts +152 -0
  107. package/src/providers/google-antigravity/translators.ts +1663 -0
  108. package/src/providers/ollama/api-key-validation.ts +59 -0
  109. package/src/providers/ollama/credentials.ts +28 -0
  110. package/src/providers/ollama/forward.ts +306 -0
  111. package/src/providers/ollama/index.ts +85 -0
  112. package/src/providers/ollama/login.ts +55 -0
  113. package/src/providers/ollama/prediction.ts +188 -0
  114. package/src/providers/ollama/quota-poll-store.ts +160 -0
  115. package/src/providers/ollama/quota.ts +189 -0
  116. package/src/providers/ollama/translators.ts +256 -0
  117. package/src/providers/ollama/usage-windows.ts +48 -0
  118. package/src/providers/proxy-dispatcher.ts +269 -0
  119. package/src/providers/registry.ts +70 -0
  120. package/src/proxy.ts +2446 -0
  121. package/src/rate-limit-parser.ts +126 -0
  122. package/src/response-headers.ts +98 -0
  123. package/src/responses-store.ts +159 -0
  124. package/src/rotator.ts +3614 -0
  125. package/src/settings-repository.ts +327 -0
  126. package/src/spend-logger.ts +696 -0
  127. package/src/static/dashboard-keys.js +384 -0
  128. package/src/static/dashboard-logs.js +797 -0
  129. package/src/static/dashboard.css +2740 -0
  130. package/src/static/dashboard.js +3177 -0
  131. package/src/storage.ts +105 -0
  132. package/src/systemd-env.ts +214 -0
  133. package/src/telemetry.ts +384 -0
  134. package/src/token-encryption.ts +199 -0
  135. package/src/types.ts +897 -0
  136. package/src/validators.ts +218 -0
  137. package/src/version-check.ts +225 -0
  138. package/src/virtual-keys.ts +312 -0
  139. package/tools/telemetry-receiver/README.md +147 -0
  140. package/tools/telemetry-receiver/package.json +13 -0
  141. package/tools/telemetry-receiver/receiver.js +2334 -0
  142. package/tuxevil-rotator_logo.png +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sebastián Real (tuxevil)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,341 @@
1
+ <div align="center">
2
+
3
+ [![npm version](https://img.shields.io/npm/v/tuxevil-rotator?logo=npm&label=version)](https://www.npmjs.com/package/tuxevil-rotator)
4
+ [![Node](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen?logo=node.js)](package.json)
5
+ [![License](https://img.shields.io/github/license/tuxevil/tuxevil-rotator?logo=opensourceinitiative)](LICENSE)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/tuxevil/tuxevil-rotator/ci.yml?logo=github&label=CI)](https://github.com/tuxevil/tuxevil-rotator/actions)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org)
8
+ [![Docker Image](https://img.shields.io/badge/ghcr.io-tuxevil--tuxevil--rotator-blue?logo=docker)](https://github.com/tuxevil/tuxevil-rotator/pkgs/container/tuxevil-rotator)
9
+ [![Stars](https://img.shields.io/github/stars/tuxevil/tuxevil-rotator?style=social)](https://github.com/tuxevil/tuxevil-rotator/stargazers)
10
+
11
+ [![Installations](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Ftelemetry.tuxevil.com%2Fv1%2Fpublic-stats&query=%24.installsFormatted&label=installations&color=6366f1)](https://telemetry.tuxevil.com/v1/public-stats)
12
+ [![Requests Routed](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Ftelemetry.tuxevil.com%2Fv1%2Fpublic-stats&query=%24.requestsFormatted&label=requests%20routed&color=10b981)](https://telemetry.tuxevil.com/v1/public-stats)
13
+ [![Input Tokens](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Ftelemetry.tuxevil.com%2Fv1%2Fpublic-stats&query=%24.tokensInputFormatted&label=input%20tokens&color=3b82f6)](https://telemetry.tuxevil.com/v1/public-stats)
14
+ [![Output Tokens](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Ftelemetry.tuxevil.com%2Fv1%2Fpublic-stats&query=%24.tokensOutputFormatted&label=output%20tokens&color=8b5cf6)](https://telemetry.tuxevil.com/v1/public-stats)
15
+ [![Estimated Savings](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Ftelemetry.tuxevil.com%2Fv1%2Fpublic-stats&query=%24.savingsFormatted&label=estimated%20savings&color=f59e0b)](https://telemetry.tuxevil.com/v1/public-stats)
16
+
17
+ [View live telemetry stats](https://telemetry.tuxevil.com/stats)
18
+
19
+ ![tuxevil-rotator logo](./tuxevil-rotator_logo.png)
20
+
21
+ </div>
22
+
23
+ # tuxevil-rotator
24
+
25
+ **Production-ready OpenAI-compatible gateway for multiple free-tier LLM providers.**
26
+
27
+ 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
+
29
+ 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.
30
+
31
+ > **⚠️ WARNING:** Using this proxy may put connected accounts at risk of Terms of Service enforcement, including restriction, suspension, or permanent bans. Use at your own risk.
32
+
33
+ <details>
34
+ <summary><strong>⚠️ Terms of Service Warning — Read Before Installing</strong></summary>
35
+
36
+ > [!CAUTION]
37
+ > This is an unofficial tool. Routing traffic through this proxy may violate a provider's Terms of Service or trigger automated abuse or policy enforcement systems.
38
+ >
39
+ > **By using this proxy, you acknowledge:**
40
+ > - Your account may be restricted, suspended, shadow-banned, or permanently banned
41
+ > - Multi-account rotation and proxying can increase account risk compared to normal interactive usage
42
+ > - You assume all responsibility for the accounts and traffic routed through this tool
43
+ >
44
+ > **Recommendation:** Do not use your primary account on any provider. Prefer disposable or lower-risk accounts, and keep account exposure conservative.
45
+
46
+ </details>
47
+
48
+ > **Migrating from `pi-antigravity-rotator`?** Install the new `tuxevil-rotator` package. It includes the new CLI plus a legacy shim, automatically migrates legacy config files, and keeps old environment variables and paths working as fallbacks. See [Migration from pi-antigravity-rotator](docs/migrating-from-pi-antigravity-rotator.md).
49
+
50
+ ---
51
+
52
+ ## v3.0 Highlights
53
+
54
+ - **Parent-Account Credential Model**: Each account (email) is now the parent entity and may hold per-provider credentials — a single human with both a Google Antigravity OAuth token and an Ollama Cloud API key lives in one account row. Login (`login --provider <id>`) and the legacy importer merge credentials onto existing accounts instead of duplicating by email.
55
+ - **Antigravity quota pools consolidated by family**: One quota bucket per family — `claude` (every Claude variant + gpt-oss) and `gemini` (every Gemini variant) — instead of one per model. The Antigravity quota API reports the same bucket for all of them, and the dashboard's consolidated RAW POLL line now shows both providers at once, with Antigravity pools first and Ollama last.
56
+ - **Ollama model pricing in `MODEL_PRICING`**: Spend summaries now report real USD for Ollama traffic (18 entries ported from the predecessor project's catalog of paid prices). Unknown models still return 0.
57
+ - **Routing robustness**: Dispatch for Ollama models now keys on the live catalog (`rotator.getOllamaModels()`), so models without `:` in the name (`minimax-m3`, `kimi-k3`, `glm-5.1`, `nemotron-3-super`, `deepseek-v4-pro`) no longer leak to the Antigravity adapter. Multi-turn tool-call requests now parse `function.arguments` to a real object before forwarding, since Ollama's Go API rejects OpenAI-style JSON-encoded strings.
58
+
59
+ ## v2.7 Highlights
60
+
61
+ - **Multi-Provider Support**: The rotator now routes through two provider families. Google Antigravity accounts (OAuth, default) and Ollama Cloud accounts (static API keys, `login --provider ollama`) coexist in one account store, with per-provider model catalog resolution.
62
+ - **Ollama Cloud Compatibility (B2)**: `POST /v1/chat/completions`, `/v1/responses`, and `/v1/messages` translate requests to Ollama's native `api/chat` NDJSON protocol for Ollama models; streaming deltas (including `tool_calls` and `usage`) are converted to SSE in both OpenAI and Anthropic formats. `GET /v1/models` lists the Ollama catalog (`owned_by: "ollama"`), and the native `POST /api/chat` endpoint routes Ollama models to Ollama accounts.
63
+ - **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
+ - **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
+
66
+ ## v2.6 Highlights
67
+
68
+ - **Lossless Prompt Compression**: Optional Lite and RTK compression modes preserve code-critical content while reducing prompt size. Enable `compressionMode` in `accounts.json` or override a request with `X-Rotator-Compression: lite`, `rtk`, or `rtk+lite`.
69
+ - **Operational Observability**: `X-Rotator-*` response headers expose routing, latency, token, cost, health, idempotency, and compression metrics without changing response bodies.
70
+ - **Reliable Request Handling**: Configurable pre-flush stream recovery, duplicate-request idempotency, asynchronous persistence, and an active-account benchmark improve production operations.
71
+ - **Dashboard Workspaces**: Refined Accounts, Virtual Keys, Spend Logs, telemetry, and notification experiences with responsive layouts, filtering, and consistent PII masking.
72
+ - **Security Hardening**: Refresh tokens now use salted `scrypt` plus AES-256-GCM for new encrypted records, legacy encrypted tokens remain readable, and public error responses no longer expose internal details.
73
+
74
+ ## v2.5 Highlights
75
+
76
+ - **Automated GHCR Multi-arch Builds**: Official Docker images (`linux/amd64`, `linux/arm64`) automatically built and published to GitHub Container Registry.
77
+ - **Pre-built Docker Deployment**: Updated `docker-compose.yml` to pull pre-built GHCR images directly out-of-the-box.
78
+
79
+ ## v2.4 Highlights
80
+
81
+ - **Virtual Keys & Scoped Access Control**: Generate scoped API keys (`rk-...`) with per-key model authorization rules and user tracking.
82
+ - **Spend Logging & Audit Inspector**: PostgreSQL audit trail of all requests, token metrics, TTFB/Total duration, Base64 media sanitization, 6-decimal USD cost breakdown, and Request/Response payload viewer.
83
+ - **Multi-page Web Dashboard**: Unified header navigation connecting Accounts, Virtual Keys, and Spend Logs, featuring customizable column visibility, search/filtering, and instant PII masking.
84
+ - **PostgreSQL Persistence Backend**: Enable `TUXEVIL_ROTATOR_DATABASE_URL` for high-concurrency key validation, persistent spend logging, and retention policies.
85
+
86
+ ---
87
+
88
+ ### Compression and token encryption
89
+
90
+ Compression is disabled by default. To enable a default mode, add this field to `accounts.json`:
91
+
92
+ ```json
93
+ {
94
+ "compressionMode": "lite"
95
+ }
96
+ ```
97
+
98
+ For a single request, send `X-Rotator-Compression: lite`, `rtk`, or `rtk+lite`. The response reports the selected mode and savings through `X-Rotator-Compression-*` headers.
99
+
100
+ To encrypt refresh tokens at rest, set a secret before starting the rotator. A 64-character hexadecimal key is recommended:
101
+
102
+ ```bash
103
+ export TUXEVIL_ROTATOR_ENCRYPTION_KEY="$(openssl rand -hex 32)"
104
+ tuxevil-rotator start
105
+ ```
106
+
107
+ Existing `enc:v1` records remain decryptable during migration; newly written records use `enc:v2`.
108
+
109
+ > **Legacy env vars still work:** `PI_ROTATOR_ENCRYPTION_KEY` is honored as a fallback so existing setups keep working without changes.
110
+
111
+ ---
112
+
113
+ ## Features
114
+
115
+ - **Multi-provider gateway** — OpenAI-compatible endpoint (`/v1/chat/completions`, `/v1/responses`, `/v1/messages`) plus native Ollama (`/api/chat`) routes; any agent or tool can use either
116
+ - **Google Antigravity accounts** — OAuth load balancing across a pool, with per-model independent routing
117
+ - **Ollama Cloud accounts** — Static-API-key accounts (`login --provider ollama`) for the Ollama Cloud catalog (`gpt-oss`, `gemma4`, `kimi-k3`, `minimax-m3`, `qwen3.5`, `glm-5`, `mistral-large-3`, `nemotron-3`, `deepseek-v4`)
118
+ - **Parent-account credentials** — One email, many providers; the same human with Google OAuth and an Ollama key is one row in `accounts.json`, with `credentials: [{provider, apiKey|refreshToken, projectId}]` instead of duplicate rows by email
119
+ - **Provider-agnostic rotation** — The rotation engine treats Antigravity and Ollama uniformly. The next free-tier provider with a per-account credential and a quota API slots in as a new `--provider` value without forking the engine.
120
+ - **Multi-account load balancing** — Distributes traffic across a pool of accounts with per-model independent routing
121
+ - **One-command account setup** — `tuxevil-rotator login` auto-discovers (or provisions) the Cloud Code companion project for brand-new Google accounts; `login --provider ollama` adds an Ollama Cloud API key to an existing email or creates a new one
122
+ - **Smart rotation & health scoring** — Six routing policies (`timer-first`, `tier-first`, `quota-first`, `hybrid`, `sequential-quota`, `sticky-quota`) with composite health scores per account
123
+ - **Real-time quota monitoring** — Polls each provider's quota API on its own cadence; Antigravity quota pools are consolidated by family (`claude`, `gemini`) and Ollama reports session/weekly usage
124
+ - **Infringement & abuse detection** — Flags accounts on enforcement signals and triggers protective pause to preserve the rest of the pool
125
+ - **Virtual Keys & access control** — Issue scoped `rk-...` keys for teams, agents, or CI pipelines with per-key model restrictions
126
+ - **Spend logging & audit inspector** — Full request/response audit trail with 6-decimal USD cost estimates for both Antigravity and Ollama traffic (requires PostgreSQL)
127
+ - **Legacy importer** — On startup, automatically merges Ollama Cloud accounts from `~/.ollama-rotator/accounts.json` (the predecessor product) onto existing accounts, idempotently
128
+ - **Web dashboard** — Real-time routing state, quota bars, latency tracking (p50/p95), savings chart, activity heatmap, and routing inspector
129
+ - **State persistence** — Survives restarts; routing assignments, cooldowns, and flags saved to disk or PostgreSQL
130
+ - **Tool/function calling** — Fully supported in OpenAI and Anthropic formats, including multi-turn and parallel tool calls, with reliable function-name resolution for tool responses across turns. Ollama forwards `function.arguments` as a parsed object (OpenAI sends it as a JSON string and Ollama's Go API rejects that).
131
+ - **Reasoning/thinking visibility** — Interleaved thinking blocks exposed as `reasoning_content` / `thinking_delta` in real time
132
+
133
+ [Full feature list →](docs/how-it-works.md)
134
+
135
+ ## Quick Start
136
+
137
+ **Requirements:** Node.js 22+ for npm/source installs. Docker image uses Node 22.
138
+
139
+ ### Option A: npm
140
+
141
+ ```bash
142
+ npm install -g tuxevil-rotator
143
+ tuxevil-rotator login # Google Antigravity (default)
144
+ tuxevil-rotator login --provider ollama # Ollama Cloud (static API key)
145
+ tuxevil-rotator start
146
+ ```
147
+
148
+ Ollama Cloud accounts from a previous `~/ollama-rotator` install are imported automatically at startup — no manual step required.
149
+
150
+ > **Coming from `pi-antigravity-rotator`?** Install the new package, then run the guided migration:
151
+ >
152
+ > ```bash
153
+ > npm install -g tuxevil-rotator
154
+ > tuxevil-rotator migrate
155
+ > tuxevil-rotator doctor
156
+ > ```
157
+ >
158
+ > The migration copies legacy config files without deleting them. The new package also keeps the old CLI as a deprecation shim and honors legacy environment variables and paths. See the [Migration guide](docs/migrating-from-pi-antigravity-rotator.md).
159
+
160
+ ### Option B: Docker
161
+
162
+ ```bash
163
+ mkdir -p docker-data
164
+ docker compose up -d
165
+ ```
166
+
167
+ ### Option C: Source
168
+
169
+ ```bash
170
+ git clone https://github.com/tuxevil/tuxevil-rotator.git
171
+ cd tuxevil-rotator
172
+ npm install
173
+ npm run login # Google Antigravity
174
+ npm run login -- --provider ollama # Ollama Cloud
175
+ npm start
176
+ ```
177
+
178
+ Dashboard opens at `http://localhost:51200/dashboard`
179
+
180
+ [Full deployment guide →](docs/deployment.md) · [Adding accounts →](docs/adding-accounts.md)
181
+
182
+ ---
183
+
184
+ ## Connect Your Agent
185
+
186
+ Point any OpenAI-compatible agent to `http://localhost:51200/v1` with API key `tuxevil` (or a [Virtual Key](docs/virtual-keys.md)):
187
+
188
+ | Agent | Guide |
189
+ |-------|-------|
190
+ | Pi | [docs/integrations/pi.md](docs/integrations/pi.md) |
191
+ | OpenCode | [docs/integrations/opencode.md](docs/integrations/opencode.md) |
192
+ | Hermes | [docs/integrations/hermes.md](docs/integrations/hermes.md) |
193
+ | OpenClaw | [docs/integrations/openclaw.md](docs/integrations/openclaw.md) |
194
+ | Cursor | [docs/integrations/cursor.md](docs/integrations/cursor.md) |
195
+ | Claude Code | [docs/integrations/claude-code.md](docs/integrations/claude-code.md) |
196
+ | Codex (OpenAI CLI) | [docs/integrations/codex.md](docs/integrations/codex.md) |
197
+ | Cline | [docs/integrations/cline.md](docs/integrations/cline.md) |
198
+ | Roo Code | [docs/integrations/roo-code.md](docs/integrations/roo-code.md) |
199
+ | Continue | [docs/integrations/continue.md](docs/integrations/continue.md) |
200
+ | Aider | [docs/integrations/aider.md](docs/integrations/aider.md) |
201
+ | Open WebUI | [docs/integrations/open-webui.md](docs/integrations/open-webui.md) |
202
+
203
+ ---
204
+
205
+ ## Architecture
206
+
207
+ ```mermaid
208
+ graph LR
209
+ A[Your Agent] -->|OpenAI / Anthropic API| B["tuxevil-rotator<br/>localhost:51200"]
210
+ B -->|Smart Routing| C[Google Account 1]
211
+ B -->|Smart Routing| D[Google Account 2]
212
+ B -->|Smart Routing| E[Ollama Cloud Account 1]
213
+ B -->|Smart Routing| F[Ollama Cloud Account 2]
214
+ B -->|Smart Routing| G[... up to N]
215
+ C --> H[Google Antigravity]
216
+ D --> H
217
+ E --> I[Ollama Cloud]
218
+ F --> I
219
+ G --> I
220
+
221
+ H -.Quota API<br/>every 5 min.-> B
222
+ I -.Usage API<br/>every 5 min.-> B
223
+ ```
224
+
225
+ Each model routes to its own best available account independently. The same email can hold both a Google OAuth credential and an Ollama Cloud API key (parent-account model) — the rotator picks the right credential at request time based on the destination model.
226
+
227
+ How model routing works:
228
+ - **Antigravity pool** — Claude variants (`claude-opus-4-6-thinking`, `claude-sonnet-4-6`, `gpt-oss-120b`) share the `claude` quota bucket; Gemini variants share the `gemini` bucket.
229
+ - **Ollama pool** — Any model returned by `https://ollama.com/api/tags` (e.g. `gemma4:31b`, `gpt-oss:20b`, `minimax-m3`, `kimi-k3`) routes to an Ollama credential.
230
+ - The pool is selected by the destination model's provider; a single account with both credentials participates in both pools.
231
+
232
+ [How it works in detail →](docs/how-it-works.md)
233
+
234
+ ---
235
+
236
+ ## Dashboard
237
+
238
+ After starting the proxy, open `http://localhost:51200/dashboard`.
239
+
240
+ The dashboard shows:
241
+ - **Routing state** — real-time status, uptime, requests, protective pause timers
242
+ - **Account cards** — quota bars (Antigravity family buckets `claude` / `gemini`; Ollama session/weekly usage), per-model timers, health scores, flagged alerts
243
+ - **Token usage & savings** — interactive chart with time ranges and CSV/JSON export (real USD for both providers)
244
+ - **Latency (p50/p95)** — per-model TTFB and total duration
245
+ - **Activity heatmap** — 60-day GitHub-style request intensity grid
246
+ - **Quota forecast** — tier-weighted depletion predictions
247
+ - **Routing inspector** — on-demand modal with candidate scores, health-score breakdown, and rejection reasons
248
+
249
+ ![Dashboard](dashboard.png)
250
+
251
+ [Dashboard reference →](docs/adding-accounts.md)
252
+
253
+ ## Virtual Keys & Spend Logging
254
+
255
+ With PostgreSQL, the gateway adds enterprise-grade access control and cost auditing.
256
+
257
+ ```bash
258
+ # Set up PostgreSQL (or paste the prompt in docs/integrations/setup-postgresql.md into your AI agent)
259
+ export TUXEVIL_ROTATOR_DATABASE_URL="postgres://user:***@localhost:5432/rotatordb"
260
+
261
+ # Generate a scoped key
262
+ tuxevil-rotator keys generate --alias "cursor-agent" --models "gemini-3.6-flash-high"
263
+ # → rk-a1b2c3d4...
264
+ ```
265
+
266
+ [Virtual Keys guide →](docs/virtual-keys.md) · [Setting up PostgreSQL →](docs/integrations/setup-postgresql.md)
267
+
268
+ ---
269
+
270
+ ## Documentation
271
+
272
+ | Topic | Link |
273
+ |-------|------|
274
+ | How It Works | [docs/how-it-works.md](docs/how-it-works.md) |
275
+ | Configuration | [docs/configuration.md](docs/configuration.md) |
276
+ | Virtual Keys & Spend Logging | [docs/virtual-keys.md](docs/virtual-keys.md) |
277
+ | API Reference | [docs/api-reference.md](docs/api-reference.md) |
278
+ | Compatibility Adapters | [docs/compatibility.md](docs/compatibility.md) |
279
+ | Deployment | [docs/deployment.md](docs/deployment.md) |
280
+ | Adding Accounts | [docs/adding-accounts.md](docs/adding-accounts.md) |
281
+ | Migration from pi-antigravity-rotator | [docs/migrating-from-pi-antigravity-rotator.md](docs/migrating-from-pi-antigravity-rotator.md) |
282
+ | Troubleshooting | [docs/troubleshooting.md](docs/troubleshooting.md) |
283
+ | Telemetry | [docs/telemetry.md](docs/telemetry.md) |
284
+ | PostgreSQL Setup | [docs/integrations/setup-postgresql.md](docs/integrations/setup-postgresql.md) |
285
+
286
+ ---
287
+
288
+ ## Why its called "tuxevil-rotator" now?
289
+
290
+ This project started as a focused, single-purpose rotator for pi coder agent and for Google Antigravity provider. As the rotation engine matured and the Ollama Cloud integration landed, the same engine applied cleanly to any free-tier provider with per-account credentials and a quota API. Renaming to `tuxevil-rotator` makes that generalization explicit: the provider is a plug-in, the rotation is the product.
291
+
292
+ A few things shaped the decision concretely:
293
+
294
+ - The original name (`pi-antigravity-rotator`) signaled "I only know one provider." That's no longer true.
295
+ - The account store moved to a parent-account model where one email can hold credentials for multiple providers. The product surface needed to follow.
296
+ - Open-sourcing the rotator as `pi-*` implied it was only interesting inside the `pi.dev` ecosystem. The engine itself is provider-agnostic and useful in any agent stack.
297
+
298
+ The name comes from the maintainer's nickname (`tuxevil`). It's also the namespace already used across this maintainer's other open-source work, so the rotator stops being a one-off and becomes part of a recognizable family of tools.
299
+
300
+ > **Want the longer story?** A deeper post on the rationale, the design tradeoffs, and the provider-pluggable architecture is on the maintainer's blog: [Why I renamed pi-antigravity-rotator to tuxevil-rotator](https://tuxevil.com/en/blog/tuxevil-rotator/).
301
+
302
+ ---
303
+
304
+ ## Star History
305
+
306
+ <a href="https://www.star-history.com/?repos=tuxevil%2Ftuxevil-rotator&type=date&legend=top-left">
307
+ <picture>
308
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=tuxevil/tuxevil-rotator&type=date&theme=dark&legend=top-left&sealed_token=obDO-nvWTZErW7T7dgOBp_5AMavHuc70IWvLlTQs9wfbuB4-NINioIoVFjcHccMOcJGmL7mm8JGodxBWC4vWl2W5FW7C1i_xak0Mc0mOD2HIowLdL2VS07heeIUk3YibkZcN0qAFzMFcH_B6_4wgzT-t-jTrOUEntcsmoVgjfFCGUA7hduT3LtyOzQiW" />
309
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=tuxevil/tuxevil-rotator&type=date&legend=top-left&sealed_token=obDO-nvWTZErW7T7dgOBp_5AMavHuc70IWvLlTQs9wfbuB4-NINioIoVFjcHccMOcJGmL7mm8JGodxBWC4vWl2W5FW7C1i_xak0Mc0mOD2HIowLdL2VS07heeIUk3YibkZcN0qAFzMFcH_B6_4wgzT-t-jTrOUEntcsmoVgjfFCGUA7hduT3LtyOzQiW" />
310
+ <img alt="Star History Chart" src="https://api.star-history.com/chart?repos=tuxevil/tuxevil-rotator&type=date&legend=top-left&sealed_token=obDO-nvWTZErW7T7dgOBp_5AMavHuc70IWvLlTQs9wfbuB4-NINioIoVFjcHccMOcJGmL7mm8JGodxBWC4vWl2W5FW7C1i_xak0Mc0mOD2HIowLdL2VS07heeIUk3YibkZcN0qAFzMFcH_B6_4wgzT-t-jTrOUEntcsmoVgjfFCGUA7hduT3LtyOzQiW" />
311
+ </picture>
312
+ </a>
313
+
314
+ ---
315
+
316
+ ## Support
317
+
318
+ If this tool has saved you API costs, consider supporting its development!
319
+
320
+ <a href="https://ko-fi.com/tuxevil" target="_blank"><img src="https://storage.ko-fi.com/cdn/kofi2.png?v=3" height="36" alt="Buy Me a Coffee at ko-fi.com" /></a> <a href="https://discord.gg/GgwVqTaKgK" target="_blank"><img src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white" height="36" alt="Join Discord" /></a>
321
+
322
+ To donate an authorized account for testing across supported providers, see [CONTRIBUTING.md](CONTRIBUTING.md).
323
+
324
+ ## Contributors
325
+
326
+ Thanks to these amazing people who have contributed to the project:
327
+
328
+ - **[@Codder-hermes](https://github.com/Codder-hermes)** — Fixed Claude Code tool-schema requests by stripping the unsupported JSON Schema `propertyNames` keyword for Gemini and Claude-via-Gemini routes, with regression coverage for both compatibility paths. ([PR #19](https://github.com/tuxevil/tuxevil-rotator/pull/19))
329
+ - **[@CyR1en](https://github.com/CyR1en)** (Ethan Bacurio) — Added the Gemini 3.6 Flash model family, shared quota-pool routing, pricing, dashboard support, and regression coverage. ([PR #18](https://github.com/tuxevil/tuxevil-rotator/pull/18))
330
+ - **[@josenicomaia](https://github.com/josenicomaia)** (José Nicodemos Maia Neto) — Modularized the compatibility layer architecture, added multimodal tool response support, and fixed streaming pass-through for tool executions. ([PR #8](https://github.com/tuxevil/tuxevil-rotator/pull/8), [PR #9](https://github.com/tuxevil/tuxevil-rotator/pull/9), [PR #11](https://github.com/tuxevil/tuxevil-rotator/pull/11))
331
+ - **[@yashyadav711](https://github.com/yashyadav711)** (Yash) — Fixed Draft-2020-12 inline JSON-Schema union type mapping for Gemini tools support. ([PR #10](https://github.com/tuxevil/tuxevil-rotator/pull/10))
332
+ - **[@javargasm](https://github.com/javargasm)** (Jeisson Alexander Vargas Marroquin) — Anthropic tool-use compatibility layer (`tool_use`/`tool_result` content block conversion), JSON schema round-trip fixes, and compat test suite expansion. ([PR #3](https://github.com/tuxevil/tuxevil-rotator/pull/3), [PR #7](https://github.com/tuxevil/tuxevil-rotator/pull/7))
333
+
334
+ ## Development
335
+
336
+ ```bash
337
+ npm run typecheck # Type-check src/
338
+ npm run typecheck:test # Type-check src/ + test/
339
+ npm test # Run test suite
340
+ npm run check # typecheck + test + lint (full gate)
341
+ ```
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ // Legacy shim for `pi-antigravity-rotator` (v2.x and earlier).
3
+ //
4
+ // The binary was renamed to `tuxevil-rotator` in v3.0. This shim keeps
5
+ // existing scripts, systemd units, docker images, and agent configs that
6
+ // still invoke `pi-antigravity-rotator` working without changes.
7
+ //
8
+ // It forwards every argument to the new `tuxevil-rotator` binary, which
9
+ // in turn dispatches into the same `src/cli.ts` entry point. There is
10
+ // no duplicated logic here — the shim is intentionally a thin wrapper.
11
+ //
12
+ // Removal: this shim will be removed in a future major version. A
13
+ // deprecation warning is printed once per process to stderr so existing
14
+ // users notice the rename without breaking their automation.
15
+
16
+ if (!process.env.PI_ANTIGRAVITY_ROTATOR_SHIM_QUIET) {
17
+ process.stderr.write(
18
+ "[deprecation] `pi-antigravity-rotator` has been renamed to `tuxevil-rotator`. " +
19
+ "This shim forwards to the new binary and will be removed in a future major version. " +
20
+ "See https://github.com/tuxevil/tuxevil-rotator/blob/main/docs/migrating-from-pi-antigravity-rotator.md\n",
21
+ );
22
+ }
23
+
24
+ import("tsx/esm/api").then(({ register }) => {
25
+ register();
26
+ return import("../src/cli.ts");
27
+ });
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import("tsx/esm/api").then(({ register }) => {
3
+ register();
4
+ return import("../src/cli.ts");
5
+ });
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "tuxevil-rotator",
3
+ "version": "3.0.0",
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
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "tuxevil-rotator": "bin/tuxevil-rotator.js",
9
+ "pi-antigravity-rotator": "bin/pi-antigravity-rotator.js"
10
+ },
11
+ "engines": {
12
+ "node": ">=22.0.0"
13
+ },
14
+ "scripts": {
15
+ "start": "tsx src/cli.ts start",
16
+ "login": "tsx src/cli.ts login",
17
+ "typecheck": "tsc --noEmit",
18
+ "typecheck:test": "tsc --project tsconfig.test.json",
19
+ "test": "ANTIGRAVITY_CLIENT_ID=test-client-id ANTIGRAVITY_CLIENT_SECRET=test-client-secret TUXEVIL_ROTATOR_DIR=/tmp/tuxevil-rotator-test node --import tsx/esm --test \"test/**/*.test.ts\"",
20
+ "lint": "eslint src test",
21
+ "coverage": "c8 --reporter=text --reporter=html --check-coverage --lines=60 --branches=50 --functions=60 --statements=60 npm test",
22
+ "check": "npm run typecheck && npm run typecheck:test && npm test && npm run lint"
23
+ },
24
+ "files": [
25
+ "bin/",
26
+ "src/",
27
+ "tools/telemetry-receiver/",
28
+ "CHANGELOG.md",
29
+ "README.md",
30
+ "LICENSE",
31
+ "tuxevil-rotator_logo.png"
32
+ ],
33
+ "keywords": [
34
+ "ai",
35
+ "proxy",
36
+ "rotation",
37
+ "multiprovider",
38
+ "antigravity",
39
+ "ollama",
40
+ "gemini",
41
+ "quota",
42
+ "load-balancing"
43
+ ],
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/tuxevil/tuxevil-rotator.git"
47
+ },
48
+ "author": "Sebasti\u00e1n Real (tuxevil)",
49
+ "dependencies": {
50
+ "pg": "^8.22.0",
51
+ "tsx": "^4.22.4",
52
+ "undici": "^7.29.0"
53
+ },
54
+ "devDependencies": {
55
+ "@eslint/js": "^10.0.1",
56
+ "@types/node": "^22.20.0",
57
+ "@types/pg": "^8.20.0",
58
+ "c8": "^11.0.0",
59
+ "eslint": "^10.6.0",
60
+ "typescript": "^5.7.0",
61
+ "typescript-eslint": "^8.62.1"
62
+ }
63
+ }