/** * Control message helpers for the bidirectional control protocol. * * The SDK and CLI communicate control messages over stdin/stdout using * a request/response pattern. Each request carries a unique `request_id` * which the response echoes back, allowing the SDK to match responses * to their originating requests. * * This module provides: * - Factory functions for creating control request/response envelopes * - Type guards for identifying message types in the readMessages loop * - A random ID generator for request correlation */ import type { SDKControlRequest, SDKControlResponse, SDKControlCancelRequest, SDKControlRequestInner } from '../types/control.js'; /** * Generate a random request ID for control messages. * * Uses Math.random() base-36 encoding to produce a short, unique * identifier. This is sufficient for request correlation within a * single session — collisions are astronomically unlikely given the * short lifetime of pending requests. */ export declare function generateRequestId(): string; /** * Create a control request envelope. * * Wraps an inner request payload in the standard envelope format * expected by the CLI. * * @param requestId - Unique identifier for correlating the response * @param request - The inner request payload (e.g., `{ type: 'interrupt' }`) */ export declare function createControlRequest(requestId: string, request: SDKControlRequestInner): SDKControlRequest; /** * Create a success control response. * * Used when the SDK has successfully handled a control request from the CLI * (e.g., a permission prompt or hook callback). * * @param requestId - The request_id from the originating control request * @param data - Optional response data to include */ export declare function createControlResponse(requestId: string, data?: unknown): SDKControlResponse; /** * Create an error control response. * * Used when the SDK encounters an error while handling a control request * from the CLI. * * @param requestId - The request_id from the originating control request * @param error - Human-readable error description * @param code - Optional machine-readable error code */ export declare function createControlErrorResponse(requestId: string, error: string, code?: string): SDKControlResponse; export declare function isControlResponse(msg: unknown): msg is SDKControlResponse; export declare function isControlRequest(msg: unknown): msg is SDKControlRequest; export declare function isControlCancelRequest(msg: unknown): msg is SDKControlCancelRequest; /** * Extract the control request subtype used for wire-format dispatch. * Supports both `subtype` (baseline) and `type` (older Qoder codepaths). */ export declare function getControlRequestSubtype(request: SDKControlRequest['request']): string | undefined; export declare function isKeepAlive(msg: unknown): boolean; export declare function isStreamlinedText(msg: unknown): boolean; export declare function isStreamlinedToolUseSummary(msg: unknown): boolean; export declare function isPostTurnSummary(msg: unknown): boolean; export declare function isResultMessage(msg: unknown): boolean;