From babe599977630fb34486fe7f6798c9f53e5586a0 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Sat, 20 Jun 2026 13:42:25 +0000 Subject: [PATCH] =?UTF-8?q?refactor(OpenCode=20TLS):=20=E5=85=B1=E7=94=A8?= =?UTF-8?q?=20httpsAgent=20=E5=BB=BA=E7=AB=8B=E9=82=8F=E8=BC=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config.js | 6 ++++++ app/llm.js | 5 ++--- app/preflight.js | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/config.js b/app/config.js index 9ba433f..0fcf655 100644 --- a/app/config.js +++ b/app/config.js @@ -1,3 +1,5 @@ +import https from 'https'; + export const GITEA_TOKEN = process.env.GITEA_TOKEN || ''; export const GITEA_COMMENT_TOKEN = process.env.GITEA_COMMENT_TOKEN || ''; export const GITEA_SERVER_URL = process.env.GITEA_SERVER_URL || 'https://gitea.com'; @@ -15,6 +17,10 @@ export function shouldSkipOpenCodeTLSVerify() { return process.env.OPENCODE_SKIP_TLS_VERIFY === 'true'; } +export function getOpenCodeHttpsAgent() { + return shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined; +} + /** 將逗號分隔的 API key 字串拆成陣列 */ function splitKeys(value) { if (!value) return []; diff --git a/app/llm.js b/app/llm.js index d4e6214..a6830f8 100644 --- a/app/llm.js +++ b/app/llm.js @@ -1,6 +1,5 @@ import axios from 'axios'; -import https from 'https'; -import { getLLMConfig, shouldSkipOpenCodeTLSVerify } from './config.js'; +import { getLLMConfig, getOpenCodeHttpsAgent } from './config.js'; import { line, error } from './log.js'; function isOpenAIGpt55(provider, model) { @@ -50,7 +49,7 @@ function applyOpenCodeAuth(headers) { function opencodeAxiosOptions(headers) { return { headers, - httpsAgent: shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined, + httpsAgent: getOpenCodeHttpsAgent(), }; } diff --git a/app/preflight.js b/app/preflight.js index 6690bbe..143ce57 100644 --- a/app/preflight.js +++ b/app/preflight.js @@ -7,8 +7,8 @@ import { GITEA_REPOSITORY, GITEA_SKIP_TLS_VERIFY, PR_NUMBER, + getOpenCodeHttpsAgent, getLLMConfig, - shouldSkipOpenCodeTLSVerify, } from './config.js'; import { verifyRemoteAccess } from './git.js'; import { step, line, ok, error } from './log.js'; @@ -30,7 +30,7 @@ const applyOpenCodeAuth = (headers) => { const opencodeAxiosOptions = (headers) => ({ headers, timeout: 30000, - httpsAgent: shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined, + httpsAgent: getOpenCodeHttpsAgent(), }); function giteaErr(e) {