Skip to content

Add regional endpoint selection with GatewayArea support#1

Closed
fern-support wants to merge 6 commits into
mainfrom
devin/1765317048-regional-client
Closed

Add regional endpoint selection with GatewayArea support#1
fern-support wants to merge 6 commits into
mainfrom
devin/1765317048-regional-client

Conversation

@fern-support

@fern-support fern-support commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator

Add regional endpoint selection with GatewayArea support

Summary

Adds area-based URL selection to the TypeScript SDK, mirroring the pattern implemented in the Go SDK. Users can now specify a gatewayArea (US, EU, APAC, CN) when creating a client to automatically connect to the optimal regional endpoint.

Key changes:

  • src/area.ts: Defines GatewayArea type and RegionalEndpointPool class with region cycling support
  • src/RegionalClient.ts: Wrapper client that adds gatewayArea and endpointPool options
  • src/index.ts: Exports the wrapper as AgoraClient (backwards compatible) plus new GatewayArea and RegionalEndpointPool exports
  • .fernignore: Protects manually added files from Fern regeneration

Usage:

import { AgoraClient, GatewayArea } from "agora-sdk";

const client = new AgoraClient({
    gatewayArea: GatewayArea.US,
    username: "...",
    password: "...",
});

Note: Unlike the Go SDK, DNS-based domain selection is intentionally omitted for browser compatibility. The TS SDK uses a fixed priority order instead.

Updates since last revision

  • Fixed regional URL path: Added /api/conversational-ai-agent suffix to getCurrentUrl() to match the default environment URL structure
  • Fixed TypeScript type error: Refactored RegionalClient.ts constructor to capture endpointPool in a narrowed const pool variable, ensuring the baseUrl supplier returns string instead of string | undefined
  • Merged main with pagination type fix: Incorporated the SDK regeneration from fern-config PR#1 which fixed the Cannot find namespace 'undefined' build errors
  • Fixed pre-existing test bug: Updated agents.test.ts to use a non-empty cursor value for pagination test (empty cursor "" correctly returns hasNextPage() = false, matching the telephony test pattern)

Review & Testing Checklist for Human

  • Verify region configuration matches Go SDK: Compare REGION_DOMAIN_CONFIG in area.ts against the Go SDK's RegionDomain map to ensure prefixes and suffixes are identical
  • Test backwards compatibility: Existing code using AgoraClient without gatewayArea should continue to work unchanged
  • Test regional endpoint selection: Create a client with gatewayArea: GatewayArea.US and verify requests go to https://api-us-west-1.agora.io/api/conversational-ai-agent
  • Verify baseUrl supplier logic: In RegionalClient.ts, confirm the const pool = endpointPool narrowing correctly captures the pool before creating the supplier function

Recommended test plan:

  1. Install the SDK locally and create a client without gatewayArea - verify it uses the default environment
  2. Create a client with each GatewayArea value and log/inspect the base URL being used
  3. Test nextRegion() cycling behavior on the endpoint pool

Notes

Link to Devin run: https://app.devin.ai/sessions/3f033f4523f94c2384477ddfc79d00a8
Requested by: blank@buildwithfern.com (@fern-support)

- Add area.ts with GatewayArea type (US, EU, APAC, CN) and RegionalEndpointPool class
- Add RegionalClient.ts with RegionalAgoraClient wrapper client
- Update index.ts to export wrapper client as AgoraClient
- Export GatewayArea and RegionalEndpointPool for advanced usage
- Support region cycling for failover scenarios
- Update .fernignore to protect manually added files

Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration Bot and others added 5 commits December 9, 2025 22:00
Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
@digitallysavvy

Copy link
Copy Markdown
Collaborator

@fern-support is this still needed?

@digitallysavvy
digitallysavvy deleted the devin/1765317048-regional-client branch March 10, 2026 00:02
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