sdk

package module
v0.0.0-...-21f71e9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunIO

func RunIO(in io.Reader, out io.Writer, logOut io.Writer, p Plugin, onCommand CommandFunc) error

RunIO runs the plugin JSON line protocol on the given streams. logOut receives the standard library logger output; if nil, os.Stderr is used.

func RunStdio

func RunStdio(p Plugin, onCommand CommandFunc) error

RunStdio runs the plugin protocol on os.Stdin / os.Stdout, logging to os.Stderr.

func ValidateManifest

func ValidateManifest(manifest *PluginManifest) error

ValidateManifest validates a plugin manifest

Types

type BasePlugin

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

BasePlugin provides a basic implementation of the Plugin interface

func NewBasePlugin

func NewBasePlugin(name string) *BasePlugin

NewBasePlugin creates a new base plugin

func (*BasePlugin) Commands

func (p *BasePlugin) Commands() []PluginCommand

Commands provides a default implementation that returns no commands

func (*BasePlugin) GetConfig

func (p *BasePlugin) GetConfig() Config

GetConfig returns the plugin configuration

func (*BasePlugin) GetHost

func (p *BasePlugin) GetHost() PluginHost

GetHost returns the plugin host

func (*BasePlugin) Init

func (p *BasePlugin) Init(config Config) error

Init initializes the base plugin

func (*BasePlugin) Name

func (p *BasePlugin) Name() string

Name returns the plugin name

func (*BasePlugin) OnMessage

func (p *BasePlugin) OnMessage(msg Message) ([]Message, error)

OnMessage provides a default implementation that does nothing

func (*BasePlugin) SetHost

func (p *BasePlugin) SetHost(host PluginHost)

SetHost sets the plugin host

type CommandFunc

type CommandFunc func(command string, args []string) PluginResponse

CommandFunc handles chat commands from the host (PluginRequest with Type "command"). Return the full PluginResponse; for chat output the Type is typically "message" with Data holding a marshaled Message, matching existing plugin examples. If onCommand is nil, command requests receive an "unknown command" error response.

type Config

type Config struct {
	PluginDir string            `json:"plugin_dir"`
	DataDir   string            `json:"data_dir"`
	Settings  map[string]string `json:"settings"`
}

Config represents plugin configuration

type InitRequestData

type InitRequestData struct {
	Config *Config `json:"config,omitempty"`
}

InitRequestData is the JSON object the host sends as PluginRequest.Data for type "init". If "config" is absent or JSON null, HandlePluginRequest skips calling Init (legacy host compatibility).

type Message

type Message struct {
	Sender    string    `json:"sender"`
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
	Type      string    `json:"type,omitempty"`
	Channel   string    `json:"channel,omitempty"`
	Encrypted bool      `json:"encrypted,omitempty"`
	MessageID int64     `json:"message_id,omitempty"`
	Recipient string    `json:"recipient,omitempty"`
	Edited    bool      `json:"edited,omitempty"`
}

Message represents a chat message.

Fields added after the initial SDK release (Channel, Encrypted, MessageID, Recipient, Edited) use omitempty and are backwards-compatible: older plugins that were compiled against the 4-field struct silently ignore the extra JSON keys on input and omit them on output.

type Plugin

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

	// Init initializes the plugin with configuration
	Init(config Config) error

	// OnMessage is called when a new message is received
	// Plugins can return additional messages to be sent
	OnMessage(msg Message) ([]Message, error)

	// Commands returns the list of commands this plugin registers
	Commands() []PluginCommand
}

Plugin is the main interface that all marchat plugins must implement

type PluginCommand

type PluginCommand struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Usage       string `json:"usage"`
	AdminOnly   bool   `json:"admin_only"`
}

PluginCommand represents a command that a plugin can register

type PluginHost

type PluginHost interface {
	// SendMessage sends a message to the chat
	SendMessage(msg Message) error

	// GetUsers returns the list of online users
	GetUsers() []string

	// GetSetting retrieves a plugin setting
	GetSetting(key string) string

	// SetSetting stores a plugin setting
	SetSetting(key, value string) error

	// Log logs a message to the host's log system
	Log(level, message string)
}

PluginHost provides methods for plugins to interact with the host

type PluginManifest

type PluginManifest struct {
	Name        string            `json:"name"`
	Version     string            `json:"version"`
	Description string            `json:"description"`
	Author      string            `json:"author"`
	License     string            `json:"license"`
	Repository  string            `json:"repository,omitempty"`
	Homepage    string            `json:"homepage,omitempty"`
	Commands    []PluginCommand   `json:"commands"`
	Permissions []string          `json:"permissions"`
	Settings    map[string]string `json:"settings,omitempty"`
	MinVersion  string            `json:"min_version,omitempty"`
	MaxVersion  string            `json:"max_version,omitempty"`
}

PluginManifest contains metadata about a plugin

type PluginRequest

type PluginRequest struct {
	Type    string          `json:"type"`
	Command string          `json:"command,omitempty"`
	Data    json.RawMessage `json:"data,omitempty"`
}

PluginRequest represents a request to a plugin

type PluginResponse

type PluginResponse struct {
	Type    string          `json:"type"`
	Success bool            `json:"success"`
	Data    json.RawMessage `json:"data,omitempty"`
	Error   string          `json:"error,omitempty"`
}

PluginResponse represents a response from a plugin

func HandlePluginRequest

func HandlePluginRequest(p Plugin, req PluginRequest, onCommand CommandFunc) PluginResponse

HandlePluginRequest dispatches one host request to a Plugin implementation. init, message, and shutdown are handled internally; command is delegated to onCommand.

Jump to

Keyboard shortcuts

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