dsh-any-deepseek 0.0.20 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -219,6 +219,21 @@ window.__ModuleLoader__.load({
219
219
  */
220
220
  const REPO_URL = "https://github.com/tellmewhattodo/dsh-any-deepseek";
221
221
  /**
222
+ * How many usage rows are shown before 「查看更多」 (owner request 2026-10-27: 「只展示前10」).
223
+ *
224
+ * 🔴 This is a DISPLAY limit, not a data limit: `/stats` still returns every row it computed, and
225
+ * the 合计 footer is summed server-side over ALL of them. Both halves matter:
226
+ * · showing 10 rows while summing all of them is the honest reading — "these are the 10 newest
227
+ * days; this is the total across the whole range";
228
+ * · summing only the visible 10 would silently shrink 合计 as the range grew, which turns a
229
+ * total into a partial sum that looks exactly like a total.
230
+ *
231
+ * The number is 10 because the default range is 7 days, so the table normally shows everything
232
+ * and the limit only engages when the reader widens the range — which is exactly when a cap
233
+ * helps.
234
+ */
235
+ const USAGE_ROW_LIMIT = 10;
236
+ /**
222
237
  * A channel id derived from a preset id, made unique against what already exists.
223
238
  *
224
239
  * The id is a configuration key, so it must match `^[a-z0-9][a-z0-9_-]*$`. Preset ids already do,
@@ -269,6 +284,15 @@ window.__ModuleLoader__.load({
269
284
  const [balancesLoading, setBalancesLoading] = (0, react.useState)(false);
270
285
  const [group, setGroup] = (0, react.useState)("channel");
271
286
  /**
287
+ * Whether the usage table shows every row or only the newest {@link USAGE_ROW_LIMIT}.
288
+ *
289
+ * Collapsed by default so opening 用量 answers "how much lately" at a glance instead of
290
+ * starting with a long scroll. Reset whenever the grouping changes: "expanded" was a decision
291
+ * about one specific table, and carrying it into a different grouping would silently show a
292
+ * different amount of data than the reader last chose.
293
+ */
294
+ const [showAllRows, setShowAllRows] = (0, react.useState)(false);
295
+ /**
272
296
  * Which of the panel's two questions is on screen.
273
297
  *
274
298
  * 渠道 is the default because it is the one a new user must answer first — an empty panel
@@ -505,6 +529,17 @@ window.__ModuleLoader__.load({
505
529
  setRenaming(null);
506
530
  setRenameDraft("");
507
531
  };
532
+ /**
533
+ * The usage rows actually rendered.
534
+ *
535
+ * Truncation happens HERE, in the component, and not in `/stats` — the server keeps returning
536
+ * the full set so that (a) 合计 can be summed over everything, and (b) 「查看更多」 is instant
537
+ * rather than a second round-trip that might answer with a different range.
538
+ */
539
+ const allRows = stats?.rows ?? [];
540
+ const visibleRows = showAllRows ? allRows : allRows.slice(0, USAGE_ROW_LIMIT);
541
+ /** Rows held back by the display limit; `0` means the table is complete. */
542
+ const hiddenRowCount = allRows.length - visibleRows.length;
508
543
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
509
544
  className: "ad-page",
510
545
  children: [
@@ -916,13 +951,19 @@ window.__ModuleLoader__.load({
916
951
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
917
952
  type: "button",
918
953
  className: `ad-seg${group === "channel" ? " ad-seg-on" : ""}`,
919
- onClick: () => setGroup("channel"),
954
+ onClick: () => {
955
+ setGroup("channel");
956
+ setShowAllRows(false);
957
+ },
920
958
  children: "按渠道"
921
959
  }),
922
960
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
923
961
  type: "button",
924
962
  className: `ad-seg${group === "day" ? " ad-seg-on" : ""}`,
925
- onClick: () => setGroup("day"),
963
+ onClick: () => {
964
+ setGroup("day");
965
+ setShowAllRows(false);
966
+ },
926
967
  children: "按天"
927
968
  }),
928
969
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
@@ -988,7 +1029,7 @@ window.__ModuleLoader__.load({
988
1029
  title: "首字平均等待时间",
989
1030
  children: "首字"
990
1031
  })
991
- ] }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tbody", { children: [stats.rows.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", { children: [
1032
+ ] }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tbody", { children: [visibleRows.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", { children: [
992
1033
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", { children: row.label ?? row.key }),
993
1034
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
994
1035
  className: "ad-num",
@@ -1078,6 +1119,28 @@ window.__ModuleLoader__.load({
1078
1119
  })] })]
