@mastra/core
Version:
43 lines • 1.97 kB
TypeScript
/**
* Code Mode — Sandbox runner
*
* Builds the JavaScript program that runs *inside* the sandbox. The runner:
* - defines an `external_<name>` function per allow-listed tool, each of which
* emits a JSON-RPC request on the protocol channel and awaits its response
* (matched by `id`, so `Promise.all` calls resolve independently);
* - wraps the model's program in an async function, captures `console.*`, and
* emits a terminal `done` frame.
*
* Protocol (host <-> runner), newline-delimited JSON on stdout/stdin:
* - Frames the runner emits are prefixed with FRAME_PREFIX so the host can
* tell them apart from any stray output. Forms: `rpc`, `log`, `done`.
* - The host writes `rpc-result` frames to the runner stdin (no prefix).
*/
/** Marks a line on stdout as a Code Mode protocol frame. */
export declare const FRAME_PREFIX = "\0CODEMODE\0";
export interface BuildRunnerOptions {
/**
* Module specifier the runner imports to obtain the user program. The
* referenced module must `export default` an async function (the wrapped
* model code). Written as a sibling `.ts` file so the sandbox's `node`
* strips the TypeScript types natively at import time.
*/
programModule: string;
/** Map of `external_<name>` -> original tool id used in the RPC request. */
externals: Array<{
externalName: string;
toolId: string;
}>;
}
/**
* Wrap the model's TypeScript program as a default-exported async function
* module. Written to a `.ts` file; Node strips the type annotations at import.
* Top-level `return`, `await`, and `const` work because the body lives inside
* an async function.
*/
export declare function buildProgramModule(program: string): string;
/**
* Produce the full runner source to write into the sandbox and run with node.
*/
export declare function buildRunner({ programModule, externals }: BuildRunnerOptions): string;
//# sourceMappingURL=runner.d.ts.map