/** * Lightweight HTTP client for Sequence0 agent node communication * * Uses native fetch -- works in Node.js 18+ and all modern browsers. * Includes client-side rate limiting, automatic retries with exponential * backoff, request/response debug logging, response validation, and * a per-host circuit breaker to fail fast on unreachable agents. */ import { Sequence0Error } from './errors'; import { RateLimiterOptions } from './rate-limiter'; import { Logger } from './logger'; export type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN'; /** * Thrown when a request is rejected because the circuit breaker is OPEN. * The caller should select a different agent or wait for the cooldown. */ export declare class CircuitBreakerError extends Sequence0Error { host: string; timeUntilHalfOpen: number; constructor(host: string, timeUntilHalfOpen: number); } export interface CircuitBreakerOptions { /** Consecutive failures before tripping OPEN (default: 3) */ failureThreshold?: number; /** Cooldown in ms before moving from OPEN to HALF_OPEN (default: 30000) */ cooldownMs?: number; } /** * Per-host circuit breaker. * * States: * CLOSED — normal operation, requests pass through * OPEN — failing, requests are rejected immediately * HALF_OPEN — testing recovery, one request is allowed through * * Transitions: * CLOSED → OPEN after `failureThreshold` consecutive failures * OPEN → HALF_OPEN after `cooldownMs` elapses * HALF_OPEN → CLOSED on first success * HALF_OPEN → OPEN on first failure */ export declare class CircuitBreaker { private states; private failureCounts; private lastFailureTimes; private failureThreshold; private cooldownMs; constructor(options?: CircuitBreakerOptions); /** * Check whether a request to the given host is allowed. * Throws CircuitBreakerError if the circuit is OPEN and cooldown has not elapsed. */ allowRequest(host: string): void; /** * Record a successful request. Resets the circuit to CLOSED. */ recordSuccess(host: string): void; /** * Record a failed request. Increments failure count and may trip the circuit. */ recordFailure(host: string): void; /** * Get the current state for a host (defaults to CLOSED). */ getState(host: string): CircuitState; /** * Reset the circuit breaker for a specific host. */ reset(host: string): void; /** * Reset all circuit breakers. */ resetAll(): void; } export interface HttpOptions { /** Base URL of the agent node (e.g. http://52.14.62.162:8080) */ baseUrl: string; /** Request timeout in ms (default: 30000) */ timeout?: number; /** Additional headers */ headers?: Record; /** Max retry attempts on transient failures (default: 3) */ maxRetries?: number; /** Client-side rate limiting options */ rateLimiter?: RateLimiterOptions | false; /** Enable debug logging (default: false) */ debug?: boolean; /** Custom logger instance (overrides debug flag) */ logger?: Logger; /** Circuit breaker instance (shared across HttpClient instances for per-host tracking) */ circuitBreaker?: CircuitBreaker; /** Enable HTTP keep-alive for connection reuse (default: true) */ keepAlive?: boolean; /** Keep-alive timeout in ms (default: 30000) */ keepAliveTimeout?: number; } export declare class HttpClient { private baseUrl; private host; private timeout; private headers; private maxRetries; private rateLimiter; private logger; private circuitBreaker; constructor(options: HttpOptions); get(path: string): Promise; post(path: string, body?: unknown): Promise; /** * Destroy internal resources (rate limiter timers, etc.) */ destroy(): void; /** * Request with circuit breaker check, automatic retries, and exponential backoff. */ private requestWithRetry; private request; } //# sourceMappingURL=http.d.ts.map