Generative UI implementation patterns for AI SDK RSC including server-side streaming components, dynamic UI generation, and client-server coordination. Use when implementing generative UI, building AI SDK RSC, creating streaming components, or when user mentions generative UI, React Server Components, dynamic UI, AI-generated interfaces, or server-side streaming.
/plugin marketplace add vanman2024/ai-dev-marketplace/plugin install vercel-ai-sdk@ai-dev-marketplaceThis skill is limited to using the following tools:
examples/chart-generator.tsxscripts/validate-rsc-setup.shtemplates/client-wrapper.tsxtemplates/server-action-pattern.tsxPurpose: Provide reusable templates, patterns, and validation scripts for implementing Generative UI with Vercel AI SDK RSC (React Server Components).
Activation Triggers:
Key Resources:
templates/server-action-pattern.tsx - Server action template for AI RSCtemplates/streaming-component.tsx - Streaming component patterntemplates/client-wrapper.tsx - Client component wrapper patterntemplates/route-handler.ts - API route handler for streaming UIscripts/validate-rsc-setup.sh - Validate Next.js RSC configurationscripts/generate-ui-component.sh - Generate UI component from schemaexamples/ - Real-world generative UI implementationsWhen to use: Next.js App Router with React Server Components
Template: templates/server-action-pattern.tsx
Pattern:
'use server'
import { streamUI } from 'ai/rsc'
import { openai } from '@ai-sdk/openai'
export async function generateUI(prompt: string) {
const result = await streamUI({
model: openai('gpt-4')
prompt
text: ({ content }) => <p>{content}</p>
tools: {
// Tool definitions for dynamic UI generation
}
})
return result.value
}
Key features:
When to use: Need real-time UI updates during AI generation
Template: templates/streaming-component.tsx
Pattern:
When to use: Complex interactions between client and server components
Template: templates/client-wrapper.tsx
Pattern:
# Check Next.js version and App Router setup
./scripts/validate-rsc-setup.sh
Checks:
app/ directory existsDecision tree:
# Generate component from pattern
./scripts/generate-ui-component.sh <pattern-type> <component-name>
# Examples:
./scripts/generate-ui-component.sh stream-text MessageCard
./scripts/generate-ui-component.sh dynamic-tool ChartGenerator
./scripts/generate-ui-component.sh workflow MultiStepForm
Use template: templates/server-action-pattern.tsx
Customize:
Use template: templates/client-wrapper.tsx
For:
Pattern:
const tools = {
showChart: tool({
description: 'Display data as chart'
parameters: z.object({
data: z.array(z.number())
type: z.enum(['bar', 'line', 'pie'])
})
generate: async ({ data, type }) => {
return <ChartComponent data={data} type={type} />
}
})
showTable: tool({
description: 'Display data as table'
parameters: z.object({
rows: z.array(z.record(z.string()))
})
generate: async ({ rows }) => {
return <TableComponent rows={rows} />
}
})
}
Key principle: Let AI choose appropriate UI component based on data
const result = await streamUI({
// ... config
onError: (error) => {
return <ErrorBoundary error={error} />
}
fallback: <LoadingSpinner />
})
Best practices:
Use dynamic imports for heavy components:
const HeavyChart = dynamic(() => import('./HeavyChart'))
Control chunk size for optimal UX:
const result = await streamUI({
// ... config
experimental_streamChunking: true
})
Cache static UI components:
export const revalidate = 3600 // 1 hour
Critical: Never expose server actions to client
// ✅ Good: server action
'use server'
export async function generateUI() { /* ... */ }
// ❌ Bad: client-accessible
export async function generateUI() { /* ... */ }
Always sanitize AI-generated content:
import DOMPurify from 'isomorphic-dompurify'
const sanitized = DOMPurify.sanitize(aiContent)
File structure:
app/
actions/
generate-ui.ts # Server actions
components/
ui/
generated/ # Generated UI components
client-wrapper.tsx # Client components
api/
stream-ui/
route.ts # Alternative API route pattern
Required: Proper RSC types
// tsconfig.json
{
"compilerOptions": {
"jsx": "preserve"
"lib": ["dom", "dom.iterable", "esnext"]
"module": "esnext"
"moduleResolution": "bundler"
}
}
import { generateUI } from './actions'
test('generates UI from prompt', async () => {
const ui = await generateUI('Show weather chart')
expect(ui).toMatchSnapshot()
})
Use testing-patterns skill for comprehensive streaming tests
Use case: AI generates form fields dynamically
Template: examples/multi-step-form.tsx
Use case: AI selects appropriate chart type
Template: examples/chart-generator.tsx
Use case: AI creates dashboard widgets
Template: examples/dashboard-generator.tsx
Use case: AI generates content in card layouts
Template: examples/content-cards.tsx
Scripts:
validate-rsc-setup.sh - Verify Next.js and RSC configurationgenerate-ui-component.sh - Scaffold component from patternTemplates:
server-action-pattern.tsx - Complete server action templatestreaming-component.tsx - Streaming component patternclient-wrapper.tsx - Client component wrapperroute-handler.ts - API route alternative patternExamples:
multi-step-form.tsx - Complete multi-step form implementationchart-generator.tsx - Dynamic chart generationdashboard-generator.tsx - Full dashboard examplecontent-cards.tsx - Card-based content layoutSupported Frameworks: Next.js 13.4+ (App Router only) SDK Version: Vercel AI SDK 5+ with RSC support React Version: React 18+ (Server Components)
Best Practice: Always start with validate-rsc-setup.sh to ensure environment compatibility
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.