opencode-gemini-web 1.0.0 → 1.0.2

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
@@ -66,7 +66,7 @@ mv ~/.local/state/opencode-hydrogen ~/.local/state/opencode-gemini-web
66
66
  ## Configuration notes
67
67
 
68
68
  The state directory defaults to `~/.local/state/opencode-gemini-web`. Set
69
- `XDG_STATE_HOME` before running both commands to use a different state root.
69
+ `XDG_STATE_HOME` before running the commands to use a different state root.
70
70
  The adapter and Chrome's debug port listen on loopback. Give access to the
71
71
  browser profile and its debugger only to people who should control that Gemini
72
72
  session.
@@ -82,15 +82,24 @@ If OpenCode reports that your Gemini session expired, run
82
82
  `opencode-gemini-web login` again, finish sign-in, and retry in the same
83
83
  conversation. If OpenCode reports an invalid local adapter key, check that the
84
84
  provider references the key path printed at startup. If a selected model is
85
- unavailable, refresh the provider catalog with the sync command.
85
+ unavailable, refresh the provider catalog with the sync command. If OpenCode
86
+ keeps retrying and failing, Gemini may be throttling sustained automation on
87
+ your account for a few minutes; wait between sessions.
86
88
 
87
- ## Working on the source
88
-
89
- Clone the repository, run `npm ci`, and use `npm run login`, `npm start`,
90
- `npm run sync-models`, and `npm test` in place of the global CLI. The `npm`
91
- scripts run the same code as the CLI.
89
+ ## Behavior
92
90
 
93
91
  Each request selects the requested model and sends the OpenCode transcript
94
92
  through a fresh Gemini Temporary Chat. The adapter supports text and one tool call per reply. OpenCode can
95
93
  run more tool calls in subsequent replies and applies its own tool permissions.
96
94
  Streaming clients receive the completed reply as SSE.
95
+
96
+ Each reply costs a full Gemini web round-trip, so tool-heavy tasks take
97
+ minutes. If Gemini returns its own error page or claims it ran out of tool
98
+ calls, the adapter reports it as a retryable error and OpenCode retries the
99
+ request automatically.
100
+
101
+ ## Working on the source
102
+
103
+ Clone the repository, run `npm ci`, and use `npm run login`, `npm start`,
104
+ `npm run sync-models`, and `npm test` in place of the global CLI. The `npm`
105
+ scripts run the same code as the CLI.
package/adapter.mjs CHANGED
@@ -76,8 +76,8 @@ function prepare(body) {
76
76
  if (tools.length) {
77
77
  // shortcut: the web composer accepts text, switch to native function calling when the upstream supports it.
78
78
  instructions.push(
79
- required ? 'Your next reply must call an available tool.' : 'You can request one tool call per reply. After a tool result, continue with another tool call whenever the task needs one.',
80
- 'For a tool call, output only this JSON shape: {"opencode_tool_call":{"name":"tool-name","arguments":{}}}. The top-level key must be opencode_tool_call. Argument names must match the tool schema.',
79
+ required ? 'Your next reply must call an available tool.' : 'Use a tool whenever the task needs one. There is no limit on tool calls: after a tool result you may call another tool in your next reply.',
80
+ 'To call a tool, reply with only this JSON shape: {"opencode_tool_call":{"name":"tool-name","arguments":{}}}. The top-level key must be opencode_tool_call. Argument names must match the tool schema. The reply must contain no other text. Never say tools are unavailable or used up.',
81
81
  'Available tools: ' + JSON.stringify(tools),
82
82
  );
83
83
  }
@@ -109,6 +109,10 @@ function formatReply(text, { tools, required }) {
109
109
  };
110
110
  }
111
111
  if (required) throw new RequestError(502, 'Gemini did not return the required tool call.');
112
+ // Gemini sometimes confabulates a tool-call budget it ran out of, or returns its own error page as text; 502 makes the client retry for a fresh sample.
113
+ if (/^sorry, something went wrong/i.test(text) || (tools.length && /\btool (calls?|execution)\b[^.]{0,40}\b(unavailable|remaining|permitted|exhausted)\b/i.test(text))) {
114
+ throw new RequestError(502, 'Gemini claimed its tool calls ran out. Retry the request.', 'gemini_tool_refusal');
115
+ }
112
116
  return { message: { role: 'assistant', content: text }, finish: 'stop' };
113
117
  }
114
118
 
package/adapter.test.mjs CHANGED
@@ -18,10 +18,11 @@ const server = createAdapter(key, async (prompt, _signal, requestedModel) => {
18
18
  throw new RequestError(401, 'Sign in to Gemini again with npm run login.', 'gemini_login_required');
19
19
  }
20
20
  if (prompt.includes('First tool result')) {
21
- assert.match(prompt, /one tool call per reply/i);
22
- assert.match(prompt, /after a tool result, continue/i);
21
+ assert.match(prompt, /no limit on tool calls/i);
22
+ assert.match(prompt, /after a tool result you may call another tool/i);
23
23
  }
24
24
  if (prompt.includes('Unlisted tool test')) return call.replace('"read"', '"write"');
25
+ if (prompt.includes('Tool refusal test')) return 'I cannot act; tool calls are currently unavailable (0 remaining in this turn).';
25
26
  if (!models.some(({ id }) => id === requestedModel)) {
26
27
  throw new RequestError(404, 'No such model.', 'gemini_model_unavailable');
27
28
  }
@@ -77,6 +78,15 @@ test('reports an expired Gemini session independently of the adapter key', async
77
78
  assert.match(error.message, /npm run login/);
78
79
  });
79
80
 
81
+ test('turns a confabulated tool-budget refusal into a retryable 502', async () => {
82
+ const response = await complete({
83
+ tools: [tool],
84
+ messages: [...messages, { role: 'user', content: 'Tool refusal test' }],
85
+ });
86
+ assert.equal(response.status, 502);
87
+ assert.equal((await response.json()).error.code, 'gemini_tool_refusal');
88
+ });
89
+
80
90
  test('offers another tool call after receiving a tool result', async () => {
81
91
  const response = await complete({
82
92
  tools: [tool],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gemini-web",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Use your signed-in Gemini web account's models from OpenCode through a local adapter",
5
5
  "type": "module",
6
6
  "bin": {
package/serve.mjs CHANGED
@@ -5,7 +5,7 @@ import { createAdapter, RequestError } from './adapter.mjs';
5
5
  import { geminiPageState, geminiURL, openBrowser, stateDir, waitForSession } from './browser.mjs';
6
6
  import { readModelMenu, selectModel } from './models.mjs';
7
7
 
8
- const generationTimeout = 150_000;
8
+ const generationTimeout = 240_000;
9
9
  let browserConnection;
10
10
 
11
11
  function loginRequired() {