agent功能开发增加MCP后端
This commit is contained in:
@@ -135,24 +135,47 @@ export const MarkdownWithCharts = ({ content }) => {
|
||||
} else if (part.type === 'chart') {
|
||||
// 渲染 ECharts 图表
|
||||
try {
|
||||
const chartOption = JSON.parse(part.content);
|
||||
// 清理可能的 Markdown 残留符号
|
||||
let cleanContent = part.content.trim();
|
||||
|
||||
// 移除可能的前后空白和不可见字符
|
||||
cleanContent = cleanContent.replace(/^\s+|\s+$/g, '');
|
||||
|
||||
// 尝试解析 JSON
|
||||
const chartOption = JSON.parse(cleanContent);
|
||||
|
||||
// 验证是否是有效的 ECharts 配置
|
||||
if (!chartOption || typeof chartOption !== 'object') {
|
||||
throw new Error('Invalid chart configuration: not an object');
|
||||
}
|
||||
|
||||
return (
|
||||
<Box key={index}>
|
||||
<EChartsRenderer option={chartOption} height={350} />
|
||||
</Box>
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error('解析 ECharts 配置失败', error, part.content);
|
||||
// 记录详细的错误信息
|
||||
logger.error('解析 ECharts 配置失败', {
|
||||
error: error.message,
|
||||
contentLength: part.content.length,
|
||||
contentPreview: part.content.substring(0, 200),
|
||||
errorStack: error.stack
|
||||
});
|
||||
|
||||
return (
|
||||
<Alert status="warning" key={index} borderRadius="md">
|
||||
<AlertIcon />
|
||||
<VStack align="flex-start" spacing={1}>
|
||||
<VStack align="flex-start" spacing={1} flex="1">
|
||||
<Text fontSize="sm" fontWeight="bold">
|
||||
图表配置解析失败
|
||||
</Text>
|
||||
<Code fontSize="xs" maxW="100%" overflow="auto">
|
||||
{part.content.substring(0, 200)}
|
||||
{part.content.length > 200 ? '...' : ''}
|
||||
<Text fontSize="xs" color="gray.600">
|
||||
错误: {error.message}
|
||||
</Text>
|
||||
<Code fontSize="xs" maxW="100%" overflow="auto" whiteSpace="pre-wrap">
|
||||
{part.content.substring(0, 300)}
|
||||
{part.content.length > 300 ? '...' : ''}
|
||||
</Code>
|
||||
</VStack>
|
||||
</Alert>
|
||||
|
||||
@@ -431,11 +431,16 @@ const AgentChatV3 = () => {
|
||||
} else if (currentEvent === 'summary') {
|
||||
// 收到完整总结(包含元数据)
|
||||
if (summaryMessageId) {
|
||||
// 更新已有消息的元数据,并标记流式输出完成
|
||||
// 更新已有消息的元数据和内容,并标记流式输出完成
|
||||
setMessages((prev) =>
|
||||
prev.map((m) =>
|
||||
m.id === summaryMessageId
|
||||
? { ...m, metadata: data.metadata, isStreaming: false }
|
||||
? {
|
||||
...m,
|
||||
content: data.content || summaryContent, // ✅ 使用后端返回的完整内容,如果没有则使用累积内容
|
||||
metadata: data.metadata,
|
||||
isStreaming: false, // ✅ 标记流式输出完成
|
||||
}
|
||||
: m
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user