chore: rebuild release package

This commit is contained in:
shiyue
2026-07-18 19:47:04 +08:00
parent b90f5e1e44
commit a038485ab5
9 changed files with 729 additions and 49 deletions

View File

@@ -4275,6 +4275,8 @@
updateSessionIdBadge();
updateCwdBadge();
updateReloadMcpButtonUI();
// 真正替换聊天 DOM 时,使之前 renderMessages 的异步批次失效。
renderEpoch++;
messagesDiv.innerHTML = buildWelcomeMarkup(currentCwd);
setStatsDisplay(null);
renderPendingAttachments();
@@ -4513,21 +4515,41 @@
(!sessionId || activeSessionLoad.sessionId === sessionId));
}
function finishSessionSwitch(sessionId) {
function finishSessionSwitch(sessionId, requestId) {
// 带 requestId 的完成事件必须属于当前加载代次,避免旧请求尾块关闭新请求。
if (requestId && (!activeSessionLoad ||
activeSessionLoad.sessionId !== sessionId ||
activeSessionLoad.requestId !== requestId)) {
return;
}
if (isBlockingSessionLoad(sessionId)) {
scrollToBottom();
requestAnimationFrame(() => clearSessionLoading(sessionId));
requestAnimationFrame(() => {
// RAF 执行时再次校验请求代次,避免旧请求清除同会话的新加载。
if (requestId && (!activeSessionLoad ||
activeSessionLoad.sessionId !== sessionId ||
activeSessionLoad.requestId !== requestId)) {
return;
}
clearSessionLoading(sessionId);
});
return;
}
clearSessionLoading(sessionId);
}
function finalizeLoadedSession(sessionId) {
function finalizeLoadedSession(sessionId, requestId) {
// 带 requestId 的完成事件必须属于当前加载代次,避免旧 A 尾块完成新 A 请求。
if (requestId && (!activeSessionLoad ||
activeSessionLoad.sessionId !== sessionId ||
activeSessionLoad.requestId !== requestId)) {
return;
}
if (activeSessionLoad?.sessionId === sessionId && activeSessionLoad.snapshot) {
activeSessionLoad.snapshot.complete = true;
cacheSessionSnapshot(activeSessionLoad.snapshot);
}
finishSessionSwitch(sessionId);
finishSessionSwitch(sessionId, requestId);
}
function beginSessionSwitch(sessionId, options = {}) {
@@ -4536,7 +4558,6 @@
const force = options.force === true;
if (!force && activeSessionLoad?.sessionId === sessionId && !activeSessionLoad.overlayReleased) return;
if (!force && sessionId === currentSessionId && !activeSessionLoad) return;
renderEpoch++;
loadedHistorySessionId = null;
setSessionLoading(sessionId, { blocking, label: options.label });
requestSessionLoad(sessionId, { blocking, label: options.label });
@@ -5304,24 +5325,28 @@
&& (!pendingNewSession.cwd || snapshot.cwd === pendingNewSession.cwd)
&& (!pendingNewSession.mode || snapshot.mode === pendingNewSession.mode));
const matchesActiveLoad = !!(activeLoad?.sessionId === msg.sessionId
&& (!activeLoad.requestId || activeLoad.requestId === messageRequestId));
&& (!messageRequestId || activeLoad.requestId === messageRequestId));
const matchesPendingNewSession = !!(pendingNewSession
&& ((!pendingNewSession.requestId || pendingNewSession.requestId === messageRequestId)
&& ((messageRequestId && pendingNewSession.requestId === messageRequestId)
|| matchesPendingNewSessionFallback));
const allowsRequestlessCurrentSession = !messageRequestId && msg.sessionId === currentSessionId;
const allowsRequestlessIdleSession = !messageRequestId && !currentSessionId && !activeLoad && !pendingNewSession;
const allowsRequestlessUnclaimedSession = !messageRequestId && !activeLoad && !pendingNewSession;
const canSwitchToSessionInfo = matchesActiveLoad
|| matchesPendingNewSession
|| msg.sessionId === currentSessionId
|| (!messageRequestId && !currentSessionId && !activeLoad && !pendingNewSession)
|| (!messageRequestId && !activeLoad && !pendingNewSession);
// 带 requestId 的响应只能由对应的活动加载/新建请求接管视图;
// 没有 requestId 的旧服务事件保留当前会话兼容路径。
|| allowsRequestlessCurrentSession
|| allowsRequestlessIdleSession
|| allowsRequestlessUnclaimedSession;
if (!canSwitchToSessionInfo) {
// 旧代次事件不能污染缓存或会话列表。
break;
}
mergeSessionListSnapshot(snapshot);
if (matchesActiveLoad) {
activeSessionLoad.snapshot = snapshot;
}
if (!canSwitchToSessionInfo) {
if (!msg.historyPending) cacheSessionSnapshot(snapshot);
renderSessionList();
break;
}
if (matchesPendingNewSession) {
pendingNewSessionRequest = null;
if (!matchesActiveLoad) clearSessionLoading();
@@ -5341,34 +5366,48 @@
}
if (!msg.historyPending) {
if (matchesActiveLoad) {
finalizeLoadedSession(msg.sessionId);
finalizeLoadedSession(msg.sessionId, messageRequestId || undefined);
} else {
cacheSessionSnapshot(snapshot);
finishSessionSwitch(msg.sessionId);
finishSessionSwitch(msg.sessionId, messageRequestId || undefined);
}
}
break;
case 'session_history_chunk':
if (activeSessionLoad?.recoverCurrent && activeSessionLoad.sessionId === msg.sessionId) {
if (!msg.remaining) finalizeLoadedSession(msg.sessionId);
case 'session_history_chunk': {
const historyRequestId = String(msg.requestId || '');
const matchesActiveHistoryLoad = !!(activeSessionLoad
&& activeSessionLoad.sessionId === msg.sessionId
&& (!historyRequestId || activeSessionLoad.requestId === historyRequestId));
const allowsLegacyHistory = !historyRequestId
&& msg.sessionId === currentSessionId
&& loadedHistorySessionId === msg.sessionId;
if (activeSessionLoad?.recoverCurrent && matchesActiveHistoryLoad) {
if (activeSessionLoad.snapshot) {
activeSessionLoad.snapshot.messages = cloneMessages(msg.messages || [])
.concat(activeSessionLoad.snapshot.messages);
}
if (!msg.remaining) finalizeLoadedSession(msg.sessionId, historyRequestId || undefined);
break;
}
if ((matchesActiveHistoryLoad || allowsLegacyHistory)
&& msg.sessionId === currentSessionId
&& loadedHistorySessionId === msg.sessionId) {
const blocking = isBlockingSessionLoad(msg.sessionId);
if (activeSessionLoad?.sessionId === msg.sessionId && activeSessionLoad.snapshot) {
activeSessionLoad.snapshot.messages = cloneMessages(msg.messages || []).concat(activeSessionLoad.snapshot.messages);
}
prependHistoryMessages(msg.messages || [], {
preserveScroll: !blocking,
skipScrollbar: blocking,
baseIndex: Number.isFinite(Number(msg.historyBaseIndex)) ? Number(msg.historyBaseIndex) : 0,
});
if (!msg.remaining) {
finalizeLoadedSession(msg.sessionId, historyRequestId || undefined);
}
}
break;
}
if (msg.sessionId === currentSessionId && loadedHistorySessionId === msg.sessionId) {
const blocking = isBlockingSessionLoad(msg.sessionId);
if (activeSessionLoad?.sessionId === msg.sessionId && activeSessionLoad.snapshot) {
activeSessionLoad.snapshot.messages = cloneMessages(msg.messages || []).concat(activeSessionLoad.snapshot.messages);
}
prependHistoryMessages(msg.messages || [], {
preserveScroll: !blocking,
skipScrollbar: blocking,
baseIndex: Number.isFinite(Number(msg.historyBaseIndex)) ? Number(msg.historyBaseIndex) : 0,
});
if (!msg.remaining) {
finalizeLoadedSession(msg.sessionId);
}
}
break;
case 'session_message':
if (msg.sessionId && msg.message) {