├── .dbrheo.json ├── packages ├── cli │ ├── src │ │ ├── tests │ │ │ └── __init__.py │ │ └── dbrheo_cli │ │ │ ├── app │ │ │ ├── __init__.py │ │ │ └── config.py │ │ │ ├── handlers │ │ │ ├── __init__.py │ │ │ ├── input_handler.py │ │ │ └── event_handler.py │ │ │ ├── ui │ │ │ ├── __init__.py │ │ │ ├── messages.py │ │ │ ├── console.py │ │ │ ├── ascii_art.py │ │ │ ├── startup.py │ │ │ └── tools.py │ │ │ ├── __init__.py │ │ │ ├── utils │ │ │ ├── __init__.py │ │ │ └── api_key_checker.py │ │ │ └── constants.py │ ├── .dbrheo.json │ ├── .gitignore │ ├── cli.py │ ├── pyproject.toml │ └── setup_enhanced_layout.py ├── web │ ├── README.md │ ├── src │ │ ├── main.tsx │ │ ├── styles │ │ │ └── global.css │ │ ├── components │ │ │ ├── chat │ │ │ │ └── ChatContainer.tsx │ │ │ └── database │ │ │ │ ├── QueryEditor.tsx │ │ │ │ └── ResultTable.tsx │ │ └── App.tsx │ ├── tsconfig.node.json │ ├── index.html │ ├── tailwind.config.js │ ├── vite.config.ts │ ├── tsconfig.json │ └── package.json └── core │ ├── src │ └── dbrheo │ │ ├── utils │ │ ├── __init__.py │ │ ├── type_converter.py │ │ ├── parameter_sanitizer.py │ │ ├── retry.py │ │ ├── errors.py │ │ └── log_integration.py │ │ ├── config │ │ ├── __init__.py │ │ └── test_config.py │ │ ├── api │ │ ├── __init__.py │ │ ├── routes │ │ │ ├── __init__.py │ │ │ ├── websocket.py │ │ │ ├── chat.py │ │ │ └── database.py │ │ ├── dependencies.py │ │ └── app.py │ │ ├── adapters │ │ ├── __init__.py │ │ ├── connection_manager.py │ │ └── base.py │ │ ├── services │ │ ├── __init__.py │ │ └── llm_factory.py │ │ ├── telemetry │ │ ├── __init__.py │ │ ├── tracer.py │ │ ├── logger.py │ │ └── metrics.py │ │ ├── tools │ │ ├── __init__.py │ │ └── mcp │ │ │ └── __init__.py │ │ ├── types │ │ ├── __init__.py │ │ ├── core_types.py │ │ ├── file_types.py │ │ └── tool_types.py │ │ ├── core │ │ ├── __init__.py │ │ ├── next_speaker.py │ │ ├── turn.py │ │ ├── compression.py │ │ └── token_statistics.py │ │ ├── prompts(old) │ │ └── optimized_database_prompt.py │ │ ├── __init__.py │ │ ├── __main__.py │ │ └── prompts.py │ └── pyproject.toml ├── logs └── .gitkeep ├── testdata ├── Index ├── old.adult.names └── adult.names ├── requirements.in ├── .claude └── settings.local.json ├── log_config.yaml ├── pyproject.toml ├── .gitignore ├── .env.example └── README.md /.dbrheo.json: -------------------------------------------------------------------------------- 1 | { 2 | "mcp_servers": {} 3 | } -------------------------------------------------------------------------------- /packages/cli/src/tests/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | CLI测试模块 3 | """ -------------------------------------------------------------------------------- /packages/web/README.md: -------------------------------------------------------------------------------- 1 | Web interface is not yet implemented. Please refer to the CLI. 2 | -------------------------------------------------------------------------------- /packages/cli/src/dbrheo_cli/app/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 应用核心模块 3 | 4 | 包含CLI应用的主类、配置管理、生命周期管理等。 5 | """ -------------------------------------------------------------------------------- /packages/cli/src/dbrheo_cli/handlers/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 事件处理器模块 3 | 4 | 处理来自DbRheo核心的各种事件,将其转换为UI操作。 5 | """ -------------------------------------------------------------------------------- /packages/cli/src/dbrheo_cli/ui/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | UI层模块 3 | 4 | 包含所有UI相关的组件和显示逻辑。 5 | 整合了原来的display、components和utils中的UI相关部分。 6 | """ -------------------------------------------------------------------------------- /logs/.gitkeep: -------------------------------------------------------------------------------- 1 | # This file ensures the logs directory is tracked by Git 2 | # Log files will be ignored but the directory structure is preserved 3 | -------------------------------------------------------------------------------- /packages/core/src/dbrheo/utils/__init__.py: -------------------------------------------------------------------------------- 1 | """工具函数模块""" 2 | 3 | from .parameter_sanitizer import sanitize_parameters 4 | 5 | __all__ = ["sanitize_parameters"] -------------------------------------------------------------------------------- /testdata/Index: -------------------------------------------------------------------------------- 1 | Index of adult 2 | 3 | 02 Dec 1996 140 Index 4 | 10 Aug 1996 3974305 adult.data 5 | 10 Aug 1996 4267 adult.names 6 | 10 Aug 1996 2003153 adult.test 7 | -------------------------------------------------------------------------------- /packages/cli/src/dbrheo_cli/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | DbRheo CLI - 智能数据库Agent的命令行界面 3 | 4 | 基于Rich库实现的专业终端UI,提供流畅的交互体验。 5 | """ 6 | 7 | __version__ = "0.2.0" 8 | __author__ = "DbRheo Team" -------------------------------------------------------------------------------- /packages/core/src/dbrheo/config/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 配置管理系统 - 分层配置加载和验证 3 | 支持环境变量、配置文件等多种配置源 4 | """ 5 | 6 | from .base import DatabaseConfig 7 | 8 | __all__ = [ 9 | "DatabaseConfig" 10 | ] 11 | -------------------------------------------------------------------------------- /packages/cli/src/dbrheo_cli/utils/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 工具模块 3 | """ 4 | 5 | from .api_key_checker import check_api_key_for_model, show_api_key_setup_guide 6 | 7 | __all__ = ['check_api_key_for_model', 'show_api_key_setup_guide'] -------------------------------------------------------------------------------- /packages/cli/.dbrheo.json: -------------------------------------------------------------------------------- 1 | { 2 | "mcp_servers": { 3 | "filesystem": { 4 | "command": "npx", 5 | "args": [ 6 | "-y", 7 | "@modelcontextprotocol/server-filesystem", 8 | "/tmp" 9 | ], 10 | "trust": false, 11 | "enabled": true 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /packages/core/src/dbrheo/api/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | API层 - FastAPI应用和路由定义 3 | 提供RESTful API和WebSocket接口 4 | """ 5 | 6 | from .app import create_app 7 | from .routes import chat_router, database_router 8 | 9 | __all__ = [ 10 | "create_app", 11 | "chat_router", 12 | "database_router" 13 | ] 14 | -------------------------------------------------------------------------------- /packages/core/src/dbrheo/api/routes/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | API路由模块 - 组织不同功能的路由 3 | """ 4 | 5 | from .chat import chat_router 6 | from .database import database_router 7 | from .websocket import websocket_router 8 | 9 | __all__ = [ 10 | "chat_router", 11 | "database_router", 12 | "websocket_router" 13 | ] 14 | -------------------------------------------------------------------------------- /packages/core/src/dbrheo/adapters/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 数据库适配器系统 - 支持多数据库方言和连接管理 3 | 提供统一的数据库操作接口,支持MySQL、PostgreSQL、SQLite等 4 | """ 5 | 6 | from .base import DatabaseAdapter 7 | from .connection_manager import DatabaseConnectionManager 8 | 9 | __all__ = [ 10 | "DatabaseAdapter", 11 | "DatabaseConnectionManager" 12 | ] 13 | -------------------------------------------------------------------------------- /packages/core/src/dbrheo/services/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 服务层 - 处理外部API调用和业务服务 3 | 包括Gemini API服务、文件操作服务等 4 | """ 5 | 6 | from .gemini_service_new import GeminiService 7 | from .llm_factory import create_llm_service, LLMServiceFactory 8 | 9 | __all__ = [ 10 | "GeminiService", 11 | "create_llm_service", 12 | "LLMServiceFactory" 13 | ] 14 | -------------------------------------------------------------------------------- /packages/core/src/dbrheo/telemetry/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 监控遥测系统 - 完全对齐Gemini CLI的遥测机制 3 | 提供OpenTelemetry集成、性能监控、错误追踪等功能 4 | """ 5 | 6 | from .tracer import DatabaseTracer 7 | from .metrics import DatabaseMetrics 8 | from .logger import DatabaseLogger 9 | 10 | __all__ = [ 11 | "DatabaseTracer", 12 | "DatabaseMetrics", 13 | "DatabaseLogger" 14 | ] 15 | -------------------------------------------------------------------------------- /packages/web/src/main.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Web应用入口点 3 | * 初始化React应用和全局配置 - DbRheo数据库Agent 4 | */ 5 | import React from 'react' 6 | import ReactDOM from 'react-dom/client' 7 | import App from './App' 8 | import './styles/global.css' 9 | 10 | ReactDOM.createRoot(document.getElementById('root')!).render( 11 | 12 | 13 | 14 | ) 15 | -------------------------------------------------------------------------------- /packages/web/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", 5 | "skipLibCheck": true, 6 | "module": "ESNext", 7 | "moduleResolution": "bundler", 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "types": ["node"] 11 | }, 12 | "include": ["vite.config.ts"] 13 | } -------------------------------------------------------------------------------- /packages/core/src/dbrheo/tools/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 工具系统 - 实现SQLTool和SchemaDiscoveryTool等核心工具 3 | 遵循"工具极简,智能在Agent层"的设计原则 4 | """ 5 | 6 | from .base import DatabaseTool 7 | from .registry import DatabaseToolRegistry 8 | from .sql_tool import SQLTool 9 | from .schema_discovery import SchemaDiscoveryTool 10 | 11 | __all__ = [ 12 | "DatabaseTool", 13 | "DatabaseToolRegistry", 14 | "SQLTool", 15 | "SchemaDiscoveryTool" 16 | ] 17 | -------------------------------------------------------------------------------- /packages/core/src/dbrheo/types/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 类型定义系统 - 完全对齐Gemini CLI的类型系统 3 | 提供核心类型、工具类型、数据库类型等定义 4 | """ 5 | 6 | from .core_types import * 7 | from .tool_types import * 8 | 9 | __all__ = [ 10 | # 核心类型 11 | "Part", 12 | "PartListUnion", 13 | "Content", 14 | "AbortSignal", 15 | 16 | # 工具类型 17 | "ToolResult", 18 | "ToolCallRequestInfo", 19 | "DatabaseConfirmationDetails", 20 | "ToolCall" 21 | ] 22 | -------------------------------------------------------------------------------- /packages/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | DbRheo - 智能数据库Agent 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /packages/web/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: [ 4 | "./index.html", 5 | "./src/**/*.{js,ts,jsx,tsx}", 6 | ], 7 | theme: { 8 | extend: { 9 | fontFamily: { 10 | sans: ['Inter', 'system-ui', 'sans-serif'], 11 | mono: ['JetBrains Mono', 'Consolas', 'monospace'], 12 | }, 13 | colors: { 14 | primary: { 15 | 50: '#eff6ff', 16 | 500: '#3b82f6', 17 | 600: '#2563eb', 18 | 700: '#1d4ed8', 19 | } 20 | } 21 | }, 22 | }, 23 | plugins: [], 24 | } 25 | -------------------------------------------------------------------------------- /packages/cli/.gitignore: -------------------------------------------------------------------------------- 1 | # Python 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | *.so 6 | .Python 7 | build/ 8 | develop-eggs/ 9 | dist/ 10 | downloads/ 11 | eggs/ 12 | .eggs/ 13 | lib/ 14 | lib64/ 15 | parts/ 16 | sdist/ 17 | var/ 18 | wheels/ 19 | *.egg-info/ 20 | .installed.cfg 21 | *.egg 22 | MANIFEST 23 | 24 | # Virtual environments 25 | venv/ 26 | ENV/ 27 | env/ 28 | .venv 29 | 30 | # IDE 31 | .vscode/ 32 | .idea/ 33 | *.swp 34 | *.swo 35 | *~ 36 | 37 | # Testing 38 | .pytest_cache/ 39 | .coverage 40 | htmlcov/ 41 | .tox/ 42 | .mypy_cache/ 43 | .dmypy.json 44 | dmypy.json 45 | 46 | # Logs 47 | *.log 48 | 49 | # OS 50 | .DS_Store 51 | Thumbs.db -------------------------------------------------------------------------------- /packages/core/src/dbrheo/core/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 核心逻辑层 - 实现Turn系统、对话管理、工具调度等核心功能 3 | 完全对齐Gemini CLI的架构设计 4 | """ 5 | 6 | from .client import DatabaseClient 7 | from .chat import DatabaseChat 8 | from .turn import DatabaseTurn 9 | from .scheduler import DatabaseToolScheduler 10 | from .prompts import DatabasePromptManager 11 | from .next_speaker import check_next_speaker 12 | from .compression import try_compress_chat 13 | 14 | __all__ = [ 15 | "DatabaseClient", 16 | "DatabaseChat", 17 | "DatabaseTurn", 18 | "DatabaseToolScheduler", 19 | "DatabasePromptManager", 20 | "check_next_speaker", 21 | "try_compress_chat" 22 | ] 23 | -------------------------------------------------------------------------------- /packages/web/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | import path from 'path' 4 | 5 | // Vite构建配置 - DbRheo Web界面 6 | export default defineConfig({ 7 | plugins: [react()], 8 | resolve: { 9 | alias: { 10 | '@': path.resolve(__dirname, './src'), 11 | }, 12 | }, 13 | server: { 14 | port: 3000, 15 | proxy: { 16 | '/api': { 17 | target: 'http://localhost:8000', 18 | changeOrigin: true, 19 | }, 20 | '/ws': { 21 | target: 'ws://localhost:8000', 22 | ws: true, 23 | }, 24 | }, 25 | }, 26 | build: { 27 | outDir: 'dist', 28 | sourcemap: true, 29 | }, 30 | }) 31 | -------------------------------------------------------------------------------- /packages/web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | 17 | /* Linting */ 18 | "strict": true, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "noFallthroughCasesInSwitch": true, 22 | 23 | /* Path mapping */ 24 | "baseUrl": ".", 25 | "paths": { 26 | "@/*": ["./src/*"] 27 | } 28 | }, 29 | "include": ["src"], 30 | "references": [{ "path": "./tsconfig.node.json" }] 31 | } 32 | -------------------------------------------------------------------------------- /packages/web/src/styles/global.css: -------------------------------------------------------------------------------- 1 | /* 全局样式 - DbRheo Web界面 */ 2 | @tailwind base; 3 | @tailwind components; 4 | @tailwind utilities; 5 | 6 | /* 基础样式重置和全局设置 */ 7 | @layer base { 8 | html { 9 | font-family: 'Inter', system-ui, sans-serif; 10 | } 11 | 12 | body { 13 | @apply bg-gray-50 text-gray-900; 14 | } 15 | } 16 | 17 | /* 组件样式 */ 18 | @layer components { 19 | .btn-primary { 20 | @apply bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition-colors; 21 | } 22 | 23 | .btn-secondary { 24 | @apply bg-gray-200 hover:bg-gray-300 text-gray-900 font-medium py-2 px-4 rounded-md transition-colors; 25 | } 26 | 27 | .card { 28 | @apply bg-white rounded-lg shadow-sm border border-gray-200 p-6; 29 | } 30 | } 31 | 32 | /* 工具样式 */ 33 | @layer utilities { 34 | .text-balance { 35 | text-wrap: balance; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/core/src/dbrheo/api/dependencies.py: -------------------------------------------------------------------------------- 1 | """ 2 | API依赖项 - 提供依赖注入的函数 3 | 避免循环导入问题 4 | """ 5 | 6 | from typing import Dict, Any 7 | from fastapi import HTTPException 8 | 9 | from ..config.base import DatabaseConfig 10 | from ..core.client import DatabaseClient 11 | 12 | # 全局应用状态存储 13 | app_state: Dict[str, Any] = {} 14 | 15 | 16 | def get_client() -> DatabaseClient: 17 | """获取数据库客户端实例""" 18 | if "client" not in app_state: 19 | raise HTTPException(status_code=500, detail="Database client not initialized") 20 | return app_state["client"] 21 | 22 | 23 | def get_config() -> DatabaseConfig: 24 | """获取配置实例""" 25 | if "config" not in app_state: 26 | raise HTTPException(status_code=500, detail="Configuration not initialized") 27 | return app_state["config"] 28 | 29 | 30 | def set_app_state(key: str, value: Any): 31 | """设置应用状态""" 32 | app_state[key] = value 33 | 34 | 35 | def get_app_state(key: str) -> Any: 36 | """获取应用状态""" 37 | return app_state.get(key) -------------------------------------------------------------------------------- /packages/core/src/dbrheo/tools/mcp/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | MCP (Model Context Protocol) integration for DbRheo. 3 | 4 | This module provides a flexible adapter system to integrate MCP servers 5 | and their tools into the DbRheo database agent system. 6 | 7 | Key components: 8 | - MCPConfig: Configuration management for MCP servers 9 | - MCPClientManager: Manages MCP client connections 10 | - MCPToolAdapter: Adapts MCP tools to DbRheo tool interface 11 | - MCPConverter: Handles format conversion between models 12 | """ 13 | 14 | from .mcp_config import MCPConfig, MCPServerConfig 15 | from .mcp_client import MCPClientManager, MCPServerStatus, MCP_AVAILABLE 16 | from .mcp_adapter import MCPToolAdapter 17 | from .mcp_converter import MCPConverter 18 | from .mcp_registry import MCPRegistry 19 | 20 | __all__ = [ 21 | 'MCPConfig', 22 | 'MCPServerConfig', 23 | 'MCPClientManager', 24 | 'MCPServerStatus', 25 | 'MCP_AVAILABLE', 26 | 'MCPToolAdapter', 27 | 'MCPConverter', 28 | 'MCPRegistry', 29 | ] -------------------------------------------------------------------------------- /packages/cli/cli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | DbRheo CLI快速启动脚本 4 | 5 | 用于开发时快速启动CLI,不需要安装。 6 | """ 7 | 8 | import sys 9 | import os 10 | from pathlib import Path 11 | 12 | # 创建一个过滤的stderr包装器 13 | class FilteredStderr: 14 | def __init__(self, original_stderr): 15 | self.original_stderr = original_stderr 16 | 17 | def write(self, text): 18 | # 过滤掉特定的警告 19 | if "there are non-text parts in the response" not in text: 20 | self.original_stderr.write(text) 21 | 22 | def flush(self): 23 | self.original_stderr.flush() 24 | 25 | def __getattr__(self, name): 26 | return getattr(self.original_stderr, name) 27 | 28 | # 替换标准错误输出 29 | sys.stderr = FilteredStderr(sys.stderr) 30 | 31 | # 添加src目录到Python路径 32 | src_path = Path(__file__).parent / "src" 33 | if str(src_path) not in sys.path: 34 | sys.path.insert(0, str(src_path)) 35 | 36 | # 添加core包路径 37 | core_path = Path(__file__).parent.parent / "core" / "src" 38 | if str(core_path) not in sys.path: 39 | sys.path.insert(0, str(core_path)) 40 | 41 | if __name__ == "__main__": 42 | from dbrheo_cli.main import main 43 | main() -------------------------------------------------------------------------------- /packages/core/pyproject.toml: -------------------------------------------------------------------------------- 1 | # Core包配置 - DbRheo核心业务逻辑 2 | 3 | [build-system] 4 | requires = ["setuptools>=61.0", "wheel"] 5 | build-backend = "setuptools.build_meta" 6 | 7 | [project] 8 | name = "dbrheo-core" 9 | version = "1.0.0" 10 | description = "DbRheo数据库Agent核心包" 11 | authors = [{name = "DbRheo Team", email = "team@dbrheo.com"}] 12 | license = {text = "MIT"} 13 | requires-python = ">=3.9" 14 | dependencies = [ 15 | # AI和API 16 | "google-generativeai>=0.8.3", 17 | "google-auth>=2.35.0", 18 | 19 | # 数据库相关 20 | "sqlalchemy[asyncio]>=2.0.36", 21 | "asyncpg>=0.30.0", 22 | "aiomysql>=0.2.0", 23 | "aiosqlite>=0.20.0", 24 | 25 | # 核心依赖 26 | "pydantic>=2.10.0", 27 | "pyyaml>=6.0.2", 28 | "httpx>=0.28.0", 29 | "aiofiles>=24.1.0" 30 | ] 31 | 32 | [project.optional-dependencies] 33 | mcp = [ 34 | "mcp>=1.0.0" 35 | ] 36 | dev = [ 37 | "pytest>=8.3.0", 38 | "pytest-asyncio>=0.24.0", 39 | "black>=24.10.0", 40 | "mypy>=1.13.0", 41 | "ruff>=0.8.0" 42 | ] 43 | 44 | [tool.setuptools.packages.find] 45 | where = ["src"] 46 | include = ["dbrheo*"] 47 | 48 | [tool.setuptools.package-dir] 49 | "" = "src" 50 | -------------------------------------------------------------------------------- /packages/web/src/components/chat/ChatContainer.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 对话容器组件 - 管理与数据库Agent的对话交互 3 | * 实现流式对话、工具调用确认等核心功能 4 | */ 5 | import React from 'react' 6 | 7 | interface ChatContainerProps { 8 | // TODO: 定义props类型 9 | } 10 | 11 | export function ChatContainer(props: ChatContainerProps) { 12 | return ( 13 |
14 |
15 | {/* 消息列表区域 */} 16 |
17 |
18 | 对话容器组件 - 待实现 19 |
20 |
21 |
22 | 23 |
24 | {/* 消息输入区域 */} 25 |
26 | 31 | 34 |
35 |
36 |
37 | ) 38 | } 39 | 40 | export default ChatContainer 41 | -------------------------------------------------------------------------------- /requirements.in: -------------------------------------------------------------------------------- 1 | # DbRheo Project Dependencies 2 | # This file contains the high-level dependencies 3 | # Use pip-compile to generate requirements.txt with exact versions 4 | 5 | # Web Framework and Server 6 | fastapi>=0.116.0 7 | uvicorn[standard]>=0.35.0 8 | 9 | # Database Related 10 | sqlalchemy[asyncio]>=2.0.42 11 | asyncpg>=0.30.0 12 | aiomysql>=0.2.0 13 | aiosqlite>=0.21.0 14 | 15 | # AI and API 16 | google-genai>=1.0.0 # 新版Gemini SDK,支持显式缓存 17 | anthropic>=0.34.0 # Claude API support 18 | openai>=1.0.0 # OpenAI GPT API support 19 | 20 | # Core Dependencies 21 | pydantic>=2.11.7 22 | pyyaml>=6.0.2 23 | rich>=14.1.0 24 | rich-gradient>=0.1.2 25 | pygments>=2.17.2 # 代码高亮支持,Rich的Syntax组件需要 26 | click>=8.2.1 27 | python-dotenv>=1.0.0 28 | 29 | # Cross-platform readline support 30 | pyreadline3>=3.5.4; sys_platform == "win32" 31 | gnureadline>=8.2.10; sys_platform != "win32" 32 | 33 | # Utility Libraries 34 | aiofiles>=24.1.0 35 | httpx>=0.28.1 36 | 37 | # Network and Parsing 38 | aiohttp>=3.12.0 39 | beautifulsoup4>=4.13.4 40 | requests>=2.32.4 41 | 42 | # Monitoring and Telemetry (Optional) 43 | opentelemetry-api>=1.36.0 44 | opentelemetry-sdk>=1.36.0 45 | opentelemetry-exporter-otlp>=1.36.0 46 | opentelemetry-instrumentation-httpx>=0.57b0 47 | 48 | # MCP (Model Context Protocol) Support 49 | mcp>=1.0.0 50 | -------------------------------------------------------------------------------- /.claude/settings.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "allow": [ 4 | "Bash(chmod:*)", 5 | "Bash(python test:*)", 6 | "Bash(find:*)", 7 | "WebFetch(domain:docs.anthropic.com)", 8 | "Bash(pip install:*)", 9 | "Bash(python3:*)", 10 | "Bash(rm:*)", 11 | "Bash(python -m mypy:*)", 12 | "Bash(mkdir:*)", 13 | "Bash(grep:*)", 14 | "Bash(pip show:*)", 15 | "WebFetch(domain:discuss.ai.google.dev)", 16 | "WebFetch(domain:ai.google.dev)", 17 | "Bash(python:*)", 18 | "WebFetch(domain:pypi.org)", 19 | "WebFetch(domain:github.com)", 20 | "Bash(cp:*)", 21 | "Bash(mv:*)", 22 | "WebFetch(domain:medium.com)", 23 | "Bash(pip3 show:*)", 24 | "WebFetch(domain:googleapis.github.io)", 25 | "Bash(/mnt/c/Users/q9951/anaconda3/python.exe test_config_priority.py)", 26 | "Bash(/mnt/c/Users/q9951/anaconda3/python.exe test_cache_with_system.py)", 27 | "Bash(/mnt/c/Users/q9951/anaconda3/Scripts/pip.exe show google-genai)", 28 | "Bash(/mnt/c/Users/q9951/anaconda3/python.exe -m dbrheo_cli.main --debug --no-color)", 29 | "Bash(/mnt/c/Users/q9951/anaconda3/python.exe src/dbrheo_cli/main.py --help)", 30 | "Bash(/mnt/c/Users/q9951/anaconda3/Scripts/pip.exe install -e packages/core)", 31 | "Bash(/mnt/c/Users/q9951/anaconda3/Scripts/pip.exe install -e packages/cli)", 32 | "WebFetch(domain:modelcontextprotocol.io)" 33 | ], 34 | "deny": [] 35 | } 36 | } -------------------------------------------------------------------------------- /packages/web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@dbrheo/web", 3 | "version": "1.0.0", 4 | "type": "module", 5 | "description": "DbRheo数据库Agent Web界面", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "preview": "vite preview", 10 | "test": "vitest", 11 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0" 12 | }, 13 | "dependencies": { 14 | "react": "^19.1.0", 15 | "react-dom": "^19.1.0", 16 | "@monaco-editor/react": "^4.6.0", 17 | "@tanstack/react-query": "^5.62.0", 18 | "zustand": "^5.0.2", 19 | "socket.io-client": "^4.8.1", 20 | "lucide-react": "^0.468.0", 21 | "@radix-ui/react-dialog": "^1.1.2", 22 | "@radix-ui/react-toast": "^1.2.2", 23 | "clsx": "^2.1.1", 24 | "tailwind-merge": "^2.5.4", 25 | "date-fns": "^4.1.0", 26 | "zod": "^3.24.1" 27 | }, 28 | "devDependencies": { 29 | "@types/react": "^19.1.8", 30 | "@types/react-dom": "^19.1.6", 31 | "@typescript-eslint/eslint-plugin": "^8.30.1", 32 | "@typescript-eslint/parser": "^8.30.1", 33 | "@vitejs/plugin-react": "^4.3.4", 34 | "eslint": "^9.24.0", 35 | "eslint-plugin-react-hooks": "^5.2.0", 36 | "eslint-plugin-react-refresh": "^0.4.16", 37 | "typescript": "^5.3.3", 38 | "vite": "^6.0.3", 39 | "vitest": "^3.2.4", 40 | "tailwindcss": "^3.4.17", 41 | "autoprefixer": "^10.4.20", 42 | "postcss": "^8.5.1" 43 | }, 44 | "engines": { 45 | "node": ">=20" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/cli/src/dbrheo_cli/ui/messages.py: -------------------------------------------------------------------------------- 1 | """ 2 | 消息显示组件 3 | 定义各种消息类型的显示方式: 4 | - UserMessage: 用户输入消息 5 | - AgentMessage: AI响应消息 6 | - SystemMessage: 系统消息 7 | - ErrorMessage: 错误消息 8 | 9 | 对应Gemini CLI的各种Message组件。 10 | """ 11 | 12 | from typing import Optional 13 | from .console import console 14 | from ..i18n import _ 15 | 16 | 17 | # 消息前缀定义(便于后续自定义) 18 | MESSAGE_PREFIXES = { 19 | 'user': '> ', 20 | 'agent': '', 21 | 'system': '# ', 22 | 'error': '✗ ', 23 | 'tool': ' → ' 24 | } 25 | 26 | 27 | def show_user_message(message: str): 28 | """显示用户消息""" 29 | prefix = MESSAGE_PREFIXES['user'] 30 | console.print(f"\n[bold]{prefix}{message}[/bold]") 31 | console.print() # 添加空行 32 | 33 | 34 | def show_agent_message(message: str, end: str = '\n'): 35 | """显示AI响应消息""" 36 | # Agent消息无前缀,直接显示 37 | console.print(message, end=end) 38 | 39 | 40 | def show_system_message(message: str): 41 | """显示系统消息""" 42 | prefix = MESSAGE_PREFIXES['system'] 43 | console.print(f"[dim]{prefix}{message}[/dim]") 44 | 45 | 46 | def show_tool_call(tool_name: str): 47 | """显示工具调用提示""" 48 | console.print(f"\n[cyan][{_('tool_executing', tool_name=tool_name)}][/cyan]", end='') 49 | 50 | 51 | def show_error_message(message: str): 52 | """显示错误消息""" 53 | prefix = MESSAGE_PREFIXES['error'] 54 | console.print(f"[error]{prefix}{message}[/error]") 55 | 56 | 57 | def show_tool_message(tool_name: str, message: str): 58 | """显示工具消息""" 59 | prefix = MESSAGE_PREFIXES['tool'] 60 | console.print(f"[info]{prefix}[{tool_name}] {message}[/info]") -------------------------------------------------------------------------------- /packages/web/src/components/database/QueryEditor.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * SQL查询编辑器组件 - 基于Monaco Editor 3 | * 提供SQL语法高亮、自动补全、错误检查等功能 4 | */ 5 | import React from 'react' 6 | 7 | interface QueryEditorProps { 8 | value?: string 9 | onChange?: (value: string) => void 10 | readOnly?: boolean 11 | } 12 | 13 | export function QueryEditor({ value = '', onChange, readOnly = false }: QueryEditorProps) { 14 | return ( 15 |
16 |
17 |
18 | SQL编辑器 19 |
20 | 23 | 26 |
27 |
28 |
29 | 30 |
31 |