Render Codex review messages

This commit is contained in:
weishu
2026-05-17 23:11:36 +08:00
parent c5e80e9a66
commit 0e594da84d
11 changed files with 530 additions and 7 deletions
+45 -2
View File
@@ -3,13 +3,13 @@ import type { AppendMessage, AttachmentAdapter, ThreadMessageLike } from '@assis
import { useExternalMessageConverter, useExternalStoreRuntime } from '@assistant-ui/react'
import { safeStringify } from '@hapi/protocol'
import { renderEventLabel } from '@/chat/presentation'
import type { ChatBlock, CliOutputBlock, UsageData } from '@/chat/types'
import type { ChatBlock, CliOutputBlock, CodexReview, UsageData } from '@/chat/types'
import type { AgentEvent, ToolCallBlock } from '@/chat/types'
import type { ToolGroupBlock, VisibleChatBlock } from '@/chat/toolGroups'
import type { AttachmentMetadata, MessageStatus as HappyMessageStatus, Session } from '@/types/api'
export type HappyChatMessageMetadata = {
kind: 'user' | 'assistant' | 'tool' | 'event' | 'cli-output'
kind: 'user' | 'assistant' | 'tool' | 'event' | 'cli-output' | 'codex-review'
status?: HappyMessageStatus
localId?: string | null
originalText?: string
@@ -21,6 +21,29 @@ export type HappyChatMessageMetadata = {
durationMs?: number
usage?: UsageData
model?: string | null
review?: CodexReview
}
function formatCodexReviewText(review: CodexReview): string {
const lines = ['Codex review']
if (review.overallCorrectness) {
lines.push(`Overall: ${review.overallCorrectness}`)
}
if (review.overallExplanation) {
lines.push('', review.overallExplanation)
}
if (review.findings.length > 0) {
lines.push('', 'Findings:')
for (const finding of review.findings) {
const priority = finding.priority === null ? '' : `[P${finding.priority}] `
const location = finding.filePath
? ` (${finding.filePath}${finding.lineStart === null ? '' : `:${finding.lineStart}${finding.lineEnd !== null && finding.lineEnd !== finding.lineStart ? `-${finding.lineEnd}` : ''}`})`
: ''
lines.push(`- ${priority}${finding.title}${location}`)
lines.push(` ${finding.body}`)
}
}
return lines.join('\n')
}
function toThreadMessageLike(block: VisibleChatBlock): ThreadMessageLike {
@@ -104,6 +127,26 @@ function toThreadMessageLike(block: VisibleChatBlock): ThreadMessageLike {
}
}
if (block.kind === 'codex-review') {
const messageId = `review:${block.id}`
return {
role: 'assistant',
id: messageId,
createdAt: new Date(block.createdAt),
content: [{ type: 'text', text: formatCodexReviewText(block.review) }],
metadata: {
custom: {
kind: 'codex-review',
invokedAt: block.invokedAt,
durationMs: block.durationMs,
usage: block.usage,
model: block.model,
review: block.review
} satisfies HappyChatMessageMetadata
}
}
}
if (block.kind === 'agent-event') {
const messageId = `event:${block.id}`
return {
+6
View File
@@ -163,6 +163,12 @@ export default {
'chat.terminal': 'Terminal',
'chat.switchRemote': 'Switch to remote mode',
// Codex review
'codexReview.title': 'Codex review',
'codexReview.findings': '{count} findings',
'codexReview.confidence': 'Confidence {value}',
'codexReview.location.missing': 'No location',
// Terminal
'terminal.commandName': 'Command',
'terminal.commandMessage': 'Command message',
+6
View File
@@ -165,6 +165,12 @@ export default {
'chat.terminal': '终端',
'chat.switchRemote': '切换到远程模式',
// Codex review
'codexReview.title': 'Codex review',
'codexReview.findings': '{count} 条发现',
'codexReview.confidence': '置信度 {value}',
'codexReview.location.missing': '无位置',
// Terminal
'terminal.commandName': '命令',
'terminal.commandMessage': '命令消息',