@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
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
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:
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
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
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
@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 anexecutionId, 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:
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
{ 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
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
px.concepts.runStream() instead of run(). It
streams one status event per concept:
Handle errors
Failed requests throw a typed error that you can narrow withinstanceof:
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.
