@alexeiled/claude-router 1.20.1 → 1.21.1

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/lib/modes.mjs CHANGED
@@ -15,18 +15,19 @@ function steppedEffort(config, route, step) {
15
15
  return choices.find((effort) => supported.includes(effort)) ?? null;
16
16
  }
17
17
 
18
- // The route `mode` runs for tier and activity, always from the configured routes. `cost` takes the tier below (never
19
- // below `low`) when it runs a model with a lower input price, else one effort level less; `quality` one effort level
20
- // more, else the tier above. One lever per decision: cost pays mostly for input and cache tokens, which effort does
21
- // not lower, and quality keeps the model and its cache. `micro` and `balanced` keep the configured route.
18
+ // The route `mode` runs for tier and activity, always from the configured routes. `cost` takes a model with a lower
19
+ // input price where one is below: the tier below, or at `low` the tier's route without its activity override (never
20
+ // `micro`); else one effort level less. `high` keeps its model, so a turn that clears the upgrade bar runs on the
21
+ // strongest one. `quality` one effort level more, else the tier above. One lever per decision; quality keeps the
22
+ // model and its cache. `micro` and `balanced` keep the configured route.
22
23
  export function modeRoute(config, mode, tier, activity = null) {
23
24
  const routeAt = (t) => resolveRoute(config, t, activity);
24
25
  const route = routeAt(tier);
25
26
  if (mode === 'balanced' || tier === 'micro') return route;
26
27
  if (mode === 'cost') {
27
- const below = routeAt(TIERS[Math.max(rank('low'), rank(tier) - 1)]);
28
- if (below.model !== route.model && config.models[below.model].input < config.models[route.model].input)
29
- return below;
28
+ const below = tier === 'low' ? resolveRoute(config, 'low') : routeAt(TIERS[rank(tier) - 1]);
29
+ const cheaper = config.models[below.model].input < config.models[route.model].input;
30
+ if (tier !== 'high' && below.model !== route.model && cheaper) return below;
30
31
  const effort = steppedEffort(config, route, -1);
31
32
  return effort ? { model: route.model, effort } : route;
32
33
  }