agentboot

package
v0.26041.1000-preview Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MPL-2.0 Imports: 6 Imported by: 0

README

AgentBoot Package

AgentBoot is a unified agent bootstrapping and management package that provides a clean abstraction for running different AI coding agents.

Features

  • Unified Agent Interface: Common interface for all agent types
  • Stream-JSON Support: Real-time event streaming for rich output
  • Permission Management: Flexible permission handling with multiple modes
  • Extensible Design: Easy to add new agent types
  • Configuration: Environment-based configuration

Supported Agents

Agent Status Description
claude ✅ Implemented Claude Code CLI
codex 🚧 Planned OpenAI Codex
gemini 🚧 Planned Google Gemini
cursor 🚧 Planned Cursor AI

Usage

Basic Usage
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/tingly-dev/tingly-box/agentboot"
    _ "github.com/tingly-dev/tingly-box/agentboot/claude" // Import to register Claude agent
)

func main() {
    // Create AgentBoot instance
    ab := agentboot.New(agentboot.Config{
        DefaultAgent:     agentboot.AgentTypeClaude,
        DefaultFormat:    agentboot.OutputFormatStreamJSON,
        EnableStreamJSON: true,
    })

    // Register Claude agent (or use agents that have auto-registered via init())
    claudeAgent := claude.NewAgent(ab.GetConfig())
    ab.RegisterAgent(agentboot.AgentTypeClaude, claudeAgent)

    // Get Claude agent
    agent, err := ab.GetAgent(agentboot.AgentTypeClaude)
    if err != nil {
        log.Fatal(err)
    }

    // Execute prompt
    result, err := agent.Execute(context.Background(), "Say hello", agentboot.ExecutionOptions{
        OutputFormat: agentboot.OutputFormatStreamJSON,
    })

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(result.TextOutput())
}
Alternative: Using Claude Agent Directly
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/tingly-dev/tingly-box/agentboot"
    "github.com/tingly-dev/tingly-box/agentboot/claude"
)

func main() {
    // Create config
    config := agentboot.Config{
        DefaultFormat:    agentboot.OutputFormatStreamJSON,
        EnableStreamJSON: true,
    }

    // Create Claude agent directly
    agent := claude.NewAgent(config)

    // Execute prompt
    result, err := agent.Execute(context.Background(), "Say hello", agentboot.ExecutionOptions{
        OutputFormat: agentboot.OutputFormatStreamJSON,
    })

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(result.TextOutput())
}
With Permission Handler
package main

import (
    "context"
    "log"

    "github.com/tingly-dev/tingly-box/agentboot"
    "github.com/tingly-dev/tingly-box/agentboot/claude"
    "github.com/tingly-dev/tingly-box/agentboot/permission"
)

func main() {
    // Create configuration
    config := agentboot.Config{
        DefaultFormat:    agentboot.OutputFormatStreamJSON,
        EnableStreamJSON: true,
    }

    // Create permission handler
    permHandler := permission.NewDefaultHandler(permission.Config{
        DefaultMode: agentboot.PermissionModeManual,
        Timeout:     300, // 5 minutes
    })

    // Create agent with permission handler
    agent := claude.NewAgentWithPermissionHandler(config, permHandler)

    // Set permission mode for a session
    permHandler.SetMode("session-123", agentboot.PermissionModeAuto)

    // Execute prompt
    result, err := agent.Execute(context.Background(), "List files", agentboot.ExecutionOptions{
        OutputFormat: agentboot.OutputFormatStreamJSON,
    })

    if err != nil {
        log.Fatal(err)
    }

    log.Println(result.TextOutput())
}

Output Formats

Text Format

Simple text output (default):

claude --print --output-format text "Say hello"
Stream-JSON Format

Rich event streaming:

claude --output-format stream-json --verbose --print "Say hello"

Event types:

  • text_delta - Incremental text output
  • tool_call_start - Tool invocation begins
  • tool_call_end - Tool completes
  • permission_request - Permission needed
  • status - Agent status change
  • thinking - Reasoning state

Permission Modes

Mode Description
auto Auto-approve all requests
manual Require user approval
skip Skip permission prompts

Configuration

