'use client' /** * Agent Run Log * Shows execution history for an agent. */ import { useState, useEffect } from 'react' import { X, CheckCircle2, XCircle, Loader2, Clock, ChevronDown, Wrench } from 'lucide-react' import { formatDistanceToNow } from 'date-fns' import { fr } from 'date-fns/locale/fr' import { enUS } from 'date-fns/locale/en-US' import { useLanguage } from '@/lib/i18n' interface AgentRunLogProps { agentId: string agentName: string onClose: () => void } interface Action { id: string status: string result?: string | null log?: string | null input?: string | null toolLog?: string | null tokensUsed?: number | null createdAt: string | Date } interface ToolLogStep { step: number text?: string toolCalls?: Array<{ toolName: string; args: any }> toolResults?: Array<{ toolName: string; preview?: string }> } const statusKeys: Record = { success: 'agents.status.success', failure: 'agents.status.failure', running: 'agents.status.running', pending: 'agents.status.pending', } export function AgentRunLog({ agentId, agentName, onClose }: AgentRunLogProps) { const { t, language } = useLanguage() const [actions, setActions] = useState([]) const [loading, setLoading] = useState(true) const dateLocale = language === 'fr' ? fr : enUS useEffect(() => { async function load() { try { const { getAgentActions } = await import('@/app/actions/agent-actions') const data = await getAgentActions(agentId) setActions(data) } catch { // Silent fail } finally { setLoading(false) } } load() }, [agentId]) return (
{/* Header */}

{t('agents.runLog.title')}

{agentName}

{/* List */}
{loading && (
)} {!loading && actions.length === 0 && (

{t('agents.runLog.noHistory')}

)} {actions.map(action => { let toolSteps: ToolLogStep[] = [] try { toolSteps = action.toolLog ? JSON.parse(action.toolLog) : [] } catch {} return (
{action.status === 'success' && } {action.status === 'failure' && } {action.status === 'running' && } {action.status === 'pending' && }
{t(statusKeys[action.status] || action.status)} {formatDistanceToNow(new Date(action.createdAt), { addSuffix: true, locale: dateLocale })}
{action.log && (

{action.log}

)}
{/* Tool trace */} {toolSteps.length > 0 && (
{t('agents.runLog.toolTrace', { count: toolSteps.length })}
{toolSteps.map((step, i) => (
{t('agents.runLog.step', { num: step.step })} {step.toolCalls && step.toolCalls.length > 0 && (
{step.toolCalls.map((tc, j) => (
{tc.toolName} {JSON.stringify(tc.args).substring(0, 80)}
))}
)}
))}
)}
) })}
) }