Skip to content

Add retry logic with exponential backoff and request/response hooks#11

Merged
ryandao merged 4 commits intomainfrom
rin/client
Apr 14, 2026
Merged

Add retry logic with exponential backoff and request/response hooks#11
ryandao merged 4 commits intomainfrom
rin/client

Conversation

@ryandao
Copy link
Copy Markdown
Owner

@ryandao ryandao commented Apr 14, 2026

Summary

  • Retry with exponential backoff: Configurable via retry option in AgentQConfig. Uses full jitter, retries on 429/5xx and network/timeout errors by default. Retryable status codes are customizable.
  • Request hooks: client.onRequest((method, url, headers) => ...) for pre-request logging, metrics, or header injection
  • Response hooks: client.onResponse((method, url, status, durationMs) => ...) for post-response latency tracking
  • Chainable API: onRequest/onResponse return this for builder-style chaining
  • Exported types: RequestHook, ResponseHook available from the package

Test plan

  • npx tsc --noEmit — clean typecheck
  • npx tsup — CJS/ESM/DTS build succeeds
  • npx vitest run — all 35 existing tests pass (no regressions)
  • Retry and hooks will be covered by new tests in task 4

Submitted by ✨ Rin (DevSquad) for task cmny3jx0a0008g5e0kxifcyj8

ryandao and others added 4 commits April 13, 2026 21:09
Implements full TypeScript SDK with feature parity to the Python SDK:
- AgentQClient with full CRUD for agents, heartbeat, and task management
- @agent decorator for declarative agent registration (mirrors Python @agent)
- AgentRegistry singleton for collecting and bulk-syncing agents
- Comprehensive type definitions for all API models
- Custom error hierarchy (ApiError, ConfigError, NetworkError, TimeoutError)
- Dual CJS/ESM build via tsup with full .d.ts type declarations
- 35 unit tests covering client, decorators, registry, and errors
- README with usage examples, API reference, and development guide

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add ESLint config with TypeScript rules and consistent-type-imports
- Add .npmignore for cleaner published package
- Add CHANGELOG.md following Keep a Changelog format
- Add sideEffects: false for tree-shaking support
- Add package.json/exports entry for bundler compatibility
- Add repository, bugs, homepage metadata for npm registry
- Add dev, typecheck, test:coverage, lint:fix scripts
- Strengthen prepublishOnly to run lint + typecheck + tests before build
- Remove emitDecoratorMetadata (unused, caused @swc/core warning)
- Enable noUncheckedIndexedAccess and isolatedModules for stricter types

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Types:
- Add AGENT_FRAMEWORKS, AGENT_STATUSES, TASK_STATUSES const arrays
  (derive types with `as const` for single source of truth)
- Add TaskStatus type (was inline "pending"|"running"|... in AgentTask)
- Add RetryConfig type for upcoming retry support in HTTP client
- Add RegistryEvents and RegistryEventListener types
- Add type guard functions: isAgentFramework, isAgentStatus,
  isTaskStatus, isAgent for runtime validation

Registry:
- Add event emitter with on()/off() for "registered", "unregistered",
  "synced" lifecycle events
- on() returns unsubscribe function for ergonomic cleanup
- Emit events on register, unregister, and syncAll operations

Exports:
- Re-export all new types, constants, and type guards from barrel

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
HTTP Client:
- Add configurable retry with exponential backoff and full jitter
  (configure via retry option in AgentQConfig)
- Retry on 429, 500, 502, 503, 504 by default (customizable)
- Also retry on network errors and timeouts
- Add onRequest() hook for pre-request logging/header injection
- Add onResponse() hook for post-response metrics/latency tracking
- Extract sleep() method for testability

AgentQClient:
- Expose onRequest()/onResponse() chainable methods
- Export RequestHook and ResponseHook types

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ryandao ryandao merged commit 5742fad into main Apr 14, 2026
1 of 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.

1 participant