From c2e122683644089454d180ac641981554cc403ec Mon Sep 17 00:00:00 2001 From: Jidekin Date: Wed, 21 Oct 2026 10:26:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(sync):=20=E9=80=82=E9=85=8D=20OpenCode=20?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=94=B9=E7=89=88=EF=BC=88Endpoints=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20/inference/go//v1/=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 文档 Endpoints 表地址从 https://opencode.ai/zen/go/v1/ 改为按供应商分线: /inference/go/openai/v1/{chat/completions,responses} /inference/go/anthropic/v1/messages /inference/go/google/...(Google 原生,网关不支持) 旧的 "/zen/go/v1/" 硬匹配导致一个模型都解析不出,每日同步固定 exit 2。 改为按路径末尾识别三条协议线(新旧格式都兼容),认不出的跳过并在报告里单列。 --- scripts/sync_models.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/scripts/sync_models.py b/scripts/sync_models.py index f820d6d..9e91cba 100755 --- a/scripts/sync_models.py +++ b/scripts/sync_models.py @@ -84,18 +84,44 @@ def _norm(s: str) -> str: # ── OpenCode Go ──────────────────────────────────────────────── +# 2026-10-21 文档改版:Endpoints 表里的地址从 +# https://opencode.ai/zen/go/v1/ (旧) +# 改成按供应商分线: +# https://opencode.ai/inference/go/openai/v1/chat/completions +# https://opencode.ai/inference/go/openai/v1/responses +# https://opencode.ai/inference/go/anthropic/v1/messages +# https://opencode.ai/inference/go/google/v1beta/models/ (Google 原生,网关不支持) +# 网关只认三条线,所以按「路径末尾」认协议线,认不出的(Google 原生)跳过并报告。 +OC_PROTOCOLS = ("chat/completions", "messages", "responses") +OC_SKIPPED: list[str] = [] + + +def _oc_protocol(url: str) -> str | None: + """文档 Endpoint → 网关协议线;认不出返回 None。""" + path = url.split("?", 1)[0].rstrip("/") + for proto in OC_PROTOCOLS: + if path.endswith("/" + proto): + return proto + return None + + def fetch_opencode() -> dict[str, dict]: """返回 {model_id: {name, protocol, free}}。""" html = _get(OC_DOC_URL) models: dict[str, dict] = {} + skipped: list[str] = [] for row in re.findall(r"(.*?)", html, re.S): cells = [_strip_tags(c) for c in re.findall(r"]*>(.*?)", row, re.S)] - if len(cells) < 4 or "/zen/go/v1/" not in cells[2]: + if len(cells) < 4 or "opencode.ai/" not in cells[2]: continue - tail = cells[2].split("/zen/go/v1/", 1)[1].strip("/").split("?")[0] - models[cells[1]] = {"name": cells[0], "protocol": tail, "free": False} + proto = _oc_protocol(cells[2]) + if proto is None: + skipped.append(cells[1]) + continue + models[cells[1]] = {"name": cells[0], "protocol": proto, "free": False} if not models: raise RuntimeError("OpenCode 文档没解析出 Endpoints 表(页面可能改版)") + OC_SKIPPED[:] = sorted(skipped) # 免费模型:价格表里 Input/Output 都是 Free 的那些(名字对 id 做归一匹配) by_norm = {_norm(mid): mid for mid in models} @@ -448,6 +474,7 @@ def diff(cfg: dict, oc_doc: dict, agnes_doc: dict, "protocol_drift": proto_drift, "free_drift": free_drift, "ctx_drift": oc_ctx_drift, + "skipped": list(OC_SKIPPED), } # Agnes @@ -564,6 +591,9 @@ def render(report: dict) -> str: if not any(oc[k] for k in ("added", "removed", "protocol_drift", "free_drift", "ctx_drift")): lines.append(" 无漂移 ✓") + if oc.get("skipped"): + lines.append(" 跳过(文档端点不是三条网关协议线,网关不支持):") + lines += [f" · {m}" for m in oc["skipped"]] lines.append("") lines.append(f"== Agnes == 文档 {ag['doc_count']} 个 / 网关 {ag['cfg_count']} 个")