Skip to main content

Crate slop_ai

Crate slop_ai 

Source
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 (requires native feature)
  • StateMirror — apply JSON patches and maintain a local replica of remote state
  • SlopNode, Affordance, PatchOp — protocol data types

§Transports

Each transport is behind a feature flag:

FeatureTransportUse case
websockettransport::websocket, WsClientTransportBrowser-compatible, cross-network
unixtransport::unix, UnixClientTransportFast local IPC
stdiotransport::stdioCLI tools, child processes
axumtransport::axumEmbed in an Axum HTTP server

The native feature (on by default) enables websocket + unix + stdio.

§LLM integration

§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

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;native
pub use consumer::SlopConsumer;native
pub use transport::ws_client::WsClientTransport;websocket
pub use transport::ws_accepted::AcceptedWsTransport;websocket
pub use transport::unix_client::UnixClientTransport;unix

Modules§

consumernative
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.
discoverynative
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.