Documentation
¶
Overview ¶
Package provider defines the Provider interface and shared types for AI model inference backends (Ollama, Claude, OpenAI).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoHealthyProvider = errors.New("no healthy provider available")
ErrNoHealthyProvider is returned when no provider in the routing chain is healthy.
Functions ¶
This section is empty.
Types ¶
type ActivityNotifier ¶ added in v0.1.13
type ActivityNotifier interface {
SetOnActivity(fn func())
}
ActivityNotifier is an optional interface that providers may implement to support streaming progress detection. When a provider supports this, the runner sets a callback that fires whenever the provider produces output bytes, allowing the dispatcher heartbeat to reset on active output.
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Stream bool `json:"stream"` // always false for now
}
ChatRequest contains the parameters for a chat completion.
type ChatResponse ¶
type ChatResponse struct {
Model string `json:"model"`
Message Message `json:"message"`
// Token usage (if reported by provider).
PromptTokens int `json:"prompt_eval_count,omitempty"`
CompletionTokens int `json:"eval_count,omitempty"`
}
ChatResponse contains the result of a chat completion.
type Provider ¶
type Provider interface {
// Chat sends a chat completion request and returns the response.
Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)
// Healthy returns true if the provider is reachable and ready.
Healthy(ctx context.Context) bool
// Name returns the provider identifier (e.g., "ollama", "claude", "openai").
Name() string
}
Provider is the interface for AI model inference backends. Implementations exist for Ollama (local), Claude, and OpenAI (cloud).
type ProviderConfig ¶
type ProviderConfig struct {
Type string `yaml:"type"` // "claude", "openai", "ollama", "claude-cli"
APIKeyEnv string `yaml:"api_key_env"` // env var name for API key
BaseURL string `yaml:"base_url"` // override base URL (for ollama or custom endpoints)
DefaultModel string `yaml:"default_model"` // default model for this provider
TimeoutSeconds int `yaml:"timeout_seconds"` // per-provider timeout; 0 means use provider default
}
ProviderConfig describes a single provider entry in YAML config.
type ProviderFactory ¶
type ProviderFactory func(name string, cfg ProviderConfig) (Provider, error)
ProviderFactory constructs a Provider from a ProviderConfig. It is set by the application's wiring layer (e.g., cmd/samverk) to avoid the registry importing sub-packages directly in tests.
type ProviderInfo ¶
ProviderInfo describes a registered provider for listing.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds constructed providers and routing rules.
func LoadRegistry ¶
func LoadRegistry(path string, factory ProviderFactory) (*Registry, error)
LoadRegistry reads a YAML config file, constructs providers using the given factory, and returns a fully wired Registry.
func (*Registry) Get ¶
Get returns the first healthy provider from the routing chain for the given agent type. If the agent type is not configured, it falls back to "default". Returns (provider, model, error).
func (*Registry) List ¶
func (r *Registry) List(ctx context.Context) []ProviderInfo
List returns info about all registered providers with their health status.
func (*Registry) SetRouting ¶
SetRouting sets the routing table that maps agent types to provider chains.
type RegistryConfig ¶
type RegistryConfig struct {
Providers map[string]ProviderConfig `yaml:"providers"`
Routing map[string][]string `yaml:"routing"` // agent_type -> provider names
}
RegistryConfig is the top-level YAML structure for provider configuration.
func LoadRegistryConfig ¶
func LoadRegistryConfig(path string) (*RegistryConfig, error)
LoadRegistryConfig reads and parses a YAML config file.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claude implements the provider.Provider interface using the Anthropic Claude Messages API over raw net/http (no SDK dependency).
|
Package claude implements the provider.Provider interface using the Anthropic Claude Messages API over raw net/http (no SDK dependency). |
|
Package claudecli implements provider.Provider by shelling out to the Claude Code CLI (`claude --print`).
|
Package claudecli implements provider.Provider by shelling out to the Claude Code CLI (`claude --print`). |
|
Package ollama implements the provider.Provider interface using the Ollama REST API over raw net/http (no SDK dependency).
|
Package ollama implements the provider.Provider interface using the Ollama REST API over raw net/http (no SDK dependency). |
|
Package openai implements the provider.Provider interface using the OpenAI Chat Completions API over raw net/http (no SDK dependency).
|
Package openai implements the provider.Provider interface using the OpenAI Chat Completions API over raw net/http (no SDK dependency). |