@blockrun/clawrouter 0.12.12 → 0.12.16
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 +33 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -48,7 +48,7 @@ function createPayFetchWithPreAuth(baseFetch, client, ttlMs = DEFAULT_TTL_MS, op
|
|
|
48
48
|
const responseText = await Promise.race([
|
|
49
49
|
response.text(),
|
|
50
50
|
new Promise(
|
|
51
|
-
(_, reject) => setTimeout(() => reject(new Error("Body read timeout")),
|
|
51
|
+
(_, reject) => setTimeout(() => reject(new Error("Body read timeout")), 3e4)
|
|
52
52
|
)
|
|
53
53
|
]);
|
|
54
54
|
if (responseText) body = JSON.parse(responseText);
|
|
@@ -1744,6 +1744,13 @@ function resolveModelAlias(model) {
|
|
|
1744
1744
|
if (resolvedWithoutPrefix) return resolvedWithoutPrefix;
|
|
1745
1745
|
return withoutPrefix;
|
|
1746
1746
|
}
|
|
1747
|
+
if (normalized.startsWith("openai/")) {
|
|
1748
|
+
const withoutPrefix = normalized.slice("openai/".length);
|
|
1749
|
+
const resolvedWithoutPrefix = MODEL_ALIASES[withoutPrefix];
|
|
1750
|
+
if (resolvedWithoutPrefix) return resolvedWithoutPrefix;
|
|
1751
|
+
const isVirtualProfile = BLOCKRUN_MODELS.some((m) => m.id === withoutPrefix);
|
|
1752
|
+
if (isVirtualProfile) return withoutPrefix;
|
|
1753
|
+
}
|
|
1747
1754
|
return model;
|
|
1748
1755
|
}
|
|
1749
1756
|
var BLOCKRUN_MODELS = [
|
|
@@ -3027,6 +3034,14 @@ var SolanaBalanceMonitor = class {
|
|
|
3027
3034
|
async fetchBalance() {
|
|
3028
3035
|
const owner = solAddress(this.walletAddress);
|
|
3029
3036
|
const mint = solAddress(SOLANA_USDC_MINT);
|
|
3037
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
3038
|
+
const result = await this.fetchBalanceOnce(owner, mint);
|
|
3039
|
+
if (result > 0n || attempt === 1) return result;
|
|
3040
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
3041
|
+
}
|
|
3042
|
+
return 0n;
|
|
3043
|
+
}
|
|
3044
|
+
async fetchBalanceOnce(owner, mint) {
|
|
3030
3045
|
const controller = new AbortController();
|
|
3031
3046
|
const timer = setTimeout(() => controller.abort(), BALANCE_TIMEOUT_MS);
|
|
3032
3047
|
try {
|
|
@@ -4987,23 +5002,27 @@ var HEALTH_CHECK_TIMEOUT_MS = 2e3;
|
|
|
4987
5002
|
var RATE_LIMIT_COOLDOWN_MS = 6e4;
|
|
4988
5003
|
var PORT_RETRY_ATTEMPTS = 5;
|
|
4989
5004
|
var PORT_RETRY_DELAY_MS = 1e3;
|
|
4990
|
-
var
|
|
4991
|
-
|
|
5005
|
+
var MODEL_BODY_READ_TIMEOUT_MS = 3e5;
|
|
5006
|
+
var ERROR_BODY_READ_TIMEOUT_MS = 3e4;
|
|
5007
|
+
async function readBodyWithTimeout(body, timeoutMs = MODEL_BODY_READ_TIMEOUT_MS) {
|
|
4992
5008
|
if (!body) return [];
|
|
4993
5009
|
const reader = body.getReader();
|
|
4994
5010
|
const chunks = [];
|
|
5011
|
+
let timer;
|
|
4995
5012
|
try {
|
|
4996
5013
|
while (true) {
|
|
4997
5014
|
const result = await Promise.race([
|
|
4998
5015
|
reader.read(),
|
|
4999
|
-
new Promise(
|
|
5000
|
-
|
|
5001
|
-
)
|
|
5016
|
+
new Promise((_, reject) => {
|
|
5017
|
+
timer = setTimeout(() => reject(new Error("Body read timeout")), timeoutMs);
|
|
5018
|
+
})
|
|
5002
5019
|
]);
|
|
5020
|
+
clearTimeout(timer);
|
|
5003
5021
|
if (result.done) break;
|
|
5004
5022
|
chunks.push(result.value);
|
|
5005
5023
|
}
|
|
5006
5024
|
} finally {
|
|
5025
|
+
clearTimeout(timer);
|
|
5007
5026
|
reader.releaseLock();
|
|
5008
5027
|
}
|
|
5009
5028
|
return chunks;
|
|
@@ -5108,6 +5127,8 @@ function canWrite(res) {
|
|
|
5108
5127
|
}
|
|
5109
5128
|
function safeWrite(res, data) {
|
|
5110
5129
|
if (!canWrite(res)) {
|
|
5130
|
+
const bytes = typeof data === "string" ? Buffer.byteLength(data) : data.length;
|
|
5131
|
+
console.warn(`[ClawRouter] safeWrite: socket not writable, dropping ${bytes} bytes`);
|
|
5111
5132
|
return false;
|
|
5112
5133
|
}
|
|
5113
5134
|
return res.write(data);
|
|
@@ -5507,7 +5528,7 @@ async function proxyPartnerRequest(req, res, apiBase, payFetch) {
|
|
|
5507
5528
|
});
|
|
5508
5529
|
res.writeHead(upstream.status, responseHeaders);
|
|
5509
5530
|
if (upstream.body) {
|
|
5510
|
-
const chunks = await readBodyWithTimeout(upstream.body);
|
|
5531
|
+
const chunks = await readBodyWithTimeout(upstream.body, ERROR_BODY_READ_TIMEOUT_MS);
|
|
5511
5532
|
for (const chunk of chunks) {
|
|
5512
5533
|
safeWrite(res, Buffer.from(chunk));
|
|
5513
5534
|
}
|
|
@@ -5957,7 +5978,7 @@ async function tryModelRequest(upstreamUrl, method, headers, body, modelId, maxT
|
|
|
5957
5978
|
signal
|
|
5958
5979
|
});
|
|
5959
5980
|
if (response.status !== 200) {
|
|
5960
|
-
const errorBodyChunks = await readBodyWithTimeout(response.body);
|
|
5981
|
+
const errorBodyChunks = await readBodyWithTimeout(response.body, ERROR_BODY_READ_TIMEOUT_MS);
|
|
5961
5982
|
const errorBody = Buffer.concat(errorBodyChunks).toString();
|
|
5962
5983
|
const isProviderErr = isProviderError(response.status, errorBody);
|
|
5963
5984
|
return {
|
|
@@ -5970,7 +5991,7 @@ async function tryModelRequest(upstreamUrl, method, headers, body, modelId, maxT
|
|
|
5970
5991
|
const contentType = response.headers.get("content-type") || "";
|
|
5971
5992
|
if (contentType.includes("json") || contentType.includes("text")) {
|
|
5972
5993
|
try {
|
|
5973
|
-
const clonedChunks = await readBodyWithTimeout(response.clone().body);
|
|
5994
|
+
const clonedChunks = await readBodyWithTimeout(response.clone().body, ERROR_BODY_READ_TIMEOUT_MS);
|
|
5974
5995
|
const responseBody = Buffer.concat(clonedChunks).toString();
|
|
5975
5996
|
const degradedReason = detectDegradedSuccessResponse(responseBody);
|
|
5976
5997
|
if (degradedReason) {
|
|
@@ -6355,9 +6376,9 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
6355
6376
|
const normalizedModel = typeof parsed.model === "string" ? parsed.model.trim().toLowerCase() : "";
|
|
6356
6377
|
const resolvedModel = resolveModelAlias(normalizedModel);
|
|
6357
6378
|
const wasAlias = resolvedModel !== normalizedModel;
|
|
6358
|
-
const isRoutingProfile = ROUTING_PROFILES.has(normalizedModel);
|
|
6379
|
+
const isRoutingProfile = ROUTING_PROFILES.has(normalizedModel) || ROUTING_PROFILES.has(resolvedModel);
|
|
6359
6380
|
if (isRoutingProfile) {
|
|
6360
|
-
const profileName =
|
|
6381
|
+
const profileName = resolvedModel.replace("blockrun/", "");
|
|
6361
6382
|
routingProfile = profileName;
|
|
6362
6383
|
}
|
|
6363
6384
|
console.log(
|
|
@@ -7734,6 +7755,7 @@ ClawRouter Partner APIs (v${VERSION})
|
|
|
7734
7755
|
} else {
|
|
7735
7756
|
console.log(`[ClawRouter] Wallet balance: ${balance.balanceUSD}`);
|
|
7736
7757
|
}
|
|
7758
|
+
proxy.balanceMonitor.invalidate();
|
|
7737
7759
|
} catch {
|
|
7738
7760
|
console.log(`[ClawRouter] Wallet: ${displayAddress} (balance check pending)`);
|
|
7739
7761
|
}
|