Spaces:
Sleeping
Sleeping
| """Pydantic models for request/response schemas.""" | |
| from __future__ import annotations | |
| from enum import Enum | |
| from typing import Any, Optional | |
| from pydantic import BaseModel, Field | |
| # βββ MCP Protocol Models βββββββββββββββββββββββββββββββββββββββββββ | |
| class MCPToolInput(BaseModel): | |
| """MCP tool call input.""" | |
| name: str = Field(..., description="Tool name") | |
| arguments: dict[str, Any] = Field(default_factory=dict, description="Tool arguments") | |
| class MCPToolResult(BaseModel): | |
| """MCP tool call result.""" | |
| content: list[dict[str, Any]] = Field(default_factory=list) | |
| isError: bool = False | |
| class MCPListToolsResponse(BaseModel): | |
| """MCP list tools response.""" | |
| tools: list[dict[str, Any]] | |
| # βββ Tool-Specific Request Models ββββββββββββββββββββββββββββββββββ | |
| class ExecuteCodeRequest(BaseModel): | |
| """Request to execute Python code.""" | |
| code: str = Field(..., description="Python code to execute", min_length=1) | |
| filename: Optional[str] = Field( | |
| default=None, | |
| description="Optional filename (without extension)", | |
| max_length=255, | |
| ) | |
| class InstallDependenciesRequest(BaseModel): | |
| """Request to install Python packages.""" | |
| packages: list[str] = Field( | |
| ..., description="List of package names to install", min_length=1 | |
| ) | |
| class CheckInstalledPackagesRequest(BaseModel): | |
| """Request to check if packages are installed.""" | |
| packages: list[str] = Field( | |
| ..., description="List of package names to check", min_length=1 | |
| ) | |
| class ConfigureEnvironmentRequest(BaseModel): | |
| """Request to configure the execution environment.""" | |
| type: str = Field(..., description="Environment type: conda, venv, or venv-uv") | |
| conda_name: Optional[str] = Field(default=None, description="Conda environment name") | |
| venv_path: Optional[str] = Field(default=None, description="Virtualenv path") | |
| uv_venv_path: Optional[str] = Field(default=None, description="UV virtualenv path") | |
| class InitializeCodeFileRequest(BaseModel): | |
| """Request to initialize a new code file.""" | |
| content: str = Field(..., description="Initial file content", min_length=1) | |
| filename: Optional[str] = Field( | |
| default=None, | |
| description="Optional filename (without extension)", | |
| max_length=255, | |
| ) | |
| class AppendToCodeFileRequest(BaseModel): | |
| """Request to append content to an existing code file.""" | |
| file_path: str = Field(..., description="Path to the existing code file") | |
| content: str = Field(..., description="Content to append", min_length=1) | |
| class FilePathRequest(BaseModel): | |
| """Request with just a file path.""" | |
| file_path: str = Field(..., description="Path to the code file") | |
| # βββ Response Models βββββββββββββββββββββββββββββββββββββββββββββββ | |
| class ExecutionResult(BaseModel): | |
| """Code execution result.""" | |
| success: bool | |
| stdout: str = "" | |
| stderr: str = "" | |
| return_code: int = 0 | |
| file_path: str = "" | |
| execution_time: float = 0.0 | |
| class FileResult(BaseModel): | |
| """File operation result.""" | |
| success: bool | |
| file_path: str = "" | |
| message: str = "" | |
| content: Optional[str] = None | |
| class PackageCheckResult(BaseModel): | |
| """Package check result.""" | |
| package: str | |
| installed: bool | |
| version: Optional[str] = None | |
| class EnvironmentConfig(BaseModel): | |
| """Current environment configuration.""" | |
| env_type: str | |
| conda_env_name: Optional[str] = None | |
| venv_path: Optional[str] = None | |
| uv_venv_path: Optional[str] = None | |
| python_executable: str | |
| code_storage_dir: str | |
| class HealthResponse(BaseModel): | |
| """Health check response.""" | |
| status: str = "healthy" | |
| version: str = "1.0.0" | |
| environment: str = "" | |
| code_storage_dir: str = "" | |
| max_concurrent: int = 0 |