from typing import Any from fastapi import APIRouter from openhands.controller.agent import Agent from openhands.security.options import SecurityAnalyzers from openhands.server.dependencies import get_dependencies from openhands.server.shared import config, server_config from openhands.utils.llm import get_supported_llm_models app = APIRouter(prefix='/api/options', dependencies=get_dependencies()) @app.get('/models', response_model=list[str]) async def get_litellm_models() -> list[str]: """Get all models supported by LiteLLM. This function combines models from litellm and Bedrock, removing any error-prone Bedrock models. To get the models: ```sh curl http://localhost:3000/api/litellm-models ``` Returns: list[str]: A sorted list of unique model names. """ return get_supported_llm_models(config) @app.get('/agents', response_model=list[str]) async def get_agents() -> list[str]: """Get all agents supported by LiteLLM. To get the agents: ```sh curl http://localhost:3000/api/agents ``` Returns: list[str]: A sorted list of agent names. """ return sorted(Agent.list_agents()) @app.get('/security-analyzers', response_model=list[str]) async def get_security_analyzers() -> list[str]: """Get all supported security analyzers. To get the security analyzers: ```sh curl http://localhost:3000/api/security-analyzers ``` Returns: list[str]: A sorted list of security analyzer names. """ return sorted(SecurityAnalyzers.keys()) @app.get('/config', response_model=dict[str, Any]) async def get_config() -> dict[str, Any]: """Get current config. Returns: dict[str, Any]: The current server configuration. """ return server_config.get_config()