'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'; import { appActorTypeLabel, appEventKindLabel, appStatusLabel } from '@/lib/i18n/common'; import { pickAppText } from '@/lib/i18n/core'; import { useAppI18n } from '@/lib/i18n/provider'; function artifactIcon(type: ProcessArtifact['artifact_type']) { if (type === 'json') return ; if (type === 'image') return ; if (type === 'link') return ; return ; } function renderArtifactBody(artifact: ProcessArtifact, locale: string) { 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 || pickAppText(locale, '(空产物)', '(Empty artifact)')}
); } export function ArtifactSidebar({ selectedRun, events, artifacts, }: { selectedRun: ProcessRun | null; events: ProcessEvent[]; artifacts: ProcessArtifact[]; }) { const { locale } = useAppI18n(); 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 (

{pickAppText(locale, '结果面板', 'Results')}

{selectedRun ? pickAppText(locale, `当前选中: ${selectedRun.actor_name}`, `Selected: ${selectedRun.actor_name}`) : pickAppText(locale, '选择一个任务查看详细过程与产物', 'Select a task to inspect its process and artifacts')}

{pickAppText(locale, '任务摘要', 'Task summary')} {selectedRun ? ( <>
{appActorTypeLabel(selectedRun.actor_type, locale)} {appStatusLabel(selectedRun.status, locale)} {selectedRun.source && {selectedRun.source}}
{selectedRun.title}
{selectedRun.summary || pickAppText(locale, '暂时还没有最终摘要。', 'No final summary yet.')}
) : (
{pickAppText(locale, '当前没有选中的任务。', 'No task is selected right now.')}
)}
{pickAppText(locale, '事件记录', 'Events')} {runEvents.length === 0 && (
{pickAppText(locale, '暂时还没有结构化事件。', 'No structured events yet.')}
)} {runEvents.map((event, index) => (
{appEventKindLabel(event.kind, locale)} {event.status && {appStatusLabel(event.status, locale)}}
{event.text || pickAppText(locale, '结构化更新', 'Structured update')}
{index < runEvents.length - 1 && }
))}
{pickAppText(locale, '产物列表', 'Artifacts')} {runArtifacts.length === 0 && (
{pickAppText(locale, '暂时还没有产物。', 'No artifacts yet.')}
)} {runArtifacts.map((artifact) => (
{artifactIcon(artifact.artifact_type)}
{artifact.title}
{artifact.actor_id} · {artifact.artifact_type}
{renderArtifactBody(artifact, locale)}
))}
); }