4 Commits
Author SHA1 Message Date
kicer 0433e61941 chore(ui): 清掉操作成功的冗余提示,统一各处垃圾桶图标
这些 toast 说的东西界面已经摆在眼前:撤回后的文字就在输入框里、复制按钮自己变勾、
删除完列表自己少一行、深度思考按钮自己变色。弹出来反而挡住会话内容,统一去掉。
保留全部失败提示,以及带额外信息的(终止时清了几条队列、清空后文件仍保留)。

垃圾桶在前端有四份画法(盖沿 polyline、桶身一体、线条 path 三种混写),统一成
盖沿+提手+桶身+两道竖线这一套;尺寸与描边跟随各自上下文(20px/2、13px/1.8、14px/1.9),
只求形状一致,不改各处的视觉粗细。
2026-11-13 15:12:05 +08:00
kicer 7b1ef9a479 feat(ui): 排队消息可撤回输入框重新编辑
运行中发出的消息排在待发送条幅里,原来只有一个 ×:点掉就从服务端队列删了,正文跟着蒸发。
现在拆成两支:笔(撤回编辑)删队列项并把正文回填输入框、光标停在撤回段末尾;垃圾桶直接丢弃。
两者都走 DELETE /pending/:qid,区别只在要不要把正文带回来。撤回文本必须在请求前取,
DELETE 的响应里这条已经没了。

回填拼在已有草稿之前,与发送失败的兜底同序;之后 autosize / updateSendBtn 同步,
focus 带 preventScroll,免得浏览器为了露出输入框把页面滚一下。

条幅占位会改 chat-view 的 clientHeight,浏览器不会替你补滚动,最后一条消息因此被裁在视口外。
renderSendQueue 改成改动前先记 isNearBottom,贴底就在本帧与下一帧各补一次 scrollBottom;
条幅自己限高 100px、超出内部滚动,sq-item 加 flex:none 防止被压扁。

顺带清掉复制与删除消息两处成功提示(按钮变勾、消息已消失,都不需要再说一遍)。
2026-11-13 15:12:01 +08:00
kicer 793be29331 feat(ui): 上下文注入行改成折叠卡片,摘要卡片统一同一套视觉
画像快照、渠道说明、开场记忆这些「只发给模型看」的注入内容,之前要么完全
不可见(画像快照存在 sessions 表里,不在 messages),要么假装成用户发言——
channel_note / memory_note 会被 userMsgHtml 渲染成一条用户气泡,打开微信
会话时那两段 # [CTX] 大文本就挂在你名下。

现在统一成可折叠卡片:画像快照是每轮请求拼在最前的上下文,历史又是懒加载
的,所以等翻到最早(has_more=false)再补到流顶,不会插在首屏那几条前面被
后续分页顶到中间;渠道/记忆按 type 直接渲染成卡片。内容都走 markdown,和
摘要卡片一致。

压缩摘要卡片与它们共用一套:淡蓝底、蓝边蓝字、三角箭头、虚线分隔,折叠与
展开同底色,去掉渐变/阴影/数据库图标,默认全部收起(流式收尾也不再自动
展开),标题旁的「后续对话以此为起点」一并去掉。摘要卡片补 width:100%,
否则在 align-items:flex-start 的 .msg 里折叠后只剩标题那点宽。

顺带:errAck(工具参数非法被整轮移除)在气泡上方标一行,原来只显示模型
当时的内容,看不出这一轮其实没进上下文。
2026-11-13 14:52:24 +08:00
kicer b9fad470ee feat(engine): 重启后自动续跑被中断的回合
进程被 stop/重启打断时,回合状态只在内存 runs 里,重启即丢;init 又把
active 一律归位 held,用户得重新喊一声才动。

现在归位前先挑出「回合没走完」的:最后一条非 tool 消息是 user(模型还没答)
或带 tool_calls 的 assistant(这批工具之后没了下文)。已答完、只是没来得及
finalize 的会话不在此列,照常归位。归位后延迟 5 秒(等 listen 与 executor
就绪)再拉起:补中断点的回执,然后 ensureBinding + touch(active) +
恢复 deepThink + runLoop。

