mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
fix(deploy): 内置插件的修复无法下发 + buddy 余额解析口径
## deploy.sh:内置插件修复本该覆盖 sync_plugins 原为「只补缺,已存在一律不动」。看着安全,实际造成功能性缺口: **内置插件自身的修复永远下发不了**。v2.0.3/v2.0.4/v2.0.5 三个渠道修复就这样 全部卡在仓库里 —— 二进制换了、/etc/llmsproxy/plugins/channels.lua 还是旧版 (实测 sha256 不同、headers_fn 计数 0),生产行为毫无变化。我自己的验证还被 这个"静默不生效"骗过一轮:测试全绿、部署成功,线上仍是旧逻辑。 修法:与 sync_adapters 同纪律 —— **内置同名文件覆盖(带备份)**, 运行时新增/运维自加的非内置名字一律不动。内置源码是发行物的一部分, 部署必须与二进制内容对齐;"只补缺"想保护的是非内置文件,两者不是一回事。 判据:部署日志出现 `~ 更新内置插件: channels.lua`;部署后生产文件 sha256 与仓库一致。 ## buddy 余额:双层嵌套 + 只累加有效包 余额端点响应是 **data.Response.Data.Accounts[]**(与签到端点的单层 data 不同),原实现按顶层找 totalCredit → 永远解析不出、回落 0 或报错。 且刻意**不用**服务端的 TotalDosage:那是终身口径且取整(参考实测同一响应 TotalDosage=655 而 IDE 显示 155.67)。正确算法是遍历 Accounts 现算: 只累加有效包的 CycleCapacityRemain(失效包服务端仍返回,并入会虚高), 按两位小数规整;双层缺失时如实报错,不把「查不到」当「余额为 0」。 判据 TestBuddyBalanceParseDoubleNested:100.5+55.17=155.67(失效的 500 不计入)+ 单层 data 判为失败。变异:改用 TotalDosage → 立即 FAIL(已实测)。 go test ./internal/core/ 与 ./internal/lua/ 全绿。
This commit is contained in:
@ -331,12 +331,57 @@ local PLATFORMS = {
|
||||
end,
|
||||
},
|
||||
-- 余额(对齐参考 USER_RESOURCE_PATH /v2/billing/meter/get-user-resource)
|
||||
--
|
||||
-- ⚠️ 响应是**双层嵌套** data.Response.Data.Accounts[](与签到端点的单层
|
||||
-- data 不同),这是本接口最容易解析错的地方。
|
||||
--
|
||||
-- ⚠️ 刻意**不用**服务端的 TotalDosage:它是**终身口径**且取整(实测同一
|
||||
-- 响应里 TotalDosage=655 而 IDE 显示 155.67)。正确算法是遍历 Accounts[]
|
||||
-- 现算:只累加**有效包**的 CycleCapacityRemain(失效包服务端仍会返回,
|
||||
-- 但不能用于扣费,并进总额会让数字虚高),最后按两位小数规整。
|
||||
balance = {
|
||||
url = "https://copilot.tencent.com/v2/billing/meter/get-user-resource",
|
||||
method = "POST", body = "{}",
|
||||
total_fn = function(rec)
|
||||
local d = rec.data or rec
|
||||
return tonumber(d.totalCredit or d.total_credit or d.balance or d.amount) or 0
|
||||
local data = rec.data
|
||||
if type(data) ~= "table" then return nil end
|
||||
local resp = data.Response
|
||||
if type(resp) ~= "table" then return nil end
|
||||
local inner = resp.Data
|
||||
if type(inner) ~= "table" then return nil end
|
||||
local accounts = inner.Accounts
|
||||
if type(accounts) ~= "table" then return nil end
|
||||
local now = os.time and os.time() or 0
|
||||
local sum = 0
|
||||
for _, pkg in ipairs(accounts) do
|
||||
if type(pkg) == "table" then
|
||||
-- 失效判定:Status 显式已过期,或 ExpiredTime / DeductionEndTime 已过。
|
||||
local active = true
|
||||
local st = pkg.Status
|
||||
if st == 2 or st == "2" or st == "EXPIRED" or st == "expired" then active = false end
|
||||
local function past(t)
|
||||
if type(t) ~= "string" or t == "" then return false end
|
||||
local Y, Mo, D, H, Mi, S = t:match("^(%d%d%d%d)%-(%d%d)%-(%d%d)[T ](%d%d):(%d%d):(%d%d)")
|
||||
if Y then
|
||||
local ts = os.time({ year = tonumber(Y), month = tonumber(Mo), day = tonumber(D),
|
||||
hour = tonumber(H), min = tonumber(Mi), sec = tonumber(S), isdst = false })
|
||||
return ts and now >= ts
|
||||
end
|
||||
return false
|
||||
end
|
||||
if past(pkg.ExpiredTime) then active = false end
|
||||
local ded = tonumber(pkg.DeductionEndTime)
|
||||
if ded and ded > 0 then
|
||||
-- 毫秒时间戳
|
||||
if now >= math.floor(ded / 1000) then active = false end
|
||||
end
|
||||
if active then
|
||||
sum = sum + (tonumber(pkg.CycleCapacityRemain) or 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- 两位小数规整(服务端精确值带浮点噪声,如 55.67000031)
|
||||
return math.floor(sum * 100 + 0.5) / 100
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user