plugin

package
v0.0.0-...-8155ea7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: GPL-2.0, GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadBuiltin

func LoadBuiltin()

LoadBuiltin ensures all builtin plugins are registered. Plugin registration happens via init() when plugin packages are imported. The gateway (cmd/moonhub/internal/gateway/helpers.go) imports all plugin packages to trigger registration:

  • Channel plugins: pkg/plugins/channels/*
  • Provider plugins: pkg/plugins/providers/*
  • Tool plugins: pkg/plugins/tools/*

This function is a no-op kept for API compatibility.

func RegisterPlugin

func RegisterPlugin(p Plugin)

RegisterPlugin is a convenience function for the global registry

Types

type Channel

type Channel interface {
	Name() string
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Send(ctx context.Context, msg bus.OutboundMessage) error
	IsRunning() bool
}

Channel is the interface for messaging channels Defined here to avoid circular imports

type ChannelPlugin

type ChannelPlugin interface {
	Plugin

	// ChannelPrefix returns the userId prefix this channel owns (e.g., "telegram", "discord")
	ChannelPrefix() string

	// CreateChannel instantiates the channel implementation
	CreateChannel(cfg *config.Config, bus *bus.MessageBus) (Channel, error)

	// IsEnabled checks if the channel is enabled in config
	IsEnabled(cfg *config.Config) bool
}

ChannelPlugin extends Plugin with channel-specific functionality. Channel plugins connect external messaging platforms (Telegram, Discord, etc.)

type Manager

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

Manager orchestrates plugin lifecycle

func NewManager

func NewManager(cfg *config.Config, messageBus *bus.MessageBus, store media.MediaStore) *Manager

NewManager creates a new plugin manager

func (*Manager) AllChannels

func (m *Manager) AllChannels() map[string]Channel

AllChannels returns all initialized channels

func (*Manager) AllProviders

func (m *Manager) AllProviders() map[string]providers.LLMProvider

AllProviders returns all initialized providers

func (*Manager) GetChannel

func (m *Manager) GetChannel(prefix string) (Channel, bool)

GetChannel returns an initialized channel by prefix

func (*Manager) GetProvider

func (m *Manager) GetProvider(name string) (providers.LLMProvider, bool)

GetProvider returns an initialized provider by name

func (*Manager) Initialize

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

Initialize loads and initializes all enabled plugins

func (*Manager) InitializeToolsOnly

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

InitializeToolsOnly initializes only tool plugins. Used when channels and providers are managed separately (e.g., by gateway).

func (*Manager) ToolRegistry

func (m *Manager) ToolRegistry() *tools.ToolRegistry

ToolRegistry returns the tool registry for agent use

type Metadata

type Metadata struct {
	// ID is the unique identifier for the plugin (e.g., "moonhub-channel-telegram")
	ID string `json:"id"`
	// Name is the human-readable name (e.g., "Telegram")
	Name string `json:"name"`
	// Type indicates the plugin category
	Type PluginType `json:"type"`
	// Version follows semantic versioning (e.g., "1.0.0")
	Version string `json:"version"`
	// Description provides a brief summary of the plugin
	Description string `json:"description"`
	// Author is optional attribution
	Author string `json:"author,omitempty"`
	// Priority affects loading order (higher = loaded later)
	Priority int `json:"priority,omitempty"`
}

Metadata contains common plugin information

type Plugin

type Plugin interface {
	// Metadata returns plugin metadata
	Metadata() Metadata

	// Init initializes the plugin with runtime context
	Init(ctx *RuntimeContext) error

	// Validate checks if the plugin can run with current config
	Validate(cfg *config.Config) error
}

Plugin is the base interface all plugins must implement

type PluginType

type PluginType string

PluginType defines the category of plugin

const (
	// TypeChannel indicates a channel plugin (Telegram, Discord, etc.)
	TypeChannel PluginType = "channel"
	// TypeProvider indicates a provider plugin (OpenAI, Anthropic, etc.)
	TypeProvider PluginType = "provider"
	// TypeTool indicates a tool plugin (web search, filesystem, etc.)
	TypeTool PluginType = "tool"
)

type ProviderPlugin

type ProviderPlugin interface {
	Plugin

	// ProviderName returns the provider identifier (e.g., "anthropic", "openai")
	ProviderName() string

	// CreateProvider instantiates the provider from full config (used for IsEnabled checks).
	// For actual provider creation, use CreateProviderFromModelConfig.
	CreateProvider(cfg *config.Config) (providers.LLMProvider, error)

	// CreateProviderFromModelConfig creates a provider from model-centric config.
	// Used by the factory when routing by protocol.
	CreateProviderFromModelConfig(modelCfg *config.ModelConfig) (providers.LLMProvider, error)

	// IsEnabled checks if the provider has valid configuration
	IsEnabled(cfg *config.Config) bool

	// SupportsProtocol returns true if this plugin handles the given protocol (e.g., "openai", "anthropic").
	// Used for routing in CreateProviderFromConfig.
	SupportsProtocol(protocol string) bool

	// SupportsModel checks if this provider can handle a given model name (e.g., "openai/gpt-4o")
	SupportsModel(modelName string) bool
}

ProviderPlugin extends Plugin with provider-specific functionality. Provider plugins add LLM providers (OpenAI, Anthropic, Gemini, etc.)

type Registry

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

Registry manages all registered plugins

func GlobalRegistry

func GlobalRegistry() *Registry

GlobalRegistry returns the singleton registry

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new plugin registry

func (*Registry) Count

func (r *Registry) Count() int

Count returns the total number of registered plugins

func (*Registry) CountChannels

func (r *Registry) CountChannels() int

CountChannels returns the number of registered channel plugins

func (*Registry) CountProviders

func (r *Registry) CountProviders() int

CountProviders returns the number of registered provider plugins

func (*Registry) CountTools

func (r *Registry) CountTools() int

CountTools returns the number of registered tool plugins

func (*Registry) GetChannelPlugins

func (r *Registry) GetChannelPlugins() map[string]ChannelPlugin

GetChannelPlugins returns all registered channel plugins

func (*Registry) GetPlugin

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

GetPlugin returns a plugin by ID

func (*Registry) GetProviderPlugins

func (r *Registry) GetProviderPlugins() map[string]ProviderPlugin

GetProviderPlugins returns all registered provider plugins

func (*Registry) GetToolPlugins

func (r *Registry) GetToolPlugins() map[string]ToolPlugin

GetToolPlugins returns all registered tool plugins

func (*Registry) ListChannelPlugins

func (r *Registry) ListChannelPlugins() []string

ListChannelPlugins returns a sorted list of channel plugin IDs

func (*Registry) ListPlugins

func (r *Registry) ListPlugins() []string

ListPlugins returns a list of all registered plugin IDs

func (*Registry) ListProviderPlugins

func (r *Registry) ListProviderPlugins() []string

ListProviderPlugins returns a sorted list of provider plugin IDs

func (*Registry) ListToolPlugins

func (r *Registry) ListToolPlugins() []string

ListToolPlugins returns a sorted list of tool plugin IDs

func (*Registry) Register

func (r *Registry) Register(p Plugin)

Register registers any plugin type

type RuntimeContext

type RuntimeContext struct {
	// Config is the application configuration
	Config *config.Config
	// Bus is the message bus for inter-component communication
	Bus *bus.MessageBus
	// Workspace is the path to the workspace directory
	Workspace string
	// MediaStore handles media file storage
	MediaStore media.MediaStore
}

RuntimeContext provides dependencies injected at initialization

type ToolPlugin

type ToolPlugin interface {
	Plugin

	// CreateTools returns tool instances this plugin provides
	CreateTools(ctx *RuntimeContext) []tools.Tool

	// IsCore indicates if this is a core tool (always available)
	// Non-core tools can be dynamically promoted/discovered
	IsCore() bool
}

ToolPlugin extends Plugin with tool-specific functionality. Tool plugins extend the agent's capabilities with custom tools.

Jump to

Keyboard shortcuts

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