/** * Factored, environment-agnostic core of the platform glue (player compute * P3/P5). This is the ONLY platform code that shares an execution context * with an untrusted player module, so it is deliberately tiny and auditable * and has NO dependency on worker globals, the DOM, or the SDK client — the * browser worker entry ([player-glue-worker.ts]) and the Node integration * test both drive this same core. * * ABI (matches crowdy-compute-sdk `lib.rs`): the guest imports module `ck` * with `log`, `now_ms`, `state_get`, `state_set`, and the JSON gateway * `host_call(ptr,len) -> u64` (packed `resp_ptr<<32 | resp_len`, guest frees * with `ck_free`), plus `wasi_snapshot_preview1.random_get`. The guest * exports `memory`, `ck_alloc`, `ck_free`, and the module hooks `init`, * `tick(dt_ms)`, `handle_invoke(ptr,len)->u64`, optional `on_event(ptr,len)`. * * `host_call` is SYNCHRONOUS from the guest's view. The single synchronous * dependency this core takes is `hostCallSync(reqBytes) -> respBytes`; the * browser/Node entry realizes it with a SharedArrayBuffer + `Atomics.wait` * (the worker blocks; the page/broker services the async SDK call and writes * the reply back). Everything else here is pure. */ /** The host-call names surfaced to a guest (mirrors the broker allowlist). */ export declare const GLUE_HOST_FUNCTIONS: readonly ["container_create", "container_get", "containers_list", "container_delete", "property_set", "model_invoke", "user_state_get", "user_state_set", "grid_state_get", "grid_state_set", "chunk_get", "voxels_list", "actors_list", "actors_list_radius", "voxel_set", "emit_spatial", "hud_set", "overlay_draw", "grid_permission_check"]; export interface GlueInitMessage { type: 'init'; artifact: ArrayBuffer; authority: 'player'; /** Server-authored budget loaded into an injected mutable `ck_fuel` global. */ fuelPerDispatch?: string; /** Legacy metadata; the hard watchdog is owned by the page-side broker. */ watchdogMs?: number; hostCallTimeoutMs?: number; /** Local client tick cadence in ms (0/undefined => no self-tick). */ tickIntervalMs?: number; } /** * Parse the server-authored budget used to refill an instrumented artifact's * mutable `ck_fuel` global before every guest dispatch. */ export declare function parseFuelBudget(raw: string | undefined): bigint | null; /** A dispatch outcome the worker reports back to the broker. */ export type GlueDispatchResult = { ok: true; } | { ok: false; reason: 'fuel' | 'watchdog' | 'trap'; detail?: string; }; /** * Classify a completed guest dispatch by elapsed wall time. This cannot * interrupt synchronous WASM; the page-side PlayerCodeBroker owns the hard * dispatch watchdog and terminates a worker whose dispatch never returns. */ export declare function runWithWatchdog(dispatch: () => unknown, watchdogMs: number, now?: () => number): Promise; /** The minimal guest-instance surface the runtime drives (a real WebAssembly.Instance satisfies it). */ export interface GuestExports { memory: { buffer: ArrayBuffer; }; ck_fuel?: WebAssembly.Global; ck_alloc(len: number): number; ck_free?(ptr: number, len: number): void; init?(): void; tick?(dtMs: number): void; handle_invoke?(ptr: number, len: number): bigint | number; on_event?(ptr: number, len: number): void; } export interface GlueRuntimeOptions { /** Synchronous host-API gateway: JSON request bytes in, SDK Response-envelope bytes out. */ hostCallSync: (reqBytes: Uint8Array) => Uint8Array; /** debug/info/warn/error sink for guest `ck.log` (optional). */ onLog?: (level: number, message: string) => void; /** Deterministic-enough randomness for the guest `random_get` (defaults to crypto). */ randomFill?: (buf: Uint8Array) => void; now?: () => number; fuelPerDispatch?: bigint | null; } /** * Drives one untrusted guest module: builds the `ck` + wasi import table, * instantiates the artifact, and marshals the synchronous `host_call` * gateway across guest linear memory. Durable client state is kept in-worker * (a client module's blob is ephemeral per session — the durable store is a * host_call away for anything that must survive). */ export declare class GlueRuntime { private readonly options; private exports; private stateBlob; constructor(options: GlueRuntimeOptions); private resetFuel; /** The import object handed to `WebAssembly.instantiate`. Guest sees only these. */ buildImports(getExports: () => GuestExports | null): WebAssembly.Imports; instantiate(artifact: ArrayBuffer): Promise; /** Run the module's `init` export (once, after instantiate). */ init(): void; /** Run one `tick(dt_ms)`. Throws propagate to the caller's watchdog wrapper. */ tick(dtMs: number): void; /** Invoke the module with an opaque payload; returns the reply bytes (copied out). */ invoke(payload: Uint8Array): Uint8Array; } //# sourceMappingURL=glue-runtime.d.ts.map