feat(vscode-ide-companion): implement session rehydration for loading past conversations

- Add rehydratingSessionId flag to track session loading state
- Route message chunks as discrete messages during rehydration instead of streaming
- Update session handlers to properly manage conversation switching
- Improve session manager documentation
This commit is contained in:
yiliang114
2025-12-09 00:14:35 +08:00
parent f4edcc5cd2
commit 58b9e477bc
3 changed files with 79 additions and 16 deletions

View File

@@ -598,24 +598,22 @@ export class SessionMessageHandler extends BaseMessageHandler {
// Try to load session via ACP (now we should be connected)
try {
// Set current id and clear UI first so replayed updates append afterwards
this.currentConversationId = sessionId;
this.sendToWebView({
type: 'qwenSessionSwitched',
data: { sessionId, messages: [], session: sessionDetails },
});
const loadResponse = await this.agentManager.loadSessionViaAcp(
sessionId,
(sessionDetails?.cwd as string | undefined) || undefined,
);
console.log(
'[SessionMessageHandler] session/load succeeded:',
'[SessionMessageHandler] session/load succeeded (per ACP spec result is null; actual history comes via session/update):',
loadResponse,
);
this.currentConversationId = sessionId;
const messages = await this.agentManager.getSessionMessages(sessionId);
this.sendToWebView({
type: 'qwenSessionSwitched',
data: { sessionId, messages, session: sessionDetails },
});
// Reset title flag when switching sessions
this.isTitleSet = false;
@@ -1029,17 +1027,15 @@ export class SessionMessageHandler extends BaseMessageHandler {
// Try ACP load first
try {
await this.agentManager.loadSessionViaAcp(sessionId);
// Pre-clear UI so replayed updates append afterwards
this.currentConversationId = sessionId;
const messages = await this.agentManager.getSessionMessages(sessionId);
this.sendToWebView({
type: 'qwenSessionSwitched',
data: { sessionId, messages },
data: { sessionId, messages: [] },
});
await this.agentManager.loadSessionViaAcp(sessionId);
// Reset title flag when resuming sessions
this.isTitleSet = false;