Skip to content

Conversation

Wadehl
Copy link

@Wadehl Wadehl commented Jul 23, 2025

Summary

This PR introduces comprehensive custom model name support, allowing users to configure and use custom Claude models beyond the default Sonnet and Opus options. The feature includes both backend API management and frontend UI for model configuration.

Problem Solved

Previously, users were limited to only two predefined Claude models (Sonnet and Opus). This restriction prevented users from:

  • Using newer or specialized Claude model variants
  • Configuring custom model identifiers for their specific use cases
  • Leveraging environment-based model configuration

Approach Taken

Backend Changes (Rust/Tauri)

  • New Module: Added commands/models.rs with comprehensive model management APIs
    • get_available_models() - Retrieves all available models including custom and environment models
    • save_custom_models() - Persists custom model configurations
    • add_custom_model() - Adds individual custom models with validation
    • remove_custom_model() - Removes custom models by name
  • Enhanced Storage: Extended commands/storage.rs with settings management functions
    • get_settings() - Loads application settings from JSON file
    • save_settings() - Persists settings with proper error handling
  • Environment Integration: Automatic detection of ANTHROPIC_MODEL environment variable

Frontend Changes (React/TypeScript)

  • Type System Update: Changed model type from "sonnet" | "opus" to string for flexibility
  • Dynamic Model Loading: Enhanced FloatingPromptInput component to dynamically load and display models
  • Grouped Model Selection: Organized models into logical groups (Custom, Environment, Default)
  • Settings UI: Added new "Models" tab in settings with full CRUD operations for custom models
  • Visual Improvements: Added appropriate icons and descriptions for different model types

Key Features

  1. Custom Model Configuration: Users can add models with custom names, identifiers, and descriptions
  2. Environment Variable Support: Automatic detection and display of ANTHROPIC_MODEL from environment
  3. Grouped Model Selection: Clear organization of models by source (custom, environment, default)
  4. Persistent Storage: All custom model configurations are saved locally
  5. Input Validation: Comprehensive validation for model names and identifiers
  6. Backward Compatibility: Existing functionality remains unchanged
CleanShot 2025-07-23 at 15 26 08@2x image

Technical Implementation Details

  • Data Structure: CustomModel struct with name, identifier, and optional description
  • Storage Format: JSON-based settings file in application data directory
  • Error Handling: Comprehensive error handling with user-friendly messages
  • Security: Input validation and sanitization for all model configurations

Testing

  • Manual testing of all CRUD operations for custom models
  • Environment variable detection and display
  • Model selection and usage in chat sessions
  • Settings persistence across application restarts
  • Backward compatibility with existing functionality

Dependencies

No new external dependencies were added. The implementation uses existing libraries and frameworks already present in the codebase.

Potential Side Effects

  • Minimal Impact: Changes are additive and maintain backward compatibility
  • Settings File: Creates new settings.json file in app data directory if not exists
  • Type Changes: Model type broadened from union type to string (breaking change for TypeScript, but functionally compatible)

Wadehl and others added 8 commits July 23, 2025 12:52
- Add custom model storage and management system
- Support reading ANTHROPIC_MODEL from Claude Settings environment variables
- Implement grouped model dropdown with Custom/Environment/Default sections
- Add Models tab in Settings UI for managing custom models
- Update model parameter types from literal union to string
- Fix queuedPrompts state and ref type definitions
- Update PromptQueue component to handle arbitrary model names
- Remove unused type imports in FloatingPromptInput
- Remove explanatory text about raw JSON display
- Restore original function positioning in agents.rs and claude.rs
- Remove extra blank lines that were added during development
- Keep only essential changes for custom model support functionality
- Restore original storage_reset_database function with proper error handling
- Keep only essential get_settings and save_settings functions for custom model support
- Remove simplified database reset logic that was unrelated to model management
- Add validation method to CustomModel struct for input validation
- Extract load_custom_models helper function to eliminate code duplication
- Improve error handling in save_custom_models with explicit error propagation
- Use find() instead of any() for better error messages with specific model names
- Clean up unused imports and fix formatting issues
- All changes maintain backward compatibility and improve code maintainability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
refactor: optimize Rust models.rs implementation
* feat: add Official Models section with Anthropic API integration

- Add Official Models UI section in Settings → Models tab with collapsible functionality
- Implement Anthropic Models List API integration in Rust backend
- Add get_official_models Tauri command with proper error handling
- Create unified environment variable access function (get_env_var)
- Add frontend API call for fetching official models
- Include model selection and add-to-custom functionality
- Maintain visual consistency with existing Custom Models section
- Return empty list on API failure instead of hardcoded fallbacks
- Optimize code by removing unused structures and duplicate logic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* chore: remove zustand dependency from lockfile

---------

Co-authored-by: 刘俊辉 <[email protected]>
Co-authored-by: Claude <[email protected]>
Wadehl

This comment was marked as resolved.

Wadehl and others added 5 commits July 30, 2025 11:01
Resolved conflicts:
- Added both models and proxy modules to src-tauri/src/commands/mod.rs
- Added both model management and proxy settings commands to src-tauri/src/main.rs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…lity

- Add validation tests for CustomModel struct
- Add serialization/deserialization tests
- Add Anthropic API response parsing tests
- Add database operations tests
- Add edge case testing (unicode, long strings, whitespace)
- Test coverage includes model config, validation, and data persistence
- All 8 tests pass without warnings
Incorporates latest changes including analytics infrastructure,
CI/CD workflows, and build improvements while preserving
custom model functionality.
…upport

# Conflicts:
#	src/components/FloatingPromptInput.tsx
#	src/components/Settings.tsx
#	src/lib/api.ts
- Enhanced AgentExecution with custom model selection
- Updated CreateAgent form to support custom model names
- Modified AgentRunView and AgentRunOutputViewer for custom models
- Added custom model configuration in AgentsModal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants