@dungsil/dsh-plugin-ui-usage 0.1.1 → 0.2.0

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 (2) hide show
  1. package/dist/client.js +35 -9
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -160,23 +160,35 @@ function Usage({ ctx }) {
160
160
  const locale = useLocaleSnapshot(ctx.locale);
161
161
  const text = localizedCopy(locale.active);
162
162
  const number = new Intl.NumberFormat(locale.active);
163
+ const tokens = new Intl.NumberFormat(locale.active, {
164
+ notation: "compact",
165
+ maximumFractionDigits: 1
166
+ });
163
167
  const [period, setPeriod] = (0, react.useState)(7);
164
168
  const [periodOpen, setPeriodOpen] = (0, react.useState)(false);
165
169
  const [refresh, setRefresh] = (0, react.useState)(0);
170
+ const refreshRequested = (0, react.useRef)(false);
166
171
  const connection = ctx.get("connection");
167
172
  const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
168
173
  const cacheKey = JSON.stringify([period, timeZone]);
169
174
  let cache = cachedViews.get(connection);
170
175
  if (!cache) cachedViews.set(connection, cache = /* @__PURE__ */ new Map());
171
176
  const [view, setView] = (0, react.useState)(() => cache.get(cacheKey));
172
- const [busy, setBusy] = (0, react.useState)(true);
177
+ const [busy, setBusy] = (0, react.useState)(() => !cache.has(cacheKey));
173
178
  const [error, setError] = (0, react.useState)(false);
174
179
  const [selectedDay, setSelectedDay] = (0, react.useState)(() => view?.days.at(-1)?.day ?? "");
175
180
  (0, react.useEffect)(() => {
181
+ const cached = cache.get(cacheKey);
182
+ setError(false);
183
+ setView(cached);
184
+ if (cached && !refreshRequested.current) {
185
+ setBusy(false);
186
+ setSelectedDay((day) => cached.days.some((entry) => entry.day === day) ? day : cached.days.at(-1)?.day ?? "");
187
+ return;
188
+ }
189
+ refreshRequested.current = false;
176
190
  const controller = new AbortController();
177
191
  setBusy(true);
178
- setError(false);
179
- setView(cache.get(cacheKey));
180
192
  (async () => {
181
193
  try {
182
194
  const result = await connection.rpc.call(channel, method, {
@@ -263,7 +275,10 @@ function Usage({ ctx }) {
263
275
  "aria-busy": busy,
264
276
  icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconRefreshOutlineRegular, {}),
265
277
  disabled: busy,
266
- onClick: () => setRefresh((value) => value + 1),
278
+ onClick: () => {
279
+ refreshRequested.current = true;
280
+ setRefresh((value) => value + 1);
281
+ },
267
282
  children: busy ? text.refreshing : text.refresh
268
283
  })]
269
284
  }),
@@ -281,8 +296,12 @@ function Usage({ ctx }) {
281
296
  className: "dsh-usage-summary",
282
297
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: text.total }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
283
298
  className: "dsh-usage-total",
284
- children: number.format(view.totals.total)
285
- })] }), metrics.map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: text[key] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: number.format(view.totals[key]) })] }, key))]
299
+ title: number.format(view.totals.total),
300
+ children: tokens.format(view.totals.total)
301
+ })] }), metrics.map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: text[key] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
302
+ title: number.format(view.totals[key]),
303
+ children: tokens.format(view.totals[key])
304
+ })] }, key))]
286
305
  }),
287
306
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
288
307
  className: "dsh-usage-meta dsh-usage-muted",
@@ -337,7 +356,8 @@ function Usage({ ctx }) {
337
356
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
338
357
  className: "dsh-usage-detail",
339
358
  "aria-live": "polite",
340
- children: selected && `${date(selected.day)} · ${text.total}: ${number.format(selected.total)}`
359
+ title: selected && number.format(selected.total),
360
+ children: selected && `${date(selected.day)} · ${text.total}: ${tokens.format(selected.total)}`
341
361
  }),
342
362
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: text.models }),
343
363
  view.models.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -348,8 +368,14 @@ function Usage({ ctx }) {
348
368
  row.provider || text.unknown,
349
369
  " / ",
350
370
  row.model || text.unknown
351
- ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: number.format(row.total) })]
352
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dl", { children: ["calls", ...metrics].map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: text[key] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: number.format(row[key]) })] }, key)) })]
371
+ ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
372
+ title: number.format(row.total),
373
+ children: tokens.format(row.total)
374
+ })]
375
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dl", { children: ["calls", ...metrics].map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: text[key] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
376
+ title: number.format(row[key]),
377
+ children: key === "calls" ? number.format(row[key]) : tokens.format(row[key])
378
+ })] }, key)) })]
353
379
  }, JSON.stringify([row.provider, row.model])))
354
380
  ] }),
355
381
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dungsil/dsh-plugin-ui-usage",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Recorded session token usage dashboard for DeepSeek Harness.",
5
5
  "license": "MIT",
6
6
  "repository": {