Skip to content

Assistant: Refactor Model Providers#11089

Merged
samclark2015 merged 19 commits intomainfrom
fix/assistant-model-refactor
Jan 12, 2026
Merged

Assistant: Refactor Model Providers#11089
samclark2015 merged 19 commits intomainfrom
fix/assistant-model-refactor

Conversation

@samclark2015
Copy link
Copy Markdown
Contributor

@samclark2015 samclark2015 commented Dec 12, 2025

Addresses #10532.

Summary

This PR refactors the Assistant extension's model provider architecture to improve code organization, maintainability, and developer experience. The changes address multiple items from the cleanup checklist in #10532.

Major architectural changes:

  • Separated provider classes into individual files: Broke apart the monolithic 1,749-line models.ts file into a clean directory structure under providers/
  • Created robust base classes: Introduced ModelProvider abstract base class and VercelModelProvider for shared functionality across providers
  • Improved error handling: New modelProviderErrors.ts with structured error classes for better debugging
  • Centralized logging: Added modelProviderLogger.ts with consistent logging patterns across all providers
  • Better type organization: Extracted shared types into modelProviderTypes.ts

Naming consistency improvements:

  • Renamed getLanguageModels()getModelProviders() for accurate terminology
  • Renamed provider property → providerId for consistency across model providers
  • Renamed name property → displayName to better reflect its purpose
  • Updated all related types, tests, and comments

Provider organization:

providers/
├── base/
│   ├── modelProvider.ts              # Abstract base class
│   ├── vercelModelProvider.ts        # Vercel AI SDK base class
│   ├── modelProviderErrors.ts        # Error handling
│   ├── modelProviderLogger.ts        # Logging utilities
│   └── modelProviderTypes.ts         # Shared types
├── anthropic/                         # Anthropic providers
├── aws/                               # AWS Bedrock
├── azure/                             # Azure OpenAI
├── google/                            # Google AI & Vertex
├── mistral/                           # Mistral AI
├── ollama/                            # Ollama
├── openai/                            # OpenAI & compatible providers
├── openrouter/                        # OpenRouter
├── posit/                             # Posit Connect
├── snowflake/                         # Snowflake Cortex
├── test/                              # Test providers (echo, error)
└── index.ts                           # Central export hub

What's been accomplished from #10532:

  • ✅ Separate provider classes in models.ts into separate files
  • ✅ Use more accurate language (LanguageModel → ModelProvider)
  • ✅ Make AILanguageModel abstract class more robust
    • ✅ Make providerName abstract (now providerId)
    • ✅ Reuse more code / reduce boilerplate
    • ✅ Support custom SDKs beyond Vercel AI SDK
  • ✅ Consistent logging across all providers
  • ✅ Add integration tests for each supported provider

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

@:assistant

This is a refactoring PR with no user-facing changes. All Assistant functionality should work exactly as before, just with better code organization.

Verification steps:

  1. Launch Positron
  2. Open the Assistant pane
  3. Configure and test multiple model providers:
    • OpenAI: Standard OpenAI models
    • Anthropic: Claude models (both direct and via Vercel)
    • Azure: Azure OpenAI deployment
    • Ollama: Local models
    • Google: Gemini models
    • Snowflake: Cortex LLM
  4. For each provider:
    • Verify models load correctly in the model selector
    • Start a conversation and verify responses work
    • Check that provider names display correctly in the UI
  5. Switch between different models and providers
  6. Verify error messages are clear if credentials are missing/invalid

Example test conversation:

# In console
import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})

Then ask the Assistant: "What is in the df variable?"

All provider configurations should continue to work without any behavioral changes, regressions, or errors.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 12, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:assistant

readme  valid tags

@samclark2015 samclark2015 requested a review from Copilot January 7, 2026 17:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the model provider architecture in the Positron Assistant extension to improve code organization and maintainability. The changes move from a monolithic models.ts file to a structured provider-based architecture with better separation of concerns.

