Documentation
¶
Overview ¶
Package models manages the local model cache: catalog manifests (teraflock/models format), resumable GGUF downloads with SHA256 verification, and LRU eviction under the operator's disk budget.
Index ¶
- Constants
- Variables
- func LocalArtifactPath(artifactURL string) (string, bool)
- func ValidateID(id string) error
- type Catalog
- type CatalogModel
- type Info
- type Manager
- func (m *Manager) DownloadProgress(id string) (Progress, bool)
- func (m *Manager) Ensure(ctx context.Context, spec *typesv1.ModelSpec) (string, error)
- func (m *Manager) EnsureOrigin(ctx context.Context, spec *typesv1.ModelSpec, origin string) (string, error)
- func (m *Manager) List() []Info
- func (m *Manager) Origin(id string) string
- func (m *Manager) Path(id string) string
- func (m *Manager) Pin(id string, pinned bool) error
- func (m *Manager) Remove(id string) error
- func (m *Manager) Touch(id string)
- func (m *Manager) Verify(id string) error
- type Progress
Constants ¶
const ( OriginOperator = "operator" OriginMesh = "mesh" )
Origins for cache entries.
Variables ¶
var ErrInvalidID = errors.New("models: invalid model id")
ErrInvalidID rejects a model id that is unsafe to use as a path component.
var ErrOverBudget = errors.New("models: cannot fit")
ErrOverBudget means a model cannot fit inside max_disk_mb even after evicting everything eviction is allowed to touch.
var ErrSHAMismatch = errors.New("models: sha256 mismatch")
ErrSHAMismatch means a downloaded artifact failed verification. The daemon refuses to serve hash-mismatched files (SPEC §6).
Functions ¶
func LocalArtifactPath ¶
LocalArtifactPath reports whether an artifact_url points at a file already on this machine, and returns its filesystem path. Both `file:///abs/path` and a bare absolute path are accepted — operators writing a local catalog by hand reach for the latter.
This is how a node serves an existing GGUF collection (LM Studio, ollama, hand-built quants) without re-downloading gigabytes it already has.
func ValidateID ¶ added in v0.2.0
ValidateID rejects ids that must never reach filepath.Join. Catalog entries arrive over the network (models.manifest_url is a remote default), so an id such as "../../etc/cron.d/evil" would otherwise escape Dir and let a compromised catalog write anywhere the daemon can.
Types ¶
type Catalog ¶
type Catalog struct {
Models []CatalogModel `yaml:"models" json:"models"`
}
Catalog is the manifest format of the teraflock/models repo (catalog/*.yaml). JSON is accepted too.
func LoadCatalog ¶
LoadCatalog reads a catalog from a local path or URL (one must be set; path wins).
func ParseCatalog ¶
ParseCatalog decodes YAML or JSON manifest bytes.
type CatalogModel ¶
type CatalogModel struct {
ID string `yaml:"id" json:"id"`
// DisplayName is the human-readable name (incl. quant) UIs show —
// ids are ambiguous now that model lines carry point versions
// (qwen3-8b vs qwen3.8-27b). Empty in pre-field catalogs.
DisplayName string `yaml:"display_name" json:"display_name"`
Family string `yaml:"family" json:"family"`
ParamsB float64 `yaml:"params_b" json:"params_b"`
Quant string `yaml:"quant" json:"quant"`
SHA256 string `yaml:"sha256" json:"sha256"`
MinVRAMMB uint64 `yaml:"min_vram_mb" json:"min_vram_mb"`
MinRAMMB uint64 `yaml:"min_ram_mb" json:"min_ram_mb"`
License string `yaml:"license" json:"license"`
ArtifactURL string `yaml:"artifact_url" json:"artifact_url"`
SizeBytes uint64 `yaml:"size_bytes" json:"size_bytes"`
PayoutClass string `yaml:"payout_class" json:"payout_class"`
ContextLength uint32 `yaml:"context_length" json:"context_length"`
Embeddings bool `yaml:"embeddings" json:"embeddings"`
}
CatalogModel is one curated model entry.
func (CatalogModel) Spec ¶
func (m CatalogModel) Spec() *typesv1.ModelSpec
Spec converts a catalog entry to the proto ModelSpec.
type Info ¶
type Info struct {
ID string `json:"id"`
SizeBytes int64 `json:"size_bytes"`
Pinned bool `json:"pinned"`
LastUsed time.Time `json:"last_used"`
State string `json:"state"`
// Origin is "operator" or "mesh" (who installed it).
Origin string `json:"origin"`
// ReceivedBytes is live progress, present only while downloading.
ReceivedBytes int64 `json:"received_bytes,omitempty"`
}
Info is a local cache listing row.
type Manager ¶
type Manager struct {
Dir string
MaxDiskMB int64
Client *http.Client
Log *slog.Logger
// OnProgress, when set, receives byte progress during downloads
// (throttled). total is 0 when the server sent no length and the
// catalog carries no size.
OnProgress func(id string, received, total int64)
// contains filtered or unexported fields
}
Manager owns <data_dir>/models: downloads, verification, pins and LRU eviction under the disk budget.
func NewManager ¶
NewManager loads (or initializes) the cache state.
func (*Manager) DownloadProgress ¶ added in v0.3.0
DownloadProgress reports live byte progress for an in-flight download.
func (*Manager) Ensure ¶
Ensure makes the model available locally: verified cache hit, resumed partial download, or full download. Returns the local path. The entry is operator-owned; see EnsureOrigin.
func (*Manager) EnsureOrigin ¶ added in v0.3.0
func (m *Manager) EnsureOrigin(ctx context.Context, spec *typesv1.ModelSpec, origin string) (string, error)
EnsureOrigin is Ensure with ownership: a mesh-origin fetch may only evict other mesh-origin models to make room (the operator's models are off limits to the coordinator), and a model the operator already has is never re-labelled as the mesh's.
func (*Manager) Origin ¶ added in v0.3.0
Origin reports who owns a cached model ("" when not cached).