Documentation
¶
Overview ¶
Package plugin provides a development kit for building external FlowCraft plugins. External plugins are standalone binaries that communicate with the host via gRPC over Unix domain socket.
Usage:
func main() {
plugin.Serve(
plugin.WithInfo(plugin.PluginInfo{...}),
plugin.WithTool("my_tool", "description", nil, myHandler),
)
}
Package plugin provides an extensible plugin system supporting both built-in (compiled-in, init() self-registration) and external (gRPC subprocess) plugins.
Index ¶
- func Serve(opts ...Option)
- type Context
- func (c *Context) GetVar(key string) (any, bool)
- func (c *Context) LLMGenerate(prompt string) (string, error)
- func (c *Context) SandboxExec(command string) (string, error)
- func (c *Context) SetVar(key string, value any)
- func (c *Context) Signal(signalType string, payload any) error
- func (c *Context) StreamEmit(data string)
- func (c *Context) ToolExecute(name, args string) (string, error)
- type DataSourcePlugin
- type HandshakeRequest
- type HandshakeResponse
- type InstalledPlugin
- type LifecycleClient
- type ModelPlugin
- type NodeCallbacks
- type NodeHandler
- type NodePlugin
- type NodeServiceClient
- type NodeSpec
- type Option
- type Plugin
- type PluginInfo
- type PluginStatus
- type PluginType
- type SchemaProvider
- type StrategyPlugin
- type ToolHandler
- type ToolPlugin
- type ToolServiceClient
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context wraps host callback functions available to plugin handlers.
func (*Context) LLMGenerate ¶
LLMGenerate calls the host's LLM for text generation.
func (*Context) SandboxExec ¶
SandboxExec executes a command in the host sandbox.
func (*Context) StreamEmit ¶
StreamEmit sends streaming data to the host.
type DataSourcePlugin ¶
DataSourcePlugin extends Plugin for external data connectors.
type HandshakeRequest ¶
type HandshakeRequest struct {
HostVersion string `json:"host_version"`
ProtocolVer int `json:"protocol_version"`
}
HandshakeRequest is sent by host to plugin after connection.
type HandshakeResponse ¶
type HandshakeResponse struct {
PluginInfo PluginInfo `json:"plugin_info"`
ProtocolVer int `json:"protocol_version"`
Tools []ToolSpec `json:"tools,omitempty"`
Nodes []NodeSpec `json:"nodes,omitempty"`
}
HandshakeResponse is returned by the plugin during handshake.
type InstalledPlugin ¶
type InstalledPlugin struct {
Info PluginInfo `json:"info"`
Status PluginStatus `json:"status"`
Config map[string]any `json:"config,omitempty"`
Error string `json:"error,omitempty"`
}
InstalledPlugin wraps a plugin with its runtime status.
type LifecycleClient ¶
type LifecycleClient interface {
Handshake(ctx context.Context, req *HandshakeRequest) (*HandshakeResponse, error)
Initialize(ctx context.Context, config map[string]any) error
Shutdown(ctx context.Context) error
HealthCheck(ctx context.Context) error
}
LifecycleClient is the client-side interface for plugin lifecycle management.
type ModelPlugin ¶
ModelPlugin extends Plugin for LLM model providers.
type NodeCallbacks ¶
type NodeCallbacks interface {
GetVar(key string) (any, bool)
SetVar(key string, value any)
LLMGenerate(ctx context.Context, prompt string) (string, error)
ToolExecute(ctx context.Context, name string, args string) (string, error)
StreamEmit(data string)
SandboxExec(ctx context.Context, command string) (string, error)
Signal(ctx context.Context, signalType string, payload any) error
}
NodeCallbacks are host callbacks available to external nodes during execution.
type NodeHandler ¶
NodeHandler processes a node execution from the host.
type NodePlugin ¶
type NodePlugin interface {
Plugin
NodeType() string
CreateNode(id string, config map[string]any) (any, error)
}
NodePlugin extends Plugin with a custom node type.
type NodeServiceClient ¶
type NodeServiceClient interface {
ListNodes(ctx context.Context) ([]NodeSpec, error)
Execute(ctx context.Context, nodeID string, config map[string]any, callbacks NodeCallbacks) (map[string]any, error)
}
NodeServiceClient is the client-side interface for external node execution.
type Option ¶
type Option func(*server)
Option configures the plugin server.
type Plugin ¶
type Plugin interface {
Info() PluginInfo
Initialize(ctx context.Context, config map[string]any) error
Shutdown(ctx context.Context) error
}
Plugin is the base interface for all plugins.
type PluginInfo ¶
type PluginInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Type PluginType `json:"type"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
Icon string `json:"icon,omitempty"`
Homepage string `json:"homepage,omitempty"`
Builtin bool `json:"builtin"`
CreatedAt time.Time `json:"created_at"`
}
PluginInfo contains metadata about a plugin.
type PluginStatus ¶
type PluginStatus string
PluginStatus represents the runtime state of a plugin.
const ( StatusInstalled PluginStatus = "installed" StatusActive PluginStatus = "active" StatusInactive PluginStatus = "inactive" StatusError PluginStatus = "error" )
type PluginType ¶
type PluginType string
PluginType identifies the kind of plugin.
const ( TypeModel PluginType = "model" TypeTool PluginType = "tool" TypeNode PluginType = "node" TypeStrategy PluginType = "agent_strategy" TypeData PluginType = "data_source" )
type SchemaProvider ¶
SchemaProvider is an optional interface for plugins that expose UI schemas.
type StrategyPlugin ¶
StrategyPlugin extends Plugin with custom agent reasoning strategy.
type ToolHandler ¶
ToolHandler processes a tool call from the host.
type ToolPlugin ¶
type ToolPlugin interface {
Plugin
Tools() []ToolSpec
ExecuteTool(ctx context.Context, name string, arguments string) (string, error)
}
ToolPlugin extends Plugin with tool definitions and execution.