/** * EgressGuard — Payload Size Limiter (FinOps + OOM Shield) * * Prevents oversized tool responses from: * 1. Crashing the Node process with OOM (JSON.stringify of 30MB) * 2. Overflowing the LLM context window ($15 per wasted request) * 3. Saturating the transport layer * * This is a **brute-force safety net** — the last line of defense. * Presenter `.agentLimit()` is the domain-aware guard; this is the * byte-level guard for when `.agentLimit()` is not configured. * * Architecture: * ┌──────────────────────────────────────────────┐ * │ ToolResponse from handler/Presenter │ * │ │ * │ ┌──────────┐ within limit? ┌───────────┐ │ * │ │ measure ├────YES────────►│ pass-thru │ │ * │ │ bytes │ └───────────┘ │ * │ │ │ exceeds? ┌───────────┐ │ * │ │ ├────YES────────►│ truncate │ │ * │ └──────────┘ │ + inject │ │ * │ │ guidance │ │ * │ └───────────┘ │ * └──────────────────────────────────────────────┘ * * Properties: * - Zero overhead when not configured (guard returns input directly) * - Measures byte length via Buffer.byteLength (UTF-8 accurate) * - Truncates at the text level, preserving valid ToolResponse shape * - Injects system intervention message for LLM self-correction * * @module * @internal */ import { type ToolResponse } from '../response.js'; /** * Egress guard configuration. * * @example * ```typescript * registry.attachToServer(server, { * contextFactory: createContext, * maxPayloadBytes: 2 * 1024 * 1024, // 2MB safety net * }); * ``` */ export interface EgressConfig { /** * Maximum total payload size in bytes. * When a response exceeds this limit, the text content is * truncated and a system intervention message is appended. * * @minimum 1024 (1KB minimum to avoid unusable responses) */ readonly maxPayloadBytes: number; } /** * Apply egress guard to a ToolResponse. * * Measures the total byte length of all text content blocks. * If the total exceeds `maxPayloadBytes`, truncates the LAST * text block and appends a system intervention message. * * @param response - The ToolResponse to guard * @param maxPayloadBytes - Maximum allowed bytes * @returns The original response (if within limit) or a truncated copy * * @internal */ export declare function applyEgressGuard(response: ToolResponse, maxPayloadBytes: number): ToolResponse; //# sourceMappingURL=EgressGuard.d.ts.map