@laoyuehanni/dsh-token-usage 0.3.13 → 0.4.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.
Files changed (109) hide show
  1. package/README.md +21 -86
  2. package/README.zh.md +21 -90
  3. package/docs/pricing.md +79 -0
  4. package/lib/client/QuotaButton.d.ts.map +1 -1
  5. package/lib/client/QuotaButton.js.map +1 -1
  6. package/lib/client/SessionStatsChip.d.ts.map +1 -1
  7. package/lib/client/SessionStatsChip.js.map +1 -1
  8. package/lib/client/StatCard.d.ts +61 -5
  9. package/lib/client/StatCard.d.ts.map +1 -1
  10. package/lib/client/StatCard.js +39 -1
  11. package/lib/client/StatCard.js.map +1 -1
  12. package/lib/client/TokenUsageCard.d.ts.map +1 -1
  13. package/lib/client/TokenUsageCard.js +23 -12
  14. package/lib/client/TokenUsageCard.js.map +1 -1
  15. package/lib/client/TokenUsageSection.d.ts.map +1 -1
  16. package/lib/client/TokenUsageSection.js +5 -5
  17. package/lib/client/TokenUsageSection.js.map +1 -1
  18. package/lib/client/TrendChart.d.ts +12 -3
  19. package/lib/client/TrendChart.d.ts.map +1 -1
  20. package/lib/client/TrendChart.js +42 -23
  21. package/lib/client/TrendChart.js.map +1 -1
  22. package/lib/client/UsageView.d.ts +16 -8
  23. package/lib/client/UsageView.d.ts.map +1 -1
  24. package/lib/client/UsageView.js +30 -16
  25. package/lib/client/UsageView.js.map +1 -1
  26. package/lib/client/card-form.d.ts +1 -1
  27. package/lib/client/card-form.d.ts.map +1 -1
  28. package/lib/client/format.d.ts +18 -3
  29. package/lib/client/format.d.ts.map +1 -1
  30. package/lib/client/format.js +45 -3
  31. package/lib/client/format.js.map +1 -1
  32. package/lib/client/index.d.ts +6 -6
  33. package/lib/client/index.d.ts.map +1 -1
  34. package/lib/client/index.js +7 -7
  35. package/lib/client/index.js.map +1 -1
  36. package/lib/client/locales.d.ts +21 -1
  37. package/lib/client/locales.d.ts.map +1 -1
  38. package/lib/client/locales.js +42 -2
  39. package/lib/client/locales.js.map +1 -1
  40. package/lib/client/trend-chart/index.d.ts +3 -1
  41. package/lib/client/trend-chart/index.d.ts.map +1 -1
  42. package/lib/client/trend-chart/index.js +2 -1
  43. package/lib/client/trend-chart/index.js.map +1 -1
  44. package/lib/client/trend-chart/path.d.ts +36 -0
  45. package/lib/client/trend-chart/path.d.ts.map +1 -0
  46. package/lib/client/trend-chart/path.js +51 -0
  47. package/lib/client/trend-chart/path.js.map +1 -0
  48. package/lib/client/trend-chart/points.d.ts +12 -0
  49. package/lib/client/trend-chart/points.d.ts.map +1 -1
  50. package/lib/client/trend-chart/points.js +21 -0
  51. package/lib/client/trend-chart/points.js.map +1 -1
  52. package/lib/client/trend-chart/scale.d.ts +8 -3
  53. package/lib/client/trend-chart/scale.d.ts.map +1 -1
  54. package/lib/client/trend-chart/scale.js +22 -14
  55. package/lib/client/trend-chart/scale.js.map +1 -1
  56. package/lib/client.js +412 -63
  57. package/lib/client.js.map +1 -1
  58. package/lib/index.d.ts +23 -9
  59. package/lib/index.d.ts.map +1 -1
  60. package/lib/index.js +142 -46
  61. package/lib/index.js.map +1 -1
  62. package/lib/log.d.ts +18 -0
  63. package/lib/log.d.ts.map +1 -0
  64. package/lib/log.js +16 -0
  65. package/lib/log.js.map +1 -0
  66. package/lib/migrate.d.ts +2 -1
  67. package/lib/migrate.d.ts.map +1 -1
  68. package/lib/migrate.js +3 -2
  69. package/lib/migrate.js.map +1 -1
  70. package/lib/pricing.d.ts +5 -2
  71. package/lib/pricing.d.ts.map +1 -1
  72. package/lib/pricing.js +15 -12
  73. package/lib/pricing.js.map +1 -1
  74. package/lib/record-cache.d.ts +11 -4
  75. package/lib/record-cache.d.ts.map +1 -1
  76. package/lib/record-cache.js +16 -9
  77. package/lib/record-cache.js.map +1 -1
  78. package/lib/rollup.d.ts +15 -8
  79. package/lib/rollup.d.ts.map +1 -1
  80. package/lib/rollup.js +14 -9
  81. package/lib/rollup.js.map +1 -1
  82. package/lib/stats-route.d.ts +3 -0
  83. package/lib/stats-route.d.ts.map +1 -1
  84. package/lib/stats-route.js +6 -4
  85. package/lib/stats-route.js.map +1 -1
  86. package/lib/stats.d.ts +8 -5
  87. package/lib/stats.d.ts.map +1 -1
  88. package/lib/stats.js +74 -26
  89. package/lib/stats.js.map +1 -1
  90. package/lib/sync-state.d.ts +2 -1
  91. package/lib/sync-state.d.ts.map +1 -1
  92. package/lib/sync-state.js +3 -2
  93. package/lib/sync-state.js.map +1 -1
  94. package/lib/sync.d.ts +24 -3
  95. package/lib/sync.d.ts.map +1 -1
  96. package/lib/sync.js +42 -10
  97. package/lib/sync.js.map +1 -1
  98. package/lib/usage-log.d.ts +23 -8
  99. package/lib/usage-log.d.ts.map +1 -1
  100. package/lib/usage-log.js +129 -17
  101. package/lib/usage-log.js.map +1 -1
  102. package/lib/usage-record.d.ts +88 -7
  103. package/lib/usage-record.d.ts.map +1 -1
  104. package/lib/usage-record.js +140 -4
  105. package/lib/usage-record.js.map +1 -1
  106. package/lib/wire.d.ts +19 -1
  107. package/lib/wire.d.ts.map +1 -1
  108. package/lib/wire.js.map +1 -1
  109. package/package.json +28 -17
