dsh-tool-stats 0.1.4 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ Ecosystem sync: every plugin in this suite shares one version, so a version number
6
+ identifies a set that was tested together rather than one plugin's own history.
7
+
8
+ - Fix the Model Arena panel rendering "Cannot read properties of undefined": the host
9
+ route returned the bare run list while the view reads `payload.recentRuns`.
10
+ - The client `inject` field now names services (`slots`, `connection`) instead of the
11
+ packages that provide them.
12
+ - README badges cover version, downloads, CI, license, Node requirement, stars, and the
13
+ dsh plugin topic.
14
+
3
15
  ## 0.1.4
4
16
 
5
17
  - **Fix the client half never activating.** The browser half declared package names
package/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # dsh-tool-stats
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/dsh-tool-stats)](https://www.npmjs.com/package/dsh-tool-stats) [![CI](https://github.com/hj01857655/dsh-tool-stats/actions/workflows/ci.yml/badge.svg)](https://github.com/hj01857655/dsh-tool-stats/actions/workflows/ci.yml)
3
+ [![npm version](https://img.shields.io/npm/v/dsh-tool-stats?color=cb3837&logo=npm&logoColor=white)](https://www.npmjs.com/package/dsh-tool-stats)
4
+ [![npm downloads](https://img.shields.io/npm/dm/dsh-tool-stats?color=cb3837)](https://www.npmjs.com/package/dsh-tool-stats)
5
+ [![CI](https://github.com/hj01857655/dsh-tool-stats/actions/workflows/ci.yml/badge.svg)](https://github.com/hj01857655/dsh-tool-stats/actions/workflows/ci.yml)
6
+ [![license](https://img.shields.io/npm/l/dsh-tool-stats?color=blue)](LICENSE)
7
+ [![node](https://img.shields.io/node/v/dsh-tool-stats?color=339933&logo=node.js&logoColor=white)](package.json)
8
+ [![GitHub stars](https://img.shields.io/github/stars/hj01857655/dsh-tool-stats?color=yellow)](https://github.com/hj01857655/dsh-tool-stats/stargazers)
9
+ [![dsh plugin](https://img.shields.io/badge/dsh-plugin-4B8BBE)](https://github.com/topics/dsh-plugin)
4
10
 
5
11
  Every tool call is counted, and the ones that never fire are named so you can remove them.
6
12
 
@@ -1,14 +1,15 @@
1
1
  /**
2
- * Browser half of dsh-tool-stats: the Tool Stats page inside Settings.
2
+ * Browser half of dsh-tool-stats: its page inside Settings.
3
3
  *
4
- * Services are named by their runtime identity, not by the package that provides them:
5
- * the settings shell is the `slots` service and the host bridge is `connection`. A
6
- * fiber that injects package names never resolves and the plugin stays pending, which
7
- * the loader reports as "did not activate".
4
+ * Two services are injected by their runtime identity, not by the packages that provide
5
+ * them: the settings shell is `slots`, the dictionary registry is `locale`. The label and
6
+ * every string inside the component are translated through this plugin's own namespace,
7
+ * which is why the page follows the UI language instead of the plugin author's.
8
8
  *
9
9
  * @module client
10
10
  */
11
11
  import type { ComponentType } from 'react';
12
+ export declare const inject: string[];
12
13
  interface SlotsService {
13
14
  inject(name: string, register: () => void): void;
14
15
  register(options: {
@@ -16,11 +17,21 @@ interface SlotsService {
16
17
  id: string;
17
18
  order: number;
18
19
  label: () => string;
19
- }, component: ComponentType): unknown;
20
+ locale: string;
21
+ }, component: ComponentType<{
22
+ t: (key: string, params?: Record<string, unknown>) => string;
23
+ }>): unknown;
20
24
  }
21
- /** The slots service is what the settings shell exposes. */
22
- export declare const inject: string[];
23
- export declare function apply(ctx: {
25
+ interface ClientContext {
24
26
  slots: SlotsService;
25
- }): void;
27
+ locale: {
28
+ register(ns: string, dicts: {
29
+ zh: unknown;
30
+ en: unknown;
31
+ }): () => void;
32
+ bind(ns: string): (key: string, params?: Record<string, unknown>) => string;
33
+ };
34
+ effect(callback: () => unknown, label?: string): unknown;
35
+ }
36
+ export declare function apply(ctx: ClientContext): void;
26
37
  export {};
@@ -1,65 +1,24 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
1
  /**
3
- * Browser half of dsh-tool-stats: the Tool Stats page inside Settings.
2
+ * Browser half of dsh-tool-stats: its page inside Settings.
4
3
  *
5
- * Services are named by their runtime identity, not by the package that provides them:
6
- * the settings shell is the `slots` service and the host bridge is `connection`. A
7
- * fiber that injects package names never resolves and the plugin stays pending, which
8
- * the loader reports as "did not activate".
4
+ * Two services are injected by their runtime identity, not by the packages that provide
5
+ * them: the settings shell is `slots`, the dictionary registry is `locale`. The label and
6
+ * every string inside the component are translated through this plugin's own namespace,
7
+ * which is why the page follows the UI language instead of the plugin author's.
9
8
  *
10
9
  * @module client
11
10
  */
12
- import { useCallback, useEffect, useState } from 'react';
13
- import { renderPanel } from './view.js';
14
- /** Path the host half registers on the web connection. */
15
- const PANEL_PATH = '/api/stats.panel';
16
- /** Fetch the panel payload; `reload` re-runs the request. */
17
- function usePanel() {
18
- const [html, setHtml] = useState(null);
19
- const [error, setError] = useState(null);
20
- const [tick, setTick] = useState(0);
21
- const reload = useCallback(() => setTick((t) => t + 1), []);
22
- useEffect(() => {
23
- const controller = new AbortController();
24
- setError(null);
25
- fetch(PANEL_PATH, { signal: controller.signal })
26
- .then(async (response) => {
27
- if (!response.ok)
28
- throw new Error(`panel request failed with ${response.status}`);
29
- return response.json();
30
- })
31
- .then((payload) => {
32
- if (!controller.signal.aborted)
33
- setHtml(renderPanel(payload));
34
- })
35
- .catch((cause) => {
36
- if (controller.signal.aborted)
37
- return;
38
- // Say what failed rather than rendering an empty panel, which would read as
39
- // "nothing recorded" — a different and wrong answer.
40
- setError(cause instanceof Error ? cause.message : String(cause));
41
- });
42
- return () => controller.abort();
43
- }, [tick]);
44
- return { html, error, reload };
45
- }
46
- function ToolStatsPage() {
47
- const { html, error, reload } = usePanel();
48
- if (error !== null) {
49
- return (_jsxs("section", { children: [_jsxs("p", { role: "alert", children: ["Tool Stats panel failed to load: ", error] }), _jsx("button", { type: "button", onClick: reload, children: "Retry" })] }));
50
- }
51
- if (html === null)
52
- return _jsx("p", { "aria-live": "polite", children: "Loading the Tool Stats panel\u2026" });
53
- // The markup is produced by `renderPanel`, which escapes every interpolated value.
54
- return _jsx("div", { dangerouslySetInnerHTML: { __html: html } });
55
- }
56
- /** The slots service is what the settings shell exposes. */
57
- export const inject = ['slots'];
11
+ import { NS, en, zh } from './locales.js';
12
+ import { ToolStatsPanel } from './view.js';
13
+ export const inject = ['slots', 'locale'];
58
14
  export function apply(ctx) {
15
+ // `zh` is the key-set source of truth, matching the official client plugins.
16
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-tool-stats: dictionaries');
59
17
  ctx.slots.inject('settings.section', () => ctx.slots.register({
60
18
  name: 'settings.section',
61
19
  id: 'tool-stats',
62
20
  order: 43,
63
- label: () => 'Tool Stats',
64
- }, ToolStatsPage));
21
+ label: () => ctx.locale.bind(NS)('nav'),
22
+ locale: NS,
23
+ }, ToolStatsPanel));
65
24
  }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Dictionaries for the Tool Stats page.
3
+ *
4
+ * `zh` is the key-set source of truth, as in the official client plugins, and `en` is
5
+ * typed against it: a key translated in one language but not the other fails the build
6
+ * instead of silently rendering the raw key.
7
+ *
8
+ * @module client/locales
9
+ */
10
+ /** Dictionary namespace owned by this plugin. */
11
+ export declare const NS = "toolStats";
12
+ /** Simplified Chinese dictionary (the key-set source of truth). */
13
+ export declare const zh: {
14
+ nav: string;
15
+ title: string;
16
+ tool: string;
17
+ calls: string;
18
+ failRate: string;
19
+ deadTools: string;
20
+ failingTools: string;
21
+ recommendations: string;
22
+ empty: string;
23
+ refresh: string;
24
+ loading: string;
25
+ failed: string;
26
+ retry: string;
27
+ };
28
+ /** English dictionary, checked complete against the zh key set. */
29
+ export declare const en: typeof zh;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Dictionaries for the Tool Stats page.
3
+ *
4
+ * `zh` is the key-set source of truth, as in the official client plugins, and `en` is
5
+ * typed against it: a key translated in one language but not the other fails the build
6
+ * instead of silently rendering the raw key.
7
+ *
8
+ * @module client/locales
9
+ */
10
+ /** Dictionary namespace owned by this plugin. */
11
+ export const NS = 'toolStats';
12
+ /** Simplified Chinese dictionary (the key-set source of truth). */
13
+ export const zh = {
14
+ 'nav': '工具统计',
15
+ 'title': '工具统计',
16
+ 'tool': '工具',
17
+ 'calls': '调用次数',
18
+ 'failRate': '失败率',
19
+ 'deadTools': '从未调用的工具',
20
+ 'failingTools': '高失败率工具',
21
+ 'recommendations': '建议',
22
+ 'empty': '还没有记录到工具调用。',
23
+ 'refresh': '刷新',
24
+ 'loading': '正在加载…',
25
+ 'failed': '加载失败',
26
+ 'retry': '重试',
27
+ };
28
+ /** English dictionary, checked complete against the zh key set. */
29
+ export const en = {
30
+ 'nav': 'Tool Stats',
31
+ 'title': 'Tool Stats',
32
+ 'tool': 'Tool',
33
+ 'calls': 'Calls',
34
+ 'failRate': 'Failure',
35
+ 'deadTools': 'Dead tools',
36
+ 'failingTools': 'Failing tools',
37
+ 'recommendations': 'Recommendations',
38
+ 'empty': 'No tool calls recorded yet.',
39
+ 'refresh': 'Refresh',
40
+ 'loading': 'Loading…',
41
+ 'failed': 'Failed to load',
42
+ 'retry': 'Retry',
43
+ };
@@ -1,2 +1,27 @@
1
+ /**
2
+ * Pure rendering half of the toolStats page.
3
+ *
4
+ * Separate from `index.tsx` so a static render can assert in Node what the page draws —
5
+ * the shipped bundle is a loader factory only a browser can run. Every user-visible
6
+ * string comes from the `t` seat the renderer binds from this plugin's namespace, so the
7
+ * page follows the UI language; no copy is hardcoded here.
8
+ *
9
+ * @module client/view
10
+ */
1
11
  import type { PanelPayload } from '../types.js';
2
- export declare function renderPanel(payload: PanelPayload): string;
12
+ /** The translate seat the renderer binds from this plugin's locale namespace. */
13
+ export type Translate = (key: string, params?: Record<string, unknown>) => string;
14
+ export interface PanelProps {
15
+ /** Bound translate function for this plugin's namespace. */
16
+ t: Translate;
17
+ }
18
+ interface PanelState {
19
+ payload: PanelPayload | null;
20
+ error: string | null;
21
+ }
22
+ /** Fetch the host panel payload; `reload` re-runs the request. */
23
+ export declare function usePanel(): PanelState & {
24
+ reload: () => void;
25
+ };
26
+ export declare function ToolStatsPanel({ t }: PanelProps): import("react").JSX.Element;
27
+ export {};
@@ -1,19 +1,58 @@
1
- export function renderPanel(payload) {
2
- const toolRows = payload.tools
3
- .map((t) => `<tr><td>${t.tool}</td><td>${t.invocations}</td><td>${Math.round(t.failureRate * 100)}%</td><td>${t.p50Latency}ms</td><td>${t.p95Latency}ms</td></tr>`)
4
- .join('');
5
- const deadSection = payload.deadTools.length > 0
6
- ? `<h3>Dead tools</h3><ul>${payload.deadTools.map((d) => `<li>${d.tool}</li>`).join('')}</ul>`
7
- : '';
8
- const failSection = payload.failingTools.length > 0
9
- ? `<h3>Failing tools</h3><ul>${payload.failingTools.map((f) => `<li>${f.tool}: ${Math.round(f.failureRate * 100)}%</li>`).join('')}</ul>`
10
- : '';
11
- const recSection = payload.recommendations.length > 0
12
- ? `<h3>Recommendations</h3><ul>${payload.recommendations.map((r) => `<li>${r.message}</li>`).join('')}</ul>`
13
- : '';
14
- return `<div class="stats-panel">
15
- <h2>Tool Stats</h2>
16
- ${toolRows ? `<table><thead><tr><th>Tool</th><th>Calls</th><th>Fail</th><th>p50</th><th>p95</th></tr></thead><tbody>${toolRows}</tbody></table>` : '<p>No calls recorded.</p>'}
17
- ${deadSection}${failSection}${recSection}
18
- </div>`;
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Pure rendering half of the toolStats page.
4
+ *
5
+ * Separate from `index.tsx` so a static render can assert in Node what the page draws —
6
+ * the shipped bundle is a loader factory only a browser can run. Every user-visible
7
+ * string comes from the `t` seat the renderer binds from this plugin's namespace, so the
8
+ * page follows the UI language; no copy is hardcoded here.
9
+ *
10
+ * @module client/view
11
+ */
12
+ import { useCallback, useEffect, useState } from 'react';
13
+ /** Panel route registered by the host half on the web connection. */
14
+ const PANEL_PATH = "/api/stats.panel";
15
+ const wrap = { display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 760, fontFamily: 'inherit' };
16
+ const head = { display: 'flex', alignItems: 'baseline', gap: 12, flexWrap: 'wrap' };
17
+ const muted = { fontSize: 12, opacity: 0.75 };
18
+ const table = { borderCollapse: 'collapse', width: '100%' };
19
+ const th = { textAlign: 'left', padding: '4px 10px 4px 0', fontWeight: 600, fontSize: 12, opacity: 0.8, borderBottom: '0.5px solid rgba(128,128,128,0.4)' };
20
+ const td = { padding: '6px 10px 6px 0', fontSize: 13, borderBottom: '0.5px solid rgba(128,128,128,0.18)' };
21
+ const list = { margin: 0, paddingLeft: 18, fontSize: 13 };
22
+ /** Fetch the host panel payload; `reload` re-runs the request. */
23
+ export function usePanel() {
24
+ const [state, setState] = useState({ payload: null, error: null });
25
+ const [tick, setTick] = useState(0);
26
+ const reload = useCallback(() => setTick((value) => value + 1), []);
27
+ useEffect(() => {
28
+ const controller = new AbortController();
29
+ setState((previous) => ({ ...previous, error: null }));
30
+ fetch(PANEL_PATH, { signal: controller.signal })
31
+ .then(async (response) => {
32
+ if (!response.ok)
33
+ throw new Error(String(response.status));
34
+ return response.json();
35
+ })
36
+ .then((payload) => {
37
+ if (!controller.signal.aborted)
38
+ setState({ payload, error: null });
39
+ })
40
+ .catch((cause) => {
41
+ if (controller.signal.aborted)
42
+ return;
43
+ setState({ payload: null, error: cause instanceof Error ? cause.message : String(cause) });
44
+ });
45
+ return () => controller.abort();
46
+ }, [tick]);
47
+ return { ...state, reload };
48
+ }
49
+ export function ToolStatsPanel({ t }) {
50
+ const { payload, error, reload } = usePanel();
51
+ const header = (_jsxs("header", { style: head, children: [_jsx("strong", { style: { fontSize: 13 }, children: t('title') }), _jsx("span", { style: { flex: 1 } }), _jsx("button", { type: "button", onClick: reload, style: { fontSize: 12 }, children: t('refresh') })] }));
52
+ if (error !== null) {
53
+ return (_jsxs("div", { style: wrap, children: [header, _jsxs("p", { role: "alert", style: { margin: 0, fontSize: 13 }, children: [t('failed'), ": ", error] }), _jsx("button", { type: "button", onClick: reload, style: { alignSelf: 'flex-start', fontSize: 12 }, children: t('retry') })] }));
54
+ }
55
+ if (payload === null)
56
+ return _jsx("p", { style: muted, "aria-live": "polite", children: t('loading') });
57
+ return (_jsxs("div", { style: wrap, children: [header, payload.tools.length === 0 ? (_jsx("p", { style: { margin: 0, fontSize: 13, opacity: 0.8 }, children: t('empty') })) : (_jsxs("table", { style: table, children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { style: th, children: t('tool') }), _jsx("th", { style: th, children: t('calls') }), _jsx("th", { style: th, children: t('failRate') }), _jsx("th", { style: th, children: "p50" }), _jsx("th", { style: th, children: "p95" })] }) }), _jsx("tbody", { children: payload.tools.map((row) => (_jsxs("tr", { children: [_jsx("td", { style: td, children: _jsx("code", { style: { fontSize: 11 }, children: row.tool }) }), _jsx("td", { style: td, children: row.invocations }), _jsxs("td", { style: td, children: [Math.round(row.failureRate * 100), "%"] }), _jsxs("td", { style: td, children: [row.p50Latency, "ms"] }), _jsxs("td", { style: td, children: [row.p95Latency, "ms"] })] }, row.tool))) })] })), payload.deadTools.length > 0 && (_jsxs(_Fragment, { children: [_jsx("strong", { style: { fontSize: 13 }, children: t('deadTools') }), _jsx("ul", { style: list, children: payload.deadTools.map((row) => _jsx("li", { children: _jsx("code", { style: { fontSize: 11 }, children: row.tool }) }, row.tool)) })] })), payload.failingTools.length > 0 && (_jsxs(_Fragment, { children: [_jsx("strong", { style: { fontSize: 13 }, children: t('failingTools') }), _jsx("ul", { style: list, children: payload.failingTools.map((row) => (_jsxs("li", { children: [_jsx("code", { style: { fontSize: 11 }, children: row.tool }), " \u00B7 ", Math.round(row.failureRate * 100), "%"] }, row.tool))) })] })), payload.recommendations.length > 0 && (_jsxs(_Fragment, { children: [_jsx("strong", { style: { fontSize: 13 }, children: t('recommendations') }), _jsx("ul", { style: list, children: payload.recommendations.map((row, index) => _jsx("li", { children: row.message }, index)) })] }))] }));
19
58
  }
package/lib/stats.web.js CHANGED
@@ -26,69 +26,150 @@ __export(index_exports, {
26
26
  inject: () => inject
27
27
  });
28
28
  module.exports = __toCommonJS(index_exports);
29
- var import_react = require("react");
30
29
 
31
- // src/client/view.tsx
32
- function renderPanel(payload) {
33
- const toolRows = payload.tools.map((t) => `<tr><td>${t.tool}</td><td>${t.invocations}</td><td>${Math.round(t.failureRate * 100)}%</td><td>${t.p50Latency}ms</td><td>${t.p95Latency}ms</td></tr>`).join("");
34
- const deadSection = payload.deadTools.length > 0 ? `<h3>Dead tools</h3><ul>${payload.deadTools.map((d) => `<li>${d.tool}</li>`).join("")}</ul>` : "";
35
- const failSection = payload.failingTools.length > 0 ? `<h3>Failing tools</h3><ul>${payload.failingTools.map((f) => `<li>${f.tool}: ${Math.round(f.failureRate * 100)}%</li>`).join("")}</ul>` : "";
36
- const recSection = payload.recommendations.length > 0 ? `<h3>Recommendations</h3><ul>${payload.recommendations.map((r) => `<li>${r.message}</li>`).join("")}</ul>` : "";
37
- return `<div class="stats-panel">
38
- <h2>Tool Stats</h2>
39
- ${toolRows ? `<table><thead><tr><th>Tool</th><th>Calls</th><th>Fail</th><th>p50</th><th>p95</th></tr></thead><tbody>${toolRows}</tbody></table>` : "<p>No calls recorded.</p>"}
40
- ${deadSection}${failSection}${recSection}
41
- </div>`;
42
- }
30
+ // src/client/locales.ts
31
+ var NS = "toolStats";
32
+ var zh = {
33
+ "nav": "\u5DE5\u5177\u7EDF\u8BA1",
34
+ "title": "\u5DE5\u5177\u7EDF\u8BA1",
35
+ "tool": "\u5DE5\u5177",
36
+ "calls": "\u8C03\u7528\u6B21\u6570",
37
+ "failRate": "\u5931\u8D25\u7387",
38
+ "deadTools": "\u4ECE\u672A\u8C03\u7528\u7684\u5DE5\u5177",
39
+ "failingTools": "\u9AD8\u5931\u8D25\u7387\u5DE5\u5177",
40
+ "recommendations": "\u5EFA\u8BAE",
41
+ "empty": "\u8FD8\u6CA1\u6709\u8BB0\u5F55\u5230\u5DE5\u5177\u8C03\u7528\u3002",
42
+ "refresh": "\u5237\u65B0",
43
+ "loading": "\u6B63\u5728\u52A0\u8F7D\u2026",
44
+ "failed": "\u52A0\u8F7D\u5931\u8D25",
45
+ "retry": "\u91CD\u8BD5"
46
+ };
47
+ var en = {
48
+ "nav": "Tool Stats",
49
+ "title": "Tool Stats",
50
+ "tool": "Tool",
51
+ "calls": "Calls",
52
+ "failRate": "Failure",
53
+ "deadTools": "Dead tools",
54
+ "failingTools": "Failing tools",
55
+ "recommendations": "Recommendations",
56
+ "empty": "No tool calls recorded yet.",
57
+ "refresh": "Refresh",
58
+ "loading": "Loading\u2026",
59
+ "failed": "Failed to load",
60
+ "retry": "Retry"
61
+ };
43
62
 
44
- // src/client/index.tsx
63
+ // src/client/view.tsx
64
+ var import_react = require("react");
45
65
  var import_jsx_runtime = require("react/jsx-runtime");
46
66
  var PANEL_PATH = "/api/stats.panel";
67
+ var wrap = { display: "flex", flexDirection: "column", gap: 12, maxWidth: 760, fontFamily: "inherit" };
68
+ var head = { display: "flex", alignItems: "baseline", gap: 12, flexWrap: "wrap" };
69
+ var muted = { fontSize: 12, opacity: 0.75 };
70
+ var table = { borderCollapse: "collapse", width: "100%" };
71
+ var th = { textAlign: "left", padding: "4px 10px 4px 0", fontWeight: 600, fontSize: 12, opacity: 0.8, borderBottom: "0.5px solid rgba(128,128,128,0.4)" };
72
+ var td = { padding: "6px 10px 6px 0", fontSize: 13, borderBottom: "0.5px solid rgba(128,128,128,0.18)" };
73
+ var list = { margin: 0, paddingLeft: 18, fontSize: 13 };
47
74
  function usePanel() {
48
- const [html, setHtml] = (0, import_react.useState)(null);
49
- const [error, setError] = (0, import_react.useState)(null);
75
+ const [state, setState] = (0, import_react.useState)({ payload: null, error: null });
50
76
  const [tick, setTick] = (0, import_react.useState)(0);
51
- const reload = (0, import_react.useCallback)(() => setTick((t) => t + 1), []);
77
+ const reload = (0, import_react.useCallback)(() => setTick((value) => value + 1), []);
52
78
  (0, import_react.useEffect)(() => {
53
79
  const controller = new AbortController();
54
- setError(null);
80
+ setState((previous) => ({ ...previous, error: null }));
55
81
  fetch(PANEL_PATH, { signal: controller.signal }).then(async (response) => {
56
- if (!response.ok) throw new Error(`panel request failed with ${response.status}`);
82
+ if (!response.ok) throw new Error(String(response.status));
57
83
  return response.json();
58
84
  }).then((payload) => {
59
- if (!controller.signal.aborted) setHtml(renderPanel(payload));
85
+ if (!controller.signal.aborted) setState({ payload, error: null });
60
86
  }).catch((cause) => {
61
87
  if (controller.signal.aborted) return;
62
- setError(cause instanceof Error ? cause.message : String(cause));
88
+ setState({ payload: null, error: cause instanceof Error ? cause.message : String(cause) });
63
89
  });
64
90
  return () => controller.abort();
65
91
  }, [tick]);
66
- return { html, error, reload };
92
+ return { ...state, reload };
67
93
  }
68
- function ToolStatsPage() {
69
- const { html, error, reload } = usePanel();
94
+ function ToolStatsPanel({ t }) {
95
+ const { payload, error, reload } = usePanel();
96
+ const header = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", { style: head, children: [
97
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { style: { fontSize: 13 }, children: t("title") }),
98
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { flex: 1 } }),
99
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: reload, style: { fontSize: 12 }, children: t("refresh") })
100
+ ] });
70
101
  if (error !== null) {
71
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [
72
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", children: [
73
- "Tool Stats panel failed to load: ",
102
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: wrap, children: [
103
+ header,
104
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", style: { margin: 0, fontSize: 13 }, children: [
105
+ t("failed"),
106
+ ": ",
74
107
  error
75
108
  ] }),
