Privacy-friendly analytics only with consent. No ads, no cross-site tracking. Read the privacy policy.
Complete, copy-paste patterns built entirely from Slipstream UI components. Each one is stateless — you own the data flow and transport.
The core pattern: streaming markdown responses, stop-generation, auto-scroll pinning, and feedback actions. ~80 lines.
Live demo — try it
Show me the streaming chat pattern
'use client';import { useRef, useState } from 'react';import {Conversation,MessageActions,PromptInput,Response,} from '@slipstream-ui/ai';import type { Message } from '@slipstream-ui/ai';export function StreamingChat() {const [messages, setMessages] = useState<Message[]>([]);const [streamingId, setStreamingId] = useState<string | null>(null);const abortRef = useRef<AbortController | null>(null);async function send(text: string) {const controller = new AbortController();abortRef.current = controller;// Your transport — any endpoint that streams text chunks.const response = await fetch('/api/chat', {method: 'POST',body: JSON.stringify({ prompt: text }),signal: controller.signal,});const id = crypto.randomUUID();setMessages((prev) => [...prev, { id, role: 'assistant', content: '' }]);setStreamingId(id);const reader = response.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 === id ? { ...m, content } : m)));}setStreamingId(null);}return (<div className="flex flex-col h-[600px]"><Conversationmessages={messages}streamingMessageId={streamingId ?? undefined}renderContent={(content) => <Response parseIncompleteMarkdown>{content}</Response>}className="flex-1"/><div className="pl-12">{messages.at(-1)?.role === 'assistant' && (<MessageActionscontent={messages.at(-1)!.content}onFeedback={(rating) => analytics.track(rating)}onRegenerate={() => send('Regenerate')}/>)}</div><PromptInputonSubmit={send}isLoading={streamingId !== null}onStop={() => abortRef.current?.abort()}/></div>);}
Tool calls with human-in-the-loop approval, reasoning steps, and task progress — the pattern for autonomous agents.
Live demo — try it
'use client';import { useState } from 'react';import {ChainThought,Confirmation,Reasoning,ToolCall,} from '@slipstream-ui/ai';import type { ToolCall as ToolCallType } from '@slipstream-ui/ai';export function AgentActivity({ toolCall }: { toolCall: ToolCallType }) {const [approved, setApproved] = useState(false);return (<div className="space-y-4 max-w-xl">{/* Pause destructive actions until approved */}{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={() => console.log('cancelled')}/>) : (<ToolCall toolCall={toolCall} />)}<Reasoningsteps={[{ id: '1', content: 'Parse user intent' },{ id: '2', content: 'Select delete_files tool' },{ id: '3', content: 'Await user approval' },]}/><ChainThoughtsteps={[{ id: 't1', content: 'Scan directory', status: 'completed' },{ id: 't2', content: 'Request approval', status: 'pending' },]}/></div>);}
Grounded answers with inline citations and a sources footer — the pattern for search and knowledge-base products.
Live demo — try it
Slipstream keeps agents honest by shipping a machine-readable spec with every componentCOMPONENT_MANIFEST schema referenceEvery component ships id, props, antiPatterns, accessibility, and compositionRules…. Before emitting code, your agent can call validate_usagevalidate_usage MCP toolChecks generated JSX against the manifest and rejects hallucinated props… to reject hallucinated props — and streamed markdown renders cleanly even while tokens are still arrivingStreaming-safe markdown renderingResponse repairs unclosed emphasis, inline code, and fences mid-stream….
import {InlineCitation,Sources,Suggestions,} from '@slipstream-ui/ai';import type { SourceItem } from '@slipstream-ui/ai';type GroundedAnswer = {answer: string; // markdown with {{citation:N}} markerssources: SourceItem[];followUps: { id: string; text: string }[];};// Resolve citation markers to InlineCitation chips at render time.function renderAnswer(answer: string, sources: SourceItem[]) {return answer.split(/\{\{citation:(\d+)\}\}/).map((part, i) => {const source = sources[Number(part) - 1];if (i % 2 === 1 && source) {return <InlineCitation key={i} source={source} />;}return part;});}export function GroundedResponse({ result }: { result: GroundedAnswer }) {return (<div><p>{renderAnswer(result.answer, result.sources)}</p><Sources sources={result.sources} maxDisplay={3} /><Suggestions suggestions={result.followUps} /></div>);}
Field-level validation, error states, and submit handling — the pattern for settings, signup, and data-entry flows.
Live demo — try it
'use client';import { useState } from 'react';import {Button,Checkbox,Input,Label,Select,Switch,Textarea,} from '@slipstream-ui/core';type FormErrors = {email?: string;password?: string;};export function SignupForm() {const [email, setEmail] = useState('');const [password, setPassword] = useState('');const [bio, setBio] = useState('');const [role, setRole] = useState('member');const [agree, setAgree] = useState(false);const [notify, setNotify] = useState(true);const [errors, setErrors] = useState<FormErrors>({});function validate(): boolean {const next: FormErrors = {};if (!email) next.email = 'Email is required';else if (!email.includes('@')) next.email = 'Enter a valid email';if (!password) next.password = 'Password is required';else if (password.length < 8) next.password = 'Must be at least 8 characters';setErrors(next);return Object.keys(next).length === 0;}function handleSubmit(event: React.FormEvent) {event.preventDefault();if (!validate()) return;// Submit to your API}return (<form onSubmit={handleSubmit} className="space-y-4 max-w-md"><div className="space-y-1.5"><Label htmlFor="email">Email</Label><Inputid="email"type="email"value={email}onChange={(e) => setEmail(e.target.value)}aria-invalid={Boolean(errors.email)}aria-describedby={errors.email ? 'email-error' : undefined}className={errors.email ? 'border-destructive' : ''}/>{errors.email && (<p id="email-error" className="text-xs text-destructive">{errors.email}</p>)}</div><div className="space-y-1.5"><Label htmlFor="password">Password</Label><Inputid="password"type="password"value={password}onChange={(e) => setPassword(e.target.value)}aria-invalid={Boolean(errors.password)}aria-describedby={errors.password ? 'password-error' : undefined}className={errors.password ? 'border-destructive' : ''}/>{errors.password && (<p id="password-error" className="text-xs text-destructive">{errors.password}</p>)}</div><div className="space-y-1.5"><Label htmlFor="role">Role</Label><Selectid="role"value={role}onChange={setRole}options={[{ value: 'member', label: 'Member' },{ value: 'admin', label: 'Admin' },]}/></div><div className="space-y-1.5"><Label htmlFor="bio">Bio</Label><Textareaid="bio"value={bio}onChange={(e) => setBio(e.target.value)}placeholder="Tell us about yourself"maxLength={280}/></div><div className="flex items-center gap-2"><Checkbox id="agree" checked={agree} onCheckedChange={setAgree} /><Label htmlFor="agree">Accept terms and conditions</Label></div><div className="flex items-center justify-between"><Label htmlFor="notify">Email notifications</Label><Switch id="notify" checked={notify} onCheckedChange={setNotify} /></div><Button type="submit" disabled={!agree}>Create account</Button></form>);}
Thread list beside the active conversation: per-thread message state, thread-scoped streaming, and a key-reset that keeps scroll state independent. The structure behind every chat product with a sidebar.
Live demo — try it
Draft release notes for 0.1.0
'use client';import { useState } from 'react';import { Conversation, PromptInput, Response } from '@slipstream-ui/ai';import type { Message } from '@slipstream-ui/ai';type Thread = { id: string; title: string; messages: Message[]; streamingId?: string | null };export function MultiThreadChat({ initial }: { initial: Thread[] }) {const [threads, setThreads] = useState(initial);const [activeId, setActiveId] = useState(initial[0].id);const active = threads.find((t) => t.id === activeId)!;const patch = (id: string, next: Partial<Thread>) =>setThreads((prev) => prev.map((t) => (t.id === id ? { ...t, ...next } : t)));async function send(text: string) {// Stream into the thread captured at send time — never "the active one",// the user may switch threads mid-generation.const target = active.id;patch(target, { messages: [...active.messages, { id: crypto.randomUUID(), role: 'user', content: text }] });// ... append assistant message, stream chunks into target thread only,// clear target.streamingId when done.}return (<div className="flex h-[600px]"><aside className="w-56 space-y-1 border-r p-2">{threads.map((t) => (<button key={t.id} onClick={() => setActiveId(t.id)}className={'block w-full truncate rounded-md px-2 py-1.5 text-left text-sm ' +(t.id === active.id ? 'bg-primary/10 text-primary' : 'text-muted-foreground')}>{t.title}</button>))}</aside><div className="flex min-w-0 flex-1 flex-col">{/* key resets scroll + welcome state per thread */}<Conversationkey={active.id}messages={active.messages}streamingMessageId={active.streamingId ?? undefined}renderContent={(content) => <Response parseIncompleteMarkdown>{content}</Response>}className="flex-1"/><PromptInput onSubmit={send} isLoading={Boolean(active.streamingId)} /></div></div>);}