@angelyeye/dsh-cost-tracker 1.10.1 → 1.11.1

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/client.js CHANGED
@@ -282,6 +282,14 @@ window.__ModuleLoader__.load({
282
282
  .cost-cfg-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; line-height: 1.6; padding: 2px 9px; border-radius: 999px; border: .5px solid var(--dsw-alias-border-l2, #e5e7eb); background: var(--dsw-alias-bg-layer-3, transparent); color: var(--dsw-alias-label-secondary, #5b6472); white-space: nowrap; }
283
283
  .cost-cfg-chip b { color: var(--dsw-alias-label-primary, #171a1f); font-weight: 600; font-variant-numeric: tabular-nums; }
284
284
  .cost-cfg-chip.is-on { border-color: var(--dsw-alias-brand-primary, #2563eb); color: var(--dsw-alias-brand-primary, #2563eb); }
285
+ /* v1.11.0:GPT Fast 档价格行(token 走「万/亿」后数字变宽,用等宽数字 + 单行省略兜底) */
286
+ .cost-fast-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 2px 0; font-size: 12px; font-variant-numeric: tabular-nums; }
287
+ .cost-fast-name { flex: 0 0 auto; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-primary, #171a1f); font-weight: 500; }
288
+ .cost-fast-pair { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary, #5b6472); }
289
+ .cost-fast-sep { opacity: .45; }
290
+ .cost-fast-tag { flex: 0 0 auto; font-size: 11px; padding: 0 6px; border-radius: 999px; border: .5px solid var(--dsw-alias-border-l2, #e5e7eb); color: var(--dsw-alias-label-secondary, #5b6472); white-space: nowrap; }
291
+ /* token 数字统一等宽,避免 万/亿 切换时宽度跳动 */
292
+ .cost-matrix-num, .cost-ug-tip-val, .cost-stat-sub { font-variant-numeric: tabular-nums; }
285
293
  .cost-sec { border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); border-radius: 10px; margin-top: 10px; overflow: hidden; }
286
294
  .cost-sec-head { appearance: none; width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; background: none; border: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
287
295
  .cost-sec-head:hover { background: var(--dsw-alias-bg-layer-2, transparent); }
@@ -366,6 +374,9 @@ window.__ModuleLoader__.load({
366
374
  e("path", { d: "M8.75 3.5 5.25 7l3.5 3.5", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" }));
367
375
  }
368
376
 
377
+ /** 目录价 USD→CNY 缺省汇率(与后端 vendor-catalog.CATALOG_FX_DEFAULT 一致;真实值由后端回显) */
378
+ const DEFAULT_FX = 6.67;
379
+
369
380
  function fmtInt(n) { return String(Math.round(Number(n) || 0)).replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
370
381
  function fmtMoney(n) {
371
382
  const x = Number(n) || 0;
@@ -380,14 +391,29 @@ window.__ModuleLoader__.load({
380
391
  if (n >= 1000) return (n / 1000).toFixed(1) + "K";
381
392
  return String(Math.round(n));
382
393
  }
383
- // 热力图 token 显示:<1000 原样;≥1000 用 K(≥100 时取整),≥1000000 用 M(≥100 时取整)
394
+ // v1.11.0:token 数量统一中文口径(与 token-format.js 同一规则,双端一致)
395
+ // <1万 → 千分位整数;≥1万 → X.X万(≥100万取整);≥1亿 → X.XX亿(≥10亿 1 位)
396
+ // 保留 fmtTokens 这个函数名(调用点最多),但语义已换成中文单位,
397
+ // 这样 Windows 大小写不敏感的文件系统上不会出现两个只差大小写的同名函数。
384
398
  function fmtTokens(n) {
385
- const v = Math.max(0, Number(n) || 0);
386
- const scaled = (x) => (x >= 100 ? String(Math.round(x)) : String(Math.round(x * 10) / 10));
387
- if (v < 1000) return String(Math.round(v));
388
- if (v < 1000000) return scaled(v / 1000) + "K";
389
- return scaled(v / 1000000) + "M";
390
- }
399
+ const raw = Number(n);
400
+ const v = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 0;
401
+ const trim = (s) => (s.indexOf(".") >= 0 ? s.replace(/\.?0+$/, "") : s);
402
+ if (v < 10000) return String(v).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
403
+ if (v < 100000000) {
404
+ const w = v / 10000;
405
+ return (w >= 100 ? String(Math.round(w)) : trim(w.toFixed(1))) + "万";
406
+ }
407
+ const y = v / 100000000;
408
+ return (y >= 10 ? trim(y.toFixed(1)) : trim(y.toFixed(2))) + "亿";
409
+ }
410
+ /** token 精确显示(tooltip / 明细用,完整千分位不换算单位) */
411
+ function fmtTokensExact(n) {
412
+ const raw = Number(n);
413
+ const v = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 0;
414
+ return String(v).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
415
+ }
416
+ // 热力图 token 显示:统一走上面的 fmtTokens(v1.11.0 起为中文单位 万/亿)
391
417
  function fmtAxisMoney(v) {
392
418
  if (v <= 0) return "0";
393
419
  if (v >= 1000) return (v / 1000).toFixed(1) + "k";
@@ -899,6 +925,7 @@ window.__ModuleLoader__.load({
899
925
  const views = viewCtl && viewCtl.available ? BOARD_VIEWS : [BOARD_VIEWS[0]];
900
926
  return e("div", { className: "cost-row" },
901
927
  e("select", { className: "cost-select", value: String(days), onChange: ev => setDays(parseInt(ev.target.value, 10)) },
928
+ e("option", { value: "1" }, "今天"),
902
929
  e("option", { value: "7" }, "近 7 天"),
903
930
  e("option", { value: "14" }, "近 14 天"),
904
931
  e("option", { value: "30" }, "近 30 天"),
@@ -969,13 +996,29 @@ window.__ModuleLoader__.load({
969
996
  function statCards(dash, balance, viewCtl, planTotal) {
970
997
  const today = dash.today || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
971
998
  const month = dash.month || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
999
+ // all = 全时段累计(不随筛选变化),仅作副行参考
972
1000
  const all = dash.all || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
1001
+ // win = 当前时间窗口(顶部「近 N 天 / 全部」下拉)内的合计(v1.9.x)。
1002
+ // 此前这三张卡(总花费 / API 请求次数 / Token)直接读 `all`,与筛选框完全无关:
1003
+ // 切到「近 7 天」时费用却显示全时段累计,与下方图表口径打架。
1004
+ // 现在主值取窗口内金额,累计值降到副行,并显式标注「累计」。
1005
+ // dash 由 buildDashboard({days}) 计算,realCost/subEquivalent/calls/tokens
1006
+ // 都按 cutoff 过滤;云端经 normalizeCloudDash 后同名字段齐全,故本机/云端/并集同口径。
1007
+ const n = (v) => Number(v) || 0;
1008
+ const win = {
1009
+ real: n(dash.realCost), calls: n(dash.realCalls), tokens: n(dash.realTokens),
1010
+ sub: n(dash.subEquivalent), subCalls: n(dash.subCalls), subTokens: n(dash.subTokens),
1011
+ };
1012
+ const days = Number(dash.days) || 0;
1013
+ // days=1 是「今天」(北京时间日历日,见宿主 buildDashboard 的 cutoff 约定),
1014
+ // 不能拼成「近 1 天」,否则会与「今日费用」卡看起来是两个口径。
1015
+ const winLabel = days === 1 ? "今天" : (days > 0 ? "近 " + days + " 天" : "全部");
973
1016
  // 金额卡:口径由「含 Plan 总额」开关决定
974
1017
  // off:主值 = 按量消费(不含订阅会员等效费用);副行附注订阅等效
975
1018
  // on :主值 = 按量 + 订阅等值(Plan 总额);副行说明拆分,避免看数不明口径
976
1019
  const money = (t) => planTotal ? (Number(t.real) || 0) + (Number(t.sub) || 0) : (Number(t.real) || 0);
977
1020
  const moneySub = (t) => {
978
- const base = "调用 " + fmtInt(t.calls) + " 次 · Tokens " + fmtCompact(t.tokens);
1021
+ const base = "调用 " + fmtInt(t.calls) + " 次 · Token " + fmtTokens(t.tokens);
979
1022
  if (planTotal) {
980
1023
  return base + " · 含订阅 ¥" + fmtMoney(t.sub) + (t.subCalls ? "(" + fmtInt(t.subCalls) + " 次)" : "");
981
1024
  }
@@ -1008,14 +1051,27 @@ window.__ModuleLoader__.load({
1008
1051
  : "本机 + 云端 " + Math.max(0, (viewCtl.devices || []).length - 1) + " 台其他设备")
1009
1052
  : "本机";
1010
1053
  const tag = (t) => scopeNote + (viewCtl && viewCtl.pending > 0 && viewCtl.view !== "local" ? " · 待同步 " + viewCtl.pending + " 条" : "");
1054
+ // 三张「窗口卡」:主值跟随顶部时间筛选,副行给累计值(并注明「累计」)
1055
+ // 金额卡副行的按量/订阅拆分同样取窗口值,累计单独一块,避免半窗口半累计。
1056
+ //
1057
+ // 单位说明:副行保留「N 次」写法(`按量 100 次 · 订阅 5 次`)——
1058
+ // 早先这里只有裸数字 `按量 100 · 订阅 5`,界面上看不出单位,
1059
+ // 且与「今日/本月」两卡的「调用 N 次」风格不一致。
1060
+ const moneyWin = money(win);
1061
+ const cnt = (n) => fmtInt(n) + " 次";
1062
+ const moneyWinSub = (planTotal
1063
+ ? "按量 " + cnt(win.calls) + " · 订阅 " + cnt(win.subCalls)
1064
+ : (win.sub > 0 ? "按量 ¥" + fmtMoney(win.real) + " · 订阅 ¥" + fmtMoney(win.sub) : moneySub(win)));
1065
+ const allMoney = money(all);
1011
1066
  return e("div", { className: "cost-cards" },
1012
1067
  statCard("今日费用(CNY)" + planBadge + "[" + tag() + "]", "¥" + fmtMoney(money(today)), moneySub(today)),
1013
1068
  statCard("本月费用(CNY)" + planBadge, "¥" + fmtMoney(money(month)), moneySub(month)),
1014
- statCard("总花费(CNY)" + planBadge, "¥" + fmtMoney(money(all)), "调用 " + fmtInt(all.calls) + " 次 · Tokens " + fmtCompact(all.tokens) + (all.sub > 0 ? (planTotal ? " · 含订阅 ¥" + fmtMoney(all.sub) : " · 订阅 ¥" + fmtMoney(all.sub)) : "")),
1015
- statCard("API 请求次数", fmtInt(all.calls + all.subCalls),
1016
- "按量 " + fmtInt(all.calls) + " · 订阅 " + fmtInt(all.subCalls)),
1017
- statCard("Tokens", fmtInt(all.tokens + all.subTokens),
1018
- "按量 " + fmtCompact(all.tokens) + " · 订阅 " + fmtCompact(all.subTokens)),
1069
+ statCard("花费(CNY)" + planBadge + " · " + winLabel, "¥" + fmtMoney(moneyWin),
1070
+ moneyWinSub + " · 累计 ¥" + fmtMoney(allMoney)),
1071
+ statCard("API 请求次数 · " + winLabel, cnt(win.calls + win.subCalls),
1072
+ "按量 " + cnt(win.calls) + " · 订阅 " + cnt(win.subCalls) + " · 累计 " + cnt(all.calls + all.subCalls)),
1073
+ statCard("Token · " + winLabel, fmtTokens(win.tokens + win.subTokens),
1074
+ "按量 " + fmtTokens(win.tokens) + " · 订阅 " + fmtTokens(win.subTokens) + " · 累计 " + fmtTokens(all.tokens + all.subTokens)),
1019
1075
  statCard(balTitle, balValue, balSub));
1020
1076
  }
1021
1077
 
@@ -1103,7 +1159,7 @@ window.__ModuleLoader__.load({
1103
1159
  body = e("div", null, bars);
1104
1160
  }
1105
1161
  const stats = dash
1106
- ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Tokens " + fmtInt(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1162
+ ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Token " + fmtTokens(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1107
1163
  : "加载中…";
1108
1164
  return e("div", { className: "cost-panel" },
1109
1165
  e("div", { className: "cost-row" },
@@ -1187,7 +1243,7 @@ window.__ModuleLoader__.load({
1187
1243
  }
1188
1244
  }
1189
1245
  const stats = dash
1190
- ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Tokens " + fmtInt(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1246
+ ? "累计请求 " + fmtInt(dash.subCalls) + " 次 · Token " + fmtTokens(dash.subTokens) + " · 等效按量费用 ¥" + fmtMoney(dash.subEquivalent)
1191
1247
  : "加载中…";
1192
1248
  return e("div", { className: "cost-panel" },
1193
1249
  e("div", { className: "cost-row" },
@@ -1381,7 +1437,7 @@ window.__ModuleLoader__.load({
1381
1437
  className: "cost-ug-tip",
1382
1438
  style: { left: left + "px", top: top + "px", transform: transform },
1383
1439
  },
1384
- e("div", { className: "cost-ug-tip-total" }, day.date + " · " + fmtTokens(tokens) + " tokens" + (day.calls ? " · " + fmtInt(day.calls) + " 次调用" : "")),
1440
+ e("div", { className: "cost-ug-tip-total" }, day.date + " · " + "Token " + fmtTokens(tokens) + (day.calls ? " · " + fmtInt(day.calls) + " 次调用" : "")),
1385
1441
  e("div", { className: "cost-ug-tip-row" }, e("span", { className: "cost-ug-tip-name" }, "输入"), e("span", { className: "cost-ug-tip-val" }, fmtTokens(day.input))),
1386
1442
  e("div", { className: "cost-ug-tip-row" }, e("span", { className: "cost-ug-tip-name" }, "缓存"), e("span", { className: "cost-ug-tip-val" }, fmtTokens((day.cacheRead || 0) + (day.cacheWrite || 0)))),
1387
1443
  e("div", { className: "cost-ug-tip-row" }, e("span", { className: "cost-ug-tip-name" }, "输出"), e("span", { className: "cost-ug-tip-val" }, fmtTokens(day.output))),
@@ -1390,7 +1446,7 @@ window.__ModuleLoader__.load({
1390
1446
 
1391
1447
  return e("div", { className: "cost-ug" },
1392
1448
  e("div", { className: "cost-ug-total" },
1393
- "累计 " + fmtTokens(t.tokens) + " tokens · 输入 " + fmtTokens(t.input) + " · 缓存 " + fmtTokens(t.cache) + " · 输出 " + fmtTokens(t.output) + " · " + fmtInt(t.calls) + " 次调用"),
1449
+ "累计 " + fmtTokens(t.tokens) + " · 输入 " + fmtTokens(t.input) + " · 缓存 " + fmtTokens(t.cache) + " · 输出 " + fmtTokens(t.output) + " · " + fmtInt(t.calls) + " 次调用"),
1394
1450
  e("div", { className: "cost-ug-host", ref: hostRef },
1395
1451
  e("div", { className: "cost-ug-grid", style: { gridTemplateColumns: "repeat(" + WEEKS + ", 1fr)" } }, cells),
1396
1452
  tipEl),
@@ -1750,7 +1806,7 @@ window.__ModuleLoader__.load({
1750
1806
  const [draft, setDraft] = useState({});
1751
1807
  // 分组草稿(各自独立保存;互不覆盖)
1752
1808
  const [peakDraft, setPeakDraft] = useState({});
1753
- const [bill, setBill] = useState({ showTotalWithPlan: false, priceMatch: "fuzzy", catalogFxRate: 7.2, planRows: [], priceRows: [] });
1809
+ const [bill, setBill] = useState({ showTotalWithPlan: false, priceMatch: "fuzzy", catalogFxRate: DEFAULT_FX, planRows: [], priceRows: [] });
1754
1810
  const [psDraft, setPsDraft] = useState({ priceSyncUrl: "", priceSyncAutoCheck: true });
1755
1811
  const [impDraft, setImpDraft] = useState({ autoImport: true });
1756
1812
  const [volcId, setVolcId] = useState("");
@@ -1811,7 +1867,7 @@ window.__ModuleLoader__.load({
1811
1867
  setBill({
1812
1868
  showTotalWithPlan: v.showTotalWithPlan === true,
1813
1869
  priceMatch: v.priceMatch === "exact" ? "exact" : "fuzzy",
1814
- catalogFxRate: typeof v.catalogFxRate === "number" ? v.catalogFxRate : 7.2,
1870
+ catalogFxRate: typeof v.catalogFxRate === "number" ? v.catalogFxRate : DEFAULT_FX,
1815
1871
  planRows: planOverridesToRows(v.planOverrides),
1816
1872
  priceRows: priceOverridesToRows(v.priceOverrides),
1817
1873
  });
@@ -1887,7 +1943,7 @@ window.__ModuleLoader__.load({
1887
1943
  apiCall("billing-config", {
1888
1944
  showTotalWithPlan: !!bill.showTotalWithPlan,
1889
1945
  priceMatch: bill.priceMatch === "exact" ? "exact" : "fuzzy",
1890
- catalogFxRate: Number(bill.catalogFxRate) || 7.2,
1946
+ catalogFxRate: Number(bill.catalogFxRate) || DEFAULT_FX,
1891
1947
  planOverrides: planRowsToObj(bill.planRows),
1892
1948
  priceOverrides: priceRowsToObj(bill.priceRows),
1893
1949
  }).then(v => {
@@ -2201,7 +2257,7 @@ window.__ModuleLoader__.load({
2201
2257
  e("div", { className: "cost-row", style: { gap: "8px" } },
2202
2258
  e("input", {
2203
2259
  className: "cost-input", style: { width: "90px" }, type: "number", step: "0.1", min: "0.1", max: "100",
2204
- value: String(bill.catalogFxRate == null ? 7.2 : bill.catalogFxRate),
2260
+ value: String(bill.catalogFxRate == null ? DEFAULT_FX : bill.catalogFxRate),
2205
2261
  onChange: ev => setBillField("catalogFxRate", Number(ev.target.value)),
2206
2262
  }),
2207
2263
  e("span", { className: "cost-hint" }, "目录单价为 USD/1M tokens,按此汇率折算为人民币入账"))),
@@ -2242,7 +2298,26 @@ window.__ModuleLoader__.load({
2242
2298
  cat ? e("div", { className: "cost-cfg-top", style: { marginTop: "6px" } },
2243
2299
  (cat.providers || []).map(p => e("span", { key: "cp" + p.id, className: "cost-cfg-chip" }, p.id, " ", e("b", null, p.count)))) : null,
2244
2300
  e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2245
- "命中目录 = 精确价(不计入「估算」);内置时代价优先于目录,手动覆盖价优先于两者;目录读取失败不影响计费,自动回落 provider 兜底。")));
2301
+ "命中目录 = 精确价(不计入「估算」);内置时代价优先于目录,手动覆盖价优先于两者;目录读取失败不影响计费,自动回落 provider 兜底。"),
2302
+ // v1.11.0: GPT Fast tier price comparison (service_tier fast / priority)
2303
+ cat && cat.fast && (cat.fast.models || []).length > 0
2304
+ ? e("div", { className: "cost-subblock", style: { marginTop: "10px" } },
2305
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "GPT Fast 档价格(USD → CNY @" + cat.fast.fxRate + ")"),
2306
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2307
+ "共 " + cat.fast.models.length + " 个模型登记了 Fast 档价 · 核实 " + (cat.fast.checkedAt || "—")
2308
+ + "。判定来源:请求参数优先,其次读本会话在 dsh-fast-tier 里的档位选择;识别不到时按标准价计,绝不按倍率推算。"),
2309
+ e("div", { className: "cost-list", style: { marginTop: "6px" } },
2310
+ cat.fast.models.map(m => e("div", { key: "ft" + m.provider + m.model, className: "cost-fast-row" },
2311
+ e("span", { className: "cost-fast-name", title: m.model + " · " + (m.sourceUrl || "") }, m.model),
2312
+ e("span", { className: "cost-fast-pair", title: "CNY / 1M tokens:标准 → Fast" },
2313
+ "输入 ¥" + m.standardCny.input + "→¥" + m.fastCny.input,
2314
+ e("span", { className: "cost-fast-sep" }, " · "),
2315
+ "输出 ¥" + m.standardCny.output + "→¥" + m.fastCny.output),
2316
+ e("span", { className: "cost-fast-tag" }, m.confidence === "official" ? "官方" : "交叉核对")))))
2317
+ : null,
2318
+ cat && cat.fast && (cat.fast.models || []).length === 0
2319
+ ? e("div", { className: "cost-hint", style: { marginTop: "6px" } }, "目录中暂无登记 Fast 档价的模型。")
2320
+ : null));
2246
2321
 
2247
2322
  // ---------- ⑤ 历史导入 ----------
2248
2323
  const impBody = e("div", null,
@@ -2590,7 +2665,6 @@ window.__ModuleLoader__.load({
2590
2665
  const [sync, setSync] = useState(null);
2591
2666
  const [cloudDash, setCloudDash] = useState(null);
2592
2667
  const [cloudErr, setCloudErr] = useState("");
2593
- const [cloudMatrix, setCloudMatrix] = useState(null);
2594
2668
  const [cloudUsage, setCloudUsage] = useState(null);
2595
2669
  const [cloudUsageErr, setCloudUsageErr] = useState("");
2596
2670
  const [view, setViewState] = useState(() => {
@@ -2658,10 +2732,41 @@ window.__ModuleLoader__.load({
2658
2732
  else { setCloudDash(null); setCloudErr((v && v.error) || "云端不可用"); }
2659
2733
  }).catch(err => { setCloudDash(null); setCloudErr(String(err && err.message ? err.message : err)); });
2660
2734
  }
2661
- function loadCloudMatrix(d) {
2662
- apiCall("cloud", { route: "matrix", days: d, view: view === "local+cloud" ? "cloud-rest" : "cloud" }).then(v => {
2663
- if (v && v.ok !== false) setCloudMatrix(v); else setCloudMatrix(null);
2664
- }).catch(() => setCloudMatrix(null));
2735
+ /**
2736
+ * 「设备 × Agent 矩阵」数据源。
2737
+ *
2738
+ * 此前这里请求宿主 `matrix` 路由,但宿主 ROUTES 里**没有**该路由 ——
2739
+ * 稳定 404 → setCloudMatrix(null) → 矩阵区块永远不渲染(静默失效,
2740
+ * 界面上只表现为「这块没了」,没有任何报错提示)。
2741
+ *
2742
+ * 修复:不再依赖不存在的路由。云端 overview / plugin-view 本身已返回
2743
+ * devices:[{device,name,cost,calls,tokens,sources[]}] 与
2744
+ * sources:[{source,cost,calls,tokens,devices[]}]
2745
+ * 足以就地拼出矩阵,且不引入云端版本耦合(老云端同样可用)。
2746
+ *
2747
+ * 格子填充规则:devices[].sources 只说明「该设备用过哪些 agent」,
2748
+ * 并不提供按 agent 拆分的金额。因此**单 agent 设备**把整台设备的金额记到
2749
+ * 那一列;**多 agent 设备**无法拆分,格子留空并在表头标注「部分未拆分」,
2750
+ * 不编造数字(合计列仍按设备精确总额展示)。
2751
+ */
2752
+ function buildDeviceMatrix(dash) {
2753
+ if (!dash) return null;
2754
+ const rows = Array.isArray(dash.devices) ? dash.devices : [];
2755
+ const srcs = Array.isArray(dash.sources) ? dash.sources : [];
2756
+ const cols = Array.from(new Set(srcs.map(s => s && s.source).filter(Boolean)));
2757
+ if (!rows.length || !cols.length) return null;
2758
+ const grid = rows.map(r => {
2759
+ const list = (r.sources || []).filter(Boolean);
2760
+ const cells = {};
2761
+ if (list.length === 1) cells[list[0]] = { cost: Number(r.cost) || 0 };
2762
+ return Object.assign({}, r, { cells });
2763
+ });
2764
+ return {
2765
+ cols,
2766
+ rows: grid,
2767
+ totals: { cost: rows.reduce((s, r) => s + (Number(r.cost) || 0), 0) },
2768
+ unsplit: grid.some(r => Object.keys(r.cells).length !== ((r.sources || []).filter(Boolean).length)),
2769
+ };
2665
2770
  }
2666
2771
  /**
2667
2772
  * 云端「按天用量明细」(热力图数据源)。
@@ -2755,7 +2860,7 @@ window.__ModuleLoader__.load({
2755
2860
  useEffect(() => { loadDash(days); }, [days]);
2756
2861
  useEffect(() => { loadKimi(false); loadVolc(false); loadBalance(""); loadUsage(); loadSync(); }, []);
2757
2862
  // 视图切换:local+cloud 需要额外拉「排除本机」的云端聚合、矩阵与按天用量明细
2758
- useEffect(() => { loadCloud(days, view); loadCloudMatrix(days); loadCloudUsage(view); }, [view, days]);
2863
+ useEffect(() => { loadCloud(days, view); loadCloudUsage(view); }, [view, days]);
2759
2864
  useEffect(() => {
2760
2865
  const id = setInterval(() => setNow(Date.now()), 30000);
2761
2866
  return () => clearInterval(id);
@@ -2768,6 +2873,10 @@ window.__ModuleLoader__.load({
2768
2873
  : view === "cloud"
2769
2874
  ? cloudNorm
2770
2875
  : (cloudNorm ? mergeDash(dash, cloudNorm) : dash);
2876
+ // 设备 × Agent 矩阵:由 viewDash 的 devices/sources 就地派生(见 buildDeviceMatrix 注释),
2877
+ // 不再依赖宿主 `matrix` 路由 —— 该路由不存在,此前稳定 404 导致矩阵区块永不渲染。
2878
+ // 用派生值而非 state:viewDash / days / view 变化时自动重算,不必再手工触发了拉取。
2879
+ const viewMatrix = view === "local" ? null : buildDeviceMatrix(viewDash);
2771
2880
  // 热力图同样跟随三态视图:本机 / 本机+云端 / 仅云端。
2772
2881
  // 云端明细取不到时退回本机,并在标题右侧注明口径,避免与上方卡片数字打架。
2773
2882
  const viewUsage = view === "local"
@@ -2818,7 +2927,7 @@ window.__ModuleLoader__.load({
2818
2927
  sync && sync.enabled && sync.pending > 0 && view !== "local"
2819
2928
  ? e("div", { className: "cost-cloudnote" },
2820
2929
  "本机还有 " + sync.pending + " 条尚未同步,云端数字会偏小 —— ",
2821
- e("button", { className: "cost-btn", onClick: () => { apiCall("sync-now", {}).then(() => { loadSync(); loadCloud(days, view); loadCloudMatrix(days); loadCloudUsage(view); }); } }, "立即同步"))
2930
+ e("button", { className: "cost-btn", onClick: () => { apiCall("sync-now", {}).then(() => { loadSync(); loadCloud(days, view); loadCloudUsage(view); }); } }, "立即同步"))
2822
2931
  : null,
2823
2932
  cloudErr && view !== "local"
2824
2933
  ? e("div", { className: "cost-err", style: { marginTop: "6px" } }, "云端数据不可用(已显示本机数据):" + cloudErr)
@@ -2829,7 +2938,7 @@ window.__ModuleLoader__.load({
2829
2938
  dashErr ? e("div", { className: "cost-err", style: { marginTop: "8px" } }, dashErr) : null,
2830
2939
  (!viewDash && !dashErr) ? e("div", { className: "cost-hint", style: { marginTop: "12px" } }, "加载中…") : null,
2831
2940
  viewDash ? statCards(viewDash, balance, viewCtl, planTotal) : null,
2832
- view !== "local" && dimension !== "total" && viewDash ? dimensionPanel(viewDash, dimension, cloudMatrix, loadingCloud => loadingCloud) : null,
2941
+ view !== "local" && dimension !== "total" && viewDash ? dimensionPanel(viewDash, dimension, viewMatrix, loadingCloud => loadingCloud) : null,
2833
2942
  viewDash ? mainPanel(viewDash, tab, setTab, scheme, setScheme, planTotal) : null,
2834
2943
  e("div", { className: "cost-panel" },
2835
2944
  e("div", { className: "cost-row" },
@@ -2884,10 +2993,11 @@ window.__ModuleLoader__.load({
2884
2993
  e("span", { className: "cost-matrix-key", title: r.key }, r.key),
2885
2994
  e("span", { className: "cost-matrix-num" }, "¥" + fmtMoney(r.cost)),
2886
2995
  e("span", { className: "cost-matrix-num" }, fmtInt(r.calls)),
2887
- e("span", { className: "cost-matrix-num" }, fmtCompact(r.tokens)),
2996
+ e("span", { className: "cost-matrix-num" }, fmtTokens(r.tokens)),
2888
2997
  e("span", { className: "cost-matrix-note" }, r.tag || "")))),
2889
2998
  matrix && matrix.rows && e("div", { style: { marginTop: "10px" } },
2890
- e("div", { className: "cost-hint" }, "设备 × Agent 矩阵(行=设备,列=Agent,点击云端「设备 × Agent」页可下钻到记录)"),
2999
+ e("div", { className: "cost-hint" }, "设备 × Agent 矩阵(行=设备,列=Agent,点击云端「设备 × Agent」页可下钻到记录)"
3000
+ + (matrix.unsplit ? " · 多 Agent 设备无法按 Agent 拆分金额,未拆分格子留空(合计列仍为精确总额)" : "")),
2891
3001
  e("div", { className: "cost-matrix" },
2892
3002
  e("div", { className: "cost-matrix-row cost-matrix-head" },
2893
3003
  e("span", { className: "cost-matrix-key" }, "设备"),
package/config.js CHANGED
@@ -275,10 +275,27 @@ export function defaultBillingConfig() {
275
275
  // 多厂商目录匹配模式:fuzzy(归一化包含匹配,默认)/ exact(全等)
276
276
  priceMatch: 'fuzzy',
277
277
  // 目录价 USD→CNY 汇率(目录数据为 USD / 1M tokens,账本为 CNY)
278
- catalogFxRate: 7.2,
278
+ // v1.11.0:默认由 7.2 调整为 6.67(见 CATALOG_FX_DEFAULT)
279
+ catalogFxRate: 6.67,
279
280
  }
280
281
  }
281
282
 
283
+ /**
284
+ * 汇率迁移:老配置里存着「旧默认 7.2」说明用户从未改过,升级后跟随新默认;
285
+ * 用户显式设置的其它合法值(如 6.9)保持不变。
286
+ * @param {number} fx - 配置里的原始汇率
287
+ * @param {number} def - 当前默认汇率
288
+ * @returns {number}
289
+ */
290
+ export function migrateCatalogFxRate(fx, def) {
291
+ const base = Number.isFinite(Number(def)) && Number(def) > 0 ? Number(def) : 6.67
292
+ const v = Number(fx)
293
+ if (!Number.isFinite(v) || v < 0.1 || v > 100) return base
294
+ // 旧默认值(7.2)与其等价写法(7.20 / "7.2")一并视为「未改过」
295
+ if (Math.abs(v - 7.2) < 1e-9 && Math.abs(base - 7.2) >= 1e-9) return base
296
+ return v
297
+ }
298
+
282
299
  /**
283
300
  * 规范化双轨计费与价格目录配置。
284
301
  * planOverrides 键统一为小写(provider 与 model 各自归一化拼 '/'),
@@ -305,7 +322,8 @@ export function normalizeBillingConfig(raw) {
305
322
  showTotalWithPlan: raw.showTotalWithPlan === true,
306
323
  planOverrides,
307
324
  priceMatch: raw.priceMatch === 'exact' ? 'exact' : 'fuzzy',
308
- catalogFxRate: Number.isFinite(fx) && fx >= 0.1 && fx <= 100 ? fx : def.catalogFxRate,
325
+ // 旧默认 7.2 → 新默认 6.67:仅当配置值仍是旧默认时才迁移,用户自定义值保留
326
+ catalogFxRate: migrateCatalogFxRate(fx, def.catalogFxRate),
309
327
  }
310
328
  }
311
329