Compress ```html:preview code blocks in conversation history. Instead of sending the full 5-10KB HTML, extract a compact text summary that preserves the widget's content/data so the AI can make targeted edits.
(text: &str)
| 1743 | /// Instead of sending the full 5-10KB HTML, extract a compact text summary |
| 1744 | /// that preserves the widget's content/data so the AI can make targeted edits. |
| 1745 | fn strip_preview_blocks(text: &str) -> String { |
| 1746 | let mut result = String::with_capacity(text.len()); |
| 1747 | let mut in_preview = false; |
| 1748 | let mut preview_content = String::new(); |
| 1749 | |
| 1750 | for line in text.lines() { |
| 1751 | let trimmed = line.trim(); |
| 1752 | if !in_preview |
| 1753 | && trimmed.starts_with("```") |
| 1754 | && (trimmed.contains("html:preview") |
| 1755 | || trimmed.contains("html:artifact") |
| 1756 | || trimmed.contains("html:viz") |
| 1757 | || trimmed.contains("html:render")) |
| 1758 | { |
| 1759 | in_preview = true; |
| 1760 | preview_content.clear(); |
| 1761 | continue; |
| 1762 | } |
| 1763 | if in_preview { |
| 1764 | if trimmed == "```" { |
| 1765 | in_preview = false; |
| 1766 | // Extract a compact summary from the HTML |
| 1767 | let summary = summarize_html_widget(&preview_content); |
| 1768 | result.push_str(&format!("[enowX Flux widget: {}]\n", summary)); |
| 1769 | } else { |
| 1770 | preview_content.push_str(line); |
| 1771 | preview_content.push('\n'); |
| 1772 | } |
| 1773 | continue; |
| 1774 | } |
| 1775 | result.push_str(line); |
| 1776 | result.push('\n'); |
| 1777 | } |
| 1778 | |
| 1779 | result.trim().to_string() |
| 1780 | } |
| 1781 | |
| 1782 | /// Extract a compact text summary from HTML widget content. |
| 1783 | /// Keeps: text content, data values, labels, chart config hints. |
no test coverage detected