Skip to content

Commit cf5a3c2

Browse files
authored
Merge pull request #201 from ThreeFish-AI/feature/1.x.x
v0.3.0
2 parents 2f630cd + 28db861 commit cf5a3c2

57 files changed

Lines changed: 5366 additions & 1150 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,25 @@
44

55
## [Unreleased]
66

7-
- fix(request-normalizer): 重设计 zhipu→anthropic 跨供应商 tool_use/tool_result 配对修复——以单遍自包含 `enforce_anthropic_tool_pairing` 替代原有多步串联管线(剥离→重定位→孤儿修复),消除步骤间隐式依赖导致的孤儿 tool_use 漏修问题,彻底根治 `tool_use ids were found without tool_result blocks` 400 异常;
8-
- refactor(vendor-channels): 将供应商转换通道从「目标 vendor 专属」重构为「源→目标绑定」模型——注册表键从 `target_vendor` 改为 `(source, target)` 二元组,通道函数从 `prepare_for_X` 重命名为 `prepare_X_to_Y`,触发逻辑从 `_needs_vendor_channel` 替换为 `_determine_source_vendor`(基于请求内 `failed_tier_name` 和会话历史推断源 vendor),未注册的转换对(如 anthropic→zhipu)不触发任何通道;
9-
- feat(vendor-channels): 新增 zhipu→anthropic、zhipu→copilot、copilot→zhipu 三条源→目标绑定转换通道,在跨供应商故障转移时自动清理源 vendor 产物(thinking 块、cache_control 字段、thinking 参数、tool_use/tool_result 配对),消除 `likely format incompatibility (400 + tool_results)` 错误;
7+
## [v0.3.0](https://github.com/ThreeFish-AI/coding-proxy/releases/tag/v0.3.0) — 2026-04-20
8+
9+
> [!IMPORTANT]
10+
>
11+
> **🚀 OpenAI、Anthropic、Gemini 原生 API 进驻 Coding Proxy!**
12+
>
13+
> 服务对象不在局限 Claude Code,凡兼容 OpenAI、Anthropic、Gemini 三巨头 API 协议的客户端,出口 LLM 流量可统一收敛到 Coding Proxy。
14+
15+
### ✨ 核心亮点
16+
17+
- feat(native-api): 新增 `/api/{openai,gemini,anthropic}/**` 原生 LLM API 全量 catch-all 透传通道;
18+
- feat(dashboard): 新增实时 Web Dashboard 页面,聚合展示流量与用量统计;
19+
- feat(usage): `usage` 区分 Claude Code 场景(`'cc'`)与原生 API 场景(`'api'`);
20+
- refactor(vendor-channels): 将供应商转换通道从目标专属重构为源→目标绑定模型;
21+
- docs(user-guide): 补充 POST /v1/messages 完整 API 参考文档;
22+
23+
### 🔧 更多特性
24+
25+
- feat(server): 默认监听端口 `8046``3392`,规范化 [Negentropy](https://github.com/ThreeFish-AI/negentropy) 体系端口;
1026

1127
## [v0.2.3](https://github.com/ThreeFish-AI/coding-proxy/releases/tag/v0.2.3) — 2026-04-16
1228

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ uv run coding-proxy start
7070
# INFO: Started server process [1403]
7171
# INFO: Waiting for application startup.
7272
# ...
73-
# INFO: coding-proxy started: host=127.0.0.1 port=8046
73+
# INFO: coding-proxy started: host=127.0.0.1 port=3392
7474
# INFO: Application startup complete.
75-
# INFO: Uvicorn running on http://127.0.0.1:8046 (Press CTRL+C to quit)
75+
# INFO: Uvicorn running on http://127.0.0.1:3392 (Press CTRL+C to quit)
7676
```
7777

7878
### 4. Seamless Claude Code Integration
7979

8080
Open a fresh terminal tab and route your traffic through coding-proxy before firing up Claude Code:
8181

8282
```bash
83-
export ANTHROPIC_BASE_URL=http://127.0.0.1:8046
83+
export ANTHROPIC_BASE_URL=http://127.0.0.1:3392
8484

8585
# Enjoy blissful, silky-smooth, and uninterrupted coding nirvana:
8686
claude

docs/arch/config-reference.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ flowchart TD
4949
| 字段 | 类型 | 默认值 | 说明 |
5050
| ------ | ---- | ------------- | -------- |
5151
| `host` | str | `"127.0.0.1"` | 监听地址 |
52-
| `port` | int | `8046` | 监听端口 |
52+
| `port` | int | `3392` | 监听端口 |
5353

5454
### 3.2 DatabaseConfig
5555

@@ -257,3 +257,54 @@ tiers: [anthropic, copilot, zhipu] # 显式优先级(可选)
257257
2. `zhipu` 字段名 → `fallback`
258258
3. 若无 `vendors` 字段,从 legacy flat 字段自动生成 vendors 列表
259259
4. 迁移时发出 INFO 日志建议迁移至新格式
260+
261+
---
262+
263+
## 10. native_api — 原生 API 透传配置
264+
265+
> **定义位置**:[`native_api/config.py`](../../src/coding/proxy/native_api/config.py)
266+
>
267+
> **端点**:`/api/{openai,gemini,anthropic}/**` catch-all 透传通道;认证头由客户端自带,proxy 不保管凭据。
268+
269+
### 10.1 NativeApiConfig 顶层字段
270+
271+
| 字段 | 类型 | 默认值 | 说明 |
272+
| ------------- | ---------------------- | -------------------------------------- | ----------------------------------------- |
273+
| `openai` | `NativeProviderConfig` | 内置官方 URL,`enabled=true` | OpenAI chat / responses / embeddings 等 |
274+
| `gemini` | `NativeProviderConfig` | 内置官方 URL,`enabled=true` | Gemini generateContent / embedContent 等 |
275+
| `anthropic` | `NativeProviderConfig` | 内置官方 URL,`enabled=true` | Anthropic messages / count_tokens / batches |
276+
277+
### 10.2 NativeProviderConfig 字段
278+
279+
| 字段 | 类型 | 默认值 | 说明 |
280+
| --------------------- | ---- | ------------------- | --------------------------------------------------------------------- |
281+
| `enabled` | bool | `true` | 是否启用该 provider 的原生透传端点(默认启用,开箱即用) |
282+
| `base_url` | str | 见下方内置默认 | 上游 API base_url(纯域名前缀,不含 `/v1`) |
283+
| `timeout_ms` | int | `300000` | 单次请求超时(毫秒),LLM 大模型建议 ≥ 120s |
284+
| `connect_timeout_ms` | int | `15000` | 连接建立超时(毫秒) |
285+
286+
### 10.3 内置默认 `base_url`
287+
288+
| Provider | 内置默认 |
289+
| ------------ | ----------------------------------------------------- |
290+
| `openai` | `https://api.openai.com` |
291+
| `gemini` | `https://generativelanguage.googleapis.com` |
292+
| `anthropic` | `https://api.anthropic.com` |
293+
294+
### 10.4 `base_url` 三级覆写优先级
295+
296+
由 `NativeApiConfig._apply_env_overrides` `@model_validator(mode="after")` 注入:
297+
298+
```text
299+
env var(运行时) > YAML 显式字段(部署时) > Pydantic 内置默认(兜底)
300+
```
301+
302+
| 环境变量 | 覆写目标 |
303+
| ---------------------------- | ------------------------- |
304+
| `NATIVE_OPENAI_BASE_URL` | `openai.base_url` |
305+
| `NATIVE_GEMINI_BASE_URL` | `gemini.base_url` |
306+
| `NATIVE_ANTHROPIC_BASE_URL` | `anthropic.base_url` |
307+
308+
空串或纯空白视作未设置,保留上一层值(避免"未设置 env → 空串覆盖内置默认"陷阱)。
309+
310+
> `ANTHROPIC_BASE_URL`(client → proxy,Claude Code 使用)与 `NATIVE_ANTHROPIC_BASE_URL`(proxy → upstream,原生透传使用)方向正交,勿混用。参见 [用户指引 § 4.7 native_api](../user-guide.md#47-native_api--原生-api-透传)。

docs/arch/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
| `test_convert_sse.py` | Gemini SSE→Anthropic SSE 流适配(单/多 chunk、各 finishReason、边界情况) |
6666
| `test_copilot_convert_request.py` | Anthropic→OpenAI 请求格式转换 |
6767
| `test_copilot_convert_response.py` | OpenAI→Anthropic 响应格式转换 |
68+
| `test_vendor_channels.py` | 源→目标通道:zhipu/copilot 兼容性清洗、tool_use 配对、内容感知源推断 |
6869

6970
### 2.5 数据模型(model)
7071

@@ -95,7 +96,6 @@
9596
| 测试文件 | 覆盖范围 |
9697
| ---------------------------- | ------------------------------------------------------- |
9798
| `test_app_routes.py` | FastAPI 路由端点测试 |
98-
| `test_request_normalizer.py` | 请求标准化:私有块清洗、tool_use_id 重写、fatal_reasons |
9999
| `test_cli_usage.py` | CLI 用量查询命令 |
100100
| `test_banner.py` | CLI Banner 显示 |
101101
| `test_logging_dual_write.py` | 日志双写机制 |

docs/framework.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ graph TD
6969
App["<code>app.py</code><br/>应用工厂 + lifespan"]
7070
Routes["<code>routes.py</code><br/>路由注册"]
7171
Factory["<code>factory.py</code><br/>Vendor/Tier 构建工厂"]
72-
Normalizer["<code>request_normalizer.py</code><br/>请求标准化"]
7372
Dashboard["<code>dashboard.py</code><br/>状态面板"]
7473
end
7574
@@ -179,15 +178,8 @@ graph TD
179178
```mermaid
180179
flowchart TD
181180
Client["Client POST /v1/messages"] --> Server["server.routes.messages()"]
182-
183-
subgraph Normalize ["请求标准化"]
184-
Body["body = await request.json()"]
185-
Norm["normalize_anthropic_request(body)<br/>清洗私有块 + 重写 tool_use_id"]
186-
Body --> Norm
187-
end
188-
189-
Server --> Normalize
190-
Norm --> RouteType{"stream?"}
181+
Server --> Body["body = await request.json()"]
182+
Body --> RouteType{"stream?"}
191183
192184
RouteType -- "true" --> StreamRoute["route_stream()"]
193185
RouteType -- "false" --> MsgRoute["route_message()"]
@@ -401,7 +393,6 @@ flowchart TD
401393
| [`app.py`](../src/coding/proxy/server/app.py) | FastAPI 应用工厂 `create_app()` + `lifespan` 生命周期管理 |
402394
| [`factory.py`](../src/coding/proxy/server/factory.py) | Vendor/Tier 构建工厂 + 凭证解析 |
403395
| [`routes.py`](../src/coding/proxy/server/routes.py) | 路由端点按职责分组注册 |
404-
| [`request_normalizer.py`](../src/coding/proxy/server/request_normalizer.py) | 入站请求标准化(清洗供应商私有块) |
405396
| [`responses.py`](../src/coding/proxy/server/responses.py) | 响应辅助工具(JSON error / stream error 构建) |
406397
| [`dashboard.py`](../src/coding/proxy/server/dashboard.py) | 状态面板(Web Dashboard) |
407398

docs/guide/api-reference.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
根路径连通性探针。Claude Code 在建立连接前发送 `HEAD /` 作为健康检查,代理返回 HTTP 200 空响应。
3232

3333
```bash
34-
curl -I http://127.0.0.1:8046/
34+
curl -I http://127.0.0.1:3392/
3535
# HTTP/1.1 200 OK
3636
```
3737

@@ -189,7 +189,7 @@ curl -I http://127.0.0.1:8046/
189189
Token 计数 API 透传。支持所有提供 Anthropic 兼容端点的供应商。
190190

191191
```bash
192-
curl -X POST http://127.0.0.1:8046/v1/messages/count_tokens \
192+
curl -X POST http://127.0.0.1:3392/v1/messages/count_tokens \
193193
-H "Content-Type: application/json" \
194194
-H "anthropic-version: 2023-06-01" \
195195
-d '{"model":"claude-sonnet-4-6","messages":[{"role":"user","content":"Hello"}]}'
@@ -206,7 +206,7 @@ curl -X POST http://127.0.0.1:8046/v1/messages/count_tokens \
206206
健康检查。
207207

208208
```bash
209-
curl http://127.0.0.1:8046/health
209+
curl http://127.0.0.1:3392/health
210210
# {"status":"ok"}
211211
```
212212

@@ -215,7 +215,7 @@ curl http://127.0.0.1:8046/health
215215
查询所有层级的熔断器、配额守卫、周级配额守卫、Rate Limit 及诊断信息。
216216

217217
```bash
218-
curl http://127.0.0.1:8046/api/status
218+
curl http://127.0.0.1:3392/api/status
219219
```
220220

221221
**返回示例**
@@ -258,15 +258,15 @@ curl http://127.0.0.1:8046/api/status
258258

259259
```bash
260260
# 仅重置(向后兼容)
261-
curl -X POST http://127.0.0.1:8046/api/reset
261+
curl -X POST http://127.0.0.1:3392/api/reset
262262

263263
# 重置 + 提升 anthropic 到最高优先级
264-
curl -X POST http://127.0.0.1:8046/api/reset \
264+
curl -X POST http://127.0.0.1:3392/api/reset \
265265
-H "Content-Type: application/json" \
266266
-d '{"vendors": ["anthropic"]}'
267267

268268
# 重置 + 替换整条链路顺序
269-
curl -X POST http://127.0.0.1:8046/api/reset \
269+
curl -X POST http://127.0.0.1:3392/api/reset \
270270
-H "Content-Type: application/json" \
271271
-d '{"vendors": ["zhipu", "anthropic", "copilot"]}'
272272
```
@@ -282,7 +282,7 @@ curl -X POST http://127.0.0.1:8046/api/reset \
282282
返回 Copilot 认证与交换链路的脱敏诊断信息。
283283

284284
```bash
285-
curl http://127.0.0.1:8046/api/copilot/diagnostics
285+
curl http://127.0.0.1:3392/api/copilot/diagnostics
286286
```
287287

288288
若 Copilot 供应商未启用,返回 404。
@@ -292,7 +292,7 @@ curl http://127.0.0.1:8046/api/copilot/diagnostics
292292
按需探测当前 Copilot 会话可见的模型列表。
293293

294294
```bash
295-
curl http://127.0.0.1:8046/api/copilot/models
295+
curl http://127.0.0.1:3392/api/copilot/models
296296
```
297297

298298
需要有效的 Copilot 凭证;凭证无效时返回 503。
@@ -302,15 +302,15 @@ curl http://127.0.0.1:8046/api/copilot/models
302302
查询运行时重认证状态。
303303

304304
```bash
305-
curl http://127.0.0.1:8046/api/reauth/status
305+
curl http://127.0.0.1:3392/api/reauth/status
306306
```
307307

308308
## 10. POST /api/reauth/{provider}
309309

310310
手动触发指定 provider 的运行时重认证。
311311

312312
```bash
313-
curl -X POST http://127.0.0.1:8046/api/reauth/github
313+
curl -X POST http://127.0.0.1:3392/api/reauth/github
314314
# HTTP/1.1 202 Accepted
315315
# {"status":"reauth requested"}
316316
```
@@ -330,15 +330,15 @@ curl -X POST http://127.0.0.1:8046/api/reauth/github
330330
返回 Dashboard HTML 页面。
331331

332332
```bash
333-
curl http://127.0.0.1:8046/dashboard
333+
curl http://127.0.0.1:3392/dashboard
334334
```
335335

336336
### 11.2 GET /api/dashboard/summary
337337

338338
返回 Dashboard 汇总数据(今日 + 所选区间)。
339339

340340
```bash
341-
curl "http://127.0.0.1:8046/api/dashboard/summary?days=7"
341+
curl "http://127.0.0.1:3392/api/dashboard/summary?days=7"
342342
```
343343

344344
| 参数 | 类型 | 默认值 | 说明 |
@@ -352,7 +352,7 @@ curl "http://127.0.0.1:8046/api/dashboard/summary?days=7"
352352
返回按天分组的时序数据(用于图表绘制)。
353353

354354
```bash
355-
curl "http://127.0.0.1:8046/api/dashboard/timeline?days=30"
355+
curl "http://127.0.0.1:3392/api/dashboard/timeline?days=30"
356356
```
357357

358358
| 参数 | 类型 | 默认值 | 说明 |

docs/guide/cli-reference.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ coding-proxy start
3939
coding-proxy start -p 9000 -c ~/my-config.yaml
4040

4141
# 自定义监听地址和端口
42-
coding-proxy start --host 0.0.0.0 --port 8046
42+
coding-proxy start --host 0.0.0.0 --port 3392
4343
```
4444

4545
> 若启用了 Copilot 或 Antigravity 供应商但未配置凭证,启动时会自动触发 OAuth 浏览器登录流程。
@@ -54,7 +54,7 @@ coding-proxy status [OPTIONS]
5454

5555
| 参数 | 缩写 | 说明 |
5656
| -------- | ---- | ------------------------- |
57-
| `--port` | `-p` | 代理服务端口(默认 8046|
57+
| `--port` | `-p` | 代理服务端口(默认 3392|
5858

5959
**输出示例**
6060

@@ -143,7 +143,7 @@ coding-proxy reset [OPTIONS]
143143

144144
| 参数 | 缩写 | 说明 |
145145
| ---------- | ---- | ----------------------------------------------- |
146-
| `--port` | `-p` | 代理服务端口(默认 8046|
146+
| `--port` | `-p` | 代理服务端口(默认 3392|
147147
| `--vendor` | `-v` | 提升/重排序 vendor 优先级(单个或逗号分隔多个) |
148148

149149
**重排序语义**
@@ -211,7 +211,7 @@ coding-proxy auth reauth PROVIDER [OPTIONS]
211211
| 参数 | 缩写 | 说明 |
212212
| ---------- | ---- | ------------------------------------------ |
213213
| `PROVIDER` || provider 名称(必填):`github` / `google` |
214-
| `--port` | `-p` | 代理服务端口(默认 8046|
214+
| `--port` | `-p` | 代理服务端口(默认 3392|
215215

216216
**示例**
217217

docs/guide/dashboard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ coding-proxy 内置 Web 可视化看板,提供流量、用量、故障转移
77
启动代理后,浏览器访问:
88

99
```
10-
http://127.0.0.1:8046/dashboard
10+
http://127.0.0.1:3392/dashboard
1111
```
1212

1313
## 功能概览

docs/guide/monitoring.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ coding-proxy usage --db /path/to/usage.db
6767

6868
```bash
6969
# 基础检查
70-
curl http://127.0.0.1:8046/health
70+
curl http://127.0.0.1:3392/health
7171

7272
# 详细状态(所有层级的熔断器、配额守卫、Rate Limit、诊断信息)
73-
curl http://127.0.0.1:8046/api/status
73+
curl http://127.0.0.1:3392/api/status
7474
```
7575

7676
> 端点详情参见 [API 参考](./api-reference.md)
7777
7878
## 4. Dashboard 监控
7979

80-
浏览器访问 `http://127.0.0.1:8046/dashboard` 查看 Web 可视化看板。详见 [Dashboard 文档](./dashboard.md)
80+
浏览器访问 `http://127.0.0.1:3392/dashboard` 查看 Web 可视化看板。详见 [Dashboard 文档](./dashboard.md)
8181

8282
## 5. 数据库维护
8383

@@ -138,7 +138,7 @@ coding-proxy reset -v anthropic
138138
coding-proxy auth reauth github
139139

140140
# API
141-
curl -X POST http://127.0.0.1:8046/api/reauth/github
141+
curl -X POST http://127.0.0.1:3392/api/reauth/github
142142
```
143143

144144
重认证请求发出后(HTTP 202),在浏览器中完成授权即可,无需重启。
@@ -150,7 +150,7 @@ curl -X POST http://127.0.0.1:8046/api/reauth/github
150150
**端口占用**
151151

152152
```bash
153-
lsof -i :8046
153+
lsof -i :3392
154154
coding-proxy start --port 8080
155155
```
156156

@@ -161,7 +161,7 @@ coding-proxy start --port 8080
161161
### 8.2 Claude Code 无法连接代理
162162

163163
1. 确认代理正在运行:`coding-proxy status`
164-
2. 确认环境变量:`echo $ANTHROPIC_BASE_URL`(应为 `http://127.0.0.1:8046`
164+
2. 确认环境变量:`echo $ANTHROPIC_BASE_URL`(应为 `http://127.0.0.1:3392`
165165
3. 确认端口一致
166166

167167
### 8.3 频繁触发故障转移
@@ -185,10 +185,10 @@ coding-proxy start --port 8080
185185

186186
```bash
187187
# 查看诊断信息
188-
curl http://127.0.0.1:8046/api/copilot/diagnostics
188+
curl http://127.0.0.1:3392/api/copilot/diagnostics
189189

190190
# 探查可用模型
191-
curl http://127.0.0.1:8046/api/copilot/models
191+
curl http://127.0.0.1:3392/api/copilot/models
192192

193193
# 重认证
194194
coding-proxy auth reauth github

0 commit comments

Comments
 (0)