UNPKG

@mastra/core

Version:
67 lines • 3.87 kB
import type { MastraMessageContentV2, MastraMessagePart } from '../agent/message-list/state/types.js'; export declare const WORKING_MEMORY_START_TAG = "<working_memory>"; export declare const WORKING_MEMORY_END_TAG = "</working_memory>"; export declare const SYSTEM_REMINDER_START_TAG = "<system-reminder>"; export declare const SYSTEM_REMINDER_END_TAG = "</system-reminder>"; /** * Tool name used when working memory is delivered via the legacy system-message path. * This is the registry key in `Memory.listTools()` and therefore the `toolName` on the * wire when the LLM calls the tool. */ export declare const UPDATE_WORKING_MEMORY_TOOL_NAME = "updateWorkingMemory"; /** * Tool name used when working memory is delivered via state signals * (`workingMemory.useStateSignals: true`). The rename keeps legacy strip filters * — which look for `updateWorkingMemory` — from incidentally stripping the new * path's tool-call parts, so they persist as a normal audit trail. */ export declare const SET_WORKING_MEMORY_TOOL_NAME = "setWorkingMemory"; /** * All known working-memory tool names. Use this when you want to recognize the * tool regardless of delivery mode (e.g. to skip scoring on WM-only iterations * or detect that working memory was updated). Strip-style filters should NOT * use this — they should keep matching only `UPDATE_WORKING_MEMORY_TOOL_NAME`. */ export declare const WORKING_MEMORY_TOOL_NAMES: readonly ["updateWorkingMemory", "setWorkingMemory"]; export declare function isWorkingMemoryToolName(name: string | undefined | null): boolean; /** * Extracts all working memory tag contents from text using indexOf-based parsing. * This avoids ReDoS vulnerability that exists with regex-based approaches. * @returns Array of full matches (including tags) or null if no matches */ export declare function extractWorkingMemoryTags(text: string): string[] | null; /** * Removes all working memory tags and their contents from text. * Uses indexOf-based parsing to avoid ReDoS vulnerability. */ export declare function removeWorkingMemoryTags(text: string): string; /** * Extracts the content of the first working memory tag (without the tags themselves). * Uses indexOf-based parsing to avoid ReDoS vulnerability. * @returns The content between the tags, or null if no valid tag pair found */ export declare function extractWorkingMemoryContent(text: string): string | null; /** * Removes `updateWorkingMemory` tool invocations from stored message parts, one step * at a time. A step starts at a `step-start` part, or where a tool part is followed by * a non-tool part (the same boundary prompt conversion uses when markers are missing). * A step whose tool calls were all working-memory calls loses its tool-call/tool-result * boundary once they are removed. If only reasoning is left, the whole step is dropped: * replaying that signed reasoning merges it into the next step's assistant message, * which providers such as Anthropic reject (see #22798). */ export declare function removeWorkingMemoryToolInvocationParts(parts: MastraMessagePart[]): MastraMessagePart[]; /** * Removes `updateWorkingMemory` entries from the legacy `toolInvocations` array so * prompt conversion cannot re-add a stripped working-memory call. */ export declare function removeWorkingMemoryToolInvocations(toolInvocations: MastraMessageContentV2['toolInvocations']): MastraMessageContentV2['toolInvocations']; /** * Removes all system-reminder tags and their contents from text. * Uses indexOf-based parsing to avoid ReDoS vulnerability. * * Note: system-reminder tags can have attributes like `<system-reminder type="...">`, * so we match from `<system-reminder` to the closing `>` for the start tag. */ export declare function removeSystemReminderTags(text: string): string; //# sourceMappingURL=working-memory-utils.d.ts.map