datamanagement

package
v0.4.2 Latest Latest
Warning

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

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

Documentation

Overview

GORM-backed data management.

GormService orchestrates export, import, and truncation against context-taking dependencies: GORM-backed providers, credentials, virtual models, tokens, plugins, repositories, and model overrides. It owns no tables and issues no storage statements itself: every read and write delegates to the owning service through narrow interfaces, so bundle shapes stay stable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormCredentialBackend added in v0.4.0

type GormCredentialBackend interface {
	ListAll(ctx context.Context) ([]*models.Credential, error)
	ListByProvider(ctx context.Context, providerID string) ([]*models.Credential, error)
	UpdateDetails(ctx context.Context, identifier string, label *string, disabled *bool, data map[string]any) error
	Add(ctx context.Context, options credential.AddOptions) (*models.Credential, error)
}

GormCredentialBackend is the credential surface the GORM data management path needs: inventory reads plus the add/update writes provider imports drive. Signatures match the credential GORM service.

type GormModelInfoBackend added in v0.4.0

type GormModelInfoBackend interface {
	ListOverrides(ctx context.Context, providerID string) ([]*models.ModelOverride, error)
	SetOverride(ctx context.Context, override models.ModelOverride) error
	DeleteOverride(ctx context.Context, providerID, modelName string) error
	DeleteSnapshot(ctx context.Context, providerID string) error
}

GormModelInfoBackend is the model metadata surface the GORM data management path needs: override reads/writes plus snapshot invalidation on provider purge. Signatures match the modelinfo GORM service.

type GormPluginBackend added in v0.4.0

type GormPluginBackend interface {
	ListSQLite(ctx context.Context) ([]*luaplugin.PluginRecord, error)
	InstallSQLite(ctx context.Context, source []byte, origin luaplugin.PluginOrigin) (*luaplugin.PluginRecord, error)
	SetDisabled(ctx context.Context, pluginID string, disabled bool) (*luaplugin.PluginRecord, error)
	DeleteSQLite(ctx context.Context, pluginID string) error
}

GormPluginBackend is the plugin surface the GORM data management path needs: SQLite list/install/delete plus the disabled toggle. Signatures match the luaplugin SQLite methods; storage rows cascade from the plugin delete, so no storage statement runs here.

type GormProviderBackend added in v0.4.0

type GormProviderBackend interface {
	Get(ctx context.Context, identifier string) (*models.ProviderInstance, error)
	List(ctx context.Context) ([]*models.ProviderInstance, error)
	Create(ctx context.Context, options provider.CreateOptions) (*models.ProviderInstance, error)
	Update(ctx context.Context, identifier string, options provider.UpdateOptions) (*models.ProviderInstance, error)
	Delete(ctx context.Context, identifier string) error
}

GormProviderBackend is the provider surface the GORM data management path needs: inventory reads plus the create/update/delete writes imports and purges drive. Signatures match the provider GORM service.

type GormProxyBackend added in v0.4.2

type GormProxyBackend interface {
	DataCounts(ctx context.Context) (pools, proxies int, err error)
	ExportData(ctx context.Context) (*models.ProxyDataBundle, error)
	ImportData(ctx context.Context, bundle *models.ProxyDataBundle) error
	ClearData(ctx context.Context) error
}

GormProxyBackend is the proxy subsystem persistence the data service needs.

type GormRepositoryBackend added in v0.4.0

type GormRepositoryBackend interface {
	List() ([]*pluginrepo.RepoRecord, error)
	AddRepo(ctx context.Context, rawURL string) (*pluginrepo.RepoRecord, error)
	Remove(identifier string) error
}

GormRepositoryBackend is the repository surface the GORM data management path needs. The pluginrepo Service already mirrors writes to SQLite, so the same context-free List/Remove plus context-taking AddRepo cover both paths.

type GormService added in v0.4.0

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

GormService orchestrates subsystem export, import, and truncation against GORM-backed dependencies. Construction performs no I/O. Nil plugin, repository, model info, virtual, and token backends disable their subsystems exactly as before.

func NewGorm added in v0.4.0

func NewGorm(
	providerSource GormProviderBackend,
	credentialSource GormCredentialBackend,
	virtualSource GormVirtualBackend,
	tokenSource GormTokenBackend,
	pluginSource GormPluginBackend,
	repositorySource GormRepositoryBackend,
	modelInfoSource GormModelInfoBackend,
) *GormService

NewGorm constructs a GORM-backed data management service. Construction performs no I/O.

func (*GormService) ClearPlugins added in v0.4.0

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

ClearPlugins deletes every plugin and every non-builtin repository. Plugin storage, allow host, and version rows cascade from the plugin delete in the owning luaplugin service; this package never touches tables outside its own directory.

func (*GormService) ClearProviders added in v0.4.0

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

ClearProviders deletes every provider instance. Credential, park, health, override, info, managed virtual, and member rows cascade from the provider foreign keys with no scans.

func (*GormService) ClearProxy added in v0.4.2

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

ClearProxy removes manual pools and every discovered proxy.

func (*GormService) ClearTokens added in v0.4.0

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

ClearTokens deletes every router token.

func (*GormService) ClearVirtualModels added in v0.4.0

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

ClearVirtualModels deletes every virtual model. Member rows cascade from the model delete with no scans.

func (*GormService) ExportPlugins added in v0.4.0

func (s *GormService) ExportPlugins(ctx context.Context) (*PluginsExportBundle, error)

ExportPlugins packages repository records plus installed plugin records. List failures yield empty halves, matching the previous behavior.

