@chenpu17/cc-gw 0.3.8 → 0.3.10

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 (35) hide show
  1. package/README.md +201 -60
  2. package/package.json +2 -1
  3. package/src/server/dist/index.js +10177 -48
  4. package/src/web/dist/assets/About-lwVAsqMu.js +11 -0
  5. package/src/web/dist/assets/{ApiKeys-DIj-z9NS.js → ApiKeys-C9KFsUMQ.js} +2 -2
  6. package/src/web/dist/assets/{Button-Df2SC9Z6.js → Button-BF9GpvYa.js} +1 -1
  7. package/src/web/dist/assets/Dashboard-BUKxNPQR.js +16 -0
  8. package/src/web/dist/assets/FormField-BBlxSg9a.js +1 -0
  9. package/src/web/dist/assets/Help-yYuyDHMA.js +23 -0
  10. package/src/web/dist/assets/Input-DdO84aXo.js +1 -0
  11. package/src/web/dist/assets/Login-D9r73MBo.js +1 -0
  12. package/src/web/dist/assets/Logs-CriMtwWk.js +1 -0
  13. package/src/web/dist/assets/ModelManagement-BgCUHomS.js +1 -0
  14. package/src/web/dist/assets/PageSection-Nop6p7eX.js +1 -0
  15. package/src/web/dist/assets/Settings-DKDjawCK.js +1 -0
  16. package/src/web/dist/assets/{StatusBadge-CMf3e9GN.js → StatusBadge-CZGD7No1.js} +1 -1
  17. package/src/web/dist/assets/{copy-C0txfzHv.js → copy-Bv68tIyy.js} +1 -1
  18. package/src/web/dist/assets/index-BOv43c_r.css +1 -0
  19. package/src/web/dist/assets/{index-oWYCCpBl.js → index-CQzd1dOI.js} +1 -1
  20. package/src/web/dist/assets/{index-DtM-AT3x.js → index-DggPstk7.js} +41 -16
  21. package/src/web/dist/assets/{info-jEzfgMxW.js → info-oTKmY9Oy.js} +1 -1
  22. package/src/web/dist/assets/useApiQuery-C6-ZfYVn.js +1 -0
  23. package/src/web/dist/index.html +4 -3
  24. package/src/web/dist/assets/About-B4P46oBY.js +0 -11
  25. package/src/web/dist/assets/Dashboard-ofxha89A.js +0 -16
  26. package/src/web/dist/assets/FormField-IhMRFkvg.js +0 -1
  27. package/src/web/dist/assets/Help-DWp0N8et.js +0 -6
  28. package/src/web/dist/assets/Input-BR1EKmIk.js +0 -1
  29. package/src/web/dist/assets/Login-D8amVPUK.js +0 -1
  30. package/src/web/dist/assets/Logs-DRwOarji.js +0 -1
  31. package/src/web/dist/assets/ModelManagement-CtaCkRed.js +0 -1
  32. package/src/web/dist/assets/PageSection-D21hdQmW.js +0 -1
  33. package/src/web/dist/assets/Settings-C2-eI9Yb.js +0 -1
  34. package/src/web/dist/assets/index-BRI-aVAi.css +0 -1
  35. package/src/web/dist/assets/useApiQuery-Dz2idWoC.js +0 -1
package/README.md CHANGED
@@ -17,7 +17,150 @@ cc-gw 是一个面向 Claude Code 与同类客户端的本地多模型网关,
17
17
  | `@cc-gw/web` | React + Vite Web UI,包含仪表盘、日志面板、模型管理、系统设置 |
18
18
  | `@cc-gw/cli` | CLI 守护工具,封装 start/stop/restart/status 并托管 PID/日志 |
19
19
 
