@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
48 lines • 2.34 kB
TypeScript
/** Default number of lines to return (tail). */
export declare const DEFAULT_TAIL_LINES = 200;
/** Default estimated token limit for tool output. Safety net on top of line-based tail. */
export declare const DEFAULT_MAX_OUTPUT_TOKENS = 2000;
export declare function stripAnsi(text: string): string;
/**
* `toModelOutput` handler for sandbox tools.
* Strips ANSI escape codes so the model sees clean text, while the raw
* output (with colors) is preserved in the stream/TUI.
*
* Returns `{ type: 'text', value: '...' }` to match the AI SDK's
* expected tool-result output format.
*/
export declare function sandboxToModelOutput(output: unknown): unknown;
/**
* Return the last N lines of output, similar to `tail -n`.
* - `n > 0`: last N lines
* - `n === 0`: no limit (return all)
* - `undefined/null`: use DEFAULT_TAIL_LINES
*/
export declare function applyTail(output: string, tail: number | null | undefined): string;
/**
* Token-based output limit. Truncates output to fit within a token budget.
* Uses tokenx for fast token estimation and truncates at the token level
* (not line boundaries) to maximise use of the budget.
*
* @param output - The text to truncate
* @param limit - Maximum tokens (default: DEFAULT_MAX_OUTPUT_TOKENS)
* @param from - Which end to truncate from:
* - `'start'` (default): Remove tokens from the start, keep the end
* - `'end'`: Remove tokens from the end, keep the start
*/
export declare function applyTokenLimit(output: string, limit?: number, from?: 'start' | 'end'): Promise<string>;
/**
* Head+tail sandwich truncation. Keeps lines from both the start and end
* of the output, with a truncation notice in the middle.
* Uses tokenx for fast token estimation.
*
* @param output - The text to truncate
* @param limit - Maximum tokens (default: DEFAULT_MAX_OUTPUT_TOKENS)
* @param headRatio - Fraction of the token budget to allocate to the head (default: 0.1 = 10%)
*/
export declare function applyTokenLimitSandwich(output: string, limit?: number, headRatio?: number): Promise<string>;
/**
* Apply both tail (line-based) and token limit (safety net) to output.
*/
export declare function truncateOutput(output: string, tail?: number | null, tokenLimit?: number, tokenFrom?: 'start' | 'end' | 'sandwich'): Promise<string>;
//# sourceMappingURL=output-helpers.d.ts.map