π Languages: English | Π ΡΡΡΠΊΠΈΠΉ
A Next.js application demonstrating Vercel AI SDK v5 (beta) capabilities with Google Generative AI, featuring real-time progress tracking for multi-step tool operations.
streaming-demo.mp4
See the AI tool streaming in action with real-time progress updates
π Complete Technical Implementation Guide - Step-by-step guide showing exactly how to implement real-time tool progress streaming with Vercel AI SDK v5. Includes full code examples, data flow diagrams, and debugging tips.
- AI Chat Interface: Modern chat UI built with shadcn/ui components
- Multi-Step Tool Execution:
sampleCreateTool
that simulates project creation with multiple stages - Real-Time Progress Updates: Visual progress indicators with spinners and checkmarks
- Streaming Data: Real-time UI updates as tasks progress
- Internationalization: Support for English and Russian languages with automatic detection
- Theme System: Light/dark/system theme support with user preferences
- Environment Configuration: Customizable defaults for language and theme
- TypeScript: Full type safety throughout the application
- Tailwind CSS 4: Modern styling with the latest Tailwind features
- Next.js 15.4 with App Router
- Vercel AI SDK v5 (beta) for AI integration
- Google Generative AI (Gemini 2.5 Flash)
- TypeScript for type safety
- Tailwind CSS 4 for styling
- shadcn/ui for UI components
- Lucide React for icons
- Node.js 18+
- npm or yarn
- Google AI API Key (from Google AI Studio)
-
Clone and Install Dependencies
git clone <repository-url> cd ai-sdk-new-chat npm install
-
Configure Environment Variables
Create a
.env.local
file in the root directory:# Required: Google AI API Key GOOGLE_GENERATIVE_AI_API_KEY=your-google-ai-api-key-here # Optional: Default language (en | ru) # NEXT_PUBLIC_DEFAULT_LANGUAGE=en # Optional: Default theme (light | dark | system) # NEXT_PUBLIC_DEFAULT_THEME=system
Get your API key from Google AI Studio.
-
Run the Development Server
npm run dev
Open http://localhost:3000 in your browser.
The application supports automatic language detection and manual configuration:
- Automatic Detection: Detects browser language and uses Russian for Slavic languages (ru, be, uk)
- Environment Override: Set
NEXT_PUBLIC_DEFAULT_LANGUAGE=en
orNEXT_PUBLIC_DEFAULT_LANGUAGE=ru
- User Preference: Users can switch language manually using the language switcher in the UI
The application includes a comprehensive theme system:
- System Theme: Automatically follows user's OS theme preference (default)
- Environment Override: Force specific theme with
NEXT_PUBLIC_DEFAULT_THEME
:light
: Always use light themedark
: Always use dark themesystem
: Follow OS preference (default)
- User Preference: Users can override theme using the theme switcher in the UI
- Persistence: User choices are saved to localStorage
Priority Order:
- User manual selection (highest priority)
- Environment variable setting
- System/OS preference (fallback)
For Russian-language dark theme environment:
NEXT_PUBLIC_DEFAULT_LANGUAGE=ru
NEXT_PUBLIC_DEFAULT_THEME=dark
For English-language light theme environment:
NEXT_PUBLIC_DEFAULT_LANGUAGE=en
NEXT_PUBLIC_DEFAULT_THEME=light
For system preferences (default behavior):
# Comment out or omit both variables to use auto-detection
# NEXT_PUBLIC_DEFAULT_LANGUAGE=en
# NEXT_PUBLIC_DEFAULT_THEME=system
-
Start a Conversation: Type a message requesting project creation, such as:
- "Create a new React project called MyApp"
- "Build a complex web application"
- "Set up a simple project for me"
-
Watch Progress: The AI will use the
sampleCreateTool
to simulate multi-step project creation with:- Real-time progress indicators
- Spinning loaders for active tasks
- Green checkmarks for completed tasks
- Time tracking for each step and total execution
-
Project Complexity: The tool supports three complexity levels:
- Simple: 3 basic steps (6-9 seconds)
- Medium: 5 steps with build tools (12-20 seconds)
- Complex: 7 steps with CI/CD and monitoring (21-35 seconds)
src/
βββ app/
β βββ api/chat/route.ts # AI Chat API endpoint
β βββ globals.css # Global styles with Tailwind CSS 4
β βββ layout.tsx # Root layout with theme initialization
β βββ page.tsx # Main chat page
βββ components/
β βββ ui/ # shadcn/ui components
β β βββ button.tsx
β β βββ card.tsx
β β βββ input.tsx
β β βββ spinner.tsx
β β βββ language-switcher.tsx # Language selection dropdown
β β βββ theme-switcher.tsx # Theme selection dropdown
β βββ chat/
β β βββ chat-interface.tsx # Main chat component
β β βββ message-list.tsx # Messages display
β β βββ tool-progress.tsx # Progress indicator UI
β β βββ progress-item.tsx # Individual progress item
β βββ language-provider.tsx # i18n context and logic
β βββ theme-provider.tsx # Theme context with env support
βββ lib/
β βββ tools.ts # sampleCreateTool implementation
β βββ utils.ts # Utility functions
βββ types/
β βββ chat.ts # TypeScript type definitions
βββ public/
βββ messages/ # Translation files
βββ en.json # English translations
βββ ru.json # Russian translations
The application demonstrates how to create engaging user experiences with long-running AI tool operations:
- Visual Feedback: Each step shows a spinner while in progress
- Status Updates: Real-time transitions from pending β in-progress β completed
- Time Tracking: Individual step duration and total execution time
- Responsive UI: Smooth animations and state transitions
This project showcases several AI SDK v5 capabilities:
- Tool Calling: Structured tool definitions with Zod schemas
- Streaming Responses: Real-time message and tool result streaming
- Message Metadata: Enhanced message structure for tool invocations
- Error Handling: Proper error boundaries and loading states
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Lint code
npm run lint
- Real-Time Streaming Implementation: Technical Guide - Complete implementation guide for AI tool progress streaming
- Product Specifications: Product Documentation - Detailed technical specifications and reference documentation
- API Key Issues: Ensure your Google AI API key is correctly set in
.env.local
- Build Errors: Make sure all dependencies are installed with
npm install
- Port Conflicts: The default port is 3000; set
PORT
environment variable to change it - Streaming Issues: Check browser developer tools for WebSocket or SSE connection errors
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is for demonstration purposes. Please check individual package licenses for production use.
Built with β€οΈ using Vercel AI SDK v5 (beta) and Next.js 15