plugins

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package plugins provides a dynamic plugin system for revoco.

This file handles embedding and extraction of default plugins that are bundled with the revoco binary and auto-extracted on first run.

Package plugins provides a dynamic plugin system for revoco.

This file handles plugin installation, removal, and updates from the plugin registry hosted on the GitHub plugins branch.

Package plugins provides a dynamic plugin system for revoco.

This file contains the integration layer that bridges the plugin system with revoco's existing connector, processor, and output registries.

Package plugins provides a dynamic plugin system for revoco.

The plugin system supports two tiers:

  • Lua plugins: Sandboxed, single-file plugins for most use cases
  • External plugins: Any language via JSON-RPC for complex integrations

Plugin types: Connector, Processor, Output

Index

Constants

View Source
const DefaultPluginsVersion = "2"

DefaultPluginsVersion is the version of the default plugins bundle. Increment this when default plugins are updated to trigger re-extraction.

View Source
const DefaultRegistryURL = "https://raw.githubusercontent.com/fulgidus/revoco/plugins"

DefaultRegistryURL is the default URL for the plugin registry.

View Source
const IndexCacheDuration = 15 * time.Minute

IndexCacheDuration is how long to cache the registry index.

Variables

View Source
var (
	ErrPluginNotFound      = errors.New("plugin not found")
	ErrPluginAlreadyLoaded = errors.New("plugin already loaded")
	ErrPluginLoadFailed    = errors.New("plugin load failed")
	ErrPluginDisabled      = errors.New("plugin is disabled")
	ErrPluginTypeMismatch  = errors.New("plugin type mismatch")
	ErrInvalidManifest     = errors.New("invalid plugin manifest")
	ErrMissingDependency   = errors.New("missing binary dependency")
	ErrRuntimeNotFound     = errors.New("runtime not found")
	ErrSelectorInvalid     = errors.New("invalid selector")
	ErrProcessingFailed    = errors.New("processing failed")
	ErrConnectionFailed    = errors.New("connection failed")
	ErrConfigInvalid       = errors.New("invalid configuration")
)

Common plugin errors.

View Source
var CommonRuntimes = map[string]ExternalRuntime{
	"python3": {
		Command:      "python3",
		MinVersion:   "3.8",
		VersionCheck: "python3 --version",
	},
	"python": {
		Command:      "python",
		MinVersion:   "3.8",
		VersionCheck: "python --version",
	},
	"node": {
		Command:      "node",
		MinVersion:   "16.0",
		VersionCheck: "node --version",
	},
	"ruby": {
		Command:      "ruby",
		MinVersion:   "2.7",
		VersionCheck: "ruby --version",
	},
	"go": {
		Command:      "go",
		MinVersion:   "1.20",
		VersionCheck: "go version",
	},
}

CommonRuntimes contains common runtime configurations.

Functions

func ApplyDefaults

func ApplyDefaults(schema []ConfigOption, settings map[string]any) map[string]any

ApplyDefaults applies default values to a settings map.

func ConfigPath

func ConfigPath() string

ConfigPath returns the default config file path.

func DefaultPluginDirs

func DefaultPluginDirs() []string

DefaultPluginDirs returns the default plugin directories.

func EnsurePluginDirs

func EnsurePluginDirs() error

EnsurePluginDirs creates the plugin directory structure if it doesn't exist.

func ExtractDefaultPlugins

func ExtractDefaultPlugins(destDir string) error

ExtractDefaultPlugins extracts bundled default plugins to the user's plugin directory. It only extracts if this is the first run (marker file doesn't exist) or if the plugin version has changed.

func ForceExtractDefaultPlugins

func ForceExtractDefaultPlugins(destDir string) error

ForceExtractDefaultPlugins extracts default plugins, overwriting existing files. Use with caution - this will overwrite any user modifications to default plugins.

func FormatInstallInstructions

func FormatInstallInstructions(dep BinaryDependency) string

FormatInstallInstructions returns human-readable installation instructions.

func GetDefaultPluginContent

func GetDefaultPluginContent(name string) ([]byte, error)

GetDefaultPluginContent returns the content of an embedded default plugin.

func GetInstallCommand

func GetInstallCommand(dep BinaryDependency) (string, string)

GetInstallCommand returns the install command for the current OS/package manager.

func InitializePlugins

func InitializePlugins(ctx context.Context, opts ...ManagerOption) error

InitializePlugins initializes the global plugin manager.

func InstallDependency

func InstallDependency(dep BinaryDependency) error