76
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: reload, children: "Retry" })
109
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: reload, style: { alignSelf: "flex-start", fontSize: 12 }, children: t("retry") })
77
110
  ] });
78
111
  }
79
- if (html === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { "aria-live": "polite", children: "Loading the Tool Stats panel\u2026" });
80
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { dangerouslySetInnerHTML: { __html: html } });
112
+ if (payload === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: muted, "aria-live": "polite", children: t("loading") });
113
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: wrap, children: [
114
+ header,
115
+ payload.tools.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { margin: 0, fontSize: 13, opacity: 0.8 }, children: t("empty") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { style: table, children: [
116
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: th, children: t("tool") }),
118
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: th, children: t("calls") }),
119
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: th, children: t("failRate") }),
120
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: th, children: "p50" }),
121
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: th, children: "p95" })
122
+ ] }) }),
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: payload.tools.map((row) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
124
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: td, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { style: { fontSize: 11 }, children: row.tool }) }),
125
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: td, children: row.invocations }),
126
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("td", { style: td, children: [
127
+ Math.round(row.failureRate * 100),
128
+ "%"
129
+ ] }),
130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("td", { style: td, children: [
131
+ row.p50Latency,
132
+ "ms"
133
+ ] }),
134
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("td", { style: td, children: [
135
+ row.p95Latency,
136
+ "ms"
137
+ ] })
138
+ ] }, row.tool)) })
139
+ ] }),
140
+ payload.deadTools.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
141
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { style: { fontSize: 13 }, children: t("deadTools") }),
142
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { style: list, children: payload.deadTools.map((row) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { style: { fontSize: 11 }, children: row.tool }) }, row.tool)) })
143
+ ] }),
144
+ payload.failingTools.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
145
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { style: { fontSize: 13 }, children: t("failingTools") }),
146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { style: list, children: payload.failingTools.map((row) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
147
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { style: { fontSize: 11 }, children: row.tool }),
148
+ " \xB7 ",
149
+ Math.round(row.failureRate * 100),
150
+ "%"
151
+ ] }, row.tool)) })
152
+ ] }),
153
+ payload.recommendations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
154
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { style: { fontSize: 13 }, children: t("recommendations") }),
155
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { style: list, children: payload.recommendations.map((row, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: row.message }, index)) })
156
+ ] })
157
+ ] });
81
158
  }
