@hsupu/copilot-api 0.7.15 → 0.7.17-beta.0
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 +103 -110
- package/dist/{main.js → main.mjs} +3366 -3088
- package/dist/main.mjs.map +1 -0
- package/package.json +12 -12
- package/dist/main.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,167 +1,160 @@
|
|
|
1
1
|
# Copilot API Proxy (Fork)
|
|
2
2
|
|
|
3
|
-
> [!NOTE]
|
|
4
|
-
> This is a fork of [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api) with additional improvements and bug fixes.
|
|
5
|
-
|
|
6
3
|
> [!WARNING]
|
|
7
|
-
>
|
|
4
|
+
> 这是 GitHub Copilot API 的逆向代理。GitHub 官方不提供支持,且可能随时失效。使用风险自负。
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
本项目是 [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api) 的 fork,因使用中遇到报错,故尝试魔改。
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
## Fork 的考虑和改进
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
CC + Opus/Haiku 是作者的唯一核心场景。其他任何花哨的功能要么是继承自上游,要么是 fallback 方案。改动全 AI 完成,我只提供功能需求、参考项目和使用反馈。
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
- **Adaptive rate limiting**: Smart rate limiting with exponential backoff, auto-recovery, and Retry-After support (replaces queue-based limiting)
|
|
17
|
-
- **Direct Anthropic API**: Claude models use Copilot's native Anthropic endpoint without translation overhead
|
|
18
|
-
- **Smart auto-truncate**: Automatically truncates conversation history when exceeding context limits, with optional tool result compression
|
|
19
|
-
- **`/v1/event_logging/batch` endpoint**: Compatibility endpoint for Anthropic SDK's event logging (returns OK without processing)
|
|
20
|
-
- **`logout` command**: Remove stored GitHub token with `copilot-api logout`
|
|
21
|
-
- **`patch-claude` command**: Patch Claude Code's context window limit to match Copilot's limits
|
|
22
|
-
- **Tool name length handling**: Automatically truncates long tool names (>64 chars) to comply with OpenAI's limit, with hash-based suffix to avoid collisions. Original names are restored in responses.
|
|
23
|
-
- **Request History UI**: Built-in Web UI (enabled by default) to view, search, filter, and export all API requests/responses. Access at `/history`.
|
|
12
|
+
本 fork 相对于上游项目包含以下增强:
|
|
24
13
|
|
|
25
|
-
###
|
|
14
|
+
### 新功能
|
|
26
15
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
16
|
+
- **`--host` 选项**:将服务器绑定到指定网络接口(如 `--host 0.0.0.0` 绑定所有接口,`--host 127.0.0.1` 仅绑定本地)
|
|
17
|
+
- **自适应限流**:基于指数退避的智能限流,支持自动恢复和 Retry-After 头(替代原有的队列限流)
|
|
18
|
+
- **直连 Anthropic API**:Claude 模型使用 Copilot 的原生 Anthropic 端点,无需格式转换
|
|
19
|
+
- **智能自动截断**:超出上下文限制时自动截断对话历史,支持可选的 tool result 压缩
|
|
20
|
+
- **`/api/event_logging/batch` 端点**:为 Anthropic SDK 的 event logging 提供兼容端点(返回 OK,不做处理)
|
|
21
|
+
- **`logout` 命令**:通过 `copilot-api logout` 移除已存储的 GitHub token
|
|
22
|
+
- **`list-claude-code` 命令**:列出所有本地安装的 Claude Code 版本
|
|
23
|
+
- **工具名长度处理**:自动截断超过 64 字符的工具名以符合 OpenAI 限制,使用 hash 后缀避免冲突。响应中会还原原始名称。
|
|
24
|
+
- **请求历史 UI**:内置 Web UI(默认启用),可查看、搜索、过滤和导出所有 API 请求/响应。访问 `/history`。
|
|
25
|
+
- **`setup-claude-code` 命令**:交互式配置 Claude Code 以使用本代理
|
|
26
|
+
- **Sonnet 重定向到 Opus**:可选将 sonnet 模型请求重定向到最佳可用 opus 模型
|
|
27
|
+
- **安全研究模式**:为授权渗透测试、CTF 和安全教育提供专用模式
|
|
30
28
|
|
|
31
|
-
###
|
|
29
|
+
### Bug 修复
|
|
32
30
|
|
|
33
|
-
-
|
|
31
|
+
- **修复流式响应中缺少 `model` 字段**:Copilot API 的首个流式 chunk 有时 `choices` 数组为空但包含模型名。现已保存该值供后续事件使用。
|
|
32
|
+
- **自动修复消息序列错误**:当 tool 调用被中断(如用户取消)时,API 会自动添加占位 `tool_result` 块以维持合法的消息序列
|
|
33
|
+
- **修复 `bunx` 符号链接问题**:将 pre-commit hook 改为使用 `bun x` 替代 `bunx` 以提高兼容性
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## 快速开始
|
|
36
36
|
|
|
37
|
-
###
|
|
37
|
+
### 从 npm 安装(推荐)
|
|
38
38
|
|
|
39
39
|
```sh
|
|
40
|
-
#
|
|
40
|
+
# 直接用 npx 运行
|
|
41
41
|
npx @hsupu/copilot-api start
|
|
42
42
|
|
|
43
|
-
#
|
|
43
|
+
# 或全局安装
|
|
44
44
|
npm install -g @hsupu/copilot-api
|
|
45
45
|
copilot-api start
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### 从 GitHub 安装
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
也可以直接从 GitHub 安装(需要构建步骤):
|
|
51
51
|
|
|
52
52
|
```sh
|
|
53
53
|
npm install -g github:puxu-msft/copilot-api-js
|
|
54
54
|
copilot-api start
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
###
|
|
57
|
+
### 从源码运行
|
|
58
58
|
|
|
59
59
|
```sh
|
|
60
|
-
#
|
|
60
|
+
# 克隆仓库
|
|
61
61
|
git clone https://github.com/puxu-msft/copilot-api-js.git
|
|
62
62
|
cd copilot-api-js
|
|
63
63
|
|
|
64
|
-
#
|
|
64
|
+
# 安装依赖
|
|
65
65
|
bun install
|
|
66
66
|
|
|
67
|
-
#
|
|
67
|
+
# 开发模式(热重载)
|
|
68
68
|
bun run dev
|
|
69
69
|
|
|
70
|
-
#
|
|
70
|
+
# 生产模式
|
|
71
71
|
bun run start
|
|
72
72
|
|
|
73
|
-
#
|
|
73
|
+
# 构建发布版
|
|
74
74
|
bun run build
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
###
|
|
77
|
+
### 构建后使用
|
|
78
78
|
|
|
79
79
|
```sh
|
|
80
|
-
#
|
|
80
|
+
# 本地运行构建版本
|
|
81
81
|
npx .
|
|
82
82
|
|
|
83
|
-
#
|
|
83
|
+
# 或全局链接
|
|
84
84
|
bun link
|
|
85
85
|
copilot-api start
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
##
|
|
89
|
-
|
|
90
|
-
|
|
|
91
|
-
|
|
92
|
-
| `start` |
|
|
93
|
-
| `auth` |
|
|
94
|
-
| `logout` |
|
|
95
|
-
| `check-usage` |
|
|
96
|
-
| `debug` |
|
|
97
|
-
| `
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
| `--
|
|
105
|
-
| `--
|
|
106
|
-
| `--
|
|
107
|
-
| `--
|
|
108
|
-
| `--
|
|
109
|
-
| `--
|
|
110
|
-
| `--
|
|
111
|
-
| `--
|
|
112
|
-
| `--
|
|
113
|
-
| `--
|
|
114
|
-
| `--
|
|
115
|
-
| `--show-token` |
|
|
116
|
-
| `--proxy-env` |
|
|
117
|
-
| `--
|
|
118
|
-
| `--
|
|
119
|
-
| `--no-
|
|
120
|
-
| `--
|
|
121
|
-
| `--
|
|
122
|
-
| `--
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
## API Endpoints
|
|
134
|
-
|
|
135
|
-
### OpenAI Compatible
|
|
136
|
-
|
|
137
|
-
| Endpoint | Method | Description |
|
|
138
|
-
|----------|--------|-------------|
|
|
88
|
+
## 命令参考
|
|
89
|
+
|
|
90
|
+
| 命令 | 说明 |
|
|
91
|
+
|------|------|
|
|
92
|
+
| `start` | 启动 API 服务器(需要时自动进行认证) |
|
|
93
|
+
| `auth` | 仅运行 GitHub 认证流程 |
|
|
94
|
+
| `logout` | 移除已存储的 GitHub token |
|
|
95
|
+
| `check-usage` | 查看 Copilot 用量和配额 |
|
|
96
|
+
| `debug` | 显示诊断信息 |
|
|
97
|
+
| `list-claude-code` | 列出所有本地安装的 Claude Code 版本 |
|
|
98
|
+
| `setup-claude-code` | 交互式配置 Claude Code 连接 |
|
|
99
|
+
|
|
100
|
+
### start 命令选项
|
|
101
|
+
|
|
102
|
+
| 选项 | 说明 | 默认值 |
|
|
103
|
+
|------|------|--------|
|
|
104
|
+
| `--port`, `-p` | 监听端口 | 4141 |
|
|
105
|
+
| `--host`, `-H` | 绑定的主机/接口 | (所有接口) |
|
|
106
|
+
| `--verbose`, `-v` | 启用详细日志 | false |
|
|
107
|
+
| `--account-type`, `-a` | 账户类型(individual, business, enterprise) | individual |
|
|
108
|
+
| `--manual` | 手动请求审批模式 | false |
|
|
109
|
+
| `--no-rate-limit` | 禁用自适应限流 | false |
|
|
110
|
+
| `--retry-interval` | 限流后重试等待秒数 | 10 |
|
|
111
|
+
| `--request-interval` | 限流模式下请求间隔秒数 | 10 |
|
|
112
|
+
| `--recovery-timeout` | 尝试恢复前等待的分钟数 | 10 |
|
|
113
|
+
| `--consecutive-successes` | 退出限流模式所需的连续成功次数 | 5 |
|
|
114
|
+
| `--github-token`, `-g` | 直接提供 GitHub token | 无 |
|
|
115
|
+
| `--show-github-token` | 在日志中显示 GitHub token | false |
|
|
116
|
+
| `--proxy-env` | 使用环境变量中的代理 | false |
|
|
117
|
+
| `--history-limit` | 内存中最大历史记录条数(0 = 无限) | 200 |
|
|
118
|
+
| `--no-auto-truncate` | 禁用超限自动截断 | false |
|
|
119
|
+
| `--no-compress-tool-results` | 禁用自动截断时的 tool result 压缩 | false(默认启用压缩) |
|
|
120
|
+
| `--redirect-anthropic` | 强制 Anthropic 请求走 OpenAI 转换 | false |
|
|
121
|
+
| `--no-rewrite-anthropic-tools` | 不重写服务端工具 | false |
|
|
122
|
+
| `--redirect-count-tokens` | count_tokens 走 OpenAI 转换而非原生 Anthropic | false |
|
|
123
|
+
| `--redirect-sonnet-to-opus` | 将 sonnet 模型请求重定向到最佳可用 opus 模型 | false |
|
|
124
|
+
| `--security-research-mode` | 启用安全研究模式(需要口令) | 无 |
|
|
125
|
+
|
|
126
|
+
## API 端点
|
|
127
|
+
|
|
128
|
+
### OpenAI 兼容
|
|
129
|
+
|
|
130
|
+
| 端点 | 方法 | 说明 |
|
|
131
|
+
|------|------|------|
|
|
139
132
|
| `/v1/chat/completions` | POST | Chat completions |
|
|
140
|
-
| `/v1/models` | GET |
|
|
141
|
-
| `/v1/embeddings` | POST |
|
|
133
|
+
| `/v1/models` | GET | 列出可用模型 |
|
|
134
|
+
| `/v1/embeddings` | POST | 文本嵌入 |
|
|
142
135
|
|
|
143
|
-
### Anthropic
|
|
136
|
+
### Anthropic 兼容
|
|
144
137
|
|
|
145
|
-
|
|
|
146
|
-
|
|
138
|
+
| 端点 | 方法 | 说明 |
|
|
139
|
+
|------|------|------|
|
|
147
140
|
| `/v1/messages` | POST | Messages API |
|
|
148
|
-
| `/v1/messages/count_tokens` | POST | Token
|
|
149
|
-
| `/
|
|
141
|
+
| `/v1/messages/count_tokens` | POST | Token 计数 |
|
|
142
|
+
| `/api/event_logging/batch` | POST | Event logging(空操作) |
|
|
150
143
|
|
|
151
|
-
###
|
|
144
|
+
### 工具端点
|
|
152
145
|
|
|
153
|
-
|
|
|
154
|
-
|
|
155
|
-
| `/` | GET |
|
|
156
|
-
| `/usage` | GET | Copilot
|
|
157
|
-
| `/token` | GET |
|
|
158
|
-
| `/health` | GET |
|
|
159
|
-
| `/history` | GET |
|
|
160
|
-
| `/history/api/*` | GET/DELETE |
|
|
146
|
+
| 端点 | 方法 | 说明 |
|
|
147
|
+
|------|------|------|
|
|
148
|
+
| `/` | GET | 服务器状态 |
|
|
149
|
+
| `/usage` | GET | Copilot 用量统计 |
|
|
150
|
+
| `/token` | GET | 当前 Copilot token |
|
|
151
|
+
| `/health` | GET | 健康检查 |
|
|
152
|
+
| `/history` | GET | 请求历史 Web UI(默认启用) |
|
|
153
|
+
| `/history/api/*` | GET/DELETE | 历史记录 API 端点 |
|
|
161
154
|
|
|
162
|
-
##
|
|
155
|
+
## 配合 Claude Code 使用
|
|
163
156
|
|
|
164
|
-
|
|
157
|
+
在用户根目录或者打开的项目中创建 `.claude/settings.json`:
|
|
165
158
|
|
|
166
159
|
```json
|
|
167
160
|
{
|
|
@@ -179,12 +172,12 @@ Create `.claude/settings.json` in your project:
|
|
|
179
172
|
}
|
|
180
173
|
```
|
|
181
174
|
|
|
182
|
-
|
|
175
|
+
或使用交互式设置:
|
|
183
176
|
|
|
184
177
|
```sh
|
|
185
|
-
|
|
178
|
+
copilot-api setup-claude-code
|
|
186
179
|
```
|
|
187
180
|
|
|
188
|
-
##
|
|
181
|
+
## 上游项目
|
|
189
182
|
|
|
190
|
-
|
|
183
|
+
原始项目的文档、功能和更新请参见:[ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api)
|