@clause-lang/runtime
v1.0.0
Published
Minimal runtime for compiled Clause programs
Downloads
150
Maintainers
Readme
@clause-lang/runtime
The minimal JavaScript runtime for compiled Clause programs.
Zero external dependencies. Works in Node.js, Deno, Bun, and the browser (ESM).
Installation
npm install @clause-lang/runtimeModules
@clause-lang/runtime/core — Pipeline Primitives
Provides the groupBy polyfill used when your Clause program contains group by.
import { installCorePrimitives } from '@clause-lang/runtime/core';
installCorePrimitives(); // call once at program startThe Clause compiler auto-injects this import when
group byis used.
@clause-lang/runtime/effects — Effect Registry
Register handlers for named effects and dispatch them via perform.
import { registerEffect, dispatchEffect } from '@clause-lang/runtime/effects';
// register your effect handlers
registerEffect('send-email', async ({ to, subject, body }) => {
await mailer.send({ to, subject, body });
});
// dispatch (called automatically by compiled workflows)
await dispatchEffect('send-email', { to: '[email protected]', subject: 'Hi', body: '...' });@clause-lang/runtime/errors — Outcome Types
Structured error types for attempt/when outcome handling.
import { ClauseError, OutcomeError, wrapOutcome } from '@clause-lang/runtime/errors';
try {
const result = await wrapOutcome(() => riskyOperation());
// result.outcome === 'succeeded'
} catch (err) {
if (err instanceof OutcomeError) {
// err.outcome === 'failed' | 'declined' | ...
console.error(err.outcome, err.message);
}
}@clause-lang/runtime/types — Runtime Type Guards
Runtime validation for Clause shape definitions.
import { isShape, assertShape } from '@clause-lang/runtime/types';
const ProductSchema = {
id: 'text',
name: 'text',
price: 'number',
inStock: 'boolean',
};
assertShape(data, ProductSchema); // throws if invalid@clause-lang/runtime/agent — AI Agent Interface
Exposes the IR and live step state of a running workflow for AI agent consumption.
import { createAgent } from '@clause-lang/runtime/agent';
const agent = createAgent({ workflowName: 'place-order' });
agent.onStep('validate', (state) => {
console.log('Agent sees:', JSON.stringify(state, null, 2));
});Compatibility
| Runtime | Supported | |---|---| | Node.js 18+ | ✅ | | Node.js 20+ | ✅ | | Deno | ✅ | | Bun | ✅ | | Browser (ESM) | ✅ |
License
MIT © Rajat Kumar