InstallDependency attempts to install a dependency.

func IsLuaError

func IsLuaError(err error) bool

IsLuaError checks if err is a Lua execution error.

func IsMissingDependency

func IsMissingDependency(err error) bool

IsMissingDependency checks if err is a missing dependency error.

func IsPluginError

func IsPluginError(err error, pluginID string) bool

IsPluginError checks if err is a PluginError for the given plugin.

func IsRPCError

func IsRPCError(err error) bool

IsRPCError checks if err is an RPC call error.

func ListDefaultPlugins

func ListDefaultPlugins() ([]string, error)

ListDefaultPlugins returns information about the embedded default plugins.

func RegisterExternalPluginFactory

func RegisterExternalPluginFactory(factory PluginFactory)

RegisterExternalPluginFactory registers the external plugin factory. This is called by the external package during initialization.

func RegisterLuaPluginFactory

func RegisterLuaPluginFactory(factory PluginFactory)

RegisterLuaPluginFactory registers the Lua plugin factory. This is called by the lua package during initialization.

func RegisterPlugin

func RegisterPlugin(p Plugin) error

Register registers a plugin with the global registry.

func ResetDefaultPlugins

func ResetDefaultPlugins(destDir string) error

ResetDefaultPlugins removes the marker file, causing defaults to be re-extracted on next run. Existing plugins are NOT removed.

func SaveConfig

func SaveConfig(cfg *Config) error

SaveConfig saves the plugin configuration to the default path.

func SaveConfigTo

func SaveConfigTo(cfg *Config, path string) error

SaveConfigTo saves the plugin configuration to a specific path.

func ShutdownPlugins

func ShutdownPlugins() error

ShutdownPlugins shuts down the global plugin manager.

func ValidatePluginConfig

func ValidatePluginConfig(plugin Plugin, settings map[string]any) error

ValidatePluginConfig validates configuration for a specific plugin.

Types

type BinaryDependency

type BinaryDependency struct {
	Binary       string            `json:"binary"`        // Binary name (e.g., "ffmpeg")
	Check        string            `json:"check"`         // Command to verify (e.g., "ffmpeg -version")
	VersionRegex string            `json:"version_regex"` // Regex to extract version
	MinVersion   string            `json:"min_version"`   // Minimum required version
	Install      map[string]string `json:"install"`       // Package manager -> install command

	// Runtime state (not serialized)
	Found   bool   `json:"-"`
	Version string `json:"-"`
}

BinaryDependency describes an external binary required by a plugin.

type Config

type Config struct {
	// Plugin directories to scan
	PluginDirs []string `json:"plugin_dirs,omitempty"`

	// Disabled plugins (by ID)
	Disabled []string `json:"disabled,omitempty"`

	// Plugin-specific settings
	PluginSettings map[string]map[string]any `json:"plugin_settings,omitempty"`

	// Hot-reload enabled
	HotReload bool `json:"hot_reload,omitempty"`
}

Config holds the plugin system configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default plugin configuration.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads the plugin configuration from the default path.

func LoadConfigFrom

func LoadConfigFrom(path string) (*Config, error)

LoadConfigFrom loads the plugin configuration from a specific path.

func (*Config) Disable

func (c *Config) Disable(pluginID string)

Disable disables a plugin.

func (*Config) Enable

func (c *Config) Enable(pluginID string)

Enable enables a previously disabled plugin.

func (*Config) GetPluginSetting

func (c *Config) GetPluginSetting(pluginID, key string) (any, bool)

GetPluginSetting returns a specific setting for a plugin.

func (*Config) GetPluginSettings

func (c *Config) GetPluginSettings(pluginID string) map[string]any

GetPluginSettings returns settings for a specific plugin.

func (*Config) IsDisabled

func (c *Config) IsDisabled(pluginID string) bool

IsDisabled checks if a plugin is disabled.

func (*Config) SetPluginSetting

func (c *Config) SetPluginSetting(pluginID, key string, value any)

SetPluginSetting sets a specific setting for a plugin.

func (*Config) SetPluginSettings

func (c *Config) SetPluginSettings(pluginID string, settings map[string]any)

SetPluginSettings sets settings for a specific plugin.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

type ConfigError

type ConfigError struct {
	PluginID string
	Field    string
	Reason   string
}

ConfigError represents a configuration validation error.

func (*ConfigError) Error

func (e *ConfigError) Error() string

type ConfigOption

