Loading component…
Loading component…
Agents working in parallel and waiting on each other, as a Petri net – tokens in places, steps that fire only when every input is ready, a person's step waiting for approval
To reuse this local React demo, copy all files from the Code tab into the same folder, then import PetriNet from ./petri-net.
import { PetriNet, type PetriPlace, type PetriTransition } from "@/components/ui/petri-net";
const places: PetriPlace[] = [
{ id: "api-todo", label: "API to build", col: 0, row: 0, tokens: 1 },
{ id: "ui-todo", label: "UI to build", col: 0, row: 1, tokens: 1 },
{ id: "api-ready", label: "API ready", col: 2, row: 0 },
{ id: "ui-ready", label: "UI ready", col: 2, row: 1 },
{ id: "tested", label: "Tests pass", col: 4, row: 0.5, kind: "end" },
];
const transitions: PetriTransition[] = [
{ id: "api", label: "Build API", col: 1, row: 0, inputs: ["api-todo"], outputs: ["api-ready"], agent: { id: "backend", name: "Backend agent" } },
{ id: "ui", label: "Build UI", col: 1, row: 1, inputs: ["ui-todo"], outputs: ["ui-ready"], agent: { id: "frontend", name: "Frontend agent" } },
// A join – it fires only once both the API and the UI are ready
{ id: "integrate", label: "Integrate", col: 3, row: 0.5, inputs: ["api-ready", "ui-ready"], outputs: ["tested"], agent: { id: "qa", name: "QA agent" } },
];
export function Release() {
return <PetriNet name="Ship v2.4" places={places} transitions={transitions} run={[["api", "ui"], "integrate"]} />;
}| Name | Type | Default | Description |
|---|---|---|---|
| name | string | The run's name, in the head | |
| places | PetriPlace[] | { id, label, col, row, tokens?, kind? } – white circles with the button edge that hold tokens as small dark pixels. col and row place it on the grid (halves are fine); tokens are the ones it starts with; kind "end" draws the final place with a check once a token arrives | |
| transitions | PetriTransition[] | { id, label, col, row, inputs, outputs, agent?, person? } – steps, drawn as cards: who does it on a tinted tile, the step, a progress circle with how many inputs hold a token (1/2 inputs) and its state. It fires when every input place holds a token: takes one from each, its agent works, puts one into every output. agent { id, name, color? } draws its pixel mark on a tile in its color; person { name, photo? } makes it a step that waits for approval | |
| run | (string \| string[])[] | Transition ids to fire by themselves, in order – an array fires several together. Each step waits until it can fire; a person's step waits a moment longer, as if deciding. Shows Pause and Reset in the head | |
| loop | boolean | Start the run over when it's done – default true | |
| pace | number | Milliseconds a step takes its tokens and gives them on – default 650; the agent works twice as long | |
| onFire | (transitionId: string) => void | Called whenever a transition fires | |
| className | string | Extra class on the root – set the color variables on it, e.g. --ui-pn-token |
The net sits right on the card – no field behind it – drawn at its own size and zoomed to the card's width (never larger); below 62% it scrolls sideways
Narrow: the name takes its own row above the counters
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"