import { Tool } from '../../tool.js'; import { ExecutionContext } from '../../types.js'; import { ExecutionLimits, SandboxExecutionResult } from './types.js'; /** * Resolves a tool name for a guest `callTool`. Implementations must walk the full * transform chain so authorization transforms (e.g. session visibility) still apply * to tools invoked from inside the sandbox. */ export type SandboxToolResolver = (name: string, context?: ExecutionContext) => Promise; export declare class WorkerPool { private readonly poolSize; private readonly toolResolver; /** Respawn attempts tolerated before the pool disables itself. */ private static readonly MAX_CONSECUTIVE_CRASHES; /** Guest scripts longer than this are rejected before they reach a worker. */ private static readonly MAX_SCRIPT_CHARS; private workers; private idleWorkers; private activeTasks; private taskQueue; /** Host-side tool calls still running for a sandbox task. Aborted when that task ends. */ private inflightCalls; /** Calls whose guest is already gone; abort the handler without posting TOOL_RESPONSE. */ private silentCalls; private isDisposed; private consecutiveCrashes; /** Set when the crash ceiling is breached; the pool stops respawning permanently. */ private disabledReason; /** Workers stopped by the watchdog. Their exit is not a crash and must not respawn again. */ private readonly intentionalStop; private readonly resolvedScriptPath; private readonly memoryLimitMb; constructor(poolSize: number | undefined, toolResolver: SandboxToolResolver, workerScriptPath?: string, memoryLimitMb?: number); private resolveWorkerScriptPath; /** * Pre-spawns worker threads up to poolSize. */ initialize(): Promise; /** * Submits a JavaScript script for sandboxed execution in an isolated worker thread. */ executeScript(code: string, limits: ExecutionLimits, context?: ExecutionContext): Promise; private spawnWorker; private handleWorkerMessage; private handleToolRequest; private abortInflight; private dispatchToolRequest; /** * A guest that exhausts the worker heap kills the thread. That is the memory * limit working, not a broken pool: replace the worker once and do not count * it toward the startup-failure latch. */ private handleGuestMemoryLimit; private handleWorkerCrash; private removeWorker; private dispatchNext; /** * Diagnostic pool statistics. */ getStats(): { totalWorkers: number; idleWorkers: number; activeTasks: number; queuedTasks: number; }; /** * Gracefully drains task queue and terminates all worker threads. */ dispose(): Promise; } //# sourceMappingURL=worker-pool.d.ts.map