fix(opencode): switch session models without restart

This commit is contained in:
2026-08-20 22:38:18 +08:00
parent 1c6b004436
commit c0163bc507
18 changed files with 718 additions and 92 deletions

View File

@@ -169,6 +169,35 @@ describe('opencode client', () => {
}
});
it('switches the model used by subsequent turns through the OpenCode session API', async () => {
const fetchImpl = vi.fn(async () => new Response(null, { status: 204 }));
const client = createOpencodeClient({
baseUrl: 'http://127.0.0.1:4096',
directory: 'D:/work/app',
fetchImpl,
});
const controller = new AbortController();
await client.switchSessionModel('ses_1', {
providerID: 'niancode-user-models',
modelID: 'qwen3.7-plus',
}, { signal: controller.signal });
expect(fetchImpl).toHaveBeenCalledWith(
'http://127.0.0.1:4096/api/session/ses_1/model?directory=D%3A%2Fwork%2Fapp',
expect.objectContaining({
method: 'POST',
body: JSON.stringify({
model: {
providerID: 'niancode-user-models',
modelID: 'qwen3.7-plus',
},
}),
signal: controller.signal,
}),
);
});
it('posts a text message to a session scoped to the selected folder', async () => {
const fetchImpl = vi.fn(async () => {
return new Response(JSON.stringify({ id: 'msg_1', role: 'user' }), {