@thelioo/opencode-balancer 0.1.8 → 0.2.1
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/INSTALL.txt +53 -25
- package/README.md +95 -51
- package/dist/core/accounts.ts +404 -0
- package/dist/core/database.ts +67 -0
- package/dist/core/events.ts +75 -0
- package/dist/core/native-auth-suppression.ts +36 -0
- package/dist/core/native-connect.ts +31 -0
- package/dist/core/path.ts +34 -0
- package/dist/core/pending.ts +351 -0
- package/dist/core/priority.ts +193 -0
- package/dist/core/schema.ts +439 -0
- package/dist/core/time.ts +3 -0
- package/dist/core/types.ts +72 -0
- package/dist/core/usage/index.ts +23 -0
- package/dist/core/usage/providers/copilot.ts +243 -0
- package/dist/core/usage/providers/openai.ts +179 -0
- package/dist/core/usage/redact.ts +80 -0
- package/dist/core/usage/store.ts +66 -0
- package/dist/core/usage/types.ts +24 -0
- package/dist/index.js +173 -4
- package/dist/index.js.map +1 -1
- package/dist/server/auth-watcher.ts +318 -0
- package/dist/server/commands.ts +58 -0
- package/dist/server/fetch-patch.ts +162 -0
- package/dist/server/index.ts +134 -0
- package/dist/server/native.ts +49 -0
- package/dist/server/request-balancer.ts +67 -0
- package/dist/tui/actions.ts +176 -112
- package/dist/tui/balancer-bar-sync.ts +55 -45
- package/dist/tui/components/alias-dialog.tsx +71 -56
- package/dist/tui/components/dashboard.tsx +530 -358
- package/dist/tui/components/priority-screen.tsx +389 -267
- package/dist/tui/components/provider-model-dialog.tsx +71 -64
- package/dist/tui/components/rename-dialog.tsx +35 -28
- package/dist/tui/components/sidebar.tsx +103 -79
- package/dist/tui/components/status-indicator.tsx +78 -59
- package/dist/tui/components/usage-bar.tsx +18 -7
- package/dist/tui/components/usage-display.tsx +32 -16
- package/dist/tui/connect.ts +104 -73
- package/dist/tui/dashboard-keys.ts +53 -41
- package/dist/tui/native-model-apply.ts +45 -36
- package/dist/tui/priority-keys.ts +44 -36
- package/dist/tui/provider-models.ts +32 -25
- package/dist/tui/responsive.ts +10 -7
- package/dist/tui/selected-account-bar-sync.ts +23 -23
- package/dist/tui/selection-colors.ts +38 -30
- package/dist/tui/state.ts +61 -44
- package/dist/tui/status-format.ts +24 -20
- package/dist/tui/tui.js +165 -153
- package/dist/tui/tui.js.map +1 -1
- package/dist/tui/tui.tsx +194 -144
- package/dist/tui/usage-auto-refresh.ts +52 -45
- package/dist/tui/usage-format.ts +9 -9
- package/package.json +61 -52
- package/dist/core/accounts.d.ts +0 -14
- package/dist/core/accounts.js +0 -260
- package/dist/core/accounts.js.map +0 -1
- package/dist/core/database.d.ts +0 -4
- package/dist/core/database.js +0 -69
- package/dist/core/database.js.map +0 -1
- package/dist/core/events.d.ts +0 -18
- package/dist/core/events.js +0 -39
- package/dist/core/events.js.map +0 -1
- package/dist/core/native-auth-suppression.d.ts +0 -3
- package/dist/core/native-auth-suppression.js +0 -19
- package/dist/core/native-auth-suppression.js.map +0 -1
- package/dist/core/native-connect.d.ts +0 -4
- package/dist/core/native-connect.js +0 -19
- package/dist/core/native-connect.js.map +0 -1
- package/dist/core/path.d.ts +0 -4
- package/dist/core/path.js +0 -26
- package/dist/core/path.js.map +0 -1
- package/dist/core/pending.d.ts +0 -9
- package/dist/core/pending.js +0 -237
- package/dist/core/pending.js.map +0 -1
- package/dist/core/priority.d.ts +0 -20
- package/dist/core/priority.js +0 -120
- package/dist/core/priority.js.map +0 -1
- package/dist/core/schema.d.ts +0 -2
- package/dist/core/schema.js +0 -265
- package/dist/core/schema.js.map +0 -1
- package/dist/core/time.d.ts +0 -1
- package/dist/core/time.js +0 -4
- package/dist/core/time.js.map +0 -1
- package/dist/core/types.d.ts +0 -59
- package/dist/core/types.js +0 -2
- package/dist/core/types.js.map +0 -1
- package/dist/core/usage/index.d.ts +0 -4
- package/dist/core/usage/index.js +0 -16
- package/dist/core/usage/index.js.map +0 -1
- package/dist/core/usage/providers/copilot.d.ts +0 -2
- package/dist/core/usage/providers/copilot.js +0 -169
- package/dist/core/usage/providers/copilot.js.map +0 -1
- package/dist/core/usage/providers/openai.d.ts +0 -2
- package/dist/core/usage/providers/openai.js +0 -133
- package/dist/core/usage/providers/openai.js.map +0 -1
- package/dist/core/usage/redact.d.ts +0 -3
- package/dist/core/usage/redact.js +0 -67
- package/dist/core/usage/redact.js.map +0 -1
- package/dist/core/usage/store.d.ts +0 -4
- package/dist/core/usage/store.js +0 -31
- package/dist/core/usage/store.js.map +0 -1
- package/dist/core/usage/types.d.ts +0 -21
- package/dist/core/usage/types.js +0 -2
- package/dist/core/usage/types.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/server/auth-watcher.d.ts +0 -32
- package/dist/server/auth-watcher.js +0 -227
- package/dist/server/auth-watcher.js.map +0 -1
- package/dist/server/commands.d.ts +0 -2
- package/dist/server/commands.js +0 -46
- package/dist/server/commands.js.map +0 -1
- package/dist/server/fetch-patch.d.ts +0 -3
- package/dist/server/fetch-patch.js +0 -118
- package/dist/server/fetch-patch.js.map +0 -1
- package/dist/server/index.d.ts +0 -8
- package/dist/server/index.js +0 -94
- package/dist/server/index.js.map +0 -1
- package/dist/server/native.d.ts +0 -6
- package/dist/server/native.js +0 -35
- package/dist/server/native.js.map +0 -1
- package/dist/server/request-balancer.d.ts +0 -16
- package/dist/server/request-balancer.js +0 -43
- package/dist/server/request-balancer.js.map +0 -1
- package/dist/tui/actions.d.ts +0 -41
- package/dist/tui/actions.js +0 -92
- package/dist/tui/actions.js.map +0 -1
- package/dist/tui/balancer-bar-sync.d.ts +0 -19
- package/dist/tui/balancer-bar-sync.js +0 -45
- package/dist/tui/balancer-bar-sync.js.map +0 -1
- package/dist/tui/components/alias-dialog.d.ts +0 -4
- package/dist/tui/components/dashboard.d.ts +0 -12
- package/dist/tui/components/priority-screen.d.ts +0 -9
- package/dist/tui/components/provider-model-dialog.d.ts +0 -14
- package/dist/tui/components/rename-dialog.d.ts +0 -4
- package/dist/tui/components/sidebar.d.ts +0 -10
- package/dist/tui/components/status-indicator.d.ts +0 -9
- package/dist/tui/components/usage-bar.d.ts +0 -8
- package/dist/tui/components/usage-display.d.ts +0 -10
- package/dist/tui/connect.d.ts +0 -30
- package/dist/tui/connect.js +0 -75
- package/dist/tui/connect.js.map +0 -1
- package/dist/tui/dashboard-keys.d.ts +0 -45
- package/dist/tui/dashboard-keys.js +0 -44
- package/dist/tui/dashboard-keys.js.map +0 -1
- package/dist/tui/native-model-apply.d.ts +0 -21
- package/dist/tui/native-model-apply.js +0 -53
- package/dist/tui/native-model-apply.js.map +0 -1
- package/dist/tui/priority-keys.d.ts +0 -40
- package/dist/tui/priority-keys.js +0 -38
- package/dist/tui/priority-keys.js.map +0 -1
- package/dist/tui/provider-models.d.ts +0 -19
- package/dist/tui/provider-models.js +0 -17
- package/dist/tui/provider-models.js.map +0 -1
- package/dist/tui/responsive.d.ts +0 -9
- package/dist/tui/responsive.js +0 -13
- package/dist/tui/responsive.js.map +0 -1
- package/dist/tui/selected-account-bar-sync.d.ts +0 -10
- package/dist/tui/selected-account-bar-sync.js +0 -26
- package/dist/tui/selected-account-bar-sync.js.map +0 -1
- package/dist/tui/selection-colors.d.ts +0 -10
- package/dist/tui/selection-colors.js +0 -38
- package/dist/tui/selection-colors.js.map +0 -1
- package/dist/tui/state.d.ts +0 -14
- package/dist/tui/state.js +0 -46
- package/dist/tui/state.js.map +0 -1
- package/dist/tui/status-format.d.ts +0 -15
- package/dist/tui/status-format.js +0 -17
- package/dist/tui/status-format.js.map +0 -1
- package/dist/tui/tui.d.ts +0 -7
- package/dist/tui/usage-auto-refresh.d.ts +0 -16
- package/dist/tui/usage-auto-refresh.js +0 -46
- package/dist/tui/usage-auto-refresh.js.map +0 -1
- package/dist/tui/usage-format.d.ts +0 -2
- package/dist/tui/usage-format.js +0 -17
- package/dist/tui/usage-format.js.map +0 -1
package/INSTALL.txt
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
opencode-balancer installation guide for AI agents
|
|
2
2
|
|
|
3
3
|
Goal
|
|
4
|
-
Install @thelioo/opencode-balancer as an opencode
|
|
4
|
+
Install @thelioo/opencode-balancer as both an opencode server plugin and an opencode TUI plugin without removing or rewriting the user's existing opencode configuration.
|
|
5
5
|
|
|
6
6
|
What this plugin does
|
|
7
|
-
opencode-balancer lets opencode users save multiple authenticated accounts per provider,
|
|
7
|
+
opencode-balancer lets opencode users save multiple authenticated accounts per provider, manage them from a TUI dashboard, choose provider/model priority, and automatically retry with another healthy account when the active account is rate-limited.
|
|
8
8
|
|
|
9
9
|
Important rules
|
|
10
|
-
- Do not run npm install for this plugin. opencode installs npm plugins automatically with Bun at startup.
|
|
11
|
-
- Preserve existing opencode config, plugins, comments, formatting, providers, agents, MCP servers, and permissions whenever possible.
|
|
10
|
+
- Do not run npm install, bun install, or other package install commands for this plugin during user setup. opencode installs npm plugins automatically with Bun at startup.
|
|
11
|
+
- Preserve existing opencode config, TUI config, plugins, comments, formatting, providers, agents, MCP servers, and permissions whenever possible.
|
|
12
12
|
- Use the singular key "plugin", not "plugins".
|
|
13
13
|
- Add the plugin only if it is not already present.
|
|
14
|
-
- Prefer @thelioo/opencode-balancer@latest for user installs.
|
|
14
|
+
- Prefer @thelioo/opencode-balancer (without @latest) for user installs.
|
|
15
|
+
- Keep config changes minimal and do not remove unrelated user settings.
|
|
15
16
|
|
|
16
17
|
Steps
|
|
17
18
|
1. Locate the user's opencode config.
|
|
@@ -25,43 +26,70 @@ Steps
|
|
|
25
26
|
- If the config is JSONC, keep JSONC syntax valid.
|
|
26
27
|
- If the config is JSON, keep JSON syntax valid.
|
|
27
28
|
|
|
28
|
-
3. Add this plugin entry:
|
|
29
|
-
@thelioo/opencode-balancer
|
|
29
|
+
3. Add this plugin entry to the opencode config plugin array:
|
|
30
|
+
@thelioo/opencode-balancer
|
|
30
31
|
|
|
31
|
-
4.
|
|
32
|
+
4. Locate the user's opencode TUI config.
|
|
33
|
+
- Prefer ~/.config/opencode/tui.jsonc if it exists.
|
|
34
|
+
- Otherwise use ~/.config/opencode/tui.json if it exists.
|
|
35
|
+
- If neither exists, create ~/.config/opencode/tui.json with a minimal JSON object.
|
|
32
36
|
|
|
33
|
-
5.
|
|
37
|
+
5. Ensure the TUI config has a top-level plugin array.
|
|
38
|
+
- If plugin already exists and is an array, keep all existing entries.
|
|
39
|
+
- If plugin is missing, create it.
|
|
40
|
+
- If the config is JSONC, keep JSONC syntax valid.
|
|
41
|
+
- If the config is JSON, keep JSON syntax valid.
|
|
42
|
+
|
|
43
|
+
6. Add this plugin entry to the TUI config plugin array:
|
|
44
|
+
@thelioo/opencode-balancer
|
|
45
|
+
|
|
46
|
+
7. Save both configs.
|
|
34
47
|
|
|
35
|
-
|
|
48
|
+
8. Show the user both final plugin arrays.
|
|
49
|
+
|
|
50
|
+
9. Tell the user to restart opencode.
|
|
36
51
|
|
|
37
52
|
Expected config shape
|
|
38
53
|
{
|
|
39
54
|
"$schema": "https://opencode.ai/config.json",
|
|
40
|
-
"plugin": ["@thelioo/opencode-balancer
|
|
55
|
+
"plugin": ["@thelioo/opencode-balancer"]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Expected TUI config shape
|
|
59
|
+
{
|
|
60
|
+
"$schema": "https://opencode.ai/tui.json",
|
|
61
|
+
"plugin": ["@thelioo/opencode-balancer"]
|
|
41
62
|
}
|
|
42
63
|
|
|
43
64
|
After restart
|
|
44
|
-
1. Tell the user to
|
|
45
|
-
|
|
65
|
+
1. Tell the user to open the Balancer dashboard using one of these options:
|
|
66
|
+
- Press Ctrl+B.
|
|
67
|
+
- Run /balancer.
|
|
68
|
+
- Open "Open Balancer Dashboard" from the opencode command palette.
|
|
69
|
+
- Use the Balancer button in the sidebar if visible.
|
|
70
|
+
|
|
71
|
+
2. Tell the user to choose "New account" in the dashboard, or press C, to start opencode's native provider connection flow.
|
|
46
72
|
|
|
47
|
-
|
|
73
|
+
3. Tell the user to complete the provider connection in opencode. The plugin detects the changed provider credentials and saves them from the TUI workflow automatically. If the credentials match an existing saved account, the saved account is refreshed instead of duplicated.
|
|
48
74
|
|
|
49
|
-
|
|
75
|
+
4. Tell the user to open the priority matrix from the dashboard header, or press P, to configure automatic balancing:
|
|
76
|
+
- Press B to turn automatic balancing on or off.
|
|
77
|
+
- Press Enter on a provider to choose its model.
|
|
78
|
+
- Use Shift+Up and Shift+Down to reorder provider priority.
|
|
79
|
+
- Press Space to enable or disable a provider.
|
|
50
80
|
|
|
51
|
-
|
|
81
|
+
5. Remind the user to restart opencode after any later config changes.
|
|
52
82
|
|
|
53
83
|
Security note
|
|
54
84
|
The plugin stores saved provider credentials locally in balancer.sqlite under the opencode config directory, usually ~/.config/opencode/balancer.sqlite or OPENCODE_CONFIG_DIR/balancer.sqlite. Keep this file private and never commit, paste, or share it.
|
|
55
85
|
|
|
56
|
-
|
|
57
|
-
/balancer
|
|
58
|
-
/balancer help
|
|
59
|
-
/balancer list
|
|
60
|
-
/balancer status
|
|
61
|
-
/balancer use <provider> <alias>
|
|
62
|
-
/balancer active <provider>
|
|
86
|
+
TUI-only workflow
|
|
87
|
+
/balancer opens the Balancer dashboard in the TUI. Account management, provider/model priority, supported usage snapshots, and balancing settings are handled from the TUI only.
|
|
63
88
|
|
|
64
89
|
Verification
|
|
65
|
-
- Confirm the opencode config contains @thelioo/opencode-balancer
|
|
90
|
+
- Confirm the opencode config contains @thelioo/opencode-balancer in the plugin array.
|
|
91
|
+
- Confirm the opencode TUI config contains @thelioo/opencode-balancer in the plugin array.
|
|
66
92
|
- Confirm no existing plugin entries were removed.
|
|
67
|
-
-
|
|
93
|
+
- Confirm the user restarted opencode after the config change.
|
|
94
|
+
- Confirm the Balancer dashboard opens with Ctrl+B, /balancer, or the command palette.
|
|
95
|
+
- Confirm at least one account can be connected from the dashboard before helping configure balancing.
|
package/README.md
CHANGED
|
@@ -2,32 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
# opencode-balancer
|
|
4
4
|
|
|
5
|
-
_Use multiple accounts
|
|
5
|
+
_Use multiple accounts and provider/model priorities in opencode, then fail over automatically when one account hits a limit._
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/@thelioo/opencode-balancer)
|
|
8
8
|
[](https://www.typescriptlang.org)
|
|
9
9
|
[](https://opencode.ai/docs/plugins)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
|
|
12
|
-
[Features](#features) | [Installation](#installation) | [Usage](#usage) | [
|
|
12
|
+
[Features](#features) | [Installation](#installation) | [Usage](#usage) | [Troubleshooting](#troubleshooting)
|
|
13
13
|
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
|
-
`opencode-balancer` is an [opencode](https://opencode.ai/) plugin that lets you
|
|
16
|
+
`opencode-balancer` is an [opencode](https://opencode.ai/) server and TUI plugin that lets you keep several authenticated accounts, choose which provider/model should be used first, and keep working when the current account becomes rate-limited.
|
|
17
17
|
|
|
18
|
-
It
|
|
18
|
+
It integrates with opencode's native provider connection flow. Use the plugin dashboard to connect accounts, inspect usage, switch active accounts, configure provider priority, and enable or disable automatic balancing.
|
|
19
19
|
|
|
20
20
|
> [!NOTE]
|
|
21
21
|
> This plugin manages credentials already configured through opencode. It does not create accounts, bypass provider limits, or modify provider-side quotas.
|
|
22
22
|
|
|
23
23
|
## Features
|
|
24
24
|
|
|
25
|
-
- **Multiple accounts per provider**: Save
|
|
26
|
-
- **Automatic failover**:
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
30
|
-
- **
|
|
25
|
+
- **Multiple accounts per provider**: Save and activate separate accounts for the same provider.
|
|
26
|
+
- **Automatic failover**: Retries with another healthy account after retryable responses such as `429`, `500`, `502`, `503`, `504`, or `529`.
|
|
27
|
+
- **Provider priority matrix**: Choose one model per provider, reorder failover priority, and disable providers from the balancer.
|
|
28
|
+
- **TUI dashboard**: Open a control center from the command palette, `/balancer`, `Ctrl+B`, or the sidebar.
|
|
29
|
+
- **Native connect flow**: Start opencode's provider connection from the dashboard and save the detected account automatically.
|
|
30
|
+
- **Usage snapshots**: Shows per-account usage when the provider exposes supported usage data.
|
|
31
|
+
- **Local credential store**: Saves accounts, usage snapshots, events, and priority settings under your opencode config directory.
|
|
31
32
|
|
|
32
33
|
## Installation
|
|
33
34
|
|
|
@@ -44,68 +45,94 @@ Or read the local guide: [INSTALL.txt](INSTALL.txt).
|
|
|
44
45
|
|
|
45
46
|
### Option B: Manual Setup
|
|
46
47
|
|
|
47
|
-
Add the plugin to your opencode config:
|
|
48
|
+
Add the plugin to your opencode config so the server hooks can run:
|
|
48
49
|
|
|
49
50
|
```json
|
|
50
51
|
{
|
|
51
52
|
"$schema": "https://opencode.ai/config.json",
|
|
52
|
-
"plugin": ["@thelioo/opencode-balancer
|
|
53
|
+
"plugin": ["@thelioo/opencode-balancer"]
|
|
53
54
|
}
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
Then
|
|
57
|
+
Then add the same plugin to your opencode TUI config so the dashboard can load:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"$schema": "https://opencode.ai/tui.json",
|
|
62
|
+
"plugin": ["@thelioo/opencode-balancer"]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Use the package name without an explicit `@latest` tag so opencode can refresh to newer published versions on restart.
|
|
67
|
+
|
|
68
|
+
Then restart opencode. The same package provides both the server hooks and the TUI dashboard.
|
|
57
69
|
|
|
58
70
|
> [!TIP]
|
|
59
|
-
> No manual `npm install` is required. opencode
|
|
71
|
+
> No manual `npm install` is required. opencode installs npm plugins automatically with Bun at startup and caches them locally.
|
|
60
72
|
|
|
61
73
|
## Usage
|
|
62
74
|
|
|
63
|
-
###
|
|
75
|
+
### Open The Dashboard
|
|
64
76
|
|
|
65
|
-
|
|
77
|
+
Open the Balancer dashboard with any of these entry points:
|
|
66
78
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
- Press `Ctrl+B`.
|
|
80
|
+
- Run `/balancer` from opencode to open the dashboard.
|
|
81
|
+
- Open **Open Balancer Dashboard** from the command palette.
|
|
82
|
+
- Click the Balancer dashboard button in the sidebar.
|
|
70
83
|
|
|
71
|
-
|
|
84
|
+
The dashboard is the primary workflow for account management. It works on compact and full terminal layouts.
|
|
72
85
|
|
|
73
|
-
###
|
|
86
|
+
### Connect An Account
|
|
74
87
|
|
|
75
|
-
|
|
88
|
+
In the dashboard, choose **New account** or press `C`. The plugin opens opencode's native provider connection flow.
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
/connect anthropic
|
|
79
|
-
```
|
|
90
|
+
After the provider auth changes, `opencode-balancer` detects the new credentials and saves them as an account. If the credentials match an existing saved account, the saved account is refreshed instead of duplicated.
|
|
80
91
|
|
|
81
92
|
### Manage Accounts
|
|
82
93
|
|
|
83
|
-
Use the
|
|
94
|
+
Use the dashboard and sidebar to:
|
|
95
|
+
|
|
96
|
+
- Activate an account for a provider.
|
|
97
|
+
- Rename an account.
|
|
98
|
+
- Remove an account after confirmation.
|
|
99
|
+
- View supported usage snapshots when the provider exposes compatible usage data.
|
|
84
100
|
|
|
85
|
-
|
|
101
|
+
Aliases are normalized to lowercase and may contain letters, numbers, dots, hyphens, and underscores.
|
|
86
102
|
|
|
87
|
-
|
|
103
|
+
### Configure Automatic Balancing
|
|
88
104
|
|
|
89
|
-
|
|
105
|
+
Open the priority matrix from the dashboard header or press `P`.
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
| --- | --- |
|
|
93
|
-
| `/balancer help` | Show fallback commands. |
|
|
94
|
-
| `/balancer list` | List saved accounts as `provider/alias`. |
|
|
95
|
-
| `/balancer status` | Show saved and pending counts. |
|
|
96
|
-
| `/balancer use <provider> <alias>` | Switch the active account for a provider. |
|
|
97
|
-
| `/balancer active <provider>` | Show the active account for a provider. |
|
|
107
|
+
In the priority matrix you can:
|
|
98
108
|
|
|
99
|
-
|
|
109
|
+
- Press `B` to enable or disable automatic balancing.
|
|
110
|
+
- Pick the model used for each provider with `Enter`.
|
|
111
|
+
- Reorder providers with `Shift+Up` and `Shift+Down`.
|
|
112
|
+
- Enable or disable individual providers with `Space`.
|
|
113
|
+
|
|
114
|
+
When balancing is on, the priority matrix decides the provider/model for each message. The plugin selects the first enabled provider with a configured model and a healthy saved account. When a retryable error is returned, the current account is temporarily marked as rate-limited and another healthy account for that provider is used when available.
|
|
115
|
+
|
|
116
|
+
When balancing is off, opencode keeps its native provider/model selection. The plugin only applies the selected saved account when needed.
|
|
117
|
+
|
|
118
|
+
## TUI Entry Points
|
|
119
|
+
|
|
120
|
+
`opencode-balancer` is managed from the TUI. Use one of these entry points to open the dashboard:
|
|
121
|
+
|
|
122
|
+
- `Ctrl+B`
|
|
123
|
+
- `/balancer`
|
|
124
|
+
- **Open Balancer Dashboard** in the command palette
|
|
125
|
+
- The Balancer sidebar button
|
|
100
126
|
|
|
101
127
|
## How It Works
|
|
102
128
|
|
|
103
|
-
`opencode-balancer`
|
|
129
|
+
`opencode-balancer` combines server hooks with a TUI module:
|
|
104
130
|
|
|
105
|
-
1.
|
|
106
|
-
2. The
|
|
107
|
-
3. Before
|
|
108
|
-
4.
|
|
131
|
+
1. The TUI dashboard opens opencode's native connect flow and stores changed provider credentials as saved accounts.
|
|
132
|
+
2. The dashboard stores selected accounts, per-provider models, balancing state, usage snapshots, and priority order in a local SQLite database.
|
|
133
|
+
3. Before a chat request, server hooks choose the active account and, when balancing is enabled, the provider/model from the priority matrix.
|
|
134
|
+
4. A fetch patch injects the selected account credentials into the provider request.
|
|
135
|
+
5. Retryable provider responses mark the account as temporarily rate-limited and trigger a retry with another healthy account when balancing is enabled.
|
|
109
136
|
|
|
110
137
|
Saved account data is written to:
|
|
111
138
|
|
|
@@ -121,12 +148,29 @@ If `OPENCODE_CONFIG_DIR` is set, the plugin uses that directory instead.
|
|
|
121
148
|
## Local Development
|
|
122
149
|
|
|
123
150
|
```bash
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
151
|
+
bun install
|
|
152
|
+
bun run check
|
|
153
|
+
bun run build
|
|
154
|
+
bun test
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Releases use Changesets:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
bun run changeset
|
|
161
|
+
bun run version
|
|
162
|
+
bun run release
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
To test a local checkout with opencode, point your opencode config to the package directory:
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"plugin": ["file:///absolute/path/to/opencode-balancer"]
|
|
170
|
+
}
|
|
127
171
|
```
|
|
128
172
|
|
|
129
|
-
|
|
173
|
+
And add the same local path to your TUI config:
|
|
130
174
|
|
|
131
175
|
```json
|
|
132
176
|
{
|
|
@@ -138,11 +182,11 @@ To test a local checkout with opencode, point your config to the package directo
|
|
|
138
182
|
|
|
139
183
|
| Problem | What to try |
|
|
140
184
|
| --- | --- |
|
|
141
|
-
| Plugin does not load | Confirm `plugin` is singular, restart opencode, and check that the package name is `@thelioo/opencode-balancer
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
185
|
+
| Plugin does not load | Confirm `plugin` is singular in opencode config, restart opencode, and check that the package name is `@thelioo/opencode-balancer`. |
|
|
186
|
+
| Dashboard does not open | Confirm `tui.json` also contains the plugin, restart opencode, then try `Ctrl+B`, `/balancer`, or the command palette. |
|
|
187
|
+
| Account was not saved | Use **New account** from the Balancer dashboard and complete opencode's native provider connection flow. |
|
|
188
|
+
| Provider is skipped | Open the priority matrix and confirm the provider is enabled and has a model selected. |
|
|
189
|
+
| Account is not switching | Confirm there is another non-disabled saved account for the same provider and automatic balancing is on. |
|
|
146
190
|
|
|
147
191
|
## Resources
|
|
148
192
|
|