import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } export function cleanMessageContent(content: string): string { if (!content) return ""; // Remove "Assumptions & Risks" section and everything until the next header or end let cleaned = content.replace(/### ⚠️ Assumptions & Risks[\s\S]*?(?=### |$)/g, ""); // Remove "Unknowns / Limitations" section and everything until the next header or end cleaned = cleaned.replace(/### ❌ Unknowns \/ Limitations[\s\S]*?(?=### |$)/g, ""); return cleaned.trim(); } export function linkifySources(content: string, sources: any[] = []): string { if (!content || !sources.length) return content; let linkedContent = content; sources.forEach((source, index) => { const sourceNum = index + 1; const url = source.url || "#"; // Regex to find "Source X" or "(Source X)" case insensitive // We use a complex regex to avoid double linking if run multiple times or overlapping // Simplified: Look for "Source X" that isn't already inside a markdown link const regex = new RegExp(`(?