diff --git a/src/llama_stack/apis/inspect/inspect.py b/src/llama_stack/apis/inspect/inspect.py index 8b0996e69..2f2925b4d 100644 --- a/src/llama_stack/apis/inspect/inspect.py +++ b/src/llama_stack/apis/inspect/inspect.py @@ -4,7 +4,7 @@ # This source code is licensed under the terms described in the LICENSE file in # the root directory of this source tree. -from typing import Protocol, runtime_checkable +from typing import Literal, Protocol, runtime_checkable from pydantic import BaseModel @@ -12,6 +12,9 @@ from llama_stack.apis.version import LLAMA_STACK_API_V1 from llama_stack.providers.datatypes import HealthStatus from llama_stack.schema_utils import json_schema_type, webmethod +# Valid API level values for filtering routes +ApiLevel = Literal["v1", "v1alpha", "v1beta", "deprecated"] + @json_schema_type class RouteInfo(BaseModel): @@ -64,11 +67,13 @@ class Inspect(Protocol): """ @webmethod(route="/inspect/routes", method="GET", level=LLAMA_STACK_API_V1) - async def list_routes(self) -> ListRoutesResponse: + async def list_routes(self, api_level: ApiLevel | None = None) -> ListRoutesResponse: """List routes. List all available API routes with their methods and implementing providers. + :param api_level: Optional filter for API level. Can be 'v1', 'v1alpha', 'v1beta', or 'deprecated'. + If not specified, returns only non-deprecated v1 APIs and providers. :returns: Response containing information about all available routes. """ ... diff --git a/src/llama_stack/core/inspect.py b/src/llama_stack/core/inspect.py index 37dab4199..42f9f695e 100644 --- a/src/llama_stack/core/inspect.py +++ b/src/llama_stack/core/inspect.py @@ -39,9 +39,21 @@ class DistributionInspectImpl(Inspect): async def initialize(self) -> None: pass - async def list_routes(self) -> ListRoutesResponse: + async def list_routes(self, api_level: str | None = None) -> ListRoutesResponse: run_config: StackRunConfig = self.config.run_config + # Helper function to determine if a route should be included based on api_level filter + def should_include_route(webmethod) -> bool: + if api_level is None: + # Default: only non-deprecated v1 APIs + return not webmethod.deprecated and webmethod.level == "v1" + elif api_level == "deprecated": + # Include only deprecated routes + return webmethod.deprecated + else: + # Include routes matching the specified level (non-deprecated) + return not webmethod.deprecated and webmethod.level == api_level + ret = [] external_apis = load_external_apis(run_config) all_endpoints = get_all_api_routes(external_apis) @@ -55,8 +67,8 @@ class DistributionInspectImpl(Inspect): method=next(iter([m for m in e.methods if m != "HEAD"])), provider_types=[], # These APIs don't have "real" providers - they're internal to the stack ) - for e, _ in endpoints - if e.methods is not None + for e, webmethod in endpoints + if e.methods is not None and should_include_route(webmethod) ] ) else: @@ -69,8 +81,8 @@ class DistributionInspectImpl(Inspect): method=next(iter([m for m in e.methods if m != "HEAD"])), provider_types=[p.provider_type for p in providers], ) - for e, _ in endpoints - if e.methods is not None + for e, webmethod in endpoints + if e.methods is not None and should_include_route(webmethod) ] )