Merge branch 'main' into fix/issue-809-plus-batch-a

This commit is contained in:
程序员阿江(Relakkes) 2026-06-22 23:08:16 +08:00
commit f36af8e17f
2 changed files with 44 additions and 1 deletions

View File

@ -287,6 +287,40 @@ describe('chatStore history mapping', () => {
})
})
it('does not prewarm an existing transcript when opening it for history review', () => {
sessionStoreSnapshot.sessions = [{
id: TEST_SESSION_ID,
title: 'Existing transcript',
createdAt: '2026-06-20T10:00:00.000Z',
modifiedAt: '2026-06-20T10:30:00.000Z',
messageCount: 4,
projectPath: '/workspace/project',
workDir: '/workspace/project',
workDirExists: true,
}]
useChatStore.getState().connectToSession(TEST_SESSION_ID)
expect(sendMock).not.toHaveBeenCalledWith(TEST_SESSION_ID, { type: 'prewarm_session' })
})
it('still prewarms empty placeholder sessions so new chats start quickly', () => {
sessionStoreSnapshot.sessions = [{
id: TEST_SESSION_ID,
title: 'New Session',
createdAt: '2026-06-20T10:00:00.000Z',
modifiedAt: '2026-06-20T10:00:00.000Z',
messageCount: 0,
projectPath: '/workspace/project',
workDir: '/workspace/project',
workDirExists: true,
}]
useChatStore.getState().connectToSession(TEST_SESSION_ID)
expect(sendMock).toHaveBeenCalledWith(TEST_SESSION_ID, { type: 'prewarm_session' })
})
it('preserves thinking blocks when restoring transcript history', () => {
const messages: MessageEntry[] = [
{

View File

@ -902,6 +902,11 @@ async function fetchAndMapSessionHistory(sessionId: string) {
const historyLoadsInFlight = new Map<string, Promise<void>>()
function shouldPrewarmSession(sessionId: string): boolean {
const knownSession = useSessionStore.getState().sessions.find((session) => session.id === sessionId)
return !knownSession || knownSession.messageCount === 0
}
export const useChatStore = create<ChatStore>((set, get) => ({
sessions: {},
@ -948,7 +953,11 @@ export const useChatStore = create<ChatStore>((set, get) => ({
if (runtimeSelection) {
wsManager.send(sessionId, { type: 'set_runtime_config', ...runtimeSelection })
}
if (!sessionId.startsWith('__') && !useTeamStore.getState().getMemberBySessionId(sessionId)) {
if (
!sessionId.startsWith('__') &&
!useTeamStore.getState().getMemberBySessionId(sessionId) &&
shouldPrewarmSession(sessionId)
) {
wsManager.send(sessionId, { type: 'prewarm_session' })
}