/** * Recursive sub-call handler for RLM queries. * Feature #5: Recursive Sub-Call Handler (MCP Spec 2025-11-25) * * Processes filtered results from RLM queries using MCP Sampling with Tools. * Enables server-side agent loops for recursive LLM processing. */ import { type SamplingClient, type ToolDefinition, type ToolCallResult } from './sampling.js'; /** * Context for sub-call processing, tracking depth and parent information. */ export interface SubCallContext { /** Current recursion depth */ depth: number; /** Maximum allowed depth */ maxDepth: number; /** Parent document path (optional) */ parentPath?: string; /** MCP Task ID for long-running operations (optional, SEP-1686) */ taskId?: string; } /** * Request for a single sub-call. */ export interface SubCallRequest { /** Item from code result to process */ item: unknown; /** Prompt for sub_query */ prompt: string; /** Sub-call context */ context: SubCallContext; } /** * Result of a single sub-call. */ export interface SubCallResult { /** Whether the sub-call succeeded */ success: boolean; /** LLM text output (if successful) */ result?: string; /** Error message (if failed) */ error?: string; /** Index in the original items array */ index: number; /** Tool calls made during sampling (if any) */ toolCalls?: ToolCallResult[]; } /** * Options for recursive sub-call processing. */ export interface RecursionOptions { /** Maximum recursion depth (default: 1) */ maxDepth?: number; /** Maximum concurrent sub-calls (default: 5) */ concurrency?: number; /** Per-call timeout in milliseconds */ timeout?: number; /** Tools available during sampling (SEP-1577) */ tools?: ToolDefinition[]; /** Return Task handle for long operations (SEP-1686, optional) */ useTask?: boolean; /** Sampling client (optional, for testing/mocking) */ samplingClient?: SamplingClient; } /** * Check if depth limit is exceeded and throw if so. * * @param context - Sub-call context * @throws DepthLimitError if depth exceeds maxDepth */ export declare function checkDepthLimit(context: SubCallContext): void; /** * Process sub-calls for items returned from RLM query code execution. * * This function: * 1. Normalizes items to an array (handles single item) * 2. Checks depth limit * 3. Processes items in parallel with concurrency control * 4. For each item, creates a sampling message with the prompt * 5. Captures results and tool calls * 6. Returns aggregated results in input order * * @param items - Items from code result (array or single item) * @param prompt - Sub_query prompt to apply to each item * @param options - Recursion options * @returns Array of sub-call results in input order * * @example * const results = await processSubCalls( * ['item1', 'item2', 'item3'], * 'Summarize each item', * { maxDepth: 1, concurrency: 5 } * ); */ export declare function processSubCalls(items: unknown[] | unknown, prompt: string, options?: RecursionOptions): Promise; //# sourceMappingURL=recursion.d.ts.map