ai-native-ui
Skill4 starsChanged 4 months agoMITView on GitHub
Load when building any UI with LLM integration: chat interfaces, AI-generated content, smart search, content generation tools, or any feature that streams AI responses to users. This is Tier 4 (Generative) in the Vanguard architecture. Load web-l100 (SK-083) for the full tier system. AI streams are a fundamentally different rendering model. Unlike T0-T3 where the final content is known at render time, T4 content builds up token-by-token with structural uncertainty. The UI must: The killer pattern: AI calls tools, each…
In this repository162 other files it gives its agents.
- agents/AGENTS.mdAGENTS.md
- skills/compound-engineering/AGENTS.mdAGENTS.md
- skills/trailofbits-security/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- examples/CLAUDE.mdCLAUDE.md
- skills/compound-engineering/CLAUDE.mdCLAUDE.md
- skills/trailofbits-security/CLAUDE.mdCLAUDE.md
- app-store-reviewSkill
- advanced-javascriptSkill
- anime-jsSkill
- app-l100Skill
- barba-jsSkill
- brand-guidelinesSkill
- cinematic-web-engineSkill
- codebase-knowledge-graphSkill
- crossplatform-monorepoSkill
- css-first-uiSkill
- design-auditSkill
- design-critiqueSkill
- dev-cycleSkill
- device-hardware-bridgeSkill
- discovery-docSkill
- docxSkill
- edge-intelligenceSkill
- graph-aware-reviewSkill
- linkedin-posterSkill
- local-first-architectureSkill
- modern-build-pipelineSkill
- motion-nativeSkill
- nano-bananaSkill
- playwrightSkill
- pptxSkill
- project-initSkill
- remotionSkill
- sensory-nativeSkill
- spline-3dSkill
- streaming-cacheSkill
- tanstack-ecosystemSkill
- design-taste-frontendSkill
- tauri-desktopSkill
- threejsSkill
- transition-nativeSkill
- ui-design-stackSkill
- visual-nativeSkill
- web-l100Skill
- web-platform-apisSkill
- xlsxSkill
- better-authSkill
- claude-real-videoSkill
- clone-websiteSkill
- css-keyframe-animationsSkill
- design-checkSkill
- design-dnaSkill
- design-polishSkill
- drizzle-neonSkill
- fastlaneSkill
- angular-architectSkill
- api-designerSkill
- architecture-designerSkill
- atlassian-mcpSkill
- The first 60 shown.
The file
Files
<!--
id: SK-086
name: ai-native-ui
description: AI-Native UI — Vercel AI SDK patterns for streaming UI. streamText, useChat, tool-to-component mapping, createStreamableValue, generative UI within PPR shells. Load when building AI-powered interfaces.
keywords: ai-sdk, stream-text, use-chat, generative-ui, tool-invocation, streaming-ui, llm, chatbot, ai-native, createStreamableValue, vercel-ai
version: 1.0.0
-->AI-Native UI
When to Use This Skill
Load when building any UI with LLM integration: chat interfaces, AI-generated content, smart search, content generation tools, or any feature that streams AI responses to users.
This is Tier 4 (Generative) in the Vanguard architecture. Load web-l100 (SK-083) for the full tier system.
The Generative Tier
AI streams are a fundamentally different rendering model. Unlike T0-T3 where the final content is known at render time, T4 content builds up token-by-token with structural uncertainty. The UI must:
- Show useful content immediately (PPR shell + cached content)
- Progressively reveal AI-generated content as it streams
- Handle tool invocations mid-stream (AI calls tools → UI renders components)
- Gracefully handle interruption (user cancels, network drops)
Core Pattern: streamText + Route Handler
Server: Route Handler
// app/api/chat/route.ts
import { streamText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: anthropic('claude-sonnet-4-5-20250514'),
system: 'You are a helpful assistant.',
messages,
tools: {
getWeather: {
description: 'Get weather for a location',
parameters: z.object({
location: z.string().describe('City name'),
}),
execute: async ({ location }) => {
const weather = await fetchWeather(location);
return weather;
},
},
},
});
return result.toDataStreamResponse();
}Client: useChat Hook
// components/chat.tsx
'use client';
import { useChat } from '@ai-sdk/react';
export function Chat() {
const { messages, input, handleInputChange, handleSubmit, isLoading, stop } = useChat({
api: '/api/chat',
});
return (
<div className="chat">
<div className="messages">
{messages.map(message => (
<div key={message.id} className={`message message--${message.role}`}>
{message.content}
{/* Render tool invocations as components */}
{message.toolInvocations?.map(invocation => (
<ToolResult key={invocation.toolCallId} invocation={invocation} />
))}
</div>
))}
</div>
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} placeholder="Ask anything..." />
{isLoading ? (
<button type="button" onClick={stop}>Stop</button>
) : (
<button type="submit">Send</button>
)}
</form>
</div>
);
}Tool Invocations → React Components
The killer pattern: AI calls tools, each tool invocation maps to a React component.
// components/tool-result.tsx
function ToolResult({ invocation }: { invocation: ToolInvocation }) {
// Tool is still being called — show loading state
if (invocation.state === 'call') {
return <ToolLoading name={invocation.toolName} />;
}
// Tool returned a result — render the appropriate component
if (invocation.state === 'result') {
switch (invocation.toolName) {
case 'getWeather':
return <WeatherCard data={invocation.result} />;
case 'searchProducts':
return <ProductGrid products={invocation.result} />;
case 'getChart':
return <Chart config={invocation.result} />;
default:
return <pre>{JSON.stringify(invocation.result, null, 2)}</pre>;
}
}
return null;
}
function ToolLoading({ name }: { name: string }) {
return (
<div className="tool-loading">
<div className="skeleton" style={{ height: name === 'getChart' ? '300px' : '120px' }} />
</div>
);
}Streaming Structured Objects
For streaming JSON objects (not just text) as they build up:
Server: streamObject
// app/api/analyze/route.ts
import { streamObject } from 'ai';
import { z } from 'zod';
const AnalysisSchema = z.object({
summary: z.string(),
sentiment: z.enum(['positive', 'negative', 'neutral']),
keyTopics: z.array(z.string()),
confidence: z.number(),
});
export async function POST(req: Request) {
const { text } = await req.json();
const result = streamObject({
model: anthropic('claude-sonnet-4-5-20250514'),
schema: AnalysisSchema,
prompt: `Analyze this text: ${text}`,
});
return result.toTextStreamResponse();
}Client: useObject
'use client';
import { useObject } from '@ai-sdk/react';
function AnalysisPanel({ text }: { text: string }) {
const { object, isLoading } = useObject({
api: '/api/analyze',
schema: AnalysisSchema,
body: { text },
});
return (
<div>
{/* Fields appear progressively as AI generates them */}
{object?.summary && <p>{object.summary}</p>}
{object?.sentiment && <SentimentBadge value={object.sentiment} />}
{object?.keyTopics && (
<div className="topics">
{object.keyTopics.map(topic => <Tag key={topic}>{topic}</Tag>)}
</div>
)}
{object?.confidence != null && <ConfidenceBar value={object.confidence} />}
</div>
);
}Generative UI within PPR
The T4 tier integrated with T0-T2. Static shell loads instantly, AI content fills in.
// app/dashboard/page.tsx
export default function AIAssistantPage() {
return (
<>
{/* T0: Static shell — instant from CDN */}
<header><h1>AI Assistant</h1></header>
{/* T1: Cached suggestions */}
<PopularQuestions />
{/* T4: AI chat — streams in */}
<Suspense fallback={<ChatSkeleton />}>
<Chat />
</Suspense>
{/* T1: Cached documentation sidebar */}
<DocsSidebar />
</>
);
}The user sees the full UI shell instantly, popular questions load from cache, and the AI chat is ready for interaction — all within 100ms. AI responses then stream in 1-3 seconds.
Multi-Stream Orchestration
Multiple independent AI streams in one UI:
function AIDashboard() {
const summary = useChat({ api: '/api/ai/summary', id: 'summary' });
const insights = useChat({ api: '/api/ai/insights', id: 'insights' });
const predictions = useChat({ api: '/api/ai/predictions', id: 'predictions' });
// Trigger all three on page load
useEffect(() => {
summary.append({ role: 'user', content: 'Summarize today' });
insights.append({ role: 'user', content: 'Key insights' });
predictions.append({ role: 'user', content: 'Predictions' });
}, []);
return (
<div className="grid grid-cols-3 gap-4">
<Panel title="Summary" messages={summary.messages} loading={summary.isLoading} />
<Panel title="Insights" messages={insights.messages} loading={insights.isLoading} />
<Panel title="Predictions" messages={predictions.messages} loading={predictions.isLoading} />
</div>
);
}Each panel updates independently as its stream progresses.
Error Handling & Cancellation
const { messages, error, reload, stop, isLoading } = useChat({
api: '/api/chat',
onError: (error) => {
console.error('Chat error:', error);
// Show toast notification
},
});
// Retry last message
{error && (
<button onClick={reload}>Retry</button>
)}
// Cancel in-progress generation
{isLoading && (
<button onClick={stop}>Stop generating</button>
)}Key Rules
- Use AI SDK UI (stable), not AI SDK RSC (experimental) for production
- Server returns data, client renders components — clean separation of concerns
- Tool invocations are the bridge between AI decisions and React components
- Always provide loading states for tool invocations (skeleton matching final size)
- Wrap AI components in Suspense for PPR integration
- Use
stop()— users expect to cancel long generations - Stream objects when structure matters —
streamObject+useObjectfor dashboards, forms - Cache common AI queries — wrap with
use cachefor FAQ-style responses
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

