import { DeeplineError, ProviderTransientError, ToolExecutionError, brandAsProviderTransientError, brandAsToolExecutionError, getProviderUnavailableReason, isProviderUnavailable, isProviderTransientFailure, isProviderWaterfallUnavailableError, type ProviderTransientErrorCategory, type ToolExecutionErrorCategory, type ToolExecutionFailureV1, type ToolExecutionErrorOrigin, type ToolExecutionErrorOptions, type ToolExecutionNetworkKind, type ToolExecutionNetworkScope, } from '../../shared_libs/tool-execution-error.js'; export { DeeplineError, ProviderTransientError, ToolExecutionError, getProviderUnavailableReason, isProviderUnavailable, isProviderWaterfallUnavailableError, type ProviderTransientErrorCategory, type ProviderUnavailableError, type ProviderUnavailableReason, type ToolExecutionErrorCategory, type ToolExecutionFailureV1, type ToolExecutionErrorOrigin, type ToolExecutionErrorOptions, type ToolExecutionNetworkKind, type ToolExecutionNetworkScope, } from '../../shared_libs/tool-execution-error.js'; /** * Thrown when the API rejects the request due to an invalid or missing API key. * * This maps to HTTP 401 responses. HTTP 403 means the caller was authenticated * but lacks permission, so the SDK preserves the server's API error instead. * The SDK never retries auth errors — * they fail immediately. * * Fix: run `deepline auth register` to obtain a valid key, or pass one via * the `apiKey` option or `DEEPLINE_API_KEY` environment variable. * * @example * ```typescript * import { AuthError } from 'deepline'; * * try { * await client.listTools(); * } catch (err) { * if (err instanceof AuthError) { * // Redirect user to auth flow * } * } * ``` * * @sdkReference errors 090 */ export class AuthError extends DeeplineError { /** Constructed by the SDK when Deepline rejects the caller's credentials. */ constructor(message = 'Authentication failed. Check your DEEPLINE_API_KEY.') { super(message, 401, 'AUTH_ERROR'); this.name = 'AuthError'; } } /** * Thrown when the API returns HTTP 429 (Too Many Requests). * * The SDK retries rate-limited requests automatically up to `maxRetries` times * with exponential backoff. This error is only thrown when all retries are exhausted. * * Use {@link RateLimitError.retryAfterMs} to implement your own backoff if needed. * * @example * ```typescript * import { RateLimitError } from 'deepline'; * * try { * await client.executeTool('dropleads_search_people', { query: 'cto' }); * } catch (err) { * if (err instanceof RateLimitError) { * console.log(`Retry after ${err.retryAfterMs}ms`); * await sleep(err.retryAfterMs); * // retry... * } * } * ``` * * @sdkReference errors 100 */ export class RateLimitError extends DeeplineError { /** Milliseconds to wait before retrying, from the `Retry-After` response header. Defaults to 5000. */ public retryAfterMs: number; /** Constructed by the SDK after exhausting HTTP-level rate-limit retries. */ constructor(retryAfterMs = 5000, message?: string) { super( message ?? `Rate limited. Retry after ${retryAfterMs}ms.`, 429, 'RATE_LIMIT', ); this.name = 'RateLimitError'; this.retryAfterMs = retryAfterMs; } } /** * Tool-specific 429 preserving both historical RateLimitError catches and the * structured ToolExecutionError ontology. JavaScript has one prototype chain, * so this class extends RateLimitError and carries ToolExecutionError's stable * cross-bundle brand. * * This class appears in external SDK calls after HTTP 429 retries are * exhausted. It also satisfies `instanceof ToolExecutionError` and, for a * provider-owned rate limit, `instanceof ProviderTransientError`. Authored * Plays should use `ProviderTransientError`; they do not need this * compatibility class. * * @sdkReference errors 110 */ export class ToolRateLimitError extends RateLimitError { /** Public tool id passed to `tools.execute`. */ readonly toolId: string; /** Provider responsible for the operation, or `null`. */ readonly provider: string | null; /** Provider operation name, or `null`. */ readonly operation: string | null; /** Stable machine-readable failure code when one exists. */ override readonly code: string | undefined; /** Boundary responsible for the failure. */ readonly origin: ToolExecutionError['origin']; /** Stable reason family for policy and diagnostics. */ readonly category: ToolExecutionError['category']; /** Whether repeating the same semantic call is delivery-safe. */ readonly retryable: boolean; /** Provider or Deepline request id, or `null`. */ readonly requestId: string | null; /** Network failure kind, or `null` for non-network failures. */ readonly networkKind: ToolExecutionError['networkKind']; /** Network boundary that failed, or `null` for non-network failures. */ readonly networkScope: ToolExecutionError['networkScope']; /** Constructed by the SDK after a structured tool HTTP 429. */ constructor(message: string, options: ToolExecutionErrorOptions) { super(options.retryAfterMs ?? 5_000, message); this.name = 'ToolRateLimitError'; this.statusCode = options.statusCode ?? 429; this.code = options.code ?? undefined; this.toolId = options.toolId; this.provider = options.provider; this.operation = options.operation; this.origin = options.origin; this.category = options.category; this.retryable = options.retryable; this.requestId = options.requestId; this.networkKind = options.networkKind; this.networkScope = options.networkScope; this.details = options.details; brandAsToolExecutionError(this); if (isProviderTransientFailure(this)) { brandAsProviderTransientError(this); } } } /** * Thrown when the SDK cannot resolve a valid configuration. * * Most commonly: no API key found in any of the resolution sources * (explicit option, environment variable, CLI env files). * * @example * ```typescript * import { ConfigError } from 'deepline'; * * try { * const client = new DeeplineClient(); * } catch (err) { * if (err instanceof ConfigError) { * console.error('Run: deepline auth register'); * } * } * ``` * * @sdkReference errors 120 */ export class ConfigError extends DeeplineError { /** Construct a local SDK configuration failure. */ constructor(message: string) { super(message, undefined, 'CONFIG_ERROR'); this.name = 'ConfigError'; } }