1079
1120
  })
1080
1121
  }),
1122
+ stats !== null && stats.total.requests > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1123
+ className: "ad-rowActions",
1124
+ children: [hiddenRowCount > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1125
+ type: "button",
1126
+ className: "ad-btn ad-btn-quiet",
1127
+ onClick: () => setShowAllRows(true),
1128
+ children: [
1129
+ "查看更多(还有 ",
1130
+ hiddenRowCount,
1131
+ " 天)"
1132
+ ]
1133
+ }), hiddenRowCount === 0 && showAllRows && allRows.length > USAGE_ROW_LIMIT && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1134
+ type: "button",
1135
+ className: "ad-btn ad-btn-quiet",
1136
+ onClick: () => setShowAllRows(false),
1137
+ children: [
1138
+ "收起(只看最近 ",
1139
+ USAGE_ROW_LIMIT,
1140
+ " 天)"
1141
+ ]
1142
+ })]
1143
+ }),
1081
1144
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
1082
1145
  className: "ad-note",
1083
1146
  children: [
@@ -1107,6 +1170,24 @@ window.__ModuleLoader__.load({
1107
1170
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "近 7 天" }),
1108
1171
  "。更早的账本仍在磁盘上(按月的 JSONL,未删除), 只是这个视图默认不展示——历史记录是花销的唯一凭据,删掉就回不来了。"
1109
1172
  ]
1173
+ }),
1174
+ hiddenRowCount > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
1175
+ className: "ad-note",
1176
+ children: [
1177
+ "下表只显示",
1178
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("strong", { children: [
1179
+ "最新的 ",
1180
+ visibleRows.length,
1181
+ " 行"
1182
+ ] }),
1183
+ ";",
1184
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "合计" }),
1185
+ "仍是整个范围内全部 ",
1186
+ allRows.length,
1187
+ " 行的总和,不是可见这部分的。 点「查看更多」看其余 ",
1188
+ hiddenRowCount,
1189
+ " 行。"
1190
+ ]
1110
1191
  })
1111
1192
  ]
1112
1193
  }),
package/lib/index.js CHANGED
@@ -1869,18 +1869,36 @@ async function readLedgerRange(dir, from, to) {
1869
1869
  }
1870
1870
  /**
1871
1871
  * Group entries by a key and aggregate each group.
1872
+ *
1873
+ * ## Ordering (owner request 2026-10-27: 「倒序排列」)
1874
+ *
1875
+ * Rows come back **newest-first** for a time key (`YYYY-MM-DD`), because that is the order a
1876
+ * reader scans a usage log in: today's spend is the question, last week's is history. The old
1877
+ * ascending order put "2026-10-22" at the top while the newest day sat at the bottom, half a
1878
+ * screen of scrolling away from the 合计 it belongs to.
1879
+ *
1880
+ * Sorting is applied PER GROUP KIND rather than generally, because the two groupings are not
1881
+ * comparable: a channel key is an identity (stable, unordered — a reader looking for "Ollama"
1882
+ * scans alphabetically), while a day key is a point in time (ordered, and meaning flows one way).
1883
+ * Reversing channel rows would scramble a list people navigate by name.
1884
+ *
1885
+ * The comparison is a plain DESCENDING STRING compare, which is exact for `YYYY-MM-DD` because
1886
+ * that format is lexicographically ordered by construction. No `Date` parsing: a locale or
1887
+ * timezone conversion here could reorder days around midnight for no benefit.
1872
1888
  * @param entries - ledger entries already filtered to the range of interest.
1873
1889
  * @param by - grouping function (`channel`, `day`, …).
1874
- * @returns one row per group, sorted by key for stable rendering.
1890
+ * @param order - `'desc'` for newest-first (time keys); `'asc'` for stable identity keys.
1891
+ * @returns one row per group.
1875
1892
  */
