shared

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package shared provides shared types and interfaces used across internal packages.

Index

Constants

View Source
const (
	MessageTypeUser      = "user"
	MessageTypeAssistant = "assistant"
	MessageTypeSystem    = "system"
	MessageTypeResult    = "result"
)

Message type constants

View Source
const (
	ContentBlockTypeText       = "text"
	ContentBlockTypeThinking   = "thinking"
	ContentBlockTypeToolUse    = "tool_use"
	ContentBlockTypeToolResult = "tool_result"
)

Content block type constants

View Source
const (
	// DefaultMaxThinkingTokens is the default maximum number of thinking tokens.
	DefaultMaxThinkingTokens = 8000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AssistantMessage

type AssistantMessage struct {
	MessageType string         `json:"type"`
	Content     []ContentBlock `json:"content"`
	Model       string         `json:"model"`
}

AssistantMessage represents a message from the assistant.

func (*AssistantMessage) MarshalJSON

func (m *AssistantMessage) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for AssistantMessage

func (*AssistantMessage) Type

func (m *AssistantMessage) Type() string

Type returns the message type for AssistantMessage.

type BaseError

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

BaseError provides common error functionality.

func (*BaseError) Error

func (e *BaseError) Error() string

func (*BaseError) Type

func (e *BaseError) Type() string

Type returns the error type for BaseError.

func (*BaseError) Unwrap

func (e *BaseError) Unwrap() error

type CLINotFoundError

type CLINotFoundError struct {
	BaseError
	Path string
}

CLINotFoundError indicates the Claude CLI was not found.

func NewCLINotFoundError

func NewCLINotFoundError(path, message string) *CLINotFoundError

NewCLINotFoundError creates a new CLINotFoundError.

func (*CLINotFoundError) Type

func (e *CLINotFoundError) Type() string

Type returns the error type for CLINotFoundError.

type ConnectionError

type ConnectionError struct {
	BaseError
}

ConnectionError represents connection-related failures.

func NewConnectionError

func NewConnectionError(message string, cause error) *ConnectionError

NewConnectionError creates a new ConnectionError.

func (*ConnectionError) Type

func (e *ConnectionError) Type() string

Type returns the error type for ConnectionError.

type ContentBlock

type ContentBlock interface {
	BlockType() string
}

ContentBlock represents any content block within a message.

type JSONDecodeError

type JSONDecodeError struct {
	BaseError
	Line          string
	Position      int
	OriginalError error
}

JSONDecodeError represents JSON parsing failures.

func NewJSONDecodeError

func NewJSONDecodeError(line string, position int, cause error) *JSONDecodeError

NewJSONDecodeError creates a new JSONDecodeError.

func (*JSONDecodeError) Type

func (e *JSONDecodeError) Type() string

Type returns the error type for JSONDecodeError.

func (*JSONDecodeError) Unwrap

func (e *JSONDecodeError) Unwrap() error

type McpHTTPServerConfig

type McpHTTPServerConfig struct {
	Type    McpServerType     `json:"type"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers,omitempty"`
}

McpHTTPServerConfig configures an MCP HTTP server.

func (*McpHTTPServerConfig) GetType

func (c *McpHTTPServerConfig) GetType() McpServerType

GetType returns the server type for McpHTTPServerConfig.

type McpSSEServerConfig

type McpSSEServerConfig struct {
	Type    McpServerType     `json:"type"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers,omitempty"`
}

McpSSEServerConfig configures an MCP Server-Sent Events server.

func (*McpSSEServerConfig) GetType

func (c *McpSSEServerConfig) GetType() McpServerType

GetType returns the server type for McpSSEServerConfig.

type McpServerConfig

type McpServerConfig interface {
	GetType() McpServerType
}

McpServerConfig represents MCP server configuration.

type McpServerType

type McpServerType string

McpServerType represents the type of MCP server.

const (
	// McpServerTypeStdio represents a stdio-based MCP server.
	McpServerTypeStdio McpServerType = "stdio"
	// McpServerTypeSSE represents a Server-Sent Events MCP server.
	McpServerTypeSSE McpServerType = "sse"
	// McpServerTypeHTTP represents an HTTP-based MCP server.
	McpServerTypeHTTP McpServerType = "http"
)

type McpStdioServerConfig

type McpStdioServerConfig struct {
	Type    McpServerType     `json:"type"`
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
}

McpStdioServerConfig configures an MCP stdio server.

func (*McpStdioServerConfig) GetType

func (c *McpStdioServerConfig) GetType() McpServerType

GetType returns the server type for McpStdioServerConfig.

type Message

type Message interface {
	Type() string
}

Message represents any message type in the Claude Code protocol.

type MessageIterator

type MessageIterator interface {
	Next(ctx context.Context) (Message, error)
	Close() error
}

MessageIterator provides an iterator pattern for streaming messages.

type MessageParseError

type MessageParseError struct {
	BaseError
	Data any
}

MessageParseError represents message structure parsing failures.

func NewMessageParseError

func NewMessageParseError(message string, data any) *MessageParseError

NewMessageParseError creates a new MessageParseError.

func (*MessageParseError) Type

func (e *MessageParseError) Type() string

Type returns the error type for MessageParseError.

type Options

type Options struct {
	// Tool Control
	AllowedTools    []string `json:"allowed_tools,omitempty"`
	DisallowedTools []string `json:"disallowed_tools,omitempty"`

	// System Prompts & Model
	SystemPrompt       *string `json:"system_prompt,omitempty"`
	AppendSystemPrompt *string `json:"append_system_prompt,omitempty"`
	Model              *string `json:"model,omitempty"`
	MaxThinkingTokens  int     `json:"max_thinking_tokens,omitempty"`

	// Permission & Safety System
	PermissionMode           *PermissionMode `json:"permission_mode,omitempty"`
	PermissionPromptToolName *string         `json:"permission_prompt_tool_name,omitempty"`

	// Session & State Management
	ContinueConversation bool    `json:"continue_conversation,omitempty"`
	Resume               *string `json:"resume,omitempty"`
	MaxTurns             int     `json:"max_turns,omitempty"`
	Settings             *string `json:"settings,omitempty"`

	// File System & Context
	Cwd     *string  `json:"cwd,omitempty"`
	AddDirs []string `json:"add_dirs,omitempty"`

	// MCP Integration
	McpServers map[string]McpServerConfig `json:"mcp_servers,omitempty"`

	// Extensibility
	ExtraArgs map[string]*string `json:"extra_args,omitempty"`

	// CLI Path (for testing and custom installations)
	CLIPath *string `json:"cli_path,omitempty"`
}

Options configures the Claude Code SDK behavior.

func NewOptions

func NewOptions() *Options

NewOptions creates Options with default values.

func (*Options) Validate

func (o *Options) Validate() error

Validate checks the options for valid values and constraints.

type PermissionMode

type PermissionMode string

PermissionMode represents the different permission handling modes.

const (
	// PermissionModeDefault is the standard permission handling mode.
	PermissionModeDefault PermissionMode = "default"
	// PermissionModeAcceptEdits automatically accepts all edit permissions.
	PermissionModeAcceptEdits PermissionMode = "acceptEdits"
	// PermissionModePlan enables plan mode for task execution.
	PermissionModePlan PermissionMode = "plan"
	// PermissionModeBypassPermissions bypasses all permission checks.
	PermissionModeBypassPermissions PermissionMode = "bypassPermissions"
)

type ProcessError

type ProcessError struct {
	BaseError
	ExitCode int
	Stderr   string
}

ProcessError represents subprocess execution failures.

func NewProcessError

func NewProcessError(message string, exitCode int, stderr string) *ProcessError

NewProcessError creates a new ProcessError.

func (*ProcessError) Error

func (e *ProcessError) Error() string

func (*ProcessError) Type

func (e *ProcessError) Type() string

Type returns the error type for ProcessError.

type ResultMessage

type ResultMessage struct {
	MessageType   string          `json:"type"`
	Subtype       string          `json:"subtype"`
	DurationMs    int             `json:"duration_ms"`
	DurationAPIMs int             `json:"duration_api_ms"`
	IsError       bool            `json:"is_error"`
	NumTurns      int             `json:"num_turns"`
	SessionID     string          `json:"session_id"`
	TotalCostUSD  *float64        `json:"total_cost_usd,omitempty"`
	Usage         *map[string]any `json:"usage,omitempty"`
	Result        *map[string]any `json:"result,omitempty"`
}

ResultMessage represents the final result of a conversation turn.

func (*ResultMessage) MarshalJSON

func (m *ResultMessage) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ResultMessage

func (*ResultMessage) Type

func (m *ResultMessage) Type() string

Type returns the message type for ResultMessage.

type SDKError

type SDKError interface {
	error
	Type() string
}

SDKError is the base interface for all Claude Code SDK errors.

type StreamMessage

type StreamMessage struct {
	Type            string                 `json:"type"`
	Message         interface{}            `json:"message,omitempty"`
	ParentToolUseID *string                `json:"parent_tool_use_id,omitempty"`
	SessionID       string                 `json:"session_id,omitempty"`
	RequestID       string                 `json:"request_id,omitempty"`
	Request         map[string]interface{} `json:"request,omitempty"`
	Response        map[string]interface{} `json:"response,omitempty"`
}

StreamMessage represents messages sent to the CLI for streaming communication.

type SystemMessage

type SystemMessage struct {
	MessageType string         `json:"type"`
	Subtype     string         `json:"subtype"`
	Data        map[string]any `json:"-"` // Preserve all original data
}

SystemMessage represents a system message.

func (*SystemMessage) MarshalJSON

func (m *SystemMessage) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for SystemMessage

func (*SystemMessage) Type

func (m *SystemMessage) Type() string

Type returns the message type for SystemMessage.

type TextBlock

type TextBlock struct {
	MessageType string `json:"type"`
	Text        string `json:"text"`
}

TextBlock represents text content.

func (*TextBlock) BlockType

func (b *TextBlock) BlockType() string

BlockType returns the content block type for TextBlock.

type ThinkingBlock

type ThinkingBlock struct {
	MessageType string `json:"type"`
	Thinking    string `json:"thinking"`
	Signature   string `json:"signature"`
}

ThinkingBlock represents thinking content with signature.

func (*ThinkingBlock) BlockType

func (b *ThinkingBlock) BlockType() string

BlockType returns the content block type for ThinkingBlock.

type ToolResultBlock

type ToolResultBlock struct {
	MessageType string      `json:"type"`
	ToolUseID   string      `json:"tool_use_id"`
	Content     interface{} `json:"content"` // string or structured data
	IsError     *bool       `json:"is_error,omitempty"`
}

ToolResultBlock represents the result of a tool use.

func (*ToolResultBlock) BlockType

func (b *ToolResultBlock) BlockType() string

BlockType returns the content block type for ToolResultBlock.

type ToolUseBlock

type ToolUseBlock struct {
	MessageType string         `json:"type"`
	ToolUseID   string         `json:"tool_use_id"`
	Name        string         `json:"name"`
	Input       map[string]any `json:"input"`
}

ToolUseBlock represents a tool use request.

func (*ToolUseBlock) BlockType

func (b *ToolUseBlock) BlockType() string

BlockType returns the content block type for ToolUseBlock.

type UserMessage

type UserMessage struct {
	MessageType string      `json:"type"`
	Content     interface{} `json:"content"` // string or []ContentBlock
}

UserMessage represents a message from the user.

func (*UserMessage) MarshalJSON

func (m *UserMessage) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for UserMessage

func (*UserMessage) Type

func (m *UserMessage) Type() string

Type returns the message type for UserMessage.

Jump to

Keyboard shortcuts

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