plugins

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package plugins embeds JavaScript tools using the pure-Go moejs runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path          string         `yaml:"path"`
	Timeout       int            `yaml:"timeout,omitempty"`         // seconds; default 30
	MemoryLimitMB int            `yaml:"memory_limit_mb,omitempty"` // default 64
	Config        map[string]any `yaml:"config,omitempty"`
}

Config describes one ES module. Paths are resolved relative to config.yml.

type Event

type Event struct {
	Type      string `json:"type"`
	Agent     string `json:"agent,omitempty"`
	Model     string `json:"model,omitempty"`
	Tool      string `json:"tool,omitempty"`
	CallID    string `json:"call_id,omitempty"`
	Prompt    string `json:"prompt,omitempty"`
	Arguments string `json:"arguments,omitempty"`
	Result    string `json:"result"`
	Error     string `json:"error,omitempty"`
}

Event is the immutable JSON snapshot sent to lifecycle hooks. Hooks observe events; their return value does not replace prompts, arguments or results.

type Plugin

type Plugin struct {
	Tools     []*Tool
	Agents    map[string]json.RawMessage
	Models    map[string]json.RawMessage
	Providers map[string]json.RawMessage
	Themes    map[string]Theme
	// contains filtered or unexported fields
}

Plugin contains the extensions exported by one ES module. Agents and models use the same fields as YAML configuration; registration is owned by config.

func Load

func Load(ctx context.Context, name string, cfg Config) (*Plugin, error)

Load compiles a plugin and reads its exported `tools` object. Tool names are namespaced as <plugin>__<tool> so multiple plugins can use the same local name.

func (*Plugin) Emit

func (p *Plugin) Emit(ctx context.Context, event Event) error

Emit runs a hook with its own runtime and the plugin's deadline and budget.

func (*Plugin) HasHook

func (p *Plugin) HasHook(name string) bool

HasHook reports whether this plugin subscribes to an event.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the configured plugin namespace.

type Theme

type Theme struct {
	Description string       `json:"description"`
	Light       ThemeVariant `json:"light"`
	Dark        ThemeVariant `json:"dark"`
}

Theme has matching light and dark variants.

type ThemeVariant

type ThemeVariant struct {
	Primary string `json:"primary"`
	Accent  string `json:"accent"`
	Success string `json:"success"`
	Warning string `json:"warning"`
	Error   string `json:"error"`
	User    string `json:"user"`
	Muted   string `json:"muted"`
}

ThemeVariant defines foreground colors for a light or dark terminal.

type Tool

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

Tool is one named tool exported by a JavaScript plugin. A compiled module is shared, but each call gets its own runtime, globals and plugin configuration.

func (*Tool) Info

func (t *Tool) Info(context.Context) (*schema.ToolInfo, error)

func (*Tool) InvokableRun

func (t *Tool) InvokableRun(ctx context.Context, arguments string, _ ...tool.Option) (string, error)

InvokableRun passes JSON arguments and {plugin, tool, config} to execute. Strings are returned as text; other JSON values are serialized as JSON.

Jump to

Keyboard shortcuts

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