feat: 新增报告协作页,并强化 Deep Research 运行诊断与报告兜底

支持浏览器侧素材快照撰写、拒绝报告读时修复、Mermaid PNG 导出与 Word 导出加固。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
董宏凯andCursor committed 2026-09-03 11:16:50 +08:00
1 parent 65d6b61d5d
commit f109a95535
65 files changed
+10342 -245

No files matched your search

@@ -1 +1,2 @@
export * from "./plugins";
export * from "./mermaid-png-download";
@@ -0,0 +1,56 @@
import { useEffect, type RefObject } from "react";
import { toast } from "sonner";
import { downloadSvgElementAsPng } from "@/core/utils/mermaid";
function findStreamdownMermaidDownloadBlock(target: EventTarget | null): HTMLElement | null {
if (!(target instanceof Element)) return null;
const button = target.closest("button");
if (!(button instanceof HTMLButtonElement)) return null;
if (button.getAttribute("title") !== "Download file") return null;
const block = button.closest('[data-streamdown="mermaid-block"]');
return block instanceof HTMLElement ? block : null;
}
function findRenderedMermaidChartSvg(block: HTMLElement): SVGSVGElement | null {
const fromChart = block.querySelector('[aria-label="Mermaid chart"] svg, [role="img"] svg');
if (fromChart instanceof SVGSVGElement && !fromChart.closest("button")) {
return fromChart;
}
for (const svg of block.querySelectorAll("svg")) {
if (svg instanceof SVGSVGElement && !svg.closest("button")) {
return svg;
}
}
return null;
}
/** Intercept Streamdown mermaid download buttons and save a PNG of the chart. */
export function useStreamdownMermaidPngDownload(rootRef: RefObject<HTMLElement | null>) {
useEffect(() => {
const onClickCapture = (event: MouseEvent) => {
const root = rootRef.current;
if (!root || !root.contains(event.target as Node)) return;
const block = findStreamdownMermaidDownloadBlock(event.target);
if (!block) return;
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
const svg = findRenderedMermaidChartSvg(block);
if (!svg) {
toast.error("流程图尚未渲染完成,请稍后再下载");
return;
}
void downloadSvgElementAsPng(svg, "flowchart.png").catch((error) => {
console.error("Failed to download mermaid image:", error);
toast.error(error instanceof Error ? error.message : "下载流程图失败");
});
};
document.addEventListener("click", onClickCapture, true);
return () => document.removeEventListener("click", onClickCapture, true);
}, [rootRef]);
}