Skip to content

Commit 5d29c8f

Browse files
committed
fix: strip leading empty lines in sanitizeUserFacingText (#16158) (thanks @mcinteerj)
1 parent 90a8394 commit 5d29c8f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/agents/pi-embedded-helpers/errors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,10 @@ export function sanitizeUserFacingText(text: string, opts?: { errorContext?: boo
527527
}
528528
}
529529

530-
return collapseConsecutiveDuplicateBlocks(stripped).trimStart();
530+
// Strip leading blank lines (including whitespace-only lines) without clobbering indentation on
531+
// the first content line (e.g. markdown/code blocks).
532+
const withoutLeadingEmptyLines = stripped.replace(/^(?:[ \t]*\r?\n)+/, "");
533+
return collapseConsecutiveDuplicateBlocks(withoutLeadingEmptyLines);
531534
}
532535

533536
export function isRateLimitAssistantError(msg: AssistantMessage | undefined): boolean {

0 commit comments

Comments
 (0)