Skip to content

Conversation

@kiwina
Copy link
Contributor

@kiwina kiwina commented Jun 5, 2025

Related GitHub Issue

Closes: #4374

Closes: #

Description

This PR significantly enhances the Vertex AI provider implementation with comprehensive refactoring and test improvements:

🔑 Vertex API Key Support

  • Added vertexApiKey field to ProviderSettings for simplified authentication alongside existing JSON credentials and key file options
  • Updated Vertex provider UI component with API key input field
  • Added complete i18n support for vertex API key labels and placeholders across all locales

🏗️ Provider Architecture Refactoring

  • Complete Independence: Refactored VertexHandler to be fully independent from GeminiHandler
    • Removed inheritance dependency and extracted all vertex-specific logic
    • Each provider now has completely separate authentication, model selection, and API logic
    • Eliminated shared state and coupling between providers
  • Shared Cost Calculation: Extracted cost calculation logic into src/utils/calculateCostGenai.ts
    • Both providers now use the same cost calculation utility for consistency
    • Comprehensive test coverage for the shared utility with 100% branch coverage

🧪 Test Suite Enhancements

  • Test Parity: Brought both provider test suites to the same comprehensive level
    • GeminiHandler tests: Enhanced from basic coverage to 26 comprehensive tests
    • VertexHandler tests: Already comprehensive with 26 tests
    • Both test suites now cover identical scenarios and edge cases
  • Test Coverage Areas:
    • Constructor initialization with various authentication methods
    • Model selection and reasoning mode (:thinking suffix) handling
    • Message creation with streaming and usage metadata
    • Prompt completion with error handling
    • Token counting with fallback mechanisms
    • Cost calculation integration
    • Error scenarios and edge cases

🔧 Technical Improvements

  • Enhanced Debug Logging: Added comprehensive debug logging for Vertex model selection and API flow
  • Correct Model Selection: Fixed vertex tests to use correct default model (claude-sonnet-4@20250514)
  • Proper Fallback Logic: Ensured robust model selection and fallback mechanisms for both providers
  • Type Safety: Improved type definitions and model ID handling

📊 Test Results

All tests pass with comprehensive coverage:

  • GeminiHandler: 26/26 tests passing
  • VertexHandler: 26/26 tests passing
  • calculateCostGenai: 13/13 tests passing
  • Total: 65/65 tests passing ✅

Test Procedure

Unit Tests

# Run all provider tests
npm test -- --testPathPattern="providers"

# Run specific provider tests
npm test -- src/api/providers/__tests__/gemini.test.ts
npm test -- src/api/providers/__tests__/vertex.test.ts
npm test -- src/utils/__tests__/calculateCostGenai.test.ts

Manual Testing

  1. Vertex API Key Configuration:

    • Open VS Code settings → Roo Code → Vertex AI
    • Verify API key input field is present with proper i18n labels
    • Test authentication with API key vs JSON credentials
  2. Provider Independence:

    • Configure different models for Gemini and Vertex
    • Verify each provider uses only its own model set and authentication
    • Test that changes to one provider don't affect the other
  3. Cost Calculation:

    • Verify both providers report consistent cost calculations
    • Test with different model types and token counts

Type of Change

  • New Feature: Vertex API key support
  • 💥 Breaking Change: VertexHandler no longer inherits from GeminiHandler
  • ♻️ Refactor: Complete provider architecture refactoring
  • 🧪 Testing: Comprehensive test suite improvements

Pre-Submission Checklist

  • Scope: Changes are focused on Vertex provider enhancements and provider architecture
  • Self-Review: Thorough self-review completed
  • Code Quality:
    • Code adheres to project style guidelines
    • No linting errors or warnings
    • All debug code removed (except intentional debug logging)
  • Testing:
    • Comprehensive test suites added/updated (65 total tests)
    • All tests pass locally
    • Application builds successfully
  • Branch Hygiene: Branch is up-to-date with main
  • Documentation Impact: UI changes are self-documenting with i18n
  • Changeset: Will be created if needed for user-facing changes

Screenshots / Videos

The Vertex provider UI now includes an API key input field with proper validation and i18n support, matching the style of other provider configurations.

Breaking Changes

⚠️ Important: This PR includes breaking changes:

  • VertexHandler no longer inherits from GeminiHandler
  • Each provider now has completely separate model sets and authentication logic
  • If you were relying on shared behavior between providers, you'll need to update your code

However, the public API remains the same, so existing configurations and usage should continue to work.

Additional Notes

This refactoring significantly improves the maintainability and testability of the provider system:

  1. Better Separation of Concerns: Each provider is now fully independent
  2. Comprehensive Testing: Both providers have identical test coverage
  3. Shared Utilities: Common logic is properly extracted and tested
  4. Enhanced Authentication: Vertex now supports multiple authentication methods

The test suite improvements ensure that both providers maintain feature parity and consistent behavior while being completely independent implementations.

@kiwina kiwina requested review from cte and mrubens as code owners June 5, 2025 09:19
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 5, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 5, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 5, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kiwina, thank you for your contribution!

I left some suggestions in the code comments above. Let me know if you have any questions!

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Jun 5, 2025
@daniel-lxs daniel-lxs added PR - Draft / In Progress and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 5, 2025
kiwina and others added 3 commits June 6, 2025 12:20
- Add vertexApiKey field to ProviderSettings for simplified authentication
- Refactor VertexHandler to be fully independent from GeminiHandler
  - Remove inheritance dependency and vertex-specific logic from GeminiHandler
  - Implement standalone VertexHandler with vertex-only authentication methods
  - Add comprehensive debug logging for model selection and API flow
- Update vertex provider UI to include API key input field
- Add i18n support for vertex API key label and placeholder
- Fix vertex tests to use correct default model (claude-sonnet-4@20250514)
- Ensure proper model selection and fallback logic for both providers

Breaking changes:
- VertexHandler no longer inherits from GeminiHandler
- Each provider now has completely separate model sets and authentication

Closes: #TBD
- Added googleCloudApiKey translations for 16 non-English locales
- Translations include proper localized terms for 'Vertex AI API Key'
- All translation checks now pass successfully
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@kiwina kiwina requested a review from jr as a code owner June 6, 2025 04:29
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 6, 2025
@daniel-lxs daniel-lxs moved this from PR [Draft / In Progress] to PR [Changes Requested] in Roo Code Roadmap Jun 7, 2025
@daniel-lxs
Copy link
Member

Hey @kiwina, thank you for updating your PR, it seems like a test is failing, can you take a look before I review your changes?

@hannesrudolph
Copy link
Collaborator

@kiwina are you going to be landing the plane on this or should we take it off your plate?

@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Sep 22, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR - Changes Requested size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

feat: Refactor Gemini and Vertex handlers to be fully independent

3 participants