feat: 全量日志接入 + 日志服务重构(非阻塞)
log-service 重构: - DOM 渲染改用 requestAnimationFrame 批量队列 - 全程 try-catch,任何异常都不阻塞主流程 - 新增 logConnection/logModel/logSession/logMemory/logRAG/logSetting/logIPC/logInit 便捷方法 全量接入(12 个文件): - header.ts: 连接状态变化(connected/disconnected/error) - model-bar.ts: 模型列表加载、模型切换、能力检测结果 - settings-modal.ts: 所有设置变更(系统提示词/上下文/温度/工具调用/命令执行/记忆)、显存释放、导出/导入 - tool-confirm-modal.ts: 工具确认弹窗、确认/取消操作 - memory-manager.ts: 记忆初始化、新增/删除、自动提取 - tool-registry.ts: 工具执行异常 - rag.ts: 文档分块、向量检索 - kb-modal.ts: 知识库创建、文档上传、批量上传 - history-modal.ts: 会话加载、会话删除 - main.ts: 应用初始化各阶段、桌面集成、菜单/托盘操作、新建会话 - input-area.ts: 消息发送、流式完成/错误、文件/图片添加、Agent Loop 错误
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
import { state, KEYS } from '../state/state.js';
|
||||
import { generateId } from '../utils/utils.js';
|
||||
import { logMemory, logDebug, logWarn } from './log-service.js';
|
||||
import type { MemoryEntry, MemorySearchResult, MemoryExtractionResult, ChatDB, OllamaAPI } from '../types.js';
|
||||
|
||||
const TYPE_ICONS: Record<string, string> = {
|
||||
@@ -41,6 +42,7 @@ export async function initMemoryManager(): Promise<void> {
|
||||
state.set('memoryEntries', memoryCache);
|
||||
|
||||
console.log(`[Memory] 初始化完成,加载 ${memoryCache.length} 条记忆`);
|
||||
logMemory(`初始化完成, 加载 ${memoryCache.length} 条`);
|
||||
}
|
||||
|
||||
export function isMemoryEnabled(): boolean {
|
||||
@@ -152,6 +154,7 @@ export async function addMemory(data: {
|
||||
state.set('memoryEntries', [...memoryCache]);
|
||||
|
||||
if (db) await db.saveMemory(entry);
|
||||
logMemory(`新增: ${data.type}`, entry.content.slice(0, 60));
|
||||
|
||||
return entry;
|
||||
}
|
||||
@@ -177,6 +180,7 @@ export async function deleteMemory(id: string): Promise<void> {
|
||||
|
||||
const db = state.get<ChatDB | null>(KEYS.DB);
|
||||
if (db) await db.deleteMemory(id);
|
||||
logMemory(`删除`, id);
|
||||
}
|
||||
|
||||
// ── 清空所有记忆 ──
|
||||
@@ -316,9 +320,11 @@ ${conversationText.slice(0, 4000)}
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count > 0) logMemory(`自动提取 ${count} 条`);
|
||||
return count;
|
||||
} catch (err) {
|
||||
console.warn('[Memory] 自动提取失败:', err);
|
||||
logWarn('记忆自动提取失败', (err as Error).message);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user