Archon/archon-ui-main
DIY Smart Code 9f2d70ae0e
Fix Issue #362: Provider-agnostic error handling for all LLM providers (#650)
* feat: Provider-agnostic error handling for Issue #362

Implements generic error handling that works for OpenAI, Google AI,
Anthropic, and other LLM providers to prevent silent failures.

Essential files only:
1. Provider error adapters (new) - handles any LLM provider
2. Backend API key validation - detects invalid keys before operations
3. Frontend error handler - provider-aware error messages
4. Updated hooks - uses generic error handling

Core functionality:
 Validates API keys before expensive operations (crawl, upload, refresh)
 Shows clear provider-specific error messages
 Works with OpenAI: 'Please verify your OpenAI API key in Settings'
 Works with Google: 'Please verify your Google API key in Settings'
 Prevents 90-minute debugging sessions from Issue #362

No unnecessary changes - only essential error handling logic.

Fixes #362

* fix: Enhance API key validation with detailed logging and error handling

- Add comprehensive logging to trace validation flow
- Ensure validation actually blocks operations on authentication failures
- Improve error detection to catch wrapped OpenAI errors
- Fail fast on any validation errors to prevent wasted operations

This should ensure invalid API keys are caught before crawl starts,
not during embedding processing after documents are crawled.

* fix: Simplify API key validation to always fail on exceptions

- Remove complex provider adapter imports that cause module issues
- Simplified validation that fails fast on any embedding creation error
- Enhanced logging to trace exactly what's happening
- Always block operations when API key validation fails

This ensures invalid API keys are caught immediately before
crawl operations start, preventing silent failures.

* fix: Add API key validation to refresh and upload endpoints

The validation was only added to new crawl endpoint but missing from:
- Knowledge item refresh endpoint (/knowledge-items/{source_id}/refresh)
- Document upload endpoint (/documents/upload)

Now all three endpoints that create embeddings will validate API keys
before starting operations, preventing silent failures on refresh/upload.

* security: Implement core security fixes from CodeRabbit review

Enhanced sanitization and provider detection based on CodeRabbit feedback:

 Comprehensive regex patterns for all provider API keys
  - OpenAI: sk-[a-zA-Z0-9]{48} with case-insensitive matching
  - Google AI: AIza[a-zA-Z0-9_-]{35} with flexible matching
  - Anthropic: sk-ant-[a-zA-Z0-9_-]{10,} with variable length

 Enhanced provider detection with multiple patterns
  - Case-insensitive keyword matching (openai, google, anthropic)
  - Regex-based API key detection for reliable identification
  - Additional keywords (gpt, claude, vertex, googleapis)

 Improved sanitization patterns
  - Provider-specific URL sanitization (openai.com, googleapis.com, anthropic.com)
  - Organization and project ID redaction
  - OAuth token and bearer token sanitization
  - Sensitive keyword detection and generic fallback

 Sanitized error logging
  - All error messages sanitized before logging
  - Prevents sensitive data exposure in backend logs
  - Maintains debugging capability with redacted information

Core security improvements while maintaining simplicity for beta deployment.

* fix: Replace ad-hoc error sanitization with centralized ProviderErrorFactory

- Remove local _sanitize_provider_error implementation with inline regex patterns
- Add ProviderErrorFactory import from embeddings.provider_error_adapters
- Update _validate_provider_api_key calls to pass correct active embedding provider
- Replace sanitization call with ProviderErrorFactory.sanitize_provider_error()
- Eliminate duplicate logic and fixed-length key assumptions
- Ensure provider-specific, configurable sanitization patterns are used consistently

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* chore: Remove accidentally committed PRP file

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: address code review feedback

