## Webhook 通知(S3-1)
- settings.py: 增加 AGENTEVAL_WEBHOOK_URL / AGENTEVAL_WEBHOOK_SECRET
- utils/webhook.py: send_run_webhook(),非阻断,任何异常仅 warning log
- runs.py: run 完成后自动触发 webhook(payload 含 run_id/status/summary/report_url)
- .env.example: 新增 webhook 配置示例
## OpenClaw Skill HTTP 改造(S3-2)
- plugins/openclaw/agenteval_skill.py: 完全重写
- 改用 HTTP API(POST /api/runs + GET /api/runs/{id} 轮询 + GET /api/reports/{id})
- 移除 subprocess + CLI 依赖
- 轮询等待至 completed/failed,支持配置 poll_interval / timeout
- 返回结构化中文摘要(summary_text),直接可用于 OpenClaw 对话展示
## Markdown 报告导出(S3-3)
- report.py: render_markdown_report() — 完整的 Markdown 表格 + 对话展示
- save_report: 支持 fmt="markdown",输出 .md 文件
- reports.py: GET /api/reports/{run_id}/markdown,Content-Disposition 附件下载
- api.ts: reportsApi.markdownUrl()
- Reports.tsx: 「导出 MD」按钮
## 对比报告(S3-4)
- report.py: generate_compare_report(run_id_1, run_id_2)
- run_a / run_b 汇总 + delta(pass_rate / passed_cases / passed_rules)
- case-level diff,标记 changed 用例
- reports.py: GET /api/reports/compare?run1=&run2=
- api.ts: reportsApi.compare()
- Reports.tsx: 完整对比视图
- Segmented 切换「单次报告」/「对比报告」
- 双 Select(报告 A vs B)+ 对比按钮
- 汇总 delta card(pass_rate 变化 + 变化用例数徽章)
- 用例对比表(通过/失败/改善↑/退步↓)+ 展开规则明细
Co-Authored-By: Claude <noreply@anthropic.com>
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""API routes for evaluation reports."""
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, Response
|
|
from sqlmodel import Session
|
|
|
|
from agenteval.evaluation.report import (
|
|
generate_compare_report,
|
|
generate_report,
|
|
render_html_report,
|
|
render_json_report,
|
|
render_markdown_report,
|
|
)
|
|
from agenteval.storage.repository import RunRepository
|
|
from agenteval.web.deps import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/compare")
|
|
def get_compare_report(
|
|
run1: str = Query(..., description="First run ID"),
|
|
run2: str = Query(..., description="Second run ID"),
|
|
session: Session = Depends(get_db),
|
|
) -> dict:
|
|
repo = RunRepository(session)
|
|
if not repo.get(run1):
|
|
raise HTTPException(status_code=404, detail=f"run not found: {run1}")
|
|
if not repo.get(run2):
|
|
raise HTTPException(status_code=404, detail=f"run not found: {run2}")
|
|
return generate_compare_report(run1, run2, session)
|
|
|
|
|
|
@router.get("/{run_id}")
|
|
def get_report(run_id: str, session: Session = Depends(get_db)) -> dict:
|
|
run = RunRepository(session).get(run_id)
|
|
if not run:
|
|
raise HTTPException(status_code=404, detail="run not found")
|
|
return generate_report(run_id, session)
|
|
|
|
|
|
@router.get("/{run_id}/html")
|
|
def get_html_report(run_id: str, session: Session = Depends(get_db)) -> Response:
|
|
run = RunRepository(session).get(run_id)
|
|
if not run:
|
|
raise HTTPException(status_code=404, detail="run not found")
|
|
html = render_html_report(run_id, session)
|
|
return Response(content=html, media_type="text/html")
|
|
|
|
|
|
@router.get("/{run_id}/json")
|
|
def get_json_report(run_id: str, session: Session = Depends(get_db)) -> Response:
|
|
run = RunRepository(session).get(run_id)
|
|
if not run:
|
|
raise HTTPException(status_code=404, detail="run not found")
|
|
json_text = render_json_report(run_id, session)
|
|
return Response(content=json_text, media_type="application/json")
|
|
|
|
|
|
@router.get("/{run_id}/markdown")
|
|
def get_markdown_report(run_id: str, session: Session = Depends(get_db)) -> Response:
|
|
run = RunRepository(session).get(run_id)
|
|
if not run:
|
|
raise HTTPException(status_code=404, detail="run not found")
|
|
md = render_markdown_report(run_id, session)
|
|
return Response(
|
|
content=md,
|
|
media_type="text/markdown; charset=utf-8",
|
|
headers={"Content-Disposition": f'attachment; filename="report-{run_id}.md"'},
|
|
)
|