修复:DSH 自主查询、图片直显与报告稳定性
允许 Agent 在循环中查目录、修正查询和提问,保留实时权限检查及模型原始回答。 统一相同查询证据与图表资源;排名补齐阶段指标,修正 OR 重量筛选,并限制模型明细输入。 增加运行恢复、图表自适应坐标轴与两位小数,修复报告主图选择、重复图及边缘标签。 验证:独立副本通过 162 项 Python、73 项前端及 21 项后端测试,前端构建通过。 线上已用原 8 题复测,并追加两轮双期对比;TOP100 与组合筛选分别核对 100 行和 20 行。
This commit is contained in:
+27
-4
@@ -3,11 +3,27 @@ import { tableTextAlignment } from './tableTextAlignment';
|
||||
import { sanitizeAnalysisDisplayText } from './analysisDisplayText';
|
||||
import { analysisEvidenceParts } from './analysisEvidenceRefs';
|
||||
|
||||
function inlineMarkdown(value: string, keyPrefix = 'inline', evidenceLabels?: Record<string, string>, evidencePrefix = ''): ReactNode[] {
|
||||
function inlineMarkdown(value: string, keyPrefix = 'inline', evidenceLabels?: Record<string, string>, evidencePrefix = '', imageTargets?: Record<string, string>, renderImage?: (alt: string, source: string, key: string) => ReactNode): ReactNode[] {
|
||||
const references = (part: string, key: string): ReactNode => !evidenceLabels ? part : analysisEvidenceParts(part).map(({ text, ref }, index) => {
|
||||
return ref && Object.hasOwn(evidenceLabels, ref) ? <a className="analysis-evidence-ref" key={`${key}-${index}`} href={`#${evidencePrefix}${ref}`} title={ref}>{evidenceLabels[ref]}</a> : text;
|
||||
});
|
||||
return value.split(/(\*\*.+?\*\*|`[^`]+`)/g).map((part, index) => {
|
||||
return value.split(/(`[^`]+`|!\[[^\]\n]*\]\([^\n]*?\)|\*\*.+?\*\*)/g).map((part, index) => {
|
||||
const image = part.match(/^!\[([^\]\n]*)\]\(([^\n]*)\)$/);
|
||||
if (image) {
|
||||
const rendered = renderImage?.(image[1], image[2].trim(), `${keyPrefix}-${index}`);
|
||||
if (rendered != null) return rendered;
|
||||
const target = imageTargets?.[image[2].trim()];
|
||||
if (target) return <a key={`${keyPrefix}-${index}`} href={`#${encodeURIComponent(target)}`} onClick={event => {
|
||||
event.preventDefault();
|
||||
const article = event.currentTarget.closest('.agent-turn');
|
||||
const chart = Array.from(article?.querySelectorAll<HTMLElement>('[data-analysis-visual-id]') || []).find(node => node.dataset.analysisVisualId === target);
|
||||
const transcript = article?.closest('.agent-transcript');
|
||||
if (chart && transcript) transcript.scrollTop += chart.getBoundingClientRect().top - transcript.getBoundingClientRect().top - 12;
|
||||
}}>{image[1] || '图表'}</a>;
|
||||
// 图片语法是展示指令,不是业务正文。资源由平台图表组件提供,
|
||||
// 未绑定资源只显示原始标题;不加载模型编造的 URL,也不改写原文。
|
||||
return <span className="ai-markdown-image-caption" role="img" aria-label={image[1] || '图表'} key={`${keyPrefix}-${index}`}>{image[1] || '图表'}</span>;
|
||||
}
|
||||
if (part.startsWith('**') && part.endsWith('**') && part.length >= 4) {
|
||||
return <strong key={`${keyPrefix}-${index}`}>{references(part.slice(2, -2), `${keyPrefix}-${index}`)}</strong>;
|
||||
}
|
||||
@@ -37,6 +53,7 @@ function isBlockStart(lines: string[], index: number): boolean {
|
||||
const line = lines[index];
|
||||
return /^\s*#{1,6}\s+/.test(line)
|
||||
|| /^\s*```/.test(line)
|
||||
|| /^\s*!\[[^\]\n]*\]\([^\n]*?\)\s*$/.test(line)
|
||||
|| isRule(line) || /^\s{0,3}>/.test(line)
|
||||
|| /^\s*(?:[-*+]\s+|\d+[.)]\s+)/.test(line)
|
||||
|| isTableStart(lines, index);
|
||||
@@ -62,8 +79,8 @@ function readingSentences(value: string, boundaries = '。!?;'): string[]
|
||||
}
|
||||
|
||||
/** Renders the small Markdown subset used by analysis answers with React text nodes only. */
|
||||
export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix, layout, preserveSource = false }: { content: string; className?: string; evidenceLabels?: Record<string, string>; evidencePrefix?: string; layout?: 'conclusions' | 'sections'; preserveSource?: boolean }) {
|
||||
const inline = (value: string, key: string) => inlineMarkdown(value, key, evidenceLabels, evidencePrefix);
|
||||
export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix, imageTargets, renderImage, layout, preserveSource = false }: { content: string; className?: string; evidenceLabels?: Record<string, string>; evidencePrefix?: string; imageTargets?: Record<string, string>; renderImage?: (alt: string, source: string, key: string) => ReactNode; layout?: 'conclusions' | 'sections'; preserveSource?: boolean }) {
|
||||
const inline = (value: string, key: string) => inlineMarkdown(value, key, evidenceLabels, evidencePrefix, imageTargets, renderImage);
|
||||
const lines = (preserveSource ? content : sanitizeAnalysisDisplayText(content)).replaceAll('\r\n', '\n').replaceAll('\r', '\n').split('\n');
|
||||
const blocks: ReactNode[] = [];
|
||||
let index = 0;
|
||||
@@ -132,6 +149,12 @@ export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/^\s*!\[[^\]\n]*\]\([^\n]*?\)\s*$/.test(line)) {
|
||||
blocks.push(<div className="ai-markdown-image-block" key={`image-${blocks.length}`}>{inline(line.trim(), `image-${blocks.length}`)}</div>);
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
const heading = line.match(/^\s*(#{1,6})\s+(.+?)\s*#*\s*$/);
|
||||
if (heading) {
|
||||
const level = heading[1].length;
|
||||
|
||||
Reference in New Issue
Block a user