fix(ai-chat): optimize result rendering in ToolInvocationComponent

This commit is contained in:
DIYgod 2025-10-29 12:29:38 +08:00
parent 187b23c271
commit eab29b54a0
No known key found for this signature in database
1 changed files with 12 additions and 1 deletions

View File

@ -25,6 +25,17 @@ export const ToolInvocationComponent: React.FC<ToolInvocationComponentProps> = R
// Generate a unique value for this accordion item
const accordionValue = `tool-${"toolCallId" in part ? part.toolCallId : Math.random()}`
const result = React.useMemo(() => {
if (hasResult) {
const string = JSON.stringify(part.output, null, 2)
if (string.length > 1000) {
return `${string.slice(0, 1000)}\n...`
} else {
return string
}
}
}, [hasResult, part])
return (
<div className={clsx("relative pl-8 last:pb-0", variant === "tight" ? "pb-0" : "pb-3")}>
<div
@ -74,7 +85,7 @@ export const ToolInvocationComponent: React.FC<ToolInvocationComponentProps> = R
<div className="mb-1 font-medium text-text-secondary">Result:</div>
<JsonHighlighter
className="overflow-x-auto rounded bg-fill-secondary p-2 text-[11px] text-text-tertiary"
json={JSON.stringify(part.output, null, 2)}
json={result!}
/>
</div>
) : null}