UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

31 lines (30 loc) • 1.65 kB
/** * Shared provider-error classification. Every provider's * `formatProviderError(error)` delegates here instead of hand-rolling its * own TimeoutError-check → .includes()-chain → `new XError(...)` ladder. * * `classifyProviderError` picks the Error subclass + message; it does NOT * stamp statusCode/isRetryable/retryAfterMs onto the result — that * passthrough already happens generically in * `BaseProvider.handleProviderError()` (src/lib/core/baseProvider.ts) for * every provider's returned error, migrated or not, so duplicating it here * would risk the two copies disagreeing. */ import { type ProviderErrorRule } from "../types/index.js"; /** * Classify a raw provider error into a NeuroLink `ProviderError` subclass. * `rules` are tried in order; the first match wins. `TimeoutError` is * always handled first, ahead of any rule table — every provider treated * it identically before this change, so it is not made overridable. */ export declare function classifyProviderError(error: unknown, rules: ProviderErrorRule[], provider: string, modelName?: string): Error; /** * Generic fallback rule table covering the five categories every * OpenAI-compatible provider already hand-rolled near-identically: * auth (401), rate limit (429), model-not-found (404), network/connection * errors, and 5xx server errors. Providers with a provider-specific auth * message (naming the exact env var) prepend one override rule and spread * this table after it — see errorClassifier usage in any migrated * provider's formatProviderError for the pattern. */ export declare const DEFAULT_ERROR_RULES: ProviderErrorRule[];