@blockrun/clawrouter 0.12.300 → 0.12.302

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
@@ -45706,10 +45706,10 @@ function isEligible(modelId, features, maxOutputTokens, options) {
45706
45706
  return model.contextWindow >= (features.estimatedInputTokens + maxOutputTokens) * 1.1;
45707
45707
  }
45708
45708
  function estimatedCost(modelId, options, inputTokens, outputTokens) {
45709
- const price = options.modelPricing.get(modelId);
45710
- if (!price) return Number.POSITIVE_INFINITY;
45711
- if (price.flatPrice !== void 0) return price.flatPrice;
45712
- return (inputTokens * price.inputPrice + outputTokens * price.outputPrice) / 1e6;
45709
+ const price2 = options.modelPricing.get(modelId);
45710
+ if (!price2) return Number.POSITIVE_INFINITY;
45711
+ if (price2.flatPrice !== void 0) return price2.flatPrice;
45712
+ return (inputTokens * price2.inputPrice + outputTokens * price2.outputPrice) / 1e6;
45713
45713
  }
45714
45714
  function profileScore(modelId, options, now2) {
45715
45715
  const profile = options.modelPerformance?.[modelId] ?? LIVE_MODEL_PROFILES[modelId] ?? HISTORICAL_MODEL_PROFILES[modelId];
@@ -48768,7 +48768,8 @@ async function parseLogFile(filePath) {
48768
48768
  cost: entry.cost || 0,
48769
48769
  baselineCost: entry.baselineCost || entry.cost || 0,
48770
48770
  savings: entry.savings || 0,
48771
- latencyMs: entry.latencyMs || 0
48771
+ latencyMs: entry.latencyMs || 0,
48772
+ status: entry.status === "error" || entry.status === "success" ? entry.status : void 0
48772
48773
  });
48773
48774
  } catch {
48774
48775
  }
