jorel
Version:
A unified wrapper for working with LLMs from multiple providers, including streams, images, documents & automatic tool use.
53 lines (52 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JorElLlmError = exports.JorElAbortError = void 0;
exports.isAbortError = isAbortError;
exports.isLlmError = isLlmError;
/**
* Error thrown when a generation request is cancelled via AbortSignal
*/
class JorElAbortError extends Error {
constructor(message = "Generation was cancelled") {
super(message);
this.name = "AbortError";
this.code = "GENERATION_ABORTED";
this.isAbortError = true;
// Maintains proper stack trace in V8
if (Error.captureStackTrace) {
Error.captureStackTrace(this, JorElAbortError);
}
}
}
exports.JorElAbortError = JorElAbortError;
/**
* Error thrown when an LLM provider encounters an error
*/
class JorElLlmError extends Error {
constructor(message, type) {
super(message);
this.type = type;
this.name = "LlmError";
this.code = "LLM_ERROR";
// Maintains proper stack trace in V8
if (Error.captureStackTrace) {
Error.captureStackTrace(this, JorElLlmError);
}
}
}
exports.JorElLlmError = JorElLlmError;
/**
* Type guard to check if an error is an AbortError
*/
function isAbortError(error) {
return (error instanceof JorElAbortError ||
(error instanceof Error && "isAbortError" in error && error.isAbortError === true) ||
(error instanceof Error && error.name === "AbortError") ||
(error instanceof Error && error.message.includes("aborted")));
}
/**
* Type guard to check if an error is an LlmError
*/
function isLlmError(error) {
return error instanceof JorElLlmError;
}