plugin

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package plugin provides an extensible plugin system for TokMan. Currently supports Go plugins. WASM plugin support is planned.

TODO: Add WASM plugin support using github.com/tetratelabs/wazero See: https://github.com/tetratelabs/wazero

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the global plugin registry.

Functions

func ValidateWASMPlugin

func ValidateWASMPlugin(path string) error

ValidateWASMPlugin checks if a WASM file is a valid TokMan plugin.

Types

type Plugin

type Plugin interface {
	// Name returns the plugin's unique identifier.
	Name() string

	// Version returns the plugin version string.
	Version() string

	// Apply processes input text and returns the result.
	// Returns the processed text and number of tokens saved.
	Apply(input string) (output string, tokensSaved int, err error)

	// Close releases any resources held by the plugin.
	Close() error
}

Plugin represents a TokMan plugin that can process text.

type PluginInfo

type PluginInfo struct {
	Name        string     `json:"name"`
	Version     string     `json:"version"`
	Type        PluginType `json:"type"`
	Path        string     `json:"path"`
	Description string     `json:"description,omitempty"`
	Author      string     `json:"author,omitempty"`
	Enabled     bool       `json:"enabled"`
}

PluginInfo contains metadata about a plugin.

func WASMPluginInfo

func WASMPluginInfo(path string) (*PluginInfo, error)

WASMPluginInfo returns information about a WASM plugin without loading it.

type PluginType

type PluginType string

PluginType represents the type of plugin.

const (
	// PluginTypeGo is a native Go plugin.
	PluginTypeGo PluginType = "go"

	// PluginTypeWASM is a WebAssembly plugin (planned).
	// TODO: Implement WASM support with wazero runtime.
	PluginTypeWASM PluginType = "wasm"

	// PluginTypeLua is a Lua script plugin (planned).
	PluginTypeLua PluginType = "lua"
)

type Registry

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

Registry manages loaded plugins.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new plugin registry.

func (*Registry) Close

func (r *Registry) Close() error

Close closes all plugins and clears the registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Plugin, bool)

Get retrieves a plugin by name.

func (*Registry) List

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

List returns info about all registered plugins.

func (*Registry) Register

func (r *Registry) Register(p Plugin, info PluginInfo) error

Register adds a plugin to the registry.

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a plugin from the registry.

type WASMPlugin

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

WASMPlugin represents a WebAssembly plugin loaded with wazero.

func LoadWASM

func LoadWASM(path string) (*WASMPlugin, error)

LoadWASM loads a WASM plugin from the specified path. The WASM module must export the following functions:

  • plugin_name() -> string
  • plugin_version() -> string
  • plugin_apply(input: string) -> (output: string, tokens_saved: int32)

func (*WASMPlugin) Apply

func (p *WASMPlugin) Apply(input string) (output string, tokensSaved int, err error)

Apply processes input text using the WASM plugin.

func (*WASMPlugin) Close

func (p *WASMPlugin) Close() error

Close releases resources held by the plugin.

func (*WASMPlugin) Name

func (p *WASMPlugin) Name() string

Name returns the plugin's unique identifier.

func (*WASMPlugin) Version

func (p *WASMPlugin) Version() string

Version returns the plugin version string.

type WASMPluginBuilder

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

WASMPluginBuilder helps build WASM plugins with a fluent API.

func NewWASMPluginBuilder

func NewWASMPluginBuilder(path string) *WASMPluginBuilder

NewWASMPluginBuilder creates a new WASM plugin builder.

func (*WASMPluginBuilder) Build

func (b *WASMPluginBuilder) Build() (*WASMPlugin, error)

Build loads and builds the WASM plugin.

func (*WASMPluginBuilder) WithMaxMemory

func (b *WASMPluginBuilder) WithMaxMemory(bytes uint32) *WASMPluginBuilder

WithMaxMemory sets the maximum memory for the WASM module.

func (*WASMPluginBuilder) WithStderr

func (b *WASMPluginBuilder) WithStderr(w *os.File) *WASMPluginBuilder

WithStderr redirects stderr to the given writer.

func (*WASMPluginBuilder) WithStdout

func (b *WASMPluginBuilder) WithStdout(w *os.File) *WASMPluginBuilder

WithStdout redirects stdout to the given writer.

Jump to

Keyboard shortcuts

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