(text: string)
| 35 | } |
| 36 | |
| 37 | export function extractThinking(text: string): ThinkingExtraction { |
| 38 | if (!text || !text.includes('<')) return { visibleText: text, thinkingBlocks: [] }; |
| 39 | const blocks: string[] = []; |
| 40 | const visible = text.replace(THINKING_TAG_RE, (_match, _tag, inner: string) => { |
| 41 | blocks.push(inner.trim()); |
| 42 | return ''; |
| 43 | }).replace(/\n{3,}/g, '\n\n').trim(); |
| 44 | return { visibleText: visible, thinkingBlocks: blocks }; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Detect partial/streaming thinking — text that starts a tag but hasn't closed yet. |
no test coverage detected