anthropic

package
v1.10.22 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ClaudeURL = "https://api.anthropic.com/v1/messages"

Variables

View Source
var Default = Claude{
	Model:            "claude-sonnet-4",
	URL:              ClaudeURL,
	AnthropicVersion: "2023-06-01",
	AnthropicBeta:    "",
	Temperature:      0.5,
	MaxTokens:        8192,
	StopSequences:    make([]string, 0),
}

Functions

This section is empty.

Types

type Claude

type Claude struct {
	Model            string   `json:"model"`
	MaxTokens        int      `json:"max_tokens"`
	URL              string   `json:"url"`
	AnthropicVersion string   `json:"anthropic-version"`
	AnthropicBeta    string   `json:"anthropic-beta"`
	Temperature      float64  `json:"temperature"`
	TopP             float64  `json:"top_p"`
	TopK             int      `json:"top_k"`
	StopSequences    []string `json:"stop_sequences"`
	PrintInputCount  bool     `json:"print_input_count"`
	// contains filtered or unexported fields
}

func (*Claude) CountInputTokens

func (c *Claude) CountInputTokens(ctx context.Context, chat pub_models.Chat) (int, error)

func (*Claude) RegisterTool

func (c *Claude) RegisterTool(tool pub_models.LLMTool)

func (*Claude) Setup

func (c *Claude) Setup() error

func (*Claude) StreamCompletions

func (c *Claude) StreamCompletions(ctx context.Context, chat pub_models.Chat) (chan models.CompletionEvent, error)

func (*Claude) TokenUsage

func (c *Claude) TokenUsage() *pub_models.Usage

TokenUsage implements models.UsageTokenCounter.

Claude exposes the (counted) input token usage via CountInputTokens. Anthropic's streaming API does not provide completion token usage in this implementation, so we only populate prompt tokens.

type ClaudeConvMessage

type ClaudeConvMessage struct {
	Role string `json:"role"`
	// Content may be either ToolContentBlock or TextContentBlock
	Content []any `json:"content"`
}

type ClaudeMessage

type ClaudeMessage struct {
	ID    string            `json:"id,omitempty"`
	Input *pub_models.Input `json:"input,omitempty"`
	Name  string            `json:"name,omitempty"`
	Text  string            `json:"text,omitempty"`
	Type  string            `json:"type"`
}

type ClaudeResponse

type ClaudeResponse struct {
	Content      []ClaudeMessage `json:"content"`
	ID           string          `json:"id"`
	Model        string          `json:"model"`
	Role         string          `json:"role"`
	StopReason   string          `json:"stop_reason"`
	StopSequence any             `json:"stop_sequence"`
	Type         string          `json:"type"`
	Usage        TokenInfo       `json:"usage"`
}

type ContentBlockDelta

type ContentBlockDelta struct {
	Type  string `json:"type"`
	Index int    `json:"index"`
	Delta Delta  `json:"delta"`
}

type ContentBlockSuper

type ContentBlockSuper struct {
	Type             string              `json:"type"`
	Index            int                 `json:"index"`
	ToolContentBlock ToolUseContentBlock `json:"content_block"`
}

type Delta

type Delta struct {
	Type        string `json:"type"`
	Text        string `json:"text,omitempty"`
	PartialJSON string `json:"partial_json,omitempty"`
	Thinking    string `json:"thinking,omitempty"`
	Signature   string `json:"signature,omitempty"`
}

type Root

type Root struct {
	Type         string              `json:"type"`
	Index        int                 `json:"index"`
	ContentBlock ToolUseContentBlock `json:"content_block"`
}

type SourceReader added in v1.10.11

type SourceReader struct {
	FS fs.FS
	// Root is the absolute directory that contains the Claude projects.
	// If empty, defaults to $HOME/.claude/projects.
	//
	// This exists primarily for tests; production code should leave it empty.
	Root string
}

SourceReader reads Claude Code / Claude Desktop conversation logs from disk.

Storage (best-effort, observed): ~/.claude/projects/<project>/*.jsonl Each line is JSON with a "type" such as: user, assistant, system, queue-operation. Task-subagent transcripts live under <sessionId>/subagents/ and carry the parent's sessionId ("isSidechain": true) — they are never sessions themselves, so both the directory and sidechain lines are skipped everywhere.

This reader is intentionally conservative: discovery is bounded and skips rows with missing SourceID.

FS is injectable for tests; if nil, the host root filesystem is used. The host-path logic (HOME expansion, walking) stays outside the FS — it is only used for opening files.

clai never writes back to these sources.

func (SourceReader) Discover added in v1.10.11

func (r SourceReader) Discover(ctx context.Context) ([]vendors.SourceRow, error)

func (SourceReader) Read added in v1.10.11

func (r SourceReader) Read(ctx context.Context, sourceID string) (pub_models.Chat, error)

func (SourceReader) Source added in v1.10.11

func (r SourceReader) Source() string

type TextContentBlock

type TextContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type TokenInfo

type TokenInfo struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

type ToolResultContentBlock

type ToolResultContentBlock struct {
	Type      string `json:"type"`
	Content   string `json:"content"`
	ToolUseID string `json:"tool_use_id"`
}

type ToolUseContentBlock

type ToolUseContentBlock struct {
	Type  string          `json:"type"`
	ID    string          `json:"id"`
	Name  string          `json:"name"`
	Input *map[string]any `json:"input,omitempty"`
}

Jump to

Keyboard shortcuts

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