A rust implementation of skywatch-phash
README.md

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 from jacquard.
    • It also holds the DID (Arc<str>) of the authenticated user for easy access.

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's Config.
  • agent(): Returns a reference to the underlying Arc<Agent<...>>, which is used to make XRPC calls.
  • did(): Returns a &str slice 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:

  1. AgentSession::new() is called once at application startup.
  2. This single call handles the entire authentication process, storing the session details within the MemoryCredentialSession.
  3. The resulting AgentSession instance is cloned and shared across all worker threads.
  4. The underlying jacquard::Agent automatically manages access_jwt and refresh_jwt tokens, 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.
  • Used by: main.rs to create the initial session, and queue/worker.rs where workers use the cloned session to perform moderation actions.