From 3fce6cea27d3e6129d6c06e528b62e1b11bf7094 Mon Sep 17 00:00:00 2001 From: Evan Senter Date: Sat, 19 Apr 2025 19:45:42 +0100 Subject: Starting to modularize into separate cli / server packages. (#55) * Starting to move a lot of code into packages/server * More of the massive refactor, builds and runs, some issues though. * Fixing outstanding issue with double messages. * Fixing a minor UI issue. * Fixing the build post-merge. * Running formatting. * Addressing comments. --- .../cli/src/ui/components/messages/ToolMessage.tsx | 144 +++++++++++++-------- 1 file changed, 92 insertions(+), 52 deletions(-) (limited to 'packages/cli/src/ui/components/messages/ToolMessage.tsx') diff --git a/packages/cli/src/ui/components/messages/ToolMessage.tsx b/packages/cli/src/ui/components/messages/ToolMessage.tsx index da93b18a..9c1dd36b 100644 --- a/packages/cli/src/ui/components/messages/ToolMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolMessage.tsx @@ -7,70 +7,110 @@ import React from 'react'; import { Box, Text } from 'ink'; import Spinner from 'ink-spinner'; -import { ToolCallStatus } from '../../types.js'; -import { ToolResultDisplay } from '../../../tools/tools.js'; +import { + IndividualToolCallDisplay, + ToolCallStatus, + ToolCallConfirmationDetails, + ToolEditConfirmationDetails, + ToolExecuteConfirmationDetails, +} from '../../types.js'; import { DiffRenderer } from './DiffRenderer.js'; -import { MarkdownRenderer } from '../../utils/MarkdownRenderer.js'; +import { FileDiff, ToolResultDisplay } from '../../../tools/tools.js'; -interface ToolMessageProps { - name: string; - description: string; - resultDisplay: ToolResultDisplay | undefined; - status: ToolCallStatus; -} - -export const ToolMessage: React.FC = ({ +export const ToolMessage: React.FC = ({ + callId, name, description, resultDisplay, status, + confirmationDetails, }) => { - const statusIndicatorWidth = 3; - const hasResult = - (status === ToolCallStatus.Invoked || status === ToolCallStatus.Canceled) && - resultDisplay && - resultDisplay.toString().trim().length > 0; + // Explicitly type the props to help the type checker + const typedConfirmationDetails = confirmationDetails as + | ToolCallConfirmationDetails + | undefined; + const typedResultDisplay = resultDisplay as ToolResultDisplay | undefined; + + let color = 'gray'; + let prefix = ''; + switch (status) { + case ToolCallStatus.Pending: + prefix = 'Pending:'; + break; + case ToolCallStatus.Invoked: + prefix = 'Executing:'; + break; + case ToolCallStatus.Confirming: + color = 'yellow'; + prefix = 'Confirm:'; + break; + case ToolCallStatus.Success: + color = 'green'; + prefix = 'Success:'; + break; + case ToolCallStatus.Error: + color = 'red'; + prefix = 'Error:'; + break; + default: + // Handle unexpected status if necessary, or just break + break; + } + + const title = `${prefix} ${name}`; return ( - - {/* Row for Status Indicator and Tool Info */} - - {/* Status Indicator */} - - {status === ToolCallStatus.Pending && } - {status === ToolCallStatus.Invoked && } - {status === ToolCallStatus.Confirming && ?} - {status === ToolCallStatus.Canceled && ( - - - + + + {status === ToolCallStatus.Invoked && ( + + + + + )} + + {title} + + + {status === ToolCallStatus.Error && typedResultDisplay + ? `: ${typedResultDisplay}` + : ` - ${description}`} + + + {status === ToolCallStatus.Confirming && typedConfirmationDetails && ( + + {/* Display diff for edit/write */} + {'fileDiff' in typedConfirmationDetails && ( + )} + {/* Display command for execute */} + {'command' in typedConfirmationDetails && ( + + Command:{' '} + { + (typedConfirmationDetails as ToolExecuteConfirmationDetails) + .command + } + + )} + {/* */} - - - {name} {description} - - - - - {hasResult && ( - - - - {/* Use default text color (white) or gray instead of dimColor */} - {typeof resultDisplay === 'string' && ( - - {MarkdownRenderer.render(resultDisplay)} - - )} - {typeof resultDisplay === 'object' && ( - - )} - + )} + {status === ToolCallStatus.Success && typedResultDisplay && ( + + {typeof typedResultDisplay === 'string' ? ( + {typedResultDisplay} + ) : ( + + )} )} -- cgit v1.2.3