(text: string)
| 87 | * render. For append-only stdout streams use {@link StreamDisplayFilter} instead. |
| 88 | */ |
| 89 | export function stripThinkingForDisplay(text: string): string { |
| 90 | if (!text) return text; |
| 91 | // Fast path: no tags to extract, but STILL collapse runaway blank lines and |
| 92 | // trim. Some local models emit long runs of newlines before their answer; |
| 93 | // without this they'd render as a huge gap (the old early-return skipped it). |
| 94 | if (!text.includes('<')) { |
| 95 | return text.replace(/\n{3,}/g, '\n\n').replace(/^\s+/, ''); |
| 96 | } |
| 97 | let s = extractThinking(text).visibleText; |
| 98 | // An unclosed block mid-stream: cut from the opening tag to the end, dropping the |
| 99 | // now-dangling whitespace that preceded it. |
| 100 | const open = s.match(/<(thinking|think|reasoning|reflection)>[\s\S]*$/i); |
| 101 | if (open && open.index !== undefined) s = s.slice(0, open.index).trimEnd(); |
| 102 | return trimTrailingPartialTag(s); |
| 103 | } |
| 104 | |
| 105 | // Tag-delimited spans we suppress from display. Two kinds leak from local models that |
| 106 | // emit tool calls (or reasoning) as plain text instead of via the structured field: |
no test coverage detected