Documentation
¶
Overview ¶
Package catalogsync owns the model-catalog data source registry: a DB-persisted, ordered list of catalog sources (llm-metadata / models.dev presets plus operator-added custom URLs) that are fetched in order and merged first-wins into the runtime catalog snapshot consumed by routing and the models marketplace.
Index ¶
- Constants
- Variables
- func DefaultSourcePresets() []pricingcatalog.SourceSpec
- type Manager
- func (m *Manager) AutoSyncEnabled() bool
- func (m *Manager) CreateSource(ctx context.Context, in SourceInput) (Source, error)
- func (m *Manager) DeleteSource(ctx context.Context, id int64) error
- func (m *Manager) Interval() time.Duration
- func (m *Manager) ReloadSources(ctx context.Context) error
- func (m *Manager) ResolveCatalogPricing(siteID, accountID int64, modelName string) (unitCost *float64, source string)
- func (m *Manager) SetAutoSyncEnabled(ctx context.Context, enabled bool) error
- func (m *Manager) Snapshot() *pricingcatalog.CatalogSnapshot
- func (m *Manager) Start()
- func (m *Manager) Status(ctx context.Context) *SyncStatus
- func (m *Manager) Stop()
- func (m *Manager) SyncNow(ctx context.Context, sourceID int64) (*SyncStatus, error)
- func (m *Manager) UpdateSource(ctx context.Context, id int64, in SourceInput) (Source, error)
- type Options
- type SnapshotStatus
- type Source
- type SourceInput
- type Store
- func (s *Store) AutoSyncEnabled(ctx context.Context) (bool, error)
- func (s *Store) CreateSource(ctx context.Context, in SourceInput) (Source, error)
- func (s *Store) DeleteSource(ctx context.Context, id int64) error
- func (s *Store) EnsureDefaults(ctx context.Context, legacyURL string) error
- func (s *Store) ListSources(ctx context.Context) ([]Source, error)
- func (s *Store) RecordStatus(ctx context.Context, report pricingcatalog.SourceReport) error
- func (s *Store) SetAutoSyncEnabled(ctx context.Context, enabled bool) error
- func (s *Store) UpdateSource(ctx context.Context, id int64, in SourceInput) (Source, error)
- type SyncStatus
Constants ¶
const ( // SettingsAutoSyncKey is the settings-table key for the automatic // catalog sync toggle ("true"/"false"; missing = enabled). SettingsAutoSyncKey = "catalog_auto_sync_enabled" // SourceTypeOfficial marks a preset official dataset source. SourceTypeOfficial = "official" // SourceTypeCustom marks an operator-added source. SourceTypeCustom = "custom" )
Variables ¶
var ErrSyncBusy = errors.New("catalogsync: sync already running")
ErrSyncBusy reports an overlapping sync run.
Functions ¶
func DefaultSourcePresets ¶
func DefaultSourcePresets() []pricingcatalog.SourceSpec
DefaultSourcePresets is the seed registry: llm-metadata (primary, native-provider filtered, daily rebuilt) followed by models.dev (fallback), then the llm-metadata newapi ratio set (same origin as llm-metadata; supplies the NewAPI ratio multipliers used for relay-site cost estimates and tiered billing metadata). A legacy PRICING_CATALOG_URL value that differs from both presets is inserted in front at seed time (see EnsureDefaults).
Types ¶
type Manager ¶
type Manager struct {
*Store
// contains filtered or unexported fields
}
Manager owns the runtime catalog: the DB registry (Store) plus the pricingcatalog Provider that fetches/merges the sources and publishes the snapshot consumed by routing (cold-start cost) and the marketplace. Implements routing.CatalogPricingResolver structurally (unitCost, source).
func NewManager ¶
NewManager builds a Manager, seeds the default registry when empty, and wires the provider to the persisted sources. Call Start to begin syncing.
func (*Manager) AutoSyncEnabled ¶
AutoSyncEnabled reports the current auto-sync toggle.
func (*Manager) CreateSource ¶
CreateSource persists a new source and re-wires the provider.
func (*Manager) DeleteSource ¶
DeleteSource removes a source and re-wires the provider.
func (*Manager) ReloadSources ¶
ReloadSources re-reads the registry into the provider after CRUD changes.
func (*Manager) ResolveCatalogPricing ¶
func (m *Manager) ResolveCatalogPricing(siteID, accountID int64, modelName string) (unitCost *float64, source string)
ResolveCatalogPricing implements routing.CatalogPricingResolver structurally: it delegates to the underlying provider (site-classified official vs relay provenance).
func (*Manager) SetAutoSyncEnabled ¶
SetAutoSyncEnabled flips the toggle and persists it to settings.
func (*Manager) Snapshot ¶
func (m *Manager) Snapshot() *pricingcatalog.CatalogSnapshot
Snapshot returns the published merged catalog snapshot (never nil).
func (*Manager) Start ¶
func (m *Manager) Start()
Start begins an immediate background sync (when auto sync is enabled) plus the periodic loop. Idempotent.
func (*Manager) Stop ¶
func (m *Manager) Stop()
Stop halts the periodic loop. Safe to call multiple times.
func (*Manager) SyncNow ¶
SyncNow runs a sync pass: all enabled sources (sourceID <= 0) or one source. Concurrent runs are declined with ErrSyncBusy. Returns the full status payload for the panel.
func (*Manager) UpdateSource ¶
UpdateSource patches a source and re-wires the provider.
type Options ¶
type Options struct {
// Interval is the auto-sync cadence. <= 0 disables the periodic loop
// (the initial background fetch still runs when auto sync is enabled).
Interval time.Duration
// LegacyURL is the PRICING_CATALOG_URL env value; when it differs from
// both presets it is seeded as the top-priority custom source.
LegacyURL string
// SiteSnapshotSource resolves site platform/URL for vendor
// classification in ResolveCatalogPricing.
SiteSnapshotSource pricingcatalog.SiteSnapshotSource
// Logger defaults to slog.Default().
Logger *slog.Logger
}
Options configures a Manager.
type SnapshotStatus ¶
type SnapshotStatus struct {
Source string `json:"source"`
FetchedAt *time.Time `json:"fetchedAt"`
Models int `json:"models"`
}
SnapshotStatus describes the published merged snapshot.
type Source ¶
type Source struct {
ID int64 `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Enabled bool `json:"enabled"`
Type string `json:"type"`
SortOrder int `json:"sortOrder"`
LastSuccessAt *time.Time `json:"lastSuccessAt"`
LastError *string `json:"lastError"`
LastCount int `json:"lastCount"`
LastAttemptAt *time.Time `json:"lastAttemptAt"`
}
Source is one persisted registry row (wire/domain shape).
type SourceInput ¶
type SourceInput struct {
Name string `json:"name"`
URL string `json:"url"`
Enabled *bool `json:"enabled"`
Type string `json:"type"`
// SortOrder, when >= 0, repositions the source (update only).
SortOrder *int `json:"sortOrder"`
}
SourceInput is the create/update payload for a source row.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the DB registry for catalog sources. Manager embeds it so CRUD goes through one owner that also re-syncs the runtime provider.
func (*Store) AutoSyncEnabled ¶
AutoSyncEnabled reads the settings toggle (missing key = enabled).
func (*Store) CreateSource ¶
CreateSource inserts a new source at the end of the fetch order.
func (*Store) DeleteSource ¶
DeleteSource removes a registry row.
func (*Store) EnsureDefaults ¶
EnsureDefaults seeds the registry with the preset sources when the table is empty. legacyURL (the PRICING_CATALOG_URL env value) is inserted as the top-priority custom source when it differs from both presets — this is the migration of the old single-URL configuration into the registry.
func (*Store) ListSources ¶
ListSources returns all registry rows in fetch order (sort_order, id).
func (*Store) RecordStatus ¶
func (s *Store) RecordStatus(ctx context.Context, report pricingcatalog.SourceReport) error
RecordStatus persists one source's sync outcome (success time / error / entry count). Successful outcomes clear the error column.
func (*Store) SetAutoSyncEnabled ¶
SetAutoSyncEnabled writes the settings toggle (upsert).
func (*Store) UpdateSource ¶
UpdateSource patches name/url/enabled/type/sortOrder of a source. Passing sortOrder repositions the row (other rows are shifted to keep the order contiguous).
type SyncStatus ¶
type SyncStatus struct {
AutoSync bool `json:"autoSync"`
IntervalMin int `json:"intervalMin"`
Snapshot SnapshotStatus `json:"snapshot"`
Sources []Source `json:"sources"`
}
SyncStatus is the status payload served to the panel.