plugins

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package plugins provides a plugin registry for extending AgentFlow.

It defines the Plugin interface for lifecycle management (Init/Shutdown) and the PluginRegistry interface for registration, discovery, and search. InMemoryPluginRegistry is the default thread-safe implementation.

Usage:

registry := plugins.NewInMemoryPluginRegistry(logger)
registry.Register(myPlugin, plugins.PluginMetadata{Name: "my-plugin", Version: "1.0.0"})
registry.InitAll(ctx)
defer registry.ShutdownAll(ctx)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPluginAlreadyRegistered = errors.New("plugin already registered")
	ErrPluginNotFound          = errors.New("plugin not found")
)

Sentinel errors for the plugin registry.

Functions

This section is empty.

Types

type InMemoryPluginRegistry

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

InMemoryPluginRegistry is a thread-safe in-memory implementation of PluginRegistry.

func NewInMemoryPluginRegistry

func NewInMemoryPluginRegistry(logger *zap.Logger) *InMemoryPluginRegistry

NewInMemoryPluginRegistry creates a new InMemoryPluginRegistry.

func (*InMemoryPluginRegistry) Get

func (r *InMemoryPluginRegistry) Get(name string) (*PluginInfo, bool)

Get returns plugin info by name.

func (*InMemoryPluginRegistry) Init

func (r *InMemoryPluginRegistry) Init(ctx context.Context, name string) error

Init initializes a single plugin by name.

func (*InMemoryPluginRegistry) InitAll

func (r *InMemoryPluginRegistry) InitAll(ctx context.Context) error

InitAll initializes all plugins in the Registered state. Errors from individual plugins are logged but do not stop the batch.

func (*InMemoryPluginRegistry) List

func (r *InMemoryPluginRegistry) List() []*PluginInfo

List returns all plugins sorted by name.

func (*InMemoryPluginRegistry) Register

func (r *InMemoryPluginRegistry) Register(plugin Plugin, metadata PluginMetadata) error

Register adds a plugin to the registry in the Registered state.

func (*InMemoryPluginRegistry) Search

func (r *InMemoryPluginRegistry) Search(tags []string) []*PluginInfo

Search returns plugins that match any of the provided tags.

func (*InMemoryPluginRegistry) ShutdownAll

func (r *InMemoryPluginRegistry) ShutdownAll(ctx context.Context) error

ShutdownAll shuts down all plugins in the Initialized state. Errors from individual plugins are logged but do not stop the batch.

func (*InMemoryPluginRegistry) Unregister

func (r *InMemoryPluginRegistry) Unregister(ctx context.Context, name string) error

Unregister removes a plugin. If it was initialized, Shutdown is called first.

type MetadataProvider

type MetadataProvider interface {
	Metadata() PluginMetadata
}

MetadataProvider is an optional interface that plugins can implement to supply their own metadata. When a plugin implements this interface, callers can use ExtractMetadata to obtain metadata without requiring it to be passed separately.

type Plugin

type Plugin interface {
	// Name returns the unique plugin name.
	Name() string
	// Version returns the plugin version string.
	Version() string
	// Init initializes the plugin. Called after registration.
	Init(ctx context.Context) error
	// Shutdown gracefully shuts down the plugin.
	Shutdown(ctx context.Context) error
}

Plugin defines a pluggable extension point for AgentFlow.

type PluginInfo

type PluginInfo struct {
	Plugin   Plugin         `json:"-"`
	Metadata PluginMetadata `json:"metadata"`
	State    PluginState    `json:"state"`
}

PluginInfo bundles a plugin instance with its metadata and current state.

type PluginManager

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

PluginManager provides a convenience layer over PluginRegistry for managing the full lifecycle of plugins: registration, initialization, and shutdown. It is the recommended entry point for applications that need to wire up plugins at startup and tear them down on exit.

func NewPluginManager

func NewPluginManager(registry PluginRegistry, logger *zap.Logger) *PluginManager

NewPluginManager creates a PluginManager backed by the given registry.

func (*PluginManager) InitAll

func (m *PluginManager) InitAll(ctx context.Context) error

InitAll initializes all registered plugins via the underlying registry.

func (*PluginManager) Register

func (m *PluginManager) Register(plugin Plugin) error

Register adds a plugin to the underlying registry. If the plugin implements MetadataProvider, its metadata is used automatically; otherwise a minimal metadata is derived from Name() and Version().

func (*PluginManager) RegisterWithMetadata

func (m *PluginManager) RegisterWithMetadata(plugin Plugin, meta PluginMetadata) error

RegisterWithMetadata adds a plugin with explicit metadata.

func (*PluginManager) Registry

func (m *PluginManager) Registry() PluginRegistry

Registry returns the underlying PluginRegistry.

func (*PluginManager) ShutdownAll

func (m *PluginManager) ShutdownAll(ctx context.Context) error

ShutdownAll shuts down all initialized plugins via the underlying registry.

type PluginMetadata

type PluginMetadata struct {
	Name        string            `json:"name"`
	Version     string            `json:"version"`
	Description string            `json:"description,omitempty"`
	Author      string            `json:"author,omitempty"`
	Tags        []string          `json:"tags,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

PluginMetadata holds descriptive information about a plugin.

func ExtractMetadata

func ExtractMetadata(p Plugin) PluginMetadata

ExtractMetadata returns metadata from a plugin. If the plugin implements MetadataProvider, its Metadata method is called. Otherwise, a minimal PluginMetadata is constructed from Name() and Version().

type PluginRegistry

type PluginRegistry interface {
	// Register adds a plugin without initializing it.
	Register(plugin Plugin, metadata PluginMetadata) error
	// Unregister removes a plugin, calling Shutdown first if initialized.
	Unregister(ctx context.Context, name string) error
	// Get returns plugin info by name.
	Get(name string) (*PluginInfo, bool)
	// List returns all plugins sorted by name.
	List() []*PluginInfo
	// Search returns plugins matching any of the given tags.
	Search(tags []string) []*PluginInfo
	// Init initializes a single plugin by name.
	Init(ctx context.Context, name string) error
	// InitAll initializes all registered-but-not-yet-initialized plugins.
	InitAll(ctx context.Context) error
	// ShutdownAll shuts down all initialized plugins.
	ShutdownAll(ctx context.Context) error
}

PluginRegistry defines the interface for managing plugins.

type PluginState

type PluginState string

PluginState represents the lifecycle state of a plugin.

const (
	PluginStateRegistered  PluginState = "registered"
	PluginStateInitialized PluginState = "initialized"
	PluginStateFailed      PluginState = "failed"
	PluginStateShutdown    PluginState = "shutdown"
)

Jump to

Keyboard shortcuts

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