type ConfigOption struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Type        string   `json:"type"` // bool, string, int, float, select, path, password
	Default     any      `json:"default,omitempty"`
	Options     []string `json:"options,omitempty"` // For select type
	Required    bool     `json:"required,omitempty"`
	Sensitive   bool     `json:"sensitive,omitempty"` // If true, mask in UI
}

ConfigOption describes a configurable setting for a plugin.

type ConnectorPlugin

type ConnectorPlugin interface {
	Plugin

	// AsConnector returns the base connector interface.
	AsConnector() core.Connector

	// AsReader returns the reader interface if supported.
	AsReader() (core.ConnectorReader, bool)

	// AsWriter returns the writer interface if supported.
	AsWriter() (core.ConnectorWriter, bool)

	// AsTester returns the tester interface if supported.
	AsTester() (core.ConnectorTester, bool)
}

ConnectorPlugin wraps a dynamically-loaded connector.

func GetConnectorPlugin

func GetConnectorPlugin(id string) (ConnectorPlugin, bool)

GetConnectorPlugin returns a connector plugin from the global registry.

type DependencyChecker

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

DependencyChecker verifies binary dependencies for plugins.

func NewDependencyChecker

func NewDependencyChecker() *DependencyChecker

NewDependencyChecker creates a new dependency checker.

func (*DependencyChecker) AllSatisfied

func (c *DependencyChecker) AllSatisfied(deps []BinaryDependency) bool

AllSatisfied returns true if all dependencies are satisfied.

func (*DependencyChecker) Check

Check verifies a single dependency.

func (*DependencyChecker) CheckAll

func (c *DependencyChecker) CheckAll(deps []BinaryDependency) []*DependencyStatus

CheckAll verifies all dependencies for a plugin.

func (*DependencyChecker) ClearCache

func (c *DependencyChecker) ClearCache()

ClearCache clears the dependency cache.

func (*DependencyChecker) MissingDependencies

func (c *DependencyChecker) MissingDependencies(deps []BinaryDependency) []BinaryDependency

MissingDependencies returns all unsatisfied dependencies.

type DependencyError

type DependencyError struct {
	Binary  string
	Message string
	Install map[string]string
}

DependencyError wraps an error with dependency context.

func (*DependencyError) Error

func (e *DependencyError) Error() string

type DependencyStatus

type DependencyStatus struct {
	Binary    string
	Found     bool
	Path      string
	Version   string
	MeetsMin  bool
	MinNeeded string
	Error     string
}

DependencyStatus holds the status of a binary dependency.

func CheckRuntime

func CheckRuntime(rt ExternalRuntime) *DependencyStatus

CheckRuntime verifies that a runtime is available.

type DiscoveredPlugin

type DiscoveredPlugin struct {
	Path     string
	Type     PluginType
	Tier     PluginTier
	Info     *PluginInfo
	Manifest *ExternalManifest
	Source   PluginSource
	Error    string
}

DiscoveredPlugin represents a plugin found during discovery.

type ExternalManifest

type ExternalManifest struct {
	APIVersion string               `json:"apiVersion"` // e.g., "revoco/v1"
	Kind       string               `json:"kind"`       // "ExternalPlugin"
	Metadata   ExternalManifestMeta `json:"metadata"`
	Spec       ExternalManifestSpec `json:"spec"`
}

ExternalManifest is the manifest.json structure for external plugins.

type ExternalManifestMeta

type ExternalManifestMeta struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Version     string `json:"version"`
	Author      string `json:"author,omitempty"`
}

ExternalManifestMeta contains plugin identity information.

type ExternalManifestSpec

type ExternalManifestSpec struct {
	Type            PluginType         `json:"type"` // connector, processor, output
	Runtime         ExternalRuntime    `json:"runtime"`
	Entrypoint      string             `json:"entrypoint"`
	Setup           *ExternalSetup     `json:"setup,omitempty"`
	Capabilities    []string           `json:"capabilities,omitempty"`
	DataTypes       []string           `json:"dataTypes,omitempty"`
	RequiresAuth    bool               `json:"requiresAuth,omitempty"`
	AuthType        string             `json:"authType,omitempty"`
	ConfigSchema    []ConfigOption     `json:"configSchema,omitempty"`
	DefaultSelector *Selector          `json:"defaultSelector,omitempty"`
	Dependencies    []BinaryDependency `json:"dependencies,omitempty"`
}

ExternalManifestSpec contains plugin specification.

type ExternalRuntime

