mimo2codex 0.1.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/AGENTS.md +124 -0
- package/LICENSE +21 -0
- package/README.md +536 -0
- package/README.zh.md +750 -0
- package/dist/cli.js +202 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js +86 -0
- package/dist/config.js.map +1 -0
- package/dist/server.js +161 -0
- package/dist/server.js.map +1 -0
- package/dist/translate/reqToChat.js +381 -0
- package/dist/translate/reqToChat.js.map +1 -0
- package/dist/translate/respToResponses.js +94 -0
- package/dist/translate/respToResponses.js.map +1 -0
- package/dist/translate/streamToSse.js +352 -0
- package/dist/translate/streamToSse.js.map +1 -0
- package/dist/translate/types.js +4 -0
- package/dist/translate/types.js.map +1 -0
- package/dist/upstream/chatStream.js +56 -0
- package/dist/upstream/chatStream.js.map +1 -0
- package/dist/upstream/mimoClient.js +99 -0
- package/dist/upstream/mimoClient.js.map +1 -0
- package/dist/util/ids.js +19 -0
- package/dist/util/ids.js.map +1 -0
- package/dist/util/log.js +32 -0
- package/dist/util/log.js.map +1 -0
- package/dist/util/sse.js +61 -0
- package/dist/util/sse.js.map +1 -0
- package/mimoskill/SKILL.md +145 -0
- package/mimoskill/assets/pet_prompt_template.md +94 -0
- package/mimoskill/references/models.md +111 -0
- package/mimoskill/references/pet_workflow.md +197 -0
- package/mimoskill/scripts/generate_pet.py +365 -0
- package/mimoskill/scripts/install_pet.sh +220 -0
- package/mimoskill/scripts/mimo_chat.py +199 -0
- package/package.json +69 -0
package/README.zh.md
ADDED
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
# mimo2codex · 中文文档
|
|
2
|
+
|
|
3
|
+
> [English](./README.md) · 中文
|
|
4
|
+
|
|
5
|
+
让**最新版** OpenAI Codex CLI / Codex 桌面端无缝接入**小米 MiMo V2.5 Pro** 的本地代理。它把 Codex 的 Responses API 实时翻译成 MiMo 的 Chat Completions API,纯本地无状态转换。
|
|
6
|
+
|
|
7
|
+
可独立使用,也可作为自定义供应商配置进 [cc-switch](https://github.com/farion1231/cc-switch),与 OpenAI 官方、Azure、AiHubMix 等其他 Codex 供应商**一键切换**。
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 这个工具解决什么问题
|
|
12
|
+
|
|
13
|
+
小米米莫官方的 [Codex 集成文档](https://platform.xiaomimimo.com/docs/zh-CN/integration/codex) 明确写着:
|
|
14
|
+
|
|
15
|
+
> "MiMo Models are not yet compatible with the Responses API and are only supported by older versions of Codex that use the ChatCompletions API."
|
|
16
|
+
>
|
|
17
|
+
> "Newer versions of Codex no longer support `wire_api = "chat"`. If you encounter the error `wire_api = chat is no longer supported`, please downgrade the Codex version."
|
|
18
|
+
|
|
19
|
+
也就是说:
|
|
20
|
+
|
|
21
|
+
- MiMo 服务端**只暴露 Chat Completions 协议**
|
|
22
|
+
- OpenAI 已弃用 Codex 的 `wire_api = "chat"`(2026 年 2 月起为硬错误)
|
|
23
|
+
- 官方建议的解决方案是**降级 Codex 到 0.80.0**——但这样就丢掉了 pet 宠物、桌面端新功能、新工具支持等改进
|
|
24
|
+
- cc-switch 的 Codex 预设里也没有 MiMo(只有 OpenAI 官方、Azure、AiHubMix、DMXAPI、PackyCode、OpenRouter 等)——同样因为 MiMo 不支持 Responses API
|
|
25
|
+
|
|
26
|
+
**mimo2codex 把这两边都救活了**:本地起个 HTTP 服务,对外伪装成 OpenAI Responses API 后端,对内翻译成 MiMo Chat Completions。Codex 用最新版、MiMo 服务端不变、cc-switch 把它当一个普通自定义供应商管理。
|
|
27
|
+
|
|
28
|
+
工作原理类似 [openrouter](https://openrouter.ai)、[claude-code-router](https://github.com/musistudio/claude-code-router)、[y-router](https://github.com/luohy15/y-router)——纯协议网关,不缓存、不调度、不存储。
|
|
29
|
+
|
|
30
|
+
## 支持的能力
|
|
31
|
+
|
|
32
|
+
- ✅ Codex CLI 0.x 最新版(`wire_api = "responses"`)
|
|
33
|
+
- ✅ Codex 桌面端(macOS / Windows)
|
|
34
|
+
- ✅ **Pet 宠物**(状态由 SSE 事件生命周期驱动,无需特殊处理)
|
|
35
|
+
- ✅ **工具调用**——function tools,含并行调用
|
|
36
|
+
- ✅ 多轮对话 + 混合工具调用 + reasoning
|
|
37
|
+
- ✅ 流式 SSE,完整 Responses 事件序列(`response.created` / `output_item.added` / `output_text.delta` / `function_call_arguments.delta` / `reasoning_summary_text.delta` / `completed` 等)
|
|
38
|
+
- ✅ **思维链透传**——MiMo 的 `reasoning_content` 在 Codex 终端显示为思考摘要,多轮工具调用时按 MiMo 官方推荐回填给上游
|
|
39
|
+
- ✅ **1M 长上下文**——把 model 写成 `mimo-v2.5-pro[1m]` 即可
|
|
40
|
+
- ✅ **可配进 cc-switch**——与 OpenAI 官方等其他供应商一键切换
|
|
41
|
+
|
|
42
|
+
## 工作原理
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
┌──────────────┐ POST /v1/responses ┌──────────────┐ POST /v1/chat/completions ┌──────────────┐
|
|
46
|
+
│ Codex CLI / │ (wire_api="responses") │ mimo2codex │ (chat completions, SSE) │ Xiaomimimo │
|
|
47
|
+
│ Codex 桌面端 │ ──────────────────────► │ 127.0.0.1 │ ──────────────────────────► │ MiMo V2.5 │
|
|
48
|
+
└──────────────┘ ◄────────────────────── │ :8788 │ ◄────────────────────────── └──────────────┘
|
|
49
|
+
Responses SSE 事件流 └──────────────┘ Chat Completions SSE
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
每个请求的处理:
|
|
53
|
+
|
|
54
|
+
1. Codex POST 一个 Responses 请求体(`input` 是 message / function_call / function_call_output / reasoning items 数组)
|
|
55
|
+
2. mimo2codex 把 `input` 翻译成 Chat `messages`,并把连续的 `reasoning` + `function_call` 折叠成一条带 `reasoning_content` + `tool_calls` 的 assistant 消息(这是 MiMo 推荐的多轮高质量做法)
|
|
56
|
+
3. mimo2codex 用你的 `MIMO_API_KEY` 调 MiMo 的 `/v1/chat/completions`
|
|
57
|
+
4. 流式读 Chat SSE 块,状态机改写成 Responses SSE 事件流回 Codex
|
|
58
|
+
|
|
59
|
+
整个代理**完全无状态**——不存 `previous_response_id`、不缓存、不校验入站 key。想跑几个实例都行。
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 安装
|
|
64
|
+
|
|
65
|
+
三选一,按你的偏好:
|
|
66
|
+
|
|
67
|
+
### 🟢 方式 1:npm 全局安装(最简单,推荐普通用户)
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm install -g mimo2codex
|
|
71
|
+
mimo2codex --version
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
需要 Node.js ≥ 18。装完之后 `mimo2codex` 就在 PATH 里了,所有命令直接用:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
export MIMO_API_KEY=sk-xxxxxxxxxxxxxxxx
|
|
78
|
+
mimo2codex # 启动代理
|
|
79
|
+
mimo2codex print-config # 打印 ~/.codex/config.toml 片段
|
|
80
|
+
mimo2codex print-cc-switch # 打印 cc-switch 配置片段
|
|
81
|
+
mimo2codex --port 9000 --verbose # 改端口 + 详细日志
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**升级到新版本**:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm update -g mimo2codex
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**卸载**:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm rm -g mimo2codex
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
下面方式 2 / 3 是给开发者或想看源码的人准备的——如果你只是用,方式 1 已经够了,直接跳到 [**准备:拿一个 MiMo API Key**](#准备拿一个-mimo-api-key)。
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### 🛠 方式 2:本地源码 + 一键脚本(贡献者首选)
|
|
101
|
+
|
|
102
|
+
仓库自带 [`scripts/install.sh`](./scripts/install.sh)(Linux / macOS / Git Bash / WSL)和 [`scripts/install.ps1`](./scripts/install.ps1)(Windows PowerShell)。脚本会自动:
|
|
103
|
+
|
|
104
|
+
1. 检测 git / Node.js ≥ 18 / npm,缺哪个就提示怎么装
|
|
105
|
+
2. 拉仓库(首次执行),或在已存在的克隆里 `git pull --ff-only`
|
|
106
|
+
3. `npm install` → `npm run build` → `npm test`
|
|
107
|
+
4. 打印「下一步该做什么」的清单
|
|
108
|
+
|
|
109
|
+
**Linux / macOS / Git Bash / WSL**:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# 远程一键(替换为实际 raw URL)
|
|
113
|
+
curl -fsSL https://raw.githubusercontent.com/7as0nch/mimo2codex/main/scripts/install.sh | bash
|
|
114
|
+
|
|
115
|
+
# 或本地:先 clone 再跑
|
|
116
|
+
git clone https://github.com/your-org/mimo2codex.git
|
|
117
|
+
cd mimo2codex
|
|
118
|
+
./scripts/install.sh
|
|
119
|
+
|
|
120
|
+
# 装完直接启动代理(需提前 export MIMO_API_KEY)
|
|
121
|
+
MIMO_API_KEY=sk-xxx ./scripts/install.sh --start
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Windows PowerShell**:
|
|
125
|
+
|
|
126
|
+
```powershell
|
|
127
|
+
# 远程一键
|
|
128
|
+
irm https://raw.githubusercontent.com/7as0nch/mimo2codex/main/scripts/install.ps1 | iex
|
|
129
|
+
|
|
130
|
+
# 或本地:先 clone 再跑
|
|
131
|
+
git clone https://github.com/your-org/mimo2codex.git
|
|
132
|
+
cd mimo2codex
|
|
133
|
+
.\scripts\install.ps1
|
|
134
|
+
|
|
135
|
+
# 装完直接启动代理
|
|
136
|
+
$env:MIMO_API_KEY = "sk-xxx"
|
|
137
|
+
.\scripts\install.ps1 -Start
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
> 如果 PowerShell 报"running scripts is disabled",先执行:
|
|
141
|
+
> `Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned`
|
|
142
|
+
|
|
143
|
+
脚本是**幂等**的——重复执行只会拉新代码、重装依赖、重新构建,不会重置你的配置。要升级版本随时再跑一遍即可。
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### 🔧 方式 3:手动一步步装(完全控制每一步)
|
|
148
|
+
|
|
149
|
+
只在前两种方式都不合你心意时再看;普通用户跳到 [**准备:拿一个 MiMo API Key**](#准备拿一个-mimo-api-key) 即可。
|
|
150
|
+
|
|
151
|
+
#### 0. 先决条件
|
|
152
|
+
|
|
153
|
+
| 软件 | 版本要求 | 检查命令 |
|
|
154
|
+
|---|---|---|
|
|
155
|
+
| Node.js | **≥ 18.0** | `node -v` |
|
|
156
|
+
| npm | 与 Node 同包 | `npm -v` |
|
|
157
|
+
| git | 任意版本 | `git --version` |
|
|
158
|
+
|
|
159
|
+
如果 `node -v` 报错或版本不到 18,去 [nodejs.org](https://nodejs.org) 装一个 LTS。Windows 用户也可以用 [nvs](https://github.com/jasongin/nvs) / [nvm-windows](https://github.com/coreybutler/nvm-windows) 管理多版本。
|
|
160
|
+
|
|
161
|
+
#### 1. 克隆仓库 & 装依赖
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
git clone https://github.com/your-org/mimo2codex.git
|
|
165
|
+
cd mimo2codex
|
|
166
|
+
npm install
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`npm install` 会装大约 87 个包(typescript、vitest、tsx、nanoid、eventsource-parser),耗时 30 秒到 1 分钟。
|
|
170
|
+
|
|
171
|
+
#### 2. 选一种启动方式
|
|
172
|
+
|
|
173
|
+
下面三种任选其一。**A** 是最快上手的;**B** 启动最快、运行时占用最低;**C** 让 `mimo2codex` 像全局命令一样使用。
|
|
174
|
+
|
|
175
|
+
#### 方式 A:开发模式(推荐首次试用)
|
|
176
|
+
|
|
177
|
+
直接用 `tsx` 跑 TypeScript 源码,**不需要构建**:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# Linux / macOS / Git Bash
|
|
181
|
+
export MIMO_API_KEY=sk-xxxxxxxxxxxxxxxx
|
|
182
|
+
npm run dev
|
|
183
|
+
|
|
184
|
+
# Windows PowerShell
|
|
185
|
+
$env:MIMO_API_KEY="sk-xxxxxxxxxxxxxxxx"
|
|
186
|
+
npm run dev
|
|
187
|
+
|
|
188
|
+
# Windows CMD
|
|
189
|
+
set MIMO_API_KEY=sk-xxxxxxxxxxxxxxxx
|
|
190
|
+
npm run dev
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
要带额外参数(例如改端口):
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
npm run dev -- --port 9000
|
|
197
|
+
npm run dev -- --base-url https://token-plan-cn.xiaomimimo.com/v1
|
|
198
|
+
npm run dev -- print-cc-switch
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
> ⚠️ 注意 `--` 分隔符:`--` 前面是给 npm 的参数,后面才是给 mimo2codex 的。
|
|
202
|
+
|
|
203
|
+
#### 方式 B:构建后跑(推荐长期使用)
|
|
204
|
+
|
|
205
|
+
把 TypeScript 编译成 JavaScript,再用纯 Node 跑——启动快(< 100ms)、内存占用低、没有 tsx 的额外开销:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# 一次性构建
|
|
209
|
+
npm run build
|
|
210
|
+
|
|
211
|
+
# 启动(任选其一)
|
|
212
|
+
npm start
|
|
213
|
+
node dist/cli.js
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
带参数:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npm start -- --port 9000
|
|
220
|
+
node dist/cli.js --port 9000
|
|
221
|
+
node dist/cli.js print-cc-switch
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
构建产物在 `dist/`(已在 `.gitignore` 里,不会污染仓库)。改了源码记得重新 `npm run build`。
|
|
225
|
+
|
|
226
|
+
#### 方式 C:把 `mimo2codex` 注册为全局命令(不需要 publish)
|
|
227
|
+
|
|
228
|
+
在仓库根目录跑一次:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
npm run build # 先确保 dist/ 已生成
|
|
232
|
+
npm link # 把当前目录注册为全局 mimo2codex
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
之后在**任何目录**都能直接用:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
mimo2codex --version
|
|
239
|
+
mimo2codex print-cc-switch
|
|
240
|
+
MIMO_API_KEY=sk-xxx mimo2codex
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
要解除链接:在仓库根目录跑 `npm unlink`,或全局 `npm rm -g mimo2codex`。
|
|
244
|
+
|
|
245
|
+
> 💡 后文所有的 `mimo2codex ...` 命令示例,对应到方式 A 是 `npm run dev -- ...`、方式 B 是 `node dist/cli.js ...`、方式 C 是 `mimo2codex ...` 直接用。
|
|
246
|
+
|
|
247
|
+
#### 3. 跑测试(可选)
|
|
248
|
+
|
|
249
|
+
确认你这台机器上一切正常:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
npm test
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
预期 25 个用例全过:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
✓ test/respToResponses.test.ts (6 tests)
|
|
259
|
+
✓ test/reqToChat.test.ts (11 tests)
|
|
260
|
+
✓ test/streamToSse.test.ts (8 tests)
|
|
261
|
+
|
|
262
|
+
Test Files 3 passed (3)
|
|
263
|
+
Tests 25 passed (25)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
#### 4. 让代理常驻后台
|
|
267
|
+
|
|
268
|
+
mimo2codex 是个长时运行的服务,开发时直接前台跑就行;如果想常驻:
|
|
269
|
+
|
|
270
|
+
#### macOS / Linux:systemd 用户单元(推荐)
|
|
271
|
+
|
|
272
|
+
新建 `~/.config/systemd/user/mimo2codex.service`:
|
|
273
|
+
|
|
274
|
+
```ini
|
|
275
|
+
[Unit]
|
|
276
|
+
Description=mimo2codex — Codex Responses → Xiaomi MiMo proxy
|
|
277
|
+
After=network.target
|
|
278
|
+
|
|
279
|
+
[Service]
|
|
280
|
+
Type=simple
|
|
281
|
+
WorkingDirectory=/绝对路径/到/mimo2codex
|
|
282
|
+
Environment="MIMO_API_KEY=sk-xxxxxxxxxxxxxxxx"
|
|
283
|
+
ExecStart=/usr/bin/node dist/cli.js
|
|
284
|
+
Restart=on-failure
|
|
285
|
+
|
|
286
|
+
[Install]
|
|
287
|
+
WantedBy=default.target
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
systemctl --user daemon-reload
|
|
292
|
+
systemctl --user enable --now mimo2codex
|
|
293
|
+
systemctl --user status mimo2codex # 看状态
|
|
294
|
+
journalctl --user -u mimo2codex -f # 看日志
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### 跨平台:[pm2](https://pm2.keymetrics.io)
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
npm install -g pm2
|
|
301
|
+
cd mimo2codex
|
|
302
|
+
npm run build
|
|
303
|
+
MIMO_API_KEY=sk-xxx pm2 start dist/cli.js --name mimo2codex
|
|
304
|
+
pm2 save
|
|
305
|
+
pm2 startup # 跟着提示开机自启
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
#### Windows:[node-windows](https://github.com/coreybutler/node-windows) 或任务计划程序
|
|
309
|
+
|
|
310
|
+
最省事的方法是**任务计划程序**:
|
|
311
|
+
|
|
312
|
+
1. 控制面板 → 任务计划程序 → 创建基本任务
|
|
313
|
+
2. 触发器:登录时
|
|
314
|
+
3. 操作:启动程序
|
|
315
|
+
- 程序:`C:\Program Files\nodejs\node.exe`
|
|
316
|
+
- 参数:`D:\workspace\goproject\my\mimo2codex\dist\cli.js`
|
|
317
|
+
- 起始位置:`D:\workspace\goproject\my\mimo2codex`
|
|
318
|
+
4. 完成后右键任务 → 属性 → 设置「使用最高权限运行」可选;在「条件」/「设置」里关掉空闲限制
|
|
319
|
+
5. 在「环境变量」里把 `MIMO_API_KEY` 设上(或在系统属性 → 环境变量里全局设)
|
|
320
|
+
|
|
321
|
+
#### 5. 升级到新版本
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
cd mimo2codex
|
|
325
|
+
git pull
|
|
326
|
+
npm install # 拉了新依赖才需要
|
|
327
|
+
npm run build # 方式 B/C 必跑;方式 A 不用
|
|
328
|
+
# 重启你的常驻进程(systemctl restart / pm2 restart 等)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## 准备:拿一个 MiMo API Key
|
|
334
|
+
|
|
335
|
+
去 [platform.xiaomimimo.com](https://platform.xiaomimimo.com) 注册(用小米账号),在「控制台 → API Keys」里创建一个 Key。
|
|
336
|
+
|
|
337
|
+
- **按量付费**:`sk-xxx` 开头,BASE_URL 用 `https://api.xiaomimimo.com/v1`
|
|
338
|
+
- **Token 套餐**:`tp-xxx` 开头,BASE_URL 用订阅页面给出的专属 URL(一般是 `https://token-plan-cn.xiaomimimo.com/v1`)
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## 使用方式
|
|
343
|
+
|
|
344
|
+
下面三种用法任选其一。**A** 是最简单的;**B** 适合已经在用 cc-switch 管理多家供应商的;**C** 是把 mimo2codex 与其他 Codex 供应商混合使用、随时切换。
|
|
345
|
+
|
|
346
|
+
### A. 独立使用(手动配 Codex)
|
|
347
|
+
|
|
348
|
+
#### 1. 启动代理
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
# 任选你前面装好的方式。这里用方式 A:
|
|
352
|
+
export MIMO_API_KEY=sk-xxxxxxxxxxxxxxxx
|
|
353
|
+
npm run dev
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
启动后会打印 Codex 需要的配置片段(默认 **auth.json 方式**——CLI 和桌面端都能用、不依赖任何环境变量):
|
|
357
|
+
|
|
358
|
+
```
|
|
359
|
+
mimo2codex v0.1.0 listening on http://127.0.0.1:8788
|
|
360
|
+
upstream: https://api.xiaomimimo.com/v1
|
|
361
|
+
api key: sk-x…xxxx
|
|
362
|
+
reasoning: passthrough
|
|
363
|
+
|
|
364
|
+
# Step 1 — 写 ~/.codex/auth.json (Windows: %USERPROFILE%\.codex\auth.json)
|
|
365
|
+
{
|
|
366
|
+
"OPENAI_API_KEY": "mimo2codex-local"
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
# Step 2 — 追加到 ~/.codex/config.toml
|
|
370
|
+
model = "mimo-v2.5-pro"
|
|
371
|
+
model_provider = "mimo"
|
|
372
|
+
|
|
373
|
+
[model_providers.mimo]
|
|
374
|
+
name = "MiMo (via mimo2codex)"
|
|
375
|
+
base_url = "http://127.0.0.1:8788/v1"
|
|
376
|
+
wire_api = "responses"
|
|
377
|
+
requires_openai_auth = true
|
|
378
|
+
request_max_retries = 1
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
#### 2. 写两个文件
|
|
382
|
+
|
|
383
|
+
按上面的 Step 1 / Step 2 把两段内容分别写到对应文件:
|
|
384
|
+
|
|
385
|
+
| 文件 | macOS / Linux | Windows |
|
|
386
|
+
|---|---|---|
|
|
387
|
+
| auth.json | `~/.codex/auth.json` | `%USERPROFILE%\.codex\auth.json` |
|
|
388
|
+
| config.toml | `~/.codex/config.toml` | `%USERPROFILE%\.codex\config.toml` |
|
|
389
|
+
|
|
390
|
+
> ⚠️ **注意**:如果你也在用 OpenAI 官方账号登录 Codex,写 auth.json 会把官方登录覆盖掉。这种情况建议改用 [cc-switch 方式](#b-通过-cc-switch-添加自定义供应商),它会自动备份和切换。
|
|
391
|
+
|
|
392
|
+
`mimo2codex-local` 这个值是占位字符串,随便填非空都行——代理本身不校验。
|
|
393
|
+
|
|
394
|
+
#### 3. 重启 Codex(桌面端必须做)
|
|
395
|
+
|
|
396
|
+
如果你在用 **Codex 桌面端**:从托盘 / 任务栏完全退出(不只是关窗口),再重新启动。否则 Codex 不会重读新写的 auth.json。
|
|
397
|
+
|
|
398
|
+
如果你在用 **Codex CLI**:直接启动就行:
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
codex
|
|
402
|
+
> 帮我写一个 Python 计算斐波那契的函数并保存到 fib.py
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Pet、工具调用、思考摘要、多轮对话都能正常工作。
|
|
406
|
+
|
|
407
|
+
> 💡 **想用环境变量方式的(不动 auth.json)**:跑 `npm run dev -- print-config --env-key` 拿环境变量版的 snippet。但**仅 CLI 适用**,桌面端从 Finder / 开始菜单启动**不会**读到 shell 的 env vars。
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
### B. 通过 cc-switch 添加自定义供应商
|
|
412
|
+
|
|
413
|
+
[cc-switch](https://github.com/farion1231/cc-switch) 是一个跨平台桌面 App,专门管理 Claude Code / Codex / OpenCode / OpenClaw / Gemini CLI 五个工具的多供应商切换。它的 Codex 预设里**没有 MiMo**(因为 MiMo 不支持 Responses API),所以我们用 mimo2codex 当桥,再以「自定义供应商」的方式加进 cc-switch。
|
|
414
|
+
|
|
415
|
+
> ⚠️ **流程要点**:mimo2codex 是个**本地 HTTP 代理服务**,必须**保持运行**才能接收 Codex 的请求。`print-cc-switch` 只是打印配置文本给你拷贝——它不启动任何东西。下面步骤 1(启代理)和步骤 2(拿配置文本)是两件独立的事。
|
|
416
|
+
|
|
417
|
+
#### 1. 启动 mimo2codex 代理(必须保持运行)
|
|
418
|
+
|
|
419
|
+
打开一个终端,进 mimo2codex 仓库目录:
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
cd /path/to/mimo2codex
|
|
423
|
+
export MIMO_API_KEY=sk-xxxxxxxxxxxxxxxx
|
|
424
|
+
npm run dev # 或 node dist/cli.js
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
看到 `listening on http://127.0.0.1:8788` 就成了。**这个终端不要关**——关了代理就停了,Codex 就连不上。
|
|
428
|
+
|
|
429
|
+
要让它常驻后台(开机自启 / pm2 / systemctl / Windows 任务计划程序),见上面的 [**4. 让代理常驻后台**](#4-让代理常驻后台) 章节。
|
|
430
|
+
|
|
431
|
+
#### 2. 拿到 cc-switch 配置片段
|
|
432
|
+
|
|
433
|
+
**新开一个终端**(不要关掉步骤 1 的那个),跑:
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
cd /path/to/mimo2codex
|
|
437
|
+
npm run dev -- print-cc-switch # 或 node dist/cli.js print-cc-switch
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
输出:
|
|
441
|
+
|
|
442
|
+
```
|
|
443
|
+
# cc-switch — Add Provider → Codex tab → Custom
|
|
444
|
+
|
|
445
|
+
# ───────── auth.json (粘到 auth.json 文本框) ─────────
|
|
446
|
+
{
|
|
447
|
+
"OPENAI_API_KEY": "mimo2codex-local"
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
# ───────── config.toml (粘到 config.toml 文本框) ─────────
|
|
451
|
+
model_provider = "mimo2codex"
|
|
452
|
+
model = "mimo-v2.5-pro"
|
|
453
|
+
|
|
454
|
+
[model_providers.mimo2codex]
|
|
455
|
+
name = "MiMo (via mimo2codex)"
|
|
456
|
+
base_url = "http://127.0.0.1:8788/v1"
|
|
457
|
+
wire_api = "responses"
|
|
458
|
+
requires_openai_auth = true
|
|
459
|
+
request_max_retries = 1
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
#### 3. 在 cc-switch 里添加
|
|
463
|
+
|
|
464
|
+
打开 cc-switch → 顶部切到 **Codex** Tab → 点右上角 **+** 号 → 选「**应用专属供应商**」→ 预设选「**自定义**」(或 Custom):
|
|
465
|
+
|
|
466
|
+
| 字段 | 填入 |
|
|
467
|
+
|---|---|
|
|
468
|
+
| **名称** | `MiMo (via mimo2codex)` |
|
|
469
|
+
| **auth.json** | 上面 print-cc-switch 输出的 auth.json 部分(整段 JSON) |
|
|
470
|
+
| **config.toml** | 上面 print-cc-switch 输出的 config.toml 部分(整段 TOML) |
|
|
471
|
+
| **备注**(可选) | `本地 mimo2codex 代理 → MiMo V2.5 Pro` |
|
|
472
|
+
|
|
473
|
+
点「添加」即可。
|
|
474
|
+
|
|
475
|
+
#### 4. 切换并启动 Codex
|
|
476
|
+
|
|
477
|
+
回到 cc-switch 主界面,在 Codex 列表里点击「**MiMo (via mimo2codex)**」,让它变成当前激活供应商(cc-switch 会自动写入 `~/.codex/auth.json` 和 `~/.codex/config.toml`)。
|
|
478
|
+
|
|
479
|
+
然后跑:
|
|
480
|
+
|
|
481
|
+
```bash
|
|
482
|
+
codex
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
完事。
|
|
486
|
+
|
|
487
|
+
> 💡 **小贴士**:cc-switch 的「获取模型」按钮(下载图标)会调用 `/v1/models` 端点。mimo2codex 已经实现了这个端点,所以你点一下就能下拉选 `mimo-v2.5-pro` / `mimo-v2.5-pro[1m]` / `mimo-v2-flash`。
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
### C. 在多个 Codex 供应商之间随时切换
|
|
492
|
+
|
|
493
|
+
cc-switch 的核心价值就是**一键切换**。结合 mimo2codex 后,你可以同时拥有:
|
|
494
|
+
|
|
495
|
+
| 名称 | 用途 |
|
|
496
|
+
|---|---|
|
|
497
|
+
| OpenAI 官方(cc-switch 内置预设) | GPT-5.2、思考能力最强但贵 |
|
|
498
|
+
| **MiMo (via mimo2codex)** | MiMo V2.5 Pro,1M 上下文,国内访问快 |
|
|
499
|
+
| Azure OpenAI(cc-switch 内置) | 企业合规走 Azure |
|
|
500
|
+
| OpenRouter(cc-switch 内置) | 多家模型聚合 |
|
|
501
|
+
| AiHubMix / DMXAPI(cc-switch 内置) | 国内中转 |
|
|
502
|
+
|
|
503
|
+
切换流程:
|
|
504
|
+
|
|
505
|
+
1. 打开 cc-switch
|
|
506
|
+
2. Codex Tab 里点想用的那个供应商
|
|
507
|
+
3. 顶部托盘也能直接切(cc-switch 支持)
|
|
508
|
+
4. 当前 Codex 会话不需要重启——下次启动 `codex` 就用新的了
|
|
509
|
+
|
|
510
|
+
> ⚠️ **注意**:mimo2codex 进程要保持运行状态。即使你在 cc-switch 里切到了别的供应商也没关系——mimo2codex 只在被路由到时才接收请求,不会消耗资源。可以挂在 `pm2`、Windows 服务或 systemd 用户单元里常驻。
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
## CLI 参数速查
|
|
515
|
+
|
|
516
|
+
| 参数 | 环境变量 | 默认 | 说明 |
|
|
517
|
+
|---|---|---|---|
|
|
518
|
+
| `--port`, `-p` | `MIMO2CODEX_PORT` | `8788` | 监听端口 |
|
|
519
|
+
| `--host` | `MIMO2CODEX_HOST` | `127.0.0.1` | 绑定地址(建议不要暴露到公网) |
|
|
520
|
+
| `--base-url` | `MIMO_BASE_URL` | `https://api.xiaomimimo.com/v1` | 切换到 Token 套餐:`https://token-plan-cn.xiaomimimo.com/v1` |
|
|
521
|
+
| `--api-key` | `MIMO_API_KEY` | _必填_ | 上游 MiMo 的 Key |
|
|
522
|
+
| `--no-reasoning` | `MIMO2CODEX_NO_REASONING=1` | 关 | 终端不显示思考摘要(多轮工具调用时仍会回填给 MiMo) |
|
|
523
|
+
| `--verbose`, `-v` | `MIMO2CODEX_VERBOSE=1` | 关 | 打印每次翻译的请求 |
|
|
524
|
+
|
|
525
|
+
子命令:
|
|
526
|
+
|
|
527
|
+
```bash
|
|
528
|
+
mimo2codex # 启动代理
|
|
529
|
+
mimo2codex print-config # 输出 ~/.codex/config.toml 片段
|
|
530
|
+
mimo2codex print-cc-switch # 输出 cc-switch 自定义供应商片段
|
|
531
|
+
mimo2codex --port 9000 print-config # 端口换 9000 后再输出
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
## 故障排查
|
|
537
|
+
|
|
538
|
+
**Q:Codex 启动报 `Missing environment variable: MIMO2CODEX_KEY`(或类似的 env var 缺失)**
|
|
539
|
+
|
|
540
|
+
A:你的 `~/.codex/config.toml` 里写了 `env_key = "MIMO2CODEX_KEY"`,Codex 启动时会去**自己进程的环境变量**里找这个名字,没找到就报错。
|
|
541
|
+
|
|
542
|
+
最容易踩的坑是 **Codex 桌面端**:你在终端 `export MIMO2CODEX_KEY=anything` 是对的,但桌面端是从 Finder / 开始菜单启动的,**不会继承 shell 的环境变量**。
|
|
543
|
+
|
|
544
|
+
**修复(推荐:改成 auth.json 方式,CLI 和桌面端通用)**:
|
|
545
|
+
|
|
546
|
+
1. 编辑 `~/.codex/config.toml`(Windows: `%USERPROFILE%\.codex\config.toml`),把 mimo2codex 段落里的:
|
|
547
|
+
```toml
|
|
548
|
+
env_key = "MIMO2CODEX_KEY"
|
|
549
|
+
```
|
|
550
|
+
**删掉**,改成:
|
|
551
|
+
```toml
|
|
552
|
+
requires_openai_auth = true
|
|
553
|
+
```
|
|
554
|
+
2. 写 `~/.codex/auth.json`(Windows: `%USERPROFILE%\.codex\auth.json`):
|
|
555
|
+
```json
|
|
556
|
+
{ "OPENAI_API_KEY": "mimo2codex-local" }
|
|
557
|
+
```
|
|
558
|
+
3. **完全退出并重启 Codex**(桌面端:托盘右键 → 退出,不只是关窗口)
|
|
559
|
+
|
|
560
|
+
或直接跑 `npm run dev -- print-config` 拿到现成的两段 snippet 复制即可。
|
|
561
|
+
|
|
562
|
+
**坚持用环境变量方式的(仅 CLI)**:
|
|
563
|
+
|
|
564
|
+
- macOS / Linux:在 `~/.bashrc` / `~/.zshrc` 末尾加 `export MIMO2CODEX_KEY=anything`,`source` 一下,再启 `codex`。
|
|
565
|
+
- Windows:用 `setx MIMO2CODEX_KEY anything`(不是 `set`),打开**新的** CMD 窗口再启动 Codex。`setx` 不会影响已经打开的窗口。
|
|
566
|
+
- **注意**:这两种都不解决桌面端问题。桌面端用 auth.json 方式或 cc-switch。
|
|
567
|
+
|
|
568
|
+
---
|
|
569
|
+
|
|
570
|
+
**Q:mimo2codex 跑起来了但 Codex 一直转圈 / 504 / connection refused?**
|
|
571
|
+
|
|
572
|
+
A:检查清单:
|
|
573
|
+
|
|
574
|
+
1. mimo2codex 进程是否还在前台跑?看终端最后一行是不是 `listening on http://127.0.0.1:8788`
|
|
575
|
+
2. `curl http://127.0.0.1:8788/healthz` 返回什么?应该是 `{"ok":true,...}`
|
|
576
|
+
3. config.toml 里的 `base_url` 有没有以 `/v1` 结尾?必须是 `http://127.0.0.1:8788/v1`,不是 `http://127.0.0.1:8788`
|
|
577
|
+
4. 端口冲突?默认 `8788`,被占了就 `npm run dev -- --port 9999`,**记得同步改 config.toml 里的 base_url**
|
|
578
|
+
|
|
579
|
+
---
|
|
580
|
+
|
|
581
|
+
**Q:报 `MiMo returned 401 ...` 或 `authentication_error`**
|
|
582
|
+
|
|
583
|
+
A:你的 `MIMO_API_KEY`(启动 mimo2codex 时设的那个)无效。重新去 [platform.xiaomimimo.com](https://platform.xiaomimimo.com) 控制台 → API Keys 创建一个,注意 `sk-` 和 `tp-` 前缀对应不同 BASE_URL:
|
|
584
|
+
|
|
585
|
+
- `sk-xxx` → `--base-url https://api.xiaomimimo.com/v1`(默认)
|
|
586
|
+
- `tp-xxx` → `--base-url https://token-plan-cn.xiaomimimo.com/v1`
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
**Q:报 `MiMo returned 404: ... No endpoints found that support image input`**
|
|
591
|
+
|
|
592
|
+
A:请求里带了图片,但你的模型不支持图像。按 [MiMo 官方文档](https://platform.xiaomimimo.com/docs/zh-CN/usage-guide/multimodal-understanding/image-understanding),**只有 `mimo-v2.5` 和 `mimo-v2-omni` 支持视觉**——`mimo-v2.5-pro` / `mimo-v2.5-pro[1m]` / `mimo-v2-flash` 都**不支持**。
|
|
593
|
+
|
|
594
|
+
mimo2codex 会按模型名自动判断:
|
|
595
|
+
|
|
596
|
+
| 模型 | 视觉 |
|
|
597
|
+
|---|---|
|
|
598
|
+
| `mimo-v2.5` / `mimo-v2.5[1m]` | ✅ |
|
|
599
|
+
| `mimo-v2-omni` / `mimo-v2-omni[1m]` | ✅ |
|
|
600
|
+
| `mimo-v2.5-pro` / `mimo-v2.5-pro[1m]` | ❌(自动丢图 + 加文本说明) |
|
|
601
|
+
| `mimo-v2-flash` | ❌ |
|
|
602
|
+
|
|
603
|
+
要用视觉能力,把 model 改成 `mimo-v2.5` 或 `mimo-v2-omni`:
|
|
604
|
+
|
|
605
|
+
```toml
|
|
606
|
+
# ~/.codex/config.toml
|
|
607
|
+
model = "mimo-v2.5"
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
**Q:报 `MiMo returned 400: Param Incorrect: \`text\` is not set`**
|
|
613
|
+
|
|
614
|
+
A:MiMo 的 image API **要求每条带图片的 user 消息必须同时带至少一个 text part**——光发图不带文字会被拒。Codex 桌面端有时会发"光图无文字"的消息(比如粘贴图片直接回车)。
|
|
615
|
+
|
|
616
|
+
mimo2codex 现在会自动在这种情况下补一个空白 text part(仅一个空格),让 MiMo 的参数校验通过。**这意味着你直接粘图发送也不会报错了**——模型会基于图片内容自己理解你想问啥。
|
|
617
|
+
|
|
618
|
+
---
|
|
619
|
+
|
|
620
|
+
**Q:日志里看到 `dropping unsupported tool type "xxx"`,这些都不能用吗?**
|
|
621
|
+
|
|
622
|
+
A:分情况:
|
|
623
|
+
|
|
624
|
+
| Codex 发来的工具类型 | mimo2codex 怎么处理 | 说明 |
|
|
625
|
+
|---|---|---|
|
|
626
|
+
| `function` | ✅ 透传 | 标准 function tool,所有 LLM 都认 |
|
|
627
|
+
| `local_shell` | ✅ 翻译成 `shell` 函数 | Codex 自动 fallback,调用照常 |
|
|
628
|
+
| `custom` | ✅ 翻译成 function tool | 自由格式 / grammar 工具,丢失了 grammar 约束但能调用 |
|
|
629
|
+
| `namespace` | ✅ 递归展开里面的子工具 | MCP 等分组工具 |
|
|
630
|
+
| **`web_search` / `web_search_preview`** | ✅ **翻译成 MiMo 的 `web_search` builtin** | 联网搜索!见下一题 |
|
|
631
|
+
| `code_interpreter` | ❌ 丢弃(仅 debug 日志) | OpenAI 服务端独占,MiMo 无等价物 |
|
|
632
|
+
| `file_search` / `image_generation` | ❌ 丢弃 | 同上 |
|
|
633
|
+
| `computer_use_preview` | ❌ 丢弃 | 同上 |
|
|
634
|
+
| 其他陌生类型 | ❌ 丢弃,**首次见到时打 WARN**(同类型只警告一次,不刷屏) | 欢迎提 issue 让我们加翻译 |
|
|
635
|
+
|
|
636
|
+
被丢弃的"服务端工具"是 OpenAI 自己跑的——MiMo 这边没有对应的实现,强行送过去 MiMo 也不会认。
|
|
637
|
+
|
|
638
|
+
之前每次请求都会刷屏的问题修了:现在只在**第一次见到某个未知类型**时 WARN 一次,已知"服务端工具"完全静默(除非加 `--verbose` 才用 debug 级输出)。
|
|
639
|
+
|
|
640
|
+
---
|
|
641
|
+
|
|
642
|
+
**Q:联网搜索(web_search)能用吗?**
|
|
643
|
+
|
|
644
|
+
A:**能用!** mimo2codex 会把 Codex 的 `web_search` / `web_search_preview` 工具翻译成 MiMo 的原生 [Web Search builtin](https://platform.xiaomimimo.com/#/docs/usage-guide/tool-calling/web-search),包括:
|
|
645
|
+
|
|
646
|
+
- 透传 `user_location`(国家、城市、经纬度等)
|
|
647
|
+
- 透传 MiMo 特有参数 `max_keyword`、`force_search`、`limit`(如果 Codex 发了的话)
|
|
648
|
+
- 反向把 MiMo 返回的 `annotations`(搜索引用)翻译回 Codex 的 `url_citation` 格式,**Codex 终端会显示带链接的引用**
|
|
649
|
+
- 流式场景下,每条搜索源会发 `response.output_text.annotation.added` 事件,Codex 边写边亮引用
|
|
650
|
+
|
|
651
|
+
**前置条件**:
|
|
652
|
+
|
|
653
|
+
1. 去 [MiMo 控制台 → 插件管理](https://platform.xiaomimimo.com/#/console/plugin)**激活 Web Search Plugin**(独立计费,不是包月送的)
|
|
654
|
+
2. 计费规则见 [Pricing 页面](https://platform.xiaomimimo.com/#/docs/pricing)
|
|
655
|
+
3. 一次问答里模型可能并发触发多个关键词搜索,每个都计一次费——可以通过 MiMo 自己的 `max_keyword` 限制
|
|
656
|
+
|
|
657
|
+
激活完无需任何配置,Codex 启动联网功能、问个时事问题就会触发。
|
|
658
|
+
|
|
659
|
+
---
|
|
660
|
+
|
|
661
|
+
## 常见问题
|
|
662
|
+
|
|
663
|
+
**Q:Pet 宠物在 mimo2codex 后还能用吗?**
|
|
664
|
+
|
|
665
|
+
A:**完全可用。** Pet 是桌面端的 UI 悬浮组件,状态来自 Codex 内部的 agent 状态(working / waiting-input / done / error)。这些状态由 Responses SSE 事件生命周期决定(`response.created` → `response.in_progress` → `response.output_item.added` → `response.completed` / `response.failed`)。mimo2codex 严格按规范发出全部事件,所以 pet 的转圈、闲置、完成、错误状态都会正确显示。
|
|
666
|
+
|
|
667
|
+
**Q:工具调用支持哪些?**
|
|
668
|
+
|
|
669
|
+
A:**全部 Codex 的内置工具都支持**——本地 shell、文件读写、apply_patch、web fetch 等。包括并行调用、多轮调用、流式 arguments delta。Codex 把工具定义放进 `tools` 字段,模型返回 `function_call` items;mimo2codex 在两种 API 之间双向翻译这部分,本地工具的执行还是 Codex 自己负责。
|
|
670
|
+
|
|
671
|
+
**Q:图片 / 文件输入支持吗?**
|
|
672
|
+
|
|
673
|
+
A:`input_image` 部分会被翻译成 `image_url` 格式透传——但 MiMo 的 chat API 只在 `mimo-v2-omni` 模型上接受图片,在 `mimo-v2.5-pro` 上会被上游静默丢弃。`input_file`(PDF 等)当前 MiMo chat API 不支持,会被丢弃并打 warn 日志。
|
|
674
|
+
|
|
675
|
+
**Q:思考过程可以隐藏吗?**
|
|
676
|
+
|
|
677
|
+
A:可以,启动时加 `--no-reasoning`。注意这只是不向 Codex 暴露——多轮工具调用时仍会把上一轮的 `reasoning_content` 回填给 MiMo(这是 MiMo 官方推荐的做法,能显著提升多轮工具调用质量)。
|
|
678
|
+
|
|
679
|
+
**Q:为什么不直接改 Codex 让它接受 chat wire?**
|
|
680
|
+
|
|
681
|
+
A:CLI 端确实可以降级到 0.80.0 临时绕过,但你会失去:
|
|
682
|
+
- pet 宠物(5月新出)
|
|
683
|
+
- 桌面端新版本的所有改进
|
|
684
|
+
- 后续所有 Codex 新功能
|
|
685
|
+
|
|
686
|
+
加一层协议 shim 是更小的改动、生命周期更长。
|
|
687
|
+
|
|
688
|
+
**Q:和 [claude-code-router](https://github.com/musistudio/claude-code-router) 是什么关系?**
|
|
689
|
+
|
|
690
|
+
A:思路一样(本地代理 + 协议翻译),但 claude-code-router 是面向 **Claude Code**(Anthropic Messages API)的;mimo2codex 是面向 **Codex**(OpenAI Responses API)的。两个工具可以并存。
|
|
691
|
+
|
|
692
|
+
**Q:把端口改了之后 cc-switch 还能用吗?**
|
|
693
|
+
|
|
694
|
+
A:能。改完用 `mimo2codex --port 9999 print-cc-switch` 拿新片段,去 cc-switch 里编辑一下「MiMo (via mimo2codex)」供应商的 config.toml 文本框(把 `base_url` 里的端口改了)即可。
|
|
695
|
+
|
|
696
|
+
**Q:mimo2codex 会校验入站 Key 吗?**
|
|
697
|
+
|
|
698
|
+
A:**不会。** 它只在 127.0.0.1 监听,假设你的本机是可信的。所有请求一律转发到 MiMo(用启动时的 `MIMO_API_KEY`)。这样设计是为了:
|
|
699
|
+
- 解耦凭据:Codex / cc-switch 那边随便填一个非空字符串就行,真正的 MiMo Key 不会暴露给 Codex 进程
|
|
700
|
+
- 简化使用:换 MiMo Key 不需要改 Codex / cc-switch 配置
|
|
701
|
+
|
|
702
|
+
如果担心本机有恶意进程,请确保只 bind `127.0.0.1`(默认就是)。
|
|
703
|
+
|
|
704
|
+
**Q:怎么看代理在干嘛?**
|
|
705
|
+
|
|
706
|
+
A:启动时加 `--verbose`(或设环境变量 `MIMO2CODEX_VERBOSE=1`):
|
|
707
|
+
|
|
708
|
+
```bash
|
|
709
|
+
# 方式 A
|
|
710
|
+
npm run dev -- --verbose
|
|
711
|
+
# 方式 B
|
|
712
|
+
node dist/cli.js --verbose
|
|
713
|
+
# 方式 C
|
|
714
|
+
mimo2codex --verbose
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
会在 stderr 打印每次的上游 POST、模型名、消息数、工具数、流式与否。API Key 会被脱敏成 `sk-x…xxxx`。
|
|
718
|
+
|
|
719
|
+
---
|
|
720
|
+
|
|
721
|
+
## 项目结构
|
|
722
|
+
|
|
723
|
+
```
|
|
724
|
+
mimo2codex/
|
|
725
|
+
├── src/
|
|
726
|
+
│ ├── cli.ts # 入口:argv 解析、启动 server、打印片段
|
|
727
|
+
│ ├── server.ts # node:http server,路由 /v1/responses、/v1/models、/healthz
|
|
728
|
+
│ ├── config.ts # env + flags 合并
|
|
729
|
+
│ ├── upstream/
|
|
730
|
+
│ │ ├── mimoClient.ts # 调上游 fetch 包装(重试 / 错误归一化)
|
|
731
|
+
│ │ └── chatStream.ts # 上游 Chat SSE → ChatStreamChunk 异步迭代器
|
|
732
|
+
│ ├── translate/
|
|
733
|
+
│ │ ├── types.ts # Responses + ChatCompletions 类型定义
|
|
734
|
+
│ │ ├── reqToChat.ts # 请求方向翻译
|
|
735
|
+
│ │ ├── respToResponses.ts # 非流式响应翻译
|
|
736
|
+
│ │ └── streamToSse.ts # 流式响应状态机
|
|
737
|
+
│ └── util/
|
|
738
|
+
│ ├── ids.ts # resp_*, msg_*, fc_*, rs_* id 生成
|
|
739
|
+
│ ├── sse.ts # SSE 写入 / 测试用 in-memory sink
|
|
740
|
+
│ └── log.ts # debug/info/warn/error + 脱敏
|
|
741
|
+
├── test/ # 25 个 vitest 单测
|
|
742
|
+
├── dist/ # tsc 输出(构建后产生)
|
|
743
|
+
├── package.json
|
|
744
|
+
├── tsconfig.json
|
|
745
|
+
└── vitest.config.ts
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
## 许可证
|
|
749
|
+
|
|
750
|
+
MIT
|