dsh-any-deepseek 0.0.20 → 0.0.22

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/adapter.d.ts CHANGED
@@ -202,6 +202,17 @@ export declare function collectImages(options: GenerateOptions, readImage: Adapt
202
202
  * @returns a pi-ai context plus the one-shot system prompt, when the caller set one.
203
203
  */
204
204
  export declare function toPiContext(options: GenerateOptions, images?: ImageBytes): PiContext;
205
+ /**
206
+ * 🔴 **DELETED: `textBlocks()` — do not reintroduce a text-only tool-result converter.**
207
+ *
208
+ * It mapped tool results to `{type:'text'}[]` only, justified by a comment claiming "tool results
209
+ * carry no images once projected". No layer enforces that: pi-ai types tool-result content as
210
+ * `(TextContent | ImageContent)[]` and the host converts tool messages through its user-message
211
+ * image path. The comment made a silent data loss look like a contract.
212
+ *
213
+ * The tool branch now uses {@link userContent}, so a `read_image` result reaches the model with
214
+ * its bytes — and an unreadable one becomes a visible placeholder instead of vanishing.
215
+ */
205
216
  /** Map pi-ai usage onto the harness's disjoint counters. */
206
217
  export declare function toTokenUsage(usage: AssistantMessage['usage']): TokenUsage;
207
218
  /**
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
@@ -1017,7 +1017,7 @@ function toPiContext(options, images) {
1017
1017
  role: "toolResult",
1018
1018
  toolCallId: message.toolCallId,
1019
1019
  toolName: "tool",
1020
- content: textBlocks(message.content),
1020
+ content: userContent(message.content, images),
1021
1021
  isError: message.isError ?? false,
1022
1022
  timestamp: 0
1023
1023
  };
@@ -1106,18 +1106,17 @@ function userContent(content, images) {
1106
1106
  }
1107
1107
  return out;
1108
1108
  }
1109
- /** Map harness content blocks to pi-ai text blocks (tool results carry no images once projected). */
1110
- function textBlocks(content) {
1111
- const out = [];
1112
- for (const block of content) {
1113
- const typed = block;
1114
- if (typed.type === "text" && typeof typed.text === "string") out.push({
1115
- type: "text",
1116
- text: typed.text
1117
- });
1118
- }
1119
- return out;
1120
- }
1109
+ /**
1110
+ * 🔴 **DELETED: `textBlocks()` — do not reintroduce a text-only tool-result converter.**
1111
+ *
1112
+ * It mapped tool results to `{type:'text'}[]` only, justified by a comment claiming "tool results
1113
+ * carry no images once projected". No layer enforces that: pi-ai types tool-result content as
1114
+ * `(TextContent | ImageContent)[]` and the host converts tool messages through its user-message
1115
+ * image path. The comment made a silent data loss look like a contract.
1116
+ *
1117
+ * The tool branch now uses {@link userContent}, so a `read_image` result reaches the model with
1118
+ * its bytes — and an unreadable one becomes a visible placeholder instead of vanishing.
1119
+ */
1121
1120
  /** Map pi-ai usage onto the harness's disjoint counters. */
1122
1121
  function toTokenUsage(usage) {
1123
1122
  const total = usage.totalTokens ?? usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
@@ -1869,18 +1868,36 @@ async function readLedgerRange(dir, from, to) {
1869
1868
  }
1870
1869
  /**
1871
1870
  * Group entries by a key and aggregate each group.
1871
+ *
1872
+ * ## Ordering (owner request 2026-10-27: 「倒序排列」)
1873
+ *
1874
+ * Rows come back **newest-first** for a time key (`YYYY-MM-DD`), because that is the order a
1875
+ * reader scans a usage log in: today's spend is the question, last week's is history. The old
1876
+ * ascending order put "2026-10-22" at the top while the newest day sat at the bottom, half a
1877
+ * screen of scrolling away from the 合计 it belongs to.
1878
+ *
1879
+ * Sorting is applied PER GROUP KIND rather than generally, because the two groupings are not
1880
+ * comparable: a channel key is an identity (stable, unordered — a reader looking for "Ollama"
1881
+ * scans alphabetically), while a day key is a point in time (ordered, and meaning flows one way).
1882
+ * Reversing channel rows would scramble a list people navigate by name.
1883
+ *
1884
+ * The comparison is a plain DESCENDING STRING compare, which is exact for `YYYY-MM-DD` because
1885
+ * that format is lexicographically ordered by construction. No `Date` parsing: a locale or
1886
+ * timezone conversion here could reorder days around midnight for no benefit.
1872
1887
  * @param entries - ledger entries already filtered to the range of interest.
1873
1888
  * @param by - grouping function (`channel`, `day`, …).
1874
- * @returns one row per group, sorted by key for stable rendering.
1889
+ * @param order - `'desc'` for newest-first (time keys); `'asc'` for stable identity keys.
1890
+ * @returns one row per group.
1875
1891
  */
1876
- function summarize(entries, by) {
1892
+ function summarize(entries, by, order = "asc") {
1877
1893
  const groups = /* @__PURE__ */ new Map();
1878
1894
  for (const entry of entries) {
1879
1895
  const key = by(entry);
1880
1896
  const existing = groups.get(key) ?? emptyAggregate();
1881
1897
  groups.set(key, addToAggregate(existing, entry));
1882
1898
  }
1883
- return [...groups.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, aggregate]) => ({
1899
+ const direction = order === "desc" ? -1 : 1;
1900
+ return [...groups.entries()].sort(([a], [b]) => a < b ? -direction : a > b ? direction : 0).map(([key, aggregate]) => ({
1884
1901
  key,
1885
1902
  aggregate
1886
1903
  }));
@@ -2557,7 +2574,12 @@ function registerStatsRoutes(ctx, webServer, deps) {
2557
2574
  const from = requestedFrom ?? (to === void 0 ? void 0 : /* @__PURE__ */ new Date(to.getTime() - 6048e5));
2558
2575
  const group = url.searchParams.get("group") ?? "channel";
2559
2576
  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);
2577
+ /**
2578
+ * 🔴 Day rows are NEWEST-FIRST (owner 2026-10-27: 「倒序排列」); channel rows stay
2579
+ * alphabetical. The order is a property of the grouping, not a global preference — see
2580
+ * `summarize` for why a time key and an identity key are not sorted the same way.
2581
+ */
2582
+ const rows = group === "day" ? summarize(entries, (entry) => dayKey(new Date(entry.at)), "desc") : summarize(entries, (entry) => entry.channel);
2561
2583
  /**
2562
2584
  * 🔴 Label each row with the channel's DISPLAY NAME, not its id.
2563
2585
  *
@@ -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.22",
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": {