func (*GormService) ExportProvider added in v0.4.0

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

ExportProvider packages one provider instance with its credentials and overrides. Credential and override list failures yield empty lists, matching the previous behavior.

func (*GormService) ExportProviders added in v0.4.0

func (s *GormService) ExportProviders(ctx context.Context) ([]*ProviderBundle, error)

ExportProviders packages every provider instance with its credentials and model overrides. Override list failures yield no overrides for that provider, matching the previous behavior: overrides stay optional metadata.

func (*GormService) ExportProxy added in v0.4.2

func (s *GormService) ExportProxy(ctx context.Context) (*models.ProxyDataBundle, error)

ExportProxy packages the proxy switches, manual pools and healthy discovered proxies.

func (*GormService) ExportTokens added in v0.4.0

func (s *GormService) ExportTokens(ctx context.Context) ([]*models.RouterToken, error)

ExportTokens returns every router token.

func (*GormService) ExportVirtualModels added in v0.4.0

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

ExportVirtualModels returns every virtual model.

func (*GormService) ImportPlugins added in v0.4.0

func (s *GormService) ImportPlugins(ctx context.Context, bundle *PluginsExportBundle) error

ImportPlugins adds every bundled repository, then installs every bundled plugin source. Failures return immediately.

func (*GormService) ImportProvider added in v0.4.0

func (s *GormService) ImportProvider(ctx context.Context, bundle *ProviderBundle) error

ImportProvider imports a single provider bundle.

func (*GormService) ImportProviders added in v0.4.0

func (s *GormService) ImportProviders(ctx context.Context, bundles []*ProviderBundle) error

ImportProviders creates or updates every bundled provider, then its credentials and overrides. Update failures return immediately; create failures return immediately instead of surfacing later at the credential write.

func (*GormService) ImportProxy added in v0.4.2

func (s *GormService) ImportProxy(ctx context.Context, bundle *models.ProxyDataBundle) error

ImportProxy restores a proxy data bundle.

func (*GormService) ImportTokens added in v0.4.0

func (s *GormService) ImportTokens(ctx context.Context, tokens []*models.RouterToken) error

ImportTokens updates rules for known token IDs, otherwise mints fresh tokens. Mint failures return immediately.

func (*GormService) ImportVirtualModels added in v0.4.0

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

ImportVirtualModels creates or updates every virtual model. Update failures return immediately instead of falling through to a duplicate create.

func (*GormService) PurgeProvider added in v0.4.0

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

PurgeProvider removes a provider instance and all associated data: credentials cascade from the provider delete, snapshots and overrides go through the owning model info service, and managed virtual models delete through the virtual service. A missing snapshot is not an error, matching the idempotent previous invalidation.

func (*GormService) SetLogger added in v0.4.0

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

SetLogger wires structured logging.

func (*GormService) SetProxyBackend added in v0.4.2

func (s *GormService) SetProxyBackend(backend GormProxyBackend)

SetProxyBackend wires the proxy subsystem. Without it the proxy data operations report an error.

func (*GormService) Stats added in v0.4.0

func (s *GormService) Stats(ctx context.Context) (SubsystemStats, error)

Stats returns the record counts for each managed subsystem. A failing subsystem contributes no count, matching the previous behavior: stats stay best-effort so one broken subsystem never hides the rest.

type GormTokenBackend added in v0.4.0

type GormTokenBackend interface {
	List(ctx context.Context) ([]*models.RouterToken, error)
	UpdateRules(ctx context.Context, identifier string, rules models.TokenRules) error
	Create(ctx context.Context, options token.CreateOptions) (*models.RouterToken, error)
	Delete(ctx context.Context, identifier string) error
}

GormTokenBackend is the token surface the GORM data management path needs. Signatures match the token GORM service.

type GormVirtualBackend added in v0.4.0

type GormVirtualBackend interface {
	List(ctx context.Context) ([]*models.VirtualModel, error)
	Get(ctx context.Context, identifier string) (*models.VirtualModel, error)
	Create(ctx context.Context, virtualModel *models.VirtualModel) error
	Update(ctx context.Context, identifier string, virtualModel *models.VirtualModel) error
	Delete(ctx context.Context, identifier string) error
}

GormVirtualBackend is the virtual model surface the GORM data management path needs. Signatures match the virtual GORM service.

type PluginsExportBundle

type PluginsExportBundle struct {
	Repos   []*pluginrepo.RepoRecord  `json:"repos"`
	Plugins []*luaplugin.PluginRecord `json:"plugins"`
}

PluginsExportBundle packages plugin store repositories with installed plugins.

type ProviderBundle

type ProviderBundle struct {
	Instance    *models.ProviderInstance `json:"instance"`
	Credentials []*models.Credential     `json:"credentials"`
	Overrides   []*models.ModelOverride  `json:"overrides,omitempty"`
}

ProviderBundle packages a provider instance with its credentials and model overrides.

type SubsystemStats

type SubsystemStats struct {
	Providers     int `json:"providers"`
	Credentials   int `json:"credentials"`
	VirtualModels int `json:"virtual_models"`
	Plugins       int `json:"plugins"`
	PluginRepos   int `json:"plugin_repos"`
	Tokens        int `json:"tokens"`
	ProxyPools    int `json:"proxy_pools"`
	Proxies       int `json:"proxies"`
}

SubsystemStats reports record counts for data management UI.

type TokenImport

type TokenImport = models.RouterToken

type VirtualModelImport

type VirtualModelImport = models.VirtualModel

Aliases for clean API import payloads

Jump to

Keyboard shortcuts

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