types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 3 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractText

func ExtractText(msg *Message) string

ExtractText extracts all text from a message's content blocks.

Types

type CanUseToolFn

type CanUseToolFn func(tool Tool, input map[string]interface{}) (*PermissionDecision, error)

CanUseToolFn is a callback for permission decisions.

type ContentBlock

type ContentBlock struct {
	Type  ContentBlockType       `json:"type"`
	Text  string                 `json:"text,omitempty"`
	ID    string                 `json:"id,omitempty"`
	Name  string                 `json:"name,omitempty"`
	Input map[string]interface{} `json:"input,omitempty"`

	// For tool_result
	ToolUseID string         `json:"tool_use_id,omitempty"`
	Content   []ContentBlock `json:"content,omitempty"`
	IsError   bool           `json:"is_error,omitempty"`

	// For image
	Source *ImageSource `json:"source,omitempty"`

	// For thinking
	Thinking string `json:"thinking,omitempty"`
}

ContentBlock represents a block of content in a message.

func (ContentBlock) MarshalJSON

func (b ContentBlock) MarshalJSON() ([]byte, error)

MarshalJSON customizes JSON serialization per block type. Ensures tool_use blocks always include "input" (even if empty).

type ContentBlockType

type ContentBlockType string

ContentBlockType represents a type of content block.

const (
	ContentBlockText       ContentBlockType = "text"
	ContentBlockToolUse    ContentBlockType = "tool_use"
	ContentBlockToolResult ContentBlockType = "tool_result"
	ContentBlockThinking   ContentBlockType = "thinking"
	ContentBlockImage      ContentBlockType = "image"
)

type FileReadState

type FileReadState struct {
	Content   string
	Timestamp int64
	Offset    int
	Limit     int
}

FileReadState tracks when a file was last read.

type ImageSource

type ImageSource struct {
	Type      string `json:"type"` // "base64"
	MediaType string `json:"media_type"`
	Data      string `json:"data"`
}

ImageSource represents an inline image.

type MCPContentBlock

type MCPContentBlock struct {
	Type     string `json:"type"` // "text", "image", "resource"
	Text     string `json:"text,omitempty"`
	Data     string `json:"data,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
}

MCPContentBlock represents content from an MCP tool result.

type MCPServerConfig

type MCPServerConfig struct {
	// Transport type (stdio, sse, http, websocket)
	Type MCPTransportType `json:"type,omitempty"`

	// For stdio transport
	Command string            `json:"command,omitempty"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`

	// For SSE/HTTP/WebSocket transport
	URL     string            `json:"url,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

MCPServerConfig is the configuration for an MCP server.

type MCPServerConnection

type MCPServerConnection struct {
	Name         string              `json:"name"`
	Status       MCPServerStatus     `json:"status"`
	Config       MCPServerConfig     `json:"config"`
	Tools        []MCPToolDefinition `json:"tools,omitempty"`
	ServerInfo   *MCPServerInfo      `json:"server_info,omitempty"`
	Instructions string              `json:"instructions,omitempty"`
	Error        string              `json:"error,omitempty"`
}

MCPServerConnection represents a connected MCP server.

type MCPServerInfo

type MCPServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

MCPServerInfo holds server metadata.

type MCPServerStatus

type MCPServerStatus string

MCPServerStatus represents the connection status of an MCP server.

const (
	MCPStatusConnected    MCPServerStatus = "connected"
	MCPStatusDisconnected MCPServerStatus = "disconnected"
	MCPStatusError        MCPServerStatus = "error"
	MCPStatusPending      MCPServerStatus = "pending"
)

type MCPToolCallResult

type MCPToolCallResult struct {
	Content []MCPContentBlock `json:"content"`
	IsError bool              `json:"isError,omitempty"`
}

MCPToolCallResult is the result from calling an MCP tool.

type MCPToolDefinition

type MCPToolDefinition struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	InputSchema ToolInputSchema `json:"inputSchema"`
}

MCPToolDefinition describes a tool exposed by an MCP server.

type MCPTransportType

type MCPTransportType string

MCPTransportType is the type of MCP transport.

const (
	MCPTransportStdio     MCPTransportType = "stdio"
	MCPTransportSSE       MCPTransportType = "sse"
	MCPTransportHTTP      MCPTransportType = "http"
	MCPTransportWebSocket MCPTransportType = "websocket"
)

type Message