20
- ## 快速开始
20
+ ## 🚀 快速开始
21
+
22
+ ### 完整配置指南(新手必读)
23
+
24
+ 以下是完整的配置流程,请按照步骤顺序操作:
25
+
26
+ #### 步骤 1: 安装并启动服务
27
+
28
+ ```bash
29
+ # 方式一:npm 全局安装(推荐)
30
+ npm install -g @chenpu17/cc-gw
31
+ cc-gw start --daemon --port 4100
32
+
33
+ # 方式二:从源码构建(开发者)
34
+ git clone <repository>
35
+ cd cc-gw
36
+ pnpm install
37
+ pnpm --filter @cc-gw/server build
38
+ pnpm --filter @cc-gw/web build
39
+ pnpm --filter @cc-gw/cli exec tsx index.ts start --daemon --port 4100
40
+ ```
41
+
42
+ 启动后访问 Web 管理界面:`http://127.0.0.1:4100/ui`
43
+
44
+ #### 步骤 2: 配置模型提供商
45
+
46
+ 1. 在 Web UI 中进入 **模型管理** 页面
47
+ 2. 点击 **添加提供商**,配置至少一个 Provider:
48
+ - **Anthropic Claude**:
49
+ ```
50
+ Base URL: https://api.anthropic.com
51
+ API Key: sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
52
+ 默认模型: claude-3-5-sonnet-20241022
53
+ ```
54
+ - **Moonshot Kimi**:
55
+ ```
56
+ Base URL: https://api.moonshot.cn/v1
57
+ API Key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
58
+ 默认模型: kimi-k2-0905-preview
59
+ ```
60
+ - **DeepSeek**:
61
+ ```
62
+ Base URL: https://api.deepseek.com/v1
63
+ API Key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
64
+ 默认模型: deepseek-chat
65
+ ```
66
+ 3. 配置完成后使用 **测试连接** 验证连通性
67
+
68
+ #### 步骤 3: 生成网关 API Key
69
+
70
+ 1. 在 Web UI 中进入 **系统设置 → API Key 管理**
71
+ 2. 点击 **生成新密钥**,为不同客户端创建独立的密钥:
72
+ - Claude Code IDE: `sk-gw-ide-xxxxxxxx`
73
+ - Codex CLI: `sk-gw-codex-xxxxxxxx`
74
+ - 其他工具: `sk-gw-other-xxxxxxxx`
75
+
76
+ #### 步骤 4: 配置环境变量(关键步骤)
77
+
78
+ 将以下命令添加到 `~/.bashrc`、`~/.zshrc` 等 shell 启动脚本,或使用 `direnv` 等工具统一管理:
79
+
80
+ ```bash
81
+ # Claude Code / VS Code
82
+ export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
83
+ export ANTHROPIC_API_KEY=sk-gw-ide-xxxxxxxxxxxxxxxx
84
+
85
+ # Codex CLI
86
+ export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
87
+ export OPENAI_API_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
88
+ export CC_GW_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
89
+ ```
90
+
91
+ 更新完毕后执行 `source ~/.bashrc`(或 `source ~/.zshrc`)让环境变量立即生效。完成后可以马上做一次快速连通性测试:
92
+
93
+ ```bash
94
+ claude "你好,请简短回应"
95
+ codex ask "你好,请介绍一下自己"
96
+ ```
97
+
98
+ 若命令能够正常返回,同时可在 Web UI 的 **请求日志** 页面看到对应记录,即表明环境变量已经正确生效。
99
+
100
+ #### 步骤 5: 配置客户端
101
+
102
+ - **Claude Code / VS Code**:在设置中选择自定义 API,填入 `http://127.0.0.1:4100/anthropic` 与 `sk-gw-ide-xxxxxxxxxxxxxxxx`。
103
+ - **Codex CLI**:编辑 `~/.codex/config.toml`,内容示例:
104
+
105
+ ```toml
106
+ model = "gpt-5-codex"
107
+ model_provider = "cc_gw"
108
+ model_reasoning_effort = "high"
109
+ disable_response_storage = true
110
+
111
+ [model_providers.cc_gw]
112
+ name = "cc_gw"
113
+ base_url = "http://127.0.0.1:4100/openai/v1"
114
+ wire_api = "responses"
115
+ env_key = "cc_gw_key"
116
+ ```
117
+
118
+ 配置完成后,建议运行 `codex status` 或 `codex chat "测试"` 再确认一次终端输出。
119
+
120
+ #### 步骤 6: 高级配置(可选)
121
+
122
+ ##### 6.1 模型路由配置
123
+
124
+ 在 **模型管理 → 路由配置** 中,可以设置模型映射:
125
+ ```json
126
+ {
127
+ "claude-3-5-sonnet-20241022": "kimi:kimi-k2-0905-preview",
128
+ "claude-opus-4-1-20250805": "anthropic:claude-3-5-sonnet-20241022"
129
+ }
130
+ ```
131
+
132
+ ##### 6.2 环境变量持久化
133
+
134
+ 推荐使用 `direnv` 管理环境变量,在项目目录创建 `.envrc`:
135
+ ```bash
136
+ # .envrc
137
+ export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
138
+ export ANTHROPIC_API_KEY=sk-gw-ide-xxxxxxxxxxxxxxxx
139
+ export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
140
+ export OPENAI_API_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
141
+ export CC_GW_KEY=sk-gw-codex-xxxxxxxxxxxxxxxx
142
+ ```
143
+
144
+ 然后运行 `direnv allow` 自动加载。
145
+
146
+ #### 常见问题排查
147
+
148
+ 1. **连接失败**:
149
+ - 检查 cc-gw 服务状态:`cc-gw status`
150
+ - 验证环境变量:`echo $ANTHROPIC_BASE_URL`
151
+ - 查看请求日志确认错误信息
152
+
153
+ 2. **认证错误**:
154
+ - 确认 API Key 正确且未过期
155
+ - 检查环境变量是否正确加载
156
+ - 验证 Provider 的 API Key 配置
157
+
158
+ 3. **模型不可用**:
159
+ - 在"模型管理"中测试 Provider 连接
160
+ - 检查模型路由配置
161
+ - 确认上游服务模型名称正确
162
+
163
+ > ✅ 完成以上 6 个步骤后,你的 cc-gw 网关就完全配置好了!所有 AI 客户端都可以通过统一的网关访问不同的模型服务。
21
164
 
