From 103308ef15ef5a6da9294382a7d6d216774cfc13 Mon Sep 17 00:00:00 2001 From: kicer Date: Wed, 2 Sep 2026 12:20:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=8F=AF=E6=89=8B=E5=8A=A8=E9=80=89=E6=8B=A9=E7=A9=BA=E9=97=B2?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/engine.js | 19 +++++++++++++++++++ app/server/public/index.html | 23 ++++++++++++++++++----- app/server/public/js/tasks.js | 32 ++++++++++++++++++++++++++++++++ app/server/routes/sessions.js | 4 ++++ 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/app/server/engine.js b/app/server/engine.js index ee9eb6a..c280567 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -219,6 +219,24 @@ function releaseModel(sessionId) { db.prepare('UPDATE sessions SET model_id = NULL, updated_at = ? WHERE id = ?').run(now(), sessionId); } +// 手动为已结版/已终止的会话指定模型:选定的模型必须空闲,绑定后状态直接 active, +// 下一条消息不再排队;若有未回应消息则立刻开跑。绑而不用同样受闲置租约兑底(sweepHeld)。 +function bindToSession(sessionId, modelId) { + const s = getSession(sessionId); + if (!s) throw Object.assign(new Error('会话不存在'), { status_code: 404 }); + if (s.status !== 'completed' && s.status !== 'cancelled') { + throw Object.assign(new Error('仅已完成/已终止的会话可手动选择模型'), { status_code: 409 }); + } + const model = db.prepare('SELECT * FROM model_pool WHERE id = ? AND is_busy = 0').get(String(modelId || '')); + if (!model) throw Object.assign(new Error('模型不存在或正被占用'), { status_code: 409 }); + touch(sessionId, { cancelled_at: null, completed_at: null, held_at: null }); + bindModel(s, model); + emitStatus(sessionId); + log.info('[model] ' + sessionId + ' 手动绑定模型 ' + model.id); + if (hasPendingUser(sessionId)) runLoop(sessionId); + return { ok: true, model_id: model.id }; +} + // 是否还有待回应的新用户消息(最后一条非 tool 消息是 user)。 // 会话上下文消息(role=user 但带 SESSION_CONTEXT_NAME 标记)不算待回应消息。 function hasPendingUser(sessionId) { @@ -675,6 +693,7 @@ module.exports = { recordModelUsage, modelUsageStats, dispatchQueued, + bindToSession, TOOL_DEFINITIONS, START_EXECUTION_MESSAGE, }; diff --git a/app/server/public/index.html b/app/server/public/index.html index dd75582..675ee1e 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -155,6 +155,7 @@
-- +
@@ -203,6 +204,18 @@ + + +