Skip to content

fix: Model validation error when saving AI model configuration #245

@xqliu

Description

@xqliu

有个编辑 model 时候 block 的 bug fix #246

重现:我创建了一个 AI 模型,但是 model name 输错了(输成了 deepseek) 然后再次编辑这个 model 想要清空 model name 就报错了

Bug Description

When attempting to save a new AI model configuration (e.g., adding a DeepSeek model), the system displays an error message "模型不存在" (Model does not exist), even when the model has been selected from the dropdown list.

Root Cause

In web/src/components/AITradersPage.tsx line 281, the handleSaveModelConfig function validates the model by searching only in supportedModels:

const modelToUpdate = supportedModels?.find(m => m.id === modelId);
if (\!modelToUpdate) {
  alert(t('modelNotExist', language));
  return;
}

This validation fails when:

  1. User creates a new model configuration
  2. The model is not found in supportedModels (which comes from the default user's configuration)

Steps to Reproduce

  1. Navigate to AI Traders page
  2. Click "Add AI Model"
  3. Select a model from the dropdown (e.g., DeepSeek)
  4. Enter API Key
  5. Click Save
  6. Error: "模型不存在"

Proposed Solution

Update the validation logic to check both allModels (user's configured models) and supportedModels:

const existingModel = allModels?.find(m => m.id === modelId);
let updatedModels;

// Find model from either configured or supported lists
const modelToUpdate = existingModel || supportedModels?.find(m => m.id === modelId);
if (\!modelToUpdate) {
  alert(t('modelNotExist', language));
  return;
}

Related

Environment

  • Browser: Chrome/Firefox
  • Version: Latest dev branch

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions