@tscgoods/opencode-effort-discovery 0.4.9 → 0.4.10

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 +18 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscgoods/opencode-effort-discovery",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
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
@@ -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 || previous.source.startsWith("http-") || Date.now() - previous.at >= ttlMs
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) changed = true
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))