Core concepts
Learn how Throughline turns source text into steps and complete state snapshots.
Version scope — v0.0.2 (historical schema 1). This page and its examples use @0xbuff/throughline@0.0.2, the version pinned by this documentation app. They do not describe the unreleased schema-2 API intended for v0.2.0. See compatibility and upgrading.
Throughline separates the trace you write from the frames it produces. This makes the result predictable and lets a player move directly to any step.
From source to frames
- Source is one
thlblock. The first line selects a domain such asfloworbinary. - Program describes entities, links, and ordered steps after the domain is parsed.
- Trace is the compiled result. It contains the initial state and a complete snapshot after each step.
- Player is optional. It displays the trace and lets you move between frames.
The compiler does not interpret arbitrary JavaScript or call a service.
Entities and links
In the flow domain, an entity is a named value with an identifier and a display label. A relation is a directed link between entities. A group can arrange related entities in a row, column, or tree.
```thl flow
node input "Input" = 1
node output "Output" = 0
link copy input -> output "copy"
step "Transfer"
send copy = 1
step "Store"
set output = 1
```Here, send highlights a transfer, but does not change output. Only set changes its stored value.
Steps and events
A step (also called a beat in the API) contains one or more events. The compiler combines their effects into a single resulting frame.
| Event | What happens |
|---|---|
set | Changes a value and keeps that change in later frames |
show / hide | Changes visibility for this and later frames |
focus | Highlights a target in the current frame |
send | Shows a transfer on a link in the current frame |
note | Adds explanatory text to the current frame |
Updates to the same or overlapping targets in one step are rejected. Split them into separate steps if you need to show intermediate states.
Frames and snapshots
Frame 0 contains the declared initial state. Each subsequent frame represents one authored or generated step, including its label, events, and a complete state snapshot.
import { compile } from "@0xbuff/throughline";
const trace = compile(
'thl flow\nnode status "Status" = "idle"\nstep "Start"\nset status = "running"',
);
console.log(trace.frames[0].state.entities[0].value); // "idle"
console.log(trace.frames[1].state.entities[0].value); // "running"You can read trace.frames[n] directly. The player does not replay earlier steps when you seek; it selects an existing snapshot. Treat compiled trace data as read-only.
Versions
The npm package and trace data use different version numbers. In Throughline v0.0.2, Program.version and Trace.version are both 1. See compatibility before persisting trace data across package upgrades.
For details of validation and rendering, read How Throughline works. For syntax, start with Flow authoring.