import React from 'react'; import { CheckCircle, XCircle, Copy } from 'lucide-react'; import { Button } from '@/components/ui/button'; import type { ToolResult as ToolResultType } from '@dexto/core'; interface ToolResultProps { result: ToolResultType; toolName: string; onCopyResult?: () => void; } export function ToolResult({ result, toolName, onCopyResult }: ToolResultProps) { const renderResultContent = () => { // Check if this is an image result by examining the data structure const isImageResult = result.data && typeof result.data === 'object' && (Array.isArray(result.data) || (typeof result.data === 'object' && Array.isArray((result.data as any).content))); if (isImageResult && result.data) { let imgSrc = ''; let imagePart: { data?: string; mimeType?: string; type?: string } | null = null; let nonImageParts: any[] = []; if (Array.isArray(result.data)) { imagePart = result.data.find((part) => part && part.type === 'image'); if (imagePart && typeof imagePart.data === 'string' && imagePart.mimeType) { imgSrc = `data:${imagePart.mimeType};base64,${imagePart.data}`; } } else if ( result.data && typeof result.data === 'object' && Array.isArray((result.data as any).content) ) { const partsArray = (result.data as any).content as any[]; imagePart = partsArray.find((part) => part && part.type === 'image'); if (imagePart && typeof imagePart.data === 'string' && imagePart.mimeType) { imgSrc = `data:${imagePart.mimeType};base64,${imagePart.data}`; } nonImageParts = partsArray.filter((part) => part && part.type !== 'image'); } else if (typeof result.data === 'string') { if (result.data.startsWith('data:image')) { imgSrc = result.data; } else if ( result.data.startsWith('http://') || result.data.startsWith('https://') ) { imgSrc = result.data; } } if (imgSrc) { return ( Tool result ); } else if (nonImageParts.length > 0) { return (
{nonImageParts.map((part, idx) => (
                                {typeof part === 'object'
                                    ? JSON.stringify(part, null, 2)
                                    : String(part)}
                            
))}
); } } // Default result rendering return (
                {typeof result.data === 'object'
                    ? JSON.stringify(result.data, null, 2)
                    : String(result.data)}
            
); }; return (
{result.success ? ( ) : ( )}

{result.success ? 'Success' : 'Error'}

• {toolName}
{onCopyResult && result.success && ( )}
{result.success ? (
{renderResultContent()}
) : (

Error executing tool:

                        {result.error || 'Unknown error'}
                    
)}
); }