Skip to content

Commit f7594f8

Browse files
committed
fix(sdk-core): remove @atproto/xrpc import to eliminate build warning
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.
1 parent 7e6edea commit f7594f8

File tree

3 files changed

+72
-6
lines changed

3 files changed

+72
-6
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
"@hypercerts-org/sdk-core": minor
3+
---
4+
5+
Implement ConfigurableAgent for proper multi-server routing
6+
7+
This release introduces the `ConfigurableAgent` class that enables proper routing of AT Protocol requests to different servers (PDS, SDS, or custom instances) while maintaining OAuth authentication from a single session.
8+
9+
**Breaking Changes:**
10+
- Repository now uses `ConfigurableAgent` internally instead of standard `Agent`
11+
- This fixes the issue where invalid `agent.service` and `agent.api.xrpc.uri` property assignments were causing TypeScript errors
12+
13+
**New Features:**
14+
- `ConfigurableAgent` class exported from `@hypercerts-org/sdk-core`
15+
- Support for simultaneous connections to multiple SDS instances with one OAuth session
16+
- Proper request routing based on configured service URL rather than session defaults
17+
18+
**Bug Fixes:**
19+
- Remove invalid Agent property assignments that caused TypeScript compilation errors (TS2339)
20+
- Replace all `any` types in test files with proper type annotations
21+
- Eliminate build warnings from missing type declarations
22+
23+
**Architecture:**
24+
The new routing system wraps the OAuth session's fetch handler to prepend the target server URL, ensuring requests go to the intended destination while maintaining full authentication (DPoP, access tokens, etc.). This enables use cases like:
25+
- Routing to SDS while authenticated via PDS
26+
- Accessing multiple organization SDS instances simultaneously
27+
- Testing against different server environments
28+
- Dynamic switching between PDS and SDS operations
29+
30+
**Migration:**
31+
No action required - the change is transparent to existing code. The Repository API remains unchanged.

packages/sdk-core/README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ await orgRepo.hypercerts.list(); // Queries organization's hypercerts on SDS
7777

7878
#### How Repository Routing Works
7979

80-
When you create or switch repositories, the SDK ensures requests are routed to the correct server:
80+
The SDK uses a `ConfigurableAgent` to route requests to different servers while maintaining your OAuth authentication:
8181

8282
1. **Initial Repository Creation**
8383
```typescript
@@ -105,10 +105,11 @@ When you create or switch repositories, the SDK ensures requests are routed to t
105105
```
106106

107107
3. **Key Implementation Details**
108-
- The SDK configures the AT Protocol Agent's service URL when creating repositories
109-
- When you call `.repo(did)`, a new Repository instance is created that maintains the same server URL
110-
- This ensures that even when querying different DIDs, requests go to the intended server
111-
- User's OAuth session provides authentication, but doesn't determine routing
108+
- Each Repository uses a `ConfigurableAgent` that wraps your OAuth session's fetch handler
109+
- The agent routes all requests to the specified server URL (PDS, SDS, or custom)
110+
- When you call `.repo(did)`, a new Repository is created with the same server configuration
111+
- Your OAuth session provides authentication (DPoP, access tokens), while the agent handles routing
112+
- This enables simultaneous connections to multiple servers with one authentication session
112113

113114
#### Common Patterns
114115

@@ -549,6 +550,35 @@ try {
549550

550551
## Advanced Usage
551552

553+
### Multi-Server Routing with ConfigurableAgent
554+
555+
The `ConfigurableAgent` allows you to create custom agents that route to specific servers:
556+
557+
```typescript
558+
import { ConfigurableAgent } from "@hypercerts-org/sdk-core";
559+
560+
// Authenticate once with your PDS
561+
const session = await sdk.callback(params);
562+
563+
// Create agents for different servers using the same session
564+
const pdsAgent = new ConfigurableAgent(session, "https://bsky.social");
565+
const sdsAgent = new ConfigurableAgent(session, "https://sds.hypercerts.org");
566+
const orgAgent = new ConfigurableAgent(session, "https://sds-org-a.example.com");
567+
568+
// Use agents directly with AT Protocol APIs
569+
await pdsAgent.com.atproto.repo.createRecord({...});
570+
await sdsAgent.com.atproto.repo.listRecords({...});
571+
572+
// Or pass to Repository for high-level operations
573+
// (Repository internally uses ConfigurableAgent)
574+
```
575+
576+
This is useful for:
577+
- Connecting to multiple SDS instances simultaneously
578+
- Testing against different server environments
579+
- Building tools that work across multiple organizations
580+
- Direct AT Protocol API access with custom routing
581+
552582
### Custom Session Storage
553583

554584
```typescript

packages/sdk-core/src/agent/ConfigurableAgent.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
*/
99

1010
import { Agent } from "@atproto/api";
11-
import type { FetchHandler } from "@atproto/xrpc";
1211
import type { Session } from "../core/types.js";
1312

13+
/**
14+
* FetchHandler type - function that makes HTTP requests with authentication.
15+
* Takes a pathname and request init, returns a Response promise.
16+
*/
17+
type FetchHandler = (pathname: string, init: RequestInit) => Promise<Response>;
18+
1419
/**
1520
* Agent subclass that routes requests to a configurable service URL.
1621
*

0 commit comments

Comments
 (0)