Documentation
¶
Index ¶
- Constants
- Variables
- func BrainInstructions() string
- func BrainPath() string
- func CompileHookMatcher(matcher string) (*regexp.Regexp, error)
- func Dir() (string, error)
- func Exists() bool
- func ExpandTemplate(v string) (string, error)
- func IsWholeRef(v string) bool
- func LoadCatalogs() map[string]Catalog
- func LogEvent(op, detail string)
- func MarkSetupDone()
- func MemoryOrganizerPath(configPath string) string
- func MigrateProjectDir(project string) error
- func Path() (string, error)
- func ProjectDir(project string) string
- func ProjectGoalMaxRounds(dir string) int
- func ProjectID(dir string) string
- func ReadJSON(name string, v any) error
- func ResolveEnvMap(env map[string]string) (map[string]string, error)
- func ResolveEnvMapContext(ctx context.Context, env map[string]string) (map[string]string, error)
- func ResolveHeader(v string) (string, error)
- func ResolveHeaderContext(ctx context.Context, v string) (string, error)
- func ResolveSecret(v string) (string, error)
- func ResolveSecretContext(ctx context.Context, v string) (string, error)
- func RestoreMemoryOrganizer(configPath string, m MemoryOrganizerConfig, saved bool) error
- func SaveCatalogs(cats map[string]Catalog) error
- func SaveMemoryOrganizer(configPath string, m MemoryOrganizerConfig) error
- func SetProjectGoalMaxRounds(dir string, n int) error
- func SetupDone() bool
- func SystemInstructions() string
- func SystemPath() string
- func Trust(dir string) error
- func TrustDecision(dir string) (trusted bool, source string)
- func Trusted(dir string) bool
- func TrustedPath() (string, error)
- func Untrust(dir string) error
- func UsageCost(cats map[string]Catalog, model, prov string, u ai.Usage) (cost float64, ok bool)
- func UserDir() (string, error)
- func ValidateHook(event string, i int, hook Hook) error
- func WebSearchKeyEnv(provider string) string
- func WriteJSON(name string, v any) error
- type AIApprovalConfig
- type BrowserConfig
- type Catalog
- func (c Catalog) ContextLength(id string) int
- func (c Catalog) Efforts(id string) []string
- func (c Catalog) Find(id string) *ModelInfoLite
- func (c Catalog) MaxCompletionTokens(id string) int
- func (c Catalog) Pricing(id string) (ai.TokenRates, bool)
- func (c Catalog) Stale() bool
- func (c Catalog) SupportsVision(id string) (vision, found bool)
- type ComputerConfig
- type Config
- func (c *Config) AdoptMemory(from *Config)
- func (c *Config) ImageConfigUnavailable() bool
- func (c *Config) OrderedProviderIDs() []string
- func (c *Config) RemoveProvider(name string)
- func (c *Config) Resolve(model, provider string) (Provider, Model, string, error)
- func (c *Config) Save() error
- func (c *Config) SaveFile(filename string) error
- func (c *Config) Snapshot() *Config
- func (c *Config) SubscriptionBilled(name string) bool
- type CustomHeader
- type Hook
- type LSPServer
- type MCPServer
- type MemoryConfig
- type MemoryOrganizerConfig
- type Model
- type ModelInfoLite
- type NotificationsConfig
- type PiModel
- type PromptFile
- type Provider
- type RulesCompatConfig
- type SamplingParams
- type SandboxConfig
- type StatusLineConfig
- type UnknownModelError
- type WebSearchConfig
- type WebSearchEffective
Constants ¶
const ( // MemoryOrganizerMinHours and MemoryOrganizerMaxHours bound a saved interval. MemoryOrganizerMinHours = 1 MemoryOrganizerMaxHours = 168 // DefaultMemoryOrganizerInterval applies when neither a saved setting nor a // startup flag gives one. DefaultMemoryOrganizerInterval = 24 * time.Hour )
const ( WebSearchTavily = "tavily" WebSearchBrave = "brave" WebSearchSearXNG = "searxng" WebSearchBocha = "bocha" WebSearchJina = "jina" )
Web search providers the web_search tool can call.
const ( // WebSearchDefaultResults is how many results a search returns unless the // configuration or the call asks for another count. WebSearchDefaultResults = 5 // WebSearchMaxResults caps every search, whatever the configuration or call asks. WebSearchMaxResults = 10 )
const ( EnvWebSearchProvider = "K_BRAIN_WEB_SEARCH_PROVIDER" EnvWebSearchAPIKey = "K_BRAIN_WEB_SEARCH_API_KEY" EnvWebSearchBaseURL = "K_BRAIN_WEB_SEARCH_BASE_URL" )
Environment variables that override the webSearch section. The general key variable wins over the provider-specific ones.
const ( WebSearchKeyFromEnv = "env" WebSearchKeyFromConfig = "config" )
Key sources reported by WebSearchEffective.KeySource.
const DefaultCompactModel = "model1"
const DefaultCompactPct = 90
const DefaultGoalMaxRounds = 100
const SecretCmdTimeout = 5 * time.Second
const SystemSeed = `` /* 5834-byte string literal not displayed */
Variables ¶
var HookEvents = []string{
"SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure",
"PreCompact", "PostCompact", "Stop", "SessionEnd",
}
HookEvents lists the lifecycle events a hooks entry may name.
var HookToolEvents = []string{"PreToolUse", "PostToolUse", "PostToolUseFailure"}
HookToolEvents are the hook events that carry a tool name and accept a matcher.
var WebSearchProviders = []string{WebSearchTavily, WebSearchBrave, WebSearchSearXNG, WebSearchBocha, WebSearchJina}
WebSearchProviders lists the supported webSearch.provider values.
Functions ¶
func BrainInstructions ¶ added in v0.103.0
func BrainInstructions() string
func CompileHookMatcher ¶ added in v0.107.40
CompileHookMatcher compiles a hook matcher. An empty matcher or "*" matches every tool and yields nil. Anything else is a regular expression that must match the whole tool name, so "bash" matches only bash and "edit|write" matches either.
func ExpandTemplate ¶
func IsWholeRef ¶
func LoadCatalogs ¶
func MarkSetupDone ¶
func MarkSetupDone()
func MemoryOrganizerPath ¶ added in v0.107.28
MemoryOrganizerPath is the organizer schedule file for a config file.
func MigrateProjectDir ¶ added in v0.107.0
func ProjectDir ¶ added in v0.107.0
func ProjectGoalMaxRounds ¶
func ResolveEnvMapContext ¶ added in v0.103.0
func ResolveHeader ¶
func ResolveHeaderContext ¶ added in v0.103.0
func ResolveSecret ¶
func ResolveSecretContext ¶ added in v0.103.0
func RestoreMemoryOrganizer ¶ added in v0.107.28
func RestoreMemoryOrganizer(configPath string, m MemoryOrganizerConfig, saved bool) error
RestoreMemoryOrganizer puts back a schedule file state captured before a save: saved=false removes the file.
func SaveCatalogs ¶
func SaveMemoryOrganizer ¶ added in v0.107.28
func SaveMemoryOrganizer(configPath string, m MemoryOrganizerConfig) error
SaveMemoryOrganizer atomically writes the schedule file for a config file.
func SetProjectGoalMaxRounds ¶
func SystemInstructions ¶ added in v0.106.0
func SystemInstructions() string
func SystemPath ¶ added in v0.106.0
func SystemPath() string
func TrustDecision ¶ added in v0.107.40
TrustDecision reports whether dir is trusted and which recorded folder (dir itself or its nearest recorded ancestor) decided it. source is empty when no record covers dir.
func TrustedPath ¶ added in v0.103.0
func Untrust ¶ added in v0.107.40
Untrust revokes trust for dir. Its own record is removed; when an ancestor record would still grant trust, an explicit trusted = false record is kept for dir instead so the revocation sticks. Records of descendants are left as they are.
func UsageCost ¶ added in v0.107.34
UsageCost prices usage of model on provider prov with the model catalogs' rates, in USD. It is the cost logic of the kn /usage card and the backend's usage statistics. With prov empty the model must appear in exactly one catalog. ok is false when the route has no known price (or the usage is inconsistent); usage of zero tokens always costs 0.
func ValidateHook ¶ added in v0.107.40
ValidateHook checks entry i of the hooks configured for event.
func WebSearchKeyEnv ¶ added in v0.107.33
WebSearchKeyEnv names the provider-specific API key variable, or "" when the provider has none.
Types ¶
type AIApprovalConfig ¶ added in v0.107.6
type AIApprovalConfig struct {
Mode string `json:"mode"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
}
func (AIApprovalConfig) Enabled ¶ added in v0.107.6
func (c AIApprovalConfig) Enabled() bool
func (*AIApprovalConfig) UnmarshalJSON ¶ added in v0.107.6
func (c *AIApprovalConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON accepts the read-only perRun marker that /v1/settings adds (capability ai_review_per_run), so a host can write back exactly what it read. The marker is never stored; any other unknown field is still rejected.
func (AIApprovalConfig) Validate ¶ added in v0.107.6
func (c AIApprovalConfig) Validate() error
type BrowserConfig ¶
type Catalog ¶
type Catalog struct {
FetchedAt time.Time `json:"fetchedAt"`
BaseURL string `json:"baseUrl"`
Models []ModelInfoLite `json:"models"`
}
func (Catalog) ContextLength ¶
func (Catalog) Find ¶
func (c Catalog) Find(id string) *ModelInfoLite
func (Catalog) MaxCompletionTokens ¶
func (Catalog) SupportsVision ¶
type ComputerConfig ¶
type ComputerConfig struct {
Backend string `json:"backend,omitempty"`
Command []string `json:"command,omitempty"`
ApprovalPolicy string `json:"approvalPolicy,omitempty"`
Allow []string `json:"allow,omitempty"`
Deny []string `json:"deny,omitempty"`
DefaultDeny *bool `json:"defaultDeny,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}
type Config ¶
type Config struct {
// Image is optional. Public JSON is redacted; marshalConfig uses private disk types.
Image *imaging.ImageSettings `json:"image,omitempty"`
Language string `json:"language,omitempty"`
DefaultModel string `json:"defaultModel"`
DefaultProvider string `json:"defaultProvider,omitempty"`
DefaultEffort string `json:"defaultEffort,omitempty"`
CompactModel string `json:"compactModel,omitempty"`
CompactProvider string `json:"compactProvider,omitempty"`
CompactPct int `json:"compactPct,omitempty"`
TaskModel string `json:"taskModel,omitempty"`
TaskProvider string `json:"taskProvider,omitempty"`
Theme string `json:"theme,omitempty"`
Mouse *bool `json:"mouse,omitempty"`
Thinking *bool `json:"thinking,omitempty"`
CollapsePaste *bool `json:"collapsePaste,omitempty"`
GoalMaxRounds int `json:"goalMaxRounds,omitempty"`
// GoalVerify turns the independent check of a GOAL_MET claim on or off; nil is on.
GoalVerify *bool `json:"goalVerify,omitempty"`
// GoalVerifyMaxRejections caps verifier rejections per goal; 0 uses the default.
GoalVerifyMaxRejections int `json:"goalVerifyMaxRejections,omitempty"`
WorktreeSubagents *bool `json:"worktreeSubagents,omitempty"`
MaxRetries int `json:"maxRetries,omitempty"`
Experimental []string `json:"experimental,omitempty"`
Providers map[string]Provider `json:"providers"`
// ProviderOrder is the user's display order. It is persisted per provider inside
// metadata (see providerOrderMetadataKey); empty means providers sort by ID.
ProviderOrder []string `json:"-"`
Models map[string]Model `json:"-"`
MCPServers map[string]MCPServer `json:"mcp,omitempty"`
LSPServers map[string]LSPServer `json:"lsp,omitempty"`
Browser BrowserConfig `json:"browser,omitzero"`
// Memory is persisted in the memorySwitchSuffix file, never in config.json; the key is still
// read so values written by earlier builds of the switch carry over.
Memory MemoryConfig `json:"memory,omitzero"`
// WebSearch configures the third-party search service behind the web_search
// tool, used when web search is on but the model's API has no native search.
WebSearch WebSearchConfig `json:"webSearch,omitzero"`
AIApproval AIApprovalConfig `json:"aiApproval,omitzero"`
Computer ComputerConfig `json:"computer,omitzero"`
Sandbox SandboxConfig `json:"sandbox,omitzero"`
Hooks map[string][]Hook `json:"hooks,omitempty"`
RulesCompat RulesCompatConfig `json:"rulesCompat,omitzero"`
// Notifications and StatusLine are terminal UI settings.
Notifications NotificationsConfig `json:"notifications,omitzero"`
StatusLine StatusLineConfig `json:"statusLine,omitzero"`
// contains filtered or unexported fields
}
func LoadFile ¶ added in v0.107.0
LoadFile reads a configuration without changing the user's default file.
func (*Config) AdoptMemory ¶ added in v0.107.6
AdoptMemory takes the switch from a freshly loaded config, with the disk state that load observed, so this config shows it and a later Save writes it only when the disk needs it (a legacy config.json value still moves into the switch file).
func (*Config) ImageConfigUnavailable ¶ added in v0.107.6
ImageConfigUnavailable reports an isolated optional configuration failure. The original image document is retained privately for subsequent saves.
func (*Config) OrderedProviderIDs ¶ added in v0.107.6
OrderedProviderIDs returns every configured provider ID in display order: IDs listed in ProviderOrder first, then any remaining providers sorted by ID.
func (*Config) RemoveProvider ¶
func (*Config) SaveFile ¶ added in v0.107.0
SaveFile atomically replaces the explicit backend configuration, including an empty catalog.
func (*Config) SubscriptionBilled ¶ added in v0.107.34
SubscriptionBilled reports whether provider name is billed by subscription rather than per token, so catalog prices do not describe what it costs.
type CustomHeader ¶ added in v0.107.0
type Hook ¶ added in v0.103.0
type Hook struct {
Command string `json:"command"`
Shell string `json:"shell,omitempty"`
Timeout int `json:"timeout,omitempty"`
// Matcher selects the tools a PreToolUse, PostToolUse or PostToolUseFailure
// hook runs for; see CompileHookMatcher. Other events reject it.
Matcher string `json:"matcher,omitempty"`
}
type MCPServer ¶
type MCPServer struct {
Command []string `json:"command,omitempty"`
Env map[string]string `json:"env,omitempty"`
Cwd string `json:"cwd,omitempty"`
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Note string `json:"note,omitempty"`
StartupTimeout int `json:"startupTimeout,omitempty"`
ToolTimeout int `json:"toolTimeout,omitempty"`
}
type MemoryConfig ¶ added in v0.107.6
type MemoryConfig struct {
Enabled *bool `json:"enabled,omitempty"`
}
MemoryConfig is the memory master switch. Off stops memory injection, hidden extraction and the agent memory tools; stored memories and the memory management API stay available.
func (MemoryConfig) IsEnabled ¶ added in v0.107.6
func (m MemoryConfig) IsEnabled() bool
IsEnabled defaults to true so configurations written before the switch keep memory on.
type MemoryOrganizerConfig ¶ added in v0.107.28
type MemoryOrganizerConfig struct {
Enabled bool `json:"enabled"`
IntervalHours float64 `json:"intervalHours"`
}
MemoryOrganizerConfig is a saved organizer schedule. Both fields are always written; a file missing either is treated as unreadable.
func LoadMemoryOrganizer ¶ added in v0.107.28
func LoadMemoryOrganizer(configPath string) (m MemoryOrganizerConfig, saved bool, err error)
LoadMemoryOrganizer reads the saved schedule for a config file. saved is false when no schedule was ever saved; an unreadable or invalid file is an error and leaves saved false, so callers fall back to the startup default.
func (MemoryOrganizerConfig) Interval ¶ added in v0.107.28
func (m MemoryOrganizerConfig) Interval() time.Duration
Interval converts the saved hours to a duration.
func (MemoryOrganizerConfig) Validate ¶ added in v0.107.28
func (m MemoryOrganizerConfig) Validate() error
Validate checks the saved interval range (1 to 168 hours, inclusive).
type Model ¶
type Model struct {
Name string `json:"name,omitempty"`
DisplayName string `json:"displayName,omitempty"`
OwnedBy string `json:"ownedBy,omitempty"`
LimitsSource string `json:"limitsSource,omitempty"`
OutputModalities []string `json:"outputModalities,omitempty"`
// ImageAdapter explicitly selects an image protocol; "disabled" opts out of discovery.
ImageAdapter string `json:"imageAdapter,omitempty"`
InputModalities []string `json:"inputModalities,omitempty"`
Providers []string `json:"providers"`
ID string `json:"id,omitempty"`
Context int `json:"context,omitempty"`
MaxOut int `json:"maxOut,omitempty"`
Vision bool `json:"vision,omitempty"`
SamplingParams *SamplingParams `json:"samplingParams,omitempty"`
// ProviderMetadata holds per-provider metadata that differs from the
// shared fields above; use ForProvider to read a provider's view of the model.
ProviderMetadata map[string]Model `json:"providerMetadata,omitempty"`
}
func (Model) ContextWindow ¶
func (*Model) DropProvider ¶ added in v0.107.6
DropProvider removes provider from m. When the remaining providers all carry overrides, the first one is promoted to the shared metadata so the record stays as small as possible.
func (Model) ForProvider ¶ added in v0.107.6
ForProvider returns m with the metadata the given provider declared for it. Models are keyed globally by ID, so two providers serving the same ID may disagree on context window, max output or modalities; the shared record holds one variant and ProviderMetadata holds the rest.
func (Model) Metadata ¶ added in v0.107.6
Metadata returns the provider-independent part of m: everything except the provider list, ID and per-provider overrides.
func (*Model) SetProviderMetadata ¶ added in v0.107.6
SetProviderMetadata records meta as provider's view of m, storing an override only when it differs from the shared metadata.
type ModelInfoLite ¶
type ModelInfoLite struct {
ID string `json:"id"`
ContextLength int `json:"contextLength,omitempty"`
MaxCompletionTokens int `json:"maxCompletionTokens,omitempty"`
ReasoningEfforts []string `json:"reasoningEfforts,omitempty"`
Pricing *ai.TokenRates `json:"pricing,omitempty"`
InputModalities []string `json:"inputModalities,omitempty"`
}
type NotificationsConfig ¶ added in v0.107.21
type NotificationsConfig struct {
Desktop string `json:"desktop,omitempty"`
Title *bool `json:"title,omitempty"`
}
NotificationsConfig controls desktop notifications and the window title.
desktop: "auto" (default: notify while the terminal reports it is
unfocused, once it has proved it reports focus), "on", "off",
or a fixed route: "osc9", "osc777", "bel"
title: set the terminal title to the session (default true)
type PiModel ¶
type PiModel struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
DisplayName string `json:"displayName,omitempty"`
OwnedBy string `json:"ownedBy,omitempty"`
LimitsSource string `json:"limitsSource,omitempty"`
OutputModalities []string `json:"outputModalities,omitempty"`
// ImageAdapter explicitly selects an image protocol; "disabled" opts out of discovery.
ImageAdapter string `json:"imageAdapter,omitempty"`
InputModalities []string `json:"inputModalities,omitempty"`
API string `json:"api,omitempty"`
Reasoning bool `json:"reasoning,omitempty"`
Input []string `json:"input,omitempty"`
ContextWindow int `json:"contextWindow,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
SamplingParams *SamplingParams `json:"samplingParams,omitempty"`
}
type PromptFile ¶ added in v0.106.0
type PromptFile struct {
Scope string
Path string
Text string
// User marks the user's own standing rules (for example ~/.claude/CLAUDE.md), as
// opposed to rules that belong to the project tree.
User bool
}
func InstructionFiles ¶ added in v0.107.13
func InstructionFiles(wd string) []PromptFile
InstructionFiles returns every instruction file that applies to wd, in prompt order: user-level compatibility files first, then each directory from the project root down to wd. Within a directory the order is AGENTS.md, CLAUDE.md, .claude/CLAUDE.md, CLAUDE.local.md, .claude/CLAUDE.local.md, .cursorrules, .cursor/rules and finally the native .liveagent/brain.md, so later (deeper, more local) files win on conflicts.
A file reachable through several names (symlinks, hard links, case-insensitive filesystems) and a file whose text repeats an earlier one are included once.
func ProjectPromptFiles ¶ added in v0.106.0
func ProjectPromptFiles(wd string) []PromptFile
ProjectPromptFiles returns the project-tree instruction files, root first.
type Provider ¶
type Provider struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
BaseURL string `json:"baseUrl"`
IsFullURL bool `json:"isFullUrl,omitempty"`
ModelsURL string `json:"modelsUrl,omitempty"`
API string `json:"api"`
APIKey string `json:"apiKey"`
CustomHeaders []CustomHeader `json:"customHeaders,omitempty"`
ActiveModels []string `json:"activeModels"`
ModelOrder []string `json:"modelOrder,omitempty"`
RequestFormat string `json:"requestFormat,omitempty"`
Reasoning string `json:"reasoning,omitempty"`
PromptCacheHintMode string `json:"promptCacheHintMode,omitempty"`
NativeWebSearchEnabled bool `json:"nativeWebSearchEnabled,omitempty"`
UseSystemProxy bool `json:"useSystemProxy,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
PromptCachingEnabled *bool `json:"promptCachingEnabled,omitempty"`
PromptCacheRetention string `json:"promptCacheRetention,omitempty"`
RetryPolicy map[string]any `json:"retryPolicy,omitempty"`
UsageQuery map[string]any `json:"usageQuery,omitempty"`
CacheSessionAffinity *bool `json:"cacheSessionAffinity,omitempty"`
CacheControlFormat string `json:"cacheControlFormat,omitempty"`
CacheCapabilities ai.CacheCapabilities `json:"cacheCapabilities,omitzero"`
Models []PiModel `json:"models"`
}
func (Provider) ModelActive ¶ added in v0.107.0
func (Provider) ResolveKey ¶
type RulesCompatConfig ¶ added in v0.107.13
type RulesCompatConfig struct {
Claude *bool `json:"claude,omitempty"`
Cursor *bool `json:"cursor,omitempty"`
}
RulesCompatConfig toggles discovery of instruction files written for other agent harnesses. Both sources default to on; set a field to false to opt out.
claude: CLAUDE.md, CLAUDE.local.md, .claude/CLAUDE*.md, ~/.claude/CLAUDE.md, .claude/skills cursor: .cursor/rules/*.md|*.mdc and the legacy .cursorrules
func RulesCompatSettings ¶ added in v0.107.13
func RulesCompatSettings() RulesCompatConfig
RulesCompatSettings reads the rulesCompat switches straight from config.json. It never writes defaults, so prompt assembly stays free of side effects; any read or parse problem falls back to the defaults (everything on).
func (RulesCompatConfig) ClaudeEnabled ¶ added in v0.107.13
func (r RulesCompatConfig) ClaudeEnabled() bool
func (RulesCompatConfig) CursorEnabled ¶ added in v0.107.13
func (r RulesCompatConfig) CursorEnabled() bool
type SamplingParams ¶
type SandboxConfig ¶ added in v0.103.0
type SandboxConfig struct {
Mode string `json:"mode,omitempty"`
Backend string `json:"backend,omitempty"`
Network *bool `json:"network,omitempty"`
Writable []string `json:"writable,omitempty"`
ReadOnly []string `json:"readOnly,omitempty"`
// EnvKeep names variables (globs allowed) sandboxed commands still inherit
// although they look like credentials.
EnvKeep []string `json:"envKeep,omitempty"`
}
type StatusLineConfig ¶ added in v0.107.21
type StatusLineConfig struct {
Command string `json:"command,omitempty"`
// IntervalMs is the shortest gap between runs (default 2000, at least 500).
IntervalMs int `json:"intervalMs,omitempty"`
// TimeoutMs bounds one run (default 1000).
TimeoutMs int `json:"timeoutMs,omitempty"`
}
StatusLineConfig runs a command whose first output line is shown in the terminal UI's footer. The command gets the session as JSON on stdin. Off while Command is empty.
type UnknownModelError ¶
type UnknownModelError struct {
Model string
// contains filtered or unexported fields
}
func (*UnknownModelError) Error ¶
func (e *UnknownModelError) Error() string
type WebSearchConfig ¶ added in v0.107.33
type WebSearchConfig struct {
Provider string `json:"provider,omitempty"`
APIKey string `json:"apiKey,omitempty"`
BaseURL string `json:"baseUrl,omitempty"`
MaxResults int `json:"maxResults,omitempty"`
}
WebSearchConfig is the webSearch section: the third-party search service the web_search tool calls when web search is on and the model's API cannot search natively.
provider: tavily, brave, searxng, bocha or jina
apiKey: the service's key; like provider keys it may be $ENV, ${ENV} or !command
baseUrl: the service root (required for searxng, optional override for the others)
maxResults: results per search (default 5, at most 10)
func (WebSearchConfig) Effective ¶ added in v0.107.33
func (w WebSearchConfig) Effective() WebSearchEffective
Effective applies the K_BRAIN_WEB_SEARCH_* and provider key variables over the section and says whether the result is usable. Precedence for the key: K_BRAIN_WEB_SEARCH_API_KEY, then the provider's own variable (TAVILY_API_KEY, BRAVE_SEARCH_API_KEY, BOCHA_API_KEY, JINA_API_KEY), then webSearch.apiKey.
func (WebSearchConfig) Validate ¶ added in v0.107.33
func (w WebSearchConfig) Validate() error
Validate checks the stored section; environment overrides are judged by Effective, which reports a problem instead of failing the configuration.
type WebSearchEffective ¶ added in v0.107.33
type WebSearchEffective struct {
Provider string
BaseURL string
MaxResults int
// KeySource is WebSearchKeyFromEnv, WebSearchKeyFromConfig or "" (no key).
KeySource string
// Problem says why the web_search tool cannot be offered; "" when it can.
Problem string
// contains filtered or unexported fields
}
WebSearchEffective is the webSearch section with environment overrides applied. The key is kept as written (a secret reference is resolved only when a search runs), so building it never runs a command.
func (WebSearchEffective) Available ¶ added in v0.107.33
func (e WebSearchEffective) Available() bool
Available reports whether the web_search tool can be offered.
func (WebSearchEffective) KeyConfigured ¶ added in v0.107.33
func (e WebSearchEffective) KeyConfigured() bool
KeyConfigured reports whether an API key was found in the environment or the configuration.
func (WebSearchEffective) ResolveKey ¶ added in v0.107.33
func (e WebSearchEffective) ResolveKey(ctx context.Context) (string, error)
ResolveKey returns the API key, resolving a $ENV, ${ENV} or !command reference. Errors never contain the key.