4fa4f13558
Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
18 lines
524 B
TypeScript
18 lines
524 B
TypeScript
export const normalizeAssistantDisplayText = (value: string): string => {
|
|
const lines = value.replace(/\r\n?/g, "\n").split("\n");
|
|
const normalized: string[] = [];
|
|
let lastWasBlank = false;
|
|
for (const rawLine of lines) {
|
|
const line = rawLine.replace(/[ \t]+$/g, "");
|
|
if (line.trim().length === 0) {
|
|
if (lastWasBlank) continue;
|
|
normalized.push("");
|
|
lastWasBlank = true;
|
|
continue;
|
|
}
|
|
normalized.push(line);
|
|
lastWasBlank = false;
|
|
}
|
|
return normalized.join("\n").trim();
|
|
};
|