Skip to content

Commit be41931

Browse files
authored
feat: enhance ToolCallMessage component with dynamic status colors (#110)
Added a new utility function to determine color classes based on the status and error state of tool calls. This improves the visual feedback in the ToolCallMessage component by using color-coded indicators for different states (error, completed, loading). This change enhances user experience by providing clearer status information at a glance. ![CleanShot 2025-07-07 at 16 15 25](https://github.com/user-attachments/assets/9bbd8f67-ef45-4f01-b355-83c906ddffd0) ![CleanShot 2025-07-07 at 16 14 09@2x](https://github.com/user-attachments/assets/6ba87eba-f5ae-48f5-8011-b67bf90d2792) Closes #111
1 parent 2fb50c1 commit be41931

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/components/ToolCallMessage.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ const getStatusText = (status?: string, error?: string) => {
3838
return 'Tool call'
3939
}
4040

41+
const getColorClasses = (status?: string, error?: string) => {
42+
// Red for failed/error states
43+
if (error || status?.includes('failed')) {
44+
return {
45+
icon: 'bg-red-100 text-red-600 dark:bg-red-900 dark:text-red-300',
46+
content: 'bg-red-50 text-red-900 dark:bg-red-950 dark:text-red-100',
47+
}
48+
}
49+
50+
// Green for completed/done states
51+
if (status?.includes('completed') || status?.includes('done')) {
52+
return {
53+
icon: 'bg-green-100 text-green-600 dark:bg-green-900 dark:text-green-300',
54+
content:
55+
'bg-green-50 text-green-900 dark:bg-green-950 dark:text-green-100',
56+
}
57+
}
58+
59+
// Yellow for loading/working states (in progress, preparing, etc.)
60+
return {
61+
icon: 'bg-yellow-100 text-yellow-600 dark:bg-yellow-900 dark:text-yellow-300',
62+
content:
63+
'bg-yellow-50 text-yellow-900 dark:bg-yellow-950 dark:text-yellow-100',
64+
}
65+
}
66+
4167
const getTitle = (name: string, args: ToolCallMessageProps['args']) => {
4268
// For tool calls, include the tool name if available
4369
if (args.toolName) {
@@ -51,14 +77,20 @@ const getTitle = (name: string, args: ToolCallMessageProps['args']) => {
5177
}
5278

5379
export function ToolCallMessage({ name, args }: ToolCallMessageProps) {
80+
const colorClasses = getColorClasses(args.status, args.error)
81+
5482
return (
5583
<div className="flex w-full max-w-full gap-2 py-2 animate-in fade-in justify-start">
56-
<div className="flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-md bg-orange-100 text-orange-600 dark:bg-orange-900 dark:text-orange-300">
84+
<div
85+
className={`flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-md ${colorClasses.icon}`}
86+
>
5787
<Wrench className="h-5 w-5" />
5888
</div>
5989

6090
<div className="flex flex-col space-y-1 items-start w-full sm:w-[85%] md:w-[75%] lg:w-[65%]">
61-
<details className="rounded-2xl px-4 py-2 text-sm w-full group [&:not([open])]:h-8 [&:not([open])]:flex [&:not([open])]:items-center [&:not([open])]:py-0 bg-orange-50 text-orange-900 dark:bg-orange-950 dark:text-orange-100">
91+
<details
92+
className={`rounded-2xl px-4 py-2 text-sm w-full group [&:not([open])]:h-8 [&:not([open])]:flex [&:not([open])]:items-center [&:not([open])]:py-0 ${colorClasses.content}`}
93+
>
6294
<summary className="font-medium mb-1 flex items-center gap-2 list-none [&::-webkit-details-marker]:hidden cursor-pointer group-[&:not([open])]:mb-0">
6395
<ChevronRight className="h-4 w-4 transition-transform group-open:rotate-90" />
6496
{getTitle(name, args)}

0 commit comments

Comments
 (0)