mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:21:23 +00:00
fix: log env opts and collapse duplicate blocks
This commit is contained in:
@@ -77,6 +77,29 @@ function stripFinalTagsFromText(text: string): string {
|
||||
return text.replace(FINAL_TAG_RE, "");
|
||||
}
|
||||
|
||||
function collapseConsecutiveDuplicateBlocks(text: string): string {
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed) return text;
|
||||
const blocks = trimmed.split(/\n{2,}/);
|
||||
if (blocks.length < 2) return text;
|
||||
|
||||
const normalizeBlock = (value: string) => value.trim().replace(/\s+/g, " ");
|
||||
const result: string[] = [];
|
||||
let lastNormalized: string | null = null;
|
||||
|
||||
for (const block of blocks) {
|
||||
const normalized = normalizeBlock(block);
|
||||
if (lastNormalized && normalized === lastNormalized) {
|
||||
continue;
|
||||
}
|
||||
result.push(block.trim());
|
||||
lastNormalized = normalized;
|
||||
}
|
||||
|
||||
if (result.length === blocks.length) return text;
|
||||
return result.join("\n\n");
|
||||
}
|
||||
|
||||
function isLikelyHttpErrorText(raw: string): boolean {
|
||||
const match = raw.match(HTTP_STATUS_PREFIX_RE);
|
||||
if (!match) return false;
|
||||
@@ -321,7 +344,7 @@ export function sanitizeUserFacingText(text: string): string {
|
||||
return formatRawAssistantErrorForUi(trimmed);
|
||||
}
|
||||
|
||||
return stripped;
|
||||
return collapseConsecutiveDuplicateBlocks(stripped);
|
||||
}
|
||||
|
||||
export function isRateLimitAssistantError(msg: AssistantMessage | undefined): boolean {
|
||||
|
||||
Reference in New Issue
Block a user