tools

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentBlock

type ContentBlock struct {
	Type      string          `json:"type"`
	Text      string          `json:"text,omitempty"`
	ID        string          `json:"id,omitempty"`
	Name      string          `json:"name,omitempty"`
	Input     json.RawMessage `json:"input,omitempty"`
	Content   json.RawMessage `json:"content,omitempty"`
	ToolUseID string          `json:"tool_use_id,omitempty"`
}

ContentBlock represents a content block in Claude's response

type Handler

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

Handler processes tool-related responses and requests

func NewHandler

func NewHandler() *Handler

NewHandler creates a new tool handler

func (*Handler) CreateToolResultMessage

func (h *Handler) CreateToolResultMessage(results []ToolResult) Message

CreateToolResultMessage creates a message containing tool results

func (*Handler) ExtractToolUses

func (h *Handler) ExtractToolUses(message interface{}) ([]ToolUse, error)

ExtractToolUses extracts tool use blocks from a message

func (*Handler) ProcessToolResponse

func (h *Handler) ProcessToolResponse(ctx context.Context, response interface{}) (interface{}, error)

ProcessToolResponse processes a response that may contain tool use blocks

func (*Handler) TransformToolsForProvider

func (h *Handler) TransformToolsForProvider(tools []interface{}, provider string) ([]interface{}, error)

TransformToolsForProvider transforms tool definitions for a specific provider

func (*Handler) ValidateToolDefinition

func (h *Handler) ValidateToolDefinition(tool interface{}) error

ValidateToolDefinition validates a tool definition

type Message

type Message struct {
	Role    string         `json:"role"`
	Content []ContentBlock `json:"content"`
}

Message represents a message with content blocks

type SSEEvent

type SSEEvent struct {
	Event string
	Data  string
	ID    string
	Retry string
}

SSEEvent represents a Server-Sent Event

type StreamingHandler

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

StreamingHandler processes tool-related SSE streams

func NewStreamingHandler

func NewStreamingHandler() *StreamingHandler

NewStreamingHandler creates a new streaming handler

func (*StreamingHandler) ExtractToolUseFromStream

func (sh *StreamingHandler) ExtractToolUseFromStream(event SSEEvent) (*ToolUse, error)

ExtractToolUseFromStream extracts tool use information from a streaming event

func (*StreamingHandler) ProcessToolStream

func (sh *StreamingHandler) ProcessToolStream(ctx context.Context, reader io.Reader, writer io.Writer) error

ProcessToolStream processes a stream that may contain tool use events

type ToolResult

type ToolResult struct {
	Type      string          `json:"type"`
	ToolUseID string          `json:"tool_use_id"`
	Content   json.RawMessage `json:"content,omitempty"`
	Error     *string         `json:"error,omitempty"`
}

ToolResult represents a tool execution result

type ToolUse

type ToolUse struct {
	Type  string          `json:"type"`
	ID    string          `json:"id"`
	Name  string          `json:"name"`
	Input json.RawMessage `json:"input"`
}

ToolUse represents a tool use request from Claude

Jump to

Keyboard shortcuts

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