Environment Variables
Variable Description Default
AGENTBOOT_DEFAULT_AGENT Default agent type claude
AGENTBOOT_DEFAULT_FORMAT Default output format text
AGENTBOOT_ENABLE_STREAM_JSON Enable stream-json true
AGENTBOOT_STREAM_BUFFER_SIZE Event buffer size 100
RCC_PERMISSION_MODE Permission mode auto
RCC_PERMISSION_TIMEOUT Approval timeout 5m
RCC_WHITELIST Whitelisted tools
RCC_BLACKLIST Blacklisted tools

Package Structure

agentboot/
├── agentboot.go      # Core package and factory
├── types.go          # Common types and interfaces
├── config.go         # Configuration
├── events/           # Event streaming
│   ├── events.go     # Event interfaces
│   ├── parser.go     # Stream parser
│   └── bus.go        # Event bus
├── permission/       # Permission management
│   ├── handler.go    # Permission handler interface
│   ├── handler_impl.go # Default implementation
│   └── store.go      # Permission history storage
└── claude/           # Claude Code agent
    ├── agent.go      # Claude agent
    ├── launcher.go   # Process launcher
    ├── config.go     # Claude config
    └── events.go     # Claude event types

Adding a New Agent

  1. Create agent package: agentboot/youragent/

  2. Implement agent.Agent interface:

type Agent struct {
    launcher *Launcher
}

func (a *Agent) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (*agentboot.Result, error)
func (a *Agent) IsAvailable() bool
func (a *Agent) Type() agentboot.AgentType
func (a *Agent) SetDefaultFormat(format agentboot.OutputFormat)
func (a *Agent) GetDefaultFormat() agentboot.OutputFormat
  1. Register in agentboot.go:
ab.agents[AgentTypeYourAgent] = youragent.NewAgent(ab.config)

License

MIT

Documentation

Index

Constants

View Source
const (
	// EventTypeInit indicates agent initialization
	EventTypeInit = "init"
	// EventTypeSystem indicates system-level messages
	EventTypeSystem = "system"
	// EventTypeAssistant indicates assistant/agent response messages
	EventTypeAssistant = "assistant"
	// EventTypeUser indicates user messages (echoed back)
	EventTypeUser = "user"
	// EventTypeToolUse indicates a tool is being invoked
	EventTypeToolUse = "tool_use"
	// EventTypeToolResult indicates the result of a tool invocation
	EventTypeToolResult = "tool_result"
	// EventTypePermissionRequest indicates a permission request is pending
	EventTypePermissionRequest = "permission_request"
	// EventTypePermissionResult indicates the result of a permission request
	EventTypePermissionResult = "permission_result"
	// EventTypeResult indicates the final result of execution
	EventTypeResult = "result"
	// EventTypeError indicates an error occurred
	EventTypeError = "error"
	// EventTypeStreamDelta indicates incremental streaming content
	EventTypeStreamDelta = "stream_delta"
)

EventType constants for unified agent events All agents should map their internal events to these standard types

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	// Execute runs the agent with the given prompt
	Execute(ctx context.Context, prompt string, opts ExecutionOptions) (*Result, error)

	// IsAvailable checks if the agent is available
	IsAvailable() bool

	// Type returns the agent type
	Type() AgentType

	// SetDefaultFormat sets the default output format
	SetDefaultFormat(format OutputFormat)

	// GetDefaultFormat returns the current default format
	GetDefaultFormat() OutputFormat
}

Agent is the interface for all agent types

type AgentBoot

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

AgentBoot manages agent instances

func New

func New(config Config) *AgentBoot

New creates a new AgentBoot instance

func (*AgentBoot) GetAgent

func (ab *AgentBoot) GetAgent(agentType AgentType) (Agent, error)

GetAgent returns an agent by type

func (*AgentBoot) GetConfig

func (ab *AgentBoot) GetConfig() Config

GetConfig returns the current configuration

func (*AgentBoot) GetDefaultAgent

func (ab *AgentBoot) GetDefaultAgent() (Agent, error)

GetDefaultAgent returns the default agent

func (*AgentBoot) ListAgents

func (ab *AgentBoot) ListAgents() []AgentType

ListAgents returns all registered agent types

func (*AgentBoot) MustGetAgent

func (ab *AgentBoot) MustGetAgent(agentType AgentType) Agent

MustGetAgent returns an agent by type or panics

func (*AgentBoot) RegisterAgent

