CMDC 会话的类型化配置 struct。
通过 CMDC.Config.new/1 构建一次,在整个系统中传递。
所有字段有已知类型和合理默认值,不硬编码任何领域逻辑。
优先级(高者优先)
- 传给
new/1的会话覆盖 - Application env —
config :cmdc, key: value - 内置默认值
多 Provider 路由配置示例
config :cmdc,
default_model: "anthropic:claude-sonnet-4-5",
providers: [
{CMDC.Provider, [
api_key: "sk-ant-xxx",
base_url: "https://api.anthropic.com",
models: ~r/^claude-/
]},
{CMDC.Provider, [
api_key: "sk-openai-yyy",
models: :default
]}
]models 支持:正则(~r/^claude-/)、字符串列表(["gpt-4o"])、:default(兜底)。
Summary
Functions
数据目录的展开绝对路径。
返回当前平台的默认数据目录(~/.cmdc)。
从 default_model 字符串中提取纯模型 ID(去除 provider 前缀)。
确保数据目录树存在(目录不存在时自动创建)。
日志目录路径。
从 Application env + 可选覆盖构建 Config struct,返回 {:ok, t()} 或 {:error, ...}。
从 Application env + 可选覆盖构建 Config struct,校验失败时抛出异常。
根据模型名解析对应的 Provider 模块和 opts。
会话存储目录路径。
Types
Functions
数据目录的展开绝对路径。
@spec default_data_dir() :: String.t()
返回当前平台的默认数据目录(~/.cmdc)。
从 default_model 字符串中提取纯模型 ID(去除 provider 前缀)。
@spec ensure_dirs!(t()) :: :ok
确保数据目录树存在(目录不存在时自动创建)。
日志目录路径。
@spec new(keyword() | map()) :: {:ok, t()} | {:error, NimbleOptions.ValidationError.t()}
从 Application env + 可选覆盖构建 Config struct,返回 {:ok, t()} 或 {:error, ...}。
从 Application env + 可选覆盖构建 Config struct,校验失败时抛出异常。
示例
iex> CMDC.Config.new!(data_dir: "/tmp/cmdc")
%CMDC.Config{data_dir: "/tmp/cmdc", ...}
@spec resolve_provider(t(), String.t()) :: provider_entry()
根据模型名解析对应的 Provider 模块和 opts。
路由规则:
- 若配置了
providers,按models规则查找第一个匹配项 - 若无匹配,返回
:default标记的兜底接入点 - 均未匹配,回退到
provider+provider_opts单 Provider 配置
会话存储目录路径。