runner

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelEventBus

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

ChannelEventBus is the default EventBus implementation using a buffered channel.

func NewEventBus

func NewEventBus(bufferSize int) *ChannelEventBus

NewEventBus creates a new ChannelEventBus with the given buffer size.

func (*ChannelEventBus) Close

func (b *ChannelEventBus) Close()

Close closes the event bus.

func (*ChannelEventBus) Events

func (b *ChannelEventBus) Events() <-chan Event

Events returns the channel to receive events from.

func (*ChannelEventBus) Send

func (b *ChannelEventBus) Send(event Event)

Send sends an event to the bus. Non-blocking; drops if buffer full.

type Event

type Event interface {
	Type() EventType
	Timestamp() time.Time
}

Event is the base interface for all events emitted by the runner.

type EventBus

type EventBus interface {
	// Send sends an event to the bus. Non-blocking; drops if buffer full.
	Send(event Event)
	// Events returns the channel to receive events from.
	Events() <-chan Event
	// Close closes the event bus.
	Close()
}

EventBus receives events from the runner for TUI consumption.

type EventType

type EventType int

EventType identifies the kind of event.

const (
	EventTypeStatus EventType = iota
	EventTypeMessage
	EventTypeTool
	EventTypeLog
)

type IncomingMessage

type IncomingMessage struct {
	SessionID string `json:"session_id,omitempty"`
	Content   string `json:"content,omitempty"`
}

IncomingMessage represents a structured message with optional session info.

type LogEvent

type LogEvent struct {
	Time    time.Time
	Level   LogLevel
	Message string
	Attrs   map[string]any
}

LogEvent represents a log entry.

func (LogEvent) Timestamp

func (e LogEvent) Timestamp() time.Time

func (LogEvent) Type

func (e LogEvent) Type() EventType

type LogLevel

type LogLevel int

LogLevel mirrors slog levels for the TUI.

const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
)

type MCPManager

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

MCPManager manages MCP server connections and tool execution.

func NewMCPManager

func NewMCPManager(logger *slog.Logger) *MCPManager

NewMCPManager creates a new MCP manager.

func (*MCPManager) CallTool

func (m *MCPManager) CallTool(ctx context.Context, name string, args json.RawMessage) (string, error)

CallTool executes a tool call and returns the result.

func (*MCPManager) Close

func (m *MCPManager) Close() error

Close shuts down all MCP server connections.

func (*MCPManager) GetAthyrTools

func (m *MCPManager) GetAthyrTools() []athyr.Tool

GetAthyrTools returns all discovered tools in athyr.Tool format.

func (*MCPManager) GetServerForTool

func (m *MCPManager) GetServerForTool(toolName string) string

GetServerForTool returns the server name that provides a given tool.

func (*MCPManager) GetToolsInfo

func (m *MCPManager) GetToolsInfo() []ToolInfo

GetToolsInfo returns tool information including which server they came from.

func (*MCPManager) RegisterTool

func (m *MCPManager) RegisterTool(serverName string, tool athyr.Tool)

RegisterTool manually registers a tool (useful for testing or shell tools).

func (*MCPManager) SetToolExecutor

func (m *MCPManager) SetToolExecutor(executor ToolExecutor)

SetToolExecutor sets a custom tool executor (useful for testing).

func (*MCPManager) Start

func (m *MCPManager) Start(ctx context.Context, servers []config.MCPServerConfig) error

Start connects to all configured MCP servers and discovers their tools.

type MessageDirection

type MessageDirection int

MessageDirection indicates whether a message is incoming or outgoing.

const (
	MessageIncoming MessageDirection = iota
	MessageOutgoing
)

type MessageEvent

type MessageEvent struct {
	Time      time.Time
	Direction MessageDirection
	Topic     string
	Content   string
	Model     string
	Tokens    int
}

MessageEvent represents a message sent or received.

func (MessageEvent) Timestamp

func (e MessageEvent) Timestamp() time.Time

func (MessageEvent) Type

func (e MessageEvent) Type() EventType

type MessageHandler

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

MessageHandler processes incoming messages through the LLM.

func (*MessageHandler) DirectChat

func (h *MessageHandler) DirectChat(content string) (response string, model string, tokens int, err error)

