Compare commits
No commits in common. "main" and "v0.1.2" have entirely different histories.
17 changed files with 72 additions and 72 deletions
42
Cargo.lock
generated
42
Cargo.lock
generated
|
|
@ -41,27 +41,6 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "chain-module-sdk"
|
|
||||||
version = "0.1.2"
|
|
||||||
dependencies = [
|
|
||||||
"chain-module-sdk-macros",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sha2",
|
|
||||||
"thiserror",
|
|
||||||
"wit-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "chain-module-sdk-macros"
|
|
||||||
version = "0.1.2"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
|
|
@ -97,6 +76,27 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fai-module-sdk"
|
||||||
|
version = "0.1.2"
|
||||||
|
dependencies = [
|
||||||
|
"fai-module-sdk-macros",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sha2",
|
||||||
|
"thiserror",
|
||||||
|
"wit-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fai-module-sdk-macros"
|
||||||
|
version = "0.1.2"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "generic-array"
|
name = "generic-array"
|
||||||
version = "0.14.7"
|
version = "0.14.7"
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"crates/chain-module-sdk",
|
"crates/fai-module-sdk",
|
||||||
"crates/chain-module-sdk-macros",
|
"crates/fai-module-sdk-macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Dr. Stefan Flemming <chain@flemming.ai>"]
|
authors = ["Dr. Stefan Flemming <platform@flemming.ai>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
repository = "https://git.flemming.ai/fai/module-sdk-rust"
|
repository = "https://git.flemming.ws/fai/module-sdk"
|
||||||
homepage = "https://flemming.ai/"
|
homepage = "https://flemming.ai/"
|
||||||
rust-version = "1.85"
|
rust-version = "1.85"
|
||||||
|
|
||||||
|
|
|
||||||
2
NOTICE
2
NOTICE
|
|
@ -4,7 +4,7 @@ Copyright 2026 Flemming.AI
|
||||||
This product includes software developed by Dr. Stefan Flemming
|
This product includes software developed by Dr. Stefan Flemming
|
||||||
and contributors (https://flemming.ai/).
|
and contributors (https://flemming.ai/).
|
||||||
|
|
||||||
This SDK ships a copy of the WIT contract owned by Ch∆In
|
This SDK ships a copy of the WIT contract owned by F∆I Platform
|
||||||
(`fai/platform`, frozen at v1.0). The mirror is verified by a
|
(`fai/platform`, frozen at v1.0). The mirror is verified by a
|
||||||
SHA-256 snapshot test and updated only in lockstep with the
|
SHA-256 snapshot test and updated only in lockstep with the
|
||||||
upstream contract.
|
upstream contract.
|
||||||
|
|
|
||||||
10
README.md
10
README.md
|
|
@ -1,6 +1,6 @@
|
||||||
# fai-module-sdk
|
# fai-module-sdk
|
||||||
|
|
||||||
Stable, ergonomic Rust surface for writing Ch∆In modules.
|
Stable, ergonomic Rust surface for writing F∆I Platform modules.
|
||||||
|
|
||||||
A module written against this crate looks like:
|
A module written against this crate looks like:
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ That single function — plus a `Cargo.toml` listing
|
||||||
## Stability
|
## Stability
|
||||||
|
|
||||||
The SDK insulates module code from the underlying WIT contract
|
The SDK insulates module code from the underlying WIT contract
|
||||||
(`chain:platform`, frozen at v1.0 in the platform repo). The
|
(`fai:platform`, frozen at v1.0 in the platform repo). The
|
||||||
WIT may evolve in additive minor versions or, eventually, a
|
WIT may evolve in additive minor versions or, eventually, a
|
||||||
coordinated v2.0; the SDK absorbs that change so existing
|
coordinated v2.0; the SDK absorbs that change so existing
|
||||||
module code keeps compiling.
|
module code keeps compiling.
|
||||||
|
|
@ -47,7 +47,7 @@ two ever drift, CI fails.
|
||||||
|
|
||||||
| Track | Stability |
|
| Track | Stability |
|
||||||
|-------|-----------|
|
|-------|-----------|
|
||||||
| WIT contract (`chain:platform`) | Frozen at v1.0 in the platform repo |
|
| WIT contract (`fai:platform`) | Frozen at v1.0 in the platform repo |
|
||||||
| `fai-module-sdk` Rust API | Semver; v0.x while ergonomics evolve |
|
| `fai-module-sdk` Rust API | Semver; v0.x while ergonomics evolve |
|
||||||
| Per-module versions | Each module repo's own concern |
|
| Per-module versions | Each module repo's own concern |
|
||||||
|
|
||||||
|
|
@ -55,5 +55,5 @@ two ever drift, CI fails.
|
||||||
|
|
||||||
Apache-2.0. See `LICENSE`.
|
Apache-2.0. See `LICENSE`.
|
||||||
|
|
||||||
Author: Dr. Stefan Flemming, Flemming.AI <chain@flemming.ai>
|
Author: Dr. Stefan Flemming, Flemming.AI <platform@flemming.ai>
|
||||||
Repository: https://git.flemming.ai/fai/module-sdk-rust
|
Repository: https://git.flemming.ws/fai/module-sdk
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chain-module-sdk-macros"
|
name = "fai-module-sdk-macros"
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
@ -7,7 +7,7 @@ license.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
homepage.workspace = true
|
homepage.workspace = true
|
||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
description = "Procedural macros for chain-module-sdk. Not used directly — see chain-module-sdk."
|
description = "Procedural macros for fai-module-sdk. Not used directly — see fai-module-sdk."
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Procedural macros powering `chain-module-sdk`.
|
//! Procedural macros powering `fai-module-sdk`.
|
||||||
//!
|
//!
|
||||||
//! This crate exists only to host the `#[fai_module]` attribute.
|
//! This crate exists only to host the `#[fai_module]` attribute.
|
||||||
//! Module authors should depend on `chain-module-sdk` (which
|
//! Module authors should depend on `fai-module-sdk` (which
|
||||||
//! re-exports the macro), not on this crate directly.
|
//! re-exports the macro), not on this crate directly.
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
|
@ -51,14 +51,14 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
clippy::nursery
|
clippy::nursery
|
||||||
)]
|
)]
|
||||||
|
|
||||||
::chain_module_sdk::__rt::wit_bindgen::generate!({
|
::fai_module_sdk::__rt::wit_bindgen::generate!({
|
||||||
inline: #wit_literal,
|
inline: #wit_literal,
|
||||||
world: "module",
|
world: "module",
|
||||||
runtime_path: "::chain_module_sdk::__rt::wit_bindgen::rt",
|
runtime_path: "::fai_module_sdk::__rt::wit_bindgen::rt",
|
||||||
});
|
});
|
||||||
|
|
||||||
use exports::chain::platform::invoke::Guest;
|
use exports::fai::platform::invoke::Guest;
|
||||||
use chain::platform::types::{
|
use fai::platform::types::{
|
||||||
BytesValue as WitBytes,
|
BytesValue as WitBytes,
|
||||||
FileRef as WitFileRef,
|
FileRef as WitFileRef,
|
||||||
InvocationContext as WitContext,
|
InvocationContext as WitContext,
|
||||||
|
|
@ -79,7 +79,7 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
::std::vec::Vec<(::std::string::String, WitPayload)>,
|
::std::vec::Vec<(::std::string::String, WitPayload)>,
|
||||||
WitError,
|
WitError,
|
||||||
> {
|
> {
|
||||||
let sdk_ctx = ::chain_module_sdk::Context {
|
let sdk_ctx = ::fai_module_sdk::Context {
|
||||||
invocation_id: ctx.invocation_id,
|
invocation_id: ctx.invocation_id,
|
||||||
capability_namespace: ctx.capability_namespace,
|
capability_namespace: ctx.capability_namespace,
|
||||||
capability_name: ctx.capability_name,
|
capability_name: ctx.capability_name,
|
||||||
|
|
@ -87,13 +87,13 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
};
|
};
|
||||||
let sdk_pairs: ::std::vec::Vec<(
|
let sdk_pairs: ::std::vec::Vec<(
|
||||||
::std::string::String,
|
::std::string::String,
|
||||||
::chain_module_sdk::Payload,
|
::fai_module_sdk::Payload,
|
||||||
)> = inputs
|
)> = inputs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, p)| (k, wit_payload_to_sdk(p)))
|
.map(|(k, p)| (k, wit_payload_to_sdk(p)))
|
||||||
.collect();
|
.collect();
|
||||||
let sdk_inputs =
|
let sdk_inputs =
|
||||||
::chain_module_sdk::Inputs::__from_pairs(sdk_pairs);
|
::fai_module_sdk::Inputs::__from_pairs(sdk_pairs);
|
||||||
|
|
||||||
match super::#user_fn_name(sdk_ctx, sdk_inputs) {
|
match super::#user_fn_name(sdk_ctx, sdk_inputs) {
|
||||||
Ok(outputs) => {
|
Ok(outputs) => {
|
||||||
|
|
@ -109,18 +109,18 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wit_payload_to_sdk(p: WitPayload) -> ::chain_module_sdk::Payload {
|
fn wit_payload_to_sdk(p: WitPayload) -> ::fai_module_sdk::Payload {
|
||||||
match p {
|
match p {
|
||||||
WitPayload::Text(s) => ::chain_module_sdk::Payload::Text(s),
|
WitPayload::Text(s) => ::fai_module_sdk::Payload::Text(s),
|
||||||
WitPayload::Json(s) => ::chain_module_sdk::Payload::Json(s),
|
WitPayload::Json(s) => ::fai_module_sdk::Payload::Json(s),
|
||||||
WitPayload::Bytes(b) => ::chain_module_sdk::Payload::Bytes(
|
WitPayload::Bytes(b) => ::fai_module_sdk::Payload::Bytes(
|
||||||
::chain_module_sdk::BytesValue {
|
::fai_module_sdk::BytesValue {
|
||||||
mime_type: b.mime_type,
|
mime_type: b.mime_type,
|
||||||
data: b.data,
|
data: b.data,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
WitPayload::FileRef(f) => ::chain_module_sdk::Payload::FileRef(
|
WitPayload::FileRef(f) => ::fai_module_sdk::Payload::FileRef(
|
||||||
::chain_module_sdk::FileRef {
|
::fai_module_sdk::FileRef {
|
||||||
uri: f.uri,
|
uri: f.uri,
|
||||||
mime_type: f.mime_type,
|
mime_type: f.mime_type,
|
||||||
size_bytes: f.size_bytes,
|
size_bytes: f.size_bytes,
|
||||||
|
|
@ -130,15 +130,15 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sdk_payload_to_wit(p: ::chain_module_sdk::Payload) -> WitPayload {
|
fn sdk_payload_to_wit(p: ::fai_module_sdk::Payload) -> WitPayload {
|
||||||
match p {
|
match p {
|
||||||
::chain_module_sdk::Payload::Text(s) => WitPayload::Text(s),
|
::fai_module_sdk::Payload::Text(s) => WitPayload::Text(s),
|
||||||
::chain_module_sdk::Payload::Json(s) => WitPayload::Json(s),
|
::fai_module_sdk::Payload::Json(s) => WitPayload::Json(s),
|
||||||
::chain_module_sdk::Payload::Bytes(b) => WitPayload::Bytes(WitBytes {
|
::fai_module_sdk::Payload::Bytes(b) => WitPayload::Bytes(WitBytes {
|
||||||
mime_type: b.mime_type,
|
mime_type: b.mime_type,
|
||||||
data: b.data,
|
data: b.data,
|
||||||
}),
|
}),
|
||||||
::chain_module_sdk::Payload::FileRef(f) => WitPayload::FileRef(WitFileRef {
|
::fai_module_sdk::Payload::FileRef(f) => WitPayload::FileRef(WitFileRef {
|
||||||
uri: f.uri,
|
uri: f.uri,
|
||||||
mime_type: f.mime_type,
|
mime_type: f.mime_type,
|
||||||
size_bytes: f.size_bytes,
|
size_bytes: f.size_bytes,
|
||||||
|
|
@ -147,21 +147,21 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sdk_error_to_wit(e: ::chain_module_sdk::ModuleError) -> WitError {
|
fn sdk_error_to_wit(e: ::fai_module_sdk::ModuleError) -> WitError {
|
||||||
match e {
|
match e {
|
||||||
::chain_module_sdk::ModuleError::InvalidInput(s) => {
|
::fai_module_sdk::ModuleError::InvalidInput(s) => {
|
||||||
WitError::InvalidInput(s)
|
WitError::InvalidInput(s)
|
||||||
}
|
}
|
||||||
::chain_module_sdk::ModuleError::PermissionDenied(s) => {
|
::fai_module_sdk::ModuleError::PermissionDenied(s) => {
|
||||||
WitError::PermissionDenied(s)
|
WitError::PermissionDenied(s)
|
||||||
}
|
}
|
||||||
::chain_module_sdk::ModuleError::ResourceExhausted(s) => {
|
::fai_module_sdk::ModuleError::ResourceExhausted(s) => {
|
||||||
WitError::ResourceExhausted(s)
|
WitError::ResourceExhausted(s)
|
||||||
}
|
}
|
||||||
::chain_module_sdk::ModuleError::DeadlineExceeded => {
|
::fai_module_sdk::ModuleError::DeadlineExceeded => {
|
||||||
WitError::DeadlineExceeded
|
WitError::DeadlineExceeded
|
||||||
}
|
}
|
||||||
::chain_module_sdk::ModuleError::Internal(s) => WitError::Internal(s),
|
::fai_module_sdk::ModuleError::Internal(s) => WitError::Internal(s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chain-module-sdk"
|
name = "fai-module-sdk"
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
@ -7,10 +7,10 @@ license.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
homepage.workspace = true
|
homepage.workspace = true
|
||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
description = "Stable, ergonomic surface for writing Ch∆In modules in Rust"
|
description = "Stable, ergonomic surface for writing F∆I Platform modules in Rust"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chain-module-sdk-macros = { path = "../chain-module-sdk-macros" }
|
fai-module-sdk-macros = { path = "../fai-module-sdk-macros" }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
//! Ergonomic Rust surface for writing Ch∆In modules.
|
//! Ergonomic Rust surface for writing F∆I Platform modules.
|
||||||
//!
|
//!
|
||||||
//! A module written against this crate looks like:
|
//! A module written against this crate looks like:
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```ignore
|
||||||
//! use chain_module_sdk::prelude::*;
|
//! use fai_module_sdk::prelude::*;
|
||||||
//!
|
//!
|
||||||
//! #[fai_module]
|
//! #[fai_module]
|
||||||
//! fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
//! fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
//! # Stability
|
//! # Stability
|
||||||
//!
|
//!
|
||||||
//! This crate insulates modules from the underlying WIT contract
|
//! This crate insulates modules from the underlying WIT contract
|
||||||
//! (`chain:platform`, frozen at v1.0). The WIT may evolve in additive
|
//! (`fai:platform`, frozen at v1.0). The WIT may evolve in additive
|
||||||
//! minor versions or, eventually, a coordinated v2.0; the SDK absorbs
|
//! minor versions or, eventually, a coordinated v2.0; the SDK absorbs
|
||||||
//! that change so module code keeps compiling.
|
//! that change so module code keeps compiling.
|
||||||
|
|
||||||
|
|
@ -35,9 +35,9 @@ pub use inputs::Inputs;
|
||||||
pub use outputs::Outputs;
|
pub use outputs::Outputs;
|
||||||
pub use payload::{BytesValue, FileRef, Payload};
|
pub use payload::{BytesValue, FileRef, Payload};
|
||||||
|
|
||||||
pub use chain_module_sdk_macros::fai_module;
|
pub use fai_module_sdk_macros::fai_module;
|
||||||
|
|
||||||
/// Convenience prelude — `use chain_module_sdk::prelude::*;` brings
|
/// Convenience prelude — `use fai_module_sdk::prelude::*;` brings
|
||||||
/// every type a typical module needs into scope.
|
/// every type a typical module needs into scope.
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::{
|
pub use super::{
|
||||||
|
|
@ -10,13 +10,13 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
description = "Reference module showing the minimum needed to write an F∆I module with chain-module-sdk."
|
description = "Reference module showing the minimum needed to write an F∆I module with fai-module-sdk."
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chain-module-sdk = { path = "../../crates/chain-module-sdk" }
|
fai-module-sdk = { path = "../../crates/fai-module-sdk" }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = "s"
|
opt-level = "s"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
//! `unsafe_op_in_unsafe_fn` allow, no `export!` call, no manual
|
//! `unsafe_op_in_unsafe_fn` allow, no `export!` call, no manual
|
||||||
//! Payload-variant matching.
|
//! Payload-variant matching.
|
||||||
|
|
||||||
use chain_module_sdk::prelude::*;
|
use fai_module_sdk::prelude::*;
|
||||||
|
|
||||||
#[fai_module]
|
#[fai_module]
|
||||||
fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
// stable, ergonomic surface. That is what protects modules
|
// stable, ergonomic surface. That is what protects modules
|
||||||
// from any future evolution of this contract.
|
// from any future evolution of this contract.
|
||||||
|
|
||||||
package chain:platform@1.0.0;
|
package fai:platform@1.0.0;
|
||||||
|
|
||||||
/// Types that flow between the host (hub) and modules.
|
/// Types that flow between the host (hub) and modules.
|
||||||
interface types {
|
interface types {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue