openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
25 lines (24 loc) • 1.2 kB
JavaScript
import { y as stripReasoningTagsFromText } from "./assistant-visible-text-BSYbiXdn.js";
//#region src/shared/text/formatted-reasoning-message.ts
/** Strip provider-formatted Reasoning/Thinking preambles from visible text. */
function stripFormattedReasoningMessage(text) {
const stripped = stripReasoningTagsFromText(text);
const firstNewline = stripped.indexOf("\n");
const prefix = (firstNewline === -1 ? stripped : stripped.slice(0, firstNewline)).trim();
const thinking = /^Thinking\.{0,3}$/u.test(prefix);
if (prefix !== "Reasoning:" && !thinking) return stripped;
let offset = firstNewline === -1 ? stripped.length : firstNewline + 1;
let hasSummary = false;
while (offset < stripped.length) {
const newline = stripped.indexOf("\n", offset);
const end = newline === -1 ? stripped.length : newline;
const line = stripped.slice(offset, end).trim();
const isSummary = line.length >= 2 && line.startsWith("_") && line.endsWith("_");
if (line && !isSummary) break;
hasSummary ||= isSummary;
offset = end + 1;
}
return thinking && !hasSummary ? stripped : stripped.slice(offset).replace(/\r\n/g, "\n").trim();
}
//#endregion
export { stripFormattedReasoningMessage as t };