type Message struct {
	Type      MessageType    `json:"type"`
	Role      string         `json:"role"`
	Content   []ContentBlock `json:"content,omitempty"`
	UUID      string         `json:"uuid"`
	Timestamp time.Time      `json:"timestamp"`

	// For assistant messages
	Model      string `json:"model,omitempty"`
	StopReason string `json:"stop_reason,omitempty"`

	// Usage tracking
	Usage *Usage `json:"usage,omitempty"`
}

Message represents a conversation message.

type MessageType

type MessageType string

MessageType represents the kind of message in a conversation.

const (
	MessageTypeUser      MessageType = "user"
	MessageTypeAssistant MessageType = "assistant"
	MessageTypeProgress  MessageType = "progress"
	MessageTypeSystem    MessageType = "system"
	MessageTypeResult    MessageType = "result"
)

type PermissionBehavior

type PermissionBehavior string

PermissionBehavior represents a permission decision.

const (
	PermissionAllow PermissionBehavior = "allow"
	PermissionDeny  PermissionBehavior = "deny"
	PermissionAsk   PermissionBehavior = "ask"
)

type PermissionDecision

type PermissionDecision struct {
	Behavior     PermissionBehavior     `json:"behavior"`
	UpdatedInput map[string]interface{} `json:"updated_input,omitempty"`
	Reason       string                 `json:"reason,omitempty"`
}

PermissionDecision is the result of a permission check.

type PermissionMode

type PermissionMode string

PermissionMode controls tool approval behavior.

const (
	PermissionModeDefault           PermissionMode = "default"
	PermissionModeAcceptEdits       PermissionMode = "acceptEdits"
	PermissionModeBypassPermissions PermissionMode = "bypassPermissions"
	PermissionModePlan              PermissionMode = "plan"
)

type SDKMessage

type SDKMessage struct {
	Type MessageType `json:"type"`

	// For "assistant" type
	Message *Message `json:"message,omitempty"`

	// For "result" type
	Text     string    `json:"text,omitempty"`
	Usage    *Usage    `json:"usage,omitempty"`
	NumTurns int       `json:"num_turns,omitempty"`
	Duration int64     `json:"duration_ms,omitempty"`
	Messages []Message `json:"messages,omitempty"`
	Cost     float64   `json:"cost,omitempty"`
}

SDKMessage is the streaming event type yielded by the agent loop.

type Tool

type Tool interface {
	// Name returns the tool's unique name.
	Name() string

	// Description returns a human-readable description for the model.
	Description() string

	// InputSchema returns the JSON schema for tool input.
	InputSchema() ToolInputSchema

	// Call executes the tool with the given input.
	Call(ctx context.Context, input map[string]interface{}, tCtx *ToolUseContext) (*ToolResult, error)

	// IsConcurrencySafe returns whether the tool can run concurrently.
	IsConcurrencySafe(input map[string]interface{}) bool

	// IsReadOnly returns whether the tool only reads (no side effects).
	IsReadOnly(input map[string]interface{}) bool
}

Tool defines the interface for an executable tool.

type ToolInputSchema

type ToolInputSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties,omitempty"`
	Required   []string               `json:"required,omitempty"`
}

ToolInputSchema describes the JSON schema for tool input.

type ToolResult

type ToolResult struct {
	Data    interface{}    `json:"data,omitempty"`
	Content []ContentBlock `json:"content,omitempty"`
	IsError bool           `json:"is_error,omitempty"`
	Error   string         `json:"error,omitempty"`
}

ToolResult is the result of executing a tool.

type ToolUseBlock

type ToolUseBlock struct {
	ID    string                 `json:"id"`
	Name  string                 `json:"name"`
	Input map[string]interface{} `json:"input"`
}

ToolUseBlock extracts tool use info from a content block.

func ExtractToolUseBlocks

func ExtractToolUseBlocks(msg *Message) []ToolUseBlock

ExtractToolUseBlocks extracts all tool_use blocks from a message.

type ToolUseContext

type ToolUseContext struct {
	// WorkingDir is the current working directory.
	WorkingDir string

	// AbortCtx is a cancellable context for the tool execution.
	AbortCtx context.Context

	// ReadFileState tracks file read state for staleness detection.
	ReadFileState map[string]*FileReadState
}

ToolUseContext provides context for tool execution.

type Usage

type Usage struct {
	InputTokens              int `json:"input_tokens"`
	OutputTokens             int `json:"output_tokens"`
	CacheReadInputTokens     int `json:"cache_read_input_tokens,omitempty"`
	CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"`
}

Usage represents token usage for a message.

Jump to

Keyboard shortcuts

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