/**
 * Handles multi-line paste detection and summarization
 * Provides graceful handling of large text blocks pasted into chat
 */
/**
 * Detect if text is a multi-line paste (3+ lines)
 */
export function isMultilinePaste(text) {
    const lines = text.split('\n').filter(line => line.trim().length > 0);
    return lines.length >= 3;
}
/**
 * Detect likely programming language from content
 */
function detectLanguage(text) {
    const patterns = {
        javascript: /\b(const|let|var|function|async|await|import|export|=>)\b/,
        typescript: /\b(interface|type|enum|namespace|declare|as const)\b/,
        python: /\b(def|class|import|from|if __name__|async def)\b/,
        json: /^\s*(?:\{|\[).*(?:\}|\])\s*$/,
        html: /^<[a-z]/i,
        css: /^\s*[.#[]?[\w-]+\s*{/,
        sql: /\b(SELECT|FROM|WHERE|INSERT|UPDATE|DELETE|CREATE|TABLE)\b/i,
        bash: /^#!/,
        yaml: /^[\w-]+:\s*\S/m,
    };
    for (const [lang, pattern] of Object.entries(patterns)) {
        if (pattern.test(text)) {
            return lang;
        }
    }
    return undefined;
}
/**
 * Generate a concise summary of pasted content
 */
export function generatePasteSummary(text) {
    const lines = text.split('\n');
    const nonEmptyLines = lines.filter(line => line.trim().length > 0);
    const charCount = text.length;
    const lineCount = nonEmptyLines.length;
    const language = detectLanguage(text);
    // Create preview: first 60 chars or first line
    let preview = nonEmptyLines[0]?.substring(0, 60) || '';
    if (preview.length === 60) {
        preview += '...';
    }
    // Generate summary description
    const summaryParts = [];
    if (language) {
        summaryParts.push(`${language.toUpperCase()}`);
    }
    summaryParts.push(`${lineCount} line${lineCount !== 1 ? 's' : ''}`);
    summaryParts.push(`${charCount} char${charCount !== 1 ? 's' : ''}`);
    const summary = `📋 Pasted: ${summaryParts.join(' • ')}`;
    return {
        isMultiline: true,
        lineCount,
        charCount,
        preview,
        language,
        summary,
    };
}
/**
 * Format a paste summary for display
 */
export function formatPasteSummaryForDisplay(summary) {
    return `${summary.summary}\n"${summary.preview}"`;
}
export function processPaste(text) {
    const summary = generatePasteSummary(text);
    const displaySummary = formatPasteSummaryForDisplay(summary);
    return {
        displaySummary,
        fullContent: text,
        metadata: summary,
    };
}
//# sourceMappingURL=multilinePasteHandler.js.map