({
chatHistory,
sessionTitle,
}: SessionPreviewProps)
| 24 | } |
| 25 | |
| 26 | export function SessionPreview({ |
| 27 | chatHistory, |
| 28 | sessionTitle, |
| 29 | }: SessionPreviewProps) { |
| 30 | const { rows: terminalHeight } = useTerminalSize(); |
| 31 | |
| 32 | // Filter and format messages for preview |
| 33 | const previewMessages = useMemo(() => { |
| 34 | return chatHistory |
| 35 | .filter((item) => { |
| 36 | // Skip system messages |
| 37 | if (item.message.role === "system") return false; |
| 38 | |
| 39 | // Skip empty assistant messages |
| 40 | if (item.message.role === "assistant") { |
| 41 | const content = formatMessageContent(item.message.content); |
| 42 | if (!content || content.trim() === "") return false; |
| 43 | } |
| 44 | |
| 45 | return true; |
| 46 | }) |
| 47 | .map((item) => ({ |
| 48 | role: item.message.role, |
| 49 | content: formatMessageContent(item.message.content), |
| 50 | })); |
| 51 | }, [chatHistory]); |
| 52 | |
| 53 | // Calculate how many messages we can display based on terminal height |
| 54 | const maxMessages = useMemo(() => { |
| 55 | // Account for: |
| 56 | // - Box border (top + bottom): 2 lines |
| 57 | // - Box padding (top + bottom): 2 lines |
| 58 | // - Title line: 1 line |
| 59 | // - Empty line after title: 1 line |
| 60 | // - "... and X more messages" line: 1 line |
| 61 | // - Each message: ~4 lines (role + content + marginBottom) |
| 62 | const OVERHEAD = 7; |
| 63 | const LINES_PER_MESSAGE = 4; |
| 64 | const availableHeight = Math.max(1, terminalHeight - OVERHEAD); |
| 65 | return Math.max(1, Math.floor(availableHeight / LINES_PER_MESSAGE)); |
| 66 | }, [terminalHeight]); |
| 67 | |
| 68 | if (previewMessages.length === 0) { |
| 69 | return ( |
| 70 | <Box {...defaultBoxStyles("blue")} flexDirection="column" width="100%"> |
| 71 | <Text color="blue" bold> |
| 72 | Preview |
| 73 | </Text> |
| 74 | <Text color="gray">(no messages)</Text> |
| 75 | </Box> |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | return ( |
| 80 | <Box {...defaultBoxStyles("blue")} flexDirection="column" width="100%"> |
| 81 | <Text color="blue" bold> |
| 82 | {sessionTitle} |
| 83 | </Text> |
nothing calls this directly
no test coverage detected