1876
- function summarize(entries, by) {
1893
+ function summarize(entries, by, order = "asc") {
1877
1894
  const groups = /* @__PURE__ */ new Map();
1878
1895
  for (const entry of entries) {
1879
1896
  const key = by(entry);
1880
1897
  const existing = groups.get(key) ?? emptyAggregate();
1881
1898
  groups.set(key, addToAggregate(existing, entry));
1882
1899
  }
1883
- return [...groups.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, aggregate]) => ({
1900
+ const direction = order === "desc" ? -1 : 1;
1901
+ return [...groups.entries()].sort(([a], [b]) => a < b ? -direction : a > b ? direction : 0).map(([key, aggregate]) => ({
1884
1902
  key,
1885
1903
  aggregate
1886
1904
  }));
@@ -2557,7 +2575,12 @@ function registerStatsRoutes(ctx, webServer, deps) {
2557
2575
  const from = requestedFrom ?? (to === void 0 ? void 0 : /* @__PURE__ */ new Date(to.getTime() - 6048e5));
2558
2576
  const group = url.searchParams.get("group") ?? "channel";
2559
2577
  const entries = await readLedgerRange(deps.ledgerDir(), from, to);
2560
- const rows = group === "day" ? summarize(entries, (entry) => dayKey(new Date(entry.at))) : summarize(entries, (entry) => entry.channel);
2578
+ /**
2579
+ * 🔴 Day rows are NEWEST-FIRST (owner 2026-10-27: 「倒序排列」); channel rows stay
2580
+ * alphabetical. The order is a property of the grouping, not a global preference — see
2581
+ * `summarize` for why a time key and an identity key are not sorted the same way.
2582
+ */
2583
+ const rows = group === "day" ? summarize(entries, (entry) => dayKey(new Date(entry.at)), "desc") : summarize(entries, (entry) => entry.channel);
2561
2584
  /**
2562
2585
  * 🔴 Label each row with the channel's DISPLAY NAME, not its id.
2563
2586
  *
@@ -187,10 +187,27 @@ export declare function appendLedgerEntry(dir: string, entry: LedgerEntry, now?:
187
187
  export declare function readLedgerRange(dir: string, from?: Date, to?: Date): Promise<LedgerEntry[]>;
188
188
  /**
189
189
  * Group entries by a key and aggregate each group.
190
+ *
191
+ * ## Ordering (owner request 2026-10-27: 「倒序排列」)
192
+ *
193
+ * Rows come back **newest-first** for a time key (`YYYY-MM-DD`), because that is the order a
194
+ * reader scans a usage log in: today's spend is the question, last week's is history. The old
195
+ * ascending order put "2026-10-22" at the top while the newest day sat at the bottom, half a
196
+ * screen of scrolling away from the 合计 it belongs to.
197
+ *
198
+ * Sorting is applied PER GROUP KIND rather than generally, because the two groupings are not
199
+ * comparable: a channel key is an identity (stable, unordered — a reader looking for "Ollama"
200
+ * scans alphabetically), while a day key is a point in time (ordered, and meaning flows one way).
201
+ * Reversing channel rows would scramble a list people navigate by name.
202
+ *
203
+ * The comparison is a plain DESCENDING STRING compare, which is exact for `YYYY-MM-DD` because
204
+ * that format is lexicographically ordered by construction. No `Date` parsing: a locale or
205
+ * timezone conversion here could reorder days around midnight for no benefit.
190
206
  * @param entries - ledger entries already filtered to the range of interest.
191
207
  * @param by - grouping function (`channel`, `day`, …).
192
- * @returns one row per group, sorted by key for stable rendering.
208
+ * @param order - `'desc'` for newest-first (time keys); `'asc'` for stable identity keys.
209
+ * @returns one row per group.
193
210
  */
194
- export declare function summarize(entries: readonly LedgerEntry[], by: (entry: LedgerEntry) => string): LedgerSummary[];
211
+ export declare function summarize(entries: readonly LedgerEntry[], by: (entry: LedgerEntry) => string, order?: 'asc' | 'desc'): LedgerSummary[];
195
212
  /** Sum every group into one row (the table's footer). */
196
213
  export declare function totalOf(rows: readonly LedgerSummary[]): LedgerAggregate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-any-deepseek",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "One DeepSeek V4.1 Flash provider for DeepSeek Harness: paste a key per channel, switch channels manually, token usage booked per real upstream.",
5
5
  "license": "MIT",
6
6
  "repository": {