mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
实现listExperiments端点和通用转发机制
- 添加forwardToCodeAssist通用转发函数支持简单端点 - 添加handleSimpleEndpoint通用路由处理函数 - 注册listExperiments路由(v1internal和v1beta) - 解决gemini-cli启动时404 Not Found错误
This commit is contained in:
@@ -1060,6 +1060,47 @@ async function getOauthClient(accessToken, refreshToken, proxyConfig = null) {
|
||||
return client
|
||||
}
|
||||
|
||||
// 通用的 Code Assist API 转发函数(用于简单的请求/响应端点)
|
||||
// 适用于:loadCodeAssist, onboardUser, countTokens, listExperiments 等不需要特殊处理的端点
|
||||
async function forwardToCodeAssist(client, apiMethod, requestBody, proxyConfig = null) {
|
||||
const axios = require('axios')
|
||||
const CODE_ASSIST_ENDPOINT = 'https://cloudcode-pa.googleapis.com'
|
||||
const CODE_ASSIST_API_VERSION = 'v1internal'
|
||||
|
||||
const { token } = await client.getAccessToken()
|
||||
const proxyAgent = ProxyHelper.createProxyAgent(proxyConfig)
|
||||
|
||||
logger.info(`📡 ${apiMethod} API调用开始`)
|
||||
|
||||
const axiosConfig = {
|
||||
url: `${CODE_ASSIST_ENDPOINT}/${CODE_ASSIST_API_VERSION}:${apiMethod}`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: requestBody,
|
||||
timeout: 30000
|
||||
}
|
||||
|
||||
// 添加代理配置
|
||||
if (proxyAgent) {
|
||||
axiosConfig.httpAgent = proxyAgent
|
||||
axiosConfig.httpsAgent = proxyAgent
|
||||
axiosConfig.proxy = false
|
||||
logger.info(
|
||||
`🌐 Using proxy for ${apiMethod}: ${ProxyHelper.getProxyDescription(proxyConfig)}`
|
||||
)
|
||||
} else {
|
||||
logger.debug(`🌐 No proxy configured for ${apiMethod}`)
|
||||
}
|
||||
|
||||
const response = await axios(axiosConfig)
|
||||
|
||||
logger.info(`✅ ${apiMethod} API调用成功`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
// 调用 Google Code Assist API 的 loadCodeAssist 方法(支持代理)
|
||||
async function loadCodeAssist(client, projectId = null, proxyConfig = null) {
|
||||
const axios = require('axios')
|
||||
@@ -1529,6 +1570,7 @@ module.exports = {
|
||||
getAccountRateLimitInfo,
|
||||
isTokenExpired,
|
||||
getOauthClient,
|
||||
forwardToCodeAssist, // 通用转发函数
|
||||
loadCodeAssist,
|
||||
getOnboardTier,
|
||||
onboardUser,
|
||||
|
||||
Reference in New Issue
Block a user