pub struct Relay {
pub base_dir: PathBuf,
}Expand description
The main relay hub. All operations are local filesystem — no network.
Create one per repo/project with a shared base_dir path. Every agent
that uses the same path will see each other’s messages.
Fields§
§base_dir: PathBufImplementations§
Source§impl Relay
impl Relay
Sourcepub fn new(base_dir: PathBuf) -> Self
pub fn new(base_dir: PathBuf) -> Self
Create a new relay rooted at the given directory.
Typical usage: Relay::new(".relay".into()) at the repo root.
All agents must use the same path to see each other.
Sourcepub fn register(
&self,
agent_id: &str,
session_id: &str,
pid: u32,
) -> AgentRegistration
pub fn register( &self, agent_id: &str, session_id: &str, pid: u32, ) -> AgentRegistration
Register an agent so others can discover it.
Sourcepub fn register_with_metadata(
&self,
agent_id: &str,
session_id: &str,
pid: u32,
metadata: Value,
) -> AgentRegistration
pub fn register_with_metadata( &self, agent_id: &str, session_id: &str, pid: u32, metadata: Value, ) -> AgentRegistration
Register with custom metadata (model name, capabilities, etc).
Sourcepub fn heartbeat(&self, session_id: &str)
pub fn heartbeat(&self, session_id: &str)
Update heartbeat to signal this agent is still alive.
Sourcepub fn unregister(&self, session_id: &str)
pub fn unregister(&self, session_id: &str)
Unregister an agent (cleanup on exit).
Sourcepub fn agents(&self) -> Vec<AgentRegistration>
pub fn agents(&self) -> Vec<AgentRegistration>
List all registered agents.
Sourcepub fn cleanup_dead(&self) -> usize
pub fn cleanup_dead(&self) -> usize
Remove registrations for agents whose PID is no longer alive.
Sourcepub fn send(
&self,
from_session: &str,
from_agent: &str,
to_session: Option<&str>,
content: &str,
) -> Message
pub fn send( &self, from_session: &str, from_agent: &str, to_session: Option<&str>, content: &str, ) -> Message
Send a message. to_session: None = broadcast to all agents.
Sourcepub fn inbox(&self, session_id: &str, limit: usize) -> Vec<(Message, bool)>
pub fn inbox(&self, session_id: &str, limit: usize) -> Vec<(Message, bool)>
Read inbox: returns messages with a flag indicating if newly read. Marks all returned messages as read by this session.
Sourcepub fn unread(&self, session_id: &str) -> Vec<Message>
pub fn unread(&self, session_id: &str) -> Vec<Message>
Get unread messages without marking them as read.
Sourcepub fn unread_count(&self, session_id: &str) -> u64
pub fn unread_count(&self, session_id: &str) -> u64
Count unread messages for a session.
Sourcepub fn cleanup_old(&self, max_age_secs: u64) -> usize
pub fn cleanup_old(&self, max_age_secs: u64) -> usize
Delete messages older than max_age_secs.