Abhisingh-18's picture
Mirror of github.com/Abhisingh18/Trust-first-AI-Copilot
f35583f verified
Raw
History Blame Contribute Delete
1.43 kB
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(`(?<!\\[)Source ${sourceNum}(?!\\])`, 'gi');
linkedContent = linkedContent.replace(regex, `[Source ${sourceNum}](${url})`);
});
return linkedContent;
}