@chenpu17/cc-gw 0.7.21 → 0.8.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +98 -548
- package/package.json +41 -62
- package/src/cli/dist/index.js +95 -32
- package/src/web/dist/assets/About-DK8nmPZ6.js +1 -0
- package/src/web/dist/assets/ApiKeys-BrP75sWu.js +1 -0
- package/src/web/dist/assets/ConfirmDialog-Dhp5pCJl.js +1 -0
- package/src/web/dist/assets/Dashboard-BIW14z5s.js +1 -0
- package/src/web/dist/assets/EChart-T3foksfR.js +1 -0
- package/src/web/dist/assets/Events-CnvgH7ed.js +1 -0
- package/src/web/dist/assets/Help-CVp-PrLr.js +8 -0
- package/src/web/dist/assets/Login-Bplhk_cV.js +1 -0
- package/src/web/dist/assets/Logs-DoYv6X2i.js +1 -0
- package/src/web/dist/assets/ModelManagement-CDNkOZMr.js +1 -0
- package/src/web/dist/assets/PageHeader-BDJTHSc4.js +1 -0
- package/src/web/dist/assets/PageSection-opNH6Eh_.js +1 -0
- package/src/web/dist/assets/Settings-nv1XiDhg.js +1 -0
- package/src/web/dist/assets/Skeleton-nQ45JH_C.js +1 -0
- package/src/web/dist/assets/card-BvCN6Enp.js +1 -0
- package/src/web/dist/assets/charts-core-BvEliZR3.js +12 -0
- package/src/web/dist/assets/charts-engine-_HMDDVBV.js +16 -0
- package/src/web/dist/assets/charts-react-ChNmcnvb.js +1 -0
- package/src/web/dist/assets/i18n-DJG0aQry.js +1 -0
- package/src/web/dist/assets/index-DRy01TFD.js +61 -0
- package/src/web/dist/assets/index-NGg4j8sr.css +1 -0
- package/src/web/dist/assets/input-BiHju62h.js +1 -0
- package/src/web/dist/assets/label-DDyzn2Km.js +1 -0
- package/src/web/dist/assets/popover-BmyFxZJG.js +1 -0
- package/src/web/dist/assets/query-krBOLGyc.js +1 -0
- package/src/web/dist/assets/radix-CWM98B4t.js +5 -0
- package/src/web/dist/assets/router-CYXnniTf.js +19 -0
- package/src/web/dist/assets/select-DCRn4QJE.js +1 -0
- package/src/web/dist/assets/switch-DWuisIdD.js +1 -0
- package/src/web/dist/assets/useApiQuery-DqJ_GQ6F.js +1 -0
- package/src/web/dist/assets/vendor-DORguW2v.js +317 -0
- package/src/web/dist/index.html +7 -2
- package/src/server/dist/index.js +0 -18202
- package/src/web/dist/assets/About-Bjq70P_K.js +0 -6
- package/src/web/dist/assets/ApiKeys-BHwlIBRG.js +0 -16
- package/src/web/dist/assets/Dashboard-Bv6E5M2u.js +0 -16
- package/src/web/dist/assets/Events-DyqUKr1b.js +0 -16
- package/src/web/dist/assets/Help-BNn_Zuo4.js +0 -23
- package/src/web/dist/assets/Login-BHXuuVq3.js +0 -1
- package/src/web/dist/assets/Logs-CRnJOy2J.js +0 -6
- package/src/web/dist/assets/ModelManagement-DAE8AYAE.js +0 -6
- package/src/web/dist/assets/PageHeader-D2u2opjK.js +0 -1
- package/src/web/dist/assets/PageSection-jfq2rgUu.js +0 -1
- package/src/web/dist/assets/Settings-CssUPWdg.js +0 -6
- package/src/web/dist/assets/Skeleton-BwMNCVcg.js +0 -1
- package/src/web/dist/assets/card-C9wVDhpJ.js +0 -1
- package/src/web/dist/assets/dialog-DbEoPxgf.js +0 -10
- package/src/web/dist/assets/index-B1EJcuR-.css +0 -1
- package/src/web/dist/assets/index-BjqieXJo.js +0 -48
- package/src/web/dist/assets/index-Blclkvp7.js +0 -280
- package/src/web/dist/assets/info-BmVX8zJd.js +0 -6
- package/src/web/dist/assets/input-CGgq_gCJ.js +0 -1
- package/src/web/dist/assets/label-BGUvZ4t2.js +0 -1
- package/src/web/dist/assets/refresh-cw-D7rJxbFV.js +0 -6
- package/src/web/dist/assets/select-Chuh7X1A.js +0 -11
- package/src/web/dist/assets/shield-Beuqdf31.js +0 -11
- package/src/web/dist/assets/switch-XbPwmM_b.js +0 -1
- package/src/web/dist/assets/useApiQuery-DiX6xcfY.js +0 -1
package/README.md
CHANGED
|
@@ -1,616 +1,166 @@
|
|
|
1
1
|
# cc-gw
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
GitHub 仓库:[chenpu17/cc-gw2](https://github.com/chenpu17/cc-gw2)
|
|
4
4
|
|
|
5
|
-
cc-gw
|
|
5
|
+
`cc-gw` 是一个本地网关项目,使用 Rust 重写原先的 Node.js 后端,同时保留现有 Web UI、CLI 使用方式、配置文件和 SQLite 数据格式的兼容性。
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- 复刻 Claude API 的流式与工具调用语义
|
|
9
|
-
- 记录请求日志、Token(含缓存命中)、TTFT/TPOT 等运行指标
|
|
10
|
-
- 提供可视化 Web 管理台与守护进程 CLI
|
|
11
|
-
- 在同一个 OpenAI 接入点聚合多 Provider / 多模型,兼容 Responses 与 Chat Completions 双协议
|
|
7
|
+
说明:
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
- 当前 GitHub 仓库名是 `cc-gw2`
|
|
10
|
+
- 对外 npm 包名仍然是 `@chenpu17/cc-gw`
|
|
11
|
+
- 命令行入口仍然是 `cc-gw`
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
## 项目目标
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
- Web 前端保持不改,继续复用现有管理台
|
|
16
|
+
- 后端接口尽量对齐旧 Node.js 版本的外部行为
|
|
17
|
+
- SQLite 数据、配置目录、密钥格式继续兼容旧版本
|
|
18
|
+
- CLI 保持 `start`、`stop`、`restart`、`status`、`version` 等命令习惯
|
|
19
|
+
- npm 安装默认使用预编译原生二进制,不要求用户本机安装 Rust
|
|
20
|
+
- 发布目标尽量提供自包含二进制,减少宿主机运行时依赖
|
|
22
21
|
|
|
23
|
-
##
|
|
22
|
+
## 快速开始
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
以下是完整的配置流程,请按照步骤顺序操作:
|
|
28
|
-
|
|
29
|
-
#### 步骤 1: 安装并启动服务
|
|
24
|
+
全局安装:
|
|
30
25
|
|
|
31
26
|
```bash
|
|
32
|
-
# 方式一:npm 全局安装(推荐)
|
|
33
27
|
npm install -g @chenpu17/cc-gw
|
|
34
|
-
cc-gw start --daemon --port 4100
|
|
35
|
-
|
|
36
|
-
# 方式二:从源码构建(开发者)
|
|
37
|
-
git clone <repository>
|
|
38
|
-
cd cc-gw
|
|
39
|
-
pnpm install
|
|
40
|
-
pnpm --filter @cc-gw/server build
|
|
41
|
-
pnpm --filter @cc-gw/web build
|
|
42
|
-
pnpm --filter @cc-gw/cli exec tsx index.ts start --daemon --port 4100
|
|
43
28
|
```
|
|
44
29
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
#### 步骤 2: 配置模型提供商
|
|
48
|
-
|
|
49
|
-
1. 在 Web UI 中进入 **模型管理** 页面
|
|
50
|
-
2. 点击 **添加提供商**,配置至少一个 Provider:
|
|
51
|
-
- **Anthropic Claude**:
|
|
52
|
-
```
|
|
53
|
-
Base URL: https://api.anthropic.com
|
|
54
|
-
API Key: sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
55
|
-
默认模型: claude-3-5-sonnet-20241022
|
|
56
|
-
```
|
|
57
|
-
Roo Code / Claude CLI 可通过 OpenAI 接入点访问 Anthropic 模型,但部分第三方代理可能拒绝该路径;若收到“暂不支持”或类似错误,请改用 `/anthropic/v1/messages`。
|
|
58
|
-
- **Moonshot Kimi**:
|
|
59
|
-
```
|
|
60
|
-
Base URL: https://api.moonshot.cn/v1
|
|
61
|
-
API Key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
62
|
-
默认模型: kimi-k2-0905-preview
|
|
63
|
-
```
|
|
64
|
-
- **DeepSeek**:
|
|
65
|
-
```
|
|
66
|
-
Base URL: https://api.deepseek.com/v1
|
|
67
|
-
API Key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
68
|
-
默认模型: deepseek-chat
|
|
69
|
-
```
|
|
70
|
-
3. 配置完成后使用 **测试连接** 验证连通性
|
|
71
|
-
|
|
72
|
-
#### 步骤 3: 生成网关 API Key
|
|
73
|
-
|
|
74
|
-
1. 在 Web UI 中进入 **系统设置 → API Key 管理**
|
|
75
|
-
2. 点击 **生成新密钥**,为不同客户端创建独立的密钥:
|
|
76
|
-
- Claude Code IDE: `sk-gw-ide-xxxxxxxx`
|
|
77
|
-
- Codex CLI: `sk-gw-codex-xxxxxxxx`
|
|
78
|
-
- 其他工具: `sk-gw-other-xxxxxxxx`
|
|
79
|
-
|
|
80
|
-
#### 步骤 4: 配置环境变量(关键步骤)
|
|
81
|
-
|
|
82
|
-
将以下命令添加到 `~/.bashrc`、`~/.zshrc` 等 shell 启动脚本,或使用 `direnv` 等工具统一管理:
|
|
30
|
+
以前台模式启动:
|
|
83
31
|
|
|
84
32
|
```bash
|
|
85
|
-
|
|
86
|
-
export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
|
|
87
|
-
export ANTHROPIC_API_KEY=sk-gw-ide-xxxxxxxxxxxxxxxx
|
|
88
|
-
|
|
89
|
-
# Codex CLI(Responses API)
|
|
90
|
-
export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
|
|
91
|
-
export OPENAI_API_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
|
|
92
|
-
export CC_GW_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
|
|
93
|
-
|
|
94
|
-
# Roo Code / 旧式 OpenAI Chat Completions
|
|
95
|
-
export OPENAI_CHAT_BASE_URL=http://127.0.0.1:4100/openai/v1
|
|
96
|
-
export OPENAI_CHAT_PATH=/chat/completions
|
|
33
|
+
cc-gw start --foreground --port 4100
|
|
97
34
|
```
|
|
98
35
|
|
|
99
|
-
|
|
36
|
+
或以守护进程模式启动:
|
|
100
37
|
|
|
101
38
|
```bash
|
|
102
|
-
|
|
103
|
-
codex ask "你好,请介绍一下自己"
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
若命令能够正常返回,同时可在 Web UI 的 **请求日志** 页面看到对应记录,即表明环境变量已经正确生效。
|
|
107
|
-
|
|
108
|
-
#### 步骤 5: 配置客户端
|
|
109
|
-
|
|
110
|
-
- **Claude Code / VS Code**:在设置中选择自定义 API,填入 `http://127.0.0.1:4100/anthropic` 与 `sk-gw-ide-xxxxxxxxxxxxxxxx`。
|
|
111
|
-
- **Codex CLI**:编辑 `~/.codex/config.toml`,内容示例:
|
|
112
|
-
|
|
113
|
-
```toml
|
|
114
|
-
model = "gpt-5-codex"
|
|
115
|
-
model_provider = "cc_gw"
|
|
116
|
-
model_reasoning_effort = "high"
|
|
117
|
-
disable_response_storage = true
|
|
118
|
-
|
|
119
|
-
[model_providers.cc_gw]
|
|
120
|
-
name = "cc_gw"
|
|
121
|
-
base_url = "http://127.0.0.1:4100/openai/v1"
|
|
122
|
-
wire_api = "responses"
|
|
123
|
-
env_key = "cc_gw_key"
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
配置完成后,建议运行 `codex status` 或 `codex chat "测试"` 再确认一次终端输出。
|
|
127
|
-
|
|
128
|
-
##### 5.1 OpenAI 接入点接入说明
|
|
129
|
-
|
|
130
|
-
- **Responses API**:推荐给支持新版 OpenAI Responses(例如 Codex CLI、最新 Agent 工具)的客户端,直接指向 `http://127.0.0.1:4100/openai/v1/responses`,即可自动在下游 Provider 间路由并返回标准 `response` 结构。
|
|
131
|
-
- **Chat Completions API**:针对 Roo Code、OpenAI CLI 等仍使用传统 `POST /v1/chat/completions` 的客户端,现可通过 `http://127.0.0.1:4100/openai/v1/chat/completions` 接入;工具仅需设置 Base URL(例如 Roo Code 的 “OpenAI Compatible” 配置)和 API Key 即可。
|
|
132
|
-
- **注意兼容性**:OpenAI 入口为实验性最佳实践。若下游服务只支持 Claude Code 专用头部,可能仍返回“暂不支持”,此时改用 `/anthropic/v1/messages`。
|
|
133
|
-
- **Anthropic Beta Header**:若上游模型需要 beta 头(例如 Claude 4.5 预览),可设置环境变量 `CC_GW_ANTHROPIC_BETA_<MODEL>`(如 `CC_GW_ANTHROPIC_BETA_CLAUDE_SONNET_4_5_20250929`)或全局 `CC_GW_ANTHROPIC_BETA_ALL`;网关会在转发至 Anthropic 时尝试附加,也会针对 4.5 系列模型进行默认推断。
|
|
134
|
-
- **多模型聚合**:无论使用 Responses 还是 Chat Completions,两种接口都会按配置聚合所有 Provider 模型,`GET /openai/v1/models` 将返回当前可用模型列表及默认 Provider。
|
|
135
|
-
|
|
136
|
-
#### 步骤 6: 高级配置(可选)
|
|
137
|
-
|
|
138
|
-
##### 6.1 模型路由配置
|
|
139
|
-
|
|
140
|
-
在 **模型管理 → 路由配置** 中,可以设置模型映射:
|
|
141
|
-
```json
|
|
142
|
-
{
|
|
143
|
-
"claude-3-5-sonnet-20241022": "kimi:kimi-k2-0905-preview",
|
|
144
|
-
"claude-opus-4-1-20250805": "anthropic:claude-3-5-sonnet-20241022"
|
|
145
|
-
}
|
|
39
|
+
cc-gw start --daemon --port 4100
|
|
146
40
|
```
|
|
147
41
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
推荐使用 `direnv` 管理环境变量,在项目目录创建 `.envrc`:
|
|
151
|
-
```bash
|
|
152
|
-
# .envrc
|
|
153
|
-
export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
|
|
154
|
-
export ANTHROPIC_API_KEY=sk-gw-ide-xxxxxxxxxxxxxxxx
|
|
155
|
-
export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
|
|
156
|
-
export OPENAI_API_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
|
|
157
|
-
export CC_GW_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
|
|
158
|
-
# 若需兼容旧版 Chat Completions,可继续暴露聊天端点
|
|
159
|
-
export OPENAI_CHAT_BASE_URL=http://127.0.0.1:4100/openai/v1
|
|
160
|
-
export OPENAI_CHAT_PATH=/chat/completions
|
|
161
|
-
# 针对 Anthropic 新模型可设置 Beta Header(示例)
|
|
162
|
-
export CC_GW_ANTHROPIC_BETA_CLAUDE_SONNET_4_5_20250929=claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14
|
|
163
|
-
export CC_GW_ANTHROPIC_BETA_ALL=claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14
|
|
42
|
+
启动后访问:
|
|
164
43
|
|
|
44
|
+
```text
|
|
45
|
+
http://127.0.0.1:4100/ui
|
|
165
46
|
```
|
|
166
47
|
|
|
167
|
-
|
|
48
|
+
默认本地数据目录:
|
|
168
49
|
|
|
169
|
-
|
|
50
|
+
- 配置:`~/.cc-gw/config.json`
|
|
51
|
+
- 数据库:`~/.cc-gw/data/gateway.db`
|
|
52
|
+
- 日志:`~/.cc-gw/logs`
|
|
53
|
+
- PID:`~/.cc-gw/cc-gw.pid`
|
|
170
54
|
|
|
171
|
-
|
|
55
|
+
## 当前实现
|
|
172
56
|
|
|
173
|
-
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
57
|
+
- Rust workspace:`crates/cc-gw-core`、`crates/cc-gw-server`
|
|
58
|
+
- 兼容型 CLI:`src/cli`
|
|
59
|
+
- 原 Web 前端:`src/web`
|
|
60
|
+
- 兼容配置路径:`~/.cc-gw/config.json`
|
|
61
|
+
- 兼容数据库路径:`~/.cc-gw/data/gateway.db`
|
|
62
|
+
- 兼容旧 `encryption.key`、旧 `api_keys.key_ciphertext`、旧 Web Auth `scrypt` 密码格式
|
|
63
|
+
- 已覆盖 Web 管理台和客户端依赖的核心接口,包括 `/ui`、`/assets/*`、`/favicon.ico`、`/api/*`、`/v1/*`、`/openai/v1/*`
|
|
64
|
+
- 已实现 Anthropic / OpenAI Chat / OpenAI Responses 的代理与流式转换
|
|
65
|
+
- 已实现 API Key、日志、事件、统计、路由预设、自定义端点和 SQLite 兼容迁移
|
|
177
66
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
- **自签名证书无效**:Claude Code 和大多数 AI 工具无法信任自签名证书,会导致 "Unable to connect to API" 错误
|
|
181
|
-
- **推荐方案**:本地开发环境建议使用 HTTP 协议(`127.0.0.1` 本地访问非常安全)
|
|
182
|
-
- **如需 HTTPS**:请使用受信任 CA(如 Let's Encrypt)签发的正式证书,或配置反向代理(如 Nginx/Caddy)处理 HTTPS
|
|
183
|
-
|
|
184
|
-
**手动配置 HTTPS(通过配置文件)**:
|
|
185
|
-
|
|
186
|
-
编辑 `~/.cc-gw/config.json`:
|
|
187
|
-
|
|
188
|
-
```json
|
|
189
|
-
{
|
|
190
|
-
"http": {
|
|
191
|
-
"enabled": true,
|
|
192
|
-
"port": 4100,
|
|
193
|
-
"host": "127.0.0.1"
|
|
194
|
-
},
|
|
195
|
-
"https": {
|
|
196
|
-
"enabled": true,
|
|
197
|
-
"port": 4443,
|
|
198
|
-
"host": "127.0.0.1",
|
|
199
|
-
"keyPath": "/path/to/your/ssl/key.pem",
|
|
200
|
-
"certPath": "/path/to/your/ssl/cert.pem",
|
|
201
|
-
"caPath": ""
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
**使用 HTTPS 访问**:
|
|
67
|
+
## 本地开发
|
|
207
68
|
|
|
208
69
|
```bash
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# 访问 HTTPS 端点
|
|
213
|
-
curl https://127.0.0.1:4443/health
|
|
214
|
-
|
|
215
|
-
# Web UI HTTPS 访问
|
|
216
|
-
open https://127.0.0.1:4443/ui
|
|
70
|
+
pnpm install
|
|
71
|
+
pnpm build
|
|
72
|
+
pnpm dev
|
|
217
73
|
```
|
|
218
74
|
|
|
219
|
-
|
|
75
|
+
直接通过 CLI 前台启动:
|
|
220
76
|
|
|
221
77
|
```bash
|
|
222
|
-
|
|
223
|
-
export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
|
|
224
|
-
export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
|
|
225
|
-
|
|
226
|
-
# 如果使用 HTTPS(需要受信任的证书)
|
|
227
|
-
export ANTHROPIC_BASE_URL=https://127.0.0.1:4443/anthropic
|
|
228
|
-
export OPENAI_BASE_URL=https://127.0.0.1:4443/openai/v1
|
|
78
|
+
pnpm --filter @cc-gw/cli exec tsx index.ts start --foreground
|
|
229
79
|
```
|
|
230
80
|
|
|
231
|
-
|
|
232
|
-
- `keyPath`: 私钥文件路径(必需)
|
|
233
|
-
- `certPath`: 证书文件路径(必需)
|
|
234
|
-
- `caPath`: CA 证书路径(可选,用于证书链)
|
|
235
|
-
|
|
236
|
-
##### 6.4 自定义接入点(Custom Endpoints)
|
|
237
|
-
|
|
238
|
-
cc-gw 支持创建额外的自定义 API 端点,每个端点可以:
|
|
239
|
-
- 使用不同的协议(Anthropic、OpenAI)
|
|
240
|
-
- 配置独立的路由规则
|
|
241
|
-
- 支持多路径注册(一个端点支持多种协议)
|
|
242
|
-
- **自动路径扩展**:只需配置基础路径(如 `/my-endpoint`),系统会根据协议自动注册完整的 API 路径
|
|
243
|
-
|
|
244
|
-
**快速示例**:
|
|
245
|
-
|
|
246
|
-
通过 Web UI 或配置文件创建自定义端点:
|
|
247
|
-
```json
|
|
248
|
-
{
|
|
249
|
-
"customEndpoints": [
|
|
250
|
-
{
|
|
251
|
-
"id": "claude-api",
|
|
252
|
-
"label": "Claude 专用接入点",
|
|
253
|
-
"path": "/claude",
|
|
254
|
-
"protocol": "anthropic",
|
|
255
|
-
"enabled": true
|
|
256
|
-
}
|
|
257
|
-
]
|
|
258
|
-
}
|
|
259
|
-
```
|
|
81
|
+
`pnpm build` 会执行:
|
|
260
82
|
|
|
261
|
-
|
|
83
|
+
1. 构建 Rust 服务端
|
|
84
|
+
2. 构建 `src/cli/dist`
|
|
85
|
+
3. 构建 `src/web/dist`
|
|
86
|
+
4. 为当前平台生成 `bin/<platform>-<arch>/cc-gw-server`
|
|
87
|
+
5. 同步当前平台 native npm 子包中的原生二进制
|
|
262
88
|
|
|
263
|
-
|
|
264
|
-
- **协议自动路径扩展**:配置 `/claude` + `anthropic` 协议,自动注册 `/claude/v1/messages`
|
|
265
|
-
- **多协议支持**:同时支持 Anthropic 和 OpenAI(Chat Completions / Responses API)
|
|
266
|
-
- **独立路由**:每个端点可以配置独立的模型路由规则
|
|
267
|
-
- **路由模板**:支持保存和应用路由预设,快速切换不同的 Provider 配置
|
|
89
|
+
CLI 启动时的后端解析顺序:
|
|
268
90
|
|
|
269
|
-
|
|
91
|
+
1. 平台专用 native npm 子包
|
|
92
|
+
2. `CC_GW_SERVER_BIN`
|
|
93
|
+
3. 工作区 `bin/<platform>-<arch>/cc-gw-server`
|
|
94
|
+
4. 工作区 `target/release` 或 `target/debug`
|
|
95
|
+
5. `cargo run -p cc-gw-server --`
|
|
270
96
|
|
|
271
|
-
|
|
97
|
+
## 安装与发布
|
|
272
98
|
|
|
273
|
-
|
|
99
|
+
对外发布模型:
|
|
274
100
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
101
|
+
- 根包:`@chenpu17/cc-gw`
|
|
102
|
+
- 平台包:`@chenpu17/cc-gw-darwin-arm64`
|
|
103
|
+
- 平台包:`@chenpu17/cc-gw-linux-x64`
|
|
104
|
+
- 平台包:`@chenpu17/cc-gw-linux-arm64`
|
|
105
|
+
- 平台包:`@chenpu17/cc-gw-win32-x64`
|
|
279
106
|
|
|
280
|
-
|
|
281
|
-
- 确认 API Key 正确且未过期
|
|
282
|
-
- 检查环境变量是否正确加载
|
|
283
|
-
- 验证 Provider 的 API Key 配置
|
|
284
|
-
|
|
285
|
-
3. **模型不可用**:
|
|
286
|
-
- 在"模型管理"中测试 Provider 连接
|
|
287
|
-
- 检查模型路由配置
|
|
288
|
-
- 确认上游服务模型名称正确
|
|
289
|
-
|
|
290
|
-
4. **HTTPS 连接问题**:
|
|
291
|
-
- ⚠️ **Claude Code 无法连接**: 自签名证书会导致 "Unable to connect to API" 错误,建议使用 HTTP 协议(本地 127.0.0.1 访问安全)
|
|
292
|
-
- **证书路径错误**: 检查配置文件中的 `keyPath` 和 `certPath` 是否正确
|
|
293
|
-
- **需要受信任证书**: 如必须使用 HTTPS,请配置 Let's Encrypt 等受信任 CA 签发的证书
|
|
294
|
-
- **两个协议都禁用**: 至少要启用 HTTP 或 HTTPS 中的一个
|
|
295
|
-
|
|
296
|
-
> ✅ 完成以上 6 个步骤后,你的 cc-gw 网关就完全配置好了!所有 AI 客户端都可以通过统一的网关访问不同的模型服务。
|
|
297
|
-
|
|
298
|
-
### 推荐方式:npm 全局安装
|
|
107
|
+
用户安装:
|
|
299
108
|
|
|
300
109
|
```bash
|
|
301
110
|
npm install -g @chenpu17/cc-gw
|
|
302
|
-
cc-gw start --daemon --port 4100
|
|
303
111
|
```
|
|
304
112
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
> ⚠️ **Linux 安装提示**:本项目依赖 `better-sqlite3`;该库已为 Node 20/22/24 在 glibc/musl(x64/arm64/arm)提供预编译二进制,通常无需额外工具。如果你的环境未命中预编译(例如更早版本的 Node 或稀有架构),请先安装 `build-essential python3 make g++`,再运行 `npm install -g @chenpu17/cc-gw --unsafe-perm --build-from-source`。
|
|
113
|
+
安装时会通过 `optionalDependencies` 自动拉取当前平台的预编译二进制,无需本地编译 Rust。
|
|
114
|
+
Linux 版本使用 `musl`,Windows 版本使用静态 CRT,目标是让用户只需 `npm install` 即可直接运行。
|
|
308
115
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
前置:Node.js 18.18+(推荐 20 LTS)、pnpm 8+
|
|
116
|
+
本地在仓库中直接验证未发布包时,需要额外安装当前平台 native 包;否则 CLI 会回退到 `cargo run`:
|
|
312
117
|
|
|
313
118
|
```bash
|
|
314
|
-
pnpm
|
|
315
|
-
pnpm --
|
|
316
|
-
|
|
317
|
-
|
|
119
|
+
pnpm pack:dry-run
|
|
120
|
+
pnpm --dir packages/native/darwin-arm64 pack --pack-destination ../../../.pack/native
|
|
121
|
+
npm install -g ./.pack/native/chenpu17-cc-gw-darwin-arm64-0.8.0-alpha.1.tgz
|
|
122
|
+
npm install -g ./.pack/chenpu17-cc-gw-0.8.0-alpha.1.tgz
|
|
318
123
|
```
|
|
319
124
|
|
|
320
|
-
|
|
125
|
+
当前发布目标:
|
|
321
126
|
|
|
322
|
-
|
|
127
|
+
- macOS arm64
|
|
128
|
+
- Linux x64
|
|
129
|
+
- Linux arm64
|
|
130
|
+
- Windows x64(npm 包名为 `win32-x64`)
|
|
323
131
|
|
|
324
|
-
|
|
325
|
-
export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
|
|
326
|
-
export ANTHROPIC_API_KEY=$(cc-gw keys current)
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
将其写入 `direnv`/shell profile,即可让后续工具自动读取。
|
|
330
|
-
|
|
331
|
-
## Web 管理台
|
|
332
|
-
|
|
333
|
-
强烈建议以 Web 管理台作为主要的配置入口,可视化界面涵盖仪表盘、请求日志、模型管理与系统设置,所见即所得,避免手工改动 JSON 引入错误。
|
|
334
|
-
|
|
335
|
-
访问 `http://<host>:<port>/ui`,主要页面:
|
|
336
|
-
|
|
337
|
-
- **Dashboard**:展示请求量、Token 使用、缓存命中、各模型 TTFT(Time To First Token)/TPOT(Total Processing Time)、SQLite 数据库占用。
|
|
338
|
-
- **请求日志**:多条件筛选(时间、Provider、模型、状态),查看压缩日志详情,支持分页导出与清理。
|
|
339
|
-
- **模型管理**:维护 Provider 列表、预置模型、路由策略;一键测试连通性(发送诊断 PROMPT),支持保存并应用 Anthropic 路由模板,实现不同 Provider 方案的“一键切换”。
|
|
340
|
-
- **系统设置**:端口、日志保留策略、是否存储请求 payload、日志级别与访问日志开关、日志清理工具。
|
|
341
|
-
- **安全控制**:在“系统设置 → 安全”中可启用 Web UI 登录校验,自定义用户名及密码并自动保护所有 `/api/*` 管理接口(模型请求端点仍保持开放)。
|
|
342
|
-
- **使用指南**:提供图文步骤、常见问题与排查提示,帮助团队成员快速熟悉配置流程。
|
|
343
|
-
|
|
344
|
-
UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供键盘可达性(Skip Link、焦点管理)。
|
|
345
|
-
|
|
346
|
-
#### 界面预览
|
|
347
|
-
|
|
348
|
-

|
|
349
|
-
|
|
350
|
-

|
|
351
|
-
|
|
352
|
-
### 连接 Claude Code
|
|
353
|
-
1. 启动 cc-gw 并在“模型管理”完成 Provider 配置。
|
|
354
|
-
2. 确认第 4 步环境变量已写入当前 shell 或系统(`ANTHROPIC_BASE_URL` / `ANTHROPIC_API_KEY`)。
|
|
355
|
-
3. 在 Claude Code 终端或 VS Code 插件中选择“自定义 API”,填入 `http://127.0.0.1:4100/anthropic` 并粘贴密钥。
|
|
356
|
-
4. 运行 `claude "hello"` 或在 VS Code 新建对话,若能在 Web UI 的“请求日志”看到记录即成功。
|
|
357
|
-
|
|
358
|
-
### 连接 Codex(原 Claude Code for Repo)
|
|
359
|
-
1. 在 Web UI “路由配置”页设定 `/openai` 端点默认模型。
|
|
360
|
-
2. 设置环境变量 `OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1` 与 `OPENAI_API_KEY=<第 3 步生成的密钥>`。
|
|
361
|
-
3. 在 `~/.codex/config.toml` 按前文示例声明 `model_providers.cc_gw`,或在 CLI `codex config set` 中写入相同配置。
|
|
362
|
-
4. 执行 `codex status` / `codex ask` 验证连通性;如遇 404,请确认是否调用了 `/openai/v1/responses`。
|
|
363
|
-
|
|
364
|
-
### 环境变量与客户端配置示例
|
|
365
|
-
|
|
366
|
-
(段落保留,已在上方详细说明,可用于快速复制粘贴。)
|
|
367
|
-
|
|
368
|
-
### 使用场景 / Usage Scenarios
|
|
369
|
-
|
|
370
|
-
1. **双端点适配 / Dual Endpoint Support**:通过 `/anthropic` 与 `/openai` 端点,分别兼容 Claude Code 与 Codex 客户端。无需重启 cc-gw,即可在 Web UI 中为两个端点配置独立的默认模型与路由策略。
|
|
371
|
-
2. **日志追踪 / Request Auditing**:在“请求日志”页按端点、Provider、API Key 等维度筛选记录,可直接查看和复制完整的请求/响应 payload,辅助排查联调问题。
|
|
372
|
-
3. **模型切换 / Cross-Provider Routing**:利用“模型管理”页的路由映射,将 Claude Code 请求透明地转发到 GLM、Kimi K2、DeepSeek 等任意 OpenAI 兼容模型,实现一套 IDE 客户端、多家大模型的快速切换;对 Anthropic 端点可保存当前映射为模板(例如“fox”“glm”),后续一键切换整套路由。
|
|
373
|
-
4. **操作指引 / Built-in Guidance**:左侧“Help”导航提供分步配置、日常运维建议及 FAQ,可作为新人上手或问题排查的快速参考。
|
|
374
|
-
|
|
375
|
-
## 配置说明
|
|
376
|
-
|
|
377
|
-
大多数场景请通过 Web 管理台调整设置,以下仅作为 `~/.cc-gw/config.json` 结构参考,便于脚本化或排查:
|
|
378
|
-
|
|
379
|
-
```json
|
|
380
|
-
{
|
|
381
|
-
"http": {
|
|
382
|
-
"enabled": true,
|
|
383
|
-
"port": 4100,
|
|
384
|
-
"host": "127.0.0.1"
|
|
385
|
-
},
|
|
386
|
-
"https": {
|
|
387
|
-
"enabled": true,
|
|
388
|
-
"port": 4443,
|
|
389
|
-
"host": "127.0.0.1",
|
|
390
|
-
"keyPath": "~/.cc-gw/certs/key.pem",
|
|
391
|
-
"certPath": "~/.cc-gw/certs/cert.pem",
|
|
392
|
-
"caPath": ""
|
|
393
|
-
},
|
|
394
|
-
"host": "127.0.0.1",
|
|
395
|
-
"port": 4100,
|
|
396
|
-
"providers": [
|
|
397
|
-
{
|
|
398
|
-
"id": "kimi",
|
|
399
|
-
"label": "Moonshot Kimi",
|
|
400
|
-
"type": "kimi",
|
|
401
|
-
"baseUrl": "https://api.moonshot.cn/v1",
|
|
402
|
-
"apiKey": "sk-...",
|
|
403
|
-
"models": [
|
|
404
|
-
{ "id": "kimi-k2-0905-preview", "label": "Kimi K2" }
|
|
405
|
-
]
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
"id": "anthropic",
|
|
409
|
-
"label": "Claude",
|
|
410
|
-
"type": "anthropic",
|
|
411
|
-
"baseUrl": "https://api.anthropic.com",
|
|
412
|
-
"apiKey": "sk-ant-...",
|
|
413
|
-
"models": [
|
|
414
|
-
{ "id": "claude-3-5-sonnet-latest" }
|
|
415
|
-
]
|
|
416
|
-
}
|
|
417
|
-
],
|
|
418
|
-
"defaults": {
|
|
419
|
-
"completion": "kimi:kimi-k2-0905-preview",
|
|
420
|
-
"reasoning": "anthropic:claude-3-5-sonnet-latest",
|
|
421
|
-
"background": "kimi:kimi-k2-0905-preview",
|
|
422
|
-
"longContextThreshold": 60000
|
|
423
|
-
},
|
|
424
|
-
"modelRoutes": {
|
|
425
|
-
"claude-sonnet-4-5-20250929": "kimi:kimi-k2-0905-preview",
|
|
426
|
-
"claude-opus-4-1-20250805": "anthropic:claude-3-5-sonnet-latest"
|
|
427
|
-
},
|
|
428
|
-
"logRetentionDays": 30,
|
|
429
|
-
"storeRequestPayloads": true,
|
|
430
|
-
"storeResponsePayloads": true,
|
|
431
|
-
"logLevel": "info",
|
|
432
|
-
"requestLogging": true,
|
|
433
|
-
"responseLogging": true
|
|
434
|
-
}
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
字段要点(建议仍以 Web UI "系统设置 / 模型管理" 进行操作,下列仅便于理解结构):
|
|
438
|
-
|
|
439
|
-
- `http` / `https`:协议配置,支持独立启用/禁用,但至少要保持一个启用。
|
|
440
|
-
- `enabled`:是否启用该协议
|
|
441
|
-
- `port`:监听端口
|
|
442
|
-
- `host`:监听地址
|
|
443
|
-
- `keyPath` / `certPath`(仅 HTTPS):SSL/TLS 证书路径
|
|
444
|
-
- `caPath`(可选):CA 证书链路径
|
|
445
|
-
- `host` / `port`:旧格式向后兼容字段,新配置会自动迁移到 `http` / `https` 格式。
|
|
446
|
-
- `providers`:定义上游服务;`type` 支持 `openai | anthropic | kimi | deepseek | custom`。
|
|
447
|
-
- 模型标识使用 `providerId:modelId` 形式供路由引用。
|
|
448
|
-
- `modelRoutes`:将 Claude 发起的模型名映射到上游模型;支持在源模型名中使用 `*` 通配符匹配,匹配度更高(字符更多)的规则优先,同等情况下按配置顺序取第一条;若希望直接透传请求的模型名,可将目标写成 `providerId:*`,此时会将源请求中的模型名原样发送给对应 Provider。
|
|
449
|
-
- `routingPresets`:可选字段,保存多个 `anthropic`(或其他端点)路由模板,供 Web UI “一键切换”;每个模板仅包含 `name` 与 `modelRoutes`。
|
|
450
|
-
- `storeRequestPayloads` / `storeResponsePayloads`:是否分别在 SQLite 中压缩保存请求原文与响应内容;关闭可减少敏感数据落盘。
|
|
451
|
-
- `bodyLimit`:单次请求允许的最大请求体大小(字节),默认 10 MiB。`/compact` 等场景会发送较大上下文,如遇 413 可按需增大。
|
|
452
|
-
- `logLevel`:控制 Fastify/Pino 控制台日志级别(`fatal`/`error`/`warn`/`info`/`debug`/`trace`)。
|
|
453
|
-
- `providers[].authMode`:仅在 `type: "anthropic"` 时生效,可选 `apiKey`(默认,发送 `x-api-key`)或 `authToken`(发送 `Authorization: Bearer`)。配置 Claude Code 使用 `ANTHROPIC_AUTH_TOKEN` 时,请选择 `authToken` 并在 `apiKey` 输入框填入该值。
|
|
454
|
-
- `requestLogging`:是否输出每个 HTTP 请求的进入日志。
|
|
455
|
-
- `responseLogging`:是否输出每个 HTTP 请求完成的日志,可独立于 `requestLogging` 控制。
|
|
456
|
-
- 推荐通过 Web UI 的“模型管理 / 系统设置”在线编辑并热加载,无需手工修改文件。
|
|
457
|
-
|
|
458
|
-
#### Anthropic Provider 额外说明
|
|
459
|
-
|
|
460
|
-
- 当 Provider `type` 设置为 `anthropic` 时,网关会保留 Claude Code 发来的完整 payload,并将其原样转发到 `<baseUrl>/v1/messages`,无需转换工具调用或 metadata 字段。
|
|
461
|
-
- 所有自定义 Header(如 `x-stainless-*`、`anthropic-beta`、`anthropic-dangerous-direct-browser-access`)会自动透传到下游,确保 Claude Code 的诊断与调试能力不受影响。
|
|
462
|
-
- usage 统计会解析 `cache_read_input_tokens` / `cache_creation_input_tokens`,从而在日志与 Web UI 的 Token 指标中显示缓存命中或写入量;Moonshot / Anthropic 若未返回上述字段,则 `cached` 会继续显示为空。
|
|
463
|
-
|
|
464
|
-
### 环境变量
|
|
465
|
-
|
|
466
|
-
| 变量 | 说明 |
|
|
467
|
-
| ---- | ---- |
|
|
468
|
-
| `PORT` | CLI 启动时临时覆盖监听端口 |
|
|
469
|
-
| `CC_GW_UI_ROOT` | 指定 Web UI 静态目录(默认自动检测 `@cc-gw/web` build 结果) |
|
|
470
|
-
| `CC_GW_DEBUG_ENDPOINTS` | 设为 `1` 可在日志中输出下游请求 URL |
|
|
471
|
-
|
|
472
|
-
## CLI 守护
|
|
473
|
-
|
|
474
|
-
```bash
|
|
475
|
-
pnpm --filter @cc-gw/cli exec tsx index.ts start [--daemon] [--port 4100]
|
|
476
|
-
pnpm --filter @cc-gw/cli exec tsx index.ts stop
|
|
477
|
-
pnpm --filter @cc-gw/cli exec tsx index.ts restart [--daemon] [--port 4100]
|
|
478
|
-
pnpm --filter @cc-gw/cli exec tsx index.ts status
|
|
479
|
-
```
|
|
132
|
+
## 验证
|
|
480
133
|
|
|
481
|
-
|
|
482
|
-
- `status` 会回显配置与日志路径,便于排查。
|
|
483
|
-
- `cc-gw version`(或 `cc-gw --version`)可输出与 npm 包同步的版本号,便于核对升级情况。
|
|
484
|
-
|
|
485
|
-
## 数据与日志
|
|
486
|
-
|
|
487
|
-
- 数据库:`~/.cc-gw/data/gateway.db`(`better-sqlite3` 管理的嵌入式 SQLite)。
|
|
488
|
-
- `request_logs`:请求摘要、路由结果、耗时、TTFT/TPOT。
|
|
489
|
-
- `request_payloads`:压缩的请求/响应正文(Brotli)。
|
|
490
|
-
- `daily_metrics`:按日聚合的调用次数与 Token 统计。
|
|
491
|
-
- 日志:`~/.cc-gw/logs/cc-gw.log`,包含请求生命周期、Provider 调用与 usage 摘要(`event: usage.metrics`)。
|
|
492
|
-
|
|
493
|
-
## 常见问题
|
|
494
|
-
|
|
495
|
-
- **Web UI 404**:请确认执行过 `pnpm --filter @cc-gw/web build`,并在 CLI 启动时自动或手动设置 `CC_GW_UI_ROOT`。
|
|
496
|
-
- **usage 中无 `cached_tokens`**:部分 Provider(如火山 DeepSeek)需开启 `stream_options.include_usage` 或提供专有缓存参数;cc-gw 已在支持的适配器中自动注入,如仍为 `null` 需确认上游是否支持。
|
|
497
|
-
- **日志数据库过大**:可在“系统设置”关闭 payload 保存或缩短保留天数;Web UI 亦提供手动清理工具。
|
|
498
|
-
|
|
499
|
-
---
|
|
500
|
-
|
|
501
|
-
## English
|
|
502
|
-
|
|
503
|
-
cc-gw is a local gateway tailored for Claude Code and similar Anthropic-compatible clients. It normalizes `/v1/messages`, routes traffic across heterogeneous providers, mirrors Claude’s streaming & tool semantics, and records detailed metrics that surface in a bilingual Web console and CLI daemon.
|
|
504
|
-
|
|
505
|
-
### Highlights
|
|
506
|
-
|
|
507
|
-
| Feature | Details |
|
|
508
|
-
| ------- | ------- |
|
|
509
|
-
| Protocol adaptation | Converts Claude-style payloads into OpenAI-, Anthropic-, Kimi-, and DeepSeek-compatible requests while preserving tool calls and reasoning blocks. |
|
|
510
|
-
| Model routing | Maps incoming model IDs to configured upstream providers with fallbacks for long-context/background tasks, plus Anthropic routing presets for one-click provider swaps. |
|
|
511
|
-
| Observability | Persists request logs, token usage (including cache hits), TTFT, TPOT, and daily aggregates via better-sqlite3 with Brotli-compressed payloads; request/response bodies can be stored independently. |
|
|
512
|
-
| Web console | React + Vite UI with dashboards, filters, provider CRUD, bilingual copy, and responsive layout. |
|
|
513
|
-
| CLI daemon | `cc-gw` command wraps start/stop/restart/status, manages PID/log files, and scaffolds a default config on first launch. |
|
|
514
|
-
|
|
515
|
-
### Standard Onboarding Checklist
|
|
516
|
-
|
|
517
|
-
1. **Install & launch**: `npm install -g @chenpu17/cc-gw && cc-gw start --daemon --port 4100`. The first run scaffolds `~/.cc-gw/config.json` and makes the Web UI available at `http://127.0.0.1:4100/ui`.
|
|
518
|
-
2. **Add providers**: In *Model Management*, create at least one provider by entering its base URL/API key and selecting default models. Templates for Anthropic, Kimi, DeepSeek, etc., are provided in the sidebar.
|
|
519
|
-
3. **Issue gateway API keys**: Navigate to *System Settings → API Keys* and mint a key for each client (IDE, Codex CLI, automation). This is what clients will send to cc-gw.
|
|
520
|
-
4. **Export environment variables (required)**:
|
|
521
|
-
```bash
|
|
522
|
-
export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
|
|
523
|
-
export ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
524
|
-
|
|
525
|
-
# Optional: OpenAI-compatible endpoint (Codex, Open Interpreter, ...)
|
|
526
|
-
export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
|
|
527
|
-
export OPENAI_API_KEY=$ANTHROPIC_API_KEY
|
|
528
|
-
```
|
|
529
|
-
Drop these lines into your shell profile (or `direnv`) so that IDEs inherit them automatically.
|
|
530
|
-
5. **Point your clients**:
|
|
531
|
-
- **Claude Code / VS Code extension**: enable custom API mode, paste `http://127.0.0.1:4100/anthropic`, and use the key from step 3. The extension appends `/v1/messages?beta=true` automatically.
|
|
532
|
-
- **Codex CLI**: update `~/.codex/config.toml`:
|
|
533
|
-
```toml
|
|
534
|
-
model = "gpt-5-codex"
|
|
535
|
-
model_provider = "cc_gw"
|
|
536
|
-
model_reasoning_effort = "high"
|
|
537
|
-
disable_response_storage = true
|
|
538
|
-
|
|
539
|
-
[model_providers.cc_gw]
|
|
540
|
-
name = "cc_gw"
|
|
541
|
-
base_url = "http://127.0.0.1:4100/openai/v1"
|
|
542
|
-
wire_api = "responses"
|
|
543
|
-
env_key = "cc_gw_key"
|
|
544
|
-
```
|
|
545
|
-
Then export `CC_GW_KEY=<gateway api key>`.
|
|
546
|
-
6. **Smoke test**: run a short prompt (`claude "hello"`, `codex ask`, etc.) and confirm a matching entry appears in *Request Logs*. If not, re-check the environment variables and provider routing.
|
|
547
|
-
|
|
548
|
-
> Once these six steps are complete, any Anthropic/OpenAI-style client can pivot to cc-gw. All further tweaks (providers, routing, logging) can be handled from the Web UI.
|
|
549
|
-
|
|
550
|
-
### Quick reinstall / binary upgrade
|
|
134
|
+
建议在上传或发版前执行:
|
|
551
135
|
|
|
552
136
|
```bash
|
|
553
|
-
|
|
554
|
-
|
|
137
|
+
cargo test
|
|
138
|
+
pnpm build
|
|
139
|
+
pnpm smoke:cli
|
|
140
|
+
pnpm pack:dry-run
|
|
555
141
|
```
|
|
556
142
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
> ⚠️ **Linux build note**: cc-gw relies on `better-sqlite3`. Prebuilt binaries cover Node 20/22/24 on glibc & musl (x64/arm64/arm). For other combos install `build-essential python3 make g++`, then rerun `npm install -g @chenpu17/cc-gw --unsafe-perm --build-from-source`.
|
|
560
|
-
|
|
561
|
-
### From Source (contributors)
|
|
143
|
+
首次运行 Web E2E 前,先安装 Playwright Chromium:
|
|
562
144
|
|
|
563
145
|
```bash
|
|
564
|
-
pnpm install
|
|
565
|
-
pnpm
|
|
566
|
-
pnpm --filter @cc-gw/web build
|
|
567
|
-
pnpm --filter @cc-gw/cli exec tsx index.ts start --daemon --port 4100
|
|
146
|
+
pnpm exec playwright install --with-deps chromium
|
|
147
|
+
pnpm test:e2e:web
|
|
568
148
|
```
|
|
569
149
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
### Configuration Snapshot
|
|
573
|
-
|
|
574
|
-
- Providers include `type`, `baseUrl`, `apiKey`, and `models` descriptions.
|
|
575
|
-
- When `type` is `anthropic`, cc-gw forwards the original Claude payload and all headers to `<baseUrl>/v1/messages`, so tool calls/metadata remain intact.
|
|
576
|
-
- Model routes use `providerId:modelId` syntax to remap Claude requests.
|
|
577
|
-
- `storeRequestPayloads` / `storeResponsePayloads` control whether prompts and completions are persisted; disable either switch to avoid storing sensitive data.
|
|
578
|
-
- `bodyLimit`: maximum request body size (in bytes). Defaults to 10 MiB—raise this if clients like Claude Code `/compact` hit HTTP 413.
|
|
579
|
-
- `logLevel` adjusts Fastify/Pino verbosity (`fatal` → `trace`).
|
|
580
|
-
- `requestLogging` controls whether per-request access logs are emitted to the console.
|
|
581
|
-
- `responseLogging` toggles completion logs separately so you can keep the console quieter while preserving metrics.
|
|
582
|
-
- Web UI allows editing without restarting; CLI restart will pick up bundle changes after rebuilds.
|
|
583
|
-
|
|
584
|
-
### Observability & Storage
|
|
585
|
-
|
|
586
|
-
- SQLite file under `~/.cc-gw/data/gateway.db` tracks logs and aggregated metrics.
|
|
587
|
-
- Dashboard surfaces per-model TTFT/TPOT, cache hits(including Anthropic `cache_read_input_tokens` / `cache_creation_input_tokens`), and DB size.
|
|
588
|
-
- Logs can be filtered/exported/cleaned directly from the UI.
|
|
589
|
-
|
|
590
|
-
### CLI Reference
|
|
591
|
-
|
|
592
|
-
| Command | Description |
|
|
593
|
-
| ------- | ----------- |
|
|
594
|
-
| `cc-gw start [--daemon] [--port]` | Launch the Fastify server, auto-creating config if missing. |
|
|
595
|
-
| `cc-gw stop` | Send SIGTERM and remove stale PID files. |
|
|
596
|
-
| `cc-gw restart` | Convenience wrapper for stop + start. |
|
|
597
|
-
| `cc-gw status` | Show running status, PID, log directory, config path. |
|
|
598
|
-
|
|
599
|
-
### Environment
|
|
600
|
-
|
|
601
|
-
| Variable | Purpose |
|
|
602
|
-
| -------- | ------- |
|
|
603
|
-
| `PORT` | Override listening port at launch. |
|
|
604
|
-
| `CC_GW_UI_ROOT` | Manually point to the built web assets. |
|
|
605
|
-
| `CC_GW_DEBUG_ENDPOINTS=1` | Log upstream provider endpoints for debugging. |
|
|
606
|
-
|
|
607
|
-
### Tips
|
|
150
|
+
当前仓库已具备:
|
|
608
151
|
|
|
609
|
-
-
|
|
610
|
-
-
|
|
611
|
-
-
|
|
612
|
-
-
|
|
152
|
+
- Web UI 构建通过
|
|
153
|
+
- Web Playwright E2E 通过
|
|
154
|
+
- CLI smoke 流程可单独执行
|
|
155
|
+
- GitHub Actions CI 与 release workflow 已落地
|
|
613
156
|
|
|
614
|
-
|
|
157
|
+
## CI 与文档
|
|
615
158
|
|
|
616
|
-
|
|
159
|
+
- 文档索引:[`docs/README.md`](docs/README.md)
|
|
160
|
+
- 系统设计:[`docs/system-design.md`](docs/system-design.md)
|
|
161
|
+
- 存储设计:[`docs/database-schema.md`](docs/database-schema.md)
|
|
162
|
+
- API 兼容矩阵:[`docs/api-compatibility.md`](docs/api-compatibility.md)
|
|
163
|
+
- 日常校验:[`ci.yml`](.github/workflows/ci.yml)
|
|
164
|
+
- 发布流水线:[`release.yml`](.github/workflows/release.yml)
|
|
165
|
+
- npm 打包说明:[`docs/npm-packaging.md`](docs/npm-packaging.md)
|
|
166
|
+
- GitHub 上传和发版清单:[`docs/github-release-checklist.md`](docs/github-release-checklist.md)
|