ahp-ws 0.5.2

WebSocket transport adapter for the Agent Host Protocol SDK.
Documentation

ahp-ws

WebSocket transport for the Agent Host Protocol (AHP) Rust SDK.

crates.io docs.rs

Implements ahp::Transport using tokio-tungstenite, supporting both ws:// and wss://.

Usage

[dependencies]
ahp = "0.1"
ahp-ws = "0.1"
tokio = { version = "1", features = ["full"] }
use ahp::{Client, ClientConfig, SubscriptionEvent};
use ahp_ws::WebSocketTransport;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let transport = WebSocketTransport::connect("ws://localhost:12345").await?;
    let client = Client::connect(transport, ClientConfig::default()).await?;

    client.initialize("my-client".into(), vec![ahp_types::PROTOCOL_VERSION.to_string()], vec![ahp_types::ROOT_RESOURCE_URI.to_string()]).await?;

    let mut sub = client.attach_subscription(ahp_types::ROOT_RESOURCE_URI).await;
    while let Some(SubscriptionEvent::Action(a)) = sub.recv().await {
        println!("{:?}", a.action);
    }

    client.shutdown().await;
    Ok(())
}

API

TLS backends

wss:// support is selected by Cargo feature. The default is rustls-tls-native-roots: a pure-Rust TLS stack (no OpenSSL on Linux) with roots loaded from the OS trust store, so dials through a TLS-intercepting egress proxy keep working. Override it with default-features = false and pick one:

Feature TLS stack Trust roots
rustls-tls-native-roots (default) rustls (pure Rust) OS trust store
rustls-tls-webpki-roots rustls (pure Rust) bundled Mozilla roots
native-tls platform (SChannel / Secure Transport / OpenSSL) OS trust store

With no TLS feature enabled, only ws:// works; wss:// fails at connect time. The rustls backends use the ring crypto provider. If more than one backend ends up enabled (e.g. via Cargo feature unification across the dependency graph), native-tls takes precedence, since tokio-tungstenite's automatic connector prefers it.

See also