Documentation
¶
Overview ¶
Package modelregistry provides a client for fetching per-provider model lists from a static JSON model registry server with in-memory caching.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetBaseURL ¶
func SetBaseURL(url string)
SetBaseURL sets the registry base URL (useful for testing).
func SetHTTPTimeout ¶
SetHTTPTimeout sets the HTTP client timeout (useful for testing).
func SetNegativeTTL ¶
SetNegativeTTL sets the negative cache TTL for 404 responses (useful for testing).
Types ¶
type ModelInfo ¶
type ModelInfo struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Provider string `json:"provider,omitempty"`
Size string `json:"size,omitempty"`
Cost float64 `json:"cost,omitempty"`
InputCost float64 `json:"input_cost,omitempty"`
OutputCost float64 `json:"output_cost,omitempty"`
CachedInputCost float64 `json:"cached_input_cost,omitempty"`
ContextLength int `json:"context_length,omitempty"`
Tags []string `json:"tags,omitempty"`
EligibleRoles []string `json:"eligible_roles,omitempty"`
RecommendedRoles []string `json:"recommended_roles,omitempty"`
Warnings []string `json:"warnings,omitempty"`
VisionProbe *bool `json:"vision_probe,omitempty"`
}
ModelInfo mirrors api.ModelInfo for registry JSON responses. NOTE: Intentionally duplicated to avoid import cycles between modelregistry and agent_api. Keep in sync with pkg/agent_api/models.go ModelInfo.
type RawModel ¶
type RawModel struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Provider string `json:"provider,omitempty"`
Size string `json:"size,omitempty"`
Cost float64 `json:"cost,omitempty"`
InputCost float64 `json:"input_cost,omitempty"`
OutputCost float64 `json:"output_cost,omitempty"`
CachedInputCost float64 `json:"cached_input_cost,omitempty"`
ContextLength int `json:"context_length,omitempty"`
Tags []string `json:"tags,omitempty"`
EligibleRoles []string `json:"eligible_roles,omitempty"`
RecommendedRoles []string `json:"recommended_roles,omitempty"`
Warnings []string `json:"warnings,omitempty"`
VisionProbe *bool `json:"vision_probe,omitempty"`
}
RawModel is a provider-agnostic model representation used for cache storage and inter-package transfer without creating import cycles.
func FetchModels ¶
FetchModels returns raw model data for a provider from the registry.
Return values:
- (models, nil): models from registry or cache
- (nil, nil): registry disabled, provider not found (404/negative cache), or temporary error triggers fallback
- (nil, err): hard error (invalid provider ID, network failure other than 404)
Caching behavior:
- Successful responses are cached for the configured TTL (default 5 minutes)
- 404 responses are cached in a negative cache for negativeTTL (default 30 seconds) to avoid repeated requests
- Singleflight deduplicates concurrent requests for the same provider
- Use ClearCache() to manually invalidate all cached entries