opencode-auth-load-balancer 0.7.2 → 0.8.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/README.md +23 -39
- package/dist/index.d.ts +0 -6
- package/dist/index.js +13 -29141
- package/dist/refresh.d.ts +3 -1
- package/dist/v1.js +12 -5
- package/dist/v2-entry.d.ts +6 -0
- package/dist/v2-entry.js +47529 -0
- package/index.js +2 -2
- package/package.json +12 -6
- package/tui.ts +1 -1
- package/v2.js +2 -0
package/README.md
CHANGED
|
@@ -27,45 +27,31 @@ Selection is **not** round-robin. It is weighted primarily by **weekly** usage,
|
|
|
27
27
|
- [Bun](https://bun.com) ≥ 1.3
|
|
28
28
|
- opencode (TUI), with the Anthropic, OpenAI, and/or Kimi For Coding providers available
|
|
29
29
|
|
|
30
|
-
### OpenCode
|
|
30
|
+
### OpenCode 1 compatibility
|
|
31
31
|
|
|
32
|
-
The
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
The existing account pool, scheduling, token refresh, fallback and durable
|
|
36
|
-
pending files are reused; accounts do not need to be registered again.
|
|
37
|
-
|
|
38
|
-
Configure the **package directory** in `opencode.json` after building:
|
|
32
|
+
The default server and TUI entries target **OpenCode 1.x** (verified with **1.19.0**).
|
|
33
|
+
The existing account pool is reused; accounts do not need to be registered again.
|
|
34
|
+
Configure the npm package in `opencode.json`:
|
|
39
35
|
|
|
40
36
|
```jsonc
|
|
41
37
|
{
|
|
42
38
|
"$schema": "https://opencode.ai/config.json",
|
|
43
|
-
"
|
|
39
|
+
"plugin": ["opencode-auth-load-balancer"]
|
|
44
40
|
}
|
|
45
41
|
```
|
|
46
42
|
|
|
47
|
-
For a
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
so requests pass through account rotation and usage tracking. Providers without
|
|
60
|
-
a pooled account keep their normal native driver. V2 can resume an unfinished
|
|
61
|
-
pending turn by its original durable prompt ID after a restart.
|
|
62
|
-
|
|
63
|
-
For **OpenCode 1.x**, use `dist/v1.js` as the local server plugin and the existing
|
|
64
|
-
`tui/auth-load-balancer-tui.ts` entry in `tui.json`. The instructions below about
|
|
65
|
-
copying a standalone bundle and registering TUI files describe this V1 setup.
|
|
66
|
-
The V2 sidebar supports rename, enable/disable, delete, and re-login/pairing;
|
|
67
|
-
the existing Gist sync engine runs on the server, but its V1 sidebar controls
|
|
68
|
-
have not yet been ported to the V2 UI.
|
|
43
|
+
For a local build, use the package directory or `dist/index.js`. Register the
|
|
44
|
+
existing `tui/auth-load-balancer-tui.ts` entry in `tui.json` as described below.
|
|
45
|
+
On OAuth inference HTTP 401, the plugin refreshes the rejected access token once
|
|
46
|
+
and retries, even if its advertised expiry is still in the future. Refreshes
|
|
47
|
+
share the account lock and adopt a concurrently rotated token; a second 401
|
|
48
|
+
rotates to another account. A revoked refresh token requires re-login.
|
|
49
|
+
|
|
50
|
+
OpenCode 2 remains an explicit opt-in through `v2.js` (or the npm `./v2`
|
|
51
|
+
export), with the separate `./tui-v2` entry. Its configuration uses `plugins`
|
|
52
|
+
(plural), and it uses different host APIs. Do not load a V2 entry into V1.
|
|
53
|
+
V2 status and account management use server RPC; its Gist sidebar controls
|
|
54
|
+
have not yet been ported from V1.
|
|
69
55
|
|
|
70
56
|
Verification:
|
|
71
57
|
|
|
@@ -73,10 +59,8 @@ Verification:
|
|
|
73
59
|
bun run typecheck
|
|
74
60
|
bun test
|
|
75
61
|
bun run build
|
|
76
|
-
bun run scripts/smoke-
|
|
77
|
-
bun run scripts/smoke-v2.ts . --inference #
|
|
78
|
-
bun run scripts/smoke-v2.ts . --live # real Anthropic request using the existing pool
|
|
79
|
-
bun run scripts/smoke-v2.ts . --live-codex # real GPT-6.1 Sol request; obsolete host auth must not gate the pool
|
|
62
|
+
bun run scripts/smoke-v1.ts . --live # OpenCode 1, real Opus call using the existing pool
|
|
63
|
+
bun run scripts/smoke-v2.ts . --inference # OpenCode 2, local mock Anthropic rotation
|
|
80
64
|
```
|
|
81
65
|
|
|
82
66
|
---
|
|
@@ -85,11 +69,11 @@ bun run scripts/smoke-v2.ts . --live-codex # real GPT-6.1 Sol request; obsolete
|
|
|
85
69
|
|
|
86
70
|
```bash
|
|
87
71
|
bun install
|
|
88
|
-
bun run build #
|
|
72
|
+
bun run build # V1: dist/index.js; V2: dist/v2-entry.js
|
|
89
73
|
```
|
|
90
74
|
|
|
91
75
|
The V1 bundle imports only Node built-ins and can be installed as one file.
|
|
92
|
-
OpenCode
|
|
76
|
+
OpenCode 1 loads the default package entry. OpenCode 2 must explicitly load `v2.js`.
|
|
93
77
|
|
|
94
78
|
### Load it into OpenCode 1 (local / dev)
|
|
95
79
|
|
|
@@ -120,7 +104,7 @@ Restart opencode to load it. (opencode does **not** hot-reload plugins — see t
|
|
|
120
104
|
// opencode.json
|
|
121
105
|
{
|
|
122
106
|
"$schema": "https://opencode.ai/config.json",
|
|
123
|
-
"
|
|
107
|
+
"plugin": ["opencode-auth-load-balancer"]
|
|
124
108
|
}
|
|
125
109
|
```
|
|
126
110
|
|
|
@@ -413,7 +397,7 @@ The unit/integration suite runs with coverage **gated at 100%** (lines and funct
|
|
|
413
397
|
opencode loads plugins once at startup, so the loop is:
|
|
414
398
|
|
|
415
399
|
1. `bun run dev` — keeps both server entry points rebuilt on every edit.
|
|
416
|
-
2. For
|
|
400
|
+
2. For V1, register the package in `opencode.json` using `plugin`, or symlink `dist/index.js` into `.opencode/plugins/` (see install above).
|
|
417
401
|
3. Edit code → the watcher rebuilds → **restart opencode** to reload the plugin.
|
|
418
402
|
4. Use it; watch the toasts, run `bun run status`, and set `OPENCODE_AUTH_LB_DEBUG=1` to log selections.
|
|
419
403
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import type { Plugin } from '@opencode/plugin';
|
|
2
1
|
export { AnthropicLoadBalancerPlugin, AuthLoadBalancerStatusPlugin, KimiCodeGlobalLoadBalancerPlugin, KimiCodeLoadBalancerPlugin, OpenAILoadBalancerPlugin, } from './legacy';
|
|
3
|
-
declare const _default: {
|
|
4
|
-
id: string;
|
|
5
|
-
setup(ctx: Plugin.Context): Promise<Plugin.Cleanup>;
|
|
6
|
-
};
|
|
7
|
-
export default _default;
|