@tokenboard/cli 0.1.4 → 0.1.5
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/dist/cli.js +24 -40
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1027,6 +1027,17 @@ if (provenance_default.priceTableVersion !== PRICE_TABLE_VERSION || provenance_d
|
|
|
1027
1027
|
function recordTokens(r) {
|
|
1028
1028
|
return r.input + r.output + r.cacheRead + r.cacheCreate5m + r.cacheCreate1h;
|
|
1029
1029
|
}
|
|
1030
|
+
function dominantModel(byModel) {
|
|
1031
|
+
let best = "";
|
|
1032
|
+
let bestTokens = -1;
|
|
1033
|
+
for (const [model, tokens] of byModel) {
|
|
1034
|
+
if (tokens > bestTokens || tokens === bestTokens && model < best) {
|
|
1035
|
+
best = model;
|
|
1036
|
+
bestTokens = tokens;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return best;
|
|
1040
|
+
}
|
|
1030
1041
|
function summarize(records, prices) {
|
|
1031
1042
|
let totalTokens = 0;
|
|
1032
1043
|
let totalCostUsd = 0;
|
|
@@ -1044,9 +1055,10 @@ function summarize(records, prices) {
|
|
|
1044
1055
|
unpricedTokens += tokens;
|
|
1045
1056
|
unpricedModels.add(r.model);
|
|
1046
1057
|
}
|
|
1047
|
-
const d = perDay.get(r.date) ?? { tokens: 0, costUsd: 0 };
|
|
1058
|
+
const d = perDay.get(r.date) ?? { tokens: 0, costUsd: 0, byModel: /* @__PURE__ */ new Map() };
|
|
1048
1059
|
d.tokens += tokens;
|
|
1049
1060
|
d.costUsd += costUsd;
|
|
1061
|
+
d.byModel.set(r.model, (d.byModel.get(r.model) ?? 0) + tokens);
|
|
1050
1062
|
perDay.set(r.date, d);
|
|
1051
1063
|
const t = perTool.get(r.tool) ?? { tokens: 0, costUsd: 0 };
|
|
1052
1064
|
t.tokens += tokens;
|
|
@@ -1064,7 +1076,7 @@ function summarize(records, prices) {
|
|
|
1064
1076
|
anyUnpriced: unpricedModels.size > 0,
|
|
1065
1077
|
unpricedTokens,
|
|
1066
1078
|
unpricedModels: [...unpricedModels].sort(),
|
|
1067
|
-
perDay: [...perDay.entries()].map(([date, v]) => ({ date,
|
|
1079
|
+
perDay: [...perDay.entries()].map(([date, v]) => ({ date, tokens: v.tokens, costUsd: v.costUsd, model: dominantModel(v.byModel) })).sort((a, b) => a.date < b.date ? -1 : 1),
|
|
1068
1080
|
perTool: [...perTool.entries()].map(([tool, v]) => ({ tool, ...v })).sort((a, b) => b.tokens - a.tokens),
|
|
1069
1081
|
perModel: [...perModel.entries()].map(([model, v]) => ({ model, ...v })).sort((a, b) => b.tokens - a.tokens)
|
|
1070
1082
|
};
|
|
@@ -1785,20 +1797,6 @@ function formatApproxUsd(n) {
|
|
|
1785
1797
|
return "~$" + Math.round(n).toLocaleString("en-US");
|
|
1786
1798
|
}
|
|
1787
1799
|
|
|
1788
|
-
// src/render/sparkline.ts
|
|
1789
|
-
init_esm_shims();
|
|
1790
|
-
var GLYPHS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
|
|
1791
|
-
var ASCII_GLYPHS = ["_", ".", ".", "-", "-", "=", "=", "#"];
|
|
1792
|
-
function sparkline(values, ascii = false, colorize) {
|
|
1793
|
-
const glyphs2 = ascii ? ASCII_GLYPHS : GLYPHS;
|
|
1794
|
-
if (values.length === 0) return "";
|
|
1795
|
-
const min = Math.min(...values);
|
|
1796
|
-
const max = Math.max(...values);
|
|
1797
|
-
const range = max - min;
|
|
1798
|
-
const pick = (v) => range === 0 ? glyphs2[0] : glyphs2[Math.round((v - min) / range * (glyphs2.length - 1))];
|
|
1799
|
-
return values.map((v, i) => colorize ? colorize(pick(v), i) : pick(v)).join("");
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
1800
|
// src/render/model-display.ts
|
|
1803
1801
|
init_esm_shims();
|
|
1804
1802
|
function displayModel(model) {
|
|
@@ -1817,14 +1815,16 @@ function renderLocalPreview(summary, style) {
|
|
|
1817
1815
|
);
|
|
1818
1816
|
lines.push("");
|
|
1819
1817
|
lines.push(c.coral("\u{1FA99} tokenboard") + c.dim(" \xB7 your usage by day"));
|
|
1820
|
-
const headers = ["date", "tokens", "~$ est"];
|
|
1821
|
-
const aligns = ["left", "right", "right"];
|
|
1818
|
+
const headers = ["date", "model", "tokens", "~$ est"];
|
|
1819
|
+
const aligns = ["left", "left", "right", "right"];
|
|
1822
1820
|
const bodyRows = summary.perDay.map((d) => [
|
|
1823
1821
|
d.date,
|
|
1822
|
+
displayModel(d.model),
|
|
1824
1823
|
humanizeTokens(d.tokens),
|
|
1825
1824
|
formatApproxUsd(d.costUsd)
|
|
1826
1825
|
]);
|
|
1827
|
-
const
|
|
1826
|
+
const totalModel = summary.perModel[0] ? displayModel(summary.perModel[0].model) : "";
|
|
1827
|
+
const totalRow = ["TOTAL", totalModel, humanizeTokens(summary.totalTokens), formatApproxUsd(summary.totalCostUsd)];
|
|
1828
1828
|
const allRows = [headers, ...bodyRows, totalRow];
|
|
1829
1829
|
const colWidths = headers.map(
|
|
1830
1830
|
(_, col) => Math.max(...allRows.map((r) => [...r[col]].length), 1)
|
|
@@ -1850,8 +1850,9 @@ function renderLocalPreview(summary, style) {
|
|
|
1850
1850
|
summary.perDay.forEach((d, idx) => {
|
|
1851
1851
|
lines.push(
|
|
1852
1852
|
renderRow(bodyRows[idx], (p, col) => {
|
|
1853
|
-
if (col === 1) return c.
|
|
1854
|
-
if (col === 2) return c.
|
|
1853
|
+
if (col === 1) return c.dim(p);
|
|
1854
|
+
if (col === 2) return c.accentByLevel(p, norm(d.tokens));
|
|
1855
|
+
if (col === 3) return c.dim(p);
|
|
1855
1856
|
return p;
|
|
1856
1857
|
})
|
|
1857
1858
|
);
|
|
@@ -1860,15 +1861,12 @@ function renderLocalPreview(summary, style) {
|
|
|
1860
1861
|
lines.push(
|
|
1861
1862
|
renderRow(totalRow, (p, col) => {
|
|
1862
1863
|
if (col === 0) return c.dim(c.bold(p));
|
|
1863
|
-
if (col === 1) return c.
|
|
1864
|
+
if (col === 1) return c.coral(p);
|
|
1865
|
+
if (col === 2) return c.bold(c.coral(p));
|
|
1864
1866
|
return c.coral(p);
|
|
1865
1867
|
})
|
|
1866
1868
|
);
|
|
1867
1869
|
lines.push(dimRule("bottom"));
|
|
1868
|
-
const spark = sparkline(dayTokens, style.ascii, (glyph, i) => c.accentByLevel(glyph, norm(dayTokens[i])));
|
|
1869
|
-
if (spark) lines.push(c.dim("daily burn ") + spark);
|
|
1870
|
-
const modelStrip = renderModelStrip(summary, c);
|
|
1871
|
-
if (modelStrip) lines.push(modelStrip);
|
|
1872
1870
|
lines.push(
|
|
1873
1871
|
c.dim("approx $ is a local estimate from a bundled LiteLLM snapshot \u2014 the server is authoritative")
|
|
1874
1872
|
);
|
|
@@ -1877,20 +1875,6 @@ function renderLocalPreview(summary, style) {
|
|
|
1877
1875
|
}
|
|
1878
1876
|
return lines.join("\n");
|
|
1879
1877
|
}
|
|
1880
|
-
function renderModelStrip(summary, c) {
|
|
1881
|
-
if (summary.perModel.length === 0) return "";
|
|
1882
|
-
const TOP = 3;
|
|
1883
|
-
const shown = summary.perModel.slice(0, TOP);
|
|
1884
|
-
const parts = shown.map((m, rank) => {
|
|
1885
|
-
const name = displayModel(m.model) + (m.priced ? "" : c.dim("*"));
|
|
1886
|
-
const nameStyled = rank === 0 ? c.coral(name) : name;
|
|
1887
|
-
return `${nameStyled} ${humanizeTokens(m.tokens)} ${c.dim(formatApproxUsd(m.costUsd))}`;
|
|
1888
|
-
});
|
|
1889
|
-
let strip = c.dim("models ") + parts.join(c.dim(" \xB7 "));
|
|
1890
|
-
const extra = summary.perModel.length - shown.length;
|
|
1891
|
-
if (extra > 0) strip += c.dim(` \xB7 +${extra} more`);
|
|
1892
|
-
return strip;
|
|
1893
|
-
}
|
|
1894
1878
|
var CLAIM_PROMPT = "Sign in with GitHub to claim your spot?";
|
|
1895
1879
|
var CLAIM_HINT = "\u2192 Claim your spot anytime \u2192 tokenboard claim";
|
|
1896
1880
|
|