@@ -48822,11 +48823,17 @@ async function getStats(days = 7) {
48822
48823
  let totalCost = 0;
48823
48824
  let totalBaselineCost = 0;
48824
48825
  let totalLatency = 0;
48826
+ let errorCount = 0;
48825
48827
  for (const file of filesToRead) {
48826
48828
  const date = file.replace("usage-", "").replace(".jsonl", "");
48827
48829
  const filePath = join6(LOG_DIR2, file);
48828
48830
  const entries = await parseLogFile(filePath);
48829
48831
  if (entries.length === 0) continue;
48832
+ for (const entry of entries) {
48833
+ if (entry.status === "error") {
48834
+ errorCount++;
48835
+ }
48836
+ }
48830
48837
  const dayStats = aggregateDay(date, entries);
48831
48838
  dailyBreakdown.push(dayStats);
48832
48839
  totalRequests += dayStats.totalRequests;
@@ -48879,8 +48886,9 @@ async function getStats(days = 7) {
48879
48886
  byModel: byModelWithPercentage,
48880
48887
  dailyBreakdown: dailyBreakdown.reverse(),
48881
48888
  // Oldest first for charts
48882
- entriesWithBaseline
48889
+ entriesWithBaseline,
48883
48890
  // How many entries have valid baseline tracking
48891
+ errorCount
48884
48892
  };
48885
48893
  }
48886
48894
  function formatStatsAscii(stats) {
@@ -287490,8 +287498,7 @@ async function collectLogInfo() {
287490
287498
  return {
287491
287499
  requestsLast24h: stats.totalRequests,
287492
287500
  costLast24h: `$${stats.totalCost.toFixed(4)}`,
287493
- errorsFound: 0
287494
- // TODO: parse error logs
287501
+ errorsFound: stats.errorCount
287495
287502
  };
287496
287503
  } catch {
287497
287504
  return {
package/dist/index.d.ts CHANGED
@@ -1731,6 +1731,7 @@ type AggregatedStats = {
1731
1731
  }>;
1732
1732
  dailyBreakdown: DailyStats[];
1733
1733
  entriesWithBaseline: number;
1734
+ errorCount: number;
1734
1735
  };
1735
1736
  /**
1736
1737
  * Get aggregated statistics for the last N days.
package/dist/index.js CHANGED
@@ -259128,10 +259128,10 @@ function isEligible(modelId, features, maxOutputTokens, options) {
259128
259128
  return model.contextWindow >= (features.estimatedInputTokens + maxOutputTokens) * 1.1;
259129
259129
  }
259130
259130
  function estimatedCost(modelId, options, inputTokens, outputTokens) {
259131
- const price = options.modelPricing.get(modelId);
259132
- if (!price) return Number.POSITIVE_INFINITY;
259133
- if (price.flatPrice !== void 0) return price.flatPrice;
259134
- return (inputTokens * price.inputPrice + outputTokens * price.outputPrice) / 1e6;
259131
+ const price2 = options.modelPricing.get(modelId);
259132
+ if (!price2) return Number.POSITIVE_INFINITY;
259133
+ if (price2.flatPrice !== void 0) return price2.flatPrice;
259134
+ return (inputTokens * price2.inputPrice + outputTokens * price2.outputPrice) / 1e6;
259135
259135
  }
259136
259136
  function profileScore(modelId, options, now2) {
259137
259137
  const profile = options.modelPerformance?.[modelId] ?? LIVE_MODEL_PROFILES[modelId] ?? HISTORICAL_MODEL_PROFILES[modelId];
@@ -260853,7 +260853,8 @@ async function parseLogFile(filePath) {
260853
260853
  cost: entry.cost || 0,
260854
260854
  baselineCost: entry.baselineCost || entry.cost || 0,
260855
260855
  savings: entry.savings || 0,
260856
- latencyMs: entry.latencyMs || 0
260856
+ latencyMs: entry.latencyMs || 0,
260857
+ status: entry.status === "error" || entry.status === "success" ? entry.status : void 0
260857
260858
  });
260858
260859
  } catch {
260859
260860
  }
@@ -260907,11 +260908,17 @@ async function getStats(days = 7) {
260907
260908
  let totalCost = 0;
260908
260909
  let totalBaselineCost = 0;
260909
260910
  let totalLatency = 0;
260911
+ let errorCount = 0;
260910
260912
  for (const file of filesToRead) {
260911
260913
  const date = file.replace("usage-", "").replace(".jsonl", "");
260912
260914
  const filePath = join6(LOG_DIR2, file);
260913
260915
  const entries = await parseLogFile(filePath);
260914
260916
  if (entries.length === 0) continue;
260917
+ for (const entry of entries) {
260918
+ if (entry.status === "error") {
260919
+ errorCount++;
260920
+ }
260921
+ }
260915
260922
  const dayStats = aggregateDay(date, entries);
260916
260923
  dailyBreakdown.push(dayStats);
260917
260924
  totalRequests += dayStats.totalRequests;
@@ -260964,8 +260971,9 @@ async function getStats(days = 7) {
260964
260971
  byModel: byModelWithPercentage,
260965
260972
  dailyBreakdown: dailyBreakdown.reverse(),
260966
260973
  // Oldest first for charts
260967
- entriesWithBaseline
260974
+ entriesWithBaseline,
260968
260975
  // How many entries have valid baseline tracking
260976
+ errorCount
260969
260977
  };
260970
260978
  }
260971
260979
  function formatStatsAscii(stats) {
@@ -2361,10 +2361,10 @@ function isEligible(modelId, features, maxOutputTokens, options) {
2361
2361
  return model.contextWindow >= (features.estimatedInputTokens + maxOutputTokens) * 1.1;
2362
2362
  }
2363
2363
  function estimatedCost(modelId, options, inputTokens, outputTokens) {
2364
- const price = options.modelPricing.get(modelId);
2365
- if (!price) return Number.POSITIVE_INFINITY;
2366
- if (price.flatPrice !== void 0) return price.flatPrice;
2367
- return (inputTokens * price.inputPrice + outputTokens * price.outputPrice) / 1e6;
2364
+ const price2 = options.modelPricing.get(modelId);
2365
+ if (!price2) return Number.POSITIVE_INFINITY;
2366
+ if (price2.flatPrice !== void 0) return price2.flatPrice;
2367
+ return (inputTokens * price2.inputPrice + outputTokens * price2.outputPrice) / 1e6;
2368
2368
  }
2369
2369
  function profileScore(modelId, options, now) {
2370
2370
  const profile = options.modelPerformance?.[modelId] ?? LIVE_MODEL_PROFILES[modelId] ?? HISTORICAL_MODEL_PROFILES[modelId];
@@ -2525,6 +2525,81 @@ var PortfolioStrategy = class {
2525
2525
  };
2526
2526
  }
2527
2527
  };
2528
+ var MODEL_KINDS = ["chat", "image", "video", "music"];
2529
+ var PRICE_KEYS = [
2530
+ "input",
2531
+ "output",
2532
+ "per_image",
2533
+ "per_second",
2534
+ "per_track",
2535
+ "cache_read",
2536
+ "cache_write",
2537
+ "transaction_fee",
2538
+ "per_call_surcharge",
2539
+ "default_duration_seconds",
2540
+ "max_duration_seconds"
2541
+ ];
2542
+ var UNIT_PRICE = { image: "per_image", video: "per_second", music: "per_track" };
2543
+ var MODEL_ID = /^[a-z0-9][a-z0-9._-]*\/[a-zA-Z0-9][a-zA-Z0-9._:+-]*$/;
2544
+ var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
2545
+ var price = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
2546
+ var capacity = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
2547
+ function parseModelCatalog(value) {
2548
+ if (!record(value) || !Array.isArray(value.data)) {
2549
+ throw new TypeError("Model catalog must contain a data array");
2550
+ }
2551
+ const entries = /* @__PURE__ */ new Map();
2552
+ for (const entry of value.data) {
2553
+ if (record(entry) && typeof entry.id === "string" && entry.id.length <= 200 && MODEL_ID.test(entry.id)) {
2554
+ entries.set(entry.id, entry);
2555
+ }
2556
+ }
2557
+ const result = { models: [], chat: [], image: [], video: [], music: [], unavailable: [] };
2558
+ const models = [];
2559
+ const unavailable = [];
2560
+ for (const [id, entry] of entries) {
2561
+ if (entry.available === false) unavailable.push(id);
2562
+ if (entry.available !== void 0 && entry.available !== true || entry.hidden !== void 0 && entry.hidden !== false || !Array.isArray(entry.categories) || !record(entry.pricing)) continue;
2563
+ const categories = [...new Set(entry.categories.filter((c) => typeof c === "string"))];
2564
+ const rawPricing = entry.pricing;
2565
+ const pricing = {};
2566
+ for (const key of PRICE_KEYS) if (price(rawPricing[key])) pricing[key] = rawPricing[key];
2567
+ const kinds = MODEL_KINDS.filter((kind) => categories.includes(kind) && (kind === "chat" ? price(rawPricing.input) && price(rawPricing.output) : price(rawPricing[UNIT_PRICE[kind]])));
2568
+ if (!kinds.length) continue;
2569
+ const model = {
2570
+ id,
2571
+ name: typeof entry.name === "string" && entry.name.trim() ? entry.name : id,
2572
+ categories,
2573
+ kinds,
2574
+ pricing,
2575
+ free: kinds.includes("chat") && entry.billing_mode === "free" && pricing.input === 0 && pricing.output === 0,
2576
+ ...typeof entry.billing_mode === "string" ? { billingMode: entry.billing_mode } : {},
2577
+ ...capacity(entry.context_window) !== void 0 ? { contextWindow: capacity(entry.context_window) } : {},
2578
+ ...capacity(entry.max_output) !== void 0 ? { maxOutputTokens: capacity(entry.max_output) } : {}
2579
+ };
2580
+ models.push(model);
2581
+ }
2582
+ result.models = models;
2583
+ result.unavailable = unavailable;
2584
+ for (const kind of MODEL_KINDS) result[kind] = models.filter((model) => model.kinds.includes(kind));
2585
+ return result;
2586
+ }
2587
+ function toRoutingCatalog(catalog, options = {}) {
2588
+ const verified = { ...DEFAULT_MODEL_CAPABILITIES, ...options.verifiedCapabilities };
2589
+ const modelPricing = /* @__PURE__ */ new Map();
2590
+ const modelCapabilities = {};
2591
+ for (const model of catalog.chat) {
2592
+ modelPricing.set(model.id, { inputPrice: model.pricing.input, outputPrice: model.pricing.output });
2593
+ const evidence = verified[model.id];
2594
+ modelCapabilities[model.id] = {
2595
+ contextWindow: model.contextWindow ?? evidence?.contextWindow ?? 0,
2596
+ maxOutputTokens: model.maxOutputTokens ?? evidence?.maxOutputTokens ?? 0,
2597
+ supportsTools: evidence?.supportsTools === true,
2598
+ supportsVision: model.categories.includes("vision")
2599
+ };
2600
+ }
2601
+ return { modelPricing, modelCapabilities, unavailableModels: [...catalog.unavailable] };
2602
+ }
2528
2603
  var DEFAULT_ROUTING_CONFIG = {
2529
2604
  version: "3.5",
2530
2605
  strategy: "portfolio",
@@ -4021,6 +4096,7 @@ export {
4021
4096
  DEFAULT_ROUTING_CONFIG,
4022
4097
  HISTORICAL_MODEL_PROFILES,
4023
4098
  LIVE_MODEL_PROFILES,
4099
+ MODEL_KINDS,
4024
4100
  PortfolioStrategy,
4025
4101
  RulesStrategy,
4026
4102
  applyUnavailableModels,
@@ -4035,7 +4111,9 @@ export {
4035
4111
  getFallbackChainFiltered,
4036
4112
  getStrategy,
4037
4113
  inferToolRequirement,
4114
+ parseModelCatalog,
4038
4115
  registerStrategy,
4039
- route
4116
+ route,
4117
+ toRoutingCatalog
4040
4118
  };
4041
4119
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/clawrouter",
3
- "version": "0.12.300",
3
+ "version": "0.12.302",
4
4
  "description": "Smart LLM router — save 84% on inference costs. 90 models (7 free). Pay by credit card (API key) or USDC (x402 wallet).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -116,7 +116,7 @@
116
116
  },
117
117
  "devDependencies": {
118
118
  "@blockrun/model-catalog": "https://codeload.github.com/BlockRunAI/model-catalog/tar.gz/b95efe2f025c9968742e6479bc9ec71b6a40c0f4",
119
- "@blockrun/router-core": "https://codeload.github.com/BlockRunAI/router-core/tar.gz/8773a9954b091bd0090acdfec67c75a006c0e156",
119
+ "@blockrun/router-core": "https://codeload.github.com/BlockRunAI/router-core/tar.gz/fd6d03d035ff676642ba1683c333d929939f8a00",
120
120
  "@eslint/js": "^10.0.1",
121
121
  "eslint": "^10.2.0",
122
122
  "openclaw": "^2026.7.2-beta.7",