Documentation
¶
Overview ¶
Package modelregistry Model registry runtime and cache for backend model inventory.
Package modelregistry provides core-owned lookup over backend-exposed models.
Index ¶
- Constants
- Variables
- func MarshalOpenAIModelsListJSON(models []BackendModel) ([]byte, error)
- func WithBoundView(ctx context.Context, v BoundView) context.Context
- type BackendDiscovery
- type BackendInventory
- type BackendModel
- type BoundView
- func (v BoundView) Active() bool
- func (v BoundView) All() []BackendModel
- func (v BoundView) Diagnostics() Diagnostics
- func (v BoundView) Generation() string
- func (v BoundView) Lookup(canonicalID string) ([]BackendModel, bool)
- func (v BoundView) ModelsJSON() (body []byte, generation string, ok bool)
- func (v BoundView) PublicationGeneration() string
- func (v BoundView) RefreshedAt() time.Time
- func (v BoundView) ResolveModelBinding(backendID, model string) routing.ModelBinding
- func (v BoundView) ResolveNative(backendID, model string) (native string, ok bool)
- type BuildResult
- type Cache
- type Diagnostics
- type OpenAIModel
- type OpenAIModelList
- type RefreshFailureCategory
- type Registry
- type Runtime
- func (r *Runtime) ActiveRegistry() *Registry
- func (r *Runtime) All() []BackendModel
- func (r *Runtime) BoundView() BoundView
- func (r *Runtime) Diagnostics() Diagnostics
- func (r *Runtime) Discoveries() []BackendDiscovery
- func (r *Runtime) LastCacheFailure() RefreshFailureCategory
- func (r *Runtime) LastRefreshFailure() RefreshFailureCategory
- func (r *Runtime) Lookup(canonicalID string) ([]BackendModel, bool)
- func (r *Runtime) ModelsJSON() (body []byte, generation string, ok bool)
- func (r *Runtime) RunRefresh(ctx context.Context)
- func (r *Runtime) Start(ctx context.Context) error
- type RuntimeConfig
- type Snapshot
Constants ¶
const ( CapabilitySourceStaticConfig = "static_config" CapabilitySourceRemoteDiscovery = "remote_discovery" CapabilitySourceBuiltin = "builtin" )
const MaxInventoryModelSample = 3
MaxInventoryModelSample is the maximum number of model rows exposed in operator diagnostics.
Variables ¶
var ( ErrNilContext = errors.New("modelregistry: nil context") ErrMissingProvider = errors.New("modelregistry: missing inventory provider") ErrMissingBackendPrefix = errors.New("modelregistry: missing backend prefix") ErrDuplicateBackendPrefix = errors.New("modelregistry: duplicate backend prefix") ErrInvalidModel = errors.New("modelregistry: invalid model") ErrInvalidCanonicalID = errors.New("modelregistry: invalid canonical model id") ErrNoUsableInventory = errors.New("modelregistry: no usable inventory") // ErrConflictingMapping is returned when two rows claim the same // (backendID, canonicalID) with different NativeID values. ErrConflictingMapping = errors.New("modelregistry: conflicting exact model mapping") )
Functions ¶
func MarshalOpenAIModelsListJSON ¶
func MarshalOpenAIModelsListJSON(models []BackendModel) ([]byte, error)
MarshalOpenAIModelsListJSON returns the JSON body for GET /v1/models.
Types ¶
type BackendDiscovery ¶
type BackendDiscovery struct {
BackendID string
Kind string
Status modelinventory.DiscoveryStatus
Source modelinventory.Source
ModelCount int
ErrorCode string
}
BackendDiscovery is per-backend inventory discovery state for diagnostics.
type BackendInventory ¶
type BackendModel ¶
type BoundView ¶
type BoundView struct {
// contains filtered or unexported fields
}
BoundView is an immutable, request-scoped publication of the model registry. It freezes registry lookups, models JSON, generation, and publication-tied discovery metadata so a later Runtime refresh cannot alter an in-flight request.
BoundView never exposes the mutable Runtime, its mutexes, or atomics. Live operational last-refresh/cache failure categories are captured at bind time for diagnostics but are not part of the immutable publication object.
func BoundViewFromContext ¶
BoundViewFromContext returns the request-bound registry view when present.
func EmptyBoundView ¶
func EmptyBoundView() BoundView
EmptyBoundView returns a safe empty view (nil/unavailable runtime).
func (BoundView) All ¶
func (v BoundView) All() []BackendModel
All returns a defensive clone of all frozen registry rows.
func (BoundView) Diagnostics ¶
func (v BoundView) Diagnostics() Diagnostics
Diagnostics returns coherent publication diagnostics frozen at bind time. LastRefreshErrorCategory / LastCacheErrorCategory reflect live operational state captured at bind and are not publication identity fields.
func (BoundView) Generation ¶
Generation returns the frozen model-registry generation identity.
func (BoundView) Lookup ¶
func (v BoundView) Lookup(canonicalID string) ([]BackendModel, bool)
Lookup returns defensive clones of models for canonicalID from the frozen registry.
func (BoundView) ModelsJSON ¶
ModelsJSON returns a defensive copy of the frozen OpenAI /v1/models body.
func (BoundView) PublicationGeneration ¶
PublicationGeneration returns the frozen publication generation (alias of Generation).
func (BoundView) RefreshedAt ¶
RefreshedAt returns the frozen publication refresh time.
func (BoundView) ResolveModelBinding ¶
func (v BoundView) ResolveModelBinding(backendID, model string) routing.ModelBinding
ResolveModelBinding implements routing.NativeModelResolver with multi-state outcomes.
func (BoundView) ResolveNative ¶
ResolveNative is a compatibility helper: ok is true only for exact-canonical or known-native bindings. Wrong-backend and unknown both return ok=false; callers that need fail-closed planning must use ResolveModelBinding.
type BuildResult ¶
type BuildResult struct {
Registry *Registry
Discoveries []BackendDiscovery
}
BuildResult is the fail-soft aggregation outcome for configured backend inventories.
func Build ¶
func Build(ctx context.Context, inventories []BackendInventory, log *slog.Logger) (BuildResult, error)
type Diagnostics ¶
type Diagnostics struct {
Active bool
Generation string
RefreshedAt time.Time
ModelCount int
BackendModelCounts map[string]int
BackendDiscoveries []BackendDiscovery
LastRefreshErrorCategory RefreshFailureCategory
LastCacheErrorCategory RefreshFailureCategory
}
type OpenAIModel ¶
type OpenAIModel struct {
ID string `json:"id"`
Object string `json:"object"`
OwnedBy string `json:"owned_by"`
}
OpenAIModel is one advertised model row. IDs are instance-pinned canonical selectors (`<backend-instance>:<canonicalID>`). Native IDs are never exposed.
type OpenAIModelList ¶
type OpenAIModelList struct {
Object string `json:"object"`
Data []OpenAIModel `json:"data"`
}
OpenAIModelList is the minimal OpenAI-compatible GET /v1/models response body.
func BuildOpenAIModelsList ¶
func BuildOpenAIModelsList(models []BackendModel) OpenAIModelList
BuildOpenAIModelsList converts registry rows into a stable, deduplicated OpenAI list. Ordering is by id then owned_by. owned_by is the backend kind.
type RefreshFailureCategory ¶
type RefreshFailureCategory string
const ( RefreshFailureNone RefreshFailureCategory = "" RefreshFailureFetch RefreshFailureCategory = "fetch" RefreshFailureCache RefreshFailureCategory = "cache" RefreshFailureParse RefreshFailureCategory = "parse" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) All ¶
func (r *Registry) All() []BackendModel
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
func NewRuntime ¶
func NewRuntime(cfg RuntimeConfig) *Runtime
func (*Runtime) ActiveRegistry ¶
func (*Runtime) All ¶
func (r *Runtime) All() []BackendModel
func (*Runtime) BoundView ¶
BoundView captures the current atomic publication (registry+discoveries) once. A nil receiver returns an empty view.
func (*Runtime) Diagnostics ¶
func (r *Runtime) Diagnostics() Diagnostics
func (*Runtime) Discoveries ¶
func (r *Runtime) Discoveries() []BackendDiscovery
func (*Runtime) LastCacheFailure ¶
func (r *Runtime) LastCacheFailure() RefreshFailureCategory
func (*Runtime) LastRefreshFailure ¶
func (r *Runtime) LastRefreshFailure() RefreshFailureCategory
func (*Runtime) ModelsJSON ¶
ModelsJSON returns the precomputed OpenAI /v1/models JSON body and generation ETag for the published snapshot. ok is false when nothing is published.
func (*Runtime) RunRefresh ¶
RunRefresh runs a background inventory refresh. Concurrent calls while a refresh is already in flight are skipped (no stampede of LoadModels/CLI spawns).