import React, { useEffect, useMemo, useState } from 'react'; import { ChevronDown, ChevronRight, Wrench } from 'lucide-react'; import { Badge, Button } from '@/components/UI'; import { cn } from '@/lib/utils'; import type { DebugTranscriptToolRow } from './types'; const shouldAutoExpand = (status: DebugTranscriptToolRow['status']) => status === 'pending' || status === 'error' || status === 'timeout'; const formatStructuredValue = (value: unknown) => { if (value === undefined || value === null) return ''; if (typeof value === 'string') { const trimmed = value.trim(); if (!trimmed) return ''; try { return JSON.stringify(JSON.parse(trimmed), null, 2); } catch { return value; } } if (typeof value === 'number' || typeof value === 'boolean') { return String(value); } try { return JSON.stringify(value, null, 2); } catch { return String(value); } }; const getStatusBadge = (status: DebugTranscriptToolRow['status']) => { if (status === 'success') { return { label: 'Success', variant: 'success' as const, className: '' }; } if (status === 'pending') { return { label: 'Pending', variant: 'warning' as const, className: '' }; } if (status === 'timeout') { return { label: 'Timeout', variant: 'outline' as const, className: 'border-orange-400/40 bg-orange-500/10 text-orange-200', }; } return { label: 'Error', variant: 'outline' as const, className: 'border-rose-400/40 bg-rose-500/10 text-rose-200', }; }; const Section: React.FC<{ label: string; value: unknown; defaultOpen?: boolean; }> = ({ label, value, defaultOpen = true }) => { const formattedValue = useMemo(() => formatStructuredValue(value), [value]); if (!formattedValue) return null; return (
{label}
        {formattedValue}
      
); }; const MessageTool: React.FC<{ row: DebugTranscriptToolRow; nested?: boolean; }> = ({ row, nested = false }) => { const [isExpanded, setIsExpanded] = useState(() => shouldAutoExpand(row.status)); useEffect(() => { setIsExpanded(shouldAutoExpand(row.status)); }, [row.status]); const statusBadge = getStatusBadge(row.status); return (
{row.toolDisplayName || row.toolName}
{row.toolName}
{statusBadge.label} {row.executor} {row.source && ( {row.source} )}
tool_call_id: {row.toolCallId}
); }; export default React.memo(MessageTool);