fix(opencode): switch session models without restart
This commit is contained in:
@@ -1527,6 +1527,36 @@ export async function handleOpencodeRoutes(
|
||||
const sessionSummarizeMatch = url.pathname.match(
|
||||
/^\/api\/opencode\/sessions\/([^/]+)\/summarize$/,
|
||||
);
|
||||
const sessionModelMatch = url.pathname.match(
|
||||
/^\/api\/opencode\/sessions\/([^/]+)\/model$/,
|
||||
);
|
||||
if (sessionModelMatch && req.method === 'POST') {
|
||||
try {
|
||||
await coordinateRuntimeExecution(res, ctx, async (signal, _markPending, response) => {
|
||||
signal.throwIfAborted();
|
||||
const body = await parseJsonBody<{ model?: unknown }>(req);
|
||||
const model = parseRuntimePromptModel(body.model);
|
||||
if (!model) {
|
||||
sendJson(response, 400, { success: false, error: 'Invalid model reference' });
|
||||
return;
|
||||
}
|
||||
const client = await createClientForActiveProject(response, ctx, { signal });
|
||||
signal.throwIfAborted();
|
||||
if (!client) return;
|
||||
const sessionID = decodeURIComponent(sessionModelMatch[1]);
|
||||
await client.switchSessionModel(sessionID, model, { signal });
|
||||
signal.throwIfAborted();
|
||||
sendJson(response, 200, {
|
||||
success: true,
|
||||
model: `${model.providerID}/${model.modelID}`,
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
sendJson(res, 500, { success: false, error: String(error) });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sessionSummarizeMatch && req.method === 'POST') {
|
||||
try {
|
||||
await coordinateRuntimeExecution(res, ctx, async (signal, markPending, response) => {
|
||||
@@ -1985,7 +2015,7 @@ export async function handleOpencodeRoutes(
|
||||
sendJson(response, 400, { success: false, error: 'Invalid model reference' });
|
||||
return;
|
||||
}
|
||||
const model = explicitModel ?? await resolveRuntimePromptModel(runtimeConfigSummary);
|
||||
const model = explicitModel;
|
||||
signal.throwIfAborted();
|
||||
const files = normalizePromptFileParts(body.files);
|
||||
const userContext = typeof body.userContext === 'string' ? body.userContext.trim().slice(0, 2_000) : '';
|
||||
|
||||
Reference in New Issue
Block a user