/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import React from 'react'; import { Box, Text } from 'ink'; import Spinner from 'ink-spinner'; import { IndividualToolCallDisplay, ToolCallStatus } from '../../types.js'; import { DiffRenderer } from './DiffRenderer.js'; import { Colors } from '../../colors.js'; import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js'; export interface ToolMessageProps extends IndividualToolCallDisplay { availableTerminalHeight: number; } export const ToolMessage: React.FC = ({ name, description, resultDisplay, status, availableTerminalHeight, }) => { const statusIndicatorWidth = 3; const hasResult = resultDisplay && resultDisplay.toString().trim().length > 0; const staticHeight = /* Header */ 1; let displayableResult = resultDisplay; let hiddenLines = 0; // Truncate the overall string content if it's too long. // MarkdownRenderer will handle specific truncation for code blocks within this content. if (typeof resultDisplay === 'string' && resultDisplay.length > 0) { const lines = resultDisplay.split('\n'); // Estimate available height for this specific tool message content area // This is a rough estimate; ideally, we'd have a more precise measurement. const contentHeightEstimate = availableTerminalHeight - staticHeight - 5; // Subtracting lines for tool name, status, padding etc. if (lines.length > contentHeightEstimate && contentHeightEstimate > 0) { displayableResult = lines.slice(0, contentHeightEstimate).join('\n'); hiddenLines = lines.length - contentHeightEstimate; } } return ( {/* Status Indicator */} {(status === ToolCallStatus.Pending || status === ToolCallStatus.Executing) && } {status === ToolCallStatus.Success && ( )} {status === ToolCallStatus.Confirming && ( ? )} {status === ToolCallStatus.Canceled && ( - )} {status === ToolCallStatus.Error && ( x )} {name}{' '} {description} {hasResult && ( {typeof displayableResult === 'string' && ( )} {typeof displayableResult === 'object' && ( )} {hiddenLines > 0 && ( ... {hiddenLines} more line{hiddenLines === 1 ? '' : 's'}{' '} hidden ... )} )} ); };