diff --git a/internal/lua/billing_test.go b/internal/lua/billing_test.go index aecefb5..6edabe5 100644 --- a/internal/lua/billing_test.go +++ b/internal/lua/billing_test.go @@ -1236,8 +1236,6 @@ func TestLongContextComposesWithCacheDiscount(t *testing.T) { // total = 0.2325 approx(t, "step composes with cache discount", got, 0.2325) } -<<<<<<< HEAD -======= // ---- 源层零价覆盖模型价(issue #1)--------------------------------------- // @@ -1371,4 +1369,3 @@ func TestBillingProfileDefaultPolicy(t *testing.T) { } } } ->>>>>>> 7941b41 (refactor(billing)!: 计费全部沉入插件,内核零 billing 代码;规则由插件自持) diff --git a/internal/lua/plugins/billing.lua b/internal/lua/plugins/billing.lua index 62be325..2c4f41a 100644 --- a/internal/lua/plugins/billing.lua +++ b/internal/lua/plugins/billing.lua @@ -72,8 +72,6 @@ local DEFAULT_PRICES = { } plugin.prices = DEFAULT_PRICES -<<<<<<< HEAD -======= -- ===== 规则 → 价格表编译(全部在插件内) ============================== -- -- billing 没有任何内核逻辑(issue #1 的方向):规则文件、编译、计价、账目、 @@ -479,7 +477,6 @@ plugin.http = { -- 测试/运维直调导出(/api/plugins/billing/call/...);不是内核接口。 plugin.exports = { "rules_get", "rules_put", "rules_add", "rules_delete" } ->>>>>>> 7941b41 (refactor(billing)!: 计费全部沉入插件,内核零 billing 代码;规则由插件自持) -- Default prompt-cache discount. 0.1 = a cache read costs a tenth of a fresh -- token, which is what DeepSeek/Qwen/Kimi and most others charge. It can be -- overridden per price entry (prices.models..cache_discount) or globally by @@ -597,7 +594,11 @@ local function priceFor(payload) -- look the same: an unpriced model silently costing 0 is the most dangerous -- failure mode a cost plugin has, because the bill still adds up and just -- quietly under-reports. It is counted separately and surfaced in the UI. - out = { + -- ★ local 是必须的:此前写的是全局 `out = {`,而 priceFor 每个请求都会调用, + -- 于是这个表挂在 VM 级全局变量上跨请求残留/泄漏(GitCode issue #1 顺带发现)。 + -- 功能上因为每次整体重建而侥幸正确,但它是共享可变状态,任何提前 return 或 + -- 后续分支忘了重建都会让上一单的价格漏到下一单 —— 计费错误不会报错。 + local out = { prompt = d.prompt or 0, completion = d.completion or 0, per_request = 0, cache_discount = d.cache_discount, peak = d.peak, -- nil = bill reasoning at the completion rate, which is what every @@ -644,8 +645,6 @@ local function priceFor(payload) if kp.cache_discount ~= nil then out.cache_discount = kp.cache_discount end if kp.peak ~= nil then out.peak = kp.peak end end -<<<<<<< HEAD -======= -- profile 级 default 策略(编译期写入 prices.default_mode)在这里落地: -- `free` = 运营声明"没有单独规则的源一律免费" ⇒ 计为已定价(不进 unpriced 统计); @@ -656,7 +655,6 @@ local function priceFor(payload) out.priced = true end end ->>>>>>> 7941b41 (refactor(billing)!: 计费全部沉入插件,内核零 billing 代码;规则由插件自持) return out end