tuxevil-rotator 4.2.1 → 4.2.2
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 +21 -0
- package/README.md +11 -2
- package/package.json +3 -3
- package/plugins/opencode-discovery/index.d.mts +59 -0
- package/plugins/opencode-discovery/index.mjs +328 -0
- package/plugins/opencode-discovery/package.json +22 -0
- package/src/compat.ts +4 -5
- package/src/install-agent.ts +47 -20
- package/src/install-opencode.ts +138 -32
- package/src/providers/google-antigravity/catalog.ts +34 -163
- package/src/providers/google-antigravity/dynamic-catalog.ts +28 -7
- package/src/providers/google-antigravity/index.ts +12 -4
- package/src/providers/google-antigravity/quota.ts +5 -7
- package/src/proxy.ts +20 -4
- package/src/rotator.ts +16 -20
- package/src/types.ts +1 -38
- package/plugins/opencode-discovery.js +0 -174
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [4.2.2] - 2026-10-24
|
|
6
|
+
|
|
7
|
+
### Security
|
|
8
|
+
|
|
9
|
+
- Require Node.js 22.23.4+ on 22.x, 24.22.1+ on 24.x, or 26.12.1+ to address the bundled Brotli decoder vulnerability [CVE-2026-111497](https://nodejs.org/en/blog/vulnerability/october-2026-security-releases). Pin Docker and CI to Node.js 22.23.4 and document runtime upgrades and service restarts. Updating npm dependencies alone does not patch an existing Node.js process. ([PR #41](https://github.com/tuxevil/tuxevil-rotator/pull/41))
|
|
10
|
+
- Update the direct Undici dependency to 7.30.1 for its upstream security fixes.
|
|
11
|
+
- Replace the OpenCode discovery plugin's quadratic trailing-slash regular expression with a linear scan. Long slash sequences in configured base URLs can no longer block plugin startup through regular-expression backtracking (CodeQL alert #53). Add regression coverage for large matching and nonmatching inputs and URL normalization behavior.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Discover Antigravity models from live account quota snapshots instead of advertising retired static model IDs. Preserve valid snapshots on malformed quota-only responses and keep request reservations scoped to the provider when model IDs overlap.
|
|
16
|
+
- Update the OpenCode discovery plugin and installers to the OpenCode 2 plugin API and configuration format.
|
|
17
|
+
|
|
18
|
+
### Documentation
|
|
19
|
+
|
|
20
|
+
- Add English and Spanish agent installation prompts covering account logins, background services and agent configuration, and surface them in the README and repository agent instructions.
|
|
21
|
+
|
|
22
|
+
### Contributors
|
|
23
|
+
|
|
24
|
+
- Thanks to [@CyR1en](https://github.com/CyR1en) for the Node.js and Undici security updates and deployment guidance in [PR #41](https://github.com/tuxevil/tuxevil-rotator/pull/41).
|
|
25
|
+
|
|
5
26
|
## [4.2.1] - 2026-10-17
|
|
6
27
|
|
|
7
28
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/tuxevil-rotator)
|
|
4
|
-
[](package.json)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://github.com/tuxevil/tuxevil-rotator/actions)
|
|
7
7
|
[](https://www.typescriptlang.org)
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
|
|
25
25
|
**Production-ready OpenAI-compatible gateway for multiple free-tier LLM providers.**
|
|
26
26
|
|
|
27
|
+
> **Not a developer? No manual steps needed.** Ask your AI agent (OpenCode, Codex, Claude Code, Cursor, Cline…) to: *"Install tuxevil-rotator following docs/agent-install-prompt.md"* — that file contains a ready-made copy-paste prompt (English and Spanish) that walks your agent through the whole installation, account logins, background service, and wiring your agent to it.
|
|
28
|
+
|
|
27
29
|
> **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
30
|
|
|
29
31
|
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.
|
|
@@ -53,6 +55,8 @@ Originally built as a multi-account rotator for Google Antigravity. It now gener
|
|
|
53
55
|
|
|
54
56
|
## Current Model Update
|
|
55
57
|
|
|
58
|
+
- **v4.2.2: Security updates and dynamic model discovery**: Requires patched Node.js releases (22.23.4+, 24.22.1+, or 26.12.1+ on their supported release lines), updates Undici to 7.30.1, and prevents long URL slash sequences from blocking the OpenCode discovery plugin. Antigravity models now follow live account catalogs, and installers use the OpenCode 2 plugin API. Upgrade Node.js and restart existing rotator services after updating the package. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.2.2); [PR #41](https://github.com/tuxevil/tuxevil-rotator/pull/41) by [@CyR1en](https://github.com/CyR1en))
|
|
59
|
+
|
|
56
60
|
- **v4.2.0: Effort routing editor**: Create, edit, rename and disable effort aliases from the Models page, with route previews and unsaved-edit protection. Claude-style requests now select variants from `output_config.effort` or thinking budgets, and model configuration edits apply immediately. Includes automatic discovery of future Codex GPT models across account catalogs. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.2.0); [PR #40](https://github.com/tuxevil/tuxevil-rotator/pull/40) by [@CyR1en](https://github.com/CyR1en))
|
|
57
61
|
|
|
58
62
|
- **v4.1.0: Models and provider controls**: Manage provider order, provider and per-account switches, individual model availability, and review of newly discovered models at `/dashboard/models`. Controls apply to aliases, automatic routing, native requests, audio, benchmarks, and warm-up. Includes Ollama credit-balance polling and clearer Codex reauthentication status. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.1.0); [PR #39](https://github.com/tuxevil/tuxevil-rotator/pull/39) by [@CyR1en](https://github.com/CyR1en))
|
|
@@ -171,7 +175,9 @@ Existing `enc:v1` records remain decryptable during migration; newly written rec
|
|
|
171
175
|
|
|
172
176
|
## Quick Start
|
|
173
177
|
|
|
174
|
-
**Requirements:** Node.js 22+ for npm/source installs. Docker image uses Node 22.
|
|
178
|
+
**Requirements:** Node.js 22.23.4+ on 22.x, 24.22.1+ on 24.x, or 26.12.1+ for npm/source installs. The Docker image uses Node 22.23.4. These releases fix the [Brotli decoder vulnerability, CVE-2026-111497](https://nodejs.org/en/blog/vulnerability/october-2026-security-releases). Restart the rotator after upgrading Node.js.
|
|
179
|
+
|
|
180
|
+
> **Non-technical? Don't follow the steps — paste a prompt instead.** Copy the ready-made install prompt from [`docs/agent-install-prompt.md`](docs/agent-install-prompt.md) (English and Spanish versions) into your AI agent — OpenCode, Codex, Claude Code, Cursor, Cline… — and it installs the rotator, walks you through the account logins, runs it as a background service, and wires your agent to it automatically.
|
|
175
181
|
|
|
176
182
|
### Option A: npm
|
|
177
183
|
|
|
@@ -234,6 +240,8 @@ tuxevil-rotator install-agent --target auto
|
|
|
234
240
|
|
|
235
241
|
Use `--target all` or a comma-separated list (`opencode,hermes,pi,codex`) to choose clients. Add `--host <hostname> --user <ssh-user>` to configure them over SSH, or `--dry-run` to review the generated installer first. For OpenCode's live model catalog, use `tuxevil-rotator install-opencode`; see the [OpenCode integration guide](docs/integrations/opencode.md).
|
|
236
242
|
|
|
243
|
+
> **Rather have your agent do all of this?** The [`agent-install-prompt`](docs/agent-install-prompt.md) is a copy-paste prompt (English/Spanish) that makes any coding agent perform the whole setup for a non-technical user: install, account logins with hand-holding, background service, agent wiring, and verification.
|
|
244
|
+
|
|
237
245
|
| Agent | Guide |
|
|
238
246
|
|-------|-------|
|
|
239
247
|
| Pi | [docs/integrations/pi.md](docs/integrations/pi.md) |
|
|
@@ -333,6 +341,7 @@ tuxevil-rotator keys generate --alias "cursor-agent" --models "gemini-3.6-flash-
|
|
|
333
341
|
| Migration from pi-antigravity-rotator | [docs/migrating-from-pi-antigravity-rotator.md](docs/migrating-from-pi-antigravity-rotator.md) |
|
|
334
342
|
| Troubleshooting | [docs/troubleshooting.md](docs/troubleshooting.md) |
|
|
335
343
|
| Telemetry | [docs/telemetry.md](docs/telemetry.md) |
|
|
344
|
+
| One-Prompt Agent Install | [docs/agent-install-prompt.md](docs/agent-install-prompt.md) |
|
|
336
345
|
| PostgreSQL Setup | [docs/integrations/setup-postgresql.md](docs/integrations/setup-postgresql.md) |
|
|
337
346
|
|
|
338
347
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuxevil-rotator",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
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",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"pi-antigravity-rotator": "bin/pi-antigravity-rotator.js"
|
|
10
10
|
},
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": "
|
|
12
|
+
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"start": "tsx src/cli.ts start",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"pg": "^8.22.0",
|
|
56
56
|
"preact": "^10.29.8",
|
|
57
57
|
"tsx": "^4.22.4",
|
|
58
|
-
"undici": "^7.
|
|
58
|
+
"undici": "^7.30.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@eslint/js": "^10.0.1",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loose ambient types for plugins/opencode-discovery/index.mjs, so the repo's
|
|
3
|
+
* TS tests can import the untyped module without pull-in of @opencode/plugin.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface ProviderEntry {
|
|
7
|
+
id?: string;
|
|
8
|
+
providerID?: string;
|
|
9
|
+
name?: string | null;
|
|
10
|
+
baseURL?: string | null;
|
|
11
|
+
info?: {
|
|
12
|
+
id?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
settings?: { baseURL?: string };
|
|
15
|
+
};
|
|
16
|
+
provider?: {
|
|
17
|
+
id?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
settings?: { baseURL?: string };
|
|
20
|
+
};
|
|
21
|
+
settings?: { baseURL?: string };
|
|
22
|
+
options?: { baseURL?: string };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ResolvedOptions {
|
|
26
|
+
baseURL: string;
|
|
27
|
+
providerID: string;
|
|
28
|
+
providerName: string;
|
|
29
|
+
timeoutMs: number;
|
|
30
|
+
refreshMs: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface RawRotatorModel {
|
|
34
|
+
id: string;
|
|
35
|
+
meta?: Record<string, unknown>;
|
|
36
|
+
info?: Record<string, unknown>;
|
|
37
|
+
context_window?: number;
|
|
38
|
+
max_model_len?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ModelDef {
|
|
42
|
+
name: string;
|
|
43
|
+
limit: { context: number; output: number };
|
|
44
|
+
capabilities: { tools: boolean; input: string[]; output: string[] };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function normalizeProviderEntries(input: unknown): ProviderEntry[];
|
|
48
|
+
export function resolvePluginOptions(
|
|
49
|
+
options?: Record<string, unknown>,
|
|
50
|
+
providerEntries?: unknown,
|
|
51
|
+
): ResolvedOptions;
|
|
52
|
+
export function fetchRotatorModels(baseURL: string, timeoutMs?: number): Promise<RawRotatorModel[]>;
|
|
53
|
+
export function mapModelToOpenCode(rawModel: RawRotatorModel): { id: string; modelDef: ModelDef };
|
|
54
|
+
|
|
55
|
+
const plugin: {
|
|
56
|
+
id: string;
|
|
57
|
+
setup(ctx: unknown): Promise<(() => void) | undefined>;
|
|
58
|
+
};
|
|
59
|
+
export default plugin;
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode V2 Model Discovery Plugin for tuxevil-rotator
|
|
3
|
+
*
|
|
4
|
+
* Fetches the active model list from a tuxevil-rotator (or any OpenAI-compatible)
|
|
5
|
+
* /v1/models endpoint and registers / refreshes the provider through the OpenCode 2
|
|
6
|
+
* plugin API (`ctx.provider.transform`).
|
|
7
|
+
*
|
|
8
|
+
* Replaces the V1 `plugins/opencode-discovery.js`, whose function-style default
|
|
9
|
+
* export OpenCode 2.x refuses to load ("Plugin must export a default definition
|
|
10
|
+
* with an id and an effect or setup function").
|
|
11
|
+
*
|
|
12
|
+
* Options (`plugins[].options` in opencode.json):
|
|
13
|
+
* - baseURL explicit rotator endpoint (else env, else config scan, else default)
|
|
14
|
+
* - providerID target provider id (default "antigravity")
|
|
15
|
+
* - providerName display name (default "Antigravity (rotator)")
|
|
16
|
+
* - timeoutMs fetch timeout (default 3500)
|
|
17
|
+
* - refreshMs background re-discovery interval (default 600000; 0 disables)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const PLUGIN_ID = "tuxevil.model-discovery"
|
|
21
|
+
const DEFAULT_BASE_URL = "http://127.0.0.1:51200/v1"
|
|
22
|
+
const DEFAULT_PROVIDER_PACKAGE = "@opencode/ai/providers/openai-compatible"
|
|
23
|
+
|
|
24
|
+
// The host provides `@opencode/plugin` at runtime and redirects the import to its
|
|
25
|
+
// own instance; outside OpenCode (unit tests) the import simply fails and the
|
|
26
|
+
// guarded helpers below fall back to plain objects.
|
|
27
|
+
let SDK = {}
|
|
28
|
+
try {
|
|
29
|
+
SDK = await import("@opencode/plugin")
|
|
30
|
+
} catch {
|
|
31
|
+
SDK = {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function makeModelID(id) {
|
|
35
|
+
try {
|
|
36
|
+
return SDK?.Model?.ID?.make?.(id) ?? id
|
|
37
|
+
} catch {
|
|
38
|
+
return id
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function makeProviderID(id) {
|
|
43
|
+
try {
|
|
44
|
+
return SDK?.Provider?.ID?.make?.(id) ?? id
|
|
45
|
+
} catch {
|
|
46
|
+
return id
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function modelInfoDefault(providerID, id) {
|
|
51
|
+
try {
|
|
52
|
+
return SDK?.Model?.Info?.default?.(makeProviderID(providerID), makeModelID(id)) ?? {}
|
|
53
|
+
} catch {
|
|
54
|
+
return {}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function providerInfoEmpty(providerID) {
|
|
59
|
+
try {
|
|
60
|
+
return SDK?.Provider?.Info?.empty?.(makeProviderID(providerID)) ?? {}
|
|
61
|
+
} catch {
|
|
62
|
+
return {}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Normalizes the many shapes a provider collection can take into
|
|
68
|
+
* `{ id, name, baseURL }` records.
|
|
69
|
+
*
|
|
70
|
+
* Accepted inputs:
|
|
71
|
+
* - V2 `ctx.provider.list()` output (array or `{ providers }`)
|
|
72
|
+
* - V2 provider records (`{ info: { name, settings: { baseURL } } }`)
|
|
73
|
+
* - V1 `config.provider` maps (`{ [id]: { name, options: { baseURL } } }`)
|
|
74
|
+
*/
|
|
75
|
+
export function normalizeProviderEntries(input) {
|
|
76
|
+
let list
|
|
77
|
+
if (Array.isArray(input)) {
|
|
78
|
+
list = input
|
|
79
|
+
} else if (input && typeof input === "object" && Array.isArray(input.providers)) {
|
|
80
|
+
list = input.providers
|
|
81
|
+
} else if (input && typeof input === "object") {
|
|
82
|
+
list = Object.entries(input).map(([id, value]) => ({ id, ...value }))
|
|
83
|
+
} else {
|
|
84
|
+
list = []
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return list
|
|
88
|
+
.map((entry) => {
|
|
89
|
+
const id =
|
|
90
|
+
entry?.id ?? entry?.providerID ?? entry?.info?.id ?? entry?.provider?.id ?? (typeof entry === "string" ? entry : undefined)
|
|
91
|
+
if (!id) return null
|
|
92
|
+
const baseURL =
|
|
93
|
+
entry?.info?.settings?.baseURL ??
|
|
94
|
+
entry?.settings?.baseURL ??
|
|
95
|
+
entry?.provider?.settings?.baseURL ??
|
|
96
|
+
entry?.options?.baseURL ??
|
|
97
|
+
entry?.baseURL ??
|
|
98
|
+
null
|
|
99
|
+
const name =
|
|
100
|
+
entry?.info?.name ?? entry?.provider?.name ?? entry?.name ?? null
|
|
101
|
+
return { id, name, baseURL }
|
|
102
|
+
})
|
|
103
|
+
.filter(Boolean)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Resolves the options for this plugin run.
|
|
108
|
+
* Precedence (same as the V1 plugin):
|
|
109
|
+
* 1. explicit plugin options
|
|
110
|
+
* 2. environment variables (TUXEVIL_ROTATOR_BASE_URL, ROTATOR_URL)
|
|
111
|
+
* 3. discovered provider whose baseURL mentions 51200 / rotator / antigravity
|
|
112
|
+
* 4. default http://127.0.0.1:51200/v1
|
|
113
|
+
*/
|
|
114
|
+
export function resolvePluginOptions(options = {}, providerEntries = []) {
|
|
115
|
+
const entries = normalizeProviderEntries(providerEntries)
|
|
116
|
+
const envBaseURL = process.env.TUXEVIL_ROTATOR_BASE_URL || process.env.ROTATOR_URL
|
|
117
|
+
|
|
118
|
+
let baseURL = options.baseURL || envBaseURL || null
|
|
119
|
+
let providerID = options.providerID || null
|
|
120
|
+
let providerName = options.providerName || null
|
|
121
|
+
|
|
122
|
+
if (!baseURL) {
|
|
123
|
+
const found = entries.find((entry) => {
|
|
124
|
+
const url = entry.baseURL
|
|
125
|
+
return typeof url === "string" && (url.includes("51200") || url.includes("rotator") || url.includes("antigravity"))
|
|
126
|
+
})
|
|
127
|
+
if (found) {
|
|
128
|
+
baseURL = found.baseURL ?? null
|
|
129
|
+
if (!providerID) providerID = found.id
|
|
130
|
+
if (!providerName) providerName = found.name
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Scan backwards once so a long internal slash run cannot cause ReDoS.
|
|
135
|
+
const baseURLText = String(baseURL ?? DEFAULT_BASE_URL)
|
|
136
|
+
let end = baseURLText.length
|
|
137
|
+
while (end > 0 && baseURLText.charCodeAt(end - 1) === 47) end--
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
baseURL: baseURLText.slice(0, end),
|
|
141
|
+
providerID: providerID || "antigravity",
|
|
142
|
+
providerName: providerName || "Antigravity (rotator)",
|
|
143
|
+
timeoutMs: Number(options.timeoutMs) || 3500,
|
|
144
|
+
refreshMs: options.refreshMs === 0 ? 0 : Number(options.refreshMs) || 600_000,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Fetches available models from the target rotator endpoint.
|
|
150
|
+
*/
|
|
151
|
+
export async function fetchRotatorModels(baseURL, timeoutMs = 3500) {
|
|
152
|
+
const modelsUrl = `${baseURL}/models`
|
|
153
|
+
let url
|
|
154
|
+
try {
|
|
155
|
+
url = new URL(modelsUrl)
|
|
156
|
+
} catch {
|
|
157
|
+
throw new Error(`fetch() URL is invalid: "${modelsUrl}" (bad baseURL "${baseURL}")`)
|
|
158
|
+
}
|
|
159
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
160
|
+
throw new Error(`Unsupported URL protocol in "${modelsUrl}"`)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const controller = new AbortController()
|
|
164
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
const res = await fetch(url, {
|
|
168
|
+
signal: controller.signal,
|
|
169
|
+
headers: { Accept: "application/json" },
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
if (!res.ok) {
|
|
173
|
+
throw new Error(`Endpoint returned status ${res.status}: ${res.statusText}`)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const json = await res.json()
|
|
177
|
+
if (!json || !Array.isArray(json.data)) {
|
|
178
|
+
throw new Error('Invalid response format: "data" array not found')
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return json.data
|
|
182
|
+
} finally {
|
|
183
|
+
clearTimeout(timer)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Maps a raw model object from the rotator /v1/models endpoint to an
|
|
189
|
+
* OpenCode model definition core (limit + capabilities).
|
|
190
|
+
*/
|
|
191
|
+
export function mapModelToOpenCode(rawModel) {
|
|
192
|
+
const id = rawModel.id
|
|
193
|
+
const meta = rawModel.meta || rawModel.info || {}
|
|
194
|
+
|
|
195
|
+
const contextLimit =
|
|
196
|
+
Number(meta.context_length) || Number(rawModel.context_window) || Number(rawModel.max_model_len) || 128000
|
|
197
|
+
const outputLimit = Number(meta.max_output_tokens) || 8192
|
|
198
|
+
|
|
199
|
+
const isMultimodal = Boolean(meta.multimodal)
|
|
200
|
+
const toolCalling = meta.tool_calling !== false
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
id,
|
|
204
|
+
modelDef: {
|
|
205
|
+
name: id,
|
|
206
|
+
limit: { context: contextLimit, output: outputLimit },
|
|
207
|
+
capabilities: {
|
|
208
|
+
tools: toolCalling,
|
|
209
|
+
input: isMultimodal ? ["text", "image"] : ["text"],
|
|
210
|
+
output: ["text"],
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function toModelMap(models) {
|
|
217
|
+
if (models instanceof Map) return models
|
|
218
|
+
if (models && typeof models === "object") return new Map(Object.entries(models))
|
|
219
|
+
return new Map()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function safeGet(editor, id) {
|
|
223
|
+
try {
|
|
224
|
+
return editor?.get?.(id)
|
|
225
|
+
} catch {
|
|
226
|
+
return undefined
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function modelSignature(models) {
|
|
231
|
+
return JSON.stringify(
|
|
232
|
+
(models ?? [])
|
|
233
|
+
.map((model) => model?.id)
|
|
234
|
+
.filter(Boolean)
|
|
235
|
+
.sort(),
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function mergeProviderInfo(existingProvider, resolved) {
|
|
240
|
+
const prior = existingProvider ?? {}
|
|
241
|
+
return {
|
|
242
|
+
...providerInfoEmpty(resolved.providerID),
|
|
243
|
+
...prior,
|
|
244
|
+
name: prior.name || resolved.providerName,
|
|
245
|
+
activation: prior.activation || "enabled",
|
|
246
|
+
package: prior.package || DEFAULT_PROVIDER_PACKAGE,
|
|
247
|
+
settings: { ...(prior.settings ?? {}), baseURL: resolved.baseURL },
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* OpenCode V2 Plugin Entrypoint (plain-object definition, same pattern the
|
|
253
|
+
* official @openviking/opencode-plugin uses).
|
|
254
|
+
*/
|
|
255
|
+
export default {
|
|
256
|
+
id: PLUGIN_ID,
|
|
257
|
+
async setup(ctx) {
|
|
258
|
+
const options = (ctx && ctx.options) || {}
|
|
259
|
+
let entries
|
|
260
|
+
try {
|
|
261
|
+
entries = normalizeProviderEntries(await ctx?.provider?.list?.())
|
|
262
|
+
} catch {
|
|
263
|
+
entries = []
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const resolved = resolvePluginOptions(options, entries)
|
|
267
|
+
const source = { models: null }
|
|
268
|
+
let lastSignature = null
|
|
269
|
+
|
|
270
|
+
async function load() {
|
|
271
|
+
try {
|
|
272
|
+
const models = await fetchRotatorModels(resolved.baseURL, resolved.timeoutMs)
|
|
273
|
+
const list = Array.isArray(models) ? models : []
|
|
274
|
+
const changed = lastSignature !== null && modelSignature(list) !== lastSignature
|
|
275
|
+
source.models = list
|
|
276
|
+
lastSignature = modelSignature(list)
|
|
277
|
+
return { ok: true, changed }
|
|
278
|
+
} catch (err) {
|
|
279
|
+
// Safe degrade: never fail OpenCode startup when the rotator is unreachable
|
|
280
|
+
console.warn(`[opencode-discovery] model discovery skipped: ${err?.message ?? err}`)
|
|
281
|
+
return { ok: false, changed: false }
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const first = await load()
|
|
286
|
+
if (!first.ok || !source.models?.length) return undefined
|
|
287
|
+
|
|
288
|
+
const toModelInfo = (raw, existingModel) => {
|
|
289
|
+
const { id, modelDef } = mapModelToOpenCode(raw)
|
|
290
|
+
return {
|
|
291
|
+
...modelInfoDefault(resolved.providerID, id),
|
|
292
|
+
...(existingModel ?? {}),
|
|
293
|
+
id: makeModelID(id),
|
|
294
|
+
name: existingModel?.name || modelDef.name,
|
|
295
|
+
capabilities: { ...modelDef.capabilities, ...(existingModel?.capabilities ?? {}) },
|
|
296
|
+
limit: { ...modelDef.limit, ...(existingModel?.limit ?? {}) },
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
await ctx.provider.transform((editor) => {
|
|
301
|
+
if (!source.models?.length) return
|
|
302
|
+
const existing = safeGet(editor, resolved.providerID)
|
|
303
|
+
const existingModels = toModelMap(existing?.models)
|
|
304
|
+
const models = source.models.flatMap((raw) =>
|
|
305
|
+
raw?.id ? [toModelInfo(raw, existingModels.get(raw.id) ?? null)] : [],
|
|
306
|
+
)
|
|
307
|
+
editor.add({ info: mergeProviderInfo(existing?.provider, resolved), models })
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
if (resolved.refreshMs <= 0) return undefined
|
|
311
|
+
|
|
312
|
+
const timer = setInterval(() => {
|
|
313
|
+
void (async () => {
|
|
314
|
+
const result = await load()
|
|
315
|
+
if (!result.changed) return
|
|
316
|
+
try {
|
|
317
|
+
await ctx.provider.reload()
|
|
318
|
+
} catch {
|
|
319
|
+
// Registry reload unavailable; keep the last known inventory
|
|
320
|
+
}
|
|
321
|
+
})()
|
|
322
|
+
}, resolved.refreshMs)
|
|
323
|
+
if (typeof timer.unref === "function") timer.unref()
|
|
324
|
+
|
|
325
|
+
return () => clearInterval(timer)
|
|
326
|
+
},
|
|
327
|
+
}
|
|
328
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tuxevil-opencode-discovery",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OpenCode V2 plugin that discovers tuxevil-rotator models and registers the provider",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.mjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.mjs",
|
|
12
|
+
"index.d.mts"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"opencode",
|
|
16
|
+
"opencode-plugin",
|
|
17
|
+
"openviking",
|
|
18
|
+
"rotator",
|
|
19
|
+
"model-discovery"
|
|
20
|
+
],
|
|
21
|
+
"license": "Apache-2.0"
|
|
22
|
+
}
|
package/src/compat.ts
CHANGED
|
@@ -2602,11 +2602,10 @@ function getOpenAIAntigravityModels(
|
|
|
2602
2602
|
/**
|
|
2603
2603
|
* Build the OpenAI-compatible `/v1/models` catalog for the proxy.
|
|
2604
2604
|
*
|
|
2605
|
-
*
|
|
2606
|
-
*
|
|
2607
|
-
*
|
|
2608
|
-
*
|
|
2609
|
-
* by the provider its requests go to.
|
|
2605
|
+
* Dynamically discovered Antigravity models are included unless Antigravity is
|
|
2606
|
+
* turned off. An active rotator also contributes its other providers. Models
|
|
2607
|
+
* turned off on the dashboard's Models page are left out, and an id more than
|
|
2608
|
+
* one provider lists appears once, owned by the provider its requests go to.
|
|
2610
2609
|
*/
|
|
2611
2610
|
export function buildOpenAIModelCatalog(
|
|
2612
2611
|
rotator?: AccountRotator,
|
package/src/install-agent.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { resolve, dirname } from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const
|
|
7
|
+
const OPENCODE_PLUGIN_SOURCE_DIR = resolve(__dirname, "../plugins/opencode-discovery");
|
|
8
|
+
const OPENCODE_PLUGIN_RUNTIME_FILES = ["index.mjs", "package.json"];
|
|
8
9
|
|
|
9
10
|
export type SupportedAgent = "opencode" | "hermes" | "pi" | "codex";
|
|
10
11
|
|
|
@@ -25,7 +26,7 @@ export interface AgentInstallOptions {
|
|
|
25
26
|
* Builds the composite shell script that detects and configures all requested agents.
|
|
26
27
|
*/
|
|
27
28
|
export function buildCompositeInstallerScript(
|
|
28
|
-
|
|
29
|
+
opencodePluginFiles: Record<string, string>,
|
|
29
30
|
options: {
|
|
30
31
|
targets: Array<SupportedAgent | "auto" | "all">;
|
|
31
32
|
rotatorUrl: string;
|
|
@@ -34,7 +35,14 @@ export function buildCompositeInstallerScript(
|
|
|
34
35
|
apiKey?: string;
|
|
35
36
|
}
|
|
36
37
|
): string {
|
|
37
|
-
|
|
38
|
+
if (!OPENCODE_PLUGIN_RUNTIME_FILES.every((name) => name in opencodePluginFiles)) {
|
|
39
|
+
throw new Error(`opencodePluginFiles must include all of: ${OPENCODE_PLUGIN_RUNTIME_FILES.join(", ")}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const pluginFileWriteLines = OPENCODE_PLUGIN_RUNTIME_FILES.map((name) => {
|
|
43
|
+
const base64 = Buffer.from(opencodePluginFiles[name], "utf8").toString("base64");
|
|
44
|
+
return `echo "${base64}" | base64 -d > "$OPENCODE_DIR/plugins/opencode-discovery/${name}"`;
|
|
45
|
+
}).join("\n");
|
|
38
46
|
const rotatorUrl = options.rotatorUrl.replace(/\/+$/, "");
|
|
39
47
|
const providerId = options.providerId || "tuxevil-rotator";
|
|
40
48
|
const providerName = options.providerName || "Tuxevil Rotator";
|
|
@@ -83,15 +91,15 @@ OPENCODE_DIR="$HOME/.config/opencode"
|
|
|
83
91
|
if should_install "opencode" "$OPENCODE_DIR"; then
|
|
84
92
|
echo ""
|
|
85
93
|
echo "==> [OpenCode] Configuring in $OPENCODE_DIR..."
|
|
86
|
-
mkdir -p "$OPENCODE_DIR/plugins"
|
|
87
|
-
|
|
94
|
+
mkdir -p "$OPENCODE_DIR/plugins/opencode-discovery"
|
|
95
|
+
${pluginFileWriteLines}
|
|
88
96
|
|
|
89
97
|
node -e '
|
|
90
98
|
const fs = require("fs");
|
|
91
99
|
const path = require("path");
|
|
92
100
|
|
|
93
101
|
const configFile = path.join(process.env.HOME, ".config/opencode/opencode.json");
|
|
94
|
-
const
|
|
102
|
+
const pluginDir = path.join(process.env.HOME, ".config/opencode/plugins/opencode-discovery");
|
|
95
103
|
const providerID = process.argv[1];
|
|
96
104
|
const providerName = process.argv[2];
|
|
97
105
|
const baseURL = process.argv[3];
|
|
@@ -109,19 +117,34 @@ if should_install "opencode" "$OPENCODE_DIR"; then
|
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
config.$schema = config.$schema || "https://opencode.ai/config.json";
|
|
112
|
-
config.plugin = Array.isArray(config.plugin) ? config.plugin : [];
|
|
113
120
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
const isDiscoveryEntry = (entry) => {
|
|
122
|
+
if (typeof entry === "string") return entry.includes("opencode-discovery");
|
|
123
|
+
if (Array.isArray(entry)) {
|
|
124
|
+
return typeof entry[0] === "string" && entry[0].includes("opencode-discovery");
|
|
125
|
+
}
|
|
126
|
+
if (entry && typeof entry === "object") {
|
|
127
|
+
return typeof entry.package === "string" && entry.package.includes("opencode-discovery");
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// V2 plugin list: scrub prior discovery entries, then register the directory
|
|
133
|
+
config.plugins = Array.isArray(config.plugins) ? config.plugins.filter(p => !isDiscoveryEntry(p)) : [];
|
|
134
|
+
config.plugins.push({
|
|
135
|
+
package: pluginDir,
|
|
136
|
+
options: { baseURL, providerID, providerName }
|
|
119
137
|
});
|
|
120
138
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
// Legacy V1 key: scrub discovery entries, keep everything else untouched
|
|
140
|
+
if (Array.isArray(config.plugin)) {
|
|
141
|
+
const kept = config.plugin.filter(p => !isDiscoveryEntry(p));
|
|
142
|
+
if (kept.length > 0) {
|
|
143
|
+
config.plugin = kept;
|
|
144
|
+
} else {
|
|
145
|
+
delete config.plugin;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
125
148
|
|
|
126
149
|
config.provider = config.provider || {};
|
|
127
150
|
config.provider[providerID] = config.provider[providerID] || {
|
|
@@ -383,11 +406,15 @@ echo "==> All target agents processed successfully!"
|
|
|
383
406
|
* Installs configuration for one or more agents locally or over SSH.
|
|
384
407
|
*/
|
|
385
408
|
export async function installAgents(options: AgentInstallOptions): Promise<void> {
|
|
386
|
-
if (!existsSync(
|
|
387
|
-
throw new Error(`OpenCode plugin
|
|
409
|
+
if (!existsSync(resolve(OPENCODE_PLUGIN_SOURCE_DIR, "index.mjs"))) {
|
|
410
|
+
throw new Error(`OpenCode plugin directory missing index.mjs at ${OPENCODE_PLUGIN_SOURCE_DIR}`);
|
|
388
411
|
}
|
|
389
412
|
|
|
390
|
-
const
|
|
413
|
+
const opencodePluginFiles: Record<string, string> = {};
|
|
414
|
+
for (const name of OPENCODE_PLUGIN_RUNTIME_FILES) {
|
|
415
|
+
const filePath = resolve(OPENCODE_PLUGIN_SOURCE_DIR, name);
|
|
416
|
+
opencodePluginFiles[name] = readFileSync(filePath, "utf8");
|
|
417
|
+
}
|
|
391
418
|
const rotatorUrl = (
|
|
392
419
|
options.rotatorUrl ||
|
|
393
420
|
process.env.TUXEVIL_ROTATOR_BASE_URL ||
|
|
@@ -399,7 +426,7 @@ export async function installAgents(options: AgentInstallOptions): Promise<void>
|
|
|
399
426
|
const providerName = options.providerName || "Tuxevil Rotator";
|
|
400
427
|
const targets: Array<SupportedAgent | "auto" | "all"> = options.targets && options.targets.length > 0 ? options.targets : ["auto"];
|
|
401
428
|
|
|
402
|
-
const script = buildCompositeInstallerScript(
|
|
429
|
+
const script = buildCompositeInstallerScript(opencodePluginFiles, {
|
|
403
430
|
targets,
|
|
404
431
|
rotatorUrl,
|
|
405
432
|
providerId,
|