/** * Runs tool calls with a time limit and cancellation. The worker executor * isolates the CPU-bound PlantUML pipeline on a worker thread, so a timeout or * a cancelled request really stops the work (the thread is terminated) and an * out-of-memory crash does not take the server down. The inline executor runs * in the calling thread and can only give up waiting; it is meant for tests * and embedding. * @module mcp/executor */ export type ExecutorFailure = "timeout" | "aborted" | "busy" | "crashed" | "closed"; /** * Why a run did not produce a result. * @typedef {"timeout" | "aborted" | "busy" | "crashed" | "closed"} ExecutorFailure */ /** Failure of an executor run (as opposed to a tool error, which is a result). */ export declare class ExecutorError extends Error { reason: ExecutorFailure; /** * @param {ExecutorFailure} reason */ constructor(reason: ExecutorFailure); } export type RunOptions = { /** * Abort the run (request cancelled). */ signal?: AbortSignal; /** * Time limit for the run itself. */ timeoutMs: number; }; export type Executor = { run: (tool: string, args: unknown, options: RunOptions) => Promise; /** * Pre-load the layout engine where the * tools run, in the background. Resolves with whether the engine is loaded * afterwards (never rejects). Calls are idempotent and a tool call never has * to wait for it. */ warmup?: () => Promise; close: () => Promise; }; /** * @typedef {object} RunOptions * @property {AbortSignal} [signal] Abort the run (request cancelled). * @property {number} timeoutMs Time limit for the run itself. */ /** * @typedef {object} Executor * @property {(tool: string, args: unknown, options: RunOptions) => Promise} run * @property {() => Promise} [warmup] Pre-load the layout engine where the * tools run, in the background. Resolves with whether the engine is loaded * afterwards (never rejects). Calls are idempotent and a tool call never has * to wait for it. * @property {() => Promise} close */ /** * @param {import("./tools.mjs").ToolEnv} env * @param {(message: string) => void} log * @returns {Executor} */ export declare function createInlineExecutor(env: import("./tools.mjs").ToolEnv, log: (message: string) => void): Executor; export type WorkerExecutorOptions = { /** * Pending calls beyond the running one before `busy` (default 16). */ maxQueue?: number; /** * Heap limit of the worker thread (default 768). */ maxMemoryMb?: number; /** * Worker entry point (default `./worker.mjs`); for tests. */ workerUrl?: URL; }; /** * @typedef {object} WorkerExecutorOptions * @property {number} [maxQueue] Pending calls beyond the running one before `busy` (default 16). * @property {number} [maxMemoryMb] Heap limit of the worker thread (default 768). * @property {URL} [workerUrl] Worker entry point (default `./worker.mjs`); for tests. */ /** * Executor backed by one lazily started worker thread. Calls run one at a * time; a timeout or cancellation terminates the thread and the next call * starts a fresh one. After `warmup()` was called, every worker (also a * restarted one) pre-loads the layout engine in the background, concurrently * with the first calls: a call never waits for it. * @param {import("./tools.mjs").ToolEnv} env * @param {(message: string) => void} log * @param {WorkerExecutorOptions} [options] * @returns {Executor} */ export declare function createWorkerExecutor(env: import("./tools.mjs").ToolEnv, log: (message: string) => void, options?: WorkerExecutorOptions): Executor;