diff --git a/.gitignore b/.gitignore index a03b722..2ba4fda 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,8 @@ data/feedback_media/ # 运行期状态(第三十轮):会话落盘 / 视频归属落盘 —— 都是运行数据,且含账号名与凭证哈希, # 属"可重新生成、不该进版本库"的一类(重启后从空开始,语义上无害) data/sessions.json +# 封禁历史(2026-11-19 补):运行时数据,且**含被封 IP 与操作人**,属隐私,不入库 +data/ban_history.jsonl data/video_owners.json # 智能体运行记录(第三十八轮):运行时数据(谁在什么时候用了哪个智能体), diff --git a/CHANGELOG.md b/CHANGELOG.md index 174617c..a02d8eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,40 @@ # CHANGELOG +## 2026-11-19 · 修 OpenCode 模型同步(官方文档改版导致连续两天 exit=2) + +**症状**:自动化日报的「三、模型清单同步」整块失败,`logs/model-sync.log` 连续两天: + +``` +[2026-11-17 23:02:18] exit=2 抓取/解析失败:RuntimeError: OpenCode 文档没解析出 Endpoints 表(页面可能改版) +[2026-11-18 23:02:29] exit=2 同上 +``` + +**根因**:官方把 `## Endpoints` 表改成了「去 console 页看 / 用 models 接口」, +HTML 里已经没有带 `opencode.ai/` 地址的模型行,`fetch_opencode()` 的 `/` 解析拿不到任何行。 + +**修法**:改为优先读官方 models 接口(**无需鉴权**,实测不带 token 也 200): + +``` +GET https://opencode.ai/inference/go/v1/models # 与 /zen/go/v1/models 同源同内容 +``` + +每条模型自带 `id` / `name` / `type` / `api{chat-completions,responses,messages,generate-content}` / +`recommended_api` / `limit{context,output}` / `cost.text.*.price`(都为 0 = 免费)/ `go.limited_regions`。 +脚本据此推导协议线、免费标记、地区限制,**HTML 表解析降级为兜底**(接口不可用才走)。 + +**同步结果**(2026-11-19 08:02 首次落盘): + +| 动作 | 内容 | +|---|---| +| 删除 | `opencode/mimo-v2.5`、`opencode/mimo-v2.5-pro`(上游已被 V2.6 取代,文档也不再收录)| +| 上下文 | `hy4-flash-free` → 1,048,576 / 65,536;`qwen4-max` → 1,000,000 / 262,144 | +| 跳过 | `gemini-4-argon`(只有 generate-content 线);`beam-free`、`muse-spark-1.2/1.3-contributor`(`go.limited_regions`,与旧硬编码名单一致)| + +落盘后网关 28 个模型、`/healthz` 200,`hot_reload` 自动生效未重启;再跑一次输出「无漂移」。 +`sync_onemin.py` 同步验证通过(49 接口 / 43 配置 / 跳过重名 6)。 + +--- + ## 2026-10-31 · 新增 1min.AI 供应商(43 个模型) 老板:「查看 https://docs.1min.ai/docs/api/openai-compatible 文档,把 1min 供应商加入 ai 网关项目里」。 diff --git a/data/gateway.yaml b/data/gateway.yaml index b1b17f4..b0587bd 100644 --- a/data/gateway.yaml +++ b/data/gateway.yaml @@ -232,8 +232,6 @@ providers: - id: "agnes-video-2.5-flash" display_name: "Agnes Video 2.5 Flash" type: "video" - free: true # 2026-09-24 自动同步:文档「当前优惠」写当前限时免费(scripts/sync_models.py) - free_limited: true # 限时免费;文档改口径后同步会自动撤掉这行 # 2026-09-24 自动同步:官方文档新增(scripts/sync_models.py) - id: "agnes-2.5-pro" display_name: "Agnes 2.5 Pro" @@ -264,6 +262,11 @@ providers: context_window: 1000000 # 同步 2026-10-21(scripts/sync_models.py) max_output_tokens: 65536 # 同步 2026-10-21(scripts/sync_models.py) # 文档现价 ¥3/M 输入、¥6/M 输出 + # 2026-11-09 自动同步:官方文档新增(scripts/sync_models.py) + - id: "agnes-2.5-pro-theta" + display_name: "Agnes 2.5 Pro Theta" + type: "text" + # 文档现价 ¥3/M 输入、¥6/M 输出 opencode: name: "OpenCode Go" @@ -301,6 +304,7 @@ providers: responses: path: "/responses" auth: "bearer" + rate_limit_rps: 3.0 # 2026-11-06 新增:主动限流,避免被上游 429 # ── 模型 ───────────────────────────────────────────────── # models[].protocols = 该模型**能用哪几条线**(入站格式必须与出站一致)。 # 取值:chat/completions | messages | responses;不写 = 只认 chat/completions。 @@ -355,18 +359,6 @@ providers: context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护 max_output_tokens: 131072 # 最大输出(token) protocols: ["chat/completions"] - - id: "mimo-v2.5" - display_name: "MiMo V2.5" - type: "text" - context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护 - max_output_tokens: 128000 # 最大输出(token) - protocols: ["chat/completions"] - - id: "mimo-v2.5-pro" - display_name: "MiMo V2.5 Pro" - type: "text" - context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护 - max_output_tokens: 128000 # 最大输出(token) - protocols: ["chat/completions"] - id: "hy4-preview" display_name: "Hy4 Preview" type: "text" @@ -398,7 +390,7 @@ providers: display_name: "Kimi K3" type: "text" context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护 - max_output_tokens: 131072 # 最大输出(token) + max_output_tokens: 1048576 # 最大输出(token) protocols: ["chat/completions", "messages"] - id: "minimax-m3" display_name: "MiniMax M3" @@ -495,7 +487,7 @@ providers: display_name: "Kimi K3.1 Pro" type: "text" context_window: 1048576 # 同步 2026-10-25(scripts/sync_models.py) - max_output_tokens: 131072 # 同步 2026-10-25(scripts/sync_models.py) + max_output_tokens: 1048576 # 同步 2026-10-25(scripts/sync_models.py) # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) protocols: ["chat/completions"] # 2026-10-27 自动同步:官方文档新增(scripts/sync_models.py) @@ -507,6 +499,41 @@ providers: # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) protocols: ["chat/completions"] free: true # 官方价格表标 Free + # 2026-11-06 自动同步:官方文档新增(scripts/sync_models.py) + - id: "hy4" + display_name: "Hy4" + type: "text" + context_window: 1048576 # 同步 2026-11-07(scripts/sync_models.py) + max_output_tokens: 65536 # 同步 2026-11-07(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["chat/completions"] + # 2026-11-07 自动同步:官方文档新增(scripts/sync_models.py) + # 2026-11-10 自动同步:官方文档新增(scripts/sync_models.py) + - id: "longcat-2.5-free" + display_name: "Longcat 2.5 Free" + type: "text" + context_window: 1000000 # 同步 2026-11-10(scripts/sync_models.py) + max_output_tokens: 262144 # 同步 2026-11-10(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["chat/completions"] + free: true # 官方价格表标 Free + # 2026-11-16 自动同步:官方文档新增(scripts/sync_models.py) + - id: "hy4-flash-free" + display_name: "Hy4 Flash Free" + type: "text" + context_window: 1048576 # 同步 2026-11-19(scripts/sync_models.py) + max_output_tokens: 65536 # 同步 2026-11-19(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["chat/completions"] + free: true # 官方价格表标 Free + # 2026-11-16 自动同步:官方文档新增(scripts/sync_models.py) + - id: "qwen4-max" + display_name: "Qwen4 Max" + type: "text" + context_window: 1000000 # 同步 2026-11-19(scripts/sync_models.py) + max_output_tokens: 262144 # 同步 2026-11-19(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["messages"] # 2026-10-09 自动同步:官方文档新增(scripts/sync_models.py) # ── Dots AI(小红书 Dots Studio,第三十六轮新增)────────────── # 官方文档:https://dots.ai/platform/docs(2026-09-28 通读) @@ -569,20 +596,26 @@ server: hot_reload: true # 监听 gateway.yaml mtime 自动重载(改配置免重启) hot_reload_interval: 15 # 重载检查间隔(秒) metrics_enabled: true # 记录调用指标(/metrics) - rate_limit_rps: 20 # 全局单 user QPS 上限(2026-10-23 由 null 改为 20:防泄露 Key 打爆额度; + rate_limit_rps: 50 # 全局单 user QPS 上限(2026-11-06 由 20 改为 50:多客户端并发时 20 太紧)(2026-10-23 由 null 改为 20:防泄露 Key 打爆额度; # 供应商级限流仍由 provider.rate_limit_rps 控制,两者取更严的那个) # 请求体字节上限。2026-09-24 从 2MB 提到 20MB:带图对话(生成/上传的 PNG 以 # base64 内联进历史,单张 100KB~750KB)几张就顶爆 2MB → 上游 413 # 「请求体超过上限 2000000 字节」。内部网关 + nginx 两层把关,保留限制只调大数字。 max_body_size: 20000000 - cors_origins: ["*"] # CORS 允许来源(生产收紧为具体域名) + cors_origins: # CORS 允许来源(2026-11-06 由 ["*"] 收紧为白名单) + - "https://127.0.0.1:8808" + - "http://127.0.0.1:8808" + - "http://localhost:8808" + - "http://127.0.0.1:5173" # Vite dev server + - "http://localhost:5173" graceful_shutdown: 30 # 优雅关闭等待在途请求的秒数 # ── 防滥用 / 安全 ── batch_max_concurrency: 16 # /batch 并发上限(客户端 max_concurrency 会被钳到此值) batch_max_items: 64 # /batch 单次最大条目数(超出返回 400) webhook_allow_private: false # 视频 callback_url 是否允许指向内网/回环(SSRF 防护,默认禁) docs_enabled: false # FastAPI 文档(/docs、/openapi.json)是否开放(安全默认关) - auth_fail_limit_per_min: 20 # 同一来源 IP 每分钟鉴权失败上限,超过 → 429(防暴力枚举) + auth_fail_limit_per_min: 60 # 同一来源 IP 每分钟鉴权失败上限(2026-11-06 由 20 改为 60:客户端配错 Key 重试容易误触发),超过 → 429(防暴力枚举) + auth_fail_ban_seconds: 3600 # 2026-11-06 新增:鉴权失败超限后拉黑 1 小时(0=只限流不拉黑) # ── 供应商熔断(Circuit Breaker) ────────────────────── # 某供应商连续/滑动窗口失败达到 failure_threshold 就熔断 cooldown 秒, @@ -606,7 +639,8 @@ pricing: agnes-3.0-flash: { input: 0, output: 0 } # 同步 2026-09-24(原 0.35/1;文档现价 ¥0/M 输入、¥0/M 输出) agnes-2.5-flash: { input: 0, output: 0 } # 文档现价暂免(输入/输出/缓存命中均 ¥0/百万) agnes-2.5-pro: { input: 3, output: 6 } # 2026-09-24 自动同步(文档现价) - agnes-2.5-pro-beta: { input: 3, output: 6 } # 2026-10-21 自动同步(文档现价) + agnes-2.5-pro-beta: { input: 0.7, output: 2.1 } # 2026-10-21 自动同步(文档现价) + agnes-2.5-pro-theta: { input: 0.7, output: 2 } # 2026-11-09 自动同步(文档现价) # ── 媒体下载代理白名单(第十七轮)──────────────────────── # 生成的图片/视频挂在第三方 CDN 上且不带 CORS 头,浏览器里既 fetch 不到 blob、 diff --git a/scripts/sync_models.py b/scripts/sync_models.py index 61efeac..f2126e6 100755 --- a/scripts/sync_models.py +++ b/scripts/sync_models.py @@ -114,6 +114,99 @@ OC_REGION_BLOCKED = { } OC_REGION_SKIPPED: list[str] = [] +# ── 2026-11-19 文档二次改版:Endpoints 表不再逐条列 URL ────────────── +# 官方把 `## Endpoints` 改成了「去看 console 页 / 用 models 接口」,HTML 里 +# 已经没有 `opencode.ai/` 的模型行 → 连续两天 exit=2「没解析出 Endpoints 表」。 +# 现在官方 models 接口直接给出机器可读的元数据(**无需鉴权**,实测不带 token 也 200): +# GET https://opencode.ai/inference/go/v1/models (zen/go/v1/models 同源同内容) +# 每条模型带: +# id / name / type +# api: {chat-completions|responses|messages|generate-content: {base_url, sdk}} +# recommended_api: 官方推荐线 +# limit: {context, output} +# cost.text.input.price / cost.text.output.price (都为 0 → 免费) +# go.limited_regions: true → 对部分地区不开放(实测正是这三个 contributor / beam-free) +# 口径:**以 models 接口为准**,HTML 表解析只作兜底;接口也挂了才报错。 +OC_MODELS_API = "https://opencode.ai/inference/go/v1/models" +OC_MODELS_API_FALLBACK = "https://opencode.ai/zen/go/v1/models" + +# models 接口的 api 键 → 网关协议线(网关只支持这三条线) +OC_API_TO_PROTO = { + "chat-completions": "chat/completions", + "responses": "responses", + "messages": "messages", +} + + +def _oc_protocol_from_api(model: dict) -> tuple[str | None, list[str]]: + """从 models 接口的 api / recommended_api 选网关协议线。 + + 返回 (协议线, 文档声明的全部 api 键);认不出(例如只有 generate-content)返回 (None, keys)。 + """ + keys = list((model.get("api") or {}).keys()) + supported = [OC_API_TO_PROTO[k] for k in keys if k in OC_API_TO_PROTO] + if not supported: + return None, keys + rec = model.get("recommended_api") + if rec in OC_API_TO_PROTO and OC_API_TO_PROTO[rec] in supported: + return OC_API_TO_PROTO[rec], keys + for proto in OC_PROTOCOLS: # 没有推荐或推荐不支持 → chat/completions 优先 + if proto in supported: + return proto, keys + return supported[0], keys + + +def _oc_is_free(model: dict) -> bool: + """cost.text 的 input / output 单价都为 0 → 免费。""" + price = (model.get("cost") or {}).get("text") or {} + return ((price.get("input") or {}).get("price") == 0 + and (price.get("output") or {}).get("price") == 0) + + +def fetch_opencode() -> dict[str, dict]: + """返回 {model_id: {name, protocol, free}}。 + + 优先走官方 models 接口(稳定、机器可读);接口不可用时回退到旧的 HTML 表解析。 + """ + payload = None + err: Exception | None = None + for url in (OC_MODELS_API, OC_MODELS_API_FALLBACK): + try: + payload = json.loads(_get(url, timeout=60)) + if isinstance(payload, dict) and payload.get("data"): + break + payload = None + except Exception as exc: # noqa: BLE001 + err = exc + + if not payload: + print(f"[warn] OpenCode models 接口不可用({err}),回退 HTML 解析", file=sys.stderr) + return _fetch_opencode_html() + + models: dict[str, dict] = {} + skipped: list[str] = [] + region_skipped: list[str] = [] + for m in payload["data"]: + mid = m.get("id") + if not mid or (m.get("type") or "chat") != "chat": + continue + if (m.get("go") or {}).get("limited_regions") or mid in OC_REGION_BLOCKED: + region_skipped.append(mid) + continue + proto, keys = _oc_protocol_from_api(m) + if proto is None: + skipped.append(f"{mid}({'/'.join(keys) or '无 api 字段'})") + continue + models[mid] = {"name": m.get("name") or mid, + "protocol": proto, + "free": _oc_is_free(m)} + + if not models: + raise RuntimeError("OpenCode models 接口返回 0 个可用模型(接口可能改版)") + OC_SKIPPED[:] = sorted(skipped) + OC_REGION_SKIPPED[:] = sorted(region_skipped) + return models + def _oc_protocol(url: str) -> str | None: """文档 Endpoint → 网关协议线;认不出返回 None。""" @@ -124,8 +217,12 @@ def _oc_protocol(url: str) -> str | None: return None -def fetch_opencode() -> dict[str, dict]: - """返回 {model_id: {name, protocol, free}}。""" +def _fetch_opencode_html() -> dict[str, dict]: + """【兜底】旧版 HTML 表解析。 + + 2026-11-19 起官方 `## Endpoints` 表已不再逐条列 URL(内容搬到 console 页 + + models 接口),这里正常不会走到;保留只为页面万一改回去时还能用。 + """ html = _get(OC_DOC_URL) models: dict[str, dict] = {} skipped: list[str] = []