Skip to content

refacto(admin): Remove ModelProviderGateway - #972

Open
bakr-a wants to merge 18 commits into
mainfrom
921-remove-modelprovidergateway
Open

refacto(admin): Remove ModelProviderGateway#972
bakr-a wants to merge 18 commits into
mainfrom
921-remove-modelprovidergateway

Conversation

@bakr-a

@bakr-a bakr-a commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Overview

Resolves #921.

Removes the ModelProviderGateway abstraction and replaces it with aProviderCapabilitiesRepository that lives in the provider domain package.

What was done:

  • Introduced ProviderCapabilitiesRepository under api/domain/provider, exposing get_provider_capabilities
  • Moved the ProviderCapabilities dataclass into provider/entities.py.
  • Deleted ModelProviderGateway and the old ProviderGateway domain class, and dropped them from wiring / domain exports.
  • Injected the new repository into CreateProviderUseCase and BootstrapModelsUseCase
  • Fixed ModelNotFoundError handling in CreateProviderUseCase: it now maps to a 404 at the endpoint, matching BootstrapModelsUseCase
  • Migrated the gateway's unit and integration tests to the new repository.

Definition of Done:

  • ModelProviderGateway / ProviderGateway fully removed from the codebase
  • Capability fetching provided by an injected ProviderCapabilitiesRepository
  • CreateProviderUseCase handles ModelNotFoundError (404) like bootstrap
  • No regression on model bootstrap, admin provider creation, rollback on provider errors, and max_context_length / vector_size consistency validation across providers on the same router
  • Existing gateway test coverage preserved (migrated, not dropped)

Breaking changes:

  • No breaking changes
  • This PR contains breaking changes (explain below)

Check lists

Review checklist

  • Updated or added documentation: N/A, internal refactor with no
    user-facing or API documentation impact
  • Updated or added unit tests
  • Updated or added integration tests
  • No debug logs or commented-out code left
  • No secrets or environment variables committed in clear text
  • Code is linted and formatted using the project pre-commit hooks

If api/sql/models.py has been modified, please confirm that the following steps have been completed:

  • Alembic migration has been generated — N/A, models.py not modified
  • Alembic migration upgrade has been tested locally — N/A
  • Alembic migration downgrade has been tested locally — N/A

Deployment checklist

  • Alembic migration has been generated — N/A
  • Configuration file has been modified — N/A
  • Environment variables have been modified — N/A

No new environment variables and no special deployment steps required.

Bakr Annour and others added 14 commits July 22, 2026 18:36
Extract provider capability-fetching (formerly ModelProviderGateway)
into a shared module-level function in the use-case layer.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ilities

Replace the removed provider_gateway dependency in CreateProviderUseCase
and BootstrapModelsUseCase with calls to the shared
get_provider_capabilities helper, injecting provider_client and
provider_adapter_builder instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Remove the deleted ModelProviderGateway/ProviderGateway references:
inject provider_client and provider_adapter_builder into the
create-provider factory, and drop ProviderGateway from the provider
domain package exports.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Relocate the ProviderCapabilities value object from the now-empty
_providergateway module into entities.py (as a BaseModel, matching the
other domain types) and delete _providergateway.py. Update importers to
api.domain.provider.entities.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the get_provider_capabilities use-case helper into a
ProviderCapabilitiesRepository domain class and inject it where it's
needed.

- add ProviderCapabilitiesRepository under api/domain/provider, exposing
  get_provider_capabilities plus its context-length / vector-size helpers
- wire it as a dependency and delegate from CreateProviderUseCase and
  BootstrapModelsUseCase, dropping their direct ProviderClient /
  ProviderAdapterBuilder dependencies
- build it explicitly in the bootstrap_models lifespan hook
- remove the now-unused api/use_cases/provider package

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- migrate the ModelProviderGateway integration test to
  ProviderCapabilitiesRepository under tests/integration/http
- import ProviderClient / adapter classes from their submodules to break
  the circular import introduced by moving the repository into the
  provider package

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ository

- move the orphaned ModelProviderGateway unit test to
  tests/unit/domain/provider, renaming symbols to
  ProviderCapabilitiesRepository
- make _get_max_context_length / _get_vector_size instance methods that
  read self.provider_client, dropping the redundant argument threading

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bakr-a bakr-a self-assigned this Jul 23, 2026
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.

Remove ModelProviderGateway

1 participant