82
- var inject = ["slots"];
159
+
160
+ // src/client/index.tsx
161
+ var inject = ["slots", "locale"];
83
162
  function apply(ctx) {
163
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-tool-stats: dictionaries");
84
164
  ctx.slots.inject("settings.section", () => ctx.slots.register(
85
165
  {
86
166
  name: "settings.section",
87
167
  id: "tool-stats",
88
168
  order: 43,
89
- label: () => "Tool Stats"
169
+ label: () => ctx.locale.bind(NS)("nav"),
170
+ locale: NS
90
171
  },
91
- ToolStatsPage
172
+ ToolStatsPanel
92
173
  ));
93
174
  }
94
175
  return module.exports; } });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/client/index.tsx", "../src/client/view.tsx"],
4
- "sourcesContent": ["/**\n * Browser half of dsh-tool-stats: the Tool Stats page inside Settings.\n *\n * Services are named by their runtime identity, not by the package that provides them:\n * the settings shell is the `slots` service and the host bridge is `connection`. A\n * fiber that injects package names never resolves and the plugin stays pending, which\n * the loader reports as \"did not activate\".\n *\n * @module client\n */\n\nimport { useCallback, useEffect, useState } from 'react'\nimport type { ComponentType } from 'react'\nimport type { PanelPayload } from '../types.js'\nimport { renderPanel } from './view.js'\n\n/** Path the host half registers on the web connection. */\nconst PANEL_PATH = '/api/stats.panel'\n\ninterface SlotsService {\n inject(name: string, register: () => void): void\n register(options: { name: string; id: string; order: number; label: () => string }, component: ComponentType): unknown\n}\n\n/** Fetch the panel payload; `reload` re-runs the request. */\nfunction usePanel() {\n const [html, setHtml] = useState<string | null>(null)\n const [error, setError] = useState<string | null>(null)\n const [tick, setTick] = useState(0)\n const reload = useCallback(() => setTick((t) => t + 1), [])\n\n useEffect(() => {\n const controller = new AbortController()\n setError(null)\n fetch(PANEL_PATH, { signal: controller.signal })\n .then(async (response) => {\n if (!response.ok) throw new Error(`panel request failed with ${response.status}`)\n return response.json() as Promise<PanelPayload>\n })\n .then((payload) => {\n if (!controller.signal.aborted) setHtml(renderPanel(payload))\n })\n .catch((cause: unknown) => {\n if (controller.signal.aborted) return\n // Say what failed rather than rendering an empty panel, which would read as\n // \"nothing recorded\" \u2014 a different and wrong answer.\n setError(cause instanceof Error ? cause.message : String(cause))\n })\n return () => controller.abort()\n }, [tick])\n\n return { html, error, reload }\n}\n\nfunction ToolStatsPage() {\n const { html, error, reload } = usePanel()\n if (error !== null) {\n return (\n <section>\n <p role=\"alert\">Tool Stats panel failed to load: {error}</p>\n <button type=\"button\" onClick={reload}>Retry</button>\n </section>\n )\n }\n if (html === null) return <p aria-live=\"polite\">Loading the Tool Stats panel\u2026</p>\n // The markup is produced by `renderPanel`, which escapes every interpolated value.\n return <div dangerouslySetInnerHTML={{ __html: html }} />\n}\n\n/** The slots service is what the settings shell exposes. */\nexport const inject = ['slots']\n\nexport function apply(ctx: { slots: SlotsService }): void {\n ctx.slots.inject('settings.section', () => ctx.slots.register(\n {\n name: 'settings.section',\n id: 'tool-stats',\n order: 43,\n label: () => 'Tool Stats',\n },\n ToolStatsPage,\n ))\n}\n", "import type { PanelPayload } from '../types.js';\n\nexport function renderPanel(payload: PanelPayload): string {\n const toolRows = payload.tools\n .map((t) => `<tr><td>${t.tool}</td><td>${t.invocations}</td><td>${Math.round(t.failureRate * 100)}%</td><td>${t.p50Latency}ms</td><td>${t.p95Latency}ms</td></tr>`)\n .join('');\n\n const deadSection = payload.deadTools.length > 0\n ? `<h3>Dead tools</h3><ul>${payload.deadTools.map((d) => `<li>${d.tool}</li>`).join('')}</ul>`\n : '';\n\n const failSection = payload.failingTools.length > 0\n ? `<h3>Failing tools</h3><ul>${payload.failingTools.map((f) => `<li>${f.tool}: ${Math.round(f.failureRate * 100)}%</li>`).join('')}</ul>`\n : '';\n\n const recSection = payload.recommendations.length > 0\n ? `<h3>Recommendations</h3><ul>${payload.recommendations.map((r) => `<li>${r.message}</li>`).join('')}</ul>`\n : '';\n\n return `<div class=\"stats-panel\">\n <h2>Tool Stats</h2>\n ${toolRows ? `<table><thead><tr><th>Tool</th><th>Calls</th><th>Fail</th><th>p50</th><th>p95</th></tr></thead><tbody>${toolRows}</tbody></table>` : '<p>No calls recorded.</p>'}\n ${deadSection}${failSection}${recSection}\n </div>`;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,mBAAiD;;;ACT1C,SAAS,YAAY,SAA+B;AACzD,QAAM,WAAW,QAAQ,MACtB,IAAI,CAAC,MAAM,WAAW,EAAE,IAAI,YAAY,EAAE,WAAW,YAAY,KAAK,MAAM,EAAE,cAAc,GAAG,CAAC,aAAa,EAAE,UAAU,cAAc,EAAE,UAAU,cAAc,EACjK,KAAK,EAAE;AAEV,QAAM,cAAc,QAAQ,UAAU,SAAS,IAC3C,0BAA0B,QAAQ,UAAU,IAAI,CAAC,MAAM,OAAO,EAAE,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC,UACrF;AAEJ,QAAM,cAAc,QAAQ,aAAa,SAAS,IAC9C,6BAA6B,QAAQ,aAAa,IAAI,CAAC,MAAM,OAAO,EAAE,IAAI,KAAK,KAAK,MAAM,EAAE,cAAc,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,UAChI;AAEJ,QAAM,aAAa,QAAQ,gBAAgB,SAAS,IAChD,+BAA+B,QAAQ,gBAAgB,IAAI,CAAC,MAAM,OAAO,EAAE,OAAO,OAAO,EAAE,KAAK,EAAE,CAAC,UACnG;AAEJ,SAAO;AAAA;AAAA,MAEH,WAAW,yGAAyG,QAAQ,qBAAqB,2BAA2B;AAAA,MAC5K,WAAW,GAAG,WAAW,GAAG,UAAU;AAAA;AAE5C;;;ADmCQ;AA1CR,IAAM,aAAa;AAQnB,SAAS,WAAW;AAClB,QAAM,CAA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C,OAAO;AAEvB,SAAS,MAAM,KAAoC;AACxD,MAAI,MAAM,OAAO,oBAAoB,MAAM,IAAI,MAAM;AAAA,IACnD;AAAA,MACE,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,OAAO,MAAM;AAAA,IACf;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
3
+ "sources": ["../src/client/index.tsx", "../src/client/locales.ts", "../src/client/view.tsx"],
4
+ "sourcesContent": ["/**\n * Browser half of dsh-tool-stats: its page inside Settings.\n *\n * Two services are injected by their runtime identity, not by the packages that provide\n * them: the settings shell is `slots`, the dictionary registry is `locale`. The label and\n * every string inside the component are translated through this plugin's own namespace,\n * which is why the page follows the UI language instead of the plugin author's.\n *\n * @module client\n */\n\nimport type { ComponentType } from 'react'\n\nimport { NS, en, zh } from './locales.js'\nimport { ToolStatsPanel } from './view.js'\n\nexport const inject = ['slots', 'locale']\n\ninterface SlotsService {\n inject(name: string, register: () => void): void\n register(\n options: { name: string; id: string; order: number; label: () => string; locale: string },\n component: ComponentType<{ t: (key: string, params?: Record<string, unknown>) => string }>,\n ): unknown\n}\n\ninterface ClientContext {\n slots: SlotsService\n locale: {\n register(ns: string, dicts: { zh: unknown; en: unknown }): () => void\n bind(ns: string): (key: string, params?: Record<string, unknown>) => string\n }\n effect(callback: () => unknown, label?: string): unknown\n}\n\nexport function apply(ctx: ClientContext): void {\n // `zh` is the key-set source of truth, matching the official client plugins.\n ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-tool-stats: dictionaries')\n\n ctx.slots.inject('settings.section', () => ctx.slots.register(\n {\n name: 'settings.section',\n id: 'tool-stats',\n order: 43,\n label: () => ctx.locale.bind(NS)('nav'),\n locale: NS,\n },\n ToolStatsPanel,\n ))\n}\n", "/**\n * Dictionaries for the Tool Stats page.\n *\n * `zh` is the key-set source of truth, as in the official client plugins, and `en` is\n * typed against it: a key translated in one language but not the other fails the build\n * instead of silently rendering the raw key.\n *\n * @module client/locales\n */\n\n/** Dictionary namespace owned by this plugin. */\nexport const NS = 'toolStats'\n\n/** Simplified Chinese dictionary (the key-set source of truth). */\nexport const zh = {\n 'nav': '\u5DE5\u5177\u7EDF\u8BA1',\n 'title': '\u5DE5\u5177\u7EDF\u8BA1',\n 'tool': '\u5DE5\u5177',\n 'calls': '\u8C03\u7528\u6B21\u6570',\n 'failRate': '\u5931\u8D25\u7387',\n 'deadTools': '\u4ECE\u672A\u8C03\u7528\u7684\u5DE5\u5177',\n 'failingTools': '\u9AD8\u5931\u8D25\u7387\u5DE5\u5177',\n 'recommendations': '\u5EFA\u8BAE',\n 'empty': '\u8FD8\u6CA1\u6709\u8BB0\u5F55\u5230\u5DE5\u5177\u8C03\u7528\u3002',\n 'refresh': '\u5237\u65B0',\n 'loading': '\u6B63\u5728\u52A0\u8F7D\u2026',\n 'failed': '\u52A0\u8F7D\u5931\u8D25',\n 'retry': '\u91CD\u8BD5',\n}\n\n/** English dictionary, checked complete against the zh key set. */\nexport const en: typeof zh = {\n 'nav': 'Tool Stats',\n 'title': 'Tool Stats',\n 'tool': 'Tool',\n 'calls': 'Calls',\n 'failRate': 'Failure',\n 'deadTools': 'Dead tools',\n 'failingTools': 'Failing tools',\n 'recommendations': 'Recommendations',\n 'empty': 'No tool calls recorded yet.',\n 'refresh': 'Refresh',\n 'loading': 'Loading\u2026',\n 'failed': 'Failed to load',\n 'retry': 'Retry',\n}\n", "/**\n * Pure rendering half of the toolStats page.\n *\n * Separate from `index.tsx` so a static render can assert in Node what the page draws \u2014\n * the shipped bundle is a loader factory only a browser can run. Every user-visible\n * string comes from the `t` seat the renderer binds from this plugin's namespace, so the\n * page follows the UI language; no copy is hardcoded here.\n *\n * @module client/view\n */\n\nimport { useCallback, useEffect, useState } from 'react'\nimport type { CSSProperties } from 'react'\n\nimport type { PanelPayload } from '../types.js'\n\n/** The translate seat the renderer binds from this plugin's locale namespace. */\nexport type Translate = (key: string, params?: Record<string, unknown>) => string\n\nexport interface PanelProps {\n /** Bound translate function for this plugin's namespace. */\n t: Translate\n}\n\n/** Panel route registered by the host half on the web connection. */\nconst PANEL_PATH = \"/api/stats.panel\"\n\nconst wrap: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 760, fontFamily: 'inherit' }\nconst head: CSSProperties = { display: 'flex', alignItems: 'baseline', gap: 12, flexWrap: 'wrap' }\nconst muted: CSSProperties = { fontSize: 12, opacity: 0.75 }\nconst table: CSSProperties = { borderCollapse: 'collapse', width: '100%' }\nconst th: CSSProperties = { textAlign: 'left', padding: '4px 10px 4px 0', fontWeight: 600, fontSize: 12, opacity: 0.8, borderBottom: '0.5px solid rgba(128,128,128,0.4)' }\nconst td: CSSProperties = { padding: '6px 10px 6px 0', fontSize: 13, borderBottom: '0.5px solid rgba(128,128,128,0.18)' }\nconst list: CSSProperties = { margin: 0, paddingLeft: 18, fontSize: 13 }\n\ninterface PanelState {\n payload: PanelPayload | null\n error: string | null\n}\n\n/** Fetch the host panel payload; `reload` re-runs the request. */\nexport function usePanel(): PanelState & { reload: () => void } {\n const [state, setState] = useState<PanelState>({ payload: null, error: null })\n const [tick, setTick] = useState(0)\n const reload = useCallback(() => setTick((value) => value + 1), [])\n\n useEffect(() => {\n const controller = new AbortController()\n setState((previous) => ({ ...previous, error: null }))\n fetch(PANEL_PATH, { signal: controller.signal })\n .then(async (response) => {\n if (!response.ok) throw new Error(String(response.status))\n return response.json() as Promise<PanelPayload>\n })\n .then((payload) => {\n if (!controller.signal.aborted) setState({ payload, error: null })\n })\n .catch((cause: unknown) => {\n if (controller.signal.aborted) return\n setState({ payload: null, error: cause instanceof Error ? cause.message : String(cause) })\n })\n return () => controller.abort()\n }, [tick])\n\n return { ...state, reload }\n}\n\nexport function ToolStatsPanel({ t }: PanelProps) {\n const { payload, error, reload } = usePanel()\n const header = (\n <header style={head}>\n <strong style={{ fontSize: 13 }}>{t('title')}</strong>\n <span style={{ flex: 1 }} />\n <button type=\"button\" onClick={reload} style={{ fontSize: 12 }}>{t('refresh')}</button>\n </header>\n )\n if (error !== null) {\n return (\n <div style={wrap}>\n {header}\n <p role=\"alert\" style={{ margin: 0, fontSize: 13 }}>{t('failed')}: {error}</p>\n <button type=\"button\" onClick={reload} style={{ alignSelf: 'flex-start', fontSize: 12 }}>{t('retry')}</button>\n </div>\n )\n }\n if (payload === null) return <p style={muted} aria-live=\"polite\">{t('loading')}</p>\n return (\n <div style={wrap}>\n {header}\n {payload.tools.length === 0 ? (\n <p style={{ margin: 0, fontSize: 13, opacity: 0.8 }}>{t('empty')}</p>\n ) : (\n <table style={table}>\n <thead>\n <tr>\n <th style={th}>{t('tool')}</th><th style={th}>{t('calls')}</th>\n <th style={th}>{t('failRate')}</th><th style={th}>p50</th><th style={th}>p95</th>\n </tr>\n </thead>\n <tbody>\n {payload.tools.map((row) => (\n <tr key={row.tool}>\n <td style={td}><code style={{ fontSize: 11 }}>{row.tool}</code></td>\n <td style={td}>{row.invocations}</td>\n <td style={td}>{Math.round(row.failureRate * 100)}%</td>\n <td style={td}>{row.p50Latency}ms</td>\n <td style={td}>{row.p95Latency}ms</td>\n </tr>\n ))}\n </tbody>\n </table>\n )}\n {payload.deadTools.length > 0 && (\n <>\n <strong style={{ fontSize: 13 }}>{t('deadTools')}</strong>\n <ul style={list}>\n {payload.deadTools.map((row) => <li key={row.tool}><code style={{ fontSize: 11 }}>{row.tool}</code></li>)}\n </ul>\n </>\n )}\n {payload.failingTools.length > 0 && (\n <>\n <strong style={{ fontSize: 13 }}>{t('failingTools')}</strong>\n <ul style={list}>\n {payload.failingTools.map((row) => (\n <li key={row.tool}><code style={{ fontSize: 11 }}>{row.tool}</code> \u00B7 {Math.round(row.failureRate * 100)}%</li>\n ))}\n </ul>\n </>\n )}\n {payload.recommendations.length > 0 && (\n <>\n <strong style={{ fontSize: 13 }}>{t('recommendations')}</strong>\n <ul style={list}>\n {payload.recommendations.map((row, index) => <li key={index}>{row.message}</li>)}\n </ul>\n </>\n )}\n </div>\n )\n}\n"],
5
+ "mapp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AAEpF,MAAI,MAAM,OAAO,oBAAoB,MAAM,IAAI,MAAM;AAAA,IACnD;AAAA,MACE,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,OAAO,MAAM,IAAI,OAAO,KAAK,EAAE,EAAE,KAAK;AAAA,MACtC,QAAQ;AAAA,IACV;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,32 +1,67 @@
1
1
  {
2
2
  "name": "dsh-tool-stats",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "Every tool call is counted, and the ones that never fire are named so you can remove them.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
8
- "bin": { "dsh-tool-stats": "lib/bin.js" },
8
+ "bin": {
9
+ "dsh-tool-stats": "lib/bin.js"
10
+ },
9
11
  "exports": {
10
- ".": { "types": "./lib/index.d.ts", "default": "./lib/index.js" },
11
- "./client": { "types": "./lib/client/index.d.ts", "default": "./lib/stats.web.js" },
12
+ ".": {
13
+ "types": "./lib/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./client": {
17
+ "types": "./lib/client/index.d.ts",
18
+ "default": "./lib/stats.web.js"
19
+ },
12
20
  "./package.json": "./package.json"
13
21
  },
14
- "files": ["lib", "cordis.patch.yml", "README.md", "CHANGELOG.md"],
15
- "keywords": ["dsh", "dsh-plugin", "deepseek-harness", "tools", "analytics", "usage"],
22
+ "files": [
23
+ "lib",
24
+ "cordis.patch.yml",
25
+ "README.md",
26
+ "CHANGELOG.md"
27
+ ],
28
+ "keywords": [
29
+ "dsh",
30
+ "dsh-plugin",
31
+ "deepseek-harness",
32
+ "tools",
33
+ "analytics",
34
+ "usage"
35
+ ],
16
36
  "dsh": {
17
- "bundle": { "patch": "./cordis.patch.yml" },
37
+ "bundle": {
38
+ "patch": "./cordis.patch.yml"
39
+ },
18
40
  "client": {
19
41
  "platform": "web",
20
- "inject": ["slots", "connection"]
42
+ "inject": [
43
+ "@deepseek-ai/dsh-client-ui-renderer",
44
+ "@deepseek-ai/dsh-client-locale",
45
+ "@deepseek-ai/dsh-client-ui-settings"
46
+ ]
21
47
  }
22
48
  },
23
49
  "license": "MIT",
24
50
  "author": "hj01857655",
25
- "repository": { "type": "git", "url": "git+https://github.com/hj01857655/dsh-tool-stats.git" },
26
- "bugs": { "url": "https://github.com/hj01857655/dsh-tool-stats/issues" },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/hj01857655/dsh-tool-stats.git"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/hj01857655/dsh-tool-stats/issues"
57
+ },
27
58
  "homepage": "https://github.com/hj01857655/dsh-tool-stats#readme",
28
- "engines": { "node": ">=20" },
29
- "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1" },
59
+ "engines": {
60
+ "node": ">=20"
61
+ },
62
+ "peerDependencies": {
63
+ "@deepseek-ai/cordis": "^4.0.1"
64
+ },
30
65
  "devDependencies": {
31
66
  "@deepseek-ai/cordis": "^4.0.2",
32
67
  "@types/node": "^22.20.3",