thrum (TS)
the thrum client for a bee written in TS
A TS bee reaches humd through hum’s own client. Bee runs
hum bee link, which enters the bee, signs its hello, reads humd’s
verdict, reconnects when humd restarts, and checks every tone against the
thrum. Every language gets that same client, so a TS bee behaves exactly
as a Rust, Python, Go or C one.
import { Bee, Chi, PetalKind, Role } from "thrum";
const bee = new Bee({ hive: "my-hive", as: "main", role: Role.nurse, hello: { models: ["my-model"] } });bee.on(Chi.prompt, (tone) => { bee.send({ chi: Chi.unfurl, sid: tone.sid, petal: 0, kind: PetalKind.text, text: "hello" }); bee.send({ chi: Chi.wilt, sid: tone.sid, reason: "stop" });});await bee.start();await bee.closed();new Bee({ hive, as, role, hello }) | a bee’s client; nothing runs until start |
on(chi, fn), onSid(sid, fn), offSid(sid), onAny(fn) | a tone goes to its sid’s handler, else its chi’s, else onAny |
onNestled(fn), onAstray(fn), onAdvisory(fn) | humd admitted the bee; humd went away; something to fix |
start() | resolves once humd admits the bee; rejects with Refused or LinkError |
send(tone), hello(patch) | send a tone, given a rid if it has none; change the hello |
close(), closed() | close the link; how the link ended |
hum is found at $HUM_CLI, else on PATH, else ~/.local/bin/hum.
Every source here but the example is generated by cargo run -p codegen:
chi.ts and protocol.ts from thrum-core, link.ts from
codegen/templates/ts with the link’s constants from hum-thrum.
examples/echo_bee.ts is the bee the conformance run
(cargo test -p hum --test conform) drives in every language.