会话级profile绑定:sessions表加profile列(PRAGMA迁移,旧行空串=随模型);resolveProfileName优先级插层——每消息参数>会话绑定>模型默认>全量;bind路由双语义:profile=模式绑定任意状态即切(''解绑/default归一,存在性400同messages路由),model_id=原手动占模型路径零改动
This commit is contained in:
@@ -19,6 +19,7 @@ function initDb(dbPath) {
|
||||
last_model_id TEXT,
|
||||
assistant_type TEXT DEFAULT 'secretary',
|
||||
user TEXT DEFAULT '',
|
||||
profile TEXT DEFAULT '',
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
completed_at INTEGER,
|
||||
@@ -142,6 +143,11 @@ function initDb(dbPath) {
|
||||
if (!cols.some(c => c.name === 'user')) {
|
||||
db.exec("ALTER TABLE sessions ADD COLUMN user TEXT DEFAULT ''");
|
||||
}
|
||||
// 迁移:profile 记会话绑定的 prompt+tools 组合名(config.yml 顶层 model_profiles;''=随模型配置)。
|
||||
// 选取优先级见 engine.resolveProfileName,切换入口见 routes/sessions.js bind 路由(弹窗「模式」区)。
|
||||
if (!cols.some(c => c.name === 'profile')) {
|
||||
db.exec("ALTER TABLE sessions ADD COLUMN profile TEXT DEFAULT ''");
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
+18
-3
@@ -241,12 +241,14 @@ function registerProfilePrompts() {
|
||||
setProfilePrompts(map);
|
||||
}
|
||||
|
||||
// 本轮生效的 profile 名:前端显式选择(run.profile,与 deepThink 同约定:
|
||||
// 每轮迭代取最新值,回合中途切换下一个请求即生效)> 模型配置默认(cfg.models[].profile)> ''(默认全量)。
|
||||
// 保留值 'default' = 前端显式切回全量(覆盖配了 profile 的模型的默认组合)。
|
||||
// 本轮生效的 profile 名:每消息参数(run.profile,与 deepThink 同约定:每轮迭代取最新值)
|
||||
// > 会话绑定(sessions.profile,弹窗「模式」区写入,跨回合/刷新持久)> 模型配置默认(cfg.models[].profile)
|
||||
// > ''(默认全量)。保留值 'default' 归一为 ''(显式摆脱模型默认组合;无 profile 模型下二者等效)。
|
||||
function resolveProfileName(session, run) {
|
||||
const manual = run && String(run.profile || '').trim();
|
||||
if (manual) return manual === 'default' ? '' : manual;
|
||||
const bound = String((session && session.profile) || '').trim();
|
||||
if (bound) return bound === 'default' ? '' : bound;
|
||||
const m = session.model_id && (cfg.models || []).find(x => x.id === session.model_id);
|
||||
return m && m.profile ? String(m.profile) : '';
|
||||
}
|
||||
@@ -328,6 +330,18 @@ function bindToSession(sessionId, modelId) {
|
||||
return { ok: true, model_id: want };
|
||||
}
|
||||
|
||||
// 会话级 profile 绑定(bind 弹窗「模式」区):''=解绑回随模型配置;保留值 'default' 归一为 ''。
|
||||
// 不设会话状态门槛——模式是每轮选择,切换下一轮迭代/下条消息即生效;不碰模型槽位占用。
|
||||
// 名字存在性由路由校验(hasModelProfile,与 messages 路由同款 400),这里只管落库。
|
||||
function setSessionProfile(sessionId, profile) {
|
||||
const s = getSession(sessionId);
|
||||
if (!s) throw Object.assign(new Error('会话不存在'), { status_code: 404 });
|
||||
const name = profile === 'default' ? '' : String(profile || '').trim();
|
||||
db.prepare('UPDATE sessions SET profile = ?, updated_at = ? WHERE id = ?').run(name, now(), sessionId);
|
||||
log.info('model', sessionId + ' 会话模式绑定 → ' + (name || '默认(随模型配置)'));
|
||||
return name;
|
||||
}
|
||||
|
||||
// 是否还有待回应的新用户消息(最后一条非 tool 消息是 user)。
|
||||
function hasPendingUser(sessionId) {
|
||||
const rows = loadHistory(sessionId);
|
||||
@@ -1235,6 +1249,7 @@ module.exports = {
|
||||
modelUsageStats,
|
||||
dispatchQueued,
|
||||
bindToSession,
|
||||
setSessionProfile,
|
||||
TOOL_DEFINITIONS,
|
||||
effectiveTools,
|
||||
hasModelProfile,
|
||||
|
||||
@@ -226,8 +226,26 @@ router.get('/:id', wrap((req, res) => {
|
||||
// 按需加载单条消息的完整内容(用于 tool 消息的懒加载)
|
||||
router.get('/:id/messages/:mid', wrap(getMessage));
|
||||
|
||||
// 一路由双语义(弹窗内模型/模式两套选择共用):model_id=手动占模型(仅已结版/已终止,见 bindToSession);
|
||||
// profile=会话模式绑定(任意状态,''解绑,'default' 归一为 '')。各传各的,同传先模式后模型。
|
||||
router.post('/:id/bind', wrap((req, res) => {
|
||||
res.json(engine.bindToSession(req.params.id, req.body && req.body.model_id));
|
||||
const body = req.body || {};
|
||||
let prof;
|
||||
if (body.profile !== undefined && body.profile !== null) {
|
||||
const p = String(body.profile).trim();
|
||||
if (p && p !== 'default' && !engine.hasModelProfile(p)) {
|
||||
throw Object.assign(new Error('profile 不存在:' + p + '(可选:' + Object.keys(engine.getConfig().model_profiles || {}).join(', ') + ')'), { status_code: 400 });
|
||||
}
|
||||
prof = engine.setSessionProfile(req.params.id, p);
|
||||
}
|
||||
const mid = body.model_id;
|
||||
if (mid === undefined || mid === null || String(mid).trim() === '') {
|
||||
if (prof === undefined) throw Object.assign(new Error('model_id / profile 至少传一项'), { status_code: 400 });
|
||||
return res.json({ ok: true, profile: prof });
|
||||
}
|
||||
const r = engine.bindToSession(req.params.id, mid);
|
||||
if (prof !== undefined) r.profile = prof;
|
||||
res.json(r);
|
||||
}));
|
||||
|
||||
router.patch('/:id', wrap((req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user