type ExternalRuntime struct {
	Command      string `json:"command"`      // e.g., "python3"
	MinVersion   string `json:"minVersion"`   // e.g., "3.9"
	VersionCheck string `json:"versionCheck"` // e.g., "python3 --version"
}

ExternalRuntime describes the runtime requirements.

type ExternalSetup

type ExternalSetup struct {
	Command string `json:"command"` // e.g., "pip install -r requirements.txt"
	RunWhen string `json:"runWhen"` // File to check for changes (e.g., "requirements.txt")
}

ExternalSetup describes setup requirements.

type InstalledPlugin

type InstalledPlugin struct {
	Entry       RegistryEntry `json:"entry"`
	InstalledAt time.Time     `json:"installed_at"`
	UpdatedAt   time.Time     `json:"updated_at"`
	Source      string        `json:"source"` // "registry", "local", "url"
	SourcePath  string        `json:"source_path"`
	LocalPath   string        `json:"local_path"`
}

InstalledPlugin represents a locally installed plugin.

type InstalledPluginsDB

type InstalledPluginsDB struct {
	Version   string                     `json:"version"`
	Plugins   map[string]InstalledPlugin `json:"plugins"`
	UpdatedAt time.Time                  `json:"updated_at"`
}

InstalledPluginsDB tracks installed plugins.

type Installer

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

Installer handles plugin installation and management.

func NewInstaller

func NewInstaller(opts ...InstallerOption) *Installer

NewInstaller creates a new plugin installer.

func (*Installer) CheckUpdates

func (i *Installer) CheckUpdates(ctx context.Context) ([]PluginUpdate, error)

CheckUpdates checks for available plugin updates.

func (*Installer) FetchIndex

func (i *Installer) FetchIndex(ctx context.Context) (*RegistryIndex, error)

FetchIndex fetches the plugin registry index.

func (*Installer) GetEntry

func (i *Installer) GetEntry(ctx context.Context, id string) (*RegistryEntry, error)

GetEntry returns a specific plugin entry from the registry.

func (*Installer) GetInstalled

func (i *Installer) GetInstalled(id string) (*InstalledPlugin, error)

GetInstalled returns information about an installed plugin.

func (*Installer) Install

func (i *Installer) Install(ctx context.Context, id string) error

Install installs a plugin by ID from the registry.

func (*Installer) InstallFromPath

func (i *Installer) InstallFromPath(ctx context.Context, path string) error

InstallFromPath installs a plugin from a local path.

func (*Installer) InstallFromURL

func (i *Installer) InstallFromURL(ctx context.Context, url string) error

InstallFromURL installs a plugin from a URL.

func (*Installer) ListInstalled

func (i *Installer) ListInstalled() ([]InstalledPlugin, error)

ListInstalled returns all installed plugins.

func (*Installer) Remove

func (i *Installer) Remove(ctx context.Context, id string) error

Remove removes an installed plugin.

func (*Installer) Search

func (i *Installer) Search(ctx context.Context, query string) ([]RegistryEntry, error)

Search searches the plugin registry.

func (*Installer) Update

func (i *Installer) Update(ctx context.Context, id string) error

Update updates a specific plugin to the latest version.

func (*Installer) UpdateAll

func (i *Installer) UpdateAll(ctx context.Context) ([]string, error)

UpdateAll updates all plugins from the registry.

type InstallerOption

type InstallerOption func(*Installer)

InstallerOption configures the installer.

func WithCacheDir

func WithCacheDir(dir string) InstallerOption

WithCacheDir sets a custom cache directory.

func WithPluginDir

func WithPluginDir(dir string) InstallerOption

WithPluginDir sets a custom plugin directory.

func WithRegistryURL

func WithRegistryURL(url string) InstallerOption

WithRegistryURL sets a custom registry URL.

type Loader

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

Loader discovers and loads plugins from directories.

func NewLoader

func NewLoader(registry *Registry, dirs ...string) *Loader

NewLoader creates a new plugin loader.

func (*Loader) Discover

func (l *Loader) Discover(dir string) ([]*DiscoveredPlugin, error)

Discover scans a directory for plugins.

func (*Loader) DiscoverAll

func (l *Loader) DiscoverAll() ([]*DiscoveredPlugin, error)

DiscoverAll scans all plugin directories and returns discovered plugins.

func (*Loader) LoadAll

func (l *Loader) LoadAll(ctx context.Context) error

LoadAll loads all discovered plugins into the registry.

func (*Loader) Watch

func (l *Loader) Watch(ctx context.Context, onChange func(path string, op WatchOp)) error

