feat(OpenCode TLS): 新增自簽憑證驗證略過設定

This commit is contained in:
2026-06-20 13:15:44 +00:00
parent c7e63c9468
commit f7e4f09d4e
4 changed files with 28 additions and 5 deletions
+11 -3
View File
@@ -1,5 +1,6 @@
import axios from 'axios';
import { getLLMConfig } from './config.js';
import https from 'https';
import { getLLMConfig, shouldSkipOpenCodeTLSVerify } from './config.js';
import { line, error } from './log.js';
function isOpenAIGpt55(provider, model) {
@@ -46,6 +47,13 @@ function applyOpenCodeAuth(headers) {
headers['Authorization'] = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
}
function opencodeAxiosOptions(headers) {
return {
headers,
httpsAgent: shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined,
};
}
function extractOpenCodeContent(data) {
const parts = data.parts || data.data?.parts || data.info?.content || data.data?.info?.content || [];
return parts
@@ -60,7 +68,7 @@ async function chatOpenCode(baseURL, model, systemPrompt, userContent, headers)
const session = await axios.post(
`${base}/session`,
{ title: 'AI Code Review', model: { providerID, id: modelID } },
{ headers }
opencodeAxiosOptions(headers)
);
const sessionID = session.data.id || session.data.data?.id;
if (!sessionID) throw new Error('OpenCode session 建立失敗:回應中沒有 session id');
@@ -72,7 +80,7 @@ async function chatOpenCode(baseURL, model, systemPrompt, userContent, headers)
system: systemPrompt,
parts: [{ type: 'text', text: userContent }],
},
{ headers }
opencodeAxiosOptions(headers)
);
return extractOpenCodeContent(resp.data);
}