feat: add capability and admin introspection endpoints

Expose capability discovery plus admin-only config and request inspection endpoints so clients and operators can understand gateway behavior without reading code.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
mmc
2026-05-12 14:30:08 +08:00
parent 94a8025ae5
commit b719bdeaa2
5 changed files with 780 additions and 93 deletions

View File

@@ -4,6 +4,8 @@
- OpenAI`/v1/models``/v1/chat/completions`(含 stream
- Anthropic`/v1/messages``/v1/messages/count_tokens`(含 stream
- 能力探测:`/capabilities``/v1/capabilities`
- 内省端点:`/internal/effective-config``/internal/debug/requests`
- 内置多实例池、会话复用、Prometheus 指标、登录态 bundle 注入
- 工具事件桥接Lingma 上游返回 `tool` 事件时,网关会输出为 OpenAI `tool_calls`stream/non-stream和 Anthropic `tool_use` / `tool_result`stream/non-stream请求侧 `tools` / `tool_choice` 仅在 `TOOL_FORWARD_ENABLED=true` 时透传(默认开启,可显式关闭)
- 工具模拟回退:当 Lingma 未稳定外显原生 `tool/*` 事件时,网关会把注入后的 `json action` / `#Tool Call` 等动作文本归一化为 OpenAI `tool_calls`,并支持 tool result continuation
@@ -56,6 +58,7 @@ API_KEY=$(grep '^API_KEYS=' .env | cut -d= -f2 | cut -d, -f1)
curl -s "http://127.0.0.1:${PORT}/healthz"
curl -s "http://127.0.0.1:${PORT}/v1/models" \
-H "Authorization: Bearer ${API_KEY}"
curl -s "http://127.0.0.1:${PORT}/capabilities"
```
---
@@ -172,6 +175,32 @@ curl -s "http://127.0.0.1:${PORT}/v1/messages/count_tokens" \
}'
```
### 能力探测
```bash
curl -s "http://127.0.0.1:${PORT}/capabilities"
curl -s "http://127.0.0.1:${PORT}/v1/capabilities" \
-H "x-api-key: ${API_KEY}" \
-H "anthropic-version: 2023-06-01"
```
### 内省端点admin
如果配置了 `ADMIN_TOKEN`,以下端点需要使用该 token否则会回退复用 `API_KEYS`
```bash
ADMIN_TOKEN=${ADMIN_TOKEN:-$API_KEY}
curl -s "http://127.0.0.1:${PORT}/internal/effective-config" \
-H "Authorization: Bearer ${ADMIN_TOKEN}"
curl -s "http://127.0.0.1:${PORT}/internal/debug/requests?limit=5" \
-H "Authorization: Bearer ${ADMIN_TOKEN}"
```
> `internal/debug/requests` 会对 token、session bundle、data URL 图片和超长工具参数做脱敏/截断。
---
## 部署与更新