CompletionTool.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Box, Text } from "ink"
  2. import * as theme from "../../theme.js"
  3. import type { ToolRendererProps } from "./types.js"
  4. import { truncateText, sanitizeContent } from "./utils.js"
  5. const MAX_CONTENT_LINES = 15
  6. export function CompletionTool({ toolData }: ToolRendererProps) {
  7. const result = toolData.result ? sanitizeContent(toolData.result) : ""
  8. const question = toolData.question ? sanitizeContent(toolData.question) : ""
  9. const content = toolData.content ? sanitizeContent(toolData.content) : ""
  10. const isQuestion = toolData.tool.includes("question") || toolData.tool.includes("Question")
  11. const displayContent = result || question || content
  12. const { text: previewContent, truncated, hiddenLines } = truncateText(displayContent, MAX_CONTENT_LINES)
  13. return previewContent ? (
  14. <Box flexDirection="column" paddingX={1} marginBottom={1}>
  15. {isQuestion ? (
  16. <Box flexDirection="column">
  17. <Text color={theme.text}>{previewContent}</Text>
  18. </Box>
  19. ) : (
  20. <Box flexDirection="column">
  21. {previewContent.split("\n").map((line, i) => (
  22. <Text key={i} color={theme.toolText}>
  23. {line}
  24. </Text>
  25. ))}
  26. </Box>
  27. )}
  28. {truncated && (
  29. <Text color={theme.dimText} dimColor>
  30. ... ({hiddenLines} more lines)
  31. </Text>
  32. )}
  33. </Box>
  34. ) : null
  35. }