feat(token-tracking): add Token usage panel to the report detail page

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
wangwei
2026-07-02 15:40:37 +08:00
co-authored by Copilot
parent 4bb1952348
commit 6bad007cd9
2 changed files with 25 additions and 0 deletions
+21
View File
@@ -32,6 +32,7 @@ const Report = {
Report.renderGroupings(detail.report);
Report.renderLowest(detail.report);
Report.renderAdvice(detail.summary, detail.report);
Report.renderTokenUsage(detail.report);
content.style.opacity = "1";
// 同步下拉选中项
@@ -254,6 +255,26 @@ const Report = {
tableEl.innerHTML = `<table class="group-table">${head}${body}</table>`;
},
// 渲染"Token 用量"面板:按模型分组的 input/output/调用次数表格。
renderTokenUsage(report) {
const wrap = document.getElementById("token-usage-wrap");
if (!wrap) return;
const usage = report.token_usage || {};
const models = Object.keys(usage).sort();
if (models.length === 0) {
wrap.innerHTML = '<p class="muted tiny">暂无 token 用量数据。</p>';
return;
}
let head = "<tr><th>模型</th><th>input_tokens</th><th>output_tokens</th><th>调用次数</th></tr>";
let body = "";
models.forEach((model) => {
const u = usage[model] || {};
body += `<tr><td>${App.escape(model)}</td><td>${u.input_tokens ?? 0}</td>` +
`<td>${u.output_tokens ?? 0}</td><td>${u.calls ?? 0}</td></tr>`;
});
wrap.innerHTML = `<table class="group-table">${head}${body}</table>`;
},
// ④ 最低分样本逐条复核表(点击展开)。
renderLowest(report) { const wrap = document.getElementById("lowest-table");
const samples = report.lowest_samples || [];