fix: 记忆去重时明确告知 AI「已存在,不要再重复添加」

之前 addEntry 检测到重复后静默返回已有条目(success),AI 误以为又成功保存了
新条目,于是继续循环调用。现在改为抛出 DuplicateEntryError,tool handler
捕获后返回 {success:true, duplicate:true, message:'已跳过...不要再重复添加'},
明确告诉 AI 任务已完成。

也处理了内存面板的手动添加场景,友好提示用户。
This commit is contained in:
紫影233
2026-06-24 15:31:58 +08:00
parent e39820d19e
commit 5f9acebad1
3 changed files with 34 additions and 7 deletions
+6 -2
View File
@@ -3,7 +3,7 @@
* 基于工作空间 MEMORY.md 文件
*/
import { loadAllEntries, addEntry, removeEntry, type MemoryEntry, type MemoryType } from '../services/memory-service.js';
import { loadAllEntries, addEntry, removeEntry, DuplicateEntryError, type MemoryEntry, type MemoryType } from '../services/memory-service.js';
import { showToast } from './toast.js';
import { showPrompt, showConfirm } from './prompt-modal.js';
import { escapeHtml, formatTime } from '../utils/utils.js';
@@ -170,6 +170,10 @@ async function openAddDialog(): Promise<void> {
await renderList();
showToast('记忆已添加', 'success', 1500);
} catch (err) {
showToast(`添加失败: ${(err as Error).message}`, 'error');
if (err instanceof DuplicateEntryError) {
showToast('该记忆已存在,无需重复添加', 'info', 2000);
} else {
showToast(`添加失败: ${(err as Error).message}`, 'error');
}
}
}