设置页配置预设:平台与同栈 MCP 的固定契约收进 presets.json
- 新增 app/server/presets.json:3 个模型平台(url/type/model_defaults)与 4 个内置 MCP(url/mode/header 字段,含 placeholder/hint),不含任何密钥 - routes/config.js 新增 GET /api/config/presets(随 /api/config 挂载,仅管理员) - 启动时校验一次:key/url/type 必填、key 不重复、mode 枚举、fields[].header 必填; 失败只 warn 并降级为空预设,不影响启动
This commit is contained in:
@@ -39,6 +39,7 @@ AGENT_CONFIG=./config.yml node server/server.js
|
||||
|---|---|
|
||||
| `server/server.js` | 装配、路由挂载、`/api/models`、`/api/health`、prompt dump、优雅退出 |
|
||||
| `server/config.js` | YAML 加载/校验/默认值;`platforms` 展开成 `cfg.models`;配置文本改写(设置页) |
|
||||
| `server/presets.json` | 平台与同栈 MCP 的固定契约(url / type / header 名),设置页新增时的模板来源;改服务地址改这里 |
|
||||
| `server/db.js` | 建表、索引、幂等迁移;纯 SQL 数据层,不放业务 |
|
||||
| `server/engine.js` | **核心**:会话状态机、模型池调度、Agent 主循环、压缩、标题、日记收口、消息增删 |
|
||||
| `server/llm.js` | 消息组装、system prompt 拼接、上游流式调用、占位裁剪、多模态块编解码 |
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"platforms": [
|
||||
{
|
||||
"key": "bigmodel",
|
||||
"label": "智谱 BigModel",
|
||||
"url": "https://open.bigmodel.cn/api/paas/v4",
|
||||
"type": "bigmodel",
|
||||
"model_hint": "glm-5.3-flash",
|
||||
"model_defaults": {
|
||||
"vision": true,
|
||||
"extra_params": { "reasoning_effort": "low", "tool_stream": true },
|
||||
"thinking_params": { "reasoning_effort": "max" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "deepseek",
|
||||
"label": "DeepSeek",
|
||||
"url": "https://api.deepseek.com",
|
||||
"type": "deepseek",
|
||||
"model_hint": "deepseek-flash",
|
||||
"model_defaults": {
|
||||
"vision": true,
|
||||
"extra_params": { "thinking": { "type": "disabled" } },
|
||||
"thinking_params": { "thinking": { "type": "enabled" }, "reasoning_effort": "max" },
|
||||
"reasoning_ack_field": "reasoning_content"
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "qwen",
|
||||
"label": "通义千问",
|
||||
"url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||||
"type": "qwen",
|
||||
"model_hint": "qwen3.8-flash",
|
||||
"model_defaults": {
|
||||
"vision": true,
|
||||
"extra_params": { "enable_thinking": false },
|
||||
"thinking_params": { "enable_thinking": true, "reasoning_effort": "xhigh" }
|
||||
}
|
||||
}
|
||||
],
|
||||
"mcp": [
|
||||
{
|
||||
"key": "web_search",
|
||||
"label": "网页搜索",
|
||||
"desc": "栈内搜索服务,无需密钥",
|
||||
"url": "http://mcp_web_search:3000/",
|
||||
"mode": "advertise",
|
||||
"fields": []
|
||||
},
|
||||
{
|
||||
"key": "image_task",
|
||||
"label": "图片生成",
|
||||
"desc": "文生图 / 图生图,走任意 OpenAI 兼容的 /images/generations 与 /images/edits",
|
||||
"url": "http://mcp_image_task:3000/mcp",
|
||||
"mode": "skill",
|
||||
"fields": [
|
||||
{
|
||||
"header": "Authorization",
|
||||
"label": "API Key",
|
||||
"secret": true,
|
||||
"prefix": "Bearer ",
|
||||
"required": true,
|
||||
"placeholder": "上游的 API Key"
|
||||
},
|
||||
{
|
||||
"header": "X-Image-Task-Base-Url",
|
||||
"label": "上游地址",
|
||||
"required": true,
|
||||
"placeholder": "https://<host>/v1",
|
||||
"hint": "填到 /v1 即可,文生图自动补 /images/generations,图生图自动补 /images/edits"
|
||||
},
|
||||
{
|
||||
"header": "X-Image-Task-Model",
|
||||
"label": "模型",
|
||||
"required": true,
|
||||
"placeholder": "上游的模型 id"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "video_task",
|
||||
"label": "视频生成",
|
||||
"desc": "智谱 BigModel 异步视频接口",
|
||||
"url": "http://mcp_video_task:3000/mcp",
|
||||
"mode": "skill",
|
||||
"fields": [
|
||||
{
|
||||
"header": "Authorization",
|
||||
"label": "API Key",
|
||||
"secret": true,
|
||||
"prefix": "Bearer ",
|
||||
"required": true,
|
||||
"placeholder": "智谱 API Key"
|
||||
},
|
||||
{
|
||||
"header": "X-Video-Task-Model",
|
||||
"label": "模型",
|
||||
"default": "cogvideox-flash",
|
||||
"hint": "留空 = cogvideox-flash"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "asr",
|
||||
"label": "语音识别",
|
||||
"desc": "输入框「按住说话」与模型的 transcribe_audio 共用",
|
||||
"url": "http://mcp_asr:3000/mcp",
|
||||
"mode": "skill",
|
||||
"fields": [
|
||||
{
|
||||
"header": "Authorization",
|
||||
"label": "API Key",
|
||||
"secret": true,
|
||||
"prefix": "Bearer ",
|
||||
"placeholder": "自建免鉴权服务可留空"
|
||||
},
|
||||
{
|
||||
"header": "X-ASR-Base-Url",
|
||||
"label": "上游地址",
|
||||
"required": true,
|
||||
"placeholder": "https://<host>/v1",
|
||||
"hint": "任意 OpenAI 兼容的 /audio/transcriptions"
|
||||
},
|
||||
{
|
||||
"header": "X-ASR-Model",
|
||||
"label": "模型",
|
||||
"required": true,
|
||||
"default": "whisper-1",
|
||||
"placeholder": "whisper-1"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -9,6 +9,50 @@ const log = require('../log');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 平台 / MCP 预设:设置页「新增平台」「添加内置 MCP」的模板来源(纯静态,无密钥)。
|
||||
// 文件写坏时降级为空预设:通用表单仍可用,不影响其它功能。
|
||||
const MCP_MODES = ['advertise', 'skill', 'disable'];
|
||||
function checkPresetList(list, kind, bad) {
|
||||
const seen = new Set();
|
||||
(list || []).forEach((x, i) => {
|
||||
const at = kind + '[' + i + ']';
|
||||
if (!x || typeof x !== 'object') { bad.push(at + ' 必须是对象'); return; }
|
||||
if (!x.key || !x.url) { bad.push(at + ' 缺 key/url'); return; }
|
||||
if (seen.has(x.key)) { bad.push(at + ' key 重复:' + x.key); return; }
|
||||
seen.add(x.key);
|
||||
if (kind === 'platforms') {
|
||||
if (!x.type) bad.push(at + ' 缺 type');
|
||||
if (x.model_defaults != null && typeof x.model_defaults !== 'object') {
|
||||
bad.push(at + '.model_defaults 必须是对象');
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (x.mode != null && MCP_MODES.indexOf(x.mode) < 0) {
|
||||
bad.push(at + '.mode 只能是 ' + MCP_MODES.join(' / '));
|
||||
}
|
||||
if (x.fields != null && !Array.isArray(x.fields)) { bad.push(at + '.fields 必须是数组'); return; }
|
||||
(x.fields || []).forEach((f, fi) => {
|
||||
if (!f || !f.header) bad.push(at + '.fields[' + fi + '] 缺 header');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function loadPresets() {
|
||||
const p = require('../presets.json') || {};
|
||||
const bad = [];
|
||||
checkPresetList(p.platforms, 'platforms', bad);
|
||||
checkPresetList(p.mcp, 'mcp', bad);
|
||||
if (bad.length) throw new Error(bad.join(';'));
|
||||
return { platforms: p.platforms || [], mcp: p.mcp || [] };
|
||||
}
|
||||
|
||||
let PRESETS = { platforms: [], mcp: [] };
|
||||
try {
|
||||
PRESETS = loadPresets();
|
||||
} catch (e) {
|
||||
log.warn('config', 'presets.json 无效,设置页将没有预设:' + String((e && e.message) || e));
|
||||
}
|
||||
|
||||
function sendErr(res, err) {
|
||||
const code = err && err.status_code || 500;
|
||||
res.status(code).json({ error: String(err && err.message || err) });
|
||||
@@ -215,6 +259,9 @@ router.get('/', wrap((req, res) => {
|
||||
res.json({ config_path: cfg.config_path || '', exists: text !== null, text: shown, effective: eff, balance_types: balance.types() });
|
||||
}));
|
||||
|
||||
// 预设模板(前端新增平台 / 添加内置 MCP 用)
|
||||
router.get('/presets', wrap((req, res) => { res.json(PRESETS); }));
|
||||
|
||||
// 干跑校验(编辑器保存前预检):body { text }
|
||||
// 还原脱敏后的 api_key/password 再校验,避免 diff 误报变更。
|
||||
router.post('/validate', wrap((req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user