Expand description
OpenCode API catalog module.
This module handles fetching, caching, and querying the OpenCode model catalog from https://models.dev/api.json. The catalog contains available providers and models that OpenCode supports, enabling dynamic agent configuration.
§Module Structure
- [
types] - API catalog data structures - [
cache] - File-based caching with TTL - [
fetch] - HTTP fetching logic
§Dependency Injection
The CatalogLoader trait enables dependency injection for testing.
Production code uses RealCatalogLoader which fetches from the network,
while tests can provide mock implementations.
Structs§
- ApiCatalog
- OpenCode API catalog containing all available providers and models.
- Model
- A model available from a provider.
- Provider
- A provider supported by OpenCode.
- Real
Catalog Loader - Production implementation of
CatalogLoaderthat fetches from the network.
Enums§
- Cache
Error - Errors that can occur when loading the API catalog.
Constants§
- API_URL
- OpenCode API endpoint for model catalog.
- CACHE_
TTL_ ENV_ VAR - Environment variable for customizing cache TTL.
- DEFAULT_
CACHE_ TTL_ SECONDS - Default cache TTL in seconds (24 hours).
Traits§
- Catalog
Loader - Trait for loading the OpenCode API catalog.
Functions§
- load_
api_ catalog - Load the API catalog from cache or fetch if expired.