UNPKG

mcard-js

Version:

MCard - Content-addressable storage with cryptographic hashing, handle resolution, and vector search for Node.js and browsers

79 lines 2.26 kB
/** * SandboxWorker - Execute code in isolated Web Worker * * Provides safe execution environment for PCard logic. * Supports multiple runtimes: * - JavaScript: Native execution via Function() * - Python: Execution via Pyodide (WebAssembly Python) * * @see https://pyodide.org/en/stable/ */ /** Supported runtime types */ export type RuntimeType = 'javascript' | 'python' | 'js' | 'py'; /** * SandboxWorker - Manages Web Worker for isolated execution * * Supports multiple runtimes: * - javascript/js: Native JS execution * - python/py: Python via Pyodide (WebAssembly) */ export declare class SandboxWorker { private worker; private pythonLoaded; private pendingRequests; private defaultTimeout; /** * Initialize the sandbox worker */ init(): Promise<void>; private requestCounter; /** * Execute code in sandbox * @param code - Code to execute * @param input - Input data for the code * @param context - Optional execution context * @param runtime - Runtime to use: 'javascript' (default) or 'python' */ execute(code: string, input: unknown, context?: Record<string, unknown>, runtime?: RuntimeType): Promise<unknown>; /** * Preload a runtime for faster first execution * Useful for Python which requires loading Pyodide (~10MB) * @param runtime - Runtime to preload: 'python' or 'javascript' */ preloadRuntime(runtime?: RuntimeType): Promise<{ loaded: boolean; runtime: string; }>; /** * Check if Python runtime is loaded */ isPythonLoaded(): boolean; /** * Verify output matches expected * Note: Uses internal JSON-RPC format with direct values */ verify(hash: string, expectedOutput: unknown, actualOutput: unknown): Promise<{ verified: boolean; }>; /** * Send request and wait for response */ private sendRequest; /** * Handle worker message */ private handleMessage; /** * Handle worker error */ private handleError; /** * Terminate the worker */ terminate(): void; /** * Set timeout for requests */ setTimeout(ms: number): void; } //# sourceMappingURL=SandboxWorker.d.ts.map