Documentation
¶
Overview ¶
Package claude implements the Claude agent via the Claude SDK WebSocket server.
Index ¶
- type Agent
- func (a *Agent) Execute(ctx context.Context, msgs []*bridge.Message) (*agent.Result, error)
- func (a *Agent) IsRunning() bool
- func (a *Agent) Name() string
- func (a *Agent) SessionID() string
- func (a *Agent) SetMCPServerAddr(addr string)
- func (a *Agent) Start(ctx context.Context) error
- func (a *Agent) Status() *agent.Status
- func (a *Agent) Stop(ctx context.Context) error
- type ControlApprovePayload
- type ControlDenyPayload
- type ControlRequestPayload
- type ErrorPayload
- type InitPayload
- type MCPServer
- type Message
- type MessageType
- type ResultPayload
- type Statistics
- type StreamEventPayload
- type ToolCall
- type UserMessagePayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent implements the Agent interface for Claude.
func (*Agent) SetMCPServerAddr ¶
SetMCPServerAddr sets the MCP server address for bridge tools.
type ControlApprovePayload ¶
type ControlApprovePayload struct {
RequestID string `json:"request_id"`
}
ControlApprovePayload approves a control request.
type ControlDenyPayload ¶
type ControlDenyPayload struct {
RequestID string `json:"request_id"`
Reason string `json:"reason,omitempty"`
}
ControlDenyPayload denies a control request.
type ControlRequestPayload ¶
type ControlRequestPayload struct {
RequestID string `json:"request_id"`
Type string `json:"type"` // "command", "file_write", "file_edit", etc.
Description string `json:"description"`
Command string `json:"command,omitempty"`
FilePath string `json:"file_path,omitempty"`
Content string `json:"content,omitempty"`
}
ControlRequestPayload is sent when Claude needs permission.
type ErrorPayload ¶
type ErrorPayload struct {
Code string `json:"code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
}
ErrorPayload represents an error from Claude.
type InitPayload ¶
type InitPayload struct {
SessionID string `json:"session_id,omitempty"`
WorkDir string `json:"work_dir"`
Prompt string `json:"prompt,omitempty"`
Model string `json:"model,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Tools []string `json:"tools,omitempty"`
MCPServers []MCPServer `json:"mcp_servers,omitempty"`
SystemPrompt string `json:"system_prompt,omitempty"`
Permissions map[string]any `json:"permissions,omitempty"`
}
InitPayload is sent to initialize a Claude session.
type MCPServer ¶
type MCPServer struct {
Name string `json:"name"`
Command string `json:"command"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
MCPServer represents an MCP server configuration.
type Message ¶
type Message struct {
Type MessageType `json:"type"`
Payload json.RawMessage `json:"payload,omitempty"`
}
Message is the base NDJSON message structure.
func DecodeMessage ¶
DecodeMessage decodes a JSON message.
func NewMessage ¶
func NewMessage(msgType MessageType, payload any) (*Message, error)
NewMessage creates a new message with the given type and payload.
func (*Message) DecodePayload ¶
DecodePayload decodes the message payload into the given type.
type MessageType ¶
type MessageType string
MessageType represents NDJSON message types from Claude SDK.
const ( // Incoming from Claude TypeStreamEvent MessageType = "stream_event" TypeResult MessageType = "result" TypeControlRequest MessageType = "control_request" TypeError MessageType = "error" // Outgoing to Claude TypeInit MessageType = "init" TypeUserMessage MessageType = "user_message" TypeControlApprove MessageType = "control_approve" TypeControlDeny MessageType = "control_deny" TypeStop MessageType = "stop" )
type ResultPayload ¶
type ResultPayload struct {
SessionID string `json:"session_id"`
Output string `json:"output"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Done bool `json:"done"`
Error string `json:"error,omitempty"`
Statistics *Statistics `json:"statistics,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
ResultPayload is the final result from Claude.
type Statistics ¶
type Statistics struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
Duration time.Duration `json:"duration"`
}
Statistics contains usage statistics.
type StreamEventPayload ¶
type StreamEventPayload struct {
Event string `json:"event"`
Data json.RawMessage `json:"data,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
StreamEventPayload represents streaming events from Claude.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
ToolCall represents a tool invocation by Claude.
type UserMessagePayload ¶
type UserMessagePayload struct {
Content string `json:"content"`
}
UserMessagePayload is sent to provide user input.