Watch starts watching plugin directories for changes (hot-reload).

type LuaError

type LuaError struct {
	PluginID string
	Function string
	Message  string
}

LuaError wraps an error from Lua execution.

func (*LuaError) Error

func (e *LuaError) Error() string

type LuaPluginMeta

type LuaPluginMeta struct {
	ID           string   `lua:"id"`
	Name         string   `lua:"name"`
	Description  string   `lua:"description"`
	Version      string   `lua:"version"`
	Type         string   `lua:"type"` // connector, processor, output
	Capabilities []string `lua:"capabilities,omitempty"`
	DataTypes    []string `lua:"data_types,omitempty"`
	RequiresAuth bool     `lua:"requires_auth,omitempty"`
	AuthType     string   `lua:"auth_type,omitempty"`
}

LuaPluginMeta represents the Plugin table in a Lua plugin.

type Manager

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

Manager handles plugin discovery, loading, and integration with revoco.

func NewManager

func NewManager(opts ...ManagerOption) *Manager

NewManager creates a new plugin manager.

func PluginManager

func PluginManager() *Manager

PluginManager returns the global plugin manager.

func (*Manager) CheckDependencies

func (m *Manager) CheckDependencies() []*DependencyStatus

CheckDependencies checks binary dependencies for all plugins.

func (*Manager) GetApplicableProcessors

func (m *Manager) GetApplicableProcessors(item *core.DataItem) []Processor

GetApplicableProcessors returns all processors that can handle the given item.

func (*Manager) GetConnector

func (m *Manager) GetConnector(id string) (core.Connector, bool)

GetConnector returns a connector by ID (checks both plugins and built-in).

func (*Manager) GetOutput

func (m *Manager) GetOutput(id string) (svccore.Output, bool)

GetOutput returns an output by ID (checks both plugins and built-in).

func (*Manager) GetProcessor

func (m *Manager) GetProcessor(id string) (Processor, bool)

GetProcessor returns a processor plugin by ID.

func (*Manager) Initialize

func (m *Manager) Initialize(ctx context.Context) error

Initialize discovers and loads all plugins. This method is idempotent - calling it multiple times is safe.

func (*Manager) ListPlugins

func (m *Manager) ListPlugins() []PluginInfo

ListPlugins returns information about all loaded plugins.

func (*Manager) Registry

func (m *Manager) Registry() *Registry

Registry returns the plugin registry.

func (*Manager) ReloadPlugin

func (m *Manager) ReloadPlugin(ctx context.Context, id string) error

ReloadPlugin reloads a specific plugin by ID.

func (*Manager) Shutdown

func (m *Manager) Shutdown() error

Shutdown stops all plugins and releases resources.

type ManagerOption

type ManagerOption func(*Manager)

ManagerOption configures the plugin manager.

func WithHotReload

func WithHotReload(enabled bool) ManagerOption

WithHotReload enables or disables hot-reload for Lua plugins.

func WithLogLevel

func WithLogLevel(level string) ManagerOption

WithLogLevel sets the log level for plugin operations.

func WithPluginDirs

func WithPluginDirs(dirs ...string) ManagerOption

WithPluginDirs sets the directories to search for plugins.

type ManifestError

type ManifestError struct {
	Path   string
	Field  string
	Reason string
}

ManifestError wraps an error in manifest parsing/validation.

func (*ManifestError) Error

func (e *ManifestError) Error() string

type OutputPlugin

type OutputPlugin interface {
	Plugin

	// AsOutput returns the output interface.
	AsOutput() svccore.Output

	// Selector returns the default selector for this output.
	Selector() *Selector
}

OutputPlugin wraps a dynamically-loaded output.

func GetOutputPlugin

func GetOutputPlugin(id string) (OutputPlugin, bool)

GetOutputPlugin returns an output plugin from the global registry.

type Plugin

type Plugin interface {
	// Info returns the plugin metadata.
	Info() PluginInfo

	// Load initializes the plugin. Called once when discovered.
	Load(ctx context.Context) error

	// Unload releases any resources held by the plugin.
	Unload() error

	// Reload reloads the plugin (for hot-reload support).
	Reload(ctx context.Context) error
}

Plugin is the base interface for all plugins.

func GetPlugin

func GetPlugin(id string) (Plugin, bool)

GetPlugin returns a plugin from the global registry.

type PluginConfig

type PluginConfig struct {
	PluginID string         `json:"plugin_id"`
	Enabled  bool           `json:"enabled"`
	Settings map[string]any `json:"settings"`
	Selector *Selector      `json:"selector,omitempty"`
}