package/lib/client.js CHANGED
@@ -1050,6 +1050,19 @@ window.__ModuleLoader__.load({
1050
1050
  }
1051
1051
  //#endregion
1052
1052
  //#region src/client/format.ts
1053
+ /** Known `LlmFailure.code`s that have a `fail.*` locale label. An unknown
1054
+ * future code is not in this map and the tooltip renders it verbatim. */
1055
+ const FAILURE_CODE_LABEL_KEYS = {
1056
+ RATE_LIMIT: "fail.RATE_LIMIT",
1057
+ SERVER: "fail.SERVER",
1058
+ TIMEOUT: "fail.TIMEOUT",
1059
+ TRANSPORT: "fail.TRANSPORT",
1060
+ EMPTY_RESPONSE: "fail.EMPTY_RESPONSE",
1061
+ QUOTA: "fail.QUOTA",
1062
+ CONTEXT_WINDOW_EXCEEDED: "fail.CONTEXT_WINDOW_EXCEEDED",
1063
+ INVALID_CREDENTIAL: "fail.INVALID_CREDENTIAL",
1064
+ UNKNOWN: "fail.UNKNOWN"
1065
+ };
1053
1066
  /** One decimal below 10, integer otherwise, trailing `.0` stripped. */
1054
1067
  function scale(value) {
1055
1068
  if (value >= 10) return String(Math.round(value));
@@ -1191,6 +1204,27 @@ window.__ModuleLoader__.load({
1191
1204
  const clamped = Math.max(0, tokensPerSecond);
1192
1205
  return clamped >= 10 ? String(Math.round(clamped)) : String(Math.round(clamped * 10) / 10);
1193
1206
  }
1207
+ /**
1208
+ * The failure pill's hover tooltip text: one `label ×count` line per failure
1209
+ * class, largest count first (code name ascending breaks ties), newline-joined —
1210
+ * the shell Tooltip renders `pre-line`, so each line lands on its own row.
1211
+ * Known `LlmFailure.code`s map through `fail.*` locale keys (限流 / Rate
1212
+ * limited); an unknown future code renders verbatim. A legacy shape without
1213
+ * the breakdown, or an empty map, yields '' and the caller suppresses the
1214
+ * tooltip.
1215
+ * @param byCode - the per-code failure counts from the totals (may be undefined).
1216
+ * @param t - locale lookup; codes without a `fail.*` key stay verbatim.
1217
+ * @returns the multi-line tooltip label, or '' when there is nothing to show.
1218
+ */
1219
+ function failuresTooltip(byCode, t) {
1220
+ if (byCode === void 0) return "";
1221
+ return Object.entries(byCode).filter(([, count]) => count > 0).sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0])).map(([code, count]) => `${failureCodeLabel(code, t)} ×${count}`).join("\n");
1222
+ }
1223
+ /** Locale label for one failure code; unknown codes stay verbatim. */
1224
+ function failureCodeLabel(code, t) {
1225
+ if (Object.hasOwn(FAILURE_CODE_LABEL_KEYS, code)) return t(FAILURE_CODE_LABEL_KEYS[code]);
1226
+ return code;
1227
+ }
1194
1228
  //#endregion
1195
1229
  //#region \0dsh-css:D:\Code\dsh-token-usage\src\client\hit-rate-band.module.css.mjs
1196
1230
  const css$8 = ".t6JM8a_band_critical{color:var(--dsw-alias-state-error-primary,#dc2626)}.t6JM8a_band_amber{color:#f59e0b}.t6JM8a_band_lime{color:#84cc16}.t6JM8a_band_healthy{color:var(--dsw-alias-state-success-primary,#16a34a)}";
@@ -1875,7 +1909,8 @@ window.__ModuleLoader__.load({
1875
1909
  processed: body.processed,
1876
1910
  total: body.total,
1877
1911
  added: body.added,
1878
- skipped: body.skipped
1912
+ skipped: body.skipped,
1913
+ failedSessions: typeof body.failedSessions === "number" ? body.failedSessions : 0
1879
1914
  };
1880
1915
  return null;
1881
1916
  }
@@ -1920,7 +1955,8 @@ window.__ModuleLoader__.load({
1920
1955
  processed: 0,
1921
1956
  total: 0,
1922
1957
  added: 0,
1923
- skipped: 0
1958
+ skipped: 0,
1959
+ failedSessions: 0
1924
1960
  });
1925
1961
  return;
1926
1962
  }
@@ -2071,14 +2107,14 @@ window.__ModuleLoader__.load({
2071
2107
  fullSync.status === "running" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2072
2108
  className: TokenUsageCard_module_css_default.fullSyncProgress,
2073
2109
  role: "status",
2074
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2110
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2075
2111
  className: TokenUsageCard_module_css_default.fullSyncProgressLabel,
2076
- children: t("card.fullSync.progress", {
2112
+ children: [t("card.fullSync.progress", {
2077
2113
  processed: String(fullSync.processed),
2078
2114
  total: String(fullSync.total),
2079
2115
  added: String(fullSync.added),
2080
2116
  skipped: String(fullSync.skipped)
2081
- })
2117
+ }), fullSync.failedSessions > 0 ? t("card.fullSync.failuresNote", { count: String(fullSync.failedSessions) }) : ""]
2082
2118
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2083
2119
  className: TokenUsageCard_module_css_default.fullSyncBar,
2084
2120
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -2087,13 +2123,13 @@ window.__ModuleLoader__.load({
2087
2123
  })
2088
2124
  })]
2089
2125
  }) : null,
2090
- fullSync.status === "done" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2126
+ fullSync.status === "done" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
2091
2127
  className: TokenUsageCard_module_css_default.fullSyncResult,
2092
2128
  role: "status",
2093
- children: t("card.fullSync.done", {
2129
+ children: [t("card.fullSync.done", {
2094
2130
  added: String(fullSync.added),
2095
2131
  skipped: String(fullSync.skipped)
2096
- })
2132
+ }), fullSync.failedSessions > 0 ? t("card.fullSync.failuresNote", { count: String(fullSync.failedSessions) }) : ""]
2097
2133
  }) : null,
2098
2134
  fullSync.status === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2099
2135
  className: TokenUsageCard_module_css_default.fullSyncError,
@@ -2537,7 +2573,7 @@ window.__ModuleLoader__.load({
2537
2573
  }
2538
2574
  //#endregion
2539
2575
  //#region \0dsh-css:D:\Code\dsh-token-usage\src\client\StatCard.module.css.mjs
2540
- const css$3 = ".F2LbNW_card{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;flex-direction:column;gap:2px;min-width:0;padding:10px 12px;display:flex}.F2LbNW_cardLabel{color:var(--dsw-alias-label-secondary);white-space:nowrap;text-overflow:ellipsis;font-size:11px;overflow:hidden}.F2LbNW_cardValue{font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary);white-space:nowrap;text-overflow:ellipsis;font-size:18px;font-weight:600;overflow:hidden}";
2576
+ const css$3 = ".F2LbNW_card{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;flex-direction:column;gap:2px;min-width:0;padding:10px 12px;display:flex}.F2LbNW_cardLabel{color:var(--dsw-alias-label-secondary);white-space:nowrap;text-overflow:ellipsis;font-size:11px;overflow:hidden}.F2LbNW_cardValue{font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary);flex-wrap:wrap;align-items:baseline;gap:4px 8px;min-width:0;font-size:18px;font-weight:600;display:flex}.F2LbNW_cardValueMain{white-space:nowrap;text-overflow:ellipsis;min-width:0;overflow:hidden}.F2LbNW_pillWrap{flex-shrink:0;display:inline-flex}.F2LbNW_pillWrap [role=tooltip]{white-space:pre;width:max-content;min-width:max-content;max-width:none;font-size:12px;font-weight:400;line-height:1.4}.F2LbNW_split{grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);align-items:baseline;column-gap:4px;width:100%;display:grid}.F2LbNW_splitOk{text-align:right;min-width:0}.F2LbNW_splitSep{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary))}.F2LbNW_splitFailHead{text-align:left;min-width:0}.F2LbNW_splitFail{text-align:left;min-width:0;color:var(--dsw-alias-state-error-primary);display:block}.F2LbNW_split>.F2LbNW_pillWrap{justify-self:stretch;min-width:0;display:block}.F2LbNW_pill{font-variant-numeric:tabular-nums;white-space:nowrap;color:var(--dsw-alias-state-error-primary);background:color-mix(in srgb, var(--dsw-alias-state-error-primary) 12%, transparent);border:1px solid color-mix(in srgb, var(--dsw-alias-state-error-primary) 28%, transparent);border-radius:999px;flex-shrink:0;padding:1px 7px;font-size:12px;font-weight:400;line-height:1.4}";
2541
2577
  const tagId$3 = "@laoyuehanni/dsh-token-usage/StatCard.module.css";
2542
2578
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$3) + "]") === null) {
2543
2579
  const tag = document.createElement("style");
@@ -2549,7 +2585,15 @@ window.__ModuleLoader__.load({
2549
2585
  var StatCard_module_css_default = {
2550
2586
  "card": "F2LbNW_card",
2551
2587
  "cardLabel": "F2LbNW_cardLabel",
2552
- "cardValue": "F2LbNW_cardValue"
2588
+ "cardValue": "F2LbNW_cardValue",
2589
+ "cardValueMain": "F2LbNW_cardValueMain",
2590
+ "pill": "F2LbNW_pill",
2591
+ "pillWrap": "F2LbNW_pillWrap",
2592
+ "split": "F2LbNW_split",
2593
+ "splitFail": "F2LbNW_splitFail",
2594
+ "splitFailHead": "F2LbNW_splitFailHead",
2595
+ "splitOk": "F2LbNW_splitOk",
2596
+ "splitSep": "F2LbNW_splitSep"
2553
2597
  };
2554
2598
  //#endregion
2555
2599
  //#region src/client/StatCard.tsx
@@ -2569,6 +2613,108 @@ window.__ModuleLoader__.load({
2569
2613
  })]
2570
2614
  });
