/** * Protocol Utilities * * Utility functions for parsing stream-json protocol messages. * * @module agents/claude/protocol/utils */ import type { Readable } from 'stream'; import type { ClaudeStreamMessage } from '../types/messages.js'; /** * Parse a single line of stream-json into a ClaudeStreamMessage * * @param line - JSON string to parse * @returns Parsed message or null if invalid * * @example * ```typescript * const msg = parseStreamJsonLine('{"type":"system","sessionId":"sess-123"}'); * if (msg?.type === 'system') { * console.log('Session:', msg.sessionId); * } * ``` */ export declare function parseStreamJsonLine(line: string): ClaudeStreamMessage | null; /** * Create an async generator that yields messages from a readable stream * * Reads newline-delimited JSON from the stream and yields parsed messages. * Handles partial lines and buffering. * * @param stream - Readable stream (e.g., process.stdout) * @yields Parsed ClaudeStreamMessage objects * * @example * ```typescript * for await (const message of readStreamJson(process.stdout)) { * if (message.type === 'assistant') { * console.log('Assistant:', message.message.content); * } * } * ``` */ export declare function readStreamJson(stream: Readable): AsyncGenerator; /** * Serialize a message to stream-json format (newline-terminated JSON) * * @param message - Message object to serialize * @returns JSON string with trailing newline * * @example * ```typescript * const json = serializeStreamJson({ type: 'control_response', response: {...} }); * process.stdin.write(json); * ``` */ export declare function serializeStreamJson(message: unknown): string; //# sourceMappingURL=utils.d.ts.map