补回执不是伪造执行结果,文案写明「服务重启,本次调用被中断,执行结果未知」。
没有配对回执时 buildMessages 会把整行 tool_calls 丢掉,模型看不到自己发过
什么命令,「重启」这类任务就会无限重试(实测 stop/start 来回三轮)。
2026-11-13 14:30:30 +08:00
8 changed files with 176 additions and 49 deletions
+63
View File
@@ -205,9 +205,44 @@ function syncModelPool() {
// 进程重启后:key 非独占,所有会话的绑定保持不动(顶部展示的模型持续可见,直到用户手动断开/换绑)。
// active(重启后必无回合进程)与遗留 queued 会话统一归位 held;指向已被删除/禁用模型的绑定,
// 下次发消息时由 ensureBinding 自动改选(优先留原平台),用户无感。
// 归位前先把「回合没走完」的 active 挑出来:stop/重启打断时它们停在半路,最后一条非 tool 消息
// 必是 user(模型还没答)或带 tool_calls 的 assistant(这批工具之后没了下文)。
// 已答完、只是没来得及 finalize 的会话(最后是纯文本 assistant)不在此列,照常归位 held。
const resumeIds = [];
for (const r of db.prepare("SELECT id FROM sessions WHERE status='active'").all()) {
const last = db.prepare(
"SELECT role, tool_calls FROM messages WHERE session_id = ? AND role != 'tool' ORDER BY id DESC LIMIT 1"
).get(r.id);
if (last && (last.role === 'user'
|| (last.role === 'assistant' && last.tool_calls && last.tool_calls !== '[]'))) resumeIds.push(r.id);
}
db.prepare('UPDATE model_pool SET is_busy = 0, current_session_id = NULL').run(); // 旧版独占列清残留(调度已不读)
db.prepare("UPDATE sessions SET status='held', held_at=COALESCE(held_at, updated_at), updated_at=? WHERE status IN ('active','queued')").run(now());
startHeldSweeper();
// 续跑:不伪造工具执行结果,但给中断点那批调用补一条「服务重启、结果未知」的回执,
// 否则 buildMessages 会把整行 tool_calls 丢掉,模型看不到自己发过什么命令,重启类任务就会无限重试。
// 等 5s 是因为 init 早于 server.listen,executor 也可能还在起,太早开跑首轮工具只会拿到连接错误。
const RESUME_DELAY_MS = 5000;
for (const id of resumeIds) {
setTimeout(() => {
const s = getSession(id);
// 5s 内用户可能已经自己发消息(已开跑)或点了停止:只接管仍停在 held/active 的会话
if (!s || (s.status !== 'held' && s.status !== 'active')) return;
try {
ensureBinding(s);
touch(id, { status: 'active', held_at: null, completed_at: null, cancelled_at: null });
getRun(id, true).deepThink = !!s.deep_think; // 恢复中断前的深度思考开关(会话行里持久化的值)
const n = markInterruptedBatch(id); // 先补中断点的回执,模型才能看到自己发过什么命令
if (n) log.info('tool', id + ' 重启续跑前补齐 ' + n + ' 条中断回执');
emitStatus(id);
runLoop(id);
log.info('engine', id + ' 重启后续跑未完成的回合');
} catch (e) {
log.warn('engine', id + ' 重启续跑失败:' + (e && e.message || e));
}
}, RESUME_DELAY_MS);
}
if (resumeIds.length) log.info('engine', '检测到 ' + resumeIds.length + ' 个被中断的回合,就绪后自动续跑');
}
// ---------- 会话闲置处理(30min held 归档 + 4h 记忆收口) ----------
@@ -587,6 +622,34 @@ async function runLoop(sessionId) {
}
}
// 重启续跑前给中断点那批调用补回执:不伪造执行结果,只告知「服务重启、结果未知」。
// 有了配对回执,buildMessages 才会保留整行 tool_calls——否则它会把无回执的调用剔掉,
// 模型看不到自己发过什么命令,「重启」类任务就靠猜,猜错就无限重试。
function markInterruptedBatch(sessionId) {
const last = db.prepare(
"SELECT id, role, tool_calls FROM messages WHERE session_id = ? AND role != 'tool' ORDER BY id DESC LIMIT 1"
).get(sessionId);
if (!last || last.role !== 'assistant' || !last.tool_calls) return 0; // 收尾回复或用户才发完话
let calls = [];
try { calls = JSON.parse(last.tool_calls) || []; } catch (_) { return 0; }
const got = new Set(
db.prepare(
"SELECT tool_call_id FROM messages WHERE session_id = ? AND role = 'tool' AND id > ? AND tool_call_id IS NOT NULL AND tool_call_id != ''"
).all(sessionId, last.id).map(r => r.tool_call_id)
);
let n = 0;
for (const c of calls) {
if (!c || !c.id || got.has(c.id)) continue;
const name = (c.function && c.function.name) || '未知工具';
saveMessage(sessionId, {
role: 'tool', tool_call_id: c.id, name,
content: '[系统] 服务重启,本次调用被中断,执行结果未知:先核实实际状态再决定,不要直接重试。',
});
n++;
}
return n;
}
function finalize(sessionId, run) {
const s = getSession(sessionId);
if (!s || s.status !== 'active') { runs.delete(sessionId); return; }
+34 -3
View File
@@ -225,6 +225,36 @@ main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* 流式阶段给一点视觉提示:边色稍亮,收尾(assistant_message)后去除 */
.msg-think.streaming { border-color: #d8e0f5; }
/* 上下文卡片:只发给模型看的注入行(画像快照 / 渠道说明 / 开场记忆)折叠展示,
视觉与压缩摘要卡片一致:淡蓝底、蓝边蓝字、三角箭头、虚线分隔,不用渐变/阴影 */
.msg-ctx {
margin: 0 0 12px; border: 1px solid #dbe4fb; border-radius: 12px; overflow: hidden;
background: #f7f9ff;
}
.msg-ctx > summary {
list-style: none; cursor: pointer; user-select: none;
display: flex; align-items: center; gap: 7px;
padding: 9px 12px; font-size: 13px; font-weight: 600; color: var(--active);
}
.msg-ctx > summary::-webkit-details-marker { display: none; }
.msg-ctx > summary::before {
content: ''; flex: none; width: 0; height: 0; margin-left: 1px;
border-left: 5px solid var(--active); border-top: 4px solid transparent; border-bottom: 4px solid transparent;
transition: transform .15s ease;
}
.msg-ctx[open] > summary::before { transform: rotate(90deg); }
.msg-ctx-body {
/* 比标题区(#f7f9ff)再淡一档,分隔开又不跳色 */
border-top: 1px dashed #dbe4fb; background: #fbfcff;
padding: 10px 13px 12px;
}
.msg-ctx-body .bubble-ai { margin: 0; background: transparent; font-size: 14px; line-height: 1.7; }
/* errAck:这一轮工具参数非法、已从上下文移除,气泡上方标一行 */
.msg-note {
margin: 0 0 6px; padding: 3px 9px; border-radius: 6px;
background: #fff8c5; color: #9a6700; font-size: 12px;
}
/* 用户气泡:右侧,浅色背景,圆角矩形 */
.bubble-user {
background: var(--active-soft); color: var(--ink);
@@ -1889,8 +1919,9 @@ body.pv-resizing #pv-pane iframe { pointer-events: none; }
/* ================= 待发送条幅(运行中排队 / 干预 / 立即发送) ================= */
/* 输入卡上方一行小条:正文单行省略 + 动作按钮。多条时逐条堆叠,每条仍是一行。
配色刻意与「编辑提示条」的蓝色区分:排队是“稍后执行”的提示态,不是输入态。 */
.send-queue { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.send-queue { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; max-height: 100px; overflow-y: auto; }
.sq-item {
flex: none; /* 多条时容器限高滚动,别把条目压扁 */
display: flex; align-items: center; gap: 6px;
padding: 5px 5px 5px 11px;
border-radius: 12px; background: #fff4dc; color: #a06a00; font-size: 12.5px;
@@ -1903,9 +1934,9 @@ body.pv-resizing #pv-pane iframe { pointer-events: none; }
}
.sq-item button:active { background: rgba(160, 106, 0, 0.12); }
.sq-item button:disabled { opacity: .45; }
.sq-item .sq-x { padding: 2px 7px; font-weight: 500; }
.sq-item .sq-act { padding: 0; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 7px; }
/* 已升级为「干预/立即发送」但还没到边界:按钮置灰,显示“等待当前步骤” */
.sq-item.sq-busy button:not(.sq-x) { opacity: .45; }
.sq-item.sq-busy button:not(.sq-act) { opacity: .45; }
/* ================= 编辑已发送消息提示条 ================= */
/* 覆盖式重发:输入框内部的浅蓝提示条(嵌在 .input-shell 顶端,间距由 shell 的 gap 提供)。 */
+8 -10
View File
@@ -17,13 +17,12 @@
<link rel="icon" type="image/png" sizes="192x192" href="/icons/icon-192.png">
<link rel="stylesheet" href="/css/style.css">
<style>
/* 「压缩」摘要卡片:与 .msg-think 同族的折叠交互,但做成更醒目的蓝色调卡片;
流式收尾(live)和历史重渲染(type='summary' 消息)共用同一套样式。
live 阶段 open=true 展开阅读;历史重渲染默认收起。 */
/* 「压缩」摘要卡片:与 .msg-ctx(画像快照/渠道/记忆)同一套视觉——淡蓝底、蓝边蓝字、
三角箭头、虚线分隔。纯色不用渐变/阴影,折叠与展开同一底色。默认收起 */
.msg-summary {
width: 100%; /* .msg.other 是 align-items:flex-start 的列 flex,不写就只撑标题那点宽 */
margin: 0 0 8px; border: 1px solid #dbe4fb; border-radius: 12px; overflow: hidden;
background: linear-gradient(180deg, #f7f9ff 0%, #ffffff 56%);
box-shadow: 0 1px 3px rgba(57, 100, 254, 0.08);
background: #f7f9ff;
}
.msg-summary > summary {
list-style: none; cursor: pointer; user-select: none;
@@ -37,13 +36,12 @@
transition: transform .15s ease;
}
.msg-summary[open] > summary::before { transform: rotate(90deg); }
.msg-summary .sum-ic { flex: none; width: 15px; height: 15px; }
.msg-summary .sum-hint { margin-left: auto; font-size: 11px; font-weight: 400; color: var(--gray); }
.msg-summary-body {
border-top: 1px dashed #dbe4fb; background: var(--page);
/* 比标题区(#f7f9ff)再淡一档,分隔开又不跳色 */
border-top: 1px dashed #dbe4fb; background: #fbfcff;
padding: 10px 13px 12px;
}
.msg-summary-body .bubble-ai { margin: 0; font-size: 14px; line-height: 1.7; }
.msg-summary-body .bubble-ai { margin: 0; background: transparent; font-size: 14px; line-height: 1.7; }
/* 「仅摘要」后摘要之前的旧历史:UI 保留但变淡,尾部附存档说明(不再发给 AI) */
.msg-archived { opacity: .55; }
.archived-note {
@@ -275,7 +273,7 @@
<svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
</button>
<button class="files-fab del" id="files-bulk-delete" title="批量删除" aria-label="批量删除" disabled>
<svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
<svg viewBox="0 0 24 24"><path d="M3 6h18"/><path d="M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/></svg>
</button>
</div>
</div>
+32 -13
View File
@@ -56,6 +56,21 @@
'</div>';
}
// 上下文卡片:画像快照 / 渠道说明 / 开场记忆这类「只发给模型看的注入行」,
// 统一渲染成可折叠的系统卡片,而不是伪装成用户发言。
function ctxCardHtml(title, text, id) {
const r = mdHtml(text || ''); // 与摘要卡片同样走 markdown,保持四张卡片观感一致
return '<details class="msg-ctx"' + (id ? ' id="' + id + '"' : '') + '><summary>' + esc(title) + '</summary>'
+ '<div class="msg-ctx-body"><div class="bubble-ai' + (r.fmt ? ' md' : '') + '">' + r.html + '</div></div></details>';
}
// 画像快照是每轮请求拼在最前的上下文(不在 messages 表里)。历史是懒加载的,首屏只拉最近几条,
// 所以不能一打开就插,得等翻到最早、确认没有更早的消息了再放到最顶。
function ensureProfileCard(box) {
if (!state.profileSnapshot || !box || box.querySelector('#ctx-profile')) return;
box.insertAdjacentHTML('afterbegin', ctxCardHtml('画像快照', state.profileSnapshot, 'ctx-profile'));
}
function userMsgHtml(m) {
const p = parseUploadNotice(m.content);
const attach = p.files && p.files.length
@@ -72,10 +87,14 @@
function aiMsgHtml(m) {
const text = (m.content || '').trim();
const reason = (m.reasoning || '').trim();
if (!text && !reason) return null; // 纯工具调用的应答:不渲染气泡,工具卡由 appendToolCardsFromAssistant 铺
const errAck = m.type === 'errAck';
// 纯工具调用的应答不渲染气泡(工具卡由 appendToolCardsFromAssistant 铺),但 errAck 要留个标记
if (!text && !reason && !errAck) return null;
const note = errAck
? '<div class="msg-note">工具调用参数无效,本轮已从上下文移除,模型会重新发起</div>' : '';
const think = reason ? thinkPanelHtml(m.reasoning) : '';
const bubble = text ? (() => { const r = mdHtml(m.content); return '<div class="bubble-ai' + (r.fmt ? ' md' : '') + '">' + r.html + '</div>'; })() : '';
return '<div class="msg other">' + think + bubble + actionsHtml(m.created_at, m.content || '', m.id, m.usage) + '</div>';
return '<div class="msg other">' + note + think + bubble + actionsHtml(m.created_at, m.content || '', m.id, m.usage) + '</div>';
}
// 思考过程折叠面板:summary 固定名「思考过程」+ 右侧复制按钮,body 展示推理全文。
// 历史重渲染默认收起(与原设计一致),流式阶段的展开行为由 ensureStreamThinkPanel 显式控制。
@@ -118,15 +137,7 @@
// 「压缩」摘要卡片:流式收尾与历史重渲染共用的头部(图标 + 标题 + 右侧说明)。
function summaryHeaderHtml() {
return '<summary>' +
'<svg class="sum-ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round">' +
'<ellipse cx="12" cy="5" rx="8" ry="2.5"></ellipse>' +
'<path d="M4 5v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5V5"></path>' +
'<path d="M4 11v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5v-6"></path>' +
'</svg>' +
'<span>上下文总结</span>' +
'<span class="sum-hint">后续对话以此为起点</span>' +
'</summary>';
return '<summary><span>上下文总结</span></summary>';
}
// 历史重渲染:被标记 type='summary' 的摘要消息渲染成摘要卡片(默认收起,点开可重现)。
@@ -322,7 +333,11 @@
}
function msgNode(m) {
if (m.role === 'user') return userMsgHtml(m);
if (m.role === 'user') {
if (m.type === 'channel_note') return ctxCardHtml('渠道上下文', m.content);
if (m.type === 'memory_note') return ctxCardHtml('开场记忆', m.content);
return userMsgHtml(m);
}
// 被「压缩总结」标记的摘要消息:重渲染成摘要卡片,而不是普通 AI 气泡
if (m.role === 'assistant') return m.type === 'summary' ? summaryMsgHtml(m) : aiMsgHtml(m);
return null; // tool 结果不单独展示
@@ -431,9 +446,12 @@
const prevTop = keepView ? box.scrollTop : 0;
const followBottom = !keepView || !box.firstElementChild || isNearBottom();
box.innerHTML = '';
state.profileSnapshot = (s && s.profile_snapshot) || '';
appendMessagesDom(detail.messages || [], box).closeArc();
// 首屏就把历史拉完了(条数少):直接上画像卡片;否则等上滑翻到最早再插
if (!detail.has_more) ensureProfileCard(box);
if (!(detail.messages || []).length) {
box.innerHTML = '<div class="drawer-empty">描述你的需求,AI 会和你讨论并直接干活。</div>';
box.insertAdjacentHTML('beforeend', '<div class="drawer-empty">描述你的需求,AI 会和你讨论并直接干活。</div>');
}
state.chatHasMore = !!detail.has_more;
state.chatOldestId = detail.oldest_id || null;
@@ -501,6 +519,7 @@
while (frag.firstChild) box.insertBefore(frag.firstChild, anchor);
box.scrollTop = box.scrollHeight - prevH + prevTop;
state.chatHasMore = !!detail.has_more;
if (!detail.has_more) ensureProfileCard(box); // 翻到最早了:画像卡片补到流最顶
if (detail.oldest_id) state.chatOldestId = detail.oldest_id;
state.chatLoadedCount += (detail.messages || []).length;
// 旧页太短导致补完后仍贴在触发区:继续拉下一页,避免卡在顶部要再动一下才加载
+2 -3
View File
@@ -17,7 +17,7 @@
const SVG_VCS = '<svg class="ic sm" viewBox="0 0 24 24"><circle cx="6" cy="5" r="2"/><circle cx="6" cy="19" r="2"/><circle cx="18" cy="7" r="2"/><path d="M6 7v10"/><path d="M18 9v1a4 4 0 0 1-4 4H9"/></svg>';
const SVG_EYE = '<svg class="ic sm" viewBox="0 0 24 24"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="2.6"/></svg>';
const SVG_DL = '<svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>';
const SVG_DEL = '<svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>';
const SVG_DEL = '<svg viewBox="0 0 24 24"><path d="M3 6h18"/><path d="M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/></svg>';
const SVG_REVEAL_SM = '<svg viewBox="0 0 24 24"><path d="M14 4h6v6"/><path d="M20 4l-9 9"/><path d="M19 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h5"/></svg>';
let localCapable = false; // local 启动器:才显示「在 Finder/终端中打开」
@@ -195,7 +195,6 @@
sel.delete(rel);
invalidate(true);
renderBody();
toast('已删除');
} catch (e) { toast('删除失败:' + e.message); }
}
@@ -349,7 +348,7 @@
sel.clear();
invalidate(true);
renderBody();
toast(fail ? ('已删除 ' + done + ' 项,' + fail + ' 项失败') : ('已删除 ' + done + ' 项'));
if (fail) toast('已删除 ' + done + ' 项,' + fail + ' 项失败'); // 全成功时列表自己就空了,不弹
}
function onTreeClick(e) {
+2 -4
View File
@@ -49,8 +49,7 @@
// 深度思考开关:每次发消息随 body 传给后端,后端会合并该模型的 thinking_params
$('deep-think-btn').addEventListener('click', () => {
state.deepThink = !state.deepThink;
$('deep-think-btn').classList.toggle('on', state.deepThink);
toast(state.deepThink ? '深度思考已开启' : '深度思考已关闭');
$('deep-think-btn').classList.toggle('on', state.deepThink); // 按钮态即反馈,不再弹 toast
});
// ---------- 任务文件面板(底部浮层:点输入行右侧文件夹按钮展开,遮罩盖住输入区) ----------
@@ -666,8 +665,7 @@
ok++;
} catch (e) { fail++; toast('删除失败:' + name + ' ' + e.message); }
}
if (ok) toast('已删除 ' + ok + ' 项');
loadFiles(); // 重新拉取并重置选中
loadFiles(); // 重新拉取并重置选中;失败已逐条提示,全成功时不弹汇总
}
$('files-bulk-download').addEventListener('click', bulkDownload);
$('files-bulk-delete').addEventListener('click', bulkDelete);
+1 -3
View File
@@ -35,7 +35,7 @@
'<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>' +
'</button>' +
'<button class="conv-del" data-del="' + esc(s.id) + '" title="删除会话" aria-label="删除会话">' +
'<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>' +
'<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/></svg>' +
'</button>' +
'</div>';
}
@@ -96,7 +96,6 @@
syncUrl();
setView('welcome'); // 复用 newChat 同样的视图切换路径
}
toast('已删除会话');
loadSessionList();
} catch (e) { toast('删除失败:' + e.message); }
}
@@ -365,7 +364,6 @@
const title = String(t).trim();
try {
await req('PATCH', '/api/sessions/' + state.sessionId, { title: title });
toast('已重命名');
state.sessionTitle = title;
renderHeader();
loadSessionList();
+34 -13
View File
@@ -98,13 +98,19 @@
// ---------- 待发送条幅 ----------
// 队列本身在服务端(engine.pendings),关页面/换设备/重连都不丢;这里只负责画。
// 每条一行;只有队首有「干预 / 立即发送」,其余显示排队中(不能越过前一条先发)。
// 两条操作各配一枚图标:笔=撤回编辑(正文退回输入框),垃圾桶=直接丢弃这条
const SQ_EDIT_ICON = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>';
const SQ_TRASH_ICON = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/></svg>';
function renderSendQueue() {
const box = $('send-queue');
if (!box) return;
const list = state.pending || [];
// 条幅增减会改 chat-view 的 clientHeight,浏览器不会替你补滚动:
// 改动前先记住是不是贴底,贴底就强制滚回去,否则最后一条消息被裁在视口外。
const keepBottom = typeof isNearBottom === 'function' ? isNearBottom() : false;
box.classList.toggle('hidden', !list.length);
if (!list.length) { box.innerHTML = ''; return; }
box.innerHTML = list.map((it, i) => {
box.innerHTML = list.length ? list.map((it, i) => {
const busy = it.mode === 'interject' || it.mode === 'now';
const tag = it.mode === 'now' ? '<span class="sq-tag">正在中断…</span>'
: it.mode === 'interject' ? '<span class="sq-tag">等待当前步骤…</span>'
@@ -116,11 +122,14 @@
return '<div class="sq-item' + (busy ? ' sq-busy' : '') + '" data-qid="' + esc(it.id) + '">' +
'<span class="sq-text" title="' + esc(it.content) + '">' + esc(it.content) + '</span>' +
tag + acts +
'<button class="sq-x" data-act="cancel" title="取消这条">×</button></div>';
}).join('');
'<button class="sq-act" data-act="recall" title="撤回到输入框,重新编辑" aria-label="撤回编辑">' + SQ_EDIT_ICON + '</button>' +
'<button class="sq-act" data-act="cancel" title="删除这条" aria-label="删除这条">' + SQ_TRASH_ICON + '</button></div>';
}).join('') : '';
// 双帧补滚:hidden 类与 textarea 高度都是本帧生效,rAF 后再跟一次才稳
if (keepBottom && typeof scrollBottom === 'function') { scrollBottom(); requestAnimationFrame(scrollBottom); }
}
// 条幅按钮:× 取消;干预/立即发送升级队首(服务端只在安全边界真正投递)。
// 条幅按钮:笔=撤回编辑(正文退回输入框),垃圾桶=直接丢弃;干预/立即发送升级队首。
async function onSendQueueClick(e) {
const btn = e.target.closest('#send-queue button[data-act]');
if (!btn || !state.sessionId) return;
@@ -128,20 +137,34 @@
const qid = item && item.dataset.qid;
if (!qid) return;
const act = btn.dataset.act;
const isDel = act === 'recall' || act === 'cancel'; // 两者都是删队列项,区别只在要不要回填
// 撤回文本必须在请求前取:DELETE 的响应里这条已经没了
const draft = act === 'recall' ? ((state.pending || []).find(x => x.id === qid) || {}).content || '' : '';
btn.disabled = true;
try {
const base = '/api/sessions/' + state.sessionId + '/pending/' + encodeURIComponent(qid);
const r = act === 'cancel' ? await req('DELETE', base) : await req('POST', base, { action: act });
const r = isDel ? await req('DELETE', base) : await req('POST', base, { action: act });
if (r && Array.isArray(r.pending)) { state.pending = r.pending; renderSendQueue(); }
if (act === 'cancel') return;
if (r && r.delivered) return; // 回合已结束:服务端直接投递,等 user_message 画气泡
toast(act === 'now' ? '已请求中断,随后立即发送' : '已请求干预:当前步骤结束后插话');
if (isDel) { if (draft) recallToInput(draft); return; }
// 干预/立即发送:条幅自己会变成「等待当前步骤…」/「正在中断…」,不再弹 toast
} catch (err) {
toast('操作失败:' + err.message);
renderSendQueue();
}
}
// 撤回:塞回输入框(撤回段在前、已有草稿在后,与发送失败的兜底同序),光标停在撤回段末尾
function recallToInput(text) {
const ta = $('msg-input');
if (!ta) return;
ta.value = text + (ta.value ? '\n' + ta.value : '');
autosize();
updateSendBtn();
ta.focus({ preventScroll: true }); // 别让浏览器为露出输入框去滚页面,聊天区的位置由下面统一管
try { ta.setSelectionRange(text.length, text.length); } catch (_) {}
if (typeof scrollBottom === 'function') { scrollBottom(); requestAnimationFrame(scrollBottom); }
}
const sendQueueBox = $('send-queue');
if (sendQueueBox) sendQueueBox.addEventListener('click', onSendQueueClick);
@@ -308,13 +331,12 @@
// 「压缩」总结回合的最终答复(后端已保证只有压缩回合里首条无工具调用的收尾回复才带 is_summary,
// 中间 AI 回复已按普通消息渲染):把已流式输出的气泡装进摘要卡片(与历史重渲染同款样式),
// 并标记 wrap 为 msg-summary-live:archiveDomBeforeSummary 据此定位摘要卡片,之前的旧消息收进存档容器。
// open=true 让用户立刻读到;后续轮次不自动折起(卡片可手动点 summary 收起)。
// 摘要卡片默认收起(与画像快照/渠道/记忆同一种交互),用户想读时点开。
// 防重:同一 streamWrap 已有卡片则不再重复插入(保护 SSE 重连重发等场景)。
if (d.is_summary && hasText && state.streamWrap && !state.streamWrap.querySelector('.msg-summary')) {
const wrap0 = state.streamWrap;
const det = document.createElement('details');
det.className = 'msg-summary';
det.open = true;
det.innerHTML = summaryHeaderHtml() + '<div class="msg-summary-body"></div>';
const body = det.querySelector('.msg-summary-body');
const bubble = wrap0.querySelector('.bubble-ai');
@@ -520,7 +542,7 @@
try { text = decodeURIComponent(escape(atob(copyBtn.dataset.b64 || ''))); } catch (_) {}
}
const ok = await copyText(text);
toast(ok ? '已复制' : '复制失败');
if (!ok) toast('复制失败');
if (ok) {
copyBtn.classList.add('copied');
setTimeout(() => copyBtn.classList.remove('copied'), 1200);
@@ -541,7 +563,6 @@
btn.disabled = true;
try {
await req('DELETE', '/api/sessions/' + state.sessionId + '/messages/' + msgId);
toast('已删除');
// 按已加载量分页重拉(长会话删一条不该退回全量重建)
const detail = await req('GET', '/api/sessions/' + state.sessionId + '?limit=' + Math.max(CHAT_PAGE_SIZE, state.chatLoadedCount));
if (state.view === 'chat') renderDetail(detail);