mxyhi/ok-skills / ai-elements
ai-elements
VerifiedBuild AI chat interfaces using ai-elements components — conversations, messages, tool displays, prompt inputs, and more. Use when the user wants to build a chatbot, AI assistant UI, or any AI-powered chat interface.
scripts/checkpoint.tsx
View on GitHub"use client";
import {
Checkpoint,
CheckpointIcon,
CheckpointTrigger,
} from "@/components/ai-elements/checkpoint";
import { Conversation, ConversationContent } from "@/components/ai-elements/conversation";
import {
Message,
MessageContent,
MessageResponse,
} from "@/components/ai-elements/message";
import { nanoid } from "nanoid";
import { Fragment, memo, useCallback, useState } from "react";
interface MessageType {
id: string;
role: "user" | "assistant";
content: string;
}
const initialMessages: MessageType[] = [
{
content: "What is React?",
id: nanoid(),
role: "user",
},
{
content:
"React is a JavaScript library for building user interfaces. It was developed by Facebook and is now maintained by Meta and a community of developers.",
id: nanoid(),
role: "assistant",
},
{
content: "How does component state work?",
id: nanoid(),
role: "user",
},
];
interface CheckpointItemProps {
checkpoint: { messageCount: number; timestamp: Date };
onRestore: (messageCount: number) => void;
}
const CheckpointItem = memo(
({ checkpoint, onRestore }: CheckpointItemProps) => {
const handleClick = useCallback(
() => onRestore(checkpoint.messageCount),
[onRestore, checkpoint.messageCount]
);
return (
<Checkpoint>
<CheckpointIcon />
<CheckpointTrigger
onClick={handleClick}
tooltip="Restores workspace and chat to this point"
>
Restore checkpoint
</CheckpointTrigger>
</Checkpoint>
);
}
);
CheckpointItem.displayName = "CheckpointItem";
const Example = () => {
const [messages, setMessages] = useState<MessageType[]>(initialMessages);
const [checkpoints] = useState([
{ messageCount: 2, timestamp: new Date(Date.now() - 3_600_000) },
]);
const handleRestore = useCallback((messageCount: number) => {
setMessages(initialMessages.slice(0, messageCount));
}, []);
return (
<div className="flex size-full flex-col rounded-lg border p-6">
<Conversation>
<ConversationContent>
{messages.map((message, index) => {
const checkpoint = checkpoints.find(
(cp) => cp.messageCount === index + 1
);
return (
<Fragment key={message.id}>
<Message from={message.role}>
<MessageContent>
<MessageResponse>{message.content}</MessageResponse>
</MessageContent>
</Message>
{checkpoint && (
<CheckpointItem
checkpoint={checkpoint}
onRestore={handleRestore}
/>
)}
</Fragment>
);
})}
</ConversationContent>
</Conversation>
</div>
);
};
export default Example;
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |