refactor: centralize tool status symbols in constants (#7054)

This commit is contained in:
Arya Gummadi
2025-08-27 07:54:32 -07:00
committed by GitHub
parent 83a40ff9d4
commit 4c3ec1f0cc
3 changed files with 28 additions and 14 deletions

View File

@@ -13,6 +13,7 @@ import type {
Config, Config,
ToolCallConfirmationDetails, ToolCallConfirmationDetails,
} from '@google/gemini-cli-core'; } from '@google/gemini-cli-core';
import { TOOL_STATUS } from '../../constants.js';
// Mock child components to isolate ToolGroupMessage behavior // Mock child components to isolate ToolGroupMessage behavior
vi.mock('./ToolMessage.js', () => ({ vi.mock('./ToolMessage.js', () => ({
@@ -29,14 +30,16 @@ vi.mock('./ToolMessage.js', () => ({
status: ToolCallStatus; status: ToolCallStatus;
emphasis: string; emphasis: string;
}) { }) {
const statusSymbol = { // Use the same constants as the real component
[ToolCallStatus.Success]: '✓', const statusSymbolMap: Record<ToolCallStatus, string> = {
[ToolCallStatus.Pending]: 'o', [ToolCallStatus.Success]: TOOL_STATUS.SUCCESS,
[ToolCallStatus.Executing]: '⊷', [ToolCallStatus.Pending]: TOOL_STATUS.PENDING,
[ToolCallStatus.Confirming]: '?', [ToolCallStatus.Executing]: TOOL_STATUS.EXECUTING,
[ToolCallStatus.Canceled]: '-', [ToolCallStatus.Confirming]: TOOL_STATUS.CONFIRMING,
[ToolCallStatus.Error]: 'x', [ToolCallStatus.Canceled]: TOOL_STATUS.CANCELED,
}[status]; [ToolCallStatus.Error]: TOOL_STATUS.ERROR,
};
const statusSymbol = statusSymbolMap[status] || '?';
return ( return (
<Text> <Text>
MockTool[{callId}]: {statusSymbol} {name} - {description} ({emphasis}) MockTool[{callId}]: {statusSymbol} {name} - {description} ({emphasis})

View File

@@ -13,6 +13,7 @@ import { Colors } from '../../colors.js';
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js'; import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
import { GeminiRespondingSpinner } from '../GeminiRespondingSpinner.js'; import { GeminiRespondingSpinner } from '../GeminiRespondingSpinner.js';
import { MaxSizedBox } from '../shared/MaxSizedBox.js'; import { MaxSizedBox } from '../shared/MaxSizedBox.js';
import { TOOL_STATUS } from '../../constants.js';
const STATIC_HEIGHT = 1; const STATIC_HEIGHT = 1;
const RESERVED_LINE_COUNT = 5; // for tool name, status, padding etc. const RESERVED_LINE_COUNT = 5; // for tool name, status, padding etc.
@@ -119,28 +120,28 @@ const ToolStatusIndicator: React.FC<ToolStatusIndicatorProps> = ({
}) => ( }) => (
<Box minWidth={STATUS_INDICATOR_WIDTH}> <Box minWidth={STATUS_INDICATOR_WIDTH}>
{status === ToolCallStatus.Pending && ( {status === ToolCallStatus.Pending && (
<Text color={Colors.AccentGreen}>o</Text> <Text color={Colors.AccentGreen}>{TOOL_STATUS.PENDING}</Text>
)} )}
{status === ToolCallStatus.Executing && ( {status === ToolCallStatus.Executing && (
<GeminiRespondingSpinner <GeminiRespondingSpinner
spinnerType="toggle" spinnerType="toggle"
nonRespondingDisplay={'⊷'} nonRespondingDisplay={TOOL_STATUS.EXECUTING}
/> />
)} )}
{status === ToolCallStatus.Success && ( {status === ToolCallStatus.Success && (
<Text color={Colors.AccentGreen}></Text> <Text color={Colors.AccentGreen}>{TOOL_STATUS.SUCCESS}</Text>
)} )}
{status === ToolCallStatus.Confirming && ( {status === ToolCallStatus.Confirming && (
<Text color={Colors.AccentYellow}>?</Text> <Text color={Colors.AccentYellow}>{TOOL_STATUS.CONFIRMING}</Text>
)} )}
{status === ToolCallStatus.Canceled && ( {status === ToolCallStatus.Canceled && (
<Text color={Colors.AccentYellow} bold> <Text color={Colors.AccentYellow} bold>
- {TOOL_STATUS.CANCELED}
</Text> </Text>
)} )}
{status === ToolCallStatus.Error && ( {status === ToolCallStatus.Error && (
<Text color={Colors.AccentRed} bold> <Text color={Colors.AccentRed} bold>
x {TOOL_STATUS.ERROR}
</Text> </Text>
)} )}
</Box> </Box>

View File

@@ -19,3 +19,13 @@ export const SHELL_COMMAND_NAME = 'Shell Command';
export const SCREEN_READER_USER_PREFIX = 'User: '; export const SCREEN_READER_USER_PREFIX = 'User: ';
export const SCREEN_READER_MODEL_PREFIX = 'Model: '; export const SCREEN_READER_MODEL_PREFIX = 'Model: ';
// Tool status symbols used in ToolMessage component
export const TOOL_STATUS = {
SUCCESS: '✓',
PENDING: 'o',
EXECUTING: '⊷',
CONFIRMING: '?',
CANCELED: '-',
ERROR: 'x',
} as const;