Skip to content

Commit a3be8f6

Browse files
committed
feat: highlight tool errors in red text
1 parent 3032a67 commit a3be8f6

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

client/src/components/JsonView.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface JsonViewProps {
1111
initialExpandDepth?: number;
1212
className?: string;
1313
withCopyButton?: boolean;
14+
isError?: boolean;
1415
}
1516

1617
function tryParseJson(str: string): { success: boolean; data: JsonValue } {
@@ -35,6 +36,7 @@ const JsonView = memo(
3536
initialExpandDepth = 3,
3637
className,
3738
withCopyButton = true,
39+
isError = false
3840
}: JsonViewProps) => {
3941
const { toast } = useToast();
4042
const [copied, setCopied] = useState(false);
@@ -100,6 +102,7 @@ const JsonView = memo(
100102
name={name}
101103
depth={0}
102104
initialExpandDepth={initialExpandDepth}
105+
isError = {isError}
103106
/>
104107
</div>
105108
</div>
@@ -114,10 +117,11 @@ interface JsonNodeProps {
114117
name?: string;
115118
depth: number;
116119
initialExpandDepth: number;
120+
isError?: boolean;
117121
}
118122

119123
const JsonNode = memo(
120-
({ data, name, depth = 0, initialExpandDepth }: JsonNodeProps) => {
124+
({ data, name, depth = 0, initialExpandDepth, isError = false }: JsonNodeProps) => {
121125
const [isExpanded, setIsExpanded] = useState(depth < initialExpandDepth);
122126

123127
const getDataType = (value: JsonValue): string => {
@@ -133,7 +137,8 @@ const JsonNode = memo(
133137
boolean: "text-amber-600",
134138
null: "text-purple-600",
135139
undefined: "text-gray-600",
136-
string: "text-green-600 break-all whitespace-pre-wrap",
140+
string: "text-green-600 group-hover:text-green-500",
141+
error: "text-red-600 group-hover:text-red-500",
137142
default: "text-gray-700",
138143
};
139144

@@ -236,7 +241,7 @@ const JsonNode = memo(
236241
{name}:
237242
</span>
238243
)}
239-
<pre className={typeStyleMap.string}>"{value}"</pre>
244+
<pre className={clsx(typeStyleMap.string, "break-all whitespace-pre-wrap")}>"{value}"</pre>
240245
</div>
241246
);
242247
}
@@ -250,8 +255,8 @@ const JsonNode = memo(
250255
)}
251256
<pre
252257
className={clsx(
253-
typeStyleMap.string,
254-
"cursor-pointer group-hover:text-green-500",
258+
isError ? typeStyleMap.error : typeStyleMap.string,
259+
"cursor-pointer break-all whitespace-pre-wrap",
255260
)}
256261
onClick={() => setIsExpanded(!isExpanded)}
257262
title={isExpanded ? "Click to collapse" : "Click to expand"}

client/src/components/ToolsTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ const ToolsTab = ({
6666
return (
6767
<>
6868
<h4 className="font-semibold mb-2">
69-
Tool Result: {isError ? "Error" : "Success"}
69+
Tool Result: {isError ? <span className="text-red-600 font-semibold">Error</span> : <span className="text-green-600 font-semibold">Success</span>}
7070
</h4>
7171
{structuredResult.content.map((item, index) => (
7272
<div key={index} className="mb-2">
73-
{item.type === "text" && <JsonView data={item.text} />}
73+
{item.type === "text" && <JsonView data={item.text} isError={isError}/>}
7474
{item.type === "image" && (
7575
<img
7676
src={`data:${item.mimeType};base64,${item.data}`}

0 commit comments

Comments
 (0)