@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
27 lines (26 loc) • 1.22 kB
JavaScript
import { NetworkError } from "../types/index.js";
/**
* Shared error-rule builder for local-runtime OpenAI-compatible providers —
* Ollama, LM Studio, llama.cpp. All three had byte-identical connection-
* refused predicates (including the duck-typed `code`/`cause.code`
* extraction, since none of that lives on ProviderErrorContext) before this
* factored it out. A plain function, not a shared base class: the
* `neurolink/provider-base-class` lint rule requires every provider to
* extend BaseProvider or OpenAIChatCompletionsProvider directly, so the
* three keep their existing class hierarchy and just call this from their
* own `formatProviderError()`.
*
* `message` stays per-vendor (each provider's own exact wording, unchanged)
* — only the match predicate and errorClass were ever duplicated.
*/
export function buildLocalUnreachableErrorRule(error, message) {
const errorRecord = error;
const cause = errorRecord?.cause ?? {};
const code = (errorRecord?.code ?? cause?.code);
return {
match: (ctx) => code === "ECONNREFUSED" ||
/ECONNREFUSED|Failed to fetch|fetch failed/.test(ctx.message),
errorClass: NetworkError,
message,
};
}