Privacy-friendly analytics only with consent. No ads, no cross-site tracking. Read the privacy policy.
Full recipes for the surfaces AI products actually ship. Every one is stateless — you own the transport and the state. Prefer a complete copy-paste app? Start from the templates.
The baseline assistant surface: stream markdown tokens as they arrive, repair incomplete syntax mid-stream, stop generation on demand, and pin the viewport to the latest message. Wire the `send` body to any transport — fetch SSE, Vercel AI SDK, or a raw ReadableStream.
const [messages, setMessages] = useState<Message[]>([]);const [streamingId, setStreamingId] = useState<string | null>(null);async function send(text: string) {const id = crypto.randomUUID();setMessages((prev) => [...prev, { id, role: 'user', content: text }]);const replyId = crypto.randomUUID();setMessages((prev) => [...prev, { id: replyId, role: 'assistant', content: '' }]);setStreamingId(replyId);// Any transport that yields text chunks.const res = await fetch('/api/chat', { method: 'POST', body: JSON.stringify({ prompt: text }) });const reader = res.body!.getReader();const decoder = new TextDecoder();let content = '';while (true) {const { done, value } = await reader.read();if (done) break;content += decoder.decode(value, { stream: true });setMessages((prev) => prev.map((m) => (m.id === replyId ? { ...m, content } : m)));}setStreamingId(null);}<Conversationmessages={messages}streamingMessageId={streamingId ?? undefined}renderContent={(content) => <Response parseIncompleteMarkdown>{content}</Response>}/><PromptInput onSubmit={send} isLoading={streamingId !== null} onStop={() => controller.abort()} />
Render the agent's tool lifecycle — pending → running → success/error — with arguments and results inspectable. Failures stay inline with a retry affordance instead of collapsing the transcript.
<ToolCalltoolCall={{id: call.id,name: 'search_files',status: 'running', // 'pending' | 'running' | 'success' | 'error'arguments: { query: '*.tsx', directory: 'src' },}}/>{/* Failed calls keep the args visible and surface the error */}<ToolCalltoolCall={{id: failed.id,name: 'read_file',status: 'error',arguments: { path: 'src/missing.ts' },result: 'ENOENT: no such file',}}/>{/* Pair with a collapsible reasoning panel for longer tasks */}<Reasoning steps={[{ id: '1', content: 'Locate candidate files' }, { id: '2', content: 'Read and rank' }]} />
Ground answers in retrieved context: inline citation chips inside the markdown, a numbered sources footer, and follow-up suggestions. Your retriever emits `{{citation:N}}` markers; resolve them to InlineCitation chips at render time.
import { InlineCitation, Response, Sources, Suggestions } from '@slipstream-ui/ai';// The model answers with {{citation:N}} markers; resolve them as the text renders.function GroundedAnswer({ answer, sources, followUps }) {const parts = answer.split(/\{\{citation:(\d+)\}\}/);return (<><Response parseIncompleteMarkdown>{parts.map((part, i) => {const source = sources[Number(part) - 1];return i % 2 === 1 && source ? <InlineCitation key={i} source={source} /> : part;}).join('')}</Response><Sources sources={sources} maxDisplay={3} /><Suggestions suggestions={followUps} /></>);}
Pause destructive or outward-facing tool calls behind an explicit approval gate. While pending, Confirmation renders as an alertdialog so screen readers announce the decision point; approve to resume, reject to unwind.
const [approved, setApproved] = useState(false);{toolCall.name === 'delete_files' && !approved ? (<Confirmationtitle="Delete all files in /tmp?"description="This affects 14 files and cannot be undone."toolName={toolCall.name}onApprove={() => setApproved(true)}onReject={() => onCancel(toolCall.id)}/>) : (<ToolCall toolCall={toolCall} />)}
When a generation can be regenerated into alternatives, keep every variant and let the user navigate them. Each message id carries its branch list; Branch renders prev/next arrows with an N/M indicator in the toolbar.
// Regenerating stores a new variant instead of replacing the message.function regenerate(messageId: string) {const variants = branches[messageId] ?? [messages.find((m) => m.id === messageId)!];const next = variants.length + 1;setBranches({ ...branches, [messageId]: [...variants, { ...variants[0], id: crypto.randomUUID() }] });return next;}// Render the navigator only for messages that actually branch.{branchCount > 1 && (<Branchcurrent={branchIndex}total={branchCount}onPrev={() => showVariant(messageId, branchIndex - 1)}onNext={() => showVariant(messageId, branchIndex + 1)}/>)}
None of these recipes import a model SDK. Swap the fetch call for Vercel AI SDK's useChat, a LangGraph stream, or WebSocket frames — the components only consume messages and streamingMessageId. See Conversation for the full prop contract.