2026-02-09 19:24:41 -08:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type React from 'react';
|
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
import { Box, Text } from 'ink';
|
|
|
|
|
import type { ThoughtSummary } from '@google/gemini-cli-core';
|
|
|
|
|
import { theme } from '../../semantic-colors.js';
|
2026-02-10 11:12:40 -08:00
|
|
|
import { normalizeEscapedNewlines } from '../../utils/textUtils.js';
|
2026-02-09 19:24:41 -08:00
|
|
|
|
|
|
|
|
interface ThinkingMessageProps {
|
|
|
|
|
thought: ThoughtSummary;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 11:12:40 -08:00
|
|
|
/**
|
|
|
|
|
* Renders a model's thought as a distinct bubble.
|
|
|
|
|
* Leverages Ink layout for wrapping and borders.
|
|
|
|
|
*/
|
|
|
|
|
export const ThinkingMessage: React.FC<ThinkingMessageProps> = ({
|
|
|
|
|
thought,
|
|
|
|
|
}) => {
|
|
|
|
|
const { summary, body } = useMemo(() => {
|
|
|
|
|
const subject = normalizeEscapedNewlines(thought.subject).trim();
|
|
|
|
|
const description = normalizeEscapedNewlines(thought.description).trim();
|
2026-02-09 19:24:41 -08:00
|
|
|
|
2026-02-10 11:12:40 -08:00
|
|
|
if (!subject && !description) {
|
|
|
|
|
return { summary: '', body: '' };
|
2026-02-09 19:24:41 -08:00
|
|
|
}
|
|
|
|
|
|
2026-02-10 11:12:40 -08:00
|
|
|
if (!subject) {
|
|
|
|
|
const lines = description
|
|
|
|
|
.split('\n')
|
|
|
|
|
.map((l) => l.trim())
|
|
|
|
|
.filter(Boolean);
|
|
|
|
|
return {
|
|
|
|
|
summary: lines[0] || '',
|
|
|
|
|
body: lines.slice(1).join('\n'),
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-02-09 19:24:41 -08:00
|
|
|
|
2026-02-10 11:12:40 -08:00
|
|
|
return {
|
|
|
|
|
summary: subject,
|
|
|
|
|
body: description,
|
|
|
|
|
};
|
|
|
|
|
}, [thought]);
|
2026-02-09 19:24:41 -08:00
|
|
|
|
2026-02-10 11:12:40 -08:00
|
|
|
if (!summary && !body) {
|
2026-02-09 19:24:41 -08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-02-10 11:12:40 -08:00
|
|
|
<Box width="100%" marginBottom={1} paddingLeft={1} flexDirection="column">
|
|
|
|
|
{summary && (
|
|
|
|
|
<Box paddingLeft={2}>
|
|
|
|
|
<Text color={theme.text.primary} bold italic>
|
|
|
|
|
{summary}
|
2026-02-09 19:24:41 -08:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
2026-02-10 11:12:40 -08:00
|
|
|
)}
|
|
|
|
|
{body && (
|
|
|
|
|
<Box
|
|
|
|
|
borderStyle="single"
|
|
|
|
|
borderLeft
|
|
|
|
|
borderRight={false}
|
|
|
|
|
borderTop={false}
|
|
|
|
|
borderBottom={false}
|
|
|
|
|
borderColor={theme.border.default}
|
|
|
|
|
paddingLeft={1}
|
|
|
|
|
>
|
|
|
|
|
<Text color={theme.text.secondary} italic>
|
|
|
|
|
{body}
|
2026-02-09 19:24:41 -08:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
2026-02-10 11:12:40 -08:00
|
|
|
)}
|
2026-02-09 19:24:41 -08:00
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|