@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
52 lines (51 loc) • 1.05 kB
JavaScript
/**
* Common utility types for NeuroLink
*/
/**
* Type guard to check if value is Error
*/
export function isError(value) {
return value instanceof Error;
}
/**
* Type guard to check if value is ErrorInfo
*/
export function isErrorInfo(value) {
return (typeof value === "object" &&
value !== null &&
"message" in value &&
typeof value.message === "string");
}
/**
* Safe error message extraction
*/
export function getErrorMessage(error) {
if (isError(error)) {
return error.message;
}
if (isErrorInfo(error)) {
return error.message;
}
if (typeof error === "string") {
return error;
}
return String(error);
}
/**
* Safe error conversion
*/
export function toErrorInfo(error) {
if (isError(error)) {
return {
message: error.message,
stack: error.stack,
code: error.code,
};
}
if (isErrorInfo(error)) {
return error;
}
return {
message: getErrorMessage(error),
};
}