adapter

package
v0.0.1-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package adapter - Tool plugin adapter system Provides plugin-based tool loading with hot-reload support

Package adapter - Configuration utilities

Package adapter provides a plugin-based tool management system with support for dynamic loading, hot-reload, and loose coupling.

Key components:

  • ToolAdapter: Main adapter that manages plugins
  • PluginLoader: Loads plugins from shared libraries (.so files)
  • JSONPluginLoader: Loads plugins from JSON configuration files
  • ConfigManager: Manages adapter configuration

Index

Constants

View Source
const (
	CapabilityRead       = "read"
	CapabilityWrite      = "write"
	CapabilityExec       = "exec"
	CapabilityNetwork    = "network"
	CapabilityMemory     = "memory"
	CapabilityFilesystem = "filesystem"
	CapabilityProcess    = "process"
	CapabilityWeb        = "web"
	CapabilityBrowser    = "browser"
	CapabilityCanvas     = "canvas"
	CapabilityNodes      = "nodes"
	CapabilityCron       = "cron"
	CapabilityGateway    = "gateway"
	CapabilityMessaging  = "messaging"
)

Capability constants

Variables

This section is empty.

Functions

func ReflectArgs

func ReflectArgs(args map[string]interface{}, expected interface{}) error

ReflectArgs converts args to the expected type using reflection

func SaveManifest

func SaveManifest(manifest PluginManifest, filePath string) error

SaveManifest saves a plugin manifest to file

func ValidateArgs

func ValidateArgs(args map[string]interface{}, required []string) error

ValidateArgs validates that required args are present

Types

type AdapterConfig

type AdapterConfig struct {
	PluginDir      string `json:"pluginDir"`
	AutoReload     bool   `json:"autoReload"`
	ReloadInterval int    `json:"reloadIntervalSeconds"`
	MaxRetries     int    `json:"maxRetries"`
	Timeout        int    `json:"defaultTimeoutSeconds"`
}

AdapterConfig holds adapter configuration

func DefaultAdapterConfig

func DefaultAdapterConfig() AdapterConfig

DefaultAdapterConfig returns default configuration

type AdapterConfigV1

type AdapterConfigV1 struct {
	Version     string                    `json:"version"`
	PluginDir   string                    `json:"pluginDir"`
	ConfigDir   string                    `json:"configDir"`
	AutoReload  bool                      `json:"autoReload"`
	ReloadSecs  int                       `json:"reloadIntervalSeconds"`
	MaxRetries  int                       `json:"maxRetries"`
	TimeoutSecs int                       `json:"defaultTimeoutSeconds"`
	Plugins     map[string]PluginConfigV1 `json:"plugins"`
}

AdapterConfigV1 represents the adapter configuration version 1

func DefaultConfigV1

func DefaultConfigV1() *AdapterConfigV1

DefaultConfigV1 returns the default configuration

type ConfigManager

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

ConfigManager manages adapter configuration

func NewConfigManager

func NewConfigManager(configDir string) *ConfigManager

NewConfigManager creates a new configuration manager

func (*ConfigManager) Load

func (c *ConfigManager) Load() (*AdapterConfigV1, error)

Load loads the configuration from file

func (*ConfigManager) LoadOrCreate

func (c *ConfigManager) LoadOrCreate() (*AdapterConfigV1, error)

LoadOrCreate loads existing config or creates a new one

func (*ConfigManager) Save

func (c *ConfigManager) Save(config *AdapterConfigV1) error

Save saves the configuration to file

type Context

type Context struct {
	AgentName  string
	SessionID  string
	Workspace  string
	GatewayURL string
	UserID     string
	Channel    string
	Timestamp  int64
	Extra      map[string]interface{}
}

Context holds the execution context for tools

func (*Context) GetContextString

func (c *Context) GetContextString(key string) string

GetContextString retrieves a string from context

type ManifestData

type ManifestData struct {
	Version      string   `json:"version"`
	APIVersion   string   `json:"apiVersion"`
	Capabilities []string `json:"capabilities"`
	Dependencies []string `json:"dependencies,omitempty"`
	Entrypoint   string   `json:"entrypoint,omitempty"`
}

ManifestData contains manifest data

type PluginBase

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

PluginBase provides common functionality for plugins

func (*PluginBase) GetConfig

func (p *PluginBase) GetConfig(key string) string

func (*PluginBase) SetConfig

func (p *PluginBase) SetConfig(key string, value interface{})

type PluginConfigV1

type PluginConfigV1 struct {
	Enabled     bool                   `json:"enabled"`
	Type        string                 `json:"type"` // "builtin", "external", "wasm"
	Config      map[string]interface{} `json:"config"`
	Permissions map[string]bool        `json:"permissions,omitempty"`
}

PluginConfigV1 represents a plugin configuration

type PluginInfo

type PluginInfo struct {
	Name        string                 `json:"name"`
	Version     string                 `json:"version"`
	Description string                 `json:"description"`
	Author      string                 `json:"author"`
	Schema      map[string]interface{} `json:"schema,omitempty"`
	Tags        []string               `json:"tags,omitempty"`
}

PluginInfo contains metadata about a plugin

type PluginLoader

