| 1 | export const STREAMING_REASONING_TAIL_CHARS = 12_000; |
| 2 | export const STREAMING_REASONING_TAIL_LINES = 240; |
| 3 | |
| 4 | type ReasoningDisplayOptions = { |
| 5 | streaming: boolean; |
| 6 | truncateStreaming?: boolean; |
| 7 | maxChars?: number; |
| 8 | maxLines?: number; |
| 9 | }; |
| 10 | |
| 11 | export function displayReasoningText( |
| 12 | reasoning: string, |
| 13 | { |
| 14 | streaming, |
| 15 | truncateStreaming = true, |
| 16 | maxChars = STREAMING_REASONING_TAIL_CHARS, |
| 17 | maxLines = STREAMING_REASONING_TAIL_LINES, |
| 18 | }: ReasoningDisplayOptions, |
| 19 | ): string { |
| 20 | if (!streaming || !truncateStreaming) return reasoning; |
| 21 | |
| 22 | let text = reasoning; |
| 23 | let truncated = false; |
| 24 | |
| 25 | if (maxChars > 0 && text.length > maxChars) { |
| 26 | text = text.slice(-maxChars); |
| 27 | truncated = true; |
| 28 | } |
| 29 | |
| 30 | if (maxLines > 0) { |
| 31 | const lines = text.split(/\r?\n/); |
| 32 | if (lines.length > maxLines) { |
| 33 | text = lines.slice(-maxLines).join("\n"); |
| 34 | truncated = true; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return truncated ? `...\n${text}` : text; |
| 39 | } |
| 40 |