Skip to Content
Kokonut UI

Use with shadcn chat

shadcn/ui's chat components draw the thread. Kokonut UI's AI components add what an agent needs around it, like tool approvals, diffs, citations, context and handoff.

shadcn/ui ships the conversation layer: Message Scroller, Message, Bubble, Attachment and Marker. Kokonut UI fills in the parts an agent needs inside and around those messages. Both are shadcn registries, so they install the same way and live side by side in components/.

Install with
lucide-react, motion

Who draws what

In the conversationshadcn/uiKokonut UI
The thread, scrolling and jump to latestMessage Scroller
A message, its avatar and its bubbleMessage, Bubble
A file in a messageAttachmentAI Attachment for uploads with progress
A step the agent took ("Explored 4 files")MarkerAI Tool Calls for a live trace of each step
Asking before a tool runsAI Tool Approval
Reviewing the agent's editsAI Diff Review
Sources behind an answerAI Inline Citations
How full the context window isAI Context Meter
Passing the chat to a personAI Handoff
The prompt boxAI Input Selector, AI Input Search

Install both

npx shadcn@latest add message-scroller message bubble
npx shadcn@latest add @kokonutui/ai-tool-approval @kokonutui/ai-citations

Or ask your agent: "Add shadcn's message scroller, message and bubble, then Kokonut UI's AI Tool Approval and AI Inline Citations." With the Kokonut UI MCP server connected, it finds both.

Put Kokonut parts inside a message

With the AI SDK, each message has parts. Text parts go in a shadcn Bubble. Tool parts go to AI Tool Approval, which takes the AI SDK's tool states as they are. Source parts go to AI Inline Citations.

components/chat.tsx
"use client";

import { useChat } from "@ai-sdk/react";
import { getToolName, isToolUIPart } from "ai";
import AICitations from "@/components/kokonutui/ai-citations";
import AIToolApproval, {
  type ToolCall,
  type ToolCallState,
} from "@/components/kokonutui/ai-tool-approval";
import { Bubble, BubbleContent } from "@/components/ui/bubble";
import { Message, MessageContent } from "@/components/ui/message";
import {
  MessageScroller,
  MessageScrollerContent,
  MessageScrollerItem,
  MessageScrollerProvider,
  MessageScrollerViewport,
} from "@/components/ui/message-scroller";

const TITLES: Record<string, string> = {
  run_command: "Run a command",
  delete_files: "Delete files",
};

const STATES = new Set<string>([
  "approval-requested",
  "approval-responded",
  "output-available",
  "output-denied",
  "output-error",
]);

export function Chat() {
  const { messages, addToolApprovalResponse } = useChat();

  return (
    <div className="h-[600px]">
      <MessageScrollerProvider>
        <MessageScroller>
          <MessageScrollerViewport>
            <MessageScrollerContent>
              {messages.map((message) => {
                const tools = message.parts
                  .filter(isToolUIPart)
                  .filter((part) => STATES.has(part.state));
                const calls: ToolCall[] = tools.map((part) => ({
                  id: part.toolCallId,
                  tool: getToolName(part),
                  title: TITLES[getToolName(part)] ?? getToolName(part),
                  input: part.input as ToolCall["input"],
                  state: part.state as ToolCallState,
                  destructive: getToolName(part) === "delete_files",
                }));
                const sources = message.parts
                  .filter((part) => part.type === "source-url")
                  .map((part) => ({ id: part.sourceId, title: part.title ?? part.url, url: part.url }));
                const text = message.parts
                  .filter((part) => part.type === "text")
                  .map((part) => part.text)
                  .join("");

                return (
                  <MessageScrollerItem
                    key={message.id}
                    messageId={message.id}
                    scrollAnchor={message.role === "user"}
                  >
                    <Message>
                      <MessageContent>
                        {calls.length > 0 && (
                          <AIToolApproval
                            calls={calls}
                            onRespond={(id, approved) => {
                              const part = tools.find((p) => p.toolCallId === id);
                              if (part?.approval) {
                                addToolApprovalResponse({ id: part.approval.id, approved });
                              }
                            }}
                          />
                        )}
                        {sources.length > 0 ? (
                          <AICitations
                            parts={[{ text, cite: sources.map((s) => s.id) }]}
                            sources={sources}
                          />
                        ) : (
                          text && (
                            <Bubble>
                              <BubbleContent>{text}</BubbleContent>
                            </Bubble>
                          )
                        )}
                      </MessageContent>
                    </Message>
                  </MessageScrollerItem>
                );
              })}
            </MessageScrollerContent>
          </MessageScrollerViewport>
        </MessageScroller>
      </MessageScrollerProvider>
    </div>
  );
}

On the server, mark the tools that should ask first with needsApproval: true. AI Tool Approval shows them waiting, a press and hold for destructive ones, and folds each decided call into a trace with its output.

To put a chip after each claim rather than one at the end, ask the model to mark claims with the source ids and split text there into parts, each with its own cite.

Around the thread

Some parts sit outside the messages:

  • AI Context Meter goes in the prompt footer. Pass segments from your token counts and onCompact to summarize.
  • AI Handoff takes over the last message when the agent calls a handoff_to_human tool.
  • AI Diff Review takes a coding agent's edits as files and reports each accept or reject through onDecision.

Every AI component plays a demo when you leave its data out, so you can place it first and wire it after. See all of them in AI.