Agent Module#
Purpose#
This module manages the authenticated session for the moderation bot. It acts as a wrapper around the jacquard library's client to provide a simple, shareable session object for making authenticated API calls to the Bluesky network.
Key Components#
session.rs#
AgentSession: A thread-safe, cloneable struct that holds the authenticated state.- It contains an
Arc<Agent<MemoryCredentialSession>>, which is the core authenticated client fromjacquard. - It also holds the DID (
Arc<str>) of the authenticated user for easy access.
- It contains an
Key Methods#
AgentSession::new(config): An async constructor that creates a new session by authenticating with the PDS using the handle and password from the application'sConfig.agent(): Returns a reference to the underlyingArc<Agent<...>>, which is used to make XRPC calls.did(): Returns a&strslice of the authenticated user's DID.
Session Flow#
The jacquard library handles all session management internally, including token storage and refresh logic. The flow is now much simpler:
AgentSession::new()is called once at application startup.- This single call handles the entire authentication process, storing the session details within the
MemoryCredentialSession. - The resulting
AgentSessioninstance is cloned and shared across all worker threads. - The underlying
jacquard::Agentautomatically managesaccess_jwtandrefresh_jwttokens, refreshing them as needed when API calls are made.
Dependencies#
jacquard: Provides the core client, session management, and authentication logic.miette: For error handling.crate::config::Config: To access the bot's credentials.
Related Modules#
- Used by:
main.rsto create the initial session, andqueue/worker.rswhere workers use the cloned session to perform moderation actions.