feat: 报告结构支持检索方向/来源与智能新增,并修复协助卡停轮与宿主跳转

为深度研究报告结构增加检索方向与技能来源、对话式智能新增页与详情排版;澄清中间件在 after_model 可靠结束本轮,避免弱模型出卡后继续生成;任务按钮补充 host 跳转与相关深链能力。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
董宏凯andCursor committed 2026-08-22 17:46:06 +08:00
1 parent a5a9c952e8
commit 51afebb394
67 files changed
+4511 -699

No files matched your search

@@ -6,9 +6,12 @@ row; picking a card applies ``content`` to the research config's
Routes (prefix ``/api/report-structures``):
GET "" list (optional ``enabled`` / ``title`` filters)
POST "" create (title / name / content; enabled forced True)
POST "" create (title / name / content / structure_mode /
retrieval_directions / retrieval_skills;
enabled forced True)
GET "/{id}" get one
PUT "/{id}" update title / name / content
PUT "/{id}" update title / name / content / structure_mode /
retrieval_directions / retrieval_skills
PUT "/{id}/enabled" toggle 启用/停用
DELETE "/{id}" delete
@@ -27,6 +30,13 @@ from pydantic import BaseModel, Field
from app.gateway.deps import get_optional_user_from_request
from deerflow.persistence.report_structures import ReportStructureStore
from deerflow.persistence.report_structures.directions import normalize_retrieval_directions
from deerflow.persistence.report_structures.skills import normalize_retrieval_skills
from deerflow.persistence.report_structures.modes import (
DEFAULT_STRUCTURE_MODE,
StructureMode,
normalize_structure_mode,
)
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api/report-structures", tags=["report-structures"])
@@ -40,6 +50,9 @@ class ReportStructureResponse(BaseModel):
title: str
name: str
content: str
structure_mode: StructureMode = DEFAULT_STRUCTURE_MODE
retrieval_directions: list[str] = []
retrieval_skills: list[str] = []
enabled: bool = True
created_by: str | None = None
created_at: str | None = None
@@ -54,12 +67,18 @@ class ReportStructureCreateRequest(BaseModel):
title: str = Field(..., min_length=1, max_length=256)
name: str = Field(default="", max_length=256)
content: str = Field(..., min_length=1, max_length=20_000)
structure_mode: StructureMode = DEFAULT_STRUCTURE_MODE
retrieval_directions: list[str] = Field(default_factory=list)
retrieval_skills: list[str] = Field(default_factory=list)
class ReportStructureUpdateRequest(BaseModel):
title: str | None = Field(default=None, min_length=1, max_length=256)
name: str | None = Field(default=None, max_length=256)
content: str | None = Field(default=None, min_length=1, max_length=20_000)
structure_mode: StructureMode | None = None
retrieval_directions: list[str] | None = None
retrieval_skills: list[str] | None = None
class ReportStructureEnabledRequest(BaseModel):
@@ -69,6 +88,14 @@ class ReportStructureEnabledRequest(BaseModel):
# ── helpers ──────────────────────────────────────────────────────────────
def _to_response(row: dict) -> ReportStructureResponse:
data = dict(row)
data["structure_mode"] = normalize_structure_mode(data.get("structure_mode"))
data["retrieval_directions"] = normalize_retrieval_directions(data.get("retrieval_directions"))
data["retrieval_skills"] = normalize_retrieval_skills(data.get("retrieval_skills"))
return ReportStructureResponse(**data)
def _get_store(request: Request) -> ReportStructureStore:
store = getattr(request.app.state, "report_structure_store", None)
if store is None:
@@ -102,7 +129,7 @@ async def list_report_structures(
needle = title.strip().lower()
if needle:
rows = [r for r in rows if needle in str(r.get("title", "")).lower()]
return ReportStructureListResponse(structures=[ReportStructureResponse(**r) for r in rows])
return ReportStructureListResponse(structures=[_to_response(r) for r in rows])
@router.post("", response_model=ReportStructureResponse, status_code=201)
@@ -114,10 +141,13 @@ async def create_report_structure(request: Request, body: ReportStructureCreateR
"title": body.title.strip(),
"name": body.name.strip(),
"content": body.content.strip(),
"structure_mode": normalize_structure_mode(body.structure_mode),
"retrieval_directions": normalize_retrieval_directions(body.retrieval_directions),
"retrieval_skills": normalize_retrieval_skills(body.retrieval_skills),
"created_by": await _current_username(request),
}
)
return ReportStructureResponse(**row)
return _to_response(row)
@router.get("/{structure_id}", response_model=ReportStructureResponse)
@@ -126,7 +156,7 @@ async def get_report_structure(request: Request, structure_id: str) -> ReportStr
row = await store.get_structure(structure_id)
if row is None:
raise HTTPException(status_code=404, detail="报告结构不存在")
return ReportStructureResponse(**row)
return _to_response(row)
@router.put("/{structure_id}", response_model=ReportStructureResponse)
@@ -141,12 +171,18 @@ async def update_report_structure(
data["name"] = body.name.strip()
if body.content is not None:
data["content"] = body.content.strip()
if body.structure_mode is not None:
data["structure_mode"] = normalize_structure_mode(body.structure_mode)
if body.retrieval_directions is not None:
data["retrieval_directions"] = normalize_retrieval_directions(body.retrieval_directions)
if body.retrieval_skills is not None:
data["retrieval_skills"] = normalize_retrieval_skills(body.retrieval_skills)
if not data:
raise HTTPException(status_code=400, detail="没有需要更新的字段")
row = await store.update_structure(structure_id, data)
if row is None:
raise HTTPException(status_code=404, detail="报告结构不存在")
return ReportStructureResponse(**row)
return _to_response(row)
@router.put("/{structure_id}/enabled", response_model=ReportStructureResponse)
@@ -157,7 +193,7 @@ async def set_report_structure_enabled(
row = await store.set_enabled(structure_id, body.enabled)
if row is None:
raise HTTPException(status_code=404, detail="报告结构不存在")
return ReportStructureResponse(**row)
return _to_response(row)
@router.delete("/{structure_id}", status_code=204)