Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | 1x 1x 41x 41x 1x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 1x 1x 1x 23x 23x 23x 23x 23x 23x 1x 1x 1x 1x 8x 8x 8x 8x 1x 1x 1x 9x 9x 9x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 6x 6x 6x 6x 1x | /**
* AgentKits — Unified Error Hierarchy
*
* All errors thrown by AgentKits extend AgentKitsError.
*
* @example
* ```ts
* import { ProviderError, RateLimitError } from 'agentkits/errors';
*
* try {
* await chat.complete('Hello');
* } catch (err) {
* if (err instanceof RateLimitError) {
* console.log('retry after', err.retryAfter, 'ms');
* }
* }
* ```
*/
// ── Base ───────────────────────────────────────────────────────────
/**
* Base error class for all AgentKits errors.
*/
export class AgentKitsError extends Error {
/** Machine-readable error code */
readonly code: string;
/** Provider name (if applicable) */
readonly provider?: string;
/** HTTP status code (if applicable) */
readonly statusCode?: number;
constructor(
message: string,
options: { code?: string; provider?: string; statusCode?: number } = {},
) {
super(message);
this.name = 'AgentKitsError';
this.code = options.code ?? 'AGENTKITS_ERROR';
this.provider = options.provider;
this.statusCode = options.statusCode;
// Maintains proper stack trace in V8
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
// ── Provider Errors ────────────────────────────────────────────────
/**
* Thrown when an upstream provider API returns an error.
*/
export class ProviderError extends AgentKitsError {
constructor(
message: string,
options: { code?: string; provider?: string; statusCode?: number } = {},
) {
super(message, { code: options.code ?? 'PROVIDER_ERROR', provider: options.provider, statusCode: options.statusCode });
this.name = 'ProviderError';
}
}
/**
* Thrown when a provider returns HTTP 429 (Too Many Requests).
*/
export class RateLimitError extends ProviderError {
/** Milliseconds until the client may retry (from Retry-After header, if present) */
readonly retryAfter?: number;
constructor(message: string, options: { provider?: string; retryAfter?: number } = {}) {
super(message, { code: 'RATE_LIMIT_ERROR', provider: options.provider, statusCode: 429 });
this.name = 'RateLimitError';
this.retryAfter = options.retryAfter;
}
}
/**
* Thrown when a provider returns HTTP 401 or 403 (auth failure).
*/
export class AuthenticationError extends ProviderError {
constructor(message: string, options: { provider?: string; statusCode?: number } = {}) {
super(message, { code: 'AUTHENTICATION_ERROR', provider: options.provider, statusCode: options.statusCode ?? 401 });
this.name = 'AuthenticationError';
}
}
/**
* Thrown when the requested model does not exist or is not available.
*/
export class ModelNotFoundError extends ProviderError {
/** The model ID that was requested */
readonly model: string;
constructor(model: string, options: { provider?: string } = {}) {
super(`Model not found: ${model}`, { code: 'MODEL_NOT_FOUND', provider: options.provider, statusCode: 404 });
this.name = 'ModelNotFoundError';
this.model = model;
}
}
// ── Client-side Errors ─────────────────────────────────────────────
/**
* Thrown when a request exceeds the configured timeout.
*/
export class TimeoutError extends AgentKitsError {
/** Configured timeout in milliseconds */
readonly timeoutMs?: number;
constructor(message: string, options: { provider?: string; timeoutMs?: number } = {}) {
super(message, { code: 'TIMEOUT_ERROR', provider: options.provider });
this.name = 'TimeoutError';
this.timeoutMs = options.timeoutMs;
}
}
/**
* Thrown when input validation fails (bad arguments, schema mismatch, etc.).
*/
export class ValidationError extends AgentKitsError {
/** Field or property that failed validation (if applicable) */
readonly field?: string;
constructor(message: string, options: { field?: string; provider?: string } = {}) {
super(message, { code: 'VALIDATION_ERROR', provider: options.provider });
this.name = 'ValidationError';
this.field = options.field;
}
}
|