"""代理面路由(T-P0 骨架:/proxy/v1/models;主对话路由 T-P4 落地)。""" from __future__ import annotations from fastapi import APIRouter, Request from gateway.proxy.config import ProxyConfig def build_proxy_router(cfg: ProxyConfig, pool) -> APIRouter: """组装代理面路由(唯一组装点;pool 为 gateway.model_pool.PoolStore)。""" router = APIRouter(prefix="/proxy") @router.get("/v1/models", tags=["proxy"]) async def list_models(): """学生面:池内允许代理的模型列表(OpenAI /models 形状)。""" entries = pool.list().get("entries", []) names = [e["model"] for e in entries if e.get("enabled") and e.get("backend") not in ("mock",)] # 去重保序 seen, data = set(), [] for n in names: if n not in seen: seen.add(n) data.append({"id": n, "object": "model", "owned_by": "campus-proxy"}) return {"object": "list", "data": data} # /v1/chat/completions 与 /admin/* 在 T-P1/T-P4 追加 return router