/** * Guest prelude for the connector isolate lane. * * A bare `isolated-vm` context has ECMAScript plus an inert `console`: no * timers, no `URL`, no text codecs, no `fetch`. This prelude installs exactly * the web-platform surface the SDK root and the bundled isolate-eligible * connectors touch (measured by loading and running them, not by emulating a * browser): * * - CJS shell (`module`/`exports`) and a `require` that answers a fixed * builtin map (`node:crypto`, `node:buffer`, `node:events`, `node:stream`, * `node:module`, `cloudflare:sockets`) and fails closed on everything else. * `node:stream` is admitted so postgres.js loads; its constructors throw, * because an isolate has no Node streams to give. * - `console.*` to the host `log` capability (the host redacts). * - Timers, `setImmediate` and `queueMicrotask` over the host `sleep` * capability; a callback that throws ends the run through `fatal`, the way * an uncaught exception ended the forked child this replaced. * - `process = { env }` from the job env. * - `TextEncoder`/`TextDecoder` and `atob`/`btoa`: object shells whose * byte-level work the host does with Node's own codecs. A decode with * `{ stream: true }` opens a Node `TextDecoder` on the host that keeps the * partial sequence between chunks until the flushing decode releases it. * - `performance.now()`/`timeOrigin` over `Date`: millisecond resolution is * all just-bash reads it for (command timing), and the isolate has no * monotonic clock of its own to offer. * - `structuredClone`, guest-side: a deep copy of the JSON-shaped values, * dates, regexps, maps, sets, errors and byte arrays a tool call carries, * with cycles preserved. pi-ai clones every tool call's arguments before * validating them, so a lane without it cannot run a single tool. * - `URL` over the host `urlParse`/`urlSet` capabilities: the host runs Node's * own URL, so both lanes agree on every input by construction. * `URLSearchParams` keeps its list guest-side, parses and serializes through * the host, and writes back through `search`. * - `AbortController`/`AbortSignal`. * - `Headers`, `Response` and `fetch` over the host `fetchOpen` / `fetchRead` * capabilities. The host performs the network call and answers with status * and headers as soon as they arrive; the body is a pull `ReadableStream` * the guest drains one host chunk at a time, exactly as a socket's * `readable` is, so an SSE response is consumed as it streams. * - `crypto`: `getRandomValues`/`randomUUID`, plus the `subtle` operations * postgres.js needs to answer an md5 or SCRAM-SHA-256 challenge, all * computed by Node on the host. `require('node:crypto')` additionally * answers with `createHash`/`createHmac`/`randomBytes` over the same host * capabilities, because that specifier is a Node module and not WebCrypto. * - `Buffer`, `EventEmitter`, `ReadableStream`/`WritableStream` and * `connect` (WinterCG Direct Sockets), which the DB connectors need. * * The guest talks to the host through two `ivm.Reference`s captured at the * top of the prelude and removed from the global: `__host_sync(name, ...args)` * and `__host_async(name, ...args)`. Every reply is an envelope * `{ __lobu: 1, ok, value | error }`; the host never throws across the * boundary because an async rejection also surfaces as an unhandled rejection * in the host process. * * `FormData` carries text fields and `Blob` file parts, and serialises itself * to a multipart body. It exists at all because the Stainless clients pi's LLM * providers are built on test `body instanceof FormData` unguarded on every * request, so the guest cannot reach a provider without it; it carries file * parts because `@lobu/plugin-media`'s upload driver is one implementation for * both lanes and posts a named `Blob` to the gateway's file-upload route. * `Blob` itself is the minimum that part needs — bytes, a media type, and the * readers the upload path calls — with no `slice`/`stream`. * * Deliberately absent (no isolate-eligible connector or SDK root path uses * them): `Request`, `File`. Add one only with a real caller that needs it. * * Written as sloppy-mode ES2020 with no template literals so the string can * live in this module verbatim. `String.raw` keeps the regex escapes intact. */ /** Names the prelude defines on the guest global. */ export declare const PRELUDE_GLOBALS: readonly ["module", "exports", "require", "console", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "setImmediate", "clearImmediate", "queueMicrotask", "process", "TextEncoder", "TextDecoder", "atob", "btoa", "structuredClone", "performance", "URL", "URLSearchParams", "AbortController", "AbortSignal", "Headers", "Blob", "FormData", "Response", "fetch", "crypto", "Buffer", "connect", "EventEmitter", "ReadableStream", "WritableStream"]; /** * Host halves of prelude globals that delegate to Node. `IsolateHost` installs * a fresh set under every run, so they are part of the guest's standard * library rather than a capability a particular executor grants. Pure * conversions only: no network, no filesystem. The one piece of state is the * registry of streaming `TextDecoder`s, which is why this is a factory and not * a table: a decoder's partial sequence belongs to one run. */ export declare function createPreludeHostSync(): Record unknown>; export declare const GUEST_PRELUDE: string; //# sourceMappingURL=prelude.d.ts.map