Revert "perf: <tool_use> display (#5489)"

This reverts commit 0782b24790.
This commit is contained in:
kangfenmao 2025-05-07 21:08:16 +08:00
parent 5fe1d077e3
commit 06a590328c
2 changed files with 8 additions and 3 deletions

View File

@ -30,6 +30,8 @@ interface Props {
role: Message['role']
}
const toolUseRegex = /<tool_use>([\s\S]*?)<\/tool_use>/g
const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions = [] }) => {
// Use the passed citationBlockId directly in the selector
const { renderInputMessageAsMarkdown } = useSettings()
@ -66,6 +68,10 @@ const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions
return content
}, [block.content, block.citationReferences, citationBlockId, formattedCitations])
const ignoreToolUse = useMemo(() => {
return processedContent.replace(toolUseRegex, '')
}, [processedContent])
return (
<>
{/* Render mentions associated with the message */}
@ -79,7 +85,7 @@ const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions
{role === 'user' && !renderInputMessageAsMarkdown ? (
<p style={{ marginBottom: 5, whiteSpace: 'pre-wrap' }}>{block.content}</p>
) : (
<Markdown block={{ ...block, content: processedContent }} />
<Markdown block={{ ...block, content: ignoreToolUse }} />
)}
</>
)

View File

@ -56,8 +56,7 @@ export function createStreamProcessor(callbacks: StreamProcessorCallbacks = {})
callbacks.onTextChunk(data.text)
}
if (data.type === ChunkType.TEXT_COMPLETE && callbacks.onTextComplete) {
// 消除工具使用对信息流的影响
callbacks.onTextComplete(data.text.replace(/<tool_use>([\s\S]*?)<\/tool_use>/g, ''))
callbacks.onTextComplete(data.text)
}
if (data.type === ChunkType.THINKING_DELTA && callbacks.onThinkingChunk) {
callbacks.onThinkingChunk(data.text, data.thinking_millsec)