/** * @fileoverview Transport-agnostic batch and stream execution * * `executeBatch()` and `executeStream()` hold the batch and stream semantics in * one place: request preflight, the batch deadline, bounded parallelism, * `stopOnError`, abort handling and error redaction. Like `executePipeline()`, * they take a `CommandExecutor` callback, so every host (the core registry, the * MCP server engine, DirectClient, test harnesses) can delegate to the same code * instead of keeping its own copy. * * Every entry is executed through the callback with the caller's context * (including `interface`), so the host's exposure, context and validation * checks apply to each batch entry and to streams exactly as they do to a * single call. */ import type { BatchRequest, BatchResult } from './batch.js'; import { createFailedBatchResult } from './batch.js'; import type { CommandContext } from './commands.js'; import type { CommandError } from './errors.js'; import type { CommandExecutor } from './pipeline-executor.js'; import type { CommandResult } from './result.js'; import type { StreamChunk } from './streaming.js'; /** * Options shared by the core executors. */ export interface ExecutorOptions { /** * Include raw exception messages and stack traces in results. * * Default `false`: a thrown exception becomes a generic * `COMMAND_EXECUTION_ERROR` (or `STREAM_ERROR`) so internal details such as * file paths never reach a remote caller. Matches `devMode` in * `createMcpServer()`. */ devMode?: boolean; } /** * Convert an exception thrown while executing a command into a failure result. * * Outside `devMode` the result carries no exception text or stack. * * @param error - The thrown value * @param devMode - Whether to include the raw message and stack */ export declare function executionFailure(error: unknown, devMode?: boolean): CommandResult; /** Canonical malformed batch result, shared by executor and transport preflight. */ export declare function failedBatchRequest(timing?: Parameters[1], details?: CommandError['details'], suggestion?: string): BatchResult; /** * Execute a batch of commands with partial success semantics. * * - The whole envelope is validated with `isBatchRequest()` before any command * runs; a malformed or empty batch returns `INVALID_BATCH_REQUEST`. * - `options.timeout` is a deadline for the whole batch, whatever the * `parallelism`: each in-flight command's `signal` is aborted and its result * becomes `BATCH_TIMEOUT` when the deadline passes, and commands not yet * started are reported as `BATCH_TIMEOUT` without running. * - With `stopOnError`, commands not yet started after a failure are reported * as `COMMAND_SKIPPED`. Already-started handlers preserve their actual results. * - Caller cancellation stops scheduling queued commands (`COMMAND_CANCELLED`) * while started handlers receive the signal and finish cooperatively. * - Each command runs through `execute` with the caller's `context` (so * `interface` reaches the host's exposure check), a per-command `traceId`, * and a `signal` that aborts on the deadline or with the caller's signal. * * @param request - The batch request (validated at runtime) * @param execute - Callback that executes a single command * @param context - Context passed to every command * @param options - Executor options such as `devMode` * @returns The aggregated batch result, one entry per requested command * * @example * ```typescript * const result = await executeBatch(request, (name, input, ctx) => registry.execute(name, input, ctx), { * interface: 'mcp', * }); * ``` */ export declare function executeBatch(request: BatchRequest, execute: CommandExecutor, context?: CommandContext, options?: ExecutorOptions): Promise; /** * Options for {@link executeStream}. */ export interface StreamExecutorOptions extends ExecutorOptions { /** * Deadline for the whole stream in milliseconds, a nonnegative finite * number. When it passes, the command's `signal` aborts and the stream ends * with a `STREAM_TIMEOUT` error chunk, even if the command ignores the * signal. Default: no deadline. */ timeout?: number; } /** * Execute a command and stream its result. * * This is not incremental streaming: the command runs once, to completion, * through `execute` with `context` (so `interface` reaches the host's exposure * check), and the chunks are produced from its final result afterwards. An * array result is emitted as one data chunk per item, any other result as a * single data chunk, followed by a complete chunk; no progress chunks are * emitted. A failure result becomes an error chunk. `context.signal` cancels * the stream: an aborted signal yields a `STREAM_ABORTED` error chunk before * execution, after it, or between data chunks. With `options.timeout`, the * stream ends with a `STREAM_TIMEOUT` error chunk once the deadline passes. * * @param commandName - Command to execute * @param input - Command input * @param execute - Callback that executes a single command * @param context - Context passed to the command; `signal` cancels the stream * @param options - Executor options such as `devMode` and `timeout` */ export declare function executeStream(commandName: string, input: unknown, execute: CommandExecutor, context?: CommandContext, options?: StreamExecutorOptions): AsyncGenerator, void, unknown>; //# sourceMappingURL=command-execution.d.ts.map