const OVERFLOW_PATTERNS = [
    /prompt is too long/i,
    /input is too long for requested model/i,
    /exceeds the context window/i,
    /input token count.*exceeds the maximum/i,
    /maximum prompt length is \d+/i,
    /reduce the length of the messages/i,
    /maximum context length is \d+ tokens/i,
    /exceeds the limit of \d+/i,
    /exceeds the available context size/i,
    /greater than the context length/i,
    /context window exceeds limit/i,
    /exceeded model token limit/i,
    /context[_ ]length[_ ]exceeded/i,
    /too many tokens/i,
    /token limit exceeded/i
];
/**
 * Browser-safe context overflow classifier vendored from owned AI.
 *
 * Do not import this as a runtime value from `shortcutxl/ai`: the package
 * root pulls provider implementations with Node-only dependencies into the
 * embedded/web-worker bundle.
 */
export function isContextOverflow(message, contextWindow) {
    const errorMessage = message.errorMessage;
    if (message.stopReason === 'error' && errorMessage) {
        if (OVERFLOW_PATTERNS.some((pattern) => pattern.test(errorMessage))) {
            return true;
        }
        // Cerebras and Mistral can return 400/413 with no body for context overflow.
        // 429 is rate limiting, not context overflow.
        if (/^4(00|13)\s*(status code)?\s*\(no body\)/i.test(errorMessage)) {
            return true;
        }
    }
    if (contextWindow && message.stopReason === 'stop') {
        return message.usage.input > contextWindow;
    }
    return false;
}
//# sourceMappingURL=context-overflow.js.map