TypeScript or Rust?
@zaun/bot (TypeScript) and the zaun-bot crate (Rust) are two SDKs for the same thing: a
WebAssembly component the host runs in its sandbox, with the same commands, components, modals,
events, direct messages, voice, storage, timers and HTTP. The manifest, zbot pack, signing and
installing are identical. These docs show TypeScript first.
TypeScript (@zaun/bot) |
Rust (zaun-bot) |
|
|---|---|---|
| API style | builder classes and interaction objects (SlashCommandBuilder, interaction.reply) |
a Bot trait with handler methods, builders |
| Build | zbot build: esbuild bundles src/index.ts, jco makes the component |
zbot build: cargo build --target wasm32-wasip2 |
| Package size | about 24 MB (the JavaScript engine is inside) | about 300 KB |
| First load on a host | about 11 s to compile, then cached | well under a second |
| A warm call | tens of microseconds (about 22 µs) | under a microsecond (about 0.4 µs) |
| Errors | thrown ZaunError { code, detail, retryAfterMs } |
Result<_, HostError> |
Either is fast enough for chat: a call is a tiny part of what a member waits for. Choose TypeScript if you know JavaScript, Rust if you want the smallest, fastest package.
Rules that are specific to TypeScript
Section titled “Rules that are specific to TypeScript”- No
setTimeoutorsetInterval. Nothing runs between calls, so they never fire. Usebot.timers.after(ms, tag)orbot.timers.every(ms, tag)and listen withbot.on('timer', …). - Autocomplete answers synchronously. Call
interaction.respond(choices)before the handler’s firstawait: the choices are taken when the handler returns. - Async is fine otherwise. Host calls are synchronous, so awaiting them (or promises that are already resolved) completes inside the same call.
- No
fetch. Usebot.http.fetch(url, options), which goes only to hosts in the bot’snetworkgrant. - The entry exports the world. End
src/index.tswithexport const { init, onEvent, onInteraction, onAutocomplete, onTimer, onVoiceEvent } = bot.exports(); - Builders check the limits (custom ids ≤ 100 bytes, ≤ 5 buttons per row, modal titles ≤ 45, …)
and throw
ZaunValidationErrorbefore anything reaches the host.
Reference
Section titled “Reference”@zaun/botAPI (generated from the TypeScript source)zaun-botcrate (generated from rustdoc)- Bot WIT interface, which both SDKs wrap