plugin

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdaptTool

func AdaptTool(t Tool) tool.Tool

AdaptTool converts a plugin Tool into an internal tool.Tool.

func ExpandPath

func ExpandPath(path string) string

ExpandPath expands ~ to the user's home directory.

Types

type EventKind

type EventKind string

EventKind identifies lifecycle events.

const (
	EventBeforeToolCall EventKind = "before_tool_call"
	EventAfterToolCall  EventKind = "after_tool_call"
	EventSessionStart   EventKind = "session_start"
	EventSessionEnd     EventKind = "session_end"
)

type HookFunc

type HookFunc func(ctx context.Context, event any) error

HookFunc is a lifecycle hook handler. For "before" events, returning a non-nil error cancels the action. For "after" events, return values are ignored.

type JSPlugin

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

JSPlugin wraps a single JS extension loaded via QJS. All JS calls are serialized via mu since QJS runtimes are not goroutine-safe.

func LoadJS

func LoadJS(path string, cfg map[string]any, registry *Registry, logger *slog.Logger, opts ...loadOption) (*JSPlugin, error)

LoadJS loads a JS extension from the given path, registers its tools and hooks into the registry, and returns a JSPlugin.

func (*JSPlugin) Close

func (p *JSPlugin) Close() error

func (*JSPlugin) Name

func (p *JSPlugin) Name() string

type Manager

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

Manager discovers, loads, and manages JS plugins.

func NewManager

func NewManager(logger *slog.Logger, builtinToolNames []string) *Manager

NewManager creates a plugin manager.

func (*Manager) Close

func (m *Manager) Close() error

Close shuts down all plugins in reverse order.

func (*Manager) LoadAll

func (m *Manager) LoadAll(configs []config.PluginConfig)

LoadAll loads JS plugins from config. Best-effort: logs warnings for failures and continues loading remaining plugins.

func (*Manager) Registry

func (m *Manager) Registry() *Registry

Registry returns the plugin registry.

type Registry

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

Registry collects tools and hooks from all plugins.

func NewRegistry

func NewRegistry(builtinNames []string) *Registry

NewRegistry creates a registry with the given built-in tool names reserved.

func (*Registry) RegisterHook

func (r *Registry) RegisterHook(event EventKind, fn HookFunc)

RegisterHook adds a lifecycle hook for the given event kind.

func (*Registry) RegisterTool

func (r *Registry) RegisterTool(t Tool) error

RegisterTool adds a tool. Returns error on duplicate or reserved name.

func (*Registry) RunHooks

func (r *Registry) RunHooks(ctx context.Context, event string, data any) error

RunHooks executes all hooks for the given event kind sequentially.

Only before_tool_call is blocking: the first hook that returns an error stops execution and the error is returned, cancelling the tool call. All other events (after_tool_call, session_start, session_end) are fire-and-forget — hook errors are silently ignored.

The event parameter is a string (not EventKind) so that callers in the engine package can use this method without importing internal/plugin directly, avoiding circular imports.

func (*Registry) Tools

func (r *Registry) Tools() map[string]Tool

Tools returns a copy of all registered tools.

type Tool

type Tool struct {
	Name        string
	Description string
	InputSchema map[string]any
	Execute     func(ctx context.Context, args map[string]any) (string, error)
}

Tool is a plugin-provided tool definition.

Jump to

Keyboard shortcuts

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