@tscgoods/dsh-effort-discovery 0.3.2 → 0.5.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 CHANGED
@@ -17,8 +17,8 @@ reasoningEfforts: { 'off': null, minimal: minimal, low: low, medium: medium, hig
17
17
  ## 安装
18
18
 
19
19
  ```powershell
20
- # 本地开发(pnpm link,改完重启 profile 生效)
21
- dsh plugin --profile web add C:\Users\蒋老师\projects\opencode-effort-discovery\packages\dsh
20
+ # 本地开发(在仓库根目录执行;pnpm link,改完重启 profile 生效)
21
+ dsh plugin --profile web add (Join-Path (Get-Location) 'packages\dsh')
22
22
 
23
23
  # 或从 npm
24
24
  dsh plugin --profile web add @tscgoods/dsh-effort-discovery
@@ -38,7 +38,7 @@ dsh --profile web --dump-config | Select-String effort-discovery
38
38
  node packages\dsh\scripts\probe.mjs --provider ts-dpsk
39
39
  ```
40
40
 
41
- 结果写到 `~/.cache/effort-discovery/dsh.json`。插件在启动/配置更新时读这份缓存,按模型 id 匹配。
41
+ 结果写到 `~/.cache/effort-discovery/dsh.json`。启动/配置更新时,只有 provider 名、baseURL、`openai-completions` 协议和模型 id 均匹配,且实测缓存未超过 TTL 时才变换;否则保留原配置。
42
42
 
43
43
  ## 行为
44
44
 
@@ -46,7 +46,7 @@ node packages\dsh\scripts\probe.mjs --provider ts-dpsk
46
46
  | --- | --- |
47
47
  | 探测到合法档位 | `reasoningEfforts` 只保留实测档位(`none` → `off: null`),沿用原有 wire 值 |
48
48
  | 探测到只有 `none` | `reasoningEfforts: false`(当作非推理模型,菜单不再出现 Effort) |
49
- | 没探测结果 / `unknown` | 不动原配置 |
49
+ | 没探测结果 / `unknown` / 超过 TTL / 路由不匹配 | 不动原配置 |
50
50
  | `mode: "off"` | 完全不改配置,只保留 `reasoning_effort_probe` 工具 |
51
51
 
52
52
  配置项(`cordis.patch.yml` 里那一行的 `config`):
@@ -62,7 +62,7 @@ ttlMs: 21600000
62
62
 
63
63
  ## 风险与验证
64
64
 
65
- - 插件用 Cordis 的 `internal/config` waterfall 改写 `@deepseek-ai/dsh-llm-pi-ai` 这一行的 `providers`。这是 rc 版本里的内部事件,升级 dsh 后如果行为变了,请先 `--dump-config` 对照。
65
+ - 插件用 Cordis 的 `internal/config` waterfall 改写 `@deepseek-ai/dsh-llm-pi-ai` 的 `providers`,这是内部事件。0.2.3-alpha.3 的 `--dump-config` 只确认旧包存在,新代码尚需在隔离 profile 里验证宿主内实际变换。
66
66
  - 插件注册在 `llm-pi-ai` 之后(insert 追加到末尾),所以它的变换结果会参与该行的配置校验;如果未来有 bundle 插到它前面,顺序假设需要重新确认。
67
67
  - 收窄档位对已保存的会话有影响:如果会话固定了一个被移除的档位,下一步会报 `UNSUPPORTED_REASONING_EFFORT`,重新选一次档位即可。
68
- - 不想让插件改配置时,把 `mode` 设为 `off`,只用探测脚本 + 手工改 `cordis.patch.yml`。
68
+ - 不想让插件改配置时,把 `mode` 设为 `off`,只用探测脚本 + 手工改 `cordis.patch.yml`。
package/lib/index.js CHANGED
@@ -16,6 +16,8 @@ export const Config = z.object({
16
16
 
17
17
  const TARGET_ADAPTER = "dsh-llm-pi-ai"
18
18
  const LEVELS = ["minimal", "low", "medium", "high", "xhigh", "max"]
19
+ const DEFAULT_TTL_MS = 6 * 60 * 60 * 1000
20
+ const normalizeURL = (value) => typeof value === "string" ? value.replace(/\/+$/, "") : ""
19
21
 
20
22
  function cacheDir() {
21
23
  return (
@@ -72,19 +74,26 @@ export function narrowEfforts(model, levels) {
72
74
  return Object.keys(next).filter((level) => level !== "off").length > 0 ? next : false
73
75
  }
74
76
 
75
- function transformProviders(raw, cache) {
77
+ export function transformProviders(raw, cache, ttlMs = DEFAULT_TTL_MS, now = Date.now()) {
76
78
  if (!raw || typeof raw !== "object" || !raw.providers || typeof raw.providers !== "object") {
77
79
  return raw
78
80
  }
81
+ if (typeof cache?.provider !== "string" || !cache.provider) return raw
79
82
  const providers = { ...raw.providers }
80
83
  let changed = false
81
84
 
82
85
  for (const [route, profile] of Object.entries(providers)) {
86
+ // A model id alone does not identify a gateway or its protocol.
87
+ if (route !== cache.provider) continue
83
88
  if (!profile || typeof profile !== "object" || !Array.isArray(profile.models)) continue
89
+ if (!cache.baseURL || !profile.baseURL || normalizeURL(cache.baseURL) !== normalizeURL(profile.baseURL)) continue
90
+ if (profile.api !== "openai-completions") continue
84
91
  const models = profile.models.map((model) => {
85
92
  if (!model || typeof model.id !== "string") return model
86
93
  const info = cache?.models?.[model.id]
87
- if (!info || !Array.isArray(info.levels)) return model
94
+ const at = info?.at ?? cache.at
95
+ if (info?.source !== "validated" || !Array.isArray(info.levels) ||
96
+ !Number.isFinite(at) || at > now || now - at >= ttlMs) return model
88
97
  const reasoningEfforts = narrowEfforts(model, info.levels)
89
98
  if (reasoningEfforts === undefined) return model
90
99
  changed = true
@@ -146,7 +155,7 @@ export default {
146
155
  return raw
147
156
  }
148
157
  try {
149
- const next = transformProviders(raw, cache)
158
+ const next = transformProviders(raw, cache, config?.ttlMs ?? DEFAULT_TTL_MS)
150
159
  if (config?.diag) {
151
160
  const before = []
152
161
  for (const profile of Object.values(raw?.providers ?? {})) {
@@ -171,4 +180,4 @@ export default {
171
180
 
172
181
  export function __diag() {
173
182
  return { cachePath: cachePath(), exists: existsSync(cachePath()) }
174
- }
183
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscgoods/dsh-effort-discovery",
3
- "version": "0.3.2",
3
+ "version": "0.5.2",
4
4
  "description": "DeepSeek Harness (dsh) bundle: probe the gateway for the reasoning-effort levels each model accepts and narrow llm-pi-ai reasoningEfforts to them.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -34,7 +34,7 @@
34
34
  "access": "public"
35
35
  },
36
36
  "engines": {
37
- "dsh": ">=0.2.2-rc.1 <0.3.0",
37
+ "dsh": ">=0.2.2-rc.1 <0.3.0 || >=0.2.3-alpha.3 <0.2.3",
38
38
  "node": ">=20"
39
39
  },
40
40
  "dsh": {
@@ -46,8 +46,8 @@
46
46
  "@deepseek-ai/schemastery": "~3.19.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@deepseek-ai/cordis": "~4.1.0",
50
- "@deepseek-ai/dsh-llm": ">=0.2.2-rc.1 <0.3.0",
51
- "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.3.0"
49
+ "@deepseek-ai/cordis": "~4.1.0 || ~4.2.0-alpha.2",
50
+ "@deepseek-ai/dsh-llm": ">=0.2.2-rc.1 <0.3.0 || >=0.2.3-alpha.3 <0.2.3",
51
+ "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.3.0 || >=0.2.3-alpha.3 <0.2.3"
52
52
  }
53
53
  }
package/scripts/probe.mjs CHANGED
@@ -136,6 +136,10 @@ if (!entry) {
136
136
  process.stderr.write("no provider: add one to ~/.config/effort-discovery.json\n")
137
137
  process.exit(2)
138
138
  }
139
+ if (entry.api && entry.api !== "openai") {
140
+ process.stderr.write(`provider "${providerID}" is not configured for OpenAI-compatible requests\n`)
141
+ process.exit(2)
142
+ }
139
143
 
140
144
  const models = args.models.length > 0 ? args.models : Array.isArray(entry.models) ? entry.models : []
141
145
  if (models.length === 0) {
@@ -173,4 +177,4 @@ if (args.json) {
173
177
  )
174
178
  }
175
179
  process.stdout.write(`\ncache: ${cachePath()}\n`)
176
- }
180
+ }