blob: f21e1d286d22537f0b66abccb324ac303382b84e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/**
* @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 { FileDiff, ToolResultDisplay } from '../../../tools/tools.js';
import { Colors } from '../../colors.js';
export const ToolMessage: React.FC<IndividualToolCallDisplay> = ({
callId,
name,
description,
resultDisplay,
status,
}) => {
const typedResultDisplay = resultDisplay as ToolResultDisplay | undefined;
let color = Colors.SubtleComment;
let prefix = '';
switch (status) {
case ToolCallStatus.Pending:
prefix = 'Pending:';
break;
case ToolCallStatus.Invoked:
prefix = 'Executing:';
break;
case ToolCallStatus.Confirming:
color = Colors.AccentYellow;
prefix = 'Confirm:';
break;
case ToolCallStatus.Success:
color = Colors.AccentGreen;
prefix = 'Success:';
break;
case ToolCallStatus.Error:
color = Colors.AccentRed;
prefix = 'Error:';
break;
default:
// Handle unexpected status if necessary, or just break
break;
}
const title = `${prefix} ${name}`;
return (
<Box key={callId} flexDirection="column" paddingX={1}>
<Box>
{status === ToolCallStatus.Invoked && (
<Box marginRight={1}>
<Text color={Colors.AccentBlue}>
<Spinner type="dots" />
</Text>
</Box>
)}
<Text bold color={color}>
{title}
</Text>
<Text color={color}>
{status === ToolCallStatus.Error && typedResultDisplay
? `: ${typedResultDisplay}`
: ` - ${description}`}
</Text>
</Box>
{status === ToolCallStatus.Success && typedResultDisplay && (
<Box flexDirection="column" marginLeft={2}>
{typeof typedResultDisplay === 'string' ? (
<Text>{typedResultDisplay}</Text>
) : (
<DiffRenderer
diffContent={(typedResultDisplay as FileDiff).fileDiff}
/>
)}
</Box>
)}
</Box>
);
};
|