{"version":3,"file":"index.mjs","sources":["../../../../src/tools/memory/index.ts"],"sourcesContent":["/**\n * Public entry for the memory tool family.\n *\n * `buildMemoryTools` is the one function host calls. It returns an array\n * of LangChain tools with scope captured in a closure — the LLM cannot\n * override the `(agentId, userId)` pair through any tool argument.\n *\n * Phase 2: accepts independent `readEnabled` / `writeEnabled` flags that\n * mirror host's existing `agent.memory_read_enabled` /\n * `agent.memory_write_enabled` fields. Either flag can be set without the\n * other: a read-only agent can consult memory without mutating it; a\n * write-only agent can reflect without reading.\n */\nimport type { StructuredToolInterface } from '@langchain/core/tools';\nimport type { MemoryConfig, MemoryPhase } from '@/memory/types';\nimport { createMemorySearchTool } from './memorySearchTool';\nimport { createMemoryGetTool } from './memoryGetTool';\nimport { createMemoryAppendTool } from './memoryAppendTool';\nimport type { MemoryToolBinding } from './shared';\n\nexport * from './shared';\nexport { createMemorySearchTool } from './memorySearchTool';\nexport { createMemoryGetTool } from './memoryGetTool';\nexport { createMemoryAppendTool } from './memoryAppendTool';\n\nexport interface BuildMemoryToolsOptions extends MemoryConfig {\n  /**\n   * Attach `memory_search` + `memory_get`. Maps to\n   * `agent.memory_read_enabled` on the host Agent document.\n   */\n  readEnabled?: boolean;\n  /**\n   * Attach `memory_append` (still phase-gated to `memory_flushing`).\n   * Maps to `agent.memory_write_enabled` on the host Agent document.\n   */\n  writeEnabled?: boolean;\n  /**\n   * @deprecated — legacy Phase 1 flag. When set, equivalent to\n   * `{ readEnabled: true, writeEnabled: false }`. Kept so existing tests\n   * don't break during the Phase 1→2 transition. New callers should pass\n   * `readEnabled`/`writeEnabled` explicitly.\n   */\n  readOnly?: boolean;\n}\n\nexport function buildMemoryTools(\n  options: BuildMemoryToolsOptions\n): StructuredToolInterface[] {\n  // Back-compat for the Phase 1 readOnly flag — maps to read-only mode.\n  let readEnabled = options.readEnabled;\n  let writeEnabled = options.writeEnabled;\n  if (options.readOnly) {\n    readEnabled = true;\n    writeEnabled = false;\n  }\n  // Default: if neither flag supplied, attach both (back-compat with the\n  // pre-Phase-2 single-flag caller).\n  if (readEnabled === undefined && writeEnabled === undefined) {\n    readEnabled = true;\n    writeEnabled = true;\n  }\n\n  const binding: MemoryToolBinding = {\n    backend: options.backend,\n    scope: options.scope,\n    maxInjectedChars: options.search?.maxInjectedChars,\n    searchOptions: {\n      mmr: options.search?.mmr,\n      temporalDecay: options.search?.temporalDecay,\n      citations: options.search?.citations,\n    },\n    recallTracker: options.recallTracker,\n  };\n\n  const tools: StructuredToolInterface[] = [];\n\n  if (readEnabled) {\n    tools.push(\n      createMemorySearchTool(binding) as unknown as StructuredToolInterface,\n      createMemoryGetTool(binding) as unknown as StructuredToolInterface\n    );\n  }\n\n  if (writeEnabled) {\n    const getPhase: () => MemoryPhase =\n      options.getPhase ?? ((): MemoryPhase => 'normal');\n    tools.push(\n      createMemoryAppendTool({\n        ...binding,\n        getPhase,\n      }) as unknown as StructuredToolInterface\n    );\n  }\n\n  return tools;\n}\n"],"names":[],"mappings":";;;;;AA6CM,SAAU,gBAAgB,CAC9B,OAAgC,EAAA;;AAGhC,IAAA,IAAI,WAAW,GAAG,OAAO,CAAC,WAAW;AACrC,IAAA,IAAI,YAAY,GAAG,OAAO,CAAC,YAAY;AACvC,IAAA,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,WAAW,GAAG,IAAI;QAClB,YAAY,GAAG,KAAK;IACtB;;;IAGA,IAAI,WAAW,KAAK,SAAS,IAAI,YAAY,KAAK,SAAS,EAAE;QAC3D,WAAW,GAAG,IAAI;QAClB,YAAY,GAAG,IAAI;IACrB;AAEA,IAAA,MAAM,OAAO,GAAsB;QACjC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;AACpB,QAAA,gBAAgB,EAAE,OAAO,CAAC,MAAM,EAAE,gBAAgB;AAClD,QAAA,aAAa,EAAE;AACb,YAAA,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG;AACxB,YAAA,aAAa,EAAE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