UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

43 lines • 2.21 kB
import type { Context } from '../../../commands/config.ts'; import { type RuntimeOptions } from '../../config.ts'; import type { OutputFn, Program, RunResult } from '../../types.ts'; import { WasmExecution } from '../../wasm/execution.ts'; import { JsRuntime } from '../base.ts'; export declare const QUICKJS_HOME_ENV = "MIRAGE_QUICKJS_HOME"; /** * Run JavaScript on a WASI quickjs-ng, the engine the Python host runs. * * A bare modern JS engine (ES2023 syntax, ES modules, `JSON`, regex, * `Promise`, top-level await) inside a wasm sandbox: no node builtins, * no `require`, no npm, no network. The `std`/`os` globals are exposed * (quickjs-ng `--std`), so scripts read stdin with * `std.in.readAsString()` and reach files with `std.open`/`os.readdir`. * The engine's filesystem imports are intercepted, so file I/O routes * through the workspace dispatch, with the same cache, write modes and * session narrowing as shell commands. * * Each run is on a worker of its own (`WasmExecution`), so a stopped run * ends its worker, however busy the guest. The module comes from the * config `home` or the MIRAGE_QUICKJS_HOME environment variable, a * directory on Node and a URL on a page. Mirrors Python's `QuickJsRuntime`. */ export declare class QuickJsRuntime extends JsRuntime<WasmExecution> { readonly name = "quickjs"; readonly reach = "workspace"; readonly filesystem: readonly ["read", "write", "list", "stat"]; constructor(options?: RuntimeOptions); protected openEngine(): Promise<WasmExecution>; protected closeEngine(engine: WasmExecution): Promise<void>; version(env: Record<string, string>, signal?: AbortSignal): Promise<RunResult>; /** * Run one program on the install's engine. * * @param engine - the install's compiled module and its workers. * @param program - the source and argv to run. * @param ctx - the run's context. * @param output - receives stdout as it is written; absent returns it. * @param errors - the same for stderr. */ interpret(engine: WasmExecution, program: Program, ctx: Context, output?: OutputFn, errors?: OutputFn): Promise<RunResult>; } //# sourceMappingURL=runtime.d.ts.map