Spaces:
Sleeping
Sleeping
File size: 4,036 Bytes
a234ba5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | """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 |