|
|
3 недель назад | |
|---|---|---|
| .. | ||
| public | 3 месяцев назад | |
| src | 3 недель назад | |
| .gitignore | 3 месяцев назад | |
| COMPONENT_EXAMPLES.md | 2 месяцев назад | |
| README.md | 2 месяцев назад | |
| eslint.config.js | 3 месяцев назад | |
| index.html | 3 месяцев назад | |
| package.json | 2 месяцев назад | |
| postcss.config.js | 3 месяцев назад | |
| tailwind.config.js | 3 месяцев назад | |
| tsconfig.app.json | 3 месяцев назад | |
| tsconfig.json | 3 месяцев назад | |
| tsconfig.node.json | 3 месяцев назад | |
| vite.config.ts | 3 месяцев назад | |
| vitest.config.ts | 2 месяцев назад | |
This document provides an overview of the WebGUI component architecture.
The codebase follows these key principles:
src/
├── components/ # React components
│ ├── common/ # Reusable UI components (Button, Modal, Input, etc.)
│ ├── MessageInput/ # Message input editor (refactored from 1153 lines)
│ ├── MessageList/ # Message list and rendering (refactored from 782 lines)
│ ├── CompactHeader/ # Header with session management (refactored from 655 lines)
│ ├── SettingsPanel/ # Settings panel orchestrator (refactored from 296 lines)
│ ├── DiffModal/ # Diff viewer modal (refactored from 413 lines)
│ ├── parts/ # Message part renderers
│ │ └── ToolPart/ # Tool part renderer (refactored from 682 lines)
│ ├── settings/ # Settings tab components
│ │ └── ApiKeysTab/ # API key management (refactored from 524 lines)
│ └── mention/ # Mention-related components
│ └── MentionPlugin/ # Lexical mention plugin (refactored from 284 lines)
├── hooks/ # Shared custom hooks
├── utils/ # Utility functions
├── state/ # State management (Context/Zustand)
├── lib/ # Third-party integrations
└── test/ # Test setup and utilities
Complex message input editor with Lexical, file attachments, mentions, and keyboard shortcuts.
Structure:
MessageInput/
├── index.tsx # Main orchestrator
├── EditorConfig.ts # Lexical configuration
├── EditorToolbar.tsx # Model/agent/file buttons
├── EditorContent.tsx # Main editor area
├── MessageActions.tsx # Send/stop/compact buttons
├── RetryBanner.tsx # Retry on error banner
└── hooks/
├── useMessageInput.ts # Message submission logic
├── useFileAttachment.ts # File handling
├── useDragDrop.ts # Drag and drop
└── useEditorKeyboard.ts # Keyboard shortcuts
Key Features:
Renders message history with multiple part types, scrolling, and fork/revert functionality.
Structure:
MessageList/
├── index.tsx # Main orchestrator
├── MessageRow.tsx # Single message row
├── MessagePart.tsx # Part renderer dispatcher
├── TextPart.tsx # Text with mentions
├── ReasoningPart.tsx # Thinking blocks
├── CollapsiblePart.tsx # Reusable collapsible
├── EmptyState.tsx # No messages state
├── RevertBanner.tsx # Revert status banner
├── RevertSummary.tsx # Inline revert summary
├── ActionButtons.tsx # Fork/undo buttons
└── hooks/
├── useMessageScroll.ts # Scroll management
└── useMessageActions.ts # Fork/revert logic
Key Features:
Renders tool invocations with syntax highlighting and interactive features.
Structure:
parts/ToolPart/
├── index.tsx # Main dispatcher
├── BashTool.tsx # Bash command renderer
├── ReadTool.tsx # File read renderer
├── WriteTool.tsx # File write renderer
├── EditTool.tsx # File edit renderer (with diffs)
├── TodoTool.tsx # Todo list renderer
├── GenericOutput.tsx # Generic tool output
├── ToolHeader.tsx # Common tool header
├── PermissionBanner.tsx # Permission handling
├── PatchInfo.tsx # Patch information
├── ToolDetails.tsx # Collapsible details
├── ErrorDisplay.tsx # Error display
├── TimingInfo.tsx # Timing information
└── utils.tsx # Shared utilities
Key Features:
Header with session management, usage display, and action buttons.
Structure:
CompactHeader/
├── index.tsx # Main component
├── StatusIndicator.tsx # Connection status dot
├── ActionButtons.tsx # Theme/settings/new session
├── UsageDisplay.tsx # Usage metrics
├── SessionDropdown.tsx # Session dropdown menu
├── SessionList.tsx # Session list rendering
├── SessionItem.tsx # Individual session item
├── utils.ts # Formatting utilities
└── hooks/
├── useSessionDropdown.ts # Dropdown state & keyboard
└── useSessionActions.ts # Edit/delete operations
Key Features:
API key management with OAuth support.
Structure:
settings/ApiKeysTab/
├── index.tsx # Main component
├── ProviderCard.tsx # Individual provider config
├── KeyInput.tsx # Secure key input
├── OAuthSection.tsx # OAuth login UI
├── ManualCodeInput.tsx # Manual code entry
├── ProviderDropdown.tsx # Add provider dropdown
├── EmptyState.tsx # No providers state
├── utils.ts # Utilities
└── hooks/
├── useApiKeys.ts # API key management
├── useOAuthFlow.ts # OAuth authentication
└── useProviderManagement.ts # Add/delete providers
Modal for viewing file diffs with navigation.
Structure:
DiffModal/
├── index.tsx # Modal wrapper
├── DiffViewer.tsx # Diff display
├── DiffNavigation.tsx # File tabs navigation
├── DiffHeader.tsx # Header with view mode
├── utils.ts # Diff computation
└── hooks/
└── useDiffData.ts # Diff data management
Settings panel with tab navigation.
Structure:
SettingsPanel/
├── index.tsx # Main component
├── TabBar.tsx # Tab navigation
├── SettingsHeader.tsx # Header with close button
├── SettingsFooter.tsx # Save/cancel buttons
└── hooks/
├── useSettingsForm.ts # Form state
└── useUnsavedChanges.ts # Change detection
Lexical plugin for @ mentions.
Structure:
mention/MentionPlugin/
├── index.tsx # Main plugin
├── MentionDetector.tsx # @ detection logic
├── MentionHandler.tsx # Mention creation
└── utils.ts # Helper functions
Reusable UI components following the existing design system.
See components/common/README.md for detailed documentation.
Reusable hooks for common functionality.
Centralized utilities for consistent behavior.
See utils/README.md for detailed documentation.
bun run test - Run tests in watch modebun run test:ui - Open Vitest UIbun run test:run - Run tests oncebun run test:coverage - Generate coverage reportsrc/
├── test/
│ ├── setup.ts # Test configuration
│ └── test-utils.tsx # Testing utilities
├── components/common/
│ ├── Button.test.tsx # Button component tests
│ ├── IconButton.test.tsx
│ ├── Modal.test.tsx
│ ├── Input.test.tsx
│ ├── Select.test.tsx
│ └── Card.test.tsx
├── hooks/
│ ├── useDebounce.test.ts
│ ├── useLocalStorage.test.ts
│ ├── useClickOutside.test.ts
│ └── useKeyboard.test.ts
└── utils/
├── classNames.test.ts
├── formatting.test.ts
└── validation.test.ts
Use barrel exports for cleaner imports:
// Common components
import { Button, Modal, Input } from "@/components/common"
// Utilities
import { cn, formatDate, isValidEmail } from "@/utils"
// Hooks
import { useDebounce, useLocalStorage } from "@/hooks"
Components maintain their original import paths:
// Before refactoring
import MessageInput from "@/components/MessageInput"
// After refactoring (same path!)
import MessageInput from "@/components/MessageInput"
All refactored components meet these targets:
If you're working with code that references old monolithic components:
Replace custom implementations with common components:
// Before
<button className="modern-button button-primary">
Click me
</button>
// After
import { Button } from '@/components/common'
<Button variant="primary">Click me</Button>
Replace custom implementations with shared hooks:
// Before
useEffect(() => {
const handler = (e: MouseEvent) => {
if (!ref.current?.contains(e.target)) {
close()
}
}
document.addEventListener("mousedown", handler)
return () => document.removeEventListener("mousedown", handler)
}, [])
// After
import { useClickOutside } from "@/hooks"
useClickOutside(ref, close)
For questions or issues with the component architecture: