const CONTEXT_TOO_LONG_PATTERNS = [
    'context_too_long',
    'context too long',
    'context window',
    'maximum context',
    'token limit',
    'prompt is too long',
    'too long for the model',
    'string_above_max_length'
];
const LLM_UNAVAILABLE_PATTERNS = [
    'llm_unavailable',
    'service unavailable',
    '503',
    '502',
    '504',
    'overloaded',
    'rate limit',
    'rate_limit',
    'timeout',
    'timed out',
    'fetch failed',
    'connection refused',
    'connection reset',
    'econnrefused',
    'econnreset',
    'enotfound'
];
export function getAgentErrorMessage(error) {
    if (error instanceof Error)
        return error.message;
    if (typeof error === 'string')
        return error;
    if (error && typeof error === 'object') {
        const record = error;
        for (const key of ['errorMessage', 'message', 'error']) {
            const value = record[key];
            if (typeof value === 'string')
                return value;
            if (value instanceof Error)
                return value.message;
            if (value && typeof value === 'object') {
                const nested = value;
                if (typeof nested.message === 'string')
                    return nested.message;
                if (typeof nested.errorMessage === 'string')
                    return nested.errorMessage;
            }
        }
    }
    return String(error);
}
export function classifyAgentError(error) {
    const haystack = getAgentErrorMessage(error).toLowerCase();
    for (const needle of CONTEXT_TOO_LONG_PATTERNS) {
        if (haystack.includes(needle))
            return 'context_too_long';
    }
    for (const needle of LLM_UNAVAILABLE_PATTERNS) {
        if (haystack.includes(needle))
            return 'llm_unavailable';
    }
    return 'internal';
}
//# sourceMappingURL=error-classification.js.map