From 800151771c0e3aaca224c3cc53a8505da44a4d3c Mon Sep 17 00:00:00 2001 From: zzlgreat Date: Mon, 10 Nov 2025 08:14:53 +0800 Subject: [PATCH] =?UTF-8?q?agent=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0MCP=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ChatBot/MarkdownWithCharts.js | 35 ++++++++++++++++---- src/views/AgentChat/index.js | 9 +++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/components/ChatBot/MarkdownWithCharts.js b/src/components/ChatBot/MarkdownWithCharts.js index 6f140d14..609c14f2 100644 --- a/src/components/ChatBot/MarkdownWithCharts.js +++ b/src/components/ChatBot/MarkdownWithCharts.js @@ -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 ( ); } 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 ( - + 图表配置解析失败 - - {part.content.substring(0, 200)} - {part.content.length > 200 ? '...' : ''} + + 错误: {error.message} + + + {part.content.substring(0, 300)} + {part.content.length > 300 ? '...' : ''} diff --git a/src/views/AgentChat/index.js b/src/views/AgentChat/index.js index cc7b05d5..d74c3ce2 100644 --- a/src/views/AgentChat/index.js +++ b/src/views/AgentChat/index.js @@ -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 ) );