From 2e5372cf908708d473198e6155b10c0d5d80f5d2 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 8 Oct 2026 14:54:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(paper):=20=E8=AE=BA=E6=96=87=E4=BA=A7?= =?UTF-8?q?=E7=89=A9=E6=B8=B2=E6=9F=93=E4=B8=BA=20HTML=20+=20=E6=96=87?= =?UTF-8?q?=E6=9C=AB=E8=BF=BD=E5=8A=A0=E5=8F=82=E8=80=83=E6=96=87=E7=8C=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8/disclaimer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/app/services/paper/agent.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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)}, ]