TypeScript experiments with System One decision models — models that answer typed questions (Choice / Score / Noul) about a piece of state and return probabilities plus a confidence, instead of generated text. Every use case runs on either:
-m |
model | where it runs |
|---|---|---|
jev |
TypeSafe Jev (default) | TypeSafe's hosted API, needs TYPESAFE_API_KEY |
laya |
Laya, English checkpoint | locally, in a Python sidecar |
npm install
cp .env.example .env # then put your key from https://console.typesafe.ai/keys in itnpm run cricket -m jev
npm run cricket -m laya
npm run batsman -m laya-m is read even though npm swallows it: npm run x -m y hands y to scripts only as
npm_config_message (npm treats -m as its own --message), and the CLI falls back to
that. Outside npm, npx tsx src/cli.ts cricket -m laya or --model laya work directly.
npm run cricket # use case 1, the whole labelled dataset
npm run batsman # use case 2
npm start -- cricket --rich # plus the fan-out questions
npm start -- cricket --text "Bowled him!" # one ad-hoc line, full distribution
npm start -- batsman --dry-run # candidate finder only, calls nothing
npm start -- cricket --limit 8 --concurrency 8
npm start -- --helpOne ball of ball-by-ball commentary in, one of three labels out:
| label | meaning |
|---|---|
runs |
runs were added and nobody was dismissed (off the bat or as extras) |
wicket |
a dismissal that stood, even if runs were completed on the same ball |
no-runs |
a dot ball |
The whole decision is one Choice question in src/usecases/cricket-commentary/index.ts.
The precedence rule (a standing dismissal outranks runs) lives in the option
descriptions, not in post-processing, so the model resolves it rather than our code.
--rich adds three speculative questions to the same request — was it a boundary,
were the runs off the bat, how dramatic was the ball — which is free to ask and lets
calling code branch without a second round trip.
The dataset in dataset.ts is deliberately awkward in places: a catch off a no-ball,
a boundary off a fielder's boot on the rope, a run out completed after a run, a review
that overturns a not-out. Those rows are where confidence drops, and the eval prints
accuracy above and below a 0.9 confidence gate so you can see that.
Jev picks among options; it never writes free text. So extraction is not "read the name out of the sentence", it is code over-finds candidate spans, Jev picks one, code copies it verbatim — the pattern from the pre-parsed value extraction cookbook. Because the options are the spans a regex found, the answer cannot be an invented name or a misspelled one.
candidates.tsfinds every plausible name: capitalised runs, initial clusters (KL,MS,AB), particles (de Villiers,Van der Dussen). It is tuned to over-find — a false positive costs one option in the prompt, a miss costs the answer. A short stoplist keeps sentence openers like Beaten and Trapped out; a few (Punched, Absolutely) are left in on purpose as distractors.index.tsoffers those spans to a singleChoice, plus anonehatch for lines where the batsman is only a pronoun.noneis lowercase and every candidate starts with a capital, so the hatch can never collide with a real name.- When the finder returns nothing, no request is made at all.
The dataset names a bowler in every line and usually a fielder, keeper, umpire, team or
ground too. Some lines name the bowler first, some last, and two use the same pair of
players in opposite word order, so position in the sentence is no help. Four lines name
nobody on strike and should come back none.
The eval splits failures into the two that have different fixes:
accuracy: n/28
finder missed the value ... <- a regex bug; no model can recover it
value found, wrong pick ... <- a Jev result
--dry-run runs only step 1 and reports whether every expected value is reachable,
so you can iterate on the regex without spending a request.
Laya is PyTorch, so it runs in laya-server/ — a stdlib HTTP server that loads a
checkpoint once and serves the same POST /v1/systemone shape Jev does. The use cases
don't know which model they are talking to (src/models.ts).
cd laya-server && uv sync # once: installs laya, torch, transformersThat's all the setup. -m laya starts the sidecar itself if nothing is listening on
:8788 and stops it on exit. The first start downloads the checkpoint (~1.7 GB) from
Hugging Face. Across repeated runs it is faster to keep one running:
cd laya-server && uv run python server.py # the CLI reuses it| env | default | |
|---|---|---|
LAYA_CHECKPOINT |
english |
or multilingual, typed-decisions |
LAYA_HEAD_MAX_LEN |
320 |
budget for one question's instructions + options (checkpoint ships 192) |
LAYA_MAX_LEN |
from checkpoint | total budget, options + state |
LAYA_DEVICE |
auto (MPS on Apple Silicon) | cpu, mps, cuda |
LAYA_PORT |
8788 |
- Make a folder under
src/usecases/with anindex.tsexporting aClassificationUseCaseor anExtractionUseCase(seesrc/usecase.ts) and adataset.tsof labelled examples. - Register it in
src/usecases/index.ts.
The CLI, both eval runners, the confusion matrix and the confidence gate come for free.