utils/tool_result/tool_result_storage library

Utility for persisting large tool results to disk instead of truncating them.

Ported from neomage/src/utils/toolResultStorage.ts (1040 LOC).

Manages tool result persistence, content replacement budgets, and per-message aggregate enforcement to keep prompt sizes manageable.

Classes

ContentReplacementRecord
Serializable record of one content-replacement decision. Written to the transcript for resume reconstruction.
ContentReplacementState
Per-conversation-thread state for the aggregate tool result budget.
ImageContentBlock
An image content block within a tool result.
Message
Simplified message representation for budget enforcement.
MessageContent
Simplified message content.
PersistedToolResult
Result of persisting a tool result to disk.
PersistToolResultError
Error result when persistence fails.
TextContentBlock
A text content block within a tool result.
ToolResultBlock
Simplified representation of a tool result content block.
ToolResultStorage
Manages tool result persistence and content replacement budgets.

Constants

bytesPerToken → const int
Approximate bytes per token for size estimation.
defaultMaxResultSizeChars → const int
Default maximum result size in characters.
maxToolResultBytes → const int
Maximum tool result bytes (global limit).
maxToolResultsPerMessageChars → const int
Maximum tool results per message in characters.
persistedOutputClosingTag → const String
persistedOutputTag → const String
XML tag used to wrap persisted output messages.
previewSizeBytes → const int
Preview size in bytes for the reference message.
toolResultClearedMessage → const String
Message used when tool result content was cleared without persisting to file.
toolResultsSubdir → const String
Subdirectory name for tool results within a session.

Functions

cloneContentReplacementState(ContentReplacementState source) ContentReplacementState
Clone replacement state for a cache-sharing fork.
createContentReplacementState() ContentReplacementState
Create a fresh content replacement state.