refactor: reorganize into monorepo with separate subprojects
Structure webber into three independent subprojects: - webber-api/: FastAPI backend server with all agent code - webber-cli/: Standalone CLI client (renamed from cli/ to webber_cli/) - webber-sandbox/: Test project for functional testing Key changes: - Each subproject has its own .venv (Python 3.12+) - Added sandbox.sh for managing test project templates - Created sandbox-templates/ with calculator-cli and empty starter - Updated CI/CD for prefixed tags (api/v*, cli/v*) - Added comprehensive AGENTS.md with operational instructions - Added gitignore filtering to glob and grep tools - Created pyproject.toml for each subproject Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
"""
|
||||
Webber API client.
|
||||
|
||||
Communicates with the Webber API backend for agent execution.
|
||||
"""
|
||||
import httpx
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass
|
||||
class AgentResponse:
|
||||
"""Response from agent execution."""
|
||||
response: str
|
||||
agent_type: str
|
||||
success: bool
|
||||
error: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class AgentInfo:
|
||||
"""Information about an available agent."""
|
||||
name: str
|
||||
description: str
|
||||
|
||||
|
||||
class WebberClient:
|
||||
"""
|
||||
Client for the Webber API.
|
||||
|
||||
Usage:
|
||||
client = WebberClient("http://localhost:8086")
|
||||
response = await client.run_agent("explore", "find python files", "/path/to/project")
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
base_url: str = "http://localhost:8086",
|
||||
api_key: str | None = None,
|
||||
timeout: float = 120.0,
|
||||
):
|
||||
"""
|
||||
Initialize the Webber client.
|
||||
|
||||
Args:
|
||||
base_url: Webber API URL
|
||||
api_key: Optional API key for authentication
|
||||
timeout: Request timeout in seconds
|
||||
"""
|
||||
self.base_url = base_url.rstrip("/")
|
||||
self.api_key = api_key
|
||||
self.timeout = timeout
|
||||
self._client: httpx.AsyncClient | None = None
|
||||
|
||||
async def _get_client(self) -> httpx.AsyncClient:
|
||||
"""Get or create the HTTP client."""
|
||||
if self._client is None or self._client.is_closed:
|
||||
headers = {}
|
||||
if self.api_key:
|
||||
headers["X-API-Key"] = self.api_key
|
||||
self._client = httpx.AsyncClient(
|
||||
base_url=self.base_url,
|
||||
headers=headers,
|
||||
timeout=self.timeout,
|
||||
)
|
||||
return self._client
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Close the HTTP client."""
|
||||
if self._client and not self._client.is_closed:
|
||||
await self._client.aclose()
|
||||
self._client = None
|
||||
|
||||
async def health_check(self) -> bool:
|
||||
"""Check if the API is healthy."""
|
||||
try:
|
||||
client = await self._get_client()
|
||||
response = await client.get("/health")
|
||||
return response.status_code == 200
|
||||
except httpx.RequestError:
|
||||
return False
|
||||
|
||||
async def list_agents(self) -> list[AgentInfo]:
|
||||
"""List available agents."""
|
||||
client = await self._get_client()
|
||||
response = await client.get("/agents/")
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return [AgentInfo(**a) for a in data.get("agents", [])]
|
||||
|
||||
async def get_agent(self, agent_type: str) -> AgentInfo | None:
|
||||
"""Get information about a specific agent."""
|
||||
client = await self._get_client()
|
||||
response = await client.get(f"/agents/{agent_type}")
|
||||
if response.status_code == 404:
|
||||
return None
|
||||
response.raise_for_status()
|
||||
return AgentInfo(**response.json())
|
||||
|
||||
async def run_agent(
|
||||
self,
|
||||
agent_type: str,
|
||||
prompt: str,
|
||||
working_dir: str = ".",
|
||||
) -> AgentResponse:
|
||||
"""
|
||||
Run an agent with the given prompt.
|
||||
|
||||
Args:
|
||||
agent_type: Type of agent (e.g., "explore")
|
||||
prompt: User prompt/query
|
||||
working_dir: Working directory for the agent
|
||||
|
||||
Returns:
|
||||
AgentResponse with the result
|
||||
"""
|
||||
client = await self._get_client()
|
||||
response = await client.post(
|
||||
"/agents/run",
|
||||
json={
|
||||
"agent_type": agent_type,
|
||||
"prompt": prompt,
|
||||
"working_dir": working_dir,
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return AgentResponse(
|
||||
response=data.get("response", ""),
|
||||
agent_type=data.get("agent_type", agent_type),
|
||||
success=data.get("success", True),
|
||||
error=data.get("error"),
|
||||
)
|
||||
|
||||
async def __aenter__(self) -> "WebberClient":
|
||||
"""Async context manager entry."""
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *args: Any) -> None:
|
||||
"""Async context manager exit."""
|
||||
await self.close()
|
||||
Reference in New Issue
Block a user