type PluginLoader interface {
	// PluginInfo returns metadata about the plugin
	PluginInfo() PluginInfo

	// Initialize is called when the plugin is loaded
	Initialize(config map[string]interface{}) error

	// Execute runs the tool with given arguments
	Execute(args map[string]interface{}) (interface{}, error)

	// Shutdown is called when the plugin is unloaded
	Shutdown() error

	// HealthCheck verifies the plugin is working
	HealthCheck() error
}

PluginLoader defines the interface for tool plugins

func ConvertToolToPlugin

func ConvertToolToPlugin(name, description string, executeFunc func(args map[string]interface{}) (interface{}, error)) PluginLoader

ConvertToolToPlugin converts a legacy tool to a plugin

func MakePlugin

func MakePlugin(name, version, description string, executeFunc interface{}) (PluginLoader, error)

MakePlugin is a helper to create a plugin from functions

type PluginManifest

type PluginManifest struct {
	Info     PluginInfo   `json:"info"`
	Manifest ManifestData `json:"manifest"`
}

PluginManifest represents a plugin manifest file

func CreatePluginManifest

func CreatePluginManifest(info PluginInfo, capabilities []string) PluginManifest

CreatePluginManifest creates a plugin manifest

func LoadManifest

func LoadManifest(filePath string) (*PluginManifest, error)

LoadManifest loads a plugin manifest from file

type PluginRegistry

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

PluginRegistry maintains a registry of all loaded plugins

func NewPluginRegistry

func NewPluginRegistry() *PluginRegistry

func (*PluginRegistry) Add

func (r *PluginRegistry) Add(info PluginInfo)

func (*PluginRegistry) Get

func (r *PluginRegistry) Get(name string) (PluginInfo, bool)

func (*PluginRegistry) List

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

func (*PluginRegistry) Remove

func (r *PluginRegistry) Remove(name string)

type Result

type Result struct {
	Success  bool                   `json:"success"`
	Data     interface{}            `json:"data,omitempty"`
	Error    string                 `json:"error,omitempty"`
	Duration int64                  `json:"duration_ms"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Result represents a tool execution result

func NewErrorResult

func NewErrorResult(err error) *Result

NewErrorResult creates an error result

func NewResult

func NewResult(data interface{}) *Result

NewResult creates a successful result

func (*Result) GetBool

func (r *Result) GetBool(key string) bool

func (*Result) GetInt

func (r *Result) GetInt(key string) int

func (*Result) GetString

func (r *Result) GetString(key string) string

Type-safe result getters

func (*Result) ToJSON

func (r *Result) ToJSON() ([]byte, error)

JSON Marshal helpers for tool results

func (*Result) ToString

func (r *Result) ToString() string

type ToolAdapter

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

ToolAdapter is the main adapter that manages plugins

func CreateBuiltinAdapter

func CreateBuiltinAdapter(workspace string) *ToolAdapter

CreateBuiltinAdapter creates an adapter with all built-in tools

func NewToolAdapter

func NewToolAdapter(cfg AdapterConfig) *ToolAdapter

NewToolAdapter creates a new tool adapter

func (*ToolAdapter) ExecuteTool

func (a *ToolAdapter) ExecuteTool(name string, args map[string]interface{}, ctx *Context) *Result

ExecuteTool runs a tool by name

func (*ToolAdapter) GetAllToolSpecs

func (a *ToolAdapter) GetAllToolSpecs() []ToolSpec

GetAllToolSpecs returns all tool specifications

func (*ToolAdapter) GetPluginInfo

func (a *ToolAdapter) GetPluginInfo(name string) (*PluginInfo, error)

GetPluginInfo returns info about a specific plugin

func (*ToolAdapter) GetRegistry

func (a *ToolAdapter) GetRegistry() *PluginRegistry

GetRegistry returns the plugin registry

func (*ToolAdapter) GetToolCount

func (a *ToolAdapter) GetToolCount() int

GetToolCount returns the number of registered tools

func (*ToolAdapter) GetToolDocumentation

func (a *ToolAdapter) GetToolDocumentation() string

GetToolDocumentation returns markdown documentation for all tools

func (*ToolAdapter) GetToolSpec

func (a *ToolAdapter) GetToolSpec(name string) (*ToolSpec, error)

GetToolSpec returns the OpenAI-compatible tool specification

func (*ToolAdapter) HasTool

func (a *ToolAdapter) HasTool(name string) bool

HasTool checks if a tool is registered

func (*ToolAdapter) ListTools

func (a *ToolAdapter) ListTools() []string

ListTools returns the list of registered tool names

func (*ToolAdapter) RegisterPlugin

func (a *ToolAdapter) RegisterPlugin(name string, plugin PluginLoader) error

RegisterPlugin registers a plugin with the adapter

func (*ToolAdapter) Shutdown

func (a *ToolAdapter) Shutdown() error

Shutdown unloads all plugins

func (*ToolAdapter) UnregisterPlugin

func (a *ToolAdapter) UnregisterPlugin(name string) error

UnregisterPlugin removes a plugin from the adapter

type ToolSpec

type ToolSpec struct {
	Type     string `json:"type"`
	Function struct {
		Name        string                 `json:"name"`
		Description string                 `json:"description"`
		Parameters  map[string]interface{} `json:"parameters"`
	} `json:"function"`
}

ToolSpec defines the OpenAI-compatible tool specification

Jump to

Keyboard shortcuts

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