feat: 实现会话记忆同步和知识图谱恢复机制

- 添加 memory_compacted SSE 事件处理
- 添加 CompactedMemory/CompactedMessage 类型定义
- 添加 COMPACTION_SUMMARY 消息类型
- 实现压缩数据存储到 conversation.json
- 实现从 conversation.json 构建恢复数据
- 发送请求时附带 knowledgeData 用于恢复知识图谱
This commit is contained in:
XiaoFeng
2025-12-31 09:35:20 +08:00
parent 023fdb66c3
commit 16e91bd2c0
6 changed files with 335 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import type {
AgentCompleteEvent,
AgentErrorEvent
} from '../types/api';
import type { MemoryCompactedEvent } from '../types/memory';
/**
* SSE 事件回调接口
@ -68,6 +69,8 @@ export interface SSECallbacks {
onAgentComplete?: (data: AgentCompleteEvent) => void;
/** 子智能体错误 */
onAgentError?: (data: AgentErrorEvent) => void;
/** 记忆压缩完成 */
onMemoryCompacted?: (data: MemoryCompactedEvent) => void;
/** 连接打开 */
onOpen?: () => void;
/** 连接关闭 */
@ -319,6 +322,9 @@ function dispatchEvent(
case 'agent_error':
callbacks.onAgentError?.(data as AgentErrorEvent);
break;
case 'memory_compacted':
callbacks.onMemoryCompacted?.(data as MemoryCompactedEvent);
break;
default:
console.log(`[SSE] 未知事件类型: ${eventType}`, data);
}