@blockrun/clawrouter 0.8.10 → 0.8.11

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/index.d.ts CHANGED
@@ -860,6 +860,7 @@ type AggregatedStats = {
860
860
  percentage: number;
861
861
  }>;
862
862
  dailyBreakdown: DailyStats[];
863
+ entriesWithBaseline: number;
863
864
  };
864
865
  /**
865
866
  * Get aggregated statistics for the last N days.
package/dist/index.js CHANGED
@@ -1829,6 +1829,12 @@ async function getStats(days = 7) {
1829
1829
  }
1830
1830
  const totalSavings = totalBaselineCost - totalCost;
1831
1831
  const savingsPercentage = totalBaselineCost > 0 ? totalSavings / totalBaselineCost * 100 : 0;
1832
+ let entriesWithBaseline = 0;
1833
+ for (const day of dailyBreakdown) {
1834
+ if (day.totalBaselineCost !== day.totalCost) {
1835
+ entriesWithBaseline += day.totalRequests;
1836
+ }
1837
+ }
1832
1838
  return {
1833
1839
  period: days === 1 ? "today" : `last ${days} days`,
1834
1840
  totalRequests,
@@ -1840,8 +1846,10 @@ async function getStats(days = 7) {
1840
1846
  avgCostPerRequest: totalRequests > 0 ? totalCost / totalRequests : 0,
1841
1847
  byTier: byTierWithPercentage,
1842
1848
  byModel: byModelWithPercentage,
1843
- dailyBreakdown: dailyBreakdown.reverse()
1849
+ dailyBreakdown: dailyBreakdown.reverse(),
1844
1850
  // Oldest first for charts
1851
+ entriesWithBaseline
1852
+ // How many entries have valid baseline tracking
1845
1853
  };
1846
1854
  }
1847
1855
  function formatStatsAscii(stats) {
@@ -1853,20 +1861,27 @@ function formatStatsAscii(stats) {
1853
1861
  lines.push(`\u2551 Total Requests: ${stats.totalRequests.toString().padEnd(41)}\u2551`);
1854
1862
  lines.push(`\u2551 Total Cost: $${stats.totalCost.toFixed(4).padEnd(43)}\u2551`);
1855
1863
  lines.push(`\u2551 Baseline Cost (Opus): $${stats.totalBaselineCost.toFixed(4).padEnd(33)}\u2551`);
1856
- lines.push(
1857
- `\u2551 \u{1F4B0} Total Saved: $${stats.totalSavings.toFixed(4)} (${stats.savingsPercentage.toFixed(1)}%)`.padEnd(
1858
- 61
1859
- ) + "\u2551"
1860
- );
1864
+ const savingsLine = `\u2551 \u{1F4B0} Total Saved: $${stats.totalSavings.toFixed(4)} (${stats.savingsPercentage.toFixed(1)}%)`;
1865
+ if (stats.entriesWithBaseline < stats.totalRequests && stats.entriesWithBaseline > 0) {
1866
+ lines.push(savingsLine.padEnd(61) + "\u2551");
1867
+ const note = `\u2551 (based on ${stats.entriesWithBaseline}/${stats.totalRequests} tracked requests)`;
1868
+ lines.push(note.padEnd(61) + "\u2551");
1869
+ } else {
1870
+ lines.push(savingsLine.padEnd(61) + "\u2551");
1871
+ }
1861
1872
  lines.push(`\u2551 Avg Latency: ${stats.avgLatencyMs.toFixed(0)}ms`.padEnd(61) + "\u2551");
1862
1873
  lines.push("\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563");
1863
1874
  lines.push("\u2551 Routing by Tier: \u2551");
1864
- const tierOrder = ["SIMPLE", "MEDIUM", "COMPLEX", "REASONING"];
1875
+ const knownTiers = ["SIMPLE", "MEDIUM", "COMPLEX", "REASONING"];
1876
+ const allTiers = Object.keys(stats.byTier);
1877
+ const otherTiers = allTiers.filter((t) => !knownTiers.includes(t));
1878
+ const tierOrder = [...knownTiers.filter((t) => stats.byTier[t]), ...otherTiers];
1865
1879
  for (const tier of tierOrder) {
1866
1880
  const data = stats.byTier[tier];
1867
1881
  if (data) {
1868
1882
  const bar = "\u2588".repeat(Math.min(20, Math.round(data.percentage / 5)));
1869
- const line = `\u2551 ${tier.padEnd(10)} ${bar.padEnd(20)} ${data.percentage.toFixed(1).padStart(5)}% (${data.count})`;
1883
+ const displayTier = tier === "UNKNOWN" ? "OTHER" : tier;
1884
+ const line = `\u2551 ${displayTier.padEnd(10)} ${bar.padEnd(20)} ${data.percentage.toFixed(1).padStart(5)}% (${data.count})`;
1870
1885
  lines.push(line.padEnd(61) + "\u2551");
1871
1886
  }
1872
1887
  }