/** * Multiline log aggregator for JSON and structured data. * * Detects and aggregates multiline log entries such as JSON objects, * tables, and structured data that span multiple lines. Prevents * timestamp/level repetition on continuation lines. * * @module components/devenv/terminal/parsing/multiline */ import type { IParsedLogEntry, TLogLevel } from './LogParser.types'; /** * Multiline aggregation state. * * Tracks buffer and context while aggregating multiline logs. */ export interface IMultilineState { /** Buffered lines for current multiline entry */ buffer: string[]; /** Parent entry for continuation lines (only line_number is used) */ parentEntry?: { line_number: number; level: TLogLevel; }; /** Whether currently in multiline mode */ isMultiline: boolean; /** Expected closing bracket/brace for current multiline */ expectedClose?: '}' | ']'; /** Current depth of nested braces/brackets */ depth: number; } /** * Multiline log aggregator class. * * Detects and aggregates lines that are part of a multiline JSON * or structured data entry. Marks continuation lines so they don't * get timestamp/level prefixes. * * @example * ```ts * const aggregator = new MultilineAggregator(); * const aggregated = aggregator.aggregate(entries); * // Lines like '{', ' filter: {},', '}' get marked as continuation * ``` */ export declare class MultilineAggregator { /** * Detect if a line is a continuation of multiline JSON/structured data. * * Continuation indicators: * - Line starts with `{` or `[` alone → opens multiline * - Line has indentation + `key: value,` → continuation * - Line is just `}` or `]` → closes multiline * - Line ends with `{` or `[` without match → opens multiline * - When in multiline mode: lines ending with comma or containing key-value patterns * * @param line - Line to check * @param state - Current multiline state * @returns true if line is a continuation */ detectContinuation(line: string, state: IMultilineState): boolean; /** * Aggregate entries, marking continuation lines. * * Processes entries and marks lines that are continuations * of a previous multiline entry. Handles: * - JSON/structured data blocks * - Table borders (box-drawing characters) * - Indented continuation lines * * @param entries - Parsed log entries to aggregate * @param initialState - Optional initial multiline state (for persistence across chunks) * @returns Entries with continuation marking and new multiline state */ aggregate(entries: IParsedLogEntry[], initialState?: IMultilineState): { entries: IParsedLogEntry[]; state: IMultilineState; }; /** * Check if a line opens a multiline block. * * @param trimmed - Trimmed line to check * @returns true if line opens multiline * @private */ private opensMultiline; /** * Check if a line is an opening brace/bracket. * * @param trimmed - Trimmed line to check * @returns true if line contains opening brace/bracket * @private */ private isOpeningBrace; /** * Check if a line is a closing brace/bracket for expected type. * * @param trimmed - Trimmed line to check * @param expected - Expected close type * @returns true if line closes the multiline block * @private */ private isClosingBrace; /** * Get the expected closing character for a line. * * @param trimmed - Trimmed line to check * @returns Expected closing character or undefined * @private */ private getExpectedClose; /** * Count opening braces/brackets in a line. * * @param trimmed - Trimmed line to check * @returns Count of opening braces/brackets * @private */ private countOpeningBraces; /** * Check if a line is a table line (contains box-drawing characters). * * @param trimmed - Trimmed line to check * @returns true if line contains table borders * @private */ private isTableLine; /** * Check if a line looks like a new log entry (not a continuation). * * New entries typically start with: * - Timestamp followed by log level * - HTTP method followed by path * - Component/module tag * * @param trimmed - Trimmed line to check * @returns true if line looks like a new entry * @private */ private looksLikeNewEntry; /** * Check if a trimmed line is a JSON/structured data continuation. * * This handles lines that have their own timestamp/level metadata * but are actually continuations of a multiline JSON block. * * Examples: * - `container: "name",` - ends with comma * - `tail: 100,` - ends with comma * - `key: "value"` - key-value pattern * - `}` - closing brace * - Lines with pipe characters (table rows) * * @param trimmed - Trimmed line to check * @returns true if line is a JSON continuation * @private */ private isJsonContinuation; /** * Check if a line looks like a continuation line (indented content). * * @param line - Line to check (not trimmed, to check indentation) * @returns true if line appears to be a continuation * @private */ private isContinuationLine; /** * Create initial multiline state. * * @returns Fresh multiline state */ createInitialState(): IMultilineState; } //# sourceMappingURL=MultilineAggregator.d.ts.map