config

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContainerNetworkModeContainerIP 直接访问容器 IP,不发布宿主机端口(默认)。
	ContainerNetworkModeContainerIP = "container_ip"
	// ContainerNetworkModeHostPort 随机发布到宿主机端口,经宿主机地址访问。
	ContainerNetworkModeHostPort = "host_port"
)

容器端口访问模式。

View Source
const (
	// BashExecutionModeHost 表示 bash 工具在宿主机上执行命令。
	BashExecutionModeHost = "host"
	// BashExecutionModeContainer 表示 bash 工具在容器模板终端中执行命令。
	BashExecutionModeContainer = "container"
)

bash 工具的执行模式。

View Source
const (
	// DefaultProvisionDistro 默认发行版名(仅 Windows 使用)。
	DefaultProvisionDistro = "gobrave-ubuntu-docker"
	// DefaultProvisionEndpoint 默认 daemon 地址。
	DefaultProvisionEndpoint = "tcp://localhost:2375"
)

自管运行时预置的默认值。

View Source
const (
	DefaultGitUser  = "gobrave"
	DefaultGitEmail = "gobrave@123.com"
)

默认 git 提交身份:config.yml 未配置 git 段或字段为空时使用。

View Source
const (
	// DatabaseLogLevelSilent 完全关闭 SQL 日志。
	DatabaseLogLevelSilent = "silent"
	// DatabaseLogLevelError 只打印执行报错的 SQL。
	DatabaseLogLevelError = "error"
	// DatabaseLogLevelWarn 打印慢查询与报错的 SQL。
	DatabaseLogLevelWarn = "warn"
	// DatabaseLogLevelInfo 打印每一条 SQL,仅用于排查问题。
	DatabaseLogLevelInfo = "info"
)

数据库 SQL 日志级别取值,与 GORM logger.LogLevel 一一对应。

View Source
const (
	// ModelVendorOpenAI OpenAI 官方(含所有 OpenAI 兼容网关)。
	ModelVendorOpenAI = "openai"
	// ModelVendorAnthropic Anthropic 官方(Claude)。
	ModelVendorAnthropic = "anthropic"
	// ModelVendorDeepSeek 深度求索(OpenAI 兼容协议)。
	ModelVendorDeepSeek = "deepseek"
	// ModelVendorGemini Google Gemini。
	ModelVendorGemini = "gemini"
	// ModelVendorOpenRouter OpenRouter 聚合网关(OpenAI 兼容协议)。
	ModelVendorOpenRouter = "openrouter"
	// ModelVendorXAI xAI Grok(OpenAI 兼容协议)。
	ModelVendorXAI = "xai"
	// ModelVendorGroq Groq 推理云(OpenAI 兼容协议)。
	ModelVendorGroq = "groq"
	// ModelVendorAzure Azure OpenAI。
	ModelVendorAzure = "azure"
	// ModelVendorVertexAI Google Vertex AI。
	ModelVendorVertexAI = "vertexai"
	// ModelVendorBedrock AWS Bedrock。
	ModelVendorBedrock = "bedrock"
)

模型厂商(Provider)预置配置。

目录中只保存「看图就能确定的」信息:厂商类型、默认 base_url、常见模型名与展示名。 其余可调参数(上下文窗口 / 最大输出 / 是否支持推理 / 价格 / 推理强度)通过 Overrides 补充,见 ModelVendorOverride。

设计要点:

  • config.agent.providers 中的条目与预置条目按模型名合并:用户显式填写的字段优先, 未填写的字段由预置补齐,因此「选厂商 + 填 API Key」即可完成模型配置;
  • providers 表的 key 是模型名(与 Profile.model 对应),统一小写;
  • base_url 留空表示使用厂商 SDK 的默认地址(这里只记录可读的默认值用于展示)。
View Source
const DefaultBashContainerTemplateID int64 = 2112483278714834944

DefaultBashContainerTemplateID 是 container 模式下 bash 工具默认使用的容器模板 ID。 取值即内置 ubuntu 模板(builtin/container_templates/ubuntu.json)的 definition 主键。

View Source
const DefaultConfigFileName = "config.yml"

DefaultConfigFileName 是默认的配置文件名。

View Source
const DefaultDatabaseLogLevel = DatabaseLogLevelWarn

DefaultDatabaseLogLevel 是 database.log_level 未配置或取值非法时的默认级别。

View Source
const DefaultMCPTimeoutSeconds = 60

DefaultMCPTimeoutSeconds 是启动时发现 MCP 工具的超时时间(秒)。

Variables

This section is empty.

Functions

func ConfigFilePath added in v0.1.4

func ConfigFilePath() (string, error)

ConfigFilePath 解析 config.yml 的路径,规则与 LoadConfig 保持一致: CLI --config > BRAVE_CONFIG_DIR > 当前工作目录。

func NormalizeBashExecutionMode added in v0.2.0

func NormalizeBashExecutionMode(mode string) (string, error)

NormalizeBashExecutionMode 归一化 bash 执行模式:空值回退 host,非法值报错。

