models 配置改为每模型独立 url/api_key:移除全局 upstream_url/api_key,config.js 校验每模型必填 url(选填 api_key,去尾斜杠),llm.callModel 按 model_id 解析各自上游与鉴权头,server 启动日志逐模型打印 url;example/test 配置与 README/DEPLOY 同步(本地 config.yml 已改为同值独立结构,gitignore 不入库)

This commit is contained in:
2026-08-31 16:29:45 +08:00
parent ab18e17aa7
commit b926e6e48a
8 changed files with 29 additions and 21 deletions
+6 -6
View File
@@ -5,8 +5,6 @@ const YAML = require('yaml');
const DEFAULTS = {
port: 8080,
upstream_url: '',
api_key: '',
workspace_root: './data/tasks',
db_path: '', // 默认为 workspace_root/.agent.db
terminal: { default_timeout_ms: 30000, max_output_chars: 10000 },
@@ -45,14 +43,16 @@ function loadConfig(configPath) {
const cfg = deepMerge(DEFAULTS, raw);
if (!Array.isArray(cfg.models) || cfg.models.length === 0) {
throw new Error('配置缺少 models:至少需要一个模型 {id, display_name}');
throw new Error('配置缺少 models:至少需要一个模型 {id, url, display_name}')
}
// 每个模型独立配置上游:url 必填(OpenAI 兼容 /v1 地址),api_key 选填(留空则不带鉴权头)
for (const m of cfg.models) {
if (!m.id) throw new Error('models 中每项必须有 id');
if (!m || !m.id) throw new Error('models 中每项必须有 id');
if (!m.url) throw new Error('models.' + m.id + ' 缺少 url(每个模型独立配置上游 /v1 地址)');
if (!m.display_name) m.display_name = m.id;
m.url = String(m.url).replace(/\/+$/, '');
m.api_key = m.api_key || '';
}
if (!cfg.upstream_url) throw new Error('配置缺少 upstream_url(cli-proxy-api 的 /v1 地址)');
cfg.upstream_url = cfg.upstream_url.replace(/\/+$/, '');
cfg.workspace_root = path.resolve(cfg.workspace_root);
if (!cfg.db_path) cfg.db_path = path.join(cfg.workspace_root, '.agent.db');