// Test script to verify smart HTML context reduction function getSmartHtmlContext(html, selectedElementHtml) { // If no selected element, use the original HTML but truncate if too large if (!selectedElementHtml) { return html.length > 10000 ? html.substring(0, 10000) + "...\n" : html; } // If there's a selected element, provide minimal context around it const selectedIndex = html.indexOf(selectedElementHtml); if (selectedIndex === -1) { // Fallback: if selected element not found, use truncated HTML return html.length > 8000 ? html.substring(0, 8000) + "...\n" : html; } // Provide context around the selected element const contextSize = 2000; // Characters before and after const start = Math.max(0, selectedIndex - contextSize); const end = Math.min(html.length, selectedIndex + selectedElementHtml.length + contextSize); let contextHtml = html.substring(start, end); // Add markers if we truncated if (start > 0) { contextHtml = "...\n\n" + contextHtml; } if (end < html.length) { contextHtml = contextHtml + "\n\n..."; } return contextHtml; } console.log("Testing smart HTML context reduction:\n"); // Test 1: Large HTML without selected element const largeHtml = "
" + "x".repeat(15000) + ""; const result1 = getSmartHtmlContext(largeHtml); console.log("1. Large HTML without selection:"); console.log(` Original: ${largeHtml.length} chars`); console.log(` Reduced: ${result1.length} chars`); console.log(` Savings: ${largeHtml.length - result1.length} chars\n`); // Test 2: Large HTML with selected element const htmlWithElement = "