@blockrun/clawrouter 0.8.9 → 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/cli.js CHANGED
@@ -443,12 +443,16 @@ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPric
443
443
  const tierConfig = tierConfigs[tier];
444
444
  const model = tierConfig.primary;
445
445
  const pricing = modelPricing.get(model);
446
- const inputCost = pricing ? estimatedInputTokens / 1e6 * pricing.inputPrice : 0;
447
- const outputCost = pricing ? maxOutputTokens / 1e6 * pricing.outputPrice : 0;
446
+ const inputPrice = pricing?.inputPrice ?? 0;
447
+ const outputPrice = pricing?.outputPrice ?? 0;
448
+ const inputCost = estimatedInputTokens / 1e6 * inputPrice;
449
+ const outputCost = maxOutputTokens / 1e6 * outputPrice;
448
450
  const costEstimate = inputCost + outputCost;
449
451
  const opusPricing = modelPricing.get("anthropic/claude-opus-4");
450
- const baselineInput = opusPricing ? estimatedInputTokens / 1e6 * opusPricing.inputPrice : 0;
451
- const baselineOutput = opusPricing ? maxOutputTokens / 1e6 * opusPricing.outputPrice : 0;
452
+ const opusInputPrice = opusPricing?.inputPrice ?? 0;
453
+ const opusOutputPrice = opusPricing?.outputPrice ?? 0;
454
+ const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
455
+ const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
452
456
  const baselineCost = baselineInput + baselineOutput;
453
457
  const savings = baselineCost > 0 ? Math.max(0, (baselineCost - costEstimate) / baselineCost) : 0;
454
458
  return {
@@ -468,12 +472,16 @@ function getFallbackChain(tier, tierConfigs) {
468
472
  }
469
473
  function calculateModelCost(model, modelPricing, estimatedInputTokens, maxOutputTokens) {
470
474
  const pricing = modelPricing.get(model);
471
- const inputCost = pricing ? estimatedInputTokens / 1e6 * pricing.inputPrice : 0;
472
- const outputCost = pricing ? maxOutputTokens / 1e6 * pricing.outputPrice : 0;
475
+ const inputPrice = pricing?.inputPrice ?? 0;
476
+ const outputPrice = pricing?.outputPrice ?? 0;
477
+ const inputCost = estimatedInputTokens / 1e6 * inputPrice;
478
+ const outputCost = maxOutputTokens / 1e6 * outputPrice;
473
479
  const costEstimate = inputCost + outputCost;
474
480
  const opusPricing = modelPricing.get("anthropic/claude-opus-4");
475
- const baselineInput = opusPricing ? estimatedInputTokens / 1e6 * opusPricing.inputPrice : 0;
476
- const baselineOutput = opusPricing ? maxOutputTokens / 1e6 * opusPricing.outputPrice : 0;
481
+ const opusInputPrice = opusPricing?.inputPrice ?? 0;
482
+ const opusOutputPrice = opusPricing?.outputPrice ?? 0;
483
+ const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
484
+ const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
477
485
  const baselineCost = baselineInput + baselineOutput;
478
486
  const savings = baselineCost > 0 ? Math.max(0, (baselineCost - costEstimate) / baselineCost) : 0;
479
487
  return { costEstimate, baselineCost, savings };
@@ -1783,6 +1791,12 @@ async function getStats(days = 7) {
1783
1791
  }
1784
1792
  const totalSavings = totalBaselineCost - totalCost;
1785
1793
  const savingsPercentage = totalBaselineCost > 0 ? totalSavings / totalBaselineCost * 100 : 0;
1794
+ let entriesWithBaseline = 0;
1795
+ for (const day of dailyBreakdown) {
1796
+ if (day.totalBaselineCost !== day.totalCost) {
1797
+ entriesWithBaseline += day.totalRequests;
1798
+ }
1799
+ }
1786
1800
  return {
1787
1801
  period: days === 1 ? "today" : `last ${days} days`,
1788
1802
  totalRequests,
@@ -1794,8 +1808,10 @@ async function getStats(days = 7) {
1794
1808
  avgCostPerRequest: totalRequests > 0 ? totalCost / totalRequests : 0,
1795
1809
  byTier: byTierWithPercentage,
1796
1810
  byModel: byModelWithPercentage,
1797
- dailyBreakdown: dailyBreakdown.reverse()
1811
+ dailyBreakdown: dailyBreakdown.reverse(),
1798
1812
  // Oldest first for charts
1813
+ entriesWithBaseline
1814
+ // How many entries have valid baseline tracking
1799
1815
  };
1800
1816
  }
1801
1817