UNPKG

zettelkasten-memory-server

Version:

基于 Zettelkasten 记忆片段盒方法的 MCP 记忆服务器 v1.6.X

44 lines 2.12 kB
import { checkLatestContent, resetMemoryAccessCounter, removeLatestContentFetched, markLatestContentFetched } from './utils.js'; /** * 设置记忆片段内容处理器 */ function createSetMemoryHandler(manager) { return async (args) => { try { const { fragmentName, content, conversationId } = args; if (!fragmentName || typeof fragmentName !== 'string') { throw new Error('fragmentName is required and must be a string'); } if (!content || typeof content !== 'string') { throw new Error('content is required and must be a string'); } // 验证 conversationId 参数 if (!conversationId || typeof conversationId !== 'string') { throw new Error('conversationId is required and must be a string'); } await checkLatestContent(manager, fragmentName, conversationId); await manager.setMemory(fragmentName, content); // 编辑后移除已获取最新内容标记,并自动标记为最新内容 removeLatestContentFetched(fragmentName, conversationId); markLatestContentFetched(fragmentName, conversationId); // 重置读取计数器 resetMemoryAccessCounter(fragmentName, conversationId); return { content: [{ type: "text", text: `✅ 记忆片段 "${fragmentName}" 已保存成功\n\n💡 **提示**:内容创建后,可使用 insertLinkAt 工具 再其他记忆片段中插入链接,保持知识网络的连贯性。或者使用 getBacklinks 工具查看反向链接。` }] }; } catch (error) { return { content: [{ type: "text", text: `❌ 保存记忆片段失败: ${error && error.message ? error.message : String(error)}` }] }; } }; } export default createSetMemoryHandler; //# sourceMappingURL=createSetMemoryHandler.js.map