ComputerWorld

API reference

JavaScript API#

The npm package computerworld is one module for Node and the browser: Node gets the CommonJS glue through exports, everything else the ES module. These are its exported types, as computerworld.d.ts declares them. Objects that cross the boundary as any are plain JSON: the world definition, an environment config, actions, results, observations and scenes are the same documents the agent API and action families describe.

See the Wasm guide for loading the module and the font pack.

/**
 * Restricted actor handle: no privileged inspection, topology export, or snapshots.
 */
export class Environment {
    private constructor();
    free(): void;
    [Symbol.dispose](): void;
    observe(): any;
    render(width: number, height: number): Frame;
    scene(width: number, height: number): any;
    step(actions: any): any;
    readonly id: string;
}

export class Frame {
    private constructor();
    free(): void;
    [Symbol.dispose](): void;
    readonly rgba: Uint8Array;
    height: number;
    width: number;
}

/**
 * Standalone retained renderer for synthetic applications and measurement.
 */
export class SceneRenderer {
    free(): void;
    [Symbol.dispose](): void;
    constructor();
    patch(patch: any): Frame;
    render(scene: any): Frame;
}

export class Snapshot {
    private constructor();
    free(): void;
    [Symbol.dispose](): void;
}

/**
 * Privileged owner handle. Give agents only the Environment returned by environment().
 */
export class World {
    free(): void;
    [Symbol.dispose](): void;
    /**
     * Owner-only topology mutation. Wiring is explicit; no implicit host access.
     */
    addComputer(computer: any, node: any, links: any): void;
    definition(): any;
    environment(config: any): Environment;
    exportSnapshot(): string;
    fork(snapshot: Snapshot): World;
    importSnapshot(json: string): void;
    inspect(): any;
    constructor(definition: any, seed: any);
    removeComputer(id: string): void;
    reset(seed: any): void;
    restore(snapshot: Snapshot): void;
    /**
     * Reconnect an actor stored in a restored/forked checkpoint.
     */
    session(id: string): Environment;
    snapshot(): Snapshot;
    stateHash(): string;
    trajectory(): any;
}

export function createWorld(definition: any, seed: any): World;

/**
 * Version of the canonical engine embedded in this binding.
 */
export function engineVersion(): string;

/**
 * The font pack: every file with its SHA-256 and size, which are installed, and
 * which renderers have needed but not had (fetch exactly those, then re-render).
 */
export function fontPackStatus(): any;

/**
 * Install one file of the CJK/emoji font pack (`fonts/<file>` beside this module).
 * The Wasm build does not embed those faces; until a file is installed its glyphs
 * draw as `.notdef` boxes, while layout is already final. Bytes are identified by
 * SHA-256, so only the exact files this build was made with are accepted, and every
 * renderer drops its cached text on the next frame. Returns the file name.
 */
export function installFont(bytes: Uint8Array): string;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput { readonly memory: WebAssembly.Memory; /* wasm-bindgen internals */ }

export type SyncInitInput = BufferSource | WebAssembly.Module;

/**
 * Instantiates the given `module`, which can either be bytes or
 * a precompiled `WebAssembly.Module`.
 *
 * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
 *
 * @returns {InitOutput}
 */
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;

/**
 * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
 * for everything else, calls `WebAssembly.instantiate` directly.
 *
 * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
 *
 * @returns {Promise<InitOutput>}
 */
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;