feat(proxy): flag managed-OAuth providers as routing-required

Managed-OAuth providers (github_copilot / codex_oauth / xai_oauth) need
proxy takeover to inject credentials, but the "needs routing" badge and
the switch-time warning only keyed off apiFormat — missing OAuth providers
whose upstream format is native (e.g. the new Codex xAI Grok OAuth preset
on openai_responses).

- Add isOAuthProviderType / OAUTH_PROVIDER_TYPES as the SSOT for OAuth types
- Extract providerNeedsRouting() as the authoritative predicate: managed
  OAuth always needs routing (the backend rejects these accounts' direct
  connection) regardless of apiFormat or Claude Desktop mode
- ProviderCard badges (claude / codex / claude-desktop) and the switch
  warning consume the shared predicate instead of raw apiFormat
- Gate the warning on per-app routing readiness: claude-desktop uses
  isProxyRunning (backend takeover status has no such field), other apps
  use isProxyTakeover — fixes false warnings on Desktop and missing
  warnings when the proxy runs but the app isn't taken over
- Force proxy mode for all managed-OAuth providers in the Claude Desktop
  form (lock the mode toggle), not only xai_oauth
- Add unit tests for providerNeedsRouting, the switch routing gate, and
  Desktop OAuth preset enforcement
- i18n(zh/en/ja/zh-TW): add notifications.proxyReasonManagedOAuth
This commit is contained in:
Jason
2026-07-21 10:04:55 +08:00
parent dbb5bd1537
commit 6428e993a3
12 changed files with 465 additions and 49 deletions
+16
View File
@@ -5,6 +5,22 @@ export const PROVIDER_TYPES = {
XAI_OAUTH: "xai_oauth",
} as const;
// 托管 OAuth 供应商类型:真实凭据由本地代理按请求注入,因此无论上游是否
// 需要格式转换,都必须开启路由接管才能通过认证。新增此类预设时只需把
// providerType 加进本数组,needsRouting 判定即自动覆盖,无需逐个特判。
export const OAUTH_PROVIDER_TYPES: readonly string[] = [
PROVIDER_TYPES.GITHUB_COPILOT,
PROVIDER_TYPES.CODEX_OAUTH,
PROVIDER_TYPES.XAI_OAUTH,
];
/** 判断某 providerType 是否为托管 OAuth(凭据由代理注入、必须开启路由)。 */
export function isOAuthProviderType(
providerType: string | null | undefined,
): boolean {
return providerType != null && OAUTH_PROVIDER_TYPES.includes(providerType);
}
// 用量脚本模板类型常量
export const TEMPLATE_TYPES = {
CUSTOM: "custom",