modelinfo

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormService added in v0.4.0

type GormService struct {
	// contains filtered or unexported fields
}

GormService manages model overrides and the per-provider model metadata cache with explicit converters between wire types and override plus snapshot rows. Overrides live in the durable database; snapshots and cached model rows live in the cache file and reference providers softly. The discovery layer (memory cache, upstream fetch, merged views) rides the same handles: persistence stamps the header verbatim and never expires reads. Traditional GORM use: none; every statement runs through gorm.G with typed clauses.

func NewGorm added in v0.4.0

func NewGorm(database *db.Database, providerService *provider.GormService, credentialService *credential.GormService, cacheTTL time.Duration) *GormService

NewGorm constructs a GORM-backed model info service on the SQLite handle. Construction performs no I/O.

func (*GormService) DeleteOverride added in v0.4.0

func (s *GormService) DeleteOverride(ctx context.Context, providerID, modelName string) error

DeleteOverride removes the override for one model. Capability and modality rows cascade from the composite foreign key; no child scan runs. A zero-row delete reports the not-found sentinel through the WithResult tracker.

func (*GormService) DeleteSnapshot added in v0.4.0

func (s *GormService) DeleteSnapshot(ctx context.Context, providerID string) error

DeleteSnapshot removes the cached model list of one provider. Model rows cascade from the header delete with no model scan; capability, modality, and endpoint rows cascade from their model rows. A zero-row delete reports the not-found sentinel through the WithResult tracker.

func (*GormService) GetModelInfo added in v0.4.0

func (s *GormService) GetModelInfo(ctx context.Context, modelID models.ModelId) (*models.ModelInfo, error)

GetModelInfo retrieves metadata for a specific model.

func (*GormService) GetModelInfos added in v0.4.0

func (s *GormService) GetModelInfos(ctx context.Context, providerID string) ([]models.ModelInfo, error)

GetModelInfos retrieves all model metadata for a provider.

func (*GormService) GetModels added in v0.4.0

func (s *GormService) GetModels(ctx context.Context, providerID string) ([]string, error)

GetModels retrieves just the model names for a provider.

func (*GormService) GetOverride added in v0.4.0

func (s *GormService) GetOverride(ctx context.Context, providerID, modelName string) (*models.ModelOverride, error)

GetOverride returns the override for one model with its child lists. A miss reports the not-found sentinel with override context.

func (*GormService) GetSnapshot added in v0.4.0

func (s *GormService) GetSnapshot(ctx context.Context, providerID string) ([]models.ModelInfo, time.Time, error)

GetSnapshot returns the cached model list of one provider ordered by model name with child lists rebuilt per row, plus the stamped header time. A missing header reports the not-found sentinel; the TTL check stays with the caller. Corrupt reasoning payloads surface an error.

func (*GormService) InvalidateAll added in v0.4.0

func (s *GormService) InvalidateAll(ctx context.Context) error

InvalidateAll clears the memory cache and every persisted snapshot.

func (*GormService) InvalidateProvider added in v0.4.0

func (s *GormService) InvalidateProvider(ctx context.Context, providerID string) error

InvalidateProvider clears the memory cache and the persisted snapshot of one provider. A missing snapshot succeeds: invalidation is idempotent.

func (*GormService) IsModelEnabled added in v0.4.0

func (s *GormService) IsModelEnabled(ctx context.Context, providerID, modelName string) (bool, error)

IsModelEnabled reports whether a model may be routed. Models are enabled unless an override disables them. Missing overrides allow routing; storage failures deny routing.

func (*GormService) ListOverrides added in v0.4.0

func (s *GormService) ListOverrides(ctx context.Context, providerID string) ([]*models.ModelOverride, error)

ListOverrides returns all overrides of a provider ordered by model name with child lists rebuilt per row. Empty providers yield an empty slice, never an error.

func (*GormService) MergedView added in v0.4.0

func (s *GormService) MergedView(ctx context.Context, providerID string) ([]ModelView, error)

MergedView merges the cached upstream model list with admin overrides: disabled models are flagged, custom models appended, display metadata applied. Fetches from the upstream on a cache miss — explicit refresh paths only.

func (*GormService) PeekMergedView added in v0.4.0

func (s *GormService) PeekMergedView(ctx context.Context, providerID string) ([]ModelView, error)

PeekMergedView is MergedView over the cache (stale entries count) with no upstream fetch. Browsing paths use it: upstream sync is opt-in (models_auto_sync) or an explicit user action.

func (*GormService) PeekModelInfos added in v0.4.0

func (s *GormService) PeekModelInfos(ctx context.Context, providerID string) []models.ModelInfo

PeekModelInfos returns the cached model list without triggering an upstream fetch; stale entries count, and a memory miss hydrates from the persisted snapshot. A true miss returns nil — callers that merely display a count must not ping the provider.

func (*GormService) PutSnapshot added in v0.4.0

func (s *GormService) PutSnapshot(ctx context.Context, providerID string, modelList []models.ModelInfo, cachedAt time.Time) error

PutSnapshot replaces the cached model list of one provider. The header upserts on the provider key; model rows replace wholesale so dropped models disappear, and capability, modality, and endpoint children follow their model rows. One transaction holds the header upsert, the model delete, and every insert on the cache handle only. Snapshots reference the provider row softly across files: a dangling provider persists instead of failing, and provider deletion clears its snapshots explicitly.

func (*GormService) Refresh added in v0.4.0

func (s *GormService) Refresh(ctx context.Context, providerID string) ([]models.ModelInfo, error)

Refresh forces an upstream fetch and stores it. The previous cache is kept when the fetch fails: until a new list arrives the old one counts as current.

func (*GormService) RemoveModel added in v0.4.0

func (s *GormService) RemoveModel(ctx context.Context, providerID, modelName string) (bool, error)

RemoveModel drops one model from the cached list of one provider. Capability, modality, and endpoint rows cascade from the model delete. A missing provider or model is a no-op reporting false. The memory entry filters in step so peeks observe the removal without a refetch.

func (*GormService) SetLogger added in v0.4.0

func (s *GormService) SetLogger(l *slog.Logger)

SetLogger wires structured logging (called once from server.New).

func (*GormService) SetOverride added in v0.4.0

func (s *GormService) SetOverride(ctx context.Context, override models.ModelOverride) error

SetOverride creates or replaces the override for one model. The base row upserts on the composite key; capability and modality children replace wholesale so removed chips disappear. One transaction holds the upsert, the child deletes, and the child inserts on the transaction handle only. The provider row must exist: a dangling provider fails through the foreign key as invalid input.

func (*GormService) WarmMissing added in v0.4.0

func (s *GormService) WarmMissing(ctx context.Context)

WarmMissing creates model caches for providers that have none. Runs in the background at startup; refresh afterwards stays opt-in (models_auto_sync) or manual.

type ModelView

type ModelView struct {
	models.ModelInfo
	Disabled bool `json:"disabled"`
	Custom   bool `json:"custom"`
}

ModelView is a model merged with its admin override state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL