A modern React SPA that provides a seamless chat interface for interacting with your local AI through the Bodhi Browser Extension. Built with TypeScript, React 18, and Vite for optimal performance and developer experience.
- π€ AI Chat Interface: Stream-based conversations with local AI models
- π Model Selection: Dynamic model selection from
/v1/models
endpoint - π¬ Real-time Streaming: Live streaming responses for better UX
- π New Chat: Start fresh conversations anytime
- π± Responsive Design: Works seamlessly on desktop and mobile
- β‘ Fast Performance: Built with Vite for lightning-fast development
- π§ͺ Comprehensive Testing: Full test coverage with Vitest
- π¨ Modern UI: Clean, intuitive interface with smooth animations
Before running this application, ensure you have:
- Bodhi Browser Extension installed and active
- Bodhi App Server running locally
- Node.js (v18 or higher)
- npm or yarn package manager
-
Clone and navigate to the project:
cd webchat
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:5173
npm run dev
- Start development servernpm run build
- Build for productionnpm run preview
- Preview production buildnpm run lint
- Run ESLintnpm run test
- Run testsnpm run test:ui
- Run tests with UI
- System Check: The app automatically verifies that the Bodhi Browser Extension is installed and the server is running
- Model Selection: Choose your preferred AI model from the dropdown
- Start Chatting: Type your message and press Enter or click Send
- Streaming Response: Watch as the AI responds in real-time
- New Chat: Click "New Chat" to start a fresh conversation
- Enter: Send message
- Shift + Enter: New line in message input
The application gracefully handles various error scenarios:
- Extension not installed
- Server unavailable
- Network connectivity issues
- API errors
src/
βββ components/ # Reusable UI components
β βββ ChatInput.tsx # Message input with auto-resize
β βββ ChatInterface.tsx # Message display and streaming
β βββ ModelSelector.tsx # Model selection dropdown
β βββ NewChatButton.tsx # New chat functionality
β βββ ErrorBoundary.tsx # Error handling wrapper
βββ hooks/ # Custom React hooks
β βββ useChat.ts # Chat state and streaming logic
β βββ useModels.ts # Model fetching and management
β βββ useSystemStatus.ts # Extension/server status
βββ pages/ # Page components
β βββ ChatPage.tsx # Main chat page
βββ types/ # TypeScript definitions
β βββ index.ts # Shared interfaces
βββ styles/ # CSS styles
β βββ App.css # Application styles
βββ __tests__/ # Test files
βββ components/ # Component tests
βββ hooks/ # Hook tests
- React 18: Latest React with concurrent features
- TypeScript: Type safety and better developer experience
- React Router: Client-side routing
- Vite: Fast build tool and dev server
- Vitest: Fast unit testing framework
- @bodhiapp/bodhijs: Integration with Bodhi ecosystem
This application integrates with the Bodhi ecosystem through:
- Extension Detection: Uses
isInstalled()
to verify extension presence - Server Communication: Leverages
isServerAvailable()
for connectivity checks - Model Discovery: Fetches available models via
/v1/models
endpoint - Chat API: Utilizes streaming chat completions for real-time responses
React App β bodhijs Library β Browser Extension β Bodhi App Server
β β
βββββββββββββ Streaming Response βββββββββββββββββββββββ
The application uses CSS custom properties for easy theming. Key variables:
:root {
--primary-color: #1a73e8;
--background-color: #f5f5f5;
--text-color: #374151;
/* ... more variables */
}
- New Components: Add to
src/components/
- New Hooks: Add to
src/hooks/
- New Types: Update
src/types/index.ts
- Tests: Add corresponding test files
The application includes comprehensive tests:
# Run all tests
npm run test
# Run tests with coverage
npm run test -- --coverage
# Run tests in watch mode
npm run test -- --watch
# Run specific test file
npm run test ChatInput.test.tsx
- Component Tests: UI behavior and user interactions
- Hook Tests: Custom hook logic and state management
- Integration Tests: End-to-end functionality
# Build the application
npm run build
# Preview the production build
npm run preview
The built files will be in the dist/
directory, ready for deployment to any static hosting service.
-
Extension Not Detected
- Ensure Bodhi Browser Extension is installed and enabled
- Check browser console for extension-related errors
-
Server Connection Failed
- Verify Bodhi App Server is running
- Check server URL and port configuration
-
Models Not Loading
- Ensure
/v1/models
endpoint is accessible - Check network connectivity to local server
- Ensure
-
Streaming Issues
- Verify browser supports streaming APIs
- Check for network interruptions
-
TypeScript Errors
- Run
npm run build
to check for type errors - Ensure all dependencies are properly typed
- Run
-
Test Failures
- Run tests individually to isolate issues
- Check mock configurations in test setup
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Add tests for new functionality
- Ensure all tests pass:
npm run test
- Build successfully:
npm run build
- Submit a pull request
This project is part of the Bodhi Browser ecosystem. See the main repository for license information.
For issues and questions:
- Check the troubleshooting section above
- Review the Bodhi Browser Extension documentation
- File issues in the main Bodhi Browser repository