Skip to content

Commit ad0b1a7

Browse files
NiallJoeMaherclaude
andcommitted
Fix custom artifact cards not appearing after page refresh
Add handlers for tool-quizMaster and tool-planner in message.tsx so custom artifact cards render in the chat thread after page refresh. Also add preview content for flashcard and study-plan kinds in DocumentContent. The bug was that agent tools were not being rendered - only the built-in createDocument/updateDocument tools had rendering code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d1708a9 commit ad0b1a7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

components/document-preview.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,22 @@ const DocumentContent = ({ document }: { document: Document }) => {
275275
<SpreadsheetEditor {...commonProps} />
276276
</div>
277277
</div>
278+
) : document.kind === "flashcard" ? (
279+
<div className="flex h-full flex-col items-center justify-center p-8 text-center">
280+
<div className="mb-2 text-2xl">📝</div>
281+
<p className="font-medium text-foreground">Interactive Quiz</p>
282+
<p className="mt-1 text-muted-foreground text-sm">
283+
Click to start the flashcard quiz
284+
</p>
285+
</div>
286+
) : document.kind === "study-plan" ? (
287+
<div className="flex h-full flex-col items-center justify-center p-8 text-center">
288+
<div className="mb-2 text-2xl">📚</div>
289+
<p className="font-medium text-foreground">Study Plan</p>
290+
<p className="mt-1 text-muted-foreground text-sm">
291+
Click to view your personalized study plan
292+
</p>
293+
</div>
278294
) : null}
279295
</div>
280296
);

components/message.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { memo, useState } from "react";
66
import type { Vote } from "@/lib/db/types";
77
import type { ChatMessage } from "@/lib/types";
88
import { cn, sanitizeText } from "@/lib/utils";
9+
import type { ArtifactKind } from "./artifact";
910
import { useDataStream } from "./data-stream-provider";
1011
import { DocumentToolResult } from "./document";
1112
import { DocumentPreview } from "./document-preview";
@@ -267,6 +268,53 @@ const PurePreviewMessage = ({
267268
);
268269
}
269270

271+
// Custom agent tools that create artifacts
272+
if (type === "tool-quizMaster") {
273+
const { toolCallId, state, output } = part;
274+
275+
if (
276+
state === "output-available" &&
277+
output?.success &&
278+
output?.data?.documentId
279+
) {
280+
return (
281+
<DocumentPreview
282+
isReadonly={isReadonly}
283+
key={toolCallId}
284+
result={{
285+
id: output.data.documentId,
286+
title: `Quiz: ${output.data.topic}`,
287+
kind: "flashcard" as ArtifactKind,
288+
}}
289+
/>
290+
);
291+
}
292+
return null;
293+
}
294+
295+
if (type === "tool-planner") {
296+
const { toolCallId, state, output } = part;
297+
298+
if (
299+
state === "output-available" &&
300+
output?.success &&
301+
output?.data?.documentId
302+
) {
303+
return (
304+
<DocumentPreview
305+
isReadonly={isReadonly}
306+
key={toolCallId}
307+
result={{
308+
id: output.data.documentId,
309+
title: `Study Plan: ${output.data.topic}`,
310+
kind: "study-plan" as ArtifactKind,
311+
}}
312+
/>
313+
);
314+
}
315+
return null;
316+
}
317+
270318
return null;
271319
})}
272320

0 commit comments

Comments
 (0)