Skip to content

Commit a3a1ad4

Browse files
authored
Merge pull request #275 from kavinkumar807/highlight-tool-errors-in-red-text
feat: highlight tool errors in red text
2 parents 6c07559 + 1596973 commit a3a1ad4

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

client/src/components/JsonView.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface JsonViewProps {
1212
initialExpandDepth?: number;
1313
className?: string;
1414
withCopyButton?: boolean;
15+
isError?: boolean;
1516
}
1617

1718
const JsonView = memo(
@@ -21,6 +22,7 @@ const JsonView = memo(
2122
initialExpandDepth = 3,
2223
className,
2324
withCopyButton = true,
25+
isError = false,
2426
}: JsonViewProps) => {
2527
const { toast } = useToast();
2628
const [copied, setCopied] = useState(false);
@@ -86,6 +88,7 @@ const JsonView = memo(
8688
name={name}
8789
depth={0}
8890
initialExpandDepth={initialExpandDepth}
91+
isError={isError}
8992
/>
9093
</div>
9194
</div>
@@ -100,17 +103,25 @@ interface JsonNodeProps {
100103
name?: string;
101104
depth: number;
102105
initialExpandDepth: number;
106+
isError?: boolean;
103107
}
104108

105109
const JsonNode = memo(
106-
({ data, name, depth = 0, initialExpandDepth }: JsonNodeProps) => {
110+
({
111+
data,
112+
name,
113+
depth = 0,
114+
initialExpandDepth,
115+
isError = false,
116+
}: JsonNodeProps) => {
107117
const [isExpanded, setIsExpanded] = useState(depth < initialExpandDepth);
108118
const [typeStyleMap] = useState<Record<string, string>>({
109119
number: "text-blue-600",
110120
boolean: "text-amber-600",
111121
null: "text-purple-600",
112122
undefined: "text-gray-600",
113-
string: "text-green-600 break-all whitespace-pre-wrap",
123+
string: "text-green-600 group-hover:text-green-500",
124+
error: "text-red-600 group-hover:text-red-500",
114125
default: "text-gray-700",
115126
});
116127
const dataType = getDataType(data);
@@ -214,7 +225,14 @@ const JsonNode = memo(
214225
{name}:
215226
</span>
216227
)}
217-
<pre className={typeStyleMap.string}>"{value}"</pre>
228+
<pre
229+
className={clsx(
230+
typeStyleMap.string,
231+
"break-all whitespace-pre-wrap",
232+
)}
233+
>
234+
"{value}"
235+
</pre>
218236
</div>
219237
);
220238
}
@@ -228,8 +246,8 @@ const JsonNode = memo(
228246
)}
229247
<pre
230248
className={clsx(
231-
typeStyleMap.string,
232-
"cursor-pointer group-hover:text-green-500",
249+
isError ? typeStyleMap.error : typeStyleMap.string,
250+
"cursor-pointer break-all whitespace-pre-wrap",
233251
)}
234252
onClick={() => setIsExpanded(!isExpanded)}
235253
title={isExpanded ? "Click to collapse" : "Click to expand"}

client/src/components/ToolsTab.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ const ToolsTab = ({
6969
return (
7070
<>
7171
<h4 className="font-semibold mb-2">
72-
Tool Result: {isError ? "Error" : "Success"}
72+
Tool Result:{" "}
73+
{isError ? (
74+
<span className="text-red-600 font-semibold">Error</span>
75+
) : (
76+
<span className="text-green-600 font-semibold">Success</span>
77+
)}
7378
</h4>
7479
{structuredResult.content.map((item, index) => (
7580
<div key={index} className="mb-2">
76-
{item.type === "text" && <JsonView data={item.text} />}
81+
{item.type === "text" && (
82+
<JsonView data={item.text} isError={isError} />
83+
)}
7784
{item.type === "image" && (
7885
<img
7986
src={`data:${item.mimeType};base64,${item.data}`}

0 commit comments

Comments
 (0)