fix(chat): render chart artifacts
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
|||||||
import type { Message, SpeechState } from "./GlobalChatbox.types";
|
import type { Message, SpeechState } from "./GlobalChatbox.types";
|
||||||
import { stripMarkdown } from "./GlobalChatbox.utils";
|
import { stripMarkdown } from "./GlobalChatbox.utils";
|
||||||
import { AgentProgressTimeline } from "./AgentProgressTimeline";
|
import { AgentProgressTimeline } from "./AgentProgressTimeline";
|
||||||
|
import { AgentArtifactPanel } from "./AgentArtifactPanel";
|
||||||
import { ChatInlineChart } from "./ChatInlineChart";
|
import { ChatInlineChart } from "./ChatInlineChart";
|
||||||
import { ChatToolCallBlock } from "./ChatToolCallBlock";
|
import { ChatToolCallBlock } from "./ChatToolCallBlock";
|
||||||
import { MarkdownBlock, normalizeClipboardText } from "./AgentMarkdownBlock";
|
import { MarkdownBlock, normalizeClipboardText } from "./AgentMarkdownBlock";
|
||||||
@@ -92,6 +93,19 @@ export const AgentTurn = React.memo(
|
|||||||
: [{ type: "text", content: answerContent }],
|
: [{ type: "text", content: answerContent }],
|
||||||
[answerContent, isErrorMessage, isUser],
|
[answerContent, isErrorMessage, isUser],
|
||||||
);
|
);
|
||||||
|
const hasInlineChart = contentSegments.some(
|
||||||
|
(segment) =>
|
||||||
|
segment.type === "tool_call" &&
|
||||||
|
(segment.toolCall.tool === "chart" ||
|
||||||
|
segment.toolCall.tool === "show_chart"),
|
||||||
|
);
|
||||||
|
const visibleArtifacts = useMemo(
|
||||||
|
() =>
|
||||||
|
hasInlineChart
|
||||||
|
? message.artifacts?.filter((artifact) => artifact.kind !== "chart")
|
||||||
|
: message.artifacts,
|
||||||
|
[hasInlineChart, message.artifacts],
|
||||||
|
);
|
||||||
|
|
||||||
if (isUser) {
|
if (isUser) {
|
||||||
return (
|
return (
|
||||||
@@ -275,6 +289,10 @@ export const AgentTurn = React.memo(
|
|||||||
})}
|
})}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
{visibleArtifacts?.length ? (
|
||||||
|
<AgentArtifactPanel artifacts={visibleArtifacts} />
|
||||||
|
) : null}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
|
|||||||
Reference in New Issue
Block a user