Skip to content

Single file, or a typed project

The following two layouts describe legacy realms without realm.ts. New definitions use source composition; their handlers use the separate handler import rules.

  • Legacy single file: wasm/handlers.js, realm.yml and a hand-authored dist/manifest.json. The host compiles the JavaScript handler on load.
  • Legacy typed project: src/ handlers and their existing build artifacts, including dist/handlers.wasm and dist/manifest.json. The host keeps loading those committed artifacts as before. This is not a declaration-generation path for realm.ts.

Types come from two places, both already in the ecosystem: @embabel/runtime-types supplies the Ctx, event, and envelope types, and a generated .embabel/gateway.d.ts (via embabel-realm sync) types ctx.gateway.<namespace>.<method> against the world’s actual tool surface. So ctx.gateway.signals.recent({ … }) autocompletes and type-checks, and a handler’s declared input/return types drive the manifest schemas rather than being hand-copied into JSON.

// src/api/chatops.ts — typed, multi-file project
import { digestByChannel } from "../lib/aggregate";
import type { Ctx } from "@embabel/runtime-types";
export async function digest(input: { limit?: number }, ctx: Ctx): Promise<Digest> {
const messages = await ctx.gateway.signals.recent({ type: "chatops.message", hours: 168, limit: 200 });
return digestByChannel(messages, input.limit ?? 5);
}

The project layout and toolchain are the docker src/ project’s: source under src/api/<namespace>.ts (the filename is the namespace), each exported handler a function in that namespace, helpers under src/lib/ excluded from extraction. Functions resolve by (namespace, name), so a.get and b.get are distinct. The build bundles the reachable module graph from those entrypoints into one module and compiles it to the artifact its placement runs — docker JS modules, or a wasm bundle. wasm/handlers.js stays the no-build escape hatch; src/ is the path when you want types, imports, and tests.

A wasm-targeted src/ project ships its built dist/handlers.wasm and generated manifest as one artifactDigest-bound set; the host does not build src/ on load (build-on-load covers wasm/handlers.js only). A marketplace accepts that set only when the platform built it from the reviewed source or can verify a reproducible-build attestation. A local or organization-reviewed installation may choose a weaker provenance policy, but still verifies the artifact-set digest.

artifactDigest covers the executable and manifest correspondence. The broader canonical realmDigest covers all author-controlled package content: the artifact set plus handlers, events/mappings, channels, types, producers, APIs, MCP/webhook declarations, prompts, and other realm surfaces. Adoption and dispatch pin realmDigest; changing a non-code declaration can change behavior just as surely as changing code.

The handler ABI is selected per manifest, not per handler:

  • One signature across hosts. The canonical handler signature is (input, ctx) with the gateway under ctx.gateway (as shown throughout). A manifest selects the invocation convention for the whole artifact with the top-level field handlerAbi, "input-ctx" or "ctx-args-legacy", never inferred from parameter names or arity (both are arity-two). Any other value refuses handler binding, naming the field. A manifest with no handlerAbi is read as it always has been: on the docker host as "ctx-args-legacy", the (ctx, args) form with the gateway passed directly as the first argument, and on the wasm host as "input-ctx", the only form that host has run. A docker realm moves to (input, ctx) by declaring handlerAbi: "input-ctx", so one src/ can serve both hosts. A realm.ts declaration has no manifest, and its handlers are always (input, ctx). New realm.ts definitions keep handler schemas in their handlers record. Legacy manifest extraction is not a proposed authoring step for those definitions.