fix(roundtable-share): 修复分享拿不到总控结论/各席位交付 + 分享总结报告与大屏多页

排查发现后台作业把结果写进 step2.runs[activeRun],而顶层 step2 残留前台 seed
的陈旧气泡(无交付、无结论)。_result_sections 旧逻辑「顶层为空才回退 run」因顶层
非空而永不回退,导致分享页 consensus 与 seat_deliveries 为空。改为优先读活动 run
(与前端 hydrate 一致),已有分享链接无需重建即生效。

同时把第三步另外两个产物纳入分享:
- 方案总结报告(step3.summaryReport.md,Markdown 内联渲染)
- 大屏多页(step3.dashboardJson,用应用内 React 大屏 DashboardApp 渲染,新增
  /roundtable-share/:code/dashboard 路由,与应用渲染/新窗口打开同源)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-15 12:57:33 +08:00
1 parent 49101ef0e8
commit fbd237531e
4 files changed
+153 -53

No files matched your search

@@ -115,10 +115,17 @@ class PublicDraftShareSnapshotResponse(BaseModel):
seat_deliveries: list[SeatDeliveryItem] = Field(default_factory=list)
# The Step 3「结果绘制」report — a self-contained HTML document. Empty when the
# shared draft never reached / generated a result report.
html: str = Field(default="", description="Self-contained Step 3 result report HTML")
html: str = Field(default="", description="Self-contained Step 3 result report HTML (经典 HTML 看板)")
summary: str | None = Field(default=None, description="The report's closing one-liner")
generated_at: str | None = Field(default=None, description="When the report was generated (ISO-8601)")
has_report: bool = Field(default=False, description="Whether a Step 3 report exists")
has_report: bool = Field(default=False, description="Whether a Step 3 HTML report exists")
# Step 3「方案总结报告」—— the Markdown report from roundtable-summary (step3.summaryReport.md).
summary_report_md: str = Field(default="", description="Step 3 Markdown 方案总结报告")
has_summary_report: bool = Field(default=False, description="Whether a Step 3 Markdown summary report exists")
# Step 3「大屏多页」(模式二) —— structured dashboard data (step3.dashboardJson); the
# frontend renders it to self-contained HTML via renderDashboardHtml at view time.
dashboard_json: str | None = Field(default=None, description="Step 3 大屏多页 structured data (report-json)")
has_dashboard: bool = Field(default=False, description="Whether a Step 3 大屏多页 dashboard exists")
created_at: str | None = Field(default=None, description="When the share was created (ISO-8601)")
@@ -259,29 +266,32 @@ async def import_share(
def _result_sections(draft: dict) -> tuple[str, list[dict[str, str]]]:
"""Derive (总控最终结论, 各席位最终交付) from a draft's Step 2 snapshot.
Mirrors the frontend `Step3Panel`: the consensus is `step2.lastLeaderContent`
and each seat delivery is a Step 2 dialogue bubble tagged
``confidence == "子智能体交付"``. Falls back to the active run's snapshot when
the top-level Step 2 fields are empty (multi-run drafts).
Mirrors the frontend draft hydration (`RoundtablePlanningPage.normalizeStep2Runs`):
when the draft has ``runs[]`` the rendered content is the **active run**
(``activeRunId``), NOT the top-level ``step2`` fields — those can be a stale
foreground seed (e.g. only the 系统消息/开场 2 条气泡) left over after a later
background job wrote its results into ``runs[]``. Reading the top level there
yields an empty consensus and no deliveries (the reported bug). Only drafts
with no ``runs[]`` (legacy/foreground-only) fall back to the top-level fields.
The consensus is ``lastLeaderContent`` and each seat delivery is a dialogue
bubble tagged ``confidence == "子智能体交付"``.
"""
step2 = draft.get("step2") if isinstance(draft.get("step2"), dict) else {}
step2 = step2 or {}
consensus = step2.get("lastLeaderContent") or ""
dialogues = step2.get("step2RoundtableDialogues")
runs = [r for r in step2.get("runs", []) if isinstance(r, dict)] if isinstance(step2.get("runs"), list) else []
if runs:
active_id = step2.get("activeRunId")
source = next((r for r in runs if r.get("id") == active_id), None) or runs[0]
else:
source = step2
consensus = source.get("lastLeaderContent") or ""
dialogues = source.get("step2RoundtableDialogues")
if not isinstance(dialogues, list):
dialogues = []
# Multi-run drafts keep the freshest content on the active run; use it when
# the top-level snapshot carries nothing.
if not consensus and not dialogues and isinstance(step2.get("runs"), list):
runs = [r for r in step2["runs"] if isinstance(r, dict)]
active_id = step2.get("activeRunId")
active = next((r for r in runs if r.get("id") == active_id), None) or (runs[0] if runs else None)
if active:
consensus = active.get("lastLeaderContent") or ""
d = active.get("step2RoundtableDialogues")
dialogues = d if isinstance(d, list) else []
seat_deliveries = [
{"sender": str(d.get("sender") or ""), "content": str(d.get("content") or "")}
for d in dialogues
@@ -313,8 +323,14 @@ async def get_public_draft_share_snapshot(
if draft is None:
raise HTTPException(status_code=404, detail="The shared draft no longer exists")
step3 = draft.get("step3") if isinstance(draft.get("step3"), dict) else None
html = (step3 or {}).get("html") or ""
step3 = draft.get("step3") if isinstance(draft.get("step3"), dict) else {}
step3 = step3 or {}
html = step3.get("html") or ""
# 方案总结报告(Markdown,模式:roundtable-summary)—— 嵌在 step3.summaryReport.md。
summary_report = step3.get("summaryReport") if isinstance(step3.get("summaryReport"), dict) else {}
summary_report_md = (summary_report or {}).get("md") or ""
# 大屏多页(模式二)—— 只存结构化数据 step3.dashboardJson,前端按主题渲染成自包含 HTML。
dashboard_json = step3.get("dashboardJson") or None
consensus_text, seat_deliveries = _result_sections(draft)
return PublicDraftShareSnapshotResponse(
share_code=share_code,
@@ -323,8 +339,12 @@ async def get_public_draft_share_snapshot(
consensus_text=consensus_text,
seat_deliveries=[SeatDeliveryItem(**s) for s in seat_deliveries],
html=html,
summary=(step3 or {}).get("summary"),
generated_at=(step3 or {}).get("generatedAt"),
summary=step3.get("summary"),
generated_at=step3.get("generatedAt"),
has_report=bool(html),
summary_report_md=summary_report_md,
has_summary_report=bool(summary_report_md),
dashboard_json=dashboard_json,
has_dashboard=bool(dashboard_json),
created_at=share.get("created_at"),
)