opencode-gemini-business 2.0.5 β†’ 2.2.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 CHANGED
@@ -1,3 +1,22 @@
1
+ # [2.2.0](https://github.com/izzzzzi/opencode-gemini-business/compare/v2.1.0...v2.2.0) (2026-03-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * browser-based account login, update model list, swap README lang ([d0eb82f](https://github.com/izzzzzi/opencode-gemini-business/commit/d0eb82fabf337004f330646fb1ec1af38cb87d96))
7
+
8
+ # [2.1.0](https://github.com/izzzzzi/opencode-gemini-business/compare/v2.0.5...v2.1.0) (2026-02-15)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update tests for named export and async plugin factory ([582bada](https://github.com/izzzzzi/opencode-gemini-business/commit/582badaa32aefd7cee8c39642224f06972e15b2e))
14
+
15
+
16
+ ### Features
17
+
18
+ * auto-create auth record, update models and streaming ([13c5e8a](https://github.com/izzzzzi/opencode-gemini-business/commit/13c5e8a065051deadc4663757b42cbba189fcaec))
19
+
1
20
  ## [2.0.5](https://github.com/izzzzzi/opencode-gemini-business/compare/v2.0.4...v2.0.5) (2026-02-15)
2
21
 
3
22
 
package/README.en.md ADDED
@@ -0,0 +1,278 @@
1
+ <div align="center">
2
+
3
+ # πŸ”„ opencode-gemini-business
4
+
5
+ **Multi-account Gemini Business pool with intelligent rotation for OpenCode**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/opencode-gemini-business.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/opencode-gemini-business)
8
+ [![npm downloads](https://img.shields.io/npm/dm/opencode-gemini-business.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/opencode-gemini-business)
9
+ [![GitHub release](https://img.shields.io/github/v/release/izzzzzi/opencode-gemini-business?style=flat&colorA=18181B&colorB=28CF8D)](https://github.com/izzzzzi/opencode-gemini-business/releases)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat&colorA=18181B&colorB=28CF8D)](LICENSE)
11
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue?style=flat&colorA=18181B&colorB=3178C6)](https://www.typescriptlang.org/)
12
+ [![Node.js](https://img.shields.io/badge/Node.js-ESM-green?style=flat&colorA=18181B&colorB=339933)](https://nodejs.org/)
13
+
14
+ [πŸ‡·πŸ‡Ί Русский](README.md) | **πŸ‡¬πŸ‡§ English**
15
+
16
+ <br />
17
+
18
+ *Auth plugin for [OpenCode](https://github.com/anomalyco/opencode) β€” pool multiple Gemini Business accounts with automatic rotation, failover, and load balancing.*
19
+
20
+ </div>
21
+
22
+ ---
23
+
24
+ ## πŸ“– Overview
25
+
26
+ **opencode-gemini-business** is an OpenCode plugin that enables multi-account rotation for **Gemini Business API** (`business.gemini.google`), providing automatic failover and load balancing across multiple accounts.
27
+
28
+ > **Important**: This plugin uses the **Gemini Business / Enterprise API**, NOT Google AI Studio.
29
+
30
+ ---
31
+
32
+ ## ✨ Features
33
+
34
+ | Feature | Description |
35
+ |---------|-------------|
36
+ | πŸ”„ **Multi-Account Rotation** | Automatically rotate between multiple Gemini Business accounts |
37
+ | πŸ›‘οΈ **Automatic Failover** | Retry failed requests with different accounts seamlessly |
38
+ | πŸ” **JWT Authentication** | Built-in XSRF token retrieval and JWT (HS256) signing |
39
+ | πŸ“‘ **Streaming Support** | Full SSE streaming, JSON-lines, and fallback parsing |
40
+ | βš™οΈ **Flexible Strategies** | Round-robin, least-used, or random rotation |
41
+ | πŸ”‘ **Auto Auth Setup** | `add-account` automatically creates OpenCode auth record |
42
+
43
+ ---
44
+
45
+ ## πŸ€– Supported Models
46
+
47
+ | Model | Internal API ID | Best For |
48
+ |-------|:---------------:|---------|
49
+ | `gemini-2.5-flash` | `gemini-2.5-flash` | Everyday tasks, fast responses |
50
+ | `gemini-2.5-pro` | `gemini-2.5-pro` | Complex reasoning |
51
+ | `gemini-3-flash` | `gemini-3-flash-preview` | Next-gen fast model |
52
+ | `gemini-3.1-pro` | `gemini-3.1-pro-preview` | Advanced reasoning (preview) |
53
+ | `auto` | *(empty)* | Gemini auto-selects the best model |
54
+
55
+ ---
56
+
57
+ ## πŸš€ Quick Start
58
+
59
+ ### Step 1: Configure OpenCode
60
+
61
+ Add to `~/.config/opencode/opencode.json`:
62
+
63
+ ```json
64
+ {
65
+ "$schema": "https://opencode.ai/config.json",
66
+ "plugin": ["opencode-gemini-business@latest"],
67
+ "provider": {
68
+ "gemini-business": {
69
+ "name": "Gemini Business",
70
+ "options": {
71
+ "baseURL": "https://business.gemini.google/v1",
72
+ "apiKey": "unused"
73
+ },
74
+ "models": {
75
+ "gemini-2.5-flash": { "name": "Gemini 2.5 Flash" },
76
+ "gemini-2.5-pro": { "name": "Gemini 2.5 Pro" },
77
+ "gemini-3-flash": { "name": "Gemini 3 Flash" },
78
+ "gemini-3.1-pro": { "name": "Gemini 3.1 Pro" },
79
+ "auto": { "name": "Auto Select" }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ ### Step 2: Add Gemini Business account
87
+
88
+ Install the CLI tool:
89
+
90
+ ```bash
91
+ npm install -g opencode-gemini-business
92
+ ```
93
+
94
+ Then add your account (requires Google Chrome or Chromium):
95
+
96
+ ```bash
97
+ opencode-gemini-business add-account
98
+ ```
99
+
100
+ A Chrome window will open β€” sign in to your Gemini Business account and send any message in the chat. Cookies and credentials are captured automatically. That's it!
101
+
102
+ > **Note:** `add-account` automatically creates the auth record in `~/.local/share/opencode/auth.json`, so you don't need to run `opencode auth login`.
103
+
104
+ <details>
105
+ <summary>Manual mode (advanced)</summary>
106
+
107
+ If you prefer to provide credentials manually or don't have Chrome installed:
108
+
109
+ ```bash
110
+ opencode-gemini-business add-account --manual \
111
+ "My Account" \
112
+ "e1f353e7-0291-44cf-9085-e0b6efd20e41" \
113
+ "CSE.AXUaAj_MKeqeFLr_..." \
114
+ "COS.AfQtEyCcW1aLwKb3..." \
115
+ "1370433092"
116
+ ```
117
+
118
+ | # | Argument | Description |
119
+ |:-:|----------|-------------|
120
+ | 1 | Account name | Display name for the account |
121
+ | 2 | `team_id` | UUID from URL `/cid/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/` |
122
+ | 3 | `__Secure-C_SES` | Cookie value (starts with `CSE.`) |
123
+ | 4 | `__Host-C_OSES` | Cookie value (starts with `COS.`) |
124
+ | 5 | `csesidx` | Number from URL `?csesidx=...` |
125
+
126
+ Or use environment variables:
127
+
128
+ ```bash
129
+ export GEMINI_ACCOUNT_NAME="My Account"
130
+ export GEMINI_TEAM_ID="e1f353e7-0291-44cf-9085-e0b6efd20e41"
131
+ export GEMINI_SECURE_C_SES="CSE.AXUaAj_MKeqeFLr_..."
132
+ export GEMINI_HOST_C_OSES="COS.AfQtEyCcW1aLwKb3..."
133
+ export GEMINI_CSESIDX="1370433092"
134
+
135
+ opencode-gemini-business add-account --manual
136
+ ```
137
+
138
+ </details>
139
+
140
+ ### Step 3: Use it
141
+
142
+ ```bash
143
+ # Flash model (fast)
144
+ opencode run --model=gemini-business/gemini-2.5-flash "Fix this bug"
145
+
146
+ # Pro model (best quality)
147
+ opencode run --model=gemini-business/gemini-2.5-pro "Design architecture"
148
+
149
+ # Next-gen models
150
+ opencode run --model=gemini-business/gemini-3-flash "Quick task"
151
+ opencode run --model=gemini-business/gemini-3.1-pro "Advanced reasoning"
152
+ opencode run --model=gemini-business/auto "Let Gemini choose"
153
+ ```
154
+
155
+ Set as default model in `opencode.json`:
156
+
157
+ ```json
158
+ {
159
+ "model": "gemini-business/gemini-2.5-flash"
160
+ }
161
+ ```
162
+
163
+ ---
164
+
165
+ ## πŸ” Extracting Credentials
166
+
167
+ ### Where to find each value
168
+
169
+ Login to [business.gemini.google](https://business.gemini.google) and look at the URL:
170
+
171
+ ```
172
+ https://business.gemini.google/home/cid/e1f353e7-0291-44cf-9085-e0b6efd20e41/r/session/123?csesidx=1370433092
173
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
174
+ team_id (UUID after /cid/) csesidx
175
+ ```
176
+
177
+ ### Cookies
178
+
179
+ **Method 1: Browser Extension (Recommended)**
180
+
181
+ 1. Install [Get cookies.txt LOCALLY](https://chromewebstore.google.com/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc)
182
+ 2. Open `business.gemini.google` and export cookies
183
+ 3. Find `__Secure-C_SES` (starts with `CSE.`) and `__Host-C_OSES` (starts with `COS.`)
184
+
185
+ **Method 2: DevTools**
186
+
187
+ 1. Open DevTools (F12) β†’ **Application** β†’ **Cookies** β†’ `https://business.gemini.google`
188
+ 2. Copy `__Secure-C_SES` and `__Host-C_OSES` values
189
+
190
+ ---
191
+
192
+ ## πŸ”§ Account Management
193
+
194
+ ```bash
195
+ # List all accounts
196
+ opencode-gemini-business list-accounts
197
+
198
+ # Test account connectivity
199
+ opencode-gemini-business test-account <account_id>
200
+
201
+ # Remove account
202
+ opencode-gemini-business remove-account <account_id>
203
+
204
+ # Help
205
+ opencode-gemini-business help
206
+ ```
207
+
208
+ ---
209
+
210
+ ## βš™οΈ Rotation Strategies
211
+
212
+ | Strategy | Behavior |
213
+ |----------|----------|
214
+ | `round-robin` (default) | Cycles through accounts in order |
215
+ | `least-used` | Selects least recently used account |
216
+ | `random` | Random selection |
217
+
218
+ Configure in `~/.config/opencode/gemini-business-accounts.json` (auto-created on first `add-account`).
219
+
220
+ ---
221
+
222
+ ## πŸ› οΈ How It Works
223
+
224
+ 1. Plugin registers as an OpenCode auth provider for `gemini-business`
225
+ 2. When a request comes in, `loader()` returns a custom `fetch()` function
226
+ 3. Custom `fetch()` intercepts the request from `@ai-sdk/openai-compatible`
227
+ 4. Instead of calling `baseURL/chat/completions`, it:
228
+ - Picks an account via rotation strategy
229
+ - Gets XSRF token and creates JWT (HS256)
230
+ - Creates a session via `widgetCreateSession`
231
+ - Sends the actual request to `widgetStreamAssist`
232
+ - Converts the response back to OpenAI-compatible format
233
+ 5. Supports both streaming (SSE) and non-streaming responses
234
+
235
+ ---
236
+
237
+ ## ❓ FAQ
238
+
239
+ <details>
240
+ <summary><b>Q: Where do I find team_id?</b></summary>
241
+
242
+ Look at the URL in your browser: `https://business.gemini.google/home/cid/e1f353e7-0291-44cf-9085-e0b6efd20e41/...`
243
+
244
+ The UUID after `/cid/` is your `team_id`.
245
+ </details>
246
+
247
+ <details>
248
+ <summary><b>Q: Do I need to run `opencode auth login`?</b></summary>
249
+
250
+ No. The `add-account` command automatically creates the auth record in `~/.local/share/opencode/auth.json`. If for some reason it wasn't created, you can run `opencode auth login`, select **gemini-business**, and enter any key (e.g. `unused`).
251
+ </details>
252
+
253
+ <details>
254
+ <summary><b>Q: Session expired errors?</b></summary>
255
+
256
+ The plugin automatically refreshes sessions (cached for 50 minutes). If you see persistent errors, your cookies may have expired β€” re-extract them from the browser.
257
+ </details>
258
+
259
+ <details>
260
+ <summary><b>Q: Difference from Google AI Studio?</b></summary>
261
+
262
+ This plugin uses **Gemini Business API** (`business.gemini.google`) β€” enterprise accounts with higher rate limits. NOT Google AI Studio (`aistudio.google.com`).
263
+ </details>
264
+
265
+ ---
266
+
267
+ ## πŸ”’ Security
268
+
269
+ - Credentials are stored locally in `~/.config/opencode/gemini-business-accounts.json`
270
+ - Never commit credentials to git
271
+ - Rotate cookies regularly
272
+ - The plugin does not send credentials to any third-party services
273
+
274
+ ---
275
+
276
+ ## πŸ“„ License
277
+
278
+ [MIT](LICENSE) Β© opencode-gemini-business contributors