import { CodeViewer } from './CodeViewer'
import { memo, useState } from 'react'
import { useTranslation } from '../../i18n'
import { InlineImageGallery } from './InlineImageGallery'
type Props = {
content: unknown
isError: boolean
toolName?: string
standalone?: boolean
}
/**
* Standalone tool result block — only shown when not already rendered
* inline within ToolCallBlock (i.e., when the tool_use and tool_result
* are NOT grouped together by MessageList).
*/
export const ToolResultBlock = memo(function ToolResultBlock({ content, isError, toolName, standalone = true }: Props) {
const [expanded, setExpanded] = useState(false)
const t = useTranslation()
// Don't render standalone if this result is already rendered inline
if (!standalone) return null
const text = extractText(content)
const preview = text.slice(0, 200)
const hasMore = text.length > 200
return (
{/* Status header */}
{/* Inline image gallery from detected paths */}
{/* Content */}
{expanded ? (
isError ? (
{text}
) : (
)
) : (
{preview}
{hasMore ? '…' : ''}
)}
{hasMore && (
)}
)
})
function extractText(content: unknown): string {
if (typeof content === 'string') return content
if (Array.isArray(content)) {
return content
.map((c: any) => (typeof c === 'string' ? c : c?.text || ''))
.filter(Boolean)
.join('\n')
}
if (content && typeof content === 'object') {
return JSON.stringify(content, null, 2)
}
return String(content ?? '')
}