fix: provider-aware error messages and skip Anthropic key approval for 3P

1. errors.ts: Add getCustomOffSwitchMessage() that returns a
   provider-neutral message for 3P users instead of the hardcoded
   "Opus is experiencing high load, please use /model to switch to
   Sonnet" which is misleading for OpenAI/Gemini/Ollama users.
   The original constant is preserved for backward-compatible string
   matching in error handlers.

2. Onboarding.tsx: Skip the "approve API key" step when a 3P provider
   is active. Previously, having ANTHROPIC_API_KEY in the environment
   (e.g., from a previous Anthropic setup) triggered an irrelevant
   Anthropic key approval UI even when using Gemini or OpenAI.
This commit is contained in:
Juan Camilo
2026-04-02 16:23:12 +02:00
parent 3353101e83
commit c66b859342
2 changed files with 8 additions and 2 deletions

View File

@@ -99,7 +99,7 @@ export function Onboarding({
// Add API key step if needed // Add API key step if needed
// On homespace, ANTHROPIC_API_KEY is preserved in process.env for child // On homespace, ANTHROPIC_API_KEY is preserved in process.env for child
// processes but ignored by Claude Code itself (see auth.ts). // processes but ignored by Claude Code itself (see auth.ts).
if (!process.env.ANTHROPIC_API_KEY || isRunningOnHomespace()) { if (!process.env.ANTHROPIC_API_KEY || isRunningOnHomespace() || !isAnthropicAuthEnabled()) {
return ''; return '';
} }
const customApiKeyTruncated = normalizeApiKeyForConfig(process.env.ANTHROPIC_API_KEY); const customApiKeyTruncated = normalizeApiKeyForConfig(process.env.ANTHROPIC_API_KEY);

View File

@@ -164,6 +164,12 @@ export const TOKEN_REVOKED_ERROR_MESSAGE =
export const CCR_AUTH_ERROR_MESSAGE = export const CCR_AUTH_ERROR_MESSAGE =
'Authentication error · This may be a temporary network issue, please try again' 'Authentication error · This may be a temporary network issue, please try again'
export const REPEATED_529_ERROR_MESSAGE = 'Repeated 529 Overloaded errors' export const REPEATED_529_ERROR_MESSAGE = 'Repeated 529 Overloaded errors'
export function getCustomOffSwitchMessage(): string {
return getAPIProvider() === 'firstParty'
? 'Opus is experiencing high load, please use /model to switch to Sonnet'
: 'The API is experiencing high load, please try again shortly or use /model to switch models'
}
// Backward-compatible constant for string matching in error handlers
export const CUSTOM_OFF_SWITCH_MESSAGE = export const CUSTOM_OFF_SWITCH_MESSAGE =
'Opus is experiencing high load, please use /model to switch to Sonnet' 'Opus is experiencing high load, please use /model to switch to Sonnet'
export const API_TIMEOUT_ERROR_MESSAGE = 'Request timed out' export const API_TIMEOUT_ERROR_MESSAGE = 'Request timed out'
@@ -457,7 +463,7 @@ export function getAssistantMessageFromError(
error.message.includes(CUSTOM_OFF_SWITCH_MESSAGE) error.message.includes(CUSTOM_OFF_SWITCH_MESSAGE)
) { ) {
return createAssistantAPIErrorMessage({ return createAssistantAPIErrorMessage({
content: CUSTOM_OFF_SWITCH_MESSAGE, content: getCustomOffSwitchMessage(),
error: 'rate_limit', error: 'rate_limit',
}) })
} }