@chenpu17/cc-gw 0.5.0 → 0.5.2

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.
Files changed (27) hide show
  1. package/README.md +95 -2
  2. package/package.json +3 -2
  3. package/src/cli/dist/index.js +20 -2
  4. package/src/server/dist/index.js +251 -121
  5. package/src/web/dist/assets/{About-DK242vw9.js → About-BkGxQ3Pv.js} +2 -2
  6. package/src/web/dist/assets/{ApiKeys-BGROxK6-.js → ApiKeys-GdImp523.js} +1 -1
  7. package/src/web/dist/assets/{Button-Bnnxe9ep.js → Button-BkhovQFd.js} +1 -1
  8. package/src/web/dist/assets/{Dashboard-B7zokimB.js → Dashboard-DxSNZwZc.js} +1 -1
  9. package/src/web/dist/assets/{FormField-BzT4FGj8.js → FormField-C-bAE13W.js} +1 -1
  10. package/src/web/dist/assets/{Help-CJooSMdJ.js → Help-Bj3HXV4H.js} +1 -1
  11. package/src/web/dist/assets/{Input-B-P-J4xQ.js → Input-B6cOxhbI.js} +1 -1
  12. package/src/web/dist/assets/{Login-B9RgxiYX.js → Login-Btsbo17f.js} +1 -1
  13. package/src/web/dist/assets/Logs-72HRZmFi.js +1 -0
  14. package/src/web/dist/assets/{ModelManagement-dDhNa_5z.js → ModelManagement-cuAzyPgP.js} +1 -1
  15. package/src/web/dist/assets/{PageSection-Dzvd3cKD.js → PageSection-Bq4tdag3.js} +1 -1
  16. package/src/web/dist/assets/Settings-DPvX1pD_.js +11 -0
  17. package/src/web/dist/assets/{StatusBadge-CAkVtC--.js → StatusBadge-P00M_NBZ.js} +1 -1
  18. package/src/web/dist/assets/{copy-D6cuJHzh.js → copy-D321KBhI.js} +1 -1
  19. package/src/web/dist/assets/{index-Cm-hZvRJ.js → index-BLBh7aj6.js} +1 -1
  20. package/src/web/dist/assets/index-DEa23YLm.css +1 -0
  21. package/src/web/dist/assets/{index-agm-2asf.js → index-DP6DzFEd.js} +30 -30
  22. package/src/web/dist/assets/{info-CfAuBePJ.js → info-CADQNr0Q.js} +1 -1
  23. package/src/web/dist/assets/{useApiQuery-ns68sM2H.js → useApiQuery-C5jmZPyb.js} +1 -1
  24. package/src/web/dist/index.html +2 -2
  25. package/src/web/dist/assets/Logs-CsJCTftU.js +0 -1
  26. package/src/web/dist/assets/Settings-BcMQ79b0.js +0 -1
  27. package/src/web/dist/assets/index-BFd07aus.css +0 -1
package/README.md CHANGED
@@ -166,7 +166,74 @@ export CC_GW_ANTHROPIC_BETA_ALL=claude-code-20250219,interleaved-thinking-2025-0
166
166
 
167
167
  然后运行 `direnv allow` 自动加载。
168
168
 
169
- ##### 6.3 自定义接入点(Custom Endpoints)
169
+ ##### 6.3 HTTPS 配置
170
+
171
+ cc-gw 支持同时启动 HTTP 和 HTTPS 服务。
172
+
173
+ **默认配置**:
174
+ - HTTP: 端口 `4100`(**默认启用**,推荐用于本地开发)
175
+ - HTTPS: 端口 `4443`(**默认关闭**)
176
+ - 两个协议可独立启用/禁用,但**至少要保持一个启用**
177
+
178
+ ⚠️ **重要提示:关于 HTTPS 证书**
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 访问**:
207
+
208
+ ```bash
209
+ # 重启服务使配置生效
210
+ cc-gw restart --daemon
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
217
+ ```
218
+
219
+ **环境变量配置**:
220
+
221
+ ```bash
222
+ # 推荐:使用 HTTP(默认)
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
229
+ ```
230
+
231
+ **证书路径说明**:
232
+ - `keyPath`: 私钥文件路径(必需)
233
+ - `certPath`: 证书文件路径(必需)
234
+ - `caPath`: CA 证书路径(可选,用于证书链)
235
+
236
+ ##### 6.4 自定义接入点(Custom Endpoints)
170
237
 
171
238
  cc-gw 支持创建额外的自定义 API 端点,每个端点可以:
172
239
  - 使用不同的协议(Anthropic、OpenAI)
@@ -220,6 +287,12 @@ cc-gw 支持创建额外的自定义 API 端点,每个端点可以:
220
287
  - 检查模型路由配置
221
288
  - 确认上游服务模型名称正确
222
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
+
223
296
  > ✅ 完成以上 6 个步骤后,你的 cc-gw 网关就完全配置好了!所有 AI 客户端都可以通过统一的网关访问不同的模型服务。
224
297
 
225
298
  ### 推荐方式:npm 全局安装
