fix: 结构化渲染审查总结,替换原始JSON显示

- 后端发送结构化数据(score/overall/findings/recommendations)而非格式化文本
- 增加灵活JSON解析,兼容LLM返回recommendations为数组的情况
- 前端渲染带样式的审查总结:评分徽章(颜色分级)、分区展示
- 两个页面统一处理:repo页面的内联审查和review页面的完整审查
This commit is contained in:
2026-06-20 22:15:00 +08:00
parent 292588ef23
commit 37aa9c0a33
3 changed files with 114 additions and 22 deletions
+34 -1
View File
@@ -427,6 +427,34 @@
}
}
// ── Utilities ────────────────────────────────────────────────
function escapeHtml(text) {
if (!text) return '';
return String(text)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
function renderSummaryHtml(data) {
let html = '<div class="space-y-3">';
const score = data.score || 0;
const scoreColor = score >= 7 ? 'bg-green-100 text-green-800' : score >= 4 ? 'bg-yellow-100 text-yellow-800' : 'bg-red-100 text-red-800';
html += `<div class="flex items-center gap-2"><span class="text-sm font-medium text-gray-600">整体评分</span><span class="px-2 py-0.5 rounded-full text-xs font-semibold ${scoreColor}">${score}/10</span></div>`;
if (data.overall) {
html += `<div><span class="text-sm font-medium text-gray-600">总体评价</span><p class="mt-1 text-sm text-gray-800">${escapeHtml(data.overall)}</p></div>`;
}
if (data.findings) {
html += `<div><span class="text-sm font-medium text-gray-600">主要发现</span><p class="mt-1 text-sm text-gray-800">${escapeHtml(data.findings)}</p></div>`;
}
if (data.recommendations) {
html += `<div><span class="text-sm font-medium text-gray-600">改进建议</span><p class="mt-1 text-sm text-gray-800">${escapeHtml(data.recommendations)}</p></div>`;
}
html += '</div>';
return html;
}
// ── Inline AI Review ────────────────────────────────────────
let inlineReviewSSE = null;
@@ -476,7 +504,12 @@
inlineSuggestions.push(data);
},
summary(data) {
document.getElementById('review-summary-content').innerHTML = renderInlineMarkdown(data.content || '');
const el = document.getElementById('review-summary-content');
if (data.score !== undefined) {
el.innerHTML = renderSummaryHtml(data);
} else {
el.innerHTML = renderInlineMarkdown(data.content || '');
}
document.getElementById('review-progress-bar').style.width = '90%';
},
done() {