@blockrun/clawrouter 0.10.10 → 0.10.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
@@ -512,7 +512,7 @@ function calibrateConfidence(distance, steepness) {
512
512
 
513
513
  // src/router/selector.ts
514
514
  var BASELINE_MODEL_ID = "anthropic/claude-opus-4.6";
515
- function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPricing, estimatedInputTokens, maxOutputTokens, routingProfile) {
515
+ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPricing, estimatedInputTokens, maxOutputTokens, routingProfile, agenticScore) {
516
516
  const tierConfig = tierConfigs[tier];
517
517
  const model = tierConfig.primary;
518
518
  const pricing = modelPricing.get(model);
@@ -536,7 +536,8 @@ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPric
536
536
  reasoning,
537
537
  costEstimate,
538
538
  baselineCost,
539
- savings
539
+ savings,
540
+ ...agenticScore !== void 0 && { agenticScore }
540
541
  };
541
542
  }
542
543
  function getFallbackChain(tier, tierConfigs) {
@@ -1793,6 +1794,7 @@ function route(prompt, systemPrompt, maxOutputTokens, options) {
1793
1794
  tierConfigs = useAgenticTiers ? config.agenticTiers : config.tiers;
1794
1795
  profileSuffix = useAgenticTiers ? " | agentic" : "";
1795
1796
  }
1797
+ const agenticScoreValue = ruleResult.agenticScore;
1796
1798
  if (estimatedTokens > config.overrides.maxTokensForceComplex) {
1797
1799
  return selectModel(
1798
1800
  "COMPLEX",
@@ -1803,7 +1805,8 @@ function route(prompt, systemPrompt, maxOutputTokens, options) {
1803
1805
  modelPricing,
1804
1806
  estimatedTokens,
1805
1807
  maxOutputTokens,
1806
- routingProfile
1808
+ routingProfile,
1809
+ agenticScoreValue
1807
1810
  );
1808
1811
  }
1809
1812
  const hasStructuredOutput = systemPrompt ? /json|structured|schema/i.test(systemPrompt) : false;
@@ -1837,7 +1840,8 @@ function route(prompt, systemPrompt, maxOutputTokens, options) {
1837
1840
  modelPricing,
1838
1841
  estimatedTokens,
1839
1842
  maxOutputTokens,
1840
- routingProfile
1843
+ routingProfile,
1844
+ agenticScoreValue
1841
1845
  );
1842
1846
  }
1843
1847
 
@@ -5028,6 +5032,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
5028
5032
  }
5029
5033
  let body = Buffer.concat(bodyChunks);
5030
5034
  const originalContextSizeKB = Math.ceil(body.length / 1024);
5035
+ const debugMode = req.headers["x-clawrouter-debug"] !== "false";
5031
5036
  let routingDecision;
5032
5037
  let isStreaming = false;
5033
5038
  let modelId = "";
@@ -5326,8 +5331,18 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
5326
5331
  if (routingDecision) {
5327
5332
  const estimatedInputTokens = Math.ceil(body.length / 4);
5328
5333
  const estimatedTotalTokens = estimatedInputTokens + maxTokens;
5329
- const useAgenticTiers = routingDecision.reasoning?.includes("agentic") && routerOpts.config.agenticTiers;
5330
- const tierConfigs = useAgenticTiers ? routerOpts.config.agenticTiers : routerOpts.config.tiers;
5334
+ const tierConfigs = (() => {
5335
+ if (routingDecision.reasoning?.includes("agentic") && routerOpts.config.agenticTiers) {
5336
+ return routerOpts.config.agenticTiers;
5337
+ }
5338
+ if (routingProfile === "eco" && routerOpts.config.ecoTiers) {
5339
+ return routerOpts.config.ecoTiers;
5340
+ }
5341
+ if (routingProfile === "premium" && routerOpts.config.premiumTiers) {
5342
+ return routerOpts.config.premiumTiers;
5343
+ }
5344
+ return routerOpts.config.tiers;
5345
+ })();
5331
5346
  const fullChain = getFallbackChain(routingDecision.tier, tierConfigs);
5332
5347
  const contextFiltered = getFallbackChainFiltered(
5333
5348
  routingDecision.tier,
@@ -5399,6 +5414,12 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
5399
5414
  clearInterval(heartbeatInterval);
5400
5415
  heartbeatInterval = void 0;
5401
5416
  }
5417
+ if (debugMode && headersSentEarly && routingDecision) {
5418
+ const debugComment = `: x-clawrouter-debug profile=${routingProfile ?? "auto"} tier=${routingDecision.tier} model=${actualModelUsed} agentic=${routingDecision.agenticScore?.toFixed(2) ?? "n/a"} confidence=${routingDecision.confidence.toFixed(2)} reasoning=${routingDecision.reasoning}
5419
+
5420
+ `;
5421
+ safeWrite(res, debugComment);
5422
+ }
5402
5423
  if (routingDecision && actualModelUsed !== routingDecision.model) {
5403
5424
  const estimatedInputTokens = Math.ceil(body.length / 4);
5404
5425
  const newCosts = calculateModelCost(
@@ -5578,6 +5599,16 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
5578
5599
  });
5579
5600
  responseHeaders["x-context-used-kb"] = String(originalContextSizeKB);
5580
5601
  responseHeaders["x-context-limit-kb"] = String(CONTEXT_LIMIT_KB);
5602
+ if (debugMode && routingDecision) {
5603
+ responseHeaders["x-clawrouter-profile"] = routingProfile ?? "auto";
5604
+ responseHeaders["x-clawrouter-tier"] = routingDecision.tier;
5605
+ responseHeaders["x-clawrouter-model"] = actualModelUsed;
5606
+ responseHeaders["x-clawrouter-confidence"] = routingDecision.confidence.toFixed(2);
5607
+ responseHeaders["x-clawrouter-reasoning"] = routingDecision.reasoning;
5608
+ if (routingDecision.agenticScore !== void 0) {
5609
+ responseHeaders["x-clawrouter-agentic-score"] = routingDecision.agenticScore.toFixed(2);
5610
+ }
5611
+ }
5581
5612
  res.writeHead(upstream.status, responseHeaders);
5582
5613
  if (upstream.body) {
5583
5614
  const reader = upstream.body.getReader();