2025-04-18 17:44:24 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
import type React from 'react';
|
2025-04-15 21:41:08 -07:00
|
|
|
import { Text, Box } from 'ink';
|
2025-05-15 00:36:08 -07:00
|
|
|
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
|
2026-01-27 16:06:24 -08:00
|
|
|
import { ShowMoreLines } from '../ShowMoreLines.js';
|
2025-09-10 10:57:07 -07:00
|
|
|
import { theme } from '../../semantic-colors.js';
|
2025-08-28 20:52:14 +00:00
|
|
|
import { SCREEN_READER_MODEL_PREFIX } from '../../textConstants.js';
|
2025-10-16 11:23:36 -07:00
|
|
|
import { useUIState } from '../../contexts/UIStateContext.js';
|
2025-11-11 07:50:11 -08:00
|
|
|
import { useAlternateBuffer } from '../../hooks/useAlternateBuffer.js';
|
2025-04-15 21:41:08 -07:00
|
|
|
|
|
|
|
|
interface GeminiMessageProps {
|
2025-04-17 18:06:21 -04:00
|
|
|
text: string;
|
2025-05-15 22:56:03 -07:00
|
|
|
isPending: boolean;
|
2025-06-19 20:17:23 +00:00
|
|
|
availableTerminalHeight?: number;
|
|
|
|
|
terminalWidth: number;
|
2025-04-15 21:41:08 -07:00
|
|
|
}
|
|
|
|
|
|
2025-05-15 22:56:03 -07:00
|
|
|
export const GeminiMessage: React.FC<GeminiMessageProps> = ({
|
|
|
|
|
text,
|
|
|
|
|
isPending,
|
|
|
|
|
availableTerminalHeight,
|
2025-06-19 20:17:23 +00:00
|
|
|
terminalWidth,
|
2025-05-15 22:56:03 -07:00
|
|
|
}) => {
|
2025-10-16 11:23:36 -07:00
|
|
|
const { renderMarkdown } = useUIState();
|
2025-04-17 18:06:21 -04:00
|
|
|
const prefix = '✦ ';
|
|
|
|
|
const prefixWidth = prefix.length;
|
|
|
|
|
|
2025-11-11 07:50:11 -08:00
|
|
|
const isAlternateBuffer = useAlternateBuffer();
|
2025-04-17 18:06:21 -04:00
|
|
|
return (
|
|
|
|
|
<Box flexDirection="row">
|
2025-04-22 07:48:12 -04:00
|
|
|
<Box width={prefixWidth}>
|
2025-09-10 10:57:07 -07:00
|
|
|
<Text color={theme.text.accent} aria-label={SCREEN_READER_MODEL_PREFIX}>
|
2025-08-21 22:29:15 +00:00
|
|
|
{prefix}
|
|
|
|
|
</Text>
|
2025-04-22 07:48:12 -04:00
|
|
|
</Box>
|
2025-04-17 18:06:21 -04:00
|
|
|
<Box flexGrow={1} flexDirection="column">
|
2025-05-15 22:56:03 -07:00
|
|
|
<MarkdownDisplay
|
|
|
|
|
text={text}
|
|
|
|
|
isPending={isPending}
|
2025-11-11 07:50:11 -08:00
|
|
|
availableTerminalHeight={
|
2026-01-27 16:06:24 -08:00
|
|
|
isAlternateBuffer || availableTerminalHeight === undefined
|
|
|
|
|
? undefined
|
|
|
|
|
: Math.max(availableTerminalHeight - 1, 1)
|
2025-11-11 07:50:11 -08:00
|
|
|
}
|
2025-06-19 20:17:23 +00:00
|
|
|
terminalWidth={terminalWidth}
|
2025-10-16 11:23:36 -07:00
|
|
|
renderMarkdown={renderMarkdown}
|
2025-05-15 22:56:03 -07:00
|
|
|
/>
|
2026-02-09 20:18:21 -08:00
|
|
|
<Box
|
|
|
|
|
marginTop={isAlternateBuffer ? 0 : 1}
|
|
|
|
|
marginBottom={isAlternateBuffer ? 1 : 0}
|
|
|
|
|
>
|
2026-01-27 16:06:24 -08:00
|
|
|
<ShowMoreLines
|
|
|
|
|
constrainHeight={availableTerminalHeight !== undefined}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
2025-04-17 18:06:21 -04:00
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2025-04-15 21:41:08 -07:00
|
|
|
};
|