func NormalizeContainerNetworkMode added in v0.2.4

func NormalizeContainerNetworkMode(mode string) (string, error)

NormalizeContainerNetworkMode 归一化容器网络模式:空值回退 container_ip,非法值报错。

func ResolveAppsPathPrefix

func ResolveAppsPathPrefix(cfg *Config) string

func ResolveContainerNetworkMode added in v0.2.4

func ResolveContainerNetworkMode(cfg *Config) string

ResolveContainerNetworkMode 返回生效的容器网络模式(未配置或非法值一律回退默认)。

func ResolveContainerRuntime

func ResolveContainerRuntime(cfg *Config) string

func ResolveContainerRuntimes added in v0.1.4

func ResolveContainerRuntimes(cfg *Config) []string

ResolveContainerRuntimes returns the normalized list of container runtimes to register at startup. It prefers the explicit `runtimes` list and falls back to the single resolved default runtime.

func ResolveDatabaseLogLevel added in v0.1.4

func ResolveDatabaseLogLevel(cfg *Config) string

ResolveDatabaseLogLevel 返回当前生效的数据库 SQL 日志级别。 cfg 或其 database 段为空时返回默认级别。

func ResolveGitIdentity added in v0.1.4

func ResolveGitIdentity(cfg *Config) (string, string)

ResolveGitIdentity 返回 git 提交使用的用户名与邮箱。 cfg 为 nil、git 段缺失或字段为空时,逐项回退到默认值。 保证返回值始终非空(go-git 的 commit author 不允许为空)。

func RuntimeProvisionEnabled added in v0.2.4

func RuntimeProvisionEnabled(cfg *Config) bool

RuntimeProvisionEnabled 报告是否启用容器运行时预置的启动自检 (container.docker.provision.enabled)。

与平台无关:Windows 上拉起 WSL 内的 dockerd,Linux 上拉起本机 dockerd。

func SaveConfigSection added in v0.1.4

func SaveConfigSection(key string, value any) (string, error)

SaveConfigSection 把某个顶层配置段写入 config.yml(不存在则创建), 其余配置段保持原样,该段中未建模的键也会保留。返回实际写入的文件路径。

func SetCLIFlags

func SetCLIFlags(f *CLIFlags)

SetCLIFlags sets the CLI overrides to be applied by LoadConfig. Call this before LoadConfig is invoked (e.g. in main.go).

func StorageBaseDir added in v0.2.3

func StorageBaseDir(cfg *Config) string

StorageBaseDir 返回 storage.base_dir(已去空白),未配置时返回空串。

它是宿主路径与容器路径的唯一锚点:盘符由它决定,容器路径由它派生 (见 containerruntime.PathMapper)。

func StorageDrive added in v0.2.0

func StorageDrive(cfg *Config) string

