balance-dsh 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +76 -1
- package/lib/index.js +125 -9
- package/package.json +1 -4
package/lib/client.js
CHANGED
|
@@ -40,10 +40,85 @@ window.__ModuleLoader__.load({
|
|
|
40
40
|
// `Rendered more hooks than during the previous render`,整块 UI 白掉。
|
|
41
41
|
// 用 no-op 占位后 hook 数量恒定,缺失时的返回值与原来的 `null` / `undefined` 完全一致,
|
|
42
42
|
// 所以**行为与视觉零变化**,只是把合规风险消掉了。
|
|
43
|
+
//
|
|
44
|
+
// ⚠️ 2026-11-19(DSH 0.2.2-rc.5):`primitives.useAnchoredPosition` **已被移除**
|
|
45
|
+
// —— 官方升级指南 `v0.2.2-alpha.2/css-anchored-menus`:
|
|
46
|
+
// 「`@deepseek-ai/dsh-client-ui-primitives` 移除 `useAnchoredPosition` 值导出和
|
|
47
|
+
// `AnchoredPositionOptions` 类型导出。`Menu` 将 `getAnchorRect` 替换为 `anchorRef`…」
|
|
48
|
+
// 它原来负责给「本会话消耗明细」浮层算 top/left。缺了之后原来退回 `() => null`,
|
|
49
|
+
// 而 `.balance-usage-panel` 的 CSS 只有 `position:fixed`、**没有 top/left** ——
|
|
50
|
+
// portal 到 body 后它落在文档流原位(页面底部附近),用户点开明细看到浮层乱跑。
|
|
51
|
+
// 所以这里补一个等价的自实现(不依赖 CSS Anchor Positioning 的浏览器支持度):
|
|
52
|
+
// 量锚点矩形 → 优先放上面、放不下翻到下面 → 水平居中并夹进视口 → 跟随 resize / 滚动 /
|
|
53
|
+
// 两侧尺寸变化重算。⚠️ 不用 requestAnimationFrame(DSH 渲染进程里窗口不可见时它会被挂起)。
|
|
54
|
+
function useAnchoredPositionFallback(options) {
|
|
55
|
+
const open = options?.open === true;
|
|
56
|
+
const anchorRef = options?.anchorRef;
|
|
57
|
+
const panelRef = options?.panelRef;
|
|
58
|
+
const side = options?.side === "bottom" ? "bottom" : "top";
|
|
59
|
+
const gap = Number(options?.gap ?? 6) || 0;
|
|
60
|
+
const margin = Number(options?.margin ?? 8) || 0;
|
|
61
|
+
const [style, setStyle] = react.useState(null);
|
|
62
|
+
react.useEffect(() => {
|
|
63
|
+
if (!open) {
|
|
64
|
+
setStyle(null);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let timer = null;
|
|
68
|
+
let disposed = false;
|
|
69
|
+
const compute = () => {
|
|
70
|
+
if (disposed) return;
|
|
71
|
+
const anchor = anchorRef?.current;
|
|
72
|
+
const panel = panelRef?.current;
|
|
73
|
+
if (anchor == null || typeof anchor.getBoundingClientRect !== "function") return;
|
|
74
|
+
const ar = anchor.getBoundingClientRect();
|
|
75
|
+
if (ar.width === 0 && ar.height === 0) return;
|
|
76
|
+
const pw = panel != null ? panel.offsetWidth : 0;
|
|
77
|
+
const ph = panel != null ? panel.offsetHeight : 0;
|
|
78
|
+
const vw = window.innerWidth || 0;
|
|
79
|
+
const vh = window.innerHeight || 0;
|
|
80
|
+
let left = Math.round(ar.left + ar.width / 2 - pw / 2);
|
|
81
|
+
if (vw > 0) left = Math.max(margin, Math.min(left, vw - pw - margin));
|
|
82
|
+
let top = side === "top" ? Math.round(ar.top - ph - gap) : Math.round(ar.bottom + gap);
|
|
83
|
+
if (top < margin) top = Math.round(ar.bottom + gap);
|
|
84
|
+
if (vh > 0 && top + ph > vh - margin) top = Math.max(margin, vh - ph - margin);
|
|
85
|
+
// 同值不换对象:避免每次 resize 都触发一次无意义的重渲染
|
|
86
|
+
setStyle((prev) =>
|
|
87
|
+
prev !== null && prev.left === left && prev.top === top
|
|
88
|
+
? prev
|
|
89
|
+
: { position: "fixed", left, top, right: "auto", bottom: "auto" },
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
const schedule = () => {
|
|
93
|
+
if (disposed || timer !== null) return;
|
|
94
|
+
timer = setTimeout(() => {
|
|
95
|
+
timer = null;
|
|
96
|
+
compute();
|
|
97
|
+
}, 16);
|
|
98
|
+
};
|
|
99
|
+
// 首帧同步算一次:panel 已经在 DOM 里(detailsOpen 变 true 之后才渲染)
|
|
100
|
+
compute();
|
|
101
|
+
window.addEventListener("resize", schedule);
|
|
102
|
+
window.addEventListener("scroll", schedule, true);
|
|
103
|
+
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(schedule) : null;
|
|
104
|
+
if (ro !== null) {
|
|
105
|
+
if (anchorRef?.current != null) ro.observe(anchorRef.current);
|
|
106
|
+
if (panelRef?.current != null) ro.observe(panelRef.current);
|
|
107
|
+
}
|
|
108
|
+
return () => {
|
|
109
|
+
disposed = true;
|
|
110
|
+
if (timer !== null) clearTimeout(timer);
|
|
111
|
+
window.removeEventListener("resize", schedule);
|
|
112
|
+
window.removeEventListener("scroll", schedule, true);
|
|
113
|
+
if (ro !== null) ro.disconnect();
|
|
114
|
+
};
|
|
115
|
+
}, [open, side, gap, margin, anchorRef, panelRef]);
|
|
116
|
+
return style;
|
|
117
|
+
}
|
|
43
118
|
const useAnchoredPositionHook =
|
|
44
119
|
typeof primitives.useAnchoredPosition === "function"
|
|
45
120
|
? primitives.useAnchoredPosition.bind(primitives)
|
|
46
|
-
:
|
|
121
|
+
: useAnchoredPositionFallback;
|
|
47
122
|
const useDismissOnOutsidePointerHook =
|
|
48
123
|
typeof primitives.useDismissOnOutsidePointer === "function"
|
|
49
124
|
? primitives.useDismissOnOutsidePointer.bind(primitives)
|
package/lib/index.js
CHANGED
|
@@ -1077,7 +1077,7 @@ function formatBalance(balance) {
|
|
|
1077
1077
|
// | { status:"failed" } (网络失败;官方明确“失败绝不变成 0 余额”)
|
|
1078
1078
|
// client 是 AccountClientMetadata(version / locale / timezoneOffsetSeconds),
|
|
1079
1079
|
// 缺字段会在平台侧组装请求头时抛错,所以三个字段都要给。
|
|
1080
|
-
const PLUGIN_VERSION = "2.3.
|
|
1080
|
+
const PLUGIN_VERSION = "2.3.2";
|
|
1081
1081
|
|
|
1082
1082
|
/** 斜杠命令名(2026-10-31 定案:用带作者后缀的全名,避免和别的余额插件撞车,也不设备用名)。
|
|
1083
1083
|
* ⚠️ DSH 的 COMMAND_NAME = /^[a-z][a-z0-9_-]*$/u —— **只允许小写**。
|
|
@@ -1758,7 +1758,23 @@ const WEB_TOOL_BILLING_START = Date.parse("2026-11-01T00:00:00+08:00");
|
|
|
1758
1758
|
const WEB_TOOL_PRICE_PER_CALL = 5 / 1000;
|
|
1759
1759
|
|
|
1760
1760
|
/** 统计网页工具调用:次数、可计费次数与金额。
|
|
1761
|
-
* 只认 tool/call 与 tool/result 配对成功、且 isError !== true 的调用(官方口径:失败不计费)。
|
|
1761
|
+
* 只认 tool/call 与 tool/result 配对成功、且 isError !== true 的调用(官方口径:失败不计费)。
|
|
1762
|
+
*
|
|
1763
|
+
* ⚠️ 2026-11-19(DSH 0.2.2-rc.4 起,用户「更新了新的 dsh 看看有哪里需要适配」):
|
|
1764
|
+
* 搜索的计费口径变了。官方升级指南 `v0.2.2-rc.4/web-search-deepseek-model-default`:
|
|
1765
|
+
* 「为 `deepseek-official` / `deepseek-account` 路由上的模型请求发起的搜索使用
|
|
1766
|
+
* `deepseek-official` 搜索提供方:它向 `web-search-deepseek` 的端点发送一次辅助
|
|
1767
|
+
* Messages 请求,**不按次收费,按模型 token 计费**,并向会话日志追加一个
|
|
1768
|
+
* `web/deepseek-search-llm-request` 事件。」
|
|
1769
|
+
* `dsh-web-search-deepseek/README.md` 也写明:「DeepSeek makes no per-search charge for it,
|
|
1770
|
+
* so its cost is that model turn's tokens.」
|
|
1771
|
+
*
|
|
1772
|
+
* 于是走这条路线的 `web_search` **不该再按 ¥5/千次 计**。而那次辅助 Messages 请求是
|
|
1773
|
+
* **log-only** 事件(只带 endpoint / apiVersion / body,不含 usage),插件**拿不到**它的
|
|
1774
|
+
* token —— 所以只能做到「不按次收费」,那部分 token 成本无法估算。
|
|
1775
|
+
*
|
|
1776
|
+
* 判据:会话里出现 `web/deepseek-search-llm-request` = 该次搜索走 Messages 搜索 = 不计次费。
|
|
1777
|
+
* 下面按「每个北京日期有几条该事件」做抵扣,数量上限为该日可计费的搜索次数。 */
|
|
1762
1778
|
function webToolUsage(events) {
|
|
1763
1779
|
const calls = new Map(); // callId -> { name, time }
|
|
1764
1780
|
for (const event of events ?? []) {
|
|
@@ -1791,13 +1807,25 @@ function webToolUsage(events) {
|
|
|
1791
1807
|
if (call.time >= WEB_TOOL_BILLING_START) {
|
|
1792
1808
|
if (call.name === "web_search") {
|
|
1793
1809
|
webSearchBillable += 1;
|
|
1794
|
-
webSearchCost += WEB_TOOL_PRICE_PER_CALL;
|
|
1795
1810
|
} else {
|
|
1796
1811
|
webFetchBillable += 1;
|
|
1797
1812
|
webFetchCost += WEB_TOOL_PRICE_PER_CALL;
|
|
1798
1813
|
}
|
|
1799
1814
|
}
|
|
1800
1815
|
}
|
|
1816
|
+
// 走 Messages 搜索的那几次不按次收费(见函数头注释)
|
|
1817
|
+
let llmSearchCount = 0;
|
|
1818
|
+
for (const event of events ?? []) {
|
|
1819
|
+
if (event.type !== "web/deepseek-search-llm-request") continue;
|
|
1820
|
+
const time = Number(event.time ?? 0);
|
|
1821
|
+
if (!Number.isFinite(time) || time < WEB_TOOL_BILLING_START) continue;
|
|
1822
|
+
llmSearchCount += 1;
|
|
1823
|
+
}
|
|
1824
|
+
if (llmSearchCount > 0) {
|
|
1825
|
+
webSearchBillable = Math.max(0, webSearchBillable - Math.min(llmSearchCount, webSearchBillable));
|
|
1826
|
+
}
|
|
1827
|
+
// 统一按次数重算,避免逐次累加的浮点漂移
|
|
1828
|
+
webSearchCost = webSearchBillable * WEB_TOOL_PRICE_PER_CALL;
|
|
1801
1829
|
return {
|
|
1802
1830
|
webSearchCalls,
|
|
1803
1831
|
webFetchCalls,
|
|
@@ -1806,6 +1834,7 @@ function webToolUsage(events) {
|
|
|
1806
1834
|
webSearchCost,
|
|
1807
1835
|
webFetchCost,
|
|
1808
1836
|
webToolCost: webSearchCost + webFetchCost,
|
|
1837
|
+
llmSearchCount,
|
|
1809
1838
|
};
|
|
1810
1839
|
}
|
|
1811
1840
|
|
|
@@ -2776,6 +2805,9 @@ function ensureDay(days, key) {
|
|
|
2776
2805
|
// 网页搜索 / 抓取的工具调用次数与按次费用(官方 ¥5/千次,2026-11-01 起计费)
|
|
2777
2806
|
webSearchCalls: 0,
|
|
2778
2807
|
webFetchCalls: 0,
|
|
2808
|
+
// 走「旧版 Messages 搜索」的搜索次数(2026-11-19 起):这部分**不按次收费**,
|
|
2809
|
+
// 只用于展示与核对,不计入 webSearchBillable / webSearchCost。
|
|
2810
|
+
webSearchLlm: 0,
|
|
2779
2811
|
webSearchBillable: 0,
|
|
2780
2812
|
webFetchBillable: 0,
|
|
2781
2813
|
webSearchCost: 0,
|
|
@@ -2858,7 +2890,23 @@ async function updateTodayCostWithSession(ctx, config, state, sessionId, events,
|
|
|
2858
2890
|
// 今日总额塌成只剩当前会话一个桶(就是注释里那个 16 元塌成 3.2)。
|
|
2859
2891
|
// 还会被当成非 partial 发给客户端,于是「打开时先小后大」换个入口又复发。
|
|
2860
2892
|
if (base.bySession == null || typeof base.bySession !== "object") return null;
|
|
2861
|
-
|
|
2893
|
+
// ⚠️ 空表不再一刀拒绝(2026-11-19 实测,用户:「跨天清零之后 继续工作就不计费了 啥意思」)。
|
|
2894
|
+
//
|
|
2895
|
+
// 上面那条「旧版快照空表会塌成 16→3.2」的前提**已经不存在了**:
|
|
2896
|
+
// `readTodaySnapshot` 现在先挡 `Number(parsed.v ?? 1) !== TODAY_SNAPSHOT_VERSION` 和
|
|
2897
|
+
// `date !== beijingDayKey()`,两条都过了才会返回对象,而返回值里 `v` 恒为当前版本 ——
|
|
2898
|
+
// 所以能走到这里的 base **一定是可信的今天的快照**,空表只可能是「今天真的还没有别的会话」。
|
|
2899
|
+
//
|
|
2900
|
+
// 而跨天后的头几十分钟正是这种情况:今天的会话都还没落盘,全量扫描走持久化
|
|
2901
|
+
// 也算出 `{cost:0, sessions:0, bySession:{}}`。此时当前会话就是今天唯一的消耗,
|
|
2902
|
+
// 「总额只剩当前会话一个桶」**恰恰是正确答案**。
|
|
2903
|
+
// 原来这一行 `return null` 让 `?session=` 整天不带 today,客户端手上再没有任何东西能把
|
|
2904
|
+
// 新值送进来(`?today=1` 走持久化、读不到未落盘的当前会话),界面就一直 ¥0.00 ——
|
|
2905
|
+
// 钱在花、数字不动,正是用户看到的现象。
|
|
2906
|
+
//
|
|
2907
|
+
// 保留上面那条判类型(字段缺失是真问题);空表放行。
|
|
2908
|
+
// 若今天稍后真的出现了别的会话,下一次全量重算会把它们补进 bySession,
|
|
2909
|
+
// 且客户端与 mergeTodayMax 都是「只增不减」,不会因此往回退。
|
|
2862
2910
|
// 同一会话 600 ms 内重复问(模型解析 + usage 拉取打的是同一个 URL)直接复用上次结果,
|
|
2863
2911
|
// 省掉一遍整会话事件遍历。必须在 collectDailyUsage 之前短路,否则等于没省。
|
|
2864
2912
|
const cachedIncrement = todayIncrementCache.get(sessionKey);
|
|
@@ -2945,6 +2993,20 @@ function collectDailyUsage(events, config, fallbackModel, cutoffMs, days, sessio
|
|
|
2945
2993
|
}
|
|
2946
2994
|
// 网页搜索 / 抓取:按调用发生的北京日期归日,金额按官方「每千次 ¥5」、且只在
|
|
2947
2995
|
// 2026-11-01 00:00(北京)之后计费。tool/call 与 tool/result 配对 + isError 过滤同 webToolUsage。
|
|
2996
|
+
//
|
|
2997
|
+
// ⚠️ 2026-11-19(DSH 0.2.2-rc.4 起):走「旧版 Messages 搜索」的 `web_search` **不按次收费**
|
|
2998
|
+
// (官方 README:「no per-search charge,成本是那一次模型调用的 token」)。
|
|
2999
|
+
// 判据是 `web/deepseek-search-llm-request` 事件 —— 每次走 Messages 搜索的搜索都追加一条。
|
|
3000
|
+
// 这里先按天统计该事件的条数作为「抵扣额度」,累加时优先用掉额度、额度用尽的才计次费。
|
|
3001
|
+
const llmBudget = new Map(); // 北京日期 -> 还能抵扣几次
|
|
3002
|
+
for (const event of events ?? []) {
|
|
3003
|
+
if (event.type !== "web/deepseek-search-llm-request") continue;
|
|
3004
|
+
const time = Number(event.time ?? 0);
|
|
3005
|
+
if (!Number.isFinite(time) || time < cutoffMs) continue;
|
|
3006
|
+
if (time < WEB_TOOL_BILLING_START) continue;
|
|
3007
|
+
const k = beijingDayKey(time);
|
|
3008
|
+
llmBudget.set(k, (llmBudget.get(k) ?? 0) + 1);
|
|
3009
|
+
}
|
|
2948
3010
|
const webCalls = new Map(); // callId -> { name, time }
|
|
2949
3011
|
for (const event of events ?? []) {
|
|
2950
3012
|
if (event.type !== "tool/call") continue;
|
|
@@ -2966,11 +3028,17 @@ function collectDailyUsage(events, config, fallbackModel, cutoffMs, days, sessio
|
|
|
2966
3028
|
if (call === void 0 || seen.has(key)) continue;
|
|
2967
3029
|
seen.add(key);
|
|
2968
3030
|
if (event.data?.message?.isError === true) continue;
|
|
2969
|
-
const
|
|
3031
|
+
const dayKey = beijingDayKey(call.time);
|
|
3032
|
+
const day = ensureDay(days, dayKey);
|
|
2970
3033
|
const billable = call.time >= WEB_TOOL_BILLING_START;
|
|
2971
3034
|
if (call.name === "web_search") {
|
|
2972
3035
|
day.webSearchCalls += 1;
|
|
2973
|
-
|
|
3036
|
+
// 这次是否走了 Messages 搜索(额度按天发放,先到先扣)
|
|
3037
|
+
const left = llmBudget.get(dayKey) ?? 0;
|
|
3038
|
+
const viaMessages = left > 0;
|
|
3039
|
+
if (viaMessages) llmBudget.set(dayKey, left - 1);
|
|
3040
|
+
day.webSearchLlm += viaMessages ? 1 : 0;
|
|
3041
|
+
if (billable && !viaMessages) {
|
|
2974
3042
|
day.webSearchBillable += 1;
|
|
2975
3043
|
day.webSearchCost += WEB_TOOL_PRICE_PER_CALL;
|
|
2976
3044
|
day.cost += WEB_TOOL_PRICE_PER_CALL;
|
|
@@ -3044,13 +3112,18 @@ function recentDayKeys(days, now = Date.now()) {
|
|
|
3044
3112
|
* @param {{ sessionId?: string, events?: unknown[] }} [reuse] 调用方已持有的会话事件,
|
|
3045
3113
|
* 命中时不再为它解压一遍(?session= 请求靠这个实现「零额外成本」的实时刷新)。
|
|
3046
3114
|
* @returns {Promise<{ cost:number, totalTokens:number, sessions:number, bySession:object }>} */
|
|
3047
|
-
async function buildTodayCost(ctx, config, reuse = null) {
|
|
3115
|
+
async function buildTodayCost(ctx, config, reuse = null, dayStartOverride = null) {
|
|
3048
3116
|
const getService = typeof ctx.get === "function" ? ctx.get.bind(ctx) : null;
|
|
3049
3117
|
const controller = getService?.("sessionController");
|
|
3050
3118
|
const persistence = getService?.("sessionPersistence");
|
|
3051
3119
|
const now = Date.now();
|
|
3052
|
-
|
|
3053
|
-
|
|
3120
|
+
// ⚠️ `dayStartOverride`(2026-11-19 起):让同一个函数能算**指定某一天**的账。
|
|
3121
|
+
// 目前唯一用途是「跨天补账」—— 结算用的是最后一版快照,快照写入有间隔,
|
|
3122
|
+
// 跨天前最后几十秒的消耗两边都没记(实测 11-18 差 0.1607)。
|
|
3123
|
+
// 不传时行为与原来逐位相同(`?? beijingDayStart(now)`)。
|
|
3124
|
+
const dayStart = dayStartOverride ?? beijingDayStart(now);
|
|
3125
|
+
// key 必须落在「dayStart 那一天的北京日期」上:取那天的正午最稳(不受 23:59:59 边界影响)
|
|
3126
|
+
const todayKey = dayStartOverride === null ? beijingDayKey(now) : beijingDayKey(dayStart + 12 * 3600000);
|
|
3054
3127
|
// ⚠️ 会话时间戳单位不保证是毫秒(2026-10-31:「怎么变成0了」)。
|
|
3055
3128
|
// `controller.list()` 的 updatedAt 有可能是**秒**,而 dayStart 是毫秒 ——
|
|
3056
3129
|
// `x.at >= dayStart` 就永远为假,今天动过的会话被整批滤掉,daily 为空,
|
|
@@ -3277,6 +3350,49 @@ async function computeAndStoreToday(ctx, config, state, reuse = null) {
|
|
|
3277
3350
|
} catch {
|
|
3278
3351
|
// 结算失败不影响今天的数字
|
|
3279
3352
|
}
|
|
3353
|
+
// ⚠️ 跨天补账(2026-11-19 实测发现,用户:「对话运行跨天 会不会计算错误」)。
|
|
3354
|
+
//
|
|
3355
|
+
// `settleStaleTodaySnapshot` 结算用的是**最后一版落盘快照**,而快照是有写入间隔的:
|
|
3356
|
+
// 实测 11-18 结算进历史的是 5.5451(快照 at 23:59:30),而 23:59:35 的实时值已经是
|
|
3357
|
+
// 5.7058 —— 差的 0.1607 既不在历史、也不在今天的账里(今天从 0 重新累计)。
|
|
3358
|
+
// 长任务跨天时这一段最大可达「一个快照间隔 + 一次全量耗时」,不能就这么丢掉。
|
|
3359
|
+
//
|
|
3360
|
+
// 做法:跨天后的**第一次**全量里把昨天重算一遍,取较大值补进历史。
|
|
3361
|
+
// 只在「prevSnapshot.date !== 今天」时触发一次,之后条件不再成立,平时零开销。
|
|
3362
|
+
if (
|
|
3363
|
+
prevSnapshot != null &&
|
|
3364
|
+
typeof prevSnapshot.date === "string" &&
|
|
3365
|
+
/^\d{4}-\d{2}-\d{2}$/.test(prevSnapshot.date) &&
|
|
3366
|
+
prevSnapshot.date !== value.date
|
|
3367
|
+
) {
|
|
3368
|
+
try {
|
|
3369
|
+
const yStart = new Date(prevSnapshot.date + "T00:00:00+08:00").getTime();
|
|
3370
|
+
if (Number.isFinite(yStart)) {
|
|
3371
|
+
const yDay = await buildTodayCost(ctx, config, null, yStart);
|
|
3372
|
+
const yCost = Number(yDay?.cost);
|
|
3373
|
+
const yTokens = Number(yDay?.totalTokens);
|
|
3374
|
+
// 可疑的空结果不许补进历史(那会把一个假的 0 之外的脏数写进永久统计)
|
|
3375
|
+
if (Number.isFinite(yCost) && yCost > 0 && yDay.suspiciousEmpty !== true && yDay.emptyListing !== true) {
|
|
3376
|
+
const settledFile = siblingFilePath(ctx, DAILY_SETTLED_FILENAME);
|
|
3377
|
+
if (settledFile !== "") {
|
|
3378
|
+
const map = await readDailySettled(settledFile);
|
|
3379
|
+
const prevEntry = map[prevSnapshot.date] ?? { cost: 0, totalTokens: 0 };
|
|
3380
|
+
const nextCost = Math.max(Number(prevEntry.cost) || 0, yCost);
|
|
3381
|
+
const nextTokens = Math.max(
|
|
3382
|
+
Number(prevEntry.totalTokens) || 0,
|
|
3383
|
+
Number.isFinite(yTokens) && yTokens > 0 ? yTokens : 0,
|
|
3384
|
+
);
|
|
3385
|
+
if (nextCost > (Number(prevEntry.cost) || 0) || nextTokens > (Number(prevEntry.totalTokens) || 0)) {
|
|
3386
|
+
map[prevSnapshot.date] = { cost: nextCost, totalTokens: nextTokens };
|
|
3387
|
+
await writeDailySettled(settledFile, map);
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
}
|
|
3392
|
+
} catch {
|
|
3393
|
+
// 补账失败不影响今天的数字:历史里保留 settle 那份(只会偏小一点点)
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3280
3396
|
await writeTodaySnapshot(state.snapshotFile, snapshot);
|
|
3281
3397
|
}
|
|
3282
3398
|
} catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balance-dsh",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "在 DeepSeek Harness 中显示 DeepSeek 账户余额和当前会话 token/费用消耗(含高峰/空闲峰谷计费)。仅支持 DeepSeek 官方模型与账号,暂不支持其他大模型。",
|
|
5
5
|
"author": "Rannist",
|
|
6
6
|
"type": "module",
|
|
@@ -26,9 +26,6 @@
|
|
|
26
26
|
"patch": "./cordis.patch.yml"
|
|
27
27
|
},
|
|
28
28
|
"client": {
|
|
29
|
-
"inject": [
|
|
30
|
-
"@deepseek-ai/dsh-client-runtime"
|
|
31
|
-
],
|
|
32
29
|
"platform": "web",
|
|
33
30
|
"immediately": true
|
|
34
31
|
}
|