The pieces / weirdnet-ext-sdk

weirdnet-ext-sdk

Write Weirdnet extensions: connect to the host, call app services, log, report health, handle events.

v0.1.1 GitHub crates.io docs.rs weirdnet-ext-sdk = "0.1.1"

What it brings

Write a Weirdnet extension in Rust. A host such as Morph starts your binary in its sandbox with a private socket and a one-time token; the SDK uses them to connect and hand-shake, and gives you calls into the app, logging, health reports and the app's events.

What it is

The SDK for extension authors. It lives in the weirdnet-ext repository.

How it works

  • Extension::connect(version) reads the socket and token the host set, does the handshake and returns a session with the extension id, the host and the API version.
  • granted() and has(name) show what the user granted; call(service, method, payload) calls an app service (for example morph.ext.v1.Notes), which the host checks against the grants.
  • log and health report to the host; run(on_event) handles app events until the host says stop.

The sandbox leaves you no network, no files outside your package and data directory, and no socket() call: everything goes through the host.

Key types and modules

  • Extension: connect, granted, has, call, log, health, run.
  • Event, Capability, Error.

Feature flags

None: everything is on by default.

Usage

In Cargo.toml:

[dependencies]
weirdnet-ext-sdk = "0.1.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Then (built and run against the published crate when this page was made):

// An extension: connect to the host that started it, log, and handle the app's events.
use weirdnet_ext_sdk::{Event, Extension, Level};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ext = Extension::connect(env!("CARGO_PKG_VERSION")).await?;
    ext.log(Level::Info, "started", &[]).await?;
    let e = ext.clone();
    ext.run(move |ev| {
        let e = e.clone();
        async move {
            if let Event::App { kind, payload } = ev {
                let _ = e.call("morph.ext.v1.Notes", "Append", payload).await;
                let _ = kind;
            }
        }
    })
    .await?;
    Ok(())
}

Where it fits