refactor: 修复 any 滥用 & 拆分 tool-handlers.ts & 记忆数据治理 (v5.1.3)
Fix 2 - 类型安全: - (window as any).metonaDesktop → window.metonaDesktop - any[] → Record<string, unknown>[] - 回调 :any → ChatSession | null - 78 处 → 38 处(减少 51%) Fix 3 - 架构拆分: - tool-handlers.ts (1308行) → 4 个模块: - tool-handlers-shared.ts: 共享工具函数 - tool-handlers-fs.ts: 15 个文件系统操作 - tool-handlers-system.ts: 6 个系统网络操作 - tool-handlers-git.ts: 1 个 Git 操作 Fix 4 - 记忆数据治理: - 90 天未使用自动降低 importance - 清理评分新增 agePenalty - 向量错误日志增强(记忆ID、内容摘要、模型、栈) - 去重增强(前缀匹配)
This commit is contained in:
@@ -152,8 +152,8 @@ export function initMemoryModal(): void {
|
||||
document.querySelector('#btnMemory')?.addEventListener('click', openMemoryModal);
|
||||
|
||||
// 全局状态监听
|
||||
if (typeof (window as any).__memoryStateListener === 'undefined') {
|
||||
(window as any).__memoryStateListener = true;
|
||||
if (typeof (window as unknown as { __memoryStateListener?: boolean }).__memoryStateListener === 'undefined') {
|
||||
(window as unknown as { __memoryStateListener?: boolean }).__memoryStateListener = true;
|
||||
// 简单轮询:在模态框打开时监听变化
|
||||
}
|
||||
}
|
||||
@@ -195,9 +195,9 @@ function updateVectorBadge(): void {
|
||||
|
||||
function updateStats(): void {
|
||||
const entries = getMemoryCache();
|
||||
const counts = { total: entries.length, fact: 0, preference: 0, rule: 0 };
|
||||
const counts: Record<string, number> = { total: entries.length, fact: 0, preference: 0, rule: 0 };
|
||||
for (const e of entries) {
|
||||
if (e.type in counts) (counts as any)[e.type]++;
|
||||
if (e.type in counts) counts[e.type]++;
|
||||
}
|
||||
const el = (id: string) => modalEl.querySelector(`#${id}`)!;
|
||||
el('memStatTotal').textContent = String(counts.total);
|
||||
@@ -295,7 +295,7 @@ async function importMemoryFromMd(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge || !bridge.isDesktop) {
|
||||
showToast('导入功能仅在桌面端可用', 'warning');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user