tool

package
v0.0.0-...-58009f2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor struct {
	Registry *Registry
}

Executor wraps a Registry to implement runtime.ToolExecutor.

func NewExecutor

func NewExecutor(r *Registry) *Executor

NewExecutor creates an executor from a registry.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, tool, version string, input json.RawMessage) (*runtime.ToolResult, error)

Execute implements runtime.ToolExecutor.

type InputSchema

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

InputSchema validates tool input. Uses JSON Schema.

func NewInputSchema

func NewInputSchema(raw []byte) (*InputSchema, error)

NewInputSchema creates an InputSchema from a JSON Schema document.

func (*InputSchema) Validate

func (s *InputSchema) Validate(input []byte) error

Validate validates input against the schema.

type Marketplace

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

Marketplace is a specialized client for the tool marketplace.

func NewMarketplace

func NewMarketplace(db *sql.DB, serverURL, localPath string) *Marketplace

NewMarketplace creates a new tool marketplace client.

func (*Marketplace) GetTool

func (m *Marketplace) GetTool(ctx context.Context, toolID string) (*registry.PluginMetadata, error)

GetTool retrieves a specific tool.

func (*Marketplace) InstallTool

func (m *Marketplace) InstallTool(ctx context.Context, toolID string) error

InstallTool installs a tool from the marketplace.

func (*Marketplace) ListInstalledTools

func (m *Marketplace) ListInstalledTools() ([]registry.PluginMetadata, error)

ListInstalledTools lists locally installed tools.

func (*Marketplace) PublishTool

func (m *Marketplace) PublishTool(ctx context.Context, manifest *registry.PluginManifest, artifact []byte) error

PublishTool publishes a tool to the marketplace.

func (*Marketplace) SearchTools

func (m *Marketplace) SearchTools(ctx context.Context, query string, limit int) ([]registry.PluginMetadata, error)

SearchTools searches for tools in the marketplace.

type Permission

type Permission struct {
	Scope    string // e.g., "fs:read", "net:external", "email:send"
	Required bool
}

Permission defines a scoped permission for a tool.

type PluginDiscovery

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

PluginDiscovery handles plugin discovery and hot-reload.

func NewPluginDiscovery

func NewPluginDiscovery(pluginDirs []string) *PluginDiscovery

NewPluginDiscovery creates a new plugin discovery manager.

func (*PluginDiscovery) GetGoPlugin

func (pd *PluginDiscovery) GetGoPlugin(name, version string) (*PluginTool, error)

GetGoPlugin retrieves a Go plugin.

func (*PluginDiscovery) GetWASMPlugin

func (pd *PluginDiscovery) GetWASMPlugin(name, version string) (*WASMTool, error)

GetWASMPlugin retrieves a WASM plugin.

func (*PluginDiscovery) ListAllPlugins

func (pd *PluginDiscovery) ListAllPlugins() []string

ListAllPlugins returns all loaded plugins.

func (*PluginDiscovery) LoadFromManifest

func (pd *PluginDiscovery) LoadFromManifest(manifest PluginManifest) error

LoadFromManifest loads a plugin from a manifest.

func (*PluginDiscovery) ScanPlugins

func (pd *PluginDiscovery) ScanPlugins() ([]PluginManifest, error)

ScanPlugins scans plugin directories for available plugins.

func (*PluginDiscovery) StopWatching

func (pd *PluginDiscovery) StopWatching(dir string)

StopWatching stops watching a directory.

func (*PluginDiscovery) WatchForChanges

func (pd *PluginDiscovery) WatchForChanges(dir string, reloadInterval time.Duration) error

WatchForChanges enables hot-reload for a plugin directory.

type PluginLoader

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

PluginLoader manages loading and hot-reloading of plugins.

func NewPluginLoader

func NewPluginLoader() *PluginLoader

NewPluginLoader creates a new plugin loader.

func (*PluginLoader) GetPlugin

func (l *PluginLoader) GetPlugin(name, version string) (*PluginTool, error)

GetPlugin retrieves a loaded plugin.

func (*PluginLoader) ListPlugins

func (l *PluginLoader) ListPlugins() []string

ListPlugins returns all loaded plugins.

func (*PluginLoader) LoadPlugin

func (l *PluginLoader) LoadPlugin(path string) error

LoadPlugin loads a plugin from a file.

func (*PluginLoader) ReloadPlugin

func (l *PluginLoader) ReloadPlugin(path, name, version string) error

ReloadPlugin hot-reloads a plugin.

func (*PluginLoader) UnloadPlugin

func (l *PluginLoader) UnloadPlugin(name, version string) error

UnloadPlugin removes a plugin from memory.

type PluginManifest

type PluginManifest struct {
	Name        string   `yaml:"name"`
	Version     string   `yaml:"version"`
	Type        string   `yaml:"type"` // "goplugin" or "wasm"
	Binary      string   `yaml:"binary"`
	Description string   `yaml:"description"`
	Author      string   `yaml:"author"`
	Permissions []string `yaml:"permissions"`
}