func (ab *AgentBoot) RegisterAgent(agentType AgentType, agent Agent)

RegisterAgent registers a new agent type

func (*AgentBoot) SetDefaultAgent

func (ab *AgentBoot) SetDefaultAgent(agentType AgentType) error

SetDefaultAgent sets the default agent type

type AgentMessage

type AgentMessage interface {
	// GetType returns the message type (one of EventType constants)
	GetType() string
	// GetTimestamp returns when the message was created
	GetTimestamp() time.Time
	// GetSessionID returns the session ID if available
	GetSessionID() string
	// GetAgentType returns the source agent type
	GetAgentType() AgentType
	// GetRawData returns the raw message data as a map
	GetRawData() map[string]interface{}
	// ToEvent converts the message to an Event
	ToEvent() Event
}

AgentMessage is the unified interface for all agent messages All agent implementations should convert their messages to this interface

func MessageFromEvent

func MessageFromEvent(event Event, agentType AgentType) AgentMessage

MessageFromEvent converts an Event to an AgentMessage if possible

type AgentType

type AgentType string

AgentType defines the supported agent types

const (
	AgentTypeClaude    AgentType = "claude"
	AgentTypeMockAgent AgentType = "mock" // Mock agent for testing

)

func (AgentType) String

func (t AgentType) String() string

String returns the string representation of AgentType

type ApprovalHandler

type ApprovalHandler interface {
	OnApproval(ctx context.Context, req PermissionRequest) (PermissionResult, error)
}

ApprovalHandler handles permission confirmations

type AskHandler

type AskHandler interface {
	OnAsk(ctx context.Context, req AskRequest) (AskResult, error)
}

AskHandler handles user questions/selections

type AskRequest

