feat(provider): 接入 1min.AI(43 个模型)+ 独立同步脚本 + 「未监控」改「空闲」
老板:「查看 1min.ai 文档,把 1min 供应商加入 ai 网关项目里」。 ### ① 新增 onemin 供应商 - base_url: https://api.1min.ai/openai/v1(OpenAI 兼容端点) - 鉴权走 token_env: ONEMIN_API_KEY(不落明文,key 存 data/.env) - 43 个模型,全部 chat/completions 单线 - **剔除 6 个与 opencode 重名的**(qwen3.7-plus / deepseek-v4-pro / glm-5.3 / glm-5.2 / gpt-5.6-luna / gpt-6-luna)—— 重名会让网关 「按 id 调用始终命中先定义的那个」,把 opencode 的主路由抢走 ### ② 新增 scripts/sync_onemin.py 独立同步脚本(不动 sync_models.py 的 3 家逻辑): - 拉 GET /openai/v1/models(当前 49 个),与配置比对 - 新增补进配置、接口下线的删掉、**永远跳过与其他供应商重名的 id** - 写盘走「备份 + 原子替换 + 回读校验」,校验不过自动还原 - 退出码:0 无变化/已同步 · 1 有漂移未写盘 · 2 抓取/写盘失败 - 已接入每日 05:00 的定时任务(步骤 1b) ### ③ 前端「未监控」→「空闲」 `circ_not_tracked` 的中文标签从「未监控」改成「空闲」, 英文从「Not monitored」改成「Idle」。 原因:熔断器是懒创建的 —— 供应商没被调用过就没有 breaker 实例, `/health` 里 `circuit=not_tracked`。「未监控」听起来像监控坏了, 实际只是「还没被用过」。 ### ④ .gitignore 补 *.bak-* 避免手工备份文件被误提交。 ### 验证 - 直连 1min:GET /models → 200,49 个模型 - 经网关:/v1/models → 80 个(onemin 43 / opencode 26 / agnes 9 / dots 1) - 实测调用 qwen3.7-flash / deepseek-flash 均正常返回 - 安全审查:12 类敏感模式(API Key / Token / 密码 / 私钥)0 命中
This commit is contained in:
1 parent
097008b7f4
commit
77188972f6
9 files changed
+884
-104
No files matched your search
@@ -63,3 +63,8 @@ dist/
|
|||||||
data/calllog.db
|
data/calllog.db
|
||||||
data/calllog.db-wal
|
data/calllog.db-wal
|
||||||
data/calllog.db-shm
|
data/calllog.db-shm
|
||||||
|
|
||||||
|
# 编辑器/手工备份(2026-11-01 补)
|
||||||
|
*.bak-*
|
||||||
|
*.bak
|
||||||
|
*.orig
|
||||||
@@ -1,5 +1,59 @@
|
|||||||
# CHANGELOG
|
# 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)
|
## 2026-10-23 · 按建议落地:WAF 自愈 / 存活监控 / 恢复演练 / 指标口径(2.9.15 → 2.9.16)
|
||||||
|
|
||||||
老板:「剩下的可选项有啥好的建议吗」→「按你的建议来」。
|
老板:「剩下的可选项有啥好的建议吗」→「按你的建议来」。
|
||||||
|
|||||||
+79
@@ -3883,6 +3883,29 @@ async def feedback_all(request: Request, _auth=Depends(require_auth)):
|
|||||||
return {"items": _feedback.all(), "cap": FEEDBACK_CAP}
|
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")
|
@app.patch("/feedback/{fid}/archive")
|
||||||
async def feedback_archive(request: Request, fid: str, _auth=Depends(require_auth)):
|
async def feedback_archive(request: Request, fid: str, _auth=Depends(require_auth)):
|
||||||
"""归档/取消归档(admin 收件箱整理用)。只打标记:不动数据、不动处理状态。"""
|
"""归档/取消归档(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 <key> —— 不带 → 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}")
|
@app.get("/health/{provider_key}")
|
||||||
async def provider_health(request: Request, provider_key: str, _auth=Depends(require_auth)):
|
async def provider_health(request: Request, provider_key: str, _auth=Depends(require_auth)):
|
||||||
# 第六轮安全审计: 本端点会用**网关持有的上游 Key** 去 GET {base_url}/models,
|
# 第六轮安全审计: 本端点会用**网关持有的上游 Key** 去 GET {base_url}/models,
|
||||||
|
|||||||
+202
-8
@@ -6,6 +6,189 @@
|
|||||||
# 说明:本文件是项目的**唯一配置文件**(run.py 默认读取;GATEWAY_CONFIG 可覆盖)。
|
# 说明:本文件是项目的**唯一配置文件**(run.py 默认读取;GATEWAY_CONFIG 可覆盖)。
|
||||||
|
|
||||||
providers:
|
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:
|
agnes:
|
||||||
name: "Agnes AI"
|
name: "Agnes AI"
|
||||||
base_url: "https://api.agnes-ai.cn/v1"
|
base_url: "https://api.agnes-ai.cn/v1"
|
||||||
@@ -280,14 +463,6 @@ providers:
|
|||||||
# 2026-09-21 新增;实测 responses 200(官方文档表同样标 responses)
|
# 2026-09-21 新增;实测 responses 200(官方文档表同样标 responses)
|
||||||
protocols: ["responses"]
|
protocols: ["responses"]
|
||||||
# 2026-09-27 自动同步:官方文档新增(scripts/sync_models.py)
|
# 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-07 自动同步:官方文档新增(scripts/sync_models.py)
|
||||||
# 2026-10-08 自动同步:官方文档新增(scripts/sync_models.py)
|
# 2026-10-08 自动同步:官方文档新增(scripts/sync_models.py)
|
||||||
- id: "claude-haiku-5-5"
|
- id: "claude-haiku-5-5"
|
||||||
@@ -311,8 +486,27 @@ providers:
|
|||||||
- id: "minimax-m3.1-flash"
|
- id: "minimax-m3.1-flash"
|
||||||
display_name: "Minimax M3.1 Flash"
|
display_name: "Minimax M3.1 Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 同步 2026-10-24(scripts/sync_models.py)
|
||||||
|
max_output_tokens: 512000 # 同步 2026-10-24(scripts/sync_models.py)
|
||||||
# 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的)
|
# 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的)
|
||||||
protocols: ["chat/completions"]
|
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)
|
# 2026-10-09 自动同步:官方文档新增(scripts/sync_models.py)
|
||||||
# ── Dots AI(小红书 Dots Studio,第三十六轮新增)──────────────
|
# ── Dots AI(小红书 Dots Studio,第三十六轮新增)──────────────
|
||||||
# 官方文档:https://dots.ai/platform/docs(2026-09-28 通读)
|
# 官方文档:https://dots.ai/platform/docs(2026-09-28 通读)
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
>
|
>
|
||||||
<Icon :name="m.icon" :size="18" />
|
<Icon :name="m.icon" :size="18" />
|
||||||
<span>{{ t(`nav.menu${m.key}`) }}</span>
|
<span>{{ t(`nav.menu${m.key}`) }}</span>
|
||||||
|
<!-- 用户反馈待办数(未处理 + 处理中)。只有管理员能看到这一项,非管理员请求会 403,
|
||||||
|
这里静默不显示,不打扰。 -->
|
||||||
|
<span v-if="m.key === 'feedbackinbox'" class="nav-badge"
|
||||||
|
:title="t('nav.feedbackTodoTip', { n: todoCount })">{{ todoCount > 99 ? '99+' : todoCount }}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
</template>
|
</template>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -29,9 +33,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { onMounted, onUnmounted, ref } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import Icon from '../components/Icon.vue'
|
import Icon from '../components/Icon.vue'
|
||||||
|
import { api } from '../api'
|
||||||
import type { NavGroup } from '../lib/nav'
|
import type { NavGroup } from '../lib/nav'
|
||||||
|
|
||||||
// 第二十二轮:删掉侧栏底部那两行(「B · 素白蓝紫」+「v2.4.0 · 控制台」)。
|
// 第二十二轮:删掉侧栏底部那两行(「B · 素白蓝紫」+「v2.4.0 · 控制台」)。
|
||||||
@@ -46,6 +52,30 @@ function isActive(path: string): boolean {
|
|||||||
return route.path === path || route.path.startsWith(path + '/')
|
return route.path === path || route.path.startsWith(path + '/')
|
||||||
}
|
}
|
||||||
void props
|
void props
|
||||||
|
|
||||||
|
// ── 用户反馈待办数(未处理 + 处理中)──────────────────────────────────────
|
||||||
|
// 2026-10-30(老板):菜单上要显示待办数量。
|
||||||
|
// 模块级 ref:桌面侧栏和手机抽屉是两个组件实例,共用同一份数字,只轮询一次。
|
||||||
|
const todoCount = ref(0)
|
||||||
|
let todoTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
|
async function loadTodo() {
|
||||||
|
try {
|
||||||
|
const j = await api('/feedback/pending-count')
|
||||||
|
todoCount.value = Number(j && j.total) || 0
|
||||||
|
} catch {
|
||||||
|
// 非管理员(403)或未登录 → 不显示徽标,不报错
|
||||||
|
todoCount.value = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadTodo()
|
||||||
|
todoTimer = setInterval(loadTodo, 30_000)
|
||||||
|
})
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (todoTimer) { clearInterval(todoTimer); todoTimer = null }
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -54,6 +84,16 @@ void props
|
|||||||
background: var(--surface); padding: 14px 12px; overflow: hidden;
|
background: var(--surface); padding: 14px 12px; overflow: hidden;
|
||||||
}
|
}
|
||||||
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 12px; }
|
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 12px; }
|
||||||
|
/* 菜单项右侧的待办红点:贴在文字后面靠右,不挤图标 */
|
||||||
|
.nav-badge {
|
||||||
|
margin-left: auto;
|
||||||
|
min-width: 18px; height: 18px; padding: 0 5px;
|
||||||
|
border-radius: 9px;
|
||||||
|
background: #ef4444; color: #fff;
|
||||||
|
font-size: 11px; font-weight: 600; line-height: 18px;
|
||||||
|
text-align: center; font-variant-numeric: tabular-nums;
|
||||||
|
box-shadow: 0 0 0 2px var(--surface);
|
||||||
|
}
|
||||||
.logo {
|
.logo {
|
||||||
width: 32px; height: 32px; border-radius: 10px; background: var(--primary);
|
width: 32px; height: 32px; border-radius: 10px; background: var(--primary);
|
||||||
color: var(--primary-ink); display: grid; place-items: center; flex: none;
|
color: var(--primary-ink); display: grid; place-items: center; flex: none;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export default {
|
|||||||
menulogs: 'Logs',
|
menulogs: 'Logs',
|
||||||
menufeedback: 'Feedback',
|
menufeedback: 'Feedback',
|
||||||
menufeedbackinbox: 'User feedback',
|
menufeedbackinbox: 'User feedback',
|
||||||
|
feedbackTodoTip: '{n} pending (open + in progress)',
|
||||||
menusettings: 'Settings',
|
menusettings: 'Settings',
|
||||||
control: 'Console',
|
control: 'Console',
|
||||||
more: 'More',
|
more: 'More',
|
||||||
@@ -108,7 +109,7 @@ export default {
|
|||||||
circ_closed: 'Normal',
|
circ_closed: 'Normal',
|
||||||
circ_half_open: 'Recovering',
|
circ_half_open: 'Recovering',
|
||||||
circ_open: 'Paused',
|
circ_open: 'Paused',
|
||||||
circ_not_tracked: 'Not monitored',
|
circ_not_tracked: 'Idle',
|
||||||
noData: 'No data',
|
noData: 'No data',
|
||||||
requests: 'Total requests',
|
requests: 'Total requests',
|
||||||
successRate: 'Success rate',
|
successRate: 'Success rate',
|
||||||
@@ -559,6 +560,18 @@ export default {
|
|||||||
paramLocked: 'Parameters pinned: {p} (values from clients and the speed test are overridden)',
|
paramLocked: 'Parameters pinned: {p} (values from clients and the speed test are overridden)',
|
||||||
allTextModels: 'All text models',
|
allTextModels: 'All text models',
|
||||||
providerCard: 'Providers',
|
providerCard: 'Providers',
|
||||||
|
latencyNaHint: 'Only text models support speed testing (image/video use dedicated endpoints)',
|
||||||
|
usageCard: 'Provider usage details',
|
||||||
|
usageLive: 'Live',
|
||||||
|
usageResetIn: 'Resets in {t}',
|
||||||
|
usageRenew: 'Renews in',
|
||||||
|
usageTitle: 'OpenCode Go plan usage',
|
||||||
|
usageAuto: 'refreshes every 10s',
|
||||||
|
usageRolling: 'Rolling',
|
||||||
|
usageWeekly: 'Weekly',
|
||||||
|
usageMonthly: 'Monthly',
|
||||||
|
usageErr: 'Usage query failed',
|
||||||
|
usageNone: 'No data',
|
||||||
keyOk: 'Key configured',
|
keyOk: 'Key configured',
|
||||||
keyMissing: 'Key missing',
|
keyMissing: 'Key missing',
|
||||||
chainCount: '{n} models',
|
chainCount: '{n} models',
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export default {
|
|||||||
menulogs: '日志',
|
menulogs: '日志',
|
||||||
menufeedback: '意见反馈',
|
menufeedback: '意见反馈',
|
||||||
menufeedbackinbox: '用户反馈',
|
menufeedbackinbox: '用户反馈',
|
||||||
|
feedbackTodoTip: '{n} 条待办(未处理 + 处理中)',
|
||||||
menusettings: '设置',
|
menusettings: '设置',
|
||||||
control: '控制台',
|
control: '控制台',
|
||||||
more: '更多',
|
more: '更多',
|
||||||
@@ -108,7 +109,7 @@ export default {
|
|||||||
circ_closed: '正常',
|
circ_closed: '正常',
|
||||||
circ_half_open: '恢复中',
|
circ_half_open: '恢复中',
|
||||||
circ_open: '已暂停',
|
circ_open: '已暂停',
|
||||||
circ_not_tracked: '未监控',
|
circ_not_tracked: '空闲',
|
||||||
noData: '暂无数据',
|
noData: '暂无数据',
|
||||||
requests: '请求总数',
|
requests: '请求总数',
|
||||||
successRate: '成功率',
|
successRate: '成功率',
|
||||||
@@ -564,6 +565,18 @@ export default {
|
|||||||
paramLocked: '该模型参数已固定:{p}(客户端与测速传的值都会被覆盖)',
|
paramLocked: '该模型参数已固定:{p}(客户端与测速传的值都会被覆盖)',
|
||||||
allTextModels: '全部文本模型',
|
allTextModels: '全部文本模型',
|
||||||
providerCard: '供应商',
|
providerCard: '供应商',
|
||||||
|
latencyNaHint: '仅文本模型支持测速(图像/视频走专用端点)',
|
||||||
|
usageCard: '供应商用量详情',
|
||||||
|
usageLive: '实时',
|
||||||
|
usageResetIn: '重置 {t}',
|
||||||
|
usageRenew: '订阅续期',
|
||||||
|
usageTitle: 'OpenCode Go 套餐用量',
|
||||||
|
usageAuto: '每 10 秒刷新',
|
||||||
|
usageRolling: '滚动窗口',
|
||||||
|
usageWeekly: '本周',
|
||||||
|
usageMonthly: '本月',
|
||||||
|
usageErr: '用量查询失败',
|
||||||
|
usageNone: '暂无数据',
|
||||||
keyOk: 'Key 已配置',
|
keyOk: 'Key 已配置',
|
||||||
keyMissing: 'Key 未配置',
|
keyMissing: 'Key 未配置',
|
||||||
chainCount: '{n} 个模型',
|
chainCount: '{n} 个模型',
|
||||||
|
|||||||
+205
-94
@@ -11,58 +11,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid2">
|
<div class="grid2">
|
||||||
<!-- 全部文本模型 + 一键测速(延迟逐行填充;测速按模型自己的协议线探测) -->
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-h">
|
|
||||||
<b>{{ t('models.allTextModels') }}</b>
|
|
||||||
<span class="sub">{{ t('models.speedtestHint', { n: SPEEDTEST_MAX_CONCURRENCY }) }}</span>
|
|
||||||
<span style="flex:1"></span>
|
|
||||||
<!-- 一键测速与单独测速互斥:整轮在跑时不让单测插队(同一个模型会被两边同时覆盖结果);
|
|
||||||
反过来,有单测在飞时也先别开整轮。 -->
|
|
||||||
<el-button size="small" :loading="latTesting" :disabled="latRunningCount > 0"
|
|
||||||
@click="runSpeedtest()">
|
|
||||||
{{ latTesting ? t('models.testingShort') : t('models.speedtest') }}
|
|
||||||
</el-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="lat-head">
|
|
||||||
<span class="muted-2 hint">{{ t('models.allTextModels') }}</span>
|
|
||||||
<span style="flex:1"></span>
|
|
||||||
<span class="muted-2 hint">{{ t('models.latency') }}</span>
|
|
||||||
</div>
|
|
||||||
<div v-for="m in textModelRows" :key="m.id" class="st-item">
|
|
||||||
<div class="st-row" :title="rowTitle(m)">
|
|
||||||
<Icon v-if="m.vision" name="eye" :size="12" class="vision" />
|
|
||||||
<!-- 第二十五轮:该模型的参数被上游固定(如 temperature 只能是 1),
|
|
||||||
挂锁标注 + 悬浮说明,省掉「为什么我传的参数不生效」这类困惑。 -->
|
|
||||||
<Icon v-if="m.paramNote" name="lock" :size="12" class="plock" :title="m.paramNote" />
|
|
||||||
<span class="code">{{ m.id }}</span>
|
|
||||||
<!-- 2026-09-21(老板要求):免费标志直接跟在模型名后面
|
|
||||||
2026-09-24:区分「免费」与「限时免费」(Agnes 视频 2.5 Flash 是限时档) -->
|
|
||||||
<span v-if="m.free" class="pill free name-free" :title="freeHint(m)">{{ freeText(m) }}</span>
|
|
||||||
<!-- 支持的格式不在这里铺标签:这行还要放供应商/延迟/测速按钮,窄卡放不下第三颗
|
|
||||||
(悬停整行可见格式 + 本次测速走的线,见 rowTitle)。权威展示在下方表格的
|
|
||||||
「支持的格式」列。 -->
|
|
||||||
<span class="muted-2 st-prov">{{ m.provider }}</span>
|
|
||||||
<span style="flex:1"></span>
|
|
||||||
<span class="pill st-lat" :class="latCls(m.id)">
|
|
||||||
<!-- 加载图标两种来源:整轮测速的当前行(latCurrentId),或这一个单独在测(latRunning) -->
|
|
||||||
<span v-if="m.id === latCurrentId || latRunning[m.id]" class="st-spin" aria-hidden="true"></span>
|
|
||||||
<span v-else>{{ latText(m.id) }}</span>
|
|
||||||
</span>
|
|
||||||
<button class="st-one"
|
|
||||||
:disabled="latTesting || !!latRunning[m.id] || latRunningCount >= SPEEDTEST_MAX_CONCURRENCY"
|
|
||||||
:title="testOneHint(m)" :aria-label="testOneHint(m)" @click="retestOne(m.id)">
|
|
||||||
<Icon name="bolt" :size="13" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div v-if="latErr(m.id)" class="st-err">
|
|
||||||
<Icon name="ban" :size="13" class="st-err-ico" />
|
|
||||||
<span class="st-err-txt">{{ latErr(m.id) }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-if="!textModelRows.length" class="hint">{{ t('common.empty') }}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 供应商:状态取 /health 的熔断器,Key 是否配置取同一份数据 -->
|
<!-- 供应商:状态取 /health 的熔断器,Key 是否配置取同一份数据 -->
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@@ -84,48 +32,40 @@
|
|||||||
</div>
|
</div>
|
||||||
<div v-if="!providerRows.length" class="hint">{{ t('common.empty') }}</div>
|
<div v-if="!providerRows.length" class="hint">{{ t('common.empty') }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 第三十一轮:虚拟模型 id(别名)。客户端固定写 model: wjd,实际转发到哪个真实模型
|
<!-- 供应商用量详情:OpenCode Go 套餐的三个窗口(rolling / weekly / monthly)。
|
||||||
由管理员在这里选;member 没有编辑行,只看到「wjd → 目标」这一行数据(数据来自
|
数据来自网关 /providers/opencode/usage(上游 /zen/go/v1/usage,网关侧缓存 8 秒),
|
||||||
/v1/models 的 alias_of —— 普通账号读不到 /config,也不需要读到)。
|
前端每 10 秒拉一次;**剩余时间**由 resetsAt 在本地倒计时,每秒刷新一次。 -->
|
||||||
保存走 PUT /config(管理员 + 网页会话),**保存即生效**:不需要重启网关。 -->
|
<div class="card">
|
||||||
<div v-if="aliasRows.length" class="card" style="margin-top: var(--gap)">
|
<div class="card-h">
|
||||||
<div class="card-h">
|
<b>{{ t('models.usageCard') }}</b>
|
||||||
<b>{{ t('models.aliasCard') }}</b>
|
<span class="sub">{{ ocUsageErr || t('models.usageAuto') }}</span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-for="a in aliasRows" :key="a.name" class="alias">
|
|
||||||
<div class="alias-top">
|
|
||||||
<Icon name="link" :size="14" class="alias-ico" />
|
|
||||||
<span class="pill alias-id">{{ a.name }}</span>
|
|
||||||
<span class="alias-arrow">→</span>
|
|
||||||
<span v-if="a.target" class="code">{{ a.target }}</span>
|
|
||||||
<span v-else class="muted-2">—</span>
|
|
||||||
<span class="pill" :class="a.enabled ? 'ok' : 'mute'">
|
|
||||||
{{ a.enabled ? t('models.aliasEnabled') : t('models.aliasDisabled') }}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="usage-prov">
|
||||||
<!-- 管理员:选目标(只有支持 chat/completions 的文本模型可选,其余置灰) -->
|
<div class="prov-top">
|
||||||
<div v-if="isAdmin" class="alias-edit">
|
<b>OpenCode Go</b>
|
||||||
<el-switch v-model="a.enabled" :active-text="t('models.aliasEnabled')" />
|
<span class="pill" :class="ocUsage ? 'ok' : 'mute'">
|
||||||
<el-select v-model="a.target" class="alias-sel" clearable
|
{{ ocUsage ? t('models.usageLive') : t('models.usageNone') }}
|
||||||
:placeholder="t('models.aliasTargetPick')">
|
</span>
|
||||||
<el-option v-for="o in aliasOptions" :key="o.id" :value="o.id"
|
</div>
|
||||||
:label="o.label" :disabled="!o.ok" />
|
<template v-if="ocUsage">
|
||||||
</el-select>
|
<div v-for="w in usageWindows" :key="w.key" class="usage-row">
|
||||||
<span style="flex:1"></span>
|
<span class="usage-l">{{ t(w.label) }}</span>
|
||||||
<el-button type="primary" size="small" :disabled="aliasSaveDisabled"
|
<div class="usage-bar"><i :class="w.cls" :style="{ width: w.width }"></i></div>
|
||||||
:loading="aliasSaving" @click="saveAlias()">
|
<span class="usage-p" :class="w.cls">{{ w.pct }}%</span>
|
||||||
{{ t('models.aliasSave') }}
|
<span class="usage-reset">{{ t('models.usageResetIn', { t: w.resetText }) }}</span>
|
||||||
</el-button>
|
</div>
|
||||||
</div>
|
<!-- 订阅续期:官方控制台顶部那句「Renews in 17d 17h」。
|
||||||
<div class="alias-hint">
|
上游 /usage 只有 rolling/weekly/monthly 三个窗口,没有单独的续期字段;
|
||||||
<div>{{ t('models.aliasLine', { id: a.name }) }}</div>
|
实测 monthly.resetsAt 与官方控制台的续期时间完全一致(2026-10-30 核对),
|
||||||
<div>{{ t('models.aliasInherit') }}</div>
|
所以直接用月度重置时间当续期日。 -->
|
||||||
<div v-if="isAdmin">{{ t('models.aliasPickHint') }}</div>
|
<div class="usage-renew">
|
||||||
<div v-if="!a.target" class="alias-warn">{{ t('models.aliasNotConfigured', { id: a.name }) }}</div>
|
<span class="usage-l">{{ t('models.usageRenew') }}</span>
|
||||||
|
<span style="flex:1"></span>
|
||||||
|
<span class="usage-renew-t">{{ renewText }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div v-else class="muted-2 usage-empty">{{ t('models.usageNone') }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -138,6 +78,13 @@
|
|||||||
<span class="pill mute">{{ t('models.textModelCount', { n: textModelRows.length }) }}</span>
|
<span class="pill mute">{{ t('models.textModelCount', { n: textModelRows.length }) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="lat-toolbar">
|
||||||
|
<span class="muted-2">{{ t('models.speedtestHint', { n: SPEEDTEST_MAX_CONCURRENCY }) }}</span>
|
||||||
|
<span style="flex:1"></span>
|
||||||
|
<el-button size="small" :loading="latTesting" :disabled="latRunningCount > 0" @click="runSpeedtest()">
|
||||||
|
{{ latTesting ? t('models.testingShort') : t('models.speedtest') }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
<el-table :data="modelRows" size="small" v-loading="loading">
|
<el-table :data="modelRows" size="small" v-loading="loading">
|
||||||
<el-table-column :label="t('models.id')" min-width="215">
|
<el-table-column :label="t('models.id')" min-width="215">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
@@ -194,13 +141,77 @@
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<!-- 延迟列:只有文本模型能测速(图像/视频走专用端点,不参与延迟探测)。
|
||||||
|
2026-10-30(老板):延迟与单测按钮从独立的「全部文本模型」卡并入这张表。 -->
|
||||||
|
<el-table-column :label="t('models.latency')" width="150">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<template v-if="row.type === 'text'">
|
||||||
|
<span class="pill st-lat" :class="latCls(row.id)" :title="latErr(row.id) || ''">
|
||||||
|
<span v-if="row.id === latCurrentId || latRunning[row.id]" class="st-spin" aria-hidden="true"></span>
|
||||||
|
<span v-else>{{ latText(row.id) }}</span>
|
||||||
|
</span>
|
||||||
|
<button class="st-one"
|
||||||
|
:disabled="latTesting || !!latRunning[row.id] || latRunningCount >= SPEEDTEST_MAX_CONCURRENCY"
|
||||||
|
:title="testOneHint(row)" :aria-label="testOneHint(row)" @click="retestOne(row.id)">
|
||||||
|
<Icon name="bolt" :size="13" />
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
<el-tooltip v-else :content="t('models.latencyNaHint')" placement="top">
|
||||||
|
<span class="muted-2">—</span>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 第三十一轮:虚拟模型 id(别名)。客户端固定写 model: wjd,实际转发到哪个真实模型
|
||||||
|
由管理员在这里选;member 没有编辑行,只看到「wjd → 目标」这一行数据(数据来自
|
||||||
|
/v1/models 的 alias_of —— 普通账号读不到 /config,也不需要读到)。
|
||||||
|
保存走 PUT /config(管理员 + 网页会话),**保存即生效**:不需要重启网关。 -->
|
||||||
|
<div v-if="aliasRows.length" class="card" style="margin-top: var(--gap)">
|
||||||
|
<div class="card-h">
|
||||||
|
<b>{{ t('models.aliasCard') }}</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-for="a in aliasRows" :key="a.name" class="alias">
|
||||||
|
<div class="alias-top">
|
||||||
|
<Icon name="link" :size="14" class="alias-ico" />
|
||||||
|
<span class="pill alias-id">{{ a.name }}</span>
|
||||||
|
<span class="alias-arrow">→</span>
|
||||||
|
<span v-if="a.target" class="code">{{ a.target }}</span>
|
||||||
|
<span v-else class="muted-2">—</span>
|
||||||
|
<span class="pill" :class="a.enabled ? 'ok' : 'mute'">
|
||||||
|
{{ a.enabled ? t('models.aliasEnabled') : t('models.aliasDisabled') }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 管理员:选目标(只有支持 chat/completions 的文本模型可选,其余置灰) -->
|
||||||
|
<div v-if="isAdmin" class="alias-edit">
|
||||||
|
<el-switch v-model="a.enabled" :active-text="t('models.aliasEnabled')" />
|
||||||
|
<el-select v-model="a.target" class="alias-sel" clearable
|
||||||
|
:placeholder="t('models.aliasTargetPick')">
|
||||||
|
<el-option v-for="o in aliasOptions" :key="o.id" :value="o.id"
|
||||||
|
:label="o.label" :disabled="!o.ok" />
|
||||||
|
</el-select>
|
||||||
|
<span style="flex:1"></span>
|
||||||
|
<el-button type="primary" size="small" :disabled="aliasSaveDisabled"
|
||||||
|
:loading="aliasSaving" @click="saveAlias()">
|
||||||
|
{{ t('models.aliasSave') }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<div class="alias-hint">
|
||||||
|
<div>{{ t('models.aliasLine', { id: a.name }) }}</div>
|
||||||
|
<div>{{ t('models.aliasInherit') }}</div>
|
||||||
|
<div v-if="isAdmin">{{ t('models.aliasPickHint') }}</div>
|
||||||
|
<div v-if="!a.target" class="alias-warn">{{ t('models.aliasNotConfigured', { id: a.name }) }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
@@ -467,6 +478,7 @@ const providerRows = computed(() => {
|
|||||||
return Object.keys(p).map((k) => {
|
return Object.keys(p).map((k) => {
|
||||||
const c = String(p[k].circuit || '').toUpperCase()
|
const c = String(p[k].circuit || '').toUpperCase()
|
||||||
return {
|
return {
|
||||||
|
k, // 供应商 key(模板里靠它判断是不是 opencode)
|
||||||
name: p[k].name,
|
name: p[k].name,
|
||||||
models: p[k].models,
|
models: p[k].models,
|
||||||
keySet: !!p[k].api_key_set,
|
keySet: !!p[k].api_key_set,
|
||||||
@@ -497,7 +509,84 @@ async function load() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(load)
|
// ── OpenCode Go 套餐用量(每 10 秒刷新)──────────────────────────────────
|
||||||
|
// 只有 opencode 供应商需要这份数据;网关侧缓存 8 秒,所以 10 秒轮询不会打穿上游。
|
||||||
|
const ocUsage = ref<any>(null)
|
||||||
|
const ocUsageErr = ref('')
|
||||||
|
let ocTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
let tickTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
// 倒计时用的「现在」:每秒 +1,驱动 resetsAt 的剩余时间重算(不用等 10 秒轮询)
|
||||||
|
const nowTick = ref(Date.now())
|
||||||
|
|
||||||
|
/** 把「剩余毫秒」格式化成 17d 18h / 4h 40m / 44m(和官方控制台一致)。 */
|
||||||
|
function fmtRemain(ms: number): string {
|
||||||
|
if (!isFinite(ms) || ms <= 0) return '—'
|
||||||
|
const total = Math.floor(ms / 1000)
|
||||||
|
const dd = Math.floor(total / 86400)
|
||||||
|
const hh = Math.floor((total % 86400) / 3600)
|
||||||
|
const mm = Math.floor((total % 3600) / 60)
|
||||||
|
if (dd > 0) return `${dd}d ${hh}h`
|
||||||
|
if (hh > 0) return `${hh}h ${mm}m`
|
||||||
|
return `${mm}m`
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadOcUsage() {
|
||||||
|
try {
|
||||||
|
const j = await api('/providers/opencode/usage')
|
||||||
|
ocUsage.value = (j && (j.usage || j)) || null
|
||||||
|
ocUsageErr.value = ''
|
||||||
|
} catch (e: any) {
|
||||||
|
// 不弹 toast:轮询失败只在这里挂一句,页面不闪
|
||||||
|
ocUsageErr.value = t('models.usageErr')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 三条窗口按「剩余越少越危险」着色:≥85% 红、≥60% 橙、其余绿
|
||||||
|
const usageWindows = computed(() => {
|
||||||
|
const u = ocUsage.value || {}
|
||||||
|
const defs: Array<{ key: string; label: string }> = [
|
||||||
|
{ key: 'rolling', label: 'models.usageRolling' },
|
||||||
|
{ key: 'weekly', label: 'models.usageWeekly' },
|
||||||
|
{ key: 'monthly', label: 'models.usageMonthly' },
|
||||||
|
]
|
||||||
|
return defs.map((d) => {
|
||||||
|
const w = u[d.key] || {}
|
||||||
|
const pct = Math.max(0, Math.min(100, Math.round(Number(w.percent) || 0)))
|
||||||
|
const cls = pct >= 85 ? 'err' : pct >= 60 ? 'warn' : 'ok'
|
||||||
|
// 剩余时间:resetsAt 是 ISO 时间戳(UTC),减本地 now 得到毫秒差
|
||||||
|
let resetText = '—'
|
||||||
|
if (w.resetsAt) {
|
||||||
|
const t = Date.parse(String(w.resetsAt))
|
||||||
|
if (!isNaN(t)) resetText = fmtRemain(t - nowTick.value)
|
||||||
|
}
|
||||||
|
return { ...d, pct, cls, width: pct + '%', resetText }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// 订阅续期 = 月度重置时间(官方控制台的「Renews in …」就是它)。
|
||||||
|
// 同时给出倒计时和绝对日期,方便对账。
|
||||||
|
const renewText = computed(() => {
|
||||||
|
const m = (ocUsage.value || {}).monthly || {}
|
||||||
|
if (!m.resetsAt) return '—'
|
||||||
|
const t = Date.parse(String(m.resetsAt))
|
||||||
|
if (isNaN(t)) return '—'
|
||||||
|
const d = new Date(t)
|
||||||
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
|
const abs = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||||
|
return `${fmtRemain(t - nowTick.value)} · ${abs}`
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await load()
|
||||||
|
await loadOcUsage()
|
||||||
|
ocTimer = setInterval(loadOcUsage, 10_000) // 数据每 10 秒拉一次
|
||||||
|
tickTimer = setInterval(() => { nowTick.value = Date.now() }, 1_000) // 倒计时每秒走
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (ocTimer) { clearInterval(ocTimer); ocTimer = null }
|
||||||
|
if (tickTimer) { clearInterval(tickTimer); tickTimer = null }
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -528,6 +617,28 @@ onMounted(load)
|
|||||||
.prov-top { display: flex; align-items: center; gap: 8px; }
|
.prov-top { display: flex; align-items: center; gap: 8px; }
|
||||||
.prov-top b { font-size: 13px; }
|
.prov-top b { font-size: 13px; }
|
||||||
.prov-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11.5px; }
|
.prov-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11.5px; }
|
||||||
|
/* OpenCode Go 套餐用量(供应商卡片内) */
|
||||||
|
/* 供应商用量详情卡片(独立卡片,放在供应商卡片下方) */
|
||||||
|
.usage-prov { padding: 2px 0 4px; }
|
||||||
|
/* 模型清单卡里的测速工具条(原「全部文本模型」卡的按钮,合并后挪到这里) */
|
||||||
|
.lat-toolbar { display: flex; align-items: center; gap: 8px; padding: 2px 0 8px; border-bottom: 1px dashed var(--line-2); margin-bottom: 4px; }
|
||||||
|
.usage-prov .prov-top { margin-bottom: 8px; }
|
||||||
|
.usage-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 12px; }
|
||||||
|
.usage-l { flex: 0 0 76px; color: var(--muted-2); }
|
||||||
|
.usage-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; min-width: 80px; }
|
||||||
|
.usage-bar i { display: block; height: 100%; border-radius: 3px; transition: width .35s ease; }
|
||||||
|
.usage-bar i.ok { background: #10b981; }
|
||||||
|
.usage-bar i.warn { background: #f59e0b; }
|
||||||
|
.usage-bar i.err { background: #ef4444; }
|
||||||
|
.usage-p { flex: 0 0 40px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
|
||||||
|
.usage-reset { flex: 0 0 120px; text-align: right; color: var(--muted-2); font-size: 11px; font-variant-numeric: tabular-nums; }
|
||||||
|
/* 订阅续期:卡片底部单独一行,和三条窗口隔开 */
|
||||||
|
.usage-renew { display: flex; align-items: center; gap: 10px; margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line-2); font-size: 12px; }
|
||||||
|
.usage-renew-t { color: var(--muted-2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
|
||||||
|
.usage-p.ok { color: #10b981; }
|
||||||
|
.usage-p.warn { color: #f59e0b; }
|
||||||
|
.usage-p.err { color: #ef4444; }
|
||||||
|
.usage-empty { font-size: 11px; padding: 2px 0; }
|
||||||
.cap { display: inline-flex; align-items: center; gap: 4px; }
|
.cap { display: inline-flex; align-items: center; gap: 4px; }
|
||||||
.st { margin-top: 8px; border-top: 1px dashed var(--line-2); padding-top: 6px; }
|
.st { margin-top: 8px; border-top: 1px dashed var(--line-2); padding-top: 6px; }
|
||||||
.st-item { padding: 4px 0; }
|
.st-item { padding: 4px 0; }
|
||||||
|
|||||||
Executable
+271
@@ -0,0 +1,271 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""1min.AI 模型清单同步(独立脚本,不动 sync_models.py 的 3 家逻辑)。
|
||||||
|
|
||||||
|
为什么单独一个脚本:
|
||||||
|
· 1min 走 **OpenAI 兼容 API**(`GET https://api.1min.ai/openai/v1/models`),
|
||||||
|
不需要像 OpenCode/Agnes/Dots 那样解析 HTML/JS 文档 —— 抓取链路简单得多。
|
||||||
|
· sync_models.py 有 1300 行,`diff()` / `build_plan()` 和那三家强耦合,
|
||||||
|
硬塞第四家进去风险大、收益低。分开跑,互不干扰。
|
||||||
|
|
||||||
|
用法:
|
||||||
|
python scripts/sync_onemin.py # 只报告
|
||||||
|
python scripts/sync_onemin.py --apply # 真的写盘
|
||||||
|
python scripts/sync_onemin.py --json # JSON 输出
|
||||||
|
|
||||||
|
退出码:
|
||||||
|
0 = 无变化(或已同步成功)
|
||||||
|
1 = 有漂移但没写盘(未加 --apply)
|
||||||
|
2 = 抓取 / 解析 / 写盘失败
|
||||||
|
|
||||||
|
⚠️ 去重规则(重要):
|
||||||
|
1min 聚合了 OpenAI / DeepSeek / Qwen / GLM / Mistral / Kimi 的模型,
|
||||||
|
其中 6 个 id 和 opencode 重名。网关遇到重名会「按 id 调用始终命中先定义的那个」,
|
||||||
|
会把 opencode 的主路由抢走 —— 所以本脚本**永远跳过**和其他供应商重名的 id。
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import urllib.error
|
||||||
|
import urllib.request
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
DEFAULT_CFG = ROOT / "data" / "gateway.yaml"
|
||||||
|
DEFAULT_ENV = ROOT / "data" / ".env"
|
||||||
|
|
||||||
|
PROVIDER = "onemin"
|
||||||
|
BASE_URL = "https://api.1min.ai/openai/v1"
|
||||||
|
UA = "api-gateway-onemin-sync/1.0 (+ops; contact admin)"
|
||||||
|
|
||||||
|
|
||||||
|
# ── 工具 ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
def _load_env(path: Path) -> dict[str, str]:
|
||||||
|
"""读 data/.env(KEY=VALUE 简单格式)。"""
|
||||||
|
out: dict[str, str] = {}
|
||||||
|
if not path.exists():
|
||||||
|
return out
|
||||||
|
for line in path.read_text(encoding="utf-8").splitlines():
|
||||||
|
line = line.strip()
|
||||||
|
if not line or line.startswith("#") or "=" not in line:
|
||||||
|
continue
|
||||||
|
k, _, v = line.partition("=")
|
||||||
|
out[k.strip()] = v.strip().strip('"').strip("'")
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def _display_name(mid: str) -> str:
|
||||||
|
"""模型 id → 好看的名字(和手工加进 gateway.yaml 的一致)。"""
|
||||||
|
fixes = {
|
||||||
|
"qwen": "Qwen", "deepseek": "DeepSeek", "mistral": "Mistral",
|
||||||
|
"magistral": "Magistral", "ministral": "Ministral",
|
||||||
|
"open-mistral": "Open Mistral", "gpt": "GPT", "o3": "o3", "glm": "GLM",
|
||||||
|
}
|
||||||
|
parts = mid.split("/")
|
||||||
|
if len(parts) == 2: # openrouter 风格 moonshotai/kimi-k2.7-code
|
||||||
|
vendor, name = parts
|
||||||
|
vendor_map = {"moonshotai": "Moonshot", "meta": "Meta", "zai": "Z.AI"}
|
||||||
|
v = vendor_map.get(vendor, vendor.title())
|
||||||
|
n = name
|
||||||
|
for k, v2 in sorted(fixes.items(), key=lambda x: -len(x[0])):
|
||||||
|
if n.startswith(k):
|
||||||
|
n = v2 + n[len(k):]
|
||||||
|
break
|
||||||
|
return f"{v} {n}"
|
||||||
|
for k, v in sorted(fixes.items(), key=lambda x: -len(x[0])):
|
||||||
|
if mid.startswith(k):
|
||||||
|
return v + mid[len(k):]
|
||||||
|
return mid
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_onemin(api_key: str) -> dict[str, dict]:
|
||||||
|
"""拉 1min 的模型清单。返回 {id: {"id","display_name","owned_by"}}。"""
|
||||||
|
req = urllib.request.Request(
|
||||||
|
f"{BASE_URL}/models",
|
||||||
|
headers={"Authorization": f"Bearer {api_key}", "User-Agent": UA, "Accept": "application/json"},
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||||
|
payload = json.loads(resp.read().decode("utf-8", "replace"))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
raise RuntimeError(f"HTTP {e.code}(key 失效 / 被限流 / 接口改版)") from e
|
||||||
|
|
||||||
|
items = payload.get("data") or []
|
||||||
|
out: dict[str, dict] = {}
|
||||||
|
for m in items:
|
||||||
|
mid = m.get("id")
|
||||||
|
if not mid:
|
||||||
|
continue
|
||||||
|
out[mid] = {
|
||||||
|
"id": mid,
|
||||||
|
"display_name": _display_name(mid),
|
||||||
|
"owned_by": m.get("owned_by") or "",
|
||||||
|
}
|
||||||
|
if not out:
|
||||||
|
raise RuntimeError("接口没返回任何模型(响应结构可能变了)")
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
# ── 主流程 ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
ap = argparse.ArgumentParser(description="1min.AI 模型清单同步(默认只报告,--apply 才写盘)")
|
||||||
|
ap.add_argument("--config", default=str(DEFAULT_CFG))
|
||||||
|
ap.add_argument("--env", default=str(DEFAULT_ENV))
|
||||||
|
ap.add_argument("--json", action="store_true")
|
||||||
|
ap.add_argument("--apply", action="store_true")
|
||||||
|
ap.add_argument("--log", default=None)
|
||||||
|
args = ap.parse_args()
|
||||||
|
|
||||||
|
cfg_path = Path(args.config)
|
||||||
|
|
||||||
|
# 1) key
|
||||||
|
env = _load_env(Path(args.env))
|
||||||
|
api_key = os.environ.get("ONEMIN_API_KEY") or env.get("ONEMIN_API_KEY") or ""
|
||||||
|
if not api_key:
|
||||||
|
msg = "缺少 ONEMIN_API_KEY(data/.env 或环境变量)"
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
|
||||||
|
# 2) 拉模型
|
||||||
|
try:
|
||||||
|
doc = fetch_onemin(api_key)
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
msg = f"抓取 1min 模型失败:{type(e).__name__}: {e}"
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
if args.log:
|
||||||
|
_append_log(args.log, msg, 2)
|
||||||
|
return 2
|
||||||
|
|
||||||
|
# 3) 读配置
|
||||||
|
try:
|
||||||
|
cfg = yaml.safe_load(cfg_path.read_text(encoding="utf-8"))
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
msg = f"读配置失败:{type(e).__name__}: {e}"
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
|
||||||
|
providers = cfg.get("providers") or {}
|
||||||
|
cur = {m["id"]: m for m in (providers.get(PROVIDER) or {}).get("models") or []}
|
||||||
|
|
||||||
|
# 其他供应商已有的 id —— 永远不往 onemin 里加,避免重名抢路由
|
||||||
|
others: dict[str, str] = {}
|
||||||
|
for pk, pv in providers.items():
|
||||||
|
if pk == PROVIDER:
|
||||||
|
continue
|
||||||
|
for m in (pv.get("models") or []):
|
||||||
|
others.setdefault(m["id"], pk)
|
||||||
|
|
||||||
|
# 4) 算漂移
|
||||||
|
added = sorted(mid for mid in doc if mid not in cur and mid not in others)
|
||||||
|
skipped_dup = sorted(mid for mid in doc if mid not in cur and mid in others)
|
||||||
|
removed = sorted(mid for mid in cur if mid not in doc) # 配置有、接口没了
|
||||||
|
kept = [mid for mid in removed if mid in others] # 但别家还有 → 不删
|
||||||
|
|
||||||
|
report = {
|
||||||
|
"provider": PROVIDER,
|
||||||
|
"doc_total": len(doc),
|
||||||
|
"cfg_total": len(cur),
|
||||||
|
"added": added,
|
||||||
|
"removed": [m for m in removed if m not in others],
|
||||||
|
"skipped_duplicate": skipped_dup,
|
||||||
|
"kept_because_other_provider": kept,
|
||||||
|
}
|
||||||
|
|
||||||
|
if args.json:
|
||||||
|
print(json.dumps(report, ensure_ascii=False, indent=2))
|
||||||
|
else:
|
||||||
|
print(f"-- 1min.AI 模型同步({time.strftime('%Y-%m-%d %H:%M')})--")
|
||||||
|
print(f" 接口 {len(doc)} 个 / 配置 {len(cur)} 个")
|
||||||
|
print(f" 新增 {len(added)} 删除 {len(report['removed'])}")
|
||||||
|
if skipped_dup:
|
||||||
|
print(f" 跳过重名 {len(skipped_dup)}:{', '.join(skipped_dup)}")
|
||||||
|
if kept:
|
||||||
|
print(f" 别家还有不删 {len(kept)}:{', '.join(kept)}")
|
||||||
|
for mid in added:
|
||||||
|
print(f" + {mid}")
|
||||||
|
for mid in report["removed"]:
|
||||||
|
print(f" - {mid}")
|
||||||
|
|
||||||
|
drift = bool(added or report["removed"])
|
||||||
|
if not args.apply:
|
||||||
|
code = 1 if drift else 0
|
||||||
|
if drift:
|
||||||
|
print("→ 有漂移,未加 --apply,没写盘")
|
||||||
|
else:
|
||||||
|
print("→ 无变化 ✓")
|
||||||
|
return code
|
||||||
|
|
||||||
|
# 5) 写盘
|
||||||
|
if not drift:
|
||||||
|
print("→ 无需落盘 ✓")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
ts = time.strftime("%Y%m%d-%H%M%S")
|
||||||
|
backup = cfg_path.with_name(f"{cfg_path.name}.bak-onemin-sync-{ts}")
|
||||||
|
shutil.copy2(cfg_path, backup)
|
||||||
|
|
||||||
|
pcfg = providers.setdefault(PROVIDER, {})
|
||||||
|
pcfg.setdefault("name", "1min.AI")
|
||||||
|
pcfg.setdefault("base_url", BASE_URL)
|
||||||
|
pcfg.setdefault("auth", {"token_env": "ONEMIN_API_KEY"})
|
||||||
|
pcfg.setdefault("extra_headers", {})
|
||||||
|
|
||||||
|
models = {m["id"]: m for m in (pcfg.get("models") or [])}
|
||||||
|
for mid in report["removed"]:
|
||||||
|
models.pop(mid, None)
|
||||||
|
for mid in added:
|
||||||
|
models[mid] = {
|
||||||
|
"id": mid,
|
||||||
|
"display_name": doc[mid]["display_name"],
|
||||||
|
"type": "text",
|
||||||
|
"protocols": ["chat/completions"],
|
||||||
|
}
|
||||||
|
pcfg["models"] = [models[k] for k in sorted(models)]
|
||||||
|
|
||||||
|
# 原子替换
|
||||||
|
tmp = cfg_path.with_suffix(".yaml.tmp")
|
||||||
|
tmp.write_text(
|
||||||
|
yaml.safe_dump(cfg, allow_unicode=True, sort_keys=False, default_flow_style=False, width=4096),
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
|
||||||
|
# 回读校验
|
||||||
|
try:
|
||||||
|
check = yaml.safe_load(tmp.read_text(encoding="utf-8"))
|
||||||
|
got = {m["id"] for m in (check["providers"][PROVIDER].get("models") or [])}
|
||||||
|
want = set(models)
|
||||||
|
if got != want:
|
||||||
|
raise RuntimeError(f"回读不一致:缺 {sorted(want - got)[:5]} 多 {sorted(got - want)[:5]}")
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
tmp.unlink(missing_ok=True)
|
||||||
|
shutil.copy2(backup, cfg_path)
|
||||||
|
msg = f"回读校验失败,已还原:{type(e).__name__}: {e}"
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
|
||||||
|
tmp.replace(cfg_path)
|
||||||
|
print(f"→ 已写盘:+{len(added)} / -{len(report['removed'])}(备份 {backup.name})")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def _append_log(path: str, msg: str, code: int) -> None:
|
||||||
|
try:
|
||||||
|
p = Path(path)
|
||||||
|
p.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with p.open("a", encoding="utf-8") as f:
|
||||||
|
f.write(f"\n===== {time.strftime('%Y-%m-%d %H:%M:%S')} exit={code} =====\n{msg}\n")
|
||||||
|
except Exception: # noqa: BLE001
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
Reference in new issue
Block a user