fix: 修复对话停止和会话记忆保存问题

- apiClient 添加 stopDialog 接口
- dialogService 添加 getSegments/getAccumulatedText 方法
- dialogService.abort 调用后端停止接口
- messageHandler.abortCurrentDialog 保存中止前的对话内容
- userInteraction 添加 getWebviewPanel 方法
- webviewContent 添加 resetSegmentedMessage 命令处理
- 修复停止后新消息覆盖旧消息的问题
This commit is contained in:
XiaoFeng
2025-12-31 11:55:31 +08:00
parent 28b75e8475
commit 0f8674e1c7
8 changed files with 221 additions and 39 deletions

View File

@ -273,7 +273,35 @@ export async function handleUserAnswer(
/**
* 中止当前对话
*/
export function abortCurrentDialog(): void {
export async function abortCurrentDialog(): Promise<void> {
if (currentSession) {
// 保存当前已有的对话内容
const segments = currentSession.getSegments();
if (segments && segments.length > 0) {
try {
const historyManager = ChatHistoryManager.getInstance();
const textContent = segments
.filter(s => s.type === 'text' && s.content)
.map(s => s.content)
.join('\n');
// 添加中止标记
const abortedContent = textContent + '\n\n[对话已被用户中止]';
await historyManager.addAiMessage(abortedContent, undefined, segments);
console.log('[MessageHandler] 已保存中止前的对话内容');
} catch (error) {
console.warn('[MessageHandler] 保存中止对话失败:', error);
}
}
}
// 通知 WebView 重置分段消息容器
const panel = userInteractionManager.getWebviewPanel();
if (panel) {
panel.webview.postMessage({ command: 'resetSegmentedMessage' });
console.log('[MessageHandler] 已发送重置分段消息命令');
}
dialogManager.abortCurrentSession();
currentSession = null;
}