type AskRequest struct {
	ID   string `json:"id"`
	Type string `json:"type"` // "permission", "question", "confirmation", "text_input"

	Platform  string `json:"platform"`
	ChatID    string `json:"chat_id"`
	BotUUID   string `json:"bot_uuid"`
	SessionID string `json:"session_id,omitempty"`

	AgentType AgentType              `json:"agent_type"`
	ToolName  string                 `json:"tool_name,omitempty"`
	Input     map[string]interface{} `json:"input,omitempty"`
	Message   string                 `json:"message,omitempty"`
	CallID    string                 `json:"call_id,omitempty"`
	Reason    string                 `json:"reason,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

AskRequest represents a request to ask the user something This is a simplified version of ask.Request to avoid circular imports

type AskResult

type AskResult struct {
	ID           string                 `json:"id"`
	Approved     bool                   `json:"approved,omitempty"`
	Response     string                 `json:"response,omitempty"`
	Selection    map[string]interface{} `json:"selection,omitempty"`
	Remember     bool                   `json:"remember,omitempty"`
	Reason       string                 `json:"reason,omitempty"`
	UpdatedInput map[string]interface{} `json:"updated_input,omitempty"`
}

AskResult represents the user's response to an ask request

type AssistantMessage

type AssistantMessage struct {
	BaseMessage
	Text    string                 `json:"text,omitempty"`
	Content []ContentBlock         `json:"content,omitempty"`
	Extra   map[string]interface{} `json:"extra,omitempty"`
}

AssistantMessage represents an assistant response

func NewAssistantMessage

func NewAssistantMessage(agentType AgentType, sessionID, text string) *AssistantMessage

NewAssistantMessage creates a new assistant message

func (*AssistantMessage) GetRawData

func (m *AssistantMessage) GetRawData() map[string]interface{}

GetRawData returns raw data

func (*AssistantMessage) GetText

func (m *AssistantMessage) GetText() string

GetText returns the text content

func (*AssistantMessage) ToEvent

func (m *AssistantMessage) ToEvent() Event

ToEvent converts AssistantMessage to Event

type BaseMessage

type BaseMessage struct {
	Type      string    `json:"type"`
	AgentType AgentType `json:"agent_type"`
	SessionID string    `json:"session_id,omitempty"`
	Timestamp time.Time `json:"timestamp"`
}

BaseMessage provides common fields for message implementations

func (*BaseMessage) GetAgentType

func (m *BaseMessage) GetAgentType() AgentType

GetAgentType returns the agent type

func (*BaseMessage) GetRawData

func (m *BaseMessage) GetRawData() map[string]interface{}

GetRawData returns the raw data - should be overridden by embedders

func (*BaseMessage) GetSessionID

func (m *BaseMessage) GetSessionID() string

GetSessionID returns the session ID

func (*BaseMessage) GetTimestamp

func (m *BaseMessage) GetTimestamp() time.Time

GetTimestamp returns the timestamp

func (*BaseMessage) GetType

func (m *BaseMessage) GetType() string

GetType returns the message type

func (*BaseMessage) ToEvent

func (m *BaseMessage) ToEvent() Event

ToEvent converts BaseMessage to Event - should be overridden by embedders

type CompletionCallback

type CompletionCallback interface {
	OnComplete(result *CompletionResult)
}

CompletionCallback handles completion notification

type CompletionResult

type CompletionResult struct {
	Success     bool
	DurationMS  int64
	SessionID   string
	Error       string
	ExtraFields map[string]any
}

CompletionResult contains the final result information

type CompositeHandler

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

CompositeHandler combines multiple handler interfaces into one MessageHandler. It allows composing different handlers for streaming, approval, ask, and completion.

func NewCompositeHandler

func NewCompositeHandler() *CompositeHandler

NewCompositeHandler creates a new empty CompositeHandler. Use Set* methods to configure individual handlers.

func (*CompositeHandler) OnApproval

OnApproval implements MessageHandler. Forwards to the ApprovalHandler if set, otherwise auto-approves.

func (*CompositeHandler) OnAsk

func (h *CompositeHandler) OnAsk(ctx context.Context, req AskRequest) (AskResult, error)

OnAsk implements MessageHandler. Forwards to the AskHandler if set, otherwise auto-approves.

func (*CompositeHandler) OnComplete

func (h *CompositeHandler) OnComplete(result *CompletionResult)

OnComplete implements MessageHandler. Forwards to the CompletionCallback if set.

func (*CompositeHandler) OnError

func (h *CompositeHandler) OnError(err error)

OnError implements MessageHandler. Forwards to the MessageStreamer if set.

func (*CompositeHandler) OnMessage

func (h *CompositeHandler) OnMessage(msg interface{}) error

OnMessage implements MessageHandler. Forwards to the MessageStreamer if set.

func (*CompositeHandler) SetApprovalHandler

func (h *CompositeHandler) SetApprovalHandler(a ApprovalHandler) *CompositeHandler

SetApprovalHandler sets the approval handler. Returns self for chaining.

func (*CompositeHandler) SetAskHandler

func (h *CompositeHandler) SetAskHandler(a AskHandler) *CompositeHandler

SetAskHandler sets the ask handler. Returns self for chaining.

func (*CompositeHandler) SetCompletionCallback

func (h *CompositeHandler) SetCompletionCallback(c CompletionCallback) *CompositeHandler

SetCompletionCallback sets the completion callback. Returns self for chaining.

func (*CompositeHandler) SetStreamer

SetStreamer sets the message streamer handler. Returns self for chaining.

type Config

type Config struct {
	DefaultAgent            AgentType     `json:"default_agent"`
	DefaultFormat           OutputFormat  `json:"default_format"`
	EnableStreamJSON        bool          `json:"enable_stream_json"`
	StreamBufferSize        int           `json:"stream_buffer_size"`
	DefaultExecutionTimeout time.Duration `json:"default_execution_timeout"`
}

Config holds the AgentBoot configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default AgentBoot configuration

type ContentBlock

type ContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
	// For tool_use
	ToolID   string                 `json:"tool_id,omitempty"`
	ToolName string                 `json:"tool_name,omitempty"`
	Input    map[string]interface{} `json:"input,omitempty"`
}

ContentBlock represents a block of content

type Event

type Event struct {
	Type      string                 `json:"type"`
	Data      map[string]interface{} `json:"data"`
	Timestamp time.Time              `json:"timestamp"`
	Raw       string                 `json:"raw,omitempty"`
}

Event represents a generic agent event

type ExecutionOptions

type ExecutionOptions struct {
	ProjectPath  string
	OutputFormat OutputFormat
	Timeout      time.Duration
	Env          []string
	// Handler is an optional message handler for real-time processing
	// If provided, messages will be streamed to the handler during execution
	Handler MessageHandler
	// SessionID is the session ID to use or resume
	// If Resume is true, --resume <session_id> is used to continue an existing session
	// If Resume is false, --session-id <session_id> is used to create a new session with specific ID
	SessionID string
	// Resume indicates whether to resume an existing session (true) or create a new one (false)
	Resume bool
	// ChatID is the chat ID for permission requests (used by mock agent)
	ChatID string
	// Platform is the platform for permission requests (used by mock agent)
	Platform string
	// BotUUID is the bot UUID for permission callbacks
	BotUUID string

	// Model selection (per-execution override)
	Model         string
	FallbackModel string

	// Execution control
	MaxTurns int

	// Tool filtering (per-execution override)
	AllowedTools    []string
	DisallowedTools []string

	// MCP servers (per-execution override)
	MCPServers      map[string]interface{}
	StrictMcpConfig bool

	// System prompts (per-execution override)
	CustomSystemPrompt string
	AppendSystemPrompt string

	// Permission mode (per-execution override)
	PermissionMode string

	// Settings path (per-execution override)
	SettingsPath string

	// PermissionPromptTool specifies the tool for permission prompts (e.g., "stdio")
	// When set to "stdio", permission requests are sent via stdin/stdout for callback handling
	PermissionPromptTool string
}

ExecutionOptions controls agent execution

type HandlerBuilder

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

HandlerBuilder provides a fluent API for building CompositeHandler instances.

func NewHandlerBuilder

func NewHandlerBuilder() *HandlerBuilder

NewHandlerBuilder creates a new HandlerBuilder.

func (*HandlerBuilder) Build

func (b *HandlerBuilder) Build() MessageHandler

Build returns the configured MessageHandler.

func (*HandlerBuilder) OnComplete

func (b *HandlerBuilder) OnComplete(f func(result *CompletionResult)) *HandlerBuilder

OnComplete sets a function to be called on completion. This is a convenience method that wraps the function in a CompletionCallback.

func (*HandlerBuilder) OnError

func (b *HandlerBuilder) OnError(f func(err error)) *HandlerBuilder

OnError sets a function to be called on error. This wraps the existing streamer to also call the error function.

func (*HandlerBuilder) WithApprovalHandler

func (b *HandlerBuilder) WithApprovalHandler(a ApprovalHandler) *HandlerBuilder

WithApprovalHandler sets the approval handler.

func (*HandlerBuilder) WithAskHandler

func (b *HandlerBuilder) WithAskHandler(a AskHandler) *HandlerBuilder

WithAskHandler sets the ask handler.

func (*HandlerBuilder) WithCompletionCallback

func (b *HandlerBuilder) WithCompletionCallback(c CompletionCallback) *HandlerBuilder

WithCompletionCallback sets the completion callback.

func (*HandlerBuilder) WithStreamer

func (b *HandlerBuilder) WithStreamer(s MessageStreamer) *HandlerBuilder

WithStreamer sets the message streamer handler.

type InitMessage

type InitMessage struct {
	BaseMessage
	MaxIterations int `json:"max_iterations,omitempty"`
}

InitMessage represents agent initialization

func NewInitMessage

func NewInitMessage(agentType AgentType, sessionID string, maxIterations int) *InitMessage

NewInitMessage creates a new init message

func (*InitMessage) GetRawData

func (m *InitMessage) GetRawData() map[string]interface{}

GetRawData returns raw data

func (*InitMessage) ToEvent

func (m *InitMessage) ToEvent() Event

ToEvent converts InitMessage to Event

type MessageHandler

type MessageHandler interface {
	OnMessage(msg interface{}) error
	OnError(err error)
	OnComplete(result *CompletionResult)
	OnApproval(ctx context.Context, req PermissionRequest) (PermissionResult, error)
	OnAsk(ctx context.Context, req AskRequest) (AskResult, error)
}

MessageHandler is the primary interface for handling agent callbacks This interface is defined here to avoid circular dependencies

type MessageStreamer

type MessageStreamer interface {
	OnMessage(msg interface{}) error
	OnError(err error)
}

MessageStreamer handles streaming messages (subset of MessageHandler)

type OutputFormat

type OutputFormat string

OutputFormat defines agent output format

const (
	OutputFormatText       OutputFormat = "text"
	OutputFormatStreamJSON OutputFormat = "stream-json"
)

func (OutputFormat) String

func (f OutputFormat) String() string

String returns the string representation of OutputFormat

type PermissionConfig

type PermissionConfig struct {
	DefaultMode       PermissionMode `json:"default_mode"`
	Timeout           time.Duration  `json:"timeout"`
	EnableWhitelist   bool           `json:"enable_whitelist"`
	Whitelist         []string       `json:"whitelist"`
	Blacklist         []string       `json:"blacklist"`
	RememberDecisions bool           `json:"remember_decisions"`
	DecisionDuration  time.Duration  `json:"decision_duration"`
}

PermissionConfig holds permission handler configuration

func DefaultPermissionConfig

func DefaultPermissionConfig() PermissionConfig

DefaultPermissionConfig returns the default permission handler configuration

type PermissionHandler

type PermissionHandler interface {
	CanUseTool(ctx context.Context, req PermissionRequest) (PermissionResult, error)
	SetMode(scopeID string, mode PermissionMode) error
	GetMode(scopeID string) (PermissionMode, error)
}

PermissionHandler is the interface for permission handling This is defined here to avoid circular dependencies Deprecated: Use ask.Handler instead

type PermissionMode

type PermissionMode string

PermissionMode defines how permission requests are handled Deprecated: Use ask.Mode instead

const (
	PermissionModeAuto   PermissionMode = "auto"   // Auto-approve all requests
	PermissionModeManual PermissionMode = "manual" // Require user approval
	PermissionModeSkip   PermissionMode = "skip"   // Skip permission prompts
)

func (PermissionMode) String

func (m PermissionMode) String() string

String returns the string representation of PermissionMode

type PermissionRequest

type PermissionRequest struct {
	RequestID string                 `json:"request_id"`
	AgentType AgentType              `json:"agent_type"`
	ToolName  string                 `json:"tool_name"`
	Input     map[string]interface{} `json:"input"`
	Reason    string                 `json:"reason,omitempty"`
	Timestamp time.Time              `json:"timestamp"`
	SessionID string                 `json:"session_id,omitempty"`
	BotUUID   string                 `json:"bot_uuid,omitempty"` // Bot UUID for routing permission requests
	ChatID    string                 `json:"chat_id,omitempty"`  // Chat ID for routing
	Platform  string                 `json:"platform,omitempty"` // Platform for routing
}

PermissionRequest represents a permission request from an agent

type PermissionRequestMessage

type PermissionRequestMessage struct {
	BaseMessage
	RequestID string                 `json:"request_id"`
	ToolName  string                 `json:"tool_name"`
	Input     map[string]interface{} `json:"input"`
	Reason    string                 `json:"reason,omitempty"`
	Step      int                    `json:"step,omitempty"`
	Total     int                    `json:"total,omitempty"`
}

PermissionRequestMessage represents a permission request

func NewPermissionRequestMessage

func NewPermissionRequestMessage(agentType AgentType, sessionID, requestID, toolName string, input map[string]interface{}, reason string) *PermissionRequestMessage

NewPermissionRequestMessage creates a new permission request message

func (*PermissionRequestMessage) GetRawData

func (m *PermissionRequestMessage) GetRawData() map[string]interface{}

GetRawData returns raw data

func (*PermissionRequestMessage) ToEvent

func (m *PermissionRequestMessage) ToEvent() Event

ToEvent converts PermissionRequestMessage to Event

type PermissionResponse

type PermissionResponse struct {
	RequestID string    `json:"request_id"`
	Approved  bool      `json:"approved"`
	Reason    string    `json:"reason,omitempty"`
	Timestamp time.Time `json:"timestamp"`
}

PermissionResponse represents the response to a permission request

type PermissionResult

type PermissionResult struct {
	Approved     bool                   `json:"approved"`
	Reason       string                 `json:"reason,omitempty"`
	UpdatedInput map[string]interface{} `json:"updated_input,omitempty"`
	Remember     bool                   `json:"remember,omitempty"`
}

PermissionResult represents the result of a permission check

type PermissionResultMessage

type PermissionResultMessage struct {
	BaseMessage
	RequestID string `json:"request_id"`
	Approved  bool   `json:"approved"`
	Reason    string `json:"reason,omitempty"`
	Remember  bool   `json:"remember,omitempty"`
}

PermissionResultMessage represents the result of a permission request

func NewPermissionResultMessage

func NewPermissionResultMessage(agentType AgentType, sessionID, requestID string, approved bool, reason string) *PermissionResultMessage

NewPermissionResultMessage creates a new permission result message

func (*PermissionResultMessage) GetRawData

func (m *PermissionResultMessage) GetRawData() map[string]interface{}

GetRawData returns raw data

func (*PermissionResultMessage) ToEvent

func (m *PermissionResultMessage) ToEvent() Event

ToEvent converts PermissionResultMessage to Event

type Result

type Result struct {
	Output   string // Agent output (text mode)
	ExitCode int    // Process exit code
	Error    string // Error message if failed
	Duration time.Duration
	Format   OutputFormat           // Output format used
	Events   []Event                // Stream events (stream-json mode)
	Metadata map[string]interface{} // Additional metadata
}

Result represents the result of an agent execution

func (*Result) GetAssistantMessages

func (r *Result) GetAssistantMessages() []Event

GetAssistantMessages returns all assistant message events

func (*Result) GetCostUSD

func (r *Result) GetCostUSD() float64

GetCostUSD extracts the total cost from result events if available

func (*Result) GetMessageChain

func (r *Result) GetMessageChain() []Event

GetMessageChain returns all events in order, excluding result/system events

func (*Result) GetMessagesByType

func (r *Result) GetMessagesByType(messageType string) []Event

GetMessagesByType returns all events of a specific type

func (*Result) GetSessionID

func (r *Result) GetSessionID() string

GetSessionID extracts the session ID from metadata or events

func (*Result) GetStatus

func (r *Result) GetStatus() string

GetStatus extracts the final status from events

func (*Result) GetToolResultMessages

func (r *Result) GetToolResultMessages() []Event

GetToolResultMessages returns all tool_result message events

func (*Result) GetToolUseMessages

func (r *Result) GetToolUseMessages() []Event

GetToolUseMessages returns all tool_use message events

func (*Result) GetUserMessages

func (r *Result) GetUserMessages() []Event

GetUserMessages returns all user message events

func (*Result) IsSuccess

func (r *Result) IsSuccess() bool

IsSuccess returns true if the execution was successful

func (*Result) TextOutput

func (r *Result) TextOutput() string

TextOutput returns the full text output from the result

type ResultMessage

type ResultMessage struct {
	BaseMessage
	Status   string  `json:"status"` // "success", "error", "cancelled", "permission_denied"
	Message  string  `json:"message,omitempty"`
	CostUSD  float64 `json:"cost_usd,omitempty"`
	Duration int64   `json:"duration_ms,omitempty"`
	Steps    int     `json:"steps_completed,omitempty"`
	IsError  bool    `json:"is_error,omitempty"`
	ErrorMsg string  `json:"error,omitempty"`
}

ResultMessage represents the final result

func NewResultMessage

func NewResultMessage(agentType AgentType, sessionID, status, message string) *ResultMessage

NewResultMessage creates a new result message

func (*ResultMessage) GetRawData

func (m *ResultMessage) GetRawData() map[string]interface{}

GetRawData returns raw data

func (*ResultMessage) IsSuccess

func (m *ResultMessage) IsSuccess() bool

IsSuccess returns true if result is successful

func (*ResultMessage) ToEvent

func (m *ResultMessage) ToEvent() Event

ToEvent converts ResultMessage to Event

type StreamDeltaMessage

type StreamDeltaMessage struct {
	BaseMessage
	Delta string `json:"delta"`
}

StreamDeltaMessage represents incremental streaming content

func NewStreamDeltaMessage

func NewStreamDeltaMessage(agentType AgentType, sessionID, delta string) *StreamDeltaMessage

NewStreamDeltaMessage creates a new stream delta message

func (*StreamDeltaMessage) GetRawData

func (m *StreamDeltaMessage) GetRawData() map[string]interface{}

GetRawData returns raw data

func (*StreamDeltaMessage) ToEvent

func (m *StreamDeltaMessage) ToEvent() Event

ToEvent converts StreamDeltaMessage to Event

Directories

Path Synopsis
examples/query command
examples/server command

Jump to

Keyboard shortcuts

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