'use client'; import { FileJson, FileOutput, FolderSearch, Image as ImageIcon, Link2, MessagesSquare } from 'lucide-react'; import type { ProcessArtifact, ProcessEvent, ProcessRun } from '@/types'; import { Badge } from '@/components/ui/badge'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; function statusLabel(status: string) { if (status === 'done') return '已完成'; if (status === 'error') return '失败'; if (status === 'cancelled') return '已取消'; if (status === 'waiting') return '等待中'; if (status === 'running') return '运行中'; if (status === 'queued') return '排队中'; return status; } function actorTypeLabel(actorType: string) { if (actorType === 'mcp') return 'MCP'; if (actorType === 'system') return '系统'; if (actorType === 'agent') return '智能体'; return actorType; } function eventKindLabel(kind: string) { if (kind === 'run_started') return '已启动'; if (kind === 'run_progress') return '进行中'; if (kind === 'run_status') return '状态更新'; if (kind === 'run_artifact') return '产物'; if (kind === 'run_finished') return '已结束'; if (kind === 'run_cancelled') return '已取消'; return kind; } function artifactIcon(type: ProcessArtifact['artifact_type']) { if (type === 'json') return ; if (type === 'image') return ; if (type === 'link') return ; return ; } function renderArtifactBody(artifact: ProcessArtifact) { if (artifact.artifact_type === 'json' && artifact.data !== undefined) { return (
        {JSON.stringify(artifact.data, null, 2)}
      
); } if (artifact.artifact_type === 'link' && artifact.url) { return ( {artifact.url} ); } return (
{artifact.content || '(空产物)'}
); } export function ArtifactSidebar({ selectedRun, events, artifacts, }: { selectedRun: ProcessRun | null; events: ProcessEvent[]; artifacts: ProcessArtifact[]; }) { const runArtifacts = selectedRun ? artifacts.filter((item) => item.run_id === selectedRun.run_id) : artifacts; const runEvents = selectedRun ? events.filter((item) => item.run_id === selectedRun.run_id) : events.slice(-12); const hasContent = Boolean( selectedRun || runArtifacts.length > 0 || runEvents.length > 0 ); if (!hasContent) { return null; } return (

结果面板

{selectedRun ? `当前选中: ${selectedRun.actor_name}` : '选择一个任务查看详细过程与产物'}

任务摘要 {selectedRun ? ( <>
{actorTypeLabel(selectedRun.actor_type)} {statusLabel(selectedRun.status)} {selectedRun.source && {selectedRun.source}}
{selectedRun.title}
{selectedRun.summary || '暂时还没有最终摘要。'}
) : (
当前没有选中的任务。
)}
事件记录 {runEvents.length === 0 && (
暂时还没有结构化事件。
)} {runEvents.map((event, index) => (
{eventKindLabel(event.kind)} {event.status && {statusLabel(event.status)}}
{event.text || '结构化更新'}
{index < runEvents.length - 1 && }
))}
产物列表 {runArtifacts.length === 0 && (
暂时还没有产物。
)} {runArtifacts.map((artifact) => (
{artifactIcon(artifact.artifact_type)}
{artifact.title}
{artifact.actor_id} · {artifact.artifact_type}
{renderArtifactBody(artifact)}
))}
); }