22
165
  ### 推荐方式:npm 全局安装
23
166
 
@@ -43,6 +186,15 @@ pnpm --filter @cc-gw/cli exec tsx index.ts start --daemon --port 4100
43
186
 
44
187
  > ✅ 首次启动后推荐直接使用 Web 管理台完成 Provider、模型、日志等设置;仅在自动化或高级场景下再手动编辑配置文件。
45
188
 
189
+ 如需以 CLI 启动后配合本地脚本使用,可在 shell 中补充以下变量:
190
+
191
+ ```bash
192
+ export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
193
+ export ANTHROPIC_API_KEY=$(cc-gw keys current)
194
+ ```
195
+
196
+ 将其写入 `direnv`/shell profile,即可让后续工具自动读取。
197
+
46
198
  ## Web 管理台
47
199
 
48
200
  强烈建议以 Web 管理台作为主要的配置入口,可视化界面涵盖仪表盘、请求日志、模型管理与系统设置,所见即所得,避免手工改动 JSON 引入错误。
@@ -65,50 +217,20 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
65
217
  ![Request Logs](docs/images/logs.png)
66
218
 
67
219
  ### 连接 Claude Code
68
- 1. 启动 cc-gw 并确认配置中 `host` 为 `127.0.0.1`,`port` 与 CLI 启动一致。
69
- 2. 在安装了 Claude Code 的终端设置环境变量:
70
- ```bash
71
- export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
72
- claude "help me review this file"
73
- ```
74
- 3. 如果使用 VS Code 插件(Claude Code),在“自定义 API”中同样填写 `http://127.0.0.1:4100/anthropic`,插件会自动追加 `/v1/messages` 与 `?beta=true`,最后粘贴 cc-gw Web UI 或 CLI 创建的 API Key。
75
- 4. cc-gw 会根据 `modelRoutes`/默认策略将 Claude 请求路由到已配置的目标模型(如 Kimi、火山 DeepSeek、OpenAI 或自建模型)。
220
+ 1. 启动 cc-gw 并在“模型管理”完成 Provider 配置。
221
+ 2. 确认第 4 步环境变量已写入当前 shell 或系统(`ANTHROPIC_BASE_URL` / `ANTHROPIC_API_KEY`)。
222
+ 3. 在 Claude Code 终端或 VS Code 插件中选择“自定义 API”,填入 `http://127.0.0.1:4100/anthropic` 并粘贴密钥。
223
+ 4. 运行 `claude "hello"` 或在 VS Code 新建对话,若能在 Web UI 的“请求日志”看到记录即成功。
76
224
 
