agent
XRPC agent for atiproto endpoints. Wraps @atproto/api, transparently runs the workflow protocol on every call (record writes get executed against the user's PDS as the server emits them), and exposes utility methods like com.appendBroker for tasks that don't fit a single XRPC call.
Installation
bash
npm install @atiproto/agent
Construction
Construct from a SessionManager, FetchHandler, or another XrpcClient. The agent proxies through to the underlying client for everything it doesn't handle itself.
typescript
import { Agent } from "@atiproto/agent";import { AtpAgent } from "@atproto/api";const upstream = new AtpAgent({ service: "https://pds.example" });await upstream.login({ identifier: "alice.example", password });const agent = new Agent(upstream);// Now agent.com.atiproto.* hits the PoS via the atproto-proxy header,// and the workflow interpreter handles record writes against the PDS.
Attestation
Pass an Attestation (or options for one) to sign records that the workflow interpreter writes to the PDS. The fields included in the canonical signing payload come from signature_scope_collections for each known collection.
typescript
const agent = new Agent(upstream, {attestation: {privateKey: process.env.APPVIEW_KEY!,role: "appview",issuer: "did:web:appview.example",},});
Utility methods
- com.appendBroker: add or promote a broker on the authenticated user's DID document via the standard PLC signing flow.
Related
- atproto-attestation: sign and verify records.
- Checkout Flow: end-to-end purchase example built on the agent.