examples/README.md
本目录包含 CCR 预设配置的示例文件。
simple-preset-example.json - 简单示例适合初学者,展示了基本的动态配置功能:
使用场景:快速配置单个 Provider
preset-manifest-example.json - 完整示例展示了所有高级功能:
使用场景:生产环境的完整配置
dynamic-preset-example.json - 多Provider示例展示了如何在多个 Provider 之间切换:
# 创建预设目录
mkdir -p ~/.claude-code-router/presets/my-preset
# 复制示例文件
cp simple-preset-example.json ~/.claude-code-router/presets/my-preset/manifest.json
# 应用预设
ccr my-preset
ccr preset install ./simple-preset-example.json --name my-preset
| 类型 | 说明 | 适用场景 |
|---|---|---|
password | 密码输入 | API Key、密钥等敏感信息 |
input | 单行文本 | Base URL、端点地址 |
number | 数字输入 | 超时时间、Token数量 |
select | 单选 | Provider选择、模型选择 |
multiselect | 多选 | 功能开关、标签选择 |
confirm | 确认框 | 是否启用某功能 |
editor | 多行文本 | 自定义配置、脚本 |
| 运算符 | 说明 | 示例 |
|---|---|---|
eq | 等于 | 当 provider == "openai" 时显示 |
ne | 不等于 | 当 mode != "simple" 时显示 |
exists | 字段存在 | 当 apiKey 有值时显示 |
gt/lt | 大于/小于 | 当 timeout > 30 时显示 |
"options": {
"type": "static",
"options": [
{"label": "选项1", "value": "value1"},
{"label": "选项2", "value": "value2"}
]
}
"options": {
"type": "providers"
}
自动从 Providers 数组中提取 name 作为选项。
"options": {
"type": "models",
"providerField": "{{selectedProvider}}"
}
根据用户选择的 Provider,动态显示该 Provider 的 models。
使用 {{变量名}} 语法在 template 中引用用户输入:
"template": {
"Providers": [
{
"name": "{{providerName}}",
"api_key": "{{apiKey}}"
}
]
}
对于复杂的配置需求,使用 configMappings 精确控制值的位置:
"configMappings": [
{
"target": "Providers[0].api_key",
"value": "{{apiKey}}"
},
{
"target": "PROXY_URL",
"value": "{{proxyUrl}}",
"when": {
"field": "useProxy",
"operator": "eq",
"value": true
}
}
]
defaultValuelabel 和 promptwhen 避免显示无关选项validator 或 min/max 确保输入有效proxy*)