opencode-auth-load-balancer 0.6.0 → 0.7.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 CHANGED
@@ -27,18 +27,70 @@ 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
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:
39
+
40
+ ```jsonc
41
+ {
42
+ "$schema": "https://opencode.ai/config.json",
43
+ "plugins": ["C:/path/to/opencode-auth-load-balancer"]
44
+ }
45
+ ```
46
+
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.
69
+
70
+ Verification:
71
+
72
+ ```bash
73
+ bun run typecheck
74
+ bun test
75
+ 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
79
+ ```
80
+
30
81
  ---
31
82
 
32
83
  ## Install & build
33
84
 
34
85
  ```bash
35
86
  bun install
36
- bun run build # → dist/index.js (a single self-contained file)
87
+ bun run build # V2: dist/index.js; V1: dist/v1.js
37
88
  ```
38
89
 
39
- The bundle imports only Node built-ins, so it can be dropped into opencode as one file.
90
+ 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.
40
92
 
41
- ### Load it into opencode (local / dev)
93
+ ### Load it into OpenCode 1 (local / dev)
42
94
 
43
95
  opencode auto-loads any `.ts`/`.js` file in a **plugins directory**:
44
96
 
@@ -50,13 +102,13 @@ Copy or symlink the built bundle into your opencode project's plugin dir:
50
102
  ```bash
51
103
  # macOS / Linux — symlink so rebuilds are picked up automatically
52
104
  mkdir -p .opencode/plugins
53
- ln -sf "$(pwd)/dist/index.js" .opencode/plugins/auth-load-balancer.js
105
+ ln -sf "$(pwd)/dist/v1.js" .opencode/plugins/auth-load-balancer.js
54
106
  ```
55
107
 
56
108
  ```powershell
57
109
  # Windows (PowerShell) — copy (symlinks need Developer Mode / admin)
58
110
  New-Item -ItemType Directory -Force -Path .opencode\plugins | Out-Null
59
- Copy-Item dist\index.js .opencode\plugins\auth-load-balancer.js
111
+ Copy-Item dist\v1.js .opencode\plugins\auth-load-balancer.js
60
112
  ```
61
113
 
62
114
  Restart opencode to load it. (opencode does **not** hot-reload plugins — see the dev loop below.)
@@ -67,7 +119,7 @@ Restart opencode to load it. (opencode does **not** hot-reload plugins — see t
67
119
  // opencode.json
68
120
  {
69
121
  "$schema": "https://opencode.ai/config.json",
70
- "plugin": ["opencode-auth-load-balancer"]
122
+ "plugins": ["opencode-auth-load-balancer"]
71
123
  }
72
124
  ```
73
125
 
@@ -266,7 +318,7 @@ Then register the entry in `~/.config/opencode/tui.json` (this is how opencode l
266
318
  }
267
319
  ```
268
320
 
269
- > **Why this shape (it matters):** TUI plugins load from the `plugin` array in `tui.json`, **not** from the server's plugins-dir glob. The server *separately* globs `{plugin,plugins}/*.{ts,js}` and loads every match as a **server** plugin — so a TUI entry dropped in `plugins/` is also loaded by the server, rejected (`must default export … server()`), and logs an error on **every** launch (and a stray scoring `.ts` there would be mis-loaded as a plugin and break provider resolution). Keeping the four files OUTSIDE `plugins/` and registering only via `tui.json` avoids that. The split into a `.ts` **entry** that **lazily imports** a `.tsx` **view** is still required because opencode's runtime SolidJS JSX transform (`@opentui/solid`) only matches `*.{tsx,jsx}` — a `.ts` cannot itself contain JSX, and the lazy import keeps the server plugin worker (which never runs `tui()`) from evaluating the SolidJS module graph. Developed against opencode / `@opencode-ai/plugin` `>=1.18.26` + `@opentui/solid` `0.5.10` (the versions currently pinned in `package.json`). The `.tsx` view **is** typechecked (`tsconfig.tui.json`) and linted here — its JSX deps (`solid-js` + `@opentui/*`) are installed as devDependencies pinned to those versions — so type/import/prop breaks are caught in CI; only its runtime rendering still needs a live opencode TUI to verify. The toast + `auth_lb_status` tool + `bun run status` CLI cover the same information regardless. (`auth-load-balancer-tui.logic.ts` has no JSX and no TUI-runtime dependency, so it is directly unit-tested rather than only typechecked.)
321
+ > **Why this shape (it matters):** TUI plugins load from the `plugin` array in `tui.json`, **not** from the server's plugins-dir glob. The server *separately* globs `{plugin,plugins}/*.{ts,js}` and loads every match as a **server** plugin — so a TUI entry dropped in `plugins/` is also loaded by the server, rejected (`must default export … server()`), and logs an error on **every** launch (and a stray scoring `.ts` there would be mis-loaded as a plugin and break provider resolution). Keeping the four files OUTSIDE `plugins/` and registering only via `tui.json` avoids that. The split into a `.ts` **entry** that **lazily imports** a `.tsx` **view** is still required because opencode's runtime SolidJS JSX transform (`@opentui/solid`) only matches `*.{tsx,jsx}` — a `.ts` cannot itself contain JSX, and the lazy import keeps the server plugin worker (which never runs `tui()`) from evaluating the SolidJS module graph. Developed against opencode / `@opencode-ai/plugin` `>=1.18.26` + `@opentui/solid` `0.5.10` originally; development dependencies now use `0.5.17` for V2 compatibility. The `.tsx` view **is** typechecked (`tsconfig.tui.json`) and linted here — its JSX deps (`solid-js` + `@opentui/*`) are installed as devDependencies pinned to those versions — so type/import/prop breaks are caught in CI; only its runtime rendering still needs a live opencode TUI to verify. The toast + `auth_lb_status` tool + `bun run status` CLI cover the same information regardless. (`auth-load-balancer-tui.logic.ts` has no JSX and no TUI-runtime dependency, so it is directly unit-tested rather than only typechecked.)
270
322
 
271
323
  ---
272
324
 
@@ -359,8 +411,8 @@ The unit/integration suite runs with coverage **gated at 100%** (lines and funct
359
411
 
360
412
  opencode loads plugins once at startup, so the loop is:
361
413
 
362
- 1. `bun run dev` — keeps `dist/index.js` rebuilt on every edit.
363
- 2. Symlink `dist/index.js` into your opencode project's `.opencode/plugins/` once (see install above).
414
+ 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).
364
416
  3. Edit code → the watcher rebuilds → **restart opencode** to reload the plugin.
365
417
  4. Use it; watch the toasts, run `bun run status`, and set `OPENCODE_AUTH_LB_DEBUG=1` to log selections.
366
418
 
package/dist/index.d.ts CHANGED
@@ -1,12 +1,7 @@
1
- import type { Plugin } from '@opencode-ai/plugin';
2
- export declare const AnthropicLoadBalancerPlugin: Plugin;
3
- export declare const OpenAILoadBalancerPlugin: Plugin;
4
- export declare const KimiCodeLoadBalancerPlugin: Plugin;
5
- export declare const KimiCodeGlobalLoadBalancerPlugin: Plugin;
6
- /**
7
- * A standalone plugin that registers the `auth_lb_status` tool — an on-demand
8
- * dashboard (in-use account per provider, each account's weekly/5h usage,
9
- * cooldowns, and the ranked next candidates) across ALL providers. Registered once
10
- * (not per provider) so the tool name doesn't collide.
11
- */
12
- export declare const AuthLoadBalancerStatusPlugin: Plugin;
1
+ import type { Plugin } from '@opencode/plugin';
2
+ 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;