feat(provider): add free providers and enhance error handling

This commit is contained in:
decolua
2026-02-07 11:17:06 +07:00
parent 53a5f43993
commit bdbe8162e7
16 changed files with 285 additions and 120 deletions
+42
View File
@@ -219,6 +219,48 @@ export const DEFAULT_MAX_TOKENS = 64000;
// Minimum max tokens for tool calling (to prevent truncated arguments)
export const DEFAULT_MIN_TOKENS = 32000;
// HTTP status codes
export const HTTP_STATUS = {
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
PAYMENT_REQUIRED: 402,
FORBIDDEN: 403,
NOT_FOUND: 404,
NOT_ACCEPTABLE: 406,
REQUEST_TIMEOUT: 408,
RATE_LIMITED: 429,
SERVER_ERROR: 500,
BAD_GATEWAY: 502,
SERVICE_UNAVAILABLE: 503,
GATEWAY_TIMEOUT: 504
};
// OpenAI-compatible error types mapping
export const ERROR_TYPES = {
[HTTP_STATUS.BAD_REQUEST]: { type: "invalid_request_error", code: "bad_request" },
[HTTP_STATUS.UNAUTHORIZED]: { type: "authentication_error", code: "invalid_api_key" },
[HTTP_STATUS.FORBIDDEN]: { type: "permission_error", code: "insufficient_quota" },
[HTTP_STATUS.NOT_FOUND]: { type: "invalid_request_error", code: "model_not_found" },
[HTTP_STATUS.RATE_LIMITED]: { type: "rate_limit_error", code: "rate_limit_exceeded" },
[HTTP_STATUS.SERVER_ERROR]: { type: "server_error", code: "internal_server_error" },
[HTTP_STATUS.BAD_GATEWAY]: { type: "server_error", code: "bad_gateway" },
[HTTP_STATUS.SERVICE_UNAVAILABLE]: { type: "server_error", code: "service_unavailable" },
[HTTP_STATUS.GATEWAY_TIMEOUT]: { type: "server_error", code: "gateway_timeout" }
};
// Default error messages per status code
export const DEFAULT_ERROR_MESSAGES = {
[HTTP_STATUS.BAD_REQUEST]: "Bad request",
[HTTP_STATUS.UNAUTHORIZED]: "Invalid API key provided",
[HTTP_STATUS.FORBIDDEN]: "You exceeded your current quota",
[HTTP_STATUS.NOT_FOUND]: "Model not found",
[HTTP_STATUS.RATE_LIMITED]: "Rate limit exceeded",
[HTTP_STATUS.SERVER_ERROR]: "Internal server error",
[HTTP_STATUS.BAD_GATEWAY]: "Bad gateway - upstream provider error",
[HTTP_STATUS.SERVICE_UNAVAILABLE]: "Service temporarily unavailable",
[HTTP_STATUS.GATEWAY_TIMEOUT]: "Gateway timeout"
};
// Exponential backoff config for rate limits (like CLIProxyAPI)
export const BACKOFF_CONFIG = {
base: 1000, // 1 second base