- Add barrel export for providerErrorHandler in utils/index.ts
- Change TypeScript typing from 'any' to 'unknown' for strict type safety

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Rasmus Widing <rasmus.widing@gmail.com>
2025-09-17 13:13:41 +03:00
..
public feat: Ollama Integration with Separate LLM/Embedding Model Support (#643) 2025-09-15 06:38:02 -07:00
src Fix Issue #362: Provider-agnostic error handling for all LLM providers (#650) 2025-09-17 13:13:41 +03:00
tests feat: TanStack Query Migration Phase 3 - Knowledge Base Feature (#605) 2025-09-12 16:45:18 +03:00
.dockerignore feat: TanStack Query Migration Phase 2 - Cleanup and Test Reorganization (#588) 2025-09-06 13:43:53 +03:00
.eslintrc.cjs Removing references to Archon "Alpha" 2025-09-06 14:51:02 -05:00
.gitignore The New Archon (Beta) - The Operating System for AI Coding Assistants! 2025-08-13 07:58:24 -05:00
biome.json feat: TanStack Query Migration Phase 2 - Cleanup and Test Reorganization (#588) 2025-09-06 13:43:53 +03:00
Dockerfile Improve development environment with Docker Compose profiles (#435) 2025-08-22 17:18:10 +03:00
index.html Updating the Logo for Archon 2025-08-18 13:59:49 -05:00
package-lock.json feat: Document Browser with Domain Filtering (Updated Architecture) (#564) 2025-09-06 13:27:17 +03:00
package.json feat: TanStack Query Migration Phase 3 - Knowledge Base Feature (#605) 2025-09-12 16:45:18 +03:00
postcss.config.js The New Archon (Beta) - The Operating System for AI Coding Assistants! 2025-08-13 07:58:24 -05:00
README.md The New Archon (Beta) - The Operating System for AI Coding Assistants! 2025-08-13 07:58:24 -05:00
tailwind.config.js The New Archon (Beta) - The Operating System for AI Coding Assistants! 2025-08-13 07:58:24 -05:00
tsconfig.json feat: TanStack Query Migration Phase 2 - Cleanup and Test Reorganization (#588) 2025-09-06 13:43:53 +03:00
tsconfig.node.json The New Archon (Beta) - The Operating System for AI Coding Assistants! 2025-08-13 07:58:24 -05:00
tsconfig.prod.json feat: TanStack Query Migration Phase 2 - Cleanup and Test Reorganization (#588) 2025-09-06 13:43:53 +03:00
vite.config.ts feat: Ollama Integration with Separate LLM/Embedding Model Support (#643) 2025-09-15 06:38:02 -07:00
vitest.config.ts feat: Ollama Integration with Separate LLM/Embedding Model Support (#643) 2025-09-15 06:38:02 -07:00
vitest.integration.config.ts feat: TanStack Query Migration Phase 3 - Knowledge Base Feature (#605) 2025-09-12 16:45:18 +03:00

Archon UI - Knowledge Engine Web Interface

A modern React-based web interface for the Archon Knowledge Engine MCP Server. Built with TypeScript, Vite, and Tailwind CSS.

🎨 UI Overview

Archon UI provides a comprehensive dashboard for managing your AI's knowledge base:

UI Architecture

Key Features

  • 📊 MCP Dashboard: Monitor and control the MCP server
  • ⚙️ Settings Management: Configure credentials and RAG strategies
  • 🕷️ Web Crawling: Crawl documentation sites and build knowledge base
  • 📚 Knowledge Management: Browse, search, and organize knowledge items
  • 💬 Interactive Chat: Test RAG queries with real-time responses
  • 📈 Real-time Updates: WebSocket-based live updates across the UI

🏗️ Architecture

Technology Stack

  • React 18.3: Modern React with hooks and functional components
  • TypeScript: Full type safety and IntelliSense support
  • Vite: Fast build tool and dev server
  • Tailwind CSS: Utility-first styling
  • Framer Motion: Smooth animations and transitions
  • Lucide Icons: Beautiful and consistent iconography
  • React Router: Client-side routing

Project Structure

archon-ui-main/
├── src/
│   ├── components/          # Reusable UI components
│   │   ├── ui/             # Base UI components (Button, Card, etc.)
│   │   ├── layouts/        # Layout components (Sidebar, Header)
│   │   └── animations/     # Animation components
│   ├── pages/              # Page components
│   │   ├── MCPPage.tsx     # MCP Dashboard
│   │   ├── Settings.tsx    # Settings page
│   │   ├── Crawl.tsx       # Web crawling interface
│   │   ├── KnowledgeBase.tsx # Knowledge management
│   │   └── Chat.tsx        # RAG chat interface
│   ├── services/           # API and service layers
│   │   ├── api.ts          # Base API configuration
│   │   ├── mcpService.ts   # MCP server communication
│   │   └── chatService.ts  # Chat/RAG service
│   ├── contexts/           # React contexts
│   │   └── ToastContext.tsx # Toast notifications
│   ├── hooks/              # Custom React hooks
│   │   └── useStaggeredEntrance.ts # Animation hook
│   ├── types/              # TypeScript type definitions
│   └── lib/                # Utility functions
├── public/                 # Static assets
└── test/                   # Test files

📄 Pages Documentation

1. MCP Dashboard (/mcp)

The central control panel for the MCP server.

Components:

  • Server Control Panel: Start/stop server, view status, select transport mode
  • Server Logs Viewer: Real-time log streaming with auto-scroll
  • Available Tools Table: Dynamic tool discovery and documentation
  • MCP Test Panel: Interactive tool testing interface

Features:

  • Dual transport support (SSE/stdio)
  • Real-time status polling (5-second intervals)
  • WebSocket-based log streaming
  • Copy-to-clipboard configuration
  • Tool parameter validation

2. Settings (/settings)

Comprehensive configuration management.

Sections:

  • Credentials:
    • OpenAI API key (encrypted storage)
    • Supabase connection details
    • MCP server configuration
  • RAG Strategies:
    • Contextual Embeddings toggle
    • Hybrid Search toggle
    • Agentic RAG (code extraction) toggle
    • Reranking toggle

Features:

  • Secure credential storage with encryption
  • Real-time validation
  • Toast notifications for actions
  • Default value management

3. Web Crawling (/crawl)

Interface for crawling documentation sites.

Components:

  • URL Input: Smart URL validation
  • Crawl Options: Max depth, concurrent sessions
  • Progress Monitoring: Real-time crawl status
  • Results Summary: Pages crawled, chunks stored

Features:

  • Intelligent URL type detection
  • Sitemap support
  • Recursive crawling
  • Batch processing

4. Knowledge Base (/knowledge)

Browse and manage your knowledge items.

Components:

  • Knowledge Grid: Card-based knowledge display
  • Search/Filter: Search by title, type, tags
  • Knowledge Details: View full item details
  • Actions: Delete, refresh, organize

Features:

  • Pagination support
  • Real-time updates via WebSocket
  • Type-based filtering (technical/business)
  • Metadata display

5. RAG Chat (/chat)

Interactive chat interface for testing RAG queries.

Components:

  • Chat Messages: Threaded conversation view
  • Input Area: Query input with source selection
  • Results Display: Formatted RAG results
  • Source Selector: Filter by knowledge source

Features:

  • Real-time streaming responses
  • Source attribution
  • Markdown rendering
  • Copy functionality

🧩 Component Library

Base UI Components

Button

<Button 
  variant="primary|secondary|ghost" 
  size="sm|md|lg"
  accentColor="blue|green|purple|orange|pink"
  onClick={handleClick}
>
  Click me
</Button>

Card

<Card accentColor="blue" className="p-6">
  <h3>Card Title</h3>
  <p>Card content</p>
</Card>

LoadingSpinner

<LoadingSpinner size="sm|md|lg" />

Layout Components

Sidebar

  • Collapsible navigation
  • Active route highlighting
  • Icon + text navigation items
  • Responsive design

Header

  • Dark mode toggle
  • User menu
  • Breadcrumb navigation

Animation Components

PageTransition

Wraps pages with smooth fade/slide animations:

<PageTransition>
  <YourPageContent />
</PageTransition>

🔌 Services

mcpService

Handles all MCP server communication:

  • startServer(): Start the MCP server
  • stopServer(): Stop the MCP server
  • getStatus(): Get current server status
  • streamLogs(): WebSocket log streaming
  • getAvailableTools(): Fetch MCP tools

api

Base API configuration with:

  • Automatic error handling
  • Request/response interceptors
  • Base URL configuration
  • TypeScript generics

chatService

RAG query interface:

  • sendMessage(): Send RAG query
  • streamResponse(): Stream responses
  • getSources(): Get available sources

🎨 Styling

Tailwind Configuration

  • Custom color palette
  • Dark mode support
  • Custom animations
  • Responsive breakpoints

Theme Variables

--primary: Blue accent colors
--secondary: Gray/neutral colors
--success: Green indicators
--warning: Orange indicators
--error: Red indicators

🚀 Development

Setup

# Install dependencies
npm install

# Start dev server
npm run dev

# Build for production
npm run build

# Run tests
npm test

Environment Variables

VITE_API_URL=http://localhost:8080

Hot Module Replacement

Vite provides instant HMR for:

  • React components
  • CSS modules
  • TypeScript files

🧪 Testing

Unit Tests

  • Component testing with React Testing Library
  • Service mocking with MSW
  • Hook testing with @testing-library/react-hooks

Integration Tests

  • Page-level testing
  • API integration tests
  • WebSocket testing

📦 Build & Deployment

Docker Support

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 5173
CMD ["npm", "run", "preview"]

Production Optimization

  • Code splitting by route
  • Lazy loading for pages
  • Image optimization
  • Bundle size analysis

🔧 Configuration Files

vite.config.ts

  • Path aliases
  • Build optimization
  • Development server config

tsconfig.json

  • Strict type checking
  • Path mappings
  • Compiler options

tailwind.config.js

  • Custom theme
  • Plugin configuration
  • Purge settings

🤝 Contributing

Code Style

  • ESLint configuration
  • Prettier formatting
  • TypeScript strict mode
  • Component naming conventions

Git Workflow

  • Feature branches
  • Conventional commits
  • PR templates
  • Code review process