/** * The synchronous host-call transport for browser-target player WASM * (player compute P5). WASM imports are synchronous, but the host-call * handler (the server-authorized SDK path) is async and lives on the page, * while the guest runs in a Worker. The only correct bridge is a * SharedArrayBuffer the worker blocks on with `Atomics.wait`: the worker * writes the request, posts a wake to the page, and blocks; the page * services the async call and writes the reply back into the SAB, then * `Atomics.notify` wakes the worker. (A worker blocked in `Atomics.wait` * cannot receive `postMessage`, which is exactly why the reply must return * through the SAB, not a message.) * * SharedArrayBuffer + Atomics require cross-origin isolation * (COOP: same-origin + COEP: require-corp) in the browser; Node worker * threads have them unconditionally, which is how this is integration-tested. * * Layout: [ state:i32, len:i32, requestId:i32 ] header, then a byte data * region. The request id prevents a host response that completed after the * worker's timeout from waking a later request that reused the same SAB. * state: 0 IDLE, 1 PENDING (worker waiting), 2 DONE. * The request travels to the page as a normal postMessage (before the * worker blocks); only the reply uses the SAB. */ export declare const SAB_STATE_IDLE = 0; export declare const SAB_STATE_PENDING = 1; export declare const SAB_STATE_DONE = 2; export declare const GLUE_HOST_CALL_TIMEOUT_MS = 5000; export declare const SAB_HEADER_BYTES: number; /** 1 MiB reply region — host-call replies (chunk/actor reads) are well under this. */ export declare const SAB_DATA_BYTES: number; export interface GlueSab { sab: SharedArrayBuffer; header: Int32Array; data: Uint8Array; } export declare function createGlueSab(dataBytes?: number): GlueSab; export declare function wrapGlueSab(sab: SharedArrayBuffer): GlueSab; declare const encoder: TextEncoder; declare const decoder: TextDecoder; /** * Responder side (page/broker): write the reply envelope bytes into the SAB * and wake the blocked worker. `respBytes` must already be the SDK Response * envelope (`{ok,data}` / `{ok:false,error}`) the guest expects. */ export declare function writeGlueReply(view: GlueSab, respBytes: Uint8Array, requestId?: number): boolean; /** Convenience for responders holding a plain object result. */ export declare function writeGlueResult(view: GlueSab, result: unknown, requestId?: number): boolean; /** * Requester side (worker): mark PENDING before posting the wake, block until * the page flips the state to DONE, then read the reply bytes out. The * caller is responsible for posting the request message between `arm()` and * `waitAndRead()` — that ordering (post, then wait) is what lets the page * see the request while the worker is blocked. */ export declare function armGlueRequest(view: GlueSab, requestId: number): void; export declare function waitAndReadGlueReply(view: GlueSab, requestId: number, timeoutMs?: number): Uint8Array; export { encoder as glueEncoder, decoder as glueDecoder }; //# sourceMappingURL=glue-sab.d.ts.map