// Review Inline: renders AI review suggestions inline in a diff view const ReviewInline = { suggestions: [], init(diffContainerId, suggestionsContainerId) { this.diffContainer = document.getElementById(diffContainerId); this.suggestionsContainer = document.getElementById(suggestionsContainerId); this.suggestions = []; }, // Add a suggestion to the collection addSuggestion(suggestion) { this.suggestions.push(suggestion); }, // Render all collected suggestions inline in the diff renderInline() { if (!this.diffContainer) return; this.suggestions.forEach((s, index) => { DiffViewer.insertSuggestion( s.file, s.line, s.side || 'right', s.severity || 'info', s.content || '', `suggestion-${index}` ); }); }, // Render a single suggestion card (for the card-based view) renderSuggestionCard(suggestion) { const severityStyles = { critical: { border: 'border-l-4 border-red-500', bg: 'bg-red-50', badge: 'bg-red-100 text-red-800', icon: '🔴', label: '严重', }, warning: { border: 'border-l-4 border-yellow-500', bg: 'bg-yellow-50', badge: 'bg-yellow-100 text-yellow-800', icon: '🟡', label: '建议', }, info: { border: 'border-l-4 border-green-500', bg: 'bg-green-50', badge: 'bg-green-100 text-green-800', icon: '🟢', label: '提示', }, }; const style = severityStyles[suggestion.severity] || severityStyles.info; return `
${style.icon} ${style.label} ${suggestion.file ? `${suggestion.file}` : ''} ${suggestion.line ? `行 ${suggestion.line}` : ''}
${typeof renderMarkdown === 'function' ? renderMarkdown(suggestion.content || '') : (suggestion.content || '')}
${suggestion.code_example ? `
${this._escapeHtml(suggestion.code_example)}
` : ''}
`; }, // Render file review section renderFileReview(fileReview) { const severityOrder = { critical: 0, warning: 1, info: 2 }; const suggestions = (fileReview.suggestions || []).sort((a, b) => (severityOrder[a.severity] || 2) - (severityOrder[b.severity] || 2) ); const maxSeverity = suggestions.length > 0 ? suggestions[0].severity : 'info'; const severityColors = { critical: 'border-red-500', warning: 'border-yellow-500', info: 'border-green-500', }; let html = `

${fileReview.filename || ''}

${fileReview.summary ? `

${fileReview.summary}

` : ''}
`; suggestions.forEach(s => { html += this.renderSuggestionCard(s); }); html += `
`; return html; }, // Render overall summary renderSummary(summary) { if (!summary) return ''; return `

整体评估

${summary}
`; }, _escapeHtml(text) { const div = document.createElement('div'); div.textContent = text; return div.innerHTML; } }; window.ReviewInline = ReviewInline;