diff --git a/sdk/app/services/paper/agent.py b/sdk/app/services/paper/agent.py index eea4cc8..6af8a24 100644 --- a/sdk/app/services/paper/agent.py +++ b/sdk/app/services/paper/agent.py @@ -249,17 +249,36 @@ async def run_writing_loop(db, paper_id: str, session_id: str) -> None: await _write_message(db, session_id, blocks=[_text_block(f"撰写失败:{exc}")], text="撰写失败") +def _build_full_markdown(paper: dict[str, Any]) -> str: + """把 full_markdown + 文末参考文献列表 + disclaimer 拼成完整 markdown(供渲染 HTML 与落盘)。""" + md = paper.get("full_markdown", "") + refs = paper.get("references") or [] + if refs: + md += "\n\n## 参考文献\n\n" + "\n".join( + f"[{r.get('n', '')}] {r.get('text', '')}".strip() for r in refs + ) + disclaimer = (paper.get("disclaimer") or "").strip() + if disclaimer: + md += f"\n\n> {disclaimer}" + return md + + async def _artifact_message(db, session_id: str, paper: dict[str, Any], nl: str) -> list[dict[str, Any]]: from ...routers.docgen import insert_artifact # 惰性导入 + from ..docgen import templating # 惰性导入:复用 docgen markdown→HTML 渲染链 refs = paper.get("references") or [] + title = paper.get("title", "") + full_md = _build_full_markdown(paper) + html, css = templating.render_html(full_md, title=title, key="document") artifact_id = await insert_artifact( - db, session_id=session_id, title=paper.get("title", ""), - markdown=paper.get("full_markdown", ""), template_name="论文", + db, session_id=session_id, title=title, + markdown=full_md, template_name="论文", template_key="document", + template_css=css, html=html, ) blocks = [ _text_block(nl), - {"type": "artifact", "artifact_id": artifact_id, "title": paper.get("title", ""), + {"type": "artifact", "artifact_id": artifact_id, "title": title, "template_name": "论文", "status": "done", "paper_id": paper.get("paper_id", ""), "citation_count": len(refs)}, ]