@blockrun/clawrouter 0.8.29 → 0.8.30

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/index.d.ts CHANGED
@@ -478,7 +478,8 @@ declare function getSessionId(headers: Record<string, string | string[] | undefi
478
478
  */
479
479
 
480
480
  /**
481
- * Get the proxy port from environment variable or default.
481
+ * Get the proxy port from pre-loaded configuration.
482
+ * Port is validated at module load time, this just returns the cached value.
482
483
  */
483
484
  declare function getProxyPort(): number;
484
485
  /** Callback info for low balance warning */
package/dist/index.js CHANGED
@@ -1810,14 +1810,22 @@ async function logUsage(entry) {
1810
1810
 
1811
1811
  // src/stats.ts
1812
1812
  import { readFile, readdir } from "fs/promises";
1813
- import { join as join2, dirname } from "path";
1813
+ import { join as join3 } from "path";
1814
1814
  import { homedir as homedir2 } from "os";
1815
+
1816
+ // src/version.ts
1817
+ import { createRequire } from "module";
1815
1818
  import { fileURLToPath } from "url";
1816
- var __dirname = dirname(fileURLToPath(import.meta.url));
1817
- var pkgPath = join2(__dirname, "..", "package.json");
1818
- var pkg = JSON.parse(await readFile(pkgPath, "utf-8").catch(() => '{"version":"unknown"}'));
1819
+ import { dirname, join as join2 } from "path";
1820
+ var __filename = fileURLToPath(import.meta.url);
1821
+ var __dirname = dirname(__filename);
1822
+ var require2 = createRequire(import.meta.url);
1823
+ var pkg = require2(join2(__dirname, "..", "package.json"));
1819
1824
  var VERSION = pkg.version;
1820
- var LOG_DIR2 = join2(homedir2(), ".openclaw", "blockrun", "logs");
1825
+ var USER_AGENT = `clawrouter/${VERSION}`;
1826
+
1827
+ // src/stats.ts
1828
+ var LOG_DIR2 = join3(homedir2(), ".openclaw", "blockrun", "logs");
1821
1829
  async function parseLogFile(filePath) {
1822
1830
  try {
1823
1831
  const content = await readFile(filePath, "utf-8");
@@ -1884,7 +1892,7 @@ async function getStats(days = 7) {
1884
1892
  let totalLatency = 0;
1885
1893
  for (const file of filesToRead) {
1886
1894
  const date = file.replace("usage-", "").replace(".jsonl", "");
1887
- const filePath = join2(LOG_DIR2, file);
1895
+ const filePath = join3(LOG_DIR2, file);
1888
1896
  const entries = await parseLogFile(filePath);
1889
1897
  if (entries.length === 0) continue;
1890
1898
  const dayStats = aggregateDay(date, entries);
@@ -2300,17 +2308,6 @@ var BalanceMonitor = class {
2300
2308
  }
2301
2309
  };
2302
2310
 
2303
- // src/version.ts
2304
- import { createRequire } from "module";
2305
- import { fileURLToPath as fileURLToPath2 } from "url";
2306
- import { dirname as dirname2, join as join3 } from "path";
2307
- var __filename = fileURLToPath2(import.meta.url);
2308
- var __dirname2 = dirname2(__filename);
2309
- var require2 = createRequire(import.meta.url);
2310
- var pkg2 = require2(join3(__dirname2, "..", "package.json"));
2311
- var VERSION2 = pkg2.version;
2312
- var USER_AGENT = `clawrouter/${VERSION2}`;
2313
-
2314
2311
  // src/session.ts
2315
2312
  var DEFAULT_SESSION_CONFIG = {
2316
2313
  enabled: false,
@@ -2467,9 +2464,9 @@ async function checkForUpdates() {
2467
2464
  const data = await res.json();
2468
2465
  const latest = data.version;
2469
2466
  if (!latest) return;
2470
- if (compareSemver(latest, VERSION2) > 0) {
2467
+ if (compareSemver(latest, VERSION) > 0) {
2471
2468
  console.log("");
2472
- console.log(`\x1B[33m\u2B06\uFE0F ClawRouter ${latest} available (you have ${VERSION2})\x1B[0m`);
2469
+ console.log(`\x1B[33m\u2B06\uFE0F ClawRouter ${latest} available (you have ${VERSION})\x1B[0m`);
2473
2470
  console.log(` Run: \x1B[36mcurl -fsSL ${UPDATE_URL} | bash\x1B[0m`);
2474
2471
  console.log("");
2475
2472
  }
@@ -2477,6 +2474,19 @@ async function checkForUpdates() {
2477
2474
  }
2478
2475
  }
2479
2476
 
2477
+ // src/config.ts
2478
+ var DEFAULT_PORT = 8402;
2479
+ var PROXY_PORT = (() => {
2480
+ const envPort = process.env.BLOCKRUN_PROXY_PORT;
2481
+ if (envPort) {
2482
+ const parsed = parseInt(envPort, 10);
2483
+ if (!isNaN(parsed) && parsed > 0 && parsed < 65536) {
2484
+ return parsed;
2485
+ }
2486
+ }
2487
+ return DEFAULT_PORT;
2488
+ })();
2489
+
2480
2490
  // src/proxy.ts
2481
2491
  var BLOCKRUN_API = "https://blockrun.ai/api";
2482
2492
  var AUTO_MODEL = "blockrun/auto";
@@ -2493,7 +2503,6 @@ var ROUTING_PROFILES = /* @__PURE__ */ new Set([
2493
2503
  var FREE_MODEL = "nvidia/gpt-oss-120b";
2494
2504
  var HEARTBEAT_INTERVAL_MS = 2e3;
2495
2505
  var DEFAULT_REQUEST_TIMEOUT_MS = 18e4;
2496
- var DEFAULT_PORT = 8402;
2497
2506
  var MAX_FALLBACK_ATTEMPTS = 3;
2498
2507
  var HEALTH_CHECK_TIMEOUT_MS = 2e3;
2499
2508
  var RATE_LIMIT_COOLDOWN_MS = 6e4;
@@ -2593,14 +2602,7 @@ function safeWrite(res, data) {
2593
2602
  }
2594
2603
  var BALANCE_CHECK_BUFFER = 1.5;
2595
2604
  function getProxyPort() {
2596
- const envPort = process.env.BLOCKRUN_PROXY_PORT;
2597
- if (envPort) {
2598
- const parsed = parseInt(envPort, 10);
2599
- if (!isNaN(parsed) && parsed > 0 && parsed < 65536) {
2600
- return parsed;
2601
- }
2602
- }
2603
- return DEFAULT_PORT;
2605
+ return PROXY_PORT;
2604
2606
  }
2605
2607
  async function checkExistingProxy(port) {
2606
2608
  const controller = new AbortController();
@@ -4171,7 +4173,7 @@ var plugin = {
4171
4173
  id: "clawrouter",
4172
4174
  name: "ClawRouter",
4173
4175
  description: "Smart LLM router \u2014 30+ models, x402 micropayments, 78% cost savings",
4174
- version: VERSION2,
4176
+ version: VERSION,
4175
4177
  async register(api) {
4176
4178
  const isDisabled = process.env.CLAWROUTER_DISABLED === "true" || process.env.CLAWROUTER_DISABLED === "1";
4177
4179
  if (isDisabled) {