File size: 1,372 Bytes
8b41737 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | export interface HighlightSegment {
text: string;
className: string;
}
export function highlightTrace(text: string): HighlightSegment[] {
if (!text) return [{ text: "(no response)", className: "text-gray-500 italic" }];
const segments: HighlightSegment[] = [];
const lines = text.split("\n");
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const lo = line.toLowerCase().trim();
let className = "text-gray-300";
if (lo.startsWith("wait") || lo.startsWith("hmm") || lo.startsWith("but wait")) {
className = "text-yellow-400";
} else if (lo.startsWith("let me try") || lo.startsWith("let me reconsider") || lo.startsWith("let me think")) {
className = "text-cyan-400";
} else if (lo.startsWith("so the answer") || lo.startsWith("so the expression") || lo.startsWith("therefore") || lo.startsWith("the final")) {
className = "text-green-400 font-bold";
} else if (lo.startsWith("i give up") || lo.startsWith("i can't find") || lo.startsWith("i'm stuck") || lo.startsWith("i'm sorry")) {
className = "text-red-400 font-bold";
} else if (line.includes("=") && /[+\-*/]/.test(line)) {
className = "text-gray-100";
}
segments.push({ text: line, className });
if (i < lines.length - 1) {
segments.push({ text: "\n", className: "" });
}
}
return segments;
}
|