feat: expose /internal/models/raw for authoritative model metadata

Lets callers see Lingma's raw config/queryModels response, so the
official per-key displayName/description is discoverable without
reverse-engineering the VSIX. Falls back to the pool's pick() unless
a specific instance is requested.

Made-with: Cursor
This commit is contained in:
GitHub Actions
2026-04-18 09:29:11 +08:00
parent dfdb7087dc
commit ba865f3be0

View File

@@ -633,6 +633,36 @@ async def internal_auto_login_status():
return {"ok": True, "instances": out} return {"ok": True, "instances": out}
@app.get("/internal/models/raw", dependencies=[Depends(auth_guard)])
async def internal_models_raw(instance: str | None = None):
"""Return the raw `config/queryModels` response from Lingma.
This is the authoritative source for per-key displayName, description,
capability flags, etc. We only ever extract `key` + `displayName` for
OpenAI compatibility, but clients may want to inspect everything.
"""
p = _require_pool()
target = None
if instance:
for inst in p.instances:
if inst.name == instance:
target = inst
break
if target is None:
raise HTTPException(status_code=404, detail={"error": f"instance {instance} not found"})
else:
target = p.pick()
await _ensure_instance_logged_in(target)
raw = await target.client.query_models()
name_map = build_model_name_map(raw if isinstance(raw, dict) else {})
return {
"instance": target.name,
"raw": raw,
"extracted_name_map": name_map,
"exposed_keys": flatten_model_keys(raw if isinstance(raw, dict) else {}),
}
@app.get("/internal/stats", dependencies=[Depends(auth_guard)]) @app.get("/internal/stats", dependencies=[Depends(auth_guard)])
async def internal_stats(): async def internal_stats():
p = _require_pool() p = _require_pool()