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
)
);