@chenpu17/cc-gw 0.3.6 → 0.3.8
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/README.md +39 -4
- package/package.json +1 -1
- package/src/cli/dist/index.js +36 -3
- package/src/server/dist/index.js +472 -117
- package/src/web/dist/assets/About-B4P46oBY.js +11 -0
- package/src/web/dist/assets/ApiKeys-DIj-z9NS.js +16 -0
- package/src/web/dist/assets/Button-Df2SC9Z6.js +1 -0
- package/src/web/dist/assets/Dashboard-ofxha89A.js +16 -0
- package/src/web/dist/assets/FormField-IhMRFkvg.js +1 -0
- package/src/web/dist/assets/Help-DWp0N8et.js +6 -0
- package/src/web/dist/assets/Input-BR1EKmIk.js +1 -0
- package/src/web/dist/assets/Login-D8amVPUK.js +1 -0
- package/src/web/dist/assets/Logs-DRwOarji.js +1 -0
- package/src/web/dist/assets/ModelManagement-CtaCkRed.js +1 -0
- package/src/web/dist/assets/PageSection-D21hdQmW.js +1 -0
- package/src/web/dist/assets/Settings-C2-eI9Yb.js +1 -0
- package/src/web/dist/assets/StatusBadge-CMf3e9GN.js +1 -0
- package/src/web/dist/assets/copy-C0txfzHv.js +6 -0
- package/src/web/dist/assets/index-BRI-aVAi.css +1 -0
- package/src/web/dist/assets/index-DtM-AT3x.js +148 -0
- package/src/web/dist/assets/{index-B0rGDFRO.js → index-oWYCCpBl.js} +1 -1
- package/src/web/dist/assets/info-jEzfgMxW.js +6 -0
- package/src/web/dist/assets/useApiQuery-Dz2idWoC.js +1 -0
- package/src/web/dist/index.html +2 -2
- package/src/web/dist/assets/About-Cgfq_d7I.js +0 -1
- package/src/web/dist/assets/ApiKeys-C4QbVKdv.js +0 -21
- package/src/web/dist/assets/Dashboard-28JGQst7.js +0 -1
- package/src/web/dist/assets/Help-BojpuZMh.js +0 -1
- package/src/web/dist/assets/Logs-B1rVvkYR.js +0 -1
- package/src/web/dist/assets/ModelManagement-DIMCLs1b.js +0 -1
- package/src/web/dist/assets/Settings-CB4YZNh9.js +0 -1
- package/src/web/dist/assets/index-Gx2WWHJn.css +0 -1
- package/src/web/dist/assets/index-wA9rsqII.js +0 -133
- package/src/web/dist/assets/useApiQuery-De0jYBDD.js +0 -6
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ pnpm --filter @cc-gw/cli exec tsx index.ts start --daemon --port 4100
|
|
|
53
53
|
- **请求日志**:多条件筛选(时间、Provider、模型、状态),查看压缩日志详情,支持分页导出与清理。
|
|
54
54
|
- **模型管理**:维护 Provider 列表、预置模型、路由策略;一键测试连通性(发送诊断 PROMPT),支持保存并应用 Anthropic 路由模板,实现不同 Provider 方案的“一键切换”。
|
|
55
55
|
- **系统设置**:端口、日志保留策略、是否存储请求 payload、日志级别与访问日志开关、日志清理工具。
|
|
56
|
+
- **安全控制**:在“系统设置 → 安全”中可启用 Web UI 登录校验,自定义用户名及密码并自动保护所有 `/api/*` 管理接口(模型请求端点仍保持开放)。
|
|
56
57
|
- **使用指南**:提供图文步骤、常见问题与排查提示,帮助团队成员快速熟悉配置流程。
|
|
57
58
|
|
|
58
59
|
UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供键盘可达性(Skip Link、焦点管理)。
|
|
@@ -79,6 +80,36 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
|
|
|
79
80
|
3. 将 API Key 设置为 cc-gw 生成的密钥(支持 Bearer Header 或 `x-api-key` Header)。
|
|
80
81
|
4. 触发一次 `hello` 或最小请求检查 Streaming 是否正常;若遇到 `Unsupported parameter: thinking` 等提示,说明 cc-gw 已自动剥离该字段并兼容上游。
|
|
81
82
|
|
|
83
|
+
### 环境变量与客户端配置示例
|
|
84
|
+
|
|
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 读取新的网关地址与密钥,无需在界面里多次粘贴。
|
|
112
|
+
|
|
82
113
|
### 使用场景 / Usage Scenarios
|
|
83
114
|
|
|
84
115
|
1. **双端点适配 / Dual Endpoint Support**:通过 `/anthropic` 与 `/openai` 端点,分别兼容 Claude Code 与 Codex 客户端。无需重启 cc-gw,即可在 Web UI 中为两个端点配置独立的默认模型与路由策略。
|
|
@@ -127,7 +158,8 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
|
|
|
127
158
|
"claude-opus-4-1-20250805": "anthropic:claude-3-5-sonnet-latest"
|
|
128
159
|
},
|
|
129
160
|
"logRetentionDays": 30,
|
|
130
|
-
"
|
|
161
|
+
"storeRequestPayloads": true,
|
|
162
|
+
"storeResponsePayloads": true,
|
|
131
163
|
"logLevel": "info",
|
|
132
164
|
"requestLogging": true,
|
|
133
165
|
"responseLogging": true
|
|
@@ -140,7 +172,8 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
|
|
|
140
172
|
- 模型标识使用 `providerId:modelId` 形式供路由引用。
|
|
141
173
|
- `modelRoutes`:将 Claude 发起的模型名映射到上游模型;未命中时使用 `defaults`。
|
|
142
174
|
- `routingPresets`:可选字段,保存多个 `anthropic`(或其他端点)路由模板,供 Web UI “一键切换”;每个模板仅包含 `name` 与 `modelRoutes`。
|
|
143
|
-
- `
|
|
175
|
+
- `storeRequestPayloads` / `storeResponsePayloads`:是否分别在 SQLite 中压缩保存请求原文与响应内容;关闭可减少敏感数据落盘。
|
|
176
|
+
- `bodyLimit`:单次请求允许的最大请求体大小(字节),默认 10 MiB。`/compact` 等场景会发送较大上下文,如遇 413 可按需增大。
|
|
144
177
|
- `logLevel`:控制 Fastify/Pino 控制台日志级别(`fatal`/`error`/`warn`/`info`/`debug`/`trace`)。
|
|
145
178
|
- `providers[].authMode`:仅在 `type: "anthropic"` 时生效,可选 `apiKey`(默认,发送 `x-api-key`)或 `authToken`(发送 `Authorization: Bearer`)。配置 Claude Code 使用 `ANTHROPIC_AUTH_TOKEN` 时,请选择 `authToken` 并在 `apiKey` 输入框填入该值。
|
|
146
179
|
- `requestLogging`:是否输出每个 HTTP 请求的进入日志。
|
|
@@ -172,6 +205,7 @@ pnpm --filter @cc-gw/cli exec tsx index.ts status
|
|
|
172
205
|
|
|
173
206
|
- 守护模式下 PID/日志存放于 `~/.cc-gw/cc-gw.pid` 与 `~/.cc-gw/logs/cc-gw.log`。
|
|
174
207
|
- `status` 会回显配置与日志路径,便于排查。
|
|
208
|
+
- `cc-gw version`(或 `cc-gw --version`)可输出与 npm 包同步的版本号,便于核对升级情况。
|
|
175
209
|
|
|
176
210
|
## 数据与日志
|
|
177
211
|
|
|
@@ -199,7 +233,7 @@ cc-gw is a local gateway tailored for Claude Code and similar Anthropic-compatib
|
|
|
199
233
|
| ------- | ------- |
|
|
200
234
|
| Protocol adaptation | Converts Claude-style payloads into OpenAI-, Anthropic-, Kimi-, and DeepSeek-compatible requests while preserving tool calls and reasoning blocks. |
|
|
201
235
|
| 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. |
|
|
202
|
-
| Observability | Persists request logs, token usage (including cache hits), TTFT, TPOT, and daily aggregates via better-sqlite3 with Brotli-compressed payloads. |
|
|
236
|
+
| 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. |
|
|
203
237
|
| Web console | React + Vite UI with dashboards, filters, provider CRUD, bilingual copy, and responsive layout. |
|
|
204
238
|
| CLI daemon | `cc-gw` command wraps start/stop/restart/status, manages PID/log files, and scaffolds a default config on first launch. |
|
|
205
239
|
|
|
@@ -246,7 +280,8 @@ If the client expects a full path, call `POST /openai/v1/responses`. The gateway
|
|
|
246
280
|
- Providers include `type`, `baseUrl`, `apiKey`, and `models` descriptions.
|
|
247
281
|
- When `type` is `anthropic`, cc-gw forwards the original Claude payload and all headers to `<baseUrl>/v1/messages`, so tool calls/metadata remain intact.
|
|
248
282
|
- Model routes use `providerId:modelId` syntax to remap Claude requests.
|
|
249
|
-
- `
|
|
283
|
+
- `storeRequestPayloads` / `storeResponsePayloads` control whether prompts and completions are persisted; disable either switch to avoid storing sensitive data.
|
|
284
|
+
- `bodyLimit`: maximum request body size (in bytes). Defaults to 10 MiB—raise this if clients like Claude Code `/compact` hit HTTP 413.
|
|
250
285
|
- `logLevel` adjusts Fastify/Pino verbosity (`fatal` → `trace`).
|
|
251
286
|
- `requestLogging` controls whether per-request access logs are emitted to the console.
|
|
252
287
|
- `responseLogging` toggles completion logs separately so you can keep the console quieter while preserving metrics.
|
package/package.json
CHANGED
package/src/cli/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import path from "path";
|
|
|
10
10
|
import process from "process";
|
|
11
11
|
import { fileURLToPath } from "url";
|
|
12
12
|
import { green, yellow } from "colorette";
|
|
13
|
+
import { createRequire } from "module";
|
|
13
14
|
var program = new Command();
|
|
14
15
|
var DEFAULT_PORT = 4100;
|
|
15
16
|
var HOME_DIR = path.join(os.homedir(), ".cc-gw");
|
|
@@ -17,6 +18,27 @@ var PID_FILE = path.join(HOME_DIR, "cc-gw.pid");
|
|
|
17
18
|
var LOG_DIR = path.join(HOME_DIR, "logs");
|
|
18
19
|
var LOG_FILE = path.join(LOG_DIR, "cc-gw.log");
|
|
19
20
|
var CONFIG_FILE = path.join(HOME_DIR, "config.json");
|
|
21
|
+
var require2 = createRequire(import.meta.url);
|
|
22
|
+
function resolvePackageVersion() {
|
|
23
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
24
|
+
const __dirname = path.dirname(__filename);
|
|
25
|
+
const candidates = [
|
|
26
|
+
path.resolve(__dirname, "../../package.json"),
|
|
27
|
+
path.resolve(__dirname, "../package.json"),
|
|
28
|
+
path.resolve(__dirname, "../../../package.json")
|
|
29
|
+
];
|
|
30
|
+
for (const candidate of candidates) {
|
|
31
|
+
try {
|
|
32
|
+
const pkg = require2(candidate);
|
|
33
|
+
if (pkg && typeof pkg.version === "string") {
|
|
34
|
+
return pkg.version;
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return "0.0.0";
|
|
40
|
+
}
|
|
41
|
+
var CLI_VERSION = resolvePackageVersion();
|
|
20
42
|
async function readConfiguredPort() {
|
|
21
43
|
try {
|
|
22
44
|
const raw = await fsp.readFile(CONFIG_FILE, "utf-8");
|
|
@@ -79,6 +101,8 @@ async function ensureConfigTemplate(port) {
|
|
|
79
101
|
port: selectedPort,
|
|
80
102
|
providers: [],
|
|
81
103
|
defaults: { ...baseDefaults },
|
|
104
|
+
storeRequestPayloads: true,
|
|
105
|
+
storeResponsePayloads: true,
|
|
82
106
|
endpointRouting: {
|
|
83
107
|
anthropic: {
|
|
84
108
|
defaults: { ...baseDefaults },
|
|
@@ -91,10 +115,16 @@ async function ensureConfigTemplate(port) {
|
|
|
91
115
|
},
|
|
92
116
|
logRetentionDays: 30,
|
|
93
117
|
modelRoutes: {},
|
|
94
|
-
storePayloads: true,
|
|
95
118
|
logLevel: "info",
|
|
96
119
|
requestLogging: true,
|
|
97
|
-
responseLogging: true
|
|
120
|
+
responseLogging: true,
|
|
121
|
+
bodyLimit: 10 * 1024 * 1024,
|
|
122
|
+
webAuth: {
|
|
123
|
+
enabled: false,
|
|
124
|
+
username: "",
|
|
125
|
+
passwordHash: "",
|
|
126
|
+
passwordSalt: ""
|
|
127
|
+
}
|
|
98
128
|
};
|
|
99
129
|
await fsp.mkdir(path.dirname(CONFIG_FILE), { recursive: true });
|
|
100
130
|
await fsp.writeFile(CONFIG_FILE, JSON.stringify(template, null, 2), "utf-8");
|
|
@@ -246,7 +276,10 @@ async function handleStatus() {
|
|
|
246
276
|
console.log(`\u65E5\u5FD7\u76EE\u5F55: ${LOG_DIR}`);
|
|
247
277
|
console.log(`\u914D\u7F6E\u6587\u4EF6: ${CONFIG_FILE}`);
|
|
248
278
|
}
|
|
249
|
-
program.name("cc-gw").description("Claude Code Gateway CLI").version(
|
|
279
|
+
program.name("cc-gw").description("Claude Code Gateway CLI").version(CLI_VERSION);
|
|
280
|
+
program.command("version").description("\u663E\u793A\u5F53\u524D cc-gw CLI \u7248\u672C").action(() => {
|
|
281
|
+
console.log(`cc-gw CLI \u7248\u672C: ${CLI_VERSION}`);
|
|
282
|
+
});
|
|
250
283
|
program.command("start").description("\u542F\u52A8 cc-gw \u670D\u52A1").option("--daemon", "\u4EE5\u5B88\u62A4\u8FDB\u7A0B\u65B9\u5F0F\u8FD0\u884C\uFF08\u9ED8\u8BA4\uFF09").option("--foreground", "\u4EE5\u524D\u53F0\u6A21\u5F0F\u8FD0\u884C\u5E76\u4FDD\u6301\u63A7\u5236\u53F0\u8F93\u51FA").option("--port <port>", "\u6307\u5B9A\u670D\u52A1\u76D1\u542C\u7AEF\u53E3").action(async (options) => {
|
|
251
284
|
try {
|
|
252
285
|
await handleStart(options);
|