Expand description
§slop-ai
Rust SDK for the SLOP protocol — let AI observe and interact with your app’s state.
§Core types
SlopServer— publish state and register affordances (actions an AI can invoke)SlopConsumer— subscribe to a provider and invoke affordances (requiresnativefeature)StateMirror— apply JSON patches and maintain a local replica of remote stateSlopNode,Affordance,PatchOp— protocol data types
§Transports
Each transport is behind a feature flag:
| Feature | Transport | Use case |
|---|---|---|
websocket | transport::websocket, WsClientTransport | Browser-compatible, cross-network |
unix | transport::unix, UnixClientTransport | Fast local IPC |
stdio | transport::stdio | CLI tools, child processes |
axum | transport::axum | Embed in an Axum HTTP server |
The native feature (on by default) enables websocket + unix + stdio.
§LLM integration
affordances_to_tools— convert affordances into OpenAI-compatible tool definitionsformat_tree— render state as Markdown for LLM context injectionprepare_tree/auto_compact— scale trees to fit token budgets
§Quick start
use slop_ai::{SlopServer, ActionOptions};
use serde_json::json;
let slop = SlopServer::new("my-app", "My App");
slop.register("todos", json!({
"type": "collection",
"props": {"count": 0},
}));
slop.action_with("todos", "add", |params| {
let text = params["text"].as_str().unwrap_or("untitled");
Ok(Some(json!({ "added": text })))
}, ActionOptions::new().label("Add todo"));
assert_eq!(slop.version(), 2);§Documentation
- Project docs: https://docs.slopai.dev/api/rust
- Integration guide: https://docs.slopai.dev/guides/rust
- crates.io docs: https://docs.rs/slop-ai
Re-exports§
pub use error::Result;pub use error::SlopError;pub use scaling::auto_compact;pub use scaling::count_nodes;pub use scaling::filter_tree;pub use scaling::get_subtree;pub use scaling::prepare_tree;pub use scaling::truncate_tree;pub use scaling::OutputTreeOptions;pub use server::ActionOptions;pub use server::Connection;pub use server::ScopedServer;pub use server::SlopServer;pub use state_mirror::StateMirror;pub use tools::affordances_to_tools;pub use tools::format_tree;pub use tools::LlmFunction;pub use tools::LlmTool;pub use tools::ToolResolution;pub use tools::ToolSet;pub use types::Affordance;pub use types::ContentRef;pub use types::ContentType;pub use types::Estimate;pub use types::NodeMeta;pub use types::PatchOp;pub use types::PatchOpKind;pub use types::SlopNode;pub use types::Urgency;pub use consumer::ClientTransport;nativepub use consumer::SlopConsumer;nativepub use transport::ws_client::WsClientTransport;websocketpub use transport::ws_accepted::AcceptedWsTransport;websocketpub use transport::unix_client::UnixClientTransport;unix
Modules§
- consumer
native - Async SLOP consumer — connects to a provider, mirrors state, and dispatches actions via a channel-based transport abstraction.
- descriptor
- Normalize developer-friendly JSON descriptors into wire-format
SlopNodes. - diff
- Recursive diff of two SLOP trees producing JSON Patch operations.
- discovery
native - error
- Error types for the SLOP SDK.
- scaling
- Tree scaling utilities: depth truncation, node-budget compaction, salience filtering, and subtree extraction.
- server
- SLOP server — manages registrations, connections, subscriptions, and message routing.
- state_
mirror - Local state mirror — applies snapshots and JSON patch ops to maintain a client-side copy of the SLOP state tree.
- tools
- LLM tool integration — convert SLOP affordances into LLM-consumable tool definitions and format trees for context injection.
- transport
- Transport implementations for connecting consumers to the SLOP server.
- tree
- Assemble a hierarchical SLOP tree from flat path-based registrations.
- types
- validate_
params - Minimal JSON Schema validator for affordance invoke params.