fix opencode error

This commit is contained in:
southseact-3d
2026-02-10 18:32:41 +00:00
parent 8e8129d71c
commit f1d3dce73c
2 changed files with 4 additions and 11 deletions

View File

@@ -7954,15 +7954,7 @@ async function listModels(cliName = 'opencode') {
const cliCommand = resolveCliCommand(normalizedCli);
// Try CLI models with --json
try {
const { stdout } = await runCommand(cliCommand, ['models', '--json'], { timeout: 15000 });
const parsed = JSON.parse(stdout);
const parsedList = Array.isArray(parsed) ? parsed : parsed.models || [];
parsedList.forEach((m) => addModel(m));
} catch (error) { log('Unable to read models via --json', { cli: normalizedCli, error: String(error) }); }
// Fallback: Try CLI models without --json
// Try CLI models (text output format: provider/model per line)
try {
const { stdout } = await runCommand(cliCommand, ['models'], { timeout: 15000 });
const lines = stdout.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
@@ -7972,7 +7964,7 @@ async function listModels(cliName = 'opencode') {
addModel({ name, label: name });
}
});
} catch (fallbackError) { log('Models text fallback failed', { cli: normalizedCli, error: String(fallbackError) }); }
} catch (error) { log('Unable to read models', { cli: normalizedCli, error: String(error) }); }
// Try provider and connection commands in parallel
const providerCmds = [
@@ -16556,7 +16548,7 @@ async function handleDeleteSession(req, res, sessionId, userId) {
async function handleDiagnostics(_req, res) {
try {
const versionRes = await runCommand('opencode', ['--version'], { timeout: 5000 }).catch((e) => ({ stdout: e.stdout, stderr: e.stderr, code: e.code }));
const modelRes = await runCommand('opencode', ['models', '--json'], { timeout: 10000 }).catch((e) => ({ stdout: e.stdout, stderr: e.stderr, code: e.code }));
const modelRes = await runCommand('opencode', ['models'], { timeout: 10000 }).catch((e) => ({ stdout: e.stdout, stderr: e.stderr, code: e.code }));
sendJson(res, 200, { version: versionRes.stdout || versionRes.stderr, modelsOutput: modelRes.stdout || modelRes.stderr });
} catch (error) {
sendJson(res, 500, { error: String(error.message || error) });