/** * The LLM-facing `memory_block` tool. * * Single tool with an `action` discriminator (view/add/replace/remove) — * keeps the model's tool schema simple, matches the AI SDK docs example * pattern and Hermes's design. View is required even for read because * persistent blocks are NOT in the prompt (the FROZEN snapshot is); the * tool gives the agent a way to read its OWN latest writes mid-session. * * Char-limit + safety scanning are enforced here at the tool layer, so * the store stays a dumb persistence adapter and a future seed-script * or admin write can bypass them when intentional. */ import { z } from 'zod'; import type { AiSdkTool } from '../../tools/Tool.js'; import { type PersistentMemoryStore, type MemoryBlockScope } from './types.js'; import type { WorkingMemoryBlockSpec } from '../../types/grounding.js'; export interface MemoryBlockToolOptions { store: PersistentMemoryStore; /** * The blocks this agent declares. The model can address these and nothing * else — the tool's `block` argument is an enum built from this list, so an * undeclared name is not rejected at runtime, it cannot be expressed. * * Previously `block` was `z.string().min(1).max(64)` with a free-text * `scope`, which let the model create and overwrite arbitrary blocks in any * scope. Nothing consumed those: `loadWorkingMemoryBlocks` only injects * declared keys, so an ad-hoc block was never visible in a later session — * the model could create it and never find it again. */ blocks: WorkingMemoryBlockSpec[]; /** Owner for a scope, or `undefined` when this session has none (no userId). * There is deliberately no placeholder — see `resolveWorkingMemoryOwner`. */ resolveOwner: (scope: MemoryBlockScope) => string | undefined; /** Per-block char limit (default 10,000). */ charLimit?: number; /** When false, skip the prompt-injection scanner (NOT recommended). */ scanForInjection?: boolean; } declare function buildInputSchema(blockKeys: [string, ...string[]]): z.ZodObject<{ action: z.ZodEnum<{ replace: "replace"; view: "view"; add: "add"; remove: "remove"; }>; block: z.ZodEnum<{ [x: string]: string; }>; content: z.ZodOptional; match: z.ZodOptional; }, z.core.$strip>; type Input = z.infer>; export declare function buildMemoryBlockTool(opts: MemoryBlockToolOptions): AiSdkTool; export {};