@tscgoods/opencode-effort-discovery 0.5.2 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +19 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscgoods/opencode-effort-discovery",
3
- "version": "0.5.2",
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",
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