Skip to main content

Agent

Struct Agent 

Source
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

Source

pub fn new(service: impl AsRef<str>) -> Result<Self, AgentError>

Create a new agent pointing at the given service URL.

Source

pub fn service(&self) -> String

Get the service URL string.

Source

pub async fn did(&self) -> Option<String>

Get the current session’s DID, if logged in.

Source

pub async fn session(&self) -> Option<Session>

Get the current session, if any.

Source

pub async fn login( &self, identifier: &str, password: &str, ) -> Result<Session, AgentError>

Log in with identifier (handle or DID) and password.

Source

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.

Source

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.

Source

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.

Source

pub async fn post_rich( &self, rt: &RichText, created_at: Option<&str>, ) -> Result<Value, AgentError>

Create a post from RichText (includes detected facets).

Source

pub async fn delete_post(&self, uri: &str) -> Result<(), AgentError>

Delete a post by AT-URI.

Source

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.

Source

pub async fn delete_like(&self, like_uri: &str) -> Result<(), AgentError>

Unlike a post by AT-URI of the like record.

Source

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.

Source

pub async fn delete_repost(&self, repost_uri: &str) -> Result<(), AgentError>

Delete a repost by AT-URI.

Source

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.

Source

pub async fn delete_follow(&self, follow_uri: &str) -> Result<(), AgentError>

Unfollow by AT-URI of the follow record.

Source

pub async fn get_profile(&self, actor: &str) -> Result<Value, AgentError>

Get a user’s profile.

Source

pub async fn get_timeline( &self, limit: Option<i64>, cursor: Option<&str>, ) -> Result<Value, AgentError>

Get the home timeline.

Source

pub async fn get_post_thread( &self, uri: &str, depth: Option<i64>, ) -> Result<Value, AgentError>

Get a post thread.

Source

pub async fn search_actors( &self, query: &str, limit: Option<i64>, ) -> Result<Value, AgentError>

Search actors.

Source

pub async fn resolve_handle(&self, handle: &str) -> Result<String, AgentError>

Resolve a handle to a DID.

Source

pub async fn list_notifications( &self, limit: Option<i64>, cursor: Option<&str>, ) -> Result<Value, AgentError>

Get notifications.

Source

pub async fn upload_blob( &self, data: Vec<u8>, content_type: &str, ) -> Result<Value, AgentError>

Upload a blob (image, video, etc.).

Source

pub async fn describe_server(&self) -> Result<Value, AgentError>

Describe the server.

Auto Trait Implementations§

§

impl Freeze for Agent

§

impl !RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

§

impl !UnwindSafe for Agent

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more