2571
2615
  }
2616
+ /**
2617
+ * Compact "失败 n" chip for the requests **card** only. Hovering or focusing
2618
+ * it lists `限流 ×count` per class. Zero failures render nothing. Per-model
2619
+ * tables do not use this — they print `A/B` via {@link RequestsCell}.
2620
+ */
2621
+ function FailurePill({ failures, failuresByCode, t }) {
2622
+ if (failures === 0) return null;
2623
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2624
+ className: StatCard_module_css_default["pillWrap"],
2625
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
2626
+ label: failuresTooltip(failuresByCode, t),
2627
+ side: "bottom",
2628
+ delayMs: 200,
2629
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2630
+ className: StatCard_module_css_default["pill"],
2631
+ tabIndex: 0,
2632
+ children: t("stat.failuresPill", { count: failures.toLocaleString() })
2633
+ })
2634
+ })
2635
+ });
2636
+ }
2637
+ /**
2638
+ * The requests tile both dashboards share: hero figure is the successful
2639
+ * count; a compact pill to its right carries the failure count.
2640
+ */
2641
+ function RequestsStatCard({ requests, failures, failuresByCode, t }) {
2642
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatCard, {
2643
+ label: t("stat.requests"),
2644
+ value: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2645
+ className: StatCard_module_css_default["cardValueMain"],
2646
+ children: requests.toLocaleString()
2647
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FailurePill, {
2648
+ failures,
2649
+ failuresByCode,
2650
+ t
2651
+ })] })
2652
+ });
2653
+ }
2654
+ /** Column header for the per-model success/fail split: same 3-track
2655
+ * grid as {@link RequestsCell} so the slash sits on the column midline. */
2656
+ function RequestsSplitHead({ t }) {
2657
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2658
+ className: StatCard_module_css_default["split"],
2659
+ children: [
2660
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2661
+ className: StatCard_module_css_default["splitOk"],
2662
+ children: t("stat.ok")
2663
+ }),
2664
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2665
+ className: StatCard_module_css_default["splitSep"],
2666
+ "aria-hidden": true,
2667
+ children: "/"
2668
+ }),
2669
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2670
+ className: StatCard_module_css_default["splitFailHead"],
2671
+ children: t("stat.fail")
2672
+ })
2673
+ ]
2674
+ });
2675
+ }
2676
+ /** One table cell: successful count, and when failures > 0 a slash on
2677
+ * the column midline plus the failure count in the error color.
2678
+ * Zero failures print only A (same left track, so the figure still
2679
+ * lines up with rows that have a B). Hovering B lists the per-code
2680
+ * breakdown. */
2681
+ function RequestsCell({ requests, failures, failuresByCode, t }) {
2682
+ const ok = requests.toLocaleString();
2683
+ const okFigure = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2684
+ className: StatCard_module_css_default["splitOk"],
2685
+ children: ok
2686
+ });
2687
+ if (failures === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2688
+ className: StatCard_module_css_default["split"],
2689
+ children: okFigure
2690
+ });
2691
+ const fail = failures.toLocaleString();
2692
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2693
+ className: StatCard_module_css_default["split"],
2694
+ children: [
2695
+ okFigure,
2696
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2697
+ className: StatCard_module_css_default["splitSep"],
2698
+ "aria-hidden": true,
2699
+ children: "/"
2700
+ }),
2701
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2702
+ className: StatCard_module_css_default["pillWrap"],
2703
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
2704
+ label: failuresTooltip(failuresByCode, t),
2705
+ side: "bottom",
2706
+ delayMs: 200,
2707
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2708
+ className: StatCard_module_css_default["splitFail"],
2709
+ tabIndex: 0,
2710
+ "aria-label": t("stat.failuresPill", { count: fail }),
2711
+ children: fail
2712
+ })
2713
+ })
2714
+ })
2715
+ ]
2716
+ });
2717
+ }
2572
2718
  //#endregion
2573
2719
  //#region src/client/trend-chart/axis.ts
2574
2720
  /**
@@ -2607,6 +2753,46 @@ window.__ModuleLoader__.load({
2607
2753
  };
2608
2754
  }
2609
2755
  //#endregion
2756
+ //#region src/client/trend-chart/path.ts
2757
+ /**
2758
+ * Per-segment gap flags: `flags[i]` is true when the next bucket starts
2759
+ * after this bucket's exclusive `end`. Adjacent uniform buckets have
2760
+ * `next.time === prev.end` and are not gaps.
2761
+ */
2762
+ function gapAfter(points) {
2763
+ const flags = [];
2764
+ for (let index = 0; index < points.length - 1; index += 1) flags.push(points[index + 1].time > points[index].end);
2765
+ return flags;
2766
+ }
2767
+ /**
2768
+ * SVG `d` for already-scaled coordinates. Empty → `''`; one point → `M`.
2769
+ *
2770
+ * `gap` is the original polyline plus a patch: adjacent buckets stay a
2771
+ * straight `L`; a gap holds `hold` (`zero` = axis, `previous` = last y)
2772
+ * from the previous bucket's end until one bucket-width before the next
2773
+ * start, then slants in — so idle is not interpolated and dense hours
2774
+ * keep the polyline.
2775
+ */
2776
+ function seriesPath(input) {
2777
+ const { xs, ys, yZero, style, hold, gaps, xEnds } = input;
2778
+ if (xs.length === 0) return "";
2779
+ const cmd = (letter, x, y) => `${letter}${x.toFixed(1)},${y.toFixed(1)}`;
2780
+ const parts = [cmd("M", xs[0], ys[0])];
2781
+ for (let index = 0; index < xs.length - 1; index += 1) {
2782
+ const xNext = xs[index + 1];
2783
+ const yNext = ys[index + 1];
2784
+ if (style === "gap" && gaps?.[index] === true) {
2785
+ const ends = xEnds ?? xs;
2786
+ const xEnd = ends[index];
2787
+ const nextWidth = Math.max(ends[index + 1] - xNext, 0);
2788
+ const xHold = Math.max(xEnd, xNext - nextWidth);
2789
+ const holdY = hold === "previous" ? ys[index] : yZero;
2790
+ parts.push(cmd("L", xEnd, holdY), cmd("L", xHold, holdY), cmd("L", xNext, yNext));
2791
+ } else parts.push(cmd("L", xNext, yNext));
2792
+ }
2793
+ return parts.join(" ");
2794
+ }
2795
+ //#endregion
2610
2796
  //#region src/trend-bucket.ts
