@blockrun/clawrouter 0.12.9 → 0.12.10
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 +26 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +40 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1284,6 +1284,12 @@ declare function getStats(days?: number): Promise<AggregatedStats>;
|
|
|
1284
1284
|
* Format stats as ASCII table for terminal display.
|
|
1285
1285
|
*/
|
|
1286
1286
|
declare function formatStatsAscii(stats: AggregatedStats): string;
|
|
1287
|
+
/**
|
|
1288
|
+
* Delete all usage log files, resetting stats to zero.
|
|
1289
|
+
*/
|
|
1290
|
+
declare function clearStats(): Promise<{
|
|
1291
|
+
deletedFiles: number;
|
|
1292
|
+
}>;
|
|
1287
1293
|
|
|
1288
1294
|
/**
|
|
1289
1295
|
* Partner Service Registry
|
|
@@ -1381,4 +1387,4 @@ declare function buildPartnerTools(proxyBaseUrl: string): PartnerToolDefinition[
|
|
|
1381
1387
|
|
|
1382
1388
|
declare const plugin: OpenClawPluginDefinition;
|
|
1383
1389
|
|
|
1384
|
-
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PARTNER_SERVICES, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, type SweepError, type SweepResult, type Tier, type UsageEntry, type WalletConfig, type WalletResolution, blockrunProvider, buildPartnerTools, buildProviderModels, calculateModelCost, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, deriveSolanaKeyBytesLegacy, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, hashRequestContent, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, resolveModelAlias, resolvePaymentChain, route, savePaymentChain, setupSolana, startProxy, sweepSolanaWallet };
|
|
1390
|
+
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PARTNER_SERVICES, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, type SweepError, type SweepResult, type Tier, type UsageEntry, type WalletConfig, type WalletResolution, blockrunProvider, buildPartnerTools, buildProviderModels, calculateModelCost, clearStats, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, deriveSolanaKeyBytesLegacy, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, hashRequestContent, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, resolveModelAlias, resolvePaymentChain, route, savePaymentChain, setupSolana, startProxy, sweepSolanaWallet };
|
package/dist/index.js
CHANGED
|
@@ -3305,7 +3305,7 @@ async function logUsage(entry) {
|
|
|
3305
3305
|
}
|
|
3306
3306
|
|
|
3307
3307
|
// src/stats.ts
|
|
3308
|
-
import { readdir } from "fs/promises";
|
|
3308
|
+
import { readdir, unlink } from "fs/promises";
|
|
3309
3309
|
|
|
3310
3310
|
// src/fs-read.ts
|
|
3311
3311
|
import { open } from "fs/promises";
|
|
@@ -3545,6 +3545,16 @@ function formatStatsAscii(stats) {
|
|
|
3545
3545
|
lines.push("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D");
|
|
3546
3546
|
return lines.join("\n");
|
|
3547
3547
|
}
|
|
3548
|
+
async function clearStats() {
|
|
3549
|
+
try {
|
|
3550
|
+
const files = await readdir(LOG_DIR2);
|
|
3551
|
+
const logFiles = files.filter((f) => f.startsWith("usage-") && f.endsWith(".jsonl"));
|
|
3552
|
+
await Promise.all(logFiles.map((f) => unlink(join3(LOG_DIR2, f))));
|
|
3553
|
+
return { deletedFiles: logFiles.length };
|
|
3554
|
+
} catch {
|
|
3555
|
+
return { deletedFiles: 0 };
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3548
3558
|
|
|
3549
3559
|
// src/dedup.ts
|
|
3550
3560
|
import { createHash } from "crypto";
|
|
@@ -6131,6 +6141,21 @@ async function startProxy(options) {
|
|
|
6131
6141
|
res.end(JSON.stringify(stats, null, 2));
|
|
6132
6142
|
return;
|
|
6133
6143
|
}
|
|
6144
|
+
if (req.url === "/stats" && req.method === "DELETE") {
|
|
6145
|
+
try {
|
|
6146
|
+
const result = await clearStats();
|
|
6147
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
6148
|
+
res.end(JSON.stringify({ cleared: true, deletedFiles: result.deletedFiles }));
|
|
6149
|
+
} catch (err) {
|
|
6150
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
6151
|
+
res.end(
|
|
6152
|
+
JSON.stringify({
|
|
6153
|
+
error: `Failed to clear stats: ${err instanceof Error ? err.message : String(err)}`
|
|
6154
|
+
})
|
|
6155
|
+
);
|
|
6156
|
+
}
|
|
6157
|
+
return;
|
|
6158
|
+
}
|
|
6134
6159
|
if (req.url === "/stats" || req.url?.startsWith("/stats?")) {
|
|
6135
6160
|
try {
|
|
6136
6161
|
const url = new URL(req.url, "http://localhost");
|
|
@@ -8293,6 +8318,19 @@ async function createStatsCommand() {
|
|
|
8293
8318
|
requireAuth: false,
|
|
8294
8319
|
handler: async (ctx) => {
|
|
8295
8320
|
const arg = ctx.args?.trim().toLowerCase() || "7";
|
|
8321
|
+
if (arg === "clear" || arg === "reset") {
|
|
8322
|
+
try {
|
|
8323
|
+
const { deletedFiles } = await clearStats();
|
|
8324
|
+
return {
|
|
8325
|
+
text: `Stats cleared \u2014 ${deletedFiles} log file(s) deleted. Fresh start!`
|
|
8326
|
+
};
|
|
8327
|
+
} catch (err) {
|
|
8328
|
+
return {
|
|
8329
|
+
text: `Failed to clear stats: ${err instanceof Error ? err.message : String(err)}`,
|
|
8330
|
+
isError: true
|
|
8331
|
+
};
|
|
8332
|
+
}
|
|
8333
|
+
}
|
|
8296
8334
|
const days = parseInt(arg, 10) || 7;
|
|
8297
8335
|
try {
|
|
8298
8336
|
const stats = await getStats(Math.min(days, 30));
|
|
@@ -8761,6 +8799,7 @@ export {
|
|
|
8761
8799
|
buildPartnerTools,
|
|
8762
8800
|
buildProviderModels,
|
|
8763
8801
|
calculateModelCost,
|
|
8802
|
+
clearStats,
|
|
8764
8803
|
index_default as default,
|
|
8765
8804
|
deriveAllKeys,
|
|
8766
8805
|
deriveEvmKey,
|