virtual

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseMarker added in v0.1.2

func ParseMarker(marker string) (providerID, slug string, err error)

ParseMarker splits a ManagedBy marker into provider ID and endpoint slug. The split runs at the last colon, so provider IDs containing colons (qualified "type:qualifier" rows) survive the round trip.

func ProviderMarker added in v0.1.0

func ProviderMarker(providerID, slug string) string

ProviderMarker builds the ManagedBy marker for a provider endpoint group.

Types

type GormService added in v0.4.0

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

GormService manages virtual models on the SQLite handle with explicit converters between wire types and the virtual_models base rows plus position-ordered virtual_model_members rows. Provider existence checks run as typed reads inside each write transaction. Managed sync reads the provider registry and the model info merged view. 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, modelInfoService *modelinfo.GormService) *GormService

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

func (*GormService) Create added in v0.4.0

func (s *GormService) Create(ctx context.Context, virtualModel *models.VirtualModel) error

Create persists a new virtual model with a slug ID derived from its name. Members insert position-ordered behind the base row; the name_key UNIQUE index rejects case-insensitive name duplicates with the previous message plus the already-exists sentinel. A dangling member provider fails through the existence check as invalid input. One transaction holds the slug loop, the provider check, and both inserts on the transaction handle only.

func (*GormService) Delete added in v0.4.0

func (s *GormService) Delete(ctx context.Context, identifier string) error

Delete removes a virtual model by ID in one conditioned delete. Member rows cascade from the virtual model foreign key; no member scan runs. A zero-row delete reports the not-found sentinel through the WithResult tracker.

func (*GormService) Get added in v0.4.0

func (s *GormService) Get(ctx context.Context, identifier string) (*models.VirtualModel, error)

Get returns a virtual model by ID with members in fall-through order. A miss reports the not-found sentinel with virtual model context. One transaction holds the base read and the member read on the transaction handle only.

func (*GormService) GroupsForProvider added in v0.4.0

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

GroupsForProvider computes endpoint groups from the cached merged view (no upstream fetch) with managed markers resolved. Only non-empty groups are returned; disabled models never become members.

func (*GormService) List added in v0.4.0

func (s *GormService) List(ctx context.Context) ([]*models.VirtualModel, error)

List returns all virtual models sorted by ID with members in fall-through order. One transaction holds the base read and the member read on the transaction handle only; members group in Go. Empty tables yield an empty slice, never an error.

func (*GormService) LiveMembers added in v0.4.0

func (s *GormService) LiveMembers(ctx context.Context, agent *models.VirtualModel) ([]models.ModelId, error)

LiveMembers returns the model ids to try for the agent, snapshotted for one request. Managed virtual models resolve their endpoint group live from the provider model list (disabled and removed models drop out on the next call); manual models use the stored list. Storage failures and corrupt markers are errors; a managed group with no models is an empty list without an error.

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) SyncProviderModels added in v0.4.0

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

SyncProviderModels creates/updates/deletes managed virtual models so each non-empty endpoint group has exactly one. Members are enabled models serving the endpoint, in cache order. Managed VMs whose group emptied are deleted. Disabled providers hold no groups: their managed rows delete so a disabled provider never leaves routable-looking virtual models behind; re-enabling recreates them from the cache. Manual edits to name/description/instruction survive: only the member list is rewritten. Per-group failures accumulate into the returned error; completed groups still apply.

func (*GormService) Update added in v0.4.0

func (s *GormService) Update(ctx context.Context, identifier string, virtualModel *models.VirtualModel) error

Update replaces a virtual model under a stable ID. Member rows replace wholesale so removed positions disappear. Optimistic locking mirrors the previous path: a nonzero caller version must match storage. Renames onto another model name fail through the name_key index with the previous message plus the already-exists sentinel. One transaction holds the read, the provider check, the base upsert, the member delete, and the member insert on the transaction handle only.

type Metadata added in v0.1.0

type Metadata struct {
	Capabilities        []string
	ContextLength       int64
	MaxCompletionTokens int64
	InputModalities     []string
	OutputModalities    []string
	Reasoning           *models.ModelReasoning
	SupportedParameters []string
}

Metadata is generated virtual-model metadata, folded serve-time from the currently available members. Every set is an intersection (only what all members share); limits are minima over members reporting them.

func FoldMembers added in v0.1.0

func FoldMembers(members []models.ModelInfo) Metadata

FoldMembers folds member models into one virtual metadata record. Callers pass only available (known, enabled) members; an empty input yields a zero Metadata.

type ProviderVMGroup added in v0.1.0

type ProviderVMGroup struct {
	Endpoint string               `json:"endpoint"`
	Label    string               `json:"label"`
	Models   []string             `json:"models"`
	Virtual  *models.VirtualModel `json:"virtual,omitempty"`
}

ProviderVMGroup is one endpoint group with its managed virtual model.

Jump to

Keyboard shortcuts

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