Assistant
Approve or reject the archive request to see what happens next.
tsx
'use client';
import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport, lastAssistantMessageIsCompleteWithApprovalResponses } from 'ai';
import { Chat, useAiSdkChat } from '@stackunseen/ui/chat';
import { renderMarkdownPart } from '@stackunseen/ui/markdown';
import '@stackunseen/ui/styles.css';
import '@stackunseen/ui/chat.css';
export function Assistant() {
const chat = useChat({
transport: new DefaultChatTransport({ api: '/api/chat' }),
// Send the conversation back once every pending approval has an answer.
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
});
return <Chat {...useAiSdkChat(chat)} title="Assistant" renderTextPart={renderMarkdownPart} />;
}- The model calls a tool marked
needsApproval; the SDK streams an approval request. - Chat shows the tool card and an approval card with the server's reason.
- Approve or Reject calls
addToolApprovalResponsewith the approval id. - The card stays locked until the tool runs or is denied, then reads acknowledged.
Start from these two files in your project: npx shadcn@latest add https://unseenui.com/r/chat-ai-sdk.json, or npx @stackunseen/ui init --ai-sdk.
Full mapping table and what is and is not verified: the Chat page. Components used: Chat, ToolCall, ApprovalCard, MarkdownResponse.