@aiti-ai/aiti-ai-usage 0.1.9 → 0.1.10
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/README.md +14 -22
- package/README.zh-CN.md +31 -0
- package/client/src/entry.tsx +2 -2
- package/client/src/report.tsx +180 -3
- package/dev-pack.mjs +16 -3
- package/dist/aiti-ai-usage.mjs +474 -37
- package/index.ts +64 -4
- package/lib/catalog.ts +199 -0
- package/lib/db.ts +27 -0
- package/lib/ingest.ts +118 -3
- package/package.json +3 -3
- package/server/api.ts +24 -0
- package/skills/usage-report/SKILL.md +2 -0
- package/tool-usage.test.mjs +192 -0
- package/tools/build-client.mjs +2 -1
- package/tools/deploy.mjs +1 -1
package/README.md
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
# @aiti-ai/aiti-ai-usage
|
|
2
2
|
|
|
3
|
-
> AI token
|
|
3
|
+
> AI token usage statistics — multi-dimensional reports by workspace/provider/model/key/time-slot, pivot over any dimension combination + sankey diagram + CSV export, event-driven with zero polling, standalone SQLite storage
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
English · [简体中文](./README.zh-CN.md)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## About aiti
|
|
8
8
|
|
|
9
9
|
This package is part of the **aiti** ecosystem — a personal AI development workbench powered by [pi](https://pi.dev): **aiti-agent** (a self-hosted web workbench built on the open-source [pi-web](https://github.com/aiti-ai/pi-web)) plus debug injection into mainstream dev tools (aiti-devtools) and a rich extension system.
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
11
|
+
- Workbench (aiti-agent, built on pi-web): <https://github.com/aiti-ai/pi-web>
|
|
12
|
+
- Ecosystem monorepo: <https://github.com/aiti-ai/aiti-ai>
|
|
13
|
+
- Site: <https://aiti.pw>
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Category: System tools · Tags: `usage` · `token` · `statistics` · `sqlite` · `dashboard`
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## Install
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Bundled with **aiti-agent** (`@aiti-ai/pi-web`) — enable it from the in-app extension manager (ExtMan / App Center).
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Manual install: place this package at `~/.pi/web/extensions/aiti-ai-usage/` and reload pi-web.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
## Documentation
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
# 部署到 ~/.pi/web/extensions/aiti-ai-usage/ 后 reload
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## 文档 · Documentation
|
|
32
|
-
|
|
33
|
-
- 中文完整文档(aiti-docs): <https://aiti.pw/extensions/aiti-ai-usage.html>
|
|
34
|
-
- English docs: <https://aiti.pw/en/extensions/aiti-ai-usage.html>
|
|
35
|
-
- 扩展注册表 / registry: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
|
|
25
|
+
- Documentation (English): <https://aiti.pw/en/extensions/aiti-ai-usage.html>
|
|
26
|
+
- 文档(中文): <https://aiti.pw/extensions/aiti-ai-usage.html>
|
|
27
|
+
- Extension registry: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
|
|
36
28
|
|
|
37
29
|
## License
|
|
38
30
|
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @aiti-ai/aiti-ai-usage
|
|
2
|
+
|
|
3
|
+
> AI token 用量统计 —— workspace/provider/model/key/时段多维报表,任意多维组合透视 + 桑基图 + CSV 导出,事件驱动零轮询,独立 SQLite 存储
|
|
4
|
+
|
|
5
|
+
[English](./README.md) · 简体中文
|
|
6
|
+
|
|
7
|
+
## 关于 aiti
|
|
8
|
+
|
|
9
|
+
本包是 **aiti** 生态的组成部分——以 [pi](https://pi.dev) 为引擎的个人 AI 开发工作台与本地调试注入生态:**aiti-agent**(自托管 Web 工作台,基于开源项目 [pi-web](https://github.com/aiti-ai/pi-web) 构建,浏览器为主操作面)+ 各开发工具内的调试注入(aiti-devtools)+ 丰富的扩展体系。
|
|
10
|
+
|
|
11
|
+
- 工作台(aiti-agent,基于 pi-web): <https://github.com/aiti-ai/pi-web>
|
|
12
|
+
- 生态仓库: <https://github.com/aiti-ai/aiti-ai>
|
|
13
|
+
- 官网: <https://aiti.pw>
|
|
14
|
+
|
|
15
|
+
分类: 系统工具 · tags: `usage` · `token` · `statistics` · `sqlite` · `dashboard`
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
随 **aiti-agent**(`@aiti-ai/pi-web`)捆绑发行——在工作台内的扩展管理器(ExtMan / 应用中心)启用即可。
|
|
20
|
+
|
|
21
|
+
手动安装:把本包放到 `~/.pi/web/extensions/aiti-ai-usage/` 后 reload。
|
|
22
|
+
|
|
23
|
+
## 文档
|
|
24
|
+
|
|
25
|
+
- 中文文档: <https://aiti.pw/extensions/aiti-ai-usage.html>
|
|
26
|
+
- Documentation (English): <https://aiti.pw/en/extensions/aiti-ai-usage.html>
|
|
27
|
+
- 扩展注册表: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
|
|
28
|
+
|
|
29
|
+
## 许可证
|
|
30
|
+
|
|
31
|
+
MIT
|
package/client/src/entry.tsx
CHANGED
|
@@ -18,9 +18,9 @@ export default function register(ctx: Record<string, unknown>) {
|
|
|
18
18
|
seedDockDefault(REPORT_KEY, "right-panel");
|
|
19
19
|
// meta.onClick:懒加载下 toolbar 静态条目点击后由宿主转发——panel.open() 驱动 float 状态机
|
|
20
20
|
// (模块级),物化前后调用都生效。
|
|
21
|
-
ctx.registerItems?.("toolbar", [{ id: "usage", render: ToolbarEntry, meta: { label: "
|
|
21
|
+
ctx.registerItems?.("toolbar", [{ id: "usage", render: ToolbarEntry, meta: { label: "i18n:au.app.label", icon: "icons/chart-column.svg", onClick: () => panel.open() } }]);
|
|
22
22
|
ctx.registerItems?.("sessionStats", [{ id: "report-entry", render: SessionStatsEntry }]);
|
|
23
23
|
ctx.registerItems?.("dialogs", [{ id: "report", render: UsageReport }]);
|
|
24
24
|
// 右栏停靠 face:注册 raw itemId(宿主拼 extId:itemId = REPORT_KEY)
|
|
25
|
-
ctx.registerItems?.("rightFileDock", [{ id: "report", render: ReportDockFace, meta: { title: "
|
|
25
|
+
ctx.registerItems?.("rightFileDock", [{ id: "report", render: ReportDockFace, meta: { title: "i18n:it.report.title" } }]);
|
|
26
26
|
}
|
package/client/src/report.tsx
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { useState, useEffect, useMemo, useRef } from "react";
|
|
6
6
|
import { t, apiUrl, extSvc } from "./host-shim";
|
|
7
|
+
|
|
8
|
+
/** Glob → RegExp for excludeTools display matching (client-local copy; catalog.ts carries node:fs). */
|
|
9
|
+
function globToRegExp(pattern: string): RegExp {
|
|
10
|
+
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[\\s\\S]*");
|
|
11
|
+
return new RegExp("^" + escaped + "$", "i");
|
|
12
|
+
}
|
|
7
13
|
import { fmtUsdCny, fxNote, isCnyBillingProvider, useMoneyTick } from "./money";
|
|
8
14
|
// aiti-float dock v3(position-picker-plan §3.2 P1):面板接停靠状态机——浮窗 face 走
|
|
9
15
|
// useGate 门控;打开/关闭收口 openFloat/closePanel;右栏停靠 face 用 DockBody 包同一内容。
|
|
@@ -1922,6 +1928,176 @@ const Empty = () => <div style={{ padding: 20, textAlign: "center", color: "var(
|
|
|
1922
1928
|
const Err = ({ msg }: { msg: string }) => <div style={{ padding: 24, color: "var(--danger, #f87171)", fontSize: 12 }}>{msg}</div>;
|
|
1923
1929
|
const PickHint = () => <div style={{ padding: 24, textAlign: "center", color: "var(--text-dim)", fontSize: 12 }}>{t("au.range.pick")}</div>;
|
|
1924
1930
|
|
|
1931
|
+
// ---------------------------------------------------------------- Catalog billing (borrow plan §2.7B/C)
|
|
1932
|
+
|
|
1933
|
+
/** Catalog billing: MCP catalog (mcp-cache × mcp.json enabled) × 30-day calls + skills surface.
|
|
1934
|
+
* Governance = manual toggles (MCP server → POST /api/mcp enable/disable; skill → PATCH /api/skills);
|
|
1935
|
+
* they only affect model visibility (manual slash/mention paths stay). New installs get a ~7-day
|
|
1936
|
+
* trial — display-only hints, never auto-disable. */
|
|
1937
|
+
function CatalogTab() {
|
|
1938
|
+
// cwd → server forwards to same-origin /api/skills (cwd required there; project skills included)
|
|
1939
|
+
const cwd = (() => {
|
|
1940
|
+
try {
|
|
1941
|
+
const ui = extSvc?.("pi-web.ui") as { get?: (k: string) => unknown } | undefined;
|
|
1942
|
+
const v = ui?.get?.("selectedCwd");
|
|
1943
|
+
return typeof v === "string" && v ? v : "";
|
|
1944
|
+
} catch { return ""; }
|
|
1945
|
+
})();
|
|
1946
|
+
const { data, err, reload } = useFetch<any>("/catalog" + (cwd ? "?cwd=" + encodeURIComponent(cwd) : ""), []);
|
|
1947
|
+
const [busyKey, setBusyKey] = useState<string | null>(null);
|
|
1948
|
+
const [openSrv, setOpenSrv] = useState<string | null>(null);
|
|
1949
|
+
const cat = data && data.ok !== false ? data : null;
|
|
1950
|
+
const act = async (key: string, fn: () => Promise<unknown>) => {
|
|
1951
|
+
setBusyKey(key);
|
|
1952
|
+
try { await fn(); reload(); } catch { /* toggle failure stays silent; next reload reflects reality */ }
|
|
1953
|
+
finally { setBusyKey(null); }
|
|
1954
|
+
};
|
|
1955
|
+
const toggleServer = (name: string, enabled: boolean) =>
|
|
1956
|
+
act("srv:" + name, () => fetch(apiUrl("/api/mcp"), {
|
|
1957
|
+
method: "POST", headers: { "content-type": "application/json" },
|
|
1958
|
+
body: JSON.stringify({ action: enabled ? "enable" : "disable", scope: "global", name }),
|
|
1959
|
+
}));
|
|
1960
|
+
// per-tool exclusion (borrow plan §2.7C-②): writes mcp.json excludeTools via the host /api/mcp;
|
|
1961
|
+
// effective when the adapter registers tools next session. restore strips exact + matching globs.
|
|
1962
|
+
const setExcluded = (server: any, nextPatterns: string[]) =>
|
|
1963
|
+
act("srv:" + server.name, () => fetch(apiUrl("/api/mcp"), {
|
|
1964
|
+
method: "POST", headers: { "content-type": "application/json" },
|
|
1965
|
+
body: JSON.stringify({ action: "set-excluded-tools", scope: "global", name: server.name, excludeTools: nextPatterns }),
|
|
1966
|
+
}));
|
|
1967
|
+
const excludeTool = (server: any, toolName: string) => {
|
|
1968
|
+
const cur: string[] = server.excludedPatterns || [];
|
|
1969
|
+
if (cur.some((p) => p.toLowerCase() === toolName.toLowerCase())) return;
|
|
1970
|
+
void setExcluded(server, [...cur, toolName]);
|
|
1971
|
+
};
|
|
1972
|
+
const restoreTool = (server: any, toolName: string) => {
|
|
1973
|
+
const cur: string[] = server.excludedPatterns || [];
|
|
1974
|
+
void setExcluded(server, cur.filter((p) => {
|
|
1975
|
+
try { return !globToRegExp(p).test(toolName); } catch { return true; }
|
|
1976
|
+
}));
|
|
1977
|
+
};
|
|
1978
|
+
const toggleSkill = (filePath: string, disabled: boolean) =>
|
|
1979
|
+
act("sk:" + filePath, () => fetch(apiUrl("/api/skills"), {
|
|
1980
|
+
method: "PATCH", headers: { "content-type": "application/json" },
|
|
1981
|
+
body: JSON.stringify({ filePath, disableModelInvocation: disabled }),
|
|
1982
|
+
}));
|
|
1983
|
+
if (err) return <div style={{ padding: 16, color: "var(--danger, #ef4444)", fontSize: 12 }}>{err}</div>;
|
|
1984
|
+
if (!cat) return <div style={{ padding: 16, color: "var(--text-muted)", fontSize: 12 }}>{t("ui.loading")}</div>;
|
|
1985
|
+
const thStyle: React.CSSProperties = { textAlign: "left", padding: "4px 8px", borderBottom: "1px solid var(--border)", color: "var(--text-dim)", fontSize: 10.5, fontWeight: 600 };
|
|
1986
|
+
const tdStyle: React.CSSProperties = { padding: "4px 8px", borderBottom: "1px solid var(--border)", fontSize: 11.5, verticalAlign: "top" };
|
|
1987
|
+
return (
|
|
1988
|
+
<div style={{ flex: 1, minHeight: 0, overflowY: "auto", padding: "10px 12px" }}>
|
|
1989
|
+
<div style={{ fontSize: 11, color: "var(--text-muted)", marginBottom: 8, lineHeight: 1.5 }}>{t("au.catalog.intro", { n: cat.mcpTotalTools, tok: cat.mcpTotalTokens })}</div>
|
|
1990
|
+
{(cat.notes || []).map((note: string, i: number) => (
|
|
1991
|
+
<div key={i} style={{ fontSize: 10.5, color: "var(--text-dim)", marginBottom: 4 }}>· {note}</div>
|
|
1992
|
+
))}
|
|
1993
|
+
{/* MCP servers */}
|
|
1994
|
+
<div style={{ fontSize: 10, fontWeight: 600, letterSpacing: "0.06em", textTransform: "uppercase", color: "var(--text-dim)", margin: "8px 0 4px" }}>{t("au.catalog.mcp")}</div>
|
|
1995
|
+
<table style={{ width: "100%", borderCollapse: "collapse" }}>
|
|
1996
|
+
<thead><tr>
|
|
1997
|
+
{[t("au.catalog.server"), t("au.catalog.state"), t("au.catalog.tools"), t("au.catalog.estTok"), t("au.catalog.used30d"), ""].map((h, i) => <th key={i} style={thStyle}>{h}</th>)}
|
|
1998
|
+
</tr></thead>
|
|
1999
|
+
<tbody>
|
|
2000
|
+
{(cat.mcp || []).map((s: any) => (
|
|
2001
|
+
<CatalogMcpRow key={s.name} s={s} open={openSrv === s.name} onOpen={() => setOpenSrv(openSrv === s.name ? null : s.name)}
|
|
2002
|
+
busy={busyKey === "srv:" + s.name} onToggle={() => toggleServer(s.name, !s.enabled)} tdStyle={tdStyle}
|
|
2003
|
+
onExcludeTool={(tool: string) => excludeTool(s, tool)} onRestoreTool={(tool: string) => restoreTool(s, tool)}
|
|
2004
|
+
onDropPattern={(p: string) => setExcluded(s, (s.excludedPatterns || []).filter((x: string) => x !== p))}
|
|
2005
|
+
busyKey={busyKey} />
|
|
2006
|
+
))}
|
|
2007
|
+
{(cat.mcp || []).length === 0 && <tr><td style={tdStyle} colSpan={6}>{t("au.catalog.noMcp")}</td></tr>}
|
|
2008
|
+
</tbody>
|
|
2009
|
+
</table>
|
|
2010
|
+
{/* skills */}
|
|
2011
|
+
<div style={{ fontSize: 10, fontWeight: 600, letterSpacing: "0.06em", textTransform: "uppercase", color: "var(--text-dim)", margin: "14px 0 4px" }}>{t("au.catalog.skills")}</div>
|
|
2012
|
+
<table style={{ width: "100%", borderCollapse: "collapse" }}>
|
|
2013
|
+
<thead><tr>
|
|
2014
|
+
{[t("au.catalog.skillName"), t("au.catalog.state"), t("au.catalog.used30d"), ""].map((h, i) => <th key={i} style={thStyle}>{h}</th>)}
|
|
2015
|
+
</tr></thead>
|
|
2016
|
+
<tbody>
|
|
2017
|
+
{(cat.skills || []).map((sk: any) => (
|
|
2018
|
+
<tr key={sk.filePath || sk.name}>
|
|
2019
|
+
<td style={tdStyle}>
|
|
2020
|
+
<span style={{ fontFamily: "var(--font-mono)" }}>{sk.name}</span>
|
|
2021
|
+
{sk.filePath ? <span title={sk.filePath} style={{ fontSize: 10, color: "var(--text-dim)", marginLeft: 6 }}>{sk.filePath.split("/").slice(-2).join("/")}</span> : null}
|
|
2022
|
+
</td>
|
|
2023
|
+
<td style={tdStyle}>
|
|
2024
|
+
<button disabled={busyKey === "sk:" + sk.filePath} onClick={() => toggleSkill(sk.filePath, !sk.disabled)}
|
|
2025
|
+
style={{ ...ghostBtn, padding: "1px 8px", fontSize: 10.5 }}>
|
|
2026
|
+
{sk.disabled ? t("au.catalog.enable") : t("au.catalog.disable")}
|
|
2027
|
+
</button>
|
|
2028
|
+
</td>
|
|
2029
|
+
<td style={{ ...tdStyle, color: sk.calls30d === 0 ? "var(--text-dim)" : undefined }}>{sk.calls30d}</td>
|
|
2030
|
+
<td style={tdStyle}>{sk.disabled ? <span style={{ fontSize: 10, color: "var(--text-dim)" }}>{t("au.catalog.disabledNote")}</span> : null}</td>
|
|
2031
|
+
</tr>
|
|
2032
|
+
))}
|
|
2033
|
+
{(cat.skills || []).length === 0 && <tr><td style={tdStyle} colSpan={4}>{t("au.catalog.noSkills")}</td></tr>}
|
|
2034
|
+
</tbody>
|
|
2035
|
+
</table>
|
|
2036
|
+
<div style={{ fontSize: 10, color: "var(--text-dim)", marginTop: 10, lineHeight: 1.5 }}>{t("au.catalog.rules")}</div>
|
|
2037
|
+
</div>
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
/** MCP server row (summary + expandable per-tool detail: schema tokens × 30-day calls × exclude toggle; glob pattern chips) */
|
|
2042
|
+
function CatalogMcpRow({ s, open, onOpen, busy, onToggle, tdStyle, onExcludeTool, onRestoreTool, onDropPattern, busyKey }: {
|
|
2043
|
+
s: any; open: boolean; onOpen: () => void; busy: boolean; onToggle: () => void; tdStyle: React.CSSProperties;
|
|
2044
|
+
onExcludeTool: (tool: string) => void; onRestoreTool: (tool: string) => void;
|
|
2045
|
+
onDropPattern: (pattern: string) => void; busyKey: string | null;
|
|
2046
|
+
}) {
|
|
2047
|
+
const globPatterns: string[] = (s.excludedPatterns || []).filter((p: string) => p.includes("*"));
|
|
2048
|
+
const chipStyle: React.CSSProperties = { fontSize: 9.5, padding: "1px 6px", borderRadius: 4, border: "1px solid var(--border)", color: "var(--text-muted)", background: "none", cursor: "pointer" };
|
|
2049
|
+
return (
|
|
2050
|
+
<>
|
|
2051
|
+
<tr>
|
|
2052
|
+
<td style={tdStyle}>
|
|
2053
|
+
<span role="button" tabIndex={0} onClick={onOpen} style={{ cursor: "pointer", fontFamily: "var(--font-mono)", color: "var(--text)" }}>
|
|
2054
|
+
{open ? "▾ " : "▸ "}{s.name}
|
|
2055
|
+
</span>
|
|
2056
|
+
</td>
|
|
2057
|
+
<td style={tdStyle}>
|
|
2058
|
+
<button disabled={busy} onClick={onToggle} style={{ ...ghostBtn, padding: "1px 8px", fontSize: 10.5 }}>
|
|
2059
|
+
{busy ? "…" : s.enabled ? t("au.catalog.disable") : t("au.catalog.enable")}
|
|
2060
|
+
</button>
|
|
2061
|
+
</td>
|
|
2062
|
+
<td style={{ ...tdStyle, color: s.toolCount === 0 ? "var(--text-dim)" : undefined }}>{s.toolCount}</td>
|
|
2063
|
+
<td style={tdStyle}>{s.estTokens ? `~${s.estTokens}` : "—"}</td>
|
|
2064
|
+
<td style={{ ...tdStyle, color: s.calls30d === 0 ? "var(--danger, #ef4444)" : undefined }}>{s.calls30d}</td>
|
|
2065
|
+
<td style={tdStyle}>{s.enabled ? "" : <span style={{ fontSize: 10, color: "var(--text-dim)" }}>{t("au.catalog.disabledNote")}</span>}</td>
|
|
2066
|
+
</tr>
|
|
2067
|
+
{open && globPatterns.length > 0 ? (
|
|
2068
|
+
<tr style={{ background: "var(--bg-hover)" }}>
|
|
2069
|
+
<td style={{ ...tdStyle, paddingLeft: 26, fontSize: 10, color: "var(--text-dim)" }} colSpan={6}>
|
|
2070
|
+
{t("au.catalog.patterns")}:{globPatterns.map((p: string) => (
|
|
2071
|
+
<button key={p} type="button" title={t("au.catalog.dropPattern")} style={{ ...chipStyle, marginRight: 4 }}
|
|
2072
|
+
onClick={() => onDropPattern(p)}>{p} ✕</button>
|
|
2073
|
+
))}
|
|
2074
|
+
</td>
|
|
2075
|
+
</tr>
|
|
2076
|
+
) : null}
|
|
2077
|
+
{open && (s.tools || []).map((tool: any) => (
|
|
2078
|
+
<tr key={tool.name} style={{ background: tool.excluded ? "color-mix(in srgb, var(--danger, #ef4444) 6%, transparent)" : "var(--bg-hover)" }}>
|
|
2079
|
+
<td style={{ ...tdStyle, paddingLeft: 26, fontFamily: "var(--font-mono)", fontSize: 10.5, color: tool.excluded ? "var(--text-dim)" : undefined }}>
|
|
2080
|
+
{tool.name}
|
|
2081
|
+
{tool.excluded ? <span style={{ fontSize: 9, color: "var(--text-dim)", marginLeft: 6, border: "1px solid var(--border)", borderRadius: 4, padding: "0 4px" }}>{t("au.catalog.excludedBadge")}</span> : null}
|
|
2082
|
+
{tool.phantom ? <span title={t("au.catalog.phantomNote")} style={{ fontSize: 9, color: "var(--text-dim)", marginLeft: 4 }}>?</span> : null}
|
|
2083
|
+
</td>
|
|
2084
|
+
<td style={{ ...tdStyle, fontSize: 10, color: "var(--text-dim)" }} colSpan={3}>
|
|
2085
|
+
{t("au.catalog.toolMeta", { tok: tool.estTokens, n: tool.calls30d })}
|
|
2086
|
+
</td>
|
|
2087
|
+
<td style={tdStyle}>
|
|
2088
|
+
<button type="button" disabled={busyKey === "srv:" + s.name} onClick={() => (tool.excluded ? onRestoreTool(tool.name) : onExcludeTool(tool.name))}
|
|
2089
|
+
title={tool.excluded ? t("au.catalog.restoreNote") : t("au.catalog.excludeNote")}
|
|
2090
|
+
style={{ ...chipStyle, color: tool.excluded ? "var(--text)" : "var(--text-muted)" }}>
|
|
2091
|
+
{busyKey === "srv:" + s.name ? "…" : tool.excluded ? t("au.catalog.restore") : t("au.catalog.exclude")}
|
|
2092
|
+
</button>
|
|
2093
|
+
</td>
|
|
2094
|
+
<td style={tdStyle} />
|
|
2095
|
+
</tr>
|
|
2096
|
+
))}
|
|
2097
|
+
</>
|
|
2098
|
+
);
|
|
2099
|
+
}
|
|
2100
|
+
|
|
1925
2101
|
// ---------------------------------------------------------------- 主面板
|
|
1926
2102
|
|
|
1927
2103
|
/** 报表内容(头行工具栏 + 六标签体):浮窗/停靠两面共用。inDock=true 时隐藏自身关闭钮
|
|
@@ -1929,7 +2105,7 @@ const PickHint = () => <div style={{ padding: 24, textAlign: "center", color: "v
|
|
|
1929
2105
|
* useState 丢失 = §7 状态自管语义(可接受,与 demo 一致)。 */
|
|
1930
2106
|
function ReportBody({ inDock = false }: { inDock?: boolean }) {
|
|
1931
2107
|
useMoneyTick(); // 汇率到位/切语言时重渲染(fmtCost 双币显示)
|
|
1932
|
-
const [tab, setTab] = useState<"overview" | "models" | "keys" | "pivot" | "trend" | "sessions" | "input">("overview");
|
|
2108
|
+
const [tab, setTab] = useState<"overview" | "models" | "keys" | "pivot" | "trend" | "sessions" | "input" | "catalog">("overview");
|
|
1933
2109
|
const [range, setRange] = useState<RangeKey>("30d");
|
|
1934
2110
|
const [custom, setCustom] = useState<CustomRange>(() => ({ from: dayStr(-30), to: dayStr(0) }));
|
|
1935
2111
|
const [filters, setFilters] = useState<Filters>(EMPTY_FILTERS); // provider/model 筛选(总览/模型/Keys/维度四页共用)
|
|
@@ -1942,7 +2118,7 @@ function ReportBody({ inDock = false }: { inDock?: boolean }) {
|
|
|
1942
2118
|
// 小屏全屏(data-ext-float-full)与最大化按钮(⛶/❐ 自动注入)都由 aiti-float 托管
|
|
1943
2119
|
const tabs: Array<[typeof tab, string]> = [
|
|
1944
2120
|
["overview", t("au.tabOverview")], ["models", t("au.tabModels")],
|
|
1945
|
-
["keys", t("au.tabKeys")], ["pivot", t("au.tabPivot")], ["trend", t("au.tabTrend")], ["input", t("au.tabInput")], ["sessions", t("au.tabSessions")],
|
|
2121
|
+
["keys", t("au.tabKeys")], ["pivot", t("au.tabPivot")], ["trend", t("au.tabTrend")], ["input", t("au.tabInput")], ["sessions", t("au.tabSessions")], ["catalog", t("au.tabCatalog")],
|
|
1946
2122
|
];
|
|
1947
2123
|
const ranges: Array<[RangeKey, string]> = [
|
|
1948
2124
|
["today", t("au.range.today")], ["7d", t("au.range.7d")], ["30d", t("au.range.30d")],
|
|
@@ -1973,7 +2149,7 @@ function ReportBody({ inDock = false }: { inDock?: boolean }) {
|
|
|
1973
2149
|
))}
|
|
1974
2150
|
</div>
|
|
1975
2151
|
<span style={{ width: 1, height: 18, background: "var(--border)", margin: "0 4px" }} />
|
|
1976
|
-
{tab !== "sessions" && tab !== "input" && (
|
|
2152
|
+
{tab !== "sessions" && tab !== "input" && tab !== "catalog" && (
|
|
1977
2153
|
<div style={{ display: "flex", gap: 4, flexWrap: "wrap", alignItems: "center" }}>
|
|
1978
2154
|
{ranges.map(([id, label]) => (
|
|
1979
2155
|
<button key={id} onClick={() => setRange(id)}
|
|
@@ -2020,6 +2196,7 @@ function ReportBody({ inDock = false }: { inDock?: boolean }) {
|
|
|
2020
2196
|
{tab === "trend" && <TrendTab key={`td-${range}-${custom.from}~${custom.to}`} range={range} custom={custom} filters={filters} />}
|
|
2021
2197
|
{tab === "input" && <InputTab key={`in-${range}-${custom.from}~${custom.to}`} range={range} custom={custom} />}
|
|
2022
2198
|
{tab === "sessions" && <SessionsTab />}
|
|
2199
|
+
{tab === "catalog" && <CatalogTab />}
|
|
2023
2200
|
</div>
|
|
2024
2201
|
</>
|
|
2025
2202
|
);
|
package/dev-pack.mjs
CHANGED
|
@@ -77,7 +77,7 @@ export function agentsMdTemplate(extId) {
|
|
|
77
77
|
|
|
78
78
|
/** 默认 tools/build.mjs(esbuild 单包零配置;扩展自带 tools/build.mjs 则不走到这里)。 */
|
|
79
79
|
function buildMjsTemplate(extId, extRoot, clientOut, entryRel) {
|
|
80
|
-
|
|
80
|
+
// No hardcoded checkout path: candidates are resolved at run time (see repoCandidates below).
|
|
81
81
|
return `/**
|
|
82
82
|
* ${extId} · 现场构建入口(dev-pack 默认模板,esbuild 单包零配置)
|
|
83
83
|
* 用法:node tools/build.mjs
|
|
@@ -96,12 +96,25 @@ const entryRel = ${JSON.stringify(entryRel || "")};
|
|
|
96
96
|
|
|
97
97
|
// esbuild 解析:部署目录 node_modules → 源码仓 node_modules(本机开发场景)→ PATH 上的 esbuild → npm exec 现拉。
|
|
98
98
|
// 注意:node_modules/esbuild/bin/esbuild 是原生二进制(ELF/Mach-O),必须直接执行(不能当 JS 跑)。
|
|
99
|
+
// Checkout roots are discovered by walking up from the extension dir (a root has node_modules/),
|
|
100
|
+
// plus AITI_REPO_ROOT when set — no machine-specific absolute paths baked into generated files.
|
|
101
|
+
function repoCandidates() {
|
|
102
|
+
const out = [];
|
|
103
|
+
if (process.env.AITI_REPO_ROOT) out.push(process.env.AITI_REPO_ROOT.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
|
|
104
|
+
let d = extRoot;
|
|
105
|
+
for (let i = 0; i < 8; i++) {
|
|
106
|
+
out.push(d.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
|
|
107
|
+
const up = dirname(d);
|
|
108
|
+
if (up === d) break;
|
|
109
|
+
d = up;
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
99
113
|
function findEsbuild() {
|
|
100
114
|
const home = (process.env.HOME || process.env.USERPROFILE || "").split(pathSep).join("/");
|
|
101
115
|
const candidates = [
|
|
102
116
|
extRoot + "/node_modules/esbuild/bin/esbuild",
|
|
103
|
-
|
|
104
|
-
"C:/workspace/aiti-ai/node_modules/esbuild/bin/esbuild", // windows dev box(源码在 D 盘)
|
|
117
|
+
...repoCandidates(),
|
|
105
118
|
];
|
|
106
119
|
for (const c of candidates) {
|
|
107
120
|
if (!existsSync(c)) continue;
|