MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / handle_selector

Function handle_selector

uncommon_route/proxy.py:3472–3510  ·  view source on GitHub ↗

GET /v1/selector — selector state. POST /v1/selector — preview candidate choice.

(request: Request)

Source from the content-addressed store, hash-verified

3470 })
3471
3472 async def handle_selector(request: Request) -> JSONResponse:
3473 """GET /v1/selector — selector state. POST /v1/selector — preview candidate choice."""
3474 if request.method == "GET":
3475 mode_param = request.query_params.get("mode")
3476 tier_param = request.query_params.get("tier")
3477 if (mode_param and not tier_param) or (tier_param and not mode_param):
3478 return JSONResponse(
3479 {"error": "mode and tier must be provided together"},
3480 status_code=400,
3481 )
3482 if mode_param and tier_param:
3483 try:
3484 return JSONResponse(_selector_state(
3485 bucket_mode=_parse_mode_value(mode_param),
3486 bucket_tier=_parse_tier_value(tier_param),
3487 ))
3488 except ValueError:
3489 return JSONResponse(
3490 {"error": "Invalid mode or tier"},
3491 status_code=400,
3492 )
3493 return JSONResponse(_selector_state())
3494
3495 denied = _admin_auth_failure(request)
3496 if denied is not None:
3497 return denied
3498 body = await request.json()
3499 normalized_body, error = _normalize_selector_body(
3500 body,
3501 default_mode=_routing_store.default_mode(),
3502 )
3503 if normalized_body is None:
3504 return JSONResponse({"error": error or "Invalid selector payload"}, status_code=400)
3505 try:
3506 return JSONResponse(_build_selector_preview(normalized_body, request))
3507 except RoutingInfeasibleError as exc:
3508 payload = _routing_infeasible_payload(exc)
3509 payload["selector"] = _selector_state()
3510 return JSONResponse(payload, status_code=400)
3511
3512 async def handle_routing_config(request: Request) -> JSONResponse:
3513 """GET /v1/routing-config — active routing mode/tier config. POST — update overrides."""

Callers

nothing calls this directly

Calls 9

_selector_stateFunction · 0.85
_parse_mode_valueFunction · 0.85
_parse_tier_valueFunction · 0.85
_admin_auth_failureFunction · 0.85
_normalize_selector_bodyFunction · 0.85
_build_selector_previewFunction · 0.85
default_modeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected