Documentation
¶
Index ¶
- Constants
- Variables
- func DebugRawEvent(enabled bool, event Event)
- func DebugRawRequest(enabled bool, providerName, credential string, req Request, label string)
- func DebugRawSection(enabled bool, label, body string)
- func DebugRawToolCall(enabled bool, call ToolCall)
- func DebugRawToolResult(enabled bool, id, name, content string)
- func DebugToolCall(enabled bool, call ToolCall)
- func DebugToolResult(enabled bool, id, name, content string)
- func EditToolSchema() map[string]interface{}
- func GetImageProviderNames() []string
- func GetProviderCompletions(toComplete string, isImage bool) []string
- func GetProviderNames() []string
- func IsCodexModel(model string) bool
- func ParseProviderModel(s string) (string, string, error)
- func ParseUnifiedDiff(call ToolCall) (string, error)
- func UnifiedDiffToolSchema() map[string]interface{}
- type AnthropicProvider
- func (p *AnthropicProvider) Capabilities() Capabilities
- func (p *AnthropicProvider) Credential() string
- func (p *AnthropicProvider) ListModels(ctx context.Context) ([]ModelInfo, error)
- func (p *AnthropicProvider) Name() string
- func (p *AnthropicProvider) Stream(ctx context.Context, req Request) (Stream, error)
- type Capabilities
- type CodeAssistProvider
- type CodexProvider
- type CommandSuggestion
- type EditToolCall
- type Engine
- type Event
- type EventType
- type GeminiProvider
- type Message
- type ModelInfo
- type OpenAICompatProvider
- func NewOpenAICompatProvider(baseURL, apiKey, model, name string) *OpenAICompatProvider
- func NewOpenAICompatProviderWithHeaders(baseURL, apiKey, model, name string, headers map[string]string) *OpenAICompatProvider
- func NewOpenRouterProvider(apiKey, model, appURL, appTitle string) *OpenAICompatProvider
- func NewZenProvider(apiKey, model string) *OpenAICompatProvider
- func (p *OpenAICompatProvider) Capabilities() Capabilities
- func (p *OpenAICompatProvider) Credential() string
- func (p *OpenAICompatProvider) ListModels(ctx context.Context) ([]ModelInfo, error)
- func (p *OpenAICompatProvider) Name() string
- func (p *OpenAICompatProvider) Stream(ctx context.Context, req Request) (Stream, error)
- type OpenAIProvider
- type Part
- type PartType
- type Provider
- type ReadURLTool
- type Request
- type RetryConfig
- type RetryProvider
- type Role
- type Stream
- type Tool
- type ToolCall
- type ToolChoice
- type ToolChoiceMode
- type ToolRegistry
- type ToolResult
- type ToolSpec
- type Usage
- type WebSearchTool
Constants ¶
const ( SuggestCommandsToolName = "suggest_commands" EditToolName = "edit" UnifiedDiffToolName = "unified_diff" WebSearchToolName = "web_search" )
const EditToolDescription = "" /* 215-byte string literal not displayed */
EditToolDescription is the description for the edit tool.
const (
ReadURLToolName = "read_url"
)
const UnifiedDiffToolDescription = `` /* 929-byte string literal not displayed */
UnifiedDiffToolDescription is the description for the unified diff tool.
Variables ¶
var ImageProviderModels = map[string][]string{
"gemini": {"gemini-2.5-flash-image", "gemini-3-pro-image-preview"},
"openai": {"gpt-image-1.5", "gpt-image-1-mini"},
"flux": {"flux-2-pro", "flux-kontext-pro", "flux-2-max"},
}
var ProviderModels = map[string][]string{
"anthropic": {
"claude-sonnet-4-5",
"claude-sonnet-4-5-thinking",
"claude-opus-4-5",
"claude-opus-4-5-thinking",
"claude-haiku-4-5",
"claude-haiku-4-5-thinking",
},
"openai": {
"gpt-5.2",
"gpt-5.2-high",
"gpt-5.2-codex",
"gpt-5.2-codex-medium",
"gpt-5.2-codex-high",
"gpt-5.2-codex-xhigh",
"gpt-4.1",
},
"openrouter": {
"x-ai/grok-code-fast-1",
},
"gemini": {
"gemini-3-pro-preview",
"gemini-3-pro-preview-thinking",
"gemini-3-flash-preview",
"gemini-3-flash-preview-thinking",
"gemini-2.5-flash",
"gemini-2.5-flash-lite",
},
"zen": {
"glm-4.7-free",
"grok-code",
"minimax-m2.1-free",
"big-pickle",
"gpt-5-nano",
},
}
ProviderModels contains the curated list of common models per LLM provider
Functions ¶
func DebugRawEvent ¶ added in v0.0.10
DebugRawEvent prints each stream event with a timestamp.
func DebugRawRequest ¶ added in v0.0.10
DebugRawRequest prints the raw request with all message parts in debug mode.
func DebugRawSection ¶ added in v0.0.10
DebugRawSection prints a timestamped debug section.
func DebugRawToolCall ¶ added in v0.0.10
DebugRawToolCall prints a tool call with raw JSON arguments and a timestamp.
func DebugRawToolResult ¶ added in v0.0.10
DebugRawToolResult prints a tool result payload with a timestamp.
func DebugToolCall ¶ added in v0.0.10
DebugToolCall prints a tool call in debug mode with readable formatting.
func DebugToolResult ¶ added in v0.0.10
DebugToolResult prints a tool result in debug mode with readable formatting.
func EditToolSchema ¶ added in v0.0.9
func EditToolSchema() map[string]interface{}
EditToolSchema returns the JSON schema for the edit tool.
func GetImageProviderNames ¶ added in v0.0.6
func GetImageProviderNames() []string
GetImageProviderNames returns valid provider names for image generation
func GetProviderCompletions ¶ added in v0.0.6
GetProviderCompletions returns completions for the --provider flag It handles both provider-only and provider:model completion scenarios
func GetProviderNames ¶ added in v0.0.6
func GetProviderNames() []string
GetProviderNames returns valid provider names for LLM
func IsCodexModel ¶ added in v0.0.6
IsCodexModel returns true if the model name indicates a Codex model.
func ParseProviderModel ¶ added in v0.0.6
ParseProviderModel parses "provider:model" or just "provider" from a flag value. Returns (provider, model, error). Model will be empty if not specified.
func ParseUnifiedDiff ¶ added in v0.0.9
ParseUnifiedDiff parses a unified_diff tool call payload.
func UnifiedDiffToolSchema ¶ added in v0.0.9
func UnifiedDiffToolSchema() map[string]interface{}
UnifiedDiffToolSchema returns the JSON schema for the unified diff tool.
Types ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
// contains filtered or unexported fields
}
AnthropicProvider implements Provider using the Anthropic API.
func NewAnthropicProvider ¶
func NewAnthropicProvider(apiKey, model string) *AnthropicProvider
func (*AnthropicProvider) Capabilities ¶ added in v0.0.10
func (p *AnthropicProvider) Capabilities() Capabilities
func (*AnthropicProvider) Credential ¶ added in v0.0.10
func (p *AnthropicProvider) Credential() string
func (*AnthropicProvider) ListModels ¶ added in v0.0.8
func (p *AnthropicProvider) ListModels(ctx context.Context) ([]ModelInfo, error)
ListModels returns available models from Anthropic.
func (*AnthropicProvider) Name ¶
func (p *AnthropicProvider) Name() string
type Capabilities ¶ added in v0.0.10
type Capabilities struct {
NativeWebSearch bool // Provider has native web search capability
NativeWebFetch bool // Provider has native URL fetch capability
ToolCalls bool
}
Capabilities describe optional provider features.
type CodeAssistProvider ¶
type CodeAssistProvider struct {
// contains filtered or unexported fields
}
CodeAssistProvider implements Provider using Google Code Assist API with OAuth
func NewCodeAssistProvider ¶
func NewCodeAssistProvider(creds *credentials.GeminiOAuthCredentials, model string) *CodeAssistProvider
func (*CodeAssistProvider) Capabilities ¶ added in v0.0.10
func (p *CodeAssistProvider) Capabilities() Capabilities
func (*CodeAssistProvider) Credential ¶ added in v0.0.10
func (p *CodeAssistProvider) Credential() string
func (*CodeAssistProvider) Name ¶
func (p *CodeAssistProvider) Name() string
type CodexProvider ¶
type CodexProvider struct {
// contains filtered or unexported fields
}
CodexProvider implements Provider using the ChatGPT backend API with Codex OAuth.
func NewCodexProvider ¶
func NewCodexProvider(accessToken, model, accountID string) *CodexProvider
func (*CodexProvider) Capabilities ¶ added in v0.0.10
func (p *CodexProvider) Capabilities() Capabilities
func (*CodexProvider) Credential ¶ added in v0.0.10
func (p *CodexProvider) Credential() string
func (*CodexProvider) Name ¶
func (p *CodexProvider) Name() string
type CommandSuggestion ¶
type CommandSuggestion struct {
Command string `json:"command"`
Explanation string `json:"explanation"`
Likelihood int `json:"likelihood"` // 1-10, how likely this matches user intent
}
CommandSuggestion represents a single command suggestion from the LLM.
func ParseCommandSuggestions ¶ added in v0.0.10
func ParseCommandSuggestions(call ToolCall) ([]CommandSuggestion, error)
ParseCommandSuggestions parses a suggest_commands tool call.
type EditToolCall ¶ added in v0.0.5
type EditToolCall struct {
FilePath string `json:"file_path"`
OldString string `json:"old_string"`
NewString string `json:"new_string"`
}
EditToolCall represents a single edit tool call (find/replace).
func ParseEditToolCall ¶ added in v0.0.10
func ParseEditToolCall(call ToolCall) (EditToolCall, error)
ParseEditToolCall parses a single edit tool call payload.
type Engine ¶ added in v0.0.10
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates provider calls and external tool execution.
func NewEngine ¶ added in v0.0.10
func NewEngine(provider Provider, tools *ToolRegistry) *Engine
type Event ¶ added in v0.0.10
type Event struct {
Type EventType
Text string
Tool *ToolCall
ToolName string // For EventToolExecStart: name of tool being executed
ToolInfo string // For EventToolExecStart: additional info (e.g., URL being fetched)
Use *Usage
Err error
// Retry fields (for EventRetry)
RetryAttempt int
RetryMaxAttempts int
RetryWaitSecs float64
}
Event represents a streamed output update.
type EventType ¶ added in v0.0.10
type EventType string
EventType describes streaming events.
const ( EventTextDelta EventType = "text_delta" EventToolCall EventType = "tool_call" EventToolExecStart EventType = "tool_exec_start" // Emitted when tool execution begins EventUsage EventType = "usage" EventDone EventType = "done" EventError EventType = "error" EventRetry EventType = "retry" // Emitted when retrying after rate limit )
type GeminiProvider ¶
type GeminiProvider struct {
// contains filtered or unexported fields
}
GeminiProvider implements Provider using the Google Gemini API.
func NewGeminiProvider ¶
func NewGeminiProvider(apiKey, model string) *GeminiProvider
func (*GeminiProvider) Capabilities ¶ added in v0.0.10
func (p *GeminiProvider) Capabilities() Capabilities
func (*GeminiProvider) Credential ¶ added in v0.0.10
func (p *GeminiProvider) Credential() string
func (*GeminiProvider) Name ¶
func (p *GeminiProvider) Name() string
type Message ¶ added in v0.0.10
Message holds a role with structured parts.
func AssistantText ¶ added in v0.0.10
func SystemText ¶ added in v0.0.10
func ToolResultMessage ¶ added in v0.0.10
type OpenAICompatProvider ¶ added in v0.0.8
type OpenAICompatProvider struct {
// contains filtered or unexported fields
}
OpenAICompatProvider implements Provider for OpenAI-compatible APIs Used by Ollama, LM Studio, and other compatible servers.
func NewOpenAICompatProvider ¶ added in v0.0.8
func NewOpenAICompatProvider(baseURL, apiKey, model, name string) *OpenAICompatProvider
func NewOpenAICompatProviderWithHeaders ¶ added in v0.0.10
func NewOpenAICompatProviderWithHeaders(baseURL, apiKey, model, name string, headers map[string]string) *OpenAICompatProvider
func NewOpenRouterProvider ¶ added in v0.0.10
func NewOpenRouterProvider(apiKey, model, appURL, appTitle string) *OpenAICompatProvider
NewOpenRouterProvider creates an OpenRouter provider using OpenAI-compatible APIs.
func NewZenProvider ¶ added in v0.0.2
func NewZenProvider(apiKey, model string) *OpenAICompatProvider
NewZenProvider creates an OpenAICompatProvider preconfigured for OpenCode Zen. Zen provides free access to models like GLM 4.7 via opencode.ai. API key is optional: empty for free tier, or set ZEN_API_KEY for paid models.
func (*OpenAICompatProvider) Capabilities ¶ added in v0.0.10
func (p *OpenAICompatProvider) Capabilities() Capabilities
func (*OpenAICompatProvider) Credential ¶ added in v0.0.10
func (p *OpenAICompatProvider) Credential() string
func (*OpenAICompatProvider) ListModels ¶ added in v0.0.8
func (p *OpenAICompatProvider) ListModels(ctx context.Context) ([]ModelInfo, error)
ListModels returns available models from the server.
func (*OpenAICompatProvider) Name ¶ added in v0.0.8
func (p *OpenAICompatProvider) Name() string
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider implements Provider using the standard OpenAI API.
func NewOpenAIProvider ¶
func NewOpenAIProvider(apiKey, model string) *OpenAIProvider
func (*OpenAIProvider) Capabilities ¶ added in v0.0.10
func (p *OpenAIProvider) Capabilities() Capabilities
func (*OpenAIProvider) Credential ¶ added in v0.0.10
func (p *OpenAIProvider) Credential() string
func (*OpenAIProvider) Name ¶
func (p *OpenAIProvider) Name() string
type Part ¶ added in v0.0.10
type Part struct {
Type PartType
Text string
ToolCall *ToolCall
ToolResult *ToolResult
}
Part represents a single content part.
type Provider ¶
type Provider interface {
Name() string
Credential() string // Returns credential type for debugging (e.g., "api_key", "codex", "claude-code")
Capabilities() Capabilities
Stream(ctx context.Context, req Request) (Stream, error)
}
Provider streams model output events for a request.
func NewProvider ¶
NewProvider creates a new LLM provider based on the config. Providers are wrapped with automatic retry for rate limits (429) and transient errors.
func WrapWithRetry ¶ added in v0.0.12
func WrapWithRetry(p Provider, config RetryConfig) Provider
WrapWithRetry wraps a provider with retry logic.
type ReadURLTool ¶ added in v0.0.11
type ReadURLTool struct {
// contains filtered or unexported fields
}
ReadURLTool fetches web pages using Jina AI Reader.
func NewReadURLTool ¶ added in v0.0.11
func NewReadURLTool() *ReadURLTool
func (*ReadURLTool) Execute ¶ added in v0.0.11
func (t *ReadURLTool) Execute(ctx context.Context, args json.RawMessage) (string, error)
func (*ReadURLTool) Spec ¶ added in v0.0.11
func (t *ReadURLTool) Spec() ToolSpec
type Request ¶ added in v0.0.10
type Request struct {
Model string
Messages []Message
Tools []ToolSpec
ToolChoice ToolChoice
ParallelToolCalls bool
Search bool
ReasoningEffort string
MaxOutputTokens int
Temperature float32
TopP float32
Debug bool
DebugRaw bool
}
Request represents a single model turn.
type RetryConfig ¶ added in v0.0.12
RetryConfig configures retry behavior.
func DefaultRetryConfig ¶ added in v0.0.12
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns sensible defaults for rate limit retries.
type RetryProvider ¶ added in v0.0.12
type RetryProvider struct {
// contains filtered or unexported fields
}
RetryProvider wraps a provider with automatic retry on transient errors.
func (*RetryProvider) Capabilities ¶ added in v0.0.12
func (r *RetryProvider) Capabilities() Capabilities
func (*RetryProvider) Credential ¶ added in v0.0.12
func (r *RetryProvider) Credential() string
func (*RetryProvider) Name ¶ added in v0.0.12
func (r *RetryProvider) Name() string
type Stream ¶ added in v0.0.10
Stream yields events until io.EOF.
func WrapDebugStream ¶ added in v0.0.10
type Tool ¶ added in v0.0.10
type Tool interface {
Spec() ToolSpec
Execute(ctx context.Context, args json.RawMessage) (string, error)
}
Tool describes a callable external tool.
type ToolCall ¶ added in v0.0.10
type ToolCall struct {
ID string
Name string
Arguments json.RawMessage
}
ToolCall is a model-requested tool invocation.
type ToolChoice ¶ added in v0.0.10
type ToolChoice struct {
Mode ToolChoiceMode
Name string
}
ToolChoice configures which tool the model should call.
type ToolChoiceMode ¶ added in v0.0.10
type ToolChoiceMode string
ToolChoiceMode controls tool selection behavior.
const ( ToolChoiceAuto ToolChoiceMode = "auto" ToolChoiceNone ToolChoiceMode = "none" ToolChoiceRequired ToolChoiceMode = "required" ToolChoiceName ToolChoiceMode = "name" )
type ToolRegistry ¶ added in v0.0.10
type ToolRegistry struct {
// contains filtered or unexported fields
}
ToolRegistry stores tools by name for execution.
func NewToolRegistry ¶ added in v0.0.10
func NewToolRegistry() *ToolRegistry
func (*ToolRegistry) Register ¶ added in v0.0.10
func (r *ToolRegistry) Register(tool Tool)
type ToolResult ¶ added in v0.0.10
ToolResult is the output from executing a tool call.
type ToolSpec ¶ added in v0.0.10
ToolSpec describes a callable tool.
func EditToolSpec ¶ added in v0.0.10
func EditToolSpec() ToolSpec
EditToolSpec returns the tool spec for the edit tool.
func ReadURLToolSpec ¶ added in v0.0.11
func ReadURLToolSpec() ToolSpec
ReadURLToolSpec returns the tool spec for reading web pages.
func SuggestCommandsToolSpec ¶ added in v0.0.10
SuggestCommandsToolSpec returns the tool spec for command suggestions.
func UnifiedDiffToolSpec ¶ added in v0.0.10
func UnifiedDiffToolSpec() ToolSpec
UnifiedDiffToolSpec returns the tool spec for unified diff edits.
func WebSearchToolSpec ¶ added in v0.0.10
func WebSearchToolSpec() ToolSpec
WebSearchToolSpec returns the tool spec for external web search.
type WebSearchTool ¶ added in v0.0.10
type WebSearchTool struct {
// contains filtered or unexported fields
}
WebSearchTool executes searches through a Searcher.
func NewWebSearchTool ¶ added in v0.0.10
func NewWebSearchTool(searcher search.Searcher) *WebSearchTool
func (*WebSearchTool) Execute ¶ added in v0.0.10
func (t *WebSearchTool) Execute(ctx context.Context, args json.RawMessage) (string, error)
func (*WebSearchTool) Spec ¶ added in v0.0.10
func (t *WebSearchTool) Spec() ToolSpec