atproto.dart SDK

repository·main·Indexed 42 days ago

https://github.com/myconsciousness/atproto.dart

A comprehensive Dart/Flutter SDK for the AT Protocol ecosystem. It provides tools for building Bluesky-compatible social apps, bots, and backend services through packages including at_primitives for URI and NSID handling, atproto_core for session management and XRPC clients, atproto_identity for DID and handle resolution, and atproto_oauth for authentication.

Tokens
354.7K
Snippets
1.2K
Records
1.6K
Agent score
52%

What's inside atproto.dart

  1. What is lex_gen?

    main

    lex_gen is a Lexicon-to-Dart code generator that transforms Lexicon schema documents into Dart source code. It is the engine behind the atproto, bluesky, and bluesky_cli packages in this repository, ensuring the API surface remains in sync with the AT Protocol.

    It is a library intended for use within a build script (like scripts/gen_codes.dart) rather than a standalone CLI tool.

    Note: If you only need to parse or validate Lexicon documents at runtime, use the lexicon package instead.

  2. Overview of atproto.dart

    main

    atproto.dart is a comprehensive Dart and Flutter SDK designed for the AT Protocol ecosystem. It enables developers to build decentralized social applications, including mobile apps, web applications, bots, and backend services that integrate with Bluesky and other AT Protocol-compliant platforms.

    Key Capabilities

    Mobile & Web Development

    • Build cross-platform social apps using Flutter.
    • Access the full Bluesky API (posts, feeds, profiles, messaging, and moderation).
    • Use built-in OAuth DPoP authentication for secure user sessions.

    Backend & Bot Development

    • Create automation tools and bots.
    • Process real-time data streams via an optimized Firehose implementation.
    • Build custom AT Protocol services and platform bridges.
    • Access Ozone moderation tools for administrative tasks.

    Protocol Primitives

    • Work directly with core AT Protocol primitives: DIDs, NSIDs, AT URIs, Lexicons, and XRPC.
  3. Overview of the Feed Generator Template

    main

    The Feed Generator Template is a clone-and-edit template for building custom Bluesky feed generators. A feed generator is an HTTP service that Bluesky's AppView calls to retrieve an ordered list of post URIs (a "skeleton").

    Key components included in the template:

    • bin/server.dart: Serves the required AppView endpoints (/.well-known/did.json, app.bsky.feed.describeFeedGenerator, and app.bsky.feed.getFeedSkeleton) and verifies inbound service-auth JWTs via atproto_identity.
    • bin/publish_feed.dart: Registers the feed on the network by writing an app.bsky.feed.generator record.
    • Firehose Indexer (lib/src/indexer/): Ingests new posts and handles reconnections with exponential backoff.
    • FeedAlgorithm interface: Defines how posts are ranked. The template includes a whats_hot_algorithm.dart implementation (reverse-chronological sample) which you should replace with your own logic.
    • FeedStore interface: Defines how posts are stored. The template uses an in-memory implementation that you should swap for a database in production.
  4. Overview of atproto.dart packages

    main

    The atproto.dart ecosystem consists of modular packages designed for different levels of the AT Protocol stack:

    • bluesky: The primary toolkit for Bluesky-specific features like posts, feeds, chat, and moderation. Use this to start building social apps.
    • atproto: Core AT Protocol support for building services beyond Bluesky.
    • atproto_oauth: Implementation of OAuth 2.0 with DPoP for secure user sign-in.
    • bluesky_text: Utilities for facet detection and accurate post-length counting.
    • bluesky_cli: A command-line interface to interact with the APIs from your terminal.

    Lower-level dependencies like at_primitives, xrpc, and multiformats are included automatically when using the higher-level packages.

  5. Explore the atproto.dart package ecosystem

    main

    The atproto.dart ecosystem is modular, allowing you to select specific packages based on your project's requirements. The ecosystem is divided into Core Libraries, Client Libraries, Utilities, a CLI tool, and GitHub Actions workflows.

    Core Libraries

    Use these for low-level AT Protocol primitives and data structures:

    • at_primitives: Unified package for AT Protocol primitive types (identifiers, URIs, NSIDs).
    • xrpc: XRPC HTTP client featuring built-in retry and error handling.
    • multiformats: Support for IPFS multiformats (CIDs, multihash, etc.).
    • lexicon: Schema parsing and validation for Lexicons.
    • atproto_core: Shared utilities and base functionality for AT Protocol clients.

    Client Libraries

    Use these for high-level interaction with AT Protocol services:

    • atproto: Complete AT Protocol client (covering com.atproto.* endpoints) with Firehose support.
    • bluesky: Full-featured Bluesky client (covering app.bsky.*, chat.bsky.*, and AT Protocol).
    • atproto_oauth: OAuth DPoP authentication client for secure user sessions.
    • did_plc: PLC Directory client for DID resolution and management.
    • atproto_identity: Identity resolution (handle/DID → PDS + signing key) and service-auth JWT verification.

    Utilities & Tools

    • bluesky_text: Rich text parsing for mentions, links, hashtags, and formatting.
    • bluesky_text_flutter: Flutter widgets for bluesky_text, including a rich-text editing controller and a post viewer.
    • bluesky_cli: A command line tool for interacting with app.bsky.* endpoints.
  6. Understand the xrpc package purpose and selection

    main

    The xrpc package implements the XRPC request layer of the AT Protocol. It is a thin wrapper around package:http that handles NSID-based addressing under /xrpc/, parses {error, message} error bodies, and processes ratelimit-* headers.

    When to use xrpc directly:

    • Calling a lexicon method not covered by the generated atproto or bluesky packages (including your own).
    • Subscribing to an event stream that lacks a wrapper method.
    • Writing a client for a service that speaks XRPC but is not a PDS or AppView.

    When to use other packages:

    • For com.atproto.* endpoints: use atproto.
    • For app.bsky.* or chat.bsky.* endpoints: use bluesky.
    • For sessions, retries, and the request pipeline: use atproto_core.
  7. Key features of atproto

    main

    The atproto package provides the following core capabilities:

    • Comprehensive API Coverage: Supports all major com.atproto.* endpoints.
    • Service Agnostic: Works with any AT Protocol service, not just Bluesky.
    • Multiple Authentication Methods: Supports session-based auth (with transparent refresh), OAuth 2.0 with DPoP, and anonymous access.
    • Real-time Firehose API: Provides typed, decoded streams of live events from AT Protocol services.
    • Pluggable Retry: Includes an idempotency-safe Exponential BackOff And Jitter policy via a RetryStrategy interface.
    • Rate Limit Handling: Built-in detection and management of rate limits.
    • Injectable Transport: Allows supplying a custom HTTP client for testing, proxies, or tracing.
    • Type Safety: 100% null safety with support for complex AT Protocol union types.
  8. Key features of the bluesky package

    main

    The bluesky package provides several high-level capabilities for Bluesky development:

    • Social Graph & Feed Operations: Management of posts, likes, reposts, timelines, follows, blocks, mutes, and lists.
    • Chat API: Full support for conversation management and messaging (chat.bsky.*).
    • Real-time Data: Support for the Firehose API for streaming data.
    • Notifications: A rich notification system including client-side notification grouping that matches the official Bluesky app.
    • Media: Video upload support with status tracking and limits management.
    • Security: Support for OAuth DPoP for secure authentication.
    • Reliability: Built-in retry logic using Exponential BackOff and Jitter with a pluggable RetryStrategy.
    • Moderation: Comprehensive Moderation API for labeling and reporting.
  9. Understand list purposes in app.bsky.graph.defs

    main

    Lists in the graph lexicon serve three primary purposes:

    • modlist: A list of actors used to apply aggregate moderation actions like muting or blocking.
    • curatelist: A list of actors used for curation, such as powering list feeds or gating interactions.
    • referencelist: A list of actors used strictly for reference purposes, such as within a starter pack.
    | Property | Type | Known Values | Required | Description |
    | --- | --- | --- | :---: | --- |
    | **listPurpose** | string | [app.bsky.graph.defs#modlist](../../../../lexicons/app/bsky/graph/defs.md#modlist)<br/>[app.bsky.graph.defs#curatelist](../../../../lexicons/app/bsky/graph/defs.md#curatelist)<br/>[app.bsky.graph.defs#referencelist](../../../../lexicons/app/bsky/graph/defs.md#referencelist) | ❌ | -
  10. Configure post replies using replyRef

    main

    To create a reply in a Bluesky thread, include a reply object in your app.bsky.feed.post record. This object uses the replyRef structure, which requires two com.atproto.repo.strongRef references:

    • root: The reference to the very first post in the thread.
    • parent: The reference to the post being directly replied to.

    Both root and parent are required for a valid reply structure.

  11. Handle video processing job states

    main

    When monitoring a video processing job via app.bsky.video.defs.jobStatus, use the state property to determine the current lifecycle stage.

    Known States:

    • JOB_STATE_CREATED
    • JOB_STATE_ENCODING
    • JOB_STATE_ENCODED
    • JOB_STATE_SCANNING
    • JOB_STATE_SCANNED
    • JOB_STATE_UPLOADING
    • JOB_STATE_UPLOADED
    • JOB_STATE_COMPLETED
    • JOB_STATE_FAILED

    Note: Any value received that is not explicitly listed above indicates the job is currently in an active processing state.