From 61245b1c656c34bea1be0f6260bef08a8e96068a Mon Sep 17 00:00:00 2001 From: kicer Date: Thu, 22 Oct 2026 20:55:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BC=96=E8=BE=91=E5=B7=B2?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=9A=84=E7=94=A8=E6=88=B7=E6=B6=88=E6=81=AF?= =?UTF-8?q?=EF=BC=88=E8=A6=86=E7=9B=96=E5=BC=8F=E9=87=8D=E5=8F=91=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/engine.js | 20 ++++++++ app/server/public/css/style.css | 18 ++++++- app/server/public/index.html | 17 ++++--- app/server/public/js/chat.js | 15 ++++-- app/server/public/js/core.js | 2 + app/server/public/js/sessions.js | 3 ++ app/server/public/js/stream.js | 82 ++++++++++++++++++++++++++++++-- app/server/routes/messages.js | 11 +++++ 8 files changed, 154 insertions(+), 14 deletions(-) diff --git a/app/server/engine.js b/app/server/engine.js index 97befd8..c1b0502 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -1465,6 +1465,25 @@ function deleteMessage(sessionId, messageId) { return { ok: true, id: messageId, removed: removed + 1 }; } +// 覆盖式编辑用户消息:删掉该条及其后的全部历史(含 tool 回执/摘要),再以新内容重开一轮。 +// 编辑点是 user 行,前缀必然停在 assistant,不会留下无配对的 tool_call。 +// 运行中不支持:runLoop 每轮重载历史,中途截断会让当前回合的 tool 回执缺失。 +function editUserMessage(sessionId, messageId, content, opts) { + const session = getSession(sessionId); + if (!session) throw Object.assign(new Error('会话不存在'), { status_code: 404 }); + const row = db.prepare('SELECT id, role FROM messages WHERE id = ? AND session_id = ?').get(messageId, sessionId); + if (!row) throw Object.assign(new Error('消息不存在'), { status_code: 404 }); + if (row.role !== 'user') throw Object.assign(new Error('只能编辑用户消息'), { status_code: 400 }); + const run = runs.get(sessionId); + if (run && run.looping) throw Object.assign(new Error('任务正在执行,请先终止再编辑'), { status_code: 409 }); + // 先确保能开跑:无可用模型时抛 503,避免删完历史却发不出去 + ensureBinding(session); + const removed = db.prepare('DELETE FROM messages WHERE session_id = ? AND id >= ?').run(sessionId, messageId).changes; + const r = postUserMessage(sessionId, content, opts); + log.info('msg', sessionId + ' 编辑消息 ' + messageId + ',丢弃其后 ' + Math.max(0, removed - 1) + ' 条历史'); + return Object.assign({ removed: removed }, r); +} + // 删工具回执(任务执行卡片):同步把对应 tool_call 从父 assistant 的 tool_calls 里摘掉, // 避免留下「有调用无结果」被严格上游拒收。父回合若是纯工具调用轮(无文本)且已无 // 其余调用,则整行一起删(空气泡没有意义);有文本则保留为普通文本回复。 @@ -1511,6 +1530,7 @@ module.exports = { clearSessionMessages, summarizeContext, deleteMessage, + editUserMessage, getSession, getRun, taskDirOf, diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index bf6e8d9..598e4d3 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -280,7 +280,7 @@ main { flex: 1; min-height: 0; display: flex; flex-direction: column; } .tool-card .tool-time .act-del:hover { color: #c0392b; } /* ================= 底部输入区 ================= */ -footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--page); } +footer { position: relative; flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--page); } .attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; } .attach-chip { display: inline-flex; align-items: center; gap: 6px; @@ -792,8 +792,10 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0 } /* ================= 回到底部浮动按钮(同步 index 右下角导航浮动图标) ================= */ +/* 停靠在输入区上方:包含块是 footer,bottom:100% = footer 顶边, + 输入框长高/编辑条出现时随 footer 一起上移,不再用固定值 140px 遮挡输入区。 */ .scroll-bottom-btn { - position: absolute; right: 14px; bottom: 140px; + position: absolute; right: 14px; bottom: calc(100% + 6px); margin: 0; width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; @@ -1458,3 +1460,15 @@ body.pv-resizing #pv-pane iframe { pointer-events: none; } background: var(--active-soft); color: var(--active); } @keyframes drop-overlay-in { from { opacity: 0; } to { opacity: 1; } } + +/* ================= 编辑已发送消息提示条 ================= */ +/* 覆盖式重发:输入框内部的浅蓝提示条(嵌在 .input-shell 顶端,间距由 shell 的 gap 提供)。 */ +.edit-bar { + display: flex; align-items: center; gap: 8px; + padding: 6px 6px 6px 12px; + border-radius: 12px; background: var(--active-soft); + color: var(--active); font-size: 12.5px; +} +.edit-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.edit-bar button { flex: none; padding: 2px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--active); } +.edit-bar button:active { background: rgba(57, 100, 254, 0.12); } diff --git a/app/server/public/index.html b/app/server/public/index.html index 5f7c4f4..a13c2c5 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -158,6 +158,11 @@ - - -