fix chain summary count: include costless user msgs, exclude invisible no-cost entries

This commit is contained in:
Meleki committed 2026-02-23 07:15:06 +01:00
1 parent 6666129dfa
commit 9aa8b8a1c6
1 file changed
+9 -6
+9 -6
View File
@@ -572,14 +572,17 @@ async function openModal(dataStr, clickedId, chainId) {
const chain = await api(`/api/entry-chain/${encodeURIComponent(entryId)}`);
// Calculate chain total
const chainCosts = chain.map(entry => {
let chainTotal = 0, chainCount = 0, visibleCount = 0;
chain.forEach(entry => {
try {
const d = JSON.parse(entry.data);
return d.message?.usage?.cost?.total || 0;
} catch { return 0; }
const msg = d.message;
const cost = msg?.usage?.cost?.total || 0;
if ((msg && extractContent(msg).trim()) || cost > 0) visibleCount++;
chainTotal += cost;
if (cost > 0) chainCount++;
} catch {}
});
const chainTotal = chainCosts.reduce((a, b) => a + b, 0);
const chainCount = chainCosts.filter(c => c > 0).length;
// Fill raw JSON if not set (e.g. opened from chain block)
if (!dataStr) {
@@ -588,7 +591,7 @@ async function openModal(dataStr, clickedId, chainId) {
let html = `<div class="chain-summary">
<span class="chain-summary-cost">Kette: ${pct(chainTotal)}</span>
<span class="chain-summary-count">${chainCount} Einträge mit Kosten / ${chain.length} gesamt</span>
<span class="chain-summary-count">${chainCount} mit Kosten / ${visibleCount} gesamt</span>
</div>`;
html += chain.map(entry => {