aicodeswitch 2.1.3 → 2.1.5
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 +29 -12
- package/dist/server/main.js +1 -0
- package/dist/server/proxy-server.js +6 -4
- package/dist/types/index.js +9 -0
- package/dist/ui/assets/{index-JLfUlR-1.js → index-4IziQEi6.js} +81 -63
- package/dist/ui/assets/index-BVblbmz5.css +1 -0
- package/dist/ui/index.html +2 -2
- package/package.json +1 -1
- package/dist/ui/assets/index-CYoOk21n.css +0 -1
package/README.md
CHANGED
|
@@ -10,13 +10,19 @@ AI Code Switch 是帮助你在本地管理 AI 编程工具接入大模型的工
|
|
|
10
10
|
- 视频演示:[https://www.bilibili.com/video/BV1uEznBuEJd/](https://www.bilibili.com/video/BV1uEznBuEJd/?from=github)
|
|
11
11
|
- 1分钟让Claude Code接入GLM国产模型:[https://www.bilibili.com/video/BV1a865B8ErA/](https://www.bilibili.com/video/BV1a865B8ErA/)
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 桌面版
|
|
14
|
+
|
|
15
|
+
桌面端应用下载:[https://github.com/tangshuang/aicodeswitch/releases](https://github.com/tangshuang/aicodeswitch/releases)
|
|
16
|
+
|
|
17
|
+
## 命令行工具
|
|
18
|
+
|
|
19
|
+
### 安装
|
|
14
20
|
|
|
15
21
|
```
|
|
16
22
|
npm install -g aicodeswitch
|
|
17
23
|
```
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
### 使用方法
|
|
20
26
|
|
|
21
27
|
**启动服务**
|
|
22
28
|
|
|
@@ -24,6 +30,12 @@ npm install -g aicodeswitch
|
|
|
24
30
|
aicos start
|
|
25
31
|
```
|
|
26
32
|
|
|
33
|
+
或者直接运行
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
aicos ui
|
|
37
|
+
```
|
|
38
|
+
|
|
27
39
|
**停止服务**
|
|
28
40
|
|
|
29
41
|
```
|
|
@@ -42,6 +54,8 @@ aicos ui
|
|
|
42
54
|
http://127.0.0.1:4567
|
|
43
55
|
```
|
|
44
56
|
|
|
57
|
+
## 管理界面
|
|
58
|
+
|
|
45
59
|
**配置供应商**
|
|
46
60
|
|
|
47
61
|
* 什么是供应商?
|
|
@@ -127,11 +141,18 @@ aicodeswitch内部,会根据“源类型”来转换数据。例如,你的
|
|
|
127
141
|
|
|
128
142
|
你可以根据你的实际情况来实时切换路由,比如,你可以在发现自己的某个服务商处的余额较少时,立即切换到另外一个服务商。
|
|
129
143
|
|
|
130
|
-
|
|
144
|
+
**智能故障切换机制**
|
|
145
|
+
|
|
146
|
+
当同一请求类型配置多个规则时,系统会按排序优先使用第一个,如果某个服务报错(4xx/5xx)或请求超时,将自动切换到下一个可用规则,确保你可以正常使用coding工具。
|
|
147
|
+
|
|
148
|
+
## Skills管理
|
|
149
|
+
|
|
150
|
+
你可以在 aicodeswitch 中集中统一管理 skills,把skills分发给claude code和codex,随时启用和停用skills。
|
|
151
|
+
另外,你可以基于自然语言搜索skills,找到skill之后,支持一键安装。
|
|
131
152
|
|
|
132
|
-
|
|
153
|
+
## 日志
|
|
133
154
|
|
|
134
|
-
|
|
155
|
+
在**日志**页面,您可以查看:
|
|
135
156
|
|
|
136
157
|
**请求日志**:所有 API 请求的详细记录
|
|
137
158
|
|
|
@@ -140,18 +161,14 @@ aicodeswitch内部,会根据“源类型”来转换数据。例如,你的
|
|
|
140
161
|
* 耗时和状态码
|
|
141
162
|
* 错误信息(如有)
|
|
142
163
|
|
|
143
|
-
**访问日志**:系统访问记录
|
|
144
|
-
|
|
145
|
-
* 访问时间
|
|
146
|
-
* 请求路径
|
|
147
|
-
* HTTP 方法
|
|
148
|
-
|
|
149
164
|
**错误日志**:错误和异常记录
|
|
150
165
|
|
|
151
166
|
* 错误类型
|
|
152
167
|
* 错误详情
|
|
153
168
|
* 发生时间
|
|
154
169
|
|
|
170
|
+
**会话日志**:按照会话session来汇集日志
|
|
171
|
+
|
|
155
172
|
**日志筛选**
|
|
156
173
|
|
|
157
174
|
根据提供的选项进行筛选。
|
|
@@ -219,4 +236,4 @@ PORT=4567
|
|
|
219
236
|
|
|
220
237
|
## 技术支持
|
|
221
238
|
|
|
222
|
-
如有问题或建议,请访问项目 [GitHub 仓库](https://github.com/tangshuang/aicodeswitch/issues)提交 Issue。
|
|
239
|
+
如有问题或建议,请访问项目 [GitHub 仓库](https://github.com/tangshuang/aicodeswitch/issues)提交 Issue。
|
package/dist/server/main.js
CHANGED
|
@@ -114,6 +114,7 @@ const writeClaudeConfig = (dbManager) => __awaiter(void 0, void 0, void 0, funct
|
|
|
114
114
|
const claudeSettings = {
|
|
115
115
|
env: {
|
|
116
116
|
ANTHROPIC_AUTH_TOKEN: config.apiKey || "api_key",
|
|
117
|
+
ANTHROPIC_API_KEY: "",
|
|
117
118
|
ANTHROPIC_BASE_URL: `http://${host}:${port}/claude-code`,
|
|
118
119
|
API_TIMEOUT_MS: "3000000"
|
|
119
120
|
}
|
|
@@ -53,6 +53,7 @@ const streaming_1 = require("./transformers/streaming");
|
|
|
53
53
|
const chunk_collector_1 = require("./transformers/chunk-collector");
|
|
54
54
|
const rules_status_service_1 = require("./rules-status-service");
|
|
55
55
|
const claude_openai_1 = require("./transformers/claude-openai");
|
|
56
|
+
const types_1 = require("../types");
|
|
56
57
|
const SUPPORTED_TARGETS = ['claude-code', 'codex'];
|
|
57
58
|
class ProxyServer {
|
|
58
59
|
constructor(dbManager, app) {
|
|
@@ -1128,7 +1129,8 @@ class ProxyServer {
|
|
|
1128
1129
|
buildUpstreamHeaders(req, service, sourceType, streamRequested) {
|
|
1129
1130
|
const headers = {};
|
|
1130
1131
|
for (const [key, value] of Object.entries(req.headers)) {
|
|
1131
|
-
|
|
1132
|
+
// 排除原始认证头,防止与代理设置的认证头冲突
|
|
1133
|
+
if (['host', 'connection', 'content-length', 'authorization', 'x-api-key', 'x-anthropic-api-key', 'anthropic-api-key'].includes(key.toLowerCase())) {
|
|
1132
1134
|
continue;
|
|
1133
1135
|
}
|
|
1134
1136
|
if (typeof value === 'string') {
|
|
@@ -1142,12 +1144,12 @@ class ProxyServer {
|
|
|
1142
1144
|
headers.accept = 'text/event-stream';
|
|
1143
1145
|
}
|
|
1144
1146
|
// 确定认证方式:优先使用服务配置的 authType,否则根据 sourceType 自动判断
|
|
1145
|
-
const authType = service.authType ||
|
|
1146
|
-
const useXApiKey = authType ===
|
|
1147
|
+
const authType = service.authType || types_1.AuthType.AUTO;
|
|
1148
|
+
const useXApiKey = authType === types_1.AuthType.API_KEY || (authType === types_1.AuthType.AUTO && this.isClaudeSource(sourceType));
|
|
1147
1149
|
if (useXApiKey) {
|
|
1148
1150
|
// 使用 x-api-key 认证(适用于 claude-chat, claude-code 及某些需要 x-api-key 的 openai-chat 兼容 API)
|
|
1149
1151
|
headers['x-api-key'] = service.apiKey;
|
|
1150
|
-
if (this.isClaudeSource(sourceType) || authType ===
|
|
1152
|
+
if (this.isClaudeSource(sourceType) || authType === types_1.AuthType.API_KEY) {
|
|
1151
1153
|
// 仅在明确配置或 Claude 源时添加 anthropic-version
|
|
1152
1154
|
headers['anthropic-version'] = headers['anthropic-version'] || '2023-06-01';
|
|
1153
1155
|
}
|
package/dist/types/index.js
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthType = void 0;
|
|
4
|
+
/** 认证方式类型 */
|
|
5
|
+
var AuthType;
|
|
6
|
+
(function (AuthType) {
|
|
7
|
+
AuthType["AUTH_TOKEN"] = "authorization";
|
|
8
|
+
AuthType["API_KEY"] = "x-api-key";
|
|
9
|
+
AuthType["AUTO"] = "auto";
|
|
10
|
+
})(AuthType || (exports.AuthType = AuthType = {}));
|
|
11
|
+
;
|