Key changes:

  • Introduced an abstract ModelProvider base class that all providers extend
  • Moved provider implementations to individual files under src/providers/
  • Renamed classes from *LanguageModel to *ModelProvider for consistency
  • Standardized provider lifecycle methods and error handling

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/tokens.ts Updated imports and references to use new AnthropicModelProvider
src/test/snowflake.test.ts Updated import path for Snowflake authentication utilities
src/test/openai.test.ts Renamed OpenAILanguageModel to OpenAIModelProvider and updated imports
src/test/anthropic.test.ts Renamed AnthropicLanguageModel to AnthropicModelProvider and added mock model info
src/pwb.ts Changed autoconfigure result property from signedIn to configured
src/providers/test/errorProvider.ts New test provider that always throws errors for testing error handling
src/providers/test/echoProvider.ts New test provider that echoes back user input for testing
src/providers/snowflake/snowflakeProvider.ts New Snowflake Cortex provider with credential refresh support
src/providers/snowflake/snowflakeAuth.ts Updated import path for extension utilities
src/providers/posit/positProvider.ts Moved and refactored Posit AI provider with OAuth support
src/providers/openrouter/openrouterProvider.ts New OpenRouter provider implementation
src/providers/openai/openaiProvider.ts Refactored OpenAI provider with comprehensive documentation
src/providers/openai/openaiCompatibleProvider.ts New provider for OpenAI-compatible endpoints
src/providers/ollama/ollamaProvider.ts New Ollama provider for local model execution
src/providers/mistral/mistralProvider.ts New Mistral AI provider implementation
src/providers/index.ts Central export file for all providers with factory functions
src/providers/google/vertexProvider.ts New Google Vertex AI provider
src/providers/google/googleProvider.ts New Google Gemini provider implementation
src/providers/base/vercelModelProvider.ts Base class for Vercel AI SDK-based providers
src/providers/base/modelProviderTypes.ts Type definitions for model provider interfaces
src/providers/base/modelProviderLogger.ts Standardized logging utility for providers
src/providers/base/modelProviderErrors.ts Error type hierarchy for provider operations
src/providers/base/modelProvider.ts Abstract base class defining provider interface
src/providers/azure/azureProvider.ts New Azure OpenAI Service provider
src/providers/aws/awsBedrockProvider.ts AWS Bedrock provider with SSO support
src/providers/anthropic/anthropicVercelProvider.ts Anthropic provider using Vercel AI SDK
src/providers/anthropic/anthropicProvider.ts Anthropic provider using native SDK with detailed refactoring
src/participants.ts Updated comment reference from EchoLanguageModel to EchoModelProvider
src/models.ts Deleted monolithic file - functionality distributed to provider modules
src/extension.ts Updated imports and references to use new provider structure
src/diagnostics.ts Updated import for getLanguageModels function
src/copilot.ts Changed autoconfigure property from signedIn to configured
src/constants.ts Moved ModelCapabilities interface to modelProviderTypes.ts
src/config.ts Updated imports and autoconfigure result handling

Comment thread extensions/positron-assistant/src/providers/anthropic/anthropicProvider.ts Outdated
Comment thread extensions/positron-assistant/src/providers/base/modelProvider.ts Outdated
Comment thread extensions/positron-assistant/src/providers/base/modelProvider.ts Outdated
Comment thread extensions/positron-assistant/src/providers/base/modelProvider.ts
Comment thread extensions/positron-assistant/src/providers/base/vercelModelProvider.ts Outdated
Comment thread extensions/positron-assistant/src/providers/anthropic/anthropicProvider.ts Outdated
Comment thread extensions/positron-assistant/src/providers/ollama/ollamaProvider.ts Outdated
Comment thread extensions/positron-assistant/src/providers/index.ts Outdated
Comment thread extensions/positron-assistant/src/providers/base/modelProvider.ts Outdated
Comment thread extensions/positron-assistant/src/providers/base/modelProvider.ts
@samclark2015 samclark2015 marked this pull request as ready for review January 8, 2026 22:35
…Provider to return undefined when no models are available, improving clarity and consistency.
…ovider registration in index.ts for improved integration.
…r language model chat responses, enhancing flexibility for Anthropic and Bedrock models.
Copy link
Copy Markdown
Contributor

@melissa-barca melissa-barca left a comment

Choose a reason for hiding this comment

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

I built the branch and did some light testing of different providers and everything is looking good. Let's get this merged! 💃

@samclark2015 samclark2015 merged commit e8838c3 into main Jan 12, 2026
15 checks passed
@samclark2015 samclark2015 deleted the fix/assistant-model-refactor branch January 12, 2026 16:22
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants