@blockrun/clawrouter 0.10.19 → 0.10.21

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
@@ -5287,9 +5287,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
5287
5287
  const tools = parsed.tools;
5288
5288
  hasTools = Array.isArray(tools) && tools.length > 0;
5289
5289
  if (hasTools && tools) {
5290
- console.log(
5291
- `[ClawRouter] Tools detected (${tools.length}), agentic mode via keywords`
5292
- );
5290
+ console.log(`[ClawRouter] Tools detected (${tools.length}), agentic mode via keywords`);
5293
5291
  }
5294
5292
  routingDecision = route(prompt, systemPrompt, maxTokens, {
5295
5293
  ...routerOpts,
@@ -5554,11 +5552,10 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
5554
5552
  modelsToTry = toolFiltered.slice(0, MAX_FALLBACK_ATTEMPTS);
5555
5553
  modelsToTry = prioritizeNonRateLimited(modelsToTry);
5556
5554
  } else {
5557
- if (modelId && modelId !== FREE_MODEL) {
5558
- modelsToTry = [modelId, FREE_MODEL];
5559
- } else {
5560
- modelsToTry = modelId ? [modelId] : [];
5561
- }
5555
+ modelsToTry = modelId ? [modelId] : [];
5556
+ }
5557
+ if (!modelsToTry.includes(FREE_MODEL)) {
5558
+ modelsToTry.push(FREE_MODEL);
5562
5559
  }
5563
5560
  let upstream;
5564
5561
  let lastError;
@@ -5592,6 +5589,19 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
5592
5589
  if (result.errorStatus === 429) {
5593
5590
  markRateLimited(tryModel);
5594
5591
  }
5592
+ const isPaymentErr = /payment.*verification.*failed|insufficient.*funds/i.test(
5593
+ result.errorBody || ""
5594
+ );
5595
+ if (isPaymentErr && tryModel !== FREE_MODEL) {
5596
+ const freeIdx = modelsToTry.indexOf(FREE_MODEL);
5597
+ if (freeIdx > i + 1) {
5598
+ console.log(
5599
+ `[ClawRouter] Payment error \u2014 skipping to free model: ${FREE_MODEL}`
5600
+ );
5601
+ i = freeIdx - 1;
5602
+ continue;
5603
+ }
5604
+ }
5595
5605
  console.log(
5596
5606
  `[ClawRouter] Provider error from ${tryModel}, trying fallback: ${result.errorBody?.slice(0, 100)}`
5597
5607
  );