@tscgoods/opencode-effort-discovery 0.4.10 → 0.5.5

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
@@ -1,6 +1,6 @@
1
1
  # @tscgoods/opencode-effort-discovery
2
2
 
3
- OpenCode 插件:让 `/models` 里的 reasoning effort 档位**只**出现你的网关真正接受的那些。
3
+ OpenCode 插件:根据网关错误回显、目录或手动覆盖更新模型的 reasoning effort variant。证据不足时不改,声明不保证推理效果。
4
4
 
5
5
  ## 安装
6
6
 
@@ -10,7 +10,7 @@ OpenCode 插件:让 `/models` 里的 reasoning effort 档位**只**出现你
10
10
  "$schema": "https://opencode.ai/config.json",
11
11
  "plugins": [
12
12
  {
13
- "package": "@tscgoods/opencode-effort-discovery@0.3.0",
13
+ "package": "@tscgoods/opencode-effort-discovery",
14
14
  "options": {
15
15
  "providers": ["ts-dpsk"],
16
16
  "debug": false
@@ -46,5 +46,5 @@ OpenCode 插件:让 `/models` 里的 reasoning effort 档位**只**出现你
46
46
  ## 注意
47
47
 
48
48
  - 密钥支持明文、`{env:NAME}`、`!command` 三种写法(与 OpenCode provider 配置一致)。
49
- - 遇到 429/5xx 会保留旧结论并退避重试,不会把免费额度打光。
50
- - 如果某个会话固定了一个被判定不可用的档位,会报 `VariantUnavailableError`,重新选一次模型即可。
49
+ - 遇到 429/5xx 会保留旧结论并退避重试;探测是真实请求,可能产生费用。
50
+ - 如果某个会话固定了一个被判定不可用的档位,会报 `VariantUnavailableError`,重新选一次模型即可。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscgoods/opencode-effort-discovery",
3
- "version": "0.4.10",
3
+ "version": "0.5.5",
4
4
  "description": "OpenCode plugin: show exactly the reasoning effort levels your provider actually accepts.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,6 +31,6 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@opencode/plugin": "^2.4.1"
34
+ "@opencode/plugin": "^2.4.3"
35
35
  }
36
36
  }
package/src/index.ts CHANGED
@@ -133,6 +133,17 @@ export function parseLevels(text: string): string[] | null {
133
133
  return null
134
134
  }
135
135
 
136
+ /** 通用网关可能回显全枚举;只有互相印证的窄子集才算模型级证据 */
137
+ export function pickLevels(candidates: string[][]): string[] | null {
138
+ const specific = candidates.filter((levels) => levels.length > 0 && levels.length < 6)
139
+ if (specific.length === 0) return null
140
+ let result = specific[0]
141
+ for (const levels of specific.slice(1)) {
142
+ result = result.filter((level) => levels.includes(level))
143
+ }
144
+ return result.length > 0 ? result : null
145
+ }
146
+
136
147
  /** 用非法值探一次,读回上游自己声明的合法档位;个别网关只对特定非法值透传上游报错 */
137
148
  export async function probeEffort(input: {
138
149
  baseURL: string
@@ -148,6 +159,7 @@ export async function probeEffort(input: {
148
159
 
149
160
  let last: ProbeResult = { levels: null, source: "error", at: Date.now() }
150
161
  let sawOk = false
162
+ const candidates: string[][] = []
151
163
 
152
164
  for (const sentinel of ["opencode-probe", "ultra", "maximum", "bogus"]) {
153
165
  let response: Response
@@ -176,12 +188,18 @@ export async function probeEffort(input: {
176
188
  }
177
189
 
178
190
  const levels = parseLevels(text)
179
- if (levels) return { levels, source: "validated", at: Date.now() }
191
+ if (levels) {
192
+ candidates.push(levels)
193
+ continue
194
+ }
180
195
 
181
196
  last = { levels: null, source: `http-${response.status}`, at: Date.now() }
182
197
  if ([401, 403, 429].includes(response.status)) return last
183
198
  }
184
199
 
200
+ const levels = pickLevels(candidates)
201
+ if (levels) return { levels, source: "validated", at: Date.now() }
202
+ if (candidates.length > 0) return { levels: null, source: "no-validation", at: Date.now() }
185
203
  return sawOk ? { levels: null, source: "no-validation", at: Date.now() } : last
186
204
  }
187
205