@pmtx/chain is the TypeScript SDK for Prometheux. It covers the same backend surface as the Python SDK, with typed requests and responses, streaming, and errors you can narrow on. A common use is to keep your Vadalog programs as .vada files in your own repository and evaluate them against the platform engine. You don’t need to save anything as a concept, so you can version, review and test your programs like the rest of your code.

Runnable examples

The examples on this page are runnable scripts in the prometheux-chain-ts-examples repository. Clone it, add your token, and run each one with npm run.

Installation

The SDK runs in Node.js 22 or newer and in browsers. It ships ESM and CommonJS builds for Node.js and an ESM build for browsers, with type definitions included. Browser bundlers such as Vite, webpack and esbuild pick the browser build automatically.
In a browser, pass token and baseUrl to the client explicitly, because there are no environment variables. fileFromPath() and saveTo() use the file system and work in Node.js only. In a browser, upload a File from an <input type="file"> and read downloads with .blob() or .text(). Browser support needs @pmtx/chain 0.1.2 or newer. For a working page, see browser/app.ts in the examples repository (npm run browser).

Configuration

The client reads your token and backend URL from the environment:
.env
You can also pass them explicitly, along with other options:
See Authentication for how to get a token.
Keep the token on the server. A token in browser code ships to every visitor and grants full access to your account. See Bring your own frontend.

Evaluate a Vadalog program

px.vadalog.evaluate() sends a program to the engine and returns its output. Nothing is saved to the platform.
src/01-evaluate-inline.ts
Evaluation runs on your compute, so a machine must be running. Pass compute to target a specific one: px.vadalog.evaluate(program, { compute }). See Compute.

Read the result

The result has one entry per @output predicate:
The SDK types this result as unknown, because the engine defines its shape. The examples repository declares the shape once and converts rows to objects:
src/lib/evaluation.ts

Evaluate a .vada file

A program is just a string, so you can keep it in a file next to your code and read it before you evaluate it:
programs/company-control.vada
src/02-evaluate-file.ts
Output
The control output lists every company each owner controls. For example, “Alpha Treasury” controls “Goldward Bank” without owning any of it directly: the companies it controls, “Royal Crown Bank” and “Soylent Corp”, own 60% of it together. The banking supervision example explains the rules.

Pass parameters

Declare inputs with @param and reference them as ${name}. The declared values are defaults, and params overrides them, so the same file can answer many queries:
programs/large-orders.vada
src/03-evaluate-with-params.ts
Each value in params is pasted into the program as Vadalog text. Numbers work as they are, but a string needs its own quotes: pass '"North"', not "North". Without the quotes, Region = ${region} becomes Region = North, and the engine reads North as an unbound variable and rejects the rule as not safe.

Read your own data

Your programs read data through @bind. To use a local file, upload it to your workspace storage (disk/) first, then bind a predicate to it:
programs/company-control-from-csv.vada
src/05-evaluate-with-your-data.ts
Uploading a file with the same name replaces the existing one. File paths in @bind must be relative and stay under disk/. A bind can also point to a database, a warehouse or object storage: see Data sources.

Stop a long evaluation

Every evaluation is tagged with an executionId, a random UUID unless you pass one. When a request times out or you abort it, the SDK stops that evaluation on the engine before it throws. Otherwise the engine would keep running it and hold up the evaluations that follow:
You can also stop evaluations yourself, and check whether the engine is busy:
Stopping evaluations needs @pmtx/chain 0.1.1 or newer.

Check programs before you run them

px.vadalog.validate() compiles a program without running it. px.vadalog.analyze() lists the predicates a program reads and the ones it produces. Together they make a quick CI step that checks every program in a folder:
src/04-check-programs.ts
Output
An invalid program resolves to { valid: false, error } and doesn’t throw. Check valid before you use the result.

Unit-test your programs

Evaluate a program in a test and compare its output with the rows you expect. This works with any test runner. Here is Node’s built-in one:
test/company-control.test.ts
Run it with npx tsx --test test/*.test.ts. On Node 23.6 or newer, node --test runs TypeScript files directly.

Save and run concepts

To make a program part of an ontology, save it as a concept. Concepts appear in the platform UI, take part in lineage, and can build on each other. Their results are stored, so you can page through them later:
src/06-concepts.ts
To follow a long run as it progresses, use px.concepts.runStream() instead of run(). It streams one status event per concept:
Use px.vadalog.evaluate() for programs that live in your repository, and concepts for logic your team works on in the platform. A concept’s body is the same Vadalog, so a program can start as a .vada file and become a concept later.

Handle errors

Failed requests throw a typed error that you can narrow with instanceof:
All of them extend PrometheuxError. Every method also takes a last { signal, timeout } argument, so you can cancel a request with an AbortController.

More of the SDK

The client groups the API by resource: px.ontologies, px.concepts, px.datasources, px.files, px.context, px.agent, px.apps, px.policies and more. The package README lists every option and includes a table that maps each Python SDK function to its TypeScript method.