cursor-openai-byok 1.0.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.
- package/README.md +252 -0
- package/TROUBLESHOOTING.md +84 -0
- package/bin/cursor-openai-byok.js +9 -0
- package/config.example.json +48 -0
- package/lib/cli.js +1888 -0
- package/lib/daemon-entry.js +1128 -0
- package/lib/extension.js +302 -0
- package/package.json +77 -0
- package/scripts/install.ps1 +3 -0
- package/scripts/install.sh +4 -0
- package/scripts/uninstall.ps1 +3 -0
- package/scripts/uninstall.sh +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# cursor-openai-byok
|
|
2
|
+
|
|
3
|
+
`cursor-openai-byok` 是 Cursor 的本地 BYOK 桥接器。它把 Cursor 里选中的自定义模型转发到任意 OpenAI-compatible provider。
|
|
4
|
+
|
|
5
|
+
## 支持范围
|
|
6
|
+
|
|
7
|
+
- macOS 和 Windows。
|
|
8
|
+
- Cursor 3.8.x。其它版本会由 `doctor` 或 `install` 拒绝,除非显式 `--force`。
|
|
9
|
+
- OpenAI Responses API 风格 provider,包括文本和图片输入。
|
|
10
|
+
- OpenAI Chat Completions 风格 provider,包括文本和图片输入。
|
|
11
|
+
- 多 provider、多 model 映射。
|
|
12
|
+
|
|
13
|
+
首版目标是 Cursor chat/agent 所需能力,不包含 audio、embeddings 等非 chat 端点。
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
推荐使用 npm 或 pnpm 一次性运行 CLI。安装命令不会自动修改 Cursor;只有显式执行 `install` 时才会 patch Cursor、安装扩展并同步模型。
|
|
18
|
+
|
|
19
|
+
npm:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx --yes cursor-openai-byok@latest configure
|
|
23
|
+
# 编辑 ~/.cursor-openai-byok/config.json,填入 provider 和 API key
|
|
24
|
+
npx --yes cursor-openai-byok@latest install
|
|
25
|
+
npx --yes cursor-openai-byok@latest doctor
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
pnpm:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm dlx cursor-openai-byok@latest configure
|
|
32
|
+
# 编辑 ~/.cursor-openai-byok/config.json,填入 provider 和 API key
|
|
33
|
+
pnpm dlx cursor-openai-byok@latest install
|
|
34
|
+
pnpm dlx cursor-openai-byok@latest doctor
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`npx` 和 `pnpm dlx` 每次都会临时下载并运行当前发布包,不要求全局安装。
|
|
38
|
+
|
|
39
|
+
安装会做三件事:
|
|
40
|
+
|
|
41
|
+
- 校验 `~/.cursor-openai-byok/config.json` 或 `%USERPROFILE%\.cursor-openai-byok\config.json`
|
|
42
|
+
- Patch Cursor 3.8.x 的 workbench bundle
|
|
43
|
+
- 安装 Cursor 扩展,由扩展在 Cursor 启动时启动 daemon,并在 Cursor 退出时停止 daemon
|
|
44
|
+
|
|
45
|
+
安装后重启 Cursor。
|
|
46
|
+
|
|
47
|
+
## 离线 zip 安装
|
|
48
|
+
|
|
49
|
+
macOS:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
unzip cursor-openai-byok-macos-arm64.zip
|
|
53
|
+
cd cursor-openai-byok
|
|
54
|
+
node bin/cursor-openai-byok.js configure
|
|
55
|
+
# 编辑 ~/.cursor-openai-byok/config.json,填入 provider 和 API key
|
|
56
|
+
./scripts/install.sh
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Windows PowerShell:
|
|
60
|
+
|
|
61
|
+
```powershell
|
|
62
|
+
Expand-Archive .\cursor-openai-byok-windows-x64.zip
|
|
63
|
+
cd .\cursor-openai-byok
|
|
64
|
+
node .\bin\cursor-openai-byok.js configure
|
|
65
|
+
# 编辑 $env:USERPROFILE\.cursor-openai-byok\config.json,填入 provider 和 API key
|
|
66
|
+
.\scripts\install.ps1
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 配置模型
|
|
70
|
+
|
|
71
|
+
编辑配置文件:
|
|
72
|
+
|
|
73
|
+
macOS:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
open ~/.cursor-openai-byok/config.json
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Windows:
|
|
80
|
+
|
|
81
|
+
```powershell
|
|
82
|
+
notepad "$env:USERPROFILE\.cursor-openai-byok\config.json"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
示例:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"$schemaVersion": 1,
|
|
90
|
+
"server": { "host": "127.0.0.1", "port": 39832 },
|
|
91
|
+
"defaults": { "model": "gpt-5.5" },
|
|
92
|
+
"providers": [
|
|
93
|
+
{
|
|
94
|
+
"id": "fastskills",
|
|
95
|
+
"name": "FastSkills",
|
|
96
|
+
"type": "openai-responses",
|
|
97
|
+
"baseUrl": "https://api-hw.fastskills.ai/v1",
|
|
98
|
+
"apiKey": "sk-xxx",
|
|
99
|
+
"models": [
|
|
100
|
+
{
|
|
101
|
+
"displayName": "gpt-5.5",
|
|
102
|
+
"apiModel": "gpt-5.5",
|
|
103
|
+
"supportsTools": true,
|
|
104
|
+
"supportsStreaming": true,
|
|
105
|
+
"supportsImages": true,
|
|
106
|
+
"contextTokenLimit": 258000,
|
|
107
|
+
"maxOutputTokens": 32000
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"displayName": "gpt-5.4",
|
|
111
|
+
"apiModel": "gpt-5.4",
|
|
112
|
+
"supportsTools": true,
|
|
113
|
+
"supportsStreaming": true,
|
|
114
|
+
"contextTokenLimit": 258000,
|
|
115
|
+
"maxOutputTokens": 32000
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`displayName` 是 Cursor 下拉框里看到和选择的名字。
|
|
124
|
+
|
|
125
|
+
`apiModel` 是实际发给 provider 的 `model` 字段。
|
|
126
|
+
|
|
127
|
+
`supportsImages` 控制 Cursor 是否把图片输入交给这个模型,并让 daemon 转成 OpenAI 的 `input_image` / `image_url` 格式。
|
|
128
|
+
|
|
129
|
+
你可以添加任意 OpenAI-compatible provider,只要它兼容 `/v1/responses` 或 `/v1/chat/completions`。
|
|
130
|
+
|
|
131
|
+
如果你之前已经用过 ccursor,并且 `~/.ccursor/providers.json` 里已有 provider,可以迁移:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
node bin/cursor-openai-byok.js configure --import-ccursor
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
迁移命令只写入本机配置文件,不会把 API key 打包进 zip。
|
|
138
|
+
|
|
139
|
+
## 常用命令
|
|
140
|
+
|
|
141
|
+
使用 npm/pnpm 时:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
npx --yes cursor-openai-byok@latest doctor
|
|
145
|
+
npx --yes cursor-openai-byok@latest models
|
|
146
|
+
npx --yes cursor-openai-byok@latest logs
|
|
147
|
+
npx --yes cursor-openai-byok@latest restart
|
|
148
|
+
npx --yes cursor-openai-byok@latest uninstall
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
离线 zip 解压目录内也可以直接运行:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
node bin/cursor-openai-byok.js doctor
|
|
155
|
+
node bin/cursor-openai-byok.js models
|
|
156
|
+
node bin/cursor-openai-byok.js logs
|
|
157
|
+
node bin/cursor-openai-byok.js restart
|
|
158
|
+
node bin/cursor-openai-byok.js uninstall
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`start|stop|restart` 只是手动调试命令。正常使用时不需要单独启动 server;Cursor 启动后扩展会自动拉起,Cursor 退出时会自动关闭。
|
|
162
|
+
|
|
163
|
+
## 配置页面
|
|
164
|
+
|
|
165
|
+
在 Cursor 命令面板运行:
|
|
166
|
+
|
|
167
|
+
```text
|
|
168
|
+
Cursor OpenAI BYOK: Open Settings
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
配置页面支持:
|
|
172
|
+
|
|
173
|
+
- 查看 server running/stopped 状态
|
|
174
|
+
- Start / Stop / Restart server
|
|
175
|
+
- 打开配置文件
|
|
176
|
+
- 打开日志文件
|
|
177
|
+
- 查看当前配置的模型映射
|
|
178
|
+
|
|
179
|
+
## 验证
|
|
180
|
+
|
|
181
|
+
运行:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
node bin/cursor-openai-byok.js doctor
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
然后重启 Cursor,在模型下拉框里选择配置的 `displayName`,发送一句 `只回复 pong`。
|
|
188
|
+
|
|
189
|
+
成功时日志里应该能看到:
|
|
190
|
+
|
|
191
|
+
- daemon `/health` 正常
|
|
192
|
+
- Cursor patch 已安装
|
|
193
|
+
- Cursor 扩展已安装
|
|
194
|
+
- 选择模型命中本地 BYOK
|
|
195
|
+
- Cursor 收到 first token 并完成 stream
|
|
196
|
+
|
|
197
|
+
## 卸载
|
|
198
|
+
|
|
199
|
+
macOS:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
./scripts/uninstall.sh
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Windows:
|
|
206
|
+
|
|
207
|
+
```powershell
|
|
208
|
+
.\scripts\uninstall.ps1
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
卸载会停止 daemon、删除 Cursor 扩展,并从安装时的备份恢复 Cursor bundle。
|
|
212
|
+
|
|
213
|
+
## npm 发布
|
|
214
|
+
|
|
215
|
+
首次发布前需要 npmjs 账号。可以使用 `zhangever@gmail.com` 注册账号,完成邮箱验证并启用 2FA。浏览器已登录 Gmail 只用于接收验证邮件,不代表已经登录 npm。
|
|
216
|
+
|
|
217
|
+
发布前确认本机 npm registry 指向官方源:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
npm config set registry https://registry.npmjs.org/
|
|
221
|
+
npm login --registry=https://registry.npmjs.org/
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
发布前验证:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
npm test
|
|
228
|
+
node bin/cursor-openai-byok.js doctor
|
|
229
|
+
npm run package
|
|
230
|
+
npm pack --dry-run --json
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
确认 tarball 只包含 `lib/` 构建产物、CLI 入口、安装脚本和文档,不包含 `src/`、`extension/`、`dist/*.zip`、`test/`、本地配置或 API key 后发布:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
npm publish --registry=https://registry.npmjs.org/ --access public
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
本地 tarball 可以这样验证 CLI 入口:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
npm pack
|
|
243
|
+
npx --yes --package ./cursor-openai-byok-<version>.tgz cursor-openai-byok help
|
|
244
|
+
pnpm dlx ./cursor-openai-byok-<version>.tgz help
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
发布后验证:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
npx --yes cursor-openai-byok@latest help
|
|
251
|
+
pnpm dlx cursor-openai-byok@latest help
|
|
252
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# TROUBLESHOOTING
|
|
2
|
+
|
|
3
|
+
## Cursor 提示 installation appears to be corrupt
|
|
4
|
+
|
|
5
|
+
这是因为插件需要 patch Cursor app bundle。只要 `doctor` 正常且模型可用,可以忽略。
|
|
6
|
+
|
|
7
|
+
如果要恢复:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
node bin/cursor-openai-byok.js uninstall
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 模型下拉框里看不到模型
|
|
14
|
+
|
|
15
|
+
检查:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
node bin/cursor-openai-byok.js doctor
|
|
19
|
+
node bin/cursor-openai-byok.js models
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
确认:
|
|
23
|
+
|
|
24
|
+
- `config.json` 里有 `providers[].models[].displayName`
|
|
25
|
+
- API key 不是 `sk-REPLACE_ME`
|
|
26
|
+
- Cursor 版本是 3.8.x
|
|
27
|
+
- 安装后已经重启 Cursor
|
|
28
|
+
|
|
29
|
+
## 能看到模型,但发送消息没有响应
|
|
30
|
+
|
|
31
|
+
先在 Cursor 命令面板打开配置页面:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
Cursor OpenAI BYOK: Open Settings
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
确认 server 是 `running`。也可以用 CLI 检查:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
node bin/cursor-openai-byok.js restart
|
|
41
|
+
node bin/cursor-openai-byok.js logs
|
|
42
|
+
curl http://127.0.0.1:39832/health
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
正常使用时 server 不需要系统服务;它只应该在 Cursor 启动后由扩展拉起,并在 Cursor 退出时关闭。
|
|
46
|
+
|
|
47
|
+
如果 provider 报错,日志会脱敏显示 HTTP 状态和错误片段。
|
|
48
|
+
|
|
49
|
+
## provider 模型名不一致
|
|
50
|
+
|
|
51
|
+
使用两个字段解决:
|
|
52
|
+
|
|
53
|
+
- `displayName`: Cursor 展示名,比如 `my-gpt`
|
|
54
|
+
- `apiModel`: provider 实际模型名,比如 `gpt-5.5`
|
|
55
|
+
|
|
56
|
+
Cursor 选择 `displayName`,daemon 发请求时改成 `apiModel`。
|
|
57
|
+
|
|
58
|
+
## 工具调用没有按预期执行
|
|
59
|
+
|
|
60
|
+
首版会解析 OpenAI Responses / Chat Completions 的 tool call 流,并把 tool call 事件传回 Cursor patch。Cursor 端工具执行依赖 3.8.x 的内部 interaction bridge,如果 Cursor 版本或 bundle 结构变化,`doctor` 会要求更新 patch template。
|
|
61
|
+
|
|
62
|
+
排查时先用普通文本聊天确认链路,再用只读工具调用 smoke test。
|
|
63
|
+
|
|
64
|
+
## Windows 脚本执行策略阻止 install.ps1
|
|
65
|
+
|
|
66
|
+
在 PowerShell 中使用:
|
|
67
|
+
|
|
68
|
+
```powershell
|
|
69
|
+
powershell -ExecutionPolicy Bypass -File .\scripts\install.ps1
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 端口冲突
|
|
73
|
+
|
|
74
|
+
默认端口是 `39832`。如需修改,编辑 `config.json`:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{ "server": { "host": "127.0.0.1", "port": 39833 } }
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
修改后运行:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
node bin/cursor-openai-byok.js restart
|
|
84
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schemaVersion": 1,
|
|
3
|
+
"server": {
|
|
4
|
+
"host": "127.0.0.1",
|
|
5
|
+
"port": 39832
|
|
6
|
+
},
|
|
7
|
+
"defaults": {
|
|
8
|
+
"model": "fastskills-gpt-5.5"
|
|
9
|
+
},
|
|
10
|
+
"providers": [
|
|
11
|
+
{
|
|
12
|
+
"id": "fastskills",
|
|
13
|
+
"name": "FastSkills",
|
|
14
|
+
"type": "openai-responses",
|
|
15
|
+
"baseUrl": "https://api-hw.fastskills.ai/v1",
|
|
16
|
+
"apiKey": "sk-REPLACE_ME",
|
|
17
|
+
"models": [
|
|
18
|
+
{
|
|
19
|
+
"displayName": "fastskills-gpt-5.5",
|
|
20
|
+
"apiModel": "gpt-5.5",
|
|
21
|
+
"supportsTools": true,
|
|
22
|
+
"supportsStreaming": true,
|
|
23
|
+
"supportsImages": true,
|
|
24
|
+
"contextTokenLimit": 258000,
|
|
25
|
+
"maxOutputTokens": 32000
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "openai-compatible-chat",
|
|
31
|
+
"name": "OpenAI Compatible Chat Example",
|
|
32
|
+
"type": "openai-chat-completions",
|
|
33
|
+
"baseUrl": "https://example.com/v1",
|
|
34
|
+
"apiKey": "sk-REPLACE_ME",
|
|
35
|
+
"models": [
|
|
36
|
+
{
|
|
37
|
+
"displayName": "my-chat-model",
|
|
38
|
+
"apiModel": "provider-model-id",
|
|
39
|
+
"supportsTools": true,
|
|
40
|
+
"supportsStreaming": true,
|
|
41
|
+
"supportsImages": true,
|
|
42
|
+
"contextTokenLimit": 128000,
|
|
43
|
+
"maxOutputTokens": 8192
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|