77
225
  ### 连接 Codex(原 Claude Code for Repo)
78
- 1. 在 Web UI 的“模型管理 → 路由配置”中为 `/openai` 端点选择目标模型,默认会映射至配置中的 `defaults.completion`。
79
- 2. Codex 或其他需要 OpenAI 风格接口的客户端中,将 Base URL 设置为 `http://127.0.0.1:4100/openai/v1`;若需手动指定路径,请调用 `POST /openai/v1/responses`。
80
- 3. API Key 设置为 cc-gw 生成的密钥(支持 Bearer Header 或 `x-api-key` Header)。
81
- 4. 触发一次 `hello` 或最小请求检查 Streaming 是否正常;若遇到 `Unsupported parameter: thinking` 等提示,说明 cc-gw 已自动剥离该字段并兼容上游。
226
+ 1. 在 Web UI “路由配置”页设定 `/openai` 端点默认模型。
227
+ 2. 设置环境变量 `OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1` `OPENAI_API_KEY=<第 3 步生成的密钥>`。
228
+ 3. `~/.codex/config.toml` 按前文示例声明 `model_providers.cc_gw`,或在 CLI `codex config set` 中写入相同配置。
229
+ 4. 执行 `codex status` / `codex ask` 验证连通性;如遇 404,请确认是否调用了 `/openai/v1/responses`。
82
230
 
83
231
  ### 环境变量与客户端配置示例
84
232
 
85
- 绝大多数 Claude Code/Codex 客户端都支持通过环境变量快速切换到 cc-gw。建议在启动 IDE 或终端前写入:
86
-
87
- ```bash
88
- export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
89
- export ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
90
-
91
- # 如需走 OpenAI 兼容接口(Codex、Open Interpreter 等)
92
- export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
93
- export OPENAI_API_KEY=$ANTHROPIC_API_KEY
94
- ```
95
-
96
- 对于 Codex CLI,可在 `~/.codex/config.toml` 中直接声明 cc-gw,避免每次手动输入:
97
-
98
- ```toml
99
- model = "gpt-5-codex"
100
- model_provider = "cc_gw"
101
- model_reasoning_effort = "high"
102
- disable_response_storage = true
103
-
104
- [model_providers.cc_gw]
105
- name = "cc_gw"
106
- base_url = "http://127.0.0.1:4100/openai/v1"
107
- wire_api = "responses"
108
- env_key = "cc_gw_key"
109
- ```
110
-
111
- 设置完成后,运行 `source ~/.bashrc`(或等效文件)即可让 IDE/CLI 读取新的网关地址与密钥,无需在界面里多次粘贴。
233
+ (段落保留,已在上方详细说明,可用于快速复制粘贴。)
112
234
 
113
235
  ### 使用场景 / Usage Scenarios
114
236
 
@@ -237,16 +359,51 @@ cc-gw is a local gateway tailored for Claude Code and similar Anthropic-compatib
237
359
  | Web console | React + Vite UI with dashboards, filters, provider CRUD, bilingual copy, and responsive layout. |
238
360
  | CLI daemon | `cc-gw` command wraps start/stop/restart/status, manages PID/log files, and scaffolds a default config on first launch. |
239
361
 
