Runtime Adapter
The PlaygroundRuntimeAdapter interface defines the contract between the UI and any execution backend.
interface PlaygroundRuntimeAdapter {
validate(source: PlaygroundSource): Promise<ValidationResult>
compile(source: PlaygroundSource): Promise<CompileResult>
execute(request: ExecuteRequest, callbacks?: ExecutionCallbacks): Promise<ExecutionResult>
replay(request: ReplayRequest, callbacks?: ExecutionCallbacks): Promise<ReplayResult>
runQuery(request: QueryRequest): Promise<QueryResult>
}Current implementation
Local mode (default)
BrowserPlaygroundAdapter in @causet/playground-runtime provides:
| Stage | Implementation |
|---|---|
| Parse | YAML parser with multi-file @file splitting |
| Validate | Schema checks for states, actions, events, projections, queries |
| Compile | Produces internal IR (CompiledIR) |
| Execute | Rules engine with preflight, core, and side-effect phases |
| Projections | In-memory table materialization with upsert/insert/delete |
| Queries | SQL-like filtering against projection tables |
| Replay | Re-processes event ledger into projections |
Live Causet mode
Toggle Live Causet in the sidebar to execute against a real Causet deployment. This uses:
| Package | Role |
|---|---|
@causet/causet-sdk | TypeScript port of the jamlet causet-sdk-python HTTP client |
@causet/playground-sdk-adapter | Implements PlaygroundRuntimeAdapter — local compile/validate, remote execute |
/api/causet/proxy | Next.js API route that forwards requests to Causet (avoids browser CORS) |
In Live mode, Run still compiles DSL locally, then sends each command as an intent via POST .../intents/execute. Queries run against the remote fork; projections are skipped (they materialize asynchronously on the server).
Connection settings (sidebar):
- API URL — e.g.
https://api.causet.cloud - Platform slug, app slug, fork (default
main) - API key or bearer token
You can also set server-side defaults with environment variables on the docs site:
CAUSET_API_URL=
CAUSET_API_KEY=
CAUSET_BEARER_TOKEN=Replay is not available in Live mode — switch back to Local for event replay in the browser.
Rules engine
Intents execute in three phases matching production Causet:
- Preflight — validation rules that can
rejectintents - Core — state mutations (
set,add) - Side effects — event emission via
emit
Expressions in when clauses evaluate against intent and state contexts.
Replacing with production runtime
The tutorials already ship a Live adapter backed by @causet/causet-sdk. For deeper integration (WASM compiler, WebSocket streaming, server-only credentials):
- Extend
CausetSdkAdapteror implement a newPlaygroundRuntimeAdapter - Call SaaS
product-spec/compilefor compilation instead of the browser parser - Stream entity updates via the SDK WebSocket client
- Map production errors to
Diagnosticobjects
The UI, examples, persistence, and share URLs remain unchanged.
Callbacks for streaming
Pass ExecutionCallbacks to receive live updates:
onEvent— each ledger event as it’s appendedonProjection— projection materialization resultsonQuery— query execution resultsonStateChange— aggregate version snapshotsonLog— structured runtime logsonTimelineUpdate— execution graph nodesonDiagnostic— errors and warnings