tuxevil-rotator 3.9.0 → 3.10.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 +35 -7
- package/README.md +3 -1
- package/package.json +3 -2
- package/plugins/opencode-discovery.d.ts +65 -0
- package/plugins/opencode-discovery.js +174 -0
- package/src/audio-transcription.ts +1265 -117
- package/src/cli.ts +130 -0
- package/src/compat/model-specs.ts +59 -58
- package/src/compat/schema-sanitizer.ts +11 -3
- package/src/compat.ts +4 -4
- package/src/index.ts +39 -1
- package/src/install-agent.ts +453 -0
- package/src/install-opencode.ts +201 -0
- package/src/key-auth.ts +69 -5
- package/src/providers/google-antigravity/dynamic-catalog.ts +1 -1
- package/src/providers/google-antigravity/translators.ts +16 -0
- package/src/proxy.ts +36 -3
- package/src/rotator.ts +52 -7
- package/src/telemetry.ts +32 -2
- package/src/types.ts +2 -3
- package/tools/telemetry-receiver/README.md +3 -1
- package/tools/telemetry-receiver/receiver.js +36 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## [3.10.0] - 2026-09-28
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Rotator-backed audio transcription and live streaming**: `/v1/audio/transcriptions` and live WebSocket sessions use active Antigravity accounts for Gemini transcription, with Language Server fallback after rotator failures and timeouts. Model scopes follow the executed model; live sessions preserve segment order, use bounded deadlines, echo Ping payloads, and honor client cancellation ([PR #36](https://github.com/tuxevil/tuxevil-rotator/pull/36) by [@javargasm](https://github.com/javargasm)).
|
|
10
|
+
- **Actionable account-flag telemetry**: flag events can carry Google's reason code and a short privacy-filtered message. The reference receiver stores the reason, reports counts by reason, and lists recent incidents in its protected dashboard.
|
|
11
|
+
|
|
12
|
+
### Improved
|
|
13
|
+
|
|
14
|
+
- **Google account-verification diagnostics**: account-enforcement responses retain Google's reason and message in the rotator's flag state, including kickstart failures, so operators can tell account verification requirements from model-specific access errors.
|
|
15
|
+
- **Claude tool-schema compatibility**: Claude tool schemas sent through Gemini drop unsupported `uniqueItems` and normalize boolean enums while retaining valid string enums, fixing tool requests such as Claude Opus 4.6 Thinking.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **Gemini tool responses with schema references**: unresolved `$ref` values in function responses are preserved as text instead of being reinterpreted as Gemini's special response-part metadata.
|
|
20
|
+
- **Ollama content-array normalization**: multimodal OpenAI-style content arrays are flattened to text and image blocks are moved into Ollama's native `images` field.
|
|
21
|
+
- **Native Ollama chat requests and startup discovery**: `/api/chat` now accepts Ollama's native request shape, and the Ollama model catalog is loaded at startup so routing and `/v1/models` see it immediately.
|
|
22
|
+
- **Ollama tool arguments and quota reporting**: JSON-encoded tool arguments are normalized for Ollama, and monthly quota pools are parsed and reported consistently.
|
|
23
|
+
|
|
3
24
|
## [3.9.0] - 2026-09-22
|
|
4
25
|
|
|
5
26
|
### Added
|
|
@@ -47,6 +68,20 @@
|
|
|
47
68
|
- **Codex kickstart lifecycle**: Unstarted Codex quota timers are now kicked off on startup; stale kickstart responses are drained to avoid blocking subsequent requests.
|
|
48
69
|
- **Ollama pricing and forecast label**: Corrected the Ollama pricing entry and aligned the forecast label shown in the dashboard.
|
|
49
70
|
|
|
71
|
+
### Changed
|
|
72
|
+
|
|
73
|
+
- **Audio model scopes follow the executed model**: `/v1/audio/transcriptions` and the audio WebSocket now check virtual-key model scopes against the model that actually runs upstream (plus the requested name), and record spend under that model. Keys scoped to the v3.7.0 audio model `models/proactive-observer-v10` keep default audio access on the audio routes only.
|
|
74
|
+
- **Audio `prompt` is context, not an instruction**: the client `prompt` is passed as delimited spelling context (last 1000 characters) and can no longer replace the transcription instruction.
|
|
75
|
+
|
|
76
|
+
### Fixed
|
|
77
|
+
|
|
78
|
+
- **Audio stream failures are no longer reported as success**: mid-stream resets, in-band upstream error events, timeouts, streams that end without a finish reason, and `MAX_TOKENS` truncation now fail the request (HTTP `502`/`504`, WebSocket `antigravity_error`) instead of returning partial text; the last SSE event is kept even without a trailing newline.
|
|
79
|
+
- **No fixed 128-token cap on transcriptions**: the output limit now comes from the target model's spec, so long recordings are no longer silently truncated.
|
|
80
|
+
- **Audio rate limits keep their status**: rotator `429`/`503` answers are returned as `429` (with `Retry-After`) and `503` instead of a generic `500`.
|
|
81
|
+
- **Graceful shutdown with audio WebSockets**: unresponsive or still-authenticating WebSocket peers are force-closed after a short grace period, the server close wait is bounded, and a repeated SIGINT/SIGTERM no longer restarts the shutdown.
|
|
82
|
+
- **WebSocket control frames during `stop`**: ping and close frames are answered immediately while a `stop` command waits for the session to finish.
|
|
83
|
+
- **Rotator WebSocket accounting and transcripts**: a session that survives a failed segment is accounted once, as a success, when it completes; legitimate short utterances ("thank you", "one", "cuatro") and short final words are no longer dropped, and word de-duplication compares whole words.
|
|
84
|
+
|
|
50
85
|
## [3.7.0] - 2026-09-07
|
|
51
86
|
|
|
52
87
|
### Added
|
|
@@ -299,13 +334,6 @@
|
|
|
299
334
|
### Fixed
|
|
300
335
|
- **Ollama singleton-pool rotation threshold** (closed by `pi-antigravity-rotator-tuv`): with only one Ollama account, the persisted request-count threshold (`requestsPerRotation`) excluded the lone account from the pool after one request, producing `All accounts disabled or unavailable`. Resolved by F4: the Ollama pool now holds 28 accounts (27 dual + 1 Ollama-only), so rotation always has an alternative.
|
|
301
336
|
|
|
302
|
-
## [Unreleased]
|
|
303
|
-
|
|
304
|
-
### Fixed
|
|
305
|
-
- **Ollama Content Array Normalization**: message `content` arrays (OpenAI-style blocks, e.g. from multimodal requests) are flattened to plain strings and `image_url` blocks are moved to the native `images` field before forwarding to Ollama Cloud, whose Go API rejects `messages[].content` arrays with `cannot unmarshal array` errors. Ported from ollama-rotator `ec5fa5a`; applies to the native `/api/chat` route and all v1 compat adapters.
|
|
306
|
-
- **Native `/api/chat` Payload Parsing**: the native route now parses the Ollama payload shape (`{model, messages, stream, options}`) before internal validation, which previously rejected every native request with `400 body.request is required`. Requires `model` and a non-empty `messages` array.
|
|
307
|
-
- **Ollama Catalog at Startup**: the Ollama Cloud model catalog is fetched once at boot (previously only inside quota poll cycles, every ~5 min), so provider-aware routing and `GET /v1/models` see Ollama models immediately.
|
|
308
|
-
|
|
309
337
|
## [2.7.0] - 2026-08-10
|
|
310
338
|
|
|
311
339
|
### Added
|
package/README.md
CHANGED
|
@@ -53,6 +53,8 @@ Originally built as a multi-account rotator for Google Antigravity. It now gener
|
|
|
53
53
|
|
|
54
54
|
## Current Model Update
|
|
55
55
|
|
|
56
|
+
- **v3.10.0: Claude tools, account-flag diagnostics, and audio reliability**: Fixed Claude Opus 4.6 Thinking tool-schema errors; account verification reasons now persist and flow into anonymous telemetry with a protected recent-incidents dashboard; audio transcription and WebSocket streaming use active Antigravity accounts with Language Server fallback. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v3.10.0); audio hardening in [PR #36](https://github.com/tuxevil/tuxevil-rotator/pull/36) by [@javargasm](https://github.com/javargasm))
|
|
57
|
+
- **Rotator-Backed Audio Transcription and Live-Streaming Hardening**: Batch transcription and live WebSocket sessions use active Antigravity accounts with Language Server fallback after rotator errors and timeouts. Virtual-key scopes follow the executed model; live streams preserve segment order, echo Ping payloads, and avoid fallback after client cancellation. ([PR #36](https://github.com/tuxevil/tuxevil-rotator/pull/36) by [@javargasm](https://github.com/javargasm))
|
|
56
58
|
- **OpenAI Codex GPT-6 catalog**: Added GPT-6 Astra, Sol, and Luna to the Codex options while keeping GPT-5.6 Sol, Terra, and Luna available. ([v3.9.0](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v3.9.0))
|
|
57
59
|
- **TypeSafe Jev Auto-Routing Improvements & Shadow Mode**: Decoupled dynamic effort and model judgments for `model: "auto"`, corrected target selection to strictly honor Jev's judgment, bounded decision payloads with strict non-text redaction, and introduced an opt-in shadow mode with observability headers (`X-Rotator-Model-Selection: shadow`). See [TypeSafe Jev model selection](docs/configuration.md#typesafe-jev-model-selection) and [v3.9.0](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v3.9.0).
|
|
58
60
|
- **Single-Account Transport Retry Recovery**: Transient upstream network failures now retry the current account with cancellable jittered exponential backoff when no alternate account is available, covering native proxy, compatibility, and Code Assist routes. ([PR #35](https://github.com/tuxevil/tuxevil-rotator/pull/35) by [@toRolex](https://github.com/toRolex))
|
|
@@ -364,7 +366,7 @@ Thanks to these amazing people who have contributed to the project:
|
|
|
364
366
|
- **[@josenicomaia](https://github.com/josenicomaia)** (José Nicodemos Maia Neto) — Modularized the compatibility layer architecture, added multimodal tool response support, fixed streaming pass-through for tool executions, and added PostgreSQL storage and weighted pool quota forecasting. ([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), [PR #13](https://github.com/tuxevil/tuxevil-rotator/pull/13), [PR #14](https://github.com/tuxevil/tuxevil-rotator/pull/14))
|
|
365
367
|
- **[@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))
|
|
366
368
|
- **[@toRolex](https://github.com/toRolex)** (Rolex) — Added cached prompt-token extraction from Google Antigravity/Cloud Code usage and mapped it to OpenAI and Anthropic compatibility responses, with focused regression tests, plus transport-error retry recovery for single-account and exhausted-account pools. ([PR #34](https://github.com/tuxevil/tuxevil-rotator/pull/34), [PR #35](https://github.com/tuxevil/tuxevil-rotator/pull/35))
|
|
367
|
-
- **[@javargasm](https://github.com/javargasm)** (Jeisson Alexander Vargas Marroquin) — Queued multi-request Antigravity account pooling (5×5 concurrent streams), strict FIFO overflow queue, dashboard concurrency metrics, canonical project ID resolution, account-scoped dynamic Antigravity discovery and routing, dynamic catalog and quota-safety hardening, persistent dynamic model ownership across restarts, 429 quota resilience with account-scoped retry, synchronous leasing, snapshot-based token refresh with generation validation, provider-scoped token publication, spend-logger memory leak fix, atomic PostgreSQL CTE daily spend aggregation with idempotent retries, virtual-key cache bounding, Anthropic tool-use compatibility layer (`tool_use`/`tool_result` content block conversion), JSON schema round-trip fixes, compat test suite expansion, model-scoped cooldowns, explicit Antigravity reset-duration parsing, idle pool normalization, RAW POLL deadline reconciliation, serialized per-account quota polling, Ollama kickstart routing for multi-provider accounts, and OpenAI-compatible audio transcription plus bidirectional live WebSocket streaming through the local Antigravity observer model. ([PR #3](https://github.com/tuxevil/tuxevil-rotator/pull/3), [PR #7](https://github.com/tuxevil/tuxevil-rotator/pull/7), [PR #22](https://github.com/tuxevil/tuxevil-rotator/pull/22), [PR #23](https://github.com/tuxevil/tuxevil-rotator/pull/23), [PR #24](https://github.com/tuxevil/tuxevil-rotator/pull/24), [PR #26](https://github.com/tuxevil/tuxevil-rotator/pull/26), [PR #29](https://github.com/tuxevil/tuxevil-rotator/pull/29), [PR #30](https://github.com/tuxevil/tuxevil-rotator/pull/30), [PR #31](https://github.com/tuxevil/tuxevil-rotator/pull/31), [PR #33](https://github.com/tuxevil/tuxevil-rotator/pull/33))
|
|
369
|
+
- **[@javargasm](https://github.com/javargasm)** (Jeisson Alexander Vargas Marroquin) — Queued multi-request Antigravity account pooling (5×5 concurrent streams), strict FIFO overflow queue, dashboard concurrency metrics, canonical project ID resolution, account-scoped dynamic Antigravity discovery and routing, dynamic catalog and quota-safety hardening, persistent dynamic model ownership across restarts, 429 quota resilience with account-scoped retry, synchronous leasing, snapshot-based token refresh with generation validation, provider-scoped token publication, spend-logger memory leak fix, atomic PostgreSQL CTE daily spend aggregation with idempotent retries, virtual-key cache bounding, Anthropic tool-use compatibility layer (`tool_use`/`tool_result` content block conversion), JSON schema round-trip fixes, compat test suite expansion, model-scoped cooldowns, explicit Antigravity reset-duration parsing, idle pool normalization, RAW POLL deadline reconciliation, serialized per-account quota polling, Ollama kickstart routing for multi-provider accounts, and OpenAI-compatible audio transcription plus bidirectional live WebSocket streaming through the local Antigravity observer model, with PR #36 adding rotator-backed transcription, Language Server fallback, model-scope checks, and live timeout/control-frame hardening. ([PR #3](https://github.com/tuxevil/tuxevil-rotator/pull/3), [PR #7](https://github.com/tuxevil/tuxevil-rotator/pull/7), [PR #22](https://github.com/tuxevil/tuxevil-rotator/pull/22), [PR #23](https://github.com/tuxevil/tuxevil-rotator/pull/23), [PR #24](https://github.com/tuxevil/tuxevil-rotator/pull/24), [PR #26](https://github.com/tuxevil/tuxevil-rotator/pull/26), [PR #29](https://github.com/tuxevil/tuxevil-rotator/pull/29), [PR #30](https://github.com/tuxevil/tuxevil-rotator/pull/30), [PR #31](https://github.com/tuxevil/tuxevil-rotator/pull/31), [PR #33](https://github.com/tuxevil/tuxevil-rotator/pull/33), [PR #36](https://github.com/tuxevil/tuxevil-rotator/pull/36))
|
|
368
370
|
|
|
369
371
|
## Development
|
|
370
372
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuxevil-rotator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.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",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"login": "tsx src/cli.ts login",
|
|
17
17
|
"typecheck": "tsc --noEmit",
|
|
18
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\"",
|
|
19
|
+
"test": "TUXEVIL_ROTATOR_ADMIN_TOKEN= PI_ROTATOR_ADMIN_TOKEN= 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
20
|
"lint": "eslint src test",
|
|
21
21
|
"coverage": "c8 --reporter=text --reporter=html --check-coverage --lines=60 --branches=50 --functions=60 --statements=60 npm test",
|
|
22
22
|
"check": "npm run typecheck && npm run typecheck:test && npm test && npm run lint"
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"bin/",
|
|
26
26
|
"src/",
|
|
27
|
+
"plugins/",
|
|
27
28
|
"tools/telemetry-receiver/",
|
|
28
29
|
"CHANGELOG.md",
|
|
29
30
|
"README.md",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface OpenCodePluginOptions {
|
|
2
|
+
baseURL?: string;
|
|
3
|
+
providerID?: string;
|
|
4
|
+
providerName?: string;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ResolvedPluginOptions {
|
|
9
|
+
baseURL: string;
|
|
10
|
+
providerID: string;
|
|
11
|
+
providerName: string;
|
|
12
|
+
timeoutMs: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RawModelMeta {
|
|
16
|
+
context_length?: number;
|
|
17
|
+
max_output_tokens?: number;
|
|
18
|
+
multimodal?: boolean;
|
|
19
|
+
tool_calling?: boolean;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RawRotatorModel {
|
|
24
|
+
id: string;
|
|
25
|
+
context_window?: number;
|
|
26
|
+
max_model_len?: number;
|
|
27
|
+
meta?: RawModelMeta;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface OpenCodeModelDef {
|
|
32
|
+
name: string;
|
|
33
|
+
limit: {
|
|
34
|
+
context: number;
|
|
35
|
+
output: number;
|
|
36
|
+
};
|
|
37
|
+
capabilities: {
|
|
38
|
+
tools: boolean;
|
|
39
|
+
input: string[];
|
|
40
|
+
output: string[];
|
|
41
|
+
};
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function resolvePluginOptions(
|
|
46
|
+
config?: Record<string, any>,
|
|
47
|
+
options?: OpenCodePluginOptions
|
|
48
|
+
): ResolvedPluginOptions;
|
|
49
|
+
|
|
50
|
+
export function mapModelToOpenCode(rawModel: RawRotatorModel): {
|
|
51
|
+
id: string;
|
|
52
|
+
modelDef: OpenCodeModelDef;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export function fetchRotatorModels(
|
|
56
|
+
baseURL: string,
|
|
57
|
+
timeoutMs?: number
|
|
58
|
+
): Promise<RawRotatorModel[]>;
|
|
59
|
+
|
|
60
|
+
export default function RotatorDiscoveryPlugin(
|
|
61
|
+
input?: unknown,
|
|
62
|
+
options?: OpenCodePluginOptions
|
|
63
|
+
): Promise<{
|
|
64
|
+
config: (config: Record<string, any>) => Promise<void>;
|
|
65
|
+
}>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Model Discovery Plugin for tuxevil-rotator
|
|
3
|
+
*
|
|
4
|
+
* Automatically fetches the active model list from a tuxevil-rotator instance
|
|
5
|
+
* (or any compatible endpoint) and injects the models with their limits and capabilities
|
|
6
|
+
* into the OpenCode configuration at startup.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Resolves the configuration options for the discovery plugin.
|
|
11
|
+
* Precedence:
|
|
12
|
+
* 1. Explicit plugin options passed in opencode.json
|
|
13
|
+
* 2. Environment variables (TUXEVIL_ROTATOR_BASE_URL, ROTATOR_URL)
|
|
14
|
+
* 3. Existing provider with baseURL matching rotator port or localhost in config
|
|
15
|
+
* 4. Default: http://127.0.0.1:51200/v1
|
|
16
|
+
*/
|
|
17
|
+
export function resolvePluginOptions(config = {}, options = {}) {
|
|
18
|
+
const envBaseURL = process.env.TUXEVIL_ROTATOR_BASE_URL || process.env.ROTATOR_URL;
|
|
19
|
+
|
|
20
|
+
let discoveredBaseURL = options.baseURL || envBaseURL;
|
|
21
|
+
let providerID = options.providerID;
|
|
22
|
+
let providerName = options.providerName;
|
|
23
|
+
|
|
24
|
+
if (!discoveredBaseURL && config.provider) {
|
|
25
|
+
for (const [id, prov] of Object.entries(config.provider)) {
|
|
26
|
+
const url = prov?.options?.baseURL;
|
|
27
|
+
if (typeof url === "string" && (url.includes("51200") || url.includes("rotator") || url.includes("antigravity"))) {
|
|
28
|
+
discoveredBaseURL = url;
|
|
29
|
+
if (!providerID) providerID = id;
|
|
30
|
+
if (!providerName && prov.name) providerName = prov.name;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!discoveredBaseURL) {
|
|
37
|
+
discoveredBaseURL = "http://127.0.0.1:51200/v1";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Normalize baseURL (remove trailing slashes)
|
|
41
|
+
discoveredBaseURL = discoveredBaseURL.replace(/\/+$/, "");
|
|
42
|
+
|
|
43
|
+
if (!providerID) {
|
|
44
|
+
providerID = options.providerID || "antigravity";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!providerName) {
|
|
48
|
+
providerName = options.providerName || "Antigravity (rotator)";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const timeoutMs = Number(options.timeoutMs) || 3500;
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
baseURL: discoveredBaseURL,
|
|
55
|
+
providerID,
|
|
56
|
+
providerName,
|
|
57
|
+
timeoutMs,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Maps raw model object from rotator /v1/models to OpenCode model definition.
|
|
63
|
+
*/
|
|
64
|
+
export function mapModelToOpenCode(rawModel) {
|
|
65
|
+
const id = rawModel.id;
|
|
66
|
+
const meta = rawModel.meta || {};
|
|
67
|
+
|
|
68
|
+
const contextLimit = Number(meta.context_length) || Number(rawModel.context_window) || Number(rawModel.max_model_len) || 128000;
|
|
69
|
+
const outputLimit = Number(meta.max_output_tokens) || 8192;
|
|
70
|
+
|
|
71
|
+
const isMultimodal = Boolean(meta.multimodal);
|
|
72
|
+
const toolCalling = meta.tool_calling !== false;
|
|
73
|
+
|
|
74
|
+
const modelDef = {
|
|
75
|
+
name: id,
|
|
76
|
+
limit: {
|
|
77
|
+
context: contextLimit,
|
|
78
|
+
output: outputLimit,
|
|
79
|
+
},
|
|
80
|
+
capabilities: {
|
|
81
|
+
tools: toolCalling,
|
|
82
|
+
input: isMultimodal ? ["text", "image"] : ["text"],
|
|
83
|
+
output: ["text"],
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return { id, modelDef };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Fetches available models from the target rotator endpoint.
|
|
92
|
+
*/
|
|
93
|
+
export async function fetchRotatorModels(baseURL, timeoutMs = 3500) {
|
|
94
|
+
const modelsUrl = `${baseURL}/models`;
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const res = await fetch(modelsUrl, {
|
|
100
|
+
signal: controller.signal,
|
|
101
|
+
headers: {
|
|
102
|
+
Accept: "application/json",
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (!res.ok) {
|
|
107
|
+
throw new Error(`Endpoint returned status ${res.status}: ${res.statusText}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const json = await res.json();
|
|
111
|
+
if (!json || !Array.isArray(json.data)) {
|
|
112
|
+
throw new Error("Invalid response format: 'data' array not found");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return json.data;
|
|
116
|
+
} finally {
|
|
117
|
+
clearTimeout(timer);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* OpenCode Plugin Entrypoint
|
|
123
|
+
*/
|
|
124
|
+
export default async function RotatorDiscoveryPlugin(_input, options = {}) {
|
|
125
|
+
return {
|
|
126
|
+
config: async (config) => {
|
|
127
|
+
try {
|
|
128
|
+
const resolved = resolvePluginOptions(config, options);
|
|
129
|
+
const rawModels = await fetchRotatorModels(resolved.baseURL, resolved.timeoutMs);
|
|
130
|
+
|
|
131
|
+
if (!config.provider) {
|
|
132
|
+
config.provider = {};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const existingProvider = config.provider[resolved.providerID] || {};
|
|
136
|
+
const models = { ...(existingProvider.models || {}) };
|
|
137
|
+
|
|
138
|
+
for (const raw of rawModels) {
|
|
139
|
+
if (!raw || !raw.id) continue;
|
|
140
|
+
const { id, modelDef } = mapModelToOpenCode(raw);
|
|
141
|
+
// Preserve any user-customized options or limits while merging capabilities
|
|
142
|
+
models[id] = {
|
|
143
|
+
...modelDef,
|
|
144
|
+
...(models[id] || {}),
|
|
145
|
+
capabilities: {
|
|
146
|
+
...modelDef.capabilities,
|
|
147
|
+
...(models[id]?.capabilities || {}),
|
|
148
|
+
},
|
|
149
|
+
limit: {
|
|
150
|
+
...modelDef.limit,
|
|
151
|
+
...(models[id]?.limit || {}),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
config.provider[resolved.providerID] = {
|
|
157
|
+
npm: "@ai-sdk/openai-compatible",
|
|
158
|
+
name: resolved.providerName,
|
|
159
|
+
...existingProvider,
|
|
160
|
+
options: {
|
|
161
|
+
baseURL: resolved.baseURL,
|
|
162
|
+
...(existingProvider.options || {}),
|
|
163
|
+
},
|
|
164
|
+
models,
|
|
165
|
+
};
|
|
166
|
+
} catch (err) {
|
|
167
|
+
// Safe degrade: do not fail OpenCode startup if rotator is unreachable
|
|
168
|
+
if (process.env.DEBUG || process.env.NODE_ENV === "development") {
|
|
169
|
+
console.warn("[rotator-discovery-plugin] Could not auto-discover models:", err?.message || err);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|