240
- ### Quick Start
362
+ ### Standard Onboarding Checklist
363
+
364
+ 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`.
365
+ 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.
366
+ 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.
367
+ 4. **Export environment variables (required)**:
368
+ ```bash
369
+ export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
370
+ export ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
371
+
372
+ # Optional: OpenAI-compatible endpoint (Codex, Open Interpreter, ...)
373
+ export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
374
+ export OPENAI_API_KEY=$ANTHROPIC_API_KEY
375
+ ```
376
+ Drop these lines into your shell profile (or `direnv`) so that IDEs inherit them automatically.
377
+ 5. **Point your clients**:
378
+ - **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.
379
+ - **Codex CLI**: update `~/.codex/config.toml`:
380
+ ```toml
381
+ model = "gpt-5-codex"
382
+ model_provider = "cc_gw"
383
+ model_reasoning_effort = "high"
384
+ disable_response_storage = true
385
+
386
+ [model_providers.cc_gw]
387
+ name = "cc_gw"
388
+ base_url = "http://127.0.0.1:4100/openai/v1"
389
+ wire_api = "responses"
390
+ env_key = "cc_gw_key"
391
+ ```
392
+ Then export `CC_GW_KEY=<gateway api key>`.
393
+ 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.
394
+
395
+ > 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.
396
+
397
+ ### Quick reinstall / binary upgrade
241
398
 
242
399
  ```bash
243
400
  npm install -g @chenpu17/cc-gw
244
401
  cc-gw start --daemon --port 4100
245
402
  ```
246
403
 
247
- The first launch writes `~/.cc-gw/config.json`. Manage everything through the Web UI at `http://127.0.0.1:4100/ui`. Use `cc-gw status`, `cc-gw stop`, and `cc-gw restart` to control the daemon.
404
+ `cc-gw status`, `cc-gw stop`, and `cc-gw restart` manage the daemon. The Web UI remains at `http://127.0.0.1:4100/ui`.
248
405
 
249
- > ⚠️ **Linux build note**: We now depend on `better-sqlite3`. Prebuilt binaries ship for Node 20/22/24 on glibc & musl (x64/arm64/arm). If you’re targeting an unsupported combo, install `build-essential python3 make g++` first, then rerun `npm install -g @chenpu17/cc-gw --unsafe-perm --build-from-source`.
406
+ > ⚠️ **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`.
250
407
 
251
408
  ### From Source (contributors)
252
409
 
@@ -257,23 +414,7 @@ pnpm --filter @cc-gw/web build
257
414
  pnpm --filter @cc-gw/cli exec tsx index.ts start --daemon --port 4100
258
415
  ```
259
416
 
260
- Connect Claude Code by pointing `ANTHROPIC_BASE_URL` to the Anthropic namespace on cc-gw. Both the CLI and editor clients append `/v1/messages` automatically:
261
-
262
- ```bash
263
- export ANTHROPIC_BASE_URL=http://127.0.0.1:4100/anthropic
264
- claude "help me review this file"
265
- ```
266
-
267
- Using the Claude Code VS Code extension? Open the extension settings, enable the custom API mode, set the Base URL to the same `http://127.0.0.1:4100/anthropic`, and paste an API key generated from the cc-gw Web UI or CLI—the extension appends `/v1/messages?beta=true` automatically and cc-gw now forwards the query string upstream.
268
-
269
- Connect Codex (or any OpenAI-compatible IDE integration) by targeting the OpenAI endpoint exposed by cc-gw:
270
-
271
- ```bash
272
- export OPENAI_BASE_URL=http://127.0.0.1:4100/openai/v1
273
- export OPENAI_API_KEY="<your cc-gw api key>"
274
- ```
275
-
276
- If the client expects a full path, call `POST /openai/v1/responses`. The gateway strips unsupported fields (such as `thinking`) before forwarding to the upstream provider, so health checks like `hello` should stream back correctly.
417
+ Connect Claude Code after completing the onboarding steps above—the CLI and editor automatically append `/v1/messages`, and cc-gw will forward `?beta=true` samples or tool metadata upstream. For Codex or other OpenAI-style integrations, use `http://127.0.0.1:4100/openai/v1` (or the equivalent value from step 4) and hit `POST /openai/v1/responses` if the client requires an explicit path.
277
418
 
278
419
  ### Configuration Snapshot
279
420
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenpu17/cc-gw",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -59,6 +59,7 @@
59
59
  "better-sqlite3": "^12.4.1",
60
60
  "colorette": "^2.0.20",
61
61
  "commander": "^12.0.0",
62
+ "jszip": "^3.10.1",
62
63
  "fastify": "^4.26.2",
63
64
  "open": "^10.1.0",
64
65
  "tiktoken": "^1.0.21",