Spaces:
Paused
Paused
Download src/opencode_api/routes/agent.py from AUXteam/opencode-api: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/AUXteam/opencode-api/resolve/bb4ddbd3b0b0dfd7ace5c9004f5bbc6f5ee873a3/src/opencode_api/routes/agent.py
- Command line
-
hf download hf://spaces/AUXteam/opencode-api@bb4ddbd3b0b0dfd7ace5c9004f5bbc6f5ee873a3/src/opencode_api/routes/agent.py
-
curl -L -o agent.py https://huggingface.co/spaces/AUXteam/opencode-api/resolve/bb4ddbd3b0b0dfd7ace5c9004f5bbc6f5ee873a3/src/opencode_api/routes/agent.py
1.72 kB
| """ | |
| Agent routes - manage agent configurations. | |
| """ | |
| from fastapi import APIRouter, HTTPException | |
| from typing import Optional, List | |
| from ..agent import ( | |
| AgentInfo, | |
| get, | |
| list_agents, | |
| default_agent, | |
| register, | |
| unregister, | |
| ) | |
| router = APIRouter(prefix="/agent", tags=["agent"]) | |
| async def get_agents( | |
| mode: Optional[str] = None, | |
| include_hidden: bool = False | |
| ): | |
| """List all available agents.""" | |
| return list_agents(mode=mode, include_hidden=include_hidden) | |
| async def get_default_agent(): | |
| """Get the default agent configuration.""" | |
| return default_agent() | |
| async def get_agent(agent_id: str): | |
| """Get a specific agent by ID.""" | |
| agent = get(agent_id) | |
| if not agent: | |
| raise HTTPException(status_code=404, detail=f"Agent not found: {agent_id}") | |
| return agent | |
| async def create_agent(agent: AgentInfo): | |
| """Register a custom agent.""" | |
| existing = get(agent.id) | |
| if existing and existing.native: | |
| raise HTTPException(status_code=400, detail=f"Cannot override native agent: {agent.id}") | |
| register(agent) | |
| return agent | |
| async def delete_agent(agent_id: str): | |
| """Unregister a custom agent.""" | |
| agent = get(agent_id) | |
| if not agent: | |
| raise HTTPException(status_code=404, detail=f"Agent not found: {agent_id}") | |
| if agent.native: | |
| raise HTTPException(status_code=400, detail=f"Cannot delete native agent: {agent_id}") | |
| unregister(agent_id) | |
| return {"deleted": agent_id} | |