feat: 实现上下文使用量监控和会话压缩功能

- sseHandler: 新增 onContextUsage 回调处理上下文使用量事件
- dialogService: 集成上下文使用量回调,追踪 AI 消息用于后端重启恢复
- apiClient: 新增 compactDialog API 支持手动压缩对话历史
- messageHandler: 新增 lastTaskId 管理机制,支持会话恢复后的压缩操作,转发上下文使用量到 WebView
This commit is contained in:
XiaoFeng
2025-12-31 18:50:20 +08:00
parent 259310a29d
commit b794d1ceb0
4 changed files with 64 additions and 2 deletions

View File

@ -27,7 +27,8 @@ import type {
AgentStartEvent,
AgentProgressEvent,
AgentCompleteEvent,
AgentErrorEvent
AgentErrorEvent,
ContextUsageEvent
} from '../types/api';
import type { MemoryCompactedEvent } from '../types/memory';
@ -71,6 +72,8 @@ export interface SSECallbacks {
onAgentError?: (data: AgentErrorEvent) => void;
/** 记忆压缩完成 */
onMemoryCompacted?: (data: MemoryCompactedEvent) => void;
/** 上下文使用量更新 */
onContextUsage?: (data: ContextUsageEvent) => void;
/** 连接打开 */
onOpen?: () => void;
/** 连接关闭 */
@ -325,6 +328,9 @@ function dispatchEvent(
case 'memory_compacted':
callbacks.onMemoryCompacted?.(data as MemoryCompactedEvent);
break;
case 'context_usage':
callbacks.onContextUsage?.(data as ContextUsageEvent);
break;
default:
console.log(`[SSE] 未知事件类型: ${eventType}`, data);
}