> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rkat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# WASM runtime

> Browser deployment with the meerkat-web-runtime embedded surface.

The WASM runtime compiles the full Meerkat agent stack to wasm32 for browser deployment. It routes through the same `AgentFactory::build_agent()` pipeline as all other surfaces.

<Note>
  This page is intentionally browser/WASM-specific rather than a cross-surface tabbed page. Use [Examples: Mobpack](/examples/mobpack) first if you want the packaging/deployment path that usually leads into browser delivery.
</Note>

## Build the WASM bundle

<Tabs>
  <Tab title="CLI">
    Build a self-contained, runnable web bundle from a `.mobpack` artifact.
    `--wasm` points at the prebuilt meerkat-web-runtime (the wasm-pack
    `--target web` output dir, or the committed `sdks/web/wasm`):

    ```bash theme={null}
    rkat mob web build ./dist/my-mob.mobpack -o ./dist/web-bundle --wasm ./sdks/web/wasm
    ```

    Then serve and open it: `python3 -m http.server -d ./dist/web-bundle`.
  </Tab>

  <Tab title="Manual (wasm-pack)">
    Build the WASM package directly with wasm-pack:

    ```bash theme={null}
    RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \
      wasm-pack build meerkat-web-runtime --target web --out-dir pkg
    ```
  </Tab>
</Tabs>

## Initialize runtime

Use init-time credentials and provider base URLs to seed the browser runtime's
realm config. The `@rkat/web` `RuntimeConfig` is provider-specific:
`anthropicApiKey`, `openaiApiKey`, `geminiApiKey`, and the matching provider
base URL fields (`anthropicBaseUrl`, `openaiBaseUrl`, `geminiBaseUrl`). The old
generic `apiKey`/`baseUrl` compatibility fields are deleted, and
`SessionConfig` does not accept per-session `apiKey` or `baseUrl`.

```typescript theme={null}
import { MeerkatRuntime } from "@rkat/web";
import * as wasm from "@rkat/web/wasm/meerkat_web_runtime.js";

const runtime = await MeerkatRuntime.initFromMobpack(wasm, mobpackBytes, {
  anthropicApiKey: "sk-ant-...",
  model: "claude-sonnet-4-6",
});
```

For proxy deployments, pass a provider-specific dummy key and base URL. The
proxy injects the real server-side credential.

```typescript theme={null}
const runtime = await MeerkatRuntime.init(wasm, {
  anthropicApiKey: "proxy",
  anthropicBaseUrl: "http://localhost:3100/anthropic",
  model: "claude-sonnet-4-6",
});
```

## Create session and run turn

```typescript theme={null}
const session = runtime.createSession({
  model: "claude-sonnet-4-6",
});

const result = await session.turn("Hello");
console.log(result.text);
```

For OAuth or host-owned cloud credentials, register an external auth resolver
and bind the session to a structural auth binding. The selected realm binding
must be configured to use the WASM external-resolver credential source.

```typescript theme={null}
import { registerExternalAuthResolver, withAuthBinding } from "@rkat/web";

registerExternalAuthResolver(wasm, async (authBinding) => {
  const token = await hostAuth.freshAccessToken(authBinding);
  return {
    kind: "inline_secret",
    secret: token.accessToken,
    metadata: { account_id: token.accountId },
    expires_at: token.expiresAt,
  };
});

const bound = runtime.createSession(withAuthBinding(
  { realm: "team-alpha", binding: "anthropic" },
  { model: "claude-sonnet-4-6" },
));
```

## Poll events

```typescript theme={null}
for (const event of session.pollEvents()) {
  if (event.type === "text_delta") {
    document.body.innerText += event.delta;
  }
}
```

## Mob lifecycle in browser

```typescript theme={null}
// Create mob from definition
const mob = await runtime.createMob({
  id: "research-team",
  orchestrator: { profile: "lead" },
  profiles: {
    lead: { model: "claude-sonnet-4-6" },
    worker: { model: "claude-sonnet-4-6" },
  },
});

// Spawn members
await mob.spawn([
  { profile: "lead", agent_identity: "lead-1" },
  { profile: "worker", agent_identity: "worker-1" },
]);

// Wire peers
await mob.wire("lead-1", "worker-1");

// Inspect runtime state
const members = await mob.listMembers();
const leadStatus = await mob.memberStatus("lead-1");
```

## Subscribe to member events

```typescript theme={null}
const sub = await mob.subscribeMemberEvents("lead-1");

for (const event of sub.poll()) {
  console.log(event.type, event);
}

sub.close();
```

## Cross-mob comms

Wire ambassadors across mobs for inter-faction communication. `mob.wire()` accepts either a local member name or an external peer target, so trust between members of different mobs is established by wiring each ambassador to the other side's peer identity (comms name, address, Ed25519 public key).

```typescript theme={null}
// Wire an ambassador to a peer in another mob
await northMob.wire("ambassador-north", {
  external: {
    name: "ambassador-south",
    address: southAddress,
    identity: { kind: "ed25519_public_key", public_key: southPublicKey },
  },
});

// Send work to a member through the canonical member path
await northMob
  .member("ambassador-north")
  .send("Send a message to the south faction proposing an alliance on the eastern front.");
```

<Note>
  Direct `comms_send` and `comms_peers` are reserved low-level placeholders rather
  than current wasm-bindgen exports or public `@rkat/web` wrapper methods.
  Inter-agent messaging happens through member-directed turn submission and the
  comms tools available to agents during their turns (`send_message`,
  `send_request`, `send_response`, and `peers`).
</Note>

## What is available on wasm32

| Category       | Available                                   | Not available                            |
| -------------- | ------------------------------------------- | ---------------------------------------- |
| **Agent loop** | Full agent state machine, streaming, budget | --                                       |
| **Providers**  | Anthropic, OpenAI, Gemini (browser fetch)   | --                                       |
| **Sessions**   | Ephemeral sessions                          | Persistent sessions (filesystem)         |
| **Mobs**       | Full orchestration, flows, lifecycle        | --                                       |
| **Comms**      | In-process (`inproc`) transport             | TCP, UDS, network transports             |
| **Tools**      | Custom tools, tool dispatch                 | Shell tools, filesystem tools            |
| **Skills**     | Embedded skills, HTTP skills                | Filesystem skill sources                 |
| **Hooks**      | In-process hooks                            | Command hooks, filesystem hooks          |
| **Compaction** | Context compaction                          | --                                       |
| **Other**      | --                                          | MCP client, delegated work orchestration |

## Next step

* [Examples: Mobpack](/examples/mobpack) — the packaging/deployment path that often comes before browser delivery
* [Examples: Mobs](/examples/mobs) — the multi-agent runtime model behind many WASM demos
