refactor(ui): remove redundant KimiModelSelector and unify model configuration

Remove KimiModelSelector component and useKimiModelSelector hook to
eliminate code duplication and unify model configuration across all
Claude-compatible providers.

**Problem Statement:**
Previously, we maintained two separate implementations for the same
functionality:
- KimiModelSelector: API-driven dropdown with 211 lines of code
- ClaudeFormFields: Simple text inputs for model configuration

After removing API fetching logic from KimiModelSelector, both components
became functionally identical (4 text inputs), violating DRY principle
and creating unnecessary maintenance burden.

**Changes:**

Backend (Rust):
- No changes (model normalization logic already in place)

Frontend (React):
- Delete KimiModelSelector.tsx (-211 lines)
- Delete useKimiModelSelector.ts (-142 lines)
- Update ClaudeFormFields.tsx: remove Kimi-specific props (-35 lines)
- Update ProviderForm.tsx: unify display logic (-31 lines)
- Clean up hooks/index.ts: remove useKimiModelSelector export (-1 line)

Configuration:
- Update Kimi preset: kimi-k2-turbo-preview → kimi-k2-0905-preview
  * Uses official September 2025 release
  * 256K context window (vs 128K in older version)

Internationalization:
- Remove kimiSelector.* i18n keys (15 keys × 2 languages = -36 lines)
- Remove providerForm.kimiApiKeyHint

**Unified Architecture:**

Before (complex branching):
  ProviderForm
  ├─ if Kimi → useKimiModelSelector → KimiModelSelector (4 inputs)
  └─ else → useModelState → ClaudeFormFields inline (4 inputs)

After (single path):
  ProviderForm
  └─ useModelState → ClaudeFormFields (4 inputs for all providers)

Display logic simplified:
  - Old: shouldShowModelSelector = category !== "official" && !shouldShowKimiSelector
  - New: shouldShowModelSelector = category !== "official"

**Impact:**

Code Quality:
- Remove 457 lines of redundant code (-98.5%)
- Eliminate dual-track maintenance
- Improve code consistency
- Pass TypeScript type checking with zero errors
- Zero remaining references to deleted code

User Experience:
- Consistent UI across all providers (including Kimi)
- Same model configuration workflow for everyone
- No functional changes from user perspective

Architecture:
- Single source of truth for model configuration
- Easier to extend for future providers
- Reduced bundle size (removed lucide-react icons dependency)

**Testing:**
-  TypeScript compilation passes
-  No dangling references
-  All model configuration fields functional
-  Display logic works for official/cn_official/aggregator categories

**Migration Notes:**
- Existing Kimi users: configurations automatically upgraded to new model name
- No manual intervention required
- Backend normalization ensures backward compatibility
This commit is contained in:
Jason
2025-11-02 20:57:16 +08:00
parent 4811aa2dcd
commit ebb7106102
8 changed files with 7 additions and 457 deletions

View File

@@ -28,7 +28,6 @@ import {
useCodexConfigState,
useApiKeyLink,
useCustomEndpoints,
useKimiModelSelector,
useTemplateValues,
useCommonConfigSnippet,
useCodexCommonConfig,
@@ -219,26 +218,6 @@ export function ProviderForm({
}));
}, [appId]);
// 使用 Kimi 模型选择器 hook
const {
shouldShow: shouldShowKimiSelector,
kimiAnthropicModel,
kimiDefaultHaikuModel,
kimiDefaultSonnetModel,
kimiDefaultOpusModel,
handleKimiModelChange,
} = useKimiModelSelector({
initialData,
settingsConfig: form.watch("settingsConfig"),
onConfigChange: (config) => form.setValue("settingsConfig", config),
selectedPresetId,
presetName:
selectedPresetId && selectedPresetId !== "custom"
? presetEntries.find((item) => item.id === selectedPresetId)?.preset
.name || ""
: "",
});
// 使用模板变量 hook (仅 Claude 模式)
const {
templateValues,
@@ -502,20 +481,12 @@ export function ProviderForm({
isEndpointModalOpen={isEndpointModalOpen}
onEndpointModalToggle={setIsEndpointModalOpen}
onCustomEndpointsChange={setDraftCustomEndpoints}
shouldShowKimiSelector={shouldShowKimiSelector}
shouldShowModelSelector={
category !== "official" && !shouldShowKimiSelector
}
shouldShowModelSelector={category !== "official"}
claudeModel={claudeModel}
defaultHaikuModel={defaultHaikuModel}
defaultSonnetModel={defaultSonnetModel}
defaultOpusModel={defaultOpusModel}
onModelChange={handleModelChange}
kimiAnthropicModel={kimiAnthropicModel}
kimiDefaultHaikuModel={kimiDefaultHaikuModel}
kimiDefaultSonnetModel={kimiDefaultSonnetModel}
kimiDefaultOpusModel={kimiDefaultOpusModel}
onKimiModelChange={handleKimiModelChange}
speedTestEndpoints={speedTestEndpoints}
/>
)}