config

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MCPTypeStdio          = "stdio"
	MCPTypeSSE            = "sse"
	MCPTypeStreamableHTTP = "streamable_http"
)

MCP transport types use exact lowercase identifiers with snake_case for multiple words. No aliases, case folding, whitespace trimming, or default apply.

View Source
const (
	ProviderTypeOpenAI    = "openai"
	ProviderTypeAnthropic = "anthropic"
	ProviderTypeGemini    = "gemini"
	ProviderTypeQwen      = "qwen"
	ProviderTypeQianfan   = "qianfan"
	ProviderTypeArk       = "ark"
	ProviderTypeDeepSeek  = "deepseek"
	ProviderTypeOllama    = "ollama"
)

Canonical provider types are exact lowercase identifiers. Aliases, case variants, and surrounding whitespace are rejected. Supported types are openai, anthropic, gemini, qwen, qianfan, ark, deepseek, and ollama. User-defined provider names and remote model IDs are independent of these identifiers.

View Source
const DefaultMaxSteps = 1000

DefaultMaxSteps is the ReAct loop cap used when an agent does not set max_steps. Eino's own default (12) is far too low once tools are involved.

View Source
const MCPToolNameMaxLength = 64

MCPToolNameMaxLength bounds runtime names including the server__ prefix.

View Source
const StarterConfig = `` /* 569-byte string literal not displayed */

StarterConfig is the configuration written on the first run. Oni3 already ships the common providers (OpenAI, Anthropic, Gemini, DeepSeek, Qwen, Kimi, Zhipu, MiniMax, Ollama and more), so this file only needs entries for custom endpoints. Models are imported from the provider at runtime and API keys are never stored here.

Variables

This section is empty.

Functions

func EnsureConfigFile added in v0.1.1

func EnsureConfigFile(path string) (bool, error)

EnsureConfigFile creates a starter configuration file at path when none exists yet. It reports whether the file was created.

func SkillDirectories

func SkillDirectories() []string

SkillDirectories returns the directories scanned for skill markdown files in priority order: on name clashes the first directory wins.

func ValidateMCPServerName

func ValidateMCPServerName(name string) error

ValidateMCPServerName reserves room for "__" and at least one remote name character. Names are used verbatim; case and punctuation are never normalized.

func ValidateMCPToolName

func ValidateMCPToolName(name string) error

ValidateMCPToolName checks the actual runtime name after converting the remote name to a local identifier and adding the server namespace.

func ValidateMCPType

func ValidateMCPType(kind string) error

ValidateMCPType accepts only the canonical MCP transport type constants.

func ValidateProviderType

func ValidateProviderType(kind string) error

ValidateProviderType accepts only the canonical provider type constants. Call with Provider.EffectiveType() when the empty OpenAI default applies.

Types

type A2AAgent added in v0.5.0

type A2AAgent struct {
	// CardURL points at the remote /.well-known/agent-card.json document.
	CardURL string `yaml:"card_url"`
	// Description is shown to the model when choosing a remote agent.
	Description string `yaml:"description,omitempty"`
	// Token is sent as a Bearer token when non-empty.
	Token string `yaml:"token,omitempty"`
	// TokenEnv names an environment variable holding the Bearer token. It is
	// read when the remote agent is first used.
	TokenEnv string `yaml:"token_env,omitempty"`
}

A2AAgent describes a remote agent reached over the A2A protocol.

type Agent

type Agent struct {
	// Name is the label shown in the interface. It is optional: when it is
	// empty the configuration key is used as the label.
	Name        string   `yaml:"name,omitempty"`
	Description string   `yaml:"description,omitempty"`
	System      string   `yaml:"system"`
	Model       string   `yaml:"model"`
	Tools       []string `yaml:"tools,omitempty"`
	MCPServers  []string `yaml:"mcp_servers,omitempty"`
	// MaxSteps caps the ReAct loop (model + tool rounds). It defaults to
	// DefaultMaxSteps when unset.
	MaxSteps int `yaml:"max_steps,omitempty"`
}

Agent represents AI agent configuration

type ApprovalConfig

type ApprovalConfig struct {
	Mode   string   `yaml:"mode,omitempty"`
	Allow  []string `yaml:"allow,omitempty"`
	Always []string `yaml:"always,omitempty"`
}

ApprovalConfig controls which tool calls must be confirmed by the user in interactive sessions (agent/chat TUI).

Mode is one of:

  • off: never ask
  • dangerous: ask only for calls a tool flags as mutating (default)
  • all: ask before every tool call

Allow lists tool names that never need approval; Always lists tools that always do (useful for MCP tools, which cannot be classified).

type BuiltinProvider added in v0.3.0

type BuiltinProvider struct {
	Name           string // configuration key, also the /provider value
	Type           string // canonical provider type
	BaseURL        string
	Description    string
	KeyURL         string // where to create an API key
	APIKeyOptional bool   // local servers need no key
}

