Engine and file format
The workflow file, the checks on it, the MCP config it implies, and an engine that runs it. All of it is plain TypeScript with no DOM and no Svelte, so it runs in a browser, in Node, or in a test.
Install
pnpm add @fractaldesign/machines-ui import { exportFlow, exportMarkdown, importFlow, validateGraph, createRunner, mcpConfigText } from '@fractaldesign/machines-ui/engine';
import { fileRunStore } from '@fractaldesign/machines-ui/engine/node'; // Node onlyThe file
machines.flow/1 is one JSON document: the name, the steps, the connections and, if you ask for it, the log of a test run. Export then import gives back the same graph. Import reports what is wrong with a file by path, and renames older step kinds.
const meta = { id: 'support', name: 'Support Triage', description: '' };
const doc = exportFlow(graph, meta, { testRun }); // the document; JSON.stringify(doc) is the file
const markdown = exportMarkdown(graph, meta, { testRun });
const { graph, meta, warnings } = importFlow(text); // text or parsed JSON; throws FlowParseError with problems[]
const problems = validateGraph(graph); // { code, message, nodeId? }[]Running
A step runs when its inputs have arrived. Parallel branches run together, a join waits for all of its live inputs, and loops stop at maxVisitsPerStep and maxSteps. With no adapters the engine simulates: agents answer from each step's sample output, and the run is marked simulated.
const runner = createRunner({ adapters, env: { OPENAI_API_KEY }, limits: { timeoutMs: 20_000 } });
const run = runner.run(graph, { trigger: { prompt: 'hi' } });
run.subscribe((event) => console.log(event.type)); // run.started, step.finished, edge.taken, run.finished …
const record = await run.result; // status, steps, logs, simulated
run.approve('support-approve'); // a Review step waiting for a person
const again = runner.resume(graph, record); // pick a paused run back up | Step | What it does when run |
|---|---|
| Receive Trigger | Starts the run with the payload. |
| Read Source / Write Output | Storage adapter, or a stand-in. |
| Run Agent | One adapter function per model name, or a stand-in answer. |
| Transform | JSON, Markdown, CSV, HTML and text conversions, run for real. |
| Branch | Conditions on earlier outputs; takes the true or false port. |
| Review | Waits for a person, or checks a condition or a test result. |
| Wait | A delay; skipped by the fast clock. |
| Loop | Runs again until its exit condition holds, bounded by the limits. |
| Send Email / Send Webhook / Update Record | Adapters; webhooks only reach allowed hosts. |
| Run Workflow | Runs another workflow through the flows adapter. |
Each step can set onError (stop, continue or retry), attempts, backoffMs and timeoutMs. Values that look like secrets are blanked out of every log and output.
Adapters
The package ships these interfaces and the stand-ins, and no provider code. Pass only what you have.
createRunner({
adapters: {
agents: { 'Luna (worker)': async ({ prompt, input }) => callYourModel(prompt, input) },
mail: { send: async (message) => yourMailer(message) },
http: { allow: ['hooks.example.com'] }, // webhooks reach only these hosts
storage: { read, write },
records: { update },
flows: { get },
tests: { run }
}
});Stores and clocks
Runs are kept in a RunStore: memoryRunStore(), indexedDbRunStore() in a browser, fileRunStore(dir) in Node. The fast clock skips waits and is what simulation uses; the real clock waits.
MCP config
mcpConfigText(name, graph) returns the config an MCP client would use for the workflow: the server key, the command, and the environment variables its steps imply. It is the shape of the server, not a server: to run it, host it yourself. This package does not provide hosting.
In the canvas
The same engine drives the Run button, the Status and Logs tabs, Export and Connect MCP in the creator. From code, startRun, stopRun, approveStep and rejectStep are exported from the package root.