You are an expert in TypeScript, Node.
Add this skill
npx mdskills install PatrickJS/cursor-nextjs-vercel-typescriptComprehensive Next.js/RSC ruleset with AI SDK integration, good structure but includes questionable code patterns
To extend the provided rules to include usage of the ai-sdk-rsc library and integrate it with Vercel middleware and a KV database, here's an updated set of instructions tailored for use with Cursor IDE. These instructions are designed to help you effectively implement generative user interfaces using React Server Components (RSC) with the AI SDK.
Environment and Tools
Code Style and Structure
isLoading, hasError).Naming Conventions
components/auth-wizard).TypeScript Usage
Syntax and Formatting
function keyword for pure functions.UI and Styling
Performance Optimization
use client, useEffect, and setState; favor React Server Components (RSC).Suspense with fallback.Key Conventions
nuqs for URL search parameter state management.use client:
AI SDK RSC Integration
Setup and Installation: Integrate ai-sdk-rsc into your Next.js project.
npm install ai-sdk-rsc or yarn add ai-sdk-rsc.middleware.ts to manage requests and sessions using Vercel's KV database.Middleware Implementation: Use Vercel middleware to handle incoming requests.
middleware directory (e.g., middleware/ai-middleware.ts).import { NextRequest, NextResponse } from 'next/server';
import { kv } from '@vercel/kv';
export async function middleware(req: NextRequest) {
const sessionId = req.cookies.get('session-id');
if (!sessionId) {
const newSessionId = generateSessionId();
await kv.set(newSessionId, { state: {} }); // Initialize state in KV database
const res = NextResponse.next();
res.cookies.set('session-id', newSessionId);
return res;
}
// Fetch state from KV database
const state = await kv.get(sessionId);
req.nextUrl.searchParams.set('state', JSON.stringify(state));
return NextResponse.next();
}
function generateSessionId() {
return Math.random().toString(36).substring(2);
}
React Server Components (RSC) and AI SDK:
ai-sdk-rsc hooks to manage state and stream generative content.import { useAIStream } from 'ai-sdk-rsc';
import { FC } from 'react';
interface ChatProps {
initialMessage: string;
}
const Chat: FC = ({ initialMessage }) => {
const { messages, sendMessage } = useAIStream({
initialMessage,
onMessage: (message) => console.log('New message:', message),
});
return (
{msg.content}
);
export default Chat;
KV Database Integration:
kv.set, kv.get, and kv.delete to manage data.Data Fetching and State Management:
getServerSideProps, getStaticProps) to manage server-side state.useEffect, fetch) except for critical, non-blocking operations.Deployment Considerations:
By following these extended rules, you'll be able to create a well-optimized, scalable, and efficient Next.js application that leverages ai-sdk-rsc, Vercel middleware, and KV database for building sophisticated AI-driven interfaces.
Install via CLI
npx mdskills install PatrickJS/cursor-nextjs-vercel-typescriptNext.js Vercel TypeScript is a free, open-source AI agent skill. You are an expert in TypeScript, Node.
Install Next.js Vercel TypeScript with a single command:
npx mdskills install PatrickJS/cursor-nextjs-vercel-typescriptThis downloads the skill files into your project and your AI agent picks them up automatically.
Next.js Vercel TypeScript works with Cursor. Skills use the open SKILL.md format which is compatible with any AI coding agent that reads markdown instructions.