/**
 * Enumeration of error codes for Server-Sent Events (SSE) related to generated answers.
 */
export var GeneratedAnswerSseErrorCode;
(function (GeneratedAnswerSseErrorCode) {
    GeneratedAnswerSseErrorCode[GeneratedAnswerSseErrorCode["SseMaxDurationExceeded"] = 1000] = "SseMaxDurationExceeded";
    GeneratedAnswerSseErrorCode[GeneratedAnswerSseErrorCode["SseFollowUpNotSupported"] = 1001] = "SseFollowUpNotSupported";
    GeneratedAnswerSseErrorCode[GeneratedAnswerSseErrorCode["ConversationNotFound"] = 1002] = "ConversationNotFound";
    GeneratedAnswerSseErrorCode[GeneratedAnswerSseErrorCode["SseModelsNotAvailable"] = 1003] = "SseModelsNotAvailable";
    GeneratedAnswerSseErrorCode[GeneratedAnswerSseErrorCode["SseInternalError"] = 1004] = "SseInternalError";
    GeneratedAnswerSseErrorCode[GeneratedAnswerSseErrorCode["SseTurnLimitReached"] = 1005] = "SseTurnLimitReached";
})(GeneratedAnswerSseErrorCode || (GeneratedAnswerSseErrorCode = {}));
const generatedAnswerSseErrorMap = {
    'KNOWLEDGE:SSE_MAX_DURATION_EXCEEDED': GeneratedAnswerSseErrorCode.SseMaxDurationExceeded,
    'KNOWLEDGE:SSE_FOLLOW_UP_NOT_SUPPORTED': GeneratedAnswerSseErrorCode.SseFollowUpNotSupported,
    'KNOWLEDGE:NOT_FOUND': GeneratedAnswerSseErrorCode.ConversationNotFound,
    'KNOWLEDGE:SSE_MODELS_NOT_AVAILABLE': GeneratedAnswerSseErrorCode.SseModelsNotAvailable,
    'KNOWLEDGE:SSE_INTERNAL_ERROR': GeneratedAnswerSseErrorCode.SseInternalError,
    'KNOWLEDGE:TURN_LIMIT_REACHED': GeneratedAnswerSseErrorCode.SseTurnLimitReached,
};
/**
 * Maps backend error codes to frontend error codes for generated answer SSE errors.
 */
export function mapRunErrorCode(code) {
    if (!code)
        return GeneratedAnswerSseErrorCode.SseInternalError;
    return (generatedAnswerSseErrorMap[code] ??
        GeneratedAnswerSseErrorCode.SseInternalError);
}
function attachErrorHelpers(error) {
    const isCode = (value) => error.code === value;
    Object.defineProperties(error, {
        isMaxDurationExceededError: {
            value: () => isCode(GeneratedAnswerSseErrorCode.SseMaxDurationExceeded),
            enumerable: false,
        },
        isFollowupNotSupportedError: {
            value: () => isCode(GeneratedAnswerSseErrorCode.SseFollowUpNotSupported),
            enumerable: false,
        },
        isConversationNotFoundError: {
            value: () => isCode(GeneratedAnswerSseErrorCode.ConversationNotFound),
            enumerable: false,
        },
        isSseModelNotAvailableError: {
            value: () => isCode(GeneratedAnswerSseErrorCode.SseModelsNotAvailable),
            enumerable: false,
        },
        isSseInternalError: {
            value: () => isCode(GeneratedAnswerSseErrorCode.SseInternalError),
            enumerable: false,
        },
        isSseTurnLimitReachedError: {
            value: () => isCode(GeneratedAnswerSseErrorCode.SseTurnLimitReached),
            enumerable: false,
        },
    });
    return error;
}
/**
 * Decorates a generated answer error with helper predicates for SSE error codes.
 */
export function withGeneratedAnswerSseErrorHelpers(error) {
    if (!error) {
        return undefined;
    }
    return attachErrorHelpers({ ...error });
}
