Documentation
¶
Overview ¶
Package plugins provides a framework for dynamically loading and managing plugins
Index ¶
- Variables
- func AsHTTPTransportPlugin(plugin schemas.BasePlugin) schemas.HTTPTransportPlugin
- func AsLLMPlugin(plugin schemas.BasePlugin) schemas.LLMPlugin
- func AsMCPPlugin(plugin schemas.BasePlugin) schemas.MCPPlugin
- func AsObservabilityPlugin(plugin schemas.BasePlugin) schemas.ObservabilityPlugin
- func DownloadPlugin(url string, extension string) (string, error)
- func FilterHTTPTransportPlugins(plugins []schemas.BasePlugin) []schemas.HTTPTransportPlugin
- func FilterLLMPlugins(plugins []schemas.BasePlugin) []schemas.LLMPlugin
- func FilterMCPPlugins(plugins []schemas.BasePlugin) []schemas.MCPPlugin
- func FilterObservabilityPlugins(plugins []schemas.BasePlugin) []schemas.ObservabilityPlugin
- func LoadPlugins(loader PluginLoader, config *Config) ([]schemas.BasePlugin, error)
- type Config
- type DynamicPlugin
- func (dp *DynamicPlugin) Cleanup() error
- func (dp *DynamicPlugin) GetName() string
- func (dp *DynamicPlugin) HTTPTransportPostHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, ...) error
- func (dp *DynamicPlugin) HTTPTransportPreHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest) (*schemas.HTTPResponse, error)
- func (dp *DynamicPlugin) HTTPTransportStreamChunkHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, ...) (*schemas.BifrostStreamChunk, error)
- func (dp *DynamicPlugin) Inject(ctx context.Context, trace *schemas.Trace) error
- func (dp *DynamicPlugin) PostLLMHook(ctx *schemas.BifrostContext, resp *schemas.BifrostResponse, ...) (*schemas.BifrostResponse, *schemas.BifrostError, error)
- func (dp *DynamicPlugin) PostMCPHook(ctx *schemas.BifrostContext, resp *schemas.BifrostMCPResponse, ...) (*schemas.BifrostMCPResponse, *schemas.BifrostError, error)
- func (dp *DynamicPlugin) PreLLMHook(ctx *schemas.BifrostContext, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.LLMPluginShortCircuit, error)
- func (dp *DynamicPlugin) PreMCPHook(ctx *schemas.BifrostContext, req *schemas.BifrostMCPRequest) (*schemas.BifrostMCPRequest, *schemas.MCPPluginShortCircuit, error)
- type PluginConfig
- type PluginLoader
- type SharedObjectPluginLoader
Constants ¶
This section is empty.
Variables ¶
var (
ErrPluginNotFound = fmt.Errorf("plugin not found")
)
Functions ¶
func AsHTTPTransportPlugin ¶ added in v1.2.17
func AsHTTPTransportPlugin(plugin schemas.BasePlugin) schemas.HTTPTransportPlugin
AsHTTPTransportPlugin checks if a base plugin implements HTTPTransportPlugin and actually has HTTP transport hooks. For DynamicPlugin, it checks if the hook function pointers are not nil. Returns nil if the plugin does not implement the interface or has no HTTP transport hooks.
func AsLLMPlugin ¶ added in v1.2.17
func AsLLMPlugin(plugin schemas.BasePlugin) schemas.LLMPlugin
AsLLMPlugin checks if a base plugin implements LLMPlugin and actually has LLM hooks. For DynamicPlugin, it checks if the hook function pointers are not nil. Returns nil if the plugin does not implement the interface or has no LLM hooks.
func AsMCPPlugin ¶ added in v1.2.17
func AsMCPPlugin(plugin schemas.BasePlugin) schemas.MCPPlugin
AsMCPPlugin checks if a base plugin implements MCPPlugin and actually has MCP hooks. For DynamicPlugin, it checks if the hook function pointers are not nil. Returns nil if the plugin does not implement the interface or has no MCP hooks.
func AsObservabilityPlugin ¶ added in v1.2.17
func AsObservabilityPlugin(plugin schemas.BasePlugin) schemas.ObservabilityPlugin
AsObservabilityPlugin checks if a base plugin implements ObservabilityPlugin and actually has observability hooks. For DynamicPlugin, it checks if the hook function pointer is not nil. Returns nil if the plugin does not implement the interface or has no observability hooks.
func DownloadPlugin ¶ added in v1.2.4
DownloadPlugin downloads a plugin from a URL and returns the local file path
func FilterHTTPTransportPlugins ¶ added in v1.2.17
func FilterHTTPTransportPlugins(plugins []schemas.BasePlugin) []schemas.HTTPTransportPlugin
FilterHTTPTransportPlugins filters a list of BasePlugins to only include those implementing HTTPTransportPlugin
func FilterLLMPlugins ¶ added in v1.2.17
func FilterLLMPlugins(plugins []schemas.BasePlugin) []schemas.LLMPlugin
FilterLLMPlugins filters a list of BasePlugins to only include those implementing LLMPlugin
func FilterMCPPlugins ¶ added in v1.2.17
func FilterMCPPlugins(plugins []schemas.BasePlugin) []schemas.MCPPlugin
FilterMCPPlugins filters a list of BasePlugins to only include those implementing MCPPlugin
func FilterObservabilityPlugins ¶ added in v1.2.17
func FilterObservabilityPlugins(plugins []schemas.BasePlugin) []schemas.ObservabilityPlugin
FilterObservabilityPlugins filters a list of BasePlugins to only include those implementing ObservabilityPlugin
func LoadPlugins ¶
func LoadPlugins(loader PluginLoader, config *Config) ([]schemas.BasePlugin, error)
LoadPlugins loads all plugins from the config
Types ¶
type Config ¶
type Config struct {
// Plugins is the unified configuration for all plugin types
Plugins []PluginConfig `json:"plugins"`
}
Config is the configuration for the plugins framework
type DynamicPlugin ¶
type DynamicPlugin struct {
Enabled bool
Path string
Config any
// contains filtered or unexported fields
}
DynamicPlugin is a generic dynamic plugin that can implement any combination of plugin interfaces It uses optional function pointers - nil pointers indicate the interface is not implemented
func (*DynamicPlugin) Cleanup ¶
func (dp *DynamicPlugin) Cleanup() error
Cleanup is invoked by core/bifrost.go during plugin unload, reload, and shutdown (BasePlugin interface)
func (*DynamicPlugin) GetName ¶
func (dp *DynamicPlugin) GetName() string
GetName returns the name of the plugin (BasePlugin interface)
func (*DynamicPlugin) HTTPTransportPostHook ¶ added in v1.2.9
func (dp *DynamicPlugin) HTTPTransportPostHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, resp *schemas.HTTPResponse) error
HTTPTransportPostHook intercepts HTTP responses at the transport layer after exiting Bifrost core (HTTPTransportPlugin interface)
func (*DynamicPlugin) HTTPTransportPreHook ¶ added in v1.2.9
func (dp *DynamicPlugin) HTTPTransportPreHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest) (*schemas.HTTPResponse, error)
HTTPTransportPreHook intercepts HTTP requests at the transport layer before entering Bifrost core (HTTPTransportPlugin interface)
func (*DynamicPlugin) HTTPTransportStreamChunkHook ¶ added in v1.2.15
func (dp *DynamicPlugin) HTTPTransportStreamChunkHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, stream *schemas.BifrostStreamChunk) (*schemas.BifrostStreamChunk, error)
HTTPTransportStreamChunkHook intercepts streaming chunks before they are written to the client
func (*DynamicPlugin) Inject ¶ added in v1.2.17
Inject receives completed traces for observability backends (ObservabilityPlugin interface)
func (*DynamicPlugin) PostLLMHook ¶ added in v1.2.17
func (dp *DynamicPlugin) PostLLMHook(ctx *schemas.BifrostContext, resp *schemas.BifrostResponse, bifrostErr *schemas.BifrostError) (*schemas.BifrostResponse, *schemas.BifrostError, error)
PostLLMHook is invoked after LLM provider calls (LLMPlugin interface)
func (*DynamicPlugin) PostMCPHook ¶ added in v1.2.17
func (dp *DynamicPlugin) PostMCPHook(ctx *schemas.BifrostContext, resp *schemas.BifrostMCPResponse, bifrostErr *schemas.BifrostError) (*schemas.BifrostMCPResponse, *schemas.BifrostError, error)
PostMCPHook is invoked after MCP calls (MCPPlugin interface)
func (*DynamicPlugin) PreLLMHook ¶ added in v1.2.17
func (dp *DynamicPlugin) PreLLMHook(ctx *schemas.BifrostContext, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.LLMPluginShortCircuit, error)
PreLLMHook is invoked before LLM provider calls (LLMPlugin interface)
func (*DynamicPlugin) PreMCPHook ¶ added in v1.2.17
func (dp *DynamicPlugin) PreMCPHook(ctx *schemas.BifrostContext, req *schemas.BifrostMCPRequest) (*schemas.BifrostMCPRequest, *schemas.MCPPluginShortCircuit, error)
PreMCPHook is invoked before MCP calls (MCPPlugin interface)
type PluginConfig ¶ added in v1.2.17
type PluginConfig struct {
Path string `json:"path"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Config any `json:"config,omitempty"`
}
PluginConfig is the generic configuration for any plugin type Plugin types are automatically detected based on implemented interfaces
type PluginLoader ¶ added in v1.2.4
type PluginLoader interface {
// LoadPlugin loads a generic plugin from the given path with the provided config
// Returns a BasePlugin that can be type-asserted to specific plugin interfaces
LoadPlugin(path string, config any) (schemas.BasePlugin, error)
// VerifyBasePlugin verifies a plugin at the given path
// Returns the name of the plugin or an empty string if the plugin is invalid
// Returns an error if the plugin is invalid
// This method is used to verify that the plugin is a valid base plugin and has the required symbols
VerifyBasePlugin(path string) (string, error)
}
PluginLoader is the contract for a plugin loader
type SharedObjectPluginLoader ¶ added in v1.2.4
type SharedObjectPluginLoader struct{}
SharedObjectPluginLoader is the loader for shared object plugins
func (*SharedObjectPluginLoader) LoadPlugin ¶ added in v1.2.17
func (l *SharedObjectPluginLoader) LoadPlugin(path string, config any) (schemas.BasePlugin, error)
LoadPlugin loads a generic plugin from a shared object file It uses optional symbol lookup - only GetName and Cleanup are required All other hook methods are optional and stored as nil if not implemented
func (*SharedObjectPluginLoader) VerifyBasePlugin ¶ added in v1.2.17
func (l *SharedObjectPluginLoader) VerifyBasePlugin(path string) (string, error)
VerifyBasePlugin verifies a plugin at the given path Returns the name of the plugin or an empty string if the plugin is invalid Returns an error if the plugin is invalid This method is used to verify that the plugin is a valid base plugin and has the required symbols