@tscgoods/opencode-effort-discovery 0.4.9 → 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 +4 -4
- package/package.json +2 -2
- package/src/index.ts +18 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tscgoods/opencode-effort-discovery
|
|
2
2
|
|
|
3
|
-
OpenCode
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.5.2",
|
|
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.
|
|
34
|
+
"@opencode/plugin": "^2.4.3"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -392,13 +392,28 @@ export default Plugin.define({
|
|
|
392
392
|
log("skip", provider.id, "no baseURL")
|
|
393
393
|
continue
|
|
394
394
|
}
|
|
395
|
+
// 官方 zen 端点的模型在 models.dev 里有目录元数据,且端点对探测一律 400/429,不打扰
|
|
396
|
+
try {
|
|
397
|
+
const host = new URL(baseURL).hostname
|
|
398
|
+
if (host === "opencode.ai" || host.endsWith(".opencode.ai")) {
|
|
399
|
+
log("skip", provider.id, "zen endpoint uses catalog metadata")
|
|
400
|
+
continue
|
|
401
|
+
}
|
|
402
|
+
} catch {
|
|
403
|
+
// 非法 URL 照常尝试
|
|
404
|
+
}
|
|
395
405
|
|
|
396
406
|
for (const model of models.filter((item) => item.providerID === provider.id)) {
|
|
397
407
|
const modelID = String((model as { modelID?: string }).modelID ?? model.id)
|
|
398
408
|
const id = cacheKey(provider.id, modelID)
|
|
399
409
|
const previous = probes.get(id)
|
|
410
|
+
// error/429/5xx 视为可重试;http-400/404 等确定性答复在 TTL 内缓存,避免探测风暴
|
|
411
|
+
const retryable =
|
|
412
|
+
previous?.source === "error" ||
|
|
413
|
+
previous?.source === "http-429" ||
|
|
414
|
+
(previous?.source.startsWith("http-5") ?? false)
|
|
400
415
|
const stale =
|
|
401
|
-
!previous ||
|
|
416
|
+
!previous || retryable || Date.now() - previous.at >= ttlMs
|
|
402
417
|
if (!stale) continue
|
|
403
418
|
|
|
404
419
|
const result = await probeEffort({ baseURL, apiKey, modelID, headers })
|
|
@@ -426,18 +441,15 @@ export default Plugin.define({
|
|
|
426
441
|
return { changed, limited }
|
|
427
442
|
}
|
|
428
443
|
|
|
429
|
-
//
|
|
430
|
-
let changed = false
|
|
444
|
+
// 遇到限流就退避重试,直到探测稳定或放弃;每轮结束立刻 reload,不等全部轮次
|
|
431
445
|
for (let round = 0; round < 5; round++) {
|
|
432
446
|
const result = await runProbes()
|
|
433
|
-
if (result.changed)
|
|
447
|
+
if (result.changed || (round === 0 && probes.size > 0)) await ctx.model.reload()
|
|
434
448
|
if (!result.limited) break
|
|
435
449
|
const waitMs = 60_000 * (round + 1)
|
|
436
450
|
log("backing off", waitMs)
|
|
437
451
|
await sleep(waitMs)
|
|
438
452
|
}
|
|
439
|
-
|
|
440
|
-
if (changed || probes.size > 0) await ctx.model.reload()
|
|
441
453
|
}
|
|
442
454
|
|
|
443
455
|
void bootstrap().catch((error) => log("bootstrap failed", error))
|