修复两处状态/渲染 bug:1) 引擎 postUserMessage 对已完成/已取消会话重新入队后回读真实状态——dispatchQueued 已立即绑定空闲模型时返回 delivered=live,前端不再误显「排队中,暂存」误标(仅真排队才显示);2) tool_call 与 assistant_message 两个 SSE 事件按 toolCards 注册表去重,同 id 只建一张卡,执行结果原地替换不再残留「执行中」重复卡
This commit is contained in:
@@ -350,12 +350,13 @@ function postUserMessage(sessionId, content, opts) {
|
||||
runLoop(sessionId);
|
||||
return { message_id: messageId, delivered: 'live' };
|
||||
}
|
||||
// 排队 / 已完成 / 已取消 → 重新入队
|
||||
// 排队 / 已完成 / 已取消 → 重新入队;若派发后已立即拿到空闲模型,则算直接送达
|
||||
touch(sessionId, { status: 'queued', cancelled_at: null, completed_at: null });
|
||||
enqueue(sessionId);
|
||||
emitStatus(sessionId);
|
||||
dispatchQueued();
|
||||
return { message_id: messageId, delivered: 'queued' };
|
||||
const after = getSession(sessionId);
|
||||
emitStatus(sessionId);
|
||||
return { message_id: messageId, delivered: after && after.status === 'active' ? 'live' : 'queued' };
|
||||
}
|
||||
|
||||
function startExecution(sessionId) {
|
||||
|
||||
@@ -202,6 +202,7 @@ function appendToolCardsFromAssistant(m, container) {
|
||||
try { calls = typeof m.tool_calls === 'string' ? JSON.parse(m.tool_calls) : m.tool_calls; } catch (_) { return; }
|
||||
for (const c of calls) {
|
||||
const id = c.id || ('c' + Math.random().toString(36).slice(2, 10));
|
||||
if (state.toolCards[id]) continue; // tool_call 事件已经建过同一张卡,不重复创建
|
||||
const card = renderToolCard(id, c.function.name, c.function.arguments);
|
||||
container.appendChild(card);
|
||||
state.toolCards[id] = card;
|
||||
@@ -282,6 +283,7 @@ function connectStream() {
|
||||
});
|
||||
es.addEventListener('tool_call', ev => {
|
||||
const d = JSON.parse(ev.data);
|
||||
if (state.toolCards[d.id]) return; // assistant_message 已建卡(含完整参数),不重复创建
|
||||
const card = renderToolCard(d.id, d.name, d.arguments);
|
||||
$('messages').appendChild(card);
|
||||
state.toolCards[d.id] = card;
|
||||
|
||||
Reference in New Issue
Block a user