BuiltinProvider is a provider preset that ships with Oni3. Presets are only added to the in-memory configuration when the user's file does not define a provider with the same name, so the configuration file always wins.

func BuiltinProviders added in v0.3.0

func BuiltinProviders() []BuiltinProvider

BuiltinProviders returns the provider presets shown on the first run and in the /provider palette. The catalog mirrors the vendors commonly used with Oni3; OpenAI-compatible endpoints use the openai type so a single client can talk to them.

type ConfLoader

type ConfLoader interface {
	Load(value *Value) error
}

type Config

type Config struct {
	Agents        map[string]Agent          `yaml:"agents,omitempty"`
	Providers     map[string]Provider       `yaml:"providers,omitempty"`
	Models        map[string]Model          `yaml:"models,omitempty"`
	DefaultModel  string                    `yaml:"default_model,omitempty"`
	MCPServers    map[string]MCPServer      `yaml:"mcp_servers,omitempty"`
	A2AAgents     map[string]A2AAgent       `yaml:"a2a_agents,omitempty"`
	Tools         map[string]Tool           `yaml:"tools,omitempty"`
	Skills        map[string]Skill          `yaml:"skills,omitempty"`
	Settings      Settings                  `yaml:"settings,omitempty"`
	Plugins       map[string]plugins.Config `yaml:"plugins,omitempty"`
	PluginThemes  map[string]plugins.Theme  `yaml:"-"`
	LoadedPlugins []*plugins.Plugin         `yaml:"-"`
	SourcePath    string                    `yaml:"-"`
	// contains filtered or unexported fields
}

Config represents the configuration for Oni3

func GetConfig

func GetConfig() *Config

GetConfig gets global configuration

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

LoadConfig loads configuration from file and saves to global variable

func (*Config) AddProviderModels

func (c *Config) AddProviderModels(providerName string, ids []string) ([]string, error)

AddProviderModels imports a batch atomically and returns usable model names in input order. Existing aliases and their generation settings are preserved.

func (*Config) AgentDisplayName

func (c *Config) AgentDisplayName(key string) string

AgentDisplayName returns the label of the agent with the given configuration key. It falls back to the key itself when no name is set.

func (*Config) AgentUsesDefaultModel

func (c *Config) AgentUsesDefaultModel(agentName string) bool

AgentUsesDefaultModel reports whether the agent follows the effective default model (its model is unset or equal to it). Agents that pin their own model in the config keep it, so they are not "default model" agents.

func (*Config) DefaultModelName

func (c *Config) DefaultModelName() string

DefaultModelName returns the effective default model: `default_model` when it names a configured model, otherwise the alphabetically first configured model. It returns "" when no model is configured.

func (*Config) EmitPluginEvent

func (c *Config) EmitPluginEvent(ctx context.Context, event plugins.Event) error

EmitPluginEvent invokes subscribers in configured plugin-name order. A hook error is returned to the caller, so failures cannot silently disappear.

func (*Config) HasPluginHook

func (c *Config) HasPluginHook(event string) bool

HasPluginHook reports whether an event has subscribers.

func (*Config) SetProviderAPIKey

func (c *Config) SetProviderAPIKey(providerName, key string) error

SetProviderAPIKey saves a successfully verified key before updating memory. An explicit key in the source YAML/plugin continues to win on the next load.

type LangfuseConfig

type LangfuseConfig struct {
	Host             string        `yaml:"host"`
	PublicKey        string        `yaml:"public_key"`
	SecretKey        string        `yaml:"secret_key"`
	Threads          int           `yaml:"threads,omitempty"`
	Timeout          time.Duration `yaml:"timeout,omitempty"`
	MaxTaskQueueSize int           `yaml:"max_task_queue_size,omitempty"`
	FlushAt          int           `yaml:"flush_at,omitempty"`
	FlushInterval    time.Duration `yaml:"flush_interval,omitempty"`
	SampleRate       float64       `yaml:"sample_rate,omitempty"`
	LogMessage       string        `yaml:"log_message,omitempty"`
	MaxRetry         uint64        `yaml:"max_retry,omitempty"`
	Name             string        `yaml:"name,omitempty"`
	UserID           string        `yaml:"user_id,omitempty"`
	SessionID        string        `yaml:"session_id,omitempty"`
	Release          string        `yaml:"release,omitempty"`
	Tags             []string      `yaml:"tags,omitempty"`
	Public           bool          `yaml:"public,omitempty"`
}

LangfuseConfig owns the YAML schema instead of relying on the SDK's untagged Go fields. Duration values include units, e.g. timeout: 30s.

func (*LangfuseConfig) SDKConfig

func (c *LangfuseConfig) SDKConfig() *langfuse.Config

SDKConfig converts the application schema to the upstream callback options.

type MCPServer

