Stable, ergonomic Rust SDK for writing F∆I Platform modules. Wraps the frozen v1.0 WIT contract behind #[fai_module].
Find a file
flemming-it eb7a1d5d42
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Has been cancelled
fix(macros): emit WASM glue only on target_arch = "wasm32"
The #[fai_module] expansion previously always inserted the
wit_bindgen::generate! call, the Guest impl, and the export!
macro. That is correct on the wasm32 target but causes host
compilation of a module crate to fail because wit_bindgen's
runtime types are not in scope on a non-wasm target.

The orchestrator-llm module worked around this with a manual
#[cfg(target_arch = "wasm32")] gate around its hand-written
wit_bindgen call. The point of the SDK is to remove that
boilerplate, so the gate now lives inside the macro itself.

Module crates can now declare crate-type = ["cdylib", "rlib"]
and run integration tests via `cargo test` against the
`invoke` function directly without having the WASM glue on
the host build.

Bumps the SDK patch version 0.1.0 -> 0.1.1 per the per-commit
policy.

Signed-off-by: flemming-it <sf@flemming.it>
2026-05-01 14:57:44 +02:00
.forgejo/workflows feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
crates fix(macros): emit WASM glue only on target_arch = "wasm32" 2026-05-01 14:57:44 +02:00
examples/echo feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
wit feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
.gitignore feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
Cargo.lock feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
Cargo.toml fix(macros): emit WASM glue only on target_arch = "wasm32" 2026-05-01 14:57:44 +02:00
LICENSE feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
NOTICE feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
README.md feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00
rust-toolchain.toml feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro 2026-05-01 02:23:44 +02:00

fai-module-sdk

Stable, ergonomic Rust surface for writing F∆I Platform modules.

A module written against this crate looks like:

use fai_module_sdk::prelude::*;

#[fai_module]
fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
    let text = inputs.require_text("input")?;
    Ok(Outputs::new().with_text("output", format!("echo: {text}")))
}

That single function — plus a Cargo.toml listing fai-module-sdk as a dependency — is the entire module. The #[fai_module] macro generates the wit_bindgen invocation, the Guest implementation, the type conversions, and the wit_bindgen::export! glue behind the scenes.

What the SDK gives you

You get Instead of
Inputs::require_text("name") manual match payload { Payload::Text(s) => ..., _ => ... }
Outputs::new().with_json(...)? building Vec<(String, Payload)> by hand
ModuleError::invalid_input("...") constructing WIT invocation-error variants
#[fai_module] wit_bindgen::generate! + Guest impl + export! + #![allow(unsafe_op_in_unsafe_fn)]

Stability

The SDK insulates module code from the underlying WIT contract (fai:platform, frozen at v1.0 in the platform repo). The WIT may evolve in additive minor versions or, eventually, a coordinated v2.0; the SDK absorbs that change so existing module code keeps compiling.

The SDK ships its own copy of wit/world.wit so that the proc-macro can embed the contract via include_str! at compile time. A snapshot test (crates/fai-module-sdk/tests/wit_freeze.rs) asserts the SHA-256 matches the platform's frozen hash — if the two ever drift, CI fails.

Versioning

Track Stability
WIT contract (fai:platform) Frozen at v1.0 in the platform repo
fai-module-sdk Rust API Semver; v0.x while ergonomics evolve
Per-module versions Each module repo's own concern

License

Apache-2.0. See LICENSE.

Author: Dr. Stefan Flemming, Flemming.AI platform@flemming.ai Repository: https://git.flemming.ws/fai/module-sdk