Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(eval): give a test case its own page, addressable without a run (#18809)

Arvin Xu4339bf5c526e
diff --git a/apps/server/src/routers/lambda/agentEval.ts b/apps/server/src/routers/lambda/agentEval.ts
index 6ed0aef129c..1bcd62c4c03 100644
--- a/apps/server/src/routers/lambda/agentEval.ts
+++ b/apps/server/src/routers/lambda/agentEval.ts
@@ -349,7 +349,9 @@ export const agentEvalRouter = router({
createDataset: agentEvalProcedureWrite
.input(
z.object({
- benchmarkId: z.string(),
+ // Optional: a dataset accumulated from captured cases belongs to no
+ // published benchmark.
+ benchmarkId: z.string().optional(),
identifier: z.string(),
name: z.string(),
description: z.string().optional(),
diff --git a/locales/en-US/eval.json b/locales/en-US/eval.json
index 71d78bccc73..cf598330d9c 100644
--- a/locales/en-US/eval.json
+++ b/locales/en-US/eval.json
@@ -90,6 +90,7 @@
"common.edit": "Edit",
"common.later": "Later",
"common.next": "Next",
+ "common.save": "Save",
"common.unknown": "Unknown",
"common.update": "Update",
"dataset.actions.addDataset": "Add Dataset",
@@ -131,8 +132,10 @@
"dataset.delete.success": "Dataset deleted successfully",
"dataset.detail.addRun": "New Run",
"dataset.detail.backToBenchmark": "Back to Benchmark",
+ "dataset.detail.backToEval": "Back to Eval",
"dataset.detail.caseCount": "{{count}} test case{{count, plural, one {} other {s}}}",
"dataset.detail.relatedRuns": "Related Runs ({{count}})",
+ "dataset.detail.runsNeedBenchmark": "An evaluation run belongs to a benchmark. Attach this dataset to one to run it.",
"dataset.detail.testCases": "Test Cases",
"dataset.detail.viewDetail": "View Details",
"dataset.edit.error": "Failed to update dataset",
@@ -248,6 +251,9 @@
"overview.sections.benchmarks.subtitle": "Shared evaluation assets and benchmark baselines.",
"overview.sections.benchmarks.title": "Benchmarks",
"overview.sections.count": "{{count}} total",
+ "overview.sections.datasets.empty": "No datasets yet",
+ "overview.sections.datasets.noBenchmark": "Not part of a benchmark",
+ "overview.sections.datasets.title": "Datasets",
"overview.sections.experiments.subtitle": "Optimization workspaces for scoped datasets, baselines, and forked iterations.",
"overview.sections.experiments.title": "Experiments",
"overview.sections.experiments.viewAll": "View all experiments",
@@ -370,6 +376,7 @@
"sidebar.benchmarks": "Benchmarks",
"sidebar.dashboard": "Dashboard",
"sidebar.datasets": "Datasets",
+ "sidebar.datasetsEmpty": "No datasets yet",
"sidebar.experiments": "Experiments",
"sidebar.runs": "Runs",
"table.columns.avgCost": "Avg Cost",
@@ -418,5 +425,28 @@
"testCase.preview.expected": "Expected",
"testCase.preview.input": "Input",
"testCase.preview.title": "Test Case Preview",
- "testCase.search.placeholder": "Search cases..."
+ "testCase.search.placeholder": "Search cases...",
+ "testCaseDetail.backToDataset": "Back to Dataset",
+ "testCaseDetail.boundary": "The case starts here",
+ "testCaseDetail.breadcrumb.dataset": "Dataset",
+ "testCaseDetail.breadcrumb.eval": "Eval",
+ "testCaseDetail.capturedOutput": "Captured answer",
+ "testCaseDetail.capturedOutputHint": "The answer this case was captured from — kept as a counter-example for the judge, not as the expected output.",
+ "testCaseDetail.context_one": "Prior context · {{count}} turn",
+ "testCaseDetail.context_other": "Prior context · {{count}} turns",
+ "testCaseDetail.counterExample": "counter-example",
+ "testCaseDetail.criteria": "Criteria",
+ "testCaseDetail.criteria.empty": "No criteria set — this case is scored by its expected output alone.",
+ "testCaseDetail.definition": "Case definition",
+ "testCaseDetail.expected": "Expected output",
+ "testCaseDetail.expected.empty": "Not set — scored by the criteria alone.",
+ "testCaseDetail.expected.placeholder": "Leave empty when there is no single right answer.",
+ "testCaseDetail.notFound": "This test case no longer exists.",
+ "testCaseDetail.open": "Open case",
+ "testCaseDetail.role.assistant": "Assistant",
+ "testCaseDetail.role.system": "System",
+ "testCaseDetail.role.tool": "Tool",
+ "testCaseDetail.role.user": "User",
+ "testCaseDetail.saveFailed": "Could not save this case.",
+ "testCaseDetail.title": "Test case"
}
diff --git a/locales/zh-CN/eval.json b/locales/zh-CN/eval.json
index 2f51bd49ab5..6fc684daa37 100644
--- a/locales/zh-CN/eval.json
+++ b/locales/zh-CN/eval.json
@@ -90,6 +90,7 @@
"common.edit": "编辑",
"common.later": "稍后",
"common.next": "下一步",
+ "common.save": "保存",
"common.unknown": "未知",
"common.update": "更新",
"dataset.actions.addDataset": "添加数据集",
@@ -131,8 +132,10 @@
"dataset.delete.success": "数据集删除成功",
"dataset.detail.addRun": "新增运行",
"dataset.detail.backToBenchmark": "返回基准测试",
+ "dataset.detail.backToEval": "返回评测",
"dataset.detail.caseCount": "{{count}} 个测试用例",
"dataset.detail.relatedRuns": "相关运行({{count}})",
+ "dataset.detail.runsNeedBenchmark": "评测运行归属于某个基准测试。把该数据集挂到一个基准测试下才能发起运行。",
"dataset.detail.testCases": "测试用例",
"dataset.detail.viewDetail": "查看详情",
"dataset.edit.error": "更新数据集失败",
@@ -248,6 +251,9 @@
"overview.sections.benchmarks.subtitle": "共享评估资源和基准基线。",
"overview.sections.benchmarks.title": "基准",
"overview.sections.count": "共计 {{count}}",
+ "overview.sections.datasets.empty": "还没有数据集",
+ "overview.sections.datasets.noBenchmark": "未归入基准测试",
+ "overview.sections.datasets.title": "数据集",
"overview.sections.experiments.subtitle": "跟踪优化上下文与运行迭代。",
"overview.sections.experiments.title": "实验",
"overview.sections.experiments.viewAll": "查看全部实验",
@@ -370,6 +376,7 @@
"sidebar.benchmarks": "基准",
"sidebar.dashboard": "总览",
"sidebar.datasets": "数据集",
+ "sidebar.datasetsEmpty": "还没有数据集",
"sidebar.experiments": "实验",
"sidebar.runs": "评测",
"table.columns.avgCost": "平均成本",
@@ -418,5 +425,28 @@
"testCase.preview.expected": "期望",
"testCase.preview.input": "输入",
"testCase.preview.title": "数据用例预览",
- "testCase.search.placeholder": "搜索用例..."
+ "testCase.search.placeholder": "搜索用例...",
+ "testCaseDetail.backToDataset": "返回数据集",
+ "testCaseDetail.boundary": "用例从这里开始",
+ "testCaseDetail.breadcrumb.dataset": "数据集",
+ "testCaseDetail.breadcrumb.eval": "评测",
+ "testCaseDetail.capturedOutput": "捕获时的回答",
+ "testCaseDetail.capturedOutputHint": "该用例捕获自这条回答 —— 存为反例供判官参照,不是期望输出。",
+ "testCaseDetail.context_one": "前置上下文 · {{count}} 轮",
+ "testCaseDetail.context_other": "前置上下文 · {{count}} 轮",
+ "testCaseDetail.counterExample": "反例",
+ "testCaseDetail.criteria": "判定标准",
+ "testCaseDetail.criteria.empty": "未设置判定标准 —— 该用例仅按期望输出打分。",
+ "testCaseDetail.definition": "用例定义",
+ "testCaseDetail.expected": "期望输出",
+ "testCaseDetail.expected.empty": "未填写 —— 仅按判定标准打分。",
+ "testCaseDetail.expected.placeholder": "没有唯一正确答案时留空。",
+ "testCaseDetail.notFound": "该测试用例已不存在。",
+ "testCaseDetail.open": "打开用例",
+ "testCaseDetail.role.assistant": "助手",
+ "testCaseDetail.role.system": "系统",
+ "testCaseDetail.role.tool": "工具",
+ "testCaseDetail.role.user": "用户",
+ "testCaseDetail.saveFailed": "保存失败。",
+ "testCaseDetail.title": "测试用例"
}
diff --git a/packages/locales/src/default/eval.ts b/packages/locales/src/default/eval.ts
index 217f56ba999..87f37f322b2 100644
--- a/packages/locales/src/default/eval.ts
+++ b/packages/locales/src/default/eval.ts
@@ -76,6 +76,7 @@ export default {
'common.edit': 'Edit',
'common.later': 'Later',
'common.next': 'Next',
+ 'common.save': 'Save',
'common.unknown': 'Unknown',
'common.update': 'Update',
@@ -182,10 +183,13 @@ export default {
'dataset.import.upload.hint': 'Supports CSV, XLSX, JSON, JSONL',
'dataset.import.upload.text': 'Click or drag file here to upload',
'dataset.import.uploading': 'Uploading...',
+ 'dataset.detail.backToEval': 'Back to Eval',
'dataset.detail.backToBenchmark': 'Back to Benchmark',
'dataset.detail.caseCount': '{{count}} test case{{count, plural, one {} other {s}}}',
'dataset.detail.addRun': 'New Run',
'dataset.detail.relatedRuns': 'Related Runs ({{count}})',
+ 'dataset.detail.runsNeedBenchmark':
+ 'An evaluation run belongs to a benchmark. Attach this dataset to one to run it.',
'dataset.detail.testCases': 'Test Cases',
'dataset.detail.viewDetail': 'View Details',
'dataset.switchDataset': 'Switch Dataset',
@@ -264,6 +268,9 @@ export default {
'overview.createExperiment': 'Create Experiment',
'overview.importDataset': 'Import Dataset',
'overview.sections.benchmarks.subtitle': 'Shared evaluation assets and benchmark baselines.',
+ 'overview.sections.datasets.empty': 'No datasets yet',
+ 'overview.sections.datasets.noBenchmark': 'Not part of a benchmark',
+ 'overview.sections.datasets.title': 'Datasets',
'overview.sections.benchmarks.title': 'Benchmarks',
'overview.sections.count': '{{count}} total',
'overview.sections.experiments.subtitle':
@@ -385,6 +392,7 @@ export default {
'sidebar.benchmarks': 'Benchmarks',
'sidebar.dashboard': 'Dashboard',
'sidebar.datasets': 'Datasets',
+ 'sidebar.datasetsEmpty': 'No datasets yet',
'sidebar.experiments': 'Experiments',
'sidebar.runs': 'Runs',
@@ -450,4 +458,29 @@ export default {
'testCase.preview.input': 'Input',
'testCase.preview.title': 'Test Case Preview',
'testCase.search.placeholder': 'Search cases...',
+ 'testCaseDetail.backToDataset': 'Back to Dataset',
+ 'testCaseDetail.boundary': 'The case starts here',
+ 'testCaseDetail.breadcrumb.dataset': 'Dataset',
+ 'testCaseDetail.breadcrumb.eval': 'Eval',
+ 'testCaseDetail.capturedOutput': 'Captured answer',
+ 'testCaseDetail.capturedOutputHint':
+ 'The answer this case was captured from \u2014 kept as a counter-example for the judge, not as the expected output.',
+ 'testCaseDetail.context_one': 'Prior context · {{count}} turn',
+ 'testCaseDetail.context_other': 'Prior context · {{count}} turns',
+ 'testCaseDetail.counterExample': 'counter-example',
+ 'testCaseDetail.criteria': 'Criteria',
+ 'testCaseDetail.criteria.empty':
+ 'No criteria set \u2014 this case is scored by its expected output alone.',
+ 'testCaseDetail.definition': 'Case definition',
+ 'testCaseDetail.expected': 'Expected output',
+ 'testCaseDetail.expected.empty': 'Not set \u2014 scored by the criteria alone.',
+ 'testCaseDetail.expected.placeholder': 'Leave empty when there is no single right answer.',
+ 'testCaseDetail.open': 'Open case',
+ 'testCaseDetail.notFound': 'This test case no longer exists.',
+ 'testCaseDetail.saveFailed': 'Could not save this case.',
+ 'testCaseDetail.role.assistant': 'Assistant',
+ 'testCaseDetail.role.system': 'System',
+ 'testCaseDetail.role.tool': 'Tool',
+ 'testCaseDetail.role.user': 'User',
+ 'testCaseDetail.title': 'Test case',
};
diff --git a/src/libs/swr/keys.ts b/src/libs/swr/keys.ts
index 15c2b317964..64008e4066c 100644
--- a/src/libs/swr/keys.ts
+++ b/src/libs/swr/keys.ts
@@ -727,12 +727,14 @@ export const evalKeys = {
benchmarks: def('eval:benchmarks', () => ['eval:benchmarks']),
datasetDetail: def('eval:datasetDetail', (id: string) => ['eval:datasetDetail', id]),
datasetRuns: def('eval:datasetRuns', (datasetId: string) => ['eval:datasetRuns', datasetId]),
+ datasetsAll: def('eval:datasetsAll', () => ['eval:datasetsAll']),
datasets: def('eval:datasets', (benchmarkId: string) => ['eval:datasets', benchmarkId]),
experimentDetail: def('eval:experimentDetail', (id: string) => ['eval:experimentDetail', id]),
experiments: def('eval:experiments', () => ['eval:experiments']),
runDetail: def('eval:runDetail', (id: string) => ['eval:runDetail', id]),
runResults: def('eval:runResults', (id: string) => ['eval:runResults', id]),
runs: def('eval:runs', (benchmarkId?: string) => ['eval:runs', benchmarkId]),
+ testCaseDetail: def('eval:testCaseDetail', (id: string) => ['eval:testCaseDetail', id]),
testCases: def('eval:testCases', (datasetId: string, limit?: number, offset?: number) => [
'eval:testCases',
datasetId,
diff --git a/src/routes/(main)/eval/_layout/Sidebar/Body/DatasetList.tsx b/src/routes/(main)/eval/_layout/Sidebar/Body/DatasetList.tsx
new file mode 100644
index 00000000000..0c62f707a31
--- /dev/null
+++ b/src/routes/(main)/eval/_layout/Sidebar/Body/DatasetList.tsx
@@ -0,0 +1,83 @@
+'use client';
+
+import { AccordionItem, Flexbox } from '@lobehub/ui';
+import { Text } from '@lobehub/ui/base-ui';
+import { Database } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import NavItem from '@/features/NavPanel/components/NavItem';
+import SkeletonList from '@/features/NavPanel/components/SkeletonList';
+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
+import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
+import { useEvalStore } from '@/store/eval';
+import { isModifierClick } from '@/utils/navigation';
+
+interface DatasetListProps {
+ activeKey: string;
+ itemKey: string;
+}
+
+/**
+ * Every dataset, not only the ones under a benchmark. A dataset need not belong
+ * to one, and every other listing in the product is benchmark-scoped — without
+ * this a captured dataset could be created but never found.
+ */
+const DatasetList = memo<DatasetListProps>(({ activeKey, itemKey }) => {
+ const { t } = useTranslation('eval');
+ const navigate = useWorkspaceAwareNavigate();
+ const useFetchAllDatasets = useEvalStore((s) => s.useFetchAllDatasets);
+ const { data, isLoading } = useFetchAllDatasets();
+ const datasets: Array<{ id: string; name: string }> = data ?? [];
+
+ return (
+ <AccordionItem
+ itemKey={itemKey}
+ paddingBlock={4}
+ paddingInline={'8px 4px'}
+ title={
+ <Flexbox horizontal align="center" gap={4}>
+ <Text ellipsis fontSize={12} type={'secondary'} weight={500}>
+ {t('sidebar.datasets')}
+ </Text>
+ {datasets.length > 0 && (
+ <Text fontSize={12} type="secondary">
+ {datasets.length}
+ </Text>
+ )}
+ </Flexbox>
+ }
+ >
+ <Flexbox gap={1} paddingBlock={1}>
+ {isLoading ? (
+ <SkeletonList rows={2} />
+ ) : datasets.length > 0 ? (
+ datasets.map((d) => (
+ <WorkspaceLink
+ key={d.id}
+ to={`/eval/datasets/${d.id}`}
+ onClick={(e) => {
+ if (isModifierClick(e)) return;
+ e.preventDefault();
+ navigate(`/eval/datasets/${d.id}`);
+ }}
+ >
+ <NavItem
+ active={activeKey === `dataset-${d.id}`}
+ icon={Database}
+ iconSize={16}
+ title={d.name}
+ />
+ </WorkspaceLink>
+ ))
+ ) : (
+ <Text fontSize={12} style={{ padding: '8px 12px' }} type="secondary">
+ {t('sidebar.datasetsEmpty')}
+ </Text>
+ )}
+ </Flexbox>
+ </AccordionItem>
+ );
+});
+
+export default DatasetList;
diff --git a/src/routes/(main)/eval/_layout/Sidebar/Body/index.tsx b/src/routes/(main)/eval/_layout/Sidebar/Body/index.tsx
index fcaa06fc654..021e7fb8921 100644
--- a/src/routes/(main)/eval/_layout/Sidebar/Body/index.tsx
+++ b/src/routes/(main)/eval/_layout/Sidebar/Body/index.tsx
@@ -12,6 +12,7 @@ import { useActiveLocation } from '@/hooks/useActiveLocation';
import { useEvalStore } from '@/store/eval';
import BenchmarkList from './BenchmarkList';
+import DatasetList from './DatasetList';
import ExperimentList from './ExperimentList';
const useActiveKey = () => {
@@ -24,6 +25,9 @@ const useActiveKey = () => {
const experimentMatch = pathname.match(/\/eval\/experiments\/([^/]+)/);
if (experimentMatch) return `experiment-${experimentMatch[1]}`;
+ const datasetMatch = pathname.match(/\/eval\/datasets\/([^/]+)/);
+ if (datasetMatch) return `dataset-${datasetMatch[1]}`;
+
return 'dashboard';
};
@@ -53,9 +57,10 @@ const Body = memo(() => {
/>
</WorkspaceLink>
</Flexbox>
- <Accordion defaultExpandedKeys={['benchmarks', 'experiments']} gap={8}>
+ <Accordion defaultExpandedKeys={['benchmarks', 'datasets', 'experiments']} gap={8}>
<ExperimentList activeKey={activeKey} itemKey="experiments" />
<BenchmarkList activeKey={activeKey} itemKey="benchmarks" />
+ <DatasetList activeKey={activeKey} itemKey="datasets" />
</Accordion>
</Flexbox>
);
diff --git a/src/routes/(main)/eval/bench/[benchmarkId]/datasets/[datasetId]/index.tsx b/src/routes/(main)/eval/bench/[benchmarkId]/datasets/[datasetId]/index.tsx
index 9e33c9abaa4..2d700900168 100644
--- a/src/routes/(main)/eval/bench/[benchmarkId]/datasets/[datasetId]/index.tsx
+++ b/src/routes/(main)/eval/bench/[benchmarkId]/datasets/[datasetId]/index.tsx
@@ -1,383 +1,18 @@
'use client';
-import { Flexbox } from '@lobehub/ui';
-import { Button, confirmModal, Text, toast } from '@lobehub/ui/base-ui';
-import { createStaticStyles, cssVar } from 'antd-style';
-import { ArrowLeft, Database, Pencil, Plus, Trash2 } from 'lucide-react';
-import { memo, useCallback, useMemo, useState } from 'react';
-import { useTranslation } from 'react-i18next';
-import { useParams } from 'react-router';
+import { memo } from 'react';
+import { Navigate, useParams } from 'react-router';
-import AsyncBoundary from '@/components/AsyncBoundary';
-import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
-import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
-import { agentEvalService } from '@/services/agentEval';
-import { runSelectors, useEvalStore } from '@/store/eval';
+/**
+ * Legacy address. A dataset no longer has to belong to a benchmark, so its
+ * canonical path cannot carry one; this keeps existing links resolving.
+ */
+const LegacyDatasetRedirect = memo(() => {
+ const { datasetId } = useParams<{ datasetId: string }>();
-import { createDatasetEditModal } from '../../../../features/DatasetEditModal';
-import { createDatasetImportModal } from '../../../../features/DatasetImportModal';
-import SegmentBar from '../../../../features/SegmentBar';
-import { createTestCaseCreateModal } from '../../../../features/TestCaseCreateModal';
-import { createTestCaseEditModal } from '../../../../features/TestCaseEditModal';
-import TestCasePreviewPanel from '../../features/DatasetsTab/TestCasePreviewPanel';
-import TestCaseTable from '../../features/DatasetsTab/TestCaseTable';
-import { createRunCreateModal } from '../../features/RunCreateModal';
-import EmptyState from '../../features/RunsTab/EmptyState';
-import RunCard from '../../features/RunsTab/RunCard';
-
-const styles = createStaticStyles(({ css }) => ({
- backLink: css`
- display: inline-flex;
- gap: 4px;
- align-items: center;
-
- width: fit-content;
-
- font-size: ${cssVar.fontSize};
- color: ${cssVar.colorTextTertiary};
- text-decoration: none;
-
- transition: color 0.15s ease;
-
- &:hover {
- color: ${cssVar.colorText};
- }
-
- &:focus-visible {
- outline: 2px solid ${cssVar.colorPrimary};
- outline-offset: 2px;
- }
-
- @media (prefers-reduced-motion: reduce) {
- transition: none;
- }
- `,
- header: css`
- display: flex;
- flex-shrink: 0;
- align-items: center;
- justify-content: center;
-
- width: 40px;
- height: 40px;
- border-radius: ${cssVar.borderRadiusLG};
-
- background: ${cssVar.colorPrimaryBg};
- `,
- // Summary hero — leads the dataset detail with its headline case count as a
- // large mono figure, mirroring the benchmark/run result heroes.
- heroBand: css`
- padding: 20px;
- border-radius: ${cssVar.borderRadiusLG};
- background: ${cssVar.colorFillQuaternary};
- `,
- heroValue: css`
- font-family: ${cssVar.fontFamilyCode};
- font-size: ${cssVar.fontSizeHeading2};
- font-weight: 600;
- line-height: 1;
- color: ${cssVar.colorText};
- `,
- summaryDot: css`
- width: 8px;
- height: 8px;
- border-radius: 999px;
- `,
- tableWrapper: css`
- overflow: hidden;
- border: 1px solid ${cssVar.colorBorderSecondary};
- border-radius: ${cssVar.borderRadius};
- `,
-}));
-
-const DatasetDetail = memo(() => {
- const { t } = useTranslation('eval');
- const { benchmarkId, datasetId } = useParams<{ benchmarkId: string; datasetId: string }>();
- const navigate = useWorkspaceAwareNavigate();
-
- const [pagination, setPagination] = useState({ current: 1, pageSize: 10 });
- const [search, setSearch] = useState('');
- const [diffFilter, setDiffFilter] = useState<'all' | 'easy' | 'medium' | 'hard'>('all');
- const [previewCase, setPreviewCase] = useState<any | null>(null);
-
- const useFetchDatasetDetail = useEvalStore((s) => s.useFetchDatasetDetail);
- const useFetchTestCases = useEvalStore((s) => s.useFetchTestCases);
- const useFetchDatasetRuns = useEvalStore((s) => s.useFetchDatasetRuns);
- const runList = useEvalStore(runSelectors.datasetRunList(datasetId!));
- const refreshTestCases = useEvalStore((s) => s.refreshTestCases);
- const refreshDatasetDetail = useEvalStore((s) => s.refreshDatasetDetail);
-
- const { data: dataset, error, isLoading, mutate } = useFetchDatasetDetail(datasetId);
- useFetchDatasetRuns(datasetId);
-
- const sortedRuns = useMemo(
- () =>
- [...runList].sort(
- (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
- ),
- [runList],
- );
-
- const { data: testCaseData } = useFetchTestCases({
- datasetId: datasetId!,
- limit: pagination.pageSize,
- offset: (pagination.current - 1) * pagination.pageSize,
- });
-
- const testCases = testCaseData?.data || [];
- const total = testCaseData?.total || 0;
-
- const filteredCases = testCases.filter((c: any) => {
- if (diffFilter !== 'all' && c.metadata?.difficulty !== diffFilter) return false;
- if (search && !c.content?.input?.toLowerCase().includes(search.toLowerCase())) return false;
- return true;
- });
-
- // Difficulty mix across the loaded cases — feeds the summary hero's bar.
- const difficulty = useMemo(() => {
- const counts = { easy: 0, hard: 0, medium: 0 };
- for (const c of testCases as any[]) {
- const d = c?.metadata?.difficulty as 'easy' | 'hard' | 'medium' | undefined;
- if (d === 'easy' || d === 'medium' || d === 'hard') counts[d] += 1;
- }
- return {
- counts,
- segments: [
- { color: cssVar.colorSuccess, value: counts.easy },
- { color: cssVar.colorWarning, value: counts.medium },
- { color: cssVar.colorError, value: counts.hard },
- ],
- tagged: counts.easy + counts.medium + counts.hard,
- };
- }, [testCases]);
-
- const handleRefresh = useCallback(async () => {
- if (datasetId) {
- await refreshTestCases(datasetId);
- await refreshDatasetDetail(datasetId);
- }
- }, [datasetId, refreshTestCases, refreshDatasetDetail]);
-
- const handleDeleteCase = useCallback(
- (testCase: any) => {
- confirmModal({
- content: t('testCase.delete.confirm'),
- okButtonProps: { danger: true },
- okText: t('common.delete'),
- onOk: async () => {
- try {
- await agentEvalService.deleteTestCase(testCase.id);
- toast.success(t('testCase.delete.success'));
- await handleRefresh();
- } catch {
- toast.error(t('testCase.delete.error'));
- }
- },
- title: t('common.delete'),
- });
- },
- [handleRefresh, t],
- );
-
- const handleDelete = useCallback(() => {
- confirmModal({
- content: t('dataset.delete.confirm'),
- okButtonProps: { danger: true },
- okText: t('common.delete'),
- onOk: async () => {
- try {
- await agentEvalService.deleteDataset(datasetId!);
- toast.success(t('dataset.delete.success'));
- navigate(`/eval/bench/${benchmarkId}`);
- } catch {
- toast.error(t('dataset.delete.error'));
- }
- },
- title: t('common.delete'),
- });
- }, [benchmarkId, datasetId, navigate, t]);
-
- // Skeleton → error → (resolved-null) blank, replacing a bare `return null`
- // that flashed blank on the happy path and stayed permanently blank on a
- // failed fetch (ux Read §1.1). A page-level failure gets a reason + Reload.
- return (
- <AsyncBoundary
- data={dataset}
- error={error}
- errorVariant={'page'}
- isEmpty={!dataset}
- isLoading={isLoading}
- onRetry={() => mutate()}
- >
- {dataset && (
- <Flexbox horizontal style={{ flex: 1, minHeight: 0 }}>
- <Flexbox
- flex={1}
- gap={24}
- style={{ minWidth: 0, overflow: 'auto', paddingBlock: 24, paddingInline: 32 }}
- >
- {/* Back link */}
- <WorkspaceLink className={styles.backLink} to={`/eval/bench/${benchmarkId}`}>
- <ArrowLeft size={16} />
- {t('dataset.detail.backToBenchmark')}
- </WorkspaceLink>
-
- {/* Header */}
- <Flexbox horizontal align="start" justify="space-between">
- <Flexbox horizontal align="start" gap={12}>
- <div className={styles.header}>
- <Database size={20} style={{ color: cssVar.colorPrimary }} />
- </div>
- <Flexbox gap={4}>
- <Text as="h4" style={{ fontSize: 20, fontWeight: 600, margin: 0 }}>
- {dataset.name}
- </Text>
- {dataset.description && <Text type="secondary">{dataset.description}</Text>}
- </Flexbox>
- </Flexbox>
-
- <Flexbox horizontal gap={8}>
- <Button
- icon={Pencil}
- size="small"
- onClick={() => createDatasetEditModal({ dataset, onSuccess: handleRefresh })}
- >
- {t('common.edit')}
- </Button>
- <Button danger icon={Trash2} size="small" onClick={handleDelete}>
- {t('common.delete')}
- </Button>
- </Flexbox>
- </Flexbox>
-
- {/* Summary hero — headline case count + difficulty mix */}
- <Flexbox
- horizontal
- align="center"
- className={styles.heroBand}
- gap={16}
- justify="space-between"
- >
- <Flexbox gap={6}>
- <span className={styles.heroValue}>{total}</span>
- <Text color={cssVar.colorTextTertiary} fontSize={12}>
- {t('dataset.detail.testCases')}
- </Text>
- </Flexbox>
- {difficulty.tagged > 0 && (
- <Flexbox gap={8} style={{ maxWidth: 280, minWidth: 0, width: '100%' }}>
- <SegmentBar segments={difficulty.segments} />
- <Flexbox horizontal gap={12} justify="flex-end" style={{ flexWrap: 'wrap' }}>
- {(['easy', 'medium', 'hard'] as const).map((d) => (
- <Flexbox horizontal align="center" gap={6} key={d}>
- <span
- className={styles.summaryDot}
- style={{
- background:
- d === 'easy'
- ? cssVar.colorSuccess
- : d === 'medium'
- ? cssVar.colorWarning
- : cssVar.colorError,
- }}
- />
- <Text color={cssVar.colorTextTertiary} fontSize={12}>
- {t(`difficulty.${d}`)} {difficulty.counts[d]}
- </Text>
- </Flexbox>
- ))}
- </Flexbox>
- </Flexbox>
- )}
- </Flexbox>
-
- {/* Test Cases */}
- <Flexbox gap={12}>
- <Flexbox horizontal align="center" justify="space-between">
- <Text weight={600}>{t('dataset.detail.testCases')}</Text>
- <Text type="secondary">{t('dataset.detail.caseCount', { count: total })}</Text>
- </Flexbox>
-
- <div className={styles.tableWrapper}>
- <TestCaseTable
- datasetEvalMode={dataset?.evalMode}
- diffFilter={diffFilter}
- pagination={pagination}
- search={search}
- selectedId={previewCase?.id}
- testCases={filteredCases}
- total={total}
- onDelete={handleDeleteCase}
- onPageChange={(page, pageSize) => setPagination({ current: page, pageSize })}
- onPreview={setPreviewCase}
- onAddCase={() =>
- createTestCaseCreateModal({ datasetId: datasetId!, onSuccess: handleRefresh })
- }
- onDiffFilterChange={(f) => {
- setDiffFilter(f);
- setPagination((prev) => ({ ...prev, current: 1 }));
- }}
- onEdit={(testCase) =>
- createTestCaseEditModal({ onSuccess: handleRefresh, testCase })
- }
- onImport={() =>
- createDatasetImportModal({ datasetId: datasetId!, onSuccess: handleRefresh })
- }
- onSearchChange={(v) => {
- setSearch(v);
- setPagination((prev) => ({ ...prev, current: 1 }));
- }}
- />
- </div>
- </Flexbox>
-
- {/* Related Runs */}
- <Flexbox gap={12}>
- <Flexbox horizontal align="center" justify="space-between">
- <Text weight={600}>
- {t('dataset.detail.relatedRuns', { count: sortedRuns.length })}
- </Text>
- <Button
- icon={Plus}
- size="small"
- onClick={() =>
- createRunCreateModal({
- benchmarkId: benchmarkId!,
- datasetId: datasetId!,
- datasetName: dataset.name,
- })
- }
- >
- {t('dataset.detail.addRun')}
- </Button>
- </Flexbox>
- {sortedRuns.length > 0 ? (
- <Flexbox gap={12}>
- {sortedRuns.map((run) => (
- <RunCard benchmarkId={benchmarkId!} key={run.id} run={run} />
- ))}
- </Flexbox>
- ) : (
- <EmptyState
- onCreate={() =>
- createRunCreateModal({
- benchmarkId: benchmarkId!,
- datasetId: datasetId!,
- datasetName: dataset.name,
- })
- }
- />
- )}
- </Flexbox>
- </Flexbox>
-
- {previewCase && (
- <TestCasePreviewPanel testCase={previewCase} onClose={() => setPreviewCase(null)} />
- )}
- </Flexbox>
- )}
- </AsyncBoundary>
- );
+ return <Navigate replace to={`/eval/datasets/${datasetId}`} />;
});
-export default DatasetDetail;
+LegacyDatasetRedirect.displayName = 'EvalLegacyDatasetRedirect';
+
+export default LegacyDatasetRedirect;
diff --git a/src/routes/(main)/eval/bench/[benchmarkId]/features/DatasetsTab/TestCaseTable.tsx b/src/routes/(main)/eval/bench/[benchmarkId]/features/DatasetsTab/TestCaseTable.tsx
index 15997113a88..fabc661be38 100644
--- a/src/routes/(main)/eval/bench/[benchmarkId]/features/DatasetsTab/TestCaseTable.tsx
+++ b/src/routes/(main)/eval/bench/[benchmarkId]/features/DatasetsTab/TestCaseTable.tsx
@@ -3,7 +3,7 @@ import { ActionIcon, Button, Text } from '@lobehub/ui/base-ui';
import { Pagination, Table } from 'antd';
import { type ColumnsType } from 'antd/es/table';
import { createStaticStyles, cssVar } from 'antd-style';
-import { Ellipsis, FileUp, Pencil, Plus, Search, Trash2 } from 'lucide-react';
+import { Ellipsis, ExternalLink, FileUp, Pencil, Plus, Search, Trash2 } from 'lucide-react';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
@@ -127,6 +127,8 @@ interface TestCaseTableProps {
onDiffFilterChange: (filter: 'all' | 'easy' | 'medium' | 'hard') => void;
onEdit?: (testCase: any) => void;
onImport?: () => void;
+ /** Navigate to the case definition page. */
+ onOpen?: (testCase: any) => void;
onPageChange: (page: number, pageSize: number) => void;
onPreview?: (testCase: any) => void;
onSearchChange: (value: string) => void;
@@ -151,6 +153,7 @@ const TestCaseTable = memo<TestCaseTableProps>(
onPageChange,
onPreview,
onEdit,
+ onOpen,
onDelete,
onAddCase,
onImport,
@@ -266,6 +269,17 @@ const TestCaseTable = memo<TestCaseTableProps>(
<DropdownMenu
trigger={['click']}
items={[
+ ...(onOpen
+ ? [
+ {
+ icon: <ExternalLink size={14} />,
+ key: 'open',
+ label: t('testCaseDetail.open'),
+ onClick: () => onOpen(record),
+ },
+ { type: 'divider' as const },
+ ]
+ : []),
{
icon: <Pencil size={14} />,
key: 'edit',
@@ -291,7 +305,7 @@ const TestCaseTable = memo<TestCaseTableProps>(
}
return base;
- }, [pagination, readOnly, onEdit, onDelete, t, datasetEvalMode]);
+ }, [pagination, readOnly, onEdit, onOpen, onDelete, t, datasetEvalMode]);
return (
<>
diff --git a/src/routes/(main)/eval/cases/[caseId]/index.tsx b/src/routes/(main)/eval/cases/[caseId]/index.tsx
new file mode 100644
index 00000000000..aae0957f718
--- /dev/null
+++ b/src/routes/(main)/eval/cases/[caseId]/index.tsx
@@ -0,0 +1,51 @@
+'use client';
+
+import { Center } from '@lobehub/ui';
+import { Text } from '@lobehub/ui/base-ui';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useParams } from 'react-router';
+
+import AsyncBoundary from '@/components/AsyncBoundary';
+import { useEvalStore } from '@/store/eval';
+import { isTrpcErrorCode } from '@/utils/trpcError';
+
+import TestCaseDetail from '../../features/TestCaseDetail';
+
+const Page = memo(() => {
+ const { t } = useTranslation('eval');
+ const { caseId } = useParams<{ caseId: string }>();
+
+ const useFetchTestCase = useEvalStore((s) => s.useFetchTestCase);
+ const useFetchDatasetDetail = useEvalStore((s) => s.useFetchDatasetDetail);
+ const { data: testCase, error, isLoading, mutate } = useFetchTestCase(caseId);
+ const { data: dataset } = useFetchDatasetDetail(testCase?.datasetId);
+
+ // A deleted or mistyped case id is an absent resource, not a failed request:
+ // `getTestCase` throws NOT_FOUND, and AsyncBoundary reads `error` before
+ // `isEmpty`, so without this it renders a generic "load failed" page offering
+ // a Retry that can never succeed.
+ const isMissing = isTrpcErrorCode(error, 'NOT_FOUND');
+
+ return (
+ <AsyncBoundary
+ data={isMissing ? null : testCase}
+ error={isMissing ? undefined : error}
+ errorVariant={'page'}
+ isEmpty={isMissing || !testCase}
+ isLoading={isLoading}
+ empty={
+ <Center flex={1}>
+ <Text type="secondary">{t('testCaseDetail.notFound')}</Text>
+ </Center>
+ }
+ onRetry={() => mutate()}
+ >
+ {testCase && <TestCaseDetail datasetName={dataset?.name} testCase={testCase} />}
+ </AsyncBoundary>
+ );
+});
+
+Page.displayName = 'EvalTestCaseDetailPage';
+
+export default Page;
diff --git a/src/routes/(main)/eval/datasets/[datasetId]/index.tsx b/src/routes/(main)/eval/datasets/[datasetId]/index.tsx
new file mode 100644
index 00000000000..2d69bb6ba98
--- /dev/null
+++ b/src/routes/(main)/eval/datasets/[datasetId]/index.tsx
@@ -0,0 +1,398 @@
+'use client';
+
+import { Flexbox } from '@lobehub/ui';
+import { Button, confirmModal, Text, toast } from '@lobehub/ui/base-ui';
+import { createStaticStyles, cssVar } from 'antd-style';
+import { ArrowLeft, Database, Pencil, Plus, Trash2 } from 'lucide-react';
+import { memo, useCallback, useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useParams } from 'react-router';
+
+import AsyncBoundary from '@/components/AsyncBoundary';
+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
+import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
+import { agentEvalService } from '@/services/agentEval';
+import { runSelectors, useEvalStore } from '@/store/eval';
+
+import TestCasePreviewPanel from '../../bench/[benchmarkId]/features/DatasetsTab/TestCasePreviewPanel';
+import TestCaseTable from '../../bench/[benchmarkId]/features/DatasetsTab/TestCaseTable';
+import { createRunCreateModal } from '../../bench/[benchmarkId]/features/RunCreateModal';
+import EmptyState from '../../bench/[benchmarkId]/features/RunsTab/EmptyState';
+import RunCard from '../../bench/[benchmarkId]/features/RunsTab/RunCard';
+import { createDatasetEditModal } from '../../features/DatasetEditModal';
+import { createDatasetImportModal } from '../../features/DatasetImportModal';
+import SegmentBar from '../../features/SegmentBar';
+import { createTestCaseCreateModal } from '../../features/TestCaseCreateModal';
+import { createTestCaseEditModal } from '../../features/TestCaseEditModal';
+
+const styles = createStaticStyles(({ css }) => ({
+ backLink: css`
+ display: inline-flex;
+ gap: 4px;
+ align-items: center;
+
+ width: fit-content;
+
+ font-size: ${cssVar.fontSize};
+ color: ${cssVar.colorTextTertiary};
+ text-decoration: none;
+
+ transition: color 0.15s ease;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ }
+
+ &:focus-visible {
+ outline: 2px solid ${cssVar.colorPrimary};
+ outline-offset: 2px;
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
+ `,
+ header: css`
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
+
+ width: 40px;
+ height: 40px;
+ border-radius: ${cssVar.borderRadiusLG};
+
+ background: ${cssVar.colorPrimaryBg};
+ `,
+ // Summary hero — leads the dataset detail with its headline case count as a
+ // large mono figure, mirroring the benchmark/run result heroes.
+ heroBand: css`
+ padding: 20px;
+ border-radius: ${cssVar.borderRadiusLG};
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ heroValue: css`
+ font-family: ${cssVar.fontFamilyCode};
+ font-size: ${cssVar.fontSizeHeading2};
+ font-weight: 600;
+ line-height: 1;
+ color: ${cssVar.colorText};
+ `,
+ summaryDot: css`
+ width: 8px;
+ height: 8px;
+ border-radius: 999px;
+ `,
+ tableWrapper: css`
+ overflow: hidden;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadius};
+ `,
+}));
+
+const DatasetDetail = memo(() => {
+ const { t } = useTranslation('eval');
+ const { datasetId } = useParams<{ datasetId: string }>();
+ const navigate = useWorkspaceAwareNavigate();
+
+ const [pagination, setPagination] = useState({ current: 1, pageSize: 10 });
+ const [search, setSearch] = useState('');
+ const [diffFilter, setDiffFilter] = useState<'all' | 'easy' | 'medium' | 'hard'>('all');
+ const [previewCase, setPreviewCase] = useState<any | null>(null);
+
+ const useFetchDatasetDetail = useEvalStore((s) => s.useFetchDatasetDetail);
+ const useFetchTestCases = useEvalStore((s) => s.useFetchTestCases);
+ const useFetchDatasetRuns = useEvalStore((s) => s.useFetchDatasetRuns);
+ const runList = useEvalStore(runSelectors.datasetRunList(datasetId!));
+ const refreshTestCases = useEvalStore((s) => s.refreshTestCases);
+ const refreshDatasetDetail = useEvalStore((s) => s.refreshDatasetDetail);
+
+ const { data: dataset, error, isLoading, mutate } = useFetchDatasetDetail(datasetId);
+ // Nullable: a dataset accumulated from captured cases belongs to no benchmark.
+ const benchmarkId: string | null =
+ (dataset as { benchmarkId?: string | null })?.benchmarkId ?? null;
+ useFetchDatasetRuns(datasetId);
+
+ const sortedRuns = useMemo(
+ () =>
+ [...runList].sort(
+ (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
+ ),
+ [runList],
+ );
+
+ const { data: testCaseData } = useFetchTestCases({
+ datasetId: datasetId!,
+ limit: pagination.pageSize,
+ offset: (pagination.current - 1) * pagination.pageSize,
+ });
+
+ const testCases = testCaseData?.data || [];
+ const total = testCaseData?.total || 0;
+
+ const filteredCases = testCases.filter((c: any) => {
+ if (diffFilter !== 'all' && c.metadata?.difficulty !== diffFilter) return false;
+ if (search && !c.content?.input?.toLowerCase().includes(search.toLowerCase())) return false;
+ return true;
+ });
+
+ // Difficulty mix across the loaded cases — feeds the summary hero's bar.
+ const difficulty = useMemo(() => {
+ const counts = { easy: 0, hard: 0, medium: 0 };
+ for (const c of testCases as any[]) {
+ const d = c?.metadata?.difficulty as 'easy' | 'hard' | 'medium' | undefined;
+ if (d === 'easy' || d === 'medium' || d === 'hard') counts[d] += 1;
+ }
+ return {
+ counts,
+ segments: [
+ { color: cssVar.colorSuccess, value: counts.easy },
+ { color: cssVar.colorWarning, value: counts.medium },
+ { color: cssVar.colorError, value: counts.hard },
+ ],
+ tagged: counts.easy + counts.medium + counts.hard,
+ };
+ }, [testCases]);
+
+ const handleRefresh = useCallback(async () => {
+ if (datasetId) {
+ await refreshTestCases(datasetId);
+ await refreshDatasetDetail(datasetId);
+ }
+ }, [datasetId, refreshTestCases, refreshDatasetDetail]);
+
+ const handleDeleteCase = useCallback(
+ (testCase: any) => {
+ confirmModal({
+ content: t('testCase.delete.confirm'),
+ okButtonProps: { danger: true },
+ okText: t('common.delete'),
+ onOk: async () => {
+ try {
+ await agentEvalService.deleteTestCase(testCase.id);
+ toast.success(t('testCase.delete.success'));
+ await handleRefresh();
+ } catch {
+ toast.error(t('testCase.delete.error'));
+ }
+ },
+ title: t('common.delete'),
+ });
+ },
+ [handleRefresh, t],
+ );
+
+ const handleDelete = useCallback(() => {
+ confirmModal({
+ content: t('dataset.delete.confirm'),
+ okButtonProps: { danger: true },
+ okText: t('common.delete'),
+ onOk: async () => {
+ try {
+ await agentEvalService.deleteDataset(datasetId!);
+ toast.success(t('dataset.delete.success'));
+ navigate(benchmarkId ? `/eval/bench/${benchmarkId}` : '/eval');
+ } catch {
+ toast.error(t('dataset.delete.error'));
+ }
+ },
+ title: t('common.delete'),
+ });
+ }, [benchmarkId, datasetId, navigate, t]);
+
+ // Skeleton → error → (resolved-null) blank, replacing a bare `return null`
+ // that flashed blank on the happy path and stayed permanently blank on a
+ // failed fetch (ux Read §1.1). A page-level failure gets a reason + Reload.
+ return (
+ <AsyncBoundary
+ data={dataset}
+ error={error}
+ errorVariant={'page'}
+ isEmpty={!dataset}
+ isLoading={isLoading}
+ onRetry={() => mutate()}
+ >
+ {dataset && (
+ <Flexbox horizontal style={{ flex: 1, minHeight: 0 }}>
+ <Flexbox
+ flex={1}
+ gap={24}
+ style={{ minWidth: 0, overflow: 'auto', paddingBlock: 24, paddingInline: 32 }}
+ >
+ {/* Back link */}
+ <WorkspaceLink
+ className={styles.backLink}
+ to={benchmarkId ? `/eval/bench/${benchmarkId}` : '/eval'}
+ >
+ <ArrowLeft size={16} />
+ {benchmarkId ? t('dataset.detail.backToBenchmark') : t('dataset.detail.backToEval')}
+ </WorkspaceLink>
+
+ {/* Header */}
+ <Flexbox horizontal align="start" justify="space-between">
+ <Flexbox horizontal align="start" gap={12}>
+ <div className={styles.header}>
+ <Database size={20} style={{ color: cssVar.colorPrimary }} />
+ </div>
+ <Flexbox gap={4}>
+ <Text as="h4" style={{ fontSize: 20, fontWeight: 600, margin: 0 }}>
+ {dataset.name}
+ </Text>
+ {dataset.description && <Text type="secondary">{dataset.description}</Text>}
+ </Flexbox>
+ </Flexbox>
+
+ <Flexbox horizontal gap={8}>
+ <Button
+ icon={Pencil}
+ size="small"
+ onClick={() => createDatasetEditModal({ dataset, onSuccess: handleRefresh })}
+ >
+ {t('common.edit')}
+ </Button>
+ <Button danger icon={Trash2} size="small" onClick={handleDelete}>
+ {t('common.delete')}
+ </Button>
+ </Flexbox>
+ </Flexbox>
+
+ {/* Summary hero — headline case count + difficulty mix */}
+ <Flexbox
+ horizontal
+ align="center"
+ className={styles.heroBand}
+ gap={16}
+ justify="space-between"
+ >
+ <Flexbox gap={6}>
+ <span className={styles.heroValue}>{total}</span>
+ <Text color={cssVar.colorTextTertiary} fontSize={12}>
+ {t('dataset.detail.testCases')}
+ </Text>
+ </Flexbox>
+ {difficulty.tagged > 0 && (
+ <Flexbox gap={8} style={{ maxWidth: 280, minWidth: 0, width: '100%' }}>
+ <SegmentBar segments={difficulty.segments} />
+ <Flexbox horizontal gap={12} justify="flex-end" style={{ flexWrap: 'wrap' }}>
+ {(['easy', 'medium', 'hard'] as const).map((d) => (
+ <Flexbox horizontal align="center" gap={6} key={d}>
+ <span
+ className={styles.summaryDot}
+ style={{
+ background:
+ d === 'easy'
+ ? cssVar.colorSuccess
+ : d === 'medium'
+ ? cssVar.colorWarning
+ : cssVar.colorError,
+ }}
+ />
+ <Text color={cssVar.colorTextTertiary} fontSize={12}>
+ {t(`difficulty.${d}`)} {difficulty.counts[d]}
+ </Text>
+ </Flexbox>
+ ))}
+ </Flexbox>
+ </Flexbox>
+ )}
+ </Flexbox>
+
+ {/* Test Cases */}
+ <Flexbox gap={12}>
+ <Flexbox horizontal align="center" justify="space-between">
+ <Text weight={600}>{t('dataset.detail.testCases')}</Text>
+ <Text type="secondary">{t('dataset.detail.caseCount', { count: total })}</Text>
+ </Flexbox>
+
+ <div className={styles.tableWrapper}>
+ <TestCaseTable
+ datasetEvalMode={dataset?.evalMode}
+ diffFilter={diffFilter}
+ pagination={pagination}
+ search={search}
+ selectedId={previewCase?.id}
+ testCases={filteredCases}
+ total={total}
+ onDelete={handleDeleteCase}
+ onOpen={(testCase: any) => navigate(`/eval/cases/${testCase.id}`)}
+ onPageChange={(page, pageSize) => setPagination({ current: page, pageSize })}
+ onPreview={setPreviewCase}
+ onAddCase={() =>
+ createTestCaseCreateModal({ datasetId: datasetId!, onSuccess: handleRefresh })
+ }
+ onDiffFilterChange={(f) => {
+ setDiffFilter(f);
+ setPagination((prev) => ({ ...prev, current: 1 }));
+ }}
+ onEdit={(testCase) =>
+ createTestCaseEditModal({ onSuccess: handleRefresh, testCase })
+ }
+ onImport={() =>
+ createDatasetImportModal({ datasetId: datasetId!, onSuccess: handleRefresh })
+ }
+ onSearchChange={(v) => {
+ setSearch(v);
+ setPagination((prev) => ({ ...prev, current: 1 }));
+ }}
+ />
+ </div>
+ </Flexbox>
+
+ {/* Related Runs. A run belongs to a benchmark by design — that is
+ what defines the shared rubrics it is scored against — so a
+ dataset that belongs to none has nothing to run against yet. */}
+ {benchmarkId ? (
+ <Flexbox gap={12}>
+ <Flexbox horizontal align="center" justify="space-between">
+ <Text weight={600}>
+ {t('dataset.detail.relatedRuns', { count: sortedRuns.length })}
+ </Text>
+ <Button
+ icon={Plus}
+ size="small"
+ onClick={() =>
+ createRunCreateModal({
+ benchmarkId: benchmarkId!,
+ datasetId: datasetId!,
+ datasetName: dataset.name,
+ })
+ }
+ >
+ {t('dataset.detail.addRun')}
+ </Button>
+ </Flexbox>
+ {sortedRuns.length > 0 ? (
+ <Flexbox gap={12}>
+ {sortedRuns.map((run) => (
+ <RunCard benchmarkId={benchmarkId!} key={run.id} run={run} />
+ ))}
+ </Flexbox>
+ ) : (
+ <EmptyState
+ onCreate={() =>
+ createRunCreateModal({
+ benchmarkId: benchmarkId!,
+ datasetId: datasetId!,
+ datasetName: dataset.name,
+ })
+ }
+ />
+ )}
+ </Flexbox>
+ ) : (
+ <Text color={cssVar.colorTextTertiary} fontSize={12}>
+ {t('dataset.detail.runsNeedBenchmark')}
+ </Text>
+ )}
+ </Flexbox>
+
+ {previewCase && (
+ <TestCasePreviewPanel testCase={previewCase} onClose={() => setPreviewCase(null)} />
+ )}
+ </Flexbox>
+ )}
+ </AsyncBoundary>
+ );
+});
+
+export default DatasetDetail;
diff --git a/src/routes/(main)/eval/features/TestCaseDetail/MessageBlock.tsx b/src/routes/(main)/eval/features/TestCaseDetail/MessageBlock.tsx
new file mode 100644
index 00000000000..34349ebfa0e
--- /dev/null
+++ b/src/routes/(main)/eval/features/TestCaseDetail/MessageBlock.tsx
@@ -0,0 +1,80 @@
+'use client';
+
+import { Flexbox } from '@lobehub/ui';
+import { Tag } from '@lobehub/ui/base-ui';
+import { createStaticStyles, cssVar } from 'antd-style';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+const styles = createStaticStyles(({ css }) => ({
+ body: css`
+ overflow-y: auto;
+
+ /* Each turn is capped so a long one cannot push the rest of the
+ transcript out of view; the full text stays reachable inside. */
+ max-height: 240px;
+ padding-block: 10px;
+ padding-inline: 12px;
+ border-radius: 10px;
+
+ font-size: ${cssVar.fontSize};
+ line-height: 1.75;
+ white-space: pre-wrap;
+
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ bodyMuted: css`
+ overflow-y: auto;
+
+ max-height: 120px;
+ padding-block: 8px;
+ padding-inline: 12px;
+ border-radius: 10px;
+
+ font-size: ${cssVar.fontSizeSM};
+ line-height: 1.7;
+ color: ${cssVar.colorTextTertiary};
+ white-space: pre-wrap;
+
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ head: css`
+ font-size: ${cssVar.fontSizeSM};
+ font-weight: 500;
+ color: ${cssVar.colorTextTertiary};
+ `,
+}));
+
+export interface MessageBlockProps {
+ badge?: string;
+ content: string;
+ /** Context turns are dimmed so the eye lands on the turn under test. */
+ muted?: boolean;
+ role: string;
+}
+
+const ROLE_KEYS: Record<string, string> = {
+ assistant: 'testCaseDetail.role.assistant',
+ system: 'testCaseDetail.role.system',
+ tool: 'testCaseDetail.role.tool',
+ user: 'testCaseDetail.role.user',
+};
+
+const MessageBlock = memo<MessageBlockProps>(({ badge, content, muted, role }) => {
+ const { t } = useTranslation('eval');
+ const roleKey = ROLE_KEYS[role];
+
+ return (
+ <Flexbox gap={5}>
+ <Flexbox horizontal align="center" className={styles.head} gap={6}>
+ <span>{roleKey ? t(roleKey as any) : role}</span>
+ {badge && <Tag size="small">{badge}</Tag>}
+ </Flexbox>
+ <div className={muted ? styles.bodyMuted : styles.body}>{content}</div>
+ </Flexbox>
+ );
+});
+
+MessageBlock.displayName = 'MessageBlock';
+
+export default MessageBlock;
diff --git a/src/routes/(main)/eval/features/TestCaseDetail/Transcript.tsx b/src/routes/(main)/eval/features/TestCaseDetail/Transcript.tsx
new file mode 100644
index 00000000000..8f97d36dcce
--- /dev/null
+++ b/src/routes/(main)/eval/features/TestCaseDetail/Transcript.tsx
@@ -0,0 +1,104 @@
+'use client';
+
+import { Flexbox, Icon } from '@lobehub/ui';
+import { createStaticStyles, cssVar } from 'antd-style';
+import { ChevronRight } from 'lucide-react';
+import { memo, type ReactNode, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { buildTranscript, type TranscriptMessage } from './buildTranscript';
+import MessageBlock from './MessageBlock';
+
+const styles = createStaticStyles(({ css }) => ({
+ boundary: css`
+ display: flex;
+ gap: 8px;
+ align-items: center;
+
+ font-size: ${cssVar.fontSizeSM};
+ color: ${cssVar.colorTextQuaternary};
+
+ &::after {
+ content: '';
+ flex: 1;
+ height: 1px;
+ background: ${cssVar.colorSplit};
+ }
+ `,
+ chevron: css`
+ transition: transform 0.15s ease;
+ `,
+ chevronOpen: css`
+ transform: rotate(90deg);
+ `,
+ toggle: css`
+ cursor: pointer;
+
+ display: flex;
+ gap: 6px;
+ align-items: center;
+ align-self: flex-start;
+
+ padding: 0;
+ border: none;
+
+ font-size: ${cssVar.fontSizeSM};
+ color: ${cssVar.colorTextTertiary};
+
+ background: transparent;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ }
+ `,
+}));
+
+export interface TranscriptProps {
+ input: string;
+ /** Replaces the input block, so the turn under test can be made editable. */
+ inputSlot?: ReactNode;
+ /** Conversation replayed into the eval topic before `input` is sent. */
+ messages?: TranscriptMessage[];
+}
+
+/**
+ * The case read as one conversation rather than as separate labelled fields:
+ * the replayed context, a boundary, then the turn actually under test.
+ *
+ * The context is collapsed by default. It is provenance — usually long, rarely
+ * what you opened the case to read — and expanded it pushes the turn under test
+ * and its criteria below the fold.
+ */
+const Transcript = memo<TranscriptProps>(({ input, inputSlot, messages }) => {
+ const { t } = useTranslation('eval');
+ const { context, hasBoundary } = buildTranscript(messages);
+ const [expanded, setExpanded] = useState(false);
+
+ return (
+ <Flexbox gap={12}>
+ {hasBoundary && (
+ <button className={styles.toggle} type="button" onClick={() => setExpanded((v) => !v)}>
+ <Icon
+ className={expanded ? `${styles.chevron} ${styles.chevronOpen}` : styles.chevron}
+ icon={ChevronRight}
+ size={14}
+ />
+ {t('testCaseDetail.context', { count: context.length })}
+ </button>
+ )}
+ {expanded && (
+ <>
+ {context.map((turn, index) => (
+ <MessageBlock muted content={turn.text} key={index} role={turn.role} />
+ ))}
+ <div className={styles.boundary}>{t('testCaseDetail.boundary')}</div>
+ </>
+ )}
+ {inputSlot ?? <MessageBlock badge="input" content={input} role="user" />}
+ </Flexbox>
+ );
+});
+
+Transcript.displayName = 'Transcript';
+
+export default Transcript;
diff --git a/src/routes/(main)/eval/features/TestCaseDetail/buildTranscript.test.ts b/src/routes/(main)/eval/features/TestCaseDetail/buildTranscript.test.ts
new file mode 100644
index 00000000000..cc8df82200d
--- /dev/null
+++ b/src/routes/(main)/eval/features/TestCaseDetail/buildTranscript.test.ts
@@ -0,0 +1,63 @@
+import { describe, expect, it } from 'vitest';
+
+import { buildTranscript, toText } from './buildTranscript';
+
+describe('toText', () => {
+ it('passes a plain string through', () => {
+ expect(toText('hello')).toBe('hello');
+ });
+
+ it('flattens provider content parts', () => {
+ expect(toText([{ text: 'part one', type: 'text' }, 'part two'])).toBe('part one\npart two');
+ });
+
+ it('drops parts with no text rather than stringifying them', () => {
+ expect(toText([{ image: 'x' }, { text: 'kept' }])).toBe('kept');
+ });
+
+ it('returns an empty string for content it cannot read', () => {
+ expect(toText({ odd: true })).toBe('');
+ expect(toText(undefined)).toBe('');
+ expect(toText(null)).toBe('');
+ });
+});
+
+describe('buildTranscript', () => {
+ it('returns no context and no boundary when the case has none', () => {
+ expect(buildTranscript()).toEqual({ context: [], hasBoundary: false });
+ expect(buildTranscript([])).toEqual({ context: [], hasBoundary: false });
+ });
+
+ it('keeps user and assistant turns in order', () => {
+ const result = buildTranscript([
+ { content: 'first', role: 'user' },
+ { content: 'second', role: 'assistant' },
+ ]);
+
+ expect(result.context).toEqual([
+ { role: 'user', text: 'first' },
+ { role: 'assistant', text: 'second' },
+ ]);
+ expect(result.hasBoundary).toBe(true);
+ });
+
+ it('drops the system message, which is harness context rather than a turn', () => {
+ const result = buildTranscript([
+ { content: 'you are helpful', role: 'system' },
+ { content: 'earlier', role: 'user' },
+ ]);
+
+ expect(result.context).toEqual([{ role: 'user', text: 'earlier' }]);
+ });
+
+ it('reports no boundary when system messages were the only context', () => {
+ expect(buildTranscript([{ content: 'sys', role: 'system' }])).toEqual({
+ context: [],
+ hasBoundary: false,
+ });
+ });
+
+ it('defaults a missing role to user', () => {
+ expect(buildTranscript([{ content: 'x' }]).context).toEqual([{ role: 'user', text: 'x' }]);
+ });
+});
diff --git a/src/routes/(main)/eval/features/TestCaseDetail/buildTranscript.ts b/src/routes/(main)/eval/features/TestCaseDetail/buildTranscript.ts
new file mode 100644
index 00000000000..0beb76db13d
--- /dev/null
+++ b/src/routes/(main)/eval/features/TestCaseDetail/buildTranscript.ts
@@ -0,0 +1,49 @@
+export interface TranscriptMessage {
+ content?: unknown;
+ role?: string;
+}
+
+export interface TranscriptTurn {
+ role: string;
+ text: string;
+}
+
+export interface Transcript {
+ context: TranscriptTurn[];
+ /** Whether there is prior context to separate from the turn under test. */
+ hasBoundary: boolean;
+}
+
+/**
+ * Message content arrives as a string on most providers and as content parts on
+ * others. Unusable parts are dropped rather than stringified, so a case with an
+ * image attachment reads as its text instead of as `[object Object]`.
+ */
+export const toText = (content: unknown): string => {
+ if (typeof content === 'string') return content;
+ if (!Array.isArray(content)) return '';
+
+ return content
+ .map((part) => {
+ if (typeof part === 'string') return part;
+ const text = (part as { text?: unknown })?.text;
+ return typeof text === 'string' ? text : '';
+ })
+ .filter(Boolean)
+ .join('\n');
+};
+
+/**
+ * The replayed conversation that precedes the turn under test.
+ *
+ * The system message is dropped: it is harness context rather than a turn
+ * someone took, and showing it as one would misrepresent the conversation. The
+ * boundary is only meaningful when something remains to be separated.
+ */
+export const buildTranscript = (messages?: TranscriptMessage[]): Transcript => {
+ const context = (messages ?? [])
+ .filter((message) => message.role !== 'system')
+ .map((message) => ({ role: message.role ?? 'user', text: toText(message.content) }));
+
+ return { context, hasBoundary: context.length > 0 };
+};
diff --git a/src/routes/(main)/eval/features/TestCaseDetail/index.tsx b/src/routes/(main)/eval/features/TestCaseDetail/index.tsx
new file mode 100644
index 00000000000..c98d986669e
--- /dev/null
+++ b/src/routes/(main)/eval/features/TestCaseDetail/index.tsx
@@ -0,0 +1,257 @@
+'use client';
+
+import { Flexbox, Icon, TextArea } from '@lobehub/ui';
+import { Button, Tag, Text, toast } from '@lobehub/ui/base-ui';
+import { Breadcrumb } from 'antd';
+import { createStaticStyles, cssVar } from 'antd-style';
+import { ChevronRight, FileText, Pencil } from 'lucide-react';
+import { memo, useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
+import { useEvalStore } from '@/store/eval';
+
+import Transcript from './Transcript';
+import { useCaseDraft } from './useCaseDraft';
+
+const styles = createStaticStyles(({ css }) => ({
+ breadcrumb: css`
+ font-size: ${cssVar.fontSize};
+
+ a {
+ color: ${cssVar.colorTextTertiary};
+ text-decoration: none;
+ transition: color 0.15s ease;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ }
+ }
+ `,
+ icon: css`
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ width: 36px;
+ height: 36px;
+ border-radius: 10px;
+
+ background: ${cssVar.colorFillTertiary};
+ `,
+ label: css`
+ font-size: ${cssVar.fontSizeSM};
+ font-weight: 500;
+ color: ${cssVar.colorTextSecondary};
+ `,
+ editor: css`
+ font-size: ${cssVar.fontSize};
+ line-height: 1.75;
+ `,
+ prose: css`
+ padding-block: 10px;
+ padding-inline: 12px;
+ border-radius: 10px;
+
+ font-size: ${cssVar.fontSize};
+ line-height: 1.75;
+ white-space: pre-wrap;
+
+ background: ${cssVar.colorFillQuaternary};
+ `,
+}));
+
+export interface TestCaseDetailProps {
+ /** Shown in the breadcrumb; falls back to a generic label when unknown. */
+ datasetName?: string;
+ testCase: {
+ datasetId: string;
+ content?: {
+ input?: string;
+ messages?: Array<{ content?: unknown; role?: string }>;
+ } & Record<string, unknown>;
+ evalConfig?: Record<string, unknown> | null;
+ evalMode?: string | null;
+ id: string;
+ metadata?: Record<string, unknown> | null;
+ };
+}
+
+/**
+ * A test case as a definition — what it asks and how it is judged — addressable
+ * without a run. The `runs/:runId/cases/:caseId` page is a different surface: it
+ * renders one case's *result* inside a single run.
+ */
+const TestCaseDetail = memo<TestCaseDetailProps>(({ datasetName, testCase }) => {
+ const { t } = useTranslation('eval');
+ const updateTestCase = useEvalStore((s) => s.updateTestCase);
+ const [saving, setSaving] = useState(false);
+
+ const content = testCase.content ?? {};
+ const expected = typeof content.expected === 'string' ? content.expected : undefined;
+ const criteria =
+ typeof testCase.evalConfig?.criteria === 'string' ? testCase.evalConfig.criteria : undefined;
+ const caseId =
+ typeof testCase.metadata?.caseId === 'string' ? testCase.metadata.caseId : undefined;
+ // The answer this case was captured from. It is the counter-example, which is
+ // why it is stored apart from `expected` — and why it has to be visible here,
+ // or the case reads as if nothing ever went wrong.
+ const capturedOutput =
+ typeof testCase.metadata?.capturedOutput === 'string'
+ ? testCase.metadata.capturedOutput
+ : undefined;
+
+ const initial = useMemo(
+ () => ({ criteria: criteria ?? '', expected: expected ?? '', input: content.input ?? '' }),
+ [criteria, expected, content.input],
+ );
+ const { cancel, draft, editing, patch, setDraft, start, stop } = useCaseDraft(initial);
+
+ const handleSave = async () => {
+ if (!patch) return stop();
+ setSaving(true);
+ try {
+ await updateTestCase(testCase.id, testCase.datasetId, patch);
+ stop();
+ } catch (error) {
+ toast.error((error as Error)?.message ?? t('testCaseDetail.saveFailed'));
+ } finally {
+ setSaving(false);
+ }
+ };
+
+ return (
+ <Flexbox
+ gap={24}
+ style={{
+ marginInline: 'auto',
+ maxWidth: 880,
+ paddingBlock: 24,
+ paddingInline: 32,
+ width: '100%',
+ }}
+ >
+ <Breadcrumb
+ className={styles.breadcrumb}
+ separator={<Icon icon={ChevronRight} size={14} />}
+ items={[
+ {
+ title: <WorkspaceLink to="/eval">{t('testCaseDetail.breadcrumb.eval')}</WorkspaceLink>,
+ },
+ {
+ title: (
+ <WorkspaceLink to={`/eval/datasets/${testCase.datasetId}`}>
+ {datasetName || t('testCaseDetail.breadcrumb.dataset')}
+ </WorkspaceLink>
+ ),
+ },
+ { title: caseId ?? t('testCaseDetail.title') },
+ ]}
+ />
+
+ <Flexbox horizontal align="center" gap={12} justify="space-between">
+ <Flexbox horizontal align="center" gap={12}>
+ <div className={styles.icon}>
+ <FileText size={18} style={{ color: cssVar.colorTextSecondary }} />
+ </div>
+ <Flexbox gap={6}>
+ <Text as="h4" style={{ fontSize: 20, fontWeight: 600, margin: 0 }}>
+ {caseId ?? t('testCaseDetail.title')}
+ </Text>
+ <Flexbox horizontal gap={6}>
+ {testCase.evalMode && <Tag size="small">{testCase.evalMode}</Tag>}
+ </Flexbox>
+ </Flexbox>
+ </Flexbox>
+ {editing ? (
+ <Flexbox horizontal gap={8}>
+ <Button disabled={saving} size="small" onClick={cancel}>
+ {t('common.cancel')}
+ </Button>
+ <Button loading={saving} size="small" type="primary" onClick={handleSave}>
+ {t('common.save')}
+ </Button>
+ </Flexbox>
+ ) : (
+ <Button icon={Pencil} size="small" onClick={start}>
+ {t('common.edit')}
+ </Button>
+ )}
+ </Flexbox>
+
+ <Flexbox gap={10}>
+ <span className={styles.label}>{t('testCaseDetail.definition')}</span>
+ <Transcript
+ input={content.input ?? ''}
+ messages={content.messages}
+ inputSlot={
+ editing ? (
+ <TextArea
+ autoSize={{ maxRows: 12, minRows: 3 }}
+ className={styles.editor}
+ value={draft.input}
+ onChange={(e) => setDraft({ input: e.target.value })}
+ />
+ ) : undefined
+ }
+ />
+ </Flexbox>
+
+ {capturedOutput && (
+ <Flexbox gap={10}>
+ <Flexbox horizontal align="center" gap={8}>
+ <span className={styles.label}>{t('testCaseDetail.capturedOutput')}</span>
+ <Tag color="error" size="small">
+ {t('testCaseDetail.counterExample')}
+ </Tag>
+ </Flexbox>
+ <div className={styles.prose}>{capturedOutput}</div>
+ <Text style={{ fontSize: 12 }} type="secondary">
+ {t('testCaseDetail.capturedOutputHint')}
+ </Text>
+ </Flexbox>
+ )}
+
+ <Flexbox gap={10}>
+ <span className={styles.label}>{t('testCaseDetail.criteria')}</span>
+ {editing ? (
+ <TextArea
+ autoSize={{ maxRows: 12, minRows: 3 }}
+ className={styles.editor}
+ value={draft.criteria}
+ onChange={(e) => setDraft({ criteria: e.target.value })}
+ />
+ ) : criteria ? (
+ <div className={styles.prose}>{criteria}</div>
+ ) : (
+ <Text style={{ fontSize: 12 }} type="secondary">
+ {t('testCaseDetail.criteria.empty')}
+ </Text>
+ )}
+ </Flexbox>
+
+ <Flexbox gap={10}>
+ <span className={styles.label}>{t('testCaseDetail.expected')}</span>
+ {editing ? (
+ <TextArea
+ autoSize={{ maxRows: 12, minRows: 3 }}
+ className={styles.editor}
+ placeholder={t('testCaseDetail.expected.placeholder')}
+ value={draft.expected}
+ onChange={(e) => setDraft({ expected: e.target.value })}
+ />
+ ) : expected ? (
+ <div className={styles.prose}>{expected}</div>
+ ) : (
+ <Text style={{ fontSize: 12 }} type="secondary">
+ {t('testCaseDetail.expected.empty')}
+ </Text>
+ )}
+ </Flexbox>
+ </Flexbox>
+ );
+});
+
+TestCaseDetail.displayName = 'TestCaseDetail';
+
+export default TestCaseDetail;
diff --git a/src/routes/(main)/eval/features/TestCaseDetail/useCaseDraft.test.ts b/src/routes/(main)/eval/features/TestCaseDetail/useCaseDraft.test.ts
new file mode 100644
index 00000000000..0d74604938c
--- /dev/null
+++ b/src/routes/(main)/eval/features/TestCaseDetail/useCaseDraft.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest';
+
+import { type CaseDraft, diffCaseDraft } from './useCaseDraft';
+
+const base: CaseDraft = { criteria: 'c', expected: 'e', input: 'i' };
+
+describe('diffCaseDraft', () => {
+ it('sends nothing when nothing changed', () => {
+ expect(diffCaseDraft(base, { ...base })).toBeNull();
+ });
+
+ it('sends only the changed content field', () => {
+ expect(diffCaseDraft(base, { ...base, input: 'i2' })).toEqual({ content: { input: 'i2' } });
+ });
+
+ it('sends criteria under evalConfig, not content', () => {
+ expect(diffCaseDraft(base, { ...base, criteria: 'c2' })).toEqual({
+ evalConfig: { criteria: 'c2' },
+ });
+ });
+
+ it('combines content and evalConfig changes into one patch', () => {
+ expect(diffCaseDraft(base, { criteria: 'c2', expected: 'e2', input: 'i' })).toEqual({
+ content: { expected: 'e2' },
+ evalConfig: { criteria: 'c2' },
+ });
+ });
+
+ // A captured case has no expected answer on purpose. Clearing the field has to
+ // reach the server as an empty string, not be dropped as "unchanged".
+ it('treats clearing a field as a change', () => {
+ expect(diffCaseDraft(base, { ...base, expected: '' })).toEqual({ content: { expected: '' } });
+ });
+
+ it('does not resurrect a field that was empty and stayed empty', () => {
+ const empty: CaseDraft = { criteria: '', expected: '', input: 'i' };
+ expect(diffCaseDraft(empty, { ...empty })).toBeNull();
+ });
+});
diff --git a/src/routes/(main)/eval/features/TestCaseDetail/useCaseDraft.ts b/src/routes/(main)/eval/features/TestCaseDetail/useCaseDraft.ts
new file mode 100644
index 00000000000..4793b452fac
--- /dev/null
+++ b/src/routes/(main)/eval/features/TestCaseDetail/useCaseDraft.ts
@@ -0,0 +1,59 @@
+import { useCallback, useMemo, useState } from 'react';
+
+export interface CaseDraft {
+ criteria: string;
+ expected: string;
+ input: string;
+}
+
+export interface CaseDraftPatch {
+ content?: { expected?: string; input?: string };
+ evalConfig?: { criteria?: string };
+}
+
+/**
+ * Only what actually changed. Sending the whole draft would rewrite fields the
+ * user never touched — and `expected` in particular is meaningfully empty on a
+ * captured case, so a blanket write is not a no-op.
+ */
+export const diffCaseDraft = (initial: CaseDraft, draft: CaseDraft): CaseDraftPatch | null => {
+ const content: { expected?: string; input?: string } = {};
+ if (draft.input !== initial.input) content.input = draft.input;
+ if (draft.expected !== initial.expected) content.expected = draft.expected;
+
+ const patch: CaseDraftPatch = {};
+ if (Object.keys(content).length > 0) patch.content = content;
+ if (draft.criteria !== initial.criteria) patch.evalConfig = { criteria: draft.criteria };
+
+ return Object.keys(patch).length > 0 ? patch : null;
+};
+
+/**
+ * Edit state for a case definition: the values being typed, and what to send.
+ *
+ * `initial` is re-read on every entry into edit mode rather than held from
+ * mount, so reopening the editor after a save starts from what was saved.
+ */
+export const useCaseDraft = (initial: CaseDraft) => {
+ const [editing, setEditing] = useState(false);
+ const [draft, setDraft] = useState<CaseDraft>(initial);
+
+ const start = useCallback(() => {
+ setDraft(initial);
+ setEditing(true);
+ }, [initial]);
+
+ const cancel = useCallback(() => setEditing(false), []);
+
+ const patch = useMemo(() => diffCaseDraft(initial, draft), [initial, draft]);
+
+ return {
+ cancel,
+ draft,
+ editing,
+ patch,
+ setDraft: (next: Partial<CaseDraft>) => setDraft((prev) => ({ ...prev, ...next })),
+ start,
+ stop: () => setEditing(false),
+ };
+};
diff --git a/src/routes/(main)/eval/index.tsx b/src/routes/(main)/eval/index.tsx
index df1a1acdcf6..73b7b427ec5 100644
--- a/src/routes/(main)/eval/index.tsx
+++ b/src/routes/(main)/eval/index.tsx
@@ -3,11 +3,12 @@
import { Empty, Flexbox, Skeleton } from '@lobehub/ui';
import { Button, Text } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar } from 'antd-style';
-import { FlaskConical, Plus } from 'lucide-react';
+import { Database, FlaskConical, Plus } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import AsyncBoundary from '@/components/AsyncBoundary';
+import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
import { useEvalStore } from '@/store/eval';
import BenchmarkCard from './features/BenchmarkCard';
@@ -25,6 +26,37 @@ const styles = createStaticStyles(({ css }) => ({
grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
gap: 20px;
`,
+ datasetRow: css`
+ display: flex;
+ gap: 12px;
+ align-items: center;
+
+ padding-block: 14px;
+ padding-inline: 16px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadiusLG};
+
+ color: inherit;
+ text-decoration: none;
+
+ transition: border-color 0.15s ease;
+
+ &:hover {
+ border-color: ${cssVar.colorBorder};
+ }
+ `,
+ datasetIcon: css`
+ display: flex;
+ flex: none;
+ align-items: center;
+ justify-content: center;
+
+ width: 32px;
+ height: 32px;
+ border-radius: 10px;
+
+ background: ${cssVar.colorFillTertiary};
+ `,
skeletonCard: css`
padding: 20px;
border: 1px solid ${cssVar.colorBorderSecondary};
@@ -60,7 +92,9 @@ const EvalOverview = memo(() => {
const { t } = useTranslation('eval');
const benchmarkList = useEvalStore((s) => s.benchmarkList);
const useFetchBenchmarks = useEvalStore((s) => s.useFetchBenchmarks);
+ const useFetchAllDatasets = useEvalStore((s) => s.useFetchAllDatasets);
const { data, isLoading, error, mutate } = useFetchBenchmarks();
+ const { data: allDatasets } = useFetchAllDatasets();
const experimentList = useEvalStore((s) => s.experimentList);
const useFetchExperiments = useEvalStore((s) => s.useFetchExperiments);
@@ -187,6 +221,49 @@ const EvalOverview = memo(() => {
</div>
</AsyncBoundary>
</Flexbox>
+
+ {/* Every dataset, benchmark-owned or not. A dataset need not belong to a
+ benchmark, and every other listing is benchmark-scoped, so this is the
+ only place all of them are visible. */}
+ <Flexbox gap={16}>
+ <Text as={'h2'} style={{ fontSize: 18, fontWeight: 600, margin: 0 }}>
+ {t('overview.sections.datasets.title')}
+ </Text>
+ {allDatasets && allDatasets.length > 0 ? (
+ <div className={styles.grid}>
+ {allDatasets.map(
+ (dataset: {
+ benchmarkId?: string | null;
+ description?: string | null;
+ id: string;
+ name: string;
+ }) => (
+ <WorkspaceLink
+ className={styles.datasetRow}
+ key={dataset.id}
+ to={`/eval/datasets/${dataset.id}`}
+ >
+ <div className={styles.datasetIcon}>
+ <Database size={16} style={{ color: cssVar.colorTextSecondary }} />
+ </div>
+ <Flexbox gap={2} style={{ minWidth: 0 }}>
+ <Text ellipsis weight={500}>
+ {dataset.name}
+ </Text>
+ <Text ellipsis fontSize={12} type="secondary">
+ {dataset.description || t('overview.sections.datasets.noBenchmark')}
+ </Text>
+ </Flexbox>
+ </WorkspaceLink>
+ ),
+ )}
+ </div>
+ ) : (
+ <Text fontSize={12} type="secondary">
+ {t('overview.sections.datasets.empty')}
+ </Text>
+ )}
+ </Flexbox>
</Flexbox>
);
});
diff --git a/src/services/agentEval.ts b/src/services/agentEval.ts
index 9dc5309f361..603a49ebb51 100644
--- a/src/services/agentEval.ts
+++ b/src/services/agentEval.ts
@@ -75,6 +75,11 @@ class AgentEvalService {
return lambdaClient.agentEval.listDatasets.query({ benchmarkId });
}
+ /** Every dataset, whether or not it belongs to a benchmark. */
+ async listAllDatasets() {
+ return lambdaClient.agentEval.listDatasets.query({});
+ }
+
async getDataset(id: string) {
return lambdaClient.agentEval.getDataset.query({ id });
}
@@ -130,6 +135,10 @@ class AgentEvalService {
}
// ============ Test Case ============
+ async getTestCase(id: string) {
+ return lambdaClient.agentEval.getTestCase.query({ id });
+ }
+
async listTestCases(params: { datasetId: string; limit?: number; offset?: number }) {
return lambdaClient.agentEval.listTestCases.query(params);
}
@@ -157,9 +166,9 @@ class AgentEvalService {
content?: {
category?: string;
expected?: string;
- input: string;
+ input?: string;
};
- evalConfig?: { judgePrompt?: string } | null;
+ evalConfig?: { criteria?: string; judgePrompt?: string } | null;
evalMode?: RubricType | null;
metadata?: Record<string, unknown>;
sortOrder?: number;
diff --git a/src/spa/router/desktopRouter.shared.tsx b/src/spa/router/desktopRouter.shared.tsx
index f43cda4b236..ef91a49c267 100644
--- a/src/spa/router/desktopRouter.shared.tsx
+++ b/src/spa/router/desktopRouter.shared.tsx
@@ -832,6 +832,25 @@ export const sharedMainAreaChildren: RouteObject[] = [
),
path: 'experiments/:experimentId',
},
+ // A dataset and a case are addressable on their own — a dataset need
+ // not belong to a benchmark, so a benchmark id cannot be part of
+ // their canonical path. They live in the home group to keep the eval
+ // workspace sidebar; the bench group's sidebar is benchmark-scoped
+ // and has nothing to show for a dataset that belongs to none.
+ {
+ element: dynamicElement(
+ () => import('@/routes/(main)/eval/datasets/[datasetId]'),
+ 'Desktop > Eval > Dataset Detail',
+ ),
+ path: 'datasets/:datasetId',
+ },
+ {
+ element: dynamicElement(
+ () => import('@/routes/(main)/eval/cases/[caseId]'),
+ 'Desktop > Eval > Test Case Detail',
+ ),
+ path: 'cases/:caseId',
+ },
],
element: dynamicElement(
() => import('@/routes/(main)/eval/(home)/_layout'),
@@ -870,9 +889,11 @@ export const sharedMainAreaChildren: RouteObject[] = [
path: 'runs/:runId',
},
{
+ // Legacy shape, kept so existing links still resolve; it redirects
+ // to the benchmark-free `/eval/datasets/:datasetId`.
element: dynamicElement(
() => import('@/routes/(main)/eval/bench/[benchmarkId]/datasets/[datasetId]'),
- 'Desktop > Eval > Dataset Detail',
+ 'Desktop > Eval > Dataset Detail (legacy redirect)',
),
path: 'datasets/:datasetId',
},
diff --git a/src/store/eval/slices/dataset/action.ts b/src/store/eval/slices/dataset/action.ts
index f0b8915c85e..32fb048ad7b 100644
--- a/src/store/eval/slices/dataset/action.ts
+++ b/src/store/eval/slices/dataset/action.ts
@@ -66,6 +66,13 @@ export class DatasetActionImpl {
},
);
+ /**
+ * Every dataset. Without this a dataset is only reachable through its
+ * benchmark, so one belonging to none could be created but never found.
+ */
+ useFetchAllDatasets = (): SWRResponse =>
+ useClientDataSWR(evalKeys.datasetsAll(), () => agentEvalService.listAllDatasets());
+
internal_dispatchDatasetDetail = (payload: DatasetDetailDispatch): void => {
const currentMap = this.#get().datasetDetailMap;
const nextMap = datasetDetailReducer(currentMap, payload);
diff --git a/src/store/eval/slices/testCase/action.ts b/src/store/eval/slices/testCase/action.ts
index a03c7a5ed89..7e194d3368f 100644
--- a/src/store/eval/slices/testCase/action.ts
+++ b/src/store/eval/slices/testCase/action.ts
@@ -21,6 +21,10 @@ export class TestCaseActionImpl {
this.#get = get;
}
+ getTestCaseById = (id: string): any | undefined => {
+ return this.#get().testCaseDetailCache[id];
+ };
+
getTestCasesByDatasetId = (datasetId: string): any[] => {
return this.#get().testCasesCache[datasetId]?.data || [];
};
@@ -39,6 +43,46 @@ export class TestCaseActionImpl {
);
};
+ /**
+ * Edit a case definition in place. The dataset list is revalidated too: its
+ * rows render the same input and expected answer, so leaving it alone shows a
+ * stale row the moment you navigate back.
+ */
+ updateTestCase = async (
+ id: string,
+ datasetId: string,
+ data: {
+ content?: { expected?: string; input?: string };
+ evalConfig?: { criteria?: string };
+ },
+ ): Promise<void> => {
+ await agentEvalService.updateTestCase({ id, ...data });
+ await mutate(evalKeys.testCaseDetail(id));
+ await this.refreshTestCases(datasetId);
+ };
+
+ /**
+ * A test case on its own, not as a row of a dataset page — the case detail
+ * route is reachable directly, so it cannot rely on the list being loaded.
+ */
+ useFetchTestCase = (id?: string): SWRResponse => {
+ return useClientDataSWR(
+ id ? evalKeys.testCaseDetail(id) : null,
+ () => agentEvalService.getTestCase(id!),
+ {
+ onSuccess: (data: any) => {
+ this.#set(
+ (state) => ({
+ testCaseDetailCache: { ...state.testCaseDetailCache, [data.id]: data },
+ }),
+ false,
+ `useFetchTestCase/success/${id}`,
+ );
+ },
+ },
+ );
+ };
+
useFetchTestCases = (params: {
datasetId: string;
limit?: number;
diff --git a/src/store/eval/slices/testCase/initialState.ts b/src/store/eval/slices/testCase/initialState.ts
index fe99408dc84..77fc6fdd04b 100644
--- a/src/store/eval/slices/testCase/initialState.ts
+++ b/src/store/eval/slices/testCase/initialState.ts
@@ -7,10 +7,13 @@ interface TestCaseCacheItem {
export interface TestCaseSliceState {
// Map to cache test cases by datasetId
loadingTestCaseIds: string[];
+ /** A single test case addressed by its own id, for the case detail page. */
+ testCaseDetailCache: Record<string, any>;
testCasesCache: Record<string, TestCaseCacheItem>;
}
export const testCaseInitialState: TestCaseSliceState = {
loadingTestCaseIds: [],
+ testCaseDetailCache: {},
testCasesCache: {},
};