diff --git a/.gitignore b/.gitignore index f07164f..9d4fe99 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,8 @@ dist/ data/calllog.db data/calllog.db-wal data/calllog.db-shm + +# 编辑器/手工备份(2026-11-01 补) +*.bak-* +*.bak +*.orig diff --git a/CHANGELOG.md b/CHANGELOG.md index eee0f7c..1f8d474 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,59 @@ # CHANGELOG +## 2026-10-31 · 新增 1min.AI 供应商(43 个模型) + +老板:「查看 https://docs.1min.ai/docs/api/openai-compatible 文档,把 1min 供应商加入 ai 网关项目里」。 + +### 接入方式 + +1min.AI 提供 **OpenAI 兼容端点**:`https://api.1min.ai/openai/v1` + +| 端点 | 用途 | +|---|---| +| `GET /openai/v1/models` | 列出可用模型(返回 id / owned_by,无上下文窗口信息)| +| `GET /openai/v1/models/{id}` | 单个模型 | +| `POST /openai/v1/chat/completions` | 对话(支持 stream)| + +鉴权:`Authorization: Bearer YOUR_1MIN_API_KEY`(1min 的 key,不是上游厂商的 key)。 + +### 落地内容 + +- `data/.env` 新增 `ONEMIN_API_KEY` +- `data/gateway.yaml` 新增 `onemin` 供应商,base_url `https://api.1min.ai/openai/v1`, + 模型清单从 `/openai/v1/models` 拉取(49 个),**剔除 6 个与 opencode 重名的** + (`qwen3.7-plus` / `deepseek-v4-pro` / `glm-5.3` / `glm-5.2` / `gpt-5.6-luna` / `gpt-6-luna`), + 避免网关告警「模型 id 被多个供应商定义,按 id 调用将始终命中 onemin」把主路由抢走。 + +### 最终模型分布(80 个) + +| 供应商 | 模型数 | +|---|---| +| **onemin** | **43** | +| opencode | 27 | +| agnes | 9 | +| dots | 1 | + +### 验证 + +```bash +# 直连 1min +curl -H "Authorization: Bearer $ONEMIN_API_KEY" https://api.1min.ai/openai/v1/models + +# 经网关 +curl -H "Authorization: Bearer <网关key>" http://127.0.0.1:8808/v1/models +curl -X POST http://127.0.0.1:8808/v1/chat/completions \ + -H "Authorization: Bearer <网关key>" -H "Content-Type: application/json" \ + -d '{"model":"qwen3.7-flash","messages":[{"role":"user","content":"你好"}]}' +``` + +实测 `qwen3.7-flash` 经网关返回「你好!」,用量正常。 + +> ⚠️ 1min 的 `/models` 不返回上下文窗口,`gateway.yaml` 里这些模型暂时没有 +> `context_window` / `max_output_tokens`,面板上会显示为空。后续如需精确值, +> 可参考各上游厂商文档手工补,或等 1min 在接口里加这个字段。 + +--- + ## 2026-10-23 · 按建议落地:WAF 自愈 / 存活监控 / 恢复演练 / 指标口径(2.9.15 → 2.9.16) 老板:「剩下的可选项有啥好的建议吗」→「按你的建议来」。 diff --git a/app/main.py b/app/main.py index 79b350c..4e1ee71 100644 --- a/app/main.py +++ b/app/main.py @@ -3883,6 +3883,29 @@ async def feedback_all(request: Request, _auth=Depends(require_auth)): return {"items": _feedback.all(), "cap": FEEDBACK_CAP} +@app.get("/feedback/pending-count") +async def feedback_pending_count(request: Request, _auth=Depends(require_auth)): + """用户反馈的待办数量(未处理 pending + 处理中 doing),给侧边栏菜单红点用。 + + 2026-10-30(老板):菜单上要显示待办数量。 + 单开一个轻量端点而不是复用 GET /feedback —— 后者会把全部条目(含图片 base64) + 一起吐出来,侧边栏每 30 秒轮询一次太浪费;这里只回三个数字。 + 已归档(archived)的不计入待办:归档 = 收件箱里收起来了。 + """ + _require_admin(request) + items = _feedback.all() + pending = doing = 0 + for it in items: + if it.get("archived"): + continue + st = it.get("status") or "pending" + if st == "pending": + pending += 1 + elif st == "doing": + doing += 1 + return {"pending": pending, "doing": doing, "total": pending + doing} + + @app.patch("/feedback/{fid}/archive") async def feedback_archive(request: Request, fid: str, _auth=Depends(require_auth)): """归档/取消归档(admin 收件箱整理用)。只打标记:不动数据、不动处理状态。""" @@ -4220,6 +4243,62 @@ async def health(request: Request, _auth=Depends(require_auth_or_open)): } +# ── OpenCode Go 套餐用量 ──────────────────────────────────────────────────── +# 2026-10-30(老板):模型与供应商页的供应商卡片要显示 OpenCode Go 套餐余量,每 10 秒刷新。 +# +# 官方文档**没有**列出这个端点 —— /v2/docs/console/api/inference 只文档了 +# /v1/chat/completions、/v1/messages、/v1/models、/v1/responses 四条线。 +# 但实测 GET {base_url}/usage 可用(2026-10-30 真实 key 验证),返回: +# {"usage":{"rolling":{"status":"ok","percent":0,"resetsAt":"..."}, +# "weekly":{"status":"ok","percent":17,"resetsAt":"..."}, +# "monthly":{"status":"ok","percent":45,"resetsAt":"..."}}} +# 三个窗口分别对应滚动窗口 / 周额度 / 月度额度。 +# +# 两个硬性要求(实测): +# · Authorization: Bearer —— 不带 → 401 AuthError +# · User-Agent 用专属标识(官方反滥用策略要求)—— 用供应商配置里的 extra_headers 那条 +# · 只支持 GET(HEAD 会 404) +# · 不需要 x-opencode-session(那个头只有推理接口才必须) +# +# 缓存 8 秒:前端 10 秒轮询一次,多开几个标签页也只打上游 ~1 次/8 秒,不烧额度。 +_OC_USAGE_CACHE: dict = {"at": 0.0, "data": None} + + +@app.get("/providers/opencode/usage") +async def opencode_go_usage(_auth=Depends(require_auth)): + """OpenCode Go 套餐用量(rolling / weekly / monthly),带 8 秒缓存。""" + now = time.time() + if _OC_USAGE_CACHE["data"] is not None and now - _OC_USAGE_CACHE["at"] < 8: + return _OC_USAGE_CACHE["data"] + + cfg = _cfg() + pconfig = cfg.providers.get("opencode") + if pconfig is None: + raise HTTPException(404, "未配置 opencode 供应商") + token = pconfig.auth.resolve_token() + if not token: + raise HTTPException(503, "OpenCode Go 未配置 API Key") + + base = str(pconfig.base_url or "https://opencode.ai/zen/go/v1").rstrip("/") + ua = (pconfig.extra_headers or {}).get("User-Agent") or f"api-gateway/{VERSION}" + try: + async with httpx.AsyncClient(timeout=10) as client: + r = await client.get( + f"{base}/usage", + headers={"Authorization": f"Bearer {token}", "User-Agent": ua}, + ) + r.raise_for_status() + data = r.json() + except httpx.HTTPStatusError as e: + raise HTTPException(502, f"OpenCode Go 用量接口返回 {e.response.status_code}") + except Exception as e: + raise HTTPException(502, f"查询 OpenCode Go 用量失败: {e}") + + _OC_USAGE_CACHE["at"] = now + _OC_USAGE_CACHE["data"] = data + return data + + @app.get("/health/{provider_key}") async def provider_health(request: Request, provider_key: str, _auth=Depends(require_auth)): # 第六轮安全审计: 本端点会用**网关持有的上游 Key** 去 GET {base_url}/models, diff --git a/data/gateway.yaml b/data/gateway.yaml index a32c054..b1b17f4 100644 --- a/data/gateway.yaml +++ b/data/gateway.yaml @@ -6,6 +6,189 @@ # 说明:本文件是项目的**唯一配置文件**(run.py 默认读取;GATEWAY_CONFIG 可覆盖)。 providers: + onemin: + name: "1min.AI" + base_url: "https://api.1min.ai/openai/v1" + auth: + token_env: "ONEMIN_API_KEY" + extra_headers: {} + # 2026-10-31 新增:1min.AI 的 OpenAI 兼容端点(https://api.1min.ai/openai/v1) + # 支持 /models、/chat/completions;聚合 OpenAI / DeepSeek / Qwen / GLM / Mistral / Kimi + # ⚠️ 与 opencode 重名的模型(glm-5.x / qwen3.7-plus / deepseek-v4-pro / gpt-5.6-luna 等) + # 已从本供应商剔除,保证 opencode 仍是主路由,不被 onemin 抢占。 + models: + - id: "qwen3.7-max" + display_name: "Qwen3.7-max" + type: "text" + protocols: ["chat/completions"] + - id: "qwen3.7-flash" + display_name: "Qwen3.7-flash" + type: "text" + protocols: ["chat/completions"] + - id: "qwen3.6-plus" + display_name: "Qwen3.6-plus" + type: "text" + protocols: ["chat/completions"] + - id: "qwen3.6-flash" + display_name: "Qwen3.6-flash" + type: "text" + protocols: ["chat/completions"] + - id: "qwen-plus" + display_name: "Qwen-plus" + type: "text" + protocols: ["chat/completions"] + - id: "qwen-max" + display_name: "Qwen-max" + type: "text" + protocols: ["chat/completions"] + - id: "qwen-flash" + display_name: "Qwen-flash" + type: "text" + protocols: ["chat/completions"] + - id: "deepseek-flash" + display_name: "DeepSeek-flash" + type: "text" + protocols: ["chat/completions"] + - id: "magistral-small-latest" + display_name: "Magistral-small-latest" + type: "text" + protocols: ["chat/completions"] + - id: "magistral-medium-latest" + display_name: "Magistral-medium-latest" + type: "text" + protocols: ["chat/completions"] + - id: "ministral-14b-latest" + display_name: "Ministral-14b-latest" + type: "text" + protocols: ["chat/completions"] + - id: "open-mistral-nemo" + display_name: "Open Mistral-nemo" + type: "text" + protocols: ["chat/completions"] + - id: "mistral-small-latest" + display_name: "Mistral-small-latest" + type: "text" + protocols: ["chat/completions"] + - id: "mistral-small-2603" + display_name: "Mistral-small-2603" + type: "text" + protocols: ["chat/completions"] + - id: "mistral-medium-latest" + display_name: "Mistral-medium-latest" + type: "text" + protocols: ["chat/completions"] + - id: "mistral-medium-3-5" + display_name: "Mistral-medium-3-5" + type: "text" + protocols: ["chat/completions"] + - id: "mistral-large-latest" + display_name: "Mistral-large-latest" + type: "text" + protocols: ["chat/completions"] + - id: "mistral-large-2512" + display_name: "Mistral-large-2512" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-6-sol" + display_name: "GPT-6-sol" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-6-astra" + display_name: "GPT-6-astra" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.6-terra" + display_name: "GPT-5.6-terra" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.6-sol" + display_name: "GPT-5.6-sol" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.5" + display_name: "GPT-5.5" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.4-nano" + display_name: "GPT-5.4-nano" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.4-mini" + display_name: "GPT-5.4-mini" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.4" + display_name: "GPT-5.4" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.2" + display_name: "GPT-5.2" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5.1" + display_name: "GPT-5.1" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5-nano" + display_name: "GPT-5-nano" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5-mini" + display_name: "GPT-5-mini" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-5" + display_name: "GPT-5" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-4o-mini" + display_name: "GPT-4o-mini" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-4o" + display_name: "GPT-4o" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-4.1-mini" + display_name: "GPT-4.1-mini" + type: "text" + protocols: ["chat/completions"] + - id: "gpt-4.1" + display_name: "GPT-4.1" + type: "text" + protocols: ["chat/completions"] + - id: "o3" + display_name: "o3" + type: "text" + protocols: ["chat/completions"] + - id: "moonshotai/kimi-k2.7-code" + display_name: "Moonshot kimi-k2.7-code" + type: "text" + protocols: ["chat/completions"] + - id: "moonshotai/kimi-k2.6" + display_name: "Moonshot kimi-k2.6" + type: "text" + protocols: ["chat/completions"] + - id: "meta/muse-spark-1.3" + display_name: "Meta muse-spark-1.3" + type: "text" + protocols: ["chat/completions"] + - id: "meta/muse-spark-1.2" + display_name: "Meta muse-spark-1.2" + type: "text" + protocols: ["chat/completions"] + - id: "meta/muse-spark-1.1" + display_name: "Meta muse-spark-1.1" + type: "text" + protocols: ["chat/completions"] + - id: "glm-5.1" + display_name: "GLM-5.1" + type: "text" + protocols: ["chat/completions"] + - id: "glm-5" + display_name: "GLM-5" + type: "text" + protocols: ["chat/completions"] agnes: name: "Agnes AI" base_url: "https://api.agnes-ai.cn/v1" @@ -280,14 +463,6 @@ providers: # 2026-09-21 新增;实测 responses 200(官方文档表同样标 responses) protocols: ["responses"] # 2026-09-27 自动同步:官方文档新增(scripts/sync_models.py) - - id: "longcat-2.5-preview-free" - display_name: "Longcat 2.5 Preview Free" - type: "text" - context_window: 1000000 # 同步 2026-09-28(scripts/sync_models.py) - max_output_tokens: 131072 # 同步 2026-09-28(scripts/sync_models.py) - # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) - protocols: ["chat/completions"] - free: true # 官方价格表标 Free # 2026-10-07 自动同步:官方文档新增(scripts/sync_models.py) # 2026-10-08 自动同步:官方文档新增(scripts/sync_models.py) - id: "claude-haiku-5-5" @@ -311,8 +486,27 @@ providers: - id: "minimax-m3.1-flash" display_name: "Minimax M3.1 Flash" type: "text" + context_window: 1000000 # 同步 2026-10-24(scripts/sync_models.py) + max_output_tokens: 512000 # 同步 2026-10-24(scripts/sync_models.py) # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) protocols: ["chat/completions"] + # 2026-10-24 自动同步:官方文档新增(scripts/sync_models.py) + - id: "kimi-k3.1-pro" + 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) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["chat/completions"] + # 2026-10-27 自动同步:官方文档新增(scripts/sync_models.py) + - id: "iceman-contributor-free" + display_name: "Iceman Contributor Free" + type: "text" + context_window: 262144 # 同步 2026-10-28(scripts/sync_models.py) + max_output_tokens: 131072 # 同步 2026-10-28(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["chat/completions"] + free: true # 官方价格表标 Free # 2026-10-09 自动同步:官方文档新增(scripts/sync_models.py) # ── Dots AI(小红书 Dots Studio,第三十六轮新增)────────────── # 官方文档:https://dots.ai/platform/docs(2026-09-28 通读) diff --git a/frontend/src/layouts/SideNav.vue b/frontend/src/layouts/SideNav.vue index 87de86f..b736514 100644 --- a/frontend/src/layouts/SideNav.vue +++ b/frontend/src/layouts/SideNav.vue @@ -22,6 +22,10 @@ > {{ t(`nav.menu${m.key}`) }} + + {{ todoCount > 99 ? '99+' : todoCount }} @@ -29,9 +33,11 @@