Documentation
¶
Overview ¶
Package provider asks model provider APIs (Anthropic, and any OpenAI-compatible server) with a key the player saved, and runs the tool loop in process. It uses only the standard library for HTTP and SSE.
Index ¶
- Constants
- Variables
- func CleanKey(key string) (string, error)
- func DataDir() string
- func IsStart(err error) bool
- func KeyTarget(provider string) string
- func Save(path string, s Settings) error
- func SettingsPath() string
- type Adapter
- type Anthropic
- type Call
- type Cite
- type ClientRef
- type Endpoint
- type FileKeyStore
- type KeyStore
- type Lister
- type Loop
- type Message
- type NoToolsError
- type OpenAI
- type Preset
- type Reply
- type Request
- type Result
- type Settings
- type StartError
- type ToolDef
- type Tools
- type Usage
- type WebSearch
Constants ¶
const ( ClientAPI = "api" ClientCLI = "cli" )
Client kinds in the ordered client list.
const ( DefaultMaxTurns = 10 DefaultTimeout = 2 * time.Minute DefaultMaxResult = 16 << 10 )
Defaults.
const ( KindAnthropic = "anthropic" KindOpenAI = "openai" // OpenAI-compatible Chat Completions )
Kinds of adapter.
const ErrNoTools = "This model can't use tools; pick another."
ErrNoTools is the plain message shown when a model can't call tools.
const SettingsSchema = 1
SettingsSchema is the current layout version of providers.json.
Variables ¶
var ErrNoKey = errors.New("no key saved")
ErrNoKey says no key is saved for the provider.
var Presets = []Preset{ {ID: "anthropic", Name: "Anthropic (Claude)", Kind: KindAnthropic, BaseURL: "https://api.anthropic.com/v1", NeedKey: true, Models: map[string]string{"efficient": "claude-haiku-5-5", "balanced": "claude-sonnet-5-5", "best": "claude-opus-5-5"}, Doc: "https://platform.claude.com/docs/en/models/overview"}, {ID: "openai", Name: "OpenAI", Kind: KindOpenAI, BaseURL: "https://api.openai.com/v1", NeedKey: true, Models: map[string]string{"efficient": "gpt-6-luna", "balanced": "gpt-6.2-sol", "best": "gpt-6.2-astra"}, Doc: "https://developers.openai.com/api/docs/models", Extra: map[string]any{"reasoning_effort": "none"}}, {ID: "openrouter", Name: "OpenRouter", Kind: KindOpenAI, BaseURL: "https://openrouter.ai/api/v1", NeedKey: true, Models: map[string]string{"efficient": "anthropic/claude-haiku-5.5", "balanced": "anthropic/claude-sonnet-5.5", "best": "anthropic/claude-opus-5.5"}, Doc: "https://openrouter.ai/api/v1/models", Note: "Pick a free model from the list to pay nothing."}, {ID: "ollama", Name: "Ollama (on this PC)", Kind: KindOpenAI, BaseURL: "http://localhost:11434/v1", Local: true, Doc: "https://docs.ollama.com/api/openai-compatibility", Note: "Pick a model that supports tools."}, {ID: "lmstudio", Name: "LM Studio (on this PC)", Kind: KindOpenAI, BaseURL: "http://localhost:1234/v1", Local: true, Doc: "https://lmstudio.ai/docs/developer/openai-compat", Note: "Pick a model that supports tools."}, {ID: "custom", Name: "Other OpenAI-compatible server", Kind: KindOpenAI, Local: false, Doc: "", Note: "Enter the server's base URL (ending in /v1) and a model."}, }
Presets lists the providers. Model ids were read from each provider's own docs on 2026-11-24:
- Anthropic: https://platform.claude.com/docs/en/models/overview (Claude API IDs)
- OpenAI: https://developers.openai.com/api/docs/models (chat completions stays supported for tool calling per https://developers.openai.com/api/docs/guides/migrate-to-responses; reasoning_effort "none" is sent because tool calling in Chat Completions needs it on the newer models)
- OpenRouter: https://openrouter.ai/api/v1/models (ids are vendor/model; free models are chosen from the models list, as the free set changes)
- Ollama and LM Studio: no defaults; the installed models come from the server's /models endpoint.
Functions ¶
func DataDir ¶
func DataDir() string
DataDir is the advisor's data folder: <user config dir>/wowc-advisor.
Types ¶
type Adapter ¶
type Adapter interface {
Chat(ctx context.Context, req Request, onText func(string)) (Reply, error)
}
Adapter makes one model call; onText (may be nil) is told text as it streams.
func NewAdapter ¶
NewAdapter builds the adapter for a preset (or a custom base URL) with key.
type Anthropic ¶
type Anthropic struct{ Endpoint }
Anthropic talks to the Messages API (https://platform.claude.com/docs/en/api/messages). The system prompt and the tool list carry cache-control breakpoints, so repeat asks read them from the cache.
type Call ¶
type Call struct {
ID, Name string
Args json.RawMessage
}
Call is a tool call the model asked for.
type Cite ¶ added in v0.7.115
type Cite struct{ Title, URL string }
Cite is a page the model's answer cites from a web search.
type ClientRef ¶
type ClientRef struct {
Kind string `json:"kind"` // "api" or "cli"
Provider string `json:"provider,omitempty"` // a preset id, for an API client
BaseURL string `json:"base_url,omitempty"` // overrides the preset's (required for "custom")
Model string `json:"model,omitempty"` // a model id; empty: the tier's default
Tier string `json:"tier,omitempty"` // efficient, balanced or best; empty: the overlay's model setting
Agent string `json:"agent,omitempty"` // for a CLI client: a preset name or a command
}
ClientRef is one configured AI client. It holds no key: only whether one is saved is ever shown.
type Endpoint ¶
type Endpoint struct {
BaseURL string
Key string
HTTP *http.Client // nil: http.DefaultClient (the caller's context sets the timeout)
// Extra fields merged into every request body (for example reasoning_effort).
Extra map[string]any
}
Endpoint is where an adapter sends its calls. Key may be empty for a local server.
type FileKeyStore ¶
type FileKeyStore struct{ Dir string }
FileKeyStore keeps each key in its own file in Dir, readable only by the user (mode 0600, in a 0700 folder). It is the store wherever the platform has no small pure-Go keychain binding.
func (FileKeyStore) Delete ¶
func (f FileKeyStore) Delete(provider string) error
Delete removes the key.
func (FileKeyStore) Get ¶
func (f FileKeyStore) Get(provider string) (string, error)
Get reads the key.
func (FileKeyStore) Set ¶
func (f FileKeyStore) Set(provider, key string) error
Set writes the key, replacing any earlier one.
type KeyStore ¶
type KeyStore interface {
// Get returns the saved key, or ErrNoKey.
Get(provider string) (string, error)
Set(provider, key string) error
// Delete removes the key; deleting a key that is not there is not an error.
Delete(provider string) error
}
KeyStore keeps the player's API keys, one per provider. Keys never go in the config file or a log.
func DefaultKeyStore ¶
func DefaultKeyStore() KeyStore
DefaultKeyStore is a private file in the data folder: macOS and Linux have no small pure-Go keychain binding (the macOS one shells out to `security`, which would put the key in a process argument list), so the key sits in <data folder>/keys/<provider>.key, mode 0600 in a 0700 folder.
type Loop ¶
type Loop struct {
Adapter Adapter
Model string
System string
Prompt string
Tools Tools
MaxTurns int // at most this many model calls (default 10)
Timeout time.Duration // for the whole loop (default 2 minutes)
MaxResult int // bytes kept of one tool result (default 16 KiB)
Stream bool
OnText func(string)
// WebSearch offers the provider's web search; OnWeb is told, per model call, how many searches ran and
// which pages the text cited.
WebSearch *WebSearch
OnWeb func(searches int, cites []Cite)
}
Loop limits and inputs.
type Message ¶
type Message struct {
Role string // "user" or "assistant"
Text string
Calls []Call
Results []Result
// Server are the provider's own server-side tool blocks (web search calls and results) of an assistant
// turn, sent back as they came so the model keeps what it found.
Server []json.RawMessage
}
Message is one turn of the conversation. An assistant message carries text and tool calls; a user message carries text, or the results of the assistant's calls.
type NoToolsError ¶
type NoToolsError struct{}
NoToolsError is returned when the provider says the model does not support tools.
func (NoToolsError) Error ¶
func (NoToolsError) Error() string
type OpenAI ¶
type OpenAI struct{ Endpoint }
OpenAI talks to an OpenAI-compatible Chat Completions endpoint (BaseURL ends in /v1): OpenAI, OpenRouter, Ollama, LM Studio and the like. Key may be empty.
type Preset ¶
type Preset struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
BaseURL string `json:"base_url"`
NeedKey bool `json:"needs_key"`
Local bool `json:"local"` // a server on the player's PC: list its installed models
Models map[string]string `json:"models"` // default model id per tier (efficient, balanced, best)
Doc string `json:"doc"` // where the model ids were read
Note string `json:"note,omitempty"`
Extra map[string]any `json:"-"` // fields added to every request
}
Preset is a provider the player can pick.
type Reply ¶
type Reply struct {
Text string
Calls []Call
Usage Usage
// Server, Searches and Cites describe the provider's web search this call made: its raw blocks, how many
// searches ran and the pages the text cites. Paused means the provider stopped a long turn and wants it continued.
Server []json.RawMessage
Searches int
Cites []Cite
Paused bool
}
Reply is what one model call returned.
type Request ¶
type Request struct {
Model string
System string
Messages []Message
Tools []ToolDef
Stream bool
// WebSearch, when set, offers the provider's own server-side web search (Anthropic only; others ignore it).
WebSearch *WebSearch
}
Request is one model call.
type Settings ¶
type Settings struct {
// Schema is the layout version of providers.json. Changes are additive only (see docs/releasing.md).
Schema int `json:"schema,omitempty"`
Clients []ClientRef `json:"clients"`
}
Settings is the saved client list: tried in order, the first is the active one. Empty means the CLI-only setup the advisor always had (the agent from ask.json or detection).
type StartError ¶
type StartError struct{ Msg string }
Error kinds. StartError means the provider could not be used at all (no key, not reachable, key refused), so the next client in a fallback list may be tried. NoToolsError means the model cannot use tools.
func (*StartError) Error ¶
func (e *StartError) Error() string
type ToolDef ¶
type ToolDef struct {
Name, Description string
Schema json.RawMessage // JSON Schema of the arguments
}
ToolDef is a tool offered to the model.
type Tools ¶
type Tools interface {
List(ctx context.Context) ([]ToolDef, error)
// Call runs one tool; isErr marks a tool-level failure whose text is shown to the model.
Call(ctx context.Context, name string, args json.RawMessage) (text string, isErr bool, err error)
}
Tools is the set of tools the model may call.