summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/messages/GeminiMessage.tsx
blob: 96773358c5393002c4bc99d5a28e7db2720edfb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from 'react';
import { Text, Box } from 'ink';
import { MarkdownRenderer } from '../../utils/MarkdownRenderer.js';

interface GeminiMessageProps {
  text: string;
}

export const GeminiMessage: React.FC<GeminiMessageProps> = ({ text }) => {
  const prefix = '✦ ';
  const prefixWidth = prefix.length;

  // Handle potentially null or undefined text gracefully
  const safeText = text || '';

  // Use the static render method from the MarkdownRenderer class
  // Pass safeText which is guaranteed to be a string
  const renderedBlocks = MarkdownRenderer.render(safeText);

  // If the original text was actually empty/null, render the minimal state
  if (!safeText && renderedBlocks.length === 0) {
    return (
      <Box flexDirection="row">
        <Box width={prefixWidth}>
          <Text color="blue">{prefix}</Text>
        </Box>
        <Box flexGrow={1}></Box>
      </Box>
    );
  }

  return (
    <Box flexDirection="row">
      <Box width={prefixWidth}>
        <Text color="blue">{prefix}</Text>
      </Box>
      <Box flexGrow={1} flexDirection="column">
        {renderedBlocks}
      </Box>
    </Box>
  );
};