config

package
v0.107.39 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	WebSearchTavily  = "tavily"
	WebSearchBrave   = "brave"
	WebSearchSearXNG = "searxng"
	WebSearchBocha   = "bocha"
	WebSearchJina    = "jina"
)

Web search providers the web_search tool can call.

View Source
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
)
View Source
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.

View Source
const (
	WebSearchKeyFromEnv    = "env"
	WebSearchKeyFromConfig = "config"
)

Key sources reported by WebSearchEffective.KeySource.

View Source
const DefaultCompactModel = "model1"
View Source
const DefaultCompactPct = 90
View Source
const DefaultGoalMaxRounds = 100
View Source
const SecretCmdTimeout = 5 * time.Second
View Source
const SystemSeed = `` /* 5834-byte string literal not displayed */

Variables

View Source
var HookEvents = []string{
	"SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure",
	"PreCompact", "PostCompact", "Stop", "SessionEnd",
}

HookEvents lists the lifecycle events a hooks entry may name.

WebSearchProviders lists the supported webSearch.provider values.

Functions

func BrainInstructions added in v0.103.0

func BrainInstructions() string

func BrainPath added in v0.103.0

func BrainPath() string

func Dir

func Dir() (string, error)

func Exists

func Exists() bool

func ExpandTemplate

func ExpandTemplate(v string) (string, error)

func IsWholeRef

func IsWholeRef(v string) bool

func LoadCatalogs

func LoadCatalogs() map[string]Catalog

func LogEvent

func LogEvent(op, detail string)

func MarkSetupDone

func MarkSetupDone()

func MemoryOrganizerPath added in v0.107.28

func MemoryOrganizerPath(configPath string) string

MemoryOrganizerPath is the organizer schedule file for a config file.

func MigrateProjectDir added in v0.107.0

func MigrateProjectDir(project string) error

func Path added in v0.107.0

func Path() (string, error)

Path returns the default configuration file path.

func ProjectDir added in v0.107.0

func ProjectDir(project string) string

func ProjectGoalMaxRounds

func ProjectGoalMaxRounds(dir string) int

func ProjectID added in v0.103.0

func ProjectID(dir string) string

func ReadJSON

func ReadJSON(name string, v any) error

func ResolveEnvMap

func ResolveEnvMap(env map[string]string) (map[string]string, error)

func ResolveEnvMapContext added in v0.103.0

func ResolveEnvMapContext(ctx context.Context, env map[string]string) (map[string]string, error)

func ResolveHeader

func ResolveHeader(v string) (string, error)

func ResolveHeaderContext added in v0.103.0

func ResolveHeaderContext(ctx context.Context, v string) (string, error)

func ResolveSecret

func ResolveSecret(v string) (string, error)

func ResolveSecretContext added in v0.103.0

func ResolveSecretContext(ctx context.Context, v string) (string, error)

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 SaveCatalogs(cats map[string]Catalog) error

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 SetProjectGoalMaxRounds(dir string, n int) error

func SetupDone

func SetupDone() bool

func SystemInstructions added in v0.106.0

func SystemInstructions() string

func SystemPath added in v0.106.0

func SystemPath() string

func Trust

func Trust(dir string) error

func Trusted

func Trusted(dir string) bool

func TrustedPath added in v0.103.0

func TrustedPath() (string, error)

func UsageCost added in v0.107.34

func UsageCost(cats map[string]Catalog, model, prov string, u ai.Usage) (cost float64, ok bool)

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 UserDir added in v0.107.0

func UserDir() (string, error)

func WebSearchKeyEnv added in v0.107.33

func WebSearchKeyEnv(provider string) string

WebSearchKeyEnv names the provider-specific API key variable, or "" when the provider has none.

func WriteJSON

func WriteJSON(name string, v any) error

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 BrowserConfig struct {
	Mode string `json:"mode,omitempty"`

	CDPURL string `json:"cdpUrl,omitempty"`

	AllowPrivateURLs bool `json:"allowPrivateUrls,omitempty"`

	Enabled *bool `json:"enabled,omitempty"`
}

type Catalog

type Catalog struct {
	FetchedAt time.Time       `json:"fetchedAt"`
	BaseURL   string          `json:"baseUrl"`
	Models    []ModelInfoLite `json:"models"`
}

func (Catalog) ContextLength

func (c Catalog) ContextLength(id string) int

func (Catalog) Efforts

func (c Catalog) Efforts(id string) []string

func (Catalog) Find

func (c Catalog) Find(id string) *ModelInfoLite

func (Catalog) MaxCompletionTokens

func (c Catalog) MaxCompletionTokens(id string) int

func (Catalog) Pricing

func (c Catalog) Pricing(id string) (ai.TokenRates, bool)

func (Catalog) Stale

func (c Catalog) Stale() bool

func (Catalog) SupportsVision

func (c Catalog) SupportsVision(id string) (vision, found bool)

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"`

	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 Default

func Default() *Config

func Load

func Load() (*Config, error)

func LoadFile added in v0.107.0

func LoadFile(path string) (*Config, error)

LoadFile reads a configuration without changing the user's default file.

func (*Config) AdoptMemory added in v0.107.6

func (c *Config) AdoptMemory(from *Config)

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

func (c *Config) ImageConfigUnavailable() bool

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

func (c *Config) OrderedProviderIDs() []string

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 (c *Config) RemoveProvider(name string)

func (*Config) Resolve

func (c *Config) Resolve(model, provider string) (Provider, Model, string, error)

func (*Config) Save

func (c *Config) Save() error

func (*Config) SaveFile added in v0.107.0

func (c *Config) SaveFile(filename string) error

SaveFile atomically replaces the explicit backend configuration, including an empty catalog.

func (*Config) Snapshot

func (c *Config) Snapshot() *Config

func (*Config) SubscriptionBilled added in v0.107.34

func (c *Config) SubscriptionBilled(name string) bool

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 CustomHeader struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Hook added in v0.103.0

type Hook struct {
	Command string `json:"command"`
	Shell   string `json:"shell,omitempty"`
	Timeout int    `json:"timeout,omitempty"`
}

type LSPServer

type LSPServer struct {
	Command     []string          `json:"command,omitempty"`
	Extensions  []string          `json:"extensions,omitempty"`
	RootMarkers []string          `json:"rootMarkers,omitempty"`
	Env         map[string]string `json:"env,omitempty"`
	Enabled     *bool             `json:"enabled,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 (m Model) ContextWindow() int

func (*Model) DropProvider added in v0.107.6

func (m *Model) DropProvider(provider string)

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

func (m Model) ForProvider(provider string) Model

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

func (m Model) Metadata() Model

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

func (m *Model) SetProviderMetadata(provider string, meta Model)

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) Key

func (p Provider) Key() string

func (Provider) ModelActive added in v0.107.0

func (p Provider) ModelActive(id string) bool

func (Provider) ResolveKey

func (p Provider) ResolveKey() (string, error)

func (Provider) ResolveKeyContext added in v0.103.0

func (p Provider) ResolveKeyContext(ctx context.Context) (string, error)

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 SamplingParams struct {
	Temperature *float64 `json:"temperature,omitempty"`
	TopP        *float64 `json:"top_p,omitempty"`
}

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"`
}

func (SandboxConfig) Policy added in v0.103.0

func (s SandboxConfig) Policy(root string) *sandbox.Policy

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.

Jump to

Keyboard shortcuts

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