@blockrun/clawrouter 0.8.18 → 0.8.20
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/README.md +17 -17
- package/dist/cli.js +57 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2372,6 +2372,42 @@ function getSessionId(headers, headerName = DEFAULT_SESSION_CONFIG.headerName) {
|
|
|
2372
2372
|
return void 0;
|
|
2373
2373
|
}
|
|
2374
2374
|
|
|
2375
|
+
// src/updater.ts
|
|
2376
|
+
var NPM_REGISTRY = "https://registry.npmjs.org/@blockrun/clawrouter/latest";
|
|
2377
|
+
var UPDATE_URL = "https://blockrun.ai/ClawRouter-update";
|
|
2378
|
+
var CHECK_TIMEOUT_MS = 5e3;
|
|
2379
|
+
function compareSemver(a, b) {
|
|
2380
|
+
const pa = a.split(".").map(Number);
|
|
2381
|
+
const pb = b.split(".").map(Number);
|
|
2382
|
+
for (let i = 0; i < 3; i++) {
|
|
2383
|
+
if ((pa[i] || 0) > (pb[i] || 0)) return 1;
|
|
2384
|
+
if ((pa[i] || 0) < (pb[i] || 0)) return -1;
|
|
2385
|
+
}
|
|
2386
|
+
return 0;
|
|
2387
|
+
}
|
|
2388
|
+
async function checkForUpdates() {
|
|
2389
|
+
try {
|
|
2390
|
+
const controller = new AbortController();
|
|
2391
|
+
const timeout = setTimeout(() => controller.abort(), CHECK_TIMEOUT_MS);
|
|
2392
|
+
const res = await fetch(NPM_REGISTRY, {
|
|
2393
|
+
signal: controller.signal,
|
|
2394
|
+
headers: { Accept: "application/json" }
|
|
2395
|
+
});
|
|
2396
|
+
clearTimeout(timeout);
|
|
2397
|
+
if (!res.ok) return;
|
|
2398
|
+
const data = await res.json();
|
|
2399
|
+
const latest = data.version;
|
|
2400
|
+
if (!latest) return;
|
|
2401
|
+
if (compareSemver(latest, VERSION) > 0) {
|
|
2402
|
+
console.log("");
|
|
2403
|
+
console.log(`\x1B[33m\u2B06\uFE0F ClawRouter ${latest} available (you have ${VERSION})\x1B[0m`);
|
|
2404
|
+
console.log(` Run: \x1B[36mcurl -fsSL ${UPDATE_URL} | bash\x1B[0m`);
|
|
2405
|
+
console.log("");
|
|
2406
|
+
}
|
|
2407
|
+
} catch {
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2375
2411
|
// src/proxy.ts
|
|
2376
2412
|
var BLOCKRUN_API = "https://blockrun.ai/api";
|
|
2377
2413
|
var AUTO_MODEL = "blockrun/auto";
|
|
@@ -2415,8 +2451,28 @@ function transformPaymentError(errorBody) {
|
|
|
2415
2451
|
});
|
|
2416
2452
|
}
|
|
2417
2453
|
}
|
|
2454
|
+
if (innerJson.invalidReason === "invalid_payload") {
|
|
2455
|
+
return JSON.stringify({
|
|
2456
|
+
error: {
|
|
2457
|
+
message: "Payment signature invalid. This may be a temporary issue.",
|
|
2458
|
+
type: "invalid_payload",
|
|
2459
|
+
help: "Try again. If this persists, reinstall ClawRouter: curl -fsSL https://blockrun.ai/ClawRouter-update | bash"
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2418
2463
|
}
|
|
2419
2464
|
}
|
|
2465
|
+
if (parsed.error === "Settlement failed" || parsed.details?.includes("Settlement failed")) {
|
|
2466
|
+
const details = parsed.details || "";
|
|
2467
|
+
const gasError = details.includes("unable to estimate gas");
|
|
2468
|
+
return JSON.stringify({
|
|
2469
|
+
error: {
|
|
2470
|
+
message: gasError ? "Payment failed: network congestion or gas issue. Try again." : "Payment settlement failed. Try again in a moment.",
|
|
2471
|
+
type: "settlement_failed",
|
|
2472
|
+
help: "This is usually temporary. If it persists, try: /model free"
|
|
2473
|
+
}
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2420
2476
|
} catch {
|
|
2421
2477
|
}
|
|
2422
2478
|
return errorBody;
|
|
@@ -2917,6 +2973,7 @@ async function startProxy(options) {
|
|
|
2917
2973
|
const port = addr.port;
|
|
2918
2974
|
const baseUrl = `http://127.0.0.1:${port}`;
|
|
2919
2975
|
options.onReady?.(port);
|
|
2976
|
+
checkForUpdates();
|
|
2920
2977
|
server.on("error", (err) => {
|
|
2921
2978
|
console.error(`[ClawRouter] Server runtime error: ${err.message}`);
|
|
2922
2979
|
options.onError?.(err);
|