@caius_kong/ccusage-dashboard 0.2.14 → 0.2.15
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/lib/index.html +16 -5
- package/package.json +1 -1
package/lib/index.html
CHANGED
|
@@ -134,6 +134,18 @@ function fmtTok(n){
|
|
|
134
134
|
return String(n);
|
|
135
135
|
}
|
|
136
136
|
function fmtPct(n){return n==null?"–":n.toFixed(1)+"%";}
|
|
137
|
+
// cache hit rate (input side): read / (read + non-cached input). Shared by the
|
|
138
|
+
// c5 summary card and per-row hit spans.
|
|
139
|
+
function cacheHitStats(o){
|
|
140
|
+
const readIn=(o&&o.cacheReadTokens)||0, missIn=(o&&o.inputTokens)||0;
|
|
141
|
+
const rate=(readIn+missIn)>0?(readIn/(readIn+missIn))*100:null;
|
|
142
|
+
return {readIn, missIn, rate};
|
|
143
|
+
}
|
|
144
|
+
function cacheHitSpan(o){
|
|
145
|
+
const {readIn, missIn, rate}=cacheHitStats(o);
|
|
146
|
+
const tip=rate!=null?`cache hit rate: ${fmtPct(rate)} (read ${fmtTok(readIn)} / in ${fmtTok(missIn)})`:"no cache read data";
|
|
147
|
+
return `<span title="${tip}">hit ${fmtPct(rate)}</span>`;
|
|
148
|
+
}
|
|
137
149
|
function esc(s){const d=document.createElement("div");d.textContent=s;return d.innerHTML;}
|
|
138
150
|
async function copySessionId(id, ev){
|
|
139
151
|
ev.stopPropagation();
|
|
@@ -165,7 +177,7 @@ function renderModels(data){
|
|
|
165
177
|
const badge=m2?`<span class="pill">${esc(m2[1])}</span>`:"";
|
|
166
178
|
const mn=m2?esc(m2[2]||m2[1]):esc(m.name);
|
|
167
179
|
return `<div class="row"><div class="row-top"><span class="name">${mn}${badge ? " " + badge : ""}</span><span class="cost">${fmtUsd(m.cost)} · ${pct.toFixed(1)}%</span></div>
|
|
168
|
-
<div class="toks"><span title="input">in ${fmtTok(m.inputTokens)}</span><span title="output">out ${fmtTok(m.outputTokens)}</span><span title="cache read">read ${fmtTok(m.cacheReadTokens)}</span
|
|
180
|
+
<div class="toks"><span title="input">in ${fmtTok(m.inputTokens)}</span><span title="output">out ${fmtTok(m.outputTokens)}</span><span title="cache read">read ${fmtTok(m.cacheReadTokens)}</span>${cacheHitSpan(m)}<span title="cache write">write ${fmtTok(m.cacheCreationTokens)}</span></div>
|
|
169
181
|
<div class="bar"><div style="width:${Math.max(pct,1.2)}%"></div></div></div>`;
|
|
170
182
|
}).join("");
|
|
171
183
|
}
|
|
@@ -218,7 +230,7 @@ function renderSessions(data){
|
|
|
218
230
|
const last=(s.lastActivity||"").slice(0,10);
|
|
219
231
|
return `<div class="row">
|
|
220
232
|
<div class="row-top"><span>${label} <span class="pill">${esc(s.agent)}</span></span><span class="cost">${fmtUsd(s.cost)}</span></div>
|
|
221
|
-
<div class="toks">${last?`<span>${esc(last)}</span>`:""}<span title="input">in ${fmtTok(s.inputTokens)}</span><span title="output">out ${fmtTok(s.outputTokens)}</span><span title="cache read">read ${fmtTok(s.cacheReadTokens)}</span
|
|
233
|
+
<div class="toks">${last?`<span>${esc(last)}</span>`:""}<span title="input">in ${fmtTok(s.inputTokens)}</span><span title="output">out ${fmtTok(s.outputTokens)}</span><span title="cache read">read ${fmtTok(s.cacheReadTokens)}</span>${cacheHitSpan(s)}<span title="cache write">write ${fmtTok(s.cacheCreationTokens)}</span></div>
|
|
222
234
|
</div>`;
|
|
223
235
|
}).join("");
|
|
224
236
|
}
|
|
@@ -232,10 +244,9 @@ function applyCards(data){
|
|
|
232
244
|
$("c3").textContent=fmtTok(data.cacheReadTokens);
|
|
233
245
|
$("c4").textContent=fmtTok(data.cacheCreationTokens);
|
|
234
246
|
// cache hit rate = cache-read input / (cache-read input + non-cached input)
|
|
235
|
-
const
|
|
236
|
-
const hitRate = (hitIn+plainIn)>0 ? (hitIn/(hitIn+plainIn))*100 : null;
|
|
247
|
+
const {readIn, missIn, rate: hitRate}=cacheHitStats(data);
|
|
237
248
|
$("c5").innerHTML=fmtPct(hitRate)+(hitRate!=null?"<small> cache</small>":"");
|
|
238
|
-
$("c5p").textContent=hitRate!=null?`${fmtTok(
|
|
249
|
+
$("c5p").textContent=hitRate!=null?`${fmtTok(missIn)} miss · ${fmtTok(readIn)} hit`:"";
|
|
239
250
|
$("c1label").textContent=tabs[active].label;
|
|
240
251
|
$("modelSum").textContent=fmtUsd(total);
|
|
241
252
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caius_kong/ccusage-dashboard",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "One-command local dashboard for ccusage: today/week/month/custom cost by model, 30-day trend, monthly budget alert. Numbers straight from ccusage.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|