Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,50 @@ jobs:
run: cargo check --release --all --all-features
- name: Test
run: cargo test --all --features mock-ffi

get-features:
runs-on: ubuntu-latest
outputs:
features: ${{ steps.get-features.outputs.features }}
steps:
- name: Check out
uses: actions/checkout@v4
- name: Install toml-cli
run: cargo install toml-cli
- name: Extract features from Cargo.toml
id: get-features
run: |
# Extract all feature names from Cargo.toml
all_features=$(toml get Cargo.toml features | jq -r 'keys[]')

# Filter out default and mock-ffi
features=$(echo "$all_features" | grep -v -E '^(default|mock-ffi)$' | jq -R -s -c 'split("\n") | map(select(length > 0))')

# Add "default" and "all" to test with default features and all features
features=$(echo $features | jq -c '. + ["default", "all"]')

echo "features=$features" >> $GITHUB_OUTPUT
echo "Detected features: $features"

feature-matrix:
needs: get-features
runs-on: ubuntu-latest
strategy:
matrix:
feature: ${{ fromJson(needs.get-features.outputs.features) }}
steps:
- name: Check out
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.85.0
with:
toolchain: stable
targets: wasm32-wasip1
- name: Check feature ${{ matrix.feature }}
run: |
if [ "${{ matrix.feature }}" = "default" ]; then
cargo check --release
elif [ "${{ matrix.feature }}" = "all" ]; then
cargo check --release --all-features
else
cargo check --release --no-default-features --features ${{ matrix.feature }}
fi
26 changes: 20 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@ license = "MIT/Apache-2.0"
repository = "https://github.com/blocklessnetwork/sdk-rust"

[dependencies]
base64 = { version = "0.13", default-features = false, features = ["alloc"] }
htmd = { version = "0.2.2", default-features = false }
base64 = { version = "0.13", default-features = false, features = ["alloc"], optional = true }
htmd = { version = "0.2.2", default-features = false, optional = true }
json = { version = "0.12", default-features = false }
kuchikiki = { version = "0.8", default-features = false }
regex = { version = "1.11.1", default-features = false, features = ["unicode-case"] }
kuchikiki = { version = "0.8", default-features = false, optional = true }
regex = { version = "1.11.1", default-features = false, features = ["unicode-case"], optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
url = { version = "2.5", default-features = false }

[features]
default = ["serde"]
serde = ["dep:serde"]
default = [
"http",
"llm",
"bless-crawl",
"cgi",
"socket",
"memory",
"rpc",
]
mock-ffi = []
http = ["rpc", "dep:base64", "dep:serde"]
llm = ["dep:serde"]
bless-crawl = ["http", "dep:htmd", "dep:kuchikiki", "dep:regex", "dep:serde"]
cgi = []
socket = []
memory = []
rpc = ["dep:serde"]
5 changes: 2 additions & 3 deletions examples/coingecko_oracle.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use blockless_sdk::http::HttpClient;
use blockless_sdk::read_stdin;
use blockless_sdk::memory::read_stdin;
use serde_json::json;
use std::collections::HashMap;

#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug)]
#[derive(Debug, serde::Serialize)]
struct CoinPrice {
id: String,
price: u64,
Expand Down
2 changes: 1 addition & 1 deletion examples/llm-mcp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use blockless_sdk::*;
use blockless_sdk::llm::*;

/// This example demonstrates how to use the Blockless SDK to interact with two different LLM models
/// and use MCP to call the tools.
Expand Down
2 changes: 1 addition & 1 deletion examples/llm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use blockless_sdk::*;
use blockless_sdk::llm::*;

/// This example demonstrates how to use the Blockless SDK to interact with two different LLM models.
///
Expand Down
2 changes: 1 addition & 1 deletion examples/web-scrape.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use blockless_sdk::*;
use blockless_sdk::bless_crawl::*;

/// This example demonstrates how to use the Blockless SDK to perform web scraping
/// using the BlessCrawl functionality.
Expand Down
26 changes: 25 additions & 1 deletion src/cgi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::CGIErrorKind;
use json::{object::Object, JsonValue};
use std::fmt::{Debug, Display};

Expand Down Expand Up @@ -280,3 +279,28 @@ impl CGIListExtensions {
Ok(externs)
}
}

#[derive(Debug)]
pub enum CGIErrorKind {
ListError,
EncodingError,
JsonDecodingError,
ExecError,
ReadError,
NoCommandError,
}

impl std::fmt::Display for CGIErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
CGIErrorKind::ListError => write!(f, "CGI List Error."),
CGIErrorKind::EncodingError => write!(f, "CGI Encoding Error."),
CGIErrorKind::JsonDecodingError => write!(f, "Json decoding Error."),
CGIErrorKind::ExecError => write!(f, "CGI Exec Error."),
CGIErrorKind::ReadError => write!(f, "Read Error."),
CGIErrorKind::NoCommandError => write!(f, "No CGI Command Error."),
}
}
}

impl std::error::Error for CGIErrorKind {}
107 changes: 0 additions & 107 deletions src/error.rs

This file was deleted.

30 changes: 17 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
mod bless_crawl;
mod cgi;
mod error;
mod llm;
mod memory;
mod socket;
#[cfg(feature = "rpc")]
pub mod rpc;

#[cfg(feature = "cgi")]
pub mod cgi;

#[cfg(feature = "llm")]
pub mod llm;

#[cfg(feature = "memory")]
pub mod memory;

#[cfg(feature = "socket")]
pub mod socket;

#[cfg(feature = "http")]
pub mod http;
pub mod rpc;

pub use bless_crawl::*;
pub use cgi::*;
pub use error::*;
pub use llm::*;
pub use memory::*;
pub use socket::*;
#[cfg(feature = "bless-crawl")]
pub mod bless_crawl;
6 changes: 2 additions & 4 deletions src/llm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,14 @@ impl std::fmt::Display for Models {
}
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct BlocklessLlm {
inner: Handle,
model_name: String,
options: LlmOptions,
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Default, PartialEq)]
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct LlmOptions {
pub system_message: Option<String>,
pub tools_sse_urls: Option<Vec<String>>,
Expand Down
23 changes: 21 additions & 2 deletions src/socket.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::SocketErrorKind;

#[cfg(not(feature = "mock-ffi"))]
#[link(wasm_import_module = "blockless_socket")]
extern "C" {
Expand Down Expand Up @@ -42,3 +40,24 @@ pub fn create_tcp_bind_socket(addr: &str) -> Result<u32, SocketErrorKind> {
})
}
}

#[derive(Debug)]
pub enum SocketErrorKind {
ConnectRefused,
ParameterError,
ConnectionReset,
AddressInUse,
}

impl std::fmt::Display for SocketErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
SocketErrorKind::ConnectRefused => write!(f, "Connect Refused."),
SocketErrorKind::ParameterError => write!(f, "Parameter Error."),
SocketErrorKind::ConnectionReset => write!(f, "Connection Reset."),
SocketErrorKind::AddressInUse => write!(f, "Address In Use."),
}
}
}

impl std::error::Error for SocketErrorKind {}
Loading