SDK for writing Jasper plugins in Rust,
compiled to wasm32-unknown-unknown and run inside the host's wasmi sandbox.
The crate's minor version tracks the plugin API spec version (SDK 0.2.x ⇔
apiVersion = "0.2" in manifest.toml). The full contract lives in
docs/plugin-spec.md.
[lib]
crate-type = ["cdylib"]
[dependencies]
jasper-plugin-sdk = "0.2"use jasper_plugin_sdk as sdk;
use sdk::core::model::Note;
fn before_save(mut note: Note) -> Result<Note, String> {
note.body = note.body.lines().map(|l| l.trim_end()).collect::<Vec<_>>().join("\n");
Ok(note)
}
sdk::register! { before_save: before_save }Build with cargo build --release --target wasm32-unknown-unknown, then zip
manifest.toml + plugin.wasm (+ assets) into a .jplug package.
register!— wires your code to the wasm ABI (plugin_dispatch); the three slotsbefore_save,storage,commandcan be combined freelyhost— typed wrappers overhost_call:log,now_ms(the sandbox has no clock),settings_get/settings_set(needssettingscapability),http_request(needshost:httpcapability)storage::Storage— implement this trait to provide a storage backend (declared via[[contributes.storage]]in the manifest)sdk::core— re-export ofjasper-coremodel types crossing the ABI
Plain unit tests just work (cargo test — the ABI exports are wasm-only).
For integration tests that need host APIs, enable the native-host feature
in dev-dependencies: host_call is then served by a local stand-in —
http.request performs real HTTP via ureq, time.now uses the system clock,
and settings live in a thread-local map you can seed with
sdk::native_host::set_setting:
[dev-dependencies]
jasper-plugin-sdk = { version = "0.2", features = ["native-host"] }This is a test double, not the sandbox: no capability gating, no fuel/memory limits. It never affects the wasm build.
- Don't pull dependencies that drag in
wasm-bindgen(e.g.chronowith default features) — the sandbox is plain wasm, not a JS environment. The SDK registers agetrandomerror stub sowasm32-unknown-unknownlinks. - Reference plugins live in
plugins-examples/(before-save hook, storage providers, editor command).
MIT OR Apache-2.0, at your option.