type MCPServer struct {
	// Type must be exactly stdio, sse, or streamable_http; it has no default.
	Type string `yaml:"type"`
	// Description is an optional label shown in the interface (e.g. the /mcp
	// palette). When it is empty a summary of the endpoint is shown instead.
	Description string `yaml:"description,omitempty"`
	// for stdio
	Cmd  string            `yaml:"cmd,omitempty"`
	Args []string          `yaml:"args,omitempty"`
	Env  map[string]string `yaml:"env,omitempty"`
	// for sse & streamable_http
	URL     string            `yaml:"url,omitempty"`
	Headers map[string]string `yaml:"headers,omitempty"`
	// Timeout bounds connecting to this server, in seconds. It covers the MCP
	// handshake and tool discovery; zero uses the default (60). A slow stdio
	// launcher (npx, uvx) may need more.
	Timeout int `yaml:"timeout,omitempty"`
}

MCPServer represents MCP server configuration

type Model

type Model struct {
	Provider    string  `yaml:"provider"`
	Model       string  `yaml:"model"`
	MaxTokens   int     `yaml:"max_tokens,omitempty"`
	Temperature float64 `yaml:"temperature,omitempty"`
	TopP        float64 `yaml:"top_p,omitempty"`
	TopK        int     `yaml:"top_k,omitempty"`
}

Model represents AI model configuration

type Provider

type Provider struct {
	// Type is an exact canonical identifier (see ProviderType constants).
	// Only the empty string defaults to openai; aliases and case variants fail.
	Type        string `yaml:"type,omitempty"`
	BaseURL     string `yaml:"base_url,omitempty"`
	APIKey      string `yaml:"api_key,omitempty"`
	Description string `yaml:"description,omitempty"`
	// KeyURL points at the page that issues an API key for this provider. It is
	// shown by the API key prompt; built-in presets fill it in.
	KeyURL string `yaml:"key_url,omitempty"`
	// ModelsURL may be absolute or relative to BaseURL. A relative path such as
	// "models" appends to its base path; "/models" replaces the base path.
	ModelsURL      string            `yaml:"models_url,omitempty"`
	ModelsPath     string            `yaml:"models_path,omitempty"`
	ModelIDPath    string            `yaml:"model_id_path,omitempty"`
	ModelNamePath  string            `yaml:"model_name_path,omitempty"`
	ModelHeaders   map[string]string `yaml:"model_headers,omitempty"`
	APIKeyOptional bool              `yaml:"api_key_optional,omitempty"`
}

Provider represents AI provider configuration

func (Provider) EffectiveType

func (p Provider) EffectiveType() string

EffectiveType applies the OpenAI default only to an empty Type. It preserves all nonempty values so validation can reject noncanonical spellings.

type Settings

type Settings struct {
	Langfuse *LangfuseConfig `yaml:"langfuse,omitempty"`
	Approval *ApprovalConfig `yaml:"approval,omitempty"`
}

Settings global settings

type Skill

type Skill struct {
	Description string   `yaml:"description,omitempty"`
	System      string   `yaml:"system,omitempty"`
	Tools       []string `yaml:"tools,omitempty"`
}

Skill represents an optional capability preset that can be switched on at runtime (via the /skill command in the TUI). A skill extends the active agent's system prompt and can add extra tools.

type Tool

type Tool struct {
	Type        string           `yaml:"type"`
	Description string           `yaml:"description,omitempty"`
	Config      map[string]Value `yaml:"config,omitempty"`
	Parameters  []ToolParameter  `yaml:"parameters,omitempty"`
	PluginTool  *plugins.Tool    `yaml:"-"`
}

Tool represents tool configuration

type ToolParameter

type ToolParameter struct {
	Name        string `yaml:"name"`
	Type        string `yaml:"type"`
	Description string `yaml:"description,omitempty"`
	Required    bool   `yaml:"required,omitempty"`
}

ToolParameter represents tool parameter configuration.

type Value

type Value struct {
	// contains filtered or unexported fields
}

func (*Value) Array

func (v *Value) Array() []*Value

func (*Value) Bool

func (v *Value) Bool() bool

func (*Value) Get

func (v *Value) Get(key string) *Value

func (*Value) GetBool

func (v *Value) GetBool(key string) bool

func (*Value) GetInt

func (v *Value) GetInt(key string) int

func (*Value) GetString

func (v *Value) GetString(key string) string

func (*Value) Int

func (v *Value) Int() int

func (*Value) IsArray

func (v *Value) IsArray() bool

func (*Value) IsEmpty

func (v *Value) IsEmpty() bool

func (*Value) IsMap

func (v *Value) IsMap() bool

func (*Value) IsScalar

func (v *Value) IsScalar() bool

func (*Value) Location

func (v *Value) Location() string

func (*Value) Map

func (v *Value) Map() map[string]*Value

func (*Value) Parse

func (v *Value) Parse(target interface{}) error

func (*Value) String

func (v *Value) String() string

func (*Value) UnmarshalYAML

func (v *Value) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

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