From 1b22a8957257ef1997d754f85359423f4bf87e68 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Fri, 10 Apr 2026 10:27:50 +0800 Subject: [PATCH] Align Thinking fallback with main-model-only Claude mappings The Claude provider form reopened with an empty Thinking model after users saved only a main model. This updates model-state hydration to mirror the existing Haiku-style fallback semantics: read ANTHROPIC_REASONING_MODEL when present, otherwise display ANTHROPIC_MODEL, without writing a synthetic reasoning field back into config. Constraint: Existing Haiku, Sonnet, and Opus selectors already rely on read-time fallback behavior Rejected: Persist ANTHROPIC_REASONING_MODEL from ANTHROPIC_MODEL automatically | would diverge from Haiku behavior and silently rewrite saved config Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep Thinking fallback read-only unless all model-mapping fields are intentionally migrated to write-through semantics Tested: pnpm typecheck Tested: pnpm test:unit (1 unrelated pre-existing failure in tests/components/UnifiedSkillsPanel.test.tsx mock setup) Not-tested: Manual add-provider reopen flow in the desktop UI --- .../providers/forms/hooks/useModelState.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/providers/forms/hooks/useModelState.ts b/src/components/providers/forms/hooks/useModelState.ts index 46a1c6d7e..01278c4b5 100644 --- a/src/components/providers/forms/hooks/useModelState.ts +++ b/src/components/providers/forms/hooks/useModelState.ts @@ -14,10 +14,11 @@ function parseModelsFromConfig(settingsConfig: string) { const env = cfg?.env || {}; const model = typeof env.ANTHROPIC_MODEL === "string" ? env.ANTHROPIC_MODEL : ""; - const reasoning = + const explicitReasoning = typeof env.ANTHROPIC_REASONING_MODEL === "string" ? env.ANTHROPIC_REASONING_MODEL : ""; + const reasoning = explicitReasoning || model; const small = typeof env.ANTHROPIC_SMALL_FAST_MODEL === "string" ? env.ANTHROPIC_SMALL_FAST_MODEL @@ -92,10 +93,11 @@ export function useModelState({ const env = cfg?.env || {}; const model = typeof env.ANTHROPIC_MODEL === "string" ? env.ANTHROPIC_MODEL : ""; - const reasoning = + const explicitReasoning = typeof env.ANTHROPIC_REASONING_MODEL === "string" ? env.ANTHROPIC_REASONING_MODEL : ""; + const reasoning = explicitReasoning || model; const small = typeof env.ANTHROPIC_SMALL_FAST_MODEL === "string" ? env.ANTHROPIC_SMALL_FAST_MODEL @@ -148,16 +150,17 @@ export function useModelState({ ? JSON.parse(settingsConfig) : { env: {} }; if (!currentConfig.env) currentConfig.env = {}; + const env = currentConfig.env as Record; // 新键仅写入;旧键不再写入 const trimmed = value.trim(); if (trimmed) { - currentConfig.env[field] = trimmed; + env[field] = trimmed; } else { - delete currentConfig.env[field]; + delete env[field]; } // 删除旧键 - delete currentConfig.env["ANTHROPIC_SMALL_FAST_MODEL"]; + delete env["ANTHROPIC_SMALL_FAST_MODEL"]; onConfigChange(JSON.stringify(currentConfig, null, 2)); } catch (err) {