/** * Error types for the AI provider layer. * * Errors are classified so callers can react appropriately: auth failures are * terminal (the key is wrong), rate-limit/overloaded errors are retryable, and * budget violations are a client-side guard. * * See CHUNK#8.md ยง3. */ /** Base class for all provider-layer errors. */ export class ProviderError extends Error { constructor(message: string) { super(message); this.name = "ProviderError"; } } /** The provider rejected the request due to missing/invalid credentials. */ export class ProviderAuthError extends ProviderError { constructor(message = "Provider authentication failed (invalid API key).") { super(message); this.name = "ProviderAuthError"; } } /** The provider rate-limited or overloaded the request; safe to retry. */ export class ProviderRateLimitError extends ProviderError { constructor(message = "Provider rate limit exceeded; retrying.") { super(message); this.name = "ProviderRateLimitError"; } } /** The request exceeded the configured token budget. */ export class BudgetExceededError extends ProviderError { constructor(message: string) { super(message); this.name = "BudgetExceededError"; } } /** No provider adapter is registered for the given kind. */ export class UnknownProviderError extends ProviderError { constructor(kind: string) { super(`Unknown provider kind: ${kind}`); this.name = "UnknownProviderError"; } }