@tscgoods/codex-effort-discovery 0.3.0 → 0.4.7
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 +68 -0
- package/package.json +2 -2
- package/scripts/probe.mjs +24 -11
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @tscgoods/codex-effort-discovery
|
|
2
|
+
|
|
3
|
+
Codex CLI 插件:探测网关真正接受的 reasoning effort 档位,然后生成/更新一份 **model catalog**,让 Codex 的档位菜单只出现这些档位。
|
|
4
|
+
|
|
5
|
+
## 为什么需要
|
|
6
|
+
|
|
7
|
+
Codex 的档位列表来自 `model_catalog_json`(**配置**,不是插件接口):每个模型的 `supported_reasoning_levels` 决定 UI 里出现哪些档位。插件不能改枚举,但可以:
|
|
8
|
+
|
|
9
|
+
1. 探测网关(默认:上游错误回显优先,原生 catalog 兜底);
|
|
10
|
+
2. 把结果写进现有 catalog 的副本,并告诉你把 `model_catalog_json` 指过去。
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```powershell
|
|
15
|
+
codex plugin marketplace add <本仓库或本包目录的上级目录>
|
|
16
|
+
codex plugin add effort-discovery@<marketplace>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
也可以把包目录放进任意本地 marketplace(`.agents/plugins/marketplace.json`)再安装。
|
|
20
|
+
|
|
21
|
+
## 用法
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
# 1. 探测(provider 来自 ~/.config/effort-discovery.json,默认第一个 openai provider)
|
|
25
|
+
node scripts/probe.mjs
|
|
26
|
+
|
|
27
|
+
# 2. 预览 catalog 改动(默认 dry-run)
|
|
28
|
+
node scripts/sync-catalog.mjs
|
|
29
|
+
|
|
30
|
+
# 3. 确认后写入 ~/.codex/model-catalogs/efforts.json
|
|
31
|
+
node scripts/sync-catalog.mjs --write
|
|
32
|
+
|
|
33
|
+
# 4. 在 ~/.codex/config.toml 里指向它
|
|
34
|
+
# model_catalog_json = 'C:\Users\<you>\.codex\model-catalogs\efforts.json'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
插件还提供 `/efforts` 命令和 `effort-probe` 技能,让 agent 代跑这两步。
|
|
38
|
+
|
|
39
|
+
## 哪个证据可信
|
|
40
|
+
|
|
41
|
+
DeepSeek 官方文档(https://api-docs.deepseek.com/zh-cn/guides/thinking_mode)明确写着 `reasoning_effort` 只接受 `low / high / max`,`medium` 和 `xhigh` 都会被映射成 `high`;Anthropic 格式是 `none/low/high/max`。
|
|
42
|
+
|
|
43
|
+
但网关的原生 catalog(cc-switch 生成的 `/v1/models`)给 deepseek 标的是 `low/medium/high/xhigh`——**这个 catalog 是错的,而且漏了 max**,导致 Codex 菜单里选不到 max。
|
|
44
|
+
|
|
45
|
+
因此 `probe.mjs` 的默认优先级是:
|
|
46
|
+
|
|
47
|
+
1. **上游错误回显**(`/v1/chat/completions` 的非法值 400,反映实际接受的档位)→ `source: validated`;
|
|
48
|
+
2. **原生 catalog** 兜底(错误回显拿不到时)→ `source: native-catalog`。
|
|
49
|
+
|
|
50
|
+
`none` 会被过滤掉(Codex 的 `supported_reasoning_levels` 不接受它),最终 deepseek 得到 `low/high/max`。`--no-native` 保留作"只看错误回显"的诊断开关。若网关原生 catalog 与错误回显一致,两者结果相同,无副作用。
|
|
51
|
+
|
|
52
|
+
## 更省事的替代
|
|
53
|
+
|
|
54
|
+
如果网关的 catalog 本身准确,可以不装插件:
|
|
55
|
+
|
|
56
|
+
```toml
|
|
57
|
+
[model_providers.custom]
|
|
58
|
+
base_url = "http://127.0.0.1:7891/v1"
|
|
59
|
+
model_catalog_url = "http://127.0.0.1:7891/v1/models" # 必须与 base_url 同源同端口
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
但本例中 cc-switch 的 catalog 是错的,所以要用插件生成并写入正确的 catalog。
|
|
63
|
+
|
|
64
|
+
## 注意
|
|
65
|
+
|
|
66
|
+
- Codex 只在启动时读 catalog,改完需要重开会话。
|
|
67
|
+
- 只有 `ultra` 会被 Codex 重映射;其余值(包括非法值)会原样发给上游,上游 400 会直接变成 `turn.failed`。所以 catalog 写得准很关键。
|
|
68
|
+
- `(unknown)` 的模型不会被写进 catalog,保留原值。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscgoods/codex-effort-discovery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Codex CLI plugin: probe which reasoning-effort levels your gateway accepts, then generate a model catalog that makes Codex offer exactly those.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=20"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
package/scripts/probe.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
CODEX_EFFORTS,
|
|
3
4
|
cachePath,
|
|
4
5
|
loadConfig,
|
|
5
6
|
nativeCatalog,
|
|
@@ -54,19 +55,31 @@ const headers = entry.headers ?? {}
|
|
|
54
55
|
|
|
55
56
|
const result = { at: Date.now(), provider: providerID, baseURL, models: {} }
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
for (const [model, levels] of Object.entries(native)) {
|
|
61
|
-
result.models[model] = { levels, source: "native-catalog", at: Date.now() }
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
58
|
+
const native = args.noNative ? undefined : await nativeCatalog({ baseURL, apiKey, headers })
|
|
59
|
+
const configured = args.models.length > 0 ? args.models : Array.isArray(entry.models) ? entry.models : []
|
|
60
|
+
const models = [...new Set([...Object.keys(native ?? {}), ...configured])]
|
|
65
61
|
|
|
66
|
-
const models = args.models.length > 0 ? args.models : Array.isArray(entry.models) ? entry.models : []
|
|
67
62
|
for (const model of models) {
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const nativeLevels = native?.[model] ?? null
|
|
64
|
+
const probed = await probeOpenAI({ baseURL, apiKey, model, headers })
|
|
65
|
+
const validated = probed.source === "validated" && Array.isArray(probed.levels) && probed.levels.length > 0
|
|
66
|
+
|
|
67
|
+
// 上游错误回显优先(它反映实际接受的 effort),原生 catalog 兜底
|
|
68
|
+
const levels = validated
|
|
69
|
+
? probed.levels.filter((level) => CODEX_EFFORTS.includes(level))
|
|
70
|
+
: nativeLevels ?? null
|
|
71
|
+
|
|
72
|
+
result.models[model] = {
|
|
73
|
+
levels,
|
|
74
|
+
source: validated
|
|
75
|
+
? "validated"
|
|
76
|
+
: nativeLevels
|
|
77
|
+
? "native-catalog"
|
|
78
|
+
: probed.source,
|
|
79
|
+
rawLevels: probed.levels,
|
|
80
|
+
nativeLevels,
|
|
81
|
+
at: Date.now(),
|
|
82
|
+
}
|
|
70
83
|
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
71
84
|
}
|
|
72
85
|
|