PluginConfig holds configuration for a plugin instance.

type PluginError

type PluginError struct {
	PluginID string
	Op       string // Operation that failed
	Err      error
}

PluginError wraps an error with plugin context.

func NewPluginError

func NewPluginError(pluginID, op string, err error) *PluginError

NewPluginError creates a new PluginError.

func (*PluginError) Error

func (e *PluginError) Error() string

func (*PluginError) Unwrap

func (e *PluginError) Unwrap() error

type PluginFactory

type PluginFactory func(dp *DiscoveredPlugin) (Plugin, error)

PluginFactory creates a Plugin from discovered metadata.

type PluginInfo

type PluginInfo struct {
	// Identity
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Version     string `json:"version"`
	Author      string `json:"author,omitempty"`

	// Classification
	Type   PluginType   `json:"type"`
	Tier   PluginTier   `json:"tier"`
	Source PluginSource `json:"source"`

	// Location
	Path string `json:"path"` // File path or directory

	// State
	State      PluginState `json:"state"`
	StateError string      `json:"state_error,omitempty"`

	// Capabilities (for connectors)
	Capabilities []core.ConnectorCapability `json:"capabilities,omitempty"`
	DataTypes    []core.DataType            `json:"data_types,omitempty"`
	RequiresAuth bool                       `json:"requires_auth,omitempty"`
	AuthType     string                     `json:"auth_type,omitempty"`

	// Configuration
	ConfigSchema []ConfigOption `json:"config_schema,omitempty"`

	// Dependencies
	Dependencies []BinaryDependency `json:"dependencies,omitempty"`

	// Default selector (for processors and outputs)
	DefaultSelector *Selector `json:"default_selector,omitempty"`
}

PluginInfo contains metadata about a plugin.

type PluginReader

type PluginReader struct {
	io.ReadCloser
	Plugin Plugin
	Item   *core.DataItem
}

PluginReader wraps io.ReadCloser with plugin context.

type PluginSource

type PluginSource string

PluginSource identifies where the plugin came from.

const (
	PluginSourceBuiltIn   PluginSource = "builtin"   // Shipped with revoco
	PluginSourceUser      PluginSource = "user"      // User's plugin directory
	PluginSourceCommunity PluginSource = "community" // Future: community repository
)

type PluginState

type PluginState string

PluginState represents the current state of a plugin.

const (
	PluginStateUnloaded    PluginState = "unloaded"     // Not yet loaded
	PluginStateLoading     PluginState = "loading"      // Currently loading
	PluginStateReady       PluginState = "ready"        // Loaded and ready
	PluginStateMissingDeps PluginState = "missing_deps" // Missing binary dependencies
	PluginStateError       PluginState = "error"        // Failed to load
	PluginStateDisabled    PluginState = "disabled"     // Disabled by user
)

type PluginTier

type PluginTier string

PluginTier identifies how the plugin is executed.

const (
	PluginTierLua      PluginTier = "lua"      // Embedded Lua interpreter
	PluginTierExternal PluginTier = "external" // External process via JSON-RPC
)

type PluginType

type PluginType string

PluginType identifies the kind of plugin.

const (
	PluginTypeConnector PluginType = "connector"
	PluginTypeProcessor PluginType = "processor"
	PluginTypeOutput    PluginType = "output"
)

type PluginUpdate

type PluginUpdate struct {
	ID             string
	CurrentVersion string
	LatestVersion  string
	Entry          RegistryEntry
}

PluginUpdate represents an available plugin update.

type Processor

type Processor interface {
	// Identity
	ID() string
	Name() string
	Description() string

	// Configuration
	ConfigSchema() []ConfigOption

	// Selector
	DefaultSelector() *Selector

	// Processing
	CanProcess(item *core.DataItem) bool
	Process(ctx context.Context, item *core.DataItem, config map[string]any) (*core.DataItem, error)
	ProcessBatch(ctx context.Context, items []*core.DataItem, config map[string]any, progress ProgressFunc) ([]*core.DataItem, error)
}

Processor is the interface for data processors. This extends the service-level processor with plugin-specific features.

type ProcessorPlugin

type ProcessorPlugin interface {
	Plugin

	// AsProcessor returns the processor interface.
	AsProcessor() Processor

	// Selector returns the default selector for this processor.
	Selector() *Selector
}

ProcessorPlugin wraps a dynamically-loaded processor.

func GetProcessorPlugin

