@angelyeye/dsh-cost-tracker 1.8.14 → 1.9.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
@@ -241,6 +241,31 @@ window.__ModuleLoader__.load({
241
241
  .cost-pcard-chevron { color: var(--dsw-alias-label-tertiary, #8b93a1); flex: none; transition: transform .16s; }
242
242
  .cost-pcard-chevron.is-open { transform: rotate(180deg); }
243
243
  .cost-pcard-body { border-top: .5px solid var(--dsw-alias-border-l2, #e5e7eb); margin: 0 16px; padding: 12px 0 10px; }
244
+ /* ---------- 插件配置卡片 v1.9.0:顶部状态条 + 折叠分组 ---------- */
245
+ .cost-cfg-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 2px 0 10px; }
246
+ .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; }
247
+ .cost-cfg-chip b { color: var(--dsw-alias-label-primary, #171a1f); font-weight: 600; font-variant-numeric: tabular-nums; }
248
+ .cost-cfg-chip.is-on { border-color: var(--dsw-alias-brand-primary, #2563eb); color: var(--dsw-alias-brand-primary, #2563eb); }
249
+ .cost-sec { border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); border-radius: 10px; margin-top: 10px; overflow: hidden; }
250
+ .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; }
251
+ .cost-sec-head:hover { background: var(--dsw-alias-bg-layer-2, transparent); }
252
+ .cost-sec-head:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #2563eb); outline-offset: -2px; }
253
+ .cost-sec-title { font-size: 13px; font-weight: 600; color: var(--dsw-alias-label-primary, #171a1f); flex: none; }
254
+ .cost-sec-sum { font-size: 12px; color: var(--dsw-alias-label-tertiary, #8b93a1); margin-left: auto; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
255
+ .cost-sec-arrow { color: var(--dsw-alias-label-tertiary, #8b93a1); flex: none; transition: transform .16s; }
256
+ .cost-sec-arrow.is-open { transform: rotate(180deg); }
257
+ .cost-sec-body { padding: 2px 12px 12px; }
258
+ .cost-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
259
+ .cost-tbl th, .cost-tbl td { text-align: left; padding: 4px 6px; border-bottom: .5px solid var(--dsw-alias-border-l2, #e5e7eb); }
260
+ .cost-tbl th { color: var(--dsw-alias-label-secondary, #5b6472); font-weight: 500; }
261
+ .cost-tbl tr:last-child td { border-bottom: 0; }
262
+ .cost-tbl .cost-num { text-align: right; font-variant-numeric: tabular-nums; }
263
+ .cost-kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 12px; align-items: center; }
264
+ .cost-kv .k { color: var(--dsw-alias-label-secondary, #5b6472); }
265
+ .cost-danger { color: var(--dsw-alias-status-error, #dc2626); }
266
+ .cost-plan-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dsw-alias-label-secondary, #5b6472); cursor: pointer; user-select: none; }
267
+ .cost-subblock { border-top: .5px dashed var(--dsw-alias-border-l2, #e5e7eb); margin-top: 10px; padding-top: 10px; }
268
+ .cost-list { font-size: 12px; color: var(--dsw-alias-label-secondary, #5b6472); line-height: 1.7; }
244
269
  `;
245
270
  const tag = document.createElement("style");
246
271
  tag.setAttribute("data-plugin-css", "cost-tracker-plugin");
@@ -763,7 +788,37 @@ window.__ModuleLoader__.load({
763
788
  const mergeDash = VIEW.mergeDash;
764
789
  const mergeUsageHeat = VIEW.mergeUsageHeat || vMergeUsageHeat;
765
790
 
766
- function filterRow(days, setDays, onExport, onRefresh, msg, busy, peakWindows, viewCtl) {
791
+ /**
792
+ * 双轨计费口径开关(v1.9.0):金额是否含 Plan 等值总额。
793
+ * off(默认)= 只算按量真金白银,订阅以附注展示(与 v1.8.x 一致);
794
+ * on = 金额 = 按量 + 订阅等值,图表也把订阅并入堆叠。
795
+ * 取值优先级:服务端配置 showTotalWithPlan → 浏览器 localStorage(跨设备各存各的)
796
+ * 用户一改就同时写两处:localStorage 立即可用,服务端让其它浏览器/看板默认一致。
797
+ */
798
+ const PLAN_TOTAL_KEY = "cost-tracker:showTotalWithPlan";
799
+ function planTotalInit(serverValue) {
800
+ try {
801
+ const ls = window.localStorage.getItem(PLAN_TOTAL_KEY);
802
+ if (ls === "1") return true;
803
+ if (ls === "0") return false;
804
+ } catch (_) { /* 隐私模式禁用 localStorage:回落服务端配置 */ }
805
+ return serverValue === true;
806
+ }
807
+ function planTotalStore(on) {
808
+ try { window.localStorage.setItem(PLAN_TOTAL_KEY, on ? "1" : "0"); } catch (_) {}
809
+ }
810
+
811
+ function planSwitch(planTotal, setPlanTotal) {
812
+ return e("label", { className: "cost-plan-switch", title: "开启后金额含订阅套餐等值费用(Plan 总额);关闭只统计按量真金白银" },
813
+ e("input", {
814
+ type: "checkbox",
815
+ checked: !!planTotal,
816
+ onChange: ev => setPlanTotal(ev.target.checked),
817
+ }),
818
+ e("span", null, "含 Plan 总额"));
819
+ }
820
+
821
+ function filterRow(days, setDays, onExport, onRefresh, msg, busy, peakWindows, viewCtl, onOpenVolc, planTotal, setPlanTotal) {
767
822
  const views = viewCtl && viewCtl.available ? BOARD_VIEWS : [BOARD_VIEWS[0]];
768
823
  return e("div", { className: "cost-row" },
769
824
  e("select", { className: "cost-select", value: String(days), onChange: ev => setDays(parseInt(ev.target.value, 10)) },
@@ -781,6 +836,11 @@ window.__ModuleLoader__.load({
781
836
  ? e("select", { className: "cost-select", value: viewCtl.dimension, onChange: ev => viewCtl.setDimension(ev.target.value), title: "维度:查看合计,或按机器 / Agent / 模型 / 项目拆分" },
782
837
  BOARD_DIMS.map(d => e("option", { key: d.id, value: d.id }, d.label)))
783
838
  : null,
839
+ // 火山方舟配额面板的入口:没配过凭据时面板默认不显示,没这个按钮用户就找不到入口
840
+ onOpenVolc
841
+ ? e("button", { className: "cost-btn", title: "配置火山方舟 AccessKeyID / SecretAccessKey 并查看 Coding Plan 配额", onClick: onOpenVolc }, "火山方舟配额")
842
+ : null,
843
+ planSwitch(planTotal, setPlanTotal),
784
844
  e("button", { className: "cost-btn", onClick: onExport, disabled: busy }, "导出 CSV"),
785
845
  e("button", { className: "cost-btn", onClick: onRefresh, disabled: busy }, busy ? "刷新中…" : "刷新"),
786
846
  msg ? e("span", { className: "cost-hint" }, msg) : null,
@@ -790,12 +850,22 @@ window.__ModuleLoader__.load({
790
850
  : e("span", { className: "cost-hint" }, "峰谷时段(北京时间):" + peakWindows + " · 闲时半价"));
791
851
  }
792
852
 
793
- function statCards(dash, balance, viewCtl) {
853
+ function statCards(dash, balance, viewCtl, planTotal) {
794
854
  const today = dash.today || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
795
855
  const month = dash.month || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
796
856
  const all = dash.all || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
797
- // 金额卡:主值为按量消费(不含订阅会员等效费用);副行附注订阅等效
798
- const moneySub = (t) => "调用 " + fmtInt(t.calls) + " 次 · Tokens " + fmtCompact(t.tokens) + (t.sub > 0 ? " · 订阅 ¥" + fmtMoney(t.sub) : "");
857
+ // 金额卡:口径由「含 Plan 总额」开关决定
858
+ // off:主值 = 按量消费(不含订阅会员等效费用);副行附注订阅等效
859
+ // on :主值 = 按量 + 订阅等值(Plan 总额);副行说明拆分,避免看数不明口径
860
+ const money = (t) => planTotal ? (Number(t.real) || 0) + (Number(t.sub) || 0) : (Number(t.real) || 0);
861
+ const moneySub = (t) => {
862
+ const base = "调用 " + fmtInt(t.calls) + " 次 · Tokens " + fmtCompact(t.tokens);
863
+ if (planTotal) {
864
+ return base + " · 含订阅 ¥" + fmtMoney(t.sub) + (t.subCalls ? "(" + fmtInt(t.subCalls) + " 次)" : "");
865
+ }
866
+ return base + (t.sub > 0 ? " · 订阅 ¥" + fmtMoney(t.sub) : "");
867
+ };
868
+ const planBadge = planTotal ? "(含 Plan)" : "";
799
869
  // 余额卡
800
870
  let balValue = "—", balSub = "查询中…";
801
871
  if (balance && balance.ok) {
@@ -815,9 +885,9 @@ window.__ModuleLoader__.load({
815
885
  : "本机";
816
886
  const tag = (t) => scopeNote + (viewCtl && viewCtl.pending > 0 && viewCtl.view !== "local" ? " · 待同步 " + viewCtl.pending + " 条" : "");
817
887
  return e("div", { className: "cost-cards" },
818
- statCard("今日费用(CNY)[" + tag() + "]", "¥" + fmtMoney(today.real), moneySub(today)),
819
- statCard("本月费用(CNY)", "¥" + fmtMoney(month.real), moneySub(month)),
820
- statCard("总花费(CNY)", "¥" + fmtMoney(all.real), "调用 " + fmtInt(all.calls) + " 次 · Tokens " + fmtCompact(all.tokens) + (all.sub > 0 ? " · 订阅 ¥" + fmtMoney(all.sub) : "")),
888
+ statCard("今日费用(CNY)" + planBadge + "[" + tag() + "]", "¥" + fmtMoney(money(today)), moneySub(today)),
889
+ statCard("本月费用(CNY)" + planBadge, "¥" + fmtMoney(money(month)), moneySub(month)),
890
+ statCard("总花费(CNY)" + planBadge, "¥" + fmtMoney(money(all)), "调用 " + fmtInt(all.calls) + " 次 · Tokens " + fmtCompact(all.tokens) + (all.sub > 0 ? (planTotal ? " · 含订阅 ¥" + fmtMoney(all.sub) : " · 订阅 ¥" + fmtMoney(all.sub)) : "")),
821
891
  statCard("API 请求次数", fmtInt(all.calls + all.subCalls),
822
892
  "按量 " + fmtInt(all.calls) + " · 订阅 " + fmtInt(all.subCalls)),
823
893
  statCard("Tokens", fmtInt(all.tokens + all.subTokens),
@@ -825,12 +895,17 @@ window.__ModuleLoader__.load({
825
895
  statCard("总余额(CNY)", balValue, balSub));
826
896
  }
827
897
 
828
- function mainPanel(dash, tab, setTab, scheme, setScheme) {
898
+ function mainPanel(dash, tab, setTab, scheme, setScheme, planTotal) {
829
899
  let chart = null;
830
900
  let legend = [];
831
901
  const labels = dash.byDay.map(d => d.label);
832
902
  const titles = dash.byDay.map(d => d.date);
833
903
  const fmtMoneyValue = (v) => "¥" + fmtMoney(v);
904
+ // 含 Plan 总额:订阅等值按天并入图(byDay[].sub 由服务端单独给出),
905
+ // 作为独立图例项而不是混进峰谷段 —— 订阅本就不分峰谷,混进去会污染时段口径。
906
+ const subTotal = dash.byDay.reduce((s, d) => s + (Number(d.sub) || 0), 0);
907
+ const showSub = !!planTotal && subTotal > 0;
908
+ const totalCost = planTotal ? (Number(dash.realCost) || 0) + (Number(dash.subEquivalent) || 0) : (Number(dash.realCost) || 0);
834
909
  if (tab === "period") {
835
910
  // 图例只列真实存在的档位:官方定价只有「高峰 / 闲时」两档;
836
911
  // flat(不分峰谷:订阅套餐、非 DeepSeek provider 兜底价等)**为 0 时不占图例位置**——
@@ -838,16 +913,20 @@ window.__ModuleLoader__.load({
838
913
  const flatTotal = dash.byDay.reduce((s, d) => s + (Number(d.flat) || 0), 0);
839
914
  const hasFlat = flatTotal > 0;
840
915
  const segs = [{ name: "闲时", color: BLUE }, { name: "高峰", color: AMBER }]
841
- .concat(hasFlat ? [{ name: "不分峰谷", color: GRAY }] : []);
842
- const rows = dash.byDay.map(d => hasFlat ? [d.off, d.peak, d.flat] : [d.off, d.peak]);
916
+ .concat(hasFlat ? [{ name: "不分峰谷", color: GRAY }] : [])
917
+ .concat(showSub ? [{ name: "订阅等值", color: GREEN }] : []);
918
+ const rows = dash.byDay.map(d => {
919
+ const base = hasFlat ? [d.off, d.peak, d.flat] : [d.off, d.peak];
920
+ return showSub ? base.concat([d.sub || 0]) : base;
921
+ });
843
922
  chart = e(StackedBarsChart, { labels, titles, segs, rows, fmtY: fmtAxisMoney, fmtValue: fmtMoneyValue });
844
923
  legend = segs;
845
924
  } else {
846
925
  // 模型按总消费降序排名(byModelDay 已按费用降序),全部展示、不合并、不循环:
847
926
  // 第 1 名取色阶首色(最深,垫底),名次越靠后越浅;色相按所选方案漂移
848
- const models = dash.byModelDay.filter(m => !m.subscription);
927
+ const models = dash.byModelDay.filter(m => planTotal || !m.subscription);
849
928
  const sc = COLOR_SCHEMES[scheme] || COLOR_SCHEMES["orange-yellow"];
850
- const segs = models.map((m, i) => ({ name: shortModel(m.model), color: schemeColor(i, sc) }));
929
+ const segs = models.map((m, i) => ({ name: shortModel(m.model) + (m.subscription ? "(订阅)" : ""), color: schemeColor(i, sc) }));
851
930
  const daySegs = dash.byDay.map((d, di) => {
852
931
  const list = [];
853
932
  for (let i = 0; i < models.length; i++) {
@@ -861,7 +940,7 @@ window.__ModuleLoader__.load({
861
940
  }
862
941
  return e("div", { className: "cost-panel" },
863
942
  e("div", { className: "cost-row" },
864
- e("span", { className: "cost-panel-title" }, "消费金额(CNY)¥" + fmtMoney(dash.realCost)),
943
+ e("span", { className: "cost-panel-title" }, "消费金额(CNY)¥" + fmtMoney(totalCost) + (planTotal ? "(含 Plan 总额)" : "")),
865
944
  tab === "model" ? e("span", { style: { display: "inline-flex", alignItems: "center", gap: "4px", marginLeft: "10px" } },
866
945
  Object.keys(COLOR_SCHEMES).map(k => e("button", {
867
946
  key: k,
@@ -937,7 +1016,33 @@ window.__ModuleLoader__.load({
937
1016
  resetsAt ? e("div", { className: "cost-hint", style: { marginTop: "4px" } }, countdown(resetsAt, now)) : null);
938
1017
  }
939
1018
 
940
- function volcenginePanel(volc, dash, now, onForce) {
1019
+ // 火山方舟凭据输入区(面板自带,不必去翻插件配置卡片或手写环境变量)。
1020
+ // AK 明文回显(控制台里本就可见);SK 从不回显,已存过时只提示「已保存」。
1021
+ function volcCredForm(cred, hasSecret, onQuery, onSave, onClear) {
1022
+ const busy = cred.busy;
1023
+ return e("div", { style: { marginTop: "10px" } },
1024
+ e("div", { className: "cost-row", style: { gap: "6px", flexWrap: "wrap" } },
1025
+ e("input", {
1026
+ className: "cost-input", placeholder: "火山引擎 AccessKeyID",
1027
+ value: cred.id, spellCheck: false, autoComplete: "off",
1028
+ onChange: ev => cred.setId(ev.target.value),
1029
+ }),
1030
+ e("input", {
1031
+ className: "cost-input", type: "password", spellCheck: false, autoComplete: "new-password",
1032
+ placeholder: hasSecret ? "SecretAccessKey(已保存,留空则不改)" : "火山引擎 SecretAccessKey",
1033
+ value: cred.secret,
1034
+ onChange: ev => cred.setSecret(ev.target.value),
1035
+ }),
1036
+ e("button", { className: "cost-btn", disabled: busy, onClick: onQuery }, busy ? "查询中…" : "查询"),
1037
+ e("button", { className: "cost-btn", disabled: busy, onClick: onSave }, "保存"),
1038
+ hasSecret || cred.id ? e("button", { className: "cost-btn", disabled: busy, onClick: onClear }, "清除凭据") : null),
1039
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
1040
+ "配额查询走方舟**管控面** OpenAPI,需要 IAM 的 AccessKeyID / SecretAccessKey"
1041
+ + "(子用户授予 ArkReadOnlyAccess + BillingCenterReadOnlyAccess);"
1042
+ + "它与推理用的 ARK API Key 是**两套不同凭据**。保存后写入本机插件配置,重启不丢。"));
1043
+ }
1044
+
1045
+ function volcenginePanel(volc, dash, now, onForce, credForm) {
941
1046
  const ok = volc && volc.ok;
942
1047
  let body;
943
1048
  if (!volc) {
@@ -945,11 +1050,10 @@ window.__ModuleLoader__.load({
945
1050
  } else if (!volc.ok) {
946
1051
  body = e("div", { style: { marginTop: "8px" } },
947
1052
  e("div", { className: "cost-err" }, "配额查询不可用:" + (volc.error || "未知错误")),
948
- e("div", { className: "cost-hint", style: { marginTop: "4px" } },
949
- "配额查询走方舟**管控面** OpenAPI,需要火山引擎 AccessKeyID / SecretAccessKey"
950
- + "(IAM 子用户授予 ArkReadOnlyAccess + BillingCenterReadOnlyAccess),"
951
- + "与推理用的 ARK API Key 是两套凭据。当前尝试的变量:" + (volc.keyEnv || "未知")
952
- + "(来源:" + (volc.keySource || "无") + ")。"));
1053
+ volc.keyEnv && volc.keySource !== "none"
1054
+ ? e("div", { className: "cost-hint", style: { marginTop: "4px" } },
1055
+ "本次尝试的凭据来源:" + volc.keyEnv + "(" + volc.keySource + ")。")
1056
+ : null);
953
1057
  } else {
954
1058
  const list = volc.windowList || [];
955
1059
  if (list.length === 0) {
@@ -965,9 +1069,11 @@ window.__ModuleLoader__.load({
965
1069
  e("div", { className: "cost-row" },
966
1070
  e("span", { className: "cost-panel-title" }, "订阅套餐用量 · 火山方舟 Coding Plan"),
967
1071
  ok && volc.action ? e("span", { className: "cost-badge" }, volc.action) : null,
1072
+ ok ? e("span", { className: "cost-badge" }, volc.keySource === "config" ? "已保存凭据" : volc.keySource === "manual" ? "临时凭据" : "环境变量") : null,
968
1073
  e("span", { className: "cost-spacer" }),
969
1074
  e("button", { className: "cost-btn", onClick: onForce }, "刷新配额")),
970
1075
  body,
1076
+ credForm,
971
1077
  e("div", { className: "cost-hint", style: { marginTop: "10px" } },
972
1078
  "订阅用量统计:" + stats + "(订阅已覆盖,等效费用仅供参考)"));
973
1079
  }
@@ -1399,97 +1505,50 @@ window.__ModuleLoader__.load({
1399
1505
  }
1400
1506
 
1401
1507
  // 设置面板:峰谷计价与提示
1508
+ /**
1509
+ * 「峰谷计价与提示」看板面板(v1.9.0 起**只读**)。
1510
+ * 设置入口统一到「设置 → 插件 → 插件配置 → 花费统计 → 峰谷计价与提示」,
1511
+ * 这里只回显当前档位与生效配置,避免两处都能改造成口径不一致。
1512
+ * 预览按钮保留:它只是本地弹窗预览,不改任何持久化状态。
1513
+ */
1402
1514
  function PeakPanel(props) {
1403
1515
  const [snap, setSnap] = useState(null);
1404
- const [draft, setDraft] = useState(null);
1405
1516
  const [now, setNow] = useState(Date.now());
1406
- const [savedMsg, setSavedMsg] = useState("");
1407
1517
  function load() {
1408
- apiCall("peak", {}).then(v => {
1409
- if (v && v.ok) {
1410
- setSnap(v);
1411
- setDraft(Object.assign({}, v.config || {}));
1412
- }
1413
- }).catch(() => {});
1518
+ apiCall("peak", {}).then(v => { if (v && v.ok) setSnap(v); }).catch(() => {});
1414
1519
  }
1415
1520
  useEffect(() => { load(); }, []);
1416
1521
  useEffect(() => {
1417
1522
  const id = setInterval(() => setNow(Date.now()), 30000);
1418
1523
  return () => clearInterval(id);
1419
1524
  }, []);
1420
- function setField(k, v) {
1421
- setDraft(d => Object.assign({}, d, { [k]: v }));
1422
- }
1423
- function save() {
1424
- apiCall("peak-config", draft || {}).then(v => {
1425
- if (v && typeof v === 'object') {
1426
- setSnap(s => Object.assign({}, s, { config: v, enabled: v.peakEnabled, notice: v.peakNotice, style: v.peakStyle, alert: { enabled: v.peakAlertEnabled, ahead: v.peakAlertAhead, target: v.peakAlertTarget, position: v.peakAlertPosition, webNotify: v.peakAlertWebNotify } }));
1427
- setDraft(Object.assign({}, v));
1428
- setSavedMsg("已保存");
1429
- setTimeout(() => setSavedMsg(""), 2000);
1430
- }
1431
- }).catch(() => setSavedMsg("保存失败"));
1432
- }
1433
1525
  function preview(kind) {
1434
1526
  window.dispatchEvent(new CustomEvent(PEAK_PREVIEW_EVENT, { detail: { kind } }));
1435
1527
  }
1436
- const d = draft || {};
1437
- const cfgSnap = snap ? Object.assign({}, snap, { config: d }) : null;
1438
- const noticeOn = snap && snap.notice !== false && d.peakNotice !== false;
1528
+ const cfg = (snap && snap.config) || {};
1529
+ const noticeOn = snap && snap.notice !== false && cfg.peakNotice !== false;
1530
+ const rows = [
1531
+ ["峰谷计价", cfg.peakEnabled !== false ? "已启用" : "已停用"],
1532
+ ["时段条样式", cfg.peakStyle === "classic" ? "环形表盘(24h)" : "简洁(单行紧凑)"],
1533
+ ["切换提醒", cfg.peakAlertEnabled !== false ? ("提前 " + (cfg.peakAlertAhead == null ? 2 : cfg.peakAlertAhead) + " 分钟 · " + (cfg.peakAlertTarget === "peak" ? "进入峰时" : cfg.peakAlertTarget === "offpeak" ? "进入谷时" : "峰和谷")) : "已关闭"],
1534
+ ["系统通知", cfg.peakAlertWebNotify === true ? "已开启" : "未开启"],
1535
+ ["当前档位", snap && snap.phase ? (snap.phase.weekend ? "周末全谷价" : snap.phase.inPeak ? "高峰时段" : "平价时段") : "…"],
1536
+ ];
1439
1537
  return e("div", { className: "cost-panel" },
1440
1538
  e("div", { className: "cost-row" },
1441
1539
  e("span", { className: "cost-panel-title" }, "峰谷计价与提示"),
1442
1540
  e("span", { className: "cost-spacer" }),
1443
- e("button", { className: "cost-btn", onClick: save, disabled: !draft }, "保存设置")),
1444
- e("div", { style: { marginTop: "8px", display: "grid", gap: "6px" } },
1445
- e("label", { className: "cost-row", style: { gap: "8px" } },
1446
- e("input", { type: "checkbox", checked: d.peakEnabled !== false, onChange: ev => setField("peakEnabled", ev.target.checked) }),
1447
- e("span", null, "启用 DeepSeek 峰谷时段价格")),
1448
- e("label", { className: "cost-row", style: { gap: "8px" } },
1449
- e("input", { type: "checkbox", checked: d.peakNotice !== false, onChange: ev => setField("peakNotice", ev.target.checked) }),
1450
- e("span", null, "峰时高价时段显著提示(时段条显示)")),
1451
- e("div", { className: "cost-row", style: { gap: "8px" } },
1452
- e("span", null, "时段条样式"),
1453
- e("select", { className: "cost-select", value: d.peakStyle === "classic" ? "classic" : "compact", onChange: ev => setField("peakStyle", ev.target.value) },
1454
- e("option", { value: "compact" }, "简洁(单行紧凑)"),
1455
- e("option", { value: "classic" }, "环形表盘(24h)"))),
1456
- d.peakStyle === "classic" ? e("label", { className: "cost-row", style: { gap: "8px" } },
1457
- e("input", { type: "checkbox", checked: d.peakShowTickLabels !== false, onChange: ev => setField("peakShowTickLabels", ev.target.checked) }),
1458
- e("span", null, "显示时间(00:00–21:00 刻度)"))
1459
- : e("label", { className: "cost-row", style: { gap: "8px" } },
1460
- e("input", { type: "checkbox", checked: d.peakCompactStack === true, onChange: ev => setField("peakCompactStack", ev.target.checked) }),
1461
- e("span", null, "双行紧凑(上下布局)"),
1462
- d.peakCompactStack === true ? e("select", { className: "cost-select", value: d.peakCompactOrder === "text-first" ? "text-first" : "bar-first", onChange: ev => setField("peakCompactOrder", ev.target.value) },
1463
- e("option", { value: "bar-first" }, "时段条在上·文字在下"),
1464
- e("option", { value: "text-first" }, "文字在上·时段条在下"))
1465
- : null),
1466
- e("label", { className: "cost-row", style: { gap: "8px" } },
1467
- e("input", { type: "checkbox", checked: d.peakAlertEnabled !== false, onChange: ev => setField("peakAlertEnabled", ev.target.checked) }),
1468
- e("span", null, "峰/谷切换前弹窗提醒")),
1469
- d.peakAlertEnabled !== false ? e("div", { className: "cost-row", style: { gap: "8px" } },
1470
- e("span", null, "提前提醒(分钟,1-30)"),
1471
- e("input", { className: "cost-input", style: { width: "80px" }, type: "number", min: 1, max: 30, value: String(d.peakAlertAhead == null ? 2 : d.peakAlertAhead), onChange: ev => { const n = parseInt(ev.target.value, 10); if (Number.isInteger(n) && n >= 1 && n <= 30) setField("peakAlertAhead", n); } }),
1472
- e("span", null, "提醒类型"),
1473
- e("select", { className: "cost-select", value: d.peakAlertTarget === "peak" || d.peakAlertTarget === "offpeak" ? d.peakAlertTarget : "both", onChange: ev => setField("peakAlertTarget", ev.target.value) },
1474
- e("option", { value: "both" }, "峰和谷"),
1475
- e("option", { value: "peak" }, "进入峰时"),
1476
- e("option", { value: "offpeak" }, "进入谷时")),
1477
- e("span", null, "弹窗位置"),
1478
- e("select", { className: "cost-select", value: d.peakAlertPosition === "center" ? "center" : "corner", onChange: ev => setField("peakAlertPosition", ev.target.value) },
1479
- e("option", { value: "corner" }, "右下角"),
1480
- e("option", { value: "center" }, "屏幕中心")))
1481
- : null,
1482
- e("label", { className: "cost-row", style: { gap: "8px" } },
1483
- e("input", { type: "checkbox", checked: d.peakAlertWebNotify === true, onChange: ev => setField("peakAlertWebNotify", ev.target.checked) }),
1484
- e("span", null, "同步发送系统通知(需授权通知权限)")),
1485
- e("div", { className: "cost-row", style: { gap: "8px", marginTop: "4px" } },
1486
- e("span", null, "预览弹窗"),
1487
- e("button", { className: "cost-btn", onClick: () => preview("peak") }, "预览进入峰"),
1488
- e("button", { className: "cost-btn", onClick: () => preview("offpeak") }, "预览进入谷"),
1489
- savedMsg ? e("span", { className: "cost-hint" }, savedMsg) : null),
1490
- e("div", { className: "cost-hint", style: { marginTop: "6px" } },
1491
- "峰时段(北京时间):" + (snap ? snap.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)") + "。生效时间:" + (snap ? snap.effectiveAt : "2026-08-01T00:00:00Z") + "。当前:" + (cfgSnap && cfgSnap.phase ? (cfgSnap.phase.weekend ? "周末全谷价" : cfgSnap.phase.inPeak ? "高峰时段" : "平价时段") : "…"))),
1492
- noticeOn ? e("div", { style: { marginTop: "8px" } }, e(PeakStrip, { snap: cfgSnap, style: d.peakStyle || "compact", wide: true, now, ringSize: 150 }))
1541
+ e("button", { className: "cost-btn", onClick: () => preview("peak") }, "预览进入峰"),
1542
+ e("button", { className: "cost-btn", onClick: () => preview("offpeak") }, "预览进入谷"),
1543
+ e("button", { className: "cost-btn", onClick: load }, "刷新")),
1544
+ e("div", { className: "cost-sync-ro", style: { marginTop: "8px" } },
1545
+ rows.map(r => e("div", { key: "pk" + r[0], className: "cost-row", style: { gap: "8px" } },
1546
+ e("span", { className: "k", style: { minWidth: "90px" } }, r[0]),
1547
+ e("span", { className: "v" }, r[1])))),
1548
+ e("div", { className: "cost-hint", style: { marginTop: "6px" } },
1549
+ "峰时段(北京时间):" + (snap ? snap.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)") +
1550
+ "。当前:" + (snap && snap.phase ? (snap.phase.weekend ? "周末全谷价" : snap.phase.inPeak ? "高峰时段" : "平价时段") : "…")),
1551
+ noticeOn ? e("div", { style: { marginTop: "8px" } }, e(PeakStrip, { snap, style: cfg.peakStyle || "compact", wide: true, now, ringSize: 150 }))
1493
1552
  : e("p", { className: "cost-hint", style: { marginTop: "8px" } }, "提示已隐藏:需启用峰谷计价并开启「峰时高价时段显著提示」。"),
1494
1553
  e(SyncReadonlyCard, { sync: props.sync }));
1495
1554
  }
@@ -1536,15 +1595,47 @@ window.__ModuleLoader__.load({
1536
1595
  // ============================================================
1537
1596
  function PluginConfigCard() {
1538
1597
  const [st, setSt] = useState(null);
1598
+ const [prices, setPrices] = useState(null);
1599
+ const [imp, setImp] = useState(null);
1600
+ const [peakSnap, setPeakSnap] = useState(null);
1539
1601
  const [draft, setDraft] = useState({});
1540
- const [msg, setMsg] = useState("");
1541
- const [busy, setBusy] = useState(false);
1542
- const [testing, setTesting] = useState("");
1543
- // 界面显示三开关(独立于云端同步草稿:勾选即刻生效并落盘)
1602
+ // 分组草稿(各自独立保存;互不覆盖)
1603
+ const [peakDraft, setPeakDraft] = useState({});
1604
+ const [bill, setBill] = useState({ showTotalWithPlan: false, priceMatch: "fuzzy", catalogFxRate: 7.2, planRows: [], priceRows: [] });
1605
+ const [psDraft, setPsDraft] = useState({ priceSyncUrl: "", priceSyncAutoCheck: true });
1606
+ const [impDraft, setImpDraft] = useState({ autoImport: true });
1607
+ const [volcId, setVolcId] = useState("");
1608
+ const [volcSecret, setVolcSecret] = useState("");
1609
+ const [volcHasSecret, setVolcHasSecret] = useState(false);
1610
+ const [volcBackend, setVolcBackend] = useState("");
1611
+ const [volcData, setVolcData] = useState(null);
1612
+ const [recomputeRes, setRecomputeRes] = useState(null);
1613
+ const [confirmClear, setConfirmClear] = useState(false);
1614
+ const [msg, setMsg] = useState({});
1615
+ const [busy, setBusy] = useState("");
1616
+ const [now, setNow] = useState(Date.now());
1617
+ // 界面显示三开关(独立于其它草稿:勾选即刻生效并落盘)
1544
1618
  const [uiDraft, setUiDraft] = useState({ uiDockEnabled: true, uiPeakEnabled: true, uiDashboardEnabled: true });
1545
1619
  const [uiMsg, setUiMsg] = useState("");
1546
1620
  // 折叠态:与宿主「插件配置」里其它卡片一致——默认收起,点标题展开
1547
1621
  const [open, setOpen] = useState(false);
1622
+ // 当前展开的分组(手风琴;默认展开「多机汇总」,其余收起)
1623
+ const [openSec, setOpenSec] = useState("cloud");
1624
+ function say(group, text) {
1625
+ setMsg(prev => Object.assign({}, prev, { [group]: text }));
1626
+ setTimeout(() => setMsg(prev => Object.assign({}, prev, { [group]: "" })), 4000);
1627
+ }
1628
+ function loadPrices() {
1629
+ apiCall("prices", {}).then(v => { if (v && v.ok) setPrices(v); }).catch(() => {});
1630
+ }
1631
+ function loadImport() {
1632
+ apiCall("import-status", {}).then(v => { if (v && v.ok) setImp(v); }).catch(() => {});
1633
+ }
1634
+ function loadPeak() {
1635
+ apiCall("peak", {}).then(v => {
1636
+ if (v && v.ok) { setPeakSnap(v); setPeakDraft(Object.assign({}, v.config || {})); }
1637
+ }).catch(() => {});
1638
+ }
1548
1639
  function load() {
1549
1640
  apiCall("sync", {}).then(v => {
1550
1641
  if (!v) return;
@@ -1555,8 +1646,11 @@ window.__ModuleLoader__.load({
1555
1646
  cloudUrl: v.url || "",
1556
1647
  cloudToken: "",
1557
1648
  syncIntervalSec: v.intervalSec || 60,
1649
+ syncBatchSize: v.syncBatchSize || 500,
1558
1650
  maskSessionId: !!v.maskSessionId,
1559
1651
  includePurpose: v.includePurpose !== false,
1652
+ syncRollups: v.syncRollups !== false,
1653
+ syncSinceDays: typeof v.syncSinceDays === "number" ? v.syncSinceDays : 180,
1560
1654
  cloudView: v.view || "local",
1561
1655
  });
1562
1656
  // 界面显示:缺省视为可见(与 normalizeUiConfig 同一真值语义)
@@ -1565,40 +1659,168 @@ window.__ModuleLoader__.load({
1565
1659
  uiPeakEnabled: v.uiPeakEnabled !== false,
1566
1660
  uiDashboardEnabled: v.uiDashboardEnabled !== false,
1567
1661
  });
1662
+ setBill({
1663
+ showTotalWithPlan: v.showTotalWithPlan === true,
1664
+ priceMatch: v.priceMatch === "exact" ? "exact" : "fuzzy",
1665
+ catalogFxRate: typeof v.catalogFxRate === "number" ? v.catalogFxRate : 7.2,
1666
+ planRows: planOverridesToRows(v.planOverrides),
1667
+ priceRows: priceOverridesToRows(v.priceOverrides),
1668
+ });
1669
+ setPsDraft({ priceSyncUrl: v.priceSyncUrl || "", priceSyncAutoCheck: v.priceSyncAutoCheck !== false });
1670
+ setImpDraft({ autoImport: v.autoImport !== false });
1671
+ if (typeof v.volcengineAccessKeyId === "string" && v.volcengineAccessKeyId) setVolcId(prev => prev || v.volcengineAccessKeyId);
1672
+ setVolcHasSecret(!!v.volcengineHasSecret);
1673
+ setVolcBackend(v.volcengineSecretBackend || "");
1568
1674
  }).catch(() => {});
1675
+ loadPrices();
1676
+ loadImport();
1677
+ loadPeak();
1569
1678
  }
1570
1679
  useEffect(() => { load(); }, []);
1680
+ useEffect(() => {
1681
+ const id = setInterval(() => setNow(Date.now()), 30000);
1682
+ return () => clearInterval(id);
1683
+ }, []);
1571
1684
  const set = (k, v) => setDraft(prev => Object.assign({}, prev, { [k]: v }));
1685
+ const setPeak = (k, v) => setPeakDraft(prev => Object.assign({}, prev, { [k]: v }));
1686
+ const setBillField = (k, v) => setBill(prev => Object.assign({}, prev, { [k]: v }));
1572
1687
  const field = (label, node, hint) => [
1573
1688
  e("span", { key: "k" + label, className: "k" }, label),
1574
1689
  e("span", { key: "v" + label }, node, hint ? e("span", { className: "cost-hint", style: { marginLeft: "8px" } }, hint) : null),
1575
1690
  ];
1691
+ // ---------- 各分组动作 ----------
1576
1692
  function save() {
1577
- setBusy(true); setMsg("");
1693
+ setBusy("cloud"); say("cloud", "");
1578
1694
  const patch = Object.assign({}, draft);
1579
1695
  if (!patch.cloudToken) delete patch.cloudToken; // 留空 = 不改令牌
1580
1696
  if (!patch.cloudUrl) patch.cloudEnabled = false;
1581
1697
  apiCall("sync-config", patch).then(v => {
1582
- setBusy(false);
1583
- setMsg(v && v.ok ? "已保存" : "保存失败:" + ((v && v.error) || "未知错误"));
1698
+ setBusy("");
1699
+ say("cloud", v && v.ok ? "已保存" : "保存失败:" + ((v && v.error) || "未知错误"));
1584
1700
  load();
1585
- }).catch(err => { setBusy(false); setMsg("保存失败:" + String(err && err.message ? err.message : err)); });
1701
+ }).catch(err => { setBusy(""); say("cloud", "保存失败:" + String(err && err.message ? err.message : err)); });
1586
1702
  }
1587
1703
  function test() {
1588
- setBusy(true); setTesting("测试中…");
1704
+ setBusy("cloud"); say("cloud", "测试中…");
1589
1705
  apiCall("sync-test", { config: Object.assign({}, draft, { cloudToken: draft.cloudToken || undefined }) }).then(v => {
1590
- setBusy(false);
1591
- setTesting(v && v.ok ? ("连接正常 · 服务端 " + (v.serviceVersion || "?") + (v.selfRegister ? " · 允许自注册" : "")) : ("连接失败:" + ((v && v.error) || "未知错误")));
1592
- }).catch(err => { setBusy(false); setTesting("连接失败:" + String(err && err.message ? err.message : err)); });
1706
+ setBusy("");
1707
+ say("cloud", v && v.ok ? ("连接正常 · 服务端 " + (v.serviceVersion || "?") + (v.selfRegister ? " · 允许自注册" : "")) : ("连接失败:" + ((v && v.error) || "未知错误")));
1708
+ }).catch(err => { setBusy(""); say("cloud", "连接失败:" + String(err && err.message ? err.message : err)); });
1593
1709
  }
1594
1710
  function syncNow(full) {
1595
- setBusy(true); setMsg("同步中…");
1711
+ setBusy("cloud"); say("cloud", "同步中…");
1596
1712
  apiCall("sync-now", full ? { full: true } : {}).then(v => {
1597
- setBusy(false);
1713
+ setBusy("");
1598
1714
  const r = (v && v.result) || {};
1599
- setMsg(r.error ? ("同步失败:" + r.error) : ("已同步:新增 " + (r.accepted || 0) + " · 去重 " + (r.duplicates || 0) + " · 日汇总 " + (r.rollups || 0)));
1715
+ say("cloud", r.error ? ("同步失败:" + r.error) : ("已同步:新增 " + (r.accepted || 0) + " · 去重 " + (r.duplicates || 0) + " · 日汇总 " + (r.rollups || 0)));
1716
+ load();
1717
+ }).catch(err => { setBusy(""); say("cloud", "同步失败:" + String(err && err.message ? err.message : err)); });
1718
+ }
1719
+ /** 峰谷计价与提示:只作用于界面提示与档位判定,不改历史记录 */
1720
+ function savePeak() {
1721
+ setBusy("peak"); say("peak", "");
1722
+ apiCall("peak-config", peakDraft || {}).then(v => {
1723
+ setBusy("");
1724
+ if (v && typeof v === "object") {
1725
+ setPeakDraft(Object.assign({}, v));
1726
+ setPeakSnap(s => Object.assign({}, s, {
1727
+ config: v, enabled: v.peakEnabled, notice: v.peakNotice, style: v.peakStyle,
1728
+ alert: { enabled: v.peakAlertEnabled, ahead: v.peakAlertAhead, target: v.peakAlertTarget, position: v.peakAlertPosition, webNotify: v.peakAlertWebNotify },
1729
+ }));
1730
+ say("peak", "已保存");
1731
+ } else say("peak", "保存失败");
1732
+ }).catch(err => { setBusy(""); say("peak", "保存失败:" + String(err && err.message ? err.message : err)); });
1733
+ }
1734
+ /** 计价与目录:口径开关 + 目录匹配 + 覆盖价(含订阅归类) */
1735
+ function saveBilling() {
1736
+ setBusy("bill"); say("bill", "");
1737
+ apiCall("billing-config", {
1738
+ showTotalWithPlan: !!bill.showTotalWithPlan,
1739
+ priceMatch: bill.priceMatch === "exact" ? "exact" : "fuzzy",
1740
+ catalogFxRate: Number(bill.catalogFxRate) || 7.2,
1741
+ planOverrides: planRowsToObj(bill.planRows),
1742
+ priceOverrides: priceRowsToObj(bill.priceRows),
1743
+ }).then(v => {
1744
+ setBusy("");
1745
+ say("bill", v && v.ok ? "已保存(对之后入库的记录生效)" : "保存失败:" + ((v && v.error) || "未知错误"));
1746
+ loadPrices();
1747
+ }).catch(err => { setBusy(""); say("bill", "保存失败:" + String(err && err.message ? err.message : err)); });
1748
+ }
1749
+ function savePriceSync() {
1750
+ setBusy("bill"); say("bill", "");
1751
+ apiCall("prices-config", { priceSyncUrl: psDraft.priceSyncUrl, priceSyncAutoCheck: !!psDraft.priceSyncAutoCheck }).then(v => {
1752
+ setBusy("");
1753
+ say("bill", v && v.ok ? "已保存" : "保存失败:" + ((v && v.error) || "未知错误"));
1754
+ }).catch(err => { setBusy(""); say("bill", "保存失败:" + String(err && err.message ? err.message : err)); });
1755
+ }
1756
+ function runPriceSync(apply) {
1757
+ setBusy("price"); say("price", apply ? "抓取并应用中…" : "核对中…");
1758
+ apiCall("prices-sync", { apply: !!apply }).then(v => {
1759
+ setBusy("");
1760
+ if (!v || v.ok !== true) { say("price", "失败:" + ((v && v.error) || "未知错误")); return; }
1761
+ say("price", v.applied ? ("已应用新价:" + (v.era || "")) : (v.diff ? ("发现差异:" + v.diff) : "与当前生效价一致"));
1762
+ loadPrices();
1763
+ }).catch(err => { setBusy(""); say("price", "失败:" + String(err && err.message ? err.message : err)); });
1764
+ }
1765
+ function saveImportCfg() {
1766
+ setBusy("imp"); say("imp", "");
1767
+ apiCall("import-config", { autoImport: !!impDraft.autoImport }).then(v => {
1768
+ setBusy("");
1769
+ say("imp", v && v.ok ? "已保存" : "保存失败:" + ((v && v.error) || "未知错误"));
1770
+ }).catch(err => { setBusy(""); say("imp", "保存失败:" + String(err && err.message ? err.message : err)); });
1771
+ }
1772
+ function runImport() {
1773
+ setBusy("imp"); say("imp", "扫描会话日志…");
1774
+ apiCall("import-run", {}).then(v => {
1775
+ setBusy("");
1776
+ say("imp", v && v.ok ? ("完成:扫描 " + v.scanned + " 个日志,新增 " + v.imported + " 条") : ("失败:" + ((v && v.error) || "未知错误")));
1777
+ loadImport();
1778
+ }).catch(err => { setBusy(""); say("imp", "失败:" + String(err && err.message ? err.message : err)); });
1779
+ }
1780
+ function runRecompute(apply) {
1781
+ setBusy("data"); say("data", apply ? "重算并写回…" : "试算中…");
1782
+ apiCall("recompute", { apply: !!apply }).then(v => {
1783
+ setBusy("");
1784
+ if (!v || v.ok !== true) { say("data", "失败:" + ((v && v.error) || "未知错误")); return; }
1785
+ setRecomputeRes(v);
1786
+ say("data", v.note || (apply ? "已重算" : "试算完成"));
1787
+ }).catch(err => { setBusy(""); say("data", "失败:" + String(err && err.message ? err.message : err)); });
1788
+ }
1789
+ function exportCsv() {
1790
+ setBusy("data"); say("data", "导出中…");
1791
+ apiCall("export", {}).then(v => {
1792
+ setBusy("");
1793
+ say("data", v && v.ok ? "已导出 " + v.count + " 条到 " + v.path : "导出失败:" + ((v && v.error) || "未知错误"));
1794
+ }).catch(err => { setBusy(""); say("data", "导出失败:" + String(err && err.message ? err.message : err)); });
1795
+ }
1796
+ function clearData() {
1797
+ setBusy("data"); say("data", "清空中…");
1798
+ apiCall("reset", {}).then(v => {
1799
+ setBusy(""); setConfirmClear(false);
1800
+ say("data", v && v.ok ? ("已清空 " + v.cleared + " 条记录") : "清空失败:" + ((v && v.error) || "未知错误"));
1600
1801
  load();
1601
- }).catch(err => { setBusy(false); setMsg("同步失败:" + String(err && err.message ? err.message : err)); });
1802
+ }).catch(err => { setBusy(""); say("data", "清空失败:" + String(err && err.message ? err.message : err)); });
1803
+ }
1804
+ function saveVolcEngine(clear) {
1805
+ setBusy("sub"); say("sub", "");
1806
+ const args = clear ? { clear: true } : { volcengineAccessKeyId: volcId };
1807
+ if (!clear && volcSecret) args.volcengineSecretAccessKey = volcSecret;
1808
+ apiCall("volcengine-config", args).then(v => {
1809
+ setBusy("");
1810
+ setVolcSecret("");
1811
+ if (v && v.ok) {
1812
+ setVolcHasSecret(!!v.volcengineHasKeys);
1813
+ setVolcBackend(v.volcengineSecretBackend || "");
1814
+ say("sub", clear ? "已清除凭据" : "已保存(SecretAccessKey 存入凭据库)");
1815
+ } else say("sub", "保存失败:" + ((v && v.error) || "未知错误"));
1816
+ }).catch(err => { setBusy(""); say("sub", "保存失败:" + String(err && err.message ? err.message : err)); });
1817
+ }
1818
+ function queryVolc() {
1819
+ setBusy("sub"); say("sub", "查询配额…");
1820
+ apiCall("volcengine-usage", { force: true }).then(v => {
1821
+ setBusy(""); setVolcData(v);
1822
+ say("sub", v && v.ok ? "配额已刷新" : ("查询失败:" + ((v && v.error) || "未知错误")));
1823
+ }).catch(err => { setBusy(""); say("sub", "查询失败:" + String(err && err.message ? err.message : err)); });
1602
1824
  }
1603
1825
  /**
1604
1826
  * 界面显示开关:勾选即刻提交并落盘(无需点「保存」),随后广播 UI_EVENT,
@@ -1626,17 +1848,26 @@ window.__ModuleLoader__.load({
1626
1848
  setUiMsg("保存失败:" + String(err && err.message ? err.message : err));
1627
1849
  });
1628
1850
  }
1629
- // 卡片外壳对齐宿主 PluginCard:li.cost-pcard > button.cost-pcard-head(标题+副标题+箭头)> body
1630
- const head = e("button", { type: "button", className: "cost-pcard-head", "aria-expanded": open, onClick: () => setOpen(v => !v) },
1631
- e("span", { className: "cost-pcard-headtext" },
1632
- e("span", { className: "cost-pcard-name" }, "花费统计" + (st && st.enabled ? " · 云端同步已开启" : "")),
1633
- e("span", { className: "cost-pcard-desc" }, "把本机用量汇总到自建云端服务;多台电脑共用同一个地址与令牌,即可在「花费统计」看板切换查看全网数据。")),
1634
- e("svg", { className: "cost-pcard-chevron" + (open ? " is-open" : ""), width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true" },
1635
- e("path", { d: "M3.5 5.25 7 8.75l3.5-3.5", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round" })));
1636
- const body = !st
1637
- ? e("div", { className: "cost-hint", style: { margin: "12px 0" } }, "加载云端同步状态…")
1638
- : e("div", {},
1639
- e("div", { className: "cost-hint" }, "填好地址与令牌后点「保存」,再点「测试连接」确认可达;首次同步会自动回补历史明细。"),
1851
+ // ---------- 顶部状态条:一眼看清关键状态 ----------
1852
+ const chips = [
1853
+ e("span", { key: "c1", className: "cost-cfg-chip" + (st && st.enabled ? " is-on" : "") },
1854
+ "云端同步", e("b", null, st && st.enabled ? "已开启" : "未开启")),
1855
+ ];
1856
+ if (st) {
1857
+ chips.push(e("span", { key: "c2", className: "cost-cfg-chip" }, "已记账 ", e("b", null, fmtInt(st.maxSeq || 0)), " 条"));
1858
+ chips.push(e("span", { key: "c3", className: "cost-cfg-chip" }, "待上报 ", e("b", null, fmtInt(st.pending || 0)), " 条"));
1859
+ chips.push(e("span", { key: "c4", className: "cost-cfg-chip" }, "上次同步 ", e("b", null, timeLabel(st.lastSyncAt))));
1860
+ }
1861
+ if (prices) chips.push(e("span", { key: "c5", className: "cost-cfg-chip" + (prices.eraSynced ? " is-on" : "") }, "计价时代 ", e("b", null, prices.eraLabel || prices.era || "—")));
1862
+ if (imp) chips.push(e("span", { key: "c6", className: "cost-cfg-chip" }, "历史导入 ", e("b", null, fmtInt(imp.totalImported || 0)), " 条"));
1863
+ chips.push(e("span", { key: "c7", className: "cost-cfg-chip" + (bill.showTotalWithPlan ? " is-on" : "") }, "金额口径 ", e("b", null, bill.showTotalWithPlan ? "含 Plan 总额" : "仅按量")));
1864
+ const topStrip = e("div", { className: "cost-cfg-top" }, chips);
1865
+
1866
+ const secProps = (id, title, summary) => ({ id, title, summary, open: openSec === id, onToggle: (k) => setOpenSec(prev => prev === k ? "" : k) });
1867
+
1868
+ // ---------- ① 多机汇总(云端同步) ----------
1869
+ const cloudBody = e("div", null,
1870
+ e("div", { className: "cost-hint" }, "把本机用量汇总到自建云端服务。多台电脑共用同一个地址与令牌,即可在「花费统计」看板切换查看全网数据;首次同步会自动回补历史明细。"),
1640
1871
  e("div", { className: "cost-sync-fields" },
1641
1872
  field("设备名", e("input", {
1642
1873
  className: "cost-input", style: { width: "200px" }, value: draft.deviceName || "", placeholder: "如:办公台式机",
@@ -1646,55 +1877,425 @@ window.__ModuleLoader__.load({
1646
1877
  field("服务地址", e("input", {
1647
1878
  className: "cost-input", style: { width: "320px" }, value: draft.cloudUrl || "", placeholder: "https://cost.example.com",
1648
1879
  onChange: ev => set("cloudUrl", ev.target.value),
1649
- }), "仅 http/https"),
1880
+ }), "仅 http/https;本机地址可用 http"),
1650
1881
  field("共享令牌", e("input", {
1651
1882
  className: "cost-input", type: "password", style: { width: "320px" }, value: draft.cloudToken || "",
1652
- placeholder: st.hasToken ? "已配置(留空则不修改)" : "dshc_...",
1883
+ placeholder: (st && st.hasToken) || (st && st.cloudTokenConfigured) ? "已配置(留空则不修改)" : "dshc_...",
1653
1884
  onChange: ev => set("cloudToken", ev.target.value),
1654
- }), "在云端看板「设置」页生成"),
1885
+ }), "保存后写入 DSH 凭据库,配置文件不落明文"),
1655
1886
  field("同步间隔", e("select", { className: "cost-select", value: String(draft.syncIntervalSec || 60), onChange: ev => set("syncIntervalSec", parseInt(ev.target.value, 10)) },
1656
1887
  [15, 30, 60, 120, 300, 600, 1800, 3600].map(s => e("option", { key: "iv" + s, value: String(s) }, s < 60 ? s + " 秒" : (s / 60) + " 分钟")))),
1888
+ field("单批条数", e("select", { className: "cost-select", value: String(draft.syncBatchSize || 500), onChange: ev => set("syncBatchSize", parseInt(ev.target.value, 10)) },
1889
+ [50, 100, 200, 500, 1000, 2000].map(s => e("option", { key: "bs" + s, value: String(s) }, String(s))))),
1657
1890
  field("会话脱敏", e("input", { type: "checkbox", checked: !!draft.maskSessionId, onChange: ev => set("maskSessionId", ev.target.checked) }), "上报前把 sessionId 换成不可逆哈希"),
1658
1891
  field("上报 purpose", e("input", { type: "checkbox", checked: draft.includePurpose !== false, onChange: ev => set("includePurpose", ev.target.checked) }), "项目/用途归属"),
1892
+ field("上报日汇总", e("input", { type: "checkbox", checked: draft.syncRollups !== false, onChange: ev => set("syncRollups", ev.target.checked) }), "保留窗口外的历史日汇总"),
1893
+ field("补传窗口(天)", e("input", {
1894
+ className: "cost-input", style: { width: "90px" }, type: "number", min: 0, max: 3650,
1895
+ value: String(typeof draft.syncSinceDays === "number" ? draft.syncSinceDays : 180),
1896
+ onChange: ev => { const n = parseInt(ev.target.value, 10); if (Number.isInteger(n) && n >= 0) set("syncSinceDays", n); },
1897
+ }), "0 = 不限(全量补传)"),
1659
1898
  field("默认视图", e("select", { className: "cost-select", value: draft.cloudView || "local", onChange: ev => set("cloudView", ev.target.value) },
1660
1899
  BOARD_VIEWS.map(v => e("option", { key: v.id, value: v.id }, v.label))))),
1661
1900
  e("div", { className: "cost-sync-actions" },
1662
- e("button", { className: "cost-btn cost-btn-primary", onClick: save, disabled: busy }, "保存"),
1663
- e("button", { className: "cost-btn", onClick: test, disabled: busy }, "测试连接"),
1664
- e("button", { className: "cost-btn", onClick: () => syncNow(false), disabled: busy }, "立即同步"),
1665
- e("button", { className: "cost-btn", onClick: () => syncNow(true), disabled: busy }, "全量补传")),
1666
- msg ? e("div", { className: "cost-sync-state" }, msg) : null,
1667
- testing ? e("div", { className: "cost-sync-state" }, testing) : null,
1668
- e("div", { className: "cost-sync-state" },
1669
- "设备 ID " + (st.deviceId || "(未生成)") + " · 水位 seq=" + st.watermark + " · 待上报 " + st.pending + " 条 · 上次同步 " + (st.lastSyncAt ? timeLabel(st.lastSyncAt) : "从未")),
1670
- st.lastError ? e("div", { className: "cost-err" }, "最近错误:" + st.lastError) : null,
1671
- st.needAuth ? e("div", { className: "cost-err" }, "令牌无效:请在云端看板重新生成共享引导令牌后填入上方「共享令牌」。") : null,
1672
- st.url ? e("div", { className: "cost-hint", style: { marginTop: "6px" } }, "云端看板:" + st.url) : null,
1673
- // ---------- 界面显示:三个前端落点各自显隐,勾选即刻生效 ----------
1674
- // 只影响渲染,不影响记账 / 云端同步 / Agent 工具;本卡片不受这三个开关控制
1675
- // (否则关掉之后就再没有入口能打开了)。
1676
- e("div", { className: "cost-sync-card" },
1677
- e("div", { className: "cost-panel-title" }, "界面显示"),
1678
- e("div", { className: "cost-hint", style: { marginTop: "6px" } },
1679
- "控制插件在 DSH 界面上的落点,勾选后立即生效(无需点上面的「保存」)。关闭只影响显示:记账、云端同步与 Agent 工具照常工作。"),
1680
- e("div", { style: { marginTop: "8px", display: "grid", gap: "6px" } },
1681
- UI_SURFACES.map(s => e("label", { key: s.key, className: "cost-row", style: { gap: "8px", alignItems: "flex-start" } },
1901
+ e("button", { className: "cost-btn cost-btn-primary", onClick: save, disabled: busy === "cloud" }, "保存"),
1902
+ e("button", { className: "cost-btn", onClick: test, disabled: busy === "cloud" }, "测试连接"),
1903
+ e("button", { className: "cost-btn", onClick: () => syncNow(false), disabled: busy === "cloud" }, "立即同步"),
1904
+ e("button", { className: "cost-btn", onClick: () => syncNow(true), disabled: busy === "cloud" }, "全量补传")),
1905
+ msg.cloud ? e("div", { className: "cost-sync-state" }, msg.cloud) : null,
1906
+ st ? e("div", { className: "cost-sync-state" },
1907
+ "设备 ID " + (st.deviceId || "(未生成)") + " · 水位 seq=" + st.watermark + " · 待上报 " + st.pending + " 条 · 上次同步 " + timeLabel(st.lastSyncAt)) : null,
1908
+ st && st.lastError ? e("div", { className: "cost-err" }, "最近错误:" + st.lastError) : null,
1909
+ st && st.needAuth ? e("div", { className: "cost-err" }, "令牌无效:请在云端看板重新生成共享引导令牌后填入上方「共享令牌」。") : null,
1910
+ st && st.url ? e("div", { className: "cost-hint", style: { marginTop: "6px" } }, "云端看板:" + st.url) : null);
1911
+
1912
+ // ---------- ② 峰谷计价与提示 ----------
1913
+ const pd = peakDraft || {};
1914
+ // 预览用快照:把草稿覆盖到服务端快照上,从而「改完即可预览、点保存才落盘」
1915
+ const peakPreviewSnap = peakSnap ? Object.assign({}, peakSnap, { config: pd }) : null;
1916
+ const noticeOn = peakSnap && peakSnap.notice !== false && pd.peakNotice !== false;
1917
+ const peakBody = e("div", null,
1918
+ e("div", { className: "cost-hint" }, "官方只有两档:高峰(工作日 9:00-12:00 / 14:00-18:00)与闲时(高峰 × 0.5,含周末全天)。此处只影响界面提示与档位判定:改价请用「计价与价格目录 → 官方价格同步」。"),
1919
+ e("div", { style: { marginTop: "8px", display: "grid", gap: "6px" } },
1920
+ e("label", { className: "cost-row", style: { gap: "8px" } },
1921
+ e("input", { type: "checkbox", checked: pd.peakEnabled !== false, onChange: ev => setPeak("peakEnabled", ev.target.checked) }),
1922
+ e("span", null, "启用 DeepSeek 峰谷时段价格")),
1923
+ e("label", { className: "cost-row", style: { gap: "8px" } },
1924
+ e("input", { type: "checkbox", checked: pd.peakNotice !== false, onChange: ev => setPeak("peakNotice", ev.target.checked) }),
1925
+ e("span", null, "峰时高价时段显著提示(时段条显示)")),
1926
+ e("div", { className: "cost-row", style: { gap: "8px" } },
1927
+ e("span", null, "时段条样式"),
1928
+ e("select", { className: "cost-select", value: pd.peakStyle === "classic" ? "classic" : "compact", onChange: ev => setPeak("peakStyle", ev.target.value) },
1929
+ e("option", { value: "compact" }, "简洁(单行紧凑)"),
1930
+ e("option", { value: "classic" }, "环形表盘(24h)"))),
1931
+ pd.peakStyle === "classic"
1932
+ ? e("label", { className: "cost-row", style: { gap: "8px" } },
1933
+ e("input", { type: "checkbox", checked: pd.peakShowTickLabels !== false, onChange: ev => setPeak("peakShowTickLabels", ev.target.checked) }),
1934
+ e("span", null, "显示时间(00:00–21:00 刻度)"))
1935
+ : e("label", { className: "cost-row", style: { gap: "8px" } },
1936
+ e("input", { type: "checkbox", checked: pd.peakCompactStack === true, onChange: ev => setPeak("peakCompactStack", ev.target.checked) }),
1937
+ e("span", null, "双行紧凑(上下布局)"),
1938
+ pd.peakCompactStack === true ? e("select", { className: "cost-select", value: pd.peakCompactOrder === "text-first" ? "text-first" : "bar-first", onChange: ev => setPeak("peakCompactOrder", ev.target.value) },
1939
+ e("option", { value: "bar-first" }, "时段条在上·文字在下"),
1940
+ e("option", { value: "text-first" }, "文字在上·时段条在下")) : null),
1941
+ e("label", { className: "cost-row", style: { gap: "8px" } },
1942
+ e("input", { type: "checkbox", checked: pd.peakAlertEnabled !== false, onChange: ev => setPeak("peakAlertEnabled", ev.target.checked) }),
1943
+ e("span", null, "峰/谷切换前弹窗提醒")),
1944
+ pd.peakAlertEnabled !== false
1945
+ ? e("div", { className: "cost-row", style: { gap: "8px", flexWrap: "wrap" } },
1946
+ e("span", null, "提前提醒(分钟,1-30)"),
1682
1947
  e("input", {
1683
- type: "checkbox",
1684
- checked: uiDraft[s.key] !== false,
1685
- onChange: ev => saveUi({ [s.key]: ev.target.checked }),
1948
+ className: "cost-input", style: { width: "80px" }, type: "number", min: 1, max: 30,
1949
+ value: String(pd.peakAlertAhead == null ? 2 : pd.peakAlertAhead),
1950
+ onChange: ev => { const n = parseInt(ev.target.value, 10); if (Number.isInteger(n) && n >= 1 && n <= 30) setPeak("peakAlertAhead", n); },
1686
1951
  }),
1687
- e("span", null,
1688
- e("span", null, s.label),
1689
- e("div", { className: "cost-hint" }, s.desc))))),
1690
- e("div", { className: "cost-row", style: { gap: "8px", marginTop: "6px" } },
1691
- e("button", { className: "cost-btn", onClick: () => saveUi({ uiDockEnabled: true, uiPeakEnabled: true, uiDashboardEnabled: true }) }, "全部显示"),
1692
- uiMsg ? e("span", { className: "cost-hint" }, uiMsg) : null)));
1952
+ e("span", null, "提醒类型"),
1953
+ e("select", { className: "cost-select", value: pd.peakAlertTarget === "peak" || pd.peakAlertTarget === "offpeak" ? pd.peakAlertTarget : "both", onChange: ev => setPeak("peakAlertTarget", ev.target.value) },
1954
+ e("option", { value: "both" }, "峰和谷"), e("option", { value: "peak" }, "进入峰时"), e("option", { value: "offpeak" }, "进入谷时")),
1955
+ e("span", null, "弹窗位置"),
1956
+ e("select", { className: "cost-select", value: pd.peakAlertPosition === "center" ? "center" : "corner", onChange: ev => setPeak("peakAlertPosition", ev.target.value) },
1957
+ e("option", { value: "corner" }, "右下角"), e("option", { value: "center" }, "屏幕中心")))
1958
+ : null,
1959
+ e("label", { className: "cost-row", style: { gap: "8px" } },
1960
+ e("input", { type: "checkbox", checked: pd.peakAlertWebNotify === true, onChange: ev => setPeak("peakAlertWebNotify", ev.target.checked) }),
1961
+ e("span", null, "同步发送系统通知(需授权通知权限)")),
1962
+ e("div", { className: "cost-row", style: { gap: "8px", marginTop: "4px" } },
1963
+ e("span", null, "预览弹窗"),
1964
+ e("button", { className: "cost-btn", onClick: () => { try { window.dispatchEvent(new CustomEvent(PEAK_PREVIEW_EVENT, { detail: { kind: "peak" } })); } catch (_) {} } }, "预览进入峰"),
1965
+ e("button", { className: "cost-btn", onClick: () => { try { window.dispatchEvent(new CustomEvent(PEAK_PREVIEW_EVENT, { detail: { kind: "offpeak" } })); } catch (_) {} } }, "预览进入谷"),
1966
+ e("button", { className: "cost-btn cost-btn-primary", onClick: savePeak, disabled: busy === "peak" }, "保存"),
1967
+ msg.peak ? e("span", { className: "cost-hint" }, msg.peak) : null),
1968
+ e("div", { className: "cost-hint", style: { marginTop: "6px" } },
1969
+ "峰时段(北京时间):" + (peakSnap ? peakSnap.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)") +
1970
+ "。当前:" + (peakPreviewSnap && peakPreviewSnap.phase ? (peakPreviewSnap.phase.weekend ? "周末全谷价" : peakPreviewSnap.phase.inPeak ? "高峰时段" : "平价时段") : "…")),
1971
+ noticeOn ? e("div", { style: { marginTop: "8px" } }, e(PeakStrip, { snap: peakPreviewSnap, style: pd.peakStyle || "compact", wide: true, now, ringSize: 150 }))
1972
+ : e("p", { className: "cost-hint", style: { marginTop: "8px" } }, "提示已隐藏:需启用峰谷计价并开启「峰时高价时段显著提示」。")));
1973
+
1974
+ // ---------- ③ 订阅套餐与配额 ----------
1975
+ const quotaWindows = (volcData && volcData.windowList) || [];
1976
+ const subBody = e("div", null,
1977
+ e("div", { className: "cost-hint" }, "订阅制(Coding Plan / 会员)的调用**不计入按量消费金额**,只按等值费用展示;这里配置查配额所需的凭据与订阅归类。"),
1978
+ e("div", { className: "cost-subblock" },
1979
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "火山方舟 Coding Plan 配额凭据"),
1980
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
1981
+ "配额查询走方舟**管控面**,需要 IAM 的 AccessKeyID + SecretAccessKey(授予 ArkReadOnlyAccess + BillingCenterReadOnlyAccess);它与推理用的 ARK API Key 是两套凭据。SecretAccessKey 只写入凭据库,任何响应都不回显。"),
1982
+ e("div", { className: "cost-sync-fields" },
1983
+ field("AccessKeyID", e("input", {
1984
+ className: "cost-input", style: { width: "260px" }, value: volcId, placeholder: "AKLT...",
1985
+ onChange: ev => setVolcId(ev.target.value),
1986
+ })),
1987
+ field("SecretAccessKey", e("input", {
1988
+ className: "cost-input", type: "password", style: { width: "260px" }, value: volcSecret,
1989
+ placeholder: volcHasSecret ? "已存入凭据库(留空则不修改)" : "仅本机保存,不回显",
1990
+ onChange: ev => setVolcSecret(ev.target.value),
1991
+ })),
1992
+ field("凭据状态", e("span", null,
1993
+ e("span", { className: "cost-badge" }, volcHasSecret ? "已配置" : "未配置"),
1994
+ volcBackend === "memory" ? e("span", { className: "cost-hint", style: { marginLeft: "6px" } }, "(凭据服务缺席,仅进程内暂存)") : null))),
1995
+ e("div", { className: "cost-sync-actions" },
1996
+ e("button", { className: "cost-btn cost-btn-primary", onClick: () => saveVolcEngine(false), disabled: busy === "sub" }, "保存凭据"),
1997
+ e("button", { className: "cost-btn", onClick: queryVolc, disabled: busy === "sub" }, "查询配额"),
1998
+ e("button", { className: "cost-btn", onClick: () => saveVolcEngine(true), disabled: busy === "sub" }, "清除凭据"),
1999
+ msg.sub ? e("span", { className: "cost-hint" }, msg.sub) : null),
2000
+ quotaWindows.length
2001
+ ? e("div", { style: { marginTop: "6px" } }, quotaWindows.map((w, i) => e("div", { key: "qw" + i }, pctBar(w.label || w.name, w.percent, w.resetsAt, now, w.used, w.quota))))
2002
+ : null),
2003
+ e("div", { className: "cost-subblock" },
2004
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "订阅归类覆盖"),
2005
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2006
+ "内置规则:火山方舟**专属 Coding 端点**整档算订阅;泛 volcengine 走模型白名单;Kimi 整档算订阅。清单追不上模型 id 时,用下面的覆盖表把某个 provider(或某个模型)强制归到订阅/按量。"),
2007
+ planOverrideEditor(bill.planRows, rows => setBillField("planRows", rows)),
2008
+ e("div", { className: "cost-sync-actions", style: { marginTop: "8px" } },
2009
+ e("button", { className: "cost-btn cost-btn-primary", onClick: saveBilling, disabled: busy === "bill" }, "保存归类"),
2010
+ msg.bill ? e("span", { className: "cost-hint" }, msg.bill) : null)));
2011
+
2012
+ // ---------- ④ 计价与价格目录 ----------
2013
+ const cat = prices && prices.catalog;
2014
+ const ps = prices && prices.priceSync;
2015
+ const syncEras = (ps && ps.syncedEras) || [];
2016
+ const lastCheck = ps && ps.lastCheck;
2017
+ const billBody = e("div", null,
2018
+ e("div", { className: "cost-kv" },
2019
+ e("span", { className: "k" }, "金额口径"),
2020
+ e("label", { className: "cost-row", style: { gap: "8px" } },
2021
+ e("input", { type: "checkbox", checked: !!bill.showTotalWithPlan, onChange: ev => setBillField("showTotalWithPlan", ev.target.checked) }),
2022
+ e("span", null, "含 Plan 总额(金额 = 按量 + 订阅等值)"),
2023
+ e("span", { className: "cost-hint" }, "关掉只统计按量真金白银;看板右上角也有同款快捷开关")),
2024
+ e("span", { className: "k" }, "目录匹配"),
2025
+ e("div", { className: "cost-row", style: { gap: "8px" } },
2026
+ e("select", { className: "cost-select", value: bill.priceMatch === "exact" ? "exact" : "fuzzy", onChange: ev => setBillField("priceMatch", ev.target.value) },
2027
+ e("option", { value: "fuzzy" }, "宽松(归一化包含匹配,默认)"),
2028
+ e("option", { value: "exact" }, "严格(名称全等才命中)")),
2029
+ e("span", { className: "cost-hint" }, "目录用于识别内置价格表之外的模型(OpenAI / Anthropic / Gemini / Qwen 等)")),
2030
+ e("span", { className: "k" }, "目录汇率"),
2031
+ e("div", { className: "cost-row", style: { gap: "8px" } },
2032
+ e("input", {
2033
+ className: "cost-input", style: { width: "90px" }, type: "number", step: "0.1", min: "0.1", max: "100",
2034
+ value: String(bill.catalogFxRate == null ? 7.2 : bill.catalogFxRate),
2035
+ onChange: ev => setBillField("catalogFxRate", Number(ev.target.value)),
2036
+ }),
2037
+ e("span", { className: "cost-hint" }, "目录单价为 USD/1M tokens,按此汇率折算为人民币入账"))),
2038
+ e("div", { className: "cost-subblock" },
2039
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "手动覆盖价(CNY / 1M tokens)"),
2040
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } }, "优先级最高:命中即按此价计费(含缓存写入价 = 缓存命中价)。用于内网自建端点、议价套餐或官方页未列出的模型。"),
2041
+ priceOverrideEditor(bill.priceRows, rows => setBillField("priceRows", rows))),
2042
+ e("div", { className: "cost-subblock" },
2043
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "官方价格同步"),
2044
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2045
+ "抓取官方定价页(中文页给出人民币价),解析出各模型峰价后构建**新的计费时代**:只对生效时刻之后的记录生效,历史记录口径不回改。应用前可先「核对官方价」看差异。"),
2046
+ e("div", { className: "cost-sync-fields" },
2047
+ field("定价页地址", e("input", {
2048
+ className: "cost-input", style: { width: "320px" }, value: psDraft.priceSyncUrl || "", placeholder: "https://api-docs.deepseek.com/zh-cn/quick_start/pricing",
2049
+ onChange: ev => setPsDraft(prev => Object.assign({}, prev, { priceSyncUrl: ev.target.value })),
2050
+ })),
2051
+ field("每日自动核对", e("input", {
2052
+ type: "checkbox", checked: psDraft.priceSyncAutoCheck !== false,
2053
+ onChange: ev => setPsDraft(prev => Object.assign({}, prev, { priceSyncAutoCheck: ev.target.checked })),
2054
+ }), "只核对并提示差异,绝不自动应用"))),
2055
+ e("div", { className: "cost-sync-actions" },
2056
+ e("button", { className: "cost-btn", onClick: savePriceSync, disabled: busy === "bill" }, "保存设置"),
2057
+ e("button", { className: "cost-btn", onClick: () => runPriceSync(false), disabled: busy === "price" }, "核对官方价"),
2058
+ e("button", { className: "cost-btn cost-btn-primary", onClick: () => runPriceSync(true), disabled: busy === "price" }, "应用新价"),
2059
+ msg.price ? e("span", { className: "cost-hint" }, msg.price) : null),
2060
+ lastCheck ? e("div", { className: "cost-sync-state" },
2061
+ "最近核对 " + timeLabel(lastCheck.at) + " · " + (lastCheck.ok ? (lastCheck.diff ? "差异:" + lastCheck.diff : "与当前生效价一致") : ("失败:" + (lastCheck.error || "未知错误")))) : null,
2062
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2063
+ "当前时代:" + (prices ? (prices.eraLabel || prices.era) : "…") + " · 已同步时代 " + syncEras.length + " 个"
2064
+ + (syncEras.length ? ":" + syncEras.map(x => x.id).join("、") : "(内置价格表)"),
2065
+ e("div", { className: "cost-sync-actions", style: { marginTop: "8px" } },
2066
+ e("button", { className: "cost-btn cost-btn-primary", onClick: saveBilling, disabled: busy === "bill" }, "保存计价设置"))),
2067
+ e("div", { className: "cost-subblock" },
2068
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "多厂商模型价格目录"),
2069
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2070
+ cat ? ("共 " + (cat.providers || []).reduce((a, p) => a + p.count, 0) + " 个模型条目 · " + (cat.providers || []).length + " 家厂商 · 数据 " + (cat.meta && cat.meta.generatedAt ? cat.meta.generatedAt : "—") + " · 指纹 " + cat.fingerprint)
2071
+ : "目录数据不可用(未随包分发或读取失败)"),
2072
+ cat ? e("div", { className: "cost-cfg-top", style: { marginTop: "6px" } },
2073
+ (cat.providers || []).map(p => e("span", { key: "cp" + p.id, className: "cost-cfg-chip" }, p.id, " ", e("b", null, p.count)))) : null,
2074
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2075
+ "命中目录 = 精确价(不计入「估算」);内置时代价优先于目录,手动覆盖价优先于两者;目录读取失败不影响计费,自动回落 provider 兜底。")));
2076
+
2077
+ // ---------- ⑤ 历史导入 ----------
2078
+ const impBody = e("div", null,
2079
+ e("div", { className: "cost-hint" }, "回放宿主会话日志($DSH_HOME/sessions/…),把**装插件之前**的对话调用补录进账本。幂等:重复执行不会重复计数。"),
2080
+ e("div", { className: "cost-list", style: { marginTop: "6px" } },
2081
+ e("div", null, "· 只导入「插件不可能记到」的调用:早于本机最早一条实时记录,或所在日完全没有实时覆盖(停机缺口)。"),
2082
+ e("div", null, "· 跨安装点的会话按切割线截断:安装前那段补录,安装后那段以实时记录为准。"),
2083
+ e("div", null, "· 已被实时覆盖的日子**宁可不导入**也不重复计数;导入记录标记 source=import,可在明细中区分。")),
2084
+ e("label", { className: "cost-row", style: { gap: "8px", marginTop: "8px" } },
2085
+ e("input", { type: "checkbox", checked: impDraft.autoImport !== false, onChange: ev => setImpDraft({ autoImport: ev.target.checked }) }),
2086
+ e("span", null, "启动时自动导入(延迟 8 秒执行,不阻塞启动)")),
2087
+ e("div", { className: "cost-sync-actions" },
2088
+ e("button", { className: "cost-btn cost-btn-primary", onClick: saveImportCfg, disabled: busy === "imp" }, "保存设置"),
2089
+ e("button", { className: "cost-btn", onClick: runImport, disabled: busy === "imp" }, "立即导入"),
2090
+ msg.imp ? e("span", { className: "cost-hint" }, msg.imp) : null),
2091
+ imp ? e("div", { className: "cost-sync-state" },
2092
+ "累计导入 " + fmtInt(imp.totalImported || 0) + " 条 · 已处理 " + fmtInt(imp.filesImported || 0) + "/" + fmtInt(imp.filesTracked || 0) + " 个日志文件 · 上次运行 " + (imp.lastRunAt ? timeLabel(imp.lastRunAt) : "从未")) : null,
2093
+ imp && imp.lastResult && imp.lastResult.error ? e("div", { className: "cost-err" }, "上次失败:" + imp.lastResult.error) : null,
2094
+ imp ? e("div", { className: "cost-hint", style: { marginTop: "4px" } }, "会话目录:" + imp.sessionsRoot) : null);
2095
+
2096
+ // ---------- ⑥ 数据与界面 ----------
2097
+ const dataBody = e("div", null,
2098
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "界面显示"),
2099
+ e("div", { className: "cost-hint", style: { marginTop: "6px" } },
2100
+ "控制插件在 DSH 界面上的落点,勾选后立即生效(无需点保存)。关闭只影响显示:记账、云端同步与 Agent 工具照常工作。"),
2101
+ e("div", { style: { marginTop: "8px", display: "grid", gap: "6px" } },
2102
+ UI_SURFACES.map(s => e("label", { key: s.key, className: "cost-row", style: { gap: "8px", alignItems: "flex-start" } },
2103
+ e("input", {
2104
+ type: "checkbox",
2105
+ checked: uiDraft[s.key] !== false,
2106
+ onChange: ev => saveUi({ [s.key]: ev.target.checked }),
2107
+ }),
2108
+ e("span", null,
2109
+ e("span", null, s.label),
2110
+ e("div", { className: "cost-hint" }, s.desc))))),
2111
+ e("div", { className: "cost-row", style: { gap: "8px", marginTop: "6px" } },
2112
+ e("button", { className: "cost-btn", onClick: () => saveUi({ uiDockEnabled: true, uiPeakEnabled: true, uiDashboardEnabled: true }) }, "全部显示"),
2113
+ uiMsg ? e("span", { className: "cost-hint" }, uiMsg) : null),
2114
+ e("div", { className: "cost-subblock" },
2115
+ e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "数据管理"),
2116
+ e("div", { className: "cost-hint", style: { marginTop: "4px" } },
2117
+ "明细保留最近 180 天,更早自动压缩为永久日汇总(看板总额仍精确)。重算按「计费时代 + 覆盖价 + 目录」重算已入库记录,建议先试算。"),
2118
+ e("div", { className: "cost-sync-actions" },
2119
+ e("button", { className: "cost-btn", onClick: exportCsv, disabled: busy === "data" }, "导出 CSV"),
2120
+ e("button", { className: "cost-btn", onClick: () => runRecompute(false), disabled: busy === "data" }, "重算费用(试算)"),
2121
+ e("button", { className: "cost-btn", onClick: () => runRecompute(true), disabled: busy === "data" }, "重算并写回"),
2122
+ confirmClear
2123
+ ? e("span", { className: "cost-row", style: { gap: "6px" } },
2124
+ e("span", { className: "cost-danger" }, "确认清空全部记录?不可恢复"),
2125
+ e("button", { className: "cost-btn cost-danger", onClick: clearData, disabled: busy === "data" }, "确认清空"),
2126
+ e("button", { className: "cost-btn", onClick: () => setConfirmClear(false) }, "取消"))
2127
+ : e("button", { className: "cost-btn", onClick: () => setConfirmClear(true) }, "清空数据"),
2128
+ msg.data ? e("span", { className: "cost-hint" }, msg.data) : null),
2129
+ recomputeRes ? e("div", { className: "cost-sync-state" },
2130
+ "扫描 " + recomputeRes.scanned + " 条 · 需修正 " + recomputeRes.changed + " 条 · 合计 ¥" + recomputeRes.oldCost + " → ¥" + recomputeRes.newCost + "(" + (recomputeRes.delta >= 0 ? "+" : "") + recomputeRes.delta + ")") : null));
2131
+
2132
+ // ---------- ⑦ 安全与凭据 ----------
2133
+ const secBody = e("div", null,
2134
+ e("div", { className: "cost-hint" }, "密钥零落盘:令牌与 SecretAccessKey 只存 DSH 凭据库(宿主托管的 .credentials.yaml),配置文件里只保留「是否已配置」。出站请求带三重防护:主机白名单、非本机强制 https、3xx 一律拒绝跟随(防止重定向把 Authorization 头带去别处)。"),
2135
+ e("table", { className: "cost-tbl", style: { marginTop: "8px" } },
2136
+ e("thead", null, e("tr", null, e("th", null, "凭据"), e("th", null, "状态"), e("th", null, "存储位置"))),
2137
+ e("tbody", null,
2138
+ e("tr", null,
2139
+ e("td", null, "云端共享令牌"),
2140
+ e("td", null, st && st.cloudTokenConfigured ? "已配置" : "未配置"),
2141
+ e("td", null, st && st.cloudTokenConfigured ? (st.cloudTokenBackend === "memory" ? "进程内存(凭据服务缺席)" : "DSH 凭据库") : "—")),
2142
+ e("tr", null,
2143
+ e("td", null, "火山 SecretAccessKey"),
2144
+ e("td", null, volcHasSecret ? "已配置" : "未配置"),
2145
+ e("td", null, volcHasSecret ? (volcBackend === "memory" ? "进程内存(凭据服务缺席)" : "DSH 凭据库") : "—")),
2146
+ e("tr", null,
2147
+ e("td", null, "旧版明文迁移"),
2148
+ e("td", null, st && st.secretsMigrated ? "已完成" : "无需迁移"),
2149
+ e("td", null, "配置文件不含明文")))),
2150
+ e("div", { className: "cost-sync-actions" },
2151
+ e("button", { className: "cost-btn", onClick: () => saveVolcEngine(true), disabled: busy === "sub" }, "清除火山 SK"),
2152
+ msg.sub ? e("span", { className: "cost-hint" }, msg.sub) : null),
2153
+ e("div", { className: "cost-hint", style: { marginTop: "6px" } },
2154
+ "提示:AccessKeyID 属非敏感标识(控制台可见),会随看板回显以便预填;SecretAccessKey 与令牌在任何响应里都只有布尔标记。"));
2155
+
2156
+ // 卡片外壳对齐宿主 PluginCard:li.cost-pcard > button.cost-pcard-head(标题+副标题+箭头)> body
2157
+ const head = e("button", { type: "button", className: "cost-pcard-head", "aria-expanded": open, onClick: () => setOpen(v => !v) },
2158
+ e("span", { className: "cost-pcard-headtext" },
2159
+ e("span", { className: "cost-pcard-name" }, "花费统计" + (st && st.enabled ? " · 云端同步已开启" : "")),
2160
+ e("span", { className: "cost-pcard-desc" }, "全部设置集中于此:云端同步(多机汇总)、峰谷计价与提示、订阅套餐与配额、计价与价格目录、历史导入、数据与界面、安全与凭据。")),
2161
+ e("svg", { className: "cost-pcard-chevron" + (open ? " is-open" : ""), width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true" },
2162
+ e("path", { d: "M3.5 5.25 7 8.75l3.5-3.5", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round" })));
2163
+ const body = e("div", null,
2164
+ topStrip,
2165
+ !st ? e("div", { className: "cost-hint", style: { margin: "4px 0 8px" } }, "加载状态…") : null,
2166
+ cfgSection(Object.assign({ key: "s1" }, secProps("cloud", "多机汇总(云端同步)", st && st.enabled ? ("已开启 · " + (st.deviceName || "未命名设备")) : "未开启")), cloudBody),
2167
+ cfgSection(Object.assign({ key: "s2" }, secProps("peak", "峰谷计价与提示", (pd.peakEnabled !== false ? "已启用" : "已停用") + " · " + (pd.peakStyle === "classic" ? "环形表盘" : "简洁样式"))), peakBody),
2168
+ cfgSection(Object.assign({ key: "s3" }, secProps("sub", "订阅套餐与配额", (volcHasSecret ? "火山凭据已配" : "火山凭据未配") + " · 归类覆盖 " + bill.planRows.length + " 条")), subBody),
2169
+ cfgSection(Object.assign({ key: "s4" }, secProps("bill", "计价与价格目录", (bill.showTotalWithPlan ? "含 Plan 总额" : "仅按量") + " · 覆盖价 " + bill.priceRows.length + " 条 · " + (cat ? (cat.providers || []).length + " 家目录" : "无目录"))), billBody),
2170
+ cfgSection(Object.assign({ key: "s5" }, secProps("imp", "历史导入", (impDraft.autoImport !== false ? "开机自动" : "手动") + " · 已导入 " + fmtInt((imp && imp.totalImported) || 0) + " 条")), impBody),
2171
+ cfgSection(Object.assign({ key: "s6" }, secProps("data", "数据与界面", "保留 180 天明细 · 界面落点 " + UI_SURFACES.filter(s => uiDraft[s.key] !== false).length + "/3")), dataBody),
2172
+ cfgSection(Object.assign({ key: "s7" }, secProps("sec", "安全与凭据", "密钥零落盘 · 出站白名单")), secBody));
1693
2173
  return e("li", { className: "cost-pcard" + (open ? " is-open" : "") },
1694
2174
  head,
1695
2175
  open ? e("div", { className: "cost-pcard-body" }, body) : null);
1696
2176
  }
1697
2177
 
2178
+ /**
2179
+ * 折叠分组外壳(配置卡片 v1.9.0)。
2180
+ * 折叠只切 CSS 显隐、**不卸载内容**:展开任一分组都无需重新取数,
2181
+ * 草稿也不会因为切分组而丢;同时让「按 id 手风琴」保持简单。
2182
+ */
2183
+ function cfgSection(p, body) {
2184
+ const open = !!p.open;
2185
+ return e("div", { className: "cost-sec" + (open ? " is-open" : "") },
2186
+ e("button", {
2187
+ type: "button", className: "cost-sec-head", "aria-expanded": open,
2188
+ onClick: () => p.onToggle(p.id),
2189
+ },
2190
+ e("span", { className: "cost-sec-title" }, p.title),
2191
+ p.summary ? e("span", { className: "cost-sec-sum" }, p.summary) : null,
2192
+ e("svg", { className: "cost-sec-arrow" + (open ? " is-open" : ""), width: 12, height: 12, viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true" },
2193
+ e("path", { d: "M3.5 5.25 7 8.75l3.5-3.5", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round" }))),
2194
+ e("div", { className: "cost-sec-body", style: open ? null : { display: "none" } }, body));
2195
+ }
2196
+
2197
+ /** 配置里的订阅归类对象 ⇄ 编辑行(键形如 'provider/model',model 可为 '*') */
2198
+ function planOverridesToRows(obj) {
2199
+ return Object.keys(obj || {}).map(k => {
2200
+ const p = String(k).split("/");
2201
+ return { provider: p[0] || "", model: p[1] || "*", kind: obj[k] === "api" ? "api" : "plan" };
2202
+ });
2203
+ }
2204
+ function planRowsToObj(rows) {
2205
+ const out = {};
2206
+ for (const r of rows || []) {
2207
+ const p = String(r.provider || "").trim();
2208
+ const m = String(r.model || "*").trim() || "*";
2209
+ if (!p) continue;
2210
+ out[p + "/" + m] = r.kind === "api" ? "api" : "plan";
2211
+ }
2212
+ return out;
2213
+ }
2214
+ /** 配置里的覆盖价对象 ⇄ 编辑行(cacheWrite 恒等于 cacheRead,与官方口径一致) */
2215
+ function priceOverridesToRows(obj) {
2216
+ return Object.keys(obj || {}).map(k => {
2217
+ const p = String(k).split("/");
2218
+ const v = obj[k] || {};
2219
+ return { provider: p[0] || "", model: p[1] || "", input: v.input, output: v.output, cacheRead: v.cacheRead };
2220
+ });
2221
+ }
2222
+ function priceRowsToObj(rows) {
2223
+ const out = {};
2224
+ for (const r of rows || []) {
2225
+ const p = String(r.provider || "").trim();
2226
+ const m = String(r.model || "").trim();
2227
+ if (!p || !m) continue;
2228
+ out[p + "/" + m] = {
2229
+ input: Number(r.input) || 0,
2230
+ output: Number(r.output) || 0,
2231
+ cacheRead: Number(r.cacheRead) || 0,
2232
+ cacheWrite: Number(r.cacheRead) || 0,
2233
+ };
2234
+ }
2235
+ return out;
2236
+ }
2237
+
2238
+ /** 订阅归类覆盖编辑器 */
2239
+ function planOverrideEditor(rows, setRows) {
2240
+ const list = rows || [];
2241
+ const upd = (i, patch) => setRows(list.map((r, j) => (j === i ? Object.assign({}, r, patch) : r)));
2242
+ return e("div", { style: { marginTop: "6px" } },
2243
+ list.length
2244
+ ? e("table", { className: "cost-tbl" },
2245
+ e("thead", null, e("tr", null,
2246
+ e("th", null, "Provider"), e("th", null, "模型(* = 该 provider 全部)"), e("th", null, "归类"), e("th", null, ""))),
2247
+ e("tbody", null, list.map((r, i) => e("tr", { key: "po" + i },
2248
+ e("td", null, e("input", {
2249
+ className: "cost-input", style: { width: "170px" }, value: r.provider || "", placeholder: "byteblus-coding-plan-cn",
2250
+ onChange: ev => upd(i, { provider: ev.target.value }),
2251
+ })),
2252
+ e("td", null, e("input", {
2253
+ className: "cost-input", style: { width: "170px" }, value: r.model || "", placeholder: "*",
2254
+ onChange: ev => upd(i, { model: ev.target.value }),
2255
+ })),
2256
+ e("td", null, e("select", { className: "cost-select", value: r.kind === "api" ? "api" : "plan", onChange: ev => upd(i, { kind: ev.target.value }) },
2257
+ e("option", { value: "plan" }, "订阅(Plan)"), e("option", { value: "api" }, "按量"))),
2258
+ e("td", null, e("button", { className: "cost-btn", onClick: () => setRows(list.filter((_, j) => j !== i)) }, "删除"))))))
2259
+ : e("div", { className: "cost-hint" }, "暂无覆盖:套餐内模型按内置规则自动识别。"),
2260
+ e("button", {
2261
+ className: "cost-btn", style: { marginTop: "6px" },
2262
+ onClick: () => setRows(list.concat([{ provider: "", model: "*", kind: "plan" }])),
2263
+ }, "+ 添加归类"));
2264
+ }
2265
+
2266
+ /** 手动覆盖价编辑器(CNY / 1M tokens;缓存写入价 = 缓存命中价) */
2267
+ function priceOverrideEditor(rows, setRows) {
2268
+ const list = rows || [];
2269
+ const upd = (i, patch) => setRows(list.map((r, j) => (j === i ? Object.assign({}, r, patch) : r)));
2270
+ const numCell = (r, i, key, width) => e("td", { className: "cost-num" }, e("input", {
2271
+ className: "cost-input", style: { width: width || "80px" }, type: "number", step: "0.01", min: "0",
2272
+ value: r[key] == null ? "" : String(r[key]),
2273
+ onChange: ev => upd(i, { [key]: Number(ev.target.value) }),
2274
+ }));
2275
+ return e("div", { style: { marginTop: "6px" } },
2276
+ list.length
2277
+ ? e("table", { className: "cost-tbl" },
2278
+ e("thead", null, e("tr", null,
2279
+ e("th", null, "Provider"), e("th", null, "模型"), e("th", { className: "cost-num" }, "输入(未命中)"),
2280
+ e("th", { className: "cost-num" }, "输出"), e("th", { className: "cost-num" }, "缓存命中/写入"), e("th", null, ""))),
2281
+ e("tbody", null, list.map((r, i) => e("tr", { key: "pr" + i },
2282
+ e("td", null, e("input", {
2283
+ className: "cost-input", style: { width: "120px" }, value: r.provider || "", placeholder: "deepseek-official",
2284
+ onChange: ev => upd(i, { provider: ev.target.value }),
2285
+ })),
2286
+ e("td", null, e("input", {
2287
+ className: "cost-input", style: { width: "140px" }, value: r.model || "", placeholder: "deepseek-flash",
2288
+ onChange: ev => upd(i, { model: ev.target.value }),
2289
+ })),
2290
+ numCell(r, i, "input"), numCell(r, i, "output"), numCell(r, i, "cacheRead", "90px"),
2291
+ e("td", null, e("button", { className: "cost-btn", onClick: () => setRows(list.filter((_, j) => j !== i)) }, "删除"))))))
2292
+ : e("div", { className: "cost-hint" }, "暂无覆盖价:直接用内置价格表 / 目录价。"),
2293
+ e("button", {
2294
+ className: "cost-btn", style: { marginTop: "6px" },
2295
+ onClick: () => setRows(list.concat([{ provider: "", model: "", input: "", output: "", cacheRead: "" }])),
2296
+ }, "+ 添加覆盖价"));
2297
+ }
2298
+
1698
2299
  /**
1699
2300
  * 「花费统计」看板的插槽门卫。
1700
2301
  * 关掉界面显示时**不能注册成空渲染**(会留下一个点不开的空白导航项),
@@ -1729,6 +2330,11 @@ window.__ModuleLoader__.load({
1729
2330
  const [dashErr, setDashErr] = useState("");
1730
2331
  const [kimi, setKimi] = useState(null);
1731
2332
  const [volc, setVolc] = useState(null);
2333
+ // 火山方舟凭据输入(面板自带):AK 回显、SK 不回显、busy 只管自己这块
2334
+ const [volcId, setVolcId] = useState("");
2335
+ const [volcSecret, setVolcSecret] = useState("");
2336
+ const [volcHasSecret, setVolcHasSecret] = useState(false);
2337
+ const [volcBusy, setVolcBusy] = useState(false);
1732
2338
  const [balance, setBalance] = useState(null);
1733
2339
  const [tab, setTab] = useState("period");
1734
2340
  const [scheme, setSchemeState] = useState(() => {
@@ -1743,6 +2349,17 @@ window.__ModuleLoader__.load({
1743
2349
  const [now, setNow] = useState(Date.now());
1744
2350
  const [manualKey, setManualKey] = useState("");
1745
2351
  const [usage, setUsage] = useState(null);
2352
+ // 双轨计费口径:「含 Plan 总额」开关(localStorage 优先,服务端配置兜底/回写)
2353
+ const [planTotal, setPlanTotalState] = useState(() => planTotalInit(null));
2354
+ // 用户是否已手动改过:改过之后**不再**被服务端/轮询回包覆盖
2355
+ // (用 state 而不是 useRef:渲染期读到的必须是最新值,测试替身也不支持持久 ref)
2356
+ const [planLocked, setPlanLocked] = useState(false);
2357
+ function setPlanTotal(on) {
2358
+ setPlanTotalState(on);
2359
+ setPlanLocked(true);
2360
+ planTotalStore(on);
2361
+ apiCall("billing-config", { showTotalWithPlan: on }).catch(() => {});
2362
+ }
1746
2363
  const [usageErr, setUsageErr] = useState("");
1747
2364
  // ---- 云端三态视图 ----
1748
2365
  const [sync, setSync] = useState(null);
@@ -1767,6 +2384,8 @@ window.__ModuleLoader__.load({
1767
2384
  try { localStorage.setItem("dsh-cost-tracker-dim", d) } catch (e) {}
1768
2385
  }
1769
2386
  const viewInitRef = useRef(false);
2387
+ // 凭据一次回填即可,之后以输入框为准(不然用户刚改完就被 sync 轮询覆盖回去)
2388
+ const volcCredInitRef = useRef(false);
1770
2389
 
1771
2390
  function loadDash(d) {
1772
2391
  apiCall("dashboard", { days: d }).then(v => {
@@ -1778,6 +2397,20 @@ window.__ModuleLoader__.load({
1778
2397
  apiCall("sync", {}).then(v => {
1779
2398
  if (!v) return;
1780
2399
  setSync(v);
2400
+ // 面板凭据回显:AK 明文(与云端看板同口径),SK 只回「是否已保存」
2401
+ if (typeof v.volcengineAccessKeyId === "string" && v.volcengineAccessKeyId) {
2402
+ volcCredInitRef.current = true;
2403
+ setVolcId(prev => prev || v.volcengineAccessKeyId);
2404
+ }
2405
+ setVolcHasSecret(!!v.volcengineHasSecret);
2406
+ // 「含 Plan 总额」:本机偏好优先,其次服务端配置;用户手动改过后不再覆盖
2407
+ if (!planLocked) {
2408
+ let stored = null;
2409
+ try { stored = window.localStorage.getItem(PLAN_TOTAL_KEY); } catch (_) { stored = null; }
2410
+ if (stored === "1") setPlanTotalState(true);
2411
+ else if (stored === "0") setPlanTotalState(false);
2412
+ else setPlanTotalState(v.showTotalWithPlan === true);
2413
+ }
1781
2414
  // 首次进入:以配置里的视图为准(三态开关的权威值在配置,便于多机一致)
1782
2415
  if (!viewInitRef.current && (v.view === "local" || v.view === "local+cloud" || v.view === "cloud")) {
1783
2416
  viewInitRef.current = true;
@@ -1825,6 +2458,38 @@ window.__ModuleLoader__.load({
1825
2458
  function loadVolc(force) {
1826
2459
  apiCall("volcengine-usage", { force: !!force }).then(v => setVolc(v)).catch(() => {});
1827
2460
  }
2461
+ // 面板自带的凭据输入:AK 明文回显、SK 从不回显(只提示已保存)
2462
+ function volcSaveCred() {
2463
+ const patch = {};
2464
+ if (volcId.trim()) patch.volcengineAccessKeyId = volcId.trim();
2465
+ if (volcSecret.trim()) patch.volcengineSecretAccessKey = volcSecret.trim();
2466
+ if (!Object.keys(patch).length) { setMsg("请先填写 AccessKeyID 与 SecretAccessKey"); return; }
2467
+ apiCall("volcengine-config", patch).then(v => {
2468
+ setVolcHasSecret(!!(v && v.volcengineHasSecret) || !!volcSecret.trim());
2469
+ setVolcSecret("");
2470
+ setMsg(v && v.volcengineHasKeys ? "火山方舟凭据已保存" : "已保存(仍缺一半,请补全)");
2471
+ loadVolc(true);
2472
+ }).catch(err => setMsg("保存失败:" + String(err && err.message ? err.message : err)));
2473
+ }
2474
+ function volcClearCred() {
2475
+ apiCall("volcengine-config", { clear: true }).then(() => {
2476
+ setVolcId(""); setVolcSecret(""); setVolcHasSecret(false);
2477
+ setMsg("火山方舟凭据已清除");
2478
+ loadVolc(true);
2479
+ }).catch(() => {});
2480
+ }
2481
+ // 用输入框里的凭据直接查一次(不落盘,便于先验证再保存)
2482
+ function volcQueryWithCred() {
2483
+ const payload = { force: true };
2484
+ if (volcId.trim()) payload.accessKeyId = volcId.trim();
2485
+ if (volcSecret.trim()) payload.secretAccessKey = volcSecret.trim();
2486
+ setVolcBusy(true);
2487
+ apiCall("volcengine-usage", payload).then(v => {
2488
+ setVolc(v); setVolcBusy(false);
2489
+ if (v && v.ok) setVolcHasSecret(!!(volcHasSecret || volcSecret.trim()));
2490
+ else setMsg("查询失败:" + String((v && v.error) || "未知错误").slice(0, 200));
2491
+ }).catch(err => { setVolcBusy(false); setMsg("查询失败:" + String(err && err.message ? err.message : err)); });
2492
+ }
1828
2493
  function loadUsage() {
1829
2494
  apiCall("usage", {}).then(v => {
1830
2495
  if (v && v.ok) { setUsage(v); setUsageErr(""); }
@@ -1895,14 +2560,23 @@ window.__ModuleLoader__.load({
1895
2560
  pending: sync ? sync.pending : 0,
1896
2561
  };
1897
2562
 
1898
- // 火山方舟面板只在「用得上」时出现:存在火山订阅调用(宿主判定并在
1899
- // summary 里回传 volcengineActive),或已有窗口数据 / 已尝试过凭据。
1900
- // 只跑 DeepSeek 或 Kimi 的用户界面保持不变,不会被一个无关面板撑长。
1901
- const showVolc = !!(volc || (viewDash && viewDash.volcengineActive === true));
2563
+ // 火山方舟面板的显示条件(按「用不用得上」):
2564
+ // · 已有窗口数据(volc 非空)—— 查过就会显示,含失败(失败也要能就地改凭据);
2565
+ // · 宿主判定存在火山订阅调用(summary.volcengineActive);
2566
+ // · 已经保存过凭据 —— 用户显然在用,必须一直可见,否则保存完就找不到入口了;
2567
+ // · 用户主动打开过(本地标记)—— 首次使用时的入口,避免「必须先调用过才看得到配置」。
2568
+ let volcOpened = false;
2569
+ try { volcOpened = localStorage.getItem("dsh-cost-tracker-volc-open") === "1" } catch (e) {}
2570
+ const showVolc = !!(volc || volcOpened || volcHasSecret || volcId
2571
+ || (viewDash && viewDash.volcengineActive === true));
2572
+ function openVolc() {
2573
+ try { localStorage.setItem("dsh-cost-tracker-volc-open", "1") } catch (e) {}
2574
+ loadVolc(true);
2575
+ }
1902
2576
 
1903
2577
  return e("div", { className: "cost-wrap" },
1904
2578
  e("div", { className: "cost-h1" }, pluginIcon(18), "花费统计"),
1905
- filterRow(days, setDays, onExport, onRefresh, msg, busy, dash ? dash.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)", viewCtl),
2579
+ filterRow(days, setDays, onExport, onRefresh, msg, busy, dash ? dash.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)", viewCtl, openVolc, planTotal, setPlanTotal),
1906
2580
  !cloudAvailable
1907
2581
  ? e("div", { className: "cost-hint", style: { marginTop: "4px" } },
1908
2582
  "仅显示本机数据。在多台电脑/多个 Agent 之间汇总:到「设置 → 插件 → 插件配置 → 花费统计」填写云端服务地址与令牌。")
@@ -1920,9 +2594,9 @@ window.__ModuleLoader__.load({
1920
2594
  : null,
1921
2595
  dashErr ? e("div", { className: "cost-err", style: { marginTop: "8px" } }, dashErr) : null,
1922
2596
  (!viewDash && !dashErr) ? e("div", { className: "cost-hint", style: { marginTop: "12px" } }, "加载中…") : null,
1923
- viewDash ? statCards(viewDash, balance, viewCtl) : null,
2597
+ viewDash ? statCards(viewDash, balance, viewCtl, planTotal) : null,
1924
2598
  view !== "local" && dimension !== "total" && viewDash ? dimensionPanel(viewDash, dimension, cloudMatrix, loadingCloud => loadingCloud) : null,
1925
- viewDash ? mainPanel(viewDash, tab, setTab, scheme, setScheme) : null,
2599
+ viewDash ? mainPanel(viewDash, tab, setTab, scheme, setScheme, planTotal) : null,
1926
2600
  e("div", { className: "cost-panel" },
1927
2601
  e("div", { className: "cost-row" },
1928
2602
  e("span", { className: "cost-panel-title" }, "Token 用量统计"),
@@ -1933,7 +2607,10 @@ window.__ModuleLoader__.load({
1933
2607
  : usageErr ? e("div", { className: "cost-err" }, "加载失败:" + usageErr)
1934
2608
  : e("div", { className: "cost-hint" }, "加载中…"))),
1935
2609
  subPanel(kimi, viewDash, now, () => loadKimi(true)),
1936
- showVolc ? volcenginePanel(volc, viewDash, now, () => loadVolc(true)) : null,
2610
+ showVolc ? volcenginePanel(volc, viewDash, now, () => loadVolc(true), volcCredForm({
2611
+ id: volcId, secret: volcSecret, busy: volcBusy,
2612
+ setId: setVolcId, setSecret: setVolcSecret,
2613
+ }, volcHasSecret, volcQueryWithCred, volcSaveCred, volcClearCred)) : null,
1937
2614
  balancePanel(balance, manualKey, setManualKey, k => loadBalance(k)),
1938
2615
  viewDash ? modelSections(viewDash) : null,
1939
2616
  viewDash ? recentPanel(viewDash) : null,