PluginManifest describes a plugin's metadata.

type PluginTool

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

PluginTool wraps a dynamically loaded Go plugin.

func NewPluginTool

func NewPluginTool(pluginPath string) (*PluginTool, error)

NewPluginTool loads a tool from a Go plugin file.

func (*PluginTool) Description

func (p *PluginTool) Description() string

Description returns the tool description.

func (*PluginTool) Execute

func (p *PluginTool) Execute(ctx context.Context, input json.RawMessage) (map[string]any, error)

Execute runs the plugin tool.

func (*PluginTool) InputSchema

func (p *PluginTool) InputSchema() ([]byte, error)

InputSchema returns the tool's input schema.

func (*PluginTool) Name

func (p *PluginTool) Name() string

Name returns the plugin tool name.

func (*PluginTool) Permissions

func (p *PluginTool) Permissions() []Permission

Permissions returns the tool's permission requirements.

func (*PluginTool) Version

func (p *PluginTool) Version() string

Version returns the plugin tool version.

type PolicyExecutor

type PolicyExecutor struct {
	Inner       runtime.ToolExecutor
	Policy      *policy.Engine
	RiskScorer  policy.RiskScorer
	Approval    *policy.ApprovalGate
	Environment string
}

PolicyExecutor wraps an executor with policy checks and approval gates.

func (*PolicyExecutor) Execute

func (e *PolicyExecutor) Execute(ctx context.Context, tool, version string, input json.RawMessage) (*runtime.ToolResult, error)

Execute implements runtime.ToolExecutor with policy enforcement.

type Registry

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

Registry holds registered tools and executes them.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new tool registry.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, tool, version string, input json.RawMessage) (*runtime.ToolResult, error)

Execute implements runtime.ToolExecutor.

func (*Registry) Get

func (r *Registry) Get(name, version string) (Tool, bool)

Get returns a tool by name and version.

func (*Registry) List

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

List returns all registered tool names and versions.

func (*Registry) Register

func (r *Registry) Register(t Tool)

Register adds a tool to the registry.

type Tool

type Tool interface {
	Name() string
	Version() string
	Description() string
	InputSchema() ([]byte, error)
	Permissions() []Permission
	Execute(ctx context.Context, input json.RawMessage) (output map[string]any, err error)
}

Tool is the interface for executable tools.

type WASMLoader

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

WASMLoader manages WASM plugin loading.

func NewWASMLoader

func NewWASMLoader() *WASMLoader

NewWASMLoader creates a new WASM loader.

func (*WASMLoader) GetWASMTool

func (l *WASMLoader) GetWASMTool(name, version string) (*WASMTool, error)

GetWASMTool retrieves a loaded WASM tool.

func (*WASMLoader) ListWASMTools

func (l *WASMLoader) ListWASMTools() []string

ListWASMTools returns a list of all loaded WASM tools.

func (*WASMLoader) LoadWASM

func (l *WASMLoader) LoadWASM(ctx context.Context, wasmPath string, metadata WASMToolMetadata) error

LoadWASM loads a WASM tool.

func (*WASMLoader) UnloadWASM

func (l *WASMLoader) UnloadWASM(ctx context.Context, name, version string) error

UnloadWASM unloads a WASM tool.

type WASMTool

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

WASMTool wraps a WASM-based tool for secure sandboxed execution.

func NewWASMTool

func NewWASMTool(ctx context.Context, wasmPath string, metadata WASMToolMetadata) (*WASMTool, error)

NewWASMTool creates a new WASM tool from a .wasm file.

func (*WASMTool) Close

func (w *WASMTool) Close(ctx context.Context) error

Close cleans up WASM runtime resources.

func (*WASMTool) Description

func (w *WASMTool) Description() string

Description returns the tool description.

func (*WASMTool) Execute

func (w *WASMTool) Execute(ctx context.Context, input json.RawMessage) (map[string]any, error)

Execute runs the WASM tool with sandboxing.

func (*WASMTool) InputSchema

func (w *WASMTool) InputSchema() ([]byte, error)

InputSchema returns the tool's input schema.

func (*WASMTool) Name

func (w *WASMTool) Name() string

Name returns the tool name.

func (*WASMTool) Permissions

func (w *WASMTool) Permissions() []Permission

Permissions returns the tool's permission requirements.

func (*WASMTool) Version

func (w *WASMTool) Version() string

Version returns the tool version.

type WASMToolMetadata

type WASMToolMetadata struct {
	Name        string       `json:"name"`
	Version     string       `json:"version"`
	InputSchema []byte       `json:"input_schema"`
	Permissions []Permission `json:"permissions"`
}

WASMToolMetadata contains metadata for a WASM tool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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