2611
2797
  /**
2612
2798
  * Bucket widths tried from fine to coarse (ms); the first whose bucket count
@@ -2707,6 +2893,7 @@ window.__ModuleLoader__.load({
2707
2893
  full: `${bucketLabel(bucket.start, crossDay)}–${bucketLabel(bucket.end, crossDay)}`,
2708
2894
  tokens: bucket.tokens,
2709
2895
  time: bucket.start,
2896
+ end: bucket.end,
2710
2897
  count: bucket.count
2711
2898
  }))
2712
2899
  };
@@ -2726,6 +2913,34 @@ window.__ModuleLoader__.load({
2726
2913
  };
2727
2914
  return null;
2728
2915
  }
2916
+ /**
2917
+ * The cumulative view of a series: every point's `tokens` replaced by the
2918
+ * running total up to and including that point (a prefix sum), so the chart
2919
+ * reads as a monotonic rise. Orthogonal to the mode — all three input
2920
+ * shapes are time-ascending, so a plain forward fold is order-correct. The
2921
+ * input series is left untouched; each point is copied with only `tokens`
2922
+ * rewritten, so the renderer's shape probes (`'time' in point`) keep working.
2923
+ * @param series - the series from {@link buildChartPoints}.
2924
+ * @returns a new series of the same mode and shape.
2925
+ */
2926
+ function cumulateSeries(series) {
2927
+ let running = 0;
2928
+ const fold = (points) => points.map((point) => {
2929
+ running += point.tokens;
2930
+ return {
2931
+ ...point,
2932
+ tokens: running
2933
+ };
2934
+ });
2935
+ if (series.mode === "equidistant") return {
2936
+ mode: "equidistant",
2937
+ points: fold(series.points)
2938
+ };
2939
+ return {
2940
+ mode: "temporal",
2941
+ points: fold(series.points)
2942
+ };
2943
+ }
2729
2944
  /** A series that already carries `count` (the host's `fields=session`
2730
2945
  * downsample) is plotted as-is; a raw per-request series is folded here. */
