# @ai-assistant/web Modern web interface for AI Terminal Assistant - built with React, Vite, and Tailwind CSS. ## ๐Ÿ“ฆ Installation ```bash # Install dependencies pnpm install # Start development server pnpm dev # Build for production pnpm build ``` ## ๐ŸŒŸ Features - **Modern UI** - Clean, responsive interface with dark/light themes - **Real-time Chat** - WebSocket-based instant messaging - **Code Editor** - Syntax highlighting with Monaco Editor - **File Browser** - Browse and edit project files - **Terminal Integration** - Embedded terminal for command execution - **Markdown Rendering** - Rich text formatting for AI responses - **PWA Support** - Install as desktop/mobile app - **Mobile Responsive** - Optimized for all screen sizes - **Keyboard Shortcuts** - Efficient navigation and actions ## ๐Ÿ—๏ธ Architecture ``` src/ โ”œโ”€โ”€ components/ โ”‚ โ”œโ”€โ”€ Chat/ # Chat interface components โ”‚ โ”‚ โ”œโ”€โ”€ ChatWindow.tsx โ”‚ โ”‚ โ”œโ”€โ”€ MessageList.tsx โ”‚ โ”‚ โ”œโ”€โ”€ MessageInput.tsx โ”‚ โ”‚ โ””โ”€โ”€ CodeBlock.tsx โ”‚ โ”œโ”€โ”€ Editor/ # Code editor components โ”‚ โ”‚ โ”œโ”€โ”€ MonacoEditor.tsx โ”‚ โ”‚ โ””โ”€โ”€ EditorToolbar.tsx โ”‚ โ”œโ”€โ”€ FileBrowser/ # File navigation โ”‚ โ”‚ โ”œโ”€โ”€ FileTree.tsx โ”‚ โ”‚ โ””โ”€โ”€ FilePreview.tsx โ”‚ โ”œโ”€โ”€ Terminal/ # Terminal emulator โ”‚ โ”‚ โ””โ”€โ”€ XTerminal.tsx โ”‚ โ”œโ”€โ”€ Layout/ # Layout components โ”‚ โ”‚ โ”œโ”€โ”€ Sidebar.tsx โ”‚ โ”‚ โ”œโ”€โ”€ Header.tsx โ”‚ โ”‚ โ””โ”€โ”€ Tabs.tsx โ”‚ โ””โ”€โ”€ Common/ # Shared components โ”‚ โ”œโ”€โ”€ Button.tsx โ”‚ โ”œโ”€โ”€ Modal.tsx โ”‚ โ””โ”€โ”€ Loading.tsx โ”œโ”€โ”€ hooks/ # Custom React hooks โ”‚ โ”œโ”€โ”€ useChat.ts โ”‚ โ”œโ”€โ”€ useWebSocket.ts โ”‚ โ”œโ”€โ”€ useTheme.ts โ”‚ โ””โ”€โ”€ useKeyboard.ts โ”œโ”€โ”€ services/ # API and service layer โ”‚ โ”œโ”€โ”€ api.ts โ”‚ โ”œโ”€โ”€ websocket.ts โ”‚ โ””โ”€โ”€ storage.ts โ”œโ”€โ”€ store/ # State management โ”‚ โ”œโ”€โ”€ chat.store.ts โ”‚ โ”œโ”€โ”€ editor.store.ts โ”‚ โ””โ”€โ”€ settings.store.ts โ”œโ”€โ”€ styles/ # Global styles โ”‚ โ””โ”€โ”€ index.css โ”œโ”€โ”€ types/ # TypeScript definitions โ”œโ”€โ”€ utils/ # Utility functions โ”œโ”€โ”€ App.tsx # Main app component โ””โ”€โ”€ main.tsx # Entry point ``` ## ๐Ÿš€ Quick Start ### Development ```bash # Start development server pnpm dev # The app will be available at http://localhost:5173 # Hot module replacement is enabled for instant updates ``` ### Production Build ```bash # Create optimized build pnpm build # Preview production build pnpm preview # Build output in dist/ directory ``` ## ๐ŸŽจ User Interface ### Main Features #### Chat Interface - **Message History** - Scrollable chat with persistent history - **Code Highlighting** - Syntax highlighting for code blocks - **File Attachments** - Drag & drop file support - **Message Actions** - Copy, edit, regenerate responses - **Streaming Responses** - Real-time AI response streaming #### Code Editor - **Monaco Editor** - VS Code's editor engine - **Multi-file Tabs** - Work with multiple files - **Syntax Highlighting** - 100+ language support - **IntelliSense** - Code completion and hints - **Diff View** - Side-by-side code comparison #### File Browser - **Tree View** - Hierarchical file structure - **Quick Actions** - Create, rename, delete files - **Search** - Fast file search with fuzzy matching - **Preview** - Quick file preview without opening - **Context Menu** - Right-click actions #### Terminal - **XTerm.js** - Full terminal emulation - **Command History** - Navigate previous commands - **Copy/Paste** - Standard clipboard operations - **Themes** - Multiple color schemes ## ๐ŸŽฏ Component Examples ### Using the Chat Component ```tsx import { Chat } from '@ai-assistant/web/components'; function App() { return ( console.log('New message:', message)} theme="dark" /> ); } ``` ### Custom Hook Usage ```tsx import { useChat } from '@ai-assistant/web/hooks'; function MyComponent() { const { messages, sendMessage, isLoading } = useChat({ serverUrl: 'http://localhost:3000', sessionId: 'my-session' }); return (
{messages.map(msg => (
{msg.content}
))}
); } ``` ## โš™๏ธ Configuration ### Environment Variables Create `.env` file: ```env # API Configuration VITE_API_URL=http://localhost:3000 VITE_WS_URL=ws://localhost:3000 VITE_AUTH_TOKEN=your-token-here # Feature Flags VITE_ENABLE_TERMINAL=true VITE_ENABLE_FILE_BROWSER=true VITE_ENABLE_CODE_EDITOR=true # Theme VITE_DEFAULT_THEME=dark ``` ### Build Configuration `vite.config.ts`: ```typescript export default defineConfig({ plugins: [react()], server: { port: 5173, proxy: { '/api': 'http://localhost:3000' } }, build: { outDir: 'dist', sourcemap: true, minify: 'esbuild' } }); ``` ## ๐ŸŽน Keyboard Shortcuts | Shortcut | Action | |----------|--------| | `Ctrl/Cmd + Enter` | Send message | | `Ctrl/Cmd + K` | Clear chat | | `Ctrl/Cmd + /` | Toggle sidebar | | `Ctrl/Cmd + ,` | Open settings | | `Ctrl/Cmd + Shift + P` | Command palette | | `Ctrl/Cmd + B` | Toggle file browser | | `Ctrl/Cmd + J` | Toggle terminal | | `Esc` | Close modal/popup | ## ๐Ÿ“ฑ Progressive Web App The app can be installed as a PWA: 1. Open in Chrome/Edge 2. Click install icon in address bar 3. Or use browser menu: "Install App" Features: - Offline support with service worker - Desktop/mobile app experience - Push notifications (coming soon) - Background sync ## ๐Ÿงช Testing ```bash # Run unit tests pnpm test # Run with coverage pnpm test:coverage # Run E2E tests pnpm test:e2e # Component testing pnpm test:components ``` ### Testing Examples ```tsx import { render, screen } from '@testing-library/react'; import { Chat } from './Chat'; test('renders chat interface', () => { render(); expect(screen.getByPlaceholderText('Type a message...')).toBeInTheDocument(); }); ``` ## ๐ŸŽจ Theming ### Custom Theme ```css /* src/styles/themes/custom.css */ :root[data-theme="custom"] { --primary: #6366f1; --background: #0f172a; --foreground: #f8fafc; --border: #334155; --accent: #8b5cf6; } ``` ### Apply Theme ```tsx import { useTheme } from '@ai-assistant/web/hooks'; function ThemeToggle() { const { theme, setTheme } = useTheme(); return ( ); } ``` ## ๐Ÿ“Š Performance ### Optimization Tips 1. **Code Splitting** - Routes are lazy loaded 2. **Image Optimization** - WebP with fallbacks 3. **Bundle Size** - Tree shaking enabled 4. **Caching** - Service worker caching 5. **Virtual Scrolling** - For long lists ### Bundle Analysis ```bash # Analyze bundle size pnpm build:analyze # Opens visualization in browser ``` ## ๐Ÿš€ Deployment ### Vercel ```bash # Deploy to Vercel vercel deploy --prod ``` ### Docker ```dockerfile FROM node:20-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html EXPOSE 80 ``` ### Static Hosting Build output in `dist/` can be served by any static host: - Netlify - GitHub Pages - CloudFlare Pages - AWS S3 + CloudFront ## ๐Ÿค Contributing See the main repository's contributing guide for details. ## ๐Ÿ“„ License MIT License - see [LICENSE](../../LICENSE) for details. ## ๐Ÿ”— Links - [Main Repository](https://github.com/username/ai-terminal-assistant) - [Component Storybook](https://storybook.example.com) - [Design System](https://design.example.com)