A TypeScript class API for MeTTa atoms, spaces and a runner, modeled on Hyperon's hyperon.atoms and
hyperon.base. Where the Python package wraps a Rust core over FFI, this one wraps the immutable terms
of @mettascript/core in classes, so
it runs anywhere TypeScript runs with no native addon and no WASM.
Hyperon's Python method names are kept as aliases beside the idiomatic TypeScript ones, so code ported
from hyperon reads naturally: get_name() sits beside name(), get_children() beside children(),
add_atom() beside addAtom().
npm install @mettascript/hyperonimport { MeTTa, S, V, E } from "@mettascript/hyperon";
const metta = new MeTTa();
// The runner's space is live: what you add stays for the next call.
metta.run("(= (fact $n) (if (> $n 0) (* $n (fact (- $n 1))) 1))");
console.log(metta.run("!(fact 5)")[0]!.map(String)); // [ '120' ]
// Or work in atoms instead of text. S is a symbol, V a variable, E an expression.
metta.space().addAtom(E(S("parent"), S("Tom"), S("Bob")));
const set = metta.space().query(E(S("parent"), S("Tom"), V("c")));
console.log(set.frames.map((f) => f.resolve(V("c"))!.toString())); // [ 'Bob' ]A query answers with binding frames rather than atoms, because a query asks what the variables could
be. resolve reads one variable out of a frame.
The guide on the website teaches this package properly:
- Running MeTTa in TypeScript is the place to start: programs, the live runner, atoms, and your first grounded operation.
- Grounded operations covers declining an argument, failures as values, and nondeterministic results.
- Embedding TypeScript objects puts whole objects in the space and lets a type join unification.
- Async MeTTa is for operations that await.
- JavaScript interop is the two-way bridge between MeTTa values and JavaScript ones.
- API reference lists the full surface, including the grounded object wrappers and the opt-in JSON and random modules.
If you would rather not write atoms by hand,
@mettascript/edsl builds them for
you and types the results.
LLMS.md is a one-page, high-density reference for this package: API surface, working
examples, and the mistakes that produce wrong code. The repository root carries an
llms.txt index of all of them.
MIT.