StorageDrive 返回 storage.base_dir 所在的 Windows 盘符前缀(形如 `D:\`)。

容器内路径是 POSIX 的(/data/1),而 Windows 宿主上的 storage.base_dir 形如 D:\workspace\gobrave\.gobrave;把容器路径还原成宿主路径时,盘符是唯一丢失的信息, 因此它由配置决定。Linux/macOS 上没有盘符,返回空串。

这是纯函数:盘符随时从 cfg 现算,调用方不需要额外缓存或初始化。

Types

type AgentConfig added in v0.1.2

type AgentConfig struct {
	// Providers 是「模型提供商」配置表,key 为模型名(与 Profile.Model 对应)。
	// 一次请求使用的模型由 Profile.Model 指定,据此在此表中查找 base_url / api_key 等 LLM 配置。
	Providers map[string]ModelProviderConfig `yaml:"providers" json:"providers"`
}

AgentConfig 是 AI Agent 调用框架的配置。 用于灵活切换第三方 Agent(claude_code / codex / copilot)以及后续自研 Agent。

type CLIFlags

type CLIFlags struct {
	ConfigPath     string // --config, config file path
	Port           int    // --port, server port
	Host           string // --host, server host
	LogPath        string // --log-path, server log path
	LogLevel       string // --log-level, log level (debug/info/warn/error/fatal)
	GinMode        string // --gin-mode, gin run mode (debug/release/test)
	DBDriver       string // --db-driver, database driver (sqlite/postgres)
	DBHost         string // --db-host, database host
	DBPort         string // --db-port, database port
	DBUser         string // --db-user, database user
	DBPassword     string // --db-password, database password
	DBName         string // --db-name, database name
	DBPath         string // --db-path, sqlite database file path
	DBSSLMode      string // --db-ssl-mode, database ssl mode
	DefaultRuntime string // --default-runtime, default container runtime (docker/k8s/k3s)
	BaseDir        string // --base-dir, storage base directory
	// contains filtered or unexported fields
}

CLIFlags holds command-line arguments that can override config.yml values.

func ParseCLIFlags

func ParseCLIFlags() *CLIFlags

ParseCLIFlags parses command-line flags into a CLIFlags struct. It does NOT call flag.Parse() — the caller should do that.

func (*CLIFlags) DisableRegistrationSet

func (f *CLIFlags) DisableRegistrationSet() (value bool, ok bool)

DisableRegistrationSet reports whether --disable-registration was explicitly provided on the command line and returns its value.

type Config

type Config struct {
	Server      *ServerConfig    `yaml:"server"   json:"server"`
	Database    *DatabaseConfig  `yaml:"database" json:"database"`
	Proxy       *ProxyConfig     `yaml:"proxy"    json:"proxy"`
	Route       *RouteConfig     `yaml:"route"    json:"route"`
	Storage     *StorageConfig   `yaml:"storage"  json:"storage"`
	Git         *GitConfig       `yaml:"git"      json:"git"`
	Realtime    *RealtimeConfig  `yaml:"realtime" json:"realtime"`
	LLM         *LLMConfig       `yaml:"llm" json:"llm"`
	Agent       *AgentConfig     `yaml:"agent" json:"agent"`
	MCP         *MCPConfig       `yaml:"mcp" json:"mcp"`
	Container   *ContainerConfig `yaml:"container" json:"container"`
	DebugConfig *DebugConfig     `yaml:"debug" json:"debug"`
	User        *UserConfig      `yaml:"user"  json:"user"`
	Log         *LogConfig       `yaml:"log"   json:"log"`
}

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig 加载配置:先取代码内置默认值,再用 config.yml 覆盖。 文件中没有出现的键会保留默认值,具体语义见 applyConfigData。

func (*Config) NewHTTPClient added in v0.2.0

func (c *Config) NewHTTPClient(timeout time.Duration) *http.Client

NewHTTPClient 返回当前配置下套用了代理的 http.Client。

func (*Config) NewHTTPTransport added in v0.2.0

func (c *Config) NewHTTPTransport() *http.Transport

NewHTTPTransport 返回当前配置下套用了代理的 Transport。

func (*Config) ProxyFunc added in v0.2.0

func (c *Config) ProxyFunc() func(*url.URL) (*url.URL, error)

ProxyFunc 返回当前配置下的出站代理选择函数;cfg 或其 proxy 段为 nil、 或未配置 http_proxy / https_proxy 时一律直连(忽略环境变量)。

type ConfigFile added in v0.1.4

type ConfigFile struct {
	// Path 是 config.yml 的绝对路径。
	Path string
	// Exists 表示文档被加载时文件是否已经存在。
	Exists bool
	// contains filtered or unexported fields
}

ConfigFile 表示 config.yml 的原始 YAML 文档。 它保留顶层与嵌套键的顺序,因此更新某个配置段时不会打乱文件中的其他内容。

func LoadConfigFile added in v0.1.4

func LoadConfigFile() (*ConfigFile, error)

LoadConfigFile 读取 config.yml。 文件不存在时返回 Exists=false 的空文档(不视为错误), 调用方可以据此回退到代码中的默认配置。

func (*ConfigFile) Save added in v0.1.4

func (d *ConfigFile) Save() error

Save 把文档写回 config.yml;文件或其父目录不存在时自动创建。

func (*ConfigFile) Section added in v0.1.4

func (d *ConfigFile) Section(key string) any

Section 返回某个顶层配置段的原始值,不存在时返回 nil。

func (*ConfigFile) SetSection added in v0.1.4

func (d *ConfigFile) SetSection(key string, value any)

SetSection 写入或替换一个顶层配置段。

func (*ConfigFile) SetSectionMerged added in v0.1.4

func (d *ConfigFile) SetSectionMerged(key string, value any) error

SetSectionMerged 用 value 覆盖某个顶层配置段,同时保留原段落中 value 未声明的键。

这样即使 config.yml 里存在当前版本结构体尚未建模的键(例如旧版本的 container.create_queue_enabled),保存其它字段时也不会把它们丢掉。

type ContainerConfig

type ContainerConfig struct {
	Kubernetes *KubernetesRuntimeConfig `yaml:"kubernetes" json:"kubernetes"`
	Docker     *DockerRuntimeConfig     `yaml:"docker" json:"docker"`
	// Runtimes is the list of container runtimes to register at startup.
	// e.g. [docker, k8s]. Each entry is normalized via normalizeContainerRuntime.
	Runtimes []string `yaml:"runtimes" json:"runtimes"`
	// DefaultRuntime is the runtime used when no specific runtime is selected.
	// Falls back to the first entry in Runtimes, then "docker".
	DefaultRuntime string `yaml:"default_runtime" json:"default_runtime"`
	// RefreshImageStatusOnStart           bool   `yaml:"refresh_image_status_on_start" json:"refresh_image_status_on_start"`
	RecoverRunningDagOnStart            bool   `yaml:"recover_running_dag_on_start" json:"recover_running_dag_on_start"`
	CleanupDagNodeContainersBeforeStart bool   `yaml:"cleanup_dag_node_containers_before_start" json:"cleanup_dag_node_containers_before_start"`
	DeleteContainerOnNodeSuccess        bool   `yaml:"delete_container_on_node_success" json:"delete_container_on_node_success"`
	DagNodeCleanupOnFailed              string `yaml:"dag_node_cleanup_on_failed" json:"dag_node_cleanup_on_failed"`
	DagNodeCleanupOnDagFinished         string `yaml:"dag_node_cleanup_on_dag_finished" json:"dag_node_cleanup_on_dag_finished"`
	// CreateQueueMaxConcurrency limits how many containers can be created concurrently.
	CreateQueueMaxConcurrency int `yaml:"create_queue_max_concurrency" json:"create_queue_max_concurrency"`
	// CreateQueueMaxPending limits how many creation requests can wait in the queue.
	CreateQueueMaxPending int `yaml:"create_queue_max_pending" json:"create_queue_max_pending"`
	// TerminalSessionTTLMinutes 是终端会话的空闲上限:空闲超过该时长即回收容器并删除记录。
	// <=0 使用默认 120 分钟。设置为很大的值时,只有显式删除 / 容器消失才会回收。
	TerminalSessionTTLMinutes int `yaml:"terminal_session_ttl_minutes" json:"terminal_session_ttl_minutes"`
	// TerminalMaxSessionsPerUser 是单用户同时存在的终端会话上限;<=0 使用默认 4。
	TerminalMaxSessionsPerUser int `yaml:"terminal_max_sessions_per_user" json:"terminal_max_sessions_per_user"`
	// TerminalBufferDir 是滚动缓冲落盘目录;留空使用 <storage.base_dir>/terminal_sessions。
	TerminalBufferDir string `yaml:"terminal_buffer_dir" json:"terminal_buffer_dir"`
	// TerminalBufferKB 是单个会话滚动缓冲的上限(KB);<=0 使用默认 1024。
	TerminalBufferKB int `yaml:"terminal_buffer_kb" json:"terminal_buffer_kb"`

	// BashExecutionMode 决定 bash 工具的实际执行位置:host(宿主机,默认)或 container(容器)。
	// 该开关只影响执行位置,Agent 对此无感知(工具参数不变)。
	BashExecutionMode string `yaml:"bash_execution_mode" json:"bash_execution_mode"`
	// BashContainerTemplateID 是 container 模式下 bash 工具使用的容器模板 ID。
	// <=0 时使用 DefaultBashContainerTemplateID。
	// ,string 让 JSON 同时接受字符串与数字:int64 主键超出 JS 安全整数范围,
	// 前端以字符串传递,不加该标记会报 cannot unmarshal string into int64。
	BashContainerTemplateID int64 `yaml:"bash_container_template_id" json:"bash_container_template_id,string"`

	// NetworkMode 决定应用容器端口的可达方式(container.network_mode)。
	//
	// 默认 container_ip:gobrave 直接访问容器 IP(docker0 / k8s Pod IP),
	// 不占用宿主机端口;适用于 Linux、Docker Desktop 等能与 daemon 共享网络的主机。
	//
	// host_port:容器端口随机发布到宿主机(-p 0.0.0.0:<random>:<port>),
	// gobrave 通过 宿主机地址 + 随机端口 访问;多实例不会端口冲突。
	// 用于「gobrave 无法路由容器 IP」的场景,典型是 Windows + WSL2 自管 dockerd
	// (容器 IP 在发行版内的 docker0 网桥上,Windows 不可路由)。
	NetworkMode string `yaml:"network_mode" json:"network_mode"`
}

func DefaultContainerConfig added in v0.1.4

func DefaultContainerConfig() *ContainerConfig

DefaultContainerConfig 返回 container 段在代码中的默认配置。 LoadConfig 与可视化配置共用它,保证 config.yml 缺失/缺段时的默认值一致。

type DatabaseConfig

type DatabaseConfig struct {
	Driver   string `yaml:"driver"   json:"driver"`
	Host     string `yaml:"host"     json:"host"`
	Port     string `yaml:"port"     json:"port"`
	User     string `yaml:"user"     json:"user"`
	Password string `yaml:"password" json:"password"`
	Name     string `yaml:"name"     json:"name"`
	SSLMode  string `yaml:"ssl_mode" json:"ssl_mode"`
	Path     string `yaml:"path"     json:"path"`
	// LogLevel 控制 GORM 的 SQL 日志级别,取值 silent / error / warn / info。
	// 默认 warn(只打印慢查询与报错的 SQL);设为 info 可打印每条 SQL,
	// 仅在排查问题时开启;设为 silent 完全关闭。
	// 该级别只影响 SQL 日志,与 log.level(进程日志级别)互不影响。
	LogLevel string `yaml:"log_level" json:"log_level"`
}

DatabaseConfig 数据库配置

type DebugConfig

type DebugConfig struct {
	// EnableDagOrchestrator 为 true 时,提交分析会把编排器入参写入调试目录。
	EnableDagOrchestrator bool `yaml:"enable_dag_orchestrator" json:"enable_dag_orchestrator"`
}

DebugConfig 调试开关。

type DockerRuntimeConfig added in v0.2.3

type DockerRuntimeConfig struct {
	// WSLDaemon 声明 docker daemon 是否运行在 WSL2 内。
	//
	// nil(未配置):Windows 上按照 DOCKER_HOST(tcp://…)自动推断;
	// true:强制开启,bind mount 的 Source 会从 D:\x 翻译成 /mnt/d/x;
	// false:强制关闭,Source 保持 Windows 盘符路径(Docker Desktop npipe 等)。
	WSLDaemon *bool `yaml:"wsl_daemon" json:"wsl_daemon"`

	// Provision 是 gobrave 自管运行时预置(Windows 上是 WSL 发行版,Linux 上是
	// 本机 dockerd)的配置段。
	Provision *RuntimeProvisionConfig `yaml:"provision" json:"provision"`
}

DockerRuntimeConfig 是 docker 运行时相关配置。

type GitConfig added in v0.1.4

type GitConfig struct {
	User  string `yaml:"user"  json:"user"`
	Email string `yaml:"email" json:"email"`
}

GitConfig 是版本仓库(脚本/工作流目录)的提交身份配置。 SaveScript 等在初始化 git 仓库并提交变更时用它构造 commit 的 author/committer。

func DefaultGitConfig added in v0.1.4

func DefaultGitConfig() *GitConfig

DefaultGitConfig 返回 git 段在代码中的默认配置。 LoadConfig 与可视化配置共用它,保证 config.yml 缺失/缺段时的默认值一致。

type K8sIngressRouteConfig

type K8sIngressRouteConfig struct {
	Namespace        string            `yaml:"namespace"          json:"namespace"`
	Kubeconfig       string            `yaml:"kubeconfig"         json:"kubeconfig"`
	InCluster        bool              `yaml:"in_cluster"         json:"in_cluster"`
	IngressClassName string            `yaml:"ingress_class_name" json:"ingress_class_name"`
	Host             string            `yaml:"host"               json:"host"`
	PathType         string            `yaml:"path_type"          json:"path_type"`
	Annotations      map[string]string `yaml:"annotations"        json:"annotations"`
}

type KubernetesRuntimeConfig

type KubernetesRuntimeConfig struct {
	Namespace  string `yaml:"namespace" json:"namespace"`
	Kubeconfig string `yaml:"kubeconfig" json:"kubeconfig"`
	InCluster  bool   `yaml:"in_cluster" json:"in_cluster"`
}

func DefaultKubernetesRuntimeConfig added in v0.1.4

func DefaultKubernetesRuntimeConfig() *KubernetesRuntimeConfig

DefaultKubernetesRuntimeConfig 返回 kubernetes 段的默认配置。

type LLMConfig

type LLMConfig struct {
	CLIURL      string             `yaml:"cli_url" json:"cli_url"`
	Model       string             `yaml:"model" json:"model"`
	GitHubToken string             `yaml:"github_token" json:"github_token"`
	Provider    *LLMProviderConfig `yaml:"provider" json:"provider"`
}

type LLMProviderConfig

type LLMProviderConfig struct {
	Type        string `yaml:"type" json:"type"`
	BaseURL     string `yaml:"base_url" json:"base_url"`
	APIKey      string `yaml:"api_key" json:"api_key"`
	BearerToken string `yaml:"bearer_token" json:"bearer_token"`
}

type LogConfig added in v0.1.4

type LogConfig struct {
	// Level 日志级别:trace/debug/info/warn/error/fatal/panic。默认 info。
	// 需要开启 debug 模式时将其设为 debug 即可。
	Level string `yaml:"level" json:"level"`
	// Path 日志文件路径;为空时使用默认路径 logs/app.log。
	Path string `yaml:"path" json:"path"`
	// Color 颜色模式:auto(默认,仅终端着色)/always/never。
	Color string `yaml:"color" json:"color"`
}

LogConfig 控制进程日志的级别与输出方式。 它的取值最终由 logger.Configure 应用,因此修改后无需改动日志代码。

func DefaultLogConfig added in v0.1.4

func DefaultLogConfig() *LogConfig

DefaultLogConfig 返回 log 段在代码中的默认配置。

type MCPConfig added in v0.2.0

type MCPConfig struct {
	// Enabled 是总开关;false 时不会连接任何 MCP 服务。
	Enabled bool `yaml:"enabled" json:"enabled"`
	// TimeoutSeconds 是启动时发现工具的超时时间(秒),<=0 时使用默认值 60。
	TimeoutSeconds int `yaml:"timeout_seconds" json:"timeout_seconds"`
	// Servers 是 MCP 服务表,key 为服务名。
	Servers map[string]MCPServerConfig `yaml:"servers" json:"servers"`
}

MCPConfig 描述外部 MCP(Model Context Protocol)服务配置。

启用后,服务启动时会连接各 MCP 服务并把其工具注册到 Agent 工具表, 工具名为 <服务名>_<工具名>。单个服务连接失败只记录日志并跳过。

func DefaultMCPConfig added in v0.2.0

func DefaultMCPConfig() *MCPConfig

DefaultMCPConfig 返回 mcp 段在代码中的默认配置(默认不配置任何服务)。

func ResolveMCPConfig added in v0.2.0

func ResolveMCPConfig(cfg *Config) *MCPConfig

ResolveMCPConfig 返回 nil 安全的 mcp 配置。

func (*MCPConfig) Timeout added in v0.2.0

func (c *MCPConfig) Timeout() time.Duration

Timeout 返回工具发现超时时间。

type MCPServerConfig added in v0.2.0

type MCPServerConfig struct {
	// Enabled 控制单个服务是否启用;nil 视为启用。
	Enabled *bool `yaml:"enabled" json:"enabled,omitempty"`
	// Type 是传输类型:stdio(默认)/ sse。留空时按 command / url 推断。
	Type string `yaml:"type" json:"type"`
	// Command / Args / Env 仅 stdio 使用。
	Command string            `yaml:"command" json:"command,omitempty"`
	Args    []string          `yaml:"args" json:"args,omitempty"`
	Env     map[string]string `yaml:"env" json:"env,omitempty"`
	// URL / Headers 仅 sse 使用。
	URL     string            `yaml:"url" json:"url,omitempty"`
	Headers map[string]string `yaml:"headers" json:"headers,omitempty"`
}

MCPServerConfig 是一个 MCP 服务的连接配置。

type ModelProviderConfig added in v0.1.4

type ModelProviderConfig struct {
	// ModelID 是模型标识(配置表的 key),与 API 模型名分离。
	ModelID string `yaml:"model_id" json:"model_id"`
	BaseURL string `yaml:"base_url" json:"base_url"`
	APIKey  string `yaml:"api_key" json:"api_key"`

	// Provider 是模型厂商类型(openai / anthropic / deepseek / gemini …)。
	Provider string `yaml:"provider" json:"provider"`
	// APIModel 是发给厂商的真实模型名;为空时回退 ModelID。
	APIModel string `yaml:"api_model" json:"api_model"`
	// Name 是模型展示名(供前端 / TUI 显示);为空时回退 ModelID。
	Name string `yaml:"name" json:"name"`

	// ContextWindow 模型上下文窗口(token);0 表示未知。
	ContextWindow int64 `yaml:"context_window" json:"context_window"`
	// DefaultMaxTokens 模型默认最大输出 token;0 表示未知。
	DefaultMaxTokens int64 `yaml:"default_max_tokens" json:"default_max_tokens"`
	// CanReason 表示模型支持推理 / 思考过程。
	CanReason bool `yaml:"can_reason" json:"can_reason"`
	// SupportsAttachments 表示模型支持图片等附件。
	SupportsAttachments bool `yaml:"supports_attachments" json:"supports_attachments"`

	// CostPer1MIn / CostPer1MOut 是每百万输入 / 输出 token 的价格(美元)。
	// 仅用于会话费用统计与 TUI 展示,不参与请求。
	CostPer1MIn  float64 `yaml:"cost_per_1m_in" json:"cost_per_1m_in"`
	CostPer1MOut float64 `yaml:"cost_per_1m_out" json:"cost_per_1m_out"`
	// CostPer1MInCached / CostPer1MOutCached 是命中缓存的输入 / 输出价格。
	CostPer1MInCached  float64 `yaml:"cost_per_1m_in_cached" json:"cost_per_1m_in_cached"`
	CostPer1MOutCached float64 `yaml:"cost_per_1m_out_cached" json:"cost_per_1m_out_cached"`

	// ReasoningEffort 推理强度(openai 系 low / medium / high),空表示不指定。
	ReasoningEffort string `yaml:"reasoning_effort" json:"reasoning_effort"`

	Extra map[string]string `yaml:"extra" json:"extra"`
}

ModelProviderConfig 描述一个「模型提供商」的连接配置(base_url / api_key / 类型等)。 与具体 Agent 无关,可被多个 Agent 共享。

Provider 是模型厂商类型(openai / anthropic / deepseek / gemini …), APIModel 是发给厂商的真实模型名(为空时回退 ModelID)。 ContextWindow / DefaultMaxTokens / CanReason / SupportsAttachments 是模型能力元信息, 供 Agent 类库替代内置模型表。其余可选参数(如 bearer_token、wire_api)仍放在 Extra 中。

func DefaultModelProviderConfig added in v0.2.0

func DefaultModelProviderConfig(vendorType, modelName string) ModelProviderConfig

DefaultModelProviderConfig 返回某个厂商/模型的内置默认配置(不含凭据)。

优先使用厂商预置的默认 base_url 与模型能力元信息;未命中时返回一个只带 Provider / ModelID / APIModel 的最小可用配置。

func MergeModelProviderConfig added in v0.2.0

func MergeModelProviderConfig(base, override ModelProviderConfig) ModelProviderConfig

MergeModelProviderConfig 把「用户显式填写的值」合并到「默认值」之上。

规则:字符串 / 数值 / 布尔字段为「零值」时保留默认值,否则以用户值为准。 这样 UI 只需提交 provider + api_model(或模型名)+ api_key,其余元信息自动补齐。

type ModelVendorOverride added in v0.2.0

type ModelVendorOverride map[string]ModelProviderConfig

ModelVendorOverride 补充单个厂商中某个模型的能力元信息。

预置模型表只覆盖「常用且稳定」的取值;未命中的模型会保留 PATCH 请求中的值 (或 ModelProviderConfig 的默认值),因此新增模型无需改代码即可使用。

type ModelVendorPreset added in v0.2.0

type ModelVendorPreset struct {
	// Type 是厂商类型,写入 ModelProviderConfig.Provider(决定 SDK 走哪条客户端)。
	Type string `json:"type"`
	// Name 是展示名(UI 下拉框使用)。
	Name string `json:"name"`
	// BaseURL 是厂商默认 API 基地址;留空表示由 SDK 决定(如 azure / bedrock)。
	BaseURL string `json:"base_url"`
	// APIModelPrefix 是该厂商常见的模型名前缀,用于自动补全 APIModel
	// (例如 deepseek 的 deepseek-v4-flash 直接就是真实模型名,前缀即模型名本身)。
	APIModelPrefix string `json:"api_model_prefix,omitempty"`
	// Models 是常见模型名(可为空,用户也可以自行填写)。
	Models []string `json:"models"`
}

ModelVendorPreset 描述一个模型厂商的预置信息。

func FindModelVendor added in v0.2.0

func FindModelVendor(vendorType string) (ModelVendorPreset, bool)

FindModelVendor 按厂商类型查找预置信息(大小写与首尾空白不敏感)。

func ModelVendors added in v0.2.0

func ModelVendors() []ModelVendorPreset

ModelVendors 返回内置厂商目录(按 UI 展示顺序)。

type ProxyConfig

type ProxyConfig struct {
	BraveAPI   string `yaml:"brave_api" json:"brave_api"`
	Container  string `yaml:"container" json:"container"`
	OnlyOffice string `yaml:"onlyoffice" json:"onlyoffice"`

	// HTTPProxy 是出站 http:// 请求使用的代理地址,例如 http://10.110.1.11:7890。
	// 为空表示不使用该协议的代理(不会回退到环境变量)。
	HTTPProxy string `yaml:"http_proxy" json:"http_proxy"`
	// HTTPSProxy 是出站 https:// 请求使用的代理地址,例如 http://10.110.1.11:7890。
	// 为空表示不使用该协议的代理(不会回退到环境变量)。
	HTTPSProxy string `yaml:"https_proxy" json:"https_proxy"`
	// NoProxy 是不走代理的主机列表(逗号分隔,支持域名 / IP / CIDR)。
	NoProxy string `yaml:"no_proxy" json:"no_proxy"`
}

ProxyConfig 保存内部服务地址与出站网络代理配置。

出站代理(http_proxy / https_proxy / no_proxy)是完全由配置驱动的通用能力: 任何需要访问外部网络的组件都可以通过 (*Config).NewHTTPClient / NewHTTPTransport 复用,而不只是 fetch 工具。未配置时一律直连,不读取环境变量。

func (*ProxyConfig) NewHTTPClient added in v0.2.0

func (p *ProxyConfig) NewHTTPClient(timeout time.Duration) *http.Client

NewHTTPClient 返回套用了代理配置的 http.Client。

func (*ProxyConfig) NewHTTPTransport added in v0.2.0

func (p *ProxyConfig) NewHTTPTransport() *http.Transport

NewHTTPTransport 返回套用了代理配置的 Transport。 可在需要自定义超时 / 连接池时作为任意出站 http.Client 的基础。

func (*ProxyConfig) ProxyFunc added in v0.2.0

func (p *ProxyConfig) ProxyFunc() func(*url.URL) (*url.URL, error)

ProxyFunc 返回按目标 URL 选择代理的函数。

行为完全由配置决定:http_proxy / https_proxy / no_proxy。 未配置(或 p 为 nil)时一律直连,不读取 http_proxy / https_proxy 等环境变量。

type RealtimeConfig

type RealtimeConfig struct {
	Transport             string `yaml:"transport" json:"transport"`
	MaxConnectionsPerUser int    `yaml:"max_connections_per_user" json:"max_connections_per_user"`
	AckTimeoutSeconds     int    `yaml:"ack_timeout_seconds" json:"ack_timeout_seconds"`
	AckMaxRetries         int    `yaml:"ack_max_retries" json:"ack_max_retries"`
}

type RouteConfig

type RouteConfig struct {
	// Registrys is the list of route registries to register at startup.
	// e.g. [gateway, traefik, k8s-ingress]. Each entry is normalized via
	// normalizeRouteRegistry.
	Registrys  []string               `yaml:"registrys"    json:"registrys"`
	AppsPrefix string                 `yaml:"apps_prefix"  json:"apps_prefix"`
	Traefik    *TraefikRouteConfig    `yaml:"traefik"      json:"traefik"`
	K8sIngress *K8sIngressRouteConfig `yaml:"k8s_ingress"  json:"k8s_ingress"`
}

type RuntimeProvisionConfig added in v0.2.4

type RuntimeProvisionConfig struct {
	// Enabled 为 true 时启用运行时预置的启动自检:每次启动尝试 Start
	// (已安装则拉起 daemon),未安装时不安装任何东西,等待 UI 安装向导。
	//
	// 与平台无关:Windows 上拉起 WSL 内的 dockerd,Linux 上拉起本机 dockerd。
	Enabled bool `yaml:"enabled" json:"enabled"`
	// Distro 导入到 WSL 的发行版名,默认 gobrave-ubuntu-docker。仅 Windows 生效。
	//
	// 若系统上已存在同名发行版(例如 Ubuntu),安装/启动时直接接管并启动
	// dockerd,无需 DownloadURL、也不会重新导入。
	Distro string `yaml:"distro" json:"distro"`
	// DownloadURL rootfs 包下载地址(安装向导使用)。仅 Windows 生效;
	// 接管已存在的同名发行版时可为空。
	DownloadURL string `yaml:"download_url" json:"download_url"`
	// Endpoint 是 daemon 地址,取值形如 tcp://localhost:2375 或
	// unix:///var/run/docker.sock。仅 Windows 生效:Linux 实现固定用本机 socket。
	Endpoint string `yaml:"endpoint" json:"endpoint"`
}

RuntimeProvisionConfig 描述 gobrave 自管运行时预置的下载与运行参数。

Enabled 与平台无关(Windows 上拉起自管 WSL 发行版内的 dockerd,Linux 上拉起 本机 dockerd);Distro / DownloadURL / Endpoint 仅 Windows 实现使用,Linux 实现 会忽略它们。

func DefaultRuntimeProvisionConfig added in v0.2.4

func DefaultRuntimeProvisionConfig() *RuntimeProvisionConfig

DefaultRuntimeProvisionConfig 返回预置段的默认配置。

func ResolveRuntimeProvisionConfig added in v0.2.4

func ResolveRuntimeProvisionConfig(cfg *Config) *RuntimeProvisionConfig

ResolveRuntimeProvisionConfig 返回容器运行时预置(provision)段配置; 任何一级缺失(cfg / container / docker / provision)都回退默认值。

该函数与平台无关:Windows 上参数用于自管 WSL 发行版,Linux 上 Distro / DownloadURL / Endpoint 被忽略,只用来构造本机 dockerd 的管理器。

type Section added in v0.1.4

type Section struct {
	// Key 是配置段在 config.yml 中的顶层键名,同时也是 API 中使用的段标识。
	Key string
	// Label 是用于错误提示的中文名称。
	Label string
	// Effective 返回当前生效的配置段值(用于表单回填与落盘)。
	Effective func(cfg *Config) any
	// Decode 解析并归一化请求体,返回待落盘的值;不会修改 cfg。
	Decode func(raw json.RawMessage) (any, error)
	// Apply 把已经成功落盘的值写入内存配置,使其立即生效。
	Apply func(cfg *Config, value any) error
}

Section 描述一个可以通过可视化界面编辑的配置段。

新增一个可编辑的配置段只需要在 sections 中注册一次, HTTP 层无需新增接口,前端只需新增一个 section 组件。

func FindSection added in v0.1.4

func FindSection(key string) (*Section, bool)

FindSection 按 key 查找已注册的配置段。

func RegisteredSections added in v0.1.4

func RegisteredSections() []*Section

RegisteredSections 返回所有已注册的可视化配置段。

type ServerConfig

type ServerConfig struct {
	Port int `yaml:"port"             json:"port"`
	// GRPCPort        int           `yaml:"grpc_port"        json:"grpc_port"`
	Host            string        `yaml:"host"             json:"host"`
	ShutdownTimeout time.Duration `yaml:"shutdown_timeout" json:"shutdown_timeout" default:"30s"`
	// Mode 是 Gin 运行模式:debug / release / test。
	// 留空时回退到 GIN_MODE 环境变量,最后回退到默认值(debug)。
	Mode string `yaml:"mode" json:"mode"`
}

ServerConfig 服务器配置

type StorageConfig

type StorageConfig struct {
	// ImageDir string `yaml:"image_dir" json:"image_dir"`
	BaseDir string `yaml:"base_dir" json:"base_dir"`
}

type TraefikRouteConfig

type TraefikRouteConfig struct {
	Provider      string `yaml:"provider"        json:"provider"`
	BaseURL       string `yaml:"base_url"        json:"base_url"`
	UpsertPath    string `yaml:"upsert_path"     json:"upsert_path"`
	DeletePath    string `yaml:"delete_path"     json:"delete_path"`
	AuthToken     string `yaml:"auth_token"      json:"auth_token"`
	TimeoutSecond int    `yaml:"timeout_second"  json:"timeout_second"`
	FilePath      string `yaml:"file_path"       json:"file_path"`
}

type UserConfig

type UserConfig struct {
	DisableRegistration bool   `yaml:"disable_registration" json:"disable_registration"`
	JWTSecret           string `yaml:"jwt_secret" json:"jwt_secret"`
}

Jump to

Keyboard shortcuts

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