Skip to content

TypeScript usage

The Banh source workspace contains @banh/dsl, @banh/runtime, and @banh/laya. Packages remain private and unpublished; this example assumes your application can resolve the built workspace packages.

import { readFile } from 'node:fs/promises';
import { parseProcess } from '@banh/dsl';
import { ProcessRuntime } from '@banh/runtime';
import { LayaBackend } from '@banh/laya';
const definition = parseProcess(
await readFile('examples/support-triage.yaml', 'utf8'),
);
const input = JSON.parse(
await readFile('examples/inputs/support-ticket.json', 'utf8'),
);
const backend = await LayaBackend.create();
try {
const runtime = new ProcessRuntime(backend);
const result = await runtime.execute(definition, input);
console.log(result.output);
console.log(result.decisions);
// Reuse this runtime and backend for subsequent inputs.
} finally {
await backend.close();
}

The caller owns the backend lifetime. Reuse a loaded backend across executions, then close it when finished. The CLI handles this cleanup automatically, including when execution fails.

Parsing and validation do not require loading Laya. No fallback provider, inference retries, or side-effect actions are included.

Field Meaning
process Workflow process name.
output First matching rule’s returned value.
decisions Normalized answers, policy results, optional metadata, and raw answers by decision ID.
timing.totalMs Execution duration, excluding model loading.
timing.inferenceMs Inference duration when available, including backend normalization.
usage Optional usage metadata supplied by the backend.

Pass { onEvent } as the second argument to new ProcessRuntime(backend, { onEvent }) to observe inference and flow events. Decision metadata availability depends on the backend; see decisions.