Skip to content

Conversation

@bitbeckers
Copy link
Contributor

Fix TypeScript errors and implement ConfigurableAgent for multi-server routing

Summary

This PR fixes TypeScript compilation errors and implements proper multi-server routing using a new ConfigurableAgent class, enabling reliable PDS/SDS separation and multi-SDS support.

Changes

🐛 Bug Fixes

  • Remove invalid agent.service and agent.api.xrpc.uri property assignments causing TS2339 errors
  • Replace all any types in test files with proper type annotations
  • Eliminate build warnings from @atproto/xrpc import

✨ New Features

  • ConfigurableAgent class for routing requests to configurable service URLs
  • Support for simultaneous connections to multiple servers with one OAuth session
  • Proper request routing based on configured server URL rather than session defaults

📝 Documentation

  • Updated README "How Repository Routing Works" section
  • Added "Multi-Server Routing with ConfigurableAgent" to Advanced Usage
  • Comprehensive changeset describing changes and architecture

Architecture

ConfigurableAgent wraps the OAuth session's fetch handler to prepend the target server URL, ensuring requests route to the intended destination while maintaining full authentication (DPoP, access tokens, etc.).

Use Cases

  • Route to SDS while authenticated via PDS
  • Access multiple organization SDS instances simultaneously
  • Test against different server environments
  • Dynamic switching between PDS and SDS operations

…PDS/SDS)

When using OAuth to access organization repositories on SDS via repo.repo(orgDid),
operations were incorrectly routing to the user's PDS instead of the SDS server.

Root cause: Agent was created from OAuth session but only had api.xrpc.uri configured.
Without setting agent.service, it continued using session's default PDS URL.

Solution: Set both agent.service and agent.api.xrpc.uri in Repository constructor
to ensure all operations route to the specified server URL.

Affected operations:
- HypercertOperationsImpl: list(), listCollections(), get(), create()
- RecordOperationsImpl: all CRUD operations
- ProfileOperationsImpl: get(), update()
- BlobOperationsImpl: upload(), get()

Also added comprehensive PDS/SDS orchestration documentation to README covering
server types, routing mechanics, and common usage patterns.

Fixes: Repository operations on organization repos routing to user's PDS
Location: packages/sdk-core/src/repository/Repository.ts:188
… type safety

- Remove non-existent agent.service and agent.api.xrpc.uri property assignments
  that were causing TypeScript errors (TS2339)
- Agent service URL is properly configured through Session's fetch handler
- Replace 'any' types in test files with proper types (Partial<Agent>, Partial<Session>)
- Use createMockSession() helper for consistent test mocking
- All builds, lints, and tests now pass without warnings

Fixes: TypeScript compilation errors in Repository.ts:189-190
Fixes: ESLint @typescript-eslint/no-explicit-any warnings in test files
Add ConfigurableAgent class that extends Agent to support routing requests
to configurable service URLs, enabling proper PDS/SDS separation and
multi-SDS support.

Key features:
- ConfigurableAgent wraps session's fetch handler to route to custom URL
- Repository now uses ConfigurableAgent instead of standard Agent
- Supports multiple SDS instances with same OAuth session
- Maintains all authentication (DPoP, OAuth) from original session

Architecture:
- Agent's service URL is determined by FetchHandler, not modifiable properties
- ConfigurableAgent creates custom FetchHandler that prepends target URL
- Session's fetch handler provides authentication layer
- Enables: user@PDS accessing orgA@SDS and orgB@SDS simultaneously

Use cases:
- Route to SDS while authenticated via PDS
- Access multiple organization SDS instances
- Test against different server environments
- Switch between PDS and SDS operations dynamically

Resolves the issue where invalid agent.service and agent.api.xrpc.uri
property assignments were attempted. The proper solution is to wrap
the fetch handler at Agent construction time.

Related: #59, implements pattern from hypercerts-org/atproto sds-demo
Define FetchHandler type locally instead of importing from @atproto/xrpc
to avoid TypeScript warning about missing type declarations during build.
The type definition is simple and stable, so local definition is preferred.
@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2025

🦋 Changeset detected

Latest commit: f7594f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@hypercerts-org/sdk-core Minor
@hypercerts-org/sdk-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bitbeckers bitbeckers self-assigned this Dec 4, 2025
@bitbeckers bitbeckers merged commit e2c87ff into develop Dec 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants