import { useState } from 'react' import { Button, Card, Empty, Select, Table, Tag, Timeline, message, } from 'antd' import type { ColumnsType } from 'antd/es/table' import { ArrowLeftOutlined, DownloadOutlined } from '@ant-design/icons' import { intelligentEvalsApi, type DecisionLog } from '../../api' import { colors } from '../../tokens' import { formatDateTime } from '../../utils/date' const DECISION_TYPE_LABELS: Record = { execute_session: { label: '执行会话', color: 'blue' }, wait: { label: '等待', color: 'default' }, start_analysis: { label: '开始分析', color: 'green' }, } interface DecisionProcessProps { evalId: string onBack: () => void } export default function DecisionProcess({ evalId, onBack }: DecisionProcessProps) { const [logs, setLogs] = useState(null) const [loading, setLoading] = useState(false) const [filterType, setFilterType] = useState(null) const [expandedLog, setExpandedLog] = useState(null) const loadLogs = async () => { setLoading(true) try { const res = await intelligentEvalsApi.listDecisionLogs(evalId) setLogs(res.data.logs) } catch { message.error('加载决策日志失败') } finally { setLoading(false) } } useState(() => { void loadLogs() }) const handleExport = () => { if (!logs) return const data = JSON.stringify(logs, null, 2) const blob = new Blob([data], { type: 'application/json' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = `decision-logs-${evalId.slice(0, 8)}.json` a.click() URL.revokeObjectURL(url) message.success('已导出决策日志') } const filteredLogs = filterType ? logs?.filter((log) => log.decision_type === filterType) ?? [] : logs ?? [] const columns: ColumnsType = [ { title: '时间', dataIndex: 'created_at', key: 'created_at', width: 180, render: (val: string | null) => formatDateTime(val), }, { title: '决策类型', dataIndex: 'decision_type', key: 'decision_type', width: 120, render: (val: string) => { const info = DECISION_TYPE_LABELS[val] ?? { label: val, color: 'default' } return {info.label} }, }, { title: '原因', dataIndex: 'reason', key: 'reason', ellipsis: true, }, { title: 'Cron ID', dataIndex: 'cron_id', key: 'cron_id', width: 120, render: (val: string) => {val.slice(0, 8)}, }, { title: '操作', key: 'actions', width: 80, render: (_, record) => ( ), }, ] return (
决策过程