DirectChat sends a message directly to the LLM and returns the response. This is used by the TUI for interactive chat without going through pub/sub.

func (*MessageHandler) Handle

func (h *MessageHandler) Handle(msg athyr.SubscribeMessage)

Handle processes a single incoming message.

func (*MessageHandler) PublishMessage

func (h *MessageHandler) PublishMessage(topic string, data []byte) error

PublishMessage sends a message to a topic (fire-and-forget). This is used by the TUI to send messages without waiting for a response.

func (*MessageHandler) RequestMessage

func (h *MessageHandler) RequestMessage(topic string, data []byte) ([]byte, error)

RequestMessage sends a message to a topic and waits for a reply. This uses the request/reply pattern with a 30 second timeout.

func (*MessageHandler) StopWatching

func (h *MessageHandler) StopWatching() error

StopWatching stops the current watch subscription if any.

func (*MessageHandler) WatchTopic

func (h *MessageHandler) WatchTopic(topic string, callback WatchCallback) error

WatchTopic subscribes to a topic and calls the callback for each message. Only one topic can be watched at a time; calling this again will stop the previous watch.

func (*MessageHandler) WatchingTopic

func (h *MessageHandler) WatchingTopic() string

WatchingTopic returns the currently watched topic, or empty string if not watching.

type Options

type Options struct {
	ServerAddr string
	Insecure   bool
	Logger     *slog.Logger
	EventBus   EventBus // Optional: for TUI mode
}

Options configures the runner.

type Response

type Response struct {
	Content      string `json:"content"`
	Model        string `json:"model"`
	SourceTopic  string `json:"source_topic"`
	Tokens       int    `json:"tokens"`
	FinishReason string `json:"finish_reason"`
}

Response is the structure published to output topics.

type Runner

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

Runner manages the agent lifecycle.

func New

func New(cfg *config.Config, opts Options) (*Runner, error)

New creates a new Runner.

func (*Runner) AgentID

func (r *Runner) AgentID() string

AgentID returns the connected agent's ID, or empty if not connected.

func (*Runner) Config

func (r *Runner) Config() *config.Config

Config returns the runner's configuration.

func (*Runner) Handler

func (r *Runner) Handler() *MessageHandler

Handler returns the message handler, used by the TUI for direct chat.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run starts the agent and blocks until context is cancelled.

type StatusEvent

type StatusEvent struct {
	Time      time.Time
	Connected bool
	AgentID   string
	AgentName string
	Error     error
}

StatusEvent indicates a change in connection status.

func (StatusEvent) Timestamp

func (e StatusEvent) Timestamp() time.Time

func (StatusEvent) Type

func (e StatusEvent) Type() EventType

type ToolEvent

type ToolEvent struct {
	Time     time.Time
	Status   ToolStatus
	Name     string
	Args     string
	Result   string
	Error    error
	Duration time.Duration
}

ToolEvent represents a tool execution.

func (ToolEvent) Timestamp

func (e ToolEvent) Timestamp() time.Time

func (ToolEvent) Type

func (e ToolEvent) Type() EventType

type ToolExecutor

type ToolExecutor func(ctx context.Context, name string, args json.RawMessage) (string, error)

ToolExecutor is a function that executes a tool call.

type ToolInfo

type ToolInfo struct {
	Name        string
	Description string
	Server      string // MCP server name
}

ToolInfo describes an available tool.

type ToolStatus

type ToolStatus int

ToolStatus indicates the state of a tool execution.

const (
	ToolStarted ToolStatus = iota
	ToolCompleted
	ToolFailed
)

type ToolsAvailableEvent

type ToolsAvailableEvent struct {
	Time  time.Time
	Tools []ToolInfo
}

ToolsAvailableEvent is emitted when MCP tools are discovered.

func (ToolsAvailableEvent) Timestamp

func (e ToolsAvailableEvent) Timestamp() time.Time

func (ToolsAvailableEvent) Type

func (e ToolsAvailableEvent) Type() EventType

type WatchCallback

type WatchCallback func(timestamp time.Time, content string)

WatchCallback is called when a message is received on a watched topic.

Jump to

Keyboard shortcuts

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