pub struct Agent { /* private fields */ }Expand description
High-level AT Protocol agent.
Auth state lives in a single RwLock<Option<Session>>. The XRPC client
is never mutated after construction — auth headers are passed per-request.
This avoids token leaks, giant-lock contention, and split-lock atomicity
gaps that arise from storing auth in the client’s default headers.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn new(service: impl AsRef<str>) -> Result<Self, AgentError>
pub fn new(service: impl AsRef<str>) -> Result<Self, AgentError>
Create a new agent pointing at the given service URL.
Sourcepub async fn login(
&self,
identifier: &str,
password: &str,
) -> Result<Session, AgentError>
pub async fn login( &self, identifier: &str, password: &str, ) -> Result<Session, AgentError>
Log in with identifier (handle or DID) and password.
Sourcepub async fn resume_session(&self, session: Session) -> Result<(), AgentError>
pub async fn resume_session(&self, session: Session) -> Result<(), AgentError>
Resume an existing session.
Verifies the session with the server before updating internal state. If verification fails, the agent remains unauthenticated.
Sourcepub async fn refresh_session(&self) -> Result<Session, AgentError>
pub async fn refresh_session(&self) -> Result<Session, AgentError>
Refresh the current session tokens.
Uses a per-request header for the refresh call so the refresh JWT is never exposed as the global auth state. The new session is committed atomically in a single write lock.
Sourcepub async fn post(
&self,
text: &str,
facets: Option<Vec<Facet>>,
created_at: Option<&str>,
) -> Result<Value, AgentError>
pub async fn post( &self, text: &str, facets: Option<Vec<Facet>>, created_at: Option<&str>, ) -> Result<Value, AgentError>
Create a new post.
If created_at is None, the current time is used.
Sourcepub async fn post_rich(
&self,
rt: &RichText,
created_at: Option<&str>,
) -> Result<Value, AgentError>
pub async fn post_rich( &self, rt: &RichText, created_at: Option<&str>, ) -> Result<Value, AgentError>
Create a post from RichText (includes detected facets).
Sourcepub async fn delete_post(&self, uri: &str) -> Result<(), AgentError>
pub async fn delete_post(&self, uri: &str) -> Result<(), AgentError>
Delete a post by AT-URI.
Sourcepub async fn like(
&self,
uri: &str,
cid: &str,
created_at: Option<&str>,
) -> Result<Value, AgentError>
pub async fn like( &self, uri: &str, cid: &str, created_at: Option<&str>, ) -> Result<Value, AgentError>
Like a post.
If created_at is None, the current time is used.
Sourcepub async fn delete_like(&self, like_uri: &str) -> Result<(), AgentError>
pub async fn delete_like(&self, like_uri: &str) -> Result<(), AgentError>
Unlike a post by AT-URI of the like record.
Sourcepub async fn repost(
&self,
uri: &str,
cid: &str,
created_at: Option<&str>,
) -> Result<Value, AgentError>
pub async fn repost( &self, uri: &str, cid: &str, created_at: Option<&str>, ) -> Result<Value, AgentError>
Repost a post.
If created_at is None, the current time is used.
Sourcepub async fn delete_repost(&self, repost_uri: &str) -> Result<(), AgentError>
pub async fn delete_repost(&self, repost_uri: &str) -> Result<(), AgentError>
Delete a repost by AT-URI.
Sourcepub async fn follow(
&self,
subject_did: &str,
created_at: Option<&str>,
) -> Result<Value, AgentError>
pub async fn follow( &self, subject_did: &str, created_at: Option<&str>, ) -> Result<Value, AgentError>
Follow a user by DID.
If created_at is None, the current time is used.
Sourcepub async fn delete_follow(&self, follow_uri: &str) -> Result<(), AgentError>
pub async fn delete_follow(&self, follow_uri: &str) -> Result<(), AgentError>
Unfollow by AT-URI of the follow record.
Sourcepub async fn get_profile(&self, actor: &str) -> Result<Value, AgentError>
pub async fn get_profile(&self, actor: &str) -> Result<Value, AgentError>
Get a user’s profile.
Sourcepub async fn get_timeline(
&self,
limit: Option<i64>,
cursor: Option<&str>,
) -> Result<Value, AgentError>
pub async fn get_timeline( &self, limit: Option<i64>, cursor: Option<&str>, ) -> Result<Value, AgentError>
Get the home timeline.
Sourcepub async fn get_post_thread(
&self,
uri: &str,
depth: Option<i64>,
) -> Result<Value, AgentError>
pub async fn get_post_thread( &self, uri: &str, depth: Option<i64>, ) -> Result<Value, AgentError>
Get a post thread.
Sourcepub async fn search_actors(
&self,
query: &str,
limit: Option<i64>,
) -> Result<Value, AgentError>
pub async fn search_actors( &self, query: &str, limit: Option<i64>, ) -> Result<Value, AgentError>
Search actors.
Sourcepub async fn resolve_handle(&self, handle: &str) -> Result<String, AgentError>
pub async fn resolve_handle(&self, handle: &str) -> Result<String, AgentError>
Resolve a handle to a DID.
Sourcepub async fn list_notifications(
&self,
limit: Option<i64>,
cursor: Option<&str>,
) -> Result<Value, AgentError>
pub async fn list_notifications( &self, limit: Option<i64>, cursor: Option<&str>, ) -> Result<Value, AgentError>
Get notifications.
Sourcepub async fn upload_blob(
&self,
data: Vec<u8>,
content_type: &str,
) -> Result<Value, AgentError>
pub async fn upload_blob( &self, data: Vec<u8>, content_type: &str, ) -> Result<Value, AgentError>
Upload a blob (image, video, etc.).
Sourcepub async fn describe_server(&self) -> Result<Value, AgentError>
pub async fn describe_server(&self) -> Result<Value, AgentError>
Describe the server.