opencode-auth-load-balancer 0.7.1 → 0.8.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/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 2 compatibility
30
+ ### OpenCode 1 compatibility
31
31
 
32
- The main entry targets **OpenCode 2.x**, verified against **2.0.27**. OpenCode 2
33
- uses a default `setup` entry, integration authentication methods, and domain
34
- transforms instead of the V1 `auth.loader` and `chat.headers` hooks.
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
- "plugins": ["C:/path/to/opencode-auth-load-balancer"]
39
+ "plugin": ["opencode-auth-load-balancer"]
44
40
  }
45
41
  ```
46
42
 
47
- For a published npm release, use `"plugins": ["opencode-auth-load-balancer"]`.
48
- The package's `./tui` entry loads the V2 footer and sidebar automatically.
49
- A remote terminal can also load it through `cli.json`'s `plugins` list. Status,
50
- notifications and account management use server RPC, so the terminal never
51
- needs access to the server's credential files.
52
-
53
- Remove the previous V1 server entry and separately registered V1 TUI entry when
54
- switching to V2. Its configuration key is `plugins` (plural); V1's `plugin`
55
- entry and `tui.json` extension use different host APIs. Explicit local V2 entries
56
- must point to a directory, not a copied `dist/index.js` file.
57
-
58
- V2 keeps HTTP transport for pooled providers, including Codex's Responses API,
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,9 +59,8 @@ Verification:
73
59
  bun run typecheck
74
60
  bun test
75
61
  bun run build
76
- bun run scripts/smoke-v2.ts # isolated home/config/database/pool, requires opencode 2
77
- bun run scripts/smoke-v2.ts . --inference # real host, local mock Anthropic, revoked-token rotation
78
- bun run scripts/smoke-v2.ts . --live # real Anthropic request using the existing 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
79
64
  ```
80
65
 
81
66
  ---
@@ -84,11 +69,11 @@ bun run scripts/smoke-v2.ts . --live # real Anthropic request using the existin
84
69
 
85
70
  ```bash
86
71
  bun install
87
- bun run build # V2: dist/index.js; V1: dist/v1.js
72
+ bun run build # V1: dist/index.js; V2: dist/v2-entry.js
88
73
  ```
89
74
 
90
75
  The V1 bundle imports only Node built-ins and can be installed as one file.
91
- OpenCode 2 should load the package directory, which also includes its TUI entry.
76
+ OpenCode 1 loads the default package entry. OpenCode 2 must explicitly load `v2.js`.
92
77
 
93
78
  ### Load it into OpenCode 1 (local / dev)
94
79
 
@@ -119,7 +104,7 @@ Restart opencode to load it. (opencode does **not** hot-reload plugins — see t
119
104
  // opencode.json
120
105
  {
121
106
  "$schema": "https://opencode.ai/config.json",
122
- "plugins": ["opencode-auth-load-balancer"]
107
+ "plugin": ["opencode-auth-load-balancer"]
123
108
  }
124
109
  ```
125
110
 
@@ -412,7 +397,7 @@ The unit/integration suite runs with coverage **gated at 100%** (lines and funct
412
397
  opencode loads plugins once at startup, so the loop is:
413
398
 
414
399
  1. `bun run dev` — keeps both server entry points rebuilt on every edit.
415
- 2. For V2, register the package directory in `opencode.json` using `plugins`. For V1, symlink `dist/v1.js` into `.opencode/plugins/` (see install above).
400
+ 2. For V1, register the package in `opencode.json` using `plugin`, or symlink `dist/index.js` into `.opencode/plugins/` (see install above).
416
401
  3. Edit code → the watcher rebuilds → **restart opencode** to reload the plugin.
417
402
  4. Use it; watch the toasts, run `bun run status`, and set `OPENCODE_AUTH_LB_DEBUG=1` to log selections.
418
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;