{"modulePath":"github.com/RealityLink-Tech/MoonHub","version":"v0.0.0-20260402113155-8155ea71ef7d","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\n## Functions\n\n```go\nfunc LoadBuiltin()\n```\nLoadBuiltin 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:\n\n  - Channel plugins: pkg/plugins/channels/\\*\n  - Provider plugins: pkg/plugins/providers/\\*\n  - Tool plugins: pkg/plugins/tools/\\*\n\nThis function is a no-op kept for API compatibility.\n\n```go\nfunc RegisterPlugin(p Plugin)\n```\nRegisterPlugin is a convenience function for the global registry\n\n## Types\n\n```go\ntype Channel interface {\n\tName() string\n\tStart(ctx context.Context) error\n\tStop(ctx context.Context) error\n\tSend(ctx context.Context, msg bus.OutboundMessage) error\n\tIsRunning() bool\n}\n```\nChannel is the interface for messaging channels Defined here to avoid circular imports\n\n```go\ntype ChannelPlugin interface {\n\tPlugin\n\n\t// ChannelPrefix returns the userId prefix this channel owns (e.g., \"telegram\", \"discord\")\n\tChannelPrefix() string\n\n\t// CreateChannel instantiates the channel implementation\n\tCreateChannel(cfg *config.Config, bus *bus.MessageBus) (Channel, error)\n\n\t// IsEnabled checks if the channel is enabled in config\n\tIsEnabled(cfg *config.Config) bool\n}\n```\nChannelPlugin extends Plugin with channel-specific functionality. Channel plugins connect external messaging platforms (Telegram, Discord, etc.)\n\n```go\ntype Manager struct {\n\t// contains filtered or unexported fields\n}\n```\nManager orchestrates plugin lifecycle\n\n```go\nfunc NewManager(cfg *config.Config, messageBus *bus.MessageBus, store media.MediaStore) *Manager\n```\nNewManager creates a new plugin manager\n\n```go\nfunc (m *Manager) AllChannels() map[string]Channel\n```\nAllChannels returns all initialized channels\n\n```go\nfunc (m *Manager) AllProviders() map[string]providers.LLMProvider\n```\nAllProviders returns all initialized providers\n\n```go\nfunc (m *Manager) GetChannel(prefix string) (Channel, bool)\n```\nGetChannel returns an initialized channel by prefix\n\n```go\nfunc (m *Manager) GetProvider(name string) (providers.LLMProvider, bool)\n```\nGetProvider returns an initialized provider by name\n\n```go\nfunc (m *Manager) Initialize(ctx context.Context) error\n```\nInitialize loads and initializes all enabled plugins\n\n```go\nfunc (m *Manager) InitializeToolsOnly(ctx context.Context) error\n```\nInitializeToolsOnly initializes only tool plugins. Used when channels and providers are managed separately (e.g., by gateway).\n\n```go\nfunc (m *Manager) ToolRegistry() *tools.ToolRegistry\n```\nToolRegistry returns the tool registry for agent use\n\n```go\ntype Metadata struct {\n\t// ID is the unique identifier for the plugin (e.g., \"moonhub-channel-telegram\")\n\tID string `json:\"id\"`\n\t// Name is the human-readable name (e.g., \"Telegram\")\n\tName string `json:\"name\"`\n\t// Type indicates the plugin category\n\tType PluginType `json:\"type\"`\n\t// Version follows semantic versioning (e.g., \"1.0.0\")\n\tVersion string `json:\"version\"`\n\t// Description provides a brief summary of the plugin\n\tDescription string `json:\"description\"`\n\t// Author is optional attribution\n\tAuthor string `json:\"author,omitempty\"`\n\t// Priority affects loading order (higher = loaded later)\n\tPriority int `json:\"priority,omitempty\"`\n}\n```\nMetadata contains common plugin information\n\n```go\ntype Plugin interface {\n\t// Metadata returns plugin metadata\n\tMetadata() Metadata\n\n\t// Init initializes the plugin with runtime context\n\tInit(ctx *RuntimeContext) error\n\n\t// Validate checks if the plugin can run with current config\n\tValidate(cfg *config.Config) error\n}\n```\nPlugin is the base interface all plugins must implement\n\n```go\ntype PluginType string\n```\nPluginType defines the category of plugin\n\n```go\nconst (\n\t// TypeChannel indicates a channel plugin (Telegram, Discord, etc.)\n\tTypeChannel PluginType = \"channel\"\n\t// TypeProvider indicates a provider plugin (OpenAI, Anthropic, etc.)\n\tTypeProvider PluginType = \"provider\"\n\t// TypeTool indicates a tool plugin (web search, filesystem, etc.)\n\tTypeTool PluginType = \"tool\"\n)\n```\n\n```go\ntype ProviderPlugin interface {\n\tPlugin\n\n\t// ProviderName returns the provider identifier (e.g., \"anthropic\", \"openai\")\n\tProviderName() string\n\n\t// CreateProvider instantiates the provider from full config (used for IsEnabled checks).\n\t// For actual provider creation, use CreateProviderFromModelConfig.\n\tCreateProvider(cfg *config.Config) (providers.LLMProvider, error)\n\n\t// CreateProviderFromModelConfig creates a provider from model-centric config.\n\t// Used by the factory when routing by protocol.\n\tCreateProviderFromModelConfig(modelCfg *config.ModelConfig) (providers.LLMProvider, error)\n\n\t// IsEnabled checks if the provider has valid configuration\n\tIsEnabled(cfg *config.Config) bool\n\n\t// SupportsProtocol returns true if this plugin handles the given protocol (e.g., \"openai\", \"anthropic\").\n\t// Used for routing in CreateProviderFromConfig.\n\tSupportsProtocol(protocol string) bool\n\n\t// SupportsModel checks if this provider can handle a given model name (e.g., \"openai/gpt-4o\")\n\tSupportsModel(modelName string) bool\n}\n```\nProviderPlugin extends Plugin with provider-specific functionality. Provider plugins add LLM providers (OpenAI, Anthropic, Gemini, etc.)\n\n```go\ntype Registry struct {\n\t// contains filtered or unexported fields\n}\n```\nRegistry manages all registered plugins\n\n```go\nfunc GlobalRegistry() *Registry\n```\nGlobalRegistry returns the singleton registry\n\n```go\nfunc NewRegistry() *Registry\n```\nNewRegistry creates a new plugin registry\n\n```go\nfunc (r *Registry) Count() int\n```\nCount returns the total number of registered plugins\n\n```go\nfunc (r *Registry) CountChannels() int\n```\nCountChannels returns the number of registered channel plugins\n\n```go\nfunc (r *Registry) CountProviders() int\n```\nCountProviders returns the number of registered provider plugins\n\n```go\nfunc (r *Registry) CountTools() int\n```\nCountTools returns the number of registered tool plugins\n\n```go\nfunc (r *Registry) GetChannelPlugins() map[string]ChannelPlugin\n```\nGetChannelPlugins returns all registered channel plugins\n\n```go\nfunc (r *Registry) GetPlugin(id string) (Plugin, bool)\n```\nGetPlugin returns a plugin by ID\n\n```go\nfunc (r *Registry) GetProviderPlugins() map[string]ProviderPlugin\n```\nGetProviderPlugins returns all registered provider plugins\n\n```go\nfunc (r *Registry) GetToolPlugins() map[string]ToolPlugin\n```\nGetToolPlugins returns all registered tool plugins\n\n```go\nfunc (r *Registry) ListChannelPlugins() []string\n```\nListChannelPlugins returns a sorted list of channel plugin IDs\n\n```go\nfunc (r *Registry) ListPlugins() []string\n```\nListPlugins returns a list of all registered plugin IDs\n\n```go\nfunc (r *Registry) ListProviderPlugins() []string\n```\nListProviderPlugins returns a sorted list of provider plugin IDs\n\n```go\nfunc (r *Registry) ListToolPlugins() []string\n```\nListToolPlugins returns a sorted list of tool plugin IDs\n\n```go\nfunc (r *Registry) Register(p Plugin)\n```\nRegister registers any plugin type\n\n```go\ntype RuntimeContext struct {\n\t// Config is the application configuration\n\tConfig *config.Config\n\t// Bus is the message bus for inter-component communication\n\tBus *bus.MessageBus\n\t// Workspace is the path to the workspace directory\n\tWorkspace string\n\t// MediaStore handles media file storage\n\tMediaStore media.MediaStore\n}\n```\nRuntimeContext provides dependencies injected at initialization\n\n```go\ntype ToolPlugin interface {\n\tPlugin\n\n\t// CreateTools returns tool instances this plugin provides\n\tCreateTools(ctx *RuntimeContext) []tools.Tool\n\n\t// IsCore indicates if this is a core tool (always available)\n\t// Non-core tools can be dynamically promoted/discovered\n\tIsCore() bool\n}\n```\nToolPlugin extends Plugin with tool-specific functionality. Tool plugins extend the agent's capabilities with custom tools.\n\n","path":"github.com/RealityLink-Tech/MoonHub/pkg/framework","name":"plugin","synopsis":"","isRedistributable":true}
