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.ymland a hand-authoreddist/manifest.json. The host compiles the JavaScript handler on load. - Legacy typed project:
src/handlers and their existing build artifacts, includingdist/handlers.wasmanddist/manifest.json. The host keeps loading those committed artifacts as before. This is not a declaration-generation path forrealm.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 projectimport { 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 underctx.gateway(as shown throughout). A manifest selects the invocation convention for the whole artifact with the top-level fieldhandlerAbi,"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 nohandlerAbiis read as it always has been: on thedockerhost as"ctx-args-legacy", the(ctx, args)form with the gateway passed directly as the first argument, and on thewasmhost as"input-ctx", the only form that host has run. Adockerrealm moves to(input, ctx)by declaringhandlerAbi: "input-ctx", so onesrc/can serve both hosts. Arealm.tsdeclaration has no manifest, and its handlers are always(input, ctx). Newrealm.tsdefinitions keep handler schemas in theirhandlersrecord. Legacy manifest extraction is not a proposed authoring step for those definitions.

