From b83395cdfe64c50976e5ac55e3f33dc899ea406f Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Tue, 16 Jun 2026 19:40:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=99=BB=E5=BD=95=E5=90=8E=E6=B8=85?= =?UTF-8?q?=E7=90=86=20OpenAI=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=92=8C=20ChatGPT=20auth=20=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=87=AD=E8=AF=81=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenAI Compatible / ChatGPT Subscription / 中国区登录成功后,清除 缓存的 OpenAI 客户端实例和 ChatGPT auth 文件,确保下次请求使用新凭证。 Co-Authored-By: deepseek-v4-pro --- src/components/ConsoleOAuthFlow.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/ConsoleOAuthFlow.tsx b/src/components/ConsoleOAuthFlow.tsx index b33b37b7d..8f4219ca3 100644 --- a/src/components/ConsoleOAuthFlow.tsx +++ b/src/components/ConsoleOAuthFlow.tsx @@ -11,9 +11,11 @@ import { getSSLErrorHint } from '@ant/model-provider'; import { sendNotification } from '../services/notifier.js'; import { completeChatGPTDeviceLogin, + removeChatGPTAuth, requestChatGPTDeviceCode, type ChatGPTDeviceCode, } from '../services/api/openai/chatgptAuth.js'; +import { clearOpenAIClientCache } from '../services/api/openai/client.js'; import { OAuthService } from '../services/oauth/index.js'; import { getOauthAccountInfo, validateForceLoginOrg } from '../utils/auth.js'; import { openBrowser } from '../utils/browser.js'; @@ -909,6 +911,11 @@ function OAuthStatusMessage({ process.env[k] = v; } } + // Drop any cached OpenAI client so the next request rebuilds it + // with the new env vars. Also clear ChatGPT auth file so a prior + // ChatGPT Subscription login can't leak into the OpenAI Compatible path. + clearOpenAIClientCache(); + void removeChatGPTAuth().catch(() => {}); setOAuthStatus({ state: 'success' }); void onDone(); } @@ -1043,6 +1050,11 @@ function OAuthStatusMessage({ throw new Error('Failed to save settings. Please try again.'); } for (const [k, v] of Object.entries(env)) process.env[k] = v; + // Drop any cached OpenAI client built from prior OpenAI Compatible + // env vars; the ChatGPT Subscription path bypasses the SDK client + // entirely (uses createChatGPTResponsesStream) but a stale cached + // client would still be picked up by sideQuery. + clearOpenAIClientCache(); setOAuthStatus({ state: 'success' }); void onDone(); } catch (err) { @@ -1468,6 +1480,10 @@ function OAuthStatusMessage({ process.env[k] = v; } } + // Drop any cached OpenAI client and ChatGPT auth so the new + // provider/credentials take effect on the next request. + clearOpenAIClientCache(); + void removeChatGPTAuth().catch(() => {}); logEvent('tengu_china_login_success', {}); setOAuthStatus({ state: 'success' }); void onDone();