func GetProcessorPlugin(id string) (ProcessorPlugin, bool)

GetProcessorPlugin returns a processor plugin from the global registry.

type ProgressFunc

type ProgressFunc func(done, total int, message string)

ProgressFunc reports progress during processing.

type RPCCallError

type RPCCallError struct {
	PluginID string
	Method   string
	Code     int
	Message  string
}

RPCCallError wraps an error from an external plugin RPC call.

func (*RPCCallError) Error

func (e *RPCCallError) Error() string

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

RPCError is a JSON-RPC 2.0 error.

type RPCRequest

type RPCRequest struct {
	JSONRPC string         `json:"jsonrpc"`
	ID      int            `json:"id,omitempty"`
	Method  string         `json:"method"`
	Params  map[string]any `json:"params,omitempty"`
}

RPCRequest is a JSON-RPC 2.0 request.

type RPCResponse

type RPCResponse struct {
	JSONRPC string    `json:"jsonrpc"`
	ID      int       `json:"id,omitempty"`
	Result  any       `json:"result,omitempty"`
	Error   *RPCError `json:"error,omitempty"`
}

RPCResponse is a JSON-RPC 2.0 response.

type Registry

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

Registry manages all loaded plugins.

func Global

func Global() *Registry

Global returns the global plugin registry.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new plugin registry.

func (*Registry) All

func (r *Registry) All() []Plugin

All returns all plugins in registration order.

func (*Registry) Connectors

func (r *Registry) Connectors() []ConnectorPlugin

Connectors returns all connector plugins.

func (*Registry) ConnectorsByCapability

func (r *Registry) ConnectorsByCapability(cap string) []ConnectorPlugin

ConnectorsByCapability returns connectors with the given capability.

func (*Registry) Get

func (r *Registry) Get(id string) (Plugin, bool)

Get returns a plugin by ID.

func (*Registry) GetConnector

func (r *Registry) GetConnector(id string) (ConnectorPlugin, bool)

GetConnector returns a connector plugin by ID.

func (*Registry) GetOutput

func (r *Registry) GetOutput(id string) (OutputPlugin, bool)

GetOutput returns an output plugin by ID.

func (*Registry) GetProcessor

func (r *Registry) GetProcessor(id string) (ProcessorPlugin, bool)

GetProcessor returns a processor plugin by ID.

func (*Registry) LoadAll

func (r *Registry) LoadAll(ctx context.Context) error

LoadAll loads all registered plugins.

func (*Registry) OnLoad

func (r *Registry) OnLoad(cb func(Plugin))

OnLoad registers a callback for when a plugin is loaded.

func (*Registry) OnReload

func (r *Registry) OnReload(cb func(Plugin))

OnReload registers a callback for when a plugin is reloaded.

func (*Registry) OnUnload

func (r *Registry) OnUnload(cb func(Plugin))

OnUnload registers a callback for when a plugin is unloaded.

func (*Registry) Outputs

func (r *Registry) Outputs() []OutputPlugin

Outputs returns all output plugins.

func (*Registry) PluginsByState

func (r *Registry) PluginsByState(state PluginState) []Plugin

PluginsByState returns plugins in the given state.

func (*Registry) PluginsByTier

func (r *Registry) PluginsByTier(tier PluginTier) []Plugin

PluginsByTier returns plugins of the given tier.

func (*Registry) Processors

func (r *Registry) Processors() []ProcessorPlugin

Processors returns all processor plugins.

func (*Registry) ProcessorsByDataType

func (r *Registry) ProcessorsByDataType(dt string) []ProcessorPlugin

ProcessorsByDataType returns processors that handle the given data type.

func (*Registry) Register

func (r *Registry) Register(p Plugin) error

Register adds a plugin to the registry.

func (*Registry) Reload

func (r *Registry) Reload(ctx context.Context, id string) error

Reload reloads a specific plugin.

func (*Registry) Stats

func (r *Registry) Stats() RegistryStats

Stats returns registry statistics.

func (*Registry) UnloadAll

func (r *Registry) UnloadAll() error

UnloadAll unloads all registered plugins.

func (*Registry) Unregister

func (r *Registry) Unregister(id string) error

Unregister removes a plugin from the registry.

type RegistryEntry

