"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createErrorHandlerNode = createErrorHandlerNode;
function createErrorHandlerNode() {
    return async (state) => {
        // Determine the error message
        const errorMessage = state.error || 'Unknown error occurred';
        const isRephraseNeeded = errorMessage === 'ARGUS_REPHRASE_NEEDED' ||
            errorMessage.includes('GraphRecursionError') ||
            errorMessage.toLowerCase().includes('recursion limit');
        // Create error response
        const errorResponse = {
            answer: isRephraseNeeded
                ? "I couldn't complete that request reliably. Please rephrase it (or break it into 1–2 smaller questions) and try again."
                : `Please rephrase your query and try again.`,
            metadata: {
                domain: state.domain,
                dataPoints: 0,
                //confidence: 0,
                error: errorMessage,
            },
        };
        return {
            response: errorResponse,
            metadata: {
                ...(state.metadata || {}),
                startTime: state.metadata?.startTime || new Date(),
                executionPath: state.metadata?.executionPath || [],
                endTime: new Date(),
                error: errorMessage,
            },
        };
    };
}
//# sourceMappingURL=errorHandlerNode.js.map