Files
gemini-cli/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx
T

68 lines
2.1 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
2025-04-15 21:41:08 -07:00
import React from 'react';
import { Box } from 'ink';
import { IndividualToolCallDisplay, ToolCallStatus } from '../../types.js';
2025-04-18 19:09:41 -04:00
import { ToolMessage } from './ToolMessage.js';
import { ToolConfirmationMessage } from './ToolConfirmationMessage.js';
2025-04-19 12:38:09 -04:00
import { Colors } from '../../colors.js';
2025-04-15 21:41:08 -07:00
interface ToolGroupMessageProps {
groupId: number;
2025-04-17 18:06:21 -04:00
toolCalls: IndividualToolCallDisplay[];
2025-04-15 21:41:08 -07:00
}
// Main component renders the border and maps the tools using ToolMessage
2025-04-18 19:09:41 -04:00
export const ToolGroupMessage: React.FC<ToolGroupMessageProps> = ({
groupId,
2025-04-17 18:06:21 -04:00
toolCalls,
}) => {
2025-04-22 07:48:12 -04:00
const hasPending = !toolCalls.every(
(t) => t.status === ToolCallStatus.Success,
);
2025-05-08 16:00:55 -07:00
const borderColor = hasPending ? Colors.AccentYellow : Colors.AccentPurple;
2025-04-15 21:41:08 -07:00
2025-04-17 18:06:21 -04:00
return (
2025-04-22 07:48:12 -04:00
<Box
key={groupId}
2025-04-22 07:48:12 -04:00
flexDirection="column"
borderStyle="round"
/*
This width constraint is highly important and protects us from an Ink rendering bug.
Since the ToolGroup can typically change rendering states frequently, it can cause
Ink to render the border of the box incorrectly and span multiple lines and even
cause tearing.
*/
width="100%"
marginLeft={1}
2025-04-22 07:48:12 -04:00
borderDimColor={hasPending}
borderColor={borderColor}
marginBottom={1}
2025-04-22 07:48:12 -04:00
>
2025-04-18 10:53:16 -04:00
{toolCalls.map((tool) => (
<Box key={groupId + '-' + tool.callId} flexDirection="column">
2025-04-18 18:08:43 -04:00
<ToolMessage
key={tool.callId} // Use callId as the key
callId={tool.callId} // Pass callId
2025-04-18 18:08:43 -04:00
name={tool.name}
description={tool.description}
resultDisplay={tool.resultDisplay}
status={tool.status}
confirmationDetails={tool.confirmationDetails} // Pass confirmationDetails
2025-04-18 18:08:43 -04:00
/>
{tool.status === ToolCallStatus.Confirming &&
tool.confirmationDetails && (
<ToolConfirmationMessage
confirmationDetails={tool.confirmationDetails}
></ToolConfirmationMessage>
)}
</Box>
2025-04-18 18:08:43 -04:00
))}
2025-04-17 18:06:21 -04:00
</Box>
);
2025-04-15 21:41:08 -07:00
};