opencode-gemini-web 1.0.0 → 1.0.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/adapter.mjs +6 -2
- package/adapter.test.mjs +12 -2
- package/package.json +1 -1
- package/serve.mjs +1 -1
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.' : '
|
|
80
|
-
'
|
|
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, /
|
|
22
|
-
assert.match(prompt, /after a tool result
|
|
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
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 =
|
|
8
|
+
const generationTimeout = 240_000;
|
|
9
9
|
let browserConnection;
|
|
10
10
|
|
|
11
11
|
function loginRequired() {
|