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

189 lines (188 loc) • 7.19 kB
/** * Base error class for all NeuroLink-specific errors. * This allows for easy identification of errors thrown by the SDK. */ export declare class BaseError extends Error { constructor(message: string); } /** * Thrown when a provider encounters a generic error. */ export declare class ProviderError extends BaseError { provider?: string | undefined; constructor(message: string, provider?: string | undefined); } export type OllamaHttpError = ProviderError & { statusCode?: number; statusText?: string; responseBody?: string; }; /** * Thrown for authentication-related errors, such as invalid or missing API keys. */ export declare class AuthenticationError extends ProviderError { constructor(message: string, provider?: string); } /** * Thrown for authorization errors, where the user does not have permission. */ export declare class AuthorizationError extends ProviderError { constructor(message: string, provider?: string); } /** * Thrown for network-related issues, such as connectivity problems or timeouts. */ export declare class NetworkError extends ProviderError { constructor(message: string, provider?: string); } /** * Thrown when an API rate limit has been exceeded. */ export declare class RateLimitError extends ProviderError { constructor(message: string, provider?: string); } /** * Thrown when a specified model is not found or is invalid for the provider. */ export declare class InvalidModelError extends ProviderError { constructor(message: string, provider?: string); } /** * Everything a ProviderErrorRule's `match`/`message` functions can inspect * about a raw thrown error, pre-extracted once so every rule doesn't * re-derive the same duck-typed fields. */ export type ProviderErrorContext = { /** The raw thrown value, for rules that need custom inspection beyond the extracted fields. */ error: unknown; /** `.message` off the raw error, or "Unknown error" if absent/non-string. */ message: string; /** HTTP status code, duck-typed from `.statusCode` / `.status`. */ statusCode: number | undefined; /** `.name` off the raw error (e.g. AWS SDK exception names like "ThrottlingException"). */ errorName: string | undefined; /** `.code` off the raw error (e.g. AWS SDK / Node network error codes). */ errorCode: string | undefined; /** Provider key passed to classifyProviderError (e.g. "mistral", "vertex"). */ provider: string; /** Model name in effect for this call, when the caller has one available. */ modelName: string | undefined; }; /** * One row of a provider's error-classification table. Rules are tried in * array order; the first `match` to return true wins. `errorClass` must be * `ProviderError` or one of its subclasses (AuthenticationError, * RateLimitError, InvalidModelError, NetworkError, ...) sharing its * `(message, provider?)` constructor shape. `message` can be a static * string or a function of the context, for providers that need to * interpolate a model name, a scraped retry-delay, or an AWS error code. */ export type ProviderErrorRule = { match: (ctx: ProviderErrorContext) => boolean; errorClass: new (message: string, provider?: string) => ProviderError; message: string | ((ctx: ProviderErrorContext) => string); }; /** * Base class for OAuth-specific errors */ export declare class OAuthError extends BaseError { code?: string | undefined; constructor(message: string, code?: string | undefined); } /** * Thrown when OAuth configuration is invalid or missing */ export declare class OAuthConfigurationError extends OAuthError { constructor(message: string); } /** * Thrown when authorization code exchange fails */ export declare class OAuthTokenExchangeError extends OAuthError { statusCode?: number | undefined; constructor(message: string, statusCode?: number | undefined); } /** * Thrown when token refresh fails */ export declare class OAuthTokenRefreshError extends OAuthError { statusCode?: number | undefined; constructor(message: string, statusCode?: number | undefined); } /** * Thrown when token validation fails */ export declare class OAuthTokenValidationError extends OAuthError { constructor(message: string); } /** * Thrown when token revocation fails */ export declare class OAuthTokenRevocationError extends OAuthError { statusCode?: number | undefined; constructor(message: string, statusCode?: number | undefined); } /** * Thrown when callback server operations fail */ export declare class OAuthCallbackServerError extends OAuthError { constructor(message: string); } /** * Token storage error for authentication-related failures */ export declare class TokenStoreError extends BaseError { readonly code: "STORAGE_ERROR" | "ENCRYPTION_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "REFRESH_ERROR"; constructor(message: string, code?: "STORAGE_ERROR" | "ENCRYPTION_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "REFRESH_ERROR"); } /** * Error thrown when model access is denied based on subscription tier */ export declare class ModelAccessError extends BaseError { readonly model: string; readonly tier: string; readonly requiredTier: string; constructor(model: string, tier: string, requiredTier: string); } /** * Curator P1-1: thrown when a provider rejects a request because the * caller's team / API key is not whitelisted for the requested model. * * LiteLLM's `team not allowed to access model. This team can only access * models=['glm-latest', 'kimi-latest', ...]` is the canonical example — * the list is parsed off the error body so callers / fallback orchestrators * can choose a whitelisted alternative without scraping strings. */ export declare class ModelAccessDeniedError extends ProviderError { readonly requestedModel: string | undefined; readonly allowedModels: string[] | undefined; readonly code: "MODEL_ACCESS_DENIED"; constructor(message: string, options?: { provider?: string; requestedModel?: string; allowedModels?: string[]; }); } /** * Parse the `allowed_models` array out of a provider error message body. * Currently targets the LiteLLM team-whitelist response shape: * * "team not allowed to access model. This team can only access * models=['glm-latest', 'kimi-latest', 'open-large']" * * Implementation note: deliberately uses `indexOf`/`slice` instead of a * single `/models\s*=\s*\[([^\]]*)\]/` regex. CodeQL flagged the latter * as `js/polynomial-redos` because the `[^\]]*` greedy quantifier on * library-supplied input can be exploited by a crafted long string. The * indexOf/slice path is O(n) with no backtracking and we additionally * cap the input length. * * Returns undefined when no list is found. */ export declare function parseAllowedModels(message: string): string[] | undefined; /** * Returns true when `message` looks like a model-access-denied response * (LiteLLM "team not allowed", generic "not allowed to access model", * or "team can only access models=[...]"). */ export declare function isModelAccessDeniedMessage(message: string): boolean;