运行中发送改为待发送条幅:排队 / 干预 / 立即发送
- 运行中点发送不再立即插话,改为进服务端队列(engine.pendings,内存态), 输入框上方一行条幅:默认本轮结束后发出,队首可「干预」(当前工具跑完就插话) 或「立即发送」(终止本轮工具调用并立刻发)。队列在服务端,关页面/重连不丢。 - 新增 closeToolBatch():给未闭合批次里缺回执的 tool_call 补合成回执, 取消/干预/finalize 兜底三处调用;顺带修掉「中途停止后库里留孤儿 tool_calls、 下一轮请求被上游拒收」的存量 bug。 - llm.buildMessages 加读侧配对过滤(pairedByAssistant / emittedCallIds): 只下发本批确有回执的调用,孤儿回执也不下发,兜历史脏数据,DB/UI 不动。 - HTTP:POST /messages 支持 delivery:'queue';新增 POST/DELETE /pending/:qid; 会话详情与 status 事件带 pending。 - 前端:条幅渲染与动作、pending_added/pending_removed/user_message 事件、 硬中断后工具卡标「已取消」;发送始终交服务端判定,避免过期状态把 user 行 插进工具批次中间。 - 文档:app/AGENTS.md 补生命周期、SSE 事件清单与待投递队列语义。
This commit is contained in:
@@ -16,17 +16,46 @@ function wrap(fn) {
|
||||
}
|
||||
|
||||
// 附件上传只写任务目录文件(见 routes/files.js),消息正文原样入库,不再拼接任何通知行。
|
||||
// delivery:
|
||||
// live(默认,兼容旧调用方/微信)→ 立即入库;回合在跑时下一轮迭代自动带上
|
||||
// queue → 回合在跑时进待投递队列(不落库),回合收尾后自动发出;不在跑则等价于 live
|
||||
// 「干预 / 立即发送」不走这里,而是对已在队列里的条目做升级(POST /pending/:qid)。
|
||||
router.post('/:id/messages', wrap((req, res) => {
|
||||
const content = String((req.body && req.body.content) || '').trim();
|
||||
if (!content) return res.status(400).json({ error: 'content 不能为空' });
|
||||
// deepThink:是否启用模型该「深度思考」参数(thinking_params 合并进上游请求体)
|
||||
const deepThink = !!(req.body && req.body.deepThink);
|
||||
const delivery = String((req.body && req.body.delivery) || 'live');
|
||||
if (delivery === 'queue') {
|
||||
const r = engine.enqueueMessage(req.params.id, content, { deepThink });
|
||||
log.info('msg', (req.user || '-') + ' ' + req.params.id + ' 用户消息(' +
|
||||
(r.queued ? '排队 ' + r.pending_id : r.delivered || '?') + '):' +
|
||||
content.slice(0, 60).replace(/\s+/g, ' '));
|
||||
return res.json(r);
|
||||
}
|
||||
const r = engine.postUserMessage(req.params.id, content, { deepThink });
|
||||
log.info('msg', (req.user || '-') + ' ' + req.params.id + ' 用户消息(' + (r && r.delivered || '?') + '):' +
|
||||
content.slice(0, 60).replace(/\s+/g, ' '));
|
||||
res.json(r);
|
||||
}));
|
||||
|
||||
// 待投递队列:升级队首(干预 / 立即发送)。
|
||||
// 干预 = 等当前工具跑完/本条回复落库后插话;立即发送 = 杀进程 + abort 流,本回合收尾后立刻发。
|
||||
router.post('/:id/pending/:qid', wrap((req, res) => {
|
||||
const action = String((req.body && req.body.action) || 'interject');
|
||||
if (action !== 'interject' && action !== 'now') {
|
||||
return res.status(400).json({ error: 'action 只能是 interject 或 now' });
|
||||
}
|
||||
const r = engine.promotePending(req.params.id, req.params.qid, action);
|
||||
log.info('msg', (req.user || '-') + ' ' + req.params.id + ' 待投递消息 ' + req.params.qid + ' → ' + action);
|
||||
res.json(r);
|
||||
}));
|
||||
|
||||
// 取消一条待投递消息(条幅上的 ×)。
|
||||
router.delete('/:id/pending/:qid', wrap((req, res) => {
|
||||
res.json(engine.cancelPending(req.params.id, req.params.qid));
|
||||
}));
|
||||
|
||||
|
||||
// 覆盖式编辑:删除该条及其后的历史,再以新内容重开一轮(运行中 409)。
|
||||
router.post('/:id/messages/:mid/edit', wrap((req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user