Documentation
¶
Overview ¶
Package plugins provides the application layer service for managing plugins.
Index ¶
- Constants
- Variables
- func GetCategoryLabel(id string) string
- func GetCategoryPriority(id string) int
- func IsValidCategory(id string) bool
- type Category
- type ConfigureError
- type EnricherCapabilities
- type ErrBuiltinPlugin
- type ErrPluginNotFound
- type FilterTab
- type InstallProgress
- type InstallRequest
- type InstallStatus
- type LogEntry
- type LogOptions
- type MarketplaceCatalog
- type MarketplaceConfig
- type MarketplacePlugin
- type MarketplaceService
- func (s *MarketplaceService) CheckUpdates(ctx context.Context) (*UpdatesResponse, error)
- func (s *MarketplaceService) GetDetails(ctx context.Context, pluginID string) (*MarketplacePlugin, error)
- func (s *MarketplaceService) Install(ctx context.Context, req InstallRequest, progress chan<- InstallProgress) error
- func (s *MarketplaceService) ListAvailable(ctx context.Context) (*MarketplaceCatalog, error)
- func (s *MarketplaceService) RefreshCatalog(ctx context.Context) error
- func (s *MarketplaceService) Uninstall(ctx context.Context, pluginID string) error
- func (s *MarketplaceService) Update(ctx context.Context, pluginID string, progress chan<- InstallProgress) error
- type Plugin
- type PluginDetail
- type PluginHealthDetail
- type PluginQueries
- type PluginSettings
- type PluginSource
- type PluginSummary
- type SchemaParser
- type Service
- func (s *Service) ApplyStoredSettings(ctx context.Context) error
- func (s *Service) Disable(ctx context.Context, id string) error
- func (s *Service) Enable(ctx context.Context, id string) error
- func (s *Service) Get(ctx context.Context, id string) (*PluginDetail, error)
- func (s *Service) GetHealth(ctx context.Context, id string) (*PluginHealthDetail, error)
- func (s *Service) GetLogs(ctx context.Context, id string, opts LogOptions) ([]LogEntry, error)
- func (s *Service) GetSettings(ctx context.Context, id string) (*PluginSettings, error)
- func (s *Service) List(ctx context.Context) ([]PluginSummary, error)
- func (s *Service) RegisterPlugin(ctx context.Context, p Plugin) error
- func (s *Service) Restart(ctx context.Context, id string) error
- func (s *Service) SetEncryptor(encryptor *crypto.Encryptor)
- func (s *Service) UpdateSettings(ctx context.Context, id string, values json.RawMessage) error
- type UpdateInfo
- type UpdatesResponse
Constants ¶
const ( // DefaultCacheTTL is the default time-to-live for the marketplace cache. DefaultCacheTTL = 15 * time.Minute )
Variables ¶
var ( ErrPluginNotInMarketplace = errors.New("plugin not found in marketplace") ErrPluginAlreadyInstalled = errors.New("plugin is already installed") ErrNoCompatibleAsset = errors.New("no compatible binary for this platform") ErrChecksumMismatch = errors.New("checksum verification failed") ErrCannotUninstallBuiltin = errors.New("cannot uninstall built-in plugins") ErrPluginHasDependents = errors.New("other plugins depend on this plugin") )
Marketplace errors.
Functions ¶
func GetCategoryLabel ¶
GetCategoryLabel returns the display label for a category ID. Returns "Other" if the ID is not found.
func GetCategoryPriority ¶
GetCategoryPriority returns the sort priority for a category ID. Returns 99 (Other's priority) if the ID is not found.
func IsValidCategory ¶
IsValidCategory returns true if the given ID is a valid display category.
Types ¶
type Category ¶
type Category = manifest.DisplayCategory
Category is an alias for manifest.DisplayCategory. Kept for backwards compatibility with existing code.
func Categories ¶
func Categories() []Category
Categories returns the predefined plugin categories from the manifest package. This is the single source of truth for display categories.
type ConfigureError ¶
type ConfigureError struct {
Message string
}
ConfigureError is returned when plugin configuration fails.
func (*ConfigureError) Error ¶
func (e *ConfigureError) Error() string
type EnricherCapabilities ¶
type EnricherCapabilities struct {
MediaTypes []string `json:"media_types"`
Provides []string `json:"provides"`
IsLocal bool `json:"is_local"`
RateLimit int `json:"rate_limit"`
Requires []string `json:"requires,omitempty"`
}
EnricherCapabilities describes what an enricher plugin provides.
type ErrBuiltinPlugin ¶
type ErrBuiltinPlugin struct {
PluginID string
}
ErrBuiltinPlugin is returned when trying to disable a built-in plugin.
func (ErrBuiltinPlugin) Error ¶
func (e ErrBuiltinPlugin) Error() string
type ErrPluginNotFound ¶
type ErrPluginNotFound struct {
PluginID string
}
ErrPluginNotFound is returned when a plugin doesn't exist.
func (ErrPluginNotFound) Error ¶
func (e ErrPluginNotFound) Error() string
type FilterTab ¶
type FilterTab struct {
ID string `json:"id"` // Tab identifier (e.g., "all", "enrichers")
Label string `json:"label"` // Display label
Count int `json:"count"` // Number of plugins matching this filter
}
FilterTab represents a filter tab for the plugins UI.
func ComputeFilterTabs ¶
func ComputeFilterTabs(plugins []PluginSummary) []FilterTab
ComputeFilterTabs returns the available filter tabs with counts based on the plugin list. Uses the predefined Categories for ordering and labels.
type InstallProgress ¶
type InstallProgress struct {
PluginID string `json:"plugin_id"`
Status InstallStatus `json:"status"`
Progress int `json:"progress"` // 0-100
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Version string `json:"version,omitempty"`
}
InstallProgress tracks installation progress for SSE streaming.
type InstallRequest ¶
type InstallRequest struct {
PluginID string `json:"plugin_id" binding:"required"`
Version string `json:"version,omitempty"` // Empty means latest
}
InstallRequest is the request to install a plugin.
type InstallStatus ¶
type InstallStatus string
InstallStatus represents the current stage of installation.
const ( InstallStatusPending InstallStatus = "pending" InstallStatusDownloading InstallStatus = "downloading" InstallStatusExtracting InstallStatus = "extracting" InstallStatusInstalling InstallStatus = "installing" InstallStatusComplete InstallStatus = "complete" InstallStatusFailed InstallStatus = "failed" )
type LogEntry ¶
type LogEntry struct {
Timestamp time.Time `json:"timestamp"`
Level string `json:"level"`
Message string `json:"message"`
Fields map[string]string `json:"fields,omitempty"`
}
LogEntry represents a single log entry from a plugin.
type LogOptions ¶
type LogOptions struct {
Limit int // Max entries to return (default 100)
Level string // Filter by level (e.g., "error", "warn")
Since time.Time // Only entries after this time
}
LogOptions configures log retrieval.
type MarketplaceCatalog ¶
type MarketplaceCatalog struct {
Plugins []MarketplacePlugin `json:"plugins"`
UpdatedAt time.Time `json:"updated_at"`
CacheAge string `json:"cache_age,omitempty"` // Human-readable, e.g. "5m ago"
}
MarketplaceCatalog is the list of available plugins.
type MarketplaceConfig ¶
type MarketplaceConfig struct {
// Enabled controls whether marketplace features are available.
Enabled bool
// CacheTTL is how long to cache the plugin catalog.
CacheTTL time.Duration
// PluginDir is where plugins are installed.
PluginDir string
// TempDir is for temporary downloads.
TempDir string
}
MarketplaceConfig configures the marketplace service.
type MarketplacePlugin ¶
type MarketplacePlugin struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Author string `json:"author,omitempty"`
LatestVersion string `json:"latest_version"`
InstalledVersion string `json:"installed_version,omitempty"`
IsInstalled bool `json:"is_installed"`
HasUpdate bool `json:"has_update"`
Capabilities []string `json:"capabilities,omitempty"`
DownloadCount int64 `json:"download_count,omitempty"`
PublishedAt string `json:"published_at,omitempty"` // RFC3339
}
MarketplacePlugin represents a plugin available in the marketplace.
type MarketplaceService ¶
type MarketplaceService struct {
// contains filtered or unexported fields
}
MarketplaceService provides marketplace operations for browsing, installing, updating, and uninstalling plugins from GitHub releases.
func NewMarketplaceService ¶
func NewMarketplaceService( config MarketplaceConfig, queries PluginQueries, manager *infraplugins.Manager, logger *slog.Logger, ) *MarketplaceService
NewMarketplaceService creates a new marketplace service.
func (*MarketplaceService) CheckUpdates ¶
func (s *MarketplaceService) CheckUpdates(ctx context.Context) (*UpdatesResponse, error)
CheckUpdates returns a list of installed plugins that have updates available.
func (*MarketplaceService) GetDetails ¶
func (s *MarketplaceService) GetDetails(ctx context.Context, pluginID string) (*MarketplacePlugin, error)
GetDetails returns details for a specific marketplace plugin.
func (*MarketplaceService) Install ¶
func (s *MarketplaceService) Install(ctx context.Context, req InstallRequest, progress chan<- InstallProgress) error
Install downloads and installs a plugin from the marketplace.
func (*MarketplaceService) ListAvailable ¶
func (s *MarketplaceService) ListAvailable(ctx context.Context) (*MarketplaceCatalog, error)
ListAvailable returns the list of plugins available in the marketplace.
func (*MarketplaceService) RefreshCatalog ¶
func (s *MarketplaceService) RefreshCatalog(ctx context.Context) error
RefreshCatalog forces a refresh of the cached catalog.
func (*MarketplaceService) Uninstall ¶
func (s *MarketplaceService) Uninstall(ctx context.Context, pluginID string) error
Uninstall removes a plugin.
func (*MarketplaceService) Update ¶
func (s *MarketplaceService) Update(ctx context.Context, pluginID string, progress chan<- InstallProgress) error
Update updates an installed plugin to the latest version.
type Plugin ¶
type Plugin struct {
ID string
Name string
Version string
Description string
Author string
License string
Homepage string
Capabilities string // JSON array of capability strings
IsBuiltin bool
Enabled bool
Path string
HealthStatus string
LastHeartbeat time.Time
RestartCount int
Settings string // JSON string of plugin settings
SettingsSchema string // JSON Schema for plugin settings
InstalledAt time.Time
UpdatedAt time.Time
}
Plugin represents a plugin record from the database. Uses native Go types - the repository handles conversion from sql.Null* types.
type PluginDetail ¶
type PluginDetail struct {
PluginSummary
License string `json:"license"`
Homepage string `json:"homepage"`
InstalledAt time.Time `json:"installed_at"`
UpdatedAt time.Time `json:"updated_at"`
RestartCount int `json:"restart_count"`
LastHeartbeat time.Time `json:"last_heartbeat"`
HealthMessage string `json:"health_message,omitempty"`
// EnricherCapabilities contains enricher-specific capabilities (nil for non-enrichers)
EnricherCapabilities *EnricherCapabilities `json:"enricher_capabilities,omitempty"`
}
PluginDetail contains full plugin information.
type PluginHealthDetail ¶
type PluginHealthDetail struct {
Status string `json:"status"`
Message string `json:"message"`
LastHeartbeat time.Time `json:"last_heartbeat"`
ErrorRate float64 `json:"error_rate"`
AvgLatencyMs int64 `json:"avg_latency_ms"`
Restarts int `json:"restarts"`
UptimeSeconds int64 `json:"uptime_seconds"`
}
PluginHealthDetail contains detailed health information.
type PluginQueries ¶
type PluginQueries interface {
ListPlugins(ctx context.Context) ([]Plugin, error)
GetPlugin(ctx context.Context, id string) (Plugin, error)
EnablePlugin(ctx context.Context, id string) error
DisablePlugin(ctx context.Context, id string) error
UpsertPlugin(ctx context.Context, p Plugin) error
DeletePlugin(ctx context.Context, id string) error
GetPluginSettings(ctx context.Context, id string) (string, error)
UpdatePluginSettings(ctx context.Context, id string, settings string) error
UpdatePluginSettingsSchema(ctx context.Context, id string, schema string) error
}
PluginQueries defines the database operations needed by the service. Implemented by both sqlc_sqlite.Queries and sqlc_postgres.Queries.
type PluginSettings ¶
type PluginSettings struct {
PluginID string `json:"plugin_id"`
Schema json.RawMessage `json:"schema"`
Values json.RawMessage `json:"values"`
}
PluginSettings contains the settings schema and current values for a plugin.
type PluginSource ¶
type PluginSource string
PluginSource indicates where a plugin came from.
const ( PluginSourceLocal PluginSource = "local" // Manually installed PluginSourceMarketplace PluginSource = "marketplace" // Installed from marketplace )
type PluginSummary ¶
type PluginSummary struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Author string `json:"author"`
Enabled bool `json:"enabled"`
IsBuiltin bool `json:"is_builtin"`
Health string `json:"health"` // "healthy", "degraded", "unhealthy", "unknown"
ProviderID string `json:"provider_id,omitempty"` // Provider ID if this is a provider plugin (e.g., "ollama")
Meta map[string]any `json:"meta,omitempty"` // x-viewra-meta from settings schema
// Settings availability
HasSettings bool `json:"has_settings"` // Whether this plugin has configurable settings
// Capabilities this plugin provides (e.g., "search", "embedding", "chat")
Capabilities []string `json:"capabilities,omitempty"`
// Dependencies this plugin requires but are not currently available
// Used to show warnings in the UI about missing capabilities
MissingDependencies []string `json:"missing_dependencies,omitempty"`
// DisplayCategory is the computed category for UI grouping
// Determined by: builtin → "Local", provider capability → "AI Providers",
// search capability → "Search", enricher category → "Enrichers", else "Other"
DisplayCategory string `json:"display_category"`
}
PluginSummary contains basic plugin information for list views.
type SchemaParser ¶
type SchemaParser struct{}
SchemaParser extracts metadata from JSON Schema definitions.
func NewSchemaParser ¶
func NewSchemaParser() *SchemaParser
NewSchemaParser creates a new SchemaParser.
func (*SchemaParser) GetSensitiveFields ¶
func (p *SchemaParser) GetSensitiveFields(schemaJSON json.RawMessage) map[string]bool
GetSensitiveFields returns a set of field names that are marked as sensitive. Sensitive fields are identified by having format: "password" in their schema.
func (*SchemaParser) IsSensitiveField ¶
func (p *SchemaParser) IsSensitiveField(schemaJSON json.RawMessage, fieldName string) bool
IsSensitiveField checks if a specific field is sensitive in the given schema.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides plugin management operations.
func NewService ¶
func NewService(queries PluginQueries, manager *infraplugins.Manager, bus *bus.Bus, logger *slog.Logger) *Service
NewService creates a new plugin service.
func (*Service) ApplyStoredSettings ¶
ApplyStoredSettings applies stored settings to all running plugins. This should be called after plugins are loaded to restore their configuration.
func (*Service) GetSettings ¶
GetSettings returns the settings schema and current values for a plugin. Sensitive fields are masked for display (not decrypted).
func (*Service) List ¶
func (s *Service) List(ctx context.Context) ([]PluginSummary, error)
List returns all plugins.
func (*Service) RegisterPlugin ¶
RegisterPlugin persists an external plugin to the database. This is called when external plugins are loaded at startup.
func (*Service) SetEncryptor ¶
SetEncryptor sets the encryptor for sensitive field encryption. If not set, sensitive fields will be stored in plaintext.
func (*Service) UpdateSettings ¶
UpdateSettings updates a plugin's settings.
type UpdateInfo ¶
type UpdateInfo struct {
PluginID string `json:"plugin_id"`
PluginName string `json:"plugin_name"`
InstalledVersion string `json:"installed_version"`
LatestVersion string `json:"latest_version"`
}
UpdateInfo describes an available update.
type UpdatesResponse ¶
type UpdatesResponse struct {
Updates []UpdateInfo `json:"updates"`
Count int `json:"count"`
}
UpdatesResponse is the response for checking updates.