UNPKG

zettelkasten-memory-server

Version:

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

53 lines 2.49 kB
import { checkLatestContent, resetMemoryAccessCounter, removeLatestContentFetched, markLatestContentFetched } from './utils.js'; /** * 内容提取处理器 - 支持精确范围定位 */ function createExtractMemoryHandler(manager) { return async (args) => { try { const { from, to, range, conversationId } = args; if (!from || typeof from !== 'string') { throw new Error('from is required and must be a string'); } if (!to || typeof to !== 'string') { throw new Error('to is required and must be a string'); } if (!range) { throw new Error('range is required. Use start and/or end properties to specify extraction range.'); } // 验证 conversationId 参数 if (!conversationId || typeof conversationId !== 'string') { throw new Error('conversationId is required and must be a string'); } try { await checkLatestContent(manager, from, conversationId); } catch (e) { throw new Error(`为保证内容一致性,请先使用 getMemory 获取 "${from}" 的最新内容后再提取。`); } await manager.extractMemory(from, to, range); // 编辑后移除已获取最新内容标记(源文件),并自动标记目标文件为最新内容 removeLatestContentFetched(from, conversationId); markLatestContentFetched(to, conversationId); // 重置读取计数器 resetMemoryAccessCounter(from, conversationId); resetMemoryAccessCounter(to, conversationId); return { content: [{ type: "text", text: `✅ **内容提取成功**\n\n从记忆片段 [[${from}]] 中提取内容到 [[${to}]],并在原位置替换为链接。` }] }; } catch (error) { return { content: [{ type: "text", text: `❌ 内容提取失败: ${error && error.message ? error.message : String(error)}\n\n💡 **提示**:请检查范围参数格式,支持 start/end 属性配合 line 和 regex 使用。` }] }; } }; } export default createExtractMemoryHandler; //# sourceMappingURL=createExtractMemoryHandler.js.map