From baffd02b02d0805243b2ece7362cb509f10808c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=BA=86=E9=9B=B7?= Date: Wed, 12 Nov 2025 14:10:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DloadCodeAssist=E4=B8=AD?= =?UTF-8?q?=E7=A7=BB=E9=99=A4tokeninfo=E5=92=8Cuserinfo=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决使用GOOGLE_CLOUD_ACCESS_TOKEN时401错误,提升接口响应速度 --- src/services/geminiAccountService.js | 50 ++-------------------------- 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/src/services/geminiAccountService.js b/src/services/geminiAccountService.js index 2e35966e..169df32e 100644 --- a/src/services/geminiAccountService.js +++ b/src/services/geminiAccountService.js @@ -1069,54 +1069,10 @@ async function loadCodeAssist(client, projectId = null, proxyConfig = null) { const { token } = await client.getAccessToken() const proxyAgent = ProxyHelper.createProxyAgent(proxyConfig) - const tokenInfoConfig = { - url: 'https://oauth2.googleapis.com/tokeninfo', - method: 'POST', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/x-www-form-urlencoded' - }, - data: new URLSearchParams({ access_token: token }).toString(), - timeout: 15000 - } - - if (proxyAgent) { - tokenInfoConfig.httpAgent = proxyAgent - tokenInfoConfig.httpsAgent = proxyAgent - tokenInfoConfig.proxy = false - } - - try { - await axios(tokenInfoConfig) - logger.info('📋 tokeninfo 接口验证成功') - } catch (error) { - logger.info('tokeninfo 接口获取失败', error) - } - - const userInfoConfig = { - url: 'https://www.googleapis.com/oauth2/v2/userinfo', - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - Accept: '*/*' - }, - timeout: 15000 - } - - if (proxyAgent) { - userInfoConfig.httpAgent = proxyAgent - userInfoConfig.httpsAgent = proxyAgent - userInfoConfig.proxy = false - } - - try { - await axios(userInfoConfig) - logger.info('📋 userinfo 接口获取成功') - } catch (error) { - logger.info('userinfo 接口获取失败', error) - } - // 创建ClientMetadata + // Note: 移除了 tokeninfo 和 userinfo 验证调用 + // 这些调用在原生 gemini-cli 的 CodeAssistServer.loadCodeAssist 中不存在 + // 且会导致使用特殊 token 时出现 401 错误 const clientMetadata = { ideType: 'IDE_UNSPECIFIED', platform: 'PLATFORM_UNSPECIFIED',