2731
2946
  function bucketsOf(requests) {
@@ -2767,14 +2982,17 @@ window.__ModuleLoader__.load({
2767
2982
  }
2768
2983
  //#endregion
2769
2984
  //#region src/client/trend-chart/scale.ts
2985
+ function clampX(value, leftEdge, rightEdge) {
2986
+ return Math.min(Math.max(value, leftEdge), rightEdge);
2987
+ }
2770
2988
  /**
2771
2989
  * Pick the right x scale for a {@link ChartSeries} and produce the
2772
2990
  * per-point offsets in absolute viewBox coordinates. Equidistant modes
2773
2991
  * lay points one stride apart across the `[leftEdge, rightEdge]` span;
2774
2992
  * temporal mode uses each point's wall time against the series' own
2775
- * first-to-last span and adds `leftEdge` to the result. Single-point
2776
- * series pin to the centerline of the span (a zero stride would not
2777
- * scale, and temporal scale would divide by zero).
2993
+ * first-start to last-start span and adds `leftEdge` to the result.
2994
+ * A zero span (one point, or every start equal) pins to the centerline.
2995
+ * Temporal results include `xEnds` for the gap-path bucket width.
2778
2996
  *
2779
2997
  * @param series - the discriminated-union series from {@link buildChartPoints}.
2780
2998
  * @param leftEdge - the absolute SVG x of the chart's left edge (the
@@ -2798,14 +3016,29 @@ window.__ModuleLoader__.load({
2798
3016
  innerWidth
2799
3017
  };
2800
3018
  }
2801
- const temporal = points;
3019
+ const temporal = series.points;
2802
3020
  const first = temporal[0].time;
2803
- const last = temporal[temporal.length - 1].time;
3021
+ const lastStart = temporal[temporal.length - 1].time;
3022
+ if (temporal.length === 1 || first === lastStart) {
3023
+ const mid = (leftEdge + rightEdge) / 2;
3024
+ const xs = temporal.map(() => mid);
3025
+ return {
3026
+ xs,
3027
+ xEnds: [...xs],
3028
+ innerWidth
3029
+ };
3030
+ }
2804
3031
  const xs = [];
2805
- if (temporal.length === 1 || first === last) xs.push((leftEdge + rightEdge) / 2);
2806
- else for (const point of temporal) xs.push(leftEdge + scaleToSpan(first, last, point.time, innerWidth));
3032
+ const xEnds = [];
3033
+ for (const point of temporal) {
3034
+ const x = clampX(leftEdge + scaleToSpan(first, lastStart, point.time, innerWidth), leftEdge, rightEdge);
3035
+ const xEnd = clampX(leftEdge + scaleToSpan(first, lastStart, point.end, innerWidth), leftEdge, rightEdge);
3036
+ xs.push(x);
3037
+ xEnds.push(Math.max(x, xEnd));
3038
+ }
2807
3039
  return {
2808
3040
  xs,
3041
+ xEnds,
2809
3042
  innerWidth
2810
3043
  };
2811
3044
  }
@@ -2886,21 +3119,28 @@ window.__ModuleLoader__.load({
2886
3119
  /**
2887
3120
  * Apply the `t`-based localisation to a point's `full` tooltip. The pre-shape
2888
3121
  * labels live in points.ts; the chart's aria-label and the floating tooltip
2889
- * both use this single source so the two stay consistent.
3122
+ * both use this single source so the two stay consistent. Cumulative mode
3123
+ * swaps in its own phrasing so "total" never reads ambiguous next to a
3124
+ * running sum.
2890
3125
  * @param t - the locale seat.
2891
3126
  * @param point - the pre-shaped point.
3127
+ * @param mode - the active y-axis mode.
2892
3128
  * @returns the tooltip / aria-label text.
2893
3129
  */
2894
- function tipOf(t, point) {
2895
- if (point.time !== void 0) return t("chart.bucket", {
2896
- window: point.full,
2897
- count: String(point.count ?? 0),
2898
- tokens: formatTokens(point.tokens)
2899
- });
2900
- return t("chart.pointLabel", {
3130
+ function tipOf(t, point, mode) {
3131
+ if (point.time !== void 0) {
3132
+ const params = {
3133
+ window: point.full,
3134
+ count: String(point.count ?? 0),
3135
+ tokens: formatTokens(point.tokens)
3136
+ };
3137
+ return mode === "cumulative" ? t("chart.cumulativeBucket", params) : t("chart.bucket", params);
3138
+ }
3139
+ const params = {
2901
3140
  day: point.full,
2902
3141
  tokens: formatTokens(point.tokens)
2903
- });
3142
+ };
3143
+ return mode === "cumulative" ? t("chart.cumulativePoint", params) : t("chart.pointLabel", params);
2904
3144
  }
2905
3145
  /**
2906
3146
  * Render the daily / hourly / request-bucketed token line chart. Pure
@@ -2915,22 +3155,25 @@ window.__ModuleLoader__.load({
2915
3155
  * @param props - the filtered per-day rows plus the optional per-hour rows
2916
3156
  * (when present the chart plots hours instead of days), the optional
2917
3157
  * per-request series (session-scoped reads), the active range bounds
2918
- * (absent when unfiltered; the chart then spans first to last row), and
3158
+ * (absent when unfiltered; the chart then spans first to last row), the
3159
+ * optional y-axis mode (interval totals, or their running cumulative sum),
3160
+ * and
2919
3161
  * the `t` seat for the empty hint and chart aria-label.
2920
3162
  * @returns the SVG chart, or a placeholder for an empty range.
2921
3163
  */
2922
- function TrendChart({ rows, hours, requests, from, to, t }) {
2923
- const series = buildChartPoints({
3164
+ function TrendChart({ rows, hours, requests, from, to, mode = "interval", t }) {
3165
+ const base = buildChartPoints({
2924
3166
  rows,
2925
3167
  hours,
2926
3168
  requests,
2927
3169
  from,
2928
3170
  to
2929
3171
  });
2930
- if (series === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3172
+ if (base === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2931
3173
  className: TrendChart_module_css_default.empty,
2932
3174
  children: t("chart.empty")
2933
3175
  });
3176
+ const series = mode === "cumulative" ? cumulateSeries(base) : base;
2934
3177
  const points = series.points.map((point) => ({
2935
3178
  key: point.key,
2936
3179
  label: point.label,
@@ -2941,13 +3184,23 @@ window.__ModuleLoader__.load({
2941
3184
  }));
2942
3185
  const { top, ticks } = tickValues(Math.max(...points.map((p) => p.tokens)));
2943
3186
  const innerHeight = 140;
2944
- const { xs, innerWidth } = scaleSeries(series, LEFT, 784);
3187
+ const { xs, xEnds, innerWidth } = scaleSeries(series, LEFT, 784);
2945
3188
  const radius = dotRadius(points.length);
2946
3189
  const [active, setActive] = (0, react.useState)(null);
2947
3190
  const activePoint = active === null ? null : points[active] ?? null;
2948
3191
  const y = (tokens) => 152 - tokens / top * innerHeight;
2949
- const path = points.map((point, index) => `${index === 0 ? "M" : "L"}${xs[index].toFixed(1)},${y(point.tokens).toFixed(1)}`).join(" ");
2950
- const chartAria = series.mode === "temporal" ? t("chart.ariaRequests") : hours !== void 0 ? t("chart.ariaHour") : t("chart.aria");
3192
+ const path = seriesPath({
3193
+ xs,
3194
+ ys: points.map((point) => y(point.tokens)),
3195
+ yZero: y(0),
3196
+ style: series.mode === "temporal" ? "gap" : "polyline",
3197
+ ...series.mode === "temporal" ? {
3198
+ gaps: gapAfter(series.points),
3199
+ xEnds: xEnds ?? xs,
3200
+ hold: mode === "cumulative" ? "previous" : "zero"
3201
+ } : {}
3202
+ });
3203
+ const chartAria = mode === "cumulative" ? t("chart.ariaCumulative") : series.mode === "temporal" ? t("chart.ariaRequests") : hours !== void 0 ? t("chart.ariaHour") : t("chart.aria");
2951
3204
  const hitExtent = (index) => {
2952
3205
  if (points.length === 1) return {
2953
3206
  start: LEFT,
@@ -3016,7 +3269,7 @@ window.__ModuleLoader__.load({
3016
3269
  width: hit.width,
3017
3270
  height: innerHeight,
3018
3271
  fill: "transparent",
3019
- "aria-label": tipOf(t, point),
3272
+ "aria-label": tipOf(t, point, mode),
3020
3273
  role: "button",
3021
3274
  tabIndex: 0,
3022
3275
  className: TrendChart_module_css_default.hit,
@@ -3026,7 +3279,7 @@ window.__ModuleLoader__.load({
3026
3279
  }, point.key);
3027
3280
  }),
3028
3281
  activePoint !== null ? (() => {
3029
- const label = tipOf(t, activePoint);
3282
+ const label = tipOf(t, activePoint, mode);
3030
3283
  const labelWidth = label.length * 6.2 + 12;
3031
3284
  const center = xs[active];
3032
3285
  const left = Math.min(Math.max(center - labelWidth / 2, LEFT), 784 - labelWidth);
@@ -3469,16 +3722,18 @@ window.__ModuleLoader__.load({
3469
3722
  onChange: setFilters,
3470
3723
  t
3471
3724
  }),
3472
- total.requests === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3725
+ total.requests === 0 && (total.failures ?? 0) === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3473
3726
  className: TokenUsageSection_module_css_default["empty"],
3474
3727
  children: t("empty")
3475
3728
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
3476
3729
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3477
3730
  className: TokenUsageSection_module_css_default["cards"],
3478
3731
  children: [
3479
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatCard, {
3480
- label: t("stat.requests"),
3481
- value: total.requests.toLocaleString()
3732
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestsStatCard, {
3733
+ requests: total.requests,
3734
+ failures: total.failures ?? 0,
3735
+ failuresByCode: total.failuresByCode,
3736
+ t
3482
3737
  }),
3483
3738
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatCard, {
3484
3739
  label: t("stat.cost"),
@@ -3544,7 +3799,10 @@ window.__ModuleLoader__.load({
3544
3799
  className: TokenUsageSection_module_css_default["modelHead"],
3545
3800
  children: t("filter.model")
3546
3801
  }),
3547
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.requests") }),
3802
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
3803
+ "aria-label": t("stat.successFail"),
3804
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestsSplitHead, { t })
3805
+ }),
3548
3806
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.cost") }),
3549
3807
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.totalTokens") }),
3550
3808
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.input") }),
@@ -3574,7 +3832,12 @@ window.__ModuleLoader__.load({
3574
3832
  })]
3575
3833
  })
3576
3834
  }),
3577
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row.totals.requests.toLocaleString() }),
3835
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestsCell, {
3836
+ requests: row.totals.requests,
3837
+ failures: row.totals.failures ?? 0,
3838
+ failuresByCode: row.totals.failuresByCode,
3839
+ t
3840
+ }) }),
3578
3841
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: rules !== void 0 ? formatCost(row.cost, view) : "—" }),
3579
3842
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(totalTokens(row.totals)) }),
3580
3843
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(row.totals.inputTokens) }),
@@ -3599,7 +3862,7 @@ window.__ModuleLoader__.load({
3599
3862
  }
3600
3863
  //#endregion
3601
3864
  //#region \0dsh-css:D:\Code\dsh-token-usage\src\client\UsageView.module.css.mjs
3602
- const css = "._0MkXVa_root{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,16px) + 16px);flex-direction:column;gap:12px;max-width:1400px;height:100%;margin:0 auto;display:flex;overflow-y:auto}._0MkXVa_head{flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:12px;display:flex}._0MkXVa_headRight{align-items:center;gap:10px;display:flex}._0MkXVa_back{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;padding:3px 10px;font-size:12px}._0MkXVa_back:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}._0MkXVa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}._0MkXVa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}._0MkXVa_segBtn:hover:not(._0MkXVa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}._0MkXVa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}._0MkXVa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}._0MkXVa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}._0MkXVa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}._0MkXVa_empty{color:var(--dsw-alias-label-secondary);text-align:center;margin:24px 0 0;font-size:13px}._0MkXVa_button{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;align-self:flex-start;padding:3px 10px;font-size:12px}._0MkXVa_warning{color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-label-secondary));margin:0;font-size:12px}._0MkXVa_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:11px}._0MkXVa_cards{grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;display:grid}._0MkXVa_tokenStrip{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:18px;padding:6px 2px 0;font-size:12px;display:flex}._0MkXVa_tokenStrip b{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}._0MkXVa_mid{grid-template-columns:minmax(0,3fr) minmax(0,2fr);align-items:start;gap:14px;display:grid}._0MkXVa_chartCol,._0MkXVa_modelCol,._0MkXVa_subagents{flex-direction:column;gap:6px;min-width:0;display:flex}._0MkXVa_subagentsHead{align-items:center;gap:8px;display:flex}._0MkXVa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px;font-weight:600}._0MkXVa_tableWrap{overflow-x:auto}._0MkXVa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}._0MkXVa_table th,._0MkXVa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}._0MkXVa_table th:first-child,._0MkXVa_table td:first-child,._0MkXVa_modelHead{text-align:left}._0MkXVa_modelCell{font-variant-numeric:normal;text-overflow:ellipsis;max-width:180px;overflow:hidden}._0MkXVa_childLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:none;max-width:220px;padding:0;font-size:12px;overflow:hidden}._0MkXVa_childLink:hover{text-decoration:underline}._0MkXVa_nestedBadge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px;font-size:11px}@media (width<=900px){._0MkXVa_cards{grid-template-columns:repeat(3,minmax(0,1fr))}._0MkXVa_mid{grid-template-columns:1fr}}";
3865
+ const css = "._0MkXVa_root{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,16px) + 16px);padding-bottom:calc(var(--dsh-composer-height,152px) + 16px);flex-direction:column;gap:12px;max-width:1400px;height:100%;min-height:0;margin:0 auto;display:flex;overflow-y:auto}._0MkXVa_head{flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:12px;display:flex}._0MkXVa_headRight{align-items:center;gap:10px;display:flex}._0MkXVa_back{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;padding:3px 10px;font-size:12px}._0MkXVa_back:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}._0MkXVa_segmented{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-fill-container,transparent);border-radius:8px;align-items:stretch;gap:2px;padding:2px;display:inline-flex}._0MkXVa_segBtn{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer;background:0 0;border:none;border-radius:6px;padding:4px 12px;font-size:12px;font-weight:500}._0MkXVa_segBtn:hover:not(._0MkXVa_segActive){color:var(--dsw-alias-label-secondary);background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent)}._0MkXVa_segBtn:focus-visible{outline:2px solid var(--dsw-alias-border-l2);outline-offset:1px}._0MkXVa_segActive{background:color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);color:var(--dsw-alias-label-primary);font-weight:600}._0MkXVa_muted{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px}._0MkXVa_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px}._0MkXVa_empty{color:var(--dsw-alias-label-secondary);text-align:center;margin:24px 0 0;font-size:13px}._0MkXVa_button{border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border-radius:6px;align-self:flex-start;padding:3px 10px;font-size:12px}._0MkXVa_warning{color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-label-secondary));margin:0;font-size:12px}._0MkXVa_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:11px}._0MkXVa_cards{grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;display:grid}._0MkXVa_tokenStrip{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:18px;padding:6px 2px 0;font-size:12px;display:flex}._0MkXVa_tokenStrip b{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}._0MkXVa_mid{grid-template-columns:minmax(0,3fr) minmax(0,2fr);align-items:start;gap:14px;display:grid}._0MkXVa_chartCol,._0MkXVa_modelCol,._0MkXVa_subagents{flex-direction:column;gap:6px;min-width:0;display:flex}._0MkXVa_subagentsHead,._0MkXVa_chartHead{align-items:center;gap:8px;display:flex}._0MkXVa_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px;font-weight:600}._0MkXVa_tableWrap{overflow-x:auto}._0MkXVa_table{border-collapse:collapse;font-variant-numeric:tabular-nums;width:100%;min-width:480px;font-size:12px}._0MkXVa_table th,._0MkXVa_table td{text-align:right;border-bottom:1px solid var(--dsw-alias-border-l1);white-space:nowrap;padding:4px 6px}._0MkXVa_table th:first-child,._0MkXVa_table td:first-child,._0MkXVa_modelHead{text-align:left}._0MkXVa_modelCell{font-variant-numeric:normal;text-overflow:ellipsis;max-width:180px;overflow:hidden}._0MkXVa_childLink{color:var(--dsw-alias-link-primary,var(--dsw-alias-label-primary));cursor:pointer;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:none;max-width:220px;padding:0;font-size:12px;overflow:hidden}._0MkXVa_childLink:hover{text-decoration:underline}._0MkXVa_nestedBadge{color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;margin-left:6px;font-size:11px}@media (width<=900px){._0MkXVa_cards{grid-template-columns:repeat(3,minmax(0,1fr))}._0MkXVa_mid{grid-template-columns:1fr}}";
3603
3866
  const tagId = "@laoyuehanni/dsh-token-usage/UsageView.module.css";
3604
3867
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
3605
3868
  const tag = document.createElement("style");
@@ -3613,6 +3876,7 @@ window.__ModuleLoader__.load({
3613
3876
  "button": "_0MkXVa_button",
3614
3877
  "cards": "_0MkXVa_cards",
3615
3878
  "chartCol": "_0MkXVa_chartCol",
3879
+ "chartHead": "_0MkXVa_chartHead",
3616
3880
  "childLink": "_0MkXVa_childLink",
3617
3881
  "empty": "_0MkXVa_empty",
3618
3882
  "error": "_0MkXVa_error",
@@ -3643,11 +3907,12 @@ window.__ModuleLoader__.load({
3643
3907
  * The conversation view tab "Usage" (browser half): one entry of the
3644
3908
  * `conversation.view` slot ring (beside Chat / Trajectory), rendering the
3645
3909
  * per-session token & cost dashboard for the ACTIVE conversation. The tab
3646
- * shows the focused session's totals (4 token buckets, cost, hit rate,
3647
- * TTFT average, decode throughput) with a scope switch between the session
3648
- * alone and its whole subagent subtree, a per-hour trend chart and the
3649
- * per-model table from the host stats route (`sessionId`-scoped), and a
3650
- * subagent table below — each row drill-in switches the focus to that child.
3910
+ * shows the focused session's totals (successful requests with a failure
3911
+ * pill, 4 token buckets, cost, hit rate, TTFT average, decode throughput) with a
3912
+ * scope switch between the session alone and its whole subagent subtree, a
3913
+ * per-hour trend chart and the per-model table from the host stats route
3914
+ * (`sessionId`-scoped), and a subagent table below — each row drill-in
3915
+ * switches the focus to that child.
3651
3916
  *
3652
3917
  * Data sources: token/cost figures come from the host route (the pricing
3653
3918
  * rule chain's authority); TTFT and throughput come from the framework's
@@ -3656,12 +3921,21 @@ window.__ModuleLoader__.load({
3656
3921
  * the whole log including history written before this plugin was installed.
3657
3922
  * A footnote states the two scopes so the difference is not a surprise.
3658
3923
  *
3924
+ * The root declares `data-conversation-composer-overlay` — the same host
3925
+ * opt-in Trajectory uses. ConversationRoot hides the chat-column width
3926
+ * handles when that attribute is present, and the view owns its own
3927
+ * scroller instead of sharing the transcript's constrained column.
3928
+ *
3659
3929
  * @module token-usage/client/UsageView
3660
3930
  */
3661
3931
  /** Refresh debounce: bursts of session-mirror updates (one request's events)
3662
3932
  * collapse into a single fetch, so the dashboard refreshes at REQUEST
3663
3933
  * granularity instead of per event or per turn. */
3664
3934
  const REFRESH_DEBOUNCE_MS = 250;
3935
+ /** Host contract (ui-conversation ConversationRoot): views that own a
3936
+ * full-bleed scroller set this so the chat-column width handles hide and
3937
+ * the composer seat overlays instead of stealing clicks over the dashboard. */
3938
+ const COMPOSER_OVERLAY = { "data-conversation-composer-overlay": "" };
3665
3939
  /** One fetch of the session-scoped summary from the host stats route,
3666
3940
  * including the direct-child breakdown for the subagent table. */
3667
3941
  function fetchSessionSummary(sessionIds, childGroups, signal) {
@@ -3688,6 +3962,7 @@ window.__ModuleLoader__.load({
3688
3962
  const rootRef = (0, react.useRef)(null);
3689
3963
  useColorSchemeMirror(rootRef);
3690
3964
  const [scope, setScope] = (0, react.useState)("session");
3965
+ const [chartMode, setChartMode] = (0, react.useState)("interval");
3691
3966
  const [focusId, setFocusId] = (0, react.useState)(sessionId);
3692
3967
  (0, react.useEffect)(() => {
3693
3968
  setFocusId(sessionId);
@@ -3770,6 +4045,7 @@ window.__ModuleLoader__.load({
3770
4045
  if (summaryState.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3771
4046
  ref: rootRef,
3772
4047
  className: UsageView_module_css_default["root"],
4048
+ ...COMPOSER_OVERLAY,
3773
4049
  children: [header, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3774
4050
  className: UsageView_module_css_default["muted"],
3775
4051
  children: t("loading")
@@ -3778,6 +4054,7 @@ window.__ModuleLoader__.load({
3778
4054
  if (summaryState.status === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3779
4055
  ref: rootRef,
3780
4056
  className: UsageView_module_css_default["root"],
4057
+ ...COMPOSER_OVERLAY,
3781
4058
  children: [
3782
4059
  header,
3783
4060
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
@@ -3798,18 +4075,21 @@ window.__ModuleLoader__.load({
3798
4075
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3799
4076
  ref: rootRef,
3800
4077
  className: UsageView_module_css_default["root"],
4078
+ ...COMPOSER_OVERLAY,
3801
4079
  children: [
3802
4080
  header,
3803
- total.requests === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4081
+ total.requests === 0 && (total.failures ?? 0) === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3804
4082
  className: UsageView_module_css_default["empty"],
3805
4083
  children: t("view.empty")
3806
4084
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
3807
4085
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3808
4086
  className: UsageView_module_css_default["cards"],
3809
4087
  children: [
3810
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatCard, {
3811
- label: t("stat.requests"),
3812
- value: total.requests.toLocaleString()
4088
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestsStatCard, {
4089
+ requests: total.requests,
4090
+ failures: total.failures ?? 0,
4091
+ failuresByCode: total.failuresByCode,
4092
+ t
3813
4093
  }),
3814
4094
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatCard, {
3815
4095
  label: t("stat.cost"),
@@ -3871,11 +4151,32 @@ window.__ModuleLoader__.load({
3871
4151
  className: UsageView_module_css_default["mid"],
3872
4152
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
3873
4153
  className: UsageView_module_css_default["chartCol"],
3874
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
3875
- className: UsageView_module_css_default["subtitle"],
3876
- children: t("view.chart.title")
4154
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4155
+ className: UsageView_module_css_default["chartHead"],
4156
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
4157
+ className: UsageView_module_css_default["subtitle"],
4158
+ children: t("view.chart.title")
4159
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4160
+ className: UsageView_module_css_default["segmented"],
4161
+ role: "group",
4162
+ "aria-label": t("chart.mode.label"),
4163
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4164
+ type: "button",
4165
+ className: chartMode === "interval" ? `${UsageView_module_css_default["segBtn"]} ${UsageView_module_css_default["segActive"]}` : UsageView_module_css_default["segBtn"],
4166
+ "aria-pressed": chartMode === "interval",
4167
+ onClick: () => setChartMode("interval"),
4168
+ children: t("chart.mode.interval")
4169
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4170
+ type: "button",
4171
+ className: chartMode === "cumulative" ? `${UsageView_module_css_default["segBtn"]} ${UsageView_module_css_default["segActive"]}` : UsageView_module_css_default["segBtn"],
4172
+ "aria-pressed": chartMode === "cumulative",
4173
+ onClick: () => setChartMode("cumulative"),
4174
+ children: t("chart.mode.cumulative")
4175
+ })]
4176
+ })]
3877
4177
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TrendChart, {
3878
4178
  rows: summary.byDay,
4179
+ mode: chartMode,
3879
4180
  t,
3880
4181
  ...summary.requestSeries !== void 0 ? { requests: summary.requestSeries } : {},
3881
4182
  ...summary.byDay.length === 1 ? { hours: summary.byHour } : {}
@@ -3895,7 +4196,10 @@ window.__ModuleLoader__.load({
3895
4196
  className: UsageView_module_css_default["modelHead"],
3896
4197
  children: t("filter.model")
3897
4198
  }),
3898
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.requests") }),
4199
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
4200
+ "aria-label": t("stat.successFail"),
4201
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestsSplitHead, { t })
4202
+ }),
3899
4203
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.input") }),
3900
4204
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.output") }),
3901
4205
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", { children: t("stat.cacheRead") }),
@@ -3907,7 +4211,12 @@ window.__ModuleLoader__.load({
3907
4211
  className: UsageView_module_css_default["modelCell"],
3908
4212
  children: row.model
3909
4213
  }),
3910
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row.totals.requests.toLocaleString() }),
4214
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestsCell, {
4215
+ requests: row.totals.requests,
4216
+ failures: row.totals.failures ?? 0,
4217
+ failuresByCode: row.totals.failuresByCode,
4218
+ t
4219
+ }) }),
3911
4220
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(row.totals.inputTokens) }),
3912
4221
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(row.totals.outputTokens) }),
3913
4222
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: formatTokens(row.totals.cacheReadTokens) }),
@@ -3995,7 +4304,7 @@ window.__ModuleLoader__.load({
3995
4304
  })
3996
4305
  })]
3997
4306
  }),
3998
- total.requests > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4307
+ (total.requests > 0 || (total.failures ?? 0) > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3999
4308
  className: UsageView_module_css_default["note"],
4000
4309
  children: t("view.note")
4001
4310
  })
@@ -4036,7 +4345,20 @@ window.__ModuleLoader__.load({
4036
4345
  "calendar.weekday.4": "五",
4037
4346
  "calendar.weekday.5": "六",
4038
4347
  "calendar.weekday.6": "日",
4039
- "stat.requests": "请求数",
4348
+ "stat.requests": "成功请求数",
4349
+ "stat.successFail": "成功/失败",
4350
+ "stat.ok": "成功",
4351
+ "stat.fail": "失败",
4352
+ "stat.failuresPill": "失败 {count}",
4353
+ "fail.RATE_LIMIT": "限流",
4354
+ "fail.SERVER": "服务异常",
4355
+ "fail.TIMEOUT": "超时",
4356
+ "fail.TRANSPORT": "网络异常",
4357
+ "fail.EMPTY_RESPONSE": "空响应",
4358
+ "fail.QUOTA": "配额耗尽",
4359
+ "fail.CONTEXT_WINDOW_EXCEEDED": "上下文超限",
4360
+ "fail.INVALID_CREDENTIAL": "凭证无效",
4361
+ "fail.UNKNOWN": "未知错误",
4040
4362
  "stat.totalTokens": "总 token",
4041
4363
  "stat.hitRate": "命中率",
4042
4364
  "stat.cost": "费用",
@@ -4092,6 +4414,7 @@ window.__ModuleLoader__.load({
4092
4414
  "card.fullSync.button": "开始扫描",
4093
4415
  "card.fullSync.running": "扫描中…",
4094
4416
  "card.fullSync.progress": "已处理 {processed}/{total} 个 session,新增 {added} 条,跳过 {skipped} 条",
4417
+ "card.fullSync.failuresNote": ",无法读取 {count} 个 session 已跳过",
4095
4418
  "card.fullSync.done": "扫描完成:新增 {added} 条,跳过 {skipped} 条",
4096
4419
  "card.fullSync.failed": "扫描失败:{error}",
4097
4420
  "loadFailed": "统计加载失败:{message}",
@@ -4102,6 +4425,12 @@ window.__ModuleLoader__.load({
4102
4425
  "chart.ariaRequests": "按时间分段的 token 曲线",
4103
4426
  "chart.pointLabel": "{day} 总量 {tokens}",
4104
4427
  "chart.bucket": "{window} · {count} 请求 · {tokens}",
4428
+ "chart.mode.label": "趋势模式",
4429
+ "chart.mode.interval": "分时",
4430
+ "chart.mode.cumulative": "累计",
4431
+ "chart.ariaCumulative": "累计 token 曲线",
4432
+ "chart.cumulativePoint": "{day} 累计 {tokens}",
4433
+ "chart.cumulativeBucket": "{window} · {count} 请求 · 累计 {tokens}",
4105
4434
  "view.usage": "用量",
4106
4435
  "view.scope.label": "统计范围",
4107
4436
  "view.scope.session": "本会话",
@@ -4156,7 +4485,20 @@ window.__ModuleLoader__.load({
4156
4485
  "calendar.weekday.4": "Fr",
4157
4486
  "calendar.weekday.5": "Sa",
4158
4487
  "calendar.weekday.6": "Su",
4159
- "stat.requests": "Requests",
4488
+ "stat.requests": "Successful requests",
4489
+ "stat.successFail": "OK/Fail",
4490
+ "stat.ok": "OK",
4491
+ "stat.fail": "Fail",
4492
+ "stat.failuresPill": "Failed {count}",
4493
+ "fail.RATE_LIMIT": "Rate limited",
4494
+ "fail.SERVER": "Server error",
4495
+ "fail.TIMEOUT": "Timed out",
4496
+ "fail.TRANSPORT": "Network error",
4497
+ "fail.EMPTY_RESPONSE": "Empty response",
4498
+ "fail.QUOTA": "Quota exceeded",
4499
+ "fail.CONTEXT_WINDOW_EXCEEDED": "Context exceeded",
4500
+ "fail.INVALID_CREDENTIAL": "Invalid credential",
4501
+ "fail.UNKNOWN": "Unknown error",
4160
4502
  "stat.totalTokens": "Total",
4161
4503
  "stat.hitRate": "Hit %",
4162
4504
  "stat.cost": "Cost",
@@ -4212,6 +4554,7 @@ window.__ModuleLoader__.load({
4212
4554
  "card.fullSync.button": "Start scan",
4213
4555
  "card.fullSync.running": "Scanning…",
4214
4556
  "card.fullSync.progress": "Processed {processed}/{total} sessions, added {added}, skipped {skipped}",
4557
+ "card.fullSync.failuresNote": ", {count} unreadable sessions skipped",
4215
4558
  "card.fullSync.done": "Scan complete: added {added}, skipped {skipped}",
4216
4559
  "card.fullSync.failed": "Scan failed: {error}",
4217
4560
  "loadFailed": "Failed to load stats: {message}",
@@ -4222,6 +4565,12 @@ window.__ModuleLoader__.load({
4222
4565
  "chart.ariaRequests": "Time-bucketed token trend",
4223
4566
  "chart.pointLabel": "{day} total {tokens}",
4224
4567
  "chart.bucket": "{window} · {count} requests · {tokens}",
4568
+ "chart.mode.label": "Trend mode",
4569
+ "chart.mode.interval": "Interval",
4570
+ "chart.mode.cumulative": "Cumulative",
4571
+ "chart.ariaCumulative": "Cumulative token trend",
4572
+ "chart.cumulativePoint": "{day} cumulative {tokens}",
4573
+ "chart.cumulativeBucket": "{window} · {count} requests · cumulative {tokens}",
4225
4574
  "view.usage": "Usage",
4226
4575
  "view.scope.label": "Scope",
4227
4576
  "view.scope.session": "Session",
@@ -4263,15 +4612,15 @@ window.__ModuleLoader__.load({
4263
4612
  */
4264
4613
  const TOKEN_USAGE_NS = "token-usage";
4265
4614
  /** Required services: the slot registry, the locale dictionaries, the
4266
- * settings scope, and the workspace service (its native directory picker
4267
- * backs the card's browse button). */
4615
+ * settings scope, and the workspace navigation service (its native
4616
+ * directory picker backs the card's browse button). */
4268
4617
  const inject = [
4269
4618
  "slots",
4270
4619
  "locale",
4271
4620
  "connection",
4272
4621
  "remote",
4273
4622
  "settingsScope",
4274
- "workspaces"
4623
+ "uiWorkspace"
4275
4624
  ];
4276
4625
  /**
4277
4626
  * Register the dictionary pair, then the settings page and the plugin
@@ -4329,7 +4678,7 @@ window.__ModuleLoader__.load({
4329
4678
  inject: () => ({
4330
4679
  hooks: { tokenUsageCard: store },
4331
4680
  ...form.actions(),
4332
- pickDirectory: () => ctx.workspaces.pickDirectory()
4681
+ pickDirectory: () => ctx.uiWorkspace.pickDirectory()
4333
4682
  })
4334
4683
  }, TokenUsageCard));
4335
4684
  }