chore: /v1/inspect/routes to return only valid non-deprecated routes by default

This commit is contained in:
Raghotham Murthy 2025-10-28 09:17:58 -07:00
parent c2ae42b343
commit 467801b78b
2 changed files with 24 additions and 7 deletions

View file

@ -4,7 +4,7 @@
# This source code is licensed under the terms described in the LICENSE file in # This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree. # the root directory of this source tree.
from typing import Protocol, runtime_checkable from typing import Literal, Protocol, runtime_checkable
from pydantic import BaseModel 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.providers.datatypes import HealthStatus
from llama_stack.schema_utils import json_schema_type, webmethod 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 @json_schema_type
class RouteInfo(BaseModel): class RouteInfo(BaseModel):
@ -64,11 +67,13 @@ class Inspect(Protocol):
""" """
@webmethod(route="/inspect/routes", method="GET", level=LLAMA_STACK_API_V1) @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 routes.
List all available API routes with their methods and implementing providers. 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. :returns: Response containing information about all available routes.
""" """
... ...

View file

@ -39,9 +39,21 @@ class DistributionInspectImpl(Inspect):
async def initialize(self) -> None: async def initialize(self) -> None:
pass 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 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 = [] ret = []
external_apis = load_external_apis(run_config) external_apis = load_external_apis(run_config)
all_endpoints = get_all_api_routes(external_apis) 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"])), 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 provider_types=[], # These APIs don't have "real" providers - they're internal to the stack
) )
for e, _ in endpoints for e, webmethod in endpoints
if e.methods is not None if e.methods is not None and should_include_route(webmethod)
] ]
) )
else: else:
@ -69,8 +81,8 @@ class DistributionInspectImpl(Inspect):
method=next(iter([m for m in e.methods if m != "HEAD"])), method=next(iter([m for m in e.methods if m != "HEAD"])),
provider_types=[p.provider_type for p in providers], provider_types=[p.provider_type for p in providers],
) )
for e, _ in endpoints for e, webmethod in endpoints
if e.methods is not None if e.methods is not None and should_include_route(webmethod)
] ]
) )