Skip to content

🤖 [Experimental] SDK Quality Improvements - Error Types, Docs & Timeout Support#114

Open
jeffzwang wants to merge 2 commits intomasterfrom
claude-code/sdk-quality-improvements
Open

🤖 [Experimental] SDK Quality Improvements - Error Types, Docs & Timeout Support#114
jeffzwang wants to merge 2 commits intomasterfrom
claude-code/sdk-quality-improvements

Conversation

@jeffzwang
Copy link
Copy Markdown
Contributor

⚠️ Experimental PR - Generated by Claude Code

This PR was autonomously generated by Claude Code at @jwang's request. It's an experimental effort to improve SDK quality based on a comprehensive audit. Please review carefully!


Summary

This PR addresses several quality improvements identified in an SDK audit:

  • Add specialized error types - RateLimitError, AuthenticationError, ValidationError, TimeoutError, NotFoundError, ServerError with relevant metadata
  • Document ResearchClient - Added comprehensive JSDoc to all 8 public methods (was 0% documented)
  • Add streaming timeout support - streamAnswer() now supports timeoutMs option with proper AbortController handling
  • Modernize README - Complete rewrite with current API patterns, removed deprecated method examples
  • Add Node.js version requirement - engines.node >= 18.0.0

Changes by File

File Changes
src/errors.ts +124 lines - 6 new error subclasses
src/research/client.ts +182 lines - Complete JSDoc coverage
src/index.ts +109 lines - Timeout support, @throws docs
README.md Rewritten - Modern examples, error handling section
package.json +3 lines - engines field

Error Types Added

import { 
  RateLimitError,      // 429 - includes retryAfter
  AuthenticationError, // 401 - invalid API key
  ValidationError,     // 400 - includes field, constraint  
  TimeoutError,        // 408 - includes timeoutMs
  NotFoundError,       // 404 - includes resourceId
  ServerError          // 500/503 - includes retryable boolean
} from "exa-js";

New Streaming Timeout

// Now supports timeout to prevent hung connections
for await (const chunk of exa.streamAnswer("query", {
  timeoutMs: 30000 // 30 second timeout (default: 60s)
})) {
  // ...
}

Test plan

  • All 65 unit tests passing
  • Build successful (CJS, ESM, DTS outputs)
  • TypeScript compilation successful
  • Manual testing of error types in real API calls
  • Manual testing of streaming timeout behavior

🤖 Generated with Claude Code

jeffzwang and others added 2 commits December 20, 2025 21:05
This PR includes several improvements identified in an SDK quality audit:

## Changes

### Error Handling
- Add specialized error subclasses: RateLimitError, AuthenticationError,
  ValidationError, TimeoutError, NotFoundError, ServerError
- Each error type includes relevant metadata (retryAfter, field, timeoutMs, etc.)

### Documentation
- Complete JSDoc documentation for ResearchClient (was 0% documented)
- Add @throws annotations to key methods
- Comprehensive README rewrite with modern API patterns
- Remove deprecated method examples (searchAndContents, findSimilarAndContents)

### Streaming
- Add configurable timeout support to streamAnswer() via timeoutMs option
- Implement AbortController for proper stream cancellation
- Add per-read timeout protection to prevent hung connections

### Package
- Add engines field requiring Node.js >= 18.0.0

## Testing
- All 65 unit tests passing
- Build successful (CJS, ESM, DTS)

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use type erasure via Function to avoid excessively deep type instantiation
  when zod-to-json-schema's complex recursive types interact with TypeScript
- Use repo-local TypeScript (npx tsc) instead of globally installed version
  in CI workflow for consistent compilation behavior

Co-Authored-By: conrad@exa.ai <conradsoon@gmail.com>
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.

1 participant