pub struct NodeClient {
pub api_base: String,
pub token: Option<String>,
/* private fields */
}Expand description
HTTP client for the local zerox1-node REST API.
Supports both local-node mode (POST /envelopes/send, GET /ws/inbox)
and hosted-agent mode (POST /hosted/send, GET /ws/hosted/inbox).
§Example
use zerox1_client::NodeClient;
let client = NodeClient::new("http://127.0.0.1:9090", Some("my-secret".into()));Fields§
§api_base: String§token: Option<String>Implementations§
Source§impl NodeClient
impl NodeClient
Sourcepub fn new(api_base: impl Into<String>, token: Option<String>) -> Result<Self>
pub fn new(api_base: impl Into<String>, token: Option<String>) -> Result<Self>
Create a new client. token is the ZX01_API_SECRET or a read key.
Sourcepub fn inbox_ws_url(&self) -> String
pub fn inbox_ws_url(&self) -> String
WebSocket URL for GET /ws/inbox.
Sourcepub fn hosted_inbox_ws_url(&self, hosted_token: &str) -> String
pub fn hosted_inbox_ws_url(&self, hosted_token: &str) -> String
WebSocket URL for GET /ws/hosted/inbox (hosted-agent mode).
Sourcepub async fn send_envelope(
&self,
msg_type: &str,
recipient: Option<&AgentId>,
conversation_id: &ConversationId,
payload: &[u8],
) -> Result<SendEnvelopeResponse>
pub async fn send_envelope( &self, msg_type: &str, recipient: Option<&AgentId>, conversation_id: &ConversationId, payload: &[u8], ) -> Result<SendEnvelopeResponse>
POST /envelopes/send — local-node mode.
payload is raw bytes; base64-encoding is handled internally.
Sourcepub async fn hosted_send(
&self,
hosted_token: &str,
msg_type: &str,
recipient: Option<&AgentId>,
conversation_id: &ConversationId,
payload: &[u8],
) -> Result<()>
pub async fn hosted_send( &self, hosted_token: &str, msg_type: &str, recipient: Option<&AgentId>, conversation_id: &ConversationId, payload: &[u8], ) -> Result<()>
POST /hosted/send — hosted-agent mode.
payload is raw bytes; hex-encoding is handled internally.
Sourcepub async fn listen_inbox<F, Fut>(&self, handler: F) -> Result<()>
pub async fn listen_inbox<F, Fut>(&self, handler: F) -> Result<()>
Open a GET /ws/inbox stream and call handler for each inbound envelope.
Returns when the connection closes or an error occurs. The caller is responsible for reconnect logic.
§Example
client.listen_inbox(|env| async move {
println!("{} from {}", env.msg_type, env.sender);
Ok(())
}).await.ok();Trait Implementations§
Source§impl Clone for NodeClient
impl Clone for NodeClient
Source§fn clone(&self) -> NodeClient
fn clone(&self) -> NodeClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for NodeClient
impl !RefUnwindSafe for NodeClient
impl Send for NodeClient
impl Sync for NodeClient
impl Unpin for NodeClient
impl UnsafeUnpin for NodeClient
impl !UnwindSafe for NodeClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more