@@ -305,6 +378,19 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
305
378
 
306
379
  ```json
307
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
+ },
308
394
  "host": "127.0.0.1",
309
395
  "port": 4100,
310
396
  "providers": [
@@ -348,8 +434,15 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
348
434
  }
349
435
  ```
350
436
 
351
- 字段要点(建议仍以 Web UI “系统设置 / 模型管理” 进行操作,下列仅便于理解结构):
437
+ 字段要点(建议仍以 Web UI "系统设置 / 模型管理" 进行操作,下列仅便于理解结构):
352
438
 
439
+ - `http` / `https`:协议配置,支持独立启用/禁用,但至少要保持一个启用。
440
+ - `enabled`:是否启用该协议
441
+ - `port`:监听端口
442
+ - `host`:监听地址
443
+ - `keyPath` / `certPath`(仅 HTTPS):SSL/TLS 证书路径
444
+ - `caPath`(可选):CA 证书链路径
445
+ - `host` / `port`:旧格式向后兼容字段,新配置会自动迁移到 `http` / `https` 格式。
353
446
  - `providers`:定义上游服务;`type` 支持 `openai | anthropic | kimi | deepseek | custom`。
354
447
  - 模型标识使用 `providerId:modelId` 形式供路由引用。
355
448
  - `modelRoutes`:将 Claude 发起的模型名映射到上游模型;支持在源模型名中使用 `*` 通配符匹配,匹配度更高(字符更多)的规则优先,同等情况下按配置顺序取第一条;若希望直接透传请求的模型名,可将目标写成 `providerId:*`,此时会将源请求中的模型名原样发送给对应 Provider。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenpu17/cc-gw",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -59,8 +59,8 @@
59
59
  "better-sqlite3": "^12.4.1",
60
60
  "colorette": "^2.0.20",
61
61
  "commander": "^12.0.0",
62
- "jszip": "^3.10.1",
63
62
  "fastify": "^4.26.2",
63
+ "jszip": "^3.10.1",
64
64
  "open": "^10.1.0",
65
65
  "tiktoken": "^1.0.21",
66
66
  "undici": "^6.11.1"
@@ -68,6 +68,7 @@
68
68
  "devDependencies": {
69
69
  "@eslint/js": "^9.5.0",
70
70
  "@playwright/test": "^1.55.1",
71
+ "@types/better-sqlite3": "^7.6.13",
71
72
  "@types/node": "^20.12.7",
72
73
  "eslint": "^8.57.0",
73
74
  "globals": "^15.0.0",
@@ -97,6 +97,20 @@ async function ensureConfigTemplate(port) {
97
97
  longContextThreshold: 6e4
98
98
  };
99
99
  const template = {
100
+ http: {
101
+ enabled: true,
102
+ port: selectedPort,
103
+ host: "127.0.0.1"
104
+ },
105
+ https: {
106
+ enabled: false,
107
+ port: 4443,
108
+ host: "127.0.0.1",
109
+ keyPath: "",
110
+ certPath: "",
111
+ caPath: ""
112
+ },
113
+ // 保留旧字段以兼容
100
114
  host: "127.0.0.1",
101
115
  port: selectedPort,
102
116
  providers: [],
@@ -218,10 +232,14 @@ async function handleStart(options) {
218
232
  }
219
233
  if (configCreated) {
220
234
  console.log(green(`\u5DF2\u5728 ${CONFIG_FILE} \u751F\u6210\u9ED8\u8BA4\u914D\u7F6E`));
221
- console.log(yellow(`\u9996\u6B21\u542F\u52A8\uFF1A\u5F85\u670D\u52A1\u5C31\u7EEA\u540E\uFF0C\u8BF7\u5728\u6D4F\u89C8\u5668\u8BBF\u95EE http://127.0.0.1:${effectivePort}/ui \u8FDB\u884C\u914D\u7F6E\u3002`));
235
+ console.log(yellow(`\u9996\u6B21\u542F\u52A8\uFF1A\u5F85\u670D\u52A1\u5C31\u7EEA\u540E\uFF0C\u8BF7\u8BBF\u95EE\u4EE5\u4E0B\u5730\u5740\u8FDB\u884C\u914D\u7F6E:`));
236
+ console.log(yellow(` HTTP: http://127.0.0.1:${effectivePort}/ui`));
237
+ console.log(yellow(` HTTPS: https://127.0.0.1:4443/ui (\u9700\u5148\u751F\u6210\u8BC1\u4E66)`));
222
238
  }
223
239
  if (daemonMode) {
224
- console.log(green(`Web UI \u5DF2\u5C31\u7EEA: http://127.0.0.1:${effectivePort}/ui`));
240
+ console.log(green(`\u670D\u52A1\u5DF2\u542F\u52A8:`));
241
+ console.log(green(` HTTP: http://127.0.0.1:${effectivePort}/ui`));
242
+ console.log(green(` HTTPS: https://127.0.0.1:4443/ui (\u5982\u5DF2\u542F\u7528)`));
225
243
  }
226
244
  if (!daemonMode) {
227
245
  const forwardSignal = (signal) => {