Files
ai-code-review/app/config.js
T

49 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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';
export const GITEA_REPOSITORY = process.env.GITEA_REPOSITORY || '';
export const PR_NUMBER = process.env.PR_NUMBER || '';
export const PR_HEAD_SHA = process.env.PR_HEAD_SHA || '';
export const PR_HEAD_BRANCH = process.env.PR_HEAD_BRANCH || '';
export const PR_BASE_BRANCH = process.env.PR_BASE_BRANCH || '';
export const FINDINGS_PATH = '.gitea/ai-review/findings.json';
export const EXCLUSIONS_PATH = '.gitea/ai-review/exclusions.json';
/**
* 建立一個停用 TLS 憑證驗證(`rejectUnauthorized: false`)的 HTTPS Agent
* 供連接使用自簽或無效憑證的 OpenCode 服務時使用。
*
* @remarks 每次呼叫都會回傳全新的 Agent 實例(不快取),建議呼叫端重用以共用連線池。
* 停用憑證驗證有中間人攻擊風險,僅限受信任的內部環境使用。
* @returns {import('https').Agent} 已關閉憑證驗證的 HTTPS Agent 實例。
*/
export function getOpenCodeHttpsAgent() {
return new https.Agent({ rejectUnauthorized: false });
}
/**
* 依環境變數解析並回傳 LLM 提供者設定。
*
* 當設定了 `OPENCODE_BASE_URL` 時回傳 OpenCode 提供者設定
* model 取自 `OPENCODE_MODEL`,預設為 `gemini-2.5-flash`);
* 否則回傳各欄位皆為空/null 的「無提供者」設定,由呼叫端據此判斷是否略過 LLM 流程。
*
* @remarks 每次呼叫都會即時讀取 `process.env`。`apiKeys` 在 OpenCode 模式下為固定佔位值 `['opencode']`,並非真實金鑰。
* @returns {{ provider: ('opencode'|null), apiKeys: string[], baseURL: (string|null), model: (string|null) }}
* LLM 設定物件;`provider` 為 `null` 表示沒有可用的提供者。
*/
export function getLLMConfig() {
if (process.env.OPENCODE_BASE_URL) {
return {
provider: 'opencode',
apiKeys: ['opencode'],
baseURL: process.env.OPENCODE_BASE_URL,
model: process.env.OPENCODE_MODEL || 'gemini-2.5-flash',
};
}
return { provider: null, apiKeys: [], baseURL: null, model: null };
}