File size: 1,720 Bytes
1397957
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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"])


@router.get("", response_model=List[AgentInfo])
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)


@router.get("/default", response_model=AgentInfo)
async def get_default_agent():
    """Get the default agent configuration."""
    return default_agent()


@router.get("/{agent_id}", response_model=AgentInfo)
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


@router.post("", response_model=AgentInfo)
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


@router.delete("/{agent_id}")
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}