type RegistryEntry struct {
	ID          string            `json:"id"`
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Author      string            `json:"author"`
	Version     string            `json:"version"`
	Type        PluginType        `json:"type"`
	Tier        PluginTier        `json:"tier"`
	Tags        []string          `json:"tags,omitempty"`
	Homepage    string            `json:"homepage,omitempty"`
	Repository  string            `json:"repository,omitempty"`
	License     string            `json:"license,omitempty"`
	Downloads   int               `json:"downloads,omitempty"`
	Path        string            `json:"path"` // Path within the plugins branch
	Checksum    string            `json:"checksum,omitempty"`
	Platforms   []string          `json:"platforms,omitempty"`   // e.g., ["linux", "darwin", "windows"]
	MinVersion  string            `json:"min_version,omitempty"` // Minimum revoco version
	Deprecated  bool              `json:"deprecated,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

RegistryEntry represents a plugin entry in the registry.

type RegistryIndex

type RegistryIndex struct {
	Version     string                   `json:"version"`
	LastUpdated time.Time                `json:"last_updated"`
	Plugins     map[string]RegistryEntry `json:"plugins"`
}

RegistryIndex represents the plugin registry index.json file.

type RegistryStats

type RegistryStats struct {
	Total      int
	Connectors int
	Processors int
	Outputs    int
	ByTier     map[PluginTier]int
	ByState    map[PluginState]int
}

RegistryStats contains registry statistics.

type Selector

type Selector struct {
	// By data type
	DataTypes []core.DataType `json:"data_types,omitempty" yaml:"data_types,omitempty"`

	// By file extension (e.g., ".jpg", ".png")
	Extensions []string `json:"extensions,omitempty" yaml:"extensions,omitempty"`

	// By MIME type (supports wildcards like "image/*")
	MimeTypes []string `json:"mime_types,omitempty" yaml:"mime_types,omitempty"`

	// By source connector ID
	SourceConnectors []string `json:"source_connectors,omitempty" yaml:"source_connectors,omitempty"`

	// By path pattern (glob)
	PathMatch   string `json:"path_match,omitempty" yaml:"path_match,omitempty"`
	PathExclude string `json:"path_exclude,omitempty" yaml:"path_exclude,omitempty"`

	// By metadata condition (Lua expression evaluated at runtime)
	Condition string `json:"condition,omitempty" yaml:"condition,omitempty"`

	// Chain from another job's output
	From string `json:"from,omitempty" yaml:"from,omitempty"`

	// Select all items (overrides other filters)
	All bool `json:"all,omitempty" yaml:"all,omitempty"`
}

Selector defines criteria for matching data items. Selectors can filter items by type, extension, path, metadata, etc.

func MergeSelectors

func MergeSelectors(selectors ...*Selector) *Selector

MergeSelectors merges multiple selectors into one. Later selectors override earlier ones for non-slice fields.

func (*Selector) Clone

func (s *Selector) Clone() *Selector

Clone creates a deep copy of the selector.

func (*Selector) IsEmpty

func (s *Selector) IsEmpty() bool

IsEmpty returns true if the selector has no criteria set.

type SelectorError

type SelectorError struct {
	Field string
	Err   error
}

SelectorError wraps an error with selector field context.

func (*SelectorError) Error

func (e *SelectorError) Error() string

func (*SelectorError) Unwrap

func (e *SelectorError) Unwrap() error

type SelectorMatcher

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

SelectorMatcher provides methods to match items against a selector.

func NewSelectorMatcher

func NewSelectorMatcher(s *Selector) (*SelectorMatcher, error)

NewSelectorMatcher creates a new matcher for the given selector.

func (*SelectorMatcher) Match

func (m *SelectorMatcher) Match(item *core.DataItem) bool

Match checks if an item matches the selector criteria. Note: Condition evaluation requires Lua runtime and is handled separately.

func (*SelectorMatcher) MatchWithCondition

func (m *SelectorMatcher) MatchWithCondition(item *core.DataItem, conditionEvaluator func(item *core.DataItem, condition string) (bool, error)) (bool, error)

MatchWithCondition checks if an item matches, including Lua condition evaluation. The conditionEvaluator is a function that evaluates the Lua condition.

type WatchOp

type WatchOp int

WatchOp represents a file system change operation.

const (
	WatchOpCreate WatchOp = iota
	WatchOpModify
	WatchOpDelete
)

Directories

Path Synopsis
Package external provides the external plugin runtime for revoco.
Package external provides the external plugin runtime for revoco.
Package lua provides the Lua runtime for revoco plugins.
Package lua provides the Lua runtime for revoco plugins.
Package pipeline provides the pipeline engine for revoco.
Package pipeline provides the pipeline engine for revoco.

Jump to

Keyboard shortcuts

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